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
651919f101c0e1d0547f861a89be6e29ae6028be
d1a52c3f208fa42c41df8278c3d280f075eb020c
/tests/leanpkg/user_attr_app/UserAttr.lean
219093ee95d0e5021e6a9b8aa5ac2fe078f434a9
[ "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
367
lean
import UserAttr.Tst open Lean def tst : MetaM Unit := do let env ← getEnv assert! (blaAttr.hasTag env `f) assert! (blaAttr.hasTag env `g) assert! !(blaAttr.hasTag env `id) pure () #eval tst unsafe def main : IO Unit := do initSearchPath (← Lean.findSysroot?) ["build"] withImportModules [{ module := `UserAttr.Tst : Import }] {} 0 fun env => ()
931e5519f912cdf61401fa185a1335eb39f06f00
94e33a31faa76775069b071adea97e86e218a8ee
/src/set_theory/surreal/dyadic.lean
4a7c24ed6d7b8ea61b1d4bd6bf16e8a44106df01
[ "Apache-2.0" ]
permissive
urkud/mathlib
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
6379d39e6b5b279df9715f8011369a301b634e41
refs/heads/master
1,658,425,342,662
1,658,078,703,000
1,658,078,703,000
186,910,338
0
0
Apache-2.0
1,568,512,083,000
1,557,958,709,000
Lean
UTF-8
Lean
false
false
10,061
lean
/- Copyright (c) 2021 Apurva Nakade. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Apurva Nakade -/ import algebra.algebra.basic import ring_theory.localization.away import set_theory.game.birthday import set_theory.surreal.basic /-! # Dyadic numbers Dyadic numbers are obtained by localizing ℤ away from 2. They are the initial object in the category of rings with no 2-torsion. ## Dyadic surreal numbers We construct dyadic surreal numbers using the canonical map from ℤ[2 ^ {-1}] to surreals. As we currently do not have a ring structure on `surreal` we construct this map explicitly. Once we have the ring structure, this map can be constructed directly by sending `2 ^ {-1}` to `half`. ## Embeddings The above construction gives us an abelian group embedding of ℤ into `surreal`. The goal is to extend this to an embedding of dyadic rationals into `surreal` and use Cauchy sequences of dyadic rational numbers to construct an ordered field embedding of ℝ into `surreal`. -/ universes u local infix ` ≈ ` := pgame.equiv namespace pgame /-- For a natural number `n`, the pre-game `pow_half (n + 1)` is recursively defined as `{0 | pow_half n}`. These are the explicit expressions of powers of `1 / 2`. By definition, we have `pow_half 0 = 1` and `pow_half 1 ≈ 1 / 2` and we prove later on that `pow_half (n + 1) + pow_half (n + 1) ≈ pow_half n`. -/ def pow_half : ℕ → pgame | 0 := 1 | (n + 1) := ⟨punit, punit, 0, λ _, pow_half n⟩ @[simp] lemma pow_half_zero : pow_half 0 = 1 := rfl lemma pow_half_left_moves (n) : (pow_half n).left_moves = punit := by cases n; refl lemma pow_half_zero_right_moves : (pow_half 0).right_moves = pempty := rfl lemma pow_half_succ_right_moves (n) : (pow_half (n + 1)).right_moves = punit := rfl @[simp] lemma pow_half_move_left (n i) : (pow_half n).move_left i = 0 := by cases n; cases i; refl @[simp] lemma pow_half_succ_move_right (n i) : (pow_half (n + 1)).move_right i = pow_half n := rfl instance unique_pow_half_left_moves (n) : unique (pow_half n).left_moves := by cases n; exact punit.unique instance is_empty_pow_half_zero_right_moves : is_empty (pow_half 0).right_moves := pempty.is_empty instance unique_pow_half_succ_right_moves (n) : unique (pow_half (n + 1)).right_moves := punit.unique @[simp] theorem birthday_half : birthday (pow_half 1) = 2 := by { rw birthday_def, dsimp, simpa using order.le_succ (1 : ordinal) } /-- For all natural numbers `n`, the pre-games `pow_half n` are numeric. -/ theorem numeric_pow_half (n) : (pow_half n).numeric := begin induction n with n hn, { exact numeric_one }, { split, { simpa using hn.move_left_lt default }, { exact ⟨λ _, numeric_zero, λ _, hn⟩ } } end theorem pow_half_succ_lt_pow_half (n : ℕ) : pow_half (n + 1) < pow_half n := (numeric_pow_half (n + 1)).lt_move_right default theorem pow_half_succ_le_pow_half (n : ℕ) : pow_half (n + 1) ≤ pow_half n := (pow_half_succ_lt_pow_half n).le theorem pow_half_le_one (n : ℕ) : pow_half n ≤ 1 := begin induction n with n hn, { exact le_rfl }, { exact (pow_half_succ_le_pow_half n).trans hn } end theorem pow_half_succ_lt_one (n : ℕ) : pow_half (n + 1) < 1 := (pow_half_succ_lt_pow_half n).trans_le $ pow_half_le_one n theorem pow_half_pos (n : ℕ) : 0 < pow_half n := by { rw [←lf_iff_lt numeric_zero (numeric_pow_half n), zero_lf_le], simp } theorem zero_le_pow_half (n : ℕ) : 0 ≤ pow_half n := (pow_half_pos n).le theorem add_pow_half_succ_self_eq_pow_half (n) : pow_half (n + 1) + pow_half (n + 1) ≈ pow_half n := begin induction n using nat.strong_induction_on with n hn, { split; rw le_iff_forall_lf; split, { rintro (⟨⟨ ⟩⟩ | ⟨⟨ ⟩⟩); apply lf_of_lt, { calc 0 + pow_half n.succ ≈ pow_half n.succ : zero_add_equiv _ ... < pow_half n : pow_half_succ_lt_pow_half n }, { calc pow_half n.succ + 0 ≈ pow_half n.succ : add_zero_equiv _ ... < pow_half n : pow_half_succ_lt_pow_half n } }, { cases n, { rintro ⟨ ⟩ }, rintro ⟨ ⟩, apply lf_of_move_right_le, swap, exact sum.inl default, calc pow_half n.succ + pow_half (n.succ + 1) ≤ pow_half n.succ + pow_half n.succ : add_le_add_left (pow_half_succ_le_pow_half _) _ ... ≈ pow_half n : hn _ (nat.lt_succ_self n) }, { simp only [pow_half_move_left, forall_const], apply lf_of_lt, calc 0 ≈ 0 + 0 : (add_zero_equiv 0).symm ... ≤ pow_half n.succ + 0 : add_le_add_right (zero_le_pow_half _) _ ... < pow_half n.succ + pow_half n.succ : add_lt_add_left (pow_half_pos _) _ }, { rintro (⟨⟨ ⟩⟩ | ⟨⟨ ⟩⟩); apply lf_of_lt, { calc pow_half n ≈ pow_half n + 0 : (add_zero_equiv _).symm ... < pow_half n + pow_half n.succ : add_lt_add_left (pow_half_pos _) _ }, { calc pow_half n ≈ 0 + pow_half n : (zero_add_equiv _).symm ... < pow_half n.succ + pow_half n : add_lt_add_right (pow_half_pos _) _ } } } end theorem half_add_half_equiv_one : pow_half 1 + pow_half 1 ≈ 1 := add_pow_half_succ_self_eq_pow_half 0 end pgame namespace surreal open pgame /-- Powers of the surreal number `half`. -/ def pow_half (n : ℕ) : surreal := ⟦⟨pgame.pow_half n, pgame.numeric_pow_half n⟩⟧ @[simp] lemma pow_half_zero : pow_half 0 = 1 := rfl @[simp] lemma double_pow_half_succ_eq_pow_half (n : ℕ) : 2 • pow_half n.succ = pow_half n := by { rw two_nsmul, exact quotient.sound (pgame.add_pow_half_succ_self_eq_pow_half n) } @[simp] lemma nsmul_pow_two_pow_half (n : ℕ) : 2 ^ n • pow_half n = 1 := begin induction n with n hn, { simp only [nsmul_one, pow_half_zero, nat.cast_one, pow_zero] }, { rw [← hn, ← double_pow_half_succ_eq_pow_half n, smul_smul (2^n) 2 (pow_half n.succ), mul_comm, pow_succ] } end @[simp] lemma nsmul_pow_two_pow_half' (n k : ℕ) : 2 ^ n • pow_half (n + k) = pow_half k := begin induction k with k hk, { simp only [add_zero, surreal.nsmul_pow_two_pow_half, nat.nat_zero_eq_zero, eq_self_iff_true, surreal.pow_half_zero] }, { rw [← double_pow_half_succ_eq_pow_half (n + k), ← double_pow_half_succ_eq_pow_half k, smul_algebra_smul_comm] at hk, rwa ← zsmul_eq_zsmul_iff' two_ne_zero } end lemma zsmul_pow_two_pow_half (m : ℤ) (n k : ℕ) : (m * 2 ^ n) • pow_half (n + k) = m • pow_half k := begin rw mul_zsmul, congr, norm_cast, exact nsmul_pow_two_pow_half' n k end lemma dyadic_aux {m₁ m₂ : ℤ} {y₁ y₂ : ℕ} (h₂ : m₁ * (2 ^ y₁) = m₂ * (2 ^ y₂)) : m₁ • pow_half y₂ = m₂ • pow_half y₁ := begin revert m₁ m₂, wlog h : y₁ ≤ y₂, intros m₁ m₂ h₂, obtain ⟨c, rfl⟩ := le_iff_exists_add.mp h, rw [add_comm, pow_add, ← mul_assoc, mul_eq_mul_right_iff] at h₂, cases h₂, { rw [h₂, add_comm, zsmul_pow_two_pow_half m₂ c y₁] }, { have := nat.one_le_pow y₁ 2 nat.succ_pos', norm_cast at h₂, linarith }, end /-- The additive monoid morphism `dyadic_map` sends ⟦⟨m, 2^n⟩⟧ to m • half ^ n. -/ def dyadic_map : localization.away (2 : ℤ) →+ surreal := { to_fun := λ x, localization.lift_on x (λ x y, x • pow_half (submonoid.log y)) $ begin intros m₁ m₂ n₁ n₂ h₁, obtain ⟨⟨n₃, y₃, hn₃⟩, h₂⟩ := localization.r_iff_exists.mp h₁, simp only [subtype.coe_mk, mul_eq_mul_right_iff] at h₂, cases h₂, { simp only, obtain ⟨a₁, ha₁⟩ := n₁.prop, obtain ⟨a₂, ha₂⟩ := n₂.prop, have hn₁ : n₁ = submonoid.pow 2 a₁ := subtype.ext ha₁.symm, have hn₂ : n₂ = submonoid.pow 2 a₂ := subtype.ext ha₂.symm, have h₂ : 1 < (2 : ℤ).nat_abs, from one_lt_two, rw [hn₁, hn₂, submonoid.log_pow_int_eq_self h₂, submonoid.log_pow_int_eq_self h₂], apply dyadic_aux, rwa [ha₁, ha₂] }, { have : (1 : ℤ) ≤ 2 ^ y₃ := by exact_mod_cast nat.one_le_pow y₃ 2 nat.succ_pos', linarith } end, map_zero' := localization.lift_on_zero _ _, map_add' := λ x y, localization.induction_on₂ x y $ begin rintro ⟨a, ⟨b, ⟨b', rfl⟩⟩⟩ ⟨c, ⟨d, ⟨d', rfl⟩⟩⟩, have h₂ : 1 < (2 : ℤ).nat_abs, from one_lt_two, have hpow₂ := submonoid.log_pow_int_eq_self h₂, simp_rw submonoid.pow_apply at hpow₂, simp_rw [localization.add_mk, localization.lift_on_mk, subtype.coe_mk, submonoid.log_mul (int.pow_right_injective h₂), hpow₂], calc (2 ^ b' * c + 2 ^ d' * a) • pow_half (b' + d') = (c * 2 ^ b') • pow_half (b' + d') + (a * 2 ^ d') • pow_half (d' + b') : by simp only [add_smul, mul_comm,add_comm] ... = c • pow_half d' + a • pow_half b' : by simp only [zsmul_pow_two_pow_half] ... = a • pow_half b' + c • pow_half d' : add_comm _ _, end } @[simp] lemma dyadic_map_apply (m : ℤ) (p : submonoid.powers (2 : ℤ)) : dyadic_map (is_localization.mk' (localization (submonoid.powers 2)) m p) = m • pow_half (submonoid.log p) := by { rw ← localization.mk_eq_mk', refl } @[simp] lemma dyadic_map_apply_pow (m : ℤ) (n : ℕ) : dyadic_map (is_localization.mk' (localization (submonoid.powers 2)) m (submonoid.pow 2 n)) = m • pow_half n := by rw [dyadic_map_apply, @submonoid.log_pow_int_eq_self 2 one_lt_two] /-- We define dyadic surreals as the range of the map `dyadic_map`. -/ def dyadic : set surreal := set.range dyadic_map -- We conclude with some ideas for further work on surreals; these would make fun projects. -- TODO show that the map from dyadic rationals to surreals is injective -- TODO map the reals into the surreals, using dyadic Dedekind cuts -- TODO show this is a group homomorphism, and injective -- TODO show the maps from the dyadic rationals and from the reals -- into the surreals are multiplicative end surreal
b58db1fa1223511b0754d37e25bb2de038a94c65
957a80ea22c5abb4f4670b250d55534d9db99108
/tests/lean/run/prec_max.lean
1ab6577a04e09dde32d4171e6e96c287e9c0e4cd
[ "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
369
lean
open nat reserve postfix ⁻¹:(max + 1) postfix ⁻¹ := eq.symm constant foo (a b : nat) : a + b = 0 theorem tst1 (a b : nat) : 0 = a + b := (foo _ _)⁻¹ constant f {a b : nat} (h1 : 0 = a + b) (h2 : a = b) : a = 0 ∧ b = 0 example (a b : nat) : a = 0 ∧ b = 0 := f (foo _ _)⁻¹ sorry example (a b : nat) : a = 0 ∧ b = 0 := f (foo _ _)⁻¹ sorry⁻¹
43683891142df31e0037b04879128a19329dc558
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/analysis/calculus/deriv/star.lean
1f75c711e9ad2cd4ada877d5a9df1166529df1e1
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
2,429
lean
/- Copyright (c) 2023 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import analysis.calculus.deriv.basic import analysis.calculus.fderiv.star /-! # Star operations on derivatives > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file contains the usual formulas (and existence assertions) for the derivative of the star operation. Note that these only apply when the field that the derivative is respect to has a trivial star operation; which as should be expected rules out `𝕜 = ℂ`. -/ universes u v w noncomputable theory open_locale classical topology big_operators filter ennreal open filter asymptotics set open continuous_linear_map (smul_right smul_right_one_eq_iff) variables {𝕜 : Type u} [nontrivially_normed_field 𝕜] variables {F : Type v} [normed_add_comm_group F] [normed_space 𝕜 F] variables {E : Type w} [normed_add_comm_group E] [normed_space 𝕜 E] variables {f f₀ f₁ g : 𝕜 → F} variables {f' f₀' f₁' g' : F} variables {x : 𝕜} variables {s t : set 𝕜} variables {L L₁ L₂ : filter 𝕜} section star /-! ### Derivative of `x ↦ star x` -/ variables [star_ring 𝕜] [has_trivial_star 𝕜] [star_add_monoid F] [has_continuous_star F] variable [star_module 𝕜 F] protected theorem has_deriv_at_filter.star (h : has_deriv_at_filter f f' x L) : has_deriv_at_filter (λ x, star (f x)) (star f') x L := by simpa using h.star.has_deriv_at_filter protected theorem has_deriv_within_at.star (h : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, star (f x)) (star f') s x := h.star protected theorem has_deriv_at.star (h : has_deriv_at f f' x) : has_deriv_at (λ x, star (f x)) (star f') x := h.star protected theorem has_strict_deriv_at.star (h : has_strict_deriv_at f f' x) : has_strict_deriv_at (λ x, star (f x)) (star f') x := by simpa using h.star.has_strict_deriv_at protected lemma deriv_within.star (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (λ y, star (f y)) s x = star (deriv_within f s x) := fun_like.congr_fun (fderiv_within_star hxs) _ protected lemma deriv.star : deriv (λ y, star (f y)) x = star (deriv f x) := fun_like.congr_fun fderiv_star _ @[simp] protected lemma deriv.star' : deriv (λ y, star (f y)) = (λ x, star (deriv f x)) := funext $ λ x, deriv.star end star
8df12f10a2d1adba69168d23d44201624aab9a5b
f4bff2062c030df03d65e8b69c88f79b63a359d8
/src/game/functions/bothInjective.lean
1c34a699552ac2a09a4c6f087906a7f6f4c0f3f8
[ "Apache-2.0" ]
permissive
adastra7470/real-number-game
776606961f52db0eb824555ed2f8e16f92216ea3
f9dcb7d9255a79b57e62038228a23346c2dc301b
refs/heads/master
1,669,221,575,893
1,594,669,800,000
1,594,669,800,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
548
lean
import data.real.basic open function /- # Chapter 6 : Functions ## Level 1 A classical result in composition of functions. -/ /- Lemma If $f : X \to Y$ and $g : Y \to Z$ are both injective functions, then the function resulting from their composition is also injective. -/ theorem both_injective (X Y Z : set ℝ) (f : X → Y) (g : Y → Z) : injective f ∧ injective g → injective (g ∘ f) := begin intros h a b ha, apply h.left, apply h.right, --either this: assumption, --or the line below exact ha, done end
4a100cd89ce66820fcddd40e7e18a29a3519e196
0ec6b5eb2131429a4464b8e6c6f09897abba3de1
/src/field_extensions.lean
511b1f5c36095ba13b836cfa27b84b627ab049f3
[]
no_license
kckennylau/local-langlands-abelian
ba1b86e9d956778cd28ac900ffec02b0f0ba172a
ee22666898357dab800a0432214a22c519ed26a9
refs/heads/master
1,584,671,060,846
1,545,151,246,000
1,545,151,246,000
137,111,892
8
0
null
null
null
null
UTF-8
Lean
false
false
6,118
lean
import linear_algebra.dimension import analysis.topology.topological_structures import algebra.pi_instances import field_theory.subfield import ring_theory.ideal_operations import .topological_group import .algebra_tensor local attribute [instance] classical.prop_decidable universes u v set_option eqn_compiler.zeta true class is_alg_closed_field (F : Type u) [field F] : Prop := (alg_closed : ∀ f : polynomial F, f.degree > 1 → ∃ x, f.eval x = 0) variables {F : Type u} [discrete_field F] class is_integral {K : Type v} [comm_ring K] (i : algebra F K) : Prop := (integral : ∀ x : K, ∃ f : polynomial F, f.monic ∧ polynomial.aeval F i x f = 0) instance discrete_field_of_subalgebra_of_integral {K : Type v} [discrete_field K] (i : algebra F K) [is_integral i] (S : subalgebra i) : discrete_field S := sorry class is_algebraic_closure {K : Type v} [discrete_field K] (i : algebra F K) extends is_alg_closed_field K, is_integral i : Prop structure Gal {K : Type v} [comm_ring K] (i : algebra F K) extends K ≃ K := (hom : is_ring_hom to_fun) (fix : ∀ x : F, to_fun (i x) = i x) attribute [instance] Gal.hom instance Gal.hom' {K : Type v} [comm_ring K] (i : algebra F K) (f : Gal i) : is_ring_hom f.to_equiv := f.hom theorem Gal.ext {K : Type v} [comm_ring K] (i : algebra F K) : ∀ f g : Gal i, (∀ x, f.to_equiv x = g.to_equiv x) → f = g | ⟨_, _, _⟩ ⟨_, _, _⟩ H := by rw Gal.mk.inj_eq; from equiv.ext _ _ H def is_reduced_comm_ring (R : Type u) [comm_ring R] : Prop := (⊥ : ideal R).radical = ⊥ def algebraic_closure_field (F : Type u) [discrete_field F] : Type u := sorry instance (F : Type u) [discrete_field F] : discrete_field (algebraic_closure_field F) := sorry def algebraic_closure (F : Type u) [discrete_field F] : algebra F (algebraic_closure_field F) := sorry instance (F : Type u) [discrete_field F] : is_algebraic_closure (algebraic_closure F) := sorry -- http://www.math.uconn.edu/~kconrad/blurbs/galoistheory/separable2.pdf class is_separable (S : subalgebra $ algebraic_closure F) : Prop := (separable : is_reduced_comm_ring (S.algebra.mod ⊗ (algebraic_closure F).mod)) variables F structure finite_Galois_extension : Type u := (S : subalgebra $ algebraic_closure F) (finite : vector_space.dim F S.algebra.mod < cardinal.omega) (separable : is_separable S) (proj : Gal (algebraic_closure F) → Gal S.algebra) (proj_commutes : ∀ f : Gal (algebraic_closure F), ∀ x : S, ((proj f).to_equiv x).1 = f.to_equiv x.1) attribute [instance] finite_Galois_extension.separable variables {F} instance Gal.group {K : Type v} [comm_ring K] (i : algebra F K) : group (Gal i) := { mul := λ f g, ⟨f.to_equiv.trans g.to_equiv, @@is_ring_hom.comp _ _ _ f.hom _ _ g.hom, λ _, by simp [equiv.trans, f.fix, g.fix]⟩, mul_assoc := λ _ _ _, Gal.ext _ _ _ $ λ _, by simp, one := ⟨equiv.refl _, is_ring_hom.id, λ _, rfl⟩, one_mul := λ _, Gal.ext _ _ _ $ λ _, rfl, mul_one := λ _, Gal.ext _ _ _ $ λ _, rfl, inv := λ f, ⟨f.to_equiv.symm, ⟨show f.to_equiv.symm 1 = 1, by rw [equiv.symm_apply_eq, is_ring_hom.map_one f.to_equiv], λ x y, show f.to_equiv.symm (x * y) = f.to_equiv.symm x * f.to_equiv.symm y, by rw [equiv.symm_apply_eq, is_ring_hom.map_mul f.to_equiv]; rw [equiv.apply_inverse_apply, equiv.apply_inverse_apply], λ x y, show f.to_equiv.symm (x + y) = f.to_equiv.symm x + f.to_equiv.symm y, by rw [equiv.symm_apply_eq, is_ring_hom.map_add f.to_equiv]; rw [equiv.apply_inverse_apply, equiv.apply_inverse_apply]⟩, λ x, show f.to_equiv.symm (i x) = i x, by rw equiv.symm_apply_eq; from (f.fix x).symm⟩, mul_left_inv := λ _, Gal.ext _ _ _ $ λ _, equiv.apply_inverse_apply _ _ } instance Gal.finite_Galois_extension.topological_space (E : finite_Galois_extension F) : topological_space (Gal E.S.algebra) := ⊤ instance Gal.finite_Galois_extension.topological_group (E : finite_Galois_extension F) : topological_group (Gal E.S.algebra) := { continuous_mul := λ x1 h1, by apply is_open_prod_iff.2; intros x y H; refine ⟨{x}, {y}, trivial, trivial, _, _, _⟩; simp; simpa using H, continuous_inv := continuous_top } variables (F) instance Gal_algebraic_closure.topological_space : topological_space (Gal $ algebraic_closure F) := @topological_space.induced _ (Π E : finite_Galois_extension F, Gal E.S.algebra) (λ f E, E.proj f) (@Pi.topological_space _ _ (λ _, ⊤)) instance Gal.topological_group : topological_group (Gal $ algebraic_closure F) := @topological_group.induced _ _ _ _ _ (@Pi.topological_group (finite_Galois_extension F) (λ E, Gal E.S.algebra) _ _ _) (λ f S, S.proj f) (by constructor; intros f g; funext S; apply Gal.ext; intro x; apply subtype.eq; have := S.proj_commutes; dsimp at this ⊢; change ((S.proj (f * g)).to_equiv x).1 = ((S.proj f * S.proj g).to_equiv x).1; dsimp [(*), semigroup.mul, monoid.mul, group.mul]; simp [this]) variables {F} def subalgebra.Gal {K : Type v} [comm_ring K] {i : algebra F K} (S : subalgebra i) : set (Gal i) := { f | ∀ x ∈ S, f.to_equiv x = x } instance Gal.intermediate.subgroup {K : Type v} [comm_ring K] {i : algebra F K} (S : subalgebra i) : is_subgroup S.Gal := { mul_mem := λ f g H1 H2 x hx, show f.to_equiv.trans g.to_equiv x = x, by simp [H1 x hx, H2 x hx], one_mem := λ x hx, rfl, inv_mem := λ f H1 x hx, show f.to_equiv.symm x = x, by rw equiv.symm_apply_eq; from (H1 x hx).symm } instance Gal.normal (E : finite_Galois_extension F) : normal_subgroup E.S.Gal := { normal := λ f hf g x hx, show g.to_equiv.trans (f.to_equiv.trans g.to_equiv.symm) x = x, from have _ := E.proj_commutes g ⟨x, hx⟩, by simp at this ⊢; rw [← this, hf, this]; [simp, from (((E.proj g).to_equiv) ⟨x, hx⟩).2] } instance Gal.intermediate.topological_group (E : finite_Galois_extension F) : topological_group E.S.Gal := topological_group.induced _ _ subtype.val
518a428f18c64b04b89e925bedc2f0fc05f5faa4
bd12a817ba941113eb7fdb7ddf0979d9ed9386a0
/src/category_theory/limits/cones.lean
cb3a700dc2581bea2a82ca452782faa416ff2770
[ "Apache-2.0" ]
permissive
flypitch/mathlib
563d9c3356c2885eb6cefaa704d8d86b89b74b15
70cd00bc20ad304f2ac0886b2291b44261787607
refs/heads/master
1,590,167,818,658
1,557,762,121,000
1,557,762,121,000
186,450,076
0
0
Apache-2.0
1,557,762,289,000
1,557,762,288,000
null
UTF-8
Lean
false
false
13,761
lean
-- Copyright (c) 2017 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Stephen Morgan, Scott Morrison import category_theory.whiskering import category_theory.const import category_theory.opposites import category_theory.yoneda import category_theory.concrete_category universes v u u' -- declare the `v`'s first; see `category_theory.category` for an explanation open category_theory -- There is an awkward difficulty with universes here. -- If we allowed `J` to be a small category in `Prop`, we'd run into trouble -- because `yoneda.obj (F : (J ⥤ C)ᵒᵖ)` will be a functor into `Sort (max v 1)`, -- not into `Sort v`. -- So we don't allow this case; it's not particularly useful anyway. variables {J : Type v} [small_category J] variables {C : Sort u} [𝒞 : category.{v+1} C] include 𝒞 open category_theory open category_theory.category open category_theory.functor namespace category_theory namespace functor variables {J C} (F : J ⥤ C) /-- `F.cones` is the functor assigning to an object `X` the type of natural transformations from the constant functor with value `X` to `F`. An object representing this functor is a limit of `F`. -/ def cones : Cᵒᵖ ⥤ Type v := (const J).op ⋙ (yoneda.obj F) lemma cones_obj (X : Cᵒᵖ) : F.cones.obj X = ((const J).obj (unop X) ⟶ F) := rfl @[simp] lemma cones_map_app {X₁ X₂ : Cᵒᵖ} (f : X₁ ⟶ X₂) (t : F.cones.obj X₁) (j : J) : (F.cones.map f t).app j = f.unop ≫ t.app j := rfl /-- `F.cocones` is the functor assigning to an object `X` the type of natural transformations from `F` to the constant functor with value `X`. An object corepresenting this functor is a colimit of `F`. -/ def cocones : C ⥤ Type v := const J ⋙ coyoneda.obj (op F) lemma cocones_obj (X : C) : F.cocones.obj X = (F ⟶ (const J).obj X) := rfl @[simp] lemma cocones_map_app {X₁ X₂ : C} (f : X₁ ⟶ X₂) (t : F.cocones.obj X₁) (j : J) : (F.cocones.map f t).app j = t.app j ≫ f := rfl end functor section variables (J C) def cones : (J ⥤ C) ⥤ (Cᵒᵖ ⥤ Type v) := { obj := functor.cones, map := λ F G f, whisker_left (const J).op (yoneda.map f) } def cocones : (J ⥤ C)ᵒᵖ ⥤ (C ⥤ Type v) := { obj := λ F, functor.cocones (unop F), map := λ F G f, whisker_left (const J) (coyoneda.map f) } variables {J C} @[simp] lemma cones_obj (F : J ⥤ C) : (cones J C).obj F = F.cones := rfl @[simp] lemma cones_map {F G : J ⥤ C} {f : F ⟶ G} : (cones J C).map f = (whisker_left (const J).op (yoneda.map f)) := rfl @[simp] lemma cocones_obj (F : (J ⥤ C)ᵒᵖ) : (cocones J C).obj F = (unop F).cocones := rfl @[simp] lemma cocones_map {F G : (J ⥤ C)ᵒᵖ} {f : F ⟶ G} : (cocones J C).map f = (whisker_left (const J) (coyoneda.map f)) := rfl end namespace limits /-- A `c : cone F` is: * an object `c.X` and * a natural transformation `c.π : c.X ⟶ F` from the constant `c.X` functor to `F`. `cone F` is equivalent, in the obvious way, to `Σ X, F.cones.obj X`. -/ structure cone (F : J ⥤ C) := (X : C) (π : (const J).obj X ⟶ F) @[simp] lemma cone.w {F : J ⥤ C} (c : cone F) {j j' : J} (f : j ⟶ j') : c.π.app j ≫ F.map f = c.π.app j' := by convert ←(c.π.naturality f).symm; apply id_comp /-- A `c : cocone F` is * an object `c.X` and * a natural transformation `c.ι : F ⟶ c.X` from `F` to the constant `c.X` functor. `cocone F` is equivalent, in the obvious way, to `Σ X, F.cocones.obj X`. -/ structure cocone (F : J ⥤ C) := (X : C) (ι : F ⟶ (const J).obj X) @[simp] lemma cocone.w {F : J ⥤ C} (c : cocone F) {j j' : J} (f : j ⟶ j') : F.map f ≫ c.ι.app j' = c.ι.app j := by convert ←(c.ι.naturality f); apply comp_id variables {F : J ⥤ C} namespace cone @[simp] def extensions (c : cone F) : yoneda.obj c.X ⟶ F.cones := { app := λ X f, ((const J).map f) ≫ c.π } /-- A map to the vertex of a cone induces a cone by composition. -/ @[simp] def extend (c : cone F) {X : C} (f : X ⟶ c.X) : cone F := { X := X, π := c.extensions.app (op X) f } @[simp] lemma extend_π (c : cone F) {X : Cᵒᵖ} (f : unop X ⟶ c.X) : (extend c f).π = c.extensions.app X f := rfl def whisker {K : Type v} [small_category K] (E : K ⥤ J) (c : cone F) : cone (E ⋙ F) := { X := c.X, π := whisker_left E c.π } @[simp] lemma whisker_π_app (c : cone F) {K : Type v} [small_category K] (E : K ⥤ J) (k : K) : (c.whisker E).π.app k = (c.π).app (E.obj k) := rfl section omit 𝒞 variables {m : Type v → Type v} variables (hom : ∀ {α β : Type v}, m α → m β → (α → β) → Prop) variables [h : concrete_category @hom] include h @[simp] lemma naturality_bundled {G : J ⥤ bundled m} (s : cone G) {j j' : J} (f : j ⟶ j') (x : s.X) : (G.map f) ((s.π.app j) x) = (s.π.app j') x := congr_fun (congr_arg (λ k : s.X ⟶ G.obj j', (k : s.X → G.obj j')) (s.π.naturality f).symm) x end end cone namespace cocone @[simp] def extensions (c : cocone F) : coyoneda.obj (op c.X) ⟶ F.cocones := { app := λ X f, c.ι ≫ ((const J).map f) } /-- A map from the vertex of a cocone induces a cocone by composition. -/ @[simp] def extend (c : cocone F) {X : C} (f : c.X ⟶ X) : cocone F := { X := X, ι := c.extensions.app X f } @[simp] lemma extend_ι (c : cocone F) {X : C} (f : c.X ⟶ X) : (extend c f).ι = c.extensions.app X f := rfl def whisker {K : Type v} [small_category K] (E : K ⥤ J) (c : cocone F) : cocone (E ⋙ F) := { X := c.X, ι := whisker_left E c.ι } @[simp] lemma whisker_ι_app (c : cocone F) {K : Type v} [small_category K] (E : K ⥤ J) (k : K) : (c.whisker E).ι.app k = (c.ι).app (E.obj k) := rfl section omit 𝒞 variables {m : Type v → Type v} variables (hom : ∀ {α β : Type v}, m α → m β → (α → β) → Prop) variables [h : concrete_category @hom] include h @[simp] lemma naturality_bundled {G : J ⥤ bundled m} (s : cocone G) {j j' : J} (f : j ⟶ j') (x : G.obj j) : (s.ι.app j') ((G.map f) x) = (s.ι.app j) x := congr_fun (congr_arg (λ k : G.obj j ⟶ s.X, (k : G.obj j → s.X)) (s.ι.naturality f)) x end end cocone structure cone_morphism (A B : cone F) := (hom : A.X ⟶ B.X) (w' : ∀ j : J, hom ≫ B.π.app j = A.π.app j . obviously) restate_axiom cone_morphism.w' attribute [simp] cone_morphism.w @[extensionality] lemma cone_morphism.ext {A B : cone F} {f g : cone_morphism A B} (w : f.hom = g.hom) : f = g := by cases f; cases g; simpa using w instance cone.category : category.{v+1} (cone F) := { hom := λ A B, cone_morphism A B, comp := λ X Y Z f g, { hom := f.hom ≫ g.hom, w' := by intro j; rw [assoc, g.w, f.w] }, id := λ B, { hom := 𝟙 B.X } } namespace cones @[simp] lemma id.hom (c : cone F) : (𝟙 c : cone_morphism c c).hom = 𝟙 (c.X) := rfl @[simp] lemma comp.hom {c d e : cone F} (f : c ⟶ d) (g : d ⟶ e) : (f ≫ g).hom = f.hom ≫ g.hom := rfl /-- To give an isomorphism between cones, it suffices to give an isomorphism between their vertices which commutes with the cone maps. -/ @[extensionality] def ext {c c' : cone F} (φ : c.X ≅ c'.X) (w : ∀ j, c.π.app j = φ.hom ≫ c'.π.app j) : c ≅ c' := { hom := { hom := φ.hom }, inv := { hom := φ.inv, w' := λ j, φ.inv_comp_eq.mpr (w j) } } def postcompose {G : J ⥤ C} (α : F ⟶ G) : cone F ⥤ cone G := { obj := λ c, { X := c.X, π := c.π ≫ α }, map := λ c₁ c₂ f, { hom := f.hom, w' := by intro; erw ← category.assoc; simp [-category.assoc] } } @[simp] lemma postcompose_obj_X {G : J ⥤ C} (α : F ⟶ G) (c : cone F) : ((postcompose α).obj c).X = c.X := rfl @[simp] lemma postcompose_obj_π {G : J ⥤ C} (α : F ⟶ G) (c : cone F) : ((postcompose α).obj c).π = c.π ≫ α := rfl @[simp] lemma postcompose_map_hom {G : J ⥤ C} (α : F ⟶ G) {c₁ c₂ : cone F} (f : c₁ ⟶ c₂): ((postcompose α).map f).hom = f.hom := rfl def forget : cone F ⥤ C := { obj := λ t, t.X, map := λ s t f, f.hom } @[simp] lemma forget_obj {t : cone F} : forget.obj t = t.X := rfl @[simp] lemma forget_map {s t : cone F} {f : s ⟶ t} : forget.map f = f.hom := rfl section variables {D : Sort u'} [𝒟 : category.{v+1} D] include 𝒟 @[simp] def functoriality (G : C ⥤ D) : cone F ⥤ cone (F ⋙ G) := { obj := λ A, { X := G.obj A.X, π := { app := λ j, G.map (A.π.app j), naturality' := by intros; erw ←G.map_comp; tidy } }, map := λ X Y f, { hom := G.map f.hom, w' := by intros; rw [←functor.map_comp, f.w] } } end end cones structure cocone_morphism (A B : cocone F) := (hom : A.X ⟶ B.X) (w' : ∀ j : J, A.ι.app j ≫ hom = B.ι.app j . obviously) restate_axiom cocone_morphism.w' attribute [simp] cocone_morphism.w @[extensionality] lemma cocone_morphism.ext {A B : cocone F} {f g : cocone_morphism A B} (w : f.hom = g.hom) : f = g := by cases f; cases g; simpa using w instance cocone.category : category.{v+1} (cocone F) := { hom := λ A B, cocone_morphism A B, comp := λ _ _ _ f g, { hom := f.hom ≫ g.hom, w' := by intro j; rw [←assoc, f.w, g.w] }, id := λ B, { hom := 𝟙 B.X } } namespace cocones @[simp] lemma id.hom (c : cocone F) : (𝟙 c : cocone_morphism c c).hom = 𝟙 (c.X) := rfl @[simp] lemma comp.hom {c d e : cocone F} (f : c ⟶ d) (g : d ⟶ e) : (f ≫ g).hom = f.hom ≫ g.hom := rfl /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ @[extensionality] def ext {c c' : cocone F} (φ : c.X ≅ c'.X) (w : ∀ j, c.ι.app j ≫ φ.hom = c'.ι.app j) : c ≅ c' := { hom := { hom := φ.hom }, inv := { hom := φ.inv, w' := λ j, φ.comp_inv_eq.mpr (w j).symm } } def precompose {G : J ⥤ C} (α : G ⟶ F) : cocone F ⥤ cocone G := { obj := λ c, { X := c.X, ι := α ≫ c.ι }, map := λ c₁ c₂ f, { hom := f.hom } } @[simp] lemma precompose_obj_X {G : J ⥤ C} (α : G ⟶ F) (c : cocone F) : ((precompose α).obj c).X = c.X := rfl @[simp] lemma precompose_obj_ι {G : J ⥤ C} (α : G ⟶ F) (c : cocone F) : ((precompose α).obj c).ι = α ≫ c.ι := rfl @[simp] lemma precompose_map_hom {G : J ⥤ C} (α : G ⟶ F) {c₁ c₂ : cocone F} (f : c₁ ⟶ c₂) : ((precompose α).map f).hom = f.hom := rfl def forget : cocone F ⥤ C := { obj := λ t, t.X, map := λ s t f, f.hom } @[simp] lemma forget_obj {t : cocone F} : forget.obj t = t.X := rfl @[simp] lemma forget_map {s t : cocone F} {f : s ⟶ t} : forget.map f = f.hom := rfl section variables {D : Sort u'} [𝒟 : category.{v+1} D] include 𝒟 @[simp] def functoriality (G : C ⥤ D) : cocone F ⥤ cocone (F ⋙ G) := { obj := λ A, { X := G.obj A.X, ι := { app := λ j, G.map (A.ι.app j), naturality' := by intros; erw ←G.map_comp; tidy } }, map := λ _ _ f, { hom := G.map f.hom, w' := by intros; rw [←functor.map_comp, cocone_morphism.w] } } end end cocones end limits namespace functor variables {D : Sort u'} [category.{v+1} D] variables {F : J ⥤ C} {G : J ⥤ C} (H : C ⥤ D) open category_theory.limits /-- The image of a cone in C under a functor G : C ⥤ D is a cone in D. -/ def map_cone (c : cone F) : cone (F ⋙ H) := (cones.functoriality H).obj c /-- The image of a cocone in C under a functor G : C ⥤ D is a cocone in D. -/ def map_cocone (c : cocone F) : cocone (F ⋙ H) := (cocones.functoriality H).obj c def map_cone_morphism {c c' : cone F} (f : cone_morphism c c') : cone_morphism (H.map_cone c) (H.map_cone c') := (cones.functoriality H).map f def map_cocone_morphism {c c' : cocone F} (f : cocone_morphism c c') : cocone_morphism (H.map_cocone c) (H.map_cocone c') := (cocones.functoriality H).map f @[simp] lemma map_cone_π (c : cone F) (j : J) : (map_cone H c).π.app j = H.map (c.π.app j) := rfl @[simp] lemma map_cocone_ι (c : cocone F) (j : J) : (map_cocone H c).ι.app j = H.map (c.ι.app j) := rfl end functor end category_theory namespace category_theory.limits variables {F : J ⥤ Cᵒᵖ} def cone_of_cocone_left_op (c : cocone F.left_op) : cone F := { X := op c.X, π := nat_trans.right_op (c.ι ≫ (const.op_obj_unop (op c.X)).hom) } @[simp] lemma cone_of_cocone_left_op_X (c : cocone F.left_op) : (cone_of_cocone_left_op c).X = op c.X := rfl @[simp] lemma cone_of_cocone_left_op_π_app (c : cocone F.left_op) (j) : (cone_of_cocone_left_op c).π.app j = (c.ι.app (op j)).op := by { dsimp [cone_of_cocone_left_op], simp } def cocone_left_op_of_cone (c : cone F) : cocone (F.left_op) := { X := unop c.X, ι := nat_trans.left_op c.π } @[simp] lemma cocone_left_op_of_cone_X (c : cone F) : (cocone_left_op_of_cone c).X = unop c.X := rfl @[simp] lemma cocone_left_op_of_cone_ι_app (c : cone F) (j) : (cocone_left_op_of_cone c).ι.app j = (c.π.app (unop j)).unop := by { dsimp [cocone_left_op_of_cone], simp } def cocone_of_cone_left_op (c : cone F.left_op) : cocone F := { X := op c.X, ι := nat_trans.right_op ((const.op_obj_unop (op c.X)).hom ≫ c.π) } @[simp] lemma cocone_of_cone_left_op_X (c : cone F.left_op) : (cocone_of_cone_left_op c).X = op c.X := rfl @[simp] lemma cocone_of_cone_left_op_ι_app (c : cone F.left_op) (j) : (cocone_of_cone_left_op c).ι.app j = (c.π.app (op j)).op := by { dsimp [cocone_of_cone_left_op], simp } def cone_left_op_of_cocone (c : cocone F) : cone (F.left_op) := { X := unop c.X, π := nat_trans.left_op c.ι } @[simp] lemma cone_left_op_of_cocone_X (c : cocone F) : (cone_left_op_of_cocone c).X = unop c.X := rfl @[simp] lemma cone_left_op_of_cocone_π_app (c : cocone F) (j) : (cone_left_op_of_cocone c).π.app j = (c.ι.app (unop j)).unop := by { dsimp [cone_left_op_of_cocone], simp } end category_theory.limits
1243071ff68256dde08f192280e9bb173cfbfb91
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
/src/data/nat/fact.lean
d82a1573c4ad11c3805f2b2ff910105ec7a16d33
[ "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
2,803
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, Floris van Doorn -/ import data.nat.basic /-! # The factorial function -/ namespace nat variables {m n : ℕ} /-- `nat.fact n` is the factorial of `n`. -/ @[simp] def fact : nat → nat | 0 := 1 | (succ n) := succ n * fact n @[simp] theorem fact_zero : fact 0 = 1 := rfl @[simp] theorem fact_succ (n) : fact (succ n) = succ n * fact n := rfl @[simp] theorem fact_one : fact 1 = 1 := rfl theorem fact_pos : ∀ n, 0 < fact n | 0 := zero_lt_one | (succ n) := mul_pos (succ_pos _) (fact_pos n) theorem fact_ne_zero (n : ℕ) : fact n ≠ 0 := ne_of_gt (fact_pos _) theorem fact_dvd_fact {m n} (h : m ≤ n) : fact m ∣ fact n := begin induction n with n IH; simp, { have := eq_zero_of_le_zero h, subst m, simp }, { cases eq_or_lt_of_le h with he hl, { subst m, simp }, { apply dvd_mul_of_dvd_right (IH (le_of_lt_succ hl)) } } end theorem dvd_fact : ∀ {m n}, 0 < m → m ≤ n → m ∣ fact n | (succ m) n _ h := dvd_of_mul_right_dvd (fact_dvd_fact h) theorem fact_le {m n} (h : m ≤ n) : fact m ≤ fact n := le_of_dvd (fact_pos _) (fact_dvd_fact h) lemma fact_mul_pow_le_fact : ∀ {m n : ℕ}, m.fact * m.succ ^ n ≤ (m + n).fact | m 0 := by simp | m (n+1) := by rw [← add_assoc, nat.fact_succ, mul_comm (nat.succ _), pow_succ', ← mul_assoc]; exact mul_le_mul fact_mul_pow_le_fact (nat.succ_le_succ (nat.le_add_right _ _)) (nat.zero_le _) (nat.zero_le _) lemma monotone_fact : monotone fact := λ n m, fact_le lemma fact_lt (h0 : 0 < n) : n.fact < m.fact ↔ n < m := begin split; intro h, { rw [← not_le], intro hmn, apply not_le_of_lt h (fact_le hmn) }, { have : ∀(n : ℕ), 0 < n → n.fact < n.succ.fact, { intros k hk, rw [fact_succ, succ_mul, lt_add_iff_pos_left], apply mul_pos hk (fact_pos k) }, induction h generalizing h0, { exact this _ h0, }, { refine lt_trans (h_ih h0) (this _ _), exact lt_trans h0 (lt_of_succ_le h_a) }} end lemma one_lt_fact : 1 < n.fact ↔ 1 < n := by { convert fact_lt _, refl, exact one_pos } lemma fact_eq_one : n.fact = 1 ↔ n ≤ 1 := begin split; intro h, { rw [← not_lt, ← one_lt_fact, h], apply lt_irrefl }, { cases h with h h, refl, cases h, refl } end lemma fact_inj (h0 : 1 < n.fact) : n.fact = m.fact ↔ n = m := begin split; intro h, { rcases lt_trichotomy n m with hnm|hnm|hnm, { exfalso, rw [← fact_lt, h] at hnm, exact lt_irrefl _ hnm, rw [one_lt_fact] at h0, exact lt_trans one_pos h0 }, { exact hnm }, { exfalso, rw [← fact_lt, h] at hnm, exact lt_irrefl _ hnm, rw [h, one_lt_fact] at h0, exact lt_trans one_pos h0 }}, { rw h } end end nat
70ca24a89ab75a9df579de9df91bef003871dfd4
63abd62053d479eae5abf4951554e1064a4c45b4
/src/data/complex/basic.lean
c6465d287093b17492d0471b8d0df7ed347a03ca
[ "Apache-2.0" ]
permissive
Lix0120/mathlib
0020745240315ed0e517cbf32e738d8f9811dd80
e14c37827456fc6707f31b4d1d16f1f3a3205e91
refs/heads/master
1,673,102,855,024
1,604,151,044,000
1,604,151,044,000
308,930,245
0
0
Apache-2.0
1,604,164,710,000
1,604,163,547,000
null
UTF-8
Lean
false
false
20,808
lean
/- Copyright (c) 2017 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Mario Carneiro -/ import data.real.basic open_locale big_operators /-! # The complex numbers The complex numbers are modelled as ℝ^2 in the obvious way. -/ /-! ### Definition and basic arithmmetic -/ /-- Complex numbers consist of two `real`s: a real part `re` and an imaginary part `im`. -/ structure complex : Type := (re : ℝ) (im : ℝ) notation `ℂ` := complex namespace complex noncomputable instance : decidable_eq ℂ := classical.dec_eq _ /-- The equivalence between the complex numbers and `ℝ × ℝ`. -/ def equiv_real_prod : ℂ ≃ (ℝ × ℝ) := { to_fun := λ z, ⟨z.re, z.im⟩, inv_fun := λ p, ⟨p.1, p.2⟩, left_inv := λ ⟨x, y⟩, rfl, right_inv := λ ⟨x, y⟩, rfl } @[simp] theorem equiv_real_prod_apply (z : ℂ) : equiv_real_prod z = (z.re, z.im) := rfl theorem equiv_real_prod_symm_re (x y : ℝ) : (equiv_real_prod.symm (x, y)).re = x := rfl theorem equiv_real_prod_symm_im (x y : ℝ) : (equiv_real_prod.symm (x, y)).im = y := rfl @[simp] theorem eta : ∀ z : ℂ, complex.mk z.re z.im = z | ⟨a, b⟩ := rfl @[ext] theorem ext : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w | ⟨zr, zi⟩ ⟨_, _⟩ rfl rfl := rfl theorem ext_iff {z w : ℂ} : z = w ↔ z.re = w.re ∧ z.im = w.im := ⟨λ H, by simp [H], and.rec ext⟩ instance : has_coe ℝ ℂ := ⟨λ r, ⟨r, 0⟩⟩ @[simp, norm_cast] lemma of_real_re (r : ℝ) : (r : ℂ).re = r := rfl @[simp, norm_cast] lemma of_real_im (r : ℝ) : (r : ℂ).im = 0 := rfl @[simp, norm_cast] theorem of_real_inj {z w : ℝ} : (z : ℂ) = w ↔ z = w := ⟨congr_arg re, congr_arg _⟩ instance : has_zero ℂ := ⟨(0 : ℝ)⟩ instance : inhabited ℂ := ⟨0⟩ @[simp] lemma zero_re : (0 : ℂ).re = 0 := rfl @[simp] lemma zero_im : (0 : ℂ).im = 0 := rfl @[simp, norm_cast] lemma of_real_zero : ((0 : ℝ) : ℂ) = 0 := rfl @[simp] theorem of_real_eq_zero {z : ℝ} : (z : ℂ) = 0 ↔ z = 0 := of_real_inj theorem of_real_ne_zero {z : ℝ} : (z : ℂ) ≠ 0 ↔ z ≠ 0 := not_congr of_real_eq_zero instance : has_one ℂ := ⟨(1 : ℝ)⟩ @[simp] lemma one_re : (1 : ℂ).re = 1 := rfl @[simp] lemma one_im : (1 : ℂ).im = 0 := rfl @[simp, norm_cast] lemma of_real_one : ((1 : ℝ) : ℂ) = 1 := rfl instance : has_add ℂ := ⟨λ z w, ⟨z.re + w.re, z.im + w.im⟩⟩ @[simp] lemma add_re (z w : ℂ) : (z + w).re = z.re + w.re := rfl @[simp] lemma add_im (z w : ℂ) : (z + w).im = z.im + w.im := rfl @[simp] lemma bit0_re (z : ℂ) : (bit0 z).re = bit0 z.re := rfl @[simp] lemma bit1_re (z : ℂ) : (bit1 z).re = bit1 z.re := rfl @[simp] lemma bit0_im (z : ℂ) : (bit0 z).im = bit0 z.im := eq.refl _ @[simp] lemma bit1_im (z : ℂ) : (bit1 z).im = bit0 z.im := add_zero _ @[simp, norm_cast] lemma of_real_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s := ext_iff.2 $ by simp @[simp, norm_cast] lemma of_real_bit0 (r : ℝ) : ((bit0 r : ℝ) : ℂ) = bit0 r := ext_iff.2 $ by simp [bit0] @[simp, norm_cast] lemma of_real_bit1 (r : ℝ) : ((bit1 r : ℝ) : ℂ) = bit1 r := ext_iff.2 $ by simp [bit1] instance : has_neg ℂ := ⟨λ z, ⟨-z.re, -z.im⟩⟩ @[simp] lemma neg_re (z : ℂ) : (-z).re = -z.re := rfl @[simp] lemma neg_im (z : ℂ) : (-z).im = -z.im := rfl @[simp, norm_cast] lemma of_real_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r := ext_iff.2 $ by simp instance : has_mul ℂ := ⟨λ z w, ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩ @[simp] lemma mul_re (z w : ℂ) : (z * w).re = z.re * w.re - z.im * w.im := rfl @[simp] lemma mul_im (z w : ℂ) : (z * w).im = z.re * w.im + z.im * w.re := rfl @[simp, norm_cast] lemma of_real_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = r * s := ext_iff.2 $ by simp lemma smul_re (r : ℝ) (z : ℂ) : (↑r * z).re = r * z.re := by simp lemma smul_im (r : ℝ) (z : ℂ) : (↑r * z).im = r * z.im := by simp lemma of_real_smul (r : ℝ) (z : ℂ) : (↑r * z) = ⟨r * z.re, r * z.im⟩ := ext (smul_re _ _) (smul_im _ _) /-! ### The imaginary unit, `I` -/ /-- The imaginary unit. -/ def I : ℂ := ⟨0, 1⟩ @[simp] lemma I_re : I.re = 0 := rfl @[simp] lemma I_im : I.im = 1 := rfl @[simp] lemma I_mul_I : I * I = -1 := ext_iff.2 $ by simp lemma I_mul (z : ℂ) : I * z = ⟨-z.im, z.re⟩ := ext_iff.2 $ by simp lemma I_ne_zero : (I : ℂ) ≠ 0 := mt (congr_arg im) zero_ne_one.symm lemma mk_eq_add_mul_I (a b : ℝ) : complex.mk a b = a + b * I := ext_iff.2 $ by simp @[simp] lemma re_add_im (z : ℂ) : (z.re : ℂ) + z.im * I = z := ext_iff.2 $ by simp /-! ### Commutative ring instance and lemmas -/ instance : comm_ring ℂ := by refine { zero := 0, add := (+), neg := has_neg.neg, one := 1, mul := (*), ..}; { intros, apply ext_iff.2; split; simp; ring } instance re.is_add_group_hom : is_add_group_hom complex.re := { map_add := complex.add_re } instance im.is_add_group_hom : is_add_group_hom complex.im := { map_add := complex.add_im } @[simp] lemma I_pow_bit0 (n : ℕ) : I ^ (bit0 n) = (-1) ^ n := by rw [pow_bit0', I_mul_I] @[simp] lemma I_pow_bit1 (n : ℕ) : I ^ (bit1 n) = (-1) ^ n * I := by rw [pow_bit1', I_mul_I] /-! ### Complex conjugation -/ /-- The complex conjugate. -/ def conj : ℂ →+* ℂ := begin refine_struct { to_fun := λ z : ℂ, (⟨z.re, -z.im⟩ : ℂ), .. }; { intros, ext; simp [add_comm], }, end @[simp] lemma conj_re (z : ℂ) : (conj z).re = z.re := rfl @[simp] lemma conj_im (z : ℂ) : (conj z).im = -z.im := rfl @[simp] lemma conj_of_real (r : ℝ) : conj r = r := ext_iff.2 $ by simp [conj] @[simp] lemma conj_I : conj I = -I := ext_iff.2 $ by simp @[simp] lemma conj_bit0 (z : ℂ) : conj (bit0 z) = bit0 (conj z) := ext_iff.2 $ by simp [bit0] @[simp] lemma conj_bit1 (z : ℂ) : conj (bit1 z) = bit1 (conj z) := ext_iff.2 $ by simp [bit0] @[simp] lemma conj_neg_I : conj (-I) = I := ext_iff.2 $ by simp @[simp] lemma conj_conj (z : ℂ) : conj (conj z) = z := ext_iff.2 $ by simp lemma conj_involutive : function.involutive conj := conj_conj lemma conj_bijective : function.bijective conj := conj_involutive.bijective lemma conj_inj {z w : ℂ} : conj z = conj w ↔ z = w := conj_bijective.1.eq_iff @[simp] lemma conj_eq_zero {z : ℂ} : conj z = 0 ↔ z = 0 := by simpa using @conj_inj z 0 lemma eq_conj_iff_real {z : ℂ} : conj z = z ↔ ∃ r : ℝ, z = r := ⟨λ h, ⟨z.re, ext rfl $ eq_zero_of_neg_eq (congr_arg im h)⟩, λ ⟨h, e⟩, by rw [e, conj_of_real]⟩ lemma eq_conj_iff_re {z : ℂ} : conj z = z ↔ (z.re : ℂ) = z := eq_conj_iff_real.trans ⟨by rintro ⟨r, rfl⟩; simp, λ h, ⟨_, h.symm⟩⟩ /-! ### Norm squared -/ /-- The norm squared function. -/ @[pp_nodot] def norm_sq (z : ℂ) : ℝ := z.re * z.re + z.im * z.im @[simp] lemma norm_sq_of_real (r : ℝ) : norm_sq r = r * r := by simp [norm_sq] @[simp] lemma norm_sq_zero : norm_sq 0 = 0 := by simp [norm_sq] @[simp] lemma norm_sq_one : norm_sq 1 = 1 := by simp [norm_sq] @[simp] lemma norm_sq_I : norm_sq I = 1 := by simp [norm_sq] lemma norm_sq_nonneg (z : ℂ) : 0 ≤ norm_sq z := add_nonneg (mul_self_nonneg _) (mul_self_nonneg _) @[simp] lemma norm_sq_eq_zero {z : ℂ} : norm_sq z = 0 ↔ z = 0 := ⟨λ h, ext (eq_zero_of_mul_self_add_mul_self_eq_zero h) (eq_zero_of_mul_self_add_mul_self_eq_zero $ (add_comm _ _).trans h), λ h, h.symm ▸ norm_sq_zero⟩ @[simp] lemma norm_sq_pos {z : ℂ} : 0 < norm_sq z ↔ z ≠ 0 := by rw [lt_iff_le_and_ne, ne, eq_comm]; simp [norm_sq_nonneg] @[simp] lemma norm_sq_neg (z : ℂ) : norm_sq (-z) = norm_sq z := by simp [norm_sq] @[simp] lemma norm_sq_conj (z : ℂ) : norm_sq (conj z) = norm_sq z := by simp [norm_sq] @[simp] lemma norm_sq_mul (z w : ℂ) : norm_sq (z * w) = norm_sq z * norm_sq w := by dsimp [norm_sq]; ring lemma norm_sq_add (z w : ℂ) : norm_sq (z + w) = norm_sq z + norm_sq w + 2 * (z * conj w).re := by dsimp [norm_sq]; ring lemma re_sq_le_norm_sq (z : ℂ) : z.re * z.re ≤ norm_sq z := le_add_of_nonneg_right (mul_self_nonneg _) lemma im_sq_le_norm_sq (z : ℂ) : z.im * z.im ≤ norm_sq z := le_add_of_nonneg_left (mul_self_nonneg _) theorem mul_conj (z : ℂ) : z * conj z = norm_sq z := ext_iff.2 $ by simp [norm_sq, mul_comm, sub_eq_neg_add, add_comm] theorem add_conj (z : ℂ) : z + conj z = (2 * z.re : ℝ) := ext_iff.2 $ by simp [two_mul] /-- The coercion `ℝ → ℂ` as a `ring_hom`. -/ def of_real : ℝ →+* ℂ := ⟨coe, of_real_one, of_real_mul, of_real_zero, of_real_add⟩ @[simp] lemma of_real_eq_coe (r : ℝ) : of_real r = r := rfl @[simp] lemma I_sq : I ^ 2 = -1 := by rw [pow_two, I_mul_I] @[simp] lemma sub_re (z w : ℂ) : (z - w).re = z.re - w.re := rfl @[simp] lemma sub_im (z w : ℂ) : (z - w).im = z.im - w.im := rfl @[simp, norm_cast] lemma of_real_sub (r s : ℝ) : ((r - s : ℝ) : ℂ) = r - s := ext_iff.2 $ by simp @[simp, norm_cast] lemma of_real_pow (r : ℝ) (n : ℕ) : ((r ^ n : ℝ) : ℂ) = r ^ n := by induction n; simp [*, of_real_mul, pow_succ] theorem sub_conj (z : ℂ) : z - conj z = (2 * z.im : ℝ) * I := ext_iff.2 $ by simp [two_mul, sub_eq_add_neg] lemma norm_sq_sub (z w : ℂ) : norm_sq (z - w) = norm_sq z + norm_sq w - 2 * (z * conj w).re := by rw [sub_eq_add_neg, norm_sq_add]; simp [-mul_re, add_comm, add_left_comm, sub_eq_add_neg] /-! ### Inversion -/ noncomputable instance : has_inv ℂ := ⟨λ z, conj z * ((norm_sq z)⁻¹:ℝ)⟩ theorem inv_def (z : ℂ) : z⁻¹ = conj z * ((norm_sq z)⁻¹:ℝ) := rfl @[simp] lemma inv_re (z : ℂ) : (z⁻¹).re = z.re / norm_sq z := by simp [inv_def, division_def] @[simp] lemma inv_im (z : ℂ) : (z⁻¹).im = -z.im / norm_sq z := by simp [inv_def, division_def] @[simp, norm_cast] lemma of_real_inv (r : ℝ) : ((r⁻¹ : ℝ) : ℂ) = r⁻¹ := ext_iff.2 $ begin simp, by_cases r = 0, { simp [h] }, { rw [← div_div_eq_div_mul, div_self h, one_div] }, end protected lemma inv_zero : (0⁻¹ : ℂ) = 0 := by rw [← of_real_zero, ← of_real_inv, inv_zero] protected theorem mul_inv_cancel {z : ℂ} (h : z ≠ 0) : z * z⁻¹ = 1 := by rw [inv_def, ← mul_assoc, mul_conj, ← of_real_mul, mul_inv_cancel (mt norm_sq_eq_zero.1 h), of_real_one] /-! ### Field instance and lemmas -/ noncomputable instance : field ℂ := { inv := has_inv.inv, exists_pair_ne := ⟨0, 1, mt (congr_arg re) zero_ne_one⟩, mul_inv_cancel := @complex.mul_inv_cancel, inv_zero := complex.inv_zero, ..complex.comm_ring } @[simp] lemma I_fpow_bit0 (n : ℤ) : I ^ (bit0 n) = (-1) ^ n := by rw [fpow_bit0', I_mul_I] @[simp] lemma I_fpow_bit1 (n : ℤ) : I ^ (bit1 n) = (-1) ^ n * I := by rw [fpow_bit1', I_mul_I] lemma div_re (z w : ℂ) : (z / w).re = z.re * w.re / norm_sq w + z.im * w.im / norm_sq w := by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg] lemma div_im (z w : ℂ) : (z / w).im = z.im * w.re / norm_sq w - z.re * w.im / norm_sq w := by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm] @[simp, norm_cast] lemma of_real_div (r s : ℝ) : ((r / s : ℝ) : ℂ) = r / s := of_real.map_div r s @[simp, norm_cast] lemma of_real_fpow (r : ℝ) (n : ℤ) : ((r ^ n : ℝ) : ℂ) = (r : ℂ) ^ n := of_real.map_fpow r n @[simp] lemma div_I (z : ℂ) : z / I = -(z * I) := (div_eq_iff_mul_eq I_ne_zero).2 $ by simp [mul_assoc] @[simp] lemma inv_I : I⁻¹ = -I := by simp [inv_eq_one_div] @[simp] lemma norm_sq_inv (z : ℂ) : norm_sq z⁻¹ = (norm_sq z)⁻¹ := if h : z = 0 then by simp [h] else mul_right_cancel' (mt norm_sq_eq_zero.1 h) $ by rw [← norm_sq_mul]; simp [h, -norm_sq_mul] @[simp] lemma norm_sq_div (z w : ℂ) : norm_sq (z / w) = norm_sq z / norm_sq w := by rw [division_def, norm_sq_mul, norm_sq_inv]; refl /-! ### Cast lemmas -/ @[simp, norm_cast] theorem of_real_nat_cast (n : ℕ) : ((n : ℝ) : ℂ) = n := of_real.map_nat_cast n @[simp, norm_cast] lemma nat_cast_re (n : ℕ) : (n : ℂ).re = n := by rw [← of_real_nat_cast, of_real_re] @[simp, norm_cast] lemma nat_cast_im (n : ℕ) : (n : ℂ).im = 0 := by rw [← of_real_nat_cast, of_real_im] @[simp, norm_cast] theorem of_real_int_cast (n : ℤ) : ((n : ℝ) : ℂ) = n := of_real.map_int_cast n @[simp, norm_cast] lemma int_cast_re (n : ℤ) : (n : ℂ).re = n := by rw [← of_real_int_cast, of_real_re] @[simp, norm_cast] lemma int_cast_im (n : ℤ) : (n : ℂ).im = 0 := by rw [← of_real_int_cast, of_real_im] @[simp, norm_cast] theorem of_real_rat_cast (n : ℚ) : ((n : ℝ) : ℂ) = n := of_real.map_rat_cast n @[simp, norm_cast] lemma rat_cast_re (q : ℚ) : (q : ℂ).re = q := by rw [← of_real_rat_cast, of_real_re] @[simp, norm_cast] lemma rat_cast_im (q : ℚ) : (q : ℂ).im = 0 := by rw [← of_real_rat_cast, of_real_im] /-! ### Characteristic zero -/ instance char_zero_complex : char_zero ℂ := char_zero_of_inj_zero $ λ n h, by rwa [← of_real_nat_cast, of_real_eq_zero, nat.cast_eq_zero] at h theorem re_eq_add_conj (z : ℂ) : (z.re : ℂ) = (z + conj z) / 2 := by rw [add_conj]; simp; rw [mul_div_cancel_left (z.re:ℂ) two_ne_zero'] /-! ### Absolute value -/ /-- The complex absolute value function, defined as the square root of the norm squared. -/ @[pp_nodot] noncomputable def abs (z : ℂ) : ℝ := (norm_sq z).sqrt local notation `abs'` := _root_.abs @[simp, norm_cast] lemma abs_of_real (r : ℝ) : abs r = abs' r := by simp [abs, norm_sq_of_real, real.sqrt_mul_self_eq_abs] lemma abs_of_nonneg {r : ℝ} (h : 0 ≤ r) : abs r = r := (abs_of_real _).trans (abs_of_nonneg h) lemma abs_of_nat (n : ℕ) : complex.abs n = n := calc complex.abs n = complex.abs (n:ℝ) : by rw [of_real_nat_cast] ... = _ : abs_of_nonneg (nat.cast_nonneg n) lemma mul_self_abs (z : ℂ) : abs z * abs z = norm_sq z := real.mul_self_sqrt (norm_sq_nonneg _) @[simp] lemma abs_zero : abs 0 = 0 := by simp [abs] @[simp] lemma abs_one : abs 1 = 1 := by simp [abs] @[simp] lemma abs_I : abs I = 1 := by simp [abs] @[simp] lemma abs_two : abs 2 = 2 := calc abs 2 = abs (2 : ℝ) : by rw [of_real_bit0, of_real_one] ... = (2 : ℝ) : abs_of_nonneg (by norm_num) lemma abs_nonneg (z : ℂ) : 0 ≤ abs z := real.sqrt_nonneg _ @[simp] lemma abs_eq_zero {z : ℂ} : abs z = 0 ↔ z = 0 := (real.sqrt_eq_zero $ norm_sq_nonneg _).trans norm_sq_eq_zero lemma abs_ne_zero {z : ℂ} : abs z ≠ 0 ↔ z ≠ 0 := not_congr abs_eq_zero @[simp] lemma abs_conj (z : ℂ) : abs (conj z) = abs z := by simp [abs] @[simp] lemma abs_mul (z w : ℂ) : abs (z * w) = abs z * abs w := by rw [abs, norm_sq_mul, real.sqrt_mul (norm_sq_nonneg _)]; refl lemma abs_re_le_abs (z : ℂ) : abs' z.re ≤ abs z := by rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.re) (abs_nonneg _), abs_mul_abs_self, mul_self_abs]; apply re_sq_le_norm_sq lemma abs_im_le_abs (z : ℂ) : abs' z.im ≤ abs z := by rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.im) (abs_nonneg _), abs_mul_abs_self, mul_self_abs]; apply im_sq_le_norm_sq lemma re_le_abs (z : ℂ) : z.re ≤ abs z := (abs_le.1 (abs_re_le_abs _)).2 lemma im_le_abs (z : ℂ) : z.im ≤ abs z := (abs_le.1 (abs_im_le_abs _)).2 lemma abs_add (z w : ℂ) : abs (z + w) ≤ abs z + abs w := (mul_self_le_mul_self_iff (abs_nonneg _) (add_nonneg (abs_nonneg _) (abs_nonneg _))).2 $ begin rw [mul_self_abs, add_mul_self_eq, mul_self_abs, mul_self_abs, add_right_comm, norm_sq_add, add_le_add_iff_left, mul_assoc, mul_le_mul_left (@zero_lt_two ℝ _ _)], simpa [-mul_re] using re_le_abs (z * conj w) end instance : is_absolute_value abs := { abv_nonneg := abs_nonneg, abv_eq_zero := λ _, abs_eq_zero, abv_add := abs_add, abv_mul := abs_mul } open is_absolute_value @[simp] lemma abs_abs (z : ℂ) : abs' (abs z) = abs z := _root_.abs_of_nonneg (abs_nonneg _) @[simp] lemma abs_pos {z : ℂ} : 0 < abs z ↔ z ≠ 0 := abv_pos abs @[simp] lemma abs_neg : ∀ z, abs (-z) = abs z := abv_neg abs lemma abs_sub : ∀ z w, abs (z - w) = abs (w - z) := abv_sub abs lemma abs_sub_le : ∀ a b c, abs (a - c) ≤ abs (a - b) + abs (b - c) := abv_sub_le abs @[simp] theorem abs_inv : ∀ z, abs z⁻¹ = (abs z)⁻¹ := abv_inv abs @[simp] theorem abs_div : ∀ z w, abs (z / w) = abs z / abs w := abv_div abs lemma abs_abs_sub_le_abs_sub : ∀ z w, abs' (abs z - abs w) ≤ abs (z - w) := abs_abv_sub_le_abv_sub abs lemma abs_le_abs_re_add_abs_im (z : ℂ) : abs z ≤ abs' z.re + abs' z.im := by simpa [re_add_im] using abs_add z.re (z.im * I) lemma abs_re_div_abs_le_one (z : ℂ) : abs' (z.re / z.abs) ≤ 1 := if hz : z = 0 then by simp [hz, zero_le_one] else by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_re_le_abs] } lemma abs_im_div_abs_le_one (z : ℂ) : abs' (z.im / z.abs) ≤ 1 := if hz : z = 0 then by simp [hz, zero_le_one] else by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_im_le_abs] } @[simp, norm_cast] lemma abs_cast_nat (n : ℕ) : abs (n : ℂ) = n := by rw [← of_real_nat_cast, abs_of_nonneg (nat.cast_nonneg n)] lemma norm_sq_eq_abs (x : ℂ) : norm_sq x = abs x ^ 2 := by rw [abs, pow_two, real.mul_self_sqrt (norm_sq_nonneg _)] /-! ### Cauchy sequences -/ theorem is_cau_seq_re (f : cau_seq ℂ abs) : is_cau_seq abs' (λ n, (f n).re) := λ ε ε0, (f.cauchy ε0).imp $ λ i H j ij, lt_of_le_of_lt (by simpa using abs_re_le_abs (f j - f i)) (H _ ij) theorem is_cau_seq_im (f : cau_seq ℂ abs) : is_cau_seq abs' (λ n, (f n).im) := λ ε ε0, (f.cauchy ε0).imp $ λ i H j ij, lt_of_le_of_lt (by simpa using abs_im_le_abs (f j - f i)) (H _ ij) /-- The real part of a complex Cauchy sequence, as a real Cauchy sequence. -/ noncomputable def cau_seq_re (f : cau_seq ℂ abs) : cau_seq ℝ abs' := ⟨_, is_cau_seq_re f⟩ /-- The imaginary part of a complex Cauchy sequence, as a real Cauchy sequence. -/ noncomputable def cau_seq_im (f : cau_seq ℂ abs) : cau_seq ℝ abs' := ⟨_, is_cau_seq_im f⟩ lemma is_cau_seq_abs {f : ℕ → ℂ} (hf : is_cau_seq abs f) : is_cau_seq abs' (abs ∘ f) := λ ε ε0, let ⟨i, hi⟩ := hf ε ε0 in ⟨i, λ j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)⟩ /-- The limit of a Cauchy sequence of complex numbers. -/ noncomputable def lim_aux (f : cau_seq ℂ abs) : ℂ := ⟨cau_seq.lim (cau_seq_re f), cau_seq.lim (cau_seq_im f)⟩ theorem equiv_lim_aux (f : cau_seq ℂ abs) : f ≈ cau_seq.const abs (lim_aux f) := λ ε ε0, (exists_forall_ge_and (cau_seq.equiv_lim ⟨_, is_cau_seq_re f⟩ _ (half_pos ε0)) (cau_seq.equiv_lim ⟨_, is_cau_seq_im f⟩ _ (half_pos ε0))).imp $ λ i H j ij, begin cases H _ ij with H₁ H₂, apply lt_of_le_of_lt (abs_le_abs_re_add_abs_im _), dsimp [lim_aux] at *, have := add_lt_add H₁ H₂, rwa add_halves at this, end noncomputable instance : cau_seq.is_complete ℂ abs := ⟨λ f, ⟨lim_aux f, equiv_lim_aux f⟩⟩ open cau_seq lemma lim_eq_lim_im_add_lim_re (f : cau_seq ℂ abs) : lim f = ↑(lim (cau_seq_re f)) + ↑(lim (cau_seq_im f)) * I := lim_eq_of_equiv_const $ calc f ≈ _ : equiv_lim_aux f ... = cau_seq.const abs (↑(lim (cau_seq_re f)) + ↑(lim (cau_seq_im f)) * I) : cau_seq.ext (λ _, complex.ext (by simp [lim_aux, cau_seq_re]) (by simp [lim_aux, cau_seq_im])) lemma lim_re (f : cau_seq ℂ abs) : lim (cau_seq_re f) = (lim f).re := by rw [lim_eq_lim_im_add_lim_re]; simp lemma lim_im (f : cau_seq ℂ abs) : lim (cau_seq_im f) = (lim f).im := by rw [lim_eq_lim_im_add_lim_re]; simp lemma is_cau_seq_conj (f : cau_seq ℂ abs) : is_cau_seq abs (λ n, conj (f n)) := λ ε ε0, let ⟨i, hi⟩ := f.2 ε ε0 in ⟨i, λ j hj, by rw [← conj.map_sub, abs_conj]; exact hi j hj⟩ /-- The complex conjugate of a complex Cauchy sequence, as a complex Cauchy sequence. -/ noncomputable def cau_seq_conj (f : cau_seq ℂ abs) : cau_seq ℂ abs := ⟨_, is_cau_seq_conj f⟩ lemma lim_conj (f : cau_seq ℂ abs) : lim (cau_seq_conj f) = conj (lim f) := complex.ext (by simp [cau_seq_conj, (lim_re _).symm, cau_seq_re]) (by simp [cau_seq_conj, (lim_im _).symm, cau_seq_im, (lim_neg _).symm]; refl) /-- The absolute value of a complex Cauchy sequence, as a real Cauchy sequence. -/ noncomputable def cau_seq_abs (f : cau_seq ℂ abs) : cau_seq ℝ abs' := ⟨_, is_cau_seq_abs f.2⟩ lemma lim_abs (f : cau_seq ℂ abs) : lim (cau_seq_abs f) = abs (lim f) := lim_eq_of_equiv_const (λ ε ε0, let ⟨i, hi⟩ := equiv_lim f ε ε0 in ⟨i, λ j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)⟩) @[simp, norm_cast] lemma of_real_prod {α : Type*} (s : finset α) (f : α → ℝ) : ((∏ i in s, f i : ℝ) : ℂ) = ∏ i in s, (f i : ℂ) := ring_hom.map_prod of_real _ _ @[simp, norm_cast] lemma of_real_sum {α : Type*} (s : finset α) (f : α → ℝ) : ((∑ i in s, f i : ℝ) : ℂ) = ∑ i in s, (f i : ℂ) := ring_hom.map_sum of_real _ _ end complex
6a9d0a33768056d5f4bb024bbcbd50405c2d578f
43390109ab88557e6090f3245c47479c123ee500
/src/Euclid_old/tarski_6.lean
1a52def71bec207050a3ee86b833bb8b5422c4ef
[ "Apache-2.0" ]
permissive
Ja1941/xena-UROP-2018
41f0956519f94d56b8bf6834a8d39473f4923200
b111fb87f343cf79eca3b886f99ee15c1dd9884b
refs/heads/master
1,662,355,955,139
1,590,577,325,000
1,590,577,325,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
42,450
lean
import Euclid.tarski_5 open classical set namespace Euclidean_plane variables {point : Type} [Euclidean_plane point] local attribute [instance] prop_decidable theorem eleven22a {a b c p a' b' c' p' : point} : Bl a (l b p) c → Bl a' (l b' p') c' → eqa a b p a' b' p' → eqa p b c p' b' c' → eqa a b c a' b' c' := begin intros h h1 h2 h3, cases h.2.2.2 with d h4, cases exists_of_exists_unique (six11 h2.2.2.1 h2.1.symm) with a₁ ha, suffices : ∃ d₁, col b' p' d₁ ∧ (B p' b' d₁ ↔ B p b d) ∧ eqd b' d₁ b d, cases this with d₁ hd, cases seg_cons d₁ d c a₁ with c₁ hc, have h5 : eqd a d a₁ d₁, by_cases h_1 : d = b, subst d, have h_1 : b' = d₁, exact id_eqd hd.2.2, subst d₁, exact ha.2.symm.flip, have h_2 : d₁ ≠ b', intro h_2, subst d₁, exact h_1 (id_eqd hd.2.2.symm.flip), suffices : eqa a b d a' b' d₁, rw eleven4 at this, apply this.2.2.2.2 (six5 h2.1) (six5 h_1) ha.1 (six5 h_2) ha.2.symm hd.2.2.symm, by_cases h_3 : B p b d, exact (eleven13 h2.flip h_1 h_3 h_2 (hd.2.1.2 h_3)).flip, have h4 := six4.2 ⟨(four11 h4.1).2.1, h_3⟩, have h5 : ¬B p' b' d₁, intro h_4, exact h_3 (hd.2.1.1 h_4), have h6 := six4.2 ⟨(four11 hd.1).2.1, h5⟩, exact eleven10 h2 (six5 h2.1) h4.symm (six5 ha.1.2.1) h6.symm, have h6 : eqd b c b' c₁, apply (afive_seg ⟨h4.2, hc.1, h5, hc.2.symm, ha.2.symm.flip, hd.2.2.symm.flip⟩ _).flip, intro h_1, subst d, exact h.2.1 h4.1, have h7 : eqa a b c a₁ b' c₁, apply eleven3.2 ⟨a, c, a₁, c₁, six5 h2.1, six5 h3.2.1, six5 ha.1.1, _⟩, split, apply six5 (two7 h6.flip h3.2.1), refine ⟨ha.2.symm.flip, h6, _⟩, exact two11 h4.2 hc.1 h5 hc.2.symm, apply eleven10 h7 (six5 h2.1) (six5 h3.2.1) ha.1.symm, have h8 : eqa p b c p' b' c₁, by_cases h_1 : d = b, subst d, have h_1 : b' = d₁, exact id_eqd hd.2.2, subst d₁, apply (eleven13 _ h3.2.1 h4.2 (two7 hc.2.symm.flip h3.2.1) hc.1).flip, exact eleven10 h2 (six5 h2.1) (six5 h2.2.1) ha.1 (six5 h3.2.2.1), have h_2 : d₁ ≠ b', intro h_2, subst d₁, exact h_1 (id_eqd hd.2.2.symm.flip), suffices : eqa d b c d₁ b' c₁, by_cases h_3 : B p b d, exact (eleven13 this h2.2.1 h_3.symm h2.2.2.2.1 (hd.2.1.2 h_3).symm), have h8 := six4.2 ⟨(four11 h4.1).2.1, h_3⟩, have h9 : ¬B p' b' d₁, intro h_4, exact h_3 (hd.2.1.1 h_4), have h10 := six4.2 ⟨(four11 hd.1).2.1, h9⟩, exact eleven10 this h8 (six5 this.2.1) h10 (six5 this.2.2.2.1), apply eleven3.2 ⟨d, c, d₁, c₁, six5 h_1, six5 h3.2.1, six5 h_2, (six5 h7.2.2.2.1), _⟩, exact ⟨hd.2.2.symm.flip, h6, hc.2.symm⟩, have h9 : a₁ ∉ l b' p', intro h_1, apply h1.2.1, exact six20 h1.1 (six17a b' p') h_1 ha.1.1.symm (four11 (six4.1 ha.1).1).2.1, have h10 : c₁ ∉ l b' p', intro h_1, apply h9, apply six20 h1.1 h_1 hd.1 _ (or.inl hc.1.symm), apply two7 hc.2.symm.flip, intro h_2, subst d, exact h.2.2.1 h4.1, have h11 : side (l b' p') c' c₁, refine ⟨a₁, (nine5 h1 (six17a b' p') ha.1.symm).symm, _⟩, split, exact h1.1, refine ⟨h10, h9, _⟩, exact ⟨d₁, hd.1, hc.1.symm⟩, rw six17 at h, rw six17 at h10, apply eleven15b h.2.2.1 h10 h3 h11 h8, rw six17 b' p' at *, exact side.refl h1.1 h10, by_cases h_1 : B p b d, simp [h_1], cases seg_cons b' b d p' with d₁ hd, exact ⟨d₁, or.inr (or.inr hd.1.symm), hd.1, hd.2⟩, simp [h_1], have h5 : sided b p d, exact six4.2 ⟨(four11 h4.1).2.1, h_1⟩, cases exists_of_exists_unique (six11 h3.2.2.1 h5.2.1.symm) with d₁ hd, exact ⟨d₁, (four11 (six4.1 hd.1).1).2.2.1, (six4.1 hd.1.symm).2, hd.2⟩ end theorem eleven22b {a b c p a' b' c' p' : point} : side (l b p) a c → side (l b' p') a' c' → eqa a b p a' b' p' → eqa p b c p' b' c' → eqa a b c a' b' c' := begin intros h h1 h2 h3, apply eleven13 _ h2.1 (seven5 b a).1.symm h2.2.2.1 (seven5 b' a').1.symm, have h4 : Bl a (l b p) (S b a), refine ⟨(nine11 h).1, (nine11 h).2.1, _, b, (six17a b p), (seven5 b a).1⟩, intro h_1, exact (nine11 h).2.1 ((seven24 (nine11 h).1 (six17a b p)).2 h_1), have h5 : Bl a' (l b' p') (S b' a'), refine ⟨(nine11 h1).1, (nine11 h1).2.1, _, b', (six17a b' p'), (seven5 b' a').1⟩, intro h_1, exact (nine11 h1).2.1 ((seven24 (nine11 h1).1 (six17a b' p')).2 h_1), apply (eleven22a _ _ (eleven13 h2 (seven12a h2.1.symm).symm ((seven5 b a).1) (seven12a h2.2.2.1.symm).symm (seven5 b' a').1) h3), exact ((nine8 h4).2 h).symm, exact ((nine8 h5).2 h1).symm end def I (p a b c : point) : Prop := a ≠ b ∧ c ≠ b ∧ p ≠ b ∧ (B a b c ∨ ∃ x, B a x c ∧ sided b x p) theorem eleven23a {a b c p : point} : I p a b c → B a b c ∨ ∃ q, a ≠ b ∧ c ≠ b ∧ q ≠ b ∧ B a q c ∧ sided b q p := begin intro h, cases h.2.2.2, exact or.inl h_1, cases h_1 with q hq, exact or.inr ⟨q, h.1, h.2.1, hq.2.1, hq.1, hq.2⟩ end theorem eleven23b {p a b c : point} : ¬B a b c → I p a b c → a ≠ b ∧ c ≠ b ∧ p ≠ b ∧ ∃ x, B a x c ∧ sided b x p := begin intros h h1, unfold I at h1, simpa [h] using h1 end theorem I.symm {p a b c : point} : I p a b c → I p c b a := begin intro h, refine ⟨h.2.1, h.1, h.2.2.1, _⟩, cases h.2.2.2, exact or.inl h_1.symm, right, cases h_1 with x hx, exact ⟨x, hx.1.symm, hx.2⟩ end theorem eleven25 {p a b c a' c' p' : point} : I p a b c → sided b a' a → sided b c' c → sided b p' p → I p' a' b c' := begin intros h h1 h2 h3, by_cases h_1 : B a b c, exact ⟨h1.1, h2.1, h3.1, or.inl (six8 h1 h2 h_1)⟩, replace h := eleven23b h_1 h, cases h.2.2.2 with x hx, have h4 : ∃ x', B c x' a' ∧ sided b x' x, cases h1.2.2, cases pasch h_2 hx.1.symm with x' hx', refine ⟨x', hx'.1.symm, _⟩, apply six7 hx'.2.symm, intro h_3, subst x', exact h_1 (six6 hx'.1.symm h1).symm, cases nine6 h_2.symm hx.1.symm with x' hx', exact ⟨x', hx'.1.symm, (six7 hx'.2 hx.2.1).symm⟩, cases h4 with x' hx', have h5 : ∃ y, B a' y c' ∧ sided b x' y, cases h2.2.2, cases pasch h_2 hx'.1.symm with y hy, refine ⟨y, hy.1.symm, _⟩, apply (six7 hy.2.symm _).symm, intro h_3, subst y, exact h_1 (six8 h1.symm h2.symm hy.1.symm), cases nine6 h_2.symm hx'.1.symm with y hy, exact ⟨y, hy.1.symm, (six7 hy.2 hx'.2.1)⟩, cases h5 with y hy, refine ⟨h1.1, h2.1, h3.1, or.inr ⟨y, hy.1,_⟩⟩, exact hy.2.symm.trans (hx'.2.trans (hx.2.trans h3.symm)) end theorem eleven26a {a b c : point} : a ≠ b → c ≠ b → I a a b c := λ h h1, ⟨h, h1, h, or.inr ⟨a, three3 a c, six5 h⟩⟩ theorem eleven26b {a b c : point} : a ≠ b → c ≠ b → I c a b c := λ h h1, ⟨h, h1, h1, or.inr ⟨c, three1 a c, six5 h1⟩⟩ lemma eleven28 {a b c d a' b' c' : point} : cong a b c a' b' c' → col a c d → ∃ d', eqd a d a' d' ∧ eqd b d b' d' ∧ eqd c d c' d' := begin intros h h1, by_cases h_1 : a = c, subst c, have h_1 : a' = c', exact id_eqd h.2.2.symm, subst c', by_cases h_1 : col a b d, cases four14 h_1 h.1 with d' hd, exact ⟨d', hd.2.2, hd.2.1, hd.2.2⟩, have h_2 : a' ≠ b', intro h_2, subst b', exact (six26 h_1).1 (id_eqd h.1), cases six25 h_2 with p' hp, cases exists_of_exists_unique (ten16 h_1 hp h.1) with d' hd, exact ⟨d', hd.1.2.2, hd.1.2.1, hd.1.2.2⟩, cases four14 h1 h.2.2 with d' hd, exact ⟨d', hd.2.2, (four16 ⟨h1, hd, h.1, h.2.1.flip ⟩ h_1).flip, hd.2.1⟩ end def ang_le (a b c d e f : point) : Prop := ∃ p, I p d e f ∧ eqa a b c d e p theorem eleven31a {a b c d e f : point} : sided b a c → d ≠ e → f ≠ e → ang_le a b c d e f := λ h h1 h2, ⟨d, ⟨h1, h2, h1, or.inr ⟨d, three3 d f, six5 h1⟩⟩, (eleven21a h).2 (six5 h1)⟩ theorem eleven31b {a b c d e f : point} : a ≠ b → c ≠ b → d ≠ e → f ≠ e → B d e f → ang_le a b c d e f := begin intros h h1 h2 h3 h4, by_cases h_1 : col a b c, cases six1 h_1, exact ⟨f, ⟨h2, h3, h3, or.inl h4⟩, eleven21c h h1 h2 h3 h_2 h4⟩, exact eleven31a h_2 h2 h3, cases exists_of_exists_unique (six11 h h2.symm) with a' ha, cases six25 h2 with x hx, suffices : ¬col a' b c, cases (exists_of_exists_unique (ten16 this hx ha.2.flip)) with p hp, refine ⟨p, ⟨h2, h3, two7 hp.1.2.1.flip h1, or.inl h4⟩, _⟩, exact (eleven9 ha.1 (six5 h1)).trans (eleven11 ha.1.1 h1 hp.1), intro h_2, exact h_1 (four11 (five4 ha.1.1.symm (four11 h_2).2.1 (four11 (six4.1 ha.1).1).2.1)).2.2.2.1 end theorem eleven32a {a b c d e f : point} : ¬B a b c → ang_le d e f a b c → ∃ p, B a p c ∧ eqa d e f a b p := begin rintros h ⟨x, h1, h2⟩, cases (eleven23b h h1).2.2.2 with p hp, refine ⟨p, hp.1, _⟩, exact eleven10 h2 (six5 h2.1) (six5 h2.2.1) (six5 h2.2.2.1) hp.2 end theorem eleven32b {a b c p : point} : a ≠ b → c ≠ b → p ≠ b → B a p c → ang_le a b p a b c := begin intros h h1 h2 h3, exact ⟨p, ⟨h, h1, h2, or.inr ⟨p, h3, six5 h2⟩⟩, eqa.refl h h2⟩ end theorem eleven30 {a b c d e f a' b' c' d' e' f' : point} : ang_le a b c d e f → eqa a b c a' b' c' → eqa d e f d' e' f' → ang_le a' b' c' d' e' f' := begin rintros ⟨p, hp⟩ h1 h2, rcases eleven5.1 h2 with ⟨d₁, f₁, hd, hf, h⟩, cases hp.1.2.2.2, exact eleven31b h1.2.2.1 h1.2.2.2.1 h2.2.2.1 h2.2.2.2.1 (eleven21b h_1 h2), cases h_1 with x hx, cases four5 hx.1 h.2.2 with y hy, have h3 : eqd e x e' y, apply (four2 ⟨hx.1, hy.1, h.2.2, hy.2.2.1, h.1, h.2.1.flip⟩).flip, suffices : ang_le a b c d₁ e' f₁, unfold ang_le at *, cases this with r hr, refine ⟨r, eleven25 hr.1 hd.symm hf.symm (six5 hr.1.2.2.1), _⟩, exact h1.symm.trans (hr.2.trans (eleven9 hd.symm (six5 hr.1.2.2.1))), refine ⟨y, ⟨hd.1, hf.1, two7 h3.flip hx.2.1, or.inr ⟨y, hy.1, six5 (two7 h3.flip hx.2.1)⟩⟩, _⟩, apply hp.2.trans ((eleven9 (six5 h2.1) hx.2).trans (eleven11 h2.1 hx.2.1 ⟨h.1, h3, hy.2.1⟩)) end theorem eleven29 {a b c d e f : point} : ang_le a b c d e f ↔ ∃ q, I c a b q ∧ eqa a b q d e f := begin split, rintros ⟨p, hp, h⟩, by_cases h_1 : B d e f, refine ⟨S b a, ⟨h.1, (seven12a h.1.symm).symm, h.2.1, or.inl (seven5 b a).1⟩, _⟩, exact eleven21c h.1 (seven12a h.1.symm).symm hp.1 hp.2.1 (seven5 b a).1 h_1, unfold I at hp, simp [h_1, - ne.def] at hp, cases hp.2.2.2 with x hx, have h1 : eqa a b c d e x, exact eleven10 h (six5 h.1) (six5 h.2.1) (six5 h.2.2.1) hx.2, rcases eleven5.1 h1.symm with ⟨a', c', h2, h3, h4⟩, cases eleven28 h4 (or.inl hx.1) with q hq, existsi q, suffices : I c' a' b q ∧ eqa a' b q d e f, refine ⟨eleven25 this.1 h2.symm (six5 this.1.2.1).symm h3.symm, _⟩, exact eleven10 this.2 h2.symm (six5 this.2.2.1) (six5 this.2.2.2.1) (six5 this.2.2.2.2.1), have h5 : B a' c' q, exact four6 hx.1 ⟨h4.2.2, hq.2.2, hq.1⟩, refine ⟨⟨h2.1, (two7 hq.2.1.flip hp.2.1), h3.1, or.inr ⟨c', h5, six5 h3.1⟩⟩, _⟩, have h6 : eqa c' b q x e f, exact eleven11 h3.1 (two7 hq.2.1.flip hp.2.1) ⟨h4.2.1.symm.flip, hq.2.1.symm, hq.2.2.symm⟩, by_cases h_2 : col d e x, have h7 : sided e d x, apply six4.2 ⟨h_2, _⟩, intro h_3, exact h_1 (three6b h_3 hx.1), apply eleven10 h6 _ (six5 h6.2.1) h7 (six5 h6.2.2.2.1), exact six10a h7 ⟨h4.1.flip, h4.2.2, h4.2.1⟩, by_cases h_3 : col x e f, have h7 : sided e x f, apply six4.2 ⟨h_3, _⟩, intro h_4, exact h_1 (three5b hx.1 h_4), apply eleven10 (eleven11 h2.1 h3.1 h4.symm) (six5 h2.1) _ (six5 h.2.2.1) h7.symm, exact six10a h7.symm ⟨hq.2.1, hq.2.2.flip, h4.2.1⟩, apply eleven22a _ _ (eleven11 h2.1 h3.1 h4.symm) h6, unfold Bl, refine ⟨six14 h3.1.symm, _, _, c', six17b b c', h5⟩, intro h_4, exact h_2 (four13 (four11 h_4).2.2.2.1 h4.symm), intro h_4, exact h_3 (eleven21d (four11 h_4).2.1 h6), refine ⟨six14 hx.2.1.symm, (four10 h_2).2.2.1, (four10 h_3).2.1, x, six17b e x, hx.1⟩, rintros ⟨q, h, h1⟩, apply eleven30 _ (eqa.refl h.1 h.2.2.1) h1, exact ⟨c, h, (eqa.refl h.1 h.2.2.1)⟩ end theorem eleven33 {a b c d e f : point} : ang_le a b c d e f → a ≠ b ∧ c ≠ b ∧ d ≠ e ∧ f ≠ e := λ ⟨p, hp⟩, ⟨hp.2.1, hp.2.2.1, hp.1.1, hp.1.2.1⟩ theorem eleven33a {a b c d e f : point} : ang_le a b c d e f → ang_le c b a d e f := λ h, have h1 : _ := eleven33 h, eleven30 h (eleven6 h1.1 h1.2.1) (eqa.refl h1.2.2.1 h1.2.2.2) theorem eleven33b {a b c d e f : point} : ang_le a b c d e f → ang_le a b c f e d := λ h, have h1 : _ := eleven33 h, eleven30 h (eqa.refl h1.1 h1.2.1) (eleven6 h1.2.2.1 h1.2.2.2) theorem ang_le.refl {a b c : point} : a ≠ b → c ≠ b → ang_le a b c a b c := λ h h1, ⟨c, eleven26b h h1, eqa.refl h h1⟩ theorem ang_le.trans {a b c d e f x y z : point} : ang_le a b c d e f → ang_le d e f x y z → ang_le a b c x y z := begin intros h h1, rcases h1 with ⟨q, h2, h3⟩, cases h2.2.2.2, exact eleven31b (eleven33 h).1 (eleven33 h).2.1 h2.1 h2.2.1 h_1, cases h_1 with r hr, replace h3 := eleven10 h3 (six5 h3.1) (six5 h3.2.1) (six5 h3.2.2.1) hr.2, replace h := eleven30 h (eqa.refl (eleven33 h).1 (eleven33 h).2.1) h3, rcases h with ⟨s, hs, h4⟩, cases hs.2.2.2, exact eleven31b h4.1 h4.2.1 h2.1 h2.2.1 (three6b h hr.1), cases h with p hp, refine ⟨p, ⟨h2.1, h2.2.1, hp.2.1, or.inr ⟨p, three6b hp.1 hr.1, six5 hp.2.1⟩⟩, _⟩, exact eleven10 h4 (six5 h4.1) (six5 h4.2.1) (six5 h4.2.2.1) hp.2 end theorem ang_le.flip {a b c d e f : point} : ang_le a b c d e f → ang_le c b a f e d := λ h, eleven33b (eleven33a h) theorem eleven34 {a b c d e f : point} : ang_le a b c d e f → ang_le d e f a b c → eqa a b c d e f := begin rintros ⟨p, h, h1⟩ h2, by_cases h_1 : B d e f, apply eleven21c h1.1 h1.2.1 h.1 h.2.1 _ h_1, rcases h2 with ⟨q, h2, h3⟩, cases eleven23a h2, exact h_2, cases h_2 with r hr, apply three6b (eleven21b h_1 _) hr.2.2.2.1, exact eleven10 h3 (six5 h3.1) (six5 h3.2.1) (six5 h3.2.2.1) hr.2.2.2.2, rcases eleven29.1 h2 with ⟨q, h4, h3⟩, replace h2 := eleven23a h4, clear h4, cases h2, exfalso, cases (eleven23b h_1 h).2.2.2 with r hr, exact h_1 (three6b (six6 (eleven21b h2 (h3.trans h1)) hr.2.symm) hr.1), cases h2 with t ht, have h4 : ¬B d e t, intro h_2, exact h_1 (six6 h_2 ht.2.2.2.2), cases (eleven23b h4 (eleven25 h (six5 h.1) ht.2.2.2.2 (six5 h.2.2.1))).2.2.2 with r hr, replace h1 := eleven10 h1 (six5 h1.1) (six5 h1.2.1) (six5 h1.2.2.1) hr.2, apply eleven10 _ (six5 h3.2.2.1) (six5 h3.2.2.2.1) (six5 h3.1) ht.2.2.2.2.symm, by_cases h_2 : col a b c, cases six1 h_2, apply eleven21c h1.1 h1.2.1 ht.1 ht.2.2.2.2.1 h_3, exact three6b (eleven21b h_3 h1) hr.1, exact (eleven21a h_3).2 (six6a ((eleven21a h_3).1 h3.symm) ht.2.2.2.1), suffices : sided e r q, apply eleven10 h1 (six5 h1.1) (six5 h1.2.1) (six5 h1.2.2.1) _, exact (six6a this (three6a hr.1 ht.2.2.2.1)).symm, have h5 : ¬col d e r, intro h_3, exact h_2 (eleven21d h_3 h1.symm), apply eleven15b h_2 h5 h1 (side.refl (six14 ht.1.symm) (four10 h5).2.1) h3.symm, apply nine12 (six14 ht.1.symm) (six17b e d)((six7 (three6b hr.1 ht.2.2.2.1) (six26 h5).2.2.symm).symm), intro h_3, exact h5 (eleven21d (four11 h_3).2.1 (h3.trans h1)) end theorem eleven35 {a b c d e f : point} : a ≠ b → c ≠ b → d ≠ e → f ≠ e → ang_le a b c d e f ∨ ang_le d e f a b c := begin intros h h1 h2 h3, by_cases h4 : col a b c, cases six1 h4, exact or.inr (eleven31b h2 h3 h h1 h_1), exact or.inl (eleven31a h_1 h2 h3), by_cases h5 : col d e f, cases six1 h5, exact or.inl (eleven31b h h1 h2 h3 h_1), exact or.inr (eleven31a h_1 h h1), rcases eleven15a h5 h4 with ⟨c', h6, hc⟩, have h7 : c' ∈ pl (l b c) a, suffices : pl (l b a) c = pl (l b c) a, exact this ▸ (or.inl hc), exact (nine24 (four10 h4).2.1).1, cases h7, cases (nine31 hc h7).2.2.2 with x hx, refine or.inr ⟨c', ⟨h, h1, h6.2.2.2.1, or.inr ⟨x, hx.2, _⟩⟩, h6⟩, apply (nine19 (six14 h.symm) (six17a b a) (four11 hx.1).2.2.2.2 _).1, apply (nine19a hc (six17b b a) (six7 hx.2 _).symm).symm, intro h_1, subst x, exact (nine11 hc).2.1 (four11 hx.1).1, suffices : ∃ x, col b c x ∧ B c' x a, cases this with x hx, refine or.inl (eleven29.2 ⟨c', ⟨h, h6.2.2.2.1, h1, or.inr ⟨x, hx.2.symm, _⟩⟩, h6.symm⟩), apply (nine19 (six14 h.symm) (six17a b a) (four11 hx.1).2.2.2.2 _).1, apply (nine19a hc.symm (six17b b a) (six7 hx.2.symm _).symm).symm, intro h_1, subst x, exact (nine11 hc).2.2 (four11 hx.1).1, cases h7, exact ⟨c', h7, three3 c' a⟩, exact h7.symm.2.2.2 end lemma eleven36a {a b c d e f a' d' : point} : a' ≠ b → d' ≠ e → B a b a' → B d e d' → ang_le a b c d e f → ang_le d' e f a' b c := begin intros h h1 h2 h3 h4, by_cases h_1 : col a b c, cases six1 h_1, suffices : B d e f, apply eleven31a _ h (eleven33 h4).2.1, exact ⟨h1, (eleven33 h4).2.2.2, five2 (eleven33 h4).2.2.1 h3 this⟩, exact eleven21b h_2 (eleven34 h4 (eleven31b (eleven33 h4).2.2.1 (eleven33 h4).2.2.2 (eleven33 h4).1 (eleven33 h4).2.1 h_2)), apply eleven31b h1 (eleven33 h4).2.2.2 h (eleven33 h4).2.1 _, exact six6 h2.symm h_2, cases eleven29.1 h4 with p hp, cases hp.1.2.2.2, suffices : B d e f, apply eleven31a _ h (eleven33 h4).2.1, exact ⟨h1, (eleven33 h4).2.2.2, five2 (eleven33 h4).2.2.1 h3 this⟩, exact eleven21b h_2 hp.2, cases h_2 with y hy, by_cases h_2 : y = p, subst y, apply eleven30 (ang_le.refl h (eleven33 h4).2.1) _ (eqa.refl h (eleven33 h4).2.1), exact eleven13 (eleven10 hp.2 (six5 hp.2.1) hy.2.symm (six5 hp.2.2.2.1) (six5 hp.2.2.2.2.1)) h h2 h1 h3, refine ⟨p, ⟨h, hp.1.2.2.1, hp.1.2.1, or.inr _⟩, (eleven13 hp.2 h h2 h1 h3).symm⟩, have h5 : side (l b p) a c, apply (nine19a _ (six17a b p) hy.2), apply (nine12 (six14 hp.2.2.1.symm) (six17b b p) (six7 hy.1.symm h_2) _).symm, intro h_3, apply h_1 (six23.2 ⟨l b p, (six14 hp.2.2.1.symm), _, (six17a b p), _⟩), rw (six18 (six14 hp.2.2.1.symm) h_2 h_3 (six17b b p)), exact or.inr (or.inr hy.1), rw (six18 (six14 hp.2.2.1.symm) hy.2.1 h_3 (six17a b p)), exact (six4.1 hy.2).1, have h6 : Bl c (l b p) a', apply (nine8 ⟨(nine11 h5).1, (nine11 h5).2.1, _, ⟨b, (six17a b p), h2⟩⟩).2 h5, intro h_3, apply (nine11 h5).2.1, rw (six18 ((nine11 h5).1) h h_3 (six17a b p)), exact or.inl h2.symm, cases h6.2.2.2 with x hx, refine ⟨x, hx.2.symm, six4.2 ⟨(four11 hx.1).2.2.2.1, _⟩⟩, intro h_3, suffices : side (l a b) p c, have h6 : side (l a b) p x, apply nine19a this (or.inl h2) (six7 hx.2.symm _).symm, intro h_4, subst x, exact h6.2.2.1 (or.inr (or.inr h_3)), apply (nine9 _) h6, exact ⟨(nine11 h6).1, (nine11 h6).2.1, (nine11 h6).2.2, ⟨b, (six17b a b), h_3.symm⟩⟩, have h7 : side (l a b) c y, exact nine12 (six14 (six26 h_1).1) (six17b a b) hy.2.symm h_1, apply (nine19a h7 (six17a a b) _).symm, apply (six7 hy.1 _), intro h_4, subst y, exact (nine11 h7).2.2 (six17a a b) end theorem eleven36 {a b c d e f a' d' : point} : a ≠ b → a' ≠ b → d ≠ e → d' ≠ e → B a b a' → B d e d' → (ang_le a b c d e f ↔ ang_le d' e f a' b c) := begin intros h h1 h2 h3 h4 h5, split, intro h6, exact eleven36a h1 h3 h4 h5 h6, intro h6, exact eleven36a h2 h h5.symm h4.symm h6 end def ang_lt (a b c d e f : point) : Prop := ang_le a b c d e f ∧ ¬eqa a b c d e f theorem ang_lt_or_eq_of_le {a b c d e f : point} : ang_le a b c d e f → (ang_lt a b c d e f ∨ eqa a b c d e f) := begin intro h, by_cases h1 : eqa a b c d e f, exact or.inr h1, exact or.inl ⟨h, h1⟩, end theorem ang_lt.flip {a b c d e f : point} : ang_lt a b c d e f → ang_lt c b a f e d := λ h, ⟨h.1.flip, λ h_1, h.2 h_1.flip⟩ theorem eleven32c {a b c d e f : point} : ¬B a b c → ang_lt d e f a b c → ∃ p, p ≠ c ∧ B a p c ∧ eqa d e f a b p := begin rintros h ⟨h1, h2⟩, cases eleven32a h h1 with p hp, refine ⟨p, _, hp.1, hp.2⟩, intro h_1, subst p, exact h2 hp.2 end theorem eleven32d {a b c p : point} : ¬col a b c → p ≠ c → B a p c → ang_lt a b p a b c := begin intros h h1 h2, refine ⟨eleven32b (six26 h).1 (six26 h).2.1.symm _ h2, _⟩, intro h_1, subst p, exact h (or.inl h2), intro h_1, by_cases h_2 : p = a, subst p, exact h (six4.1 ((eleven21a (six5 (six26 h).1)).1 h_1)).1, have h3 : sided a c p, exact (six7 h2 h_2).symm, have h4 : side (l a b) c p, exact nine12 (six14 (six26 h).1) (six17a a b) (six7 h2 h_2).symm h, suffices : sided b c p, exact (four10 h).2.2.2.1 (five4 h1.symm (or.inl h2.symm) (four11 (six4.1 this).1).1), exact eleven15c h_1.symm h4 end theorem eleven37 {a b c d e f a' b' c' d' e' f' : point} : ang_lt a b c d e f → eqa a b c a' b' c' → eqa d e f d' e' f' → ang_lt a' b' c' d' e' f' := begin rintros ⟨h, h1⟩ h2 h3, refine ⟨eleven30 h h2 h3, _⟩, intro h_1, exact h1 (h2.trans (h_1.trans h3.symm)) end theorem eleven38a {a b c d e f : point} : ang_lt a b c d e f ↔ a ≠ b ∧ c ≠ b ∧ d ≠ e ∧ f ≠ e ∧ ¬ang_le d e f a b c := begin split, rintros ⟨⟨p, h, h1⟩, h2⟩, refine ⟨h1.1, h1.2.1, h1.2.2.1, h.2.1, _⟩, intro h3, exact h2 (eleven34 ⟨p, h, h1⟩ h3), rintros ⟨h, h1, h2, h3, h4⟩, split, simpa [h4] using (eleven35 h h1 h2 h3), intro h_1, exact h4 (eleven30 (ang_le.refl h h1) h_1 (eqa.refl h h1)) end theorem ang_lt_or_ge {a b c d e f : point} : a ≠ b → c ≠ b → d ≠ e → f ≠ e → (ang_lt a b c d e f ∨ ang_le d e f a b c) := begin intros h h1 h2 h3, by_cases h_1 : ang_le d e f a b c, exact or.inr h_1, exact or.inl (eleven38a.2 ⟨h, h1, h2, h3, h_1⟩) end theorem eleven38b {a b c d e f : point} : ang_lt a b c d e f → ang_lt d e f a b c → false := begin intros h h1, suffices : ¬ang_lt d e f a b c, exact this h1, intro h_1, exact (eleven38a.1 h).2.2.2.2 h_1.1 end theorem eleven39 {a b c d e f a' d' : point} : a ≠ b → a' ≠ b → d ≠ e → d' ≠ e → B a b a' → B d e d' → (ang_lt a b c d e f ↔ ang_lt d' e f a' b c) := begin intros h h1 h2 h3 h4 h5, split, intro h6, refine ⟨(eleven36 h h1 h2 h3 h4 h5).1 h6.1, _⟩, intro h_1, exact h6.2 (eleven13 h_1.symm h h4.symm h2 h5.symm), intro h6, refine ⟨(eleven36 h h1 h2 h3 h4 h5).2 h6.1, _⟩, intro h_1, exact h6.2 (eleven13 h_1.symm h3 h5 h1 h4) end theorem ang_lt.trans {a b c d e f x y z : point} : ang_lt a b c d e f → ang_lt d e f x y z → ang_lt a b c x y z := begin intros h h1, refine ⟨ang_le.trans h.1 h1.1, _⟩, intro h_1, replace h1 := eleven37 h1 (eqa.refl (eleven38a.1 h1).1 (eleven38a.1 h1).2.1) h_1.symm, exact eleven38b h h1 end def acute (a b c : point) : Prop := ∃ x y z, R x y z ∧ ang_lt a b c x y z theorem tri_of_acute {a b c : point} : acute a b c → a ≠ b ∧ c ≠ b := λ ⟨x, y, z, h⟩, ⟨(eleven38a.1 h.2).1, (eleven38a.1 h.2).2.1⟩ theorem acute.symm {a b c : point} : acute a b c → acute c b a := begin rintros ⟨x, y, z, h, h1⟩, refine ⟨x, y, z, h, (eleven37 h1 (eleven6 (eleven38a.1 h1).1 (eleven38a.1 h1).2.1) _)⟩, exact (eqa.refl (eleven38a.1 h1).2.2.1 (eleven38a.1 h1).2.2.2.1) end theorem eleven40a {a b c : point} : sided b a c → acute a b c := begin intro h, cases eight25 h.1 with d hd, refine ⟨a, b, d, hd.1, eleven31a h h.1 hd.2, _⟩, intro h1, cases (eight9 hd.1 (six4.1 ((eleven21a h).1 h1)).1), exact h.1 h_1, exact hd.2 h_1 end def obtuse (a b c : point) : Prop := ∃ x y z, R x y z ∧ ang_lt x y z a b c theorem tri_of_obtuse {a b c : point} : obtuse a b c → a ≠ b ∧ c ≠ b := λ ⟨x, y, z, h⟩, ⟨(eleven38a.1 h.2).2.2.1, (eleven38a.1 h.2).2.2.2.1⟩ theorem obtuse.symm {a b c : point} : obtuse a b c → obtuse c b a := begin rintros ⟨x, y, z, h, h1⟩, refine ⟨x, y, z, h, (eleven37 h1 _ (eleven6 (eleven38a.1 h1).2.2.1 (eleven38a.1 h1).2.2.2.1))⟩, exact (eqa.refl (eleven38a.1 h1).1 (eleven38a.1 h1).2.1) end theorem eleven40b {a b c : point} : a ≠ b → c ≠ b → B a b c → obtuse a b c := begin intros h h1 h2, cases eight25 h with d hd, refine ⟨a, b, d, hd.1, eleven31b h hd.2 h h1 h2, _⟩, intro h3, cases (eight9 hd.1 (or.inl ((eleven21b h2) h3.symm))), exact h h_1, exact hd.2 h_1 end def right (a b c : point) : Prop := a ≠ b ∧ c ≠ b ∧ R a b c theorem lt_right_of_acute {a b c p q r : point} : acute a b c → right p q r → ang_lt a b c p q r := begin rintros ⟨x, y, z, h⟩ h1, apply eleven37 h.2 (eqa.refl (eleven38a.1 h.2).1 (eleven38a.1 h.2).2.1), exact eleven16 (eleven38a.1 h.2).2.2.1 (eleven38a.1 h.2).2.2.2.1 h1.1 h1.2.1 h.1 h1.2.2 end theorem gt_right_of_obtuse {a b c p q r : point} : obtuse a b c → right p q r → ang_lt p q r a b c := begin rintros ⟨x, y, z, h⟩ h1, apply eleven37 h.2 _ (eqa.refl (eleven38a.1 h.2).2.2.1 (eleven38a.1 h.2).2.2.2.1), exact eleven16 (eleven38a.1 h.2).1 (eleven38a.1 h.2).2.1 h1.1 h1.2.1 h.1 h1.2.2 end theorem lt_obtuse_of_acute {a b c d e f : point} : acute a b c → obtuse d e f → ang_lt a b c d e f := begin rintros ⟨x, y, z, h⟩ h1, suffices : right x y z, exact h.2.trans (gt_right_of_obtuse h1 this), exact ⟨(eleven38a.1 h.2).2.2.1, (eleven38a.1 h.2).2.2.2.1, h.1⟩ end lemma eleven41a {a b c d : point} : ¬col a b c → B b a d → d ≠ a → ang_lt a c b c a d := begin intros h h1 h2, generalize h3 : S (mid a c) b = p, have h4 : eqa a c b c a p, suffices : eqa a c b (S (mid a c) a) (S (mid a c) c) (S (mid a c) b), rwa [h3, mid_to_Sa a c, mid.symm a c, mid_to_Sa c a] at this, exact eleven12 (mid a c) (six26 h).2.2 (six26 h).2.1, cases pasch h1.symm (seven5 (mid a c) b).1.symm with x hx, rw h3 at hx, have h5 : I p c a d, suffices : I p (mid a c) a d, apply eleven25 this (six7 (ten1 a c).1 _).symm (six5 this.2.1) (six5 this.2.2.1), exact mid.neq (six26 h).2.2, have h6 : x ≠ a, intro h_1, subst x, apply h (six23.2 ⟨l d a, six14 h2,(six17b d a), or.inl h1.symm, _⟩), exact or.inl (three7b hx.2.symm (ten1 a c).1 (mid.neq (six26 h).2.2).symm), refine ⟨mid.neq (six26 h).2.2 , h2, _, or.inr ⟨x, hx.2, (six7 hx.1 h6)⟩⟩, exact (six7 hx.1 h6).2.1, refine ⟨⟨p, h5, h4⟩, _⟩, intro h_1, suffices h7 : side (l a c) d p, suffices : ¬col d a p, have h8 : ¬sided a d p, intro h_2, exact this (six4.1 h_2).1, apply h8 (eleven15b (four10 h).1 (four10 (nine11 h7).2.1).2.1 h_1 _ h4 h7.symm), exact side.trans h7 h7.symm, intro h_2, apply h (six23.2 ⟨l d a, six14 h2,(six17b d a), or.inl h1.symm, _⟩), rw ←mid_to_Sa a c, apply (seven24 (six14 h2) _).1 (six17b d a), apply six27 (six14 h2) (or.inl h1.symm) h_2, rw ←h3, exact (seven5 (mid a c) b).1, refine ⟨b, ⟨six14 (six26 h).2.2, _, (four10 h).1, ⟨a, (six17a a c), h1.symm⟩⟩, ⟨six14 (six26 h).2.2, _⟩⟩, intro h_2, exact h (six23.2 ⟨l d a, six14 h2,(six17b d a), or.inl h1.symm, (four11 h_2).2.2.2.1⟩), subst p, refine ⟨_, (four10 h).1, ⟨(mid a c), or.inr (or.inl (ten1 a c).1.symm), (seven5 (mid a c) b).1.symm⟩⟩, intro h_2, exact (four10 h).1 ((seven24 (six14 (six26 h).2.2) (or.inr (or.inl (ten1 a c).1.symm))).2 h_2), end theorem eleven41 {a b c d : point} : ¬col a b c → B b a d → d ≠ a → ang_lt a c b c a d ∧ ang_lt a b c c a d := begin intros h h1 h2, refine ⟨eleven41a h h1 h2, _⟩, have h3 : eqa c a d b a (S a c), apply ((eleven6 h2 (six26 h).2.2.symm).trans _).flip, apply eleven14 (six26 h).2.2.symm h2 (seven12a (six26 h).2.2).symm (six26 h).1.symm _ h1.symm, exact (seven5 a c).1, apply eleven37 _ (eqa.refl (six26 h).1 (six26 h).2.1.symm) h3.symm, exact eleven41a (four10 h).1 (seven5 a c).1 (seven12a (six26 h).2.2).symm end theorem eleven42 {a b c d: point} : B a b d → (d ≠ b ∧ acute a b c ↔ a ≠ b ∧ obtuse d b c) := begin intros h, split, rintros ⟨h1, h2⟩, rcases h2 with ⟨x, y, z, h2, ⟨h3, h4⟩⟩, have h5 : ang_le (S y x) y z d b c, exact eleven36a h1 (seven12a (eleven33 h3).2.2.1.symm).symm h (seven5 y x).1 h3, refine ⟨(eleven33 h3).1, S y x, y, z, h2.symm.flip.symm, ⟨h5, _⟩⟩, intro h_1, exact h4 (eleven13 h_1.symm (eleven33 h3).1 h.symm (eleven33 h3).2.2.1 (seven5 y x).1.symm), rintros ⟨h1, h2⟩, rcases h2 with ⟨x, y, z, h2, ⟨h3, h4⟩⟩, have h5 : ang_le a b c (S y x) y z, exact eleven36a (seven12a (eleven33 h3).1.symm).symm h1 (seven5 y x).1 h.symm h3, refine ⟨(eleven33 h3).2.2.1, S y x, y, z, h2.symm.flip.symm, ⟨h5, _⟩⟩, intro h_1, exact h4 (eleven13 h_1.symm (eleven33 h3).1 (seven5 y x).1.symm (eleven33 h3).2.2.1 h) end theorem eleven43 {a b c : point} : ¬col a b c → (R b a c ∨ obtuse b a c) → acute a b c ∧ acute a c b := begin intros h h1, have h2 := eleven41 h (seven5 a b).1 (seven12a (six26 h).1).symm, cases h1, refine ⟨⟨c, a, (S a b), h1.symm.flip, _⟩, c, a, (S a b), h1.symm.flip, _⟩, exact h2.2, exact h2.1, suffices : acute c a (S a b), rcases this with ⟨x, y, z, h3, h4⟩, refine ⟨⟨x, y, z, h3, h2.2.trans h4⟩, x, y, z, h3, h2.1.trans h4⟩, exact ((eleven42 (seven5 a b).1.symm).2 ⟨(seven12a (six26 h).1).symm, h1⟩).2.symm end theorem ang_total {a b c d e f : point} : a ≠ b → c ≠ b → d ≠ e → f ≠ e → (ang_lt a b c d e f ∨ eqa a b c d e f ∨ ang_lt d e f a b c) := begin intros h h1 h2 h3, unfold ang_lt, cases eleven35 h h1 h2 h3, by_cases h_2 : eqa a b c d e f; simp [h_1, h_2], by_cases h_2 : eqa a b c d e f, simp [h_2, h_1], refine or.inr (or.inr ⟨h_1, _⟩), intro h_3, exact h_2 h_3.symm end theorem right_total {a b c d e f : point} : a ≠ b → c ≠ b → (acute a b c ∨ right a b c ∨ obtuse a b c) := begin intros h h1, cases eight25 h with t ht, cases ang_lt_or_ge h h1 h ht.2, exact or.inl ⟨a, b, t, ht.1, h_1⟩, cases ang_lt_or_eq_of_le h_1, exact or.inr (or.inr ⟨a, b, t, ht.1, h_2⟩), exact or.inr (or.inl ⟨h, h1, (eleven17 ht.1 h_2)⟩) end lemma eleven44c {a b c : point} : ¬col a b c → eqd a b a c → eqa a c b a b c := begin intros h h1, suffices : cong a c b a b c, exact eleven11 (six26 h).2.2 (six26 h).2.1 this, exact ⟨h1.symm, two5 (eqd.refl c b), h1⟩ end theorem eleven44d {a b c : point} : ¬col a b c → distlt a b a c → ang_lt a c b a b c := begin intros h h1, cases five13 h1 with d hd, have h2 : ¬col d c b, intro h_1, exact (four10 h).2.2.2.1 (five4 hd.2.2.symm (or.inl hd.1.symm) (four11 h_1).2.1), have h3 : ang_lt d b c b d a ∧ ang_lt d c b b d a, exact eleven41 h2 hd.1.symm (two7 hd.2.1 (six26 h).1), have h4 : ¬col a b d, intro h_1, exact h (five4 (two7 hd.2.1 (six26 h).1) (four11 h_1).1 (or.inl hd.1)), suffices : ang_lt a b d a b c, apply ang_lt.trans _ this, apply eleven37 h3.2 (eleven9 _ (six5 (six26 h).2.1)) (eqa.trans _ (eleven44c h4 hd.2.1)), exact (six7 hd.1.symm hd.2.2).symm, exact (eleven6 (six26 h4).2.1 (six26 h4).2.2), exact eleven32d h hd.2.2 hd.1 end theorem eleven44a {a b c : point} : ¬col a b c → (eqd a b a c ↔ eqa a c b a b c) := begin intro h, refine ⟨eleven44c h, _⟩, intro h1, cases dist_total a b a c, exact ((eleven44d h h_1).2 h1).elim, cases h_1, assumption, exact ((eleven44d (four10 h).1 h_1).2 h1.symm).elim end theorem eleven44b {a b c : point} : ¬col a b c → (distlt a b a c ↔ ang_lt a c b a b c) := begin intro h, refine ⟨eleven44d h, _⟩, intro h1, cases dist_total a b a c, assumption, cases h_1, exact (h1.2 (eleven44c h h_1)).elim, exact (eleven38b h1 (eleven44d (four10 h).1 h_1)).elim end def isoc (a b c : point) : Prop := ¬col a b c ∧ eqd b a b c def equil (a b c : point) : Prop := tri a b c ∧ eqd a b b c ∧ eqd a b a c theorem eleven45a {a b c : point} : acute a b c → ¬right a b c ∧ ¬obtuse a b c := λ h, ⟨λ h1, (lt_right_of_acute h h1).2 (eqa.refl (tri_of_acute h).1 (tri_of_acute h).2), λ h1, (lt_obtuse_of_acute h h1).2 (eqa.refl (tri_of_acute h).1 (tri_of_acute h).2)⟩ theorem eleven45b {a b c : point} : right a b c → ¬acute a b c ∧ ¬obtuse a b c := λ h, ⟨λ h1, (lt_right_of_acute h1 h).2 (eqa.refl h.1 h.2.1), λ h1, (gt_right_of_obtuse h1 h).2 (eqa.refl h.1 h.2.1)⟩ theorem eleven45c {a b c : point} : obtuse a b c → ¬acute a b c ∧ ¬right a b c := λ h, ⟨λ h1, (lt_obtuse_of_acute h1 h).2 (eqa.refl (tri_of_obtuse h).1 (tri_of_obtuse h).2), λ h1, (gt_right_of_obtuse h h1).2 (eqa.refl (tri_of_obtuse h).1 (tri_of_obtuse h).2)⟩ theorem eleven46 {a b c : point} : ¬col a b c → (R b a c ∨ obtuse b a c) → distlt a b b c ∧ distlt a c b c := begin intros h h1, split, apply five14 ((eleven44b (four10 h).2.1).2 _) (two5 (eqd.refl b a)) (eqd.refl b c), cases h1, exact lt_right_of_acute (eleven43 h (or.inl h1)).2.symm ⟨(six26 h).1.symm, (six26 h).2.2.symm, h1⟩, exact lt_obtuse_of_acute (eleven43 h (or.inr h1)).2.symm h1, apply five14 ((eleven44b (four10 h).2.2.2.1).2 _) (two5 (eqd.refl c a)) (two5 (eqd.refl c b)), cases h1, exact lt_right_of_acute (eleven43 h (or.inl h1)).1.symm ⟨(six26 h).2.2.symm, (six26 h).1.symm, h1.symm⟩, exact lt_obtuse_of_acute (eleven43 h (or.inr h1)).1.symm h1.symm end theorem eleven47 {a b c x : point} : R a c b → xperp x (l c x) (l a b) → B a x b ∧ x ≠ a ∧ x ≠ b := begin intros h h1, have h2 : ¬col a b c, intro h_1, exact (eight14b h1) (six18 h1.2.1 (six13 h1.1) h_1 h1.2.2.2.1).symm, have h3 := eleven43 (four10 h2).2.2.2.1 (or.inl h), have h4 : x ≠ a, intro h_1, subst x, exact (eleven45a h3.1).1 ⟨(six26 h2).2.2.symm, (six26 h2).1.symm, h1.2.2.2.2 (six17a c a) (six17b a b)⟩, have h5 : x ≠ b, intro h_1, subst x, exact (eleven45a h3.2).1 ⟨(six26 h2).2.1.symm, h4.symm, h1.2.2.2.2 (six17a c b) (six17a a b)⟩, refine ⟨_, h4, h5⟩, wlog h6 : distle b x a x := (five10 b x a x) using a b, suffices : distle a x a b, cases h1.2.2.2.1, exact (six12 (six7 h_1 (six26 h2).1.symm).symm).1 this, cases h_1, exact h_1.symm, suffices : distle b x b a, exact ((six12 (six7 h_1.symm (six26 h2).1).symm).1 this).symm, exact h6.trans (five6 this (eqd.refl a x) (two5 (eqd.refl a b))), apply distle.trans _ (eleven46 (four10 h2).2.2.2.1 (or.inl h)).1.1, suffices : ¬col x c a, exact five6 (eleven46 this (or.inl (h1.2.2.2.2 (six17a c x) (six17a a b)))).2.1 (two5 (eqd.refl x a)) (eqd.refl c a), intro h_1, exact h4 (eight14d h1 (eight15 ⟨x, h1⟩ (four11 h_1).2.1 (six17a a b))), apply (this h.symm _ (four10 h2).2.1 h3.symm h5 h4).symm, rwa six17 b a end theorem eleven48 {a b c d e f : point} : ang_lt a b c d e f → ang_lt c b a d e f := λ h, ⟨eleven33a h.1, λ h_1, h.2 (eleven7 h_1)⟩ theorem eleven49 {a b c d e f : point} : ang_lt a b c d e f → ang_lt a b c f e d := λ h, ⟨eleven33b h.1, λ h_1, h.2 (eleven8 h_1)⟩ theorem SAS {a b c a' b' c' : point} : eqa a b c a' b' c' → eqd a b a' b' → eqd c b c' b' → eqd a c a' c' ∧ (a ≠ c → eqa b a c b' a' c' ∧ eqa b c a b' c' a') := begin intros h h1 h2, suffices : cong a b c a' b' c', refine ⟨this.2.2, λ h1, _⟩, refine ⟨eleven11 h.1.symm h1.symm (four4 this).2.1, eleven11 h.2.1.symm h1 (four4 this).2.2.1⟩, exact ⟨h1, h2.flip, (eleven4.1 h).2.2.2.2 (six5 h.1) (six5 h.2.1) (six5 h.2.2.1) (six5 h.2.2.2.1) h1.flip h2.flip⟩ end theorem ASA {a b c a' b' c' : point} : ¬col a b c → eqa b a c b' a' c' → eqa a b c a' b' c' → eqd a b a' b' → eqd a c a' c' ∧ eqd b c b' c' ∧ eqa a c b a' c' b' := begin intros h h1 h2 h3, cases exists_of_exists_unique (six11 h1.2.2.2.1 h1.2.1.symm) with x hx, have h4 : cong a b c a' b' x, refine ⟨h3, _, hx.2.symm⟩, exact (eleven4.1 h1).2.2.2.2 (six5 h1.1) (six5 h1.2.1) (six5 h1.2.2.1) hx.1 h3 hx.2.symm, suffices : x = c', subst x, exact ⟨h4.2.2, h4.2.1, eleven11 h1.2.1.symm h2.2.1.symm (four4 h4).1⟩, have h5 : ¬col a' b' c', intro h_1, exact h (eleven21d h_1 h2.symm), suffices : sided b' x c', apply six21a (six14 h1.2.2.2.1.symm) (six14 h2.2.2.2.1.symm) _ (four11 (six4.1 hx.1).1).2.2.1 (four11 (six4.1 this).1).2.2.1 (six17b a' c') (six17b b' c'), intro h_1, apply h5, suffices : b' ∈ l a' c', exact (four11 this).1, rw h_1, exact six17a b' c', apply eleven15b h h5 (eleven11 h2.1 h2.2.1 h4) _ h2 (side.refla (four10 h5).2.1), apply (nine12 (six14 h1.2.2.1) (six17b b' a') hx.1.symm (four10 h5).2.1).symm end theorem AAS {a b c a' b' c' : point} : ¬col a b c → eqa b c a b' c' a' → eqa a b c a' b' c' → eqd a b a' b' → eqd a c a' c' ∧ eqd b c b' c' ∧ eqa b a c b' a' c' := begin intros h h1 h2 h3, cases exists_of_exists_unique (six11 h1.2.2.1.symm h1.1) with x hx, have h4 : cong a b c a' b' x, refine ⟨h3, hx.2.symm, _⟩, exact (eleven4.1 h2).2.2.2.2 (six5 h2.1) (six5 h2.2.1) (six5 h2.2.2.1) hx.1 h3.flip hx.2.symm, suffices : x = c', subst x, exact ⟨h4.2.2, h4.2.1, eleven11 h2.1.symm h1.2.1.symm (four4 h4).2.1⟩, clear h2 h3, replace hx := hx.1, replace h4 := (eleven11 h1.1 h1.2.1 (four4 h4).2.2.1), wlog h6 := hx.2.2 using x c', by_contradiction h_1, have h5 : ¬col x c' a', intro h_2, apply (four10 h).2.2.1 (eleven21d (six23.2 ⟨l x c', six14 h_1, _, six17b x c', h_2⟩) h1.symm), exact (four11 (six4.1 hx).1).1, apply (eleven41 h5 h6.symm hx.1.symm).2.2, apply eleven8 (eqa.trans _ (h1.symm.trans h4)), exact eleven9 (six7 h6.symm h_1).symm (six5 h1.2.2.2.1), exact (this h4 hx.symm h1).symm end theorem SSS {a b c d e f : point} : tri a b c → cong a b c d e f → eqa a b c d e f ∧ eqa b c a e f d ∧ eqa c a b f d e := λ h h1, ⟨eleven11 h.1 h.2.1.symm h1, eleven11 h.2.1 h.2.2 (four4 h1).2.2.1, eleven11 h.2.2.symm h.1.symm (four4 h1).2.2.2.1⟩ theorem SSA {a b c a' b' c' : point} : eqa a b c a' b' c' → eqd a c a' c' → eqd b c b' c' → distle b c a c → eqd a b a' b' ∧ eqa b a c b' a' c' ∧ eqa b c a b' c' a' := begin intros h h1 h2 h3, cases exists_of_exists_unique (six11 h.2.2.1 h.1.symm) with x hx, have h4 : cong a b c x b' c', refine ⟨hx.2.symm.flip, h2, _⟩, exact (eleven4.1 h).2.2.2.2 (six5 h.1) (six5 h.2.1) hx.1 (six5 h.2.2.2.1) hx.2.symm h2, have h5 : a ≠ c, intro h_1, subst c, exact h.1.symm (id_eqd (five9 h3 (five11 a b a))), suffices : x = a', subst x, exact ⟨h4.1, eleven11 h.1.symm h5.symm (four4 h4).2.1, eleven11 h.2.1.symm h5 (four4 h4).2.2.1⟩, by_contradiction h_1, cases hx.1.2.2.symm with h6 h6, have h7 : ¬col a b c, intro h_2, apply dist_le_iff_not_lt.1 h3 (five14 _ h1.symm h2.symm), suffices : B b' a' c', refine ⟨((five12 (or.inl this)).1 this).2, λ h_3, _⟩, apply h.2.2.1 (unique_of_exists_unique (six11 h.2.2.2.1.symm h.2.2.2.1) _ _), exact ⟨six7 this.symm (two7 h1 h5), h_3.flip⟩, exact ⟨six5 h.2.2.2.1.symm, eqd.refl c' b'⟩, apply three5a h6 _, cases seven20 _ (h1.symm.flip.trans h4.2.2.flip), exact (h_1 h_3.symm).elim, exact h_3.1, apply (four11 (five4 h.2.2.2.1 (four11 (eleven21d h_2 h)).2.2.2.2 _)).2.1, exact (four11 (four13 h_2 h4)).2.2.2.2, apply dist_le_iff_not_lt.1 h3 (five14 _ h4.2.2.symm h2.symm), apply ((eleven44b _).2 _).flip, intro h_2, exact h7 (four13 (four11 h_2).2.2.1 h4.symm), have h8 : ¬col a' b' c', intro h_2, exact h7 (eleven21d h_2 h.symm), suffices : ang_lt a' b' c' c' a' x, apply eleven37 (eleven48 this) (eleven9 (six5 h.2.2.2.1) hx.1) (((eleven44a _).1 (h1.symm.trans h4.2.2).flip).symm.trans _), intro h_2, exact h8 (five4 (ne.symm h_1) (four11 (or.inl h6)).2.2.1 (four11 h_2).2.2.1), exact eleven9 (six5 (two7 h4.2.2 h5).symm) (six7 h6.symm (ne.symm h_1)).symm, exact (eleven41 h8 h6 h_1).2, have h7 : ¬col a b c, intro h_2, apply dist_le_iff_not_lt.1 h3 (five14 _ h4.2.2.symm h4.2.1.symm), suffices : B b' x c', refine ⟨((five12 (or.inl this)).1 this).2, λ h_3, _⟩, apply hx.1.1 (unique_of_exists_unique (six11 h.2.2.2.1.symm h.2.2.2.1) _ _), exact ⟨six7 this.symm (two7 h4.2.2 h5), h_3.flip⟩, exact ⟨six5 h.2.2.2.1.symm, eqd.refl c' b'⟩, apply three5a h6 _, cases seven20 _ (h1.symm.flip.trans h4.2.2.flip), exact (h_1 h_3.symm).elim, exact h_3.1.symm, apply (four11 (five4 h.2.2.2.1 (four11 (eleven21d h_2 h)).2.2.2.2 _)).2.1, exact (four11 (four13 h_2 h4)).2.2.2.2, apply dist_le_iff_not_lt.1 h3 (five14 _ h1.symm h2.symm), apply ((eleven44b _).2 _).flip, intro h_2, exact h7 (eleven21d (four11 h_2).2.2.1 h.symm), have h8 : ¬col x b' c', intro h_2, exact h7 (four13 h_2 h4.symm), suffices : ang_lt x b' c' c' x a', apply eleven37 (eleven48 this) (eleven9 (six5 h.2.2.2.1) hx.1.symm) (((eleven44a _).1 (h4.2.2.symm.trans h1).flip).symm.trans _), intro h_2, exact h8 (five4 h_1 (four11 (or.inl h6)).2.2.1 (four11 h_2).2.2.1), exact eleven9 (six5 (two7 h1 h5).symm) (six7 h6.symm h_1).symm, exact (eleven41 h8 h6 (ne.symm h_1)).2 end theorem eleven53 {a b c d : point} : R a d c → c ≠ d → a ≠ b → a ≠ d → B d a b → ang_lt d b c d a c ∧ distlt a c b c := begin intros h h1 h2 h3 h4, have h5 : c ∉ l a b, intro h_1, suffices : col a d c, exact (eight9 h this).elim h3 h1, suffices : l a b = l a d, rwa this at h_1, exact six16 h2 h3 (or.inr (or.inr h4)), have h6 := (eleven41 h5 h4.symm h3.symm).2, refine ⟨eleven37 (eleven49 h6) (eleven9 (six7 h4.symm h2).symm (six5 (six26 h5).2.1.symm)) (eqa.refl h3.symm (six26 h5).2.2.symm), _⟩, have h7 : eqd c a c (S d a), exact h.symm, apply five14 _ h7.symm.flip (eqd.refl b c), apply ((eleven44b _).2 _).flip, intro h_1, suffices : l a b = l (S d a) b, rw this at h5, exact h5 (four11 h_1).2.2.1, apply six18 (six14 h2) _ (or.inr (or.inr (three7b h4.symm (seven5 d a).1 h3).symm)) (six17b a b), intro h_2, subst b, exact h3 (three4 (seven5 d a).1 h4), apply eleven37 (eleven48 h6) (eleven9 (six5 (six26 h5).2.1.symm) _) _, exact (six7 (three7b h4.symm (seven5 d a).1 h3) h2).symm, apply eleven10 _ (six5 (six26 h5).2.2.symm) (six7 (seven5 d a).1 h3.symm) (six5 (two7 h7 (six26 h5).2.2.symm)) (six7 (three7b h4.symm (seven5 d a).1 h3).symm (seven12b h3.symm)).symm, apply (eleven44a (four10 _).2.2.2.2).1 h7.symm, intro h_1, suffices : l a b = l a (S d a), rw this at *, exact h5 h_1, exact six16 h2 (seven12b h3.symm) (or.inr (or.inr (three7b h4.symm (seven5 d a).1 h3).symm)) end end Euclidean_plane
b55ff7322eed96db5c62a0a79eb1195ba8d76a25
76ce87faa6bc3c2aa9af5962009e01e04f2a074a
/12_Sets/00_intro.lean
45363e7b7580d715f2fd8a3186b1c9fe8ae5ae60
[]
no_license
Mnormansell/Discrete-Notes
db423dd9206bbe7080aecb84b4c2d275b758af97
61f13b98be590269fc4822be7b47924a6ddc1261
refs/heads/master
1,585,412,435,424
1,540,919,483,000
1,540,919,483,000
148,684,638
0
0
null
null
null
null
UTF-8
Lean
false
false
190
lean
def e: set nat := { } def x: set nat := { 1, 2, 3 } def y: set nat := { 2, 3, 4 } def z := x ∪ y def w := x ∩ y #check false #check e #reduce e #check z #reduce z #check w #reduce w
e76b84c89d17e7df4e8fbbca76446e396fc45d38
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/linear_algebra/lagrange.lean
f7e819cb12038bbd5eb274e79b72832dda157282
[]
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,380
lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Kenny Lau. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.ring_theory.polynomial.default import Mathlib.algebra.big_operators.basic import Mathlib.PostPort universes u namespace Mathlib /-! # Lagrange interpolation ## Main definitions * `lagrange.basis s x` where `s : finset F` and `x : F`: the Lagrange basis polynomial that evaluates to `1` at `x` and `0` at other elements of `s`. * `lagrange.interpolate s f` where `s : finset F` and `f : s → F`: the Lagrange interpolant that evaluates to `f x` at `x` for `x ∈ s`. -/ namespace lagrange /-- Lagrange basis polynomials that evaluate to 1 at `x` and 0 at other elements of `s`. -/ def basis {F : Type u} [DecidableEq F] [field F] (s : finset F) (x : F) : polynomial F := finset.prod (finset.erase s x) fun (y : F) => coe_fn polynomial.C (x - y⁻¹) * (polynomial.X - coe_fn polynomial.C y) @[simp] theorem basis_empty {F : Type u} [DecidableEq F] [field F] (x : F) : basis ∅ x = 1 := rfl @[simp] theorem eval_basis_self {F : Type u} [DecidableEq F] [field F] (s : finset F) (x : F) : polynomial.eval x (basis s x) = 1 := sorry @[simp] theorem eval_basis_ne {F : Type u} [DecidableEq F] [field F] (s : finset F) (x : F) (y : F) (h1 : y ∈ s) (h2 : y ≠ x) : polynomial.eval y (basis s x) = 0 := sorry theorem eval_basis {F : Type u} [DecidableEq F] [field F] (s : finset F) (x : F) (y : F) (h : y ∈ s) : polynomial.eval y (basis s x) = ite (y = x) 1 0 := sorry @[simp] theorem nat_degree_basis {F : Type u} [DecidableEq F] [field F] (s : finset F) (x : F) (hx : x ∈ s) : polynomial.nat_degree (basis s x) = finset.card s - 1 := sorry /-- Lagrange interpolation: given a finset `s` and a function `f : s → F`, `interpolate s f` is the unique polynomial of degree `< s.card` that takes value `f x` on all `x` in `s`. -/ def interpolate {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : ↥↑s → F) : polynomial F := finset.sum (finset.attach s) fun (x : Subtype fun (x : F) => x ∈ s) => coe_fn polynomial.C (f x) * basis s ↑x @[simp] theorem interpolate_empty {F : Type u} [DecidableEq F] [field F] (f : ↥↑∅ → F) : interpolate ∅ f = 0 := rfl @[simp] theorem eval_interpolate {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : ↥↑s → F) (x : F) (H : x ∈ s) : polynomial.eval x (interpolate s f) = f { val := x, property := H } := sorry theorem degree_interpolate_lt {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : ↥↑s → F) : polynomial.degree (interpolate s f) < ↑(finset.card s) := sorry /-- Linear version of `interpolate`. -/ def linterpolate {F : Type u} [DecidableEq F] [field F] (s : finset F) : linear_map F (↥↑s → F) (polynomial F) := linear_map.mk (interpolate s) sorry sorry @[simp] theorem interpolate_add {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : ↥↑s → F) (g : ↥↑s → F) : interpolate s (f + g) = interpolate s f + interpolate s g := linear_map.map_add (linterpolate s) f g @[simp] theorem interpolate_zero {F : Type u} [DecidableEq F] [field F] (s : finset F) : interpolate s 0 = 0 := linear_map.map_zero (linterpolate s) @[simp] theorem interpolate_neg {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : ↥↑s → F) : interpolate s (-f) = -interpolate s f := linear_map.map_neg (linterpolate s) f @[simp] theorem interpolate_sub {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : ↥↑s → F) (g : ↥↑s → F) : interpolate s (f - g) = interpolate s f - interpolate s g := linear_map.map_sub (linterpolate s) f g @[simp] theorem interpolate_smul {F : Type u} [DecidableEq F] [field F] (s : finset F) (c : F) (f : ↥↑s → F) : interpolate s (c • f) = c • interpolate s f := linear_map.map_smul (linterpolate s) c f theorem eq_zero_of_eval_eq_zero {F' : Type u} [field F'] (s' : finset F') {f : polynomial F'} (hf1 : polynomial.degree f < ↑(finset.card s')) (hf2 : ∀ (x : F'), x ∈ s' → polynomial.eval x f = 0) : f = 0 := sorry theorem eq_of_eval_eq {F' : Type u} [field F'] (s' : finset F') {f : polynomial F'} {g : polynomial F'} (hf : polynomial.degree f < ↑(finset.card s')) (hg : polynomial.degree g < ↑(finset.card s')) (hfg : ∀ (x : F'), x ∈ s' → polynomial.eval x f = polynomial.eval x g) : f = g := sorry theorem eq_interpolate {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : polynomial F) (hf : polynomial.degree f < ↑(finset.card s)) : (interpolate s fun (x : ↥↑s) => polynomial.eval (↑x) f) = f := eq_of_eval_eq s (degree_interpolate_lt s fun (x : ↥↑s) => polynomial.eval (↑x) f) hf fun (x : F) (hx : x ∈ s) => eval_interpolate s (fun (x : ↥↑s) => polynomial.eval (↑x) f) x hx /-- Lagrange interpolation induces isomorphism between functions from `s` and polynomials of degree less than `s.card`. -/ def fun_equiv_degree_lt {F : Type u} [DecidableEq F] [field F] (s : finset F) : linear_equiv F (↥(polynomial.degree_lt F (finset.card s))) (↥↑s → F) := linear_equiv.mk (fun (f : ↥(polynomial.degree_lt F (finset.card s))) (x : ↥↑s) => polynomial.eval (↑x) (subtype.val f)) sorry sorry (fun (f : ↥↑s → F) => { val := interpolate s f, property := sorry }) sorry sorry
7b0a488739fcefeb5baf7b1c53b4f3ae548dc3dc
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/algebra/euclidean_domain/basic.lean
676b8b96855e826afa4a30bf9a478e6ffec80988
[ "Apache-2.0" ]
permissive
alreadydone/mathlib
dc0be621c6c8208c581f5170a8216c5ba6721927
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
refs/heads/master
1,685,523,275,196
1,670,184,141,000
1,670,184,141,000
287,574,545
0
0
Apache-2.0
1,670,290,714,000
1,597,421,623,000
Lean
UTF-8
Lean
false
false
9,755
lean
/- Copyright (c) 2018 Louis Carlin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Louis Carlin, Mario Carneiro -/ import algebra.euclidean_domain.defs import algebra.ring.divisibility import algebra.ring.regular import algebra.group_with_zero.divisibility /-! # Lemmas about Euclidean domains ## Main statements * `gcd_eq_gcd_ab`: states Bézout's lemma for Euclidean domains. -/ universe u namespace euclidean_domain variable {R : Type u} variables [euclidean_domain R] local infix ` ≺ `:50 := euclidean_domain.r lemma mul_div_cancel_left {a : R} (b) (a0 : a ≠ 0) : a * b / a = b := eq.symm $ eq_of_sub_eq_zero $ classical.by_contradiction $ λ h, begin have := mul_left_not_lt a h, rw [mul_sub, sub_eq_iff_eq_add'.2 (div_add_mod (a*b) a).symm] at this, exact this (mod_lt _ a0) end lemma mul_div_cancel (a) {b : R} (b0 : b ≠ 0) : a * b / b = a := by { rw mul_comm, exact mul_div_cancel_left a b0 } @[simp] lemma mod_eq_zero {a b : R} : a % b = 0 ↔ b ∣ a := ⟨λ h, by { rw [← div_add_mod a b, h, add_zero], exact dvd_mul_right _ _ }, λ ⟨c, e⟩, begin rw [e, ← add_left_cancel_iff, div_add_mod, add_zero], haveI := classical.dec, by_cases b0 : b = 0, { simp only [b0, zero_mul] }, { rw [mul_div_cancel_left _ b0] } end⟩ @[simp] lemma mod_self (a : R) : a % a = 0 := mod_eq_zero.2 dvd_rfl lemma dvd_mod_iff {a b c : R} (h : c ∣ b) : c ∣ a % b ↔ c ∣ a := by rw [dvd_add_iff_right (h.mul_right _), div_add_mod] @[simp] lemma mod_one (a : R) : a % 1 = 0 := mod_eq_zero.2 (one_dvd _) @[simp] lemma zero_mod (b : R) : 0 % b = 0 := mod_eq_zero.2 (dvd_zero _) @[simp, priority 900] lemma zero_div {a : R} : 0 / a = 0 := classical.by_cases (λ a0 : a = 0, a0.symm ▸ div_zero 0) (λ a0, by simpa only [zero_mul] using mul_div_cancel 0 a0) @[simp, priority 900] lemma div_self {a : R} (a0 : a ≠ 0) : a / a = 1 := by simpa only [one_mul] using mul_div_cancel 1 a0 lemma eq_div_of_mul_eq_left {a b c : R} (hb : b ≠ 0) (h : a * b = c) : a = c / b := by rw [← h, mul_div_cancel _ hb] lemma eq_div_of_mul_eq_right {a b c : R} (ha : a ≠ 0) (h : a * b = c) : b = c / a := by rw [← h, mul_div_cancel_left _ ha] theorem mul_div_assoc (x : R) {y z : R} (h : z ∣ y) : x * y / z = x * (y / z) := begin classical, by_cases hz : z = 0, { subst hz, rw [div_zero, div_zero, mul_zero] }, rcases h with ⟨p, rfl⟩, rw [mul_div_cancel_left _ hz, mul_left_comm, mul_div_cancel_left _ hz] end @[simp, priority 900] -- This generalizes `int.div_one`, see note [simp-normal form] lemma div_one (p : R) : p / 1 = p := (euclidean_domain.eq_div_of_mul_eq_left (one_ne_zero' R) (mul_one p)).symm lemma div_dvd_of_dvd {p q : R} (hpq : q ∣ p) : p / q ∣ p := begin by_cases hq : q = 0, { rw [hq, zero_dvd_iff] at hpq, rw hpq, exact dvd_zero _ }, use q, rw [mul_comm, ← euclidean_domain.mul_div_assoc _ hpq, mul_comm, euclidean_domain.mul_div_cancel _ hq] end lemma dvd_div_of_mul_dvd {a b c : R} (h : a * b ∣ c) : b ∣ c / a := begin rcases eq_or_ne a 0 with rfl | ha, { simp only [div_zero, dvd_zero] }, rcases h with ⟨d, rfl⟩, refine ⟨d, _⟩, rw [mul_assoc, mul_div_cancel_left _ ha] end section gcd variable [decidable_eq R] @[simp] theorem gcd_zero_right (a : R) : gcd a 0 = a := by { rw gcd, split_ifs; simp only [h, zero_mod, gcd_zero_left] } theorem gcd_val (a b : R) : gcd a b = gcd (b % a) a := by { rw gcd, split_ifs; [simp only [h, mod_zero, gcd_zero_right], refl]} theorem gcd_dvd (a b : R) : gcd a b ∣ a ∧ gcd a b ∣ b := gcd.induction a b (λ b, by { rw gcd_zero_left, exact ⟨dvd_zero _, dvd_rfl⟩ }) (λ a b aneq ⟨IH₁, IH₂⟩, by { rw gcd_val, exact ⟨IH₂, (dvd_mod_iff IH₂).1 IH₁⟩ }) theorem gcd_dvd_left (a b : R) : gcd a b ∣ a := (gcd_dvd a b).left theorem gcd_dvd_right (a b : R) : gcd a b ∣ b := (gcd_dvd a b).right protected theorem gcd_eq_zero_iff {a b : R} : gcd a b = 0 ↔ a = 0 ∧ b = 0 := ⟨λ h, by simpa [h] using gcd_dvd a b, by { rintro ⟨rfl, rfl⟩, exact gcd_zero_right _ }⟩ theorem dvd_gcd {a b c : R} : c ∣ a → c ∣ b → c ∣ gcd a b := gcd.induction a b (λ _ _ H, by simpa only [gcd_zero_left] using H) (λ a b a0 IH ca cb, by { rw gcd_val, exact IH ((dvd_mod_iff ca).2 cb) ca }) theorem gcd_eq_left {a b : R} : gcd a b = a ↔ a ∣ b := ⟨λ h, by {rw ← h, apply gcd_dvd_right }, λ h, by rw [gcd_val, mod_eq_zero.2 h, gcd_zero_left]⟩ @[simp] theorem gcd_one_left (a : R) : gcd 1 a = 1 := gcd_eq_left.2 (one_dvd _) @[simp] theorem gcd_self (a : R) : gcd a a = a := gcd_eq_left.2 dvd_rfl @[simp] theorem xgcd_aux_fst (x y : R) : ∀ s t s' t', (xgcd_aux x s t y s' t').1 = gcd x y := gcd.induction x y (by { intros, rw [xgcd_zero_left, gcd_zero_left] }) (λ x y h IH s t s' t', by { simp only [xgcd_aux_rec h, if_neg h, IH], rw ← gcd_val }) theorem xgcd_aux_val (x y : R) : xgcd_aux x 1 0 y 0 1 = (gcd x y, xgcd x y) := by rw [xgcd, ← xgcd_aux_fst x y 1 0 0 1, prod.mk.eta] private def P (a b : R) : R × R × R → Prop | (r, s, t) := (r : R) = a * s + b * t theorem xgcd_aux_P (a b : R) {r r' : R} : ∀ {s t s' t'}, P a b (r, s, t) → P a b (r', s', t') → P a b (xgcd_aux r s t r' s' t') := gcd.induction r r' (by { intros, simpa only [xgcd_zero_left] }) $ λ x y h IH s t s' t' p p', begin rw [xgcd_aux_rec h], refine IH _ p, unfold P at p p' ⊢, rw [mul_sub, mul_sub, add_sub, sub_add_eq_add_sub, ← p', sub_sub, mul_comm _ s, ← mul_assoc, mul_comm _ t, ← mul_assoc, ← add_mul, ← p, mod_eq_sub_mul_div] end /-- An explicit version of **Bézout's lemma** for Euclidean domains. -/ theorem gcd_eq_gcd_ab (a b : R) : (gcd a b : R) = a * gcd_a a b + b * gcd_b a b := by { have := @xgcd_aux_P _ _ _ a b a b 1 0 0 1 (by rw [P, mul_one, mul_zero, add_zero]) (by rw [P, mul_one, mul_zero, zero_add]), rwa [xgcd_aux_val, xgcd_val] at this } @[priority 70] -- see Note [lower instance priority] instance (R : Type*) [e : euclidean_domain R] : is_domain R := by { haveI := classical.dec_eq R, exact { eq_zero_or_eq_zero_of_mul_eq_zero := λ a b h, (or_iff_not_and_not.2 $ λ h0, h0.1 $ by rw [← mul_div_cancel a h0.2, h, zero_div]), ..e }} end gcd section lcm variables [decidable_eq R] theorem dvd_lcm_left (x y : R) : x ∣ lcm x y := classical.by_cases (assume hxy : gcd x y = 0, by { rw [lcm, hxy, div_zero], exact dvd_zero _ }) (λ hxy, let ⟨z, hz⟩ := (gcd_dvd x y).2 in ⟨z, eq.symm $ eq_div_of_mul_eq_left hxy $ by rw [mul_right_comm, mul_assoc, ← hz]⟩) theorem dvd_lcm_right (x y : R) : y ∣ lcm x y := classical.by_cases (assume hxy : gcd x y = 0, by { rw [lcm, hxy, div_zero], exact dvd_zero _ }) (λ hxy, let ⟨z, hz⟩ := (gcd_dvd x y).1 in ⟨z, eq.symm $ eq_div_of_mul_eq_right hxy $ by rw [← mul_assoc, mul_right_comm, ← hz]⟩) theorem lcm_dvd {x y z : R} (hxz : x ∣ z) (hyz : y ∣ z) : lcm x y ∣ z := begin rw lcm, by_cases hxy : gcd x y = 0, { rw [hxy, div_zero], rw euclidean_domain.gcd_eq_zero_iff at hxy, rwa hxy.1 at hxz }, rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩, suffices : x * y ∣ z * gcd x y, { cases this with p hp, use p, generalize_hyp : gcd x y = g at hxy hs hp ⊢, subst hs, rw [mul_left_comm, mul_div_cancel_left _ hxy, ← mul_left_inj' hxy, hp], rw [← mul_assoc], simp only [mul_right_comm] }, rw [gcd_eq_gcd_ab, mul_add], apply dvd_add, { rw mul_left_comm, exact mul_dvd_mul_left _ (hyz.mul_right _) }, { rw [mul_left_comm, mul_comm], exact mul_dvd_mul_left _ (hxz.mul_right _) } end @[simp] lemma lcm_dvd_iff {x y z : R} : lcm x y ∣ z ↔ x ∣ z ∧ y ∣ z := ⟨λ hz, ⟨(dvd_lcm_left _ _).trans hz, (dvd_lcm_right _ _).trans hz⟩, λ ⟨hxz, hyz⟩, lcm_dvd hxz hyz⟩ @[simp] lemma lcm_zero_left (x : R) : lcm 0 x = 0 := by rw [lcm, zero_mul, zero_div] @[simp] lemma lcm_zero_right (x : R) : lcm x 0 = 0 := by rw [lcm, mul_zero, zero_div] @[simp] lemma lcm_eq_zero_iff {x y : R} : lcm x y = 0 ↔ x = 0 ∨ y = 0 := begin split, { intro hxy, rw [lcm, mul_div_assoc _ (gcd_dvd_right _ _), mul_eq_zero] at hxy, apply or_of_or_of_imp_right hxy, intro hy, by_cases hgxy : gcd x y = 0, { rw euclidean_domain.gcd_eq_zero_iff at hgxy, exact hgxy.2 }, { rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩, generalize_hyp : gcd x y = g at hr hs hy hgxy ⊢, subst hs, rw [mul_div_cancel_left _ hgxy] at hy, rw [hy, mul_zero] } }, rintro (hx | hy), { rw [hx, lcm_zero_left] }, { rw [hy, lcm_zero_right] } end @[simp] lemma gcd_mul_lcm (x y : R) : gcd x y * lcm x y = x * y := begin rw lcm, by_cases h : gcd x y = 0, { rw [h, zero_mul], rw euclidean_domain.gcd_eq_zero_iff at h, rw [h.1, zero_mul] }, rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩, generalize_hyp : gcd x y = g at h hr ⊢, subst hr, rw [mul_assoc, mul_div_cancel_left _ h] end end lcm section div lemma mul_div_mul_cancel {a b c : R} (ha : a ≠ 0) (hcb : c ∣ b) : a * b / (a * c) = b / c := begin by_cases hc : c = 0, { simp [hc] }, refine eq_div_of_mul_eq_right hc (mul_left_cancel₀ ha _), rw [← mul_assoc, ← mul_div_assoc _ (mul_dvd_mul_left a hcb), mul_div_cancel_left _ (mul_ne_zero ha hc)] end lemma mul_div_mul_comm_of_dvd_dvd {a b c d : R} (hac : c ∣ a) (hbd : d ∣ b) : a * b / (c * d) = a / c * (b / d) := begin rcases eq_or_ne c 0 with rfl | hc0, { simp }, rcases eq_or_ne d 0 with rfl | hd0, { simp }, obtain ⟨k1, rfl⟩ := hac, obtain ⟨k2, rfl⟩ := hbd, rw [mul_div_cancel_left _ hc0, mul_div_cancel_left _ hd0, mul_mul_mul_comm, mul_div_cancel_left _ (mul_ne_zero hc0 hd0)], end end div end euclidean_domain
f317f79faf67d5370a15d017e5774cf85e1345cb
64874bd1010548c7f5a6e3e8902efa63baaff785
/tests/lean/run/class8.lean
2982e5679fae8693b27539af0d3a52c84bca1748
[ "Apache-2.0" ]
permissive
tjiaqi/lean
4634d729795c164664d10d093f3545287c76628f
d0ce4cf62f4246b0600c07e074d86e51f2195e30
refs/heads/master
1,622,323,796,480
1,422,643,069,000
1,422,643,069,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,077
lean
import logic data.prod open tactic prod inductive inh [class] (A : Type) : Prop := intro : A -> inh A attribute inh.intro [instance] theorem inh_elim {A : Type} {B : Prop} (H1 : inh A) (H2 : A → B) : B := inh.rec H2 H1 theorem inh_exists {A : Type} {P : A → Prop} (H : ∃x, P x) : inh A := obtain w Hw, from H, inh.intro w theorem inh_bool [instance] : inh Prop := inh.intro true theorem inh_fun [instance] {A B : Type} (H : inh B) : inh (A → B) := inh.rec (λb, inh.intro (λa : A, b)) H theorem pair_inh [instance] {A : Type} {B : Type} (H1 : inh A) (H2 : inh B) : inh (prod A B) := inh_elim H1 (λa, inh_elim H2 (λb, inh.intro (pair a b))) definition assump := eassumption tactic_hint assump theorem tst {A B : Type} (H : inh B) : inh (A → B → B) set_option class.trace_instances true theorem T1 {A B C D : Type} {P : C → Prop} (a : A) (H1 : inh B) (H2 : ∃x, P x) : inh ((A → A) × B × (D → C) × Prop) := have h1 [visible] : inh A, from inh.intro a, have h2 [visible] : inh C, from inh_exists H2, _ (* print(get_env():find("T1"):value()) *)
4acb50df3a3c7681ab58e134c6ce537a9e7bd09a
432d948a4d3d242fdfb44b81c9e1b1baacd58617
/src/linear_algebra/invariant_basis_number.lean
aef037a4421bc6e812d46c61e9de373f2a483b7d
[ "Apache-2.0" ]
permissive
JLimperg/aesop3
306cc6570c556568897ed2e508c8869667252e8a
a4a116f650cc7403428e72bd2e2c4cda300fe03f
refs/heads/master
1,682,884,916,368
1,620,320,033,000
1,620,320,033,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
5,606
lean
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import linear_algebra.finite_dimensional import ring_theory.ideal.basic /-! # Invariant basis number property We say that a ring `R` satisfies the invariant basis number property if there is a well-defined notion of the rank of a finitely generated free (left) `R`-module. Since a finitely generated free module with a basis consisting of `n` elements is linearly equivalent to `fin n → R`, it is sufficient that `(fin n → R) ≃ₗ[R] (fin m → R)` implies `n = m`. ## Main definitions `invariant_basis_number R` is a type class stating that `R` has the invariant basis number property. ## Main results We show that every nontrivial commutative ring has the invariant basis number property. ## Future work So far, there is no API at all for the `invariant_basis_number` class. There are several natural ways to formulate that a module `M` is finitely generated and free, for example `M ≃ₗ[R] (fin n → R)`, `M ≃ₗ[R] (ι → R)`, where `ι` is a fintype, or prividing a basis indexed by a finite type. There should be lemmas applying the invariant basis number property to each situation. The finite version of the invariant basis number property implies the infinite analogue, i.e., that `(ι →₀ R) ≃ₗ[R] (ι' →₀ R)` implies that `cardinal.mk ι = cardinal.mk ι'`. This fact (and its variants) should be formalized. ## References * https://en.wikipedia.org/wiki/Invariant_basis_number ## Tags free module, rank, invariant basis number, IBN -/ noncomputable theory open_locale classical big_operators universes u v w section variables (R : Type u) [ring R] /-- We say that `R` has the invariant basis number property if `(fin n → R) ≃ₗ[R] (fin m → R)` implies `n = m`. This gives rise to a well-defined notion of rank of a finitely generated free module. -/ class invariant_basis_number : Prop := (eq_of_fin_equiv : ∀ {n m : ℕ}, ((fin n → R) ≃ₗ[R] (fin m → R)) → n = m) end section variables (R : Type u) [ring R] [invariant_basis_number R] lemma eq_of_fin_equiv {n m : ℕ} : ((fin n → R) ≃ₗ[R] (fin m → R)) → n = m := invariant_basis_number.eq_of_fin_equiv lemma nontrivial_of_invariant_basis_number : nontrivial R := begin by_contra h, refine zero_ne_one (eq_of_fin_equiv R _), haveI := not_nontrivial_iff_subsingleton.1 h, haveI : subsingleton (fin 1 → R) := ⟨λ a b, funext $ λ x, subsingleton.elim _ _⟩, refine { .. }; { intros, exact 0 } <|> tidy end end section open finite_dimensional /-- A field has invariant basis number. This will be superseded below by the fact that any nonzero commutative ring has invariant basis number. -/ lemma invariant_basis_number_field {K : Type u} [field K] : invariant_basis_number K := ⟨λ n m e, calc n = fintype.card (fin n) : eq.symm $ fintype.card_fin n ... = finrank K (fin n → K) : eq.symm $ finrank_eq_card_basis (pi.is_basis_fun K (fin n)) ... = finrank K (fin m → K) : linear_equiv.finrank_eq e ... = fintype.card (fin m) : finrank_eq_card_basis (pi.is_basis_fun K (fin m)) ... = m : fintype.card_fin m⟩ end /-! We want to show that nontrivial commutative rings have invariant basis number. The idea is to take a maximal ideal `I` of `R` and use an isomorphism `R^n ≃ R^m` of `R` modules to produce an isomorphism `(R/I)^n ≃ (R/I)^m` of `R/I`-modules, which will imply `n = m` since `R/I` is a field and we know that fields have invariant basis number. We construct the isomorphism in two steps: 1. We construct the ring `R^n/I^n`, show that it is an `R/I`-module and show that there is an isomorphism of `R/I`-modules `R^n/I^n ≃ (R/I)^n`. This isomorphism is called `ideal.pi_quot_equiv` and is located in the file `ring_theory/ideals.lean`. 2. We construct an isomorphism of `R/I`-modules `R^n/I^n ≃ R^m/I^m` using the isomorphism `R^n ≃ R^m`. -/ section variables {R : Type u} [comm_ring R] (I : ideal R) {ι : Type v} [fintype ι] {ι' : Type w} /-- An `R`-linear map `R^n → R^m` induces a function `R^n/I^n → R^m/I^m`. -/ private def induced_map (I : ideal R) (e : (ι → R) →ₗ[R] (ι' → R)) : (I.pi ι).quotient → (I.pi ι').quotient := λ x, quotient.lift_on' x (λ y, ideal.quotient.mk _ (e y)) begin refine λ a b hab, ideal.quotient.eq.2 (λ h, _), rw ←linear_map.map_sub, exact ideal.map_pi _ _ hab e h, end /-- An isomorphism of `R`-modules `R^n ≃ R^m` induces an isomorphism `R/I`-modules `R^n/I^n ≃ R^m/I^m`. -/ private def induced_equiv [fintype ι'] (I : ideal R) (e : (ι → R) ≃ₗ[R] (ι' → R)) : (I.pi ι).quotient ≃ₗ[I.quotient] (I.pi ι').quotient := begin refine { to_fun := induced_map I e, inv_fun := induced_map I e.symm, .. }, all_goals { rintro ⟨a⟩ ⟨b⟩ <|> rintro ⟨a⟩, change ideal.quotient.mk _ _ = ideal.quotient.mk _ _, congr, simp } end end section local attribute [instance] invariant_basis_number_field local attribute [instance, priority 1] ideal.quotient.field /-- Nontrivial commutative rings have the invariant basis number property. -/ @[priority 100] instance invariant_basis_number_of_nontrivial_of_comm_ring {R : Type u} [comm_ring R] [nontrivial R] : invariant_basis_number R := ⟨λ n m e, let ⟨I, hI⟩ := ideal.exists_maximal R in by exactI eq_of_fin_equiv I.quotient ((ideal.pi_quot_equiv _ _).symm.trans ((induced_equiv _ e).trans (ideal.pi_quot_equiv _ _)))⟩ end
d585543a043ad19873761aebb3e65beb14b35b96
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/topology/topological_fiber_bundle.lean
9d87be93d51e6a9cfe8551cac0ed9459cca29611
[]
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
26,714
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_2 u_3 u_4 l u_5 u_6 u_1 namespace Mathlib /-! # Fiber bundles A topological fiber bundle with fiber `F` over a base `B` is a space projecting on `B` for which the fibers are all homeomorphic to `F`, such that the local situation around each point is a direct product. We define a predicate `is_topological_fiber_bundle F p` saying that `p : Z → B` is a topological fiber bundle with fiber `F`. It is in general nontrivial to construct a fiber bundle. A way is to start from the knowledge of how changes of local trivializations act on the fiber. From this, one can construct the total space of the bundle and its topology by a suitable gluing construction. The main content of this file is an implementation of this construction: starting from an object of type `topological_fiber_bundle_core` registering the trivialization changes, one gets the corresponding fiber bundle and projection. ## Main definitions * `bundle_trivialization F p` : structure extending local homeomorphisms, defining a local trivialization of a topological space `Z` with projection `p` and fiber `F`. * `is_topological_fiber_bundle F p` : Prop saying that the map `p` between topological spaces is a fiber bundle with fiber `F`. * `topological_fiber_bundle_core ι B F` : structure registering how changes of coordinates act on the fiber `F` above open subsets of `B`, where local trivializations are indexed by `ι`. Let `Z : topological_fiber_bundle_core ι B F`. Then we define * `Z.total_space` : the total space of `Z`, defined as a `Type` as `Σ (b : B), F`, but with a twisted topology coming from the fiber bundle structure * `Z.proj` : projection from `Z.total_space` to `B`. It is continuous. * `Z.fiber x` : the fiber above `x`, homeomorphic to `F` (and defeq to `F` as a type). * `Z.local_triv i`: for `i : ι`, a local homeomorphism from `Z.total_space` to `B × F`, that realizes a trivialization above the set `Z.base_set i`, which is an open set in `B`. ## Implementation notes A topological fiber bundle with fiber `F` over a base `B` is a family of spaces isomorphic to `F`, indexed by `B`, which is locally trivial in the following sense: there is a covering of `B` by open sets such that, on each such open set `s`, the bundle is isomorphic to `s × F`. To construct a fiber bundle formally, the main data is what happens when one changes trivializations from `s × F` to `s' × F` on `s ∩ s'`: one should get a family of homeomorphisms of `F`, depending continuously on the base point, satisfying basic compatibility conditions (cocycle property). Useful classes of bundles can then be specified by requiring that these homeomorphisms of `F` belong to some subgroup, preserving some structure (the "structure group of the bundle"): then these structures are inherited by the fibers of the bundle. Given such trivialization change data (encoded below in a structure called `topological_fiber_bundle_core`), one can construct the fiber bundle. The intrinsic canonical mathematical construction is the following. The fiber above `x` is the disjoint union of `F` over all trivializations, modulo the gluing identifications: one gets a fiber which is isomorphic to `F`, but non-canonically (each choice of one of the trivializations around `x` gives such an isomorphism). Given a trivialization over a set `s`, one gets an isomorphism between `s × F` and `proj^{-1} s`, by using the identification corresponding to this trivialization. One chooses the topology on the bundle that makes all of these into homeomorphisms. For the practical implementation, it turns out to be more convenient to avoid completely the gluing and quotienting construction above, and to declare above each `x` that the fiber is `F`, but thinking that it corresponds to the `F` coming from the choice of one trivialization around `x`. This has several practical advantages: * without any work, one gets a topological space structure on the fiber. And if `F` has more structure it is inherited for free by the fiber. * In the case of the tangent bundle of manifolds, this implies that on vector spaces the derivative (from `F` to `F`) and the manifold derivative (from `tangent_space I x` to `tangent_space I' (f x)`) are equal. A drawback is that some silly constructions will typecheck: in the case of the tangent bundle, one can add two vectors in different tangent spaces (as they both are elements of `F` from the point of view of Lean). To solve this, one could mark the tangent space as irreducible, but then one would lose the identification of the tangent space to `F` with `F`. There is however a big advantage of this situation: even if Lean can not check that two basepoints are defeq, it will accept the fact that the tangent spaces are the same. For instance, if two maps `f` and `g` are locally inverse to each other, one can express that the composition of their derivatives is the identity of `tangent_space I x`. One could fear issues as this composition goes from `tangent_space I x` to `tangent_space I (g (f x))` (which should be the same, but should not be obvious to Lean as it does not know that `g (f x) = x`). As these types are the same to Lean (equal to `F`), there are in fact no dependent type difficulties here! For this construction of a fiber bundle from a `topological_fiber_bundle_core`, we should thus choose for each `x` one specific trivialization around it. We include this choice in the definition of the `topological_fiber_bundle_core`, as it makes some constructions more functorial and it is a nice way to say that the trivializations cover the whole space `B`. With this definition, the type of the fiber bundle space constructed from the core data is just `Σ (b : B), F `, but the topology is not the product one, in general. We also take the indexing type (indexing all the trivializations) as a parameter to the fiber bundle core: it could always be taken as a subtype of all the maps from open subsets of `B` to continuous maps of `F`, but in practice it will sometimes be something else. For instance, on a manifold, one will use the set of charts as a good parameterization for the trivializations of the tangent bundle. Or for the pullback of a `topological_fiber_bundle_core`, the indexing type will be the same as for the initial bundle. ## Tags Fiber bundle, topological bundle, vector bundle, local trivialization, structure group -/ /-- A structure extending local homeomorphisms, defining a local trivialization of a projection `proj : Z → B` with fiber `F`, as a local homeomorphism between `Z` and `B × F` defined between two sets of the form `proj ⁻¹' base_set` and `base_set × F`, acting trivially on the first coordinate. -/ structure bundle_trivialization {B : Type u_2} (F : Type u_3) {Z : Type u_4} [topological_space B] [topological_space Z] [topological_space F] (proj : Z → B) extends local_homeomorph Z (B × F) where base_set : set B open_base_set : is_open base_set source_eq : local_equiv.source (local_homeomorph.to_local_equiv _to_local_homeomorph) = proj ⁻¹' base_set target_eq : local_equiv.target (local_homeomorph.to_local_equiv _to_local_homeomorph) = set.prod base_set set.univ proj_to_fun : ∀ (p : Z), p ∈ local_equiv.source (local_homeomorph.to_local_equiv _to_local_homeomorph) → prod.fst (local_equiv.to_fun (local_homeomorph.to_local_equiv _to_local_homeomorph) p) = proj p protected instance bundle_trivialization.has_coe_to_fun {B : Type u_2} (F : Type u_3) {Z : Type u_4} [topological_space B] [topological_space Z] [topological_space F] (proj : Z → B) : has_coe_to_fun (bundle_trivialization F proj) := has_coe_to_fun.mk (fun (e : bundle_trivialization F proj) => Z → B × F) fun (e : bundle_trivialization F proj) => local_equiv.to_fun (local_homeomorph.to_local_equiv (bundle_trivialization.to_local_homeomorph e)) @[simp] theorem bundle_trivialization.coe_coe {B : Type u_2} (F : Type u_3) {Z : Type u_4} [topological_space B] [topological_space Z] [topological_space F] (proj : Z → B) (e : bundle_trivialization F proj) (x : Z) : coe_fn (bundle_trivialization.to_local_homeomorph e) x = coe_fn e x := rfl @[simp] theorem bundle_trivialization.coe_mk {B : Type u_2} (F : Type u_3) {Z : Type u_4} [topological_space B] [topological_space Z] [topological_space F] (proj : Z → B) (e : local_homeomorph Z (B × F)) (i : set B) (j : is_open i) (k : local_equiv.source (local_homeomorph.to_local_equiv e) = proj ⁻¹' i) (l : local_equiv.target (local_homeomorph.to_local_equiv e) = set.prod i set.univ) (m : ∀ (p : Z), p ∈ local_equiv.source (local_homeomorph.to_local_equiv e) → prod.fst (local_equiv.to_fun (local_homeomorph.to_local_equiv e) p) = proj p) (x : Z) : coe_fn (bundle_trivialization.mk e i j k l m) x = coe_fn e x := rfl /-- A topological fiber bundle with fiber F over a base B is a space projecting on B for which the fibers are all homeomorphic to F, such that the local situation around each point is a direct product. -/ def is_topological_fiber_bundle {B : Type u_2} (F : Type u_3) {Z : Type u_4} [topological_space B] [topological_space Z] [topological_space F] (proj : Z → B) := ∀ (x : Z), ∃ (e : bundle_trivialization F proj), x ∈ local_equiv.source (local_homeomorph.to_local_equiv (bundle_trivialization.to_local_homeomorph e)) @[simp] theorem bundle_trivialization.coe_fst {B : Type u_2} {F : Type u_3} {Z : Type u_4} [topological_space B] [topological_space Z] [topological_space F] {proj : Z → B} (e : bundle_trivialization F proj) {x : Z} (ex : x ∈ local_equiv.source (local_homeomorph.to_local_equiv (bundle_trivialization.to_local_homeomorph e))) : prod.fst (coe_fn e x) = proj x := bundle_trivialization.proj_to_fun e x ex /-- In the domain of a bundle trivialization, the projection is continuous-/ theorem bundle_trivialization.continuous_at_proj {B : Type u_2} {F : Type u_3} {Z : Type u_4} [topological_space B] [topological_space Z] [topological_space F] {proj : Z → B} (e : bundle_trivialization F proj) {x : Z} (ex : x ∈ local_equiv.source (local_homeomorph.to_local_equiv (bundle_trivialization.to_local_homeomorph e))) : continuous_at proj x := sorry /-- The projection from a topological fiber bundle to its base is continuous. -/ theorem is_topological_fiber_bundle.continuous_proj {B : Type u_2} {F : Type u_3} {Z : Type u_4} [topological_space B] [topological_space Z] [topological_space F] {proj : Z → B} (h : is_topological_fiber_bundle F proj) : continuous proj := sorry /-- The projection from a topological fiber bundle to its base is an open map. -/ theorem is_topological_fiber_bundle.is_open_map_proj {B : Type u_2} {F : Type u_3} {Z : Type u_4} [topological_space B] [topological_space Z] [topological_space F] {proj : Z → B} (h : is_topological_fiber_bundle F proj) : is_open_map proj := sorry /-- The first projection in a product is a topological fiber bundle. -/ theorem is_topological_fiber_bundle_fst {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] : is_topological_fiber_bundle F prod.fst := sorry /-- The second projection in a product is a topological fiber bundle. -/ theorem is_topological_fiber_bundle_snd {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] : is_topological_fiber_bundle F prod.snd := sorry /-- Core data defining a locally trivial topological bundle with fiber `F` over a topological space `B`. Note that "bundle" is used in its mathematical sense. This is the (computer science) bundled version, i.e., all the relevant data is contained in the following structure. A family of local trivializations is indexed by a type ι, on open subsets `base_set i` for each `i : ι`. Trivialization changes from `i` to `j` are given by continuous maps `coord_change i j` from `base_set i ∩ base_set j` to the set of homeomorphisms of `F`, but we express them as maps `B → F → F` and require continuity on `(base_set i ∩ base_set j) × F` to avoid the topology on the space of continuous maps on `F`. -/ structure topological_fiber_bundle_core (ι : Type u_4) (B : Type u_5) [topological_space B] (F : Type u_6) [topological_space F] where base_set : ι → set B is_open_base_set : ∀ (i : ι), is_open (base_set i) index_at : B → ι mem_base_set_at : ∀ (x : B), x ∈ base_set (index_at x) coord_change : ι → ι → B → F → F coord_change_self : ∀ (i : ι) (x : B), x ∈ base_set i → ∀ (v : F), coord_change i i x v = v coord_change_continuous : ∀ (i j : ι), continuous_on (fun (p : B × F) => coord_change i j (prod.fst p) (prod.snd p)) (set.prod (base_set i ∩ base_set j) set.univ) coord_change_comp : ∀ (i j k : ι) (x : B), x ∈ base_set i ∩ base_set j ∩ base_set k → ∀ (v : F), coord_change j k x (coord_change i j x v) = coord_change i k x v namespace topological_fiber_bundle_core /-- The index set of a topological fiber bundle core, as a convenience function for dot notation -/ def index {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) := ι /-- The base space of a topological fiber bundle core, as a convenience function for dot notation -/ def base {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) := B /-- The fiber of a topological fiber bundle core, as a convenience function for dot notation and typeclass inference -/ def fiber {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (x : B) := F protected instance topological_space_fiber {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (x : B) : topological_space (fiber Z x) := id _inst_2 /-- Total space of a topological bundle created from core. It is equal to `Σ (x : B), F` as a type, but the fiber above `x` is registered as `Z.fiber x` to make sure that it is possible to register additional type classes on these fibers. -/ def total_space {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) := sigma fun (x : B) => fiber Z x /-- The projection from the total space of a topological fiber bundle core, on its base. -/ @[simp] def proj {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) : total_space Z → B := fun (p : total_space Z) => sigma.fst p /-- Local homeomorphism version of the trivialization change. -/ def triv_change {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) (j : ι) : local_homeomorph (B × F) (B × F) := local_homeomorph.mk (local_equiv.mk (fun (p : B × F) => (prod.fst p, coord_change Z i j (prod.fst p) (prod.snd p))) (fun (p : B × F) => (prod.fst p, coord_change Z j i (prod.fst p) (prod.snd p))) (set.prod (base_set Z i ∩ base_set Z j) set.univ) (set.prod (base_set Z i ∩ base_set Z j) set.univ) sorry sorry sorry sorry) sorry sorry sorry sorry @[simp] theorem mem_triv_change_source {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) (j : ι) (p : B × F) : p ∈ local_equiv.source (local_homeomorph.to_local_equiv (triv_change Z i j)) ↔ prod.fst p ∈ base_set Z i ∩ base_set Z j := sorry /-- Associate to a trivialization index `i : ι` the corresponding trivialization, i.e., a bijection between `proj ⁻¹ (base_set i)` and `base_set i × F`. As the fiber above `x` is `F` but read in the chart with index `index_at x`, the trivialization in the fiber above x is by definition the coordinate change from i to `index_at x`, so it depends on `x`. The local trivialization will ultimately be a local homeomorphism. For now, we only introduce the local equiv version, denoted with a prime. In further developments, avoid this auxiliary version, and use Z.local_triv instead. -/ def local_triv' {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) : local_equiv (total_space Z) (B × F) := local_equiv.mk (fun (p : total_space Z) => (sigma.fst p, coord_change Z (index_at Z (sigma.fst p)) i (sigma.fst p) (sigma.snd p))) (fun (p : B × F) => sigma.mk (prod.fst p) (coord_change Z i (index_at Z (prod.fst p)) (prod.fst p) (prod.snd p))) (proj Z ⁻¹' base_set Z i) (set.prod (base_set Z i) set.univ) sorry sorry sorry sorry @[simp] theorem mem_local_triv'_source {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) (p : total_space Z) : p ∈ local_equiv.source (local_triv' Z i) ↔ sigma.fst p ∈ base_set Z i := iff.refl (p ∈ local_equiv.source (local_triv' Z i)) @[simp] theorem mem_local_triv'_target {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) (p : B × F) : p ∈ local_equiv.target (local_triv' Z i) ↔ prod.fst p ∈ base_set Z i := sorry @[simp] theorem local_triv'_apply {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) (p : total_space Z) : coe_fn (local_triv' Z i) p = (sigma.fst p, coord_change Z (index_at Z (sigma.fst p)) i (sigma.fst p) (sigma.snd p)) := rfl @[simp] theorem local_triv'_symm_apply {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) (p : B × F) : coe_fn (local_equiv.symm (local_triv' Z i)) p = sigma.mk (prod.fst p) (coord_change Z i (index_at Z (prod.fst p)) (prod.fst p) (prod.snd p)) := rfl /-- The composition of two local trivializations is the trivialization change Z.triv_change i j. -/ theorem local_triv'_trans {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) (j : ι) : local_equiv.trans (local_equiv.symm (local_triv' Z i)) (local_triv' Z j) ≈ local_homeomorph.to_local_equiv (triv_change Z i j) := sorry /-- Topological structure on the total space of a topological bundle created from core, designed so that all the local trivialization are continuous. -/ protected instance to_topological_space {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) : topological_space (total_space Z) := topological_space.generate_from (set.Union fun (i : ι) => set.Union fun (s : set (B × F)) => set.Union fun (s_open : is_open s) => singleton (local_equiv.source (local_triv' Z i) ∩ ⇑(local_triv' Z i) ⁻¹' s)) theorem open_source' {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) : is_open (local_equiv.source (local_triv' Z i)) := sorry theorem open_target' {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) : is_open (local_equiv.target (local_triv' Z i)) := is_open.prod (is_open_base_set Z i) is_open_univ /-- Local trivialization of a topological bundle created from core, as a local homeomorphism. -/ def local_triv {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) : local_homeomorph (total_space Z) (B × F) := local_homeomorph.mk (local_equiv.mk (local_equiv.to_fun (local_triv' Z i)) (local_equiv.inv_fun (local_triv' Z i)) (local_equiv.source (local_triv' Z i)) (local_equiv.target (local_triv' Z i)) sorry sorry sorry sorry) (open_source' Z i) (open_target' Z i) sorry sorry /- We will now state again the basic properties of the local trivializations, but without primes, i.e., for the local homeomorphism instead of the local equiv. -/ @[simp] theorem mem_local_triv_source {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) (p : total_space Z) : p ∈ local_equiv.source (local_homeomorph.to_local_equiv (local_triv Z i)) ↔ sigma.fst p ∈ base_set Z i := iff.refl (p ∈ local_equiv.source (local_homeomorph.to_local_equiv (local_triv Z i))) @[simp] theorem mem_local_triv_target {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) (p : B × F) : p ∈ local_equiv.target (local_homeomorph.to_local_equiv (local_triv Z i)) ↔ prod.fst p ∈ base_set Z i := sorry @[simp] theorem local_triv_apply {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) (p : total_space Z) : coe_fn (local_triv Z i) p = (sigma.fst p, coord_change Z (index_at Z (sigma.fst p)) i (sigma.fst p) (sigma.snd p)) := rfl @[simp] theorem local_triv_symm_fst {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) (p : B × F) : coe_fn (local_homeomorph.symm (local_triv Z i)) p = sigma.mk (prod.fst p) (coord_change Z i (index_at Z (prod.fst p)) (prod.fst p) (prod.snd p)) := rfl /-- The composition of two local trivializations is the trivialization change Z.triv_change i j. -/ theorem local_triv_trans {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) (j : ι) : local_homeomorph.trans (local_homeomorph.symm (local_triv Z i)) (local_triv Z j) ≈ triv_change Z i j := local_triv'_trans Z i j /-- Extended version of the local trivialization of a fiber bundle constructed from core, registering additionally in its type that it is a local bundle trivialization. -/ def local_triv_ext {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (i : ι) : bundle_trivialization F (proj Z) := bundle_trivialization.mk (local_homeomorph.mk (local_homeomorph.to_local_equiv (local_triv Z i)) sorry sorry sorry sorry) (base_set Z i) (is_open_base_set Z i) sorry sorry sorry /-- A topological fiber bundle constructed from core is indeed a topological fiber bundle. -/ theorem is_topological_fiber_bundle {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) : is_topological_fiber_bundle F (proj Z) := sorry /-- The projection on the base of a topological bundle created from core is continuous -/ theorem continuous_proj {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) : continuous (proj Z) := is_topological_fiber_bundle.continuous_proj (is_topological_fiber_bundle Z) /-- The projection on the base of a topological bundle created from core is an open map -/ theorem is_open_map_proj {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) : is_open_map (proj Z) := is_topological_fiber_bundle.is_open_map_proj (is_topological_fiber_bundle Z) /-- Preferred local trivialization of a fiber bundle constructed from core, at a given point, as a local homeomorphism -/ def local_triv_at {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (p : total_space Z) : local_homeomorph (total_space Z) (B × F) := local_triv Z (index_at Z (proj Z p)) @[simp] theorem mem_local_triv_at_source {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (p : total_space Z) : p ∈ local_equiv.source (local_homeomorph.to_local_equiv (local_triv_at Z p)) := sorry @[simp] theorem local_triv_at_fst {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (p : total_space Z) (q : total_space Z) : prod.fst (coe_fn (local_triv_at Z p) q) = sigma.fst q := rfl @[simp] theorem local_triv_at_symm_fst {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (p : total_space Z) (q : B × F) : sigma.fst (coe_fn (local_homeomorph.symm (local_triv_at Z p)) q) = prod.fst q := rfl /-- Preferred local trivialization of a fiber bundle constructed from core, at a given point, as a bundle trivialization -/ def local_triv_at_ext {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (p : total_space Z) : bundle_trivialization F (proj Z) := local_triv_ext Z (index_at Z (proj Z p)) @[simp] theorem local_triv_at_ext_to_local_homeomorph {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (p : total_space Z) : bundle_trivialization.to_local_homeomorph (local_triv_at_ext Z p) = local_triv_at Z p := rfl /-- If an element of `F` is invariant under all coordinate changes, then one can define a corresponding section of the fiber bundle, which is continuous. This applies in particular to the zero section of a vector bundle. Another example (not yet defined) would be the identity section of the endomorphism bundle of a vector bundle. -/ theorem continuous_const_section {ι : Type u_1} {B : Type u_2} {F : Type u_3} [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) (v : F) (h : ∀ (i j : ι) (x : B), x ∈ base_set Z i ∩ base_set Z j → coord_change Z i j x v = v) : continuous ((fun (this : B → total_space Z) => this) fun (x : B) => sigma.mk x v) := sorry
d8461d55221491b69e6df59a14f149e41cc23f4e
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/geometry/manifold/diffeomorph.lean
f7eef23e11ca7f06d5ac55daf419a8d56ecf7ba7
[ "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
21,371
lean
/- Copyright © 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Yury Kudryashov -/ import geometry.manifold.cont_mdiff_map import geometry.manifold.cont_mdiff_mfderiv /-! # Diffeomorphisms > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file implements diffeomorphisms. ## Definitions * `diffeomorph I I' M M' n`: `n`-times continuously differentiable diffeomorphism between `M` and `M'` with respect to I and I'; we do not introduce a separate definition for the case `n = ∞`; we use notation instead. * `diffeomorph.to_homeomorph`: reinterpret a diffeomorphism as a homeomorphism. * `continuous_linear_equiv.to_diffeomorph`: reinterpret a continuous equivalence as a diffeomorphism. * `model_with_corners.trans_diffeomorph`: compose a given `model_with_corners` with a diffeomorphism between the old and the new target spaces. Useful, e.g, to turn any finite dimensional manifold into a manifold modelled on a Euclidean space. * `diffeomorph.to_trans_diffeomorph`: the identity diffeomorphism between `M` with model `I` and `M` with model `I.trans_diffeomorph e`. ## Notations * `M ≃ₘ^n⟮I, I'⟯ M'` := `diffeomorph I J M N n` * `M ≃ₘ⟮I, I'⟯ M'` := `diffeomorph I J M N ⊤` * `E ≃ₘ^n[𝕜] E'` := `E ≃ₘ^n⟮𝓘(𝕜, E), 𝓘(𝕜, E')⟯ E'` * `E ≃ₘ[𝕜] E'` := `E ≃ₘ⟮𝓘(𝕜, E), 𝓘(𝕜, E')⟯ E'` ## Implementation notes This notion of diffeomorphism is needed although there is already a notion of structomorphism because structomorphisms do not allow the model spaces `H` and `H'` of the two manifolds to be different, i.e. for a structomorphism one has to impose `H = H'` which is often not the case in practice. ## Keywords diffeomorphism, manifold -/ open_locale manifold topology open function set 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] {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} {I' : model_with_corners 𝕜 E' H'} {J : model_with_corners 𝕜 F G} {J' : model_with_corners 𝕜 F G'} variables {M : Type*} [topological_space M] [charted_space H M] {M' : Type*} [topological_space M'] [charted_space H' M'] {N : Type*} [topological_space N] [charted_space G N] {N' : Type*} [topological_space N'] [charted_space G' N'] {n : ℕ∞} section defs variables (I I' M M' n) /-- `n`-times continuously differentiable diffeomorphism between `M` and `M'` with respect to I and I' -/ @[protect_proj, nolint has_nonempty_instance] structure diffeomorph extends M ≃ M' := (cont_mdiff_to_fun : cont_mdiff I I' n to_equiv) (cont_mdiff_inv_fun : cont_mdiff I' I n to_equiv.symm) end defs localized "notation (name := diffeomorph) M ` ≃ₘ^` n:1000 `⟮`:50 I `, ` J `⟯ ` N := diffeomorph I J M N n" in manifold localized "notation (name := diffeomorph.top) M ` ≃ₘ⟮` I `, ` J `⟯ ` N := diffeomorph I J M N ⊤" in manifold localized "notation (name := diffeomorph.self) E ` ≃ₘ^` n:1000 `[`:50 𝕜 `] ` E' := diffeomorph (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') E E' n" in manifold localized "notation (name := diffeomorph.self.top) E ` ≃ₘ[` 𝕜 `] ` E' := diffeomorph (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') E E' ⊤" in manifold namespace diffeomorph instance : has_coe_to_fun (M ≃ₘ^n⟮I, I'⟯ M') (λ _, M → M') := ⟨λe, e.to_equiv⟩ instance : has_coe (M ≃ₘ^n⟮I, I'⟯ M') C^n⟮I, M; I', M'⟯ := ⟨λ Φ, ⟨Φ, Φ.cont_mdiff_to_fun⟩⟩ @[continuity] protected lemma continuous (h : M ≃ₘ^n⟮I, I'⟯ M') : continuous h := h.cont_mdiff_to_fun.continuous protected lemma cont_mdiff (h : M ≃ₘ^n⟮I, I'⟯ M') : cont_mdiff I I' n h := h.cont_mdiff_to_fun protected lemma cont_mdiff_at (h : M ≃ₘ^n⟮I, I'⟯ M') {x} : cont_mdiff_at I I' n h x := h.cont_mdiff.cont_mdiff_at protected lemma cont_mdiff_within_at (h : M ≃ₘ^n⟮I, I'⟯ M') {s x} : cont_mdiff_within_at I I' n h s x := h.cont_mdiff_at.cont_mdiff_within_at protected lemma cont_diff (h : E ≃ₘ^n[𝕜] E') : cont_diff 𝕜 n h := h.cont_mdiff.cont_diff protected lemma smooth (h : M ≃ₘ⟮I, I'⟯ M') : smooth I I' h := h.cont_mdiff_to_fun protected lemma mdifferentiable (h : M ≃ₘ^n⟮I, I'⟯ M') (hn : 1 ≤ n) : mdifferentiable I I' h := h.cont_mdiff.mdifferentiable hn protected lemma mdifferentiable_on (h : M ≃ₘ^n⟮I, I'⟯ M') (s : set M) (hn : 1 ≤ n) : mdifferentiable_on I I' h s := (h.mdifferentiable hn).mdifferentiable_on @[simp] lemma coe_to_equiv (h : M ≃ₘ^n⟮I, I'⟯ M') : ⇑h.to_equiv = h := rfl @[simp, norm_cast] lemma coe_coe (h : M ≃ₘ^n⟮I, I'⟯ M') : ⇑(h : C^n⟮I, M; I', M'⟯) = h := rfl lemma to_equiv_injective : injective (diffeomorph.to_equiv : (M ≃ₘ^n⟮I, I'⟯ M') → (M ≃ M')) | ⟨e, _, _⟩ ⟨e', _, _⟩ rfl := rfl @[simp] lemma to_equiv_inj {h h' : M ≃ₘ^n⟮I, I'⟯ M'} : h.to_equiv = h'.to_equiv ↔ h = h' := to_equiv_injective.eq_iff /-- Coercion to function `λ h : M ≃ₘ^n⟮I, I'⟯ M', (h : M → M')` is injective. -/ lemma coe_fn_injective : injective (λ (h : M ≃ₘ^n⟮I, I'⟯ M') (x : M), h x) := equiv.coe_fn_injective.comp to_equiv_injective @[ext] lemma ext {h h' : M ≃ₘ^n⟮I, I'⟯ M'} (Heq : ∀ x, h x = h' x) : h = h' := coe_fn_injective $ funext Heq instance : continuous_map_class (M ≃ₘ⟮I, J⟯ N) M N := { coe := coe_fn, coe_injective' := coe_fn_injective, map_continuous := λ f, f.continuous } section variables (M I n) /-- Identity map as a diffeomorphism. -/ protected def refl : M ≃ₘ^n⟮I, I⟯ M := { cont_mdiff_to_fun := cont_mdiff_id, cont_mdiff_inv_fun := cont_mdiff_id, to_equiv := equiv.refl M } @[simp] lemma refl_to_equiv : (diffeomorph.refl I M n).to_equiv = equiv.refl _ := rfl @[simp] lemma coe_refl : ⇑(diffeomorph.refl I M n) = id := rfl end /-- Composition of two diffeomorphisms. -/ protected def trans (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) : M ≃ₘ^n⟮I, J⟯ N := { cont_mdiff_to_fun := h₂.cont_mdiff_to_fun.comp h₁.cont_mdiff_to_fun, cont_mdiff_inv_fun := h₁.cont_mdiff_inv_fun.comp h₂.cont_mdiff_inv_fun, to_equiv := h₁.to_equiv.trans h₂.to_equiv } @[simp] lemma trans_refl (h : M ≃ₘ^n⟮I, I'⟯ M') : h.trans (diffeomorph.refl I' M' n) = h := ext $ λ _, rfl @[simp] lemma refl_trans (h : M ≃ₘ^n⟮I, I'⟯ M') : (diffeomorph.refl I M n).trans h = h := ext $ λ _, rfl @[simp] lemma coe_trans (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) : ⇑(h₁.trans h₂) = h₂ ∘ h₁ := rfl /-- Inverse of a diffeomorphism. -/ protected def symm (h : M ≃ₘ^n⟮I, J⟯ N) : N ≃ₘ^n⟮J, I⟯ M := { cont_mdiff_to_fun := h.cont_mdiff_inv_fun, cont_mdiff_inv_fun := h.cont_mdiff_to_fun, to_equiv := h.to_equiv.symm } @[simp] lemma apply_symm_apply (h : M ≃ₘ^n⟮I, J⟯ N) (x : N) : h (h.symm x) = x := h.to_equiv.apply_symm_apply x @[simp] lemma symm_apply_apply (h : M ≃ₘ^n⟮I, J⟯ N) (x : M) : h.symm (h x) = x := h.to_equiv.symm_apply_apply x @[simp] lemma symm_refl : (diffeomorph.refl I M n).symm = diffeomorph.refl I M n := ext $ λ _, rfl @[simp] lemma self_trans_symm (h : M ≃ₘ^n⟮I, J⟯ N) : h.trans h.symm = diffeomorph.refl I M n := ext h.symm_apply_apply @[simp] lemma symm_trans_self (h : M ≃ₘ^n⟮I, J⟯ N) : h.symm.trans h = diffeomorph.refl J N n := ext h.apply_symm_apply @[simp] lemma symm_trans' (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) : (h₁.trans h₂).symm = h₂.symm.trans h₁.symm := rfl @[simp] lemma symm_to_equiv (h : M ≃ₘ^n⟮I, J⟯ N) : h.symm.to_equiv = h.to_equiv.symm := rfl @[simp, mfld_simps] lemma to_equiv_coe_symm (h : M ≃ₘ^n⟮I, J⟯ N) : ⇑h.to_equiv.symm = h.symm := rfl lemma image_eq_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (s : set M) : h '' s = h.symm ⁻¹' s := h.to_equiv.image_eq_preimage s lemma symm_image_eq_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (s : set N) : h.symm '' s = h ⁻¹' s := h.symm.image_eq_preimage s @[simp, mfld_simps] lemma range_comp {α} (h : M ≃ₘ^n⟮I, J⟯ N) (f : α → M) : range (h ∘ f) = h.symm ⁻¹' (range f) := by rw [range_comp, image_eq_preimage] @[simp] lemma image_symm_image (h : M ≃ₘ^n⟮I, J⟯ N) (s : set N) : h '' (h.symm '' s) = s := h.to_equiv.image_symm_image s @[simp] lemma symm_image_image (h : M ≃ₘ^n⟮I, J⟯ N) (s : set M) : h.symm '' (h '' s) = s := h.to_equiv.symm_image_image s /-- A diffeomorphism is a homeomorphism. -/ def to_homeomorph (h : M ≃ₘ^n⟮I, J⟯ N) : M ≃ₜ N := ⟨h.to_equiv, h.continuous, h.symm.continuous⟩ @[simp] lemma to_homeomorph_to_equiv (h : M ≃ₘ^n⟮I, J⟯ N) : h.to_homeomorph.to_equiv = h.to_equiv := rfl @[simp] lemma symm_to_homeomorph (h : M ≃ₘ^n⟮I, J⟯ N) : h.symm.to_homeomorph = h.to_homeomorph.symm := rfl @[simp] lemma coe_to_homeomorph (h : M ≃ₘ^n⟮I, J⟯ N) : ⇑h.to_homeomorph = h := rfl @[simp] lemma coe_to_homeomorph_symm (h : M ≃ₘ^n⟮I, J⟯ N) : ⇑h.to_homeomorph.symm = h.symm := rfl @[simp] lemma cont_mdiff_within_at_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} {s x} (hm : m ≤ n) : cont_mdiff_within_at I I' m (f ∘ h) s x ↔ cont_mdiff_within_at J I' m f (h.symm ⁻¹' s) (h x) := begin split, { intro Hfh, rw [← h.symm_apply_apply x] at Hfh, simpa only [(∘), h.apply_symm_apply] using Hfh.comp (h x) (h.symm.cont_mdiff_within_at.of_le hm) (maps_to_preimage _ _) }, { rw ← h.image_eq_preimage, exact λ hf, hf.comp x (h.cont_mdiff_within_at.of_le hm) (maps_to_image _ _) } end @[simp] lemma cont_mdiff_on_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} {s} (hm : m ≤ n) : cont_mdiff_on I I' m (f ∘ h) s ↔ cont_mdiff_on J I' m f (h.symm ⁻¹' s) := h.to_equiv.forall_congr $ λ x, by simp only [hm, coe_to_equiv, symm_apply_apply, cont_mdiff_within_at_comp_diffeomorph_iff, mem_preimage] @[simp] lemma cont_mdiff_at_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} {x} (hm : m ≤ n) : cont_mdiff_at I I' m (f ∘ h) x ↔ cont_mdiff_at J I' m f (h x) := h.cont_mdiff_within_at_comp_diffeomorph_iff hm @[simp] lemma cont_mdiff_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} (hm : m ≤ n) : cont_mdiff I I' m (f ∘ h) ↔ cont_mdiff J I' m f := h.to_equiv.forall_congr $ λ x, (h.cont_mdiff_at_comp_diffeomorph_iff hm) @[simp] lemma cont_mdiff_within_at_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M} (hm : m ≤ n) {s x} : cont_mdiff_within_at I' J m (h ∘ f) s x ↔ cont_mdiff_within_at I' I m f s x := ⟨λ Hhf, by simpa only [(∘), h.symm_apply_apply] using (h.symm.cont_mdiff_at.of_le hm).comp_cont_mdiff_within_at _ Hhf, λ Hf, (h.cont_mdiff_at.of_le hm).comp_cont_mdiff_within_at _ Hf⟩ @[simp] lemma cont_mdiff_at_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M} (hm : m ≤ n) {x} : cont_mdiff_at I' J m (h ∘ f) x ↔ cont_mdiff_at I' I m f x := h.cont_mdiff_within_at_diffeomorph_comp_iff hm @[simp] lemma cont_mdiff_on_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M} (hm : m ≤ n) {s} : cont_mdiff_on I' J m (h ∘ f) s ↔ cont_mdiff_on I' I m f s := forall₂_congr $ λ x hx, h.cont_mdiff_within_at_diffeomorph_comp_iff hm @[simp] lemma cont_mdiff_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M} (hm : m ≤ n) : cont_mdiff I' J m (h ∘ f) ↔ cont_mdiff I' I m f := forall_congr $ λ x, h.cont_mdiff_within_at_diffeomorph_comp_iff hm lemma to_local_homeomorph_mdifferentiable (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) : h.to_homeomorph.to_local_homeomorph.mdifferentiable I J := ⟨h.mdifferentiable_on _ hn, h.symm.mdifferentiable_on _ hn⟩ section constructions /-- Product of two diffeomorphisms. -/ def prod_congr (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : N ≃ₘ^n⟮J, J'⟯ N') : M × N ≃ₘ^n⟮I.prod J, I'.prod J'⟯ M' × N' := { cont_mdiff_to_fun := (h₁.cont_mdiff.comp cont_mdiff_fst).prod_mk (h₂.cont_mdiff.comp cont_mdiff_snd), cont_mdiff_inv_fun := (h₁.symm.cont_mdiff.comp cont_mdiff_fst).prod_mk (h₂.symm.cont_mdiff.comp cont_mdiff_snd), to_equiv := h₁.to_equiv.prod_congr h₂.to_equiv } @[simp] lemma prod_congr_symm (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : N ≃ₘ^n⟮J, J'⟯ N') : (h₁.prod_congr h₂).symm = h₁.symm.prod_congr h₂.symm := rfl @[simp] lemma coe_prod_congr (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : N ≃ₘ^n⟮J, J'⟯ N') : ⇑(h₁.prod_congr h₂) = prod.map h₁ h₂ := rfl section variables (I J J' M N N' n) /-- `M × N` is diffeomorphic to `N × M`. -/ def prod_comm : M × N ≃ₘ^n⟮I.prod J, J.prod I⟯ N × M := { cont_mdiff_to_fun := cont_mdiff_snd.prod_mk cont_mdiff_fst, cont_mdiff_inv_fun := cont_mdiff_snd.prod_mk cont_mdiff_fst, to_equiv := equiv.prod_comm M N } @[simp] lemma prod_comm_symm : (prod_comm I J M N n).symm = prod_comm J I N M n := rfl @[simp] lemma coe_prod_comm : ⇑(prod_comm I J M N n) = prod.swap := rfl /-- `(M × N) × N'` is diffeomorphic to `M × (N × N')`. -/ def prod_assoc : (M × N) × N' ≃ₘ^n⟮(I.prod J).prod J', I.prod (J.prod J')⟯ M × (N × N') := { cont_mdiff_to_fun := (cont_mdiff_fst.comp cont_mdiff_fst).prod_mk ((cont_mdiff_snd.comp cont_mdiff_fst).prod_mk cont_mdiff_snd), cont_mdiff_inv_fun := (cont_mdiff_fst.prod_mk (cont_mdiff_fst.comp cont_mdiff_snd)).prod_mk (cont_mdiff_snd.comp cont_mdiff_snd), to_equiv := equiv.prod_assoc M N N' } end end constructions variables [smooth_manifold_with_corners I M] [smooth_manifold_with_corners J N] lemma unique_mdiff_on_image_aux (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) {s : set M} (hs : unique_mdiff_on I s) : unique_mdiff_on J (h '' s) := begin convert hs.unique_mdiff_on_preimage (h.to_local_homeomorph_mdifferentiable hn), simp [h.image_eq_preimage] end @[simp] lemma unique_mdiff_on_image (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) {s : set M} : unique_mdiff_on J (h '' s) ↔ unique_mdiff_on I s := ⟨λ hs, h.symm_image_image s ▸ h.symm.unique_mdiff_on_image_aux hn hs, h.unique_mdiff_on_image_aux hn⟩ @[simp] lemma unique_mdiff_on_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) {s : set N} : unique_mdiff_on I (h ⁻¹' s) ↔ unique_mdiff_on J s := h.symm_image_eq_preimage s ▸ h.symm.unique_mdiff_on_image hn @[simp] lemma unique_diff_on_image (h : E ≃ₘ^n[𝕜] F) (hn : 1 ≤ n) {s : set E} : unique_diff_on 𝕜 (h '' s) ↔ unique_diff_on 𝕜 s := by simp only [← unique_mdiff_on_iff_unique_diff_on, unique_mdiff_on_image, hn] @[simp] lemma unique_diff_on_preimage (h : E ≃ₘ^n[𝕜] F) (hn : 1 ≤ n) {s : set F} : unique_diff_on 𝕜 (h ⁻¹' s) ↔ unique_diff_on 𝕜 s := h.symm_image_eq_preimage s ▸ h.symm.unique_diff_on_image hn end diffeomorph namespace continuous_linear_equiv variable (e : E ≃L[𝕜] E') /-- A continuous linear equivalence between normed spaces is a diffeomorphism. -/ def to_diffeomorph : E ≃ₘ[𝕜] E' := { cont_mdiff_to_fun := e.cont_diff.cont_mdiff, cont_mdiff_inv_fun := e.symm.cont_diff.cont_mdiff, to_equiv := e.to_linear_equiv.to_equiv } @[simp] lemma coe_to_diffeomorph : ⇑e.to_diffeomorph = e := rfl @[simp] lemma symm_to_diffeomorph : e.symm.to_diffeomorph = e.to_diffeomorph.symm := rfl @[simp] lemma coe_to_diffeomorph_symm : ⇑e.to_diffeomorph.symm = e.symm := rfl end continuous_linear_equiv namespace model_with_corners variables (I) (e : E ≃ₘ[𝕜] E') /-- Apply a diffeomorphism (e.g., a continuous linear equivalence) to the model vector space. -/ def trans_diffeomorph (I : model_with_corners 𝕜 E H) (e : E ≃ₘ[𝕜] E') : model_with_corners 𝕜 E' H := { to_local_equiv := I.to_local_equiv.trans e.to_equiv.to_local_equiv, source_eq := by simp, unique_diff' := by simp [range_comp e, I.unique_diff], continuous_to_fun := e.continuous.comp I.continuous, continuous_inv_fun := I.continuous_symm.comp e.symm.continuous } @[simp, mfld_simps] lemma coe_trans_diffeomorph : ⇑(I.trans_diffeomorph e) = e ∘ I := rfl @[simp, mfld_simps] lemma coe_trans_diffeomorph_symm : ⇑(I.trans_diffeomorph e).symm = I.symm ∘ e.symm := rfl lemma trans_diffeomorph_range : range (I.trans_diffeomorph e) = e '' (range I) := range_comp e I lemma coe_ext_chart_at_trans_diffeomorph (x : M) : ⇑(ext_chart_at (I.trans_diffeomorph e) x) = e ∘ ext_chart_at I x := rfl lemma coe_ext_chart_at_trans_diffeomorph_symm (x : M) : ⇑(ext_chart_at (I.trans_diffeomorph e) x).symm = (ext_chart_at I x).symm ∘ e.symm := rfl lemma ext_chart_at_trans_diffeomorph_target (x : M) : (ext_chart_at (I.trans_diffeomorph e) x).target = e.symm ⁻¹' (ext_chart_at I x).target := by simp only [range_comp e, e.image_eq_preimage, preimage_preimage] with mfld_simps end model_with_corners namespace diffeomorph variables (e : E ≃ₘ[𝕜] F) instance smooth_manifold_with_corners_trans_diffeomorph [smooth_manifold_with_corners I M] : smooth_manifold_with_corners (I.trans_diffeomorph e) M := begin refine smooth_manifold_with_corners_of_cont_diff_on _ _ (λ e₁ e₂ h₁ h₂, _), refine e.cont_diff.comp_cont_diff_on (((cont_diff_groupoid ⊤ I).compatible h₁ h₂).1.comp e.symm.cont_diff.cont_diff_on _), mfld_set_tac end variables (I M) /-- The identity diffeomorphism between a manifold with model `I` and the same manifold with model `I.trans_diffeomorph e`. -/ def to_trans_diffeomorph (e : E ≃ₘ[𝕜] F) : M ≃ₘ⟮I, I.trans_diffeomorph e⟯ M := { to_equiv := equiv.refl M, cont_mdiff_to_fun := λ x, begin refine cont_mdiff_within_at_iff'.2 ⟨continuous_within_at_id, _⟩, refine e.cont_diff.cont_diff_within_at.congr' (λ y hy, _) _, { simp only [equiv.coe_refl, id, (∘), I.coe_ext_chart_at_trans_diffeomorph, (ext_chart_at I x).right_inv hy.1] }, exact ⟨(ext_chart_at I x).map_source (mem_ext_chart_source I x), trivial, by simp only with mfld_simps⟩ end, cont_mdiff_inv_fun := λ x, begin refine cont_mdiff_within_at_iff'.2 ⟨continuous_within_at_id, _⟩, refine e.symm.cont_diff.cont_diff_within_at.congr' (λ y hy, _) _, { simp only [mem_inter_iff, I.ext_chart_at_trans_diffeomorph_target] at hy, simp only [equiv.coe_refl, equiv.refl_symm, id, (∘), I.coe_ext_chart_at_trans_diffeomorph_symm, (ext_chart_at I x).right_inv hy.1] }, exact ⟨(ext_chart_at _ x).map_source (mem_ext_chart_source _ x), trivial, by simp only [e.symm_apply_apply, equiv.refl_symm, equiv.coe_refl] with mfld_simps⟩ end } variables {I M} @[simp] lemma cont_mdiff_within_at_trans_diffeomorph_right {f : M' → M} {x s} : cont_mdiff_within_at I' (I.trans_diffeomorph e) n f s x ↔ cont_mdiff_within_at I' I n f s x := (to_trans_diffeomorph I M e).cont_mdiff_within_at_diffeomorph_comp_iff le_top @[simp] lemma cont_mdiff_at_trans_diffeomorph_right {f : M' → M} {x} : cont_mdiff_at I' (I.trans_diffeomorph e) n f x ↔ cont_mdiff_at I' I n f x := (to_trans_diffeomorph I M e).cont_mdiff_at_diffeomorph_comp_iff le_top @[simp] lemma cont_mdiff_on_trans_diffeomorph_right {f : M' → M} {s} : cont_mdiff_on I' (I.trans_diffeomorph e) n f s ↔ cont_mdiff_on I' I n f s := (to_trans_diffeomorph I M e).cont_mdiff_on_diffeomorph_comp_iff le_top @[simp] lemma cont_mdiff_trans_diffeomorph_right {f : M' → M} : cont_mdiff I' (I.trans_diffeomorph e) n f ↔ cont_mdiff I' I n f := (to_trans_diffeomorph I M e).cont_mdiff_diffeomorph_comp_iff le_top @[simp] lemma smooth_trans_diffeomorph_right {f : M' → M} : smooth I' (I.trans_diffeomorph e) f ↔ smooth I' I f := cont_mdiff_trans_diffeomorph_right e @[simp] lemma cont_mdiff_within_at_trans_diffeomorph_left {f : M → M'} {x s} : cont_mdiff_within_at (I.trans_diffeomorph e) I' n f s x ↔ cont_mdiff_within_at I I' n f s x := ((to_trans_diffeomorph I M e).cont_mdiff_within_at_comp_diffeomorph_iff le_top).symm @[simp] lemma cont_mdiff_at_trans_diffeomorph_left {f : M → M'} {x} : cont_mdiff_at (I.trans_diffeomorph e) I' n f x ↔ cont_mdiff_at I I' n f x := ((to_trans_diffeomorph I M e).cont_mdiff_at_comp_diffeomorph_iff le_top).symm @[simp] lemma cont_mdiff_on_trans_diffeomorph_left {f : M → M'} {s} : cont_mdiff_on (I.trans_diffeomorph e) I' n f s ↔ cont_mdiff_on I I' n f s := ((to_trans_diffeomorph I M e).cont_mdiff_on_comp_diffeomorph_iff le_top).symm @[simp] lemma cont_mdiff_trans_diffeomorph_left {f : M → M'} : cont_mdiff (I.trans_diffeomorph e) I' n f ↔ cont_mdiff I I' n f := ((to_trans_diffeomorph I M e).cont_mdiff_comp_diffeomorph_iff le_top).symm @[simp] lemma smooth_trans_diffeomorph_left {f : M → M'} : smooth (I.trans_diffeomorph e) I' f ↔ smooth I I' f := e.cont_mdiff_trans_diffeomorph_left end diffeomorph
43fa9e7d8f62ddac3773f9314974567f2f63f08b
a4673261e60b025e2c8c825dfa4ab9108246c32e
/src/Init/System/ST.lean
232da595cb9a4534a8acd2c3940516c46a0fe32e
[ "Apache-2.0" ]
permissive
jcommelin/lean4
c02dec0cc32c4bccab009285475f265f17d73228
2909313475588cc20ac0436e55548a4502050d0a
refs/heads/master
1,674,129,550,893
1,606,415,348,000
1,606,415,348,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
4,402
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import Init.Classical import Init.Control.EState import Init.Control.Reader def EST (ε : Type) (σ : Type) : Type → Type := EStateM ε σ abbrev ST (σ : Type) := EST Empty σ instance (ε σ : Type) : Monad (EST ε σ) := inferInstanceAs (Monad (EStateM _ _)) instance (ε σ : Type) : MonadExceptOf ε (EST ε σ) := inferInstanceAs (MonadExceptOf ε (EStateM _ _)) instance {ε σ : Type} {α : Type} [Inhabited ε] : Inhabited (EST ε σ α) := inferInstanceAs (Inhabited (EStateM _ _ _)) instance (σ : Type) : Monad (ST σ) := inferInstanceAs (Monad (EST _ _)) -- Auxiliary class for inferring the "state" of `EST` and `ST` monads class STWorld (σ : outParam Type) (m : Type → Type) instance {σ m n} [STWorld σ m] [MonadLift m n] : STWorld σ n := ⟨⟩ instance {ε σ} : STWorld σ (EST ε σ) := ⟨⟩ @[inline] def runEST {ε α : Type} (x : forall (σ : Type), EST ε σ α) : Except ε α := match x Unit () with | EStateM.Result.ok a _ => Except.ok a | EStateM.Result.error ex _ => Except.error ex @[inline] def runST {α : Type} (x : forall (σ : Type), ST σ α) : α := match x Unit () with | EStateM.Result.ok a _ => a | EStateM.Result.error ex _ => nomatch ex instance {ε σ} : MonadLift (ST σ) (EST ε σ) := ⟨fun x s => match x s with | EStateM.Result.ok a s => EStateM.Result.ok a s | EStateM.Result.error ex _ => nomatch ex⟩ namespace ST /- References -/ constant RefPointed : PointedType.{0} structure Ref (σ : Type) (α : Type) : Type := (ref : RefPointed.type) (h : Nonempty α) instance {σ α} [Inhabited α] : Inhabited (Ref σ α) where default := { ref := RefPointed.val, h := Nonempty.intro arbitrary } namespace Prim set_option pp.all true /- Auxiliary definition for showing that `ST σ α` is inhabited when we have a `Ref σ α` -/ private noncomputable def inhabitedFromRef {σ α} (r : Ref σ α) : ST σ α := let inh : Inhabited α := Classical.inhabitedOfNonempty r.h pure arbitrary @[extern "lean_st_mk_ref"] constant mkRef {σ α} (a : α) : ST σ (Ref σ α) := pure { ref := RefPointed.val, h := Nonempty.intro a } @[extern "lean_st_ref_get"] constant Ref.get {σ α} (r : @& Ref σ α) : ST σ α := inhabitedFromRef r @[extern "lean_st_ref_set"] constant Ref.set {σ α} (r : @& Ref σ α) (a : α) : ST σ Unit @[extern "lean_st_ref_swap"] constant Ref.swap {σ α} (r : @& Ref σ α) (a : α) : ST σ α := inhabitedFromRef r @[extern "lean_st_ref_take"] unsafe constant Ref.take {σ α} (r : @& Ref σ α) : ST σ α := inhabitedFromRef r @[extern "lean_st_ref_ptr_eq"] constant Ref.ptrEq {σ α} (r1 r2 : @& Ref σ α) : ST σ Bool @[inline] unsafe def Ref.modifyUnsafe {σ α : Type} (r : Ref σ α) (f : α → α) : ST σ Unit := do let v ← Ref.take r Ref.set r (f v) @[inline] unsafe def Ref.modifyGetUnsafe {σ α β : Type} (r : Ref σ α) (f : α → β × α) : ST σ β := do let v ← Ref.take r let (b, a) := f v Ref.set r a pure b @[implementedBy Ref.modifyUnsafe] def Ref.modify {σ α : Type} (r : Ref σ α) (f : α → α) : ST σ Unit := do let v ← Ref.get r Ref.set r (f v) @[implementedBy Ref.modifyGetUnsafe] def Ref.modifyGet {σ α β : Type} (r : Ref σ α) (f : α → β × α) : ST σ β := do let v ← Ref.get r let (b, a) := f v Ref.set r a pure b end Prim section variables {σ : Type} {m : Type → Type} [Monad m] [MonadLiftT (ST σ) m] @[inline] def mkRef {α : Type} (a : α) : m (Ref σ α) := liftM <| Prim.mkRef a @[inline] def Ref.get {α : Type} (r : Ref σ α) : m α := liftM <| Prim.Ref.get r @[inline] def Ref.set {α : Type} (r : Ref σ α) (a : α) : m Unit := liftM <| Prim.Ref.set r a @[inline] def Ref.swap {α : Type} (r : Ref σ α) (a : α) : m α := liftM <| Prim.Ref.swap r a @[inline] unsafe def Ref.take {α : Type} (r : Ref σ α) : m α := liftM <| Prim.Ref.take r @[inline] def Ref.ptrEq {α : Type} (r1 r2 : Ref σ α) : m Bool := liftM <| Prim.Ref.ptrEq r1 r2 @[inline] def Ref.modify {α : Type} (r : Ref σ α) (f : α → α) : m Unit := liftM <| Prim.Ref.modify r f @[inline] def Ref.modifyGet {α : Type} {β : Type} (r : Ref σ α) (f : α → β × α) : m β := liftM <| Prim.Ref.modifyGet r f end end ST
aa01c2e3bf5517690e140e422cc72629dfa00089
c31182a012eec69da0a1f6c05f42b0f0717d212d
/src/polyhedral_lattice/quotient.lean
e6d59d17685030ad1be3a5c13fb6082a0a7df2c5
[]
no_license
Ja1941/lean-liquid
fbec3ffc7fc67df1b5ca95b7ee225685ab9ffbdc
8e80ed0cbdf5145d6814e833a674eaf05a1495c1
refs/heads/master
1,689,437,983,362
1,628,362,719,000
1,628,362,719,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
5,598
lean
import analysis.normed_space.normed_group_quotient import linear_algebra.free_module_pid import for_mathlib.finite_free import polyhedral_lattice.topology /-! # Quotients of polyhedral lattices -/ noncomputable theory open_locale big_operators section saturated -- PR #8137 variables {G G₁ G₂ : Type*} [group G] [add_comm_group G₁] [add_comm_group G₂] namespace subgroup @[to_additive] def saturated (H : subgroup G) : Prop := ∀ ⦃n g⦄, gpow n g ∈ H → n = 0 ∨ g ∈ H end subgroup lemma add_subgroup.ker_saturated [no_zero_smul_divisors ℤ G₂] (f : G₁ →+ G₂) : (f.ker).saturated := begin intros n g hg, simpa only [f.mem_ker, gsmul_eq_smul, f.map_gsmul, smul_eq_zero] using hg end end saturated namespace polyhedral_lattice variables {Λ : Type*} [polyhedral_lattice Λ] (L : add_subgroup Λ) instance : is_closed (L : set Λ) := is_closed_discrete _ instance : normed_group (quotient_add_group.quotient L) := add_subgroup.normed_group_quotient _ lemma π_apply_eq_zero_iff (x) : L.normed_mk x = 0 ↔ x ∈ L := quotient_add_group.eq_zero_iff _ lemma π_is_quotient : L.normed_mk.is_quotient := normed_group_hom.is_quotient_quotient _ instance [H : fact L.saturated] : no_zero_smul_divisors ℤ (quotient_add_group.quotient L) := { eq_zero_or_eq_zero_of_smul_eq_zero := begin intros n x h, obtain ⟨x, rfl⟩ : ∃ y, L.normed_mk y = x := quotient.surjective_quotient_mk' x, have : L.normed_mk (n • x) = n • L.normed_mk x := L.normed_mk.to_add_monoid_hom.map_gsmul x n, simp only [← this, π_apply_eq_zero_iff] at h ⊢, have := H.1, exact this h end } instance quotient_finite [H : fact L.saturated] : module.finite ℤ (quotient_add_group.quotient L) := begin apply module.finite.of_surjective (L.normed_mk).to_add_monoid_hom.to_int_linear_map, exact quotient.surjective_quotient_mk' end instance quotient_free [H : fact L.saturated] : module.free ℤ (quotient_add_group.quotient L) := begin let φ := L.normed_mk.to_add_monoid_hom.to_int_linear_map, suffices : submodule.span ℤ (set.range (φ ∘ (module.free.choose_basis ℤ Λ))) = ⊤, { obtain ⟨n, b⟩ := module.free_of_finite_type_torsion_free this, exact module.free.of_basis b, }, rw [set.range_comp, ← submodule.map_span, basis.span_eq, submodule.map_top, linear_map.range_eq_top], exact quotient.surjective_quotient_mk' end open pseudo_normed_group lemma norm_lift (y : quotient_add_group.quotient L) : ∃ x, L.normed_mk x = y ∧ ∥x∥ = ∥y∥ := begin have hq : L.normed_mk.is_quotient := normed_group_hom.is_quotient_quotient _, let s := λ ε, {x | L.normed_mk x = y ∧ ∥x∥₊ ≤ ∥y∥₊ + ε }, have hs : ∀ ε, (s ε).finite, { intro ε, apply (filtration_finite Λ (∥y∥₊ + ε)).subset, rintro x ⟨h1, h2⟩, simpa only [semi_normed_group.mem_filtration_iff] using h2 }, let t := λ ε, (hs ε).to_finset, have ht : ∀ ε, 0 < ε → (t ε).nonempty, { intros ε hε, obtain ⟨x, h1, h2⟩ := hq.norm_lift hε y, refine ⟨x, _⟩, simp only [set.finite.mem_to_finset], exact ⟨h1, h2.le⟩ }, let r := ((t 1).image nnnorm).min' ((ht _ zero_lt_one).image _), have aux := finset.min'_mem ((t 1).image nnnorm) ((ht _ zero_lt_one).image _), simp only [finset.mem_image] at aux, obtain ⟨x, hx, H⟩ := aux, simp only [set.finite.mem_to_finset, set.mem_set_of_eq] at hx, suffices hr : r = ∥y∥₊, { refine ⟨x, hx.1, _⟩, simp only [← coe_nnnorm, nnreal.coe_injective.eq_iff], exact H.trans hr }, refine ((lt_or_eq_of_le _).resolve_left _).symm, { rw ← hx.1, exact (hq.norm_le x).trans H.le }, { intro hyr, let ε := (r - ∥y∥₊) / 2, have hε' : (ε : ℝ) = (r - ∥y∥₊) / 2, { dsimp only [ε], rw [nnreal.coe_div, nnreal.coe_sub hyr.le, nnreal.coe_bit0, nnreal.coe_one] }, have hε : 0 < ε, { rw [← nnreal.coe_lt_coe, nnreal.coe_zero, hε'], exact div_pos (sub_pos.mpr $ nnreal.coe_lt_coe.mpr hyr) zero_lt_two }, have key : ∥y∥₊ + ε < r, { rw [← nnreal.coe_lt_coe, nnreal.coe_add, hε'], exact add_sub_div_two_lt (nnreal.coe_lt_coe.mpr hyr), }, refine not_le_of_lt key _, obtain ⟨x₀, hx₀⟩ := ht ε hε, simp only [exists_prop, set.finite.mem_to_finset, finset.mem_image, set.mem_set_of_eq] at hx₀, refine (finset.min'_le _ _ _).trans hx₀.2, simp only [exists_prop, set.finite.mem_to_finset, finset.mem_image, set.mem_set_of_eq], exact ⟨x₀, ⟨hx₀.1, (hx₀.2.trans key.le).trans (H.ge.trans hx.2)⟩, rfl⟩, } end instance [H : fact L.saturated] : polyhedral_lattice (quotient_add_group.quotient L) := { polyhedral' := begin obtain ⟨ι, _inst_ι, l, hl, hl'⟩ := polyhedral_lattice.polyhedral Λ, resetI, refine ⟨ι, _inst_ι, (λ i, L.normed_mk (l i)), _⟩, intros y, obtain ⟨x, rfl, hx⟩ := norm_lift _ y, obtain ⟨c, H1, H2⟩ := hl x, have key : _ := _, refine ⟨c, key, _⟩, swap, { show L.normed_mk x = _, rw [H1, normed_group_hom.map_sum, fintype.sum_congr], intro, exact L.normed_mk.to_add_monoid_hom.map_nsmul _ _ }, { apply le_antisymm, { rw key, exact (norm_sum_le _ _).trans (finset.sum_le_sum $ λ i hi, norm_nsmul_le _ _) }, { simp only [← hx, H2], apply finset.sum_le_sum, rintro i -, have hq : L.normed_mk.is_quotient := normed_group_hom.is_quotient_quotient _, exact mul_le_mul le_rfl (hq.norm_le _) (norm_nonneg _) (nat.cast_nonneg _) } }, end } end polyhedral_lattice
5ff3a28a10f39f025c259a76ba7d4868091014f9
618003631150032a5676f229d13a079ac875ff77
/src/data/list/antidiagonal.lean
3e326027e18de0563422e88b9d0ed3fc0b3bb9b0
[ "Apache-2.0" ]
permissive
awainverse/mathlib
939b68c8486df66cfda64d327ad3d9165248c777
ea76bd8f3ca0a8bf0a166a06a475b10663dec44a
refs/heads/master
1,659,592,962,036
1,590,987,592,000
1,590,987,592,000
268,436,019
1
0
Apache-2.0
1,590,990,500,000
1,590,990,500,000
null
UTF-8
Lean
false
false
1,631
lean
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import data.list.range open list function nat namespace list namespace nat /-- The antidiagonal of a natural number `n` is the list of pairs `(i,j)` such that `i+j = n`. -/ def antidiagonal (n : ℕ) : list (ℕ × ℕ) := (range (n+1)).map (λ i, (i, n - i)) /-- A pair (i,j) is contained in the antidiagonal of `n` if and only if `i+j=n`. -/ @[simp] lemma mem_antidiagonal {n : ℕ} {x : ℕ × ℕ} : x ∈ antidiagonal n ↔ x.1 + x.2 = n := begin rw [antidiagonal, mem_map], split, { rintros ⟨i, hi, rfl⟩, rw [mem_range, lt_succ_iff] at hi, exact add_sub_of_le hi }, { rintro rfl, refine ⟨x.fst, _, _⟩, { rw [mem_range, add_assoc, lt_add_iff_pos_right], exact zero_lt_succ _ }, { exact prod.ext rfl (nat.add_sub_cancel_left _ _) } } end /-- The length of the antidiagonal of `n` is `n+1`. -/ @[simp] lemma length_antidiagonal (n : ℕ) : (antidiagonal n).length = n+1 := by rw [antidiagonal, length_map, length_range] /-- The antidiagonal of `0` is the list `[(0,0)]` -/ @[simp] lemma antidiagonal_zero : antidiagonal 0 = [(0, 0)] := ext_le (length_antidiagonal 0) $ λ n h₁ h₂, begin rw [length_antidiagonal, lt_succ_iff, le_zero_iff] at h₁, subst n, simp [antidiagonal] end /-- The antidiagonal of `n` does not contain duplicate entries. -/ lemma nodup_antidiagonal (n : ℕ) : nodup (antidiagonal n) := nodup_map (@left_inverse.injective ℕ (ℕ × ℕ) prod.fst (λ i, (i, n-i)) $ λ i, rfl) (nodup_range _) end nat end list
129826c3911848b93c78a488037f193a2c91d5f3
fcf3ffa92a3847189ca669cb18b34ef6b2ec2859
/src/world7/level5.lean
fbb87faa2203526d9cee099452b007df8f0bc1f0
[ "Apache-2.0" ]
permissive
nomoid/lean-proofs
4a80a97888699dee42b092b7b959b22d9aa0c066
b9f03a24623d1a1d111d6c2bbf53c617e2596d6a
refs/heads/master
1,674,955,317,080
1,607,475,706,000
1,607,475,706,000
314,104,281
0
0
null
null
null
null
UTF-8
Lean
false
false
413
lean
lemma iff_trans (P Q R : Prop) : (P ↔ Q) → (Q ↔ R) → (P ↔ R) := begin intros pq qr, split, { intro p, apply qr.1, apply pq.1, exact p, }, { intro r, apply pq.2, apply qr.2, exact r, }, end lemma iff_trans_2 (P Q R : Prop) : (P ↔ Q) → (Q ↔ R) → (P ↔ R) := begin intros pq qr, rw pq, rw qr, end
3130689fdc363f95a84ef9adb625987628ba4459
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/tests/lean/1007.lean
2ea5230f4f581c8c36f28401c15397d837dfadc1
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
EdAyers/lean4
57ac632d6b0789cb91fab2170e8c9e40441221bd
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
refs/heads/master
1,676,463,245,298
1,660,619,433,000
1,660,619,433,000
183,433,437
1
0
Apache-2.0
1,657,612,672,000
1,556,196,574,000
Lean
UTF-8
Lean
false
false
1,860
lean
class Vec (X : Type u) class IsLin {X Y} [Vec X] [Vec Y] (f : X → Y) structure ℝ where value : Float instance instFoo1 {X : Type u} {Y : Type v} [Vec X] [Vec Y] : Vec (X × Y) := sorry instance instProblem {α : Type u} {X : Type v} [Vec X] : Vec (α → X) := sorry instance (priority := mid+1) instFoo2 : Vec ℝ := sorry -------------- instance comp_is_lin {X Y Z : Type} [Vec X] [Vec Y] [Vec Z] (f : Y → Z) (g : X → Y) [IsLin f] [IsLin g] : IsLin (λ x => f (g x)) := sorry ---------------- class Trait (X : Type u) where R : Type v attribute [reducible] Trait.R class SemiInner (X : Type u) (R : Type v) where semiInner : X → X → R @[reducible] instance (X) (R : Type u) [SemiInner X R] : Trait X := ⟨R⟩ class SemiHilbert (X) (R : Type u) [Vec R] extends Vec X, SemiInner X R @[inferTCGoalsRL] instance (X R) [Trait X] [Vec R] [SemiHilbert X R] (ι : Type v) : SemiHilbert (ι → X) R := sorry instance : SemiHilbert ℝ ℝ := sorry -------------- def norm {X} [Trait X] [inst : SemiInner X (Trait.R X)] (x : X) : Trait.R X := sorry def sum {n} (f : Fin n → ℝ) : ℝ := sorry variable (n m : Nat) -- these all should work example : Trait (Fin n → Fin m → ℝ) := by infer_instance example : SemiInner ℝ (Trait.R ℝ) := by infer_instance example : SemiHilbert (Fin n → ℝ) ℝ := by infer_instance example : SemiHilbert (Fin n → ℝ) (Trait.R ℝ) := by infer_instance example : Trait (Fin n → Fin m → (Trait.R ℝ)) := by infer_instance example : SemiHilbert (Trait.R ℝ) ℝ := by infer_instance -- set_option synthInstance.maxHeartbeats 50 in -- set_option pp.explicit true in -- set_option trace.Meta.synthInstance true in -- This should not timeout but failt in finite number of steps like in Lean 3 example : IsLin (λ (x : ℝ) => sum λ i : Fin n => norm x) := by infer_instance
7f0f447bc598121f77cf0d82d908d8e01ec72900
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
/src/data/polynomial/integral_normalization.lean
2253a36478447fad9b3ff4ce815fe08241c7a1ef
[ "Apache-2.0" ]
permissive
dupuisf/mathlib
62de4ec6544bf3b79086afd27b6529acfaf2c1bb
8582b06b0a5d06c33ee07d0bdf7c646cae22cf36
refs/heads/master
1,669,494,854,016
1,595,692,409,000
1,595,692,409,000
272,046,630
0
0
Apache-2.0
1,592,066,143,000
1,592,066,142,000
null
UTF-8
Lean
false
false
5,312
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import data.polynomial.algebra_map import data.polynomial.monic /-! # Theory of monic polynomials We define `integral_normalization`, which relate arbitrary polynomials to monic ones. -/ noncomputable theory open finsupp namespace polynomial universes u v y variables {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y} section integral_normalization section semiring variables [semiring R] /-- If `f : polynomial R` is a nonzero polynomial with root `z`, `integral_normalization f` is a monic polynomial with root `leading_coeff f * z`. Moreover, `integral_normalization 0 = 0`. -/ noncomputable def integral_normalization (f : polynomial R) : polynomial R := on_finset f.support (λ i, if f.degree = i then 1 else coeff f i * f.leading_coeff ^ (f.nat_degree - 1 - i)) begin intros i h, apply mem_support_iff.mpr, split_ifs at h with hi, { exact coeff_ne_zero_of_eq_degree hi }, { exact left_ne_zero_of_mul h }, end lemma integral_normalization_coeff_degree {f : polynomial R} {i : ℕ} (hi : f.degree = i) : (integral_normalization f).coeff i = 1 := if_pos hi lemma integral_normalization_coeff_nat_degree {f : polynomial R} (hf : f ≠ 0) : (integral_normalization f).coeff (nat_degree f) = 1 := integral_normalization_coeff_degree (degree_eq_nat_degree hf) lemma integral_normalization_coeff_ne_degree {f : polynomial R} {i : ℕ} (hi : f.degree ≠ i) : coeff (integral_normalization f) i = coeff f i * f.leading_coeff ^ (f.nat_degree - 1 - i) := if_neg hi lemma integral_normalization_coeff_ne_nat_degree {f : polynomial R} {i : ℕ} (hi : i ≠ nat_degree f) : coeff (integral_normalization f) i = coeff f i * f.leading_coeff ^ (f.nat_degree - 1 - i) := integral_normalization_coeff_ne_degree (degree_ne_of_nat_degree_ne hi.symm) lemma monic_integral_normalization {f : polynomial R} (hf : f ≠ 0) : monic (integral_normalization f) := begin apply monic_of_degree_le f.nat_degree, { refine finset.sup_le (λ i h, _), rw [integral_normalization, mem_support_iff, on_finset_apply] at h, split_ifs at h with hi, { exact le_trans (le_of_eq hi.symm) degree_le_nat_degree }, { erw [with_bot.some_le_some], apply le_nat_degree_of_ne_zero, exact left_ne_zero_of_mul h } }, { exact integral_normalization_coeff_nat_degree hf } end end semiring section domain variables [integral_domain R] @[simp] lemma support_integral_normalization {f : polynomial R} (hf : f ≠ 0) : (integral_normalization f).support = f.support := begin ext i, simp only [integral_normalization, on_finset_apply, mem_support_iff], split_ifs with hi, { simp only [ne.def, not_false_iff, true_iff, one_ne_zero, hi], exact coeff_ne_zero_of_eq_degree hi }, split, { intro h, exact left_ne_zero_of_mul h }, { intro h, refine mul_ne_zero h (pow_ne_zero _ _), exact λ h, hf (leading_coeff_eq_zero.mp h) } end variables [comm_ring S] lemma integral_normalization_eval₂_eq_zero {p : polynomial R} (hp : p ≠ 0) (f : R →+* S) {z : S} (hz : eval₂ f z p = 0) (inj : ∀ (x : R), f x = 0 → x = 0) : eval₂ f (z * f p.leading_coeff) (integral_normalization p) = 0 := calc eval₂ f (z * f p.leading_coeff) (integral_normalization p) = p.support.attach.sum (λ i, f (coeff (integral_normalization p) i.1 * p.leading_coeff ^ i.1) * z ^ i.1) : by { rw [eval₂, finsupp.sum, support_integral_normalization hp], simp only [mul_comm z, mul_pow, mul_assoc, ring_hom.map_pow, ring_hom.map_mul], exact finset.sum_attach.symm } ... = p.support.attach.sum (λ i, f (coeff p i.1 * p.leading_coeff ^ (nat_degree p - 1)) * z ^ i.1) : begin have one_le_deg : 1 ≤ nat_degree p := nat.succ_le_of_lt (nat_degree_pos_of_eval₂_root hp f hz inj), congr, ext i, congr' 2, by_cases hi : i.1 = nat_degree p, { rw [hi, integral_normalization_coeff_degree, one_mul, leading_coeff, ←pow_succ, nat.sub_add_cancel one_le_deg], exact degree_eq_nat_degree hp }, { have : i.1 ≤ p.nat_degree - 1 := nat.le_pred_of_lt (lt_of_le_of_ne (le_nat_degree_of_ne_zero (finsupp.mem_support_iff.mp i.2)) hi), rw [integral_normalization_coeff_ne_nat_degree hi, mul_assoc, ←pow_add, nat.sub_add_cancel this] } end ... = f p.leading_coeff ^ (nat_degree p - 1) * eval₂ f z p : by { simp_rw [eval₂, finsupp.sum, λ i, mul_comm (coeff p i), ring_hom.map_mul, ring_hom.map_pow, mul_assoc, ←finset.mul_sum], congr' 1, exact @finset.sum_attach _ _ p.support _ (λ i, f (p.coeff i) * z ^ i) } ... = 0 : by rw [hz, _root_.mul_zero] lemma integral_normalization_aeval_eq_zero [algebra R S] {f : polynomial R} (hf : f ≠ 0) {z : S} (hz : aeval z f = 0) (inj : ∀ (x : R), algebra_map R S x = 0 → x = 0) : aeval (z * algebra_map R S f.leading_coeff) (integral_normalization f) = 0 := integral_normalization_eval₂_eq_zero hf (algebra_map R S) hz inj end domain end integral_normalization end polynomial
3fcc6f58a1738350d245c667e5c005402d479a8a
b7f22e51856f4989b970961f794f1c435f9b8f78
/library/data/set/basic.lean
44a6253cc58038358071656859e57856e0d213e9
[ "Apache-2.0" ]
permissive
soonhokong/lean
cb8aa01055ffe2af0fb99a16b4cda8463b882cd1
38607e3eb57f57f77c0ac114ad169e9e4262e24f
refs/heads/master
1,611,187,284,081
1,450,766,737,000
1,476,122,547,000
11,513,992
2
0
null
1,401,763,102,000
1,374,182,235,000
C++
UTF-8
Lean
false
false
35,917
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jeremy Avigad, Leonardo de Moura -/ import logic.connectives logic.identities algebra.binary open eq.ops binary function definition set (X : Type) := X → Prop namespace set variable {X : Type} /- membership and subset -/ definition mem (x : X) (a : set X) := a x infix ∈ := mem notation a ∉ b := ¬ mem a b theorem ext {a b : set X} (H : ∀x, x ∈ a ↔ x ∈ b) : a = b := funext (take x, propext (H x)) definition subset (a b : set X) := ∀⦃x⦄, x ∈ a → x ∈ b infix ⊆ := subset definition superset (s t : set X) : Prop := t ⊆ s infix ⊇ := superset theorem subset.refl (a : set X) : a ⊆ a := take x, assume H, H theorem subset.trans {a b c : set X} (subab : a ⊆ b) (subbc : b ⊆ c) : a ⊆ c := take x, assume ax, subbc (subab ax) theorem subset.antisymm {a b : set X} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b := ext (λ x, iff.intro (λ ina, h₁ ina) (λ inb, h₂ inb)) -- an alterantive name theorem eq_of_subset_of_subset {a b : set X} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b := subset.antisymm h₁ h₂ theorem mem_of_subset_of_mem {s₁ s₂ : set X} {a : X} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := assume h₁ h₂, h₁ _ h₂ /- strict subset -/ definition strict_subset (a b : set X) := a ⊆ b ∧ a ≠ b infix ` ⊂ `:50 := strict_subset theorem strict_subset.irrefl (a : set X) : ¬ a ⊂ a := assume h, absurd rfl (and.elim_right h) /- bounded quantification -/ abbreviation bounded_forall (a : set X) (P : X → Prop) := ∀⦃x⦄, x ∈ a → P x notation `forallb` binders ` ∈ ` a `, ` r:(scoped:1 P, P) := bounded_forall a r notation `∀₀` binders ` ∈ ` a `, ` r:(scoped:1 P, P) := bounded_forall a r abbreviation bounded_exists (a : set X) (P : X → Prop) := ∃⦃x⦄, x ∈ a ∧ P x notation `existsb` binders ` ∈ ` a `, ` r:(scoped:1 P, P) := bounded_exists a r notation `∃₀` binders ` ∈ ` a `, ` r:(scoped:1 P, P) := bounded_exists a r theorem bounded_exists.intro {P : X → Prop} {s : set X} {x : X} (xs : x ∈ s) (Px : P x) : ∃₀ x ∈ s, P x := exists.intro x (and.intro xs Px) lemma bounded_forall_congr {A : Type} {S : set A} {P Q : A → Prop} (H : ∀₀ x ∈ S, P x ↔ Q x) : (∀₀ x ∈ S, P x) = (∀₀ x ∈ S, Q x) := begin apply propext, apply forall_congr, intros x, apply imp_congr_right, apply H end lemma bounded_exists_congr {A : Type} {S : set A} {P Q : A → Prop} (H : ∀₀ x ∈ S, P x ↔ Q x) : (∃₀ x ∈ S, P x) = (∃₀ x ∈ S, Q x) := begin apply propext, apply exists_congr, intros x, apply and_congr_right, apply H end section open classical lemma not_bounded_exists {A : Type} {S : set A} {P : A → Prop} : (¬ (∃₀ x ∈ S, P x)) = (∀₀ x ∈ S, ¬ P x) := begin rewrite forall_iff_not_exists, apply propext, apply forall_congr, intro x, rewrite not_and_iff_not_or_not, symmetry, apply imp_iff_not_or end lemma not_bounded_forall {A : Type} {S : set A} {P : A → Prop} : (¬ (∀₀ x ∈ S, P x)) = (∃₀ x ∈ S, ¬ P x) := calc (¬ (∀₀ x ∈ S, P x)) = ¬ ¬ (∃₀ x ∈ S, ¬ P x) : begin rewrite not_bounded_exists, apply (congr_arg not), apply bounded_forall_congr, intros x H, rewrite not_not_iff end ... = (∃₀ x ∈ S, ¬ P x) : by (rewrite not_not_iff) end /- empty set -/ definition empty : set X := λx, false notation `∅` := empty theorem not_mem_empty (x : X) : ¬ (x ∈ ∅) := assume H : x ∈ ∅, H theorem mem_empty_eq (x : X) : x ∈ ∅ = false := rfl theorem eq_empty_of_forall_not_mem {s : set X} (H : ∀ x, x ∉ s) : s = ∅ := ext (take x, iff.intro (assume xs, absurd xs (H x)) (assume xe, absurd xe !not_mem_empty)) theorem ne_empty_of_mem {s : set X} {x : X} (H : x ∈ s) : s ≠ ∅ := begin intro Hs, rewrite Hs at H, apply not_mem_empty _ H end section open classical theorem exists_mem_of_ne_empty {s : set X} (H : s ≠ ∅) : ∃ x, x ∈ s := by_contradiction (assume H', H (eq_empty_of_forall_not_mem (forall_not_of_not_exists H'))) end theorem empty_subset (s : set X) : ∅ ⊆ s := take x, assume H, false.elim H theorem eq_empty_of_subset_empty {s : set X} (H : s ⊆ ∅) : s = ∅ := subset.antisymm H (empty_subset s) theorem subset_empty_iff (s : set X) : s ⊆ ∅ ↔ s = ∅ := iff.intro eq_empty_of_subset_empty (take xeq, by rewrite xeq; apply subset.refl ∅) lemma bounded_forall_empty_iff {P : X → Prop} : (∀₀x∈∅, P x) ↔ true := iff.intro (take H, true.intro) (take H, by contradiction) /- universal set -/ definition univ : set X := λx, true theorem mem_univ (x : X) : x ∈ univ := trivial theorem mem_univ_iff (x : X) : x ∈ univ ↔ true := !iff.refl theorem mem_univ_eq (x : X) : x ∈ univ = true := rfl theorem empty_ne_univ [h : inhabited X] : (empty : set X) ≠ univ := assume H : empty = univ, absurd (mem_univ (inhabited.value h)) (eq.rec_on H (not_mem_empty _)) theorem subset_univ (s : set X) : s ⊆ univ := λ x H, trivial theorem eq_univ_of_univ_subset {s : set X} (H : univ ⊆ s) : s = univ := eq_of_subset_of_subset (subset_univ s) H theorem eq_univ_of_forall {s : set X} (H : ∀ x, x ∈ s) : s = univ := ext (take x, iff.intro (assume H', trivial) (assume H', H x)) /- union -/ definition union (a b : set X) : set X := λx, x ∈ a ∨ x ∈ b notation a ∪ b := union a b theorem mem_union_left {x : X} {a : set X} (b : set X) : x ∈ a → x ∈ a ∪ b := assume h, or.inl h theorem mem_union_right {x : X} {b : set X} (a : set X) : x ∈ b → x ∈ a ∪ b := assume h, or.inr h theorem mem_unionl {x : X} {a b : set X} : x ∈ a → x ∈ a ∪ b := assume h, or.inl h theorem mem_unionr {x : X} {a b : set X} : x ∈ b → x ∈ a ∪ b := assume h, or.inr h theorem mem_or_mem_of_mem_union {x : X} {a b : set X} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b := H theorem mem_union.elim {x : X} {a b : set X} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P) (H₃ : x ∈ b → P) : P := or.elim H₁ H₂ H₃ theorem mem_union_iff (x : X) (a b : set X) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := !iff.refl theorem mem_union_eq (x : X) (a b : set X) : x ∈ a ∪ b = (x ∈ a ∨ x ∈ b) := rfl theorem union_self (a : set X) : a ∪ a = a := ext (take x, !or_self) theorem union_empty (a : set X) : a ∪ ∅ = a := ext (take x, !or_false) theorem empty_union (a : set X) : ∅ ∪ a = a := ext (take x, !false_or) theorem union_comm (a b : set X) : a ∪ b = b ∪ a := ext (take x, or.comm) theorem union_assoc (a b c : set X) : (a ∪ b) ∪ c = a ∪ (b ∪ c) := ext (take x, or.assoc) theorem union_left_comm (s₁ s₂ s₃ : set X) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) := !left_comm union_comm union_assoc s₁ s₂ s₃ theorem union_right_comm (s₁ s₂ s₃ : set X) : (s₁ ∪ s₂) ∪ s₃ = (s₁ ∪ s₃) ∪ s₂ := !right_comm union_comm union_assoc s₁ s₂ s₃ theorem subset_union_left (s t : set X) : s ⊆ s ∪ t := λ x H, or.inl H theorem subset_union_right (s t : set X) : t ⊆ s ∪ t := λ x H, or.inr H theorem union_subset {s t r : set X} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := λ x xst, or.elim xst (λ xs, sr xs) (λ xt, tr xt) /- intersection -/ definition inter (a b : set X) : set X := λx, x ∈ a ∧ x ∈ b notation a ∩ b := inter a b theorem mem_inter_iff (x : X) (a b : set X) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := !iff.refl theorem mem_inter_eq (x : X) (a b : set X) : x ∈ a ∩ b = (x ∈ a ∧ x ∈ b) := rfl theorem mem_inter {x : X} {a b : set X} (Ha : x ∈ a) (Hb : x ∈ b) : x ∈ a ∩ b := and.intro Ha Hb theorem mem_of_mem_inter_left {x : X} {a b : set X} (H : x ∈ a ∩ b) : x ∈ a := and.left H theorem mem_of_mem_inter_right {x : X} {a b : set X} (H : x ∈ a ∩ b) : x ∈ b := and.right H theorem inter_self (a : set X) : a ∩ a = a := ext (take x, !and_self) theorem inter_empty (a : set X) : a ∩ ∅ = ∅ := ext (take x, !and_false) theorem empty_inter (a : set X) : ∅ ∩ a = ∅ := ext (take x, !false_and) theorem nonempty_of_inter_nonempty_right {T : Type} {s t : set T} (H : s ∩ t ≠ ∅) : t ≠ ∅ := suppose t = ∅, have s ∩ t = ∅, by rewrite this; apply inter_empty, H this theorem nonempty_of_inter_nonempty_left {T : Type} {s t : set T} (H : s ∩ t ≠ ∅) : s ≠ ∅ := suppose s = ∅, have s ∩ t = ∅, by rewrite this; apply empty_inter, H this theorem inter_comm (a b : set X) : a ∩ b = b ∩ a := ext (take x, !and.comm) theorem inter_assoc (a b c : set X) : (a ∩ b) ∩ c = a ∩ (b ∩ c) := ext (take x, !and.assoc) theorem inter_left_comm (s₁ s₂ s₃ : set X) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := !left_comm inter_comm inter_assoc s₁ s₂ s₃ theorem inter_right_comm (s₁ s₂ s₃ : set X) : (s₁ ∩ s₂) ∩ s₃ = (s₁ ∩ s₃) ∩ s₂ := !right_comm inter_comm inter_assoc s₁ s₂ s₃ theorem inter_univ (a : set X) : a ∩ univ = a := ext (take x, !and_true) theorem univ_inter (a : set X) : univ ∩ a = a := ext (take x, !true_and) theorem inter_subset_left (s t : set X) : s ∩ t ⊆ s := λ x H, and.left H theorem inter_subset_right (s t : set X) : s ∩ t ⊆ t := λ x H, and.right H theorem inter_subset_inter_right {s t : set X} (u : set X) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u := take x, assume xsu, and.intro (H (and.left xsu)) (and.right xsu) theorem inter_subset_inter_left {s t : set X} (u : set X) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t := take x, assume xus, and.intro (and.left xus) (H (and.right xus)) theorem subset_inter {s t r : set X} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := λ x xr, and.intro (rs xr) (rt xr) theorem not_mem_of_mem_of_not_mem_inter_left {s t : set X} {x : X} (Hxs : x ∈ s) (Hnm : x ∉ s ∩ t) : x ∉ t := suppose x ∈ t, have x ∈ s ∩ t, from and.intro Hxs this, show false, from Hnm this theorem not_mem_of_mem_of_not_mem_inter_right {s t : set X} {x : X} (Hxs : x ∈ t) (Hnm : x ∉ s ∩ t) : x ∉ s := suppose x ∈ s, have x ∈ s ∩ t, from and.intro this Hxs, show false, from Hnm this /- distributivity laws -/ theorem inter_distrib_left (s t u : set X) : s ∩ (t ∪ u) = (s ∩ t) ∪ (s ∩ u) := ext (take x, !and.left_distrib) theorem inter_distrib_right (s t u : set X) : (s ∪ t) ∩ u = (s ∩ u) ∪ (t ∩ u) := ext (take x, !and.right_distrib) theorem union_distrib_left (s t u : set X) : s ∪ (t ∩ u) = (s ∪ t) ∩ (s ∪ u) := ext (take x, !or.left_distrib) theorem union_distrib_right (s t u : set X) : (s ∩ t) ∪ u = (s ∪ u) ∩ (t ∪ u) := ext (take x, !or.right_distrib) /- set-builder notation -/ -- {x : X | P} definition set_of (P : X → Prop) : set X := P notation `{` binder ` | ` r:(scoped:1 P, set_of P) `}` := r -- {x ∈ s | P} definition sep (P : X → Prop) (s : set X) : set X := λx, x ∈ s ∧ P x notation `{` binder ` ∈ ` s ` | ` r:(scoped:1 p, sep p s) `}` := r /- insert -/ definition insert (x : X) (a : set X) : set X := {y : X | y = x ∨ y ∈ a} -- '{x, y, z} notation `'{`:max a:(foldr `, ` (x b, insert x b) ∅) `}`:0 := a theorem subset_insert (x : X) (a : set X) : a ⊆ insert x a := take y, assume ys, or.inr ys theorem mem_insert (x : X) (s : set X) : x ∈ insert x s := or.inl rfl theorem mem_insert_of_mem {x : X} {s : set X} (y : X) : x ∈ s → x ∈ insert y s := assume h, or.inr h theorem eq_or_mem_of_mem_insert {x a : X} {s : set X} : x ∈ insert a s → x = a ∨ x ∈ s := assume h, h theorem mem_of_mem_insert_of_ne {x a : X} {s : set X} (xin : x ∈ insert a s) : x ≠ a → x ∈ s := or_resolve_right (eq_or_mem_of_mem_insert xin) theorem mem_insert_eq (x a : X) (s : set X) : x ∈ insert a s = (x = a ∨ x ∈ s) := propext (iff.intro !eq_or_mem_of_mem_insert (or.rec (λH', (eq.substr H' !mem_insert)) !mem_insert_of_mem)) theorem insert_eq_of_mem {a : X} {s : set X} (H : a ∈ s) : insert a s = s := ext (λ x, eq.substr (mem_insert_eq x a s) (or_iff_right_of_imp (λH1, eq.substr H1 H))) theorem insert.comm (x y : X) (s : set X) : insert x (insert y s) = insert y (insert x s) := ext (take a, by rewrite [*mem_insert_eq, propext !or.left_comm]) -- useful in proofs by induction theorem forall_of_forall_insert {P : X → Prop} {a : X} {s : set X} (H : ∀ x, x ∈ insert a s → P x) : ∀ x, x ∈ s → P x := λ x xs, H x (!mem_insert_of_mem xs) lemma bounded_forall_insert_iff {P : X → Prop} {a : X} {s : set X} : (∀₀x ∈ insert a s, P x) ↔ P a ∧ (∀₀x ∈ s, P x) := begin apply iff.intro, all_goals (intro H), { apply and.intro, { apply H, apply mem_insert }, { intro x Hx, apply H, apply mem_insert_of_mem, assumption } }, { intro x Hx, cases Hx with eq Hx, { cases eq, apply (and.elim_left H) }, { apply (and.elim_right H), assumption } } end /- singleton -/ theorem mem_singleton_iff (a b : X) : a ∈ '{b} ↔ a = b := iff.intro (assume ainb, or.elim ainb (λ aeqb, aeqb) (λ f, false.elim f)) (assume aeqb, or.inl aeqb) theorem mem_singleton (a : X) : a ∈ '{a} := !mem_insert theorem eq_of_mem_singleton {x y : X} (h : x ∈ '{y}) : x = y := or.elim (eq_or_mem_of_mem_insert h) (suppose x = y, this) (suppose x ∈ ∅, absurd this !not_mem_empty) theorem mem_singleton_of_eq {x y : X} (H : x = y) : x ∈ '{y} := eq.symm H ▸ mem_singleton y theorem insert_eq (x : X) (s : set X) : insert x s = '{x} ∪ s := ext (take y, iff.intro (suppose y ∈ insert x s, or.elim this (suppose y = x, or.inl (or.inl this)) (suppose y ∈ s, or.inr this)) (suppose y ∈ '{x} ∪ s, or.elim this (suppose y ∈ '{x}, or.inl (eq_of_mem_singleton this)) (suppose y ∈ s, or.inr this))) theorem pair_eq_singleton (a : X) : '{a, a} = '{a} := by rewrite [insert_eq_of_mem !mem_singleton] theorem singleton_ne_empty (a : X) : '{a} ≠ ∅ := begin intro H, apply not_mem_empty a, rewrite -H, apply mem_insert end /- separation -/ theorem mem_sep {s : set X} {P : X → Prop} {x : X} (xs : x ∈ s) (Px : P x) : x ∈ {x ∈ s | P x} := and.intro xs Px theorem eq_sep_of_subset {s t : set X} (ssubt : s ⊆ t) : s = {x ∈ t | x ∈ s} := ext (take x, iff.intro (suppose x ∈ s, and.intro (ssubt this) this) (suppose x ∈ {x ∈ t | x ∈ s}, and.right this)) theorem mem_sep_iff {s : set X} {P : X → Prop} {x : X} : x ∈ {x ∈ s | P x} ↔ x ∈ s ∧ P x := !iff.refl theorem sep_subset (s : set X) (P : X → Prop) : {x ∈ s | P x} ⊆ s := take x, assume H, and.left H theorem forall_not_of_sep_empty {s : set X} {P : X → Prop} (H : {x ∈ s | P x} = ∅) : ∀₀ x ∈ s, ¬ P x := take x, suppose x ∈ s, suppose P x, have x ∈ {x ∈ s | P x}, from and.intro `x ∈ s` this, show false, from ne_empty_of_mem this H /- complement -/ definition compl (s : set X) : set X := {x | x ∉ s} prefix `-` := compl theorem mem_compl {s : set X} {x : X} (H : x ∉ s) : x ∈ -s := H theorem not_mem_of_mem_compl {s : set X} {x : X} (H : x ∈ -s) : x ∉ s := H theorem mem_compl_iff (s : set X) (x : X) : x ∈ -s ↔ x ∉ s := !iff.refl theorem inter_compl_self (s : set X) : s ∩ -s = ∅ := ext (take x, !and_not_self_iff) theorem compl_inter_self (s : set X) : -s ∩ s = ∅ := ext (take x, !not_and_self_iff) /- some classical identities -/ section open classical theorem compl_empty : -(∅ : set X) = univ := ext (take x, iff.intro (assume H, trivial) (assume H, not_false)) theorem compl_union (s t : set X) : -(s ∪ t) = -s ∩ -t := ext (take x, !not_or_iff_not_and_not) theorem compl_compl (s : set X) : -(-s) = s := ext (take x, !not_not_iff) theorem compl_inter (s t : set X) : -(s ∩ t) = -s ∪ -t := ext (take x, !not_and_iff_not_or_not) theorem compl_univ : -(univ : set X) = ∅ := by rewrite [-compl_empty, compl_compl] theorem union_eq_compl_compl_inter_compl (s t : set X) : s ∪ t = -(-s ∩ -t) := ext (take x, !or_iff_not_and_not) theorem inter_eq_compl_compl_union_compl (s t : set X) : s ∩ t = -(-s ∪ -t) := ext (take x, !and_iff_not_or_not) theorem union_compl_self (s : set X) : s ∪ -s = univ := ext (take x, !or_not_self_iff) theorem compl_union_self (s : set X) : -s ∪ s = univ := ext (take x, !not_or_self_iff) theorem compl_comp_compl : #function compl ∘ compl = @id (set X) := funext (λ s, compl_compl s) end /- set difference -/ definition diff (s t : set X) : set X := {x ∈ s | x ∉ t} infix ` \ `:70 := diff theorem mem_diff {s t : set X} {x : X} (H1 : x ∈ s) (H2 : x ∉ t) : x ∈ s \ t := and.intro H1 H2 theorem mem_of_mem_diff {s t : set X} {x : X} (H : x ∈ s \ t) : x ∈ s := and.left H theorem not_mem_of_mem_diff {s t : set X} {x : X} (H : x ∈ s \ t) : x ∉ t := and.right H theorem mem_diff_iff (s t : set X) (x : X) : x ∈ s \ t ↔ x ∈ s ∧ x ∉ t := !iff.refl theorem mem_diff_eq (s t : set X) (x : X) : x ∈ s \ t = (x ∈ s ∧ x ∉ t) := rfl theorem diff_eq (s t : set X) : s \ t = s ∩ -t := rfl theorem union_diff_cancel {s t : set X} [dec : Π x, decidable (x ∈ s)] (H : s ⊆ t) : s ∪ (t \ s) = t := ext (take x, iff.intro (assume H1 : x ∈ s ∪ (t \ s), or.elim H1 (assume H2, !H H2) (assume H2, and.left H2)) (assume H1 : x ∈ t, decidable.by_cases (suppose x ∈ s, or.inl this) (suppose x ∉ s, or.inr (and.intro H1 this)))) theorem diff_subset (s t : set X) : s \ t ⊆ s := inter_subset_left s _ theorem compl_eq_univ_diff (s : set X) : -s = univ \ s := ext (take x, iff.intro (assume H, and.intro trivial H) (assume H, and.right H)) /- powerset -/ definition powerset (s : set X) : set (set X) := {x : set X | x ⊆ s} prefix `𝒫`:100 := powerset theorem mem_powerset {x s : set X} (H : x ⊆ s) : x ∈ 𝒫 s := H theorem subset_of_mem_powerset {x s : set X} (H : x ∈ 𝒫 s) : x ⊆ s := H theorem mem_powerset_iff (x s : set X) : x ∈ 𝒫 s ↔ x ⊆ s := !iff.refl /- function image -/ section image variables {Y Z : Type} abbreviation eq_on (f1 f2 : X → Y) (a : set X) : Prop := ∀₀ x ∈ a, f1 x = f2 x definition image (f : X → Y) (a : set X) : set Y := {y : Y | ∃x, x ∈ a ∧ f x = y} infix ` ' ` := image theorem image_eq_image_of_eq_on {f1 f2 : X → Y} {a : set X} (H1 : eq_on f1 f2 a) : f1 ' a = f2 ' a := ext (take y, iff.intro (assume H2, obtain x (H3 : x ∈ a ∧ f1 x = y), from H2, have H4 : x ∈ a, from and.left H3, have H5 : f2 x = y, from (H1 H4)⁻¹ ⬝ and.right H3, exists.intro x (and.intro H4 H5)) (assume H2, obtain x (H3 : x ∈ a ∧ f2 x = y), from H2, have H4 : x ∈ a, from and.left H3, have H5 : f1 x = y, from (H1 H4) ⬝ and.right H3, exists.intro x (and.intro H4 H5))) theorem mem_image {f : X → Y} {a : set X} {x : X} {y : Y} (H1 : x ∈ a) (H2 : f x = y) : y ∈ f ' a := exists.intro x (and.intro H1 H2) theorem mem_image_of_mem (f : X → Y) {x : X} {a : set X} (H : x ∈ a) : f x ∈ image f a := mem_image H rfl lemma image_comp (f : Y → Z) (g : X → Y) (a : set X) : (f ∘ g) ' a = f ' (g ' a) := ext (take z, iff.intro (assume Hz : z ∈ (f ∘ g) ' a, obtain x (Hx₁ : x ∈ a) (Hx₂ : f (g x) = z), from Hz, have Hgx : g x ∈ g ' a, from mem_image Hx₁ rfl, show z ∈ f ' (g ' a), from mem_image Hgx Hx₂) (assume Hz : z ∈ f ' (g 'a), obtain y (Hy₁ : y ∈ g ' a) (Hy₂ : f y = z), from Hz, obtain x (Hz₁ : x ∈ a) (Hz₂ : g x = y), from Hy₁, show z ∈ (f ∘ g) ' a, from mem_image Hz₁ (Hz₂⁻¹ ▸ Hy₂))) lemma image_subset {a b : set X} (f : X → Y) (H : a ⊆ b) : f ' a ⊆ f ' b := take y, assume Hy : y ∈ f ' a, obtain x (Hx₁ : x ∈ a) (Hx₂ : f x = y), from Hy, mem_image (H Hx₁) Hx₂ theorem image_union (f : X → Y) (s t : set X) : image f (s ∪ t) = image f s ∪ image f t := ext (take y, iff.intro (assume H : y ∈ image f (s ∪ t), obtain x [(xst : x ∈ s ∪ t) (fxy : f x = y)], from H, or.elim xst (assume xs, or.inl (mem_image xs fxy)) (assume xt, or.inr (mem_image xt fxy))) (assume H : y ∈ image f s ∪ image f t, or.elim H (assume yifs : y ∈ image f s, obtain x [(xs : x ∈ s) (fxy : f x = y)], from yifs, mem_image (or.inl xs) fxy) (assume yift : y ∈ image f t, obtain x [(xt : x ∈ t) (fxy : f x = y)], from yift, mem_image (or.inr xt) fxy))) theorem image_empty (f : X → Y) : image f ∅ = ∅ := eq_empty_of_forall_not_mem (take y, suppose y ∈ image f ∅, obtain x [(H : x ∈ empty) H'], from this, H) theorem mem_image_compl (t : set X) (S : set (set X)) : t ∈ compl ' S ↔ -t ∈ S := iff.intro (suppose t ∈ compl ' S, obtain t' [(Ht' : t' ∈ S) (Ht : -t' = t)], from this, show -t ∈ S, by rewrite [-Ht, compl_compl]; exact Ht') (suppose -t ∈ S, have -(-t) ∈ compl 'S, from mem_image_of_mem compl this, show t ∈ compl 'S, from compl_compl t ▸ this) theorem image_id (s : set X) : id ' s = s := ext (take x, iff.intro (suppose x ∈ id ' s, obtain x' [(Hx' : x' ∈ s) (x'eq : x' = x)], from this, show x ∈ s, by rewrite [-x'eq]; apply Hx') (suppose x ∈ s, mem_image_of_mem id this)) theorem compl_compl_image (S : set (set X)) : compl ' (compl ' S) = S := by rewrite [-image_comp, compl_comp_compl, image_id] lemma bounded_forall_image_of_bounded_forall {f : X → Y} {S : set X} {P : Y → Prop} (H : ∀₀ x ∈ S, P (f x)) : ∀₀ y ∈ f ' S, P y := begin intro x' Hx; cases Hx with x Hx; cases Hx with Hx eq; rewrite (eq⁻¹); apply H; assumption end lemma bounded_forall_image_iff {f : X → Y} {S : set X} {P : Y → Prop} : (∀₀ y ∈ f ' S, P y) ↔ (∀₀ x ∈ S, P (f x)) := iff.intro (take H x Hx, H _ (!mem_image_of_mem `x ∈ S`)) bounded_forall_image_of_bounded_forall lemma image_insert_eq {f : X → Y} {a : X} {S : set X} : f ' insert a S = insert (f a) (f ' S) := begin apply set.ext, intro x, apply iff.intro, all_goals (intros H), { cases H with y Hy, cases Hy with Hy eq, rewrite (eq⁻¹), cases Hy with y_eq, { rewrite y_eq, apply mem_insert }, { apply mem_insert_of_mem, apply mem_image_of_mem, assumption } }, { cases H with eq Hx, { rewrite eq, apply mem_image_of_mem, apply mem_insert }, { cases Hx with y Hy, cases Hy with Hy eq, rewrite (eq⁻¹), apply mem_image_of_mem, apply mem_insert_of_mem, assumption } } end end image /- collections of disjoint sets -/ definition disjoint_sets (S : set (set X)) : Prop := ∀ a b, a ∈ S → b ∈ S → a ≠ b → a ∩ b = ∅ theorem disjoint_sets_empty : disjoint_sets (∅ : set (set X)) := take a b, assume H, !not.elim !not_mem_empty H theorem disjoint_sets_union {s t : set (set X)} (Hs : disjoint_sets s) (Ht : disjoint_sets t) (H : ∀ x y, x ∈ s ∧ y ∈ t → x ∩ y = ∅) : disjoint_sets (s ∪ t) := take a b, assume Ha Hb Hneq, or.elim Ha (assume H1, or.elim Hb (suppose b ∈ s, (Hs a b) H1 this Hneq) (suppose b ∈ t, (H a b) (and.intro H1 this))) (assume H2, or.elim Hb (suppose b ∈ s, !inter_comm ▸ ((H b a) (and.intro this H2))) (suppose b ∈ t, (Ht a b) H2 this Hneq)) theorem disjoint_sets_singleton (s : set (set X)) : disjoint_sets '{s} := take a b, assume Ha Hb Hneq, absurd (eq.trans ((iff.elim_left !mem_singleton_iff) Ha) ((iff.elim_left !mem_singleton_iff) Hb)⁻¹) Hneq /- large unions -/ section large_unions variables {I : Type} variable a : set I variable b : I → set X variable C : set (set X) definition sUnion : set X := {x : X | ∃₀ c ∈ C, x ∈ c} definition sInter : set X := {x : X | ∀₀ c ∈ C, x ∈ c} prefix `⋃₀`:110 := sUnion prefix `⋂₀`:110 := sInter definition Union : set X := {x : X | ∃i, x ∈ b i} definition Inter : set X := {x : X | ∀i, x ∈ b i} notation `⋃` binders `, ` r:(scoped f, Union f) := r notation `⋂` binders `, ` r:(scoped f, Inter f) := r definition bUnion : set X := {x : X | ∃₀ i ∈ a, x ∈ b i} definition bInter : set X := {x : X | ∀₀ i ∈ a, x ∈ b i} notation `⋃` binders ` ∈ ` s `, ` r:(scoped f, bUnion s f) := r notation `⋂` binders ` ∈ ` s `, ` r:(scoped f, bInter s f) := r end large_unions -- sUnion and sInter: a collection (set) of sets theorem mem_sUnion {x : X} {t : set X} {S : set (set X)} (Hx : x ∈ t) (Ht : t ∈ S) : x ∈ ⋃₀ S := exists.intro t (and.intro Ht Hx) theorem not_mem_of_not_mem_sUnion {x : X} {t : set X} {S : set (set X)} (Hx : x ∉ ⋃₀ S) (Ht : t ∈ S) : x ∉ t := suppose x ∈ t, have x ∈ ⋃₀ S, from mem_sUnion this Ht, show false, from Hx this theorem mem_sInter {x : X} {t : set X} {S : set (set X)} (H : ∀₀ t ∈ S, x ∈ t) : x ∈ ⋂₀ S := H theorem sInter_subset_of_mem {S : set (set X)} {t : set X} (tS : t ∈ S) : (⋂₀ S) ⊆ t := take x, assume H, H t tS theorem subset_sUnion_of_mem {S : set (set X)} {t : set X} (tS : t ∈ S) : t ⊆ (⋃₀ S) := take x, assume H, exists.intro t (and.intro tS H) theorem sUnion_empty : ⋃₀ ∅ = (∅ : set X) := eq_empty_of_forall_not_mem (take x, suppose x ∈ sUnion ∅, obtain t [(Ht : t ∈ ∅) Ht'], from this, show false, from Ht) theorem sInter_empty : ⋂₀ ∅ = (univ : set X) := eq_univ_of_forall (λ x s H, false.elim H) theorem sUnion_singleton (s : set X) : ⋃₀ '{s} = s := ext (take x, iff.intro (suppose x ∈ sUnion '{s}, obtain u [(Hu : u ∈ '{s}) (xu : x ∈ u)], from this, have u = s, from eq_of_mem_singleton Hu, show x ∈ s, by rewrite -this; apply xu) (suppose x ∈ s, mem_sUnion this (mem_singleton s))) theorem sInter_singleton (s : set X) : ⋂₀ '{s} = s := ext (take x, iff.intro (suppose x ∈ ⋂₀ '{s}, show x ∈ s, from this (mem_singleton s)) (suppose x ∈ s, take u, suppose u ∈ '{s}, show x ∈ u, by rewrite [eq_of_mem_singleton this]; assumption)) theorem sUnion_union (S T : set (set X)) : ⋃₀ (S ∪ T) = ⋃₀ S ∪ ⋃₀ T := ext (take x, iff.intro (suppose x ∈ sUnion (S ∪ T), obtain u [(Hu : u ∈ S ∪ T) (xu : x ∈ u)], from this, or.elim Hu (assume uS, or.inl (mem_sUnion xu uS)) (assume uT, or.inr (mem_sUnion xu uT))) (suppose x ∈ sUnion S ∪ sUnion T, or.elim this (suppose x ∈ sUnion S, obtain u [(uS : u ∈ S) (xu : x ∈ u)], from this, mem_sUnion xu (or.inl uS)) (suppose x ∈ sUnion T, obtain u [(uT : u ∈ T) (xu : x ∈ u)], from this, mem_sUnion xu (or.inr uT)))) theorem sInter_union (S T : set (set X)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T := ext (take x, iff.intro (assume H : x ∈ ⋂₀ (S ∪ T), and.intro (λ u uS, H (or.inl uS)) (λ u uT, H (or.inr uT))) (assume H : x ∈ ⋂₀ S ∩ ⋂₀ T, take u, suppose u ∈ S ∪ T, or.elim this (λ uS, and.left H u uS) (λ uT, and.right H u uT))) theorem sUnion_insert (s : set X) (T : set (set X)) : ⋃₀ (insert s T) = s ∪ ⋃₀ T := by rewrite [insert_eq, sUnion_union, sUnion_singleton] theorem sInter_insert (s : set X) (T : set (set X)) : ⋂₀ (insert s T) = s ∩ ⋂₀ T := by rewrite [insert_eq, sInter_union, sInter_singleton] theorem compl_sUnion (S : set (set X)) : - ⋃₀ S = ⋂₀ (compl ' S) := ext (take x, iff.intro (assume H : x ∈ -(⋃₀ S), take t, suppose t ∈ compl ' S, obtain t' [(Ht' : t' ∈ S) (Ht : -t' = t)], from this, have x ∈ -t', from suppose x ∈ t', H (mem_sUnion this Ht'), show x ∈ t, by rewrite -Ht; apply this) (assume H : x ∈ ⋂₀ (compl ' S), suppose x ∈ ⋃₀ S, obtain t [(tS : t ∈ S) (xt : x ∈ t)], from this, have -t ∈ compl ' S, from mem_image_of_mem compl tS, have x ∈ -t, from H this, show false, proof this xt qed)) theorem sUnion_eq_compl_sInter_compl (S : set (set X)) : ⋃₀ S = - ⋂₀ (compl ' S) := by rewrite [-compl_compl (⋃₀ S), compl_sUnion] theorem compl_sInter (S : set (set X)) : - ⋂₀ S = ⋃₀ (compl ' S) := by rewrite [sUnion_eq_compl_sInter_compl, compl_compl_image] theorem sInter_eq_comp_sUnion_compl (S : set (set X)) : ⋂₀ S = -(⋃₀ (compl ' S)) := by rewrite [-compl_compl (⋂₀ S), compl_sInter] theorem inter_sUnion_nonempty_of_inter_nonempty {s t : set X} {S : set (set X)} (Hs : t ∈ S) (Hne : s ∩ t ≠ ∅) : s ∩ ⋃₀ S ≠ ∅ := obtain x Hsx Htx, from exists_mem_of_ne_empty Hne, have x ∈ ⋃₀ S, from mem_sUnion Htx Hs, ne_empty_of_mem (mem_inter Hsx this) theorem sUnion_inter_nonempty_of_inter_nonempty {s t : set X} {S : set (set X)} (Hs : t ∈ S) (Hne : t ∩ s ≠ ∅) : (⋃₀ S) ∩ s ≠ ∅ := obtain x Htx Hsx, from exists_mem_of_ne_empty Hne, have x ∈ ⋃₀ S, from mem_sUnion Htx Hs, ne_empty_of_mem (mem_inter this Hsx) -- Union and Inter: a family of sets indexed by a type theorem Union_subset {I : Type} {b : I → set X} {c : set X} (H : ∀ i, b i ⊆ c) : (⋃ i, b i) ⊆ c := take x, suppose x ∈ Union b, obtain i (Hi : x ∈ b i), from this, show x ∈ c, from H i Hi theorem subset_Inter {I : Type} {b : I → set X} {c : set X} (H : ∀ i, c ⊆ b i) : c ⊆ ⋂ i, b i := λ x cx i, H i cx theorem Union_eq_sUnion_image {X I : Type} (s : I → set X) : (⋃ i, s i) = ⋃₀ (s ' univ) := ext (take x, iff.intro (suppose x ∈ Union s, obtain i (Hi : x ∈ s i), from this, mem_sUnion Hi (mem_image_of_mem s trivial)) (suppose x ∈ sUnion (s ' univ), obtain t [(Ht : t ∈ s ' univ) (Hx : x ∈ t)], from this, obtain i [univi (Hi : s i = t)], from Ht, exists.intro i (show x ∈ s i, by rewrite Hi; apply Hx))) theorem Inter_eq_sInter_image {X I : Type} (s : I → set X) : (⋂ i, s i) = ⋂₀ (s ' univ) := ext (take x, iff.intro (assume H : x ∈ Inter s, take t, suppose t ∈ s 'univ, obtain i [univi (Hi : s i = t)], from this, show x ∈ t, by rewrite -Hi; exact H i) (assume H : x ∈ ⋂₀ (s ' univ), take i, have s i ∈ s ' univ, from mem_image_of_mem s trivial, show x ∈ s i, from H this)) theorem compl_Union {X I : Type} (s : I → set X) : - (⋃ i, s i) = (⋂ i, - s i) := by rewrite [Union_eq_sUnion_image, compl_sUnion, -image_comp, -Inter_eq_sInter_image] theorem compl_Inter {X I : Type} (s : I → set X) : -(⋂ i, s i) = (⋃ i, - s i) := by rewrite [Inter_eq_sInter_image, compl_sInter, -image_comp, -Union_eq_sUnion_image] theorem Union_eq_comp_Inter_comp {X I : Type} (s : I → set X) : (⋃ i, s i) = - (⋂ i, - s i) := by rewrite [-compl_compl (⋃ i, s i), compl_Union] theorem Inter_eq_comp_Union_comp {X I : Type} (s : I → set X) : (⋂ i, s i) = - (⋃ i, -s i) := by rewrite [-compl_compl (⋂ i, s i), compl_Inter] lemma inter_distrib_Union_left {X I : Type} (s : I → set X) (a : set X) : a ∩ (⋃ i, s i) = ⋃ i, a ∩ s i := ext (take x, iff.intro (assume H, obtain i Hi, from and.elim_right H, have x ∈ a ∩ s i, from and.intro (and.elim_left H) Hi, show _, from exists.intro i this) (assume H, obtain i [xa xsi], from H, show _, from and.intro xa (exists.intro i xsi))) section open classical lemma union_distrib_Inter_left {X I : Type} (s : I → set X) (a : set X) : a ∪ (⋂ i, s i) = ⋂ i, a ∪ s i := ext (take x, iff.intro (assume H, or.elim H (assume H1, take i, or.inl H1) (assume H1, take i, or.inr (H1 i))) (assume H, by_cases (suppose x ∈ a, or.inl this) (suppose x ∉ a, or.inr (take i, or.resolve_left (H i) this)))) end -- these are useful for turning binary union / intersection into countable ones definition bin_ext (s t : set X) (n : ℕ) : set X := nat.cases_on n s (λ m, t) lemma Union_bin_ext (s t : set X) : (⋃ i, bin_ext s t i) = s ∪ t := ext (take x, iff.intro (assume H, obtain i (Hi : x ∈ (bin_ext s t) i), from H, by cases i; apply or.inl Hi; apply or.inr Hi) (assume H, or.elim H (suppose x ∈ s, exists.intro 0 this) (suppose x ∈ t, exists.intro 1 this))) lemma Inter_bin_ext (s t : set X) : (⋂ i, bin_ext s t i) = s ∩ t := ext (take x, iff.intro (assume H, and.intro (H 0) (H 1)) (assume H, by intro i; cases i; apply and.elim_left H; apply and.elim_right H)) -- bUnion and bInter: a family of sets indexed by a set ("b" is for bounded) variable {Y : Type} theorem mem_bUnion {s : set X} {f : X → set Y} {x : X} {y : Y} (xs : x ∈ s) (yfx : y ∈ f x) : y ∈ ⋃ x ∈ s, f x := exists.intro x (and.intro xs yfx) theorem mem_bInter {s : set X} {f : X → set Y} {y : Y} (H : ∀₀ x ∈ s, y ∈ f x) : y ∈ ⋂ x ∈ s, f x := H theorem bUnion_subset {s : set X} {t : set Y} {f : X → set Y} (H : ∀₀ x ∈ s, f x ⊆ t) : (⋃ x ∈ s, f x) ⊆ t := take y, assume Hy, obtain x [xs yfx], from Hy, show y ∈ t, from H xs yfx theorem subset_bInter {s : set X} {t : set Y} {f : X → set Y} (H : ∀₀ x ∈ s, t ⊆ f x) : t ⊆ ⋂ x ∈ s, f x := take y, assume yt, take x, assume xs, H xs yt theorem subset_bUnion_of_mem {s : set X} {f : X → set Y} {x : X} (xs : x ∈ s) : f x ⊆ ⋃ x ∈ s, f x := take y, assume Hy, mem_bUnion xs Hy theorem bInter_subset_of_mem {s : set X} {f : X → set Y} {x : X} (xs : x ∈ s) : (⋂ x ∈ s, f x) ⊆ f x := take y, assume Hy, Hy x xs theorem bInter_empty (f : X → set Y) : (⋂ x ∈ (∅ : set X), f x) = univ := eq_univ_of_forall (take y x xine, absurd xine !not_mem_empty) theorem bInter_singleton (a : X) (f : X → set Y) : (⋂ x ∈ '{a}, f x) = f a := ext (take y, iff.intro (assume H, H a !mem_singleton) (assume H, λ x xa, by rewrite [eq_of_mem_singleton xa]; apply H)) theorem bInter_union (s t : set X) (f : X → set Y) : (⋂ x ∈ s ∪ t, f x) = (⋂ x ∈ s, f x) ∩ (⋂ x ∈ t, f x) := ext (take y, iff.intro (assume H, and.intro (λ x xs, H x (or.inl xs)) (λ x xt, H x (or.inr xt))) (assume H, λ x xst, or.elim (xst) (λ xs, and.left H x xs) (λ xt, and.right H x xt))) theorem bInter_insert (a : X) (s : set X) (f : X → set Y) : (⋂ x ∈ insert a s, f x) = f a ∩ (⋂ x ∈ s, f x) := by rewrite [insert_eq, bInter_union, bInter_singleton] theorem bInter_pair (a b : X) (f : X → set Y) : (⋂ x ∈ '{a, b}, f x) = f a ∩ f b := by rewrite [*bInter_insert, bInter_empty, inter_univ] theorem bUnion_empty (f : X → set Y) : (⋃ x ∈ (∅ : set X), f x) = ∅ := eq_empty_of_forall_not_mem (λ y H, obtain x [xine yfx], from H, !not_mem_empty xine) theorem bUnion_singleton (a : X) (f : X → set Y) : (⋃ x ∈ '{a}, f x) = f a := ext (take y, iff.intro (assume H, obtain x [xina yfx], from H, show y ∈ f a, by rewrite [-eq_of_mem_singleton xina]; exact yfx) (assume H, exists.intro a (and.intro !mem_singleton H))) theorem bUnion_union (s t : set X) (f : X → set Y) : (⋃ x ∈ s ∪ t, f x) = (⋃ x ∈ s, f x) ∪ (⋃ x ∈ t, f x) := ext (take y, iff.intro (assume H, obtain x [xst yfx], from H, or.elim xst (λ xs, or.inl (exists.intro x (and.intro xs yfx))) (λ xt, or.inr (exists.intro x (and.intro xt yfx)))) (assume H, or.elim H (assume H1, obtain x [xs yfx], from H1, exists.intro x (and.intro (or.inl xs) yfx)) (assume H1, obtain x [xt yfx], from H1, exists.intro x (and.intro (or.inr xt) yfx)))) theorem bUnion_insert (a : X) (s : set X) (f : X → set Y) : (⋃ x ∈ insert a s, f x) = f a ∪ (⋃ x ∈ s, f x) := by rewrite [insert_eq, bUnion_union, bUnion_singleton] theorem bUnion_pair (a b : X) (f : X → set Y) : (⋃ x ∈ '{a, b}, f x) = f a ∪ f b := by rewrite [*bUnion_insert, bUnion_empty, union_empty] end set
e3ae01abe7978d8361ee004c6d93121580ecaeb2
5fbbd711f9bfc21ee168f46a4be146603ece8835
/lean/natural_number_game/multiplication/1.lean
948d4e002b90839327463872bc0bed11022e5f93
[ "LicenseRef-scancode-warranty-disclaimer" ]
no_license
goedel-gang/maths
22596f71e3fde9c088e59931f128a3b5efb73a2c
a20a6f6a8ce800427afd595c598a5ad43da1408d
refs/heads/master
1,623,055,941,960
1,621,599,441,000
1,621,599,441,000
169,335,840
0
0
null
null
null
null
UTF-8
Lean
false
false
120
lean
lemma zero_mul (m : mynat) : 0 * m = 0 := induction m with n hn, rwa mul_zero, rw mul_succ, rw hn, simp, end
907c2c01bd6773c4c0de6a007f5f8df5ec281a47
6de8ea38e7f58ace8fbf74ba3ad0bf3b3d1d7ab5
/homework2/Warmup/solutions.lean
b3e76c2817e2ec9587d962ec0876406861f97576
[]
no_license
KinanBab/CS591K1-Labs
72f4e2c7d230d4e4f548a343a47bf815272b1f58
d4569bf99d20c22cd56721024688cda247d1447f
refs/heads/master
1,587,016,758,873
1,558,148,366,000
1,558,148,366,000
165,329,114
5
2
null
1,550,689,848,000
1,547,252,664,000
TeX
UTF-8
Lean
false
false
476
lean
-- Warmup: first order logic (10 points) -- Two simple first order logic tautologies, these are true -- in intuisionistic first order. -- Part A: 5 points theorem simple_one (t: Type) (P1 P2: t-> Prop) : (∀{a: t}, P1 a ∧ P2 a) -> (∀{b: t}, P1 b) := begin -- proof goes here end -- Part B: 5 points theorem simple_two (t: Type) (P1 P2: t -> Prop) : (∃{a: t}, (P1 a ∨ P2 a)) → (∃{b: t}, P1 b) ∨ (∃{b: t}, P2 b) := begin -- proof goes here end
61d333f4a8f54b1ad0f46c11c8ba8d2012b48ddd
c777c32c8e484e195053731103c5e52af26a25d1
/src/measure_theory/measure/measure_space_def.lean
cb8949247984b71ef8348107045af7e7d5178b98
[ "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
24,926
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 -/ import measure_theory.measure.outer_measure import order.filter.countable_Inter /-! # Measure spaces > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines measure spaces, the almost-everywhere filter and ae_measurable functions. See `measure_theory.measure_space` for their properties and for extended documentation. Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the extended nonnegative reals that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint sets is equal to the sum of the measures of the individual sets. Every measure can be canonically extended to an outer measure, so that it assigns values to all subsets, not just the measurable subsets. On the other hand, an outer measure that is countably additive on measurable sets can be restricted to measurable sets to obtain a measure. In this file a measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`. ## Implementation notes Given `μ : measure α`, `μ s` is the value of the *outer measure* applied to `s`. This conveniently allows us to apply the measure to sets without proving that they are measurable. We get countable subadditivity for all sets, but only countable additivity for measurable sets. See the documentation of `measure_theory.measure_space` for ways to construct measures and proving that two measure are equal. A `measure_space` is a class that is a measurable space with a canonical measure. The measure is denoted `volume`. This file does not import `measure_theory.measurable_space`, but only `measurable_space_def`. ## References * <https://en.wikipedia.org/wiki/Measure_(mathematics)> * <https://en.wikipedia.org/wiki/Almost_everywhere> ## Tags measure, almost everywhere, measure space -/ noncomputable theory open classical set filter (hiding map) function measurable_space open_locale classical topology big_operators filter ennreal nnreal variables {α β γ δ ι : Type*} namespace measure_theory /-- A measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. -/ structure measure (α : Type*) [measurable_space α] extends outer_measure α := (m_Union ⦃f : ℕ → set α⦄ : (∀ i, measurable_set (f i)) → pairwise (disjoint on f) → measure_of (⋃ i, f i) = ∑' i, measure_of (f i)) (trimmed : to_outer_measure.trim = to_outer_measure) /-- Measure projections for a measure space. For measurable sets this returns the measure assigned by the `measure_of` field in `measure`. But we can extend this to _all_ sets, but using the outer measure. This gives us monotonicity and subadditivity for all sets. -/ instance measure.has_coe_to_fun [measurable_space α] : has_coe_to_fun (measure α) (λ _, set α → ℝ≥0∞) := ⟨λ m, m.to_outer_measure⟩ section variables [measurable_space α] {μ μ₁ μ₂ : measure α} {s s₁ s₂ t : set α} namespace measure /-! ### General facts about measures -/ /-- Obtain a measure by giving a countably additive function that sends `∅` to `0`. -/ def of_measurable (m : Π (s : set α), measurable_set s → ℝ≥0∞) (m0 : m ∅ measurable_set.empty = 0) (mU : ∀ {{f : ℕ → set α}} (h : ∀ i, measurable_set (f i)), pairwise (disjoint on f) → m (⋃ i, f i) (measurable_set.Union h) = ∑' i, m (f i) (h i)) : measure α := { m_Union := λ f hf hd, show induced_outer_measure m _ m0 (Union f) = ∑' i, induced_outer_measure m _ m0 (f i), begin rw [induced_outer_measure_eq m0 mU, mU hf hd], congr, funext n, rw induced_outer_measure_eq m0 mU end, trimmed := show (induced_outer_measure m _ m0).trim = induced_outer_measure m _ m0, begin unfold outer_measure.trim, congr, funext s hs, exact induced_outer_measure_eq m0 mU hs end, ..induced_outer_measure m _ m0 } lemma of_measurable_apply {m : Π (s : set α), measurable_set s → ℝ≥0∞} {m0 : m ∅ measurable_set.empty = 0} {mU : ∀ {{f : ℕ → set α}} (h : ∀ i, measurable_set (f i)), pairwise (disjoint on f) → m (⋃ i, f i) (measurable_set.Union h) = ∑' i, m (f i) (h i)} (s : set α) (hs : measurable_set s) : of_measurable m m0 mU s = m s hs := induced_outer_measure_eq m0 mU hs lemma to_outer_measure_injective : injective (to_outer_measure : measure α → outer_measure α) := λ ⟨m₁, u₁, h₁⟩ ⟨m₂, u₂, h₂⟩ h, by { congr, exact h } @[ext] lemma ext (h : ∀ s, measurable_set s → μ₁ s = μ₂ s) : μ₁ = μ₂ := to_outer_measure_injective $ by rw [← trimmed, outer_measure.trim_congr h, trimmed] lemma ext_iff : μ₁ = μ₂ ↔ ∀ s, measurable_set s → μ₁ s = μ₂ s := ⟨by { rintro rfl s hs, refl }, measure.ext⟩ end measure @[simp] lemma coe_to_outer_measure : ⇑μ.to_outer_measure = μ := rfl lemma to_outer_measure_apply (s : set α) : μ.to_outer_measure s = μ s := rfl lemma measure_eq_trim (s : set α) : μ s = μ.to_outer_measure.trim s := by rw μ.trimmed; refl lemma measure_eq_infi (s : set α) : μ s = ⨅ t (st : s ⊆ t) (ht : measurable_set t), μ t := by rw [measure_eq_trim, outer_measure.trim_eq_infi]; refl /-- A variant of `measure_eq_infi` which has a single `infi`. This is useful when applying a lemma next that only works for non-empty infima, in which case you can use `nonempty_measurable_superset`. -/ lemma measure_eq_infi' (μ : measure α) (s : set α) : μ s = ⨅ t : { t // s ⊆ t ∧ measurable_set t}, μ t := by simp_rw [infi_subtype, infi_and, subtype.coe_mk, ← measure_eq_infi] lemma measure_eq_induced_outer_measure : μ s = induced_outer_measure (λ s _, μ s) measurable_set.empty μ.empty s := measure_eq_trim _ lemma to_outer_measure_eq_induced_outer_measure : μ.to_outer_measure = induced_outer_measure (λ s _, μ s) measurable_set.empty μ.empty := μ.trimmed.symm lemma measure_eq_extend (hs : measurable_set s) : μ s = extend (λ t (ht : measurable_set t), μ t) s := (extend_eq _ hs).symm @[simp] lemma measure_empty : μ ∅ = 0 := μ.empty lemma nonempty_of_measure_ne_zero (h : μ s ≠ 0) : s.nonempty := nonempty_iff_ne_empty.2 $ λ h', h $ h'.symm ▸ measure_empty lemma measure_mono (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := μ.mono h lemma measure_mono_null (h : s₁ ⊆ s₂) (h₂ : μ s₂ = 0) : μ s₁ = 0 := nonpos_iff_eq_zero.1 $ h₂ ▸ measure_mono h lemma measure_mono_top (h : s₁ ⊆ s₂) (h₁ : μ s₁ = ∞) : μ s₂ = ∞ := top_unique $ h₁ ▸ measure_mono h /-- For every set there exists a measurable superset of the same measure. -/ lemma exists_measurable_superset (μ : measure α) (s : set α) : ∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = μ s := by simpa only [← measure_eq_trim] using μ.to_outer_measure.exists_measurable_superset_eq_trim s /-- For every set `s` and a countable collection of measures `μ i` there exists a measurable superset `t ⊇ s` such that each measure `μ i` takes the same value on `s` and `t`. -/ lemma exists_measurable_superset_forall_eq {ι} [countable ι] (μ : ι → measure α) (s : set α) : ∃ t, s ⊆ t ∧ measurable_set t ∧ ∀ i, μ i t = μ i s := by simpa only [← measure_eq_trim] using outer_measure.exists_measurable_superset_forall_eq_trim (λ i, (μ i).to_outer_measure) s lemma exists_measurable_superset₂ (μ ν : measure α) (s : set α) : ∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = μ s ∧ ν t = ν s := by simpa only [bool.forall_bool.trans and.comm] using exists_measurable_superset_forall_eq (λ b, cond b μ ν) s lemma exists_measurable_superset_of_null (h : μ s = 0) : ∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = 0 := h ▸ exists_measurable_superset μ s lemma exists_measurable_superset_iff_measure_eq_zero : (∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = 0) ↔ μ s = 0 := ⟨λ ⟨t, hst, _, ht⟩, measure_mono_null hst ht, exists_measurable_superset_of_null⟩ theorem measure_Union_le [countable β] (s : β → set α) : μ (⋃ i, s i) ≤ ∑' i, μ (s i) := μ.to_outer_measure.Union _ lemma measure_bUnion_le {s : set β} (hs : s.countable) (f : β → set α) : μ (⋃ b ∈ s, f b) ≤ ∑' p : s, μ (f p) := by { haveI := hs.to_subtype, rw bUnion_eq_Union, apply measure_Union_le } lemma measure_bUnion_finset_le (s : finset β) (f : β → set α) : μ (⋃ b ∈ s, f b) ≤ ∑ p in s, μ (f p) := begin rw [← finset.sum_attach, finset.attach_eq_univ, ← tsum_fintype], exact measure_bUnion_le s.countable_to_set f end lemma measure_Union_fintype_le [fintype β] (f : β → set α) : μ (⋃ b, f b) ≤ ∑ p, μ (f p) := by { convert measure_bUnion_finset_le finset.univ f, simp } lemma measure_bUnion_lt_top {s : set β} {f : β → set α} (hs : s.finite) (hfin : ∀ i ∈ s, μ (f i) ≠ ∞) : μ (⋃ i ∈ s, f i) < ∞ := begin convert (measure_bUnion_finset_le hs.to_finset f).trans_lt _, { ext, rw [finite.mem_to_finset] }, apply ennreal.sum_lt_top, simpa only [finite.mem_to_finset] end lemma measure_Union_null [countable β] {s : β → set α} : (∀ i, μ (s i) = 0) → μ (⋃ i, s i) = 0 := μ.to_outer_measure.Union_null @[simp] lemma measure_Union_null_iff [countable ι] {s : ι → set α} : μ (⋃ i, s i) = 0 ↔ ∀ i, μ (s i) = 0 := μ.to_outer_measure.Union_null_iff /-- A version of `measure_Union_null_iff` for unions indexed by Props TODO: in the long run it would be better to combine this with `measure_Union_null_iff` by generalising to `Sort`. -/ @[simp] lemma measure_Union_null_iff' {ι : Prop} {s : ι → set α} : μ (⋃ i, s i) = 0 ↔ ∀ i, μ (s i) = 0 := μ.to_outer_measure.Union_null_iff' lemma measure_bUnion_null_iff {s : set ι} (hs : s.countable) {t : ι → set α} : μ (⋃ i ∈ s, t i) = 0 ↔ ∀ i ∈ s, μ (t i) = 0 := μ.to_outer_measure.bUnion_null_iff hs lemma measure_sUnion_null_iff {S : set (set α)} (hS : S.countable) : μ (⋃₀ S) = 0 ↔ ∀ s ∈ S, μ s = 0 := μ.to_outer_measure.sUnion_null_iff hS theorem measure_union_le (s₁ s₂ : set α) : μ (s₁ ∪ s₂) ≤ μ s₁ + μ s₂ := μ.to_outer_measure.union _ _ lemma measure_union_null : μ s₁ = 0 → μ s₂ = 0 → μ (s₁ ∪ s₂) = 0 := μ.to_outer_measure.union_null @[simp] lemma measure_union_null_iff : μ (s₁ ∪ s₂) = 0 ↔ μ s₁ = 0 ∧ μ s₂ = 0:= ⟨λ h, ⟨measure_mono_null (subset_union_left _ _) h, measure_mono_null (subset_union_right _ _) h⟩, λ h, measure_union_null h.1 h.2⟩ lemma measure_union_lt_top (hs : μ s < ∞) (ht : μ t < ∞) : μ (s ∪ t) < ∞ := (measure_union_le s t).trans_lt (ennreal.add_lt_top.mpr ⟨hs, ht⟩) @[simp] lemma measure_union_lt_top_iff : μ (s ∪ t) < ∞ ↔ μ s < ∞ ∧ μ t < ∞ := begin refine ⟨λ h, ⟨_, _⟩, λ h, measure_union_lt_top h.1 h.2⟩, { exact (measure_mono (set.subset_union_left s t)).trans_lt h, }, { exact (measure_mono (set.subset_union_right s t)).trans_lt h, }, end lemma measure_union_ne_top (hs : μ s ≠ ∞) (ht : μ t ≠ ∞) : μ (s ∪ t) ≠ ∞ := (measure_union_lt_top hs.lt_top ht.lt_top).ne @[simp] lemma measure_union_eq_top_iff : μ (s ∪ t) = ∞ ↔ μ s = ∞ ∨ μ t = ∞ := not_iff_not.1 $ by simp only [← lt_top_iff_ne_top, ← ne.def, not_or_distrib, measure_union_lt_top_iff] lemma exists_measure_pos_of_not_measure_Union_null [countable β] {s : β → set α} (hs : μ (⋃ n, s n) ≠ 0) : ∃ n, 0 < μ (s n) := begin contrapose! hs, exact measure_Union_null (λ n, nonpos_iff_eq_zero.1 (hs n)) end lemma measure_inter_lt_top_of_left_ne_top (hs_finite : μ s ≠ ∞) : μ (s ∩ t) < ∞ := (measure_mono (set.inter_subset_left s t)).trans_lt hs_finite.lt_top lemma measure_inter_lt_top_of_right_ne_top (ht_finite : μ t ≠ ∞) : μ (s ∩ t) < ∞ := inter_comm t s ▸ measure_inter_lt_top_of_left_ne_top ht_finite lemma measure_inter_null_of_null_right (S : set α) {T : set α} (h : μ T = 0) : μ (S ∩ T) = 0 := measure_mono_null (inter_subset_right S T) h lemma measure_inter_null_of_null_left {S : set α} (T : set α) (h : μ S = 0) : μ (S ∩ T) = 0 := measure_mono_null (inter_subset_left S T) h /-! ### The almost everywhere filter -/ /-- The “almost everywhere” filter of co-null sets. -/ def measure.ae {α} {m : measurable_space α} (μ : measure α) : filter α := { sets := {s | μ sᶜ = 0}, univ_sets := by simp, inter_sets := λ s t hs ht, by simp only [compl_inter, mem_set_of_eq]; exact measure_union_null hs ht, sets_of_superset := λ s t hs hst, measure_mono_null (set.compl_subset_compl.2 hst) hs } notation `∀ᵐ` binders ` ∂` μ `, ` r:(scoped P, filter.eventually P (measure.ae μ)) := r notation `∃ᵐ` binders ` ∂` μ `, ` r:(scoped P, filter.frequently P (measure.ae μ)) := r notation f ` =ᵐ[`:50 μ:50 `] `:0 g:50 := f =ᶠ[measure.ae μ] g notation f ` ≤ᵐ[`:50 μ:50 `] `:0 g:50 := f ≤ᶠ[measure.ae μ] g lemma mem_ae_iff {s : set α} : s ∈ μ.ae ↔ μ sᶜ = 0 := iff.rfl lemma ae_iff {p : α → Prop} : (∀ᵐ a ∂ μ, p a) ↔ μ { a | ¬ p a } = 0 := iff.rfl lemma compl_mem_ae_iff {s : set α} : sᶜ ∈ μ.ae ↔ μ s = 0 := by simp only [mem_ae_iff, compl_compl] lemma frequently_ae_iff {p : α → Prop} : (∃ᵐ a ∂μ, p a) ↔ μ {a | p a} ≠ 0 := not_congr compl_mem_ae_iff lemma frequently_ae_mem_iff {s : set α} : (∃ᵐ a ∂μ, a ∈ s) ↔ μ s ≠ 0 := not_congr compl_mem_ae_iff lemma measure_zero_iff_ae_nmem {s : set α} : μ s = 0 ↔ ∀ᵐ a ∂ μ, a ∉ s := compl_mem_ae_iff.symm lemma ae_of_all {p : α → Prop} (μ : measure α) : (∀ a, p a) → ∀ᵐ a ∂ μ, p a := eventually_of_forall --instance ae_is_measurably_generated : is_measurably_generated μ.ae := --⟨λ s hs, let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs in -- ⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩ instance : countable_Inter_filter μ.ae := ⟨begin intros S hSc hS, rw [mem_ae_iff, compl_sInter, sUnion_image], exact (measure_bUnion_null_iff hSc).2 hS end⟩ lemma ae_all_iff {ι : Sort*} [countable ι] {p : α → ι → Prop} : (∀ᵐ a ∂ μ, ∀ i, p a i) ↔ ∀ i, ∀ᵐ a ∂ μ, p a i := eventually_countable_forall lemma ae_ball_iff {S : set ι} (hS : S.countable) {p : Π (x : α) (i ∈ S), Prop} : (∀ᵐ x ∂ μ, ∀ i ∈ S, p x i ‹_›) ↔ ∀ i ∈ S, ∀ᵐ x ∂ μ, p x i ‹_› := eventually_countable_ball hS lemma ae_eq_refl (f : α → δ) : f =ᵐ[μ] f := eventually_eq.rfl lemma ae_eq_symm {f g : α → δ} (h : f =ᵐ[μ] g) : g =ᵐ[μ] f := h.symm lemma ae_eq_trans {f g h: α → δ} (h₁ : f =ᵐ[μ] g) (h₂ : g =ᵐ[μ] h) : f =ᵐ[μ] h := h₁.trans h₂ lemma ae_le_of_ae_lt {f g : α → ℝ≥0∞} (h : ∀ᵐ x ∂μ, f x < g x) : f ≤ᵐ[μ] g := begin rw [filter.eventually_le, ae_iff], rw ae_iff at h, refine measure_mono_null (λ x hx, _) h, exact not_lt.2 (le_of_lt (not_le.1 hx)), end @[simp] lemma ae_eq_empty : s =ᵐ[μ] (∅ : set α) ↔ μ s = 0 := eventually_eq_empty.trans $ by simp only [ae_iff, not_not, set_of_mem_eq] @[simp] lemma ae_eq_univ : s =ᵐ[μ] (univ : set α) ↔ μ sᶜ = 0 := eventually_eq_univ lemma ae_le_set : s ≤ᵐ[μ] t ↔ μ (s \ t) = 0 := calc s ≤ᵐ[μ] t ↔ ∀ᵐ x ∂μ, x ∈ s → x ∈ t : iff.rfl ... ↔ μ (s \ t) = 0 : by simp [ae_iff]; refl lemma ae_le_set_inter {s' t' : set α} (h : s ≤ᵐ[μ] t) (h' : s' ≤ᵐ[μ] t') : (s ∩ s' : set α) ≤ᵐ[μ] (t ∩ t' : set α) := h.inter h' lemma ae_le_set_union {s' t' : set α} (h : s ≤ᵐ[μ] t) (h' : s' ≤ᵐ[μ] t') : (s ∪ s' : set α) ≤ᵐ[μ] (t ∪ t' : set α) := h.union h' lemma union_ae_eq_right : (s ∪ t : set α) =ᵐ[μ] t ↔ μ (s \ t) = 0 := by simp [eventually_le_antisymm_iff, ae_le_set, union_diff_right, diff_eq_empty.2 (set.subset_union_right _ _)] lemma diff_ae_eq_self : (s \ t : set α) =ᵐ[μ] s ↔ μ (s ∩ t) = 0 := by simp [eventually_le_antisymm_iff, ae_le_set, diff_diff_right, diff_diff, diff_eq_empty.2 (set.subset_union_right _ _)] lemma diff_null_ae_eq_self (ht : μ t = 0) : (s \ t : set α) =ᵐ[μ] s := diff_ae_eq_self.mpr (measure_mono_null (inter_subset_right _ _) ht) lemma ae_eq_set {s t : set α} : s =ᵐ[μ] t ↔ μ (s \ t) = 0 ∧ μ (t \ s) = 0 := by simp [eventually_le_antisymm_iff, ae_le_set] @[simp] lemma measure_symm_diff_eq_zero_iff {s t : set α} : μ (s ∆ t) = 0 ↔ s =ᵐ[μ] t := by simp [ae_eq_set, symm_diff_def] @[simp] lemma ae_eq_set_compl_compl {s t : set α} : sᶜ =ᵐ[μ] tᶜ ↔ s =ᵐ[μ] t := by simp only [← measure_symm_diff_eq_zero_iff, compl_symm_diff_compl] lemma ae_eq_set_compl {s t : set α} : sᶜ =ᵐ[μ] t ↔ s =ᵐ[μ] tᶜ := by rw [← ae_eq_set_compl_compl, compl_compl] lemma ae_eq_set_inter {s' t' : set α} (h : s =ᵐ[μ] t) (h' : s' =ᵐ[μ] t') : (s ∩ s' : set α) =ᵐ[μ] (t ∩ t' : set α) := h.inter h' lemma ae_eq_set_union {s' t' : set α} (h : s =ᵐ[μ] t) (h' : s' =ᵐ[μ] t') : (s ∪ s' : set α) =ᵐ[μ] (t ∪ t' : set α) := h.union h' lemma union_ae_eq_univ_of_ae_eq_univ_left (h : s =ᵐ[μ] univ) : (s ∪ t : set α) =ᵐ[μ] univ := by { convert ae_eq_set_union h (ae_eq_refl t), rw univ_union, } lemma union_ae_eq_univ_of_ae_eq_univ_right (h : t =ᵐ[μ] univ) : (s ∪ t : set α) =ᵐ[μ] univ := by { convert ae_eq_set_union (ae_eq_refl s) h, rw union_univ, } lemma union_ae_eq_right_of_ae_eq_empty (h : s =ᵐ[μ] (∅ : set α)) : (s ∪ t : set α) =ᵐ[μ] t := by { convert ae_eq_set_union h (ae_eq_refl t), rw empty_union, } lemma union_ae_eq_left_of_ae_eq_empty (h : t =ᵐ[μ] (∅ : set α)) : (s ∪ t : set α) =ᵐ[μ] s := by { convert ae_eq_set_union (ae_eq_refl s) h, rw union_empty, } lemma inter_ae_eq_right_of_ae_eq_univ (h : s =ᵐ[μ] univ) : (s ∩ t : set α) =ᵐ[μ] t := by { convert ae_eq_set_inter h (ae_eq_refl t), rw univ_inter, } lemma inter_ae_eq_left_of_ae_eq_univ (h : t =ᵐ[μ] univ) : (s ∩ t : set α) =ᵐ[μ] s := by { convert ae_eq_set_inter (ae_eq_refl s) h, rw inter_univ, } lemma inter_ae_eq_empty_of_ae_eq_empty_left (h : s =ᵐ[μ] (∅ : set α)) : (s ∩ t : set α) =ᵐ[μ] (∅ : set α) := by { convert ae_eq_set_inter h (ae_eq_refl t), rw empty_inter, } lemma inter_ae_eq_empty_of_ae_eq_empty_right (h : t =ᵐ[μ] (∅ : set α)) : (s ∩ t : set α) =ᵐ[μ] (∅ : set α) := by { convert ae_eq_set_inter (ae_eq_refl s) h, rw inter_empty, } @[to_additive] lemma _root_.set.mul_indicator_ae_eq_one {M : Type*} [has_one M] {f : α → M} {s : set α} (h : s.mul_indicator f =ᵐ[μ] 1) : μ (s ∩ function.mul_support f) = 0 := by simpa [filter.eventually_eq, ae_iff] using h /-- If `s ⊆ t` modulo a set of measure `0`, then `μ s ≤ μ t`. -/ @[mono] lemma measure_mono_ae (H : s ≤ᵐ[μ] t) : μ s ≤ μ t := calc μ s ≤ μ (s ∪ t) : measure_mono $ subset_union_left s t ... = μ (t ∪ s \ t) : by rw [union_diff_self, set.union_comm] ... ≤ μ t + μ (s \ t) : measure_union_le _ _ ... = μ t : by rw [ae_le_set.1 H, add_zero] alias measure_mono_ae ← _root_.filter.eventually_le.measure_le /-- If two sets are equal modulo a set of measure zero, then `μ s = μ t`. -/ lemma measure_congr (H : s =ᵐ[μ] t) : μ s = μ t := le_antisymm H.le.measure_le H.symm.le.measure_le alias measure_congr ← _root_.filter.eventually_eq.measure_eq lemma measure_mono_null_ae (H : s ≤ᵐ[μ] t) (ht : μ t = 0) : μ s = 0 := nonpos_iff_eq_zero.1 $ ht ▸ H.measure_le /-- A measurable set `t ⊇ s` such that `μ t = μ s`. It even satisfies `μ (t ∩ u) = μ (s ∩ u)` for any measurable set `u` if `μ s ≠ ∞`, see `measure_to_measurable_inter`. (This property holds without the assumption `μ s ≠ ∞` when the space is sigma-finite, see `measure_to_measurable_inter_of_sigma_finite`). If `s` is a null measurable set, then we also have `t =ᵐ[μ] s`, see `null_measurable_set.to_measurable_ae_eq`. This notion is sometimes called a "measurable hull" in the literature. -/ @[irreducible] def to_measurable (μ : measure α) (s : set α) : set α := if h : ∃ t ⊇ s, measurable_set t ∧ t =ᵐ[μ] s then h.some else if h' : ∃ t ⊇ s, measurable_set t ∧ (∀ u, measurable_set u → μ (t ∩ u) = μ (s ∩ u)) then h'.some else (exists_measurable_superset μ s).some lemma subset_to_measurable (μ : measure α) (s : set α) : s ⊆ to_measurable μ s := begin rw to_measurable, split_ifs with hs h's, exacts [hs.some_spec.fst, h's.some_spec.fst, (exists_measurable_superset μ s).some_spec.1] end lemma ae_le_to_measurable : s ≤ᵐ[μ] to_measurable μ s := (subset_to_measurable _ _).eventually_le @[simp] lemma measurable_set_to_measurable (μ : measure α) (s : set α) : measurable_set (to_measurable μ s) := begin rw to_measurable, split_ifs with hs h's, exacts [hs.some_spec.snd.1, h's.some_spec.snd.1, (exists_measurable_superset μ s).some_spec.2.1] end @[simp] lemma measure_to_measurable (s : set α) : μ (to_measurable μ s) = μ s := begin rw to_measurable, split_ifs with hs h's, { exact measure_congr hs.some_spec.snd.2 }, { simpa only [inter_univ] using h's.some_spec.snd.2 univ measurable_set.univ }, { exact (exists_measurable_superset μ s).some_spec.2.2 } end /-- A measure space is a measurable space equipped with a measure, referred to as `volume`. -/ class measure_space (α : Type*) extends measurable_space α := (volume : measure α) export measure_space (volume) /-- `volume` is the canonical measure on `α`. -/ add_decl_doc volume section measure_space notation `∀ᵐ` binders `, ` r:(scoped P, filter.eventually P (measure_theory.measure.ae measure_theory.measure_space.volume)) := r notation `∃ᵐ` binders `, ` r:(scoped P, filter.frequently P (measure_theory.measure.ae measure_theory.measure_space.volume)) := r /-- The tactic `exact volume`, to be used in optional (`auto_param`) arguments. -/ meta def volume_tac : tactic unit := `[exact measure_theory.measure_space.volume] end measure_space end end measure_theory section open measure_theory /-! # Almost everywhere measurable functions A function is almost everywhere measurable if it coincides almost everywhere with a measurable function. We define this property, called `ae_measurable f μ`. It's properties are discussed in `measure_theory.measure_space`. -/ variables {m : measurable_space α} [measurable_space β] {f g : α → β} {μ ν : measure α} /-- A function is almost everywhere measurable if it coincides almost everywhere with a measurable function. -/ def ae_measurable {m : measurable_space α} (f : α → β) (μ : measure α . measure_theory.volume_tac) : Prop := ∃ g : α → β, measurable g ∧ f =ᵐ[μ] g lemma measurable.ae_measurable (h : measurable f) : ae_measurable f μ := ⟨f, h, ae_eq_refl f⟩ namespace ae_measurable /-- Given an almost everywhere measurable function `f`, associate to it a measurable function that coincides with it almost everywhere. `f` is explicit in the definition to make sure that it shows in pretty-printing. -/ def mk (f : α → β) (h : ae_measurable f μ) : α → β := classical.some h lemma measurable_mk (h : ae_measurable f μ) : measurable (h.mk f) := (classical.some_spec h).1 lemma ae_eq_mk (h : ae_measurable f μ) : f =ᵐ[μ] (h.mk f) := (classical.some_spec h).2 lemma congr (hf : ae_measurable f μ) (h : f =ᵐ[μ] g) : ae_measurable g μ := ⟨hf.mk f, hf.measurable_mk, h.symm.trans hf.ae_eq_mk⟩ end ae_measurable lemma ae_measurable_congr (h : f =ᵐ[μ] g) : ae_measurable f μ ↔ ae_measurable g μ := ⟨λ hf, ae_measurable.congr hf h, λ hg, ae_measurable.congr hg h.symm⟩ @[simp] lemma ae_measurable_const {b : β} : ae_measurable (λ a : α, b) μ := measurable_const.ae_measurable lemma ae_measurable_id : ae_measurable id μ := measurable_id.ae_measurable lemma ae_measurable_id' : ae_measurable (λ x, x) μ := measurable_id.ae_measurable lemma measurable.comp_ae_measurable [measurable_space δ] {f : α → δ} {g : δ → β} (hg : measurable g) (hf : ae_measurable f μ) : ae_measurable (g ∘ f) μ := ⟨g ∘ hf.mk f, hg.comp hf.measurable_mk, eventually_eq.fun_comp hf.ae_eq_mk _⟩ end
edff326886b390be6a482dcff03ab734b5ea8636
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/data/set/intervals/infinite.lean
4ec7fdc2a6ac582abc26dd394813c988e6544baa
[ "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,935
lean
/- Copyright (c) 2020 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton -/ import data.set.finite /-! # Infinitude of intervals Bounded intervals in dense orders are infinite, as are unbounded intervals in orders that are unbounded on the appropriate side. -/ namespace set variables {α : Type*} [preorder α] section bounded variables [densely_ordered α] lemma Ioo.infinite {a b : α} (h : a < b) : infinite (Ioo a b) := begin rintro (f : finite (Ioo a b)), obtain ⟨m, hm₁, hm₂⟩ : ∃ m ∈ Ioo a b, ∀ x ∈ Ioo a b, ¬x < m, { simpa [h] using finset.exists_minimal f.to_finset }, obtain ⟨z, hz₁, hz₂⟩ : ∃ z, a < z ∧ z < m := exists_between hm₁.1, exact hm₂ z ⟨hz₁, lt_trans hz₂ hm₁.2⟩ hz₂, end lemma Ico.infinite {a b : α} (h : a < b) : infinite (Ico a b) := infinite_mono Ioo_subset_Ico_self (Ioo.infinite h) lemma Ioc.infinite {a b : α} (h : a < b) : infinite (Ioc a b) := infinite_mono Ioo_subset_Ioc_self (Ioo.infinite h) lemma Icc.infinite {a b : α} (h : a < b) : infinite (Icc a b) := infinite_mono Ioo_subset_Icc_self (Ioo.infinite h) end bounded section unbounded_below variables [no_bot_order α] lemma Iio.infinite {b : α} : infinite (Iio b) := begin rintro (f : finite (Iio b)), obtain ⟨m, hm₁, hm₂⟩ : ∃ m < b, ∀ x < b, ¬x < m, { simpa using finset.exists_minimal f.to_finset }, obtain ⟨z, hz⟩ : ∃ z, z < m := no_bot _, exact hm₂ z (lt_trans hz hm₁) hz end lemma Iic.infinite {b : α} : infinite (Iic b) := infinite_mono Iio_subset_Iic_self Iio.infinite end unbounded_below section unbounded_above variables [no_top_order α] lemma Ioi.infinite {a : α} : infinite (Ioi a) := by apply @Iio.infinite (order_dual α) lemma Ici.infinite {a : α} : infinite (Ici a) := infinite_mono Ioi_subset_Ici_self Ioi.infinite end unbounded_above end set
1b9e5246721f72e0182f1156324ab4cdfb245480
82e44445c70db0f03e30d7be725775f122d72f3e
/src/combinatorics/choose/bounds.lean
4e03c50b670698a27b1670268871a7ab850c2ab2
[ "Apache-2.0" ]
permissive
stjordanis/mathlib
51e286d19140e3788ef2c470bc7b953e4991f0c9
2568d41bca08f5d6bf39d915434c8447e21f42ee
refs/heads/master
1,631,748,053,501
1,627,938,886,000
1,627,938,886,000
228,728,358
0
0
Apache-2.0
1,576,630,588,000
1,576,630,587,000
null
UTF-8
Lean
false
false
1,232
lean
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Eric Rodriguez -/ import data.nat.choose.basic import data.nat.cast import algebra.group_power.lemmas /-! # Inequalities for binomial coefficients This file proves exponential bounds on binomial coefficients. We might want to add here the bounds `n^r/r^r ≤ n.choose r ≤ e^r n^r/r^r` in the future. ## Main declarations * `choose_le_pow`: `n.choose r ≤ n^r / r!` * `pow_le_choose`: `(n + 1 - r)^r / r! ≤ n.choose r`. Beware of the fishy ℕ-subtraction. -/ open_locale nat variables {α : Type*} [linear_ordered_field α] lemma choose_le_pow (r n : ℕ) : (n.choose r : α) ≤ n^r / r! := begin rw le_div_iff', { norm_cast, rw ←nat.desc_factorial_eq_factorial_mul_choose, exact n.desc_factorial_le_pow r }, exact_mod_cast r.factorial_pos, end -- horrific casting is due to ℕ-subtraction lemma pow_le_choose (r n : ℕ) : ((n + 1 - r : ℕ)^r : α) / r! ≤ n.choose r := begin rw div_le_iff', { norm_cast, rw [←nat.desc_factorial_eq_factorial_mul_choose], exact n.pow_sub_le_desc_factorial r }, exact_mod_cast r.factorial_pos, end
1968266473e9541ae99359444a395d0c2b7a677c
57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d
/tests/lean/run/struct3.lean
3879aa5cc3e27095683a0908f3e4bc1e1e3a973b
[ "Apache-2.0" ]
permissive
collares/lean4
861a9269c4592bce49b71059e232ff0bfe4594cc
52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee
refs/heads/master
1,691,419,031,324
1,618,678,138,000
1,618,678,138,000
358,989,750
0
0
Apache-2.0
1,618,696,333,000
1,618,696,333,000
null
UTF-8
Lean
false
false
1,136
lean
universes u v class Bind2 (m : Type u → Type v) where bind : ∀ {α β : Type u}, m α → (α → m β) → m β class Monad2 (m : Type u → Type v) extends Applicative m, Bind2 m : Type (max (u+1) v) where map := fun f x => Bind2.bind x (pure ∘ f) seq := fun f x => Bind2.bind f fun y => Functor.map y x seqLeft := fun x y => Bind2.bind x fun a => Bind2.bind y fun _ => pure a seqRight := @fun α β x y => Bind2.bind x fun _ => y -- Recall that `@` disables implicit lambda support class Monad3 (m : Type u → Type v) extends Applicative m, Bind2 m : Type (max (u+1) v) where map (f x) := Bind2.bind x (pure ∘ f) seq (f x) := Bind2.bind f fun y => Functor.map y x seqLeft (x y) := Bind2.bind x fun a => Bind2.bind y fun _ => pure a seqRight (x y) := Bind2.bind x fun _ => y class Monad4 (m : Type u → Type v) extends Applicative m, Bind2 m : Type (max (u+1) v) where map f x := Bind2.bind x (pure ∘ f) seq f x := Bind2.bind f fun y => Functor.map y x seqLeft x y := Bind2.bind x fun a => Bind2.bind y fun _ => pure a seqRight x y := Bind2.bind x fun _ => y
89f0bd7656a3a56eb322daf66389911cf3972fdc
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/instance_cache1.lean
7b8a046aad1d3829abfe75cf787d347d23463f07
[ "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
339
lean
definition f1 (A : Type*) (a : A) := have has_add A, from has_add.mk (λ (a b : A), a), a + a definition f2 (A : Type*) (a : A) : has_add A → A := λ s, a + a definition f3 (A : Type*) (a : A) := λ s : has_add A, a + a definition f4 (A : Type*) [has_add A] (a : A) := a + a definition g (A : Type*) (s : has_add A) (a : A) := a + a
67b1f188e065666964f7477b78e5c9cb57e68d1b
685ab3d59bec28c631aabbe80a39f70fb639d38b
/group_isomorphicity.lean
798cabab349e86a1b0a9d5a95be56c3413882d42
[]
no_license
0function/storage
7ffad46d00dda4c190f1a48ae6b1c23012ef8603
1a28fa3019003170c509b0c2badb85bd25319cd5
refs/heads/master
1,594,195,514,972
1,572,596,352,000
1,572,596,352,000
203,612,497
0
0
null
null
null
null
UTF-8
Lean
false
false
22,398
lean
import group_theory.coset ring_theory.matrix ring_theory.determinant ring_theory.ideals algebra.gcd_domain algebra.euclidean_domain data.int.modeq group_theory.quotient_group data.equiv.algebra group_theory.subgroup import tactic.ring tactic.fin_cases tactic.tidy open function quotient_group group is_group_hom set classical noncomputable theory structure group_equiv (G H : Type*) [group G] [group H] extends G ≃ H := (hom: is_group_hom to_fun) (inv_hom: is_group_hom inv_fun) infix ` ≅ `:50 := group_equiv namespace group_equiv --I'd like not to repeat the Type*, but then there's an error with shadowing local universes. variables{G:Type*}{H:Type*}{K:Type*}[group G][group H][group K] {X:Type*}{Y:Type*}{Z:Type*} instance: has_coe(G≅H)(G≃H) := ⟨λx,{..x}⟩ def via_biject_hom(f: G→H)(b: bijective f)(h: is_group_hom f): G ≅ H := { hom:=h, inv_hom:=⟨begin let E:= equiv.of_bijective b, let f:= E.to_fun, let g:= E.inv_fun, intros x y, change g(x*y) = g x * g y, have gf: ∀ a, g(f a) = a := E.left_inv, have fg: ∀ a, f(g a) = a := E.right_inv, rw[←gf(g x * g y)], apply congr_arg, have: f(g x * g y) = f(g x) * f(g y) := by apply h.mul, rw[this,fg,fg], end⟩, ..equiv.of_bijective b } lemma bijective_comp{f:Y→Z}{g:X→Y}(bijf: bijective f)(bijg: bijective g): bijective(f∘g) :=begin constructor, {tidy}, intro a, rcases bijf.right a with ⟨b, fb_a⟩, rcases bijg.right b with ⟨c, gc_b⟩, exact ⟨c,by simp;cc⟩, end protected def bijective(f: G ≅ H): bijective f := equiv.bijective f instance(f: G≅H): is_group_hom f := f.hom protected def refl: G ≅ G := via_biject_hom id (by simp[bijective,injective,surjective]) ⟨by simp⟩ protected def symm(f: G ≅ H): H ≅ G := { to_fun:= f.inv_fun, inv_fun:= f.to_fun, left_inv:= f.right_inv, right_inv:= f.left_inv, hom:= f.inv_hom, inv_hom:= f.hom, } protected def trans(gh: G ≅ H)(hk: H ≅ K): G ≅ K := via_biject_hom(hk ∘ gh) (bijective_comp hk.bijective gh.bijective) (by apply_instance) --infer_instance doesn't check @[extensionality] lemma range_ext(f: X→Y)(x y ix iy)(x'y: x=y): (⟨x,ix⟩: range f) = ⟨y,iy⟩ := by simp[x'y] --The first isomorphism theorem for groups. This one relates quotient to range, whereas the version below it avoids range assuming surjectivity. def quotient_ker_isom_range(f: G→H)[is_group_hom f]: quotient(ker f) ≅ range f := @via_biject_hom _ (range f) _ _ (λ x, ⟨lift (ker f) f (by simp [mem_ker]) x, by exact quotient.induction_on' x (λ x, ⟨x, rfl⟩)⟩) ⟨λ a b h, injective_ker_lift _ (subtype.mk.inj h), λ ⟨x, y, hy⟩, ⟨quotient_group.mk y, subtype.eq hy⟩⟩ ⟨λx y, begin induction x, induction y, change (⟨quotient_group.lift (ker f) f _ (quotient_group.mk x * quotient_group.mk y), _⟩ : range f) = ⟨f x * f y, _⟩, ext, rw ←is_group_hom.mul f, repeat{refl}, end⟩ def quotient_ker_isom_of_surjective(f: G→H)[is_group_hom f](s: surjective f): quotient(ker f) ≅ H := (quotient_ker_isom_range f).trans(via_biject_hom subtype.val(begin constructor, {tidy}, intro x, rcases s x with ⟨y, fy_x⟩, exact⟨⟨f y, by tidy⟩, by simpa⟩, end) (by tidy)) def isomorphism_theorem_1 := @quotient_ker_isom_range --–1. attempt: use subsets (⟹ dead end) def as_subset{A B: set X}(AsubB: A ⊆ B): set B := λb, A b --Maximum class instance resolution depth gets continuously exceeded with this coercion... instance coe_subset{B: set X}: has_coe(set X)(set B) := ⟨λA b, A b⟩ --...hence I package set under another name. This is for prototyping. Lifting all the definitions from set is inpractical, and a fixed type class inference should handle this IMO. structure sub(T: Type*) := (base: set T) namespace sub instance: has_coe_to_sort(sub X) := {S:=Sort*, coe:=λs, (set.has_coe_to_sort.coe: set X → Sort _) s.base} instance{B: sub X}: has_coe(sub X)(sub B) := ⟨λA, ⟨λb, A.base b⟩⟩ end sub variables{M N S : sub G}[is_subgroup M.base][is_subgroup S.base][normal_subgroup N.base] instance: is_subgroup((S: sub M).base) := { one_mem:= _inst_5.one_mem, mul_mem:=begin intros, have:= _inst_5.mul_mem, apply this a_1 a_2, end, inv_mem:=begin intros, have:= _inst_5.inv_mem, apply this a_1, end, } instance: normal_subgroup((N: sub M).base) := ⟨begin intros, change N.base(g*n*g⁻¹), have:= _inst_6.normal, apply this n _ g, apply H, end⟩ --Result of these definitions: quotient between subgroups becomes defined. @[reducible]def explicit_quotient(G:Type*)(N: sub G)[group G][normal_subgroup N.base] := quotient N.base infix `∕`:70 := explicit_quotient #check M∕N --But quotients are not subtypes of each others of course. --example[nM: normal_subgroup M.base](N_M: N.base ⊆ M.base): M∕N ⊆ G∕N --–2. attempt: use embeddings with inference (⟹ too hard to infer) --Embedding for sets class embed(X Y : Type*) := (fn: X → Y)(inj: injective fn) --To avoid non-termination, transitive closure must be build into another class, as in coe.lean. In general the rule is to take parameters of type embedₜ and produce instances of type embed. class embedₜ(X Y : Type*) := (fn: X → Y)(inj: injective fn) namespace embed instance: has_coe_to_fun(embedₜ X Y) := { F:=λ_, X→Y, coe:= λi, i.fn } instance set{A: set X}: embed A X := {fn:=subtype.val, inj:= by tidy} instance[i: embed X Y][j: embedₜ Y Z]: embedₜ X Z := {fn:= j.fn ∘ i.fn, inj:=begin have:= i.inj, have:= j.inj, tidy, end} --Note: It is very helpful to place the base case after the branch case for the inference engine! instance base[i: embed X Y]: embedₜ X Y := {..i} end embed --Embedding for groups class embed_group(G H : Type*)[group G][group H] extends embed G H := (hom: is_group_hom fn) class embed_groupₜ(G H : Type*)[group G][group H] extends embedₜ G H := (hom: is_group_hom fn) namespace embed_group variables[i₁: embed_group G H][i: embed_groupₜ G H][j: embed_groupₜ H K] instance set: embed_group S G := {hom:= by tidy, ..embed.set} --Compare coe:X→Y and instance[X]:Y. Both are implicit conversions, but the first is for explicit terms whereas the second for implicit. Actually extends-declaration produces the second type of conversion: example[embed_group G H]: embedₜ G H := infer_instance --Explicit embeddings are supposed to be from the transitive closure, so coercion for them sufficies. Moreover lack of conversion for single step class can signal an error if ₜ is forgotten from a parameter (with unhelpful message). instance: has_coe(embed_groupₜ G H)(embedₜ G H) := ⟨λi,{..i}⟩ instance: is_group_hom i := i.hom --Problem: A definition may require a context with G⥅H and H⥅K, and then use the composed version. Assuming only G↪H in 1 step is generally too restrictive. I see no other way than to use explicit composition in this case. def trans_comp(i: embed_groupₜ G H)(j: embed_groupₜ H K): embed_groupₜ G K :={ fn:= j.fn ∘ i.fn, inj:=begin have:= i.inj, have:= j.inj, tidy, end, hom:= @is_group_hom.comp _ _ _ _ _ i.hom _ _ _ j.hom, } instance: embed_groupₜ G K := let _:=i₁ in trans_comp{..i₁}j instance base: embed_groupₜ G H := {..i₁} @[reducible]def quot_by_embed(H G : Type*)[group G][group H][i: embed_groupₜ G H] := quotient_group.quotient(range i) infix `./ `:70 := quot_by_embed def atomic_trans{R: embed_group G H → Sort*}(F: ∀[i₁: embed_group G H], R i₁)[i: embed_groupₜ G H] := @F{..i} --Because the common assumption pair G ↪ₜ H ↪ₜ K doesn't chain automatically, the notation K./G can't be used. private def K'G(i: embed_groupₜ G H)(j: embed_groupₜ H K) := @quot_by_embed K G _ _ (trans_comp i j) def embed_and_quot_mk: H → K'G i j := @quotient_group.mk K _ (range(j∘i)) (by apply_instance) ∘ j --If G is not normal, H/G is just a set and the lift for homomorphisms can't be used. def nnlift(f: H → X)(h: ∀ a b, a⁻¹ * b ∈ range i → f a = f b): H./G → X := @quotient.lift _ _ (left_rel(range i)) f h lemma embed_and_quot_mk_liftable: ∀ a b, a⁻¹ * b ∈ range i → embed_and_quot_mk a = (embed_and_quot_mk b : K'G i j) := let j:=j in begin intros, simp[embed_and_quot_mk], apply quotient_group.eq.mpr, change (j a)⁻¹ * j b ∈ range _, rw[←is_group_hom.inv j, ←is_group_hom.mul j], simp[has_mem.mem, set.mem, range], rcases a_1 with ⟨x, ix_a'b⟩, exact⟨x, by tidy⟩, end instance quot: embed(H./G)(K'G i j) := { fn:= nnlift embed_and_quot_mk embed_and_quot_mk_liftable, inj:= begin unfold injective, intros, induction a₁, induction a₂, apply quot.sound, change a₁⁻¹ * a₂ ∈ _, have: embed_and_quot_mk a₁ = embed_and_quot_mk a₂ := a, simp[embed_and_quot_mk] at this, have j_goal: (j a₁)⁻¹ * j a₂ ∈ range(j∘i) := (@quotient_group.eq K _ (range(j∘i)) _ (j a₁) (j a₂)).mp this, rw[←is_group_hom.inv j a₁, ←is_group_hom.mul j] at j_goal, rcases j_goal with ⟨x, e⟩, exact⟨x, begin apply j.inj, exact e end⟩, refl,refl,end, } --Next the normality is addied to the embeddings. Note that embed_normal is not an extension of embed_group but instead a property for it. This way it should be applicable to compositions of embeddings more flexibly. class embed_normal(G H : Type*)[group G][group H][i: embed_groupₜ G H] := {normal: normal_subgroup(range i)} --More explicit version. @[reducible]def is_normal(i: embed_groupₜ G H) := @embed_normal G H _ _ i variables[nj: embed_normal H K][nji: is_normal(trans_comp i j)] instance[nj: is_normal j]: normal_subgroup(range j) := nj.normal instance[nj: is_normal j]: group(K./H) := by apply_instance instance comp_right_normal: is_normal i := {normal:=let _:=nji in ⟨begin intros, tactic.unfreeze_local_instances, rcases nji, have:= @normal_subgroup.normal K _ (range(j∘i)) nji (j n) _ (j g), rw[←is_group_hom.inv j, ←is_group_hom.mul j, ←is_group_hom.mul j] at this, rcases this with ⟨x, e⟩, simp at e, exact⟨x, begin apply j.inj, exact e end⟩, rcases H_1 with ⟨x,e⟩, exact⟨x, congr_arg j e⟩, end⟩} instance right_normal: normal_subgroup(range i) := (@embed_group.comp_right_normal G H K _ _ _ i j nji).normal /-instance[i₁: embed_group G H][nji: is_normal(trans_comp (by apply_instance : embed_groupₜ G H) j)]: group(K./G) := begin have i: embed_groupₜ G H, apply_instance, have: normal_subgroup(range((trans_comp (by apply_instance : embed_groupₜ G H) j : embed_groupₜ G K) : G→K)), apply_instance, have:= @embed_group.normal_subgroup _ _ _ _ _ nji, rwa(_: j∘i = ((group_equiv.embed_groupₜ : embed_groupₜ _ _).fn : G→K)), have: embedₜ.fn K = j.fn ∘ i.fn, simp[embedₜ.fn], end--/ instance right_group: group(@quot_by_embed H G _ _ i) := let _:=K,_:=j,_:=nji in begin have:= @embed_group.right_normal G H K _ _ _ i j nji, apply_instance, end instance group_K'G: group(K'G i j) :=let _:=nji in begin tactic.unfreeze_local_instances, rcases nji, exact @quotient_group.group K _inst_3 (range(j∘i)) nji, end instance hom_quot[nji: @embed_normal G K _ _ (trans_comp i j)]: embed_groupₜ(H./G)(K'G i j) := { hom:=⟨λa b, begin induction a, induction b, let f: H → H./G := quotient_group.mk, have: is_group_hom f, apply_instance, change embed.fn (K'G _ _) (f a * f b) = embed_group.embed_and_quot_mk a * embed_group.embed_and_quot_mk b, rw ←is_group_hom.mul f, change embed_group.embed_and_quot_mk _ = _, let f': K → _ := @quotient_group.mk K _ (range(j∘i)) (by apply_instance), tactic.unfreeze_local_instances, rcases nji, have nor: normal_subgroup(range(j∘i)) := nji, have gr: group(quotient(range(j∘i))) := (@quotient_group.group K _inst_3 (@range K G (⇑j ∘ ⇑i)) nor), have _hom_f' := @quotient_group.is_group_hom K _ _ nor, have: f' = @quotient_group.mk K _ (range(j∘i)) (by apply_instance) := rfl, rw←this at _hom_f', change f'(j(a*b)) = _,--f'(j a) * f'(j b), rw[is_group_hom.mul j], tidy, end⟩, ..embed_group.quot } private def normal_mk(N: set G)(h: is_subgroup N)(prf): normal_subgroup N := {normal:= prf} instance normal_quot[nj: embed_normal H K][nji: @embed_normal G K _ _ (trans_comp i j)]: embed_normal(H./G)(K'G i j):= { normal:=normal_mk (range((embed_group.hom_quot: embed_groupₜ (@quot_by_embed H G _ _ i) _): (@quot_by_embed H G _ _ i)→(K'G i j))) (begin have: is_group_hom((embed_group.hom_quot: embed_groupₜ (@quot_by_embed H G _ _ i) _): (@quot_by_embed H G _ _ i)→(K'G i j)), apply_instance, apply @is_group_hom.range_subgroup _ _ _ _ _ this, end) (begin intros, induction n, induction g, let f': K → K'G i j := @quotient_group.mk K _ (range(j∘i)) (by apply_instance), change f' g * f' n * (f' g)⁻¹ ∈ _, tactic.unfreeze_local_instances, rcases nji, have nor: normal_subgroup(range(j∘i)) := nji, let gr: group(quotient(range(j∘i))) := (@quotient_group.group K _inst_3 (@range K G (⇑j ∘ ⇑i)) nor), have _hom_f' := @quotient_group.is_group_hom K _ _ nor, have: f' = @quotient_group.mk K _ (range(j∘i)) (by apply_instance) := rfl, rw←this at _hom_f', have: gr = quotient_group.group(range(j∘i)) := rfl, simp[this] at *, rcases H_1 with ⟨⟨m⟩,e⟩, have e': f' n = f'(j m) := e.symm, rw e', rw[←@is_group_hom.mul _ _ _ _ f' _hom_f', ←@is_group_hom.inv _ _ _ _ f' _hom_f', ←@is_group_hom.mul _ _ _ _ f' _hom_f'], rcases nj.normal, rcases normal (j m) _ g with ⟨n',el⟩, exact⟨n', by tidy⟩, tidy, end) } end embed_group open embed_group /-The outcome of the attempt 2: class inference fails and the cause is very difficult to locate. set_option trace.class_instances true theorem isomorphism_theorem_3 [j: embed_groupₜ H K] [embed_normal H K] [i: embed_group G H] [embed_normal G K]: --[@embed_normal G K _ _ (trans_comp i j)]: (K./G) ≅ K./H ∨ true --(@quot_by_embed K G _ _ (trans_comp i j))./(H./G) ≅ K./H := sorry --/ end group_equiv namespace group_equiv --–3. attempt: embeddings with packing preferred over classes structure Group := (base: Type*) (struct: group base) variables{G: Group}{H: Group}{K: Group} def 𝔾(G: Type*)[g: group G]: Group := ⟨G,g⟩ instance Group_to_Type: has_coe_to_sort Group := {S:=Type*, coe:= λG, G.base} instance: group G := G.struct structure group_homs(G H : Group) := (fn: G→H) (hom: is_group_hom fn) infixr ` ⇒ ` := group_homs instance homs_to_fun: has_coe_to_fun(group_homs G H) :={ F:= λ_, G→ H, coe:= group_homs.fn } instance packed_is_group_hom{f: G⇒H}: is_group_hom f := f.hom def compose(f: H⇒K)(g: G⇒H): G⇒K := ⟨f ∘ g, @is_group_hom.comp _ _ _ _ g g.hom _ _ f f.hom⟩ @[simp]lemma compose_fn(f: H⇒K)(g: G⇒H): (compose f g).fn = f.fn ∘ g.fn := rfl --Is type class conditional coercion possible? --instance sub_to_Group{S: set G}[is_subgroup S]: has_coe(set G)(Group) := ⟨λS, ⟨S, ??⟩⟩ def subGroup(S: set G)[is_subgroup S]: Group := ⟨S, infer_instance⟩ class embₜ(G H : Group) extends group_homs G H := (inj: injective fn) class emb(G H : Group) extends group_homs G H := (inj: injective fn)--embₜ G H := unit --Prefer explicit instances so that base conversion can be ordered to be tried before transitivity. namespace emb variables[i₁: emb G H][i: embₜ G H][j: embₜ H K] instance: has_coe(embₜ G H)(group_homs G H) := ⟨λi,{..i}⟩ instance sub{S: set G}[is_subgroup S]: emb (subGroup S) G := {hom:= by tidy, ..embed.set} instance: embₜ G K := { fn:= j ∘ i₁.fn, inj:=begin have:= i₁.inj, have:= j.inj, tidy, end, hom:= @is_group_hom.comp _ _ _ _ _ i₁.hom _ _ _ j.hom, } instance base: embₜ G H := {..i₁} instance: is_group_hom i := i.hom class normally(G H : Group)[i: embₜ G H] := (normal: normal_subgroup(range i)) @[reducible]def quot_by_embed(H G : Group)[i: embₜ G H][normally G H]: Group := ⟨quotient_group.quotient(range i), begin have:= _inst_1.normal, apply @quotient_group.group _ _ _ this, end⟩ infix `. ̸`:70 := quot_by_embed instance[normally G H]: normal_subgroup(range i) := begin tactic.unfreeze_local_instances, rcases _inst_1, assumption, end protected def lift(f: H⇒K)(fG_1: ∀g, f(i g) = 1)[normally G H]: H. ̸G ⇒ K := let iG: set H := range i in ⟨@quotient_group.lift H H.struct iG _ K K.struct f f.hom (by tidy), @quotient_group.is_group_hom_quotient_lift H _ iG _ K _ f f.hom (by tidy)⟩ --When stating theorems e.g. here one wants to assume G ↪ͭ H ↪ͭ K both transitively and G ⊴ K which requires G ↪ͭ K to be inferred. This is impossible (I think). A workaround is to write helpers that assume G ↪¹ H in one step and then convert these to the desired form using atomic_trans. def atomic_trans{R: emb G H → Sort*}(F: Πi₁: emb G H, R i₁)[i: embₜ G H] := F{..i} def instance_normally(i₁: emb G H)[j: embₜ H K][normally G K]: normally G H :=⟨⟨begin intros, have:= _inst_1.normal.normal, have:= this(j n)(by tidy)(j g), rw[←is_group_hom.inv j,←is_group_hom.mul j,←is_group_hom.mul j] at this, rcases this with ⟨m,e⟩, exact⟨m, begin apply j.inj, apply e, end⟩, end⟩⟩ instance:= @atomic_trans G H _ (@instance_normally G H K) def instance_emb(i₁: emb G H)[j: embₜ H K][normally G K]: emb(H. ̸G)(K. ̸G) :={ inj:=begin unfold injective, intros, induction a₁, induction a₂, apply quot.sound, have: quotient_group.mk(j a₁) = quotient_group.mk(j a₂) := a, change a₁⁻¹ * a₂ ∈ range _, have: j(a₁⁻¹ * a₂) ∈ range _, rw[is_group_hom.mul j, is_group_hom.inv j], simp[quotient_group.mk] at this, exact this, rcases this with ⟨g,e⟩, have ji:= j.inj, unfold injective at ji, exact⟨g, by tidy⟩, refl,refl,end, ..emb.lift(compose (⟨quotient_group.mk, by apply_instance⟩: K⇒K. ̸G) {..j}) (λg,begin change (compose _ _).fn(i₁.fn g) = 1, simp, rw(_: (1:K. ̸G) = quotient_group.mk 1), apply eq.symm, apply quot.sound, change (1:K)⁻¹ * _ ∈ range _, tidy, end), } instance emb_quot_quot:= @atomic_trans G H _ (@instance_emb G H K) def instance_emb_normal(i₁: emb G H)[j: embₜ H K][normally H K][normally G K]: normally(H. ̸G)(K. ̸G) := ⟨⟨begin intros, have: group K := K.struct, induction n, induction g, change quotient_group.mk _ * quotient_group.mk _ * (quotient_group.mk _)⁻¹ ∈ _, rw[←is_group_hom.inv(@quotient_group.mk K K.struct _ _),←is_group_hom.mul (@quotient_group.mk K K.struct _ _),←is_group_hom.mul (@quotient_group.mk K K.struct _ _)], rcases H_1 with ⟨x,e⟩, induction x, change quotient_group.mk _ = quotient_group.mk _ at e, simp[quotient_group.mk] at e, change _⁻¹ * n ∈ range _ at e, rcases e with ⟨m,h⟩, have ne: n = _ * _, apply inv_mul_eq_iff_eq_mul.mp, exact h.symm, change n = j x * j(i₁.fn m) at ne, rw[←is_group_hom.mul j] at ne, have:= _inst_1.normal.normal, rcases this n (by tidy) g, exact⟨quotient_group.mk w, begin change quotient_group.mk(j _) = _, apply congr_arg, exact h_1, end⟩, tidy, end⟩⟩ instance normal_quot_quot:= @atomic_trans G H _ (@instance_emb_normal G H K) end emb open emb open group_equiv def quotient_preserves_isom{S N : set G}[normal_subgroup S][normal_subgroup N](SeN: S = N): quotient S ≅ quotient N := via_biject_hom (quotient_group.lift S quotient_group.mk (begin--well defined intros, tactic.unfreeze_local_instances, subst SeN, change _ = quotient_group.mk _, apply eq.symm, simp[quotient_group.mk], change _*x ∈ _, simpa, end)) (begin--bijective tidy, change quotient_group.mk _ = quotient_group.mk _ at a, change quotient_group.mk _ = quotient_group.mk _, tactic.unfreeze_local_instances, subst SeN, apply a, exact quotient_group.mk b, refl, end) (by apply_instance) private def f[emb G H][embₜ H K][normally H K][normally G K]: K. ̸G ⇒ K. ̸H := emb.lift ⟨quotient_group.mk, by tidy⟩ begin intros, change quotient_group.mk _ = quotient_group.mk _, apply eq.symm, apply quot.sound, tidy, end --The third isomorphism theorem. Use isomorphism_theorem_3 below that has the same type of quot_quot except that [embₜ G H] is inferred instead of explicit i₁. Unfortunately the type signature of isomorphism_theorem_3 can't be stated due to transitivity inference problems. def quot_quot(i₁: emb G H)[j: embₜ H K][normally H K][normally G K]: (K. ̸G) . ̸ (H. ̸G) ≅ K. ̸H :=begin have qk:= quotient_ker_isom_of_surjective f.fn (λx:K. ̸H, begin induction x, change ∃ y: K. ̸G, f.fn y = quotient_group.mk x, exact⟨quotient_group.mk x, begin simp[f, emb.lift], refl, end⟩, refl, end), let J: embₜ (H. ̸G) (K. ̸G) := infer_instance, have k: ker f.fn = range J, ext, induction x, simp[ker, f, emb.lift], change quotient_group.mk _ = quotient_group.mk _ ↔ _, have: (quotient_group.mk x = quotient_group.mk 1) = (quotient_group.mk 1 = quotient_group.mk x), ext, constructor; apply eq.symm, rw this, simp[quotient_group.mk], change _ * x ∈ _ ↔ _, simp, constructor;intro h; rcases h with ⟨y,jyx⟩, exact⟨quotient_group.mk y, begin rw←jyx, refl, end⟩, induction y, change quotient_group.mk _ = quotient_group.mk _ at jyx, simp[quotient_group.mk] at jyx, change _ * _ ∈ _ at jyx, rcases jyx with ⟨z,e⟩, have xe: x = _ * _, apply inv_mul_eq_iff_eq_mul.mp, exact e.symm, change x = j _ * j _ at xe, rw[←is_group_hom.mul j] at xe, exact⟨y*_, by rw xe;refl⟩, refl,refl, apply flip group_equiv.trans qk, change quotient_group.quotient _ ≅ _, have: is_subgroup(range J), apply_instance, have: is_subgroup(ker f.fn) := @is_group_hom.preimage (K. ̸G) (K. ̸H) _ _ f.fn f.hom (is_subgroup.trivial _) _, apply quotient_preserves_isom, apply k.symm, apply_instance, exact f.hom, end def isomorphism_theorem_3 := @atomic_trans G H _ (@quot_quot G H K) #check @isomorphism_theorem_3 end group_equiv /-Problem with evaluating this: basic examples are add_groups and I don't know how to transfer them into (multiplicative) groups. namespace basic_embeddings open group_equiv instance ℤsubℚ: emb (𝔾 ℤ) (𝔾 ℚ) end basic_embeddings --/
fce24b08b1be031a8031bdff73a8286c6b09cc06
c777c32c8e484e195053731103c5e52af26a25d1
/src/algebra/lie/weights.lean
a2a68d870af654891951f942f4c146c036470e19
[ "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
23,977
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.nilpotent import algebra.lie.tensor_product import algebra.lie.character import algebra.lie.engel import algebra.lie.cartan_subalgebra import linear_algebra.eigenspace import ring_theory.tensor_product /-! # Weights and roots of Lie modules and Lie algebras Just as a key tool when studying the behaviour of a linear operator is to decompose the space on which it acts into a sum of (generalised) eigenspaces, a key tool when studying a representation `M` of Lie algebra `L` is to decompose `M` into a sum of simultaneous eigenspaces of `x` as `x` ranges over `L`. These simultaneous generalised eigenspaces are known as the weight spaces of `M`. When `L` is nilpotent, it follows from the binomial theorem that weight spaces are Lie submodules. Even when `L` is not nilpotent, it may be useful to study its representations by restricting them to a nilpotent subalgebra (e.g., a Cartan subalgebra). In the particular case when we view `L` as a module over itself via the adjoint action, the weight spaces of `L` restricted to a nilpotent subalgebra are known as root spaces. Basic definitions and properties of the above ideas are provided in this file. ## Main definitions * `lie_module.weight_space` * `lie_module.is_weight` * `lie_algebra.root_space` * `lie_algebra.is_root` * `lie_algebra.root_space_weight_space_product` * `lie_algebra.root_space_product` * `lie_algebra.zero_root_subalgebra_eq_iff_is_cartan` ## References * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 7--9*](bourbaki1975b) ## Tags lie character, eigenvalue, eigenspace, weight, weight vector, root, root vector -/ universes u v w w₁ w₂ w₃ variables {R : Type u} {L : Type v} [comm_ring R] [lie_ring L] [lie_algebra R L] variables (H : lie_subalgebra R L) [lie_algebra.is_nilpotent R H] variables (M : Type w) [add_comm_group M] [module R M] [lie_ring_module L M] [lie_module R L M] namespace lie_module open lie_algebra open tensor_product open tensor_product.lie_module open_locale big_operators open_locale tensor_product /-- Given a Lie module `M` over a Lie algebra `L`, the pre-weight space of `M` with respect to a map `χ : L → R` is the simultaneous generalized eigenspace of the action of all `x : L` on `M`, with eigenvalues `χ x`. See also `lie_module.weight_space`. -/ def pre_weight_space (χ : L → R) : submodule R M := ⨅ (x : L), (to_endomorphism R L M x).maximal_generalized_eigenspace (χ x) lemma mem_pre_weight_space (χ : L → R) (m : M) : m ∈ pre_weight_space M χ ↔ ∀ x, ∃ (k : ℕ), ((to_endomorphism R L M x - (χ x) • 1)^k) m = 0 := by simp [pre_weight_space, -linear_map.pow_apply] variables (R) lemma exists_pre_weight_space_zero_le_ker_of_is_noetherian [is_noetherian R M] (x : L) : ∃ (k : ℕ), pre_weight_space M (0 : L → R) ≤ ((to_endomorphism R L M x)^k).ker := begin use (to_endomorphism R L M x).maximal_generalized_eigenspace_index 0, simp only [← module.End.generalized_eigenspace_zero, pre_weight_space, pi.zero_apply, infi_le, ← (to_endomorphism R L M x).maximal_generalized_eigenspace_eq], end variables {R} (L) /-- See also `bourbaki1975b` Chapter VII §1.1, Proposition 2 (ii). -/ protected lemma weight_vector_multiplication (M₁ : Type w₁) (M₂ : Type w₂) (M₃ : Type w₃) [add_comm_group M₁] [module R M₁] [lie_ring_module L M₁] [lie_module R L M₁] [add_comm_group M₂] [module R M₂] [lie_ring_module L M₂] [lie_module R L M₂] [add_comm_group M₃] [module R M₃] [lie_ring_module L M₃] [lie_module R L M₃] (g : M₁ ⊗[R] M₂ →ₗ⁅R,L⁆ M₃) (χ₁ χ₂ : L → R) : ((g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp (map_incl (pre_weight_space M₁ χ₁) (pre_weight_space M₂ χ₂))).range ≤ pre_weight_space M₃ (χ₁ + χ₂) := begin /- Unpack the statement of the goal. -/ intros m₃, simp only [lie_module_hom.coe_to_linear_map, pi.add_apply, function.comp_app, mem_pre_weight_space, linear_map.coe_comp, tensor_product.map_incl, exists_imp_distrib, linear_map.mem_range], rintros t rfl x, /- Set up some notation. -/ let F : module.End R M₃ := (to_endomorphism R L M₃ x) - (χ₁ x + χ₂ x) • 1, change ∃ k, (F^k) (g _) = 0, /- The goal is linear in `t` so use induction to reduce to the case that `t` is a pure tensor. -/ apply t.induction_on, { use 0, simp only [linear_map.map_zero, lie_module_hom.map_zero], }, swap, { rintros t₁ t₂ ⟨k₁, hk₁⟩ ⟨k₂, hk₂⟩, use max k₁ k₂, simp only [lie_module_hom.map_add, linear_map.map_add, linear_map.pow_map_zero_of_le (le_max_left k₁ k₂) hk₁, linear_map.pow_map_zero_of_le (le_max_right k₁ k₂) hk₂, add_zero], }, /- Now the main argument: pure tensors. -/ rintros ⟨m₁, hm₁⟩ ⟨m₂, hm₂⟩, change ∃ k, (F^k) ((g : M₁ ⊗[R] M₂ →ₗ[R] M₃) (m₁ ⊗ₜ m₂)) = 0, /- Eliminate `g` from the picture. -/ let f₁ : module.End R (M₁ ⊗[R] M₂) := (to_endomorphism R L M₁ x - (χ₁ x) • 1).rtensor M₂, let f₂ : module.End R (M₁ ⊗[R] M₂) := (to_endomorphism R L M₂ x - (χ₂ x) • 1).ltensor M₁, have h_comm_square : F ∘ₗ ↑g = (g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp (f₁ + f₂), { ext m₁ m₂, simp only [← g.map_lie x (m₁ ⊗ₜ m₂), add_smul, sub_tmul, tmul_sub, smul_tmul, lie_tmul_right, tmul_smul, to_endomorphism_apply_apply, lie_module_hom.map_smul, linear_map.one_apply, lie_module_hom.coe_to_linear_map, linear_map.smul_apply, function.comp_app, linear_map.coe_comp, linear_map.rtensor_tmul, lie_module_hom.map_add, linear_map.add_apply, lie_module_hom.map_sub, linear_map.sub_apply, linear_map.ltensor_tmul, algebra_tensor_module.curry_apply, curry_apply, linear_map.to_fun_eq_coe, linear_map.coe_restrict_scalars_eq_coe], abel, }, rsuffices ⟨k, hk⟩ : ∃ k, ((f₁ + f₂)^k) (m₁ ⊗ₜ m₂) = 0, { use k, rw [← linear_map.comp_apply, linear_map.commute_pow_left_of_commute h_comm_square, linear_map.comp_apply, hk, linear_map.map_zero], }, /- Unpack the information we have about `m₁`, `m₂`. -/ simp only [mem_pre_weight_space] at hm₁ hm₂, obtain ⟨k₁, hk₁⟩ := hm₁ x, obtain ⟨k₂, hk₂⟩ := hm₂ x, have hf₁ : (f₁^k₁) (m₁ ⊗ₜ m₂) = 0, { simp only [hk₁, zero_tmul, linear_map.rtensor_tmul, linear_map.rtensor_pow], }, have hf₂ : (f₂^k₂) (m₁ ⊗ₜ m₂) = 0, { simp only [hk₂, tmul_zero, linear_map.ltensor_tmul, linear_map.ltensor_pow], }, /- It's now just an application of the binomial theorem. -/ use k₁ + k₂ - 1, have hf_comm : commute f₁ f₂, { ext m₁ m₂, simp only [linear_map.mul_apply, linear_map.rtensor_tmul, linear_map.ltensor_tmul, algebra_tensor_module.curry_apply, linear_map.to_fun_eq_coe, linear_map.ltensor_tmul, curry_apply, linear_map.coe_restrict_scalars_eq_coe], }, rw hf_comm.add_pow', simp only [tensor_product.map_incl, submodule.subtype_apply, finset.sum_apply, submodule.coe_mk, linear_map.coe_fn_sum, tensor_product.map_tmul, linear_map.smul_apply], /- The required sum is zero because each individual term is zero. -/ apply finset.sum_eq_zero, rintros ⟨i, j⟩ hij, /- Eliminate the binomial coefficients from the picture. -/ suffices : (f₁^i * f₂^j) (m₁ ⊗ₜ m₂) = 0, { rw this, apply smul_zero, }, /- Finish off with appropriate case analysis. -/ cases nat.le_or_le_of_add_eq_add_pred (finset.nat.mem_antidiagonal.mp hij) with hi hj, { rw [(hf_comm.pow_pow i j).eq, linear_map.mul_apply, linear_map.pow_map_zero_of_le hi hf₁, linear_map.map_zero], }, { rw [linear_map.mul_apply, linear_map.pow_map_zero_of_le hj hf₂, linear_map.map_zero], }, end variables {L M} lemma lie_mem_pre_weight_space_of_mem_pre_weight_space {χ₁ χ₂ : L → R} {x : L} {m : M} (hx : x ∈ pre_weight_space L χ₁) (hm : m ∈ pre_weight_space M χ₂) : ⁅x, m⁆ ∈ pre_weight_space M (χ₁ + χ₂) := begin apply lie_module.weight_vector_multiplication L L M M (to_module_hom R L M) χ₁ χ₂, simp only [lie_module_hom.coe_to_linear_map, function.comp_app, linear_map.coe_comp, tensor_product.map_incl, linear_map.mem_range], use [⟨x, hx⟩ ⊗ₜ ⟨m, hm⟩], simp only [submodule.subtype_apply, to_module_hom_apply, tensor_product.map_tmul], refl, end variables (M) /-- If a Lie algebra is nilpotent, then pre-weight spaces are Lie submodules. -/ def weight_space [lie_algebra.is_nilpotent R L] (χ : L → R) : lie_submodule R L M := { lie_mem := λ x m hm, begin rw ← zero_add χ, refine lie_mem_pre_weight_space_of_mem_pre_weight_space _ hm, suffices : pre_weight_space L (0 : L → R) = ⊤, { simp only [this, submodule.mem_top], }, exact lie_algebra.infi_max_gen_zero_eigenspace_eq_top_of_nilpotent R L, end, .. pre_weight_space M χ } lemma mem_weight_space [lie_algebra.is_nilpotent R L] (χ : L → R) (m : M) : m ∈ weight_space M χ ↔ m ∈ pre_weight_space M χ := iff.rfl /-- See also the more useful form `lie_module.zero_weight_space_eq_top_of_nilpotent`. -/ @[simp] lemma zero_weight_space_eq_top_of_nilpotent' [lie_algebra.is_nilpotent R L] [is_nilpotent R L M] : weight_space M (0 : L → R) = ⊤ := begin rw [← lie_submodule.coe_to_submodule_eq_iff, lie_submodule.top_coe_submodule], exact infi_max_gen_zero_eigenspace_eq_top_of_nilpotent R L M, end lemma coe_weight_space_of_top [lie_algebra.is_nilpotent R L] (χ : L → R) : (weight_space M (χ ∘ (⊤ : lie_subalgebra R L).incl) : submodule R M) = weight_space M χ := begin ext m, simp only [weight_space, lie_submodule.coe_to_submodule_mk, lie_subalgebra.coe_bracket_of_module, function.comp_app, mem_pre_weight_space], split; intros h x, { obtain ⟨k, hk⟩ := h ⟨x, set.mem_univ x⟩, use k, exact hk, }, { obtain ⟨k, hk⟩ := h x, use k, exact hk, }, end @[simp] lemma zero_weight_space_eq_top_of_nilpotent [lie_algebra.is_nilpotent R L] [is_nilpotent R L M] : weight_space M (0 : (⊤ : lie_subalgebra R L) → R) = ⊤ := begin /- We use `coe_weight_space_of_top` as a trick to circumvent the fact that we don't (yet) know `is_nilpotent R (⊤ : lie_subalgebra R L) M` is equivalent to `is_nilpotent R L M`. -/ have h₀ : (0 : L → R) ∘ (⊤ : lie_subalgebra R L).incl = 0, { ext, refl, }, rw [← lie_submodule.coe_to_submodule_eq_iff, lie_submodule.top_coe_submodule, ← h₀, coe_weight_space_of_top, ← infi_max_gen_zero_eigenspace_eq_top_of_nilpotent R L M], refl, end /-- Given a Lie module `M` of a Lie algebra `L`, a weight of `M` with respect to a nilpotent subalgebra `H ⊆ L` is a Lie character whose corresponding weight space is non-empty. -/ def is_weight (χ : lie_character R H) : Prop := weight_space M χ ≠ ⊥ /-- For a non-trivial nilpotent Lie module over a nilpotent Lie algebra, the zero character is a weight with respect to the `⊤` Lie subalgebra. -/ lemma is_weight_zero_of_nilpotent [nontrivial M] [lie_algebra.is_nilpotent R L] [is_nilpotent R L M] : is_weight (⊤ : lie_subalgebra R L) M 0 := by { rw [is_weight, lie_hom.coe_zero, zero_weight_space_eq_top_of_nilpotent], exact top_ne_bot, } /-- A (nilpotent) Lie algebra acts nilpotently on the zero weight space of a Noetherian Lie module. -/ lemma is_nilpotent_to_endomorphism_weight_space_zero [lie_algebra.is_nilpotent R L] [is_noetherian R M] (x : L) : _root_.is_nilpotent $ to_endomorphism R L (weight_space M (0 : L → R)) x := begin obtain ⟨k, hk⟩ := exists_pre_weight_space_zero_le_ker_of_is_noetherian R M x, use k, ext ⟨m, hm⟩, rw [linear_map.zero_apply, lie_submodule.coe_zero, submodule.coe_eq_zero, ← lie_submodule.to_endomorphism_restrict_eq_to_endomorphism, linear_map.pow_restrict, ← set_like.coe_eq_coe, linear_map.restrict_apply, submodule.coe_mk, submodule.coe_zero], exact hk hm, end /-- By Engel's theorem, when the Lie algebra is Noetherian, the zero weight space of a Noetherian Lie module is nilpotent. -/ instance [lie_algebra.is_nilpotent R L] [is_noetherian R L] [is_noetherian R M] : is_nilpotent R L (weight_space M (0 : L → R)) := is_nilpotent_iff_forall.mpr $ is_nilpotent_to_endomorphism_weight_space_zero M end lie_module namespace lie_algebra open_locale tensor_product open tensor_product.lie_module open lie_module /-- Given a nilpotent Lie subalgebra `H ⊆ L`, the root space of a map `χ : H → R` is the weight space of `L` regarded as a module of `H` via the adjoint action. -/ abbreviation root_space (χ : H → R) : lie_submodule R H L := weight_space L χ @[simp] lemma zero_root_space_eq_top_of_nilpotent [h : is_nilpotent R L] : root_space (⊤ : lie_subalgebra R L) 0 = ⊤ := zero_weight_space_eq_top_of_nilpotent L /-- A root of a Lie algebra `L` with respect to a nilpotent subalgebra `H ⊆ L` is a weight of `L`, regarded as a module of `H` via the adjoint action. -/ abbreviation is_root := is_weight H L @[simp] lemma root_space_comap_eq_weight_space (χ : H → R) : (root_space H χ).comap H.incl' = weight_space H χ := begin ext x, let f : H → module.End R L := λ y, to_endomorphism R H L y - (χ y) • 1, let g : H → module.End R H := λ y, to_endomorphism R H H y - (χ y) • 1, suffices : (∀ (y : H), ∃ (k : ℕ), ((f y)^k).comp (H.incl : H →ₗ[R] L) x = 0) ↔ ∀ (y : H), ∃ (k : ℕ), (H.incl : H →ₗ[R] L).comp ((g y)^k) x = 0, { simp only [lie_hom.coe_to_linear_map, lie_subalgebra.coe_incl, function.comp_app, linear_map.coe_comp, submodule.coe_eq_zero] at this, simp only [mem_weight_space, mem_pre_weight_space, lie_subalgebra.coe_incl', lie_submodule.mem_comap, this], }, have hfg : ∀ (y : H), (f y).comp (H.incl : H →ₗ[R] L) = (H.incl : H →ₗ[R] L).comp (g y), { rintros ⟨y, hy⟩, ext ⟨z, hz⟩, simp only [submodule.coe_sub, to_endomorphism_apply_apply, lie_hom.coe_to_linear_map, linear_map.one_apply, lie_subalgebra.coe_incl, lie_subalgebra.coe_bracket_of_module, lie_subalgebra.coe_bracket, linear_map.smul_apply, function.comp_app, submodule.coe_smul_of_tower, linear_map.coe_comp, linear_map.sub_apply], }, simp_rw [linear_map.commute_pow_left_of_commute (hfg _)], end variables {H M} lemma lie_mem_weight_space_of_mem_weight_space {χ₁ χ₂ : H → R} {x : L} {m : M} (hx : x ∈ root_space H χ₁) (hm : m ∈ weight_space M χ₂) : ⁅x, m⁆ ∈ weight_space M (χ₁ + χ₂) := begin apply lie_module.weight_vector_multiplication H L M M ((to_module_hom R L M).restrict_lie H) χ₁ χ₂, simp only [lie_module_hom.coe_to_linear_map, function.comp_app, linear_map.coe_comp, tensor_product.map_incl, linear_map.mem_range], use [⟨x, hx⟩ ⊗ₜ ⟨m, hm⟩], simp only [submodule.subtype_apply, to_module_hom_apply, submodule.coe_mk, lie_module_hom.coe_restrict_lie, tensor_product.map_tmul], end variables (R L H M) /-- Auxiliary definition for `root_space_weight_space_product`, which is close to the deterministic timeout limit. -/ def root_space_weight_space_product_aux {χ₁ χ₂ χ₃ : H → R} (hχ : χ₁ + χ₂ = χ₃) : (root_space H χ₁) →ₗ[R] (weight_space M χ₂) →ₗ[R] (weight_space M χ₃) := { to_fun := λ x, { to_fun := λ m, ⟨⁅(x : L), (m : M)⁆, hχ ▸ (lie_mem_weight_space_of_mem_weight_space x.property m.property) ⟩, map_add' := λ m n, by { simp only [lie_submodule.coe_add, lie_add], refl, }, map_smul' := λ t m, by { conv_lhs { congr, rw [lie_submodule.coe_smul, lie_smul], }, refl, }, }, map_add' := λ x y, by ext m; rw [linear_map.add_apply, linear_map.coe_mk, linear_map.coe_mk, linear_map.coe_mk, subtype.coe_mk, lie_submodule.coe_add, lie_submodule.coe_add, add_lie, subtype.coe_mk, subtype.coe_mk], map_smul' := λ t x, begin simp only [ring_hom.id_apply], ext m, rw [linear_map.smul_apply, linear_map.coe_mk, linear_map.coe_mk, subtype.coe_mk, lie_submodule.coe_smul, smul_lie, lie_submodule.coe_smul, subtype.coe_mk], end, } /-- Given a nilpotent Lie subalgebra `H ⊆ L` together with `χ₁ χ₂ : H → R`, there is a natural `R`-bilinear product of root vectors and weight vectors, compatible with the actions of `H`. -/ def root_space_weight_space_product (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) : (root_space H χ₁) ⊗[R] (weight_space M χ₂) →ₗ⁅R,H⁆ weight_space M χ₃ := lift_lie R H (root_space H χ₁) (weight_space M χ₂) (weight_space M χ₃) { to_linear_map := root_space_weight_space_product_aux R L H M hχ, map_lie' := λ x y, by ext m; rw [root_space_weight_space_product_aux, lie_hom.lie_apply, lie_submodule.coe_sub, linear_map.coe_mk, linear_map.coe_mk, subtype.coe_mk, subtype.coe_mk, lie_submodule.coe_bracket, lie_submodule.coe_bracket, subtype.coe_mk, lie_subalgebra.coe_bracket_of_module, lie_subalgebra.coe_bracket_of_module, lie_submodule.coe_bracket, lie_subalgebra.coe_bracket_of_module, lie_lie], } @[simp] lemma coe_root_space_weight_space_product_tmul (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) (x : root_space H χ₁) (m : weight_space M χ₂) : (root_space_weight_space_product R L H M χ₁ χ₂ χ₃ hχ (x ⊗ₜ m) : M) = ⁅(x : L), (m : M)⁆ := by simp only [root_space_weight_space_product, root_space_weight_space_product_aux, lift_apply, lie_module_hom.coe_to_linear_map, coe_lift_lie_eq_lift_coe, submodule.coe_mk, linear_map.coe_mk, lie_module_hom.coe_mk] /-- Given a nilpotent Lie subalgebra `H ⊆ L` together with `χ₁ χ₂ : H → R`, there is a natural `R`-bilinear product of root vectors, compatible with the actions of `H`. -/ def root_space_product (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) : (root_space H χ₁) ⊗[R] (root_space H χ₂) →ₗ⁅R,H⁆ root_space H χ₃ := root_space_weight_space_product R L H L χ₁ χ₂ χ₃ hχ @[simp] lemma root_space_product_def : root_space_product R L H = root_space_weight_space_product R L H L := rfl lemma root_space_product_tmul (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) (x : root_space H χ₁) (y : root_space H χ₂) : (root_space_product R L H χ₁ χ₂ χ₃ hχ (x ⊗ₜ y) : L) = ⁅(x : L), (y : L)⁆ := by simp only [root_space_product_def, coe_root_space_weight_space_product_tmul] /-- Given a nilpotent Lie subalgebra `H ⊆ L`, the root space of the zero map `0 : H → R` is a Lie subalgebra of `L`. -/ def zero_root_subalgebra : lie_subalgebra R L := { lie_mem' := λ x y hx hy, by { let xy : (root_space H 0) ⊗[R] (root_space H 0) := ⟨x, hx⟩ ⊗ₜ ⟨y, hy⟩, suffices : (root_space_product R L H 0 0 0 (add_zero 0) xy : L) ∈ root_space H 0, { rwa [root_space_product_tmul, subtype.coe_mk, subtype.coe_mk] at this, }, exact (root_space_product R L H 0 0 0 (add_zero 0) xy).property, }, .. (root_space H 0 : submodule R L) } @[simp] lemma coe_zero_root_subalgebra : (zero_root_subalgebra R L H : submodule R L) = root_space H 0 := rfl lemma mem_zero_root_subalgebra (x : L) : x ∈ zero_root_subalgebra R L H ↔ ∀ (y : H), ∃ (k : ℕ), ((to_endomorphism R H L y)^k) x = 0 := by simp only [zero_root_subalgebra, mem_weight_space, mem_pre_weight_space, pi.zero_apply, sub_zero, set_like.mem_coe, zero_smul, lie_submodule.mem_coe_submodule, submodule.mem_carrier, lie_subalgebra.mem_mk_iff] lemma to_lie_submodule_le_root_space_zero : H.to_lie_submodule ≤ root_space H 0 := begin intros x hx, simp only [lie_subalgebra.mem_to_lie_submodule] at hx, simp only [mem_weight_space, mem_pre_weight_space, pi.zero_apply, sub_zero, zero_smul], intros y, unfreezingI { obtain ⟨k, hk⟩ := (infer_instance : is_nilpotent R H) }, use k, let f : module.End R H := to_endomorphism R H H y, let g : module.End R L := to_endomorphism R H L y, have hfg : g.comp (H : submodule R L).subtype = (H : submodule R L).subtype.comp f, { ext z, simp only [to_endomorphism_apply_apply, submodule.subtype_apply, lie_subalgebra.coe_bracket_of_module, lie_subalgebra.coe_bracket, function.comp_app, linear_map.coe_comp], }, change (g^k).comp (H : submodule R L).subtype ⟨x, hx⟩ = 0, rw linear_map.commute_pow_left_of_commute hfg k, have h := iterate_to_endomorphism_mem_lower_central_series R H H y ⟨x, hx⟩ k, rw [hk, lie_submodule.mem_bot] at h, simp only [submodule.subtype_apply, function.comp_app, linear_map.pow_apply, linear_map.coe_comp, submodule.coe_eq_zero], exact h, end lemma le_zero_root_subalgebra : H ≤ zero_root_subalgebra R L H := begin rw [← lie_subalgebra.coe_submodule_le_coe_submodule, ← H.coe_to_lie_submodule, coe_zero_root_subalgebra, lie_submodule.coe_submodule_le_coe_submodule], exact to_lie_submodule_le_root_space_zero R L H, end @[simp] lemma zero_root_subalgebra_normalizer_eq_self : (zero_root_subalgebra R L H).normalizer = zero_root_subalgebra R L H := begin refine le_antisymm _ (lie_subalgebra.le_normalizer _), intros x hx, rw lie_subalgebra.mem_normalizer_iff at hx, rw mem_zero_root_subalgebra, rintros ⟨y, hy⟩, specialize hx y (le_zero_root_subalgebra R L H hy), rw mem_zero_root_subalgebra at hx, obtain ⟨k, hk⟩ := hx ⟨y, hy⟩, rw [← lie_skew, linear_map.map_neg, neg_eq_zero] at hk, use k + 1, rw [linear_map.iterate_succ, linear_map.coe_comp, function.comp_app, to_endomorphism_apply_apply, lie_subalgebra.coe_bracket_of_module, submodule.coe_mk, hk], end /-- If the zero root subalgebra of a nilpotent Lie subalgebra `H` is just `H` then `H` is a Cartan subalgebra. When `L` is Noetherian, it follows from Engel's theorem that the converse holds. See `lie_algebra.zero_root_subalgebra_eq_iff_is_cartan` -/ lemma is_cartan_of_zero_root_subalgebra_eq (h : zero_root_subalgebra R L H = H) : H.is_cartan_subalgebra := { nilpotent := infer_instance, self_normalizing := by { rw ← h, exact zero_root_subalgebra_normalizer_eq_self R L H, } } @[simp] lemma zero_root_subalgebra_eq_of_is_cartan (H : lie_subalgebra R L) [H.is_cartan_subalgebra] [is_noetherian R L] : zero_root_subalgebra R L H = H := begin refine le_antisymm _ (le_zero_root_subalgebra R L H), suffices : root_space H 0 ≤ H.to_lie_submodule, { exact λ x hx, this hx, }, obtain ⟨k, hk⟩ := (root_space H 0).is_nilpotent_iff_exists_self_le_ucs.mp (by apply_instance), exact hk.trans (lie_submodule.ucs_le_of_normalizer_eq_self (by simp) k), end lemma zero_root_subalgebra_eq_iff_is_cartan [is_noetherian R L] : zero_root_subalgebra R L H = H ↔ H.is_cartan_subalgebra := ⟨is_cartan_of_zero_root_subalgebra_eq R L H, by { introsI, simp, }⟩ end lie_algebra namespace lie_module open lie_algebra variables {R L H} /-- A priori, weight spaces are Lie submodules over the Lie subalgebra `H` used to define them. However they are naturally Lie submodules over the (in general larger) Lie subalgebra `zero_root_subalgebra R L H`. Even though it is often the case that `zero_root_subalgebra R L H = H`, it is likely to be useful to have the flexibility not to have to invoke this equality (as well as to work more generally). -/ def weight_space' (χ : H → R) : lie_submodule R (zero_root_subalgebra R L H) M := { lie_mem := λ x m hm, by { have hx : (x : L) ∈ root_space H 0, { rw [← lie_submodule.mem_coe_submodule, ← coe_zero_root_subalgebra], exact x.property, }, rw ← zero_add χ, exact lie_mem_weight_space_of_mem_weight_space hx hm, }, .. (weight_space M χ : submodule R M) } @[simp] lemma coe_weight_space' (χ : H → R) : (weight_space' M χ : submodule R M) = weight_space M χ := rfl end lie_module
4d66d75fd09b34a02b2a01948c79687a7103f240
957a80ea22c5abb4f4670b250d55534d9db99108
/library/init/native/builtin.lean
04a8c3b82285a061aac6715d1b4667c83c6b80dc
[ "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
352
lean
/- Copyright (c) 2016 Jared Roesch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jared Roesch -/ prelude import init.meta.name inductive builtin | cfun : name → nat → builtin | cases : name → nat → builtin | vm : name → builtin meta constant native.get_builtin : name → option builtin
c5bb0ee41f16d67c9ae686787d1f3c9c5e6b77b5
b7f22e51856f4989b970961f794f1c435f9b8f78
/hott/hit/groupoid_quotient.hlean
8b421259bb13b28f42dd8ad60623764776a85928
[ "Apache-2.0" ]
permissive
soonhokong/lean
cb8aa01055ffe2af0fb99a16b4cda8463b882cd1
38607e3eb57f57f77c0ac114ad169e9e4262e24f
refs/heads/master
1,611,187,284,081
1,450,766,737,000
1,476,122,547,000
11,513,992
2
0
null
1,401,763,102,000
1,374,182,235,000
C++
UTF-8
Lean
false
false
9,588
hlean
/- Copyright (c) 2015-16 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn The groupoid quotient. This is a 1-type which path spaces is the same as the morphisms a given groupoid. We define it as the 1-truncation of a two quotient. -/ import algebra.category.groupoid .two_quotient homotopy.connectedness algebra.group_theory open trunc_two_quotient eq bool unit relation category e_closure iso is_trunc trunc equiv is_equiv group namespace groupoid_quotient section parameter (G : Groupoid) inductive groupoid_quotient_R : G → G → Type := | Rmk : Π{a b : G} (f : a ⟶ b), groupoid_quotient_R a b open groupoid_quotient_R local abbreviation R := groupoid_quotient_R inductive groupoid_quotient_Q : Π⦃x y : G⦄, e_closure groupoid_quotient_R x y → e_closure groupoid_quotient_R x y → Type := | Qconcat : Π{a b c : G} (g : b ⟶ c) (f : a ⟶ b), groupoid_quotient_Q [Rmk (g ∘ f)] ([Rmk f] ⬝r [Rmk g]) open groupoid_quotient_Q local abbreviation Q := groupoid_quotient_Q definition groupoid_quotient := trunc_two_quotient 1 R Q local attribute groupoid_quotient [reducible] definition is_trunc_groupoid_quotient [instance] : is_trunc 1 groupoid_quotient := _ parameter {G} variables {a b c : G} definition elt (a : G) : groupoid_quotient := incl0 a definition pth (f : a ⟶ b) : elt a = elt b := incl1 (Rmk f) definition resp_comp (g : b ⟶ c) (f : a ⟶ b) : pth (g ∘ f) = pth f ⬝ pth g := incl2 (Qconcat g f) definition resp_id (a : G) : pth (ID a) = idp := begin apply cancel_right (pth (id)), refine _ ⬝ !idp_con⁻¹, refine !resp_comp⁻¹ ⬝ _, exact ap pth !id_id, end definition resp_inv (f : a ⟶ b) : pth (f⁻¹) = (pth f)⁻¹ := begin apply eq_inv_of_con_eq_idp', refine !resp_comp⁻¹ ⬝ _, refine ap pth !right_inverse ⬝ _, apply resp_id end protected definition rec {P : groupoid_quotient → Type} [Πx, is_trunc 1 (P x)] (Pe : Πg, P (elt g)) (Pp : Π⦃a b⦄ (f : a ⟶ b), Pe a =[pth f] Pe b) (Pcomp : Π⦃a b c⦄ (g : b ⟶ c) (f : a ⟶ b), change_path (resp_comp g f) (Pp (g ∘ f)) = Pp f ⬝o Pp g) (x : groupoid_quotient) : P x := begin induction x, { apply Pe}, { induction s with a b f, apply Pp}, { induction q with a b c g f, apply Pcomp} end protected definition rec_on {P : groupoid_quotient → Type} [Πx, is_trunc 1 (P x)] (x : groupoid_quotient) (Pe : Πg, P (elt g)) (Pp : Π⦃a b⦄ (f : a ⟶ b), Pe a =[pth f] Pe b) (Pcomp : Π⦃a b c⦄ (g : b ⟶ c) (f : a ⟶ b), change_path (resp_comp g f) (Pp (g ∘ f)) = Pp f ⬝o Pp g) : P x := rec Pe Pp Pcomp x protected definition set_rec {P : groupoid_quotient → Type} [Πx, is_set (P x)] (Pe : Πg, P (elt g)) (Pp : Π⦃a b⦄ (f : a ⟶ b), Pe a =[pth f] Pe b) (x : groupoid_quotient) : P x := rec Pe Pp !center x protected definition prop_rec {P : groupoid_quotient → Type} [Πx, is_prop (P x)] (Pe : Πg, P (elt g)) (x : groupoid_quotient) : P x := rec Pe !center !center x definition rec_pth {P : groupoid_quotient → Type} [Πx, is_trunc 1 (P x)] {Pe : Πg, P (elt g)} {Pp : Π⦃a b⦄ (f : a ⟶ b), Pe a =[pth f] Pe b} (Pcomp : Π⦃a b c⦄ (g : b ⟶ c) (f : a ⟶ b), change_path (resp_comp g f) (Pp (g ∘ f)) = Pp f ⬝o Pp g) {a b : G} (f : a ⟶ b) : apd (rec Pe Pp Pcomp) (pth f) = Pp f := proof !rec_incl1 qed protected definition elim {P : Type} [is_trunc 1 P] (Pe : G → P) (Pp : Π⦃a b⦄ (f : a ⟶ b), Pe a = Pe b) (Pcomp : Π⦃a b c⦄ (g : b ⟶ c) (f : a ⟶ b), Pp (g ∘ f) = Pp f ⬝ Pp g) (x : groupoid_quotient) : P := begin induction x, { exact Pe a}, { induction s with a b f, exact Pp f}, { induction q with a b c g f, exact Pcomp g f} end protected definition elim_on [reducible] {P : Type} [is_trunc 1 P] (x : groupoid_quotient) (Pe : G → P) (Pp : Π⦃a b⦄ (f : a ⟶ b), Pe a = Pe b) (Pcomp : Π⦃a b c⦄ (g : b ⟶ c) (f : a ⟶ b), Pp (g ∘ f) = Pp f ⬝ Pp g) : P := elim Pe Pp Pcomp x protected definition set_elim [reducible] {P : Type} [is_set P] (Pe : G → P) (Pp : Π⦃a b⦄ (f : a ⟶ b), Pe a = Pe b) (x : groupoid_quotient) : P := elim Pe Pp !center x protected definition prop_elim [reducible] {P : Type} [is_prop P] (Pe : G → P) (x : groupoid_quotient) : P := elim Pe !center !center x definition elim_pth {P : Type} [is_trunc 1 P] {Pe : G → P} {Pp : Π⦃a b⦄ (f : a ⟶ b), Pe a = Pe b} (Pcomp : Π⦃a b c⦄ (g : b ⟶ c) (f : a ⟶ b), Pp (g ∘ f) = Pp f ⬝ Pp g) {a b : G} (f : a ⟶ b) : ap (elim Pe Pp Pcomp) (pth f) = Pp f := !elim_incl1 -- The following rule is also true because P is a 1-type, and can be proven by `!is_set.elims` -- The following is the canonical proofs which holds for any truncated two-quotient. theorem elim_resp_comp {P : Type} [is_trunc 1 P] {Pe : G → P} {Pp : Π⦃a b⦄ (f : a ⟶ b), Pe a = Pe b} (Pcomp : Π⦃a b c⦄ (g : b ⟶ c) (f : a ⟶ b), Pp (g ∘ f) = Pp f ⬝ Pp g) {a b c : G} (g : b ⟶ c) (f : a ⟶ b) : square (ap02 (elim Pe Pp Pcomp) (resp_comp g f)) (Pcomp g f) (elim_pth Pcomp (g ∘ f)) (!ap_con ⬝ (elim_pth Pcomp f ◾ elim_pth Pcomp g)) := proof !elim_incl2 qed protected definition elim_set.{u} (Pe : G → Set.{u}) (Pp : Π⦃a b⦄ (f : a ⟶ b), Pe a ≃ Pe b) (Pcomp : Π⦃a b c⦄ (g : b ⟶ c) (f : a ⟶ b) (x : Pe a), Pp (g ∘ f) x = Pp g (Pp f x)) (x : groupoid_quotient) : Set.{u} := elim Pe (λa b f, tua (Pp f)) (λa b c g f, ap tua (equiv_eq (Pcomp g f)) ⬝ !tua_trans) x theorem elim_set_pth {Pe : G → Set} {Pp : Π⦃a b⦄ (f : a ⟶ b), Pe a ≃ Pe b} (Pcomp : Π⦃a b c⦄ (g : b ⟶ c) (f : a ⟶ b) (x : Pe a), Pp (g ∘ f) x = Pp g (Pp f x)) {a b : G} (f : a ⟶ b) : transport (elim_set Pe Pp Pcomp) (pth f) = Pp f := by rewrite [tr_eq_cast_ap_fn, ↑elim_set, ▸*, ap_compose' trunctype.carrier, elim_pth]; apply tcast_tua_fn end end groupoid_quotient attribute groupoid_quotient.elt [constructor] attribute groupoid_quotient.rec groupoid_quotient.elim [unfold 7] [recursor 7] attribute groupoid_quotient.rec_on groupoid_quotient.elim_on [unfold 4] attribute groupoid_quotient.set_rec groupoid_quotient.set_elim [unfold 6] attribute groupoid_quotient.prop_rec groupoid_quotient.prop_elim groupoid_quotient.elim_set [unfold 5] open sigma pi is_conn function namespace groupoid_quotient section universe variables u v variables {G : Groupoid.{u v}} (a : G) {b c : G} include a protected definition code [unfold 3] (x : groupoid_quotient G) : Set.{v} := begin refine groupoid_quotient.elim_set _ _ _ x, { intro b, exact homset a b}, { intro b c g, exact equiv_postcompose g}, { intro b c d h g f, esimp at *, apply assoc'} end omit a local abbreviation code [unfold 3] := @groupoid_quotient.code G a variable {a} protected definition encode [unfold 4] (x : groupoid_quotient G) (p : elt a = x) : code a x := transport (code a) p (ID a) protected definition decode [unfold 3] (x : groupoid_quotient G) (z : code a x) : elt a = x := begin induction x using groupoid_quotient.set_rec with b b c g, { esimp, exact pth z}, { apply arrow_pathover_left, esimp, intro f, apply eq_pathover_constant_left_id_right, apply square_of_eq, refine !resp_comp⁻¹ ⬝ _ ⬝ !idp_con⁻¹, rewrite elim_set_pth} end local abbreviation encode [unfold_full] := @groupoid_quotient.encode G a local abbreviation decode [unfold_full] := @groupoid_quotient.decode G a protected definition decode_encode (x : groupoid_quotient G) (p : elt a = x) : decode x (encode x p) = p := begin induction p, esimp, apply resp_id end protected definition encode_decode (x : groupoid_quotient G) (z : code a x) : encode x (decode x z) = z := begin induction x using groupoid_quotient.prop_rec with b, esimp, refine ap10 !elim_set_pth.{u v v} (ID a) ⬝ _, esimp, apply id_right end definition decode_comp (z : code a (elt b)) (z' : code b (elt c)) : decode (elt c) (z' ∘ z) = decode (elt b) z ⬝ decode (elt c) z' := !resp_comp variables (a b) definition elt_eq_elt_equiv [constructor] : (elt a = elt b) ≃ (a ⟶ b) := equiv.MK (encode (elt b)) (decode (elt b)) (groupoid_quotient.encode_decode (elt b)) (groupoid_quotient.decode_encode (elt b)) variables {a b} definition encode_con (p : elt a = elt b) (q : elt b = elt c) : encode (elt c) (p ⬝ q) = encode (elt c) q ∘ encode (elt b) p := begin apply eq_of_fn_eq_fn (elt_eq_elt_equiv a c)⁻¹ᵉ, refine !right_inv ⬝ _ ⬝ !decode_comp⁻¹, apply concat2, do 2 exact (to_left_inv !elt_eq_elt_equiv _)⁻¹ end variable (G) definition is_conn_groupoid_quotient [H : is_conn 0 G] : is_conn 0 (groupoid_quotient G) := begin have g : trunc 0 G, from !center, induction g with g, have p : Πh, ∥ g = h ∥, begin intro h, refine !tr_eq_tr_equiv _, apply is_prop.elim end, fapply is_contr.mk, { apply trunc_functor 0 elt (tr g)}, { intro x, induction x with x, induction x using groupoid_quotient.prop_rec with b, esimp, induction p b with q, exact ap (tr ∘ elt) q} end end end groupoid_quotient export [unfold] groupoid_quotient
8937512f3834cce3e65007f5e3c3fb6804d354c8
35677d2df3f081738fa6b08138e03ee36bc33cad
/src/data/list/of_fn.lean
b77cbb57bf627b8e0fcab4c5e5ff970b32cabdc9
[ "Apache-2.0" ]
permissive
gebner/mathlib
eab0150cc4f79ec45d2016a8c21750244a2e7ff0
cc6a6edc397c55118df62831e23bfbd6e6c6b4ab
refs/heads/master
1,625,574,853,976
1,586,712,827,000
1,586,712,827,000
99,101,412
1
0
Apache-2.0
1,586,716,389,000
1,501,667,958,000
Lean
UTF-8
Lean
false
false
2,269
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import data.list.basic import data.fin universes u variables {α : Type u} open nat namespace list /- of_fn -/ theorem length_of_fn_aux {n} (f : fin n → α) : ∀ m h l, length (of_fn_aux f m h l) = length l + m | 0 h l := rfl | (succ m) h l := (length_of_fn_aux m _ _).trans (succ_add _ _) @[simp] theorem length_of_fn {n} (f : fin n → α) : length (of_fn f) = n := (length_of_fn_aux f _ _ _).trans (zero_add _) theorem nth_of_fn_aux {n} (f : fin n → α) (i) : ∀ m h l, (∀ i, nth l i = of_fn_nth_val f (i + m)) → nth (of_fn_aux f m h l) i = of_fn_nth_val f i | 0 h l H := H i | (succ m) h l H := nth_of_fn_aux m _ _ begin intro j, cases j with j, { simp only [nth, of_fn_nth_val, zero_add, dif_pos (show m < n, from h)] }, { simp only [nth, H, succ_add] } end @[simp] theorem nth_of_fn {n} (f : fin n → α) (i) : nth (of_fn f) i = of_fn_nth_val f i := nth_of_fn_aux f _ _ _ _ $ λ i, by simp only [of_fn_nth_val, dif_neg (not_lt.2 (le_add_left n i))]; refl @[simp] theorem nth_le_of_fn {n} (f : fin n → α) (i : fin n) : nth_le (of_fn f) i.1 ((length_of_fn f).symm ▸ i.2) = f i := option.some.inj $ by rw [← nth_le_nth]; simp only [list.nth_of_fn, of_fn_nth_val, fin.eta, dif_pos i.2] theorem array_eq_of_fn {n} (a : array n α) : a.to_list = of_fn a.read := suffices ∀ {m h l}, d_array.rev_iterate_aux a (λ i, cons) m h l = of_fn_aux (d_array.read a) m h l, from this, begin intros, induction m with m IH generalizing l, {refl}, simp only [d_array.rev_iterate_aux, of_fn_aux, IH] end theorem of_fn_zero (f : fin 0 → α) : of_fn f = [] := rfl theorem of_fn_succ {n} (f : fin (succ n) → α) : of_fn f = f 0 :: of_fn (λ i, f i.succ) := suffices ∀ {m h l}, of_fn_aux f (succ m) (succ_le_succ h) l = f 0 :: of_fn_aux (λ i, f i.succ) m h l, from this, begin intros, induction m with m IH generalizing l, {refl}, rw [of_fn_aux, IH], refl end theorem of_fn_nth_le : ∀ l : list α, of_fn (λ i, nth_le l i.1 i.2) = l | [] := rfl | (a::l) := by rw of_fn_succ; congr; simp only [fin.succ_val]; exact of_fn_nth_le l end list
6ac941a3e803c2de686bda86c68c98fd9c80f9d9
75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2
/tests/lean/extra/616b.hlean
7416663be9a42476d88b61840d4d7c86a03bf481
[ "Apache-2.0" ]
permissive
jroesch/lean
30ef0860fa905d35b9ad6f76de1a4f65c9af6871
3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2
refs/heads/master
1,586,090,835,348
1,455,142,203,000
1,455,142,277,000
51,536,958
1
0
null
1,455,215,811,000
1,455,215,811,000
null
UTF-8
Lean
false
false
247
hlean
import .f616a open eq definition my_elim {A P : Type} {R : A → A → Type} (Pc : A → P) (Pp : Π⦃a a' : A⦄ (H : R a a'), Pc a = Pc a') (x : quotient R) : P := begin induction x, exact (Pc a), refine (pathover_of_eq (Pp H)) end
d46a44d99c0c59e9523a6dc8f69c78ee8ed4b354
4fa161becb8ce7378a709f5992a594764699e268
/src/analysis/convex/basic.lean
0a8a9c7d2300860ea3badab88efacfc073934985
[ "Apache-2.0" ]
permissive
laughinggas/mathlib
e4aa4565ae34e46e834434284cb26bd9d67bc373
86dcd5cda7a5017c8b3c8876c89a510a19d49aad
refs/heads/master
1,669,496,232,688
1,592,831,995,000
1,592,831,995,000
274,155,979
0
0
Apache-2.0
1,592,835,190,000
1,592,835,189,000
null
UTF-8
Lean
false
false
39,233
lean
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudriashov -/ import data.set.intervals.unordered_interval import data.set.intervals.image_preimage import data.complex.module import algebra.pointwise /-! # Convex sets and functions on real vector spaces In a real vector space, we define the following objects and properties. * `segment x y` is the closed segment joining `x` and `y`. * A set `s` is `convex` if for any two points `x y ∈ s` it includes `segment x y`; * A function `f` is `convex_on` a set `s` if `s` is itself a convex set, and for any two points `x y ∈ s` the segment joining `(x, f x)` to `(y, f y)` is (non-strictly) above the graph of `f`; equivalently, `convex_on f s` means that the epigraph `{p : E × ℝ | p.1 ∈ s ∧ f p.1 ≤ p.2}` is a convex set; * Center mass of a finite set of points with prescribed weights. * Convex hull of a set `s` is the minimal convex set that includes `s`. * Standard simplex `std_simplex ι [fintype ι]` is the intersection of the positive quadrant with the hyperplane `s.sum = 1` in the space `ι → ℝ`. We also provide various equivalent versions of the definitions above, prove that some specific sets are convex, and prove Jensen's inequality. ## Notations We use the following local notations: * `I = Icc (0:ℝ) 1`; * `[x, y] = segment x y`. They are defined using `local notation`, so they are not available outside of this file. -/ universes u' u v w x variables {E : Type u} {F : Type v} {ι : Type w} {ι' : Type x} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {s : set E} open set open_locale classical big_operators local notation `I` := (Icc 0 1 : set ℝ) local attribute [instance] set.pointwise_add set.smul_set section sets /-! ### Segment -/ /-- Segments in a vector space -/ def segment (x y : E) : set E := {z : E | ∃ (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1), a • x + b • y = z} local notation `[`x `, ` y `]` := segment x y lemma segment_symm (x y : E) : [x, y] = [y, x] := set.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩, λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩ lemma left_mem_segment (x y : E) : x ∈ [x, y] := ⟨1, 0, zero_le_one, le_refl 0, add_zero 1, by rw [zero_smul, one_smul, add_zero]⟩ lemma right_mem_segment (x y : E) : y ∈ [x, y] := segment_symm y x ▸ left_mem_segment y x lemma segment_same (x : E) : [x, x] = {x} := set.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, hz⟩, by simpa only [(add_smul _ _ _).symm, mem_singleton_iff, hab, one_smul, eq_comm] using hz, λ h, mem_singleton_iff.1 h ▸ left_mem_segment z z⟩ lemma segment_eq_image (x y : E) : segment x y = (λ (θ : ℝ), (1 - θ) • x + θ • y) '' I := set.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, hz⟩, ⟨b, ⟨hb, hab ▸ le_add_of_nonneg_left ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel]⟩, λ ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩, ⟨1-θ, θ, sub_nonneg.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩ lemma segment_eq_image' (x y : E) : segment x y = (λ (θ : ℝ), x + θ • (y - x)) '' I := by { convert segment_eq_image x y, ext θ, simp only [smul_sub, sub_smul, one_smul], abel } lemma segment_eq_image₂ (x y : E) : segment x y = (λ p:ℝ×ℝ, p.1 • x + p.2 • y) '' {p | 0 ≤ p.1 ∧ 0 ≤ p.2 ∧ p.1 + p.2 = 1} := by simp only [segment, image, prod.exists, mem_set_of_eq, exists_prop, and_assoc] lemma segment_eq_Icc {a b : ℝ} (h : a ≤ b) : [a, b] = Icc a b := begin rw [segment_eq_image'], show (((+) a) ∘ (λ t, t * (b - a))) '' Icc 0 1 = Icc a b, rw [image_comp, image_mul_right_Icc (@zero_le_one ℝ _) (sub_nonneg.2 h), image_const_add_Icc], simp end lemma segment_eq_Icc' (a b : ℝ) : [a, b] = Icc (min a b) (max a b) := by cases le_total a b; [skip, rw segment_symm]; simp [segment_eq_Icc, *] lemma segment_eq_interval (a b : ℝ) : segment a b = interval a b := segment_eq_Icc' _ _ lemma mem_segment_translate (a : E) {x b c} : a + x ∈ [a + b, a + c] ↔ x ∈ [b, c] := begin rw [segment_eq_image', segment_eq_image'], refine exists_congr (λ θ, and_congr iff.rfl _), simp only [add_sub_add_left_eq_sub, add_assoc, add_right_inj] end lemma segment_translate_preimage (a b c : E) : (λ x, a + x) ⁻¹' [a + b, a + c] = [b, c] := set.ext $ λ x, mem_segment_translate a lemma segment_translate_image (a b c: E) : (λx, a + x) '' [b, c] = [a + b, a + c] := segment_translate_preimage a b c ▸ image_preimage_eq $ add_left_surjective a /-! ### Convexity of sets -/ /-- Convexity of sets -/ def convex (s : set E) := ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • x + b • y ∈ s lemma convex_iff_forall_pos : convex s ↔ ∀ ⦃x y⦄, x ∈ s → y ∈ s → ∀ ⦃a b : ℝ⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := begin refine ⟨λ h x y hx hy a b ha hb hab, h hx hy (le_of_lt ha) (le_of_lt hb) hab, _⟩, intros h x y hx hy a b ha hb hab, cases eq_or_lt_of_le ha with ha ha, { subst a, rw [zero_add] at hab, simp [hab, hy] }, cases eq_or_lt_of_le hb with hb hb, { subst b, rw [add_zero] at hab, simp [hab, hx] }, exact h hx hy ha hb hab end lemma convex_iff_segment_subset : convex s ↔ ∀ ⦃x y⦄, x ∈ s → y ∈ s → [x, y] ⊆ s := by simp only [convex, segment_eq_image₂, subset_def, ball_image_iff, prod.forall, mem_set_of_eq, and_imp] lemma convex.segment_subset (h : convex s) {x y:E} (hx : x ∈ s) (hy : y ∈ s) : [x, y] ⊆ s := convex_iff_segment_subset.1 h hx hy /-- Alternative definition of set convexity, in terms of pointwise set operations. -/ lemma convex_iff_pointwise_add_subset: convex s ↔ ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • s + b • s ⊆ s := iff.intro begin rintros hA a b ha hb hab w ⟨au, ⟨u, hu, rfl⟩, bv, ⟨v, hv, rfl⟩, rfl⟩, exact hA hu hv ha hb hab end (λ h x y hx hy a b ha hb hab, (h ha hb hab) (set.add_mem_pointwise_add ⟨_, hx, rfl⟩ ⟨_, hy, rfl⟩)) /-- Alternative definition of set convexity, using division -/ lemma convex_iff_div: convex s ↔ ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → 0 < a + b → (a/(a+b)) • x + (b/(a+b)) • y ∈ s := ⟨begin assume h x y hx hy a b ha hb hab, apply h hx hy, have ha', from mul_le_mul_of_nonneg_left ha (le_of_lt (inv_pos.2 hab)), rwa [mul_zero, ←div_eq_inv_mul] at ha', have hb', from mul_le_mul_of_nonneg_left hb (le_of_lt (inv_pos.2 hab)), rwa [mul_zero, ←div_eq_inv_mul] at hb', rw [←add_div], exact div_self (ne_of_lt hab).symm end, begin assume h x y hx hy a b ha hb hab, have h', from h hx hy ha hb, rw [hab, div_one, div_one] at h', exact h' zero_lt_one end⟩ /-! ### Examples of convex sets -/ lemma convex_empty : convex (∅ : set E) := by finish lemma convex_singleton (c : E) : convex ({c} : set E) := begin intros x y hx hy a b ha hb hab, rw [set.eq_of_mem_singleton hx, set.eq_of_mem_singleton hy, ←add_smul, hab, one_smul], exact mem_singleton c end lemma convex_univ : convex (set.univ : set E) := λ _ _ _ _ _ _ _ _ _, trivial lemma convex.inter {t : set E} (hs: convex s) (ht: convex t) : convex (s ∩ t) := λ x y (hx : x ∈ s ∩ t) (hy : y ∈ s ∩ t) a b (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1), ⟨hs hx.left hy.left ha hb hab, ht hx.right hy.right ha hb hab⟩ lemma convex_sInter {S : set (set E)} (h : ∀ s ∈ S, convex s) : convex (⋂₀ S) := assume x y hx hy a b ha hb hab s hs, h s hs (hx s hs) (hy s hs) ha hb hab lemma convex_Inter {ι : Sort*} {s: ι → set E} (h: ∀ i : ι, convex (s i)) : convex (⋂ i, s i) := (sInter_range s) ▸ convex_sInter $ forall_range_iff.2 h lemma convex.prod {s : set E} {t : set F} (hs : convex s) (ht : convex t) : convex (s.prod t) := begin intros x y hx hy a b ha hb hab, apply mem_prod.2, exact ⟨hs (mem_prod.1 hx).1 (mem_prod.1 hy).1 ha hb hab, ht (mem_prod.1 hx).2 (mem_prod.1 hy).2 ha hb hab⟩ end lemma convex.is_linear_image (hs : convex s) {f : E → F} (hf : is_linear_map ℝ f) : convex (f '' s) := begin rintros _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩ a b ha hb hab, exact ⟨a • x + b • y, hs hx hy ha hb hab, by simp only [hf.map_add,hf.map_smul]⟩ end lemma convex.linear_image (hs : convex s) (f : E →ₗ[ℝ] F) : convex (image f s) := hs.is_linear_image f.is_linear lemma convex.is_linear_preimage {s : set F} (hs : convex s) {f : E → F} (hf : is_linear_map ℝ f) : convex (preimage f s) := begin intros x y hx hy a b ha hb hab, convert hs hx hy ha hb hab, simp only [mem_preimage, hf.map_add, hf.map_smul] end lemma convex.linear_preimage {s : set F} (hs : convex s) (f : E →ₗ[ℝ] F) : convex (preimage f s) := hs.is_linear_preimage f.is_linear lemma convex.neg (hs : convex s) : convex ((λ z, -z) '' s) := hs.is_linear_image is_linear_map.is_linear_map_neg lemma convex.neg_preimage (hs : convex s) : convex ((λ z, -z) ⁻¹' s) := hs.is_linear_preimage is_linear_map.is_linear_map_neg lemma convex.smul (c : ℝ) (hs : convex s) : convex (c • s) := begin rw smul_set_eq_image, exact hs.is_linear_image (is_linear_map.is_linear_map_smul c) end lemma convex.smul_preimage (c : ℝ) (hs : convex s) : convex ((λ z, c • z) ⁻¹' s) := hs.is_linear_preimage (is_linear_map.is_linear_map_smul c) lemma convex.add {t : set E} (hs : convex s) (ht : convex t) : convex (s + t) := by { rw pointwise_add_eq_image, exact (hs.prod ht).is_linear_image is_linear_map.is_linear_map_add } lemma convex.sub {t : set E} (hs : convex s) (ht : convex t) : convex ((λx : E × E, x.1 - x.2) '' (s.prod t)) := (hs.prod ht).is_linear_image is_linear_map.is_linear_map_sub lemma convex.translate (hs : convex s) (z : E) : convex ((λx, z + x) '' s) := begin convert (convex_singleton z).add hs, ext x, simp [set.mem_image, mem_pointwise_add, eq_comm] end lemma convex.affinity (hs : convex s) (z : E) (c : ℝ) : convex ((λx, z + c • x) '' s) := begin convert (hs.smul c).translate z using 1, erw [smul_set_eq_image, ←image_comp] end lemma convex_real_iff {s : set ℝ} : convex s ↔ ∀ {x y}, x ∈ s → y ∈ s → Icc x y ⊆ s := begin simp only [convex_iff_segment_subset, segment_eq_Icc'], split; intros h x y hx hy, { cases le_or_lt x y with hxy hxy, { simpa [hxy] using h hx hy }, { simp [hxy] } }, { apply h; cases le_total x y; simp [*] } end lemma convex_Iio (r : ℝ) : convex (Iio r) := convex_real_iff.2 $ λ x y hx hy z hz, lt_of_le_of_lt hz.2 hy lemma convex_Ioi (r : ℝ) : convex (Ioi r) := convex_real_iff.2 $ λ x y hx hy z hz, lt_of_lt_of_le hx hz.1 lemma convex_Iic (r : ℝ) : convex (Iic r) := convex_real_iff.2 $ λ x y hx hy z hz, le_trans hz.2 hy lemma convex_Ici (r : ℝ) : convex (Ici r) := convex_real_iff.2 $ λ x y hx hy z hz, le_trans hx hz.1 lemma convex_Ioo (r : ℝ) (s : ℝ) : convex (Ioo r s) := (convex_Ioi _).inter (convex_Iio _) lemma convex_Ico (r : ℝ) (s : ℝ) : convex (Ico r s) := (convex_Ici _).inter (convex_Iio _) lemma convex_Ioc (r : ℝ) (s : ℝ) : convex (Ioc r s) := (convex_Ioi _).inter (convex_Iic _) lemma convex_Icc (r : ℝ) (s : ℝ) : convex (Icc r s) := (convex_Ici _).inter (convex_Iic _) lemma convex_segment (a b : E) : convex [a, b] := begin have : (λ (t : ℝ), a + t • (b - a)) = (λz : E, a + z) ∘ (λt:ℝ, t • (b - a)) := rfl, rw [segment_eq_image', this, image_comp], refine ((convex_Icc _ _).is_linear_image _).translate _, exact is_linear_map.is_linear_map_smul' _ end lemma convex_halfspace_lt {f : E → ℝ} (h : is_linear_map ℝ f) (r : ℝ) : convex {w | f w < r} := (convex_Iio r).is_linear_preimage h lemma convex_halfspace_le {f : E → ℝ} (h : is_linear_map ℝ f) (r : ℝ) : convex {w | f w ≤ r} := (convex_Iic r).is_linear_preimage h lemma convex_halfspace_gt {f : E → ℝ} (h : is_linear_map ℝ f) (r : ℝ) : convex {w | r < f w} := (convex_Ioi r).is_linear_preimage h lemma convex_halfspace_ge {f : E → ℝ} (h : is_linear_map ℝ f) (r : ℝ) : convex {w | r ≤ f w} := (convex_Ici r).is_linear_preimage h lemma convex_hyperplane {f : E → ℝ} (h : is_linear_map ℝ f) (r : ℝ) : convex {w | f w = r} := begin show convex (f ⁻¹' {p | p = r}), rw set_of_eq_eq_singleton, exact (convex_singleton r).is_linear_preimage h end lemma convex_halfspace_re_lt (r : ℝ) : convex {c : ℂ | c.re < r} := convex_halfspace_lt (is_linear_map.mk complex.add_re complex.smul_re) _ lemma convex_halfspace_re_le (r : ℝ) : convex {c : ℂ | c.re ≤ r} := convex_halfspace_le (is_linear_map.mk complex.add_re complex.smul_re) _ lemma convex_halfspace_re_gt (r : ℝ) : convex {c : ℂ | r < c.re } := convex_halfspace_gt (is_linear_map.mk complex.add_re complex.smul_re) _ lemma convex_halfspace_re_lge (r : ℝ) : convex {c : ℂ | r ≤ c.re} := convex_halfspace_ge (is_linear_map.mk complex.add_re complex.smul_re) _ lemma convex_halfspace_im_lt (r : ℝ) : convex {c : ℂ | c.im < r} := convex_halfspace_lt (is_linear_map.mk complex.add_im complex.smul_im) _ lemma convex_halfspace_im_le (r : ℝ) : convex {c : ℂ | c.im ≤ r} := convex_halfspace_le (is_linear_map.mk complex.add_im complex.smul_im) _ lemma convex_halfspace_im_gt (r : ℝ) : convex {c : ℂ | r < c.im } := convex_halfspace_gt (is_linear_map.mk complex.add_im complex.smul_im) _ lemma convex_halfspace_im_lge (r : ℝ) : convex {c : ℂ | r ≤ c.im} := convex_halfspace_ge (is_linear_map.mk complex.add_im complex.smul_im) _ section submodule open submodule lemma submodule.convex (K : submodule ℝ E) : convex (↑K : set E) := by { repeat {intro}, refine add_mem _ (smul_mem _ _ _) (smul_mem _ _ _); assumption } lemma subspace.convex (K : subspace ℝ E) : convex (↑K : set E) := K.convex end submodule end sets section functions local notation `[`x `, ` y `]` := segment x y /-! ### Convex functions -/ /-- Convexity of functions -/ def convex_on (s : set E) (f : E → ℝ) : Prop := convex s ∧ ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → f (a • x + b • y) ≤ a * f x + b * f y lemma convex_on_id {s : set ℝ} (hs : convex s) : convex_on s id := ⟨hs, by { intros, refl }⟩ lemma convex_on_const (c : ℝ) (hs : convex s) : convex_on s (λ x:E, c) := ⟨hs, by { intros, simp only [← add_mul, *, one_mul] }⟩ variables {t : set E} {f g : E → ℝ} lemma convex_on_iff_div: convex_on s f ↔ convex s ∧ ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → 0 < a + b → f ((a/(a+b)) • x + (b/(a+b)) • y) ≤ (a/(a+b)) * f x + (b/(a+b)) * f y := and_congr iff.rfl ⟨begin intros h x y hx hy a b ha hb hab, apply h hx hy (div_nonneg ha hab) (div_nonneg hb hab), rw [←add_div], exact div_self (ne_of_gt hab) end, begin intros h x y hx hy a b ha hb hab, simpa [hab, zero_lt_one] using h hx hy ha hb, end⟩ /-- For a function on a convex set in a linear ordered space, in order to prove that it is convex it suffices to verify the inequality `f (a • x + b • y) ≤ a * f x + b * f y` only for `x < y` and positive `a`, `b`. The main use case is `E = ℝ` however one can apply it, e.g., to `ℝ^n` with lexicographic order. -/ lemma linear_order.convex_on_of_lt [linear_order E] (hs : convex s) (hf : ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → x < y → ∀ ⦃a b : ℝ⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) ≤ a * f x + b * f y) : convex_on s f := begin use hs, intros x y hx hy a b ha hb hab, wlog hxy : x<=y using [x y a b, y x b a], { exact le_total _ _ }, { cases eq_or_lt_of_le hxy with hxy hxy, by { subst y, rw [← add_smul, ← add_mul, hab, one_smul, one_mul] }, cases eq_or_lt_of_le ha with ha ha, by { subst a, rw [zero_add] at hab, subst b, simp }, cases eq_or_lt_of_le hb with hb hb, by { subst b, rw [add_zero] at hab, subst a, simp }, exact hf hx hy hxy ha hb hab } end /-- For a function `f` defined on a convex subset `D` of `ℝ`, if for any three points `x<y<z` the slope of the secant line of `f` on `[x, y]` is less than or equal to the slope of the secant line of `f` on `[x, z]`, then `f` is convex on `D`. This way of proving convexity of a function is used in the proof of convexity of a function with a monotone derivative. -/ lemma convex_on_real_of_slope_mono_adjacent {s : set ℝ} (hs : convex s) {f : ℝ → ℝ} (hf : ∀ {x y z : ℝ}, x ∈ s → z ∈ s → x < y → y < z → (f y - f x) / (y - x) ≤ (f z - f y) / (z - y)) : convex_on s f := linear_order.convex_on_of_lt hs begin assume x z hx hz hxz a b ha hb hab, let y := a * x + b * z, have hxy : x < y, { rw [← one_mul x, ← hab, add_mul], exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ }, have hyz : y < z, { rw [← one_mul z, ← hab, add_mul], exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ }, have : (f y - f x) * (z - y) ≤ (f z - f y) * (y - x), from (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz), have A : z - y + (y - x) = z - x, by abel, have B : 0 < z - x, from sub_pos.2 (lt_trans hxy hyz), rw [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, A, ← le_div_iff B, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z)] at this, rw [eq_comm, ← sub_eq_iff_eq_add] at hab; subst a, convert this; symmetry; simp only [div_eq_iff (ne_of_gt B), y]; ring end lemma convex_on.subset (h_convex_on : convex_on t f) (h_subset : s ⊆ t) (h_convex : convex s) : convex_on s f := begin apply and.intro h_convex, intros x y hx hy, exact h_convex_on.2 (h_subset hx) (h_subset hy), end lemma convex_on.add (hf : convex_on s f) (hg : convex_on s g) : convex_on s (λx, f x + g x) := begin apply and.intro hf.1, intros x y hx hy a b ha hb hab, calc f (a • x + b • y) + g (a • x + b • y) ≤ (a * f x + b * f y) + (a * g x + b * g y) : add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab) ... = a * f x + a * g x + b * f y + b * g y : by linarith ... = a * (f x + g x) + b * (f y + g y) : by simp [mul_add, add_assoc] end lemma convex_on.smul {c : ℝ} (hc : 0 ≤ c) (hf : convex_on s f) : convex_on s (λx, c * f x) := begin apply and.intro hf.1, intros x y hx hy a b ha hb hab, calc c * f (a • x + b • y) ≤ c * (a * f x + b * f y) : mul_le_mul_of_nonneg_left (hf.2 hx hy ha hb hab) hc ... = a * (c * f x) + b * (c * f y) : by rw mul_add; ac_refl end lemma convex_on.le_on_segment' {x y : E} {a b : ℝ} (hf : convex_on s f) (hx : x ∈ s) (hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : f (a • x + b • y) ≤ max (f x) (f y) := calc f (a • x + b • y) ≤ a * f x + b * f y : hf.2 hx hy ha hb hab ... ≤ a * max (f x) (f y) + b * max (f x) (f y) : add_le_add (mul_le_mul_of_nonneg_left (le_max_left _ _) ha) (mul_le_mul_of_nonneg_left (le_max_right _ _) hb) ... ≤ max (f x) (f y) : by rw [←add_mul, hab, one_mul] lemma convex_on.le_on_segment (hf : convex_on s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ [x, y]) : f z ≤ max (f x) (f y) := let ⟨a, b, ha, hb, hab, hz⟩ := hz in hz ▸ hf.le_on_segment' hx hy ha hb hab lemma convex_on.convex_le (hf : convex_on s f) (r : ℝ) : convex {x ∈ s | f x ≤ r} := convex_iff_segment_subset.2 $ λ x y hx hy z hz, ⟨hf.1.segment_subset hx.1 hy.1 hz, le_trans (hf.le_on_segment hx.1 hy.1 hz) $ max_le hx.2 hy.2⟩ lemma convex_on.convex_lt (hf : convex_on s f) (r : ℝ) : convex {x ∈ s | f x < r} := convex_iff_segment_subset.2 $ λ x y hx hy z hz, ⟨hf.1.segment_subset hx.1 hy.1 hz, lt_of_le_of_lt (hf.le_on_segment hx.1 hy.1 hz) $ max_lt hx.2 hy.2⟩ lemma convex_on.convex_epigraph (hf : convex_on s f) : convex {p : E × ℝ | p.1 ∈ s ∧ f p.1 ≤ p.2} := begin rintros ⟨x, r⟩ ⟨y, t⟩ ⟨hx, hr⟩ ⟨hy, ht⟩ a b ha hb hab, refine ⟨hf.1 hx hy ha hb hab, _⟩, calc f (a • x + b • y) ≤ a * f x + b * f y : hf.2 hx hy ha hb hab ... ≤ a * r + b * t : add_le_add (mul_le_mul_of_nonneg_left hr ha) (mul_le_mul_of_nonneg_left ht hb) end lemma convex_on_iff_convex_epigraph : convex_on s f ↔ convex {p : E × ℝ | p.1 ∈ s ∧ f p.1 ≤ p.2} := begin refine ⟨convex_on.convex_epigraph, λ h, ⟨_, _⟩⟩, { assume x y hx hy a b ha hb hab, exact (@h (x, f x) (y, f y) ⟨hx, le_refl _⟩ ⟨hy, le_refl _⟩ a b ha hb hab).1 }, { assume x y hx hy a b ha hb hab, exact (@h (x, f x) (y, f y) ⟨hx, le_refl _⟩ ⟨hy, le_refl _⟩ a b ha hb hab).2 } end end functions section center_mass /-- Center mass of a finite collection of points with prescribed weights. Note that we require neither `0 ≤ w i` nor `∑ w = 1`. -/ noncomputable def finset.center_mass (t : finset ι) (w : ι → ℝ) (z : ι → E) : E := (∑ i in t, w i)⁻¹ • (∑ i in t, w i • z i) variables (i j : ι) (c : ℝ) (t : finset ι) (w : ι → ℝ) (z : ι → E) open finset lemma finset.center_mass_empty : (∅ : finset ι).center_mass w z = 0 := by simp only [center_mass, sum_empty, smul_zero] lemma finset.center_mass_pair (hne : i ≠ j) : ({i, j} : finset ι).center_mass w z = (w i / (w i + w j)) • z i + (w j / (w i + w j)) • z j := by simp only [center_mass, sum_pair hne, smul_add, (mul_smul _ _ _).symm, div_eq_inv_mul] variable {w} lemma finset.center_mass_insert (ha : i ∉ t) (hw : ∑ j in t, w j ≠ 0) : (insert i t).center_mass w z = (w i / (w i + ∑ j in t, w j)) • z i + ((∑ j in t, w j) / (w i + ∑ j in t, w j)) • t.center_mass w z := begin simp only [center_mass, sum_insert ha, smul_add, (mul_smul _ _ _).symm], congr' 2, { apply mul_comm }, { rw [div_mul_eq_mul_div, mul_inv_cancel hw, one_div_eq_inv] } end lemma finset.center_mass_singleton (hw : w i ≠ 0) : ({i} : finset ι).center_mass w z = z i := by rw [center_mass, sum_singleton, sum_singleton, ← mul_smul, inv_mul_cancel hw, one_smul] lemma finset.center_mass_eq_of_sum_1 (hw : ∑ i in t, w i = 1) : t.center_mass w z = ∑ i in t, w i • z i := by simp only [finset.center_mass, hw, inv_one, one_smul] lemma finset.center_mass_smul : t.center_mass w (λ i, c • z i) = c • t.center_mass w z := by simp only [finset.center_mass, finset.smul_sum, (mul_smul _ _ _).symm, mul_comm c, mul_assoc] /-- A convex combination of two centers of mass is a center of mass as well. This version deals with two different index types. -/ lemma finset.center_mass_segment' (s : finset ι) (t : finset ι') (ws : ι → ℝ) (zs : ι → E) (wt : ι' → ℝ) (zt : ι' → E) (hws : ∑ i in s, ws i = 1) (hwt : ∑ i in t, wt i = 1) (a b : ℝ) (hab : a + b = 1): a • s.center_mass ws zs + b • t.center_mass wt zt = (s.image sum.inl ∪ t.image sum.inr).center_mass (sum.elim (λ i, a * ws i) (λ j, b * wt j)) (sum.elim zs zt) := begin rw [s.center_mass_eq_of_sum_1 _ hws, t.center_mass_eq_of_sum_1 _ hwt, smul_sum, smul_sum, ← finset.sum_sum_elim, finset.center_mass_eq_of_sum_1], { congr, ext ⟨⟩; simp only [sum.elim_inl, sum.elim_inr, mul_smul] }, { rw [sum_sum_elim, ← mul_sum, ← mul_sum, hws, hwt, mul_one, mul_one, hab] } end /-- A convex combination of two centers of mass is a center of mass as well. This version works if two centers of mass share the set of original points. -/ lemma finset.center_mass_segment (s : finset ι) (w₁ w₂ : ι → ℝ) (z : ι → E) (hw₁ : ∑ i in s, w₁ i = 1) (hw₂ : ∑ i in s, w₂ i = 1) (a b : ℝ) (hab : a + b = 1): a • s.center_mass w₁ z + b • s.center_mass w₂ z = s.center_mass (λ i, a * w₁ i + b * w₂ i) z := have hw : ∑ i in s, (a * w₁ i + b * w₂ i) = 1, by simp only [mul_sum.symm, sum_add_distrib, mul_one, *], by simp only [finset.center_mass_eq_of_sum_1, smul_sum, sum_add_distrib, add_smul, mul_smul, *] lemma finset.center_mass_ite_eq (hi : i ∈ t) : t.center_mass (λ j, if (i = j) then 1 else 0) z = z i := begin rw [finset.center_mass_eq_of_sum_1], transitivity ∑ j in t, if (i = j) then z i else 0, { congr, ext i, split_ifs, exacts [h ▸ one_smul _ _, zero_smul _ _] }, { rw [sum_ite_eq, if_pos hi] }, { rw [sum_ite_eq, if_pos hi] } end variables {t w} lemma finset.center_mass_subset {t' : finset ι} (ht : t ⊆ t') (h : ∀ i ∈ t', i ∉ t → w i = 0) : t.center_mass w z = t'.center_mass w z := begin rw [center_mass, sum_subset ht h, smul_sum, center_mass, smul_sum], apply sum_subset ht, assume i hit' hit, rw [h i hit' hit, zero_smul, smul_zero] end lemma finset.center_mass_filter_ne_zero : (t.filter (λ i, w i ≠ 0)).center_mass w z = t.center_mass w z := finset.center_mass_subset z (filter_subset _) $ λ i hit hit', by simpa only [hit, mem_filter, true_and, ne.def, not_not] using hit' variable {z} /-- Center mass of a finite subset of a convex set belongs to the set provided that all weights are non-negative, and the total weight is positive. -/ lemma convex.center_mass_mem (hs : convex s) : (∀ i ∈ t, 0 ≤ w i) → (0 < ∑ i in t, w i) → (∀ i ∈ t, z i ∈ s) → t.center_mass w z ∈ s := begin induction t using finset.induction with i t hi ht, { simp [lt_irrefl] }, intros h₀ hpos hmem, have zi : z i ∈ s, from hmem _ (mem_insert_self _ _), have hs₀ : ∀ j ∈ t, 0 ≤ w j, from λ j hj, h₀ j $ mem_insert_of_mem hj, rw [sum_insert hi] at hpos, by_cases hsum_t : ∑ j in t, w j = 0, { have ws : ∀ j ∈ t, w j = 0, from (sum_eq_zero_iff_of_nonneg hs₀).1 hsum_t, have wz : ∑ j in t, w j • z j = 0, from sum_eq_zero (λ i hi, by simp [ws i hi]), simp only [center_mass, sum_insert hi, wz, hsum_t, add_zero], simp only [hsum_t, add_zero] at hpos, rw [← mul_smul, inv_mul_cancel (ne_of_gt hpos), one_smul], exact zi }, { rw [finset.center_mass_insert _ _ _ hi hsum_t], refine convex_iff_div.1 hs zi (ht hs₀ _ _) _ (sum_nonneg hs₀) hpos, { exact lt_of_le_of_ne (sum_nonneg hs₀) (ne.symm hsum_t) }, { intros j hj, exact hmem j (mem_insert_of_mem hj) }, { exact h₀ _ (mem_insert_self _ _) } } end lemma convex.sum_mem (hs : convex s) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i in t, w i = 1) (hz : ∀ i ∈ t, z i ∈ s) : ∑ i in t, w i • z i ∈ s := by simpa only [h₁, center_mass, inv_one, one_smul] using hs.center_mass_mem h₀ (h₁.symm ▸ zero_lt_one) hz lemma convex_iff_sum_mem : convex s ↔ (∀ (t : finset E) (w : E → ℝ), (∀ i ∈ t, 0 ≤ w i) → ∑ i in t, w i = 1 → (∀ x ∈ t, x ∈ s) → ∑ x in t, w x • x ∈ s ) := begin refine ⟨λ hs t w hw₀ hw₁ hts, hs.sum_mem hw₀ hw₁ hts, _⟩, intros h x y hx hy a b ha hb hab, by_cases h_cases: x = y, { rw [h_cases, ←add_smul, hab, one_smul], exact hy }, { convert h {x, y} (λ z, if z = y then b else a) _ _ _, { simp only [sum_pair h_cases, if_neg h_cases, if_pos rfl] }, { simp_intros i hi, cases hi; subst i; simp [ha, hb, if_neg h_cases] }, { simp only [sum_pair h_cases, if_neg h_cases, if_pos rfl, hab] }, { simp_intros i hi, cases hi; subst i; simp [hx, hy, if_neg h_cases] } } end /-- Jensen's inequality, `finset.center_mass` version. -/ lemma convex_on.map_center_mass_le {f : E → ℝ} (hf : convex_on s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (hpos : 0 < ∑ i in t, w i) (hmem : ∀ i ∈ t, z i ∈ s) : f (t.center_mass w z) ≤ t.center_mass w (f ∘ z) := begin have hmem' : ∀ i ∈ t, (z i, (f ∘ z) i) ∈ {p : E × ℝ | p.1 ∈ s ∧ f p.1 ≤ p.2}, from λ i hi, ⟨hmem i hi, le_refl _⟩, convert (hf.convex_epigraph.center_mass_mem h₀ hpos hmem').2; simp only [center_mass, function.comp, prod.smul_fst, prod.fst_sum, prod.smul_snd, prod.snd_sum] end /-- Jensen's inequality, `finset.sum` version. -/ lemma convex_on.map_sum_le {f : E → ℝ} (hf : convex_on s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i in t, w i = 1) (hmem : ∀ i ∈ t, z i ∈ s) : f (∑ i in t, w i • z i) ≤ ∑ i in t, w i * (f (z i)) := by simpa only [center_mass, h₁, inv_one, one_smul] using hf.map_center_mass_le h₀ (h₁.symm ▸ zero_lt_one) hmem /-- If a function `f` is convex on `s` takes value `y` at the center mass of some points `z i ∈ s`, then for some `i` we have `y ≤ f (z i)`. -/ lemma convex_on.exists_ge_of_center_mass {f : E → ℝ} (h : convex_on s f) (hw₀ : ∀ i ∈ t, 0 ≤ w i) (hws : 0 < ∑ i in t, w i) (hz : ∀ i ∈ t, z i ∈ s) : ∃ i ∈ t, f (t.center_mass w z) ≤ f (z i) := begin set y := t.center_mass w z, have : f y ≤ t.center_mass w (f ∘ z) := h.map_center_mass_le hw₀ hws hz, rw ← sum_filter_ne_zero at hws, rw [← finset.center_mass_filter_ne_zero (f ∘ z), center_mass, smul_eq_mul, ← div_eq_inv_mul, le_div_iff hws, mul_sum] at this, replace : ∃ i ∈ t.filter (λ i, w i ≠ 0), f y * w i ≤ w i • (f ∘ z) i := exists_le_of_sum_le (nonempty_of_sum_ne_zero (ne_of_gt hws)) this, rcases this with ⟨i, hi, H⟩, rw [mem_filter] at hi, use [i, hi.1], simp only [smul_eq_mul, mul_comm (w i)] at H, refine (mul_le_mul_right _).1 H, exact lt_of_le_of_ne (hw₀ i hi.1) hi.2.symm end end center_mass section convex_hull variable {t : set E} /-- Convex hull of a set `s` is the minimal convex set that includes `s` -/ def convex_hull (s : set E) : set E := ⋂ (t : set E) (hst : s ⊆ t) (ht : convex t), t variable (s) lemma subset_convex_hull : s ⊆ convex_hull s := set.subset_Inter $ λ t, set.subset_Inter $ λ hst, set.subset_Inter $ λ ht, hst lemma convex_convex_hull : convex (convex_hull s) := convex_Inter $ λ t, convex_Inter $ λ ht, convex_Inter id variable {s} lemma convex_hull_min (hst : s ⊆ t) (ht : convex t) : convex_hull s ⊆ t := set.Inter_subset_of_subset t $ set.Inter_subset_of_subset hst $ set.Inter_subset _ ht lemma convex_hull_mono (hst : s ⊆ t) : convex_hull s ⊆ convex_hull t := convex_hull_min (set.subset.trans hst $ subset_convex_hull t) (convex_convex_hull t) lemma convex.convex_hull_eq {s : set E} (hs : convex s) : convex_hull s = s := set.subset.antisymm (convex_hull_min (set.subset.refl _) hs) (subset_convex_hull s) @[simp] lemma convex_hull_singleton {x : E} : convex_hull ({x} : set E) = {x} := (convex_singleton x).convex_hull_eq lemma is_linear_map.image_convex_hull {f : E → F} (hf : is_linear_map ℝ f) : f '' (convex_hull s) = convex_hull (f '' s) := begin refine set.subset.antisymm _ _, { rw [set.image_subset_iff], exact convex_hull_min (set.image_subset_iff.1 $ subset_convex_hull $ f '' s) ((convex_convex_hull (f '' s)).is_linear_preimage hf) }, { exact convex_hull_min (set.image_subset _ $ subset_convex_hull s) ((convex_convex_hull s).is_linear_image hf) } end lemma linear_map.image_convex_hull (f : E →ₗ[ℝ] F) : f '' (convex_hull s) = convex_hull (f '' s) := f.is_linear.image_convex_hull lemma finset.center_mass_mem_convex_hull (t : finset ι) {w : ι → ℝ} (hw₀ : ∀ i ∈ t, 0 ≤ w i) (hws : 0 < ∑ i in t, w i) {z : ι → E} (hz : ∀ i ∈ t, z i ∈ s) : t.center_mass w z ∈ convex_hull s := (convex_convex_hull s).center_mass_mem hw₀ hws (λ i hi, subset_convex_hull s $ hz i hi) -- TODO : Do we need other versions of the next lemma? /-- Convex hull of `s` is equal to the set of all centers of masses of `finset`s `t`, `z '' t ⊆ s`. This version allows finsets in any type in any universe. -/ lemma convex_hull_eq (s : set E) : convex_hull s = {x : E | ∃ (ι : Type u') (t : finset ι) (w : ι → ℝ) (z : ι → E) (hw₀ : ∀ i ∈ t, 0 ≤ w i) (hw₁ : ∑ i in t, w i = 1) (hz : ∀ i ∈ t, z i ∈ s) , t.center_mass w z = x} := begin refine subset.antisymm (convex_hull_min _ _) _, { intros x hx, use [punit, {punit.star}, λ _, 1, λ _, x, λ _ _, zero_le_one, finset.sum_singleton, λ _ _, hx], simp only [finset.center_mass, finset.sum_singleton, inv_one, one_smul] }, { rintros x y ⟨ι, sx, wx, zx, hwx₀, hwx₁, hzx, rfl⟩ ⟨ι', sy, wy, zy, hwy₀, hwy₁, hzy, rfl⟩ a b ha hb hab, rw [finset.center_mass_segment' _ _ _ _ _ _ hwx₁ hwy₁ _ _ hab], refine ⟨_, _, _, _, _, _, _, rfl⟩, { rintros i hi, rw [finset.mem_union, finset.mem_image, finset.mem_image] at hi, rcases hi with ⟨j, hj, rfl⟩|⟨j, hj, rfl⟩; simp only [sum.elim_inl, sum.elim_inr]; apply_rules [mul_nonneg, hwx₀, hwy₀] }, { simp [finset.sum_sum_elim, finset.mul_sum.symm, *] }, { intros i hi, rw [finset.mem_union, finset.mem_image, finset.mem_image] at hi, rcases hi with ⟨j, hj, rfl⟩|⟨j, hj, rfl⟩; simp only [sum.elim_inl, sum.elim_inr]; apply_rules [hzx, hzy] } }, { rintros _ ⟨ι, t, w, z, hw₀, hw₁, hz, rfl⟩, exact t.center_mass_mem_convex_hull hw₀ (hw₁.symm ▸ zero_lt_one) hz } end /-- Maximum principle for convex functions. If a function `f` is convex on the convex hull of `s`, then `f` can't have a maximum on `convex_hull s` outside of `s`. -/ lemma convex_on.exists_ge_of_mem_convex_hull {f : E → ℝ} (hf : convex_on (convex_hull s) f) {x} (hx : x ∈ convex_hull s) : ∃ y ∈ s, f x ≤ f y := begin rw convex_hull_eq at hx, rcases hx with ⟨α, t, w, z, hw₀, hw₁, hz, rfl⟩, rcases hf.exists_ge_of_center_mass hw₀ (hw₁.symm ▸ zero_lt_one) (λ i hi, subset_convex_hull s (hz i hi)) with ⟨i, hit, Hi⟩, exact ⟨z i, hz i hit, Hi⟩ end lemma finset.convex_hull_eq (s : finset E) : convex_hull ↑s = {x : E | ∃ (w : E → ℝ) (hw₀ : ∀ y ∈ s, 0 ≤ w y) (hw₁ : ∑ y in s, w y = 1), s.center_mass w id = x} := begin refine subset.antisymm (convex_hull_min _ _) _, { intros x hx, rw [finset.mem_coe] at hx, refine ⟨_, _, _, finset.center_mass_ite_eq _ _ _ hx⟩, { intros, split_ifs, exacts [zero_le_one, le_refl 0] }, { rw [finset.sum_ite_eq, if_pos hx] } }, { rintros x y ⟨wx, hwx₀, hwx₁, rfl⟩ ⟨wy, hwy₀, hwy₁, rfl⟩ a b ha hb hab, rw [finset.center_mass_segment _ _ _ _ hwx₁ hwy₁ _ _ hab], refine ⟨_, _, _, rfl⟩, { rintros i hi, apply_rules [add_nonneg, mul_nonneg, hwx₀, hwy₀], }, { simp only [finset.sum_add_distrib, finset.mul_sum.symm, mul_one, *] } }, { rintros _ ⟨w, hw₀, hw₁, rfl⟩, exact s.center_mass_mem_convex_hull (λ x hx, hw₀ _ hx) (hw₁.symm ▸ zero_lt_one) (λ x hx, hx) } end lemma set.finite.convex_hull_eq {s : set E} (hs : finite s) : convex_hull s = {x : E | ∃ (w : E → ℝ) (hw₀ : ∀ y ∈ s, 0 ≤ w y) (hw₁ : ∑ y in hs.to_finset, w y = 1), hs.to_finset.center_mass w id = x} := by simpa only [set.finite.coe_to_finset, set.finite.mem_to_finset, exists_prop] using hs.to_finset.convex_hull_eq lemma convex_hull_eq_union_convex_hull_finite_subsets (s : set E) : convex_hull s = ⋃ (t : finset E) (w : ↑t ⊆ s), convex_hull ↑t := begin refine subset.antisymm _ _, { rw [convex_hull_eq.{u}], rintros x ⟨ι, t, w, z, hw₀, hw₁, hz, rfl⟩, simp only [mem_Union], refine ⟨t.image z, _, _⟩, { rw [finset.coe_image, image_subset_iff], exact hz }, { apply t.center_mass_mem_convex_hull hw₀, { simp only [hw₁, zero_lt_one] }, { exact λ i hi, finset.mem_coe.2 (finset.mem_image_of_mem _ hi) } } }, { exact Union_subset (λ i, Union_subset convex_hull_mono), }, end lemma is_linear_map.convex_hull_image {f : E → F} (hf : is_linear_map ℝ f) (s : set E) : convex_hull (f '' s) = f '' convex_hull s := set.subset.antisymm (convex_hull_min (image_subset _ (subset_convex_hull s)) $ (convex_convex_hull s).is_linear_image hf) (image_subset_iff.2 $ convex_hull_min (image_subset_iff.1 $ subset_convex_hull _) ((convex_convex_hull _).is_linear_preimage hf)) lemma linear_map.convex_hull_image (f : E →ₗ[ℝ] F) (s : set E) : convex_hull (f '' s) = f '' convex_hull s := f.is_linear.convex_hull_image s end convex_hull /-! ### Simplex -/ section simplex variables (ι) [fintype ι] {f : ι → ℝ} /-- Standard simplex in the space of functions `ι → ℝ` is the set of vectors with non-negative coordinates with total sum `1`. -/ def std_simplex (ι : Type*) [fintype ι] : set (ι → ℝ) := { f | (∀ x, 0 ≤ f x) ∧ ∑ x, f x = 1 } lemma std_simplex_eq_inter : std_simplex ι = (⋂ x, {f | 0 ≤ f x}) ∩ {f | ∑ x, f x = 1} := by { ext f, simp only [std_simplex, set.mem_inter_eq, set.mem_Inter, set.mem_set_of_eq] } lemma convex_std_simplex : convex (std_simplex ι) := begin refine λ f g hf hg a b ha hb hab, ⟨λ x, _, _⟩, { apply_rules [add_nonneg, mul_nonneg, hf.1, hg.1] }, { erw [finset.sum_add_distrib, ← finset.smul_sum, ← finset.smul_sum, hf.2, hg.2, smul_eq_mul, smul_eq_mul, mul_one, mul_one], exact hab } end variable {ι} lemma ite_eq_mem_std_simplex (i : ι) : (λ j, ite (i = j) (1:ℝ) 0) ∈ std_simplex ι := ⟨λ j, by simp only []; split_ifs; norm_num, by rw [finset.sum_ite_eq, if_pos (finset.mem_univ _)] ⟩ /-- `std_simplex ι` is the convex hull of the canonical basis in `ι → ℝ`. -/ lemma convex_hull_basis_eq_std_simplex : convex_hull (range $ λ(i j:ι), if i = j then (1:ℝ) else 0) = std_simplex ι := begin refine subset.antisymm (convex_hull_min _ (convex_std_simplex ι)) _, { rintros _ ⟨i, rfl⟩, exact ite_eq_mem_std_simplex i }, { rintros w ⟨hw₀, hw₁⟩, rw [pi_eq_sum_univ w, ← finset.univ.center_mass_eq_of_sum_1 _ hw₁], exact finset.univ.center_mass_mem_convex_hull (λ i hi, hw₀ i) (hw₁.symm ▸ zero_lt_one) (λ i hi, mem_range_self i) } end variable {ι} /-- Convex hull of a finite set is the image of the standard simplex in `s → ℝ` under the linear map sending each function `w` to `∑ x in s, w x • x`. Since we have no sums over finite sets, we use sum over `@finset.univ _ hs.fintype`. The map is defined in terms of operations on `(s → ℝ) →ₗ[ℝ] ℝ` so that later we will not need to prove that this map is linear. -/ lemma set.finite.convex_hull_eq_image {s : set E} (hs : finite s) : convex_hull s = by haveI := hs.fintype; exact (⇑(∑ x : s, (@linear_map.proj ℝ s _ (λ i, ℝ) _ _ x).smul_right x.1)) '' (std_simplex s) := begin rw [← convex_hull_basis_eq_std_simplex, ← linear_map.convex_hull_image, ← range_comp, (∘)], apply congr_arg, convert (subtype.range_val s).symm, ext x, simp [linear_map.sum_apply, ite_smul, finset.filter_eq] end /-- All values of a function `f ∈ std_simplex ι` belong to `[0, 1]`. -/ lemma mem_Icc_of_mem_std_simplex (hf : f ∈ std_simplex ι) (x) : f x ∈ I := ⟨hf.1 x, hf.2 ▸ finset.single_le_sum (λ y hy, hf.1 y) (finset.mem_univ x)⟩ end simplex
63b0748f5155424156e0a930b8d742995bc01657
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/category_theory/triangulated/triangulated.lean
5c78f2f72d905d890ccd3d5658546a10fec23f22
[ "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
4,760
lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import category_theory.triangulated.pretriangulated /-! # Triangulated Categories This file contains the definition of triangulated categories, which are pretriangulated categories which satisfy the octahedron axiom. -/ noncomputable theory namespace category_theory open limits category preadditive pretriangulated open_locale zero_object variables {C : Type*} [category C] [preadditive C] [has_zero_object C] [has_shift C ℤ] [∀ (n : ℤ), functor.additive (shift_functor C n)] [pretriangulated C] variables {X₁ X₂ X₃ Z₁₂ Z₂₃ Z₁₃ : C} {u₁₂ : X₁ ⟶ X₂} {u₂₃ : X₂ ⟶ X₃} {u₁₃ : X₁ ⟶ X₃} (comm : u₁₂ ≫ u₂₃ = u₁₃) {v₁₂ : X₂ ⟶ Z₁₂} {w₁₂ : Z₁₂ ⟶ X₁⟦(1 : ℤ)⟧} (h₁₂ : triangle.mk u₁₂ v₁₂ w₁₂ ∈ dist_triang C) {v₂₃ : X₃ ⟶ Z₂₃} {w₂₃ : Z₂₃ ⟶ X₂⟦(1 : ℤ)⟧} (h₂₃ : triangle.mk u₂₃ v₂₃ w₂₃ ∈ dist_triang C) {v₁₃ : X₃ ⟶ Z₁₃} {w₁₃ : Z₁₃ ⟶ X₁⟦(1 : ℤ)⟧} (h₁₃ : triangle.mk u₁₃ v₁₃ w₁₃ ∈ dist_triang C) namespace triangulated include comm h₁₂ h₂₃ h₁₃ /-- An octahedron is a type of datum whose existence is asserted by the octahedron axiom (TR 4), see https://stacks.math.columbia.edu/tag/05QK -/ structure octahedron := (m₁ : Z₁₂ ⟶ Z₁₃) (m₃ : Z₁₃ ⟶ Z₂₃) (comm₁ : v₁₂ ≫ m₁ = u₂₃ ≫ v₁₃) (comm₂ : m₁ ≫ w₁₃ = w₁₂) (comm₃ : v₁₃ ≫ m₃ = v₂₃) (comm₄ : w₁₃ ≫ u₁₂⟦1⟧' = m₃ ≫ w₂₃) (mem : triangle.mk m₁ m₃ (w₂₃ ≫ v₁₂⟦1⟧') ∈ dist_triang C) omit comm h₁₂ h₂₃ h₁₃ instance (X : C) : nonempty (octahedron (comp_id (𝟙 X)) (contractible_distinguished X) (contractible_distinguished X) (contractible_distinguished X)) := begin refine ⟨⟨0, 0, _, _, _, _, by convert contractible_distinguished (0 : C)⟩⟩, all_goals { apply subsingleton.elim, }, end namespace octahedron attribute [reassoc] comm₁ comm₂ comm₃ comm₄ variables {comm h₁₂ h₂₃ h₁₃} (h : octahedron comm h₁₂ h₂₃ h₁₃) /-- The triangle `Z₁₂ ⟶ Z₁₃ ⟶ Z₂₃ ⟶ Z₁₂⟦1⟧` given by an octahedron. -/ @[simps] def triangle : triangle C := triangle.mk h.m₁ h.m₃ (w₂₃ ≫ v₁₂⟦1⟧') /-- The first morphism of triangles given by an octahedron. -/ @[simps] def triangle_morphism₁ : triangle.mk u₁₂ v₁₂ w₁₂ ⟶ triangle.mk u₁₃ v₁₃ w₁₃ := { hom₁ := 𝟙 X₁, hom₂ := u₂₃, hom₃ := h.m₁, comm₁' := by { dsimp, rw [id_comp, comm], }, comm₂' := h.comm₁, comm₃' := by { dsimp, simpa only [functor.map_id, comp_id] using h.comm₂.symm, }, } /-- The second morphism of triangles given an octahedron. -/ @[simps] def triangle_morphism₂ : triangle.mk u₁₃ v₁₃ w₁₃ ⟶ triangle.mk u₂₃ v₂₃ w₂₃ := { hom₁ := u₁₂, hom₂ := 𝟙 X₃, hom₃ := h.m₃, comm₁' := by { dsimp, rw [comp_id, comm], }, comm₂' := by { dsimp, rw [id_comp, h.comm₃], }, comm₃' := h.comm₄, } /- TODO (@joelriou): show that in order to verify the existence of an octahedron, one may replace the composable maps `u₁₂` and `u₂₃` by any isomorphic composable maps and the given "cones" of `u₁₂`, `u₂₃`, `u₁₃` by any choice of cones. -/ end octahedron end triangulated open triangulated variable (C) /-- A triangulated category is a pretriangulated category which satisfies the octahedron axiom (TR 4), see https://stacks.math.columbia.edu/tag/05QK -/ class is_triangulated := (octahedron_axiom : ∀ ⦃X₁ X₂ X₃ Z₁₂ Z₂₃ Z₁₃ : C⦄ ⦃u₁₂ : X₁ ⟶ X₂⦄ ⦃u₂₃ : X₂ ⟶ X₃⦄ ⦃u₁₃ : X₁ ⟶ X₃⦄ (comm : u₁₂ ≫ u₂₃ = u₁₃) ⦃v₁₂ : X₂ ⟶ Z₁₂⦄ ⦃w₁₂ : Z₁₂ ⟶ X₁⟦1⟧⦄ (h₁₂ : triangle.mk u₁₂ v₁₂ w₁₂ ∈ dist_triang C) ⦃v₂₃ : X₃ ⟶ Z₂₃⦄ ⦃w₂₃ : Z₂₃ ⟶ X₂⟦1⟧⦄ (h₂₃ : triangle.mk u₂₃ v₂₃ w₂₃ ∈ dist_triang C) ⦃v₁₃ : X₃ ⟶ Z₁₃⦄ ⦃w₁₃ : Z₁₃ ⟶ X₁⟦1⟧⦄ (h₁₃ : triangle.mk u₁₃ v₁₃ w₁₃ ∈ dist_triang C), nonempty (octahedron comm h₁₂ h₂₃ h₁₃)) namespace triangulated variable {C} /-- A choice of octahedron given by the octahedron axiom. -/ def some_octahedron [is_triangulated C] : octahedron comm h₁₂ h₂₃ h₁₃ := (is_triangulated.octahedron_axiom comm h₁₂ h₂₃ h₁₃).some end triangulated end category_theory
14e9611dcb389fb7e551411cd1bc9a772e4f03a6
a4673261e60b025e2c8c825dfa4ab9108246c32e
/stage0/src/Init/Data/Option/Basic.lean
e6b8a837bb7e5a033d7cc0d1339bd39abeb172c1
[ "Apache-2.0" ]
permissive
jcommelin/lean4
c02dec0cc32c4bccab009285475f265f17d73228
2909313475588cc20ac0436e55548a4502050d0a
refs/heads/master
1,674,129,550,893
1,606,415,348,000
1,606,415,348,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
3,043
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import Init.Core import Init.Control.Basic import Init.Coe namespace Option def toMonad [Monad m] [Alternative m] : Option α → m α | none => failure | some a => pure a @[macroInline] def getD : Option α → α → α | some x, _ => x | none, e => e @[inline] def toBool : Option α → Bool | some _ => true | none => false @[inline] def isSome : Option α → Bool | some _ => true | none => false @[inline] def isNone : Option α → Bool | some _ => false | none => true @[inline] protected def bind : Option α → (α → Option β) → Option β | none, b => none | some a, b => b a @[inline] protected def map (f : α → β) (o : Option α) : Option β := Option.bind o (some ∘ f) theorem mapId : (Option.map id : Option α → Option α) = id := funext (fun o => match o with | none => rfl | some x => rfl) instance : Monad Option := { pure := some bind := Option.bind map := Option.map } @[inline] protected def filter (p : α → Bool) : Option α → Option α | some a => if p a then some a else none | none => none @[inline] protected def all (p : α → Bool) : Option α → Bool | some a => p a | none => true @[inline] protected def any (p : α → Bool) : Option α → Bool | some a => p a | none => false @[macroInline] protected def orElse : Option α → Option α → Option α | some a, _ => some a | none, b => b /- Remark: when using the polymorphic notation `a <|> b` is not a `[macroInline]`. Thus, `a <|> b` will make `Option.orelse` to behave like it was marked as `[inline]`. -/ instance : Alternative Option := { failure := none, orElse := Option.orElse } @[inline] protected def lt (r : α → α → Prop) : Option α → Option α → Prop | none, some x => True | some x, some y => r x y | _, _ => False instance (r : α → α → Prop) [s : DecidableRel r] : DecidableRel (Option.lt r) | none, some y => isTrue trivial | some x, some y => s x y | some x, none => isFalse notFalse | none, none => isFalse notFalse end Option instance [DecidableEq α] : DecidableEq (Option α) := fun a b => match a, b with | none, none => isTrue rfl | none, (some v₂) => isFalse (fun h => Option.noConfusion h) | (some v₁), none => isFalse (fun h => Option.noConfusion h) | (some v₁), (some v₂) => match decEq v₁ v₂ with | (isTrue e) => isTrue (congrArg (@some α) e) | (isFalse n) => isFalse (fun h => Option.noConfusion h (fun e => absurd e n)) instance [BEq α] : BEq (Option α) := { beq := fun | none, none => true | none, (some v₂) => false | (some v₁), none => false | (some v₁), (some v₂) => v₁ == v₂ } instance [HasLess α] : HasLess (Option α) := { Less := Option.lt (· < ·) }
846ae07158b67225a1e0f62eaf0fab0477408123
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/algebra/category/Group/filtered_colimits.lean
ff4eaf71c84da6fc58b95383b118cc8aeaed50dc
[ "Apache-2.0" ]
permissive
robertylewis/mathlib
3d16e3e6daf5ddde182473e03a1b601d2810952c
1d13f5b932f5e40a8308e3840f96fc882fae01f0
refs/heads/master
1,651,379,945,369
1,644,276,960,000
1,644,276,960,000
98,875,504
0
0
Apache-2.0
1,644,253,514,000
1,501,495,700,000
Lean
UTF-8
Lean
false
false
8,303
lean
/- Copyright (c) 2021 Justus Springer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Justus Springer -/ import algebra.category.Group.basic import algebra.category.Mon.filtered_colimits /-! # The forgetful functor from (commutative) (additive) groups preserves filtered colimits. Forgetful functors from algebraic categories usually don't preserve colimits. However, they tend to preserve _filtered_ colimits. In this file, we start with a small filtered category `J` and a functor `F : J ⥤ Group`. We show that the colimit of `F ⋙ forget₂ Group Mon` (in `Mon`) carries the structure of a group, thereby showing that the forgetful functor `forget₂ Group Mon` preserves filtered colimits. In particular, this implies that `forget Group` preserves filtered colimits. Similarly for `AddGroup`, `CommGroup` and `AddCommGroup`. -/ universe v noncomputable theory open_locale classical open category_theory open category_theory.limits open category_theory.is_filtered (renaming max → max') -- avoid name collision with `_root_.max`. namespace Group.filtered_colimits section open Mon.filtered_colimits (colimit_one_eq colimit_mul_mk_eq) -- We use parameters here, mainly so we can have the abbreviations `G` and `G.mk` below, without -- passing around `F` all the time. parameters {J : Type v} [small_category J] [is_filtered J] (F : J ⥤ Group.{v}) /-- The colimit of `F ⋙ forget₂ Group Mon` in the category `Mon`. In the following, we will show that this has the structure of a group. -/ @[to_additive "The colimit of `F ⋙ forget₂ AddGroup AddMon` in the category `AddMon`. In the following, we will show that this has the structure of an additive group."] abbreviation G : Mon := Mon.filtered_colimits.colimit (F ⋙ forget₂ Group Mon) /-- The canonical projection into the colimit, as a quotient type. -/ @[to_additive "The canonical projection into the colimit, as a quotient type."] abbreviation G.mk : (Σ j, F.obj j) → G := quot.mk (types.quot.rel (F ⋙ forget Group)) @[to_additive] lemma G.mk_eq (x y : Σ j, F.obj j) (h : ∃ (k : J) (f : x.1 ⟶ k) (g : y.1 ⟶ k), F.map f x.2 = F.map g y.2) : G.mk x = G.mk y := quot.eqv_gen_sound (types.filtered_colimit.eqv_gen_quot_rel_of_rel (F ⋙ forget Group) x y h) /-- The "unlifted" version of taking inverses in the colimit. -/ @[to_additive "The \"unlifted\" version of negation in the colimit."] def colimit_inv_aux (x : Σ j, F.obj j) : G := G.mk ⟨x.1, x.2 ⁻¹⟩ @[to_additive] lemma colimit_inv_aux_eq_of_rel (x y : Σ j, F.obj j) (h : types.filtered_colimit.rel (F ⋙ forget Group) x y) : colimit_inv_aux x = colimit_inv_aux y := begin apply G.mk_eq, obtain ⟨k, f, g, hfg⟩ := h, use [k, f, g], rw [monoid_hom.map_inv, monoid_hom.map_inv, inv_inj], exact hfg, end /-- Taking inverses in the colimit. See also `colimit_inv_aux`. -/ @[to_additive "Negation in the colimit. See also `colimit_neg_aux`."] instance colimit_has_inv : has_inv G := { inv := λ x, begin refine quot.lift (colimit_inv_aux F) _ x, intros x y h, apply colimit_inv_aux_eq_of_rel, apply types.filtered_colimit.rel_of_quot_rel, exact h, end } @[simp, to_additive] lemma colimit_inv_mk_eq (x : Σ j, F.obj j) : (G.mk x) ⁻¹ = G.mk ⟨x.1, x.2 ⁻¹⟩ := rfl @[to_additive] instance colimit_group : group G := { mul_left_inv := λ x, begin apply quot.induction_on x, clear x, intro x, cases x with j x, erw [colimit_inv_mk_eq, colimit_mul_mk_eq (F ⋙ forget₂ Group Mon) ⟨j, _⟩ ⟨j, _⟩ j (𝟙 j) (𝟙 j), colimit_one_eq (F ⋙ forget₂ Group Mon) j], dsimp, simp only [category_theory.functor.map_id, id_apply, mul_left_inv], end, .. G.monoid, .. colimit_has_inv } /-- The bundled group giving the filtered colimit of a diagram. -/ @[to_additive "The bundled additive group giving the filtered colimit of a diagram."] def colimit : Group := Group.of G /-- The cocone over the proposed colimit group. -/ @[to_additive "The cocone over the proposed colimit additive group."] def colimit_cocone : cocone F := { X := colimit, ι := { ..(Mon.filtered_colimits.colimit_cocone (F ⋙ forget₂ Group Mon)).ι } } /-- The proposed colimit cocone is a colimit in `Group`. -/ @[to_additive "The proposed colimit cocone is a colimit in `AddGroup`."] def colimit_cocone_is_colimit : is_colimit colimit_cocone := { desc := λ t, Mon.filtered_colimits.colimit_desc (F ⋙ forget₂ Group Mon) ((forget₂ Group Mon).map_cocone t), fac' := λ t j, monoid_hom.coe_inj $ (types.colimit_cocone_is_colimit (F ⋙ forget Group)).fac ((forget Group).map_cocone t) j, uniq' := λ t m h, monoid_hom.coe_inj $ (types.colimit_cocone_is_colimit (F ⋙ forget Group)).uniq ((forget Group).map_cocone t) m ((λ j, funext $ λ x, monoid_hom.congr_fun (h j) x)) } @[to_additive forget₂_AddMon_preserves_filtered_colimits] instance forget₂_Mon_preserves_filtered_colimits : preserves_filtered_colimits (forget₂ Group Mon.{v}) := { preserves_filtered_colimits := λ J _ _, by exactI { preserves_colimit := λ F, preserves_colimit_of_preserves_colimit_cocone (colimit_cocone_is_colimit F) (Mon.filtered_colimits.colimit_cocone_is_colimit (F ⋙ forget₂ Group Mon.{v})) } } @[to_additive] instance forget_preserves_filtered_colimits : preserves_filtered_colimits (forget Group) := limits.comp_preserves_filtered_colimits (forget₂ Group Mon) (forget Mon) end end Group.filtered_colimits namespace CommGroup.filtered_colimits section -- We use parameters here, mainly so we can have the abbreviation `G` below, without -- passing around `F` all the time. parameters {J : Type v} [small_category J] [is_filtered J] (F : J ⥤ CommGroup.{v}) /-- The colimit of `F ⋙ forget₂ CommGroup Group` in the category `Group`. In the following, we will show that this has the structure of a _commutative_ group. -/ @[to_additive "The colimit of `F ⋙ forget₂ AddCommGroup AddGroup` in the category `AddGroup`. In the following, we will show that this has the structure of a _commutative_ additive group."] abbreviation G : Group := Group.filtered_colimits.colimit (F ⋙ forget₂ CommGroup Group.{v}) @[to_additive] instance colimit_comm_group : comm_group G := { ..G.group, ..CommMon.filtered_colimits.colimit_comm_monoid (F ⋙ forget₂ CommGroup CommMon.{v}) } /-- The bundled commutative group giving the filtered colimit of a diagram. -/ @[to_additive "The bundled additive commutative group giving the filtered colimit of a diagram."] def colimit : CommGroup := CommGroup.of G /-- The cocone over the proposed colimit commutative group. -/ @[to_additive "The cocone over the proposed colimit additive commutative group."] def colimit_cocone : cocone F := { X := colimit, ι := { ..(Group.filtered_colimits.colimit_cocone (F ⋙ forget₂ CommGroup Group)).ι } } /-- The proposed colimit cocone is a colimit in `CommGroup`. -/ @[to_additive "The proposed colimit cocone is a colimit in `AddCommGroup`."] def colimit_cocone_is_colimit : is_colimit colimit_cocone := { desc := λ t, (Group.filtered_colimits.colimit_cocone_is_colimit (F ⋙ forget₂ CommGroup Group.{v})).desc ((forget₂ CommGroup Group.{v}).map_cocone t), fac' := λ t j, monoid_hom.coe_inj $ (types.colimit_cocone_is_colimit (F ⋙ forget CommGroup)).fac ((forget CommGroup).map_cocone t) j, uniq' := λ t m h, monoid_hom.coe_inj $ (types.colimit_cocone_is_colimit (F ⋙ forget CommGroup)).uniq ((forget CommGroup).map_cocone t) m ((λ j, funext $ λ x, monoid_hom.congr_fun (h j) x)) } @[to_additive forget₂_AddGroup_preserves_filtered_colimits] instance forget₂_Group_preserves_filtered_colimits : preserves_filtered_colimits (forget₂ CommGroup Group.{v}) := { preserves_filtered_colimits := λ J _ _, by exactI { preserves_colimit := λ F, preserves_colimit_of_preserves_colimit_cocone (colimit_cocone_is_colimit F) (Group.filtered_colimits.colimit_cocone_is_colimit (F ⋙ forget₂ CommGroup Group.{v})) } } @[to_additive] instance forget_preserves_filtered_colimits : preserves_filtered_colimits (forget CommGroup) := limits.comp_preserves_filtered_colimits (forget₂ CommGroup Group) (forget Group) end end CommGroup.filtered_colimits
478b28e0a9f7c48884d473591fea0a9bd9fe864f
7cef822f3b952965621309e88eadf618da0c8ae9
/src/tactic/scc.lean
00d4bb2f5c7fa9d4395e6294f692c4adba40a878
[ "Apache-2.0" ]
permissive
rmitta/mathlib
8d90aee30b4db2b013e01f62c33f297d7e64a43d
883d974b608845bad30ae19e27e33c285200bf84
refs/heads/master
1,585,776,832,544
1,576,874,096,000
1,576,874,096,000
153,663,165
0
2
Apache-2.0
1,544,806,490,000
1,539,884,365,000
Lean
UTF-8
Lean
false
false
12,837
lean
/- Copyright (c) 2018 Simon Hudon All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon Tactics based on the strongly connected components (SCC) of a graph where the vertices are propositions and the edges are implications found in the context. They are used for finding the sets of equivalent propositions in a set of implications. -/ import tactic.tauto import category.basic data.sum /-! # Strongly Connected Components This file defines tactics to construct proofs of equivalences between a set of mutually equivalent propositions. The tactics use implications transitively to find sets of equivalent propositions. ## Implementation notes The tactics use a strongly connected components algorithm on a graph where propositions are vertices and edges are proofs that the source implies the target. The strongly connected components are therefore sets of propositions that are pairwise equivalent to each other. The resulting strongly connected components are encoded in a disjoint set data structure to facilitate the construction of equivalence proofs between two arbitrary members of an equivalence class. ## Possible generalizations Instead of reasoning about implications and equivalence, we could generalize the machinery to reason about arbitrary partial orders. ## References * Tarjan, R. E. (1972), "Depth-first search and linear graph algorithms", SIAM Journal on Computing, 1 (2): 146–160, doi:10.1137/0201010 * Dijkstra, Edsger (1976), A Discipline of Programming, NJ: Prentice Hall, Ch. 25. * <https://en.wikipedia.org/wiki/Disjoint-set_data_structure> ## Tags graphs, tactic, strongly connected components, disjoint sets -/ namespace tactic /-- `closure` implements a disjoint set data structure using path compression optimization. For the sake of the scc algorithm, it also stores the preorder numbering of the equivalence graph of the local assumptions. The `expr_map` encodes a directed forest by storing for every non-root node, a reference to its parent and a proof of equivalence between that node's expression and its parent's expression. Given that data structure, checking that two nodes belong to the same tree is easy and fast by repeatedly following the parent references until a root is reached. If both nodes have the same root, they belong to the same tree, i.e. their expressions are equivalent. The proof of equivalence can be formed by composing the proofs along the edges of the paths to the root. More concretely, if we ignore preorder numbering, the set `{ {e₀,e₁,e₂,e₃}, {e₄,e₅} }` is represented as: ``` e₀ → ⊥ -- no parent, i.e. e₀ is a root e₁ → e₀, p₁ -- with p₁ : e₁ ↔ e₀ e₂ → e₁, p₂ -- with p₂ : e₂ ↔ e₁ e₃ → e₀, p₃ -- with p₃ : e₃ ↔ e₀ e₄ → ⊥ -- no parent, i.e. e₄ is a root e₅ → e₄, p₅ -- with p₅ : e₅ ↔ e₄ ``` We can check that `e₂` and `e₃` are equivalent by seeking the root of the tree of each. The parent of `e₂` is `e₁`, the parent of `e₁` is `e₀` and `e₀` does not have a parent, and thus, this is the root of its tree. The parent of `e₃` is `e₀` and it's also the root, the same as for `e₂` and they are therefore equivalent. We can build a proof of that equivalence by using transitivity on `p₂`, `p₁` and `p₃.symm` in that order. Similarly, we can discover that `e₂` and `e₅` aren't equivalent. A description of the path compression optimization can be found at: <https://en.wikipedia.org/wiki/Disjoint-set_data_structure#Path_compression> -/ meta def closure := ref (expr_map (ℕ ⊕ (expr × expr))) namespace closure /-- `with_new_closure f` creates an empty `closure` `c`, executes `f` on `c`, and then deletes `c`, returning the output of `f`. -/ meta def with_new_closure {α} : (closure → tactic α) → tactic α := using_new_ref (expr_map.mk _) /-- `to_tactic_format cl` pretty-prints the `closure` `cl` as a list. Assuming `cl` was built by `dfs_at`, each element corresponds to a node `pᵢ : expr` and is one of the folllowing: - if `pᵢ` is a root: `"pᵢ ⇐ i"`, where `i` is the preorder number of `pᵢ`, - otherwise: `"(pᵢ, pⱼ) : P"`, where `P` is `pᵢ ↔ pⱼ`. Useful for debugging. -/ meta def to_tactic_format (cl : closure) : tactic format := do m ← read_ref cl, let l := m.to_list, fmt ← l.mmap $ λ ⟨x,y⟩, match y with | sum.inl y := pformat!"{x} ⇐ {y}" | sum.inr ⟨y,p⟩ := pformat!"({x}, {y}) : {infer_type p}" end, pure $ to_fmt fmt meta instance : has_to_tactic_format closure := ⟨ to_tactic_format ⟩ /-- `(n,r,p) ← root cl e` returns `r` the root of the tree that `e` is a part of (which might be itself) along with `p` a proof of `e ↔ r` and `n`, the preorder numbering of the root. -/ meta def root (cl : closure) : expr → tactic (ℕ × expr × expr) | e := do m ← read_ref cl, match m.find e with | none := do p ← mk_app ``iff.refl [e], pure (0,e,p) | (some (sum.inl n)) := do p ← mk_app ``iff.refl [e], pure (n,e,p) | (some (sum.inr (e₀,p₀))) := do (n,e₁,p₁) ← root e₀, p ← mk_app ``iff.trans [p₀,p₁], modify_ref cl $ λ m, m.insert e (sum.inr (e₁,p)), pure (n,e₁,p) end /-- (Implementation of `merge`.) -/ meta def merge_intl (cl : closure) (p e₀ p₀ e₁ p₁ : expr) : tactic unit := do p₂ ← mk_app ``iff.symm [p₀], p ← mk_app ``iff.trans [p₂,p], p ← mk_app ``iff.trans [p,p₁], modify_ref cl $ λ m, m.insert e₀ $ sum.inr (e₁,p) /-- `merge cl p`, with `p` a proof of `e₀ ↔ e₁` for some `e₀` and `e₁`, merges the trees of `e₀` and `e₁` and keeps the root with the smallest preorder number as the root. This ensures that, in the depth-first traversal of the graph, when encountering an edge going into a vertex whose equivalence class includes a vertex that originated the current search, that vertex will be the root of the corresponding tree. -/ meta def merge (cl : closure) (p : expr) : tactic unit := do `(%%e₀ ↔ %%e₁) ← infer_type p >>= instantiate_mvars, (n₂,e₂,p₂) ← root cl e₀, (n₃,e₃,p₃) ← root cl e₁, if e₂ ≠ e₃ then do if n₂ < n₃ then do p ← mk_app ``iff.symm [p], cl.merge_intl p e₃ p₃ e₂ p₂ else cl.merge_intl p e₂ p₂ e₃ p₃ else pure () /-- Sequentially assign numbers to the nodes of the graph as they are being visited. -/ meta def assign_preorder (cl : closure) (e : expr) : tactic unit := modify_ref cl $ λ m, m.insert e (sum.inl m.size) /-- `prove_eqv cl e₀ e₁` constructs a proof of equivalence of `e₀` and `e₁` if they are equivalent. -/ meta def prove_eqv (cl : closure) (e₀ e₁ : expr) : tactic expr := do (_,r,p₀) ← root cl e₀, (_,r',p₁) ← root cl e₁, guard (r = r') <|> fail!"{e₀} and {e₁} are not equivalent", p₁ ← mk_app ``iff.symm [p₁], mk_app ``iff.trans [p₀,p₁] /-- `prove_impl cl e₀ e₁` constructs a proof of `e₀ -> e₁` if they are equivalent. -/ meta def prove_impl (cl : closure) (e₀ e₁ : expr) : tactic expr := cl.prove_eqv e₀ e₁ >>= iff_mp /-- `is_eqv cl e₀ e₁` checks whether `e₀` and `e₁` are equivalent without building a proof. -/ meta def is_eqv (cl : closure) (e₀ e₁ : expr) : tactic bool := do (_,r,p₀) ← root cl e₀, (_,r',p₁) ← root cl e₁, return $ r = r' end closure /-- mutable graphs between local propositions that imply each other with the proof of implication -/ @[reducible] meta def impl_graph := ref (expr_map (list $ expr × expr)) /-- `with_impl_graph f` creates an empty `impl_graph` `g`, executes `f` on `g`, and then deletes `g`, returning the output of `f`. -/ meta def with_impl_graph {α} : (impl_graph → tactic α) → tactic α := using_new_ref (expr_map.mk (list $ expr × expr)) namespace impl_graph /-- `add_edge g p`, with `p` a proof of `v₀ → v₁` or `v₀ ↔ v₁`, adds an edge to the implication graph `g`. -/ meta def add_edge (g : impl_graph) : expr → tactic unit | p := do t ← infer_type p, match t with | `(%%v₀ → %%v₁) := do m ← read_ref g, let xs := (m.find v₀).get_or_else [], let xs' := (m.find v₁).get_or_else [], modify_ref g $ λ m, (m.insert v₀ ((v₁,p) :: xs)).insert v₁ xs' | `(%%v₀ ↔ %%v₁) := do p₀ ← mk_mapp ``iff.mp [none,none,p], p₁ ← mk_mapp ``iff.mpr [none,none,p], add_edge p₀, add_edge p₁ | _ := failed end section scc open list parameter g : expr_map (list $ expr × expr) parameter visit : ref $ expr_map bool parameter cl : closure /-- `merge_path path e`, where `path` and `e` forms a cycle with proofs of implication between consecutive vertices. The proofs are compiled into proofs of equivalences and added to the closure structure. `e` and the first vertex of `path` do not have to be the same but they have to be in the same equivalence class. -/ meta def merge_path (path : list (expr × expr)) (e : expr) : tactic unit := do p₁ ← cl.prove_impl e path.head.fst, p₂ ← mk_mapp ``id [e], let path := (e,p₁) :: path, (_,ls) ← path.mmap_accuml (λ p p', prod.mk <$> mk_mapp ``implies.trans [none,p'.1,none,p,p'.2] <*> pure p) p₂, (_,rs) ← path.mmap_accumr (λ p p', prod.mk <$> mk_mapp ``implies.trans [none,none,none,p.2,p'] <*> pure p') p₂, ps ← mzip_with (λ p₀ p₁, mk_app ``iff.intro [p₀,p₁]) ls.tail rs.init, ps.mmap' cl.merge /-- (implementation of `collapse`) -/ meta def collapse' : list (expr × expr) → list (expr × expr) → expr → tactic unit | acc [] v := merge_path acc v | acc ((x,pr) :: xs) v := do b ← cl.is_eqv x v, let acc' := (x,pr)::acc, if b then merge_path acc' v else collapse' acc' xs v /-- `collapse path v`, where `v` is a vertex that originated the current search (or a vertex in the same equivalence class as the one that originated the current search). It or its equivalent should be found in `path`. Since the vertices following `v` in the path form a cycle with `v`, they can all be added to an equivalence class. -/ meta def collapse : list (expr × expr) → expr → tactic unit := collapse' [] /-- Strongly connected component algorithm inspired by Tarjan's and Dijkstra's scc algorithm. Whereas they return strongly connected components by enumerating them, this algorithm returns a disjoint set data structure using path compression. This is a compact representation that allows us, after the fact, to construct a proof of equivalence between any two members of an equivalence class. * Tarjan, R. E. (1972), "Depth-first search and linear graph algorithms", SIAM Journal on Computing, 1 (2): 146–160, doi:10.1137/0201010 * Dijkstra, Edsger (1976), A Discipline of Programming, NJ: Prentice Hall, Ch. 25. -/ meta def dfs_at : list (expr × expr) → expr → tactic unit | vs v := do m ← read_ref visit, (_,v',_) ← cl.root v, match m.find v' with | (some tt) := pure () | (some ff) := collapse vs v | none := do cl.assign_preorder v, modify_ref visit $ λ m, m.insert v ff, ns ← g.find v, ns.mmap' $ λ ⟨w,e⟩, dfs_at ((v,e) :: vs) w, modify_ref visit $ λ m, m.insert v tt, pure () end end scc /-- Use the local assumptions to create a set of equivalence classes. -/ meta def mk_scc (cl : closure) : tactic (expr_map (list (expr × expr))) := with_impl_graph $ λ g, using_new_ref (expr_map.mk bool) $ λ visit, do ls ← local_context, ls.mmap' $ λ l, try (g.add_edge l), m ← read_ref g, m.to_list.mmap $ λ ⟨v,_⟩, impl_graph.dfs_at m visit cl [] v, pure m end impl_graph meta def prove_eqv_target (cl : closure) : tactic unit := do `(%%p ↔ %%q) ← target >>= whnf, cl.prove_eqv p q >>= exact /-- Use the available equivalences and implications to prove a goal of the form `p ↔ q`. -/ meta def interactive.scc : tactic unit := closure.with_new_closure $ λ cl, do impl_graph.mk_scc cl, `(%%p ↔ %%q) ← target, cl.prove_eqv p q >>= exact /-- Collect all the available equivalences and implications and add assumptions for every equivalence that can be proven using the strongly connected components technique. Mostly useful for testing. -/ meta def interactive.scc' : tactic unit := closure.with_new_closure $ λ cl, do m ← impl_graph.mk_scc cl, let ls := m.to_list.map prod.fst, let ls' := prod.mk <$> ls <*> ls, ls'.mmap' $ λ x, do { h ← get_unused_name `h, try $ closure.prove_eqv cl x.1 x.2 >>= note h none } end tactic
d7d84677fd317e19cd1ee0591ea608a6d9a59c56
e0f9ba56b7fedc16ef8697f6caeef5898b435143
/src/order/complete_lattice.lean
9620ee88ec18bf9966cabc78f6d87d5f20936d64
[ "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
35,989
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 Theory of complete lattices. -/ import order.bounds set_option old_structure_cmd true open set universes u v w w₂ variables {α : Type u} {β : Type v} {ι : Sort w} {ι₂ : Sort w₂} /-- class for the `Sup` operator -/ class has_Sup (α : Type u) := (Sup : set α → α) /-- class for the `Inf` operator -/ class has_Inf (α : Type u) := (Inf : set α → α) /-- Supremum of a set -/ def Sup [has_Sup α] : set α → α := has_Sup.Sup /-- Infimum of a set -/ def Inf [has_Inf α] : set α → α := has_Inf.Inf /-- Indexed supremum -/ def supr [has_Sup α] (s : ι → α) : α := Sup (range s) /-- Indexed infimum -/ def infi [has_Inf α] (s : ι → α) : α := Inf (range s) lemma has_Inf_to_nonempty (α) [has_Inf α] : nonempty α := ⟨Inf ∅⟩ lemma has_Sup_to_nonempty (α) [has_Sup α] : nonempty α := ⟨Sup ∅⟩ notation `⨆` binders `, ` r:(scoped f, supr f) := r notation `⨅` binders `, ` r:(scoped f, infi f) := r section prio set_option default_priority 100 -- see Note [default priority] /-- A complete lattice is a bounded lattice which has suprema and infima for every subset. -/ class complete_lattice (α : Type u) extends bounded_lattice α, has_Sup α, has_Inf α := (le_Sup : ∀s, ∀a∈s, a ≤ Sup s) (Sup_le : ∀s a, (∀b∈s, b ≤ a) → Sup s ≤ a) (Inf_le : ∀s, ∀a∈s, Inf s ≤ a) (le_Inf : ∀s a, (∀b∈s, a ≤ b) → a ≤ Inf s) /-- 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, so it should be used with `.. complete_lattice_of_Inf α _`. -/ def complete_lattice_of_Inf (α : Type u) [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 _ _, inf_le_left := λ a b, (is_glb_Inf _).1 $ mem_insert_of_mem _ $ mem_singleton _, 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 } /-- A complete linear order is a linear order whose lattice structure is complete. -/ class complete_linear_order (α : Type u) extends complete_lattice α, decidable_linear_order α end prio section variables [complete_lattice α] {s t : set α} {a b : α} @[ematch] theorem le_Sup : a ∈ s → a ≤ Sup s := complete_lattice.le_Sup s a theorem Sup_le : (∀b∈s, b ≤ a) → Sup s ≤ a := complete_lattice.Sup_le s a @[ematch] theorem Inf_le : a ∈ s → Inf s ≤ a := complete_lattice.Inf_le s a theorem le_Inf : (∀b∈s, a ≤ b) → a ≤ Inf s := complete_lattice.le_Inf 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 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 le_Sup_of_le (hb : b ∈ s) (h : a ≤ b) : a ≤ Sup s := le_trans h (le_Sup hb) theorem Inf_le_of_le (hb : b ∈ s) (h : b ≤ a) : Inf s ≤ a := le_trans (Inf_le hb) h theorem Sup_le_Sup (h : s ⊆ t) : Sup s ≤ Sup t := Sup_le (assume a, assume ha : a ∈ s, le_Sup $ h ha) theorem Inf_le_Inf (h : s ⊆ t) : Inf t ≤ Inf s := le_Inf (assume a, assume ha : a ∈ s, Inf_le $ h ha) @[simp] theorem Sup_le_iff : Sup s ≤ a ↔ (∀b ∈ s, b ≤ a) := is_lub_le_iff (is_lub_Sup s) @[simp] theorem le_Inf_iff : a ≤ Inf s ↔ (∀b ∈ s, a ≤ b) := le_is_glb_iff (is_glb_Inf s) 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 -- TODO: it is weird that we have to add union_def 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) := by finish /- le_Inf (assume a ⟨a_s, a_t⟩, sup_le (Inf_le a_s) (Inf_le a_t)) -/ @[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 -- We will generalize this to conditionally complete lattices in `cSup_singleton`. theorem Sup_singleton {a : α} : Sup {a} = a := is_lub_singleton.Sup_eq -- We will generalize this to conditionally complete lattices in `cInf_singleton`. theorem Inf_singleton {a : α} : Inf {a} = a := is_glb_singleton.Inf_eq 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) @[simp] theorem Sup_eq_bot : Sup s = ⊥ ↔ (∀a∈s, a = ⊥) := iff.intro (assume h a ha, bot_unique $ h ▸ le_Sup ha) (assume h, bot_unique $ Sup_le $ assume a ha, le_bot_iff.2 $ h a ha) 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) := iff.intro (assume (h : Inf s = ⊥) b (hb : ⊥ < b), by rwa [←h, Inf_lt_iff] at hb) (assume h, bot_unique $ le_of_not_gt $ assume h', let ⟨a, ha, h⟩ := h _ h' in lt_irrefl a $ lt_of_lt_of_le h (Inf_le ha)) lemma lt_supr_iff {ι : Sort*} {f : ι → α} : a < supr f ↔ (∃i, a < f i) := lt_Sup_iff.trans exists_range_iff lemma infi_lt_iff {ι : Sort*} {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 supr_le (h : ∀i, s i ≤ a) : supr s ≤ a := Sup_le $ assume b ⟨i, eq⟩, eq ▸ h 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 supr_le_supr_const (h : ι → ι₂) : (⨆ i:ι, a) ≤ (⨆ j:ι₂, a) := supr_le $ le_supr _ ∘ h @[simp] theorem supr_le_iff : supr s ≤ a ↔ (∀i, s i ≤ a) := (is_lub_le_iff is_lub_supr).trans forall_range_iff 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 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) -- TODO: finish doesn't do well here. @[congr] theorem supr_congr_Prop {α : Type u} [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 unfold supr, apply congr_arg, ext, simp, split, exact λ⟨h, W⟩, ⟨pq.1 h, eq.trans (f (pq.1 h)).symm W⟩, exact λ⟨h, W⟩, ⟨pq.2 h, eq.trans (f h) W⟩ 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⟩ /- I wanted to see if this would help for infi_comm; it doesn't. @[ematch] theorem infi_le₂' (s : ι → ι₂ → α) (i : ι) (j : ι₂) : (: ⨅ i j, s i j :) ≤ (: s i j :) := begin transitivity, apply (infi_le (λ i, ⨅ j, s i j) i), apply infi_le end -/ theorem infi_le_of_le (i : ι) (h : s i ≤ a) : infi s ≤ a := le_trans (infi_le _ i) h theorem le_infi (h : ∀i, a ≤ s i) : a ≤ infi s := le_Inf $ assume b ⟨i, eq⟩, eq ▸ h 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 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⟩ 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)) := calc f (⨅ i (h : ι' i), s i h) ≤ (⨅ i, f (⨅ h, s i h)) : hf.map_infi_le ... ≤ (⨅ i h, f (s i h)) : infi_le_infi $ λ i, hf.map_infi_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 _ _) @[congr] theorem infi_congr_Prop {α : Type u} [has_Inf α] {p q : Prop} {f₁ : p → α} {f₂ : q → α} (pq : p ↔ q) (f : ∀x, f₁ (pq.mpr x) = f₂ x) : infi f₁ = infi f₂ := begin unfold infi, apply congr_arg, ext, simp, split, exact λ⟨h, W⟩, ⟨pq.1 h, eq.trans (f (pq.1 h)).symm W⟩, exact λ⟨h, W⟩, ⟨pq.2 h, eq.trans (f h) W⟩ end -- 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 := by rw [supr, range_const, Sup_singleton] @[simp] lemma infi_top : (⨅i:ι, ⊤ : α) = ⊤ := top_unique $ le_infi $ assume i, le_refl _ @[simp] lemma supr_bot : (⨆i:ι, ⊥ : α) = ⊥ := bot_unique $ supr_le $ assume i, le_refl _ @[simp] lemma infi_eq_top : infi s = ⊤ ↔ (∀i, s i = ⊤) := iff.intro (assume eq i, top_unique $ eq ▸ infi_le _ _) (assume h, top_unique $ le_infi $ assume i, top_le_iff.2 $ h i) @[simp] lemma supr_eq_bot : supr s = ⊥ ↔ (∀i, s i = ⊥) := iff.intro (assume eq i, bot_unique $ eq ▸ le_supr _ _) (assume h, bot_unique $ supr_le $ assume i, le_bot_iff.2 $ h i) @[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 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 ⊥) := by rw [supr_eq_dif, dif_eq_if] lemma infi_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 infi_eq_if {p : Prop} [decidable p] (a : α) : (⨅h:p, a) = (if p then a else ⊤) := by rw [infi_eq_dif, dif_eq_if] -- 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) := le_antisymm (supr_le $ assume i, supr_le $ assume j, le_supr_of_le j $ le_supr _ i) (supr_le $ assume j, supr_le $ assume i, le_supr_of_le i $ le_supr _ j) @[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 := le_antisymm (supr_le $ assume b', supr_le $ assume eq, match b', eq with ._, rfl := le_refl _ end) (le_supr_of_le b $ le_supr _ rfl) @[simp] theorem supr_supr_eq_right {b : β} {f : Πx:β, b = x → α} : (⨆x, ⨆h : b = x, f x h) = f b rfl := le_antisymm (supr_le $ assume b', supr_le $ assume eq, match b', eq with ._, rfl := le_refl _ end) (le_supr_of_le b $ le_supr _ rfl) attribute [ematch] le_refl 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_left_of_le $ infi_le _ _) (inf_le_right_of_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 {f : ι → α} {a : α} (i : ι) : (⨅x, f x) ⊓ a = (⨅ x, f x ⊓ a) := le_antisymm (le_infi $ assume i, le_inf (inf_le_left_of_le $ infi_le _ _) inf_le_right) (le_inf (infi_le_infi $ assume i, inf_le_left) (infi_le_of_le i inf_le_right)) lemma inf_infi {f : ι → α} {a : α} (i : ι) : a ⊓ (⨅x, f x) = (⨅ x, a ⊓ f x) := by rw [inf_comm, infi_inf i]; simp [inf_comm] lemma binfi_inf {ι : Sort*} {p : ι → Prop} {f : Πi, p i → α} {a : α} {i : ι} (hi : p i) : (⨅i (h : p i), f i h) ⊓ a = (⨅ i (h : p i), f i h ⊓ a) := le_antisymm (le_infi $ assume i, le_infi $ assume hi, le_inf (inf_le_left_of_le $ infi_le_of_le i $ infi_le _ _) inf_le_right) (le_inf (infi_le_infi $ assume i, infi_le_infi $ assume hi, inf_le_left) (infi_le_of_le i $ infi_le_of_le hi $ inf_le_right)) theorem supr_sup_eq {f g : β → α} : (⨆ x, f x ⊔ g x) = (⨆ x, f x) ⊔ (⨆ x, g x) := le_antisymm (supr_le $ assume i, sup_le (le_sup_left_of_le $ le_supr _ _) (le_sup_right_of_le $ le_supr _ _)) (sup_le (supr_le $ assume i, le_supr_of_le i le_sup_left) (supr_le $ assume i, le_supr_of_le i le_sup_right)) /- 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 @[simp] theorem infi_true {s : true → α} : infi s = s trivial := le_antisymm (infi_le _ _) (le_infi $ assume ⟨⟩, le_refl _) @[simp] theorem supr_true {s : true → α} : supr s = s trivial := le_antisymm (supr_le $ assume ⟨⟩, le_refl _) (le_supr _ _) @[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⟩) := le_antisymm (supr_le $ assume ⟨i, h⟩, le_supr_of_le i $ le_supr (λh:p i, f ⟨i, h⟩) _) (supr_le $ assume i, supr_le $ assume : p i, le_supr _ _) 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 _ _) theorem supr_and {p q : Prop} {s : p ∧ q → α} : supr s = (⨆ h₁ h₂, s ⟨h₁, h₂⟩) := le_antisymm (supr_le $ assume ⟨i, h⟩, le_supr_of_le i $ le_supr (λj, s ⟨i, j⟩) _) (supr_le $ assume i, supr_le $ assume j, le_supr _ _) 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_left_of_le $ infi_le _ _ | or.inr j := inf_le_right_of_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)) := le_antisymm (supr_le $ assume s, match s with | or.inl i := le_sup_left_of_le $ le_supr _ i | or.inr j := le_sup_right_of_le $ le_supr _ j end) (sup_le (supr_le_supr2 $ assume i, ⟨or.inl i, le_refl _⟩) (supr_le_supr2 $ assume j, ⟨or.inr j, le_refl _⟩)) theorem Inf_eq_infi {s : set α} : Inf s = (⨅a ∈ s, a) := le_antisymm (le_infi $ assume b, le_infi $ assume h, Inf_le h) (le_Inf $ assume b h, infi_le_of_le b $ infi_le _ h) 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_range {α : Type u} [has_Sup α] {f : ι → α} : Sup (range f) = supr f := rfl lemma Inf_range {α : Type u} [has_Inf α] {f : ι → α} : Inf (range f) = infi f := rfl lemma supr_range {g : β → α} {f : ι → β} : (⨆b∈range f, g b) = (⨆i, g (f i)) := le_antisymm (supr_le $ assume b, supr_le $ assume ⟨i, (h : f i = b)⟩, h ▸ le_supr _ i) (supr_le $ assume i, le_supr_of_le (f i) $ le_supr (λp, g (f i)) (mem_range_self _)) lemma infi_range {g : β → α} {f : ι → β} : (⨅b∈range f, g b) = (⨅i, g (f i)) := le_antisymm (le_infi $ assume i, infi_le_of_le (f i) $ infi_le (λp, g (f i)) (mem_range_self _)) (le_infi $ assume b, le_infi $ assume ⟨i, (h : f i = b)⟩, h ▸ infi_le _ i) theorem Inf_image {s : set β} {f : β → α} : Inf (f '' s) = (⨅ a ∈ s, f a) := calc Inf (set.image f s) = (⨅a, ⨅h : ∃b, b ∈ s ∧ f b = a, a) : Inf_eq_infi ... = (⨅a, ⨅b, ⨅h : f b = a ∧ b ∈ s, a) : by simp [and_comm] ... = (⨅a, ⨅b, ⨅h : a = f b, ⨅h : b ∈ s, a) : by simp [infi_and, eq_comm] ... = (⨅b, ⨅a, ⨅h : a = f b, ⨅h : b ∈ s, a) : by rw [infi_comm] ... = (⨅a∈s, f a) : congr_arg infi $ by funext x; rw [infi_infi_eq_left] theorem Sup_image {s : set β} {f : β → α} : Sup (f '' s) = (⨆ a ∈ s, f a) := calc Sup (set.image f s) = (⨆a, ⨆h : ∃b, b ∈ s ∧ f b = a, a) : Sup_eq_supr ... = (⨆a, ⨆b, ⨆h : f b = a ∧ b ∈ s, a) : by simp [and_comm] ... = (⨆a, ⨆b, ⨆h : a = f b, ⨆h : b ∈ s, a) : by simp [supr_and, eq_comm] ... = (⨆b, ⨆a, ⨆h : a = f b, ⨆h : b ∈ s, a) : by rw [supr_comm] ... = (⨆a∈s, f a) : congr_arg supr $ by funext x; rw [supr_supr_eq_left] /- 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) := calc (⨅ x ∈ s ∪ t, f x) = (⨅ x, (⨅h : x∈s, f x) ⊓ (⨅h : x∈t, f x)) : congr_arg infi $ funext $ assume x, infi_or ... = (⨅x∈s, f x) ⊓ (⨅x∈t, f x) : infi_inf_eq 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) := calc (⨆ x ∈ s ∪ t, f x) = (⨆ x, (⨆h : x∈s, f x) ⊔ (⨆h : x∈t, f x)) : congr_arg supr $ funext $ assume x, supr_or ... = (⨆x∈s, f x) ⊔ (⨆x∈t, f x) : supr_sup_eq theorem supr_le_supr_of_subset {f : β → α} {s t : set β} (h : s ⊆ t) : (⨆ x ∈ s, f x) ≤ (⨆ x ∈ t, f x) := by rw [(union_eq_self_of_subset_left h).symm, supr_union]; exact le_sup_left 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 [show {a, b} = (insert b {a} : set β), from rfl, infi_insert, inf_comm], simp } theorem supr_singleton {f : β → α} {b : β} : (⨆ x ∈ (singleton b : set β), f x) = f b := by simp theorem supr_pair {f : β → α} {a b : β} : (⨆ x ∈ ({a, b} : set β), f x) = f a ⊔ f b := by { rw [show {a, b} = (insert b {a} : set β), from rfl, supr_insert, sup_comm], simp } lemma infi_image {γ} {f : β → γ} {g : γ → α} {t : set β} : (⨅ c ∈ f '' t, g c) = (⨅ b ∈ t, g (f b)) := le_antisymm (le_infi $ assume b, le_infi $ assume hbt, infi_le_of_le (f b) $ infi_le (λ_, g (f b)) (mem_image_of_mem f hbt)) (le_infi $ assume c, le_infi $ assume ⟨b, hbt, eq⟩, eq ▸ infi_le_of_le b $ infi_le (λ_, g (f b)) hbt) lemma supr_image {γ} {f : β → γ} {g : γ → α} {t : set β} : (⨆ c ∈ f '' t, g c) = (⨆ b ∈ t, g (f b)) := le_antisymm (supr_le $ assume c, supr_le $ assume ⟨b, hbt, eq⟩, eq ▸ le_supr_of_le b $ le_supr (λ_, g (f b)) hbt) (supr_le $ assume b, supr_le $ assume hbt, le_supr_of_le (f b) $ le_supr (λ_, g (f b)) (mem_image_of_mem f hbt)) /- supr and infi under Type -/ @[simp] theorem infi_empty {s : empty → α} : infi s = ⊤ := le_antisymm le_top (le_infi $ assume i, empty.rec_on _ i) @[simp] theorem supr_empty {s : empty → α} : supr s = ⊥ := le_antisymm (supr_le $ assume i, empty.rec_on _ i) bot_le @[simp] theorem infi_unit {f : unit → α} : (⨅ x, f x) = f () := le_antisymm (infi_le _ _) (le_infi $ assume ⟨⟩, le_refl _) @[simp] theorem supr_unit {f : unit → α} : (⨆ x, f x) = f () := le_antisymm (supr_le $ assume ⟨⟩, le_refl _) (le_supr _ _) lemma supr_bool_eq {f : bool → α} : (⨆b:bool, f b) = f tt ⊔ f ff := le_antisymm (supr_le $ assume b, match b with tt := le_sup_left | ff := le_sup_right end) (sup_le (le_supr _ _) (le_supr _ _)) lemma infi_bool_eq {f : bool → α} : (⨅b:bool, f b) = f tt ⊓ f ff := le_antisymm (le_inf (infi_le _ _) (infi_le _ _)) (le_infi $ assume b, match b with tt := inf_le_left | ff := inf_le_right end) 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.val 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 lemma is_glb_binfi {s : set β} {f : β → α} : is_glb (f '' s) (⨅ x ∈ s, f x) := by simpa only [range_comp, subtype.range_val, infi_subtype'] using @is_glb_infi α s _ (f ∘ subtype.val) theorem supr_subtype {p : ι → Prop} {f : subtype p → α} : (⨆ x, f x) = (⨆ i (h:p i), f ⟨i, h⟩) := le_antisymm (supr_le $ assume ⟨i, h⟩, le_supr_of_le i $ le_supr (λh:p i, f ⟨i, h⟩) _) (supr_le $ assume i, supr_le $ assume : p i, le_supr _ _) lemma supr_subtype' {p : ι → Prop} {f : ∀ i, p i → α} : (⨆ i (h : p i), f i h) = (⨆ x : subtype p, f x.val x.property) := (@supr_subtype _ _ _ p (λ x, f x.val x.property)).symm lemma is_lub_bsupr {s : set β} {f : β → α} : is_lub (f '' s) (⨆ x ∈ s, f x) := by simpa only [range_comp, subtype.range_val, supr_subtype'] using @is_lub_supr α s _ (f ∘ subtype.val) theorem infi_sigma {p : β → Type w} {f : sigma 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 _ _) theorem supr_sigma {p : β → Type w} {f : sigma p → α} : (⨆ x, f x) = (⨆ i (h:p i), f ⟨i, h⟩) := le_antisymm (supr_le $ assume ⟨i, h⟩, le_supr_of_le i $ le_supr (λh:p i, f ⟨i, h⟩) _) (supr_le $ assume i, supr_le $ assume : p i, le_supr _ _) theorem infi_prod {γ : Type w} {f : β × γ → α} : (⨅ x, f x) = (⨅ i j, f (i, j)) := le_antisymm (le_infi $ assume i, le_infi $ assume j, infi_le _ _) (le_infi $ assume ⟨i, h⟩, infi_le_of_le i $ infi_le _ _) theorem supr_prod {γ : Type w} {f : β × γ → α} : (⨆ x, f x) = (⨆ i j, f (i, j)) := le_antisymm (supr_le $ assume ⟨i, h⟩, le_supr_of_le i $ le_supr (λj, f ⟨i, j⟩) _) (supr_le $ assume i, supr_le $ assume j, le_supr _ _) theorem infi_sum {γ : Type w} {f : β ⊕ γ → α} : (⨅ x, f x) = (⨅ i, f (sum.inl i)) ⊓ (⨅ j, f (sum.inr j)) := le_antisymm (le_inf (infi_le_infi2 $ assume i, ⟨_, le_refl _⟩) (infi_le_infi2 $ assume j, ⟨_, le_refl _⟩)) (le_infi $ assume s, match s with | sum.inl i := inf_le_left_of_le $ infi_le _ _ | sum.inr j := inf_le_right_of_le $ infi_le _ _ end) theorem supr_sum {γ : Type w} {f : β ⊕ γ → α} : (⨆ x, f x) = (⨆ i, f (sum.inl i)) ⊔ (⨆ j, f (sum.inr j)) := le_antisymm (supr_le $ assume s, match s with | sum.inl i := le_sup_left_of_le $ le_supr _ i | sum.inr j := le_sup_right_of_le $ le_supr _ j end) (sup_le (supr_le_supr2 $ assume i, ⟨sum.inl i, le_refl _⟩) (supr_le_supr2 $ assume j, ⟨sum.inr j, le_refl _⟩)) end section complete_linear_order variables [complete_linear_order α] lemma supr_eq_top (f : ι → α) : supr f = ⊤ ↔ (∀b<⊤, ∃i, b < f i) := by rw [← Sup_range, Sup_eq_top]; from forall_congr (assume b, forall_congr (assume hb, set.exists_range_iff)) lemma infi_eq_bot (f : ι → α) : infi f = ⊥ ↔ (∀b>⊥, ∃i, b > f i) := by rw [← Inf_range, Inf_eq_bot]; from forall_congr (assume b, forall_congr (assume hb, set.exists_range_iff)) end complete_linear_order /- Instances -/ instance complete_lattice_Prop : 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, ..bounded_lattice_Prop } lemma Inf_Prop_eq {s : set Prop} : Inf s = (∀p ∈ s, p) := rfl lemma Sup_Prop_eq {s : set Prop} : Sup s = (∃p ∈ s, p) := rfl 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) lemma supr_Prop_eq {ι : Sort*} {p : ι → Prop} : (⨆i, p i) = (∃i, p i) := le_antisymm (assume ⟨q, ⟨i, (eq : p i = q)⟩, hq⟩, ⟨i, eq.symm ▸ hq⟩) (assume ⟨i, hi⟩, ⟨p i, ⟨i, rfl⟩, hi⟩) instance pi.complete_lattice {α : Type u} {β : α → Type v} [∀ i, complete_lattice (β i)] : complete_lattice (Π i, β i) := by { pi_instance; { intros, intro, apply_field, intros, simp at H, rcases H with ⟨ x, H₀, H₁ ⟩, subst b, apply a_1 _ H₀ i, } } lemma Inf_apply {α : Type u} {β : α → Type v} [∀ i, complete_lattice (β i)] {s : set (Πa, β a)} {a : α} : (Inf s) a = (⨅f∈s, (f : Πa, β a) a) := by rw [← Inf_image]; refl lemma infi_apply {α : Type u} {β : α → Type v} {ι : Sort*} [∀ i, complete_lattice (β i)] {f : ι → Πa, β a} {a : α} : (⨅i, f i) a = (⨅i, f i a) := by erw [← Inf_range, Inf_apply, infi_range] lemma Sup_apply {α : Type u} {β : α → Type v} [∀ i, complete_lattice (β i)] {s : set (Πa, β a)} {a : α} : (Sup s) a = (⨆f∈s, (f : Πa, β a) a) := by rw [← Sup_image]; refl lemma supr_apply {α : Type u} {β : α → Type v} {ι : Sort*} [∀ i, complete_lattice (β i)] {f : ι → Πa, β a} {a : α} : (⨆i, f i) a = (⨆i, f i a) := by erw [← Sup_range, Sup_apply, supr_range] 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, Sup_le $ assume x' ⟨f, f_in, fx_eq⟩, le_Sup_of_le ⟨f, f_in, rfl⟩ $ fx_eq ▸ m_s _ f_in h theorem monotone_Inf_of_monotone {s : set (α → β)} (m_s : ∀f∈s, monotone f) : monotone (Inf s) := assume x y h, le_Inf $ assume x' ⟨f, f_in, fx_eq⟩, Inf_le_of_le ⟨f, f_in, rfl⟩ $ fx_eq ▸ m_s _ f_in h end complete_lattice section ord_continuous variables [complete_lattice α] [complete_lattice β] /-- A function `f` between complete lattices is order-continuous if it preserves all suprema. -/ def ord_continuous (f : α → β) := ∀s : set α, f (Sup s) = (⨆i∈s, f i) lemma ord_continuous.sup {f : α → β} {a₁ a₂ : α} (hf : ord_continuous f) : f (a₁ ⊔ a₂) = f a₁ ⊔ f a₂ := by rw [← Sup_pair, ← Sup_pair, hf {a₁, a₂}, ← Sup_image, image_pair] lemma ord_continuous.mono {f : α → β} (hf : ord_continuous f) : monotone f := assume a₁ a₂ h, by rw [← sup_eq_right, ← hf.sup, sup_of_le_right h] end ord_continuous namespace order_dual variable (α) instance [has_Inf α] : has_Sup (order_dual α) := ⟨(Inf : set α → α)⟩ instance [has_Sup α] : has_Inf (order_dual α) := ⟨(Sup : set α → α)⟩ 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.decidable_linear_order α } end order_dual 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
200882b46b00bc9126bd16e05cfef98e22cc2a11
9dc8cecdf3c4634764a18254e94d43da07142918
/src/analysis/normed_space/dual.lean
bdd00bb90571dee40ff586cbb1b426627e218414
[ "Apache-2.0" ]
permissive
jcommelin/mathlib
d8456447c36c176e14d96d9e76f39841f69d2d9b
ee8279351a2e434c2852345c51b728d22af5a156
refs/heads/master
1,664,782,136,488
1,663,638,983,000
1,663,638,983,000
132,563,656
0
0
Apache-2.0
1,663,599,929,000
1,525,760,539,000
Lean
UTF-8
Lean
false
false
10,345
lean
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import analysis.normed_space.hahn_banach.extension import analysis.normed_space.is_R_or_C import analysis.locally_convex.polar /-! # The topological dual of a normed space In this file we define the topological dual `normed_space.dual` of a normed space, and the continuous linear map `normed_space.inclusion_in_double_dual` from a normed space into its double dual. For base field `𝕜 = ℝ` or `𝕜 = ℂ`, this map is actually an isometric embedding; we provide a version `normed_space.inclusion_in_double_dual_li` of the map which is of type a bundled linear isometric embedding, `E →ₗᵢ[𝕜] (dual 𝕜 (dual 𝕜 E))`. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `seminormed_add_comm_group` and we specialize to `normed_add_comm_group` when needed. ## Main definitions * `inclusion_in_double_dual` and `inclusion_in_double_dual_li` are the inclusion of a normed space in its double dual, considered as a bounded linear map and as a linear isometry, respectively. * `polar 𝕜 s` is the subset of `dual 𝕜 E` consisting of those functionals `x'` for which `∥x' z∥ ≤ 1` for every `z ∈ s`. ## Tags dual -/ noncomputable theory open_locale classical topological_space universes u v namespace normed_space section general variables (𝕜 : Type*) [nontrivially_normed_field 𝕜] variables (E : Type*) [seminormed_add_comm_group E] [normed_space 𝕜 E] variables (F : Type*) [normed_add_comm_group F] [normed_space 𝕜 F] /-- The topological dual of a seminormed space `E`. -/ @[derive [inhabited, seminormed_add_comm_group, normed_space 𝕜]] def dual := E →L[𝕜] 𝕜 instance : continuous_linear_map_class (dual 𝕜 E) 𝕜 E 𝕜 := continuous_linear_map.continuous_semilinear_map_class instance : has_coe_to_fun (dual 𝕜 E) (λ _, E → 𝕜) := continuous_linear_map.to_fun instance : normed_add_comm_group (dual 𝕜 F) := continuous_linear_map.to_normed_add_comm_group instance [finite_dimensional 𝕜 E] : finite_dimensional 𝕜 (dual 𝕜 E) := continuous_linear_map.finite_dimensional /-- The inclusion of a normed space in its double (topological) dual, considered as a bounded linear map. -/ def inclusion_in_double_dual : E →L[𝕜] (dual 𝕜 (dual 𝕜 E)) := continuous_linear_map.apply 𝕜 𝕜 @[simp] lemma dual_def (x : E) (f : dual 𝕜 E) : inclusion_in_double_dual 𝕜 E x f = f x := rfl lemma inclusion_in_double_dual_norm_eq : ∥inclusion_in_double_dual 𝕜 E∥ = ∥(continuous_linear_map.id 𝕜 (dual 𝕜 E))∥ := continuous_linear_map.op_norm_flip _ lemma inclusion_in_double_dual_norm_le : ∥inclusion_in_double_dual 𝕜 E∥ ≤ 1 := by { rw inclusion_in_double_dual_norm_eq, exact continuous_linear_map.norm_id_le } lemma double_dual_bound (x : E) : ∥(inclusion_in_double_dual 𝕜 E) x∥ ≤ ∥x∥ := by simpa using continuous_linear_map.le_of_op_norm_le _ (inclusion_in_double_dual_norm_le 𝕜 E) x /-- The dual pairing as a bilinear form. -/ def dual_pairing : (dual 𝕜 E) →ₗ[𝕜] E →ₗ[𝕜] 𝕜 := continuous_linear_map.coe_lm 𝕜 @[simp] lemma dual_pairing_apply {v : dual 𝕜 E} {x : E} : dual_pairing 𝕜 E v x = v x := rfl lemma dual_pairing_separating_left : (dual_pairing 𝕜 E).separating_left := begin rw [linear_map.separating_left_iff_ker_eq_bot, linear_map.ker_eq_bot], exact continuous_linear_map.coe_injective, end end general section bidual_isometry variables (𝕜 : Type v) [is_R_or_C 𝕜] {E : Type u} [normed_add_comm_group E] [normed_space 𝕜 E] /-- If one controls the norm of every `f x`, then one controls the norm of `x`. Compare `continuous_linear_map.op_norm_le_bound`. -/ lemma norm_le_dual_bound (x : E) {M : ℝ} (hMp: 0 ≤ M) (hM : ∀ (f : dual 𝕜 E), ∥f x∥ ≤ M * ∥f∥) : ∥x∥ ≤ M := begin classical, by_cases h : x = 0, { simp only [h, hMp, norm_zero] }, { obtain ⟨f, hf₁, hfx⟩ : ∃ f : E →L[𝕜] 𝕜, ∥f∥ = 1 ∧ f x = ∥x∥ := exists_dual_vector 𝕜 x h, calc ∥x∥ = ∥(∥x∥ : 𝕜)∥ : is_R_or_C.norm_coe_norm.symm ... = ∥f x∥ : by rw hfx ... ≤ M * ∥f∥ : hM f ... = M : by rw [hf₁, mul_one] } end lemma eq_zero_of_forall_dual_eq_zero {x : E} (h : ∀ f : dual 𝕜 E, f x = (0 : 𝕜)) : x = 0 := norm_le_zero_iff.mp (norm_le_dual_bound 𝕜 x le_rfl (λ f, by simp [h f])) lemma eq_zero_iff_forall_dual_eq_zero (x : E) : x = 0 ↔ ∀ g : dual 𝕜 E, g x = 0 := ⟨λ hx, by simp [hx], λ h, eq_zero_of_forall_dual_eq_zero 𝕜 h⟩ /-- See also `geometric_hahn_banach_point_point`. -/ lemma eq_iff_forall_dual_eq {x y : E} : x = y ↔ ∀ g : dual 𝕜 E, g x = g y := begin rw [← sub_eq_zero, eq_zero_iff_forall_dual_eq_zero 𝕜 (x - y)], simp [sub_eq_zero], end /-- The inclusion of a normed space in its double dual is an isometry onto its image.-/ def inclusion_in_double_dual_li : E →ₗᵢ[𝕜] (dual 𝕜 (dual 𝕜 E)) := { norm_map' := begin intros x, apply le_antisymm, { exact double_dual_bound 𝕜 E x }, rw continuous_linear_map.norm_def, refine le_cInf continuous_linear_map.bounds_nonempty _, rintros c ⟨hc1, hc2⟩, exact norm_le_dual_bound 𝕜 x hc1 hc2 end, .. inclusion_in_double_dual 𝕜 E } end bidual_isometry section polar_sets open metric set normed_space /-- Given a subset `s` in a normed space `E` (over a field `𝕜`), the polar `polar 𝕜 s` is the subset of `dual 𝕜 E` consisting of those functionals which evaluate to something of norm at most one at all points `z ∈ s`. -/ def polar (𝕜 : Type*) [nontrivially_normed_field 𝕜] {E : Type*} [seminormed_add_comm_group E] [normed_space 𝕜 E] : set E → set (dual 𝕜 E) := (dual_pairing 𝕜 E).flip.polar variables (𝕜 : Type*) [nontrivially_normed_field 𝕜] variables {E : Type*} [seminormed_add_comm_group E] [normed_space 𝕜 E] lemma mem_polar_iff {x' : dual 𝕜 E} (s : set E) : x' ∈ polar 𝕜 s ↔ ∀ z ∈ s, ∥x' z∥ ≤ 1 := iff.rfl @[simp] lemma polar_univ : polar 𝕜 (univ : set E) = {(0 : dual 𝕜 E)} := (dual_pairing 𝕜 E).flip.polar_univ (linear_map.flip_separating_right.mpr (dual_pairing_separating_left 𝕜 E)) lemma is_closed_polar (s : set E) : is_closed (polar 𝕜 s) := begin dunfold normed_space.polar, simp only [linear_map.polar_eq_Inter, linear_map.flip_apply], refine is_closed_bInter (λ z hz, _), exact is_closed_Iic.preimage (continuous_linear_map.apply 𝕜 𝕜 z).continuous.norm end @[simp] lemma polar_closure (s : set E) : polar 𝕜 (closure s) = polar 𝕜 s := ((dual_pairing 𝕜 E).flip.polar_antitone subset_closure).antisymm $ (dual_pairing 𝕜 E).flip.polar_gc.l_le $ closure_minimal ((dual_pairing 𝕜 E).flip.polar_gc.le_u_l s) $ by simpa [linear_map.flip_flip] using (is_closed_polar _ _).preimage (inclusion_in_double_dual 𝕜 E).continuous variables {𝕜} /-- If `x'` is a dual element such that the norms `∥x' z∥` are bounded for `z ∈ s`, then a small scalar multiple of `x'` is in `polar 𝕜 s`. -/ lemma smul_mem_polar {s : set E} {x' : dual 𝕜 E} {c : 𝕜} (hc : ∀ z, z ∈ s → ∥ x' z ∥ ≤ ∥c∥) : c⁻¹ • x' ∈ polar 𝕜 s := begin by_cases c_zero : c = 0, { simp only [c_zero, inv_zero, zero_smul], exact (dual_pairing 𝕜 E).flip.zero_mem_polar _ }, have eq : ∀ z, ∥ c⁻¹ • (x' z) ∥ = ∥ c⁻¹ ∥ * ∥ x' z ∥ := λ z, norm_smul c⁻¹ _, have le : ∀ z, z ∈ s → ∥ c⁻¹ • (x' z) ∥ ≤ ∥ c⁻¹ ∥ * ∥ c ∥, { intros z hzs, rw eq z, apply mul_le_mul (le_of_eq rfl) (hc z hzs) (norm_nonneg _) (norm_nonneg _), }, have cancel : ∥ c⁻¹ ∥ * ∥ c ∥ = 1, by simp only [c_zero, norm_eq_zero, ne.def, not_false_iff, inv_mul_cancel, norm_inv], rwa cancel at le, end lemma polar_ball_subset_closed_ball_div {c : 𝕜} (hc : 1 < ∥c∥) {r : ℝ} (hr : 0 < r) : polar 𝕜 (ball (0 : E) r) ⊆ closed_ball (0 : dual 𝕜 E) (∥c∥ / r) := begin intros x' hx', rw mem_polar_iff at hx', simp only [polar, mem_set_of_eq, mem_closed_ball_zero_iff, mem_ball_zero_iff] at *, have hcr : 0 < ∥c∥ / r, from div_pos (zero_lt_one.trans hc) hr, refine continuous_linear_map.op_norm_le_of_shell hr hcr.le hc (λ x h₁ h₂, _), calc ∥x' x∥ ≤ 1 : hx' _ h₂ ... ≤ (∥c∥ / r) * ∥x∥ : (inv_pos_le_iff_one_le_mul' hcr).1 (by rwa inv_div) end variables (𝕜) lemma closed_ball_inv_subset_polar_closed_ball {r : ℝ} : closed_ball (0 : dual 𝕜 E) r⁻¹ ⊆ polar 𝕜 (closed_ball (0 : E) r) := λ x' hx' x hx, calc ∥x' x∥ ≤ ∥x'∥ * ∥x∥ : x'.le_op_norm x ... ≤ r⁻¹ * r : mul_le_mul (mem_closed_ball_zero_iff.1 hx') (mem_closed_ball_zero_iff.1 hx) (norm_nonneg _) (dist_nonneg.trans hx') ... = r / r : inv_mul_eq_div _ _ ... ≤ 1 : div_self_le_one r /-- The `polar` of closed ball in a normed space `E` is the closed ball of the dual with inverse radius. -/ lemma polar_closed_ball {𝕜 E : Type*} [is_R_or_C 𝕜] [normed_add_comm_group E] [normed_space 𝕜 E] {r : ℝ} (hr : 0 < r) : polar 𝕜 (closed_ball (0 : E) r) = closed_ball (0 : dual 𝕜 E) r⁻¹ := begin refine subset.antisymm _ (closed_ball_inv_subset_polar_closed_ball _), intros x' h, simp only [mem_closed_ball_zero_iff], refine continuous_linear_map.op_norm_le_of_ball hr (inv_nonneg.mpr hr.le) (λ z hz, _), simpa only [one_div] using linear_map.bound_of_ball_bound' hr 1 x'.to_linear_map h z end /-- Given a neighborhood `s` of the origin in a normed space `E`, the dual norms of all elements of the polar `polar 𝕜 s` are bounded by a constant. -/ lemma bounded_polar_of_mem_nhds_zero {s : set E} (s_nhd : s ∈ 𝓝 (0 : E)) : bounded (polar 𝕜 s) := begin obtain ⟨a, ha⟩ : ∃ a : 𝕜, 1 < ∥a∥ := normed_field.exists_one_lt_norm 𝕜, obtain ⟨r, r_pos, r_ball⟩ : ∃ (r : ℝ) (hr : 0 < r), ball 0 r ⊆ s := metric.mem_nhds_iff.1 s_nhd, exact bounded_closed_ball.mono (((dual_pairing 𝕜 E).flip.polar_antitone r_ball).trans $ polar_ball_subset_closed_ball_div ha r_pos) end end polar_sets end normed_space
a0466cc6ce61344ba5c691aa900ac7f59a5ca592
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/tactic/replacer_auto.lean
18e7570fbe14eb60c3c5f18f22653749952a1fd9
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
1,422
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.tactic.core import Mathlib.PostPort namespace Mathlib /-! # `def_replacer` A mechanism for defining tactics for use in auto params, whose meaning is defined incrementally through attributes. -/ namespace tactic /-- Define a new replaceable tactic. -/ /-- `def_replacer foo` sets up a stub definition `foo : tactic unit`, which can effectively be defined and re-defined later, by tagging definitions with `@[foo]`. - `@[foo] meta def foo_1 : tactic unit := ...` replaces the current definition of `foo`. - `@[foo] meta def foo_2 (old : tactic unit) : tactic unit := ...` replaces the current definition of `foo`, and provides access to the previous definition via `old`. (The argument can also be an `option (tactic unit)`, which is provided as `none` if this is the first definition tagged with `@[foo]` since `def_replacer` was invoked.) `def_replacer foo : α → β → tactic γ` allows the specification of a replacer with custom input and output types. In this case all subsequent redefinitions must have the same type, or the type `α → β → tactic γ → tactic γ` or `α → β → option (tactic γ) → tactic γ` analogously to the previous cases. -/ end Mathlib
af051ae3ff91eb376617447d68fcf2d539d2322d
491068d2ad28831e7dade8d6dff871c3e49d9431
/tests/lean/param_binder_update.lean
0fc9079ce8b0b2e61e926cca7f2113e2ce2e79fc
[ "Apache-2.0" ]
permissive
davidmueller13/lean
65a3ed141b4088cd0a268e4de80eb6778b21a0e9
c626e2e3c6f3771e07c32e82ee5b9e030de5b050
refs/heads/master
1,611,278,313,401
1,444,021,177,000
1,444,021,177,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,120
lean
section parameter {A : Type} parameter A definition id (a : A) := a parameter {A} definition id₂ (a : A) := a end check @id check @id₂ section parameters {A : Type} {B : Type} definition foo1 (a : A) (b : B) := a parameters {A} (B) definition foo2 (a : A) (b : B) := a parameters (A) {B} definition foo3 (a : A) (b : B) := a parameters (A) (B) definition foo4 (a : A) (b : B) := a check @foo1 check @foo2 check @foo3 check @foo4 end check @foo1 check @foo2 check @foo3 check @foo4 section variables {A : Type} {B : Type} definition boo1 (a : A) (b : B) := a variables {A} (B) definition boo2 (a : A) (b : B) := a variables (A) {B} definition boo3 (a : A) (b : B) := a variables (A) (B) definition boo4 (a : A) (b : B) := a check @boo1 check @boo2 check @boo3 check @boo4 end section variables {A : Type} {B : Type} parameter (A) -- ERROR variable (C) -- ERROR variables (C) (D) -- ERROR variables C -- ERROR definition id3 (a : A) := a parameter id3 -- ERROR parameter (C : Type) variables {C} -- ERROR end
a9518d55051ca0763beb0009686a5600b083a7bf
63abd62053d479eae5abf4951554e1064a4c45b4
/src/analysis/complex/basic.lean
1acd614eb953e6c2049c236dc53b2ce872df83c8
[ "Apache-2.0" ]
permissive
Lix0120/mathlib
0020745240315ed0e517cbf32e738d8f9811dd80
e14c37827456fc6707f31b4d1d16f1f3a3205e91
refs/heads/master
1,673,102,855,024
1,604,151,044,000
1,604,151,044,000
308,930,245
0
0
Apache-2.0
1,604,164,710,000
1,604,163,547,000
null
UTF-8
Lean
false
false
7,780
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: * `continuous_linear_map.re` * `continuous_linear_map.im` * `continuous_linear_map.of_real` They are bundled versions of the real part, the imaginary part, and the embedding of `ℝ` in `ℂ`, as continuous `ℝ`-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. -/ @[priority 900] instance normed_space.restrict_scalars_real (E : Type*) [normed_group E] [normed_space ℂ E] : normed_space ℝ E := normed_space.restrict_scalars ℝ ℂ E /-- The space of continuous linear maps over `ℝ`, from a real vector space to a complex vector space, is a normed vector space over `ℂ`. -/ instance continuous_linear_map.real_smul_complex (E : Type*) [normed_group E] [normed_space ℝ E] (F : Type*) [normed_group F] [normed_space ℂ F] : normed_space ℂ (E →L[ℝ] F) := continuous_linear_map.normed_space_extend_scalars /-- 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 /-- 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 /-- 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
85d5732ea04ae18cdd5ed041b2a3e502b21fc56b
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/nat/cast.lean
b6f21c7803cc6ae8be11c7e646be52d1b0933c2a
[]
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
11,536
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.algebra.ordered_field import Mathlib.data.nat.basic import Mathlib.PostPort universes u_1 u_2 namespace Mathlib namespace nat /-- Canonical homomorphism from `ℕ` to a type `α` with `0`, `1` and `+`. -/ protected def cast {α : Type u_1} [HasZero α] [HasOne α] [Add α] : ℕ → α := sorry /-- Computationally friendlier cast than `nat.cast`, using binary representation. -/ protected def bin_cast {α : Type u_1} [HasZero α] [HasOne α] [Add α] (n : ℕ) : α := binary_rec 0 (fun (odd : Bool) (k : ℕ) (a : α) => cond odd (a + a + 1) (a + a)) n /-- Coercions such as `nat.cast_coe` that go from a concrete structure such as `ℕ` to an arbitrary ring `α` should be set up as follows: ```lean @[priority 900] instance : has_coe_t ℕ α := ⟨...⟩ ``` It needs to be `has_coe_t` instead of `has_coe` because otherwise type-class inference would loop when constructing the transitive coercion `ℕ → ℕ → ℕ → ...`. The reduced priority is necessary so that it doesn't conflict with instances such as `has_coe_t α (option α)`. For this to work, we reduce the priority of the `coe_base` and `coe_trans` instances because we want the instances for `has_coe_t` to be tried in the following order: 1. `has_coe_t` instances declared in mathlib (such as `has_coe_t α (with_top α)`, etc.) 2. `coe_base`, which contains instances such as `has_coe (fin n) n` 3. `nat.cast_coe : has_coe_t ℕ α` etc. 4. `coe_trans` If `coe_trans` is tried first, then `nat.cast_coe` doesn't get a chance to apply. -/ -- see note [coercion into rings] protected instance cast_coe {α : Type u_1} [HasZero α] [HasOne α] [Add α] : has_coe_t ℕ α := has_coe_t.mk nat.cast @[simp] theorem cast_zero {α : Type u_1} [HasZero α] [HasOne α] [Add α] : ↑0 = 0 := rfl theorem cast_add_one {α : Type u_1} [HasZero α] [HasOne α] [Add α] (n : ℕ) : ↑(n + 1) = ↑n + 1 := rfl @[simp] theorem cast_succ {α : Type u_1} [HasZero α] [HasOne α] [Add α] (n : ℕ) : ↑(Nat.succ n) = ↑n + 1 := rfl @[simp] theorem cast_ite {α : Type u_1} [HasZero α] [HasOne α] [Add α] (P : Prop) [Decidable P] (m : ℕ) (n : ℕ) : ↑(ite P m n) = ite P ↑m ↑n := sorry @[simp] theorem cast_one {α : Type u_1} [add_monoid α] [HasOne α] : ↑1 = 1 := zero_add 1 @[simp] theorem cast_add {α : Type u_1} [add_monoid α] [HasOne α] (m : ℕ) (n : ℕ) : ↑(m + n) = ↑m + ↑n := sorry @[simp] theorem bin_cast_eq {α : Type u_1} [add_monoid α] [HasOne α] (n : ℕ) : nat.bin_cast n = ↑n := sorry /-- `coe : ℕ → α` as an `add_monoid_hom`. -/ def cast_add_monoid_hom (α : Type u_1) [add_monoid α] [HasOne α] : ℕ →+ α := add_monoid_hom.mk coe sorry cast_add @[simp] theorem coe_cast_add_monoid_hom {α : Type u_1} [add_monoid α] [HasOne α] : ⇑(cast_add_monoid_hom α) = coe := rfl @[simp] theorem cast_bit0 {α : Type u_1} [add_monoid α] [HasOne α] (n : ℕ) : ↑(bit0 n) = bit0 ↑n := cast_add n n @[simp] theorem cast_bit1 {α : Type u_1} [add_monoid α] [HasOne α] (n : ℕ) : ↑(bit1 n) = bit1 ↑n := eq.mpr (id (Eq._oldrec (Eq.refl (↑(bit1 n) = bit1 ↑n)) (bit1.equations._eqn_1 n))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑(bit0 n + 1) = bit1 ↑n)) (cast_add_one (bit0 n)))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑(bit0 n) + 1 = bit1 ↑n)) (cast_bit0 n))) (Eq.refl (bit0 ↑n + 1)))) theorem cast_two {α : Type u_1} [add_monoid α] [HasOne α] : ↑(bit0 1) = bit0 1 := sorry @[simp] theorem cast_pred {α : Type u_1} [add_group α] [HasOne α] {n : ℕ} : 0 < n → ↑(n - 1) = ↑n - 1 := sorry @[simp] theorem cast_sub {α : Type u_1} [add_group α] [HasOne α] {m : ℕ} {n : ℕ} (h : m ≤ n) : ↑(n - m) = ↑n - ↑m := eq_sub_of_add_eq (eq.mpr (id (Eq._oldrec (Eq.refl (↑(n - m) + ↑m = ↑n)) (Eq.symm (cast_add (n - m) m)))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑(n - m + m) = ↑n)) (nat.sub_add_cancel h))) (Eq.refl ↑n))) @[simp] theorem cast_mul {α : Type u_1} [semiring α] (m : ℕ) (n : ℕ) : ↑(m * n) = ↑m * ↑n := sorry @[simp] theorem cast_dvd {α : Type u_1} [field α] {m : ℕ} {n : ℕ} (n_dvd : n ∣ m) (n_nonzero : ↑n ≠ 0) : ↑(m / n) = ↑m / ↑n := sorry /-- `coe : ℕ → α` as a `ring_hom` -/ def cast_ring_hom (α : Type u_1) [semiring α] : ℕ →+* α := ring_hom.mk coe sorry cast_mul sorry sorry @[simp] theorem coe_cast_ring_hom {α : Type u_1} [semiring α] : ⇑(cast_ring_hom α) = coe := rfl theorem cast_commute {α : Type u_1} [semiring α] (n : ℕ) (x : α) : commute (↑n) x := nat.rec_on n (commute.zero_left x) fun (n : ℕ) (ihn : commute (↑n) x) => commute.add_left ihn (commute.one_left x) theorem commute_cast {α : Type u_1} [semiring α] (x : α) (n : ℕ) : commute x ↑n := commute.symm (cast_commute n x) @[simp] theorem cast_nonneg {α : Type u_1} [ordered_semiring α] (n : ℕ) : 0 ≤ ↑n := sorry theorem mono_cast {α : Type u_1} [ordered_semiring α] : monotone coe := sorry theorem strict_mono_cast {α : Type u_1} [ordered_semiring α] [nontrivial α] : strict_mono coe := fun (m n : ℕ) (h : m < n) => le_induction (lt_add_of_pos_right (↑m) zero_lt_one) (fun (n : ℕ) (_x : Nat.succ m ≤ n) (h : ↑m < ↑n) => lt_add_of_lt_of_pos h zero_lt_one) n h @[simp] theorem cast_le {α : Type u_1} [ordered_semiring α] [nontrivial α] {m : ℕ} {n : ℕ} : ↑m ≤ ↑n ↔ m ≤ n := strict_mono.le_iff_le strict_mono_cast @[simp] theorem cast_lt {α : Type u_1} [ordered_semiring α] [nontrivial α] {m : ℕ} {n : ℕ} : ↑m < ↑n ↔ m < n := strict_mono.lt_iff_lt strict_mono_cast @[simp] theorem cast_pos {α : Type u_1} [ordered_semiring α] [nontrivial α] {n : ℕ} : 0 < ↑n ↔ 0 < n := eq.mpr (id (Eq._oldrec (Eq.refl (0 < ↑n ↔ 0 < n)) (Eq.symm cast_zero))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑0 < ↑n ↔ 0 < n)) (propext cast_lt))) (iff.refl (0 < n))) theorem cast_add_one_pos {α : Type u_1} [ordered_semiring α] [nontrivial α] (n : ℕ) : 0 < ↑n + 1 := add_pos_of_nonneg_of_pos (cast_nonneg n) zero_lt_one @[simp] theorem one_lt_cast {α : Type u_1} [ordered_semiring α] [nontrivial α] {n : ℕ} : 1 < ↑n ↔ 1 < n := eq.mpr (id (Eq._oldrec (Eq.refl (1 < ↑n ↔ 1 < n)) (Eq.symm cast_one))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑1 < ↑n ↔ 1 < n)) (propext cast_lt))) (iff.refl (1 < n))) @[simp] theorem one_le_cast {α : Type u_1} [ordered_semiring α] [nontrivial α] {n : ℕ} : 1 ≤ ↑n ↔ 1 ≤ n := eq.mpr (id (Eq._oldrec (Eq.refl (1 ≤ ↑n ↔ 1 ≤ n)) (Eq.symm cast_one))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑1 ≤ ↑n ↔ 1 ≤ n)) (propext cast_le))) (iff.refl (1 ≤ n))) @[simp] theorem cast_lt_one {α : Type u_1} [ordered_semiring α] [nontrivial α] {n : ℕ} : ↑n < 1 ↔ n = 0 := sorry @[simp] theorem cast_le_one {α : Type u_1} [ordered_semiring α] [nontrivial α] {n : ℕ} : ↑n ≤ 1 ↔ n ≤ 1 := eq.mpr (id (Eq._oldrec (Eq.refl (↑n ≤ 1 ↔ n ≤ 1)) (Eq.symm cast_one))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑n ≤ ↑1 ↔ n ≤ 1)) (propext cast_le))) (iff.refl (n ≤ 1))) @[simp] theorem cast_min {α : Type u_1} [linear_ordered_semiring α] {a : ℕ} {b : ℕ} : ↑(min a b) = min ↑a ↑b := sorry @[simp] theorem cast_max {α : Type u_1} [linear_ordered_semiring α] {a : ℕ} {b : ℕ} : ↑(max a b) = max ↑a ↑b := sorry @[simp] theorem abs_cast {α : Type u_1} [linear_ordered_ring α] (a : ℕ) : abs ↑a = ↑a := abs_of_nonneg (cast_nonneg a) theorem coe_nat_dvd {α : Type u_1} [comm_semiring α] {m : ℕ} {n : ℕ} (h : m ∣ n) : ↑m ∣ ↑n := ring_hom.map_dvd (cast_ring_hom α) h theorem Mathlib.has_dvd.dvd.nat_cast {α : Type u_1} [comm_semiring α] {m : ℕ} {n : ℕ} (h : m ∣ n) : ↑m ∣ ↑n := coe_nat_dvd theorem inv_pos_of_nat {α : Type u_1} [linear_ordered_field α] {n : ℕ} : 0 < (↑n + 1⁻¹) := iff.mpr inv_pos (add_pos_of_nonneg_of_pos (cast_nonneg n) zero_lt_one) theorem one_div_pos_of_nat {α : Type u_1} [linear_ordered_field α] {n : ℕ} : 0 < 1 / (↑n + 1) := eq.mpr (id (Eq._oldrec (Eq.refl (0 < 1 / (↑n + 1))) (one_div (↑n + 1)))) inv_pos_of_nat theorem one_div_le_one_div {α : Type u_1} [linear_ordered_field α] {n : ℕ} {m : ℕ} (h : n ≤ m) : 1 / (↑m + 1) ≤ 1 / (↑n + 1) := one_div_le_one_div_of_le (cast_add_one_pos n) (eq.mpr (id (Eq.trans (propext (add_le_add_iff_right 1)) (propext cast_le))) h) theorem one_div_lt_one_div {α : Type u_1} [linear_ordered_field α] {n : ℕ} {m : ℕ} (h : n < m) : 1 / (↑m + 1) < 1 / (↑n + 1) := one_div_lt_one_div_of_lt (cast_add_one_pos n) (eq.mpr (id (Eq.trans (propext (add_lt_add_iff_right 1)) (propext cast_lt))) h) end nat namespace add_monoid_hom theorem ext_nat {A : Type u_1} [add_monoid A] {f : ℕ →+ A} {g : ℕ →+ A} (h : coe_fn f 1 = coe_fn g 1) : f = g := sorry theorem eq_nat_cast {A : Type u_1} [add_monoid A] [HasOne A] (f : ℕ →+ A) (h1 : coe_fn f 1 = 1) (n : ℕ) : coe_fn f n = ↑n := congr_fun ((fun (this : f = nat.cast_add_monoid_hom A) => this) (ext_nat (Eq.trans h1 (Eq.symm nat.cast_one)))) theorem map_nat_cast {A : Type u_1} {B : Type u_2} [add_monoid A] [HasOne A] [add_monoid B] [HasOne B] (f : A →+ B) (h1 : coe_fn f 1 = 1) (n : ℕ) : coe_fn f ↑n = ↑n := sorry end add_monoid_hom namespace ring_hom @[simp] theorem eq_nat_cast {R : Type u_1} [semiring R] (f : ℕ →+* R) (n : ℕ) : coe_fn f n = ↑n := add_monoid_hom.eq_nat_cast (to_add_monoid_hom f) (map_one f) n @[simp] theorem map_nat_cast {R : Type u_1} {S : Type u_2} [semiring R] [semiring S] (f : R →+* S) (n : ℕ) : coe_fn f ↑n = ↑n := eq_nat_cast (comp f (nat.cast_ring_hom R)) n theorem ext_nat {R : Type u_1} [semiring R] (f : ℕ →+* R) (g : ℕ →+* R) : f = g := coe_add_monoid_hom_injective (add_monoid_hom.ext_nat (Eq.trans (map_one f) (Eq.symm (map_one g)))) end ring_hom @[simp] theorem nat.cast_id (n : ℕ) : ↑n = n := Eq.symm (ring_hom.eq_nat_cast (ring_hom.id ℕ) n) @[simp] theorem nat.cast_with_bot (n : ℕ) : ↑n = ↑n := sorry protected instance nat.subsingleton_ring_hom {R : Type u_1} [semiring R] : subsingleton (ℕ →+* R) := subsingleton.intro ring_hom.ext_nat namespace with_top @[simp] theorem coe_nat {α : Type u_1} [HasZero α] [HasOne α] [Add α] (n : ℕ) : ↑↑n = ↑n := sorry @[simp] theorem nat_ne_top {α : Type u_1} [HasZero α] [HasOne α] [Add α] (n : ℕ) : ↑n ≠ ⊤ := eq.mpr (id (Eq._oldrec (Eq.refl (↑n ≠ ⊤)) (Eq.symm (coe_nat n)))) coe_ne_top @[simp] theorem top_ne_nat {α : Type u_1} [HasZero α] [HasOne α] [Add α] (n : ℕ) : ⊤ ≠ ↑n := eq.mpr (id (Eq._oldrec (Eq.refl (⊤ ≠ ↑n)) (Eq.symm (coe_nat n)))) top_ne_coe theorem add_one_le_of_lt {i : with_top ℕ} {n : with_top ℕ} (h : i < n) : i + 1 ≤ n := sorry theorem one_le_iff_pos {n : with_top ℕ} : 1 ≤ n ↔ 0 < n := sorry theorem nat_induction {P : with_top ℕ → Prop} (a : with_top ℕ) (h0 : P 0) (hsuc : ∀ (n : ℕ), P ↑n → P ↑(Nat.succ n)) (htop : (∀ (n : ℕ), P ↑n) → P ⊤) : P a := option.cases_on a (htop fun (n : ℕ) => nat.rec_on n h0 hsuc) fun (a : ℕ) => (fun (n : ℕ) => nat.rec_on n h0 hsuc) a
497489824ffebcf6b110bb0e95f41acc8c78c4d4
57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d
/src/Lean/Elab/Tactic/Simp.lean
1c5ac9d6361da9735fba31093d7374d779fda141
[ "Apache-2.0" ]
permissive
collares/lean4
861a9269c4592bce49b71059e232ff0bfe4594cc
52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee
refs/heads/master
1,691,419,031,324
1,618,678,138,000
1,618,678,138,000
358,989,750
0
0
Apache-2.0
1,618,696,333,000
1,618,696,333,000
null
UTF-8
Lean
false
false
6,525
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Meta.Tactic.Simp import Lean.Elab.Tactic.Basic import Lean.Elab.Tactic.ElabTerm import Lean.Elab.Tactic.Location import Lean.Meta.Tactic.Replace import Lean.Elab.BuiltinNotation namespace Lean.Elab.Tactic open Meta unsafe def evalSimpConfigUnsafe (e : Expr) : TermElabM Meta.Simp.Config := Term.evalExpr Meta.Simp.Config ``Meta.Simp.Config e @[implementedBy evalSimpConfigUnsafe] constant evalSimpConfig (e : Expr) : TermElabM Meta.Simp.Config unsafe def evalSimpConfigCtxUnsafe (e : Expr) : TermElabM Meta.Simp.ConfigCtx := Term.evalExpr Meta.Simp.ConfigCtx ``Meta.Simp.ConfigCtx e @[implementedBy evalSimpConfigCtxUnsafe] constant evalSimpConfigCtx (e : Expr) : TermElabM Meta.Simp.ConfigCtx /- `optConfig` is of the form `("(" "config" ":=" term ")")?` If `ctx == false`, the argument is assumed to have type `Meta.Simp.Config`, and `Meta.Simp.ConfigCtx` otherwise. -/ def elabSimpConfig (optConfig : Syntax) (ctx : Bool) : TermElabM Meta.Simp.Config := do if optConfig.isNone then if ctx then return { : Meta.Simp.ConfigCtx }.toConfig else return {} else withLCtx {} {} <| withNewMCtxDepth <| Term.withSynthesize do let c ← Term.elabTermEnsuringType optConfig[3] (Lean.mkConst (if ctx then ``Meta.Simp.ConfigCtx else ``Meta.Simp.Config)) if ctx then return (← evalSimpConfigCtx (← instantiateMVars c)).toConfig else evalSimpConfig (← instantiateMVars c) private def addDeclToUnfoldOrLemma (lemmas : Meta.SimpLemmas) (e : Expr) (post : Bool) : MetaM Meta.SimpLemmas := do if e.isConst then let declName := e.constName! let info ← getConstInfo declName if (← isProp info.type) then lemmas.addConst declName post else lemmas.addDeclToUnfold declName else lemmas.add #[] e post private def addSimpLemma (lemmas : Meta.SimpLemmas) (stx : Syntax) (post : Bool) : TermElabM Meta.SimpLemmas := do let (levelParams, proof) ← Term.withoutModifyingElabMetaState <| withRef stx <| Term.withoutErrToSorry do let e ← Term.elabTerm stx none Term.synthesizeSyntheticMVarsUsingDefault let e ← instantiateMVars e let e := e.eta if e.hasMVar then let r ← abstractMVars e return (r.paramNames, r.expr) else return (#[], e) lemmas.add levelParams proof /-- Elaborate extra simp lemmas provided to `simp`. `stx` is of the `simpLemma,*` If `eraseLocal == true`, then we consider local declarations when resolving names for erased lemmas (`- id`), this option only makes sense for `simp_all`. -/ private def elabSimpLemmas (stx : Syntax) (ctx : Simp.Context) (eraseLocal : Bool) : TacticM Simp.Context := do if stx.isNone then return ctx else /- syntax simpPre := "↓" syntax simpPost := "↑" syntax simpLemma := (simpPre <|> simpPost)? term syntax simpErase := "-" ident -/ withMainContext do let mut lemmas := ctx.simpLemmas for arg in stx[1].getSepArgs do if arg.getKind == ``Lean.Parser.Tactic.simpErase then if eraseLocal && (← Term.isLocalIdent? arg[1]).isSome then -- We use `eraseCore` because the simp lemma for the hypothesis was not added yet lemmas ← lemmas.eraseCore arg[1].getId else let declName ← resolveGlobalConstNoOverloadWithInfo arg[1] lemmas ← lemmas.erase declName else let post := if arg[0].isNone then true else arg[0][0].getKind == ``Parser.Tactic.simpPost match (← resolveSimpIdLemma? arg[1]) with | some e => lemmas ← addDeclToUnfoldOrLemma lemmas e post | _ => lemmas ← addSimpLemma lemmas arg[1] post return { ctx with simpLemmas := lemmas } where resolveSimpIdLemma? (simpArgTerm : Syntax) : TacticM (Option Expr) := do if simpArgTerm.isIdent then try Term.resolveId? simpArgTerm catch _ => return none else Term.elabCDotFunctionAlias? simpArgTerm -- If `ctx == false`, the argument is assumed to have type `Meta.Simp.Config`, and `Meta.Simp.ConfigCtx` otherwise. -/ private def mkSimpContext (stx : Syntax) (eraseLocal : Bool) (ctx := false) : TacticM Simp.Context := do let simpOnly := !stx[2].isNone elabSimpLemmas stx[3] (eraseLocal := eraseLocal) { config := (← elabSimpConfig stx[1] (ctx := ctx)) simpLemmas := if simpOnly then {} else (← getSimpLemmas) congrLemmas := (← getCongrLemmas) } /- "simp " ("(" "config" ":=" term ")")? ("only ")? ("[" simpLemma,* "]")? (location)? -/ @[builtinTactic Lean.Parser.Tactic.simp] def evalSimp : Tactic := fun stx => do let ctx ← mkSimpContext stx (eraseLocal := false) -- trace[Meta.debug] "Lemmas {← toMessageData ctx.simpLemmas.post}" let loc := expandOptLocation stx[4] match loc with | Location.targets hUserNames simpTarget => withMainContext do let fvarIds ← hUserNames.mapM fun hUserName => return (← getLocalDeclFromUserName hUserName).fvarId go ctx fvarIds simpTarget | Location.wildcard => withMainContext do go ctx (← getNondepPropHyps (← getMainGoal)) true where go (ctx : Simp.Context) (fvarIdsToSimp : Array FVarId) (simpType : Bool) : TacticM Unit := do let mut mvarId ← getMainGoal let mut toAssert : Array Hypothesis := #[] for fvarId in fvarIdsToSimp do let localDecl ← getLocalDecl fvarId let type ← instantiateMVars localDecl.type match (← simpStep mvarId (mkFVar fvarId) type ctx) with | none => replaceMainGoal []; return () | some (value, type) => toAssert := toAssert.push { userName := localDecl.userName, type := type, value := value } if simpType then match (← simpTarget mvarId ctx) with | none => replaceMainGoal []; return () | some mvarIdNew => mvarId := mvarIdNew let (_, mvarIdNew) ← assertHypotheses mvarId toAssert let mvarIdNew ← tryClearMany mvarIdNew fvarIdsToSimp replaceMainGoal [mvarIdNew] @[builtinTactic Lean.Parser.Tactic.simpAll] def evalSimpAll : Tactic := fun stx => do let ctx ← mkSimpContext stx (eraseLocal := true) (ctx := true) match (← simpAll (← getMainGoal) ctx) with | none => replaceMainGoal [] | some mvarId => replaceMainGoal [mvarId] end Lean.Elab.Tactic
e55bf13e4af7adf2d440ca48f67f376f6ae3dc3a
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
/src/linear_algebra/nonsingular_inverse.lean
5989914d1f3ea100b5d3d94653960f21f4209ac3
[ "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
15,864
lean
/- Copyright (c) 2019 Tim Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Tim Baanen. -/ import algebra.associated import linear_algebra.determinant import tactic.linarith import tactic.ring_exp /-! # Nonsingular inverses In this file, we define an inverse for square matrices of invertible determinant. For matrices that are not square or not of full rank, there is a more general notion of pseudoinverses. Unfortunately, the definition of pseudoinverses is typically in terms of inverses of nonsingular matrices, so we need to define those first. The file also doesn't define a `has_inv` instance for `matrix` so that can be used for the pseudoinverse instead. The definition of inverse used in this file is the adjugate divided by the determinant. The adjugate is calculated with Cramer's rule, which we introduce first. The vectors returned by Cramer's rule are given by the linear map `cramer`, which sends a matrix `A` and vector `b` to the vector consisting of the determinant of replacing the `i`th column of `A` with `b` at index `i` (written as `(A.update_column i b).det`). Using Cramer's rule, we can compute for each matrix `A` the matrix `adjugate A`. The entries of the adjugate are the determinants of each minor of `A`. Instead of defining a minor to be `A` with column `i` and row `j` deleted, we replace the `i`th column of `A` with the `j`th basis vector; this has the same determinant as the minor but more importantly equals Cramer's rule applied to `A` and the `j`th basis vector, simplifying the subsequent proofs. We prove the adjugate behaves like `det A • A⁻¹`. Finally, we show that dividing the adjugate by `det A` (if possible), giving a matrix `nonsing_inv A`, will result in a multiplicative inverse to `A`. ## References * https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix ## Tags matrix inverse, cramer, cramer's rule, adjugate -/ namespace matrix universes u v variables {n : Type u} [fintype n] [decidable_eq n] {α : Type v} open_locale matrix big_operators open equiv equiv.perm finset section cramer /-! ### `cramer` section Introduce the linear map `cramer` with values defined by `cramer_map`. After defining `cramer_map` and showing it is linear, we will restrict our proofs to using `cramer`. -/ variables [comm_ring α] (A : matrix n n α) (b : n → α) /-- `cramer_map A b i` is the determinant of the matrix `A` with column `i` replaced with `b`, and thus `cramer_map A b` is the vector output by Cramer's rule on `A` and `b`. If `A ⬝ x = b` has a unique solution in `x`, `cramer_map` sends a square matrix `A` and vector `b` to the vector `x` such that `A ⬝ x = b`. Otherwise, the outcome of `cramer_map` is well-defined but not necessarily useful. -/ def cramer_map (i : n) : α := (A.update_row i b).det lemma cramer_map_is_linear (i : n) : is_linear_map α (λ b, cramer_map A b i) := begin have : Π {f : n → n} {i : n} (x : n → α), (∏ i' : n, (update_row A i x)ᵀ (f i') i') = (∏ i' : n, if i' = i then x (f i') else A i' (f i')), { intros, congr, ext i', rw [transpose_val, update_row_val] }, split, { intros x y, repeat { rw [cramer_map, ←det_transpose, det] }, rw [←sum_add_distrib], congr, ext σ, rw [←mul_add ↑↑(sign σ)], congr, repeat { erw [this, finset.prod_ite] }, erw [finset.filter_eq', if_pos (mem_univ i), prod_singleton, prod_singleton, prod_singleton, ←add_mul], refl }, { intros c x, repeat { rw [cramer_map, ←det_transpose, det] }, rw [smul_eq_mul, mul_sum], congr, ext σ, rw [←mul_assoc, mul_comm c, mul_assoc], congr, repeat { erw [this, finset.prod_ite] }, erw [finset.filter_eq', if_pos (mem_univ i), prod_singleton, prod_singleton, mul_assoc], } end lemma cramer_is_linear : is_linear_map α (cramer_map A) := begin split; intros; ext i, { apply (cramer_map_is_linear A i).1 }, { apply (cramer_map_is_linear A i).2 } end /-- The linear map of vectors associated to Cramer's rule. To help the elaborator, we need to make the type `α` an explicit argument to `cramer`. Otherwise, the coercion `⇑(cramer A) : (n → α) → (n → α)` gives an error because it fails to infer the type (even though `α` can be inferred from `A : matrix n n α`). -/ def cramer (α : Type v) [comm_ring α] (A : matrix n n α) : (n → α) →ₗ[α] (n → α) := is_linear_map.mk' (cramer_map A) (cramer_is_linear A) lemma cramer_apply (i : n) : cramer α A b i = (A.update_row i b).det := rfl /-- Applying Cramer's rule to a column of the matrix gives a scaled basis vector. -/ lemma cramer_column_self (i : n) : cramer α A (A i) = (λ j, if i = j then A.det else 0) := begin ext j, rw cramer_apply, by_cases i = j, { -- i = j: this entry should be `A.det` rw [if_pos h, ←h], congr, ext i', by_cases h : i' = i, { rw [h, update_row_self] }, { rw [update_row_ne h] } }, { -- i ≠ j: this entry should be 0 rw [if_neg h], apply det_zero_of_column_eq h, rw [update_row_self, update_row_ne], apply h } end /-- Use linearity of `cramer` to take it out of a summation. -/ lemma sum_cramer {β} (s : finset β) (f : β → n → α) : ∑ x in s, cramer α A (f x) = cramer α A (∑ x in s, f x) := (linear_map.map_sum (cramer α A)).symm /-- Use linearity of `cramer` and vector evaluation to take `cramer A _ i` out of a summation. -/ lemma sum_cramer_apply {β} (s : finset β) (f : n → β → α) (i : n) : ∑ x in s, cramer α A (λ j, f j x) i = cramer α A (λ (j : n), ∑ x in s, f j x) i := calc ∑ x in s, cramer α A (λ j, f j x) i = (∑ x in s, cramer α A (λ j, f j x)) i : (finset.sum_apply i s _).symm ... = cramer α A (λ (j : n), ∑ x in s, f j x) i : by { rw [sum_cramer, cramer_apply], congr, ext j, apply finset.sum_apply } end cramer section adjugate /-! ### `adjugate` section Define the `adjugate` matrix and a few equations. These will hold for any matrix over a commutative ring, while the `inv` section is specifically for invertible matrices. -/ variable [comm_ring α] /-- The adjugate matrix is the transpose of the cofactor matrix. Typically, the cofactor matrix is defined by taking the determinant of minors, i.e. the matrix with a row and column removed. However, the proof of `mul_adjugate` becomes a lot easier if we define the minor as replacing a column with a basis vector, since it allows us to use facts about the `cramer` map. -/ def adjugate (A : matrix n n α) : matrix n n α := λ i, cramer α A (λ j, if i = j then 1 else 0) lemma adjugate_def (A : matrix n n α) : adjugate A = λ i, cramer α A (λ j, if i = j then 1 else 0) := rfl lemma adjugate_val (A : matrix n n α) (i j : n) : adjugate A i j = (A.update_row j (λ j, if i = j then 1 else 0)).det := rfl lemma adjugate_transpose (A : matrix n n α) : (adjugate A)ᵀ = adjugate (Aᵀ) := begin ext i j, rw [transpose_val, adjugate_val, adjugate_val, update_row_transpose, det_transpose], apply finset.sum_congr rfl, intros σ _, congr' 1, by_cases i = σ j, { -- Everything except `(i , j)` (= `(σ j , j)`) is given by A, and the rest is a single `1`. congr; ext j', have := (@equiv.injective _ _ σ j j' : σ j = σ j' → j = j'), rw [update_row_val, update_column_val], finish }, { -- Otherwise, we need to show that there is a `0` somewhere in the product. have : (∏ j' : n, update_column A j (λ (i' : n), ite (i = i') 1 0) (σ j') j') = 0, { apply prod_eq_zero (mem_univ j), rw [update_column_self], exact if_neg h }, rw this, apply prod_eq_zero (mem_univ (σ⁻¹ i)), erw [apply_symm_apply σ i, update_row_self], apply if_neg, intro h', exact h ((symm_apply_eq σ).mp h'.symm) } end lemma mul_adjugate_val (A : matrix n n α) (i j k) : A i k * adjugate A k j = cramer α A (λ j, if k = j then A i k else 0) j := begin erw [←smul_eq_mul, ←pi.smul_apply, ←linear_map.map_smul], congr, ext, rw [pi.smul_apply, smul_eq_mul, mul_boole], end lemma mul_adjugate (A : matrix n n α) : A ⬝ adjugate A = A.det • 1 := begin ext i j, rw [mul_val, smul_val, one_val, mul_boole], calc ∑ k : n, A i k * adjugate A k j = ∑ k : n, cramer α A (λ j, if k = j then A i k else 0) j : by {congr, ext k, apply mul_adjugate_val A i j k} ... = cramer α A (λ j, ∑ k : n, if k = j then A i k else 0) j : sum_cramer_apply A univ (λ (j k : n), if k = j then A i k else 0) j ... = cramer α A (A i) j : by { rw [cramer_apply], congr, ext, rw [sum_ite_eq' univ x (A i), if_pos (mem_univ _)] } ... = if i = j then det A else 0 : by rw [cramer_column_self] end lemma adjugate_mul (A : matrix n n α) : adjugate A ⬝ A = A.det • 1 := calc adjugate A ⬝ A = (Aᵀ ⬝ (adjugate Aᵀ))ᵀ : by rw [←adjugate_transpose, ←transpose_mul, transpose_transpose] ... = A.det • 1 : by rw [mul_adjugate (Aᵀ), det_transpose, transpose_smul, transpose_one] /-- `det_adjugate_of_cancel` is an auxiliary lemma for computing `(adjugate A).det`, used in `det_adjugate_eq_one` and `det_adjugate_of_is_unit`. The formula for the determinant of the adjugate of an `n` by `n` matrix `A` is in general `(adjugate A).det = A.det ^ (n - 1)`, but the proof differs in several cases. This lemma `det_adjugate_of_cancel` covers the case that `det A` cancels on the left of the equation `A.det * b = A.det ^ n`. -/ lemma det_adjugate_of_cancel {A : matrix n n α} (h : ∀ b, A.det * b = A.det ^ fintype.card n → b = A.det ^ (fintype.card n - 1)) : (adjugate A).det = A.det ^ (fintype.card n - 1) := h (adjugate A).det (calc A.det * (adjugate A).det = (A ⬝ adjugate A).det : (det_mul _ _).symm ... = A.det ^ fintype.card n : by simp [mul_adjugate]) lemma adjugate_eq_one_of_card_eq_one {A : matrix n n α} (h : fintype.card n = 1) : adjugate A = 1 := begin ext i j, have univ_eq_i := univ_eq_singleton_of_card_one i h, have univ_eq_j := univ_eq_singleton_of_card_one j h, have i_eq_j : i = j := singleton_inj.mp (by rw [←univ_eq_i, univ_eq_j]), 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 [adjugate_val, det, univ_eq_i, perm_eq, i_eq_j] end @[simp] lemma adjugate_zero (h : 1 < fintype.card n) : adjugate (0 : matrix n n α) = 0 := begin ext i j, obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := fintype.exists_ne_of_one_lt_card h j, apply det_eq_zero_of_column_eq_zero j', intro j'', simp [update_row_ne hj'] end lemma det_adjugate_eq_one {A : matrix n n α} (h : A.det = 1) : (adjugate A).det = 1 := calc (adjugate A).det = A.det ^ (fintype.card n - 1) : det_adjugate_of_cancel (λ b hb, by simpa [h] using hb) ... = 1 : by rw [h, one_pow] /-- `det_adjugate_of_is_unit` gives the formula for `(adjugate A).det` if `A.det` has an inverse. The formula for the determinant of the adjugate of an `n` by `n` matrix `A` is in general `(adjugate A).det = A.det ^ (n - 1)`, but the proof differs in several cases. This lemma `det_adjugate_of_is_unit` covers the case that `det A` has an inverse. -/ lemma det_adjugate_of_is_unit {A : matrix n n α} (h : is_unit A.det) : (adjugate A).det = A.det ^ (fintype.card n - 1) := begin rcases is_unit_iff_exists_inv'.mp h with ⟨a, ha⟩, by_cases card_lt_zero : fintype.card n ≤ 0, { have h : fintype.card n = 0 := by linarith, simp [det_eq_one_of_card_eq_zero h] }, have zero_lt_card : 0 < fintype.card n := by linarith, have n_nonempty : nonempty n := fintype.card_pos_iff.mp zero_lt_card, by_cases card_lt_one : fintype.card n ≤ 1, { have h : fintype.card n = 1 := by linarith, simp [h, adjugate_eq_one_of_card_eq_one h] }, have one_lt_card : 1 < fintype.card n := by linarith, have zero_lt_card_sub_one : 0 < fintype.card n - 1 := (nat.sub_lt_sub_right_iff (refl 1)).mpr one_lt_card, apply det_adjugate_of_cancel, intros b hb, calc b = a * (det A ^ (fintype.card n - 1 + 1)) : by rw [←one_mul b, ←ha, mul_assoc, hb, nat.sub_add_cancel zero_lt_card] ... = a * det A * det A ^ (fintype.card n - 1) : by ring_exp ... = det A ^ (fintype.card n - 1) : by rw [ha, one_mul] end end adjugate section inv /-! ### `inv` section Defines the matrix `nonsing_inv A` and proves it is the inverse matrix of a square matrix `A` as long as `det A` has a multiplicative inverse. -/ variables [comm_ring α] variables (A : matrix n n α) open_locale classical lemma is_unit_det_transpose (h : is_unit A.det) : is_unit Aᵀ.det := by { rw det_transpose, exact h, } /-- The inverse of a square matrix, when it is invertible (and zero otherwise).-/ noncomputable def nonsing_inv : matrix n n α := if h : is_unit A.det then (↑h.unit⁻¹ : α) • A.adjugate else 0 noncomputable instance : has_inv (matrix n n α) := ⟨matrix.nonsing_inv⟩ lemma nonsing_inv_apply (h : is_unit A.det) : A⁻¹ = (↑h.unit⁻¹ : α) • A.adjugate := by { change A.nonsing_inv = _, dunfold nonsing_inv, simp only [dif_pos, h], } lemma transpose_nonsing_inv (h : is_unit A.det) : (A⁻¹)ᵀ = (Aᵀ)⁻¹ := begin have h' := A.is_unit_det_transpose h, have dets_eq : (↑h.unit : α) = ↑h'.unit := by rw [h.unit_spec, h'.unit_spec, det_transpose], rw [A.nonsing_inv_apply h, Aᵀ.nonsing_inv_apply h', units.inv_unique dets_eq, A.adjugate_transpose.symm], refl, end /-- The `nonsing_inv` of `A` is a right inverse. -/ @[simp] lemma mul_nonsing_inv (h : is_unit A.det) : A ⬝ A⁻¹ = 1 := by rw [A.nonsing_inv_apply h, mul_smul, mul_adjugate, smul_smul, units.inv_mul_of_eq h.unit_spec, one_smul] /-- The `nonsing_inv` of `A` is a left inverse. -/ @[simp] lemma nonsing_inv_mul (h : is_unit A.det) : A⁻¹ ⬝ A = 1 := calc A⁻¹ ⬝ A = (Aᵀ ⬝ (Aᵀ)⁻¹)ᵀ : by { rw [transpose_mul, Aᵀ.transpose_nonsing_inv (A.is_unit_det_transpose h), transpose_transpose], } ... = 1ᵀ : by { rw Aᵀ.mul_nonsing_inv, exact A.is_unit_det_transpose h, } ... = 1 : transpose_one @[simp] lemma nonsing_inv_det (h : is_unit A.det) : A⁻¹.det * A.det = 1 := by rw [←det_mul, A.nonsing_inv_mul h, det_one] lemma is_unit_nonsing_inv_det (h : is_unit A.det) : is_unit A⁻¹.det := is_unit_of_mul_eq_one _ _ (A.nonsing_inv_det h) @[simp] lemma nonsing_inv_nonsing_inv (h : is_unit A.det) : (A⁻¹)⁻¹ = A := calc (A⁻¹)⁻¹ = 1 ⬝ (A⁻¹)⁻¹ : by rw matrix.one_mul ... = A ⬝ A⁻¹ ⬝ (A⁻¹)⁻¹ : by rw A.mul_nonsing_inv h ... = A : by { rw [matrix.mul_assoc, (A⁻¹).mul_nonsing_inv (A.is_unit_nonsing_inv_det h), matrix.mul_one], } /-- A matrix whose determinant is a unit is itself a unit. -/ noncomputable def nonsing_inv_unit (h : is_unit A.det) : units (matrix n n α) := { val := A, inv := A⁻¹, val_inv := by { rw matrix.mul_eq_mul, apply A.mul_nonsing_inv h, }, inv_val := by { rw matrix.mul_eq_mul, apply A.nonsing_inv_mul h, } } lemma is_unit_iff_is_unit_det : is_unit A ↔ is_unit A.det := begin split; intros h, { -- is_unit A → is_unit A.det suffices : ∃ (B : matrix n n α), A ⬝ B = 1, { rcases this with ⟨B, hB⟩, apply is_unit_of_mul_eq_one _ B.det, rw [←det_mul, hB, det_one], }, refine ⟨↑h.unit⁻¹, _⟩, conv_lhs { congr, rw ←h.unit_spec, }, exact h.unit.mul_inv, }, { -- is_unit A.det → is_unit A exact is_unit_unit (A.nonsing_inv_unit h), }, end end inv end matrix
26677f7ea44ec78ad514f6b04b03808dcc421ddc
737dc4b96c97368cb66b925eeea3ab633ec3d702
/src/Lean/Elab/Binders.lean
7cbcca74333fe630689731dd71adcd48e7b38c8a
[ "Apache-2.0" ]
permissive
Bioye97/lean4
1ace34638efd9913dc5991443777b01a08983289
bc3900cbb9adda83eed7e6affeaade7cfd07716d
refs/heads/master
1,690,589,820,211
1,631,051,000,000
1,631,067,598,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
26,438
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Elab.Quotation.Precheck import Lean.Elab.Term import Lean.Elab.BindersUtil import Lean.Parser.Term namespace Lean.Elab.Term open Meta open Lean.Parser.Term /-- Given syntax of the forms a) (`:` term)? b) `:` term return `term` if it is present, or a hole if not. -/ private def expandBinderType (ref : Syntax) (stx : Syntax) : Syntax := if stx.getNumArgs == 0 then mkHole ref else stx[1] /-- Given syntax of the form `ident <|> hole`, return `ident`. If `hole`, then we create a new anonymous name. -/ private def expandBinderIdent (stx : Syntax) : TermElabM Syntax := match stx with | `(_) => mkFreshIdent stx | _ => pure stx /-- Given syntax of the form `(ident >> " : ")?`, return `ident`, or a new instance name. -/ private def expandOptIdent (stx : Syntax) : TermElabM Syntax := do if stx.isNone then let id ← withFreshMacroScope <| MonadQuotation.addMacroScope `inst return mkIdentFrom stx id else return stx[0] structure BinderView where id : Syntax type : Syntax bi : BinderInfo partial def quoteAutoTactic : Syntax → TermElabM Syntax | stx@(Syntax.ident _ _ _ _) => throwErrorAt stx "invalid auto tactic, identifier is not allowed" | stx@(Syntax.node k args) => do if stx.isAntiquot then throwErrorAt stx "invalid auto tactic, antiquotation is not allowed" else let mut quotedArgs ← `(Array.empty) for arg in args do if k == nullKind && (arg.isAntiquotSuffixSplice || arg.isAntiquotSplice) then throwErrorAt arg "invalid auto tactic, antiquotation is not allowed" else let quotedArg ← quoteAutoTactic arg quotedArgs ← `(Array.push $quotedArgs $quotedArg) `(Syntax.node $(quote k) $quotedArgs) | Syntax.atom info val => `(mkAtom $(quote val)) | Syntax.missing => unreachable! def declareTacticSyntax (tactic : Syntax) : TermElabM Name := withFreshMacroScope do let name ← MonadQuotation.addMacroScope `_auto let type := Lean.mkConst `Lean.Syntax let tactic ← quoteAutoTactic tactic let val ← elabTerm tactic type let val ← instantiateMVars val trace[Elab.autoParam] val let decl := Declaration.defnDecl { name := name, levelParams := [], type := type, value := val, hints := ReducibilityHints.opaque, safety := DefinitionSafety.safe } addDecl decl compileDecl decl return name /- Expand `optional (binderTactic <|> binderDefault)` def binderTactic := leading_parser " := " >> " by " >> tacticParser def binderDefault := leading_parser " := " >> termParser -/ private def expandBinderModifier (type : Syntax) (optBinderModifier : Syntax) : TermElabM Syntax := do if optBinderModifier.isNone then return type else let modifier := optBinderModifier[0] let kind := modifier.getKind if kind == `Lean.Parser.Term.binderDefault then let defaultVal := modifier[1] `(optParam $type $defaultVal) else if kind == `Lean.Parser.Term.binderTactic then let tac := modifier[2] let name ← declareTacticSyntax tac `(autoParam $type $(mkIdentFrom tac name)) else throwUnsupportedSyntax private def getBinderIds (ids : Syntax) : TermElabM (Array Syntax) := ids.getArgs.mapM fun id => let k := id.getKind if k == identKind || k == `Lean.Parser.Term.hole then return id else throwErrorAt id "identifier or `_` expected" private def matchBinder (stx : Syntax) : TermElabM (Array BinderView) := do let k := stx.getKind if k == ``Lean.Parser.Term.simpleBinder then -- binderIdent+ >> optType let ids ← getBinderIds stx[0] let optType := stx[1] ids.mapM fun id => do pure { id := (← expandBinderIdent id), type := expandOptType id optType, bi := BinderInfo.default } else if k == ``Lean.Parser.Term.explicitBinder then -- `(` binderIdent+ binderType (binderDefault <|> binderTactic)? `)` let ids ← getBinderIds stx[1] let type := stx[2] let optModifier := stx[3] ids.mapM fun id => do pure { id := (← expandBinderIdent id), type := (← expandBinderModifier (expandBinderType id type) optModifier), bi := BinderInfo.default } else if k == ``Lean.Parser.Term.implicitBinder then -- `{` binderIdent+ binderType `}` let ids ← getBinderIds stx[1] let type := stx[2] ids.mapM fun id => do pure { id := (← expandBinderIdent id), type := expandBinderType id type, bi := BinderInfo.implicit } else if k == ``Lean.Parser.Term.strictImplicitBinder then -- `⦃` binderIdent+ binderType `⦄` let ids ← getBinderIds stx[1] let type := stx[2] ids.mapM fun id => do pure { id := (← expandBinderIdent id), type := expandBinderType id type, bi := BinderInfo.strictImplicit } else if k == ``Lean.Parser.Term.instBinder then -- `[` optIdent type `]` let id ← expandOptIdent stx[1] let type := stx[2] pure #[ { id := id, type := type, bi := BinderInfo.instImplicit } ] else throwUnsupportedSyntax private def registerFailedToInferBinderTypeInfo (type : Expr) (ref : Syntax) : TermElabM Unit := registerCustomErrorIfMVar type ref "failed to infer binder type" private def addLocalVarInfo (stx : Syntax) (fvar : Expr) : TermElabM Unit := do addTermInfo (isBinder := true) stx fvar private def ensureAtomicBinderName (binderView : BinderView) : TermElabM Unit := let n := binderView.id.getId.eraseMacroScopes unless n.isAtomic do throwErrorAt binderView.id "invalid binder name '{n}', it must be atomic" register_builtin_option checkBinderAnnotations : Bool := { defValue := true descr := "check whether type is a class instance whenever the binder annotation `[...]` is used" } private partial def elabBinderViews {α} (binderViews : Array BinderView) (fvars : Array Expr) (k : Array Expr → TermElabM α) : TermElabM α := let rec loop (i : Nat) (fvars : Array Expr) : TermElabM α := do if h : i < binderViews.size then let binderView := binderViews.get ⟨i, h⟩ ensureAtomicBinderName binderView let type ← elabType binderView.type registerFailedToInferBinderTypeInfo type binderView.type if binderView.bi.isInstImplicit && checkBinderAnnotations.get (← getOptions) then unless (← isClass? type).isSome do throwErrorAt binderView.type "invalid binder annotation, type is not a class instance{indentExpr type}\nuse the command `set_option checkBinderAnnotations false` to disable the check" withLocalDecl binderView.id.getId binderView.bi type fun fvar => do addLocalVarInfo binderView.id fvar loop (i+1) (fvars.push fvar) else k fvars loop 0 fvars private partial def elabBindersAux {α} (binders : Array Syntax) (k : Array Expr → TermElabM α) : TermElabM α := let rec loop (i : Nat) (fvars : Array Expr) : TermElabM α := do if h : i < binders.size then let binderViews ← matchBinder (binders.get ⟨i, h⟩) elabBinderViews binderViews fvars <| loop (i+1) else k fvars loop 0 #[] /-- Elaborate the given binders (i.e., `Syntax` objects for `simpleBinder <|> bracketedBinder`), update the local context, set of local instances, reset instance chache (if needed), and then execute `x` with the updated context. -/ def elabBinders {α} (binders : Array Syntax) (k : Array Expr → TermElabM α) : TermElabM α := withoutPostponingUniverseConstraints do if binders.isEmpty then k #[] else elabBindersAux binders k def elabBinder {α} (binder : Syntax) (x : Expr → TermElabM α) : TermElabM α := elabBinders #[binder] fun fvars => x fvars[0] @[builtinTermElab «forall»] def elabForall : TermElab := fun stx _ => match stx with | `(forall $binders*, $term) => elabBinders binders fun xs => do let e ← elabType term mkForallFVars xs e | _ => throwUnsupportedSyntax @[builtinTermElab arrow] def elabArrow : TermElab := fun stx _ => match stx with | `($dom:term -> $rng) => do -- elaborate independently from each other let dom ← elabType dom let rng ← elabType rng mkForall (← MonadQuotation.addMacroScope `a) BinderInfo.default dom rng | _ => throwUnsupportedSyntax @[builtinTermElab depArrow] def elabDepArrow : TermElab := fun stx _ => -- bracketedBinder `->` term let binder := stx[0] let term := stx[2] elabBinders #[binder] fun xs => do mkForallFVars xs (← elabType term) /-- Auxiliary functions for converting `id_1 ... id_n` application into `#[id_1, ..., id_m]` It is used at `expandFunBinders`. -/ private partial def getFunBinderIds? (stx : Syntax) : OptionT MacroM (Array Syntax) := let convertElem (stx : Syntax) : OptionT MacroM Syntax := match stx with | `(_) => do let ident ← mkFreshIdent stx; pure ident | `($id:ident) => return id | _ => failure match stx with | `($f $args*) => do let mut acc := #[].push (← convertElem f) for arg in args do acc := acc.push (← convertElem arg) return acc | _ => return #[].push (← convertElem stx) /-- Auxiliary function for expanding `fun` notation binders. Recall that `fun` parser is defined as ``` def funBinder : Parser := implicitBinder <|> instBinder <|> termParser maxPrec leading_parser unicodeSymbol "λ" "fun" >> many1 funBinder >> "=>" >> termParser ``` to allow notation such as `fun (a, b) => a + b`, where `(a, b)` should be treated as a pattern. The result is a pair `(explicitBinders, newBody)`, where `explicitBinders` is syntax of the form ``` `(` ident `:` term `)` ``` which can be elaborated using `elabBinders`, and `newBody` is the updated `body` syntax. We update the `body` syntax when expanding the pattern notation. Example: `fun (a, b) => a + b` expands into `fun _a_1 => match _a_1 with | (a, b) => a + b`. See local function `processAsPattern` at `expandFunBindersAux`. The resulting `Bool` is true if a pattern was found. We use it "mark" a macro expansion. -/ partial def expandFunBinders (binders : Array Syntax) (body : Syntax) : MacroM (Array Syntax × Syntax × Bool) := let rec loop (body : Syntax) (i : Nat) (newBinders : Array Syntax) := do if h : i < binders.size then let binder := binders.get ⟨i, h⟩ let processAsPattern : Unit → MacroM (Array Syntax × Syntax × Bool) := fun _ => do let pattern := binder let major ← mkFreshIdent binder let (binders, newBody, _) ← loop body (i+1) (newBinders.push $ mkExplicitBinder major (mkHole binder)) let newBody ← `(match $major:ident with | $pattern => $newBody) pure (binders, newBody, true) match binder with | Syntax.node ``Lean.Parser.Term.implicitBinder _ => loop body (i+1) (newBinders.push binder) | Syntax.node ``Lean.Parser.Term.strictImplicitBinder _ => loop body (i+1) (newBinders.push binder) | Syntax.node ``Lean.Parser.Term.instBinder _ => loop body (i+1) (newBinders.push binder) | Syntax.node ``Lean.Parser.Term.explicitBinder _ => loop body (i+1) (newBinders.push binder) | Syntax.node ``Lean.Parser.Term.simpleBinder _ => loop body (i+1) (newBinders.push binder) | Syntax.node ``Lean.Parser.Term.hole _ => let ident ← mkFreshIdent binder let type := binder loop body (i+1) (newBinders.push <| mkExplicitBinder ident type) | Syntax.node ``Lean.Parser.Term.paren args => -- `(` (termParser >> parenSpecial)? `)` -- parenSpecial := (tupleTail <|> typeAscription)? let binderBody := binder[1] if binderBody.isNone then processAsPattern () else let idents := binderBody[0] let special := binderBody[1] if special.isNone then processAsPattern () else if special[0].getKind != `Lean.Parser.Term.typeAscription then processAsPattern () else -- typeAscription := `:` term let type := special[0][1] match (← getFunBinderIds? idents) with | some idents => loop body (i+1) (newBinders ++ idents.map (fun ident => mkExplicitBinder ident type)) | none => processAsPattern () | Syntax.ident .. => let type := mkHole binder loop body (i+1) (newBinders.push <| mkExplicitBinder binder type) | _ => processAsPattern () else pure (newBinders, body, false) loop body 0 #[] namespace FunBinders structure State where fvars : Array Expr := #[] lctx : LocalContext localInsts : LocalInstances expectedType? : Option Expr := none private def propagateExpectedType (fvar : Expr) (fvarType : Expr) (s : State) : TermElabM State := do match s.expectedType? with | none => pure s | some expectedType => let expectedType ← whnfForall expectedType match expectedType with | Expr.forallE _ d b _ => discard <| isDefEq fvarType d let b := b.instantiate1 fvar pure { s with expectedType? := some b } | _ => pure { s with expectedType? := none } private partial def elabFunBinderViews (binderViews : Array BinderView) (i : Nat) (s : State) : TermElabM State := do if h : i < binderViews.size then let binderView := binderViews.get ⟨i, h⟩ ensureAtomicBinderName binderView withRef binderView.type <| withLCtx s.lctx s.localInsts do let type ← elabType binderView.type registerFailedToInferBinderTypeInfo type binderView.type let fvarId ← mkFreshFVarId let fvar := mkFVar fvarId let s := { s with fvars := s.fvars.push fvar } -- dbgTrace (toString binderView.id.getId ++ " : " ++ toString type) /- We do **not** want to support default and auto arguments in lambda abstractions. Example: `fun (x : Nat := 10) => x+1`. We do not believe this is an useful feature, and it would complicate the logic here. -/ let lctx := s.lctx.mkLocalDecl fvarId binderView.id.getId type binderView.bi addTermInfo (lctx? := some lctx) (isBinder := true) binderView.id fvar let s ← withRef binderView.id <| propagateExpectedType fvar type s let s := { s with lctx := lctx } match (← isClass? type) with | none => elabFunBinderViews binderViews (i+1) s | some className => resettingSynthInstanceCache do let localInsts := s.localInsts.push { className := className, fvar := mkFVar fvarId } elabFunBinderViews binderViews (i+1) { s with localInsts := localInsts } else pure s partial def elabFunBindersAux (binders : Array Syntax) (i : Nat) (s : State) : TermElabM State := do if h : i < binders.size then let binderViews ← matchBinder (binders.get ⟨i, h⟩) let s ← elabFunBinderViews binderViews 0 s elabFunBindersAux binders (i+1) s else pure s end FunBinders def elabFunBinders {α} (binders : Array Syntax) (expectedType? : Option Expr) (x : Array Expr → Option Expr → TermElabM α) : TermElabM α := if binders.isEmpty then x #[] expectedType? else do let lctx ← getLCtx let localInsts ← getLocalInstances let s ← FunBinders.elabFunBindersAux binders 0 { lctx := lctx, localInsts := localInsts, expectedType? := expectedType? } resettingSynthInstanceCacheWhen (s.localInsts.size > localInsts.size) <| withLCtx s.lctx s.localInsts <| x s.fvars s.expectedType? /- Helper function for `expandEqnsIntoMatch` -/ private def getMatchAltsNumPatterns (matchAlts : Syntax) : Nat := let alt0 := matchAlts[0][0] let pats := alt0[1].getSepArgs pats.size def expandWhereDecls (whereDecls : Syntax) (body : Syntax) : MacroM Syntax := match whereDecls with | `(whereDecls|where $[$decls:letRecDecl $[;]?]*) => `(let rec $decls:letRecDecl,*; $body) | _ => Macro.throwUnsupported def expandWhereDeclsOpt (whereDeclsOpt : Syntax) (body : Syntax) : MacroM Syntax := if whereDeclsOpt.isNone then body else expandWhereDecls whereDeclsOpt[0] body /- Helper function for `expandMatchAltsIntoMatch` -/ private def expandMatchAltsIntoMatchAux (matchAlts : Syntax) (matchTactic : Bool) : Nat → Array Syntax → MacroM Syntax | 0, discrs => do if matchTactic then `(tactic|match $[$discrs:term],* with $matchAlts:matchAlts) else `(match $[$discrs:term],* with $matchAlts:matchAlts) | n+1, discrs => withFreshMacroScope do let x ← `(x) let d ← `(@$x:ident) -- See comment below let body ← expandMatchAltsIntoMatchAux matchAlts matchTactic n (discrs.push d) if matchTactic then `(tactic| intro $x:term; $body:tactic) else `(@fun $x => $body) /-- Expand `matchAlts` syntax into a full `match`-expression. Example ``` | 0, true => alt_1 | i, _ => alt_2 ``` expands into (for tactic == false) ``` fun x_1 x_2 => match @x_1, @x_2 with | 0, true => alt_1 | i, _ => alt_2 ``` and (for tactic == true) ``` intro x_1; intro x_2; match @x_1, @x_2 with | 0, true => alt_1 | i, _ => alt_2 ``` Remark: we add `@` to make sure we don't consume implicit arguments, and to make the behavior consistent with `fun`. Example: ``` inductive T : Type 1 := | mkT : (forall {a : Type}, a -> a) -> T def makeT (f : forall {a : Type}, a -> a) : T := mkT f def makeT' : (forall {a : Type}, a -> a) -> T | f => mkT f ``` The two definitions should be elaborated without errors and be equivalent. -/ def expandMatchAltsIntoMatch (ref : Syntax) (matchAlts : Syntax) (tactic := false) : MacroM Syntax := withRef ref <| expandMatchAltsIntoMatchAux matchAlts tactic (getMatchAltsNumPatterns matchAlts) #[] def expandMatchAltsIntoMatchTactic (ref : Syntax) (matchAlts : Syntax) : MacroM Syntax := withRef ref <| expandMatchAltsIntoMatchAux matchAlts true (getMatchAltsNumPatterns matchAlts) #[] /-- Similar to `expandMatchAltsIntoMatch`, but supports an optional `where` clause. Expand `matchAltsWhereDecls` into `let rec` + `match`-expression. Example ``` | 0, true => ... f 0 ... | i, _ => ... f i + g i ... where f x := g x + 1 g : Nat → Nat | 0 => 1 | x+1 => f x ``` expands into ``` fux x_1 x_2 => let rec f x := g x + 1, g : Nat → Nat | 0 => 1 | x+1 => f x match x_1, x_2 with | 0, true => ... f 0 ... | i, _ => ... f i + g i ... ``` -/ def expandMatchAltsWhereDecls (matchAltsWhereDecls : Syntax) : MacroM Syntax := let matchAlts := matchAltsWhereDecls[0] let whereDeclsOpt := matchAltsWhereDecls[1] let rec loop (i : Nat) (discrs : Array Syntax) : MacroM Syntax := match i with | 0 => do let matchStx ← `(match $[$discrs:term],* with $matchAlts:matchAlts) if whereDeclsOpt.isNone then return matchStx else expandWhereDeclsOpt whereDeclsOpt matchStx | n+1 => withFreshMacroScope do let d ← `(@x) -- See comment at `expandMatchAltsIntoMatch` let body ← loop n (discrs.push d) `(@fun x => $body) loop (getMatchAltsNumPatterns matchAlts) #[] @[builtinMacro Lean.Parser.Term.fun] partial def expandFun : Macro | `(fun $binders* => $body) => do let (binders, body, expandedPattern) ← expandFunBinders binders body if expandedPattern then `(fun $binders* => $body) else Macro.throwUnsupported | stx@`(fun $m:matchAlts) => expandMatchAltsIntoMatch stx m | _ => Macro.throwUnsupported open Lean.Elab.Term.Quotation in @[builtinQuotPrecheck Lean.Parser.Term.fun] def precheckFun : Precheck | `(fun $binders* => $body) => do let (binders, body, expandedPattern) ← liftMacroM <| expandFunBinders binders body let mut ids := #[] for b in binders do for v in ← matchBinder b do Quotation.withNewLocals ids <| precheck v.type ids := ids.push v.id.getId Quotation.withNewLocals ids <| precheck body | _ => throwUnsupportedSyntax @[builtinTermElab «fun»] partial def elabFun : TermElab := fun stx expectedType? => match stx with | `(fun $binders* => $body) => do -- We can assume all `match` binders have been iteratively expanded by the above macro here, though -- we still need to call `expandFunBinders` once to obtain `binders` in a normal form -- expected by `elabFunBinder`. let (binders, body, expandedPattern) ← liftMacroM <| expandFunBinders binders body elabFunBinders binders expectedType? fun xs expectedType? => do /- We ensure the expectedType here since it will force coercions to be applied if needed. If we just use `elabTerm`, then we will need to a coercion `Coe (α → β) (α → δ)` whenever there is a coercion `Coe β δ`, and another instance for the dependent version. -/ let e ← elabTermEnsuringType body expectedType? mkLambdaFVars xs e | _ => throwUnsupportedSyntax /- If `useLetExpr` is true, then a kernel let-expression `let x : type := val; body` is created. Otherwise, we create a term of the form `(fun (x : type) => body) val` The default elaboration order is `binders`, `typeStx`, `valStx`, and `body`. If `elabBodyFirst == true`, then we use the order `binders`, `typeStx`, `body`, and `valStx`. -/ def elabLetDeclAux (id : Syntax) (binders : Array Syntax) (typeStx : Syntax) (valStx : Syntax) (body : Syntax) (expectedType? : Option Expr) (useLetExpr : Bool) (elabBodyFirst : Bool) : TermElabM Expr := do let (type, val, arity) ← elabBinders binders fun xs => do let type ← elabType typeStx registerCustomErrorIfMVar type typeStx "failed to infer 'let' declaration type" if elabBodyFirst then let type ← mkForallFVars xs type let val ← mkFreshExprMVar type pure (type, val, xs.size) else let val ← elabTermEnsuringType valStx type let type ← mkForallFVars xs type /- By default `mkLambdaFVars` and `mkLetFVars` create binders only for let-declarations that are actually used in the body. This generates counterintuitive behavior in the elaborator since users will not be notified about holes such as ``` def ex : Nat := let x := _ 42 ``` -/ let val ← mkLambdaFVars xs val (usedLetOnly := false) pure (type, val, xs.size) trace[Elab.let.decl] "{id.getId} : {type} := {val}" let result ← if useLetExpr then withLetDecl id.getId type val fun x => do addLocalVarInfo id x let body ← elabTermEnsuringType body expectedType? let body ← instantiateMVars body mkLetFVars #[x] body (usedLetOnly := false) else let f ← withLocalDecl id.getId BinderInfo.default type fun x => do addLocalVarInfo id x let body ← elabTermEnsuringType body expectedType? let body ← instantiateMVars body mkLambdaFVars #[x] body (usedLetOnly := false) pure <| mkApp f val if elabBodyFirst then forallBoundedTelescope type arity fun xs type => do let valResult ← elabTermEnsuringType valStx type let valResult ← mkLambdaFVars xs valResult (usedLetOnly := false) unless (← isDefEq val valResult) do throwError "unexpected error when elaborating 'let'" pure result structure LetIdDeclView where id : Syntax binders : Array Syntax type : Syntax value : Syntax def mkLetIdDeclView (letIdDecl : Syntax) : LetIdDeclView := -- `letIdDecl` is of the form `ident >> many bracketedBinder >> optType >> " := " >> termParser let id := letIdDecl[0] let binders := letIdDecl[1].getArgs let optType := letIdDecl[2] let type := expandOptType id optType let value := letIdDecl[4] { id := id, binders := binders, type := type, value := value } def expandLetEqnsDecl (letDecl : Syntax) : MacroM Syntax := do let ref := letDecl let matchAlts := letDecl[3] let val ← expandMatchAltsIntoMatch ref matchAlts return Syntax.node `Lean.Parser.Term.letIdDecl #[letDecl[0], letDecl[1], letDecl[2], mkAtomFrom ref " := ", val] def elabLetDeclCore (stx : Syntax) (expectedType? : Option Expr) (useLetExpr : Bool) (elabBodyFirst : Bool) : TermElabM Expr := do let ref := stx let letDecl := stx[1][0] let body := stx[3] if letDecl.getKind == `Lean.Parser.Term.letIdDecl then let { id := id, binders := binders, type := type, value := val } := mkLetIdDeclView letDecl elabLetDeclAux id binders type val body expectedType? useLetExpr elabBodyFirst else if letDecl.getKind == `Lean.Parser.Term.letPatDecl then -- node `Lean.Parser.Term.letPatDecl $ try (termParser >> pushNone >> optType >> " := ") >> termParser let pat := letDecl[0] let optType := letDecl[2] let type := expandOptType pat optType let val := letDecl[4] let stxNew ← `(let x : $type := $val; match x with | $pat => $body) let stxNew := match useLetExpr, elabBodyFirst with | true, false => stxNew | true, true => stxNew.setKind `Lean.Parser.Term.«let_delayed» | false, false => stxNew.setKind `Lean.Parser.Term.«let_fun» | false, true => unreachable! withMacroExpansion stx stxNew <| elabTerm stxNew expectedType? else if letDecl.getKind == `Lean.Parser.Term.letEqnsDecl then let letDeclIdNew ← liftMacroM <| expandLetEqnsDecl letDecl let declNew := stx[1].setArg 0 letDeclIdNew let stxNew := stx.setArg 1 declNew withMacroExpansion stx stxNew <| elabTerm stxNew expectedType? else throwUnsupportedSyntax @[builtinTermElab «let»] def elabLetDecl : TermElab := fun stx expectedType? => elabLetDeclCore stx expectedType? true false @[builtinTermElab «let_fun»] def elabLetFunDecl : TermElab := fun stx expectedType? => elabLetDeclCore stx expectedType? false false @[builtinTermElab «let_delayed»] def elabLetDelayedDecl : TermElab := fun stx expectedType? => elabLetDeclCore stx expectedType? true true builtin_initialize registerTraceClass `Elab.let end Lean.Elab.Term
a9a303dc63faea027ea536e2ebecdf26d4a56ea4
5ae26df177f810c5006841e9c73dc56e01b978d7
/test/omega.lean
d7a47287bea96dbdd2586bee1331965d81ae0812
[ "Apache-2.0" ]
permissive
ChrisHughes24/mathlib
98322577c460bc6b1fe5c21f42ce33ad1c3e5558
a2a867e827c2a6702beb9efc2b9282bd801d5f9a
refs/heads/master
1,583,848,251,477
1,565,164,247,000
1,565,164,247,000
129,409,993
0
1
Apache-2.0
1,565,164,817,000
1,523,628,059,000
Lean
UTF-8
Lean
false
false
2,455
lean
/- Test cases for omega. Most of the examples are from John Harrison's Handbook of Practical Logic and Automated Reasoning. -/ import tactic.omega example (x : int) : (x = 5 ∨ x = 7) → 2 < x := by omega example (x : int) : x ≤ -x → x ≤ 0 := by omega example : ∀ x y : int, (x ≤ 5 ∧ y ≤ 3) → x + y ≤ 8 := by omega example : ∀ (x y z : int), x < y → y < z → x < z := by omega example (x y z : int) : x - y ≤ x - z → z ≤ y:= by omega example (x : int) (h1 : x = -5 ∨ x = 7) (h2 : x = 0) : false := by omega example : ∀ x : int, 31 * x > 0 → x > 0 := by omega example (x y : int) : (-x - y < x - y) → (x - y < x + y) → (x > 0 ∧ y > 0) := by omega example : ∀ (x : int), (x ≥ -1 ∧ x ≤ 1) → (x = -1 ∨ x = 0 ∨ x = 1) := by omega example : ∀ (x : int), 5 * x = 5 → x = 1 := by omega example (x y : int) : ∀ z w v : int, x = y → y = z → x = z := by omega example : ∀ x : int, x < 349 ∨ x > 123 := by omega example : ∀ x y : int, x ≤ 3 * y → 3 * x ≤ 9 * y := by omega example (x : int) (h1 : x < 43 ∧ x > 513) : false := by omega example (x y z w : int) : x ≤ y → y ≤ z → z ≤ w → x ≤ w:= by omega example (x y z : int) : ∀ w v : int, 100 = x → x = y → y = z → z = w → w = v → v = 100 := by omega example (x : nat) : 31 * x > 0 → x > 0 := by omega example (x y : nat) : (x ≤ 5 ∧ y ≤ 3) → x + y ≤ 8 := by omega example : ∀ (x y z y : nat), ¬(2 * x + 1 = 2 * y) := by omega example : ∀ (x y : nat), x > 0 → x + y > 0 := by omega example : ∀ (x : nat), x < 349 ∨ x > 123 := by omega example : ∀ (x y : nat), (x = 2 ∨ x = 10) → (x = 3 * y) → false := by omega example (x y : nat) : x ≤ 3 * y → 3 * x ≤ 9 * y := by omega example (x y z : nat) : (x ≤ y) → (z > y) → (x - z = 0) := by omega example (x y z : nat) : x - 5 > 122 → y ≤ 127 → y < x := by omega example : ∀ (x y : nat), x ≤ y ↔ x - y = 0 := by omega /- Use `omega manual` to disable automatic reverts, and `omega int` or `omega nat` to specify the domain. -/ example (i : int) (n : nat) (h1 : n = 0) (h2 : i < i) : false := by omega int example (i : int) (n : nat) (h1 : i = 0) (h2 : n < n) : false := by omega nat example (x y z w : int) (h1 : 3 * y ≥ x) (h2 : z > 19 * w) : 3 * x ≤ 9 * y := by {revert h1 x y, omega manual} example (n : nat) (h1 : n < 34) (i : int) (h2 : i * 9 = -72) : i = -8 := by {revert h2 i, omega manual int}
751b6dd60b28502659bd356d765fcee68f526044
90edd5cdcf93124fe15627f7304069fdce3442dd
/src/Lean/Aesop/Tree.lean
614a87f24f79ce35d888afcab5c866df7499c7e9
[ "Apache-2.0" ]
permissive
JLimperg/lean4-aesop
8a9d9cd3ee484a8e67fda2dd9822d76708098712
5c4b9a3e05c32f69a4357c3047c274f4b94f9c71
refs/heads/master
1,689,415,944,104
1,627,383,284,000
1,627,383,284,000
377,536,770
0
0
null
null
null
null
UTF-8
Lean
false
false
14,500
lean
/- Copyright (c) 2021 Jannis Limperg. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jannis Limperg, Asta Halkjær From -/ import Lean.Aesop.MutAltTree import Lean.Aesop.Rule import Lean.Aesop.Util import Lean.Aesop.Tracing open Lean open Lean.Meta @[inlineIfReduce] private def Bool.toYesNo : Bool → Format | true => "yes" | false => "no " namespace Lean.Aesop /-! ## Node IDs -/ structure GoalId where toNat : Nat deriving Inhabited, DecidableEq namespace GoalId protected def zero : GoalId := ⟨0⟩ protected def one : GoalId := ⟨1⟩ protected def succ : GoalId → GoalId | ⟨n⟩ => ⟨n + 1⟩ def dummy : GoalId := ⟨1000000000000000⟩ instance : LT GoalId where lt n m := n.toNat < m.toNat instance : DecidableRel (α := GoalId) (· < ·) := λ n m => inferInstanceAs (Decidable (n.toNat < m.toNat)) instance : ToString GoalId where toString n := toString n.toNat end GoalId /-! ## Rule Application IDs -/ structure RappId where toNat : Nat deriving Inhabited, DecidableEq namespace RappId protected def zero : RappId := ⟨0⟩ protected def succ : RappId → RappId | ⟨n⟩ => ⟨n + 1⟩ protected def one : RappId := ⟨1⟩ def dummy : RappId := ⟨1000000000000000⟩ instance : LT RappId where lt n m := n.toNat < m.toNat instance : DecidableRel (α := RappId) (· < ·) := λ n m => inferInstanceAs $ Decidable (n.toNat < m.toNat) instance : ToString RappId where toString n := toString n.toNat end RappId /-! ## Goal Nodes and Rule Applications -/ inductive ProofStatus | unproven | provenByRuleApplication | provenByNormalization deriving Inhabited, BEq namespace ProofStatus def isProven : ProofStatus → Bool | unproven => false | provenByRuleApplication => true | provenByNormalization => true end ProofStatus -- Invariant: if proofStatus = provenByNormalization then isNormal = true structure GoalData : Type where id : GoalId goal : MVarId successProbability : Percent failedRapps : List RegularRule unsafeQueue : Option (List UnsafeRule) proofStatus : ProofStatus isUnprovable : Bool isIrrelevant : Bool isNormal : Bool deriving Inhabited namespace GoalData def isProven (g : GoalData) : Bool := g.proofStatus.isProven protected structure MessageInfo where showGoal : Bool showUnsafeQueue : Bool showFailedRapps : Bool deriving Inhabited open GoalData (MessageInfo) protected def getMessageInfo [Monad m] [MonadOptions m] (traceCtx : TraceContext) : m MessageInfo := do return { showGoal := (← TraceOption.showGoals.get traceCtx) showUnsafeQueue := (← TraceOption.showUnsafeQueues.get traceCtx) showFailedRapps := (← TraceOption.showFailedRapps.get traceCtx) } open MessageData in protected def toMessageData (traceCtx : TraceContext) (g : GoalData) : MetaM MessageData := do let minfo ← GoalData.getMessageInfo traceCtx let unsafeQueueLength := match g.unsafeQueue with | none => f!"<not selected>" | some q => format q.length return m!"Goal {g.id} [{g.successProbability.toHumanString}]" ++ nodeFiltering #[ m!"Unsafe rules in queue: {unsafeQueueLength}, failed: {g.failedRapps.length}", join [ m!"normal: {g.isNormal.toYesNo} | ", m!"proven: {g.isProven.toYesNo} | ", m!"unprovable: {g.isUnprovable.toYesNo} | ", m!"irrelevant: {g.isIrrelevant.toYesNo}" ], if ¬ minfo.showGoal then none else m!"Goal:{indentD $ ofGoal g.goal}", if ¬ minfo.showUnsafeQueue || g.unsafeQueue.isNone then none else m!"Unsafe queue:{indentDUnlines $ g.unsafeQueue.get!.map toMessageData}", if ¬ minfo.showFailedRapps then none else m!"Failed rule applications:{indentDUnlines $ g.failedRapps.map toMessageData}" ] protected def mkInitial (id : GoalId) (goal : MVarId) (successProbability : Percent) : GoalData where id := id goal := goal successProbability := successProbability failedRapps := [] unsafeQueue := none proofStatus := ProofStatus.unproven isUnprovable := false isIrrelevant := false isNormal := false end GoalData structure RappData : Type where id : RappId state : Meta.SavedState -- This is the state *after* the rule was successfully applied, so the goal -- mvar is assigned in this state. appliedRule : RegularRule successProbability : Percent isProven : Bool isUnprovable : Bool isIrrelevant : Bool deriving Inhabited namespace RappData protected structure MessageInfo where open RappData (MessageInfo) open MessageData in protected def toMessageData [Monad m] [MonadOptions m] (traceCtx : TraceContext) (r : RappData) : m MessageData := do return m!"Rapp {r.id} [{r.successProbability.toHumanString}]" ++ nodeFiltering #[ toMessageData r.appliedRule, join [ m!"proven: {r.isProven.toYesNo} | ", m!"unprovable: {r.isUnprovable.toYesNo} | ", m!"irrelevant: {r.isIrrelevant.toYesNo}" ] ] protected def mkInitial (id : RappId) (state : Meta.SavedState) (appliedRule : RegularRule) (successProbability : Percent) : RappData where id := id state := state appliedRule := appliedRule successProbability := successProbability isProven := false isUnprovable := false isIrrelevant := false end RappData abbrev Goal := MutAltTree IO.RealWorld GoalData RappData abbrev GoalRef := IO.Ref Goal abbrev Rapp := MutAltTree IO.RealWorld RappData GoalData abbrev RappRef := IO.Ref Rapp variable [Monad m] [MonadLiftT (ST IO.RealWorld) m] /-! ## Functions on Goals -/ namespace Goal /-! ### Constructors -/ @[inline] protected def mk (parent : Option RappRef) (rapps : Array RappRef) (data : GoalData) : Goal := MutAltTree.mk data parent rapps /-! ### Getters -/ @[inline] def rapps (g : Goal) : Array RappRef := g.children @[inline] def id (g : Goal) : GoalId := g.payload.id @[inline] def goal (g : Goal) : MVarId := g.payload.goal @[inline] def successProbability (g : Goal) : Percent := g.payload.successProbability @[inline] def failedRapps (g : Goal) : List RegularRule := g.payload.failedRapps @[inline] def unsafeQueue (g : Goal) : Option (List UnsafeRule) := g.payload.unsafeQueue @[inline] def proofStatus (g : Goal) : ProofStatus := g.payload.proofStatus @[inline] def isProven (g : Goal) : Bool := g.payload.isProven @[inline] def isUnprovable (g : Goal) : Bool := g.payload.isUnprovable @[inline] def isIrrelevant (g : Goal) : Bool := g.payload.isIrrelevant @[inline] def isNormal (g : Goal) : Bool := g.payload.isNormal /-! ### Setters -/ @[inline] def setId (id : GoalId) (g : Goal) : Goal := g.modifyPayload λ d => { d with id := id } @[inline] def setGoal (goal : MVarId) (g : Goal) : Goal := g.modifyPayload λ d => { d with goal := goal } @[inline] def setSuccessProbability (successProbability : Percent) (g : Goal) : Goal := g.modifyPayload λ d => { d with successProbability := successProbability } @[inline] def setFailedRapps (failedRapps : List RegularRule) (g : Goal) : Goal := g.modifyPayload λ d => { d with failedRapps := failedRapps } @[inline] def setUnsafeQueue (unsafeQueue : Option (List UnsafeRule)) (g : Goal) : Goal := g.modifyPayload λ d => { d with unsafeQueue := unsafeQueue } @[inline] def setProofStatus (proven? : ProofStatus) (g : Goal) : Goal := g.modifyPayload λ d => { d with proofStatus := proven? } @[inline] def setUnprovable (unprovable? : Bool) (g : Goal) : Goal := g.modifyPayload λ d => { d with isUnprovable := unprovable? } @[inline] def setIrrelevant (irrelevant? : Bool) (g : Goal) : Goal := g.modifyPayload λ d => { d with isIrrelevant := irrelevant? } @[inline] def setNormal (normal? : Bool) (g : Goal) : Goal := g.modifyPayload λ d => { d with isNormal := normal? } /-! ### Miscellaneous -/ def hasNoUnexpandedUnsafeRule (g : Goal) : Bool := match g.unsafeQueue with | none => false | some q => q.isEmpty end Goal /-! ## Functions on Rule Applications -/ namespace Rapp /-! ### Constructors -/ @[inline] protected def mk (parent : Option GoalRef) (subgoals : Array GoalRef) (data : RappData) : Rapp := MutAltTree.mk data parent subgoals /-! ### Getters -/ @[inline] def parent! (r : Rapp) : GoalRef := match r.parent with | some p => p | none => panic! s!"aesop/Rapp.parent!: rapp {r.payload.id} " @[inline] def subgoals (r : Rapp) : Array GoalRef := r.children @[inline] def id (r : Rapp) : RappId := r.payload.id @[inline] def state (r : Rapp) : Meta.SavedState := r.payload.state @[inline] def appliedRule (r : Rapp) : RegularRule := r.payload.appliedRule @[inline] def successProbability (r : Rapp) : Percent := r.payload.successProbability @[inline] def isProven (r : Rapp) : Bool := r.payload.isProven @[inline] def isUnprovable (r : Rapp) : Bool := r.payload.isUnprovable @[inline] def isIrrelevant (r : Rapp) : Bool := r.payload.isIrrelevant -- Setters @[inline] def setId (id : RappId) (r : Rapp) : Rapp := r.modifyPayload λ r => { r with id := id } @[inline] def setState (state : Meta.SavedState) (r : Rapp) : Rapp := r.modifyPayload λ r => { r with state := state } @[inline] def setAppliedRule (appliedRule : RegularRule) (r : Rapp) : Rapp := r.modifyPayload λ r => { r with appliedRule := appliedRule } @[inline] def setSuccessProbability (successProbability : Percent) (r : Rapp) : Rapp := r.modifyPayload λ r => { r with successProbability := successProbability } @[inline] def setProven (proven? : Bool) (r : Rapp) : Rapp := r.modifyPayload λ r => { r with isProven := proven? } @[inline] def setUnprovable (unprovable? : Bool) (r : Rapp) : Rapp := r.modifyPayload λ r => { r with isUnprovable := unprovable? } @[inline] def setIrrelevant (irrelevant? : Bool) (r : Rapp) : Rapp := r.modifyPayload λ r => { r with isIrrelevant := irrelevant? } /-! ### Miscellaneous -/ def allSubgoalsProven (r : Rapp) : m Bool := r.subgoals.allM λ subgoal => return (← subgoal.get).isProven end Rapp /-! ## Formatting -/ mutual private partial def formatTreeGoal (traceCtx : TraceContext) (goal : Goal) : MetaM MessageData := do let goalMsg ← goal.payload.toMessageData traceCtx let childrenMsgs ← goal.rapps.mapM λ c => do formatTreeRapp traceCtx (← c.get) return goalMsg ++ indentD (MessageData.node childrenMsgs) private partial def formatTreeRapp (traceCtx : TraceContext) (rapp : Rapp) : MetaM MessageData := do let rappMsg ← rapp.payload.toMessageData TraceContext.tree let childrenMsgs ← rapp.subgoals.mapM λ c => do formatTreeGoal traceCtx (← c.get) return rappMsg ++ indentD (MessageData.node childrenMsgs) end namespace Goal def toMessageData (traceCtx : TraceContext) (g : Goal) : MetaM MessageData := g.payload.toMessageData traceCtx def treeToMessageData (traceCtx : TraceContext) (g : Goal) : MetaM MessageData := formatTreeGoal traceCtx g end Goal namespace Rapp def toMessageData (traceCtx : TraceContext) (r : Rapp) : MetaM MessageData := r.payload.toMessageData traceCtx def treeToMessageData (traceCtx : TraceContext) (r : Rapp) : MetaM MessageData := do formatTreeRapp traceCtx r end Rapp /-! ## Miscellaneous Functions on Goals -/ namespace Goal def mayHaveUnexpandedRapp (g : Goal) : m Bool := do pure $ ¬ g.hasNoUnexpandedUnsafeRule ∧ ¬ (← g.rapps.anyM λ r => return (← r.get : Rapp).appliedRule.isSafe) def hasProvableRapp (g : Goal) : m Bool := g.rapps.anyM λ r => return ¬ (← r.get).isUnprovable def firstProvenRapp? (g : Goal) : m (Option RappRef) := g.rapps.findSomeM? λ rref => return if (← rref.get).isProven then some rref else none end Goal /-! ## Propagating Provability/Unprovability/Irrelevance -/ @[inline] def setIrrelevantImpl : Sum GoalRef RappRef → m Unit := MutAltTree.visitDown' (λ gref => do let g : Goal ← gref.get if g.isIrrelevant then return false -- Subtree should already be marked as irrelevant. else do gref.set $ g.setIrrelevant true return true) (λ rref => do let r : Rapp ← rref.get if r.isIrrelevant then return false else do rref.set $ r.setIrrelevant true return true) def GoalRef.setIrrelevant : GoalRef → m Unit := setIrrelevantImpl ∘ Sum.inl def RappRef.setIrrelevant : RappRef → m Unit := setIrrelevantImpl ∘ Sum.inr @[inline] private def setProvenImpl : Sum GoalRef RappRef → m Unit := MutAltTree.visitUp' -- Goals are unconditionally marked as proven. (λ gref => do gref.modify λ (g : Goal) => g.setProofStatus ProofStatus.provenByRuleApplication return true) -- Rapps are marked as proven only if they are in fact proven, i.e. if all -- their subgoals are (marked as) proven. In this case, we also need to -- mark siblings of the rapp (and their descendants) as irrelevant. (λ rref => do let r : Rapp ← rref.get if ¬ (← r.allSubgoalsProven) then return false else do rref.set $ r.setProven true let siblings ← MutAltTree.siblings rref siblings.forM RappRef.setIrrelevant return true) def GoalRef.setProven : GoalRef → m Unit := setProvenImpl ∘ Sum.inl def RappRef.setProven : RappRef → m Unit := setProvenImpl ∘ Sum.inr @[inline] private def setUnprovableImpl : Sum GoalRef RappRef → m Unit := MutAltTree.visitUp' -- Goals are marked as unprovable only if they are in fact unprovable, i.e. -- if all their rule applications are unprovable and they do not have -- unexpanded rule applications. In this case, we also need to mark -- siblings of the goal (and their descendants) as irrelevant. (λ gref => do let g : Goal ← gref.get if (← g.mayHaveUnexpandedRapp <||> g.hasProvableRapp) then return false else do gref.set $ g.setUnprovable true let siblings ← MutAltTree.siblings gref siblings.forM GoalRef.setIrrelevant return true) -- Rapps are unconditionally marked as unprovable. (λ rref => do rref.modify λ (r : Rapp) => r.setUnprovable true return true) def GoalRef.setUnprovable : GoalRef → m Unit := setUnprovableImpl ∘ Sum.inl def RappRef.setUnprovable : RappRef → m Unit := setUnprovableImpl ∘ Sum.inr end Lean.Aesop
ded09296fe2549d7097ef199b814c0badccd0974
30b012bb72d640ec30c8fdd4c45fdfa67beb012c
/analysis/polynomial.lean
9268da1a412ced12cef5b2afbc03f42e6897ca98
[ "Apache-2.0" ]
permissive
kckennylau/mathlib
21fb810b701b10d6606d9002a4004f7672262e83
47b3477e20ffb5a06588dd3abb01fe0fe3205646
refs/heads/master
1,634,976,409,281
1,542,042,832,000
1,542,319,733,000
109,560,458
0
0
Apache-2.0
1,542,369,208,000
1,509,867,494,000
Lean
UTF-8
Lean
false
false
941
lean
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Robert Y. Lewis Analytic facts about polynomials. -/ import analysis.topology.topological_structures data.polynomial lemma polynomial.continuous_eval {α} [comm_semiring α] [decidable_eq α] [topological_space α] [topological_semiring α] (p : polynomial α) : continuous (λ x, p.eval x) := begin apply p.induction, { convert continuous_const, ext, show polynomial.eval x 0 = 0, from rfl }, { intros a b f haf hb hcts, simp only [polynomial.eval_add], refine continuous_add _ hcts, have : ∀ x, finsupp.sum (finsupp.single a b) (λ (e : ℕ) (a : α), a * x ^ e) = b * x ^a, from λ x, finsupp.sum_single_index (by simp), convert continuous_mul _ _, { ext, apply this }, { apply_instance }, { apply continuous_const }, { apply continuous_pow }} end
f86625a3f0d2290133a7d67f0d4acb823c44f1af
3f7026ea8bef0825ca0339a275c03b911baef64d
/src/category/bitraversable/instances.lean
8eaad1beedce81d1b7bad54f740c26ab70d095e7
[ "Apache-2.0" ]
permissive
rspencer01/mathlib
b1e3afa5c121362ef0881012cc116513ab09f18c
c7d36292c6b9234dc40143c16288932ae38fdc12
refs/heads/master
1,595,010,346,708
1,567,511,503,000
1,567,511,503,000
206,071,681
0
0
Apache-2.0
1,567,513,643,000
1,567,513,643,000
null
UTF-8
Lean
false
false
4,435
lean
/- Copyright (c) 2019 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author(s): Simon Hudon -/ import category.bitraversable.basic category.bitraversable.lemmas category.traversable.lemmas tactic.solve_by_elim /-! # bitraversable instances ## Instances * prod * sum * const * flip * bicompl * bicompr ## References * Hackage: https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Bitraversable.html ## Tags traversable bitraversable functor bifunctor applicative -/ universes u v w variables {t : Type u → Type u → Type u} [bitraversable t] section variables {F : Type u → Type u} [applicative F] def prod.bitraverse {α α' β β'} (f : α → F α') (f' : β → F β') : α × β → F (α' × β') | (x,y) := prod.mk <$> f x <*> f' y instance : bitraversable prod := { bitraverse := @prod.bitraverse } instance : is_lawful_bitraversable prod := by constructor; introsI; cases x; simp [bitraverse,prod.bitraverse] with functor_norm; refl open functor def sum.bitraverse {α α' β β'} (f : α → F α') (f' : β → F β') : α ⊕ β → F (α' ⊕ β') | (sum.inl x) := sum.inl <$> f x | (sum.inr x) := sum.inr <$> f' x instance : bitraversable sum := { bitraverse := @sum.bitraverse } instance : is_lawful_bitraversable sum := by constructor; introsI; cases x; simp [bitraverse,sum.bitraverse] with functor_norm; refl def const.bitraverse {α α' β β'} (f : α → F α') (f' : β → F β') : const α β → F (const α' β') := f instance bitraversable.const : bitraversable const := { bitraverse := @const.bitraverse } instance is_lawful_bitraversable.const : is_lawful_bitraversable const := by constructor; introsI; simp [bitraverse,const.bitraverse] with functor_norm; refl def flip.bitraverse {α α' β β'} (f : α → F α') (f' : β → F β') : flip t α β → F (flip t α' β') := (bitraverse f' f : t β α → F (t β' α')) instance bitraversable.flip : bitraversable (flip t) := { bitraverse := @flip.bitraverse t _ } variables [is_lawful_bitraversable t] open is_lawful_bitraversable instance is_lawful_bitraversable.flip : is_lawful_bitraversable (flip t) := by constructor; introsI; casesm is_lawful_bitraversable t; apply_assumption open bitraversable functor @[priority 0] instance bitraversable.traversable {α} : traversable (t α) := { traverse := @tsnd t _ _ } @[priority 0] instance bitraversable.is_lawful_traversable [is_lawful_bitraversable t] {α} : is_lawful_traversable (t α) := by { constructor; introsI; simp [traverse,comp_tsnd] with functor_norm, { refl }, { simp [tsnd_eq_snd_id], refl }, { simp [tsnd,binaturality,function.comp] with functor_norm } } end open bifunctor traversable is_lawful_traversable is_lawful_bitraversable open function (bicompl bicompr) section bicompl variables (F G : Type u → Type u) [traversable F] [traversable G] def bicompl.bitraverse {m} [applicative m] {α β α' β'} (f : α → m β) (f' : α' → m β') : bicompl t F G α α' → m (bicompl t F G β β') := (bitraverse (traverse f) (traverse f') : t (F α) (G α') → m _) instance : bitraversable (bicompl t F G) := { bitraverse := @bicompl.bitraverse t _ F G _ _ } instance [is_lawful_traversable F] [is_lawful_traversable G] [is_lawful_bitraversable t] : is_lawful_bitraversable (bicompl t F G) := begin constructor; introsI; simp [bitraverse,bicompl.bitraverse,bimap,traverse_id,bitraverse_id_id,comp_bitraverse] with functor_norm, { simp [traverse_eq_map_id',bitraverse_eq_bimap_id], }, { revert x, dunfold bicompl, simp [binaturality,naturality_pf] } end end bicompl section bicompr variables (F : Type u → Type u) [traversable F] def bicompr.bitraverse {m} [applicative m] {α β α' β'} (f : α → m β) (f' : α' → m β') : bicompr F t α α' → m (bicompr F t β β') := (traverse (bitraverse f f') : F (t α α') → m _) instance : bitraversable (bicompr F t) := { bitraverse := @bicompr.bitraverse t _ F _ } instance [is_lawful_traversable F] [is_lawful_bitraversable t] : is_lawful_bitraversable (bicompr F t) := begin constructor; introsI; simp [bitraverse,bicompr.bitraverse,bitraverse_id_id] with functor_norm, { simp [bitraverse_eq_bimap_id',traverse_eq_map_id'], refl }, { revert x, dunfold bicompr, intro, simp [naturality,binaturality'] } end end bicompr
7cb8037cbb619f96ec266a84ca2d7d8b9de79095
2eab05920d6eeb06665e1a6df77b3157354316ad
/src/data/nat/cast.lean
08921a39a59f14d152c168a42ad8d053e1d63654
[ "Apache-2.0" ]
permissive
ayush1801/mathlib
78949b9f789f488148142221606bf15c02b960d2
ce164e28f262acbb3de6281b3b03660a9f744e3c
refs/heads/master
1,692,886,907,941
1,635,270,866,000
1,635,270,866,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
12,253
lean
/- Copyright (c) 2014 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import algebra.order.field import data.nat.basic /-! # Cast of naturals This file defines the *canonical* homomorphism from the natural numbers into a type `α` with `0`, `1` and `+` (typically an `add_monoid` with one). ## Main declarations * `cast`: Canonical homomorphism `ℕ → α` where `α` has a `0`, `1` and `+`. * `bin_cast`: Binary representation version of `cast`. * `cast_add_monoid_hom`: `cast` bundled as an `add_monoid_hom`. * `cast_ring_hom`: `cast` bundled as a `ring_hom`. ## Implementation note Setting up the coercions priorities is tricky. See Note [coercion into rings]. -/ namespace nat variables {α : Type*} section variables [has_zero α] [has_one α] [has_add α] /-- Canonical homomorphism from `ℕ` to a type `α` with `0`, `1` and `+`. -/ protected def cast : ℕ → α | 0 := 0 | (n+1) := cast n + 1 /-- Computationally friendlier cast than `nat.cast`, using binary representation. -/ protected def bin_cast (n : ℕ) : α := @nat.binary_rec (λ _, α) 0 (λ odd k a, cond odd (a + a + 1) (a + a)) n /-- Coercions such as `nat.cast_coe` that go from a concrete structure such as `ℕ` to an arbitrary ring `α` should be set up as follows: ```lean @[priority 900] instance : has_coe_t ℕ α := ⟨...⟩ ``` It needs to be `has_coe_t` instead of `has_coe` because otherwise type-class inference would loop when constructing the transitive coercion `ℕ → ℕ → ℕ → ...`. The reduced priority is necessary so that it doesn't conflict with instances such as `has_coe_t α (option α)`. For this to work, we reduce the priority of the `coe_base` and `coe_trans` instances because we want the instances for `has_coe_t` to be tried in the following order: 1. `has_coe_t` instances declared in mathlib (such as `has_coe_t α (with_top α)`, etc.) 2. `coe_base`, which contains instances such as `has_coe (fin n) n` 3. `nat.cast_coe : has_coe_t ℕ α` etc. 4. `coe_trans` If `coe_trans` is tried first, then `nat.cast_coe` doesn't get a chance to apply. -/ library_note "coercion into rings" attribute [instance, priority 950] coe_base attribute [instance, priority 500] coe_trans -- see note [coercion into rings] @[priority 900] instance cast_coe : has_coe_t ℕ α := ⟨nat.cast⟩ @[simp, norm_cast] theorem cast_zero : ((0 : ℕ) : α) = 0 := rfl theorem cast_add_one (n : ℕ) : ((n + 1 : ℕ) : α) = n + 1 := rfl @[simp, norm_cast, priority 500] theorem cast_succ (n : ℕ) : ((succ n : ℕ) : α) = n + 1 := rfl @[simp, norm_cast] theorem cast_ite (P : Prop) [decidable P] (m n : ℕ) : (((ite P m n) : ℕ) : α) = ite P (m : α) (n : α) := by { split_ifs; refl, } end @[simp, norm_cast] theorem cast_one [add_monoid α] [has_one α] : ((1 : ℕ) : α) = 1 := zero_add _ @[simp, norm_cast] theorem cast_add [add_monoid α] [has_one α] (m) : ∀ n, ((m + n : ℕ) : α) = m + n | 0 := (add_zero _).symm | (n+1) := show ((m + n : ℕ) : α) + 1 = m + (n + 1), by rw [cast_add n, add_assoc] @[simp] lemma bin_cast_eq [add_monoid α] [has_one α] (n : ℕ) : (nat.bin_cast n : α) = ((n : ℕ) : α) := begin rw nat.bin_cast, apply binary_rec _ _ n, { rw [binary_rec_zero, cast_zero] }, { intros b k h, rw [binary_rec_eq, h], { cases b; simp [bit, bit0, bit1] }, { simp } }, end /-- `coe : ℕ → α` as an `add_monoid_hom`. -/ def cast_add_monoid_hom (α : Type*) [add_monoid α] [has_one α] : ℕ →+ α := { to_fun := coe, map_add' := cast_add, map_zero' := cast_zero } @[simp] lemma coe_cast_add_monoid_hom [add_monoid α] [has_one α] : (cast_add_monoid_hom α : ℕ → α) = coe := rfl @[simp, norm_cast] theorem cast_bit0 [add_monoid α] [has_one α] (n : ℕ) : ((bit0 n : ℕ) : α) = bit0 n := cast_add _ _ @[simp, norm_cast] theorem cast_bit1 [add_monoid α] [has_one α] (n : ℕ) : ((bit1 n : ℕ) : α) = bit1 n := by rw [bit1, cast_add_one, cast_bit0]; refl lemma cast_two {α : Type*} [add_monoid α] [has_one α] : ((2 : ℕ) : α) = 2 := by simp @[simp, norm_cast] theorem cast_pred [add_group α] [has_one α] : ∀ {n}, 0 < n → ((n - 1 : ℕ) : α) = n - 1 | (n+1) h := (add_sub_cancel (n:α) 1).symm @[simp, norm_cast] theorem cast_sub [add_group α] [has_one α] {m n} (h : m ≤ n) : ((n - m : ℕ) : α) = n - m := eq_sub_of_add_eq $ by rw [← cast_add, tsub_add_cancel_of_le h] @[simp, norm_cast] theorem cast_mul [non_assoc_semiring α] (m) : ∀ n, ((m * n : ℕ) : α) = m * n | 0 := (mul_zero _).symm | (n+1) := (cast_add _ _).trans $ show ((m * n : ℕ) : α) + m = m * (n + 1), by rw [cast_mul n, left_distrib, mul_one] @[simp] theorem cast_dvd {α : Type*} [field α] {m n : ℕ} (n_dvd : n ∣ m) (n_nonzero : (n:α) ≠ 0) : ((m / n : ℕ) : α) = m / n := begin rcases n_dvd with ⟨k, rfl⟩, have : n ≠ 0, {rintro rfl, simpa using n_nonzero}, rw nat.mul_div_cancel_left _ (pos_iff_ne_zero.2 this), rw [nat.cast_mul, mul_div_cancel_left _ n_nonzero], end /-- `coe : ℕ → α` as a `ring_hom` -/ def cast_ring_hom (α : Type*) [non_assoc_semiring α] : ℕ →+* α := { to_fun := coe, map_one' := cast_one, map_mul' := cast_mul, .. cast_add_monoid_hom α } @[simp] lemma coe_cast_ring_hom [non_assoc_semiring α] : (cast_ring_hom α : ℕ → α) = coe := rfl lemma cast_commute [non_assoc_semiring α] (n : ℕ) (x : α) : commute ↑n x := nat.rec_on n (commute.zero_left x) $ λ n ihn, ihn.add_left $ commute.one_left x lemma cast_comm [non_assoc_semiring α] (n : ℕ) (x : α) : (n : α) * x = x * n := (cast_commute n x).eq lemma commute_cast [semiring α] (x : α) (n : ℕ) : commute x n := (n.cast_commute x).symm section variables [ordered_semiring α] @[simp] theorem cast_nonneg : ∀ n : ℕ, 0 ≤ (n : α) | 0 := le_refl _ | (n+1) := add_nonneg (cast_nonneg n) zero_le_one @[mono] theorem mono_cast : monotone (coe : ℕ → α) := λ m n h, let ⟨k, hk⟩ := le_iff_exists_add.1 h in by simp [hk] variable [nontrivial α] theorem strict_mono_cast : strict_mono (coe : ℕ → α) := λ m n h, nat.le_induction (lt_add_of_pos_right _ zero_lt_one) (λ n _ h, lt_add_of_lt_of_pos h zero_lt_one) _ h @[simp, norm_cast] theorem cast_le {m n : ℕ} : (m : α) ≤ n ↔ m ≤ n := strict_mono_cast.le_iff_le @[simp, norm_cast, mono] theorem cast_lt {m n : ℕ} : (m : α) < n ↔ m < n := strict_mono_cast.lt_iff_lt @[simp] theorem cast_pos {n : ℕ} : (0 : α) < n ↔ 0 < n := by rw [← cast_zero, cast_lt] lemma cast_add_one_pos (n : ℕ) : 0 < (n : α) + 1 := add_pos_of_nonneg_of_pos n.cast_nonneg zero_lt_one @[simp, norm_cast] theorem one_lt_cast {n : ℕ} : 1 < (n : α) ↔ 1 < n := by rw [← cast_one, cast_lt] @[simp, norm_cast] theorem one_le_cast {n : ℕ} : 1 ≤ (n : α) ↔ 1 ≤ n := by rw [← cast_one, cast_le] @[simp, norm_cast] theorem cast_lt_one {n : ℕ} : (n : α) < 1 ↔ n = 0 := by rw [← cast_one, cast_lt, lt_succ_iff, le_zero_iff] @[simp, norm_cast] theorem cast_le_one {n : ℕ} : (n : α) ≤ 1 ↔ n ≤ 1 := by rw [← cast_one, cast_le] end @[simp, norm_cast] theorem cast_min [linear_ordered_semiring α] {a b : ℕ} : (↑(min a b) : α) = min a b := (@mono_cast α _).map_min @[simp, norm_cast] theorem cast_max [linear_ordered_semiring α] {a b : ℕ} : (↑(max a b) : α) = max a b := (@mono_cast α _).map_max @[simp, norm_cast] theorem abs_cast [linear_ordered_ring α] (a : ℕ) : |(a : α)| = a := abs_of_nonneg (cast_nonneg a) lemma coe_nat_dvd [comm_semiring α] {m n : ℕ} (h : m ∣ n) : (m : α) ∣ (n : α) := ring_hom.map_dvd (nat.cast_ring_hom α) h alias coe_nat_dvd ← has_dvd.dvd.nat_cast section linear_ordered_field variables [linear_ordered_field α] lemma inv_pos_of_nat {n : ℕ} : 0 < ((n : α) + 1)⁻¹ := inv_pos.2 $ add_pos_of_nonneg_of_pos n.cast_nonneg zero_lt_one lemma one_div_pos_of_nat {n : ℕ} : 0 < 1 / ((n : α) + 1) := by { rw one_div, exact inv_pos_of_nat } lemma one_div_le_one_div {n m : ℕ} (h : n ≤ m) : 1 / ((m : α) + 1) ≤ 1 / ((n : α) + 1) := by { refine one_div_le_one_div_of_le _ _, exact nat.cast_add_one_pos _, simpa } lemma one_div_lt_one_div {n m : ℕ} (h : n < m) : 1 / ((m : α) + 1) < 1 / ((n : α) + 1) := by { refine one_div_lt_one_div_of_lt _ _, exact nat.cast_add_one_pos _, simpa } end linear_ordered_field end nat namespace prod variables {α : Type*} {β : Type*} [has_zero α] [has_one α] [has_add α] [has_zero β] [has_one β] [has_add β] @[simp] lemma fst_nat_cast (n : ℕ) : (n : α × β).fst = n := by induction n; simp * @[simp] lemma snd_nat_cast (n : ℕ) : (n : α × β).snd = n := by induction n; simp * end prod namespace add_monoid_hom variables {A B : Type*} [add_monoid A] @[ext] lemma ext_nat {f g : ℕ →+ A} (h : f 1 = g 1) : f = g := ext $ λ n, nat.rec_on n (f.map_zero.trans g.map_zero.symm) $ λ n ihn, by simp only [nat.succ_eq_add_one, *, map_add] variables [has_one A] [add_monoid B] [has_one B] lemma eq_nat_cast (f : ℕ →+ A) (h1 : f 1 = 1) : ∀ n : ℕ, f n = n := congr_fun $ show f = nat.cast_add_monoid_hom A, from ext_nat (h1.trans nat.cast_one.symm) lemma map_nat_cast (f : A →+ B) (h1 : f 1 = 1) (n : ℕ) : f n = n := (f.comp (nat.cast_add_monoid_hom A)).eq_nat_cast (by simp [h1]) _ end add_monoid_hom namespace monoid_with_zero_hom variables {A : Type*} [monoid_with_zero A] /-- If two `monoid_with_zero_hom`s agree on the positive naturals they are equal. -/ @[ext] theorem ext_nat {f g : monoid_with_zero_hom ℕ A} (h_pos : ∀ {n : ℕ}, 0 < n → f n = g n) : f = g := begin ext (_ | n), { rw [f.map_zero, g.map_zero] }, { exact h_pos n.zero_lt_succ, }, end end monoid_with_zero_hom namespace ring_hom variables {R : Type*} {S : Type*} [non_assoc_semiring R] [non_assoc_semiring S] @[simp] lemma eq_nat_cast (f : ℕ →+* R) (n : ℕ) : f n = n := f.to_add_monoid_hom.eq_nat_cast f.map_one n @[simp] lemma map_nat_cast (f : R →+* S) (n : ℕ) : f n = n := (f.comp (nat.cast_ring_hom R)).eq_nat_cast n lemma ext_nat (f g : ℕ →+* R) : f = g := coe_add_monoid_hom_injective $ add_monoid_hom.ext_nat $ f.map_one.trans g.map_one.symm end ring_hom @[simp, norm_cast] theorem nat.cast_id (n : ℕ) : ↑n = n := ((ring_hom.id ℕ).eq_nat_cast n).symm @[simp] theorem nat.cast_with_bot : ∀ (n : ℕ), @coe ℕ (with_bot ℕ) (@coe_to_lift _ _ nat.cast_coe) n = n | 0 := rfl | (n+1) := by rw [with_bot.coe_add, nat.cast_add, nat.cast_with_bot n]; refl instance nat.subsingleton_ring_hom {R : Type*} [non_assoc_semiring R] : subsingleton (ℕ →+* R) := ⟨ring_hom.ext_nat⟩ namespace with_top variables {α : Type*} variables [has_zero α] [has_one α] [has_add α] @[simp, norm_cast] lemma coe_nat : ∀(n : nat), ((n : α) : with_top α) = n | 0 := rfl | (n+1) := by { push_cast, rw [coe_nat n] } @[simp] lemma nat_ne_top (n : nat) : (n : with_top α) ≠ ⊤ := by { rw [←coe_nat n], apply coe_ne_top } @[simp] lemma top_ne_nat (n : nat) : (⊤ : with_top α) ≠ n := by { rw [←coe_nat n], apply top_ne_coe } lemma add_one_le_of_lt {i n : with_top ℕ} (h : i < n) : i + 1 ≤ n := begin cases n, { exact le_top }, cases i, { exact (not_le_of_lt h le_top).elim }, exact with_top.coe_le_coe.2 (with_top.coe_lt_coe.1 h) end lemma one_le_iff_pos {n : with_top ℕ} : 1 ≤ n ↔ 0 < n := ⟨λ h, (coe_lt_coe.2 zero_lt_one).trans_le h, λ h, by simpa only [zero_add] using add_one_le_of_lt h⟩ @[elab_as_eliminator] lemma nat_induction {P : with_top ℕ → Prop} (a : with_top ℕ) (h0 : P 0) (hsuc : ∀n:ℕ, P n → P n.succ) (htop : (∀n : ℕ, P n) → P ⊤) : P a := begin have A : ∀n:ℕ, P n := λ n, nat.rec_on n h0 hsuc, cases a, { exact htop A }, { exact A a } end end with_top namespace pi variables {α β : Type*} lemma nat_apply [has_zero β] [has_one β] [has_add β] : ∀ (n : ℕ) (a : α), (n : α → β) a = n | 0 a := rfl | (n+1) a := by rw [nat.cast_succ, nat.cast_succ, add_apply, nat_apply, one_apply] @[simp] lemma coe_nat [has_zero β] [has_one β] [has_add β] (n : ℕ) : (n : α → β) = λ _, n := by { ext, rw pi.nat_apply } end pi
25ef455140b05367fd243dbbad67806c2a1c716d
4727251e0cd73359b15b664c3170e5d754078599
/src/ring_theory/localization/basic.lean
bd6dcb212d57326fcfb031b75c859f3d38f17c5c
[ "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
43,693
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import algebra.algebra.basic import algebra.ring.equiv import group_theory.monoid_localization import ring_theory.ideal.basic import ring_theory.non_zero_divisors import tactic.ring_exp /-! # Localizations of commutative rings We characterize the localization of a commutative ring `R` at a submonoid `M` up to isomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a ring homomorphism `f : R →+* S` satisfying 3 properties: 1. For all `y ∈ M`, `f y` is a unit; 2. For all `z : S`, there exists `(x, y) : R × M` such that `z * f y = f x`; 3. For all `x, y : R`, `f x = f y` iff there exists `c ∈ M` such that `x * c = y * c`. In the following, let `R, P` be commutative rings, `S, Q` be `R`- and `P`-algebras and `M, T` be submonoids of `R` and `P` respectively, e.g.: ``` variables (R S P Q : Type*) [comm_ring R] [comm_ring S] [comm_ring P] [comm_ring Q] variables [algebra R S] [algebra P Q] (M : submonoid R) (T : submonoid P) ``` ## Main definitions * `is_localization (M : submonoid R) (S : Type*)` is a typeclass expressing that `S` is a localization of `R` at `M`, i.e. the canonical map `algebra_map R S : R →+* S` is a localization map (satisfying the above properties). * `is_localization.mk' S` is a surjection sending `(x, y) : R × M` to `f x * (f y)⁻¹` * `is_localization.lift` is the ring homomorphism from `S` induced by a homomorphism from `R` which maps elements of `M` to invertible elements of the codomain. * `is_localization.map S Q` is the ring homomorphism from `S` to `Q` which maps elements of `M` to elements of `T` * `is_localization.ring_equiv_of_ring_equiv`: if `R` and `P` are isomorphic by an isomorphism sending `M` to `T`, then `S` and `Q` are isomorphic * `is_localization.alg_equiv`: if `Q` is another localization of `R` at `M`, then `S` and `Q` are isomorphic as `R`-algebras ## Main results * `localization M S`, a construction of the localization as a quotient type, defined in `group_theory.monoid_localization`, has `comm_ring`, `algebra R` and `is_localization M` instances if `R` is a ring. `localization.away`, `localization.at_prime` and `fraction_ring` are abbreviations for `localization`s and have their corresponding `is_localization` instances ## Implementation notes In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one structure with an isomorphic one; one way around this is to isolate a predicate characterizing a structure up to isomorphism, and reason about things that satisfy the predicate. A previous version of this file used a fully bundled type of ring localization maps, then used a type synonym `f.codomain` for `f : localization_map M S` to instantiate the `R`-algebra structure on `S`. This results in defining ad-hoc copies for everything already defined on `S`. By making `is_localization` a predicate on the `algebra_map R S`, we can ensure the localization map commutes nicely with other `algebra_map`s. To prove most lemmas about a localization map `algebra_map R S` in this file we invoke the corresponding proof for the underlying `comm_monoid` localization map `is_localization.to_localization_map M S`, which can be found in `group_theory.monoid_localization` and the namespace `submonoid.localization_map`. To reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas. These show the quotient map `mk : R → M → localization M` equals the surjection `localization_map.mk'` induced by the map `algebra_map : R →+* localization M`. The lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file, which are about the `localization_map.mk'` induced by any localization map. The proof that "a `comm_ring` `K` which is the localization of an integral domain `R` at `R \ {0}` is a field" is a `def` rather than an `instance`, so if you want to reason about a field of fractions `K`, assume `[field K]` instead of just `[comm_ring K]`. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ open function open_locale big_operators section comm_semiring variables {R : Type*} [comm_semiring R] (M : submonoid R) (S : Type*) [comm_semiring S] variables [algebra R S] {P : Type*} [comm_semiring P] /-- The typeclass `is_localization (M : submodule R) S` where `S` is an `R`-algebra expresses that `S` is isomorphic to the localization of `R` at `M`. -/ class is_localization : Prop := (map_units [] : ∀ y : M, is_unit (algebra_map R S y)) (surj [] : ∀ z : S, ∃ x : R × M, z * algebra_map R S x.2 = algebra_map R S x.1) (eq_iff_exists [] : ∀ {x y}, algebra_map R S x = algebra_map R S y ↔ ∃ c : M, x * c = y * c) variables {M S} namespace is_localization section is_localization variables [is_localization M S] section variables (M) lemma of_le (N : submonoid R) (h₁ : M ≤ N) (h₂ : ∀ r ∈ N, is_unit (algebra_map R S r)) : is_localization N S := { map_units := λ r, h₂ r r.2, surj := λ s, by { obtain ⟨⟨x, y, hy⟩, H⟩ := is_localization.surj M s, exact ⟨⟨x, y, h₁ hy⟩, H⟩ }, eq_iff_exists := λ x y, begin split, { rw is_localization.eq_iff_exists M, rintro ⟨c, hc⟩, exact ⟨⟨c, h₁ c.2⟩, hc⟩ }, { rintro ⟨c, h⟩, simpa only [set_like.coe_mk, map_mul, (h₂ c c.2).mul_left_inj] using congr_arg (algebra_map R S) h } end } variables (S) /-- `is_localization.to_localization_with_zero_map M S` shows `S` is the monoid localization of `R` at `M`. -/ @[simps] def to_localization_with_zero_map : submonoid.localization_with_zero_map M S := { to_fun := algebra_map R S, map_units' := is_localization.map_units _, surj' := is_localization.surj _, eq_iff_exists' := λ _ _, is_localization.eq_iff_exists _ _, .. algebra_map R S } /-- `is_localization.to_localization_map M S` shows `S` is the monoid localization of `R` at `M`. -/ abbreviation to_localization_map : submonoid.localization_map M S := (to_localization_with_zero_map M S).to_localization_map @[simp] lemma to_localization_map_to_map : (to_localization_map M S).to_map = (algebra_map R S : R →*₀ S) := rfl lemma to_localization_map_to_map_apply (x) : (to_localization_map M S).to_map x = algebra_map R S x := rfl end variables (M) /-- Given a localization map `f : M →* N`, a section function sending `z : N` to some `(x, y) : M × S` such that `f x * (f y)⁻¹ = z`. -/ noncomputable def sec (z : S) : R × M := classical.some $ is_localization.surj _ z @[simp] lemma to_localization_map_sec : (to_localization_map M S).sec = sec M := rfl /-- Given `z : S`, `is_localization.sec M z` is defined to be a pair `(x, y) : R × M` such that `z * f y = f x` (so this lemma is true by definition). -/ lemma sec_spec (z : S) : z * algebra_map R S (is_localization.sec M z).2 = algebra_map R S (is_localization.sec M z).1 := classical.some_spec $ is_localization.surj _ z /-- Given `z : S`, `is_localization.sec M z` is defined to be a pair `(x, y) : R × M` such that `z * f y = f x`, so this lemma is just an application of `S`'s commutativity. -/ lemma sec_spec' (z : S) : algebra_map R S (is_localization.sec M z).1 = algebra_map R S (is_localization.sec M z).2 * z := by rw [mul_comm, sec_spec] variables {R M} lemma map_right_cancel {x y} {c : M} (h : algebra_map R S (c * x) = algebra_map R S (c * y)) : algebra_map R S x = algebra_map R S y := (to_localization_map M S).map_right_cancel h lemma map_left_cancel {x y} {c : M} (h : algebra_map R S (x * c) = algebra_map R S (y * c)) : algebra_map R S x = algebra_map R S y := (to_localization_map M S).map_left_cancel h lemma eq_zero_of_fst_eq_zero {z x} {y : M} (h : z * algebra_map R S y = algebra_map R S x) (hx : x = 0) : z = 0 := by { rw [hx, (algebra_map R S).map_zero] at h, exact (is_unit.mul_left_eq_zero (is_localization.map_units S y)).1 h} variables (M S) lemma map_eq_zero_iff (r : R) : algebra_map R S r = 0 ↔ ∃ m : M, r * m = 0 := begin split, intro h, { obtain ⟨m, hm⟩ := (is_localization.eq_iff_exists M S).mp ((algebra_map R S).map_zero.trans h.symm), exact ⟨m, by simpa using hm.symm⟩ }, { rintro ⟨m, hm⟩, rw [← (is_localization.map_units S m).mul_left_inj, zero_mul, ← ring_hom.map_mul, hm, ring_hom.map_zero] } end variables {M} /-- `is_localization.mk' S` is the surjection sending `(x, y) : R × M` to `f x * (f y)⁻¹`. -/ noncomputable def mk' (x : R) (y : M) : S := (to_localization_map M S).mk' x y @[simp] lemma mk'_sec (z : S) : mk' S (is_localization.sec M z).1 (is_localization.sec M z).2 = z := (to_localization_map M S).mk'_sec _ lemma mk'_mul (x₁ x₂ : R) (y₁ y₂ : M) : mk' S (x₁ * x₂) (y₁ * y₂) = mk' S x₁ y₁ * mk' S x₂ y₂ := (to_localization_map M S).mk'_mul _ _ _ _ lemma mk'_one (x) : mk' S x (1 : M) = algebra_map R S x := (to_localization_map M S).mk'_one _ @[simp] lemma mk'_spec (x) (y : M) : mk' S x y * algebra_map R S y = algebra_map R S x := (to_localization_map M S).mk'_spec _ _ @[simp] lemma mk'_spec' (x) (y : M) : algebra_map R S y * mk' S x y = algebra_map R S x := (to_localization_map M S).mk'_spec' _ _ @[simp] lemma mk'_spec_mk (x) (y : R) (hy : y ∈ M) : mk' S x ⟨y, hy⟩ * algebra_map R S y = algebra_map R S x := mk'_spec S x ⟨y, hy⟩ @[simp] lemma mk'_spec'_mk (x) (y : R) (hy : y ∈ M) : algebra_map R S y * mk' S x ⟨y, hy⟩ = algebra_map R S x := mk'_spec' S x ⟨y, hy⟩ variables {S} theorem eq_mk'_iff_mul_eq {x} {y : M} {z} : z = mk' S x y ↔ z * algebra_map R S y = algebra_map R S x := (to_localization_map M S).eq_mk'_iff_mul_eq theorem mk'_eq_iff_eq_mul {x} {y : M} {z} : mk' S x y = z ↔ algebra_map R S x = z * algebra_map R S y := (to_localization_map M S).mk'_eq_iff_eq_mul theorem mk'_add_eq_iff_add_mul_eq_mul {x} {y : M} {z₁ z₂} : mk' S x y + z₁ = z₂ ↔ algebra_map R S x + z₁ * algebra_map R S y = z₂ * algebra_map R S y := by rw [←mk'_spec S x y, ←is_unit.mul_left_inj (is_localization.map_units S y), right_distrib] variables (M) lemma mk'_surjective (z : S) : ∃ x (y : M), mk' S x y = z := let ⟨r, hr⟩ := is_localization.surj _ z in ⟨r.1, r.2, (eq_mk'_iff_mul_eq.2 hr).symm⟩ variables (S) include M /-- The localization of a `fintype` is a `fintype`. Cannot be an instance. -/ noncomputable def fintype' [fintype R] : fintype S := have _ := classical.prop_decidable, by exactI fintype.of_surjective (function.uncurry $ is_localization.mk' S) (λ a, prod.exists'.mpr $ is_localization.mk'_surjective M a) omit M variables {M S} /-- Localizing at a submonoid with 0 inside it leads to the trivial ring. -/ def unique_of_zero_mem (h : (0 : R) ∈ M) : unique S := unique_of_zero_eq_one $ by simpa using is_localization.map_units S ⟨0, h⟩ lemma mk'_eq_iff_eq {x₁ x₂} {y₁ y₂ : M} : mk' S x₁ y₁ = mk' S x₂ y₂ ↔ algebra_map R S (x₁ * y₂) = algebra_map R S (x₂ * y₁) := (to_localization_map M S).mk'_eq_iff_eq lemma mk'_mem_iff {x} {y : M} {I : ideal S} : mk' S x y ∈ I ↔ algebra_map R S x ∈ I := begin split; intro h, { rw [← mk'_spec S x y, mul_comm], exact I.mul_mem_left ((algebra_map R S) y) h }, { rw ← mk'_spec S x y at h, obtain ⟨b, hb⟩ := is_unit_iff_exists_inv.1 (map_units S y), have := I.mul_mem_left b h, rwa [mul_comm, mul_assoc, hb, mul_one] at this } end protected lemma eq {a₁ b₁} {a₂ b₂ : M} : mk' S a₁ a₂ = mk' S b₁ b₂ ↔ ∃ c : M, a₁ * b₂ * c = b₁ * a₂ * c := (to_localization_map M S).eq lemma mk'_eq_zero_iff (x : R) (s : M) : mk' S x s = 0 ↔ ∃ (m : M), x * m = 0 := by rw [← (map_units S s).mul_left_inj, mk'_spec, zero_mul, map_eq_zero_iff M] @[simp] lemma mk'_zero (s : M) : is_localization.mk' S 0 s = 0 := by rw [eq_comm, is_localization.eq_mk'_iff_mul_eq, zero_mul, map_zero] lemma ne_zero_of_mk'_ne_zero {x : R} {y : M} (hxy : is_localization.mk' S x y ≠ 0) : x ≠ 0 := begin rintro rfl, exact hxy (is_localization.mk'_zero _) end section ext variables [algebra R P] [is_localization M P] lemma eq_iff_eq {x y} : algebra_map R S x = algebra_map R S y ↔ algebra_map R P x = algebra_map R P y := (to_localization_map M S).eq_iff_eq (to_localization_map M P) lemma mk'_eq_iff_mk'_eq {x₁ x₂} {y₁ y₂ : M} : mk' S x₁ y₁ = mk' S x₂ y₂ ↔ mk' P x₁ y₁ = mk' P x₂ y₂ := (to_localization_map M S).mk'_eq_iff_mk'_eq (to_localization_map M P) lemma mk'_eq_of_eq {a₁ b₁ : R} {a₂ b₂ : M} (H : b₁ * a₂ = a₁ * b₂) : mk' S a₁ a₂ = mk' S b₁ b₂ := (to_localization_map M S).mk'_eq_of_eq H variables (S) @[simp] lemma mk'_self {x : R} (hx : x ∈ M) : mk' S x ⟨x, hx⟩ = 1 := (to_localization_map M S).mk'_self _ hx @[simp] lemma mk'_self' {x : M} : mk' S (x : R) x = 1 := (to_localization_map M S).mk'_self' _ lemma mk'_self'' {x : M} : mk' S x.1 x = 1 := mk'_self' _ end ext lemma mul_mk'_eq_mk'_of_mul (x y : R) (z : M) : (algebra_map R S) x * mk' S y z = mk' S (x * y) z := (to_localization_map M S).mul_mk'_eq_mk'_of_mul _ _ _ lemma mk'_eq_mul_mk'_one (x : R) (y : M) : mk' S x y = (algebra_map R S) x * mk' S 1 y := ((to_localization_map M S).mul_mk'_one_eq_mk' _ _).symm @[simp] lemma mk'_mul_cancel_left (x : R) (y : M) : mk' S (y * x : R) y = (algebra_map R S) x := (to_localization_map M S).mk'_mul_cancel_left _ _ lemma mk'_mul_cancel_right (x : R) (y : M) : mk' S (x * y) y = (algebra_map R S) x := (to_localization_map M S).mk'_mul_cancel_right _ _ @[simp] lemma mk'_mul_mk'_eq_one (x y : M) : mk' S (x : R) y * mk' S (y : R) x = 1 := by rw [←mk'_mul, mul_comm]; exact mk'_self _ _ lemma mk'_mul_mk'_eq_one' (x : R) (y : M) (h : x ∈ M) : mk' S x y * mk' S (y : R) ⟨x, h⟩ = 1 := mk'_mul_mk'_eq_one ⟨x, h⟩ _ section variables (M) lemma is_unit_comp (j : S →+* P) (y : M) : is_unit (j.comp (algebra_map R S) y) := (to_localization_map M S).is_unit_comp j.to_monoid_hom _ end /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `comm_semiring`s `g : R →+* P` such that `g(M) ⊆ units P`, `f x = f y → g x = g y` for all `x y : R`. -/ lemma eq_of_eq {g : R →+* P} (hg : ∀ y : M, is_unit (g y)) {x y} (h : (algebra_map R S) x = (algebra_map R S) y) : g x = g y := @submonoid.localization_map.eq_of_eq _ _ _ _ _ _ _ (to_localization_map M S) g.to_monoid_hom hg _ _ h lemma mk'_add (x₁ x₂ : R) (y₁ y₂ : M) : mk' S (x₁ * y₂ + x₂ * y₁) (y₁ * y₂) = mk' S x₁ y₁ + mk' S x₂ y₂ := mk'_eq_iff_eq_mul.2 $ eq.symm begin rw [mul_comm (_ + _), mul_add, mul_mk'_eq_mk'_of_mul, mk'_add_eq_iff_add_mul_eq_mul, mul_comm (_ * _), ←mul_assoc, add_comm, ←map_mul, mul_mk'_eq_mk'_of_mul, mk'_add_eq_iff_add_mul_eq_mul], simp only [map_add, submonoid.coe_mul, map_mul], ring end lemma mul_add_inv_left {g : R →+* P} (h : ∀ y : M, is_unit (g y)) (y : M) (w z₁ z₂ : P) : w * ↑(is_unit.lift_right (g.to_monoid_hom.mrestrict M) h y)⁻¹ + z₁ = z₂ ↔ w + g y * z₁ = g y * z₂ := begin rw [mul_comm, ←one_mul z₁, ←units.inv_mul (is_unit.lift_right (g.to_monoid_hom.mrestrict M) h y), mul_assoc, ←mul_add, units.inv_mul_eq_iff_eq_mul, units.inv_mul_cancel_left, is_unit.coe_lift_right], simp only [ring_hom.to_monoid_hom_eq_coe, monoid_hom.mrestrict_apply, ring_hom.coe_monoid_hom] end lemma lift_spec_mul_add {g : R →+* P} (hg : ∀ y : M, is_unit (g y)) (z w w' v) : ((to_localization_with_zero_map M S).lift g.to_monoid_with_zero_hom hg) z * w + w' = v ↔ g ((to_localization_map M S).sec z).1 * w + g ((to_localization_map M S).sec z).2 * w' = g ((to_localization_map M S).sec z).2 * v := begin show (_ * _) * _ + _ = _ ↔ _ = _, erw [mul_comm, ←mul_assoc, mul_add_inv_left hg, mul_comm], refl end /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `comm_semiring`s `g : R →+* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from `S` to `P` sending `z : S` to `g x * (g y)⁻¹`, where `(x, y) : R × M` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def lift {g : R →+* P} (hg : ∀ y : M, is_unit (g y)) : S →+* P := { map_add' := begin intros x y, erw [(to_localization_map M S).lift_spec, mul_add, mul_comm, eq_comm, lift_spec_mul_add, add_comm, mul_comm,mul_assoc,mul_comm,mul_assoc, lift_spec_mul_add], simp_rw ←mul_assoc, show g _ * g _ * g _ + g _ * g _ * g _ = g _ * g _ * g _, simp_rw [←map_mul g, ←map_add g], apply @eq_of_eq _ _ _ S _ _ _ _ _ g hg, simp only [sec_spec', to_localization_map_sec, map_add, map_mul], ring end, .. @submonoid.localization_with_zero_map.lift _ _ _ _ _ _ _ (to_localization_with_zero_map M S) g.to_monoid_with_zero_hom hg } variables {g : R →+* P} (hg : ∀ y : M, is_unit (g y)) /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `comm_semiring`s `g : R →* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from `S` to `P` maps `f x * (f y)⁻¹` to `g x * (g y)⁻¹` for all `x : R, y ∈ M`. -/ lemma lift_mk' (x y) : lift hg (mk' S x y) = g x * ↑(is_unit.lift_right (g.to_monoid_hom.mrestrict M) hg y)⁻¹ := (to_localization_map M S).lift_mk' _ _ _ lemma lift_mk'_spec (x v) (y : M) : lift hg (mk' S x y) = v ↔ g x = g y * v := (to_localization_map M S).lift_mk'_spec _ _ _ _ @[simp] lemma lift_eq (x : R) : lift hg ((algebra_map R S) x) = g x := (to_localization_map M S).lift_eq _ _ lemma lift_eq_iff {x y : R × M} : lift hg (mk' S x.1 x.2) = lift hg (mk' S y.1 y.2) ↔ g (x.1 * y.2) = g (y.1 * x.2) := (to_localization_map M S).lift_eq_iff _ @[simp] lemma lift_comp : (lift hg).comp (algebra_map R S) = g := ring_hom.ext $ monoid_hom.ext_iff.1 $ (to_localization_map M S).lift_comp _ @[simp] lemma lift_of_comp (j : S →+* P) : lift (is_unit_comp M j) = j := ring_hom.ext $ monoid_hom.ext_iff.1 $ (to_localization_map M S).lift_of_comp j.to_monoid_hom variables (M) /-- See note [partially-applied ext lemmas] -/ lemma monoid_hom_ext ⦃j k : S →* P⦄ (h : j.comp (algebra_map R S : R →* S) = k.comp (algebra_map R S)) : j = k := submonoid.localization_map.epic_of_localization_map (to_localization_map M S) $ monoid_hom.congr_fun h /-- See note [partially-applied ext lemmas] -/ lemma ring_hom_ext ⦃j k : S →+* P⦄ (h : j.comp (algebra_map R S) = k.comp (algebra_map R S)) : j = k := ring_hom.coe_monoid_hom_injective $ monoid_hom_ext M $ monoid_hom.ext $ ring_hom.congr_fun h /-- To show `j` and `k` agree on the whole localization, it suffices to show they agree on the image of the base ring, if they preserve `1` and `*`. -/ protected lemma ext (j k : S → P) (hj1 : j 1 = 1) (hk1 : k 1 = 1) (hjm : ∀ a b, j (a * b) = j a * j b) (hkm : ∀ a b, k (a * b) = k a * k b) (h : ∀ a, j (algebra_map R S a) = k (algebra_map R S a)) : j = k := monoid_hom.mk.inj (monoid_hom_ext M $ monoid_hom.ext h : (⟨j, hj1, hjm⟩ : S →* P) = ⟨k, hk1, hkm⟩) variables {M} lemma lift_unique {j : S →+* P} (hj : ∀ x, j ((algebra_map R S) x) = g x) : lift hg = j := ring_hom.ext $ monoid_hom.ext_iff.1 $ @submonoid.localization_map.lift_unique _ _ _ _ _ _ _ (to_localization_map M S) g.to_monoid_hom hg j.to_monoid_hom hj @[simp] lemma lift_id (x) : lift (map_units S : ∀ y : M, is_unit _) x = x := (to_localization_map M S).lift_id _ lemma lift_surjective_iff : surjective (lift hg : S → P) ↔ ∀ v : P, ∃ x : R × M, v * g x.2 = g x.1 := (to_localization_map M S).lift_surjective_iff hg lemma lift_injective_iff : injective (lift hg : S → P) ↔ ∀ x y, algebra_map R S x = algebra_map R S y ↔ g x = g y := (to_localization_map M S).lift_injective_iff hg section map variables {T : submonoid P} {Q : Type*} [comm_semiring Q] (hy : M ≤ T.comap g) variables [algebra P Q] [is_localization T Q] section variables (Q) /-- Map a homomorphism `g : R →+* P` to `S →+* Q`, where `S` and `Q` are localizations of `R` and `P` at `M` and `T` respectively, such that `g(M) ⊆ T`. We send `z : S` to `algebra_map P Q (g x) * (algebra_map P Q (g y))⁻¹`, where `(x, y) : R × M` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def map (g : R →+* P) (hy : M ≤ T.comap g) : S →+* Q := @lift R _ M _ _ _ _ _ _ ((algebra_map P Q).comp g) (λ y, map_units _ ⟨g y, hy y.2⟩) end lemma map_eq (x) : map Q g hy ((algebra_map R S) x) = algebra_map P Q (g x) := lift_eq (λ y, map_units _ ⟨g y, hy y.2⟩) x @[simp] lemma map_comp : (map Q g hy).comp (algebra_map R S) = (algebra_map P Q).comp g := lift_comp $ λ y, map_units _ ⟨g y, hy y.2⟩ lemma map_mk' (x) (y : M) : map Q g hy (mk' S x y) = mk' Q (g x) ⟨g y, hy y.2⟩ := @submonoid.localization_map.map_mk' _ _ _ _ _ _ _ (to_localization_map M S) g.to_monoid_hom _ (λ y, hy y.2) _ _ (to_localization_map T Q) _ _ @[simp] lemma map_id (z : S) (h : M ≤ M.comap (ring_hom.id R) := le_refl M) : map S (ring_hom.id _) h z = z := lift_id _ lemma map_unique (j : S →+* Q) (hj : ∀ x : R, j (algebra_map R S x) = algebra_map P Q (g x)) : map Q g hy = j := lift_unique (λ y, map_units _ ⟨g y, hy y.2⟩) hj /-- If `comm_semiring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`. -/ lemma map_comp_map {A : Type*} [comm_semiring A] {U : submonoid A} {W} [comm_semiring W] [algebra A W] [is_localization U W] {l : P →+* A} (hl : T ≤ U.comap l) : (map W l hl).comp (map Q g hy : S →+* _) = map W (l.comp g) (λ x hx, hl (hy hx)) := ring_hom.ext $ λ x, @submonoid.localization_map.map_map _ _ _ _ _ P _ (to_localization_map M S) g _ _ _ _ _ _ _ _ _ _ (to_localization_map U W) l _ x /-- If `comm_semiring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`. -/ lemma map_map {A : Type*} [comm_semiring A] {U : submonoid A} {W} [comm_semiring W] [algebra A W] [is_localization U W] {l : P →+* A} (hl : T ≤ U.comap l) (x : S) : map W l hl (map Q g hy x) = map W (l.comp g) (λ x hx, hl (hy hx)) x := by rw ←map_comp_map hy hl; refl lemma map_smul (x : S) (z : R) : map Q g hy (z • x : S) = g z • map Q g hy x := by rw [algebra.smul_def, algebra.smul_def, ring_hom.map_mul, map_eq] section variables (S Q) /-- If `S`, `Q` are localizations of `R` and `P` at submonoids `M, T` respectively, an isomorphism `j : R ≃+* P` such that `j(M) = T` induces an isomorphism of localizations `S ≃+* Q`. -/ @[simps] noncomputable def ring_equiv_of_ring_equiv (h : R ≃+* P) (H : M.map h.to_monoid_hom = T) : S ≃+* Q := have H' : T.map h.symm.to_monoid_hom = M, by { rw [← M.map_id, ← H, submonoid.map_map], congr, ext, apply h.symm_apply_apply }, { to_fun := map Q (h : R →+* P) (M.le_comap_of_map_le (le_of_eq H)), inv_fun := map S (h.symm : P →+* R) (T.le_comap_of_map_le (le_of_eq H')), left_inv := λ x, by { rw [map_map, map_unique _ (ring_hom.id _), ring_hom.id_apply], intro x, convert congr_arg (algebra_map R S) (h.symm_apply_apply x).symm }, right_inv := λ x, by { rw [map_map, map_unique _ (ring_hom.id _), ring_hom.id_apply], intro x, convert congr_arg (algebra_map P Q) (h.apply_symm_apply x).symm }, .. map Q (h : R →+* P) _ } end lemma ring_equiv_of_ring_equiv_eq_map {j : R ≃+* P} (H : M.map j.to_monoid_hom = T) : (ring_equiv_of_ring_equiv S Q j H : S →+* Q) = map Q (j : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) := rfl @[simp] lemma ring_equiv_of_ring_equiv_eq {j : R ≃+* P} (H : M.map j.to_monoid_hom = T) (x) : ring_equiv_of_ring_equiv S Q j H ((algebra_map R S) x) = algebra_map P Q (j x) := map_eq _ _ lemma ring_equiv_of_ring_equiv_mk' {j : R ≃+* P} (H : M.map j.to_monoid_hom = T) (x : R) (y : M) : ring_equiv_of_ring_equiv S Q j H (mk' S x y) = mk' Q (j x) ⟨j y, show j y ∈ T, from H ▸ set.mem_image_of_mem j y.2⟩ := map_mk' _ _ _ end map section alg_equiv variables {Q : Type*} [comm_semiring Q] [algebra R Q] [is_localization M Q] section variables (M S Q) /-- If `S`, `Q` are localizations of `R` at the submonoid `M` respectively, there is an isomorphism of localizations `S ≃ₐ[R] Q`. -/ @[simps] noncomputable def alg_equiv : S ≃ₐ[R] Q := { commutes' := ring_equiv_of_ring_equiv_eq _, .. ring_equiv_of_ring_equiv S Q (ring_equiv.refl R) M.map_id } end @[simp] lemma alg_equiv_mk' (x : R) (y : M) : alg_equiv M S Q (mk' S x y) = mk' Q x y:= map_mk' _ _ _ @[simp] lemma alg_equiv_symm_mk' (x : R) (y : M) : (alg_equiv M S Q).symm (mk' Q x y) = mk' S x y:= map_mk' _ _ _ end alg_equiv end is_localization section variables (M) lemma is_localization_of_alg_equiv [algebra R P] [is_localization M S] (h : S ≃ₐ[R] P) : is_localization M P := begin constructor, { intro y, convert (is_localization.map_units S y).map h.to_alg_hom.to_ring_hom.to_monoid_hom, exact (h.commutes y).symm }, { intro y, obtain ⟨⟨x, s⟩, e⟩ := is_localization.surj M (h.symm y), apply_fun h at e, simp only [h.map_mul, h.apply_symm_apply, h.commutes] at e, exact ⟨⟨x, s⟩, e⟩ }, { intros x y, rw [← h.symm.to_equiv.injective.eq_iff, ← is_localization.eq_iff_exists M S, ← h.symm.commutes, ← h.symm.commutes], refl } end lemma is_localization_iff_of_alg_equiv [algebra R P] (h : S ≃ₐ[R] P) : is_localization M S ↔ is_localization M P := ⟨λ _, by exactI is_localization_of_alg_equiv M h, λ _, by exactI is_localization_of_alg_equiv M h.symm⟩ lemma is_localization_iff_of_ring_equiv (h : S ≃+* P) : is_localization M S ↔ @@is_localization _ M P _ (h.to_ring_hom.comp $ algebra_map R S).to_algebra := begin letI := (h.to_ring_hom.comp $ algebra_map R S).to_algebra, exact is_localization_iff_of_alg_equiv M { commutes' := λ _, rfl, ..h }, end variable (S) lemma is_localization_of_base_ring_equiv [is_localization M S] (h : R ≃+* P) : @@is_localization _ (M.map h.to_monoid_hom) S _ ((algebra_map R S).comp h.symm.to_ring_hom).to_algebra := begin constructor, { rintros ⟨_, ⟨y, hy, rfl⟩⟩, convert is_localization.map_units S ⟨y, hy⟩, dsimp only [ring_hom.algebra_map_to_algebra, ring_hom.comp_apply], exact congr_arg _ (h.symm_apply_apply _) }, { intro y, obtain ⟨⟨x, s⟩, e⟩ := is_localization.surj M y, refine ⟨⟨h x, _, _, s.prop, rfl⟩, _⟩, dsimp only [ring_hom.algebra_map_to_algebra, ring_hom.comp_apply] at ⊢ e, convert e; exact h.symm_apply_apply _ }, { intros x y, rw [ring_hom.algebra_map_to_algebra, ring_hom.comp_apply, ring_hom.comp_apply, is_localization.eq_iff_exists M S], simp_rw ← h.to_equiv.apply_eq_iff_eq, change (∃ (c : M), h (h.symm x * c) = h (h.symm y * c)) ↔ _, simp only [ring_equiv.apply_symm_apply, ring_equiv.map_mul], exact ⟨λ ⟨c, e⟩, ⟨⟨_, _, c.prop, rfl⟩, e⟩, λ ⟨⟨_, c, h, e₁⟩, e₂⟩, ⟨⟨_, h⟩, e₁.symm ▸ e₂⟩⟩ } end lemma is_localization_iff_of_base_ring_equiv (h : R ≃+* P) : is_localization M S ↔ @@is_localization _ (M.map h.to_monoid_hom) S _ ((algebra_map R S).comp h.symm.to_ring_hom).to_algebra := begin refine ⟨λ _, by exactI is_localization_of_base_ring_equiv _ _ h, _⟩, letI := ((algebra_map R S).comp h.symm.to_ring_hom).to_algebra, intro H, convert @@is_localization_of_base_ring_equiv _ _ _ _ _ _ H h.symm, { erw [submonoid.map_equiv_eq_comap_symm, submonoid.comap_map_eq_of_injective], exact h.to_equiv.injective }, rw [ring_hom.algebra_map_to_algebra, ring_hom.comp_assoc], simp only [ring_hom.comp_id, ring_equiv.symm_symm, ring_equiv.symm_to_ring_hom_comp_to_ring_hom], apply algebra.algebra_ext, intro r, rw ring_hom.algebra_map_to_algebra end end variables (M S) include M lemma non_zero_divisors_le_comap [is_localization M S] : non_zero_divisors R ≤ (non_zero_divisors S).comap (algebra_map R S) := begin rintros a ha b (e : b * algebra_map R S a = 0), obtain ⟨x, s, rfl⟩ := mk'_surjective M b, rw [← @mk'_one R _ M, ← mk'_mul, ← (algebra_map R S).map_zero, ← @mk'_one R _ M, is_localization.eq] at e, obtain ⟨c, e⟩ := e, rw [zero_mul, zero_mul, submonoid.coe_one, mul_one, mul_comm x a, mul_assoc, mul_comm] at e, rw mk'_eq_zero_iff, exact ⟨c, ha _ e⟩ end lemma map_non_zero_divisors_le [is_localization M S] : (non_zero_divisors R).map (algebra_map R S).to_monoid_hom ≤ non_zero_divisors S := submonoid.map_le_iff_le_comap.mpr (non_zero_divisors_le_comap M S) end is_localization namespace localization open is_localization /-! ### Constructing a localization at a given submonoid -/ variables {M} section instance [subsingleton R] : unique (localization M) := ⟨⟨1⟩, begin intro a, induction a, induction default, congr, refl, refl end⟩ /-- Addition in a ring localization is defined as `⟨a, b⟩ + ⟨c, d⟩ = ⟨b * c + d * a, b * d⟩`. Should not be confused with `add_localization.add`, which is defined as `⟨a, b⟩ + ⟨c, d⟩ = ⟨a + c, b + d⟩`. -/ @[irreducible] protected def add (z w : localization M) : localization M := localization.lift_on₂ z w (λ a b c d, mk ((b : R) * c + d * a) (b * d)) $ λ a a' b b' c c' d d' h1 h2, mk_eq_mk_iff.2 begin rw r_eq_r' at h1 h2 ⊢, cases h1 with t₅ ht₅, cases h2 with t₆ ht₆, use t₆ * t₅, calc ((b : R) * c + d * a) * (b' * d') * (t₆ * t₅) = (c * d' * t₆) * (b * b' * t₅) + (a * b' * t₅) * (d * d' * t₆) : by ring ... = (b' * c' + d' * a') * (b * d) * (t₆ * t₅) : by rw [ht₆, ht₅]; ring end instance : has_add (localization M) := ⟨localization.add⟩ lemma add_mk (a b c d) : (mk a b : localization M) + mk c d = mk (b * c + d * a) (b * d) := by { unfold has_add.add localization.add, apply lift_on₂_mk } lemma add_mk_self (a b c) : (mk a b : localization M) + mk c b = mk (a + c) b := begin rw [add_mk, mk_eq_mk_iff, r_eq_r'], refine (r' M).symm ⟨1, _⟩, simp only [submonoid.coe_one, submonoid.coe_mul], ring end private meta def tac := `[ { intros, simp only [add_mk, localization.mk_mul, ← localization.mk_zero 1], refine mk_eq_mk_iff.mpr (r_of_eq _), simp only [submonoid.coe_mul], ring }] instance : comm_semiring (localization M) := { zero := 0, one := 1, add := (+), mul := (*), npow := localization.npow _, nsmul := (•), nsmul_zero' := λ x, localization.induction_on x (λ x, by simp only [smul_mk, zero_nsmul, mk_zero]), nsmul_succ' := λ n x, localization.induction_on x (λ x, by simp only [smul_mk, succ_nsmul, add_mk_self]), add_assoc := λ m n k, localization.induction_on₃ m n k (by tac), zero_add := λ y, localization.induction_on y (by tac), add_zero := λ y, localization.induction_on y (by tac), add_comm := λ y z, localization.induction_on₂ z y (by tac), left_distrib := λ m n k, localization.induction_on₃ m n k (by tac), right_distrib := λ m n k, localization.induction_on₃ m n k (by tac), .. localization.comm_monoid_with_zero M } instance {S : Type*} [monoid S] [distrib_mul_action S R] [is_scalar_tower S R R] : distrib_mul_action S (localization M) := { smul_zero := λ s, by simp only [←localization.mk_zero 1, localization.smul_mk, smul_zero], smul_add := λ s x y, localization.induction_on₂ x y $ prod.rec $ by exact λ r₁ x₁, prod.rec $ by exact λ r₂ x₂, by simp only [localization.smul_mk, localization.add_mk, smul_add, mul_comm _ (s • _), mul_comm _ r₁, mul_comm _ r₂, smul_mul_assoc] } instance {S : Type*} [semiring S] [mul_semiring_action S R] [is_scalar_tower S R R] : mul_semiring_action S (localization M) := { ..localization.mul_distrib_mul_action } instance {S : Type*} [semiring S] [module S R] [is_scalar_tower S R R] : module S (localization M) := { zero_smul := localization.ind $ prod.rec $ by { intros, simp only [localization.smul_mk, zero_smul, mk_zero] }, add_smul := λ s₁ s₂, localization.ind $ prod.rec $ by { intros, simp only [localization.smul_mk, add_smul, add_mk_self] }, ..localization.distrib_mul_action } instance {S : Type*} [comm_semiring S] [algebra S R] : algebra S (localization M) := { to_ring_hom := ring_hom.comp { to_fun := (monoid_of M).to_map, map_zero' := by rw [← mk_zero (1 : M), mk_one_eq_monoid_of_mk], map_add' := λ x y, by simp only [← mk_one_eq_monoid_of_mk, add_mk, submonoid.coe_one, one_mul, add_comm], .. localization.monoid_of M } (algebra_map S R), smul_def' := λ s, localization.ind $ prod.rec $ begin intros r x, dsimp, simp only [←mk_one_eq_monoid_of_mk, mk_mul, localization.smul_mk, one_mul, algebra.smul_def], end, commutes' := λ s, localization.ind $ prod.rec $ begin intros r x, dsimp, simp only [←mk_one_eq_monoid_of_mk, mk_mul, localization.smul_mk, one_mul, mul_one, algebra.commutes], end } instance : is_localization M (localization M) := { map_units := (localization.monoid_of M).map_units, surj := (localization.monoid_of M).surj, eq_iff_exists := λ _ _, (localization.monoid_of M).eq_iff_exists } end @[simp] lemma to_localization_map_eq_monoid_of : to_localization_map M (localization M) = monoid_of M := rfl lemma monoid_of_eq_algebra_map (x) : (monoid_of M).to_map x = algebra_map R (localization M) x := rfl lemma mk_one_eq_algebra_map (x) : mk x 1 = algebra_map R (localization M) x := rfl lemma mk_eq_mk'_apply (x y) : mk x y = is_localization.mk' (localization M) x y := by rw [mk_eq_monoid_of_mk'_apply, mk', to_localization_map_eq_monoid_of] @[simp] lemma mk_eq_mk' : (mk : R → M → localization M) = is_localization.mk' (localization M) := mk_eq_monoid_of_mk' lemma mk_algebra_map {A : Type*} [comm_semiring A] [algebra A R] (m : A) : mk (algebra_map A R m) 1 = algebra_map A (localization M) m := by rw [mk_eq_mk', mk'_eq_iff_eq_mul, submonoid.coe_one, map_one, mul_one]; refl lemma mk_nat_cast (m : ℕ) : (mk m 1 : localization M) = m := by simpa using @mk_algebra_map R _ M ℕ _ _ m variables [is_localization M S] section variables (M S) /-- The localization of `R` at `M` as a quotient type is isomorphic to any other localization. -/ @[simps] noncomputable def alg_equiv : localization M ≃ₐ[R] S := is_localization.alg_equiv M _ _ /-- The localization of a singleton is a singleton. Cannot be an instance due to metavariables. -/ noncomputable def _root_.is_localization.unique (R Rₘ) [comm_semiring R] [comm_semiring Rₘ] (M : submonoid R) [subsingleton R] [algebra R Rₘ] [is_localization M Rₘ] : unique Rₘ := have inhabited Rₘ := ⟨1⟩, by exactI (alg_equiv M Rₘ).symm.injective.unique end @[simp] lemma alg_equiv_mk' (x : R) (y : M) : alg_equiv M S (mk' (localization M) x y) = mk' S x y := alg_equiv_mk' _ _ @[simp] lemma alg_equiv_symm_mk' (x : R) (y : M) : (alg_equiv M S).symm (mk' S x y) = mk' (localization M) x y := alg_equiv_symm_mk' _ _ lemma alg_equiv_mk (x y) : alg_equiv M S (mk x y) = mk' S x y := by rw [mk_eq_mk', alg_equiv_mk'] lemma alg_equiv_symm_mk (x : R) (y : M) : (alg_equiv M S).symm (mk' S x y) = mk x y := by rw [mk_eq_mk', alg_equiv_symm_mk'] end localization end comm_semiring section comm_ring variables {R : Type*} [comm_ring R] {M : submonoid R} (S : Type*) [comm_ring S] variables [algebra R S] {P : Type*} [comm_ring P] namespace localization /-- Negation in a ring localization is defined as `-⟨a, b⟩ = ⟨-a, b⟩`. -/ @[irreducible] protected def neg (z : localization M) : localization M := localization.lift_on z (λ a b, mk (-a) b) $ λ a b c d h, mk_eq_mk_iff.2 begin rw r_eq_r' at h ⊢, cases h with t ht, use t, rw [neg_mul, neg_mul, ht], ring_nf, end instance : has_neg (localization M) := ⟨localization.neg⟩ lemma neg_mk (a b) : -(mk a b : localization M) = mk (-a) b := by { unfold has_neg.neg localization.neg, apply lift_on_mk } instance : comm_ring (localization M) := { zsmul := (•), zsmul_zero' := λ x, localization.induction_on x (λ x, by simp only [smul_mk, zero_zsmul, mk_zero]), zsmul_succ' := λ n x, localization.induction_on x (λ x, by simp [smul_mk, add_mk_self, -mk_eq_monoid_of_mk', add_comm (n : ℤ) 1, add_smul]), zsmul_neg' := λ n x, localization.induction_on x (λ x, by { rw [smul_mk, smul_mk, neg_mk, ← neg_smul], refl }), neg := has_neg.neg, sub := λ x y, x + -y, sub_eq_add_neg := λ x y, rfl, add_left_neg := λ y, by exact localization.induction_on y begin intros, simp only [add_mk, localization.mk_mul, neg_mk, ← mk_zero 1], refine mk_eq_mk_iff.mpr (r_of_eq _), simp only [submonoid.coe_mul], ring end, .. localization.comm_semiring } lemma sub_mk (a c) (b d) : (mk a b : localization M) - mk c d = mk (d * a - b * c) (b * d) := calc mk a b - mk c d = mk a b + (- mk c d) : sub_eq_add_neg _ _ ... = mk a b + (mk (-c) d) : by rw neg_mk ... = mk (b * (-c) + d * a) (b * d) : add_mk _ _ _ _ ... = mk (d * a - b * c) (b * d) : by congr'; ring lemma mk_int_cast (m : ℤ) : (mk m 1 : localization M) = m := by simpa using @mk_algebra_map R _ M ℤ _ _ m end localization namespace is_localization variables {R M} (S) {K : Type*} [is_localization M S] lemma to_map_eq_zero_iff {x : R} (hM : M ≤ non_zero_divisors R) : algebra_map R S x = 0 ↔ x = 0 := begin rw ← (algebra_map R S).map_zero, split; intro h, { cases (eq_iff_exists M S).mp h with c hc, rw zero_mul at hc, exact hM c.2 x hc }, { rw h }, end protected lemma injective (hM : M ≤ non_zero_divisors R) : injective (algebra_map R S) := begin rw injective_iff_map_eq_zero (algebra_map R S), intros a ha, rwa to_map_eq_zero_iff S hM at ha end protected lemma to_map_ne_zero_of_mem_non_zero_divisors [nontrivial R] (hM : M ≤ non_zero_divisors R) {x : R} (hx : x ∈ non_zero_divisors R) : algebra_map R S x ≠ 0 := show (algebra_map R S).to_monoid_with_zero_hom x ≠ 0, from map_ne_zero_of_mem_non_zero_divisors (algebra_map R S) (is_localization.injective S hM) hx variables (S M) (Q : Type*) [comm_ring Q] {g : R →+* P} [algebra P Q] /-- Injectivity of a map descends to the map induced on localizations. -/ lemma map_injective_of_injective (hg : function.injective g) [is_localization (M.map g : submonoid P) Q] (hM : (M.map g : submonoid P) ≤ non_zero_divisors P) : function.injective (map Q g M.le_comap_map : S → Q) := begin rintros x y hxy, obtain ⟨a, b, rfl⟩ := mk'_surjective M x, obtain ⟨c, d, rfl⟩ := mk'_surjective M y, rw [map_mk' _ a b, map_mk' _ c d, mk'_eq_iff_eq] at hxy, refine mk'_eq_iff_eq.2 (congr_arg (algebra_map _ _) (hg _)), convert is_localization.injective _ hM hxy; simp, end variables {S Q M} variables (A : Type*) [comm_ring A] [is_domain A] /-- A `comm_ring` `S` which is the localization of an integral domain `R` at a subset of non-zero elements is an integral domain. See note [reducible non-instances]. -/ @[reducible] theorem is_domain_of_le_non_zero_divisors [algebra A S] {M : submonoid A} [is_localization M S] (hM : M ≤ non_zero_divisors A) : is_domain S := { eq_zero_or_eq_zero_of_mul_eq_zero := begin intros z w h, cases surj M z with x hx, cases surj M w with y hy, have : z * w * algebra_map A S y.2 * algebra_map A S x.2 = algebra_map A S x.1 * algebra_map A S y.1, by rw [mul_assoc z, hy, ←hx]; ring, rw [h, zero_mul, zero_mul, ← (algebra_map A S).map_mul] at this, cases eq_zero_or_eq_zero_of_mul_eq_zero ((to_map_eq_zero_iff S hM).mp this.symm) with H H, { exact or.inl (eq_zero_of_fst_eq_zero hx H) }, { exact or.inr (eq_zero_of_fst_eq_zero hy H) }, end, exists_pair_ne := ⟨(algebra_map A S) 0, (algebra_map A S) 1, λ h, zero_ne_one (is_localization.injective S hM h)⟩, } variables {A} /-- The localization at of an integral domain to a set of non-zero elements is an integral domain. See note [reducible non-instances]. -/ @[reducible] theorem is_domain_localization {M : submonoid A} (hM : M ≤ non_zero_divisors A) : is_domain (localization M) := is_domain_of_le_non_zero_divisors _ hM end is_localization open is_localization /-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/ lemma is_field.localization_map_bijective {R Rₘ : Type*} [comm_ring R] [comm_ring Rₘ] {M : submonoid R} (hM : (0 : R) ∉ M) (hR : is_field R) [algebra R Rₘ] [is_localization M Rₘ] : function.bijective (algebra_map R Rₘ) := begin letI := hR.to_field, replace hM := le_non_zero_divisors_of_no_zero_divisors hM, refine ⟨is_localization.injective _ hM, λ x, _⟩, obtain ⟨r, ⟨m, hm⟩, rfl⟩ := mk'_surjective M x, obtain ⟨n, hn⟩ := hR.mul_inv_cancel (non_zero_divisors.ne_zero $ hM hm), exact ⟨r * n, by erw [eq_mk'_iff_mul_eq, ←map_mul, mul_assoc, mul_comm n, hn, mul_one]⟩ end /-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/ lemma field.localization_map_bijective {K Kₘ : Type*} [field K] [comm_ring Kₘ] {M : submonoid K} (hM : (0 : K) ∉ M) [algebra K Kₘ] [is_localization M Kₘ] : function.bijective (algebra_map K Kₘ) := (field.to_is_field K).localization_map_bijective hM -- this looks weird due to the `letI` inside the above lemma, but trying to do it the other -- way round causes issues with defeq of instances, so this is actually easier. section algebra variables {R S} {Rₘ Sₘ : Type*} [comm_ring Rₘ] [comm_ring Sₘ] variables [algebra R Rₘ] [is_localization M Rₘ] variables [algebra S Sₘ] [is_localization (algebra.algebra_map_submonoid S M) Sₘ] section variables (S M) /-- Definition of the natural algebra induced by the localization of an algebra. Given an algebra `R → S`, a submonoid `R` of `M`, and a localization `Rₘ` for `M`, let `Sₘ` be the localization of `S` to the image of `M` under `algebra_map R S`. Then this is the natural algebra structure on `Rₘ → Sₘ`, such that the entire square commutes, where `localization_map.map_comp` gives the commutativity of the underlying maps -/ noncomputable def localization_algebra : algebra Rₘ Sₘ := (map Sₘ (algebra_map R S) (show _ ≤ (algebra.algebra_map_submonoid S M).comap _, from M.le_comap_map) : Rₘ →+* Sₘ).to_algebra end lemma algebra_map_mk' (r : R) (m : M) : (@algebra_map Rₘ Sₘ _ _ (localization_algebra M S)) (mk' Rₘ r m) = mk' Sₘ (algebra_map R S r) ⟨algebra_map R S m, algebra.mem_algebra_map_submonoid_of_mem m⟩ := map_mk' _ _ _ variables (Rₘ Sₘ) /-- Injectivity of the underlying `algebra_map` descends to the algebra induced by localization. -/ lemma localization_algebra_injective (hRS : function.injective (algebra_map R S)) (hM : algebra.algebra_map_submonoid S M ≤ non_zero_divisors S) : function.injective (@algebra_map Rₘ Sₘ _ _ (localization_algebra M S)) := is_localization.map_injective_of_injective M Rₘ Sₘ hRS hM end algebra end comm_ring
6155ea597b6bea62173929c241bb9026d4a19811
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/linear_algebra/affine_space/independent.lean
fa328b91b4a9f5d22f009bc72979f63d15388454
[ "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
36,900
lean
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import data.finset.sort import data.fin.vec_notation import linear_algebra.affine_space.combination import linear_algebra.affine_space.affine_equiv import linear_algebra.basis /-! # Affine independence This file defines affinely independent families of points. ## Main definitions * `affine_independent` defines affinely independent families of points as those where no nontrivial weighted subtraction is `0`. This is proved equivalent to two other formulations: linear independence of the results of subtracting a base point in the family from the other points in the family, or any equal affine combinations having the same weights. A bundled type `simplex` is provided for finite affinely independent families of points, with an abbreviation `triangle` for the case of three points. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable theory open_locale big_operators affine open function section affine_independent variables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V] variables [affine_space V P] {ι : Type*} include V /-- An indexed family is said to be affinely independent if no nontrivial weighted subtractions (where the sum of weights is 0) are 0. -/ def affine_independent (p : ι → P) : Prop := ∀ (s : finset ι) (w : ι → k), ∑ i in s, w i = 0 → s.weighted_vsub p w = (0:V) → ∀ i ∈ s, w i = 0 /-- The definition of `affine_independent`. -/ lemma affine_independent_def (p : ι → P) : affine_independent k p ↔ ∀ (s : finset ι) (w : ι → k), ∑ i in s, w i = 0 → s.weighted_vsub p w = (0 : V) → ∀ i ∈ s, w i = 0 := iff.rfl /-- A family with at most one point is affinely independent. -/ lemma affine_independent_of_subsingleton [subsingleton ι] (p : ι → P) : affine_independent k p := λ s w h hs i hi, fintype.eq_of_subsingleton_of_sum_eq h i hi /-- A family indexed by a `fintype` is affinely independent if and only if no nontrivial weighted subtractions over `finset.univ` (where the sum of the weights is 0) are 0. -/ lemma affine_independent_iff_of_fintype [fintype ι] (p : ι → P) : affine_independent k p ↔ ∀ w : ι → k, ∑ i, w i = 0 → finset.univ.weighted_vsub p w = (0 : V) → ∀ i, w i = 0 := begin split, { exact λ h w hw hs i, h finset.univ w hw hs i (finset.mem_univ _) }, { intros h s w hw hs i hi, rw finset.weighted_vsub_indicator_subset _ _ (finset.subset_univ s) at hs, rw set.sum_indicator_subset _ (finset.subset_univ s) at hw, replace h := h ((↑s : set ι).indicator w) hw hs i, simpa [hi] using h } end /-- A family is affinely independent if and only if the differences from a base point in that family are linearly independent. -/ lemma affine_independent_iff_linear_independent_vsub (p : ι → P) (i1 : ι) : affine_independent k p ↔ linear_independent k (λ i : {x // x ≠ i1}, (p i -ᵥ p i1 : V)) := begin classical, split, { intro h, rw linear_independent_iff', intros s g hg i hi, set f : ι → k := λ x, if hx : x = i1 then -∑ y in s, g y else g ⟨x, hx⟩ with hfdef, let s2 : finset ι := insert i1 (s.map (embedding.subtype _)), have hfg : ∀ x : {x // x ≠ i1}, g x = f x, { intro x, rw hfdef, dsimp only [], erw [dif_neg x.property, subtype.coe_eta] }, rw hfg, have hf : ∑ ι in s2, f ι = 0, { rw [finset.sum_insert (finset.not_mem_map_subtype_of_not_property s (not_not.2 rfl)), finset.sum_subtype_map_embedding (λ x hx, (hfg x).symm)], rw hfdef, dsimp only [], rw dif_pos rfl, exact neg_add_self _ }, have hs2 : s2.weighted_vsub p f = (0:V), { set f2 : ι → V := λ x, f x • (p x -ᵥ p i1) with hf2def, set g2 : {x // x ≠ i1} → V := λ x, g x • (p x -ᵥ p i1) with hg2def, have hf2g2 : ∀ x : {x // x ≠ i1}, f2 x = g2 x, { simp_rw [hf2def, hg2def, hfg], exact λ x, rfl }, rw [finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero s2 f p hf (p i1), finset.weighted_vsub_of_point_insert, finset.weighted_vsub_of_point_apply, finset.sum_subtype_map_embedding (λ x hx, hf2g2 x)], exact hg }, exact h s2 f hf hs2 i (finset.mem_insert_of_mem (finset.mem_map.2 ⟨i, hi, rfl⟩)) }, { intro h, rw linear_independent_iff' at h, intros s w hw hs i hi, rw [finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero s w p hw (p i1), ←s.weighted_vsub_of_point_erase w p i1, finset.weighted_vsub_of_point_apply] at hs, let f : ι → V := λ i, w i • (p i -ᵥ p i1), have hs2 : ∑ i in (s.erase i1).subtype (λ i, i ≠ i1), f i = 0, { rw [←hs], convert finset.sum_subtype_of_mem f (λ x, finset.ne_of_mem_erase) }, have h2 := h ((s.erase i1).subtype (λ i, i ≠ i1)) (λ x, w x) hs2, simp_rw [finset.mem_subtype] at h2, have h2b : ∀ i ∈ s, i ≠ i1 → w i = 0 := λ i his hi, h2 ⟨i, hi⟩ (finset.mem_erase_of_ne_of_mem hi his), exact finset.eq_zero_of_sum_eq_zero hw h2b i hi } end /-- A set is affinely independent if and only if the differences from a base point in that set are linearly independent. -/ lemma affine_independent_set_iff_linear_independent_vsub {s : set P} {p₁ : P} (hp₁ : p₁ ∈ s) : affine_independent k (λ p, p : s → P) ↔ linear_independent k (λ v, v : (λ p, (p -ᵥ p₁ : V)) '' (s \ {p₁}) → V) := begin rw affine_independent_iff_linear_independent_vsub k (λ p, p : s → P) ⟨p₁, hp₁⟩, split, { intro h, have hv : ∀ v : (λ p, (p -ᵥ p₁ : V)) '' (s \ {p₁}), (v : V) +ᵥ p₁ ∈ s \ {p₁} := λ v, (vsub_left_injective p₁).mem_set_image.1 ((vadd_vsub (v : V) p₁).symm ▸ v.property), let f : (λ p : P, (p -ᵥ p₁ : V)) '' (s \ {p₁}) → {x : s // x ≠ ⟨p₁, hp₁⟩} := λ x, ⟨⟨(x : V) +ᵥ p₁, set.mem_of_mem_diff (hv x)⟩, λ hx, set.not_mem_of_mem_diff (hv x) (subtype.ext_iff.1 hx)⟩, convert h.comp f (λ x1 x2 hx, (subtype.ext (vadd_right_cancel p₁ (subtype.ext_iff.1 (subtype.ext_iff.1 hx))))), ext v, exact (vadd_vsub (v : V) p₁).symm }, { intro h, let f : {x : s // x ≠ ⟨p₁, hp₁⟩} → (λ p : P, (p -ᵥ p₁ : V)) '' (s \ {p₁}) := λ x, ⟨((x : s) : P) -ᵥ p₁, ⟨x, ⟨⟨(x : s).property, λ hx, x.property (subtype.ext hx)⟩, rfl⟩⟩⟩, convert h.comp f (λ x1 x2 hx, subtype.ext (subtype.ext (vsub_left_cancel (subtype.ext_iff.1 hx)))) } end /-- A set of nonzero vectors is linearly independent if and only if, given a point `p₁`, the vectors added to `p₁` and `p₁` itself are affinely independent. -/ lemma linear_independent_set_iff_affine_independent_vadd_union_singleton {s : set V} (hs : ∀ v ∈ s, v ≠ (0 : V)) (p₁ : P) : linear_independent k (λ v, v : s → V) ↔ affine_independent k (λ p, p : {p₁} ∪ ((λ v, v +ᵥ p₁) '' s) → P) := begin rw affine_independent_set_iff_linear_independent_vsub k (set.mem_union_left _ (set.mem_singleton p₁)), have h : (λ p, (p -ᵥ p₁ : V)) '' (({p₁} ∪ (λ v, v +ᵥ p₁) '' s) \ {p₁}) = s, { simp_rw [set.union_diff_left, set.image_diff (vsub_left_injective p₁), set.image_image, set.image_singleton, vsub_self, vadd_vsub, set.image_id'], exact set.diff_singleton_eq_self (λ h, hs 0 h rfl) }, rw h end /-- A family is affinely independent if and only if any affine combinations (with sum of weights 1) that evaluate to the same point have equal `set.indicator`. -/ lemma affine_independent_iff_indicator_eq_of_affine_combination_eq (p : ι → P) : affine_independent k p ↔ ∀ (s1 s2 : finset ι) (w1 w2 : ι → k), ∑ i in s1, w1 i = 1 → ∑ i in s2, w2 i = 1 → s1.affine_combination p w1 = s2.affine_combination p w2 → set.indicator ↑s1 w1 = set.indicator ↑s2 w2 := begin classical, split, { intros ha s1 s2 w1 w2 hw1 hw2 heq, ext i, by_cases hi : i ∈ (s1 ∪ s2), { rw ←sub_eq_zero, rw set.sum_indicator_subset _ (finset.subset_union_left s1 s2) at hw1, rw set.sum_indicator_subset _ (finset.subset_union_right s1 s2) at hw2, have hws : ∑ i in s1 ∪ s2, (set.indicator ↑s1 w1 - set.indicator ↑s2 w2) i = 0, { simp [hw1, hw2] }, rw [finset.affine_combination_indicator_subset _ _ (finset.subset_union_left s1 s2), finset.affine_combination_indicator_subset _ _ (finset.subset_union_right s1 s2), ←@vsub_eq_zero_iff_eq V, finset.affine_combination_vsub] at heq, exact ha (s1 ∪ s2) (set.indicator ↑s1 w1 - set.indicator ↑s2 w2) hws heq i hi }, { rw [←finset.mem_coe, finset.coe_union] at hi, simp [mt (set.mem_union_left ↑s2) hi, mt (set.mem_union_right ↑s1) hi] } }, { intros ha s w hw hs i0 hi0, let w1 : ι → k := function.update (function.const ι 0) i0 1, have hw1 : ∑ i in s, w1 i = 1, { rw [finset.sum_update_of_mem hi0, finset.sum_const_zero, add_zero] }, have hw1s : s.affine_combination p w1 = p i0 := s.affine_combination_of_eq_one_of_eq_zero w1 p hi0 (function.update_same _ _ _) (λ _ _ hne, function.update_noteq hne _ _), let w2 := w + w1, have hw2 : ∑ i in s, w2 i = 1, { simp [w2, finset.sum_add_distrib, hw, hw1] }, have hw2s : s.affine_combination p w2 = p i0, { simp [w2, ←finset.weighted_vsub_vadd_affine_combination, hs, hw1s] }, replace ha := ha s s w2 w1 hw2 hw1 (hw1s.symm ▸ hw2s), have hws : w2 i0 - w1 i0 = 0, { rw ←finset.mem_coe at hi0, rw [←set.indicator_of_mem hi0 w2, ←set.indicator_of_mem hi0 w1, ha, sub_self] }, simpa [w2] using hws } end /-- A finite family is affinely independent if and only if any affine combinations (with sum of weights 1) that evaluate to the same point are equal. -/ lemma affine_independent_iff_eq_of_fintype_affine_combination_eq [fintype ι] (p : ι → P) : affine_independent k p ↔ ∀ (w1 w2 : ι → k), ∑ i, w1 i = 1 → ∑ i, w2 i = 1 → finset.univ.affine_combination p w1 = finset.univ.affine_combination p w2 → w1 = w2 := begin rw affine_independent_iff_indicator_eq_of_affine_combination_eq, split, { intros h w1 w2 hw1 hw2 hweq, simpa only [set.indicator_univ, finset.coe_univ] using h _ _ w1 w2 hw1 hw2 hweq, }, { intros h s1 s2 w1 w2 hw1 hw2 hweq, have hw1' : ∑ i, (s1 : set ι).indicator w1 i = 1, { rwa set.sum_indicator_subset _ (finset.subset_univ s1) at hw1, }, have hw2' : ∑ i, (s2 : set ι).indicator w2 i = 1, { rwa set.sum_indicator_subset _ (finset.subset_univ s2) at hw2, }, rw [finset.affine_combination_indicator_subset w1 p (finset.subset_univ s1), finset.affine_combination_indicator_subset w2 p (finset.subset_univ s2)] at hweq, exact h _ _ hw1' hw2' hweq, }, end variables {k} /-- If we single out one member of an affine-independent family of points and affinely transport all others along the line joining them to this member, the resulting new family of points is affine- independent. This is the affine version of `linear_independent.units_smul`. -/ lemma affine_independent.units_line_map {p : ι → P} (hp : affine_independent k p) (j : ι) (w : ι → units k) : affine_independent k (λ i, affine_map.line_map (p j) (p i) (w i : k)) := begin rw affine_independent_iff_linear_independent_vsub k _ j at hp ⊢, simp only [affine_map.line_map_vsub_left, affine_map.coe_const, affine_map.line_map_same], exact hp.units_smul (λ i, w i), end lemma affine_independent.indicator_eq_of_affine_combination_eq {p : ι → P} (ha : affine_independent k p) (s₁ s₂ : finset ι) (w₁ w₂ : ι → k) (hw₁ : ∑ i in s₁, w₁ i = 1) (hw₂ : ∑ i in s₂, w₂ i = 1) (h : s₁.affine_combination p w₁ = s₂.affine_combination p w₂) : set.indicator ↑s₁ w₁ = set.indicator ↑s₂ w₂ := (affine_independent_iff_indicator_eq_of_affine_combination_eq k p).1 ha s₁ s₂ w₁ w₂ hw₁ hw₂ h /-- An affinely independent family is injective, if the underlying ring is nontrivial. -/ protected lemma affine_independent.injective [nontrivial k] {p : ι → P} (ha : affine_independent k p) : function.injective p := begin intros i j hij, rw affine_independent_iff_linear_independent_vsub _ _ j at ha, by_contra hij', exact ha.ne_zero ⟨i, hij'⟩ (vsub_eq_zero_iff_eq.mpr hij) end /-- If a family is affinely independent, so is any subfamily given by composition of an embedding into index type with the original family. -/ lemma affine_independent.comp_embedding {ι2 : Type*} (f : ι2 ↪ ι) {p : ι → P} (ha : affine_independent k p) : affine_independent k (p ∘ f) := begin classical, intros fs w hw hs i0 hi0, let fs' := fs.map f, let w' := λ i, if h : ∃ i2, f i2 = i then w h.some else 0, have hw' : ∀ i2 : ι2, w' (f i2) = w i2, { intro i2, have h : ∃ i : ι2, f i = f i2 := ⟨i2, rfl⟩, have hs : h.some = i2 := f.injective h.some_spec, simp_rw [w', dif_pos h, hs] }, have hw's : ∑ i in fs', w' i = 0, { rw [←hw, finset.sum_map], simp [hw'] }, have hs' : fs'.weighted_vsub p w' = (0:V), { rw [←hs, finset.weighted_vsub_map], congr' with i, simp [hw'] }, rw [←ha fs' w' hw's hs' (f i0) ((finset.mem_map' _).2 hi0), hw'] end /-- If a family is affinely independent, so is any subfamily indexed by a subtype of the index type. -/ protected lemma affine_independent.subtype {p : ι → P} (ha : affine_independent k p) (s : set ι) : affine_independent k (λ i : s, p i) := ha.comp_embedding (embedding.subtype _) /-- If an indexed family of points is affinely independent, so is the corresponding set of points. -/ protected lemma affine_independent.range {p : ι → P} (ha : affine_independent k p) : affine_independent k (λ x, x : set.range p → P) := begin let f : set.range p → ι := λ x, x.property.some, have hf : ∀ x, p (f x) = x := λ x, x.property.some_spec, let fe : set.range p ↪ ι := ⟨f, λ x₁ x₂ he, subtype.ext (hf x₁ ▸ hf x₂ ▸ he ▸ rfl)⟩, convert ha.comp_embedding fe, ext, simp [hf] end lemma affine_independent_equiv {ι' : Type*} (e : ι ≃ ι') {p : ι' → P} : affine_independent k (p ∘ e) ↔ affine_independent k p := begin refine ⟨_, affine_independent.comp_embedding e.to_embedding⟩, intros h, have : p = p ∘ e ∘ e.symm.to_embedding, { ext, simp, }, rw this, exact h.comp_embedding e.symm.to_embedding, end /-- If a set of points is affinely independent, so is any subset. -/ protected lemma affine_independent.mono {s t : set P} (ha : affine_independent k (λ x, x : t → P)) (hs : s ⊆ t) : affine_independent k (λ x, x : s → P) := ha.comp_embedding (s.embedding_of_subset t hs) /-- If the range of an injective indexed family of points is affinely independent, so is that family. -/ lemma affine_independent.of_set_of_injective {p : ι → P} (ha : affine_independent k (λ x, x : set.range p → P)) (hi : function.injective p) : affine_independent k p := ha.comp_embedding (⟨λ i, ⟨p i, set.mem_range_self _⟩, λ x y h, hi (subtype.mk_eq_mk.1 h)⟩ : ι ↪ set.range p) section composition variables {V₂ P₂ : Type*} [add_comm_group V₂] [module k V₂] [affine_space V₂ P₂] include V₂ /-- If the image of a family of points in affine space under an affine transformation is affine- independent, then the original family of points is also affine-independent. -/ lemma affine_independent.of_comp {p : ι → P} (f : P →ᵃ[k] P₂) (hai : affine_independent k (f ∘ p)) : affine_independent k p := begin cases is_empty_or_nonempty ι with h h, { haveI := h, apply affine_independent_of_subsingleton, }, obtain ⟨i⟩ := h, rw affine_independent_iff_linear_independent_vsub k p i, simp_rw [affine_independent_iff_linear_independent_vsub k (f ∘ p) i, function.comp_app, ← f.linear_map_vsub] at hai, exact linear_independent.of_comp f.linear hai, end /-- The image of a family of points in affine space, under an injective affine transformation, is affine-independent. -/ lemma affine_independent.map' {p : ι → P} (hai : affine_independent k p) (f : P →ᵃ[k] P₂) (hf : function.injective f) : affine_independent k (f ∘ p) := begin cases is_empty_or_nonempty ι with h h, { haveI := h, apply affine_independent_of_subsingleton, }, obtain ⟨i⟩ := h, rw affine_independent_iff_linear_independent_vsub k p i at hai, simp_rw [affine_independent_iff_linear_independent_vsub k (f ∘ p) i, function.comp_app, ← f.linear_map_vsub], have hf' : f.linear.ker = ⊥, { rwa [linear_map.ker_eq_bot, f.injective_iff_linear_injective], }, exact linear_independent.map' hai f.linear hf', end /-- Injective affine maps preserve affine independence. -/ lemma affine_map.affine_independent_iff {p : ι → P} (f : P →ᵃ[k] P₂) (hf : function.injective f) : affine_independent k (f ∘ p) ↔ affine_independent k p := ⟨affine_independent.of_comp f, λ hai, affine_independent.map' hai f hf⟩ /-- Affine equivalences preserve affine independence of families of points. -/ lemma affine_equiv.affine_independent_iff {p : ι → P} (e : P ≃ᵃ[k] P₂) : affine_independent k (e ∘ p) ↔ affine_independent k p := e.to_affine_map.affine_independent_iff e.to_equiv.injective /-- Affine equivalences preserve affine independence of subsets. -/ lemma affine_equiv.affine_independent_set_of_eq_iff {s : set P} (e : P ≃ᵃ[k] P₂) : affine_independent k (coe : (e '' s) → P₂) ↔ affine_independent k (coe : s → P) := begin have : e ∘ (coe : s → P) = (coe : e '' s → P₂) ∘ ((e : P ≃ P₂).image s) := rfl, rw [← e.affine_independent_iff, this, affine_independent_equiv], end end composition /-- If a family is affinely independent, and the spans of points indexed by two subsets of the index type have a point in common, those subsets of the index type have an element in common, if the underlying ring is nontrivial. -/ lemma affine_independent.exists_mem_inter_of_exists_mem_inter_affine_span [nontrivial k] {p : ι → P} (ha : affine_independent k p) {s1 s2 : set ι} {p0 : P} (hp0s1 : p0 ∈ affine_span k (p '' s1)) (hp0s2 : p0 ∈ affine_span k (p '' s2)): ∃ (i : ι), i ∈ s1 ∩ s2 := begin rw set.image_eq_range at hp0s1 hp0s2, rw [mem_affine_span_iff_eq_affine_combination, ←finset.eq_affine_combination_subset_iff_eq_affine_combination_subtype] at hp0s1 hp0s2, rcases hp0s1 with ⟨fs1, hfs1, w1, hw1, hp0s1⟩, rcases hp0s2 with ⟨fs2, hfs2, w2, hw2, hp0s2⟩, rw affine_independent_iff_indicator_eq_of_affine_combination_eq at ha, replace ha := ha fs1 fs2 w1 w2 hw1 hw2 (hp0s1 ▸ hp0s2), have hnz : ∑ i in fs1, w1 i ≠ 0 := hw1.symm ▸ one_ne_zero, rcases finset.exists_ne_zero_of_sum_ne_zero hnz with ⟨i, hifs1, hinz⟩, simp_rw [←set.indicator_of_mem (finset.mem_coe.2 hifs1) w1, ha] at hinz, use [i, hfs1 hifs1, hfs2 (set.mem_of_indicator_ne_zero hinz)] end /-- If a family is affinely independent, the spans of points indexed by disjoint subsets of the index type are disjoint, if the underlying ring is nontrivial. -/ lemma affine_independent.affine_span_disjoint_of_disjoint [nontrivial k] {p : ι → P} (ha : affine_independent k p) {s1 s2 : set ι} (hd : s1 ∩ s2 = ∅) : (affine_span k (p '' s1) : set P) ∩ affine_span k (p '' s2) = ∅ := begin by_contradiction hne, change (affine_span k (p '' s1) : set P) ∩ affine_span k (p '' s2) ≠ ∅ at hne, rw set.ne_empty_iff_nonempty at hne, rcases hne with ⟨p0, hp0s1, hp0s2⟩, cases ha.exists_mem_inter_of_exists_mem_inter_affine_span hp0s1 hp0s2 with i hi, exact set.not_mem_empty i (hd ▸ hi) end /-- If a family is affinely independent, a point in the family is in the span of some of the points given by a subset of the index type if and only if that point's index is in the subset, if the underlying ring is nontrivial. -/ @[simp] protected lemma affine_independent.mem_affine_span_iff [nontrivial k] {p : ι → P} (ha : affine_independent k p) (i : ι) (s : set ι) : p i ∈ affine_span k (p '' s) ↔ i ∈ s := begin split, { intro hs, have h := affine_independent.exists_mem_inter_of_exists_mem_inter_affine_span ha hs (mem_affine_span k (set.mem_image_of_mem _ (set.mem_singleton _))), rwa [←set.nonempty_def, set.inter_singleton_nonempty] at h }, { exact λ h, mem_affine_span k (set.mem_image_of_mem p h) } end /-- If a family is affinely independent, a point in the family is not in the affine span of the other points, if the underlying ring is nontrivial. -/ lemma affine_independent.not_mem_affine_span_diff [nontrivial k] {p : ι → P} (ha : affine_independent k p) (i : ι) (s : set ι) : p i ∉ affine_span k (p '' (s \ {i})) := by simp [ha] lemma exists_nontrivial_relation_sum_zero_of_not_affine_ind {t : finset V} (h : ¬ affine_independent k (coe : t → V)) : ∃ f : V → k, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := begin classical, rw affine_independent_iff_of_fintype at h, simp only [exists_prop, not_forall] at h, obtain ⟨w, hw, hwt, i, hi⟩ := h, simp only [finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero _ w (coe : t → V) hw 0, vsub_eq_sub, finset.weighted_vsub_of_point_apply, sub_zero] at hwt, let f : Π (x : V), x ∈ t → k := λ x hx, w ⟨x, hx⟩, refine ⟨λ x, if hx : x ∈ t then f x hx else (0 : k), _, _, by { use i, simp [hi, f], }⟩, suffices : ∑ (e : V) in t, dite (e ∈ t) (λ hx, (f e hx) • e) (λ hx, 0) = 0, { convert this, ext, by_cases hx : x ∈ t; simp [hx], }, all_goals { simp only [finset.sum_dite_of_true (λx h, h), subtype.val_eq_coe, finset.mk_coe, f, hwt, hw], }, end /-- Viewing a module as an affine space modelled on itself, we can characterise affine independence in terms of linear combinations. -/ lemma affine_independent_iff {ι} {p : ι → V} : affine_independent k p ↔ ∀ (s : finset ι) (w : ι → k), s.sum w = 0 → ∑ e in s, w e • p e = 0 → ∀ (e ∈ s), w e = 0 := forall₃_congr (λ s w hw, by simp [s.weighted_vsub_eq_linear_combination hw]) end affine_independent section division_ring variables {k : Type*} {V : Type*} {P : Type*} [division_ring k] [add_comm_group V] [module k V] variables [affine_space V P] {ι : Type*} include V /-- An affinely independent set of points can be extended to such a set that spans the whole space. -/ lemma exists_subset_affine_independent_affine_span_eq_top {s : set P} (h : affine_independent k (λ p, p : s → P)) : ∃ t : set P, s ⊆ t ∧ affine_independent k (λ p, p : t → P) ∧ affine_span k t = ⊤ := begin rcases s.eq_empty_or_nonempty with rfl | ⟨p₁, hp₁⟩, { have p₁ : P := add_torsor.nonempty.some, let hsv := basis.of_vector_space k V, have hsvi := hsv.linear_independent, have hsvt := hsv.span_eq, rw basis.coe_of_vector_space at hsvi hsvt, have h0 : ∀ v : V, v ∈ (basis.of_vector_space_index _ _) → v ≠ 0, { intros v hv, simpa using hsv.ne_zero ⟨v, hv⟩ }, rw linear_independent_set_iff_affine_independent_vadd_union_singleton k h0 p₁ at hsvi, exact ⟨{p₁} ∪ (λ v, v +ᵥ p₁) '' _, set.empty_subset _, hsvi, affine_span_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt⟩ }, { rw affine_independent_set_iff_linear_independent_vsub k hp₁ at h, let bsv := basis.extend h, have hsvi := bsv.linear_independent, have hsvt := bsv.span_eq, rw basis.coe_extend at hsvi hsvt, have hsv := h.subset_extend (set.subset_univ _), have h0 : ∀ v : V, v ∈ (h.extend _) → v ≠ 0, { intros v hv, simpa using bsv.ne_zero ⟨v, hv⟩ }, rw linear_independent_set_iff_affine_independent_vadd_union_singleton k h0 p₁ at hsvi, refine ⟨{p₁} ∪ (λ v, v +ᵥ p₁) '' h.extend (set.subset_univ _), _, _⟩, { refine set.subset.trans _ (set.union_subset_union_right _ (set.image_subset _ hsv)), simp [set.image_image] }, { use [hsvi, affine_span_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt] } } end variables (k V) lemma exists_affine_independent (s : set P) : ∃ t ⊆ s, affine_span k t = affine_span k s ∧ affine_independent k (coe : t → P) := begin rcases s.eq_empty_or_nonempty with rfl | ⟨p, hp⟩, { exact ⟨∅, set.empty_subset ∅, rfl, affine_independent_of_subsingleton k _⟩, }, obtain ⟨b, hb₁, hb₂, hb₃⟩ := exists_linear_independent k ((equiv.vadd_const p).symm '' s), have hb₀ : ∀ (v : V), v ∈ b → v ≠ 0, { exact λ v hv, hb₃.ne_zero (⟨v, hv⟩ : b), }, rw linear_independent_set_iff_affine_independent_vadd_union_singleton k hb₀ p at hb₃, refine ⟨{p} ∪ (equiv.vadd_const p) '' b, _, _, hb₃⟩, { apply set.union_subset (set.singleton_subset_iff.mpr hp), rwa ← (equiv.vadd_const p).subset_image' b s, }, { rw [equiv.coe_vadd_const_symm, ← vector_span_eq_span_vsub_set_right k hp] at hb₂, apply affine_subspace.ext_of_direction_eq, { have : submodule.span k b = submodule.span k (insert 0 b), { simp, }, simp only [direction_affine_span, ← hb₂, equiv.coe_vadd_const, set.singleton_union, vector_span_eq_span_vsub_set_right k (set.mem_insert p _), this], congr, change (equiv.vadd_const p).symm '' insert p ((equiv.vadd_const p) '' b) = _, rw [set.image_insert_eq, ← set.image_comp], simp, }, { use p, simp only [equiv.coe_vadd_const, set.singleton_union, set.mem_inter_iff, coe_affine_span], exact ⟨mem_span_points k _ _ (set.mem_insert p _), mem_span_points k _ _ hp⟩, }, }, end variables (k) {V P} /-- Two different points are affinely independent. -/ lemma affine_independent_of_ne {p₁ p₂ : P} (h : p₁ ≠ p₂) : affine_independent k ![p₁, p₂] := begin rw affine_independent_iff_linear_independent_vsub k ![p₁, p₂] 0, let i₁ : {x // x ≠ (0 : fin 2)} := ⟨1, by norm_num⟩, have he' : ∀ i, i = i₁, { rintro ⟨i, hi⟩, ext, fin_cases i, { simpa using hi } }, haveI : unique {x // x ≠ (0 : fin 2)} := ⟨⟨i₁⟩, he'⟩, have hz : (![p₁, p₂] ↑default -ᵥ ![p₁, p₂] 0 : V) ≠ 0, { rw he' default, simpa using h.symm }, exact linear_independent_unique _ hz end variables {k V P} /-- If all but one point of a family are affinely independent, and that point does not lie in the affine span of that family, the family is affinely independent. -/ lemma affine_independent.affine_independent_of_not_mem_span {p : ι → P} {i : ι} (ha : affine_independent k (λ x : {y // y ≠ i}, p x)) (hi : p i ∉ affine_span k (p '' {x | x ≠ i})) : affine_independent k p := begin classical, intros s w hw hs, let s' : finset {y // y ≠ i} := s.subtype (≠ i), let p' : {y // y ≠ i} → P := λ x, p x, by_cases his : i ∈ s ∧ w i ≠ 0, { refine false.elim (hi _), let wm : ι → k := -(w i)⁻¹ • w, have hms : s.weighted_vsub p wm = (0 : V), { simp [wm, hs] }, have hwm : ∑ i in s, wm i = 0, { simp [wm, ←finset.mul_sum, hw] }, have hwmi : wm i = -1, { simp [wm, his.2] }, let w' : {y // y ≠ i} → k := λ x, wm x, have hw' : ∑ x in s', w' x = 1, { simp_rw [w', finset.sum_subtype_eq_sum_filter], rw ←s.sum_filter_add_sum_filter_not (≠ i) at hwm, simp_rw [not_not, finset.filter_eq', if_pos his.1, finset.sum_singleton, ←wm, hwmi, ←sub_eq_add_neg, sub_eq_zero] at hwm, exact hwm }, rw [←s.affine_combination_eq_of_weighted_vsub_eq_zero_of_eq_neg_one hms his.1 hwmi, ←(subtype.range_coe : _ = {x | x ≠ i}), ←set.range_comp, ←s.affine_combination_subtype_eq_filter], exact affine_combination_mem_affine_span hw' p' }, { rw [not_and_distrib, not_not] at his, let w' : {y // y ≠ i} → k := λ x, w x, have hw' : ∑ x in s', w' x = 0, { simp_rw [finset.sum_subtype_eq_sum_filter], rw [finset.sum_filter_of_ne, hw], rintro x hxs hwx rfl, exact hwx (his.neg_resolve_left hxs) }, have hs' : s'.weighted_vsub p' w' = (0 : V), { simp_rw finset.weighted_vsub_subtype_eq_filter, rw [finset.weighted_vsub_filter_of_ne, hs], rintro x hxs hwx rfl, exact hwx (his.neg_resolve_left hxs) }, intros j hj, by_cases hji : j = i, { rw hji at hj, exact hji.symm ▸ (his.neg_resolve_left hj) }, { exact ha s' w' hw' hs' ⟨j, hji⟩ (finset.mem_subtype.2 hj) } } end /-- If distinct points `p₁` and `p₂` lie in `s` but `p₃` does not, the three points are affinely independent. -/ lemma affine_independent_of_ne_of_mem_of_mem_of_not_mem {s : affine_subspace k P} {p₁ p₂ p₃ : P} (hp₁p₂ : p₁ ≠ p₂) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∉ s) : affine_independent k ![p₁, p₂, p₃] := begin have ha : affine_independent k (λ x : {x : fin 3 // x ≠ 2}, ![p₁, p₂, p₃] x), { rw ←affine_independent_equiv ((fin_succ_above_equiv (2 : fin 3)).to_equiv), convert affine_independent_of_ne k hp₁p₂, ext x, fin_cases x; refl }, refine ha.affine_independent_of_not_mem_span _, intro h, refine hp₃ ((affine_subspace.le_def' _ s).1 _ p₃ h), simp_rw [affine_span_le, set.image_subset_iff, set.subset_def, set.mem_preimage], intro x, fin_cases x; simp [hp₁, hp₂] end /-- If distinct points `p₁` and `p₃` lie in `s` but `p₂` does not, the three points are affinely independent. -/ lemma affine_independent_of_ne_of_mem_of_not_mem_of_mem {s : affine_subspace k P} {p₁ p₂ p₃ : P} (hp₁p₃ : p₁ ≠ p₃) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∉ s) (hp₃ : p₃ ∈ s) : affine_independent k ![p₁, p₂, p₃] := begin rw ←affine_independent_equiv (equiv.swap (1 : fin 3) 2), convert affine_independent_of_ne_of_mem_of_mem_of_not_mem hp₁p₃ hp₁ hp₃ hp₂ using 1, ext x, fin_cases x; refl end /-- If distinct points `p₂` and `p₃` lie in `s` but `p₁` does not, the three points are affinely independent. -/ lemma affine_independent_of_ne_of_not_mem_of_mem_of_mem {s : affine_subspace k P} {p₁ p₂ p₃ : P} (hp₂p₃ : p₂ ≠ p₃) (hp₁ : p₁ ∉ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) : affine_independent k ![p₁, p₂, p₃] := begin rw ←affine_independent_equiv (equiv.swap (0 : fin 3) 2), convert affine_independent_of_ne_of_mem_of_mem_of_not_mem hp₂p₃.symm hp₃ hp₂ hp₁ using 1, ext x, fin_cases x; refl end end division_ring namespace affine variables (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V] [module k V] variables [affine_space V P] include V /-- A `simplex k P n` is a collection of `n + 1` affinely independent points. -/ structure simplex (n : ℕ) := (points : fin (n + 1) → P) (independent : affine_independent k points) /-- A `triangle k P` is a collection of three affinely independent points. -/ abbreviation triangle := simplex k P 2 namespace simplex variables {P} /-- Construct a 0-simplex from a point. -/ def mk_of_point (p : P) : simplex k P 0 := ⟨λ _, p, affine_independent_of_subsingleton k _⟩ /-- The point in a simplex constructed with `mk_of_point`. -/ @[simp] lemma mk_of_point_points (p : P) (i : fin 1) : (mk_of_point k p).points i = p := rfl instance [inhabited P] : inhabited (simplex k P 0) := ⟨mk_of_point k default⟩ instance nonempty : nonempty (simplex k P 0) := ⟨mk_of_point k $ add_torsor.nonempty.some⟩ variables {k V} /-- Two simplices are equal if they have the same points. -/ @[ext] lemma ext {n : ℕ} {s1 s2 : simplex k P n} (h : ∀ i, s1.points i = s2.points i) : s1 = s2 := begin cases s1, cases s2, congr' with i, exact h i end /-- Two simplices are equal if and only if they have the same points. -/ lemma ext_iff {n : ℕ} (s1 s2 : simplex k P n): s1 = s2 ↔ ∀ i, s1.points i = s2.points i := ⟨λ h _, h ▸ rfl, ext⟩ /-- A face of a simplex is a simplex with the given subset of points. -/ def face {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : simplex k P m := ⟨s.points ∘ fs.order_emb_of_fin h, s.independent.comp_embedding (fs.order_emb_of_fin h).to_embedding⟩ /-- The points of a face of a simplex are given by `mono_of_fin`. -/ lemma face_points {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) (i : fin (m + 1)) : (s.face h).points i = s.points (fs.order_emb_of_fin h i) := rfl /-- The points of a face of a simplex are given by `mono_of_fin`. -/ lemma face_points' {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : (s.face h).points = s.points ∘ (fs.order_emb_of_fin h) := rfl /-- A single-point face equals the 0-simplex constructed with `mk_of_point`. -/ @[simp] lemma face_eq_mk_of_point {n : ℕ} (s : simplex k P n) (i : fin (n + 1)) : s.face (finset.card_singleton i) = mk_of_point k (s.points i) := by { ext, simp [face_points] } /-- The set of points of a face. -/ @[simp] lemma range_face_points {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : set.range (s.face h).points = s.points '' ↑fs := by rw [face_points', set.range_comp, finset.range_order_emb_of_fin] end simplex end affine namespace affine namespace simplex variables {k : Type*} {V : Type*} {P : Type*} [division_ring k] [add_comm_group V] [module k V] [affine_space V P] include V /-- The centroid of a face of a simplex as the centroid of a subset of the points. -/ @[simp] lemma face_centroid_eq_centroid {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : finset.univ.centroid k (s.face h).points = fs.centroid k s.points := begin convert (finset.univ.centroid_map k (fs.order_emb_of_fin h).to_embedding s.points).symm, rw [← finset.coe_inj, finset.coe_map, finset.coe_univ, set.image_univ], simp end /-- Over a characteristic-zero division ring, the centroids given by two subsets of the points of a simplex are equal if and only if those faces are given by the same subset of points. -/ @[simp] lemma centroid_eq_iff [char_zero k] {n : ℕ} (s : simplex k P n) {fs₁ fs₂ : finset (fin (n + 1))} {m₁ m₂ : ℕ} (h₁ : fs₁.card = m₁ + 1) (h₂ : fs₂.card = m₂ + 1) : fs₁.centroid k s.points = fs₂.centroid k s.points ↔ fs₁ = fs₂ := begin refine ⟨λ h, _, congr_arg _⟩, rw [finset.centroid_eq_affine_combination_fintype, finset.centroid_eq_affine_combination_fintype] at h, have ha := (affine_independent_iff_indicator_eq_of_affine_combination_eq k s.points).1 s.independent _ _ _ _ (fs₁.sum_centroid_weights_indicator_eq_one_of_card_eq_add_one k h₁) (fs₂.sum_centroid_weights_indicator_eq_one_of_card_eq_add_one k h₂) h, simp_rw [finset.coe_univ, set.indicator_univ, function.funext_iff, finset.centroid_weights_indicator_def, finset.centroid_weights, h₁, h₂] at ha, ext i, specialize ha i, have key : ∀ n : ℕ, (n : k) + 1 ≠ 0 := λ n h, by norm_cast at h, -- we should be able to golf this to `refine ⟨λ hi, decidable.by_contradiction (λ hni, _), ...⟩`, -- but for some unknown reason it doesn't work. split; intro hi; by_contra hni, { simpa [hni, hi, key] using ha }, { simpa [hni, hi, key] using ha.symm } end /-- Over a characteristic-zero division ring, the centroids of two faces of a simplex are equal if and only if those faces are given by the same subset of points. -/ lemma face_centroid_eq_iff [char_zero k] {n : ℕ} (s : simplex k P n) {fs₁ fs₂ : finset (fin (n + 1))} {m₁ m₂ : ℕ} (h₁ : fs₁.card = m₁ + 1) (h₂ : fs₂.card = m₂ + 1) : finset.univ.centroid k (s.face h₁).points = finset.univ.centroid k (s.face h₂).points ↔ fs₁ = fs₂ := begin rw [face_centroid_eq_centroid, face_centroid_eq_centroid], exact s.centroid_eq_iff h₁ h₂ end /-- Two simplices with the same points have the same centroid. -/ lemma centroid_eq_of_range_eq {n : ℕ} {s₁ s₂ : simplex k P n} (h : set.range s₁.points = set.range s₂.points) : finset.univ.centroid k s₁.points = finset.univ.centroid k s₂.points := begin rw [←set.image_univ, ←set.image_univ, ←finset.coe_univ] at h, exact finset.univ.centroid_eq_of_inj_on_of_image_eq k _ (λ _ _ _ _ he, affine_independent.injective s₁.independent he) (λ _ _ _ _ he, affine_independent.injective s₂.independent he) h end end simplex end affine
60d32a4fcbcbc44dd5305a00388b14fc8d37b29b
08bd4ba4ca87dba1f09d2c96a26f5d65da81f4b4
/tests/lean/StxQuot.lean
33954779055554734893d58310bbe9d2a455ee40
[ "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", "Apache-2.0", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
gebner/lean4
d51c4922640a52a6f7426536ea669ef18a1d9af5
8cd9ce06843c9d42d6d6dc43d3e81e3b49dfc20f
refs/heads/master
1,685,732,780,391
1,672,962,627,000
1,673,459,398,000
373,307,283
0
0
Apache-2.0
1,691,316,730,000
1,622,669,271,000
Lean
UTF-8
Lean
false
false
4,619
lean
import Lean open Lean open Lean.Elab def run {α} [ToString α] : Unhygienic α → String := toString ∘ Unhygienic.run #eval run `() #eval run `(Nat.one) def miss : TSyntax `term := ⟨Syntax.missing⟩ #eval run `($miss) namespace Lean.Syntax #eval run `($miss) #eval run `($(miss)) #eval run `($(id miss) + 1) #eval run $ let id := miss; `($id + 1) end Lean.Syntax #eval run `(1 + 1) #eval run `([x,]) #eval run $ `(fun a => a) >>= pure #eval run $ `(def foo := 1) #eval run $ `(def foo := 1 def bar := 2) #eval run $ do let a ← `(Nat.one); `($a) #eval run $ do `($(← `(Nat.one))) #eval run $ do let a ← `(Nat.one); `(f $a $a) #eval run $ do let a ← `(Nat.one); `(f $ f $a 1) #eval run $ do let a ← `(Nat.one); `(f $(id a)) #eval run $ do let a ← `(Nat.one); `($(a).b) #eval run $ do let a ← `(1 + 2); match a with | `($a + $b) => `($b + $a) | _ => pure miss #eval run $ do let a ← `(1 + 2); match a with | stx@`($a + $b) => `($stx + $a) | _ => pure miss #eval run $ do let a ← `(def foo := 1); match a with | `($f:command) => pure f #eval run $ do let a ← `(def foo := 1 def bar := 2); match a with | `($f:command $g:command) => `($g:command $f:command) | _ => pure ⟨Syntax.missing⟩ #eval run $ do let a ← `(aa); match a with | `($_:ident) => pure 0 | `($_) => pure 1 #eval match mkIdent `aa with | `(aa) => 0 | _ => 1 #eval match mkIdent `aa with | `(ab) => 0 | _ => 1 #eval run $ do let a ← `(1 + 2); match a with | `($id:ident) => pure 0 | `($e) => pure 1 #eval run $ do let params ← #[`(a), `((b : Nat))].mapM id; `(fun $params:term* => 1) #eval run $ do let a ← `(fun (a : Nat) b => c); match a with | `(fun $aa* => $e) => pure aa | _ => pure #[] #eval run $ do let a ← `(∀ a, c); match a with | `(∀ $id:ident, $e) => pure id | _ => pure ⟨a⟩ #eval run $ do let a ← `(∀ _, c); match a with | `(∀ $id:ident, $e) => pure id | _ => pure ⟨a⟩ -- this one should NOT check the kind of the matched node #eval run $ do let a ← `(∀ _, c); match a with | `(∀ $a, $e) => pure a | _ => pure ⟨a⟩ #eval run $ do let a ← `(a); match a with | `($id:ident) => pure id | _ => pure ⟨a⟩ #eval run $ do let a ← `(a.{0}); match a with | `($id:ident) => pure id | _ => pure ⟨a⟩ #eval run $ do let a ← `(match a with | a => 1 | _ => 2); match a with | `(match $e:term with $eqns:matchAlt*) => pure eqns | _ => pure #[] def f (stx : Syntax) : Unhygienic Syntax := match stx with | `({ $f:ident := $e $[: $a]?}) => `({ $f:ident := $e $[: $(id a)]?}) | _ => unreachable! #eval run do f (← `({ a := a : a })) #eval run do f (← `({ a := a })) def f' (stx : Syntax) : Unhygienic Syntax := match stx with | `(section $(id?)?) => `(section $(id?)?) | _ => unreachable! #eval run do f' (← `(section)) #eval run do f' (← `(section foo)) #eval run do match ← `(match a with | a => b | a + 1 => b + 1) with | `(match $e:term with $[| $pats =>%$arr $rhss]*) => `(match $e:term with $[| $pats =>%$arr $rhss]*) | _ => unreachable! #eval run do match ← `(match a with | a => b | a + 1 => b + 1) with | `(match $e:term with $alts:matchAlt*) => `(match $e:term with $alts:matchAlt*) | _ => unreachable! open Parser.Term #eval run do match ← `(structInstField|a := b) with | `(Parser.Term.structInstField| $lhs:ident := $rhs) => pure #[lhs.raw, rhs] | _ => unreachable! #eval run do match ← `({ a := a : a }) with | `({ $f:ident := $e : 0 }) => pure "0" | `({ $f:ident := $e $[: $a?]?}) => pure "1" | stx => pure "2" #eval run `(sufficesDecl|x from x) #eval run do match ← `([1, 2, 3, 4]) with | `([$x, $ys,*, $z]) => pure #[x.raw, mkNullNode ys, z] | _ => unreachable! #eval run do match ← `([1, 2]) with | `([$x, $y, $zs,*]) => pure zs.getElems | `([$x, $ys,*]) => pure ys.getElems | _ => unreachable! #check (match · with | `([1, $ys,*, 2, $zs,*, 3]) => _) #eval run do match Syntax.setHeadInfo (← `(fun x =>%$(Syntax.atom (SourceInfo.synthetic ⟨2⟩ ⟨2⟩) "") x)) (SourceInfo.synthetic ⟨1⟩ ⟨1⟩) with | `(fun%$i1 $x =>%$i2 $y) => pure #[i1.getPos?, i2.getPos?] | _ => unreachable! #eval run ``(x) #eval run ``(id) #eval run ``(pure) syntax "foo" term : term #eval run ``(foo $(miss)) -- syntax with no quoted identifiers should be ignored #eval run ``(fun x => x) #eval run ``(fun x => y) #eval run ``(fun x y => x y) #eval run ``(fun ⟨x, y⟩ => x) #eval run do match mkIdent `b with | `(a) => pure "0" | `(b) => pure "1" | _ => pure "2" declare_syntax_cat mycat syntax "mystx" : mycat #eval run `(mycat| mystx)
3ca4843f3dad2c191220a8f121c36ba150691cc3
77c5b91fae1b966ddd1db969ba37b6f0e4901e88
/src/analysis/normed_space/operator_norm.lean
b0aca4575c62f5906b70e330b74ba177d3116cfd
[ "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
59,498
lean
/- Copyright (c) 2019 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo -/ import algebra.algebra.tower import analysis.normed_space.linear_isometry import analysis.normed_space.riesz_lemma import data.equiv.transfer_instance /-! # Operator norm on the space of continuous linear maps Define the operator norm on the space of continuous linear maps between normed spaces, and prove its basic properties. In particular, show that this space is itself a normed space. Since a lot of elementary properties don't require `∥x∥ = 0 → x = 0` we start setting up the theory for `semi_normed_space` and we specialize to `normed_space` at the end. -/ noncomputable theory open_locale classical nnreal topological_space variables {𝕜 : Type*} {E : Type*} {F : Type*} {G : Type*} section semi_normed variables [semi_normed_group E] [semi_normed_group F] [semi_normed_group G] open metric continuous_linear_map section normed_field /-! Most statements in this file require the field to be non-discrete, as this is necessary to deduce an inequality `∥f x∥ ≤ C ∥x∥` from the continuity of f. However, the other direction always holds. In this section, we just assume that `𝕜` is a normed field. In the remainder of the file, it will be non-discrete. -/ variables [normed_field 𝕜] [semi_normed_space 𝕜 E] [semi_normed_space 𝕜 F] (f : E →ₗ[𝕜] F) lemma linear_map.lipschitz_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : lipschitz_with (real.to_nnreal C) f := f.to_add_monoid_hom.lipschitz_of_bound C h lemma linear_map.lipschitz_of_bound_nnnorm (C : ℝ≥0) (h : ∀ x, ∥f x∥₊ ≤ C * ∥x∥₊) : lipschitz_with C f := f.to_add_monoid_hom.lipschitz_of_bound_nnnorm C h theorem linear_map.antilipschitz_of_bound {K : ℝ≥0} (h : ∀ x, ∥x∥ ≤ K * ∥f x∥) : antilipschitz_with K f := antilipschitz_with.of_le_mul_dist $ λ x y, by simpa only [dist_eq_norm, f.map_sub] using h (x - y) lemma linear_map.bound_of_antilipschitz {K : ℝ≥0} (h : antilipschitz_with K f) (x) : ∥x∥ ≤ K * ∥f x∥ := by simpa only [dist_zero_right, f.map_zero] using h.le_mul_dist x 0 lemma linear_map.uniform_continuous_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : uniform_continuous f := (f.lipschitz_of_bound C h).uniform_continuous lemma linear_map.continuous_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : continuous f := (f.lipschitz_of_bound C h).continuous /-- Construct a continuous linear map from a linear map and a bound on this linear map. The fact that the norm of the continuous linear map is then controlled is given in `linear_map.mk_continuous_norm_le`. -/ def linear_map.mk_continuous (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : E →L[𝕜] F := ⟨f, linear_map.continuous_of_bound f C h⟩ /-- Reinterpret a linear map `𝕜 →ₗ[𝕜] E` as a continuous linear map. This construction is generalized to the case of any finite dimensional domain in `linear_map.to_continuous_linear_map`. -/ def linear_map.to_continuous_linear_map₁ (f : 𝕜 →ₗ[𝕜] E) : 𝕜 →L[𝕜] E := f.mk_continuous (∥f 1∥) $ λ x, le_of_eq $ by { conv_lhs { rw ← mul_one x }, rw [← smul_eq_mul, f.map_smul, norm_smul, mul_comm] } /-- Construct a continuous linear map from a linear map and the existence of a bound on this linear map. If you have an explicit bound, use `linear_map.mk_continuous` instead, as a norm estimate will follow automatically in `linear_map.mk_continuous_norm_le`. -/ def linear_map.mk_continuous_of_exists_bound (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) : E →L[𝕜] F := ⟨f, let ⟨C, hC⟩ := h in linear_map.continuous_of_bound f C hC⟩ lemma continuous_of_linear_of_bound {f : E → F} (h_add : ∀ x y, f (x + y) = f x + f y) (h_smul : ∀ (c : 𝕜) x, f (c • x) = c • f x) {C : ℝ} (h_bound : ∀ x, ∥f x∥ ≤ C*∥x∥) : continuous f := let φ : E →ₗ[𝕜] F := { to_fun := f, map_add' := h_add, map_smul' := h_smul } in φ.continuous_of_bound C h_bound @[simp, norm_cast] lemma linear_map.mk_continuous_coe (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : ((f.mk_continuous C h) : E →ₗ[𝕜] F) = f := rfl @[simp] lemma linear_map.mk_continuous_apply (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) (x : E) : f.mk_continuous C h x = f x := rfl @[simp, norm_cast] lemma linear_map.mk_continuous_of_exists_bound_coe (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) : ((f.mk_continuous_of_exists_bound h) : E →ₗ[𝕜] F) = f := rfl @[simp] lemma linear_map.mk_continuous_of_exists_bound_apply (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) (x : E) : f.mk_continuous_of_exists_bound h x = f x := rfl @[simp] lemma linear_map.to_continuous_linear_map₁_coe (f : 𝕜 →ₗ[𝕜] E) : (f.to_continuous_linear_map₁ : 𝕜 →ₗ[𝕜] E) = f := rfl @[simp] lemma linear_map.to_continuous_linear_map₁_apply (f : 𝕜 →ₗ[𝕜] E) (x) : f.to_continuous_linear_map₁ x = f x := rfl end normed_field variables [nondiscrete_normed_field 𝕜] [semi_normed_space 𝕜 E] [semi_normed_space 𝕜 F] [semi_normed_space 𝕜 G] (c : 𝕜) (f g : E →L[𝕜] F) (h : F →L[𝕜] G) (x y z : E) include 𝕜 lemma linear_map.bound_of_shell_semi_normed (f : E →ₗ[𝕜] F) {ε C : ℝ} (ε_pos : 0 < ε) {c : 𝕜} (hc : 1 < ∥c∥) (hf : ∀ x, ε / ∥c∥ ≤ ∥x∥ → ∥x∥ < ε → ∥f x∥ ≤ C * ∥x∥) {x : E} (hx : ∥x∥ ≠ 0) : ∥f x∥ ≤ C * ∥x∥ := begin rcases rescale_to_shell_semi_normed hc ε_pos hx with ⟨δ, hδ, δxle, leδx, δinv⟩, simpa only [f.map_smul, norm_smul, mul_left_comm C, mul_le_mul_left (norm_pos_iff.2 hδ)] using hf (δ • x) leδx δxle end /-- If `∥x∥ = 0` and `f` is continuous then `∥f x∥ = 0`. -/ lemma norm_image_of_norm_zero {f : E →ₗ[𝕜] F} (hf : continuous f) {x : E} (hx : ∥x∥ = 0) : ∥f x∥ = 0 := begin refine le_antisymm (le_of_forall_pos_le_add (λ ε hε, _)) (norm_nonneg (f x)), rcases normed_group.tendsto_nhds_nhds.1 (hf.tendsto 0) ε hε with ⟨δ, δ_pos, hδ⟩, replace hδ := hδ x, rw [sub_zero, hx] at hδ, replace hδ := le_of_lt (hδ δ_pos), rw [linear_map.map_zero, sub_zero] at hδ, rwa [zero_add] end /-- A continuous linear map between seminormed spaces is bounded when the field is nondiscrete. The continuity ensures boundedness on a ball of some radius `ε`. The nondiscreteness is then used to rescale any element into an element of norm in `[ε/C, ε]`, whose image has a controlled norm. The norm control for the original element follows by rescaling. -/ lemma linear_map.bound_of_continuous (f : E →ₗ[𝕜] F) (hf : continuous f) : ∃ C, 0 < C ∧ (∀ x : E, ∥f x∥ ≤ C * ∥x∥) := begin rcases normed_group.tendsto_nhds_nhds.1 (hf.tendsto 0) 1 zero_lt_one with ⟨ε, ε_pos, hε⟩, simp only [sub_zero, f.map_zero] at hε, rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩, have : 0 < ∥c∥ / ε, from div_pos (zero_lt_one.trans hc) ε_pos, refine ⟨∥c∥ / ε, this, λ x, _⟩, by_cases hx : ∥x∥ = 0, { rw [hx, mul_zero], exact le_of_eq (norm_image_of_norm_zero hf hx) }, refine f.bound_of_shell_semi_normed ε_pos hc (λ x hle hlt, _) hx, refine (hε _ hlt).le.trans _, rwa [← div_le_iff' this, one_div_div] end namespace continuous_linear_map theorem bound : ∃ C, 0 < C ∧ (∀ x : E, ∥f x∥ ≤ C * ∥x∥) := f.to_linear_map.bound_of_continuous f.2 section open filter /-- A linear map which is a homothety is a continuous linear map. Since the field `𝕜` need not have `ℝ` as a subfield, this theorem is not directly deducible from the corresponding theorem about isometries plus a theorem about scalar multiplication. Likewise for the other theorems about homotheties in this file. -/ def of_homothety (f : E →ₗ[𝕜] F) (a : ℝ) (hf : ∀x, ∥f x∥ = a * ∥x∥) : E →L[𝕜] F := f.mk_continuous a (λ x, le_of_eq (hf x)) variable (𝕜) lemma to_span_singleton_homothety (x : E) (c : 𝕜) : ∥linear_map.to_span_singleton 𝕜 E x c∥ = ∥x∥ * ∥c∥ := by {rw mul_comm, exact norm_smul _ _} /-- Given an element `x` of a normed space `E` over a field `𝕜`, the natural continuous linear map from `E` to the span of `x`.-/ def to_span_singleton (x : E) : 𝕜 →L[𝕜] E := of_homothety (linear_map.to_span_singleton 𝕜 E x) ∥x∥ (to_span_singleton_homothety 𝕜 x) lemma to_span_singleton_apply (x : E) (r : 𝕜) : to_span_singleton 𝕜 x r = r • x := by simp [to_span_singleton, of_homothety, linear_map.to_span_singleton] lemma to_span_singleton_add (x y : E) : to_span_singleton 𝕜 (x + y) = to_span_singleton 𝕜 x + to_span_singleton 𝕜 y := by { ext1, simp [to_span_singleton_apply], } lemma to_span_singleton_smul' (𝕜') [nondiscrete_normed_field 𝕜'] [semi_normed_space 𝕜' E] [smul_comm_class 𝕜 𝕜' E] (c : 𝕜') (x : E) : to_span_singleton 𝕜 (c • x) = c • to_span_singleton 𝕜 x := by { ext1, rw [to_span_singleton_apply, smul_apply, to_span_singleton_apply, smul_comm], } lemma to_span_singleton_smul (c : 𝕜) (x : E) : to_span_singleton 𝕜 (c • x) = c • to_span_singleton 𝕜 x := to_span_singleton_smul' 𝕜 𝕜 c x end section op_norm open set real /-- The operator norm of a continuous linear map is the inf of all its bounds. -/ def op_norm := Inf {c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥} instance has_op_norm : has_norm (E →L[𝕜] F) := ⟨op_norm⟩ lemma norm_def : ∥f∥ = Inf {c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥} := rfl -- So that invocations of `le_cInf` make sense: we show that the set of -- bounds is nonempty and bounded below. lemma bounds_nonempty {f : E →L[𝕜] F} : ∃ c, c ∈ { c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥ } := let ⟨M, hMp, hMb⟩ := f.bound in ⟨M, le_of_lt hMp, hMb⟩ lemma bounds_bdd_below {f : E →L[𝕜] F} : bdd_below { c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥ } := ⟨0, λ _ ⟨hn, _⟩, hn⟩ lemma op_norm_nonneg : 0 ≤ ∥f∥ := le_cInf bounds_nonempty (λ _ ⟨hx, _⟩, hx) /-- The fundamental property of the operator norm: `∥f x∥ ≤ ∥f∥ * ∥x∥`. -/ theorem le_op_norm : ∥f x∥ ≤ ∥f∥ * ∥x∥ := begin obtain ⟨C, Cpos, hC⟩ := f.bound, replace hC := hC x, by_cases h : ∥x∥ = 0, { rwa [h, mul_zero] at ⊢ hC }, have hlt : 0 < ∥x∥ := lt_of_le_of_ne (norm_nonneg x) (ne.symm h), exact (div_le_iff hlt).mp (le_cInf bounds_nonempty (λ c ⟨_, hc⟩, (div_le_iff hlt).mpr $ by { apply hc })), end theorem le_op_norm_of_le {c : ℝ} {x} (h : ∥x∥ ≤ c) : ∥f x∥ ≤ ∥f∥ * c := le_trans (f.le_op_norm x) (mul_le_mul_of_nonneg_left h f.op_norm_nonneg) theorem le_of_op_norm_le {c : ℝ} (h : ∥f∥ ≤ c) (x : E) : ∥f x∥ ≤ c * ∥x∥ := (f.le_op_norm x).trans (mul_le_mul_of_nonneg_right h (norm_nonneg x)) lemma ratio_le_op_norm : ∥f x∥ / ∥x∥ ≤ ∥f∥ := div_le_of_nonneg_of_le_mul (norm_nonneg _) f.op_norm_nonneg (le_op_norm _ _) /-- The image of the unit ball under a continuous linear map is bounded. -/ lemma unit_le_op_norm : ∥x∥ ≤ 1 → ∥f x∥ ≤ ∥f∥ := mul_one ∥f∥ ▸ f.le_op_norm_of_le /-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/ lemma op_norm_le_bound {M : ℝ} (hMp: 0 ≤ M) (hM : ∀ x, ∥f x∥ ≤ M * ∥x∥) : ∥f∥ ≤ M := cInf_le bounds_bdd_below ⟨hMp, hM⟩ theorem op_norm_le_of_lipschitz {f : E →L[𝕜] F} {K : ℝ≥0} (hf : lipschitz_with K f) : ∥f∥ ≤ K := f.op_norm_le_bound K.2 $ λ x, by simpa only [dist_zero_right, f.map_zero] using hf.dist_le_mul x 0 lemma op_norm_le_of_shell {f : E →L[𝕜] F} {ε C : ℝ} (ε_pos : 0 < ε) (hC : 0 ≤ C) {c : 𝕜} (hc : 1 < ∥c∥) (hf : ∀ x, ε / ∥c∥ ≤ ∥x∥ → ∥x∥ < ε → ∥f x∥ ≤ C * ∥x∥) : ∥f∥ ≤ C := begin refine f.op_norm_le_bound hC (λ x, _), by_cases hx : ∥x∥ = 0, { rw [hx, mul_zero], exact le_of_eq (norm_image_of_norm_zero f.2 hx) }, exact linear_map.bound_of_shell_semi_normed f ε_pos hc hf hx end lemma op_norm_le_of_ball {f : E →L[𝕜] F} {ε : ℝ} {C : ℝ} (ε_pos : 0 < ε) (hC : 0 ≤ C) (hf : ∀ x ∈ ball (0 : E) ε, ∥f x∥ ≤ C * ∥x∥) : ∥f∥ ≤ C := begin rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩, refine op_norm_le_of_shell ε_pos hC hc (λ x _ hx, hf x _), rwa ball_zero_eq end lemma op_norm_le_of_nhds_zero {f : E →L[𝕜] F} {C : ℝ} (hC : 0 ≤ C) (hf : ∀ᶠ x in 𝓝 (0 : E), ∥f x∥ ≤ C * ∥x∥) : ∥f∥ ≤ C := let ⟨ε, ε0, hε⟩ := metric.eventually_nhds_iff_ball.1 hf in op_norm_le_of_ball ε0 hC hε lemma op_norm_le_of_shell' {f : E →L[𝕜] F} {ε C : ℝ} (ε_pos : 0 < ε) (hC : 0 ≤ C) {c : 𝕜} (hc : ∥c∥ < 1) (hf : ∀ x, ε * ∥c∥ ≤ ∥x∥ → ∥x∥ < ε → ∥f x∥ ≤ C * ∥x∥) : ∥f∥ ≤ C := begin by_cases h0 : c = 0, { refine op_norm_le_of_ball ε_pos hC (λ x hx, hf x _ _), { simp [h0] }, { rwa ball_zero_eq at hx } }, { rw [← inv_inv₀ c, normed_field.norm_inv, inv_lt_one_iff_of_pos (norm_pos_iff.2 $ inv_ne_zero h0)] at hc, refine op_norm_le_of_shell ε_pos hC hc _, rwa [normed_field.norm_inv, div_eq_mul_inv, inv_inv₀] } end lemma op_norm_eq_of_bounds {φ : E →L[𝕜] F} {M : ℝ} (M_nonneg : 0 ≤ M) (h_above : ∀ x, ∥φ x∥ ≤ M*∥x∥) (h_below : ∀ N ≥ 0, (∀ x, ∥φ x∥ ≤ N*∥x∥) → M ≤ N) : ∥φ∥ = M := le_antisymm (φ.op_norm_le_bound M_nonneg h_above) ((le_cInf_iff continuous_linear_map.bounds_bdd_below ⟨M, M_nonneg, h_above⟩).mpr $ λ N ⟨N_nonneg, hN⟩, h_below N N_nonneg hN) /-- The operator norm satisfies the triangle inequality. -/ theorem op_norm_add_le : ∥f + g∥ ≤ ∥f∥ + ∥g∥ := (f + g).op_norm_le_bound (add_nonneg f.op_norm_nonneg g.op_norm_nonneg) $ λ x, (norm_add_le_of_le (f.le_op_norm x) (g.le_op_norm x)).trans_eq (add_mul _ _ _).symm /-- The norm of the `0` operator is `0`. -/ theorem op_norm_zero : ∥(0 : E →L[𝕜] F)∥ = 0 := le_antisymm (cInf_le bounds_bdd_below ⟨ge_of_eq rfl, λ _, le_of_eq (by { rw [zero_mul], exact norm_zero })⟩) (op_norm_nonneg _) /-- The norm of the identity is at most `1`. It is in fact `1`, except when the space is trivial where it is `0`. It means that one can not do better than an inequality in general. -/ lemma norm_id_le : ∥id 𝕜 E∥ ≤ 1 := op_norm_le_bound _ zero_le_one (λx, by simp) /-- If there is an element with norm different from `0`, then the norm of the identity equals `1`. (Since we are working with seminorms supposing that the space is non-trivial is not enough.) -/ lemma norm_id_of_nontrivial_seminorm (h : ∃ (x : E), ∥x∥ ≠ 0) : ∥id 𝕜 E∥ = 1 := le_antisymm norm_id_le $ let ⟨x, hx⟩ := h in have _ := (id 𝕜 E).ratio_le_op_norm x, by rwa [id_apply, div_self hx] at this lemma op_norm_smul_le {𝕜' : Type*} [normed_field 𝕜'] [semi_normed_space 𝕜' F] [smul_comm_class 𝕜 𝕜' F] (c : 𝕜') (f : E →L[𝕜] F) : ∥c • f∥ ≤ ∥c∥ * ∥f∥ := ((c • f).op_norm_le_bound (mul_nonneg (norm_nonneg _) (op_norm_nonneg _)) (λ _, begin erw [norm_smul, mul_assoc], exact mul_le_mul_of_nonneg_left (le_op_norm _ _) (norm_nonneg _) end)) lemma op_norm_neg : ∥-f∥ = ∥f∥ := by simp only [norm_def, neg_apply, norm_neg] /-- Continuous linear maps themselves form a seminormed space with respect to the operator norm. -/ instance to_semi_normed_group : semi_normed_group (E →L[𝕜] F) := semi_normed_group.of_core _ ⟨op_norm_zero, op_norm_add_le, op_norm_neg⟩ instance to_semi_normed_space {𝕜' : Type*} [normed_field 𝕜'] [semi_normed_space 𝕜' F] [smul_comm_class 𝕜 𝕜' F] : semi_normed_space 𝕜' (E →L[𝕜] F) := ⟨op_norm_smul_le⟩ /-- The operator norm is submultiplicative. -/ lemma op_norm_comp_le (f : E →L[𝕜] F) : ∥h.comp f∥ ≤ ∥h∥ * ∥f∥ := (cInf_le bounds_bdd_below ⟨mul_nonneg (op_norm_nonneg _) (op_norm_nonneg _), λ x, by { rw mul_assoc, exact h.le_op_norm_of_le (f.le_op_norm x) } ⟩) /-- Continuous linear maps form a seminormed ring with respect to the operator norm. -/ instance to_semi_normed_ring : semi_normed_ring (E →L[𝕜] E) := { norm_mul := op_norm_comp_le, .. continuous_linear_map.to_semi_normed_group } theorem le_op_nnnorm : ∥f x∥₊ ≤ ∥f∥₊ * ∥x∥₊ := f.le_op_norm x /-- continuous linear maps are Lipschitz continuous. -/ theorem lipschitz : lipschitz_with ∥f∥₊ f := (f : E →ₗ[𝕜] F).lipschitz_of_bound_nnnorm _ f.le_op_nnnorm theorem le_op_norm₂ (f : E →L[𝕜] F →L[𝕜] G) (x : E) (y : F) : ∥f x y∥ ≤ ∥f∥ * ∥x∥ * ∥y∥ := (f x).le_of_op_norm_le (f.le_op_norm x) y theorem op_norm_le_bound₂ (f : E →L[𝕜] F →L[𝕜] G) {C : ℝ} (h0 : 0 ≤ C) (hC : ∀ x y, ∥f x y∥ ≤ C * ∥x∥ * ∥y∥) : ∥f∥ ≤ C := f.op_norm_le_bound h0 $ λ x, (f x).op_norm_le_bound (mul_nonneg h0 (norm_nonneg _)) $ hC x @[simp] lemma op_norm_prod (f : E →L[𝕜] F) (g : E →L[𝕜] G) : ∥f.prod g∥ = ∥(f, g)∥ := le_antisymm (op_norm_le_bound _ (norm_nonneg _) $ λ x, by simpa only [prod_apply, prod.semi_norm_def, max_mul_of_nonneg, norm_nonneg] using max_le_max (le_op_norm f x) (le_op_norm g x)) $ max_le (op_norm_le_bound _ (norm_nonneg _) $ λ x, (le_max_left _ _).trans ((f.prod g).le_op_norm x)) (op_norm_le_bound _ (norm_nonneg _) $ λ x, (le_max_right _ _).trans ((f.prod g).le_op_norm x)) /-- `continuous_linear_map.prod` as a `linear_isometry_equiv`. -/ def prodₗᵢ (R : Type*) [ring R] [topological_space R] [module R F] [module R G] [has_continuous_smul R F] [has_continuous_smul R G] [smul_comm_class 𝕜 R F] [smul_comm_class 𝕜 R G] : (E →L[𝕜] F) × (E →L[𝕜] G) ≃ₗᵢ[R] (E →L[𝕜] F × G) := ⟨prodₗ R, λ ⟨f, g⟩, op_norm_prod f g⟩ /-- A continuous linear map is automatically uniformly continuous. -/ protected theorem uniform_continuous : uniform_continuous f := f.lipschitz.uniform_continuous @[simp, nontriviality] lemma op_norm_subsingleton [subsingleton E] : ∥f∥ = 0 := begin refine le_antisymm _ (norm_nonneg _), apply op_norm_le_bound _ rfl.ge, intros x, simp [subsingleton.elim x 0] end /-- A continuous linear map is an isometry if and only if it preserves the norm. -/ lemma isometry_iff_norm : isometry f ↔ ∀x, ∥f x∥ = ∥x∥ := f.to_linear_map.to_add_monoid_hom.isometry_iff_norm end op_norm section is_O open asymptotics theorem is_O_with_id (l : filter E) : is_O_with ∥f∥ f (λ x, x) l := is_O_with_of_le' _ f.le_op_norm theorem is_O_id (l : filter E) : is_O f (λ x, x) l := (f.is_O_with_id l).is_O theorem is_O_with_comp {α : Type*} (g : F →L[𝕜] G) (f : α → F) (l : filter α) : is_O_with ∥g∥ (λ x', g (f x')) f l := (g.is_O_with_id ⊤).comp_tendsto le_top theorem is_O_comp {α : Type*} (g : F →L[𝕜] G) (f : α → F) (l : filter α) : is_O (λ x', g (f x')) f l := (g.is_O_with_comp f l).is_O theorem is_O_with_sub (f : E →L[𝕜] F) (l : filter E) (x : E) : is_O_with ∥f∥ (λ x', f (x' - x)) (λ x', x' - x) l := f.is_O_with_comp _ l theorem is_O_sub (f : E →L[𝕜] F) (l : filter E) (x : E) : is_O (λ x', f (x' - x)) (λ x', x' - x) l := f.is_O_comp _ l end is_O end continuous_linear_map namespace linear_isometry lemma norm_to_continuous_linear_map_le (f : E →ₗᵢ[𝕜] F) : ∥f.to_continuous_linear_map∥ ≤ 1 := f.to_continuous_linear_map.op_norm_le_bound zero_le_one $ λ x, by simp end linear_isometry namespace linear_map /-- If a continuous linear map is constructed from a linear map via the constructor `mk_continuous`, then its norm is bounded by the bound given to the constructor if it is nonnegative. -/ lemma mk_continuous_norm_le (f : E →ₗ[𝕜] F) {C : ℝ} (hC : 0 ≤ C) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : ∥f.mk_continuous C h∥ ≤ C := continuous_linear_map.op_norm_le_bound _ hC h /-- If a continuous linear map is constructed from a linear map via the constructor `mk_continuous`, then its norm is bounded by the bound or zero if bound is negative. -/ lemma mk_continuous_norm_le' (f : E →ₗ[𝕜] F) {C : ℝ} (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : ∥f.mk_continuous C h∥ ≤ max C 0 := continuous_linear_map.op_norm_le_bound _ (le_max_right _ _) $ λ x, (h x).trans $ mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg x) /-- Create a bilinear map (represented as a map `E →L[𝕜] F →L[𝕜] G`) from the corresponding linear map and a bound on the norm of the image. The linear map can be constructed using `linear_map.mk₂`. -/ def mk_continuous₂ (f : E →ₗ[𝕜] F →ₗ[𝕜] G) (C : ℝ) (hC : ∀ x y, ∥f x y∥ ≤ C * ∥x∥ * ∥y∥) : E →L[𝕜] F →L[𝕜] G := linear_map.mk_continuous { to_fun := λ x, (f x).mk_continuous (C * ∥x∥) (hC x), map_add' := λ x y, by { ext z, simp }, map_smul' := λ c x, by { ext z, simp } } (max C 0) $ λ x, (mk_continuous_norm_le' _ _).trans_eq $ by rw [max_mul_of_nonneg _ _ (norm_nonneg x), zero_mul] @[simp] lemma mk_continuous₂_apply (f : E →ₗ[𝕜] F →ₗ[𝕜] G) {C : ℝ} (hC : ∀ x y, ∥f x y∥ ≤ C * ∥x∥ * ∥y∥) (x : E) (y : F) : f.mk_continuous₂ C hC x y = f x y := rfl lemma mk_continuous₂_norm_le' (f : E →ₗ[𝕜] F →ₗ[𝕜] G) {C : ℝ} (hC : ∀ x y, ∥f x y∥ ≤ C * ∥x∥ * ∥y∥) : ∥f.mk_continuous₂ C hC∥ ≤ max C 0 := mk_continuous_norm_le _ (le_max_iff.2 $ or.inr le_rfl) _ lemma mk_continuous₂_norm_le (f : E →ₗ[𝕜] F →ₗ[𝕜] G) {C : ℝ} (h0 : 0 ≤ C) (hC : ∀ x y, ∥f x y∥ ≤ C * ∥x∥ * ∥y∥) : ∥f.mk_continuous₂ C hC∥ ≤ C := (f.mk_continuous₂_norm_le' hC).trans_eq $ max_eq_left h0 end linear_map namespace continuous_linear_map /-- Flip the order of arguments of a continuous bilinear map. For a version bundled as `linear_isometry_equiv`, see `continuous_linear_map.flipL`. -/ def flip (f : E →L[𝕜] F →L[𝕜] G) : F →L[𝕜] E →L[𝕜] G := linear_map.mk_continuous₂ (linear_map.mk₂ 𝕜 (λ y x, f x y) (λ x y z, (f z).map_add x y) (λ c y x, (f x).map_smul c y) (λ z x y, by rw [f.map_add, add_apply]) (λ c y x, by rw [map_smul, smul_apply])) ∥f∥ (λ y x, (f.le_op_norm₂ x y).trans_eq $ by rw mul_right_comm) private lemma le_norm_flip (f : E →L[𝕜] F →L[𝕜] G) : ∥f∥ ≤ ∥flip f∥ := f.op_norm_le_bound₂ (norm_nonneg _) $ λ x y, by { rw mul_right_comm, exact (flip f).le_op_norm₂ y x } @[simp] lemma flip_apply (f : E →L[𝕜] F →L[𝕜] G) (x : E) (y : F) : f.flip y x = f x y := rfl @[simp] lemma flip_flip (f : E →L[𝕜] F →L[𝕜] G) : f.flip.flip = f := by { ext, refl } @[simp] lemma op_norm_flip (f : E →L[𝕜] F →L[𝕜] G) : ∥f.flip∥ = ∥f∥ := le_antisymm (by simpa only [flip_flip] using le_norm_flip f.flip) (le_norm_flip f) @[simp] lemma flip_add (f g : E →L[𝕜] F →L[𝕜] G) : (f + g).flip = f.flip + g.flip := rfl @[simp] lemma flip_smul (c : 𝕜) (f : E →L[𝕜] F →L[𝕜] G) : (c • f).flip = c • f.flip := rfl variables (𝕜 E F G) /-- Flip the order of arguments of a continuous bilinear map. This is a version bundled as a `linear_isometry_equiv`. For an unbundled version see `continuous_linear_map.flip`. -/ def flipₗᵢ : (E →L[𝕜] F →L[𝕜] G) ≃ₗᵢ[𝕜] (F →L[𝕜] E →L[𝕜] G) := { to_fun := flip, inv_fun := flip, map_add' := flip_add, map_smul' := flip_smul, left_inv := flip_flip, right_inv := flip_flip, norm_map' := op_norm_flip } variables {𝕜 E F G} @[simp] lemma flipₗᵢ_symm : (flipₗᵢ 𝕜 E F G).symm = flipₗᵢ 𝕜 F E G := rfl @[simp] lemma coe_flipₗᵢ : ⇑(flipₗᵢ 𝕜 E F G) = flip := rfl variables (𝕜 F) /-- The continuous linear map obtained by applying a continuous linear map at a given vector. This is the continuous version of `linear_map.applyₗ`. -/ def apply : E →L[𝕜] (E →L[𝕜] F) →L[𝕜] F := flip (id 𝕜 (E →L[𝕜] F)) variables {𝕜 F} @[simp] lemma apply_apply (v : E) (f : E →L[𝕜] F) : apply 𝕜 F v f = f v := rfl variables (𝕜 E F G) /-- Composition of continuous linear maps as a continuous bilinear map. -/ def compL : (F →L[𝕜] G) →L[𝕜] (E →L[𝕜] F) →L[𝕜] (E →L[𝕜] G) := linear_map.mk_continuous₂ (linear_map.mk₂ _ comp add_comp smul_comp comp_add (λ c f g, comp_smul _ _ _)) 1 $ λ f g, by simpa only [one_mul] using op_norm_comp_le f g variables {𝕜 E F G} @[simp] lemma compL_apply (f : F →L[𝕜] G) (g : E →L[𝕜] F) : compL 𝕜 E F G f g = f.comp g := rfl section multiplication_linear variables (𝕜) (𝕜' : Type*) [normed_ring 𝕜'] [normed_algebra 𝕜 𝕜'] /-- Left multiplication in a normed algebra as a linear isometry to the space of continuous linear maps. -/ def lmulₗᵢ : 𝕜' →ₗᵢ[𝕜] 𝕜' →L[𝕜] 𝕜' := { to_linear_map := (algebra.lmul 𝕜 𝕜').to_linear_map.mk_continuous₂ 1 $ λ x y, by simpa using norm_mul_le x y, norm_map' := λ x, le_antisymm (op_norm_le_bound _ (norm_nonneg x) (norm_mul_le x)) (by { convert ratio_le_op_norm _ (1 : 𝕜'), simp [normed_algebra.norm_one 𝕜 𝕜'] }) } /-- Left multiplication in a normed algebra as a continuous bilinear map. -/ def lmul : 𝕜' →L[𝕜] 𝕜' →L[𝕜] 𝕜' := (lmulₗᵢ 𝕜 𝕜').to_continuous_linear_map @[simp] lemma lmul_apply (x y : 𝕜') : lmul 𝕜 𝕜' x y = x * y := rfl @[simp] lemma coe_lmulₗᵢ : ⇑(lmulₗᵢ 𝕜 𝕜') = lmul 𝕜 𝕜' := rfl @[simp] lemma op_norm_lmul_apply (x : 𝕜') : ∥lmul 𝕜 𝕜' x∥ = ∥x∥ := (lmulₗᵢ 𝕜 𝕜').norm_map x /-- Right-multiplication in a normed algebra, considered as a continuous linear map. -/ def lmul_right : 𝕜' →L[𝕜] 𝕜' →L[𝕜] 𝕜' := (lmul 𝕜 𝕜').flip @[simp] lemma lmul_right_apply (x y : 𝕜') : lmul_right 𝕜 𝕜' x y = y * x := rfl @[simp] lemma op_norm_lmul_right_apply (x : 𝕜') : ∥lmul_right 𝕜 𝕜' x∥ = ∥x∥ := le_antisymm (op_norm_le_bound _ (norm_nonneg x) (λ y, (norm_mul_le y x).trans_eq (mul_comm _ _))) (by { convert ratio_le_op_norm _ (1 : 𝕜'), simp [normed_algebra.norm_one 𝕜 𝕜'] }) /-- Right-multiplication in a normed algebra, considered as a linear isometry to the space of continuous linear maps. -/ def lmul_rightₗᵢ : 𝕜' →ₗᵢ[𝕜] 𝕜' →L[𝕜] 𝕜' := { to_linear_map := lmul_right 𝕜 𝕜', norm_map' := op_norm_lmul_right_apply 𝕜 𝕜' } @[simp] lemma coe_lmul_rightₗᵢ : ⇑(lmul_rightₗᵢ 𝕜 𝕜') = lmul_right 𝕜 𝕜' := rfl /-- Simultaneous left- and right-multiplication in a normed algebra, considered as a continuous trilinear map. -/ def lmul_left_right : 𝕜' →L[𝕜] 𝕜' →L[𝕜] 𝕜' →L[𝕜] 𝕜' := ((compL 𝕜 𝕜' 𝕜' 𝕜').comp (lmul_right 𝕜 𝕜')).flip.comp (lmul 𝕜 𝕜') @[simp] lemma lmul_left_right_apply (x y z : 𝕜') : lmul_left_right 𝕜 𝕜' x y z = x * z * y := rfl lemma op_norm_lmul_left_right_apply_apply_le (x y : 𝕜') : ∥lmul_left_right 𝕜 𝕜' x y∥ ≤ ∥x∥ * ∥y∥ := (op_norm_comp_le _ _).trans_eq $ by simp [mul_comm] lemma op_norm_lmul_left_right_apply_le (x : 𝕜') : ∥lmul_left_right 𝕜 𝕜' x∥ ≤ ∥x∥ := op_norm_le_bound _ (norm_nonneg x) (op_norm_lmul_left_right_apply_apply_le 𝕜 𝕜' x) lemma op_norm_lmul_left_right_le : ∥lmul_left_right 𝕜 𝕜'∥ ≤ 1 := op_norm_le_bound _ zero_le_one (λ x, (one_mul ∥x∥).symm ▸ op_norm_lmul_left_right_apply_le 𝕜 𝕜' x) end multiplication_linear section smul_linear variables (𝕜) (𝕜' : Type*) [normed_field 𝕜'] [normed_algebra 𝕜 𝕜'] [semi_normed_space 𝕜' E] [is_scalar_tower 𝕜 𝕜' E] /-- Scalar multiplication as a continuous bilinear map. -/ def lsmul : 𝕜' →L[𝕜] E →L[𝕜] E := ((algebra.lsmul 𝕜 E).to_linear_map : 𝕜' →ₗ[𝕜] E →ₗ[𝕜] E).mk_continuous₂ 1 $ λ c x, by simpa only [one_mul] using (norm_smul c x).le @[simp] lemma lsmul_apply (c : 𝕜') (x : E) : lsmul 𝕜 𝕜' c x = c • x := rfl variables {𝕜'} lemma norm_to_span_singleton (x : E) : ∥to_span_singleton 𝕜 x∥ = ∥x∥ := begin refine op_norm_eq_of_bounds (norm_nonneg _) (λ x, _) (λ N hN_nonneg h, _), { rw [to_span_singleton_apply, norm_smul, mul_comm], }, { specialize h 1, rw [to_span_singleton_apply, norm_smul, mul_comm] at h, exact (mul_le_mul_right (by simp)).mp h, }, end end smul_linear section restrict_scalars variables {𝕜' : Type*} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜' 𝕜] variables [semi_normed_space 𝕜' E] [is_scalar_tower 𝕜' 𝕜 E] variables [semi_normed_space 𝕜' F] [is_scalar_tower 𝕜' 𝕜 F] @[simp] lemma norm_restrict_scalars (f : E →L[𝕜] F) : ∥f.restrict_scalars 𝕜'∥ = ∥f∥ := le_antisymm (op_norm_le_bound _ (norm_nonneg _) $ λ x, f.le_op_norm x) (op_norm_le_bound _ (norm_nonneg _) $ λ x, f.le_op_norm x) variables (𝕜 E F 𝕜') (𝕜'' : Type*) [ring 𝕜''] [topological_space 𝕜''] [module 𝕜'' F] [has_continuous_smul 𝕜'' F] [smul_comm_class 𝕜 𝕜'' F] [smul_comm_class 𝕜' 𝕜'' F] /-- `continuous_linear_map.restrict_scalars` as a `linear_isometry`. -/ def restrict_scalars_isometry : (E →L[𝕜] F) →ₗᵢ[𝕜''] (E →L[𝕜'] F) := ⟨restrict_scalarsₗ 𝕜 E F 𝕜' 𝕜'', norm_restrict_scalars⟩ variables {𝕜 E F 𝕜' 𝕜''} @[simp] lemma coe_restrict_scalars_isometry : ⇑(restrict_scalars_isometry 𝕜 E F 𝕜' 𝕜'') = restrict_scalars 𝕜' := rfl @[simp] lemma restrict_scalars_isometry_to_linear_map : (restrict_scalars_isometry 𝕜 E F 𝕜' 𝕜'').to_linear_map = restrict_scalarsₗ 𝕜 E F 𝕜' 𝕜'' := rfl variables (𝕜 E F 𝕜' 𝕜'') /-- `continuous_linear_map.restrict_scalars` as a `continuous_linear_map`. -/ def restrict_scalarsL : (E →L[𝕜] F) →L[𝕜''] (E →L[𝕜'] F) := (restrict_scalars_isometry 𝕜 E F 𝕜' 𝕜'').to_continuous_linear_map variables {𝕜 E F 𝕜' 𝕜''} @[simp] lemma coe_restrict_scalarsL : (restrict_scalarsL 𝕜 E F 𝕜' 𝕜'' : (E →L[𝕜] F) →ₗ[𝕜''] (E →L[𝕜'] F)) = restrict_scalarsₗ 𝕜 E F 𝕜' 𝕜'' := rfl @[simp] lemma coe_restrict_scalarsL' : ⇑(restrict_scalarsL 𝕜 E F 𝕜' 𝕜'') = restrict_scalars 𝕜' := rfl end restrict_scalars end continuous_linear_map namespace submodule lemma norm_subtypeL_le (K : submodule 𝕜 E) : ∥K.subtypeL∥ ≤ 1 := K.subtypeₗᵢ.norm_to_continuous_linear_map_le end submodule section has_sum -- Results in this section hold for continuous additive monoid homomorphisms or equivalences but we -- don't have bundled continuous additive homomorphisms. variables {ι R M M₂ : Type*} [semiring R] [add_comm_monoid M] [module R M] [add_comm_monoid M₂] [module R M₂] [topological_space M] [topological_space M₂] omit 𝕜 /-- Applying a continuous linear map commutes with taking an (infinite) sum. -/ protected lemma continuous_linear_map.has_sum {f : ι → M} (φ : M →L[R] M₂) {x : M} (hf : has_sum f x) : has_sum (λ (b:ι), φ (f b)) (φ x) := by simpa only using hf.map φ.to_linear_map.to_add_monoid_hom φ.continuous alias continuous_linear_map.has_sum ← has_sum.mapL protected lemma continuous_linear_map.summable {f : ι → M} (φ : M →L[R] M₂) (hf : summable f) : summable (λ b:ι, φ (f b)) := (hf.has_sum.mapL φ).summable alias continuous_linear_map.summable ← summable.mapL protected lemma continuous_linear_map.map_tsum [t2_space M₂] {f : ι → M} (φ : M →L[R] M₂) (hf : summable f) : φ (∑' z, f z) = ∑' z, φ (f z) := (hf.has_sum.mapL φ).tsum_eq.symm /-- Applying a continuous linear map commutes with taking an (infinite) sum. -/ protected lemma continuous_linear_equiv.has_sum {f : ι → M} (e : M ≃L[R] M₂) {y : M₂} : has_sum (λ (b:ι), e (f b)) y ↔ has_sum f (e.symm y) := ⟨λ h, by simpa only [e.symm.coe_coe, e.symm_apply_apply] using h.mapL (e.symm : M₂ →L[R] M), λ h, by simpa only [e.coe_coe, e.apply_symm_apply] using (e : M →L[R] M₂).has_sum h⟩ protected lemma continuous_linear_equiv.summable {f : ι → M} (e : M ≃L[R] M₂) : summable (λ b:ι, e (f b)) ↔ summable f := ⟨λ hf, (e.has_sum.1 hf.has_sum).summable, (e : M →L[R] M₂).summable⟩ lemma continuous_linear_equiv.tsum_eq_iff [t2_space M] [t2_space M₂] {f : ι → M} (e : M ≃L[R] M₂) {y : M₂} : ∑' z, e (f z) = y ↔ ∑' z, f z = e.symm y := begin by_cases hf : summable f, { exact ⟨λ h, (e.has_sum.mp ((e.summable.mpr hf).has_sum_iff.mpr h)).tsum_eq, λ h, (e.has_sum.mpr (hf.has_sum_iff.mpr h)).tsum_eq⟩ }, { have hf' : ¬summable (λ z, e (f z)) := λ h, hf (e.summable.mp h), rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hf'], exact ⟨by { rintro rfl, simp }, λ H, by simpa using (congr_arg (λ z, e z) H)⟩ } end protected lemma continuous_linear_equiv.map_tsum [t2_space M] [t2_space M₂] {f : ι → M} (e : M ≃L[R] M₂) : e (∑' z, f z) = ∑' z, e (f z) := by { refine symm (e.tsum_eq_iff.mpr _), rw e.symm_apply_apply _ } end has_sum namespace continuous_linear_equiv variables (e : E ≃L[𝕜] F) protected lemma lipschitz : lipschitz_with (∥(e : E →L[𝕜] F)∥₊) e := (e : E →L[𝕜] F).lipschitz theorem is_O_comp {α : Type*} (f : α → E) (l : filter α) : asymptotics.is_O (λ x', e (f x')) f l := (e : E →L[𝕜] F).is_O_comp f l theorem is_O_sub (l : filter E) (x : E) : asymptotics.is_O (λ x', e (x' - x)) (λ x', x' - x) l := (e : E →L[𝕜] F).is_O_sub l x theorem is_O_comp_rev {α : Type*} (f : α → E) (l : filter α) : asymptotics.is_O f (λ x', e (f x')) l := (e.symm.is_O_comp _ l).congr_left $ λ _, e.symm_apply_apply _ theorem is_O_sub_rev (l : filter E) (x : E) : asymptotics.is_O (λ x', x' - x) (λ x', e (x' - x)) l := e.is_O_comp_rev _ _ lemma homothety_inverse (a : ℝ) (ha : 0 < a) (f : E ≃ₗ[𝕜] F) : (∀ (x : E), ∥f x∥ = a * ∥x∥) → (∀ (y : F), ∥f.symm y∥ = a⁻¹ * ∥y∥) := begin intros hf y, calc ∥(f.symm) y∥ = a⁻¹ * (a * ∥ (f.symm) y∥) : _ ... = a⁻¹ * ∥f ((f.symm) y)∥ : by rw hf ... = a⁻¹ * ∥y∥ : by simp, rw [← mul_assoc, inv_mul_cancel (ne_of_lt ha).symm, one_mul], end /-- A linear equivalence which is a homothety is a continuous linear equivalence. -/ def of_homothety (f : E ≃ₗ[𝕜] F) (a : ℝ) (ha : 0 < a) (hf : ∀x, ∥f x∥ = a * ∥x∥) : E ≃L[𝕜] F := { to_linear_equiv := f, continuous_to_fun := f.to_linear_map.continuous_of_bound a (λ x, le_of_eq (hf x)), continuous_inv_fun := f.symm.to_linear_map.continuous_of_bound a⁻¹ (λ x, le_of_eq (homothety_inverse a ha f hf x)) } variable (𝕜) lemma to_span_nonzero_singleton_homothety (x : E) (h : x ≠ 0) (c : 𝕜) : ∥linear_equiv.to_span_nonzero_singleton 𝕜 E x h c∥ = ∥x∥ * ∥c∥ := continuous_linear_map.to_span_singleton_homothety _ _ _ end continuous_linear_equiv /-- Construct a continuous linear equivalence from a linear equivalence together with bounds in both directions. -/ def linear_equiv.to_continuous_linear_equiv_of_bounds (e : E ≃ₗ[𝕜] F) (C_to C_inv : ℝ) (h_to : ∀ x, ∥e x∥ ≤ C_to * ∥x∥) (h_inv : ∀ x : F, ∥e.symm x∥ ≤ C_inv * ∥x∥) : E ≃L[𝕜] F := { to_linear_equiv := e, continuous_to_fun := e.to_linear_map.continuous_of_bound C_to h_to, continuous_inv_fun := e.symm.to_linear_map.continuous_of_bound C_inv h_inv } namespace continuous_linear_map variables (𝕜) (𝕜' : Type*) [normed_ring 𝕜'] [normed_algebra 𝕜 𝕜'] variables {𝕜} variables {E' F' : Type*} [semi_normed_group E'] [semi_normed_group F'] [semi_normed_space 𝕜 E'] [semi_normed_space 𝕜 F'] /-- Compose a bilinear map `E →L[𝕜] F →L[𝕜] G` with two linear maps `E' →L[𝕜] E` and `F' →L[𝕜] F`. -/ def bilinear_comp (f : E →L[𝕜] F →L[𝕜] G) (gE : E' →L[𝕜] E) (gF : F' →L[𝕜] F) : E' →L[𝕜] F' →L[𝕜] G := ((f.comp gE).flip.comp gF).flip @[simp] lemma bilinear_comp_apply (f : E →L[𝕜] F →L[𝕜] G) (gE : E' →L[𝕜] E) (gF : F' →L[𝕜] F) (x : E') (y : F') : f.bilinear_comp gE gF x y = f (gE x) (gF y) := rfl /-- Derivative of a continuous bilinear map `f : E →L[𝕜] F →L[𝕜] G` interpreted as a map `E × F → G` at point `p : E × F` evaluated at `q : E × F`, as a continuous bilinear map. -/ def deriv₂ (f : E →L[𝕜] F →L[𝕜] G) : (E × F) →L[𝕜] (E × F) →L[𝕜] G := f.bilinear_comp (fst _ _ _) (snd _ _ _) + f.flip.bilinear_comp (snd _ _ _) (fst _ _ _) @[simp] lemma coe_deriv₂ (f : E →L[𝕜] F →L[𝕜] G) (p : E × F) : ⇑(f.deriv₂ p) = λ q : E × F, f p.1 q.2 + f q.1 p.2 := rfl lemma map_add₂ (f : E →L[𝕜] F →L[𝕜] G) (x x' : E) (y y' : F) : f (x + x') (y + y') = f x y + f.deriv₂ (x, y) (x', y') + f x' y' := by simp only [map_add, add_apply, coe_deriv₂, add_assoc] end continuous_linear_map end semi_normed section normed variables [normed_group E] [normed_group F] [normed_group G] open metric continuous_linear_map section normed_field variables [normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F] (f : E →ₗ[𝕜] F) lemma linear_map.continuous_iff_is_closed_ker {f : E →ₗ[𝕜] 𝕜} : continuous f ↔ is_closed (f.ker : set E) := begin -- the continuity of f obviously implies that its kernel is closed refine ⟨λh, (t1_space.t1 (0 : 𝕜)).preimage h, λh, _⟩, -- for the other direction, we assume that the kernel is closed by_cases hf : ∀x, x ∈ f.ker, { -- if `f = 0`, its continuity is obvious have : (f : E → 𝕜) = (λx, 0), by { ext x, simpa using hf x }, rw this, exact continuous_const }, { /- if `f` is not zero, we use an element `x₀ ∉ ker f` such that `∥x₀∥ ≤ 2 ∥x₀ - y∥` for all `y ∈ ker f`, given by Riesz's lemma, and prove that `2 ∥f x₀∥ / ∥x₀∥` gives a bound on the operator norm of `f`. For this, start from an arbitrary `x` and note that `y = x₀ - (f x₀ / f x) x` belongs to the kernel of `f`. Applying the above inequality to `x₀` and `y` readily gives the conclusion. -/ push_neg at hf, let r : ℝ := (2 : ℝ)⁻¹, have : 0 ≤ r, by norm_num [r], have : r < 1, by norm_num [r], obtain ⟨x₀, x₀ker, h₀⟩ : ∃ (x₀ : E), x₀ ∉ f.ker ∧ ∀ y ∈ linear_map.ker f, r * ∥x₀∥ ≤ ∥x₀ - y∥, from riesz_lemma h hf this, have : x₀ ≠ 0, { assume h, have : x₀ ∈ f.ker, by { rw h, exact (linear_map.ker f).zero_mem }, exact x₀ker this }, have rx₀_ne_zero : r * ∥x₀∥ ≠ 0, by { simp [norm_eq_zero, this], }, have : ∀x, ∥f x∥ ≤ (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥, { assume x, by_cases hx : f x = 0, { rw [hx, norm_zero], apply_rules [mul_nonneg, norm_nonneg, inv_nonneg.2] }, { let y := x₀ - (f x₀ * (f x)⁻¹ ) • x, have fy_zero : f y = 0, by calc f y = f x₀ - (f x₀ * (f x)⁻¹ ) * f x : by simp [y] ... = 0 : by { rw [mul_assoc, inv_mul_cancel hx, mul_one, sub_eq_zero_of_eq], refl }, have A : r * ∥x₀∥ ≤ ∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥, from calc r * ∥x₀∥ ≤ ∥x₀ - y∥ : h₀ _ (linear_map.mem_ker.2 fy_zero) ... = ∥(f x₀ * (f x)⁻¹ ) • x∥ : by { dsimp [y], congr, abel } ... = ∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥ : by rw [norm_smul, normed_field.norm_mul, normed_field.norm_inv], calc ∥f x∥ = (r * ∥x₀∥)⁻¹ * (r * ∥x₀∥) * ∥f x∥ : by rwa [inv_mul_cancel, one_mul] ... ≤ (r * ∥x₀∥)⁻¹ * (∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥) * ∥f x∥ : begin apply mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left A _) (norm_nonneg _), exact inv_nonneg.2 (mul_nonneg (by norm_num) (norm_nonneg _)) end ... = (∥f x∥ ⁻¹ * ∥f x∥) * (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥ : by ring ... = (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥ : by { rw [inv_mul_cancel, one_mul], simp [norm_eq_zero, hx] } } }, exact linear_map.continuous_of_bound f _ this } end end normed_field variables [nondiscrete_normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F] [normed_space 𝕜 G] (c : 𝕜) (f g : E →L[𝕜] F) (h : F →L[𝕜] G) (x y z : E) include 𝕜 lemma linear_map.bound_of_shell (f : E →ₗ[𝕜] F) {ε C : ℝ} (ε_pos : 0 < ε) {c : 𝕜} (hc : 1 < ∥c∥) (hf : ∀ x, ε / ∥c∥ ≤ ∥x∥ → ∥x∥ < ε → ∥f x∥ ≤ C * ∥x∥) (x : E) : ∥f x∥ ≤ C * ∥x∥ := begin by_cases hx : x = 0, { simp [hx] }, exact linear_map.bound_of_shell_semi_normed f ε_pos hc hf (ne_of_lt (norm_pos_iff.2 hx)).symm end namespace continuous_linear_map section op_norm open set real /-- An operator is zero iff its norm vanishes. -/ theorem op_norm_zero_iff : ∥f∥ = 0 ↔ f = 0 := iff.intro (λ hn, continuous_linear_map.ext (λ x, norm_le_zero_iff.1 (calc _ ≤ ∥f∥ * ∥x∥ : le_op_norm _ _ ... = _ : by rw [hn, zero_mul]))) (λ hf, le_antisymm (cInf_le bounds_bdd_below ⟨le_rfl, λ _, le_of_eq (by { rw [zero_mul, hf], exact norm_zero })⟩) (op_norm_nonneg _)) /-- If a normed space is non-trivial, then the norm of the identity equals `1`. -/ @[simp] lemma norm_id [nontrivial E] : ∥id 𝕜 E∥ = 1 := begin refine norm_id_of_nontrivial_seminorm _, obtain ⟨x, hx⟩ := exists_ne (0 : E), exact ⟨x, ne_of_gt (norm_pos_iff.2 hx)⟩, end instance norm_one_class [nontrivial E] : norm_one_class (E →L[𝕜] E) := ⟨norm_id⟩ /-- Continuous linear maps themselves form a normed space with respect to the operator norm. -/ instance to_normed_group : normed_group (E →L[𝕜] F) := normed_group.of_core _ ⟨op_norm_zero_iff, op_norm_add_le, op_norm_neg⟩ instance to_normed_space {𝕜' : Type*} [normed_field 𝕜'] [normed_space 𝕜' F] [smul_comm_class 𝕜 𝕜' F] : normed_space 𝕜' (E →L[𝕜] F) := ⟨op_norm_smul_le⟩ /-- Continuous linear maps form a normed ring with respect to the operator norm. -/ instance to_normed_ring : normed_ring (E →L[𝕜] E) := { norm_mul := op_norm_comp_le, .. continuous_linear_map.to_normed_group } /-- For a nonzero normed space `E`, continuous linear endomorphisms form a normed algebra with respect to the operator norm. -/ instance to_normed_algebra [nontrivial E] : normed_algebra 𝕜 (E →L[𝕜] E) := { norm_algebra_map_eq := λ c, show ∥c • id 𝕜 E∥ = ∥c∥, by {rw [norm_smul, norm_id], simp}, .. continuous_linear_map.algebra } variable {f} lemma homothety_norm [nontrivial E] (f : E →L[𝕜] F) {a : ℝ} (hf : ∀x, ∥f x∥ = a * ∥x∥) : ∥f∥ = a := begin obtain ⟨x, hx⟩ : ∃ (x : E), x ≠ 0 := exists_ne 0, rw ← norm_pos_iff at hx, have ha : 0 ≤ a, by simpa only [hf, hx, zero_le_mul_right] using norm_nonneg (f x), apply le_antisymm (f.op_norm_le_bound ha (λ y, le_of_eq (hf y))), simpa only [hf, hx, mul_le_mul_right] using f.le_op_norm x, end lemma to_span_singleton_norm (x : E) : ∥to_span_singleton 𝕜 x∥ = ∥x∥ := homothety_norm _ (to_span_singleton_homothety 𝕜 x) variable (f) theorem uniform_embedding_of_bound {K : ℝ≥0} (hf : ∀ x, ∥x∥ ≤ K * ∥f x∥) : uniform_embedding f := (f.to_linear_map.antilipschitz_of_bound hf).uniform_embedding f.uniform_continuous /-- If a continuous linear map is a uniform embedding, then it is expands the distances by a positive factor.-/ theorem antilipschitz_of_uniform_embedding (hf : uniform_embedding f) : ∃ K, antilipschitz_with K f := begin obtain ⟨ε, εpos, hε⟩ : ∃ (ε : ℝ) (H : ε > 0), ∀ {x y : E}, dist (f x) (f y) < ε → dist x y < 1, from (uniform_embedding_iff.1 hf).2.2 1 zero_lt_one, let δ := ε/2, have δ_pos : δ > 0 := half_pos εpos, have H : ∀{x}, ∥f x∥ ≤ δ → ∥x∥ ≤ 1, { assume x hx, have : dist x 0 ≤ 1, { refine (hε _).le, rw [f.map_zero, dist_zero_right], exact hx.trans_lt (half_lt_self εpos) }, simpa using this }, rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩, refine ⟨⟨δ⁻¹, _⟩ * nnnorm c, f.to_linear_map.antilipschitz_of_bound $ λx, _⟩, exact inv_nonneg.2 (le_of_lt δ_pos), by_cases hx : f x = 0, { have : f x = f 0, by { simp [hx] }, have : x = 0 := (uniform_embedding_iff.1 hf).1 this, simp [this] }, { rcases rescale_to_shell hc δ_pos hx with ⟨d, hd, dxlt, ledx, dinv⟩, rw [← f.map_smul d] at dxlt, have : ∥d • x∥ ≤ 1 := H dxlt.le, calc ∥x∥ = ∥d∥⁻¹ * ∥d • x∥ : by rwa [← normed_field.norm_inv, ← norm_smul, ← mul_smul, inv_mul_cancel, one_smul] ... ≤ ∥d∥⁻¹ * 1 : mul_le_mul_of_nonneg_left this (inv_nonneg.2 (norm_nonneg _)) ... ≤ δ⁻¹ * ∥c∥ * ∥f x∥ : by rwa [mul_one] } end section completeness open_locale topological_space open filter /-- If the target space is complete, the space of continuous linear maps with its norm is also complete. This works also if the source space is seminormed. -/ instance {E : Type*} [semi_normed_group E] [semi_normed_space 𝕜 E] [complete_space F] : complete_space (E →L[𝕜] F) := begin -- We show that every Cauchy sequence converges. refine metric.complete_of_cauchy_seq_tendsto (λ f hf, _), -- We now expand out the definition of a Cauchy sequence, rcases cauchy_seq_iff_le_tendsto_0.1 hf with ⟨b, b0, b_bound, b_lim⟩, clear hf, -- and establish that the evaluation at any point `v : E` is Cauchy. have cau : ∀ v, cauchy_seq (λ n, f n v), { assume v, apply cauchy_seq_iff_le_tendsto_0.2 ⟨λ n, b n * ∥v∥, λ n, _, _, _⟩, { exact mul_nonneg (b0 n) (norm_nonneg _) }, { assume n m N hn hm, rw dist_eq_norm, apply le_trans ((f n - f m).le_op_norm v) _, exact mul_le_mul_of_nonneg_right (b_bound n m N hn hm) (norm_nonneg v) }, { simpa using b_lim.mul tendsto_const_nhds } }, -- We assemble the limits points of those Cauchy sequences -- (which exist as `F` is complete) -- into a function which we call `G`. choose G hG using λv, cauchy_seq_tendsto_of_complete (cau v), -- Next, we show that this `G` is linear, let Glin : E →ₗ[𝕜] F := { to_fun := G, map_add' := λ v w, begin have A := hG (v + w), have B := (hG v).add (hG w), simp only [map_add] at A B, exact tendsto_nhds_unique A B, end, map_smul' := λ c v, begin have A := hG (c • v), have B := filter.tendsto.smul (@tendsto_const_nhds _ ℕ _ c _) (hG v), simp only [map_smul] at A B, exact tendsto_nhds_unique A B end }, -- and that `G` has norm at most `(b 0 + ∥f 0∥)`. have Gnorm : ∀ v, ∥G v∥ ≤ (b 0 + ∥f 0∥) * ∥v∥, { assume v, have A : ∀ n, ∥f n v∥ ≤ (b 0 + ∥f 0∥) * ∥v∥, { assume n, apply le_trans ((f n).le_op_norm _) _, apply mul_le_mul_of_nonneg_right _ (norm_nonneg v), calc ∥f n∥ = ∥(f n - f 0) + f 0∥ : by { congr' 1, abel } ... ≤ ∥f n - f 0∥ + ∥f 0∥ : norm_add_le _ _ ... ≤ b 0 + ∥f 0∥ : begin apply add_le_add_right, simpa [dist_eq_norm] using b_bound n 0 0 (zero_le _) (zero_le _) end }, exact le_of_tendsto (hG v).norm (eventually_of_forall A) }, -- Thus `G` is continuous, and we propose that as the limit point of our original Cauchy sequence. let Gcont := Glin.mk_continuous _ Gnorm, use Gcont, -- Our last task is to establish convergence to `G` in norm. have : ∀ n, ∥f n - Gcont∥ ≤ b n, { assume n, apply op_norm_le_bound _ (b0 n) (λ v, _), have A : ∀ᶠ m in at_top, ∥(f n - f m) v∥ ≤ b n * ∥v∥, { refine eventually_at_top.2 ⟨n, λ m hm, _⟩, apply le_trans ((f n - f m).le_op_norm _) _, exact mul_le_mul_of_nonneg_right (b_bound n m n (le_refl _) hm) (norm_nonneg v) }, have B : tendsto (λ m, ∥(f n - f m) v∥) at_top (𝓝 (∥(f n - Gcont) v∥)) := tendsto.norm (tendsto_const_nhds.sub (hG v)), exact le_of_tendsto B A }, erw tendsto_iff_norm_tendsto_zero, exact squeeze_zero (λ n, norm_nonneg _) this b_lim, end end completeness section uniformly_extend variables [complete_space F] (e : E →L[𝕜] G) (h_dense : dense_range e) section variables (h_e : uniform_inducing e) /-- Extension of a continuous linear map `f : E →L[𝕜] F`, with `E` a normed space and `F` a complete normed space, along a uniform and dense embedding `e : E →L[𝕜] G`. -/ def extend : G →L[𝕜] F := /- extension of `f` is continuous -/ have cont : _ := (uniform_continuous_uniformly_extend h_e h_dense f.uniform_continuous).continuous, /- extension of `f` agrees with `f` on the domain of the embedding `e` -/ have eq : _ := uniformly_extend_of_ind h_e h_dense f.uniform_continuous, { to_fun := (h_e.dense_inducing h_dense).extend f, map_add' := begin refine h_dense.induction_on₂ _ _, { exact is_closed_eq (cont.comp continuous_add) ((cont.comp continuous_fst).add (cont.comp continuous_snd)) }, { assume x y, simp only [eq, ← e.map_add], exact f.map_add _ _ }, end, map_smul' := λk, begin refine (λ b, h_dense.induction_on b _ _), { exact is_closed_eq (cont.comp (continuous_const.smul continuous_id)) ((continuous_const.smul continuous_id).comp cont) }, { assume x, rw ← map_smul, simp only [eq], exact map_smul _ _ _ }, end, cont := cont } lemma extend_unique (g : G →L[𝕜] F) (H : g.comp e = f) : extend f e h_dense h_e = g := continuous_linear_map.coe_fn_injective $ uniformly_extend_unique h_e h_dense (continuous_linear_map.ext_iff.1 H) g.continuous @[simp] lemma extend_zero : extend (0 : E →L[𝕜] F) e h_dense h_e = 0 := extend_unique _ _ _ _ _ (zero_comp _) end section variables {N : ℝ≥0} (h_e : ∀x, ∥x∥ ≤ N * ∥e x∥) local notation `ψ` := f.extend e h_dense (uniform_embedding_of_bound _ h_e).to_uniform_inducing /-- If a dense embedding `e : E →L[𝕜] G` expands the norm by a constant factor `N⁻¹`, then the norm of the extension of `f` along `e` is bounded by `N * ∥f∥`. -/ lemma op_norm_extend_le : ∥ψ∥ ≤ N * ∥f∥ := begin have uni : uniform_inducing e := (uniform_embedding_of_bound _ h_e).to_uniform_inducing, have eq : ∀x, ψ (e x) = f x := uniformly_extend_of_ind uni h_dense f.uniform_continuous, by_cases N0 : 0 ≤ N, { refine op_norm_le_bound ψ _ (is_closed_property h_dense (is_closed_le _ _) _), { exact mul_nonneg N0 (norm_nonneg _) }, { exact continuous_norm.comp (cont ψ) }, { exact continuous_const.mul continuous_norm }, { assume x, rw eq, calc ∥f x∥ ≤ ∥f∥ * ∥x∥ : le_op_norm _ _ ... ≤ ∥f∥ * (N * ∥e x∥) : mul_le_mul_of_nonneg_left (h_e x) (norm_nonneg _) ... ≤ N * ∥f∥ * ∥e x∥ : by rw [mul_comm ↑N ∥f∥, mul_assoc] } }, { have he : ∀ x : E, x = 0, { assume x, have N0 : N ≤ 0 := le_of_lt (lt_of_not_ge N0), rw ← norm_le_zero_iff, exact le_trans (h_e x) (mul_nonpos_of_nonpos_of_nonneg N0 (norm_nonneg _)) }, have hf : f = 0, { ext, simp only [he x, zero_apply, map_zero] }, have hψ : ψ = 0, { rw hf, apply extend_zero }, rw [hψ, hf, norm_zero, norm_zero, mul_zero] } end end end uniformly_extend end op_norm end continuous_linear_map namespace linear_isometry @[simp] lemma norm_to_continuous_linear_map [nontrivial E] (f : E →ₗᵢ[𝕜] F) : ∥f.to_continuous_linear_map∥ = 1 := f.to_continuous_linear_map.homothety_norm $ by simp end linear_isometry namespace continuous_linear_map /-- Precomposition with a linear isometry preserves the operator norm. -/ lemma op_norm_comp_linear_isometry_equiv {G : Type*} [semi_normed_group G] [semi_normed_space 𝕜 G] (f : F →L[𝕜] G) (g : E ≃ₗᵢ[𝕜] F) : ∥f.comp g.to_linear_isometry.to_continuous_linear_map∥ = ∥f∥ := begin casesI subsingleton_or_nontrivial E, { haveI := g.symm.to_linear_equiv.to_equiv.subsingleton, simp }, refine le_antisymm _ _, { convert f.op_norm_comp_le g.to_linear_isometry.to_continuous_linear_map, simp [g.to_linear_isometry.norm_to_continuous_linear_map] }, { convert (f.comp g.to_linear_isometry.to_continuous_linear_map).op_norm_comp_le g.symm.to_linear_isometry.to_continuous_linear_map, { ext, simp }, haveI := g.symm.to_linear_equiv.to_equiv.nontrivial, simp [g.symm.to_linear_isometry.norm_to_continuous_linear_map] }, end /-- The norm of the tensor product of a scalar linear map and of an element of a normed space is the product of the norms. -/ @[simp] lemma norm_smul_right_apply (c : E →L[𝕜] 𝕜) (f : F) : ∥smul_right c f∥ = ∥c∥ * ∥f∥ := begin refine le_antisymm _ _, { apply op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) (λx, _), calc ∥(c x) • f∥ = ∥c x∥ * ∥f∥ : norm_smul _ _ ... ≤ (∥c∥ * ∥x∥) * ∥f∥ : mul_le_mul_of_nonneg_right (le_op_norm _ _) (norm_nonneg _) ... = ∥c∥ * ∥f∥ * ∥x∥ : by ring }, { by_cases h : f = 0, { simp [h] }, { have : 0 < ∥f∥ := norm_pos_iff.2 h, rw ← le_div_iff this, apply op_norm_le_bound _ (div_nonneg (norm_nonneg _) (norm_nonneg f)) (λx, _), rw [div_mul_eq_mul_div, le_div_iff this], calc ∥c x∥ * ∥f∥ = ∥c x • f∥ : (norm_smul _ _).symm ... = ∥smul_right c f x∥ : rfl ... ≤ ∥smul_right c f∥ * ∥x∥ : le_op_norm _ _ } }, end /-- The non-negative norm of the tensor product of a scalar linear map and of an element of a normed space is the product of the non-negative norms. -/ @[simp] lemma nnnorm_smul_right_apply (c : E →L[𝕜] 𝕜) (f : F) : ∥smul_right c f∥₊ = ∥c∥₊ * ∥f∥₊ := nnreal.eq $ c.norm_smul_right_apply f variables (𝕜 E F) /-- `continuous_linear_map.smul_right` as a continuous trilinear map: `smul_rightL (c : E →L[𝕜] 𝕜) (f : F) (x : E) = c x • f`. -/ def smul_rightL : (E →L[𝕜] 𝕜) →L[𝕜] F →L[𝕜] E →L[𝕜] F := linear_map.mk_continuous₂ { to_fun := smul_rightₗ, map_add' := λ c₁ c₂, by { ext x, simp [add_smul] }, map_smul' := λ m c, by { ext x, simp [smul_smul] } } 1 $ λ c x, by simp variables {𝕜 E F} @[simp] lemma norm_smul_rightL_apply (c : E →L[𝕜] 𝕜) (f : F) : ∥smul_rightL 𝕜 E F c f∥ = ∥c∥ * ∥f∥ := norm_smul_right_apply c f @[simp] lemma norm_smul_rightL (c : E →L[𝕜] 𝕜) [nontrivial F] : ∥smul_rightL 𝕜 E F c∥ = ∥c∥ := continuous_linear_map.homothety_norm _ c.norm_smul_right_apply variables (𝕜) (𝕜' : Type*) [normed_ring 𝕜'] [normed_algebra 𝕜 𝕜'] @[simp] lemma op_norm_lmul : ∥lmul 𝕜 𝕜'∥ = 1 := by haveI := normed_algebra.nontrivial 𝕜 𝕜'; exact (lmulₗᵢ 𝕜 𝕜').norm_to_continuous_linear_map @[simp] lemma op_norm_lmul_right : ∥lmul_right 𝕜 𝕜'∥ = 1 := (op_norm_flip (@lmul 𝕜 _ 𝕜' _ _)).trans (op_norm_lmul _ _) end continuous_linear_map namespace submodule lemma norm_subtypeL (K : submodule 𝕜 E) [nontrivial K] : ∥K.subtypeL∥ = 1 := K.subtypeₗᵢ.norm_to_continuous_linear_map end submodule namespace continuous_linear_equiv variables (e : E ≃L[𝕜] F) protected lemma antilipschitz : antilipschitz_with (nnnorm (e.symm : F →L[𝕜] E)) e := e.symm.lipschitz.to_right_inverse e.left_inv /-- A continuous linear equiv is a uniform embedding. -/ lemma uniform_embedding : uniform_embedding e := e.antilipschitz.uniform_embedding e.lipschitz.uniform_continuous lemma one_le_norm_mul_norm_symm [nontrivial E] : 1 ≤ ∥(e : E →L[𝕜] F)∥ * ∥(e.symm : F →L[𝕜] E)∥ := begin rw [mul_comm], convert (e.symm : F →L[𝕜] E).op_norm_comp_le (e : E →L[𝕜] F), rw [e.coe_symm_comp_coe, continuous_linear_map.norm_id] end lemma norm_pos [nontrivial E] : 0 < ∥(e : E →L[𝕜] F)∥ := pos_of_mul_pos_right (lt_of_lt_of_le zero_lt_one e.one_le_norm_mul_norm_symm) (norm_nonneg _) lemma norm_symm_pos [nontrivial E] : 0 < ∥(e.symm : F →L[𝕜] E)∥ := pos_of_mul_pos_left (lt_of_lt_of_le zero_lt_one e.one_le_norm_mul_norm_symm) (norm_nonneg _) lemma nnnorm_symm_pos [nontrivial E] : 0 < nnnorm (e.symm : F →L[𝕜] E) := e.norm_symm_pos lemma subsingleton_or_norm_symm_pos : subsingleton E ∨ 0 < ∥(e.symm : F →L[𝕜] E)∥ := begin rcases subsingleton_or_nontrivial E with _i|_i; resetI, { left, apply_instance }, { right, exact e.norm_symm_pos } end lemma subsingleton_or_nnnorm_symm_pos : subsingleton E ∨ 0 < (nnnorm $ (e.symm : F →L[𝕜] E)) := subsingleton_or_norm_symm_pos e variable (𝕜) /-- Given a nonzero element `x` of a normed space `E₁` over a field `𝕜`, the natural continuous linear equivalence from `E₁` to the span of `x`.-/ def to_span_nonzero_singleton (x : E) (h : x ≠ 0) : 𝕜 ≃L[𝕜] (𝕜 ∙ x) := of_homothety (linear_equiv.to_span_nonzero_singleton 𝕜 E x h) ∥x∥ (norm_pos_iff.mpr h) (to_span_nonzero_singleton_homothety 𝕜 x h) /-- Given a nonzero element `x` of a normed space `E₁` over a field `𝕜`, the natural continuous linear map from the span of `x` to `𝕜`.-/ def coord (x : E) (h : x ≠ 0) : (𝕜 ∙ x) →L[𝕜] 𝕜 := (to_span_nonzero_singleton 𝕜 x h).symm @[simp] lemma coe_to_span_nonzero_singleton_symm {x : E} (h : x ≠ 0) : ⇑(to_span_nonzero_singleton 𝕜 x h).symm = coord 𝕜 x h := rfl @[simp] lemma coord_to_span_nonzero_singleton {x : E} (h : x ≠ 0) (c : 𝕜) : coord 𝕜 x h (to_span_nonzero_singleton 𝕜 x h c) = c := (to_span_nonzero_singleton 𝕜 x h).symm_apply_apply c @[simp] lemma to_span_nonzero_singleton_coord {x : E} (h : x ≠ 0) (y : 𝕜 ∙ x) : to_span_nonzero_singleton 𝕜 x h (coord 𝕜 x h y) = y := (to_span_nonzero_singleton 𝕜 x h).apply_symm_apply y @[simp] lemma coord_norm (x : E) (h : x ≠ 0) : ∥coord 𝕜 x h∥ = ∥x∥⁻¹ := begin have hx : 0 < ∥x∥ := (norm_pos_iff.mpr h), haveI : nontrivial (𝕜 ∙ x) := submodule.nontrivial_span_singleton h, exact continuous_linear_map.homothety_norm _ (λ y, homothety_inverse _ hx _ (to_span_nonzero_singleton_homothety 𝕜 x h) _) end @[simp] lemma coord_self (x : E) (h : x ≠ 0) : (coord 𝕜 x h) (⟨x, submodule.mem_span_singleton_self x⟩ : 𝕜 ∙ x) = 1 := linear_equiv.coord_self 𝕜 E x h end continuous_linear_equiv lemma linear_equiv.uniform_embedding (e : E ≃ₗ[𝕜] F) (h₁ : continuous e) (h₂ : continuous e.symm) : uniform_embedding e := continuous_linear_equiv.uniform_embedding { continuous_to_fun := h₁, continuous_inv_fun := h₂, .. e } end normed
c3fb2cf7137bff03a9d3b864413ff2bb92bf98be
69d4931b605e11ca61881fc4f66db50a0a875e39
/src/algebra/ring/pi.lean
6f44f77929b46597f38f7ea38f2e62f36baefce4
[ "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
2,889
lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Patrick Massot -/ import tactic.pi_instances import algebra.group.pi import algebra.ring.basic /-! # Pi instances for ring This file defines instances for ring, semiring and related structures on Pi Types -/ namespace pi universes u v w variable {I : Type u} -- The indexing type variable {f : I → Type v} -- The family of types already equipped with instances variables (x y : Π i, f i) (i : I) instance distrib [Π i, distrib $ f i] : distrib (Π i : I, f i) := by refine_struct { add := (+), mul := (*), .. }; tactic.pi_instance_derive_field instance semiring [∀ i, semiring $ f i] : semiring (Π i : I, f i) := by refine_struct { zero := (0 : Π i, f i), one := 1, add := (+), mul := (*), nsmul := λ n x i, nsmul n (x i), npow := λ n x i, npow n (x i) }; tactic.pi_instance_derive_field instance comm_semiring [∀ i, comm_semiring $ f i] : comm_semiring (Π i : I, f i) := by refine_struct { zero := (0 : Π i, f i), one := 1, add := (+), mul := (*), nsmul := λ n x i, nsmul n (x i), npow := λ n x i, npow n (x i) }; tactic.pi_instance_derive_field instance ring [∀ i, ring $ f i] : ring (Π i : I, f i) := by refine_struct { zero := (0 : Π i, f i), one := 1, add := (+), mul := (*), neg := has_neg.neg, nsmul := λ n x i, nsmul n (x i), npow := λ n x i, npow n (x i) }; tactic.pi_instance_derive_field instance comm_ring [∀ i, comm_ring $ f i] : comm_ring (Π i : I, f i) := by refine_struct { zero := (0 : Π i, f i), one := 1, add := (+), mul := (*), neg := has_neg.neg, nsmul := λ n x i, nsmul n (x i), npow := λ n x i, npow n (x i) }; tactic.pi_instance_derive_field /-- A family of ring homomorphisms `f a : γ →+* β a` defines a ring homomorphism `pi.ring_hom f : γ →+* Π a, β a` given by `pi.ring_hom f x b = f b x`. -/ protected def ring_hom {α : Type u} {β : α → Type v} [R : Π a : α, semiring (β a)] {γ : Type w} [semiring γ] (f : Π a : α, γ →+* β a) : γ →+* Π a, β a := { to_fun := λ x b, f b x, map_add' := λ x y, funext $ λ z, (f z).map_add x y, map_mul' := λ x y, funext $ λ z, (f z).map_mul x y, map_one' := funext $ λ z, (f z).map_one, map_zero' := funext $ λ z, (f z).map_zero } @[simp] lemma ring_hom_apply {α : Type u} {β : α → Type v} [R : Π a : α, semiring (β a)] {γ : Type w} [semiring γ] (f : Π a : α, γ →+* β a) (g) (a) : pi.ring_hom f g a = f a g := rfl section ring_hom variables [Π i, semiring (f i)] (f) /-- Evaluation of functions into an indexed collection of monoids at a point is a monoid homomorphism. This is `function.eval` as a `ring_hom`. -/ @[simps] def eval_ring_hom (i : I) : (Π i, f i) →+* f i := { ..(eval_monoid_hom f i), ..(eval_add_monoid_hom f i) } end ring_hom end pi
a8887b9484e79fb91f3fd4fab3583361adbd2e23
35677d2df3f081738fa6b08138e03ee36bc33cad
/src/data/fintype/basic.lean
3caac8b00f07d84809f297b8c4a1b642267cb77f
[ "Apache-2.0" ]
permissive
gebner/mathlib
eab0150cc4f79ec45d2016a8c21750244a2e7ff0
cc6a6edc397c55118df62831e23bfbd6e6c6b4ab
refs/heads/master
1,625,574,853,976
1,586,712,827,000
1,586,712,827,000
99,101,412
1
0
Apache-2.0
1,586,716,389,000
1,501,667,958,000
Lean
UTF-8
Lean
false
false
39,398
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro Finite types. -/ import data.finset data.array.lemmas logic.unique import tactic.wlog universes u v variables {α : Type*} {β : Type*} {γ : Type*} /-- `fintype α` means that `α` is finite, i.e. there are only finitely many distinct elements of type `α`. The evidence of this is a finset `elems` (a list up to permutation without duplicates), together with a proof that everything of type `α` is in the list. -/ class fintype (α : Type*) := (elems [] : finset α) (complete : ∀ x : α, x ∈ elems) namespace finset variable [fintype α] /-- `univ` is the universal finite set of type `finset α` implied from the assumption `fintype α`. -/ def univ : finset α := fintype.elems α @[simp] theorem mem_univ (x : α) : x ∈ (univ : finset α) := fintype.complete x @[simp] theorem mem_univ_val : ∀ x, x ∈ (univ : finset α).1 := mem_univ @[simp] lemma coe_univ : ↑(univ : finset α) = (set.univ : set α) := by ext; simp theorem subset_univ (s : finset α) : s ⊆ univ := λ a _, mem_univ a theorem eq_univ_iff_forall {s : finset α} : s = univ ↔ ∀ x, x ∈ s := by simp [ext] @[simp] lemma piecewise_univ [∀i : α, decidable (i ∈ (univ : finset α))] {δ : α → Sort*} (f g : Πi, δ i) : univ.piecewise f g = f := by { ext i, simp [piecewise] } end finset open finset function namespace fintype instance decidable_pi_fintype {α} {β : α → Type*} [∀a, decidable_eq (β a)] [fintype α] : decidable_eq (Πa, β a) := assume f g, decidable_of_iff (∀ a ∈ fintype.elems α, f a = g a) (by simp [function.funext_iff, fintype.complete]) instance decidable_forall_fintype {p : α → Prop} [decidable_pred p] [fintype α] : decidable (∀ a, p a) := decidable_of_iff (∀ a ∈ @univ α _, p a) (by simp) instance decidable_exists_fintype {p : α → Prop} [decidable_pred p] [fintype α] : decidable (∃ a, p a) := decidable_of_iff (∃ a ∈ @univ α _, p a) (by simp) instance decidable_eq_equiv_fintype [decidable_eq β] [fintype α] : decidable_eq (α ≃ β) := λ a b, decidable_of_iff (a.1 = b.1) ⟨λ h, equiv.ext _ _ (congr_fun h), congr_arg _⟩ instance decidable_injective_fintype [decidable_eq α] [decidable_eq β] [fintype α] : decidable_pred (injective : (α → β) → Prop) := λ x, by unfold injective; apply_instance instance decidable_surjective_fintype [decidable_eq β] [fintype α] [fintype β] : decidable_pred (surjective : (α → β) → Prop) := λ x, by unfold surjective; apply_instance instance decidable_bijective_fintype [decidable_eq α] [decidable_eq β] [fintype α] [fintype β] : decidable_pred (bijective : (α → β) → Prop) := λ x, by unfold bijective; apply_instance instance decidable_left_inverse_fintype [decidable_eq α] [fintype α] (f : α → β) (g : β → α) : decidable (function.right_inverse f g) := show decidable (∀ x, g (f x) = x), by apply_instance instance decidable_right_inverse_fintype [decidable_eq β] [fintype β] (f : α → β) (g : β → α) : decidable (function.left_inverse f g) := show decidable (∀ x, f (g x) = x), by apply_instance /-- Construct a proof of `fintype α` from a universal multiset -/ def of_multiset [decidable_eq α] (s : multiset α) (H : ∀ x : α, x ∈ s) : fintype α := ⟨s.to_finset, by simpa using H⟩ /-- Construct a proof of `fintype α` from a universal list -/ def of_list [decidable_eq α] (l : list α) (H : ∀ x : α, x ∈ l) : fintype α := ⟨l.to_finset, by simpa using H⟩ theorem exists_univ_list (α) [fintype α] : ∃ l : list α, l.nodup ∧ ∀ x : α, x ∈ l := let ⟨l, e⟩ := quotient.exists_rep (@univ α _).1 in by have := and.intro univ.2 mem_univ_val; exact ⟨_, by rwa ← e at this⟩ /-- `card α` is the number of elements in `α`, defined when `α` is a fintype. -/ def card (α) [fintype α] : ℕ := (@univ α _).card /-- If `l` lists all the elements of `α` without duplicates, then `α ≃ fin (l.length)`. -/ def equiv_fin_of_forall_mem_list {α} [decidable_eq α] {l : list α} (h : ∀ x:α, x ∈ l) (nd : l.nodup) : α ≃ fin (l.length) := ⟨λ a, ⟨_, list.index_of_lt_length.2 (h a)⟩, λ i, l.nth_le i.1 i.2, λ a, by simp, λ ⟨i, h⟩, fin.eq_of_veq $ list.nodup_iff_nth_le_inj.1 nd _ _ (list.index_of_lt_length.2 (list.nth_le_mem _ _ _)) h $ by simp⟩ /-- There is (computably) a bijection between `α` and `fin n` where `n = card α`. Since it is not unique, and depends on which permutation of the universe list is used, the bijection is wrapped in `trunc` to preserve computability. -/ def equiv_fin (α) [fintype α] [decidable_eq α] : trunc (α ≃ fin (card α)) := by unfold card finset.card; exact quot.rec_on_subsingleton (@univ α _).1 (λ l (h : ∀ x:α, x ∈ l) (nd : l.nodup), trunc.mk (equiv_fin_of_forall_mem_list h nd)) mem_univ_val univ.2 theorem exists_equiv_fin (α) [fintype α] : ∃ n, nonempty (α ≃ fin n) := by haveI := classical.dec_eq α; exact ⟨card α, nonempty_of_trunc (equiv_fin α)⟩ /-- Given a linearly ordered fintype `α` of cardinal `k`, the equiv `mono_equiv_of_fin α h` is the increasing bijection between `fin k` and `α`. Here, `h` is a proof that the cardinality of `s` is `k`. We use this instead of a map `fin s.card → α` to avoid casting issues in further uses of this function. -/ noncomputable def mono_equiv_of_fin (α) [fintype α] [decidable_linear_order α] {k : ℕ} (h : fintype.card α = k) : fin k ≃ α := have A : bijective (mono_of_fin univ h) := begin apply set.bijective_iff_bij_on_univ.2, rw ← @coe_univ α _, exact bij_on_mono_of_fin (univ : finset α) h end, equiv.of_bijective A instance (α : Type*) : subsingleton (fintype α) := ⟨λ ⟨s₁, h₁⟩ ⟨s₂, h₂⟩, by congr; simp [finset.ext, h₁, h₂]⟩ protected def subtype {p : α → Prop} (s : finset α) (H : ∀ x : α, x ∈ s ↔ p x) : fintype {x // p x} := ⟨⟨multiset.pmap subtype.mk s.1 (λ x, (H x).1), multiset.nodup_pmap (λ a _ b _, congr_arg subtype.val) s.2⟩, λ ⟨x, px⟩, multiset.mem_pmap.2 ⟨x, (H x).2 px, rfl⟩⟩ theorem subtype_card {p : α → Prop} (s : finset α) (H : ∀ x : α, x ∈ s ↔ p x) : @card {x // p x} (fintype.subtype s H) = s.card := multiset.card_pmap _ _ _ theorem card_of_subtype {p : α → Prop} (s : finset α) (H : ∀ x : α, x ∈ s ↔ p x) [fintype {x // p x}] : card {x // p x} = s.card := by rw ← subtype_card s H; congr /-- Construct a fintype from a finset with the same elements. -/ def of_finset {p : set α} (s : finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : fintype p := fintype.subtype s H @[simp] theorem card_of_finset {p : set α} (s : finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : @fintype.card p (of_finset s H) = s.card := fintype.subtype_card s H theorem card_of_finset' {p : set α} (s : finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) [fintype p] : fintype.card p = s.card := by rw ← card_of_finset s H; congr /-- If `f : α → β` is a bijection and `α` is a fintype, then `β` is also a fintype. -/ def of_bijective [fintype α] (f : α → β) (H : function.bijective f) : fintype β := ⟨univ.map ⟨f, H.1⟩, λ b, let ⟨a, e⟩ := H.2 b in e ▸ mem_map_of_mem _ (mem_univ _)⟩ /-- If `f : α → β` is a surjection and `α` is a fintype, then `β` is also a fintype. -/ def of_surjective [fintype α] [decidable_eq β] (f : α → β) (H : function.surjective f) : fintype β := ⟨univ.image f, λ b, let ⟨a, e⟩ := H b in e ▸ mem_image_of_mem _ (mem_univ _)⟩ noncomputable def of_injective [fintype β] (f : α → β) (H : function.injective f) : fintype α := by letI := classical.dec; exact if hα : nonempty α then by letI := classical.inhabited_of_nonempty hα; exact of_surjective (inv_fun f) (inv_fun_surjective H) else ⟨∅, λ x, (hα ⟨x⟩).elim⟩ /-- If `f : α ≃ β` and `α` is a fintype, then `β` is also a fintype. -/ def of_equiv (α : Type*) [fintype α] (f : α ≃ β) : fintype β := of_bijective _ f.bijective theorem of_equiv_card [fintype α] (f : α ≃ β) : @card β (of_equiv α f) = card α := multiset.card_map _ _ theorem card_congr {α β} [fintype α] [fintype β] (f : α ≃ β) : card α = card β := by rw ← of_equiv_card f; congr theorem card_eq {α β} [F : fintype α] [G : fintype β] : card α = card β ↔ nonempty (α ≃ β) := ⟨λ h, ⟨by classical; calc α ≃ fin (card α) : trunc.out (equiv_fin α) ... ≃ fin (card β) : by rw h ... ≃ β : (trunc.out (equiv_fin β)).symm⟩, λ ⟨f⟩, card_congr f⟩ def of_subsingleton (a : α) [subsingleton α] : fintype α := ⟨finset.singleton a, λ b, finset.mem_singleton.2 (subsingleton.elim _ _)⟩ @[simp] theorem univ_of_subsingleton (a : α) [subsingleton α] : @univ _ (of_subsingleton a) = finset.singleton a := rfl @[simp] theorem card_of_subsingleton (a : α) [subsingleton α] : @fintype.card _ (of_subsingleton a) = 1 := rfl end fintype namespace set /-- Construct a finset enumerating a set `s`, given a `fintype` instance. -/ def to_finset (s : set α) [fintype s] : finset α := ⟨(@finset.univ s _).1.map subtype.val, multiset.nodup_map (λ a b, subtype.eq) finset.univ.2⟩ @[simp] theorem mem_to_finset {s : set α} [fintype s] {a : α} : a ∈ s.to_finset ↔ a ∈ s := by simp [to_finset] @[simp] theorem mem_to_finset_val {s : set α} [fintype s] {a : α} : a ∈ s.to_finset.1 ↔ a ∈ s := mem_to_finset end set lemma finset.card_univ [fintype α] : (finset.univ : finset α).card = fintype.card α := rfl lemma finset.card_univ_diff [fintype α] [decidable_eq α] (s : finset α) : (finset.univ \ s).card = fintype.card α - s.card := finset.card_sdiff (subset_univ s) instance (n : ℕ) : fintype (fin n) := ⟨⟨list.fin_range n, list.nodup_fin_range n⟩, list.mem_fin_range⟩ @[simp] theorem fintype.card_fin (n : ℕ) : fintype.card (fin n) = n := list.length_fin_range n @[simp] lemma finset.card_fin (n : ℕ) : finset.card (finset.univ : finset (fin n)) = n := by rw [finset.card_univ, fintype.card_fin] lemma fin.univ_succ (n : ℕ) : (univ : finset (fin $ n+1)) = insert 0 (univ.image fin.succ) := begin ext m, simp only [mem_univ, mem_insert, true_iff, mem_image, exists_prop], exact fin.cases (or.inl rfl) (λ i, or.inr ⟨i, trivial, rfl⟩) m end lemma fin.univ_cast_succ (n : ℕ) : (univ : finset (fin $ n+1)) = insert (fin.last n) (univ.image fin.cast_succ) := begin ext m, simp only [mem_univ, mem_insert, true_iff, mem_image, exists_prop, true_and], by_cases h : m.val < n, { right, use fin.cast_lt m h, rw fin.cast_succ_cast_lt }, { left, exact fin.eq_last_of_not_lt h } end /-- Any increasing map between `fin k` and a finset of cardinality `k` has to coincide with the increasing bijection `mono_of_fin s h`. -/ lemma finset.mono_of_fin_unique' [decidable_linear_order α] {s : finset α} {k : ℕ} (h : s.card = k) {f : fin k → α} (fmap : set.maps_to f set.univ ↑s) (hmono : strict_mono f) : f = s.mono_of_fin h := begin have finj : set.inj_on f set.univ := hmono.injective.inj_on _, apply mono_of_fin_unique h (set.bij_on.mk fmap finj (λ y hy, _)) hmono, simp only [set.image_univ, set.mem_range], rcases surj_on_of_inj_on_of_card_le (λ i (hi : i ∈ finset.univ), f i) (λ i hi, fmap (set.mem_univ i)) (λ i j hi hj hij, finj (set.mem_univ i) (set.mem_univ j) hij) (by simp [h]) y hy with ⟨x, _, hx⟩, exact ⟨x, hx.symm⟩ end @[instance, priority 10] def unique.fintype {α : Type*} [unique α] : fintype α := ⟨finset.singleton (default α), λ x, by rw [unique.eq_default x]; simp⟩ @[simp] lemma univ_unique {α : Type*} [unique α] [f : fintype α] : @finset.univ α _ = {default α} := by rw [subsingleton.elim f (@unique.fintype α _)]; refl instance : fintype empty := ⟨∅, empty.rec _⟩ @[simp] theorem fintype.univ_empty : @univ empty _ = ∅ := rfl @[simp] theorem fintype.card_empty : fintype.card empty = 0 := rfl instance : fintype pempty := ⟨∅, pempty.rec _⟩ @[simp] theorem fintype.univ_pempty : @univ pempty _ = ∅ := rfl @[simp] theorem fintype.card_pempty : fintype.card pempty = 0 := rfl instance : fintype unit := fintype.of_subsingleton () theorem fintype.univ_unit : @univ unit _ = {()} := rfl theorem fintype.card_unit : fintype.card unit = 1 := rfl instance : fintype punit := fintype.of_subsingleton punit.star @[simp] theorem fintype.univ_punit : @univ punit _ = {punit.star} := rfl @[simp] theorem fintype.card_punit : fintype.card punit = 1 := rfl instance : fintype bool := ⟨⟨tt::ff::0, by simp⟩, λ x, by cases x; simp⟩ @[simp] theorem fintype.univ_bool : @univ bool _ = {ff, tt} := rfl instance units_int.fintype : fintype (units ℤ) := ⟨{1, -1}, λ x, by cases int.units_eq_one_or x; simp *⟩ instance additive.fintype : Π [fintype α], fintype (additive α) := id instance multiplicative.fintype : Π [fintype α], fintype (multiplicative α) := id @[simp] theorem fintype.card_units_int : fintype.card (units ℤ) = 2 := rfl noncomputable instance [monoid α] [fintype α] : fintype (units α) := by classical; exact fintype.of_injective units.val units.ext @[simp] theorem fintype.card_bool : fintype.card bool = 2 := rfl def finset.insert_none (s : finset α) : finset (option α) := ⟨none :: s.1.map some, multiset.nodup_cons.2 ⟨by simp, multiset.nodup_map (λ a b, option.some.inj) s.2⟩⟩ @[simp] theorem finset.mem_insert_none {s : finset α} : ∀ {o : option α}, o ∈ s.insert_none ↔ ∀ a ∈ o, a ∈ s | none := iff_of_true (multiset.mem_cons_self _ _) (λ a h, by cases h) | (some a) := multiset.mem_cons.trans $ by simp; refl theorem finset.some_mem_insert_none {s : finset α} {a : α} : some a ∈ s.insert_none ↔ a ∈ s := by simp instance {α : Type*} [fintype α] : fintype (option α) := ⟨univ.insert_none, λ a, by simp⟩ @[simp] theorem fintype.card_option {α : Type*} [fintype α] : fintype.card (option α) = fintype.card α + 1 := (multiset.card_cons _ _).trans (by rw multiset.card_map; refl) instance {α : Type*} (β : α → Type*) [fintype α] [∀ a, fintype (β a)] : fintype (sigma β) := ⟨univ.sigma (λ _, univ), λ ⟨a, b⟩, by simp⟩ instance (α β : Type*) [fintype α] [fintype β] : fintype (α × β) := ⟨univ.product univ, λ ⟨a, b⟩, by simp⟩ @[simp] theorem fintype.card_prod (α β : Type*) [fintype α] [fintype β] : fintype.card (α × β) = fintype.card α * fintype.card β := card_product _ _ def fintype.fintype_prod_left {α β} [decidable_eq α] [fintype (α × β)] [nonempty β] : fintype α := ⟨(fintype.elems (α × β)).image prod.fst, assume a, let ⟨b⟩ := ‹nonempty β› in by simp; exact ⟨b, fintype.complete _⟩⟩ def fintype.fintype_prod_right {α β} [decidable_eq β] [fintype (α × β)] [nonempty α] : fintype β := ⟨(fintype.elems (α × β)).image prod.snd, assume b, let ⟨a⟩ := ‹nonempty α› in by simp; exact ⟨a, fintype.complete _⟩⟩ instance (α : Type*) [fintype α] : fintype (ulift α) := fintype.of_equiv _ equiv.ulift.symm @[simp] theorem fintype.card_ulift (α : Type*) [fintype α] : fintype.card (ulift α) = fintype.card α := fintype.of_equiv_card _ instance (α : Type u) (β : Type v) [fintype α] [fintype β] : fintype (α ⊕ β) := @fintype.of_equiv _ _ (@sigma.fintype _ (λ b, cond b (ulift α) (ulift.{(max u v) v} β)) _ (λ b, by cases b; apply ulift.fintype)) ((equiv.sum_equiv_sigma_bool _ _).symm.trans (equiv.sum_congr equiv.ulift equiv.ulift)) lemma fintype.card_le_of_injective [fintype α] [fintype β] (f : α → β) (hf : function.injective f) : fintype.card α ≤ fintype.card β := by haveI := classical.prop_decidable; exact finset.card_le_card_of_inj_on f (λ _ _, finset.mem_univ _) (λ _ _ _ _ h, hf h) lemma fintype.card_eq_one_iff [fintype α] : fintype.card α = 1 ↔ (∃ x : α, ∀ y, y = x) := by rw [← fintype.card_unit, fintype.card_eq]; exact ⟨λ ⟨a⟩, ⟨a.symm (), λ y, a.injective (subsingleton.elim _ _)⟩, λ ⟨x, hx⟩, ⟨⟨λ _, (), λ _, x, λ _, (hx _).trans (hx _).symm, λ _, subsingleton.elim _ _⟩⟩⟩ lemma fintype.card_eq_zero_iff [fintype α] : fintype.card α = 0 ↔ (α → false) := ⟨λ h a, have e : α ≃ empty := classical.choice (fintype.card_eq.1 (by simp [h])), (e a).elim, λ h, have e : α ≃ empty := ⟨λ a, (h a).elim, λ a, a.elim, λ a, (h a).elim, λ a, a.elim⟩, by simp [fintype.card_congr e]⟩ lemma fintype.card_pos_iff [fintype α] : 0 < fintype.card α ↔ nonempty α := ⟨λ h, classical.by_contradiction (λ h₁, have fintype.card α = 0 := fintype.card_eq_zero_iff.2 (λ a, h₁ ⟨a⟩), lt_irrefl 0 $ by rwa this at h), λ ⟨a⟩, nat.pos_of_ne_zero (mt fintype.card_eq_zero_iff.1 (λ h, h a))⟩ lemma fintype.card_le_one_iff [fintype α] : fintype.card α ≤ 1 ↔ (∀ a b : α, a = b) := let n := fintype.card α in have hn : n = fintype.card α := rfl, match n, hn with | 0 := λ ha, ⟨λ h, λ a, (fintype.card_eq_zero_iff.1 ha.symm a).elim, λ _, ha ▸ nat.le_succ _⟩ | 1 := λ ha, ⟨λ h, λ a b, let ⟨x, hx⟩ := fintype.card_eq_one_iff.1 ha.symm in by rw [hx a, hx b], λ _, ha ▸ le_refl _⟩ | (n+2) := λ ha, ⟨λ h, by rw ← ha at h; exact absurd h dec_trivial, (λ h, fintype.card_unit ▸ fintype.card_le_of_injective (λ _, ()) (λ _ _ _, h _ _))⟩ end lemma fintype.exists_ne_of_one_lt_card [fintype α] (h : 1 < fintype.card α) (a : α) : ∃ b : α, b ≠ a := let ⟨b, hb⟩ := classical.not_forall.1 (mt fintype.card_le_one_iff.2 (not_le_of_gt h)) in let ⟨c, hc⟩ := classical.not_forall.1 hb in by haveI := classical.dec_eq α; exact if hba : b = a then ⟨c, by cc⟩ else ⟨b, hba⟩ lemma fintype.injective_iff_surjective [fintype α] {f : α → α} : injective f ↔ surjective f := by haveI := classical.prop_decidable; exact have ∀ {f : α → α}, injective f → surjective f, from λ f hinj x, have h₁ : image f univ = univ := eq_of_subset_of_card_le (subset_univ _) ((card_image_of_injective univ hinj).symm ▸ le_refl _), have h₂ : x ∈ image f univ := h₁.symm ▸ mem_univ _, exists_of_bex (mem_image.1 h₂), ⟨this, λ hsurj, injective_of_has_left_inverse ⟨surj_inv hsurj, left_inverse_of_surjective_of_right_inverse (this (injective_surj_inv _)) (right_inverse_surj_inv _)⟩⟩ lemma fintype.injective_iff_bijective [fintype α] {f : α → α} : injective f ↔ bijective f := by simp [bijective, fintype.injective_iff_surjective] lemma fintype.surjective_iff_bijective [fintype α] {f : α → α} : surjective f ↔ bijective f := by simp [bijective, fintype.injective_iff_surjective] lemma fintype.injective_iff_surjective_of_equiv [fintype α] {f : α → β} (e : α ≃ β) : injective f ↔ surjective f := have injective (e.symm ∘ f) ↔ surjective (e.symm ∘ f), from fintype.injective_iff_surjective, ⟨λ hinj, by simpa [function.comp] using surjective_comp e.surjective (this.1 (injective_comp e.symm.injective hinj)), λ hsurj, by simpa [function.comp] using injective_comp e.injective (this.2 (surjective_comp e.symm.surjective hsurj))⟩ lemma fintype.coe_image_univ [fintype α] [decidable_eq β] {f : α → β} : ↑(finset.image f finset.univ) = set.range f := by { ext x, simp } instance list.subtype.fintype [decidable_eq α] (l : list α) : fintype {x // x ∈ l} := fintype.of_list l.attach l.mem_attach instance multiset.subtype.fintype [decidable_eq α] (s : multiset α) : fintype {x // x ∈ s} := fintype.of_multiset s.attach s.mem_attach instance finset.subtype.fintype (s : finset α) : fintype {x // x ∈ s} := ⟨s.attach, s.mem_attach⟩ instance finset_coe.fintype (s : finset α) : fintype (↑s : set α) := finset.subtype.fintype s @[simp] lemma fintype.card_coe (s : finset α) : fintype.card (↑s : set α) = s.card := card_attach lemma finset.card_le_one_iff {s : finset α} : s.card ≤ 1 ↔ ∀ {x y}, x ∈ s → y ∈ s → x = y := begin let t : set α := ↑s, letI : fintype t := finset_coe.fintype s, have : fintype.card t = s.card := fintype.card_coe s, rw [← this, fintype.card_le_one_iff], split, { assume H x y hx hy, exact subtype.mk.inj (H ⟨x, hx⟩ ⟨y, hy⟩) }, { assume H x y, exact subtype.eq (H x.2 y.2) } end lemma finset.one_lt_card_iff {s : finset α} : 1 < s.card ↔ ∃ x y, (x ∈ s) ∧ (y ∈ s) ∧ x ≠ y := begin classical, rw ← not_iff_not, push_neg, simpa [classical.or_iff_not_imp_left] using finset.card_le_one_iff end instance plift.fintype (p : Prop) [decidable p] : fintype (plift p) := ⟨if h : p then finset.singleton ⟨h⟩ else ∅, λ ⟨h⟩, by simp [h]⟩ instance Prop.fintype : fintype Prop := ⟨⟨true::false::0, by simp [true_ne_false]⟩, classical.cases (by simp) (by simp)⟩ def set_fintype {α} [fintype α] (s : set α) [decidable_pred s] : fintype s := fintype.subtype (univ.filter (∈ s)) (by simp) namespace fintype variables [fintype α] [decidable_eq α] {δ : α → Type*} /-- Given for all `a : α` a finset `t a` of `δ a`, then one can define the finset `fintype.pi_finset t` of all functions taking values in `t a` for all `a`. This is the analogue of `finset.pi` where the base finset is `univ` (but formally they are not the same, as there is an additional condition `i ∈ finset.univ` in the `finset.pi` definition). -/ def pi_finset (t : Πa, finset (δ a)) : finset (Πa, δ a) := (finset.univ.pi t).map ⟨λ f a, f a (mem_univ a), λ _ _, by simp [function.funext_iff]⟩ @[simp] lemma mem_pi_finset {t : Πa, finset (δ a)} {f : Πa, δ a} : f ∈ pi_finset t ↔ (∀a, f a ∈ t a) := begin split, { simp only [pi_finset, mem_map, and_imp, forall_prop_of_true, exists_prop, mem_univ, exists_imp_distrib, mem_pi], assume g hg hgf a, rw ← hgf, exact hg a }, { simp only [pi_finset, mem_map, forall_prop_of_true, exists_prop, mem_univ, mem_pi], assume hf, exact ⟨λ a ha, f a, hf, rfl⟩ } end lemma pi_finset_subset (t₁ t₂ : Πa, finset (δ a)) (h : ∀ a, t₁ a ⊆ t₂ a) : pi_finset t₁ ⊆ pi_finset t₂ := λ g hg, mem_pi_finset.2 $ λ a, h a $ mem_pi_finset.1 hg a lemma pi_finset_disjoint_of_disjoint [∀ a, decidable_eq (δ a)] (t₁ t₂ : Πa, finset (δ a)) {a : α} (h : disjoint (t₁ a) (t₂ a)) : disjoint (pi_finset t₁) (pi_finset t₂) := disjoint_iff_ne.2 $ λ f₁ hf₁ f₂ hf₂ eq₁₂, disjoint_iff_ne.1 h (f₁ a) (mem_pi_finset.1 hf₁ a) (f₂ a) (mem_pi_finset.1 hf₂ a) (congr_fun eq₁₂ a) end fintype /-! ### pi -/ /-- A dependent product of fintypes, indexed by a fintype, is a fintype. -/ instance pi.fintype {α : Type*} {β : α → Type*} [decidable_eq α] [fintype α] [∀a, fintype (β a)] : fintype (Πa, β a) := ⟨fintype.pi_finset (λ _, univ), by simp⟩ @[simp] lemma fintype.pi_finset_univ {α : Type*} {β : α → Type*} [decidable_eq α] [fintype α] [∀a, fintype (β a)] : fintype.pi_finset (λ a : α, (finset.univ : finset (β a))) = (finset.univ : finset (Π a, β a)) := rfl instance d_array.fintype {n : ℕ} {α : fin n → Type*} [∀n, fintype (α n)] : fintype (d_array n α) := fintype.of_equiv _ (equiv.d_array_equiv_fin _).symm instance array.fintype {n : ℕ} {α : Type*} [fintype α] : fintype (array n α) := d_array.fintype instance vector.fintype {α : Type*} [fintype α] {n : ℕ} : fintype (vector α n) := fintype.of_equiv _ (equiv.vector_equiv_fin _ _).symm instance quotient.fintype [fintype α] (s : setoid α) [decidable_rel ((≈) : α → α → Prop)] : fintype (quotient s) := fintype.of_surjective quotient.mk (λ x, quotient.induction_on x (λ x, ⟨x, rfl⟩)) instance finset.fintype [fintype α] : fintype (finset α) := ⟨univ.powerset, λ x, finset.mem_powerset.2 (finset.subset_univ _)⟩ @[simp] lemma fintype.card_finset [fintype α] : fintype.card (finset α) = 2 ^ (fintype.card α) := finset.card_powerset finset.univ instance subtype.fintype (p : α → Prop) [decidable_pred p] [fintype α] : fintype {x // p x} := set_fintype _ theorem fintype.card_subtype_le [fintype α] (p : α → Prop) [decidable_pred p] : fintype.card {x // p x} ≤ fintype.card α := by rw fintype.subtype_card; exact card_le_of_subset (subset_univ _) theorem fintype.card_subtype_lt [fintype α] {p : α → Prop} [decidable_pred p] {x : α} (hx : ¬ p x) : fintype.card {x // p x} < fintype.card α := by rw [fintype.subtype_card]; exact finset.card_lt_card ⟨subset_univ _, classical.not_forall.2 ⟨x, by simp [*, set.mem_def]⟩⟩ instance psigma.fintype {α : Type*} {β : α → Type*} [fintype α] [∀ a, fintype (β a)] : fintype (Σ' a, β a) := fintype.of_equiv _ (equiv.psigma_equiv_sigma _).symm instance psigma.fintype_prop_left {α : Prop} {β : α → Type*} [decidable α] [∀ a, fintype (β a)] : fintype (Σ' a, β a) := if h : α then fintype.of_equiv (β h) ⟨λ x, ⟨h, x⟩, psigma.snd, λ _, rfl, λ ⟨_, _⟩, rfl⟩ else ⟨∅, λ x, h x.1⟩ instance psigma.fintype_prop_right {α : Type*} {β : α → Prop} [∀ a, decidable (β a)] [fintype α] : fintype (Σ' a, β a) := fintype.of_equiv {a // β a} ⟨λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨x, y⟩, rfl, λ ⟨x, y⟩, rfl⟩ instance psigma.fintype_prop_prop {α : Prop} {β : α → Prop} [decidable α] [∀ a, decidable (β a)] : fintype (Σ' a, β a) := if h : ∃ a, β a then ⟨{⟨h.fst, h.snd⟩}, λ ⟨_, _⟩, by simp⟩ else ⟨∅, λ ⟨x, y⟩, h ⟨x, y⟩⟩ instance set.fintype [decidable_eq α] [fintype α] : fintype (set α) := pi.fintype instance pfun_fintype (p : Prop) [decidable p] (α : p → Type*) [Π hp, fintype (α hp)] : fintype (Π hp : p, α hp) := if hp : p then fintype.of_equiv (α hp) ⟨λ a _, a, λ f, f hp, λ _, rfl, λ _, rfl⟩ else ⟨singleton (λ h, (hp h).elim), by simp [hp, function.funext_iff]⟩ def quotient.fin_choice_aux {ι : Type*} [decidable_eq ι] {α : ι → Type*} [S : ∀ i, setoid (α i)] : ∀ (l : list ι), (∀ i ∈ l, quotient (S i)) → @quotient (Π i ∈ l, α i) (by apply_instance) | [] f := ⟦λ i, false.elim⟧ | (i::l) f := begin refine quotient.lift_on₂ (f i (list.mem_cons_self _ _)) (quotient.fin_choice_aux l (λ j h, f j (list.mem_cons_of_mem _ h))) _ _, exact λ a l, ⟦λ j h, if e : j = i then by rw e; exact a else l _ (h.resolve_left e)⟧, refine λ a₁ l₁ a₂ l₂ h₁ h₂, quotient.sound (λ j h, _), by_cases e : j = i; simp [e], { subst j, exact h₁ }, { exact h₂ _ _ } end theorem quotient.fin_choice_aux_eq {ι : Type*} [decidable_eq ι] {α : ι → Type*} [S : ∀ i, setoid (α i)] : ∀ (l : list ι) (f : ∀ i ∈ l, α i), quotient.fin_choice_aux l (λ i h, ⟦f i h⟧) = ⟦f⟧ | [] f := quotient.sound (λ i h, h.elim) | (i::l) f := begin simp [quotient.fin_choice_aux, quotient.fin_choice_aux_eq l], refine quotient.sound (λ j h, _), by_cases e : j = i; simp [e], subst j, refl end def quotient.fin_choice {ι : Type*} [fintype ι] [decidable_eq ι] {α : ι → Type*} [S : ∀ i, setoid (α i)] (f : ∀ i, quotient (S i)) : @quotient (Π i, α i) (by apply_instance) := quotient.lift_on (@quotient.rec_on _ _ (λ l : multiset ι, @quotient (Π i ∈ l, α i) (by apply_instance)) finset.univ.1 (λ l, quotient.fin_choice_aux l (λ i _, f i)) (λ a b h, begin have := λ a, quotient.fin_choice_aux_eq a (λ i h, quotient.out (f i)), simp [quotient.out_eq] at this, simp [this], let g := λ a:multiset ι, ⟦λ (i : ι) (h : i ∈ a), quotient.out (f i)⟧, refine eq_of_heq ((eq_rec_heq _ _).trans (_ : g a == g b)), congr' 1, exact quotient.sound h, end)) (λ f, ⟦λ i, f i (finset.mem_univ _)⟧) (λ a b h, quotient.sound $ λ i, h _ _) theorem quotient.fin_choice_eq {ι : Type*} [fintype ι] [decidable_eq ι] {α : ι → Type*} [∀ i, setoid (α i)] (f : ∀ i, α i) : quotient.fin_choice (λ i, ⟦f i⟧) = ⟦f⟧ := begin let q, swap, change quotient.lift_on q _ _ = _, have : q = ⟦λ i h, f i⟧, { dsimp [q], exact quotient.induction_on (@finset.univ ι _).1 (λ l, quotient.fin_choice_aux_eq _ _) }, simp [this], exact setoid.refl _ end section equiv open list equiv equiv.perm variables [decidable_eq α] [decidable_eq β] def perms_of_list : list α → list (perm α) | [] := [1] | (a :: l) := perms_of_list l ++ l.bind (λ b, (perms_of_list l).map (λ f, swap a b * f)) lemma length_perms_of_list : ∀ l : list α, length (perms_of_list l) = l.length.fact | [] := rfl | (a :: l) := begin rw [length_cons, nat.fact_succ], simp [perms_of_list, length_bind, length_perms_of_list, function.comp, nat.succ_mul], cc end lemma mem_perms_of_list_of_mem : ∀ {l : list α} {f : perm α} (h : ∀ x, f x ≠ x → x ∈ l), f ∈ perms_of_list l | [] f h := list.mem_singleton.2 $ equiv.ext _ _$ λ x, by simp [imp_false, *] at * | (a::l) f h := if hfa : f a = a then mem_append_left _ $ mem_perms_of_list_of_mem (λ x hx, mem_of_ne_of_mem (λ h, by rw h at hx; exact hx hfa) (h x hx)) else have hfa' : f (f a) ≠ f a, from mt (λ h, f.injective h) hfa, have ∀ (x : α), (swap a (f a) * f) x ≠ x → x ∈ l, from λ x hx, have hxa : x ≠ a, from λ h, by simpa [h, mul_apply] using hx, have hfxa : f x ≠ f a, from mt (λ h, f.injective h) hxa, list.mem_of_ne_of_mem hxa (h x (λ h, by simp [h, mul_apply, swap_apply_def] at hx; split_ifs at hx; cc)), suffices f ∈ perms_of_list l ∨ ∃ (b : α), b ∈ l ∧ ∃ g : perm α, g ∈ perms_of_list l ∧ swap a b * g = f, by simpa [perms_of_list], (@or_iff_not_imp_left _ _ (classical.prop_decidable _)).2 (λ hfl, ⟨f a, if hffa : f (f a) = a then mem_of_ne_of_mem hfa (h _ (mt (λ h, f.injective h) hfa)) else this _ $ by simp [mul_apply, swap_apply_def]; split_ifs; cc, ⟨swap a (f a) * f, mem_perms_of_list_of_mem this, by rw [← mul_assoc, mul_def (swap a (f a)) (swap a (f a)), swap_swap, ← equiv.perm.one_def, one_mul]⟩⟩) lemma mem_of_mem_perms_of_list : ∀ {l : list α} {f : perm α}, f ∈ perms_of_list l → ∀ {x}, f x ≠ x → x ∈ l | [] f h := have f = 1 := by simpa [perms_of_list] using h, by rw this; simp | (a::l) f h := (mem_append.1 h).elim (λ h x hx, mem_cons_of_mem _ (mem_of_mem_perms_of_list h hx)) (λ h x hx, let ⟨y, hy, hy'⟩ := list.mem_bind.1 h in let ⟨g, hg₁, hg₂⟩ := list.mem_map.1 hy' in if hxa : x = a then by simp [hxa] else if hxy : x = y then mem_cons_of_mem _ $ by rwa hxy else mem_cons_of_mem _ $ mem_of_mem_perms_of_list hg₁ $ by rw [eq_inv_mul_iff_mul_eq.2 hg₂, mul_apply, swap_inv, swap_apply_def]; split_ifs; cc) lemma mem_perms_of_list_iff {l : list α} {f : perm α} : f ∈ perms_of_list l ↔ ∀ {x}, f x ≠ x → x ∈ l := ⟨mem_of_mem_perms_of_list, mem_perms_of_list_of_mem⟩ lemma nodup_perms_of_list : ∀ {l : list α} (hl : l.nodup), (perms_of_list l).nodup | [] hl := by simp [perms_of_list] | (a::l) hl := have hl' : l.nodup, from nodup_of_nodup_cons hl, have hln' : (perms_of_list l).nodup, from nodup_perms_of_list hl', have hmeml : ∀ {f : perm α}, f ∈ perms_of_list l → f a = a, from λ f hf, not_not.1 (mt (mem_of_mem_perms_of_list hf) (nodup_cons.1 hl).1), by rw [perms_of_list, list.nodup_append, list.nodup_bind, pairwise_iff_nth_le]; exact ⟨hln', ⟨λ _ _, nodup_map (λ _ _, (mul_left_inj _).1) hln', λ i j hj hij x hx₁ hx₂, let ⟨f, hf⟩ := list.mem_map.1 hx₁ in let ⟨g, hg⟩ := list.mem_map.1 hx₂ in have hix : x a = nth_le l i (lt_trans hij hj), by rw [← hf.2, mul_apply, hmeml hf.1, swap_apply_left], have hiy : x a = nth_le l j hj, by rw [← hg.2, mul_apply, hmeml hg.1, swap_apply_left], absurd (hf.2.trans (hg.2.symm)) $ λ h, ne_of_lt hij $ nodup_iff_nth_le_inj.1 hl' i j (lt_trans hij hj) hj $ by rw [← hix, hiy]⟩, λ f hf₁ hf₂, let ⟨x, hx, hx'⟩ := list.mem_bind.1 hf₂ in let ⟨g, hg⟩ := list.mem_map.1 hx' in have hgxa : g⁻¹ x = a, from f.injective $ by rw [hmeml hf₁, ← hg.2]; simp, have hxa : x ≠ a, from λ h, (list.nodup_cons.1 hl).1 (h ▸ hx), (list.nodup_cons.1 hl).1 $ hgxa ▸ mem_of_mem_perms_of_list hg.1 (by rwa [apply_inv_self, hgxa])⟩ def perms_of_finset (s : finset α) : finset (perm α) := quotient.hrec_on s.1 (λ l hl, ⟨perms_of_list l, nodup_perms_of_list hl⟩) (λ a b hab, hfunext (congr_arg _ (quotient.sound hab)) (λ ha hb _, heq_of_eq $ finset.ext.2 $ by simp [mem_perms_of_list_iff,mem_of_perm hab])) s.2 lemma mem_perms_of_finset_iff : ∀ {s : finset α} {f : perm α}, f ∈ perms_of_finset s ↔ ∀ {x}, f x ≠ x → x ∈ s := by rintros ⟨⟨l⟩, hs⟩ f; exact mem_perms_of_list_iff lemma card_perms_of_finset : ∀ (s : finset α), (perms_of_finset s).card = s.card.fact := by rintros ⟨⟨l⟩, hs⟩; exact length_perms_of_list l def fintype_perm [fintype α] : fintype (perm α) := ⟨perms_of_finset (@finset.univ α _), by simp [mem_perms_of_finset_iff]⟩ instance [fintype α] [fintype β] : fintype (α ≃ β) := if h : fintype.card β = fintype.card α then trunc.rec_on_subsingleton (fintype.equiv_fin α) (λ eα, trunc.rec_on_subsingleton (fintype.equiv_fin β) (λ eβ, @fintype.of_equiv _ (perm α) fintype_perm (equiv_congr (equiv.refl α) (eα.trans (eq.rec_on h eβ.symm)) : (α ≃ α) ≃ (α ≃ β)))) else ⟨∅, λ x, false.elim (h (fintype.card_eq.2 ⟨x.symm⟩))⟩ lemma fintype.card_perm [fintype α] : fintype.card (perm α) = (fintype.card α).fact := subsingleton.elim (@fintype_perm α _ _) (@equiv.fintype α α _ _ _ _) ▸ card_perms_of_finset _ lemma fintype.card_equiv [fintype α] [fintype β] (e : α ≃ β) : fintype.card (α ≃ β) = (fintype.card α).fact := fintype.card_congr (equiv_congr (equiv.refl α) e) ▸ fintype.card_perm lemma univ_eq_singleton_of_card_one {α} [fintype α] (x : α) (h : fintype.card α = 1) : (univ : finset α) = finset.singleton x := begin apply symm, apply eq_of_subset_of_card_le (subset_univ (finset.singleton x)), apply le_of_eq, simp [h, finset.card_univ] end end equiv namespace fintype section choose open fintype open equiv variables [fintype α] [decidable_eq α] (p : α → Prop) [decidable_pred p] def choose_x (hp : ∃! a : α, p a) : {a // p a} := ⟨finset.choose p univ (by simp; exact hp), finset.choose_property _ _ _⟩ def choose (hp : ∃! a, p a) : α := choose_x p hp lemma choose_spec (hp : ∃! a, p a) : p (choose p hp) := (choose_x p hp).property end choose section bijection_inverse open function variables [fintype α] [decidable_eq α] variables [fintype β] [decidable_eq β] variables {f : α → β} /-- ` `bij_inv f` is the unique inverse to a bijection `f`. This acts as a computable alternative to `function.inv_fun`. -/ def bij_inv (f_bij : bijective f) (b : β) : α := fintype.choose (λ a, f a = b) begin rcases f_bij.right b with ⟨a', fa_eq_b⟩, rw ← fa_eq_b, exact ⟨a', ⟨rfl, (λ a h, f_bij.left h)⟩⟩ end lemma left_inverse_bij_inv (f_bij : bijective f) : left_inverse (bij_inv f_bij) f := λ a, f_bij.left (choose_spec (λ a', f a' = f a) _) lemma right_inverse_bij_inv (f_bij : bijective f) : right_inverse (bij_inv f_bij) f := λ b, choose_spec (λ a', f a' = b) _ lemma bijective_bij_inv (f_bij : bijective f) : bijective (bij_inv f_bij) := ⟨injective_of_left_inverse (right_inverse_bij_inv _), surjective_of_has_right_inverse ⟨f, left_inverse_bij_inv _⟩⟩ end bijection_inverse lemma well_founded_of_trans_of_irrefl [fintype α] (r : α → α → Prop) [is_trans α r] [is_irrefl α r] : well_founded r := by classical; exact have ∀ x y, r x y → (univ.filter (λ z, r z x)).card < (univ.filter (λ z, r z y)).card, from λ x y hxy, finset.card_lt_card $ by simp only [finset.lt_iff_ssubset.symm, lt_iff_le_not_le, finset.le_iff_subset, finset.subset_iff, mem_filter, true_and, mem_univ, hxy]; exact ⟨λ z hzx, trans hzx hxy, not_forall_of_exists_not ⟨x, not_imp.2 ⟨hxy, irrefl x⟩⟩⟩, subrelation.wf this (measure_wf _) lemma preorder.well_founded [fintype α] [preorder α] : well_founded ((<) : α → α → Prop) := well_founded_of_trans_of_irrefl _ @[instance, priority 10] lemma linear_order.is_well_order [fintype α] [linear_order α] : is_well_order α (<) := { wf := preorder.well_founded } end fintype class infinite (α : Type*) : Prop := (not_fintype : fintype α → false) @[simp] lemma not_nonempty_fintype {α : Type*} : ¬nonempty (fintype α) ↔ infinite α := ⟨λf, ⟨λ x, f ⟨x⟩⟩, λ⟨f⟩ ⟨x⟩, f x⟩ namespace infinite lemma exists_not_mem_finset [infinite α] (s : finset α) : ∃ x, x ∉ s := classical.not_forall.1 $ λ h, not_fintype ⟨s, h⟩ @[priority 100] -- see Note [lower instance priority] instance nonempty (α : Type*) [infinite α] : nonempty α := nonempty_of_exists (exists_not_mem_finset (∅ : finset α)) lemma of_injective [infinite β] (f : β → α) (hf : injective f) : infinite α := ⟨λ I, by exactI not_fintype (fintype.of_injective f hf)⟩ lemma of_surjective [infinite β] (f : α → β) (hf : surjective f) : infinite α := ⟨λ I, by classical; exactI not_fintype (fintype.of_surjective f hf)⟩ private noncomputable def nat_embedding_aux (α : Type*) [infinite α] : ℕ → α | n := by letI := classical.dec_eq α; exact classical.some (exists_not_mem_finset ((multiset.range n).pmap (λ m (hm : m < n), nat_embedding_aux m) (λ _, multiset.mem_range.1)).to_finset) private lemma nat_embedding_aux_injective (α : Type*) [infinite α] : function.injective (nat_embedding_aux α) := begin assume m n h, letI := classical.dec_eq α, wlog hmlen : m ≤ n using m n, by_contradiction hmn, have hmn : m < n, from lt_of_le_of_ne hmlen hmn, refine (classical.some_spec (exists_not_mem_finset ((multiset.range n).pmap (λ m (hm : m < n), nat_embedding_aux α m) (λ _, multiset.mem_range.1)).to_finset)) _, refine multiset.mem_to_finset.2 (multiset.mem_pmap.2 ⟨m, multiset.mem_range.2 hmn, _⟩), rw [h, nat_embedding_aux] end noncomputable def nat_embedding (α : Type*) [infinite α] : ℕ ↪ α := ⟨_, nat_embedding_aux_injective α⟩ end infinite lemma not_injective_infinite_fintype [infinite α] [fintype β] (f : α → β) : ¬ injective f := assume (hf : injective f), have H : fintype α := fintype.of_injective f hf, infinite.not_fintype H lemma not_surjective_fintype_infinite [fintype α] [infinite β] (f : α → β) : ¬ surjective f := assume (hf : surjective f), have H : infinite α := infinite.of_surjective f hf, @infinite.not_fintype _ H infer_instance instance nat.infinite : infinite ℕ := ⟨λ ⟨s, hs⟩, finset.not_mem_range_self $ s.subset_range_sup_succ (hs _)⟩ instance int.infinite : infinite ℤ := infinite.of_injective int.of_nat (λ _ _, int.of_nat_inj)
281f8dadda6673c5b31b1d9f431298bbc19af8e6
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/order/rel_classes.lean
7d31544d225acead44c82386659024521442ddf7
[ "Apache-2.0" ]
permissive
robertylewis/mathlib
3d16e3e6daf5ddde182473e03a1b601d2810952c
1d13f5b932f5e40a8308e3840f96fc882fae01f0
refs/heads/master
1,651,379,945,369
1,644,276,960,000
1,644,276,960,000
98,875,504
0
0
Apache-2.0
1,644,253,514,000
1,501,495,700,000
Lean
UTF-8
Lean
false
false
21,989
lean
/- Copyright (c) 2020 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Mario Carneiro, Yury G. Kudryashov -/ import order.basic /-! # Unbundled relation classes In this file we prove some properties of `is_*` classes defined in `init.algebra.classes`. The main difference between these classes and the usual order classes (`preorder` etc) is that usual classes extend `has_le` and/or `has_lt` while these classes take a relation as an explicit argument. -/ universes u v variables {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop} open function lemma comm [is_symm α r] {a b : α} : r a b ↔ r b a := ⟨symm, symm⟩ lemma antisymm' {r : α → α → Prop} [is_antisymm α r] {a b : α} : r a b → r b a → b = a := λ h h', antisymm h' h /-- A version of `antisymm` with `r` explicit. This lemma matches the lemmas from lean core in `init.algebra.classes`, but is missing there. -/ @[elab_simple] lemma antisymm_of (r : α → α → Prop) [is_antisymm α r] {a b : α} : r a b → r b a → a = b := antisymm /-- A version of `antisymm'` with `r` explicit. This lemma matches the lemmas from lean core in `init.algebra.classes`, but is missing there. -/ @[elab_simple] lemma antisymm_of' (r : α → α → Prop) [is_antisymm α r] {a b : α} : r a b → r b a → b = a := antisymm' /-- A version of `comm` with `r` explicit. This lemma matches the lemmas from lean core in `init.algebra.classes`, but is missing there. -/ lemma comm_of (r : α → α → Prop) [is_symm α r] {a b : α} : r a b ↔ r b a := comm theorem is_refl.swap (r) [is_refl α r] : is_refl α (swap r) := ⟨refl_of r⟩ theorem is_irrefl.swap (r) [is_irrefl α r] : is_irrefl α (swap r) := ⟨irrefl_of r⟩ theorem is_trans.swap (r) [is_trans α r] : is_trans α (swap r) := ⟨λ a b c h₁ h₂, trans_of r h₂ h₁⟩ theorem is_antisymm.swap (r) [is_antisymm α r] : is_antisymm α (swap r) := ⟨λ a b h₁ h₂, antisymm h₂ h₁⟩ theorem is_asymm.swap (r) [is_asymm α r] : is_asymm α (swap r) := ⟨λ a b h₁ h₂, asymm_of r h₂ h₁⟩ theorem is_total.swap (r) [is_total α r] : is_total α (swap r) := ⟨λ a b, (total_of r a b).swap⟩ theorem is_trichotomous.swap (r) [is_trichotomous α r] : is_trichotomous α (swap r) := ⟨λ a b, by simpa [swap, or.comm, or.left_comm] using trichotomous_of r a b⟩ theorem is_preorder.swap (r) [is_preorder α r] : is_preorder α (swap r) := {..@is_refl.swap α r _, ..@is_trans.swap α r _} theorem is_strict_order.swap (r) [is_strict_order α r] : is_strict_order α (swap r) := {..@is_irrefl.swap α r _, ..@is_trans.swap α r _} theorem is_partial_order.swap (r) [is_partial_order α r] : is_partial_order α (swap r) := {..@is_preorder.swap α r _, ..@is_antisymm.swap α r _} theorem is_total_preorder.swap (r) [is_total_preorder α r] : is_total_preorder α (swap r) := {..@is_preorder.swap α r _, ..@is_total.swap α r _} theorem is_linear_order.swap (r) [is_linear_order α r] : is_linear_order α (swap r) := {..@is_partial_order.swap α r _, ..@is_total.swap α r _} protected theorem is_asymm.is_antisymm (r) [is_asymm α r] : is_antisymm α r := ⟨λ x y h₁ h₂, (asymm h₁ h₂).elim⟩ protected theorem is_asymm.is_irrefl [is_asymm α r] : is_irrefl α r := ⟨λ a h, asymm h h⟩ protected theorem is_total.is_trichotomous (r) [is_total α r] : is_trichotomous α r := ⟨λ a b, or.left_comm.1 (or.inr $ total_of r a b)⟩ @[priority 100] -- see Note [lower instance priority] instance is_total.to_is_refl (r) [is_total α r] : is_refl α r := ⟨λ a, (or_self _).1 $ total_of r a a⟩ lemma ne_of_irrefl {r} [is_irrefl α r] : ∀ {x y : α}, r x y → x ≠ y | _ _ h rfl := irrefl _ h lemma ne_of_irrefl' {r} [is_irrefl α r] : ∀ {x y : α}, r x y → y ≠ x | _ _ h rfl := irrefl _ h lemma trans_trichotomous_left [is_trans α r] [is_trichotomous α r] {a b c : α} : ¬r b a → r b c → r a c := begin intros h₁ h₂, rcases trichotomous_of r a b with h₃|h₃|h₃, exact trans h₃ h₂, rw h₃, exact h₂, exfalso, exact h₁ h₃ end lemma trans_trichotomous_right [is_trans α r] [is_trichotomous α r] {a b c : α} : r a b → ¬r c b → r a c := begin intros h₁ h₂, rcases trichotomous_of r b c with h₃|h₃|h₃, exact trans h₁ h₃, rw ←h₃, exact h₁, exfalso, exact h₂ h₃ end /-- Construct a partial order from a `is_strict_order` relation. See note [reducible non-instances]. -/ @[reducible] def partial_order_of_SO (r) [is_strict_order α r] : partial_order α := { le := λ x y, x = y ∨ r x y, lt := r, le_refl := λ x, or.inl rfl, le_trans := λ x y z h₁ h₂, match y, z, h₁, h₂ with | _, _, or.inl rfl, h₂ := h₂ | _, _, h₁, or.inl rfl := h₁ | _, _, or.inr h₁, or.inr h₂ := or.inr (trans h₁ h₂) end, le_antisymm := λ x y h₁ h₂, match y, h₁, h₂ with | _, or.inl rfl, h₂ := rfl | _, h₁, or.inl rfl := rfl | _, or.inr h₁, or.inr h₂ := (asymm h₁ h₂).elim end, lt_iff_le_not_le := λ x y, ⟨λ h, ⟨or.inr h, not_or (λ e, by rw e at h; exact irrefl _ h) (asymm h)⟩, λ ⟨h₁, h₂⟩, h₁.resolve_left (λ e, h₂ $ e ▸ or.inl rfl)⟩ } /-- This is basically the same as `is_strict_total_order`, but that definition has a redundant assumption `is_incomp_trans α lt`. -/ @[algebra] class is_strict_total_order' (α : Type u) (lt : α → α → Prop) extends is_trichotomous α lt, is_strict_order α lt : Prop. /-- Construct a linear order from an `is_strict_total_order'` relation. See note [reducible non-instances]. -/ @[reducible] def linear_order_of_STO' (r) [is_strict_total_order' α r] [Π x y, decidable (¬ r x y)] : linear_order α := { le_total := λ x y, match y, trichotomous_of r x y with | y, or.inl h := or.inl (or.inr h) | _, or.inr (or.inl rfl) := or.inl (or.inl rfl) | _, or.inr (or.inr h) := or.inr (or.inr h) end, decidable_le := λ x y, decidable_of_iff (¬ r y x) ⟨λ h, ((trichotomous_of r y x).resolve_left h).imp eq.symm id, λ h, h.elim (λ h, h ▸ irrefl_of _ _) (asymm_of r)⟩, ..partial_order_of_SO r } theorem is_strict_total_order'.swap (r) [is_strict_total_order' α r] : is_strict_total_order' α (swap r) := {..is_trichotomous.swap r, ..is_strict_order.swap r} /-! ### Order connection -/ /-- A connected order is one satisfying the condition `a < c → a < b ∨ b < c`. This is recognizable as an intuitionistic substitute for `a ≤ b ∨ b ≤ a` on the constructive reals, and is also known as negative transitivity, since the contrapositive asserts transitivity of the relation `¬ a < b`. -/ @[algebra] class is_order_connected (α : Type u) (lt : α → α → Prop) : Prop := (conn : ∀ a b c, lt a c → lt a b ∨ lt b c) theorem is_order_connected.neg_trans {r : α → α → Prop} [is_order_connected α r] {a b c} (h₁ : ¬ r a b) (h₂ : ¬ r b c) : ¬ r a c := mt (is_order_connected.conn a b c) $ by simp [h₁, h₂] theorem is_strict_weak_order_of_is_order_connected [is_asymm α r] [is_order_connected α r] : is_strict_weak_order α r := { trans := λ a b c h₁ h₂, (is_order_connected.conn _ c _ h₁).resolve_right (asymm h₂), incomp_trans := λ a b c ⟨h₁, h₂⟩ ⟨h₃, h₄⟩, ⟨is_order_connected.neg_trans h₁ h₃, is_order_connected.neg_trans h₄ h₂⟩, ..@is_asymm.is_irrefl α r _ } @[priority 100] -- see Note [lower instance priority] instance is_order_connected_of_is_strict_total_order' [is_strict_total_order' α r] : is_order_connected α r := ⟨λ a b c h, (trichotomous _ _).imp_right (λ o, o.elim (λ e, e ▸ h) (λ h', trans h' h))⟩ @[priority 100] -- see Note [lower instance priority] instance is_strict_total_order_of_is_strict_total_order' [is_strict_total_order' α r] : is_strict_total_order α r := {..is_strict_weak_order_of_is_order_connected} /-! ### Extensional relation -/ /-- An extensional relation is one in which an element is determined by its set of predecessors. It is named for the `x ∈ y` relation in set theory, whose extensionality is one of the first axioms of ZFC. -/ @[algebra] class is_extensional (α : Type u) (r : α → α → Prop) : Prop := (ext : ∀ a b, (∀ x, r x a ↔ r x b) → a = b) @[priority 100] -- see Note [lower instance priority] instance is_extensional_of_is_strict_total_order' [is_strict_total_order' α r] : is_extensional α r := ⟨λ a b H, ((@trichotomous _ r _ a b) .resolve_left $ mt (H _).2 (irrefl a)) .resolve_right $ mt (H _).1 (irrefl b)⟩ /-! ### Well-order -/ /-- A well order is a well-founded linear order. -/ @[algebra] class is_well_order (α : Type u) (r : α → α → Prop) extends is_strict_total_order' α r : Prop := (wf : well_founded r) @[priority 100] -- see Note [lower instance priority] instance is_well_order.is_strict_total_order {α} (r : α → α → Prop) [is_well_order α r] : is_strict_total_order α r := by apply_instance @[priority 100] -- see Note [lower instance priority] instance is_well_order.is_extensional {α} (r : α → α → Prop) [is_well_order α r] : is_extensional α r := by apply_instance @[priority 100] -- see Note [lower instance priority] instance is_well_order.is_trichotomous {α} (r : α → α → Prop) [is_well_order α r] : is_trichotomous α r := by apply_instance @[priority 100] -- see Note [lower instance priority] instance is_well_order.is_trans {α} (r : α → α → Prop) [is_well_order α r] : is_trans α r := by apply_instance @[priority 100] -- see Note [lower instance priority] instance is_well_order.is_irrefl {α} (r : α → α → Prop) [is_well_order α r] : is_irrefl α r := by apply_instance @[priority 100] -- see Note [lower instance priority] instance is_well_order.is_asymm {α} (r : α → α → Prop) [is_well_order α r] : is_asymm α r := by apply_instance /-- Construct a decidable linear order from a well-founded linear order. -/ noncomputable def is_well_order.linear_order (r : α → α → Prop) [is_well_order α r] : linear_order α := by { letI := λ x y, classical.dec (¬r x y), exact linear_order_of_STO' r } instance empty_relation.is_well_order [subsingleton α] : is_well_order α empty_relation := { trichotomous := λ a b, or.inr $ or.inl $ subsingleton.elim _ _, irrefl := λ a, id, trans := λ a b c, false.elim, wf := ⟨λ a, ⟨_, λ y, false.elim⟩⟩ } instance prod.lex.is_well_order [is_well_order α r] [is_well_order β s] : is_well_order (α × β) (prod.lex r s) := { trichotomous := λ ⟨a₁, a₂⟩ ⟨b₁, b₂⟩, match @trichotomous _ r _ a₁ b₁ with | or.inl h₁ := or.inl $ prod.lex.left _ _ h₁ | or.inr (or.inr h₁) := or.inr $ or.inr $ prod.lex.left _ _ h₁ | or.inr (or.inl e) := e ▸ match @trichotomous _ s _ a₂ b₂ with | or.inl h := or.inl $ prod.lex.right _ h | or.inr (or.inr h) := or.inr $ or.inr $ prod.lex.right _ h | or.inr (or.inl e) := e ▸ or.inr $ or.inl rfl end end, irrefl := λ ⟨a₁, a₂⟩ h, by cases h with _ _ _ _ h _ _ _ h; [exact irrefl _ h, exact irrefl _ h], trans := λ a b c h₁ h₂, begin cases h₁ with a₁ a₂ b₁ b₂ ab a₁ b₁ b₂ ab; cases h₂ with _ _ c₁ c₂ bc _ _ c₂ bc, { exact prod.lex.left _ _ (trans ab bc) }, { exact prod.lex.left _ _ ab }, { exact prod.lex.left _ _ bc }, { exact prod.lex.right _ (trans ab bc) } end, wf := prod.lex_wf is_well_order.wf is_well_order.wf } namespace set /-- An unbounded or cofinal set. -/ def unbounded (r : α → α → Prop) (s : set α) : Prop := ∀ a, ∃ b ∈ s, ¬ r b a /-- A bounded or final set. Not to be confused with `metric.bounded`. -/ def bounded (r : α → α → Prop) (s : set α) : Prop := ∃ a, ∀ b ∈ s, r b a @[simp] lemma not_bounded_iff {r : α → α → Prop} (s : set α) : ¬bounded r s ↔ unbounded r s := by simp only [bounded, unbounded, not_forall, not_exists, exists_prop, not_and, not_not] @[simp] lemma not_unbounded_iff {r : α → α → Prop} (s : set α) : ¬unbounded r s ↔ bounded r s := by rw [not_iff_comm, not_bounded_iff] end set namespace prod instance is_refl_preimage_fst {r : α → α → Prop} [h : is_refl α r] : is_refl (α × α) (prod.fst ⁻¹'o r) := ⟨λ a, refl_of r a.1⟩ instance is_refl_preimage_snd {r : α → α → Prop} [h : is_refl α r] : is_refl (α × α) (prod.snd ⁻¹'o r) := ⟨λ a, refl_of r a.2⟩ instance is_trans_preimage_fst {r : α → α → Prop} [h : is_trans α r] : is_trans (α × α) (prod.fst ⁻¹'o r) := ⟨λ _ _ _, trans_of r⟩ instance is_trans_preimage_snd {r : α → α → Prop} [h : is_trans α r] : is_trans (α × α) (prod.snd ⁻¹'o r) := ⟨λ _ _ _, trans_of r⟩ end prod /-! ### Strict-non strict relations -/ /-- An unbundled relation class stating that `r` is the nonstrict relation corresponding to the strict relation `s`. Compare `preorder.lt_iff_le_not_le`. This is mostly meant to provide dot notation on `(⊆)` and `(⊂)`. -/ class is_nonstrict_strict_order (α : Type*) (r s : α → α → Prop) := (right_iff_left_not_left (a b : α) : s a b ↔ r a b ∧ ¬ r b a) lemma right_iff_left_not_left {r s : α → α → Prop} [is_nonstrict_strict_order α r s] {a b : α} : s a b ↔ r a b ∧ ¬ r b a := is_nonstrict_strict_order.right_iff_left_not_left _ _ /-- A version of `right_iff_left_not_left` with explicit `r` and `s`. -/ lemma right_iff_left_not_left_of (r s : α → α → Prop) [is_nonstrict_strict_order α r s] {a b : α} : s a b ↔ r a b ∧ ¬ r b a := right_iff_left_not_left -- The free parameter `r` is strictly speaking not uniquely determined by `s`, but in practice it -- always has a unique instance, so this is not dangerous. @[priority 100, nolint dangerous_instance] -- see Note [lower instance priority] instance is_nonstrict_strict_order.to_is_irrefl {r : α → α → Prop} {s : α → α → Prop} [is_nonstrict_strict_order α r s] : is_irrefl α s := ⟨λ a h, ((right_iff_left_not_left_of r s).1 h).2 ((right_iff_left_not_left_of r s).1 h).1⟩ /-! #### `⊆` and `⊂` -/ section subset variables [has_subset α] {a b c : α} @[refl] lemma subset_refl [is_refl α (⊆)] (a : α) : a ⊆ a := refl _ lemma subset_rfl [is_refl α (⊆)] : a ⊆ a := refl _ lemma subset_of_eq [is_refl α (⊆)] : a = b → a ⊆ b := λ h, h ▸ subset_rfl lemma superset_of_eq [is_refl α (⊆)] : a = b → b ⊆ a := λ h, h ▸ subset_rfl lemma ne_of_not_subset [is_refl α (⊆)] : ¬ a ⊆ b → a ≠ b := mt subset_of_eq lemma ne_of_not_superset [is_refl α (⊆)] : ¬ a ⊆ b → b ≠ a := mt superset_of_eq @[trans] lemma subset_trans [is_trans α (⊆)] (h : a ⊆ b) (h' : b ⊆ c) : a ⊆ c := trans h h' lemma subset_antisymm [is_antisymm α (⊆)] (h : a ⊆ b) (h' : b ⊆ a) : a = b := antisymm h h' lemma superset_antisymm [is_antisymm α (⊆)] (h : a ⊆ b) (h' : b ⊆ a) : b = a := antisymm' h h' alias subset_of_eq ← eq.subset' --TODO: Fix it and kill `eq.subset` alias superset_of_eq ← eq.superset alias subset_trans ← has_subset.subset.trans alias subset_antisymm ← has_subset.subset.antisymm alias superset_antisymm ← has_subset.subset.antisymm' lemma subset_antisymm_iff [is_refl α (⊆)] [is_antisymm α (⊆)] : a = b ↔ a ⊆ b ∧ b ⊆ a := ⟨λ h, ⟨h.subset', h.superset⟩, λ h, h.1.antisymm h.2⟩ lemma superset_antisymm_iff [is_refl α (⊆)] [is_antisymm α (⊆)] : a = b ↔ b ⊆ a ∧ a ⊆ b := ⟨λ h, ⟨h.superset, h.subset'⟩, λ h, h.1.antisymm' h.2⟩ end subset section ssubset variables [has_ssubset α] lemma ssubset_irrefl [is_irrefl α (⊂)] (a : α) : ¬ a ⊂ a := irrefl _ lemma ssubset_irrfl [is_irrefl α (⊂)] {a : α} : ¬ a ⊂ a := irrefl _ lemma ne_of_ssubset [is_irrefl α (⊂)] {a b : α} : a ⊂ b → a ≠ b := ne_of_irrefl lemma ne_of_ssuperset [is_irrefl α (⊂)] {a b : α} : a ⊂ b → b ≠ a := ne_of_irrefl' @[trans] lemma ssubset_trans [is_trans α (⊂)] {a b c : α} (h : a ⊂ b) (h' : b ⊂ c) : a ⊂ c := trans h h' lemma ssubset_asymm [is_asymm α (⊂)] {a b : α} (h : a ⊂ b) : ¬ b ⊂ a := asymm h alias ssubset_irrfl ← has_ssubset.ssubset.false alias ne_of_ssubset ← has_ssubset.ssubset.ne alias ne_of_ssuperset ← has_ssubset.ssubset.ne' alias ssubset_trans ← has_ssubset.ssubset.trans alias ssubset_asymm ← has_ssubset.ssubset.asymm end ssubset section subset_ssubset variables [has_subset α] [has_ssubset α] [is_nonstrict_strict_order α (⊆) (⊂)] {a b c : α} lemma ssubset_iff_subset_not_subset : a ⊂ b ↔ a ⊆ b ∧ ¬ b ⊆ a := right_iff_left_not_left lemma subset_of_ssubset (h : a ⊂ b) : a ⊆ b := (ssubset_iff_subset_not_subset.1 h).1 lemma not_subset_of_ssubset (h : a ⊂ b) : ¬ b ⊆ a := (ssubset_iff_subset_not_subset.1 h).2 lemma not_ssubset_of_subset (h : a ⊆ b) : ¬ b ⊂ a := λ h', not_subset_of_ssubset h' h lemma ssubset_of_subset_not_subset (h₁ : a ⊆ b) (h₂ : ¬ b ⊆ a) : a ⊂ b := ssubset_iff_subset_not_subset.2 ⟨h₁, h₂⟩ alias subset_of_ssubset ← has_ssubset.ssubset.subset alias not_subset_of_ssubset ← has_ssubset.ssubset.not_subset alias not_ssubset_of_subset ← has_subset.subset.not_ssubset alias ssubset_of_subset_not_subset ← has_subset.subset.ssubset_of_not_subset lemma ssubset_of_subset_of_ssubset [is_trans α (⊆)] (h₁ : a ⊆ b) (h₂ : b ⊂ c) : a ⊂ c := (h₁.trans h₂.subset).ssubset_of_not_subset $ λ h, h₂.not_subset $ h.trans h₁ lemma ssubset_of_ssubset_of_subset [is_trans α (⊆)] (h₁ : a ⊂ b) (h₂ : b ⊆ c) : a ⊂ c := (h₁.subset.trans h₂).ssubset_of_not_subset $ λ h, h₁.not_subset $ h₂.trans h lemma ssubset_of_subset_of_ne [is_antisymm α (⊆)] (h₁ : a ⊆ b) (h₂ : a ≠ b) : a ⊂ b := h₁.ssubset_of_not_subset $ mt h₁.antisymm h₂ lemma ssubset_of_ne_of_subset [is_antisymm α (⊆)] (h₁ : a ≠ b) (h₂ : a ⊆ b) : a ⊂ b := ssubset_of_subset_of_ne h₂ h₁ lemma eq_or_ssubset_of_subset [is_antisymm α (⊆)] (h : a ⊆ b) : a = b ∨ a ⊂ b := (em (b ⊆ a)).imp h.antisymm h.ssubset_of_not_subset lemma ssubset_or_eq_of_subset [is_antisymm α (⊆)] (h : a ⊆ b) : a ⊂ b ∨ a = b := (eq_or_ssubset_of_subset h).swap alias ssubset_of_subset_of_ssubset ← has_subset.subset.trans_ssubset alias ssubset_of_ssubset_of_subset ← has_ssubset.ssubset.trans_subset alias ssubset_of_subset_of_ne ← has_subset.subset.ssubset_of_ne alias ssubset_of_ne_of_subset ← ne.ssubset_of_subset alias eq_or_ssubset_of_subset ← has_subset.subset.eq_or_ssubset alias ssubset_or_eq_of_subset ← has_subset.subset.ssubset_or_eq lemma ssubset_iff_subset_ne [is_antisymm α (⊆)] : a ⊂ b ↔ a ⊆ b ∧ a ≠ b := ⟨λ h, ⟨h.subset, h.ne⟩, λ h, h.1.ssubset_of_ne h.2⟩ lemma subset_iff_ssubset_or_eq [is_refl α (⊆)] [is_antisymm α (⊆)] : a ⊆ b ↔ a ⊂ b ∨ a = b := ⟨λ h, h.ssubset_or_eq, λ h, h.elim subset_of_ssubset subset_of_eq⟩ end subset_ssubset /-! ### Conversion of bundled order typeclasses to unbundled relation typeclasses -/ instance [preorder α] : is_refl α (≤) := ⟨le_refl⟩ instance [preorder α] : is_refl α (≥) := is_refl.swap _ instance [preorder α] : is_trans α (≤) := ⟨@le_trans _ _⟩ instance [preorder α] : is_trans α (≥) := is_trans.swap _ instance [preorder α] : is_preorder α (≤) := {} instance [preorder α] : is_preorder α (≥) := {} instance [preorder α] : is_irrefl α (<) := ⟨lt_irrefl⟩ instance [preorder α] : is_irrefl α (>) := is_irrefl.swap _ instance [preorder α] : is_trans α (<) := ⟨@lt_trans _ _⟩ instance [preorder α] : is_trans α (>) := is_trans.swap _ instance [preorder α] : is_asymm α (<) := ⟨@lt_asymm _ _⟩ instance [preorder α] : is_asymm α (>) := is_asymm.swap _ instance [preorder α] : is_antisymm α (<) := is_asymm.is_antisymm _ instance [preorder α] : is_antisymm α (>) := is_asymm.is_antisymm _ instance [preorder α] : is_strict_order α (<) := {} instance [preorder α] : is_strict_order α (>) := {} instance [preorder α] : is_nonstrict_strict_order α (≤) (<) := ⟨@lt_iff_le_not_le _ _⟩ instance [partial_order α] : is_antisymm α (≤) := ⟨@le_antisymm _ _⟩ instance [partial_order α] : is_antisymm α (≥) := is_antisymm.swap _ instance [partial_order α] : is_partial_order α (≤) := {} instance [partial_order α] : is_partial_order α (≥) := {} instance [linear_order α] : is_total α (≤) := ⟨le_total⟩ instance [linear_order α] : is_total α (≥) := is_total.swap _ instance linear_order.is_total_preorder [linear_order α] : is_total_preorder α (≤) := by apply_instance instance [linear_order α] : is_total_preorder α (≥) := {} instance [linear_order α] : is_linear_order α (≤) := {} instance [linear_order α] : is_linear_order α (≥) := {} instance [linear_order α] : is_trichotomous α (<) := ⟨lt_trichotomy⟩ instance [linear_order α] : is_trichotomous α (>) := is_trichotomous.swap _ instance [linear_order α] : is_trichotomous α (≤) := is_total.is_trichotomous _ instance [linear_order α] : is_trichotomous α (≥) := is_total.is_trichotomous _ instance [linear_order α] : is_strict_total_order α (<) := by apply_instance instance [linear_order α] : is_strict_total_order' α (<) := {} instance [linear_order α] : is_order_connected α (<) := by apply_instance instance [linear_order α] : is_incomp_trans α (<) := by apply_instance instance [linear_order α] : is_strict_weak_order α (<) := by apply_instance instance order_dual.is_total_le [has_le α] [is_total α (≤)] : is_total (order_dual α) (≤) := @is_total.swap α _ _ instance nat.lt.is_well_order : is_well_order ℕ (<) := ⟨nat.lt_wf⟩
c563f417154e8529b069dec37b794c2730aca282
acc85b4be2c618b11fc7cb3005521ae6858a8d07
/data/finset/default.lean
3b589b29bda6ed4c78316cecdb7b5f76cabc33ab
[ "Apache-2.0" ]
permissive
linpingchuan/mathlib
d49990b236574df2a45d9919ba43c923f693d341
5ad8020f67eb13896a41cc7691d072c9331b1f76
refs/heads/master
1,626,019,377,808
1,508,048,784,000
1,508,048,784,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
42
lean
import data.finset.basic data.finset.fold
5187182652543afa0ec97ff106fc6f7cae6d7290
02005f45e00c7ecf2c8ca5db60251bd1e9c860b5
/src/data/vector2.lean
7ae79801244bc84e34d925a15281759075f5ee0a
[ "Apache-2.0" ]
permissive
anthony2698/mathlib
03cd69fe5c280b0916f6df2d07c614c8e1efe890
407615e05814e98b24b2ff322b14e8e3eb5e5d67
refs/heads/master
1,678,792,774,873
1,614,371,563,000
1,614,371,563,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
16,306
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import data.vector import data.list.nodup import data.list.of_fn import control.applicative /-! # Additional theorems about the `vector` type This file introduces the infix notation `::ᵥ` for `vector.cons`. -/ universes u variables {n : ℕ} namespace vector variables {α : Type*} infixr `::ᵥ`:67 := vector.cons attribute [simp] head_cons tail_cons instance [inhabited α] : inhabited (vector α n) := ⟨of_fn (λ _, default α)⟩ theorem to_list_injective : function.injective (@to_list α n) := subtype.val_injective /-- Two `v w : vector α n` are equal iff they are equal at every single index. -/ @[ext] theorem ext : ∀ {v w : vector α n} (h : ∀ m : fin n, vector.nth v m = vector.nth w m), v = w | ⟨v, hv⟩ ⟨w, hw⟩ h := subtype.eq (list.ext_le (by rw [hv, hw]) (λ m hm hn, h ⟨m, hv ▸ hm⟩)) /-- The empty `vector` is a `subsingleton`. -/ instance zero_subsingleton : subsingleton (vector α 0) := ⟨λ _ _, vector.ext (λ m, fin.elim0 m)⟩ @[simp] theorem cons_val (a : α) : ∀ (v : vector α n), (a ::ᵥ v).val = a :: v.val | ⟨_, _⟩ := rfl @[simp] theorem cons_head (a : α) : ∀ (v : vector α n), (a ::ᵥ v).head = a | ⟨_, _⟩ := rfl @[simp] theorem cons_tail (a : α) : ∀ (v : vector α n), (a ::ᵥ v).tail = v | ⟨_, _⟩ := rfl @[simp] theorem to_list_of_fn : ∀ {n} (f : fin n → α), to_list (of_fn f) = list.of_fn f | 0 f := rfl | (n+1) f := by rw [of_fn, list.of_fn_succ, to_list_cons, to_list_of_fn] @[simp] theorem mk_to_list : ∀ (v : vector α n) h, (⟨to_list v, h⟩ : vector α n) = v | ⟨l, h₁⟩ h₂ := rfl @[simp] lemma to_list_map {β : Type*} (v : vector α n) (f : α → β) : (v.map f).to_list = v.to_list.map f := by cases v; refl theorem nth_eq_nth_le : ∀ (v : vector α n) (i), nth v i = v.to_list.nth_le i.1 (by rw to_list_length; exact i.2) | ⟨l, h⟩ i := rfl @[simp] lemma nth_map {β : Type*} (v : vector α n) (f : α → β) (i : fin n) : (v.map f).nth i = f (v.nth i) := by simp [nth_eq_nth_le] @[simp] theorem nth_of_fn {n} (f : fin n → α) (i) : nth (of_fn f) i = f i := by rw [nth_eq_nth_le, ← list.nth_le_of_fn f]; congr; apply to_list_of_fn @[simp] theorem of_fn_nth (v : vector α n) : of_fn (nth v) = v := begin rcases v with ⟨l, rfl⟩, apply to_list_injective, change nth ⟨l, eq.refl _⟩ with λ i, nth ⟨l, rfl⟩ i, simpa only [to_list_of_fn] using list.of_fn_nth_le _ end @[simp] theorem nth_tail : ∀ (v : vector α n.succ) (i : fin n), nth (tail v) i = nth v i.succ | ⟨a::l, e⟩ ⟨i, h⟩ := by simp [nth_eq_nth_le]; refl @[simp] theorem tail_val : ∀ (v : vector α n.succ), v.tail.val = v.val.tail | ⟨a::l, e⟩ := rfl /-- The `tail` of a `nil` vector is `nil`. -/ @[simp] lemma tail_nil : (@nil α).tail = nil := rfl /-- The `tail` of a vector made up of one element is `nil`. -/ @[simp] lemma singleton_tail (v : vector α 1) : v.tail = vector.nil := by simp only [←cons_head_tail, eq_iff_true_of_subsingleton] @[simp] theorem tail_of_fn {n : ℕ} (f : fin n.succ → α) : tail (of_fn f) = of_fn (λ i, f i.succ) := (of_fn_nth _).symm.trans $ by congr; funext i; simp /-- The list that makes up a `vector` made up of a single element, retrieved via `to_list`, is equal to the list of that single element. -/ @[simp] lemma to_list_singleton (v : vector α 1) : v.to_list = [v.head] := begin rw ←v.cons_head_tail, simp only [to_list_cons, to_list_nil, cons_head, eq_self_iff_true, and_self, singleton_tail] end /-- Mapping under `id` does not change a vector. -/ @[simp] lemma map_id {n : ℕ} (v : vector α n) : vector.map id v = v := vector.eq _ _ (by simp only [list.map_id, vector.to_list_map]) lemma mem_iff_nth {a : α} {v : vector α n} : a ∈ v.to_list ↔ ∃ i, v.nth i = a := by simp only [list.mem_iff_nth_le, fin.exists_iff, vector.nth_eq_nth_le]; exact ⟨λ ⟨i, hi, h⟩, ⟨i, by rwa to_list_length at hi, h⟩, λ ⟨i, hi, h⟩, ⟨i, by rwa to_list_length, h⟩⟩ lemma nodup_iff_nth_inj {v : vector α n} : v.to_list.nodup ↔ function.injective v.nth := begin cases v with l hl, subst hl, simp only [list.nodup_iff_nth_le_inj], split, { intros h i j hij, cases i, cases j, ext, apply h, simpa }, { intros h i j hi hj hij, have := @h ⟨i, hi⟩ ⟨j, hj⟩, simp [nth_eq_nth_le] at *, tauto } end @[simp] lemma nth_mem (i : fin n) (v : vector α n) : v.nth i ∈ v.to_list := by rw [nth_eq_nth_le]; exact list.nth_le_mem _ _ _ theorem head'_to_list : ∀ (v : vector α n.succ), (to_list v).head' = some (head v) | ⟨a::l, e⟩ := rfl def reverse (v : vector α n) : vector α n := ⟨v.to_list.reverse, by simp⟩ /-- The `list` of a vector after a `reverse`, retrieved by `to_list` is equal to the `list.reverse` after retrieving a vector's `to_list`. -/ lemma to_list_reverse {v : vector α n} : v.reverse.to_list = v.to_list.reverse := rfl @[simp] theorem nth_zero : ∀ (v : vector α n.succ), nth v 0 = head v | ⟨a::l, e⟩ := rfl @[simp] theorem head_of_fn {n : ℕ} (f : fin n.succ → α) : head (of_fn f) = f 0 := by rw [← nth_zero, nth_of_fn] @[simp] theorem nth_cons_zero (a : α) (v : vector α n) : nth (a ::ᵥ v) 0 = a := by simp [nth_zero] /-- Accessing the `nth` element of a vector made up of one element `x : α` is `x` itself. -/ @[simp] lemma nth_cons_nil {ix : fin 1} (x : α) : nth (x ::ᵥ nil) ix = x := by convert nth_cons_zero x nil @[simp] theorem nth_cons_succ (a : α) (v : vector α n) (i : fin n) : nth (a ::ᵥ v) i.succ = nth v i := by rw [← nth_tail, tail_cons] /-- The last element of a `vector`, given that the vector is at least one element. -/ def last (v : vector α (n + 1)) : α := v.nth (fin.last n) /-- The last element of a `vector`, given that the vector is at least one element. -/ lemma last_def {v : vector α (n + 1)} : v.last = v.nth (fin.last n) := rfl /-- The `last` element of a vector is the `head` of the `reverse` vector. -/ lemma reverse_nth_zero {v : vector α (n + 1)} : v.reverse.head = v.last := begin have : 0 = v.to_list.length - 1 - n, { simp only [nat.add_succ_sub_one, add_zero, to_list_length, nat.sub_self, list.length_reverse] }, rw [←nth_zero, last_def, nth_eq_nth_le, nth_eq_nth_le], simp_rw [to_list_reverse, fin.val_eq_coe, fin.coe_last, fin.coe_zero, this], rw list.nth_le_reverse, end section scan variables {β : Type*} variables (f : β → α → β) (b : β) variables (v : vector α n) /-- Construct a `vector β (n + 1)` from a `vector α n` by scanning `f : β → α → β` from the "left", that is, from 0 to `fin.last n`, using `b : β` as the starting value. -/ def scanl : vector β (n + 1) := ⟨list.scanl f b v.to_list, by rw [list.length_scanl, to_list_length]⟩ /-- Providing an empty vector to `scanl` gives the starting value `b : β`. -/ @[simp] lemma scanl_nil : scanl f b nil = b ::ᵥ nil := rfl /-- The recursive step of `scanl` splits a vector `x ::ᵥ v : vector α (n + 1)` into the provided starting value `b : β` and the recursed `scanl` `f b x : β` as the starting value. This lemma is the `cons` version of `scanl_nth`. -/ @[simp] lemma scanl_cons (x : α) : scanl f b (x ::ᵥ v) = b ::ᵥ scanl f (f b x) v := by simpa only [scanl, to_list_cons] /-- The underlying `list` of a `vector` after a `scanl` is the `list.scanl` of the underlying `list` of the original `vector`. -/ @[simp] lemma scanl_val : ∀ {v : vector α n}, (scanl f b v).val = list.scanl f b v.val | ⟨l, hl⟩ := rfl /-- The `to_list` of a `vector` after a `scanl` is the `list.scanl` of the `to_list` of the original `vector`. -/ @[simp] lemma to_list_scanl : (scanl f b v).to_list = list.scanl f b v.to_list := rfl /-- The recursive step of `scanl` splits a vector made up of a single element `x ::ᵥ nil : vector α 1` into a `vector` of the provided starting value `b : β` and the mapped `f b x : β` as the last value. -/ @[simp] lemma scanl_singleton (v : vector α 1) : scanl f b v = b ::ᵥ f b v.head ::ᵥ nil := begin rw [←cons_head_tail v], simp only [scanl_cons, scanl_nil, cons_head, singleton_tail] end /-- The first element of `scanl` of a vector `v : vector α n`, retrieved via `head`, is the starting value `b : β`. -/ @[simp] lemma scanl_head : (scanl f b v).head = b := begin cases n, { have : v = nil := by simp only [eq_iff_true_of_subsingleton], simp only [this, scanl_nil, cons_head] }, { rw ←cons_head_tail v, simp only [←nth_zero, nth_eq_nth_le, to_list_scanl, to_list_cons, list.scanl, fin.val_zero', list.nth_le] } end /-- For an index `i : fin n`, the `nth` element of `scanl` of a vector `v : vector α n` at `i.succ`, is equal to the application function `f : β → α → β` of the `i.cast_succ` element of `scanl f b v` and `nth v i`. This lemma is the `nth` version of `scanl_cons`. -/ @[simp] lemma scanl_nth (i : fin n) : (scanl f b v).nth i.succ = f ((scanl f b v).nth i.cast_succ) (v.nth i) := begin cases n, { exact fin_zero_elim i }, induction n with n hn generalizing b, { have i0 : i = 0 := by simp only [eq_iff_true_of_subsingleton], simpa only [scanl_singleton, i0, nth_zero] }, { rw [←cons_head_tail v, scanl_cons, nth_cons_succ], refine fin.cases _ _ i, { simp only [nth_zero, scanl_head, fin.cast_succ_zero, cons_head] }, { intro i', simp only [hn, fin.cast_succ_fin_succ, nth_cons_succ] } } end end scan def m_of_fn {m} [monad m] {α : Type u} : ∀ {n}, (fin n → m α) → m (vector α n) | 0 f := pure nil | (n+1) f := do a ← f 0, v ← m_of_fn (λi, f i.succ), pure (a ::ᵥ v) theorem m_of_fn_pure {m} [monad m] [is_lawful_monad m] {α} : ∀ {n} (f : fin n → α), @m_of_fn m _ _ _ (λ i, pure (f i)) = pure (of_fn f) | 0 f := rfl | (n+1) f := by simp [m_of_fn, @m_of_fn_pure n, of_fn] def mmap {m} [monad m] {α} {β : Type u} (f : α → m β) : ∀ {n}, vector α n → m (vector β n) | _ ⟨[], rfl⟩ := pure nil | _ ⟨a::l, rfl⟩ := do h' ← f a, t' ← mmap ⟨l, rfl⟩, pure (h' ::ᵥ t') @[simp] theorem mmap_nil {m} [monad m] {α β} (f : α → m β) : mmap f nil = pure nil := rfl @[simp] theorem mmap_cons {m} [monad m] {α β} (f : α → m β) (a) : ∀ {n} (v : vector α n), mmap f (a ::ᵥ v) = do h' ← f a, t' ← mmap f v, pure (h' ::ᵥ t') | _ ⟨l, rfl⟩ := rfl /-- Define `C v` by induction on `v : vector α (n + 1)`, a vector of at least one element. This function has two arguments: `h0` handles the base case on `C nil`, and `hs` defines the inductive step using `∀ x : α, C v → C (x ::ᵥ v)`. -/ @[elab_as_eliminator] def induction_on {α : Type*} {n : ℕ} {C : Π {n : ℕ}, vector α n → Sort*} (v : vector α (n + 1)) (h0 : C nil) (hs : ∀ {n : ℕ} {x : α} {w : vector α n}, C w → C (x ::ᵥ w)) : C v := begin induction n with n hn, { rw ←v.cons_head_tail, convert hs h0 }, { rw ←v.cons_head_tail, apply hs, apply hn } end def to_array : vector α n → array n α | ⟨xs, h⟩ := cast (by rw h) xs.to_array section insert_nth variable {a : α} def insert_nth (a : α) (i : fin (n+1)) (v : vector α n) : vector α (n+1) := ⟨v.1.insert_nth i a, begin rw [list.length_insert_nth, v.2], rw [v.2, ← nat.succ_le_succ_iff], exact i.2 end⟩ lemma insert_nth_val {i : fin (n+1)} {v : vector α n} : (v.insert_nth a i).val = v.val.insert_nth i.1 a := rfl @[simp] lemma remove_nth_val {i : fin n} : ∀{v : vector α n}, (remove_nth i v).val = v.val.remove_nth i | ⟨l, hl⟩ := rfl lemma remove_nth_insert_nth {v : vector α n} {i : fin (n+1)} : remove_nth i (insert_nth a i v) = v := subtype.eq $ list.remove_nth_insert_nth i.1 v.1 lemma remove_nth_insert_nth' {v : vector α (n+1)} : ∀{i : fin (n+1)} {j : fin (n+2)}, remove_nth (j.succ_above i) (insert_nth a j v) = insert_nth a (i.pred_above j) (remove_nth i v) | ⟨i, hi⟩ ⟨j, hj⟩ := begin dsimp [insert_nth, remove_nth, fin.succ_above, fin.pred_above], simp only [subtype.mk_eq_mk], split_ifs, { convert (list.insert_nth_remove_nth_of_ge i (j-1) _ _ _).symm, { convert (nat.succ_pred_eq_of_pos _).symm, exact lt_of_le_of_lt (zero_le _) h, }, { apply remove_nth_val, }, { convert hi, exact v.2, }, { exact nat.le_pred_of_lt h, }, }, { convert (list.insert_nth_remove_nth_of_le i j _ _ _).symm, { apply remove_nth_val, }, { convert hi, exact v.2, }, { simpa using h, }, } end lemma insert_nth_comm (a b : α) (i j : fin (n+1)) (h : i ≤ j) : ∀(v : vector α n), (v.insert_nth a i).insert_nth b j.succ = (v.insert_nth b j).insert_nth a i.cast_succ | ⟨l, hl⟩ := begin refine subtype.eq _, simp only [insert_nth_val, fin.coe_succ, fin.cast_succ, fin.val_eq_coe, fin.coe_cast_add], apply list.insert_nth_comm, { assumption }, { rw hl, exact nat.le_of_succ_le_succ j.2 } end end insert_nth section update_nth /-- `update_nth v n a` replaces the `n`th element of `v` with `a` -/ def update_nth (v : vector α n) (i : fin n) (a : α) : vector α n := ⟨v.1.update_nth i.1 a, by rw [list.update_nth_length, v.2]⟩ @[simp] lemma nth_update_nth_same (v : vector α n) (i : fin n) (a : α) : (v.update_nth i a).nth i = a := by cases v; cases i; simp [vector.update_nth, vector.nth_eq_nth_le] lemma nth_update_nth_of_ne {v : vector α n} {i j : fin n} (h : i ≠ j) (a : α) : (v.update_nth i a).nth j = v.nth j := by cases v; cases i; cases j; simp [vector.update_nth, vector.nth_eq_nth_le, list.nth_le_update_nth_of_ne (fin.vne_of_ne h)] lemma nth_update_nth_eq_if {v : vector α n} {i j : fin n} (a : α) : (v.update_nth i a).nth j = if i = j then a else v.nth j := by split_ifs; try {simp *}; try {rw nth_update_nth_of_ne}; assumption end update_nth end vector namespace vector section traverse variables {F G : Type u → Type u} variables [applicative F] [applicative G] open applicative functor open list (cons) nat private def traverse_aux {α β : Type u} (f : α → F β) : Π (x : list α), F (vector β x.length) | [] := pure vector.nil | (x::xs) := vector.cons <$> f x <*> traverse_aux xs protected def traverse {α β : Type u} (f : α → F β) : vector α n → F (vector β n) | ⟨v, Hv⟩ := cast (by rw Hv) $ traverse_aux f v variables [is_lawful_applicative F] [is_lawful_applicative G] variables {α β γ : Type u} @[simp] protected lemma traverse_def (f : α → F β) (x : α) : ∀ (xs : vector α n), (x ::ᵥ xs).traverse f = cons <$> f x <*> xs.traverse f := by rintro ⟨xs, rfl⟩; refl protected lemma id_traverse : ∀ (x : vector α n), x.traverse id.mk = x := begin rintro ⟨x, rfl⟩, dsimp [vector.traverse, cast], induction x with x xs IH, {refl}, simp! [IH], refl end open function protected lemma comp_traverse (f : β → F γ) (g : α → G β) : ∀ (x : vector α n), vector.traverse (comp.mk ∘ functor.map f ∘ g) x = comp.mk (vector.traverse f <$> vector.traverse g x) := by rintro ⟨x, rfl⟩; dsimp [vector.traverse, cast]; induction x with x xs; simp! [cast, *] with functor_norm; [refl, simp [(∘)]] protected lemma traverse_eq_map_id {α β} (f : α → β) : ∀ (x : vector α n), x.traverse (id.mk ∘ f) = id.mk (map f x) := by rintro ⟨x, rfl⟩; simp!; induction x; simp! * with functor_norm; refl variable (η : applicative_transformation F G) protected lemma naturality {α β : Type*} (f : α → F β) : ∀ (x : vector α n), η (x.traverse f) = x.traverse (@η _ ∘ f) := by rintro ⟨x, rfl⟩; simp! [cast]; induction x with x xs IH; simp! * with functor_norm end traverse instance : traversable.{u} (flip vector n) := { traverse := @vector.traverse n, map := λ α β, @vector.map.{u u} α β n } instance : is_lawful_traversable.{u} (flip vector n) := { id_traverse := @vector.id_traverse n, comp_traverse := @vector.comp_traverse n, traverse_eq_map_id := @vector.traverse_eq_map_id n, naturality := @vector.naturality n, id_map := by intros; cases x; simp! [(<$>)], comp_map := by intros; cases x; simp! [(<$>)] } end vector
0ef98ad90cd0a989480899e4f1d2f74addbd6517
4727251e0cd73359b15b664c3170e5d754078599
/src/combinatorics/colex.lean
202902e53ffb1a497e40746d99533faee00a0b19
[ "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
14,977
lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Alena Gusakov -/ import data.fintype.basic import algebra.geom_sum /-! # Colex We define the colex ordering for finite sets, and give a couple of important lemmas and properties relating to it. The colex ordering likes to avoid large values - it can be thought of on `finset ℕ` as the "binary" ordering. That is, order A based on `∑_{i ∈ A} 2^i`. It's defined here in a slightly more general way, requiring only `has_lt α` in the definition of colex on `finset α`. In the context of the Kruskal-Katona theorem, we are interested in particular on how colex behaves for sets of a fixed size. If the size is 3, colex on ℕ starts 123, 124, 134, 234, 125, 135, 235, 145, 245, 345, ... ## Main statements * `colex.hom_lt_iff`: strictly monotone functions preserve colex * Colex order properties - linearity, decidability and so on. * `forall_lt_of_colex_lt_of_forall_lt`: if A < B in colex, and everything in B is < t, then everything in A is < t. This confirms the idea that an enumeration under colex will exhaust all sets using elements < t before allowing t to be included. * `sum_two_pow_le_iff_lt`: colex for α = ℕ is the same as binary (this also proves binary expansions are unique) ## See also Related files are: * `data.list.lex`: Lexicographic order on lists. * `data.psigma.order`: Lexicographic order on `Σ' i, α i`. * `data.sigma.order`: Lexicographic order on `Σ i, α i`. * `order.lexicographic`: Lexicographic order on `α × β`. ## Tags colex, colexicographic, binary ## References * https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf -/ variable {α : Type*} open finset open_locale big_operators /-- We define this type synonym to refer to the colexicographic ordering on finsets rather than the natural subset ordering. -/ @[derive inhabited] def finset.colex (α) := finset α /-- A convenience constructor to turn a `finset α` into a `finset.colex α`, useful in order to use the colex ordering rather than the subset ordering. -/ def finset.to_colex {α} (s : finset α) : finset.colex α := s @[simp] lemma colex.eq_iff (A B : finset α) : A.to_colex = B.to_colex ↔ A = B := iff.rfl /-- `A` is less than `B` in the colex ordering if the largest thing that's not in both sets is in B. In other words, `max (A ∆ B) ∈ B` (if the maximum exists). -/ instance [has_lt α] : has_lt (finset.colex α) := ⟨λ (A B : finset α), ∃ (k : α), (∀ {x}, k < x → (x ∈ A ↔ x ∈ B)) ∧ k ∉ A ∧ k ∈ B⟩ /-- We can define (≤) in the obvious way. -/ instance [has_lt α] : has_le (finset.colex α) := ⟨λ A B, A < B ∨ A = B⟩ lemma colex.lt_def [has_lt α] (A B : finset α) : A.to_colex < B.to_colex ↔ ∃ k, (∀ {x}, k < x → (x ∈ A ↔ x ∈ B)) ∧ k ∉ A ∧ k ∈ B := iff.rfl lemma colex.le_def [has_lt α] (A B : finset α) : A.to_colex ≤ B.to_colex ↔ A.to_colex < B.to_colex ∨ A = B := iff.rfl /-- If everything in `A` is less than `k`, we can bound the sum of powers. -/ lemma nat.sum_two_pow_lt {k : ℕ} {A : finset ℕ} (h₁ : ∀ {x}, x ∈ A → x < k) : A.sum (pow 2) < 2^k := begin apply lt_of_le_of_lt (sum_le_sum_of_subset (λ t, mem_range.2 ∘ h₁)), have z := geom_sum_mul_add 1 k, rw [geom_sum, mul_one, one_add_one_eq_two] at z, rw ← z, apply nat.lt_succ_self, end namespace colex /-- Strictly monotone functions preserve the colex ordering. -/ lemma hom_lt_iff {β : Type*} [linear_order α] [decidable_eq β] [preorder β] {f : α → β} (h₁ : strict_mono f) (A B : finset α) : (A.image f).to_colex < (B.image f).to_colex ↔ A.to_colex < B.to_colex := begin simp only [colex.lt_def, not_exists, mem_image, exists_prop, not_and], split, { rintro ⟨k, z, q, k', _, rfl⟩, exact ⟨k', λ x hx, by simpa [h₁.injective.eq_iff] using z (h₁ hx), λ t, q _ t rfl, ‹k' ∈ B›⟩ }, rintro ⟨k, z, ka, _⟩, refine ⟨f k, λ x hx, _, _, k, ‹k ∈ B›, rfl⟩, { split, any_goals { rintro ⟨x', hx', rfl⟩, refine ⟨x', _, rfl⟩, rwa ← z _ <|> rwa z _, rwa strict_mono.lt_iff_lt h₁ at hx } }, { simp only [h₁.injective, function.injective.eq_iff], exact λ x hx, ne_of_mem_of_not_mem hx ka } end /-- A special case of `colex.hom_lt_iff` which is sometimes useful. -/ @[simp] lemma hom_fin_lt_iff {n : ℕ} (A B : finset (fin n)) : (A.image (λ i : fin n, (i : ℕ))).to_colex < (B.image (λ i : fin n, (i : ℕ))).to_colex ↔ A.to_colex < B.to_colex := colex.hom_lt_iff (λ x y k, k) _ _ instance [has_lt α] : is_irrefl (finset.colex α) (<) := ⟨λ A h, exists.elim h (λ _ ⟨_,a,b⟩, a b)⟩ @[trans] lemma lt_trans [linear_order α] {a b c : finset.colex α} : a < b → b < c → a < c := begin rintros ⟨k₁, k₁z, notinA, inB⟩ ⟨k₂, k₂z, notinB, inC⟩, cases lt_or_gt_of_ne (ne_of_mem_of_not_mem inB notinB), { refine ⟨k₂, λ x hx, _, by rwa k₁z h, inC⟩, rw ← k₂z hx, apply k₁z (trans h hx) }, { refine ⟨k₁, λ x hx, _, notinA, by rwa ← k₂z h⟩, rw k₁z hx, apply k₂z (trans h hx) } end @[trans] lemma le_trans [linear_order α] (a b c : finset.colex α) : a ≤ b → b ≤ c → a ≤ c := λ AB BC, AB.elim (λ k, BC.elim (λ t, or.inl (lt_trans k t)) (λ t, t ▸ AB)) (λ k, k.symm ▸ BC) instance [linear_order α] : is_trans (finset.colex α) (<) := ⟨λ _ _ _, colex.lt_trans⟩ lemma lt_trichotomy [linear_order α] (A B : finset.colex α) : A < B ∨ A = B ∨ B < A := begin by_cases h₁ : (A = B), { tauto }, rcases (exists_max_image (A \ B ∪ B \ A) id _) with ⟨k, hk, z⟩, { simp only [mem_union, mem_sdiff] at hk, cases hk, { right, right, refine ⟨k, λ t th, _, hk.2, hk.1⟩, specialize z t, by_contra h₂, simp only [mem_union, mem_sdiff, id.def] at z, rw [not_iff, iff_iff_and_or_not_and_not, not_not, and_comm] at h₂, apply not_le_of_lt th (z h₂) }, { left, refine ⟨k, λ t th, _, hk.2, hk.1⟩, specialize z t, by_contra h₃, simp only [mem_union, mem_sdiff, id.def] at z, rw [not_iff, iff_iff_and_or_not_and_not, not_not, and_comm, or_comm] at h₃, apply not_le_of_lt th (z h₃) }, }, rw nonempty_iff_ne_empty, intro a, simp only [union_eq_empty_iff, sdiff_eq_empty_iff_subset] at a, apply h₁ (subset.antisymm a.1 a.2) end instance [linear_order α] : is_trichotomous (finset.colex α) (<) := ⟨lt_trichotomy⟩ instance decidable_lt [linear_order α] : ∀ {A B : finset.colex α}, decidable (A < B) := show ∀ A B : finset α, decidable (A.to_colex < B.to_colex), from λ A B, decidable_of_iff' (∃ (k ∈ B), (∀ x ∈ A ∪ B, k < x → (x ∈ A ↔ x ∈ B)) ∧ k ∉ A) begin rw colex.lt_def, apply exists_congr, simp only [mem_union, exists_prop, or_imp_distrib, and_comm (_ ∈ B), and_assoc], intro k, refine and_congr_left' (forall_congr _), tauto, end instance [linear_order α] : linear_order (finset.colex α) := { le_refl := λ A, or.inr rfl, le_trans := le_trans, le_antisymm := λ A B AB BA, AB.elim (λ k, BA.elim (λ t, (asymm k t).elim) (λ t, t.symm)) id, le_total := λ A B, (lt_trichotomy A B).elim3 (or.inl ∘ or.inl) (or.inl ∘ or.inr) (or.inr ∘ or.inl), decidable_le := λ A B, by apply_instance, decidable_lt := λ A B, by apply_instance, decidable_eq := λ A B, by apply_instance, lt_iff_le_not_le := λ A B, begin split, { intro t, refine ⟨or.inl t, _⟩, rintro (i | rfl), { apply asymm_of _ t i }, { apply irrefl _ t } }, rintro ⟨h₁ | rfl, h₂⟩, { apply h₁ }, apply h₂.elim (or.inr rfl), end, ..finset.colex.has_lt, ..finset.colex.has_le } /-- The instances set up let us infer that `colex.lt` is a strict total order. -/ example [linear_order α] : is_strict_total_order (finset.colex α) (<) := infer_instance /-- Strictly monotone functions preserve the colex ordering. -/ lemma hom_le_iff {β : Type*} [linear_order α] [linear_order β] {f : α → β} (h₁ : strict_mono f) (A B : finset α) : (A.image f).to_colex ≤ (B.image f).to_colex ↔ A.to_colex ≤ B.to_colex := by rw [le_iff_le_iff_lt_iff_lt, hom_lt_iff h₁] /-- A special case of `colex_hom` which is sometimes useful. -/ @[simp] lemma hom_fin_le_iff {n : ℕ} (A B : finset (fin n)) : (A.image (λ i : fin n, (i : ℕ))).to_colex ≤ (B.image (λ i : fin n, (i : ℕ))).to_colex ↔ A.to_colex ≤ B.to_colex := colex.hom_le_iff (λ x y k, k) _ _ /-- If `A` is before `B` in colex, and everything in `B` is small, then everything in `A` is small. -/ lemma forall_lt_of_colex_lt_of_forall_lt [linear_order α] {A B : finset α} (t : α) (h₁ : A.to_colex < B.to_colex) (h₂ : ∀ x ∈ B, x < t) : ∀ x ∈ A, x < t := begin rw colex.lt_def at h₁, rcases h₁ with ⟨k, z, _, _⟩, intros x hx, apply lt_of_not_ge, intro a, refine not_lt_of_ge a (h₂ x _), rwa ← z, apply lt_of_lt_of_le (h₂ k ‹_›) a, end /-- `s.to_colex < {r}.to_colex` iff all elements of `s` are less than `r`. -/ lemma lt_singleton_iff_mem_lt [linear_order α] {r : α} {s : finset α} : s.to_colex < ({r} : finset α).to_colex ↔ ∀ x ∈ s, x < r := begin simp only [lt_def, mem_singleton, ←and_assoc, exists_eq_right], split, { intros t x hx, rw ←not_le, intro h, rcases lt_or_eq_of_le h with h₁ | rfl, { exact ne_of_irrefl h₁ ((t.1 h₁).1 hx).symm }, { exact t.2 hx } }, { exact λ h, ⟨λ z hz, ⟨λ i, (asymm hz (h _ i)).elim, λ i, (hz.ne' i).elim⟩, by simpa using h r⟩ } end /-- If {r} is less than or equal to s in the colexicographical sense, then s contains an element greater than or equal to r. -/ lemma mem_le_of_singleton_le [linear_order α] {r : α} {s : finset α}: ({r} : finset α).to_colex ≤ s.to_colex ↔ ∃ x ∈ s, r ≤ x := by { rw ←not_lt, simp [lt_singleton_iff_mem_lt] } /-- Colex is an extension of the base ordering on α. -/ lemma singleton_lt_iff_lt [linear_order α] {r s : α} : ({r} : finset α).to_colex < ({s} : finset α).to_colex ↔ r < s := by simp [lt_singleton_iff_mem_lt] /-- Colex is an extension of the base ordering on α. -/ lemma singleton_le_iff_le [linear_order α] {r s : α} : ({r} : finset α).to_colex ≤ ({s} : finset α).to_colex ↔ r ≤ s := by rw [le_iff_le_iff_lt_iff_lt, singleton_lt_iff_lt] /-- Colex doesn't care if you remove the other set -/ @[simp] lemma sdiff_lt_sdiff_iff_lt [has_lt α] [decidable_eq α] (A B : finset α) : (A \ B).to_colex < (B \ A).to_colex ↔ A.to_colex < B.to_colex := begin rw [colex.lt_def, colex.lt_def], apply exists_congr, intro k, simp only [mem_sdiff, not_and, not_not], split, { rintro ⟨z, kAB, kB, kA⟩, refine ⟨_, kA, kB⟩, { intros x hx, specialize z hx, tauto } }, { rintro ⟨z, kA, kB⟩, refine ⟨_, λ _, kB, kB, kA⟩, intros x hx, rw z hx }, end /-- Colex doesn't care if you remove the other set -/ @[simp] lemma sdiff_le_sdiff_iff_le [linear_order α] (A B : finset α) : (A \ B).to_colex ≤ (B \ A).to_colex ↔ A.to_colex ≤ B.to_colex := by rw [le_iff_le_iff_lt_iff_lt, sdiff_lt_sdiff_iff_lt] lemma empty_to_colex_lt [linear_order α] {A : finset α} (hA : A.nonempty) : (∅ : finset α).to_colex < A.to_colex := begin rw [colex.lt_def], refine ⟨max' _ hA, _, by simp, max'_mem _ _⟩, simp only [false_iff, not_mem_empty], intros x hx t, apply not_le_of_lt hx (le_max' _ _ t), end /-- If `A ⊂ B`, then `A` is less than `B` in the colex order. Note the converse does not hold, as `⊆` is not a linear order. -/ lemma colex_lt_of_ssubset [linear_order α] {A B : finset α} (h : A ⊂ B) : A.to_colex < B.to_colex := begin rw [←sdiff_lt_sdiff_iff_lt, sdiff_eq_empty_iff_subset.2 h.1], exact empty_to_colex_lt (by simpa [finset.nonempty] using exists_of_ssubset h), end @[simp] lemma empty_to_colex_le [linear_order α] {A : finset α} : (∅ : finset α).to_colex ≤ A.to_colex := begin rcases A.eq_empty_or_nonempty with rfl | hA, { simp }, { apply (empty_to_colex_lt hA).le }, end /-- If `A ⊆ B`, then `A ≤ B` in the colex order. Note the converse does not hold, as `⊆` is not a linear order. -/ lemma colex_le_of_subset [linear_order α] {A B : finset α} (h : A ⊆ B) : A.to_colex ≤ B.to_colex := begin rw [←sdiff_le_sdiff_iff_le, sdiff_eq_empty_iff_subset.2 h], apply empty_to_colex_le end /-- The function from finsets to finsets with the colex order is a relation homomorphism. -/ @[simps] def to_colex_rel_hom [linear_order α] : ((⊆) : finset α → finset α → Prop) →r ((≤) : finset.colex α → finset.colex α → Prop) := { to_fun := finset.to_colex, map_rel' := λ A B, colex_le_of_subset } instance [linear_order α] : order_bot (finset.colex α) := { bot := (∅ : finset α).to_colex, bot_le := λ x, empty_to_colex_le } instance [linear_order α] [fintype α] : order_top (finset.colex α) := { top := finset.univ.to_colex, le_top := λ x, colex_le_of_subset (subset_univ _) } instance [linear_order α] : lattice (finset.colex α) := { ..(by apply_instance : semilattice_sup (finset.colex α)), ..(by apply_instance : semilattice_inf (finset.colex α)) } instance [linear_order α] [fintype α] : bounded_order (finset.colex α) := { ..(by apply_instance : order_top (finset.colex α)), ..(by apply_instance : order_bot (finset.colex α)) } /-- For subsets of ℕ, we can show that colex is equivalent to binary. -/ lemma sum_two_pow_lt_iff_lt (A B : finset ℕ) : ∑ i in A, 2^i < ∑ i in B, 2^i ↔ A.to_colex < B.to_colex := begin have z : ∀ (A B : finset ℕ), A.to_colex < B.to_colex → ∑ i in A, 2^i < ∑ i in B, 2^i, { intros A B, rw [← sdiff_lt_sdiff_iff_lt, colex.lt_def], rintro ⟨k, z, kA, kB⟩, rw ← sdiff_union_inter A B, conv_rhs { rw ← sdiff_union_inter B A }, rw [sum_union (disjoint_sdiff_inter _ _), sum_union (disjoint_sdiff_inter _ _), inter_comm, add_lt_add_iff_right], apply lt_of_lt_of_le (@nat.sum_two_pow_lt k (A \ B) _), { apply single_le_sum (λ _ _, nat.zero_le _) kB }, intros x hx, apply lt_of_le_of_ne (le_of_not_lt (λ kx, _)), { apply (ne_of_mem_of_not_mem hx kA) }, have := (z kx).1 hx, rw mem_sdiff at this hx, exact hx.2 this.1 }, refine ⟨λ h, (lt_trichotomy A B).resolve_right (λ h₁, h₁.elim _ (not_lt_of_gt h ∘ z _ _)), z A B⟩, rintro rfl, apply irrefl _ h end /-- For subsets of ℕ, we can show that colex is equivalent to binary. -/ lemma sum_two_pow_le_iff_lt (A B : finset ℕ) : ∑ i in A, 2^i ≤ ∑ i in B, 2^i ↔ A.to_colex ≤ B.to_colex := by rw [le_iff_le_iff_lt_iff_lt, sum_two_pow_lt_iff_lt] end colex
5d9dac439e18e58c19903cf48feea354c7ac5c61
9b9a16fa2cb737daee6b2785474678b6fa91d6d4
/src/category_theory/limits/limits.lean
82e134687d9fe4787d580ef3f3acfbf70ba507d3
[ "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
26,355
lean
-- Copyright (c) 2018 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Reid Barton, Mario Carneiro, Scott Morrison import category_theory.whiskering import category_theory.yoneda import category_theory.limits.cones open category_theory category_theory.category category_theory.functor namespace category_theory.limits universes v u u' u'' w -- declare the `v`'s first; see `category_theory.category` for an explanation variables {J : Type v} [small_category J] variables {C : Type u} [𝒞 : category.{v} C] include 𝒞 variables {F : J ⥤ C} /-- A cone `t` on `F` is a limit cone if each cone on `F` admits a unique cone morphism to `t`. -/ structure is_limit (t : cone F) := (lift : Π (s : cone F), s.X ⟶ t.X) (fac' : ∀ (s : cone F) (j : J), lift s ≫ t.π.app j = s.π.app j . obviously) (uniq' : ∀ (s : cone F) (m : s.X ⟶ t.X) (w : ∀ j : J, m ≫ t.π.app j = s.π.app j), m = lift s . obviously) restate_axiom is_limit.fac' attribute [simp] is_limit.fac restate_axiom is_limit.uniq' namespace is_limit instance subsingleton {t : cone F} : subsingleton (is_limit t) := ⟨by intros P Q; cases P; cases Q; congr; ext; solve_by_elim⟩ /- Repackaging the definition in terms of cone morphisms. -/ def lift_cone_morphism {t : cone F} (h : is_limit t) (s : cone F) : s ⟶ t := { hom := h.lift s } lemma uniq_cone_morphism {s t : cone F} (h : is_limit t) {f f' : s ⟶ t} : f = f' := have ∀ {g : s ⟶ t}, g = h.lift_cone_morphism s, by intro g; ext; exact h.uniq _ _ g.w, this.trans this.symm def mk_cone_morphism {t : cone F} (lift : Π (s : cone F), s ⟶ t) (uniq' : ∀ (s : cone F) (m : s ⟶ t), m = lift s) : is_limit t := { lift := λ s, (lift s).hom, uniq' := λ s m w, have cone_morphism.mk m w = lift s, by apply uniq', congr_arg cone_morphism.hom this } /-- Limit cones on `F` are unique up to isomorphism. -/ def unique {s t : cone F} (P : is_limit s) (Q : is_limit t) : s ≅ t := { hom := Q.lift_cone_morphism s, inv := P.lift_cone_morphism t, hom_inv_id' := P.uniq_cone_morphism, inv_hom_id' := Q.uniq_cone_morphism } def of_iso_limit {r t : cone F} (P : is_limit r) (i : r ≅ t) : is_limit t := is_limit.mk_cone_morphism (λ s, P.lift_cone_morphism s ≫ i.hom) (λ s m, by rw ←i.comp_inv_eq; apply P.uniq_cone_morphism) variables {t : cone F} lemma hom_lift (h : is_limit t) {W : C} (m : W ⟶ t.X) : m = h.lift { X := W, π := { app := λ b, m ≫ t.π.app b } } := h.uniq { X := W, π := { app := λ b, m ≫ t.π.app b } } m (λ b, rfl) /-- Two morphisms into a limit are equal if their compositions with each cone morphism are equal. -/ lemma hom_ext (h : is_limit t) {W : C} {f f' : W ⟶ t.X} (w : ∀ j, f ≫ t.π.app j = f' ≫ t.π.app j) : f = f' := by rw [h.hom_lift f, h.hom_lift f']; congr; exact funext w /-- The universal property of a limit cone: a map `W ⟶ X` is the same as a cone on `F` with vertex `W`. -/ def hom_iso (h : is_limit t) (W : C) : (W ⟶ t.X) ≅ ((const J).obj W ⟹ F) := { hom := λ f, (t.extend f).π, inv := λ π, h.lift { X := W, π := π }, hom_inv_id' := by ext f; apply h.hom_ext; intro j; simp; dsimp; refl } @[simp] lemma hom_iso_hom (h : is_limit t) {W : C} (f : W ⟶ t.X) : (is_limit.hom_iso h W).hom f = (t.extend f).π := rfl /-- The limit of `F` represents the functor taking `W` to the set of cones on `F` with vertex `W`. -/ def nat_iso (h : is_limit t) : yoneda.obj t.X ≅ F.cones := nat_iso.of_components (λ W, is_limit.hom_iso h (unop W)) (by tidy) def hom_iso' (h : is_limit t) (W : C) : (W ⟶ t.X) ≅ { p : Π j, W ⟶ F.obj j // ∀ {j j'} (f : j ⟶ j'), p j ≫ F.map f = p j' } := h.hom_iso W ≪≫ { hom := λ π, ⟨λ j, π.app j, λ j j' f, by convert ←(π.naturality f).symm; apply id_comp⟩, inv := λ p, { app := λ j, p.1 j, naturality' := λ j j' f, begin dsimp, rw [id_comp], exact (p.2 f).symm end } } /-- If G : C → D is a faithful functor which sends t to a limit cone, then it suffices to check that the induced maps for the image of t can be lifted to maps of C. -/ def of_faithful {t : cone F} {D : Type u'} [category.{v} D] (G : C ⥤ D) [faithful G] (ht : is_limit (G.map_cone t)) (lift : Π (s : cone F), s.X ⟶ t.X) (h : ∀ s, G.map (lift s) = ht.lift (G.map_cone s)) : is_limit t := { lift := lift, fac' := λ s j, by apply G.injectivity; rw [G.map_comp, h]; apply ht.fac, uniq' := λ s m w, begin apply G.injectivity, rw h, refine ht.uniq (G.map_cone s) _ (λ j, _), convert ←congr_arg (λ f, G.map f) (w j), apply G.map_comp end } end is_limit def is_limit_iso_unique_cone_morphism {t : cone F} : is_limit t ≅ Π s, unique (s ⟶ t) := { hom := λ h s, { default := h.lift_cone_morphism s, uniq := λ _, h.uniq_cone_morphism }, inv := λ h, { lift := λ s, (h s).default.hom, uniq' := λ s f w, congr_arg cone_morphism.hom ((h s).uniq ⟨f, w⟩) } } /-- A cocone `t` on `F` is a colimit cocone if each cocone on `F` admits a unique cocone morphism from `t`. -/ structure is_colimit (t : cocone F) := (desc : Π (s : cocone F), t.X ⟶ s.X) (fac' : ∀ (s : cocone F) (j : J), t.ι.app j ≫ desc s = s.ι.app j . obviously) (uniq' : ∀ (s : cocone F) (m : t.X ⟶ s.X) (w : ∀ j : J, t.ι.app j ≫ m = s.ι.app j), m = desc s . obviously) restate_axiom is_colimit.fac' attribute [simp] is_colimit.fac restate_axiom is_colimit.uniq' namespace is_colimit instance subsingleton {t : cocone F} : subsingleton (is_colimit t) := ⟨by intros P Q; cases P; cases Q; congr; ext; solve_by_elim⟩ /- Repackaging the definition in terms of cone morphisms. -/ def desc_cocone_morphism {t : cocone F} (h : is_colimit t) (s : cocone F) : t ⟶ s := { hom := h.desc s } lemma uniq_cocone_morphism {s t : cocone F} (h : is_colimit t) {f f' : t ⟶ s} : f = f' := have ∀ {g : t ⟶ s}, g = h.desc_cocone_morphism s, by intro g; ext; exact h.uniq _ _ g.w, this.trans this.symm def mk_cocone_morphism {t : cocone F} (desc : Π (s : cocone F), t ⟶ s) (uniq' : ∀ (s : cocone F) (m : t ⟶ s), m = desc s) : is_colimit t := { desc := λ s, (desc s).hom, uniq' := λ s m w, have cocone_morphism.mk m w = desc s, by apply uniq', congr_arg cocone_morphism.hom this } /-- Limit cones on `F` are unique up to isomorphism. -/ def unique {s t : cocone F} (P : is_colimit s) (Q : is_colimit t) : s ≅ t := { hom := P.desc_cocone_morphism t, inv := Q.desc_cocone_morphism s, hom_inv_id' := P.uniq_cocone_morphism, inv_hom_id' := Q.uniq_cocone_morphism } def of_iso_colimit {r t : cocone F} (P : is_colimit r) (i : r ≅ t) : is_colimit t := is_colimit.mk_cocone_morphism (λ s, i.inv ≫ P.desc_cocone_morphism s) (λ s m, by rw i.eq_inv_comp; apply P.uniq_cocone_morphism) variables {t : cocone F} lemma hom_desc (h : is_colimit t) {W : C} (m : t.X ⟶ W) : m = h.desc { X := W, ι := { app := λ b, t.ι.app b ≫ m, naturality' := by intros; erw [←assoc, t.ι.naturality, comp_id, comp_id] } } := h.uniq { X := W, ι := { app := λ b, t.ι.app b ≫ m, naturality' := _ } } m (λ b, rfl) /-- Two morphisms out of a colimit are equal if their compositions with each cocone morphism are equal. -/ lemma hom_ext (h : is_colimit t) {W : C} {f f' : t.X ⟶ W} (w : ∀ j, t.ι.app j ≫ f = t.ι.app j ≫ f') : f = f' := by rw [h.hom_desc f, h.hom_desc f']; congr; exact funext w /-- The universal property of a colimit cocone: a map `X ⟶ W` is the same as a cocone on `F` with vertex `W`. -/ def hom_iso (h : is_colimit t) (W : C) : (t.X ⟶ W) ≅ (F ⟹ (const J).obj W) := { hom := λ f, (t.extend f).ι, inv := λ ι, h.desc { X := W, ι := ι }, hom_inv_id' := by ext f; apply h.hom_ext; intro j; simp; dsimp; refl } @[simp] lemma hom_iso_hom (h : is_colimit t) {W : C} (f : t.X ⟶ W) : (is_colimit.hom_iso h W).hom f = (t.extend f).ι := rfl /-- The colimit of `F` represents the functor taking `W` to the set of cocones on `F` with vertex `W`. -/ def nat_iso (h : is_colimit t) : coyoneda.obj (op t.X) ≅ F.cocones := nat_iso.of_components (is_colimit.hom_iso h) (by intros; ext; dsimp; rw ←assoc; refl) def hom_iso' (h : is_colimit t) (W : C) : (t.X ⟶ W) ≅ { p : Π j, F.obj j ⟶ W // ∀ {j j' : J} (f : j ⟶ j'), F.map f ≫ p j' = p j } := h.hom_iso W ≪≫ { hom := λ ι, ⟨λ j, ι.app j, λ j j' f, by convert ←(ι.naturality f); apply comp_id⟩, inv := λ p, { app := λ j, p.1 j, naturality' := λ j j' f, begin dsimp, rw [comp_id], exact (p.2 f) end } } /-- If G : C → D is a faithful functor which sends t to a colimit cocone, then it suffices to check that the induced maps for the image of t can be lifted to maps of C. -/ def of_faithful {t : cocone F} {D : Type u'} [category.{v} D] (G : C ⥤ D) [faithful G] (ht : is_colimit (G.map_cocone t)) (desc : Π (s : cocone F), t.X ⟶ s.X) (h : ∀ s, G.map (desc s) = ht.desc (G.map_cocone s)) : is_colimit t := { desc := desc, fac' := λ s j, by apply G.injectivity; rw [G.map_comp, h]; apply ht.fac, uniq' := λ s m w, begin apply G.injectivity, rw h, refine ht.uniq (G.map_cocone s) _ (λ j, _), convert ←congr_arg (λ f, G.map f) (w j), apply G.map_comp end } end is_colimit def is_colimit_iso_unique_cocone_morphism {t : cocone F} : is_colimit t ≅ Π s, unique (t ⟶ s) := { hom := λ h s, { default := h.desc_cocone_morphism s, uniq := λ _, h.uniq_cocone_morphism }, inv := λ h, { desc := λ s, (h s).default.hom, uniq' := λ s f w, congr_arg cocone_morphism.hom ((h s).uniq ⟨f, w⟩) } } section limit /-- `has_limit F` represents a particular chosen limit of the diagram `F`. -/ class has_limit (F : J ⥤ C) := (cone : cone F) (is_limit : is_limit cone) variables (J C) /-- `C` has limits of shape `J` if we have chosen a particular limit of every functor `F : J ⥤ C`. -/ @[class] def has_limits_of_shape := Π F : J ⥤ C, has_limit F /-- `C` has all (small) limits if it has limits of every shape. -/ @[class] def has_limits := Π {J : Type v} {𝒥 : small_category J}, by exactI has_limits_of_shape J C variables {J C} instance has_limit_of_has_limits_of_shape {J : Type v} [small_category J] [H : has_limits_of_shape J C] (F : J ⥤ C) : has_limit F := H F instance has_limits_of_shape_of_has_limits {J : Type v} [small_category J] [H : has_limits.{v} C] : has_limits_of_shape J C := H /- Interface to the `has_limit` class. -/ def limit.cone (F : J ⥤ C) [has_limit F] : cone F := has_limit.cone F def limit (F : J ⥤ C) [has_limit F] := (limit.cone F).X def limit.π (F : J ⥤ C) [has_limit F] (j : J) : limit F ⟶ F.obj j := (limit.cone F).π.app j @[simp] lemma limit.cone_π {F : J ⥤ C} [has_limit F] (j : J) : (limit.cone F).π.app j = limit.π _ j := rfl @[simp] lemma limit.w (F : J ⥤ C) [has_limit F] {j j' : J} (f : j ⟶ j') : limit.π F j ≫ F.map f = limit.π F j' := (limit.cone F).w f def limit.is_limit (F : J ⥤ C) [has_limit F] : is_limit (limit.cone F) := has_limit.is_limit.{v} F def limit.lift (F : J ⥤ C) [has_limit F] (c : cone F) : c.X ⟶ limit F := (limit.is_limit F).lift c @[simp] lemma limit.is_limit_lift {F : J ⥤ C} [has_limit F] (c : cone F) : (limit.is_limit F).lift c = limit.lift F c := rfl @[simp] lemma limit.lift_π {F : J ⥤ C} [has_limit F] (c : cone F) (j : J) : limit.lift F c ≫ limit.π F j = c.π.app j := is_limit.fac _ c j def limit.cone_morphism {F : J ⥤ C} [has_limit F] (c : cone F) : cone_morphism c (limit.cone F) := (limit.is_limit F).lift_cone_morphism c @[simp] lemma limit.cone_morphism_hom {F : J ⥤ C} [has_limit F] (c : cone F) : (limit.cone_morphism c).hom = limit.lift F c := rfl @[simp] lemma limit.cone_morphism_π {F : J ⥤ C} [has_limit F] (c : cone F) (j : J) : (limit.cone_morphism c).hom ≫ limit.π F j = c.π.app j := by erw is_limit.fac @[extensionality] lemma limit.hom_ext {F : J ⥤ C} [has_limit F] {X : C} {f f' : X ⟶ limit F} (w : ∀ j, f ≫ limit.π F j = f' ≫ limit.π F j) : f = f' := (limit.is_limit F).hom_ext w def limit.hom_iso (F : J ⥤ C) [has_limit F] (W : C) : (W ⟶ limit F) ≅ (F.cones.obj (op W)) := (limit.is_limit F).hom_iso W @[simp] lemma limit.hom_iso_hom (F : J ⥤ C) [has_limit F] {W : C} (f : W ⟶ limit F): (limit.hom_iso F W).hom f = (const J).map f ≫ (limit.cone F).π := (limit.is_limit F).hom_iso_hom f def limit.hom_iso' (F : J ⥤ C) [has_limit F] (W : C) : (W ⟶ limit F) ≅ { p : Π j, W ⟶ F.obj j // ∀ {j j' : J} (f : j ⟶ j'), p j ≫ F.map f = p j' } := (limit.is_limit F).hom_iso' W lemma limit.lift_extend {F : J ⥤ C} [has_limit F] (c : cone F) {X : C} (f : X ⟶ c.X) : limit.lift F (c.extend f) = f ≫ limit.lift F c := by obviously section pre variables {K : Type v} [small_category K] variables (F) [has_limit F] (E : K ⥤ J) [has_limit (E ⋙ F)] def limit.pre : limit F ⟶ limit (E ⋙ F) := limit.lift (E ⋙ F) { X := limit F, π := { app := λ k, limit.π F (E.obj k) } } @[simp] lemma limit.pre_π (k : K) : limit.pre F E ≫ limit.π (E ⋙ F) k = limit.π F (E.obj k) := by erw is_limit.fac @[simp] lemma limit.lift_pre (c : cone F) : limit.lift F c ≫ limit.pre F E = limit.lift (E ⋙ F) (c.whisker E) := by ext; simp variables {L : Type v} [small_category L] variables (D : L ⥤ K) [has_limit (D ⋙ E ⋙ F)] @[simp] lemma limit.pre_pre : limit.pre F E ≫ limit.pre (E ⋙ F) D = limit.pre F (D ⋙ E) := by ext j; erw [assoc, limit.pre_π, limit.pre_π, limit.pre_π]; refl end pre section post variables {D : Type u'} [𝒟 : category.{v} D] include 𝒟 variables (F) [has_limit F] (G : C ⥤ D) [has_limit (F ⋙ G)] def limit.post : G.obj (limit F) ⟶ limit (F ⋙ G) := limit.lift (F ⋙ G) { X := G.obj (limit F), π := { app := λ j, G.map (limit.π F j), naturality' := by intros j j' f; erw [←G.map_comp, limits.cone.w, id_comp]; refl } } @[simp] lemma limit.post_π (j : J) : limit.post F G ≫ limit.π (F ⋙ G) j = G.map (limit.π F j) := by erw is_limit.fac @[simp] lemma limit.lift_post (c : cone F) : G.map (limit.lift F c) ≫ limit.post F G = limit.lift (F ⋙ G) (G.map_cone c) := by ext; rw [assoc, limit.post_π, ←G.map_comp, limit.lift_π, limit.lift_π]; refl @[simp] lemma limit.post_post {E : Type u''} [category.{v} E] (H : D ⥤ E) [has_limit ((F ⋙ G) ⋙ H)] : /- H G (limit F) ⟶ H (limit (F ⋙ G)) ⟶ limit ((F ⋙ G) ⋙ H) equals -/ /- H G (limit F) ⟶ limit (F ⋙ (G ⋙ H)) -/ H.map (limit.post F G) ≫ limit.post (F ⋙ G) H = limit.post F (G ⋙ H) := by ext; erw [assoc, limit.post_π, ←H.map_comp, limit.post_π, limit.post_π]; refl end post lemma limit.pre_post {K : Type v} [small_category K] {D : Type u'} [category.{v} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D) [has_limit F] [has_limit (E ⋙ F)] [has_limit (F ⋙ G)] [has_limit ((E ⋙ F) ⋙ G)] : /- G (limit F) ⟶ G (limit (E ⋙ F)) ⟶ limit ((E ⋙ F) ⋙ G) vs -/ /- G (limit F) ⟶ limit F ⋙ G ⟶ limit (E ⋙ (F ⋙ G)) or -/ G.map (limit.pre F E) ≫ limit.post (E ⋙ F) G = limit.post F G ≫ limit.pre (F ⋙ G) E := by ext; erw [assoc, limit.post_π, ←G.map_comp, limit.pre_π, assoc, limit.pre_π, limit.post_π]; refl section lim_functor variables [has_limits_of_shape J C] /-- `limit F` is functorial in `F`, when `C` has all limits of shape `J`. -/ def lim : (J ⥤ C) ⥤ C := { obj := λ F, limit F, map := λ F G α, limit.lift G { X := limit F, π := { app := λ j, limit.π F j ≫ α.app j, naturality' := λ j j' f, by erw [id_comp, assoc, ←α.naturality, ←assoc, limit.w] } }, map_comp' := λ F G H α β, by ext; erw [assoc, is_limit.fac, is_limit.fac, ←assoc, is_limit.fac, assoc]; refl } variables {F} {G : J ⥤ C} (α : F ⟹ G) @[simp] lemma lim.map_π (j : J) : lim.map α ≫ limit.π G j = limit.π F j ≫ α.app j := by apply is_limit.fac @[simp] lemma limit.lift_map (c : cone F) : limit.lift F c ≫ lim.map α = limit.lift G ((cones.postcompose α).obj c) := by ext; rw [assoc, lim.map_π, ←assoc, limit.lift_π, limit.lift_π]; refl lemma limit.map_pre {K : Type v} [small_category K] [has_limits_of_shape K C] (E : K ⥤ J) : lim.map α ≫ limit.pre G E = limit.pre F E ≫ lim.map (whisker_left E α) := by ext; rw [assoc, limit.pre_π, lim.map_π, assoc, lim.map_π, ←assoc, limit.pre_π]; refl lemma limit.map_pre' {K : Type v} [small_category K] [has_limits_of_shape.{v} K C] (F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟹ E₂) : limit.pre F E₂ = limit.pre F E₁ ≫ lim.map (whisker_right α F) := by ext1; simp [(category.assoc _ _ _ _).symm] lemma limit.id_pre (F : J ⥤ C) : limit.pre F (functor.id _) = lim.map (functor.left_unitor F).inv := by tidy lemma limit.map_post {D : Type u'} [category.{v} D] [has_limits_of_shape J D] (H : C ⥤ D) : /- H (limit F) ⟶ H (limit G) ⟶ limit (G ⋙ H) vs H (limit F) ⟶ limit (F ⋙ H) ⟶ limit (G ⋙ H) -/ H.map (lim.map α) ≫ limit.post G H = limit.post F H ≫ lim.map (whisker_right α H) := begin ext, rw [assoc, limit.post_π, ←H.map_comp, lim.map_π, H.map_comp], rw [assoc, lim.map_π, ←assoc, limit.post_π], refl end def lim_yoneda : lim ⋙ yoneda ≅ category_theory.cones J C := nat_iso.of_components (λ F, nat_iso.of_components (λ W, limit.hom_iso F (unop W)) (by tidy)) (by tidy) end lim_functor end limit section colimit /-- `has_colimit F` represents a particular chosen colimit of the diagram `F`. -/ class has_colimit (F : J ⥤ C) := (cocone : cocone F) (is_colimit : is_colimit cocone) variables (J C) /-- `C` has colimits of shape `J` if we have chosen a particular colimit of every functor `F : J ⥤ C`. -/ @[class] def has_colimits_of_shape := Π F : J ⥤ C, has_colimit F /-- `C` has all (small) colimits if it has limits of every shape. -/ @[class] def has_colimits := Π {J : Type v} {𝒥 : small_category J}, by exactI has_colimits_of_shape J C variables {J C} instance has_colimit_of_has_colimits_of_shape {J : Type v} [small_category J] [H : has_colimits_of_shape J C] (F : J ⥤ C) : has_colimit F := H F instance has_colimits_of_shape_of_has_colimits {J : Type v} [small_category J] [H : has_colimits.{v} C] : has_colimits_of_shape J C := H /- Interface to the `has_colimit` class. -/ def colimit.cocone (F : J ⥤ C) [has_colimit F] : cocone F := has_colimit.cocone F def colimit (F : J ⥤ C) [has_colimit F] := (colimit.cocone F).X def colimit.ι (F : J ⥤ C) [has_colimit F] (j : J) : F.obj j ⟶ colimit F := (colimit.cocone F).ι.app j @[simp] lemma colimit.cocone_ι {F : J ⥤ C} [has_colimit F] (j : J) : (colimit.cocone F).ι.app j = colimit.ι _ j := rfl @[simp] lemma colimit.w (F : J ⥤ C) [has_colimit F] {j j' : J} (f : j ⟶ j') : F.map f ≫ colimit.ι F j' = colimit.ι F j := (colimit.cocone F).w f def colimit.is_colimit (F : J ⥤ C) [has_colimit F] : is_colimit (colimit.cocone F) := has_colimit.is_colimit.{v} F def colimit.desc (F : J ⥤ C) [has_colimit F] (c : cocone F) : colimit F ⟶ c.X := (colimit.is_colimit F).desc c @[simp] lemma colimit.is_colimit_desc {F : J ⥤ C} [has_colimit F] (c : cocone F) : (colimit.is_colimit F).desc c = colimit.desc F c := rfl @[simp] lemma colimit.ι_desc {F : J ⥤ C} [has_colimit F] (c : cocone F) (j : J) : colimit.ι F j ≫ colimit.desc F c = c.ι.app j := is_colimit.fac _ c j def colimit.cocone_morphism {F : J ⥤ C} [has_colimit F] (c : cocone F) : cocone_morphism (colimit.cocone F) c := (colimit.is_colimit F).desc_cocone_morphism c @[simp] lemma colimit.cocone_morphism_hom {F : J ⥤ C} [has_colimit F] (c : cocone F) : (colimit.cocone_morphism c).hom = colimit.desc F c := rfl @[simp] lemma colimit.ι_cocone_morphism {F : J ⥤ C} [has_colimit F] (c : cocone F) (j : J) : colimit.ι F j ≫ (colimit.cocone_morphism c).hom = c.ι.app j := by erw is_colimit.fac @[extensionality] lemma colimit.hom_ext {F : J ⥤ C} [has_colimit F] {X : C} {f f' : colimit F ⟶ X} (w : ∀ j, colimit.ι F j ≫ f = colimit.ι F j ≫ f') : f = f' := (colimit.is_colimit F).hom_ext w def colimit.hom_iso (F : J ⥤ C) [has_colimit F] (W : C) : (colimit F ⟶ W) ≅ (F.cocones.obj W) := (colimit.is_colimit F).hom_iso W @[simp] lemma colimit.hom_iso_hom (F : J ⥤ C) [has_colimit F] {W : C} (f : colimit F ⟶ W): (colimit.hom_iso F W).hom f = (colimit.cocone F).ι ≫ (const J).map f := (colimit.is_colimit F).hom_iso_hom f def colimit.hom_iso' (F : J ⥤ C) [has_colimit F] (W : C) : (colimit F ⟶ W) ≅ { p : Π j, F.obj j ⟶ W // ∀ {j j'} (f : j ⟶ j'), F.map f ≫ p j' = p j } := (colimit.is_colimit F).hom_iso' W lemma colimit.desc_extend (F : J ⥤ C) [has_colimit F] (c : cocone F) {X : C} (f : c.X ⟶ X) : colimit.desc F (c.extend f) = colimit.desc F c ≫ f := begin ext1, simp [category.assoc_symm], refl end section pre variables {K : Type v} [small_category K] variables (F) [has_colimit F] (E : K ⥤ J) [has_colimit (E ⋙ F)] def colimit.pre : colimit (E ⋙ F) ⟶ colimit F := colimit.desc (E ⋙ F) { X := colimit F, ι := { app := λ k, colimit.ι F (E.obj k) } } @[simp] lemma colimit.ι_pre (k : K) : colimit.ι (E ⋙ F) k ≫ colimit.pre F E = colimit.ι F (E.obj k) := by erw is_colimit.fac @[simp] lemma colimit.pre_desc (c : cocone F) : colimit.pre F E ≫ colimit.desc F c = colimit.desc (E ⋙ F) (c.whisker E) := by ext; rw [←assoc, colimit.ι_pre]; simp variables {L : Type v} [small_category L] variables (D : L ⥤ K) [has_colimit (D ⋙ E ⋙ F)] @[simp] lemma colimit.pre_pre : colimit.pre (E ⋙ F) D ≫ colimit.pre F E = colimit.pre F (D ⋙ E) := begin ext j, rw [←assoc, colimit.ι_pre, colimit.ι_pre], letI : has_colimit ((D ⋙ E) ⋙ F) := show has_colimit (D ⋙ E ⋙ F), by apply_instance, exact (colimit.ι_pre F (D ⋙ E) j).symm end end pre section post variables {D : Type u'} [𝒟 : category.{v} D] include 𝒟 variables (F) [has_colimit F] (G : C ⥤ D) [has_colimit (F ⋙ G)] def colimit.post : colimit (F ⋙ G) ⟶ G.obj (colimit F) := colimit.desc (F ⋙ G) { X := G.obj (colimit F), ι := { app := λ j, G.map (colimit.ι F j), naturality' := by intros j j' f; erw [←G.map_comp, limits.cocone.w, comp_id]; refl } } @[simp] lemma colimit.ι_post (j : J) : colimit.ι (F ⋙ G) j ≫ colimit.post F G = G.map (colimit.ι F j) := by erw is_colimit.fac @[simp] lemma colimit.post_desc (c : cocone F) : colimit.post F G ≫ G.map (colimit.desc F c) = colimit.desc (F ⋙ G) (G.map_cocone c) := by ext; rw [←assoc, colimit.ι_post, ←G.map_comp, colimit.ι_desc, colimit.ι_desc]; refl @[simp] lemma colimit.post_post {E : Type u''} [category.{v} E] (H : D ⥤ E) [has_colimit ((F ⋙ G) ⋙ H)] : /- H G (colimit F) ⟶ H (colimit (F ⋙ G)) ⟶ colimit ((F ⋙ G) ⋙ H) equals -/ /- H G (colimit F) ⟶ colimit (F ⋙ (G ⋙ H)) -/ colimit.post (F ⋙ G) H ≫ H.map (colimit.post F G) = colimit.post F (G ⋙ H) := begin ext, rw [←assoc, colimit.ι_post, ←H.map_comp, colimit.ι_post], exact (colimit.ι_post F (G ⋙ H) j).symm end end post lemma colimit.pre_post {K : Type v} [small_category K] {D : Type u'} [category.{v} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D) [has_colimit F] [has_colimit (E ⋙ F)] [has_colimit (F ⋙ G)] [has_colimit ((E ⋙ F) ⋙ G)] : /- G (colimit F) ⟶ G (colimit (E ⋙ F)) ⟶ colimit ((E ⋙ F) ⋙ G) vs -/ /- G (colimit F) ⟶ colimit F ⋙ G ⟶ colimit (E ⋙ (F ⋙ G)) or -/ colimit.post (E ⋙ F) G ≫ G.map (colimit.pre F E) = colimit.pre (F ⋙ G) E ≫ colimit.post F G := begin ext, rw [←assoc, colimit.ι_post, ←G.map_comp, colimit.ι_pre, ←assoc], letI : has_colimit (E ⋙ F ⋙ G) := show has_colimit ((E ⋙ F) ⋙ G), by apply_instance, erw [colimit.ι_pre (F ⋙ G) E j, colimit.ι_post] end section colim_functor variables [has_colimits_of_shape J C] /-- `colimit F` is functorial in `F`, when `C` has all colimits of shape `J`. -/ def colim : (J ⥤ C) ⥤ C := { obj := λ F, colimit F, map := λ F G α, colimit.desc F { X := colimit G, ι := { app := λ j, α.app j ≫ colimit.ι G j, naturality' := λ j j' f, by erw [comp_id, ←assoc, α.naturality, assoc, colimit.w] } }, map_comp' := λ F G H α β, by ext; erw [←assoc, is_colimit.fac, is_colimit.fac, assoc, is_colimit.fac, ←assoc]; refl } variables {F} {G : J ⥤ C} (α : F ⟹ G) @[simp] lemma colim.ι_map (j : J) : colimit.ι F j ≫ colim.map α = α.app j ≫ colimit.ι G j := by apply is_colimit.fac @[simp] lemma colimit.map_desc (c : cocone G) : colim.map α ≫ colimit.desc G c = colimit.desc F ((cocones.precompose α).obj c) := by ext; rw [←assoc, colim.ι_map, assoc, colimit.ι_desc, colimit.ι_desc]; refl lemma colimit.pre_map {K : Type v} [small_category K] [has_colimits_of_shape K C] (E : K ⥤ J) : colimit.pre F E ≫ colim.map α = colim.map (whisker_left E α) ≫ colimit.pre G E := by ext; rw [←assoc, colimit.ι_pre, colim.ι_map, ←assoc, colim.ι_map, assoc, colimit.ι_pre]; refl lemma colimit.pre_map' {K : Type v} [small_category K] [has_colimits_of_shape.{v} K C] (F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟹ E₂) : colimit.pre F E₁ = colim.map (whisker_right α F) ≫ colimit.pre F E₂ := by ext1; simp [(category.assoc _ _ _ _).symm] lemma colimit.pre_id (F : J ⥤ C) : colimit.pre F (functor.id _) = colim.map (functor.left_unitor F).hom := by tidy lemma colimit.map_post {D : Type u'} [category.{v} D] [has_colimits_of_shape J D] (H : C ⥤ D) : /- H (colimit F) ⟶ H (colimit G) ⟶ colimit (G ⋙ H) vs H (colimit F) ⟶ colimit (F ⋙ H) ⟶ colimit (G ⋙ H) -/ colimit.post F H ≫ H.map (colim.map α) = colim.map (whisker_right α H) ≫ colimit.post G H:= begin ext, rw [←assoc, colimit.ι_post, ←H.map_comp, colim.ι_map, H.map_comp], rw [←assoc, colim.ι_map, assoc, colimit.ι_post], refl end def colim_coyoneda : colim.op ⋙ coyoneda ≅ category_theory.cocones J C := nat_iso.of_components (λ F, nat_iso.of_components (colimit.hom_iso (unop F)) (by tidy)) (by {tidy, rw [← category.assoc,← category.assoc], tidy}) end colim_functor end colimit end category_theory.limits
9fdd3747027c3a3e88135b4c4340965d5dd554f5
367134ba5a65885e863bdc4507601606690974c1
/src/ring_theory/valuation/basic.lean
7b250c1cb8df10f0f42c25d0310407b94c7dd6a1
[ "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
23,311
lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Johan Commelin, Patrick Massot -/ import algebra.linear_ordered_comm_group_with_zero import algebra.group_power import ring_theory.ideal.operations import algebra.punit_instances /-! # The basics of valuation theory. The basic theory of valuations (non-archimedean norms) on a commutative ring, following T. Wedhorn's unpublished notes “Adic Spaces” ([wedhorn_adic]). The definition of a valuation we use here is Definition 1.22 of [wedhorn_adic]. A valuation on a ring `R` is a monoid homomorphism `v` to a linearly ordered commutative monoid with zero, that in addition satisfies the following two axioms: * `v 0 = 0` * `∀ x y, v (x + y) ≤ max (v x) (v y)` `valuation R Γ₀`is the type of valuations `R → Γ₀`, with a coercion to the underlying function. If `v` is a valuation from `R` to `Γ₀` then the induced group homomorphism `units(R) → Γ₀` is called `unit_map v`. The equivalence "relation" `is_equiv v₁ v₂ : Prop` defined in 1.27 of [wedhorn_adic] is not strictly speaking a relation, because `v₁ : valuation R Γ₁` and `v₂ : valuation R Γ₂` might not have the same type. This corresponds in ZFC to the set-theoretic difficulty that the class of all valuations (as `Γ₀` varies) on a ring `R` is not a set. The "relation" is however reflexive, symmetric and transitive in the obvious sense. Note that we use 1.27(iii) of [wedhorn_adic] as the definition of equivalence. The support of a valuation `v : valuation R Γ₀` is `supp v`. If `J` is an ideal of `R` with `h : J ⊆ supp v` then the induced valuation on R / J = `ideal.quotient J` is `on_quot v h`. ## Main definitions * `valuation R Γ₀`, the type of valuations on `R` with values in `Γ₀` * `valuation.is_equiv`, the heterogeneous equivalence relation on valuations * `valuation.supp`, the support of a valuation * `add_valuation R Γ₀`, the type of additive valuations on `R` with values in a linearly ordered additive commutative group with a top element, `Γ₀`. ## Implementation Details `add_valuation R Γ₀` is implemented as `valuation R (multiplicative (order_dual Γ₀))`. -/ open_locale classical big_operators noncomputable theory open function ideal -- universes u u₀ u₁ u₂ -- v is used for valuations variables {R : Type*} -- This will be a ring, assumed commutative in some sections set_option old_structure_cmd true section variables (R) (Γ₀ : Type*) [linear_ordered_comm_monoid_with_zero Γ₀] [ring R] /-- The type of `Γ₀`-valued valuations on `R`. -/ @[nolint has_inhabited_instance] structure valuation extends monoid_with_zero_hom R Γ₀ := (map_add' : ∀ x y, to_fun (x + y) ≤ max (to_fun x) (to_fun y)) /-- The `monoid_with_zero_hom` underlying a valuation. -/ add_decl_doc valuation.to_monoid_with_zero_hom end namespace valuation variables {Γ₀ : Type*} variables {Γ'₀ : Type*} variables {Γ''₀ : Type*} [linear_ordered_comm_monoid_with_zero Γ''₀] section basic variables (R) (Γ₀) [ring R] section monoid variables [linear_ordered_comm_monoid_with_zero Γ₀] [linear_ordered_comm_monoid_with_zero Γ'₀] /-- A valuation is coerced to the underlying function `R → Γ₀`. -/ instance : has_coe_to_fun (valuation R Γ₀) := { F := λ _, R → Γ₀, coe := valuation.to_fun } /-- A valuation is coerced to a monoid morphism R → Γ₀. -/ instance : has_coe (valuation R Γ₀) (monoid_with_zero_hom R Γ₀) := ⟨valuation.to_monoid_with_zero_hom⟩ variables {R} {Γ₀} (v : valuation R Γ₀) {x y z : R} @[simp, norm_cast] lemma coe_coe : ((v : monoid_with_zero_hom R Γ₀) : R → Γ₀) = v := rfl @[simp] lemma map_zero : v 0 = 0 := v.map_zero' @[simp] lemma map_one : v 1 = 1 := v.map_one' @[simp] lemma map_mul : ∀ x y, v (x * y) = v x * v y := v.map_mul' @[simp] lemma map_add : ∀ x y, v (x + y) ≤ max (v x) (v y) := v.map_add' lemma map_add_le {x y g} (hx : v x ≤ g) (hy : v y ≤ g) : v (x + y) ≤ g := le_trans (v.map_add x y) $ max_le hx hy lemma map_add_lt {x y g} (hx : v x < g) (hy : v y < g) : v (x + y) < g := lt_of_le_of_lt (v.map_add x y) $ max_lt hx hy lemma map_sum_le {ι : Type*} {s : finset ι} {f : ι → R} {g : Γ₀} (hf : ∀ i ∈ s, v (f i) ≤ g) : v (∑ i in s, f i) ≤ g := begin refine finset.induction_on s (λ _, trans_rel_right (≤) v.map_zero zero_le') (λ a s has ih hf, _) hf, rw finset.forall_mem_insert at hf, rw finset.sum_insert has, exact v.map_add_le hf.1 (ih hf.2) end lemma map_sum_lt {ι : Type*} {s : finset ι} {f : ι → R} {g : Γ₀} (hg : g ≠ 0) (hf : ∀ i ∈ s, v (f i) < g) : v (∑ i in s, f i) < g := begin refine finset.induction_on s (λ _, trans_rel_right (<) v.map_zero (zero_lt_iff.2 hg)) (λ a s has ih hf, _) hf, rw finset.forall_mem_insert at hf, rw finset.sum_insert has, exact v.map_add_lt hf.1 (ih hf.2) end lemma map_sum_lt' {ι : Type*} {s : finset ι} {f : ι → R} {g : Γ₀} (hg : 0 < g) (hf : ∀ i ∈ s, v (f i) < g) : v (∑ i in s, f i) < g := v.map_sum_lt (ne_of_gt hg) hf @[simp] lemma map_pow : ∀ x (n:ℕ), v (x^n) = (v x)^n := v.to_monoid_with_zero_hom.to_monoid_hom.map_pow @[ext] lemma ext {v₁ v₂ : valuation R Γ₀} (h : ∀ r, v₁ r = v₂ r) : v₁ = v₂ := by { cases v₁, cases v₂, congr, funext r, exact h r } lemma ext_iff {v₁ v₂ : valuation R Γ₀} : v₁ = v₂ ↔ ∀ r, v₁ r = v₂ r := ⟨λ h r, congr_arg _ h, ext⟩ -- The following definition is not an instance, because we have more than one `v` on a given `R`. -- In addition, type class inference would not be able to infer `v`. /-- A valuation gives a preorder on the underlying ring. -/ def to_preorder : preorder R := preorder.lift v /-- If `v` is a valuation on a division ring then `v(x) = 0` iff `x = 0`. -/ @[simp] lemma zero_iff [nontrivial Γ₀] {K : Type*} [division_ring K] (v : valuation K Γ₀) {x : K} : v x = 0 ↔ x = 0 := v.to_monoid_with_zero_hom.map_eq_zero lemma ne_zero_iff [nontrivial Γ₀] {K : Type*} [division_ring K] (v : valuation K Γ₀) {x : K} : v x ≠ 0 ↔ x ≠ 0 := v.to_monoid_with_zero_hom.map_ne_zero theorem unit_map_eq (u : units R) : (units.map (v : R →* Γ₀) u : Γ₀) = v u := rfl /-- A ring homomorphism `S → R` induces a map `valuation R Γ₀ → valuation S Γ₀`. -/ def comap {S : Type*} [ring S] (f : S →+* R) (v : valuation R Γ₀) : valuation S Γ₀ := { to_fun := v ∘ f, map_add' := λ x y, by simp only [comp_app, map_add, f.map_add], .. v.to_monoid_with_zero_hom.comp f.to_monoid_with_zero_hom, } @[simp] lemma comap_id : v.comap (ring_hom.id R) = v := ext $ λ r, rfl lemma comap_comp {S₁ : Type*} {S₂ : Type*} [ring S₁] [ring S₂] (f : S₁ →+* S₂) (g : S₂ →+* R) : v.comap (g.comp f) = (v.comap g).comap f := ext $ λ r, rfl /-- A `≤`-preserving group homomorphism `Γ₀ → Γ'₀` induces a map `valuation R Γ₀ → valuation R Γ'₀`. -/ def map (f : monoid_with_zero_hom Γ₀ Γ'₀) (hf : monotone f) (v : valuation R Γ₀) : valuation R Γ'₀ := { to_fun := f ∘ v, map_add' := λ r s, calc f (v (r + s)) ≤ f (max (v r) (v s)) : hf (v.map_add r s) ... = max (f (v r)) (f (v s)) : hf.map_max, .. monoid_with_zero_hom.comp f v.to_monoid_with_zero_hom } /-- Two valuations on `R` are defined to be equivalent if they induce the same preorder on `R`. -/ def is_equiv (v₁ : valuation R Γ₀) (v₂ : valuation R Γ'₀) : Prop := ∀ r s, v₁ r ≤ v₁ s ↔ v₂ r ≤ v₂ s end monoid section group variables [linear_ordered_comm_group_with_zero Γ₀] {R} {Γ₀} (v : valuation R Γ₀) {x y z : R} @[simp] lemma map_inv {K : Type*} [division_ring K] (v : valuation K Γ₀) {x : K} : v x⁻¹ = (v x)⁻¹ := v.to_monoid_with_zero_hom.map_inv' x lemma map_units_inv (x : units R) : v (x⁻¹ : units R) = (v x)⁻¹ := v.to_monoid_with_zero_hom.to_monoid_hom.map_units_inv x @[simp] lemma map_neg (x : R) : v (-x) = v x := v.to_monoid_with_zero_hom.to_monoid_hom.map_neg x lemma map_sub_swap (x y : R) : v (x - y) = v (y - x) := v.to_monoid_with_zero_hom.to_monoid_hom.map_sub_swap x y lemma map_sub_le_max (x y : R) : v (x - y) ≤ max (v x) (v y) := calc v (x - y) = v (x + -y) : by rw [sub_eq_add_neg] ... ≤ max (v x) (v $ -y) : v.map_add _ _ ... = max (v x) (v y) : by rw map_neg lemma map_add_of_distinct_val (h : v x ≠ v y) : v (x + y) = max (v x) (v y) := begin suffices : ¬v (x + y) < max (v x) (v y), from or_iff_not_imp_right.1 (le_iff_eq_or_lt.1 (v.map_add x y)) this, intro h', wlog vyx : v y < v x using x y, { apply lt_or_gt_of_ne h.symm }, { rw max_eq_left_of_lt vyx at h', apply lt_irrefl (v x), calc v x = v ((x+y) - y) : by simp ... ≤ max (v $ x + y) (v y) : map_sub_le_max _ _ _ ... < v x : max_lt h' vyx }, { apply this h.symm, rwa [add_comm, max_comm] at h' } end lemma map_eq_of_sub_lt (h : v (y - x) < v x) : v y = v x := begin have := valuation.map_add_of_distinct_val v (ne_of_gt h).symm, rw max_eq_right (le_of_lt h) at this, simpa using this end end group end basic -- end of section namespace is_equiv variables [ring R] variables [linear_ordered_comm_monoid_with_zero Γ₀] [linear_ordered_comm_monoid_with_zero Γ'₀] variables {v : valuation R Γ₀} variables {v₁ : valuation R Γ₀} {v₂ : valuation R Γ'₀} {v₃ : valuation R Γ''₀} @[refl] lemma refl : v.is_equiv v := λ _ _, iff.refl _ @[symm] lemma symm (h : v₁.is_equiv v₂) : v₂.is_equiv v₁ := λ _ _, iff.symm (h _ _) @[trans] lemma trans (h₁₂ : v₁.is_equiv v₂) (h₂₃ : v₂.is_equiv v₃) : v₁.is_equiv v₃ := λ _ _, iff.trans (h₁₂ _ _) (h₂₃ _ _) lemma of_eq {v' : valuation R Γ₀} (h : v = v') : v.is_equiv v' := by { subst h } lemma map {v' : valuation R Γ₀} (f : monoid_with_zero_hom Γ₀ Γ'₀) (hf : monotone f) (inf : injective f) (h : v.is_equiv v') : (v.map f hf).is_equiv (v'.map f hf) := let H : strict_mono f := strict_mono_of_monotone_of_injective hf inf in λ r s, calc f (v r) ≤ f (v s) ↔ v r ≤ v s : by rw H.le_iff_le ... ↔ v' r ≤ v' s : h r s ... ↔ f (v' r) ≤ f (v' s) : by rw H.le_iff_le /-- `comap` preserves equivalence. -/ lemma comap {S : Type*} [ring S] (f : S →+* R) (h : v₁.is_equiv v₂) : (v₁.comap f).is_equiv (v₂.comap f) := λ r s, h (f r) (f s) lemma val_eq (h : v₁.is_equiv v₂) {r s : R} : v₁ r = v₁ s ↔ v₂ r = v₂ s := by simpa only [le_antisymm_iff] using and_congr (h r s) (h s r) lemma ne_zero (h : v₁.is_equiv v₂) {r : R} : v₁ r ≠ 0 ↔ v₂ r ≠ 0 := begin have : v₁ r ≠ v₁ 0 ↔ v₂ r ≠ v₂ 0 := not_iff_not_of_iff h.val_eq, rwa [v₁.map_zero, v₂.map_zero] at this, end end is_equiv -- end of namespace section lemma is_equiv_of_map_strict_mono [linear_ordered_comm_monoid_with_zero Γ₀] [linear_ordered_comm_monoid_with_zero Γ'₀] [ring R] {v : valuation R Γ₀} (f : monoid_with_zero_hom Γ₀ Γ'₀) (H : strict_mono f) : is_equiv (v.map f (H.monotone)) v := λ x y, ⟨H.le_iff_le.mp, λ h, H.monotone h⟩ lemma is_equiv_of_val_le_one [linear_ordered_comm_group_with_zero Γ₀] [linear_ordered_comm_group_with_zero Γ'₀] {K : Type*} [division_ring K] (v : valuation K Γ₀) (v' : valuation K Γ'₀) (h : ∀ {x:K}, v x ≤ 1 ↔ v' x ≤ 1) : v.is_equiv v' := begin intros x y, by_cases hy : y = 0, { simp [hy, zero_iff], }, rw show y = 1 * y, by rw one_mul, rw [← (inv_mul_cancel_right' hy x)], iterate 2 {rw [v.map_mul _ y, v'.map_mul _ y]}, rw [v.map_one, v'.map_one], split; intro H, { apply mul_le_mul_right', replace hy := v.ne_zero_iff.mpr hy, replace H := le_of_le_mul_right hy H, rwa h at H, }, { apply mul_le_mul_right', replace hy := v'.ne_zero_iff.mpr hy, replace H := le_of_le_mul_right hy H, rwa h, }, end end section supp variables [comm_ring R] variables [linear_ordered_comm_monoid_with_zero Γ₀] [linear_ordered_comm_monoid_with_zero Γ'₀] variables (v : valuation R Γ₀) /-- The support of a valuation `v : R → Γ₀` is the ideal of `R` where `v` vanishes. -/ def supp : ideal R := { carrier := {x | v x = 0}, zero_mem' := map_zero v, add_mem' := λ x y hx hy, le_zero_iff.mp $ calc v (x + y) ≤ max (v x) (v y) : v.map_add x y ... ≤ 0 : max_le (le_zero_iff.mpr hx) (le_zero_iff.mpr hy), smul_mem' := λ c x hx, calc v (c * x) = v c * v x : map_mul v c x ... = v c * 0 : congr_arg _ hx ... = 0 : mul_zero _ } @[simp] lemma mem_supp_iff (x : R) : x ∈ supp v ↔ v x = 0 := iff.rfl -- @[simp] lemma mem_supp_iff' (x : R) : x ∈ (supp v : set R) ↔ v x = 0 := iff.rfl /-- The support of a valuation is a prime ideal. -/ instance [nontrivial Γ₀] [no_zero_divisors Γ₀] : ideal.is_prime (supp v) := ⟨λ (h : v.supp = ⊤), one_ne_zero $ show (1 : Γ₀) = 0, from calc 1 = v 1 : v.map_one.symm ... = 0 : show (1:R) ∈ supp v, by { rw h, trivial }, λ x y hxy, begin show v x = 0 ∨ v y = 0, change v (x * y) = 0 at hxy, rw [v.map_mul x y] at hxy, exact eq_zero_or_eq_zero_of_mul_eq_zero hxy end⟩ lemma map_add_supp (a : R) {s : R} (h : s ∈ supp v) : v (a + s) = v a := begin have aux : ∀ a s, v s = 0 → v (a + s) ≤ v a, { intros a' s' h', refine le_trans (v.map_add a' s') (max_le (le_refl _) _), simp [h'], }, apply le_antisymm (aux a s h), calc v a = v (a + s + -s) : by simp ... ≤ v (a + s) : aux (a + s) (-s) (by rwa ←ideal.neg_mem_iff at h) end /-- If `hJ : J ⊆ supp v` then `on_quot_val hJ` is the induced function on R/J as a function. Note: it's just the function; the valuation is `on_quot hJ`. -/ def on_quot_val {J : ideal R} (hJ : J ≤ supp v) : J.quotient → Γ₀ := λ q, quotient.lift_on' q v $ λ a b h, calc v a = v (b + (a - b)) : by simp ... = v b : v.map_add_supp b (hJ h) /-- The extension of valuation v on R to valuation on R/J if J ⊆ supp v -/ def on_quot {J : ideal R} (hJ : J ≤ supp v) : valuation J.quotient Γ₀ := { to_fun := v.on_quot_val hJ, map_zero' := v.map_zero, map_one' := v.map_one, map_mul' := λ xbar ybar, quotient.ind₂' v.map_mul xbar ybar, map_add' := λ xbar ybar, quotient.ind₂' v.map_add xbar ybar } @[simp] lemma on_quot_comap_eq {J : ideal R} (hJ : J ≤ supp v) : (v.on_quot hJ).comap (ideal.quotient.mk J) = v := ext $ λ r, begin refine @quotient.lift_on_mk _ _ (J.quotient_rel) v (λ a b h, _) _, calc v a = v (b + (a - b)) : by simp ... = v b : v.map_add_supp b (hJ h) end lemma comap_supp {S : Type*} [comm_ring S] (f : S →+* R) : supp (v.comap f) = ideal.comap f v.supp := ideal.ext $ λ x, begin rw [mem_supp_iff, ideal.mem_comap, mem_supp_iff], refl, end lemma self_le_supp_comap (J : ideal R) (v : valuation (quotient J) Γ₀) : J ≤ (v.comap (ideal.quotient.mk J)).supp := by { rw [comap_supp, ← ideal.map_le_iff_le_comap], simp } @[simp] lemma comap_on_quot_eq (J : ideal R) (v : valuation J.quotient Γ₀) : (v.comap (ideal.quotient.mk J)).on_quot (v.self_le_supp_comap J) = v := ext $ by { rintro ⟨x⟩, refl } /-- The quotient valuation on R/J has support supp(v)/J if J ⊆ supp v. -/ lemma supp_quot {J : ideal R} (hJ : J ≤ supp v) : supp (v.on_quot hJ) = (supp v).map (ideal.quotient.mk J) := begin apply le_antisymm, { rintro ⟨x⟩ hx, apply ideal.subset_span, exact ⟨x, hx, rfl⟩ }, { rw ideal.map_le_iff_le_comap, intros x hx, exact hx } end lemma supp_quot_supp : supp (v.on_quot (le_refl _)) = 0 := by { rw supp_quot, exact ideal.map_quotient_self _ } end supp -- end of section end valuation section add_monoid variables (R) [ring R] (Γ₀ : Type*) [linear_ordered_add_comm_monoid_with_top Γ₀] /-- The type of `Γ₀`-valued additive valuations on `R`. -/ @[nolint has_inhabited_instance] def add_valuation := valuation R (multiplicative (order_dual Γ₀)) end add_monoid namespace add_valuation variables {Γ₀ : Type*} [linear_ordered_add_comm_monoid_with_top Γ₀] variables {Γ'₀ : Type*} [linear_ordered_add_comm_monoid_with_top Γ'₀] section basic variables (R) (Γ₀) [ring R] /-- A valuation is coerced to the underlying function `R → Γ₀`. -/ instance : has_coe_to_fun (add_valuation R Γ₀) := { F := λ _, R → Γ₀, coe := valuation.to_fun } variables {R} {Γ₀} (v : add_valuation R Γ₀) {x y z : R} section variables (f : R → Γ₀) (h0 : f 0 = ⊤) (h1 : f 1 = 0) variables (hadd : ∀ x y, min (f x) (f y) ≤ f (x + y)) (hmul : ∀ x y, f (x * y) = f x + f y) /-- An alternate constructor of `add_valuation`, that doesn't reference `multiplicative (order_dual Γ₀)` -/ def of : add_valuation R Γ₀ := { to_fun := f, map_one' := h1, map_zero' := h0, map_add' := hadd, map_mul' := hmul } variables {h0} {h1} {hadd} {hmul} {r : R} @[simp] theorem of_apply : (of f h0 h1 hadd hmul) r = f r := rfl end @[simp] lemma map_zero : v 0 = ⊤ := v.map_zero @[simp] lemma map_one : v 1 = 0 := v.map_one @[simp] lemma map_mul : ∀ x y, v (x * y) = v x + v y := v.map_mul @[simp] lemma map_add : ∀ x y, min (v x) (v y) ≤ v (x + y) := v.map_add lemma map_le_add {x y g} (hx : g ≤ v x) (hy : g ≤ v y) : g ≤ v (x + y) := v.map_add_le hx hy lemma map_lt_add {x y g} (hx : g < v x) (hy : g < v y) : g < v (x + y) := v.map_add_lt hx hy lemma map_le_sum {ι : Type*} {s : finset ι} {f : ι → R} {g : Γ₀} (hf : ∀ i ∈ s, g ≤ v (f i)) : g ≤ v (∑ i in s, f i) := v.map_sum_le hf lemma map_lt_sum {ι : Type*} {s : finset ι} {f : ι → R} {g : Γ₀} (hg : g ≠ ⊤) (hf : ∀ i ∈ s, g < v (f i)) : g < v (∑ i in s, f i) := v.map_sum_lt hg hf lemma map_lt_sum' {ι : Type*} {s : finset ι} {f : ι → R} {g : Γ₀} (hg : g < ⊤) (hf : ∀ i ∈ s, g < v (f i)) : g < v (∑ i in s, f i) := v.map_sum_lt' hg hf @[simp] lemma map_pow : ∀ x (n:ℕ), v (x^n) = n • (v x) := v.map_pow @[ext] lemma ext {v₁ v₂ : add_valuation R Γ₀} (h : ∀ r, v₁ r = v₂ r) : v₁ = v₂ := valuation.ext h lemma ext_iff {v₁ v₂ : add_valuation R Γ₀} : v₁ = v₂ ↔ ∀ r, v₁ r = v₂ r := valuation.ext_iff -- The following definition is not an instance, because we have more than one `v` on a given `R`. -- In addition, type class inference would not be able to infer `v`. /-- A valuation gives a preorder on the underlying ring. -/ def to_preorder : preorder R := preorder.lift v /-- If `v` is an additive valuation on a division ring then `v(x) = ⊤` iff `x = 0`. -/ @[simp] lemma top_iff [nontrivial Γ₀] {K : Type*} [division_ring K] (v : add_valuation K Γ₀) {x : K} : v x = ⊤ ↔ x = 0 := v.zero_iff lemma ne_top_iff [nontrivial Γ₀] {K : Type*} [division_ring K] (v : add_valuation K Γ₀) {x : K} : v x ≠ ⊤ ↔ x ≠ 0 := v.ne_zero_iff /-- A ring homomorphism `S → R` induces a map `add_valuation R Γ₀ → add_valuation S Γ₀`. -/ def comap {S : Type*} [ring S] (f : S →+* R) (v : add_valuation R Γ₀) : add_valuation S Γ₀ := v.comap f @[simp] lemma comap_id : v.comap (ring_hom.id R) = v := v.comap_id lemma comap_comp {S₁ : Type*} {S₂ : Type*} [ring S₁] [ring S₂] (f : S₁ →+* S₂) (g : S₂ →+* R) : v.comap (g.comp f) = (v.comap g).comap f := v.comap_comp f g /-- A `≤`-preserving, `⊤`-preserving group homomorphism `Γ₀ → Γ'₀` induces a map `add_valuation R Γ₀ → add_valuation R Γ'₀`. -/ def map (f : Γ₀ →+ Γ'₀) (ht : f ⊤ = ⊤) (hf : monotone f) (v : add_valuation R Γ₀) : add_valuation R Γ'₀ := v.map { to_fun := f, map_mul' := f.map_add, map_one' := f.map_zero, map_zero' := ht } (λ x y h, hf h) /-- Two additive valuations on `R` are defined to be equivalent if they induce the same preorder on `R`. -/ def is_equiv (v₁ : add_valuation R Γ₀) (v₂ : add_valuation R Γ'₀) : Prop := v₁.is_equiv v₂ end basic namespace is_equiv variables [ring R] variables {Γ''₀ : Type*} [linear_ordered_add_comm_monoid_with_top Γ''₀] variables {v : add_valuation R Γ₀} variables {v₁ : add_valuation R Γ₀} {v₂ : add_valuation R Γ'₀} {v₃ : add_valuation R Γ''₀} @[refl] lemma refl : v.is_equiv v := valuation.is_equiv.refl @[symm] lemma symm (h : v₁.is_equiv v₂) : v₂.is_equiv v₁ := h.symm @[trans] lemma trans (h₁₂ : v₁.is_equiv v₂) (h₂₃ : v₂.is_equiv v₃) : v₁.is_equiv v₃ := h₁₂.trans h₂₃ lemma of_eq {v' : add_valuation R Γ₀} (h : v = v') : v.is_equiv v' := valuation.is_equiv.of_eq h lemma map {v' : add_valuation R Γ₀} (f : Γ₀ →+ Γ'₀) (ht : f ⊤ = ⊤) (hf : monotone f) (inf : injective f) (h : v.is_equiv v') : (v.map f ht hf).is_equiv (v'.map f ht hf) := h.map { to_fun := f, map_mul' := f.map_add, map_one' := f.map_zero, map_zero' := ht } (λ x y h, hf h) inf /-- `comap` preserves equivalence. -/ lemma comap {S : Type*} [ring S] (f : S →+* R) (h : v₁.is_equiv v₂) : (v₁.comap f).is_equiv (v₂.comap f) := h.comap f lemma val_eq (h : v₁.is_equiv v₂) {r s : R} : v₁ r = v₁ s ↔ v₂ r = v₂ s := h.val_eq lemma ne_top (h : v₁.is_equiv v₂) {r : R} : v₁ r ≠ ⊤ ↔ v₂ r ≠ ⊤ := h.ne_zero end is_equiv section supp variables [comm_ring R] variables (v : add_valuation R Γ₀) /-- The support of an additive valuation `v : R → Γ₀` is the ideal of `R` where `v x = ⊤` -/ def supp : ideal R := v.supp @[simp] lemma mem_supp_iff (x : R) : x ∈ supp v ↔ v x = ⊤ := v.mem_supp_iff x lemma map_add_supp (a : R) {s : R} (h : s ∈ supp v) : v (a + s) = v a := v.map_add_supp a h /-- If `hJ : J ⊆ supp v` then `on_quot_val hJ` is the induced function on R/J as a function. Note: it's just the function; the valuation is `on_quot hJ`. -/ def on_quot_val {J : ideal R} (hJ : J ≤ supp v) : J.quotient → Γ₀ := v.on_quot_val hJ /-- The extension of valuation v on R to valuation on R/J if J ⊆ supp v -/ def on_quot {J : ideal R} (hJ : J ≤ supp v) : add_valuation J.quotient Γ₀ := v.on_quot hJ @[simp] lemma on_quot_comap_eq {J : ideal R} (hJ : J ≤ supp v) : (v.on_quot hJ).comap (ideal.quotient.mk J) = v := v.on_quot_comap_eq hJ lemma comap_supp {S : Type*} [comm_ring S] (f : S →+* R) : supp (v.comap f) = ideal.comap f v.supp := v.comap_supp f lemma self_le_supp_comap (J : ideal R) (v : add_valuation (quotient J) Γ₀) : J ≤ (v.comap (ideal.quotient.mk J)).supp := v.self_le_supp_comap J @[simp] lemma comap_on_quot_eq (J : ideal R) (v : add_valuation J.quotient Γ₀) : (v.comap (ideal.quotient.mk J)).on_quot (v.self_le_supp_comap J) = v := v.comap_on_quot_eq J /-- The quotient valuation on R/J has support supp(v)/J if J ⊆ supp v. -/ lemma supp_quot {J : ideal R} (hJ : J ≤ supp v) : supp (v.on_quot hJ) = (supp v).map (ideal.quotient.mk J) := v.supp_quot hJ lemma supp_quot_supp : supp (v.on_quot (le_refl _)) = 0 := v.supp_quot_supp end supp -- end of section end add_valuation
b9208d1b10148f19f081c16019786d7a1961b632
64874bd1010548c7f5a6e3e8902efa63baaff785
/tests/lean/run/tactic26.lean
3530578b565664d6181d4d9249b9111fb4c08a17
[ "Apache-2.0" ]
permissive
tjiaqi/lean
4634d729795c164664d10d093f3545287c76628f
d0ce4cf62f4246b0600c07e074d86e51f2195e30
refs/heads/master
1,622,323,796,480
1,422,643,069,000
1,422,643,069,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
731
lean
import logic data.num open tactic inhabited namespace foo inductive sum (A : Type) (B : Type) : Type := inl : A → sum A B, inr : B → sum A B theorem inl_inhabited {A : Type} (B : Type) (H : inhabited A) : inhabited (sum A B) := inhabited.destruct H (λ a, inhabited.mk (sum.inl B a)) theorem inr_inhabited (A : Type) {B : Type} (H : inhabited B) : inhabited (sum A B) := inhabited.destruct H (λ b, inhabited.mk (sum.inr A b)) definition my_tac := fixpoint (λ t, [ apply @inl_inhabited; t | apply @inr_inhabited; t | apply @num.is_inhabited ]) tactic_hint my_tac theorem T : inhabited (sum false num) end foo
ad280cccc6c1fc2ab5c3d8681dd2502199f6d459
d7189ea2ef694124821b033e533f18905b5e87ef
/galois/bitvec/simplify_eq.lean
f624c43136157a8490425523965f1826dfd4a994
[ "Apache-2.0" ]
permissive
digama0/lean-protocol-support
eaa7e6f8b8e0d5bbfff1f7f52bfb79a3b11b0f59
cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda
refs/heads/master
1,625,421,450,627
1,506,035,462,000
1,506,035,462,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
7,136
lean
/- This module defines lemmas to simplify equalities between literals. -/ import data.bitvec import ..vector namespace bitvec open vector local infix `++`:65 := vector.append section adc_lemmas @[simp] theorem adc_match_def {n : ℕ} (r : bool × bitvec n) : adc._match_1 r = r^.fst :: r^.snd := begin cases r, simp [adc._match_1] end @[simp] theorem adc_empty (x y : bitvec 0) (c : bool) : adc x y c = cons c nil := begin simp [adc, map_accumr₂_nil, adc_match_def], end theorem adc_append1 {n : ℕ} (x : bitvec n) (a : bool) (y : bitvec n) (b : bool) (c : bool) : adc (x ++ cons a nil) (y ++ cons b nil) c = adc x y (bitvec.carry a b c) ++ cons (bitvec.xor3 a b c) nil := begin apply vector.eq, simp [adc, map_accumr₂_append1, adc_match_def] end @[simp] theorem carry_eq (a b : bool) : bitvec.carry a a b = a := begin unfold bitvec.carry, cases a, all_goals { simp } end @[simp] theorem xor3_eq (a b : bool) : bitvec.xor3 a a b = b := begin unfold bitvec.xor3, cases a, all_goals { simp } end theorem adc_zero {n : ℕ} (x : bitvec n) : adc x (repeat ff n) ff = (ff :: x) := begin induction n with n ind, { apply vector.eq, simp [adc_empty], }, { apply (eq.subst (init_append_last_self x)), apply vector.eq, simp [repeat_succ_to_append, adc_append1, bitvec.carry, bitvec.xor3, ind (init x)] } end theorem adc_eq {n : ℕ} (x : bitvec n) (b : bool) : adc x x b = x ++ cons b nil := begin revert b, induction n with n ind, { intro b, apply vector.eq, simp [adc_empty], }, { intro b, apply (eq.subst (init_append_last_self x)), simp [adc_append1, ind (init x)], } end end adc_lemmas section literal_definition_lemmas open nat -- Definition of 0 theorem zero_to_repeat (n : ℕ) : (0 : bitvec n) = repeat ff n := begin refl end theorem one_to_repeat (n : ℕ) : (1 : bitvec (succ n)) = repeat ff n ++ cons tt nil := begin trivial, end theorem bit0_to_repeat {n : ℕ} (x : bitvec (succ n)) : bit0 x = vector.total_tail x ++ cons ff nil := begin unfold bit0, unfold has_add.add bitvec.add, apply vector.eq, simp [adc_eq, list.tail_append], end theorem bit1_to_repeat {n : ℕ} (x : bitvec (succ n)) : bit1 x = vector.total_tail x ++ cons tt nil := begin unfold bit1, unfold has_add.add bitvec.add, apply vector.eq, simp [one_to_repeat, bit0_to_repeat, adc_append1, bitvec.carry, bitvec.xor3], dsimp [nat.succ_sub_one], simp [@adc_zero n (total_tail x)] end end literal_definition_lemmas -- Lemmas about total tail of the natural number literal primitives section total_tail_literal_lemmas @[simp] theorem total_tail_zero (n : ℕ) : vector.total_tail (0 : bitvec n) = 0 := begin apply vector.eq, simp [zero_to_repeat, vector.to_list_total_tail, list.tail_repeat], end @[simp] theorem total_tail_one (n : ℕ) : vector.total_tail (1 : bitvec n) = 1 := begin -- Case for n = 0 cases n with n, simp, -- Case for n = 1 cases n with n, simp, -- Case for n ≥ 2 { apply vector.eq, unfold has_one.one, trivial, } end @[simp] theorem total_tail_bit0 {n : ℕ} (x : bitvec n) : vector.total_tail (bit0 x) = bit0 (vector.total_tail x) := begin -- Case for n = 0 cases n with n, { simp }, -- Case for n = 1 cases n with n, { simp }, -- Case for n ≥ 2 { apply vector.eq, simp [bit0_to_repeat, list.tail_append, vector.length_to_list] } end @[simp] theorem total_tail_bit1 {n : ℕ} (x : bitvec n) : vector.total_tail (bit1 x : bitvec n) = bit1 (vector.total_tail x) := begin -- Case for n = 0 cases n with n, { simp }, -- Case for n = 1 cases n with n, { simp }, -- Case for n ≥ 2 { apply vector.eq, simp [bit1_to_repeat, list.tail_append, vector.length_to_list], } end end total_tail_literal_lemmas -- Simplification lemmas for bitvector literals section literal_simplification_literals -- This tactic simplifies the bitvector equalitiy lemmas private meta def simp_bvlit_rule : tactic unit := do let lemmas : list expr := [ -- Core lemmas expr.const `and_true [] , expr.const `true_and [] , expr.const `and_false [] , expr.const `false_and [] , expr.const `eq_self_iff_true [level.of_nat 1] , expr.const `tt_eq_ff_eq_false [] , expr.const `ff_eq_tt_eq_false [] -- Natural number lemmas , expr.const `nat.not_succ_eq_zero [] , expr.const `nat.not_zero_eq_succ [] , expr.const `nat.succ_sub_succ [] -- Vector lemmas , expr.const `vector.repeat_succ_to_append [] , expr.const `vector.zero_vec_always_eq [level.of_nat 0] , expr.const `vector.cons_eq_cons [level.of_nat 0] , expr.const `vector.append_eq_append [level.of_nat 0] , expr.const `bitvec.zero_to_repeat [] , expr.const `bitvec.one_to_repeat [] , expr.const `bitvec.bit0_to_repeat [] , expr.const `bitvec.bit1_to_repeat [] ] in do s ← simp_lemmas.mk.append lemmas, tactic.simp_target s, tactic.try (tactic.reflexivity) @[simp] theorem zero_eq_one (n : ℕ) : (0 : bitvec n) = 1 ↔ n = 0 := begin cases n, all_goals { simp_bvlit_rule } end @[simp] theorem zero_eq_bit0 {n : ℕ} (y : bitvec n) : (0 : bitvec n) = bit0 y ↔ 0 = vector.total_tail y := begin cases n, all_goals { simp_bvlit_rule } end @[simp] theorem zero_eq_bit1 {n : ℕ} (y : bitvec n) : (0 : bitvec n) = bit1 y ↔ n = 0 := begin cases n, all_goals { simp_bvlit_rule } end @[simp] theorem one_eq_zero (n : ℕ) : (1 : bitvec n) = 0 ↔ n = 0 := begin cases n, all_goals { simp_bvlit_rule } end @[simp] theorem one_eq_bit0 {n : ℕ} (y : bitvec n) : (1 : bitvec n) = bit0 y ↔ n = 0 := begin cases n, all_goals { simp_bvlit_rule } end @[simp] theorem one_eq_bit1 {n : ℕ} (y : bitvec n) : (1 : bitvec n) = bit1 y ↔ 0 = vector.total_tail y := begin cases n, all_goals { simp_bvlit_rule } end @[simp] theorem bit0_eq_zero {n : ℕ} (x : bitvec n) : bit0 x = 0 ↔ vector.total_tail x = 0 := begin cases n, all_goals { simp_bvlit_rule } end @[simp] theorem bit0_eq_one {n : ℕ} (x : bitvec n) : bit0 x = 1 ↔ n = 0 := begin cases n, all_goals { simp_bvlit_rule } end @[simp] theorem bit0_eq_bit0 {n : ℕ} (x y : bitvec n) : bit0 x = bit0 y ↔ vector.total_tail x = vector.total_tail y := begin cases n, all_goals { simp_bvlit_rule } end @[simp] theorem bit0_eq_bit1 {n : ℕ} (x y : bitvec n) : bit0 x = bit1 y ↔ n = 0 := begin cases n, all_goals { simp_bvlit_rule } end @[simp] theorem bit1_eq_zero {n : ℕ} (x : bitvec n) : bit1 x = 0 ↔ n = 0 := begin cases n, all_goals { simp_bvlit_rule } end @[simp] theorem bit1_eq_one {n : ℕ} (x : bitvec n) : bit1 x = 1 ↔ vector.total_tail x = 0 := begin cases n, all_goals { simp_bvlit_rule } end @[simp] theorem bit1_eq_bit0 {n : ℕ} (x y : bitvec n) : bit1 x = bit0 y ↔ n = 0 := begin cases n, all_goals { simp_bvlit_rule } end @[simp] theorem bit1_eq_bit1 {n : ℕ} (x y : bitvec n) : bit1 x = bit1 y ↔ vector.total_tail x = vector.total_tail y := begin cases n, all_goals { simp_bvlit_rule } end end literal_simplification_literals end bitvec
3581d60cb9214acb9d9fe656016283e054b7d3fc
9dc8cecdf3c4634764a18254e94d43da07142918
/src/ring_theory/jacobson_ideal.lean
9c39a2caf299f204d78f06667924752c8ab823b0
[ "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
14,823
lean
/- Copyright (c) 2020 Devon Tuma. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Devon Tuma -/ import ring_theory.ideal.quotient import ring_theory.polynomial.basic /-! # Jacobson radical The Jacobson radical of a ring `R` is defined to be the intersection of all maximal ideals of `R`. This is similar to how the nilradical is equal to the intersection of all prime ideals of `R`. We can extend the idea of the nilradical to ideals of `R`, by letting the radical of an ideal `I` be the intersection of prime ideals containing `I`. Under this extension, the original nilradical is the radical of the zero ideal `⊥`. Here we define the Jacobson radical of an ideal `I` in a similar way, as the intersection of maximal ideals containing `I`. ## Main definitions Let `R` be a commutative ring, and `I` be an ideal of `R` * `jacobson I` is the jacobson radical, i.e. the infimum of all maximal ideals containing I. * `is_local I` is the proposition that the jacobson radical of `I` is itself a maximal ideal ## Main statements * `mem_jacobson_iff` gives a characterization of members of the jacobson of I * `is_local_of_is_maximal_radical`: if the radical of I is maximal then so is the jacobson radical ## Tags Jacobson, Jacobson radical, Local Ideal -/ universes u v namespace ideal variables {R : Type u} {S : Type v} open_locale polynomial section jacobson section ring variables [ring R] [ring S] {I : ideal R} /-- The Jacobson radical of `I` is the infimum of all maximal (left) ideals containing `I`. -/ def jacobson (I : ideal R) : ideal R := Inf {J : ideal R | I ≤ J ∧ is_maximal J} lemma le_jacobson : I ≤ jacobson I := λ x hx, mem_Inf.mpr (λ J hJ, hJ.left hx) @[simp] lemma jacobson_idem : jacobson (jacobson I) = jacobson I := le_antisymm (Inf_le_Inf (λ J hJ, ⟨Inf_le hJ, hJ.2⟩)) le_jacobson @[simp] lemma jacobson_top : jacobson (⊤ : ideal R) = ⊤ := eq_top_iff.2 le_jacobson @[simp] theorem jacobson_eq_top_iff : jacobson I = ⊤ ↔ I = ⊤ := ⟨λ H, classical.by_contradiction $ λ hi, let ⟨M, hm, him⟩ := exists_le_maximal I hi in lt_top_iff_ne_top.1 (lt_of_le_of_lt (show jacobson I ≤ M, from Inf_le ⟨him, hm⟩) $ lt_top_iff_ne_top.2 hm.ne_top) H, λ H, eq_top_iff.2 $ le_Inf $ λ J ⟨hij, hj⟩, H ▸ hij⟩ lemma jacobson_eq_bot : jacobson I = ⊥ → I = ⊥ := λ h, eq_bot_iff.mpr (h ▸ le_jacobson) lemma jacobson_eq_self_of_is_maximal [H : is_maximal I] : I.jacobson = I := le_antisymm (Inf_le ⟨le_of_eq rfl, H⟩) le_jacobson @[priority 100] instance jacobson.is_maximal [H : is_maximal I] : is_maximal (jacobson I) := ⟨⟨λ htop, H.1.1 (jacobson_eq_top_iff.1 htop), λ J hJ, H.1.2 _ (lt_of_le_of_lt le_jacobson hJ)⟩⟩ theorem mem_jacobson_iff {x : R} : x ∈ jacobson I ↔ ∀ y, ∃ z, z * y * x + z - 1 ∈ I := ⟨λ hx y, classical.by_cases (assume hxy : I ⊔ span {y * x + 1} = ⊤, let ⟨p, hpi, q, hq, hpq⟩ := submodule.mem_sup.1 ((eq_top_iff_one _).1 hxy) in let ⟨r, hr⟩ := mem_span_singleton'.1 hq in ⟨r, by rw [mul_assoc, ←mul_add_one, hr, ← hpq, ← neg_sub, add_sub_cancel]; exact I.neg_mem hpi⟩) (assume hxy : I ⊔ span {y * x + 1} ≠ ⊤, let ⟨M, hm1, hm2⟩ := exists_le_maximal _ hxy in suffices x ∉ M, from (this $ mem_Inf.1 hx ⟨le_trans le_sup_left hm2, hm1⟩).elim, λ hxm, hm1.1.1 $ (eq_top_iff_one _).2 $ add_sub_cancel' (y * x) 1 ▸ M.sub_mem (le_sup_right.trans hm2 $ subset_span rfl) (M.mul_mem_left _ hxm)), λ hx, mem_Inf.2 $ λ M ⟨him, hm⟩, classical.by_contradiction $ λ hxm, let ⟨y, i, hi, df⟩ := hm.exists_inv hxm, ⟨z, hz⟩ := hx (-y) in hm.1.1 $ (eq_top_iff_one _).2 $ sub_sub_cancel (z * -y * x + z) 1 ▸ M.sub_mem (by { rw [mul_assoc, ←mul_add_one, neg_mul, ← (sub_eq_iff_eq_add.mpr df.symm), neg_sub, sub_add_cancel], exact M.mul_mem_left _ hi }) (him hz)⟩ lemma exists_mul_sub_mem_of_sub_one_mem_jacobson {I : ideal R} (r : R) (h : r - 1 ∈ jacobson I) : ∃ s, s * r - 1 ∈ I := begin cases mem_jacobson_iff.1 h 1 with s hs, use s, simpa [mul_sub] using hs end /-- An ideal equals its Jacobson radical iff it is the intersection of a set of maximal ideals. Allowing the set to include ⊤ is equivalent, and is included only to simplify some proofs. -/ theorem eq_jacobson_iff_Inf_maximal : I.jacobson = I ↔ ∃ M : set (ideal R), (∀ J ∈ M, is_maximal J ∨ J = ⊤) ∧ I = Inf M := begin use λ hI, ⟨{J : ideal R | I ≤ J ∧ J.is_maximal}, ⟨λ _ hJ, or.inl hJ.right, hI.symm⟩⟩, rintros ⟨M, hM, hInf⟩, refine le_antisymm (λ x hx, _) le_jacobson, rw [hInf, mem_Inf], intros I hI, cases hM I hI with is_max is_top, { exact (mem_Inf.1 hx) ⟨le_Inf_iff.1 (le_of_eq hInf) I hI, is_max⟩ }, { exact is_top.symm ▸ submodule.mem_top } end theorem eq_jacobson_iff_Inf_maximal' : I.jacobson = I ↔ ∃ M : set (ideal R), (∀ (J ∈ M) (K : ideal R), J < K → K = ⊤) ∧ I = Inf M := eq_jacobson_iff_Inf_maximal.trans ⟨λ h, let ⟨M, hM⟩ := h in ⟨M, ⟨λ J hJ K hK, or.rec_on (hM.1 J hJ) (λ h, h.1.2 K hK) (λ h, eq_top_iff.2 (le_of_lt (h ▸ hK))), hM.2⟩⟩, λ h, let ⟨M, hM⟩ := h in ⟨M, ⟨λ J hJ, or.rec_on (classical.em (J = ⊤)) (λ h, or.inr h) (λ h, or.inl ⟨⟨h, hM.1 J hJ⟩⟩), hM.2⟩⟩⟩ /-- An ideal `I` equals its Jacobson radical if and only if every element outside `I` also lies outside of a maximal ideal containing `I`. -/ lemma eq_jacobson_iff_not_mem : I.jacobson = I ↔ ∀ x ∉ I, ∃ M : ideal R, (I ≤ M ∧ M.is_maximal) ∧ x ∉ M := begin split, { intros h x hx, erw [← h, mem_Inf] at hx, push_neg at hx, exact hx }, { refine λ h, le_antisymm (λ x hx, _) le_jacobson, contrapose hx, erw mem_Inf, push_neg, exact h x hx } end theorem map_jacobson_of_surjective {f : R →+* S} (hf : function.surjective f) : ring_hom.ker f ≤ I → map f (I.jacobson) = (map f I).jacobson := begin intro h, unfold ideal.jacobson, have : ∀ J ∈ {J : ideal R | I ≤ J ∧ J.is_maximal}, f.ker ≤ J := λ J hJ, le_trans h hJ.left, refine trans (map_Inf hf this) (le_antisymm _ _), { refine Inf_le_Inf (λ J hJ, ⟨comap f J, ⟨⟨le_comap_of_map_le hJ.1, _⟩, map_comap_of_surjective f hf J⟩⟩), haveI : J.is_maximal := hJ.right, exact comap_is_maximal_of_surjective f hf }, { refine Inf_le_Inf_of_subset_insert_top (λ j hj, hj.rec_on (λ J hJ, _)), rw ← hJ.2, cases map_eq_top_or_is_maximal_of_surjective f hf hJ.left.right with htop hmax, { exact htop.symm ▸ set.mem_insert ⊤ _ }, { exact set.mem_insert_of_mem ⊤ ⟨map_mono hJ.1.1, hmax⟩ } }, end lemma map_jacobson_of_bijective {f : R →+* S} (hf : function.bijective f) : map f (I.jacobson) = (map f I).jacobson := map_jacobson_of_surjective hf.right (le_trans (le_of_eq (f.injective_iff_ker_eq_bot.1 hf.left)) bot_le) lemma comap_jacobson {f : R →+* S} {K : ideal S} : comap f (K.jacobson) = Inf (comap f '' {J : ideal S | K ≤ J ∧ J.is_maximal}) := trans (comap_Inf' f _) (Inf_eq_infi).symm theorem comap_jacobson_of_surjective {f : R →+* S} (hf : function.surjective f) {K : ideal S} : comap f (K.jacobson) = (comap f K).jacobson := begin unfold ideal.jacobson, refine le_antisymm _ _, { refine le_trans (comap_mono (le_of_eq (trans top_inf_eq.symm Inf_insert.symm))) _, rw [comap_Inf', Inf_eq_infi], refine infi_le_infi_of_subset (λ J hJ, _), have : comap f (map f J) = J := trans (comap_map_of_surjective f hf J) (le_antisymm (sup_le_iff.2 ⟨le_of_eq rfl, le_trans (comap_mono bot_le) hJ.left⟩) le_sup_left), cases map_eq_top_or_is_maximal_of_surjective _ hf hJ.right with htop hmax, { refine ⟨⊤, ⟨set.mem_insert ⊤ _, htop ▸ this⟩⟩ }, { refine ⟨map f J, ⟨set.mem_insert_of_mem _ ⟨le_map_of_comap_le_of_surjective f hf hJ.1, hmax⟩, this⟩⟩ } }, { rw comap_Inf, refine le_infi_iff.2 (λ J, (le_infi_iff.2 (λ hJ, _))), haveI : J.is_maximal := hJ.right, refine Inf_le ⟨comap_mono hJ.left, comap_is_maximal_of_surjective _ hf⟩ } end @[mono] lemma jacobson_mono {I J : ideal R} : I ≤ J → I.jacobson ≤ J.jacobson := begin intros h x hx, erw mem_Inf at ⊢ hx, exact λ K ⟨hK, hK_max⟩, hx ⟨trans h hK, hK_max⟩ end end ring section comm_ring variables [comm_ring R] [comm_ring S] {I : ideal R} lemma radical_le_jacobson : radical I ≤ jacobson I := le_Inf (λ J hJ, (radical_eq_Inf I).symm ▸ Inf_le ⟨hJ.left, is_maximal.is_prime hJ.right⟩) lemma eq_radical_of_eq_jacobson : jacobson I = I → radical I = I := λ h, le_antisymm (le_trans radical_le_jacobson (le_of_eq h)) le_radical lemma is_unit_of_sub_one_mem_jacobson_bot (r : R) (h : r - 1 ∈ jacobson (⊥ : ideal R)) : is_unit r := begin cases exists_mul_sub_mem_of_sub_one_mem_jacobson r h with s hs, rw [mem_bot, sub_eq_zero, mul_comm] at hs, exact is_unit_of_mul_eq_one _ _ hs end lemma mem_jacobson_bot {x : R} : x ∈ jacobson (⊥ : ideal R) ↔ ∀ y, is_unit (x * y + 1) := ⟨λ hx y, let ⟨z, hz⟩ := (mem_jacobson_iff.1 hx) y in is_unit_iff_exists_inv.2 ⟨z, by rwa [add_mul, one_mul, ← sub_eq_zero, mul_right_comm, mul_comm _ z, mul_right_comm]⟩, λ h, mem_jacobson_iff.mpr (λ y, (let ⟨b, hb⟩ := is_unit_iff_exists_inv.1 (h y) in ⟨b, (submodule.mem_bot R).2 (hb ▸ (by ring))⟩))⟩ /-- An ideal `I` of `R` is equal to its Jacobson radical if and only if the Jacobson radical of the quotient ring `R/I` is the zero ideal -/ theorem jacobson_eq_iff_jacobson_quotient_eq_bot : I.jacobson = I ↔ jacobson (⊥ : ideal (R ⧸ I)) = ⊥ := begin have hf : function.surjective (quotient.mk I) := submodule.quotient.mk_surjective I, split, { intro h, replace h := congr_arg (map (quotient.mk I)) h, rw map_jacobson_of_surjective hf (le_of_eq mk_ker) at h, simpa using h }, { intro h, replace h := congr_arg (comap (quotient.mk I)) h, rw [comap_jacobson_of_surjective hf, ← (quotient.mk I).ker_eq_comap_bot] at h, simpa using h } end /-- The standard radical and Jacobson radical of an ideal `I` of `R` are equal if and only if the nilradical and Jacobson radical of the quotient ring `R/I` coincide -/ theorem radical_eq_jacobson_iff_radical_quotient_eq_jacobson_bot : I.radical = I.jacobson ↔ radical (⊥ : ideal (R ⧸ I)) = jacobson ⊥ := begin have hf : function.surjective (quotient.mk I) := submodule.quotient.mk_surjective I, split, { intro h, have := congr_arg (map (quotient.mk I)) h, rw [map_radical_of_surjective hf (le_of_eq mk_ker), map_jacobson_of_surjective hf (le_of_eq mk_ker)] at this, simpa using this }, { intro h, have := congr_arg (comap (quotient.mk I)) h, rw [comap_radical, comap_jacobson_of_surjective hf, ← (quotient.mk I).ker_eq_comap_bot] at this, simpa using this } end lemma jacobson_radical_eq_jacobson : I.radical.jacobson = I.jacobson := le_antisymm (le_trans (le_of_eq (congr_arg jacobson (radical_eq_Inf I))) (Inf_le_Inf (λ J hJ, ⟨Inf_le ⟨hJ.1, hJ.2.is_prime⟩, hJ.2⟩))) (jacobson_mono le_radical) end comm_ring end jacobson section polynomial open polynomial variables [comm_ring R] lemma jacobson_bot_polynomial_le_Inf_map_maximal : jacobson (⊥ : ideal R[X]) ≤ Inf (map (C : R →+* R[X]) '' {J : ideal R | J.is_maximal}) := begin refine le_Inf (λ J, exists_imp_distrib.2 (λ j hj, _)), haveI : j.is_maximal := hj.1, refine trans (jacobson_mono bot_le) (le_of_eq _ : J.jacobson ≤ J), suffices : (⊥ : ideal (polynomial (R ⧸ j))).jacobson = ⊥, { rw [← hj.2, jacobson_eq_iff_jacobson_quotient_eq_bot], replace this := congr_arg (map (polynomial_quotient_equiv_quotient_polynomial j).to_ring_hom) this, rwa [map_jacobson_of_bijective _, map_bot] at this, exact (ring_equiv.bijective (polynomial_quotient_equiv_quotient_polynomial j)) }, refine eq_bot_iff.2 (λ f hf, _), simpa [(λ hX, by simpa using congr_arg (λ f, coeff f 1) hX : (X : (R ⧸ j)[X]) ≠ 0)] using eq_C_of_degree_eq_zero (degree_eq_zero_of_is_unit ((mem_jacobson_bot.1 hf) X)), end lemma jacobson_bot_polynomial_of_jacobson_bot (h : jacobson (⊥ : ideal R) = ⊥) : jacobson (⊥ : ideal R[X]) = ⊥ := begin refine eq_bot_iff.2 (le_trans jacobson_bot_polynomial_le_Inf_map_maximal _), refine (λ f hf, ((submodule.mem_bot _).2 (polynomial.ext (λ n, trans _ (coeff_zero n).symm)))), suffices : f.coeff n ∈ ideal.jacobson ⊥, by rwa [h, submodule.mem_bot] at this, exact mem_Inf.2 (λ j hj, (mem_map_C_iff.1 ((mem_Inf.1 hf) ⟨j, ⟨hj.2, rfl⟩⟩)) n), end end polynomial section is_local variables [comm_ring R] /-- An ideal `I` is local iff its Jacobson radical is maximal. -/ class is_local (I : ideal R) : Prop := (out : is_maximal (jacobson I)) theorem is_local_iff {I : ideal R} : is_local I ↔ is_maximal (jacobson I) := ⟨λ h, h.1, λ h, ⟨h⟩⟩ theorem is_local_of_is_maximal_radical {I : ideal R} (hi : is_maximal (radical I)) : is_local I := ⟨have radical I = jacobson I, from le_antisymm (le_Inf $ λ M ⟨him, hm⟩, hm.is_prime.radical_le_iff.2 him) (Inf_le ⟨le_radical, hi⟩), show is_maximal (jacobson I), from this ▸ hi⟩ theorem is_local.le_jacobson {I J : ideal R} (hi : is_local I) (hij : I ≤ J) (hj : J ≠ ⊤) : J ≤ jacobson I := let ⟨M, hm, hjm⟩ := exists_le_maximal J hj in le_trans hjm $ le_of_eq $ eq.symm $ hi.1.eq_of_le hm.1.1 $ Inf_le ⟨le_trans hij hjm, hm⟩ theorem is_local.mem_jacobson_or_exists_inv {I : ideal R} (hi : is_local I) (x : R) : x ∈ jacobson I ∨ ∃ y, y * x - 1 ∈ I := classical.by_cases (assume h : I ⊔ span {x} = ⊤, let ⟨p, hpi, q, hq, hpq⟩ := submodule.mem_sup.1 ((eq_top_iff_one _).1 h) in let ⟨r, hr⟩ := mem_span_singleton.1 hq in or.inr ⟨r, by rw [← hpq, mul_comm, ← hr, ← neg_sub, add_sub_cancel]; exact I.neg_mem hpi⟩) (assume h : I ⊔ span {x} ≠ ⊤, or.inl $ le_trans le_sup_right (hi.le_jacobson le_sup_left h) $ mem_span_singleton.2 $ dvd_refl x) end is_local theorem is_primary_of_is_maximal_radical [comm_ring R] {I : ideal R} (hi : is_maximal (radical I)) : is_primary I := have radical I = jacobson I, from le_antisymm (le_Inf $ λ M ⟨him, hm⟩, hm.is_prime.radical_le_iff.2 him) (Inf_le ⟨le_radical, hi⟩), ⟨ne_top_of_lt $ lt_of_le_of_lt le_radical (lt_top_iff_ne_top.2 hi.1.1), λ x y hxy, ((is_local_of_is_maximal_radical hi).mem_jacobson_or_exists_inv y).symm.imp (λ ⟨z, hz⟩, by rw [← mul_one x, ← sub_sub_cancel (z * y) 1, mul_sub, mul_left_comm]; exact I.sub_mem (I.mul_mem_left _ hxy) (I.mul_mem_left _ hz)) (this ▸ id)⟩ end ideal
7d4dbd2954c366025c0fc85a223c974d1c4436f9
4bcaca5dc83d49803f72b7b5920b75b6e7d9de2d
/src/Lean/Server/FileWorker/RequestHandling.lean
ae5237ad671e32b39c66f48ff0ea60186eef45ac
[ "Apache-2.0" ]
permissive
subfish-zhou/leanprover-zh_CN.github.io
30b9fba9bd790720bd95764e61ae796697d2f603
8b2985d4a3d458ceda9361ac454c28168d920d3f
refs/heads/master
1,689,709,967,820
1,632,503,056,000
1,632,503,056,000
409,962,097
1
0
null
null
null
null
UTF-8
Lean
false
false
18,025
lean
/- Copyright (c) 2021 Wojciech Nawrocki. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Wojciech Nawrocki, Marc Huisinga -/ import Lean.DeclarationRange import Lean.Data.Json import Lean.Data.Lsp import Lean.Server.FileWorker.Utils import Lean.Server.Requests import Lean.Server.Completion import Lean.Widget.InteractiveGoal namespace Lean.Server.FileWorker open Lsp open RequestM open Snapshots partial def handleCompletion (p : CompletionParams) : RequestM (RequestTask CompletionList) := do let doc ← readDoc let text := doc.meta.text let pos := text.lspPosToUtf8Pos p.position -- dbg_trace ">> handleCompletion invoked {pos}" -- NOTE: use `>=` since the cursor can be *after* the input withWaitFindSnap doc (fun s => s.endPos >= pos) (notFoundX := pure { items := #[], isIncomplete := true }) fun snap => do for infoTree in snap.cmdState.infoState.trees do -- for (ctx, info) in infoTree.getCompletionInfos do -- dbg_trace "{← info.format ctx}" if let some r ← Completion.find? doc.meta.text pos infoTree then return r return { items := #[ ], isIncomplete := true } open Elab in partial def handleHover (p : HoverParams) : RequestM (RequestTask (Option Hover)) := do let doc ← readDoc let text := doc.meta.text let mkHover (s : String) (f : String.Pos) (t : String.Pos) : Hover := { contents := { kind := MarkupKind.markdown value := s } range? := some { start := text.utf8PosToLspPos f «end» := text.utf8PosToLspPos t } } let hoverPos := text.lspPosToUtf8Pos p.position withWaitFindSnap doc (fun s => s.endPos > hoverPos) (notFoundX := pure none) fun snap => do for t in snap.cmdState.infoState.trees do if let some (ci, i) := t.hoverableInfoAt? hoverPos then if let some hoverFmt ← i.fmtHover? ci then return some <| mkHover (toString hoverFmt) i.pos?.get! i.tailPos?.get! return none inductive GoToKind | declaration | definition | type deriving BEq open Elab GoToKind in partial def handleDefinition (kind : GoToKind) (p : TextDocumentPositionParams) : RequestM (RequestTask (Array LocationLink)) := do let rc ← read let doc ← readDoc let text := doc.meta.text let hoverPos := text.lspPosToUtf8Pos p.position let locationLinksFromDecl (i : Elab.Info) (n : Name) := do let mod? ← findModuleOf? n let modUri? ← match mod? with | some modName => let modFname? ← rc.srcSearchPath.findWithExt "lean" modName pure <| modFname?.map toFileUri | none => pure <| some doc.meta.uri let ranges? ← findDeclarationRanges? n if let (some ranges, some modUri) := (ranges?, modUri?) then let declRangeToLspRange (r : DeclarationRange) : Lsp.Range := { start := ⟨r.pos.line - 1, r.charUtf16⟩ «end» := ⟨r.endPos.line - 1, r.endCharUtf16⟩ } let ll : LocationLink := { originSelectionRange? := (·.toLspRange text) <$> i.range? targetUri := modUri targetRange := declRangeToLspRange ranges.range targetSelectionRange := declRangeToLspRange ranges.selectionRange } return #[ll] return #[] let locationLinksFromBinder (t : InfoTree) (i : Elab.Info) (id : FVarId) := do if let some i' := t.findInfo? fun | Info.ofTermInfo { isBinder := true, expr := Expr.fvar id' .., .. } => id' == id | _ => false then if let some r := i'.range? then let r := r.toLspRange text let ll : LocationLink := { originSelectionRange? := (·.toLspRange text) <$> i.range? targetUri := p.textDocument.uri targetRange := r targetSelectionRange := r } return #[ll] return #[] withWaitFindSnap doc (fun s => s.endPos > hoverPos) (notFoundX := pure #[]) fun snap => do for t in snap.cmdState.infoState.trees do if let some (ci, i) := t.hoverableInfoAt? hoverPos then if let Info.ofTermInfo ti := i then let mut expr := ti.expr if kind == type then expr ← ci.runMetaM i.lctx do Expr.getAppFn (← Meta.instantiateMVars (← Meta.inferType expr)) match expr with | Expr.const n .. => return ← ci.runMetaM i.lctx <| locationLinksFromDecl i n | Expr.fvar id .. => return ← ci.runMetaM i.lctx <| locationLinksFromBinder t i id | _ => pure () if let Info.ofFieldInfo fi := i then if kind == type then let expr ← ci.runMetaM i.lctx do Meta.instantiateMVars (← Meta.inferType fi.val) if let some n := expr.getAppFn.constName? then return ← ci.runMetaM i.lctx <| locationLinksFromDecl i n else return ← ci.runMetaM i.lctx <| locationLinksFromDecl i fi.projName -- If other go-tos fail, we try to show the elaborator or parser if let some ei := i.toElabInfo? then if kind == declaration && ci.env.contains ei.stx.getKind then return ← ci.runMetaM i.lctx <| locationLinksFromDecl i ei.stx.getKind if kind == definition && ci.env.contains ei.elaborator then return ← ci.runMetaM i.lctx <| locationLinksFromDecl i ei.elaborator return #[] open RequestM in def getInteractiveGoals (p : Lsp.PlainGoalParams) : RequestM (RequestTask (Option Widget.InteractiveGoals)) := do let doc ← readDoc let text := doc.meta.text let hoverPos := text.lspPosToUtf8Pos p.position -- NOTE: use `>=` since the cursor can be *after* the input withWaitFindSnap doc (fun s => s.endPos >= hoverPos) (notFoundX := return none) fun snap => do for t in snap.cmdState.infoState.trees do if let rs@(_ :: _) := t.goalsAt? doc.meta.text hoverPos then let goals ← List.join <$> rs.mapM fun { ctxInfo := ci, tacticInfo := ti, useAfter := useAfter } => let ci := if useAfter then { ci with mctx := ti.mctxAfter } else { ci with mctx := ti.mctxBefore } let goals := if useAfter then ti.goalsAfter else ti.goalsBefore ci.runMetaM {} <| goals.mapM (fun g => Meta.withPPInaccessibleNames (Widget.goalToInteractive g)) return some { goals := goals.toArray } return none open Elab in partial def handlePlainGoal (p : PlainGoalParams) : RequestM (RequestTask (Option PlainGoal)) := do let t ← getInteractiveGoals p t.map <| Except.map <| Option.map <| fun ⟨goals⟩ => if goals.isEmpty then { goals := #[], rendered := "no goals" } else let goalStrs := goals.map (toString ·.pretty) let goalBlocks := goalStrs.map fun goal => s!"```lean {goal} ```" let md := String.intercalate "\n---\n" goalBlocks.toList { goals := goalStrs, rendered := md } partial def getInteractiveTermGoal (p : Lsp.PlainTermGoalParams) : RequestM (RequestTask (Option Widget.InteractiveTermGoal)) := do let doc ← readDoc let text := doc.meta.text let hoverPos := text.lspPosToUtf8Pos p.position withWaitFindSnap doc (fun s => s.endPos > hoverPos) (notFoundX := pure none) fun snap => do for t in snap.cmdState.infoState.trees do if let some (ci, i@(Elab.Info.ofTermInfo ti)) := t.termGoalAt? hoverPos then let ty ← ci.runMetaM i.lctx do Meta.instantiateMVars <| ti.expectedType?.getD (← Meta.inferType ti.expr) -- for binders, hide the last hypothesis (the binder itself) let lctx' := if ti.isBinder then i.lctx.pop else i.lctx let goal ← ci.runMetaM lctx' do Meta.withPPInaccessibleNames <| Widget.goalToInteractive (← Meta.mkFreshExprMVar ty).mvarId! let range := if let some r := i.range? then r.toLspRange text else ⟨p.position, p.position⟩ return some { goal with range } return none def handlePlainTermGoal (p : PlainTermGoalParams) : RequestM (RequestTask (Option PlainTermGoal)) := do let t ← getInteractiveTermGoal p t.map <| Except.map <| Option.map fun goal => { goal := toString goal.toInteractiveGoal.pretty range := goal.range } partial def handleDocumentHighlight (p : DocumentHighlightParams) : RequestM (RequestTask (Array DocumentHighlight)) := do let doc ← readDoc let text := doc.meta.text let pos := text.lspPosToUtf8Pos p.position let rec highlightReturn? (doRange? : Option Range) : Syntax → Option DocumentHighlight | stx@`(doElem|return%$i $e) => do if let some range := i.getRange? then if range.contains pos then return some { range := doRange?.getD (range.toLspRange text), kind? := DocumentHighlightKind.text } highlightReturn? doRange? e | `(do%$i $elems) => highlightReturn? (i.getRange?.get!.toLspRange text) elems | stx => stx.getArgs.findSome? (highlightReturn? doRange?) withWaitFindSnap doc (fun s => s.endPos > pos) (notFoundX := pure #[]) fun snap => do if let some hi := highlightReturn? none snap.stx then return #[hi] return #[] section -- TODO https://github.com/leanprover/lean4/issues/529 open Parser.Command partial def handleDocumentSymbol (p : DocumentSymbolParams) : RequestM (RequestTask DocumentSymbolResult) := do let doc ← readDoc asTask do let ⟨cmdSnaps, e?⟩ ← doc.cmdSnaps.updateFinishedPrefix let mut stxs := cmdSnaps.finishedPrefix.map (·.stx) match e? with | some ElabTaskError.aborted => throw RequestError.fileChanged | some (ElabTaskError.ioError e) => throwThe IO.Error e | _ => () let lastSnap := cmdSnaps.finishedPrefix.getLastD doc.headerSnap stxs := stxs ++ (← parseAhead doc.meta.text.source lastSnap).toList let (syms, _) := toDocumentSymbols doc.meta.text stxs return { syms := syms.toArray } where toDocumentSymbols (text : FileMap) | [] => ([], []) | stx::stxs => match stx with | `(namespace $id) => sectionLikeToDocumentSymbols text stx stxs (id.getId.toString) SymbolKind.namespace id | `(section $(id)?) => sectionLikeToDocumentSymbols text stx stxs ((·.getId.toString) <$> id |>.getD "<section>") SymbolKind.namespace (id.getD stx) | `(end $(id)?) => ([], stx::stxs) | _ => do let (syms, stxs') := toDocumentSymbols text stxs unless stx.isOfKind ``Lean.Parser.Command.declaration do return (syms, stxs') if let some stxRange := stx.getRange? then let (name, selection) := match stx with | `($dm:declModifiers $ak:attrKind instance $[$np:namedPrio]? $[$id:ident$[.{$ls,*}]?]? $sig:declSig $val) => ((·.getId.toString) <$> id |>.getD s!"instance {sig.reprint.getD ""}", id.getD sig) | _ => match stx[1][1] with | `(declId|$id:ident$[.{$ls,*}]?) => (id.getId.toString, id) | _ => (stx[1][0].isIdOrAtom?.getD "<unknown>", stx[1][0]) if let some selRange := selection.getRange? then return (DocumentSymbol.mk { name := name kind := SymbolKind.method range := stxRange.toLspRange text selectionRange := selRange.toLspRange text } :: syms, stxs') return (syms, stxs') sectionLikeToDocumentSymbols (text : FileMap) (stx : Syntax) (stxs : List Syntax) (name : String) (kind : SymbolKind) (selection : Syntax) := let (syms, stxs') := toDocumentSymbols text stxs -- discard `end` let (syms', stxs'') := toDocumentSymbols text (stxs'.drop 1) let endStx := match stxs' with | endStx::_ => endStx | [] => (stx::stxs').getLast! -- we can assume that commands always have at least one position (see `parseCommand`) let range := (mkNullNode #[stx, endStx]).getRange?.get!.toLspRange text (DocumentSymbol.mk { name kind range selectionRange := selection.getRange? |>.map (·.toLspRange text) |>.getD range children? := syms.toArray } :: syms', stxs'') end def noHighlightKinds : Array SyntaxNodeKind := #[ -- usually have special highlighting by the client ``Lean.Parser.Term.sorry, ``Lean.Parser.Term.type, ``Lean.Parser.Term.prop, -- not really keywords `antiquotName, ``Lean.Parser.Command.docComment] structure SemanticTokensContext where beginPos : String.Pos endPos : String.Pos text : FileMap infoState : Elab.InfoState structure SemanticTokensState where data : Array Nat lastLspPos : Lsp.Position partial def handleSemanticTokens (beginPos endPos : String.Pos) : RequestM (RequestTask SemanticTokens) := do let doc ← readDoc let text := doc.meta.text let t ← doc.cmdSnaps.waitAll (·.beginPos < endPos) mapTask t fun (snaps, _) => StateT.run' (s := { data := #[], lastLspPos := ⟨0, 0⟩ : SemanticTokensState }) do for s in snaps do if s.endPos <= beginPos then continue ReaderT.run (r := SemanticTokensContext.mk beginPos endPos text s.cmdState.infoState) <| go s.stx return { data := (← get).data } where go (stx : Syntax) := do match stx with | `($e.$id:ident) => go e; addToken id SemanticTokenType.property -- indistinguishable from next pattern --| `(level|$id:ident) => addToken id SemanticTokenType.variable | `($id:ident) => highlightId id | _ => if !noHighlightKinds.contains stx.getKind then highlightKeyword stx if stx.isOfKind choiceKind then go stx[0] else stx.getArgs.forM go highlightId (stx : Syntax) : ReaderT SemanticTokensContext (StateT SemanticTokensState RequestM) _ := do if let some range := stx.getRange? then for t in (← read).infoState.trees do for ti in t.deepestNodes (fun | _, i@(Elab.Info.ofTermInfo ti), _ => match i.pos? with | some ipos => if range.contains ipos then some ti else none | _ => none | _, _, _ => none) do match ti.expr with | Expr.fvar .. => addToken ti.stx SemanticTokenType.variable | _ => if ti.stx.getPos?.get! > range.start then addToken ti.stx SemanticTokenType.property highlightKeyword stx := do if let Syntax.atom info val := stx then if val.bsize > 0 && val[0].isAlpha then addToken stx SemanticTokenType.keyword addToken stx type := do let ⟨beginPos, endPos, text, _⟩ ← read if let (some pos, some tailPos) := (stx.getPos?, stx.getTailPos?) then if beginPos <= pos && pos < endPos then let lspPos := (← get).lastLspPos let lspPos' := text.utf8PosToLspPos pos let deltaLine := lspPos'.line - lspPos.line let deltaStart := lspPos'.character - (if lspPos'.line == lspPos.line then lspPos.character else 0) let length := (text.utf8PosToLspPos tailPos).character - lspPos'.character let tokenType := type.toNat let tokenModifiers := 0 modify fun st => { data := st.data ++ #[deltaLine, deltaStart, length, tokenType, tokenModifiers] lastLspPos := lspPos' } def handleSemanticTokensFull (p : SemanticTokensParams) : RequestM (RequestTask SemanticTokens) := do handleSemanticTokens 0 (1 <<< 16) def handleSemanticTokensRange (p : SemanticTokensRangeParams) : RequestM (RequestTask SemanticTokens) := do let doc ← readDoc let text := doc.meta.text let beginPos := text.lspPosToUtf8Pos p.range.start let endPos := text.lspPosToUtf8Pos p.range.end handleSemanticTokens beginPos endPos partial def handleWaitForDiagnostics (p : WaitForDiagnosticsParams) : RequestM (RequestTask WaitForDiagnostics) := do let rec waitLoop : RequestM EditableDocument := do let doc ← readDoc if p.version ≤ doc.meta.version then return doc else IO.sleep 50 waitLoop let t ← RequestM.asTask waitLoop RequestM.bindTask t fun doc? => do let doc ← doc? let t₁ ← doc.cmdSnaps.waitAll return t₁.map fun _ => pure WaitForDiagnostics.mk builtin_initialize registerLspRequestHandler "textDocument/waitForDiagnostics" WaitForDiagnosticsParams WaitForDiagnostics handleWaitForDiagnostics registerLspRequestHandler "textDocument/completion" CompletionParams CompletionList handleCompletion registerLspRequestHandler "textDocument/hover" HoverParams (Option Hover) handleHover registerLspRequestHandler "textDocument/declaration" TextDocumentPositionParams (Array LocationLink) (handleDefinition GoToKind.declaration) registerLspRequestHandler "textDocument/definition" TextDocumentPositionParams (Array LocationLink) (handleDefinition GoToKind.definition) registerLspRequestHandler "textDocument/typeDefinition" TextDocumentPositionParams (Array LocationLink) (handleDefinition GoToKind.type) registerLspRequestHandler "textDocument/documentHighlight" DocumentHighlightParams DocumentHighlightResult handleDocumentHighlight registerLspRequestHandler "textDocument/documentSymbol" DocumentSymbolParams DocumentSymbolResult handleDocumentSymbol registerLspRequestHandler "textDocument/semanticTokens/full" SemanticTokensParams SemanticTokens handleSemanticTokensFull registerLspRequestHandler "textDocument/semanticTokens/range" SemanticTokensRangeParams SemanticTokens handleSemanticTokensRange registerLspRequestHandler "$/lean/plainGoal" PlainGoalParams (Option PlainGoal) handlePlainGoal registerLspRequestHandler "$/lean/plainTermGoal" PlainTermGoalParams (Option PlainTermGoal) handlePlainTermGoal end Lean.Server.FileWorker
c7521e7fa0fc373681618f3cbb4457c368f20026
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/getElem.lean
8dbb6d3f9b4f7e5758cf6fb4d1be041b158285c4
[ "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
507
lean
def f1 (a : Array Nat) (i : Nat) := a[i] def f2 (a : Array Nat) (i : Fin a.size) := a[i] -- Ok def f3 (a : Array Nat) (h : n ≤ a.size) (i : Fin n) := a[i] -- Ok opaque a : Array Nat opaque n : Nat axiom n_lt_a_size : n < a.size def f4 (i : Nat) (h : i < n) := have : i < a.size := Nat.lt_trans h n_lt_a_size a[i] def f5 (i : Nat) (h : i < n) := a[i]'(Nat.lt_trans h n_lt_a_size) def f6 (i : Nat) := a[i]! def f7 (i : Nat) := a[i]? #print f2 #print f3 #print f5 #print f6 #print f7
77ee229112fb6d4670ceb42195bdfa5f97bb8ad7
d642a6b1261b2cbe691e53561ac777b924751b63
/src/order/lattice.lean
b05f1dab94622660f0c80ada709ab92636c39eb0
[ "Apache-2.0" ]
permissive
cipher1024/mathlib
fee56b9954e969721715e45fea8bcb95f9dc03fe
d077887141000fefa5a264e30fa57520e9f03522
refs/heads/master
1,651,806,490,504
1,573,508,694,000
1,573,508,694,000
107,216,176
0
0
Apache-2.0
1,647,363,136,000
1,508,213,014,000
Lean
UTF-8
Lean
false
false
15,521
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl Defines the inf/sup (semi)-lattice with optionally top/bot type class hierarchy. -/ import order.basic set_option old_structure_cmd true universes u v w -- TODO: move this eventually, if we decide to use them attribute [ematch] le_trans lt_of_le_of_lt lt_of_lt_of_le lt_trans section variable {α : Type u} -- TODO: this seems crazy, but it also seems to work reasonably well @[ematch] theorem le_antisymm' [partial_order α] : ∀ {a b : α}, (: a ≤ b :) → b ≤ a → a = b := @le_antisymm _ _ end /- TODO: automatic construction of dual definitions / theorems -/ namespace lattice reserve infixl ` ⊓ `:70 reserve infixl ` ⊔ `:65 /-- Typeclass for the `⊔` (`\lub`) notation -/ class has_sup (α : Type u) := (sup : α → α → α) /-- Typeclass for the `⊓` (`\glb`) notation -/ class has_inf (α : Type u) := (inf : α → α → α) infix ⊔ := has_sup.sup infix ⊓ := has_inf.inf /-- A `semilattice_sup` is a join-semilattice, that is, a partial order with a join (a.k.a. lub / least upper bound, sup / supremum) operation `⊔` which is the least element larger than both factors. -/ class semilattice_sup (α : Type u) extends has_sup α, partial_order α := (le_sup_left : ∀ a b : α, a ≤ a ⊔ b) (le_sup_right : ∀ a b : α, b ≤ a ⊔ b) (sup_le : ∀ a b c : α, a ≤ c → b ≤ c → a ⊔ b ≤ c) section semilattice_sup variables {α : Type u} [semilattice_sup α] {a b c d : α} @[simp] theorem le_sup_left : a ≤ a ⊔ b := semilattice_sup.le_sup_left a b @[ematch] theorem le_sup_left' : a ≤ (: a ⊔ b :) := semilattice_sup.le_sup_left a b @[simp] theorem le_sup_right : b ≤ a ⊔ b := semilattice_sup.le_sup_right a b @[ematch] theorem le_sup_right' : b ≤ (: a ⊔ b :) := semilattice_sup.le_sup_right a b theorem le_sup_left_of_le (h : c ≤ a) : c ≤ a ⊔ b := by finish theorem le_sup_right_of_le (h : c ≤ b) : c ≤ a ⊔ b := by finish theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c := semilattice_sup.sup_le a b c @[simp] theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c := ⟨assume h : a ⊔ b ≤ c, ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩, assume ⟨h₁, h₂⟩, sup_le h₁ h₂⟩ -- TODO: if we just write le_antisymm, Lean doesn't know which ≤ we want to use -- Can we do anything about that? theorem sup_of_le_left (h : b ≤ a) : a ⊔ b = a := by apply le_antisymm; finish theorem sup_of_le_right (h : a ≤ b) : a ⊔ b = b := by apply le_antisymm; finish theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d := by finish theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b := by finish theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c := by finish theorem le_of_sup_eq (h : a ⊔ b = b) : a ≤ b := by finish @[simp] lemma sup_lt_iff [is_total α (≤)] {a b c : α} : b ⊔ c < a ↔ b < a ∧ c < a := begin cases (is_total.total (≤) b c) with h, { simp [sup_of_le_right h], exact ⟨λI, ⟨lt_of_le_of_lt h I, I⟩, λH, H.2⟩ }, { simp [sup_of_le_left h], exact ⟨λI, ⟨I, lt_of_le_of_lt h I⟩, λH, H.1⟩ } end @[simp] theorem sup_idem : a ⊔ a = a := by apply le_antisymm; finish instance sup_is_idempotent : is_idempotent α (⊔) := ⟨@sup_idem _ _⟩ theorem sup_comm : a ⊔ b = b ⊔ a := by apply le_antisymm; finish instance sup_is_commutative : is_commutative α (⊔) := ⟨@sup_comm _ _⟩ theorem sup_assoc : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) := by apply le_antisymm; finish instance sup_is_associative : is_associative α (⊔) := ⟨@sup_assoc _ _⟩ lemma sup_left_comm (a b c : α) : a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c) := by rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a] lemma forall_le_or_exists_lt_sup (a : α) : (∀b, b ≤ a) ∨ (∃b, a < b) := suffices (∃b, ¬b ≤ a) → (∃b, a < b), by rwa [classical.or_iff_not_imp_left, classical.not_forall], assume ⟨b, hb⟩, have a ≠ a ⊔ b, from assume eq, hb $ eq.symm ▸ le_sup_right, ⟨a ⊔ b, lt_of_le_of_ne le_sup_left ‹a ≠ a ⊔ b›⟩ theorem semilattice_sup.ext_sup {α} {A B : semilattice_sup α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) (x y : α) : (by haveI := A; exact (x ⊔ y)) = x ⊔ y := eq_of_forall_ge_iff $ λ c, by simp only [sup_le_iff]; rw [← H, @sup_le_iff α A, H, H] theorem semilattice_sup.ext {α} {A B : semilattice_sup α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin haveI this := partial_order.ext H, have ss := funext (λ x, funext $ semilattice_sup.ext_sup H x), cases A; cases B; injection this; congr' end lemma directed_of_sup {β : Type*} {r : β → β → Prop} {f : α → β} (hf : ∀a₁ a₂, a₁ ≤ a₂ → r (f a₁) (f a₂)) : directed r f := assume x y, ⟨x ⊔ y, hf _ _ le_sup_left, hf _ _ le_sup_right⟩ end semilattice_sup /-- A `semilattice_inf` is a meet-semilattice, that is, a partial order with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation `⊓` which is the greatest element smaller than both factors. -/ class semilattice_inf (α : Type u) extends has_inf α, partial_order α := (inf_le_left : ∀ a b : α, a ⊓ b ≤ a) (inf_le_right : ∀ a b : α, a ⊓ b ≤ b) (le_inf : ∀ a b c : α, a ≤ b → a ≤ c → a ≤ b ⊓ c) section semilattice_inf variables {α : Type u} [semilattice_inf α] {a b c d : α} @[simp] theorem inf_le_left : a ⊓ b ≤ a := semilattice_inf.inf_le_left a b @[ematch] theorem inf_le_left' : (: a ⊓ b :) ≤ a := semilattice_inf.inf_le_left a b @[simp] theorem inf_le_right : a ⊓ b ≤ b := semilattice_inf.inf_le_right a b @[ematch] theorem inf_le_right' : (: a ⊓ b :) ≤ b := semilattice_inf.inf_le_right a b theorem le_inf : a ≤ b → a ≤ c → a ≤ b ⊓ c := semilattice_inf.le_inf a b c theorem inf_le_left_of_le (h : a ≤ c) : a ⊓ b ≤ c := le_trans inf_le_left h theorem inf_le_right_of_le (h : b ≤ c) : a ⊓ b ≤ c := le_trans inf_le_right h @[simp] theorem le_inf_iff : a ≤ b ⊓ c ↔ a ≤ b ∧ a ≤ c := ⟨assume h : a ≤ b ⊓ c, ⟨le_trans h inf_le_left, le_trans h inf_le_right⟩, assume ⟨h₁, h₂⟩, le_inf h₁ h₂⟩ theorem inf_of_le_left (h : a ≤ b) : a ⊓ b = a := by apply le_antisymm; finish theorem inf_of_le_right (h : b ≤ a) : a ⊓ b = b := by apply le_antisymm; finish theorem inf_le_inf (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊓ c ≤ b ⊓ d := by finish theorem le_of_inf_eq (h : a ⊓ b = a) : a ≤ b := by finish @[simp] lemma lt_inf_iff [is_total α (≤)] {a b c : α} : a < b ⊓ c ↔ a < b ∧ a < c := begin cases (is_total.total (≤) b c) with h, { simp [inf_of_le_left h], exact ⟨λI, ⟨I, lt_of_lt_of_le I h⟩, λH, H.1⟩ }, { simp [inf_of_le_right h], exact ⟨λI, ⟨lt_of_lt_of_le I h, I⟩, λH, H.2⟩ } end @[simp] theorem inf_idem : a ⊓ a = a := by apply le_antisymm; finish instance inf_is_idempotent : is_idempotent α (⊓) := ⟨@inf_idem _ _⟩ theorem inf_comm : a ⊓ b = b ⊓ a := by apply le_antisymm; finish instance inf_is_commutative : is_commutative α (⊓) := ⟨@inf_comm _ _⟩ theorem inf_assoc : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := by apply le_antisymm; finish instance inf_is_associative : is_associative α (⊓) := ⟨@inf_assoc _ _⟩ lemma inf_left_comm (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) := by rw [← inf_assoc, ← inf_assoc, @inf_comm α _ a] lemma forall_le_or_exists_lt_inf (a : α) : (∀b, a ≤ b) ∨ (∃b, b < a) := suffices (∃b, ¬a ≤ b) → (∃b, b < a), by rwa [classical.or_iff_not_imp_left, classical.not_forall], assume ⟨b, hb⟩, have a ⊓ b ≠ a, from assume eq, hb $ eq ▸ inf_le_right, ⟨a ⊓ b, lt_of_le_of_ne inf_le_left ‹a ⊓ b ≠ a›⟩ theorem semilattice_inf.ext_inf {α} {A B : semilattice_inf α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) (x y : α) : (by haveI := A; exact (x ⊓ y)) = x ⊓ y := eq_of_forall_le_iff $ λ c, by simp only [le_inf_iff]; rw [← H, @le_inf_iff α A, H, H] theorem semilattice_inf.ext {α} {A B : semilattice_inf α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin haveI this := partial_order.ext H, have ss := funext (λ x, funext $ semilattice_inf.ext_inf H x), cases A; cases B; injection this; congr' end lemma directed_of_inf {β : Type*} {r : β → β → Prop} {f : α → β} (hf : ∀a₁ a₂, a₁ ≤ a₂ → r (f a₂) (f a₁)) : directed r f := assume x y, ⟨x ⊓ y, hf _ _ inf_le_left, hf _ _ inf_le_right⟩ end semilattice_inf /- Lattices -/ /-- A lattice is a join-semilattice which is also a meet-semilattice. -/ -- TODO(lint): Fix double namespace issue @[nolint] class lattice (α : Type u) extends semilattice_sup α, semilattice_inf α section lattice variables {α : Type u} [lattice α] {a b c d : α} /- Distributivity laws -/ /- TODO: better names? -/ theorem sup_inf_le : a ⊔ (b ⊓ c) ≤ (a ⊔ b) ⊓ (a ⊔ c) := by finish theorem le_inf_sup : (a ⊓ b) ⊔ (a ⊓ c) ≤ a ⊓ (b ⊔ c) := by finish theorem inf_sup_self : a ⊓ (a ⊔ b) = a := le_antisymm (by finish) (by finish) theorem sup_inf_self : a ⊔ (a ⊓ b) = a := le_antisymm (by finish) (by finish) theorem ext {α} {A B : lattice α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin have SS : @lattice.to_semilattice_sup α A = @lattice.to_semilattice_sup α B := semilattice_sup.ext H, have II := semilattice_inf.ext H, resetI, cases A; cases B; injection SS; injection II; congr' end end lattice variables {α : Type u} {x y z w : α} /-- A distributive lattice is a lattice that satisfies any of four equivalent distribution properties (of sup over inf or inf over sup, on the left or right). A classic example of a distributive lattice is the lattice of subsets of a set, and in fact this example is generic in the sense that every distributive lattice is realizable as a sublattice of a powerset lattice. -/ class distrib_lattice α extends lattice α := (le_sup_inf : ∀x y z : α, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z)) section distrib_lattice variables [distrib_lattice α] theorem le_sup_inf : ∀{x y z : α}, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z) := distrib_lattice.le_sup_inf theorem sup_inf_left : x ⊔ (y ⊓ z) = (x ⊔ y) ⊓ (x ⊔ z) := le_antisymm sup_inf_le le_sup_inf theorem sup_inf_right : (y ⊓ z) ⊔ x = (y ⊔ x) ⊓ (z ⊔ x) := by simp only [sup_inf_left, λy:α, @sup_comm α _ y x, eq_self_iff_true] theorem inf_sup_left : x ⊓ (y ⊔ z) = (x ⊓ y) ⊔ (x ⊓ z) := calc x ⊓ (y ⊔ z) = (x ⊓ (x ⊔ z)) ⊓ (y ⊔ z) : by rw [inf_sup_self] ... = x ⊓ ((x ⊓ y) ⊔ z) : by simp only [inf_assoc, sup_inf_right, eq_self_iff_true] ... = (x ⊔ (x ⊓ y)) ⊓ ((x ⊓ y) ⊔ z) : by rw [sup_inf_self] ... = ((x ⊓ y) ⊔ x) ⊓ ((x ⊓ y) ⊔ z) : by rw [sup_comm] ... = (x ⊓ y) ⊔ (x ⊓ z) : by rw [sup_inf_left] theorem inf_sup_right : (y ⊔ z) ⊓ x = (y ⊓ x) ⊔ (z ⊓ x) := by simp only [inf_sup_left, λy:α, @inf_comm α _ y x, eq_self_iff_true] lemma eq_of_sup_eq_inf_eq {α : Type u} [distrib_lattice α] {a b c : α} (h₁ : b ⊓ a = c ⊓ a) (h₂ : b ⊔ a = c ⊔ a) : b = c := le_antisymm (calc b ≤ (c ⊓ a) ⊔ b : le_sup_right ... = (c ⊔ b) ⊓ (a ⊔ b) : sup_inf_right ... = c ⊔ (c ⊓ a) : by rw [←h₁, sup_inf_left, ←h₂]; simp only [sup_comm, eq_self_iff_true] ... = c : sup_inf_self) (calc c ≤ (b ⊓ a) ⊔ c : le_sup_right ... = (b ⊔ c) ⊓ (a ⊔ c) : sup_inf_right ... = b ⊔ (b ⊓ a) : by rw [h₁, sup_inf_left, h₂]; simp only [sup_comm, eq_self_iff_true] ... = b : sup_inf_self) end distrib_lattice /- Lattices derived from linear orders -/ instance lattice_of_decidable_linear_order {α : Type u} [o : decidable_linear_order α] : lattice α := { sup := max, le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := assume a b c, max_le, inf := min, inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := assume a b c, le_min, ..o } theorem sup_eq_max [decidable_linear_order α] : x ⊔ y = max x y := rfl theorem inf_eq_min [decidable_linear_order α] : x ⊓ y = min x y := rfl instance distrib_lattice_of_decidable_linear_order {α : Type u} [o : decidable_linear_order α] : distrib_lattice α := { le_sup_inf := assume a b c, match le_total b c with | or.inl h := inf_le_left_of_le $ sup_le_sup_left (le_inf (le_refl b) h) _ | or.inr h := inf_le_right_of_le $ sup_le_sup_left (le_inf h (le_refl c)) _ end, ..lattice.lattice_of_decidable_linear_order } instance nat.distrib_lattice : distrib_lattice ℕ := by apply_instance end lattice namespace order_dual open lattice variable (α : Type*) instance [has_inf α] : has_sup (order_dual α) := ⟨((⊓) : α → α → α)⟩ instance [has_sup α] : has_inf (order_dual α) := ⟨((⊔) : α → α → α)⟩ instance [semilattice_inf α] : semilattice_sup (order_dual α) := { le_sup_left := @inf_le_left α _, le_sup_right := @inf_le_right α _, sup_le := assume a b c hca hcb, @le_inf α _ _ _ _ hca hcb, .. order_dual.partial_order α, .. order_dual.lattice.has_sup α } instance [semilattice_sup α] : semilattice_inf (order_dual α) := { inf_le_left := @le_sup_left α _, inf_le_right := @le_sup_right α _, le_inf := assume a b c hca hcb, @sup_le α _ _ _ _ hca hcb, .. order_dual.partial_order α, .. order_dual.lattice.has_inf α } instance [lattice α] : lattice (order_dual α) := { .. order_dual.lattice.semilattice_sup α, .. order_dual.lattice.semilattice_inf α } instance [distrib_lattice α] : distrib_lattice (order_dual α) := { le_sup_inf := assume x y z, le_of_eq inf_sup_left.symm, .. order_dual.lattice.lattice α } end order_dual namespace prod open lattice variables (α : Type u) (β : Type v) instance [has_sup α] [has_sup β] : has_sup (α × β) := ⟨λp q, ⟨p.1 ⊔ q.1, p.2 ⊔ q.2⟩⟩ instance [has_inf α] [has_inf β] : has_inf (α × β) := ⟨λp q, ⟨p.1 ⊓ q.1, p.2 ⊓ q.2⟩⟩ instance [semilattice_sup α] [semilattice_sup β] : semilattice_sup (α × β) := { sup_le := assume a b c h₁ h₂, ⟨sup_le h₁.1 h₂.1, sup_le h₁.2 h₂.2⟩, le_sup_left := assume a b, ⟨le_sup_left, le_sup_left⟩, le_sup_right := assume a b, ⟨le_sup_right, le_sup_right⟩, .. prod.partial_order α β, .. prod.lattice.has_sup α β } instance [semilattice_inf α] [semilattice_inf β] : semilattice_inf (α × β) := { le_inf := assume a b c h₁ h₂, ⟨le_inf h₁.1 h₂.1, le_inf h₁.2 h₂.2⟩, inf_le_left := assume a b, ⟨inf_le_left, inf_le_left⟩, inf_le_right := assume a b, ⟨inf_le_right, inf_le_right⟩, .. prod.partial_order α β, .. prod.lattice.has_inf α β } instance [lattice α] [lattice β] : lattice (α × β) := { .. prod.lattice.semilattice_inf α β, .. prod.lattice.semilattice_sup α β } instance [distrib_lattice α] [distrib_lattice β] : distrib_lattice (α × β) := { le_sup_inf := assume a b c, ⟨le_sup_inf, le_sup_inf⟩, .. prod.lattice.lattice α β } end prod
d5f1afabd91f483fcb6d2c568e58699821fd1ca4
19cc34575500ee2e3d4586c15544632aa07a8e66
/src/data/polynomial/monomial.lean
e55951473505259f3f07d65a4e5e48716445664e
[ "Apache-2.0" ]
permissive
LibertasSpZ/mathlib
b9fcd46625eb940611adb5e719a4b554138dade6
33f7870a49d7cc06d2f3036e22543e6ec5046e68
refs/heads/master
1,672,066,539,347
1,602,429,158,000
1,602,429,158,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,871
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import data.polynomial.basic /-! # Univariate monomials Preparatory lemmas for degree_basic. -/ noncomputable theory open finsupp namespace polynomial universes u variables {R : Type u} {a b : R} {m n : ℕ} variables [semiring R] {p q r : polynomial R} /-- `C a` is the constant polynomial `a`. `C` is provided as a ring homomorphism. -/ def C : R →+* polynomial R := add_monoid_algebra.algebra_map' (ring_hom.id R) @[simp] lemma monomial_zero_left (a : R) : monomial 0 a = C a := rfl lemma C_0 : C (0 : R) = 0 := single_zero lemma C_1 : C (1 : R) = 1 := rfl lemma C_mul : C (a * b) = C a * C b := C.map_mul a b lemma C_add : C (a + b) = C a + C b := C.map_add a b @[simp] lemma C_bit0 : C (bit0 a) = bit0 (C a) := C_add @[simp] lemma C_bit1 : C (bit1 a) = bit1 (C a) := by simp [bit1, C_bit0] lemma C_pow : C (a ^ n) = C a ^ n := C.map_pow a n @[simp] lemma C_eq_nat_cast (n : ℕ) : C (n : R) = (n : polynomial R) := C.map_nat_cast n @[simp] lemma sum_C_index {a} {β} [add_comm_monoid β] {f : ℕ → R → β} (h : f 0 0 = 0) : (C a).sum f = f 0 a := sum_single_index h lemma coeff_C : coeff (C a) n = ite (n = 0) a 0 := by { convert coeff_monomial using 2, simp [eq_comm], } @[simp] lemma coeff_C_zero : coeff (C a) 0 = a := coeff_monomial theorem nonzero.of_polynomial_ne (h : p ≠ q) : nontrivial R := ⟨⟨0, 1, λ h01 : 0 = 1, h $ by rw [← mul_one p, ← mul_one q, ← C_1, ← h01, C_0, mul_zero, mul_zero] ⟩⟩ lemma single_eq_C_mul_X : ∀{n}, monomial n a = C a * X^n | 0 := (mul_one _).symm | (n+1) := calc monomial (n + 1) a = monomial n a * X : by { rw [X, monomial_mul_monomial, mul_one], } ... = (C a * X^n) * X : by rw [single_eq_C_mul_X] ... = C a * X^(n+1) : by simp only [pow_add, mul_assoc, pow_one] lemma C_inj : C a = C b ↔ a = b := ⟨λ h, coeff_C_zero.symm.trans (h.symm ▸ coeff_C_zero), congr_arg C⟩ instance [nontrivial R] : infinite (polynomial R) := infinite.of_injective (λ i, monomial i 1) begin intros m n h, have := (single_eq_single_iff _ _ _ _).mp h, simpa only [and_true, eq_self_iff_true, or_false, one_ne_zero, and_self], end lemma monomial_one_eq_X_pow : ∀{n}, monomial n (1 : R) = X^n | 0 := rfl | (n+1) := calc monomial (n + 1) (1 : R) = monomial n 1 * X : by rw [X, monomial_mul_monomial, mul_one] ... = X^n * X : by rw [monomial_one_eq_X_pow] ... = X^(n+1) : by simp only [pow_add, pow_one] lemma monomial_eq_smul_X {n} : monomial n (a : R) = a • X^n := begin calc monomial n a = monomial n (a * 1) : by simp ... = a • monomial n 1 : (smul_single' _ _ _).symm ... = a • X^n : by rw monomial_one_eq_X_pow end end polynomial
2a15953172cd0d62a986498abb072f7e935c31a5
853df553b1d6ca524e3f0a79aedd32dde5d27ec3
/src/category_theory/natural_isomorphism.lean
a67bc0122ca1bc08aebe6b49a44a31d4ebaa956a
[ "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
4,919
lean
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn -/ import category_theory.functor_category import category_theory.isomorphism open category_theory -- declare the `v`'s first; see `category_theory.category` for an explanation universes v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ namespace category_theory open nat_trans /-- The application of a natural isomorphism to an object. We put this definition in a different namespace, so that we can use `α.app` -/ @[simp, reducible] def iso.app {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D] {F G : C ⥤ D} (α : F ≅ G) (X : C) : F.obj X ≅ G.obj X := { hom := α.hom.app X, inv := α.inv.app X, hom_inv_id' := begin rw [← comp_app, iso.hom_inv_id], refl end, inv_hom_id' := begin rw [← comp_app, iso.inv_hom_id], refl end } namespace nat_iso open category_theory.category category_theory.functor variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D] {E : Type u₃} [category.{v₃} E] @[simp] lemma trans_app {F G H : C ⥤ D} (α : F ≅ G) (β : G ≅ H) (X : C) : (α ≪≫ β).app X = α.app X ≪≫ β.app X := rfl lemma app_hom {F G : C ⥤ D} (α : F ≅ G) (X : C) : (α.app X).hom = α.hom.app X := rfl lemma app_inv {F G : C ⥤ D} (α : F ≅ G) (X : C) : (α.app X).inv = α.inv.app X := rfl @[simp, reassoc] lemma hom_inv_id_app {F G : C ⥤ D} (α : F ≅ G) (X : C) : α.hom.app X ≫ α.inv.app X = 𝟙 (F.obj X) := congr_fun (congr_arg app α.hom_inv_id) X @[simp, reassoc] lemma inv_hom_id_app {F G : C ⥤ D} (α : F ≅ G) (X : C) : α.inv.app X ≫ α.hom.app X = 𝟙 (G.obj X) := congr_fun (congr_arg app α.inv_hom_id) X variables {F G : C ⥤ D} instance hom_app_is_iso (α : F ≅ G) (X : C) : is_iso (α.hom.app X) := { inv := α.inv.app X, hom_inv_id' := begin rw [←comp_app, iso.hom_inv_id, ←id_app] end, inv_hom_id' := begin rw [←comp_app, iso.inv_hom_id, ←id_app] end } instance inv_app_is_iso (α : F ≅ G) (X : C) : is_iso (α.inv.app X) := { inv := α.hom.app X, hom_inv_id' := begin rw [←comp_app, iso.inv_hom_id, ←id_app] end, inv_hom_id' := begin rw [←comp_app, iso.hom_inv_id, ←id_app] end } lemma hom_app_inv_app_id (α : F ≅ G) (X : C) : α.hom.app X ≫ α.inv.app X = 𝟙 _ := hom_inv_id_app _ _ lemma inv_app_hom_app_id (α : F ≅ G) (X : C) : α.inv.app X ≫ α.hom.app X = 𝟙 _ := inv_hom_id_app _ _ variables {X Y : C} lemma naturality_1 (α : F ≅ G) (f : X ⟶ Y) : (α.inv.app X) ≫ (F.map f) ≫ (α.hom.app Y) = G.map f := begin erw [naturality, ←category.assoc, is_iso.hom_inv_id, category.id_comp] end lemma naturality_2 (α : F ≅ G) (f : X ⟶ Y) : (α.hom.app X) ≫ (G.map f) ≫ (α.inv.app Y) = F.map f := begin erw [naturality, ←category.assoc, is_iso.hom_inv_id, category.id_comp] end def is_iso_of_is_iso_app (α : F ⟶ G) [∀ X : C, is_iso (α.app X)] : is_iso α := { inv := { app := λ X, inv (α.app X), naturality' := λ X Y f, begin have h := congr_arg (λ f, inv (α.app X) ≫ (f ≫ inv (α.app Y))) (α.naturality f).symm, simp only [is_iso.inv_hom_id_assoc, is_iso.hom_inv_id, assoc, comp_id, cancel_mono] at h, exact h end } } instance is_iso_of_is_iso_app' (α : F ⟶ G) [H : ∀ X : C, is_iso (nat_trans.app α X)] : is_iso α := @nat_iso.is_iso_of_is_iso_app _ _ _ _ _ _ α H -- TODO can we make this an instance? def is_iso_app_of_is_iso (α : F ⟶ G) [is_iso α] (X) : is_iso (α.app X) := { inv := (inv α).app X, hom_inv_id' := congr_fun (congr_arg nat_trans.app (is_iso.hom_inv_id α)) X, inv_hom_id' := congr_fun (congr_arg nat_trans.app (is_iso.inv_hom_id α)) X } def of_components (app : ∀ X : C, F.obj X ≅ G.obj X) (naturality : ∀ {X Y : C} (f : X ⟶ Y), F.map f ≫ (app Y).hom = (app X).hom ≫ G.map f) : F ≅ G := as_iso { app := λ X, (app X).hom } @[simp] lemma of_components.app (app' : ∀ X : C, F.obj X ≅ G.obj X) (naturality) (X) : (of_components app' naturality).app X = app' X := by tidy @[simp] lemma of_components.hom_app (app : ∀ X : C, F.obj X ≅ G.obj X) (naturality) (X) : (of_components app naturality).hom.app X = (app X).hom := rfl @[simp] lemma of_components.inv_app (app : ∀ X : C, F.obj X ≅ G.obj X) (naturality) (X) : (of_components app naturality).inv.app X = (app X).inv := rfl def hcomp {F G : C ⥤ D} {H I : D ⥤ E} (α : F ≅ G) (β : H ≅ I) : F ⋙ H ≅ G ⋙ I := begin refine ⟨α.hom ◫ β.hom, α.inv ◫ β.inv, _, _⟩, { ext, rw [←nat_trans.exchange], simp, refl }, ext, rw [←nat_trans.exchange], simp, refl end -- declare local notation for nat_iso.hcomp localized "infix ` ■ `:80 := category_theory.nat_iso.hcomp" in category end nat_iso end category_theory
bb24ce90e4863099975ea3968892c102ecfbc80a
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/111.lean
35dae94fb9c3bcdaba71e3f2146b8fa1174d78e2
[ "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
213
lean
import Lean open Lean #check mkNullNode -- Lean.Syntax #check mkNullNode #[] -- Lean.Syntax #check @mkNullNode #check let f : Array Syntax → Syntax := @mkNullNode; f #[] #check let f := @mkNullNode; f #[]
906365d2663edea0eb80825a1cbb618c3ec2f93c
3dd1b66af77106badae6edb1c4dea91a146ead30
/tests/lean/run/goal.lean
75204634bba04cd24996e7ca18a94cfa12b20331
[ "Apache-2.0" ]
permissive
silky/lean
79c20c15c93feef47bb659a2cc139b26f3614642
df8b88dca2f8da1a422cb618cd476ef5be730546
refs/heads/master
1,610,737,587,697
1,406,574,534,000
1,406,574,534,000
22,362,176
1
0
null
null
null
null
UTF-8
Lean
false
false
116
lean
import standard using tactic theorem T {a b c d : Prop} (H : a) (H : b) (H : c) (H : d) : a := by state; assumption
4aa465b9f159d2708cb280d445c1ecd9abb2b059
7282d49021d38dacd06c4ce45a48d09627687fe0
/tests/lean/add_assoc.lean
d0f715eaa4afcd4b4799fce4ead1124a27db1f4b
[ "Apache-2.0" ]
permissive
steveluc/lean
5a0b4431acefaf77f15b25bbb49294c2449923ad
92ba4e8b2d040a799eda7deb8d2a7cdd3e69c496
refs/heads/master
1,611,332,256,930
1,391,013,244,000
1,391,013,244,000
16,361,079
1
0
null
null
null
null
UTF-8
Lean
false
false
407
lean
import tactic using Nat rewrite_set basic add_rewrite add_zerol add_succl eq_id : basic theorem add_assoc (a b c : Nat) : a + (b + c) = (a + b) + c := induction_on a (have 0 + (b + c) = (0 + b) + c : by simp basic) (λ (n : Nat) (iH : n + (b + c) = (n + b) + c), have (n + 1) + (b + c) = ((n + 1) + b) + c : by simp basic) check add_zerol check add_succl check @eq_id print environment 1
ecefbf74f15441cdc8c92426cd532b49021a5033
4950bf76e5ae40ba9f8491647d0b6f228ddce173
/src/algebra/group/to_additive.lean
ff87a26d7c1776663c3ebba0142033a9d7f26739
[ "Apache-2.0" ]
permissive
ntzwq/mathlib
ca50b21079b0a7c6781c34b62199a396dd00cee2
36eec1a98f22df82eaccd354a758ef8576af2a7f
refs/heads/master
1,675,193,391,478
1,607,822,996,000
1,607,822,996,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
12,323
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Yury Kudryashov. -/ import tactic.transform_decl import tactic.algebra /-! # Transport multiplicative to additive This file defines an attribute `to_additive` that can be used to automatically transport theorems and definitions (but not inductive types and structures) from a multiplicative theory to an additive theory. Usage information is contained in the doc string of `to_additive.attr`. ### Missing features * Automatically transport structures and other inductive types. * For structures, automatically generate theorems like `group α ↔ add_group (additive α)`. * Rewrite rules for the last part of the name that work in more cases. E.g., we can replace `monoid` with `add_monoid` etc. -/ namespace to_additive open tactic exceptional section performance_hack -- see Note [user attribute parameters] local attribute [semireducible] reflected local attribute [instance, priority 9000] private meta def hacky_name_reflect : has_reflect name := λ n, `(id %%(expr.const n []) : name) /-- An auxiliary attribute used to store the names of the additive versions of declarations that have been processed by `to_additive`. -/ @[user_attribute] private meta def aux_attr : user_attribute (name_map name) name := { name := `to_additive_aux, descr := "Auxiliary attribute for `to_additive`. DON'T USE IT", cache_cfg := ⟨λ ns, ns.mfoldl (λ dict n', do let n := match n' with | name.mk_string s pre := if s = "_to_additive" then pre else n' | _ := n' end, param ← aux_attr.get_param_untyped n', pure $ dict.insert n param.app_arg.const_name) mk_name_map, []⟩, parser := lean.parser.ident } end performance_hack /-- A command that can be used to have future uses of `to_additive` change the `src` namespace to the `tgt` namespace. For example: ``` run_cmd to_additive.map_namespace `quotient_group `quotient_add_group ``` Later uses of `to_additive` on declarations in the `quotient_group` namespace will be created in the `quotient_add_group` namespaces. -/ meta def map_namespace (src tgt : name) : command := do let n := src.mk_string "_to_additive", let decl := declaration.thm n [] `(unit) (pure (reflect ())), add_decl decl, aux_attr.set n tgt tt /-- `value_type` is the type of the arguments that can be provided to `to_additive`. `to_additive.parser` parses the provided arguments into `name` for the target and an optional doc string. -/ @[derive has_reflect, derive inhabited] structure value_type : Type := (tgt : name) (doc : option string) /-- `add_comm_prefix x s` returns `"comm_" ++ s` if `x = tt` and `s` otherwise. -/ meta def add_comm_prefix : bool → string → string | tt s := ("comm_" ++ s) | ff s := s /-- Dictionary used by `to_additive.guess_name` to autogenerate names. -/ meta def tr : bool → list string → list string | is_comm ("one" :: "le" :: s) := add_comm_prefix is_comm "nonneg" :: tr ff s | is_comm ("one" :: "lt" :: s) := add_comm_prefix is_comm "pos" :: tr ff s | is_comm ("le" :: "one" :: s) := add_comm_prefix is_comm "nonpos" :: tr ff s | is_comm ("lt" :: "one" :: s) := add_comm_prefix is_comm "neg" :: tr ff s | is_comm ("mul" :: s) := add_comm_prefix is_comm "add" :: tr ff s | is_comm ("inv" :: s) := add_comm_prefix is_comm "neg" :: tr ff s | is_comm ("div" :: s) := add_comm_prefix is_comm "sub" :: tr ff s | is_comm ("one" :: s) := add_comm_prefix is_comm "zero" :: tr ff s | is_comm ("prod" :: s) := add_comm_prefix is_comm "sum" :: tr ff s | is_comm ("monoid" :: s) := ("add_" ++ add_comm_prefix is_comm "monoid") :: tr ff s | is_comm ("submonoid" :: s) := ("add_" ++ add_comm_prefix is_comm "submonoid") :: tr ff s | is_comm ("group" :: s) := ("add_" ++ add_comm_prefix is_comm "group") :: tr ff s | is_comm ("subgroup" :: s) := ("add_" ++ add_comm_prefix is_comm "subgroup") :: tr ff s | is_comm ("semigroup" :: s) := ("add_" ++ add_comm_prefix is_comm "semigroup") :: tr ff s | is_comm ("magma" :: s) := ("add_" ++ add_comm_prefix is_comm "magma") :: tr ff s | is_comm ("comm" :: s) := tr tt s | is_comm (x :: s) := (add_comm_prefix is_comm x :: tr ff s) | tt [] := ["comm"] | ff [] := [] /-- Autogenerate target name for `to_additive`. -/ meta def guess_name : string → string := string.map_tokens ''' $ λ s, string.intercalate (string.singleton '_') $ tr ff (s.split_on '_') /-- Return the provided target name or autogenerate one if one was not provided. -/ meta def target_name (src tgt : name) (dict : name_map name) : tactic name := (if tgt.get_prefix ≠ name.anonymous -- `tgt` is a full name then pure tgt else match src with | (name.mk_string s pre) := do let tgt_auto := guess_name s, guard (tgt.to_string ≠ tgt_auto) <|> trace ("`to_additive " ++ src.to_string ++ "`: correctly autogenerated target " ++ "name, you may remove the explicit " ++ tgt_auto ++ " argument."), pure $ name.mk_string (if tgt = name.anonymous then tgt_auto else tgt.to_string) (pre.map_prefix dict.find) | _ := fail ("to_additive: can't transport " ++ src.to_string) end) >>= (λ res, if res = src then fail ("to_additive: can't transport " ++ src.to_string ++ " to itself") else pure res) /-- the parser for the arguments to `to_additive` -/ meta def parser : lean.parser value_type := do tgt ← optional lean.parser.ident, e ← optional interactive.types.texpr, doc ← match e with | some pe := some <$> ((to_expr pe >>= eval_expr string) : tactic string) | none := pure none end, return ⟨tgt.get_or_else name.anonymous, doc⟩ private meta def proceed_fields_aux (src tgt : name) (prio : ℕ) (f : name → tactic (list string)) : command := do src_fields ← f src, tgt_fields ← f tgt, guard (src_fields.length = tgt_fields.length) <|> fail ("Failed to map fields of " ++ src.to_string), (src_fields.zip tgt_fields).mmap' $ λ names, guard (names.fst = names.snd) <|> aux_attr.set (src.append names.fst) (tgt.append names.snd) tt prio /-- Add the `aux_attr` attribute to the structure fields of `src` so that future uses of `to_additive` will map them to the corresponding `tgt` fields. -/ meta def proceed_fields (env : environment) (src tgt : name) (prio : ℕ) : command := let aux := proceed_fields_aux src tgt prio in do aux (λ n, pure $ list.map name.to_string $ (env.structure_fields n).get_or_else []) >> aux (λ n, (list.map (λ (x : name), "to_" ++ x.to_string) <$> get_tagged_ancestors n)) >> aux (λ n, (env.constructors_of n).mmap $ λ cs, match cs with | (name.mk_string s pre) := (guard (pre = n) <|> fail "Bad constructor name") >> pure s | _ := fail "Bad constructor name" end) /-- The attribute `to_additive` can be used to automatically transport theorems and definitions (but not inductive types and structures) from a multiplicative theory to an additive theory. To use this attribute, just write: ``` @[to_additive] theorem mul_comm' {α} [comm_semigroup α] (x y : α) : x * y = y * x := comm_semigroup.mul_comm ``` This code will generate a theorem named `add_comm'`. It is also possible to manually specify the name of the new declaration, and provide a documentation string: ``` @[to_additive add_foo "add_foo doc string"] /-- foo doc string -/ theorem foo := sorry ``` The transport tries to do the right thing in most cases using several heuristics described below. However, in some cases it fails, and requires manual intervention. If the declaration to be transported has attributes which need to be copied to the additive version, then `to_additive` should come last: ``` @[simp, to_additive] lemma mul_one' {G : Type*} [group G] (x : G) : x * 1 = x := mul_one x ``` ## Implementation notes The transport process generally works by taking all the names of identifiers appearing in the name, type, and body of a declaration and creating a new declaration by mapping those names to additive versions using a simple string-based dictionary and also using all declarations that have previously been labeled with `to_additive`. In the `mul_comm'` example above, `to_additive` maps: * `mul_comm'` to `add_comm'`, * `comm_semigroup` to `add_comm_semigroup`, * `x * y` to `x + y` and `y * x` to `y + x`, and * `comm_semigroup.mul_comm'` to `add_comm_semigroup.add_comm'`. Even when `to_additive` is unable to automatically generate the additive version of a declaration, it can be useful to apply the attribute manually: ``` attribute [to_additive foo_add_bar] foo_bar ``` This will allow future uses of `to_additive` to recognize that `foo_bar` should be replaced with `foo_add_bar`. ### Handling of hidden definitions Before transporting the “main” declaration `src`, `to_additive` first scans its type and value for names starting with `src`, and transports them. This includes auxiliary definitions like `src._match_1`, `src._proof_1`. After transporting the “main” declaration, `to_additive` transports its equational lemmas. ### Structure fields and constructors If `src` is a structure, then `to_additive` automatically adds structure fields to its mapping, and similarly for constructors of inductive types. For new structures this means that `to_additive` automatically handles coercions, and for old structures it does the same, if ancestry information is present in `@[ancestor]` attributes. ### Name generation * If `@[to_additive]` is called without a `name` argument, then the new name is autogenerated. First, it takes the longest prefix of the source name that is already known to `to_additive`, and replaces this prefix with its additive counterpart. Second, it takes the last part of the name (i.e., after the last dot), and replaces common name parts (“mul”, “one”, “inv”, “prod”) with their additive versions. * Namespaces can be transformed using `map_namespace`. For example: ``` run_cmd to_additive.map_namespace `quotient_group `quotient_add_group ``` Later uses of `to_additive` on declarations in the `quotient_group` namespace will be created in the `quotient_add_group` namespaces. * If `@[to_additive]` is called with a `name` argument `new_name` /without a dot/, then `to_additive` updates the prefix as described above, then replaces the last part of the name with `new_name`. * If `@[to_additive]` is called with a `name` argument `new_namespace.new_name` /with a dot/, then `to_additive` uses this new name as is. As a safety check, in the first two cases `to_additive` double checks that the new name differs from the original one. -/ @[user_attribute] protected meta def attr : user_attribute unit value_type := { name := `to_additive, descr := "Transport multiplicative to additive", parser := parser, after_set := some $ λ src prio persistent, do guard persistent <|> fail "`to_additive` can't be used as a local attribute", env ← get_env, val ← attr.get_param src, dict ← aux_attr.get_cache, tgt ← target_name src val.tgt dict, aux_attr.set src tgt tt, let dict := dict.insert src tgt, if env.contains tgt then proceed_fields env src tgt prio else do transform_decl_with_prefix_dict dict src tgt [`reducible, `simp, `instance, `refl, `symm, `trans, `elab_as_eliminator, `no_rsimp], match val.doc with | some doc := add_doc_string tgt doc | none := skip end } add_tactic_doc { name := "to_additive", category := doc_category.attr, decl_names := [`to_additive.attr], tags := ["transport", "environment", "lemma derivation"] } end to_additive /- map operations -/ attribute [to_additive] has_mul has_one has_inv has_div
8f3e601f2c1e9e0eeb138213bbc52ce98ae04fea
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/category_theory/triangulated/basic.lean
e4af0a0f3157860b2c52ceacc0e70352e9078d2a
[ "Apache-2.0" ]
permissive
robertylewis/mathlib
3d16e3e6daf5ddde182473e03a1b601d2810952c
1d13f5b932f5e40a8308e3840f96fc882fae01f0
refs/heads/master
1,651,379,945,369
1,644,276,960,000
1,644,276,960,000
98,875,504
0
0
Apache-2.0
1,644,253,514,000
1,501,495,700,000
Lean
UTF-8
Lean
false
false
3,980
lean
/- Copyright (c) 2021 Luke Kershaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Luke Kershaw -/ import category_theory.shift /-! # Triangles This file contains the definition of triangles in an additive category with an additive shift. It also defines morphisms between these triangles. TODO: generalise this to n-angles in n-angulated categories as in https://arxiv.org/abs/1006.4592 -/ noncomputable theory open category_theory open category_theory.limits universes v v₀ v₁ v₂ u u₀ u₁ u₂ namespace category_theory.triangulated open category_theory.category /- We work in a category `C` equipped with a shift. -/ variables (C : Type u) [category.{v} C] [has_shift C ℤ] /-- A triangle in `C` is a sextuple `(X,Y,Z,f,g,h)` where `X,Y,Z` are objects of `C`, and `f : X ⟶ Y`, `g : Y ⟶ Z`, `h : Z ⟶ X⟦1⟧` are morphisms in `C`. See https://stacks.math.columbia.edu/tag/0144. -/ structure triangle := mk' :: (obj₁ : C) (obj₂ : C) (obj₃ : C) (mor₁ : obj₁ ⟶ obj₂) (mor₂ : obj₂ ⟶ obj₃) (mor₃ : obj₃ ⟶ obj₁⟦(1:ℤ)⟧) /-- A triangle `(X,Y,Z,f,g,h)` in `C` is defined by the morphisms `f : X ⟶ Y`, `g : Y ⟶ Z` and `h : Z ⟶ X⟦1⟧`. -/ @[simps] def triangle.mk {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (h : Z ⟶ X⟦(1:ℤ)⟧) : triangle C := { obj₁ := X, obj₂ := Y, obj₃ := Z, mor₁ := f, mor₂ := g, mor₃ := h } section variables [has_zero_object C] [has_zero_morphisms C] open_locale zero_object instance : inhabited (triangle C) := ⟨⟨0,0,0,0,0,0⟩⟩ /-- For each object in `C`, there is a triangle of the form `(X,X,0,𝟙 X,0,0)` -/ @[simps] def contractible_triangle (X : C) : triangle C := triangle.mk C (𝟙 X) (0 : X ⟶ 0) 0 end variable {C} /-- A morphism of triangles `(X,Y,Z,f,g,h) ⟶ (X',Y',Z',f',g',h')` in `C` is a triple of morphisms `a : X ⟶ X'`, `b : Y ⟶ Y'`, `c : Z ⟶ Z'` such that `a ≫ f' = f ≫ b`, `b ≫ g' = g ≫ c`, and `a⟦1⟧' ≫ h = h' ≫ c`. In other words, we have a commutative diagram: ``` f g h X ───> Y ───> Z ───> X⟦1⟧ │ │ │ │ │a │b │c │a⟦1⟧' V V V V X' ───> Y' ───> Z' ───> X'⟦1⟧ f' g' h' ``` See https://stacks.math.columbia.edu/tag/0144. -/ @[ext] structure triangle_morphism (T₁ : triangle C) (T₂ : triangle C) := (hom₁ : T₁.obj₁ ⟶ T₂.obj₁) (hom₂ : T₁.obj₂ ⟶ T₂.obj₂) (hom₃ : T₁.obj₃ ⟶ T₂.obj₃) (comm₁' : T₁.mor₁ ≫ hom₂ = hom₁ ≫ T₂.mor₁ . obviously) (comm₂' : T₁.mor₂ ≫ hom₃ = hom₂ ≫ T₂.mor₂ . obviously) (comm₃' : T₁.mor₃ ≫ hom₁⟦1⟧' = hom₃ ≫ T₂.mor₃ . obviously) restate_axiom triangle_morphism.comm₁' restate_axiom triangle_morphism.comm₂' restate_axiom triangle_morphism.comm₃' attribute [simp, reassoc] triangle_morphism.comm₁ triangle_morphism.comm₂ triangle_morphism.comm₃ /-- The identity triangle morphism. -/ @[simps] def triangle_morphism_id (T : triangle C) : triangle_morphism T T := { hom₁ := 𝟙 T.obj₁, hom₂ := 𝟙 T.obj₂, hom₃ := 𝟙 T.obj₃ } instance (T : triangle C) : inhabited (triangle_morphism T T) := ⟨triangle_morphism_id T⟩ variables {T₁ T₂ T₃ : triangle C} /-- Composition of triangle morphisms gives a triangle morphism. -/ @[simps] def triangle_morphism.comp (f : triangle_morphism T₁ T₂) (g : triangle_morphism T₂ T₃) : triangle_morphism T₁ T₃ := { hom₁ := f.hom₁ ≫ g.hom₁, hom₂ := f.hom₂ ≫ g.hom₂, hom₃ := f.hom₃ ≫ g.hom₃ } /-- Triangles with triangle morphisms form a category. -/ @[simps] instance triangle_category : category (triangle C) := { hom := λ A B, triangle_morphism A B, id := λ A, triangle_morphism_id A, comp := λ A B C f g, f.comp g } end category_theory.triangulated
1ad2e0fe5c2cca77072ea60dd57fefef0c79771d
f68c8823d8ddc719de8a4513815174aa7408ac4a
/lean_resolutions/PUZ139_1.lean
3faf9014cbcaba4ec7db8b54c8989e125e70acb1
[]
no_license
FredsoNerd/tptp-lean-puzzles
e7ea66a0de9aa3cb7cc7480299f01adf885440a6
43d4d77524e797a4ac7a62b2cfaf8df08b409815
refs/heads/master
1,606,359,611,765
1,576,824,274,000
1,576,824,274,000
228,945,807
4
0
null
null
null
null
UTF-8
Lean
false
false
1,487
lean
-------------------------------------------------------------------------------- -- File : PUZ139_1 : TPTP v7.3.0. Released v6.1.0. -- Domain : Puzzles -- Problem : Caramel vanilla coffee helps people stay awake -- Version : Especial. -- English : -- Refs : [Arh14] Arhami (2010), Email to Geoff Sutcliffe -- Source : [Arh14] -------------------------------------------------------------------------------- variable beverage: Type variable syrup: Type ----Coffee is a beverage variable coffee: beverage ----Vanilla syrup is a syrup variable vanilla_syrup: syrup ----Caramel syrup is a syrup variable caramel_syrup: syrup ----The mixture of a syrup and a beverage is a beverage ----The mixture of a syrup and a syrup is a syrup variable mixture: ∀ BeverageOrSyrup: Type, (( BeverageOrSyrup × syrup ) → BeverageOrSyrup) ----The mixture of coffee and any syrup helps people stay awake variable help_people_stay_awake: beverage → Prop variable mixture_of_coffee_help_people_stay_awake: ∀ (S: syrup), help_people_stay_awake(mixture beverage (coffee,S)) ----Caramel vanilla coffee help people stay awake include mixture_of_coffee_help_people_stay_awake theorem caramel_vanilla_coffee_help_people_stay_awake : help_people_stay_awake (mixture beverage (coffee, mixture syrup (caramel_syrup, vanilla_syrup))) := begin have a, from mixture_of_coffee_help_people_stay_awake (mixture syrup (caramel_syrup, vanilla_syrup)), assumption end
037e58aba62dbd6946efeed7d134fc1017e26568
82e44445c70db0f03e30d7be725775f122d72f3e
/src/algebra/ordered_field.lean
5ce8c458c9a87e375accdf774496d7307b1cea51
[ "Apache-2.0" ]
permissive
stjordanis/mathlib
51e286d19140e3788ef2c470bc7b953e4991f0c9
2568d41bca08f5d6bf39d915434c8447e21f42ee
refs/heads/master
1,631,748,053,501
1,627,938,886,000
1,627,938,886,000
228,728,358
0
0
Apache-2.0
1,576,630,588,000
1,576,630,587,000
null
UTF-8
Lean
false
false
27,635
lean
/- Copyright (c) 2014 Robert Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn -/ import algebra.ordered_ring import algebra.field import tactic.monotonicity.basic import algebra.group_power.order import order.order_dual /-! # Linear ordered fields A linear ordered field is a field equipped with a linear order such that * addition respects the order: `a ≤ b → c + a ≤ c + b`; * multiplication of positives is positive: `0 < a → 0 < b → 0 < a * b`; * `0 < 1`. ## Main Definitions * `linear_ordered_field`: the class of linear ordered fields. -/ set_option old_structure_cmd true variable {α : Type*} /-- A linear ordered field is a field with a linear order respecting the operations. -/ @[protect_proj] class linear_ordered_field (α : Type*) extends linear_ordered_comm_ring α, field α section linear_ordered_field variables [linear_ordered_field α] {a b c d e : α} section /-- `equiv.mul_left'` as an order_iso. -/ @[simps {simp_rhs := tt}] def order_iso.mul_left' (a : α) (ha : 0 < a) : α ≃o α := { map_rel_iff' := λ _ _, mul_le_mul_left ha, ..equiv.mul_left' a ha.ne' } /-- `equiv.mul_right'` as an order_iso. -/ @[simps {simp_rhs := tt}] def order_iso.mul_right' (a : α) (ha : 0 < a) : α ≃o α := { map_rel_iff' := λ _ _, mul_le_mul_right ha, ..equiv.mul_right' a ha.ne' } end /-! ### Lemmas about pos, nonneg, nonpos, neg -/ @[simp] lemma inv_pos : 0 < a⁻¹ ↔ 0 < a := suffices ∀ a : α, 0 < a → 0 < a⁻¹, from ⟨λ h, inv_inv' a ▸ this _ h, this a⟩, assume a ha, flip lt_of_mul_lt_mul_left ha.le $ by simp [ne_of_gt ha, zero_lt_one] @[simp] lemma inv_nonneg : 0 ≤ a⁻¹ ↔ 0 ≤ a := by simp only [le_iff_eq_or_lt, inv_pos, zero_eq_inv] @[simp] lemma inv_lt_zero : a⁻¹ < 0 ↔ a < 0 := by simp only [← not_le, inv_nonneg] @[simp] lemma inv_nonpos : a⁻¹ ≤ 0 ↔ a ≤ 0 := by simp only [← not_lt, inv_pos] lemma one_div_pos : 0 < 1 / a ↔ 0 < a := inv_eq_one_div a ▸ inv_pos lemma one_div_neg : 1 / a < 0 ↔ a < 0 := inv_eq_one_div a ▸ inv_lt_zero lemma one_div_nonneg : 0 ≤ 1 / a ↔ 0 ≤ a := inv_eq_one_div a ▸ inv_nonneg lemma one_div_nonpos : 1 / a ≤ 0 ↔ a ≤ 0 := inv_eq_one_div a ▸ inv_nonpos lemma div_pos_iff : 0 < a / b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by simp [division_def, mul_pos_iff] lemma div_neg_iff : a / b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b := by simp [division_def, mul_neg_iff] lemma div_nonneg_iff : 0 ≤ a / b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 := by simp [division_def, mul_nonneg_iff] lemma div_nonpos_iff : a / b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b := by simp [division_def, mul_nonpos_iff] lemma div_pos (ha : 0 < a) (hb : 0 < b) : 0 < a / b := div_pos_iff.2 $ or.inl ⟨ha, hb⟩ lemma div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b := div_pos_iff.2 $ or.inr ⟨ha, hb⟩ lemma div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 := div_neg_iff.2 $ or.inr ⟨ha, hb⟩ lemma div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 := div_neg_iff.2 $ or.inl ⟨ha, hb⟩ lemma div_nonneg (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a / b := div_nonneg_iff.2 $ or.inl ⟨ha, hb⟩ lemma div_nonneg_of_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a / b := div_nonneg_iff.2 $ or.inr ⟨ha, hb⟩ lemma div_nonpos_of_nonpos_of_nonneg (ha : a ≤ 0) (hb : 0 ≤ b) : a / b ≤ 0 := div_nonpos_iff.2 $ or.inr ⟨ha, hb⟩ lemma div_nonpos_of_nonneg_of_nonpos (ha : 0 ≤ a) (hb : b ≤ 0) : a / b ≤ 0 := div_nonpos_iff.2 $ or.inl ⟨ha, hb⟩ /-! ### Relating one division with another term. -/ lemma le_div_iff (hc : 0 < c) : a ≤ b / c ↔ a * c ≤ b := ⟨λ h, div_mul_cancel b (ne_of_lt hc).symm ▸ mul_le_mul_of_nonneg_right h hc.le, λ h, calc a = a * c * (1 / c) : mul_mul_div a (ne_of_lt hc).symm ... ≤ b * (1 / c) : mul_le_mul_of_nonneg_right h (one_div_pos.2 hc).le ... = b / c : (div_eq_mul_one_div b c).symm⟩ lemma le_div_iff' (hc : 0 < c) : a ≤ b / c ↔ c * a ≤ b := by rw [mul_comm, le_div_iff hc] lemma div_le_iff (hb : 0 < b) : a / b ≤ c ↔ a ≤ c * b := ⟨λ h, calc a = a / b * b : by rw (div_mul_cancel _ (ne_of_lt hb).symm) ... ≤ c * b : mul_le_mul_of_nonneg_right h hb.le, λ h, calc a / b = a * (1 / b) : div_eq_mul_one_div a b ... ≤ (c * b) * (1 / b) : mul_le_mul_of_nonneg_right h (one_div_pos.2 hb).le ... = (c * b) / b : (div_eq_mul_one_div (c * b) b).symm ... = c : by refine (div_eq_iff (ne_of_gt hb)).mpr rfl⟩ lemma div_le_iff' (hb : 0 < b) : a / b ≤ c ↔ a ≤ b * c := by rw [mul_comm, div_le_iff hb] lemma lt_div_iff (hc : 0 < c) : a < b / c ↔ a * c < b := lt_iff_lt_of_le_iff_le $ div_le_iff hc lemma lt_div_iff' (hc : 0 < c) : a < b / c ↔ c * a < b := by rw [mul_comm, lt_div_iff hc] lemma div_lt_iff (hc : 0 < c) : b / c < a ↔ b < a * c := lt_iff_lt_of_le_iff_le (le_div_iff hc) lemma div_lt_iff' (hc : 0 < c) : b / c < a ↔ b < c * a := by rw [mul_comm, div_lt_iff hc] lemma inv_mul_le_iff (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ b * c := begin rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div], exact div_le_iff' h, end lemma inv_mul_le_iff' (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ c * b := by rw [inv_mul_le_iff h, mul_comm] lemma mul_inv_le_iff (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ b * c := by rw [mul_comm, inv_mul_le_iff h] lemma mul_inv_le_iff' (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ c * b := by rw [mul_comm, inv_mul_le_iff' h] lemma inv_mul_lt_iff (h : 0 < b) : b⁻¹ * a < c ↔ a < b * c := begin rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div], exact div_lt_iff' h, end lemma inv_mul_lt_iff' (h : 0 < b) : b⁻¹ * a < c ↔ a < c * b := by rw [inv_mul_lt_iff h, mul_comm] lemma mul_inv_lt_iff (h : 0 < b) : a * b⁻¹ < c ↔ a < b * c := by rw [mul_comm, inv_mul_lt_iff h] lemma mul_inv_lt_iff' (h : 0 < b) : a * b⁻¹ < c ↔ a < c * b := by rw [mul_comm, inv_mul_lt_iff' h] lemma inv_pos_le_iff_one_le_mul (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ b * a := by { rw [inv_eq_one_div], exact div_le_iff ha } lemma inv_pos_le_iff_one_le_mul' (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ a * b := by { rw [inv_eq_one_div], exact div_le_iff' ha } lemma inv_pos_lt_iff_one_lt_mul (ha : 0 < a) : a⁻¹ < b ↔ 1 < b * a := by { rw [inv_eq_one_div], exact div_lt_iff ha } lemma inv_pos_lt_iff_one_lt_mul' (ha : 0 < a) : a⁻¹ < b ↔ 1 < a * b := by { rw [inv_eq_one_div], exact div_lt_iff' ha } lemma div_le_iff_of_neg (hc : c < 0) : b / c ≤ a ↔ a * c ≤ b := ⟨λ h, div_mul_cancel b (ne_of_lt hc) ▸ mul_le_mul_of_nonpos_right h hc.le, λ h, calc a = a * c * (1 / c) : mul_mul_div a (ne_of_lt hc) ... ≥ b * (1 / c) : mul_le_mul_of_nonpos_right h (one_div_neg.2 hc).le ... = b / c : (div_eq_mul_one_div b c).symm⟩ lemma div_le_iff_of_neg' (hc : c < 0) : b / c ≤ a ↔ c * a ≤ b := by rw [mul_comm, div_le_iff_of_neg hc] lemma le_div_iff_of_neg (hc : c < 0) : a ≤ b / c ↔ b ≤ a * c := by rw [← neg_neg c, mul_neg_eq_neg_mul_symm, div_neg, le_neg, div_le_iff (neg_pos.2 hc), neg_mul_eq_neg_mul_symm] lemma le_div_iff_of_neg' (hc : c < 0) : a ≤ b / c ↔ b ≤ c * a := by rw [mul_comm, le_div_iff_of_neg hc] lemma div_lt_iff_of_neg (hc : c < 0) : b / c < a ↔ a * c < b := lt_iff_lt_of_le_iff_le $ le_div_iff_of_neg hc lemma div_lt_iff_of_neg' (hc : c < 0) : b / c < a ↔ c * a < b := by rw [mul_comm, div_lt_iff_of_neg hc] lemma lt_div_iff_of_neg (hc : c < 0) : a < b / c ↔ b < a * c := lt_iff_lt_of_le_iff_le $ div_le_iff_of_neg hc lemma lt_div_iff_of_neg' (hc : c < 0) : a < b / c ↔ b < c * a := by rw [mul_comm, lt_div_iff_of_neg hc] /-- One direction of `div_le_iff` where `b` is allowed to be `0` (but `c` must be nonnegative) -/ lemma div_le_of_nonneg_of_le_mul (hb : 0 ≤ b) (hc : 0 ≤ c) (h : a ≤ c * b) : a / b ≤ c := by { rcases eq_or_lt_of_le hb with rfl|hb', simp [hc], rwa [div_le_iff hb'] } lemma div_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : a / b ≤ 1 := div_le_of_nonneg_of_le_mul hb zero_le_one $ by rwa one_mul /-! ### Bi-implications of inequalities using inversions -/ lemma inv_le_inv_of_le (ha : 0 < a) (h : a ≤ b) : b⁻¹ ≤ a⁻¹ := by rwa [← one_div a, le_div_iff' ha, ← div_eq_mul_inv, div_le_iff (ha.trans_le h), one_mul] /-- See `inv_le_inv_of_le` for the implication from right-to-left with one fewer assumption. -/ lemma inv_le_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by rw [← one_div, div_le_iff ha, ← div_eq_inv_mul, le_div_iff hb, one_mul] lemma inv_le (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by rw [← inv_le_inv hb (inv_pos.2 ha), inv_inv'] lemma le_inv (ha : 0 < a) (hb : 0 < b) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by rw [← inv_le_inv (inv_pos.2 hb) ha, inv_inv'] lemma inv_lt_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b⁻¹ ↔ b < a := lt_iff_lt_of_le_iff_le (inv_le_inv hb ha) lemma inv_lt (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b ↔ b⁻¹ < a := lt_iff_lt_of_le_iff_le (le_inv hb ha) lemma lt_inv (ha : 0 < a) (hb : 0 < b) : a < b⁻¹ ↔ b < a⁻¹ := lt_iff_lt_of_le_iff_le (inv_le hb ha) lemma inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by rw [← one_div, div_le_iff_of_neg ha, ← div_eq_inv_mul, div_le_iff_of_neg hb, one_mul] lemma inv_le_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by rw [← inv_le_inv_of_neg hb (inv_lt_zero.2 ha), inv_inv'] lemma le_inv_of_neg (ha : a < 0) (hb : b < 0) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by rw [← inv_le_inv_of_neg (inv_lt_zero.2 hb) ha, inv_inv'] lemma inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b⁻¹ ↔ b < a := lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha) lemma inv_lt_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b ↔ b⁻¹ < a := lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha) lemma lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < b⁻¹ ↔ b < a⁻¹ := lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha) lemma inv_lt_one (ha : 1 < a) : a⁻¹ < 1 := by rwa [inv_lt ((@zero_lt_one α _ _).trans ha) zero_lt_one, inv_one] lemma one_lt_inv (h₁ : 0 < a) (h₂ : a < 1) : 1 < a⁻¹ := by rwa [lt_inv (@zero_lt_one α _ _) h₁, inv_one] lemma inv_le_one (ha : 1 ≤ a) : a⁻¹ ≤ 1 := by rwa [inv_le ((@zero_lt_one α _ _).trans_le ha) zero_lt_one, inv_one] lemma one_le_inv (h₁ : 0 < a) (h₂ : a ≤ 1) : 1 ≤ a⁻¹ := by rwa [le_inv (@zero_lt_one α _ _) h₁, inv_one] lemma inv_lt_one_iff_of_pos (h₀ : 0 < a) : a⁻¹ < 1 ↔ 1 < a := ⟨λ h₁, inv_inv' a ▸ one_lt_inv (inv_pos.2 h₀) h₁, inv_lt_one⟩ lemma inv_lt_one_iff : a⁻¹ < 1 ↔ a ≤ 0 ∨ 1 < a := begin cases le_or_lt a 0 with ha ha, { simp [ha, (inv_nonpos.2 ha).trans_lt zero_lt_one] }, { simp only [ha.not_le, false_or, inv_lt_one_iff_of_pos ha] } end lemma one_lt_inv_iff : 1 < a⁻¹ ↔ 0 < a ∧ a < 1 := ⟨λ h, ⟨inv_pos.1 (zero_lt_one.trans h), inv_inv' a ▸ inv_lt_one h⟩, and_imp.2 one_lt_inv⟩ lemma inv_le_one_iff : a⁻¹ ≤ 1 ↔ a ≤ 0 ∨ 1 ≤ a := begin rcases em (a = 1) with (rfl|ha), { simp [le_rfl] }, { simp only [ne.le_iff_lt (ne.symm ha), ne.le_iff_lt (mt inv_eq_one'.1 ha), inv_lt_one_iff] } end lemma one_le_inv_iff : 1 ≤ a⁻¹ ↔ 0 < a ∧ a ≤ 1 := ⟨λ h, ⟨inv_pos.1 (zero_lt_one.trans_le h), inv_inv' a ▸ inv_le_one h⟩, and_imp.2 one_le_inv⟩ /-! ### Relating two divisions. -/ @[mono] lemma div_le_div_of_le (hc : 0 ≤ c) (h : a ≤ b) : a / c ≤ b / c := begin rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c], exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 hc) end @[mono] lemma div_le_div_of_le_left (ha : 0 ≤ a) (hc : 0 < c) (h : c ≤ b) : a / b ≤ a / c := begin rw [div_eq_mul_inv, div_eq_mul_inv], exact mul_le_mul_of_nonneg_left ((inv_le_inv (hc.trans_le h) hc).mpr h) ha end lemma div_le_div_of_le_of_nonneg (hab : a ≤ b) (hc : 0 ≤ c) : a / c ≤ b / c := div_le_div_of_le hc hab lemma div_le_div_of_nonpos_of_le (hc : c ≤ 0) (h : b ≤ a) : a / c ≤ b / c := begin rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c], exact mul_le_mul_of_nonpos_right h (one_div_nonpos.2 hc) end lemma div_lt_div_of_lt (hc : 0 < c) (h : a < b) : a / c < b / c := begin rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c], exact mul_lt_mul_of_pos_right h (one_div_pos.2 hc) end lemma div_lt_div_of_neg_of_lt (hc : c < 0) (h : b < a) : a / c < b / c := begin rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c], exact mul_lt_mul_of_neg_right h (one_div_neg.2 hc) end lemma div_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b := ⟨le_imp_le_of_lt_imp_lt $ div_lt_div_of_lt hc, div_le_div_of_le $ hc.le⟩ lemma div_le_div_right_of_neg (hc : c < 0) : a / c ≤ b / c ↔ b ≤ a := ⟨le_imp_le_of_lt_imp_lt $ div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le $ hc.le⟩ lemma div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := lt_iff_lt_of_le_iff_le $ div_le_div_right hc lemma div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c ↔ b < a := lt_iff_lt_of_le_iff_le $ div_le_div_right_of_neg hc lemma div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b := by simp only [div_eq_mul_inv, mul_lt_mul_left ha, inv_lt_inv hb hc] lemma div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≤ a / c ↔ c ≤ b := le_iff_le_iff_lt_iff_lt.2 (div_lt_div_left ha hc hb) lemma div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b := by rw [lt_div_iff d0, div_mul_eq_mul_div, div_lt_iff b0] lemma div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≤ c / d ↔ a * d ≤ c * b := by rw [le_div_iff d0, div_mul_eq_mul_div, div_le_iff b0] @[mono] lemma div_le_div (hc : 0 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ c / d := by { rw div_le_div_iff (hd.trans_le hbd) hd, exact mul_le_mul hac hbd hd.le hc } lemma div_lt_div (hac : a < c) (hbd : d ≤ b) (c0 : 0 ≤ c) (d0 : 0 < d) : a / b < c / d := (div_lt_div_iff (d0.trans_le hbd) d0).2 (mul_lt_mul hac hbd d0 c0) lemma div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d := (div_lt_div_iff (d0.trans hbd) d0).2 (mul_lt_mul' hac hbd d0.le c0) lemma div_lt_div_of_lt_left (hb : 0 < b) (h : b < a) (hc : 0 < c) : c / a < c / b := (div_lt_div_left hc (hb.trans h) hb).mpr h /-! ### Relating one division and involving `1` -/ lemma one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a := by rw [le_div_iff hb, one_mul] lemma div_le_one (hb : 0 < b) : a / b ≤ 1 ↔ a ≤ b := by rw [div_le_iff hb, one_mul] lemma one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iff hb, one_mul] lemma div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iff hb, one_mul] lemma one_le_div_of_neg (hb : b < 0) : 1 ≤ a / b ↔ a ≤ b := by rw [le_div_iff_of_neg hb, one_mul] lemma div_le_one_of_neg (hb : b < 0) : a / b ≤ 1 ↔ b ≤ a := by rw [div_le_iff_of_neg hb, one_mul] lemma one_lt_div_of_neg (hb : b < 0) : 1 < a / b ↔ a < b := by rw [lt_div_iff_of_neg hb, one_mul] lemma div_lt_one_of_neg (hb : b < 0) : a / b < 1 ↔ b < a := by rw [div_lt_iff_of_neg hb, one_mul] lemma one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ b ↔ 1 / b ≤ a := by simpa using inv_le ha hb lemma one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt ha hb lemma le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a := by simpa using le_inv ha hb lemma lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv ha hb lemma one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ b ↔ 1 / b ≤ a := by simpa using inv_le_of_neg ha hb lemma one_div_lt_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt_of_neg ha hb lemma le_one_div_of_neg (ha : a < 0) (hb : b < 0) : a ≤ 1 / b ↔ b ≤ 1 / a := by simpa using le_inv_of_neg ha hb lemma lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv_of_neg ha hb lemma one_lt_div_iff : 1 < a / b ↔ 0 < b ∧ b < a ∨ b < 0 ∧ a < b := begin rcases lt_trichotomy b 0 with (hb|rfl|hb), { simp [hb, hb.not_lt, one_lt_div_of_neg] }, { simp [lt_irrefl, zero_le_one] }, { simp [hb, hb.not_lt, one_lt_div] } end lemma one_le_div_iff : 1 ≤ a / b ↔ 0 < b ∧ b ≤ a ∨ b < 0 ∧ a ≤ b := begin rcases lt_trichotomy b 0 with (hb|rfl|hb), { simp [hb, hb.not_lt, one_le_div_of_neg] }, { simp [lt_irrefl, zero_lt_one.not_le, zero_lt_one] }, { simp [hb, hb.not_lt, one_le_div] } end lemma div_lt_one_iff : a / b < 1 ↔ 0 < b ∧ a < b ∨ b = 0 ∨ b < 0 ∧ b < a := begin rcases lt_trichotomy b 0 with (hb|rfl|hb), { simp [hb, hb.not_lt, hb.ne, div_lt_one_of_neg] }, { simp [zero_lt_one], }, { simp [hb, hb.not_lt, div_lt_one, hb.ne.symm] } end lemma div_le_one_iff : a / b ≤ 1 ↔ 0 < b ∧ a ≤ b ∨ b = 0 ∨ b < 0 ∧ b ≤ a := begin rcases lt_trichotomy b 0 with (hb|rfl|hb), { simp [hb, hb.not_lt, hb.ne, div_le_one_of_neg] }, { simp [zero_le_one], }, { simp [hb, hb.not_lt, div_le_one, hb.ne.symm] } end /-! ### Relating two divisions, involving `1` -/ lemma one_div_le_one_div_of_le (ha : 0 < a) (h : a ≤ b) : 1 / b ≤ 1 / a := by simpa using inv_le_inv_of_le ha h lemma one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by rwa [lt_div_iff' ha, ← div_eq_mul_one_div, div_lt_one (ha.trans h)] lemma one_div_le_one_div_of_neg_of_le (hb : b < 0) (h : a ≤ b) : 1 / b ≤ 1 / a := by rwa [div_le_iff_of_neg' hb, ← div_eq_mul_one_div, div_le_one_of_neg (h.trans_lt hb)] lemma one_div_lt_one_div_of_neg_of_lt (hb : b < 0) (h : a < b) : 1 / b < 1 / a := by rwa [div_lt_iff_of_neg' hb, ← div_eq_mul_one_div, div_lt_one_of_neg (h.trans hb)] lemma le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≤ 1 / b) : b ≤ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h lemma lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h lemma le_of_neg_of_one_div_le_one_div (hb : b < 0) (h : 1 / a ≤ 1 / b) : b ≤ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_neg_of_lt hb) h lemma lt_of_neg_of_one_div_lt_one_div (hb : b < 0) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_neg_of_le hb) h /-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and `le_of_one_div_le_one_div` -/ lemma one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ 1 / b ↔ b ≤ a := div_le_div_left zero_lt_one ha hb /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and `lt_of_one_div_lt_one_div` -/ lemma one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b ↔ b < a := div_lt_div_left zero_lt_one ha hb /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_neg_of_lt` and `lt_of_one_div_lt_one_div` -/ lemma one_div_le_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ 1 / b ↔ b ≤ a := by simpa [one_div] using inv_le_inv_of_neg ha hb /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and `lt_of_one_div_lt_one_div` -/ lemma one_div_lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < 1 / b ↔ b < a := lt_iff_lt_of_le_iff_le (one_div_le_one_div_of_neg hb ha) lemma one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by rwa [lt_one_div (@zero_lt_one α _ _) h1, one_div_one] lemma one_le_one_div (h1 : 0 < a) (h2 : a ≤ 1) : 1 ≤ 1 / a := by rwa [le_one_div (@zero_lt_one α _ _) h1, one_div_one] lemma one_div_lt_neg_one (h1 : a < 0) (h2 : -1 < a) : 1 / a < -1 := suffices 1 / a < 1 / -1, by rwa one_div_neg_one_eq_neg_one at this, one_div_lt_one_div_of_neg_of_lt h1 h2 lemma one_div_le_neg_one (h1 : a < 0) (h2 : -1 ≤ a) : 1 / a ≤ -1 := suffices 1 / a ≤ 1 / -1, by rwa one_div_neg_one_eq_neg_one at this, one_div_le_one_div_of_neg_of_le h1 h2 /-! ### Results about halving. The equalities also hold in fields of characteristic `0`. -/ lemma add_halves (a : α) : a / 2 + a / 2 = a := by rw [div_add_div_same, ← two_mul, mul_div_cancel_left a two_ne_zero] lemma sub_self_div_two (a : α) : a - a / 2 = a / 2 := suffices a / 2 + a / 2 - a / 2 = a / 2, by rwa add_halves at this, by rw [add_sub_cancel] lemma div_two_sub_self (a : α) : a / 2 - a = - (a / 2) := suffices a / 2 - (a / 2 + a / 2) = - (a / 2), by rwa add_halves at this, by rw [sub_add_eq_sub_sub, sub_self, zero_sub] lemma add_self_div_two (a : α) : (a + a) / 2 = a := by rw [← mul_two, mul_div_cancel a two_ne_zero] lemma half_pos (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two lemma one_half_pos : (0:α) < 1 / 2 := half_pos zero_lt_one lemma div_two_lt_of_pos (h : 0 < a) : a / 2 < a := by { rw [div_lt_iff (@zero_lt_two α _ _)], exact lt_mul_of_one_lt_right h one_lt_two } lemma half_lt_self : 0 < a → a / 2 < a := div_two_lt_of_pos lemma half_le_self (ha_nonneg : 0 ≤ a) : a / 2 ≤ a := begin by_cases h0 : a = 0, { simp [h0], }, { rw ← ne.def at h0, exact (half_lt_self (lt_of_le_of_ne ha_nonneg h0.symm)).le, }, end lemma one_half_lt_one : (1 / 2 : α) < 1 := half_lt_self zero_lt_one lemma add_sub_div_two_lt (h : a < b) : a + (b - a) / 2 < b := begin rwa [← div_sub_div_same, sub_eq_add_neg, add_comm (b/2), ← add_assoc, ← sub_eq_add_neg, ← lt_sub_iff_add_lt, sub_self_div_two, sub_self_div_two, div_lt_div_right (@zero_lt_two α _ _)] end /-- An inequality involving `2`. -/ lemma sub_one_div_inv_le_two (a2 : 2 ≤ a) : (1 - 1 / a)⁻¹ ≤ 2 := begin -- Take inverses on both sides to obtain `2⁻¹ ≤ 1 - 1 / a` refine trans (inv_le_inv_of_le (inv_pos.mpr zero_lt_two) _) (inv_inv' (2 : α)).le, -- move `1 / a` to the left and `1 - 1 / 2 = 1 / 2` to the right to obtain `1 / a ≤ ⅟ 2` refine trans ((le_sub_iff_add_le.mpr ((_ : _ + 2⁻¹ = _ ).le))) ((sub_le_sub_iff_left 1).mpr _), { -- show 2⁻¹ + 2⁻¹ = 1 exact trans (two_mul _).symm (mul_inv_cancel two_ne_zero) }, { -- take inverses on both sides and use the assumption `2 ≤ a`. exact (one_div a).le.trans (inv_le_inv_of_le zero_lt_two a2) } end /-! ### Miscellaneous lemmas -/ /-- Pullback a `linear_ordered_field` under an injective map. See note [reducible non-instances]. -/ @[reducible] def function.injective.linear_ordered_field {β : Type*} [has_zero β] [has_one β] [has_add β] [has_mul β] [has_neg β] [has_sub β] [has_inv β] [has_div β] [nontrivial β] (f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (inv : ∀ x, f (x⁻¹) = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y) : linear_ordered_field β := { ..hf.linear_ordered_ring f zero one add mul neg sub, ..hf.field f zero one add mul neg sub inv div} lemma mul_sub_mul_div_mul_neg_iff (hc : c ≠ 0) (hd : d ≠ 0) : (a * d - b * c) / (c * d) < 0 ↔ a / c < b / d := by rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_lt_zero] alias mul_sub_mul_div_mul_neg_iff ↔ div_lt_div_of_mul_sub_mul_div_neg mul_sub_mul_div_mul_neg lemma mul_sub_mul_div_mul_nonpos_iff (hc : c ≠ 0) (hd : d ≠ 0) : (a * d - b * c) / (c * d) ≤ 0 ↔ a / c ≤ b / d := by rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_nonpos] alias mul_sub_mul_div_mul_nonpos_iff ↔ div_le_div_of_mul_sub_mul_div_nonpos mul_sub_mul_div_mul_nonpos lemma mul_le_mul_of_mul_div_le (h : a * (b / c) ≤ d) (hc : 0 < c) : b * a ≤ d * c := begin rw [← mul_div_assoc] at h, rwa [mul_comm b, ← div_le_iff hc], end lemma div_mul_le_div_mul_of_div_le_div (h : a / b ≤ c / d) (he : 0 ≤ e) : a / (b * e) ≤ c / (d * e) := begin rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div], exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he) end lemma exists_add_lt_and_pos_of_lt (h : b < a) : ∃ c : α, b + c < a ∧ 0 < c := ⟨(a - b) / 2, add_sub_div_two_lt h, div_pos (sub_pos_of_lt h) zero_lt_two⟩ lemma le_of_forall_sub_le (h : ∀ ε > 0, b - ε ≤ a) : b ≤ a := begin contrapose! h, simpa only [and_comm ((0 : α) < _), lt_sub_iff_add_lt, gt_iff_lt] using exists_add_lt_and_pos_of_lt h, end lemma monotone.div_const {β : Type*} [preorder β] {f : β → α} (hf : monotone f) {c : α} (hc : 0 ≤ c) : monotone (λ x, (f x) / c) := by simpa only [div_eq_mul_inv] using hf.mul_const (inv_nonneg.2 hc) lemma strict_mono.div_const {β : Type*} [preorder β] {f : β → α} (hf : strict_mono f) {c : α} (hc : 0 < c) : strict_mono (λ x, (f x) / c) := by simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc) @[priority 100] -- see Note [lower instance priority] instance linear_ordered_field.to_densely_ordered : densely_ordered α := { dense := λ a₁ a₂ h, ⟨(a₁ + a₂) / 2, calc a₁ = (a₁ + a₁) / 2 : (add_self_div_two a₁).symm ... < (a₁ + a₂) / 2 : div_lt_div_of_lt zero_lt_two (add_lt_add_left h _), calc (a₁ + a₂) / 2 < (a₂ + a₂) / 2 : div_lt_div_of_lt zero_lt_two (add_lt_add_right h _) ... = a₂ : add_self_div_two a₂⟩ } lemma mul_self_inj_of_nonneg (a0 : 0 ≤ a) (b0 : 0 ≤ b) : a * a = b * b ↔ a = b := mul_self_eq_mul_self_iff.trans $ or_iff_left_of_imp $ λ h, by { subst a, have : b = 0 := le_antisymm (neg_nonneg.1 a0) b0, rw [this, neg_zero] } lemma min_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : min (a / c) (b / c) = (min a b) / c := eq.symm $ monotone.map_min (λ x y, div_le_div_of_le hc) lemma max_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : max (a / c) (b / c) = (max a b) / c := eq.symm $ monotone.map_max (λ x y, div_le_div_of_le hc) lemma min_div_div_right_of_nonpos {c : α} (hc : c ≤ 0) (a b : α) : min (a / c) (b / c) = (max a b) / c := eq.symm $ @monotone.map_max α (order_dual α) _ _ _ _ _ (λ x y, div_le_div_of_nonpos_of_le hc) lemma max_div_div_right_of_nonpos {c : α} (hc : c ≤ 0) (a b : α) : max (a / c) (b / c) = (min a b) / c := eq.symm $ @monotone.map_min α (order_dual α) _ _ _ _ _ (λ x y, div_le_div_of_nonpos_of_le hc) lemma abs_div (a b : α) : abs (a / b) = abs a / abs b := (abs_hom : monoid_with_zero_hom α α).map_div a b lemma abs_one_div (a : α) : abs (1 / a) = 1 / abs a := by rw [abs_div, abs_one] lemma abs_inv (a : α) : abs a⁻¹ = (abs a)⁻¹ := (abs_hom : monoid_with_zero_hom α α).map_inv' a -- TODO: add lemmas with `a⁻¹`. lemma one_div_strict_mono_decr_on : strict_mono_decr_on (λ x : α, 1 / x) (set.Ioi 0) := λ x x1 y y1 xy, (one_div_lt_one_div (set.mem_Ioi.mp y1) (set.mem_Ioi.mp x1)).mpr xy lemma one_div_pow_le_one_div_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : 1 / a ^ n ≤ 1 / a ^ m := by refine (one_div_le_one_div _ _).mpr (pow_le_pow a1 mn); exact pow_pos (zero_lt_one.trans_le a1) _ lemma one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) : 1 / a ^ n < 1 / a ^ m := by refine (one_div_lt_one_div _ _).mpr (pow_lt_pow a1 mn); exact pow_pos (trans zero_lt_one a1) _ lemma one_div_pow_mono (a1 : 1 ≤ a) : monotone (λ n : ℕ, order_dual.to_dual 1 / a ^ n) := λ m n, one_div_pow_le_one_div_pow_of_le a1 lemma one_div_pow_strict_mono (a1 : 1 < a) : strict_mono (λ n : ℕ, order_dual.to_dual 1 / a ^ n) := λ m n, one_div_pow_lt_one_div_pow_of_lt a1 end linear_ordered_field
45e5734ceee768c1f59ca0f8f65139873806020f
b32d3853770e6eaf06817a1b8c52064baaed0ef1
/src/super/subsume.lean
73a6f052ff15375a9759e62bffa9b25652d1223a
[]
no_license
gebner/super2
4d58b7477b6f7d945d5d866502982466db33ab0b
9bc5256c31750021ab97d6b59b7387773e54b384
refs/heads/master
1,635,021,682,021
1,634,886,326,000
1,634,886,326,000
225,600,688
4
2
null
1,598,209,306,000
1,575,371,550,000
Lean
UTF-8
Lean
false
false
1,232
lean
import super.clause namespace super open tactic private meta def unify_lit (a b : literal) : tactic unit := do guard $ a.is_pos = b.is_pos, unify a.formula b.formula transparency.none tt private meta def try_subsume_core : list literal → list literal → tactic unit | [] _ := skip | (head :: small) large := first $ large.zip_with_index.map $ λ j, do unify_lit head j.1, try_subsume_core small (large.remove_nth j.2) private meta def try_subsume (small large : clause) : tactic unit := do guard $ small.ty.num_neg_literals ≤ large.ty.num_neg_literals, guard $ small.ty.num_pos_literals ≤ large.ty.num_pos_literals, let large0 := large, large ← large.with_locals_unsafe, try_subsume_core small.literals large.literals, small_mvars ← small.prf.sorted_mvars, large_mvars ← large0.prf.sorted_mvars, small_mvars.mmap' $ λ sm, first $ do lm ← large_mvars, pure $ unify sm lm transparency.reducible meta def does_subsume_pure (s : tactic_state) (small large : clause) : bool := match try_subsume small large s with | result.success _ _ := tt | result.exception _ _ _ := ff end meta def does_subsume (small large : clause) : tactic bool := do s ← read, pure $ does_subsume_pure s small large end super
e4c0530f4d9f1a0441c0ab76675011f222494faa
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/measure_theory/ae_eq_fun.lean
8eca8ba7a38287788e3a02fe087a939758553a52
[ "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
20,377
lean
/- Copyright (c) 2019 Johannes Hölzl, Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Zhouhang Zhou -/ import measure_theory.integration import order.filter.germ import topology.continuous_function.algebra /-! # Almost everywhere equal functions Two measurable functions are treated as identical if they are almost everywhere equal. We form the set of equivalence classes under the relation of being almost everywhere equal, which is sometimes known as the `L⁰` space. See `l1_space.lean` for `L¹` space. ## Notation * `α →ₘ[μ] β` is the type of `L⁰` space, where `α` and `β` are measurable spaces and `μ` is a measure on `α`. `f : α →ₘ β` is a "function" in `L⁰`. In comments, `[f]` is also used to denote an `L⁰` function. `ₘ` can be typed as `\_m`. Sometimes it is shown as a box if font is missing. ## Main statements * The linear structure of `L⁰` : Addition and scalar multiplication are defined on `L⁰` in the natural way, i.e., `[f] + [g] := [f + g]`, `c • [f] := [c • f]`. So defined, `α →ₘ β` inherits the linear structure of `β`. For example, if `β` is a module, then `α →ₘ β` is a module over the same ring. See `mk_add_mk`, `neg_mk`, `mk_sub_mk`, `smul_mk`, `add_to_fun`, `neg_to_fun`, `sub_to_fun`, `smul_to_fun` * The order structure of `L⁰` : `≤` can be defined in a similar way: `[f] ≤ [g]` if `f a ≤ g a` for almost all `a` in domain. And `α →ₘ β` inherits the preorder and partial order of `β`. TODO: Define `sup` and `inf` on `L⁰` so that it forms a lattice. It seems that `β` must be a linear order, since otherwise `f ⊔ g` may not be a measurable function. ## Implementation notes * `f.to_fun` : To find a representative of `f : α →ₘ β`, use `f.to_fun`. For each operation `op` in `L⁰`, there is a lemma called `op_to_fun`, characterizing, say, `(f op g).to_fun`. * `ae_eq_fun.mk` : To constructs an `L⁰` function `α →ₘ β` from a measurable function `f : α → β`, use `ae_eq_fun.mk` * `comp` : Use `comp g f` to get `[g ∘ f]` from `g : β → γ` and `[f] : α →ₘ γ` * `comp₂` : Use `comp₂ g f₁ f₂ to get `[λa, g (f₁ a) (f₂ a)]`. For example, `[f + g]` is `comp₂ (+)` ## Tags function space, almost everywhere equal, `L⁰`, ae_eq_fun -/ noncomputable theory open_locale classical ennreal open set filter topological_space ennreal emetric measure_theory function variables {α β γ δ : Type*} [measurable_space α] {μ ν : measure α} namespace measure_theory section measurable_space variables [measurable_space β] variable (β) /-- The equivalence relation of being almost everywhere equal -/ def measure.ae_eq_setoid (μ : measure α) : setoid { f : α → β // ae_measurable f μ } := ⟨λf g, (f : α → β) =ᵐ[μ] g, λ f, ae_eq_refl f, λ f g, ae_eq_symm, λ f g h, ae_eq_trans⟩ variable (α) /-- The space of equivalence classes of measurable functions, where two measurable functions are equivalent if they agree almost everywhere, i.e., they differ on a set of measure `0`. -/ def ae_eq_fun (μ : measure α) : Type* := quotient (μ.ae_eq_setoid β) variables {α β} notation α ` →ₘ[`:25 μ `] ` β := ae_eq_fun α β μ end measurable_space namespace ae_eq_fun variables [measurable_space β] [measurable_space γ] [measurable_space δ] /-- Construct the equivalence class `[f]` of an almost everywhere measurable function `f`, based on the equivalence relation of being almost everywhere equal. -/ def mk (f : α → β) (hf : ae_measurable f μ) : α →ₘ[μ] β := quotient.mk' ⟨f, hf⟩ /-- A measurable representative of an `ae_eq_fun` [f] -/ instance : has_coe_to_fun (α →ₘ[μ] β) := ⟨_, λf, ae_measurable.mk _ (quotient.out' f : {f : α → β // ae_measurable f μ}).2⟩ protected lemma measurable (f : α →ₘ[μ] β) : measurable f := ae_measurable.measurable_mk _ protected lemma ae_measurable (f : α →ₘ[μ] β) : ae_measurable f μ := f.measurable.ae_measurable @[simp] lemma quot_mk_eq_mk (f : α → β) (hf) : (quot.mk (@setoid.r _ $ μ.ae_eq_setoid β) ⟨f, hf⟩ : α →ₘ[μ] β) = mk f hf := rfl @[simp] lemma mk_eq_mk {f g : α → β} {hf hg} : (mk f hf : α →ₘ[μ] β) = mk g hg ↔ f =ᵐ[μ] g := quotient.eq' @[simp] lemma mk_coe_fn (f : α →ₘ[μ] β) : mk f f.ae_measurable = f := begin conv_rhs { rw ← quotient.out_eq' f }, set g : {f : α → β // ae_measurable f μ} := quotient.out' f with hg, have : g = ⟨g.1, g.2⟩ := subtype.eq rfl, rw [this, ← mk, mk_eq_mk], exact (ae_measurable.ae_eq_mk _).symm, end @[ext] lemma ext {f g : α →ₘ[μ] β} (h : f =ᵐ[μ] g) : f = g := by rwa [← f.mk_coe_fn, ← g.mk_coe_fn, mk_eq_mk] lemma ext_iff {f g : α →ₘ[μ] β} : f = g ↔ f =ᵐ[μ] g := ⟨λ h, by rw h, λ h, ext h⟩ lemma coe_fn_mk (f : α → β) (hf) : (mk f hf : α →ₘ[μ] β) =ᵐ[μ] f := begin apply (ae_measurable.ae_eq_mk _).symm.trans, exact @quotient.mk_out' _ (μ.ae_eq_setoid β) (⟨f, hf⟩ : {f // ae_measurable f μ}) end @[elab_as_eliminator] lemma induction_on (f : α →ₘ[μ] β) {p : (α →ₘ[μ] β) → Prop} (H : ∀ f hf, p (mk f hf)) : p f := quotient.induction_on' f $ subtype.forall.2 H @[elab_as_eliminator] lemma induction_on₂ {α' β' : Type*} [measurable_space α'] [measurable_space β'] {μ' : measure α'} (f : α →ₘ[μ] β) (f' : α' →ₘ[μ'] β') {p : (α →ₘ[μ] β) → (α' →ₘ[μ'] β') → Prop} (H : ∀ f hf f' hf', p (mk f hf) (mk f' hf')) : p f f' := induction_on f $ λ f hf, induction_on f' $ H f hf @[elab_as_eliminator] lemma induction_on₃ {α' β' : Type*} [measurable_space α'] [measurable_space β'] {μ' : measure α'} {α'' β'' : Type*} [measurable_space α''] [measurable_space β''] {μ'' : measure α''} (f : α →ₘ[μ] β) (f' : α' →ₘ[μ'] β') (f'' : α'' →ₘ[μ''] β'') {p : (α →ₘ[μ] β) → (α' →ₘ[μ'] β') → (α'' →ₘ[μ''] β'') → Prop} (H : ∀ f hf f' hf' f'' hf'', p (mk f hf) (mk f' hf') (mk f'' hf'')) : p f f' f'' := induction_on f $ λ f hf, induction_on₂ f' f'' $ H f hf /-- Given a measurable function `g : β → γ`, and an almost everywhere equal function `[f] : α →ₘ β`, return the equivalence class of `g ∘ f`, i.e., the almost everywhere equal function `[g ∘ f] : α →ₘ γ`. -/ def comp (g : β → γ) (hg : measurable g) (f : α →ₘ[μ] β) : α →ₘ[μ] γ := quotient.lift_on' f (λ f, mk (g ∘ (f : α → β)) (hg.comp_ae_measurable f.2)) $ λ f f' H, mk_eq_mk.2 $ H.fun_comp g @[simp] lemma comp_mk (g : β → γ) (hg : measurable g) (f : α → β) (hf) : comp g hg (mk f hf : α →ₘ[μ] β) = mk (g ∘ f) (hg.comp_ae_measurable hf) := rfl lemma comp_eq_mk (g : β → γ) (hg : measurable g) (f : α →ₘ[μ] β) : comp g hg f = mk (g ∘ f) (hg.comp_ae_measurable f.ae_measurable) := by rw [← comp_mk g hg f f.ae_measurable, mk_coe_fn] lemma coe_fn_comp (g : β → γ) (hg : measurable g) (f : α →ₘ[μ] β) : comp g hg f =ᵐ[μ] g ∘ f := by { rw [comp_eq_mk], apply coe_fn_mk } /-- The class of `x ↦ (f x, g x)`. -/ def pair (f : α →ₘ[μ] β) (g : α →ₘ[μ] γ) : α →ₘ[μ] β × γ := quotient.lift_on₂' f g (λ f g, mk (λ x, (f.1 x, g.1 x)) (f.2.prod_mk g.2)) $ λ f g f' g' Hf Hg, mk_eq_mk.2 $ Hf.prod_mk Hg @[simp] lemma pair_mk_mk (f : α → β) (hf) (g : α → γ) (hg) : (mk f hf : α →ₘ[μ] β).pair (mk g hg) = mk (λ x, (f x, g x)) (hf.prod_mk hg) := rfl lemma pair_eq_mk (f : α →ₘ[μ] β) (g : α →ₘ[μ] γ) : f.pair g = mk (λ x, (f x, g x)) (f.ae_measurable.prod_mk g.ae_measurable) := by simp only [← pair_mk_mk, mk_coe_fn] lemma coe_fn_pair (f : α →ₘ[μ] β) (g : α →ₘ[μ] γ) : f.pair g =ᵐ[μ] (λ x, (f x, g x)) := by { rw pair_eq_mk, apply coe_fn_mk } /-- Given a measurable function `g : β → γ → δ`, and almost everywhere equal functions `[f₁] : α →ₘ β` and `[f₂] : α →ₘ γ`, return the equivalence class of the function `λa, g (f₁ a) (f₂ a)`, i.e., the almost everywhere equal function `[λa, g (f₁ a) (f₂ a)] : α →ₘ γ` -/ def comp₂ {γ δ : Type*} [measurable_space γ] [measurable_space δ] (g : β → γ → δ) (hg : measurable (uncurry g)) (f₁ : α →ₘ[μ] β) (f₂ : α →ₘ[μ] γ) : α →ₘ[μ] δ := comp _ hg (f₁.pair f₂) @[simp] lemma comp₂_mk_mk {γ δ : Type*} [measurable_space γ] [measurable_space δ] (g : β → γ → δ) (hg : measurable (uncurry g)) (f₁ : α → β) (f₂ : α → γ) (hf₁ hf₂) : comp₂ g hg (mk f₁ hf₁ : α →ₘ[μ] β) (mk f₂ hf₂) = mk (λa, g (f₁ a) (f₂ a)) (hg.comp_ae_measurable (hf₁.prod_mk hf₂)) := rfl lemma comp₂_eq_pair {γ δ : Type*} [measurable_space γ] [measurable_space δ] (g : β → γ → δ) (hg : measurable (uncurry g)) (f₁ : α →ₘ[μ] β) (f₂ : α →ₘ[μ] γ) : comp₂ g hg f₁ f₂ = comp _ hg (f₁.pair f₂) := rfl lemma comp₂_eq_mk {γ δ : Type*} [measurable_space γ] [measurable_space δ] (g : β → γ → δ) (hg : measurable (uncurry g)) (f₁ : α →ₘ[μ] β) (f₂ : α →ₘ[μ] γ) : comp₂ g hg f₁ f₂ = mk (λ a, g (f₁ a) (f₂ a)) (hg.comp_ae_measurable (f₁.ae_measurable.prod_mk f₂.ae_measurable)) := by rw [comp₂_eq_pair, pair_eq_mk, comp_mk]; refl lemma coe_fn_comp₂ {γ δ : Type*} [measurable_space γ] [measurable_space δ] (g : β → γ → δ) (hg : measurable (uncurry g)) (f₁ : α →ₘ[μ] β) (f₂ : α →ₘ[μ] γ) : comp₂ g hg f₁ f₂ =ᵐ[μ] λ a, g (f₁ a) (f₂ a) := by { rw comp₂_eq_mk, apply coe_fn_mk } /-- Interpret `f : α →ₘ[μ] β` as a germ at `μ.ae` forgetting that `f` is almost everywhere measurable. -/ def to_germ (f : α →ₘ[μ] β) : germ μ.ae β := quotient.lift_on' f (λ f, ((f : α → β) : germ μ.ae β)) $ λ f g H, germ.coe_eq.2 H @[simp] lemma mk_to_germ (f : α → β) (hf) : (mk f hf : α →ₘ[μ] β).to_germ = f := rfl lemma to_germ_eq (f : α →ₘ[μ] β) : f.to_germ = (f : α → β) := by rw [← mk_to_germ, mk_coe_fn] lemma to_germ_injective : injective (to_germ : (α →ₘ[μ] β) → germ μ.ae β) := λ f g H, ext $ germ.coe_eq.1 $ by rwa [← to_germ_eq, ← to_germ_eq] lemma comp_to_germ (g : β → γ) (hg : measurable g) (f : α →ₘ[μ] β) : (comp g hg f).to_germ = f.to_germ.map g := induction_on f $ λ f hf, by simp lemma comp₂_to_germ (g : β → γ → δ) (hg : measurable (uncurry g)) (f₁ : α →ₘ[μ] β) (f₂ : α →ₘ[μ] γ) : (comp₂ g hg f₁ f₂).to_germ = f₁.to_germ.map₂ g f₂.to_germ := induction_on₂ f₁ f₂ $ λ f₁ hf₁ f₂ hf₂, by simp /-- Given a predicate `p` and an equivalence class `[f]`, return true if `p` holds of `f a` for almost all `a` -/ def lift_pred (p : β → Prop) (f : α →ₘ[μ] β) : Prop := f.to_germ.lift_pred p /-- Given a relation `r` and equivalence class `[f]` and `[g]`, return true if `r` holds of `(f a, g a)` for almost all `a` -/ def lift_rel (r : β → γ → Prop) (f : α →ₘ[μ] β) (g : α →ₘ[μ] γ) : Prop := f.to_germ.lift_rel r g.to_germ lemma lift_rel_mk_mk {r : β → γ → Prop} {f : α → β} {g : α → γ} {hf hg} : lift_rel r (mk f hf : α →ₘ[μ] β) (mk g hg) ↔ ∀ᵐ a ∂μ, r (f a) (g a) := iff.rfl lemma lift_rel_iff_coe_fn {r : β → γ → Prop} {f : α →ₘ[μ] β} {g : α →ₘ[μ] γ} : lift_rel r f g ↔ ∀ᵐ a ∂μ, r (f a) (g a) := by rw [← lift_rel_mk_mk, mk_coe_fn, mk_coe_fn] section order instance [preorder β] : preorder (α →ₘ[μ] β) := preorder.lift to_germ @[simp] lemma mk_le_mk [preorder β] {f g : α → β} (hf hg) : (mk f hf : α →ₘ[μ] β) ≤ mk g hg ↔ f ≤ᵐ[μ] g := iff.rfl @[simp, norm_cast] lemma coe_fn_le [preorder β] {f g : α →ₘ[μ] β} : (f : α → β) ≤ᵐ[μ] g ↔ f ≤ g := lift_rel_iff_coe_fn.symm instance [partial_order β] : partial_order (α →ₘ[μ] β) := partial_order.lift to_germ to_germ_injective /- TODO: Prove `L⁰` space is a lattice if β is linear order. What if β is only a lattice? -/ -- instance [linear_order β] : semilattice_sup (α →ₘ β) := -- { sup := comp₂ (⊔) (_), -- .. ae_eq_fun.partial_order } end order variable (α) /-- The equivalence class of a constant function: `[λa:α, b]`, based on the equivalence relation of being almost everywhere equal -/ def const (b : β) : α →ₘ[μ] β := mk (λa:α, b) ae_measurable_const lemma coe_fn_const (b : β) : (const α b : α →ₘ[μ] β) =ᵐ[μ] function.const α b := coe_fn_mk _ _ variable {α} instance [inhabited β] : inhabited (α →ₘ[μ] β) := ⟨const α (default β)⟩ @[to_additive] instance [has_one β] : has_one (α →ₘ[μ] β) := ⟨const α 1⟩ @[to_additive] lemma one_def [has_one β] : (1 : α →ₘ[μ] β) = mk (λa:α, 1) ae_measurable_const := rfl @[to_additive] lemma coe_fn_one [has_one β] : ⇑(1 : α →ₘ[μ] β) =ᵐ[μ] 1 := coe_fn_const _ _ @[simp, to_additive] lemma one_to_germ [has_one β] : (1 : α →ₘ[μ] β).to_germ = 1 := rfl section monoid variables [topological_space γ] [second_countable_topology γ] [borel_space γ] [monoid γ] [has_continuous_mul γ] @[to_additive] instance : has_mul (α →ₘ[μ] γ) := ⟨comp₂ (*) measurable_mul⟩ @[simp, to_additive] lemma mk_mul_mk (f g : α → γ) (hf hg) : (mk f hf : α →ₘ[μ] γ) * (mk g hg) = mk (f * g) (hf.mul hg) := rfl @[to_additive] lemma coe_fn_mul (f g : α →ₘ[μ] γ) : ⇑(f * g) =ᵐ[μ] f * g := coe_fn_comp₂ _ _ _ _ @[simp, to_additive] lemma mul_to_germ (f g : α →ₘ[μ] γ) : (f * g).to_germ = f.to_germ * g.to_germ := comp₂_to_germ _ _ _ _ @[to_additive] instance : monoid (α →ₘ[μ] γ) := to_germ_injective.monoid to_germ one_to_germ mul_to_germ end monoid @[to_additive] instance comm_monoid [topological_space γ] [second_countable_topology γ] [borel_space γ] [comm_monoid γ] [has_continuous_mul γ] : comm_monoid (α →ₘ[μ] γ) := to_germ_injective.comm_monoid to_germ one_to_germ mul_to_germ section group variables [topological_space γ] [borel_space γ] [group γ] [topological_group γ] @[to_additive] instance : has_inv (α →ₘ[μ] γ) := ⟨comp has_inv.inv measurable_inv⟩ @[simp, to_additive] lemma inv_mk (f : α → γ) (hf) : (mk f hf : α →ₘ[μ] γ)⁻¹ = mk f⁻¹ hf.inv := rfl @[to_additive] lemma coe_fn_inv (f : α →ₘ[μ] γ) : ⇑(f⁻¹) =ᵐ[μ] f⁻¹ := coe_fn_comp _ _ _ @[to_additive] lemma inv_to_germ (f : α →ₘ[μ] γ) : (f⁻¹).to_germ = f.to_germ⁻¹ := comp_to_germ _ _ _ variables [second_countable_topology γ] @[to_additive] instance : has_div (α →ₘ[μ] γ) := ⟨comp₂ has_div.div measurable_div⟩ @[to_additive, simp] lemma mk_div (f g : α → γ) (hf hg) : mk (f / g) (ae_measurable.div hf hg) = (mk f hf : α →ₘ[μ] γ) / (mk g hg) := rfl @[to_additive] lemma coe_fn_div (f g : α →ₘ[μ] γ) : ⇑(f / g) =ᵐ[μ] f / g := coe_fn_comp₂ _ _ _ _ @[to_additive] lemma div_to_germ (f g : α →ₘ[μ] γ) : (f / g).to_germ = f.to_germ / g.to_germ := comp₂_to_germ _ _ _ _ @[to_additive] instance : group (α →ₘ[μ] γ) := to_germ_injective.group _ one_to_germ mul_to_germ inv_to_germ div_to_germ end group @[to_additive] instance [topological_space γ] [borel_space γ] [comm_group γ] [topological_group γ] [second_countable_topology γ] : comm_group (α →ₘ[μ] γ) := { .. ae_eq_fun.group, .. ae_eq_fun.comm_monoid } section module variables {𝕜 : Type*} [semiring 𝕜] [topological_space 𝕜] [measurable_space 𝕜] [opens_measurable_space 𝕜] variables [topological_space γ] [borel_space γ] [add_comm_monoid γ] [module 𝕜 γ] [has_continuous_smul 𝕜 γ] instance : has_scalar 𝕜 (α →ₘ[μ] γ) := ⟨λ c f, comp ((•) c) (measurable_id.const_smul c) f⟩ @[simp] lemma smul_mk (c : 𝕜) (f : α → γ) (hf) : c • (mk f hf : α →ₘ[μ] γ) = mk (c • f) (hf.const_smul _) := rfl lemma coe_fn_smul (c : 𝕜) (f : α →ₘ[μ] γ) : ⇑(c • f) =ᵐ[μ] c • f := coe_fn_comp _ _ _ lemma smul_to_germ (c : 𝕜) (f : α →ₘ[μ] γ) : (c • f).to_germ = c • f.to_germ := comp_to_germ _ _ _ variables [second_countable_topology γ] [has_continuous_add γ] instance : module 𝕜 (α →ₘ[μ] γ) := to_germ_injective.module 𝕜 ⟨@to_germ α γ _ μ _, zero_to_germ, add_to_germ⟩ smul_to_germ end module open ennreal /-- For `f : α → ℝ≥0∞`, define `∫ [f]` to be `∫ f` -/ def lintegral (f : α →ₘ[μ] ℝ≥0∞) : ℝ≥0∞ := quotient.lift_on' f (λf, ∫⁻ a, (f : α → ℝ≥0∞) a ∂μ) (assume f g, lintegral_congr_ae) @[simp] lemma lintegral_mk (f : α → ℝ≥0∞) (hf) : (mk f hf : α →ₘ[μ] ℝ≥0∞).lintegral = ∫⁻ a, f a ∂μ := rfl lemma lintegral_coe_fn (f : α →ₘ[μ] ℝ≥0∞) : ∫⁻ a, f a ∂μ = f.lintegral := by rw [← lintegral_mk, mk_coe_fn] @[simp] lemma lintegral_zero : lintegral (0 : α →ₘ[μ] ℝ≥0∞) = 0 := lintegral_zero @[simp] lemma lintegral_eq_zero_iff {f : α →ₘ[μ] ℝ≥0∞} : lintegral f = 0 ↔ f = 0 := induction_on f $ λ f hf, (lintegral_eq_zero_iff' hf).trans mk_eq_mk.symm lemma lintegral_add (f g : α →ₘ[μ] ℝ≥0∞) : lintegral (f + g) = lintegral f + lintegral g := induction_on₂ f g $ λ f hf g hg, by simp [lintegral_add' hf hg] lemma lintegral_mono {f g : α →ₘ[μ] ℝ≥0∞} : f ≤ g → lintegral f ≤ lintegral g := induction_on₂ f g $ λ f hf g hg hfg, lintegral_mono_ae hfg section pos_part variables [topological_space γ] [linear_order γ] [order_closed_topology γ] [second_countable_topology γ] [has_zero γ] [opens_measurable_space γ] /-- Positive part of an `ae_eq_fun`. -/ def pos_part (f : α →ₘ[μ] γ) : α →ₘ[μ] γ := comp (λ x, max x 0) (measurable_id.max measurable_const) f @[simp] lemma pos_part_mk (f : α → γ) (hf) : pos_part (mk f hf : α →ₘ[μ] γ) = mk (λ x, max (f x) 0) (hf.max ae_measurable_const) := rfl lemma coe_fn_pos_part (f : α →ₘ[μ] γ) : ⇑(pos_part f) =ᵐ[μ] (λ a, max (f a) 0) := coe_fn_comp _ _ _ end pos_part end ae_eq_fun end measure_theory namespace continuous_map open measure_theory variables [topological_space α] [borel_space α] (μ) variables [topological_space β] [measurable_space β] [borel_space β] /-- The equivalence class of `μ`-almost-everywhere measurable functions associated to a continuous map. -/ def to_ae_eq_fun (f : C(α, β)) : α →ₘ[μ] β := ae_eq_fun.mk f f.continuous.measurable.ae_measurable lemma coe_fn_to_ae_eq_fun (f : C(α, β)) : f.to_ae_eq_fun μ =ᵐ[μ] f := ae_eq_fun.coe_fn_mk f _ variables [group β] [topological_group β] [second_countable_topology β] /-- The `mul_hom` from the group of continuous maps from `α` to `β` to the group of equivalence classes of `μ`-almost-everywhere measurable functions. -/ @[to_additive "The `add_hom` from the group of continuous maps from `α` to `β` to the group of equivalence classes of `μ`-almost-everywhere measurable functions."] def to_ae_eq_fun_mul_hom : C(α, β) →* α →ₘ[μ] β := { to_fun := continuous_map.to_ae_eq_fun μ, map_one' := rfl, map_mul' := λ f g, ae_eq_fun.mk_mul_mk f g f.continuous.measurable.ae_measurable g.continuous.measurable.ae_measurable } variables {𝕜 : Type*} [semiring 𝕜] [topological_space 𝕜] [measurable_space 𝕜] [opens_measurable_space 𝕜] variables [topological_space γ] [measurable_space γ] [borel_space γ] [add_comm_group γ] [module 𝕜 γ] [topological_add_group γ] [has_continuous_smul 𝕜 γ] [second_countable_topology γ] /-- The linear map from the group of continuous maps from `α` to `β` to the group of equivalence classes of `μ`-almost-everywhere measurable functions. -/ def to_ae_eq_fun_linear_map : C(α, γ) →ₗ[𝕜] α →ₘ[μ] γ := { map_smul' := λ c f, ae_eq_fun.smul_mk c f f.continuous.measurable.ae_measurable, .. to_ae_eq_fun_add_hom μ } end continuous_map
aa4fed567cd16efa9f7813b6a956066852e8fb7c
94e33a31faa76775069b071adea97e86e218a8ee
/src/analysis/normed_space/linear_isometry.lean
9401382d533994000f1e419917f4ed082b39972c
[ "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
26,655
lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Frédéric Dupuis, Heather Macbeth -/ import analysis.normed.group.basic import topology.algebra.module.basic import linear_algebra.basis /-! # (Semi-)linear isometries In this file we define `linear_isometry σ₁₂ E E₂` (notation: `E →ₛₗᵢ[σ₁₂] E₂`) to be a semilinear isometric embedding of `E` into `E₂` and `linear_isometry_equiv` (notation: `E ≃ₛₗᵢ[σ₁₂] E₂`) to be a semilinear isometric equivalence between `E` and `E₂`. The notation for the associated purely linear concepts is `E →ₗᵢ[R] E₂`, `E ≃ₗᵢ[R] E₂`, and `E →ₗᵢ⋆[R] E₂`, `E ≃ₗᵢ⋆[R] E₂` for the star-linear versions. We also prove some trivial lemmas and provide convenience constructors. Since a lot of elementary properties don't require `∥x∥ = 0 → x = 0` we start setting up the theory for `semi_normed_group` and we specialize to `normed_group` when needed. -/ open function set variables {R R₂ R₃ R₄ E E₂ E₃ E₄ F : Type*} [semiring R] [semiring R₂] [semiring R₃] [semiring R₄] {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R} {σ₁₃ : R →+* R₃} {σ₃₁ : R₃ →+* R} {σ₁₄ : R →+* R₄} {σ₄₁ : R₄ →+* R} {σ₂₃ : R₂ →+* R₃} {σ₃₂ : R₃ →+* R₂} {σ₂₄ : R₂ →+* R₄} {σ₄₂ : R₄ →+* R₂} {σ₃₄ : R₃ →+* R₄} {σ₄₃ : R₄ →+* R₃} [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂] [ring_hom_inv_pair σ₁₃ σ₃₁] [ring_hom_inv_pair σ₃₁ σ₁₃] [ring_hom_inv_pair σ₂₃ σ₃₂] [ring_hom_inv_pair σ₃₂ σ₂₃] [ring_hom_inv_pair σ₁₄ σ₄₁] [ring_hom_inv_pair σ₄₁ σ₁₄] [ring_hom_inv_pair σ₂₄ σ₄₂] [ring_hom_inv_pair σ₄₂ σ₂₄] [ring_hom_inv_pair σ₃₄ σ₄₃] [ring_hom_inv_pair σ₄₃ σ₃₄] [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃] [ring_hom_comp_triple σ₁₂ σ₂₄ σ₁₄] [ring_hom_comp_triple σ₂₃ σ₃₄ σ₂₄] [ring_hom_comp_triple σ₁₃ σ₃₄ σ₁₄] [ring_hom_comp_triple σ₃₂ σ₂₁ σ₃₁] [ring_hom_comp_triple σ₄₂ σ₂₁ σ₄₁] [ring_hom_comp_triple σ₄₃ σ₃₂ σ₄₂] [ring_hom_comp_triple σ₄₃ σ₃₁ σ₄₁] [semi_normed_group E] [semi_normed_group E₂] [semi_normed_group E₃] [semi_normed_group E₄] [module R E] [module R₂ E₂] [module R₃ E₃] [module R₄ E₄] [normed_group F] [module R F] /-- A `σ₁₂`-semilinear isometric embedding of a normed `R`-module into an `R₂`-module. -/ structure linear_isometry (σ₁₂ : R →+* R₂) (E E₂ : Type*) [semi_normed_group E] [semi_normed_group E₂] [module R E] [module R₂ E₂] extends E →ₛₗ[σ₁₂] E₂ := (norm_map' : ∀ x, ∥to_linear_map x∥ = ∥x∥) notation E ` →ₛₗᵢ[`:25 σ₁₂:25 `] `:0 E₂:0 := linear_isometry σ₁₂ E E₂ notation E ` →ₗᵢ[`:25 R:25 `] `:0 E₂:0 := linear_isometry (ring_hom.id R) E E₂ notation E ` →ₗᵢ⋆[`:25 R:25 `] `:0 E₂:0 := linear_isometry (star_ring_end R) E E₂ namespace linear_isometry /-- We use `f₁` when we need the domain to be a `normed_space`. -/ variables (f : E →ₛₗᵢ[σ₁₂] E₂) (f₁ : F →ₛₗᵢ[σ₁₂] E₂) lemma to_linear_map_injective : injective (to_linear_map : (E →ₛₗᵢ[σ₁₂] E₂) → (E →ₛₗ[σ₁₂] E₂)) | ⟨f, _⟩ ⟨g, _⟩ rfl := rfl @[simp] lemma to_linear_map_inj {f g : E →ₛₗᵢ[σ₁₂] E₂} : f.to_linear_map = g.to_linear_map ↔ f = g := to_linear_map_injective.eq_iff instance : add_monoid_hom_class (E →ₛₗᵢ[σ₁₂] E₂) E E₂ := { coe := λ e, e.to_fun, coe_injective' := λ f g h, to_linear_map_injective (fun_like.coe_injective h), map_add := λ f, map_add f.to_linear_map, map_zero := λ f, map_zero f.to_linear_map } /-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun` directly. -/ instance : has_coe_to_fun (E →ₛₗᵢ[σ₁₂] E₂) (λ _, E → E₂) := ⟨λ f, f.to_fun⟩ @[simp] lemma coe_to_linear_map : ⇑f.to_linear_map = f := rfl @[simp] lemma coe_mk (f : E →ₛₗ[σ₁₂] E₂) (hf) : ⇑(mk f hf) = f := rfl lemma coe_injective : @injective (E →ₛₗᵢ[σ₁₂] E₂) (E → E₂) coe_fn := fun_like.coe_injective @[ext] lemma ext {f g : E →ₛₗᵢ[σ₁₂] E₂} (h : ∀ x, f x = g x) : f = g := coe_injective $ funext h protected lemma congr_arg {f : E →ₛₗᵢ[σ₁₂] E₂} : Π {x x' : E}, x = x' → f x = f x' | _ _ rfl := rfl protected lemma congr_fun {f g : E →ₛₗᵢ[σ₁₂] E₂} (h : f = g) (x : E) : f x = g x := h ▸ rfl @[simp] lemma map_zero : f 0 = 0 := f.to_linear_map.map_zero @[simp] lemma map_add (x y : E) : f (x + y) = f x + f y := f.to_linear_map.map_add x y @[simp] lemma map_neg (x : E) : f (- x) = - f x := f.to_linear_map.map_neg x @[simp] lemma map_sub (x y : E) : f (x - y) = f x - f y := f.to_linear_map.map_sub x y @[simp] lemma map_smulₛₗ (c : R) (x : E) : f (c • x) = σ₁₂ c • f x := f.to_linear_map.map_smulₛₗ c x @[simp] lemma map_smul [module R E₂] (f : E →ₗᵢ[R] E₂) (c : R) (x : E) : f (c • x) = c • f x := f.to_linear_map.map_smul c x @[simp] lemma norm_map (x : E) : ∥f x∥ = ∥x∥ := f.norm_map' x @[simp] lemma nnnorm_map (x : E) : ∥f x∥₊ = ∥x∥₊ := nnreal.eq $ f.norm_map x protected lemma isometry : isometry f := add_monoid_hom_class.isometry_of_norm _ (norm_map _) @[simp] lemma is_complete_image_iff {s : set E} : is_complete (f '' s) ↔ is_complete s := is_complete_image_iff f.isometry.uniform_inducing lemma is_complete_map_iff [ring_hom_surjective σ₁₂] {p : submodule R E} : is_complete (p.map f.to_linear_map : set E₂) ↔ is_complete (p : set E) := f.is_complete_image_iff instance complete_space_map [ring_hom_surjective σ₁₂] (p : submodule R E) [complete_space p] : complete_space (p.map f.to_linear_map) := (f.is_complete_map_iff.2 $ complete_space_coe_iff_is_complete.1 ‹_›).complete_space_coe @[simp] lemma dist_map (x y : E) : dist (f x) (f y) = dist x y := f.isometry.dist_eq x y @[simp] lemma edist_map (x y : E) : edist (f x) (f y) = edist x y := f.isometry.edist_eq x y protected lemma injective : injective f₁ := f₁.isometry.injective @[simp] lemma map_eq_iff {x y : F} : f₁ x = f₁ y ↔ x = y := f₁.injective.eq_iff lemma map_ne {x y : F} (h : x ≠ y) : f₁ x ≠ f₁ y := f₁.injective.ne h protected lemma lipschitz : lipschitz_with 1 f := f.isometry.lipschitz protected lemma antilipschitz : antilipschitz_with 1 f := f.isometry.antilipschitz @[continuity] protected lemma continuous : continuous f := f.isometry.continuous instance : continuous_semilinear_map_class (E →ₛₗᵢ[σ₁₂] E₂) σ₁₂ E E₂ := { map_smulₛₗ := λ f, f.map_smulₛₗ, map_continuous := λ f, f.continuous, ..linear_isometry.add_monoid_hom_class } lemma ediam_image (s : set E) : emetric.diam (f '' s) = emetric.diam s := f.isometry.ediam_image s lemma ediam_range : emetric.diam (range f) = emetric.diam (univ : set E) := f.isometry.ediam_range lemma diam_image (s : set E) : metric.diam (f '' s) = metric.diam s := f.isometry.diam_image s lemma diam_range : metric.diam (range f) = metric.diam (univ : set E) := f.isometry.diam_range /-- Interpret a linear isometry as a continuous linear map. -/ def to_continuous_linear_map : E →SL[σ₁₂] E₂ := ⟨f.to_linear_map, f.continuous⟩ lemma to_continuous_linear_map_injective : function.injective (to_continuous_linear_map : _ → E →SL[σ₁₂] E₂) := λ x y h, coe_injective (congr_arg _ h : ⇑x.to_continuous_linear_map = _) @[simp] lemma to_continuous_linear_map_inj {f g : E →ₛₗᵢ[σ₁₂] E₂} : f.to_continuous_linear_map = g.to_continuous_linear_map ↔ f = g := to_continuous_linear_map_injective.eq_iff @[simp] lemma coe_to_continuous_linear_map : ⇑f.to_continuous_linear_map = f := rfl @[simp] lemma comp_continuous_iff {α : Type*} [topological_space α] {g : α → E} : continuous (f ∘ g) ↔ continuous g := f.isometry.comp_continuous_iff /-- The identity linear isometry. -/ def id : E →ₗᵢ[R] E := ⟨linear_map.id, λ x, rfl⟩ @[simp] lemma coe_id : ((id : E →ₗᵢ[R] E) : E → E) = _root_.id := rfl @[simp] lemma id_apply (x : E) : (id : E →ₗᵢ[R] E) x = x := rfl @[simp] lemma id_to_linear_map : (id.to_linear_map : E →ₗ[R] E) = linear_map.id := rfl @[simp] lemma id_to_continuous_linear_map : id.to_continuous_linear_map = continuous_linear_map.id R E := rfl instance : inhabited (E →ₗᵢ[R] E) := ⟨id⟩ /-- Composition of linear isometries. -/ def comp (g : E₂ →ₛₗᵢ[σ₂₃] E₃) (f : E →ₛₗᵢ[σ₁₂] E₂) : E →ₛₗᵢ[σ₁₃] E₃ := ⟨g.to_linear_map.comp f.to_linear_map, λ x, (g.norm_map _).trans (f.norm_map _)⟩ include σ₁₃ @[simp] lemma coe_comp (g : E₂ →ₛₗᵢ[σ₂₃] E₃) (f : E →ₛₗᵢ[σ₁₂] E₂) : ⇑(g.comp f) = g ∘ f := rfl omit σ₁₃ @[simp] lemma id_comp : (id : E₂ →ₗᵢ[R₂] E₂).comp f = f := ext $ λ x, rfl @[simp] lemma comp_id : f.comp id = f := ext $ λ x, rfl include σ₁₃ σ₂₄ σ₁₄ lemma comp_assoc (f : E₃ →ₛₗᵢ[σ₃₄] E₄) (g : E₂ →ₛₗᵢ[σ₂₃] E₃) (h : E →ₛₗᵢ[σ₁₂] E₂) : (f.comp g).comp h = f.comp (g.comp h) := rfl omit σ₁₃ σ₂₄ σ₁₄ instance : monoid (E →ₗᵢ[R] E) := { one := id, mul := comp, mul_assoc := comp_assoc, one_mul := id_comp, mul_one := comp_id } @[simp] lemma coe_one : ((1 : E →ₗᵢ[R] E) : E → E) = _root_.id := rfl @[simp] lemma coe_mul (f g : E →ₗᵢ[R] E) : ⇑(f * g) = f ∘ g := rfl lemma one_def : (1 : E →ₗᵢ[R] E) = id := rfl lemma mul_def (f g : E →ₗᵢ[R] E) : (f * g : E →ₗᵢ[R] E) = f.comp g := rfl end linear_isometry /-- Construct a `linear_isometry` from a `linear_map` satisfying `isometry`. -/ def linear_map.to_linear_isometry (f : E →ₛₗ[σ₁₂] E₂) (hf : isometry f) : E →ₛₗᵢ[σ₁₂] E₂ := { norm_map' := by { simp_rw [←dist_zero_right, ←f.map_zero], exact λ x, hf.dist_eq x _ }, .. f } namespace submodule variables {R' : Type*} [ring R'] [module R' E] (p : submodule R' E) /-- `submodule.subtype` as a `linear_isometry`. -/ def subtypeₗᵢ : p →ₗᵢ[R'] E := ⟨p.subtype, λ x, rfl⟩ @[simp] lemma coe_subtypeₗᵢ : ⇑p.subtypeₗᵢ = p.subtype := rfl @[simp] lemma subtypeₗᵢ_to_linear_map : p.subtypeₗᵢ.to_linear_map = p.subtype := rfl /-- `submodule.subtype` as a `continuous_linear_map`. -/ def subtypeL : p →L[R'] E := p.subtypeₗᵢ.to_continuous_linear_map @[simp] lemma coe_subtypeL : (p.subtypeL : p →ₗ[R'] E) = p.subtype := rfl @[simp] lemma coe_subtypeL' : ⇑p.subtypeL = p.subtype := rfl @[simp] lemma range_subtypeL : p.subtypeL.range = p := range_subtype _ @[simp] lemma ker_subtypeL : p.subtypeL.ker = ⊥ := ker_subtype _ end submodule /-- A semilinear isometric equivalence between two normed vector spaces. -/ structure linear_isometry_equiv (σ₁₂ : R →+* R₂) {σ₂₁ : R₂ →+* R} [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂] (E E₂ : Type*) [semi_normed_group E] [semi_normed_group E₂] [module R E] [module R₂ E₂] extends E ≃ₛₗ[σ₁₂] E₂ := (norm_map' : ∀ x, ∥to_linear_equiv x∥ = ∥x∥) notation E ` ≃ₛₗᵢ[`:25 σ₁₂:25 `] `:0 E₂:0 := linear_isometry_equiv σ₁₂ E E₂ notation E ` ≃ₗᵢ[`:25 R:25 `] `:0 E₂:0 := linear_isometry_equiv (ring_hom.id R) E E₂ notation E ` ≃ₗᵢ⋆[`:25 R:25 `] `:0 E₂:0 := linear_isometry_equiv (star_ring_end R) E E₂ namespace linear_isometry_equiv variables (e : E ≃ₛₗᵢ[σ₁₂] E₂) include σ₂₁ lemma to_linear_equiv_injective : injective (to_linear_equiv : (E ≃ₛₗᵢ[σ₁₂] E₂) → (E ≃ₛₗ[σ₁₂] E₂)) | ⟨e, _⟩ ⟨_, _⟩ rfl := rfl @[simp] lemma to_linear_equiv_inj {f g : E ≃ₛₗᵢ[σ₁₂] E₂} : f.to_linear_equiv = g.to_linear_equiv ↔ f = g := to_linear_equiv_injective.eq_iff instance : add_monoid_hom_class (E ≃ₛₗᵢ[σ₁₂] E₂) E E₂ := { coe := λ e, e.to_fun, coe_injective' := λ f g h, to_linear_equiv_injective (fun_like.coe_injective h), map_add := λ f, map_add f.to_linear_equiv, map_zero := λ f, map_zero f.to_linear_equiv } /-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun` directly. -/ instance : has_coe_to_fun (E ≃ₛₗᵢ[σ₁₂] E₂) (λ _, E → E₂) := ⟨λ f, f.to_fun⟩ lemma coe_injective : @function.injective (E ≃ₛₗᵢ[σ₁₂] E₂) (E → E₂) coe_fn := fun_like.coe_injective @[simp] lemma coe_mk (e : E ≃ₛₗ[σ₁₂] E₂) (he : ∀ x, ∥e x∥ = ∥x∥) : ⇑(mk e he) = e := rfl @[simp] lemma coe_to_linear_equiv (e : E ≃ₛₗᵢ[σ₁₂] E₂) : ⇑e.to_linear_equiv = e := rfl @[ext] lemma ext {e e' : E ≃ₛₗᵢ[σ₁₂] E₂} (h : ∀ x, e x = e' x) : e = e' := to_linear_equiv_injective $ linear_equiv.ext h protected lemma congr_arg {f : E ≃ₛₗᵢ[σ₁₂] E₂} : Π {x x' : E}, x = x' → f x = f x' | _ _ rfl := rfl protected lemma congr_fun {f g : E ≃ₛₗᵢ[σ₁₂] E₂} (h : f = g) (x : E) : f x = g x := h ▸ rfl /-- Construct a `linear_isometry_equiv` from a `linear_equiv` and two inequalities: `∀ x, ∥e x∥ ≤ ∥x∥` and `∀ y, ∥e.symm y∥ ≤ ∥y∥`. -/ def of_bounds (e : E ≃ₛₗ[σ₁₂] E₂) (h₁ : ∀ x, ∥e x∥ ≤ ∥x∥) (h₂ : ∀ y, ∥e.symm y∥ ≤ ∥y∥) : E ≃ₛₗᵢ[σ₁₂] E₂ := ⟨e, λ x, le_antisymm (h₁ x) $ by simpa only [e.symm_apply_apply] using h₂ (e x)⟩ @[simp] lemma norm_map (x : E) : ∥e x∥ = ∥x∥ := e.norm_map' x /-- Reinterpret a `linear_isometry_equiv` as a `linear_isometry`. -/ def to_linear_isometry : E →ₛₗᵢ[σ₁₂] E₂ := ⟨e.1, e.2⟩ lemma to_linear_isometry_injective : function.injective (to_linear_isometry : _ → E →ₛₗᵢ[σ₁₂] E₂) := λ x y h, coe_injective (congr_arg _ h : ⇑x.to_linear_isometry = _) @[simp] lemma to_linear_isometry_inj {f g : E ≃ₛₗᵢ[σ₁₂] E₂} : f.to_linear_isometry = g.to_linear_isometry ↔ f = g := to_linear_isometry_injective.eq_iff @[simp] lemma coe_to_linear_isometry : ⇑e.to_linear_isometry = e := rfl protected lemma isometry : isometry e := e.to_linear_isometry.isometry /-- Reinterpret a `linear_isometry_equiv` as an `isometric`. -/ def to_isometric : E ≃ᵢ E₂ := ⟨e.to_linear_equiv.to_equiv, e.isometry⟩ lemma to_isometric_injective : function.injective (to_isometric : (E ≃ₛₗᵢ[σ₁₂] E₂) → E ≃ᵢ E₂) := λ x y h, coe_injective (congr_arg _ h : ⇑x.to_isometric = _) @[simp] lemma to_isometric_inj {f g : E ≃ₛₗᵢ[σ₁₂] E₂} : f.to_isometric = g.to_isometric ↔ f = g := to_isometric_injective.eq_iff @[simp] lemma coe_to_isometric : ⇑e.to_isometric = e := rfl lemma range_eq_univ (e : E ≃ₛₗᵢ[σ₁₂] E₂) : set.range e = set.univ := by { rw ← coe_to_isometric, exact isometric.range_eq_univ _, } /-- Reinterpret a `linear_isometry_equiv` as an `homeomorph`. -/ def to_homeomorph : E ≃ₜ E₂ := e.to_isometric.to_homeomorph lemma to_homeomorph_injective : function.injective (to_homeomorph : (E ≃ₛₗᵢ[σ₁₂] E₂) → E ≃ₜ E₂) := λ x y h, coe_injective (congr_arg _ h : ⇑x.to_homeomorph = _) @[simp] lemma to_homeomorph_inj {f g : E ≃ₛₗᵢ[σ₁₂] E₂} : f.to_homeomorph = g.to_homeomorph ↔ f = g := to_homeomorph_injective.eq_iff @[simp] lemma coe_to_homeomorph : ⇑e.to_homeomorph = e := rfl protected lemma continuous : continuous e := e.isometry.continuous protected lemma continuous_at {x} : continuous_at e x := e.continuous.continuous_at protected lemma continuous_on {s} : continuous_on e s := e.continuous.continuous_on protected lemma continuous_within_at {s x} : continuous_within_at e s x := e.continuous.continuous_within_at /-- Interpret a `linear_isometry_equiv` as a continuous linear equiv. -/ def to_continuous_linear_equiv : E ≃SL[σ₁₂] E₂ := { .. e.to_linear_isometry.to_continuous_linear_map, .. e.to_homeomorph } lemma to_continuous_linear_equiv_injective : function.injective (to_continuous_linear_equiv : _ → E ≃SL[σ₁₂] E₂) := λ x y h, coe_injective (congr_arg _ h : ⇑x.to_continuous_linear_equiv = _) @[simp] lemma to_continuous_linear_equiv_inj {f g : E ≃ₛₗᵢ[σ₁₂] E₂} : f.to_continuous_linear_equiv = g.to_continuous_linear_equiv ↔ f = g := to_continuous_linear_equiv_injective.eq_iff @[simp] lemma coe_to_continuous_linear_equiv : ⇑e.to_continuous_linear_equiv = e := rfl omit σ₂₁ variables (R E) /-- Identity map as a `linear_isometry_equiv`. -/ def refl : E ≃ₗᵢ[R] E := ⟨linear_equiv.refl R E, λ x, rfl⟩ variables {R E} instance : inhabited (E ≃ₗᵢ[R] E) := ⟨refl R E⟩ @[simp] lemma coe_refl : ⇑(refl R E) = id := rfl /-- The inverse `linear_isometry_equiv`. -/ def symm : E₂ ≃ₛₗᵢ[σ₂₁] E := ⟨e.to_linear_equiv.symm, λ x, (e.norm_map _).symm.trans $ congr_arg norm $ e.to_linear_equiv.apply_symm_apply x⟩ @[simp] lemma apply_symm_apply (x : E₂) : e (e.symm x) = x := e.to_linear_equiv.apply_symm_apply x @[simp] lemma symm_apply_apply (x : E) : e.symm (e x) = x := e.to_linear_equiv.symm_apply_apply x @[simp] lemma map_eq_zero_iff {x : E} : e x = 0 ↔ x = 0 := e.to_linear_equiv.map_eq_zero_iff @[simp] lemma symm_symm : e.symm.symm = e := ext $ λ x, rfl @[simp] lemma to_linear_equiv_symm : e.to_linear_equiv.symm = e.symm.to_linear_equiv := rfl @[simp] lemma to_isometric_symm : e.to_isometric.symm = e.symm.to_isometric := rfl @[simp] lemma to_homeomorph_symm : e.to_homeomorph.symm = e.symm.to_homeomorph := rfl include σ₃₁ σ₃₂ /-- Composition of `linear_isometry_equiv`s as a `linear_isometry_equiv`. -/ def trans (e' : E₂ ≃ₛₗᵢ[σ₂₃] E₃) : E ≃ₛₗᵢ[σ₁₃] E₃ := ⟨e.to_linear_equiv.trans e'.to_linear_equiv, λ x, (e'.norm_map _).trans (e.norm_map _)⟩ include σ₁₃ σ₂₁ @[simp] lemma coe_trans (e₁ : E ≃ₛₗᵢ[σ₁₂] E₂) (e₂ : E₂ ≃ₛₗᵢ[σ₂₃] E₃) : ⇑(e₁.trans e₂) = e₂ ∘ e₁ := rfl @[simp] lemma trans_apply (e₁ : E ≃ₛₗᵢ[σ₁₂] E₂) (e₂ : E₂ ≃ₛₗᵢ[σ₂₃] E₃) (c : E) : (e₁.trans e₂ : E ≃ₛₗᵢ[σ₁₃] E₃) c = e₂ (e₁ c) := rfl @[simp] lemma to_linear_equiv_trans (e' : E₂ ≃ₛₗᵢ[σ₂₃] E₃) : (e.trans e').to_linear_equiv = e.to_linear_equiv.trans e'.to_linear_equiv := rfl omit σ₁₃ σ₂₁ σ₃₁ σ₃₂ @[simp] lemma trans_refl : e.trans (refl R₂ E₂) = e := ext $ λ x, rfl @[simp] lemma refl_trans : (refl R E).trans e = e := ext $ λ x, rfl @[simp] lemma self_trans_symm : e.trans e.symm = refl R E := ext e.symm_apply_apply @[simp] lemma symm_trans_self : e.symm.trans e = refl R₂ E₂ := ext e.apply_symm_apply @[simp] lemma symm_comp_self : e.symm ∘ e = id := funext e.symm_apply_apply @[simp] lemma self_comp_symm : e ∘ e.symm = id := e.symm.symm_comp_self include σ₁₃ σ₂₁ σ₃₂ σ₃₁ @[simp] lemma symm_trans (e₁ : E ≃ₛₗᵢ[σ₁₂] E₂) (e₂ : E₂ ≃ₛₗᵢ[σ₂₃] E₃) : (e₁.trans e₂).symm = e₂.symm.trans e₁.symm := rfl lemma coe_symm_trans (e₁ : E ≃ₛₗᵢ[σ₁₂] E₂) (e₂ : E₂ ≃ₛₗᵢ[σ₂₃] E₃) : ⇑(e₁.trans e₂).symm = e₁.symm ∘ e₂.symm := rfl include σ₁₄ σ₄₁ σ₄₂ σ₄₃ σ₂₄ lemma trans_assoc (eEE₂ : E ≃ₛₗᵢ[σ₁₂] E₂) (eE₂E₃ : E₂ ≃ₛₗᵢ[σ₂₃] E₃) (eE₃E₄ : E₃ ≃ₛₗᵢ[σ₃₄] E₄) : eEE₂.trans (eE₂E₃.trans eE₃E₄) = (eEE₂.trans eE₂E₃).trans eE₃E₄ := rfl omit σ₂₁ σ₃₁ σ₄₁ σ₃₂ σ₄₂ σ₄₃ σ₁₃ σ₂₄ σ₁₄ instance : group (E ≃ₗᵢ[R] E) := { mul := λ e₁ e₂, e₂.trans e₁, one := refl _ _, inv := symm, one_mul := trans_refl, mul_one := refl_trans, mul_assoc := λ _ _ _, trans_assoc _ _ _, mul_left_inv := self_trans_symm } @[simp] lemma coe_one : ⇑(1 : E ≃ₗᵢ[R] E) = id := rfl @[simp] lemma coe_mul (e e' : E ≃ₗᵢ[R] E) : ⇑(e * e') = e ∘ e' := rfl @[simp] lemma coe_inv (e : E ≃ₗᵢ[R] E) : ⇑(e⁻¹) = e.symm := rfl lemma one_def : (1 : E ≃ₗᵢ[R] E) = refl _ _ := rfl lemma mul_def (e e' : E ≃ₗᵢ[R] E) : (e * e' : E ≃ₗᵢ[R] E) = e'.trans e := rfl lemma inv_def (e : E ≃ₗᵢ[R] E) : (e⁻¹ : E ≃ₗᵢ[R] E) = e.symm := rfl /-! Lemmas about mixing the group structure with definitions. Because we have multiple ways to express `linear_isometry_equiv.refl`, `linear_isometry_equiv.symm`, and `linear_isometry_equiv.trans`, we want simp lemmas for every combination. The assumption made here is that if you're using the group structure, you want to preserve it after simp. This copies the approach used by the lemmas near `equiv.perm.trans_one`. -/ @[simp] lemma trans_one : e.trans (1 : E₂ ≃ₗᵢ[R₂] E₂) = e := trans_refl _ @[simp] lemma one_trans : (1 : E ≃ₗᵢ[R] E).trans e = e := refl_trans _ @[simp] lemma refl_mul (e : E ≃ₗᵢ[R] E) : (refl _ _) * e = e := trans_refl _ @[simp] lemma mul_refl (e : E ≃ₗᵢ[R] E) : e * (refl _ _) = e := refl_trans _ include σ₂₁ /-- Reinterpret a `linear_isometry_equiv` as a `continuous_linear_equiv`. -/ instance : has_coe_t (E ≃ₛₗᵢ[σ₁₂] E₂) (E ≃SL[σ₁₂] E₂) := ⟨λ e, ⟨e.to_linear_equiv, e.continuous, e.to_isometric.symm.continuous⟩⟩ instance : has_coe_t (E ≃ₛₗᵢ[σ₁₂] E₂) (E →SL[σ₁₂] E₂) := ⟨λ e, ↑(e : E ≃SL[σ₁₂] E₂)⟩ @[simp] lemma coe_coe : ⇑(e : E ≃SL[σ₁₂] E₂) = e := rfl @[simp] lemma coe_coe' : ((e : E ≃SL[σ₁₂] E₂) : E →SL[σ₁₂] E₂) = e := rfl @[simp] lemma coe_coe'' : ⇑(e : E →SL[σ₁₂] E₂) = e := rfl omit σ₂₁ @[simp] lemma map_zero : e 0 = 0 := e.1.map_zero @[simp] lemma map_add (x y : E) : e (x + y) = e x + e y := e.1.map_add x y @[simp] lemma map_sub (x y : E) : e (x - y) = e x - e y := e.1.map_sub x y @[simp] lemma map_smulₛₗ (c : R) (x : E) : e (c • x) = σ₁₂ c • e x := e.1.map_smulₛₗ c x @[simp] lemma map_smul [module R E₂] {e : E ≃ₗᵢ[R] E₂} (c : R) (x : E) : e (c • x) = c • e x := e.1.map_smul c x @[simp] lemma nnnorm_map (x : E) : ∥e x∥₊ = ∥x∥₊ := e.to_linear_isometry.nnnorm_map x @[simp] lemma dist_map (x y : E) : dist (e x) (e y) = dist x y := e.to_linear_isometry.dist_map x y @[simp] lemma edist_map (x y : E) : edist (e x) (e y) = edist x y := e.to_linear_isometry.edist_map x y protected lemma bijective : bijective e := e.1.bijective protected lemma injective : injective e := e.1.injective protected lemma surjective : surjective e := e.1.surjective @[simp] lemma map_eq_iff {x y : E} : e x = e y ↔ x = y := e.injective.eq_iff lemma map_ne {x y : E} (h : x ≠ y) : e x ≠ e y := e.injective.ne h protected lemma lipschitz : lipschitz_with 1 e := e.isometry.lipschitz protected lemma antilipschitz : antilipschitz_with 1 e := e.isometry.antilipschitz @[simp] lemma ediam_image (s : set E) : emetric.diam (e '' s) = emetric.diam s := e.isometry.ediam_image s @[simp] lemma diam_image (s : set E) : metric.diam (e '' s) = metric.diam s := e.isometry.diam_image s variables {α : Type*} [topological_space α] @[simp] lemma comp_continuous_on_iff {f : α → E} {s : set α} : continuous_on (e ∘ f) s ↔ continuous_on f s := e.isometry.comp_continuous_on_iff @[simp] lemma comp_continuous_iff {f : α → E} : continuous (e ∘ f) ↔ continuous f := e.isometry.comp_continuous_iff instance complete_space_map (p : submodule R E) [complete_space p] : complete_space (p.map (e.to_linear_equiv : E →ₛₗ[σ₁₂] E₂)) := e.to_linear_isometry.complete_space_map p include σ₂₁ /-- Construct a linear isometry equiv from a surjective linear isometry. -/ noncomputable def of_surjective (f : F →ₛₗᵢ[σ₁₂] E₂) (hfr : function.surjective f) : F ≃ₛₗᵢ[σ₁₂] E₂ := { norm_map' := f.norm_map, .. linear_equiv.of_bijective f.to_linear_map f.injective hfr } @[simp] lemma coe_of_surjective (f : F →ₛₗᵢ[σ₁₂] E₂) (hfr : function.surjective f) : ⇑(linear_isometry_equiv.of_surjective f hfr) = f := by { ext, refl } omit σ₂₁ variables (R) /-- The negation operation on a normed space `E`, considered as a linear isometry equivalence. -/ def neg : E ≃ₗᵢ[R] E := { norm_map' := norm_neg, .. linear_equiv.neg R } variables {R} @[simp] lemma coe_neg : (neg R : E → E) = λ x, -x := rfl @[simp] lemma symm_neg : (neg R : E ≃ₗᵢ[R] E).symm = neg R := rfl variables (R E E₂ E₃) /-- The natural equivalence `(E × E₂) × E₃ ≃ E × (E₂ × E₃)` is a linear isometry. -/ def prod_assoc [module R E₂] [module R E₃] : (E × E₂) × E₃ ≃ₗᵢ[R] E × E₂ × E₃ := { to_fun := equiv.prod_assoc E E₂ E₃, inv_fun := (equiv.prod_assoc E E₂ E₃).symm, map_add' := by simp, map_smul' := by simp, norm_map' := begin rintros ⟨⟨e, f⟩, g⟩, simp only [linear_equiv.coe_mk, equiv.prod_assoc_apply, prod.norm_def, max_assoc], end, .. equiv.prod_assoc E E₂ E₃, } @[simp] lemma coe_prod_assoc [module R E₂] [module R E₃] : (prod_assoc R E E₂ E₃ : (E × E₂) × E₃ → E × E₂ × E₃) = equiv.prod_assoc E E₂ E₃ := rfl @[simp] lemma coe_prod_assoc_symm [module R E₂] [module R E₃] : ((prod_assoc R E E₂ E₃).symm : E × E₂ × E₃ → (E × E₂) × E₃) = (equiv.prod_assoc E E₂ E₃).symm := rfl end linear_isometry_equiv /-- Two linear isometries are equal if they are equal on basis vectors. -/ lemma basis.ext_linear_isometry {ι : Type*} (b : basis ι R E) {f₁ f₂ : E →ₛₗᵢ[σ₁₂] E₂} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := linear_isometry.to_linear_map_injective $ b.ext h include σ₂₁ /-- Two linear isometric equivalences are equal if they are equal on basis vectors. -/ lemma basis.ext_linear_isometry_equiv {ι : Type*} (b : basis ι R E) {f₁ f₂ : E ≃ₛₗᵢ[σ₁₂] E₂} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := linear_isometry_equiv.to_linear_equiv_injective $ b.ext' h omit σ₂₁
fd1b314c88d4b560ab0ad8840868cade02b1ce30
6b10c15e653d49d146378acda9f3692e9b5b1950
/examples/logic/unnamed_227.lean
47541374813ce53b9d7d3e2e3e0fa5e62b5c2580
[]
no_license
gebner/mathematics_in_lean
3cf7f18767208ea6c3307ec3a67c7ac266d8514d
6d1462bba46d66a9b948fc1aef2714fd265cde0b
refs/heads/master
1,655,301,945,565
1,588,697,505,000
1,588,697,505,000
261,523,603
0
0
null
1,588,695,611,000
1,588,695,610,000
null
UTF-8
Lean
false
false
200
lean
variables A B C : Prop -- BEGIN example (h₁ : A → B) (h₂ : B → C) : A → C := begin intro h₃, have h₄ : B, { apply h₁, apply h₃ }, show C, apply h₂, apply h₄ end -- END
fbf7bad307cfef77aba36aded680ff3205d73047
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/src/Init/Lean/Compiler/IR/Boxing.lean
0ff72c058ae6c2f521d11964a73f20c5db0d76a0
[ "Apache-2.0" ]
permissive
mhuisi/lean4
28d35a4febc2e251c7f05492e13f3b05d6f9b7af
dda44bc47f3e5d024508060dac2bcb59fd12e4c0
refs/heads/master
1,621,225,489,283
1,585,142,689,000
1,585,142,689,000
250,590,438
0
2
Apache-2.0
1,602,443,220,000
1,585,327,814,000
C
UTF-8
Lean
false
false
12,974
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import Init.Control.EState import Init.Control.Reader import Init.Data.AssocList import Init.Data.Nat import Init.Lean.Runtime import Init.Lean.Compiler.ClosedTermCache import Init.Lean.Compiler.ExternAttr import Init.Lean.Compiler.IR.Basic import Init.Lean.Compiler.IR.CompilerM import Init.Lean.Compiler.IR.FreeVars import Init.Lean.Compiler.IR.ElimDeadVars namespace Lean namespace IR namespace ExplicitBoxing /- Add explicit boxing and unboxing instructions. Recall that the Lean to λ_pure compiler produces code without these instructions. Assumptions: - This transformation is applied before explicit RC instructions (`inc`, `dec`) are inserted. - This transformation is applied before `FnBody.case` has been simplified and `Alt.default` is used. Reason: if there is no `Alt.default` branch, then we can decide whether `x` at `FnBody.case x alts` is an enumeration type by simply inspecting the `CtorInfo` values at `alts`. - This transformation is applied before lower level optimizations are applied which use `Expr.isShared`, `Expr.isTaggedPtr`, and `FnBody.set`. - This transformation is applied after `reset` and `reuse` instructions have been added. Reason: `resetreuse.lean` ignores `box` and `unbox` instructions. -/ def mkBoxedName (n : Name) : Name := mkNameStr n "_boxed" def isBoxedName : Name → Bool | Name.str _ "_boxed" _ => true | _ => false abbrev N := StateM Nat private def mkFresh : N VarId := modifyGet $ fun n => ({ idx := n }, n + 1) def requiresBoxedVersion (env : Environment) (decl : Decl) : Bool := let ps := decl.params; (ps.size > 0 && (decl.resultType.isScalar || ps.any (fun p => p.ty.isScalar || p.borrow) || isExtern env decl.name)) || ps.size > closureMaxArgs def mkBoxedVersionAux (decl : Decl) : N Decl := do let ps := decl.params; qs ← ps.mapM (fun _ => do x ← mkFresh; pure { Param . x := x, ty := IRType.object, borrow := false }); (newVDecls, xs) ← qs.size.foldM (fun i (r : Array FnBody × Array Arg) => let (newVDecls, xs) := r; let p := ps.get! i; let q := qs.get! i; if !p.ty.isScalar then pure (newVDecls, xs.push (Arg.var q.x)) else do x ← mkFresh; pure (newVDecls.push (FnBody.vdecl x p.ty (Expr.unbox q.x) (arbitrary _)), xs.push (Arg.var x))) (#[], #[]); r ← mkFresh; let newVDecls := newVDecls.push (FnBody.vdecl r decl.resultType (Expr.fap decl.name xs) (arbitrary _)); body ← if !decl.resultType.isScalar then do { pure $ reshape newVDecls (FnBody.ret (Arg.var r)) } else do { newR ← mkFresh; let newVDecls := newVDecls.push (FnBody.vdecl newR IRType.object (Expr.box decl.resultType r) (arbitrary _)); pure $ reshape newVDecls (FnBody.ret (Arg.var newR)) }; pure $ Decl.fdecl (mkBoxedName decl.name) qs IRType.object body def mkBoxedVersion (decl : Decl) : Decl := (mkBoxedVersionAux decl).run' 1 def addBoxedVersions (env : Environment) (decls : Array Decl) : Array Decl := let boxedDecls := decls.foldl (fun (newDecls : Array Decl) decl => if requiresBoxedVersion env decl then newDecls.push (mkBoxedVersion decl) else newDecls) #[]; decls ++ boxedDecls /- Infer scrutinee type using `case` alternatives. This can be done whenever `alts` does not contain an `Alt.default _` value. -/ def getScrutineeType (alts : Array Alt) : IRType := let isScalar := alts.size > 1 && -- Recall that we encode Unit and PUnit using `object`. alts.all (fun alt => match alt with | Alt.ctor c _ => c.isScalar | Alt.default _ => false); match isScalar with | false => IRType.object | true => let n := alts.size; if n < 256 then IRType.uint8 else if n < 65536 then IRType.uint16 else if n < 4294967296 then IRType.uint32 else IRType.object -- in practice this should be unreachable def eqvTypes (t₁ t₂ : IRType) : Bool := (t₁.isScalar == t₂.isScalar) && (!t₁.isScalar || t₁ == t₂) structure BoxingContext := (f : FunId := arbitrary _) (localCtx : LocalContext := {}) (resultType : IRType := IRType.irrelevant) (decls : Array Decl) (env : Environment) structure BoxingState := (nextIdx : Index) /- We create auxiliary declarations when boxing constant and literals. The idea is to avoid code such as ``` let x1 := Uint64.inhabited; let x2 := box x1; ... ``` We currently do not cache these declarations in an environment extension, but we use auxDeclCache to avoid creating equivalent auxiliary declarations more than once when processing the same IR declaration. -/ (auxDecls : Array Decl := #[]) (auxDeclCache : AssocList FnBody Expr := AssocList.empty) (nextAuxId : Nat := 1) abbrev M := ReaderT BoxingContext (StateT BoxingState Id) def mkFresh : M VarId := do oldS ← getModify (fun s => { nextIdx := s.nextIdx + 1, .. s }); pure { idx := oldS.nextIdx } def getEnv : M Environment := BoxingContext.env <$> read def getLocalContext : M LocalContext := BoxingContext.localCtx <$> read def getResultType : M IRType := BoxingContext.resultType <$> read def getVarType (x : VarId) : M IRType := do localCtx ← getLocalContext; match localCtx.getType x with | some t => pure t | none => pure IRType.object -- unreachable, we assume the code is well formed def getJPParams (j : JoinPointId) : M (Array Param) := do localCtx ← getLocalContext; match localCtx.getJPParams j with | some ys => pure ys | none => pure #[] -- unreachable, we assume the code is well formed def getDecl (fid : FunId) : M Decl := do ctx ← read; match findEnvDecl' ctx.env fid ctx.decls with | some decl => pure decl | none => pure (arbitrary _) -- unreachable if well-formed @[inline] def withParams {α : Type} (xs : Array Param) (k : M α) : M α := adaptReader (fun (ctx : BoxingContext) => { localCtx := ctx.localCtx.addParams xs, .. ctx }) k @[inline] def withVDecl {α : Type} (x : VarId) (ty : IRType) (v : Expr) (k : M α) : M α := adaptReader (fun (ctx : BoxingContext) => { localCtx := ctx.localCtx.addLocal x ty v, .. ctx }) k @[inline] def withJDecl {α : Type} (j : JoinPointId) (xs : Array Param) (v : FnBody) (k : M α) : M α := adaptReader (fun (ctx : BoxingContext) => { localCtx := ctx.localCtx.addJP j xs v, .. ctx }) k /- If `x` declaration is of the form `x := Expr.lit _` or `x := Expr.fap c #[]`, and `x`'s type is not cheap to box (e.g., it is `UInt64), then return its value. -/ private def isExpensiveConstantValueBoxing (x : VarId) (xType : IRType) : M (Option Expr) := if !xType.isScalar then pure none -- We assume unboxing is always cheap else match xType with | IRType.uint8 => pure none | IRType.uint16 => pure none | _ => do localCtx ← getLocalContext; match localCtx.getValue x with | some val => match val with | Expr.lit _ => pure $ some val | Expr.fap _ args => pure $ if args.size == 0 then some val else none | _ => pure none | _ => pure none /- Auxiliary function used by castVarIfNeeded. It is used when the expected type does not match `xType`. If `xType` is scalar, then we need to "box" it. Otherwise, we need to "unbox" it. -/ def mkCast (x : VarId) (xType : IRType) (expectedType : IRType) : M Expr := do opt? ← isExpensiveConstantValueBoxing x xType; match opt? with | some v => do ctx ← read; s ← get; /- Create auxiliary FnBody ``` let x_1 : xType := v; let x_2 : expectedType := Expr.box xType x_1; ret x_2 ``` -/ let body : FnBody := FnBody.vdecl { idx := 1 } xType v $ FnBody.vdecl { idx := 2 } expectedType (Expr.box xType { idx := 1 }) $ FnBody.ret (mkVarArg { idx := 2 }); match s.auxDeclCache.find? body with | some v => pure v | none => do let auxName := ctx.f ++ ((`_boxed_const).appendIndexAfter s.nextAuxId); let auxConst := Expr.fap auxName #[]; let auxDecl := Decl.fdecl auxName #[] expectedType body; modify $ fun s => { auxDecls := s.auxDecls.push auxDecl, auxDeclCache := s.auxDeclCache.cons body auxConst, nextAuxId := s.nextAuxId + 1, .. s }; pure auxConst | none => pure $ if xType.isScalar then Expr.box xType x else Expr.unbox x @[inline] def castVarIfNeeded (x : VarId) (expected : IRType) (k : VarId → M FnBody) : M FnBody := do xType ← getVarType x; if eqvTypes xType expected then k x else do y ← mkFresh; v ← mkCast x xType expected; FnBody.vdecl y expected v <$> k y @[inline] def castArgIfNeeded (x : Arg) (expected : IRType) (k : Arg → M FnBody) : M FnBody := match x with | Arg.var x => castVarIfNeeded x expected (fun x => k (Arg.var x)) | _ => k x @[specialize] def castArgsIfNeededAux (xs : Array Arg) (typeFromIdx : Nat → IRType) : M (Array Arg × Array FnBody) := xs.iterateM (#[], #[]) $ fun i (x : Arg) (r : Array Arg × Array FnBody) => let expected := typeFromIdx i.val; let (xs, bs) := r; match x with | Arg.irrelevant => pure (xs.push x, bs) | Arg.var x => do xType ← getVarType x; if eqvTypes xType expected then pure (xs.push (Arg.var x), bs) else do y ← mkFresh; v ← mkCast x xType expected; let b := FnBody.vdecl y expected v FnBody.nil; pure (xs.push (Arg.var y), bs.push b) @[inline] def castArgsIfNeeded (xs : Array Arg) (ps : Array Param) (k : Array Arg → M FnBody) : M FnBody := do (ys, bs) ← castArgsIfNeededAux xs (fun i => (ps.get! i).ty); b ← k ys; pure (reshape bs b) @[inline] def boxArgsIfNeeded (xs : Array Arg) (k : Array Arg → M FnBody) : M FnBody := do (ys, bs) ← castArgsIfNeededAux xs (fun _ => IRType.object); b ← k ys; pure (reshape bs b) def unboxResultIfNeeded (x : VarId) (ty : IRType) (e : Expr) (b : FnBody) : M FnBody := if ty.isScalar then do y ← mkFresh; pure $ FnBody.vdecl y IRType.object e (FnBody.vdecl x ty (Expr.unbox y) b) else pure $ FnBody.vdecl x ty e b def castResultIfNeeded (x : VarId) (ty : IRType) (e : Expr) (eType : IRType) (b : FnBody) : M FnBody := if eqvTypes ty eType then pure $ FnBody.vdecl x ty e b else do y ← mkFresh; v ← mkCast y eType ty; pure $ FnBody.vdecl y eType e (FnBody.vdecl x ty v b) def visitVDeclExpr (x : VarId) (ty : IRType) (e : Expr) (b : FnBody) : M FnBody := match e with | Expr.ctor c ys => if c.isScalar && ty.isScalar then pure $ FnBody.vdecl x ty (Expr.lit (LitVal.num c.cidx)) b else boxArgsIfNeeded ys $ fun ys => pure $ FnBody.vdecl x ty (Expr.ctor c ys) b | Expr.reuse w c u ys => boxArgsIfNeeded ys $ fun ys => pure $ FnBody.vdecl x ty (Expr.reuse w c u ys) b | Expr.fap f ys => do decl ← getDecl f; castArgsIfNeeded ys decl.params $ fun ys => castResultIfNeeded x ty (Expr.fap f ys) decl.resultType b | Expr.pap f ys => do env ← getEnv; decl ← getDecl f; let f := if requiresBoxedVersion env decl then mkBoxedName f else f; boxArgsIfNeeded ys $ fun ys => pure $ FnBody.vdecl x ty (Expr.pap f ys) b | Expr.ap f ys => boxArgsIfNeeded ys $ fun ys => unboxResultIfNeeded x ty (Expr.ap f ys) b | other => pure $ FnBody.vdecl x ty e b partial def visitFnBody : FnBody → M FnBody | FnBody.vdecl x t v b => do b ← withVDecl x t v (visitFnBody b); visitVDeclExpr x t v b | FnBody.jdecl j xs v b => do v ← withParams xs (visitFnBody v); b ← withJDecl j xs v (visitFnBody b); pure $ FnBody.jdecl j xs v b | FnBody.uset x i y b => do b ← visitFnBody b; castVarIfNeeded y IRType.usize $ fun y => pure $ FnBody.uset x i y b | FnBody.sset x i o y ty b => do b ← visitFnBody b; castVarIfNeeded y ty $ fun y => pure $ FnBody.sset x i o y ty b | FnBody.mdata d b => FnBody.mdata d <$> visitFnBody b | FnBody.case tid x _ alts => do let expected := getScrutineeType alts; alts ← alts.mapM $ fun alt => alt.mmodifyBody visitFnBody; castVarIfNeeded x expected $ fun x => do pure $ FnBody.case tid x expected alts | FnBody.ret x => do expected ← getResultType; castArgIfNeeded x expected (fun x => pure $ FnBody.ret x) | FnBody.jmp j ys => do ps ← getJPParams j; castArgsIfNeeded ys ps (fun ys => pure $ FnBody.jmp j ys) | other => pure other def run (env : Environment) (decls : Array Decl) : Array Decl := let ctx : BoxingContext := { decls := decls, env := env }; let decls := decls.foldl (fun (newDecls : Array Decl) (decl : Decl) => match decl with | Decl.fdecl f xs t b => let nextIdx := decl.maxIndex + 1; let (b, s) := (withParams xs (visitFnBody b) { f := f, resultType := t, .. ctx }).run { nextIdx := nextIdx }; let newDecls := newDecls ++ s.auxDecls; let newDecl := Decl.fdecl f xs t b; let newDecl := newDecl.elimDead; newDecls.push newDecl | d => newDecls.push d) #[]; addBoxedVersions env decls end ExplicitBoxing def explicitBoxing (decls : Array Decl) : CompilerM (Array Decl) := do env ← getEnv; pure $ ExplicitBoxing.run env decls end IR end Lean
d52aeaefb304a7d8fb5e9506feaf331a898b4691
fbf512ee44de430e3d3c5869751ad95325c938d7
/snf.lean
13dc6d16f078285b6f672c5a95bc8d121680369e
[]
no_license
skbaek/clausify
4858c9005fb86a5e410bfcaa77524f82d955f655
d09b071bdcce7577c3fffacd0893b776285b1590
refs/heads/master
1,588,360,590,818
1,553,553,880,000
1,553,553,880,000
177,644,542
0
0
null
null
null
null
UTF-8
Lean
false
false
829
lean
import .form variables {α : Type} namespace form def skolem_term (k ms) : term := list.foldl (λ t1 m, t1 ^* # m) (& k) ms def snf_core : nat → form → (nat × form) | k ⊤* := (k, ⊤*) | k ⊥* := (k, ⊥*) | k (m ** ts) := (k, m ** ts) | k (¬* p) := (k, ¬* p) | k (p ∧* q) := let (m, p') := snf_core k p in let (n, q') := snf_core m q in (n, p' ∧* q') | k (p ∨* q) := let (m, p') := snf_core k p in let (n, q') := snf_core m q in (n, p' ∨* q') | k (∀* p) := let (m, p') := snf_core k p in (m, ∀* p') | k (∃* p) := let (m, p') := snf_core k p in let xs := fv p' in (m+1, subst 0 (skolem_term m (fv p')) p') def snf (p) := (snf_core (fresh_func_idx p) p).snd #exit lemma snf_equisat : ∀ p, (sat α (snf p) ↔ sat α p) := sorry end form
d7cc03507be3b0397fbe92c136804627aac360a1
9dc8cecdf3c4634764a18254e94d43da07142918
/src/topology/constructions.lean
757cb51a8ff069a2a70ec7abfdaa7f83441e22f7
[ "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
57,863
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 import topology.locally_finite import order.filter.pi import data.fin.tuple /-! # 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 function open_locale classical topological_space filter universes u v variables {α : Type u} {β : Type v} {γ δ ε ζ : Type*} 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 /-! ### `additive`, `multiplicative` The topology on those type synonyms is inherited without change. -/ section variables [topological_space α] open additive multiplicative instance : topological_space (additive α) := ‹topological_space α› instance : topological_space (multiplicative α) := ‹topological_space α› instance [discrete_topology α] : discrete_topology (additive α) := ‹discrete_topology α› instance [discrete_topology α] : discrete_topology (multiplicative α) := ‹discrete_topology α› lemma continuous_of_mul : continuous (of_mul : α → additive α) := continuous_id lemma continuous_to_mul : continuous (to_mul : additive α → α) := continuous_id lemma continuous_of_add : continuous (of_add : α → multiplicative α) := continuous_id lemma continuous_to_add : continuous (to_add : multiplicative α → α) := continuous_id lemma is_open_map_of_mul : is_open_map (of_mul : α → additive α) := is_open_map.id lemma is_open_map_to_mul : is_open_map (to_mul : additive α → α) := is_open_map.id lemma is_open_map_of_add : is_open_map (of_add : α → multiplicative α) := is_open_map.id lemma is_open_map_to_add : is_open_map (to_add : multiplicative α → α) := is_open_map.id lemma is_closed_map_of_mul : is_closed_map (of_mul : α → additive α) := is_closed_map.id lemma is_closed_map_to_mul : is_closed_map (to_mul : additive α → α) := is_closed_map.id lemma is_closed_map_of_add : is_closed_map (of_add : α → multiplicative α) := is_closed_map.id lemma is_closed_map_to_add : is_closed_map (to_add : multiplicative α → α) := is_closed_map.id local attribute [semireducible] nhds lemma nhds_of_mul (a : α) : 𝓝 (of_mul a) = map of_mul (𝓝 a) := rfl lemma nhds_of_add (a : α) : 𝓝 (of_add a) = map of_add (𝓝 a) := rfl lemma nhds_to_mul (a : additive α) : 𝓝 (to_mul a) = map to_mul (𝓝 a) := rfl lemma nhds_to_add (a : multiplicative α) : 𝓝 (to_add a) = map to_add (𝓝 a) := rfl end /-! ### Order dual The topology on this type synonym is inherited without change. -/ section variables [topological_space α] open order_dual instance : topological_space αᵒᵈ := ‹topological_space α› instance [discrete_topology α] : discrete_topology (αᵒᵈ) := ‹discrete_topology α› lemma continuous_to_dual : continuous (to_dual : α → αᵒᵈ) := continuous_id lemma continuous_of_dual : continuous (of_dual : αᵒᵈ → α) := continuous_id lemma is_open_map_to_dual : is_open_map (to_dual : α → αᵒᵈ) := is_open_map.id lemma is_open_map_of_dual : is_open_map (of_dual : αᵒᵈ → α) := is_open_map.id lemma is_closed_map_to_dual : is_closed_map (to_dual : α → αᵒᵈ) := is_closed_map.id lemma is_closed_map_of_dual : is_closed_map (of_dual : αᵒᵈ → α) := is_closed_map.id local attribute [semireducible] nhds lemma nhds_to_dual (a : α) : 𝓝 (to_dual a) = map to_dual (𝓝 a) := rfl lemma nhds_of_dual (a : α) : 𝓝 (of_dual a) = map of_dual (𝓝 a) := rfl end lemma quotient.preimage_mem_nhds [topological_space α] [s : setoid α] {V : set $ quotient s} {a : α} (hs : V ∈ 𝓝 (quotient.mk a)) : quotient.mk ⁻¹' V ∈ 𝓝 a := preimage_nhds_coinduced hs /-- 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α /-- A type synonym equiped with the topology whose open sets are the empty set and the sets with finite complements. -/ def cofinite_topology (α : Type*) := α namespace cofinite_topology /-- The identity equivalence between `α` and `cofinite_topology α`. -/ def of : α ≃ cofinite_topology α := equiv.refl α instance [inhabited α] : inhabited (cofinite_topology α) := { default := of default } instance : topological_space (cofinite_topology α) := { is_open := λ s, s.nonempty → set.finite sᶜ, is_open_univ := by simp, is_open_inter := λ s t, begin rintros hs ht ⟨x, hxs, hxt⟩, rw compl_inter, exact (hs ⟨x, hxs⟩).union (ht ⟨x, hxt⟩), end, is_open_sUnion := begin rintros s h ⟨x, t, hts, hzt⟩, rw set.compl_sUnion, exact set.finite.sInter (mem_image_of_mem _ hts) (h t hts ⟨x, hzt⟩), end } lemma is_open_iff {s : set (cofinite_topology α)} : is_open s ↔ (s.nonempty → (sᶜ).finite) := iff.rfl lemma is_open_iff' {s : set (cofinite_topology α)} : is_open s ↔ (s = ∅ ∨ (sᶜ).finite) := by simp only [is_open_iff, ← ne_empty_iff_nonempty, or_iff_not_imp_left] lemma is_closed_iff {s : set (cofinite_topology α)} : is_closed s ↔ s = univ ∨ s.finite := by simp [← is_open_compl_iff, is_open_iff'] lemma nhds_eq (a : cofinite_topology α) : 𝓝 a = pure a ⊔ cofinite := begin ext U, rw mem_nhds_iff, split, { rintro ⟨V, hVU, V_op, haV⟩, exact mem_sup.mpr ⟨hVU haV, mem_of_superset (V_op ⟨_, haV⟩) hVU⟩ }, { rintros ⟨hU : a ∈ U, hU' : (Uᶜ).finite⟩, exact ⟨U, subset.rfl, λ h, hU', hU⟩ } end lemma mem_nhds_iff {a : cofinite_topology α} {s : set (cofinite_topology α)} : s ∈ 𝓝 a ↔ a ∈ s ∧ sᶜ.finite := by simp [nhds_eq] end cofinite_topology end constructions section prod variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ] [topological_space ε] [topological_space ζ] @[continuity] lemma continuous_fst : continuous (@prod.fst α β) := continuous_inf_dom_left continuous_induced_dom /-- Postcomposing `f` with `prod.fst` is continuous -/ lemma continuous.fst {f : α → β × γ} (hf : continuous f) : continuous (λ a : α, (f a).1) := continuous_fst.comp hf /-- Precomposing `f` with `prod.fst` is continuous -/ lemma continuous.fst' {f : α → γ} (hf : continuous f) : continuous (λ x : α × β, f x.fst) := hf.comp continuous_fst lemma continuous_at_fst {p : α × β} : continuous_at prod.fst p := continuous_fst.continuous_at /-- Postcomposing `f` with `prod.fst` is continuous at `x` -/ lemma continuous_at.fst {f : α → β × γ} {x : α} (hf : continuous_at f x) : continuous_at (λ a : α, (f a).1) x := continuous_at_fst.comp hf /-- Precomposing `f` with `prod.fst` is continuous at `(x, y)` -/ lemma continuous_at.fst' {f : α → γ} {x : α} {y : β} (hf : continuous_at f x) : continuous_at (λ x : α × β, f x.fst) (x, y) := continuous_at.comp hf continuous_at_fst /-- Precomposing `f` with `prod.fst` is continuous at `x : α × β` -/ lemma continuous_at.fst'' {f : α → γ} {x : α × β} (hf : continuous_at f x.fst) : continuous_at (λ x : α × β, f x.fst) x := hf.comp continuous_at_fst @[continuity] lemma continuous_snd : continuous (@prod.snd α β) := continuous_inf_dom_right continuous_induced_dom /-- Postcomposing `f` with `prod.snd` is continuous -/ lemma continuous.snd {f : α → β × γ} (hf : continuous f) : continuous (λ a : α, (f a).2) := continuous_snd.comp hf /-- Precomposing `f` with `prod.snd` is continuous -/ lemma continuous.snd' {f : β → γ} (hf : continuous f) : continuous (λ x : α × β, f x.snd) := hf.comp continuous_snd lemma continuous_at_snd {p : α × β} : continuous_at prod.snd p := continuous_snd.continuous_at /-- Postcomposing `f` with `prod.snd` is continuous at `x` -/ lemma continuous_at.snd {f : α → β × γ} {x : α} (hf : continuous_at f x) : continuous_at (λ a : α, (f a).2) x := continuous_at_snd.comp hf /-- Precomposing `f` with `prod.snd` is continuous at `(x, y)` -/ lemma continuous_at.snd' {f : β → γ} {x : α} {y : β} (hf : continuous_at f y) : continuous_at (λ x : α × β, f x.snd) (x, y) := continuous_at.comp hf continuous_at_snd /-- Precomposing `f` with `prod.snd` is continuous at `x : α × β` -/ lemma continuous_at.snd'' {f : β → γ} {x : α × β} (hf : continuous_at f x.snd) : continuous_at (λ x : α × β, f x.snd) x := hf.comp continuous_at_snd @[continuity] lemma continuous.prod_mk {f : γ → α} {g : γ → β} (hf : continuous f) (hg : continuous g) : continuous (λx, (f x, g x)) := continuous_inf_rng.2 ⟨continuous_induced_rng.2 hf, continuous_induced_rng.2 hg⟩ @[simp] lemma continuous_prod_mk {f : α → β} {g : α → γ} : continuous (λ x, (f x, g x)) ↔ continuous f ∧ continuous g := ⟨λ h, ⟨h.fst, h.snd⟩, λ h, h.1.prod_mk h.2⟩ @[continuity] lemma continuous.prod.mk (a : α) : continuous (λ b : β, (a, b)) := continuous_const.prod_mk continuous_id' @[continuity] lemma continuous.prod.mk_left (b : β) : continuous (λ a : α, (a, b)) := continuous_id'.prod_mk continuous_const lemma continuous.comp₂ {g : α × β → γ} (hg : continuous g) {e : δ → α} (he : continuous e) {f : δ → β} (hf : continuous f) : continuous (λ x, g (e x, f x)) := hg.comp $ he.prod_mk hf lemma continuous.comp₃ {g : α × β × γ → ε} (hg : continuous g) {e : δ → α} (he : continuous e) {f : δ → β} (hf : continuous f) {k : δ → γ} (hk : continuous k) : continuous (λ x, g (e x, f x, k x)) := hg.comp₂ he $ hf.prod_mk hk lemma continuous.comp₄ {g : α × β × γ × ζ → ε} (hg : continuous g) {e : δ → α} (he : continuous e) {f : δ → β} (hf : continuous f) {k : δ → γ} (hk : continuous k) {l : δ → ζ} (hl : continuous l) : continuous (λ x, g (e x, f x, k x, l x)) := hg.comp₃ he hf $ hk.prod_mk hl lemma continuous.prod_map {f : γ → α} {g : δ → β} (hf : continuous f) (hg : continuous g) : continuous (λ x : γ × δ, (f x.1, g x.2)) := hf.fst'.prod_mk hg.snd' /-- A version of `continuous_inf_dom_left` for binary functions -/ lemma continuous_inf_dom_left₂ {α β γ} {f : α → β → γ} {ta1 ta2 : topological_space α} {tb1 tb2 : topological_space β} {tc1 : topological_space γ} (h : by haveI := ta1; haveI := tb1; exact continuous (λ p : α × β, f p.1 p.2)) : by haveI := ta1 ⊓ ta2; haveI := tb1 ⊓ tb2; exact continuous (λ p : α × β, f p.1 p.2) := begin have ha := @continuous_inf_dom_left _ _ id ta1 ta2 ta1 (@continuous_id _ (id _)), have hb := @continuous_inf_dom_left _ _ id tb1 tb2 tb1 (@continuous_id _ (id _)), have h_continuous_id := @continuous.prod_map _ _ _ _ ta1 tb1 (ta1 ⊓ ta2) (tb1 ⊓ tb2) _ _ ha hb, exact @continuous.comp _ _ _ (id _) (id _) _ _ _ h h_continuous_id, end /-- A version of `continuous_inf_dom_right` for binary functions -/ lemma continuous_inf_dom_right₂ {α β γ} {f : α → β → γ} {ta1 ta2 : topological_space α} {tb1 tb2 : topological_space β} {tc1 : topological_space γ} (h : by haveI := ta2; haveI := tb2; exact continuous (λ p : α × β, f p.1 p.2)) : by haveI := ta1 ⊓ ta2; haveI := tb1 ⊓ tb2; exact continuous (λ p : α × β, f p.1 p.2) := begin have ha := @continuous_inf_dom_right _ _ id ta1 ta2 ta2 (@continuous_id _ (id _)), have hb := @continuous_inf_dom_right _ _ id tb1 tb2 tb2 (@continuous_id _ (id _)), have h_continuous_id := @continuous.prod_map _ _ _ _ ta2 tb2 (ta1 ⊓ ta2) (tb1 ⊓ tb2) _ _ ha hb, exact @continuous.comp _ _ _ (id _) (id _) _ _ _ h h_continuous_id, end /-- A version of `continuous_Inf_dom` for binary functions -/ lemma continuous_Inf_dom₂ {α β γ} {f : α → β → γ} {tas : set (topological_space α)} {tbs : set (topological_space β)} {ta : topological_space α} {tb : topological_space β} {tc : topological_space γ} (ha : ta ∈ tas) (hb : tb ∈ tbs) (hf : continuous (λ p : α × β, f p.1 p.2)): by haveI := Inf tas; haveI := Inf tbs; exact @continuous _ _ _ tc (λ p : α × β, f p.1 p.2) := begin let t : topological_space (α × β) := prod.topological_space, have ha := continuous_Inf_dom ha continuous_id, have hb := continuous_Inf_dom hb continuous_id, have h_continuous_id := @continuous.prod_map _ _ _ _ ta tb (Inf tas) (Inf tbs) _ _ ha hb, exact @continuous.comp _ _ _ (id _) (id _) _ _ _ hf h_continuous_id, end 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_snd.prod_mk continuous_fst lemma continuous_uncurry_left {f : α → β → γ} (a : α) (h : continuous (uncurry f)) : continuous (f a) := show continuous (uncurry f ∘ (λ b, (a, b))), from h.comp (by continuity) lemma continuous_uncurry_right {f : α → β → γ} (b : β) (h : continuous (uncurry f)) : continuous (λ a, f a b) := show continuous (uncurry f ∘ (λ a, (a, b))), from h.comp (by continuity) lemma continuous_curry {g : α × β → γ} (a : α) (h : continuous g) : continuous (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 (s ×ˢ t) := (hs.preimage continuous_fst).inter (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] /-- If a function `f x y` is such that `y ↦ f x y` is continuous for all `x`, and `x` lives in a discrete space, then `f` is continuous. -/ lemma continuous_uncurry_of_discrete_topology [discrete_topology α] {f : α → β → γ} (hf : ∀ a, continuous (f a)) : continuous (uncurry f) := begin apply continuous_iff_continuous_at.2, rintros ⟨a, x⟩, change map _ _ ≤ _, rw [nhds_prod_eq, nhds_discrete, filter.map_pure_prod], exact (hf a).continuous_at end lemma mem_nhds_prod_iff {a : α} {b : β} {s : set (α × β)} : s ∈ 𝓝 (a, b) ↔ ∃ (u ∈ 𝓝 a) (v ∈ 𝓝 b), u ×ˢ v ⊆ s := by rw [nhds_prod_eq, mem_prod_iff] lemma mem_nhds_prod_iff' {a : α} {b : β} {s : set (α × β)} : s ∈ 𝓝 (a, b) ↔ ∃ (u : set α) (v : set β), is_open u ∧ a ∈ u ∧ is_open v ∧ b ∈ v ∧ u ×ˢ v ⊆ s := begin rw mem_nhds_prod_iff, split, { rintros ⟨u, Hu, v, Hv, h⟩, rcases mem_nhds_iff.1 Hu with ⟨u', u'u, u'_open, Hu'⟩, rcases mem_nhds_iff.1 Hv with ⟨v', v'v, v'_open, Hv'⟩, exact ⟨u', v', u'_open, Hu', v'_open, Hv', (set.prod_mono u'u v'v).trans h⟩ }, { rintros ⟨u, v, u_open, au, v_open, bv, huv⟩, exact ⟨u, u_open.mem_nhds au, v, v_open.mem_nhds bv, huv⟩ } end lemma _root_.prod.tendsto_iff {α} (seq : α → β × γ) {f : filter α} (x : β × γ) : tendsto seq f (𝓝 x) ↔ tendsto (λ n, (seq n).fst) f (𝓝 x.fst) ∧ tendsto (λ n, (seq n).snd) f (𝓝 x.snd) := by { cases x, rw [nhds_prod_eq, filter.tendsto_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 ×ˢ 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 ×ˢ 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 ×ˢ t ∈ 𝓝 (a, b) ↔ s ∈ 𝓝 a ∧ t ∈ 𝓝 b := by rw [nhds_prod_eq, prod_mem_prod_iff] lemma prod_mem_nhds {s : set α} {t : set β} {a : α} {b : β} (ha : s ∈ 𝓝 a) (hb : t ∈ 𝓝 b) : s ×ˢ t ∈ 𝓝 (a, b) := prod_mem_nhds_iff.2 ⟨ha, hb⟩ lemma filter.eventually.prod_nhds {p : α → Prop} {q : β → Prop} {a : α} {b : β} (ha : ∀ᶠ x in 𝓝 a, p x) (hb : ∀ᶠ y in 𝓝 b, q y) : ∀ᶠ z : α × β in 𝓝 (a, b), p z.1 ∧ q z.2 := prod_mem_nhds 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.fst''.prod hg.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) := hf.fst'.prod hg.snd' 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 = u ×ˢ v} := let G := generate_from {g | ∃ u ∈ s, ∃ v ∈ t, g = u ×ˢ v} in le_antisymm (le_generate_from $ λ 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 $ λ u hu, have (⋃ v ∈ t, u ×ˢ v) = prod.fst ⁻¹' u, by simp_rw [← prod_Union, ← sUnion_eq_bUnion, ht, prod_univ], show G.is_open (prod.fst ⁻¹' u), by { rw [← this], exactI is_open_Union (λ v, is_open_Union $ λ hv, generate_open.basic _ ⟨_, hu, _, hv, rfl⟩) }) (coinduced_le_iff_le_induced.mp $ le_generate_from $ λ v hv, have (⋃ u ∈ s, u ×ˢ v) = prod.snd ⁻¹' v, by simp_rw [← Union_prod_const, ← sUnion_eq_bUnion, hs, univ_prod], show G.is_open (prod.snd ⁻¹' v), by { rw [← this], exactI is_open_Union (λ u, is_open_Union $ λ 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 = s ×ˢ t} := le_antisymm (le_generate_from $ λ 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 : set α) (v : set β), is_open u ∧ is_open v ∧ a ∈ u ∧ b ∈ v ∧ 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 /-- A product of induced topologies is induced by the product map -/ lemma prod_induced_induced {α γ : Type*} (f : α → β) (g : γ → δ) : @prod.topological_space α γ (induced f ‹_›) (induced g ‹_›) = induced (λ p, (f p.1, g p.2)) prod.topological_space := by simp_rw [prod.topological_space, induced_inf, induced_compose] lemma continuous_uncurry_of_discrete_topology_left [discrete_topology α] {f : α → β → γ} (h : ∀ a, continuous (f a)) : continuous (uncurry f) := continuous_iff_continuous_at.2 $ λ ⟨a, b⟩, by simp only [continuous_at, nhds_prod_eq, nhds_discrete α, pure_prod, tendsto_map'_iff, (∘), 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 : set α, is_open U ∧ x ∈ U ∧ 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_of_superset hu (λ z hz, H _ hz _ (mem_of_mem_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_of_superset hv (λ z hz, H _ (mem_of_mem_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 (s ×ˢ t) ↔ (is_open s ∧ is_open t) ∨ (s = ∅) ∨ (t = ∅) := begin cases (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 (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 (s ×ˢ t) = closure s ×ˢ closure t := set.ext $ assume ⟨a, b⟩, have (𝓝 a ×ᶠ 𝓝 b) ⊓ 𝓟 (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 ×ˢ t) = interior s ×ˢ 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 ×ˢ t) = closure s ×ˢ frontier t ∪ frontier s ×ˢ 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 ×ˢ (univ : set β)) = frontier s ×ˢ univ := by simp [frontier_prod_eq] @[simp] lemma frontier_univ_prod_eq (s : set β) : frontier ((univ : set α) ×ˢ s) = univ ×ˢ frontier s := by simp [frontier_prod_eq] lemma map_mem_closure₂ {f : α → β → γ} {a : α} {b : β} {s : set α} {t : set β} {u : set γ} (hf : continuous (uncurry f)) (ha : a ∈ closure s) (hb : b ∈ closure t) (h : ∀ (a ∈ s) (b ∈ t), f a b ∈ u) : f a b ∈ closure u := have H₁ : (a, b) ∈ closure (s ×ˢ t), by simpa only [closure_prod_eq] using mk_mem_prod ha hb, have H₂ : maps_to (uncurry f) (s ×ˢ t) u, from forall_prod_set.2 h, H₂.closure hf H₁ lemma is_closed.prod {s₁ : set α} {s₂ : set β} (h₁ : is_closed s₁) (h₂ : is_closed s₂) : is_closed (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 ×ˢ 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 γ] [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 lemma is_open_sum_iff {s : set (α ⊕ β)} : is_open s ↔ is_open (inl ⁻¹' s) ∧ is_open (inr ⁻¹' s) := iff.rfl lemma is_open_map_inl : is_open_map (@inl α β) := λ u hu, by simpa [is_open_sum_iff, preimage_image_eq u sum.inl_injective] lemma is_open_map_inr : is_open_map (@inr α β) := λ u hu, by simpa [is_open_sum_iff, preimage_image_eq u sum.inr_injective] lemma open_embedding_inl : open_embedding (@inl α β) := open_embedding_of_continuous_injective_open continuous_inl inl_injective is_open_map_inl lemma open_embedding_inr : open_embedding (@inr α β) := open_embedding_of_continuous_injective_open continuous_inr inr_injective is_open_map_inr lemma embedding_inl : embedding (@inl α β) := open_embedding_inl.1 lemma embedding_inr : embedding (@inr α β) := open_embedding_inr.1 lemma is_open_range_inl : is_open (range (inl : α → α ⊕ β)) := open_embedding_inl.2 lemma is_open_range_inr : is_open (range (inr : β → α ⊕ β)) := open_embedding_inr.2 lemma is_closed_range_inl : is_closed (range (inl : α → α ⊕ β)) := by { rw [← is_open_compl_iff, compl_range_inl], exact is_open_range_inr } lemma is_closed_range_inr : is_closed (range (inr : β → α ⊕ β)) := by { rw [← is_open_compl_iff, compl_range_inr], exact is_open_range_inl } lemma closed_embedding_inl : closed_embedding (inl : α → α ⊕ β) := ⟨embedding_inl, is_closed_range_inl⟩ lemma closed_embedding_inr : closed_embedding (inr : β → α ⊕ β) := ⟨embedding_inr, is_closed_range_inr⟩ lemma nhds_inl (x : α) : 𝓝 (inl x : α ⊕ β) = map inl (𝓝 x) := (open_embedding_inl.map_nhds_eq _).symm lemma nhds_inr (x : β) : 𝓝 (inr x : α ⊕ β) = map inr (𝓝 x) := (open_embedding_inr.map_nhds_eq _).symm lemma continuous_sum_elim {f : α → γ} {g : β → γ} : continuous (sum.elim f g) ↔ continuous f ∧ continuous g := by simp only [continuous_sup_dom, continuous_coinduced_dom, sum.elim_comp_inl, sum.elim_comp_inr] @[continuity] lemma continuous.sum_elim {f : α → γ} {g : β → γ} (hf : continuous f) (hg : continuous g) : continuous (sum.elim f g) := continuous_sum_elim.2 ⟨hf, hg⟩ @[simp] lemma continuous_sum_map {f : α → β} {g : γ → δ} : continuous (sum.map f g) ↔ continuous f ∧ continuous g := continuous_sum_elim.trans $ embedding_inl.continuous_iff.symm.and embedding_inr.continuous_iff.symm @[continuity] lemma continuous.sum_map {f : α → β} {g : γ → δ} (hf : continuous f) (hg : continuous g) : continuous (sum.map f g) := continuous_sum_map.2 ⟨hf, hg⟩ lemma is_open_map_sum {f : α ⊕ β → γ} : is_open_map f ↔ is_open_map (λ a, f (inl a)) ∧ is_open_map (λ b, f (inr b)) := by simp only [is_open_map_iff_nhds_le, sum.forall, nhds_inl, nhds_inr, filter.map_map] @[simp] lemma is_open_map_sum_elim {f : α → γ} {g : β → γ} : is_open_map (sum.elim f g) ↔ is_open_map f ∧ is_open_map g := by simp only [is_open_map_sum, elim_inl, elim_inr] lemma is_open_map.sum_elim {f : α → γ} {g : β → γ} (hf : is_open_map f) (hg : is_open_map g) : is_open_map (sum.elim f g) := is_open_map_sum_elim.2 ⟨hf, hg⟩ end sum section subtype variables [topological_space α] [topological_space β] [topological_space γ] {p : α → Prop} lemma inducing_coe {b : set β} : inducing (coe : b → β) := ⟨rfl⟩ lemma inducing.of_cod_restrict {f : α → β} {b : set β} (hb : ∀ a, f a ∈ b) (h : inducing (b.cod_restrict f hb)) : inducing f := inducing_coe.comp h 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 continuous.subtype_coe {f : β → subtype p} (hf : continuous f) : continuous (λ x, (f x : α)) := continuous_subtype_coe.comp hf 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 : β → α} (h : continuous f) (hp : ∀x, p (f x)) : continuous (λx, (⟨f x, hp x⟩ : subtype p)) := continuous_induced_rng.2 h lemma continuous.subtype_map {f : α → β} (h : continuous f) {q : β → Prop} (hpq : ∀ x, p x → q (f x)) : continuous (subtype.map f hpq) := (h.comp continuous_subtype_coe).subtype_mk _ lemma continuous_inclusion {s t : set α} (h : s ⊆ t) : continuous (inclusion h) := continuous_id.subtype_map h 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 subtype.dense_iff {s : set α} {t : set s} : dense t ↔ s ⊆ closure (coe '' t) := by { rw [inducing_coe.dense_iff, set_coe.forall], refl } 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_mem_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 lemma continuous_at_cod_restrict_iff {f : α → β} {t : set β} (h1 : ∀ x, f x ∈ t) {x : α} : continuous_at (cod_restrict f t h1) x ↔ continuous_at f x := by simp_rw [inducing_coe.continuous_at_iff, function.comp, coe_cod_restrict_apply] alias continuous_at_cod_restrict_iff ↔ _ continuous_at.cod_restrict lemma continuous_at.restrict {f : α → β} {s : set α} {t : set β} (h1 : maps_to f s t) {x : s} (h2 : continuous_at f x) : continuous_at (h1.restrict f s t) x := (h2.comp continuous_at_subtype_coe).cod_restrict _ lemma continuous_at.restrict_preimage {f : α → β} {s : set β} {x : f ⁻¹' s} (h : continuous_at f x) : continuous_at (s.restrict_preimage f) x := h.restrict _ @[continuity] lemma continuous.cod_restrict {f : α → β} {s : set β} (hf : continuous f) (hs : ∀ a, f a ∈ s) : continuous (s.cod_restrict f hs) := hf.subtype_mk hs lemma inducing.cod_restrict {e : α → β} (he : inducing e) {s : set β} (hs : ∀ x, e x ∈ s) : inducing (cod_restrict e s hs) := inducing_of_inducing_compose (he.continuous.cod_restrict hs) continuous_subtype_coe he lemma embedding.cod_restrict {e : α → β} (he : embedding e) (s : set β) (hs : ∀ x, e x ∈ s) : embedding (cod_restrict e s hs) := embedding_of_embedding_compose (he.continuous.cod_restrict hs) continuous_subtype_coe he 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.2 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 : α → β} (h : continuous f) (hs : ∀ a b, a ≈ b → f a = f b) : continuous (quotient.lift f hs : quotient s → β) := continuous_coinduced_dom.2 h lemma continuous.quotient_lift_on' {f : α → β} (h : continuous f) (hs : ∀ a b, @setoid.r _ s a b → f a = f b) : continuous (λ x, quotient.lift_on' x f hs : quotient s → β) := h.quotient_lift hs lemma continuous.quotient_map' {t : setoid β} {f : α → β} (hf : continuous f) (H : (s.r ⇒ t.r) f f) : continuous (quotient.map' f H) := (continuous_quotient_mk.comp hf).quotient_lift _ 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.2 $ assume i, continuous_induced_rng.2 $ h i @[continuity] lemma continuous_apply [∀i, topological_space (π i)] (i : ι) : continuous (λp:Πi, π i, p i) := continuous_infi_dom continuous_induced_dom @[continuity] lemma continuous_apply_apply {κ : Type*} {ρ : κ → ι → Type*} [∀ j i, topological_space (ρ j i)] (j : κ) (i : ι) : continuous (λ p : (Π j, Π i, ρ j i), p j i) := (continuous_apply i).comp (continuous_apply j) lemma continuous_at_apply [∀i, topological_space (π i)] (i : ι) (x : Π i, π i) : continuous_at (λ p : Π i, π i, p i) x := (continuous_apply i).continuous_at lemma filter.tendsto.apply [∀i, topological_space (π i)] {l : filter α} {f : α → Π i, π i} {x : Π i, π i} (h : tendsto f l (𝓝 x)) (i : ι) : tendsto (λ a, f a i) l (𝓝 $ x i) := (continuous_at_apply i _).tendsto.comp h lemma continuous_pi_iff [topological_space α] [∀ i, topological_space (π i)] {f : α → Π i, π i} : continuous f ↔ ∀ i, continuous (λ y, f y i) := iff.intro (λ h i, (continuous_apply i).comp h) continuous_pi lemma nhds_pi [t : ∀i, topological_space (π i)] {a : Πi, π i} : 𝓝 a = pi (λ 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_nhds [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 rw [nhds_pi, filter.tendsto_pi] 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_nhds lemma filter.tendsto.update [∀i, topological_space (π i)] [decidable_eq ι] {l : filter α} {f : α → Π i, π i} {x : Π i, π i} (hf : tendsto f l (𝓝 x)) (i : ι) {g : α → π i} {xi : π i} (hg : tendsto g l (𝓝 xi)) : tendsto (λ a, update (f a) i (g a)) l (𝓝 $ update x i xi) := tendsto_pi_nhds.2 $ λ j, by { rcases em (j = i) with rfl|hj; simp [*, hf.apply] } lemma continuous_at.update [∀i, topological_space (π i)] [topological_space α] [decidable_eq ι] {f : α → Π i, π i} {a : α} (hf : continuous_at f a) (i : ι) {g : α → π i} (hg : continuous_at g a) : continuous_at (λ a, update (f a) i (g a)) a := hf.update i hg lemma continuous.update [∀i, topological_space (π i)] [topological_space α] [decidable_eq ι] {f : α → Π i, π i} (hf : continuous f) (i : ι) {g : α → π i} (hg : continuous g) : continuous (λ a, update (f a) i (g a)) := continuous_iff_continuous_at.2 $ λ x, hf.continuous_at.update i hg.continuous_at /-- `function.update f i x` is continuous in `(f, x)`. -/ @[continuity] lemma continuous_update [∀i, topological_space (π i)] [decidable_eq ι] (i : ι) : continuous (λ f : (Π j, π j) × π i, update f.1 i f.2) := continuous_fst.update i continuous_snd lemma filter.tendsto.fin_insert_nth {n} {π : fin (n + 1) → Type*} [Π i, topological_space (π i)] (i : fin (n + 1)) {f : α → π i} {l : filter α} {x : π i} (hf : tendsto f l (𝓝 x)) {g : α → Π j : fin n, π (i.succ_above j)} {y : Π j, π (i.succ_above j)} (hg : tendsto g l (𝓝 y)) : tendsto (λ a, i.insert_nth (f a) (g a)) l (𝓝 $ i.insert_nth x y) := tendsto_pi_nhds.2 (λ j, fin.succ_above_cases i (by simpa) (by simpa using tendsto_pi_nhds.1 hg) j) lemma continuous_at.fin_insert_nth {n} {π : fin (n + 1) → Type*} [Π i, topological_space (π i)] [topological_space α] (i : fin (n + 1)) {f : α → π i} {a : α} (hf : continuous_at f a) {g : α → Π j : fin n, π (i.succ_above j)} (hg : continuous_at g a) : continuous_at (λ a, i.insert_nth (f a) (g a)) a := hf.fin_insert_nth i hg lemma continuous.fin_insert_nth {n} {π : fin (n + 1) → Type*} [Π i, topological_space (π i)] [topological_space α] (i : fin (n + 1)) {f : α → π i} (hf : continuous f) {g : α → Π j : fin n, π (i.succ_above j)} (hg : continuous g) : continuous (λ a, i.insert_nth (f a) (g a)) := continuous_iff_continuous_at.2 $ λ a, hf.continuous_at.fin_insert_nth i hg.continuous_at lemma is_open_set_pi [∀a, topological_space (π a)] {i : set ι} {s : Πa, set (π a)} (hi : i.finite) (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 mem_nhds_of_pi_mem_nhds {ι : Type*} {α : ι → Type*} [Π (i : ι), topological_space (α i)] {I : set ι} {s : Π i, set (α i)} (a : Π i, α i) (hs : I.pi s ∈ 𝓝 a) {i : ι} (hi : i ∈ I) : s i ∈ 𝓝 (a i) := by { rw nhds_pi at hs, exact mem_of_pi_mem_pi hs hi } lemma set_pi_mem_nhds [Π a, topological_space (π a)] {i : set ι} {s : Π a, set (π a)} {x : Π a, π a} (hi : i.finite) (hs : ∀ a ∈ i, s a ∈ 𝓝 (x a)) : pi i s ∈ 𝓝 x := by { rw [pi_def, bInter_mem hi], exact λ a ha, (continuous_apply a).continuous_at (hs a ha) } lemma set_pi_mem_nhds_iff {α : ι → Type*} [Π (i : ι), topological_space (α i)] {I : set ι} (hI : I.finite) {s : Π i, set (α i)} (a : Π i, α i) : I.pi s ∈ 𝓝 a ↔ ∀ (i : ι), i ∈ I → s i ∈ 𝓝 (a i) := by { rw [nhds_pi, pi_mem_pi_iff hI], apply_instance } lemma interior_pi_set {α : ι → Type*} [Π i, topological_space (α i)] {I : set ι} (hI : I.finite) {s : Π i, set (α i)} : interior (pi I s) = I.pi (λ i, interior (s i)) := by { ext a, simp only [set.mem_pi, mem_interior_iff_mem_nhds, set_pi_mem_nhds_iff hI] } lemma exists_finset_piecewise_mem_of_mem_nhds [decidable_eq ι] [Π i, topological_space (π i)] {s : set (Π a, π a)} {x : Π a, π a} (hs : s ∈ 𝓝 x) (y : Π a, π a) : ∃ I : finset ι, I.piecewise x y ∈ s := begin simp only [nhds_pi, filter.mem_pi'] at hs, rcases hs with ⟨I, t, htx, hts⟩, refine ⟨I, hts $ λ i hi, _⟩, simpa [finset.mem_coe.1 hi] using mem_of_mem_nhds (htx i) end 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 _ $ ⟨update (λa, univ) a t, {a}, by simpa using ht, s_eq ▸ by ext f; simp [set.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 _ ⟨update (λa, univ) a s, {a}, by simp [hs]⟩ } end lemma pi_generate_from_eq_finite {g : Πa, set (set (π a))} [finite ι] (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 casesI nonempty_fintype ι, 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 [*, set.pi] at * }, { have : f ∈ pi {a | a ∉ i} c, { simp [*, set.pi] at * }, simpa [pi_if, hf] } } end /-- Suppose `π i` is a family of topological spaces indexed by `i : ι`, and `X` is a type endowed with a family of maps `f i : X → π i` for every `i : ι`, hence inducing a map `g : X → Π i, π i`. This lemma shows that infimum of the topologies on `X` induced by the `f i` as `i : ι` varies is simply the topology on `X` induced by `g : X → Π i, π i` where `Π i, π i` is endowed with the usual product topology. -/ lemma inducing_infi_to_pi {X : Type*} [∀ i, topological_space (π i)] (f : Π i, X → π i) : @inducing X (Π i, π i) (⨅ i, induced (f i) infer_instance) _ (λ x i, f i x) := begin constructor, erw induced_infi, congr' 1, funext, erw induced_compose, end variables [finite ι] [∀ 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 [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 only [← is_open_compl_iff, is_open_sigma_iff, preimage_compl] lemma is_open_map_sigma_mk {i : ι} : is_open_map (@sigma.mk ι σ i) := begin intros s hs, rw is_open_sigma_iff, intro j, rcases eq_or_ne i j with (rfl|hne), { rwa 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)) := is_open_map_sigma_mk.is_open_range lemma is_closed_map_sigma_mk {i : ι} : is_closed_map (@sigma.mk ι σ i) := begin intros s hs, rw is_closed_sigma_iff, intro j, rcases eq_or_ne i j with (rfl|hne), { rwa 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 lemma is_open_sigma_fst_preimage (s : set ι) : is_open (sigma.fst ⁻¹' s : set (Σ a, σ a)) := begin rw [← bUnion_of_singleton s, preimage_Union₂], simp only [← range_sigma_mk], exact is_open_bUnion (λ _ _, is_open_range_sigma_mk) end /-- 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.2 (λ i, continuous_coinduced_dom.2 (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, rw [← Union_image_preimage_sigma_mk_eq_self s, 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.2 continuous_id end ulift
e09546183d5fd3af377bbc6f31659bca16eb3194
4fa161becb8ce7378a709f5992a594764699e268
/src/analysis/normed_space/multilinear.lean
61bcb5b13fbce17a5459b841292ea4a0b18c22a9
[ "Apache-2.0" ]
permissive
laughinggas/mathlib
e4aa4565ae34e46e834434284cb26bd9d67bc373
86dcd5cda7a5017c8b3c8876c89a510a19d49aad
refs/heads/master
1,669,496,232,688
1,592,831,995,000
1,592,831,995,000
274,155,979
0
0
Apache-2.0
1,592,835,190,000
1,592,835,189,000
null
UTF-8
Lean
false
false
54,549
lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import analysis.normed_space.operator_norm import topology.algebra.multilinear /-! # Operator norm on the space of continuous multilinear maps When `f` is a continuous multilinear map in finitely many variables, we define its norm `∥f∥` as the smallest number such that `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥` for all `m`. We show that it is indeed a norm, and prove its basic properties. ## Main results Let `f` be a multilinear map in finitely many variables. * `exists_bound_of_continuous` asserts that, if `f` is continuous, then there exists `C > 0` with `∥f m∥ ≤ C * ∏ i, ∥m i∥` for all `m`. * `continuous_of_bound`, conversely, asserts that this bound implies continuity. * `mk_continuous` constructs the associated continuous multilinear map. Let `f` be a continuous multilinear map in finitely many variables. * `∥f∥` is its norm, i.e., the smallest number such that `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥` for all `m`. * `le_op_norm f m` asserts the fundamental inequality `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥`. * `norm_image_sub_le_of_bound f m₁ m₂` gives a control of the difference `f m₁ - f m₂` in terms of `∥f∥` and `∥m₁ - m₂∥`. We also register isomorphisms corresponding to currying or uncurrying variables, transforming a continuous multilinear function `f` in `n+1` variables into a continuous linear function taking values in continuous multilinear functions in `n` variables, and also into a continuous multilinear function in `n` variables taking values in continuous linear functions. These operations are called `f.curry_left` and `f.curry_right` respectively (with inverses `f.uncurry_left` and `f.uncurry_right`). They induce continuous linear equivalences between spaces of continuous multilinear functions in `n+1` variables and spaces of continuous linear functions into continuous multilinear functions in `n` variables (resp. continuous multilinear functions in `n` variables taking values in continuous linear functions), called respectively `continuous_multilinear_curry_left_equiv` and `continuous_multilinear_curry_right_equiv`. ## Implementation notes We mostly follow the API (and the proofs) of `operator_norm.lean`, with the additional complexity that we should deal with multilinear maps in several variables. The currying/uncurrying constructions are based on those in `multilinear.lean`. From the mathematical point of view, all the results follow from the results on operator norm in one variable, by applying them to one variable after the other through currying. However, this is only well defined when there is an order on the variables (for instance on `fin n`) although the final result is independent of the order. While everything could be done following this approach, it turns out that direct proofs are easier and more efficient. -/ noncomputable theory open_locale classical big_operators open finset local attribute [instance, priority 1001] add_comm_group.to_add_comm_monoid normed_group.to_add_comm_group normed_space.to_semimodule universes u v w w₁ w₂ wG variables {𝕜 : Type u} {ι : Type v} {n : ℕ} {G : Type wG} {E : fin n.succ → Type w} {E₁ : ι → Type w₁} {E₂ : Type w₂} [decidable_eq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [normed_group G] [∀i, normed_group (E i)] [∀i, normed_group (E₁ i)] [normed_group E₂] [normed_space 𝕜 G] [∀i, normed_space 𝕜 (E i)] [∀i, normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] /-! ### Continuity properties of multilinear maps We relate continuity of multilinear maps to the inequality `∥f m∥ ≤ C * ∏ i, ∥m i∥`, in both directions. Along the way, we prove useful bounds on the difference `∥f m₁ - f m₂∥`. -/ namespace multilinear_map variable (f : multilinear_map 𝕜 E₁ E₂) /-- If a multilinear map in finitely many variables on normed spaces is continuous, then it satisfies the inequality `∥f m∥ ≤ C * ∏ i, ∥m i∥`, for some `C` which can be chosen to be positive. -/ theorem exists_bound_of_continuous (hf : continuous f) : ∃ (C : ℝ), 0 < C ∧ (∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) := begin /- The proof only uses the continuity at `0`. Then, given a general point `m`, rescale each of its coordinates to bring them to a shell of fixed width around `0`, on which one knows that `f` is bounded, and then use the multiplicativity of `f` along each coordinate to deduce the desired bound.-/ obtain ⟨ε, ε_pos, hε⟩ : ∃ ε > 0, ∀{m}, dist m 0 < ε → dist (f m) (f 0) < 1 := metric.tendsto_nhds_nhds.1 hf.continuous_at 1 zero_lt_one, let δ := ε/2, have δ_pos : δ > 0 := half_pos ε_pos, /- On points of size at most `δ`, `f` is bounded (by `1 + ∥f 0∥`). -/ have H : ∀{a}, ∥a∥ ≤ δ → ∥f a∥ ≤ 1 + ∥f 0∥, { assume a ha, have : dist (f a) (f 0) ≤ 1, { apply le_of_lt (hε _), rw [dist_eq_norm, sub_zero], exact lt_of_le_of_lt ha (half_lt_self ε_pos) }, calc ∥f a∥ = dist (f a) 0 : (dist_zero_right _).symm ... ≤ dist (f a) (f 0) + dist (f 0) 0 : dist_triangle _ _ _ ... ≤ 1 + ∥f 0∥ : by { rw dist_zero_right, exact add_le_add_right this _ } }, obtain ⟨c, hc⟩ : ∃c : 𝕜, 1 < ∥c∥ := normed_field.exists_one_lt_norm 𝕜, set C := (1 + ∥f 0∥) * ∏ i : ι, (δ⁻¹ * ∥c∥), have C_pos : 0 < C := mul_pos (lt_of_lt_of_le zero_lt_one (by simp)) (prod_pos (λi hi, mul_pos (inv_pos.2 δ_pos) (lt_of_le_of_lt zero_le_one hc))), refine ⟨C, C_pos, λm, _⟩, /- Given a general point `m`, rescale each coordinate to bring it to `[δ/∥c∥, δ]` by multiplication by a power of a scalar `c` with norm `∥c∥ > 1`.-/ by_cases h : ∃i, m i = 0, { rcases h with ⟨i, hi⟩, rw [f.map_coord_zero i hi, _root_.norm_zero], exact mul_nonneg (le_of_lt C_pos) (prod_nonneg (λi hi, norm_nonneg _)) }, { push_neg at h, have : ∀i, ∃d:𝕜, d ≠ 0 ∧ ∥d • m i∥ ≤ δ ∧ (δ/∥c∥ ≤ ∥d • m i∥) ∧ (∥d∥⁻¹ ≤ δ⁻¹ * ∥c∥ * ∥m i∥) := λi, rescale_to_shell hc δ_pos (h i), choose d hd using this, have A : 0 ≤ 1 + ∥f 0∥ := add_nonneg zero_le_one (norm_nonneg _), have B : ∀ (i : ι), i ∈ univ → 0 ≤ ∥d i∥⁻¹ := λi hi, by simp, -- use the bound on `f` on the ball of size `δ` to conclude. calc ∥f m∥ = ∥f (λi, (d i)⁻¹ • (d i • m i))∥ : by { unfold_coes, congr, ext i, rw [← mul_smul, inv_mul_cancel (hd i).1, one_smul] } ... = ∥(∏ i, (d i)⁻¹) • f (λi, d i • m i)∥ : by rw f.map_smul_univ ... = (∏ i, ∥d i∥⁻¹) * ∥f (λi, d i • m i)∥ : by { rw [norm_smul, normed_field.norm_prod], congr, ext i, rw normed_field.norm_inv } ... ≤ (∏ i, ∥d i∥⁻¹) * (1 + ∥f 0∥) : mul_le_mul_of_nonneg_left (H ((pi_norm_le_iff (le_of_lt δ_pos)).2 (λi, (hd i).2.1))) (prod_nonneg B) ... ≤ (∏ i, δ⁻¹ * ∥c∥ * ∥m i∥) * (1 + ∥f 0∥) : mul_le_mul_of_nonneg_right (prod_le_prod B (λi hi, (hd i).2.2.2)) A ... = (∏ i : ι, δ⁻¹ * ∥c∥) * (∏ i, ∥m i∥) * (1 + ∥f 0∥) : by rw prod_mul_distrib ... = C * (∏ i, ∥m i∥) : by rw [mul_comm, ← mul_assoc] } end /-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂` using the multilinearity. Here, we give a precise but hard to use version. See `norm_image_sub_le_of_bound` for a less precise but more usable version. The bound reads `∥f m - f m'∥ ≤ C * ∥m 1 - m' 1∥ * max ∥m 2∥ ∥m' 2∥ * max ∥m 3∥ ∥m' 3∥ * ... * max ∥m n∥ ∥m' n∥ + ...`, where the other terms in the sum are the same products where `1` is replaced by any `i`. -/ lemma norm_image_sub_le_of_bound' {C : ℝ} (hC : 0 ≤ C) (H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) (m₁ m₂ : Πi, E₁ i) : ∥f m₁ - f m₂∥ ≤ C * ∑ i, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ := begin have A : ∀(s : finset ι), ∥f m₁ - f (s.piecewise m₂ m₁)∥ ≤ C * ∑ i in s, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥, { refine finset.induction (by simp) _, assume i s his Hrec, have I : ∥f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)∥ ≤ C * ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥, { have A : ((insert i s).piecewise m₂ m₁) = function.update (s.piecewise m₂ m₁) i (m₂ i) := s.piecewise_insert _ _ _, have B : s.piecewise m₂ m₁ = function.update (s.piecewise m₂ m₁) i (m₁ i), { ext j, by_cases h : j = i, { rw h, simp [his] }, { simp [h] } }, rw [B, A, ← f.map_sub], apply le_trans (H _) (mul_le_mul_of_nonneg_left _ hC), refine prod_le_prod (λj hj, norm_nonneg _) (λj hj, _), by_cases h : j = i, { rw h, simp }, { by_cases h' : j ∈ s; simp [h', h, le_refl] } }, calc ∥f m₁ - f ((insert i s).piecewise m₂ m₁)∥ ≤ ∥f m₁ - f (s.piecewise m₂ m₁)∥ + ∥f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)∥ : by { rw [← dist_eq_norm, ← dist_eq_norm, ← dist_eq_norm], exact dist_triangle _ _ _ } ... ≤ (C * ∑ i in s, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥) + C * ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ : add_le_add Hrec I ... = C * ∑ i in insert i s, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ : by simp [his, add_comm, left_distrib] }, convert A univ, simp end /-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂` using the multilinearity. Here, we give a usable but not very precise version. See `norm_image_sub_le_of_bound'` for a more precise but less usable version. The bound is `∥f m - f m'∥ ≤ C * card ι * ∥m - m'∥ * (max ∥m∥ ∥m'∥) ^ (card ι - 1)`. -/ lemma norm_image_sub_le_of_bound {C : ℝ} (hC : 0 ≤ C) (H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) (m₁ m₂ : Πi, E₁ i) : ∥f m₁ - f m₂∥ ≤ C * (fintype.card ι) * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) * ∥m₁ - m₂∥ := begin have A : ∀ (i : ι), ∏ j, (if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥) ≤ ∥m₁ - m₂∥ * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1), { assume i, calc ∏ j, (if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥) ≤ ∏ j : ι, function.update (λ j, max ∥m₁∥ ∥m₂∥) i (∥m₁ - m₂∥) j : begin apply prod_le_prod, { assume j hj, by_cases h : j = i; simp [h, norm_nonneg] }, { assume j hj, by_cases h : j = i, { rw h, simp, exact norm_le_pi_norm (m₁ - m₂) i }, { simp [h, max_le_max, norm_le_pi_norm] } } end ... = ∥m₁ - m₂∥ * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) : by { rw prod_update_of_mem (finset.mem_univ _), simp [card_univ_diff] } }, calc ∥f m₁ - f m₂∥ ≤ C * ∑ i, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ : f.norm_image_sub_le_of_bound' hC H m₁ m₂ ... ≤ C * ∑ i, ∥m₁ - m₂∥ * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) : mul_le_mul_of_nonneg_left (sum_le_sum (λi hi, A i)) hC ... = C * (fintype.card ι) * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) * ∥m₁ - m₂∥ : by { rw [sum_const, card_univ, nsmul_eq_mul], ring } end /-- If a multilinear map satisfies an inequality `∥f m∥ ≤ C * ∏ i, ∥m i∥`, then it is continuous. -/ theorem continuous_of_bound (C : ℝ) (H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) : continuous f := begin let D := max C 1, have D_pos : 0 ≤ D := le_trans zero_le_one (le_max_right _ _), replace H : ∀ m, ∥f m∥ ≤ D * ∏ i, ∥m i∥, { assume m, apply le_trans (H m) (mul_le_mul_of_nonneg_right (le_max_left _ _) _), exact prod_nonneg (λ(i : ι) hi, norm_nonneg (m i)) }, refine continuous_iff_continuous_at.2 (λm, _), refine continuous_at_of_locally_lipschitz zero_lt_one (D * (fintype.card ι) * (∥m∥ + 1) ^ (fintype.card ι - 1)) (λm' h', _), rw [dist_eq_norm, dist_eq_norm], have : 0 ≤ (max ∥m'∥ ∥m∥), by simp, have : (max ∥m'∥ ∥m∥) ≤ ∥m∥ + 1, by simp [zero_le_one, norm_le_of_mem_closed_ball (le_of_lt h'), -add_comm], calc ∥f m' - f m∥ ≤ D * (fintype.card ι) * (max ∥m'∥ ∥m∥) ^ (fintype.card ι - 1) * ∥m' - m∥ : f.norm_image_sub_le_of_bound D_pos H m' m ... ≤ D * (fintype.card ι) * (∥m∥ + 1) ^ (fintype.card ι - 1) * ∥m' - m∥ : by apply_rules [mul_le_mul_of_nonneg_right, mul_le_mul_of_nonneg_left, mul_nonneg, norm_nonneg, nat.cast_nonneg, pow_le_pow_of_le_left] end /-- Constructing a continuous multilinear map from a multilinear map satisfying a boundedness condition. -/ def mk_continuous (C : ℝ) (H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) : continuous_multilinear_map 𝕜 E₁ E₂ := { cont := f.continuous_of_bound C H, ..f } /-- Given a multilinear map in `n` variables, if one restricts it to `k` variables putting `z` on the other coordinates, then the resulting restricted function satisfies an inequality `∥f.restr v∥ ≤ C * ∥z∥^(n-k) * Π ∥v i∥` if the original function satisfies `∥f v∥ ≤ C * Π ∥v i∥`. -/ lemma restr_norm_le {k n : ℕ} (f : (multilinear_map 𝕜 (λ i : fin n, G) E₂ : _)) (s : finset (fin n)) (hk : s.card = k) (z : G) {C : ℝ} (H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) (v : fin k → G) : ∥f.restr s hk z v∥ ≤ C * ∥z∥ ^ (n - k) * ∏ i, ∥v i∥ := calc ∥f.restr s hk z v∥ ≤ C * ∏ j, ∥(if h : j ∈ s then v ((s.mono_equiv_of_fin hk).symm ⟨j, h⟩) else z)∥ : H _ ... = C * ((∏ j in finset.univ \ s, ∥(if h : j ∈ s then v ((s.mono_equiv_of_fin hk).symm ⟨j, h⟩) else z)∥) * (∏ j in s, ∥(if h : j ∈ s then v ((s.mono_equiv_of_fin hk).symm ⟨j, h⟩) else z)∥)) : by rw ← finset.prod_sdiff (finset.subset_univ _) ... = C * (∥z∥ ^ (n - k) * ∏ i, ∥v i∥) : begin congr' 2, { have : ∥z∥ ^ (n - k) = ∏ j in finset.univ \ s, ∥z∥, by simp [finset.card_sdiff (finset.subset_univ _), hk], rw this, exact finset.prod_congr rfl (λ i hi, by rw dif_neg (finset.mem_sdiff.1 hi).2) }, { apply finset.prod_bij (λ (i : fin n) (hi : i ∈ s), (s.mono_equiv_of_fin hk).symm ⟨i, hi⟩), { exact λ _ _, finset.mem_univ _ }, { exact λ i hi, by simp [hi] }, { exact λ i j hi hi hij, subtype.mk.inj ((s.mono_equiv_of_fin hk).symm.injective hij) }, { assume i hi, rcases (s.mono_equiv_of_fin hk).symm.surjective i with ⟨j, hj⟩, refine ⟨j.1, j.2, _⟩, unfold_coes, convert hj.symm, rw subtype.ext } } end ... = C * ∥z∥ ^ (n - k) * ∏ i, ∥v i∥ : by rw mul_assoc end multilinear_map /-! ### Continuous multilinear maps We define the norm `∥f∥` of a continuous multilinear map `f` in finitely many variables as the smallest number such that `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥` for all `m`. We show that this defines a normed space structure on `continuous_multilinear_map 𝕜 E₁ E₂`. -/ namespace continuous_multilinear_map variables (c : 𝕜) (f g : continuous_multilinear_map 𝕜 E₁ E₂) (m : Πi, E₁ i) theorem bound : ∃ (C : ℝ), 0 < C ∧ (∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) := f.to_multilinear_map.exists_bound_of_continuous f.2 open real /-- The operator norm of a continuous multilinear map is the inf of all its bounds. -/ def op_norm := Inf {c | 0 ≤ (c : ℝ) ∧ ∀ m, ∥f m∥ ≤ c * ∏ i, ∥m i∥} instance has_op_norm : has_norm (continuous_multilinear_map 𝕜 E₁ E₂) := ⟨op_norm⟩ lemma norm_def : ∥f∥ = Inf {c | 0 ≤ (c : ℝ) ∧ ∀ m, ∥f m∥ ≤ c * ∏ i, ∥m i∥} := rfl -- So that invocations of `real.Inf_le` make sense: we show that the set of -- bounds is nonempty and bounded below. lemma bounds_nonempty {f : continuous_multilinear_map 𝕜 E₁ E₂} : ∃ c, c ∈ {c | 0 ≤ c ∧ ∀ m, ∥f m∥ ≤ c * ∏ i, ∥m i∥} := let ⟨M, hMp, hMb⟩ := f.bound in ⟨M, le_of_lt hMp, hMb⟩ lemma bounds_bdd_below {f : continuous_multilinear_map 𝕜 E₁ E₂} : bdd_below {c | 0 ≤ c ∧ ∀ m, ∥f m∥ ≤ c * ∏ i, ∥m i∥} := ⟨0, λ _ ⟨hn, _⟩, hn⟩ lemma op_norm_nonneg : 0 ≤ ∥f∥ := lb_le_Inf _ bounds_nonempty (λ _ ⟨hx, _⟩, hx) /-- The fundamental property of the operator norm of a continuous multilinear map: `∥f m∥` is bounded by `∥f∥` times the product of the `∥m i∥`. -/ theorem le_op_norm : ∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥ := begin have A : 0 ≤ ∏ i, ∥m i∥ := prod_nonneg (λj hj, norm_nonneg _), by_cases h : ∏ i, ∥m i∥ = 0, { rcases prod_eq_zero_iff.1 h with ⟨i, _, hi⟩, rw norm_eq_zero at hi, have : f m = 0 := f.map_coord_zero i hi, rw [this, norm_zero], exact mul_nonneg (op_norm_nonneg f) A }, { have hlt : 0 < ∏ i, ∥m i∥ := lt_of_le_of_ne A (ne.symm h), exact le_mul_of_div_le hlt ((le_Inf _ bounds_nonempty bounds_bdd_below).2 (λ c ⟨_, hc⟩, div_le_of_le_mul hlt (begin rw mul_comm, apply hc, end))) } end lemma ratio_le_op_norm : ∥f m∥ / ∏ i, ∥m i∥ ≤ ∥f∥ := begin have : 0 ≤ ∏ i, ∥m i∥ := prod_nonneg (λj hj, norm_nonneg _), cases eq_or_lt_of_le this with h h, { simp [h.symm, op_norm_nonneg f] }, { rw div_le_iff h, exact le_op_norm f m } end /-- The image of the unit ball under a continuous multilinear map is bounded. -/ lemma unit_le_op_norm (h : ∥m∥ ≤ 1) : ∥f m∥ ≤ ∥f∥ := calc ∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥ : f.le_op_norm m ... ≤ ∥f∥ * ∏ i : ι, 1 : mul_le_mul_of_nonneg_left (prod_le_prod (λi hi, norm_nonneg _) (λi hi, le_trans (norm_le_pi_norm _ _) h)) (op_norm_nonneg f) ... = ∥f∥ : by simp /-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/ lemma op_norm_le_bound {M : ℝ} (hMp: 0 ≤ M) (hM : ∀ m, ∥f m∥ ≤ M * ∏ i, ∥m i∥) : ∥f∥ ≤ M := Inf_le _ bounds_bdd_below ⟨hMp, hM⟩ /-- The operator norm satisfies the triangle inequality. -/ theorem op_norm_add_le : ∥f + g∥ ≤ ∥f∥ + ∥g∥ := Inf_le _ bounds_bdd_below ⟨add_nonneg (op_norm_nonneg _) (op_norm_nonneg _), λ x, by { rw add_mul, exact norm_add_le_of_le (le_op_norm _ _) (le_op_norm _ _) }⟩ /-- A continuous linear map is zero iff its norm vanishes. -/ theorem op_norm_zero_iff : ∥f∥ = 0 ↔ f = 0 := begin split, { assume h, ext m, simpa [h, norm_le_zero_iff.symm] using f.le_op_norm m }, { assume h, apply le_antisymm (op_norm_le_bound f (le_refl _) (λm, _)) (op_norm_nonneg _), rw h, simp } end @[simp] lemma norm_zero : ∥(0 : continuous_multilinear_map 𝕜 E₁ E₂)∥ = 0 := by rw op_norm_zero_iff lemma op_norm_smul_le : ∥c • f∥ ≤ ∥c∥ * ∥f∥ := (Inf_le _ bounds_bdd_below ⟨mul_nonneg (norm_nonneg _) (op_norm_nonneg _), λ _, begin erw [norm_smul, mul_assoc], exact mul_le_mul_of_nonneg_left (le_op_norm _ _) (norm_nonneg _) end⟩) lemma op_norm_neg : ∥-f∥ = ∥f∥ := by { rw norm_def, apply congr_arg, ext, simp } /-- Continuous multilinear maps themselves form a normed space with respect to the operator norm. -/ instance to_normed_group : normed_group (continuous_multilinear_map 𝕜 E₁ E₂) := normed_group.of_core _ ⟨op_norm_zero_iff, op_norm_add_le, op_norm_neg⟩ instance to_normed_space : normed_space 𝕜 (continuous_multilinear_map 𝕜 E₁ E₂) := ⟨op_norm_smul_le⟩ /-- The difference `f m₁ - f m₂` is controlled in terms of `∥f∥` and `∥m₁ - m₂∥`, precise version. For a less precise but more usable version, see `norm_image_sub_le_of_bound`. The bound reads `∥f m - f m'∥ ≤ ∥f∥ * ∥m 1 - m' 1∥ * max ∥m 2∥ ∥m' 2∥ * max ∥m 3∥ ∥m' 3∥ * ... * max ∥m n∥ ∥m' n∥ + ...`, where the other terms in the sum are the same products where `1` is replaced by any `i`.-/ lemma norm_image_sub_le_of_bound' (m₁ m₂ : Πi, E₁ i) : ∥f m₁ - f m₂∥ ≤ ∥f∥ * ∑ i, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ := f.to_multilinear_map.norm_image_sub_le_of_bound' (norm_nonneg _) f.le_op_norm _ _ /-- The difference `f m₁ - f m₂` is controlled in terms of `∥f∥` and `∥m₁ - m₂∥`, less precise version. For a more precise but less usable version, see `norm_image_sub_le_of_bound'`. The bound is `∥f m - f m'∥ ≤ ∥f∥ * card ι * ∥m - m'∥ * (max ∥m∥ ∥m'∥) ^ (card ι - 1)`.-/ lemma norm_image_sub_le_of_bound (m₁ m₂ : Πi, E₁ i) : ∥f m₁ - f m₂∥ ≤ ∥f∥ * (fintype.card ι) * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) * ∥m₁ - m₂∥ := f.to_multilinear_map.norm_image_sub_le_of_bound (norm_nonneg _) f.le_op_norm _ _ /-- Applying a multilinear map to a vector is continuous in both coordinates. -/ lemma continuous_eval : continuous (λ (p : (continuous_multilinear_map 𝕜 E₁ E₂ × (Πi, E₁ i))), p.1 p.2) := begin apply continuous_iff_continuous_at.2 (λp, _), apply continuous_at_of_locally_lipschitz zero_lt_one ((∥p∥ + 1) * (fintype.card ι) * (∥p∥ + 1) ^ (fintype.card ι - 1) + ∏ i, ∥p.2 i∥) (λq hq, _), have : 0 ≤ (max ∥q.2∥ ∥p.2∥), by simp, have : 0 ≤ ∥p∥ + 1, by simp [le_trans zero_le_one], have A : ∥q∥ ≤ ∥p∥ + 1 := norm_le_of_mem_closed_ball (le_of_lt hq), have : (max ∥q.2∥ ∥p.2∥) ≤ ∥p∥ + 1 := le_trans (max_le_max (norm_snd_le q) (norm_snd_le p)) (by simp [A, -add_comm, zero_le_one]), have : ∀ (i : ι), i ∈ univ → 0 ≤ ∥p.2 i∥ := λ i hi, norm_nonneg _, calc dist (q.1 q.2) (p.1 p.2) ≤ dist (q.1 q.2) (q.1 p.2) + dist (q.1 p.2) (p.1 p.2) : dist_triangle _ _ _ ... = ∥q.1 q.2 - q.1 p.2∥ + ∥q.1 p.2 - p.1 p.2∥ : by rw [dist_eq_norm, dist_eq_norm] ... ≤ ∥q.1∥ * (fintype.card ι) * (max ∥q.2∥ ∥p.2∥) ^ (fintype.card ι - 1) * ∥q.2 - p.2∥ + ∥q.1 - p.1∥ * ∏ i, ∥p.2 i∥ : add_le_add (norm_image_sub_le_of_bound _ _ _) ((q.1 - p.1).le_op_norm p.2) ... ≤ (∥p∥ + 1) * (fintype.card ι) * (∥p∥ + 1) ^ (fintype.card ι - 1) * ∥q - p∥ + ∥q - p∥ * ∏ i, ∥p.2 i∥ : by apply_rules [add_le_add, mul_le_mul, le_refl, le_trans (norm_fst_le q) A, nat.cast_nonneg, mul_nonneg, pow_le_pow_of_le_left, pow_nonneg, norm_snd_le (q - p), norm_nonneg, norm_fst_le (q - p), norm_nonneg, prod_nonneg] ... = ((∥p∥ + 1) * (fintype.card ι) * (∥p∥ + 1) ^ (fintype.card ι - 1) + (∏ i, ∥p.2 i∥)) * dist q p : by { rw dist_eq_norm, ring } end lemma continuous_eval_left (m : Π i, E₁ i) : continuous (λ (p : (continuous_multilinear_map 𝕜 E₁ E₂)), (p : (Π i, E₁ i) → E₂) m) := continuous_eval.comp (continuous.prod_mk continuous_id continuous_const) lemma has_sum_eval {α : Type*} {p : α → continuous_multilinear_map 𝕜 E₁ E₂} {q : continuous_multilinear_map 𝕜 E₁ E₂} (h : has_sum p q) (m : Π i, E₁ i) : has_sum (λ a, p a m) (q m) := begin dsimp [has_sum] at h ⊢, convert ((continuous_eval_left m).tendsto _).comp h, ext s, simp end open_locale topological_space open filter /-- If the target space is complete, the space of continuous multilinear maps with its norm is also complete. The proof is essentially the same as for the space of continuous linear maps (modulo the addition of `finset.prod` where needed. The duplication could be avoided by deducing the linear case from the multilinear case via a currying isomorphism. However, this would mess up imports, and it is more satisfactory to have the simplest case as a standalone proof. -/ instance [complete_space E₂] : complete_space (continuous_multilinear_map 𝕜 E₁ E₂) := begin have nonneg : ∀ (v : Π i, E₁ i), 0 ≤ ∏ i, ∥v i∥ := λ v, finset.prod_nonneg (λ i hi, norm_nonneg _), -- We show that every Cauchy sequence converges. refine metric.complete_of_cauchy_seq_tendsto (λ f hf, _), -- We now expand out the definition of a Cauchy sequence, rcases cauchy_seq_iff_le_tendsto_0.1 hf with ⟨b, b0, b_bound, b_lim⟩, -- and establish that the evaluation at any point `v : Π i, E₁ i` is Cauchy. have cau : ∀ v, cauchy_seq (λ n, f n v), { assume v, apply cauchy_seq_iff_le_tendsto_0.2 ⟨λ n, b n * ∏ i, ∥v i∥, λ n, _, _, _⟩, { exact mul_nonneg (b0 n) (nonneg v) }, { assume n m N hn hm, rw dist_eq_norm, apply le_trans ((f n - f m).le_op_norm v) _, exact mul_le_mul_of_nonneg_right (b_bound n m N hn hm) (nonneg v) }, { simpa using b_lim.mul tendsto_const_nhds } }, -- We assemble the limits points of those Cauchy sequences -- (which exist as `E₂` is complete) -- into a function which we call `F`. choose F hF using λv, cauchy_seq_tendsto_of_complete (cau v), -- Next, we show that this `F` is multilinear, let Fmult : multilinear_map 𝕜 E₁ E₂ := { to_fun := F, map_add' := λ v i x y, begin have A := hF (function.update v i (x + y)), have B := (hF (function.update v i x)).add (hF (function.update v i y)), simp at A B, exact tendsto_nhds_unique filter.at_top_ne_bot A B end, map_smul' := λ v i c x, begin have A := hF (function.update v i (c • x)), have B := filter.tendsto.smul (@tendsto_const_nhds _ ℕ _ c _) (hF (function.update v i x)), simp at A B, exact tendsto_nhds_unique filter.at_top_ne_bot A B end }, -- and that `F` has norm at most `(b 0 + ∥f 0∥)`. have Fnorm : ∀ v, ∥F v∥ ≤ (b 0 + ∥f 0∥) * ∏ i, ∥v i∥, { assume v, have A : ∀ n, ∥f n v∥ ≤ (b 0 + ∥f 0∥) * ∏ i, ∥v i∥, { assume n, apply le_trans ((f n).le_op_norm _) _, apply mul_le_mul_of_nonneg_right _ (nonneg v), calc ∥f n∥ = ∥(f n - f 0) + f 0∥ : by { congr' 1, abel } ... ≤ ∥f n - f 0∥ + ∥f 0∥ : norm_add_le _ _ ... ≤ b 0 + ∥f 0∥ : begin apply add_le_add_right, simpa [dist_eq_norm] using b_bound n 0 0 (zero_le _) (zero_le _) end }, exact le_of_tendsto at_top_ne_bot (hF v).norm (eventually_of_forall _ A) }, -- Thus `F` is continuous, and we propose that as the limit point of our original Cauchy sequence. let Fcont := Fmult.mk_continuous _ Fnorm, use Fcont, -- Our last task is to establish convergence to `F` in norm. have : ∀ n, ∥f n - Fcont∥ ≤ b n, { assume n, apply op_norm_le_bound _ (b0 n) (λ v, _), have A : ∀ᶠ m in at_top, ∥(f n - f m) v∥ ≤ b n * ∏ i, ∥v i∥, { refine eventually_at_top.2 ⟨n, λ m hm, _⟩, apply le_trans ((f n - f m).le_op_norm _) _, exact mul_le_mul_of_nonneg_right (b_bound n m n (le_refl _) hm) (nonneg v) }, have B : tendsto (λ m, ∥(f n - f m) v∥) at_top (𝓝 (∥(f n - Fcont) v∥)) := tendsto.norm (tendsto_const_nhds.sub (hF v)), exact le_of_tendsto at_top_ne_bot B A }, erw tendsto_iff_norm_tendsto_zero, exact squeeze_zero (λ n, norm_nonneg _) this b_lim, end end continuous_multilinear_map /-- If a continuous multilinear map is constructed from a multilinear map via the constructor `mk_continuous`, then its norm is bounded by the bound given to the constructor if it is nonnegative. -/ lemma multilinear_map.mk_continuous_norm_le (f : multilinear_map 𝕜 E₁ E₂) {C : ℝ} (hC : 0 ≤ C) (H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) : ∥f.mk_continuous C H∥ ≤ C := continuous_multilinear_map.op_norm_le_bound _ hC (λm, H m) namespace continuous_multilinear_map /-- Given a continuous multilinear map `f` on `n` variables (parameterized by `fin n`) and a subset `s` of `k` of these variables, one gets a new continuous multilinear map on `fin k` by varying these variables, and fixing the other ones equal to a given value `z`. It is denoted by `f.restr s hk z`, where `hk` is a proof that the cardinality of `s` is `k`. The implicit identification between `fin k` and `s` that we use is the canonical (increasing) bijection. -/ def restr {k n : ℕ} (f : (G [×n]→L[𝕜] E₂ : _)) (s : finset (fin n)) (hk : s.card = k) (z : G) : G [×k]→L[𝕜] E₂ := (f.to_multilinear_map.restr s hk z).mk_continuous (∥f∥ * ∥z∥^(n-k)) $ λ v, multilinear_map.restr_norm_le _ _ _ _ f.le_op_norm _ lemma norm_restr {k n : ℕ} (f : G [×n]→L[𝕜] E₂) (s : finset (fin n)) (hk : s.card = k) (z : G) : ∥f.restr s hk z∥ ≤ ∥f∥ * ∥z∥ ^ (n - k) := begin apply multilinear_map.mk_continuous_norm_le, exact mul_nonneg (norm_nonneg _) (pow_nonneg (norm_nonneg _) _) end variables (𝕜 ι) /-- The canonical continuous multilinear map on `𝕜^ι`, associating to `m` the product of all the `m i` (multiplied by a fixed reference element `z` in the target module) -/ protected def mk_pi_field (z : E₂) : continuous_multilinear_map 𝕜 (λ(i : ι), 𝕜) E₂ := @multilinear_map.mk_continuous 𝕜 ι (λ(i : ι), 𝕜) E₂ _ _ _ _ _ _ _ (multilinear_map.mk_pi_ring 𝕜 ι z) (∥z∥) (λ m, by simp only [multilinear_map.mk_pi_ring_apply, norm_smul, normed_field.norm_prod, mul_comm]) variables {𝕜 ι} @[simp] lemma mk_pi_field_apply (z : E₂) (m : ι → 𝕜) : (continuous_multilinear_map.mk_pi_field 𝕜 ι z : (ι → 𝕜) → E₂) m = (∏ i, m i) • z := rfl lemma mk_pi_ring_apply_one_eq_self (f : continuous_multilinear_map 𝕜 (λ(i : ι), 𝕜) E₂) : continuous_multilinear_map.mk_pi_field 𝕜 ι (f (λi, 1)) = f := begin ext m, have : m = (λi, m i • 1), by { ext j, simp }, conv_rhs { rw [this, f.map_smul_univ] }, refl end variables (𝕜 ι E₂) /-- Continuous multilinear maps on `𝕜^n` with values in `E₂` are in bijection with `E₂`, as such a continuous multilinear map is completely determined by its value on the constant vector made of ones. We register this bijection as a linear equivalence in `continuous_multilinear_map.pi_field_equiv_aux`. The continuous linear equivalence is `continuous_multilinear_map.pi_field_equiv`. -/ protected def pi_field_equiv_aux : E₂ ≃ₗ[𝕜] (continuous_multilinear_map 𝕜 (λ(i : ι), 𝕜) E₂) := { to_fun := λ z, continuous_multilinear_map.mk_pi_field 𝕜 ι z, inv_fun := λ f, f (λi, 1), map_add' := λ z z', by { ext m, simp [smul_add] }, map_smul' := λ c z, by { ext m, simp [smul_smul, mul_comm] }, left_inv := λ z, by simp, right_inv := λ f, f.mk_pi_ring_apply_one_eq_self } /-- Continuous multilinear maps on `𝕜^n` with values in `E₂` are in bijection with `E₂`, as such a continuous multilinear map is completely determined by its value on the constant vector made of ones. We register this bijection as a continuous linear equivalence in `continuous_multilinear_map.pi_field_equiv`. -/ protected def pi_field_equiv : E₂ ≃L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : ι), 𝕜) E₂) := { continuous_to_fun := begin refine (continuous_multilinear_map.pi_field_equiv_aux 𝕜 ι E₂).to_linear_map.continuous_of_bound (1 : ℝ) (λz, _), rw one_mul, change ∥continuous_multilinear_map.mk_pi_field 𝕜 ι z∥ ≤ ∥z∥, exact multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _ end, continuous_inv_fun := begin refine (continuous_multilinear_map.pi_field_equiv_aux 𝕜 ι E₂).symm.to_linear_map.continuous_of_bound (1 : ℝ) (λf, _), rw one_mul, change ∥f (λi, 1)∥ ≤ ∥f∥, apply @continuous_multilinear_map.unit_le_op_norm 𝕜 ι (λ (i : ι), 𝕜) E₂ _ _ _ _ _ _ _ f, simp [pi_norm_le_iff zero_le_one, le_refl] end, .. continuous_multilinear_map.pi_field_equiv_aux 𝕜 ι E₂ } end continuous_multilinear_map section currying /-! ### Currying We associate to a continuous multilinear map in `n+1` variables (i.e., based on `fin n.succ`) two curried functions, named `f.curry_left` (which is a continuous linear map on `E 0` taking values in continuous multilinear maps in `n` variables) and `f.curry_right` (which is a continuous multilinear map in `n` variables taking values in continuous linear maps on `E (last n)`). The inverse operations are called `uncurry_left` and `uncurry_right`. We also register continuous linear equiv versions of these correspondences, in `continuous_multilinear_curry_left_equiv` and `continuous_multilinear_curry_right_equiv`. -/ open fin function lemma continuous_linear_map.norm_map_tail_le (f : E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) (m : Πi, E i) : ∥f (m 0) (tail m)∥ ≤ ∥f∥ * ∏ i, ∥m i∥ := calc ∥f (m 0) (tail m)∥ ≤ ∥f (m 0)∥ * ∏ i, ∥(tail m) i∥ : (f (m 0)).le_op_norm _ ... ≤ (∥f∥ * ∥m 0∥) * ∏ i, ∥(tail m) i∥ : mul_le_mul_of_nonneg_right (f.le_op_norm _) (prod_nonneg (λi hi, norm_nonneg _)) ... = ∥f∥ * (∥m 0∥ * ∏ i, ∥(tail m) i∥) : by ring ... = ∥f∥ * ∏ i, ∥m i∥ : by { rw prod_univ_succ, refl } lemma continuous_multilinear_map.norm_map_init_le (f : continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) (m : Πi, E i) : ∥f (init m) (m (last n))∥ ≤ ∥f∥ * ∏ i, ∥m i∥ := calc ∥f (init m) (m (last n))∥ ≤ ∥f (init m)∥ * ∥m (last n)∥ : (f (init m)).le_op_norm _ ... ≤ (∥f∥ * (∏ i, ∥(init m) i∥)) * ∥m (last n)∥ : mul_le_mul_of_nonneg_right (f.le_op_norm _) (norm_nonneg _) ... = ∥f∥ * ((∏ i, ∥(init m) i∥) * ∥m (last n)∥) : mul_assoc _ _ _ ... = ∥f∥ * ∏ i, ∥m i∥ : by { rw prod_univ_cast_succ, refl } lemma continuous_multilinear_map.norm_map_cons_le (f : continuous_multilinear_map 𝕜 E E₂) (x : E 0) (m : Π(i : fin n), E i.succ) : ∥f (cons x m)∥ ≤ ∥f∥ * ∥x∥ * ∏ i, ∥m i∥ := calc ∥f (cons x m)∥ ≤ ∥f∥ * ∏ i, ∥cons x m i∥ : f.le_op_norm _ ... = (∥f∥ * ∥x∥) * ∏ i, ∥m i∥ : by { rw prod_univ_succ, simp [mul_assoc] } lemma continuous_multilinear_map.norm_map_snoc_le (f : continuous_multilinear_map 𝕜 E E₂) (m : Π(i : fin n), E i.cast_succ) (x : E (last n)) : ∥f (snoc m x)∥ ≤ ∥f∥ * (∏ i, ∥m i∥) * ∥x∥ := calc ∥f (snoc m x)∥ ≤ ∥f∥ * ∏ i, ∥snoc m x i∥ : f.le_op_norm _ ... = ∥f∥ * (∏ i, ∥m i∥) * ∥x∥ : by { rw prod_univ_cast_succ, simp [mul_assoc] } /-! #### Left currying -/ /-- Given a continuous linear map `f` from `E 0` to continuous multilinear maps on `n` variables, construct the corresponding continuous multilinear map on `n+1` variables obtained by concatenating the variables, given by `m ↦ f (m 0) (tail m)`-/ def continuous_linear_map.uncurry_left (f : E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) : continuous_multilinear_map 𝕜 E E₂ := (@linear_map.uncurry_left 𝕜 n E E₂ _ _ _ _ _ (continuous_multilinear_map.to_multilinear_map_linear.comp f.to_linear_map)).mk_continuous (∥f∥) (λm, continuous_linear_map.norm_map_tail_le f m) @[simp] lemma continuous_linear_map.uncurry_left_apply (f : E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) (m : Πi, E i) : f.uncurry_left m = f (m 0) (tail m) := rfl /-- Given a continuous multilinear map `f` in `n+1` variables, split the first variable to obtain a continuous linear map into continuous multilinear maps in `n` variables, given by `x ↦ (m ↦ f (cons x m))`. -/ def continuous_multilinear_map.curry_left (f : continuous_multilinear_map 𝕜 E E₂) : E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂) := linear_map.mk_continuous { -- define a linear map into `n` continuous multilinear maps from an `n+1` continuous multilinear -- map to_fun := λx, (f.to_multilinear_map.curry_left x).mk_continuous (∥f∥ * ∥x∥) (f.norm_map_cons_le x), map_add' := λx y, by { ext m, exact f.cons_add m x y }, map_smul' := λc x, by { ext m, exact f.cons_smul m c x } } -- then register its continuity thanks to its boundedness properties. (∥f∥) (λx, multilinear_map.mk_continuous_norm_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _) @[simp] lemma continuous_multilinear_map.curry_left_apply (f : continuous_multilinear_map 𝕜 E E₂) (x : E 0) (m : Π(i : fin n), E i.succ) : f.curry_left x m = f (cons x m) := rfl @[simp] lemma continuous_linear_map.curry_uncurry_left (f : E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) : f.uncurry_left.curry_left = f := begin ext m x, simp only [tail_cons, continuous_linear_map.uncurry_left_apply, continuous_multilinear_map.curry_left_apply], rw cons_zero end @[simp] lemma continuous_multilinear_map.uncurry_curry_left (f : continuous_multilinear_map 𝕜 E E₂) : f.curry_left.uncurry_left = f := by { ext m, simp } @[simp] lemma continuous_multilinear_map.curry_left_norm (f : continuous_multilinear_map 𝕜 E E₂) : ∥f.curry_left∥ = ∥f∥ := begin apply le_antisymm (linear_map.mk_continuous_norm_le _ (norm_nonneg _) _), have : ∥f.curry_left.uncurry_left∥ ≤ ∥f.curry_left∥ := multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _, simpa end @[simp] lemma continuous_linear_map.uncurry_left_norm (f : E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) : ∥f.uncurry_left∥ = ∥f∥ := begin apply le_antisymm (multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _), have : ∥f.uncurry_left.curry_left∥ ≤ ∥f.uncurry_left∥ := linear_map.mk_continuous_norm_le _ (norm_nonneg _) _, simpa end variables (𝕜 E E₂) /-- The space of continuous multilinear maps on `Π(i : fin (n+1)), E i` is canonically isomorphic to the space of continuous linear maps from `E 0` to the space of continuous multilinear maps on `Π(i : fin n), E i.succ `, by separating the first variable. We register this isomorphism as a linear isomorphism in `continuous_multilinear_curry_left_equiv_aux 𝕜 E E₂`. The algebraic version (without continuity assumption on the maps) is `multilinear_curry_left_equiv 𝕜 E E₂`, and the topological isomorphism (registering additionally that the isomorphism is continuous) is `continuous_multilinear_curry_left_equiv 𝕜 E E₂`. The direct and inverse maps are given by `f.uncurry_left` and `f.curry_left`. Use these unless you need the full framework of linear equivs. -/ def continuous_multilinear_curry_left_equiv_aux : (E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) ≃ₗ[𝕜] (continuous_multilinear_map 𝕜 E E₂) := { to_fun := continuous_linear_map.uncurry_left, map_add' := λf₁ f₂, by { ext m, refl }, map_smul' := λc f, by { ext m, refl }, inv_fun := continuous_multilinear_map.curry_left, left_inv := continuous_linear_map.curry_uncurry_left, right_inv := continuous_multilinear_map.uncurry_curry_left } /-- The space of continuous multilinear maps on `Π(i : fin (n+1)), E i` is canonically isomorphic to the space of continuous linear maps from `E 0` to the space of continuous multilinear maps on `Π(i : fin n), E i.succ `, by separating the first variable. We register this isomorphism in `continuous_multilinear_curry_left_equiv 𝕜 E E₂`. The algebraic version (without topology) is given in `multilinear_curry_left_equiv 𝕜 E E₂`. The direct and inverse maps are given by `f.uncurry_left` and `f.curry_left`. Use these unless you need the full framework of continuous linear equivs. -/ def continuous_multilinear_curry_left_equiv : (E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) ≃L[𝕜] (continuous_multilinear_map 𝕜 E E₂) := { continuous_to_fun := begin refine (continuous_multilinear_curry_left_equiv_aux 𝕜 E E₂).to_linear_map.continuous_of_bound (1 : ℝ) (λf, le_of_eq _), rw one_mul, exact f.uncurry_left_norm end, continuous_inv_fun := begin refine (continuous_multilinear_curry_left_equiv_aux 𝕜 E E₂).symm.to_linear_map.continuous_of_bound (1 : ℝ) (λf, le_of_eq _), rw one_mul, exact f.curry_left_norm end, .. continuous_multilinear_curry_left_equiv_aux 𝕜 E E₂ } variables {𝕜 E E₂} @[simp] lemma continuous_multilinear_curry_left_equiv_apply (f : E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) (v : Π i, E i) : continuous_multilinear_curry_left_equiv 𝕜 E E₂ f v = f (v 0) (tail v) := rfl @[simp] lemma continuous_multilinear_curry_left_equiv_symm_apply (f : continuous_multilinear_map 𝕜 E E₂) (x : E 0) (v : Π (i : fin n), E i.succ) : (continuous_multilinear_curry_left_equiv 𝕜 E E₂).symm f x v = f (cons x v) := rfl /-! #### Right currying -/ /-- Given a continuous linear map `f` from continuous multilinear maps on `n` variables to continuous linear maps on `E 0`, construct the corresponding continuous multilinear map on `n+1` variables obtained by concatenating the variables, given by `m ↦ f (init m) (m (last n))`. -/ def continuous_multilinear_map.uncurry_right (f : continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) : continuous_multilinear_map 𝕜 E E₂ := let f' : multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →ₗ[𝕜] E₂) := { to_fun := λ m, (f m).to_linear_map, map_add' := λ m i x y, by { simp, refl }, map_smul' := λ m i c x, by { simp, refl } } in (@multilinear_map.uncurry_right 𝕜 n E E₂ _ _ _ _ _ f').mk_continuous (∥f∥) (λm, f.norm_map_init_le m) @[simp] lemma continuous_multilinear_map.uncurry_right_apply (f : continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) (m : Πi, E i) : f.uncurry_right m = f (init m) (m (last n)) := rfl /-- Given a continuous multilinear map `f` in `n+1` variables, split the last variable to obtain a continuous multilinear map in `n` variables into continuous linear maps, given by `m ↦ (x ↦ f (snoc m x))`. -/ def continuous_multilinear_map.curry_right (f : continuous_multilinear_map 𝕜 E E₂) : continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂) := let f' : multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂) := { to_fun := λm, (f.to_multilinear_map.curry_right m).mk_continuous (∥f∥ * ∏ i, ∥m i∥) $ λx, f.norm_map_snoc_le m x, map_add' := λ m i x y, by { simp, refl }, map_smul' := λ m i c x, by { simp, refl } } in f'.mk_continuous (∥f∥) (λm, linear_map.mk_continuous_norm_le _ (mul_nonneg (norm_nonneg _) (prod_nonneg (λj hj, norm_nonneg _))) _) @[simp] lemma continuous_multilinear_map.curry_right_apply (f : continuous_multilinear_map 𝕜 E E₂) (m : Π(i : fin n), E i.cast_succ) (x : E (last n)) : f.curry_right m x = f (snoc m x) := rfl @[simp] lemma continuous_multilinear_map.curry_uncurry_right (f : continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) : f.uncurry_right.curry_right = f := begin ext m x, simp only [snoc_last, continuous_multilinear_map.curry_right_apply, continuous_multilinear_map.uncurry_right_apply], rw init_snoc end @[simp] lemma continuous_multilinear_map.uncurry_curry_right (f : continuous_multilinear_map 𝕜 E E₂) : f.curry_right.uncurry_right = f := by { ext m, simp } @[simp] lemma continuous_multilinear_map.curry_right_norm (f : continuous_multilinear_map 𝕜 E E₂) : ∥f.curry_right∥ = ∥f∥ := begin refine le_antisymm (multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _) _, have : ∥f.curry_right.uncurry_right∥ ≤ ∥f.curry_right∥ := multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _, simpa end @[simp] lemma continuous_multilinear_map.uncurry_right_norm (f : continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) : ∥f.uncurry_right∥ = ∥f∥ := begin refine le_antisymm (multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _) _, have : ∥f.uncurry_right.curry_right∥ ≤ ∥f.uncurry_right∥ := multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _, simpa end variables (𝕜 E E₂) /-- The space of continuous multilinear maps on `Π(i : fin (n+1)), E i` is canonically isomorphic to the space of continuous multilinear maps on `Π(i : fin n), E i.cast_succ` with values in the space of continuous linear maps on `E (last n)`, by separating the last variable. We register this isomorphism as a linear equiv in `continuous_multilinear_curry_right_equiv_aux 𝕜 E E₂`. The algebraic version (without continuity assumption on the maps) is `multilinear_curry_right_equiv 𝕜 E E₂`, and the topological isomorphism (registering additionally that the isomorphism is continuous) is `continuous_multilinear_curry_right_equiv 𝕜 E E₂`. The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these unless you need the full framework of linear equivs. -/ def continuous_multilinear_curry_right_equiv_aux : (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) ≃ₗ[𝕜] (continuous_multilinear_map 𝕜 E E₂) := { to_fun := continuous_multilinear_map.uncurry_right, map_add' := λf₁ f₂, by { ext m, refl }, map_smul' := λc f, by { ext m, refl }, inv_fun := continuous_multilinear_map.curry_right, left_inv := continuous_multilinear_map.curry_uncurry_right, right_inv := continuous_multilinear_map.uncurry_curry_right } /-- The space of continuous multilinear maps on `Π(i : fin (n+1)), E i` is canonically isomorphic to the space of continuous multilinear maps on `Π(i : fin n), E i.cast_succ` with values in the space of continuous linear maps on `E (last n)`, by separating the last variable. We register this isomorphism as a continuous linear equiv in `continuous_multilinear_curry_right_equiv 𝕜 E E₂`. The algebraic version (without topology) is given in `multilinear_curry_right_equiv 𝕜 E E₂`. The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these unless you need the full framework of continuous linear equivs. -/ def continuous_multilinear_curry_right_equiv : (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) ≃L[𝕜] (continuous_multilinear_map 𝕜 E E₂) := { continuous_to_fun := begin refine (continuous_multilinear_curry_right_equiv_aux 𝕜 E E₂).to_linear_map.continuous_of_bound (1 : ℝ) (λf, le_of_eq _), rw one_mul, exact f.uncurry_right_norm end, continuous_inv_fun := begin refine (continuous_multilinear_curry_right_equiv_aux 𝕜 E E₂).symm.to_linear_map.continuous_of_bound (1 : ℝ) (λf, le_of_eq _), rw one_mul, exact f.curry_right_norm end, .. continuous_multilinear_curry_right_equiv_aux 𝕜 E E₂ } variables {𝕜 G E E₂} @[simp] lemma continuous_multilinear_curry_right_equiv_apply (f : (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂))) (v : Π i, E i) : (continuous_multilinear_curry_right_equiv 𝕜 E E₂) f v = f (init v) (v (last n)) := rfl @[simp] lemma continuous_multilinear_curry_right_equiv_symm_apply (f : continuous_multilinear_map 𝕜 E E₂) (v : Π (i : fin n), E i.cast_succ) (x : E (last n)) : (continuous_multilinear_curry_right_equiv 𝕜 E E₂).symm f v x = f (snoc v x) := rfl /-! #### Currying with `0` variables The space of multilinear maps with `0` variables is trivial: such a multilinear map is just an arbitrary constant (note that multilinear maps in `0` variables need not map `0` to `0`!). Therefore, the space of continuous multilinear maps on `(fin 0) → G` with values in `E₂` is isomorphic (and even isometric) to `E₂`. As this is the zeroth step in the construction of iterated derivatives, we register this isomorphism. -/ variables {𝕜 G E₂} /-- Associating to a continuous multilinear map in `0` variables the unique value it takes. -/ def continuous_multilinear_map.uncurry0 (f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) : E₂ := f 0 variables (𝕜 G) /-- Associating to an element `x` of a vector space `E₂` the continuous multilinear map in `0` variables taking the (unique) value `x` -/ def continuous_multilinear_map.curry0 (x : E₂) : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂ := { to_fun := λm, x, map_add' := λ m i, fin.elim0 i, map_smul' := λ m i, fin.elim0 i, cont := continuous_const } variable {G} @[simp] lemma continuous_multilinear_map.curry0_apply (x : E₂) (m : (fin 0) → G) : (continuous_multilinear_map.curry0 𝕜 G x : ((fin 0) → G) → E₂) m = x := rfl variable {𝕜} @[simp] lemma continuous_multilinear_map.uncurry0_apply (f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) : f.uncurry0 = f 0 := rfl @[simp] lemma continuous_multilinear_map.apply_zero_curry0 (f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) {x : fin 0 → G} : continuous_multilinear_map.curry0 𝕜 G (f x) = f := by { ext m, simp [(subsingleton.elim _ _ : x = m)] } lemma continuous_multilinear_map.uncurry0_curry0 (f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) : continuous_multilinear_map.curry0 𝕜 G (f.uncurry0) = f := by simp variables (𝕜 G) @[simp] lemma continuous_multilinear_map.curry0_uncurry0 (x : E₂) : (continuous_multilinear_map.curry0 𝕜 G x).uncurry0 = x := rfl @[simp] lemma continuous_multilinear_map.uncurry0_norm (x : E₂) : ∥continuous_multilinear_map.curry0 𝕜 G x∥ = ∥x∥ := begin apply le_antisymm, { exact continuous_multilinear_map.op_norm_le_bound _ (norm_nonneg _) (λm, by simp) }, { simpa using (continuous_multilinear_map.curry0 𝕜 G x).le_op_norm 0 } end variables {𝕜 G} @[simp] lemma continuous_multilinear_map.fin0_apply_norm (f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) {x : fin 0 → G} : ∥f x∥ = ∥f∥ := begin have : x = 0 := subsingleton.elim _ _, subst this, refine le_antisymm (by simpa using f.le_op_norm 0) _, have : ∥continuous_multilinear_map.curry0 𝕜 G (f.uncurry0)∥ ≤ ∥f.uncurry0∥ := continuous_multilinear_map.op_norm_le_bound _ (norm_nonneg _) (λm, by simp [-continuous_multilinear_map.apply_zero_curry0]), simpa end lemma continuous_multilinear_map.curry0_norm (f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) : ∥f.uncurry0∥ = ∥f∥ := by simp variables (𝕜 G E₂) /-- The linear isomorphism between elements of a normed space, and continuous multilinear maps in `0` variables with values in this normed space. The continuous version is given in `continuous_multilinear_curry_fin0`. The direct and inverse maps are `uncurry0` and `curry0`. Use these unless you need the full framework of linear equivs. -/ def continuous_multilinear_curry_fin0_aux : (continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) ≃ₗ[𝕜] E₂ := { to_fun := λf, continuous_multilinear_map.uncurry0 f, inv_fun := λf, continuous_multilinear_map.curry0 𝕜 G f, map_add' := λf g, rfl, map_smul' := λc f, rfl, left_inv := continuous_multilinear_map.uncurry0_curry0, right_inv := continuous_multilinear_map.curry0_uncurry0 𝕜 G } /-- The continuous linear isomorphism between elements of a normed space, and continuous multilinear maps in `0` variables with values in this normed space. The direct and inverse maps are `uncurry0` and `curry0`. Use these unless you need the full framework of continuous linear equivs. -/ def continuous_multilinear_curry_fin0 : (continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) ≃L[𝕜] E₂ := { continuous_to_fun := begin change continuous (λ (f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂), (f : ((fin 0) → G) → E₂) 0), exact continuous_multilinear_map.continuous_eval.comp (continuous_id.prod_mk continuous_const) end, continuous_inv_fun := begin refine (continuous_multilinear_curry_fin0_aux 𝕜 G E₂).symm.to_linear_map.continuous_of_bound (1 : ℝ) (λf, le_of_eq _), rw one_mul, exact continuous_multilinear_map.uncurry0_norm _ _ _ end, .. continuous_multilinear_curry_fin0_aux 𝕜 G E₂ } variables {𝕜 G E₂} @[simp] lemma continuous_multilinear_curry_fin0_apply (f : (continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂)) : continuous_multilinear_curry_fin0 𝕜 G E₂ f = f 0 := rfl @[simp] lemma continuous_multilinear_curry_fin0_symm_apply (x : E₂) (v : (fin 0) → G) : (continuous_multilinear_curry_fin0 𝕜 G E₂).symm x v = x := rfl /-! #### With 1 variable -/ variables (𝕜 G E₂) /-- Continuous multilinear maps from `G^1` to `E₂` are isomorphic with continuous linear maps from `G` to `E₂`. -/ def continuous_multilinear_curry_fin1 : (continuous_multilinear_map 𝕜 (λ (i : fin 1), G) E₂) ≃L[𝕜] (G →L[𝕜] E₂) := (continuous_multilinear_curry_right_equiv 𝕜 (λ (i : fin 1), G) E₂).symm.trans (continuous_multilinear_curry_fin0 𝕜 G (G →L[𝕜] E₂)) variables {𝕜 G E₂} @[simp] lemma continuous_multilinear_curry_fin1_apply (f : (continuous_multilinear_map 𝕜 (λ (i : fin 1), G) E₂)) (x : G) : continuous_multilinear_curry_fin1 𝕜 G E₂ f x = f (fin.snoc 0 x) := rfl @[simp] lemma continuous_multilinear_curry_fin1_symm_apply (f : G →L[𝕜] E₂) (v : (fin 1) → G) : (continuous_multilinear_curry_fin1 𝕜 G E₂).symm f v = f (v 0) := rfl end currying
74642199e2db736db43f5a44d322076f11d5f0c1
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/combinatorics/catalan.lean
177033317785fa24ff405ff597b60f217f684594
[ "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
5,277
lean
/- Copyright (c) 2022 Julian Kuelshammer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Julian Kuelshammer -/ import data.nat.choose.central import algebra.big_operators.fin import algebra.char_zero.lemmas import tactic.field_simp import tactic.linear_combination /-! # Catalan numbers The Catalan numbers (http://oeis.org/A000108) are probably the most ubiquitous sequence of integers in mathematics. They enumerate several important objects like binary trees, Dyck paths, and triangulations of convex polygons. ## Main definitions * `catalan n`: the `n`th Catalan number, defined recursively as `catalan (n + 1) = ∑ i : fin n.succ, catalan i * catalan (n - i)`. ## Main results * `catalan_eq_central_binom_div `: The explicit formula for the Catalan number using the central binomial coefficient, `catalan n = nat.central_binom n / (n + 1)`. ## Implementation details The proof of `catalan_eq_central_binom_div` follows https://math.stackexchange.com/questions/3304415/catalan-numbers-algebraic-proof-of-the-recurrence-relation ## TODO * Prove that the Catalan numbers enumerate many interesting objects. * Provide the many variants of Catalan numbers, e.g. associated to complex reflection groups, Fuss-Catalan, etc. -/ open_locale big_operators open finset /-- The recursive definition of the sequence of Catalan numbers: `catalan (n + 1) = ∑ i : fin n.succ, catalan i * catalan (n - i)` -/ def catalan : ℕ → ℕ | 0 := 1 | (n + 1) := ∑ i : fin n.succ, have _ := i.2, have _ := nat.lt_succ_iff.mpr (n.sub_le i), catalan i * catalan (n - i) @[simp] lemma catalan_zero : catalan 0 = 1 := by rw catalan lemma catalan_succ (n : ℕ) : catalan (n + 1) = ∑ i : fin n.succ, catalan i * catalan (n - i) := by rw catalan @[simp] lemma catalan_one : catalan 1 = 1 := by simp [catalan_succ] /-- A helper sequence that can be used to prove the equality of the recursive and the explicit definition using a telescoping sum argument. -/ private def gosper_catalan (n j : ℕ) : ℚ := nat.central_binom j * nat.central_binom (n - j) * (2 * j - n) / (2 * n * (n + 1)) private lemma gosper_trick {n i : ℕ} (h : i ≤ n) : gosper_catalan (n+1) (i+1) - gosper_catalan (n+1) i = nat.central_binom i / (i + 1) * nat.central_binom (n - i) / (n - i + 1) := begin have : (n:ℚ) + 1 ≠ 0 := by exact_mod_cast n.succ_ne_zero, have : (n:ℚ) + 1 + 1 ≠ 0 := by exact_mod_cast (n + 1).succ_ne_zero, have : (i:ℚ) + 1 ≠ 0 := by exact_mod_cast i.succ_ne_zero, have : (n:ℚ) - i + 1 ≠ 0 := by exact_mod_cast (n - i).succ_ne_zero, have h₁ : ((i:ℚ) + 1) * (i + 1).central_binom = 2 * (2 * i + 1) * i.central_binom, { exact_mod_cast nat.succ_mul_central_binom_succ i }, have h₂ : ((n:ℚ) - i + 1) * (n - i + 1).central_binom = 2 * (2 * (n - i) + 1) * (n - i).central_binom, { exact_mod_cast nat.succ_mul_central_binom_succ (n - i) }, simp only [gosper_catalan], push_cast, field_simp, rw (nat.succ_sub h), linear_combination (2:ℚ) * (n - i).central_binom * (i + 1 - (n - i)) * (n + 1) * (n + 2) * ((n - i) + 1) * h₁ - 2 * i.central_binom * (n + 1) * (n + 2) * (i - (n - i) - 1) * (i + 1) * h₂, end private lemma gosper_catalan_sub_eq_central_binom_div (n : ℕ) : gosper_catalan (n + 1) (n + 1) - gosper_catalan (n + 1) 0 = nat.central_binom (n + 1) / (n + 2) := begin have : (n:ℚ) + 1 ≠ 0 := by exact_mod_cast n.succ_ne_zero, have : (n:ℚ) + 1 + 1 ≠ 0 := by exact_mod_cast (n + 1).succ_ne_zero, have h : (n:ℚ) + 2 ≠ 0 := by exact_mod_cast (n + 1).succ_ne_zero, simp only [gosper_catalan, nat.sub_zero, nat.central_binom_zero, nat.sub_self], field_simp, ring, end theorem catalan_eq_central_binom_div (n : ℕ) : catalan n = n.central_binom / (n + 1) := begin suffices : (catalan n : ℚ) = nat.central_binom n / (n + 1), { have h := nat.succ_dvd_central_binom n, exact_mod_cast this }, induction n using nat.case_strong_induction_on with d hd, { simp }, { simp_rw [catalan_succ, nat.cast_sum, nat.cast_mul], transitivity (∑ i : fin d.succ, (nat.central_binom i / (i + 1)) * (nat.central_binom (d - i) / (d - i + 1)) : ℚ), { refine sum_congr rfl (λ i _, _), congr, { exact_mod_cast hd i i.is_le }, { rw_mod_cast hd (d - i), push_cast, rw nat.cast_sub i.is_le, exact tsub_le_self }, }, { transitivity ∑ i : fin d.succ, (gosper_catalan (d + 1) (i + 1) - gosper_catalan (d + 1) i), { refine sum_congr rfl (λ i _, _), rw_mod_cast [gosper_trick i.is_le, mul_div] }, { rw [← sum_range (λi, gosper_catalan (d + 1) (i + 1) - gosper_catalan (d + 1) i), sum_range_sub, nat.succ_eq_add_one], exact_mod_cast gosper_catalan_sub_eq_central_binom_div d } } } end theorem succ_mul_catalan_eq_central_binom (n : ℕ) : (n+1) * catalan n = n.central_binom := (nat.eq_mul_of_div_eq_right n.succ_dvd_central_binom (catalan_eq_central_binom_div n).symm).symm lemma catalan_two : catalan 2 = 2 := by norm_num [catalan_eq_central_binom_div, nat.central_binom, nat.choose] lemma catalan_three : catalan 3 = 5 := by norm_num [catalan_eq_central_binom_div, nat.central_binom, nat.choose]
d11f7195a41355444e2253e0b7624aa27bc128a3
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/ftree.lean
ea6ab3158c3c14d4c1559614a19cd221843ce248
[ "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
719
lean
inductive List (T : Sort*) : Sort* | nil {} : List | cons : T → List → List namespace explicit inductive {u₁ u₂} ftree (A : Type u₁) (B : Type u₂) : Type (max 1 u₁ u₂) | leafa : A → ftree | leafb : B → ftree | node : (A → ftree) → (B → ftree) → ftree end explicit namespace implicit inductive ftree (A : Type) (B : Type) : Type | leafa : ftree | node : (A → B → ftree) → (B → ftree) → ftree set_option pp.universes true #check ftree end implicit namespace implicit2 inductive ftree (A : Type) (B : Type) : Type | leafa : A → ftree | leafb : B → ftree | node : (List A → ftree) → (B → ftree) → ftree set_option pp.universes true #check ftree end implicit2
b49258ae6f070eb289a8969d2c16315cdae6ef8f
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/tests/lean/run/IO1.lean
d8a0b9220dfc2ccf99664dbe8426016ebb852149
[ "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
991
lean
import system.IO open list -- set_option pp.all true definition main : IO unit := do l₁ ← get_line, l₂ ← get_line, put_str (l₂ ++ l₁) -- vm_eval main -- set_option trace.compiler.code_gen true vm_eval put_str "hello\n" print "************************" definition aux (n : nat) : IO unit := do put_str "========\nvalue: ", put_nat n, put_str "\n========\n" vm_eval aux 20 print "************************" definition repeat : nat → (nat → IO unit) → IO unit | 0 a := return () | (n+1) a := do a n, repeat n a vm_eval repeat 10 aux print "************************" definition execute : list (IO unit) → IO unit | [] := return () | (x::xs) := do x, execute xs vm_eval repeat 10 (λ i, execute [aux i, put_str "hello\n"]) print "************************" vm_eval do n ← return 10, put_str "value: ", put_nat n, put_str "\n", put_nat (n+2), put_str "\n----------\n" print "************************"
49fab710060ecd42871b0435d328864a1a5b7ebf
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/order/filter/extr.lean
b13ff1f8939236fef383d23b20c86634e2015bf6
[ "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
22,464
lean
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import order.filter.basic /-! # Minimum and maximum w.r.t. a filter and on a aet > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. ## Main Definitions This file defines six predicates of the form `is_A_B`, where `A` is `min`, `max`, or `extr`, and `B` is `filter` or `on`. * `is_min_filter f l a` means that `f a ≤ f x` in some `l`-neighborhood of `a`; * `is_max_filter f l a` means that `f x ≤ f a` in some `l`-neighborhood of `a`; * `is_extr_filter f l a` means `is_min_filter f l a` or `is_max_filter f l a`. Similar predicates with `_on` suffix are particular cases for `l = 𝓟 s`. ## Main statements ### Change of the filter (set) argument * `is_*_filter.filter_mono` : replace the filter with a smaller one; * `is_*_filter.filter_inf` : replace a filter `l` with `l ⊓ l'`; * `is_*_on.on_subset` : restrict to a smaller set; * `is_*_on.inter` : replace a set `s` wtih `s ∩ t`. ### Composition * `is_*_*.comp_mono` : if `x` is an extremum for `f` and `g` is a monotone function, then `x` is an extremum for `g ∘ f`; * `is_*_*.comp_antitone` : similarly for the case of antitone `g`; * `is_*_*.bicomp_mono` : if `x` is an extremum of the same type for `f` and `g` and a binary operation `op` is monotone in both arguments, then `x` is an extremum of the same type for `λ x, op (f x) (g x)`. * `is_*_filter.comp_tendsto` : if `g x` is an extremum for `f` w.r.t. `l'` and `tendsto g l l'`, then `x` is an extremum for `f ∘ g` w.r.t. `l`. * `is_*_on.on_preimage` : if `g x` is an extremum for `f` on `s`, then `x` is an extremum for `f ∘ g` on `g ⁻¹' s`. ### Algebraic operations * `is_*_*.add` : if `x` is an extremum of the same type for two functions, then it is an extremum of the same type for their sum; * `is_*_*.neg` : if `x` is an extremum for `f`, then it is an extremum of the opposite type for `-f`; * `is_*_*.sub` : if `x` is an a minimum for `f` and a maximum for `g`, then it is a minimum for `f - g` and a maximum for `g - f`; * `is_*_*.max`, `is_*_*.min`, `is_*_*.sup`, `is_*_*.inf` : similarly for `is_*_*.add` for pointwise `max`, `min`, `sup`, `inf`, respectively. ### Miscellaneous definitions * `is_*_*_const` : any point is both a minimum and maximum for a constant function; * `is_min/max_*.is_ext` : any minimum/maximum point is an extremum; * `is_*_*.dual`, `is_*_*.undual`: conversion between codomains `α` and `dual α`; ## Missing features (TODO) * Multiplication and division; * `is_*_*.bicompl` : if `x` is a minimum for `f`, `y` is a minimum for `g`, and `op` is a monotone binary operation, then `(x, y)` is a minimum for `uncurry (bicompl op f g)`. From this point of view, `is_*_*.bicomp` is a composition * It would be nice to have a tactic that specializes `comp_(anti)mono` or `bicomp_mono` based on a proof of monotonicity of a given (binary) function. The tactic should maintain a `meta` list of known (anti)monotone (binary) functions with their names, as well as a list of special types of filters, and define the missing lemmas once one of these two lists grows. -/ universes u v w x variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} open set filter open_locale filter section preorder variables [preorder β] [preorder γ] variables (f : α → β) (s : set α) (l : filter α) (a : α) /-! ### Definitions -/ /-- `is_min_filter f l a` means that `f a ≤ f x` in some `l`-neighborhood of `a` -/ def is_min_filter : Prop := ∀ᶠ x in l, f a ≤ f x /-- `is_max_filter f l a` means that `f x ≤ f a` in some `l`-neighborhood of `a` -/ def is_max_filter : Prop := ∀ᶠ x in l, f x ≤ f a /-- `is_extr_filter f l a` means `is_min_filter f l a` or `is_max_filter f l a` -/ def is_extr_filter : Prop := is_min_filter f l a ∨ is_max_filter f l a /-- `is_min_on f s a` means that `f a ≤ f x` for all `x ∈ a`. Note that we do not assume `a ∈ s`. -/ def is_min_on := is_min_filter f (𝓟 s) a /-- `is_max_on f s a` means that `f x ≤ f a` for all `x ∈ a`. Note that we do not assume `a ∈ s`. -/ def is_max_on := is_max_filter f (𝓟 s) a /-- `is_extr_on f s a` means `is_min_on f s a` or `is_max_on f s a` -/ def is_extr_on : Prop := is_extr_filter f (𝓟 s) a variables {f s a l} {t : set α} {l' : filter α} lemma is_extr_on.elim {p : Prop} : is_extr_on f s a → (is_min_on f s a → p) → (is_max_on f s a → p) → p := or.elim lemma is_min_on_iff : is_min_on f s a ↔ ∀ x ∈ s, f a ≤ f x := iff.rfl lemma is_max_on_iff : is_max_on f s a ↔ ∀ x ∈ s, f x ≤ f a := iff.rfl lemma is_min_on_univ_iff : is_min_on f univ a ↔ ∀ x, f a ≤ f x := univ_subset_iff.trans eq_univ_iff_forall lemma is_max_on_univ_iff : is_max_on f univ a ↔ ∀ x, f x ≤ f a := univ_subset_iff.trans eq_univ_iff_forall lemma is_min_filter.tendsto_principal_Ici (h : is_min_filter f l a) : tendsto f l (𝓟 $ Ici (f a)) := tendsto_principal.2 h lemma is_max_filter.tendsto_principal_Iic (h : is_max_filter f l a) : tendsto f l (𝓟 $ Iic (f a)) := tendsto_principal.2 h /-! ### Conversion to `is_extr_*` -/ lemma is_min_filter.is_extr : is_min_filter f l a → is_extr_filter f l a := or.inl lemma is_max_filter.is_extr : is_max_filter f l a → is_extr_filter f l a := or.inr lemma is_min_on.is_extr (h : is_min_on f s a) : is_extr_on f s a := h.is_extr lemma is_max_on.is_extr (h : is_max_on f s a) : is_extr_on f s a := h.is_extr /-! ### Constant function -/ lemma is_min_filter_const {b : β} : is_min_filter (λ _, b) l a := univ_mem' $ λ _, le_rfl lemma is_max_filter_const {b : β} : is_max_filter (λ _, b) l a := univ_mem' $ λ _, le_rfl lemma is_extr_filter_const {b : β} : is_extr_filter (λ _, b) l a := is_min_filter_const.is_extr lemma is_min_on_const {b : β} : is_min_on (λ _, b) s a := is_min_filter_const lemma is_max_on_const {b : β} : is_max_on (λ _, b) s a := is_max_filter_const lemma is_extr_on_const {b : β} : is_extr_on (λ _, b) s a := is_extr_filter_const /-! ### Order dual -/ open order_dual (to_dual) lemma is_min_filter_dual_iff : is_min_filter (to_dual ∘ f) l a ↔ is_max_filter f l a := iff.rfl lemma is_max_filter_dual_iff : is_max_filter (to_dual ∘ f) l a ↔ is_min_filter f l a := iff.rfl lemma is_extr_filter_dual_iff : is_extr_filter (to_dual ∘ f) l a ↔ is_extr_filter f l a := or_comm _ _ alias is_min_filter_dual_iff ↔ is_min_filter.undual is_max_filter.dual alias is_max_filter_dual_iff ↔ is_max_filter.undual is_min_filter.dual alias is_extr_filter_dual_iff ↔ is_extr_filter.undual is_extr_filter.dual lemma is_min_on_dual_iff : is_min_on (to_dual ∘ f) s a ↔ is_max_on f s a := iff.rfl lemma is_max_on_dual_iff : is_max_on (to_dual ∘ f) s a ↔ is_min_on f s a := iff.rfl lemma is_extr_on_dual_iff : is_extr_on (to_dual ∘ f) s a ↔ is_extr_on f s a := or_comm _ _ alias is_min_on_dual_iff ↔ is_min_on.undual is_max_on.dual alias is_max_on_dual_iff ↔ is_max_on.undual is_min_on.dual alias is_extr_on_dual_iff ↔ is_extr_on.undual is_extr_on.dual /-! ### Operations on the filter/set -/ lemma is_min_filter.filter_mono (h : is_min_filter f l a) (hl : l' ≤ l) : is_min_filter f l' a := hl h lemma is_max_filter.filter_mono (h : is_max_filter f l a) (hl : l' ≤ l) : is_max_filter f l' a := hl h lemma is_extr_filter.filter_mono (h : is_extr_filter f l a) (hl : l' ≤ l) : is_extr_filter f l' a := h.elim (λ h, (h.filter_mono hl).is_extr) (λ h, (h.filter_mono hl).is_extr) lemma is_min_filter.filter_inf (h : is_min_filter f l a) (l') : is_min_filter f (l ⊓ l') a := h.filter_mono inf_le_left lemma is_max_filter.filter_inf (h : is_max_filter f l a) (l') : is_max_filter f (l ⊓ l') a := h.filter_mono inf_le_left lemma is_extr_filter.filter_inf (h : is_extr_filter f l a) (l') : is_extr_filter f (l ⊓ l') a := h.filter_mono inf_le_left lemma is_min_on.on_subset (hf : is_min_on f t a) (h : s ⊆ t) : is_min_on f s a := hf.filter_mono $ principal_mono.2 h lemma is_max_on.on_subset (hf : is_max_on f t a) (h : s ⊆ t) : is_max_on f s a := hf.filter_mono $ principal_mono.2 h lemma is_extr_on.on_subset (hf : is_extr_on f t a) (h : s ⊆ t) : is_extr_on f s a := hf.filter_mono $ principal_mono.2 h lemma is_min_on.inter (hf : is_min_on f s a) (t) : is_min_on f (s ∩ t) a := hf.on_subset (inter_subset_left s t) lemma is_max_on.inter (hf : is_max_on f s a) (t) : is_max_on f (s ∩ t) a := hf.on_subset (inter_subset_left s t) lemma is_extr_on.inter (hf : is_extr_on f s a) (t) : is_extr_on f (s ∩ t) a := hf.on_subset (inter_subset_left s t) /-! ### Composition with (anti)monotone functions -/ lemma is_min_filter.comp_mono (hf : is_min_filter f l a) {g : β → γ} (hg : monotone g) : is_min_filter (g ∘ f) l a := mem_of_superset hf $ λ x hx, hg hx lemma is_max_filter.comp_mono (hf : is_max_filter f l a) {g : β → γ} (hg : monotone g) : is_max_filter (g ∘ f) l a := mem_of_superset hf $ λ x hx, hg hx lemma is_extr_filter.comp_mono (hf : is_extr_filter f l a) {g : β → γ} (hg : monotone g) : is_extr_filter (g ∘ f) l a := hf.elim (λ hf, (hf.comp_mono hg).is_extr) (λ hf, (hf.comp_mono hg).is_extr) lemma is_min_filter.comp_antitone (hf : is_min_filter f l a) {g : β → γ} (hg : antitone g) : is_max_filter (g ∘ f) l a := hf.dual.comp_mono (λ x y h, hg h) lemma is_max_filter.comp_antitone (hf : is_max_filter f l a) {g : β → γ} (hg : antitone g) : is_min_filter (g ∘ f) l a := hf.dual.comp_mono (λ x y h, hg h) lemma is_extr_filter.comp_antitone (hf : is_extr_filter f l a) {g : β → γ} (hg : antitone g) : is_extr_filter (g ∘ f) l a := hf.dual.comp_mono (λ x y h, hg h) lemma is_min_on.comp_mono (hf : is_min_on f s a) {g : β → γ} (hg : monotone g) : is_min_on (g ∘ f) s a := hf.comp_mono hg lemma is_max_on.comp_mono (hf : is_max_on f s a) {g : β → γ} (hg : monotone g) : is_max_on (g ∘ f) s a := hf.comp_mono hg lemma is_extr_on.comp_mono (hf : is_extr_on f s a) {g : β → γ} (hg : monotone g) : is_extr_on (g ∘ f) s a := hf.comp_mono hg lemma is_min_on.comp_antitone (hf : is_min_on f s a) {g : β → γ} (hg : antitone g) : is_max_on (g ∘ f) s a := hf.comp_antitone hg lemma is_max_on.comp_antitone (hf : is_max_on f s a) {g : β → γ} (hg : antitone g) : is_min_on (g ∘ f) s a := hf.comp_antitone hg lemma is_extr_on.comp_antitone (hf : is_extr_on f s a) {g : β → γ} (hg : antitone g) : is_extr_on (g ∘ f) s a := hf.comp_antitone hg lemma is_min_filter.bicomp_mono [preorder δ] {op : β → γ → δ} (hop : ((≤) ⇒ (≤) ⇒ (≤)) op op) (hf : is_min_filter f l a) {g : α → γ} (hg : is_min_filter g l a) : is_min_filter (λ x, op (f x) (g x)) l a := mem_of_superset (inter_mem hf hg) $ λ x ⟨hfx, hgx⟩, hop hfx hgx lemma is_max_filter.bicomp_mono [preorder δ] {op : β → γ → δ} (hop : ((≤) ⇒ (≤) ⇒ (≤)) op op) (hf : is_max_filter f l a) {g : α → γ} (hg : is_max_filter g l a) : is_max_filter (λ x, op (f x) (g x)) l a := mem_of_superset (inter_mem hf hg) $ λ x ⟨hfx, hgx⟩, hop hfx hgx -- No `extr` version because we need `hf` and `hg` to be of the same kind lemma is_min_on.bicomp_mono [preorder δ] {op : β → γ → δ} (hop : ((≤) ⇒ (≤) ⇒ (≤)) op op) (hf : is_min_on f s a) {g : α → γ} (hg : is_min_on g s a) : is_min_on (λ x, op (f x) (g x)) s a := hf.bicomp_mono hop hg lemma is_max_on.bicomp_mono [preorder δ] {op : β → γ → δ} (hop : ((≤) ⇒ (≤) ⇒ (≤)) op op) (hf : is_max_on f s a) {g : α → γ} (hg : is_max_on g s a) : is_max_on (λ x, op (f x) (g x)) s a := hf.bicomp_mono hop hg /-! ### Composition with `tendsto` -/ lemma is_min_filter.comp_tendsto {g : δ → α} {l' : filter δ} {b : δ} (hf : is_min_filter f l (g b)) (hg : tendsto g l' l) : is_min_filter (f ∘ g) l' b := hg hf lemma is_max_filter.comp_tendsto {g : δ → α} {l' : filter δ} {b : δ} (hf : is_max_filter f l (g b)) (hg : tendsto g l' l) : is_max_filter (f ∘ g) l' b := hg hf lemma is_extr_filter.comp_tendsto {g : δ → α} {l' : filter δ} {b : δ} (hf : is_extr_filter f l (g b)) (hg : tendsto g l' l) : is_extr_filter (f ∘ g) l' b := hf.elim (λ hf, (hf.comp_tendsto hg).is_extr) (λ hf, (hf.comp_tendsto hg).is_extr) lemma is_min_on.on_preimage (g : δ → α) {b : δ} (hf : is_min_on f s (g b)) : is_min_on (f ∘ g) (g ⁻¹' s) b := hf.comp_tendsto (tendsto_principal_principal.mpr $ subset.refl _) lemma is_max_on.on_preimage (g : δ → α) {b : δ} (hf : is_max_on f s (g b)) : is_max_on (f ∘ g) (g ⁻¹' s) b := hf.comp_tendsto (tendsto_principal_principal.mpr $ subset.refl _) lemma is_extr_on.on_preimage (g : δ → α) {b : δ} (hf : is_extr_on f s (g b)) : is_extr_on (f ∘ g) (g ⁻¹' s) b := hf.elim (λ hf, (hf.on_preimage g).is_extr) (λ hf, (hf.on_preimage g).is_extr) lemma is_min_on.comp_maps_to {t : set δ} {g : δ → α} {b : δ} (hf : is_min_on f s a) (hg : maps_to g t s) (ha : g b = a) : is_min_on (f ∘ g) t b := λ y hy, by simpa only [mem_set_of_eq, ha, (∘)] using hf (hg hy) lemma is_max_on.comp_maps_to {t : set δ} {g : δ → α} {b : δ} (hf : is_max_on f s a) (hg : maps_to g t s) (ha : g b = a) : is_max_on (f ∘ g) t b := hf.dual.comp_maps_to hg ha lemma is_extr_on.comp_maps_to {t : set δ} {g : δ → α} {b : δ} (hf : is_extr_on f s a) (hg : maps_to g t s) (ha : g b = a) : is_extr_on (f ∘ g) t b := hf.elim (λ h, or.inl $ h.comp_maps_to hg ha) (λ h, or.inr $ h.comp_maps_to hg ha) end preorder /-! ### Pointwise addition -/ section ordered_add_comm_monoid variables [ordered_add_comm_monoid β] {f g : α → β} {a : α} {s : set α} {l : filter α} lemma is_min_filter.add (hf : is_min_filter f l a) (hg : is_min_filter g l a) : is_min_filter (λ x, f x + g x) l a := show is_min_filter (λ x, f x + g x) l a, from hf.bicomp_mono (λ x x' hx y y' hy, add_le_add hx hy) hg lemma is_max_filter.add (hf : is_max_filter f l a) (hg : is_max_filter g l a) : is_max_filter (λ x, f x + g x) l a := show is_max_filter (λ x, f x + g x) l a, from hf.bicomp_mono (λ x x' hx y y' hy, add_le_add hx hy) hg lemma is_min_on.add (hf : is_min_on f s a) (hg : is_min_on g s a) : is_min_on (λ x, f x + g x) s a := hf.add hg lemma is_max_on.add (hf : is_max_on f s a) (hg : is_max_on g s a) : is_max_on (λ x, f x + g x) s a := hf.add hg end ordered_add_comm_monoid /-! ### Pointwise negation and subtraction -/ section ordered_add_comm_group variables [ordered_add_comm_group β] {f g : α → β} {a : α} {s : set α} {l : filter α} lemma is_min_filter.neg (hf : is_min_filter f l a) : is_max_filter (λ x, -f x) l a := hf.comp_antitone (λ x y hx, neg_le_neg hx) lemma is_max_filter.neg (hf : is_max_filter f l a) : is_min_filter (λ x, -f x) l a := hf.comp_antitone (λ x y hx, neg_le_neg hx) lemma is_extr_filter.neg (hf : is_extr_filter f l a) : is_extr_filter (λ x, -f x) l a := hf.elim (λ hf, hf.neg.is_extr) (λ hf, hf.neg.is_extr) lemma is_min_on.neg (hf : is_min_on f s a) : is_max_on (λ x, -f x) s a := hf.comp_antitone (λ x y hx, neg_le_neg hx) lemma is_max_on.neg (hf : is_max_on f s a) : is_min_on (λ x, -f x) s a := hf.comp_antitone (λ x y hx, neg_le_neg hx) lemma is_extr_on.neg (hf : is_extr_on f s a) : is_extr_on (λ x, -f x) s a := hf.elim (λ hf, hf.neg.is_extr) (λ hf, hf.neg.is_extr) lemma is_min_filter.sub (hf : is_min_filter f l a) (hg : is_max_filter g l a) : is_min_filter (λ x, f x - g x) l a := by simpa only [sub_eq_add_neg] using hf.add hg.neg lemma is_max_filter.sub (hf : is_max_filter f l a) (hg : is_min_filter g l a) : is_max_filter (λ x, f x - g x) l a := by simpa only [sub_eq_add_neg] using hf.add hg.neg lemma is_min_on.sub (hf : is_min_on f s a) (hg : is_max_on g s a) : is_min_on (λ x, f x - g x) s a := by simpa only [sub_eq_add_neg] using hf.add hg.neg lemma is_max_on.sub (hf : is_max_on f s a) (hg : is_min_on g s a) : is_max_on (λ x, f x - g x) s a := by simpa only [sub_eq_add_neg] using hf.add hg.neg end ordered_add_comm_group /-! ### Pointwise `sup`/`inf` -/ section semilattice_sup variables [semilattice_sup β] {f g : α → β} {a : α} {s : set α} {l : filter α} lemma is_min_filter.sup (hf : is_min_filter f l a) (hg : is_min_filter g l a) : is_min_filter (λ x, f x ⊔ g x) l a := show is_min_filter (λ x, f x ⊔ g x) l a, from hf.bicomp_mono (λ x x' hx y y' hy, sup_le_sup hx hy) hg lemma is_max_filter.sup (hf : is_max_filter f l a) (hg : is_max_filter g l a) : is_max_filter (λ x, f x ⊔ g x) l a := show is_max_filter (λ x, f x ⊔ g x) l a, from hf.bicomp_mono (λ x x' hx y y' hy, sup_le_sup hx hy) hg lemma is_min_on.sup (hf : is_min_on f s a) (hg : is_min_on g s a) : is_min_on (λ x, f x ⊔ g x) s a := hf.sup hg lemma is_max_on.sup (hf : is_max_on f s a) (hg : is_max_on g s a) : is_max_on (λ x, f x ⊔ g x) s a := hf.sup hg end semilattice_sup section semilattice_inf variables [semilattice_inf β] {f g : α → β} {a : α} {s : set α} {l : filter α} lemma is_min_filter.inf (hf : is_min_filter f l a) (hg : is_min_filter g l a) : is_min_filter (λ x, f x ⊓ g x) l a := show is_min_filter (λ x, f x ⊓ g x) l a, from hf.bicomp_mono (λ x x' hx y y' hy, inf_le_inf hx hy) hg lemma is_max_filter.inf (hf : is_max_filter f l a) (hg : is_max_filter g l a) : is_max_filter (λ x, f x ⊓ g x) l a := show is_max_filter (λ x, f x ⊓ g x) l a, from hf.bicomp_mono (λ x x' hx y y' hy, inf_le_inf hx hy) hg lemma is_min_on.inf (hf : is_min_on f s a) (hg : is_min_on g s a) : is_min_on (λ x, f x ⊓ g x) s a := hf.inf hg lemma is_max_on.inf (hf : is_max_on f s a) (hg : is_max_on g s a) : is_max_on (λ x, f x ⊓ g x) s a := hf.inf hg end semilattice_inf /-! ### Pointwise `min`/`max` -/ section linear_order variables [linear_order β] {f g : α → β} {a : α} {s : set α} {l : filter α} lemma is_min_filter.min (hf : is_min_filter f l a) (hg : is_min_filter g l a) : is_min_filter (λ x, min (f x) (g x)) l a := show is_min_filter (λ x, min (f x) (g x)) l a, from hf.bicomp_mono (λ x x' hx y y' hy, min_le_min hx hy) hg lemma is_max_filter.min (hf : is_max_filter f l a) (hg : is_max_filter g l a) : is_max_filter (λ x, min (f x) (g x)) l a := show is_max_filter (λ x, min (f x) (g x)) l a, from hf.bicomp_mono (λ x x' hx y y' hy, min_le_min hx hy) hg lemma is_min_on.min (hf : is_min_on f s a) (hg : is_min_on g s a) : is_min_on (λ x, min (f x) (g x)) s a := hf.min hg lemma is_max_on.min (hf : is_max_on f s a) (hg : is_max_on g s a) : is_max_on (λ x, min (f x) (g x)) s a := hf.min hg lemma is_min_filter.max (hf : is_min_filter f l a) (hg : is_min_filter g l a) : is_min_filter (λ x, max (f x) (g x)) l a := show is_min_filter (λ x, max (f x) (g x)) l a, from hf.bicomp_mono (λ x x' hx y y' hy, max_le_max hx hy) hg lemma is_max_filter.max (hf : is_max_filter f l a) (hg : is_max_filter g l a) : is_max_filter (λ x, max (f x) (g x)) l a := show is_max_filter (λ x, max (f x) (g x)) l a, from hf.bicomp_mono (λ x x' hx y y' hy, max_le_max hx hy) hg lemma is_min_on.max (hf : is_min_on f s a) (hg : is_min_on g s a) : is_min_on (λ x, max (f x) (g x)) s a := hf.max hg lemma is_max_on.max (hf : is_max_on f s a) (hg : is_max_on g s a) : is_max_on (λ x, max (f x) (g x)) s a := hf.max hg end linear_order section eventually /-! ### Relation with `eventually` comparisons of two functions -/ lemma filter.eventually_le.is_max_filter {α β : Type*} [preorder β] {f g : α → β} {a : α} {l : filter α} (hle : g ≤ᶠ[l] f) (hfga : f a = g a) (h : is_max_filter f l a) : is_max_filter g l a := begin refine hle.mp (h.mono $ λ x hf hgf, _), rw ← hfga, exact le_trans hgf hf end lemma is_max_filter.congr {α β : Type*} [preorder β] {f g : α → β} {a : α} {l : filter α} (h : is_max_filter f l a) (heq : f =ᶠ[l] g) (hfga : f a = g a) : is_max_filter g l a := heq.symm.le.is_max_filter hfga h lemma filter.eventually_eq.is_max_filter_iff {α β : Type*} [preorder β] {f g : α → β} {a : α} {l : filter α} (heq : f =ᶠ[l] g) (hfga : f a = g a) : is_max_filter f l a ↔ is_max_filter g l a := ⟨λ h, h.congr heq hfga, λ h, h.congr heq.symm hfga.symm⟩ lemma filter.eventually_le.is_min_filter {α β : Type*} [preorder β] {f g : α → β} {a : α} {l : filter α} (hle : f ≤ᶠ[l] g) (hfga : f a = g a) (h : is_min_filter f l a) : is_min_filter g l a := @filter.eventually_le.is_max_filter _ βᵒᵈ _ _ _ _ _ hle hfga h lemma is_min_filter.congr {α β : Type*} [preorder β] {f g : α → β} {a : α} {l : filter α} (h : is_min_filter f l a) (heq : f =ᶠ[l] g) (hfga : f a = g a) : is_min_filter g l a := heq.le.is_min_filter hfga h lemma filter.eventually_eq.is_min_filter_iff {α β : Type*} [preorder β] {f g : α → β} {a : α} {l : filter α} (heq : f =ᶠ[l] g) (hfga : f a = g a) : is_min_filter f l a ↔ is_min_filter g l a := ⟨λ h, h.congr heq hfga, λ h, h.congr heq.symm hfga.symm⟩ lemma is_extr_filter.congr {α β : Type*} [preorder β] {f g : α → β} {a : α} {l : filter α} (h : is_extr_filter f l a) (heq : f =ᶠ[l] g) (hfga : f a = g a) : is_extr_filter g l a := begin rw is_extr_filter at *, rwa [← heq.is_max_filter_iff hfga, ← heq.is_min_filter_iff hfga], end lemma filter.eventually_eq.is_extr_filter_iff {α β : Type*} [preorder β] {f g : α → β} {a : α} {l : filter α} (heq : f =ᶠ[l] g) (hfga : f a = g a) : is_extr_filter f l a ↔ is_extr_filter g l a := ⟨λ h, h.congr heq hfga, λ h, h.congr heq.symm hfga.symm⟩ end eventually /-! ### `is_max_on`/`is_min_on` imply `csupr`/`cinfi` -/ section conditionally_complete_linear_order variables [conditionally_complete_linear_order α] {f : β → α} {s : set β} {x₀ : β} lemma is_max_on.supr_eq (hx₀ : x₀ ∈ s) (h : is_max_on f s x₀) : (⨆ x : s, f x) = f x₀ := begin haveI : nonempty s := ⟨⟨x₀, hx₀⟩⟩, exact csupr_eq_of_forall_le_of_forall_lt_exists_gt (λ x, h x.prop) (λ w hw, ⟨⟨x₀, hx₀⟩, hw⟩), end lemma is_min_on.infi_eq (hx₀ : x₀ ∈ s) (h : is_min_on f s x₀) : (⨅ x : s, f x) = f x₀ := @is_max_on.supr_eq αᵒᵈ β _ _ _ _ hx₀ h end conditionally_complete_linear_order
8c5806a318115232bca373c12a27f9ff85215d89
6094e25ea0b7699e642463b48e51b2ead6ddc23f
/library/data/set/map.lean
e39bccdcd902841f41b792ce37b1ecdb21e5fcb1
[ "Apache-2.0" ]
permissive
gbaz/lean
a7835c4e3006fbbb079e8f8ffe18aacc45adebfb
a501c308be3acaa50a2c0610ce2e0d71becf8032
refs/heads/master
1,611,198,791,433
1,451,339,111,000
1,451,339,111,000
48,713,797
0
0
null
1,451,338,939,000
1,451,338,939,000
null
UTF-8
Lean
false
false
5,916
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jeremy Avigad, Andrew Zipperer Functions between subsets of finite types, bundled with the domain and range. -/ import data.set.function open eq.ops namespace set record map {X Y : Type} (a : set X) (b : set Y) := (func : X → Y) (mapsto : maps_to func a b) attribute map.func [coercion] namespace map variables {X Y Z: Type} variables {a : set X} {b : set Y} {c : set Z} /- the equivalence relation -/ protected definition equiv [reducible] (f1 f2 : map a b) : Prop := eq_on f1 f2 a namespace equiv_notation infix `~` := map.equiv end equiv_notation open equiv_notation protected theorem equiv.refl (f : map a b) : f ~ f := take x, assume H, rfl protected theorem equiv.symm {f₁ f₂ : map a b} : f₁ ~ f₂ → f₂ ~ f₁ := assume H : f₁ ~ f₂, take x, assume Ha : x ∈ a, eq.symm (H Ha) protected theorem equiv.trans {f₁ f₂ f₃ : map a b} : f₁ ~ f₂ → f₂ ~ f₃ → f₁ ~ f₃ := assume H₁ : f₁ ~ f₂, assume H₂ : f₂ ~ f₃, take x, assume Ha : x ∈ a, eq.trans (H₁ Ha) (H₂ Ha) protected theorem equiv.is_equivalence {X Y : Type} (a : set X) (b : set Y) : equivalence (@map.equiv X Y a b) := mk_equivalence (@map.equiv X Y a b) (@equiv.refl X Y a b) (@equiv.symm X Y a b) (@equiv.trans X Y a b) /- compose -/ protected definition compose (g : map b c) (f : map a b) : map a c := map.mk (#function g ∘ f) (maps_to_compose (mapsto g) (mapsto f)) notation g ∘ f := map.compose g f /- range -/ protected definition range (f : map a b) : set Y := image f a theorem range_eq_range_of_equiv {f1 f2 : map a b} (H : f1 ~ f2) : map.range f1 = map.range f2 := image_eq_image_of_eq_on H /- injective -/ protected definition injective (f : map a b) : Prop := inj_on f a theorem injective_of_equiv {f1 f2 : map a b} (H1 : f1 ~ f2) (H2 : map.injective f1) : map.injective f2 := inj_on_of_eq_on H1 H2 theorem injective_compose {g : map b c} {f : map a b} (Hg : map.injective g) (Hf: map.injective f) : map.injective (g ∘ f) := inj_on_compose (mapsto f) Hg Hf /- surjective -/ protected definition surjective (f : map a b) : Prop := surj_on f a b theorem surjective_of_equiv {f1 f2 : map a b} (H1 : f1 ~ f2) (H2 : map.surjective f1) : map.surjective f2 := surj_on_of_eq_on H1 H2 theorem surjective_compose {g : map b c} {f : map a b} (Hg : map.surjective g) (Hf: map.surjective f) : map.surjective (g ∘ f) := surj_on_compose Hg Hf /- bijective -/ protected definition bijective (f : map a b) : Prop := map.injective f ∧ map.surjective f theorem bijective_of_equiv {f1 f2 : map a b} (H1 : f1 ~ f2) (H2 : map.bijective f1) : map.bijective f2 := and.intro (injective_of_equiv H1 (and.left H2)) (surjective_of_equiv H1 (and.right H2)) theorem bijective_compose {g : map b c} {f : map a b} (Hg : map.bijective g) (Hf: map.bijective f) : map.bijective (g ∘ f) := obtain Hg₁ Hg₂, from Hg, obtain Hf₁ Hf₂, from Hf, and.intro (injective_compose Hg₁ Hf₁) (surjective_compose Hg₂ Hf₂) /- left inverse -/ -- g is a left inverse to f protected definition left_inverse (g : map b a) (f : map a b) : Prop := left_inv_on g f a theorem left_inverse_of_equiv_left {g1 g2 : map b a} {f : map a b} (eqg : g1 ~ g2) (H : map.left_inverse g1 f) : map.left_inverse g2 f := left_inv_on_of_eq_on_left (mapsto f) eqg H theorem left_inverse_of_equiv_right {g : map b a} {f1 f2 : map a b} (eqf : f1 ~ f2) (H : map.left_inverse g f1) : map.left_inverse g f2 := left_inv_on_of_eq_on_right eqf H theorem injective_of_left_inverse {g : map b a} {f : map a b} (H : map.left_inverse g f) : map.injective f := inj_on_of_left_inv_on H theorem left_inverse_compose {f' : map b a} {g' : map c b} {g : map b c} {f : map a b} (Hf : map.left_inverse f' f) (Hg : map.left_inverse g' g) : map.left_inverse (f' ∘ g') (g ∘ f) := left_inv_on_compose (mapsto f) Hf Hg /- right inverse -/ -- g is a right inverse to f protected definition right_inverse (g : map b a) (f : map a b) : Prop := map.left_inverse f g theorem right_inverse_of_equiv_left {g1 g2 : map b a} {f : map a b} (eqg : g1 ~ g2) (H : map.right_inverse g1 f) : map.right_inverse g2 f := map.left_inverse_of_equiv_right eqg H theorem right_inverse_of_equiv_right {g : map b a} {f1 f2 : map a b} (eqf : f1 ~ f2) (H : map.right_inverse g f1) : map.right_inverse g f2 := map.left_inverse_of_equiv_left eqf H theorem right_inverse_of_injective_of_left_inverse {f : map a b} {g : map b a} (injf : map.injective f) (lfg : map.left_inverse f g) : map.right_inverse f g := right_inv_on_of_inj_on_of_left_inv_on (mapsto f) (mapsto g) injf lfg theorem surjective_of_right_inverse {g : map b a} {f : map a b} (H : map.right_inverse g f) : map.surjective f := surj_on_of_right_inv_on (mapsto g) H theorem left_inverse_of_surjective_of_right_inverse {f : map a b} {g : map b a} (surjf : map.surjective f) (rfg : map.right_inverse f g) : map.left_inverse f g := left_inv_on_of_surj_on_right_inv_on surjf rfg theorem right_inverse_compose {f' : map b a} {g' : map c b} {g : map b c} {f : map a b} (Hf : map.right_inverse f' f) (Hg : map.right_inverse g' g) : map.right_inverse (f' ∘ g') (g ∘ f) := map.left_inverse_compose Hg Hf theorem equiv_of_map.left_inverse_of_right_inverse {g1 g2 : map b a} {f : map a b} (H1 : map.left_inverse g1 f) (H2 : map.right_inverse g2 f) : g1 ~ g2 := eq_on_of_left_inv_of_right_inv (mapsto g2) H1 H2 /- inverse -/ -- g is an inverse to f protected definition is_inverse (g : map b a) (f : map a b) : Prop := map.left_inverse g f ∧ map.right_inverse g f theorem bijective_of_is_inverse {g : map b a} {f : map a b} (H : map.is_inverse g f) : map.bijective f := and.intro (injective_of_left_inverse (and.left H)) (surjective_of_right_inverse (and.right H)) end map end set
bb1110e891581a81072954b1131c76d8e4027d04
842b7df4a999c5c50bbd215b8617dd705e43c2e1
/nat_num_game/src/Addition_World/add_wrld1.lean
abca70ce196dab8686d396a7e639ca8c9fcd4347
[]
no_license
Samyak-Surti/LeanCode
1c245631f74b00057d20483c8ac75916e8643b14
944eac3e5f43e2614ed246083b97fbdf24181d83
refs/heads/master
1,669,023,730,828
1,595,534,784,000
1,595,534,784,000
282,037,186
0
0
null
null
null
null
UTF-8
Lean
false
false
135
lean
variable n : ℕ lemma zero_add1 : 0 + n = n := begin induction n with d hd, rw add_zero, rw nat.add_succ, rw hd, end
3e17c9feb2a54a2e3c0cfffefc49df1d651a2a2f
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/geometry/manifold/diffeomorph.lean
4f9495090654949d24033c02aa374933e4aec3c1
[]
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
9,387
lean
/- Copyright © 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Nicolò Cavalleri. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.geometry.manifold.times_cont_mdiff_map import Mathlib.PostPort universes u_1 u_2 u_3 u_5 u_6 u_8 u_9 l u_10 u_4 u_7 namespace Mathlib /-! # Diffeomorphisms This file implements diffeomorphisms. ## Definitions * `times_diffeomorph I I' M M' n`: `n`-times continuously differentiable diffeomorphism between `M` and `M'` with respect to I and I' * `diffeomorph I I' M M'` : smooth diffeomorphism between `M` and `M'` with respect to I and I' ## Notations * `M ≃ₘ^n⟮I, I'⟯ M'` := `times_diffeomorph I J M N n` * `M ≃ₘ⟮I, I'⟯ M'` := `times_diffeomorph I J M N ⊤` ## Implementation notes This notion of diffeomorphism is needed although there is already a notion of structomorphism because structomorphisms do not allow the model spaces `H` and `H'` of the two manifolds to be different, i.e. for a structomorphism one has to impose `H = H'` which is often not the case in practice. -/ /-- `n`-times continuously differentiable diffeomorphism between `M` and `M'` with respect to I and I' -/ structure times_diffeomorph {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {E' : Type u_3} [normed_group E'] [normed_space 𝕜 E'] {H : Type u_5} [topological_space H] {H' : Type u_6} [topological_space H'] (I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') (M : Type u_8) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (M' : Type u_9) [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] (n : with_top ℕ) extends M ≃ M' where times_cont_mdiff_to_fun : times_cont_mdiff I I' n (equiv.to_fun _to_equiv) times_cont_mdiff_inv_fun : times_cont_mdiff I' I n (equiv.inv_fun _to_equiv) /-- A `diffeomorph` is just a smooth `times_diffeomorph`. -/ def diffeomorph {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {E' : Type u_3} [normed_group E'] [normed_space 𝕜 E'] {H : Type u_5} [topological_space H] {H' : Type u_6} [topological_space H'] (I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') (M : Type u_8) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (M' : Type u_9) [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] := times_diffeomorph I I' M M' ⊤ namespace times_diffeomorph protected instance has_coe_to_fun {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {E' : Type u_3} [normed_group E'] [normed_space 𝕜 E'] {H : Type u_5} [topological_space H] {H' : Type u_6} [topological_space H'] (I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') (M : Type u_8) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (M' : Type u_9) [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] (n : with_top ℕ) : has_coe_to_fun (times_diffeomorph I I' M M' n) := has_coe_to_fun.mk (fun (_x : times_diffeomorph I I' M M' n) => M → M') fun (e : times_diffeomorph I I' M M' n) => ⇑(times_diffeomorph.to_equiv e) protected instance times_cont_mdiff_map.has_coe {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {E' : Type u_3} [normed_group E'] [normed_space 𝕜 E'] {H : Type u_5} [topological_space H] {H' : Type u_6} [topological_space H'] (I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') (M : Type u_8) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (M' : Type u_9) [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] (n : with_top ℕ) : has_coe (times_diffeomorph I I' M M' n) (times_cont_mdiff_map I I' M M' n) := has_coe.mk fun (Φ : times_diffeomorph I I' M M' n) => times_cont_mdiff_map.mk (⇑Φ) (times_diffeomorph.times_cont_mdiff_to_fun Φ) protected theorem continuous {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {E' : Type u_3} [normed_group E'] [normed_space 𝕜 E'] {H : Type u_5} [topological_space H] {H' : Type u_6} [topological_space H'] (I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') (M : Type u_8) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (M' : Type u_9) [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] (n : with_top ℕ) (h : times_diffeomorph I I' M M' n) : continuous ⇑h := times_cont_mdiff.continuous (times_diffeomorph.times_cont_mdiff_to_fun h) protected theorem times_cont_mdiff {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {E' : Type u_3} [normed_group E'] [normed_space 𝕜 E'] {H : Type u_5} [topological_space H] {H' : Type u_6} [topological_space H'] (I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') (M : Type u_8) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (M' : Type u_9) [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] (n : with_top ℕ) (h : times_diffeomorph I I' M M' n) : times_cont_mdiff I I' n ⇑h := times_diffeomorph.times_cont_mdiff_to_fun h protected theorem smooth {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {E' : Type u_3} [normed_group E'] [normed_space 𝕜 E'] {H : Type u_5} [topological_space H] {H' : Type u_6} [topological_space H'] (I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') (M : Type u_8) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (M' : Type u_9) [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] (h : times_diffeomorph I I' M M' ⊤) : smooth I I' ⇑h := times_diffeomorph.times_cont_mdiff_to_fun h theorem coe_eq_to_equiv {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {E' : Type u_3} [normed_group E'] [normed_space 𝕜 E'] {H : Type u_5} [topological_space H] {H' : Type u_6} [topological_space H'] (I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') (M : Type u_8) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (M' : Type u_9) [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] (n : with_top ℕ) (h : times_diffeomorph I I' M M' n) (x : M) : coe_fn h x = coe_fn (times_diffeomorph.to_equiv h) x := rfl /-- Identity map as a diffeomorphism. -/ protected def refl {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {H : Type u_5} [topological_space H] (I : model_with_corners 𝕜 E H) (M : Type u_8) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (n : with_top ℕ) : times_diffeomorph I I M M n := mk (equiv.mk (equiv.to_fun (equiv.refl M)) (equiv.inv_fun (equiv.refl M)) sorry sorry) times_cont_mdiff_id times_cont_mdiff_id /-- Composition of two diffeomorphisms. -/ protected def trans {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {E' : Type u_3} [normed_group E'] [normed_space 𝕜 E'] {F : Type u_4} [normed_group F] [normed_space 𝕜 F] {H : Type u_5} [topological_space H] {H' : Type u_6} [topological_space H'] {G : Type u_7} [topological_space G] (I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') (J : model_with_corners 𝕜 F G) (M : Type u_8) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (M' : Type u_9) [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] (N : Type u_10) [topological_space N] [charted_space G N] [smooth_manifold_with_corners J N] (n : with_top ℕ) (h₁ : times_diffeomorph I I' M M' n) (h₂ : times_diffeomorph I' J M' N n) : times_diffeomorph I J M N n := mk (equiv.mk (equiv.to_fun (equiv.trans (times_diffeomorph.to_equiv h₁) (times_diffeomorph.to_equiv h₂))) (equiv.inv_fun (equiv.trans (times_diffeomorph.to_equiv h₁) (times_diffeomorph.to_equiv h₂))) sorry sorry) sorry sorry /-- Inverse of a diffeomorphism. -/ protected def symm {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {F : Type u_4} [normed_group F] [normed_space 𝕜 F] {H : Type u_5} [topological_space H] {G : Type u_7} [topological_space G] (I : model_with_corners 𝕜 E H) (J : model_with_corners 𝕜 F G) (M : Type u_8) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (N : Type u_10) [topological_space N] [charted_space G N] [smooth_manifold_with_corners J N] (n : with_top ℕ) (h : times_diffeomorph I J M N n) : times_diffeomorph J I N M n := mk (equiv.mk (equiv.to_fun (equiv.symm (times_diffeomorph.to_equiv h))) (equiv.inv_fun (equiv.symm (times_diffeomorph.to_equiv h))) sorry sorry) (times_diffeomorph.times_cont_mdiff_inv_fun h) (times_diffeomorph.times_cont_mdiff_to_fun h)
065c4a5a1932dcdd37893b0b5ea0106fb9db37ad
4727251e0cd73359b15b664c3170e5d754078599
/src/number_theory/class_number/function_field.lean
1ee867b982a754b56347bcf9f3b8658cdaae9229
[ "Apache-2.0" ]
permissive
Vierkantor/mathlib
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
refs/heads/master
1,658,323,012,449
1,652,256,003,000
1,652,256,003,000
209,296,341
0
1
Apache-2.0
1,568,807,655,000
1,568,807,655,000
null
UTF-8
Lean
false
false
1,752
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 number_theory.class_number.admissible_card_pow_degree import number_theory.class_number.finite import number_theory.function_field /-! # Class numbers of function fields This file defines the class number of a function field as the (finite) cardinality of the class group of its ring of integers. It also proves some elementary results on the class number. ## Main definitions - `function_field.class_number`: the class number of a function field is the (finite) cardinality of the class group of its ring of integers -/ namespace function_field open_locale polynomial variables (Fq F : Type) [field Fq] [fintype Fq] [field F] variables [algebra Fq[X] F] [algebra (ratfunc Fq) F] variables [is_scalar_tower Fq[X] (ratfunc Fq) F] variables [function_field Fq F] [is_separable (ratfunc Fq) F] open_locale classical namespace ring_of_integers open function_field noncomputable instance : fintype (class_group (ring_of_integers Fq F) F) := class_group.fintype_of_admissible_of_finite (ratfunc Fq) F (polynomial.card_pow_degree_is_admissible : absolute_value.is_admissible (polynomial.card_pow_degree : absolute_value Fq[X] ℤ)) end ring_of_integers /-- The class number in a function field is the (finite) cardinality of the class group. -/ noncomputable def class_number : ℕ := fintype.card (class_group (ring_of_integers Fq F) F) /-- The class number of a function field is `1` iff the ring of integers is a PID. -/ theorem class_number_eq_one_iff : class_number Fq F = 1 ↔ is_principal_ideal_ring (ring_of_integers Fq F) := card_class_group_eq_one_iff end function_field
eccd31216679777060231036e03061ee771519dd
d29d82a0af640c937e499f6be79fc552eae0aa13
/src/algebra/ordered_group.lean
5f8739c4eb5824190310b78ca6d7fb30f395c959
[ "Apache-2.0" ]
permissive
AbdulMajeedkhurasani/mathlib
835f8a5c5cf3075b250b3737172043ab4fa1edf6
79bc7323b164aebd000524ebafd198eb0e17f956
refs/heads/master
1,688,003,895,660
1,627,788,521,000
1,627,788,521,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
44,917
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl -/ import algebra.ordered_monoid import order.rel_iso /-! # Ordered groups This file develops the basics of ordered groups. ## Implementation details Unfortunately, the number of `'` appended to lemmas in this file may differ between the multiplicative and the additive version of a lemma. The reason is that we did not want to change existing names in the library. -/ set_option old_structure_cmd true universe u variable {α : Type u} @[to_additive] instance group.covariant_class_le.to_contravariant_class_le [group α] [has_le α] [covariant_class α α (*) (≤)] : contravariant_class α α (*) (≤) := { elim := λ a b c bc, calc b = a⁻¹ * (a * b) : eq_inv_mul_of_mul_eq rfl ... ≤ a⁻¹ * (a * c) : mul_le_mul_left' bc a⁻¹ ... = c : inv_mul_cancel_left a c } @[to_additive] instance group.swap.covariant_class_le.to_contravariant_class_le [group α] [has_le α] [covariant_class α α (function.swap (*)) (≤)] : contravariant_class α α (function.swap (*)) (≤) := { elim := λ a b c bc, calc b = b * a * a⁻¹ : eq_mul_inv_of_mul_eq rfl ... ≤ c * a * a⁻¹ : mul_le_mul_right' bc a⁻¹ ... = c : mul_inv_eq_of_eq_mul rfl } @[to_additive] instance group.covariant_class_lt.to_contravariant_class_lt [group α] [has_lt α] [covariant_class α α (*) (<)] : contravariant_class α α (*) (<) := { elim := λ a b c bc, calc b = a⁻¹ * (a * b) : eq_inv_mul_of_mul_eq rfl ... < a⁻¹ * (a * c) : mul_lt_mul_left' bc a⁻¹ ... = c : inv_mul_cancel_left a c } @[to_additive] instance group.swap.covariant_class_lt.to_contravariant_class_lt [group α] [has_lt α] [covariant_class α α (function.swap (*)) (<)] : contravariant_class α α (function.swap (*)) (<) := { elim := λ a b c bc, calc b = b * a * a⁻¹ : eq_mul_inv_of_mul_eq rfl ... < c * a * a⁻¹ : mul_lt_mul_right' bc a⁻¹ ... = c : mul_inv_eq_of_eq_mul rfl } /-- An ordered additive commutative group is an additive commutative group with a partial order in which addition is strictly monotone. -/ @[protect_proj, ancestor add_comm_group partial_order] class ordered_add_comm_group (α : Type u) extends add_comm_group α, partial_order α := (add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b) /-- An ordered commutative group is an commutative group with a partial order in which multiplication is strictly monotone. -/ @[protect_proj, ancestor comm_group partial_order] class ordered_comm_group (α : Type u) extends comm_group α, partial_order α := (mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b) attribute [to_additive] ordered_comm_group @[to_additive] instance ordered_comm_group.to_covariant_class_left_le (α : Type u) [ordered_comm_group α] : covariant_class α α (*) (≤) := { elim := λ a b c bc, ordered_comm_group.mul_le_mul_left b c bc a } /--The units of an ordered commutative monoid form an ordered commutative group. -/ @[to_additive] instance units.ordered_comm_group [ordered_comm_monoid α] : ordered_comm_group (units α) := { mul_le_mul_left := λ a b h c, (mul_le_mul_left' (h : (a : α) ≤ b) _ : (c : α) * a ≤ c * b), .. units.partial_order, .. (infer_instance : comm_group (units α)) } @[priority 100, to_additive] -- see Note [lower instance priority] instance ordered_comm_group.to_ordered_cancel_comm_monoid (α : Type u) [s : ordered_comm_group α] : ordered_cancel_comm_monoid α := { mul_left_cancel := λ a b c, (mul_right_inj a).mp, le_of_mul_le_mul_left := λ a b c, (mul_le_mul_iff_left a).mp, ..s } @[priority 100, to_additive] instance ordered_comm_group.has_exists_mul_of_le (α : Type u) [ordered_comm_group α] : has_exists_mul_of_le α := ⟨λ a b hab, ⟨b * a⁻¹, (mul_inv_cancel_comm_assoc a b).symm⟩⟩ section group variables [group α] section typeclasses_left_le variables [has_le α] [covariant_class α α (*) (≤)] {a b c d : α} /-- Uses `left` co(ntra)variant. -/ @[simp, to_additive left.neg_nonpos_iff] lemma left.inv_le_one_iff : a⁻¹ ≤ 1 ↔ 1 ≤ a := by { rw [← mul_le_mul_iff_left a], simp } /-- Uses `left` co(ntra)variant. -/ @[simp, to_additive left.nonneg_neg_iff] lemma left.one_le_inv_iff : 1 ≤ a⁻¹ ↔ a ≤ 1 := by { rw [← mul_le_mul_iff_left a], simp } @[simp, to_additive] lemma le_inv_mul_iff_mul_le : b ≤ a⁻¹ * c ↔ a * b ≤ c := by { rw ← mul_le_mul_iff_left a, simp } @[simp, to_additive] lemma inv_mul_le_iff_le_mul : b⁻¹ * a ≤ c ↔ a ≤ b * c := by rw [← mul_le_mul_iff_left b, mul_inv_cancel_left] @[to_additive neg_le_iff_add_nonneg'] lemma inv_le_iff_one_le_mul' : a⁻¹ ≤ b ↔ 1 ≤ a * b := (mul_le_mul_iff_left a).symm.trans $ by rw mul_inv_self @[to_additive] lemma le_inv_iff_mul_le_one_left : a ≤ b⁻¹ ↔ b * a ≤ 1 := (mul_le_mul_iff_left b).symm.trans $ by rw mul_inv_self @[to_additive] lemma le_inv_mul_iff_le : 1 ≤ b⁻¹ * a ↔ b ≤ a := by rw [← mul_le_mul_iff_left b, mul_one, mul_inv_cancel_left] @[to_additive] lemma inv_mul_le_one_iff : a⁻¹ * b ≤ 1 ↔ b ≤ a := trans (inv_mul_le_iff_le_mul) $ by rw mul_one end typeclasses_left_le section typeclasses_left_lt variables [has_lt α] [covariant_class α α (*) (<)] {a b c : α} /-- Uses `left` co(ntra)variant. -/ @[simp, to_additive left.neg_pos_iff] lemma left.one_lt_inv_iff : 1 < a⁻¹ ↔ a < 1 := by rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one] /-- Uses `left` co(ntra)variant. -/ @[simp, to_additive left.neg_neg_iff] lemma left.inv_lt_one_iff : a⁻¹ < 1 ↔ 1 < a := by rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one] @[simp, to_additive] lemma lt_inv_mul_iff_mul_lt : b < a⁻¹ * c ↔ a * b < c := by { rw [← mul_lt_mul_iff_left a], simp } @[simp, to_additive] lemma inv_mul_lt_iff_lt_mul : b⁻¹ * a < c ↔ a < b * c := by rw [← mul_lt_mul_iff_left b, mul_inv_cancel_left] @[to_additive] lemma inv_lt_iff_one_lt_mul' : a⁻¹ < b ↔ 1 < a * b := (mul_lt_mul_iff_left a).symm.trans $ by rw mul_inv_self @[to_additive] lemma lt_inv_iff_mul_lt_one' : a < b⁻¹ ↔ b * a < 1 := (mul_lt_mul_iff_left b).symm.trans $ by rw mul_inv_self @[to_additive] lemma lt_inv_mul_iff_lt : 1 < b⁻¹ * a ↔ b < a := by rw [← mul_lt_mul_iff_left b, mul_one, mul_inv_cancel_left] @[to_additive] lemma inv_mul_lt_one_iff : a⁻¹ * b < 1 ↔ b < a := trans (inv_mul_lt_iff_lt_mul) $ by rw mul_one end typeclasses_left_lt section typeclasses_right_le variables [has_le α] [covariant_class α α (function.swap (*)) (≤)] {a b c : α} /-- Uses `right` co(ntra)variant. -/ @[simp, to_additive right.neg_nonpos_iff] lemma right.inv_le_one_iff : a⁻¹ ≤ 1 ↔ 1 ≤ a := by { rw [← mul_le_mul_iff_right a], simp } /-- Uses `right` co(ntra)variant. -/ @[simp, to_additive right.nonneg_neg_iff] lemma right.one_le_inv_iff : 1 ≤ a⁻¹ ↔ a ≤ 1 := by { rw [← mul_le_mul_iff_right a], simp } @[to_additive neg_le_iff_add_nonneg] lemma inv_le_iff_one_le_mul : a⁻¹ ≤ b ↔ 1 ≤ b * a := (mul_le_mul_iff_right a).symm.trans $ by rw inv_mul_self @[to_additive] lemma le_inv_iff_mul_le_one_right : a ≤ b⁻¹ ↔ a * b ≤ 1 := (mul_le_mul_iff_right b).symm.trans $ by rw inv_mul_self @[simp, to_additive] lemma mul_inv_le_iff_le_mul : a * b⁻¹ ≤ c ↔ a ≤ c * b := (mul_le_mul_iff_right b).symm.trans $ by rw inv_mul_cancel_right @[simp, to_additive] lemma le_mul_inv_iff_mul_le : c ≤ a * b⁻¹ ↔ c * b ≤ a := (mul_le_mul_iff_right b).symm.trans $ by rw inv_mul_cancel_right @[simp, to_additive] lemma mul_inv_le_one_iff_le : a * b⁻¹ ≤ 1 ↔ a ≤ b := mul_inv_le_iff_le_mul.trans $ by rw one_mul @[to_additive] lemma le_mul_inv_iff_le : 1 ≤ a * b⁻¹ ↔ b ≤ a := by rw [← mul_le_mul_iff_right b, one_mul, inv_mul_cancel_right] @[to_additive] lemma mul_inv_le_one_iff : b * a⁻¹ ≤ 1 ↔ b ≤ a := trans (mul_inv_le_iff_le_mul) $ by rw one_mul end typeclasses_right_le section typeclasses_right_lt variables [has_lt α] [covariant_class α α (function.swap (*)) (<)] {a b c : α} /-- Uses `right` co(ntra)variant. -/ @[simp, to_additive right.neg_neg_iff] lemma right.inv_lt_one_iff : a⁻¹ < 1 ↔ 1 < a := by rw [← mul_lt_mul_iff_right a, inv_mul_self, one_mul] /-- Uses `right` co(ntra)variant. -/ @[simp, to_additive right.neg_pos_iff] lemma right.one_lt_inv_iff : 1 < a⁻¹ ↔ a < 1 := by rw [← mul_lt_mul_iff_right a, inv_mul_self, one_mul] @[to_additive] lemma inv_lt_iff_one_lt_mul : a⁻¹ < b ↔ 1 < b * a := (mul_lt_mul_iff_right a).symm.trans $ by rw inv_mul_self @[to_additive] lemma lt_inv_iff_mul_lt_one : a < b⁻¹ ↔ a * b < 1 := (mul_lt_mul_iff_right b).symm.trans $ by rw inv_mul_self @[simp, to_additive] lemma mul_inv_lt_iff_lt_mul : a * b⁻¹ < c ↔ a < c * b := by rw [← mul_lt_mul_iff_right b, inv_mul_cancel_right] @[simp, to_additive] lemma lt_mul_inv_iff_mul_lt : c < a * b⁻¹ ↔ c * b < a := (mul_lt_mul_iff_right b).symm.trans $ by rw inv_mul_cancel_right @[simp, to_additive] lemma inv_mul_lt_one_iff_lt : a * b⁻¹ < 1 ↔ a < b := by rw [← mul_lt_mul_iff_right b, inv_mul_cancel_right, one_mul] @[to_additive] lemma lt_mul_inv_iff_lt : 1 < a * b⁻¹ ↔ b < a := by rw [← mul_lt_mul_iff_right b, one_mul, inv_mul_cancel_right] @[to_additive] lemma mul_inv_lt_one_iff : b * a⁻¹ < 1 ↔ b < a := trans (mul_inv_lt_iff_lt_mul) $ by rw one_mul end typeclasses_right_lt section typeclasses_left_right_le variables [has_le α] [covariant_class α α (*) (≤)] [covariant_class α α (function.swap (*)) (≤)] {a b c d : α} @[simp, to_additive] lemma inv_le_inv_iff : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by { rw [← mul_le_mul_iff_left a, ← mul_le_mul_iff_right b], simp } alias neg_le_neg_iff ↔ le_of_neg_le_neg _ @[to_additive] lemma inv_le_of_inv_le (h : a⁻¹ ≤ b) : b⁻¹ ≤ a := inv_le_inv_iff.mp ( calc a⁻¹ ≤ b : h ... = b⁻¹⁻¹ : (inv_inv _).symm) @[to_additive neg_le] lemma inv_le' : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by rw [← inv_le_inv_iff, inv_inv] @[to_additive le_neg] lemma le_inv' : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by rw [← inv_le_inv_iff, inv_inv] @[to_additive] lemma mul_inv_le_inv_mul_iff : a * b⁻¹ ≤ d⁻¹ * c ↔ d * a ≤ c * b := by rw [← mul_le_mul_iff_left d, ← mul_le_mul_iff_right b, mul_inv_cancel_left, mul_assoc, inv_mul_cancel_right] @[simp, to_additive] lemma div_le_self_iff (a : α) {b : α} : a / b ≤ a ↔ 1 ≤ b := by simp [div_eq_mul_inv] alias sub_le_self_iff ↔ _ sub_le_self end typeclasses_left_right_le section typeclasses_left_right_lt variables [has_lt α] [covariant_class α α (*) (<)] [covariant_class α α (function.swap (*)) (<)] {a b c d : α} @[simp, to_additive] lemma inv_lt_inv_iff : a⁻¹ < b⁻¹ ↔ b < a := by { rw [← mul_lt_mul_iff_left a, ← mul_lt_mul_iff_right b], simp } @[to_additive] lemma lt_inv_of_lt_inv (h : a < b⁻¹) : b < a⁻¹ := inv_lt_inv_iff.mp ( calc a⁻¹⁻¹ = a : inv_inv a ... < b⁻¹ : h) @[to_additive] lemma inv_lt_of_inv_lt (h : a⁻¹ < b) : b⁻¹ < a := inv_lt_inv_iff.mp ( calc a⁻¹ < b : h ... = b⁻¹⁻¹ : (inv_inv b).symm) @[to_additive neg_lt] lemma inv_lt' : a⁻¹ < b ↔ b⁻¹ < a := by rw [← inv_lt_inv_iff, inv_inv] @[to_additive lt_neg] lemma lt_inv' : a < b⁻¹ ↔ b < a⁻¹ := by rw [← inv_lt_inv_iff, inv_inv] @[to_additive] lemma mul_inv_lt_inv_mul_iff : a * b⁻¹ < d⁻¹ * c ↔ d * a < c * b := by rw [← mul_lt_mul_iff_left d, ← mul_lt_mul_iff_right b, mul_inv_cancel_left, mul_assoc, inv_mul_cancel_right] @[simp, to_additive] lemma div_lt_self_iff (a : α) {b : α} : a / b < a ↔ 1 < b := by simp [div_eq_mul_inv] alias sub_lt_self_iff ↔ _ sub_lt_self end typeclasses_left_right_lt section pre_order variable [preorder α] section left_le variables [covariant_class α α (*) (≤)] {a : α} @[to_additive] lemma left.inv_le_self (h : 1 ≤ a) : a⁻¹ ≤ a := le_trans (left.inv_le_one_iff.mpr h) h alias left.neg_le_self ← neg_le_self @[to_additive] lemma left.self_le_inv (h : a ≤ 1) : a ≤ a⁻¹ := le_trans h (left.one_le_inv_iff.mpr h) end left_le section left_lt variables [covariant_class α α (*) (<)] {a : α} @[to_additive] lemma left.inv_lt_self (h : 1 < a) : a⁻¹ < a := (left.inv_lt_one_iff.mpr h).trans h alias left.neg_lt_self ← neg_lt_self @[to_additive] lemma left.self_lt_inv (h : a < 1) : a < a⁻¹ := lt_trans h (left.one_lt_inv_iff.mpr h) end left_lt section right_le variables [covariant_class α α (function.swap (*)) (≤)] {a : α} @[to_additive] lemma right.inv_le_self (h : 1 ≤ a) : a⁻¹ ≤ a := le_trans (right.inv_le_one_iff.mpr h) h @[to_additive] lemma right.self_le_inv (h : a ≤ 1) : a ≤ a⁻¹ := le_trans h (right.one_le_inv_iff.mpr h) end right_le section right_lt variables [covariant_class α α (function.swap (*)) (<)] {a : α} @[to_additive] lemma right.inv_lt_self (h : 1 < a) : a⁻¹ < a := (right.inv_lt_one_iff.mpr h).trans h @[to_additive] lemma right.self_lt_inv (h : a < 1) : a < a⁻¹ := lt_trans h (right.one_lt_inv_iff.mpr h) end right_lt end pre_order end group section comm_group variables [comm_group α] section has_le variables [has_le α] [covariant_class α α (*) (≤)] {a b c d : α} @[to_additive] lemma inv_mul_le_iff_le_mul' : c⁻¹ * a ≤ b ↔ a ≤ b * c := by rw [inv_mul_le_iff_le_mul, mul_comm] @[simp, to_additive] lemma mul_inv_le_iff_le_mul' : a * b⁻¹ ≤ c ↔ a ≤ b * c := by rw [← inv_mul_le_iff_le_mul, mul_comm] @[to_additive add_neg_le_add_neg_iff] lemma mul_inv_le_mul_inv_iff' : a * b⁻¹ ≤ c * d⁻¹ ↔ a * d ≤ c * b := by rw [mul_comm c, mul_inv_le_inv_mul_iff, mul_comm] end has_le section has_lt variables [has_lt α] [covariant_class α α (*) (<)] {a b c d : α} @[to_additive] lemma inv_mul_lt_iff_lt_mul' : c⁻¹ * a < b ↔ a < b * c := by rw [inv_mul_lt_iff_lt_mul, mul_comm] @[simp, to_additive] lemma mul_inv_lt_iff_le_mul' : a * b⁻¹ < c ↔ a < b * c := by rw [← inv_mul_lt_iff_lt_mul, mul_comm] @[to_additive add_neg_lt_add_neg_iff] lemma mul_inv_lt_mul_inv_iff' : a * b⁻¹ < c * d⁻¹ ↔ a * d < c * b := by rw [mul_comm c, mul_inv_lt_inv_mul_iff, mul_comm] end has_lt end comm_group alias le_inv' ↔ le_inv_of_le_inv _ attribute [to_additive] le_inv_of_le_inv alias left.inv_le_one_iff ↔ one_le_of_inv_le_one _ attribute [to_additive] one_le_of_inv_le_one alias left.one_le_inv_iff ↔ le_one_of_one_le_inv _ attribute [to_additive nonpos_of_neg_nonneg] le_one_of_one_le_inv alias inv_lt_inv_iff ↔ lt_of_inv_lt_inv _ attribute [to_additive] lt_of_inv_lt_inv alias left.inv_lt_one_iff ↔ one_lt_of_inv_lt_one _ attribute [to_additive] one_lt_of_inv_lt_one alias left.inv_lt_one_iff ← inv_lt_one_iff_one_lt attribute [to_additive] inv_lt_one_iff_one_lt alias left.inv_lt_one_iff ← inv_lt_one' attribute [to_additive neg_lt_zero] inv_lt_one' alias left.one_lt_inv_iff ↔ inv_of_one_lt_inv _ attribute [to_additive neg_of_neg_pos] inv_of_one_lt_inv alias left.one_lt_inv_iff ↔ _ one_lt_inv_of_inv attribute [to_additive neg_pos_of_neg] one_lt_inv_of_inv alias le_inv_mul_iff_mul_le ↔ mul_le_of_le_inv_mul _ attribute [to_additive] mul_le_of_le_inv_mul alias le_inv_mul_iff_mul_le ↔ _ le_inv_mul_of_mul_le attribute [to_additive] le_inv_mul_of_mul_le alias inv_mul_le_iff_le_mul ↔ _ inv_mul_le_of_le_mul attribute [to_additive] inv_mul_le_iff_le_mul alias lt_inv_mul_iff_mul_lt ↔ mul_lt_of_lt_inv_mul _ attribute [to_additive] mul_lt_of_lt_inv_mul alias lt_inv_mul_iff_mul_lt ↔ _ lt_inv_mul_of_mul_lt attribute [to_additive] lt_inv_mul_of_mul_lt alias inv_mul_lt_iff_lt_mul ↔ lt_mul_of_inv_mul_lt inv_mul_lt_of_lt_mul attribute [to_additive] lt_mul_of_inv_mul_lt attribute [to_additive] inv_mul_lt_of_lt_mul alias lt_mul_of_inv_mul_lt ← lt_mul_of_inv_mul_lt_left attribute [to_additive] lt_mul_of_inv_mul_lt_left alias left.inv_le_one_iff ← inv_le_one' attribute [to_additive neg_nonpos] inv_le_one' alias left.one_le_inv_iff ← one_le_inv' attribute [to_additive neg_nonneg] one_le_inv' alias left.one_lt_inv_iff ← one_lt_inv' attribute [to_additive neg_pos] one_lt_inv' alias mul_lt_mul_left' ← ordered_comm_group.mul_lt_mul_left' attribute [to_additive ordered_add_comm_group.add_lt_add_left] ordered_comm_group.mul_lt_mul_left' alias le_of_mul_le_mul_left' ← ordered_comm_group.le_of_mul_le_mul_left attribute [to_additive ordered_add_comm_group.le_of_add_le_add_left] ordered_comm_group.le_of_mul_le_mul_left alias lt_of_mul_lt_mul_left' ← ordered_comm_group.lt_of_mul_lt_mul_left attribute [to_additive ordered_add_comm_group.lt_of_add_lt_add_left] ordered_comm_group.lt_of_mul_lt_mul_left /-- Pullback an `ordered_comm_group` under an injective map. See note [reducible non-instances]. -/ @[reducible, to_additive function.injective.ordered_add_comm_group "Pullback an `ordered_add_comm_group` under an injective map."] def function.injective.ordered_comm_group [ordered_comm_group α] {β : Type*} [has_one β] [has_mul β] [has_inv β] [has_div β] (f : β → α) (hf : function.injective f) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f (x⁻¹) = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y) : ordered_comm_group β := { ..partial_order.lift f hf, ..hf.ordered_comm_monoid f one mul, ..hf.comm_group f one mul inv div } /- Most of the lemmas that are primed in this section appear in ordered_field. -/ /- I (DT) did not try to minimise the assumptions. -/ section group variables [group α] [has_le α] section right variables [covariant_class α α (function.swap (*)) (≤)] {a b c d : α} @[simp, to_additive] lemma div_le_div_iff_right (c : α) : a / c ≤ b / c ↔ a ≤ b := by simpa only [div_eq_mul_inv] using mul_le_mul_iff_right _ @[to_additive sub_le_sub_right] lemma div_le_div_right' (h : a ≤ b) (c : α) : a / c ≤ b / c := (div_le_div_iff_right c).2 h @[simp, to_additive sub_nonneg] lemma one_le_div' : 1 ≤ a / b ↔ b ≤ a := by rw [← mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right] alias sub_nonneg ↔ le_of_sub_nonneg sub_nonneg_of_le @[simp, to_additive sub_nonpos] lemma div_le_one' : a / b ≤ 1 ↔ a ≤ b := by rw [← mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right] alias sub_nonpos ↔ le_of_sub_nonpos sub_nonpos_of_le @[to_additive] lemma le_div_iff_mul_le : a ≤ c / b ↔ a * b ≤ c := by rw [← mul_le_mul_iff_right b, div_eq_mul_inv, inv_mul_cancel_right] alias le_sub_iff_add_le ↔ add_le_of_le_sub_right le_sub_right_of_add_le @[to_additive] lemma div_le_iff_le_mul : a / c ≤ b ↔ a ≤ b * c := by rw [← mul_le_mul_iff_right c, div_eq_mul_inv, inv_mul_cancel_right] /-- `equiv.mul_right` as an `order_iso`. -/ @[to_additive "`equiv.add_right` as an `order_iso`.", simps to_equiv apply {simp_rhs := tt}] def order_iso.mul_right (a : α) : α ≃o α := { map_rel_iff' := λ _ _, mul_le_mul_iff_right a, to_equiv := equiv.mul_right a } @[simp, to_additive] lemma order_iso.mul_right_symm (a : α) : (order_iso.mul_right a).symm = order_iso.mul_right a⁻¹ := by { ext x, refl } end right section left variables [covariant_class α α (*) (≤)] /-- `equiv.mul_left` as an `order_iso`. -/ @[to_additive "`equiv.add_left` as an `order_iso`.", simps to_equiv apply {simp_rhs := tt}] def order_iso.mul_left (a : α) : α ≃o α := { map_rel_iff' := λ _ _, mul_le_mul_iff_left a, to_equiv := equiv.mul_left a } @[simp, to_additive] lemma order_iso.mul_left_symm (a : α) : (order_iso.mul_left a).symm = order_iso.mul_left a⁻¹ := by { ext x, refl } variables [covariant_class α α (function.swap (*)) (≤)] {a b c : α} @[simp, to_additive] lemma div_le_div_iff_left (a : α) : a / b ≤ a / c ↔ c ≤ b := by rw [div_eq_mul_inv, div_eq_mul_inv, ← mul_le_mul_iff_left a⁻¹, inv_mul_cancel_left, inv_mul_cancel_left, inv_le_inv_iff] @[to_additive sub_le_sub_left] lemma div_le_div_left' (h : a ≤ b) (c : α) : c / b ≤ c / a := (div_le_div_iff_left c).2 h end left end group section comm_group variables [comm_group α] section has_le variables [has_le α] [covariant_class α α (*) (≤)] {a b c d : α} @[to_additive sub_le_sub_iff] lemma div_le_div_iff' : a / b ≤ c / d ↔ a * d ≤ c * b := by simpa only [div_eq_mul_inv] using mul_inv_le_mul_inv_iff' @[to_additive] lemma le_div_iff_mul_le' : b ≤ c / a ↔ a * b ≤ c := by rw [le_div_iff_mul_le, mul_comm] alias le_sub_iff_add_le' ↔ add_le_of_le_sub_left le_sub_left_of_add_le @[to_additive] lemma div_le_iff_le_mul' : a / b ≤ c ↔ a ≤ b * c := by rw [div_le_iff_le_mul, mul_comm] alias sub_le_iff_le_add' ↔ le_add_of_sub_left_le sub_left_le_of_le_add @[simp, to_additive] lemma inv_le_div_iff_le_mul : b⁻¹ ≤ a / c ↔ c ≤ a * b := le_div_iff_mul_le.trans inv_mul_le_iff_le_mul' @[to_additive] lemma inv_le_div_iff_le_mul' : a⁻¹ ≤ b / c ↔ c ≤ a * b := by rw [inv_le_div_iff_le_mul, mul_comm] @[to_additive sub_le] lemma div_le'' : a / b ≤ c ↔ a / c ≤ b := div_le_iff_le_mul'.trans div_le_iff_le_mul.symm @[to_additive le_sub] lemma le_div'' : a ≤ b / c ↔ c ≤ b / a := le_div_iff_mul_le'.trans le_div_iff_mul_le.symm end has_le section preorder variables [preorder α] [covariant_class α α (*) (≤)] {a b c d : α} @[to_additive sub_le_sub] lemma div_le_div'' (hab : a ≤ b) (hcd : c ≤ d) : a / d ≤ b / c := begin rw [div_eq_mul_inv, div_eq_mul_inv, mul_comm b, mul_inv_le_inv_mul_iff, mul_comm], exact mul_le_mul' hab hcd end end preorder end comm_group /- Most of the lemmas that are primed in this section appear in ordered_field. -/ /- I (DT) did not try to minimise the assumptions. -/ section group variables [group α] [has_lt α] section right variables [covariant_class α α (function.swap (*)) (<)] {a b c d : α} @[simp, to_additive] lemma div_lt_div_iff_right (c : α) : a / c < b / c ↔ a < b := by simpa only [div_eq_mul_inv] using mul_lt_mul_iff_right _ @[to_additive sub_lt_sub_right] lemma div_lt_div_right' (h : a < b) (c : α) : a / c < b / c := (div_lt_div_iff_right c).2 h @[simp, to_additive sub_pos] lemma one_lt_div' : 1 < a / b ↔ b < a := by rw [← mul_lt_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right] alias sub_pos ↔ lt_of_sub_pos sub_pos_of_lt @[simp, to_additive sub_neg] lemma div_lt_one' : a / b < 1 ↔ a < b := by rw [← mul_lt_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right] alias sub_neg ↔ lt_of_sub_neg sub_neg_of_lt alias sub_neg ← sub_lt_zero @[to_additive] lemma lt_div_iff_mul_lt : a < c / b ↔ a * b < c := by rw [← mul_lt_mul_iff_right b, div_eq_mul_inv, inv_mul_cancel_right] alias lt_sub_iff_add_lt ↔ add_lt_of_lt_sub_right lt_sub_right_of_add_lt @[to_additive] lemma div_lt_iff_lt_mul : a / c < b ↔ a < b * c := by rw [← mul_lt_mul_iff_right c, div_eq_mul_inv, inv_mul_cancel_right] alias sub_lt_iff_lt_add ↔ lt_add_of_sub_right_lt sub_right_lt_of_lt_add end right section left variables [covariant_class α α (*) (<)] [covariant_class α α (function.swap (*)) (<)] {a b c : α} @[simp, to_additive] lemma div_lt_div_iff_left (a : α) : a / b < a / c ↔ c < b := by rw [div_eq_mul_inv, div_eq_mul_inv, ← mul_lt_mul_iff_left a⁻¹, inv_mul_cancel_left, inv_mul_cancel_left, inv_lt_inv_iff] @[simp, to_additive] lemma inv_lt_div_iff_lt_mul : a⁻¹ < b / c ↔ c < a * b := by rw [div_eq_mul_inv, lt_mul_inv_iff_mul_lt, inv_mul_lt_iff_lt_mul] @[to_additive sub_lt_sub_left] lemma div_lt_div_left' (h : a < b) (c : α) : c / b < c / a := (div_lt_div_iff_left c).2 h end left end group section comm_group variables [comm_group α] section has_lt variables [has_lt α] [covariant_class α α (*) (<)] {a b c d : α} @[to_additive sub_lt_sub_iff] lemma div_lt_div_iff' : a / b < c / d ↔ a * d < c * b := by simpa only [div_eq_mul_inv] using mul_inv_lt_mul_inv_iff' @[to_additive] lemma lt_div_iff_mul_lt' : b < c / a ↔ a * b < c := by rw [lt_div_iff_mul_lt, mul_comm] alias lt_sub_iff_add_lt' ↔ add_lt_of_lt_sub_left lt_sub_left_of_add_lt @[to_additive] lemma div_lt_iff_lt_mul' : a / b < c ↔ a < b * c := by rw [div_lt_iff_lt_mul, mul_comm] alias sub_lt_iff_lt_add' ↔ lt_add_of_sub_left_lt sub_left_lt_of_lt_add @[to_additive] lemma inv_lt_div_iff_lt_mul' : b⁻¹ < a / c ↔ c < a * b := lt_div_iff_mul_lt.trans inv_mul_lt_iff_lt_mul' @[to_additive sub_lt] lemma div_lt'' : a / b < c ↔ a / c < b := div_lt_iff_lt_mul'.trans div_lt_iff_lt_mul.symm @[to_additive lt_sub] lemma lt_div'' : a < b / c ↔ c < b / a := lt_div_iff_mul_lt'.trans lt_div_iff_mul_lt.symm end has_lt section preorder variables [preorder α] [covariant_class α α (*) (<)] {a b c d : α} @[to_additive sub_lt_sub] lemma div_lt_div'' (hab : a < b) (hcd : c < d) : a / d < b / c := begin rw [div_eq_mul_inv, div_eq_mul_inv, mul_comm b, mul_inv_lt_inv_mul_iff, mul_comm], exact mul_lt_mul_of_lt_of_lt hab hcd end end preorder end comm_group section linear_order variables [group α] [linear_order α] [covariant_class α α (*) (≤)] section variable_names variables {a b c : α} @[to_additive] lemma le_of_forall_one_lt_lt_mul (h : ∀ ε : α, 1 < ε → a < b * ε) : a ≤ b := le_of_not_lt (λ h₁, lt_irrefl a (by simpa using (h _ (lt_inv_mul_iff_lt.mpr h₁)))) @[to_additive] lemma le_iff_forall_one_lt_lt_mul : a ≤ b ↔ ∀ ε, 1 < ε → a < b * ε := ⟨λ h ε, lt_mul_of_le_of_one_lt h, le_of_forall_one_lt_lt_mul⟩ /- I (DT) introduced this lemma to prove (the additive version `sub_le_sub_flip` of) `div_le_div_flip` below. Now I wonder what is the point of either of these lemmas... -/ @[to_additive] lemma div_le_inv_mul_iff [covariant_class α α (function.swap (*)) (≤)] : a / b ≤ a⁻¹ * b ↔ a ≤ b := begin rw [div_eq_mul_inv, mul_inv_le_inv_mul_iff], exact ⟨λ h, not_lt.mp (λ k, not_lt.mpr h (mul_lt_mul''' k k)), λ h, mul_le_mul' h h⟩, end /- What is the point of this lemma? See comment about `div_le_inv_mul_iff` above. -/ @[simp, to_additive] lemma div_le_div_flip {α : Type*} [comm_group α] [linear_order α] [covariant_class α α (*) (≤)] {a b : α}: a / b ≤ b / a ↔ a ≤ b := begin rw [div_eq_mul_inv b, mul_comm], exact div_le_inv_mul_iff, end @[simp, to_additive] lemma max_one_div_max_inv_one_eq_self (a : α) : max a 1 / max a⁻¹ 1 = a := by { rcases le_total a 1 with h|h; simp [h] } alias max_zero_sub_max_neg_zero_eq_self ← max_zero_sub_eq_self end variable_names section densely_ordered variables [densely_ordered α] {a b c : α} @[to_additive] lemma le_of_forall_one_lt_le_mul (h : ∀ ε : α, 1 < ε → a ≤ b * ε) : a ≤ b := le_of_forall_le_of_dense $ λ c hc, calc a ≤ b * (b⁻¹ * c) : h _ (lt_inv_mul_iff_lt.mpr hc) ... = c : mul_inv_cancel_left b c @[to_additive] lemma le_iff_forall_one_lt_le_mul : a ≤ b ↔ ∀ ε, 1 < ε → a ≤ b * ε := ⟨λ h ε ε_pos, le_mul_of_le_of_one_le h ε_pos.le, le_of_forall_one_lt_le_mul⟩ end densely_ordered end linear_order /-! ### Linearly ordered commutative groups -/ /-- A linearly ordered additive commutative group is an additive commutative group with a linear order in which addition is monotone. -/ @[protect_proj, ancestor ordered_add_comm_group linear_order] class linear_ordered_add_comm_group (α : Type u) extends ordered_add_comm_group α, linear_order α /-- A linearly ordered commutative monoid with an additively absorbing `⊤` element. Instances should include number systems with an infinite element adjoined.` -/ @[protect_proj, ancestor linear_ordered_add_comm_monoid_with_top sub_neg_monoid nontrivial] class linear_ordered_add_comm_group_with_top (α : Type*) extends linear_ordered_add_comm_monoid_with_top α, sub_neg_monoid α, nontrivial α := (neg_top : - (⊤ : α) = ⊤) (add_neg_cancel : ∀ a:α, a ≠ ⊤ → a + (- a) = 0) /-- A linearly ordered commutative group is a commutative group with a linear order in which multiplication is monotone. -/ @[protect_proj, ancestor ordered_comm_group linear_order, to_additive] class linear_ordered_comm_group (α : Type u) extends ordered_comm_group α, linear_order α section linear_ordered_comm_group variables [linear_ordered_comm_group α] {a b c : α} @[priority 100, to_additive] -- see Note [lower instance priority] instance linear_ordered_comm_group.to_linear_ordered_cancel_comm_monoid : linear_ordered_cancel_comm_monoid α := { le_of_mul_le_mul_left := λ x y z, le_of_mul_le_mul_left', mul_left_cancel := λ x y z, mul_left_cancel, ..‹linear_ordered_comm_group α› } /-- Pullback a `linear_ordered_comm_group` under an injective map. See note [reducible non-instances]. -/ @[reducible, to_additive function.injective.linear_ordered_add_comm_group "Pullback a `linear_ordered_add_comm_group` under an injective map."] def function.injective.linear_ordered_comm_group {β : Type*} [has_one β] [has_mul β] [has_inv β] [has_div β] (f : β → α) (hf : function.injective f) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f (x⁻¹) = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y) : linear_ordered_comm_group β := { ..linear_order.lift f hf, ..hf.ordered_comm_group f one mul inv div } @[to_additive linear_ordered_add_comm_group.add_lt_add_left] lemma linear_ordered_comm_group.mul_lt_mul_left' (a b : α) (h : a < b) (c : α) : c * a < c * b := mul_lt_mul_left' h c @[to_additive min_neg_neg] lemma min_inv_inv' (a b : α) : min (a⁻¹) (b⁻¹) = (max a b)⁻¹ := eq.symm $ @monotone.map_max α (order_dual α) _ _ has_inv.inv a b $ λ a b, inv_le_inv_iff.mpr @[to_additive max_neg_neg] lemma max_inv_inv' (a b : α) : max (a⁻¹) (b⁻¹) = (min a b)⁻¹ := eq.symm $ @monotone.map_min α (order_dual α) _ _ has_inv.inv a b $ λ a b, inv_le_inv_iff.mpr @[to_additive min_sub_sub_right] lemma min_div_div_right' (a b c : α) : min (a / c) (b / c) = min a b / c := by simpa only [div_eq_mul_inv] using min_mul_mul_right a b (c⁻¹) @[to_additive max_sub_sub_right] lemma max_div_div_right' (a b c : α) : max (a / c) (b / c) = max a b / c := by simpa only [div_eq_mul_inv] using max_mul_mul_right a b (c⁻¹) @[to_additive min_sub_sub_left] lemma min_div_div_left' (a b c : α) : min (a / b) (a / c) = a / max b c := by simp only [div_eq_mul_inv, min_mul_mul_left, min_inv_inv'] @[to_additive max_sub_sub_left] lemma max_div_div_left' (a b c : α) : max (a / b) (a / c) = a / min b c := by simp only [div_eq_mul_inv, max_mul_mul_left, max_inv_inv'] @[to_additive eq_zero_of_neg_eq] lemma eq_one_of_inv_eq' (h : a⁻¹ = a) : a = 1 := match lt_trichotomy a 1 with | or.inl h₁ := have 1 < a, from h ▸ one_lt_inv_of_inv h₁, absurd h₁ this.asymm | or.inr (or.inl h₁) := h₁ | or.inr (or.inr h₁) := have a < 1, from h ▸ inv_lt_one'.mpr h₁, absurd h₁ this.asymm end @[to_additive exists_zero_lt] lemma exists_one_lt' [nontrivial α] : ∃ (a:α), 1 < a := begin obtain ⟨y, hy⟩ := decidable.exists_ne (1 : α), cases hy.lt_or_lt, { exact ⟨y⁻¹, one_lt_inv'.mpr h⟩ }, { exact ⟨y, h⟩ } end @[priority 100, to_additive] -- see Note [lower instance priority] instance linear_ordered_comm_group.to_no_top_order [nontrivial α] : no_top_order α := ⟨ begin obtain ⟨y, hy⟩ : ∃ (a:α), 1 < a := exists_one_lt', exact λ a, ⟨a * y, lt_mul_of_one_lt_right' a hy⟩ end ⟩ @[priority 100, to_additive] -- see Note [lower instance priority] instance linear_ordered_comm_group.to_no_bot_order [nontrivial α] : no_bot_order α := ⟨ begin obtain ⟨y, hy⟩ : ∃ (a:α), 1 < a := exists_one_lt', exact λ a, ⟨a / y, (div_lt_self_iff a).mpr hy⟩ end ⟩ end linear_ordered_comm_group section covariant_add_le section has_neg variables [has_neg α] [linear_order α] {a b: α} /-- `abs a` is the absolute value of `a`. -/ def abs {α : Type*} [has_neg α] [linear_order α] (a : α) : α := max a (-a) lemma abs_choice (x : α) : abs x = x ∨ abs x = -x := max_choice _ _ lemma abs_le' : abs a ≤ b ↔ a ≤ b ∧ -a ≤ b := max_le_iff lemma le_abs : a ≤ abs b ↔ a ≤ b ∨ a ≤ -b := le_max_iff lemma le_abs_self (a : α) : a ≤ abs a := le_max_left _ _ lemma neg_le_abs_self (a : α) : -a ≤ abs a := le_max_right _ _ lemma lt_abs : a < abs b ↔ a < b ∨ a < -b := lt_max_iff theorem abs_le_abs (h₀ : a ≤ b) (h₁ : -a ≤ b) : abs a ≤ abs b := (abs_le'.2 ⟨h₀, h₁⟩).trans (le_abs_self b) lemma abs_by_cases (P : α → Prop) {a : α} (h1 : P a) (h2 : P (-a)) : P (abs a) := sup_ind _ _ h1 h2 end has_neg section add_group variables [add_group α] [linear_order α] @[simp] lemma abs_neg (a : α) : abs (-a) = abs a := begin unfold abs, rw [max_comm, neg_neg] end lemma eq_or_eq_neg_of_abs_eq {a b : α} (h : abs a = b) : a = b ∨ a = -b := by simpa only [← h, eq_comm, eq_neg_iff_eq_neg] using abs_choice a lemma abs_eq_abs {a b : α} : abs a = abs b ↔ a = b ∨ a = -b := begin refine ⟨λ h, _, λ h, _⟩, { obtain rfl | rfl := eq_or_eq_neg_of_abs_eq h; simpa only [neg_eq_iff_neg_eq, neg_inj, or.comm, @eq_comm _ (-b)] using abs_choice b }, { cases h; simp only [h, abs_neg] }, end lemma abs_sub_comm (a b : α) : abs (a - b) = abs (b - a) := calc abs (a - b) = abs (- (b - a)) : congr_arg _ (neg_sub b a).symm ... = abs (b - a) : abs_neg (b - a) variables [covariant_class α α (+) (≤)] {a b c : α} lemma abs_of_nonneg (h : 0 ≤ a) : abs a = a := max_eq_left $ (neg_nonpos.2 h).trans h lemma abs_of_pos (h : 0 < a) : abs a = a := abs_of_nonneg h.le lemma abs_of_nonpos (h : a ≤ 0) : abs a = -a := max_eq_right $ h.trans (neg_nonneg.2 h) lemma abs_of_neg (h : a < 0) : abs a = -a := abs_of_nonpos h.le @[simp] lemma abs_zero : abs 0 = (0:α) := abs_of_nonneg le_rfl @[simp] lemma abs_pos : 0 < abs a ↔ a ≠ 0 := begin rcases lt_trichotomy a 0 with (ha|rfl|ha), { simp [abs_of_neg ha, neg_pos, ha.ne, ha] }, { simp }, { simp [abs_of_pos ha, ha, ha.ne.symm] } end lemma abs_pos_of_pos (h : 0 < a) : 0 < abs a := abs_pos.2 h.ne.symm lemma abs_pos_of_neg (h : a < 0) : 0 < abs a := abs_pos.2 h.ne lemma neg_abs_le_self (a : α) : -abs a ≤ a := begin cases le_total 0 a with h h, { calc -abs a = - a : congr_arg (has_neg.neg) (abs_of_nonneg h) ... ≤ 0 : neg_nonpos.mpr h ... ≤ a : h }, { calc -abs a = - - a : congr_arg (has_neg.neg) (abs_of_nonpos h) ... ≤ a : (neg_neg a).le } end lemma abs_nonneg (a : α) : 0 ≤ abs a := (le_total 0 a).elim (λ h, h.trans (le_abs_self a)) (λ h, (neg_nonneg.2 h).trans $ neg_le_abs_self a) @[simp] lemma abs_abs (a : α) : abs (abs a) = abs a := abs_of_nonneg $ abs_nonneg a @[simp] lemma abs_eq_zero : abs a = 0 ↔ a = 0 := decidable.not_iff_not.1 $ ne_comm.trans $ (abs_nonneg a).lt_iff_ne.symm.trans abs_pos @[simp] lemma abs_nonpos_iff {a : α} : abs a ≤ 0 ↔ a = 0 := (abs_nonneg a).le_iff_eq.trans abs_eq_zero variable [covariant_class α α (function.swap (+)) (≤)] lemma abs_lt : abs a < b ↔ - b < a ∧ a < b := max_lt_iff.trans $ and.comm.trans $ by rw [neg_lt] lemma neg_lt_of_abs_lt (h : abs a < b) : -b < a := (abs_lt.mp h).1 lemma lt_of_abs_lt (h : abs a < b) : a < b := (abs_lt.mp h).2 lemma max_sub_min_eq_abs' (a b : α) : max a b - min a b = abs (a - b) := begin cases le_total a b with ab ba, { rw [max_eq_right ab, min_eq_left ab, abs_of_nonpos, neg_sub], rwa sub_nonpos }, { rw [max_eq_left ba, min_eq_right ba, abs_of_nonneg], rwa sub_nonneg } end lemma max_sub_min_eq_abs (a b : α) : max a b - min a b = abs (b - a) := by { rw abs_sub_comm, exact max_sub_min_eq_abs' _ _ } end add_group section add_comm_group variables [add_comm_group α] [linear_order α] [covariant_class α α (+) (≤)] {a b c d : α} lemma abs_le : abs a ≤ b ↔ - b ≤ a ∧ a ≤ b := by rw [abs_le', and.comm, neg_le] lemma neg_le_of_abs_le (h : abs a ≤ b) : -b ≤ a := (abs_le.mp h).1 lemma le_of_abs_le (h : abs a ≤ b) : a ≤ b := (abs_le.mp h).2 /-- The **triangle inequality** in `linear_ordered_add_comm_group`s. -/ lemma abs_add (a b : α) : abs (a + b) ≤ abs a + abs b := abs_le.2 ⟨(neg_add (abs a) (abs b)).symm ▸ add_le_add (neg_le.2 $ neg_le_abs_self _) (neg_le.2 $ neg_le_abs_self _), add_le_add (le_abs_self _) (le_abs_self _)⟩ theorem abs_sub (a b : α) : abs (a - b) ≤ abs a + abs b := by { rw [sub_eq_add_neg, ←abs_neg b], exact abs_add a _ } lemma abs_sub_le_iff : abs (a - b) ≤ c ↔ a - b ≤ c ∧ b - a ≤ c := by rw [abs_le, neg_le_sub_iff_le_add, sub_le_iff_le_add', and_comm, sub_le_iff_le_add'] lemma abs_sub_lt_iff : abs (a - b) < c ↔ a - b < c ∧ b - a < c := by rw [abs_lt, neg_lt_sub_iff_lt_add', sub_lt_iff_lt_add', and_comm, sub_lt_iff_lt_add'] lemma sub_le_of_abs_sub_le_left (h : abs (a - b) ≤ c) : b - c ≤ a := sub_le.1 $ (abs_sub_le_iff.1 h).2 lemma sub_le_of_abs_sub_le_right (h : abs (a - b) ≤ c) : a - c ≤ b := sub_le_of_abs_sub_le_left (abs_sub_comm a b ▸ h) lemma sub_lt_of_abs_sub_lt_left (h : abs (a - b) < c) : b - c < a := sub_lt.1 $ (abs_sub_lt_iff.1 h).2 lemma sub_lt_of_abs_sub_lt_right (h : abs (a - b) < c) : a - c < b := sub_lt_of_abs_sub_lt_left (abs_sub_comm a b ▸ h) lemma abs_sub_abs_le_abs_sub (a b : α) : abs a - abs b ≤ abs (a - b) := sub_le_iff_le_add.2 $ calc abs a = abs (a - b + b) : by rw [sub_add_cancel] ... ≤ abs (a - b) + abs b : abs_add _ _ lemma abs_abs_sub_abs_le_abs_sub (a b : α) : abs (abs a - abs b) ≤ abs (a - b) := abs_sub_le_iff.2 ⟨abs_sub_abs_le_abs_sub _ _, by rw abs_sub_comm; apply abs_sub_abs_le_abs_sub⟩ lemma abs_eq (hb : 0 ≤ b) : abs a = b ↔ a = b ∨ a = -b := begin refine ⟨eq_or_eq_neg_of_abs_eq, _⟩, rintro (rfl|rfl); simp only [abs_neg, abs_of_nonneg hb] end lemma abs_le_max_abs_abs (hab : a ≤ b) (hbc : b ≤ c) : abs b ≤ max (abs a) (abs c) := abs_le'.2 ⟨by simp [hbc.trans (le_abs_self c)], by simp [(neg_le_neg_iff.mpr hab).trans (neg_le_abs_self a)]⟩ lemma eq_of_abs_sub_eq_zero {a b : α} (h : abs (a - b) = 0) : a = b := sub_eq_zero.1 $ abs_eq_zero.1 h lemma abs_sub_le (a b c : α) : abs (a - c) ≤ abs (a - b) + abs (b - c) := calc abs (a - c) = abs (a - b + (b - c)) : by rw [sub_add_sub_cancel] ... ≤ abs (a - b) + abs (b - c) : abs_add _ _ lemma abs_add_three (a b c : α) : abs (a + b + c) ≤ abs a + abs b + abs c := (abs_add _ _).trans (add_le_add_right (abs_add _ _) _) lemma dist_bdd_within_interval {a b lb ub : α} (hal : lb ≤ a) (hau : a ≤ ub) (hbl : lb ≤ b) (hbu : b ≤ ub) : abs (a - b) ≤ ub - lb := abs_sub_le_iff.2 ⟨sub_le_sub hau hbl, sub_le_sub hbu hal⟩ lemma eq_of_abs_sub_nonpos (h : abs (a - b) ≤ 0) : a = b := eq_of_abs_sub_eq_zero (le_antisymm h (abs_nonneg (a - b))) lemma abs_max_sub_max_le_abs (a b c : α) : abs (max a c - max b c) ≤ abs (a - b) := begin simp_rw [abs_le, le_sub_iff_add_le, sub_le_iff_le_add, ← max_add_add_left], split; apply max_le_max; simp only [← le_sub_iff_add_le, ← sub_le_iff_le_add, sub_self, neg_le, neg_le_abs_self, neg_zero, abs_nonneg, le_abs_self] end end add_comm_group end covariant_add_le section linear_ordered_add_comm_group variable [linear_ordered_add_comm_group α] instance with_top.linear_ordered_add_comm_group_with_top : linear_ordered_add_comm_group_with_top (with_top α) := { neg := option.map (λ a : α, -a), neg_top := @option.map_none _ _ (λ a : α, -a), add_neg_cancel := begin rintro (a | a) ha, { exact (ha rfl).elim }, { exact with_top.coe_add.symm.trans (with_top.coe_eq_coe.2 (add_neg_self a)) } end, .. with_top.linear_ordered_add_comm_monoid_with_top, .. option.nontrivial } end linear_ordered_add_comm_group /-- This is not so much a new structure as a construction mechanism for ordered groups, by specifying only the "positive cone" of the group. -/ class nonneg_add_comm_group (α : Type*) extends add_comm_group α := (nonneg : α → Prop) (pos : α → Prop := λ a, nonneg a ∧ ¬ nonneg (neg a)) (pos_iff : ∀ a, pos a ↔ nonneg a ∧ ¬ nonneg (-a) . order_laws_tac) (zero_nonneg : nonneg 0) (add_nonneg : ∀ {a b}, nonneg a → nonneg b → nonneg (a + b)) (nonneg_antisymm : ∀ {a}, nonneg a → nonneg (-a) → a = 0) namespace nonneg_add_comm_group variable [s : nonneg_add_comm_group α] include s @[reducible, priority 100] -- see Note [lower instance priority] instance to_ordered_add_comm_group : ordered_add_comm_group α := { le := λ a b, nonneg (b - a), lt := λ a b, pos (b - a), lt_iff_le_not_le := λ a b, by simp; rw [pos_iff]; simp, le_refl := λ a, by simp [zero_nonneg], le_trans := λ a b c nab nbc, by simp [-sub_eq_add_neg]; rw ← sub_add_sub_cancel; exact add_nonneg nbc nab, le_antisymm := λ a b nab nba, eq_of_sub_eq_zero $ nonneg_antisymm nba (by rw neg_sub; exact nab), add_le_add_left := λ a b nab c, by simpa [(≤), preorder.le] using nab, ..s } theorem nonneg_def {a : α} : nonneg a ↔ 0 ≤ a := show _ ↔ nonneg _, by simp theorem pos_def {a : α} : pos a ↔ 0 < a := show _ ↔ pos _, by simp theorem not_zero_pos : ¬ pos (0 : α) := mt pos_def.1 (lt_irrefl _) theorem zero_lt_iff_nonneg_nonneg {a : α} : 0 < a ↔ nonneg a ∧ ¬ nonneg (-a) := pos_def.symm.trans (pos_iff _) theorem nonneg_total_iff : (∀ a : α, nonneg a ∨ nonneg (-a)) ↔ (∀ a b : α, a ≤ b ∨ b ≤ a) := ⟨λ h a b, by have := h (b - a); rwa [neg_sub] at this, λ h a, by rw [nonneg_def, nonneg_def, neg_nonneg]; apply h⟩ /-- A `nonneg_add_comm_group` is a `linear_ordered_add_comm_group` if `nonneg` is total and decidable. -/ def to_linear_ordered_add_comm_group [decidable_pred (@nonneg α _)] (nonneg_total : ∀ a : α, nonneg a ∨ nonneg (-a)) : linear_ordered_add_comm_group α := { le := (≤), lt := (<), le_total := nonneg_total_iff.1 nonneg_total, decidable_le := by apply_instance, decidable_lt := by apply_instance, ..@nonneg_add_comm_group.to_ordered_add_comm_group _ s } end nonneg_add_comm_group namespace order_dual instance [ordered_add_comm_group α] : ordered_add_comm_group (order_dual α) := { add_left_neg := λ a : α, add_left_neg a, sub := λ a b, (a - b : α), ..order_dual.ordered_add_comm_monoid, ..show add_comm_group α, by apply_instance } instance [linear_ordered_add_comm_group α] : linear_ordered_add_comm_group (order_dual α) := { add_le_add_left := λ a b h c, by exact add_le_add_left h _, ..order_dual.linear_order α, ..show add_comm_group α, by apply_instance } end order_dual namespace prod variables {G H : Type*} @[to_additive] instance [ordered_comm_group G] [ordered_comm_group H] : ordered_comm_group (G × H) := { .. prod.comm_group, .. prod.partial_order G H, .. prod.ordered_cancel_comm_monoid } end prod section type_tags instance [ordered_add_comm_group α] : ordered_comm_group (multiplicative α) := { ..multiplicative.comm_group, ..multiplicative.ordered_comm_monoid } instance [ordered_comm_group α] : ordered_add_comm_group (additive α) := { ..additive.add_comm_group, ..additive.ordered_add_comm_monoid } instance [linear_ordered_add_comm_group α] : linear_ordered_comm_group (multiplicative α) := { ..multiplicative.linear_order, ..multiplicative.ordered_comm_group } instance [linear_ordered_comm_group α] : linear_ordered_add_comm_group (additive α) := { ..additive.linear_order, ..additive.ordered_add_comm_group } end type_tags section norm_num_lemmas /- The following lemmas are stated so that the `norm_num` tactic can use them with the expected signatures. -/ variables [ordered_comm_group α] {a b : α} @[to_additive neg_le_neg] lemma inv_le_inv' : a ≤ b → b⁻¹ ≤ a⁻¹ := inv_le_inv_iff.mpr @[to_additive neg_lt_neg] lemma inv_lt_inv' : a < b → b⁻¹ < a⁻¹ := inv_lt_inv_iff.mpr /- The additive version is also a `linarith` lemma. -/ @[to_additive] theorem inv_lt_one_of_one_lt : 1 < a → a⁻¹ < 1 := inv_lt_one_iff_one_lt.mpr /- The additive version is also a `linarith` lemma. -/ @[to_additive] lemma inv_le_one_of_one_le : 1 ≤ a → a⁻¹ ≤ 1 := inv_le_one'.mpr @[to_additive neg_nonneg_of_nonpos] lemma one_le_inv_of_le_one : a ≤ 1 → 1 ≤ a⁻¹ := one_le_inv'.mpr end norm_num_lemmas