Context
stringlengths
285
157k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
18
3.69k
theorem
stringlengths
25
2.71k
proof
stringlengths
5
10.6k
/- Copyright (c) 2022 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.RingTheory.DedekindDomain.Ideal #align_import number_theory.ramification_inertia from "leanprover-community/mathlib"@"039a089d2a4b93c761b234f3e5f5aeb752bac60f" /-! # Ramification index and inertia degree Given `P : Ideal S` lying over `p : Ideal R` for the ring extension `f : R →+* S` (assuming `P` and `p` are prime or maximal where needed), the **ramification index** `Ideal.ramificationIdx f p P` is the multiplicity of `P` in `map f p`, and the **inertia degree** `Ideal.inertiaDeg f p P` is the degree of the field extension `(S / P) : (R / p)`. ## Main results The main theorem `Ideal.sum_ramification_inertia` states that for all coprime `P` lying over `p`, `Σ P, ramification_idx f p P * inertia_deg f p P` equals the degree of the field extension `Frac(S) : Frac(R)`. ## Implementation notes Often the above theory is set up in the case where: * `R` is the ring of integers of a number field `K`, * `L` is a finite separable extension of `K`, * `S` is the integral closure of `R` in `L`, * `p` and `P` are maximal ideals, * `P` is an ideal lying over `p` We will try to relax the above hypotheses as much as possible. ## Notation In this file, `e` stands for the ramification index and `f` for the inertia degree of `P` over `p`, leaving `p` and `P` implicit. -/ namespace Ideal universe u v variable {R : Type u} [CommRing R] variable {S : Type v} [CommRing S] (f : R →+* S) variable (p : Ideal R) (P : Ideal S) open FiniteDimensional open UniqueFactorizationMonoid section DecEq open scoped Classical /-- The ramification index of `P` over `p` is the largest exponent `n` such that `p` is contained in `P^n`. In particular, if `p` is not contained in `P^n`, then the ramification index is 0. If there is no largest such `n` (e.g. because `p = ⊥`), then `ramificationIdx` is defined to be 0. -/ noncomputable def ramificationIdx : ℕ := sSup {n | map f p ≤ P ^ n} #align ideal.ramification_idx Ideal.ramificationIdx variable {f p P} theorem ramificationIdx_eq_find (h : ∃ n, ∀ k, map f p ≤ P ^ k → k ≤ n) : ramificationIdx f p P = Nat.find h := Nat.sSup_def h #align ideal.ramification_idx_eq_find Ideal.ramificationIdx_eq_find theorem ramificationIdx_eq_zero (h : ∀ n : ℕ, ∃ k, map f p ≤ P ^ k ∧ n < k) : ramificationIdx f p P = 0 := dif_neg (by push_neg; exact h) #align ideal.ramification_idx_eq_zero Ideal.ramificationIdx_eq_zero theorem ramificationIdx_spec {n : ℕ} (hle : map f p ≤ P ^ n) (hgt : ¬map f p ≤ P ^ (n + 1)) : ramificationIdx f p P = n := by let Q : ℕ → Prop := fun m => ∀ k : ℕ, map f p ≤ P ^ k → k ≤ m have : Q n := by intro k hk refine le_of_not_lt fun hnk => ?_ exact hgt (hk.trans (Ideal.pow_le_pow_right hnk)) rw [ramificationIdx_eq_find ⟨n, this⟩] refine le_antisymm (Nat.find_min' _ this) (le_of_not_gt fun h : Nat.find _ < n => ?_) obtain this' := Nat.find_spec ⟨n, this⟩ exact h.not_le (this' _ hle) #align ideal.ramification_idx_spec Ideal.ramificationIdx_spec theorem ramificationIdx_lt {n : ℕ} (hgt : ¬map f p ≤ P ^ n) : ramificationIdx f p P < n := by cases' n with n n · simp at hgt · rw [Nat.lt_succ_iff] have : ∀ k, map f p ≤ P ^ k → k ≤ n := by refine fun k hk => le_of_not_lt fun hnk => ?_ exact hgt (hk.trans (Ideal.pow_le_pow_right hnk)) rw [ramificationIdx_eq_find ⟨n, this⟩] exact Nat.find_min' ⟨n, this⟩ this #align ideal.ramification_idx_lt Ideal.ramificationIdx_lt @[simp] theorem ramificationIdx_bot : ramificationIdx f ⊥ P = 0 := dif_neg <| not_exists.mpr fun n hn => n.lt_succ_self.not_le (hn _ (by simp)) #align ideal.ramification_idx_bot Ideal.ramificationIdx_bot @[simp] theorem ramificationIdx_of_not_le (h : ¬map f p ≤ P) : ramificationIdx f p P = 0 := ramificationIdx_spec (by simp) (by simpa using h) #align ideal.ramification_idx_of_not_le Ideal.ramificationIdx_of_not_le theorem ramificationIdx_ne_zero {e : ℕ} (he : e ≠ 0) (hle : map f p ≤ P ^ e) (hnle : ¬map f p ≤ P ^ (e + 1)) : ramificationIdx f p P ≠ 0 := by rwa [ramificationIdx_spec hle hnle] #align ideal.ramification_idx_ne_zero Ideal.ramificationIdx_ne_zero theorem le_pow_of_le_ramificationIdx {n : ℕ} (hn : n ≤ ramificationIdx f p P) : map f p ≤ P ^ n := by contrapose! hn exact ramificationIdx_lt hn #align ideal.le_pow_of_le_ramification_idx Ideal.le_pow_of_le_ramificationIdx theorem le_pow_ramificationIdx : map f p ≤ P ^ ramificationIdx f p P := le_pow_of_le_ramificationIdx (le_refl _) #align ideal.le_pow_ramification_idx Ideal.le_pow_ramificationIdx theorem le_comap_pow_ramificationIdx : p ≤ comap f (P ^ ramificationIdx f p P) := map_le_iff_le_comap.mp le_pow_ramificationIdx #align ideal.le_comap_pow_ramification_idx Ideal.le_comap_pow_ramificationIdx theorem le_comap_of_ramificationIdx_ne_zero (h : ramificationIdx f p P ≠ 0) : p ≤ comap f P := Ideal.map_le_iff_le_comap.mp <| le_pow_ramificationIdx.trans <| Ideal.pow_le_self <| h #align ideal.le_comap_of_ramification_idx_ne_zero Ideal.le_comap_of_ramificationIdx_ne_zero namespace IsDedekindDomain variable [IsDedekindDomain S] theorem ramificationIdx_eq_normalizedFactors_count (hp0 : map f p ≠ ⊥) (hP : P.IsPrime) (hP0 : P ≠ ⊥) : ramificationIdx f p P = (normalizedFactors (map f p)).count P := by have hPirr := (Ideal.prime_of_isPrime hP0 hP).irreducible refine ramificationIdx_spec (Ideal.le_of_dvd ?_) (mt Ideal.dvd_iff_le.mpr ?_) <;> rw [dvd_iff_normalizedFactors_le_normalizedFactors (pow_ne_zero _ hP0) hp0, normalizedFactors_pow, normalizedFactors_irreducible hPirr, normalize_eq, Multiset.nsmul_singleton, ← Multiset.le_count_iff_replicate_le] exact (Nat.lt_succ_self _).not_le #align ideal.is_dedekind_domain.ramification_idx_eq_normalized_factors_count Ideal.IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count theorem ramificationIdx_eq_factors_count (hp0 : map f p ≠ ⊥) (hP : P.IsPrime) (hP0 : P ≠ ⊥) : ramificationIdx f p P = (factors (map f p)).count P := by rw [IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count hp0 hP hP0, factors_eq_normalizedFactors] #align ideal.is_dedekind_domain.ramification_idx_eq_factors_count Ideal.IsDedekindDomain.ramificationIdx_eq_factors_count theorem ramificationIdx_ne_zero (hp0 : map f p ≠ ⊥) (hP : P.IsPrime) (le : map f p ≤ P) : ramificationIdx f p P ≠ 0 := by have hP0 : P ≠ ⊥ := by rintro rfl have := le_bot_iff.mp le contradiction have hPirr := (Ideal.prime_of_isPrime hP0 hP).irreducible rw [IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count hp0 hP hP0] obtain ⟨P', hP', P'_eq⟩ := exists_mem_normalizedFactors_of_dvd hp0 hPirr (Ideal.dvd_iff_le.mpr le) rwa [Multiset.count_ne_zero, associated_iff_eq.mp P'_eq] #align ideal.is_dedekind_domain.ramification_idx_ne_zero Ideal.IsDedekindDomain.ramificationIdx_ne_zero end IsDedekindDomain variable (f p P) attribute [local instance] Ideal.Quotient.field /-- The inertia degree of `P : Ideal S` lying over `p : Ideal R` is the degree of the extension `(S / P) : (R / p)`. We do not assume `P` lies over `p` in the definition; we return `0` instead. See `inertiaDeg_algebraMap` for the common case where `f = algebraMap R S` and there is an algebra structure `R / p → S / P`. -/ noncomputable def inertiaDeg [p.IsMaximal] : ℕ := if hPp : comap f P = p then @finrank (R ⧸ p) (S ⧸ P) _ _ <| @Algebra.toModule _ _ _ _ <| RingHom.toAlgebra <| Ideal.Quotient.lift p ((Ideal.Quotient.mk P).comp f) fun _ ha => Quotient.eq_zero_iff_mem.mpr <| mem_comap.mp <| hPp.symm ▸ ha else 0 #align ideal.inertia_deg Ideal.inertiaDeg -- Useful for the `nontriviality` tactic using `comap_eq_of_scalar_tower_quotient`. @[simp] theorem inertiaDeg_of_subsingleton [hp : p.IsMaximal] [hQ : Subsingleton (S ⧸ P)] : inertiaDeg f p P = 0 := by have := Ideal.Quotient.subsingleton_iff.mp hQ subst this exact dif_neg fun h => hp.ne_top <| h.symm.trans comap_top #align ideal.inertia_deg_of_subsingleton Ideal.inertiaDeg_of_subsingleton @[simp] theorem inertiaDeg_algebraMap [Algebra R S] [Algebra (R ⧸ p) (S ⧸ P)] [IsScalarTower R (R ⧸ p) (S ⧸ P)] [hp : p.IsMaximal] : inertiaDeg (algebraMap R S) p P = finrank (R ⧸ p) (S ⧸ P) := by nontriviality S ⧸ P using inertiaDeg_of_subsingleton, finrank_zero_of_subsingleton have := comap_eq_of_scalar_tower_quotient (algebraMap (R ⧸ p) (S ⧸ P)).injective rw [inertiaDeg, dif_pos this] congr refine Algebra.algebra_ext _ _ fun x' => Quotient.inductionOn' x' fun x => ?_ change Ideal.Quotient.lift p _ _ (Ideal.Quotient.mk p x) = algebraMap _ _ (Ideal.Quotient.mk p x) rw [Ideal.Quotient.lift_mk, ← Ideal.Quotient.algebraMap_eq P, ← IsScalarTower.algebraMap_eq, ← Ideal.Quotient.algebraMap_eq, ← IsScalarTower.algebraMap_apply] #align ideal.inertia_deg_algebra_map Ideal.inertiaDeg_algebraMap end DecEq section FinrankQuotientMap open scoped nonZeroDivisors variable [Algebra R S] variable {K : Type*} [Field K] [Algebra R K] [hRK : IsFractionRing R K] variable {L : Type*} [Field L] [Algebra S L] [IsFractionRing S L] variable {V V' V'' : Type*} variable [AddCommGroup V] [Module R V] [Module K V] [IsScalarTower R K V] variable [AddCommGroup V'] [Module R V'] [Module S V'] [IsScalarTower R S V'] variable [AddCommGroup V''] [Module R V''] variable (K) /-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`, is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`. The statement we prove is actually slightly more general: * it suffices that the inclusion `algebraMap R S : R → S` is nontrivial * the function `f' : V'' → V'` doesn't need to be injective -/ theorem FinrankQuotientMap.linearIndependent_of_nontrivial [IsDedekindDomain R] (hRS : RingHom.ker (algebraMap R S) ≠ ⊤) (f : V'' →ₗ[R] V) (hf : Function.Injective f) (f' : V'' →ₗ[R] V') {ι : Type*} {b : ι → V''} (hb' : LinearIndependent S (f' ∘ b)) : LinearIndependent K (f ∘ b) := by contrapose! hb' with hb -- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`, -- then we can find a linear dependence with coefficients `I.Quotient.mk g'` in `R/I`, -- where `I = ker (algebraMap R S)`. -- We make use of the same principle but stay in `R` everywhere. simp only [linearIndependent_iff', not_forall] at hb ⊢ obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb use s obtain ⟨a, hag, j, hjs, hgI⟩ := Ideal.exist_integer_multiples_not_mem hRS s g hj's hj'g choose g'' hg'' using hag letI := Classical.propDecidable let g' i := if h : i ∈ s then g'' i h else 0 have hg' : ∀ i ∈ s, algebraMap _ _ (g' i) = a * g i := by intro i hi; exact (congr_arg _ (dif_pos hi)).trans (hg'' i hi) -- Because `R/I` is nontrivial, we can lift `g` to a nontrivial linear dependence in `S`. have hgI : algebraMap R S (g' j) ≠ 0 := by simp only [FractionalIdeal.mem_coeIdeal, not_exists, not_and'] at hgI exact hgI _ (hg' j hjs) refine ⟨fun i => algebraMap R S (g' i), ?_, j, hjs, hgI⟩ have eq : f (∑ i ∈ s, g' i • b i) = 0 := by rw [map_sum, ← smul_zero a, ← eq, Finset.smul_sum] refine Finset.sum_congr rfl ?_ intro i hi rw [LinearMap.map_smul, ← IsScalarTower.algebraMap_smul K, hg' i hi, ← smul_assoc, smul_eq_mul, Function.comp_apply] simp only [IsScalarTower.algebraMap_smul, ← map_smul, ← map_sum, (f.map_eq_zero_iff hf).mp eq, LinearMap.map_zero, (· ∘ ·)] #align ideal.finrank_quotient_map.linear_independent_of_nontrivial Ideal.FinrankQuotientMap.linearIndependent_of_nontrivial open scoped Matrix variable {K} /-- If `b` mod `p` spans `S/p` as `R/p`-space, then `b` itself spans `Frac(S)` as `K`-space. Here, * `p` is an ideal of `R` such that `R / p` is nontrivial * `K` is a field that has an embedding of `R` (in particular we can take `K = Frac(R)`) * `L` is a field extension of `K` * `S` is the integral closure of `R` in `L` More precisely, we avoid quotients in this statement and instead require that `b ∪ pS` spans `S`. -/
Mathlib/NumberTheory/RamificationInertia.lean
289
382
theorem FinrankQuotientMap.span_eq_top [IsDomain R] [IsDomain S] [Algebra K L] [IsNoetherian R S] [Algebra R L] [IsScalarTower R S L] [IsScalarTower R K L] [IsIntegralClosure S R L] [NoZeroSMulDivisors R K] (hp : p ≠ ⊤) (b : Set S) (hb' : Submodule.span R b ⊔ (p.map (algebraMap R S)).restrictScalars R = ⊤) : Submodule.span K (algebraMap S L '' b) = ⊤ := by
have hRL : Function.Injective (algebraMap R L) := by rw [IsScalarTower.algebraMap_eq R K L] exact (algebraMap K L).injective.comp (NoZeroSMulDivisors.algebraMap_injective R K) -- Let `M` be the `R`-module spanned by the proposed basis elements. let M : Submodule R S := Submodule.span R b -- Then `S / M` is generated by some finite set of `n` vectors `a`. letI h : Module.Finite R (S ⧸ M) := Module.Finite.of_surjective (Submodule.mkQ _) (Submodule.Quotient.mk_surjective _) obtain ⟨n, a, ha⟩ := @Module.Finite.exists_fin _ _ _ _ _ h -- Because the image of `p` in `S / M` is `⊤`, have smul_top_eq : p • (⊤ : Submodule R (S ⧸ M)) = ⊤ := by calc p • ⊤ = Submodule.map M.mkQ (p • ⊤) := by rw [Submodule.map_smul'', Submodule.map_top, M.range_mkQ] _ = ⊤ := by rw [Ideal.smul_top_eq_map, (Submodule.map_mkQ_eq_top M _).mpr hb'] -- we can write the elements of `a` as `p`-linear combinations of other elements of `a`. have exists_sum : ∀ x : S ⧸ M, ∃ a' : Fin n → R, (∀ i, a' i ∈ p) ∧ ∑ i, a' i • a i = x := by intro x obtain ⟨a'', ha'', hx⟩ := (Submodule.mem_ideal_smul_span_iff_exists_sum p a x).1 (by { rw [ha, smul_top_eq]; exact Submodule.mem_top } : x ∈ p • Submodule.span R (Set.range a)) · refine ⟨fun i => a'' i, fun i => ha'' _, ?_⟩ rw [← hx, Finsupp.sum_fintype] exact fun _ => zero_smul _ _ choose A' hA'p hA' using fun i => exists_sum (a i) -- This gives us a(n invertible) matrix `A` such that `det A ∈ (M = span R b)`, let A : Matrix (Fin n) (Fin n) R := Matrix.of A' - 1 let B := A.adjugate have A_smul : ∀ i, ∑ j, A i j • a j = 0 := by intros simp [A, Matrix.sub_apply, Matrix.of_apply, ne_eq, Matrix.one_apply, sub_smul, Finset.sum_sub_distrib, hA', sub_self] -- since `span S {det A} / M = 0`. have d_smul : ∀ i, A.det • a i = 0 := by intro i calc A.det • a i = ∑ j, (B * A) i j • a j := ?_ _ = ∑ k, B i k • ∑ j, A k j • a j := ?_ _ = 0 := Finset.sum_eq_zero fun k _ => ?_ · simp only [B, Matrix.adjugate_mul, Matrix.smul_apply, Matrix.one_apply, smul_eq_mul, ite_true, mul_ite, mul_one, mul_zero, ite_smul, zero_smul, Finset.sum_ite_eq, Finset.mem_univ] · simp only [Matrix.mul_apply, Finset.smul_sum, Finset.sum_smul, smul_smul] rw [Finset.sum_comm] · rw [A_smul, smul_zero] -- In the rings of integers we have the desired inclusion. have span_d : (Submodule.span S ({algebraMap R S A.det} : Set S)).restrictScalars R ≤ M := by intro x hx rw [Submodule.restrictScalars_mem] at hx obtain ⟨x', rfl⟩ := Submodule.mem_span_singleton.mp hx rw [smul_eq_mul, mul_comm, ← Algebra.smul_def] at hx ⊢ rw [← Submodule.Quotient.mk_eq_zero, Submodule.Quotient.mk_smul] obtain ⟨a', _, quot_x_eq⟩ := exists_sum (Submodule.Quotient.mk x') rw [← quot_x_eq, Finset.smul_sum] conv => lhs; congr; next => skip intro x; rw [smul_comm A.det, d_smul, smul_zero] exact Finset.sum_const_zero refine top_le_iff.mp (calc ⊤ = (Ideal.span {algebraMap R L A.det}).restrictScalars K := ?_ _ ≤ Submodule.span K (algebraMap S L '' b) := ?_) -- Because `det A ≠ 0`, we have `span L {det A} = ⊤`. · rw [eq_comm, Submodule.restrictScalars_eq_top_iff, Ideal.span_singleton_eq_top] refine IsUnit.mk0 _ ((map_ne_zero_iff (algebraMap R L) hRL).mpr ?_) refine ne_zero_of_map (f := Ideal.Quotient.mk p) ?_ haveI := Ideal.Quotient.nontrivial hp calc Ideal.Quotient.mk p A.det = Matrix.det ((Ideal.Quotient.mk p).mapMatrix A) := by rw [RingHom.map_det] _ = Matrix.det ((Ideal.Quotient.mk p).mapMatrix (Matrix.of A' - 1)) := rfl _ = Matrix.det fun i j => (Ideal.Quotient.mk p) (A' i j) - (1 : Matrix (Fin n) (Fin n) (R ⧸ p)) i j := ?_ _ = Matrix.det (-1 : Matrix (Fin n) (Fin n) (R ⧸ p)) := ?_ _ = (-1 : R ⧸ p) ^ n := by rw [Matrix.det_neg, Fintype.card_fin, Matrix.det_one, mul_one] _ ≠ 0 := IsUnit.ne_zero (isUnit_one.neg.pow _) · refine congr_arg Matrix.det (Matrix.ext fun i j => ?_) rw [map_sub, RingHom.mapMatrix_apply, map_one] rfl · refine congr_arg Matrix.det (Matrix.ext fun i j => ?_) rw [Ideal.Quotient.eq_zero_iff_mem.mpr (hA'p i j), zero_sub] rfl -- And we conclude `L = span L {det A} ≤ span K b`, so `span K b` spans everything. · intro x hx rw [Submodule.restrictScalars_mem, IsScalarTower.algebraMap_apply R S L] at hx have : Algebra.IsAlgebraic R L := by have : NoZeroSMulDivisors R L := NoZeroSMulDivisors.of_algebraMap_injective hRL rw [← IsFractionRing.isAlgebraic_iff' R S] infer_instance refine IsFractionRing.ideal_span_singleton_map_subset R hRL span_d hx
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Geometry.Euclidean.Circumcenter #align_import geometry.euclidean.monge_point from "leanprover-community/mathlib"@"1a4df69ca1a9a0e5e26bfe12e2b92814216016d0" /-! # Monge point and orthocenter This file defines the orthocenter of a triangle, via its n-dimensional generalization, the Monge point of a simplex. ## Main definitions * `mongePoint` is the Monge point of a simplex, defined in terms of its position on the Euler line and then shown to be the point of concurrence of the Monge planes. * `mongePlane` is a Monge plane of an (n+2)-simplex, which is the (n+1)-dimensional affine subspace of the subspace spanned by the simplex that passes through the centroid of an n-dimensional face and is orthogonal to the opposite edge (in 2 dimensions, this is the same as an altitude). * `altitude` is the line that passes through a vertex of a simplex and is orthogonal to the opposite face. * `orthocenter` is defined, for the case of a triangle, to be the same as its Monge point, then shown to be the point of concurrence of the altitudes. * `OrthocentricSystem` is a predicate on sets of points that says whether they are four points, one of which is the orthocenter of the other three (in which case various other properties hold, including that each is the orthocenter of the other three). ## References * <https://en.wikipedia.org/wiki/Altitude_(triangle)> * <https://en.wikipedia.org/wiki/Monge_point> * <https://en.wikipedia.org/wiki/Orthocentric_system> * Małgorzata Buba-Brzozowa, [The Monge Point and the 3(n+1) Point Sphere of an n-Simplex](https://pdfs.semanticscholar.org/6f8b/0f623459c76dac2e49255737f8f0f4725d16.pdf) -/ noncomputable section open scoped Classical open scoped RealInnerProductSpace namespace Affine namespace Simplex open Finset AffineSubspace EuclideanGeometry PointsWithCircumcenterIndex variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The Monge point of a simplex (in 2 or more dimensions) is a generalization of the orthocenter of a triangle. It is defined to be the intersection of the Monge planes, where a Monge plane is the (n-1)-dimensional affine subspace of the subspace spanned by the simplex that passes through the centroid of an (n-2)-dimensional face and is orthogonal to the opposite edge (in 2 dimensions, this is the same as an altitude). The circumcenter O, centroid G and Monge point M are collinear in that order on the Euler line, with OG : GM = (n-1): 2. Here, we use that ratio to define the Monge point (so resulting in a point that equals the centroid in 0 or 1 dimensions), and then show in subsequent lemmas that the point so defined lies in the Monge planes and is their unique point of intersection. -/ def mongePoint {n : ℕ} (s : Simplex ℝ P n) : P := (((n + 1 : ℕ) : ℝ) / ((n - 1 : ℕ) : ℝ)) • ((univ : Finset (Fin (n + 1))).centroid ℝ s.points -ᵥ s.circumcenter) +ᵥ s.circumcenter #align affine.simplex.monge_point Affine.Simplex.mongePoint /-- The position of the Monge point in relation to the circumcenter and centroid. -/ theorem mongePoint_eq_smul_vsub_vadd_circumcenter {n : ℕ} (s : Simplex ℝ P n) : s.mongePoint = (((n + 1 : ℕ) : ℝ) / ((n - 1 : ℕ) : ℝ)) • ((univ : Finset (Fin (n + 1))).centroid ℝ s.points -ᵥ s.circumcenter) +ᵥ s.circumcenter := rfl #align affine.simplex.monge_point_eq_smul_vsub_vadd_circumcenter Affine.Simplex.mongePoint_eq_smul_vsub_vadd_circumcenter /-- The Monge point lies in the affine span. -/ theorem mongePoint_mem_affineSpan {n : ℕ} (s : Simplex ℝ P n) : s.mongePoint ∈ affineSpan ℝ (Set.range s.points) := smul_vsub_vadd_mem _ _ (centroid_mem_affineSpan_of_card_eq_add_one ℝ _ (card_fin (n + 1))) s.circumcenter_mem_affineSpan s.circumcenter_mem_affineSpan #align affine.simplex.monge_point_mem_affine_span Affine.Simplex.mongePoint_mem_affineSpan /-- Two simplices with the same points have the same Monge point. -/ theorem mongePoint_eq_of_range_eq {n : ℕ} {s₁ s₂ : Simplex ℝ P n} (h : Set.range s₁.points = Set.range s₂.points) : s₁.mongePoint = s₂.mongePoint := by simp_rw [mongePoint_eq_smul_vsub_vadd_circumcenter, centroid_eq_of_range_eq h, circumcenter_eq_of_range_eq h] #align affine.simplex.monge_point_eq_of_range_eq Affine.Simplex.mongePoint_eq_of_range_eq /-- The weights for the Monge point of an (n+2)-simplex, in terms of `pointsWithCircumcenter`. -/ def mongePointWeightsWithCircumcenter (n : ℕ) : PointsWithCircumcenterIndex (n + 2) → ℝ | pointIndex _ => ((n + 1 : ℕ) : ℝ)⁻¹ | circumcenterIndex => -2 / ((n + 1 : ℕ) : ℝ) #align affine.simplex.monge_point_weights_with_circumcenter Affine.Simplex.mongePointWeightsWithCircumcenter /-- `mongePointWeightsWithCircumcenter` sums to 1. -/ @[simp] theorem sum_mongePointWeightsWithCircumcenter (n : ℕ) : ∑ i, mongePointWeightsWithCircumcenter n i = 1 := by simp_rw [sum_pointsWithCircumcenter, mongePointWeightsWithCircumcenter, sum_const, card_fin, nsmul_eq_mul] -- Porting note: replaced -- have hn1 : (n + 1 : ℝ) ≠ 0 := mod_cast Nat.succ_ne_zero _ field_simp [n.cast_add_one_ne_zero] ring #align affine.simplex.sum_monge_point_weights_with_circumcenter Affine.Simplex.sum_mongePointWeightsWithCircumcenter /-- The Monge point of an (n+2)-simplex, in terms of `pointsWithCircumcenter`. -/ theorem mongePoint_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P (n + 2)) : s.mongePoint = (univ : Finset (PointsWithCircumcenterIndex (n + 2))).affineCombination ℝ s.pointsWithCircumcenter (mongePointWeightsWithCircumcenter n) := by rw [mongePoint_eq_smul_vsub_vadd_circumcenter, centroid_eq_affineCombination_of_pointsWithCircumcenter, circumcenter_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub, ← LinearMap.map_smul, weightedVSub_vadd_affineCombination] congr with i rw [Pi.add_apply, Pi.smul_apply, smul_eq_mul, Pi.sub_apply] -- Porting note: replaced -- have hn1 : (n + 1 : ℝ) ≠ 0 := mod_cast Nat.succ_ne_zero _ have hn1 : (n + 1 : ℝ) ≠ 0 := n.cast_add_one_ne_zero cases i <;> simp_rw [centroidWeightsWithCircumcenter, circumcenterWeightsWithCircumcenter, mongePointWeightsWithCircumcenter] <;> rw [add_tsub_assoc_of_le (by decide : 1 ≤ 2), (by decide : 2 - 1 = 1)] · rw [if_pos (mem_univ _), sub_zero, add_zero, card_fin] -- Porting note: replaced -- have hn3 : (n + 2 + 1 : ℝ) ≠ 0 := mod_cast Nat.succ_ne_zero _ have hn3 : (n + 2 + 1 : ℝ) ≠ 0 := by norm_cast field_simp [hn1, hn3, mul_comm] · field_simp [hn1] ring #align affine.simplex.monge_point_eq_affine_combination_of_points_with_circumcenter Affine.Simplex.mongePoint_eq_affineCombination_of_pointsWithCircumcenter /-- The weights for the Monge point of an (n+2)-simplex, minus the centroid of an n-dimensional face, in terms of `pointsWithCircumcenter`. This definition is only valid when `i₁ ≠ i₂`. -/ def mongePointVSubFaceCentroidWeightsWithCircumcenter {n : ℕ} (i₁ i₂ : Fin (n + 3)) : PointsWithCircumcenterIndex (n + 2) → ℝ | pointIndex i => if i = i₁ ∨ i = i₂ then ((n + 1 : ℕ) : ℝ)⁻¹ else 0 | circumcenterIndex => -2 / ((n + 1 : ℕ) : ℝ) #align affine.simplex.monge_point_vsub_face_centroid_weights_with_circumcenter Affine.Simplex.mongePointVSubFaceCentroidWeightsWithCircumcenter /-- `mongePointVSubFaceCentroidWeightsWithCircumcenter` is the result of subtracting `centroidWeightsWithCircumcenter` from `mongePointWeightsWithCircumcenter`. -/ theorem mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub {n : ℕ} {i₁ i₂ : Fin (n + 3)} (h : i₁ ≠ i₂) : mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂ = mongePointWeightsWithCircumcenter n - centroidWeightsWithCircumcenter {i₁, i₂}ᶜ := by ext i cases' i with i · rw [Pi.sub_apply, mongePointWeightsWithCircumcenter, centroidWeightsWithCircumcenter, mongePointVSubFaceCentroidWeightsWithCircumcenter] have hu : card ({i₁, i₂}ᶜ : Finset (Fin (n + 3))) = n + 1 := by simp [card_compl, Fintype.card_fin, h] rw [hu] by_cases hi : i = i₁ ∨ i = i₂ <;> simp [compl_eq_univ_sdiff, hi] · simp [mongePointWeightsWithCircumcenter, centroidWeightsWithCircumcenter, mongePointVSubFaceCentroidWeightsWithCircumcenter] #align affine.simplex.monge_point_vsub_face_centroid_weights_with_circumcenter_eq_sub Affine.Simplex.mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub /-- `mongePointVSubFaceCentroidWeightsWithCircumcenter` sums to 0. -/ @[simp] theorem sum_mongePointVSubFaceCentroidWeightsWithCircumcenter {n : ℕ} {i₁ i₂ : Fin (n + 3)} (h : i₁ ≠ i₂) : ∑ i, mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂ i = 0 := by rw [mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub h] simp_rw [Pi.sub_apply, sum_sub_distrib, sum_mongePointWeightsWithCircumcenter] rw [sum_centroidWeightsWithCircumcenter, sub_self] simp [← card_pos, card_compl, h] #align affine.simplex.sum_monge_point_vsub_face_centroid_weights_with_circumcenter Affine.Simplex.sum_mongePointVSubFaceCentroidWeightsWithCircumcenter /-- The Monge point of an (n+2)-simplex, minus the centroid of an n-dimensional face, in terms of `pointsWithCircumcenter`. -/ theorem mongePoint_vsub_face_centroid_eq_weightedVSub_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} (h : i₁ ≠ i₂) : s.mongePoint -ᵥ ({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points = (univ : Finset (PointsWithCircumcenterIndex (n + 2))).weightedVSub s.pointsWithCircumcenter (mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂) := by simp_rw [mongePoint_eq_affineCombination_of_pointsWithCircumcenter, centroid_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub, mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub h] #align affine.simplex.monge_point_vsub_face_centroid_eq_weighted_vsub_of_points_with_circumcenter Affine.Simplex.mongePoint_vsub_face_centroid_eq_weightedVSub_of_pointsWithCircumcenter /-- The Monge point of an (n+2)-simplex, minus the centroid of an n-dimensional face, is orthogonal to the difference of the two vertices not in that face. -/ theorem inner_mongePoint_vsub_face_centroid_vsub {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} : ⟪s.mongePoint -ᵥ ({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points, s.points i₁ -ᵥ s.points i₂⟫ = 0 := by by_cases h : i₁ = i₂ · simp [h] simp_rw [mongePoint_vsub_face_centroid_eq_weightedVSub_of_pointsWithCircumcenter s h, point_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub] have hs : ∑ i, (pointWeightsWithCircumcenter i₁ - pointWeightsWithCircumcenter i₂) i = 0 := by simp rw [inner_weightedVSub _ (sum_mongePointVSubFaceCentroidWeightsWithCircumcenter h) _ hs, sum_pointsWithCircumcenter, pointsWithCircumcenter_eq_circumcenter] simp only [mongePointVSubFaceCentroidWeightsWithCircumcenter, pointsWithCircumcenter_point] let fs : Finset (Fin (n + 3)) := {i₁, i₂} have hfs : ∀ i : Fin (n + 3), i ∉ fs → i ≠ i₁ ∧ i ≠ i₂ := by intro i hi constructor <;> · intro hj; simp [fs, ← hj] at hi rw [← sum_subset fs.subset_univ _] · simp_rw [sum_pointsWithCircumcenter, pointsWithCircumcenter_eq_circumcenter, pointsWithCircumcenter_point, Pi.sub_apply, pointWeightsWithCircumcenter] rw [← sum_subset fs.subset_univ _] · simp_rw [sum_insert (not_mem_singleton.2 h), sum_singleton] repeat rw [← sum_subset fs.subset_univ _] · simp_rw [sum_insert (not_mem_singleton.2 h), sum_singleton] simp [h, Ne.symm h, dist_comm (s.points i₁)] all_goals intro i _ hi; simp [hfs i hi] · intro i _ hi simp [hfs i hi, pointsWithCircumcenter] · intro i _ hi simp [hfs i hi] #align affine.simplex.inner_monge_point_vsub_face_centroid_vsub Affine.Simplex.inner_mongePoint_vsub_face_centroid_vsub /-- A Monge plane of an (n+2)-simplex is the (n+1)-dimensional affine subspace of the subspace spanned by the simplex that passes through the centroid of an n-dimensional face and is orthogonal to the opposite edge (in 2 dimensions, this is the same as an altitude). This definition is only intended to be used when `i₁ ≠ i₂`. -/ def mongePlane {n : ℕ} (s : Simplex ℝ P (n + 2)) (i₁ i₂ : Fin (n + 3)) : AffineSubspace ℝ P := mk' (({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points) (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ affineSpan ℝ (Set.range s.points) #align affine.simplex.monge_plane Affine.Simplex.mongePlane /-- The definition of a Monge plane. -/ theorem mongePlane_def {n : ℕ} (s : Simplex ℝ P (n + 2)) (i₁ i₂ : Fin (n + 3)) : s.mongePlane i₁ i₂ = mk' (({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points) (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ affineSpan ℝ (Set.range s.points) := rfl #align affine.simplex.monge_plane_def Affine.Simplex.mongePlane_def /-- The Monge plane associated with vertices `i₁` and `i₂` equals that associated with `i₂` and `i₁`. -/ theorem mongePlane_comm {n : ℕ} (s : Simplex ℝ P (n + 2)) (i₁ i₂ : Fin (n + 3)) : s.mongePlane i₁ i₂ = s.mongePlane i₂ i₁ := by simp_rw [mongePlane_def] congr 3 · congr 1 exact pair_comm _ _ · ext simp_rw [Submodule.mem_span_singleton] constructor all_goals rintro ⟨r, rfl⟩; use -r; rw [neg_smul, ← smul_neg, neg_vsub_eq_vsub_rev] #align affine.simplex.monge_plane_comm Affine.Simplex.mongePlane_comm /-- The Monge point lies in the Monge planes. -/ theorem mongePoint_mem_mongePlane {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} : s.mongePoint ∈ s.mongePlane i₁ i₂ := by rw [mongePlane_def, mem_inf_iff, ← vsub_right_mem_direction_iff_mem (self_mem_mk' _ _), direction_mk', Submodule.mem_orthogonal'] refine ⟨?_, s.mongePoint_mem_affineSpan⟩ intro v hv rcases Submodule.mem_span_singleton.mp hv with ⟨r, rfl⟩ rw [inner_smul_right, s.inner_mongePoint_vsub_face_centroid_vsub, mul_zero] #align affine.simplex.monge_point_mem_monge_plane Affine.Simplex.mongePoint_mem_mongePlane /-- The direction of a Monge plane. -/ theorem direction_mongePlane {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} : (s.mongePlane i₁ i₂).direction = (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ vectorSpan ℝ (Set.range s.points) := by rw [mongePlane_def, direction_inf_of_mem_inf s.mongePoint_mem_mongePlane, direction_mk', direction_affineSpan] #align affine.simplex.direction_monge_plane Affine.Simplex.direction_mongePlane /-- The Monge point is the only point in all the Monge planes from any one vertex. -/ theorem eq_mongePoint_of_forall_mem_mongePlane {n : ℕ} {s : Simplex ℝ P (n + 2)} {i₁ : Fin (n + 3)} {p : P} (h : ∀ i₂, i₁ ≠ i₂ → p ∈ s.mongePlane i₁ i₂) : p = s.mongePoint := by rw [← @vsub_eq_zero_iff_eq V] have h' : ∀ i₂, i₁ ≠ i₂ → p -ᵥ s.mongePoint ∈ (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ vectorSpan ℝ (Set.range s.points) := by intro i₂ hne rw [← s.direction_mongePlane, vsub_right_mem_direction_iff_mem s.mongePoint_mem_mongePlane] exact h i₂ hne have hi : p -ᵥ s.mongePoint ∈ ⨅ i₂ : { i // i₁ ≠ i }, (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ := by rw [Submodule.mem_iInf] exact fun i => (Submodule.mem_inf.1 (h' i i.property)).1 rw [Submodule.iInf_orthogonal, ← Submodule.span_iUnion] at hi have hu : ⋃ i : { i // i₁ ≠ i }, ({s.points i₁ -ᵥ s.points i} : Set V) = (s.points i₁ -ᵥ ·) '' (s.points '' (Set.univ \ {i₁})) := by rw [Set.image_image] ext x simp_rw [Set.mem_iUnion, Set.mem_image, Set.mem_singleton_iff, Set.mem_diff_singleton] constructor · rintro ⟨i, rfl⟩ use i, ⟨Set.mem_univ _, i.property.symm⟩ · rintro ⟨i, ⟨-, hi⟩, rfl⟩ -- Porting note: was `use ⟨i, hi.symm⟩, rfl` exact ⟨⟨i, hi.symm⟩, rfl⟩ rw [hu, ← vectorSpan_image_eq_span_vsub_set_left_ne ℝ _ (Set.mem_univ _), Set.image_univ] at hi have hv : p -ᵥ s.mongePoint ∈ vectorSpan ℝ (Set.range s.points) := by let s₁ : Finset (Fin (n + 3)) := univ.erase i₁ obtain ⟨i₂, h₂⟩ := card_pos.1 (show 0 < card s₁ by simp [s₁, card_erase_of_mem]) have h₁₂ : i₁ ≠ i₂ := (ne_of_mem_erase h₂).symm exact (Submodule.mem_inf.1 (h' i₂ h₁₂)).2 exact Submodule.disjoint_def.1 (vectorSpan ℝ (Set.range s.points)).orthogonal_disjoint _ hv hi #align affine.simplex.eq_monge_point_of_forall_mem_monge_plane Affine.Simplex.eq_mongePoint_of_forall_mem_mongePlane /-- An altitude of a simplex is the line that passes through a vertex and is orthogonal to the opposite face. -/ def altitude {n : ℕ} (s : Simplex ℝ P (n + 1)) (i : Fin (n + 2)) : AffineSubspace ℝ P := mk' (s.points i) (affineSpan ℝ (s.points '' ↑(univ.erase i))).directionᗮ ⊓ affineSpan ℝ (Set.range s.points) #align affine.simplex.altitude Affine.Simplex.altitude /-- The definition of an altitude. -/ theorem altitude_def {n : ℕ} (s : Simplex ℝ P (n + 1)) (i : Fin (n + 2)) : s.altitude i = mk' (s.points i) (affineSpan ℝ (s.points '' ↑(univ.erase i))).directionᗮ ⊓ affineSpan ℝ (Set.range s.points) := rfl #align affine.simplex.altitude_def Affine.Simplex.altitude_def /-- A vertex lies in the corresponding altitude. -/ theorem mem_altitude {n : ℕ} (s : Simplex ℝ P (n + 1)) (i : Fin (n + 2)) : s.points i ∈ s.altitude i := (mem_inf_iff _ _ _).2 ⟨self_mem_mk' _ _, mem_affineSpan ℝ (Set.mem_range_self _)⟩ #align affine.simplex.mem_altitude Affine.Simplex.mem_altitude /-- The direction of an altitude. -/ theorem direction_altitude {n : ℕ} (s : Simplex ℝ P (n + 1)) (i : Fin (n + 2)) : (s.altitude i).direction = (vectorSpan ℝ (s.points '' ↑(Finset.univ.erase i)))ᗮ ⊓ vectorSpan ℝ (Set.range s.points) := by rw [altitude_def, direction_inf_of_mem (self_mem_mk' (s.points i) _) (mem_affineSpan ℝ (Set.mem_range_self _)), direction_mk', direction_affineSpan, direction_affineSpan] #align affine.simplex.direction_altitude Affine.Simplex.direction_altitude /-- The vector span of the opposite face lies in the direction orthogonal to an altitude. -/ theorem vectorSpan_isOrtho_altitude_direction {n : ℕ} (s : Simplex ℝ P (n + 1)) (i : Fin (n + 2)) : vectorSpan ℝ (s.points '' ↑(Finset.univ.erase i)) ⟂ (s.altitude i).direction := by rw [direction_altitude] exact (Submodule.isOrtho_orthogonal_right _).mono_right inf_le_left #align affine.simplex.vector_span_is_ortho_altitude_direction Affine.Simplex.vectorSpan_isOrtho_altitude_direction open FiniteDimensional /-- An altitude is finite-dimensional. -/ instance finiteDimensional_direction_altitude {n : ℕ} (s : Simplex ℝ P (n + 1)) (i : Fin (n + 2)) : FiniteDimensional ℝ (s.altitude i).direction := by rw [direction_altitude] infer_instance #align affine.simplex.finite_dimensional_direction_altitude Affine.Simplex.finiteDimensional_direction_altitude /-- An altitude is one-dimensional (i.e., a line). -/ @[simp] theorem finrank_direction_altitude {n : ℕ} (s : Simplex ℝ P (n + 1)) (i : Fin (n + 2)) : finrank ℝ (s.altitude i).direction = 1 := by rw [direction_altitude] have h := Submodule.finrank_add_inf_finrank_orthogonal (vectorSpan_mono ℝ (Set.image_subset_range s.points ↑(univ.erase i))) have hc : card (univ.erase i) = n + 1 := by rw [card_erase_of_mem (mem_univ _)]; simp refine add_left_cancel (_root_.trans h ?_) rw [s.independent.finrank_vectorSpan (Fintype.card_fin _), ← Finset.coe_image, s.independent.finrank_vectorSpan_image_finset hc] #align affine.simplex.finrank_direction_altitude Affine.Simplex.finrank_direction_altitude /-- A line through a vertex is the altitude through that vertex if and only if it is orthogonal to the opposite face. -/ theorem affineSpan_pair_eq_altitude_iff {n : ℕ} (s : Simplex ℝ P (n + 1)) (i : Fin (n + 2)) (p : P) : line[ℝ, p, s.points i] = s.altitude i ↔ p ≠ s.points i ∧ p ∈ affineSpan ℝ (Set.range s.points) ∧ p -ᵥ s.points i ∈ (affineSpan ℝ (s.points '' ↑(Finset.univ.erase i))).directionᗮ := by rw [eq_iff_direction_eq_of_mem (mem_affineSpan ℝ (Set.mem_insert_of_mem _ (Set.mem_singleton _))) (s.mem_altitude _), ← vsub_right_mem_direction_iff_mem (mem_affineSpan ℝ (Set.mem_range_self i)) p, direction_affineSpan, direction_affineSpan, direction_affineSpan] constructor · intro h constructor · intro heq rw [heq, Set.pair_eq_singleton, vectorSpan_singleton] at h have hd : finrank ℝ (s.altitude i).direction = 0 := by rw [← h, finrank_bot] simp at hd · rw [← Submodule.mem_inf, _root_.inf_comm, ← direction_altitude, ← h] exact vsub_mem_vectorSpan ℝ (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_singleton _)) · rintro ⟨hne, h⟩ rw [← Submodule.mem_inf, _root_.inf_comm, ← direction_altitude] at h rw [vectorSpan_eq_span_vsub_set_left_ne ℝ (Set.mem_insert _ _), Set.insert_diff_of_mem _ (Set.mem_singleton _), Set.diff_singleton_eq_self fun h => hne (Set.mem_singleton_iff.1 h), Set.image_singleton] refine eq_of_le_of_finrank_eq ?_ ?_ · rw [Submodule.span_le] simpa using h · rw [finrank_direction_altitude, finrank_span_set_eq_card] · simp · refine linearIndependent_singleton ?_ simpa using hne #align affine.simplex.affine_span_pair_eq_altitude_iff Affine.Simplex.affineSpan_pair_eq_altitude_iff end Simplex namespace Triangle open EuclideanGeometry Finset Simplex AffineSubspace FiniteDimensional variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The orthocenter of a triangle is the intersection of its altitudes. It is defined here as the 2-dimensional case of the Monge point. -/ def orthocenter (t : Triangle ℝ P) : P := t.mongePoint #align affine.triangle.orthocenter Affine.Triangle.orthocenter /-- The orthocenter equals the Monge point. -/ theorem orthocenter_eq_mongePoint (t : Triangle ℝ P) : t.orthocenter = t.mongePoint := rfl #align affine.triangle.orthocenter_eq_monge_point Affine.Triangle.orthocenter_eq_mongePoint /-- The position of the orthocenter in relation to the circumcenter and centroid. -/ theorem orthocenter_eq_smul_vsub_vadd_circumcenter (t : Triangle ℝ P) : t.orthocenter = (3 : ℝ) • ((univ : Finset (Fin 3)).centroid ℝ t.points -ᵥ t.circumcenter : V) +ᵥ t.circumcenter := by rw [orthocenter_eq_mongePoint, mongePoint_eq_smul_vsub_vadd_circumcenter] norm_num #align affine.triangle.orthocenter_eq_smul_vsub_vadd_circumcenter Affine.Triangle.orthocenter_eq_smul_vsub_vadd_circumcenter /-- The orthocenter lies in the affine span. -/ theorem orthocenter_mem_affineSpan (t : Triangle ℝ P) : t.orthocenter ∈ affineSpan ℝ (Set.range t.points) := t.mongePoint_mem_affineSpan #align affine.triangle.orthocenter_mem_affine_span Affine.Triangle.orthocenter_mem_affineSpan /-- Two triangles with the same points have the same orthocenter. -/ theorem orthocenter_eq_of_range_eq {t₁ t₂ : Triangle ℝ P} (h : Set.range t₁.points = Set.range t₂.points) : t₁.orthocenter = t₂.orthocenter := mongePoint_eq_of_range_eq h #align affine.triangle.orthocenter_eq_of_range_eq Affine.Triangle.orthocenter_eq_of_range_eq /-- In the case of a triangle, altitudes are the same thing as Monge planes. -/ theorem altitude_eq_mongePlane (t : Triangle ℝ P) {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : t.altitude i₁ = t.mongePlane i₂ i₃ := by have hs : ({i₂, i₃}ᶜ : Finset (Fin 3)) = {i₁} := by -- Porting note (#11043): was `decide!` fin_cases i₁ <;> fin_cases i₂ <;> fin_cases i₃ <;> simp (config := {decide := true}) at h₁₂ h₁₃ h₂₃ ⊢ have he : univ.erase i₁ = {i₂, i₃} := by -- Porting note (#11043): was `decide!` fin_cases i₁ <;> fin_cases i₂ <;> fin_cases i₃ <;> simp (config := {decide := true}) at h₁₂ h₁₃ h₂₃ ⊢ rw [mongePlane_def, altitude_def, direction_affineSpan, hs, he, centroid_singleton, coe_insert, coe_singleton, vectorSpan_image_eq_span_vsub_set_left_ne ℝ _ (Set.mem_insert i₂ _)] simp [h₂₃, Submodule.span_insert_eq_span] #align affine.triangle.altitude_eq_monge_plane Affine.Triangle.altitude_eq_mongePlane /-- The orthocenter lies in the altitudes. -/ theorem orthocenter_mem_altitude (t : Triangle ℝ P) {i₁ : Fin 3} : t.orthocenter ∈ t.altitude i₁ := by obtain ⟨i₂, i₃, h₁₂, h₂₃, h₁₃⟩ : ∃ i₂ i₃, i₁ ≠ i₂ ∧ i₂ ≠ i₃ ∧ i₁ ≠ i₃ := by -- Porting note (#11043): was `decide!` fin_cases i₁ <;> decide rw [orthocenter_eq_mongePoint, t.altitude_eq_mongePlane h₁₂ h₁₃ h₂₃] exact t.mongePoint_mem_mongePlane #align affine.triangle.orthocenter_mem_altitude Affine.Triangle.orthocenter_mem_altitude /-- The orthocenter is the only point lying in any two of the altitudes. -/ theorem eq_orthocenter_of_forall_mem_altitude {t : Triangle ℝ P} {i₁ i₂ : Fin 3} {p : P} (h₁₂ : i₁ ≠ i₂) (h₁ : p ∈ t.altitude i₁) (h₂ : p ∈ t.altitude i₂) : p = t.orthocenter := by obtain ⟨i₃, h₂₃, h₁₃⟩ : ∃ i₃, i₂ ≠ i₃ ∧ i₁ ≠ i₃ := by clear h₁ h₂ -- Porting note (#11043): was `decide!` fin_cases i₁ <;> fin_cases i₂ <;> decide rw [t.altitude_eq_mongePlane h₁₃ h₁₂ h₂₃.symm] at h₁ rw [t.altitude_eq_mongePlane h₂₃ h₁₂.symm h₁₃.symm] at h₂ rw [orthocenter_eq_mongePoint] have ha : ∀ i, i₃ ≠ i → p ∈ t.mongePlane i₃ i := by intro i hi have hi₁₂ : i₁ = i ∨ i₂ = i := by clear h₁ h₂ -- Porting note (#11043): was `decide!` fin_cases i₁ <;> fin_cases i₂ <;> fin_cases i₃ <;> fin_cases i <;> simp at h₁₂ h₁₃ h₂₃ hi ⊢ cases' hi₁₂ with hi₁₂ hi₁₂ · exact hi₁₂ ▸ h₂ · exact hi₁₂ ▸ h₁ exact eq_mongePoint_of_forall_mem_mongePlane ha #align affine.triangle.eq_orthocenter_of_forall_mem_altitude Affine.Triangle.eq_orthocenter_of_forall_mem_altitude /-- The distance from the orthocenter to the reflection of the circumcenter in a side equals the circumradius. -/ theorem dist_orthocenter_reflection_circumcenter (t : Triangle ℝ P) {i₁ i₂ : Fin 3} (h : i₁ ≠ i₂) : dist t.orthocenter (reflection (affineSpan ℝ (t.points '' {i₁, i₂})) t.circumcenter) = t.circumradius := by rw [← mul_self_inj_of_nonneg dist_nonneg t.circumradius_nonneg, t.reflection_circumcenter_eq_affineCombination_of_pointsWithCircumcenter h, t.orthocenter_eq_mongePoint, mongePoint_eq_affineCombination_of_pointsWithCircumcenter, dist_affineCombination t.pointsWithCircumcenter (sum_mongePointWeightsWithCircumcenter _) (sum_reflectionCircumcenterWeightsWithCircumcenter h)] simp_rw [sum_pointsWithCircumcenter, Pi.sub_apply, mongePointWeightsWithCircumcenter, reflectionCircumcenterWeightsWithCircumcenter] have hu : ({i₁, i₂} : Finset (Fin 3)) ⊆ univ := subset_univ _ obtain ⟨i₃, hi₃, hi₃₁, hi₃₂⟩ : ∃ i₃, univ \ ({i₁, i₂} : Finset (Fin 3)) = {i₃} ∧ i₃ ≠ i₁ ∧ i₃ ≠ i₂ := by -- Porting note (#11043): was `decide!` fin_cases i₁ <;> fin_cases i₂ <;> simp at h <;> decide -- Porting note: Original proof was `simp_rw [← sum_sdiff hu, hi₃]; simp [hi₃₁, hi₃₂]; norm_num` rw [← sum_sdiff hu, ← sum_sdiff hu, hi₃, sum_singleton, ← sum_sdiff hu, hi₃] split_ifs with h · exact (h.elim hi₃₁ hi₃₂).elim simp only [zero_add, Nat.cast_one, inv_one, sub_zero, one_mul, pointsWithCircumcenter_point, sum_singleton, h, ite_false, dist_self, mul_zero, mem_singleton, true_or, ite_true, sub_self, zero_mul, implies_true, sum_insert_of_eq_zero_if_not_mem, or_true, add_zero, div_one, sub_neg_eq_add, pointsWithCircumcenter_eq_circumcenter, dist_circumcenter_eq_circumradius, sum_const_zero, dist_circumcenter_eq_circumradius', mul_one, neg_add_rev, half_add_self] norm_num #align affine.triangle.dist_orthocenter_reflection_circumcenter Affine.Triangle.dist_orthocenter_reflection_circumcenter /-- The distance from the orthocenter to the reflection of the circumcenter in a side equals the circumradius, variant using a `Finset`. -/ theorem dist_orthocenter_reflection_circumcenter_finset (t : Triangle ℝ P) {i₁ i₂ : Fin 3} (h : i₁ ≠ i₂) : dist t.orthocenter (reflection (affineSpan ℝ (t.points '' ↑({i₁, i₂} : Finset (Fin 3)))) t.circumcenter) = t.circumradius := by simp only [mem_singleton, coe_insert, coe_singleton, Set.mem_singleton_iff] exact dist_orthocenter_reflection_circumcenter _ h #align affine.triangle.dist_orthocenter_reflection_circumcenter_finset Affine.Triangle.dist_orthocenter_reflection_circumcenter_finset /-- The affine span of the orthocenter and a vertex is contained in the altitude. -/
Mathlib/Geometry/Euclidean/MongePoint.lean
562
566
theorem affineSpan_orthocenter_point_le_altitude (t : Triangle ℝ P) (i : Fin 3) : line[ℝ, t.orthocenter, t.points i] ≤ t.altitude i := by
refine spanPoints_subset_coe_of_subset_coe ?_ rw [Set.insert_subset_iff, Set.singleton_subset_iff] exact ⟨t.orthocenter_mem_altitude, t.mem_altitude i⟩
/- Copyright (c) 2021 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Data.Array.Lemmas import Batteries.Tactic.Lint.Misc namespace Batteries /-- Union-find node type -/ structure UFNode where /-- Parent of node -/ parent : Nat /-- Rank of node -/ rank : Nat namespace UnionFind /-- Panic with return value -/ def panicWith (v : α) (msg : String) : α := @panic α ⟨v⟩ msg @[simp] theorem panicWith_eq (v : α) (msg) : panicWith v msg = v := rfl /-- Parent of a union-find node, defaults to self when the node is a root -/ def parentD (arr : Array UFNode) (i : Nat) : Nat := if h : i < arr.size then (arr.get ⟨i, h⟩).parent else i /-- Rank of a union-find node, defaults to 0 when the node is a root -/ def rankD (arr : Array UFNode) (i : Nat) : Nat := if h : i < arr.size then (arr.get ⟨i, h⟩).rank else 0 theorem parentD_eq {arr : Array UFNode} {i} : parentD arr i.1 = (arr.get i).parent := dif_pos _ theorem parentD_eq' {arr : Array UFNode} {i} (h) : parentD arr i = (arr.get ⟨i, h⟩).parent := dif_pos _ theorem rankD_eq {arr : Array UFNode} {i} : rankD arr i.1 = (arr.get i).rank := dif_pos _ theorem rankD_eq' {arr : Array UFNode} {i} (h) : rankD arr i = (arr.get ⟨i, h⟩).rank := dif_pos _ theorem parentD_of_not_lt : ¬i < arr.size → parentD arr i = i := (dif_neg ·) theorem lt_of_parentD : parentD arr i ≠ i → i < arr.size := Decidable.not_imp_comm.1 parentD_of_not_lt theorem parentD_set {arr : Array UFNode} {x v i} : parentD (arr.set x v) i = if x.1 = i then v.parent else parentD arr i := by rw [parentD]; simp [Array.get_eq_getElem, parentD] split <;> [split <;> simp [Array.get_set, *]; split <;> [(subst i; cases ‹¬_› x.2); rfl]] theorem rankD_set {arr : Array UFNode} {x v i} : rankD (arr.set x v) i = if x.1 = i then v.rank else rankD arr i := by rw [rankD]; simp [Array.get_eq_getElem, rankD] split <;> [split <;> simp [Array.get_set, *]; split <;> [(subst i; cases ‹¬_› x.2); rfl]] end UnionFind open UnionFind /-- ### Union-find data structure The `UnionFind` structure is an implementation of disjoint-set data structure that uses path compression to make the primary operations run in amortized nearly linear time. The nodes of a `UnionFind` structure `s` are natural numbers smaller than `s.size`. The structure associates with a canonical representative from its equivalence class. The structure can be extended using the `push` operation and equivalence classes can be updated using the `union` operation. The main operations for `UnionFind` are: * `empty`/`mkEmpty` are used to create a new empty structure. * `size` returns the size of the data structure. * `push` adds a new node to a structure, unlinked to any other node. * `union` links two nodes of the data structure, joining their equivalence classes, and performs path compression. * `find` returns the canonical representative of a node and updates the data structure using path compression. * `root` returns the canonical representative of a node without altering the data structure. * `checkEquiv` checks whether two nodes have the same canonical representative and updates the structure using path compression. Most use cases should prefer `find` over `root` to benefit from the speedup from path-compression. The main operations use `Fin s.size` to represent nodes of the union-find structure. Some alternatives are provided: * `unionN`, `findN`, `rootN`, `checkEquivN` use `Fin n` with a proof that `n = s.size`. * `union!`, `find!`, `root!`, `checkEquiv!` use `Nat` and panic when the indices are out of bounds. * `findD`, `rootD`, `checkEquivD` use `Nat` and treat out of bound indices as isolated nodes. The noncomputable relation `UnionFind.Equiv` is provided to use the equivalence relation from a `UnionFind` structure in the context of proofs. -/ structure UnionFind where /-- Array of union-find nodes -/ arr : Array UFNode /-- Validity for parent nodes -/ parentD_lt : ∀ {i}, i < arr.size → parentD arr i < arr.size /-- Validity for rank -/ rankD_lt : ∀ {i}, parentD arr i ≠ i → rankD arr i < rankD arr (parentD arr i) namespace UnionFind /-- Size of union-find structure. -/ @[inline] abbrev size (self : UnionFind) := self.arr.size /-- Create an empty union-find structure with specific capacity -/ def mkEmpty (c : Nat) : UnionFind where arr := Array.mkEmpty c parentD_lt := nofun rankD_lt := nofun /-- Empty union-find structure -/ def empty := mkEmpty 0 instance : EmptyCollection UnionFind := ⟨.empty⟩ /-- Parent of union-find node -/ abbrev parent (self : UnionFind) (i : Nat) : Nat := parentD self.arr i theorem parent'_lt (self : UnionFind) (i : Fin self.size) : (self.arr.get i).parent < self.size := by simp only [← parentD_eq, parentD_lt, Fin.is_lt, Array.data_length] theorem parent_lt (self : UnionFind) (i : Nat) : self.parent i < self.size ↔ i < self.size := by simp only [parentD]; split <;> simp only [*, parent'_lt] /-- Rank of union-find node -/ abbrev rank (self : UnionFind) (i : Nat) : Nat := rankD self.arr i theorem rank_lt {self : UnionFind} {i : Nat} : self.parent i ≠ i → self.rank i < self.rank (self.parent i) := by simpa only [rank] using self.rankD_lt theorem rank'_lt (self : UnionFind) (i : Fin self.size) : (self.arr.get i).parent ≠ i → self.rank i < self.rank (self.arr.get i).parent := by simpa only [← parentD_eq] using self.rankD_lt /-- Maximum rank of nodes in a union-find structure -/ noncomputable def rankMax (self : UnionFind) := self.arr.foldr (max ·.rank) 0 + 1 theorem rank'_lt_rankMax (self : UnionFind) (i : Fin self.size) : (self.arr.get i).rank < self.rankMax := by let rec go : ∀ {l} {x : UFNode}, x ∈ l → x.rank ≤ List.foldr (max ·.rank) 0 l | a::l, _, List.Mem.head _ => by dsimp; apply Nat.le_max_left | a::l, _, .tail _ h => by dsimp; exact Nat.le_trans (go h) (Nat.le_max_right ..) simp [rankMax, Array.foldr_eq_foldr_data] exact Nat.lt_succ.2 <| go (self.arr.data.get_mem i.1 i.2) theorem rankD_lt_rankMax (self : UnionFind) (i : Nat) : rankD self.arr i < self.rankMax := by simp [rankD]; split <;> [apply rank'_lt_rankMax; apply Nat.succ_pos] theorem lt_rankMax (self : UnionFind) (i : Nat) : self.rank i < self.rankMax := rankD_lt_rankMax .. theorem push_rankD (arr : Array UFNode) : rankD (arr.push ⟨arr.size, 0⟩) i = rankD arr i := by simp [rankD, Array.get_eq_getElem, Array.get_push] split <;> split <;> first | simp | cases ‹¬_› (Nat.lt_succ_of_lt ‹_›) theorem push_parentD (arr : Array UFNode) : parentD (arr.push ⟨arr.size, 0⟩) i = parentD arr i := by simp [parentD, Array.get_eq_getElem, Array.get_push] split <;> split <;> try simp · exact Nat.le_antisymm (Nat.ge_of_not_lt ‹_›) (Nat.le_of_lt_succ ‹_›) · cases ‹¬_› (Nat.lt_succ_of_lt ‹_›) /-- Add a new node to a union-find structure, unlinked with any other nodes -/ def push (self : UnionFind) : UnionFind where arr := self.arr.push ⟨self.arr.size, 0⟩ parentD_lt {i} := by simp [push_parentD]; simp [parentD] split <;> [exact fun _ => Nat.lt_succ_of_lt (self.parent'_lt _); exact id] rankD_lt := by simp [push_parentD, push_rankD]; exact self.rank_lt /-- Root of a union-find node. -/ def root (self : UnionFind) (x : Fin self.size) : Fin self.size := let y := (self.arr.get x).parent if h : y = x then x else have := Nat.sub_lt_sub_left (self.lt_rankMax x) (self.rank'_lt _ h) self.root ⟨y, self.parent'_lt x⟩ termination_by self.rankMax - self.rank x @[inherit_doc root] def rootN (self : UnionFind) (x : Fin n) (h : n = self.size) : Fin n := match n, h with | _, rfl => self.root x /-- Root of a union-find node. Panics if index is out of bounds. -/ def root! (self : UnionFind) (x : Nat) : Nat := if h : x < self.size then self.root ⟨x, h⟩ else panicWith x "index out of bounds" /-- Root of a union-find node. Returns input if index is out of bounds. -/ def rootD (self : UnionFind) (x : Nat) : Nat := if h : x < self.size then self.root ⟨x, h⟩ else x @[nolint unusedHavesSuffices] theorem parent_root (self : UnionFind) (x : Fin self.size) : (self.arr.get (self.root x)).parent = self.root x := by rw [root]; split <;> [assumption; skip] have := Nat.sub_lt_sub_left (self.lt_rankMax x) (self.rank'_lt _ ‹_›) apply parent_root termination_by self.rankMax - self.rank x theorem parent_rootD (self : UnionFind) (x : Nat) : self.parent (self.rootD x) = self.rootD x := by rw [rootD]; split <;> [simp [parentD, parent_root, -Array.get_eq_getElem]; simp [parentD_of_not_lt, *]] @[nolint unusedHavesSuffices] theorem rootD_parent (self : UnionFind) (x : Nat) : self.rootD (self.parent x) = self.rootD x := by simp [rootD, parent_lt]; split <;> simp [parentD, parentD_of_not_lt, *, -Array.get_eq_getElem] (conv => rhs; rw [root]); split · rw [root, dif_pos] <;> simp [*, -Array.get_eq_getElem] · simp theorem rootD_lt {self : UnionFind} {x : Nat} : self.rootD x < self.size ↔ x < self.size := by simp [rootD]; split <;> simp [*] @[nolint unusedHavesSuffices] theorem rootD_eq_self {self : UnionFind} {x : Nat} : self.rootD x = x ↔ self.parent x = x := by refine ⟨fun h => by rw [← h, parent_rootD], fun h => ?_⟩ rw [rootD]; split <;> [rw [root, dif_pos (by rwa [parent, parentD_eq' ‹_›] at h)]; rfl] theorem rootD_rootD {self : UnionFind} {x : Nat} : self.rootD (self.rootD x) = self.rootD x := rootD_eq_self.2 (parent_rootD ..) theorem rootD_ext {m1 m2 : UnionFind} (H : ∀ x, m1.parent x = m2.parent x) {x} : m1.rootD x = m2.rootD x := by if h : m2.parent x = x then rw [rootD_eq_self.2 h, rootD_eq_self.2 ((H _).trans h)] else have := Nat.sub_lt_sub_left (m2.lt_rankMax x) (m2.rank_lt h) rw [← rootD_parent, H, rootD_ext H, rootD_parent] termination_by m2.rankMax - m2.rank x theorem le_rank_root {self : UnionFind} {x : Nat} : self.rank x ≤ self.rank (self.rootD x) := by if h : self.parent x = x then rw [rootD_eq_self.2 h]; exact Nat.le_refl .. else have := Nat.sub_lt_sub_left (self.lt_rankMax x) (self.rank_lt h) rw [← rootD_parent] exact Nat.le_trans (Nat.le_of_lt (self.rank_lt h)) le_rank_root termination_by self.rankMax - self.rank x theorem lt_rank_root {self : UnionFind} {x : Nat} : self.rank x < self.rank (self.rootD x) ↔ self.parent x ≠ x := by refine ⟨fun h h' => Nat.ne_of_lt h (by rw [rootD_eq_self.2 h']), fun h => ?_⟩ rw [← rootD_parent] exact Nat.lt_of_lt_of_le (self.rank_lt h) le_rank_root /-- Auxiliary data structure for find operation -/ structure FindAux (n : Nat) where /-- Array of nodes -/ s : Array UFNode /-- Index of root node -/ root : Fin n /-- Size requirement -/ size_eq : s.size = n /-- Auxiliary function for find operation -/ def findAux (self : UnionFind) (x : Fin self.size) : FindAux self.size := let y := (self.arr.get x).parent if h : y = x then ⟨self.arr, x, rfl⟩ else have := Nat.sub_lt_sub_left (self.lt_rankMax x) (self.rank'_lt _ h) let ⟨arr₁, root, H⟩ := self.findAux ⟨y, self.parent'_lt x⟩ ⟨arr₁.modify x fun s => { s with parent := root }, root, by simp [H]⟩ termination_by self.rankMax - self.rank x @[nolint unusedHavesSuffices] theorem findAux_root {self : UnionFind} {x : Fin self.size} : (findAux self x).root = self.root x := by rw [findAux, root]; simp; split <;> simp have := Nat.sub_lt_sub_left (self.lt_rankMax x) (self.rank'_lt _ ‹_›) exact findAux_root termination_by self.rankMax - self.rank x @[nolint unusedHavesSuffices] theorem findAux_s {self : UnionFind} {x : Fin self.size} : (findAux self x).s = if (self.arr.get x).parent = x then self.arr else (self.findAux ⟨_, self.parent'_lt x⟩).s.modify x fun s => { s with parent := self.rootD x } := by rw [show self.rootD _ = (self.findAux ⟨_, self.parent'_lt x⟩).root from _] · rw [findAux]; split <;> rfl · rw [← rootD_parent, parent, parentD_eq] simp [findAux_root, rootD] apply dif_pos exact parent'_lt .. theorem rankD_findAux {self : UnionFind} {x : Fin self.size} : rankD (findAux self x).s i = self.rank i := by if h : i < self.size then rw [findAux_s]; split <;> [rfl; skip] have := Nat.sub_lt_sub_left (self.lt_rankMax x) (self.rank'_lt _ ‹_›) have := lt_of_parentD (by rwa [parentD_eq]) rw [rankD_eq' (by simp [FindAux.size_eq, h]), Array.get_modify (by rwa [FindAux.size_eq])] split <;> simp [← rankD_eq, rankD_findAux (x := ⟨_, self.parent'_lt x⟩), -Array.get_eq_getElem] else simp [rank, rankD]; rw [dif_neg (by rwa [FindAux.size_eq]), dif_neg h] termination_by self.rankMax - self.rank x theorem parentD_findAux {self : UnionFind} {x : Fin self.size} : parentD (findAux self x).s i = if i = x then self.rootD x else parentD (self.findAux ⟨_, self.parent'_lt x⟩).s i := by rw [findAux_s]; split <;> [split; skip] · subst i; rw [rootD_eq_self.2 _] <;> simp [parentD_eq, *, -Array.get_eq_getElem] · rw [findAux_s]; simp [*, -Array.get_eq_getElem] · next h => rw [parentD]; split <;> rename_i h' · rw [Array.get_modify (by simpa using h')] simp [@eq_comm _ i, -Array.get_eq_getElem] split <;> simp [← parentD_eq, -Array.get_eq_getElem] · rw [if_neg (mt (by rintro rfl; simp [FindAux.size_eq]) h')] rw [parentD, dif_neg]; simpa using h' theorem parentD_findAux_rootD {self : UnionFind} {x : Fin self.size} : parentD (findAux self x).s (self.rootD x) = self.rootD x := by rw [parentD_findAux]; split <;> [rfl; rename_i h] rw [rootD_eq_self, parent, parentD_eq] at h have := Nat.sub_lt_sub_left (self.lt_rankMax x) (self.rank'_lt _ ‹_›) rw [← rootD_parent, parent, parentD_eq] exact parentD_findAux_rootD (x := ⟨_, self.parent'_lt x⟩) termination_by self.rankMax - self.rank x theorem parentD_findAux_lt {self : UnionFind} {x : Fin self.size} (h : i < self.size) : parentD (findAux self x).s i < self.size := by if h' : (self.arr.get x).parent = x then rw [findAux_s, if_pos h']; apply self.parentD_lt h else rw [parentD_findAux]; split <;> [simp [rootD_lt]; skip] have := Nat.sub_lt_sub_left (self.lt_rankMax x) (self.rank'_lt _ ‹_›) apply parentD_findAux_lt h termination_by self.rankMax - self.rank x theorem parentD_findAux_or (self : UnionFind) (x : Fin self.size) (i) : parentD (findAux self x).s i = self.rootD i ∧ self.rootD i = self.rootD x ∨ parentD (findAux self x).s i = self.parent i := by if h' : (self.arr.get x).parent = x then rw [findAux_s, if_pos h']; exact .inr rfl else rw [parentD_findAux]; split <;> [simp [*]; skip] have := Nat.sub_lt_sub_left (self.lt_rankMax x) (self.rank'_lt _ ‹_›) exact (parentD_findAux_or self ⟨_, self.parent'_lt x⟩ i).imp_left <| .imp_right fun h => by simp only [h, ← parentD_eq, rootD_parent, Array.data_length] termination_by self.rankMax - self.rank x theorem lt_rankD_findAux {self : UnionFind} {x : Fin self.size} : parentD (findAux self x).s i ≠ i → self.rank i < self.rank (parentD (findAux self x).s i) := by if h' : (self.arr.get x).parent = x then rw [findAux_s, if_pos h']; apply self.rank_lt else rw [parentD_findAux]; split <;> rename_i h <;> intro h' · subst i; rwa [lt_rank_root, Ne, ← rootD_eq_self] · have := Nat.sub_lt_sub_left (self.lt_rankMax x) (self.rank'_lt _ ‹_›) apply lt_rankD_findAux h' termination_by self.rankMax - self.rank x /-- Find root of a union-find node, updating the structure using path compression. -/ def find (self : UnionFind) (x : Fin self.size) : (s : UnionFind) × {_root : Fin s.size // s.size = self.size} := let r := self.findAux x { 1.arr := r.s 2.1.val := r.root 1.parentD_lt := fun h => by simp [FindAux.size_eq] at *; exact parentD_findAux_lt h 1.rankD_lt := fun h => by rw [rankD_findAux, rankD_findAux]; exact lt_rankD_findAux h 2.1.isLt := show _ < r.s.size by rw [r.size_eq]; exact r.root.2 2.2 := by simp [size, r.size_eq] } @[inherit_doc find] def findN (self : UnionFind) (x : Fin n) (h : n = self.size) : UnionFind × Fin n := match n, h with | _, rfl => match self.find x with | ⟨s, r, h⟩ => (s, Fin.cast h r) /-- Find root of a union-find node, updating the structure using path compression. Panics if index is out of bounds. -/ def find! (self : UnionFind) (x : Nat) : UnionFind × Nat := if h : x < self.size then match self.find ⟨x, h⟩ with | ⟨s, r, _⟩ => (s, r) else panicWith (self, x) "index out of bounds" /-- Find root of a union-find node, updating the structure using path compression. Returns inputs unchanged when index is out of bounds. -/ def findD (self : UnionFind) (x : Nat) : UnionFind × Nat := if h : x < self.size then match self.find ⟨x, h⟩ with | ⟨s, r, _⟩ => (s, r) else (self, x) @[simp] theorem find_size (self : UnionFind) (x : Fin self.size) : (self.find x).1.size = self.size := by simp [find, size, FindAux.size_eq] @[simp] theorem find_root_2 (self : UnionFind) (x : Fin self.size) : (self.find x).2.1.1 = self.rootD x := by simp [find, findAux_root, rootD] @[simp] theorem find_parent_1 (self : UnionFind) (x : Fin self.size) : (self.find x).1.parent x = self.rootD x := by simp [find, parent]; rw [parentD_findAux, if_pos rfl] theorem find_parent_or (self : UnionFind) (x : Fin self.size) (i) : (self.find x).1.parent i = self.rootD i ∧ self.rootD i = self.rootD x ∨ (self.find x).1.parent i = self.parent i := parentD_findAux_or .. @[simp] theorem find_root_1 (self : UnionFind) (x : Fin self.size) (i : Nat) : (self.find x).1.rootD i = self.rootD i := by if h : (self.find x).1.parent i = i then rw [rootD_eq_self.2 h] obtain ⟨h1, _⟩ | h1 := find_parent_or self x i <;> rw [h1] at h · rw [h] · rw [rootD_eq_self.2 h] else have := Nat.sub_lt_sub_left ((self.find x).1.lt_rankMax _) ((self.find x).1.rank_lt h) rw [← rootD_parent, find_root_1 self x ((self.find x).1.parent i)] obtain ⟨h1, _⟩ | h1 := find_parent_or self x i · rw [h1, rootD_rootD] · rw [h1, rootD_parent] termination_by (self.find x).1.rankMax - (self.find x).1.rank i decreasing_by exact this -- why is this needed? It is way slower without it /-- Link two union-find nodes -/ def linkAux (self : Array UFNode) (x y : Fin self.size) : Array UFNode := if x.1 = y then self else let nx := self.get x let ny := self.get y if ny.rank < nx.rank then self.set y {ny with parent := x} else let arr₁ := self.set x {nx with parent := y} if nx.rank = ny.rank then arr₁.set ⟨y, by simp [arr₁]⟩ {ny with rank := ny.rank + 1} else arr₁
.lake/packages/batteries/Batteries/Data/UnionFind/Basic.lean
439
461
theorem setParentBump_rankD_lt {arr : Array UFNode} {x y : Fin arr.size} (hroot : (arr.get x).rank < (arr.get y).rank ∨ (arr.get y).parent = y) (H : (arr.get x).rank ≤ (arr.get y).rank) {i : Nat} (rankD_lt : parentD arr i ≠ i → rankD arr i < rankD arr (parentD arr i)) (hP : parentD arr' i = if x.1 = i then y.1 else parentD arr i) (hR : ∀ {i}, rankD arr' i = if y.1 = i ∧ (arr.get x).rank = (arr.get y).rank then (arr.get y).rank + 1 else rankD arr i) : ¬parentD arr' i = i → rankD arr' i < rankD arr' (parentD arr' i) := by
simp [hP, hR, -Array.get_eq_getElem] at *; split <;> rename_i h₁ <;> [simp [← h₁]; skip] <;> split <;> rename_i h₂ <;> intro h · simp [h₂] at h · simp [rankD_eq]; split <;> rename_i h₃ · rw [← h₃]; apply Nat.lt_succ_self · exact Nat.lt_of_le_of_ne H h₃ · cases h₂.1 simp only [h₂.2, false_or, Nat.lt_irrefl] at hroot simp only [hroot, parentD_eq, not_true_eq_false] at h · have := rankD_lt h split <;> rename_i h₃ · rw [← rankD_eq, h₃.1]; exact Nat.lt_succ_of_lt this · exact this
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Topology.Algebra.Algebra import Mathlib.Topology.ContinuousFunction.Compact import Mathlib.Topology.UrysohnsLemma import Mathlib.Analysis.RCLike.Basic import Mathlib.Analysis.NormedSpace.Units import Mathlib.Topology.Algebra.Module.CharacterSpace #align_import topology.continuous_function.ideals from "leanprover-community/mathlib"@"c2258f7bf086b17eac0929d635403780c39e239f" /-! # Ideals of continuous functions For a topological semiring `R` and a topological space `X` there is a Galois connection between `Ideal C(X, R)` and `Set X` given by sending each `I : Ideal C(X, R)` to `{x : X | ∀ f ∈ I, f x = 0}ᶜ` and mapping `s : Set X` to the ideal with carrier `{f : C(X, R) | ∀ x ∈ sᶜ, f x = 0}`, and we call these maps `ContinuousMap.setOfIdeal` and `ContinuousMap.idealOfSet`. As long as `R` is Hausdorff, `ContinuousMap.setOfIdeal I` is open, and if, in addition, `X` is locally compact, then `ContinuousMap.setOfIdeal s` is closed. When `R = 𝕜` with `RCLike 𝕜` and `X` is compact Hausdorff, then this Galois connection can be improved to a true Galois correspondence (i.e., order isomorphism) between the type `opens X` and the subtype of closed ideals of `C(X, 𝕜)`. Because we do not have a bundled type of closed ideals, we simply register this as a Galois insertion between `Ideal C(X, 𝕜)` and `opens X`, which is `ContinuousMap.idealOpensGI`. Consequently, the maximal ideals of `C(X, 𝕜)` are precisely those ideals corresponding to (complements of) singletons in `X`. In addition, when `X` is locally compact and `𝕜` is a nontrivial topological integral domain, then there is a natural continuous map from `X` to `WeakDual.characterSpace 𝕜 C(X, 𝕜)` given by point evaluation, which is herein called `WeakDual.CharacterSpace.continuousMapEval`. Again, when `X` is compact Hausdorff and `RCLike 𝕜`, more can be obtained. In particular, in that context this map is bijective, and since the domain is compact and the codomain is Hausdorff, it is a homeomorphism, herein called `WeakDual.CharacterSpace.homeoEval`. ## Main definitions * `ContinuousMap.idealOfSet`: ideal of functions which vanish on the complement of a set. * `ContinuousMap.setOfIdeal`: complement of the set on which all functions in the ideal vanish. * `ContinuousMap.opensOfIdeal`: `ContinuousMap.setOfIdeal` as a term of `opens X`. * `ContinuousMap.idealOpensGI`: The Galois insertion `ContinuousMap.opensOfIdeal` and `fun s ↦ ContinuousMap.idealOfSet ↑s`. * `WeakDual.CharacterSpace.continuousMapEval`: the natural continuous map from a locally compact topological space `X` to the `WeakDual.characterSpace 𝕜 C(X, 𝕜)` which sends `x : X` to point evaluation at `x`, with modest hypothesis on `𝕜`. * `WeakDual.CharacterSpace.homeoEval`: this is `WeakDual.CharacterSpace.continuousMapEval` upgraded to a homeomorphism when `X` is compact Hausdorff and `RCLike 𝕜`. ## Main statements * `ContinuousMap.idealOfSet_ofIdeal_eq_closure`: when `X` is compact Hausdorff and `RCLike 𝕜`, `idealOfSet 𝕜 (setOfIdeal I) = I.closure` for any ideal `I : Ideal C(X, 𝕜)`. * `ContinuousMap.setOfIdeal_ofSet_eq_interior`: when `X` is compact Hausdorff and `RCLike 𝕜`, `setOfIdeal (idealOfSet 𝕜 s) = interior s` for any `s : Set X`. * `ContinuousMap.ideal_isMaximal_iff`: when `X` is compact Hausdorff and `RCLike 𝕜`, a closed ideal of `C(X, 𝕜)` is maximal if and only if it is `idealOfSet 𝕜 {x}ᶜ` for some `x : X`. ## Implementation details Because there does not currently exist a bundled type of closed ideals, we don't provide the actual order isomorphism described above, and instead we only consider the Galois insertion `ContinuousMap.idealOpensGI`. ## Tags ideal, continuous function, compact, Hausdorff -/ open scoped NNReal namespace ContinuousMap open TopologicalSpace section TopologicalRing variable {X R : Type*} [TopologicalSpace X] [Semiring R] variable [TopologicalSpace R] [TopologicalSemiring R] variable (R) /-- Given a topological ring `R` and `s : Set X`, construct the ideal in `C(X, R)` of functions which vanish on the complement of `s`. -/ def idealOfSet (s : Set X) : Ideal C(X, R) where carrier := {f : C(X, R) | ∀ x ∈ sᶜ, f x = 0} add_mem' {f g} hf hg x hx := by simp [hf x hx, hg x hx, coe_add, Pi.add_apply, add_zero] zero_mem' _ _ := rfl smul_mem' c f hf x hx := mul_zero (c x) ▸ congr_arg (fun y => c x * y) (hf x hx) #align continuous_map.ideal_of_set ContinuousMap.idealOfSet theorem idealOfSet_closed [T2Space R] (s : Set X) : IsClosed (idealOfSet R s : Set C(X, R)) := by simp only [idealOfSet, Submodule.coe_set_mk, Set.setOf_forall] exact isClosed_iInter fun x => isClosed_iInter fun _ => isClosed_eq (continuous_eval_const x) continuous_const #align continuous_map.ideal_of_set_closed ContinuousMap.idealOfSet_closed variable {R} theorem mem_idealOfSet {s : Set X} {f : C(X, R)} : f ∈ idealOfSet R s ↔ ∀ ⦃x : X⦄, x ∈ sᶜ → f x = 0 := by convert Iff.rfl #align continuous_map.mem_ideal_of_set ContinuousMap.mem_idealOfSet theorem not_mem_idealOfSet {s : Set X} {f : C(X, R)} : f ∉ idealOfSet R s ↔ ∃ x ∈ sᶜ, f x ≠ 0 := by simp_rw [mem_idealOfSet]; push_neg; rfl #align continuous_map.not_mem_ideal_of_set ContinuousMap.not_mem_idealOfSet /-- Given an ideal `I` of `C(X, R)`, construct the set of points for which every function in the ideal vanishes on the complement. -/ def setOfIdeal (I : Ideal C(X, R)) : Set X := {x : X | ∀ f ∈ I, (f : C(X, R)) x = 0}ᶜ #align continuous_map.set_of_ideal ContinuousMap.setOfIdeal theorem not_mem_setOfIdeal {I : Ideal C(X, R)} {x : X} : x ∉ setOfIdeal I ↔ ∀ ⦃f : C(X, R)⦄, f ∈ I → f x = 0 := by rw [← Set.mem_compl_iff, setOfIdeal, compl_compl, Set.mem_setOf] #align continuous_map.not_mem_set_of_ideal ContinuousMap.not_mem_setOfIdeal theorem mem_setOfIdeal {I : Ideal C(X, R)} {x : X} : x ∈ setOfIdeal I ↔ ∃ f ∈ I, (f : C(X, R)) x ≠ 0 := by simp_rw [setOfIdeal, Set.mem_compl_iff, Set.mem_setOf]; push_neg; rfl #align continuous_map.mem_set_of_ideal ContinuousMap.mem_setOfIdeal
Mathlib/Topology/ContinuousFunction/Ideals.lean
128
132
theorem setOfIdeal_open [T2Space R] (I : Ideal C(X, R)) : IsOpen (setOfIdeal I) := by
simp only [setOfIdeal, Set.setOf_forall, isOpen_compl_iff] exact isClosed_iInter fun f => isClosed_iInter fun _ => isClosed_eq (map_continuous f) continuous_const
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Data.Set.Subsingleton import Mathlib.Order.WithBot #align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29" /-! # Images and preimages of sets ## Main definitions * `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β. * `range f : Set β` : the image of `univ` under `f`. Also works for `{p : Prop} (f : p → α)` (unlike `image`) ## Notation * `f ⁻¹' t` for `Set.preimage f t` * `f '' s` for `Set.image f s` ## Tags set, sets, image, preimage, pre-image, range -/ universe u v open Function Set namespace Set variable {α β γ : Type*} {ι ι' : Sort*} /-! ### Inverse image -/ section Preimage variable {f : α → β} {g : β → γ} @[simp] theorem preimage_empty : f ⁻¹' ∅ = ∅ := rfl #align set.preimage_empty Set.preimage_empty theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by congr with x simp [h] #align set.preimage_congr Set.preimage_congr @[gcongr] theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx #align set.preimage_mono Set.preimage_mono @[simp, mfld_simps] theorem preimage_univ : f ⁻¹' univ = univ := rfl #align set.preimage_univ Set.preimage_univ theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ := subset_univ _ #align set.subset_preimage_univ Set.subset_preimage_univ @[simp, mfld_simps] theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t := rfl #align set.preimage_inter Set.preimage_inter @[simp] theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t := rfl #align set.preimage_union Set.preimage_union @[simp] theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ := rfl #align set.preimage_compl Set.preimage_compl @[simp] theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t := rfl #align set.preimage_diff Set.preimage_diff open scoped symmDiff in @[simp] lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) := rfl #align set.preimage_symm_diff Set.preimage_symmDiff @[simp] theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) : f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) := rfl #align set.preimage_ite Set.preimage_ite @[simp] theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } := rfl #align set.preimage_set_of_eq Set.preimage_setOf_eq @[simp] theorem preimage_id_eq : preimage (id : α → α) = id := rfl #align set.preimage_id_eq Set.preimage_id_eq @[mfld_simps] theorem preimage_id {s : Set α} : id ⁻¹' s = s := rfl #align set.preimage_id Set.preimage_id @[simp, mfld_simps] theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s := rfl #align set.preimage_id' Set.preimage_id' @[simp] theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ := eq_univ_of_forall fun _ => h #align set.preimage_const_of_mem Set.preimage_const_of_mem @[simp] theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ := eq_empty_of_subset_empty fun _ hx => h hx #align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] : (fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by split_ifs with hb exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb] #align set.preimage_const Set.preimage_const /-- If preimage of each singleton under `f : α → β` is either empty or the whole type, then `f` is a constant. -/ lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β} (hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf' · exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩ · have : ∀ x b, f x ≠ b := fun x b ↦ eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩ theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) := rfl #align set.preimage_comp Set.preimage_comp theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g := rfl #align set.preimage_comp_eq Set.preimage_comp_eq theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by induction' n with n ih; · simp rw [iterate_succ, iterate_succ', preimage_comp_eq, ih] #align set.preimage_iterate_eq Set.preimage_iterate_eq theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} : f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s := preimage_comp.symm #align set.preimage_preimage Set.preimage_preimage theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} : s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t := ⟨fun s_eq x h => by rw [s_eq] simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩ #align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) : s.Nonempty := let ⟨x, hx⟩ := hf ⟨f x, hx⟩ #align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage @[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp #align set.preimage_singleton_true Set.preimage_singleton_true @[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp #align set.preimage_singleton_false Set.preimage_singleton_false theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v) (H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by ext ⟨x, x_in_s⟩ constructor · intro x_in_u x_in_v exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩ · intro hx exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx' #align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl end Preimage /-! ### Image of a set under a function -/ section Image variable {f : α → β} {s t : Set α} -- Porting note: `Set.image` is already defined in `Init.Set` #align set.image Set.image @[deprecated mem_image (since := "2024-03-23")] theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} : y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y := bex_def.symm #align set.mem_image_iff_bex Set.mem_image_iff_bex theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s := rfl #align set.image_eta Set.image_eta theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} : f a ∈ f '' s ↔ a ∈ s := ⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩ #align function.injective.mem_set_image Function.Injective.mem_set_image theorem forall_mem_image {f : α → β} {s : Set α} {p : β → Prop} : (∀ y ∈ f '' s, p y) ↔ ∀ ⦃x⦄, x ∈ s → p (f x) := by simp #align set.ball_image_iff Set.forall_mem_image theorem exists_mem_image {f : α → β} {s : Set α} {p : β → Prop} : (∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp #align set.bex_image_iff Set.exists_mem_image @[deprecated (since := "2024-02-21")] alias ball_image_iff := forall_mem_image @[deprecated (since := "2024-02-21")] alias bex_image_iff := exists_mem_image @[deprecated (since := "2024-02-21")] alias ⟨_, ball_image_of_ball⟩ := forall_mem_image #align set.ball_image_of_ball Set.ball_image_of_ball @[deprecated forall_mem_image (since := "2024-02-21")] theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) : ∀ {y : β}, y ∈ f '' s → C y := forall_mem_image.2 h _ #align set.mem_image_elim Set.mem_image_elim @[deprecated forall_mem_image (since := "2024-02-21")] theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s) (h : ∀ x : α, x ∈ s → C (f x)) : C y := forall_mem_image.2 h _ h_y #align set.mem_image_elim_on Set.mem_image_elim_on -- Porting note: used to be `safe` @[congr] theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by ext x exact exists_congr fun a ↦ and_congr_right fun ha ↦ by rw [h a ha] #align set.image_congr Set.image_congr /-- A common special case of `image_congr` -/ theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s := image_congr fun x _ => h x #align set.image_congr' Set.image_congr' @[gcongr] lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha) theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) := by aesop #align set.image_comp Set.image_comp theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp /-- A variant of `image_comp`, useful for rewriting -/ theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s := (image_comp g f s).symm #align set.image_image Set.image_image theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ} (h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by simp_rw [image_image, h_comm] #align set.image_comm Set.image_comm theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ => image_comm h #align function.semiconj.set_image Function.Semiconj.set_image theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) : Function.Commute (image f) (image g) := Function.Semiconj.set_image h #align function.commute.set_image Function.Commute.set_image /-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in terms of `≤`. -/ @[gcongr] theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by simp only [subset_def, mem_image] exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩ #align set.image_subset Set.image_subset /-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/ lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _ #align set.monotone_image Set.monotone_image theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t := ext fun x => ⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine ⟨_, ?_, rfl⟩ · exact mem_union_left t h · exact mem_union_right s h⟩ #align set.image_union Set.image_union @[simp] theorem image_empty (f : α → β) : f '' ∅ = ∅ := by ext simp #align set.image_empty Set.image_empty theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t := subset_inter (image_subset _ inter_subset_left) (image_subset _ inter_subset_right) #align set.image_inter_subset Set.image_inter_subset theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) : f '' (s ∩ t) = f '' s ∩ f '' t := (image_inter_subset _ _ _).antisymm fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦ have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*]) ⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩ #align set.image_inter_on Set.image_inter_on theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t := image_inter_on fun _ _ _ _ h => H h #align set.image_inter Set.image_inter theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ := eq_univ_of_forall <| by simpa [image] #align set.image_univ_of_surjective Set.image_univ_of_surjective @[simp] theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by ext simp [image, eq_comm] #align set.image_singleton Set.image_singleton @[simp] theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} := ext fun _ => ⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h => (eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩ #align set.nonempty.image_const Set.Nonempty.image_const @[simp, mfld_simps] theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by simp only [eq_empty_iff_forall_not_mem] exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩ #align set.image_eq_empty Set.image_eq_empty -- Porting note: `compl` is already defined in `Init.Set` theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) : HasCompl.compl ⁻¹' S = HasCompl.compl '' S := Set.ext fun x => ⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h => Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩ #align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) : t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by simp [← preimage_compl_eq_image_compl] #align set.mem_compl_image Set.mem_compl_image @[simp] theorem image_id_eq : image (id : α → α) = id := by ext; simp /-- A variant of `image_id` -/ @[simp] theorem image_id' (s : Set α) : (fun x => x) '' s = s := by ext simp #align set.image_id' Set.image_id' theorem image_id (s : Set α) : id '' s = s := by simp #align set.image_id Set.image_id lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by induction n with | zero => simp | succ n ih => rw [iterate_succ', iterate_succ', ← ih, image_comp_eq] theorem compl_compl_image [BooleanAlgebra α] (S : Set α) : HasCompl.compl '' (HasCompl.compl '' S) = S := by rw [← image_comp, compl_comp_compl, image_id] #align set.compl_compl_image Set.compl_compl_image theorem image_insert_eq {f : α → β} {a : α} {s : Set α} : f '' insert a s = insert (f a) (f '' s) := by ext simp [and_or_left, exists_or, eq_comm, or_comm, and_comm] #align set.image_insert_eq Set.image_insert_eq theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by simp only [image_insert_eq, image_singleton] #align set.image_pair Set.image_pair theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) : f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s) #align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) : f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩ #align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : image f = preimage g := funext fun s => Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s) #align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by rw [image_eq_preimage_of_inverse h₁ h₂]; rfl #align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ := Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H] #align set.image_compl_subset Set.image_compl_subset theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ := compl_subset_iff_union.2 <| by rw [← image_union] simp [image_univ_of_surjective H] #align set.subset_image_compl Set.subset_image_compl theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ := Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2) #align set.image_compl_eq Set.image_compl_eq theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by rw [diff_subset_iff, ← image_union, union_diff_self] exact image_subset f subset_union_right #align set.subset_image_diff Set.subset_image_diff open scoped symmDiff in theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t := (union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans (superset_of_eq (image_union _ _ _)) #align set.subset_image_symm_diff Set.subset_image_symmDiff theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t := Subset.antisymm (Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf) (subset_image_diff f s t) #align set.image_diff Set.image_diff open scoped symmDiff in theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by simp_rw [Set.symmDiff_def, image_union, image_diff hf] #align set.image_symm_diff Set.image_symmDiff theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty | ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩ #align set.nonempty.image Set.Nonempty.image theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty | ⟨_, x, hx, _⟩ => ⟨x, hx⟩ #align set.nonempty.of_image Set.Nonempty.of_image @[simp] theorem image_nonempty {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty := ⟨Nonempty.of_image, fun h => h.image f⟩ #align set.nonempty_image_iff Set.image_nonempty @[deprecated (since := "2024-01-06")] alias nonempty_image_iff := image_nonempty theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) : (f ⁻¹' s).Nonempty := let ⟨y, hy⟩ := hs let ⟨x, hx⟩ := hf y ⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩ #align set.nonempty.preimage Set.Nonempty.preimage instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) := (Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype /-- image and preimage are a Galois connection -/ @[simp] theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t := forall_mem_image #align set.image_subset_iff Set.image_subset_iff theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s := image_subset_iff.2 Subset.rfl #align set.image_preimage_subset Set.image_preimage_subset theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ => mem_image_of_mem f #align set.subset_preimage_image Set.subset_preimage_image @[simp] theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s := Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s) #align set.preimage_image_eq Set.preimage_image_eq @[simp] theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s := Subset.antisymm (image_preimage_subset f s) fun x hx => let ⟨y, e⟩ := h x ⟨y, (e.symm ▸ hx : f y ∈ s), e⟩ #align set.image_preimage_eq Set.image_preimage_eq @[simp] theorem Nonempty.subset_preimage_const {s : Set α} (hs : Set.Nonempty s) (t : Set β) (a : β) : s ⊆ (fun _ => a) ⁻¹' t ↔ a ∈ t := by rw [← image_subset_iff, hs.image_const, singleton_subset_iff] @[simp] theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t := Iff.intro fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq] fun eq => eq ▸ rfl #align set.preimage_eq_preimage Set.preimage_eq_preimage theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) : f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by apply Subset.antisymm · calc f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _ _ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t) · rintro _ ⟨⟨x, h', rfl⟩, h⟩ exact ⟨x, ⟨h', h⟩, rfl⟩ #align set.image_inter_preimage Set.image_inter_preimage theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) : f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage] #align set.image_preimage_inter Set.image_preimage_inter @[simp] theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} : (f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by rw [← image_inter_preimage, image_nonempty] #align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t := by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage] #align set.image_diff_preimage Set.image_diff_preimage theorem compl_image : image (compl : Set α → Set α) = preimage compl := image_eq_preimage_of_inverse compl_compl compl_compl #align set.compl_image Set.compl_image theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } := congr_fun compl_image p #align set.compl_image_set_of Set.compl_image_set_of theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) : s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩ #align set.inter_preimage_subset Set.inter_preimage_subset theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) : s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h => Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r #align set.union_preimage_subset Set.union_preimage_subset theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t := image_subset_iff.2 (union_preimage_subset _ _ _) #align set.subset_image_union Set.subset_image_union theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} : f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A := Iff.rfl #align set.preimage_subset_iff Set.preimage_subset_iff theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t := Iff.symm <| (Iff.intro fun eq => eq ▸ rfl) fun eq => by rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq] #align set.image_eq_image Set.image_eq_image theorem subset_image_iff {t : Set β} : t ⊆ f '' s ↔ ∃ u, u ⊆ s ∧ f '' u = t := by refine ⟨fun h ↦ ⟨f ⁻¹' t ∩ s, inter_subset_right, ?_⟩, fun ⟨u, hu, hu'⟩ ↦ hu'.symm ▸ image_mono hu⟩ rwa [image_preimage_inter, inter_eq_left] theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by refine Iff.symm <| (Iff.intro (image_subset f)) fun h => ?_ rw [← preimage_image_eq s hf, ← preimage_image_eq t hf] exact preimage_mono h #align set.image_subset_image_iff Set.image_subset_image_iff theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β} (Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) : { x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } = (fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) := Hh.symm ▸ Set.ext fun ⟨a₁, a₂⟩ => ⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ => show (g a₁, g a₂) ∈ r from have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂ h₃.1 ▸ h₃.2 ▸ h₁⟩ #align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) : (∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) := ⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ => ⟨⟨_, _, a.prop, rfl⟩, h⟩⟩ #align set.exists_image_iff Set.exists_image_iff theorem imageFactorization_eq {f : α → β} {s : Set α} : Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val := funext fun _ => rfl #align set.image_factorization_eq Set.imageFactorization_eq theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) := fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩ #align set.surjective_onto_image Set.surjective_onto_image /-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect. -/ theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by ext i obtain hi | hi := eq_or_ne (σ i) i · refine ⟨?_, fun h => ⟨i, h, hi⟩⟩ rintro ⟨j, hj, h⟩ rwa [σ.injective (hi.trans h.symm)] · refine iff_of_true ⟨σ.symm i, hs fun h => hi ?_, σ.apply_symm_apply _⟩ (hs hi) convert congr_arg σ h <;> exact (σ.apply_symm_apply _).symm #align set.image_perm Set.image_perm end Image /-! ### Lemmas about the powerset and image. -/ /-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/ theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by ext t simp_rw [mem_union, mem_image, mem_powerset_iff] constructor · intro h by_cases hs : a ∈ t · right refine ⟨t \ {a}, ?_, ?_⟩ · rw [diff_singleton_subset_iff] assumption · rw [insert_diff_singleton, insert_eq_of_mem hs] · left exact (subset_insert_iff_of_not_mem hs).mp h · rintro (h | ⟨s', h₁, rfl⟩) · exact subset_trans h (subset_insert a s) · exact insert_subset_insert h₁ #align set.powerset_insert Set.powerset_insert /-! ### Lemmas about range of a function. -/ section Range variable {f : ι → α} {s t : Set α} theorem forall_mem_range {p : α → Prop} : (∀ a ∈ range f, p a) ↔ ∀ i, p (f i) := by simp #align set.forall_range_iff Set.forall_mem_range @[deprecated (since := "2024-02-21")] alias forall_range_iff := forall_mem_range theorem forall_subtype_range_iff {p : range f → Prop} : (∀ a : range f, p a) ↔ ∀ i, p ⟨f i, mem_range_self _⟩ := ⟨fun H i => H _, fun H ⟨y, i, hi⟩ => by subst hi apply H⟩ #align set.forall_subtype_range_iff Set.forall_subtype_range_iff theorem exists_range_iff {p : α → Prop} : (∃ a ∈ range f, p a) ↔ ∃ i, p (f i) := by simp #align set.exists_range_iff Set.exists_range_iff @[deprecated (since := "2024-03-10")] alias exists_range_iff' := exists_range_iff #align set.exists_range_iff' Set.exists_range_iff' theorem exists_subtype_range_iff {p : range f → Prop} : (∃ a : range f, p a) ↔ ∃ i, p ⟨f i, mem_range_self _⟩ := ⟨fun ⟨⟨a, i, hi⟩, ha⟩ => by subst a exact ⟨i, ha⟩, fun ⟨i, hi⟩ => ⟨_, hi⟩⟩ #align set.exists_subtype_range_iff Set.exists_subtype_range_iff theorem range_iff_surjective : range f = univ ↔ Surjective f := eq_univ_iff_forall #align set.range_iff_surjective Set.range_iff_surjective alias ⟨_, _root_.Function.Surjective.range_eq⟩ := range_iff_surjective #align function.surjective.range_eq Function.Surjective.range_eq @[simp] theorem subset_range_of_surjective {f : α → β} (h : Surjective f) (s : Set β) : s ⊆ range f := Surjective.range_eq h ▸ subset_univ s @[simp] theorem image_univ {f : α → β} : f '' univ = range f := by ext simp [image, range] #align set.image_univ Set.image_univ @[simp] theorem preimage_eq_univ_iff {f : α → β} {s} : f ⁻¹' s = univ ↔ range f ⊆ s := by rw [← univ_subset_iff, ← image_subset_iff, image_univ] theorem image_subset_range (f : α → β) (s) : f '' s ⊆ range f := by rw [← image_univ]; exact image_subset _ (subset_univ _) #align set.image_subset_range Set.image_subset_range theorem mem_range_of_mem_image (f : α → β) (s) {x : β} (h : x ∈ f '' s) : x ∈ range f := image_subset_range f s h #align set.mem_range_of_mem_image Set.mem_range_of_mem_image theorem _root_.Nat.mem_range_succ (i : ℕ) : i ∈ range Nat.succ ↔ 0 < i := ⟨by rintro ⟨n, rfl⟩ exact Nat.succ_pos n, fun h => ⟨_, Nat.succ_pred_eq_of_pos h⟩⟩ #align nat.mem_range_succ Nat.mem_range_succ theorem Nonempty.preimage' {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : s ⊆ range f) : (f ⁻¹' s).Nonempty := let ⟨_, hy⟩ := hs let ⟨x, hx⟩ := hf hy ⟨x, Set.mem_preimage.2 <| hx.symm ▸ hy⟩ #align set.nonempty.preimage' Set.Nonempty.preimage' theorem range_comp (g : α → β) (f : ι → α) : range (g ∘ f) = g '' range f := by aesop #align set.range_comp Set.range_comp theorem range_subset_iff : range f ⊆ s ↔ ∀ y, f y ∈ s := forall_mem_range #align set.range_subset_iff Set.range_subset_iff theorem range_subset_range_iff_exists_comp {f : α → γ} {g : β → γ} : range f ⊆ range g ↔ ∃ h : α → β, f = g ∘ h := by simp only [range_subset_iff, mem_range, Classical.skolem, Function.funext_iff, (· ∘ ·), eq_comm] theorem range_eq_iff (f : α → β) (s : Set β) : range f = s ↔ (∀ a, f a ∈ s) ∧ ∀ b ∈ s, ∃ a, f a = b := by rw [← range_subset_iff] exact le_antisymm_iff #align set.range_eq_iff Set.range_eq_iff theorem range_comp_subset_range (f : α → β) (g : β → γ) : range (g ∘ f) ⊆ range g := by rw [range_comp]; apply image_subset_range #align set.range_comp_subset_range Set.range_comp_subset_range theorem range_nonempty_iff_nonempty : (range f).Nonempty ↔ Nonempty ι := ⟨fun ⟨_, x, _⟩ => ⟨x⟩, fun ⟨x⟩ => ⟨f x, mem_range_self x⟩⟩ #align set.range_nonempty_iff_nonempty Set.range_nonempty_iff_nonempty theorem range_nonempty [h : Nonempty ι] (f : ι → α) : (range f).Nonempty := range_nonempty_iff_nonempty.2 h #align set.range_nonempty Set.range_nonempty @[simp] theorem range_eq_empty_iff {f : ι → α} : range f = ∅ ↔ IsEmpty ι := by rw [← not_nonempty_iff, ← range_nonempty_iff_nonempty, not_nonempty_iff_eq_empty] #align set.range_eq_empty_iff Set.range_eq_empty_iff theorem range_eq_empty [IsEmpty ι] (f : ι → α) : range f = ∅ := range_eq_empty_iff.2 ‹_› #align set.range_eq_empty Set.range_eq_empty instance instNonemptyRange [Nonempty ι] (f : ι → α) : Nonempty (range f) := (range_nonempty f).to_subtype @[simp] theorem image_union_image_compl_eq_range (f : α → β) : f '' s ∪ f '' sᶜ = range f := by rw [← image_union, ← image_univ, ← union_compl_self] #align set.image_union_image_compl_eq_range Set.image_union_image_compl_eq_range theorem insert_image_compl_eq_range (f : α → β) (x : α) : insert (f x) (f '' {x}ᶜ) = range f := by rw [← image_insert_eq, insert_eq, union_compl_self, image_univ] #align set.insert_image_compl_eq_range Set.insert_image_compl_eq_range theorem image_preimage_eq_range_inter {f : α → β} {t : Set β} : f '' (f ⁻¹' t) = range f ∩ t := ext fun x => ⟨fun ⟨x, hx, HEq⟩ => HEq ▸ ⟨mem_range_self _, hx⟩, fun ⟨⟨y, h_eq⟩, hx⟩ => h_eq ▸ mem_image_of_mem f <| show y ∈ f ⁻¹' t by rw [preimage, mem_setOf, h_eq]; exact hx⟩ theorem image_preimage_eq_inter_range {f : α → β} {t : Set β} : f '' (f ⁻¹' t) = t ∩ range f := by rw [image_preimage_eq_range_inter, inter_comm] #align set.image_preimage_eq_inter_range Set.image_preimage_eq_inter_range theorem image_preimage_eq_of_subset {f : α → β} {s : Set β} (hs : s ⊆ range f) : f '' (f ⁻¹' s) = s := by rw [image_preimage_eq_range_inter, inter_eq_self_of_subset_right hs] #align set.image_preimage_eq_of_subset Set.image_preimage_eq_of_subset theorem image_preimage_eq_iff {f : α → β} {s : Set β} : f '' (f ⁻¹' s) = s ↔ s ⊆ range f := ⟨by intro h rw [← h] apply image_subset_range, image_preimage_eq_of_subset⟩ #align set.image_preimage_eq_iff Set.image_preimage_eq_iff theorem subset_range_iff_exists_image_eq {f : α → β} {s : Set β} : s ⊆ range f ↔ ∃ t, f '' t = s := ⟨fun h => ⟨_, image_preimage_eq_iff.2 h⟩, fun ⟨_, ht⟩ => ht ▸ image_subset_range _ _⟩ #align set.subset_range_iff_exists_image_eq Set.subset_range_iff_exists_image_eq theorem range_image (f : α → β) : range (image f) = 𝒫 range f := ext fun _ => subset_range_iff_exists_image_eq.symm #align set.range_image Set.range_image @[simp] theorem exists_subset_range_and_iff {f : α → β} {p : Set β → Prop} : (∃ s, s ⊆ range f ∧ p s) ↔ ∃ s, p (f '' s) := by rw [← exists_range_iff, range_image]; rfl #align set.exists_subset_range_and_iff Set.exists_subset_range_and_iff theorem exists_subset_range_iff {f : α → β} {p : Set β → Prop} : (∃ (s : _) (_ : s ⊆ range f), p s) ↔ ∃ s, p (f '' s) := by simp #align set.exists_subset_range_iff Set.exists_subset_range_iff theorem forall_subset_range_iff {f : α → β} {p : Set β → Prop} : (∀ s, s ⊆ range f → p s) ↔ ∀ s, p (f '' s) := by rw [← forall_mem_range, range_image]; rfl @[simp] theorem preimage_subset_preimage_iff {s t : Set α} {f : β → α} (hs : s ⊆ range f) : f ⁻¹' s ⊆ f ⁻¹' t ↔ s ⊆ t := by constructor · intro h x hx rcases hs hx with ⟨y, rfl⟩ exact h hx intro h x; apply h #align set.preimage_subset_preimage_iff Set.preimage_subset_preimage_iff theorem preimage_eq_preimage' {s t : Set α} {f : β → α} (hs : s ⊆ range f) (ht : t ⊆ range f) : f ⁻¹' s = f ⁻¹' t ↔ s = t := by constructor · intro h apply Subset.antisymm · rw [← preimage_subset_preimage_iff hs, h] · rw [← preimage_subset_preimage_iff ht, h] rintro rfl; rfl #align set.preimage_eq_preimage' Set.preimage_eq_preimage' -- Porting note: -- @[simp] `simp` can prove this theorem preimage_inter_range {f : α → β} {s : Set β} : f ⁻¹' (s ∩ range f) = f ⁻¹' s := Set.ext fun x => and_iff_left ⟨x, rfl⟩ #align set.preimage_inter_range Set.preimage_inter_range -- Porting note: -- @[simp] `simp` can prove this theorem preimage_range_inter {f : α → β} {s : Set β} : f ⁻¹' (range f ∩ s) = f ⁻¹' s := by rw [inter_comm, preimage_inter_range] #align set.preimage_range_inter Set.preimage_range_inter theorem preimage_image_preimage {f : α → β} {s : Set β} : f ⁻¹' (f '' (f ⁻¹' s)) = f ⁻¹' s := by rw [image_preimage_eq_range_inter, preimage_range_inter] #align set.preimage_image_preimage Set.preimage_image_preimage @[simp, mfld_simps] theorem range_id : range (@id α) = univ := range_iff_surjective.2 surjective_id #align set.range_id Set.range_id @[simp, mfld_simps] theorem range_id' : (range fun x : α => x) = univ := range_id #align set.range_id' Set.range_id' @[simp] theorem _root_.Prod.range_fst [Nonempty β] : range (Prod.fst : α × β → α) = univ := Prod.fst_surjective.range_eq #align prod.range_fst Prod.range_fst @[simp] theorem _root_.Prod.range_snd [Nonempty α] : range (Prod.snd : α × β → β) = univ := Prod.snd_surjective.range_eq #align prod.range_snd Prod.range_snd @[simp] theorem range_eval {α : ι → Sort _} [∀ i, Nonempty (α i)] (i : ι) : range (eval i : (∀ i, α i) → α i) = univ := (surjective_eval i).range_eq #align set.range_eval Set.range_eval theorem range_inl : range (@Sum.inl α β) = {x | Sum.isLeft x} := by ext (_|_) <;> simp #align set.range_inl Set.range_inl theorem range_inr : range (@Sum.inr α β) = {x | Sum.isRight x} := by ext (_|_) <;> simp #align set.range_inr Set.range_inr theorem isCompl_range_inl_range_inr : IsCompl (range <| @Sum.inl α β) (range Sum.inr) := IsCompl.of_le (by rintro y ⟨⟨x₁, rfl⟩, ⟨x₂, h⟩⟩ exact Sum.noConfusion h) (by rintro (x | y) - <;> [left; right] <;> exact mem_range_self _) #align set.is_compl_range_inl_range_inr Set.isCompl_range_inl_range_inr @[simp] theorem range_inl_union_range_inr : range (Sum.inl : α → Sum α β) ∪ range Sum.inr = univ := isCompl_range_inl_range_inr.sup_eq_top #align set.range_inl_union_range_inr Set.range_inl_union_range_inr @[simp] theorem range_inl_inter_range_inr : range (Sum.inl : α → Sum α β) ∩ range Sum.inr = ∅ := isCompl_range_inl_range_inr.inf_eq_bot #align set.range_inl_inter_range_inr Set.range_inl_inter_range_inr @[simp] theorem range_inr_union_range_inl : range (Sum.inr : β → Sum α β) ∪ range Sum.inl = univ := isCompl_range_inl_range_inr.symm.sup_eq_top #align set.range_inr_union_range_inl Set.range_inr_union_range_inl @[simp] theorem range_inr_inter_range_inl : range (Sum.inr : β → Sum α β) ∩ range Sum.inl = ∅ := isCompl_range_inl_range_inr.symm.inf_eq_bot #align set.range_inr_inter_range_inl Set.range_inr_inter_range_inl @[simp] theorem preimage_inl_image_inr (s : Set β) : Sum.inl ⁻¹' (@Sum.inr α β '' s) = ∅ := by ext simp #align set.preimage_inl_image_inr Set.preimage_inl_image_inr @[simp] theorem preimage_inr_image_inl (s : Set α) : Sum.inr ⁻¹' (@Sum.inl α β '' s) = ∅ := by ext simp #align set.preimage_inr_image_inl Set.preimage_inr_image_inl @[simp] theorem preimage_inl_range_inr : Sum.inl ⁻¹' range (Sum.inr : β → Sum α β) = ∅ := by rw [← image_univ, preimage_inl_image_inr] #align set.preimage_inl_range_inr Set.preimage_inl_range_inr @[simp] theorem preimage_inr_range_inl : Sum.inr ⁻¹' range (Sum.inl : α → Sum α β) = ∅ := by rw [← image_univ, preimage_inr_image_inl] #align set.preimage_inr_range_inl Set.preimage_inr_range_inl @[simp] theorem compl_range_inl : (range (Sum.inl : α → Sum α β))ᶜ = range (Sum.inr : β → Sum α β) := IsCompl.compl_eq isCompl_range_inl_range_inr #align set.compl_range_inl Set.compl_range_inl @[simp] theorem compl_range_inr : (range (Sum.inr : β → Sum α β))ᶜ = range (Sum.inl : α → Sum α β) := IsCompl.compl_eq isCompl_range_inl_range_inr.symm #align set.compl_range_inr Set.compl_range_inr theorem image_preimage_inl_union_image_preimage_inr (s : Set (Sum α β)) : Sum.inl '' (Sum.inl ⁻¹' s) ∪ Sum.inr '' (Sum.inr ⁻¹' s) = s := by rw [image_preimage_eq_inter_range, image_preimage_eq_inter_range, ← inter_union_distrib_left, range_inl_union_range_inr, inter_univ] #align set.image_preimage_inl_union_image_preimage_inr Set.image_preimage_inl_union_image_preimage_inr @[simp] theorem range_quot_mk (r : α → α → Prop) : range (Quot.mk r) = univ := (surjective_quot_mk r).range_eq #align set.range_quot_mk Set.range_quot_mk @[simp] theorem range_quot_lift {r : ι → ι → Prop} (hf : ∀ x y, r x y → f x = f y) : range (Quot.lift f hf) = range f := ext fun _ => (surjective_quot_mk _).exists #align set.range_quot_lift Set.range_quot_lift -- Porting note: the `Setoid α` instance is not being filled in @[simp] theorem range_quotient_mk [sa : Setoid α] : (range (α := Quotient sa) fun x : α => ⟦x⟧) = univ := range_quot_mk _ #align set.range_quotient_mk Set.range_quotient_mk @[simp] theorem range_quotient_lift [s : Setoid ι] (hf) : range (Quotient.lift f hf : Quotient s → α) = range f := range_quot_lift _ #align set.range_quotient_lift Set.range_quotient_lift @[simp] theorem range_quotient_mk' {s : Setoid α} : range (Quotient.mk' : α → Quotient s) = univ := range_quot_mk _ #align set.range_quotient_mk' Set.range_quotient_mk' @[simp] lemma Quotient.range_mk'' {sa : Setoid α} : range (Quotient.mk'' (s₁ := sa)) = univ := range_quotient_mk @[simp] theorem range_quotient_lift_on' {s : Setoid ι} (hf) : (range fun x : Quotient s => Quotient.liftOn' x f hf) = range f := range_quot_lift _ #align set.range_quotient_lift_on' Set.range_quotient_lift_on' instance canLift (c) (p) [CanLift α β c p] : CanLift (Set α) (Set β) (c '' ·) fun s => ∀ x ∈ s, p x where prf _ hs := subset_range_iff_exists_image_eq.mp fun x hx => CanLift.prf _ (hs x hx) #align set.can_lift Set.canLift theorem range_const_subset {c : α} : (range fun _ : ι => c) ⊆ {c} := range_subset_iff.2 fun _ => rfl #align set.range_const_subset Set.range_const_subset @[simp] theorem range_const : ∀ [Nonempty ι] {c : α}, (range fun _ : ι => c) = {c} | ⟨x⟩, _ => (Subset.antisymm range_const_subset) fun _ hy => (mem_singleton_iff.1 hy).symm ▸ mem_range_self x #align set.range_const Set.range_const theorem range_subtype_map {p : α → Prop} {q : β → Prop} (f : α → β) (h : ∀ x, p x → q (f x)) : range (Subtype.map f h) = (↑) ⁻¹' (f '' { x | p x }) := by ext ⟨x, hx⟩ rw [mem_preimage, mem_range, mem_image, Subtype.exists, Subtype.coe_mk] apply Iff.intro · rintro ⟨a, b, hab⟩ rw [Subtype.map, Subtype.mk.injEq] at hab use a trivial · rintro ⟨a, b, hab⟩ use a use b rw [Subtype.map, Subtype.mk.injEq] exact hab -- Porting note: `simp_rw` fails here -- simp_rw [mem_preimage, mem_range, mem_image, Subtype.exists, Subtype.map, Subtype.coe_mk, -- mem_set_of, exists_prop] #align set.range_subtype_map Set.range_subtype_map theorem image_swap_eq_preimage_swap : image (@Prod.swap α β) = preimage Prod.swap := image_eq_preimage_of_inverse Prod.swap_leftInverse Prod.swap_rightInverse #align set.image_swap_eq_preimage_swap Set.image_swap_eq_preimage_swap theorem preimage_singleton_nonempty {f : α → β} {y : β} : (f ⁻¹' {y}).Nonempty ↔ y ∈ range f := Iff.rfl #align set.preimage_singleton_nonempty Set.preimage_singleton_nonempty theorem preimage_singleton_eq_empty {f : α → β} {y : β} : f ⁻¹' {y} = ∅ ↔ y ∉ range f := not_nonempty_iff_eq_empty.symm.trans preimage_singleton_nonempty.not #align set.preimage_singleton_eq_empty Set.preimage_singleton_eq_empty theorem range_subset_singleton {f : ι → α} {x : α} : range f ⊆ {x} ↔ f = const ι x := by simp [range_subset_iff, funext_iff, mem_singleton] #align set.range_subset_singleton Set.range_subset_singleton theorem image_compl_preimage {f : α → β} {s : Set β} : f '' (f ⁻¹' s)ᶜ = range f \ s := by rw [compl_eq_univ_diff, image_diff_preimage, image_univ] #align set.image_compl_preimage Set.image_compl_preimage theorem rangeFactorization_eq {f : ι → β} : Subtype.val ∘ rangeFactorization f = f := funext fun _ => rfl #align set.range_factorization_eq Set.rangeFactorization_eq @[simp] theorem rangeFactorization_coe (f : ι → β) (a : ι) : (rangeFactorization f a : β) = f a := rfl #align set.range_factorization_coe Set.rangeFactorization_coe @[simp] theorem coe_comp_rangeFactorization (f : ι → β) : (↑) ∘ rangeFactorization f = f := rfl #align set.coe_comp_range_factorization Set.coe_comp_rangeFactorization theorem surjective_onto_range : Surjective (rangeFactorization f) := fun ⟨_, ⟨i, rfl⟩⟩ => ⟨i, rfl⟩ #align set.surjective_onto_range Set.surjective_onto_range theorem image_eq_range (f : α → β) (s : Set α) : f '' s = range fun x : s => f x := by ext constructor · rintro ⟨x, h1, h2⟩ exact ⟨⟨x, h1⟩, h2⟩ · rintro ⟨⟨x, h1⟩, h2⟩ exact ⟨x, h1, h2⟩ #align set.image_eq_range Set.image_eq_range theorem _root_.Sum.range_eq (f : Sum α β → γ) : range f = range (f ∘ Sum.inl) ∪ range (f ∘ Sum.inr) := ext fun _ => Sum.exists #align sum.range_eq Sum.range_eq @[simp] theorem Sum.elim_range (f : α → γ) (g : β → γ) : range (Sum.elim f g) = range f ∪ range g := Sum.range_eq _ #align set.sum.elim_range Set.Sum.elim_range theorem range_ite_subset' {p : Prop} [Decidable p] {f g : α → β} : range (if p then f else g) ⊆ range f ∪ range g := by by_cases h : p · rw [if_pos h] exact subset_union_left · rw [if_neg h] exact subset_union_right #align set.range_ite_subset' Set.range_ite_subset' theorem range_ite_subset {p : α → Prop} [DecidablePred p] {f g : α → β} : (range fun x => if p x then f x else g x) ⊆ range f ∪ range g := by rw [range_subset_iff]; intro x; by_cases h : p x · simp only [if_pos h, mem_union, mem_range, exists_apply_eq_apply, true_or] · simp [if_neg h, mem_union, mem_range_self] #align set.range_ite_subset Set.range_ite_subset @[simp] theorem preimage_range (f : α → β) : f ⁻¹' range f = univ := eq_univ_of_forall mem_range_self #align set.preimage_range Set.preimage_range /-- The range of a function from a `Unique` type contains just the function applied to its single value. -/ theorem range_unique [h : Unique ι] : range f = {f default} := by ext x rw [mem_range] constructor · rintro ⟨i, hi⟩ rw [h.uniq i] at hi exact hi ▸ mem_singleton _ · exact fun h => ⟨default, h.symm⟩ #align set.range_unique Set.range_unique theorem range_diff_image_subset (f : α → β) (s : Set α) : range f \ f '' s ⊆ f '' sᶜ := fun _ ⟨⟨x, h₁⟩, h₂⟩ => ⟨x, fun h => h₂ ⟨x, h, h₁⟩, h₁⟩ #align set.range_diff_image_subset Set.range_diff_image_subset theorem range_diff_image {f : α → β} (H : Injective f) (s : Set α) : range f \ f '' s = f '' sᶜ := (Subset.antisymm (range_diff_image_subset f s)) fun _ ⟨_, hx, hy⟩ => hy ▸ ⟨mem_range_self _, fun ⟨_, hx', Eq⟩ => hx <| H Eq ▸ hx'⟩ #align set.range_diff_image Set.range_diff_image @[simp] theorem range_inclusion (h : s ⊆ t) : range (inclusion h) = { x : t | (x : α) ∈ s } := by ext ⟨x, hx⟩ -- Porting note: `simp [inclusion]` doesn't solve goal apply Iff.intro · rw [mem_range] rintro ⟨a, ha⟩ rw [inclusion, Subtype.mk.injEq] at ha rw [mem_setOf, Subtype.coe_mk, ← ha] exact Subtype.coe_prop _ · rw [mem_setOf, Subtype.coe_mk, mem_range] intro hx' use ⟨x, hx'⟩ trivial -- simp_rw [inclusion, mem_range, Subtype.mk_eq_mk] -- rw [SetCoe.exists, Subtype.coe_mk, exists_prop, exists_eq_right, mem_set_of, Subtype.coe_mk] #align set.range_inclusion Set.range_inclusion -- When `f` is injective, see also `Equiv.ofInjective`. theorem leftInverse_rangeSplitting (f : α → β) : LeftInverse (rangeFactorization f) (rangeSplitting f) := fun x => by apply Subtype.ext -- Porting note: why doesn't `ext` find this lemma? simp only [rangeFactorization_coe] apply apply_rangeSplitting #align set.left_inverse_range_splitting Set.leftInverse_rangeSplitting theorem rangeSplitting_injective (f : α → β) : Injective (rangeSplitting f) := (leftInverse_rangeSplitting f).injective #align set.range_splitting_injective Set.rangeSplitting_injective theorem rightInverse_rangeSplitting {f : α → β} (h : Injective f) : RightInverse (rangeFactorization f) (rangeSplitting f) := (leftInverse_rangeSplitting f).rightInverse_of_injective fun _ _ hxy => h <| Subtype.ext_iff.1 hxy #align set.right_inverse_range_splitting Set.rightInverse_rangeSplitting theorem preimage_rangeSplitting {f : α → β} (hf : Injective f) : preimage (rangeSplitting f) = image (rangeFactorization f) := (image_eq_preimage_of_inverse (rightInverse_rangeSplitting hf) (leftInverse_rangeSplitting f)).symm #align set.preimage_range_splitting Set.preimage_rangeSplitting theorem isCompl_range_some_none (α : Type*) : IsCompl (range (some : α → Option α)) {none} := IsCompl.of_le (fun _ ⟨⟨_, ha⟩, (hn : _ = none)⟩ => Option.some_ne_none _ (ha.trans hn)) fun x _ => Option.casesOn x (Or.inr rfl) fun _ => Or.inl <| mem_range_self _ #align set.is_compl_range_some_none Set.isCompl_range_some_none @[simp] theorem compl_range_some (α : Type*) : (range (some : α → Option α))ᶜ = {none} := (isCompl_range_some_none α).compl_eq #align set.compl_range_some Set.compl_range_some @[simp] theorem range_some_inter_none (α : Type*) : range (some : α → Option α) ∩ {none} = ∅ := (isCompl_range_some_none α).inf_eq_bot #align set.range_some_inter_none Set.range_some_inter_none -- Porting note: -- @[simp] `simp` can prove this theorem range_some_union_none (α : Type*) : range (some : α → Option α) ∪ {none} = univ := (isCompl_range_some_none α).sup_eq_top #align set.range_some_union_none Set.range_some_union_none @[simp] theorem insert_none_range_some (α : Type*) : insert none (range (some : α → Option α)) = univ := (isCompl_range_some_none α).symm.sup_eq_top #align set.insert_none_range_some Set.insert_none_range_some end Range section Subsingleton variable {s : Set α} /-- The image of a subsingleton is a subsingleton. -/ theorem Subsingleton.image (hs : s.Subsingleton) (f : α → β) : (f '' s).Subsingleton := fun _ ⟨_, hx, Hx⟩ _ ⟨_, hy, Hy⟩ => Hx ▸ Hy ▸ congr_arg f (hs hx hy) #align set.subsingleton.image Set.Subsingleton.image /-- The preimage of a subsingleton under an injective map is a subsingleton. -/ theorem Subsingleton.preimage {s : Set β} (hs : s.Subsingleton) {f : α → β} (hf : Function.Injective f) : (f ⁻¹' s).Subsingleton := fun _ ha _ hb => hf <| hs ha hb #align set.subsingleton.preimage Set.Subsingleton.preimage /-- If the image of a set under an injective map is a subsingleton, the set is a subsingleton. -/ theorem subsingleton_of_image {f : α → β} (hf : Function.Injective f) (s : Set α) (hs : (f '' s).Subsingleton) : s.Subsingleton := (hs.preimage hf).anti <| subset_preimage_image _ _ #align set.subsingleton_of_image Set.subsingleton_of_image /-- If the preimage of a set under a surjective map is a subsingleton, the set is a subsingleton. -/ theorem subsingleton_of_preimage {f : α → β} (hf : Function.Surjective f) (s : Set β) (hs : (f ⁻¹' s).Subsingleton) : s.Subsingleton := fun fx hx fy hy => by rcases hf fx, hf fy with ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ exact congr_arg f (hs hx hy) #align set.subsingleton_of_preimage Set.subsingleton_of_preimage theorem subsingleton_range {α : Sort*} [Subsingleton α] (f : α → β) : (range f).Subsingleton := forall_mem_range.2 fun x => forall_mem_range.2 fun y => congr_arg f (Subsingleton.elim x y) #align set.subsingleton_range Set.subsingleton_range /-- The preimage of a nontrivial set under a surjective map is nontrivial. -/ theorem Nontrivial.preimage {s : Set β} (hs : s.Nontrivial) {f : α → β} (hf : Function.Surjective f) : (f ⁻¹' s).Nontrivial := by rcases hs with ⟨fx, hx, fy, hy, hxy⟩ rcases hf fx, hf fy with ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ exact ⟨x, hx, y, hy, mt (congr_arg f) hxy⟩ #align set.nontrivial.preimage Set.Nontrivial.preimage /-- The image of a nontrivial set under an injective map is nontrivial. -/ theorem Nontrivial.image (hs : s.Nontrivial) {f : α → β} (hf : Function.Injective f) : (f '' s).Nontrivial := let ⟨x, hx, y, hy, hxy⟩ := hs ⟨f x, mem_image_of_mem f hx, f y, mem_image_of_mem f hy, hf.ne hxy⟩ #align set.nontrivial.image Set.Nontrivial.image /-- If the image of a set is nontrivial, the set is nontrivial. -/ theorem nontrivial_of_image (f : α → β) (s : Set α) (hs : (f '' s).Nontrivial) : s.Nontrivial := let ⟨_, ⟨x, hx, rfl⟩, _, ⟨y, hy, rfl⟩, hxy⟩ := hs ⟨x, hx, y, hy, mt (congr_arg f) hxy⟩ #align set.nontrivial_of_image Set.nontrivial_of_image @[simp] theorem image_nontrivial {f : α → β} (hf : f.Injective) : (f '' s).Nontrivial ↔ s.Nontrivial := ⟨nontrivial_of_image f s, fun h ↦ h.image hf⟩ /-- If the preimage of a set under an injective map is nontrivial, the set is nontrivial. -/ theorem nontrivial_of_preimage {f : α → β} (hf : Function.Injective f) (s : Set β) (hs : (f ⁻¹' s).Nontrivial) : s.Nontrivial := (hs.image hf).mono <| image_preimage_subset _ _ #align set.nontrivial_of_preimage Set.nontrivial_of_preimage end Subsingleton end Set namespace Function variable {α β : Type*} {ι : Sort*} {f : α → β} open Set theorem Surjective.preimage_injective (hf : Surjective f) : Injective (preimage f) := fun _ _ => (preimage_eq_preimage hf).1 #align function.surjective.preimage_injective Function.Surjective.preimage_injective theorem Injective.preimage_image (hf : Injective f) (s : Set α) : f ⁻¹' (f '' s) = s := preimage_image_eq s hf #align function.injective.preimage_image Function.Injective.preimage_image theorem Injective.preimage_surjective (hf : Injective f) : Surjective (preimage f) := by intro s use f '' s rw [hf.preimage_image] #align function.injective.preimage_surjective Function.Injective.preimage_surjective theorem Injective.subsingleton_image_iff (hf : Injective f) {s : Set α} : (f '' s).Subsingleton ↔ s.Subsingleton := ⟨subsingleton_of_image hf s, fun h => h.image f⟩ #align function.injective.subsingleton_image_iff Function.Injective.subsingleton_image_iff theorem Surjective.image_preimage (hf : Surjective f) (s : Set β) : f '' (f ⁻¹' s) = s := image_preimage_eq s hf #align function.surjective.image_preimage Function.Surjective.image_preimage theorem Surjective.image_surjective (hf : Surjective f) : Surjective (image f) := by intro s use f ⁻¹' s rw [hf.image_preimage] #align function.surjective.image_surjective Function.Surjective.image_surjective @[simp] theorem Surjective.nonempty_preimage (hf : Surjective f) {s : Set β} : (f ⁻¹' s).Nonempty ↔ s.Nonempty := by rw [← image_nonempty, hf.image_preimage] #align function.surjective.nonempty_preimage Function.Surjective.nonempty_preimage theorem Injective.image_injective (hf : Injective f) : Injective (image f) := by intro s t h rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, h] #align function.injective.image_injective Function.Injective.image_injective theorem Surjective.preimage_subset_preimage_iff {s t : Set β} (hf : Surjective f) : f ⁻¹' s ⊆ f ⁻¹' t ↔ s ⊆ t := by apply Set.preimage_subset_preimage_iff rw [hf.range_eq] apply subset_univ #align function.surjective.preimage_subset_preimage_iff Function.Surjective.preimage_subset_preimage_iff theorem Surjective.range_comp {ι' : Sort*} {f : ι → ι'} (hf : Surjective f) (g : ι' → α) : range (g ∘ f) = range g := ext fun y => (@Surjective.exists _ _ _ hf fun x => g x = y).symm #align function.surjective.range_comp Function.Surjective.range_comp theorem Injective.mem_range_iff_exists_unique (hf : Injective f) {b : β} : b ∈ range f ↔ ∃! a, f a = b := ⟨fun ⟨a, h⟩ => ⟨a, h, fun _ ha => hf (ha.trans h.symm)⟩, ExistsUnique.exists⟩ #align function.injective.mem_range_iff_exists_unique Function.Injective.mem_range_iff_exists_unique theorem Injective.exists_unique_of_mem_range (hf : Injective f) {b : β} (hb : b ∈ range f) : ∃! a, f a = b := hf.mem_range_iff_exists_unique.mp hb #align function.injective.exists_unique_of_mem_range Function.Injective.exists_unique_of_mem_range theorem Injective.compl_image_eq (hf : Injective f) (s : Set α) : (f '' s)ᶜ = f '' sᶜ ∪ (range f)ᶜ := by ext y rcases em (y ∈ range f) with (⟨x, rfl⟩ | hx) · simp [hf.eq_iff] · rw [mem_range, not_exists] at hx simp [hx] #align function.injective.compl_image_eq Function.Injective.compl_image_eq theorem LeftInverse.image_image {g : β → α} (h : LeftInverse g f) (s : Set α) : g '' (f '' s) = s := by rw [← image_comp, h.comp_eq_id, image_id] #align function.left_inverse.image_image Function.LeftInverse.image_image theorem LeftInverse.preimage_preimage {g : β → α} (h : LeftInverse g f) (s : Set α) : f ⁻¹' (g ⁻¹' s) = s := by rw [← preimage_comp, h.comp_eq_id, preimage_id] #align function.left_inverse.preimage_preimage Function.LeftInverse.preimage_preimage protected theorem Involutive.preimage {f : α → α} (hf : Involutive f) : Involutive (preimage f) := hf.rightInverse.preimage_preimage #align function.involutive.preimage Function.Involutive.preimage end Function namespace EquivLike variable {ι ι' : Sort*} {E : Type*} [EquivLike E ι ι'] @[simp] lemma range_comp {α : Type*} (f : ι' → α) (e : E) : range (f ∘ e) = range f := (EquivLike.surjective _).range_comp _ #align equiv_like.range_comp EquivLike.range_comp end EquivLike /-! ### Image and preimage on subtypes -/ namespace Subtype variable {α : Type*} theorem coe_image {p : α → Prop} {s : Set (Subtype p)} : (↑) '' s = { x | ∃ h : p x, (⟨x, h⟩ : Subtype p) ∈ s } := Set.ext fun a => ⟨fun ⟨⟨_, ha'⟩, in_s, h_eq⟩ => h_eq ▸ ⟨ha', in_s⟩, fun ⟨ha, in_s⟩ => ⟨⟨a, ha⟩, in_s, rfl⟩⟩ #align subtype.coe_image Subtype.coe_image @[simp] theorem coe_image_of_subset {s t : Set α} (h : t ⊆ s) : (↑) '' { x : ↥s | ↑x ∈ t } = t := by ext x rw [mem_image] exact ⟨fun ⟨_, hx', hx⟩ => hx ▸ hx', fun hx => ⟨⟨x, h hx⟩, hx, rfl⟩⟩ #align subtype.coe_image_of_subset Subtype.coe_image_of_subset theorem range_coe {s : Set α} : range ((↑) : s → α) = s := by rw [← image_univ] simp [-image_univ, coe_image] #align subtype.range_coe Subtype.range_coe /-- A variant of `range_coe`. Try to use `range_coe` if possible. This version is useful when defining a new type that is defined as the subtype of something. In that case, the coercion doesn't fire anymore. -/ theorem range_val {s : Set α} : range (Subtype.val : s → α) = s := range_coe #align subtype.range_val Subtype.range_val /-- We make this the simp lemma instead of `range_coe`. The reason is that if we write for `s : Set α` the function `(↑) : s → α`, then the inferred implicit arguments of `(↑)` are `↑α (fun x ↦ x ∈ s)`. -/ @[simp] theorem range_coe_subtype {p : α → Prop} : range ((↑) : Subtype p → α) = { x | p x } := range_coe #align subtype.range_coe_subtype Subtype.range_coe_subtype @[simp] theorem coe_preimage_self (s : Set α) : ((↑) : s → α) ⁻¹' s = univ := by rw [← preimage_range, range_coe] #align subtype.coe_preimage_self Subtype.coe_preimage_self theorem range_val_subtype {p : α → Prop} : range (Subtype.val : Subtype p → α) = { x | p x } := range_coe #align subtype.range_val_subtype Subtype.range_val_subtype theorem coe_image_subset (s : Set α) (t : Set s) : ((↑) : s → α) '' t ⊆ s := fun x ⟨y, _, yvaleq⟩ => by rw [← yvaleq]; exact y.property #align subtype.coe_image_subset Subtype.coe_image_subset theorem coe_image_univ (s : Set α) : ((↑) : s → α) '' Set.univ = s := image_univ.trans range_coe #align subtype.coe_image_univ Subtype.coe_image_univ @[simp] theorem image_preimage_coe (s t : Set α) : ((↑) : s → α) '' (((↑) : s → α) ⁻¹' t) = s ∩ t := image_preimage_eq_range_inter.trans <| congr_arg (· ∩ t) range_coe #align subtype.image_preimage_coe Subtype.image_preimage_coe theorem image_preimage_val (s t : Set α) : (Subtype.val : s → α) '' (Subtype.val ⁻¹' t) = s ∩ t := image_preimage_coe s t #align subtype.image_preimage_val Subtype.image_preimage_val theorem preimage_coe_eq_preimage_coe_iff {s t u : Set α} : ((↑) : s → α) ⁻¹' t = ((↑) : s → α) ⁻¹' u ↔ s ∩ t = s ∩ u := by rw [← image_preimage_coe, ← image_preimage_coe, coe_injective.image_injective.eq_iff] #align subtype.preimage_coe_eq_preimage_coe_iff Subtype.preimage_coe_eq_preimage_coe_iff theorem preimage_coe_self_inter (s t : Set α) : ((↑) : s → α) ⁻¹' (s ∩ t) = ((↑) : s → α) ⁻¹' t := by rw [preimage_coe_eq_preimage_coe_iff, ← inter_assoc, inter_self] -- Porting note: -- @[simp] `simp` can prove this theorem preimage_coe_inter_self (s t : Set α) : ((↑) : s → α) ⁻¹' (t ∩ s) = ((↑) : s → α) ⁻¹' t := by rw [inter_comm, preimage_coe_self_inter] #align subtype.preimage_coe_inter_self Subtype.preimage_coe_inter_self theorem preimage_val_eq_preimage_val_iff (s t u : Set α) : (Subtype.val : s → α) ⁻¹' t = Subtype.val ⁻¹' u ↔ s ∩ t = s ∩ u := preimage_coe_eq_preimage_coe_iff #align subtype.preimage_val_eq_preimage_val_iff Subtype.preimage_val_eq_preimage_val_iff lemma preimage_val_subset_preimage_val_iff (s t u : Set α) : (Subtype.val ⁻¹' t : Set s) ⊆ Subtype.val ⁻¹' u ↔ s ∩ t ⊆ s ∩ u := by constructor · rw [← image_preimage_coe, ← image_preimage_coe] exact image_subset _ · intro h x a exact (h ⟨x.2, a⟩).2 theorem exists_set_subtype {t : Set α} (p : Set α → Prop) : (∃ s : Set t, p (((↑) : t → α) '' s)) ↔ ∃ s : Set α, s ⊆ t ∧ p s := by rw [← exists_subset_range_and_iff, range_coe] #align subtype.exists_set_subtype Subtype.exists_set_subtype theorem forall_set_subtype {t : Set α} (p : Set α → Prop) : (∀ s : Set t, p (((↑) : t → α) '' s)) ↔ ∀ s : Set α, s ⊆ t → p s := by rw [← forall_subset_range_iff, range_coe] theorem preimage_coe_nonempty {s t : Set α} : (((↑) : s → α) ⁻¹' t).Nonempty ↔ (s ∩ t).Nonempty := by rw [← image_preimage_coe, image_nonempty] #align subtype.preimage_coe_nonempty Subtype.preimage_coe_nonempty theorem preimage_coe_eq_empty {s t : Set α} : ((↑) : s → α) ⁻¹' t = ∅ ↔ s ∩ t = ∅ := by simp [← not_nonempty_iff_eq_empty, preimage_coe_nonempty] #align subtype.preimage_coe_eq_empty Subtype.preimage_coe_eq_empty -- Porting note: -- @[simp] `simp` can prove this theorem preimage_coe_compl (s : Set α) : ((↑) : s → α) ⁻¹' sᶜ = ∅ := preimage_coe_eq_empty.2 (inter_compl_self s) #align subtype.preimage_coe_compl Subtype.preimage_coe_compl @[simp] theorem preimage_coe_compl' (s : Set α) : (fun x : (sᶜ : Set α) => (x : α)) ⁻¹' s = ∅ := preimage_coe_eq_empty.2 (compl_inter_self s) #align subtype.preimage_coe_compl' Subtype.preimage_coe_compl' end Subtype /-! ### Images and preimages on `Option` -/ open Set namespace Option
Mathlib/Data/Set/Image.lean
1,490
1,496
theorem injective_iff {α β} {f : Option α → β} : Injective f ↔ Injective (f ∘ some) ∧ f none ∉ range (f ∘ some) := by
simp only [mem_range, not_exists, (· ∘ ·)] refine ⟨fun hf => ⟨hf.comp (Option.some_injective _), fun x => hf.ne <| Option.some_ne_none _⟩, ?_⟩ rintro ⟨h_some, h_none⟩ (_ | a) (_ | b) hab exacts [rfl, (h_none _ hab.symm).elim, (h_none _ hab).elim, congr_arg some (h_some hab)]
/- Copyright (c) 2022 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.Data.ENNReal.Basic import Mathlib.Topology.ContinuousFunction.Bounded import Mathlib.Topology.MetricSpace.Thickening #align_import topology.metric_space.thickened_indicator from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Thickened indicators This file is about thickened indicators of sets in (pseudo e)metric spaces. For a decreasing sequence of thickening radii tending to 0, the thickened indicators of a closed set form a decreasing pointwise converging approximation of the indicator function of the set, where the members of the approximating sequence are nonnegative bounded continuous functions. ## Main definitions * `thickenedIndicatorAux δ E`: The `δ`-thickened indicator of a set `E` as an unbundled `ℝ≥0∞`-valued function. * `thickenedIndicator δ E`: The `δ`-thickened indicator of a set `E` as a bundled bounded continuous `ℝ≥0`-valued function. ## Main results * For a sequence of thickening radii tending to 0, the `δ`-thickened indicators of a set `E` tend pointwise to the indicator of `closure E`. - `thickenedIndicatorAux_tendsto_indicator_closure`: The version is for the unbundled `ℝ≥0∞`-valued functions. - `thickenedIndicator_tendsto_indicator_closure`: The version is for the bundled `ℝ≥0`-valued bounded continuous functions. -/ open scoped Classical open NNReal ENNReal Topology BoundedContinuousFunction open NNReal ENNReal Set Metric EMetric Filter noncomputable section thickenedIndicator variable {α : Type*} [PseudoEMetricSpace α] /-- The `δ`-thickened indicator of a set `E` is the function that equals `1` on `E` and `0` outside a `δ`-thickening of `E` and interpolates (continuously) between these values using `infEdist _ E`. `thickenedIndicatorAux` is the unbundled `ℝ≥0∞`-valued function. See `thickenedIndicator` for the (bundled) bounded continuous function with `ℝ≥0`-values. -/ def thickenedIndicatorAux (δ : ℝ) (E : Set α) : α → ℝ≥0∞ := fun x : α => (1 : ℝ≥0∞) - infEdist x E / ENNReal.ofReal δ #align thickened_indicator_aux thickenedIndicatorAux theorem continuous_thickenedIndicatorAux {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : Continuous (thickenedIndicatorAux δ E) := by unfold thickenedIndicatorAux let f := fun x : α => (⟨1, infEdist x E / ENNReal.ofReal δ⟩ : ℝ≥0 × ℝ≥0∞) let sub := fun p : ℝ≥0 × ℝ≥0∞ => (p.1 : ℝ≥0∞) - p.2 rw [show (fun x : α => (1 : ℝ≥0∞) - infEdist x E / ENNReal.ofReal δ) = sub ∘ f by rfl] apply (@ENNReal.continuous_nnreal_sub 1).comp apply (ENNReal.continuous_div_const (ENNReal.ofReal δ) _).comp continuous_infEdist set_option tactic.skipAssignedInstances false in norm_num [δ_pos] #align continuous_thickened_indicator_aux continuous_thickenedIndicatorAux theorem thickenedIndicatorAux_le_one (δ : ℝ) (E : Set α) (x : α) : thickenedIndicatorAux δ E x ≤ 1 := by apply @tsub_le_self _ _ _ _ (1 : ℝ≥0∞) #align thickened_indicator_aux_le_one thickenedIndicatorAux_le_one theorem thickenedIndicatorAux_lt_top {δ : ℝ} {E : Set α} {x : α} : thickenedIndicatorAux δ E x < ∞ := lt_of_le_of_lt (thickenedIndicatorAux_le_one _ _ _) one_lt_top #align thickened_indicator_aux_lt_top thickenedIndicatorAux_lt_top theorem thickenedIndicatorAux_closure_eq (δ : ℝ) (E : Set α) : thickenedIndicatorAux δ (closure E) = thickenedIndicatorAux δ E := by simp (config := { unfoldPartialApp := true }) only [thickenedIndicatorAux, infEdist_closure] #align thickened_indicator_aux_closure_eq thickenedIndicatorAux_closure_eq theorem thickenedIndicatorAux_one (δ : ℝ) (E : Set α) {x : α} (x_in_E : x ∈ E) : thickenedIndicatorAux δ E x = 1 := by simp [thickenedIndicatorAux, infEdist_zero_of_mem x_in_E, tsub_zero] #align thickened_indicator_aux_one thickenedIndicatorAux_one theorem thickenedIndicatorAux_one_of_mem_closure (δ : ℝ) (E : Set α) {x : α} (x_mem : x ∈ closure E) : thickenedIndicatorAux δ E x = 1 := by rw [← thickenedIndicatorAux_closure_eq, thickenedIndicatorAux_one δ (closure E) x_mem] #align thickened_indicator_aux_one_of_mem_closure thickenedIndicatorAux_one_of_mem_closure theorem thickenedIndicatorAux_zero {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) {x : α} (x_out : x ∉ thickening δ E) : thickenedIndicatorAux δ E x = 0 := by rw [thickening, mem_setOf_eq, not_lt] at x_out unfold thickenedIndicatorAux apply le_antisymm _ bot_le have key := tsub_le_tsub (@rfl _ (1 : ℝ≥0∞)).le (ENNReal.div_le_div x_out (@rfl _ (ENNReal.ofReal δ : ℝ≥0∞)).le) rw [ENNReal.div_self (ne_of_gt (ENNReal.ofReal_pos.mpr δ_pos)) ofReal_ne_top] at key simpa using key #align thickened_indicator_aux_zero thickenedIndicatorAux_zero theorem thickenedIndicatorAux_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) : thickenedIndicatorAux δ₁ E ≤ thickenedIndicatorAux δ₂ E := fun _ => tsub_le_tsub (@rfl ℝ≥0∞ 1).le (ENNReal.div_le_div rfl.le (ofReal_le_ofReal hle)) #align thickened_indicator_aux_mono thickenedIndicatorAux_mono theorem indicator_le_thickenedIndicatorAux (δ : ℝ) (E : Set α) : (E.indicator fun _ => (1 : ℝ≥0∞)) ≤ thickenedIndicatorAux δ E := by intro a by_cases h : a ∈ E · simp only [h, indicator_of_mem, thickenedIndicatorAux_one δ E h, le_refl] · simp only [h, indicator_of_not_mem, not_false_iff, zero_le] #align indicator_le_thickened_indicator_aux indicator_le_thickenedIndicatorAux theorem thickenedIndicatorAux_subset (δ : ℝ) {E₁ E₂ : Set α} (subset : E₁ ⊆ E₂) : thickenedIndicatorAux δ E₁ ≤ thickenedIndicatorAux δ E₂ := fun _ => tsub_le_tsub (@rfl ℝ≥0∞ 1).le (ENNReal.div_le_div (infEdist_anti subset) rfl.le) #align thickened_indicator_aux_subset thickenedIndicatorAux_subset /-- As the thickening radius δ tends to 0, the δ-thickened indicator of a set E (in α) tends pointwise (i.e., w.r.t. the product topology on `α → ℝ≥0∞`) to the indicator function of the closure of E. This statement is for the unbundled `ℝ≥0∞`-valued functions `thickenedIndicatorAux δ E`, see `thickenedIndicator_tendsto_indicator_closure` for the version for bundled `ℝ≥0`-valued bounded continuous functions. -/ theorem thickenedIndicatorAux_tendsto_indicator_closure {δseq : ℕ → ℝ} (δseq_lim : Tendsto δseq atTop (𝓝 0)) (E : Set α) : Tendsto (fun n => thickenedIndicatorAux (δseq n) E) atTop (𝓝 (indicator (closure E) fun _ => (1 : ℝ≥0∞))) := by rw [tendsto_pi_nhds] intro x by_cases x_mem_closure : x ∈ closure E · simp_rw [thickenedIndicatorAux_one_of_mem_closure _ E x_mem_closure] rw [show (indicator (closure E) fun _ => (1 : ℝ≥0∞)) x = 1 by simp only [x_mem_closure, indicator_of_mem]] exact tendsto_const_nhds · rw [show (closure E).indicator (fun _ => (1 : ℝ≥0∞)) x = 0 by simp only [x_mem_closure, indicator_of_not_mem, not_false_iff]] rcases exists_real_pos_lt_infEdist_of_not_mem_closure x_mem_closure with ⟨ε, ⟨ε_pos, ε_lt⟩⟩ rw [Metric.tendsto_nhds] at δseq_lim specialize δseq_lim ε ε_pos simp only [dist_zero_right, Real.norm_eq_abs, eventually_atTop, ge_iff_le] at δseq_lim rcases δseq_lim with ⟨N, hN⟩ apply @tendsto_atTop_of_eventually_const _ _ _ _ _ _ _ N intro n n_large have key : x ∉ thickening ε E := by simpa only [thickening, mem_setOf_eq, not_lt] using ε_lt.le refine le_antisymm ?_ bot_le apply (thickenedIndicatorAux_mono (lt_of_abs_lt (hN n n_large)).le E x).trans exact (thickenedIndicatorAux_zero ε_pos E key).le #align thickened_indicator_aux_tendsto_indicator_closure thickenedIndicatorAux_tendsto_indicator_closure /-- The `δ`-thickened indicator of a set `E` is the function that equals `1` on `E` and `0` outside a `δ`-thickening of `E` and interpolates (continuously) between these values using `infEdist _ E`. `thickenedIndicator` is the (bundled) bounded continuous function with `ℝ≥0`-values. See `thickenedIndicatorAux` for the unbundled `ℝ≥0∞`-valued function. -/ @[simps] def thickenedIndicator {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : α →ᵇ ℝ≥0 where toFun := fun x : α => (thickenedIndicatorAux δ E x).toNNReal continuous_toFun := by apply ContinuousOn.comp_continuous continuousOn_toNNReal (continuous_thickenedIndicatorAux δ_pos E) intro x exact (lt_of_le_of_lt (@thickenedIndicatorAux_le_one _ _ δ E x) one_lt_top).ne map_bounded' := by use 2 intro x y rw [NNReal.dist_eq] apply (abs_sub _ _).trans rw [NNReal.abs_eq, NNReal.abs_eq, ← one_add_one_eq_two] have key := @thickenedIndicatorAux_le_one _ _ δ E apply add_le_add <;> · norm_cast exact (toNNReal_le_toNNReal (lt_of_le_of_lt (key _) one_lt_top).ne one_ne_top).mpr (key _) #align thickened_indicator thickenedIndicator theorem thickenedIndicator.coeFn_eq_comp {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : ⇑(thickenedIndicator δ_pos E) = ENNReal.toNNReal ∘ thickenedIndicatorAux δ E := rfl #align thickened_indicator.coe_fn_eq_comp thickenedIndicator.coeFn_eq_comp theorem thickenedIndicator_le_one {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) (x : α) : thickenedIndicator δ_pos E x ≤ 1 := by rw [thickenedIndicator.coeFn_eq_comp] simpa using (toNNReal_le_toNNReal thickenedIndicatorAux_lt_top.ne one_ne_top).mpr (thickenedIndicatorAux_le_one δ E x) #align thickened_indicator_le_one thickenedIndicator_le_one theorem thickenedIndicator_one_of_mem_closure {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) {x : α} (x_mem : x ∈ closure E) : thickenedIndicator δ_pos E x = 1 := by rw [thickenedIndicator_apply, thickenedIndicatorAux_one_of_mem_closure δ E x_mem, one_toNNReal] #align thickened_indicator_one_of_mem_closure thickenedIndicator_one_of_mem_closure lemma one_le_thickenedIndicator_apply' {X : Type _} [PseudoEMetricSpace X] {δ : ℝ} (δ_pos : 0 < δ) {F : Set X} {x : X} (hxF : x ∈ closure F) : 1 ≤ thickenedIndicator δ_pos F x := by rw [thickenedIndicator_one_of_mem_closure δ_pos F hxF] lemma one_le_thickenedIndicator_apply (X : Type _) [PseudoEMetricSpace X] {δ : ℝ} (δ_pos : 0 < δ) {F : Set X} {x : X} (hxF : x ∈ F) : 1 ≤ thickenedIndicator δ_pos F x := one_le_thickenedIndicator_apply' δ_pos (subset_closure hxF) theorem thickenedIndicator_one {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) {x : α} (x_in_E : x ∈ E) : thickenedIndicator δ_pos E x = 1 := thickenedIndicator_one_of_mem_closure _ _ (subset_closure x_in_E) #align thickened_indicator_one thickenedIndicator_one theorem thickenedIndicator_zero {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) {x : α} (x_out : x ∉ thickening δ E) : thickenedIndicator δ_pos E x = 0 := by rw [thickenedIndicator_apply, thickenedIndicatorAux_zero δ_pos E x_out, zero_toNNReal] #align thickened_indicator_zero thickenedIndicator_zero theorem indicator_le_thickenedIndicator {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : (E.indicator fun _ => (1 : ℝ≥0)) ≤ thickenedIndicator δ_pos E := by intro a by_cases h : a ∈ E · simp only [h, indicator_of_mem, thickenedIndicator_one δ_pos E h, le_refl] · simp only [h, indicator_of_not_mem, not_false_iff, zero_le] #align indicator_le_thickened_indicator indicator_le_thickenedIndicator
Mathlib/Topology/MetricSpace/ThickenedIndicator.lean
227
231
theorem thickenedIndicator_mono {δ₁ δ₂ : ℝ} (δ₁_pos : 0 < δ₁) (δ₂_pos : 0 < δ₂) (hle : δ₁ ≤ δ₂) (E : Set α) : ⇑(thickenedIndicator δ₁_pos E) ≤ thickenedIndicator δ₂_pos E := by
intro x apply (toNNReal_le_toNNReal thickenedIndicatorAux_lt_top.ne thickenedIndicatorAux_lt_top.ne).mpr apply thickenedIndicatorAux_mono hle
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Topology.Constructions #align_import topology.continuous_on from "leanprover-community/mathlib"@"d4f691b9e5f94cfc64639973f3544c95f8d5d494" /-! # Neighborhoods and continuity relative to a subset This file defines relative versions * `nhdsWithin` of `nhds` * `ContinuousOn` of `Continuous` * `ContinuousWithinAt` of `ContinuousAt` and proves their basic properties, including the relationships between these restricted notions and the corresponding notions for the subtype equipped with the subspace topology. ## Notation * `𝓝 x`: the filter of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`. -/ open Set Filter Function Topology Filter variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} variable [TopologicalSpace α] @[simp] theorem nhds_bind_nhdsWithin {a : α} {s : Set α} : ((𝓝 a).bind fun x => 𝓝[s] x) = 𝓝[s] a := bind_inf_principal.trans <| congr_arg₂ _ nhds_bind_nhds rfl #align nhds_bind_nhds_within nhds_bind_nhdsWithin @[simp] theorem eventually_nhds_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := Filter.ext_iff.1 nhds_bind_nhdsWithin { x | p x } #align eventually_nhds_nhds_within eventually_nhds_nhdsWithin theorem eventually_nhdsWithin_iff {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ x in 𝓝[s] a, p x) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → p x := eventually_inf_principal #align eventually_nhds_within_iff eventually_nhdsWithin_iff theorem frequently_nhdsWithin_iff {z : α} {s : Set α} {p : α → Prop} : (∃ᶠ x in 𝓝[s] z, p x) ↔ ∃ᶠ x in 𝓝 z, p x ∧ x ∈ s := frequently_inf_principal.trans <| by simp only [and_comm] #align frequently_nhds_within_iff frequently_nhdsWithin_iff theorem mem_closure_ne_iff_frequently_within {z : α} {s : Set α} : z ∈ closure (s \ {z}) ↔ ∃ᶠ x in 𝓝[≠] z, x ∈ s := by simp [mem_closure_iff_frequently, frequently_nhdsWithin_iff] #align mem_closure_ne_iff_frequently_within mem_closure_ne_iff_frequently_within @[simp] theorem eventually_nhdsWithin_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝[s] a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := by refine ⟨fun h => ?_, fun h => (eventually_nhds_nhdsWithin.2 h).filter_mono inf_le_left⟩ simp only [eventually_nhdsWithin_iff] at h ⊢ exact h.mono fun x hx hxs => (hx hxs).self_of_nhds hxs #align eventually_nhds_within_nhds_within eventually_nhdsWithin_nhdsWithin theorem nhdsWithin_eq (a : α) (s : Set α) : 𝓝[s] a = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (t ∩ s) := ((nhds_basis_opens a).inf_principal s).eq_biInf #align nhds_within_eq nhdsWithin_eq theorem nhdsWithin_univ (a : α) : 𝓝[Set.univ] a = 𝓝 a := by rw [nhdsWithin, principal_univ, inf_top_eq] #align nhds_within_univ nhdsWithin_univ theorem nhdsWithin_hasBasis {p : β → Prop} {s : β → Set α} {a : α} (h : (𝓝 a).HasBasis p s) (t : Set α) : (𝓝[t] a).HasBasis p fun i => s i ∩ t := h.inf_principal t #align nhds_within_has_basis nhdsWithin_hasBasis theorem nhdsWithin_basis_open (a : α) (t : Set α) : (𝓝[t] a).HasBasis (fun u => a ∈ u ∧ IsOpen u) fun u => u ∩ t := nhdsWithin_hasBasis (nhds_basis_opens a) t #align nhds_within_basis_open nhdsWithin_basis_open theorem mem_nhdsWithin {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u, IsOpen u ∧ a ∈ u ∧ u ∩ s ⊆ t := by simpa only [and_assoc, and_left_comm] using (nhdsWithin_basis_open a s).mem_iff #align mem_nhds_within mem_nhdsWithin theorem mem_nhdsWithin_iff_exists_mem_nhds_inter {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t := (nhdsWithin_hasBasis (𝓝 a).basis_sets s).mem_iff #align mem_nhds_within_iff_exists_mem_nhds_inter mem_nhdsWithin_iff_exists_mem_nhds_inter theorem diff_mem_nhdsWithin_compl {x : α} {s : Set α} (hs : s ∈ 𝓝 x) (t : Set α) : s \ t ∈ 𝓝[tᶜ] x := diff_mem_inf_principal_compl hs t #align diff_mem_nhds_within_compl diff_mem_nhdsWithin_compl theorem diff_mem_nhdsWithin_diff {x : α} {s t : Set α} (hs : s ∈ 𝓝[t] x) (t' : Set α) : s \ t' ∈ 𝓝[t \ t'] x := by rw [nhdsWithin, diff_eq, diff_eq, ← inf_principal, ← inf_assoc] exact inter_mem_inf hs (mem_principal_self _) #align diff_mem_nhds_within_diff diff_mem_nhdsWithin_diff theorem nhds_of_nhdsWithin_of_nhds {s t : Set α} {a : α} (h1 : s ∈ 𝓝 a) (h2 : t ∈ 𝓝[s] a) : t ∈ 𝓝 a := by rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.mp h2 with ⟨_, Hw, hw⟩ exact (𝓝 a).sets_of_superset ((𝓝 a).inter_sets Hw h1) hw #align nhds_of_nhds_within_of_nhds nhds_of_nhdsWithin_of_nhds theorem mem_nhdsWithin_iff_eventually {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ ∀ᶠ y in 𝓝 x, y ∈ s → y ∈ t := eventually_inf_principal #align mem_nhds_within_iff_eventually mem_nhdsWithin_iff_eventually theorem mem_nhdsWithin_iff_eventuallyEq {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ s =ᶠ[𝓝 x] (s ∩ t : Set α) := by simp_rw [mem_nhdsWithin_iff_eventually, eventuallyEq_set, mem_inter_iff, iff_self_and] #align mem_nhds_within_iff_eventually_eq mem_nhdsWithin_iff_eventuallyEq theorem nhdsWithin_eq_iff_eventuallyEq {s t : Set α} {x : α} : 𝓝[s] x = 𝓝[t] x ↔ s =ᶠ[𝓝 x] t := set_eventuallyEq_iff_inf_principal.symm #align nhds_within_eq_iff_eventually_eq nhdsWithin_eq_iff_eventuallyEq theorem nhdsWithin_le_iff {s t : Set α} {x : α} : 𝓝[s] x ≤ 𝓝[t] x ↔ t ∈ 𝓝[s] x := set_eventuallyLE_iff_inf_principal_le.symm.trans set_eventuallyLE_iff_mem_inf_principal #align nhds_within_le_iff nhdsWithin_le_iff -- Porting note: golfed, dropped an unneeded assumption theorem preimage_nhdsWithin_coinduced' {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) : π ⁻¹' s ∈ 𝓝[t] a := by lift a to t using h replace hs : (fun x : t => π x) ⁻¹' s ∈ 𝓝 a := preimage_nhds_coinduced hs rwa [← map_nhds_subtype_val, mem_map] #align preimage_nhds_within_coinduced' preimage_nhdsWithin_coinduced'ₓ theorem mem_nhdsWithin_of_mem_nhds {s t : Set α} {a : α} (h : s ∈ 𝓝 a) : s ∈ 𝓝[t] a := mem_inf_of_left h #align mem_nhds_within_of_mem_nhds mem_nhdsWithin_of_mem_nhds theorem self_mem_nhdsWithin {a : α} {s : Set α} : s ∈ 𝓝[s] a := mem_inf_of_right (mem_principal_self s) #align self_mem_nhds_within self_mem_nhdsWithin theorem eventually_mem_nhdsWithin {a : α} {s : Set α} : ∀ᶠ x in 𝓝[s] a, x ∈ s := self_mem_nhdsWithin #align eventually_mem_nhds_within eventually_mem_nhdsWithin theorem inter_mem_nhdsWithin (s : Set α) {t : Set α} {a : α} (h : t ∈ 𝓝 a) : s ∩ t ∈ 𝓝[s] a := inter_mem self_mem_nhdsWithin (mem_inf_of_left h) #align inter_mem_nhds_within inter_mem_nhdsWithin theorem nhdsWithin_mono (a : α) {s t : Set α} (h : s ⊆ t) : 𝓝[s] a ≤ 𝓝[t] a := inf_le_inf_left _ (principal_mono.mpr h) #align nhds_within_mono nhdsWithin_mono theorem pure_le_nhdsWithin {a : α} {s : Set α} (ha : a ∈ s) : pure a ≤ 𝓝[s] a := le_inf (pure_le_nhds a) (le_principal_iff.2 ha) #align pure_le_nhds_within pure_le_nhdsWithin theorem mem_of_mem_nhdsWithin {a : α} {s t : Set α} (ha : a ∈ s) (ht : t ∈ 𝓝[s] a) : a ∈ t := pure_le_nhdsWithin ha ht #align mem_of_mem_nhds_within mem_of_mem_nhdsWithin theorem Filter.Eventually.self_of_nhdsWithin {p : α → Prop} {s : Set α} {x : α} (h : ∀ᶠ y in 𝓝[s] x, p y) (hx : x ∈ s) : p x := mem_of_mem_nhdsWithin hx h #align filter.eventually.self_of_nhds_within Filter.Eventually.self_of_nhdsWithin theorem tendsto_const_nhdsWithin {l : Filter β} {s : Set α} {a : α} (ha : a ∈ s) : Tendsto (fun _ : β => a) l (𝓝[s] a) := tendsto_const_pure.mono_right <| pure_le_nhdsWithin ha #align tendsto_const_nhds_within tendsto_const_nhdsWithin theorem nhdsWithin_restrict'' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s] a = 𝓝[s ∩ t] a := le_antisymm (le_inf inf_le_left (le_principal_iff.mpr (inter_mem self_mem_nhdsWithin h))) (inf_le_inf_left _ (principal_mono.mpr Set.inter_subset_left)) #align nhds_within_restrict'' nhdsWithin_restrict'' theorem nhdsWithin_restrict' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝 a) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict'' s <| mem_inf_of_left h #align nhds_within_restrict' nhdsWithin_restrict' theorem nhdsWithin_restrict {a : α} (s : Set α) {t : Set α} (h₀ : a ∈ t) (h₁ : IsOpen t) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict' s (IsOpen.mem_nhds h₁ h₀) #align nhds_within_restrict nhdsWithin_restrict theorem nhdsWithin_le_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[t] a ≤ 𝓝[s] a := nhdsWithin_le_iff.mpr h #align nhds_within_le_of_mem nhdsWithin_le_of_mem theorem nhdsWithin_le_nhds {a : α} {s : Set α} : 𝓝[s] a ≤ 𝓝 a := by rw [← nhdsWithin_univ] apply nhdsWithin_le_of_mem exact univ_mem #align nhds_within_le_nhds nhdsWithin_le_nhds theorem nhdsWithin_eq_nhdsWithin' {a : α} {s t u : Set α} (hs : s ∈ 𝓝 a) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict' t hs, nhdsWithin_restrict' u hs, h₂] #align nhds_within_eq_nhds_within' nhdsWithin_eq_nhdsWithin' theorem nhdsWithin_eq_nhdsWithin {a : α} {s t u : Set α} (h₀ : a ∈ s) (h₁ : IsOpen s) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict t h₀ h₁, nhdsWithin_restrict u h₀ h₁, h₂] #align nhds_within_eq_nhds_within nhdsWithin_eq_nhdsWithin @[simp] theorem nhdsWithin_eq_nhds {a : α} {s : Set α} : 𝓝[s] a = 𝓝 a ↔ s ∈ 𝓝 a := inf_eq_left.trans le_principal_iff #align nhds_within_eq_nhds nhdsWithin_eq_nhds theorem IsOpen.nhdsWithin_eq {a : α} {s : Set α} (h : IsOpen s) (ha : a ∈ s) : 𝓝[s] a = 𝓝 a := nhdsWithin_eq_nhds.2 <| h.mem_nhds ha #align is_open.nhds_within_eq IsOpen.nhdsWithin_eq theorem preimage_nhds_within_coinduced {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (ht : IsOpen t) (hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) : π ⁻¹' s ∈ 𝓝 a := by rw [← ht.nhdsWithin_eq h] exact preimage_nhdsWithin_coinduced' h hs #align preimage_nhds_within_coinduced preimage_nhds_within_coinduced @[simp] theorem nhdsWithin_empty (a : α) : 𝓝[∅] a = ⊥ := by rw [nhdsWithin, principal_empty, inf_bot_eq] #align nhds_within_empty nhdsWithin_empty theorem nhdsWithin_union (a : α) (s t : Set α) : 𝓝[s ∪ t] a = 𝓝[s] a ⊔ 𝓝[t] a := by delta nhdsWithin rw [← inf_sup_left, sup_principal] #align nhds_within_union nhdsWithin_union theorem nhdsWithin_biUnion {ι} {I : Set ι} (hI : I.Finite) (s : ι → Set α) (a : α) : 𝓝[⋃ i ∈ I, s i] a = ⨆ i ∈ I, 𝓝[s i] a := Set.Finite.induction_on hI (by simp) fun _ _ hT ↦ by simp only [hT, nhdsWithin_union, iSup_insert, biUnion_insert] #align nhds_within_bUnion nhdsWithin_biUnion theorem nhdsWithin_sUnion {S : Set (Set α)} (hS : S.Finite) (a : α) : 𝓝[⋃₀ S] a = ⨆ s ∈ S, 𝓝[s] a := by rw [sUnion_eq_biUnion, nhdsWithin_biUnion hS] #align nhds_within_sUnion nhdsWithin_sUnion theorem nhdsWithin_iUnion {ι} [Finite ι] (s : ι → Set α) (a : α) : 𝓝[⋃ i, s i] a = ⨆ i, 𝓝[s i] a := by rw [← sUnion_range, nhdsWithin_sUnion (finite_range s), iSup_range] #align nhds_within_Union nhdsWithin_iUnion theorem nhdsWithin_inter (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓝[t] a := by delta nhdsWithin rw [inf_left_comm, inf_assoc, inf_principal, ← inf_assoc, inf_idem] #align nhds_within_inter nhdsWithin_inter theorem nhdsWithin_inter' (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓟 t := by delta nhdsWithin rw [← inf_principal, inf_assoc] #align nhds_within_inter' nhdsWithin_inter' theorem nhdsWithin_inter_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[s ∩ t] a = 𝓝[t] a := by rw [nhdsWithin_inter, inf_eq_right] exact nhdsWithin_le_of_mem h #align nhds_within_inter_of_mem nhdsWithin_inter_of_mem theorem nhdsWithin_inter_of_mem' {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s ∩ t] a = 𝓝[s] a := by rw [inter_comm, nhdsWithin_inter_of_mem h] #align nhds_within_inter_of_mem' nhdsWithin_inter_of_mem' @[simp] theorem nhdsWithin_singleton (a : α) : 𝓝[{a}] a = pure a := by rw [nhdsWithin, principal_singleton, inf_eq_right.2 (pure_le_nhds a)] #align nhds_within_singleton nhdsWithin_singleton @[simp] theorem nhdsWithin_insert (a : α) (s : Set α) : 𝓝[insert a s] a = pure a ⊔ 𝓝[s] a := by rw [← singleton_union, nhdsWithin_union, nhdsWithin_singleton] #align nhds_within_insert nhdsWithin_insert theorem mem_nhdsWithin_insert {a : α} {s t : Set α} : t ∈ 𝓝[insert a s] a ↔ a ∈ t ∧ t ∈ 𝓝[s] a := by simp #align mem_nhds_within_insert mem_nhdsWithin_insert theorem insert_mem_nhdsWithin_insert {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : insert a t ∈ 𝓝[insert a s] a := by simp [mem_of_superset h] #align insert_mem_nhds_within_insert insert_mem_nhdsWithin_insert theorem insert_mem_nhds_iff {a : α} {s : Set α} : insert a s ∈ 𝓝 a ↔ s ∈ 𝓝[≠] a := by simp only [nhdsWithin, mem_inf_principal, mem_compl_iff, mem_singleton_iff, or_iff_not_imp_left, insert_def] #align insert_mem_nhds_iff insert_mem_nhds_iff @[simp] theorem nhdsWithin_compl_singleton_sup_pure (a : α) : 𝓝[≠] a ⊔ pure a = 𝓝 a := by rw [← nhdsWithin_singleton, ← nhdsWithin_union, compl_union_self, nhdsWithin_univ] #align nhds_within_compl_singleton_sup_pure nhdsWithin_compl_singleton_sup_pure theorem nhdsWithin_prod {α : Type*} [TopologicalSpace α] {β : Type*} [TopologicalSpace β] {s u : Set α} {t v : Set β} {a : α} {b : β} (hu : u ∈ 𝓝[s] a) (hv : v ∈ 𝓝[t] b) : u ×ˢ v ∈ 𝓝[s ×ˢ t] (a, b) := by rw [nhdsWithin_prod_eq] exact prod_mem_prod hu hv #align nhds_within_prod nhdsWithin_prod theorem nhdsWithin_pi_eq' {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (α i)) (x : ∀ i, α i) : 𝓝[pi I s] x = ⨅ i, comap (fun x => x i) (𝓝 (x i) ⊓ ⨅ (_ : i ∈ I), 𝓟 (s i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, comap_inf, comap_iInf, pi_def, comap_principal, ← iInf_principal_finite hI, ← iInf_inf_eq] #align nhds_within_pi_eq' nhdsWithin_pi_eq' theorem nhdsWithin_pi_eq {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (α i)) (x : ∀ i, α i) : 𝓝[pi I s] x = (⨅ i ∈ I, comap (fun x => x i) (𝓝[s i] x i)) ⊓ ⨅ (i) (_ : i ∉ I), comap (fun x => x i) (𝓝 (x i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, pi_def, ← iInf_principal_finite hI, comap_inf, comap_principal, eval] rw [iInf_split _ fun i => i ∈ I, inf_right_comm] simp only [iInf_inf_eq] #align nhds_within_pi_eq nhdsWithin_pi_eq theorem nhdsWithin_pi_univ_eq {ι : Type*} {α : ι → Type*} [Finite ι] [∀ i, TopologicalSpace (α i)] (s : ∀ i, Set (α i)) (x : ∀ i, α i) : 𝓝[pi univ s] x = ⨅ i, comap (fun x => x i) (𝓝[s i] x i) := by simpa [nhdsWithin] using nhdsWithin_pi_eq finite_univ s x #align nhds_within_pi_univ_eq nhdsWithin_pi_univ_eq theorem nhdsWithin_pi_eq_bot {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : 𝓝[pi I s] x = ⊥ ↔ ∃ i ∈ I, 𝓝[s i] x i = ⊥ := by simp only [nhdsWithin, nhds_pi, pi_inf_principal_pi_eq_bot] #align nhds_within_pi_eq_bot nhdsWithin_pi_eq_bot theorem nhdsWithin_pi_neBot {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : (𝓝[pi I s] x).NeBot ↔ ∀ i ∈ I, (𝓝[s i] x i).NeBot := by simp [neBot_iff, nhdsWithin_pi_eq_bot] #align nhds_within_pi_ne_bot nhdsWithin_pi_neBot theorem Filter.Tendsto.piecewise_nhdsWithin {f g : α → β} {t : Set α} [∀ x, Decidable (x ∈ t)] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ t] a) l) (h₁ : Tendsto g (𝓝[s ∩ tᶜ] a) l) : Tendsto (piecewise t f g) (𝓝[s] a) l := by apply Tendsto.piecewise <;> rwa [← nhdsWithin_inter'] #align filter.tendsto.piecewise_nhds_within Filter.Tendsto.piecewise_nhdsWithin theorem Filter.Tendsto.if_nhdsWithin {f g : α → β} {p : α → Prop} [DecidablePred p] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ { x | p x }] a) l) (h₁ : Tendsto g (𝓝[s ∩ { x | ¬p x }] a) l) : Tendsto (fun x => if p x then f x else g x) (𝓝[s] a) l := h₀.piecewise_nhdsWithin h₁ #align filter.tendsto.if_nhds_within Filter.Tendsto.if_nhdsWithin theorem map_nhdsWithin (f : α → β) (a : α) (s : Set α) : map f (𝓝[s] a) = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (f '' (t ∩ s)) := ((nhdsWithin_basis_open a s).map f).eq_biInf #align map_nhds_within map_nhdsWithin theorem tendsto_nhdsWithin_mono_left {f : α → β} {a : α} {s t : Set α} {l : Filter β} (hst : s ⊆ t) (h : Tendsto f (𝓝[t] a) l) : Tendsto f (𝓝[s] a) l := h.mono_left <| nhdsWithin_mono a hst #align tendsto_nhds_within_mono_left tendsto_nhdsWithin_mono_left theorem tendsto_nhdsWithin_mono_right {f : β → α} {l : Filter β} {a : α} {s t : Set α} (hst : s ⊆ t) (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝[t] a) := h.mono_right (nhdsWithin_mono a hst) #align tendsto_nhds_within_mono_right tendsto_nhdsWithin_mono_right theorem tendsto_nhdsWithin_of_tendsto_nhds {f : α → β} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f (𝓝 a) l) : Tendsto f (𝓝[s] a) l := h.mono_left inf_le_left #align tendsto_nhds_within_of_tendsto_nhds tendsto_nhdsWithin_of_tendsto_nhds theorem eventually_mem_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : ∀ᶠ i in l, f i ∈ s := by simp_rw [nhdsWithin_eq, tendsto_iInf, mem_setOf_eq, tendsto_principal, mem_inter_iff, eventually_and] at h exact (h univ ⟨mem_univ a, isOpen_univ⟩).2 #align eventually_mem_of_tendsto_nhds_within eventually_mem_of_tendsto_nhdsWithin theorem tendsto_nhds_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝 a) := h.mono_right nhdsWithin_le_nhds #align tendsto_nhds_of_tendsto_nhds_within tendsto_nhds_of_tendsto_nhdsWithin theorem nhdsWithin_neBot_of_mem {s : Set α} {x : α} (hx : x ∈ s) : NeBot (𝓝[s] x) := mem_closure_iff_nhdsWithin_neBot.1 <| subset_closure hx #align nhds_within_ne_bot_of_mem nhdsWithin_neBot_of_mem theorem IsClosed.mem_of_nhdsWithin_neBot {s : Set α} (hs : IsClosed s) {x : α} (hx : NeBot <| 𝓝[s] x) : x ∈ s := hs.closure_eq ▸ mem_closure_iff_nhdsWithin_neBot.2 hx #align is_closed.mem_of_nhds_within_ne_bot IsClosed.mem_of_nhdsWithin_neBot theorem DenseRange.nhdsWithin_neBot {ι : Type*} {f : ι → α} (h : DenseRange f) (x : α) : NeBot (𝓝[range f] x) := mem_closure_iff_clusterPt.1 (h x) #align dense_range.nhds_within_ne_bot DenseRange.nhdsWithin_neBot theorem mem_closure_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : x ∈ closure (pi I s) ↔ ∀ i ∈ I, x i ∈ closure (s i) := by simp only [mem_closure_iff_nhdsWithin_neBot, nhdsWithin_pi_neBot] #align mem_closure_pi mem_closure_pi theorem closure_pi_set {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] (I : Set ι) (s : ∀ i, Set (α i)) : closure (pi I s) = pi I fun i => closure (s i) := Set.ext fun _ => mem_closure_pi #align closure_pi_set closure_pi_set theorem dense_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {s : ∀ i, Set (α i)} (I : Set ι) (hs : ∀ i ∈ I, Dense (s i)) : Dense (pi I s) := by simp only [dense_iff_closure_eq, closure_pi_set, pi_congr rfl fun i hi => (hs i hi).closure_eq, pi_univ] #align dense_pi dense_pi theorem eventuallyEq_nhdsWithin_iff {f g : α → β} {s : Set α} {a : α} : f =ᶠ[𝓝[s] a] g ↔ ∀ᶠ x in 𝓝 a, x ∈ s → f x = g x := mem_inf_principal #align eventually_eq_nhds_within_iff eventuallyEq_nhdsWithin_iff theorem eventuallyEq_nhdsWithin_of_eqOn {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) : f =ᶠ[𝓝[s] a] g := mem_inf_of_right h #align eventually_eq_nhds_within_of_eq_on eventuallyEq_nhdsWithin_of_eqOn theorem Set.EqOn.eventuallyEq_nhdsWithin {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) : f =ᶠ[𝓝[s] a] g := eventuallyEq_nhdsWithin_of_eqOn h #align set.eq_on.eventually_eq_nhds_within Set.EqOn.eventuallyEq_nhdsWithin theorem tendsto_nhdsWithin_congr {f g : α → β} {s : Set α} {a : α} {l : Filter β} (hfg : ∀ x ∈ s, f x = g x) (hf : Tendsto f (𝓝[s] a) l) : Tendsto g (𝓝[s] a) l := (tendsto_congr' <| eventuallyEq_nhdsWithin_of_eqOn hfg).1 hf #align tendsto_nhds_within_congr tendsto_nhdsWithin_congr theorem eventually_nhdsWithin_of_forall {s : Set α} {a : α} {p : α → Prop} (h : ∀ x ∈ s, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_inf_of_right h #align eventually_nhds_within_of_forall eventually_nhdsWithin_of_forall theorem tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within {a : α} {l : Filter β} {s : Set α} (f : β → α) (h1 : Tendsto f l (𝓝 a)) (h2 : ∀ᶠ x in l, f x ∈ s) : Tendsto f l (𝓝[s] a) := tendsto_inf.2 ⟨h1, tendsto_principal.2 h2⟩ #align tendsto_nhds_within_of_tendsto_nhds_of_eventually_within tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within theorem tendsto_nhdsWithin_iff {a : α} {l : Filter β} {s : Set α} {f : β → α} : Tendsto f l (𝓝[s] a) ↔ Tendsto f l (𝓝 a) ∧ ∀ᶠ n in l, f n ∈ s := ⟨fun h => ⟨tendsto_nhds_of_tendsto_nhdsWithin h, eventually_mem_of_tendsto_nhdsWithin h⟩, fun h => tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ h.1 h.2⟩ #align tendsto_nhds_within_iff tendsto_nhdsWithin_iff @[simp] theorem tendsto_nhdsWithin_range {a : α} {l : Filter β} {f : β → α} : Tendsto f l (𝓝[range f] a) ↔ Tendsto f l (𝓝 a) := ⟨fun h => h.mono_right inf_le_left, fun h => tendsto_inf.2 ⟨h, tendsto_principal.2 <| eventually_of_forall mem_range_self⟩⟩ #align tendsto_nhds_within_range tendsto_nhdsWithin_range theorem Filter.EventuallyEq.eq_of_nhdsWithin {s : Set α} {f g : α → β} {a : α} (h : f =ᶠ[𝓝[s] a] g) (hmem : a ∈ s) : f a = g a := h.self_of_nhdsWithin hmem #align filter.eventually_eq.eq_of_nhds_within Filter.EventuallyEq.eq_of_nhdsWithin theorem eventually_nhdsWithin_of_eventually_nhds {α : Type*} [TopologicalSpace α] {s : Set α} {a : α} {p : α → Prop} (h : ∀ᶠ x in 𝓝 a, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_nhdsWithin_of_mem_nhds h #align eventually_nhds_within_of_eventually_nhds eventually_nhdsWithin_of_eventually_nhds /-! ### `nhdsWithin` and subtypes -/ theorem mem_nhdsWithin_subtype {s : Set α} {a : { x // x ∈ s }} {t u : Set { x // x ∈ s }} : t ∈ 𝓝[u] a ↔ t ∈ comap ((↑) : s → α) (𝓝[(↑) '' u] a) := by rw [nhdsWithin, nhds_subtype, principal_subtype, ← comap_inf, ← nhdsWithin] #align mem_nhds_within_subtype mem_nhdsWithin_subtype theorem nhdsWithin_subtype (s : Set α) (a : { x // x ∈ s }) (t : Set { x // x ∈ s }) : 𝓝[t] a = comap ((↑) : s → α) (𝓝[(↑) '' t] a) := Filter.ext fun _ => mem_nhdsWithin_subtype #align nhds_within_subtype nhdsWithin_subtype theorem nhdsWithin_eq_map_subtype_coe {s : Set α} {a : α} (h : a ∈ s) : 𝓝[s] a = map ((↑) : s → α) (𝓝 ⟨a, h⟩) := (map_nhds_subtype_val ⟨a, h⟩).symm #align nhds_within_eq_map_subtype_coe nhdsWithin_eq_map_subtype_coe theorem mem_nhds_subtype_iff_nhdsWithin {s : Set α} {a : s} {t : Set s} : t ∈ 𝓝 a ↔ (↑) '' t ∈ 𝓝[s] (a : α) := by rw [← map_nhds_subtype_val, image_mem_map_iff Subtype.val_injective] #align mem_nhds_subtype_iff_nhds_within mem_nhds_subtype_iff_nhdsWithin theorem preimage_coe_mem_nhds_subtype {s t : Set α} {a : s} : (↑) ⁻¹' t ∈ 𝓝 a ↔ t ∈ 𝓝[s] ↑a := by rw [← map_nhds_subtype_val, mem_map] #align preimage_coe_mem_nhds_subtype preimage_coe_mem_nhds_subtype theorem eventually_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) : (∀ᶠ x : s in 𝓝 a, P x) ↔ ∀ᶠ x in 𝓝[s] a, P x := preimage_coe_mem_nhds_subtype theorem frequently_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) : (∃ᶠ x : s in 𝓝 a, P x) ↔ ∃ᶠ x in 𝓝[s] a, P x := eventually_nhds_subtype_iff s a (¬ P ·) |>.not theorem tendsto_nhdsWithin_iff_subtype {s : Set α} {a : α} (h : a ∈ s) (f : α → β) (l : Filter β) : Tendsto f (𝓝[s] a) l ↔ Tendsto (s.restrict f) (𝓝 ⟨a, h⟩) l := by rw [nhdsWithin_eq_map_subtype_coe h, tendsto_map'_iff]; rfl #align tendsto_nhds_within_iff_subtype tendsto_nhdsWithin_iff_subtype variable [TopologicalSpace β] [TopologicalSpace γ] [TopologicalSpace δ] /-- If a function is continuous within `s` at `x`, then it tends to `f x` within `s` by definition. We register this fact for use with the dot notation, especially to use `Filter.Tendsto.comp` as `ContinuousWithinAt.comp` will have a different meaning. -/ theorem ContinuousWithinAt.tendsto {f : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) : Tendsto f (𝓝[s] x) (𝓝 (f x)) := h #align continuous_within_at.tendsto ContinuousWithinAt.tendsto theorem ContinuousOn.continuousWithinAt {f : α → β} {s : Set α} {x : α} (hf : ContinuousOn f s) (hx : x ∈ s) : ContinuousWithinAt f s x := hf x hx #align continuous_on.continuous_within_at ContinuousOn.continuousWithinAt theorem continuousWithinAt_univ (f : α → β) (x : α) : ContinuousWithinAt f Set.univ x ↔ ContinuousAt f x := by rw [ContinuousAt, ContinuousWithinAt, nhdsWithin_univ] #align continuous_within_at_univ continuousWithinAt_univ theorem continuous_iff_continuousOn_univ {f : α → β} : Continuous f ↔ ContinuousOn f univ := by simp [continuous_iff_continuousAt, ContinuousOn, ContinuousAt, ContinuousWithinAt, nhdsWithin_univ] #align continuous_iff_continuous_on_univ continuous_iff_continuousOn_univ theorem continuousWithinAt_iff_continuousAt_restrict (f : α → β) {x : α} {s : Set α} (h : x ∈ s) : ContinuousWithinAt f s x ↔ ContinuousAt (s.restrict f) ⟨x, h⟩ := tendsto_nhdsWithin_iff_subtype h f _ #align continuous_within_at_iff_continuous_at_restrict continuousWithinAt_iff_continuousAt_restrict theorem ContinuousWithinAt.tendsto_nhdsWithin {f : α → β} {x : α} {s : Set α} {t : Set β} (h : ContinuousWithinAt f s x) (ht : MapsTo f s t) : Tendsto f (𝓝[s] x) (𝓝[t] f x) := tendsto_inf.2 ⟨h, tendsto_principal.2 <| mem_inf_of_right <| mem_principal.2 <| ht⟩ #align continuous_within_at.tendsto_nhds_within ContinuousWithinAt.tendsto_nhdsWithin theorem ContinuousWithinAt.tendsto_nhdsWithin_image {f : α → β} {x : α} {s : Set α} (h : ContinuousWithinAt f s x) : Tendsto f (𝓝[s] x) (𝓝[f '' s] f x) := h.tendsto_nhdsWithin (mapsTo_image _ _) #align continuous_within_at.tendsto_nhds_within_image ContinuousWithinAt.tendsto_nhdsWithin_image theorem ContinuousWithinAt.prod_map {f : α → γ} {g : β → δ} {s : Set α} {t : Set β} {x : α} {y : β} (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g t y) : ContinuousWithinAt (Prod.map f g) (s ×ˢ t) (x, y) := by unfold ContinuousWithinAt at * rw [nhdsWithin_prod_eq, Prod.map, nhds_prod_eq] exact hf.prod_map hg #align continuous_within_at.prod_map ContinuousWithinAt.prod_map theorem continuousWithinAt_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {s : Set (α × β)} {x : α × β} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨x.1, ·⟩) {b | (x.1, b) ∈ s} x.2 := by rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, pure_prod, ← map_inf_principal_preimage]; rfl theorem continuousWithinAt_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {s : Set (α × β)} {x : α × β} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨·, x.2⟩) {a | (a, x.2) ∈ s} x.1 := by rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, prod_pure, ← map_inf_principal_preimage]; rfl theorem continuousAt_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {x : α × β} : ContinuousAt f x ↔ ContinuousAt (f ⟨x.1, ·⟩) x.2 := by simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_left theorem continuousAt_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {x : α × β} : ContinuousAt f x ↔ ContinuousAt (f ⟨·, x.2⟩) x.1 := by simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_right
Mathlib/Topology/ContinuousOn.lean
581
583
theorem continuousOn_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {s : Set (α × β)} : ContinuousOn f s ↔ ∀ a, ContinuousOn (f ⟨a, ·⟩) {b | (a, b) ∈ s} := by
simp_rw [ContinuousOn, Prod.forall, continuousWithinAt_prod_of_discrete_left]; rfl
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Ring.Prod import Mathlib.GroupTheory.OrderOfElement import Mathlib.Tactic.FinCases #align_import data.zmod.basic from "leanprover-community/mathlib"@"74ad1c88c77e799d2fea62801d1dbbd698cff1b7" /-! # Integers mod `n` Definition of the integers mod n, and the field structure on the integers mod p. ## Definitions * `ZMod n`, which is for integers modulo a nat `n : ℕ` * `val a` is defined as a natural number: - for `a : ZMod 0` it is the absolute value of `a` - for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class * `valMinAbs` returns the integer closest to zero in the equivalence class. * A coercion `cast` is defined from `ZMod n` into any ring. This is a ring hom if the ring has characteristic dividing `n` -/ assert_not_exists Submodule open Function namespace ZMod instance charZero : CharZero (ZMod 0) := inferInstanceAs (CharZero ℤ) /-- `val a` is a natural number defined as: - for `a : ZMod 0` it is the absolute value of `a` - for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class See `ZMod.valMinAbs` for a variant that takes values in the integers. -/ def val : ∀ {n : ℕ}, ZMod n → ℕ | 0 => Int.natAbs | n + 1 => ((↑) : Fin (n + 1) → ℕ) #align zmod.val ZMod.val theorem val_lt {n : ℕ} [NeZero n] (a : ZMod n) : a.val < n := by cases n · cases NeZero.ne 0 rfl exact Fin.is_lt a #align zmod.val_lt ZMod.val_lt theorem val_le {n : ℕ} [NeZero n] (a : ZMod n) : a.val ≤ n := a.val_lt.le #align zmod.val_le ZMod.val_le @[simp] theorem val_zero : ∀ {n}, (0 : ZMod n).val = 0 | 0 => rfl | _ + 1 => rfl #align zmod.val_zero ZMod.val_zero @[simp] theorem val_one' : (1 : ZMod 0).val = 1 := rfl #align zmod.val_one' ZMod.val_one' @[simp] theorem val_neg' {n : ZMod 0} : (-n).val = n.val := Int.natAbs_neg n #align zmod.val_neg' ZMod.val_neg' @[simp] theorem val_mul' {m n : ZMod 0} : (m * n).val = m.val * n.val := Int.natAbs_mul m n #align zmod.val_mul' ZMod.val_mul' @[simp] theorem val_natCast {n : ℕ} (a : ℕ) : (a : ZMod n).val = a % n := by cases n · rw [Nat.mod_zero] exact Int.natAbs_ofNat a · apply Fin.val_natCast #align zmod.val_nat_cast ZMod.val_natCast @[deprecated (since := "2024-04-17")] alias val_nat_cast := val_natCast theorem val_unit' {n : ZMod 0} : IsUnit n ↔ n.val = 1 := by simp only [val] rw [Int.isUnit_iff, Int.natAbs_eq_iff, Nat.cast_one] lemma eq_one_of_isUnit_natCast {n : ℕ} (h : IsUnit (n : ZMod 0)) : n = 1 := by rw [← Nat.mod_zero n, ← val_natCast, val_unit'.mp h] theorem val_natCast_of_lt {n a : ℕ} (h : a < n) : (a : ZMod n).val = a := by rwa [val_natCast, Nat.mod_eq_of_lt] @[deprecated (since := "2024-04-17")] alias val_nat_cast_of_lt := val_natCast_of_lt instance charP (n : ℕ) : CharP (ZMod n) n where cast_eq_zero_iff' := by intro k cases' n with n · simp [zero_dvd_iff, Int.natCast_eq_zero, Nat.zero_eq] · exact Fin.natCast_eq_zero @[simp] theorem addOrderOf_one (n : ℕ) : addOrderOf (1 : ZMod n) = n := CharP.eq _ (CharP.addOrderOf_one _) (ZMod.charP n) #align zmod.add_order_of_one ZMod.addOrderOf_one /-- This lemma works in the case in which `ZMod n` is not infinite, i.e. `n ≠ 0`. The version where `a ≠ 0` is `addOrderOf_coe'`. -/ @[simp] theorem addOrderOf_coe (a : ℕ) {n : ℕ} (n0 : n ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by cases' a with a · simp only [Nat.zero_eq, Nat.cast_zero, addOrderOf_zero, Nat.gcd_zero_right, Nat.pos_of_ne_zero n0, Nat.div_self] rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a.succ_ne_zero, ZMod.addOrderOf_one] #align zmod.add_order_of_coe ZMod.addOrderOf_coe /-- This lemma works in the case in which `a ≠ 0`. The version where `ZMod n` is not infinite, i.e. `n ≠ 0`, is `addOrderOf_coe`. -/ @[simp] theorem addOrderOf_coe' {a : ℕ} (n : ℕ) (a0 : a ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a0, ZMod.addOrderOf_one] #align zmod.add_order_of_coe' ZMod.addOrderOf_coe' /-- We have that `ringChar (ZMod n) = n`. -/ theorem ringChar_zmod_n (n : ℕ) : ringChar (ZMod n) = n := by rw [ringChar.eq_iff] exact ZMod.charP n #align zmod.ring_char_zmod_n ZMod.ringChar_zmod_n -- @[simp] -- Porting note (#10618): simp can prove this theorem natCast_self (n : ℕ) : (n : ZMod n) = 0 := CharP.cast_eq_zero (ZMod n) n #align zmod.nat_cast_self ZMod.natCast_self @[deprecated (since := "2024-04-17")] alias nat_cast_self := natCast_self @[simp] theorem natCast_self' (n : ℕ) : (n + 1 : ZMod (n + 1)) = 0 := by rw [← Nat.cast_add_one, natCast_self (n + 1)] #align zmod.nat_cast_self' ZMod.natCast_self' @[deprecated (since := "2024-04-17")] alias nat_cast_self' := natCast_self' section UniversalProperty variable {n : ℕ} {R : Type*} section variable [AddGroupWithOne R] /-- Cast an integer modulo `n` to another semiring. This function is a morphism if the characteristic of `R` divides `n`. See `ZMod.castHom` for a bundled version. -/ def cast : ∀ {n : ℕ}, ZMod n → R | 0 => Int.cast | _ + 1 => fun i => i.val #align zmod.cast ZMod.cast @[simp] theorem cast_zero : (cast (0 : ZMod n) : R) = 0 := by delta ZMod.cast cases n · exact Int.cast_zero · simp #align zmod.cast_zero ZMod.cast_zero theorem cast_eq_val [NeZero n] (a : ZMod n) : (cast a : R) = a.val := by cases n · cases NeZero.ne 0 rfl rfl #align zmod.cast_eq_val ZMod.cast_eq_val variable {S : Type*} [AddGroupWithOne S] @[simp] theorem _root_.Prod.fst_zmod_cast (a : ZMod n) : (cast a : R × S).fst = cast a := by cases n · rfl · simp [ZMod.cast] #align prod.fst_zmod_cast Prod.fst_zmod_cast @[simp] theorem _root_.Prod.snd_zmod_cast (a : ZMod n) : (cast a : R × S).snd = cast a := by cases n · rfl · simp [ZMod.cast] #align prod.snd_zmod_cast Prod.snd_zmod_cast end /-- So-named because the coercion is `Nat.cast` into `ZMod`. For `Nat.cast` into an arbitrary ring, see `ZMod.natCast_val`. -/ theorem natCast_zmod_val {n : ℕ} [NeZero n] (a : ZMod n) : (a.val : ZMod n) = a := by cases n · cases NeZero.ne 0 rfl · apply Fin.cast_val_eq_self #align zmod.nat_cast_zmod_val ZMod.natCast_zmod_val @[deprecated (since := "2024-04-17")] alias nat_cast_zmod_val := natCast_zmod_val theorem natCast_rightInverse [NeZero n] : Function.RightInverse val ((↑) : ℕ → ZMod n) := natCast_zmod_val #align zmod.nat_cast_right_inverse ZMod.natCast_rightInverse @[deprecated (since := "2024-04-17")] alias nat_cast_rightInverse := natCast_rightInverse theorem natCast_zmod_surjective [NeZero n] : Function.Surjective ((↑) : ℕ → ZMod n) := natCast_rightInverse.surjective #align zmod.nat_cast_zmod_surjective ZMod.natCast_zmod_surjective @[deprecated (since := "2024-04-17")] alias nat_cast_zmod_surjective := natCast_zmod_surjective /-- So-named because the outer coercion is `Int.cast` into `ZMod`. For `Int.cast` into an arbitrary ring, see `ZMod.intCast_cast`. -/ @[norm_cast] theorem intCast_zmod_cast (a : ZMod n) : ((cast a : ℤ) : ZMod n) = a := by cases n · simp [ZMod.cast, ZMod] · dsimp [ZMod.cast, ZMod] erw [Int.cast_natCast, Fin.cast_val_eq_self] #align zmod.int_cast_zmod_cast ZMod.intCast_zmod_cast @[deprecated (since := "2024-04-17")] alias int_cast_zmod_cast := intCast_zmod_cast theorem intCast_rightInverse : Function.RightInverse (cast : ZMod n → ℤ) ((↑) : ℤ → ZMod n) := intCast_zmod_cast #align zmod.int_cast_right_inverse ZMod.intCast_rightInverse @[deprecated (since := "2024-04-17")] alias int_cast_rightInverse := intCast_rightInverse theorem intCast_surjective : Function.Surjective ((↑) : ℤ → ZMod n) := intCast_rightInverse.surjective #align zmod.int_cast_surjective ZMod.intCast_surjective @[deprecated (since := "2024-04-17")] alias int_cast_surjective := intCast_surjective theorem cast_id : ∀ (n) (i : ZMod n), (ZMod.cast i : ZMod n) = i | 0, _ => Int.cast_id | _ + 1, i => natCast_zmod_val i #align zmod.cast_id ZMod.cast_id @[simp] theorem cast_id' : (ZMod.cast : ZMod n → ZMod n) = id := funext (cast_id n) #align zmod.cast_id' ZMod.cast_id' variable (R) [Ring R] /-- The coercions are respectively `Nat.cast` and `ZMod.cast`. -/ @[simp]
Mathlib/Data/ZMod/Basic.lean
273
276
theorem natCast_comp_val [NeZero n] : ((↑) : ℕ → R) ∘ (val : ZMod n → ℕ) = cast := by
cases n · cases NeZero.ne 0 rfl rfl
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Products.Basic import Mathlib.CategoryTheory.Functor.Currying import Mathlib.CategoryTheory.Products.Bifunctor #align_import category_theory.limits.fubini from "leanprover-community/mathlib"@"59382264386afdbaf1727e617f5fdda511992eb9" /-! # A Fubini theorem for categorical (co)limits We prove that $lim_{J × K} G = lim_J (lim_K G(j, -))$ for a functor `G : J × K ⥤ C`, when all the appropriate limits exist. We begin working with a functor `F : J ⥤ K ⥤ C`. We'll write `G : J × K ⥤ C` for the associated "uncurried" functor. In the first part, given a coherent family `D` of limit cones over the functors `F.obj j`, and a cone `c` over `G`, we construct a cone over the cone points of `D`. We then show that if `c` is a limit cone, the constructed cone is also a limit cone. In the second part, we state the Fubini theorem in the setting where limits are provided by suitable `HasLimit` classes. We construct `limitUncurryIsoLimitCompLim F : limit (uncurry.obj F) ≅ limit (F ⋙ lim)` and give simp lemmas characterising it. For convenience, we also provide `limitIsoLimitCurryCompLim G : limit G ≅ limit ((curry.obj G) ⋙ lim)` in terms of the uncurried functor. All statements have their counterpart for colimits. -/ universe v u open CategoryTheory namespace CategoryTheory.Limits variable {J K : Type v} [SmallCategory J] [SmallCategory K] variable {C : Type u} [Category.{v} C] variable (F : J ⥤ K ⥤ C) -- We could try introducing a "dependent functor type" to handle this? /-- A structure carrying a diagram of cones over the functors `F.obj j`. -/ structure DiagramOfCones where /-- For each object, a cone. -/ obj : ∀ j : J, Cone (F.obj j) /-- For each map, a map of cones. -/ map : ∀ {j j' : J} (f : j ⟶ j'), (Cones.postcompose (F.map f)).obj (obj j) ⟶ obj j' id : ∀ j : J, (map (𝟙 j)).hom = 𝟙 _ := by aesop_cat comp : ∀ {j₁ j₂ j₃ : J} (f : j₁ ⟶ j₂) (g : j₂ ⟶ j₃), (map (f ≫ g)).hom = (map f).hom ≫ (map g).hom := by aesop_cat #align category_theory.limits.diagram_of_cones CategoryTheory.Limits.DiagramOfCones /-- A structure carrying a diagram of cocones over the functors `F.obj j`. -/ structure DiagramOfCocones where /-- For each object, a cocone. -/ obj : ∀ j : J, Cocone (F.obj j) /-- For each map, a map of cocones. -/ map : ∀ {j j' : J} (f : j ⟶ j'), (obj j) ⟶ (Cocones.precompose (F.map f)).obj (obj j') id : ∀ j : J, (map (𝟙 j)).hom = 𝟙 _ := by aesop_cat comp : ∀ {j₁ j₂ j₃ : J} (f : j₁ ⟶ j₂) (g : j₂ ⟶ j₃), (map (f ≫ g)).hom = (map f).hom ≫ (map g).hom := by aesop_cat variable {F} /-- Extract the functor `J ⥤ C` consisting of the cone points and the maps between them, from a `DiagramOfCones`. -/ @[simps] def DiagramOfCones.conePoints (D : DiagramOfCones F) : J ⥤ C where obj j := (D.obj j).pt map f := (D.map f).hom map_id j := D.id j map_comp f g := D.comp f g #align category_theory.limits.diagram_of_cones.cone_points CategoryTheory.Limits.DiagramOfCones.conePoints /-- Extract the functor `J ⥤ C` consisting of the cocone points and the maps between them, from a `DiagramOfCocones`. -/ @[simps] def DiagramOfCocones.coconePoints (D : DiagramOfCocones F) : J ⥤ C where obj j := (D.obj j).pt map f := (D.map f).hom map_id j := D.id j map_comp f g := D.comp f g /-- Given a diagram `D` of limit cones over the `F.obj j`, and a cone over `uncurry.obj F`, we can construct a cone over the diagram consisting of the cone points from `D`. -/ @[simps] def coneOfConeUncurry {D : DiagramOfCones F} (Q : ∀ j, IsLimit (D.obj j)) (c : Cone (uncurry.obj F)) : Cone D.conePoints where pt := c.pt π := { app := fun j => (Q j).lift { pt := c.pt π := { app := fun k => c.π.app (j, k) naturality := fun k k' f => by dsimp; simp only [Category.id_comp] have := @NatTrans.naturality _ _ _ _ _ _ c.π (j, k) (j, k') (𝟙 j, f) dsimp at this simp? at this says simp only [Category.id_comp, Functor.map_id, NatTrans.id_app] at this exact this } } naturality := fun j j' f => (Q j').hom_ext (by dsimp intro k simp only [Limits.ConeMorphism.w, Limits.Cones.postcompose_obj_π, Limits.IsLimit.fac_assoc, Limits.IsLimit.fac, NatTrans.comp_app, Category.id_comp, Category.assoc] have := @NatTrans.naturality _ _ _ _ _ _ c.π (j, k) (j', k) (f, 𝟙 k) dsimp at this simp only [Category.id_comp, Category.comp_id, CategoryTheory.Functor.map_id, NatTrans.id_app] at this exact this) } #align category_theory.limits.cone_of_cone_uncurry CategoryTheory.Limits.coneOfConeUncurry /-- Given a diagram `D` of colimit cocones over the `F.obj j`, and a cocone over `uncurry.obj F`, we can construct a cocone over the diagram consisting of the cocone points from `D`. -/ @[simps] def coconeOfCoconeUncurry {D : DiagramOfCocones F} (Q : ∀ j, IsColimit (D.obj j)) (c : Cocone (uncurry.obj F)) : Cocone D.coconePoints where pt := c.pt ι := { app := fun j => (Q j).desc { pt := c.pt ι := { app := fun k => c.ι.app (j, k) naturality := fun k k' f => by dsimp; simp only [Category.comp_id] conv_lhs => arg 1; equals (F.map (𝟙 _)).app _ ≫ (F.obj j).map f => simp; conv_lhs => arg 1; rw [← uncurry_obj_map F ((𝟙 j,f) : (j,k) ⟶ (j,k'))] rw [c.w] } } naturality := fun j j' f => (Q j).hom_ext (by dsimp intro k simp only [Limits.CoconeMorphism.w_assoc, Limits.Cocones.precompose_obj_ι, Limits.IsColimit.fac_assoc, Limits.IsColimit.fac, NatTrans.comp_app, Category.comp_id, Category.assoc] have := @NatTrans.naturality _ _ _ _ _ _ c.ι (j, k) (j', k) (f, 𝟙 k) dsimp at this simp only [Category.id_comp, Category.comp_id, CategoryTheory.Functor.map_id, NatTrans.id_app] at this exact this) } /-- `coneOfConeUncurry Q c` is a limit cone when `c` is a limit cone. -/ def coneOfConeUncurryIsLimit {D : DiagramOfCones F} (Q : ∀ j, IsLimit (D.obj j)) {c : Cone (uncurry.obj F)} (P : IsLimit c) : IsLimit (coneOfConeUncurry Q c) where lift s := P.lift { pt := s.pt π := { app := fun p => s.π.app p.1 ≫ (D.obj p.1).π.app p.2 naturality := fun p p' f => by dsimp; simp only [Category.id_comp, Category.assoc] rcases p with ⟨j, k⟩ rcases p' with ⟨j', k'⟩ rcases f with ⟨fj, fk⟩ dsimp slice_rhs 3 4 => rw [← NatTrans.naturality] slice_rhs 2 3 => rw [← (D.obj j).π.naturality] simp only [Functor.const_obj_map, Category.id_comp, Category.assoc] have w := (D.map fj).w k' dsimp at w rw [← w] have n := s.π.naturality fj dsimp at n simp only [Category.id_comp] at n rw [n] simp } } fac s j := by apply (Q j).hom_ext intro k simp uniq s m w := by refine P.uniq { pt := s.pt π := _ } m ?_ rintro ⟨j, k⟩ dsimp rw [← w j] simp #align category_theory.limits.cone_of_cone_uncurry_is_limit CategoryTheory.Limits.coneOfConeUncurryIsLimit /-- `coconeOfCoconeUncurry Q c` is a colimit cocone when `c` is a colimit cocone. -/ def coconeOfCoconeUncurryIsColimit {D : DiagramOfCocones F} (Q : ∀ j, IsColimit (D.obj j)) {c : Cocone (uncurry.obj F)} (P : IsColimit c) : IsColimit (coconeOfCoconeUncurry Q c) where desc s := P.desc { pt := s.pt ι := { app := fun p => (D.obj p.1).ι.app p.2 ≫ s.ι.app p.1 naturality := fun p p' f => by dsimp; simp only [Category.id_comp, Category.assoc] rcases p with ⟨j, k⟩ rcases p' with ⟨j', k'⟩ rcases f with ⟨fj, fk⟩ dsimp slice_lhs 2 3 => rw [(D.obj j').ι.naturality] simp only [Functor.const_obj_map, Category.id_comp, Category.assoc] have w := (D.map fj).w k dsimp at w slice_lhs 1 2 => rw [← w] have n := s.ι.naturality fj dsimp at n simp only [Category.comp_id] at n rw [← n] simp } } fac s j := by apply (Q j).hom_ext intro k simp uniq s m w := by refine P.uniq { pt := s.pt ι := _ } m ?_ rintro ⟨j, k⟩ dsimp rw [← w j] simp section variable (F) variable [HasLimitsOfShape K C] /-- Given a functor `F : J ⥤ K ⥤ C`, with all needed limits, we can construct a diagram consisting of the limit cone over each functor `F.obj j`, and the universal cone morphisms between these. -/ @[simps] noncomputable def DiagramOfCones.mkOfHasLimits : DiagramOfCones F where obj j := limit.cone (F.obj j) map f := { hom := lim.map (F.map f) } #align category_theory.limits.diagram_of_cones.mk_of_has_limits CategoryTheory.Limits.DiagramOfCones.mkOfHasLimits -- Satisfying the inhabited linter. noncomputable instance diagramOfConesInhabited : Inhabited (DiagramOfCones F) := ⟨DiagramOfCones.mkOfHasLimits F⟩ #align category_theory.limits.diagram_of_cones_inhabited CategoryTheory.Limits.diagramOfConesInhabited @[simp] theorem DiagramOfCones.mkOfHasLimits_conePoints : (DiagramOfCones.mkOfHasLimits F).conePoints = F ⋙ lim := rfl #align category_theory.limits.diagram_of_cones.mk_of_has_limits_cone_points CategoryTheory.Limits.DiagramOfCones.mkOfHasLimits_conePoints variable [HasLimit (uncurry.obj F)] variable [HasLimit (F ⋙ lim)] /-- The Fubini theorem for a functor `F : J ⥤ K ⥤ C`, showing that the limit of `uncurry.obj F` can be computed as the limit of the limits of the functors `F.obj j`. -/ noncomputable def limitUncurryIsoLimitCompLim : limit (uncurry.obj F) ≅ limit (F ⋙ lim) := by let c := limit.cone (uncurry.obj F) let P : IsLimit c := limit.isLimit _ let G := DiagramOfCones.mkOfHasLimits F let Q : ∀ j, IsLimit (G.obj j) := fun j => limit.isLimit _ have Q' := coneOfConeUncurryIsLimit Q P have Q'' := limit.isLimit (F ⋙ lim) exact IsLimit.conePointUniqueUpToIso Q' Q'' #align category_theory.limits.limit_uncurry_iso_limit_comp_lim CategoryTheory.Limits.limitUncurryIsoLimitCompLim @[simp, reassoc] theorem limitUncurryIsoLimitCompLim_hom_π_π {j} {k} : (limitUncurryIsoLimitCompLim F).hom ≫ limit.π _ j ≫ limit.π _ k = limit.π _ (j, k) := by dsimp [limitUncurryIsoLimitCompLim, IsLimit.conePointUniqueUpToIso, IsLimit.uniqueUpToIso] simp #align category_theory.limits.limit_uncurry_iso_limit_comp_lim_hom_π_π CategoryTheory.Limits.limitUncurryIsoLimitCompLim_hom_π_π -- Porting note: Added type annotation `limit (_ ⋙ lim) ⟶ _` @[simp, reassoc] theorem limitUncurryIsoLimitCompLim_inv_π {j} {k} : (limitUncurryIsoLimitCompLim F).inv ≫ limit.π _ (j, k) = (limit.π _ j ≫ limit.π _ k : limit (_ ⋙ lim) ⟶ _) := by rw [← cancel_epi (limitUncurryIsoLimitCompLim F).hom] simp #align category_theory.limits.limit_uncurry_iso_limit_comp_lim_inv_π CategoryTheory.Limits.limitUncurryIsoLimitCompLim_inv_π end section variable (F) variable [HasColimitsOfShape K C] /-- Given a functor `F : J ⥤ K ⥤ C`, with all needed colimits, we can construct a diagram consisting of the colimit cocone over each functor `F.obj j`, and the universal cocone morphisms between these. -/ @[simps] noncomputable def DiagramOfCocones.mkOfHasColimits : DiagramOfCocones F where obj j := colimit.cocone (F.obj j) map f := { hom := colim.map (F.map f) } -- Satisfying the inhabited linter. noncomputable instance diagramOfCoconesInhabited : Inhabited (DiagramOfCocones F) := ⟨DiagramOfCocones.mkOfHasColimits F⟩ @[simp] theorem DiagramOfCocones.mkOfHasColimits_coconePoints : (DiagramOfCocones.mkOfHasColimits F).coconePoints = F ⋙ colim := rfl variable [HasColimit (uncurry.obj F)] variable [HasColimit (F ⋙ colim)] /-- The Fubini theorem for a functor `F : J ⥤ K ⥤ C`, showing that the colimit of `uncurry.obj F` can be computed as the colimit of the colimits of the functors `F.obj j`. -/ noncomputable def colimitUncurryIsoColimitCompColim : colimit (uncurry.obj F) ≅ colimit (F ⋙ colim) := by let c := colimit.cocone (uncurry.obj F) let P : IsColimit c := colimit.isColimit _ let G := DiagramOfCocones.mkOfHasColimits F let Q : ∀ j, IsColimit (G.obj j) := fun j => colimit.isColimit _ have Q' := coconeOfCoconeUncurryIsColimit Q P have Q'' := colimit.isColimit (F ⋙ colim) exact IsColimit.coconePointUniqueUpToIso Q' Q'' @[simp, reassoc] theorem colimitUncurryIsoColimitCompColim_ι_ι_inv {j} {k} : colimit.ι (F.obj j) k ≫ colimit.ι (F ⋙ colim) j ≫ (colimitUncurryIsoColimitCompColim F).inv = colimit.ι (uncurry.obj F) (j, k) := by dsimp [colimitUncurryIsoColimitCompColim, IsColimit.coconePointUniqueUpToIso, IsColimit.uniqueUpToIso] simp @[simp, reassoc] theorem colimitUncurryIsoColimitCompColim_ι_hom {j} {k} : colimit.ι _ (j, k) ≫ (colimitUncurryIsoColimitCompColim F).hom = (colimit.ι _ k ≫ colimit.ι (F ⋙ colim) j : _ ⟶ (colimit (F ⋙ colim))) := by rw [← cancel_mono (colimitUncurryIsoColimitCompColim F).inv] simp end section variable (F) [HasLimitsOfShape J C] [HasLimitsOfShape K C] -- With only moderate effort these could be derived if needed: variable [HasLimitsOfShape (J × K) C] [HasLimitsOfShape (K × J) C] /-- The limit of `F.flip ⋙ lim` is isomorphic to the limit of `F ⋙ lim`. -/ noncomputable def limitFlipCompLimIsoLimitCompLim : limit (F.flip ⋙ lim) ≅ limit (F ⋙ lim) := (limitUncurryIsoLimitCompLim _).symm ≪≫ HasLimit.isoOfNatIso (uncurryObjFlip _) ≪≫ HasLimit.isoOfEquivalence (Prod.braiding _ _) (NatIso.ofComponents fun _ => by rfl) ≪≫ limitUncurryIsoLimitCompLim _ #align category_theory.limits.limit_flip_comp_lim_iso_limit_comp_lim CategoryTheory.Limits.limitFlipCompLimIsoLimitCompLim -- Porting note: Added type annotation `limit (_ ⋙ lim) ⟶ _` @[simp, reassoc] theorem limitFlipCompLimIsoLimitCompLim_hom_π_π (j) (k) : (limitFlipCompLimIsoLimitCompLim F).hom ≫ limit.π _ j ≫ limit.π _ k = (limit.π _ k ≫ limit.π _ j : limit (_ ⋙ lim) ⟶ _) := by dsimp [limitFlipCompLimIsoLimitCompLim] simp #align category_theory.limits.limit_flip_comp_lim_iso_limit_comp_lim_hom_π_π CategoryTheory.Limits.limitFlipCompLimIsoLimitCompLim_hom_π_π -- Porting note: Added type annotation `limit (_ ⋙ lim) ⟶ _` -- See note [dsimp, simp] @[simp, reassoc] theorem limitFlipCompLimIsoLimitCompLim_inv_π_π (k) (j) : (limitFlipCompLimIsoLimitCompLim F).inv ≫ limit.π _ k ≫ limit.π _ j = (limit.π _ j ≫ limit.π _ k : limit (_ ⋙ lim) ⟶ _) := by dsimp [limitFlipCompLimIsoLimitCompLim] simp #align category_theory.limits.limit_flip_comp_lim_iso_limit_comp_lim_inv_π_π CategoryTheory.Limits.limitFlipCompLimIsoLimitCompLim_inv_π_π end section variable (F) [HasColimitsOfShape J C] [HasColimitsOfShape K C] variable [HasColimitsOfShape (J × K) C] [HasColimitsOfShape (K × J) C] /-- The colimit of `F.flip ⋙ colim` is isomorphic to the colimit of `F ⋙ colim`. -/ noncomputable def colimitFlipCompColimIsoColimitCompColim : colimit (F.flip ⋙ colim) ≅ colimit (F ⋙ colim) := (colimitUncurryIsoColimitCompColim _).symm ≪≫ HasColimit.isoOfNatIso (uncurryObjFlip _) ≪≫ HasColimit.isoOfEquivalence (Prod.braiding _ _) (NatIso.ofComponents fun _ => by rfl) ≪≫ colimitUncurryIsoColimitCompColim _ @[simp, reassoc] theorem colimitFlipCompColimIsoColimitCompColim_ι_ι_hom (j) (k) : colimit.ι (F.flip.obj k) j ≫ colimit.ι (F.flip ⋙ colim) k ≫ (colimitFlipCompColimIsoColimitCompColim F).hom = (colimit.ι _ k ≫ colimit.ι (F ⋙ colim) j : _ ⟶ colimit (F⋙ colim)) := by dsimp [colimitFlipCompColimIsoColimitCompColim] slice_lhs 1 3 => simp only [] simp @[simp, reassoc] theorem colimitFlipCompColimIsoColimitCompColim_ι_ι_inv (k) (j) : colimit.ι (F.obj j) k ≫ colimit.ι (F ⋙ colim) j ≫ (colimitFlipCompColimIsoColimitCompColim F).inv = (colimit.ι _ j ≫ colimit.ι (F.flip ⋙ colim) k : _ ⟶ colimit (F.flip ⋙ colim)) := by dsimp [colimitFlipCompColimIsoColimitCompColim] slice_lhs 1 3 => simp only [] simp end variable (G : J × K ⥤ C) section variable [HasLimitsOfShape K C] variable [HasLimit G] variable [HasLimit (curry.obj G ⋙ lim)] /-- The Fubini theorem for a functor `G : J × K ⥤ C`, showing that the limit of `G` can be computed as the limit of the limits of the functors `G.obj (j, _)`. -/ noncomputable def limitIsoLimitCurryCompLim : limit G ≅ limit (curry.obj G ⋙ lim) := by have i : G ≅ uncurry.obj ((@curry J _ K _ C _).obj G) := currying.symm.unitIso.app G haveI : Limits.HasLimit (uncurry.obj ((@curry J _ K _ C _).obj G)) := hasLimitOfIso i trans limit (uncurry.obj ((@curry J _ K _ C _).obj G)) · apply HasLimit.isoOfNatIso i · exact limitUncurryIsoLimitCompLim ((@curry J _ K _ C _).obj G) #align category_theory.limits.limit_iso_limit_curry_comp_lim CategoryTheory.Limits.limitIsoLimitCurryCompLim @[simp, reassoc] theorem limitIsoLimitCurryCompLim_hom_π_π {j} {k} : (limitIsoLimitCurryCompLim G).hom ≫ limit.π _ j ≫ limit.π _ k = limit.π _ (j, k) := by set_option tactic.skipAssignedInstances false in simp [limitIsoLimitCurryCompLim, Trans.simple, HasLimit.isoOfNatIso, limitUncurryIsoLimitCompLim] #align category_theory.limits.limit_iso_limit_curry_comp_lim_hom_π_π CategoryTheory.Limits.limitIsoLimitCurryCompLim_hom_π_π -- Porting note: Added type annotation `limit (_ ⋙ lim) ⟶ _` @[simp, reassoc] theorem limitIsoLimitCurryCompLim_inv_π {j} {k} : (limitIsoLimitCurryCompLim G).inv ≫ limit.π _ (j, k) = (limit.π _ j ≫ limit.π _ k : limit (_ ⋙ lim) ⟶ _) := by rw [← cancel_epi (limitIsoLimitCurryCompLim G).hom] simp #align category_theory.limits.limit_iso_limit_curry_comp_lim_inv_π CategoryTheory.Limits.limitIsoLimitCurryCompLim_inv_π end section variable [HasColimitsOfShape K C] variable [HasColimit G] variable [HasColimit (curry.obj G ⋙ colim)] /-- The Fubini theorem for a functor `G : J × K ⥤ C`, showing that the colimit of `G` can be computed as the colimit of the colimits of the functors `G.obj (j, _)`. -/ noncomputable def colimitIsoColimitCurryCompColim : colimit G ≅ colimit (curry.obj G ⋙ colim) := by have i : G ≅ uncurry.obj ((@curry J _ K _ C _).obj G) := currying.symm.unitIso.app G haveI : Limits.HasColimit (uncurry.obj ((@curry J _ K _ C _).obj G)) := hasColimitOfIso i.symm trans colimit (uncurry.obj ((@curry J _ K _ C _).obj G)) · apply HasColimit.isoOfNatIso i · exact colimitUncurryIsoColimitCompColim ((@curry J _ K _ C _).obj G) @[simp, reassoc]
Mathlib/CategoryTheory/Limits/Fubini.lean
489
494
theorem colimitIsoColimitCurryCompColim_ι_ι_inv {j} {k} : colimit.ι ((curry.obj G).obj j) k ≫ colimit.ι (curry.obj G ⋙ colim) j ≫ (colimitIsoColimitCurryCompColim G).inv = colimit.ι _ (j, k) := by
set_option tactic.skipAssignedInstances false in simp [colimitIsoColimitCurryCompColim, Trans.simple, HasColimit.isoOfNatIso, colimitUncurryIsoColimitCompColim]
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Floris van Doorn -/ import Mathlib.Tactic.Lemma import Mathlib.Mathport.Attributes import Mathlib.Mathport.Rename import Mathlib.Tactic.Relation.Trans import Mathlib.Tactic.ProjectionNotation import Batteries.Tactic.Alias import Batteries.Tactic.Lint.Misc import Batteries.Logic -- Only needed for #align set_option autoImplicit true #align opt_param_eq optParam_eq #align non_contradictory_intro not_not_intro /- Eq -/ theorem not_of_eq_false {p : Prop} (h : p = False) : ¬p := fun hp ↦ h ▸ hp theorem cast_proof_irrel (h₁ h₂ : α = β) (a : α) : cast h₁ a = cast h₂ a := rfl attribute [symm] Eq.symm /- Ne -/ attribute [symm] Ne.symm /- HEq -/ alias eq_rec_heq := eqRec_heq -- FIXME This is still rejected after #857 -- attribute [refl] HEq.refl attribute [symm] HEq.symm attribute [trans] HEq.trans attribute [trans] heq_of_eq_of_heq theorem heq_of_eq_rec_left {φ : α → Sort v} {a a' : α} {p₁ : φ a} {p₂ : φ a'} : (e : a = a') → (h₂ : Eq.rec (motive := fun a _ ↦ φ a) p₁ e = p₂) → HEq p₁ p₂ | rfl, rfl => HEq.rfl theorem heq_of_eq_rec_right {φ : α → Sort v} {a a' : α} {p₁ : φ a} {p₂ : φ a'} : (e : a' = a) → (h₂ : p₁ = Eq.rec (motive := fun a _ ↦ φ a) p₂ e) → HEq p₁ p₂ | rfl, rfl => HEq.rfl theorem of_heq_true {a : Prop} (h : HEq a True) : a := of_eq_true (eq_of_heq h) theorem eq_rec_compose {α β φ : Sort u} : ∀ (p₁ : β = φ) (p₂ : α = β) (a : α), (Eq.recOn p₁ (Eq.recOn p₂ a : β) : φ) = Eq.recOn (Eq.trans p₂ p₁) a | rfl, rfl, _ => rfl theorem heq_prop {P Q : Prop} (p : P) (q : Q) : HEq p q := Subsingleton.helim (propext <| iff_of_true p q) _ _ /- and -/ variable {a b c d : Prop} #align and.symm And.symm #align and.swap And.symm /- or -/ #align non_contradictory_em not_not_em #align or.symm Or.symm #align or.swap Or.symm /- xor -/ def Xor' (a b : Prop) := (a ∧ ¬ b) ∨ (b ∧ ¬ a) #align xor Xor' /- iff -/ #align iff.mp Iff.mp #align iff.elim_left Iff.mp #align iff.mpr Iff.mpr #align iff.elim_right Iff.mpr attribute [refl] Iff.refl attribute [trans] Iff.trans attribute [symm] Iff.symm -- This is needed for `calc` to work with `iff`. instance : Trans Iff Iff Iff where trans := fun p q ↦ p.trans q #align not_congr not_congr #align not_iff_not_of_iff not_congr #align not_non_contradictory_iff_absurd not_not_not alias ⟨not_of_not_not_not, _⟩ := not_not_not -- FIXME -- attribute [congr] not_congr #align and.comm and_comm #align and_comm and_comm #align and_assoc and_assoc #align and.assoc and_assoc #align and.left_comm and_left_comm #align and_iff_left and_iff_leftₓ -- reorder implicits variable (p) -- FIXME: remove _iff and add _eq for the lean 4 core versions theorem and_true_iff : p ∧ True ↔ p := iff_of_eq (and_true _) #align and_true and_true_iff theorem true_and_iff : True ∧ p ↔ p := iff_of_eq (true_and _) #align true_and true_and_iff theorem and_false_iff : p ∧ False ↔ False := iff_of_eq (and_false _) #align and_false and_false_iff theorem false_and_iff : False ∧ p ↔ False := iff_of_eq (false_and _) #align false_and false_and_iff #align not_and_self not_and_self_iff #align and_not_self and_not_self_iff #align and_self and_self_iff #align or.imp Or.impₓ -- reorder implicits #align and.elim And.elimₓ #align iff.elim Iff.elimₓ #align imp_congr imp_congrₓ #align imp_congr_ctx imp_congr_ctxₓ #align imp_congr_right imp_congr_rightₓ #align eq_true_intro eq_true #align eq_false_intro eq_false #align or.comm or_comm #align or_comm or_comm #align or.assoc or_assoc #align or_assoc or_assoc #align or_left_comm or_left_comm #align or.left_comm or_left_comm #align or_iff_left_of_imp or_iff_left_of_impₓ -- reorder implicits theorem true_or_iff : True ∨ p ↔ True := iff_of_eq (true_or _) #align true_or true_or_iff theorem or_true_iff : p ∨ True ↔ True := iff_of_eq (or_true _) #align or_true or_true_iff theorem false_or_iff : False ∨ p ↔ p := iff_of_eq (false_or _) #align false_or false_or_iff theorem or_false_iff : p ∨ False ↔ p := iff_of_eq (or_false _) #align or_false or_false_iff #align or_self or_self_iff theorem not_or_of_not : ¬a → ¬b → ¬(a ∨ b) := fun h1 h2 ↦ not_or.2 ⟨h1, h2⟩ #align not_or not_or_of_not theorem iff_true_iff : (a ↔ True) ↔ a := iff_of_eq (iff_true _) #align iff_true iff_true_iff theorem true_iff_iff : (True ↔ a) ↔ a := iff_of_eq (true_iff _) #align true_iff true_iff_iff theorem iff_false_iff : (a ↔ False) ↔ ¬a := iff_of_eq (iff_false _) #align iff_false iff_false_iff theorem false_iff_iff : (False ↔ a) ↔ ¬a := iff_of_eq (false_iff _) #align false_iff false_iff_iff theorem iff_self_iff (a : Prop) : (a ↔ a) ↔ True := iff_of_eq (iff_self _) #align iff_self iff_self_iff #align iff_congr iff_congrₓ -- reorder implicits #align implies_true_iff imp_true_iff #align false_implies_iff false_imp_iff #align true_implies_iff true_imp_iff #align Exists Exists -- otherwise it would get the name ExistsCat -- TODO -- attribute [intro] Exists.intro /- exists unique -/ def ExistsUnique (p : α → Prop) := ∃ x, p x ∧ ∀ y, p y → y = x namespace Mathlib.Notation open Lean /-- Checks to see that `xs` has only one binder. -/ def isExplicitBinderSingular (xs : TSyntax ``explicitBinders) : Bool := match xs with | `(explicitBinders| $_:binderIdent $[: $_]?) => true | `(explicitBinders| ($_:binderIdent : $_)) => true | _ => false open TSyntax.Compat in /-- `∃! x : α, p x` means that there exists a unique `x` in `α` such that `p x`. This is notation for `ExistsUnique (fun (x : α) ↦ p x)`. This notation does not allow multiple binders like `∃! (x : α) (y : β), p x y` as a shorthand for `∃! (x : α), ∃! (y : β), p x y` since it is liable to be misunderstood. Often, the intended meaning is instead `∃! q : α × β, p q.1 q.2`. -/ macro "∃!" xs:explicitBinders ", " b:term : term => do if !isExplicitBinderSingular xs then Macro.throwErrorAt xs "\ The `ExistsUnique` notation should not be used with more than one binder.\n\ \n\ The reason for this is that `∃! (x : α), ∃! (y : β), p x y` has a completely different \ meaning from `∃! q : α × β, p q.1 q.2`. \ To prevent confusion, this notation requires that you be explicit \ and use one with the correct interpretation." expandExplicitBinders ``ExistsUnique xs b /-- Pretty-printing for `ExistsUnique`, following the same pattern as pretty printing for `Exists`. However, it does *not* merge binders. -/ @[app_unexpander ExistsUnique] def unexpandExistsUnique : Lean.PrettyPrinter.Unexpander | `($(_) fun $x:ident ↦ $b) => `(∃! $x:ident, $b) | `($(_) fun ($x:ident : $t) ↦ $b) => `(∃! $x:ident : $t, $b) | _ => throw () /-- `∃! x ∈ s, p x` means `∃! x, x ∈ s ∧ p x`, which is to say that there exists a unique `x ∈ s` such that `p x`. Similarly, notations such as `∃! x ≤ n, p n` are supported, using any relation defined using the `binder_predicate` command. -/ syntax "∃! " binderIdent binderPred ", " term : term macro_rules | `(∃! $x:ident $p:binderPred, $b) => `(∃! $x:ident, satisfies_binder_pred% $x $p ∧ $b) | `(∃! _ $p:binderPred, $b) => `(∃! x, satisfies_binder_pred% x $p ∧ $b) end Mathlib.Notation -- @[intro] -- TODO theorem ExistsUnique.intro {p : α → Prop} (w : α) (h₁ : p w) (h₂ : ∀ y, p y → y = w) : ∃! x, p x := ⟨w, h₁, h₂⟩ theorem ExistsUnique.elim {α : Sort u} {p : α → Prop} {b : Prop} (h₂ : ∃! x, p x) (h₁ : ∀ x, p x → (∀ y, p y → y = x) → b) : b := Exists.elim h₂ (fun w hw ↦ h₁ w (And.left hw) (And.right hw)) theorem exists_unique_of_exists_of_unique {α : Sort u} {p : α → Prop} (hex : ∃ x, p x) (hunique : ∀ y₁ y₂, p y₁ → p y₂ → y₁ = y₂) : ∃! x, p x := Exists.elim hex (fun x px ↦ ExistsUnique.intro x px (fun y (h : p y) ↦ hunique y x h px)) theorem ExistsUnique.exists {p : α → Prop} : (∃! x, p x) → ∃ x, p x | ⟨x, h, _⟩ => ⟨x, h⟩ #align exists_of_exists_unique ExistsUnique.exists #align exists_unique.exists ExistsUnique.exists theorem ExistsUnique.unique {α : Sort u} {p : α → Prop} (h : ∃! x, p x) {y₁ y₂ : α} (py₁ : p y₁) (py₂ : p y₂) : y₁ = y₂ := let ⟨_, _, hy⟩ := h; (hy _ py₁).trans (hy _ py₂).symm #align unique_of_exists_unique ExistsUnique.unique #align exists_unique.unique ExistsUnique.unique /- exists, forall, exists unique congruences -/ -- TODO -- attribute [congr] forall_congr' -- attribute [congr] exists_congr' #align forall_congr forall_congr' #align Exists.imp Exists.imp #align exists_imp_exists Exists.imp -- @[congr] theorem exists_unique_congr {p q : α → Prop} (h : ∀ a, p a ↔ q a) : (∃! a, p a) ↔ ∃! a, q a := exists_congr fun _ ↦ and_congr (h _) <| forall_congr' fun _ ↦ imp_congr_left (h _) /- decidable -/ #align decidable.to_bool Decidable.decide theorem decide_True' (h : Decidable True) : decide True = true := by simp #align to_bool_true_eq_tt decide_True' theorem decide_False' (h : Decidable False) : decide False = false := by simp #align to_bool_false_eq_ff decide_False' namespace Decidable def recOn_true [h : Decidable p] {h₁ : p → Sort u} {h₂ : ¬p → Sort u} (h₃ : p) (h₄ : h₁ h₃) : Decidable.recOn h h₂ h₁ := cast (by match h with | .isTrue _ => rfl) h₄ #align decidable.rec_on_true Decidable.recOn_true def recOn_false [h : Decidable p] {h₁ : p → Sort u} {h₂ : ¬p → Sort u} (h₃ : ¬p) (h₄ : h₂ h₃) : Decidable.recOn h h₂ h₁ := cast (by match h with | .isFalse _ => rfl) h₄ #align decidable.rec_on_false Decidable.recOn_false alias by_cases := byCases alias by_contradiction := byContradiction alias not_not_iff := not_not end Decidable #align decidable_of_decidable_of_iff decidable_of_decidable_of_iff #align decidable_of_decidable_of_eq decidable_of_decidable_of_eq #align or.by_cases Or.by_cases alias Or.decidable := instDecidableOr alias And.decidable := instDecidableAnd alias Not.decidable := instDecidableNot alias Iff.decidable := instDecidableIff alias decidableTrue := instDecidableTrue alias decidableFalse := instDecidableFalse #align decidable.true decidableTrue #align decidable.false decidableFalse #align or.decidable Or.decidable #align and.decidable And.decidable #align not.decidable Not.decidable #align iff.decidable Iff.decidable instance [Decidable p] [Decidable q] : Decidable (Xor' p q) := inferInstanceAs (Decidable (Or ..)) def IsDecEq {α : Sort u} (p : α → α → Bool) : Prop := ∀ ⦃x y : α⦄, p x y = true → x = y def IsDecRefl {α : Sort u} (p : α → α → Bool) : Prop := ∀ x, p x x = true def decidableEq_of_bool_pred {α : Sort u} {p : α → α → Bool} (h₁ : IsDecEq p) (h₂ : IsDecRefl p) : DecidableEq α | x, y => if hp : p x y = true then isTrue (h₁ hp) else isFalse (fun hxy : x = y ↦ absurd (h₂ y) (by rwa [hxy] at hp)) #align decidable_eq_of_bool_pred decidableEq_of_bool_pred theorem decidableEq_inl_refl {α : Sort u} [h : DecidableEq α] (a : α) : h a a = isTrue (Eq.refl a) := match h a a with | isTrue _ => rfl theorem decidableEq_inr_neg {α : Sort u} [h : DecidableEq α] {a b : α} (n : a ≠ b) : h a b = isFalse n := match h a b with | isFalse _ => rfl #align inhabited.default Inhabited.default #align arbitrary Inhabited.default #align nonempty_of_inhabited instNonemptyOfInhabited /- subsingleton -/ theorem rec_subsingleton {p : Prop} [h : Decidable p] {h₁ : p → Sort u} {h₂ : ¬p → Sort u} [h₃ : ∀ h : p, Subsingleton (h₁ h)] [h₄ : ∀ h : ¬p, Subsingleton (h₂ h)] : Subsingleton (Decidable.recOn h h₂ h₁) := match h with | isTrue h => h₃ h | isFalse h => h₄ h theorem imp_of_if_pos {c t e : Prop} [Decidable c] (h : ite c t e) (hc : c) : t := (if_pos hc ▸ h :) #align implies_of_if_pos imp_of_if_pos theorem imp_of_if_neg {c t e : Prop} [Decidable c] (h : ite c t e) (hnc : ¬c) : e := (if_neg hnc ▸ h :) #align implies_of_if_neg imp_of_if_neg theorem if_ctx_congr {α : Sort u} {b c : Prop} [dec_b : Decidable b] [dec_c : Decidable c] {x y u v : α} (h_c : b ↔ c) (h_t : c → x = u) (h_e : ¬c → y = v) : ite b x y = ite c u v := match dec_b, dec_c with | isFalse _, isFalse h₂ => h_e h₂ | isTrue _, isTrue h₂ => h_t h₂ | isFalse h₁, isTrue h₂ => absurd h₂ (Iff.mp (not_congr h_c) h₁) | isTrue h₁, isFalse h₂ => absurd h₁ (Iff.mpr (not_congr h_c) h₂) theorem if_congr {α : Sort u} {b c : Prop} [Decidable b] [Decidable c] {x y u v : α} (h_c : b ↔ c) (h_t : x = u) (h_e : y = v) : ite b x y = ite c u v := if_ctx_congr h_c (fun _ ↦ h_t) (fun _ ↦ h_e) theorem if_ctx_congr_prop {b c x y u v : Prop} [dec_b : Decidable b] [dec_c : Decidable c] (h_c : b ↔ c) (h_t : c → (x ↔ u)) (h_e : ¬c → (y ↔ v)) : ite b x y ↔ ite c u v := match dec_b, dec_c with | isFalse _, isFalse h₂ => h_e h₂ | isTrue _, isTrue h₂ => h_t h₂ | isFalse h₁, isTrue h₂ => absurd h₂ (Iff.mp (not_congr h_c) h₁) | isTrue h₁, isFalse h₂ => absurd h₁ (Iff.mpr (not_congr h_c) h₂) -- @[congr] theorem if_congr_prop {b c x y u v : Prop} [Decidable b] [Decidable c] (h_c : b ↔ c) (h_t : x ↔ u) (h_e : y ↔ v) : ite b x y ↔ ite c u v := if_ctx_congr_prop h_c (fun _ ↦ h_t) (fun _ ↦ h_e) theorem if_ctx_simp_congr_prop {b c x y u v : Prop} [Decidable b] (h_c : b ↔ c) (h_t : c → (x ↔ u)) -- FIXME: after https://github.com/leanprover/lean4/issues/1867 is fixed, -- this should be changed back to: -- (h_e : ¬c → (y ↔ v)) : ite b x y ↔ ite c (h := decidable_of_decidable_of_iff h_c) u v := (h_e : ¬c → (y ↔ v)) : ite b x y ↔ @ite _ c (decidable_of_decidable_of_iff h_c) u v := if_ctx_congr_prop (dec_c := decidable_of_decidable_of_iff h_c) h_c h_t h_e theorem if_simp_congr_prop {b c x y u v : Prop} [Decidable b] (h_c : b ↔ c) (h_t : x ↔ u) -- FIXME: after https://github.com/leanprover/lean4/issues/1867 is fixed, -- this should be changed back to: -- (h_e : y ↔ v) : ite b x y ↔ (ite c (h := decidable_of_decidable_of_iff h_c) u v) := (h_e : y ↔ v) : ite b x y ↔ (@ite _ c (decidable_of_decidable_of_iff h_c) u v) := if_ctx_simp_congr_prop h_c (fun _ ↦ h_t) (fun _ ↦ h_e) -- @[congr] theorem dif_ctx_congr {α : Sort u} {b c : Prop} [dec_b : Decidable b] [dec_c : Decidable c] {x : b → α} {u : c → α} {y : ¬b → α} {v : ¬c → α} (h_c : b ↔ c) (h_t : ∀ h : c, x (Iff.mpr h_c h) = u h) (h_e : ∀ h : ¬c, y (Iff.mpr (not_congr h_c) h) = v h) : @dite α b dec_b x y = @dite α c dec_c u v := match dec_b, dec_c with | isFalse _, isFalse h₂ => h_e h₂ | isTrue _, isTrue h₂ => h_t h₂ | isFalse h₁, isTrue h₂ => absurd h₂ (Iff.mp (not_congr h_c) h₁) | isTrue h₁, isFalse h₂ => absurd h₁ (Iff.mpr (not_congr h_c) h₂) theorem dif_ctx_simp_congr {α : Sort u} {b c : Prop} [Decidable b] {x : b → α} {u : c → α} {y : ¬b → α} {v : ¬c → α} (h_c : b ↔ c) (h_t : ∀ h : c, x (Iff.mpr h_c h) = u h) (h_e : ∀ h : ¬c, y (Iff.mpr (not_congr h_c) h) = v h) : -- FIXME: after https://github.com/leanprover/lean4/issues/1867 is fixed, -- this should be changed back to: -- dite b x y = dite c (h := decidable_of_decidable_of_iff h_c) u v := dite b x y = @dite _ c (decidable_of_decidable_of_iff h_c) u v := dif_ctx_congr (dec_c := decidable_of_decidable_of_iff h_c) h_c h_t h_e def AsTrue (c : Prop) [Decidable c] : Prop := if c then True else False def AsFalse (c : Prop) [Decidable c] : Prop := if c then False else True theorem AsTrue.get {c : Prop} [h₁ : Decidable c] (_ : AsTrue c) : c := match h₁ with | isTrue h_c => h_c #align of_as_true AsTrue.get #align ulift ULift #align ulift.up ULift.up #align ulift.down ULift.down #align plift PLift #align plift.up PLift.up #align plift.down PLift.down /- Equalities for rewriting let-expressions -/ theorem let_value_eq {α : Sort u} {β : Sort v} {a₁ a₂ : α} (b : α → β) (h : a₁ = a₂) : (let x : α := a₁; b x) = (let x : α := a₂; b x) := congrArg b h theorem let_value_heq {α : Sort v} {β : α → Sort u} {a₁ a₂ : α} (b : ∀ x : α, β x) (h : a₁ = a₂) : HEq (let x : α := a₁; b x) (let x : α := a₂; b x) := by cases h; rfl #align let_value_heq let_value_heq -- FIXME: mathport thinks this is a dubious translation theorem let_body_eq {α : Sort v} {β : α → Sort u} (a : α) {b₁ b₂ : ∀ x : α, β x} (h : ∀ x, b₁ x = b₂ x) : (let x : α := a; b₁ x) = (let x : α := a; b₂ x) := by exact h _ ▸ rfl #align let_value_eq let_value_eq -- FIXME: mathport thinks this is a dubious translation
Mathlib/Init/Logic.lean
461
463
theorem let_eq {α : Sort v} {β : Sort u} {a₁ a₂ : α} {b₁ b₂ : α → β} (h₁ : a₁ = a₂) (h₂ : ∀ x, b₁ x = b₂ x) : (let x : α := a₁; b₁ x) = (let x : α := a₂; b₂ x) := by
simp [h₁, h₂]
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Data.Set.Pointwise.SMul import Mathlib.Topology.MetricSpace.Isometry import Mathlib.Topology.MetricSpace.Lipschitz #align_import topology.metric_space.isometric_smul from "leanprover-community/mathlib"@"bc91ed7093bf098d253401e69df601fc33dde156" /-! # Group actions by isometries In this file we define two typeclasses: - `IsometricSMul M X` says that `M` multiplicatively acts on a (pseudo extended) metric space `X` by isometries; - `IsometricVAdd` is an additive version of `IsometricSMul`. We also prove basic facts about isometric actions and define bundled isometries `IsometryEquiv.constSMul`, `IsometryEquiv.mulLeft`, `IsometryEquiv.mulRight`, `IsometryEquiv.divLeft`, `IsometryEquiv.divRight`, and `IsometryEquiv.inv`, as well as their additive versions. If `G` is a group, then `IsometricSMul G G` means that `G` has a left-invariant metric while `IsometricSMul Gᵐᵒᵖ G` means that `G` has a right-invariant metric. For a commutative group, these two notions are equivalent. A group with a right-invariant metric can be also represented as a `NormedGroup`. -/ open Set open ENNReal Pointwise universe u v w variable (M : Type u) (G : Type v) (X : Type w) /-- An additive action is isometric if each map `x ↦ c +ᵥ x` is an isometry. -/ class IsometricVAdd [PseudoEMetricSpace X] [VAdd M X] : Prop where protected isometry_vadd : ∀ c : M, Isometry ((c +ᵥ ·) : X → X) #align has_isometric_vadd IsometricVAdd /-- A multiplicative action is isometric if each map `x ↦ c • x` is an isometry. -/ @[to_additive] class IsometricSMul [PseudoEMetricSpace X] [SMul M X] : Prop where protected isometry_smul : ∀ c : M, Isometry ((c • ·) : X → X) #align has_isometric_smul IsometricSMul -- Porting note: Lean 4 doesn't support `[]` in classes, so make a lemma instead of `export`ing @[to_additive] theorem isometry_smul {M : Type u} (X : Type w) [PseudoEMetricSpace X] [SMul M X] [IsometricSMul M X] (c : M) : Isometry (c • · : X → X) := IsometricSMul.isometry_smul c @[to_additive] instance (priority := 100) IsometricSMul.to_continuousConstSMul [PseudoEMetricSpace X] [SMul M X] [IsometricSMul M X] : ContinuousConstSMul M X := ⟨fun c => (isometry_smul X c).continuous⟩ #align has_isometric_smul.to_has_continuous_const_smul IsometricSMul.to_continuousConstSMul #align has_isometric_vadd.to_has_continuous_const_vadd IsometricVAdd.to_continuousConstVAdd @[to_additive] instance (priority := 100) IsometricSMul.opposite_of_comm [PseudoEMetricSpace X] [SMul M X] [SMul Mᵐᵒᵖ X] [IsCentralScalar M X] [IsometricSMul M X] : IsometricSMul Mᵐᵒᵖ X := ⟨fun c x y => by simpa only [← op_smul_eq_smul] using isometry_smul X c.unop x y⟩ #align has_isometric_smul.opposite_of_comm IsometricSMul.opposite_of_comm #align has_isometric_vadd.opposite_of_comm IsometricVAdd.opposite_of_comm variable {M G X} section EMetric variable [PseudoEMetricSpace X] [Group G] [MulAction G X] [IsometricSMul G X] @[to_additive (attr := simp)] theorem edist_smul_left [SMul M X] [IsometricSMul M X] (c : M) (x y : X) : edist (c • x) (c • y) = edist x y := isometry_smul X c x y #align edist_smul_left edist_smul_left #align edist_vadd_left edist_vadd_left @[to_additive (attr := simp)] theorem ediam_smul [SMul M X] [IsometricSMul M X] (c : M) (s : Set X) : EMetric.diam (c • s) = EMetric.diam s := (isometry_smul _ _).ediam_image s #align ediam_smul ediam_smul #align ediam_vadd ediam_vadd @[to_additive] theorem isometry_mul_left [Mul M] [PseudoEMetricSpace M] [IsometricSMul M M] (a : M) : Isometry (a * ·) := isometry_smul M a #align isometry_mul_left isometry_mul_left #align isometry_add_left isometry_add_left @[to_additive (attr := simp)] theorem edist_mul_left [Mul M] [PseudoEMetricSpace M] [IsometricSMul M M] (a b c : M) : edist (a * b) (a * c) = edist b c := isometry_mul_left a b c #align edist_mul_left edist_mul_left #align edist_add_left edist_add_left @[to_additive] theorem isometry_mul_right [Mul M] [PseudoEMetricSpace M] [IsometricSMul Mᵐᵒᵖ M] (a : M) : Isometry fun x => x * a := isometry_smul M (MulOpposite.op a) #align isometry_mul_right isometry_mul_right #align isometry_add_right isometry_add_right @[to_additive (attr := simp)] theorem edist_mul_right [Mul M] [PseudoEMetricSpace M] [IsometricSMul Mᵐᵒᵖ M] (a b c : M) : edist (a * c) (b * c) = edist a b := isometry_mul_right c a b #align edist_mul_right edist_mul_right #align edist_add_right edist_add_right @[to_additive (attr := simp)] theorem edist_div_right [DivInvMonoid M] [PseudoEMetricSpace M] [IsometricSMul Mᵐᵒᵖ M] (a b c : M) : edist (a / c) (b / c) = edist a b := by simp only [div_eq_mul_inv, edist_mul_right] #align edist_div_right edist_div_right #align edist_sub_right edist_sub_right @[to_additive (attr := simp)] theorem edist_inv_inv [PseudoEMetricSpace G] [IsometricSMul G G] [IsometricSMul Gᵐᵒᵖ G] (a b : G) : edist a⁻¹ b⁻¹ = edist a b := by rw [← edist_mul_left a, ← edist_mul_right _ _ b, mul_right_inv, one_mul, inv_mul_cancel_right, edist_comm] #align edist_inv_inv edist_inv_inv #align edist_neg_neg edist_neg_neg @[to_additive] theorem isometry_inv [PseudoEMetricSpace G] [IsometricSMul G G] [IsometricSMul Gᵐᵒᵖ G] : Isometry (Inv.inv : G → G) := edist_inv_inv #align isometry_inv isometry_inv #align isometry_neg isometry_neg @[to_additive] theorem edist_inv [PseudoEMetricSpace G] [IsometricSMul G G] [IsometricSMul Gᵐᵒᵖ G] (x y : G) : edist x⁻¹ y = edist x y⁻¹ := by rw [← edist_inv_inv, inv_inv] #align edist_inv edist_inv #align edist_neg edist_neg @[to_additive (attr := simp)] theorem edist_div_left [PseudoEMetricSpace G] [IsometricSMul G G] [IsometricSMul Gᵐᵒᵖ G] (a b c : G) : edist (a / b) (a / c) = edist b c := by rw [div_eq_mul_inv, div_eq_mul_inv, edist_mul_left, edist_inv_inv] #align edist_div_left edist_div_left #align edist_sub_left edist_sub_left namespace IsometryEquiv /-- If a group `G` acts on `X` by isometries, then `IsometryEquiv.constSMul` is the isometry of `X` given by multiplication of a constant element of the group. -/ @[to_additive (attr := simps! toEquiv apply) "If an additive group `G` acts on `X` by isometries, then `IsometryEquiv.constVAdd` is the isometry of `X` given by addition of a constant element of the group."] def constSMul (c : G) : X ≃ᵢ X where toEquiv := MulAction.toPerm c isometry_toFun := isometry_smul X c #align isometry_equiv.const_smul IsometryEquiv.constSMul #align isometry_equiv.const_vadd IsometryEquiv.constVAdd #align isometry_equiv.const_smul_to_equiv IsometryEquiv.constSMul_toEquiv #align isometry_equiv.const_smul_apply IsometryEquiv.constSMul_apply #align isometry_equiv.const_vadd_to_equiv IsometryEquiv.constVAdd_toEquiv #align isometry_equiv.const_vadd_apply IsometryEquiv.constVAdd_apply @[to_additive (attr := simp)] theorem constSMul_symm (c : G) : (constSMul c : X ≃ᵢ X).symm = constSMul c⁻¹ := ext fun _ => rfl #align isometry_equiv.const_smul_symm IsometryEquiv.constSMul_symm #align isometry_equiv.const_vadd_symm IsometryEquiv.constVAdd_symm variable [PseudoEMetricSpace G] /-- Multiplication `y ↦ x * y` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply toEquiv) "Addition `y ↦ x + y` as an `IsometryEquiv`."] def mulLeft [IsometricSMul G G] (c : G) : G ≃ᵢ G where toEquiv := Equiv.mulLeft c isometry_toFun := edist_mul_left c #align isometry_equiv.mul_left IsometryEquiv.mulLeft #align isometry_equiv.add_left IsometryEquiv.addLeft #align isometry_equiv.mul_left_apply IsometryEquiv.mulLeft_apply #align isometry_equiv.mul_left_to_equiv IsometryEquiv.mulLeft_toEquiv #align isometry_equiv.add_left_apply IsometryEquiv.addLeft_apply #align isometry_equiv.add_left_to_equiv IsometryEquiv.addLeft_toEquiv @[to_additive (attr := simp)] theorem mulLeft_symm [IsometricSMul G G] (x : G) : (mulLeft x).symm = IsometryEquiv.mulLeft x⁻¹ := constSMul_symm x #align isometry_equiv.mul_left_symm IsometryEquiv.mulLeft_symm #align isometry_equiv.add_left_symm IsometryEquiv.addLeft_symm /-- Multiplication `y ↦ y * x` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply toEquiv) "Addition `y ↦ y + x` as an `IsometryEquiv`."] def mulRight [IsometricSMul Gᵐᵒᵖ G] (c : G) : G ≃ᵢ G where toEquiv := Equiv.mulRight c isometry_toFun a b := edist_mul_right a b c #align isometry_equiv.mul_right IsometryEquiv.mulRight #align isometry_equiv.add_right IsometryEquiv.addRight #align isometry_equiv.mul_right_apply IsometryEquiv.mulRight_apply #align isometry_equiv.mul_right_to_equiv IsometryEquiv.mulRight_toEquiv #align isometry_equiv.add_right_apply IsometryEquiv.addRight_apply #align isometry_equiv.add_right_to_equiv IsometryEquiv.addRight_toEquiv @[to_additive (attr := simp)] theorem mulRight_symm [IsometricSMul Gᵐᵒᵖ G] (x : G) : (mulRight x).symm = mulRight x⁻¹ := ext fun _ => rfl #align isometry_equiv.mul_right_symm IsometryEquiv.mulRight_symm #align isometry_equiv.add_right_symm IsometryEquiv.addRight_symm /-- Division `y ↦ y / x` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply toEquiv) "Subtraction `y ↦ y - x` as an `IsometryEquiv`."] def divRight [IsometricSMul Gᵐᵒᵖ G] (c : G) : G ≃ᵢ G where toEquiv := Equiv.divRight c isometry_toFun a b := edist_div_right a b c #align isometry_equiv.div_right IsometryEquiv.divRight #align isometry_equiv.sub_right IsometryEquiv.subRight #align isometry_equiv.div_right_apply IsometryEquiv.divRight_apply #align isometry_equiv.div_right_to_equiv IsometryEquiv.divRight_toEquiv #align isometry_equiv.sub_right_apply IsometryEquiv.subRight_apply #align isometry_equiv.sub_right_to_equiv IsometryEquiv.subRight_toEquiv @[to_additive (attr := simp)] theorem divRight_symm [IsometricSMul Gᵐᵒᵖ G] (c : G) : (divRight c).symm = mulRight c := ext fun _ => rfl #align isometry_equiv.div_right_symm IsometryEquiv.divRight_symm #align isometry_equiv.sub_right_symm IsometryEquiv.subRight_symm variable [IsometricSMul G G] [IsometricSMul Gᵐᵒᵖ G] /-- Division `y ↦ x / y` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply symm_apply toEquiv) "Subtraction `y ↦ x - y` as an `IsometryEquiv`."] def divLeft (c : G) : G ≃ᵢ G where toEquiv := Equiv.divLeft c isometry_toFun := edist_div_left c #align isometry_equiv.div_left IsometryEquiv.divLeft #align isometry_equiv.sub_left IsometryEquiv.subLeft #align isometry_equiv.div_left_apply IsometryEquiv.divLeft_apply #align isometry_equiv.div_left_symm_apply IsometryEquiv.divLeft_symm_apply #align isometry_equiv.div_left_to_equiv IsometryEquiv.divLeft_toEquiv #align isometry_equiv.sub_left_apply IsometryEquiv.subLeft_apply #align isometry_equiv.sub_left_symm_apply IsometryEquiv.subLeft_symm_apply #align isometry_equiv.sub_left_to_equiv IsometryEquiv.subLeft_toEquiv variable (G) /-- Inversion `x ↦ x⁻¹` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply toEquiv) "Negation `x ↦ -x` as an `IsometryEquiv`."] def inv : G ≃ᵢ G where toEquiv := Equiv.inv G isometry_toFun := edist_inv_inv #align isometry_equiv.inv IsometryEquiv.inv #align isometry_equiv.neg IsometryEquiv.neg #align isometry_equiv.inv_apply IsometryEquiv.inv_apply #align isometry_equiv.inv_to_equiv IsometryEquiv.inv_toEquiv #align isometry_equiv.neg_apply IsometryEquiv.neg_apply #align isometry_equiv.neg_to_equiv IsometryEquiv.neg_toEquiv @[to_additive (attr := simp)] theorem inv_symm : (inv G).symm = inv G := rfl #align isometry_equiv.inv_symm IsometryEquiv.inv_symm #align isometry_equiv.neg_symm IsometryEquiv.neg_symm end IsometryEquiv namespace EMetric @[to_additive (attr := simp)] theorem smul_ball (c : G) (x : X) (r : ℝ≥0∞) : c • ball x r = ball (c • x) r := (IsometryEquiv.constSMul c).image_emetric_ball _ _ #align emetric.smul_ball EMetric.smul_ball #align emetric.vadd_ball EMetric.vadd_ball @[to_additive (attr := simp)] theorem preimage_smul_ball (c : G) (x : X) (r : ℝ≥0∞) : (c • ·) ⁻¹' ball x r = ball (c⁻¹ • x) r := by rw [preimage_smul, smul_ball] #align emetric.preimage_smul_ball EMetric.preimage_smul_ball #align emetric.preimage_vadd_ball EMetric.preimage_vadd_ball @[to_additive (attr := simp)] theorem smul_closedBall (c : G) (x : X) (r : ℝ≥0∞) : c • closedBall x r = closedBall (c • x) r := (IsometryEquiv.constSMul c).image_emetric_closedBall _ _ #align emetric.smul_closed_ball EMetric.smul_closedBall #align emetric.vadd_closed_ball EMetric.vadd_closedBall @[to_additive (attr := simp)] theorem preimage_smul_closedBall (c : G) (x : X) (r : ℝ≥0∞) : (c • ·) ⁻¹' closedBall x r = closedBall (c⁻¹ • x) r := by rw [preimage_smul, smul_closedBall] #align emetric.preimage_smul_closed_ball EMetric.preimage_smul_closedBall #align emetric.preimage_vadd_closed_ball EMetric.preimage_vadd_closedBall variable [PseudoEMetricSpace G] @[to_additive (attr := simp)] theorem preimage_mul_left_ball [IsometricSMul G G] (a b : G) (r : ℝ≥0∞) : (a * ·) ⁻¹' ball b r = ball (a⁻¹ * b) r := preimage_smul_ball a b r #align emetric.preimage_mul_left_ball EMetric.preimage_mul_left_ball #align emetric.preimage_add_left_ball EMetric.preimage_add_left_ball @[to_additive (attr := simp)] theorem preimage_mul_right_ball [IsometricSMul Gᵐᵒᵖ G] (a b : G) (r : ℝ≥0∞) : (fun x => x * a) ⁻¹' ball b r = ball (b / a) r := by rw [div_eq_mul_inv] exact preimage_smul_ball (MulOpposite.op a) b r #align emetric.preimage_mul_right_ball EMetric.preimage_mul_right_ball #align emetric.preimage_add_right_ball EMetric.preimage_add_right_ball @[to_additive (attr := simp)] theorem preimage_mul_left_closedBall [IsometricSMul G G] (a b : G) (r : ℝ≥0∞) : (a * ·) ⁻¹' closedBall b r = closedBall (a⁻¹ * b) r := preimage_smul_closedBall a b r #align emetric.preimage_mul_left_closed_ball EMetric.preimage_mul_left_closedBall #align emetric.preimage_add_left_closed_ball EMetric.preimage_add_left_closedBall @[to_additive (attr := simp)] theorem preimage_mul_right_closedBall [IsometricSMul Gᵐᵒᵖ G] (a b : G) (r : ℝ≥0∞) : (fun x => x * a) ⁻¹' closedBall b r = closedBall (b / a) r := by rw [div_eq_mul_inv] exact preimage_smul_closedBall (MulOpposite.op a) b r #align emetric.preimage_mul_right_closed_ball EMetric.preimage_mul_right_closedBall #align emetric.preimage_add_right_closed_ball EMetric.preimage_add_right_closedBall end EMetric end EMetric @[to_additive (attr := simp)] theorem dist_smul [PseudoMetricSpace X] [SMul M X] [IsometricSMul M X] (c : M) (x y : X) : dist (c • x) (c • y) = dist x y := (isometry_smul X c).dist_eq x y #align dist_smul dist_smul #align dist_vadd dist_vadd @[to_additive (attr := simp)] theorem nndist_smul [PseudoMetricSpace X] [SMul M X] [IsometricSMul M X] (c : M) (x y : X) : nndist (c • x) (c • y) = nndist x y := (isometry_smul X c).nndist_eq x y #align nndist_smul nndist_smul #align nndist_vadd nndist_vadd @[to_additive (attr := simp)] theorem diam_smul [PseudoMetricSpace X] [SMul M X] [IsometricSMul M X] (c : M) (s : Set X) : Metric.diam (c • s) = Metric.diam s := (isometry_smul _ _).diam_image s #align diam_smul diam_smul #align diam_vadd diam_vadd @[to_additive (attr := simp)] theorem dist_mul_left [PseudoMetricSpace M] [Mul M] [IsometricSMul M M] (a b c : M) : dist (a * b) (a * c) = dist b c := dist_smul a b c #align dist_mul_left dist_mul_left #align dist_add_left dist_add_left @[to_additive (attr := simp)] theorem nndist_mul_left [PseudoMetricSpace M] [Mul M] [IsometricSMul M M] (a b c : M) : nndist (a * b) (a * c) = nndist b c := nndist_smul a b c #align nndist_mul_left nndist_mul_left #align nndist_add_left nndist_add_left @[to_additive (attr := simp)] theorem dist_mul_right [Mul M] [PseudoMetricSpace M] [IsometricSMul Mᵐᵒᵖ M] (a b c : M) : dist (a * c) (b * c) = dist a b := dist_smul (MulOpposite.op c) a b #align dist_mul_right dist_mul_right #align dist_add_right dist_add_right @[to_additive (attr := simp)] theorem nndist_mul_right [PseudoMetricSpace M] [Mul M] [IsometricSMul Mᵐᵒᵖ M] (a b c : M) : nndist (a * c) (b * c) = nndist a b := nndist_smul (MulOpposite.op c) a b #align nndist_mul_right nndist_mul_right #align nndist_add_right nndist_add_right @[to_additive (attr := simp)] theorem dist_div_right [DivInvMonoid M] [PseudoMetricSpace M] [IsometricSMul Mᵐᵒᵖ M] (a b c : M) : dist (a / c) (b / c) = dist a b := by simp only [div_eq_mul_inv, dist_mul_right] #align dist_div_right dist_div_right #align dist_sub_right dist_sub_right @[to_additive (attr := simp)] theorem nndist_div_right [DivInvMonoid M] [PseudoMetricSpace M] [IsometricSMul Mᵐᵒᵖ M] (a b c : M) : nndist (a / c) (b / c) = nndist a b := by simp only [div_eq_mul_inv, nndist_mul_right] #align nndist_div_right nndist_div_right #align nndist_sub_right nndist_sub_right @[to_additive (attr := simp)] theorem dist_inv_inv [Group G] [PseudoMetricSpace G] [IsometricSMul G G] [IsometricSMul Gᵐᵒᵖ G] (a b : G) : dist a⁻¹ b⁻¹ = dist a b := (IsometryEquiv.inv G).dist_eq a b #align dist_inv_inv dist_inv_inv #align dist_neg_neg dist_neg_neg @[to_additive (attr := simp)] theorem nndist_inv_inv [Group G] [PseudoMetricSpace G] [IsometricSMul G G] [IsometricSMul Gᵐᵒᵖ G] (a b : G) : nndist a⁻¹ b⁻¹ = nndist a b := (IsometryEquiv.inv G).nndist_eq a b #align nndist_inv_inv nndist_inv_inv #align nndist_neg_neg nndist_neg_neg @[to_additive (attr := simp)] theorem dist_div_left [Group G] [PseudoMetricSpace G] [IsometricSMul G G] [IsometricSMul Gᵐᵒᵖ G] (a b c : G) : dist (a / b) (a / c) = dist b c := by simp [div_eq_mul_inv] #align dist_div_left dist_div_left #align dist_sub_left dist_sub_left @[to_additive (attr := simp)] theorem nndist_div_left [Group G] [PseudoMetricSpace G] [IsometricSMul G G] [IsometricSMul Gᵐᵒᵖ G] (a b c : G) : nndist (a / b) (a / c) = nndist b c := by simp [div_eq_mul_inv] #align nndist_div_left nndist_div_left #align nndist_sub_left nndist_sub_left /-- If `G` acts isometrically on `X`, then the image of a bounded set in `X` under scalar multiplication by `c : G` is bounded. See also `Bornology.IsBounded.smul₀` for a similar lemma about normed spaces. -/ @[to_additive "Given an additive isometric action of `G` on `X`, the image of a bounded set in `X` under translation by `c : G` is bounded"] theorem Bornology.IsBounded.smul [PseudoMetricSpace X] [SMul G X] [IsometricSMul G X] {s : Set X} (hs : IsBounded s) (c : G) : IsBounded (c • s) := (isometry_smul X c).lipschitz.isBounded_image hs namespace Metric variable [PseudoMetricSpace X] [Group G] [MulAction G X] [IsometricSMul G X] @[to_additive (attr := simp)] theorem smul_ball (c : G) (x : X) (r : ℝ) : c • ball x r = ball (c • x) r := (IsometryEquiv.constSMul c).image_ball _ _ #align metric.smul_ball Metric.smul_ball #align metric.vadd_ball Metric.vadd_ball @[to_additive (attr := simp)] theorem preimage_smul_ball (c : G) (x : X) (r : ℝ) : (c • ·) ⁻¹' ball x r = ball (c⁻¹ • x) r := by rw [preimage_smul, smul_ball] #align metric.preimage_smul_ball Metric.preimage_smul_ball #align metric.preimage_vadd_ball Metric.preimage_vadd_ball @[to_additive (attr := simp)] theorem smul_closedBall (c : G) (x : X) (r : ℝ) : c • closedBall x r = closedBall (c • x) r := (IsometryEquiv.constSMul c).image_closedBall _ _ #align metric.smul_closed_ball Metric.smul_closedBall #align metric.vadd_closed_ball Metric.vadd_closedBall @[to_additive (attr := simp)] theorem preimage_smul_closedBall (c : G) (x : X) (r : ℝ) : (c • ·) ⁻¹' closedBall x r = closedBall (c⁻¹ • x) r := by rw [preimage_smul, smul_closedBall] #align metric.preimage_smul_closed_ball Metric.preimage_smul_closedBall #align metric.preimage_vadd_closed_ball Metric.preimage_vadd_closedBall @[to_additive (attr := simp)] theorem smul_sphere (c : G) (x : X) (r : ℝ) : c • sphere x r = sphere (c • x) r := (IsometryEquiv.constSMul c).image_sphere _ _ #align metric.smul_sphere Metric.smul_sphere #align metric.vadd_sphere Metric.vadd_sphere @[to_additive (attr := simp)] theorem preimage_smul_sphere (c : G) (x : X) (r : ℝ) : (c • ·) ⁻¹' sphere x r = sphere (c⁻¹ • x) r := by rw [preimage_smul, smul_sphere] #align metric.preimage_smul_sphere Metric.preimage_smul_sphere #align metric.preimage_vadd_sphere Metric.preimage_vadd_sphere variable [PseudoMetricSpace G] @[to_additive (attr := simp)] theorem preimage_mul_left_ball [IsometricSMul G G] (a b : G) (r : ℝ) : (a * ·) ⁻¹' ball b r = ball (a⁻¹ * b) r := preimage_smul_ball a b r #align metric.preimage_mul_left_ball Metric.preimage_mul_left_ball #align metric.preimage_add_left_ball Metric.preimage_add_left_ball @[to_additive (attr := simp)] theorem preimage_mul_right_ball [IsometricSMul Gᵐᵒᵖ G] (a b : G) (r : ℝ) : (fun x => x * a) ⁻¹' ball b r = ball (b / a) r := by rw [div_eq_mul_inv] exact preimage_smul_ball (MulOpposite.op a) b r #align metric.preimage_mul_right_ball Metric.preimage_mul_right_ball #align metric.preimage_add_right_ball Metric.preimage_add_right_ball @[to_additive (attr := simp)] theorem preimage_mul_left_closedBall [IsometricSMul G G] (a b : G) (r : ℝ) : (a * ·) ⁻¹' closedBall b r = closedBall (a⁻¹ * b) r := preimage_smul_closedBall a b r #align metric.preimage_mul_left_closed_ball Metric.preimage_mul_left_closedBall #align metric.preimage_add_left_closed_ball Metric.preimage_add_left_closedBall @[to_additive (attr := simp)]
Mathlib/Topology/MetricSpace/IsometricSMul.lean
500
503
theorem preimage_mul_right_closedBall [IsometricSMul Gᵐᵒᵖ G] (a b : G) (r : ℝ) : (fun x => x * a) ⁻¹' closedBall b r = closedBall (b / a) r := by
rw [div_eq_mul_inv] exact preimage_smul_closedBall (MulOpposite.op a) b r
/- Copyright (c) 2021 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Analysis.Normed.Group.Hom import Mathlib.Analysis.Normed.Group.Completion #align_import analysis.normed.group.hom_completion from "leanprover-community/mathlib"@"17ef379e997badd73e5eabb4d38f11919ab3c4b3" /-! # Completion of normed group homs Given two (semi) normed groups `G` and `H` and a normed group hom `f : NormedAddGroupHom G H`, we build and study a normed group hom `f.completion : NormedAddGroupHom (completion G) (completion H)` such that the diagram ``` f G -----------> H | | | | | | V V completion G -----------> completion H f.completion ``` commutes. The map itself comes from the general theory of completion of uniform spaces, but here we want a normed group hom, study its operator norm and kernel. The vertical maps in the above diagrams are also normed group homs constructed in this file. ## Main definitions and results: * `NormedAddGroupHom.completion`: see the discussion above. * `NormedAddCommGroup.toCompl : NormedAddGroupHom G (completion G)`: the canonical map from `G` to its completion, as a normed group hom * `NormedAddGroupHom.completion_toCompl`: the above diagram indeed commutes. * `NormedAddGroupHom.norm_completion`: `‖f.completion‖ = ‖f‖` * `NormedAddGroupHom.ker_le_ker_completion`: the kernel of `f.completion` contains the image of the kernel of `f`. * `NormedAddGroupHom.ker_completion`: the kernel of `f.completion` is the closure of the image of the kernel of `f` under an assumption that `f` is quantitatively surjective onto its image. * `NormedAddGroupHom.extension` : if `H` is complete, the extension of `f : NormedAddGroupHom G H` to a `NormedAddGroupHom (completion G) H`. -/ noncomputable section open Set NormedAddGroupHom UniformSpace section Completion variable {G : Type*} [SeminormedAddCommGroup G] {H : Type*} [SeminormedAddCommGroup H] {K : Type*} [SeminormedAddCommGroup K] /-- The normed group hom induced between completions. -/ def NormedAddGroupHom.completion (f : NormedAddGroupHom G H) : NormedAddGroupHom (Completion G) (Completion H) := .ofLipschitz (f.toAddMonoidHom.completion f.continuous) f.lipschitz.completion_map #align normed_add_group_hom.completion NormedAddGroupHom.completion theorem NormedAddGroupHom.completion_def (f : NormedAddGroupHom G H) (x : Completion G) : f.completion x = Completion.map f x := rfl #align normed_add_group_hom.completion_def NormedAddGroupHom.completion_def @[simp] theorem NormedAddGroupHom.completion_coe_to_fun (f : NormedAddGroupHom G H) : (f.completion : Completion G → Completion H) = Completion.map f := rfl #align normed_add_group_hom.completion_coe_to_fun NormedAddGroupHom.completion_coe_to_fun -- Porting note: `@[simp]` moved to the next lemma theorem NormedAddGroupHom.completion_coe (f : NormedAddGroupHom G H) (g : G) : f.completion g = f g := Completion.map_coe f.uniformContinuous _ #align normed_add_group_hom.completion_coe NormedAddGroupHom.completion_coe @[simp] theorem NormedAddGroupHom.completion_coe' (f : NormedAddGroupHom G H) (g : G) : Completion.map f g = f g := f.completion_coe g /-- Completion of normed group homs as a normed group hom. -/ @[simps] def normedAddGroupHomCompletionHom : NormedAddGroupHom G H →+ NormedAddGroupHom (Completion G) (Completion H) where toFun := NormedAddGroupHom.completion map_zero' := toAddMonoidHom_injective AddMonoidHom.completion_zero map_add' f g := toAddMonoidHom_injective <| f.toAddMonoidHom.completion_add g.toAddMonoidHom f.continuous g.continuous #align normed_add_group_hom_completion_hom normedAddGroupHomCompletionHom #align normed_add_group_hom_completion_hom_apply normedAddGroupHomCompletionHom_apply @[simp] theorem NormedAddGroupHom.completion_id : (NormedAddGroupHom.id G).completion = NormedAddGroupHom.id (Completion G) := by ext x rw [NormedAddGroupHom.completion_def, NormedAddGroupHom.coe_id, Completion.map_id] rfl #align normed_add_group_hom.completion_id NormedAddGroupHom.completion_id theorem NormedAddGroupHom.completion_comp (f : NormedAddGroupHom G H) (g : NormedAddGroupHom H K) : g.completion.comp f.completion = (g.comp f).completion := by ext x rw [NormedAddGroupHom.coe_comp, NormedAddGroupHom.completion_def, NormedAddGroupHom.completion_coe_to_fun, NormedAddGroupHom.completion_coe_to_fun, Completion.map_comp g.uniformContinuous f.uniformContinuous] rfl #align normed_add_group_hom.completion_comp NormedAddGroupHom.completion_comp theorem NormedAddGroupHom.completion_neg (f : NormedAddGroupHom G H) : (-f).completion = -f.completion := map_neg (normedAddGroupHomCompletionHom : NormedAddGroupHom G H →+ _) f #align normed_add_group_hom.completion_neg NormedAddGroupHom.completion_neg theorem NormedAddGroupHom.completion_add (f g : NormedAddGroupHom G H) : (f + g).completion = f.completion + g.completion := normedAddGroupHomCompletionHom.map_add f g #align normed_add_group_hom.completion_add NormedAddGroupHom.completion_add theorem NormedAddGroupHom.completion_sub (f g : NormedAddGroupHom G H) : (f - g).completion = f.completion - g.completion := map_sub (normedAddGroupHomCompletionHom : NormedAddGroupHom G H →+ _) f g #align normed_add_group_hom.completion_sub NormedAddGroupHom.completion_sub @[simp] theorem NormedAddGroupHom.zero_completion : (0 : NormedAddGroupHom G H).completion = 0 := normedAddGroupHomCompletionHom.map_zero #align normed_add_group_hom.zero_completion NormedAddGroupHom.zero_completion /-- The map from a normed group to its completion, as a normed group hom. -/ @[simps] -- Porting note: added `@[simps]` def NormedAddCommGroup.toCompl : NormedAddGroupHom G (Completion G) where toFun := (↑) map_add' := Completion.toCompl.map_add bound' := ⟨1, by simp [le_refl]⟩ #align normed_add_comm_group.to_compl NormedAddCommGroup.toCompl open NormedAddCommGroup theorem NormedAddCommGroup.norm_toCompl (x : G) : ‖toCompl x‖ = ‖x‖ := Completion.norm_coe x #align normed_add_comm_group.norm_to_compl NormedAddCommGroup.norm_toCompl theorem NormedAddCommGroup.denseRange_toCompl : DenseRange (toCompl : G → Completion G) := Completion.denseInducing_coe.dense #align normed_add_comm_group.dense_range_to_compl NormedAddCommGroup.denseRange_toCompl @[simp] theorem NormedAddGroupHom.completion_toCompl (f : NormedAddGroupHom G H) : f.completion.comp toCompl = toCompl.comp f := by ext x; simp #align normed_add_group_hom.completion_to_compl NormedAddGroupHom.completion_toCompl @[simp] theorem NormedAddGroupHom.norm_completion (f : NormedAddGroupHom G H) : ‖f.completion‖ = ‖f‖ := le_antisymm (ofLipschitz_norm_le _ _) <| opNorm_le_bound _ (norm_nonneg _) fun x => by simpa using f.completion.le_opNorm x #align normed_add_group_hom.norm_completion NormedAddGroupHom.norm_completion theorem NormedAddGroupHom.ker_le_ker_completion (f : NormedAddGroupHom G H) : (toCompl.comp <| incl f.ker).range ≤ f.completion.ker := by rintro _ ⟨⟨g, h₀ : f g = 0⟩, rfl⟩ simp [h₀, mem_ker, Completion.coe_zero] #align normed_add_group_hom.ker_le_ker_completion NormedAddGroupHom.ker_le_ker_completion theorem NormedAddGroupHom.ker_completion {f : NormedAddGroupHom G H} {C : ℝ} (h : f.SurjectiveOnWith f.range C) : (f.completion.ker : Set <| Completion G) = closure (toCompl.comp <| incl f.ker).range := by refine le_antisymm ?_ (closure_minimal f.ker_le_ker_completion f.completion.isClosed_ker) rintro hatg (hatg_in : f.completion hatg = 0) rw [SeminormedAddCommGroup.mem_closure_iff] intro ε ε_pos rcases h.exists_pos with ⟨C', C'_pos, hC'⟩ rcases exists_pos_mul_lt ε_pos (1 + C' * ‖f‖) with ⟨δ, δ_pos, hδ⟩ obtain ⟨_, ⟨g : G, rfl⟩, hg : ‖hatg - g‖ < δ⟩ := SeminormedAddCommGroup.mem_closure_iff.mp (Completion.denseInducing_coe.dense hatg) δ δ_pos obtain ⟨g' : G, hgg' : f g' = f g, hfg : ‖g'‖ ≤ C' * ‖f g‖⟩ := hC' (f g) (mem_range_self _ g) have mem_ker : g - g' ∈ f.ker := by rw [f.mem_ker, map_sub, sub_eq_zero.mpr hgg'.symm] refine ⟨_, ⟨⟨g - g', mem_ker⟩, rfl⟩, ?_⟩ have : ‖f g‖ ≤ ‖f‖ * δ := calc ‖f g‖ ≤ ‖f‖ * ‖hatg - g‖ := by simpa [hatg_in] using f.completion.le_opNorm (hatg - g) _ ≤ ‖f‖ * δ := by gcongr calc ‖hatg - ↑(g - g')‖ = ‖hatg - g + g'‖ := by rw [Completion.coe_sub, sub_add] _ ≤ ‖hatg - g‖ + ‖(g' : Completion G)‖ := norm_add_le _ _ _ = ‖hatg - g‖ + ‖g'‖ := by rw [Completion.norm_coe] _ < δ + C' * ‖f g‖ := add_lt_add_of_lt_of_le hg hfg _ ≤ δ + C' * (‖f‖ * δ) := by gcongr _ < ε := by simpa only [add_mul, one_mul, mul_assoc] using hδ #align normed_add_group_hom.ker_completion NormedAddGroupHom.ker_completion end Completion section Extension variable {G : Type*} [SeminormedAddCommGroup G] variable {H : Type*} [SeminormedAddCommGroup H] [T0Space H] [CompleteSpace H] /-- If `H` is complete, the extension of `f : NormedAddGroupHom G H` to a `NormedAddGroupHom (completion G) H`. -/ def NormedAddGroupHom.extension (f : NormedAddGroupHom G H) : NormedAddGroupHom (Completion G) H := .ofLipschitz (f.toAddMonoidHom.extension f.continuous) <| let _ := MetricSpace.ofT0PseudoMetricSpace H f.lipschitz.completion_extension #align normed_add_group_hom.extension NormedAddGroupHom.extension theorem NormedAddGroupHom.extension_def (f : NormedAddGroupHom G H) (v : G) : f.extension v = Completion.extension f v := rfl #align normed_add_group_hom.extension_def NormedAddGroupHom.extension_def @[simp] theorem NormedAddGroupHom.extension_coe (f : NormedAddGroupHom G H) (v : G) : f.extension v = f v := AddMonoidHom.extension_coe _ f.continuous _ #align normed_add_group_hom.extension_coe NormedAddGroupHom.extension_coe theorem NormedAddGroupHom.extension_coe_to_fun (f : NormedAddGroupHom G H) : (f.extension : Completion G → H) = Completion.extension f := rfl #align normed_add_group_hom.extension_coe_to_fun NormedAddGroupHom.extension_coe_to_fun
Mathlib/Analysis/Normed/Group/HomCompletion.lean
226
230
theorem NormedAddGroupHom.extension_unique (f : NormedAddGroupHom G H) {g : NormedAddGroupHom (Completion G) H} (hg : ∀ v, f v = g v) : f.extension = g := by
ext v rw [NormedAddGroupHom.extension_coe_to_fun, Completion.extension_unique f.uniformContinuous g.uniformContinuous fun a => hg a]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios -/ import Mathlib.SetTheory.Ordinal.Basic import Mathlib.Data.Nat.SuccPred #align_import set_theory.ordinal.arithmetic from "leanprover-community/mathlib"@"31b269b60935483943542d547a6dd83a66b37dc7" /-! # Ordinal arithmetic Ordinals have an addition (corresponding to disjoint union) that turns them into an additive monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns them into a monoid. One can also define correspondingly a subtraction, a division, a successor function, a power function and a logarithm function. We also define limit ordinals and prove the basic induction principle on ordinals separating successor ordinals and limit ordinals, in `limitRecOn`. ## Main definitions and results * `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that every element of `o₁` is smaller than every element of `o₂`. * `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`. * `o₁ * o₂` is the lexicographic order on `o₂ × o₁`. * `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the divisibility predicate, and a modulo operation. * `Order.succ o = o + 1` is the successor of `o`. * `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`. We discuss the properties of casts of natural numbers of and of `ω` with respect to these operations. Some properties of the operations are also used to discuss general tools on ordinals: * `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor. * `limitRecOn` is the main induction principle of ordinals: if one can prove a property by induction at successor ordinals and at limit ordinals, then it holds for all ordinals. * `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for `a < o`. * `enumOrd`: enumerates an unbounded set of ordinals by the ordinals themselves. * `sup`, `lsub`: the supremum / least strict upper bound of an indexed family of ordinals in `Type u`, as an ordinal in `Type u`. * `bsup`, `blsub`: the supremum / least strict upper bound of a set of ordinals indexed by ordinals less than a given ordinal `o`. Various other basic arithmetic results are given in `Principal.lean` instead. -/ assert_not_exists Field assert_not_exists Module noncomputable section open Function Cardinal Set Equiv Order open scoped Classical open Cardinal Ordinal universe u v w namespace Ordinal variable {α : Type*} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} /-! ### Further properties of addition on ordinals -/ @[simp] theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b := Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift _).trans (RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩ #align ordinal.lift_add Ordinal.lift_add @[simp] theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by rw [← add_one_eq_succ, lift_add, lift_one] rfl #align ordinal.lift_succ Ordinal.lift_succ instance add_contravariantClass_le : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· ≤ ·) := ⟨fun a b c => inductionOn a fun α r hr => inductionOn b fun β₁ s₁ hs₁ => inductionOn c fun β₂ s₂ hs₂ ⟨f⟩ => ⟨have fl : ∀ a, f (Sum.inl a) = Sum.inl a := fun a => by simpa only [InitialSeg.trans_apply, InitialSeg.leAdd_apply] using @InitialSeg.eq _ _ _ _ _ ((InitialSeg.leAdd r s₁).trans f) (InitialSeg.leAdd r s₂) a have : ∀ b, { b' // f (Sum.inr b) = Sum.inr b' } := by intro b; cases e : f (Sum.inr b) · rw [← fl] at e have := f.inj' e contradiction · exact ⟨_, rfl⟩ let g (b) := (this b).1 have fr : ∀ b, f (Sum.inr b) = Sum.inr (g b) := fun b => (this b).2 ⟨⟨⟨g, fun x y h => by injection f.inj' (by rw [fr, fr, h] : f (Sum.inr x) = f (Sum.inr y))⟩, @fun a b => by -- Porting note: -- `relEmbedding.coe_fn_to_embedding` & `initial_seg.coe_fn_to_rel_embedding` -- → `InitialSeg.coe_coe_fn` simpa only [Sum.lex_inr_inr, fr, InitialSeg.coe_coe_fn, Embedding.coeFn_mk] using @RelEmbedding.map_rel_iff _ _ _ _ f.toRelEmbedding (Sum.inr a) (Sum.inr b)⟩, fun a b H => by rcases f.init (by rw [fr] <;> exact Sum.lex_inr_inr.2 H) with ⟨a' | a', h⟩ · rw [fl] at h cases h · rw [fr] at h exact ⟨a', Sum.inr.inj h⟩⟩⟩⟩ #align ordinal.add_contravariant_class_le Ordinal.add_contravariantClass_le theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c := by simp only [le_antisymm_iff, add_le_add_iff_left] #align ordinal.add_left_cancel Ordinal.add_left_cancel private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by rw [← not_le, ← not_le, add_le_add_iff_left] instance add_covariantClass_lt : CovariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) := ⟨fun a _b _c => (add_lt_add_iff_left' a).2⟩ #align ordinal.add_covariant_class_lt Ordinal.add_covariantClass_lt instance add_contravariantClass_lt : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) := ⟨fun a _b _c => (add_lt_add_iff_left' a).1⟩ #align ordinal.add_contravariant_class_lt Ordinal.add_contravariantClass_lt instance add_swap_contravariantClass_lt : ContravariantClass Ordinal.{u} Ordinal.{u} (swap (· + ·)) (· < ·) := ⟨fun _a _b _c => lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩ #align ordinal.add_swap_contravariant_class_lt Ordinal.add_swap_contravariantClass_lt theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b | 0 => by simp | n + 1 => by simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right] #align ordinal.add_le_add_iff_right Ordinal.add_le_add_iff_right theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by simp only [le_antisymm_iff, add_le_add_iff_right] #align ordinal.add_right_cancel Ordinal.add_right_cancel theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 := inductionOn a fun α r _ => inductionOn b fun β s _ => by simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty] exact isEmpty_sum #align ordinal.add_eq_zero_iff Ordinal.add_eq_zero_iff theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 := (add_eq_zero_iff.1 h).1 #align ordinal.left_eq_zero_of_add_eq_zero Ordinal.left_eq_zero_of_add_eq_zero theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 := (add_eq_zero_iff.1 h).2 #align ordinal.right_eq_zero_of_add_eq_zero Ordinal.right_eq_zero_of_add_eq_zero /-! ### The predecessor of an ordinal -/ /-- The ordinal predecessor of `o` is `o'` if `o = succ o'`, and `o` otherwise. -/ def pred (o : Ordinal) : Ordinal := if h : ∃ a, o = succ a then Classical.choose h else o #align ordinal.pred Ordinal.pred @[simp] theorem pred_succ (o) : pred (succ o) = o := by have h : ∃ a, succ o = succ a := ⟨_, rfl⟩; simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm #align ordinal.pred_succ Ordinal.pred_succ theorem pred_le_self (o) : pred o ≤ o := if h : ∃ a, o = succ a then by let ⟨a, e⟩ := h rw [e, pred_succ]; exact le_succ a else by rw [pred, dif_neg h] #align ordinal.pred_le_self Ordinal.pred_le_self theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a := ⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩ #align ordinal.pred_eq_iff_not_succ Ordinal.pred_eq_iff_not_succ theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by simpa using pred_eq_iff_not_succ #align ordinal.pred_eq_iff_not_succ' Ordinal.pred_eq_iff_not_succ' theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a := Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and_iff, not_le]) (iff_not_comm.1 pred_eq_iff_not_succ).symm #align ordinal.pred_lt_iff_is_succ Ordinal.pred_lt_iff_is_succ @[simp] theorem pred_zero : pred 0 = 0 := pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm #align ordinal.pred_zero Ordinal.pred_zero theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a := ⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩ #align ordinal.succ_pred_iff_is_succ Ordinal.succ_pred_iff_is_succ theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o := ⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩ #align ordinal.succ_lt_of_not_succ Ordinal.succ_lt_of_not_succ theorem lt_pred {a b} : a < pred b ↔ succ a < b := if h : ∃ a, b = succ a then by let ⟨c, e⟩ := h rw [e, pred_succ, succ_lt_succ_iff] else by simp only [pred, dif_neg h, succ_lt_of_not_succ h] #align ordinal.lt_pred Ordinal.lt_pred theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b := le_iff_le_iff_lt_iff_lt.2 lt_pred #align ordinal.pred_le Ordinal.pred_le @[simp] theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a := ⟨fun ⟨a, h⟩ => let ⟨b, e⟩ := lift_down <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a ⟨b, lift_inj.1 <| by rw [h, ← e, lift_succ]⟩, fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩ #align ordinal.lift_is_succ Ordinal.lift_is_succ @[simp] theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) := if h : ∃ a, o = succ a then by cases' h with a e; simp only [e, pred_succ, lift_succ] else by rw [pred_eq_iff_not_succ.2 h, pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)] #align ordinal.lift_pred Ordinal.lift_pred /-! ### Limit ordinals -/ /-- A limit ordinal is an ordinal which is not zero and not a successor. -/ def IsLimit (o : Ordinal) : Prop := o ≠ 0 ∧ ∀ a < o, succ a < o #align ordinal.is_limit Ordinal.IsLimit theorem IsLimit.isSuccLimit {o} (h : IsLimit o) : IsSuccLimit o := isSuccLimit_iff_succ_lt.mpr h.2 theorem IsLimit.succ_lt {o a : Ordinal} (h : IsLimit o) : a < o → succ a < o := h.2 a #align ordinal.is_limit.succ_lt Ordinal.IsLimit.succ_lt theorem isSuccLimit_zero : IsSuccLimit (0 : Ordinal) := isSuccLimit_bot theorem not_zero_isLimit : ¬IsLimit 0 | ⟨h, _⟩ => h rfl #align ordinal.not_zero_is_limit Ordinal.not_zero_isLimit theorem not_succ_isLimit (o) : ¬IsLimit (succ o) | ⟨_, h⟩ => lt_irrefl _ (h _ (lt_succ o)) #align ordinal.not_succ_is_limit Ordinal.not_succ_isLimit theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a | ⟨a, e⟩ => not_succ_isLimit a (e ▸ h) #align ordinal.not_succ_of_is_limit Ordinal.not_succ_of_isLimit theorem succ_lt_of_isLimit {o a : Ordinal} (h : IsLimit o) : succ a < o ↔ a < o := ⟨(lt_succ a).trans, h.2 _⟩ #align ordinal.succ_lt_of_is_limit Ordinal.succ_lt_of_isLimit theorem le_succ_of_isLimit {o} (h : IsLimit o) {a} : o ≤ succ a ↔ o ≤ a := le_iff_le_iff_lt_iff_lt.2 <| succ_lt_of_isLimit h #align ordinal.le_succ_of_is_limit Ordinal.le_succ_of_isLimit theorem limit_le {o} (h : IsLimit o) {a} : o ≤ a ↔ ∀ x < o, x ≤ a := ⟨fun h _x l => l.le.trans h, fun H => (le_succ_of_isLimit h).1 <| le_of_not_lt fun hn => not_lt_of_le (H _ hn) (lt_succ a)⟩ #align ordinal.limit_le Ordinal.limit_le theorem lt_limit {o} (h : IsLimit o) {a} : a < o ↔ ∃ x < o, a < x := by -- Porting note: `bex_def` is required. simpa only [not_forall₂, not_le, bex_def] using not_congr (@limit_le _ h a) #align ordinal.lt_limit Ordinal.lt_limit @[simp] theorem lift_isLimit (o) : IsLimit (lift o) ↔ IsLimit o := and_congr (not_congr <| by simpa only [lift_zero] using @lift_inj o 0) ⟨fun H a h => lift_lt.1 <| by simpa only [lift_succ] using H _ (lift_lt.2 h), fun H a h => by obtain ⟨a', rfl⟩ := lift_down h.le rw [← lift_succ, lift_lt] exact H a' (lift_lt.1 h)⟩ #align ordinal.lift_is_limit Ordinal.lift_isLimit theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o := lt_of_le_of_ne (Ordinal.zero_le _) h.1.symm #align ordinal.is_limit.pos Ordinal.IsLimit.pos theorem IsLimit.one_lt {o : Ordinal} (h : IsLimit o) : 1 < o := by simpa only [succ_zero] using h.2 _ h.pos #align ordinal.is_limit.one_lt Ordinal.IsLimit.one_lt theorem IsLimit.nat_lt {o : Ordinal} (h : IsLimit o) : ∀ n : ℕ, (n : Ordinal) < o | 0 => h.pos | n + 1 => h.2 _ (IsLimit.nat_lt h n) #align ordinal.is_limit.nat_lt Ordinal.IsLimit.nat_lt theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o := if o0 : o = 0 then Or.inl o0 else if h : ∃ a, o = succ a then Or.inr (Or.inl h) else Or.inr <| Or.inr ⟨o0, fun _a => (succ_lt_of_not_succ h).2⟩ #align ordinal.zero_or_succ_or_limit Ordinal.zero_or_succ_or_limit /-- Main induction principle of ordinals: if one can prove a property by induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/ @[elab_as_elim] def limitRecOn {C : Ordinal → Sort*} (o : Ordinal) (H₁ : C 0) (H₂ : ∀ o, C o → C (succ o)) (H₃ : ∀ o, IsLimit o → (∀ o' < o, C o') → C o) : C o := SuccOrder.limitRecOn o (fun o _ ↦ H₂ o) fun o hl ↦ if h : o = 0 then fun _ ↦ h ▸ H₁ else H₃ o ⟨h, fun _ ↦ hl.succ_lt⟩ #align ordinal.limit_rec_on Ordinal.limitRecOn @[simp] theorem limitRecOn_zero {C} (H₁ H₂ H₃) : @limitRecOn C 0 H₁ H₂ H₃ = H₁ := by rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ isSuccLimit_zero, dif_pos rfl] #align ordinal.limit_rec_on_zero Ordinal.limitRecOn_zero @[simp] theorem limitRecOn_succ {C} (o H₁ H₂ H₃) : @limitRecOn C (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn C o H₁ H₂ H₃) := by simp_rw [limitRecOn, SuccOrder.limitRecOn_succ _ _ (not_isMax _)] #align ordinal.limit_rec_on_succ Ordinal.limitRecOn_succ @[simp] theorem limitRecOn_limit {C} (o H₁ H₂ H₃ h) : @limitRecOn C o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn C x H₁ H₂ H₃ := by simp_rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ h.isSuccLimit, dif_neg h.1] #align ordinal.limit_rec_on_limit Ordinal.limitRecOn_limit instance orderTopOutSucc (o : Ordinal) : OrderTop (succ o).out.α := @OrderTop.mk _ _ (Top.mk _) le_enum_succ #align ordinal.order_top_out_succ Ordinal.orderTopOutSucc theorem enum_succ_eq_top {o : Ordinal} : enum (· < ·) o (by rw [type_lt] exact lt_succ o) = (⊤ : (succ o).out.α) := rfl #align ordinal.enum_succ_eq_top Ordinal.enum_succ_eq_top theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r] (h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by use enum r (succ (typein r x)) (h _ (typein_lt_type r x)) convert (enum_lt_enum (typein_lt_type r x) (h _ (typein_lt_type r x))).mpr (lt_succ _); rw [enum_typein] #align ordinal.has_succ_of_type_succ_lt Ordinal.has_succ_of_type_succ_lt theorem out_no_max_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.out.α := ⟨has_succ_of_type_succ_lt (by rwa [type_lt])⟩ #align ordinal.out_no_max_of_succ_lt Ordinal.out_no_max_of_succ_lt theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : (type r).IsLimit) (x) : Bounded r {x} := by refine ⟨enum r (succ (typein r x)) (hr.2 _ (typein_lt_type r x)), ?_⟩ intro b hb rw [mem_singleton_iff.1 hb] nth_rw 1 [← enum_typein r x] rw [@enum_lt_enum _ r] apply lt_succ #align ordinal.bounded_singleton Ordinal.bounded_singleton -- Porting note: `· < ·` requires a type ascription for an `IsWellOrder` instance. theorem type_subrel_lt (o : Ordinal.{u}) : type (Subrel ((· < ·) : Ordinal → Ordinal → Prop) { o' : Ordinal | o' < o }) = Ordinal.lift.{u + 1} o := by refine Quotient.inductionOn o ?_ rintro ⟨α, r, wo⟩; apply Quotient.sound -- Porting note: `symm; refine' [term]` → `refine' [term].symm` constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enumIso r).symm).symm #align ordinal.type_subrel_lt Ordinal.type_subrel_lt theorem mk_initialSeg (o : Ordinal.{u}) : #{ o' : Ordinal | o' < o } = Cardinal.lift.{u + 1} o.card := by rw [lift_card, ← type_subrel_lt, card_type] #align ordinal.mk_initial_seg Ordinal.mk_initialSeg /-! ### Normal ordinal functions -/ /-- A normal ordinal function is a strictly increasing function which is order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for `a < o`. -/ def IsNormal (f : Ordinal → Ordinal) : Prop := (∀ o, f o < f (succ o)) ∧ ∀ o, IsLimit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a #align ordinal.is_normal Ordinal.IsNormal theorem IsNormal.limit_le {f} (H : IsNormal f) : ∀ {o}, IsLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a := @H.2 #align ordinal.is_normal.limit_le Ordinal.IsNormal.limit_le theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsLimit o) {a} : a < f o ↔ ∃ b < o, a < f b := not_iff_not.1 <| by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a #align ordinal.is_normal.limit_lt Ordinal.IsNormal.limit_lt theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := fun a b => limitRecOn b (Not.elim (not_lt_of_le <| Ordinal.zero_le _)) (fun _b IH h => (lt_or_eq_of_le (le_of_lt_succ h)).elim (fun h => (IH h).trans (H.1 _)) fun e => e ▸ H.1 _) fun _b l _IH h => lt_of_lt_of_le (H.1 a) ((H.2 _ l _).1 le_rfl _ (l.2 _ h)) #align ordinal.is_normal.strict_mono Ordinal.IsNormal.strictMono theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f := H.strictMono.monotone #align ordinal.is_normal.monotone Ordinal.IsNormal.monotone theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) : IsNormal f ↔ StrictMono f ∧ ∀ o, IsLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a := ⟨fun hf => ⟨hf.strictMono, fun a ha c => (hf.2 a ha c).2⟩, fun ⟨hs, hl⟩ => ⟨fun a => hs (lt_succ a), fun a ha c => ⟨fun hac _b hba => ((hs hba).trans_le hac).le, hl a ha c⟩⟩⟩ #align ordinal.is_normal_iff_strict_mono_limit Ordinal.isNormal_iff_strictMono_limit theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b := StrictMono.lt_iff_lt <| H.strictMono #align ordinal.is_normal.lt_iff Ordinal.IsNormal.lt_iff theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b := le_iff_le_iff_lt_iff_lt.2 H.lt_iff #align ordinal.is_normal.le_iff Ordinal.IsNormal.le_iff theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by simp only [le_antisymm_iff, H.le_iff] #align ordinal.is_normal.inj Ordinal.IsNormal.inj theorem IsNormal.self_le {f} (H : IsNormal f) (a) : a ≤ f a := lt_wf.self_le_of_strictMono H.strictMono a #align ordinal.is_normal.self_le Ordinal.IsNormal.self_le theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b) (H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o := ⟨fun h a pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by -- Porting note: `refine'` didn't work well so `induction` is used induction b using limitRecOn with | H₁ => cases' p0 with x px have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px) rw [this] at px exact h _ px | H₂ S _ => rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_le) with ⟨a, h₁, h₂⟩ exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁) | H₃ S L _ => refine (H.2 _ L _).2 fun a h' => ?_ rcases not_forall₂.1 (mt (H₂ a).2 h'.not_le) with ⟨b, h₁, h₂⟩ exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩ #align ordinal.is_normal.le_set Ordinal.IsNormal.le_set theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b) (H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by simpa [H₂] using H.le_set (g '' p) (p0.image g) b #align ordinal.is_normal.le_set' Ordinal.IsNormal.le_set' theorem IsNormal.refl : IsNormal id := ⟨lt_succ, fun _o l _a => Ordinal.limit_le l⟩ #align ordinal.is_normal.refl Ordinal.IsNormal.refl theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) := ⟨fun _x => H₁.lt_iff.2 (H₂.1 _), fun o l _a => H₁.le_set' (· < o) ⟨0, l.pos⟩ g _ fun _c => H₂.2 _ l _⟩ #align ordinal.is_normal.trans Ordinal.IsNormal.trans theorem IsNormal.isLimit {f} (H : IsNormal f) {o} (l : IsLimit o) : IsLimit (f o) := ⟨ne_of_gt <| (Ordinal.zero_le _).trans_lt <| H.lt_iff.2 l.pos, fun _ h => let ⟨_b, h₁, h₂⟩ := (H.limit_lt l).1 h (succ_le_of_lt h₂).trans_lt (H.lt_iff.2 h₁)⟩ #align ordinal.is_normal.is_limit Ordinal.IsNormal.isLimit theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a := (H.self_le a).le_iff_eq #align ordinal.is_normal.le_iff_eq Ordinal.IsNormal.le_iff_eq theorem add_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c := ⟨fun h b' l => (add_le_add_left l.le _).trans h, fun H => le_of_not_lt <| by -- Porting note: `induction` tactics are required because of the parser bug. induction a using inductionOn with | H α r => induction b using inductionOn with | H β s => intro l suffices ∀ x : β, Sum.Lex r s (Sum.inr x) (enum _ _ l) by -- Porting note: `revert` & `intro` is required because `cases'` doesn't replace -- `enum _ _ l` in `this`. revert this; cases' enum _ _ l with x x <;> intro this · cases this (enum s 0 h.pos) · exact irrefl _ (this _) intro x rw [← typein_lt_typein (Sum.Lex r s), typein_enum] have := H _ (h.2 _ (typein_lt_type s x)) rw [add_succ, succ_le_iff] at this refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this · rcases a with ⟨a | b, h⟩ · exact Sum.inl a · exact Sum.inr ⟨b, by cases h; assumption⟩ · rcases a with ⟨a | a, h₁⟩ <;> rcases b with ⟨b | b, h₂⟩ <;> cases h₁ <;> cases h₂ <;> rintro ⟨⟩ <;> constructor <;> assumption⟩ #align ordinal.add_le_of_limit Ordinal.add_le_of_limit theorem add_isNormal (a : Ordinal) : IsNormal (a + ·) := ⟨fun b => (add_lt_add_iff_left a).2 (lt_succ b), fun _b l _c => add_le_of_limit l⟩ #align ordinal.add_is_normal Ordinal.add_isNormal theorem add_isLimit (a) {b} : IsLimit b → IsLimit (a + b) := (add_isNormal a).isLimit #align ordinal.add_is_limit Ordinal.add_isLimit alias IsLimit.add := add_isLimit #align ordinal.is_limit.add Ordinal.IsLimit.add /-! ### Subtraction on ordinals-/ /-- The set in the definition of subtraction is nonempty. -/ theorem sub_nonempty {a b : Ordinal} : { o | a ≤ b + o }.Nonempty := ⟨a, le_add_left _ _⟩ #align ordinal.sub_nonempty Ordinal.sub_nonempty /-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/ instance sub : Sub Ordinal := ⟨fun a b => sInf { o | a ≤ b + o }⟩ theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) := csInf_mem sub_nonempty #align ordinal.le_add_sub Ordinal.le_add_sub theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c := ⟨fun h => (le_add_sub a b).trans (add_le_add_left h _), fun h => csInf_le' h⟩ #align ordinal.sub_le Ordinal.sub_le theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b := lt_iff_lt_of_le_iff_le sub_le #align ordinal.lt_sub Ordinal.lt_sub theorem add_sub_cancel (a b : Ordinal) : a + b - a = b := le_antisymm (sub_le.2 <| le_rfl) ((add_le_add_iff_left a).1 <| le_add_sub _ _) #align ordinal.add_sub_cancel Ordinal.add_sub_cancel theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b := h ▸ add_sub_cancel _ _ #align ordinal.sub_eq_of_add_eq Ordinal.sub_eq_of_add_eq theorem sub_le_self (a b : Ordinal) : a - b ≤ a := sub_le.2 <| le_add_left _ _ #align ordinal.sub_le_self Ordinal.sub_le_self protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a := (le_add_sub a b).antisymm' (by rcases zero_or_succ_or_limit (a - b) with (e | ⟨c, e⟩ | l) · simp only [e, add_zero, h] · rw [e, add_succ, succ_le_iff, ← lt_sub, e] exact lt_succ c · exact (add_le_of_limit l).2 fun c l => (lt_sub.1 l).le) #align ordinal.add_sub_cancel_of_le Ordinal.add_sub_cancel_of_le theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h] #align ordinal.le_sub_of_le Ordinal.le_sub_of_le theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c := lt_iff_lt_of_le_iff_le (le_sub_of_le h) #align ordinal.sub_lt_of_le Ordinal.sub_lt_of_le instance existsAddOfLE : ExistsAddOfLE Ordinal := ⟨fun h => ⟨_, (Ordinal.add_sub_cancel_of_le h).symm⟩⟩ @[simp] theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a #align ordinal.sub_zero Ordinal.sub_zero @[simp] theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self #align ordinal.zero_sub Ordinal.zero_sub @[simp] theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0 #align ordinal.sub_self Ordinal.sub_self protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b := ⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by rwa [← Ordinal.le_zero, sub_le, add_zero]⟩ #align ordinal.sub_eq_zero_iff_le Ordinal.sub_eq_zero_iff_le theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) := eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc] #align ordinal.sub_sub Ordinal.sub_sub @[simp] theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by rw [← sub_sub, add_sub_cancel] #align ordinal.add_sub_add_cancel Ordinal.add_sub_add_cancel theorem sub_isLimit {a b} (l : IsLimit a) (h : b < a) : IsLimit (a - b) := ⟨ne_of_gt <| lt_sub.2 <| by rwa [add_zero], fun c h => by rw [lt_sub, add_succ]; exact l.2 _ (lt_sub.1 h)⟩ #align ordinal.sub_is_limit Ordinal.sub_isLimit -- @[simp] -- Porting note (#10618): simp can prove this theorem one_add_omega : 1 + ω = ω := by refine le_antisymm ?_ (le_add_left _ _) rw [omega, ← lift_one.{_, 0}, ← lift_add, lift_le, ← type_unit, ← type_sum_lex] refine ⟨RelEmbedding.collapse (RelEmbedding.ofMonotone ?_ ?_)⟩ · apply Sum.rec · exact fun _ => 0 · exact Nat.succ · intro a b cases a <;> cases b <;> intro H <;> cases' H with _ _ H _ _ H <;> [exact H.elim; exact Nat.succ_pos _; exact Nat.succ_lt_succ H] #align ordinal.one_add_omega Ordinal.one_add_omega @[simp] theorem one_add_of_omega_le {o} (h : ω ≤ o) : 1 + o = o := by rw [← Ordinal.add_sub_cancel_of_le h, ← add_assoc, one_add_omega] #align ordinal.one_add_of_omega_le Ordinal.one_add_of_omega_le /-! ### Multiplication of ordinals-/ /-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on `o₂ × o₁`. -/ instance monoid : Monoid Ordinal.{u} where mul a b := Quotient.liftOn₂ a b (fun ⟨α, r, wo⟩ ⟨β, s, wo'⟩ => ⟦⟨β × α, Prod.Lex s r, inferInstance⟩⟧ : WellOrder → WellOrder → Ordinal) fun ⟨α₁, r₁, o₁⟩ ⟨α₂, r₂, o₂⟩ ⟨β₁, s₁, p₁⟩ ⟨β₂, s₂, p₂⟩ ⟨f⟩ ⟨g⟩ => Quot.sound ⟨RelIso.prodLexCongr g f⟩ one := 1 mul_assoc a b c := Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ => Eq.symm <| Quotient.sound ⟨⟨prodAssoc _ _ _, @fun a b => by rcases a with ⟨⟨a₁, a₂⟩, a₃⟩ rcases b with ⟨⟨b₁, b₂⟩, b₃⟩ simp [Prod.lex_def, and_or_left, or_assoc, and_assoc]⟩⟩ mul_one a := inductionOn a fun α r _ => Quotient.sound ⟨⟨punitProd _, @fun a b => by rcases a with ⟨⟨⟨⟩⟩, a⟩; rcases b with ⟨⟨⟨⟩⟩, b⟩ simp only [Prod.lex_def, EmptyRelation, false_or_iff] simp only [eq_self_iff_true, true_and_iff] rfl⟩⟩ one_mul a := inductionOn a fun α r _ => Quotient.sound ⟨⟨prodPUnit _, @fun a b => by rcases a with ⟨a, ⟨⟨⟩⟩⟩; rcases b with ⟨b, ⟨⟨⟩⟩⟩ simp only [Prod.lex_def, EmptyRelation, and_false_iff, or_false_iff] rfl⟩⟩ @[simp] theorem type_prod_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r] [IsWellOrder β s] : type (Prod.Lex s r) = type r * type s := rfl #align ordinal.type_prod_lex Ordinal.type_prod_lex private theorem mul_eq_zero' {a b : Ordinal} : a * b = 0 ↔ a = 0 ∨ b = 0 := inductionOn a fun α _ _ => inductionOn b fun β _ _ => by simp_rw [← type_prod_lex, type_eq_zero_iff_isEmpty] rw [or_comm] exact isEmpty_prod instance monoidWithZero : MonoidWithZero Ordinal := { Ordinal.monoid with zero := 0 mul_zero := fun _a => mul_eq_zero'.2 <| Or.inr rfl zero_mul := fun _a => mul_eq_zero'.2 <| Or.inl rfl } instance noZeroDivisors : NoZeroDivisors Ordinal := ⟨fun {_ _} => mul_eq_zero'.1⟩ @[simp] theorem lift_mul (a b : Ordinal.{v}) : lift.{u} (a * b) = lift.{u} a * lift.{u} b := Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift _).trans (RelIso.prodLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩ #align ordinal.lift_mul Ordinal.lift_mul @[simp] theorem card_mul (a b) : card (a * b) = card a * card b := Quotient.inductionOn₂ a b fun ⟨α, _r, _⟩ ⟨β, _s, _⟩ => mul_comm #β #α #align ordinal.card_mul Ordinal.card_mul instance leftDistribClass : LeftDistribClass Ordinal.{u} := ⟨fun a b c => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ => Quotient.sound ⟨⟨sumProdDistrib _ _ _, by rintro ⟨a₁ | a₁, a₂⟩ ⟨b₁ | b₁, b₂⟩ <;> simp only [Prod.lex_def, Sum.lex_inl_inl, Sum.Lex.sep, Sum.lex_inr_inl, Sum.lex_inr_inr, sumProdDistrib_apply_left, sumProdDistrib_apply_right] <;> -- Porting note: `Sum.inr.inj_iff` is required. simp only [Sum.inl.inj_iff, Sum.inr.inj_iff, true_or_iff, false_and_iff, false_or_iff]⟩⟩⟩ theorem mul_succ (a b : Ordinal) : a * succ b = a * b + a := mul_add_one a b #align ordinal.mul_succ Ordinal.mul_succ instance mul_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (· * ·) (· ≤ ·) := ⟨fun c a b => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by refine (RelEmbedding.ofMonotone (fun a : α × γ => (f a.1, a.2)) fun a b h => ?_).ordinal_type_le cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h' · exact Prod.Lex.left _ _ (f.toRelEmbedding.map_rel_iff.2 h') · exact Prod.Lex.right _ h'⟩ #align ordinal.mul_covariant_class_le Ordinal.mul_covariantClass_le instance mul_swap_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (swap (· * ·)) (· ≤ ·) := ⟨fun c a b => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by refine (RelEmbedding.ofMonotone (fun a : γ × α => (a.1, f a.2)) fun a b h => ?_).ordinal_type_le cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h' · exact Prod.Lex.left _ _ h' · exact Prod.Lex.right _ (f.toRelEmbedding.map_rel_iff.2 h')⟩ #align ordinal.mul_swap_covariant_class_le Ordinal.mul_swap_covariantClass_le theorem le_mul_left (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ a * b := by convert mul_le_mul_left' (one_le_iff_pos.2 hb) a rw [mul_one a] #align ordinal.le_mul_left Ordinal.le_mul_left theorem le_mul_right (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ b * a := by convert mul_le_mul_right' (one_le_iff_pos.2 hb) a rw [one_mul a] #align ordinal.le_mul_right Ordinal.le_mul_right private theorem mul_le_of_limit_aux {α β r s} [IsWellOrder α r] [IsWellOrder β s] {c} (h : IsLimit (type s)) (H : ∀ b' < type s, type r * b' ≤ c) (l : c < type r * type s) : False := by suffices ∀ a b, Prod.Lex s r (b, a) (enum _ _ l) by cases' enum _ _ l with b a exact irrefl _ (this _ _) intro a b rw [← typein_lt_typein (Prod.Lex s r), typein_enum] have := H _ (h.2 _ (typein_lt_type s b)) rw [mul_succ] at this have := ((add_lt_add_iff_left _).2 (typein_lt_type _ a)).trans_le this refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this · rcases a with ⟨⟨b', a'⟩, h⟩ by_cases e : b = b' · refine Sum.inr ⟨a', ?_⟩ subst e cases' h with _ _ _ _ h _ _ _ h · exact (irrefl _ h).elim · exact h · refine Sum.inl (⟨b', ?_⟩, a') cases' h with _ _ _ _ h _ _ _ h · exact h · exact (e rfl).elim · rcases a with ⟨⟨b₁, a₁⟩, h₁⟩ rcases b with ⟨⟨b₂, a₂⟩, h₂⟩ intro h by_cases e₁ : b = b₁ <;> by_cases e₂ : b = b₂ · substs b₁ b₂ simpa only [subrel_val, Prod.lex_def, @irrefl _ s _ b, true_and_iff, false_or_iff, eq_self_iff_true, dif_pos, Sum.lex_inr_inr] using h · subst b₁ simp only [subrel_val, Prod.lex_def, e₂, Prod.lex_def, dif_pos, subrel_val, eq_self_iff_true, or_false_iff, dif_neg, not_false_iff, Sum.lex_inr_inl, false_and_iff] at h ⊢ cases' h₂ with _ _ _ _ h₂_h h₂_h <;> [exact asymm h h₂_h; exact e₂ rfl] -- Porting note: `cc` hadn't ported yet. · simp [e₂, dif_neg e₁, show b₂ ≠ b₁ from e₂ ▸ e₁] · simpa only [dif_neg e₁, dif_neg e₂, Prod.lex_def, subrel_val, Subtype.mk_eq_mk, Sum.lex_inl_inl] using h theorem mul_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a * b ≤ c ↔ ∀ b' < b, a * b' ≤ c := ⟨fun h b' l => (mul_le_mul_left' l.le _).trans h, fun H => -- Porting note: `induction` tactics are required because of the parser bug. le_of_not_lt <| by induction a using inductionOn with | H α r => induction b using inductionOn with | H β s => exact mul_le_of_limit_aux h H⟩ #align ordinal.mul_le_of_limit Ordinal.mul_le_of_limit theorem mul_isNormal {a : Ordinal} (h : 0 < a) : IsNormal (a * ·) := -- Porting note(#12129): additional beta reduction needed ⟨fun b => by beta_reduce rw [mul_succ] simpa only [add_zero] using (add_lt_add_iff_left (a * b)).2 h, fun b l c => mul_le_of_limit l⟩ #align ordinal.mul_is_normal Ordinal.mul_isNormal theorem lt_mul_of_limit {a b c : Ordinal} (h : IsLimit c) : a < b * c ↔ ∃ c' < c, a < b * c' := by -- Porting note: `bex_def` is required. simpa only [not_forall₂, not_le, bex_def] using not_congr (@mul_le_of_limit b c a h) #align ordinal.lt_mul_of_limit Ordinal.lt_mul_of_limit theorem mul_lt_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b < a * c ↔ b < c := (mul_isNormal a0).lt_iff #align ordinal.mul_lt_mul_iff_left Ordinal.mul_lt_mul_iff_left theorem mul_le_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b ≤ a * c ↔ b ≤ c := (mul_isNormal a0).le_iff #align ordinal.mul_le_mul_iff_left Ordinal.mul_le_mul_iff_left theorem mul_lt_mul_of_pos_left {a b c : Ordinal} (h : a < b) (c0 : 0 < c) : c * a < c * b := (mul_lt_mul_iff_left c0).2 h #align ordinal.mul_lt_mul_of_pos_left Ordinal.mul_lt_mul_of_pos_left theorem mul_pos {a b : Ordinal} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := by simpa only [mul_zero] using mul_lt_mul_of_pos_left h₂ h₁ #align ordinal.mul_pos Ordinal.mul_pos theorem mul_ne_zero {a b : Ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := by simpa only [Ordinal.pos_iff_ne_zero] using mul_pos #align ordinal.mul_ne_zero Ordinal.mul_ne_zero theorem le_of_mul_le_mul_left {a b c : Ordinal} (h : c * a ≤ c * b) (h0 : 0 < c) : a ≤ b := le_imp_le_of_lt_imp_lt (fun h' => mul_lt_mul_of_pos_left h' h0) h #align ordinal.le_of_mul_le_mul_left Ordinal.le_of_mul_le_mul_left theorem mul_right_inj {a b c : Ordinal} (a0 : 0 < a) : a * b = a * c ↔ b = c := (mul_isNormal a0).inj #align ordinal.mul_right_inj Ordinal.mul_right_inj theorem mul_isLimit {a b : Ordinal} (a0 : 0 < a) : IsLimit b → IsLimit (a * b) := (mul_isNormal a0).isLimit #align ordinal.mul_is_limit Ordinal.mul_isLimit theorem mul_isLimit_left {a b : Ordinal} (l : IsLimit a) (b0 : 0 < b) : IsLimit (a * b) := by rcases zero_or_succ_or_limit b with (rfl | ⟨b, rfl⟩ | lb) · exact b0.false.elim · rw [mul_succ] exact add_isLimit _ l · exact mul_isLimit l.pos lb #align ordinal.mul_is_limit_left Ordinal.mul_isLimit_left theorem smul_eq_mul : ∀ (n : ℕ) (a : Ordinal), n • a = a * n | 0, a => by rw [zero_nsmul, Nat.cast_zero, mul_zero] | n + 1, a => by rw [succ_nsmul, Nat.cast_add, mul_add, Nat.cast_one, mul_one, smul_eq_mul n] #align ordinal.smul_eq_mul Ordinal.smul_eq_mul /-! ### Division on ordinals -/ /-- The set in the definition of division is nonempty. -/ theorem div_nonempty {a b : Ordinal} (h : b ≠ 0) : { o | a < b * succ o }.Nonempty := ⟨a, (succ_le_iff (a := a) (b := b * succ a)).1 <| by simpa only [succ_zero, one_mul] using mul_le_mul_right' (succ_le_of_lt (Ordinal.pos_iff_ne_zero.2 h)) (succ a)⟩ #align ordinal.div_nonempty Ordinal.div_nonempty /-- `a / b` is the unique ordinal `o` satisfying `a = b * o + o'` with `o' < b`. -/ instance div : Div Ordinal := ⟨fun a b => if _h : b = 0 then 0 else sInf { o | a < b * succ o }⟩ @[simp] theorem div_zero (a : Ordinal) : a / 0 = 0 := dif_pos rfl #align ordinal.div_zero Ordinal.div_zero theorem div_def (a) {b : Ordinal} (h : b ≠ 0) : a / b = sInf { o | a < b * succ o } := dif_neg h #align ordinal.div_def Ordinal.div_def theorem lt_mul_succ_div (a) {b : Ordinal} (h : b ≠ 0) : a < b * succ (a / b) := by rw [div_def a h]; exact csInf_mem (div_nonempty h) #align ordinal.lt_mul_succ_div Ordinal.lt_mul_succ_div theorem lt_mul_div_add (a) {b : Ordinal} (h : b ≠ 0) : a < b * (a / b) + b := by simpa only [mul_succ] using lt_mul_succ_div a h #align ordinal.lt_mul_div_add Ordinal.lt_mul_div_add theorem div_le {a b c : Ordinal} (b0 : b ≠ 0) : a / b ≤ c ↔ a < b * succ c := ⟨fun h => (lt_mul_succ_div a b0).trans_le (mul_le_mul_left' (succ_le_succ_iff.2 h) _), fun h => by rw [div_def a b0]; exact csInf_le' h⟩ #align ordinal.div_le Ordinal.div_le theorem lt_div {a b c : Ordinal} (h : c ≠ 0) : a < b / c ↔ c * succ a ≤ b := by rw [← not_le, div_le h, not_lt] #align ordinal.lt_div Ordinal.lt_div theorem div_pos {b c : Ordinal} (h : c ≠ 0) : 0 < b / c ↔ c ≤ b := by simp [lt_div h] #align ordinal.div_pos Ordinal.div_pos theorem le_div {a b c : Ordinal} (c0 : c ≠ 0) : a ≤ b / c ↔ c * a ≤ b := by induction a using limitRecOn with | H₁ => simp only [mul_zero, Ordinal.zero_le] | H₂ _ _ => rw [succ_le_iff, lt_div c0] | H₃ _ h₁ h₂ => revert h₁ h₂ simp (config := { contextual := true }) only [mul_le_of_limit, limit_le, iff_self_iff, forall_true_iff] #align ordinal.le_div Ordinal.le_div theorem div_lt {a b c : Ordinal} (b0 : b ≠ 0) : a / b < c ↔ a < b * c := lt_iff_lt_of_le_iff_le <| le_div b0 #align ordinal.div_lt Ordinal.div_lt theorem div_le_of_le_mul {a b c : Ordinal} (h : a ≤ b * c) : a / b ≤ c := if b0 : b = 0 then by simp only [b0, div_zero, Ordinal.zero_le] else (div_le b0).2 <| h.trans_lt <| mul_lt_mul_of_pos_left (lt_succ c) (Ordinal.pos_iff_ne_zero.2 b0) #align ordinal.div_le_of_le_mul Ordinal.div_le_of_le_mul theorem mul_lt_of_lt_div {a b c : Ordinal} : a < b / c → c * a < b := lt_imp_lt_of_le_imp_le div_le_of_le_mul #align ordinal.mul_lt_of_lt_div Ordinal.mul_lt_of_lt_div @[simp] theorem zero_div (a : Ordinal) : 0 / a = 0 := Ordinal.le_zero.1 <| div_le_of_le_mul <| Ordinal.zero_le _ #align ordinal.zero_div Ordinal.zero_div theorem mul_div_le (a b : Ordinal) : b * (a / b) ≤ a := if b0 : b = 0 then by simp only [b0, zero_mul, Ordinal.zero_le] else (le_div b0).1 le_rfl #align ordinal.mul_div_le Ordinal.mul_div_le theorem mul_add_div (a) {b : Ordinal} (b0 : b ≠ 0) (c) : (b * a + c) / b = a + c / b := by apply le_antisymm · apply (div_le b0).2 rw [mul_succ, mul_add, add_assoc, add_lt_add_iff_left] apply lt_mul_div_add _ b0 · rw [le_div b0, mul_add, add_le_add_iff_left] apply mul_div_le #align ordinal.mul_add_div Ordinal.mul_add_div theorem div_eq_zero_of_lt {a b : Ordinal} (h : a < b) : a / b = 0 := by rw [← Ordinal.le_zero, div_le <| Ordinal.pos_iff_ne_zero.1 <| (Ordinal.zero_le _).trans_lt h] simpa only [succ_zero, mul_one] using h #align ordinal.div_eq_zero_of_lt Ordinal.div_eq_zero_of_lt @[simp] theorem mul_div_cancel (a) {b : Ordinal} (b0 : b ≠ 0) : b * a / b = a := by simpa only [add_zero, zero_div] using mul_add_div a b0 0 #align ordinal.mul_div_cancel Ordinal.mul_div_cancel @[simp] theorem div_one (a : Ordinal) : a / 1 = a := by simpa only [one_mul] using mul_div_cancel a Ordinal.one_ne_zero #align ordinal.div_one Ordinal.div_one @[simp] theorem div_self {a : Ordinal} (h : a ≠ 0) : a / a = 1 := by simpa only [mul_one] using mul_div_cancel 1 h #align ordinal.div_self Ordinal.div_self theorem mul_sub (a b c : Ordinal) : a * (b - c) = a * b - a * c := if a0 : a = 0 then by simp only [a0, zero_mul, sub_self] else eq_of_forall_ge_iff fun d => by rw [sub_le, ← le_div a0, sub_le, ← le_div a0, mul_add_div _ a0] #align ordinal.mul_sub Ordinal.mul_sub theorem isLimit_add_iff {a b} : IsLimit (a + b) ↔ IsLimit b ∨ b = 0 ∧ IsLimit a := by constructor <;> intro h · by_cases h' : b = 0 · rw [h', add_zero] at h right exact ⟨h', h⟩ left rw [← add_sub_cancel a b] apply sub_isLimit h suffices a + 0 < a + b by simpa only [add_zero] using this rwa [add_lt_add_iff_left, Ordinal.pos_iff_ne_zero] rcases h with (h | ⟨rfl, h⟩) · exact add_isLimit a h · simpa only [add_zero] #align ordinal.is_limit_add_iff Ordinal.isLimit_add_iff theorem dvd_add_iff : ∀ {a b c : Ordinal}, a ∣ b → (a ∣ b + c ↔ a ∣ c) | a, _, c, ⟨b, rfl⟩ => ⟨fun ⟨d, e⟩ => ⟨d - b, by rw [mul_sub, ← e, add_sub_cancel]⟩, fun ⟨d, e⟩ => by rw [e, ← mul_add] apply dvd_mul_right⟩ #align ordinal.dvd_add_iff Ordinal.dvd_add_iff theorem div_mul_cancel : ∀ {a b : Ordinal}, a ≠ 0 → a ∣ b → a * (b / a) = b | a, _, a0, ⟨b, rfl⟩ => by rw [mul_div_cancel _ a0] #align ordinal.div_mul_cancel Ordinal.div_mul_cancel theorem le_of_dvd : ∀ {a b : Ordinal}, b ≠ 0 → a ∣ b → a ≤ b -- Porting note: `⟨b, rfl⟩ => by` → `⟨b, e⟩ => by subst e` | a, _, b0, ⟨b, e⟩ => by subst e -- Porting note: `Ne` is required. simpa only [mul_one] using mul_le_mul_left' (one_le_iff_ne_zero.2 fun h : b = 0 => by simp only [h, mul_zero, Ne, not_true_eq_false] at b0) a #align ordinal.le_of_dvd Ordinal.le_of_dvd theorem dvd_antisymm {a b : Ordinal} (h₁ : a ∣ b) (h₂ : b ∣ a) : a = b := if a0 : a = 0 then by subst a; exact (eq_zero_of_zero_dvd h₁).symm else if b0 : b = 0 then by subst b; exact eq_zero_of_zero_dvd h₂ else (le_of_dvd b0 h₁).antisymm (le_of_dvd a0 h₂) #align ordinal.dvd_antisymm Ordinal.dvd_antisymm instance isAntisymm : IsAntisymm Ordinal (· ∣ ·) := ⟨@dvd_antisymm⟩ /-- `a % b` is the unique ordinal `o'` satisfying `a = b * o + o'` with `o' < b`. -/ instance mod : Mod Ordinal := ⟨fun a b => a - b * (a / b)⟩ theorem mod_def (a b : Ordinal) : a % b = a - b * (a / b) := rfl #align ordinal.mod_def Ordinal.mod_def theorem mod_le (a b : Ordinal) : a % b ≤ a := sub_le_self a _ #align ordinal.mod_le Ordinal.mod_le @[simp] theorem mod_zero (a : Ordinal) : a % 0 = a := by simp only [mod_def, div_zero, zero_mul, sub_zero] #align ordinal.mod_zero Ordinal.mod_zero theorem mod_eq_of_lt {a b : Ordinal} (h : a < b) : a % b = a := by simp only [mod_def, div_eq_zero_of_lt h, mul_zero, sub_zero] #align ordinal.mod_eq_of_lt Ordinal.mod_eq_of_lt @[simp] theorem zero_mod (b : Ordinal) : 0 % b = 0 := by simp only [mod_def, zero_div, mul_zero, sub_self] #align ordinal.zero_mod Ordinal.zero_mod theorem div_add_mod (a b : Ordinal) : b * (a / b) + a % b = a := Ordinal.add_sub_cancel_of_le <| mul_div_le _ _ #align ordinal.div_add_mod Ordinal.div_add_mod theorem mod_lt (a) {b : Ordinal} (h : b ≠ 0) : a % b < b := (add_lt_add_iff_left (b * (a / b))).1 <| by rw [div_add_mod]; exact lt_mul_div_add a h #align ordinal.mod_lt Ordinal.mod_lt @[simp] theorem mod_self (a : Ordinal) : a % a = 0 := if a0 : a = 0 then by simp only [a0, zero_mod] else by simp only [mod_def, div_self a0, mul_one, sub_self] #align ordinal.mod_self Ordinal.mod_self @[simp] theorem mod_one (a : Ordinal) : a % 1 = 0 := by simp only [mod_def, div_one, one_mul, sub_self] #align ordinal.mod_one Ordinal.mod_one theorem dvd_of_mod_eq_zero {a b : Ordinal} (H : a % b = 0) : b ∣ a := ⟨a / b, by simpa [H] using (div_add_mod a b).symm⟩ #align ordinal.dvd_of_mod_eq_zero Ordinal.dvd_of_mod_eq_zero theorem mod_eq_zero_of_dvd {a b : Ordinal} (H : b ∣ a) : a % b = 0 := by rcases H with ⟨c, rfl⟩ rcases eq_or_ne b 0 with (rfl | hb) · simp · simp [mod_def, hb] #align ordinal.mod_eq_zero_of_dvd Ordinal.mod_eq_zero_of_dvd theorem dvd_iff_mod_eq_zero {a b : Ordinal} : b ∣ a ↔ a % b = 0 := ⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩ #align ordinal.dvd_iff_mod_eq_zero Ordinal.dvd_iff_mod_eq_zero @[simp] theorem mul_add_mod_self (x y z : Ordinal) : (x * y + z) % x = z % x := by rcases eq_or_ne x 0 with rfl | hx · simp · rwa [mod_def, mul_add_div, mul_add, ← sub_sub, add_sub_cancel, mod_def] #align ordinal.mul_add_mod_self Ordinal.mul_add_mod_self @[simp] theorem mul_mod (x y : Ordinal) : x * y % x = 0 := by simpa using mul_add_mod_self x y 0 #align ordinal.mul_mod Ordinal.mul_mod theorem mod_mod_of_dvd (a : Ordinal) {b c : Ordinal} (h : c ∣ b) : a % b % c = a % c := by nth_rw 2 [← div_add_mod a b] rcases h with ⟨d, rfl⟩ rw [mul_assoc, mul_add_mod_self] #align ordinal.mod_mod_of_dvd Ordinal.mod_mod_of_dvd @[simp] theorem mod_mod (a b : Ordinal) : a % b % b = a % b := mod_mod_of_dvd a dvd_rfl #align ordinal.mod_mod Ordinal.mod_mod /-! ### Families of ordinals There are two kinds of indexed families that naturally arise when dealing with ordinals: those indexed by some type in the appropriate universe, and those indexed by ordinals less than another. The following API allows one to convert from one kind of family to the other. In many cases, this makes it easy to prove claims about one kind of family via the corresponding claim on the other. -/ /-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a specified well-ordering. -/ def bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) : ∀ a < type r, α := fun a ha => f (enum r a ha) #align ordinal.bfamily_of_family' Ordinal.bfamilyOfFamily' /-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a well-ordering given by the axiom of choice. -/ def bfamilyOfFamily {ι : Type u} : (ι → α) → ∀ a < type (@WellOrderingRel ι), α := bfamilyOfFamily' WellOrderingRel #align ordinal.bfamily_of_family Ordinal.bfamilyOfFamily /-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a specified well-ordering. -/ def familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, α) : ι → α := fun i => f (typein r i) (by rw [← ho] exact typein_lt_type r i) #align ordinal.family_of_bfamily' Ordinal.familyOfBFamily' /-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a well-ordering given by the axiom of choice. -/ def familyOfBFamily (o : Ordinal) (f : ∀ a < o, α) : o.out.α → α := familyOfBFamily' (· < ·) (type_lt o) f #align ordinal.family_of_bfamily Ordinal.familyOfBFamily @[simp] theorem bfamilyOfFamily'_typein {ι} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) (i) : bfamilyOfFamily' r f (typein r i) (typein_lt_type r i) = f i := by simp only [bfamilyOfFamily', enum_typein] #align ordinal.bfamily_of_family'_typein Ordinal.bfamilyOfFamily'_typein @[simp] theorem bfamilyOfFamily_typein {ι} (f : ι → α) (i) : bfamilyOfFamily f (typein _ i) (typein_lt_type _ i) = f i := bfamilyOfFamily'_typein _ f i #align ordinal.bfamily_of_family_typein Ordinal.bfamilyOfFamily_typein @[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this theorem familyOfBFamily'_enum {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, α) (i hi) : familyOfBFamily' r ho f (enum r i (by rwa [ho])) = f i hi := by simp only [familyOfBFamily', typein_enum] #align ordinal.family_of_bfamily'_enum Ordinal.familyOfBFamily'_enum @[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this theorem familyOfBFamily_enum (o : Ordinal) (f : ∀ a < o, α) (i hi) : familyOfBFamily o f (enum (· < ·) i (by convert hi exact type_lt _)) = f i hi := familyOfBFamily'_enum _ (type_lt o) f _ _ #align ordinal.family_of_bfamily_enum Ordinal.familyOfBFamily_enum /-- The range of a family indexed by ordinals. -/ def brange (o : Ordinal) (f : ∀ a < o, α) : Set α := { a | ∃ i hi, f i hi = a } #align ordinal.brange Ordinal.brange theorem mem_brange {o : Ordinal} {f : ∀ a < o, α} {a} : a ∈ brange o f ↔ ∃ i hi, f i hi = a := Iff.rfl #align ordinal.mem_brange Ordinal.mem_brange theorem mem_brange_self {o} (f : ∀ a < o, α) (i hi) : f i hi ∈ brange o f := ⟨i, hi, rfl⟩ #align ordinal.mem_brange_self Ordinal.mem_brange_self @[simp] theorem range_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, α) : range (familyOfBFamily' r ho f) = brange o f := by refine Set.ext fun a => ⟨?_, ?_⟩ · rintro ⟨b, rfl⟩ apply mem_brange_self · rintro ⟨i, hi, rfl⟩ exact ⟨_, familyOfBFamily'_enum _ _ _ _ _⟩ #align ordinal.range_family_of_bfamily' Ordinal.range_familyOfBFamily' @[simp] theorem range_familyOfBFamily {o} (f : ∀ a < o, α) : range (familyOfBFamily o f) = brange o f := range_familyOfBFamily' _ _ f #align ordinal.range_family_of_bfamily Ordinal.range_familyOfBFamily @[simp] theorem brange_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) : brange _ (bfamilyOfFamily' r f) = range f := by refine Set.ext fun a => ⟨?_, ?_⟩ · rintro ⟨i, hi, rfl⟩ apply mem_range_self · rintro ⟨b, rfl⟩ exact ⟨_, _, bfamilyOfFamily'_typein _ _ _⟩ #align ordinal.brange_bfamily_of_family' Ordinal.brange_bfamilyOfFamily' @[simp] theorem brange_bfamilyOfFamily {ι : Type u} (f : ι → α) : brange _ (bfamilyOfFamily f) = range f := brange_bfamilyOfFamily' _ _ #align ordinal.brange_bfamily_of_family Ordinal.brange_bfamilyOfFamily @[simp] theorem brange_const {o : Ordinal} (ho : o ≠ 0) {c : α} : (brange o fun _ _ => c) = {c} := by rw [← range_familyOfBFamily] exact @Set.range_const _ o.out.α (out_nonempty_iff_ne_zero.2 ho) c #align ordinal.brange_const Ordinal.brange_const theorem comp_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) (g : α → β) : (fun i hi => g (bfamilyOfFamily' r f i hi)) = bfamilyOfFamily' r (g ∘ f) := rfl #align ordinal.comp_bfamily_of_family' Ordinal.comp_bfamilyOfFamily' theorem comp_bfamilyOfFamily {ι : Type u} (f : ι → α) (g : α → β) : (fun i hi => g (bfamilyOfFamily f i hi)) = bfamilyOfFamily (g ∘ f) := rfl #align ordinal.comp_bfamily_of_family Ordinal.comp_bfamilyOfFamily theorem comp_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, α) (g : α → β) : g ∘ familyOfBFamily' r ho f = familyOfBFamily' r ho fun i hi => g (f i hi) := rfl #align ordinal.comp_family_of_bfamily' Ordinal.comp_familyOfBFamily' theorem comp_familyOfBFamily {o} (f : ∀ a < o, α) (g : α → β) : g ∘ familyOfBFamily o f = familyOfBFamily o fun i hi => g (f i hi) := rfl #align ordinal.comp_family_of_bfamily Ordinal.comp_familyOfBFamily /-! ### Supremum of a family of ordinals -/ -- Porting note: Universes should be specified in `sup`s. /-- The supremum of a family of ordinals -/ def sup {ι : Type u} (f : ι → Ordinal.{max u v}) : Ordinal.{max u v} := iSup f #align ordinal.sup Ordinal.sup @[simp] theorem sSup_eq_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : sSup (Set.range f) = sup.{_, v} f := rfl #align ordinal.Sup_eq_sup Ordinal.sSup_eq_sup /-- The range of an indexed ordinal function, whose outputs live in a higher universe than the inputs, is always bounded above. See `Ordinal.lsub` for an explicit bound. -/ theorem bddAbove_range {ι : Type u} (f : ι → Ordinal.{max u v}) : BddAbove (Set.range f) := ⟨(iSup (succ ∘ card ∘ f)).ord, by rintro a ⟨i, rfl⟩ exact le_of_lt (Cardinal.lt_ord.2 ((lt_succ _).trans_le (le_ciSup (Cardinal.bddAbove_range.{_, v} _) _)))⟩ #align ordinal.bdd_above_range Ordinal.bddAbove_range theorem le_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : ∀ i, f i ≤ sup.{_, v} f := fun i => le_csSup (bddAbove_range.{_, v} f) (mem_range_self i) #align ordinal.le_sup Ordinal.le_sup theorem sup_le_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : sup.{_, v} f ≤ a ↔ ∀ i, f i ≤ a := (csSup_le_iff' (bddAbove_range.{_, v} f)).trans (by simp) #align ordinal.sup_le_iff Ordinal.sup_le_iff theorem sup_le {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : (∀ i, f i ≤ a) → sup.{_, v} f ≤ a := sup_le_iff.2 #align ordinal.sup_le Ordinal.sup_le theorem lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : a < sup.{_, v} f ↔ ∃ i, a < f i := by simpa only [not_forall, not_le] using not_congr (@sup_le_iff.{_, v} _ f a) #align ordinal.lt_sup Ordinal.lt_sup theorem ne_sup_iff_lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} : (∀ i, f i ≠ sup.{_, v} f) ↔ ∀ i, f i < sup.{_, v} f := ⟨fun hf _ => lt_of_le_of_ne (le_sup _ _) (hf _), fun hf _ => ne_of_lt (hf _)⟩ #align ordinal.ne_sup_iff_lt_sup Ordinal.ne_sup_iff_lt_sup theorem sup_not_succ_of_ne_sup {ι : Type u} {f : ι → Ordinal.{max u v}} (hf : ∀ i, f i ≠ sup.{_, v} f) {a} (hao : a < sup.{_, v} f) : succ a < sup.{_, v} f := by by_contra! hoa exact hao.not_le (sup_le fun i => le_of_lt_succ <| (lt_of_le_of_ne (le_sup _ _) (hf i)).trans_le hoa) #align ordinal.sup_not_succ_of_ne_sup Ordinal.sup_not_succ_of_ne_sup @[simp] theorem sup_eq_zero_iff {ι : Type u} {f : ι → Ordinal.{max u v}} : sup.{_, v} f = 0 ↔ ∀ i, f i = 0 := by refine ⟨fun h i => ?_, fun h => le_antisymm (sup_le fun i => Ordinal.le_zero.2 (h i)) (Ordinal.zero_le _)⟩ rw [← Ordinal.le_zero, ← h] exact le_sup f i #align ordinal.sup_eq_zero_iff Ordinal.sup_eq_zero_iff theorem IsNormal.sup {f : Ordinal.{max u v} → Ordinal.{max u w}} (H : IsNormal f) {ι : Type u} (g : ι → Ordinal.{max u v}) [Nonempty ι] : f (sup.{_, v} g) = sup.{_, w} (f ∘ g) := eq_of_forall_ge_iff fun a => by rw [sup_le_iff]; simp only [comp]; rw [H.le_set' Set.univ Set.univ_nonempty g] <;> simp [sup_le_iff] #align ordinal.is_normal.sup Ordinal.IsNormal.sup @[simp] theorem sup_empty {ι} [IsEmpty ι] (f : ι → Ordinal) : sup f = 0 := ciSup_of_empty f #align ordinal.sup_empty Ordinal.sup_empty @[simp] theorem sup_const {ι} [_hι : Nonempty ι] (o : Ordinal) : (sup fun _ : ι => o) = o := ciSup_const #align ordinal.sup_const Ordinal.sup_const @[simp] theorem sup_unique {ι} [Unique ι] (f : ι → Ordinal) : sup f = f default := ciSup_unique #align ordinal.sup_unique Ordinal.sup_unique theorem sup_le_of_range_subset {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal} (h : Set.range f ⊆ Set.range g) : sup.{u, max v w} f ≤ sup.{v, max u w} g := sup_le fun i => match h (mem_range_self i) with | ⟨_j, hj⟩ => hj ▸ le_sup _ _ #align ordinal.sup_le_of_range_subset Ordinal.sup_le_of_range_subset theorem sup_eq_of_range_eq {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal} (h : Set.range f = Set.range g) : sup.{u, max v w} f = sup.{v, max u w} g := (sup_le_of_range_subset.{u, v, w} h.le).antisymm (sup_le_of_range_subset.{v, u, w} h.ge) #align ordinal.sup_eq_of_range_eq Ordinal.sup_eq_of_range_eq @[simp] theorem sup_sum {α : Type u} {β : Type v} (f : Sum α β → Ordinal) : sup.{max u v, w} f = max (sup.{u, max v w} fun a => f (Sum.inl a)) (sup.{v, max u w} fun b => f (Sum.inr b)) := by apply (sup_le_iff.2 _).antisymm (max_le_iff.2 ⟨_, _⟩) · rintro (i | i) · exact le_max_of_le_left (le_sup _ i) · exact le_max_of_le_right (le_sup _ i) all_goals apply sup_le_of_range_subset.{_, max u v, w} rintro i ⟨a, rfl⟩ apply mem_range_self #align ordinal.sup_sum Ordinal.sup_sum theorem unbounded_range_of_sup_ge {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β → α) (h : type r ≤ sup.{u, u} (typein r ∘ f)) : Unbounded r (range f) := (not_bounded_iff _).1 fun ⟨x, hx⟩ => not_lt_of_le h <| lt_of_le_of_lt (sup_le fun y => le_of_lt <| (typein_lt_typein r).2 <| hx _ <| mem_range_self y) (typein_lt_type r x) #align ordinal.unbounded_range_of_sup_ge Ordinal.unbounded_range_of_sup_ge theorem le_sup_shrink_equiv {s : Set Ordinal.{u}} (hs : Small.{u} s) (a) (ha : a ∈ s) : a ≤ sup.{u, u} fun x => ((@equivShrink s hs).symm x).val := by convert le_sup.{u, u} (fun x => ((@equivShrink s hs).symm x).val) ((@equivShrink s hs) ⟨a, ha⟩) rw [symm_apply_apply] #align ordinal.le_sup_shrink_equiv Ordinal.le_sup_shrink_equiv instance small_Iio (o : Ordinal.{u}) : Small.{u} (Set.Iio o) := let f : o.out.α → Set.Iio o := fun x => ⟨typein ((· < ·) : o.out.α → o.out.α → Prop) x, typein_lt_self x⟩ let hf : Surjective f := fun b => ⟨enum (· < ·) b.val (by rw [type_lt] exact b.prop), Subtype.ext (typein_enum _ _)⟩ small_of_surjective hf #align ordinal.small_Iio Ordinal.small_Iio instance small_Iic (o : Ordinal.{u}) : Small.{u} (Set.Iic o) := by rw [← Iio_succ] infer_instance #align ordinal.small_Iic Ordinal.small_Iic theorem bddAbove_iff_small {s : Set Ordinal.{u}} : BddAbove s ↔ Small.{u} s := ⟨fun ⟨a, h⟩ => small_subset <| show s ⊆ Iic a from fun _x hx => h hx, fun h => ⟨sup.{u, u} fun x => ((@equivShrink s h).symm x).val, le_sup_shrink_equiv h⟩⟩ #align ordinal.bdd_above_iff_small Ordinal.bddAbove_iff_small theorem bddAbove_of_small (s : Set Ordinal.{u}) [h : Small.{u} s] : BddAbove s := bddAbove_iff_small.2 h #align ordinal.bdd_above_of_small Ordinal.bddAbove_of_small theorem sup_eq_sSup {s : Set Ordinal.{u}} (hs : Small.{u} s) : (sup.{u, u} fun x => (@equivShrink s hs).symm x) = sSup s := let hs' := bddAbove_iff_small.2 hs ((csSup_le_iff' hs').2 (le_sup_shrink_equiv hs)).antisymm' (sup_le fun _x => le_csSup hs' (Subtype.mem _)) #align ordinal.sup_eq_Sup Ordinal.sup_eq_sSup theorem sSup_ord {s : Set Cardinal.{u}} (hs : BddAbove s) : (sSup s).ord = sSup (ord '' s) := eq_of_forall_ge_iff fun a => by rw [csSup_le_iff' (bddAbove_iff_small.2 (@small_image _ _ _ s (Cardinal.bddAbove_iff_small.1 hs))), ord_le, csSup_le_iff' hs] simp [ord_le] #align ordinal.Sup_ord Ordinal.sSup_ord theorem iSup_ord {ι} {f : ι → Cardinal} (hf : BddAbove (range f)) : (iSup f).ord = ⨆ i, (f i).ord := by unfold iSup convert sSup_ord hf -- Porting note: `change` is required. conv_lhs => change range (ord ∘ f) rw [range_comp] #align ordinal.supr_ord Ordinal.iSup_ord private theorem sup_le_sup {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r] [IsWellOrder ι' r'] {o} (ho : type r = o) (ho' : type r' = o) (f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily' r ho f) ≤ sup.{_, v} (familyOfBFamily' r' ho' f) := sup_le fun i => by cases' typein_surj r' (by rw [ho', ← ho] exact typein_lt_type r i) with j hj simp_rw [familyOfBFamily', ← hj] apply le_sup theorem sup_eq_sup {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r] [IsWellOrder ι' r'] {o : Ordinal.{u}} (ho : type r = o) (ho' : type r' = o) (f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily' r ho f) = sup.{_, v} (familyOfBFamily' r' ho' f) := sup_eq_of_range_eq.{u, u, v} (by simp) #align ordinal.sup_eq_sup Ordinal.sup_eq_sup /-- The supremum of a family of ordinals indexed by the set of ordinals less than some `o : Ordinal.{u}`. This is a special case of `sup` over the family provided by `familyOfBFamily`. -/ def bsup (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : Ordinal.{max u v} := sup.{_, v} (familyOfBFamily o f) #align ordinal.bsup Ordinal.bsup @[simp] theorem sup_eq_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily o f) = bsup.{_, v} o f := rfl #align ordinal.sup_eq_bsup Ordinal.sup_eq_bsup @[simp] theorem sup_eq_bsup' {o : Ordinal.{u}} {ι} (r : ι → ι → Prop) [IsWellOrder ι r] (ho : type r = o) (f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily' r ho f) = bsup.{_, v} o f := sup_eq_sup r _ ho _ f #align ordinal.sup_eq_bsup' Ordinal.sup_eq_bsup' @[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this theorem sSup_eq_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : sSup (brange o f) = bsup.{_, v} o f := by congr rw [range_familyOfBFamily] #align ordinal.Sup_eq_bsup Ordinal.sSup_eq_bsup @[simp] theorem bsup_eq_sup' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → Ordinal.{max u v}) : bsup.{_, v} _ (bfamilyOfFamily' r f) = sup.{_, v} f := by simp (config := { unfoldPartialApp := true }) only [← sup_eq_bsup' r, enum_typein, familyOfBFamily', bfamilyOfFamily'] #align ordinal.bsup_eq_sup' Ordinal.bsup_eq_sup' theorem bsup_eq_bsup {ι : Type u} (r r' : ι → ι → Prop) [IsWellOrder ι r] [IsWellOrder ι r'] (f : ι → Ordinal.{max u v}) : bsup.{_, v} _ (bfamilyOfFamily' r f) = bsup.{_, v} _ (bfamilyOfFamily' r' f) := by rw [bsup_eq_sup', bsup_eq_sup'] #align ordinal.bsup_eq_bsup Ordinal.bsup_eq_bsup @[simp] theorem bsup_eq_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : bsup.{_, v} _ (bfamilyOfFamily f) = sup.{_, v} f := bsup_eq_sup' _ f #align ordinal.bsup_eq_sup Ordinal.bsup_eq_sup @[congr] theorem bsup_congr {o₁ o₂ : Ordinal.{u}} (f : ∀ a < o₁, Ordinal.{max u v}) (ho : o₁ = o₂) : bsup.{_, v} o₁ f = bsup.{_, v} o₂ fun a h => f a (h.trans_eq ho.symm) := by subst ho -- Porting note: `rfl` is required. rfl #align ordinal.bsup_congr Ordinal.bsup_congr theorem bsup_le_iff {o f a} : bsup.{u, v} o f ≤ a ↔ ∀ i h, f i h ≤ a := sup_le_iff.trans ⟨fun h i hi => by rw [← familyOfBFamily_enum o f] exact h _, fun h i => h _ _⟩ #align ordinal.bsup_le_iff Ordinal.bsup_le_iff theorem bsup_le {o : Ordinal} {f : ∀ b < o, Ordinal} {a} : (∀ i h, f i h ≤ a) → bsup.{u, v} o f ≤ a := bsup_le_iff.2 #align ordinal.bsup_le Ordinal.bsup_le theorem le_bsup {o} (f : ∀ a < o, Ordinal) (i h) : f i h ≤ bsup o f := bsup_le_iff.1 le_rfl _ _ #align ordinal.le_bsup Ordinal.le_bsup theorem lt_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) {a} : a < bsup.{_, v} o f ↔ ∃ i hi, a < f i hi := by simpa only [not_forall, not_le] using not_congr (@bsup_le_iff.{_, v} _ f a) #align ordinal.lt_bsup Ordinal.lt_bsup theorem IsNormal.bsup {f : Ordinal.{max u v} → Ordinal.{max u w}} (H : IsNormal f) {o : Ordinal.{u}} : ∀ (g : ∀ a < o, Ordinal), o ≠ 0 → f (bsup.{_, v} o g) = bsup.{_, w} o fun a h => f (g a h) := inductionOn o fun α r _ g h => by haveI := type_ne_zero_iff_nonempty.1 h rw [← sup_eq_bsup' r, IsNormal.sup.{_, v, w} H, ← sup_eq_bsup' r] <;> rfl #align ordinal.is_normal.bsup Ordinal.IsNormal.bsup theorem lt_bsup_of_ne_bsup {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} : (∀ i h, f i h ≠ bsup.{_, v} o f) ↔ ∀ i h, f i h < bsup.{_, v} o f := ⟨fun hf _ _ => lt_of_le_of_ne (le_bsup _ _ _) (hf _ _), fun hf _ _ => ne_of_lt (hf _ _)⟩ #align ordinal.lt_bsup_of_ne_bsup Ordinal.lt_bsup_of_ne_bsup theorem bsup_not_succ_of_ne_bsup {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} (hf : ∀ {i : Ordinal} (h : i < o), f i h ≠ bsup.{_, v} o f) (a) : a < bsup.{_, v} o f → succ a < bsup.{_, v} o f := by rw [← sup_eq_bsup] at * exact sup_not_succ_of_ne_sup fun i => hf _ #align ordinal.bsup_not_succ_of_ne_bsup Ordinal.bsup_not_succ_of_ne_bsup @[simp] theorem bsup_eq_zero_iff {o} {f : ∀ a < o, Ordinal} : bsup o f = 0 ↔ ∀ i hi, f i hi = 0 := by refine ⟨fun h i hi => ?_, fun h => le_antisymm (bsup_le fun i hi => Ordinal.le_zero.2 (h i hi)) (Ordinal.zero_le _)⟩ rw [← Ordinal.le_zero, ← h] exact le_bsup f i hi #align ordinal.bsup_eq_zero_iff Ordinal.bsup_eq_zero_iff theorem lt_bsup_of_limit {o : Ordinal} {f : ∀ a < o, Ordinal} (hf : ∀ {a a'} (ha : a < o) (ha' : a' < o), a < a' → f a ha < f a' ha') (ho : ∀ a < o, succ a < o) (i h) : f i h < bsup o f := (hf _ _ <| lt_succ i).trans_le (le_bsup f (succ i) <| ho _ h) #align ordinal.lt_bsup_of_limit Ordinal.lt_bsup_of_limit theorem bsup_succ_of_mono {o : Ordinal} {f : ∀ a < succ o, Ordinal} (hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : bsup _ f = f o (lt_succ o) := le_antisymm (bsup_le fun _i hi => hf _ _ <| le_of_lt_succ hi) (le_bsup _ _ _) #align ordinal.bsup_succ_of_mono Ordinal.bsup_succ_of_mono @[simp] theorem bsup_zero (f : ∀ a < (0 : Ordinal), Ordinal) : bsup 0 f = 0 := bsup_eq_zero_iff.2 fun i hi => (Ordinal.not_lt_zero i hi).elim #align ordinal.bsup_zero Ordinal.bsup_zero theorem bsup_const {o : Ordinal.{u}} (ho : o ≠ 0) (a : Ordinal.{max u v}) : (bsup.{_, v} o fun _ _ => a) = a := le_antisymm (bsup_le fun _ _ => le_rfl) (le_bsup _ 0 (Ordinal.pos_iff_ne_zero.2 ho)) #align ordinal.bsup_const Ordinal.bsup_const @[simp] theorem bsup_one (f : ∀ a < (1 : Ordinal), Ordinal) : bsup 1 f = f 0 zero_lt_one := by simp_rw [← sup_eq_bsup, sup_unique, familyOfBFamily, familyOfBFamily', typein_one_out] #align ordinal.bsup_one Ordinal.bsup_one theorem bsup_le_of_brange_subset {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal} (h : brange o f ⊆ brange o' g) : bsup.{u, max v w} o f ≤ bsup.{v, max u w} o' g := bsup_le fun i hi => by obtain ⟨j, hj, hj'⟩ := h ⟨i, hi, rfl⟩ rw [← hj'] apply le_bsup #align ordinal.bsup_le_of_brange_subset Ordinal.bsup_le_of_brange_subset theorem bsup_eq_of_brange_eq {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal} (h : brange o f = brange o' g) : bsup.{u, max v w} o f = bsup.{v, max u w} o' g := (bsup_le_of_brange_subset.{u, v, w} h.le).antisymm (bsup_le_of_brange_subset.{v, u, w} h.ge) #align ordinal.bsup_eq_of_brange_eq Ordinal.bsup_eq_of_brange_eq /-- The least strict upper bound of a family of ordinals. -/ def lsub {ι} (f : ι → Ordinal) : Ordinal := sup (succ ∘ f) #align ordinal.lsub Ordinal.lsub @[simp] theorem sup_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} (succ ∘ f) = lsub.{_, v} f := rfl #align ordinal.sup_eq_lsub Ordinal.sup_eq_lsub theorem lsub_le_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : lsub.{_, v} f ≤ a ↔ ∀ i, f i < a := by convert sup_le_iff.{_, v} (f := succ ∘ f) (a := a) using 2 -- Porting note: `comp_apply` is required. simp only [comp_apply, succ_le_iff] #align ordinal.lsub_le_iff Ordinal.lsub_le_iff theorem lsub_le {ι} {f : ι → Ordinal} {a} : (∀ i, f i < a) → lsub f ≤ a := lsub_le_iff.2 #align ordinal.lsub_le Ordinal.lsub_le theorem lt_lsub {ι} (f : ι → Ordinal) (i) : f i < lsub f := succ_le_iff.1 (le_sup _ i) #align ordinal.lt_lsub Ordinal.lt_lsub theorem lt_lsub_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : a < lsub.{_, v} f ↔ ∃ i, a ≤ f i := by simpa only [not_forall, not_lt, not_le] using not_congr (@lsub_le_iff.{_, v} _ f a) #align ordinal.lt_lsub_iff Ordinal.lt_lsub_iff theorem sup_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f ≤ lsub.{_, v} f := sup_le fun i => (lt_lsub f i).le #align ordinal.sup_le_lsub Ordinal.sup_le_lsub theorem lsub_le_sup_succ {ι : Type u} (f : ι → Ordinal.{max u v}) : lsub.{_, v} f ≤ succ (sup.{_, v} f) := lsub_le fun i => lt_succ_iff.2 (le_sup f i) #align ordinal.lsub_le_sup_succ Ordinal.lsub_le_sup_succ theorem sup_eq_lsub_or_sup_succ_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f = lsub.{_, v} f ∨ succ (sup.{_, v} f) = lsub.{_, v} f := by cases' eq_or_lt_of_le (sup_le_lsub.{_, v} f) with h h · exact Or.inl h · exact Or.inr ((succ_le_of_lt h).antisymm (lsub_le_sup_succ f)) #align ordinal.sup_eq_lsub_or_sup_succ_eq_lsub Ordinal.sup_eq_lsub_or_sup_succ_eq_lsub theorem sup_succ_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : succ (sup.{_, v} f) ≤ lsub.{_, v} f ↔ ∃ i, f i = sup.{_, v} f := by refine ⟨fun h => ?_, ?_⟩ · by_contra! hf exact (succ_le_iff.1 h).ne ((sup_le_lsub f).antisymm (lsub_le (ne_sup_iff_lt_sup.1 hf))) rintro ⟨_, hf⟩ rw [succ_le_iff, ← hf] exact lt_lsub _ _ #align ordinal.sup_succ_le_lsub Ordinal.sup_succ_le_lsub theorem sup_succ_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : succ (sup.{_, v} f) = lsub.{_, v} f ↔ ∃ i, f i = sup.{_, v} f := (lsub_le_sup_succ f).le_iff_eq.symm.trans (sup_succ_le_lsub f) #align ordinal.sup_succ_eq_lsub Ordinal.sup_succ_eq_lsub theorem sup_eq_lsub_iff_succ {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f = lsub.{_, v} f ↔ ∀ a < lsub.{_, v} f, succ a < lsub.{_, v} f := by refine ⟨fun h => ?_, fun hf => le_antisymm (sup_le_lsub f) (lsub_le fun i => ?_)⟩ · rw [← h] exact fun a => sup_not_succ_of_ne_sup fun i => (lsub_le_iff.1 (le_of_eq h.symm) i).ne by_contra! hle have heq := (sup_succ_eq_lsub f).2 ⟨i, le_antisymm (le_sup _ _) hle⟩ have := hf _ (by rw [← heq] exact lt_succ (sup f)) rw [heq] at this exact this.false #align ordinal.sup_eq_lsub_iff_succ Ordinal.sup_eq_lsub_iff_succ theorem sup_eq_lsub_iff_lt_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f = lsub.{_, v} f ↔ ∀ i, f i < sup.{_, v} f := ⟨fun h i => by rw [h] apply lt_lsub, fun h => le_antisymm (sup_le_lsub f) (lsub_le h)⟩ #align ordinal.sup_eq_lsub_iff_lt_sup Ordinal.sup_eq_lsub_iff_lt_sup @[simp] theorem lsub_empty {ι} [h : IsEmpty ι] (f : ι → Ordinal) : lsub f = 0 := by rw [← Ordinal.le_zero, lsub_le_iff] exact h.elim #align ordinal.lsub_empty Ordinal.lsub_empty theorem lsub_pos {ι : Type u} [h : Nonempty ι] (f : ι → Ordinal.{max u v}) : 0 < lsub.{_, v} f := h.elim fun i => (Ordinal.zero_le _).trans_lt (lt_lsub f i) #align ordinal.lsub_pos Ordinal.lsub_pos @[simp] theorem lsub_eq_zero_iff {ι : Type u} (f : ι → Ordinal.{max u v}) : lsub.{_, v} f = 0 ↔ IsEmpty ι := by refine ⟨fun h => ⟨fun i => ?_⟩, fun h => @lsub_empty _ h _⟩ have := @lsub_pos.{_, v} _ ⟨i⟩ f rw [h] at this exact this.false #align ordinal.lsub_eq_zero_iff Ordinal.lsub_eq_zero_iff @[simp] theorem lsub_const {ι} [Nonempty ι] (o : Ordinal) : (lsub fun _ : ι => o) = succ o := sup_const (succ o) #align ordinal.lsub_const Ordinal.lsub_const @[simp] theorem lsub_unique {ι} [Unique ι] (f : ι → Ordinal) : lsub f = succ (f default) := sup_unique _ #align ordinal.lsub_unique Ordinal.lsub_unique theorem lsub_le_of_range_subset {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal} (h : Set.range f ⊆ Set.range g) : lsub.{u, max v w} f ≤ lsub.{v, max u w} g := sup_le_of_range_subset.{u, v, w} (by convert Set.image_subset succ h <;> apply Set.range_comp) #align ordinal.lsub_le_of_range_subset Ordinal.lsub_le_of_range_subset theorem lsub_eq_of_range_eq {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal} (h : Set.range f = Set.range g) : lsub.{u, max v w} f = lsub.{v, max u w} g := (lsub_le_of_range_subset.{u, v, w} h.le).antisymm (lsub_le_of_range_subset.{v, u, w} h.ge) #align ordinal.lsub_eq_of_range_eq Ordinal.lsub_eq_of_range_eq @[simp] theorem lsub_sum {α : Type u} {β : Type v} (f : Sum α β → Ordinal) : lsub.{max u v, w} f = max (lsub.{u, max v w} fun a => f (Sum.inl a)) (lsub.{v, max u w} fun b => f (Sum.inr b)) := sup_sum _ #align ordinal.lsub_sum Ordinal.lsub_sum theorem lsub_not_mem_range {ι : Type u} (f : ι → Ordinal.{max u v}) : lsub.{_, v} f ∉ Set.range f := fun ⟨i, h⟩ => h.not_lt (lt_lsub f i) #align ordinal.lsub_not_mem_range Ordinal.lsub_not_mem_range theorem nonempty_compl_range {ι : Type u} (f : ι → Ordinal.{max u v}) : (Set.range f)ᶜ.Nonempty := ⟨_, lsub_not_mem_range.{_, v} f⟩ #align ordinal.nonempty_compl_range Ordinal.nonempty_compl_range @[simp] theorem lsub_typein (o : Ordinal) : lsub.{u, u} (typein ((· < ·) : o.out.α → o.out.α → Prop)) = o := (lsub_le.{u, u} typein_lt_self).antisymm (by by_contra! h -- Porting note: `nth_rw` → `conv_rhs` & `rw` conv_rhs at h => rw [← type_lt o] simpa [typein_enum] using lt_lsub.{u, u} (typein (· < ·)) (enum (· < ·) _ h)) #align ordinal.lsub_typein Ordinal.lsub_typein theorem sup_typein_limit {o : Ordinal} (ho : ∀ a, a < o → succ a < o) : sup.{u, u} (typein ((· < ·) : o.out.α → o.out.α → Prop)) = o := by -- Porting note: `rwa` → `rw` & `assumption` rw [(sup_eq_lsub_iff_succ.{u, u} (typein (· < ·))).2] <;> rw [lsub_typein o]; assumption #align ordinal.sup_typein_limit Ordinal.sup_typein_limit @[simp] theorem sup_typein_succ {o : Ordinal} : sup.{u, u} (typein ((· < ·) : (succ o).out.α → (succ o).out.α → Prop)) = o := by cases' sup_eq_lsub_or_sup_succ_eq_lsub.{u, u} (typein ((· < ·) : (succ o).out.α → (succ o).out.α → Prop)) with h h · rw [sup_eq_lsub_iff_succ] at h simp only [lsub_typein] at h exact (h o (lt_succ o)).false.elim rw [← succ_eq_succ_iff, h] apply lsub_typein #align ordinal.sup_typein_succ Ordinal.sup_typein_succ /-- The least strict upper bound of a family of ordinals indexed by the set of ordinals less than some `o : Ordinal.{u}`. This is to `lsub` as `bsup` is to `sup`. -/ def blsub (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : Ordinal.{max u v} := bsup.{_, v} o fun a ha => succ (f a ha) #align ordinal.blsub Ordinal.blsub @[simp] theorem bsup_eq_blsub (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : (bsup.{_, v} o fun a ha => succ (f a ha)) = blsub.{_, v} o f := rfl #align ordinal.bsup_eq_blsub Ordinal.bsup_eq_blsub theorem lsub_eq_blsub' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, Ordinal.{max u v}) : lsub.{_, v} (familyOfBFamily' r ho f) = blsub.{_, v} o f := sup_eq_bsup'.{_, v} r ho fun a ha => succ (f a ha) #align ordinal.lsub_eq_blsub' Ordinal.lsub_eq_blsub' theorem lsub_eq_lsub {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r] [IsWellOrder ι' r'] {o} (ho : type r = o) (ho' : type r' = o) (f : ∀ a < o, Ordinal.{max u v}) : lsub.{_, v} (familyOfBFamily' r ho f) = lsub.{_, v} (familyOfBFamily' r' ho' f) := by rw [lsub_eq_blsub', lsub_eq_blsub'] #align ordinal.lsub_eq_lsub Ordinal.lsub_eq_lsub @[simp] theorem lsub_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : lsub.{_, v} (familyOfBFamily o f) = blsub.{_, v} o f := lsub_eq_blsub' _ _ _ #align ordinal.lsub_eq_blsub Ordinal.lsub_eq_blsub @[simp] theorem blsub_eq_lsub' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → Ordinal.{max u v}) : blsub.{_, v} _ (bfamilyOfFamily' r f) = lsub.{_, v} f := bsup_eq_sup'.{_, v} r (succ ∘ f) #align ordinal.blsub_eq_lsub' Ordinal.blsub_eq_lsub' theorem blsub_eq_blsub {ι : Type u} (r r' : ι → ι → Prop) [IsWellOrder ι r] [IsWellOrder ι r'] (f : ι → Ordinal.{max u v}) : blsub.{_, v} _ (bfamilyOfFamily' r f) = blsub.{_, v} _ (bfamilyOfFamily' r' f) := by rw [blsub_eq_lsub', blsub_eq_lsub'] #align ordinal.blsub_eq_blsub Ordinal.blsub_eq_blsub @[simp] theorem blsub_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : blsub.{_, v} _ (bfamilyOfFamily f) = lsub.{_, v} f := blsub_eq_lsub' _ _ #align ordinal.blsub_eq_lsub Ordinal.blsub_eq_lsub @[congr] theorem blsub_congr {o₁ o₂ : Ordinal.{u}} (f : ∀ a < o₁, Ordinal.{max u v}) (ho : o₁ = o₂) : blsub.{_, v} o₁ f = blsub.{_, v} o₂ fun a h => f a (h.trans_eq ho.symm) := by subst ho -- Porting note: `rfl` is required. rfl #align ordinal.blsub_congr Ordinal.blsub_congr theorem blsub_le_iff {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} {a} : blsub.{_, v} o f ≤ a ↔ ∀ i h, f i h < a := by convert bsup_le_iff.{_, v} (f := fun a ha => succ (f a ha)) (a := a) using 2 simp_rw [succ_le_iff] #align ordinal.blsub_le_iff Ordinal.blsub_le_iff theorem blsub_le {o : Ordinal} {f : ∀ b < o, Ordinal} {a} : (∀ i h, f i h < a) → blsub o f ≤ a := blsub_le_iff.2 #align ordinal.blsub_le Ordinal.blsub_le theorem lt_blsub {o} (f : ∀ a < o, Ordinal) (i h) : f i h < blsub o f := blsub_le_iff.1 le_rfl _ _ #align ordinal.lt_blsub Ordinal.lt_blsub theorem lt_blsub_iff {o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{max u v}} {a} : a < blsub.{_, v} o f ↔ ∃ i hi, a ≤ f i hi := by simpa only [not_forall, not_lt, not_le] using not_congr (@blsub_le_iff.{_, v} _ f a) #align ordinal.lt_blsub_iff Ordinal.lt_blsub_iff theorem bsup_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : bsup.{_, v} o f ≤ blsub.{_, v} o f := bsup_le fun i h => (lt_blsub f i h).le #align ordinal.bsup_le_blsub Ordinal.bsup_le_blsub theorem blsub_le_bsup_succ {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : blsub.{_, v} o f ≤ succ (bsup.{_, v} o f) := blsub_le fun i h => lt_succ_iff.2 (le_bsup f i h) #align ordinal.blsub_le_bsup_succ Ordinal.blsub_le_bsup_succ theorem bsup_eq_blsub_or_succ_bsup_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : bsup.{_, v} o f = blsub.{_, v} o f ∨ succ (bsup.{_, v} o f) = blsub.{_, v} o f := by rw [← sup_eq_bsup, ← lsub_eq_blsub] exact sup_eq_lsub_or_sup_succ_eq_lsub _ #align ordinal.bsup_eq_blsub_or_succ_bsup_eq_blsub Ordinal.bsup_eq_blsub_or_succ_bsup_eq_blsub theorem bsup_succ_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : succ (bsup.{_, v} o f) ≤ blsub.{_, v} o f ↔ ∃ i hi, f i hi = bsup.{_, v} o f := by refine ⟨fun h => ?_, ?_⟩ · by_contra! hf exact ne_of_lt (succ_le_iff.1 h) (le_antisymm (bsup_le_blsub f) (blsub_le (lt_bsup_of_ne_bsup.1 hf))) rintro ⟨_, _, hf⟩ rw [succ_le_iff, ← hf] exact lt_blsub _ _ _ #align ordinal.bsup_succ_le_blsub Ordinal.bsup_succ_le_blsub theorem bsup_succ_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : succ (bsup.{_, v} o f) = blsub.{_, v} o f ↔ ∃ i hi, f i hi = bsup.{_, v} o f := (blsub_le_bsup_succ f).le_iff_eq.symm.trans (bsup_succ_le_blsub f) #align ordinal.bsup_succ_eq_blsub Ordinal.bsup_succ_eq_blsub theorem bsup_eq_blsub_iff_succ {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : bsup.{_, v} o f = blsub.{_, v} o f ↔ ∀ a < blsub.{_, v} o f, succ a < blsub.{_, v} o f := by rw [← sup_eq_bsup, ← lsub_eq_blsub] apply sup_eq_lsub_iff_succ #align ordinal.bsup_eq_blsub_iff_succ Ordinal.bsup_eq_blsub_iff_succ theorem bsup_eq_blsub_iff_lt_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : bsup.{_, v} o f = blsub.{_, v} o f ↔ ∀ i hi, f i hi < bsup.{_, v} o f := ⟨fun h i => by rw [h] apply lt_blsub, fun h => le_antisymm (bsup_le_blsub f) (blsub_le h)⟩ #align ordinal.bsup_eq_blsub_iff_lt_bsup Ordinal.bsup_eq_blsub_iff_lt_bsup theorem bsup_eq_blsub_of_lt_succ_limit {o : Ordinal.{u}} (ho : IsLimit o) {f : ∀ a < o, Ordinal.{max u v}} (hf : ∀ a ha, f a ha < f (succ a) (ho.2 a ha)) : bsup.{_, v} o f = blsub.{_, v} o f := by rw [bsup_eq_blsub_iff_lt_bsup] exact fun i hi => (hf i hi).trans_le (le_bsup f _ _) #align ordinal.bsup_eq_blsub_of_lt_succ_limit Ordinal.bsup_eq_blsub_of_lt_succ_limit theorem blsub_succ_of_mono {o : Ordinal.{u}} {f : ∀ a < succ o, Ordinal.{max u v}} (hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : blsub.{_, v} _ f = succ (f o (lt_succ o)) := bsup_succ_of_mono fun {_ _} hi hj h => succ_le_succ (hf hi hj h) #align ordinal.blsub_succ_of_mono Ordinal.blsub_succ_of_mono @[simp] theorem blsub_eq_zero_iff {o} {f : ∀ a < o, Ordinal} : blsub o f = 0 ↔ o = 0 := by rw [← lsub_eq_blsub, lsub_eq_zero_iff] exact out_empty_iff_eq_zero #align ordinal.blsub_eq_zero_iff Ordinal.blsub_eq_zero_iff -- Porting note: `rwa` → `rw` @[simp] theorem blsub_zero (f : ∀ a < (0 : Ordinal), Ordinal) : blsub 0 f = 0 := by rw [blsub_eq_zero_iff] #align ordinal.blsub_zero Ordinal.blsub_zero theorem blsub_pos {o : Ordinal} (ho : 0 < o) (f : ∀ a < o, Ordinal) : 0 < blsub o f := (Ordinal.zero_le _).trans_lt (lt_blsub f 0 ho) #align ordinal.blsub_pos Ordinal.blsub_pos theorem blsub_type {α : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : ∀ a < type r, Ordinal.{max u v}) : blsub.{_, v} (type r) f = lsub.{_, v} fun a => f (typein r a) (typein_lt_type _ _) := eq_of_forall_ge_iff fun o => by rw [blsub_le_iff, lsub_le_iff]; exact ⟨fun H b => H _ _, fun H i h => by simpa only [typein_enum] using H (enum r i h)⟩ #align ordinal.blsub_type Ordinal.blsub_type theorem blsub_const {o : Ordinal} (ho : o ≠ 0) (a : Ordinal) : (blsub.{u, v} o fun _ _ => a) = succ a := bsup_const.{u, v} ho (succ a) #align ordinal.blsub_const Ordinal.blsub_const @[simp] theorem blsub_one (f : ∀ a < (1 : Ordinal), Ordinal) : blsub 1 f = succ (f 0 zero_lt_one) := bsup_one _ #align ordinal.blsub_one Ordinal.blsub_one @[simp] theorem blsub_id : ∀ o, (blsub.{u, u} o fun x _ => x) = o := lsub_typein #align ordinal.blsub_id Ordinal.blsub_id theorem bsup_id_limit {o : Ordinal} : (∀ a < o, succ a < o) → (bsup.{u, u} o fun x _ => x) = o := sup_typein_limit #align ordinal.bsup_id_limit Ordinal.bsup_id_limit @[simp] theorem bsup_id_succ (o) : (bsup.{u, u} (succ o) fun x _ => x) = o := sup_typein_succ #align ordinal.bsup_id_succ Ordinal.bsup_id_succ theorem blsub_le_of_brange_subset {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal} (h : brange o f ⊆ brange o' g) : blsub.{u, max v w} o f ≤ blsub.{v, max u w} o' g := bsup_le_of_brange_subset.{u, v, w} fun a ⟨b, hb, hb'⟩ => by obtain ⟨c, hc, hc'⟩ := h ⟨b, hb, rfl⟩ simp_rw [← hc'] at hb' exact ⟨c, hc, hb'⟩ #align ordinal.blsub_le_of_brange_subset Ordinal.blsub_le_of_brange_subset theorem blsub_eq_of_brange_eq {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal} (h : { o | ∃ i hi, f i hi = o } = { o | ∃ i hi, g i hi = o }) : blsub.{u, max v w} o f = blsub.{v, max u w} o' g := (blsub_le_of_brange_subset.{u, v, w} h.le).antisymm (blsub_le_of_brange_subset.{v, u, w} h.ge) #align ordinal.blsub_eq_of_brange_eq Ordinal.blsub_eq_of_brange_eq theorem bsup_comp {o o' : Ordinal.{max u v}} {f : ∀ a < o, Ordinal.{max u v w}} (hf : ∀ {i j} (hi) (hj), i ≤ j → f i hi ≤ f j hj) {g : ∀ a < o', Ordinal.{max u v}} (hg : blsub.{_, u} o' g = o) : (bsup.{_, w} o' fun a ha => f (g a ha) (by rw [← hg]; apply lt_blsub)) = bsup.{_, w} o f := by apply le_antisymm <;> refine bsup_le fun i hi => ?_ · apply le_bsup · rw [← hg, lt_blsub_iff] at hi rcases hi with ⟨j, hj, hj'⟩ exact (hf _ _ hj').trans (le_bsup _ _ _) #align ordinal.bsup_comp Ordinal.bsup_comp theorem blsub_comp {o o' : Ordinal.{max u v}} {f : ∀ a < o, Ordinal.{max u v w}} (hf : ∀ {i j} (hi) (hj), i ≤ j → f i hi ≤ f j hj) {g : ∀ a < o', Ordinal.{max u v}} (hg : blsub.{_, u} o' g = o) : (blsub.{_, w} o' fun a ha => f (g a ha) (by rw [← hg]; apply lt_blsub)) = blsub.{_, w} o f := @bsup_comp.{u, v, w} o _ (fun a ha => succ (f a ha)) (fun {_ _} _ _ h => succ_le_succ_iff.2 (hf _ _ h)) g hg #align ordinal.blsub_comp Ordinal.blsub_comp theorem IsNormal.bsup_eq {f : Ordinal.{u} → Ordinal.{max u v}} (H : IsNormal f) {o : Ordinal.{u}} (h : IsLimit o) : (Ordinal.bsup.{_, v} o fun x _ => f x) = f o := by rw [← IsNormal.bsup.{u, u, v} H (fun x _ => x) h.1, bsup_id_limit h.2] #align ordinal.is_normal.bsup_eq Ordinal.IsNormal.bsup_eq theorem IsNormal.blsub_eq {f : Ordinal.{u} → Ordinal.{max u v}} (H : IsNormal f) {o : Ordinal.{u}} (h : IsLimit o) : (blsub.{_, v} o fun x _ => f x) = f o := by rw [← IsNormal.bsup_eq.{u, v} H h, bsup_eq_blsub_of_lt_succ_limit h] exact fun a _ => H.1 a #align ordinal.is_normal.blsub_eq Ordinal.IsNormal.blsub_eq theorem isNormal_iff_lt_succ_and_bsup_eq {f : Ordinal.{u} → Ordinal.{max u v}} : IsNormal f ↔ (∀ a, f a < f (succ a)) ∧ ∀ o, IsLimit o → (bsup.{_, v} o fun x _ => f x) = f o := ⟨fun h => ⟨h.1, @IsNormal.bsup_eq f h⟩, fun ⟨h₁, h₂⟩ => ⟨h₁, fun o ho a => by rw [← h₂ o ho] exact bsup_le_iff⟩⟩ #align ordinal.is_normal_iff_lt_succ_and_bsup_eq Ordinal.isNormal_iff_lt_succ_and_bsup_eq theorem isNormal_iff_lt_succ_and_blsub_eq {f : Ordinal.{u} → Ordinal.{max u v}} : IsNormal f ↔ (∀ a, f a < f (succ a)) ∧ ∀ o, IsLimit o → (blsub.{_, v} o fun x _ => f x) = f o := by rw [isNormal_iff_lt_succ_and_bsup_eq.{u, v}, and_congr_right_iff] intro h constructor <;> intro H o ho <;> have := H o ho <;> rwa [← bsup_eq_blsub_of_lt_succ_limit ho fun a _ => h a] at * #align ordinal.is_normal_iff_lt_succ_and_blsub_eq Ordinal.isNormal_iff_lt_succ_and_blsub_eq theorem IsNormal.eq_iff_zero_and_succ {f g : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f) (hg : IsNormal g) : f = g ↔ f 0 = g 0 ∧ ∀ a, f a = g a → f (succ a) = g (succ a) := ⟨fun h => by simp [h], fun ⟨h₁, h₂⟩ => funext fun a => by induction' a using limitRecOn with _ _ _ ho H any_goals solve_by_elim rw [← IsNormal.bsup_eq.{u, u} hf ho, ← IsNormal.bsup_eq.{u, u} hg ho] congr ext b hb exact H b hb⟩ #align ordinal.is_normal.eq_iff_zero_and_succ Ordinal.IsNormal.eq_iff_zero_and_succ /-- A two-argument version of `Ordinal.blsub`. We don't develop a full API for this, since it's only used in a handful of existence results. -/ def blsub₂ (o₁ o₂ : Ordinal) (op : {a : Ordinal} → (a < o₁) → {b : Ordinal} → (b < o₂) → Ordinal) : Ordinal := lsub (fun x : o₁.out.α × o₂.out.α => op (typein_lt_self x.1) (typein_lt_self x.2)) #align ordinal.blsub₂ Ordinal.blsub₂ theorem lt_blsub₂ {o₁ o₂ : Ordinal} (op : {a : Ordinal} → (a < o₁) → {b : Ordinal} → (b < o₂) → Ordinal) {a b : Ordinal} (ha : a < o₁) (hb : b < o₂) : op ha hb < blsub₂ o₁ o₂ op := by convert lt_lsub _ (Prod.mk (enum (· < ·) a (by rwa [type_lt])) (enum (· < ·) b (by rwa [type_lt]))) simp only [typein_enum] #align ordinal.lt_blsub₂ Ordinal.lt_blsub₂ /-! ### Minimum excluded ordinals -/ /-- The minimum excluded ordinal in a family of ordinals. -/ def mex {ι : Type u} (f : ι → Ordinal.{max u v}) : Ordinal := sInf (Set.range f)ᶜ #align ordinal.mex Ordinal.mex theorem mex_not_mem_range {ι : Type u} (f : ι → Ordinal.{max u v}) : mex.{_, v} f ∉ Set.range f := csInf_mem (nonempty_compl_range.{_, v} f) #align ordinal.mex_not_mem_range Ordinal.mex_not_mem_range theorem le_mex_of_forall {ι : Type u} {f : ι → Ordinal.{max u v}} {a : Ordinal} (H : ∀ b < a, ∃ i, f i = b) : a ≤ mex.{_, v} f := by by_contra! h exact mex_not_mem_range f (H _ h) #align ordinal.le_mex_of_forall Ordinal.le_mex_of_forall
Mathlib/SetTheory/Ordinal/Arithmetic.lean
2,031
2,032
theorem ne_mex {ι : Type u} (f : ι → Ordinal.{max u v}) : ∀ i, f i ≠ mex.{_, v} f := by
simpa using mex_not_mem_range.{_, v} f
/- 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 -/ import Mathlib.Analysis.Convex.Function #align_import analysis.convex.quasiconvex from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Quasiconvex and quasiconcave functions This file defines quasiconvexity, quasiconcavity and quasilinearity of functions, which are generalizations of unimodality and monotonicity. Convexity implies quasiconvexity, concavity implies quasiconcavity, and monotonicity implies quasilinearity. ## Main declarations * `QuasiconvexOn 𝕜 s f`: Quasiconvexity of the function `f` on the set `s` with scalars `𝕜`. This means that, for all `r`, `{x ∈ s | f x ≤ r}` is `𝕜`-convex. * `QuasiconcaveOn 𝕜 s f`: Quasiconcavity of the function `f` on the set `s` with scalars `𝕜`. This means that, for all `r`, `{x ∈ s | r ≤ f x}` is `𝕜`-convex. * `QuasilinearOn 𝕜 s f`: Quasilinearity of the function `f` on the set `s` with scalars `𝕜`. This means that `f` is both quasiconvex and quasiconcave. ## References * https://en.wikipedia.org/wiki/Quasiconvex_function -/ open Function OrderDual Set variable {𝕜 E F β : Type*} section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid_E variable [AddCommMonoid E] [AddCommMonoid F] section LE_β variable (𝕜) [LE β] [SMul 𝕜 E] (s : Set E) (f : E → β) /-- A function is quasiconvex if all its sublevels are convex. This means that, for all `r`, `{x ∈ s | f x ≤ r}` is `𝕜`-convex. -/ def QuasiconvexOn : Prop := ∀ r, Convex 𝕜 ({ x ∈ s | f x ≤ r }) #align quasiconvex_on QuasiconvexOn /-- A function is quasiconcave if all its superlevels are convex. This means that, for all `r`, `{x ∈ s | r ≤ f x}` is `𝕜`-convex. -/ def QuasiconcaveOn : Prop := ∀ r, Convex 𝕜 ({ x ∈ s | r ≤ f x }) #align quasiconcave_on QuasiconcaveOn /-- A function is quasilinear if it is both quasiconvex and quasiconcave. This means that, for all `r`, the sets `{x ∈ s | f x ≤ r}` and `{x ∈ s | r ≤ f x}` are `𝕜`-convex. -/ def QuasilinearOn : Prop := QuasiconvexOn 𝕜 s f ∧ QuasiconcaveOn 𝕜 s f #align quasilinear_on QuasilinearOn variable {𝕜 s f} theorem QuasiconvexOn.dual : QuasiconvexOn 𝕜 s f → QuasiconcaveOn 𝕜 s (toDual ∘ f) := id #align quasiconvex_on.dual QuasiconvexOn.dual theorem QuasiconcaveOn.dual : QuasiconcaveOn 𝕜 s f → QuasiconvexOn 𝕜 s (toDual ∘ f) := id #align quasiconcave_on.dual QuasiconcaveOn.dual theorem QuasilinearOn.dual : QuasilinearOn 𝕜 s f → QuasilinearOn 𝕜 s (toDual ∘ f) := And.symm #align quasilinear_on.dual QuasilinearOn.dual theorem Convex.quasiconvexOn_of_convex_le (hs : Convex 𝕜 s) (h : ∀ r, Convex 𝕜 { x | f x ≤ r }) : QuasiconvexOn 𝕜 s f := fun r => hs.inter (h r) #align convex.quasiconvex_on_of_convex_le Convex.quasiconvexOn_of_convex_le theorem Convex.quasiconcaveOn_of_convex_ge (hs : Convex 𝕜 s) (h : ∀ r, Convex 𝕜 { x | r ≤ f x }) : QuasiconcaveOn 𝕜 s f := @Convex.quasiconvexOn_of_convex_le 𝕜 E βᵒᵈ _ _ _ _ _ _ hs h #align convex.quasiconcave_on_of_convex_ge Convex.quasiconcaveOn_of_convex_ge theorem QuasiconvexOn.convex [IsDirected β (· ≤ ·)] (hf : QuasiconvexOn 𝕜 s f) : Convex 𝕜 s := fun x hx y hy _ _ ha hb hab => let ⟨_, hxz, hyz⟩ := exists_ge_ge (f x) (f y) (hf _ ⟨hx, hxz⟩ ⟨hy, hyz⟩ ha hb hab).1 #align quasiconvex_on.convex QuasiconvexOn.convex theorem QuasiconcaveOn.convex [IsDirected β (· ≥ ·)] (hf : QuasiconcaveOn 𝕜 s f) : Convex 𝕜 s := hf.dual.convex #align quasiconcave_on.convex QuasiconcaveOn.convex end LE_β section Semilattice_β variable [SMul 𝕜 E] {s : Set E} {f g : E → β}
Mathlib/Analysis/Convex/Quasiconvex.lean
106
110
theorem QuasiconvexOn.sup [SemilatticeSup β] (hf : QuasiconvexOn 𝕜 s f) (hg : QuasiconvexOn 𝕜 s g) : QuasiconvexOn 𝕜 s (f ⊔ g) := by
intro r simp_rw [Pi.sup_def, sup_le_iff, Set.sep_and] exact (hf r).inter (hg r)
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Patrick Massot -/ import Mathlib.Data.Set.Function import Mathlib.Order.Interval.Set.OrdConnected #align_import data.set.intervals.proj_Icc from "leanprover-community/mathlib"@"4e24c4bfcff371c71f7ba22050308aa17815626c" /-! # Projection of a line onto a closed interval Given a linearly ordered type `α`, in this file we define * `Set.projIci (a : α)` to be the map `α → [a, ∞)` sending `(-∞, a]` to `a`, and each point `x ∈ [a, ∞)` to itself; * `Set.projIic (b : α)` to be the map `α → (-∞, b[` sending `[b, ∞)` to `b`, and each point `x ∈ (-∞, b]` to itself; * `Set.projIcc (a b : α) (h : a ≤ b)` to be the map `α → [a, b]` sending `(-∞, a]` to `a`, `[b, ∞)` to `b`, and each point `x ∈ [a, b]` to itself; * `Set.IccExtend {a b : α} (h : a ≤ b) (f : Icc a b → β)` to be the extension of `f` to `α` defined as `f ∘ projIcc a b h`. * `Set.IciExtend {a : α} (f : Ici a → β)` to be the extension of `f` to `α` defined as `f ∘ projIci a`. * `Set.IicExtend {b : α} (f : Iic b → β)` to be the extension of `f` to `α` defined as `f ∘ projIic b`. We also prove some trivial properties of these maps. -/ variable {α β : Type*} [LinearOrder α] open Function namespace Set /-- Projection of `α` to the closed interval `[a, ∞)`. -/ def projIci (a x : α) : Ici a := ⟨max a x, le_max_left _ _⟩ #align set.proj_Ici Set.projIci /-- Projection of `α` to the closed interval `(-∞, b]`. -/ def projIic (b x : α) : Iic b := ⟨min b x, min_le_left _ _⟩ #align set.proj_Iic Set.projIic /-- Projection of `α` to the closed interval `[a, b]`. -/ def projIcc (a b : α) (h : a ≤ b) (x : α) : Icc a b := ⟨max a (min b x), le_max_left _ _, max_le h (min_le_left _ _)⟩ #align set.proj_Icc Set.projIcc variable {a b : α} (h : a ≤ b) {x : α} @[norm_cast] theorem coe_projIci (a x : α) : (projIci a x : α) = max a x := rfl #align set.coe_proj_Ici Set.coe_projIci @[norm_cast] theorem coe_projIic (b x : α) : (projIic b x : α) = min b x := rfl #align set.coe_proj_Iic Set.coe_projIic @[norm_cast] theorem coe_projIcc (a b : α) (h : a ≤ b) (x : α) : (projIcc a b h x : α) = max a (min b x) := rfl #align set.coe_proj_Icc Set.coe_projIcc theorem projIci_of_le (hx : x ≤ a) : projIci a x = ⟨a, le_rfl⟩ := Subtype.ext <| max_eq_left hx #align set.proj_Ici_of_le Set.projIci_of_le theorem projIic_of_le (hx : b ≤ x) : projIic b x = ⟨b, le_rfl⟩ := Subtype.ext <| min_eq_left hx #align set.proj_Iic_of_le Set.projIic_of_le theorem projIcc_of_le_left (hx : x ≤ a) : projIcc a b h x = ⟨a, left_mem_Icc.2 h⟩ := by simp [projIcc, hx, hx.trans h] #align set.proj_Icc_of_le_left Set.projIcc_of_le_left theorem projIcc_of_right_le (hx : b ≤ x) : projIcc a b h x = ⟨b, right_mem_Icc.2 h⟩ := by simp [projIcc, hx, h] #align set.proj_Icc_of_right_le Set.projIcc_of_right_le @[simp] theorem projIci_self (a : α) : projIci a a = ⟨a, le_rfl⟩ := projIci_of_le le_rfl #align set.proj_Ici_self Set.projIci_self @[simp] theorem projIic_self (b : α) : projIic b b = ⟨b, le_rfl⟩ := projIic_of_le le_rfl #align set.proj_Iic_self Set.projIic_self @[simp] theorem projIcc_left : projIcc a b h a = ⟨a, left_mem_Icc.2 h⟩ := projIcc_of_le_left h le_rfl #align set.proj_Icc_left Set.projIcc_left @[simp] theorem projIcc_right : projIcc a b h b = ⟨b, right_mem_Icc.2 h⟩ := projIcc_of_right_le h le_rfl #align set.proj_Icc_right Set.projIcc_right theorem projIci_eq_self : projIci a x = ⟨a, le_rfl⟩ ↔ x ≤ a := by simp [projIci, Subtype.ext_iff] #align set.proj_Ici_eq_self Set.projIci_eq_self theorem projIic_eq_self : projIic b x = ⟨b, le_rfl⟩ ↔ b ≤ x := by simp [projIic, Subtype.ext_iff] #align set.proj_Iic_eq_self Set.projIic_eq_self theorem projIcc_eq_left (h : a < b) : projIcc a b h.le x = ⟨a, left_mem_Icc.mpr h.le⟩ ↔ x ≤ a := by simp [projIcc, Subtype.ext_iff, h.not_le] #align set.proj_Icc_eq_left Set.projIcc_eq_left theorem projIcc_eq_right (h : a < b) : projIcc a b h.le x = ⟨b, right_mem_Icc.2 h.le⟩ ↔ b ≤ x := by simp [projIcc, Subtype.ext_iff, max_min_distrib_left, h.le, h.not_le] #align set.proj_Icc_eq_right Set.projIcc_eq_right theorem projIci_of_mem (hx : x ∈ Ici a) : projIci a x = ⟨x, hx⟩ := by simpa [projIci] #align set.proj_Ici_of_mem Set.projIci_of_mem theorem projIic_of_mem (hx : x ∈ Iic b) : projIic b x = ⟨x, hx⟩ := by simpa [projIic] #align set.proj_Iic_of_mem Set.projIic_of_mem theorem projIcc_of_mem (hx : x ∈ Icc a b) : projIcc a b h x = ⟨x, hx⟩ := by simp [projIcc, hx.1, hx.2] #align set.proj_Icc_of_mem Set.projIcc_of_mem @[simp]
Mathlib/Order/Interval/Set/ProjIcc.lean
124
124
theorem projIci_coe (x : Ici a) : projIci a x = x := by
cases x; apply projIci_of_mem
/- Copyright (c) 2020 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Sébastien Gouëzel -/ import Mathlib.Analysis.Normed.Group.Hom import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Data.Set.Image import Mathlib.MeasureTheory.Function.LpSeminorm.ChebyshevMarkov import Mathlib.MeasureTheory.Function.LpSeminorm.CompareExp import Mathlib.MeasureTheory.Function.LpSeminorm.TriangleInequality import Mathlib.MeasureTheory.Measure.OpenPos import Mathlib.Topology.ContinuousFunction.Compact import Mathlib.Order.Filter.IndicatorFunction #align_import measure_theory.function.lp_space from "leanprover-community/mathlib"@"c4015acc0a223449d44061e27ddac1835a3852b9" /-! # Lp space This file provides the space `Lp E p μ` as the subtype of elements of `α →ₘ[μ] E` (see ae_eq_fun) such that `snorm f p μ` is finite. For `1 ≤ p`, `snorm` defines a norm and `Lp` is a complete metric space. ## Main definitions * `Lp E p μ` : elements of `α →ₘ[μ] E` (see ae_eq_fun) such that `snorm f p μ` is finite. Defined as an `AddSubgroup` of `α →ₘ[μ] E`. Lipschitz functions vanishing at zero act by composition on `Lp`. We define this action, and prove that it is continuous. In particular, * `ContinuousLinearMap.compLp` defines the action on `Lp` of a continuous linear map. * `Lp.posPart` is the positive part of an `Lp` function. * `Lp.negPart` is the negative part of an `Lp` function. When `α` is a topological space equipped with a finite Borel measure, there is a bounded linear map from the normed space of bounded continuous functions (`α →ᵇ E`) to `Lp E p μ`. We construct this as `BoundedContinuousFunction.toLp`. ## Notations * `α →₁[μ] E` : the type `Lp E 1 μ`. * `α →₂[μ] E` : the type `Lp E 2 μ`. ## Implementation Since `Lp` is defined as an `AddSubgroup`, dot notation does not work. Use `Lp.Measurable f` to say that the coercion of `f` to a genuine function is measurable, instead of the non-working `f.Measurable`. To prove that two `Lp` elements are equal, it suffices to show that their coercions to functions coincide almost everywhere (this is registered as an `ext` rule). This can often be done using `filter_upwards`. For instance, a proof from first principles that `f + (g + h) = (f + g) + h` could read (in the `Lp` namespace) ``` example (f g h : Lp E p μ) : (f + g) + h = f + (g + h) := by ext1 filter_upwards [coeFn_add (f + g) h, coeFn_add f g, coeFn_add f (g + h), coeFn_add g h] with _ ha1 ha2 ha3 ha4 simp only [ha1, ha2, ha3, ha4, add_assoc] ``` The lemma `coeFn_add` states that the coercion of `f + g` coincides almost everywhere with the sum of the coercions of `f` and `g`. All such lemmas use `coeFn` in their name, to distinguish the function coercion from the coercion to almost everywhere defined functions. -/ noncomputable section set_option linter.uppercaseLean3 false open TopologicalSpace MeasureTheory Filter open scoped NNReal ENNReal Topology MeasureTheory Uniformity variable {α E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α} [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] namespace MeasureTheory /-! ### Lp space The space of equivalence classes of measurable functions for which `snorm f p μ < ∞`. -/ @[simp] theorem snorm_aeeqFun {α E : Type*} [MeasurableSpace α] {μ : Measure α} [NormedAddCommGroup E] {p : ℝ≥0∞} {f : α → E} (hf : AEStronglyMeasurable f μ) : snorm (AEEqFun.mk f hf) p μ = snorm f p μ := snorm_congr_ae (AEEqFun.coeFn_mk _ _) #align measure_theory.snorm_ae_eq_fun MeasureTheory.snorm_aeeqFun theorem Memℒp.snorm_mk_lt_top {α E : Type*} [MeasurableSpace α] {μ : Measure α} [NormedAddCommGroup E] {p : ℝ≥0∞} {f : α → E} (hfp : Memℒp f p μ) : snorm (AEEqFun.mk f hfp.1) p μ < ∞ := by simp [hfp.2] #align measure_theory.mem_ℒp.snorm_mk_lt_top MeasureTheory.Memℒp.snorm_mk_lt_top /-- Lp space -/ def Lp {α} (E : Type*) {m : MeasurableSpace α} [NormedAddCommGroup E] (p : ℝ≥0∞) (μ : Measure α := by volume_tac) : AddSubgroup (α →ₘ[μ] E) where carrier := { f | snorm f p μ < ∞ } zero_mem' := by simp [snorm_congr_ae AEEqFun.coeFn_zero, snorm_zero] add_mem' {f g} hf hg := by simp [snorm_congr_ae (AEEqFun.coeFn_add f g), snorm_add_lt_top ⟨f.aestronglyMeasurable, hf⟩ ⟨g.aestronglyMeasurable, hg⟩] neg_mem' {f} hf := by rwa [Set.mem_setOf_eq, snorm_congr_ae (AEEqFun.coeFn_neg f), snorm_neg] #align measure_theory.Lp MeasureTheory.Lp -- Porting note: calling the first argument `α` breaks the `(α := ·)` notation scoped notation:25 α' " →₁[" μ "] " E => MeasureTheory.Lp (α := α') E 1 μ scoped notation:25 α' " →₂[" μ "] " E => MeasureTheory.Lp (α := α') E 2 μ namespace Memℒp /-- make an element of Lp from a function verifying `Memℒp` -/ def toLp (f : α → E) (h_mem_ℒp : Memℒp f p μ) : Lp E p μ := ⟨AEEqFun.mk f h_mem_ℒp.1, h_mem_ℒp.snorm_mk_lt_top⟩ #align measure_theory.mem_ℒp.to_Lp MeasureTheory.Memℒp.toLp theorem coeFn_toLp {f : α → E} (hf : Memℒp f p μ) : hf.toLp f =ᵐ[μ] f := AEEqFun.coeFn_mk _ _ #align measure_theory.mem_ℒp.coe_fn_to_Lp MeasureTheory.Memℒp.coeFn_toLp theorem toLp_congr {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) (hfg : f =ᵐ[μ] g) : hf.toLp f = hg.toLp g := by simp [toLp, hfg] #align measure_theory.mem_ℒp.to_Lp_congr MeasureTheory.Memℒp.toLp_congr @[simp] theorem toLp_eq_toLp_iff {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) : hf.toLp f = hg.toLp g ↔ f =ᵐ[μ] g := by simp [toLp] #align measure_theory.mem_ℒp.to_Lp_eq_to_Lp_iff MeasureTheory.Memℒp.toLp_eq_toLp_iff @[simp] theorem toLp_zero (h : Memℒp (0 : α → E) p μ) : h.toLp 0 = 0 := rfl #align measure_theory.mem_ℒp.to_Lp_zero MeasureTheory.Memℒp.toLp_zero theorem toLp_add {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) : (hf.add hg).toLp (f + g) = hf.toLp f + hg.toLp g := rfl #align measure_theory.mem_ℒp.to_Lp_add MeasureTheory.Memℒp.toLp_add theorem toLp_neg {f : α → E} (hf : Memℒp f p μ) : hf.neg.toLp (-f) = -hf.toLp f := rfl #align measure_theory.mem_ℒp.to_Lp_neg MeasureTheory.Memℒp.toLp_neg theorem toLp_sub {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) : (hf.sub hg).toLp (f - g) = hf.toLp f - hg.toLp g := rfl #align measure_theory.mem_ℒp.to_Lp_sub MeasureTheory.Memℒp.toLp_sub end Memℒp namespace Lp instance instCoeFun : CoeFun (Lp E p μ) (fun _ => α → E) := ⟨fun f => ((f : α →ₘ[μ] E) : α → E)⟩ #align measure_theory.Lp.has_coe_to_fun MeasureTheory.Lp.instCoeFun @[ext high] theorem ext {f g : Lp E p μ} (h : f =ᵐ[μ] g) : f = g := by cases f cases g simp only [Subtype.mk_eq_mk] exact AEEqFun.ext h #align measure_theory.Lp.ext MeasureTheory.Lp.ext theorem ext_iff {f g : Lp E p μ} : f = g ↔ f =ᵐ[μ] g := ⟨fun h => by rw [h], fun h => ext h⟩ #align measure_theory.Lp.ext_iff MeasureTheory.Lp.ext_iff theorem mem_Lp_iff_snorm_lt_top {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ snorm f p μ < ∞ := Iff.rfl #align measure_theory.Lp.mem_Lp_iff_snorm_lt_top MeasureTheory.Lp.mem_Lp_iff_snorm_lt_top theorem mem_Lp_iff_memℒp {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ Memℒp f p μ := by simp [mem_Lp_iff_snorm_lt_top, Memℒp, f.stronglyMeasurable.aestronglyMeasurable] #align measure_theory.Lp.mem_Lp_iff_mem_ℒp MeasureTheory.Lp.mem_Lp_iff_memℒp protected theorem antitone [IsFiniteMeasure μ] {p q : ℝ≥0∞} (hpq : p ≤ q) : Lp E q μ ≤ Lp E p μ := fun f hf => (Memℒp.memℒp_of_exponent_le ⟨f.aestronglyMeasurable, hf⟩ hpq).2 #align measure_theory.Lp.antitone MeasureTheory.Lp.antitone @[simp] theorem coeFn_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) : ((⟨f, hf⟩ : Lp E p μ) : α → E) = f := rfl #align measure_theory.Lp.coe_fn_mk MeasureTheory.Lp.coeFn_mk -- @[simp] -- Porting note (#10685): dsimp can prove this theorem coe_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) : ((⟨f, hf⟩ : Lp E p μ) : α →ₘ[μ] E) = f := rfl #align measure_theory.Lp.coe_mk MeasureTheory.Lp.coe_mk @[simp] theorem toLp_coeFn (f : Lp E p μ) (hf : Memℒp f p μ) : hf.toLp f = f := by cases f simp [Memℒp.toLp] #align measure_theory.Lp.to_Lp_coe_fn MeasureTheory.Lp.toLp_coeFn theorem snorm_lt_top (f : Lp E p μ) : snorm f p μ < ∞ := f.prop #align measure_theory.Lp.snorm_lt_top MeasureTheory.Lp.snorm_lt_top theorem snorm_ne_top (f : Lp E p μ) : snorm f p μ ≠ ∞ := (snorm_lt_top f).ne #align measure_theory.Lp.snorm_ne_top MeasureTheory.Lp.snorm_ne_top @[measurability] protected theorem stronglyMeasurable (f : Lp E p μ) : StronglyMeasurable f := f.val.stronglyMeasurable #align measure_theory.Lp.strongly_measurable MeasureTheory.Lp.stronglyMeasurable @[measurability] protected theorem aestronglyMeasurable (f : Lp E p μ) : AEStronglyMeasurable f μ := f.val.aestronglyMeasurable #align measure_theory.Lp.ae_strongly_measurable MeasureTheory.Lp.aestronglyMeasurable protected theorem memℒp (f : Lp E p μ) : Memℒp f p μ := ⟨Lp.aestronglyMeasurable f, f.prop⟩ #align measure_theory.Lp.mem_ℒp MeasureTheory.Lp.memℒp variable (E p μ) theorem coeFn_zero : ⇑(0 : Lp E p μ) =ᵐ[μ] 0 := AEEqFun.coeFn_zero #align measure_theory.Lp.coe_fn_zero MeasureTheory.Lp.coeFn_zero variable {E p μ} theorem coeFn_neg (f : Lp E p μ) : ⇑(-f) =ᵐ[μ] -f := AEEqFun.coeFn_neg _ #align measure_theory.Lp.coe_fn_neg MeasureTheory.Lp.coeFn_neg theorem coeFn_add (f g : Lp E p μ) : ⇑(f + g) =ᵐ[μ] f + g := AEEqFun.coeFn_add _ _ #align measure_theory.Lp.coe_fn_add MeasureTheory.Lp.coeFn_add theorem coeFn_sub (f g : Lp E p μ) : ⇑(f - g) =ᵐ[μ] f - g := AEEqFun.coeFn_sub _ _ #align measure_theory.Lp.coe_fn_sub MeasureTheory.Lp.coeFn_sub theorem const_mem_Lp (α) {_ : MeasurableSpace α} (μ : Measure α) (c : E) [IsFiniteMeasure μ] : @AEEqFun.const α _ _ μ _ c ∈ Lp E p μ := (memℒp_const c).snorm_mk_lt_top #align measure_theory.Lp.mem_Lp_const MeasureTheory.Lp.const_mem_Lp instance instNorm : Norm (Lp E p μ) where norm f := ENNReal.toReal (snorm f p μ) #align measure_theory.Lp.has_norm MeasureTheory.Lp.instNorm -- note: we need this to be defeq to the instance from `SeminormedAddGroup.toNNNorm`, so -- can't use `ENNReal.toNNReal (snorm f p μ)` instance instNNNorm : NNNorm (Lp E p μ) where nnnorm f := ⟨‖f‖, ENNReal.toReal_nonneg⟩ #align measure_theory.Lp.has_nnnorm MeasureTheory.Lp.instNNNorm instance instDist : Dist (Lp E p μ) where dist f g := ‖f - g‖ #align measure_theory.Lp.has_dist MeasureTheory.Lp.instDist instance instEDist : EDist (Lp E p μ) where edist f g := snorm (⇑f - ⇑g) p μ #align measure_theory.Lp.has_edist MeasureTheory.Lp.instEDist theorem norm_def (f : Lp E p μ) : ‖f‖ = ENNReal.toReal (snorm f p μ) := rfl #align measure_theory.Lp.norm_def MeasureTheory.Lp.norm_def theorem nnnorm_def (f : Lp E p μ) : ‖f‖₊ = ENNReal.toNNReal (snorm f p μ) := rfl #align measure_theory.Lp.nnnorm_def MeasureTheory.Lp.nnnorm_def @[simp, norm_cast] protected theorem coe_nnnorm (f : Lp E p μ) : (‖f‖₊ : ℝ) = ‖f‖ := rfl #align measure_theory.Lp.coe_nnnorm MeasureTheory.Lp.coe_nnnorm @[simp, norm_cast] theorem nnnorm_coe_ennreal (f : Lp E p μ) : (‖f‖₊ : ℝ≥0∞) = snorm f p μ := ENNReal.coe_toNNReal <| Lp.snorm_ne_top f @[simp] theorem norm_toLp (f : α → E) (hf : Memℒp f p μ) : ‖hf.toLp f‖ = ENNReal.toReal (snorm f p μ) := by erw [norm_def, snorm_congr_ae (Memℒp.coeFn_toLp hf)] #align measure_theory.Lp.norm_to_Lp MeasureTheory.Lp.norm_toLp @[simp] theorem nnnorm_toLp (f : α → E) (hf : Memℒp f p μ) : ‖hf.toLp f‖₊ = ENNReal.toNNReal (snorm f p μ) := NNReal.eq <| norm_toLp f hf #align measure_theory.Lp.nnnorm_to_Lp MeasureTheory.Lp.nnnorm_toLp theorem coe_nnnorm_toLp {f : α → E} (hf : Memℒp f p μ) : (‖hf.toLp f‖₊ : ℝ≥0∞) = snorm f p μ := by rw [nnnorm_toLp f hf, ENNReal.coe_toNNReal hf.2.ne] theorem dist_def (f g : Lp E p μ) : dist f g = (snorm (⇑f - ⇑g) p μ).toReal := by simp_rw [dist, norm_def] refine congr_arg _ ?_ apply snorm_congr_ae (coeFn_sub _ _) #align measure_theory.Lp.dist_def MeasureTheory.Lp.dist_def theorem edist_def (f g : Lp E p μ) : edist f g = snorm (⇑f - ⇑g) p μ := rfl #align measure_theory.Lp.edist_def MeasureTheory.Lp.edist_def protected theorem edist_dist (f g : Lp E p μ) : edist f g = .ofReal (dist f g) := by rw [edist_def, dist_def, ← snorm_congr_ae (coeFn_sub _ _), ENNReal.ofReal_toReal (snorm_ne_top (f - g))] protected theorem dist_edist (f g : Lp E p μ) : dist f g = (edist f g).toReal := MeasureTheory.Lp.dist_def .. theorem dist_eq_norm (f g : Lp E p μ) : dist f g = ‖f - g‖ := rfl @[simp] theorem edist_toLp_toLp (f g : α → E) (hf : Memℒp f p μ) (hg : Memℒp g p μ) : edist (hf.toLp f) (hg.toLp g) = snorm (f - g) p μ := by rw [edist_def] exact snorm_congr_ae (hf.coeFn_toLp.sub hg.coeFn_toLp) #align measure_theory.Lp.edist_to_Lp_to_Lp MeasureTheory.Lp.edist_toLp_toLp @[simp] theorem edist_toLp_zero (f : α → E) (hf : Memℒp f p μ) : edist (hf.toLp f) 0 = snorm f p μ := by convert edist_toLp_toLp f 0 hf zero_memℒp simp #align measure_theory.Lp.edist_to_Lp_zero MeasureTheory.Lp.edist_toLp_zero @[simp] theorem nnnorm_zero : ‖(0 : Lp E p μ)‖₊ = 0 := by rw [nnnorm_def] change (snorm (⇑(0 : α →ₘ[μ] E)) p μ).toNNReal = 0 simp [snorm_congr_ae AEEqFun.coeFn_zero, snorm_zero] #align measure_theory.Lp.nnnorm_zero MeasureTheory.Lp.nnnorm_zero @[simp] theorem norm_zero : ‖(0 : Lp E p μ)‖ = 0 := congr_arg ((↑) : ℝ≥0 → ℝ) nnnorm_zero #align measure_theory.Lp.norm_zero MeasureTheory.Lp.norm_zero @[simp] theorem norm_measure_zero (f : Lp E p (0 : MeasureTheory.Measure α)) : ‖f‖ = 0 := by simp [norm_def] @[simp] theorem norm_exponent_zero (f : Lp E 0 μ) : ‖f‖ = 0 := by simp [norm_def] theorem nnnorm_eq_zero_iff {f : Lp E p μ} (hp : 0 < p) : ‖f‖₊ = 0 ↔ f = 0 := by refine ⟨fun hf => ?_, fun hf => by simp [hf]⟩ rw [nnnorm_def, ENNReal.toNNReal_eq_zero_iff] at hf cases hf with | inl hf => rw [snorm_eq_zero_iff (Lp.aestronglyMeasurable f) hp.ne.symm] at hf exact Subtype.eq (AEEqFun.ext (hf.trans AEEqFun.coeFn_zero.symm)) | inr hf => exact absurd hf (snorm_ne_top f) #align measure_theory.Lp.nnnorm_eq_zero_iff MeasureTheory.Lp.nnnorm_eq_zero_iff theorem norm_eq_zero_iff {f : Lp E p μ} (hp : 0 < p) : ‖f‖ = 0 ↔ f = 0 := NNReal.coe_eq_zero.trans (nnnorm_eq_zero_iff hp) #align measure_theory.Lp.norm_eq_zero_iff MeasureTheory.Lp.norm_eq_zero_iff theorem eq_zero_iff_ae_eq_zero {f : Lp E p μ} : f = 0 ↔ f =ᵐ[μ] 0 := by rw [← (Lp.memℒp f).toLp_eq_toLp_iff zero_memℒp, Memℒp.toLp_zero, toLp_coeFn] #align measure_theory.Lp.eq_zero_iff_ae_eq_zero MeasureTheory.Lp.eq_zero_iff_ae_eq_zero @[simp] theorem nnnorm_neg (f : Lp E p μ) : ‖-f‖₊ = ‖f‖₊ := by rw [nnnorm_def, nnnorm_def, snorm_congr_ae (coeFn_neg _), snorm_neg] #align measure_theory.Lp.nnnorm_neg MeasureTheory.Lp.nnnorm_neg @[simp] theorem norm_neg (f : Lp E p μ) : ‖-f‖ = ‖f‖ := congr_arg ((↑) : ℝ≥0 → ℝ) (nnnorm_neg f) #align measure_theory.Lp.norm_neg MeasureTheory.Lp.norm_neg theorem nnnorm_le_mul_nnnorm_of_ae_le_mul {c : ℝ≥0} {f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) : ‖f‖₊ ≤ c * ‖g‖₊ := by simp only [nnnorm_def] have := snorm_le_nnreal_smul_snorm_of_ae_le_mul h p rwa [← ENNReal.toNNReal_le_toNNReal, ENNReal.smul_def, smul_eq_mul, ENNReal.toNNReal_mul, ENNReal.toNNReal_coe] at this · exact (Lp.memℒp _).snorm_ne_top · exact ENNReal.mul_ne_top ENNReal.coe_ne_top (Lp.memℒp _).snorm_ne_top #align measure_theory.Lp.nnnorm_le_mul_nnnorm_of_ae_le_mul MeasureTheory.Lp.nnnorm_le_mul_nnnorm_of_ae_le_mul theorem norm_le_mul_norm_of_ae_le_mul {c : ℝ} {f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ c * ‖g x‖) : ‖f‖ ≤ c * ‖g‖ := by rcases le_or_lt 0 c with hc | hc · lift c to ℝ≥0 using hc exact NNReal.coe_le_coe.mpr (nnnorm_le_mul_nnnorm_of_ae_le_mul h) · simp only [norm_def] have := snorm_eq_zero_and_zero_of_ae_le_mul_neg h hc p simp [this] #align measure_theory.Lp.norm_le_mul_norm_of_ae_le_mul MeasureTheory.Lp.norm_le_mul_norm_of_ae_le_mul theorem norm_le_norm_of_ae_le {f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : ‖f‖ ≤ ‖g‖ := by rw [norm_def, norm_def, ENNReal.toReal_le_toReal (snorm_ne_top _) (snorm_ne_top _)] exact snorm_mono_ae h #align measure_theory.Lp.norm_le_norm_of_ae_le MeasureTheory.Lp.norm_le_norm_of_ae_le theorem mem_Lp_of_nnnorm_ae_le_mul {c : ℝ≥0} {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_nnnorm_le_mul (Lp.memℒp g) f.aestronglyMeasurable h #align measure_theory.Lp.mem_Lp_of_nnnorm_ae_le_mul MeasureTheory.Lp.mem_Lp_of_nnnorm_ae_le_mul theorem mem_Lp_of_ae_le_mul {c : ℝ} {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ c * ‖g x‖) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_le_mul (Lp.memℒp g) f.aestronglyMeasurable h #align measure_theory.Lp.mem_Lp_of_ae_le_mul MeasureTheory.Lp.mem_Lp_of_ae_le_mul theorem mem_Lp_of_nnnorm_ae_le {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_le (Lp.memℒp g) f.aestronglyMeasurable h #align measure_theory.Lp.mem_Lp_of_nnnorm_ae_le MeasureTheory.Lp.mem_Lp_of_nnnorm_ae_le theorem mem_Lp_of_ae_le {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : f ∈ Lp E p μ := mem_Lp_of_nnnorm_ae_le h #align measure_theory.Lp.mem_Lp_of_ae_le MeasureTheory.Lp.mem_Lp_of_ae_le theorem mem_Lp_of_ae_nnnorm_bound [IsFiniteMeasure μ] {f : α →ₘ[μ] E} (C : ℝ≥0) (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_bound f.aestronglyMeasurable _ hfC #align measure_theory.Lp.mem_Lp_of_ae_nnnorm_bound MeasureTheory.Lp.mem_Lp_of_ae_nnnorm_bound theorem mem_Lp_of_ae_bound [IsFiniteMeasure μ] {f : α →ₘ[μ] E} (C : ℝ) (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_bound f.aestronglyMeasurable _ hfC #align measure_theory.Lp.mem_Lp_of_ae_bound MeasureTheory.Lp.mem_Lp_of_ae_bound theorem nnnorm_le_of_ae_bound [IsFiniteMeasure μ] {f : Lp E p μ} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : ‖f‖₊ ≤ measureUnivNNReal μ ^ p.toReal⁻¹ * C := by by_cases hμ : μ = 0 · by_cases hp : p.toReal⁻¹ = 0 · simp [hp, hμ, nnnorm_def] · simp [hμ, nnnorm_def, Real.zero_rpow hp] rw [← ENNReal.coe_le_coe, nnnorm_def, ENNReal.coe_toNNReal (snorm_ne_top _)] refine (snorm_le_of_ae_nnnorm_bound hfC).trans_eq ?_ rw [← coe_measureUnivNNReal μ, ENNReal.coe_rpow_of_ne_zero (measureUnivNNReal_pos hμ).ne', ENNReal.coe_mul, mul_comm, ENNReal.smul_def, smul_eq_mul] #align measure_theory.Lp.nnnorm_le_of_ae_bound MeasureTheory.Lp.nnnorm_le_of_ae_bound theorem norm_le_of_ae_bound [IsFiniteMeasure μ] {f : Lp E p μ} {C : ℝ} (hC : 0 ≤ C) (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : ‖f‖ ≤ measureUnivNNReal μ ^ p.toReal⁻¹ * C := by lift C to ℝ≥0 using hC have := nnnorm_le_of_ae_bound hfC rwa [← NNReal.coe_le_coe, NNReal.coe_mul, NNReal.coe_rpow] at this #align measure_theory.Lp.norm_le_of_ae_bound MeasureTheory.Lp.norm_le_of_ae_bound instance instNormedAddCommGroup [hp : Fact (1 ≤ p)] : NormedAddCommGroup (Lp E p μ) := { AddGroupNorm.toNormedAddCommGroup { toFun := (norm : Lp E p μ → ℝ) map_zero' := norm_zero neg' := by simp add_le' := fun f g => by suffices (‖f + g‖₊ : ℝ≥0∞) ≤ ‖f‖₊ + ‖g‖₊ from mod_cast this simp only [Lp.nnnorm_coe_ennreal] exact (snorm_congr_ae (AEEqFun.coeFn_add _ _)).trans_le (snorm_add_le (Lp.aestronglyMeasurable _) (Lp.aestronglyMeasurable _) hp.out) eq_zero_of_map_eq_zero' := fun f => (norm_eq_zero_iff <| zero_lt_one.trans_le hp.1).1 } with edist := edist edist_dist := Lp.edist_dist } #align measure_theory.Lp.normed_add_comm_group MeasureTheory.Lp.instNormedAddCommGroup -- check no diamond is created example [Fact (1 ≤ p)] : PseudoEMetricSpace.toEDist = (Lp.instEDist : EDist (Lp E p μ)) := by with_reducible_and_instances rfl example [Fact (1 ≤ p)] : SeminormedAddGroup.toNNNorm = (Lp.instNNNorm : NNNorm (Lp E p μ)) := by with_reducible_and_instances rfl section BoundedSMul variable {𝕜 𝕜' : Type*} variable [NormedRing 𝕜] [NormedRing 𝕜'] [Module 𝕜 E] [Module 𝕜' E] variable [BoundedSMul 𝕜 E] [BoundedSMul 𝕜' E] theorem const_smul_mem_Lp (c : 𝕜) (f : Lp E p μ) : c • (f : α →ₘ[μ] E) ∈ Lp E p μ := by rw [mem_Lp_iff_snorm_lt_top, snorm_congr_ae (AEEqFun.coeFn_smul _ _)] refine (snorm_const_smul_le _ _).trans_lt ?_ rw [ENNReal.smul_def, smul_eq_mul, ENNReal.mul_lt_top_iff] exact Or.inl ⟨ENNReal.coe_lt_top, f.prop⟩ #align measure_theory.Lp.mem_Lp_const_smul MeasureTheory.Lp.const_smul_mem_Lp variable (E p μ 𝕜) /-- The `𝕜`-submodule of elements of `α →ₘ[μ] E` whose `Lp` norm is finite. This is `Lp E p μ`, with extra structure. -/ def LpSubmodule : Submodule 𝕜 (α →ₘ[μ] E) := { Lp E p μ with smul_mem' := fun c f hf => by simpa using const_smul_mem_Lp c ⟨f, hf⟩ } #align measure_theory.Lp.Lp_submodule MeasureTheory.Lp.LpSubmodule variable {E p μ 𝕜} theorem coe_LpSubmodule : (LpSubmodule E p μ 𝕜).toAddSubgroup = Lp E p μ := rfl #align measure_theory.Lp.coe_Lp_submodule MeasureTheory.Lp.coe_LpSubmodule instance instModule : Module 𝕜 (Lp E p μ) := { (LpSubmodule E p μ 𝕜).module with } #align measure_theory.Lp.module MeasureTheory.Lp.instModule theorem coeFn_smul (c : 𝕜) (f : Lp E p μ) : ⇑(c • f) =ᵐ[μ] c • ⇑f := AEEqFun.coeFn_smul _ _ #align measure_theory.Lp.coe_fn_smul MeasureTheory.Lp.coeFn_smul instance instIsCentralScalar [Module 𝕜ᵐᵒᵖ E] [BoundedSMul 𝕜ᵐᵒᵖ E] [IsCentralScalar 𝕜 E] : IsCentralScalar 𝕜 (Lp E p μ) where op_smul_eq_smul k f := Subtype.ext <| op_smul_eq_smul k (f : α →ₘ[μ] E) #align measure_theory.Lp.is_central_scalar MeasureTheory.Lp.instIsCentralScalar instance instSMulCommClass [SMulCommClass 𝕜 𝕜' E] : SMulCommClass 𝕜 𝕜' (Lp E p μ) where smul_comm k k' f := Subtype.ext <| smul_comm k k' (f : α →ₘ[μ] E) #align measure_theory.Lp.smul_comm_class MeasureTheory.Lp.instSMulCommClass instance instIsScalarTower [SMul 𝕜 𝕜'] [IsScalarTower 𝕜 𝕜' E] : IsScalarTower 𝕜 𝕜' (Lp E p μ) where smul_assoc k k' f := Subtype.ext <| smul_assoc k k' (f : α →ₘ[μ] E) instance instBoundedSMul [Fact (1 ≤ p)] : BoundedSMul 𝕜 (Lp E p μ) := -- TODO: add `BoundedSMul.of_nnnorm_smul_le` BoundedSMul.of_norm_smul_le fun r f => by suffices (‖r • f‖₊ : ℝ≥0∞) ≤ ‖r‖₊ * ‖f‖₊ from mod_cast this rw [nnnorm_def, nnnorm_def, ENNReal.coe_toNNReal (Lp.snorm_ne_top _), snorm_congr_ae (coeFn_smul _ _), ENNReal.coe_toNNReal (Lp.snorm_ne_top _)] exact snorm_const_smul_le r f #align measure_theory.Lp.has_bounded_smul MeasureTheory.Lp.instBoundedSMul end BoundedSMul section NormedSpace variable {𝕜 : Type*} [NormedField 𝕜] [NormedSpace 𝕜 E] instance instNormedSpace [Fact (1 ≤ p)] : NormedSpace 𝕜 (Lp E p μ) where norm_smul_le _ _ := norm_smul_le _ _ #align measure_theory.Lp.normed_space MeasureTheory.Lp.instNormedSpace end NormedSpace end Lp namespace Memℒp variable {𝕜 : Type*} [NormedRing 𝕜] [Module 𝕜 E] [BoundedSMul 𝕜 E] theorem toLp_const_smul {f : α → E} (c : 𝕜) (hf : Memℒp f p μ) : (hf.const_smul c).toLp (c • f) = c • hf.toLp f := rfl #align measure_theory.mem_ℒp.to_Lp_const_smul MeasureTheory.Memℒp.toLp_const_smul end Memℒp /-! ### Indicator of a set as an element of Lᵖ For a set `s` with `(hs : MeasurableSet s)` and `(hμs : μ s < ∞)`, we build `indicatorConstLp p hs hμs c`, the element of `Lp` corresponding to `s.indicator (fun _ => c)`. -/ section Indicator variable {c : E} {f : α → E} {hf : AEStronglyMeasurable f μ} {s : Set α} theorem snormEssSup_indicator_le (s : Set α) (f : α → G) : snormEssSup (s.indicator f) μ ≤ snormEssSup f μ := by refine essSup_mono_ae (eventually_of_forall fun x => ?_) rw [ENNReal.coe_le_coe, nnnorm_indicator_eq_indicator_nnnorm] exact Set.indicator_le_self s _ x #align measure_theory.snorm_ess_sup_indicator_le MeasureTheory.snormEssSup_indicator_le theorem snormEssSup_indicator_const_le (s : Set α) (c : G) : snormEssSup (s.indicator fun _ : α => c) μ ≤ ‖c‖₊ := by by_cases hμ0 : μ = 0 · rw [hμ0, snormEssSup_measure_zero] exact zero_le _ · exact (snormEssSup_indicator_le s fun _ => c).trans (snormEssSup_const c hμ0).le #align measure_theory.snorm_ess_sup_indicator_const_le MeasureTheory.snormEssSup_indicator_const_le theorem snormEssSup_indicator_const_eq (s : Set α) (c : G) (hμs : μ s ≠ 0) : snormEssSup (s.indicator fun _ : α => c) μ = ‖c‖₊ := by refine le_antisymm (snormEssSup_indicator_const_le s c) ?_ by_contra! h have h' := ae_iff.mp (ae_lt_of_essSup_lt h) push_neg at h' refine hμs (measure_mono_null (fun x hx_mem => ?_) h') rw [Set.mem_setOf_eq, Set.indicator_of_mem hx_mem] #align measure_theory.snorm_ess_sup_indicator_const_eq MeasureTheory.snormEssSup_indicator_const_eq theorem snorm_indicator_le (f : α → E) : snorm (s.indicator f) p μ ≤ snorm f p μ := by refine snorm_mono_ae (eventually_of_forall fun x => ?_) suffices ‖s.indicator f x‖₊ ≤ ‖f x‖₊ by exact NNReal.coe_mono this rw [nnnorm_indicator_eq_indicator_nnnorm] exact s.indicator_le_self _ x #align measure_theory.snorm_indicator_le MeasureTheory.snorm_indicator_le theorem snorm_indicator_const₀ {c : G} (hs : NullMeasurableSet s μ) (hp : p ≠ 0) (hp_top : p ≠ ∞) : snorm (s.indicator fun _ => c) p μ = ‖c‖₊ * μ s ^ (1 / p.toReal) := have hp_pos : 0 < p.toReal := ENNReal.toReal_pos hp hp_top calc snorm (s.indicator fun _ => c) p μ = (∫⁻ x, ((‖(s.indicator fun _ ↦ c) x‖₊ : ℝ≥0∞) ^ p.toReal) ∂μ) ^ (1 / p.toReal) := snorm_eq_lintegral_rpow_nnnorm hp hp_top _ = (∫⁻ x, (s.indicator fun _ ↦ (‖c‖₊ : ℝ≥0∞) ^ p.toReal) x ∂μ) ^ (1 / p.toReal) := by congr 2 refine (Set.comp_indicator_const c (fun x : G ↦ (‖x‖₊ : ℝ≥0∞) ^ p.toReal) ?_) simp [hp_pos] _ = ‖c‖₊ * μ s ^ (1 / p.toReal) := by rw [lintegral_indicator_const₀ hs, ENNReal.mul_rpow_of_nonneg, ← ENNReal.rpow_mul, mul_one_div_cancel hp_pos.ne', ENNReal.rpow_one] positivity theorem snorm_indicator_const {c : G} (hs : MeasurableSet s) (hp : p ≠ 0) (hp_top : p ≠ ∞) : snorm (s.indicator fun _ => c) p μ = ‖c‖₊ * μ s ^ (1 / p.toReal) := snorm_indicator_const₀ hs.nullMeasurableSet hp hp_top #align measure_theory.snorm_indicator_const MeasureTheory.snorm_indicator_const theorem snorm_indicator_const' {c : G} (hs : MeasurableSet s) (hμs : μ s ≠ 0) (hp : p ≠ 0) : snorm (s.indicator fun _ => c) p μ = ‖c‖₊ * μ s ^ (1 / p.toReal) := by by_cases hp_top : p = ∞ · simp [hp_top, snormEssSup_indicator_const_eq s c hμs] · exact snorm_indicator_const hs hp hp_top #align measure_theory.snorm_indicator_const' MeasureTheory.snorm_indicator_const' theorem snorm_indicator_const_le (c : G) (p : ℝ≥0∞) : snorm (s.indicator fun _ => c) p μ ≤ ‖c‖₊ * μ s ^ (1 / p.toReal) := by rcases eq_or_ne p 0 with (rfl | hp) · simp only [snorm_exponent_zero, zero_le'] rcases eq_or_ne p ∞ with (rfl | h'p) · simp only [snorm_exponent_top, ENNReal.top_toReal, _root_.div_zero, ENNReal.rpow_zero, mul_one] exact snormEssSup_indicator_const_le _ _ let t := toMeasurable μ s calc snorm (s.indicator fun _ => c) p μ ≤ snorm (t.indicator fun _ => c) p μ := snorm_mono (norm_indicator_le_of_subset (subset_toMeasurable _ _) _) _ = ‖c‖₊ * μ t ^ (1 / p.toReal) := (snorm_indicator_const (measurableSet_toMeasurable _ _) hp h'p) _ = ‖c‖₊ * μ s ^ (1 / p.toReal) := by rw [measure_toMeasurable] #align measure_theory.snorm_indicator_const_le MeasureTheory.snorm_indicator_const_le theorem Memℒp.indicator (hs : MeasurableSet s) (hf : Memℒp f p μ) : Memℒp (s.indicator f) p μ := ⟨hf.aestronglyMeasurable.indicator hs, lt_of_le_of_lt (snorm_indicator_le f) hf.snorm_lt_top⟩ #align measure_theory.mem_ℒp.indicator MeasureTheory.Memℒp.indicator theorem snormEssSup_indicator_eq_snormEssSup_restrict {f : α → F} (hs : MeasurableSet s) : snormEssSup (s.indicator f) μ = snormEssSup f (μ.restrict s) := by simp_rw [snormEssSup, nnnorm_indicator_eq_indicator_nnnorm, ENNReal.coe_indicator, ENNReal.essSup_indicator_eq_essSup_restrict hs] #align measure_theory.snorm_ess_sup_indicator_eq_snorm_ess_sup_restrict MeasureTheory.snormEssSup_indicator_eq_snormEssSup_restrict theorem snorm_indicator_eq_snorm_restrict {f : α → F} (hs : MeasurableSet s) : snorm (s.indicator f) p μ = snorm f p (μ.restrict s) := by by_cases hp_zero : p = 0 · simp only [hp_zero, snorm_exponent_zero] by_cases hp_top : p = ∞ · simp_rw [hp_top, snorm_exponent_top] exact snormEssSup_indicator_eq_snormEssSup_restrict hs simp_rw [snorm_eq_lintegral_rpow_nnnorm hp_zero hp_top] suffices (∫⁻ x, (‖s.indicator f x‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) = ∫⁻ x in s, (‖f x‖₊ : ℝ≥0∞) ^ p.toReal ∂μ by rw [this] rw [← lintegral_indicator _ hs] congr simp_rw [nnnorm_indicator_eq_indicator_nnnorm, ENNReal.coe_indicator] have h_zero : (fun x => x ^ p.toReal) (0 : ℝ≥0∞) = 0 := by simp [ENNReal.toReal_pos hp_zero hp_top] -- Porting note: The implicit argument should be specified because the elaborator can't deal with -- `∘` well. exact (Set.indicator_comp_of_zero (g := fun x : ℝ≥0∞ => x ^ p.toReal) h_zero).symm #align measure_theory.snorm_indicator_eq_snorm_restrict MeasureTheory.snorm_indicator_eq_snorm_restrict theorem memℒp_indicator_iff_restrict (hs : MeasurableSet s) : Memℒp (s.indicator f) p μ ↔ Memℒp f p (μ.restrict s) := by simp [Memℒp, aestronglyMeasurable_indicator_iff hs, snorm_indicator_eq_snorm_restrict hs] #align measure_theory.mem_ℒp_indicator_iff_restrict MeasureTheory.memℒp_indicator_iff_restrict /-- If a function is supported on a finite-measure set and belongs to `ℒ^p`, then it belongs to `ℒ^q` for any `q ≤ p`. -/ theorem Memℒp.memℒp_of_exponent_le_of_measure_support_ne_top {p q : ℝ≥0∞} {f : α → E} (hfq : Memℒp f q μ) {s : Set α} (hf : ∀ x, x ∉ s → f x = 0) (hs : μ s ≠ ∞) (hpq : p ≤ q) : Memℒp f p μ := by have : (toMeasurable μ s).indicator f = f := by apply Set.indicator_eq_self.2 apply Function.support_subset_iff'.2 (fun x hx ↦ hf x ?_) contrapose! hx exact subset_toMeasurable μ s hx rw [← this, memℒp_indicator_iff_restrict (measurableSet_toMeasurable μ s)] at hfq ⊢ have : Fact (μ (toMeasurable μ s) < ∞) := ⟨by simpa [lt_top_iff_ne_top] using hs⟩ exact memℒp_of_exponent_le hfq hpq theorem memℒp_indicator_const (p : ℝ≥0∞) (hs : MeasurableSet s) (c : E) (hμsc : c = 0 ∨ μ s ≠ ∞) : Memℒp (s.indicator fun _ => c) p μ := by rw [memℒp_indicator_iff_restrict hs] rcases hμsc with rfl | hμ · exact zero_memℒp · have := Fact.mk hμ.lt_top apply memℒp_const #align measure_theory.mem_ℒp_indicator_const MeasureTheory.memℒp_indicator_const /-- The `ℒ^p` norm of the indicator of a set is uniformly small if the set itself has small measure, for any `p < ∞`. Given here as an existential `∀ ε > 0, ∃ η > 0, ...` to avoid later management of `ℝ≥0∞`-arithmetic. -/ theorem exists_snorm_indicator_le (hp : p ≠ ∞) (c : E) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ η : ℝ≥0, 0 < η ∧ ∀ s : Set α, μ s ≤ η → snorm (s.indicator fun _ => c) p μ ≤ ε := by rcases eq_or_ne p 0 with (rfl | h'p) · exact ⟨1, zero_lt_one, fun s _ => by simp⟩ have hp₀ : 0 < p := bot_lt_iff_ne_bot.2 h'p have hp₀' : 0 ≤ 1 / p.toReal := div_nonneg zero_le_one ENNReal.toReal_nonneg have hp₀'' : 0 < p.toReal := ENNReal.toReal_pos hp₀.ne' hp obtain ⟨η, hη_pos, hη_le⟩ : ∃ η : ℝ≥0, 0 < η ∧ (‖c‖₊ : ℝ≥0∞) * (η : ℝ≥0∞) ^ (1 / p.toReal) ≤ ε := by have : Filter.Tendsto (fun x : ℝ≥0 => ((‖c‖₊ * x ^ (1 / p.toReal) : ℝ≥0) : ℝ≥0∞)) (𝓝 0) (𝓝 (0 : ℝ≥0)) := by rw [ENNReal.tendsto_coe] convert (NNReal.continuousAt_rpow_const (Or.inr hp₀')).tendsto.const_mul _ simp [hp₀''.ne'] have hε' : 0 < ε := hε.bot_lt obtain ⟨δ, hδ, hδε'⟩ := NNReal.nhds_zero_basis.eventually_iff.mp (eventually_le_of_tendsto_lt hε' this) obtain ⟨η, hη, hηδ⟩ := exists_between hδ refine ⟨η, hη, ?_⟩ rw [ENNReal.coe_rpow_of_nonneg _ hp₀', ← ENNReal.coe_mul] exact hδε' hηδ refine ⟨η, hη_pos, fun s hs => ?_⟩ refine (snorm_indicator_const_le _ _).trans (le_trans ?_ hη_le) exact mul_le_mul_left' (ENNReal.rpow_le_rpow hs hp₀') _ #align measure_theory.exists_snorm_indicator_le MeasureTheory.exists_snorm_indicator_le protected lemma Memℒp.piecewise [DecidablePred (· ∈ s)] {g} (hs : MeasurableSet s) (hf : Memℒp f p (μ.restrict s)) (hg : Memℒp g p (μ.restrict sᶜ)) : Memℒp (s.piecewise f g) p μ := by by_cases hp_zero : p = 0 · simp only [hp_zero, memℒp_zero_iff_aestronglyMeasurable] exact AEStronglyMeasurable.piecewise hs hf.1 hg.1 refine ⟨AEStronglyMeasurable.piecewise hs hf.1 hg.1, ?_⟩ rcases eq_or_ne p ∞ with rfl | hp_top · rw [snorm_top_piecewise f g hs] exact max_lt hf.2 hg.2 rw [snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top hp_zero hp_top, ← lintegral_add_compl _ hs, ENNReal.add_lt_top] constructor · have h : ∀ᵐ (x : α) ∂μ, x ∈ s → (‖Set.piecewise s f g x‖₊ : ℝ≥0∞) ^ p.toReal = (‖f x‖₊ : ℝ≥0∞) ^ p.toReal := by filter_upwards with a ha using by simp [ha] rw [set_lintegral_congr_fun hs h] exact lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp_zero hp_top hf.2 · have h : ∀ᵐ (x : α) ∂μ, x ∈ sᶜ → (‖Set.piecewise s f g x‖₊ : ℝ≥0∞) ^ p.toReal = (‖g x‖₊ : ℝ≥0∞) ^ p.toReal := by filter_upwards with a ha have ha' : a ∉ s := ha simp [ha'] rw [set_lintegral_congr_fun hs.compl h] exact lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp_zero hp_top hg.2 end Indicator section IndicatorConstLp open Set Function variable {s : Set α} {hs : MeasurableSet s} {hμs : μ s ≠ ∞} {c : E} /-- Indicator of a set as an element of `Lp`. -/ def indicatorConstLp (p : ℝ≥0∞) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : E) : Lp E p μ := Memℒp.toLp (s.indicator fun _ => c) (memℒp_indicator_const p hs c (Or.inr hμs)) #align measure_theory.indicator_const_Lp MeasureTheory.indicatorConstLp /-- A version of `Set.indicator_add` for `MeasureTheory.indicatorConstLp`.-/ theorem indicatorConstLp_add {c' : E} : indicatorConstLp p hs hμs c + indicatorConstLp p hs hμs c' = indicatorConstLp p hs hμs (c + c') := by simp_rw [indicatorConstLp, ← Memℒp.toLp_add, indicator_add] rfl /-- A version of `Set.indicator_sub` for `MeasureTheory.indicatorConstLp`.-/ theorem indicatorConstLp_sub {c' : E} : indicatorConstLp p hs hμs c - indicatorConstLp p hs hμs c' = indicatorConstLp p hs hμs (c - c') := by simp_rw [indicatorConstLp, ← Memℒp.toLp_sub, indicator_sub] rfl theorem indicatorConstLp_coeFn : ⇑(indicatorConstLp p hs hμs c) =ᵐ[μ] s.indicator fun _ => c := Memℒp.coeFn_toLp (memℒp_indicator_const p hs c (Or.inr hμs)) #align measure_theory.indicator_const_Lp_coe_fn MeasureTheory.indicatorConstLp_coeFn theorem indicatorConstLp_coeFn_mem : ∀ᵐ x : α ∂μ, x ∈ s → indicatorConstLp p hs hμs c x = c := indicatorConstLp_coeFn.mono fun _x hx hxs => hx.trans (Set.indicator_of_mem hxs _) #align measure_theory.indicator_const_Lp_coe_fn_mem MeasureTheory.indicatorConstLp_coeFn_mem theorem indicatorConstLp_coeFn_nmem : ∀ᵐ x : α ∂μ, x ∉ s → indicatorConstLp p hs hμs c x = 0 := indicatorConstLp_coeFn.mono fun _x hx hxs => hx.trans (Set.indicator_of_not_mem hxs _) #align measure_theory.indicator_const_Lp_coe_fn_nmem MeasureTheory.indicatorConstLp_coeFn_nmem theorem norm_indicatorConstLp (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : ‖indicatorConstLp p hs hμs c‖ = ‖c‖ * (μ s).toReal ^ (1 / p.toReal) := by rw [Lp.norm_def, snorm_congr_ae indicatorConstLp_coeFn, snorm_indicator_const hs hp_ne_zero hp_ne_top, ENNReal.toReal_mul, ENNReal.toReal_rpow, ENNReal.coe_toReal, coe_nnnorm] #align measure_theory.norm_indicator_const_Lp MeasureTheory.norm_indicatorConstLp theorem norm_indicatorConstLp_top (hμs_ne_zero : μ s ≠ 0) : ‖indicatorConstLp ∞ hs hμs c‖ = ‖c‖ := by rw [Lp.norm_def, snorm_congr_ae indicatorConstLp_coeFn, snorm_indicator_const' hs hμs_ne_zero ENNReal.top_ne_zero, ENNReal.top_toReal, _root_.div_zero, ENNReal.rpow_zero, mul_one, ENNReal.coe_toReal, coe_nnnorm] #align measure_theory.norm_indicator_const_Lp_top MeasureTheory.norm_indicatorConstLp_top theorem norm_indicatorConstLp' (hp_pos : p ≠ 0) (hμs_pos : μ s ≠ 0) : ‖indicatorConstLp p hs hμs c‖ = ‖c‖ * (μ s).toReal ^ (1 / p.toReal) := by by_cases hp_top : p = ∞ · rw [hp_top, ENNReal.top_toReal, _root_.div_zero, Real.rpow_zero, mul_one] exact norm_indicatorConstLp_top hμs_pos · exact norm_indicatorConstLp hp_pos hp_top #align measure_theory.norm_indicator_const_Lp' MeasureTheory.norm_indicatorConstLp' theorem norm_indicatorConstLp_le : ‖indicatorConstLp p hs hμs c‖ ≤ ‖c‖ * (μ s).toReal ^ (1 / p.toReal) := by rw [indicatorConstLp, Lp.norm_toLp] refine ENNReal.toReal_le_of_le_ofReal (by positivity) ?_ refine (snorm_indicator_const_le _ _).trans_eq ?_ rw [← coe_nnnorm, ENNReal.ofReal_mul (NNReal.coe_nonneg _), ENNReal.ofReal_coe_nnreal, ENNReal.toReal_rpow, ENNReal.ofReal_toReal] exact ENNReal.rpow_ne_top_of_nonneg (by positivity) hμs theorem edist_indicatorConstLp_eq_nnnorm {t : Set α} {ht : MeasurableSet t} {hμt : μ t ≠ ∞} : edist (indicatorConstLp p hs hμs c) (indicatorConstLp p ht hμt c) = ‖indicatorConstLp p (hs.symmDiff ht) (measure_symmDiff_ne_top hμs hμt) c‖₊ := by unfold indicatorConstLp rw [Lp.edist_toLp_toLp, snorm_indicator_sub_indicator, Lp.coe_nnnorm_toLp]
Mathlib/MeasureTheory/Function/LpSpace.lean
828
831
theorem dist_indicatorConstLp_eq_norm {t : Set α} {ht : MeasurableSet t} {hμt : μ t ≠ ∞} : dist (indicatorConstLp p hs hμs c) (indicatorConstLp p ht hμt c) = ‖indicatorConstLp p (hs.symmDiff ht) (measure_symmDiff_ne_top hμs hμt) c‖ := by
rw [Lp.dist_edist, edist_indicatorConstLp_eq_nnnorm, ENNReal.coe_toReal, Lp.coe_nnnorm]
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Mario Carneiro, Sean Leather -/ import Mathlib.Data.Finset.Card #align_import data.finset.option from "leanprover-community/mathlib"@"c227d107bbada5d0d9d20287e3282c0a7f1651a0" /-! # Finite sets in `Option α` In this file we define * `Option.toFinset`: construct an empty or singleton `Finset α` from an `Option α`; * `Finset.insertNone`: given `s : Finset α`, lift it to a finset on `Option α` using `Option.some` and then insert `Option.none`; * `Finset.eraseNone`: given `s : Finset (Option α)`, returns `t : Finset α` such that `x ∈ t ↔ some x ∈ s`. Then we prove some basic lemmas about these definitions. ## Tags finset, option -/ variable {α β : Type*} open Function namespace Option /-- Construct an empty or singleton finset from an `Option` -/ def toFinset (o : Option α) : Finset α := o.elim ∅ singleton #align option.to_finset Option.toFinset @[simp] theorem toFinset_none : none.toFinset = (∅ : Finset α) := rfl #align option.to_finset_none Option.toFinset_none @[simp] theorem toFinset_some {a : α} : (some a).toFinset = {a} := rfl #align option.to_finset_some Option.toFinset_some @[simp] theorem mem_toFinset {a : α} {o : Option α} : a ∈ o.toFinset ↔ a ∈ o := by cases o <;> simp [eq_comm] #align option.mem_to_finset Option.mem_toFinset theorem card_toFinset (o : Option α) : o.toFinset.card = o.elim 0 1 := by cases o <;> rfl #align option.card_to_finset Option.card_toFinset end Option namespace Finset /-- Given a finset on `α`, lift it to being a finset on `Option α` using `Option.some` and then insert `Option.none`. -/ def insertNone : Finset α ↪o Finset (Option α) := (OrderEmbedding.ofMapLEIff fun s => cons none (s.map Embedding.some) <| by simp) fun s t => by rw [le_iff_subset, cons_subset_cons, map_subset_map, le_iff_subset] #align finset.insert_none Finset.insertNone @[simp] theorem mem_insertNone {s : Finset α} : ∀ {o : Option α}, o ∈ insertNone s ↔ ∀ a ∈ o, a ∈ s | none => iff_of_true (Multiset.mem_cons_self _ _) fun a h => by cases h | some a => Multiset.mem_cons.trans <| by simp #align finset.mem_insert_none Finset.mem_insertNone lemma forall_mem_insertNone {s : Finset α} {p : Option α → Prop} : (∀ a ∈ insertNone s, p a) ↔ p none ∧ ∀ a ∈ s, p a := by simp [Option.forall] theorem some_mem_insertNone {s : Finset α} {a : α} : some a ∈ insertNone s ↔ a ∈ s := by simp #align finset.some_mem_insert_none Finset.some_mem_insertNone lemma none_mem_insertNone {s : Finset α} : none ∈ insertNone s := by simp @[aesop safe apply (rule_sets := [finsetNonempty])] lemma insertNone_nonempty {s : Finset α} : insertNone s |>.Nonempty := ⟨none, none_mem_insertNone⟩ @[simp] theorem card_insertNone (s : Finset α) : s.insertNone.card = s.card + 1 := by simp [insertNone] #align finset.card_insert_none Finset.card_insertNone /-- Given `s : Finset (Option α)`, `eraseNone s : Finset α` is the set of `x : α` such that `some x ∈ s`. -/ def eraseNone : Finset (Option α) →o Finset α := (Finset.mapEmbedding (Equiv.optionIsSomeEquiv α).toEmbedding).toOrderHom.comp ⟨Finset.subtype _, subtype_mono⟩ #align finset.erase_none Finset.eraseNone @[simp] theorem mem_eraseNone {s : Finset (Option α)} {x : α} : x ∈ eraseNone s ↔ some x ∈ s := by simp [eraseNone] #align finset.mem_erase_none Finset.mem_eraseNone lemma forall_mem_eraseNone {s : Finset (Option α)} {p : Option α → Prop} : (∀ a ∈ eraseNone s, p a) ↔ ∀ a : α, (a : Option α) ∈ s → p a := by simp [Option.forall] theorem eraseNone_eq_biUnion [DecidableEq α] (s : Finset (Option α)) : eraseNone s = s.biUnion Option.toFinset := by ext simp #align finset.erase_none_eq_bUnion Finset.eraseNone_eq_biUnion @[simp] theorem eraseNone_map_some (s : Finset α) : eraseNone (s.map Embedding.some) = s := by ext simp #align finset.erase_none_map_some Finset.eraseNone_map_some @[simp] theorem eraseNone_image_some [DecidableEq (Option α)] (s : Finset α) : eraseNone (s.image some) = s := by simpa only [map_eq_image] using eraseNone_map_some s #align finset.erase_none_image_some Finset.eraseNone_image_some @[simp] theorem coe_eraseNone (s : Finset (Option α)) : (eraseNone s : Set α) = some ⁻¹' s := Set.ext fun _ => mem_eraseNone #align finset.coe_erase_none Finset.coe_eraseNone @[simp] theorem eraseNone_union [DecidableEq (Option α)] [DecidableEq α] (s t : Finset (Option α)) : eraseNone (s ∪ t) = eraseNone s ∪ eraseNone t := by ext simp #align finset.erase_none_union Finset.eraseNone_union @[simp] theorem eraseNone_inter [DecidableEq (Option α)] [DecidableEq α] (s t : Finset (Option α)) : eraseNone (s ∩ t) = eraseNone s ∩ eraseNone t := by ext simp #align finset.erase_none_inter Finset.eraseNone_inter @[simp] theorem eraseNone_empty : eraseNone (∅ : Finset (Option α)) = ∅ := by ext simp #align finset.erase_none_empty Finset.eraseNone_empty @[simp]
Mathlib/Data/Finset/Option.lean
148
150
theorem eraseNone_none : eraseNone ({none} : Finset (Option α)) = ∅ := by
ext simp
/- Copyright (c) 2021 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Star.Subalgebra import Mathlib.RingTheory.Ideal.Maps import Mathlib.Tactic.NoncommRing #align_import algebra.algebra.spectrum from "leanprover-community/mathlib"@"58a272265b5e05f258161260dd2c5d247213cbd3" /-! # Spectrum of an element in an algebra This file develops the basic theory of the spectrum of an element of an algebra. This theory will serve as the foundation for spectral theory in Banach algebras. ## Main definitions * `resolventSet a : Set R`: the resolvent set of an element `a : A` where `A` is an `R`-algebra. * `spectrum a : Set R`: the spectrum of an element `a : A` where `A` is an `R`-algebra. * `resolvent : R → A`: the resolvent function is `fun r ↦ Ring.inverse (↑ₐr - a)`, and hence when `r ∈ resolvent R A`, it is actually the inverse of the unit `(↑ₐr - a)`. ## Main statements * `spectrum.unit_smul_eq_smul` and `spectrum.smul_eq_smul`: units in the scalar ring commute (multiplication) with the spectrum, and over a field even `0` commutes with the spectrum. * `spectrum.left_add_coset_eq`: elements of the scalar ring commute (addition) with the spectrum. * `spectrum.unit_mem_mul_iff_mem_swap_mul` and `spectrum.preimage_units_mul_eq_swap_mul`: the units (of `R`) in `σ (a*b)` coincide with those in `σ (b*a)`. * `spectrum.scalar_eq`: in a nontrivial algebra over a field, the spectrum of a scalar is a singleton. ## Notations * `σ a` : `spectrum R a` of `a : A` -/ open Set open scoped Pointwise universe u v section Defs variable (R : Type u) {A : Type v} variable [CommSemiring R] [Ring A] [Algebra R A] local notation "↑ₐ" => algebraMap R A -- definition and basic properties /-- Given a commutative ring `R` and an `R`-algebra `A`, the *resolvent set* of `a : A` is the `Set R` consisting of those `r : R` for which `r•1 - a` is a unit of the algebra `A`. -/ def resolventSet (a : A) : Set R := {r : R | IsUnit (↑ₐ r - a)} #align resolvent_set resolventSet /-- Given a commutative ring `R` and an `R`-algebra `A`, the *spectrum* of `a : A` is the `Set R` consisting of those `r : R` for which `r•1 - a` is not a unit of the algebra `A`. The spectrum is simply the complement of the resolvent set. -/ def spectrum (a : A) : Set R := (resolventSet R a)ᶜ #align spectrum spectrum variable {R} /-- Given an `a : A` where `A` is an `R`-algebra, the *resolvent* is a map `R → A` which sends `r : R` to `(algebraMap R A r - a)⁻¹` when `r ∈ resolvent R A` and `0` when `r ∈ spectrum R A`. -/ noncomputable def resolvent (a : A) (r : R) : A := Ring.inverse (↑ₐ r - a) #align resolvent resolvent /-- The unit `1 - r⁻¹ • a` constructed from `r • 1 - a` when the latter is a unit. -/ @[simps] noncomputable def IsUnit.subInvSMul {r : Rˣ} {s : R} {a : A} (h : IsUnit <| r • ↑ₐ s - a) : Aˣ where val := ↑ₐ s - r⁻¹ • a inv := r • ↑h.unit⁻¹ val_inv := by rw [mul_smul_comm, ← smul_mul_assoc, smul_sub, smul_inv_smul, h.mul_val_inv] inv_val := by rw [smul_mul_assoc, ← mul_smul_comm, smul_sub, smul_inv_smul, h.val_inv_mul] #align is_unit.sub_inv_smul IsUnit.subInvSMul #align is_unit.coe_sub_inv_smul IsUnit.val_subInvSMul #align is_unit.coe_inv_sub_inv_smul IsUnit.val_inv_subInvSMul end Defs namespace spectrum section ScalarSemiring variable {R : Type u} {A : Type v} variable [CommSemiring R] [Ring A] [Algebra R A] local notation "σ" => spectrum R local notation "↑ₐ" => algebraMap R A theorem mem_iff {r : R} {a : A} : r ∈ σ a ↔ ¬IsUnit (↑ₐ r - a) := Iff.rfl #align spectrum.mem_iff spectrum.mem_iff theorem not_mem_iff {r : R} {a : A} : r ∉ σ a ↔ IsUnit (↑ₐ r - a) := by apply not_iff_not.mp simp [Set.not_not_mem, mem_iff] #align spectrum.not_mem_iff spectrum.not_mem_iff variable (R) theorem zero_mem_iff {a : A} : (0 : R) ∈ σ a ↔ ¬IsUnit a := by rw [mem_iff, map_zero, zero_sub, IsUnit.neg_iff] #align spectrum.zero_mem_iff spectrum.zero_mem_iff alias ⟨not_isUnit_of_zero_mem, zero_mem⟩ := spectrum.zero_mem_iff theorem zero_not_mem_iff {a : A} : (0 : R) ∉ σ a ↔ IsUnit a := by rw [zero_mem_iff, Classical.not_not] #align spectrum.zero_not_mem_iff spectrum.zero_not_mem_iff alias ⟨isUnit_of_zero_not_mem, zero_not_mem⟩ := spectrum.zero_not_mem_iff lemma subset_singleton_zero_compl {a : A} (ha : IsUnit a) : spectrum R a ⊆ {0}ᶜ := Set.subset_compl_singleton_iff.mpr <| spectrum.zero_not_mem R ha variable {R} theorem mem_resolventSet_of_left_right_inverse {r : R} {a b c : A} (h₁ : (↑ₐ r - a) * b = 1) (h₂ : c * (↑ₐ r - a) = 1) : r ∈ resolventSet R a := Units.isUnit ⟨↑ₐ r - a, b, h₁, by rwa [← left_inv_eq_right_inv h₂ h₁]⟩ #align spectrum.mem_resolvent_set_of_left_right_inverse spectrum.mem_resolventSet_of_left_right_inverse theorem mem_resolventSet_iff {r : R} {a : A} : r ∈ resolventSet R a ↔ IsUnit (↑ₐ r - a) := Iff.rfl #align spectrum.mem_resolvent_set_iff spectrum.mem_resolventSet_iff @[simp] theorem algebraMap_mem_iff (S : Type*) {R A : Type*} [CommSemiring R] [CommSemiring S] [Ring A] [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] {a : A} {r : R} : algebraMap R S r ∈ spectrum S a ↔ r ∈ spectrum R a := by simp only [spectrum.mem_iff, Algebra.algebraMap_eq_smul_one, smul_assoc, one_smul] protected alias ⟨of_algebraMap_mem, algebraMap_mem⟩ := spectrum.algebraMap_mem_iff @[simp] theorem preimage_algebraMap (S : Type*) {R A : Type*} [CommSemiring R] [CommSemiring S] [Ring A] [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] {a : A} : algebraMap R S ⁻¹' spectrum S a = spectrum R a := Set.ext fun _ => spectrum.algebraMap_mem_iff _ @[simp] theorem resolventSet_of_subsingleton [Subsingleton A] (a : A) : resolventSet R a = Set.univ := by simp_rw [resolventSet, Subsingleton.elim (algebraMap R A _ - a) 1, isUnit_one, Set.setOf_true] #align spectrum.resolvent_set_of_subsingleton spectrum.resolventSet_of_subsingleton @[simp] theorem of_subsingleton [Subsingleton A] (a : A) : spectrum R a = ∅ := by rw [spectrum, resolventSet_of_subsingleton, Set.compl_univ] #align spectrum.of_subsingleton spectrum.of_subsingleton theorem resolvent_eq {a : A} {r : R} (h : r ∈ resolventSet R a) : resolvent a r = ↑h.unit⁻¹ := Ring.inverse_unit h.unit #align spectrum.resolvent_eq spectrum.resolvent_eq theorem units_smul_resolvent {r : Rˣ} {s : R} {a : A} : r • resolvent a (s : R) = resolvent (r⁻¹ • a) (r⁻¹ • s : R) := by by_cases h : s ∈ spectrum R a · rw [mem_iff] at h simp only [resolvent, Algebra.algebraMap_eq_smul_one] at * rw [smul_assoc, ← smul_sub] have h' : ¬IsUnit (r⁻¹ • (s • (1 : A) - a)) := fun hu => h (by simpa only [smul_inv_smul] using IsUnit.smul r hu) simp only [Ring.inverse_non_unit _ h, Ring.inverse_non_unit _ h', smul_zero] · simp only [resolvent] have h' : IsUnit (r • algebraMap R A (r⁻¹ • s) - a) := by simpa [Algebra.algebraMap_eq_smul_one, smul_assoc] using not_mem_iff.mp h rw [← h'.val_subInvSMul, ← (not_mem_iff.mp h).unit_spec, Ring.inverse_unit, Ring.inverse_unit, h'.val_inv_subInvSMul] simp only [Algebra.algebraMap_eq_smul_one, smul_assoc, smul_inv_smul] #align spectrum.units_smul_resolvent spectrum.units_smul_resolvent theorem units_smul_resolvent_self {r : Rˣ} {a : A} : r • resolvent a (r : R) = resolvent (r⁻¹ • a) (1 : R) := by simpa only [Units.smul_def, Algebra.id.smul_eq_mul, Units.inv_mul] using @units_smul_resolvent _ _ _ _ _ r r a #align spectrum.units_smul_resolvent_self spectrum.units_smul_resolvent_self /-- The resolvent is a unit when the argument is in the resolvent set. -/ theorem isUnit_resolvent {r : R} {a : A} : r ∈ resolventSet R a ↔ IsUnit (resolvent a r) := isUnit_ring_inverse.symm #align spectrum.is_unit_resolvent spectrum.isUnit_resolvent theorem inv_mem_resolventSet {r : Rˣ} {a : Aˣ} (h : (r : R) ∈ resolventSet R (a : A)) : (↑r⁻¹ : R) ∈ resolventSet R (↑a⁻¹ : A) := by rw [mem_resolventSet_iff, Algebra.algebraMap_eq_smul_one, ← Units.smul_def] at h ⊢ rw [IsUnit.smul_sub_iff_sub_inv_smul, inv_inv, IsUnit.sub_iff] have h₁ : (a : A) * (r • (↑a⁻¹ : A) - 1) = r • (1 : A) - a := by rw [mul_sub, mul_smul_comm, a.mul_inv, mul_one] have h₂ : (r • (↑a⁻¹ : A) - 1) * a = r • (1 : A) - a := by rw [sub_mul, smul_mul_assoc, a.inv_mul, one_mul] have hcomm : Commute (a : A) (r • (↑a⁻¹ : A) - 1) := by rwa [← h₂] at h₁ exact (hcomm.isUnit_mul_iff.mp (h₁.symm ▸ h)).2 #align spectrum.inv_mem_resolvent_set spectrum.inv_mem_resolventSet theorem inv_mem_iff {r : Rˣ} {a : Aˣ} : (r : R) ∈ σ (a : A) ↔ (↑r⁻¹ : R) ∈ σ (↑a⁻¹ : A) := not_iff_not.2 <| ⟨inv_mem_resolventSet, inv_mem_resolventSet⟩ #align spectrum.inv_mem_iff spectrum.inv_mem_iff theorem zero_mem_resolventSet_of_unit (a : Aˣ) : 0 ∈ resolventSet R (a : A) := by simpa only [mem_resolventSet_iff, ← not_mem_iff, zero_not_mem_iff] using a.isUnit #align spectrum.zero_mem_resolvent_set_of_unit spectrum.zero_mem_resolventSet_of_unit theorem ne_zero_of_mem_of_unit {a : Aˣ} {r : R} (hr : r ∈ σ (a : A)) : r ≠ 0 := fun hn => (hn ▸ hr) (zero_mem_resolventSet_of_unit a) #align spectrum.ne_zero_of_mem_of_unit spectrum.ne_zero_of_mem_of_unit theorem add_mem_iff {a : A} {r s : R} : r + s ∈ σ a ↔ r ∈ σ (-↑ₐ s + a) := by simp only [mem_iff, sub_neg_eq_add, ← sub_sub, map_add] #align spectrum.add_mem_iff spectrum.add_mem_iff theorem add_mem_add_iff {a : A} {r s : R} : r + s ∈ σ (↑ₐ s + a) ↔ r ∈ σ a := by rw [add_mem_iff, neg_add_cancel_left] #align spectrum.add_mem_add_iff spectrum.add_mem_add_iff theorem smul_mem_smul_iff {a : A} {s : R} {r : Rˣ} : r • s ∈ σ (r • a) ↔ s ∈ σ a := by simp only [mem_iff, not_iff_not, Algebra.algebraMap_eq_smul_one, smul_assoc, ← smul_sub, isUnit_smul_iff] #align spectrum.smul_mem_smul_iff spectrum.smul_mem_smul_iff theorem unit_smul_eq_smul (a : A) (r : Rˣ) : σ (r • a) = r • σ a := by ext x have x_eq : x = r • r⁻¹ • x := by simp nth_rw 1 [x_eq] rw [smul_mem_smul_iff] constructor · exact fun h => ⟨r⁻¹ • x, ⟨h, show r • r⁻¹ • x = x by simp⟩⟩ · rintro ⟨w, _, (x'_eq : r • w = x)⟩ simpa [← x'_eq ] #align spectrum.unit_smul_eq_smul spectrum.unit_smul_eq_smul -- `r ∈ σ(a*b) ↔ r ∈ σ(b*a)` for any `r : Rˣ` theorem unit_mem_mul_iff_mem_swap_mul {a b : A} {r : Rˣ} : ↑r ∈ σ (a * b) ↔ ↑r ∈ σ (b * a) := by have h₁ : ∀ x y : A, IsUnit (1 - x * y) → IsUnit (1 - y * x) := by refine fun x y h => ⟨⟨1 - y * x, 1 + y * h.unit.inv * x, ?_, ?_⟩, rfl⟩ · calc (1 - y * x) * (1 + y * (IsUnit.unit h).inv * x) = 1 - y * x + y * ((1 - x * y) * h.unit.inv) * x := by noncomm_ring _ = 1 := by simp only [Units.inv_eq_val_inv, IsUnit.mul_val_inv, mul_one, sub_add_cancel] · calc (1 + y * (IsUnit.unit h).inv * x) * (1 - y * x) = 1 - y * x + y * (h.unit.inv * (1 - x * y)) * x := by noncomm_ring _ = 1 := by simp only [Units.inv_eq_val_inv, IsUnit.val_inv_mul, mul_one, sub_add_cancel] have := Iff.intro (h₁ (r⁻¹ • a) b) (h₁ b (r⁻¹ • a)) rw [mul_smul_comm r⁻¹ b a] at this simpa only [mem_iff, not_iff_not, Algebra.algebraMap_eq_smul_one, ← Units.smul_def, IsUnit.smul_sub_iff_sub_inv_smul, smul_mul_assoc] #align spectrum.unit_mem_mul_iff_mem_swap_mul spectrum.unit_mem_mul_iff_mem_swap_mul theorem preimage_units_mul_eq_swap_mul {a b : A} : ((↑) : Rˣ → R) ⁻¹' σ (a * b) = (↑) ⁻¹' σ (b * a) := Set.ext fun _ => unit_mem_mul_iff_mem_swap_mul #align spectrum.preimage_units_mul_eq_swap_mul spectrum.preimage_units_mul_eq_swap_mul section Star variable [InvolutiveStar R] [StarRing A] [StarModule R A] theorem star_mem_resolventSet_iff {r : R} {a : A} : star r ∈ resolventSet R a ↔ r ∈ resolventSet R (star a) := by refine ⟨fun h => ?_, fun h => ?_⟩ <;> simpa only [mem_resolventSet_iff, Algebra.algebraMap_eq_smul_one, star_sub, star_smul, star_star, star_one] using IsUnit.star h #align spectrum.star_mem_resolvent_set_iff spectrum.star_mem_resolventSet_iff protected theorem map_star (a : A) : σ (star a) = star (σ a) := by ext simpa only [Set.mem_star, mem_iff, not_iff_not] using star_mem_resolventSet_iff.symm #align spectrum.map_star spectrum.map_star end Star end ScalarSemiring section ScalarRing variable {R : Type u} {A : Type v} variable [CommRing R] [Ring A] [Algebra R A] local notation "σ" => spectrum R local notation "↑ₐ" => algebraMap R A -- it would be nice to state this for `subalgebra_class`, but we don't have such a thing yet theorem subset_subalgebra {S : Subalgebra R A} (a : S) : spectrum R (a : A) ⊆ spectrum R a := compl_subset_compl.2 fun _ => IsUnit.map S.val #align spectrum.subset_subalgebra spectrum.subset_subalgebra -- this is why it would be nice if `subset_subalgebra` was registered for `subalgebra_class`. theorem subset_starSubalgebra [StarRing R] [StarRing A] [StarModule R A] {S : StarSubalgebra R A} (a : S) : spectrum R (a : A) ⊆ spectrum R a := compl_subset_compl.2 fun _ => IsUnit.map S.subtype #align spectrum.subset_star_subalgebra spectrum.subset_starSubalgebra theorem singleton_add_eq (a : A) (r : R) : {r} + σ a = σ (↑ₐ r + a) := ext fun x => by rw [singleton_add, image_add_left, mem_preimage, add_comm, add_mem_iff, map_neg, neg_neg] #align spectrum.singleton_add_eq spectrum.singleton_add_eq theorem add_singleton_eq (a : A) (r : R) : σ a + {r} = σ (a + ↑ₐ r) := add_comm {r} (σ a) ▸ add_comm (algebraMap R A r) a ▸ singleton_add_eq a r #align spectrum.add_singleton_eq spectrum.add_singleton_eq theorem vadd_eq (a : A) (r : R) : r +ᵥ σ a = σ (↑ₐ r + a) := singleton_add.symm.trans <| singleton_add_eq a r #align spectrum.vadd_eq spectrum.vadd_eq theorem neg_eq (a : A) : -σ a = σ (-a) := Set.ext fun x => by simp only [mem_neg, mem_iff, map_neg, ← neg_add', IsUnit.neg_iff, sub_neg_eq_add] #align spectrum.neg_eq spectrum.neg_eq theorem singleton_sub_eq (a : A) (r : R) : {r} - σ a = σ (↑ₐ r - a) := by rw [sub_eq_add_neg, neg_eq, singleton_add_eq, sub_eq_add_neg] #align spectrum.singleton_sub_eq spectrum.singleton_sub_eq theorem sub_singleton_eq (a : A) (r : R) : σ a - {r} = σ (a - ↑ₐ r) := by simpa only [neg_sub, neg_eq] using congr_arg Neg.neg (singleton_sub_eq a r) #align spectrum.sub_singleton_eq spectrum.sub_singleton_eq end ScalarRing section ScalarField variable {𝕜 : Type u} {A : Type v} variable [Field 𝕜] [Ring A] [Algebra 𝕜 A] local notation "σ" => spectrum 𝕜 local notation "↑ₐ" => algebraMap 𝕜 A /-- Without the assumption `Nontrivial A`, then `0 : A` would be invertible. -/ @[simp] theorem zero_eq [Nontrivial A] : σ (0 : A) = {0} := by refine Set.Subset.antisymm ?_ (by simp [Algebra.algebraMap_eq_smul_one, mem_iff]) rw [spectrum, Set.compl_subset_comm] intro k hk rw [Set.mem_compl_singleton_iff] at hk have : IsUnit (Units.mk0 k hk • (1 : A)) := IsUnit.smul (Units.mk0 k hk) isUnit_one simpa [mem_resolventSet_iff, Algebra.algebraMap_eq_smul_one] #align spectrum.zero_eq spectrum.zero_eq @[simp] theorem scalar_eq [Nontrivial A] (k : 𝕜) : σ (↑ₐ k) = {k} := by rw [← add_zero (↑ₐ k), ← singleton_add_eq, zero_eq, Set.singleton_add_singleton, add_zero] #align spectrum.scalar_eq spectrum.scalar_eq @[simp]
Mathlib/Algebra/Algebra/Spectrum.lean
363
366
theorem one_eq [Nontrivial A] : σ (1 : A) = {1} := calc σ (1 : A) = σ (↑ₐ 1) := by
rw [Algebra.algebraMap_eq_smul_one, one_smul] _ = {1} := scalar_eq 1
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Complex import Qq #align_import analysis.special_functions.pow.real from "leanprover-community/mathlib"@"4fa54b337f7d52805480306db1b1439c741848c8" /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open scoped Classical open Real ComplexConjugate open Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for `y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : ℂ) ^ (y : ℂ)).re #align real.rpow Real.rpow noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl #align real.rpow_eq_pow Real.rpow_eq_pow theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl #align real.rpow_def Real.rpow_def theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, -RCLike.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] #align real.rpow_def_of_nonneg Real.rpow_def_of_nonneg theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] #align real.rpow_def_of_pos Real.rpow_def_of_pos theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] #align real.exp_mul Real.exp_mul @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] #align real.rpow_int_cast Real.rpow_intCast @[deprecated (since := "2024-04-17")] alias rpow_int_cast := rpow_intCast @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n #align real.rpow_nat_cast Real.rpow_natCast @[deprecated (since := "2024-04-17")] alias rpow_nat_cast := rpow_natCast @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] #align real.exp_one_rpow Real.exp_one_rpow @[simp] lemma exp_one_pow (n : ℕ) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] #align real.rpow_eq_zero_iff_of_nonneg Real.rpow_eq_zero_iff_of_nonneg @[simp] lemma rpow_eq_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] @[simp] lemma rpow_ne_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 := Real.rpow_eq_zero hx hy |>.not open Real theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) := by rw [rpow_def, Complex.cpow_def, if_neg] · have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * π) * Complex.I := by simp only [Complex.log, abs_of_neg hx, Complex.arg_ofReal_of_neg hx, Complex.abs_ofReal, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring · rw [Complex.ofReal_eq_zero] exact ne_of_lt hx #align real.rpow_def_of_neg Real.rpow_def_of_neg theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * π) := by split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _ #align real.rpow_def_of_nonpos Real.rpow_def_of_nonpos theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos #align real.rpow_pos_of_pos Real.rpow_pos_of_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] #align real.rpow_zero Real.rpow_zero theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp @[simp] theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *] #align real.zero_rpow Real.zero_rpow theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor · intro hyp simp only [rpow_def, Complex.ofReal_zero] at hyp by_cases h : x = 0 · subst h simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp exact Or.inr ⟨rfl, hyp.symm⟩ · rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp exact Or.inl ⟨h, hyp.symm⟩ · rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) · exact zero_rpow h · exact rpow_zero _ #align real.zero_rpow_eq_iff Real.zero_rpow_eq_iff theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_rpow_eq_iff, eq_comm] #align real.eq_zero_rpow_iff Real.eq_zero_rpow_iff @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] #align real.rpow_one Real.rpow_one @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def] #align real.one_rpow Real.one_rpow theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 := by by_cases h : x = 0 <;> simp [h, zero_le_one] #align real.zero_rpow_le_one Real.zero_rpow_le_one theorem zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x := by by_cases h : x = 0 <;> simp [h, zero_le_one] #align real.zero_rpow_nonneg Real.zero_rpow_nonneg theorem rpow_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y := by rw [rpow_def_of_nonneg hx]; split_ifs <;> simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)] #align real.rpow_nonneg_of_nonneg Real.rpow_nonneg theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : |x ^ y| = |x| ^ y := by have h_rpow_nonneg : 0 ≤ x ^ y := Real.rpow_nonneg hx_nonneg _ rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg] #align real.abs_rpow_of_nonneg Real.abs_rpow_of_nonneg theorem abs_rpow_le_abs_rpow (x y : ℝ) : |x ^ y| ≤ |x| ^ y := by rcases le_or_lt 0 x with hx | hx · rw [abs_rpow_of_nonneg hx] · rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log, abs_mul, abs_of_pos (exp_pos _)] exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _) #align real.abs_rpow_le_abs_rpow Real.abs_rpow_le_abs_rpow theorem abs_rpow_le_exp_log_mul (x y : ℝ) : |x ^ y| ≤ exp (log x * y) := by refine (abs_rpow_le_abs_rpow x y).trans ?_ by_cases hx : x = 0 · by_cases hy : y = 0 <;> simp [hx, hy, zero_le_one] · rw [rpow_def_of_pos (abs_pos.2 hx), log_abs] #align real.abs_rpow_le_exp_log_mul Real.abs_rpow_le_exp_log_mul theorem norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : ‖x ^ y‖ = ‖x‖ ^ y := by simp_rw [Real.norm_eq_abs] exact abs_rpow_of_nonneg hx_nonneg #align real.norm_rpow_of_nonneg Real.norm_rpow_of_nonneg variable {w x y z : ℝ} theorem rpow_add (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := by simp only [rpow_def_of_pos hx, mul_add, exp_add] #align real.rpow_add Real.rpow_add theorem rpow_add' (hx : 0 ≤ x) (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := by rcases hx.eq_or_lt with (rfl | pos) · rw [zero_rpow h, zero_eq_mul] have : y ≠ 0 ∨ z ≠ 0 := not_and_or.1 fun ⟨hy, hz⟩ => h <| hy.symm ▸ hz.symm ▸ zero_add 0 exact this.imp zero_rpow zero_rpow · exact rpow_add pos _ _ #align real.rpow_add' Real.rpow_add' /-- Variant of `Real.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (hx : 0 ≤ x) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add' hx]; rwa [h] theorem rpow_add_of_nonneg (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 ≤ z) : x ^ (y + z) = x ^ y * x ^ z := by rcases hy.eq_or_lt with (rfl | hy) · rw [zero_add, rpow_zero, one_mul] exact rpow_add' hx (ne_of_gt <| add_pos_of_pos_of_nonneg hy hz) #align real.rpow_add_of_nonneg Real.rpow_add_of_nonneg /-- For `0 ≤ x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for `x = 0` and `y + z = 0`, where the right hand side is `1` while the left hand side can vanish. The inequality is always true, though, and given in this lemma. -/ theorem le_rpow_add {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ y * x ^ z ≤ x ^ (y + z) := by rcases le_iff_eq_or_lt.1 hx with (H | pos) · by_cases h : y + z = 0 · simp only [H.symm, h, rpow_zero] calc (0 : ℝ) ^ y * 0 ^ z ≤ 1 * 1 := mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one _ = 1 := by simp · simp [rpow_add', ← H, h] · simp [rpow_add pos] #align real.le_rpow_add Real.le_rpow_add theorem rpow_sum_of_pos {ι : Type*} {a : ℝ} (ha : 0 < a) (f : ι → ℝ) (s : Finset ι) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := map_sum (⟨⟨fun (x : ℝ) => (a ^ x : ℝ), rpow_zero a⟩, rpow_add ha⟩ : ℝ →+ (Additive ℝ)) f s #align real.rpow_sum_of_pos Real.rpow_sum_of_pos theorem rpow_sum_of_nonneg {ι : Type*} {a : ℝ} (ha : 0 ≤ a) {s : Finset ι} {f : ι → ℝ} (h : ∀ x ∈ s, 0 ≤ f x) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := by induction' s using Finset.cons_induction with i s hi ihs · rw [sum_empty, Finset.prod_empty, rpow_zero] · rw [forall_mem_cons] at h rw [sum_cons, prod_cons, ← ihs h.2, rpow_add_of_nonneg ha h.1 (sum_nonneg h.2)] #align real.rpow_sum_of_nonneg Real.rpow_sum_of_nonneg theorem rpow_neg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by simp only [rpow_def_of_nonneg hx]; split_ifs <;> simp_all [exp_neg] #align real.rpow_neg Real.rpow_neg theorem rpow_sub {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv] #align real.rpow_sub Real.rpow_sub theorem rpow_sub' {x : ℝ} (hx : 0 ≤ x) {y z : ℝ} (h : y - z ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg] at h ⊢ simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv] #align real.rpow_sub' Real.rpow_sub' end Real /-! ## Comparing real and complex powers -/ namespace Complex theorem ofReal_cpow {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : ((x ^ y : ℝ) : ℂ) = (x : ℂ) ^ (y : ℂ) := by simp only [Real.rpow_def_of_nonneg hx, Complex.cpow_def, ofReal_eq_zero]; split_ifs <;> simp [Complex.ofReal_log hx] #align complex.of_real_cpow Complex.ofReal_cpow theorem ofReal_cpow_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℂ) : (x : ℂ) ^ y = (-x : ℂ) ^ y * exp (π * I * y) := by rcases hx.eq_or_lt with (rfl | hlt) · rcases eq_or_ne y 0 with (rfl | hy) <;> simp [*] have hne : (x : ℂ) ≠ 0 := ofReal_ne_zero.mpr hlt.ne rw [cpow_def_of_ne_zero hne, cpow_def_of_ne_zero (neg_ne_zero.2 hne), ← exp_add, ← add_mul, log, log, abs.map_neg, arg_ofReal_of_neg hlt, ← ofReal_neg, arg_ofReal_of_nonneg (neg_nonneg.2 hx), ofReal_zero, zero_mul, add_zero] #align complex.of_real_cpow_of_nonpos Complex.ofReal_cpow_of_nonpos lemma cpow_ofReal (x : ℂ) (y : ℝ) : x ^ (y : ℂ) = ↑(abs x ^ y) * (Real.cos (arg x * y) + Real.sin (arg x * y) * I) := by rcases eq_or_ne x 0 with rfl | hx · simp [ofReal_cpow le_rfl] · rw [cpow_def_of_ne_zero hx, exp_eq_exp_re_mul_sin_add_cos, mul_comm (log x)] norm_cast rw [re_ofReal_mul, im_ofReal_mul, log_re, log_im, mul_comm y, mul_comm y, Real.exp_mul, Real.exp_log] rwa [abs.pos_iff] lemma cpow_ofReal_re (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).re = (abs x) ^ y * Real.cos (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.cos] lemma cpow_ofReal_im (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).im = (abs x) ^ y * Real.sin (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.sin] theorem abs_cpow_of_ne_zero {z : ℂ} (hz : z ≠ 0) (w : ℂ) : abs (z ^ w) = abs z ^ w.re / Real.exp (arg z * im w) := by rw [cpow_def_of_ne_zero hz, abs_exp, mul_re, log_re, log_im, Real.exp_sub, Real.rpow_def_of_pos (abs.pos hz)] #align complex.abs_cpow_of_ne_zero Complex.abs_cpow_of_ne_zero theorem abs_cpow_of_imp {z w : ℂ} (h : z = 0 → w.re = 0 → w = 0) : abs (z ^ w) = abs z ^ w.re / Real.exp (arg z * im w) := by rcases ne_or_eq z 0 with (hz | rfl) <;> [exact abs_cpow_of_ne_zero hz w; rw [map_zero]] rcases eq_or_ne w.re 0 with hw | hw · simp [hw, h rfl hw] · rw [Real.zero_rpow hw, zero_div, zero_cpow, map_zero] exact ne_of_apply_ne re hw #align complex.abs_cpow_of_imp Complex.abs_cpow_of_imp theorem abs_cpow_le (z w : ℂ) : abs (z ^ w) ≤ abs z ^ w.re / Real.exp (arg z * im w) := by by_cases h : z = 0 → w.re = 0 → w = 0 · exact (abs_cpow_of_imp h).le · push_neg at h simp [h] #align complex.abs_cpow_le Complex.abs_cpow_le @[simp] theorem abs_cpow_real (x : ℂ) (y : ℝ) : abs (x ^ (y : ℂ)) = Complex.abs x ^ y := by rw [abs_cpow_of_imp] <;> simp #align complex.abs_cpow_real Complex.abs_cpow_real @[simp] theorem abs_cpow_inv_nat (x : ℂ) (n : ℕ) : abs (x ^ (n⁻¹ : ℂ)) = Complex.abs x ^ (n⁻¹ : ℝ) := by rw [← abs_cpow_real]; simp [-abs_cpow_real] #align complex.abs_cpow_inv_nat Complex.abs_cpow_inv_nat theorem abs_cpow_eq_rpow_re_of_pos {x : ℝ} (hx : 0 < x) (y : ℂ) : abs (x ^ y) = x ^ y.re := by rw [abs_cpow_of_ne_zero (ofReal_ne_zero.mpr hx.ne'), arg_ofReal_of_nonneg hx.le, zero_mul, Real.exp_zero, div_one, abs_of_nonneg hx.le] #align complex.abs_cpow_eq_rpow_re_of_pos Complex.abs_cpow_eq_rpow_re_of_pos theorem abs_cpow_eq_rpow_re_of_nonneg {x : ℝ} (hx : 0 ≤ x) {y : ℂ} (hy : re y ≠ 0) : abs (x ^ y) = x ^ re y := by rw [abs_cpow_of_imp] <;> simp [*, arg_ofReal_of_nonneg, _root_.abs_of_nonneg] #align complex.abs_cpow_eq_rpow_re_of_nonneg Complex.abs_cpow_eq_rpow_re_of_nonneg lemma norm_natCast_cpow_of_re_ne_zero (n : ℕ) {s : ℂ} (hs : s.re ≠ 0) : ‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by rw [norm_eq_abs, ← ofReal_natCast, abs_cpow_eq_rpow_re_of_nonneg n.cast_nonneg hs] lemma norm_natCast_cpow_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) : ‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by rw [norm_eq_abs, ← ofReal_natCast, abs_cpow_eq_rpow_re_of_pos (Nat.cast_pos.mpr hn) _] lemma norm_natCast_cpow_pos_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) : 0 < ‖(n : ℂ) ^ s‖ := (norm_natCast_cpow_of_pos hn _).symm ▸ Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _ theorem cpow_mul_ofReal_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (z : ℂ) : (x : ℂ) ^ (↑y * z) = (↑(x ^ y) : ℂ) ^ z := by rw [cpow_mul, ofReal_cpow hx] · rw [← ofReal_log hx, ← ofReal_mul, ofReal_im, neg_lt_zero]; exact Real.pi_pos · rw [← ofReal_log hx, ← ofReal_mul, ofReal_im]; exact Real.pi_pos.le #align complex.cpow_mul_of_real_nonneg Complex.cpow_mul_ofReal_nonneg end Complex /-! ### Positivity extension -/ namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for the `positivity` tactic: exponentiation by a real number is positive (namely 1) when the exponent is zero. The other cases are done in `evalRpow`. -/ @[positivity (_ : ℝ) ^ (0 : ℝ)] def evalRpowZero : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q($a ^ (0 : ℝ)) => assertInstancesCommute pure (.positive q(Real.rpow_zero_pos $a)) | _, _, _ => throwError "not Real.rpow" /-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when the base is nonnegative and positive when the base is positive. -/ @[positivity (_ : ℝ) ^ (_ : ℝ)] def evalRpow : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q($a ^ ($b : ℝ)) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure (.positive q(Real.rpow_pos_of_pos $pa $b)) | .nonnegative pa => pure (.nonnegative q(Real.rpow_nonneg $pa $b)) | _ => pure .none | _, _, _ => throwError "not Real.rpow" end Mathlib.Meta.Positivity /-! ## Further algebraic properties of `rpow` -/ namespace Real variable {x y z : ℝ} {n : ℕ} theorem rpow_mul {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by rw [← Complex.ofReal_inj, Complex.ofReal_cpow (rpow_nonneg hx _), Complex.ofReal_cpow hx, Complex.ofReal_mul, Complex.cpow_mul, Complex.ofReal_cpow hx] <;> simp only [(Complex.ofReal_mul _ _).symm, (Complex.ofReal_log hx).symm, Complex.ofReal_im, neg_lt_zero, pi_pos, le_of_lt pi_pos] #align real.rpow_mul Real.rpow_mul theorem rpow_add_int {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℤ) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_def, rpow_def, Complex.ofReal_add, Complex.cpow_add _ _ (Complex.ofReal_ne_zero.mpr hx), Complex.ofReal_intCast, Complex.cpow_intCast, ← Complex.ofReal_zpow, mul_comm, Complex.re_ofReal_mul, mul_comm] #align real.rpow_add_int Real.rpow_add_int theorem rpow_add_nat {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y + n) = x ^ y * x ^ n := by simpa using rpow_add_int hx y n #align real.rpow_add_nat Real.rpow_add_nat theorem rpow_sub_int {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_add_int hx y (-n) #align real.rpow_sub_int Real.rpow_sub_int theorem rpow_sub_nat {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_sub_int hx y n #align real.rpow_sub_nat Real.rpow_sub_nat lemma rpow_add_int' (hx : 0 ≤ x) {n : ℤ} (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_intCast] lemma rpow_add_nat' (hx : 0 ≤ x) (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_natCast] lemma rpow_sub_int' (hx : 0 ≤ x) {n : ℤ} (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_intCast] lemma rpow_sub_nat' (hx : 0 ≤ x) (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_natCast] theorem rpow_add_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by simpa using rpow_add_nat hx y 1 #align real.rpow_add_one Real.rpow_add_one theorem rpow_sub_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by simpa using rpow_sub_nat hx y 1 #align real.rpow_sub_one Real.rpow_sub_one lemma rpow_add_one' (hx : 0 ≤ x) (h : y + 1 ≠ 0) : x ^ (y + 1) = x ^ y * x := by rw [rpow_add' hx h, rpow_one] lemma rpow_one_add' (hx : 0 ≤ x) (h : 1 + y ≠ 0) : x ^ (1 + y) = x * x ^ y := by rw [rpow_add' hx h, rpow_one] lemma rpow_sub_one' (hx : 0 ≤ x) (h : y - 1 ≠ 0) : x ^ (y - 1) = x ^ y / x := by rw [rpow_sub' hx h, rpow_one] lemma rpow_one_sub' (hx : 0 ≤ x) (h : 1 - y ≠ 0) : x ^ (1 - y) = x / x ^ y := by rw [rpow_sub' hx h, rpow_one] @[simp] theorem rpow_two (x : ℝ) : x ^ (2 : ℝ) = x ^ 2 := by rw [← rpow_natCast] simp only [Nat.cast_ofNat] #align real.rpow_two Real.rpow_two theorem rpow_neg_one (x : ℝ) : x ^ (-1 : ℝ) = x⁻¹ := by suffices H : x ^ ((-1 : ℤ) : ℝ) = x⁻¹ by rwa [Int.cast_neg, Int.cast_one] at H simp only [rpow_intCast, zpow_one, zpow_neg] #align real.rpow_neg_one Real.rpow_neg_one theorem mul_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) : (x * y) ^ z = x ^ z * y ^ z := by iterate 2 rw [Real.rpow_def_of_nonneg]; split_ifs with h_ifs <;> simp_all · rw [log_mul ‹_› ‹_›, add_mul, exp_add, rpow_def_of_pos (hy.lt_of_ne' ‹_›)] all_goals positivity #align real.mul_rpow Real.mul_rpow theorem inv_rpow (hx : 0 ≤ x) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by simp only [← rpow_neg_one, ← rpow_mul hx, mul_comm] #align real.inv_rpow Real.inv_rpow theorem div_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := by simp only [div_eq_mul_inv, mul_rpow hx (inv_nonneg.2 hy), inv_rpow hy] #align real.div_rpow Real.div_rpow theorem log_rpow {x : ℝ} (hx : 0 < x) (y : ℝ) : log (x ^ y) = y * log x := by apply exp_injective rw [exp_log (rpow_pos_of_pos hx y), ← exp_log hx, mul_comm, rpow_def_of_pos (exp_pos (log x)) y] #align real.log_rpow Real.log_rpow theorem mul_log_eq_log_iff {x y z : ℝ} (hx : 0 < x) (hz : 0 < z) : y * log x = log z ↔ x ^ y = z := ⟨fun h ↦ log_injOn_pos (rpow_pos_of_pos hx _) hz <| log_rpow hx _ |>.trans h, by rintro rfl; rw [log_rpow hx]⟩ @[simp] lemma rpow_rpow_inv (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul hx, mul_inv_cancel hy, rpow_one] @[simp] lemma rpow_inv_rpow (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul hx, inv_mul_cancel hy, rpow_one] theorem pow_rpow_inv_natCast (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, mul_inv_cancel hn0, rpow_one] #align real.pow_nat_rpow_nat_inv Real.pow_rpow_inv_natCast theorem rpow_inv_natCast_pow (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, inv_mul_cancel hn0, rpow_one] #align real.rpow_nat_inv_pow_nat Real.rpow_inv_natCast_pow lemma rpow_natCast_mul (hx : 0 ≤ x) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_natCast] lemma rpow_mul_natCast (hx : 0 ≤ x) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_natCast] lemma rpow_intCast_mul (hx : 0 ≤ x) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_intCast] lemma rpow_mul_intCast (hx : 0 ≤ x) (y : ℝ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_intCast] /-! Note: lemmas about `(∏ i ∈ s, f i ^ r)` such as `Real.finset_prod_rpow` are proved in `Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean` instead. -/ /-! ## Order and monotonicity -/ @[gcongr] theorem rpow_lt_rpow (hx : 0 ≤ x) (hxy : x < y) (hz : 0 < z) : x ^ z < y ^ z := by rw [le_iff_eq_or_lt] at hx; cases' hx with hx hx · rw [← hx, zero_rpow (ne_of_gt hz)] exact rpow_pos_of_pos (by rwa [← hx] at hxy) _ · rw [rpow_def_of_pos hx, rpow_def_of_pos (lt_trans hx hxy), exp_lt_exp] exact mul_lt_mul_of_pos_right (log_lt_log hx hxy) hz #align real.rpow_lt_rpow Real.rpow_lt_rpow theorem strictMonoOn_rpow_Ici_of_exponent_pos {r : ℝ} (hr : 0 < r) : StrictMonoOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_lt_rpow ha hab hr @[gcongr] theorem rpow_le_rpow {x y z : ℝ} (h : 0 ≤ x) (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := by rcases eq_or_lt_of_le h₁ with (rfl | h₁'); · rfl rcases eq_or_lt_of_le h₂ with (rfl | h₂'); · simp exact le_of_lt (rpow_lt_rpow h h₁' h₂') #align real.rpow_le_rpow Real.rpow_le_rpow theorem monotoneOn_rpow_Ici_of_exponent_nonneg {r : ℝ} (hr : 0 ≤ r) : MonotoneOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_le_rpow ha hab hr lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := by have := hx.trans hxy rw [← inv_lt_inv, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_lt_rpow ?_ hxy (neg_pos.2 hz) all_goals positivity lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≤ y) (hz : z ≤ 0) : y ^ z ≤ x ^ z := by have := hx.trans_le hxy rw [← inv_le_inv, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_le_rpow ?_ hxy (neg_nonneg.2 hz) all_goals positivity theorem rpow_lt_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := ⟨lt_imp_lt_of_le_imp_le fun h => rpow_le_rpow hy h (le_of_lt hz), fun h => rpow_lt_rpow hx h hz⟩ #align real.rpow_lt_rpow_iff Real.rpow_lt_rpow_iff theorem rpow_le_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff hy hx hz #align real.rpow_le_rpow_iff Real.rpow_le_rpow_iff lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x := ⟨lt_imp_lt_of_le_imp_le fun h ↦ rpow_le_rpow_of_nonpos hx h hz.le, fun h ↦ rpow_lt_rpow_of_neg hy h hz⟩ lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≤ y ^ z ↔ y ≤ x := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff_of_neg hy hx hz lemma le_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by rw [← rpow_le_rpow_iff hx _ hz, rpow_inv_rpow] <;> positivity lemma rpow_inv_le_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by rw [← rpow_le_rpow_iff _ hy hz, rpow_inv_rpow] <;> positivity lemma lt_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := lt_iff_lt_of_le_iff_le <| rpow_inv_le_iff_of_pos hy hx hz lemma rpow_inv_lt_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := lt_iff_lt_of_le_iff_le <| le_rpow_inv_iff_of_pos hy hx hz theorem le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≤ y ^ z⁻¹ ↔ y ≤ x ^ z := by rw [← rpow_le_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity #align real.le_rpow_inv_iff_of_neg Real.le_rpow_inv_iff_of_neg theorem lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z := by rw [← rpow_lt_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity #align real.lt_rpow_inv_iff_of_neg Real.lt_rpow_inv_iff_of_neg theorem rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x := by rw [← rpow_lt_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity #align real.rpow_inv_lt_iff_of_neg Real.rpow_inv_lt_iff_of_neg theorem rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≤ y ↔ y ^ z ≤ x := by rw [← rpow_le_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity #align real.rpow_inv_le_iff_of_neg Real.rpow_inv_le_iff_of_neg theorem rpow_lt_rpow_of_exponent_lt (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos (lt_trans zero_lt_one hx)] rw [exp_lt_exp]; exact mul_lt_mul_of_pos_left hyz (log_pos hx) #align real.rpow_lt_rpow_of_exponent_lt Real.rpow_lt_rpow_of_exponent_lt @[gcongr] theorem rpow_le_rpow_of_exponent_le (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := by repeat' rw [rpow_def_of_pos (lt_of_lt_of_le zero_lt_one hx)] rw [exp_le_exp]; exact mul_le_mul_of_nonneg_left hyz (log_nonneg hx) #align real.rpow_le_rpow_of_exponent_le Real.rpow_le_rpow_of_exponent_le theorem rpow_lt_rpow_of_exponent_neg {x y z : ℝ} (hy : 0 < y) (hxy : y < x) (hz : z < 0) : x ^ z < y ^ z := by have hx : 0 < x := hy.trans hxy rw [← neg_neg z, Real.rpow_neg (le_of_lt hx) (-z), Real.rpow_neg (le_of_lt hy) (-z), inv_lt_inv (rpow_pos_of_pos hx _) (rpow_pos_of_pos hy _)] exact Real.rpow_lt_rpow (by positivity) hxy <| neg_pos_of_neg hz theorem strictAntiOn_rpow_Ioi_of_exponent_neg {r : ℝ} (hr : r < 0) : StrictAntiOn (fun (x:ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_lt_rpow_of_exponent_neg ha hab hr
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
643
652
theorem rpow_le_rpow_of_exponent_nonpos {x y : ℝ} (hy : 0 < y) (hxy : y ≤ x) (hz : z ≤ 0) : x ^ z ≤ y ^ z := by
rcases ne_or_eq z 0 with hz_zero | rfl case inl => rcases ne_or_eq x y with hxy' | rfl case inl => exact le_of_lt <| rpow_lt_rpow_of_exponent_neg hy (Ne.lt_of_le (id (Ne.symm hxy')) hxy) (Ne.lt_of_le hz_zero hz) case inr => simp case inr => simp
/- Copyright (c) 2018 Guy Leroy. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sangwoo Jo (aka Jason), Guy Leroy, Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.Group.Commute.Units import Mathlib.Algebra.Group.Int import Mathlib.Algebra.GroupWithZero.Semiconj import Mathlib.Data.Nat.GCD.Basic import Mathlib.Order.Bounds.Basic #align_import data.int.gcd from "leanprover-community/mathlib"@"47a1a73351de8dd6c8d3d32b569c8e434b03ca47" /-! # Extended GCD and divisibility over ℤ ## Main definitions * Given `x y : ℕ`, `xgcd x y` computes the pair of integers `(a, b)` such that `gcd x y = x * a + y * b`. `gcdA x y` and `gcdB x y` are defined to be `a` and `b`, respectively. ## Main statements * `gcd_eq_gcd_ab`: Bézout's lemma, given `x y : ℕ`, `gcd x y = x * gcdA x y + y * gcdB x y`. ## Tags Bézout's lemma, Bezout's lemma -/ /-! ### Extended Euclidean algorithm -/ namespace Nat /-- Helper function for the extended GCD algorithm (`Nat.xgcd`). -/ def xgcdAux : ℕ → ℤ → ℤ → ℕ → ℤ → ℤ → ℕ × ℤ × ℤ | 0, _, _, r', s', t' => (r', s', t') | succ k, s, t, r', s', t' => let q := r' / succ k xgcdAux (r' % succ k) (s' - q * s) (t' - q * t) (succ k) s t termination_by k => k decreasing_by exact mod_lt _ <| (succ_pos _).gt #align nat.xgcd_aux Nat.xgcdAux @[simp] theorem xgcd_zero_left {s t r' s' t'} : xgcdAux 0 s t r' s' t' = (r', s', t') := by simp [xgcdAux] #align nat.xgcd_zero_left Nat.xgcd_zero_left theorem xgcdAux_rec {r s t r' s' t'} (h : 0 < r) : xgcdAux r s t r' s' t' = xgcdAux (r' % r) (s' - r' / r * s) (t' - r' / r * t) r s t := by obtain ⟨r, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h.ne' simp [xgcdAux] #align nat.xgcd_aux_rec Nat.xgcdAux_rec /-- Use the extended GCD algorithm to generate the `a` and `b` values satisfying `gcd x y = x * a + y * b`. -/ def xgcd (x y : ℕ) : ℤ × ℤ := (xgcdAux x 1 0 y 0 1).2 #align nat.xgcd Nat.xgcd /-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/ def gcdA (x y : ℕ) : ℤ := (xgcd x y).1 #align nat.gcd_a Nat.gcdA /-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/ def gcdB (x y : ℕ) : ℤ := (xgcd x y).2 #align nat.gcd_b Nat.gcdB @[simp] theorem gcdA_zero_left {s : ℕ} : gcdA 0 s = 0 := by unfold gcdA rw [xgcd, xgcd_zero_left] #align nat.gcd_a_zero_left Nat.gcdA_zero_left @[simp] theorem gcdB_zero_left {s : ℕ} : gcdB 0 s = 1 := by unfold gcdB rw [xgcd, xgcd_zero_left] #align nat.gcd_b_zero_left Nat.gcdB_zero_left @[simp] theorem gcdA_zero_right {s : ℕ} (h : s ≠ 0) : gcdA s 0 = 1 := by unfold gcdA xgcd obtain ⟨s, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h rw [xgcdAux] simp #align nat.gcd_a_zero_right Nat.gcdA_zero_right @[simp] theorem gcdB_zero_right {s : ℕ} (h : s ≠ 0) : gcdB s 0 = 0 := by unfold gcdB xgcd obtain ⟨s, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h rw [xgcdAux] simp #align nat.gcd_b_zero_right Nat.gcdB_zero_right @[simp] theorem xgcdAux_fst (x y) : ∀ s t s' t', (xgcdAux x s t y s' t').1 = gcd x y := gcd.induction x y (by simp) fun x y h IH s t s' t' => by simp only [h, xgcdAux_rec, IH] rw [← gcd_rec] #align nat.xgcd_aux_fst Nat.xgcdAux_fst theorem xgcdAux_val (x y) : xgcdAux x 1 0 y 0 1 = (gcd x y, xgcd x y) := by rw [xgcd, ← xgcdAux_fst x y 1 0 0 1] #align nat.xgcd_aux_val Nat.xgcdAux_val theorem xgcd_val (x y) : xgcd x y = (gcdA x y, gcdB x y) := by unfold gcdA gcdB; cases xgcd x y; rfl #align nat.xgcd_val Nat.xgcd_val section variable (x y : ℕ) private def P : ℕ × ℤ × ℤ → Prop | (r, s, t) => (r : ℤ) = x * s + y * t theorem xgcdAux_P {r r'} : ∀ {s t s' t'}, P x y (r, s, t) → P x y (r', s', t') → P x y (xgcdAux r s t r' s' t') := by induction r, r' using gcd.induction with | H0 => simp | H1 a b h IH => intro s t s' t' p p' rw [xgcdAux_rec h]; refine IH ?_ p; dsimp [P] at * rw [Int.emod_def]; generalize (b / a : ℤ) = k rw [p, p', Int.mul_sub, sub_add_eq_add_sub, Int.mul_sub, Int.add_mul, mul_comm k t, mul_comm k s, ← mul_assoc, ← mul_assoc, add_comm (x * s * k), ← add_sub_assoc, sub_sub] set_option linter.uppercaseLean3 false in #align nat.xgcd_aux_P Nat.xgcdAux_P /-- **Bézout's lemma**: given `x y : ℕ`, `gcd x y = x * a + y * b`, where `a = gcd_a x y` and `b = gcd_b x y` are computed by the extended Euclidean algorithm. -/ theorem gcd_eq_gcd_ab : (gcd x y : ℤ) = x * gcdA x y + y * gcdB x y := by have := @xgcdAux_P x y x y 1 0 0 1 (by simp [P]) (by simp [P]) rwa [xgcdAux_val, xgcd_val] at this #align nat.gcd_eq_gcd_ab Nat.gcd_eq_gcd_ab end theorem exists_mul_emod_eq_gcd {k n : ℕ} (hk : gcd n k < k) : ∃ m, n * m % k = gcd n k := by have hk' := Int.ofNat_ne_zero.2 (ne_of_gt (lt_of_le_of_lt (zero_le (gcd n k)) hk)) have key := congr_arg (fun (m : ℤ) => (m % k).toNat) (gcd_eq_gcd_ab n k) simp only at key rw [Int.add_mul_emod_self_left, ← Int.natCast_mod, Int.toNat_natCast, mod_eq_of_lt hk] at key refine ⟨(n.gcdA k % k).toNat, Eq.trans (Int.ofNat.inj ?_) key.symm⟩ rw [Int.ofNat_eq_coe, Int.natCast_mod, Int.ofNat_mul, Int.toNat_of_nonneg (Int.emod_nonneg _ hk'), Int.ofNat_eq_coe, Int.toNat_of_nonneg (Int.emod_nonneg _ hk'), Int.mul_emod, Int.emod_emod, ← Int.mul_emod] #align nat.exists_mul_mod_eq_gcd Nat.exists_mul_emod_eq_gcd theorem exists_mul_emod_eq_one_of_coprime {k n : ℕ} (hkn : Coprime n k) (hk : 1 < k) : ∃ m, n * m % k = 1 := Exists.recOn (exists_mul_emod_eq_gcd (lt_of_le_of_lt (le_of_eq hkn) hk)) fun m hm ↦ ⟨m, hm.trans hkn⟩ #align nat.exists_mul_mod_eq_one_of_coprime Nat.exists_mul_emod_eq_one_of_coprime end Nat /-! ### Divisibility over ℤ -/ namespace Int theorem gcd_def (i j : ℤ) : gcd i j = Nat.gcd i.natAbs j.natAbs := rfl @[simp, norm_cast] protected lemma gcd_natCast_natCast (m n : ℕ) : gcd ↑m ↑n = m.gcd n := rfl #align int.coe_nat_gcd Int.gcd_natCast_natCast @[deprecated (since := "2024-05-25")] alias coe_nat_gcd := Int.gcd_natCast_natCast /-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/ def gcdA : ℤ → ℤ → ℤ | ofNat m, n => m.gcdA n.natAbs | -[m+1], n => -m.succ.gcdA n.natAbs #align int.gcd_a Int.gcdA /-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/ def gcdB : ℤ → ℤ → ℤ | m, ofNat n => m.natAbs.gcdB n | m, -[n+1] => -m.natAbs.gcdB n.succ #align int.gcd_b Int.gcdB /-- **Bézout's lemma** -/ theorem gcd_eq_gcd_ab : ∀ x y : ℤ, (gcd x y : ℤ) = x * gcdA x y + y * gcdB x y | (m : ℕ), (n : ℕ) => Nat.gcd_eq_gcd_ab _ _ | (m : ℕ), -[n+1] => show (_ : ℤ) = _ + -(n + 1) * -_ by rw [Int.neg_mul_neg]; apply Nat.gcd_eq_gcd_ab | -[m+1], (n : ℕ) => show (_ : ℤ) = -(m + 1) * -_ + _ by rw [Int.neg_mul_neg]; apply Nat.gcd_eq_gcd_ab | -[m+1], -[n+1] => show (_ : ℤ) = -(m + 1) * -_ + -(n + 1) * -_ by rw [Int.neg_mul_neg, Int.neg_mul_neg] apply Nat.gcd_eq_gcd_ab #align int.gcd_eq_gcd_ab Int.gcd_eq_gcd_ab #align int.lcm Int.lcm theorem lcm_def (i j : ℤ) : lcm i j = Nat.lcm (natAbs i) (natAbs j) := rfl #align int.lcm_def Int.lcm_def protected theorem coe_nat_lcm (m n : ℕ) : Int.lcm ↑m ↑n = Nat.lcm m n := rfl #align int.coe_nat_lcm Int.coe_nat_lcm #align int.gcd_dvd_left Int.gcd_dvd_left #align int.gcd_dvd_right Int.gcd_dvd_right theorem dvd_gcd {i j k : ℤ} (h1 : k ∣ i) (h2 : k ∣ j) : k ∣ gcd i j := natAbs_dvd.1 <| natCast_dvd_natCast.2 <| Nat.dvd_gcd (natAbs_dvd_natAbs.2 h1) (natAbs_dvd_natAbs.2 h2) #align int.dvd_gcd Int.dvd_gcd theorem gcd_mul_lcm (i j : ℤ) : gcd i j * lcm i j = natAbs (i * j) := by rw [Int.gcd, Int.lcm, Nat.gcd_mul_lcm, natAbs_mul] #align int.gcd_mul_lcm Int.gcd_mul_lcm theorem gcd_comm (i j : ℤ) : gcd i j = gcd j i := Nat.gcd_comm _ _ #align int.gcd_comm Int.gcd_comm theorem gcd_assoc (i j k : ℤ) : gcd (gcd i j) k = gcd i (gcd j k) := Nat.gcd_assoc _ _ _ #align int.gcd_assoc Int.gcd_assoc @[simp]
Mathlib/Data/Int/GCD.lean
233
233
theorem gcd_self (i : ℤ) : gcd i i = natAbs i := by
simp [gcd]
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Basic import Mathlib.RingTheory.Noetherian #align_import algebra.lie.subalgebra from "leanprover-community/mathlib"@"6d584f1709bedbed9175bd9350df46599bdd7213" /-! # Lie subalgebras This file defines Lie subalgebras of a Lie algebra and provides basic related definitions and results. ## Main definitions * `LieSubalgebra` * `LieSubalgebra.incl` * `LieSubalgebra.map` * `LieHom.range` * `LieEquiv.ofInjective` * `LieEquiv.ofEq` * `LieEquiv.ofSubalgebras` ## Tags lie algebra, lie subalgebra -/ universe u v w w₁ w₂ section LieSubalgebra variable (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L] /-- A Lie subalgebra of a Lie algebra is submodule that is closed under the Lie bracket. This is a sufficient condition for the subset itself to form a Lie algebra. -/ structure LieSubalgebra extends Submodule R L where /-- A Lie subalgebra is closed under Lie bracket. -/ lie_mem' : ∀ {x y}, x ∈ carrier → y ∈ carrier → ⁅x, y⁆ ∈ carrier #align lie_subalgebra LieSubalgebra /-- The zero algebra is a subalgebra of any Lie algebra. -/ instance : Zero (LieSubalgebra R L) := ⟨⟨0, @fun x y hx _hy ↦ by rw [(Submodule.mem_bot R).1 hx, zero_lie] exact Submodule.zero_mem 0⟩⟩ instance : Inhabited (LieSubalgebra R L) := ⟨0⟩ instance : Coe (LieSubalgebra R L) (Submodule R L) := ⟨LieSubalgebra.toSubmodule⟩ namespace LieSubalgebra instance : SetLike (LieSubalgebra R L) L where coe L' := L'.carrier coe_injective' L' L'' h := by rcases L' with ⟨⟨⟩⟩ rcases L'' with ⟨⟨⟩⟩ congr exact SetLike.coe_injective' h instance : AddSubgroupClass (LieSubalgebra R L) L where add_mem := Submodule.add_mem _ zero_mem L' := L'.zero_mem' neg_mem {L'} x hx := show -x ∈ (L' : Submodule R L) from neg_mem hx /-- A Lie subalgebra forms a new Lie ring. -/ instance lieRing (L' : LieSubalgebra R L) : LieRing L' where bracket x y := ⟨⁅x.val, y.val⁆, L'.lie_mem' x.property y.property⟩ lie_add := by intros apply SetCoe.ext apply lie_add add_lie := by intros apply SetCoe.ext apply add_lie lie_self := by intros apply SetCoe.ext apply lie_self leibniz_lie := by intros apply SetCoe.ext apply leibniz_lie section variable {R₁ : Type*} [Semiring R₁] /-- A Lie subalgebra inherits module structures from `L`. -/ instance [SMul R₁ R] [Module R₁ L] [IsScalarTower R₁ R L] (L' : LieSubalgebra R L) : Module R₁ L' := L'.toSubmodule.module' instance [SMul R₁ R] [SMul R₁ᵐᵒᵖ R] [Module R₁ L] [Module R₁ᵐᵒᵖ L] [IsScalarTower R₁ R L] [IsScalarTower R₁ᵐᵒᵖ R L] [IsCentralScalar R₁ L] (L' : LieSubalgebra R L) : IsCentralScalar R₁ L' := L'.toSubmodule.isCentralScalar instance [SMul R₁ R] [Module R₁ L] [IsScalarTower R₁ R L] (L' : LieSubalgebra R L) : IsScalarTower R₁ R L' := L'.toSubmodule.isScalarTower instance (L' : LieSubalgebra R L) [IsNoetherian R L] : IsNoetherian R L' := isNoetherian_submodule' _ end /-- A Lie subalgebra forms a new Lie algebra. -/ instance lieAlgebra (L' : LieSubalgebra R L) : LieAlgebra R L' where lie_smul := by { intros apply SetCoe.ext apply lie_smul } variable {R L} variable (L' : LieSubalgebra R L) @[simp] protected theorem zero_mem : (0 : L) ∈ L' := zero_mem L' #align lie_subalgebra.zero_mem LieSubalgebra.zero_mem protected theorem add_mem {x y : L} : x ∈ L' → y ∈ L' → (x + y : L) ∈ L' := add_mem #align lie_subalgebra.add_mem LieSubalgebra.add_mem protected theorem sub_mem {x y : L} : x ∈ L' → y ∈ L' → (x - y : L) ∈ L' := sub_mem #align lie_subalgebra.sub_mem LieSubalgebra.sub_mem theorem smul_mem (t : R) {x : L} (h : x ∈ L') : t • x ∈ L' := (L' : Submodule R L).smul_mem t h #align lie_subalgebra.smul_mem LieSubalgebra.smul_mem theorem lie_mem {x y : L} (hx : x ∈ L') (hy : y ∈ L') : (⁅x, y⁆ : L) ∈ L' := L'.lie_mem' hx hy #align lie_subalgebra.lie_mem LieSubalgebra.lie_mem theorem mem_carrier {x : L} : x ∈ L'.carrier ↔ x ∈ (L' : Set L) := Iff.rfl #align lie_subalgebra.mem_carrier LieSubalgebra.mem_carrier @[simp] theorem mem_mk_iff (S : Set L) (h₁ h₂ h₃ h₄) {x : L} : x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubalgebra R L) ↔ x ∈ S := Iff.rfl #align lie_subalgebra.mem_mk_iff LieSubalgebra.mem_mk_iff @[simp] theorem mem_coe_submodule {x : L} : x ∈ (L' : Submodule R L) ↔ x ∈ L' := Iff.rfl #align lie_subalgebra.mem_coe_submodule LieSubalgebra.mem_coe_submodule theorem mem_coe {x : L} : x ∈ (L' : Set L) ↔ x ∈ L' := Iff.rfl #align lie_subalgebra.mem_coe LieSubalgebra.mem_coe @[simp, norm_cast] theorem coe_bracket (x y : L') : (↑⁅x, y⁆ : L) = ⁅(↑x : L), ↑y⁆ := rfl #align lie_subalgebra.coe_bracket LieSubalgebra.coe_bracket theorem ext_iff (x y : L') : x = y ↔ (x : L) = y := Subtype.ext_iff #align lie_subalgebra.ext_iff LieSubalgebra.ext_iff theorem coe_zero_iff_zero (x : L') : (x : L) = 0 ↔ x = 0 := (ext_iff L' x 0).symm #align lie_subalgebra.coe_zero_iff_zero LieSubalgebra.coe_zero_iff_zero @[ext] theorem ext (L₁' L₂' : LieSubalgebra R L) (h : ∀ x, x ∈ L₁' ↔ x ∈ L₂') : L₁' = L₂' := SetLike.ext h #align lie_subalgebra.ext LieSubalgebra.ext theorem ext_iff' (L₁' L₂' : LieSubalgebra R L) : L₁' = L₂' ↔ ∀ x, x ∈ L₁' ↔ x ∈ L₂' := SetLike.ext_iff #align lie_subalgebra.ext_iff' LieSubalgebra.ext_iff' @[simp] theorem mk_coe (S : Set L) (h₁ h₂ h₃ h₄) : ((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubalgebra R L) : Set L) = S := rfl #align lie_subalgebra.mk_coe LieSubalgebra.mk_coe theorem coe_to_submodule_mk (p : Submodule R L) (h) : (({ p with lie_mem' := h } : LieSubalgebra R L) : Submodule R L) = p := by cases p rfl #align lie_subalgebra.coe_to_submodule_mk LieSubalgebra.coe_to_submodule_mk theorem coe_injective : Function.Injective ((↑) : LieSubalgebra R L → Set L) := SetLike.coe_injective #align lie_subalgebra.coe_injective LieSubalgebra.coe_injective @[norm_cast] theorem coe_set_eq (L₁' L₂' : LieSubalgebra R L) : (L₁' : Set L) = L₂' ↔ L₁' = L₂' := SetLike.coe_set_eq #align lie_subalgebra.coe_set_eq LieSubalgebra.coe_set_eq theorem to_submodule_injective : Function.Injective ((↑) : LieSubalgebra R L → Submodule R L) := fun L₁' L₂' h ↦ by rw [SetLike.ext'_iff] at h rw [← coe_set_eq] exact h #align lie_subalgebra.to_submodule_injective LieSubalgebra.to_submodule_injective @[simp] theorem coe_to_submodule_eq_iff (L₁' L₂' : LieSubalgebra R L) : (L₁' : Submodule R L) = (L₂' : Submodule R L) ↔ L₁' = L₂' := to_submodule_injective.eq_iff #align lie_subalgebra.coe_to_submodule_eq_iff LieSubalgebra.coe_to_submodule_eq_iff theorem coe_to_submodule : ((L' : Submodule R L) : Set L) = L' := rfl #align lie_subalgebra.coe_to_submodule LieSubalgebra.coe_to_submodule section LieModule variable {M : Type w} [AddCommGroup M] [LieRingModule L M] variable {N : Type w₁} [AddCommGroup N] [LieRingModule L N] [Module R N] [LieModule R L N] /-- Given a Lie algebra `L` containing a Lie subalgebra `L' ⊆ L`, together with a Lie ring module `M` of `L`, we may regard `M` as a Lie ring module of `L'` by restriction. -/ instance lieRingModule : LieRingModule L' M where bracket x m := ⁅(x : L), m⁆ add_lie x y m := add_lie (x : L) y m lie_add x y m := lie_add (x : L) y m leibniz_lie x y m := leibniz_lie (x : L) y m @[simp] theorem coe_bracket_of_module (x : L') (m : M) : ⁅x, m⁆ = ⁅(x : L), m⁆ := rfl #align lie_subalgebra.coe_bracket_of_module LieSubalgebra.coe_bracket_of_module variable [Module R M] [LieModule R L M] /-- Given a Lie algebra `L` containing a Lie subalgebra `L' ⊆ L`, together with a Lie module `M` of `L`, we may regard `M` as a Lie module of `L'` by restriction. -/ instance lieModule : LieModule R L' M where smul_lie t x m := by simp only [coe_bracket_of_module, smul_lie, Submodule.coe_smul_of_tower] lie_smul t x m := by simp only [coe_bracket_of_module, lie_smul] /-- An `L`-equivariant map of Lie modules `M → N` is `L'`-equivariant for any Lie subalgebra `L' ⊆ L`. -/ def _root_.LieModuleHom.restrictLie (f : M →ₗ⁅R,L⁆ N) (L' : LieSubalgebra R L) : M →ₗ⁅R,L'⁆ N := { (f : M →ₗ[R] N) with map_lie' := @fun x m ↦ f.map_lie (↑x) m } #align lie_module_hom.restrict_lie LieModuleHom.restrictLie @[simp] theorem _root_.LieModuleHom.coe_restrictLie (f : M →ₗ⁅R,L⁆ N) : ⇑(f.restrictLie L') = f := rfl #align lie_module_hom.coe_restrict_lie LieModuleHom.coe_restrictLie end LieModule /-- The embedding of a Lie subalgebra into the ambient space as a morphism of Lie algebras. -/ def incl : L' →ₗ⁅R⁆ L := { (L' : Submodule R L).subtype with map_lie' := rfl } #align lie_subalgebra.incl LieSubalgebra.incl @[simp] theorem coe_incl : ⇑L'.incl = ((↑) : L' → L) := rfl #align lie_subalgebra.coe_incl LieSubalgebra.coe_incl /-- The embedding of a Lie subalgebra into the ambient space as a morphism of Lie modules. -/ def incl' : L' →ₗ⁅R,L'⁆ L := { (L' : Submodule R L).subtype with map_lie' := rfl } #align lie_subalgebra.incl' LieSubalgebra.incl' @[simp] theorem coe_incl' : ⇑L'.incl' = ((↑) : L' → L) := rfl #align lie_subalgebra.coe_incl' LieSubalgebra.coe_incl' end LieSubalgebra variable {R L} variable {L₂ : Type w} [LieRing L₂] [LieAlgebra R L₂] variable (f : L →ₗ⁅R⁆ L₂) namespace LieHom /-- The range of a morphism of Lie algebras is a Lie subalgebra. -/ def range : LieSubalgebra R L₂ := { LinearMap.range (f : L →ₗ[R] L₂) with lie_mem' := by rintro - - ⟨x, rfl⟩ ⟨y, rfl⟩ exact ⟨⁅x, y⁆, f.map_lie x y⟩ } #align lie_hom.range LieHom.range @[simp] theorem range_coe : (f.range : Set L₂) = Set.range f := LinearMap.range_coe (f : L →ₗ[R] L₂) #align lie_hom.range_coe LieHom.range_coe @[simp] theorem mem_range (x : L₂) : x ∈ f.range ↔ ∃ y : L, f y = x := LinearMap.mem_range #align lie_hom.mem_range LieHom.mem_range theorem mem_range_self (x : L) : f x ∈ f.range := LinearMap.mem_range_self (f : L →ₗ[R] L₂) x #align lie_hom.mem_range_self LieHom.mem_range_self /-- We can restrict a morphism to a (surjective) map to its range. -/ def rangeRestrict : L →ₗ⁅R⁆ f.range := { (f : L →ₗ[R] L₂).rangeRestrict with map_lie' := @fun x y ↦ by apply Subtype.ext exact f.map_lie x y } #align lie_hom.range_restrict LieHom.rangeRestrict @[simp] theorem rangeRestrict_apply (x : L) : f.rangeRestrict x = ⟨f x, f.mem_range_self x⟩ := rfl #align lie_hom.range_restrict_apply LieHom.rangeRestrict_apply theorem surjective_rangeRestrict : Function.Surjective f.rangeRestrict := by rintro ⟨y, hy⟩ erw [mem_range] at hy; obtain ⟨x, rfl⟩ := hy use x simp only [Subtype.mk_eq_mk, rangeRestrict_apply] #align lie_hom.surjective_range_restrict LieHom.surjective_rangeRestrict /-- A Lie algebra is equivalent to its range under an injective Lie algebra morphism. -/ noncomputable def equivRangeOfInjective (h : Function.Injective f) : L ≃ₗ⁅R⁆ f.range := LieEquiv.ofBijective f.rangeRestrict ⟨fun x y hxy ↦ by simp only [Subtype.mk_eq_mk, rangeRestrict_apply] at hxy exact h hxy, f.surjective_rangeRestrict⟩ #align lie_hom.equiv_range_of_injective LieHom.equivRangeOfInjective @[simp] theorem equivRangeOfInjective_apply (h : Function.Injective f) (x : L) : f.equivRangeOfInjective h x = ⟨f x, mem_range_self f x⟩ := rfl #align lie_hom.equiv_range_of_injective_apply LieHom.equivRangeOfInjective_apply end LieHom theorem Submodule.exists_lieSubalgebra_coe_eq_iff (p : Submodule R L) : (∃ K : LieSubalgebra R L, ↑K = p) ↔ ∀ x y : L, x ∈ p → y ∈ p → ⁅x, y⁆ ∈ p := by constructor · rintro ⟨K, rfl⟩ _ _ exact K.lie_mem' · intro h use { p with lie_mem' := h _ _ } #align submodule.exists_lie_subalgebra_coe_eq_iff Submodule.exists_lieSubalgebra_coe_eq_iff namespace LieSubalgebra variable (K K' : LieSubalgebra R L) (K₂ : LieSubalgebra R L₂) @[simp] theorem incl_range : K.incl.range = K := by rw [← coe_to_submodule_eq_iff] exact (K : Submodule R L).range_subtype #align lie_subalgebra.incl_range LieSubalgebra.incl_range /-- The image of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the codomain. -/ def map : LieSubalgebra R L₂ := { (K : Submodule R L).map (f : L →ₗ[R] L₂) with lie_mem' := @fun x y hx hy ↦ by erw [Submodule.mem_map] at hx rcases hx with ⟨x', hx', hx⟩ rw [← hx] erw [Submodule.mem_map] at hy rcases hy with ⟨y', hy', hy⟩ rw [← hy] erw [Submodule.mem_map] exact ⟨⁅x', y'⁆, K.lie_mem hx' hy', f.map_lie x' y'⟩ } #align lie_subalgebra.map LieSubalgebra.map @[simp] theorem mem_map (x : L₂) : x ∈ K.map f ↔ ∃ y : L, y ∈ K ∧ f y = x := Submodule.mem_map #align lie_subalgebra.mem_map LieSubalgebra.mem_map -- TODO Rename and state for homs instead of equivs. theorem mem_map_submodule (e : L ≃ₗ⁅R⁆ L₂) (x : L₂) : x ∈ K.map (e : L →ₗ⁅R⁆ L₂) ↔ x ∈ (K : Submodule R L).map (e : L →ₗ[R] L₂) := Iff.rfl #align lie_subalgebra.mem_map_submodule LieSubalgebra.mem_map_submodule /-- The preimage of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the domain. -/ def comap : LieSubalgebra R L := { (K₂ : Submodule R L₂).comap (f : L →ₗ[R] L₂) with lie_mem' := @fun x y hx hy ↦ by suffices ⁅f x, f y⁆ ∈ K₂ by simp [this] exact K₂.lie_mem hx hy } #align lie_subalgebra.comap LieSubalgebra.comap section LatticeStructure open Set instance : PartialOrder (LieSubalgebra R L) := { PartialOrder.lift ((↑) : LieSubalgebra R L → Set L) coe_injective with le := fun N N' ↦ ∀ ⦃x⦄, x ∈ N → x ∈ N' } theorem le_def : K ≤ K' ↔ (K : Set L) ⊆ K' := Iff.rfl #align lie_subalgebra.le_def LieSubalgebra.le_def @[simp] theorem coe_submodule_le_coe_submodule : (K : Submodule R L) ≤ K' ↔ K ≤ K' := Iff.rfl #align lie_subalgebra.coe_submodule_le_coe_submodule LieSubalgebra.coe_submodule_le_coe_submodule instance : Bot (LieSubalgebra R L) := ⟨0⟩ @[simp] theorem bot_coe : ((⊥ : LieSubalgebra R L) : Set L) = {0} := rfl #align lie_subalgebra.bot_coe LieSubalgebra.bot_coe @[simp] theorem bot_coe_submodule : ((⊥ : LieSubalgebra R L) : Submodule R L) = ⊥ := rfl #align lie_subalgebra.bot_coe_submodule LieSubalgebra.bot_coe_submodule @[simp] theorem mem_bot (x : L) : x ∈ (⊥ : LieSubalgebra R L) ↔ x = 0 := mem_singleton_iff #align lie_subalgebra.mem_bot LieSubalgebra.mem_bot instance : Top (LieSubalgebra R L) := ⟨{ (⊤ : Submodule R L) with lie_mem' := @fun x y _ _ ↦ mem_univ ⁅x, y⁆ }⟩ @[simp] theorem top_coe : ((⊤ : LieSubalgebra R L) : Set L) = univ := rfl #align lie_subalgebra.top_coe LieSubalgebra.top_coe @[simp] theorem top_coe_submodule : ((⊤ : LieSubalgebra R L) : Submodule R L) = ⊤ := rfl #align lie_subalgebra.top_coe_submodule LieSubalgebra.top_coe_submodule @[simp] theorem mem_top (x : L) : x ∈ (⊤ : LieSubalgebra R L) := mem_univ x #align lie_subalgebra.mem_top LieSubalgebra.mem_top theorem _root_.LieHom.range_eq_map : f.range = map f ⊤ := by ext simp #align lie_hom.range_eq_map LieHom.range_eq_map instance : Inf (LieSubalgebra R L) := ⟨fun K K' ↦ { (K ⊓ K' : Submodule R L) with lie_mem' := fun hx hy ↦ mem_inter (K.lie_mem hx.1 hy.1) (K'.lie_mem hx.2 hy.2) }⟩ instance : InfSet (LieSubalgebra R L) := ⟨fun S ↦ { sInf {(s : Submodule R L) | s ∈ S} with lie_mem' := @fun x y hx hy ↦ by simp only [Submodule.mem_carrier, mem_iInter, Submodule.sInf_coe, mem_setOf_eq, forall_apply_eq_imp_iff₂, exists_imp, and_imp] at hx hy ⊢ intro K hK exact K.lie_mem (hx K hK) (hy K hK) }⟩ @[simp] theorem inf_coe : (↑(K ⊓ K') : Set L) = (K : Set L) ∩ (K' : Set L) := rfl #align lie_subalgebra.inf_coe LieSubalgebra.inf_coe @[simp] theorem sInf_coe_to_submodule (S : Set (LieSubalgebra R L)) : (↑(sInf S) : Submodule R L) = sInf {(s : Submodule R L) | s ∈ S} := rfl #align lie_subalgebra.Inf_coe_to_submodule LieSubalgebra.sInf_coe_to_submodule @[simp] theorem sInf_coe (S : Set (LieSubalgebra R L)) : (↑(sInf S) : Set L) = ⋂ s ∈ S, (s : Set L) := by rw [← coe_to_submodule, sInf_coe_to_submodule, Submodule.sInf_coe] ext x simp #align lie_subalgebra.Inf_coe LieSubalgebra.sInf_coe theorem sInf_glb (S : Set (LieSubalgebra R L)) : IsGLB S (sInf S) := by have h : ∀ K K' : LieSubalgebra R L, (K : Set L) ≤ K' ↔ K ≤ K' := by intros exact Iff.rfl apply IsGLB.of_image @h simp only [sInf_coe] exact isGLB_biInf #align lie_subalgebra.Inf_glb LieSubalgebra.sInf_glb /-- The set of Lie subalgebras of a Lie algebra form a complete lattice. We provide explicit values for the fields `bot`, `top`, `inf` to get more convenient definitions than we would otherwise obtain from `completeLatticeOfInf`. -/ instance completeLattice : CompleteLattice (LieSubalgebra R L) := { completeLatticeOfInf _ sInf_glb with bot := ⊥ bot_le := fun N _ h ↦ by rw [mem_bot] at h rw [h] exact N.zero_mem' top := ⊤ le_top := fun _ _ _ ↦ trivial inf := (· ⊓ ·) le_inf := fun N₁ N₂ N₃ h₁₂ h₁₃ m hm ↦ ⟨h₁₂ hm, h₁₃ hm⟩ inf_le_left := fun _ _ _ ↦ And.left inf_le_right := fun _ _ _ ↦ And.right } instance : Add (LieSubalgebra R L) where add := Sup.sup instance : Zero (LieSubalgebra R L) where zero := ⊥ instance addCommMonoid : AddCommMonoid (LieSubalgebra R L) where add_assoc := sup_assoc zero_add := bot_sup_eq add_zero := sup_bot_eq add_comm := sup_comm nsmul := nsmulRec instance : CanonicallyOrderedAddCommMonoid (LieSubalgebra R L) := { LieSubalgebra.addCommMonoid, LieSubalgebra.completeLattice with add_le_add_left := fun _a _b ↦ sup_le_sup_left exists_add_of_le := @fun _a b h ↦ ⟨b, (sup_eq_right.2 h).symm⟩ le_self_add := fun _a _b ↦ le_sup_left } @[simp] theorem add_eq_sup : K + K' = K ⊔ K' := rfl #align lie_subalgebra.add_eq_sup LieSubalgebra.add_eq_sup @[simp] theorem inf_coe_to_submodule : (↑(K ⊓ K') : Submodule R L) = (K : Submodule R L) ⊓ (K' : Submodule R L) := rfl #align lie_subalgebra.inf_coe_to_submodule LieSubalgebra.inf_coe_to_submodule @[simp] theorem mem_inf (x : L) : x ∈ K ⊓ K' ↔ x ∈ K ∧ x ∈ K' := by rw [← mem_coe_submodule, ← mem_coe_submodule, ← mem_coe_submodule, inf_coe_to_submodule, Submodule.mem_inf] #align lie_subalgebra.mem_inf LieSubalgebra.mem_inf theorem eq_bot_iff : K = ⊥ ↔ ∀ x : L, x ∈ K → x = 0 := by rw [_root_.eq_bot_iff] exact Iff.rfl #align lie_subalgebra.eq_bot_iff LieSubalgebra.eq_bot_iff instance subsingleton_of_bot : Subsingleton (LieSubalgebra R (⊥ : LieSubalgebra R L)) := by apply subsingleton_of_bot_eq_top ext ⟨x, hx⟩; change x ∈ ⊥ at hx; rw [LieSubalgebra.mem_bot] at hx; subst hx simp only [true_iff_iff, eq_self_iff_true, Submodule.mk_eq_zero, mem_bot, mem_top] #align lie_subalgebra.subsingleton_of_bot LieSubalgebra.subsingleton_of_bot theorem subsingleton_bot : Subsingleton (⊥ : LieSubalgebra R L) := show Subsingleton ((⊥ : LieSubalgebra R L) : Set L) by simp #align lie_subalgebra.subsingleton_bot LieSubalgebra.subsingleton_bot variable (R L) theorem wellFounded_of_noetherian [IsNoetherian R L] : WellFounded ((· > ·) : LieSubalgebra R L → LieSubalgebra R L → Prop) := let f : ((· > ·) : LieSubalgebra R L → LieSubalgebra R L → Prop) →r ((· > ·) : Submodule R L → Submodule R L → Prop) := { toFun := (↑) map_rel' := @fun _ _ h ↦ h } RelHomClass.wellFounded f (isNoetherian_iff_wellFounded.mp inferInstance) #align lie_subalgebra.well_founded_of_noetherian LieSubalgebra.wellFounded_of_noetherian variable {R L K K' f} section NestedSubalgebras variable (h : K ≤ K') /-- Given two nested Lie subalgebras `K ⊆ K'`, the inclusion `K ↪ K'` is a morphism of Lie algebras. -/ def inclusion : K →ₗ⁅R⁆ K' := { Submodule.inclusion h with map_lie' := @fun _ _ ↦ rfl } #align lie_subalgebra.hom_of_le LieSubalgebra.inclusion @[simp] theorem coe_inclusion (x : K) : (inclusion h x : L) = x := rfl #align lie_subalgebra.coe_hom_of_le LieSubalgebra.coe_inclusion theorem inclusion_apply (x : K) : inclusion h x = ⟨x.1, h x.2⟩ := rfl #align lie_subalgebra.hom_of_le_apply LieSubalgebra.inclusion_apply theorem inclusion_injective : Function.Injective (inclusion h) := fun x y ↦ by simp only [inclusion_apply, imp_self, Subtype.mk_eq_mk, SetLike.coe_eq_coe] #align lie_subalgebra.hom_of_le_injective LieSubalgebra.inclusion_injective /-- Given two nested Lie subalgebras `K ⊆ K'`, we can view `K` as a Lie subalgebra of `K'`, regarded as Lie algebra in its own right. -/ def ofLe : LieSubalgebra R K' := (inclusion h).range #align lie_subalgebra.of_le LieSubalgebra.ofLe @[simp] theorem mem_ofLe (x : K') : x ∈ ofLe h ↔ (x : L) ∈ K := by simp only [ofLe, inclusion_apply, LieHom.mem_range] constructor · rintro ⟨y, rfl⟩ exact y.property · intro h use ⟨(x : L), h⟩ #align lie_subalgebra.mem_of_le LieSubalgebra.mem_ofLe theorem ofLe_eq_comap_incl : ofLe h = K.comap K'.incl := by ext rw [mem_ofLe] rfl #align lie_subalgebra.of_le_eq_comap_incl LieSubalgebra.ofLe_eq_comap_incl @[simp] theorem coe_ofLe : (ofLe h : Submodule R K') = LinearMap.range (Submodule.inclusion h) := rfl #align lie_subalgebra.coe_of_le LieSubalgebra.coe_ofLe /-- Given nested Lie subalgebras `K ⊆ K'`, there is a natural equivalence from `K` to its image in `K'`. -/ noncomputable def equivOfLe : K ≃ₗ⁅R⁆ ofLe h := (inclusion h).equivRangeOfInjective (inclusion_injective h) #align lie_subalgebra.equiv_of_le LieSubalgebra.equivOfLe @[simp] theorem equivOfLe_apply (x : K) : equivOfLe h x = ⟨inclusion h x, (inclusion h).mem_range_self x⟩ := rfl #align lie_subalgebra.equiv_of_le_apply LieSubalgebra.equivOfLe_apply end NestedSubalgebras theorem map_le_iff_le_comap {K : LieSubalgebra R L} {K' : LieSubalgebra R L₂} : map f K ≤ K' ↔ K ≤ comap f K' := Set.image_subset_iff #align lie_subalgebra.map_le_iff_le_comap LieSubalgebra.map_le_iff_le_comap theorem gc_map_comap : GaloisConnection (map f) (comap f) := fun _ _ ↦ map_le_iff_le_comap #align lie_subalgebra.gc_map_comap LieSubalgebra.gc_map_comap end LatticeStructure section LieSpan variable (R L) (s : Set L) /-- The Lie subalgebra of a Lie algebra `L` generated by a subset `s ⊆ L`. -/ def lieSpan : LieSubalgebra R L := sInf { N | s ⊆ N } #align lie_subalgebra.lie_span LieSubalgebra.lieSpan variable {R L s} theorem mem_lieSpan {x : L} : x ∈ lieSpan R L s ↔ ∀ K : LieSubalgebra R L, s ⊆ K → x ∈ K := by change x ∈ (lieSpan R L s : Set L) ↔ _ erw [sInf_coe] exact Set.mem_iInter₂ #align lie_subalgebra.mem_lie_span LieSubalgebra.mem_lieSpan theorem subset_lieSpan : s ⊆ lieSpan R L s := by intro m hm erw [mem_lieSpan] intro K hK exact hK hm #align lie_subalgebra.subset_lie_span LieSubalgebra.subset_lieSpan theorem submodule_span_le_lieSpan : Submodule.span R s ≤ lieSpan R L s := by rw [Submodule.span_le] apply subset_lieSpan #align lie_subalgebra.submodule_span_le_lie_span LieSubalgebra.submodule_span_le_lieSpan theorem lieSpan_le {K} : lieSpan R L s ≤ K ↔ s ⊆ K := by constructor · exact Set.Subset.trans subset_lieSpan · intro hs m hm rw [mem_lieSpan] at hm exact hm _ hs #align lie_subalgebra.lie_span_le LieSubalgebra.lieSpan_le theorem lieSpan_mono {t : Set L} (h : s ⊆ t) : lieSpan R L s ≤ lieSpan R L t := by rw [lieSpan_le] exact Set.Subset.trans h subset_lieSpan #align lie_subalgebra.lie_span_mono LieSubalgebra.lieSpan_mono theorem lieSpan_eq : lieSpan R L (K : Set L) = K := le_antisymm (lieSpan_le.mpr rfl.subset) subset_lieSpan #align lie_subalgebra.lie_span_eq LieSubalgebra.lieSpan_eq
Mathlib/Algebra/Lie/Subalgebra.lean
706
712
theorem coe_lieSpan_submodule_eq_iff {p : Submodule R L} : (lieSpan R L (p : Set L) : Submodule R L) = p ↔ ∃ K : LieSubalgebra R L, ↑K = p := by
rw [p.exists_lieSubalgebra_coe_eq_iff]; constructor <;> intro h · intro x m hm rw [← h, mem_coe_submodule] exact lie_mem _ (subset_lieSpan hm) · rw [← coe_to_submodule_mk p @h, coe_to_submodule, coe_to_submodule_eq_iff, lieSpan_eq]
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Data.Finset.Attr import Mathlib.Data.Multiset.FinsetOps import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Basic #align_import data.finset.basic from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Finite sets Terms of type `Finset α` are one way of talking about finite subsets of `α` in mathlib. Below, `Finset α` is defined as a structure with 2 fields: 1. `val` is a `Multiset α` of elements; 2. `nodup` is a proof that `val` has no duplicates. Finsets in Lean are constructive in that they have an underlying `List` that enumerates their elements. In particular, any function that uses the data of the underlying list cannot depend on its ordering. This is handled on the `Multiset` level by multiset API, so in most cases one needn't worry about it explicitly. Finsets give a basic foundation for defining finite sums and products over types: 1. `∑ i ∈ (s : Finset α), f i`; 2. `∏ i ∈ (s : Finset α), f i`. Lean refers to these operations as big operators. More information can be found in `Mathlib.Algebra.BigOperators.Group.Finset`. Finsets are directly used to define fintypes in Lean. A `Fintype α` instance for a type `α` consists of a universal `Finset α` containing every term of `α`, called `univ`. See `Mathlib.Data.Fintype.Basic`. There is also `univ'`, the noncomputable partner to `univ`, which is defined to be `α` as a finset if `α` is finite, and the empty finset otherwise. See `Mathlib.Data.Fintype.Basic`. `Finset.card`, the size of a finset is defined in `Mathlib.Data.Finset.Card`. This is then used to define `Fintype.card`, the size of a type. ## Main declarations ### Main definitions * `Finset`: Defines a type for the finite subsets of `α`. Constructing a `Finset` requires two pieces of data: `val`, a `Multiset α` of elements, and `nodup`, a proof that `val` has no duplicates. * `Finset.instMembershipFinset`: Defines membership `a ∈ (s : Finset α)`. * `Finset.instCoeTCFinsetSet`: Provides a coercion `s : Finset α` to `s : Set α`. * `Finset.instCoeSortFinsetType`: Coerce `s : Finset α` to the type of all `x ∈ s`. * `Finset.induction_on`: Induction on finsets. To prove a proposition about an arbitrary `Finset α`, it suffices to prove it for the empty finset, and to show that if it holds for some `Finset α`, then it holds for the finset obtained by inserting a new element. * `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate. ### Finset constructions * `Finset.instSingletonFinset`: Denoted by `{a}`; the finset consisting of one element. * `Finset.empty`: Denoted by `∅`. The finset associated to any type consisting of no elements. * `Finset.range`: For any `n : ℕ`, `range n` is equal to `{0, 1, ... , n - 1} ⊆ ℕ`. This convention is consistent with other languages and normalizes `card (range n) = n`. Beware, `n` is not in `range n`. * `Finset.attach`: Given `s : Finset α`, `attach s` forms a finset of elements of the subtype `{a // a ∈ s}`; in other words, it attaches elements to a proof of membership in the set. ### Finsets from functions * `Finset.filter`: Given a decidable predicate `p : α → Prop`, `s.filter p` is the finset consisting of those elements in `s` satisfying the predicate `p`. ### The lattice structure on subsets of finsets There is a natural lattice structure on the subsets of a set. In Lean, we use lattice notation to talk about things involving unions and intersections. See `Mathlib.Order.Lattice`. For the lattice structure on finsets, `⊥` is called `bot` with `⊥ = ∅` and `⊤` is called `top` with `⊤ = univ`. * `Finset.instHasSubsetFinset`: Lots of API about lattices, otherwise behaves as one would expect. * `Finset.instUnionFinset`: Defines `s ∪ t` (or `s ⊔ t`) as the union of `s` and `t`. See `Finset.sup`/`Finset.biUnion` for finite unions. * `Finset.instInterFinset`: Defines `s ∩ t` (or `s ⊓ t`) as the intersection of `s` and `t`. See `Finset.inf` for finite intersections. ### Operations on two or more finsets * `insert` and `Finset.cons`: For any `a : α`, `insert s a` returns `s ∪ {a}`. `cons s a h` returns the same except that it requires a hypothesis stating that `a` is not already in `s`. This does not require decidable equality on the type `α`. * `Finset.instUnionFinset`: see "The lattice structure on subsets of finsets" * `Finset.instInterFinset`: see "The lattice structure on subsets of finsets" * `Finset.erase`: For any `a : α`, `erase s a` returns `s` with the element `a` removed. * `Finset.instSDiffFinset`: Defines the set difference `s \ t` for finsets `s` and `t`. * `Finset.product`: Given finsets of `α` and `β`, defines finsets of `α × β`. For arbitrary dependent products, see `Mathlib.Data.Finset.Pi`. ### Predicates on finsets * `Disjoint`: defined via the lattice structure on finsets; two sets are disjoint if their intersection is empty. * `Finset.Nonempty`: A finset is nonempty if it has elements. This is equivalent to saying `s ≠ ∅`. ### Equivalences between finsets * The `Mathlib.Data.Equiv` files describe a general type of equivalence, so look in there for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`. TODO: examples ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen assert_not_exists Multiset.Powerset assert_not_exists CompleteLattice open Multiset Subtype Nat Function universe u variable {α : Type*} {β : Type*} {γ : Type*} /-- `Finset α` is the type of finite sets of elements of `α`. It is implemented as a multiset (a list up to permutation) which has no duplicate elements. -/ structure Finset (α : Type*) where /-- The underlying multiset -/ val : Multiset α /-- `val` contains no duplicates -/ nodup : Nodup val #align finset Finset instance Multiset.canLiftFinset {α} : CanLift (Multiset α) (Finset α) Finset.val Multiset.Nodup := ⟨fun m hm => ⟨⟨m, hm⟩, rfl⟩⟩ #align multiset.can_lift_finset Multiset.canLiftFinset namespace Finset theorem eq_of_veq : ∀ {s t : Finset α}, s.1 = t.1 → s = t | ⟨s, _⟩, ⟨t, _⟩, h => by cases h; rfl #align finset.eq_of_veq Finset.eq_of_veq theorem val_injective : Injective (val : Finset α → Multiset α) := fun _ _ => eq_of_veq #align finset.val_injective Finset.val_injective @[simp] theorem val_inj {s t : Finset α} : s.1 = t.1 ↔ s = t := val_injective.eq_iff #align finset.val_inj Finset.val_inj @[simp] theorem dedup_eq_self [DecidableEq α] (s : Finset α) : dedup s.1 = s.1 := s.2.dedup #align finset.dedup_eq_self Finset.dedup_eq_self instance decidableEq [DecidableEq α] : DecidableEq (Finset α) | _, _ => decidable_of_iff _ val_inj #align finset.has_decidable_eq Finset.decidableEq /-! ### membership -/ instance : Membership α (Finset α) := ⟨fun a s => a ∈ s.1⟩ theorem mem_def {a : α} {s : Finset α} : a ∈ s ↔ a ∈ s.1 := Iff.rfl #align finset.mem_def Finset.mem_def @[simp] theorem mem_val {a : α} {s : Finset α} : a ∈ s.1 ↔ a ∈ s := Iff.rfl #align finset.mem_val Finset.mem_val @[simp] theorem mem_mk {a : α} {s nd} : a ∈ @Finset.mk α s nd ↔ a ∈ s := Iff.rfl #align finset.mem_mk Finset.mem_mk instance decidableMem [_h : DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ s) := Multiset.decidableMem _ _ #align finset.decidable_mem Finset.decidableMem @[simp] lemma forall_mem_not_eq {s : Finset α} {a : α} : (∀ b ∈ s, ¬ a = b) ↔ a ∉ s := by aesop @[simp] lemma forall_mem_not_eq' {s : Finset α} {a : α} : (∀ b ∈ s, ¬ b = a) ↔ a ∉ s := by aesop /-! ### set coercion -/ -- Porting note (#11445): new definition /-- Convert a finset to a set in the natural way. -/ @[coe] def toSet (s : Finset α) : Set α := { a | a ∈ s } /-- Convert a finset to a set in the natural way. -/ instance : CoeTC (Finset α) (Set α) := ⟨toSet⟩ @[simp, norm_cast] theorem mem_coe {a : α} {s : Finset α} : a ∈ (s : Set α) ↔ a ∈ (s : Finset α) := Iff.rfl #align finset.mem_coe Finset.mem_coe @[simp] theorem setOf_mem {α} {s : Finset α} : { a | a ∈ s } = s := rfl #align finset.set_of_mem Finset.setOf_mem @[simp] theorem coe_mem {s : Finset α} (x : (s : Set α)) : ↑x ∈ s := x.2 #align finset.coe_mem Finset.coe_mem -- Porting note (#10618): @[simp] can prove this theorem mk_coe {s : Finset α} (x : (s : Set α)) {h} : (⟨x, h⟩ : (s : Set α)) = x := Subtype.coe_eta _ _ #align finset.mk_coe Finset.mk_coe instance decidableMem' [DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ (s : Set α)) := s.decidableMem _ #align finset.decidable_mem' Finset.decidableMem' /-! ### extensionality -/ theorem ext_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ ∀ a, a ∈ s₁ ↔ a ∈ s₂ := val_inj.symm.trans <| s₁.nodup.ext s₂.nodup #align finset.ext_iff Finset.ext_iff @[ext] theorem ext {s₁ s₂ : Finset α} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ := ext_iff.2 #align finset.ext Finset.ext @[simp, norm_cast] theorem coe_inj {s₁ s₂ : Finset α} : (s₁ : Set α) = s₂ ↔ s₁ = s₂ := Set.ext_iff.trans ext_iff.symm #align finset.coe_inj Finset.coe_inj theorem coe_injective {α} : Injective ((↑) : Finset α → Set α) := fun _s _t => coe_inj.1 #align finset.coe_injective Finset.coe_injective /-! ### type coercion -/ /-- Coercion from a finset to the corresponding subtype. -/ instance {α : Type u} : CoeSort (Finset α) (Type u) := ⟨fun s => { x // x ∈ s }⟩ -- Porting note (#10618): @[simp] can prove this protected theorem forall_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∀ x : s, p x) ↔ ∀ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align finset.forall_coe Finset.forall_coe -- Porting note (#10618): @[simp] can prove this protected theorem exists_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∃ x : s, p x) ↔ ∃ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align finset.exists_coe Finset.exists_coe instance PiFinsetCoe.canLift (ι : Type*) (α : ι → Type*) [_ne : ∀ i, Nonempty (α i)] (s : Finset ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α (· ∈ s) #align finset.pi_finset_coe.can_lift Finset.PiFinsetCoe.canLift instance PiFinsetCoe.canLift' (ι α : Type*) [_ne : Nonempty α] (s : Finset ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiFinsetCoe.canLift ι (fun _ => α) s #align finset.pi_finset_coe.can_lift' Finset.PiFinsetCoe.canLift' instance FinsetCoe.canLift (s : Finset α) : CanLift α s (↑) fun a => a ∈ s where prf a ha := ⟨⟨a, ha⟩, rfl⟩ #align finset.finset_coe.can_lift Finset.FinsetCoe.canLift @[simp, norm_cast] theorem coe_sort_coe (s : Finset α) : ((s : Set α) : Sort _) = s := rfl #align finset.coe_sort_coe Finset.coe_sort_coe /-! ### Subset and strict subset relations -/ section Subset variable {s t : Finset α} instance : HasSubset (Finset α) := ⟨fun s t => ∀ ⦃a⦄, a ∈ s → a ∈ t⟩ instance : HasSSubset (Finset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance partialOrder : PartialOrder (Finset α) where le := (· ⊆ ·) lt := (· ⊂ ·) le_refl s a := id le_trans s t u hst htu a ha := htu <| hst ha le_antisymm s t hst hts := ext fun a => ⟨@hst _, @hts _⟩ instance : IsRefl (Finset α) (· ⊆ ·) := show IsRefl (Finset α) (· ≤ ·) by infer_instance instance : IsTrans (Finset α) (· ⊆ ·) := show IsTrans (Finset α) (· ≤ ·) by infer_instance instance : IsAntisymm (Finset α) (· ⊆ ·) := show IsAntisymm (Finset α) (· ≤ ·) by infer_instance instance : IsIrrefl (Finset α) (· ⊂ ·) := show IsIrrefl (Finset α) (· < ·) by infer_instance instance : IsTrans (Finset α) (· ⊂ ·) := show IsTrans (Finset α) (· < ·) by infer_instance instance : IsAsymm (Finset α) (· ⊂ ·) := show IsAsymm (Finset α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Finset α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ theorem subset_def : s ⊆ t ↔ s.1 ⊆ t.1 := Iff.rfl #align finset.subset_def Finset.subset_def theorem ssubset_def : s ⊂ t ↔ s ⊆ t ∧ ¬t ⊆ s := Iff.rfl #align finset.ssubset_def Finset.ssubset_def @[simp] theorem Subset.refl (s : Finset α) : s ⊆ s := Multiset.Subset.refl _ #align finset.subset.refl Finset.Subset.refl protected theorem Subset.rfl {s : Finset α} : s ⊆ s := Subset.refl _ #align finset.subset.rfl Finset.Subset.rfl protected theorem subset_of_eq {s t : Finset α} (h : s = t) : s ⊆ t := h ▸ Subset.refl _ #align finset.subset_of_eq Finset.subset_of_eq theorem Subset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ := Multiset.Subset.trans #align finset.subset.trans Finset.Subset.trans theorem Superset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ := fun h' h => Subset.trans h h' #align finset.superset.trans Finset.Superset.trans theorem mem_of_subset {s₁ s₂ : Finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := Multiset.mem_of_subset #align finset.mem_of_subset Finset.mem_of_subset theorem not_mem_mono {s t : Finset α} (h : s ⊆ t) {a : α} : a ∉ t → a ∉ s := mt <| @h _ #align finset.not_mem_mono Finset.not_mem_mono theorem Subset.antisymm {s₁ s₂ : Finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ := ext fun a => ⟨@H₁ a, @H₂ a⟩ #align finset.subset.antisymm Finset.Subset.antisymm theorem subset_iff {s₁ s₂ : Finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ := Iff.rfl #align finset.subset_iff Finset.subset_iff @[simp, norm_cast] theorem coe_subset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊆ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.coe_subset Finset.coe_subset @[simp] theorem val_le_iff {s₁ s₂ : Finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ := le_iff_subset s₁.2 #align finset.val_le_iff Finset.val_le_iff theorem Subset.antisymm_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ := le_antisymm_iff #align finset.subset.antisymm_iff Finset.Subset.antisymm_iff theorem not_subset : ¬s ⊆ t ↔ ∃ x ∈ s, x ∉ t := by simp only [← coe_subset, Set.not_subset, mem_coe] #align finset.not_subset Finset.not_subset @[simp] theorem le_eq_subset : ((· ≤ ·) : Finset α → Finset α → Prop) = (· ⊆ ·) := rfl #align finset.le_eq_subset Finset.le_eq_subset @[simp] theorem lt_eq_subset : ((· < ·) : Finset α → Finset α → Prop) = (· ⊂ ·) := rfl #align finset.lt_eq_subset Finset.lt_eq_subset theorem le_iff_subset {s₁ s₂ : Finset α} : s₁ ≤ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.le_iff_subset Finset.le_iff_subset theorem lt_iff_ssubset {s₁ s₂ : Finset α} : s₁ < s₂ ↔ s₁ ⊂ s₂ := Iff.rfl #align finset.lt_iff_ssubset Finset.lt_iff_ssubset @[simp, norm_cast] theorem coe_ssubset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊂ s₂ := show (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊆ s₂ ∧ ¬s₂ ⊆ s₁ by simp only [Set.ssubset_def, Finset.coe_subset] #align finset.coe_ssubset Finset.coe_ssubset @[simp] theorem val_lt_iff {s₁ s₂ : Finset α} : s₁.1 < s₂.1 ↔ s₁ ⊂ s₂ := and_congr val_le_iff <| not_congr val_le_iff #align finset.val_lt_iff Finset.val_lt_iff lemma val_strictMono : StrictMono (val : Finset α → Multiset α) := fun _ _ ↦ val_lt_iff.2 theorem ssubset_iff_subset_ne {s t : Finset α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne _ _ s t #align finset.ssubset_iff_subset_ne Finset.ssubset_iff_subset_ne theorem ssubset_iff_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁ ⊂ s₂ ↔ ∃ x ∈ s₂, x ∉ s₁ := Set.ssubset_iff_of_subset h #align finset.ssubset_iff_of_subset Finset.ssubset_iff_of_subset theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_ssubset_of_subset hs₁s₂ hs₂s₃ #align finset.ssubset_of_ssubset_of_subset Finset.ssubset_of_ssubset_of_subset theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_subset_of_ssubset hs₁s₂ hs₂s₃ #align finset.ssubset_of_subset_of_ssubset Finset.ssubset_of_subset_of_ssubset theorem exists_of_ssubset {s₁ s₂ : Finset α} (h : s₁ ⊂ s₂) : ∃ x ∈ s₂, x ∉ s₁ := Set.exists_of_ssubset h #align finset.exists_of_ssubset Finset.exists_of_ssubset instance isWellFounded_ssubset : IsWellFounded (Finset α) (· ⊂ ·) := Subrelation.isWellFounded (InvImage _ _) val_lt_iff.2 #align finset.is_well_founded_ssubset Finset.isWellFounded_ssubset instance wellFoundedLT : WellFoundedLT (Finset α) := Finset.isWellFounded_ssubset #align finset.is_well_founded_lt Finset.wellFoundedLT end Subset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans /-! ### Order embedding from `Finset α` to `Set α` -/ /-- Coercion to `Set α` as an `OrderEmbedding`. -/ def coeEmb : Finset α ↪o Set α := ⟨⟨(↑), coe_injective⟩, coe_subset⟩ #align finset.coe_emb Finset.coeEmb @[simp] theorem coe_coeEmb : ⇑(coeEmb : Finset α ↪o Set α) = ((↑) : Finset α → Set α) := rfl #align finset.coe_coe_emb Finset.coe_coeEmb /-! ### Nonempty -/ /-- The property `s.Nonempty` expresses the fact that the finset `s` is not empty. It should be used in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks to the dot notation. -/ protected def Nonempty (s : Finset α) : Prop := ∃ x : α, x ∈ s #align finset.nonempty Finset.Nonempty -- Porting note: Much longer than in Lean3 instance decidableNonempty {s : Finset α} : Decidable s.Nonempty := Quotient.recOnSubsingleton (motive := fun s : Multiset α => Decidable (∃ a, a ∈ s)) s.1 (fun l : List α => match l with | [] => isFalse <| by simp | a::l => isTrue ⟨a, by simp⟩) #align finset.decidable_nonempty Finset.decidableNonempty @[simp, norm_cast] theorem coe_nonempty {s : Finset α} : (s : Set α).Nonempty ↔ s.Nonempty := Iff.rfl #align finset.coe_nonempty Finset.coe_nonempty -- Porting note: Left-hand side simplifies @[simp] theorem nonempty_coe_sort {s : Finset α} : Nonempty (s : Type _) ↔ s.Nonempty := nonempty_subtype #align finset.nonempty_coe_sort Finset.nonempty_coe_sort alias ⟨_, Nonempty.to_set⟩ := coe_nonempty #align finset.nonempty.to_set Finset.Nonempty.to_set alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort #align finset.nonempty.coe_sort Finset.Nonempty.coe_sort theorem Nonempty.exists_mem {s : Finset α} (h : s.Nonempty) : ∃ x : α, x ∈ s := h #align finset.nonempty.bex Finset.Nonempty.exists_mem @[deprecated (since := "2024-03-23")] alias Nonempty.bex := Nonempty.exists_mem theorem Nonempty.mono {s t : Finset α} (hst : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := Set.Nonempty.mono hst hs #align finset.nonempty.mono Finset.Nonempty.mono theorem Nonempty.forall_const {s : Finset α} (h : s.Nonempty) {p : Prop} : (∀ x ∈ s, p) ↔ p := let ⟨x, hx⟩ := h ⟨fun h => h x hx, fun h _ _ => h⟩ #align finset.nonempty.forall_const Finset.Nonempty.forall_const theorem Nonempty.to_subtype {s : Finset α} : s.Nonempty → Nonempty s := nonempty_coe_sort.2 #align finset.nonempty.to_subtype Finset.Nonempty.to_subtype theorem Nonempty.to_type {s : Finset α} : s.Nonempty → Nonempty α := fun ⟨x, _hx⟩ => ⟨x⟩ #align finset.nonempty.to_type Finset.Nonempty.to_type /-! ### empty -/ section Empty variable {s : Finset α} /-- The empty finset -/ protected def empty : Finset α := ⟨0, nodup_zero⟩ #align finset.empty Finset.empty instance : EmptyCollection (Finset α) := ⟨Finset.empty⟩ instance inhabitedFinset : Inhabited (Finset α) := ⟨∅⟩ #align finset.inhabited_finset Finset.inhabitedFinset @[simp] theorem empty_val : (∅ : Finset α).1 = 0 := rfl #align finset.empty_val Finset.empty_val @[simp] theorem not_mem_empty (a : α) : a ∉ (∅ : Finset α) := by -- Porting note: was `id`. `a ∈ List.nil` is no longer definitionally equal to `False` simp only [mem_def, empty_val, not_mem_zero, not_false_iff] #align finset.not_mem_empty Finset.not_mem_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Finset α).Nonempty := fun ⟨x, hx⟩ => not_mem_empty x hx #align finset.not_nonempty_empty Finset.not_nonempty_empty @[simp] theorem mk_zero : (⟨0, nodup_zero⟩ : Finset α) = ∅ := rfl #align finset.mk_zero Finset.mk_zero theorem ne_empty_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ≠ ∅ := fun e => not_mem_empty a <| e ▸ h #align finset.ne_empty_of_mem Finset.ne_empty_of_mem theorem Nonempty.ne_empty {s : Finset α} (h : s.Nonempty) : s ≠ ∅ := (Exists.elim h) fun _a => ne_empty_of_mem #align finset.nonempty.ne_empty Finset.Nonempty.ne_empty @[simp] theorem empty_subset (s : Finset α) : ∅ ⊆ s := zero_subset _ #align finset.empty_subset Finset.empty_subset theorem eq_empty_of_forall_not_mem {s : Finset α} (H : ∀ x, x ∉ s) : s = ∅ := eq_of_veq (eq_zero_of_forall_not_mem H) #align finset.eq_empty_of_forall_not_mem Finset.eq_empty_of_forall_not_mem theorem eq_empty_iff_forall_not_mem {s : Finset α} : s = ∅ ↔ ∀ x, x ∉ s := -- Porting note: used `id` ⟨by rintro rfl x; apply not_mem_empty, fun h => eq_empty_of_forall_not_mem h⟩ #align finset.eq_empty_iff_forall_not_mem Finset.eq_empty_iff_forall_not_mem @[simp] theorem val_eq_zero {s : Finset α} : s.1 = 0 ↔ s = ∅ := @val_inj _ s ∅ #align finset.val_eq_zero Finset.val_eq_zero theorem subset_empty {s : Finset α} : s ⊆ ∅ ↔ s = ∅ := subset_zero.trans val_eq_zero #align finset.subset_empty Finset.subset_empty @[simp] theorem not_ssubset_empty (s : Finset α) : ¬s ⊂ ∅ := fun h => let ⟨_, he, _⟩ := exists_of_ssubset h -- Porting note: was `he` not_mem_empty _ he #align finset.not_ssubset_empty Finset.not_ssubset_empty theorem nonempty_of_ne_empty {s : Finset α} (h : s ≠ ∅) : s.Nonempty := exists_mem_of_ne_zero (mt val_eq_zero.1 h) #align finset.nonempty_of_ne_empty Finset.nonempty_of_ne_empty theorem nonempty_iff_ne_empty {s : Finset α} : s.Nonempty ↔ s ≠ ∅ := ⟨Nonempty.ne_empty, nonempty_of_ne_empty⟩ #align finset.nonempty_iff_ne_empty Finset.nonempty_iff_ne_empty @[simp] theorem not_nonempty_iff_eq_empty {s : Finset α} : ¬s.Nonempty ↔ s = ∅ := nonempty_iff_ne_empty.not.trans not_not #align finset.not_nonempty_iff_eq_empty Finset.not_nonempty_iff_eq_empty theorem eq_empty_or_nonempty (s : Finset α) : s = ∅ ∨ s.Nonempty := by_cases Or.inl fun h => Or.inr (nonempty_of_ne_empty h) #align finset.eq_empty_or_nonempty Finset.eq_empty_or_nonempty @[simp, norm_cast] theorem coe_empty : ((∅ : Finset α) : Set α) = ∅ := Set.ext <| by simp #align finset.coe_empty Finset.coe_empty @[simp, norm_cast] theorem coe_eq_empty {s : Finset α} : (s : Set α) = ∅ ↔ s = ∅ := by rw [← coe_empty, coe_inj] #align finset.coe_eq_empty Finset.coe_eq_empty -- Porting note: Left-hand side simplifies @[simp] theorem isEmpty_coe_sort {s : Finset α} : IsEmpty (s : Type _) ↔ s = ∅ := by simpa using @Set.isEmpty_coe_sort α s #align finset.is_empty_coe_sort Finset.isEmpty_coe_sort instance instIsEmpty : IsEmpty (∅ : Finset α) := isEmpty_coe_sort.2 rfl /-- A `Finset` for an empty type is empty. -/ theorem eq_empty_of_isEmpty [IsEmpty α] (s : Finset α) : s = ∅ := Finset.eq_empty_of_forall_not_mem isEmptyElim #align finset.eq_empty_of_is_empty Finset.eq_empty_of_isEmpty instance : OrderBot (Finset α) where bot := ∅ bot_le := empty_subset @[simp] theorem bot_eq_empty : (⊥ : Finset α) = ∅ := rfl #align finset.bot_eq_empty Finset.bot_eq_empty @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Finset α) _ _ _).trans nonempty_iff_ne_empty.symm #align finset.empty_ssubset Finset.empty_ssubset alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset #align finset.nonempty.empty_ssubset Finset.Nonempty.empty_ssubset end Empty /-! ### singleton -/ section Singleton variable {s : Finset α} {a b : α} /-- `{a} : Finset a` is the set `{a}` containing `a` and nothing else. This differs from `insert a ∅` in that it does not require a `DecidableEq` instance for `α`. -/ instance : Singleton α (Finset α) := ⟨fun a => ⟨{a}, nodup_singleton a⟩⟩ @[simp] theorem singleton_val (a : α) : ({a} : Finset α).1 = {a} := rfl #align finset.singleton_val Finset.singleton_val @[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : Finset α) ↔ b = a := Multiset.mem_singleton #align finset.mem_singleton Finset.mem_singleton theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Finset α)) : x = y := mem_singleton.1 h #align finset.eq_of_mem_singleton Finset.eq_of_mem_singleton theorem not_mem_singleton {a b : α} : a ∉ ({b} : Finset α) ↔ a ≠ b := not_congr mem_singleton #align finset.not_mem_singleton Finset.not_mem_singleton theorem mem_singleton_self (a : α) : a ∈ ({a} : Finset α) := -- Porting note: was `Or.inl rfl` mem_singleton.mpr rfl #align finset.mem_singleton_self Finset.mem_singleton_self @[simp] theorem val_eq_singleton_iff {a : α} {s : Finset α} : s.val = {a} ↔ s = {a} := by rw [← val_inj] rfl #align finset.val_eq_singleton_iff Finset.val_eq_singleton_iff theorem singleton_injective : Injective (singleton : α → Finset α) := fun _a _b h => mem_singleton.1 (h ▸ mem_singleton_self _) #align finset.singleton_injective Finset.singleton_injective @[simp] theorem singleton_inj : ({a} : Finset α) = {b} ↔ a = b := singleton_injective.eq_iff #align finset.singleton_inj Finset.singleton_inj @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem singleton_nonempty (a : α) : ({a} : Finset α).Nonempty := ⟨a, mem_singleton_self a⟩ #align finset.singleton_nonempty Finset.singleton_nonempty @[simp] theorem singleton_ne_empty (a : α) : ({a} : Finset α) ≠ ∅ := (singleton_nonempty a).ne_empty #align finset.singleton_ne_empty Finset.singleton_ne_empty theorem empty_ssubset_singleton : (∅ : Finset α) ⊂ {a} := (singleton_nonempty _).empty_ssubset #align finset.empty_ssubset_singleton Finset.empty_ssubset_singleton @[simp, norm_cast] theorem coe_singleton (a : α) : (({a} : Finset α) : Set α) = {a} := by ext simp #align finset.coe_singleton Finset.coe_singleton @[simp, norm_cast] theorem coe_eq_singleton {s : Finset α} {a : α} : (s : Set α) = {a} ↔ s = {a} := by rw [← coe_singleton, coe_inj] #align finset.coe_eq_singleton Finset.coe_eq_singleton @[norm_cast] lemma coe_subset_singleton : (s : Set α) ⊆ {a} ↔ s ⊆ {a} := by rw [← coe_subset, coe_singleton] @[norm_cast] lemma singleton_subset_coe : {a} ⊆ (s : Set α) ↔ {a} ⊆ s := by rw [← coe_subset, coe_singleton] theorem eq_singleton_iff_unique_mem {s : Finset α} {a : α} : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a := by constructor <;> intro t · rw [t] exact ⟨Finset.mem_singleton_self _, fun _ => Finset.mem_singleton.1⟩ · ext rw [Finset.mem_singleton] exact ⟨t.right _, fun r => r.symm ▸ t.left⟩ #align finset.eq_singleton_iff_unique_mem Finset.eq_singleton_iff_unique_mem theorem eq_singleton_iff_nonempty_unique_mem {s : Finset α} {a : α} : s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a := by constructor · rintro rfl simp · rintro ⟨hne, h_uniq⟩ rw [eq_singleton_iff_unique_mem] refine ⟨?_, h_uniq⟩ rw [← h_uniq hne.choose hne.choose_spec] exact hne.choose_spec #align finset.eq_singleton_iff_nonempty_unique_mem Finset.eq_singleton_iff_nonempty_unique_mem theorem nonempty_iff_eq_singleton_default [Unique α] {s : Finset α} : s.Nonempty ↔ s = {default} := by simp [eq_singleton_iff_nonempty_unique_mem, eq_iff_true_of_subsingleton] #align finset.nonempty_iff_eq_singleton_default Finset.nonempty_iff_eq_singleton_default alias ⟨Nonempty.eq_singleton_default, _⟩ := nonempty_iff_eq_singleton_default #align finset.nonempty.eq_singleton_default Finset.Nonempty.eq_singleton_default theorem singleton_iff_unique_mem (s : Finset α) : (∃ a, s = {a}) ↔ ∃! a, a ∈ s := by simp only [eq_singleton_iff_unique_mem, ExistsUnique] #align finset.singleton_iff_unique_mem Finset.singleton_iff_unique_mem
Mathlib/Data/Finset/Basic.lean
776
777
theorem singleton_subset_set_iff {s : Set α} {a : α} : ↑({a} : Finset α) ⊆ s ↔ a ∈ s := by
rw [coe_singleton, Set.singleton_subset_iff]
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Scott Morrison -/ import Mathlib.Algebra.Order.ZeroLEOne import Mathlib.Data.List.InsertNth import Mathlib.Logic.Relation import Mathlib.Logic.Small.Defs import Mathlib.Order.GameAdd #align_import set_theory.game.pgame from "leanprover-community/mathlib"@"8900d545017cd21961daa2a1734bb658ef52c618" /-! # Combinatorial (pre-)games. The basic theory of combinatorial games, following Conway's book `On Numbers and Games`. We construct "pregames", define an ordering and arithmetic operations on them, then show that the operations descend to "games", defined via the equivalence relation `p ≈ q ↔ p ≤ q ∧ q ≤ p`. The surreal numbers will be built as a quotient of a subtype of pregames. A pregame (`SetTheory.PGame` below) is axiomatised via an inductive type, whose sole constructor takes two types (thought of as indexing the possible moves for the players Left and Right), and a pair of functions out of these types to `SetTheory.PGame` (thought of as describing the resulting game after making a move). Combinatorial games themselves, as a quotient of pregames, are constructed in `Game.lean`. ## Conway induction By construction, the induction principle for pregames is exactly "Conway induction". That is, to prove some predicate `SetTheory.PGame → Prop` holds for all pregames, it suffices to prove that for every pregame `g`, if the predicate holds for every game resulting from making a move, then it also holds for `g`. While it is often convenient to work "by induction" on pregames, in some situations this becomes awkward, so we also define accessor functions `SetTheory.PGame.LeftMoves`, `SetTheory.PGame.RightMoves`, `SetTheory.PGame.moveLeft` and `SetTheory.PGame.moveRight`. There is a relation `PGame.Subsequent p q`, saying that `p` can be reached by playing some non-empty sequence of moves starting from `q`, an instance `WellFounded Subsequent`, and a local tactic `pgame_wf_tac` which is helpful for discharging proof obligations in inductive proofs relying on this relation. ## Order properties Pregames have both a `≤` and a `<` relation, satisfying the usual properties of a `Preorder`. The relation `0 < x` means that `x` can always be won by Left, while `0 ≤ x` means that `x` can be won by Left as the second player. It turns out to be quite convenient to define various relations on top of these. We define the "less or fuzzy" relation `x ⧏ y` as `¬ y ≤ x`, the equivalence relation `x ≈ y` as `x ≤ y ∧ y ≤ x`, and the fuzzy relation `x ‖ y` as `x ⧏ y ∧ y ⧏ x`. If `0 ⧏ x`, then `x` can be won by Left as the first player. If `x ≈ 0`, then `x` can be won by the second player. If `x ‖ 0`, then `x` can be won by the first player. Statements like `zero_le_lf`, `zero_lf_le`, etc. unfold these definitions. The theorems `le_def` and `lf_def` give a recursive characterisation of each relation in terms of themselves two moves later. The theorems `zero_le`, `zero_lf`, etc. also take into account that `0` has no moves. Later, games will be defined as the quotient by the `≈` relation; that is to say, the `Antisymmetrization` of `SetTheory.PGame`. ## Algebraic structures We next turn to defining the operations necessary to make games into a commutative additive group. Addition is defined for $x = \{xL | xR\}$ and $y = \{yL | yR\}$ by $x + y = \{xL + y, x + yL | xR + y, x + yR\}$. Negation is defined by $\{xL | xR\} = \{-xR | -xL\}$. The order structures interact in the expected way with addition, so we have ``` theorem le_iff_sub_nonneg {x y : PGame} : x ≤ y ↔ 0 ≤ y - x := sorry theorem lt_iff_sub_pos {x y : PGame} : x < y ↔ 0 < y - x := sorry ``` We show that these operations respect the equivalence relation, and hence descend to games. At the level of games, these operations satisfy all the laws of a commutative group. To prove the necessary equivalence relations at the level of pregames, we introduce the notion of a `Relabelling` of a game, and show, for example, that there is a relabelling between `x + (y + z)` and `(x + y) + z`. ## Future work * The theory of dominated and reversible positions, and unique normal form for short games. * Analysis of basic domineering positions. * Hex. * Temperature. * The development of surreal numbers, based on this development of combinatorial games, is still quite incomplete. ## References The material here is all drawn from * [Conway, *On numbers and games*][conway2001] An interested reader may like to formalise some of the material from * [Andreas Blass, *A game semantics for linear logic*][MR1167694] * [André Joyal, *Remarques sur la théorie des jeux à deux personnes*][joyal1997] -/ set_option autoImplicit true namespace SetTheory open Function Relation -- We'd like to be able to use multi-character auto-implicits in this file. set_option relaxedAutoImplicit true /-! ### Pre-game moves -/ /-- The type of pre-games, before we have quotiented by equivalence (`PGame.Setoid`). In ZFC, a combinatorial game is constructed from two sets of combinatorial games that have been constructed at an earlier stage. To do this in type theory, we say that a pre-game is built inductively from two families of pre-games indexed over any type in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`, reflecting that it is a proper class in ZFC. -/ inductive PGame : Type (u + 1) | mk : ∀ α β : Type u, (α → PGame) → (β → PGame) → PGame #align pgame SetTheory.PGame compile_inductive% PGame namespace PGame /-- The indexing type for allowable moves by Left. -/ def LeftMoves : PGame → Type u | mk l _ _ _ => l #align pgame.left_moves SetTheory.PGame.LeftMoves /-- The indexing type for allowable moves by Right. -/ def RightMoves : PGame → Type u | mk _ r _ _ => r #align pgame.right_moves SetTheory.PGame.RightMoves /-- The new game after Left makes an allowed move. -/ def moveLeft : ∀ g : PGame, LeftMoves g → PGame | mk _l _ L _ => L #align pgame.move_left SetTheory.PGame.moveLeft /-- The new game after Right makes an allowed move. -/ def moveRight : ∀ g : PGame, RightMoves g → PGame | mk _ _r _ R => R #align pgame.move_right SetTheory.PGame.moveRight @[simp] theorem leftMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).LeftMoves = xl := rfl #align pgame.left_moves_mk SetTheory.PGame.leftMoves_mk @[simp] theorem moveLeft_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveLeft = xL := rfl #align pgame.move_left_mk SetTheory.PGame.moveLeft_mk @[simp] theorem rightMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).RightMoves = xr := rfl #align pgame.right_moves_mk SetTheory.PGame.rightMoves_mk @[simp] theorem moveRight_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveRight = xR := rfl #align pgame.move_right_mk SetTheory.PGame.moveRight_mk -- TODO define this at the level of games, as well, and perhaps also for finsets of games. /-- Construct a pre-game from list of pre-games describing the available moves for Left and Right. -/ def ofLists (L R : List PGame.{u}) : PGame.{u} := mk (ULift (Fin L.length)) (ULift (Fin R.length)) (fun i => L.get i.down) fun j ↦ R.get j.down #align pgame.of_lists SetTheory.PGame.ofLists theorem leftMoves_ofLists (L R : List PGame) : (ofLists L R).LeftMoves = ULift (Fin L.length) := rfl #align pgame.left_moves_of_lists SetTheory.PGame.leftMoves_ofLists theorem rightMoves_ofLists (L R : List PGame) : (ofLists L R).RightMoves = ULift (Fin R.length) := rfl #align pgame.right_moves_of_lists SetTheory.PGame.rightMoves_ofLists /-- Converts a number into a left move for `ofLists`. -/ def toOfListsLeftMoves {L R : List PGame} : Fin L.length ≃ (ofLists L R).LeftMoves := ((Equiv.cast (leftMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_left_moves SetTheory.PGame.toOfListsLeftMoves /-- Converts a number into a right move for `ofLists`. -/ def toOfListsRightMoves {L R : List PGame} : Fin R.length ≃ (ofLists L R).RightMoves := ((Equiv.cast (rightMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_right_moves SetTheory.PGame.toOfListsRightMoves theorem ofLists_moveLeft {L R : List PGame} (i : Fin L.length) : (ofLists L R).moveLeft (toOfListsLeftMoves i) = L.get i := rfl #align pgame.of_lists_move_left SetTheory.PGame.ofLists_moveLeft @[simp] theorem ofLists_moveLeft' {L R : List PGame} (i : (ofLists L R).LeftMoves) : (ofLists L R).moveLeft i = L.get (toOfListsLeftMoves.symm i) := rfl #align pgame.of_lists_move_left' SetTheory.PGame.ofLists_moveLeft' theorem ofLists_moveRight {L R : List PGame} (i : Fin R.length) : (ofLists L R).moveRight (toOfListsRightMoves i) = R.get i := rfl #align pgame.of_lists_move_right SetTheory.PGame.ofLists_moveRight @[simp] theorem ofLists_moveRight' {L R : List PGame} (i : (ofLists L R).RightMoves) : (ofLists L R).moveRight i = R.get (toOfListsRightMoves.symm i) := rfl #align pgame.of_lists_move_right' SetTheory.PGame.ofLists_moveRight' /-- A variant of `PGame.recOn` expressed in terms of `PGame.moveLeft` and `PGame.moveRight`. Both this and `PGame.recOn` describe Conway induction on games. -/ @[elab_as_elim] def moveRecOn {C : PGame → Sort*} (x : PGame) (IH : ∀ y : PGame, (∀ i, C (y.moveLeft i)) → (∀ j, C (y.moveRight j)) → C y) : C x := x.recOn fun yl yr yL yR => IH (mk yl yr yL yR) #align pgame.move_rec_on SetTheory.PGame.moveRecOn /-- `IsOption x y` means that `x` is either a left or right option for `y`. -/ @[mk_iff] inductive IsOption : PGame → PGame → Prop | moveLeft {x : PGame} (i : x.LeftMoves) : IsOption (x.moveLeft i) x | moveRight {x : PGame} (i : x.RightMoves) : IsOption (x.moveRight i) x #align pgame.is_option SetTheory.PGame.IsOption theorem IsOption.mk_left {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : (xL i).IsOption (mk xl xr xL xR) := @IsOption.moveLeft (mk _ _ _ _) i #align pgame.is_option.mk_left SetTheory.PGame.IsOption.mk_left theorem IsOption.mk_right {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xr) : (xR i).IsOption (mk xl xr xL xR) := @IsOption.moveRight (mk _ _ _ _) i #align pgame.is_option.mk_right SetTheory.PGame.IsOption.mk_right theorem wf_isOption : WellFounded IsOption := ⟨fun x => moveRecOn x fun x IHl IHr => Acc.intro x fun y h => by induction' h with _ i _ j · exact IHl i · exact IHr j⟩ #align pgame.wf_is_option SetTheory.PGame.wf_isOption /-- `Subsequent x y` says that `x` can be obtained by playing some nonempty sequence of moves from `y`. It is the transitive closure of `IsOption`. -/ def Subsequent : PGame → PGame → Prop := TransGen IsOption #align pgame.subsequent SetTheory.PGame.Subsequent instance : IsTrans _ Subsequent := inferInstanceAs <| IsTrans _ (TransGen _) @[trans] theorem Subsequent.trans {x y z} : Subsequent x y → Subsequent y z → Subsequent x z := TransGen.trans #align pgame.subsequent.trans SetTheory.PGame.Subsequent.trans theorem wf_subsequent : WellFounded Subsequent := wf_isOption.transGen #align pgame.wf_subsequent SetTheory.PGame.wf_subsequent instance : WellFoundedRelation PGame := ⟨_, wf_subsequent⟩ @[simp] theorem Subsequent.moveLeft {x : PGame} (i : x.LeftMoves) : Subsequent (x.moveLeft i) x := TransGen.single (IsOption.moveLeft i) #align pgame.subsequent.move_left SetTheory.PGame.Subsequent.moveLeft @[simp] theorem Subsequent.moveRight {x : PGame} (j : x.RightMoves) : Subsequent (x.moveRight j) x := TransGen.single (IsOption.moveRight j) #align pgame.subsequent.move_right SetTheory.PGame.Subsequent.moveRight @[simp] theorem Subsequent.mk_left {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : Subsequent (xL i) (mk xl xr xL xR) := @Subsequent.moveLeft (mk _ _ _ _) i #align pgame.subsequent.mk_left SetTheory.PGame.Subsequent.mk_left @[simp] theorem Subsequent.mk_right {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j : xr) : Subsequent (xR j) (mk xl xr xL xR) := @Subsequent.moveRight (mk _ _ _ _) j #align pgame.subsequent.mk_right SetTheory.PGame.Subsequent.mk_right /-- Discharges proof obligations of the form `⊢ Subsequent ..` arising in termination proofs of definitions using well-founded recursion on `PGame`. -/ macro "pgame_wf_tac" : tactic => `(tactic| solve_by_elim (config := { maxDepth := 8 }) [Prod.Lex.left, Prod.Lex.right, PSigma.Lex.left, PSigma.Lex.right, Subsequent.moveLeft, Subsequent.moveRight, Subsequent.mk_left, Subsequent.mk_right, Subsequent.trans] ) -- Register some consequences of pgame_wf_tac as simp-lemmas for convenience -- (which are applied by default for WF goals) -- This is different from mk_right from the POV of the simplifier, -- because the unifier can't solve `xr =?= RightMoves (mk xl xr xL xR)` at reducible transparency. @[simp] theorem Subsequent.mk_right' (xL : xl → PGame) (xR : xr → PGame) (j : RightMoves (mk xl xr xL xR)) : Subsequent (xR j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac -- Porting note: linter claims these lemmas don't simplify? open Subsequent in attribute [nolint simpNF] mk_left mk_right mk_right' moveRight_mk_left moveRight_mk_right moveLeft_mk_left moveLeft_mk_right /-! ### Basic pre-games -/ /-- The pre-game `Zero` is defined by `0 = { | }`. -/ instance : Zero PGame := ⟨⟨PEmpty, PEmpty, PEmpty.elim, PEmpty.elim⟩⟩ @[simp] theorem zero_leftMoves : LeftMoves 0 = PEmpty := rfl #align pgame.zero_left_moves SetTheory.PGame.zero_leftMoves @[simp] theorem zero_rightMoves : RightMoves 0 = PEmpty := rfl #align pgame.zero_right_moves SetTheory.PGame.zero_rightMoves instance isEmpty_zero_leftMoves : IsEmpty (LeftMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_left_moves SetTheory.PGame.isEmpty_zero_leftMoves instance isEmpty_zero_rightMoves : IsEmpty (RightMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_right_moves SetTheory.PGame.isEmpty_zero_rightMoves instance : Inhabited PGame := ⟨0⟩ /-- The pre-game `One` is defined by `1 = { 0 | }`. -/ instance instOnePGame : One PGame := ⟨⟨PUnit, PEmpty, fun _ => 0, PEmpty.elim⟩⟩ @[simp] theorem one_leftMoves : LeftMoves 1 = PUnit := rfl #align pgame.one_left_moves SetTheory.PGame.one_leftMoves @[simp] theorem one_moveLeft (x) : moveLeft 1 x = 0 := rfl #align pgame.one_move_left SetTheory.PGame.one_moveLeft @[simp] theorem one_rightMoves : RightMoves 1 = PEmpty := rfl #align pgame.one_right_moves SetTheory.PGame.one_rightMoves instance uniqueOneLeftMoves : Unique (LeftMoves 1) := PUnit.unique #align pgame.unique_one_left_moves SetTheory.PGame.uniqueOneLeftMoves instance isEmpty_one_rightMoves : IsEmpty (RightMoves 1) := instIsEmptyPEmpty #align pgame.is_empty_one_right_moves SetTheory.PGame.isEmpty_one_rightMoves /-! ### Pre-game order relations -/ /-- The less or equal relation on pre-games. If `0 ≤ x`, then Left can win `x` as the second player. -/ instance le : LE PGame := ⟨Sym2.GameAdd.fix wf_isOption fun x y le => (∀ i, ¬le y (x.moveLeft i) (Sym2.GameAdd.snd_fst <| IsOption.moveLeft i)) ∧ ∀ j, ¬le (y.moveRight j) x (Sym2.GameAdd.fst_snd <| IsOption.moveRight j)⟩ /-- The less or fuzzy relation on pre-games. If `0 ⧏ x`, then Left can win `x` as the first player. -/ def LF (x y : PGame) : Prop := ¬y ≤ x #align pgame.lf SetTheory.PGame.LF @[inherit_doc] scoped infixl:50 " ⧏ " => PGame.LF @[simp] protected theorem not_le {x y : PGame} : ¬x ≤ y ↔ y ⧏ x := Iff.rfl #align pgame.not_le SetTheory.PGame.not_le @[simp] theorem not_lf {x y : PGame} : ¬x ⧏ y ↔ y ≤ x := Classical.not_not #align pgame.not_lf SetTheory.PGame.not_lf theorem _root_.LE.le.not_gf {x y : PGame} : x ≤ y → ¬y ⧏ x := not_lf.2 #align has_le.le.not_gf LE.le.not_gf theorem LF.not_ge {x y : PGame} : x ⧏ y → ¬y ≤ x := id #align pgame.lf.not_ge SetTheory.PGame.LF.not_ge /-- Definition of `x ≤ y` on pre-games, in terms of `⧏`. The ordering here is chosen so that `And.left` refer to moves by Left, and `And.right` refer to moves by Right. -/ theorem le_iff_forall_lf {x y : PGame} : x ≤ y ↔ (∀ i, x.moveLeft i ⧏ y) ∧ ∀ j, x ⧏ y.moveRight j := by unfold LE.le le simp only rw [Sym2.GameAdd.fix_eq] rfl #align pgame.le_iff_forall_lf SetTheory.PGame.le_iff_forall_lf /-- Definition of `x ≤ y` on pre-games built using the constructor. -/ @[simp] theorem mk_le_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ≤ mk yl yr yL yR ↔ (∀ i, xL i ⧏ mk yl yr yL yR) ∧ ∀ j, mk xl xr xL xR ⧏ yR j := le_iff_forall_lf #align pgame.mk_le_mk SetTheory.PGame.mk_le_mk theorem le_of_forall_lf {x y : PGame} (h₁ : ∀ i, x.moveLeft i ⧏ y) (h₂ : ∀ j, x ⧏ y.moveRight j) : x ≤ y := le_iff_forall_lf.2 ⟨h₁, h₂⟩ #align pgame.le_of_forall_lf SetTheory.PGame.le_of_forall_lf /-- Definition of `x ⧏ y` on pre-games, in terms of `≤`. The ordering here is chosen so that `or.inl` refer to moves by Left, and `or.inr` refer to moves by Right. -/ theorem lf_iff_exists_le {x y : PGame} : x ⧏ y ↔ (∃ i, x ≤ y.moveLeft i) ∨ ∃ j, x.moveRight j ≤ y := by rw [LF, le_iff_forall_lf, not_and_or] simp #align pgame.lf_iff_exists_le SetTheory.PGame.lf_iff_exists_le /-- Definition of `x ⧏ y` on pre-games built using the constructor. -/ @[simp] theorem mk_lf_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ⧏ mk yl yr yL yR ↔ (∃ i, mk xl xr xL xR ≤ yL i) ∨ ∃ j, xR j ≤ mk yl yr yL yR := lf_iff_exists_le #align pgame.mk_lf_mk SetTheory.PGame.mk_lf_mk theorem le_or_gf (x y : PGame) : x ≤ y ∨ y ⧏ x := by rw [← PGame.not_le] apply em #align pgame.le_or_gf SetTheory.PGame.le_or_gf theorem moveLeft_lf_of_le {x y : PGame} (h : x ≤ y) (i) : x.moveLeft i ⧏ y := (le_iff_forall_lf.1 h).1 i #align pgame.move_left_lf_of_le SetTheory.PGame.moveLeft_lf_of_le alias _root_.LE.le.moveLeft_lf := moveLeft_lf_of_le #align has_le.le.move_left_lf LE.le.moveLeft_lf theorem lf_moveRight_of_le {x y : PGame} (h : x ≤ y) (j) : x ⧏ y.moveRight j := (le_iff_forall_lf.1 h).2 j #align pgame.lf_move_right_of_le SetTheory.PGame.lf_moveRight_of_le alias _root_.LE.le.lf_moveRight := lf_moveRight_of_le #align has_le.le.lf_move_right LE.le.lf_moveRight theorem lf_of_moveRight_le {x y : PGame} {j} (h : x.moveRight j ≤ y) : x ⧏ y := lf_iff_exists_le.2 <| Or.inr ⟨j, h⟩ #align pgame.lf_of_move_right_le SetTheory.PGame.lf_of_moveRight_le theorem lf_of_le_moveLeft {x y : PGame} {i} (h : x ≤ y.moveLeft i) : x ⧏ y := lf_iff_exists_le.2 <| Or.inl ⟨i, h⟩ #align pgame.lf_of_le_move_left SetTheory.PGame.lf_of_le_moveLeft theorem lf_of_le_mk {xl xr xL xR y} : mk xl xr xL xR ≤ y → ∀ i, xL i ⧏ y := moveLeft_lf_of_le #align pgame.lf_of_le_mk SetTheory.PGame.lf_of_le_mk theorem lf_of_mk_le {x yl yr yL yR} : x ≤ mk yl yr yL yR → ∀ j, x ⧏ yR j := lf_moveRight_of_le #align pgame.lf_of_mk_le SetTheory.PGame.lf_of_mk_le theorem mk_lf_of_le {xl xr y j} (xL) {xR : xr → PGame} : xR j ≤ y → mk xl xr xL xR ⧏ y := @lf_of_moveRight_le (mk _ _ _ _) y j #align pgame.mk_lf_of_le SetTheory.PGame.mk_lf_of_le theorem lf_mk_of_le {x yl yr} {yL : yl → PGame} (yR) {i} : x ≤ yL i → x ⧏ mk yl yr yL yR := @lf_of_le_moveLeft x (mk _ _ _ _) i #align pgame.lf_mk_of_le SetTheory.PGame.lf_mk_of_le /- We prove that `x ≤ y → y ≤ z → x ≤ z` inductively, by also simultaneously proving its cyclic reorderings. This auxiliary lemma is used during said induction. -/ private theorem le_trans_aux {x y z : PGame} (h₁ : ∀ {i}, y ≤ z → z ≤ x.moveLeft i → y ≤ x.moveLeft i) (h₂ : ∀ {j}, z.moveRight j ≤ x → x ≤ y → z.moveRight j ≤ y) (hxy : x ≤ y) (hyz : y ≤ z) : x ≤ z := le_of_forall_lf (fun i => PGame.not_le.1 fun h => (h₁ hyz h).not_gf <| hxy.moveLeft_lf i) fun j => PGame.not_le.1 fun h => (h₂ h hxy).not_gf <| hyz.lf_moveRight j instance : Preorder PGame := { PGame.le with le_refl := fun x => by induction' x with _ _ _ _ IHl IHr exact le_of_forall_lf (fun i => lf_of_le_moveLeft (IHl i)) fun i => lf_of_moveRight_le (IHr i) le_trans := by suffices ∀ {x y z : PGame}, (x ≤ y → y ≤ z → x ≤ z) ∧ (y ≤ z → z ≤ x → y ≤ x) ∧ (z ≤ x → x ≤ y → z ≤ y) from fun x y z => this.1 intro x y z induction' x with xl xr xL xR IHxl IHxr generalizing y z induction' y with yl yr yL yR IHyl IHyr generalizing z induction' z with zl zr zL zR IHzl IHzr exact ⟨le_trans_aux (fun {i} => (IHxl i).2.1) fun {j} => (IHzr j).2.2, le_trans_aux (fun {i} => (IHyl i).2.2) fun {j} => (IHxr j).1, le_trans_aux (fun {i} => (IHzl i).1) fun {j} => (IHyr j).2.1⟩ lt := fun x y => x ≤ y ∧ x ⧏ y } theorem lt_iff_le_and_lf {x y : PGame} : x < y ↔ x ≤ y ∧ x ⧏ y := Iff.rfl #align pgame.lt_iff_le_and_lf SetTheory.PGame.lt_iff_le_and_lf theorem lt_of_le_of_lf {x y : PGame} (h₁ : x ≤ y) (h₂ : x ⧏ y) : x < y := ⟨h₁, h₂⟩ #align pgame.lt_of_le_of_lf SetTheory.PGame.lt_of_le_of_lf theorem lf_of_lt {x y : PGame} (h : x < y) : x ⧏ y := h.2 #align pgame.lf_of_lt SetTheory.PGame.lf_of_lt alias _root_.LT.lt.lf := lf_of_lt #align has_lt.lt.lf LT.lt.lf theorem lf_irrefl (x : PGame) : ¬x ⧏ x := le_rfl.not_gf #align pgame.lf_irrefl SetTheory.PGame.lf_irrefl instance : IsIrrefl _ (· ⧏ ·) := ⟨lf_irrefl⟩ @[trans] theorem lf_of_le_of_lf {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ⧏ z) : x ⧏ z := by rw [← PGame.not_le] at h₂ ⊢ exact fun h₃ => h₂ (h₃.trans h₁) #align pgame.lf_of_le_of_lf SetTheory.PGame.lf_of_le_of_lf -- Porting note (#10754): added instance instance : Trans (· ≤ ·) (· ⧏ ·) (· ⧏ ·) := ⟨lf_of_le_of_lf⟩ @[trans] theorem lf_of_lf_of_le {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≤ z) : x ⧏ z := by rw [← PGame.not_le] at h₁ ⊢ exact fun h₃ => h₁ (h₂.trans h₃) #align pgame.lf_of_lf_of_le SetTheory.PGame.lf_of_lf_of_le -- Porting note (#10754): added instance instance : Trans (· ⧏ ·) (· ≤ ·) (· ⧏ ·) := ⟨lf_of_lf_of_le⟩ alias _root_.LE.le.trans_lf := lf_of_le_of_lf #align has_le.le.trans_lf LE.le.trans_lf alias LF.trans_le := lf_of_lf_of_le #align pgame.lf.trans_le SetTheory.PGame.LF.trans_le @[trans] theorem lf_of_lt_of_lf {x y z : PGame} (h₁ : x < y) (h₂ : y ⧏ z) : x ⧏ z := h₁.le.trans_lf h₂ #align pgame.lf_of_lt_of_lf SetTheory.PGame.lf_of_lt_of_lf @[trans] theorem lf_of_lf_of_lt {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y < z) : x ⧏ z := h₁.trans_le h₂.le #align pgame.lf_of_lf_of_lt SetTheory.PGame.lf_of_lf_of_lt alias _root_.LT.lt.trans_lf := lf_of_lt_of_lf #align has_lt.lt.trans_lf LT.lt.trans_lf alias LF.trans_lt := lf_of_lf_of_lt #align pgame.lf.trans_lt SetTheory.PGame.LF.trans_lt theorem moveLeft_lf {x : PGame} : ∀ i, x.moveLeft i ⧏ x := le_rfl.moveLeft_lf #align pgame.move_left_lf SetTheory.PGame.moveLeft_lf theorem lf_moveRight {x : PGame} : ∀ j, x ⧏ x.moveRight j := le_rfl.lf_moveRight #align pgame.lf_move_right SetTheory.PGame.lf_moveRight theorem lf_mk {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i) : xL i ⧏ mk xl xr xL xR := @moveLeft_lf (mk _ _ _ _) i #align pgame.lf_mk SetTheory.PGame.lf_mk theorem mk_lf {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j) : mk xl xr xL xR ⧏ xR j := @lf_moveRight (mk _ _ _ _) j #align pgame.mk_lf SetTheory.PGame.mk_lf /-- This special case of `PGame.le_of_forall_lf` is useful when dealing with surreals, where `<` is preferred over `⧏`. -/ theorem le_of_forall_lt {x y : PGame} (h₁ : ∀ i, x.moveLeft i < y) (h₂ : ∀ j, x < y.moveRight j) : x ≤ y := le_of_forall_lf (fun i => (h₁ i).lf) fun i => (h₂ i).lf #align pgame.le_of_forall_lt SetTheory.PGame.le_of_forall_lt /-- The definition of `x ≤ y` on pre-games, in terms of `≤` two moves later. -/ theorem le_def {x y : PGame} : x ≤ y ↔ (∀ i, (∃ i', x.moveLeft i ≤ y.moveLeft i') ∨ ∃ j, (x.moveLeft i).moveRight j ≤ y) ∧ ∀ j, (∃ i, x ≤ (y.moveRight j).moveLeft i) ∨ ∃ j', x.moveRight j' ≤ y.moveRight j := by rw [le_iff_forall_lf] conv => lhs simp only [lf_iff_exists_le] #align pgame.le_def SetTheory.PGame.le_def /-- The definition of `x ⧏ y` on pre-games, in terms of `⧏` two moves later. -/ theorem lf_def {x y : PGame} : x ⧏ y ↔ (∃ i, (∀ i', x.moveLeft i' ⧏ y.moveLeft i) ∧ ∀ j, x ⧏ (y.moveLeft i).moveRight j) ∨ ∃ j, (∀ i, (x.moveRight j).moveLeft i ⧏ y) ∧ ∀ j', x.moveRight j ⧏ y.moveRight j' := by rw [lf_iff_exists_le] conv => lhs simp only [le_iff_forall_lf] #align pgame.lf_def SetTheory.PGame.lf_def /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ⧏`. -/ theorem zero_le_lf {x : PGame} : 0 ≤ x ↔ ∀ j, 0 ⧏ x.moveRight j := by rw [le_iff_forall_lf] simp #align pgame.zero_le_lf SetTheory.PGame.zero_le_lf /-- The definition of `x ≤ 0` on pre-games, in terms of `⧏ 0`. -/ theorem le_zero_lf {x : PGame} : x ≤ 0 ↔ ∀ i, x.moveLeft i ⧏ 0 := by rw [le_iff_forall_lf] simp #align pgame.le_zero_lf SetTheory.PGame.le_zero_lf /-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ≤`. -/ theorem zero_lf_le {x : PGame} : 0 ⧏ x ↔ ∃ i, 0 ≤ x.moveLeft i := by rw [lf_iff_exists_le] simp #align pgame.zero_lf_le SetTheory.PGame.zero_lf_le /-- The definition of `x ⧏ 0` on pre-games, in terms of `≤ 0`. -/ theorem lf_zero_le {x : PGame} : x ⧏ 0 ↔ ∃ j, x.moveRight j ≤ 0 := by rw [lf_iff_exists_le] simp #align pgame.lf_zero_le SetTheory.PGame.lf_zero_le /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ≤` two moves later. -/ theorem zero_le {x : PGame} : 0 ≤ x ↔ ∀ j, ∃ i, 0 ≤ (x.moveRight j).moveLeft i := by rw [le_def] simp #align pgame.zero_le SetTheory.PGame.zero_le /-- The definition of `x ≤ 0` on pre-games, in terms of `≤ 0` two moves later. -/ theorem le_zero {x : PGame} : x ≤ 0 ↔ ∀ i, ∃ j, (x.moveLeft i).moveRight j ≤ 0 := by rw [le_def] simp #align pgame.le_zero SetTheory.PGame.le_zero /-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ⧏` two moves later. -/ theorem zero_lf {x : PGame} : 0 ⧏ x ↔ ∃ i, ∀ j, 0 ⧏ (x.moveLeft i).moveRight j := by rw [lf_def] simp #align pgame.zero_lf SetTheory.PGame.zero_lf /-- The definition of `x ⧏ 0` on pre-games, in terms of `⧏ 0` two moves later. -/ theorem lf_zero {x : PGame} : x ⧏ 0 ↔ ∃ j, ∀ i, (x.moveRight j).moveLeft i ⧏ 0 := by rw [lf_def] simp #align pgame.lf_zero SetTheory.PGame.lf_zero @[simp] theorem zero_le_of_isEmpty_rightMoves (x : PGame) [IsEmpty x.RightMoves] : 0 ≤ x := zero_le.2 isEmptyElim #align pgame.zero_le_of_is_empty_right_moves SetTheory.PGame.zero_le_of_isEmpty_rightMoves @[simp] theorem le_zero_of_isEmpty_leftMoves (x : PGame) [IsEmpty x.LeftMoves] : x ≤ 0 := le_zero.2 isEmptyElim #align pgame.le_zero_of_is_empty_left_moves SetTheory.PGame.le_zero_of_isEmpty_leftMoves /-- Given a game won by the right player when they play second, provide a response to any move by left. -/ noncomputable def rightResponse {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) : (x.moveLeft i).RightMoves := Classical.choose <| (le_zero.1 h) i #align pgame.right_response SetTheory.PGame.rightResponse /-- Show that the response for right provided by `rightResponse` preserves the right-player-wins condition. -/ theorem rightResponse_spec {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) : (x.moveLeft i).moveRight (rightResponse h i) ≤ 0 := Classical.choose_spec <| (le_zero.1 h) i #align pgame.right_response_spec SetTheory.PGame.rightResponse_spec /-- Given a game won by the left player when they play second, provide a response to any move by right. -/ noncomputable def leftResponse {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) : (x.moveRight j).LeftMoves := Classical.choose <| (zero_le.1 h) j #align pgame.left_response SetTheory.PGame.leftResponse /-- Show that the response for left provided by `leftResponse` preserves the left-player-wins condition. -/ theorem leftResponse_spec {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) : 0 ≤ (x.moveRight j).moveLeft (leftResponse h j) := Classical.choose_spec <| (zero_le.1 h) j #align pgame.left_response_spec SetTheory.PGame.leftResponse_spec #noalign pgame.upper_bound #noalign pgame.upper_bound_right_moves_empty #noalign pgame.le_upper_bound #noalign pgame.upper_bound_mem_upper_bounds /-- A small family of pre-games is bounded above. -/ lemma bddAbove_range_of_small [Small.{u} ι] (f : ι → PGame.{u}) : BddAbove (Set.range f) := by let x : PGame.{u} := ⟨Σ i, (f $ (equivShrink.{u} ι).symm i).LeftMoves, PEmpty, fun x ↦ moveLeft _ x.2, PEmpty.elim⟩ refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩ rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf] simpa [x] using fun j ↦ @moveLeft_lf x ⟨equivShrink ι i, j⟩ /-- A small set of pre-games is bounded above. -/ lemma bddAbove_of_small (s : Set PGame.{u}) [Small.{u} s] : BddAbove s := by simpa using bddAbove_range_of_small (Subtype.val : s → PGame.{u}) #align pgame.bdd_above_of_small SetTheory.PGame.bddAbove_of_small #noalign pgame.lower_bound #noalign pgame.lower_bound_left_moves_empty #noalign pgame.lower_bound_le #noalign pgame.lower_bound_mem_lower_bounds /-- A small family of pre-games is bounded below. -/ lemma bddBelow_range_of_small [Small.{u} ι] (f : ι → PGame.{u}) : BddBelow (Set.range f) := by let x : PGame.{u} := ⟨PEmpty, Σ i, (f $ (equivShrink.{u} ι).symm i).RightMoves, PEmpty.elim, fun x ↦ moveRight _ x.2⟩ refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩ rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf] simpa [x] using fun j ↦ @lf_moveRight x ⟨equivShrink ι i, j⟩ /-- A small set of pre-games is bounded below. -/ lemma bddBelow_of_small (s : Set PGame.{u}) [Small.{u} s] : BddBelow s := by simpa using bddBelow_range_of_small (Subtype.val : s → PGame.{u}) #align pgame.bdd_below_of_small SetTheory.PGame.bddBelow_of_small /-- The equivalence relation on pre-games. Two pre-games `x`, `y` are equivalent if `x ≤ y` and `y ≤ x`. If `x ≈ 0`, then the second player can always win `x`. -/ def Equiv (x y : PGame) : Prop := x ≤ y ∧ y ≤ x #align pgame.equiv SetTheory.PGame.Equiv -- Porting note: deleted the scoped notation due to notation overloading with the setoid -- instance and this causes the PGame.equiv docstring to not show up on hover. instance : IsEquiv _ PGame.Equiv where refl _ := ⟨le_rfl, le_rfl⟩ trans := fun _ _ _ ⟨xy, yx⟩ ⟨yz, zy⟩ => ⟨xy.trans yz, zy.trans yx⟩ symm _ _ := And.symm -- Porting note: moved the setoid instance from Basic.lean to here instance setoid : Setoid PGame := ⟨Equiv, refl, symm, Trans.trans⟩ #align pgame.setoid SetTheory.PGame.setoid theorem Equiv.le {x y : PGame} (h : x ≈ y) : x ≤ y := h.1 #align pgame.equiv.le SetTheory.PGame.Equiv.le theorem Equiv.ge {x y : PGame} (h : x ≈ y) : y ≤ x := h.2 #align pgame.equiv.ge SetTheory.PGame.Equiv.ge @[refl, simp] theorem equiv_rfl {x : PGame} : x ≈ x := refl x #align pgame.equiv_rfl SetTheory.PGame.equiv_rfl theorem equiv_refl (x : PGame) : x ≈ x := refl x #align pgame.equiv_refl SetTheory.PGame.equiv_refl @[symm] protected theorem Equiv.symm {x y : PGame} : (x ≈ y) → (y ≈ x) := symm #align pgame.equiv.symm SetTheory.PGame.Equiv.symm @[trans] protected theorem Equiv.trans {x y z : PGame} : (x ≈ y) → (y ≈ z) → (x ≈ z) := _root_.trans #align pgame.equiv.trans SetTheory.PGame.Equiv.trans protected theorem equiv_comm {x y : PGame} : (x ≈ y) ↔ (y ≈ x) := comm #align pgame.equiv_comm SetTheory.PGame.equiv_comm theorem equiv_of_eq {x y : PGame} (h : x = y) : x ≈ y := by subst h; rfl #align pgame.equiv_of_eq SetTheory.PGame.equiv_of_eq @[trans] theorem le_of_le_of_equiv {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ≈ z) : x ≤ z := h₁.trans h₂.1 #align pgame.le_of_le_of_equiv SetTheory.PGame.le_of_le_of_equiv instance : Trans ((· ≤ ·) : PGame → PGame → Prop) ((· ≈ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) where trans := le_of_le_of_equiv @[trans] theorem le_of_equiv_of_le {x y z : PGame} (h₁ : x ≈ y) : y ≤ z → x ≤ z := h₁.1.trans #align pgame.le_of_equiv_of_le SetTheory.PGame.le_of_equiv_of_le instance : Trans ((· ≈ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) where trans := le_of_equiv_of_le theorem LF.not_equiv {x y : PGame} (h : x ⧏ y) : ¬(x ≈ y) := fun h' => h.not_ge h'.2 #align pgame.lf.not_equiv SetTheory.PGame.LF.not_equiv theorem LF.not_equiv' {x y : PGame} (h : x ⧏ y) : ¬(y ≈ x) := fun h' => h.not_ge h'.1 #align pgame.lf.not_equiv' SetTheory.PGame.LF.not_equiv' theorem LF.not_gt {x y : PGame} (h : x ⧏ y) : ¬y < x := fun h' => h.not_ge h'.le #align pgame.lf.not_gt SetTheory.PGame.LF.not_gt theorem le_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ ≤ y₁) : x₂ ≤ y₂ := hx.2.trans (h.trans hy.1) #align pgame.le_congr_imp SetTheory.PGame.le_congr_imp theorem le_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ≤ y₁ ↔ x₂ ≤ y₂ := ⟨le_congr_imp hx hy, le_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩ #align pgame.le_congr SetTheory.PGame.le_congr theorem le_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ≤ y ↔ x₂ ≤ y := le_congr hx equiv_rfl #align pgame.le_congr_left SetTheory.PGame.le_congr_left theorem le_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ≤ y₁ ↔ x ≤ y₂ := le_congr equiv_rfl hy #align pgame.le_congr_right SetTheory.PGame.le_congr_right theorem lf_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ ↔ x₂ ⧏ y₂ := PGame.not_le.symm.trans <| (not_congr (le_congr hy hx)).trans PGame.not_le #align pgame.lf_congr SetTheory.PGame.lf_congr theorem lf_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ → x₂ ⧏ y₂ := (lf_congr hx hy).1 #align pgame.lf_congr_imp SetTheory.PGame.lf_congr_imp theorem lf_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ⧏ y ↔ x₂ ⧏ y := lf_congr hx equiv_rfl #align pgame.lf_congr_left SetTheory.PGame.lf_congr_left theorem lf_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ⧏ y₁ ↔ x ⧏ y₂ := lf_congr equiv_rfl hy #align pgame.lf_congr_right SetTheory.PGame.lf_congr_right @[trans] theorem lf_of_lf_of_equiv {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≈ z) : x ⧏ z := lf_congr_imp equiv_rfl h₂ h₁ #align pgame.lf_of_lf_of_equiv SetTheory.PGame.lf_of_lf_of_equiv @[trans] theorem lf_of_equiv_of_lf {x y z : PGame} (h₁ : x ≈ y) : y ⧏ z → x ⧏ z := lf_congr_imp (Equiv.symm h₁) equiv_rfl #align pgame.lf_of_equiv_of_lf SetTheory.PGame.lf_of_equiv_of_lf @[trans] theorem lt_of_lt_of_equiv {x y z : PGame} (h₁ : x < y) (h₂ : y ≈ z) : x < z := h₁.trans_le h₂.1 #align pgame.lt_of_lt_of_equiv SetTheory.PGame.lt_of_lt_of_equiv @[trans] theorem lt_of_equiv_of_lt {x y z : PGame} (h₁ : x ≈ y) : y < z → x < z := h₁.1.trans_lt #align pgame.lt_of_equiv_of_lt SetTheory.PGame.lt_of_equiv_of_lt instance : Trans ((· ≈ ·) : PGame → PGame → Prop) ((· < ·) : PGame → PGame → Prop) ((· < ·) : PGame → PGame → Prop) where trans := lt_of_equiv_of_lt theorem lt_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ < y₁) : x₂ < y₂ := hx.2.trans_lt (h.trans_le hy.1) #align pgame.lt_congr_imp SetTheory.PGame.lt_congr_imp theorem lt_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ < y₁ ↔ x₂ < y₂ := ⟨lt_congr_imp hx hy, lt_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩ #align pgame.lt_congr SetTheory.PGame.lt_congr theorem lt_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ < y ↔ x₂ < y := lt_congr hx equiv_rfl #align pgame.lt_congr_left SetTheory.PGame.lt_congr_left theorem lt_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x < y₁ ↔ x < y₂ := lt_congr equiv_rfl hy #align pgame.lt_congr_right SetTheory.PGame.lt_congr_right theorem lt_or_equiv_of_le {x y : PGame} (h : x ≤ y) : x < y ∨ (x ≈ y) := and_or_left.mp ⟨h, (em <| y ≤ x).symm.imp_left PGame.not_le.1⟩ #align pgame.lt_or_equiv_of_le SetTheory.PGame.lt_or_equiv_of_le theorem lf_or_equiv_or_gf (x y : PGame) : x ⧏ y ∨ (x ≈ y) ∨ y ⧏ x := by by_cases h : x ⧏ y · exact Or.inl h · right cases' lt_or_equiv_of_le (PGame.not_lf.1 h) with h' h' · exact Or.inr h'.lf · exact Or.inl (Equiv.symm h') #align pgame.lf_or_equiv_or_gf SetTheory.PGame.lf_or_equiv_or_gf theorem equiv_congr_left {y₁ y₂ : PGame} : (y₁ ≈ y₂) ↔ ∀ x₁, (x₁ ≈ y₁) ↔ (x₁ ≈ y₂) := ⟨fun h _ => ⟨fun h' => Equiv.trans h' h, fun h' => Equiv.trans h' (Equiv.symm h)⟩, fun h => (h y₁).1 <| equiv_rfl⟩ #align pgame.equiv_congr_left SetTheory.PGame.equiv_congr_left theorem equiv_congr_right {x₁ x₂ : PGame} : (x₁ ≈ x₂) ↔ ∀ y₁, (x₁ ≈ y₁) ↔ (x₂ ≈ y₁) := ⟨fun h _ => ⟨fun h' => Equiv.trans (Equiv.symm h) h', fun h' => Equiv.trans h h'⟩, fun h => (h x₂).2 <| equiv_rfl⟩ #align pgame.equiv_congr_right SetTheory.PGame.equiv_congr_right theorem equiv_of_mk_equiv {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves) (hl : ∀ i, x.moveLeft i ≈ y.moveLeft (L i)) (hr : ∀ j, x.moveRight j ≈ y.moveRight (R j)) : x ≈ y := by constructor <;> rw [le_def] · exact ⟨fun i => Or.inl ⟨_, (hl i).1⟩, fun j => Or.inr ⟨_, by simpa using (hr (R.symm j)).1⟩⟩ · exact ⟨fun i => Or.inl ⟨_, by simpa using (hl (L.symm i)).2⟩, fun j => Or.inr ⟨_, (hr j).2⟩⟩ #align pgame.equiv_of_mk_equiv SetTheory.PGame.equiv_of_mk_equiv /-- The fuzzy, confused, or incomparable relation on pre-games. If `x ‖ 0`, then the first player can always win `x`. -/ def Fuzzy (x y : PGame) : Prop := x ⧏ y ∧ y ⧏ x #align pgame.fuzzy SetTheory.PGame.Fuzzy @[inherit_doc] scoped infixl:50 " ‖ " => PGame.Fuzzy @[symm] theorem Fuzzy.swap {x y : PGame} : x ‖ y → y ‖ x := And.symm #align pgame.fuzzy.swap SetTheory.PGame.Fuzzy.swap instance : IsSymm _ (· ‖ ·) := ⟨fun _ _ => Fuzzy.swap⟩ theorem Fuzzy.swap_iff {x y : PGame} : x ‖ y ↔ y ‖ x := ⟨Fuzzy.swap, Fuzzy.swap⟩ #align pgame.fuzzy.swap_iff SetTheory.PGame.Fuzzy.swap_iff theorem fuzzy_irrefl (x : PGame) : ¬x ‖ x := fun h => lf_irrefl x h.1 #align pgame.fuzzy_irrefl SetTheory.PGame.fuzzy_irrefl instance : IsIrrefl _ (· ‖ ·) := ⟨fuzzy_irrefl⟩ theorem lf_iff_lt_or_fuzzy {x y : PGame} : x ⧏ y ↔ x < y ∨ x ‖ y := by simp only [lt_iff_le_and_lf, Fuzzy, ← PGame.not_le] tauto #align pgame.lf_iff_lt_or_fuzzy SetTheory.PGame.lf_iff_lt_or_fuzzy theorem lf_of_fuzzy {x y : PGame} (h : x ‖ y) : x ⧏ y := lf_iff_lt_or_fuzzy.2 (Or.inr h) #align pgame.lf_of_fuzzy SetTheory.PGame.lf_of_fuzzy alias Fuzzy.lf := lf_of_fuzzy #align pgame.fuzzy.lf SetTheory.PGame.Fuzzy.lf theorem lt_or_fuzzy_of_lf {x y : PGame} : x ⧏ y → x < y ∨ x ‖ y := lf_iff_lt_or_fuzzy.1 #align pgame.lt_or_fuzzy_of_lf SetTheory.PGame.lt_or_fuzzy_of_lf theorem Fuzzy.not_equiv {x y : PGame} (h : x ‖ y) : ¬(x ≈ y) := fun h' => h'.1.not_gf h.2 #align pgame.fuzzy.not_equiv SetTheory.PGame.Fuzzy.not_equiv theorem Fuzzy.not_equiv' {x y : PGame} (h : x ‖ y) : ¬(y ≈ x) := fun h' => h'.2.not_gf h.2 #align pgame.fuzzy.not_equiv' SetTheory.PGame.Fuzzy.not_equiv' theorem not_fuzzy_of_le {x y : PGame} (h : x ≤ y) : ¬x ‖ y := fun h' => h'.2.not_ge h #align pgame.not_fuzzy_of_le SetTheory.PGame.not_fuzzy_of_le theorem not_fuzzy_of_ge {x y : PGame} (h : y ≤ x) : ¬x ‖ y := fun h' => h'.1.not_ge h #align pgame.not_fuzzy_of_ge SetTheory.PGame.not_fuzzy_of_ge theorem Equiv.not_fuzzy {x y : PGame} (h : x ≈ y) : ¬x ‖ y := not_fuzzy_of_le h.1 #align pgame.equiv.not_fuzzy SetTheory.PGame.Equiv.not_fuzzy theorem Equiv.not_fuzzy' {x y : PGame} (h : x ≈ y) : ¬y ‖ x := not_fuzzy_of_le h.2 #align pgame.equiv.not_fuzzy' SetTheory.PGame.Equiv.not_fuzzy' theorem fuzzy_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ‖ y₁ ↔ x₂ ‖ y₂ := show _ ∧ _ ↔ _ ∧ _ by rw [lf_congr hx hy, lf_congr hy hx] #align pgame.fuzzy_congr SetTheory.PGame.fuzzy_congr theorem fuzzy_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ‖ y₁ → x₂ ‖ y₂ := (fuzzy_congr hx hy).1 #align pgame.fuzzy_congr_imp SetTheory.PGame.fuzzy_congr_imp theorem fuzzy_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ‖ y ↔ x₂ ‖ y := fuzzy_congr hx equiv_rfl #align pgame.fuzzy_congr_left SetTheory.PGame.fuzzy_congr_left theorem fuzzy_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ‖ y₁ ↔ x ‖ y₂ := fuzzy_congr equiv_rfl hy #align pgame.fuzzy_congr_right SetTheory.PGame.fuzzy_congr_right @[trans] theorem fuzzy_of_fuzzy_of_equiv {x y z : PGame} (h₁ : x ‖ y) (h₂ : y ≈ z) : x ‖ z := (fuzzy_congr_right h₂).1 h₁ #align pgame.fuzzy_of_fuzzy_of_equiv SetTheory.PGame.fuzzy_of_fuzzy_of_equiv @[trans] theorem fuzzy_of_equiv_of_fuzzy {x y z : PGame} (h₁ : x ≈ y) (h₂ : y ‖ z) : x ‖ z := (fuzzy_congr_left h₁).2 h₂ #align pgame.fuzzy_of_equiv_of_fuzzy SetTheory.PGame.fuzzy_of_equiv_of_fuzzy /-- Exactly one of the following is true (although we don't prove this here). -/ theorem lt_or_equiv_or_gt_or_fuzzy (x y : PGame) : x < y ∨ (x ≈ y) ∨ y < x ∨ x ‖ y := by cases' le_or_gf x y with h₁ h₁ <;> cases' le_or_gf y x with h₂ h₂ · right left exact ⟨h₁, h₂⟩ · left exact ⟨h₁, h₂⟩ · right right left exact ⟨h₂, h₁⟩ · right right right exact ⟨h₂, h₁⟩ #align pgame.lt_or_equiv_or_gt_or_fuzzy SetTheory.PGame.lt_or_equiv_or_gt_or_fuzzy theorem lt_or_equiv_or_gf (x y : PGame) : x < y ∨ (x ≈ y) ∨ y ⧏ x := by rw [lf_iff_lt_or_fuzzy, Fuzzy.swap_iff] exact lt_or_equiv_or_gt_or_fuzzy x y #align pgame.lt_or_equiv_or_gf SetTheory.PGame.lt_or_equiv_or_gf /-! ### Relabellings -/ /-- `Relabelling x y` says that `x` and `y` are really the same game, just dressed up differently. Specifically, there is a bijection between the moves for Left in `x` and in `y`, and similarly for Right, and under these bijections we inductively have `Relabelling`s for the consequent games. -/ inductive Relabelling : PGame.{u} → PGame.{u} → Type (u + 1) | mk : ∀ {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves), (∀ i, Relabelling (x.moveLeft i) (y.moveLeft (L i))) → (∀ j, Relabelling (x.moveRight j) (y.moveRight (R j))) → Relabelling x y #align pgame.relabelling SetTheory.PGame.Relabelling @[inherit_doc] scoped infixl:50 " ≡r " => PGame.Relabelling namespace Relabelling variable {x y : PGame.{u}} /-- A constructor for relabellings swapping the equivalences. -/ def mk' (L : y.LeftMoves ≃ x.LeftMoves) (R : y.RightMoves ≃ x.RightMoves) (hL : ∀ i, x.moveLeft (L i) ≡r y.moveLeft i) (hR : ∀ j, x.moveRight (R j) ≡r y.moveRight j) : x ≡r y := ⟨L.symm, R.symm, fun i => by simpa using hL (L.symm i), fun j => by simpa using hR (R.symm j)⟩ #align pgame.relabelling.mk' SetTheory.PGame.Relabelling.mk' /-- The equivalence between left moves of `x` and `y` given by the relabelling. -/ def leftMovesEquiv : x ≡r y → x.LeftMoves ≃ y.LeftMoves | ⟨L,_, _,_⟩ => L #align pgame.relabelling.left_moves_equiv SetTheory.PGame.Relabelling.leftMovesEquiv @[simp] theorem mk_leftMovesEquiv {x y L R hL hR} : (@Relabelling.mk x y L R hL hR).leftMovesEquiv = L := rfl #align pgame.relabelling.mk_left_moves_equiv SetTheory.PGame.Relabelling.mk_leftMovesEquiv @[simp] theorem mk'_leftMovesEquiv {x y L R hL hR} : (@Relabelling.mk' x y L R hL hR).leftMovesEquiv = L.symm := rfl #align pgame.relabelling.mk'_left_moves_equiv SetTheory.PGame.Relabelling.mk'_leftMovesEquiv /-- The equivalence between right moves of `x` and `y` given by the relabelling. -/ def rightMovesEquiv : x ≡r y → x.RightMoves ≃ y.RightMoves | ⟨_, R, _, _⟩ => R #align pgame.relabelling.right_moves_equiv SetTheory.PGame.Relabelling.rightMovesEquiv @[simp] theorem mk_rightMovesEquiv {x y L R hL hR} : (@Relabelling.mk x y L R hL hR).rightMovesEquiv = R := rfl #align pgame.relabelling.mk_right_moves_equiv SetTheory.PGame.Relabelling.mk_rightMovesEquiv @[simp] theorem mk'_rightMovesEquiv {x y L R hL hR} : (@Relabelling.mk' x y L R hL hR).rightMovesEquiv = R.symm := rfl #align pgame.relabelling.mk'_right_moves_equiv SetTheory.PGame.Relabelling.mk'_rightMovesEquiv /-- A left move of `x` is a relabelling of a left move of `y`. -/ def moveLeft : ∀ (r : x ≡r y) (i : x.LeftMoves), x.moveLeft i ≡r y.moveLeft (r.leftMovesEquiv i) | ⟨_, _, hL, _⟩ => hL #align pgame.relabelling.move_left SetTheory.PGame.Relabelling.moveLeft /-- A left move of `y` is a relabelling of a left move of `x`. -/ def moveLeftSymm : ∀ (r : x ≡r y) (i : y.LeftMoves), x.moveLeft (r.leftMovesEquiv.symm i) ≡r y.moveLeft i | ⟨L, R, hL, hR⟩, i => by simpa using hL (L.symm i) #align pgame.relabelling.move_left_symm SetTheory.PGame.Relabelling.moveLeftSymm /-- A right move of `x` is a relabelling of a right move of `y`. -/ def moveRight : ∀ (r : x ≡r y) (i : x.RightMoves), x.moveRight i ≡r y.moveRight (r.rightMovesEquiv i) | ⟨_, _, _, hR⟩ => hR #align pgame.relabelling.move_right SetTheory.PGame.Relabelling.moveRight /-- A right move of `y` is a relabelling of a right move of `x`. -/ def moveRightSymm : ∀ (r : x ≡r y) (i : y.RightMoves), x.moveRight (r.rightMovesEquiv.symm i) ≡r y.moveRight i | ⟨L, R, hL, hR⟩, i => by simpa using hR (R.symm i) #align pgame.relabelling.move_right_symm SetTheory.PGame.Relabelling.moveRightSymm /-- The identity relabelling. -/ @[refl] def refl (x : PGame) : x ≡r x := ⟨Equiv.refl _, Equiv.refl _, fun i => refl _, fun j => refl _⟩ termination_by x #align pgame.relabelling.refl SetTheory.PGame.Relabelling.refl instance (x : PGame) : Inhabited (x ≡r x) := ⟨refl _⟩ /-- Flip a relabelling. -/ @[symm] def symm : ∀ {x y : PGame}, x ≡r y → y ≡r x | _, _, ⟨L, R, hL, hR⟩ => mk' L R (fun i => (hL i).symm) fun j => (hR j).symm #align pgame.relabelling.symm SetTheory.PGame.Relabelling.symm theorem le {x y : PGame} (r : x ≡r y) : x ≤ y := le_def.2 ⟨fun i => Or.inl ⟨_, (r.moveLeft i).le⟩, fun j => Or.inr ⟨_, (r.moveRightSymm j).le⟩⟩ termination_by x #align pgame.relabelling.le SetTheory.PGame.Relabelling.le theorem ge {x y : PGame} (r : x ≡r y) : y ≤ x := r.symm.le #align pgame.relabelling.ge SetTheory.PGame.Relabelling.ge /-- A relabelling lets us prove equivalence of games. -/ theorem equiv (r : x ≡r y) : x ≈ y := ⟨r.le, r.ge⟩ #align pgame.relabelling.equiv SetTheory.PGame.Relabelling.equiv /-- Transitivity of relabelling. -/ @[trans] def trans : ∀ {x y z : PGame}, x ≡r y → y ≡r z → x ≡r z | _, _, _, ⟨L₁, R₁, hL₁, hR₁⟩, ⟨L₂, R₂, hL₂, hR₂⟩ => ⟨L₁.trans L₂, R₁.trans R₂, fun i => (hL₁ i).trans (hL₂ _), fun j => (hR₁ j).trans (hR₂ _)⟩ #align pgame.relabelling.trans SetTheory.PGame.Relabelling.trans /-- Any game without left or right moves is a relabelling of 0. -/ def isEmpty (x : PGame) [IsEmpty x.LeftMoves] [IsEmpty x.RightMoves] : x ≡r 0 := ⟨Equiv.equivPEmpty _, Equiv.equivOfIsEmpty _ _, isEmptyElim, isEmptyElim⟩ #align pgame.relabelling.is_empty SetTheory.PGame.Relabelling.isEmpty end Relabelling theorem Equiv.isEmpty (x : PGame) [IsEmpty x.LeftMoves] [IsEmpty x.RightMoves] : x ≈ 0 := (Relabelling.isEmpty x).equiv #align pgame.equiv.is_empty SetTheory.PGame.Equiv.isEmpty instance {x y : PGame} : Coe (x ≡r y) (x ≈ y) := ⟨Relabelling.equiv⟩ /-- Replace the types indexing the next moves for Left and Right by equivalent types. -/ def relabel {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) : PGame := ⟨xl', xr', x.moveLeft ∘ el, x.moveRight ∘ er⟩ #align pgame.relabel SetTheory.PGame.relabel @[simp] theorem relabel_moveLeft' {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (i : xl') : moveLeft (relabel el er) i = x.moveLeft (el i) := rfl #align pgame.relabel_move_left' SetTheory.PGame.relabel_moveLeft' theorem relabel_moveLeft {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (i : x.LeftMoves) : moveLeft (relabel el er) (el.symm i) = x.moveLeft i := by simp #align pgame.relabel_move_left SetTheory.PGame.relabel_moveLeft @[simp] theorem relabel_moveRight' {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (j : xr') : moveRight (relabel el er) j = x.moveRight (er j) := rfl #align pgame.relabel_move_right' SetTheory.PGame.relabel_moveRight' theorem relabel_moveRight {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (j : x.RightMoves) : moveRight (relabel el er) (er.symm j) = x.moveRight j := by simp #align pgame.relabel_move_right SetTheory.PGame.relabel_moveRight /-- The game obtained by relabelling the next moves is a relabelling of the original game. -/ def relabelRelabelling {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) : x ≡r relabel el er := -- Porting note: needed to add `rfl` Relabelling.mk' el er (fun i => by simp; rfl) (fun j => by simp; rfl) #align pgame.relabel_relabelling SetTheory.PGame.relabelRelabelling /-! ### Negation -/ /-- The negation of `{L | R}` is `{-R | -L}`. -/ def neg : PGame → PGame | ⟨l, r, L, R⟩ => ⟨r, l, fun i => neg (R i), fun i => neg (L i)⟩ #align pgame.neg SetTheory.PGame.neg instance : Neg PGame := ⟨neg⟩ @[simp] theorem neg_def {xl xr xL xR} : -mk xl xr xL xR = mk xr xl (fun j => -xR j) fun i => -xL i := rfl #align pgame.neg_def SetTheory.PGame.neg_def instance : InvolutiveNeg PGame := { inferInstanceAs (Neg PGame) with neg_neg := fun x => by induction' x with xl xr xL xR ihL ihR simp_rw [neg_def, ihL, ihR] } instance : NegZeroClass PGame := { inferInstanceAs (Zero PGame), inferInstanceAs (Neg PGame) with neg_zero := by dsimp [Zero.zero, Neg.neg, neg] congr <;> funext i <;> cases i } @[simp] theorem neg_ofLists (L R : List PGame) : -ofLists L R = ofLists (R.map fun x => -x) (L.map fun x => -x) := by simp only [ofLists, neg_def, List.get_map, mk.injEq, List.length_map, true_and] constructor all_goals apply hfunext · simp · rintro ⟨⟨a, ha⟩⟩ ⟨⟨b, hb⟩⟩ h have : ∀ {m n} (_ : m = n) {b : ULift (Fin m)} {c : ULift (Fin n)} (_ : HEq b c), (b.down : ℕ) = ↑c.down := by rintro m n rfl b c simp only [heq_eq_eq] rintro rfl rfl congr 5 exact this (List.length_map _ _).symm h #align pgame.neg_of_lists SetTheory.PGame.neg_ofLists theorem isOption_neg {x y : PGame} : IsOption x (-y) ↔ IsOption (-x) y := by rw [isOption_iff, isOption_iff, or_comm] cases y; apply or_congr <;> · apply exists_congr intro rw [neg_eq_iff_eq_neg] rfl #align pgame.is_option_neg SetTheory.PGame.isOption_neg @[simp] theorem isOption_neg_neg {x y : PGame} : IsOption (-x) (-y) ↔ IsOption x y := by rw [isOption_neg, neg_neg] #align pgame.is_option_neg_neg SetTheory.PGame.isOption_neg_neg theorem leftMoves_neg : ∀ x : PGame, (-x).LeftMoves = x.RightMoves | ⟨_, _, _, _⟩ => rfl #align pgame.left_moves_neg SetTheory.PGame.leftMoves_neg theorem rightMoves_neg : ∀ x : PGame, (-x).RightMoves = x.LeftMoves | ⟨_, _, _, _⟩ => rfl #align pgame.right_moves_neg SetTheory.PGame.rightMoves_neg /-- Turns a right move for `x` into a left move for `-x` and vice versa. Even though these types are the same (not definitionally so), this is the preferred way to convert between them. -/ def toLeftMovesNeg {x : PGame} : x.RightMoves ≃ (-x).LeftMoves := Equiv.cast (leftMoves_neg x).symm #align pgame.to_left_moves_neg SetTheory.PGame.toLeftMovesNeg /-- Turns a left move for `x` into a right move for `-x` and vice versa. Even though these types are the same (not definitionally so), this is the preferred way to convert between them. -/ def toRightMovesNeg {x : PGame} : x.LeftMoves ≃ (-x).RightMoves := Equiv.cast (rightMoves_neg x).symm #align pgame.to_right_moves_neg SetTheory.PGame.toRightMovesNeg theorem moveLeft_neg {x : PGame} (i) : (-x).moveLeft (toLeftMovesNeg i) = -x.moveRight i := by cases x rfl #align pgame.move_left_neg SetTheory.PGame.moveLeft_neg @[simp] theorem moveLeft_neg' {x : PGame} (i) : (-x).moveLeft i = -x.moveRight (toLeftMovesNeg.symm i) := by cases x rfl #align pgame.move_left_neg' SetTheory.PGame.moveLeft_neg' theorem moveRight_neg {x : PGame} (i) : (-x).moveRight (toRightMovesNeg i) = -x.moveLeft i := by cases x rfl #align pgame.move_right_neg SetTheory.PGame.moveRight_neg @[simp] theorem moveRight_neg' {x : PGame} (i) : (-x).moveRight i = -x.moveLeft (toRightMovesNeg.symm i) := by cases x rfl #align pgame.move_right_neg' SetTheory.PGame.moveRight_neg' theorem moveLeft_neg_symm {x : PGame} (i) : x.moveLeft (toRightMovesNeg.symm i) = -(-x).moveRight i := by simp #align pgame.move_left_neg_symm SetTheory.PGame.moveLeft_neg_symm theorem moveLeft_neg_symm' {x : PGame} (i) : x.moveLeft i = -(-x).moveRight (toRightMovesNeg i) := by simp #align pgame.move_left_neg_symm' SetTheory.PGame.moveLeft_neg_symm'
Mathlib/SetTheory/Game/PGame.lean
1,360
1,361
theorem moveRight_neg_symm {x : PGame} (i) : x.moveRight (toLeftMovesNeg.symm i) = -(-x).moveLeft i := by
simp
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.LinearAlgebra.Dimension.Finrank import Mathlib.LinearAlgebra.InvariantBasisNumber #align_import linear_algebra.dimension from "leanprover-community/mathlib"@"47a5f8186becdbc826190ced4312f8199f9db6a5" /-! # Lemmas about rank and finrank in rings satisfying strong rank condition. ## Main statements For modules over rings satisfying the rank condition * `Basis.le_span`: the cardinality of a basis is bounded by the cardinality of any spanning set For modules over rings satisfying the strong rank condition * `linearIndependent_le_span`: For any linearly independent family `v : ι → M` and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. * `linearIndependent_le_basis`: If `b` is a basis for a module `M`, and `s` is a linearly independent set, then the cardinality of `s` is bounded by the cardinality of `b`. For modules over rings with invariant basis number (including all commutative rings and all noetherian rings) * `mk_eq_mk_of_basis`: the dimension theorem, any two bases of the same vector space have the same cardinality. -/ noncomputable section universe u v w w' variable {R : Type u} {M : Type v} [Ring R] [AddCommGroup M] [Module R M] variable {ι : Type w} {ι' : Type w'} open Cardinal Basis Submodule Function Set attribute [local instance] nontrivial_of_invariantBasisNumber section InvariantBasisNumber variable [InvariantBasisNumber R] /-- The dimension theorem: if `v` and `v'` are two bases, their index types have the same cardinalities. -/ theorem mk_eq_mk_of_basis (v : Basis ι R M) (v' : Basis ι' R M) : Cardinal.lift.{w'} #ι = Cardinal.lift.{w} #ι' := by classical haveI := nontrivial_of_invariantBasisNumber R cases fintypeOrInfinite ι · -- `v` is a finite basis, so by `basis_finite_of_finite_spans` so is `v'`. -- haveI : Finite (range v) := Set.finite_range v haveI := basis_finite_of_finite_spans _ (Set.finite_range v) v.span_eq v' cases nonempty_fintype ι' -- We clean up a little: rw [Cardinal.mk_fintype, Cardinal.mk_fintype] simp only [Cardinal.lift_natCast, Cardinal.natCast_inj] -- Now we can use invariant basis number to show they have the same cardinality. apply card_eq_of_linearEquiv R exact (Finsupp.linearEquivFunOnFinite R R ι).symm.trans v.repr.symm ≪≫ₗ v'.repr ≪≫ₗ Finsupp.linearEquivFunOnFinite R R ι' · -- `v` is an infinite basis, -- so by `infinite_basis_le_maximal_linearIndependent`, `v'` is at least as big, -- and then applying `infinite_basis_le_maximal_linearIndependent` again -- we see they have the same cardinality. have w₁ := infinite_basis_le_maximal_linearIndependent' v _ v'.linearIndependent v'.maximal rcases Cardinal.lift_mk_le'.mp w₁ with ⟨f⟩ haveI : Infinite ι' := Infinite.of_injective f f.2 have w₂ := infinite_basis_le_maximal_linearIndependent' v' _ v.linearIndependent v.maximal exact le_antisymm w₁ w₂ #align mk_eq_mk_of_basis mk_eq_mk_of_basis /-- Given two bases indexed by `ι` and `ι'` of an `R`-module, where `R` satisfies the invariant basis number property, an equiv `ι ≃ ι'`. -/ def Basis.indexEquiv (v : Basis ι R M) (v' : Basis ι' R M) : ι ≃ ι' := (Cardinal.lift_mk_eq'.1 <| mk_eq_mk_of_basis v v').some #align basis.index_equiv Basis.indexEquiv theorem mk_eq_mk_of_basis' {ι' : Type w} (v : Basis ι R M) (v' : Basis ι' R M) : #ι = #ι' := Cardinal.lift_inj.1 <| mk_eq_mk_of_basis v v' #align mk_eq_mk_of_basis' mk_eq_mk_of_basis' end InvariantBasisNumber section RankCondition variable [RankCondition R] /-- An auxiliary lemma for `Basis.le_span`. If `R` satisfies the rank condition, then for any finite basis `b : Basis ι R M`, and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem Basis.le_span'' {ι : Type*} [Fintype ι] (b : Basis ι R M) {w : Set M} [Fintype w] (s : span R w = ⊤) : Fintype.card ι ≤ Fintype.card w := by -- We construct a surjective linear map `(w → R) →ₗ[R] (ι → R)`, -- by expressing a linear combination in `w` as a linear combination in `ι`. fapply card_le_of_surjective' R · exact b.repr.toLinearMap.comp (Finsupp.total w M R (↑)) · apply Surjective.comp (g := b.repr.toLinearMap) · apply LinearEquiv.surjective rw [← LinearMap.range_eq_top, Finsupp.range_total] simpa using s #align basis.le_span'' Basis.le_span'' /-- Another auxiliary lemma for `Basis.le_span`, which does not require assuming the basis is finite, but still assumes we have a finite spanning set. -/ theorem basis_le_span' {ι : Type*} (b : Basis ι R M) {w : Set M} [Fintype w] (s : span R w = ⊤) : #ι ≤ Fintype.card w := by haveI := nontrivial_of_invariantBasisNumber R haveI := basis_finite_of_finite_spans w (toFinite _) s b cases nonempty_fintype ι rw [Cardinal.mk_fintype ι] simp only [Cardinal.natCast_le] exact Basis.le_span'' b s #align basis_le_span' basis_le_span' -- Note that if `R` satisfies the strong rank condition, -- this also follows from `linearIndependent_le_span` below. /-- If `R` satisfies the rank condition, then the cardinality of any basis is bounded by the cardinality of any spanning set. -/ theorem Basis.le_span {J : Set M} (v : Basis ι R M) (hJ : span R J = ⊤) : #(range v) ≤ #J := by haveI := nontrivial_of_invariantBasisNumber R cases fintypeOrInfinite J · rw [← Cardinal.lift_le, Cardinal.mk_range_eq_of_injective v.injective, Cardinal.mk_fintype J] convert Cardinal.lift_le.{v}.2 (basis_le_span' v hJ) simp · let S : J → Set ι := fun j => ↑(v.repr j).support let S' : J → Set M := fun j => v '' S j have hs : range v ⊆ ⋃ j, S' j := by intro b hb rcases mem_range.1 hb with ⟨i, hi⟩ have : span R J ≤ comap v.repr.toLinearMap (Finsupp.supported R R (⋃ j, S j)) := span_le.2 fun j hj x hx => ⟨_, ⟨⟨j, hj⟩, rfl⟩, hx⟩ rw [hJ] at this replace : v.repr (v i) ∈ Finsupp.supported R R (⋃ j, S j) := this trivial rw [v.repr_self, Finsupp.mem_supported, Finsupp.support_single_ne_zero _ one_ne_zero] at this · subst b rcases mem_iUnion.1 (this (Finset.mem_singleton_self _)) with ⟨j, hj⟩ exact mem_iUnion.2 ⟨j, (mem_image _ _ _).2 ⟨i, hj, rfl⟩⟩ refine le_of_not_lt fun IJ => ?_ suffices #(⋃ j, S' j) < #(range v) by exact not_le_of_lt this ⟨Set.embeddingOfSubset _ _ hs⟩ refine lt_of_le_of_lt (le_trans Cardinal.mk_iUnion_le_sum_mk (Cardinal.sum_le_sum _ (fun _ => ℵ₀) ?_)) ?_ · exact fun j => (Cardinal.lt_aleph0_of_finite _).le · simpa #align basis.le_span Basis.le_span end RankCondition section StrongRankCondition variable [StrongRankCondition R] open Submodule -- An auxiliary lemma for `linearIndependent_le_span'`, -- with the additional assumption that the linearly independent family is finite. theorem linearIndependent_le_span_aux' {ι : Type*} [Fintype ι] (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : range v ≤ span R w) : Fintype.card ι ≤ Fintype.card w := by -- We construct an injective linear map `(ι → R) →ₗ[R] (w → R)`, -- by thinking of `f : ι → R` as a linear combination of the finite family `v`, -- and expressing that (using the axiom of choice) as a linear combination over `w`. -- We can do this linearly by constructing the map on a basis. fapply card_le_of_injective' R · apply Finsupp.total exact fun i => Span.repr R w ⟨v i, s (mem_range_self i)⟩ · intro f g h apply_fun Finsupp.total w M R (↑) at h simp only [Finsupp.total_total, Submodule.coe_mk, Span.finsupp_total_repr] at h rw [← sub_eq_zero, ← LinearMap.map_sub] at h exact sub_eq_zero.mp (linearIndependent_iff.mp i _ h) #align linear_independent_le_span_aux' linearIndependent_le_span_aux' /-- If `R` satisfies the strong rank condition, then any linearly independent family `v : ι → M` contained in the span of some finite `w : Set M`, is itself finite. -/ lemma LinearIndependent.finite_of_le_span_finite {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Finite w] (s : range v ≤ span R w) : Finite ι := letI := Fintype.ofFinite w Fintype.finite <| fintypeOfFinsetCardLe (Fintype.card w) fun t => by let v' := fun x : (t : Set ι) => v x have i' : LinearIndependent R v' := i.comp _ Subtype.val_injective have s' : range v' ≤ span R w := (range_comp_subset_range _ _).trans s simpa using linearIndependent_le_span_aux' v' i' w s' #align linear_independent_fintype_of_le_span_fintype LinearIndependent.finite_of_le_span_finite /-- If `R` satisfies the strong rank condition, then for any linearly independent family `v : ι → M` contained in the span of some finite `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem linearIndependent_le_span' {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : range v ≤ span R w) : #ι ≤ Fintype.card w := by haveI : Finite ι := i.finite_of_le_span_finite v w s letI := Fintype.ofFinite ι rw [Cardinal.mk_fintype] simp only [Cardinal.natCast_le] exact linearIndependent_le_span_aux' v i w s #align linear_independent_le_span' linearIndependent_le_span' /-- If `R` satisfies the strong rank condition, then for any linearly independent family `v : ι → M` and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem linearIndependent_le_span {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : span R w = ⊤) : #ι ≤ Fintype.card w := by apply linearIndependent_le_span' v i w rw [s] exact le_top #align linear_independent_le_span linearIndependent_le_span /-- A version of `linearIndependent_le_span` for `Finset`. -/ theorem linearIndependent_le_span_finset {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Finset M) (s : span R (w : Set M) = ⊤) : #ι ≤ w.card := by simpa only [Finset.coe_sort_coe, Fintype.card_coe] using linearIndependent_le_span v i w s #align linear_independent_le_span_finset linearIndependent_le_span_finset /-- An auxiliary lemma for `linearIndependent_le_basis`: we handle the case where the basis `b` is infinite. -/ theorem linearIndependent_le_infinite_basis {ι : Type w} (b : Basis ι R M) [Infinite ι] {κ : Type w} (v : κ → M) (i : LinearIndependent R v) : #κ ≤ #ι := by classical by_contra h rw [not_le, ← Cardinal.mk_finset_of_infinite ι] at h let Φ := fun k : κ => (b.repr (v k)).support obtain ⟨s, w : Infinite ↑(Φ ⁻¹' {s})⟩ := Cardinal.exists_infinite_fiber Φ h (by infer_instance) let v' := fun k : Φ ⁻¹' {s} => v k have i' : LinearIndependent R v' := i.comp _ Subtype.val_injective have w' : Finite (Φ ⁻¹' {s}) := by apply i'.finite_of_le_span_finite v' (s.image b) rintro m ⟨⟨p, ⟨rfl⟩⟩, rfl⟩ simp only [SetLike.mem_coe, Subtype.coe_mk, Finset.coe_image] apply Basis.mem_span_repr_support exact w.false #align linear_independent_le_infinite_basis linearIndependent_le_infinite_basis /-- Over any ring `R` satisfying the strong rank condition, if `b` is a basis for a module `M`, and `s` is a linearly independent set, then the cardinality of `s` is bounded by the cardinality of `b`. -/ theorem linearIndependent_le_basis {ι : Type w} (b : Basis ι R M) {κ : Type w} (v : κ → M) (i : LinearIndependent R v) : #κ ≤ #ι := by classical -- We split into cases depending on whether `ι` is infinite. cases fintypeOrInfinite ι · rw [Cardinal.mk_fintype ι] -- When `ι` is finite, we have `linearIndependent_le_span`, haveI : Nontrivial R := nontrivial_of_invariantBasisNumber R rw [Fintype.card_congr (Equiv.ofInjective b b.injective)] exact linearIndependent_le_span v i (range b) b.span_eq · -- and otherwise we have `linearIndependent_le_infinite_basis`. exact linearIndependent_le_infinite_basis b v i #align linear_independent_le_basis linearIndependent_le_basis /-- Let `R` satisfy the strong rank condition. If `m` elements of a free rank `n` `R`-module are linearly independent, then `m ≤ n`. -/ theorem Basis.card_le_card_of_linearIndependent_aux {R : Type*} [Ring R] [StrongRankCondition R] (n : ℕ) {m : ℕ} (v : Fin m → Fin n → R) : LinearIndependent R v → m ≤ n := fun h => by simpa using linearIndependent_le_basis (Pi.basisFun R (Fin n)) v h #align basis.card_le_card_of_linear_independent_aux Basis.card_le_card_of_linearIndependent_aux -- When the basis is not infinite this need not be true! /-- Over any ring `R` satisfying the strong rank condition, if `b` is an infinite basis for a module `M`, then every maximal linearly independent set has the same cardinality as `b`. This proof (along with some of the lemmas above) comes from [Les familles libres maximales d'un module ont-elles le meme cardinal?][lazarus1973] -/ theorem maximal_linearIndependent_eq_infinite_basis {ι : Type w} (b : Basis ι R M) [Infinite ι] {κ : Type w} (v : κ → M) (i : LinearIndependent R v) (m : i.Maximal) : #κ = #ι := by apply le_antisymm · exact linearIndependent_le_basis b v i · haveI : Nontrivial R := nontrivial_of_invariantBasisNumber R exact infinite_basis_le_maximal_linearIndependent b v i m #align maximal_linear_independent_eq_infinite_basis maximal_linearIndependent_eq_infinite_basis
Mathlib/LinearAlgebra/Dimension/StrongRankCondition.lean
302
317
theorem Basis.mk_eq_rank'' {ι : Type v} (v : Basis ι R M) : #ι = Module.rank R M := by
haveI := nontrivial_of_invariantBasisNumber R rw [Module.rank_def] apply le_antisymm · trans swap · apply le_ciSup (Cardinal.bddAbove_range.{v, v} _) exact ⟨Set.range v, by convert v.reindexRange.linearIndependent ext simp⟩ · exact (Cardinal.mk_range_eq v v.injective).ge · apply ciSup_le' rintro ⟨s, li⟩ apply linearIndependent_le_basis v _ li
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.MeasureTheory.Integral.Bochner import Mathlib.MeasureTheory.Group.Measure #align_import measure_theory.group.integration from "leanprover-community/mathlib"@"ec247d43814751ffceb33b758e8820df2372bf6f" /-! # Bochner Integration on Groups We develop properties of integrals with a group as domain. This file contains properties about integrability and Bochner integration. -/ namespace MeasureTheory open Measure TopologicalSpace open scoped ENNReal variable {𝕜 M α G E F : Type*} [MeasurableSpace G] variable [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] [NormedAddCommGroup F] variable {μ : Measure G} {f : G → E} {g : G} section MeasurableInv variable [Group G] [MeasurableInv G] @[to_additive] theorem Integrable.comp_inv [IsInvInvariant μ] {f : G → F} (hf : Integrable f μ) : Integrable (fun t => f t⁻¹) μ := (hf.mono_measure (map_inv_eq_self μ).le).comp_measurable measurable_inv #align measure_theory.integrable.comp_inv MeasureTheory.Integrable.comp_inv #align measure_theory.integrable.comp_neg MeasureTheory.Integrable.comp_neg @[to_additive] theorem integral_inv_eq_self (f : G → E) (μ : Measure G) [IsInvInvariant μ] : ∫ x, f x⁻¹ ∂μ = ∫ x, f x ∂μ := by have h : MeasurableEmbedding fun x : G => x⁻¹ := (MeasurableEquiv.inv G).measurableEmbedding rw [← h.integral_map, map_inv_eq_self] #align measure_theory.integral_inv_eq_self MeasureTheory.integral_inv_eq_self #align measure_theory.integral_neg_eq_self MeasureTheory.integral_neg_eq_self end MeasurableInv section MeasurableMul variable [Group G] [MeasurableMul G] /-- Translating a function by left-multiplication does not change its integral with respect to a left-invariant measure. -/ @[to_additive "Translating a function by left-addition does not change its integral with respect to a left-invariant measure."] -- Porting note: was `@[simp]` theorem integral_mul_left_eq_self [IsMulLeftInvariant μ] (f : G → E) (g : G) : (∫ x, f (g * x) ∂μ) = ∫ x, f x ∂μ := by have h_mul : MeasurableEmbedding fun x => g * x := (MeasurableEquiv.mulLeft g).measurableEmbedding rw [← h_mul.integral_map, map_mul_left_eq_self] #align measure_theory.integral_mul_left_eq_self MeasureTheory.integral_mul_left_eq_self #align measure_theory.integral_add_left_eq_self MeasureTheory.integral_add_left_eq_self /-- Translating a function by right-multiplication does not change its integral with respect to a right-invariant measure. -/ @[to_additive "Translating a function by right-addition does not change its integral with respect to a right-invariant measure."] -- Porting note: was `@[simp]` theorem integral_mul_right_eq_self [IsMulRightInvariant μ] (f : G → E) (g : G) : (∫ x, f (x * g) ∂μ) = ∫ x, f x ∂μ := by have h_mul : MeasurableEmbedding fun x => x * g := (MeasurableEquiv.mulRight g).measurableEmbedding rw [← h_mul.integral_map, map_mul_right_eq_self] #align measure_theory.integral_mul_right_eq_self MeasureTheory.integral_mul_right_eq_self #align measure_theory.integral_add_right_eq_self MeasureTheory.integral_add_right_eq_self @[to_additive] -- Porting note: was `@[simp]` theorem integral_div_right_eq_self [IsMulRightInvariant μ] (f : G → E) (g : G) : (∫ x, f (x / g) ∂μ) = ∫ x, f x ∂μ := by simp_rw [div_eq_mul_inv] -- Porting note: was `simp_rw` rw [integral_mul_right_eq_self f g⁻¹] #align measure_theory.integral_div_right_eq_self MeasureTheory.integral_div_right_eq_self #align measure_theory.integral_sub_right_eq_self MeasureTheory.integral_sub_right_eq_self /-- If some left-translate of a function negates it, then the integral of the function with respect to a left-invariant measure is 0. -/ @[to_additive "If some left-translate of a function negates it, then the integral of the function with respect to a left-invariant measure is 0."] theorem integral_eq_zero_of_mul_left_eq_neg [IsMulLeftInvariant μ] (hf' : ∀ x, f (g * x) = -f x) : ∫ x, f x ∂μ = 0 := by simp_rw [← self_eq_neg ℝ E, ← integral_neg, ← hf', integral_mul_left_eq_self] #align measure_theory.integral_eq_zero_of_mul_left_eq_neg MeasureTheory.integral_eq_zero_of_mul_left_eq_neg #align measure_theory.integral_eq_zero_of_add_left_eq_neg MeasureTheory.integral_eq_zero_of_add_left_eq_neg /-- If some right-translate of a function negates it, then the integral of the function with respect to a right-invariant measure is 0. -/ @[to_additive "If some right-translate of a function negates it, then the integral of the function with respect to a right-invariant measure is 0."] theorem integral_eq_zero_of_mul_right_eq_neg [IsMulRightInvariant μ] (hf' : ∀ x, f (x * g) = -f x) : ∫ x, f x ∂μ = 0 := by simp_rw [← self_eq_neg ℝ E, ← integral_neg, ← hf', integral_mul_right_eq_self] #align measure_theory.integral_eq_zero_of_mul_right_eq_neg MeasureTheory.integral_eq_zero_of_mul_right_eq_neg #align measure_theory.integral_eq_zero_of_add_right_eq_neg MeasureTheory.integral_eq_zero_of_add_right_eq_neg @[to_additive] theorem Integrable.comp_mul_left {f : G → F} [IsMulLeftInvariant μ] (hf : Integrable f μ) (g : G) : Integrable (fun t => f (g * t)) μ := (hf.mono_measure (map_mul_left_eq_self μ g).le).comp_measurable <| measurable_const_mul g #align measure_theory.integrable.comp_mul_left MeasureTheory.Integrable.comp_mul_left #align measure_theory.integrable.comp_add_left MeasureTheory.Integrable.comp_add_left @[to_additive] theorem Integrable.comp_mul_right {f : G → F} [IsMulRightInvariant μ] (hf : Integrable f μ) (g : G) : Integrable (fun t => f (t * g)) μ := (hf.mono_measure (map_mul_right_eq_self μ g).le).comp_measurable <| measurable_mul_const g #align measure_theory.integrable.comp_mul_right MeasureTheory.Integrable.comp_mul_right #align measure_theory.integrable.comp_add_right MeasureTheory.Integrable.comp_add_right @[to_additive] theorem Integrable.comp_div_right {f : G → F} [IsMulRightInvariant μ] (hf : Integrable f μ) (g : G) : Integrable (fun t => f (t / g)) μ := by simp_rw [div_eq_mul_inv] exact hf.comp_mul_right g⁻¹ #align measure_theory.integrable.comp_div_right MeasureTheory.Integrable.comp_div_right #align measure_theory.integrable.comp_sub_right MeasureTheory.Integrable.comp_sub_right variable [MeasurableInv G] @[to_additive] theorem Integrable.comp_div_left {f : G → F} [IsInvInvariant μ] [IsMulLeftInvariant μ] (hf : Integrable f μ) (g : G) : Integrable (fun t => f (g / t)) μ := ((measurePreserving_div_left μ g).integrable_comp hf.aestronglyMeasurable).mpr hf #align measure_theory.integrable.comp_div_left MeasureTheory.Integrable.comp_div_left #align measure_theory.integrable.comp_sub_left MeasureTheory.Integrable.comp_sub_left @[to_additive] -- Porting note: was `@[simp]`
Mathlib/MeasureTheory/Group/Integral.lean
141
145
theorem integrable_comp_div_left (f : G → F) [IsInvInvariant μ] [IsMulLeftInvariant μ] (g : G) : Integrable (fun t => f (g / t)) μ ↔ Integrable f μ := by
refine ⟨fun h => ?_, fun h => h.comp_div_left g⟩ convert h.comp_inv.comp_mul_left g⁻¹ simp_rw [div_inv_eq_mul, mul_inv_cancel_left]
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.RingTheory.WittVector.Frobenius import Mathlib.RingTheory.WittVector.Verschiebung import Mathlib.RingTheory.WittVector.MulP #align_import ring_theory.witt_vector.identities from "leanprover-community/mathlib"@"0798037604b2d91748f9b43925fb7570a5f3256c" /-! ## Identities between operations on the ring of Witt vectors In this file we derive common identities between the Frobenius and Verschiebung operators. ## Main declarations * `frobenius_verschiebung`: the composition of Frobenius and Verschiebung is multiplication by `p` * `verschiebung_mul_frobenius`: the “projection formula”: `V(x * F y) = V x * y` * `iterate_verschiebung_mul_coeff`: an identity from [Haze09] 6.2 ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ namespace WittVector variable {p : ℕ} {R : Type*} [hp : Fact p.Prime] [CommRing R] -- type as `\bbW` local notation "𝕎" => WittVector p noncomputable section -- Porting note: `ghost_calc` failure: `simp only []` and the manual instances had to be added. /-- The composition of Frobenius and Verschiebung is multiplication by `p`. -/ theorem frobenius_verschiebung (x : 𝕎 R) : frobenius (verschiebung x) = x * p := by have : IsPoly p fun {R} [CommRing R] x ↦ frobenius (verschiebung x) := IsPoly.comp (hg := frobenius_isPoly p) (hf := verschiebung_isPoly) have : IsPoly p fun {R} [CommRing R] x ↦ x * p := mulN_isPoly p p ghost_calc x ghost_simp [mul_comm] #align witt_vector.frobenius_verschiebung WittVector.frobenius_verschiebung /-- Verschiebung is the same as multiplication by `p` on the ring of Witt vectors of `ZMod p`. -/ theorem verschiebung_zmod (x : 𝕎 (ZMod p)) : verschiebung x = x * p := by rw [← frobenius_verschiebung, frobenius_zmodp] #align witt_vector.verschiebung_zmod WittVector.verschiebung_zmod variable (p R) theorem coeff_p_pow [CharP R p] (i : ℕ) : ((p : 𝕎 R) ^ i).coeff i = 1 := by induction' i with i h · simp only [Nat.zero_eq, one_coeff_zero, Ne, pow_zero] · rw [pow_succ, ← frobenius_verschiebung, coeff_frobenius_charP, verschiebung_coeff_succ, h, one_pow] #align witt_vector.coeff_p_pow WittVector.coeff_p_pow theorem coeff_p_pow_eq_zero [CharP R p] {i j : ℕ} (hj : j ≠ i) : ((p : 𝕎 R) ^ i).coeff j = 0 := by induction' i with i hi generalizing j · rw [pow_zero, one_coeff_eq_of_pos] exact Nat.pos_of_ne_zero hj · rw [pow_succ, ← frobenius_verschiebung, coeff_frobenius_charP] cases j · rw [verschiebung_coeff_zero, zero_pow hp.out.ne_zero] · rw [verschiebung_coeff_succ, hi (ne_of_apply_ne _ hj), zero_pow hp.out.ne_zero] #align witt_vector.coeff_p_pow_eq_zero WittVector.coeff_p_pow_eq_zero theorem coeff_p [CharP R p] (i : ℕ) : (p : 𝕎 R).coeff i = if i = 1 then 1 else 0 := by split_ifs with hi · simpa only [hi, pow_one] using coeff_p_pow p R 1 · simpa only [pow_one] using coeff_p_pow_eq_zero p R hi #align witt_vector.coeff_p WittVector.coeff_p @[simp] theorem coeff_p_zero [CharP R p] : (p : 𝕎 R).coeff 0 = 0 := by rw [coeff_p, if_neg] exact zero_ne_one #align witt_vector.coeff_p_zero WittVector.coeff_p_zero @[simp] theorem coeff_p_one [CharP R p] : (p : 𝕎 R).coeff 1 = 1 := by rw [coeff_p, if_pos rfl] #align witt_vector.coeff_p_one WittVector.coeff_p_one theorem p_nonzero [Nontrivial R] [CharP R p] : (p : 𝕎 R) ≠ 0 := by intro h simpa only [h, zero_coeff, zero_ne_one] using coeff_p_one p R #align witt_vector.p_nonzero WittVector.p_nonzero theorem FractionRing.p_nonzero [Nontrivial R] [CharP R p] : (p : FractionRing (𝕎 R)) ≠ 0 := by simpa using (IsFractionRing.injective (𝕎 R) (FractionRing (𝕎 R))).ne (WittVector.p_nonzero _ _) #align witt_vector.fraction_ring.p_nonzero WittVector.FractionRing.p_nonzero variable {p R} -- Porting note: `ghost_calc` failure: `simp only []` and the manual instances had to be added. /-- The “projection formula” for Frobenius and Verschiebung. -/ theorem verschiebung_mul_frobenius (x y : 𝕎 R) : verschiebung (x * frobenius y) = verschiebung x * y := by have : IsPoly₂ p fun {R} [Rcr : CommRing R] x y ↦ verschiebung (x * frobenius y) := IsPoly.comp₂ (hg := verschiebung_isPoly) (hf := IsPoly₂.comp (hh := mulIsPoly₂) (hf := idIsPolyI' p) (hg := frobenius_isPoly p)) have : IsPoly₂ p fun {R} [CommRing R] x y ↦ verschiebung x * y := IsPoly₂.comp (hh := mulIsPoly₂) (hf := verschiebung_isPoly) (hg := idIsPolyI' p) ghost_calc x y rintro ⟨⟩ <;> ghost_simp [mul_assoc] #align witt_vector.verschiebung_mul_frobenius WittVector.verschiebung_mul_frobenius theorem mul_charP_coeff_zero [CharP R p] (x : 𝕎 R) : (x * p).coeff 0 = 0 := by rw [← frobenius_verschiebung, coeff_frobenius_charP, verschiebung_coeff_zero, zero_pow hp.out.ne_zero] #align witt_vector.mul_char_p_coeff_zero WittVector.mul_charP_coeff_zero theorem mul_charP_coeff_succ [CharP R p] (x : 𝕎 R) (i : ℕ) : (x * p).coeff (i + 1) = x.coeff i ^ p := by rw [← frobenius_verschiebung, coeff_frobenius_charP, verschiebung_coeff_succ] #align witt_vector.mul_char_p_coeff_succ WittVector.mul_charP_coeff_succ theorem verschiebung_frobenius [CharP R p] (x : 𝕎 R) : verschiebung (frobenius x) = x * p := by ext ⟨i⟩ · rw [mul_charP_coeff_zero, verschiebung_coeff_zero] · rw [mul_charP_coeff_succ, verschiebung_coeff_succ, coeff_frobenius_charP] #align witt_vector.verschiebung_frobenius WittVector.verschiebung_frobenius theorem verschiebung_frobenius_comm [CharP R p] : Function.Commute (verschiebung : 𝕎 R → 𝕎 R) frobenius := fun x => by rw [verschiebung_frobenius, frobenius_verschiebung] #align witt_vector.verschiebung_frobenius_comm WittVector.verschiebung_frobenius_comm /-! ## Iteration lemmas -/ open Function theorem iterate_verschiebung_coeff (x : 𝕎 R) (n k : ℕ) : (verschiebung^[n] x).coeff (k + n) = x.coeff k := by induction' n with k ih · simp · rw [iterate_succ_apply', Nat.add_succ, verschiebung_coeff_succ] exact ih #align witt_vector.iterate_verschiebung_coeff WittVector.iterate_verschiebung_coeff theorem iterate_verschiebung_mul_left (x y : 𝕎 R) (i : ℕ) : verschiebung^[i] x * y = verschiebung^[i] (x * frobenius^[i] y) := by induction' i with i ih generalizing y · simp · rw [iterate_succ_apply', ← verschiebung_mul_frobenius, ih, iterate_succ_apply']; rfl #align witt_vector.iterate_verschiebung_mul_left WittVector.iterate_verschiebung_mul_left section CharP variable [CharP R p] theorem iterate_verschiebung_mul (x y : 𝕎 R) (i j : ℕ) : verschiebung^[i] x * verschiebung^[j] y = verschiebung^[i + j] (frobenius^[j] x * frobenius^[i] y) := by calc _ = verschiebung^[i] (x * frobenius^[i] (verschiebung^[j] y)) := ?_ _ = verschiebung^[i] (x * verschiebung^[j] (frobenius^[i] y)) := ?_ _ = verschiebung^[i] (verschiebung^[j] (frobenius^[i] y) * x) := ?_ _ = verschiebung^[i] (verschiebung^[j] (frobenius^[i] y * frobenius^[j] x)) := ?_ _ = verschiebung^[i + j] (frobenius^[i] y * frobenius^[j] x) := ?_ _ = _ := ?_ · apply iterate_verschiebung_mul_left · rw [verschiebung_frobenius_comm.iterate_iterate] · rw [mul_comm] · rw [iterate_verschiebung_mul_left] · rw [iterate_add_apply] · rw [mul_comm] #align witt_vector.iterate_verschiebung_mul WittVector.iterate_verschiebung_mul -- Porting note: `ring_nf` doesn't handle powers yet; needed to add `Nat.pow_succ` rewrite theorem iterate_frobenius_coeff (x : 𝕎 R) (i k : ℕ) : (frobenius^[i] x).coeff k = x.coeff k ^ p ^ i := by induction' i with i ih · simp · rw [iterate_succ_apply', coeff_frobenius_charP, ih, Nat.pow_succ] ring_nf #align witt_vector.iterate_frobenius_coeff WittVector.iterate_frobenius_coeff /-- This is a slightly specialized form of [Hazewinkel, *Witt Vectors*][Haze09] 6.2 equation 5. -/
Mathlib/RingTheory/WittVector/Identities.lean
189
201
theorem iterate_verschiebung_mul_coeff (x y : 𝕎 R) (i j : ℕ) : (verschiebung^[i] x * verschiebung^[j] y).coeff (i + j) = x.coeff 0 ^ p ^ j * y.coeff 0 ^ p ^ i := by
calc _ = (verschiebung^[i + j] (frobenius^[j] x * frobenius^[i] y)).coeff (i + j) := ?_ _ = (frobenius^[j] x * frobenius^[i] y).coeff 0 := ?_ _ = (frobenius^[j] x).coeff 0 * (frobenius^[i] y).coeff 0 := ?_ _ = _ := ?_ · rw [iterate_verschiebung_mul] · convert iterate_verschiebung_coeff (p := p) (R := R) _ _ _ using 2 rw [zero_add] · apply mul_coeff_zero · simp only [iterate_frobenius_coeff]
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.Module.BigOperators import Mathlib.Data.Fintype.BigOperators import Mathlib.LinearAlgebra.AffineSpace.AffineMap import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace import Mathlib.LinearAlgebra.Finsupp import Mathlib.Tactic.FinCases #align_import linear_algebra.affine_space.combination from "leanprover-community/mathlib"@"2de9c37fa71dde2f1c6feff19876dd6a7b1519f0" /-! # Affine combinations of points This file defines affine combinations of points. ## Main definitions * `weightedVSubOfPoint` is a general weighted combination of subtractions with an explicit base point, yielding a vector. * `weightedVSub` uses an arbitrary choice of base point and is intended to be used when the sum of weights is 0, in which case the result is independent of the choice of base point. * `affineCombination` adds the weighted combination to the arbitrary base point, yielding a point rather than a vector, and is intended to be used when the sum of weights is 1, in which case the result is independent of the choice of base point. These definitions are for sums over a `Finset`; versions for a `Fintype` may be obtained using `Finset.univ`, while versions for a `Finsupp` may be obtained using `Finsupp.support`. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Affine namespace Finset theorem univ_fin2 : (univ : Finset (Fin 2)) = {0, 1} := by ext x fin_cases x <;> simp #align finset.univ_fin2 Finset.univ_fin2 variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [S : AffineSpace V P] variable {ι : Type*} (s : Finset ι) variable {ι₂ : Type*} (s₂ : Finset ι₂) /-- A weighted sum of the results of subtracting a base point from the given points, as a linear map on the weights. The main cases of interest are where the sum of the weights is 0, in which case the sum is independent of the choice of base point, and where the sum of the weights is 1, in which case the sum added to the base point is independent of the choice of base point. -/ def weightedVSubOfPoint (p : ι → P) (b : P) : (ι → k) →ₗ[k] V := ∑ i ∈ s, (LinearMap.proj i : (ι → k) →ₗ[k] k).smulRight (p i -ᵥ b) #align finset.weighted_vsub_of_point Finset.weightedVSubOfPoint @[simp] theorem weightedVSubOfPoint_apply (w : ι → k) (p : ι → P) (b : P) : s.weightedVSubOfPoint p b w = ∑ i ∈ s, w i • (p i -ᵥ b) := by simp [weightedVSubOfPoint, LinearMap.sum_apply] #align finset.weighted_vsub_of_point_apply Finset.weightedVSubOfPoint_apply /-- The value of `weightedVSubOfPoint`, where the given points are equal. -/ @[simp (high)] theorem weightedVSubOfPoint_apply_const (w : ι → k) (p : P) (b : P) : s.weightedVSubOfPoint (fun _ => p) b w = (∑ i ∈ s, w i) • (p -ᵥ b) := by rw [weightedVSubOfPoint_apply, sum_smul] #align finset.weighted_vsub_of_point_apply_const Finset.weightedVSubOfPoint_apply_const /-- `weightedVSubOfPoint` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSubOfPoint_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) (b : P) : s.weightedVSubOfPoint p₁ b w₁ = s.weightedVSubOfPoint p₂ b w₂ := by simp_rw [weightedVSubOfPoint_apply] refine sum_congr rfl fun i hi => ?_ rw [hw i hi, hp i hi] #align finset.weighted_vsub_of_point_congr Finset.weightedVSubOfPoint_congr /-- Given a family of points, if we use a member of the family as a base point, the `weightedVSubOfPoint` does not depend on the value of the weights at this point. -/ theorem weightedVSubOfPoint_eq_of_weights_eq (p : ι → P) (j : ι) (w₁ w₂ : ι → k) (hw : ∀ i, i ≠ j → w₁ i = w₂ i) : s.weightedVSubOfPoint p (p j) w₁ = s.weightedVSubOfPoint p (p j) w₂ := by simp only [Finset.weightedVSubOfPoint_apply] congr ext i rcases eq_or_ne i j with h | h · simp [h] · simp [hw i h] #align finset.weighted_vsub_of_point_eq_of_weights_eq Finset.weightedVSubOfPoint_eq_of_weights_eq /-- The weighted sum is independent of the base point when the sum of the weights is 0. -/ theorem weightedVSubOfPoint_eq_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w = s.weightedVSubOfPoint p b₂ w := by apply eq_of_sub_eq_zero rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_sub_distrib] conv_lhs => congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, zero_smul] #align finset.weighted_vsub_of_point_eq_of_sum_eq_zero Finset.weightedVSubOfPoint_eq_of_sum_eq_zero /-- The weighted sum, added to the base point, is independent of the base point when the sum of the weights is 1. -/ theorem weightedVSubOfPoint_vadd_eq_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w +ᵥ b₁ = s.weightedVSubOfPoint p b₂ w +ᵥ b₂ := by erw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← @vsub_eq_zero_iff_eq V, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, ← add_sub_assoc, add_comm, add_sub_assoc, ← sum_sub_distrib] conv_lhs => congr · skip · congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, one_smul, vsub_add_vsub_cancel, vsub_self] #align finset.weighted_vsub_of_point_vadd_eq_of_sum_eq_one Finset.weightedVSubOfPoint_vadd_eq_of_sum_eq_one /-- The weighted sum is unaffected by removing the base point, if present, from the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_erase [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (s.erase i).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_erase rw [vsub_self, smul_zero] #align finset.weighted_vsub_of_point_erase Finset.weightedVSubOfPoint_erase /-- The weighted sum is unaffected by adding the base point, whether or not present, to the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_insert [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (insert i s).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_insert_zero rw [vsub_self, smul_zero] #align finset.weighted_vsub_of_point_insert Finset.weightedVSubOfPoint_insert /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSubOfPoint_indicator_subset (w : ι → k) (p : ι → P) (b : P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint p b (Set.indicator (↑s₁) w) := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] exact Eq.symm <| sum_indicator_subset_of_eq_zero w (fun i wi => wi • (p i -ᵥ b : V)) h fun i => zero_smul k _ #align finset.weighted_vsub_of_point_indicator_subset Finset.weightedVSubOfPoint_indicator_subset /-- A weighted sum, over the image of an embedding, equals a weighted sum with the same points and weights over the original `Finset`. -/ theorem weightedVSubOfPoint_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) (b : P) : (s₂.map e).weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint (p ∘ e) b (w ∘ e) := by simp_rw [weightedVSubOfPoint_apply] exact Finset.sum_map _ _ _ #align finset.weighted_vsub_of_point_map Finset.weightedVSubOfPoint_map /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSubOfPoint` expressions. -/ theorem sum_smul_vsub_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ p₂ : ι → P) (b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSubOfPoint p₁ b w - s.weightedVSubOfPoint p₂ b w := by simp_rw [weightedVSubOfPoint_apply, ← sum_sub_distrib, ← smul_sub, vsub_sub_vsub_cancel_right] #align finset.sum_smul_vsub_eq_weighted_vsub_of_point_sub Finset.sum_smul_vsub_eq_weightedVSubOfPoint_sub /-- A weighted sum of pairwise subtractions, where the point on the right is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_vsub_const_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ : ι → P) (p₂ b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSubOfPoint p₁ b w - (∑ i ∈ s, w i) • (p₂ -ᵥ b) := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] #align finset.sum_smul_vsub_const_eq_weighted_vsub_of_point_sub Finset.sum_smul_vsub_const_eq_weightedVSubOfPoint_sub /-- A weighted sum of pairwise subtractions, where the point on the left is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_const_vsub_eq_sub_weightedVSubOfPoint (w : ι → k) (p₂ : ι → P) (p₁ b : P) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = (∑ i ∈ s, w i) • (p₁ -ᵥ b) - s.weightedVSubOfPoint p₂ b w := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] #align finset.sum_smul_const_vsub_eq_sub_weighted_vsub_of_point Finset.sum_smul_const_vsub_eq_sub_weightedVSubOfPoint /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w + s₂.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, sum_sdiff h] #align finset.weighted_vsub_of_point_sdiff Finset.weightedVSubOfPoint_sdiff /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w - s₂.weightedVSubOfPoint p b (-w) = s.weightedVSubOfPoint p b w := by rw [map_neg, sub_neg_eq_add, s.weightedVSubOfPoint_sdiff h] #align finset.weighted_vsub_of_point_sdiff_sub Finset.weightedVSubOfPoint_sdiff_sub /-- A weighted sum over `s.subtype pred` equals one over `s.filter pred`. -/ theorem weightedVSubOfPoint_subtype_eq_filter (w : ι → k) (p : ι → P) (b : P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSubOfPoint (fun i => p i) b fun i => w i) = (s.filter pred).weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_subtype_eq_sum_filter] #align finset.weighted_vsub_of_point_subtype_eq_filter Finset.weightedVSubOfPoint_subtype_eq_filter /-- A weighted sum over `s.filter pred` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSubOfPoint_filter_of_ne (w : ι → k) (p : ι → P) (b : P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : (s.filter pred).weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, sum_filter_of_ne] intro i hi hne refine h i hi ?_ intro hw simp [hw] at hne #align finset.weighted_vsub_of_point_filter_of_ne Finset.weightedVSubOfPoint_filter_of_ne /-- A constant multiplier of the weights in `weightedVSubOfPoint` may be moved outside the sum. -/ theorem weightedVSubOfPoint_const_smul (w : ι → k) (p : ι → P) (b : P) (c : k) : s.weightedVSubOfPoint p b (c • w) = c • s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, smul_sum, Pi.smul_apply, smul_smul, smul_eq_mul] #align finset.weighted_vsub_of_point_const_smul Finset.weightedVSubOfPoint_const_smul /-- A weighted sum of the results of subtracting a default base point from the given points, as a linear map on the weights. This is intended to be used when the sum of the weights is 0; that condition is specified as a hypothesis on those lemmas that require it. -/ def weightedVSub (p : ι → P) : (ι → k) →ₗ[k] V := s.weightedVSubOfPoint p (Classical.choice S.nonempty) #align finset.weighted_vsub Finset.weightedVSub /-- Applying `weightedVSub` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `weightedVSub` would involve selecting a preferred base point with `weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero` and then using `weightedVSubOfPoint_apply`. -/ theorem weightedVSub_apply (w : ι → k) (p : ι → P) : s.weightedVSub p w = ∑ i ∈ s, w i • (p i -ᵥ Classical.choice S.nonempty) := by simp [weightedVSub, LinearMap.sum_apply] #align finset.weighted_vsub_apply Finset.weightedVSub_apply /-- `weightedVSub` gives the sum of the results of subtracting any base point, when the sum of the weights is 0. -/ theorem weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b : P) : s.weightedVSub p w = s.weightedVSubOfPoint p b w := s.weightedVSubOfPoint_eq_of_sum_eq_zero w p h _ _ #align finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero /-- The value of `weightedVSub`, where the given points are equal and the sum of the weights is 0. -/ @[simp] theorem weightedVSub_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 0) : s.weightedVSub (fun _ => p) w = 0 := by rw [weightedVSub, weightedVSubOfPoint_apply_const, h, zero_smul] #align finset.weighted_vsub_apply_const Finset.weightedVSub_apply_const /-- The `weightedVSub` for an empty set is 0. -/ @[simp] theorem weightedVSub_empty (w : ι → k) (p : ι → P) : (∅ : Finset ι).weightedVSub p w = (0 : V) := by simp [weightedVSub_apply] #align finset.weighted_vsub_empty Finset.weightedVSub_empty /-- `weightedVSub` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSub_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.weightedVSub p₁ w₁ = s.weightedVSub p₂ w₂ := s.weightedVSubOfPoint_congr hw hp _ #align finset.weighted_vsub_congr Finset.weightedVSub_congr /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSub_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSub p w = s₂.weightedVSub p (Set.indicator (↑s₁) w) := weightedVSubOfPoint_indicator_subset _ _ _ h #align finset.weighted_vsub_indicator_subset Finset.weightedVSub_indicator_subset /-- A weighted subtraction, over the image of an embedding, equals a weighted subtraction with the same points and weights over the original `Finset`. -/ theorem weightedVSub_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).weightedVSub p w = s₂.weightedVSub (p ∘ e) (w ∘ e) := s₂.weightedVSubOfPoint_map _ _ _ _ #align finset.weighted_vsub_map Finset.weightedVSub_map /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSub` expressions. -/ theorem sum_smul_vsub_eq_weightedVSub_sub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSub p₁ w - s.weightedVSub p₂ w := s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ #align finset.sum_smul_vsub_eq_weighted_vsub_sub Finset.sum_smul_vsub_eq_weightedVSub_sub /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 0. -/ theorem sum_smul_vsub_const_eq_weightedVSub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSub p₁ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, sub_zero] #align finset.sum_smul_vsub_const_eq_weighted_vsub Finset.sum_smul_vsub_const_eq_weightedVSub /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 0. -/ theorem sum_smul_const_vsub_eq_neg_weightedVSub (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = -s.weightedVSub p₂ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, zero_sub] #align finset.sum_smul_const_vsub_eq_neg_weighted_vsub Finset.sum_smul_const_vsub_eq_neg_weightedVSub /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSub_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w + s₂.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff h _ _ _ #align finset.weighted_vsub_sdiff Finset.weightedVSub_sdiff /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSub_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w - s₂.weightedVSub p (-w) = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff_sub h _ _ _ #align finset.weighted_vsub_sdiff_sub Finset.weightedVSub_sdiff_sub /-- A weighted sum over `s.subtype pred` equals one over `s.filter pred`. -/ theorem weightedVSub_subtype_eq_filter (w : ι → k) (p : ι → P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSub (fun i => p i) fun i => w i) = (s.filter pred).weightedVSub p w := s.weightedVSubOfPoint_subtype_eq_filter _ _ _ _ #align finset.weighted_vsub_subtype_eq_filter Finset.weightedVSub_subtype_eq_filter /-- A weighted sum over `s.filter pred` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSub_filter_of_ne (w : ι → k) (p : ι → P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : (s.filter pred).weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_filter_of_ne _ _ _ h #align finset.weighted_vsub_filter_of_ne Finset.weightedVSub_filter_of_ne /-- A constant multiplier of the weights in `weightedVSub_of` may be moved outside the sum. -/ theorem weightedVSub_const_smul (w : ι → k) (p : ι → P) (c : k) : s.weightedVSub p (c • w) = c • s.weightedVSub p w := s.weightedVSubOfPoint_const_smul _ _ _ _ #align finset.weighted_vsub_const_smul Finset.weightedVSub_const_smul instance : AffineSpace (ι → k) (ι → k) := Pi.instAddTorsor variable (k) /-- A weighted sum of the results of subtracting a default base point from the given points, added to that base point, as an affine map on the weights. This is intended to be used when the sum of the weights is 1, in which case it is an affine combination (barycenter) of the points with the given weights; that condition is specified as a hypothesis on those lemmas that require it. -/ def affineCombination (p : ι → P) : (ι → k) →ᵃ[k] P where toFun w := s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty linear := s.weightedVSub p map_vadd' w₁ w₂ := by simp_rw [vadd_vadd, weightedVSub, vadd_eq_add, LinearMap.map_add] #align finset.affine_combination Finset.affineCombination /-- The linear map corresponding to `affineCombination` is `weightedVSub`. -/ @[simp] theorem affineCombination_linear (p : ι → P) : (s.affineCombination k p).linear = s.weightedVSub p := rfl #align finset.affine_combination_linear Finset.affineCombination_linear variable {k} /-- Applying `affineCombination` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `affineCombination` would involve selecting a preferred base point with `affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one` and then using `weightedVSubOfPoint_apply`. -/ theorem affineCombination_apply (w : ι → k) (p : ι → P) : (s.affineCombination k p) w = s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty := rfl #align finset.affine_combination_apply Finset.affineCombination_apply /-- The value of `affineCombination`, where the given points are equal. -/ @[simp] theorem affineCombination_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 1) : s.affineCombination k (fun _ => p) w = p := by rw [affineCombination_apply, s.weightedVSubOfPoint_apply_const, h, one_smul, vsub_vadd] #align finset.affine_combination_apply_const Finset.affineCombination_apply_const /-- `affineCombination` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem affineCombination_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.affineCombination k p₁ w₁ = s.affineCombination k p₂ w₂ := by simp_rw [affineCombination_apply, s.weightedVSubOfPoint_congr hw hp] #align finset.affine_combination_congr Finset.affineCombination_congr /-- `affineCombination` gives the sum with any base point, when the sum of the weights is 1. -/ theorem affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b : P) : s.affineCombination k p w = s.weightedVSubOfPoint p b w +ᵥ b := s.weightedVSubOfPoint_vadd_eq_of_sum_eq_one w p h _ _ #align finset.affine_combination_eq_weighted_vsub_of_point_vadd_of_sum_eq_one Finset.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one /-- Adding a `weightedVSub` to an `affineCombination`. -/ theorem weightedVSub_vadd_affineCombination (w₁ w₂ : ι → k) (p : ι → P) : s.weightedVSub p w₁ +ᵥ s.affineCombination k p w₂ = s.affineCombination k p (w₁ + w₂) := by rw [← vadd_eq_add, AffineMap.map_vadd, affineCombination_linear] #align finset.weighted_vsub_vadd_affine_combination Finset.weightedVSub_vadd_affineCombination /-- Subtracting two `affineCombination`s. -/ theorem affineCombination_vsub (w₁ w₂ : ι → k) (p : ι → P) : s.affineCombination k p w₁ -ᵥ s.affineCombination k p w₂ = s.weightedVSub p (w₁ - w₂) := by rw [← AffineMap.linearMap_vsub, affineCombination_linear, vsub_eq_sub] #align finset.affine_combination_vsub Finset.affineCombination_vsub theorem attach_affineCombination_of_injective [DecidableEq P] (s : Finset P) (w : P → k) (f : s → P) (hf : Function.Injective f) : s.attach.affineCombination k f (w ∘ f) = (image f univ).affineCombination k id w := by simp only [affineCombination, weightedVSubOfPoint_apply, id, vadd_right_cancel_iff, Function.comp_apply, AffineMap.coe_mk] let g₁ : s → V := fun i => w (f i) • (f i -ᵥ Classical.choice S.nonempty) let g₂ : P → V := fun i => w i • (i -ᵥ Classical.choice S.nonempty) change univ.sum g₁ = (image f univ).sum g₂ have hgf : g₁ = g₂ ∘ f := by ext simp rw [hgf, sum_image] · simp only [Function.comp_apply] · exact fun _ _ _ _ hxy => hf hxy #align finset.attach_affine_combination_of_injective Finset.attach_affineCombination_of_injective theorem attach_affineCombination_coe (s : Finset P) (w : P → k) : s.attach.affineCombination k ((↑) : s → P) (w ∘ (↑)) = s.affineCombination k id w := by classical rw [attach_affineCombination_of_injective s w ((↑) : s → P) Subtype.coe_injective, univ_eq_attach, attach_image_val] #align finset.attach_affine_combination_coe Finset.attach_affineCombination_coe /-- Viewing a module as an affine space modelled on itself, a `weightedVSub` is just a linear combination. -/ @[simp] theorem weightedVSub_eq_linear_combination {ι} (s : Finset ι) {w : ι → k} {p : ι → V} (hw : s.sum w = 0) : s.weightedVSub p w = ∑ i ∈ s, w i • p i := by simp [s.weightedVSub_apply, vsub_eq_sub, smul_sub, ← Finset.sum_smul, hw] #align finset.weighted_vsub_eq_linear_combination Finset.weightedVSub_eq_linear_combination /-- Viewing a module as an affine space modelled on itself, affine combinations are just linear combinations. -/ @[simp] theorem affineCombination_eq_linear_combination (s : Finset ι) (p : ι → V) (w : ι → k) (hw : ∑ i ∈ s, w i = 1) : s.affineCombination k p w = ∑ i ∈ s, w i • p i := by simp [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw 0] #align finset.affine_combination_eq_linear_combination Finset.affineCombination_eq_linear_combination /-- An `affineCombination` equals a point if that point is in the set and has weight 1 and the other points in the set have weight 0. -/ @[simp] theorem affineCombination_of_eq_one_of_eq_zero (w : ι → k) (p : ι → P) {i : ι} (his : i ∈ s) (hwi : w i = 1) (hw0 : ∀ i2 ∈ s, i2 ≠ i → w i2 = 0) : s.affineCombination k p w = p i := by have h1 : ∑ i ∈ s, w i = 1 := hwi ▸ sum_eq_single i hw0 fun h => False.elim (h his) rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p h1 (p i), weightedVSubOfPoint_apply] convert zero_vadd V (p i) refine sum_eq_zero ?_ intro i2 hi2 by_cases h : i2 = i · simp [h] · simp [hw0 i2 hi2 h] #align finset.affine_combination_of_eq_one_of_eq_zero Finset.affineCombination_of_eq_one_of_eq_zero /-- An affine combination is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem affineCombination_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.affineCombination k p w = s₂.affineCombination k p (Set.indicator (↑s₁) w) := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_indicator_subset _ _ _ h] #align finset.affine_combination_indicator_subset Finset.affineCombination_indicator_subset /-- An affine combination, over the image of an embedding, equals an affine combination with the same points and weights over the original `Finset`. -/ theorem affineCombination_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).affineCombination k p w = s₂.affineCombination k (p ∘ e) (w ∘ e) := by simp_rw [affineCombination_apply, weightedVSubOfPoint_map] #align finset.affine_combination_map Finset.affineCombination_map /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `affineCombination` expressions. -/ theorem sum_smul_vsub_eq_affineCombination_vsub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.affineCombination k p₁ w -ᵥ s.affineCombination k p₂ w := by simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ #align finset.sum_smul_vsub_eq_affine_combination_vsub Finset.sum_smul_vsub_eq_affineCombination_vsub /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 1. -/ theorem sum_smul_vsub_const_eq_affineCombination_vsub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 1) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.affineCombination k p₁ w -ᵥ p₂ := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] #align finset.sum_smul_vsub_const_eq_affine_combination_vsub Finset.sum_smul_vsub_const_eq_affineCombination_vsub /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 1. -/ theorem sum_smul_const_vsub_eq_vsub_affineCombination (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 1) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = p₁ -ᵥ s.affineCombination k p₂ w := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] #align finset.sum_smul_const_vsub_eq_vsub_affine_combination Finset.sum_smul_const_vsub_eq_vsub_affineCombination /-- A weighted sum may be split into a subtraction of affine combinations over two subsets. -/ theorem affineCombination_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).affineCombination k p w -ᵥ s₂.affineCombination k p (-w) = s.weightedVSub p w := by simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.weightedVSub_sdiff_sub h _ _ #align finset.affine_combination_sdiff_sub Finset.affineCombination_sdiff_sub /-- If a weighted sum is zero and one of the weights is `-1`, the corresponding point is the affine combination of the other points with the given weights. -/ theorem affineCombination_eq_of_weightedVSub_eq_zero_of_eq_neg_one {w : ι → k} {p : ι → P} (hw : s.weightedVSub p w = (0 : V)) {i : ι} [DecidablePred (· ≠ i)] (his : i ∈ s) (hwi : w i = -1) : (s.filter (· ≠ i)).affineCombination k p w = p i := by classical rw [← @vsub_eq_zero_iff_eq V, ← hw, ← s.affineCombination_sdiff_sub (singleton_subset_iff.2 his), sdiff_singleton_eq_erase, ← filter_ne'] congr refine (affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_singleton_self _) ?_ ?_).symm · simp [hwi] · simp #align finset.affine_combination_eq_of_weighted_vsub_eq_zero_of_eq_neg_one Finset.affineCombination_eq_of_weightedVSub_eq_zero_of_eq_neg_one /-- An affine combination over `s.subtype pred` equals one over `s.filter pred`. -/ theorem affineCombination_subtype_eq_filter (w : ι → k) (p : ι → P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).affineCombination k (fun i => p i) fun i => w i) = (s.filter pred).affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_subtype_eq_filter] #align finset.affine_combination_subtype_eq_filter Finset.affineCombination_subtype_eq_filter /-- An affine combination over `s.filter pred` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem affineCombination_filter_of_ne (w : ι → k) (p : ι → P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : (s.filter pred).affineCombination k p w = s.affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, s.weightedVSubOfPoint_filter_of_ne _ _ _ h] #align finset.affine_combination_filter_of_ne Finset.affineCombination_filter_of_ne /-- Suppose an indexed family of points is given, along with a subset of the index type. A vector can be expressed as `weightedVSubOfPoint` using a `Finset` lying within that subset and with a given sum of weights if and only if it can be expressed as `weightedVSubOfPoint` with that sum of weights for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype {v : V} {x : k} {s : Set ι} {p : ι → P} {b : P} : (∃ fs : Finset ι, ↑fs ⊆ s ∧ ∃ w : ι → k, ∑ i ∈ fs, w i = x ∧ v = fs.weightedVSubOfPoint p b w) ↔ ∃ (fs : Finset s) (w : s → k), ∑ i ∈ fs, w i = x ∧ v = fs.weightedVSubOfPoint (fun i : s => p i) b w := by classical simp_rw [weightedVSubOfPoint_apply] constructor · rintro ⟨fs, hfs, w, rfl, rfl⟩ exact ⟨fs.subtype s, fun i => w i, sum_subtype_of_mem _ hfs, (sum_subtype_of_mem _ hfs).symm⟩ · rintro ⟨fs, w, rfl, rfl⟩ refine ⟨fs.map (Function.Embedding.subtype _), map_subtype_subset _, fun i => if h : i ∈ s then w ⟨i, h⟩ else 0, ?_, ?_⟩ <;> simp #align finset.eq_weighted_vsub_of_point_subset_iff_eq_weighted_vsub_of_point_subtype Finset.eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype variable (k) /-- Suppose an indexed family of points is given, along with a subset of the index type. A vector can be expressed as `weightedVSub` using a `Finset` lying within that subset and with sum of weights 0 if and only if it can be expressed as `weightedVSub` with sum of weights 0 for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_weightedVSub_subset_iff_eq_weightedVSub_subtype {v : V} {s : Set ι} {p : ι → P} : (∃ fs : Finset ι, ↑fs ⊆ s ∧ ∃ w : ι → k, ∑ i ∈ fs, w i = 0 ∧ v = fs.weightedVSub p w) ↔ ∃ (fs : Finset s) (w : s → k), ∑ i ∈ fs, w i = 0 ∧ v = fs.weightedVSub (fun i : s => p i) w := eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype #align finset.eq_weighted_vsub_subset_iff_eq_weighted_vsub_subtype Finset.eq_weightedVSub_subset_iff_eq_weightedVSub_subtype variable (V) /-- Suppose an indexed family of points is given, along with a subset of the index type. A point can be expressed as an `affineCombination` using a `Finset` lying within that subset and with sum of weights 1 if and only if it can be expressed an `affineCombination` with sum of weights 1 for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_affineCombination_subset_iff_eq_affineCombination_subtype {p0 : P} {s : Set ι} {p : ι → P} : (∃ fs : Finset ι, ↑fs ⊆ s ∧ ∃ w : ι → k, ∑ i ∈ fs, w i = 1 ∧ p0 = fs.affineCombination k p w) ↔ ∃ (fs : Finset s) (w : s → k), ∑ i ∈ fs, w i = 1 ∧ p0 = fs.affineCombination k (fun i : s => p i) w := by simp_rw [affineCombination_apply, eq_vadd_iff_vsub_eq] exact eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype #align finset.eq_affine_combination_subset_iff_eq_affine_combination_subtype Finset.eq_affineCombination_subset_iff_eq_affineCombination_subtype variable {k V} /-- Affine maps commute with affine combinations. -/ theorem map_affineCombination {V₂ P₂ : Type*} [AddCommGroup V₂] [Module k V₂] [AffineSpace V₂ P₂] (p : ι → P) (w : ι → k) (hw : s.sum w = 1) (f : P →ᵃ[k] P₂) : f (s.affineCombination k p w) = s.affineCombination k (f ∘ p) w := by have b := Classical.choice (inferInstance : AffineSpace V P).nonempty have b₂ := Classical.choice (inferInstance : AffineSpace V₂ P₂).nonempty rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw b, s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w (f ∘ p) hw b₂, ← s.weightedVSubOfPoint_vadd_eq_of_sum_eq_one w (f ∘ p) hw (f b) b₂] simp only [weightedVSubOfPoint_apply, RingHom.id_apply, AffineMap.map_vadd, LinearMap.map_smulₛₗ, AffineMap.linearMap_vsub, map_sum, Function.comp_apply] #align finset.map_affine_combination Finset.map_affineCombination variable (k) /-- Weights for expressing a single point as an affine combination. -/ def affineCombinationSingleWeights [DecidableEq ι] (i : ι) : ι → k := Function.update (Function.const ι 0) i 1 #align finset.affine_combination_single_weights Finset.affineCombinationSingleWeights @[simp] theorem affineCombinationSingleWeights_apply_self [DecidableEq ι] (i : ι) : affineCombinationSingleWeights k i i = 1 := by simp [affineCombinationSingleWeights] #align finset.affine_combination_single_weights_apply_self Finset.affineCombinationSingleWeights_apply_self @[simp] theorem affineCombinationSingleWeights_apply_of_ne [DecidableEq ι] {i j : ι} (h : j ≠ i) : affineCombinationSingleWeights k i j = 0 := by simp [affineCombinationSingleWeights, h] #align finset.affine_combination_single_weights_apply_of_ne Finset.affineCombinationSingleWeights_apply_of_ne @[simp] theorem sum_affineCombinationSingleWeights [DecidableEq ι] {i : ι} (h : i ∈ s) : ∑ j ∈ s, affineCombinationSingleWeights k i j = 1 := by rw [← affineCombinationSingleWeights_apply_self k i] exact sum_eq_single_of_mem i h fun j _ hj => affineCombinationSingleWeights_apply_of_ne k hj #align finset.sum_affine_combination_single_weights Finset.sum_affineCombinationSingleWeights /-- Weights for expressing the subtraction of two points as a `weightedVSub`. -/ def weightedVSubVSubWeights [DecidableEq ι] (i j : ι) : ι → k := affineCombinationSingleWeights k i - affineCombinationSingleWeights k j #align finset.weighted_vsub_vsub_weights Finset.weightedVSubVSubWeights @[simp] theorem weightedVSubVSubWeights_self [DecidableEq ι] (i : ι) : weightedVSubVSubWeights k i i = 0 := by simp [weightedVSubVSubWeights] #align finset.weighted_vsub_vsub_weights_self Finset.weightedVSubVSubWeights_self @[simp]
Mathlib/LinearAlgebra/AffineSpace/Combination.lean
675
676
theorem weightedVSubVSubWeights_apply_left [DecidableEq ι] {i j : ι} (h : i ≠ j) : weightedVSubVSubWeights k i j i = 1 := by
simp [weightedVSubVSubWeights, h]
/- 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 Mathlib.Topology.Algebra.Order.Archimedean import Mathlib.Topology.Instances.Nat import Mathlib.Topology.Instances.Real #align_import topology.instances.rat from "leanprover-community/mathlib"@"560891c425c743b1a25d4f8447cce6dd60947c1a" /-! # Topology on the rational numbers The structure of a metric space on `ℚ` is introduced in this file, induced from `ℝ`. -/ open Metric Set Filter namespace Rat instance : MetricSpace ℚ := MetricSpace.induced (↑) Rat.cast_injective Real.metricSpace theorem dist_eq (x y : ℚ) : dist x y = |(x : ℝ) - y| := rfl #align rat.dist_eq Rat.dist_eq @[norm_cast, simp] theorem dist_cast (x y : ℚ) : dist (x : ℝ) y = dist x y := rfl #align rat.dist_cast Rat.dist_cast theorem uniformContinuous_coe_real : UniformContinuous ((↑) : ℚ → ℝ) := uniformContinuous_comap #align rat.uniform_continuous_coe_real Rat.uniformContinuous_coe_real theorem uniformEmbedding_coe_real : UniformEmbedding ((↑) : ℚ → ℝ) := uniformEmbedding_comap Rat.cast_injective #align rat.uniform_embedding_coe_real Rat.uniformEmbedding_coe_real theorem denseEmbedding_coe_real : DenseEmbedding ((↑) : ℚ → ℝ) := uniformEmbedding_coe_real.denseEmbedding Rat.denseRange_cast #align rat.dense_embedding_coe_real Rat.denseEmbedding_coe_real theorem embedding_coe_real : Embedding ((↑) : ℚ → ℝ) := denseEmbedding_coe_real.to_embedding #align rat.embedding_coe_real Rat.embedding_coe_real theorem continuous_coe_real : Continuous ((↑) : ℚ → ℝ) := uniformContinuous_coe_real.continuous #align rat.continuous_coe_real Rat.continuous_coe_real end Rat @[norm_cast, simp] theorem Nat.dist_cast_rat (x y : ℕ) : dist (x : ℚ) y = dist x y := by rw [← Nat.dist_cast_real, ← Rat.dist_cast]; congr #align nat.dist_cast_rat Nat.dist_cast_rat theorem Nat.uniformEmbedding_coe_rat : UniformEmbedding ((↑) : ℕ → ℚ) := uniformEmbedding_bot_of_pairwise_le_dist zero_lt_one <| by simpa using Nat.pairwise_one_le_dist #align nat.uniform_embedding_coe_rat Nat.uniformEmbedding_coe_rat theorem Nat.closedEmbedding_coe_rat : ClosedEmbedding ((↑) : ℕ → ℚ) := closedEmbedding_of_pairwise_le_dist zero_lt_one <| by simpa using Nat.pairwise_one_le_dist #align nat.closed_embedding_coe_rat Nat.closedEmbedding_coe_rat @[norm_cast, simp]
Mathlib/Topology/Instances/Rat.lean
70
71
theorem Int.dist_cast_rat (x y : ℤ) : dist (x : ℚ) y = dist x y := by
rw [← Int.dist_cast_real, ← Rat.dist_cast]; congr
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Basic import Mathlib.Algebra.Lie.Subalgebra import Mathlib.Algebra.Lie.Submodule import Mathlib.Algebra.Algebra.Subalgebra.Basic #align_import algebra.lie.of_associative from "leanprover-community/mathlib"@"f0f3d964763ecd0090c9eb3ae0d15871d08781c4" /-! # Lie algebras of associative algebras This file defines the Lie algebra structure that arises on an associative algebra via the ring commutator. Since the linear endomorphisms of a Lie algebra form an associative algebra, one can define the adjoint action as a morphism of Lie algebras from a Lie algebra to its linear endomorphisms. We make such a definition in this file. ## Main definitions * `LieAlgebra.ofAssociativeAlgebra` * `LieAlgebra.ofAssociativeAlgebraHom` * `LieModule.toEnd` * `LieAlgebra.ad` * `LinearEquiv.lieConj` * `AlgEquiv.toLieEquiv` ## Tags lie algebra, ring commutator, adjoint action -/ universe u v w w₁ w₂ section OfAssociative variable {A : Type v} [Ring A] namespace LieRing /-- An associative ring gives rise to a Lie ring by taking the bracket to be the ring commutator. -/ instance (priority := 100) ofAssociativeRing : LieRing A where add_lie _ _ _ := by simp only [Ring.lie_def, right_distrib, left_distrib]; abel lie_add _ _ _ := by simp only [Ring.lie_def, right_distrib, left_distrib]; abel lie_self := by simp only [Ring.lie_def, forall_const, sub_self] leibniz_lie _ _ _ := by simp only [Ring.lie_def, mul_sub_left_distrib, mul_sub_right_distrib, mul_assoc]; abel #align lie_ring.of_associative_ring LieRing.ofAssociativeRing theorem of_associative_ring_bracket (x y : A) : ⁅x, y⁆ = x * y - y * x := rfl #align lie_ring.of_associative_ring_bracket LieRing.of_associative_ring_bracket @[simp] theorem lie_apply {α : Type*} (f g : α → A) (a : α) : ⁅f, g⁆ a = ⁅f a, g a⁆ := rfl #align lie_ring.lie_apply LieRing.lie_apply end LieRing section AssociativeModule variable {M : Type w} [AddCommGroup M] [Module A M] /-- We can regard a module over an associative ring `A` as a Lie ring module over `A` with Lie bracket equal to its ring commutator. Note that this cannot be a global instance because it would create a diamond when `M = A`, specifically we can build two mathematically-different `bracket A A`s: 1. `@Ring.bracket A _` which says `⁅a, b⁆ = a * b - b * a` 2. `(@LieRingModule.ofAssociativeModule A _ A _ _).toBracket` which says `⁅a, b⁆ = a • b` (and thus `⁅a, b⁆ = a * b`) See note [reducible non-instances] -/ abbrev LieRingModule.ofAssociativeModule : LieRingModule A M where bracket := (· • ·) add_lie := add_smul lie_add := smul_add leibniz_lie := by simp [LieRing.of_associative_ring_bracket, sub_smul, mul_smul, sub_add_cancel] #align lie_ring_module.of_associative_module LieRingModule.ofAssociativeModule attribute [local instance] LieRingModule.ofAssociativeModule theorem lie_eq_smul (a : A) (m : M) : ⁅a, m⁆ = a • m := rfl #align lie_eq_smul lie_eq_smul end AssociativeModule section LieAlgebra variable {R : Type u} [CommRing R] [Algebra R A] /-- An associative algebra gives rise to a Lie algebra by taking the bracket to be the ring commutator. -/ instance (priority := 100) LieAlgebra.ofAssociativeAlgebra : LieAlgebra R A where lie_smul t x y := by rw [LieRing.of_associative_ring_bracket, LieRing.of_associative_ring_bracket, Algebra.mul_smul_comm, Algebra.smul_mul_assoc, smul_sub] #align lie_algebra.of_associative_algebra LieAlgebra.ofAssociativeAlgebra attribute [local instance] LieRingModule.ofAssociativeModule section AssociativeRepresentation variable {M : Type w} [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] /-- A representation of an associative algebra `A` is also a representation of `A`, regarded as a Lie algebra via the ring commutator. See the comment at `LieRingModule.ofAssociativeModule` for why the possibility `M = A` means this cannot be a global instance. -/ theorem LieModule.ofAssociativeModule : LieModule R A M where smul_lie := smul_assoc lie_smul := smul_algebra_smul_comm #align lie_module.of_associative_module LieModule.ofAssociativeModule instance Module.End.instLieRingModule : LieRingModule (Module.End R M) M := LieRingModule.ofAssociativeModule #align module.End.lie_ring_module Module.End.instLieRingModule instance Module.End.instLieModule : LieModule R (Module.End R M) M := LieModule.ofAssociativeModule #align module.End.lie_module Module.End.instLieModule @[simp] lemma Module.End.lie_apply (f : Module.End R M) (m : M) : ⁅f, m⁆ = f m := rfl end AssociativeRepresentation namespace AlgHom variable {B : Type w} {C : Type w₁} [Ring B] [Ring C] [Algebra R B] [Algebra R C] variable (f : A →ₐ[R] B) (g : B →ₐ[R] C) /-- The map `ofAssociativeAlgebra` associating a Lie algebra to an associative algebra is functorial. -/ def toLieHom : A →ₗ⁅R⁆ B := { f.toLinearMap with map_lie' := fun {_ _} => by simp [LieRing.of_associative_ring_bracket] } #align alg_hom.to_lie_hom AlgHom.toLieHom instance : Coe (A →ₐ[R] B) (A →ₗ⁅R⁆ B) := ⟨toLieHom⟩ /- Porting note: is a syntactic tautology @[simp] theorem toLieHom_coe : f.toLieHom = ↑f := rfl -/ #noalign alg_hom.to_lie_hom_coe @[simp] theorem coe_toLieHom : ((f : A →ₗ⁅R⁆ B) : A → B) = f := rfl #align alg_hom.coe_to_lie_hom AlgHom.coe_toLieHom theorem toLieHom_apply (x : A) : f.toLieHom x = f x := rfl #align alg_hom.to_lie_hom_apply AlgHom.toLieHom_apply @[simp] theorem toLieHom_id : (AlgHom.id R A : A →ₗ⁅R⁆ A) = LieHom.id := rfl #align alg_hom.to_lie_hom_id AlgHom.toLieHom_id @[simp] theorem toLieHom_comp : (g.comp f : A →ₗ⁅R⁆ C) = (g : B →ₗ⁅R⁆ C).comp (f : A →ₗ⁅R⁆ B) := rfl #align alg_hom.to_lie_hom_comp AlgHom.toLieHom_comp
Mathlib/Algebra/Lie/OfAssociative.lean
176
177
theorem toLieHom_injective {f g : A →ₐ[R] B} (h : (f : A →ₗ⁅R⁆ B) = (g : A →ₗ⁅R⁆ B)) : f = g := by
ext a; exact LieHom.congr_fun h a
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Geometry.Euclidean.Circumcenter #align_import geometry.euclidean.monge_point from "leanprover-community/mathlib"@"1a4df69ca1a9a0e5e26bfe12e2b92814216016d0" /-! # Monge point and orthocenter This file defines the orthocenter of a triangle, via its n-dimensional generalization, the Monge point of a simplex. ## Main definitions * `mongePoint` is the Monge point of a simplex, defined in terms of its position on the Euler line and then shown to be the point of concurrence of the Monge planes. * `mongePlane` is a Monge plane of an (n+2)-simplex, which is the (n+1)-dimensional affine subspace of the subspace spanned by the simplex that passes through the centroid of an n-dimensional face and is orthogonal to the opposite edge (in 2 dimensions, this is the same as an altitude). * `altitude` is the line that passes through a vertex of a simplex and is orthogonal to the opposite face. * `orthocenter` is defined, for the case of a triangle, to be the same as its Monge point, then shown to be the point of concurrence of the altitudes. * `OrthocentricSystem` is a predicate on sets of points that says whether they are four points, one of which is the orthocenter of the other three (in which case various other properties hold, including that each is the orthocenter of the other three). ## References * <https://en.wikipedia.org/wiki/Altitude_(triangle)> * <https://en.wikipedia.org/wiki/Monge_point> * <https://en.wikipedia.org/wiki/Orthocentric_system> * Małgorzata Buba-Brzozowa, [The Monge Point and the 3(n+1) Point Sphere of an n-Simplex](https://pdfs.semanticscholar.org/6f8b/0f623459c76dac2e49255737f8f0f4725d16.pdf) -/ noncomputable section open scoped Classical open scoped RealInnerProductSpace namespace Affine namespace Simplex open Finset AffineSubspace EuclideanGeometry PointsWithCircumcenterIndex variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The Monge point of a simplex (in 2 or more dimensions) is a generalization of the orthocenter of a triangle. It is defined to be the intersection of the Monge planes, where a Monge plane is the (n-1)-dimensional affine subspace of the subspace spanned by the simplex that passes through the centroid of an (n-2)-dimensional face and is orthogonal to the opposite edge (in 2 dimensions, this is the same as an altitude). The circumcenter O, centroid G and Monge point M are collinear in that order on the Euler line, with OG : GM = (n-1): 2. Here, we use that ratio to define the Monge point (so resulting in a point that equals the centroid in 0 or 1 dimensions), and then show in subsequent lemmas that the point so defined lies in the Monge planes and is their unique point of intersection. -/ def mongePoint {n : ℕ} (s : Simplex ℝ P n) : P := (((n + 1 : ℕ) : ℝ) / ((n - 1 : ℕ) : ℝ)) • ((univ : Finset (Fin (n + 1))).centroid ℝ s.points -ᵥ s.circumcenter) +ᵥ s.circumcenter #align affine.simplex.monge_point Affine.Simplex.mongePoint /-- The position of the Monge point in relation to the circumcenter and centroid. -/ theorem mongePoint_eq_smul_vsub_vadd_circumcenter {n : ℕ} (s : Simplex ℝ P n) : s.mongePoint = (((n + 1 : ℕ) : ℝ) / ((n - 1 : ℕ) : ℝ)) • ((univ : Finset (Fin (n + 1))).centroid ℝ s.points -ᵥ s.circumcenter) +ᵥ s.circumcenter := rfl #align affine.simplex.monge_point_eq_smul_vsub_vadd_circumcenter Affine.Simplex.mongePoint_eq_smul_vsub_vadd_circumcenter /-- The Monge point lies in the affine span. -/ theorem mongePoint_mem_affineSpan {n : ℕ} (s : Simplex ℝ P n) : s.mongePoint ∈ affineSpan ℝ (Set.range s.points) := smul_vsub_vadd_mem _ _ (centroid_mem_affineSpan_of_card_eq_add_one ℝ _ (card_fin (n + 1))) s.circumcenter_mem_affineSpan s.circumcenter_mem_affineSpan #align affine.simplex.monge_point_mem_affine_span Affine.Simplex.mongePoint_mem_affineSpan /-- Two simplices with the same points have the same Monge point. -/
Mathlib/Geometry/Euclidean/MongePoint.lean
103
106
theorem mongePoint_eq_of_range_eq {n : ℕ} {s₁ s₂ : Simplex ℝ P n} (h : Set.range s₁.points = Set.range s₂.points) : s₁.mongePoint = s₂.mongePoint := by
simp_rw [mongePoint_eq_smul_vsub_vadd_circumcenter, centroid_eq_of_range_eq h, circumcenter_eq_of_range_eq h]
/- 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 Mathlib.AlgebraicTopology.SplitSimplicialObject import Mathlib.AlgebraicTopology.DoldKan.PInfty #align_import algebraic_topology.dold_kan.functor_gamma from "leanprover-community/mathlib"@"32a7e535287f9c73f2e4d2aef306a39190f0b504" /-! # Construction of the inverse functor of the Dold-Kan equivalence In this file, we construct the functor `Γ₀ : ChainComplex C ℕ ⥤ SimplicialObject C` which shall be the inverse functor of the Dold-Kan equivalence in the case of abelian categories, and more generally pseudoabelian categories. By definition, when `K` is a chain_complex, `Γ₀.obj K` is a simplicial object which sends `Δ : SimplexCategoryᵒᵖ` to a certain coproduct indexed by the set `Splitting.IndexSet Δ` whose elements consists of epimorphisms `e : Δ.unop ⟶ Δ'.unop` (with `Δ' : SimplexCategoryᵒᵖ`); the summand attached to such an `e` is `K.X Δ'.unop.len`. By construction, `Γ₀.obj K` is a split simplicial object whose splitting is `Γ₀.splitting K`. We also construct `Γ₂ : Karoubi (ChainComplex C ℕ) ⥤ Karoubi (SimplicialObject C)` which shall be an equivalence for any additive category `C`. (See `Equivalence.lean` for the general strategy of proof of the Dold-Kan equivalence.) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Limits SimplexCategory SimplicialObject Opposite CategoryTheory.Idempotents Simplicial DoldKan namespace AlgebraicTopology namespace DoldKan variable {C : Type*} [Category C] [Preadditive C] (K K' : ChainComplex C ℕ) (f : K ⟶ K') {Δ Δ' Δ'' : SimplexCategory} /-- `Isδ₀ i` is a simple condition used to check whether a monomorphism `i` in `SimplexCategory` identifies to the coface map `δ 0`. -/ @[nolint unusedArguments] def Isδ₀ {Δ Δ' : SimplexCategory} (i : Δ' ⟶ Δ) [Mono i] : Prop := Δ.len = Δ'.len + 1 ∧ i.toOrderHom 0 ≠ 0 #align algebraic_topology.dold_kan.is_δ₀ AlgebraicTopology.DoldKan.Isδ₀ namespace Isδ₀ theorem iff {j : ℕ} {i : Fin (j + 2)} : Isδ₀ (SimplexCategory.δ i) ↔ i = 0 := by constructor · rintro ⟨_, h₂⟩ by_contra h exact h₂ (Fin.succAbove_ne_zero_zero h) · rintro rfl exact ⟨rfl, by dsimp; exact Fin.succ_ne_zero (0 : Fin (j + 1))⟩ #align algebraic_topology.dold_kan.is_δ₀.iff AlgebraicTopology.DoldKan.Isδ₀.iff theorem eq_δ₀ {n : ℕ} {i : ([n] : SimplexCategory) ⟶ [n + 1]} [Mono i] (hi : Isδ₀ i) : i = SimplexCategory.δ 0 := by obtain ⟨j, rfl⟩ := SimplexCategory.eq_δ_of_mono i rw [iff] at hi rw [hi] #align algebraic_topology.dold_kan.is_δ₀.eq_δ₀ AlgebraicTopology.DoldKan.Isδ₀.eq_δ₀ end Isδ₀ namespace Γ₀ namespace Obj /-- In the definition of `(Γ₀.obj K).obj Δ` as a direct sum indexed by `A : Splitting.IndexSet Δ`, the summand `summand K Δ A` is `K.X A.1.len`. -/ def summand (Δ : SimplexCategoryᵒᵖ) (A : Splitting.IndexSet Δ) : C := K.X A.1.unop.len #align algebraic_topology.dold_kan.Γ₀.obj.summand AlgebraicTopology.DoldKan.Γ₀.Obj.summand /-- The functor `Γ₀` sends a chain complex `K` to the simplicial object which sends `Δ` to the direct sum of the objects `summand K Δ A` for all `A : Splitting.IndexSet Δ` -/ def obj₂ (K : ChainComplex C ℕ) (Δ : SimplexCategoryᵒᵖ) [HasFiniteCoproducts C] : C := ∐ fun A : Splitting.IndexSet Δ => summand K Δ A #align algebraic_topology.dold_kan.Γ₀.obj.obj₂ AlgebraicTopology.DoldKan.Γ₀.Obj.obj₂ namespace Termwise /-- A monomorphism `i : Δ' ⟶ Δ` induces a morphism `K.X Δ.len ⟶ K.X Δ'.len` which is the identity if `Δ = Δ'`, the differential on the complex `K` if `i = δ 0`, and zero otherwise. -/ def mapMono (K : ChainComplex C ℕ) {Δ' Δ : SimplexCategory} (i : Δ' ⟶ Δ) [Mono i] : K.X Δ.len ⟶ K.X Δ'.len := by by_cases Δ = Δ' · exact eqToHom (by congr) · by_cases Isδ₀ i · exact K.d Δ.len Δ'.len · exact 0 #align algebraic_topology.dold_kan.Γ₀.obj.termwise.map_mono AlgebraicTopology.DoldKan.Γ₀.Obj.Termwise.mapMono variable (Δ) theorem mapMono_id : mapMono K (𝟙 Δ) = 𝟙 _ := by unfold mapMono simp only [eq_self_iff_true, eqToHom_refl, dite_eq_ite, if_true] #align algebraic_topology.dold_kan.Γ₀.obj.termwise.map_mono_id AlgebraicTopology.DoldKan.Γ₀.Obj.Termwise.mapMono_id variable {Δ} theorem mapMono_δ₀' (i : Δ' ⟶ Δ) [Mono i] (hi : Isδ₀ i) : mapMono K i = K.d Δ.len Δ'.len := by unfold mapMono suffices Δ ≠ Δ' by simp only [dif_neg this, dif_pos hi] rintro rfl simpa only [self_eq_add_right, Nat.one_ne_zero] using hi.1 #align algebraic_topology.dold_kan.Γ₀.obj.termwise.map_mono_δ₀' AlgebraicTopology.DoldKan.Γ₀.Obj.Termwise.mapMono_δ₀' @[simp] theorem mapMono_δ₀ {n : ℕ} : mapMono K (δ (0 : Fin (n + 2))) = K.d (n + 1) n := mapMono_δ₀' K _ (by rw [Isδ₀.iff]) #align algebraic_topology.dold_kan.Γ₀.obj.termwise.map_mono_δ₀ AlgebraicTopology.DoldKan.Γ₀.Obj.Termwise.mapMono_δ₀ theorem mapMono_eq_zero (i : Δ' ⟶ Δ) [Mono i] (h₁ : Δ ≠ Δ') (h₂ : ¬Isδ₀ i) : mapMono K i = 0 := by unfold mapMono rw [Ne] at h₁ split_ifs rfl #align algebraic_topology.dold_kan.Γ₀.obj.termwise.map_mono_eq_zero AlgebraicTopology.DoldKan.Γ₀.Obj.Termwise.mapMono_eq_zero variable {K K'} @[reassoc (attr := simp)] theorem mapMono_naturality (i : Δ ⟶ Δ') [Mono i] : mapMono K i ≫ f.f Δ.len = f.f Δ'.len ≫ mapMono K' i := by unfold mapMono split_ifs with h · subst h simp only [id_comp, eqToHom_refl, comp_id] · rw [HomologicalComplex.Hom.comm] · rw [zero_comp, comp_zero] #align algebraic_topology.dold_kan.Γ₀.obj.termwise.map_mono_naturality AlgebraicTopology.DoldKan.Γ₀.Obj.Termwise.mapMono_naturality variable (K) @[reassoc (attr := simp)]
Mathlib/AlgebraicTopology/DoldKan/FunctorGamma.lean
148
173
theorem mapMono_comp (i' : Δ'' ⟶ Δ') (i : Δ' ⟶ Δ) [Mono i'] [Mono i] : mapMono K i ≫ mapMono K i' = mapMono K (i' ≫ i) := by
-- case where i : Δ' ⟶ Δ is the identity by_cases h₁ : Δ = Δ' · subst h₁ simp only [SimplexCategory.eq_id_of_mono i, comp_id, id_comp, mapMono_id K, eqToHom_refl] -- case where i' : Δ'' ⟶ Δ' is the identity by_cases h₂ : Δ' = Δ'' · subst h₂ simp only [SimplexCategory.eq_id_of_mono i', comp_id, id_comp, mapMono_id K, eqToHom_refl] -- then the RHS is always zero obtain ⟨k, hk⟩ := Nat.exists_eq_add_of_lt (len_lt_of_mono i h₁) obtain ⟨k', hk'⟩ := Nat.exists_eq_add_of_lt (len_lt_of_mono i' h₂) have eq : Δ.len = Δ''.len + (k + k' + 2) := by omega rw [mapMono_eq_zero K (i' ≫ i) _ _]; rotate_left · by_contra h simp only [self_eq_add_right, h, add_eq_zero_iff, and_false] at eq · by_contra h simp only [h.1, add_right_inj] at eq omega -- in all cases, the LHS is also zero, either by definition, or because d ≫ d = 0 by_cases h₃ : Isδ₀ i · by_cases h₄ : Isδ₀ i' · rw [mapMono_δ₀' K i h₃, mapMono_δ₀' K i' h₄, HomologicalComplex.d_comp_d] · simp only [mapMono_eq_zero K i' h₂ h₄, comp_zero] · simp only [mapMono_eq_zero K i h₁ h₃, zero_comp]
/- Copyright (c) 2021 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Combinatorics.SetFamily.Shadow #align_import combinatorics.set_family.compression.uv from "leanprover-community/mathlib"@"6f8ab7de1c4b78a68ab8cf7dd83d549eb78a68a1" /-! # UV-compressions This file defines UV-compression. It is an operation on a set family that reduces its shadow. UV-compressing `a : α` along `u v : α` means replacing `a` by `(a ⊔ u) \ v` if `a` and `u` are disjoint and `v ≤ a`. In some sense, it's moving `a` from `v` to `u`. UV-compressions are immensely useful to prove the Kruskal-Katona theorem. The idea is that compressing a set family might decrease the size of its shadow, so iterated compressions hopefully minimise the shadow. ## Main declarations * `UV.compress`: `compress u v a` is `a` compressed along `u` and `v`. * `UV.compression`: `compression u v s` is the compression of the set family `s` along `u` and `v`. It is the compressions of the elements of `s` whose compression is not already in `s` along with the element whose compression is already in `s`. This way of splitting into what moves and what does not ensures the compression doesn't squash the set family, which is proved by `UV.card_compression`. * `UV.card_shadow_compression_le`: Compressing reduces the size of the shadow. This is a key fact in the proof of Kruskal-Katona. ## Notation `𝓒` (typed with `\MCC`) is notation for `UV.compression` in locale `FinsetFamily`. ## Notes Even though our emphasis is on `Finset α`, we define UV-compressions more generally in a generalized boolean algebra, so that one can use it for `Set α`. ## References * https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf ## Tags compression, UV-compression, shadow -/ open Finset variable {α : Type*} /-- UV-compression is injective on the elements it moves. See `UV.compress`. -/ theorem sup_sdiff_injOn [GeneralizedBooleanAlgebra α] (u v : α) : { x | Disjoint u x ∧ v ≤ x }.InjOn fun x => (x ⊔ u) \ v := by rintro a ha b hb hab have h : ((a ⊔ u) \ v) \ u ⊔ v = ((b ⊔ u) \ v) \ u ⊔ v := by dsimp at hab rw [hab] rwa [sdiff_sdiff_comm, ha.1.symm.sup_sdiff_cancel_right, sdiff_sdiff_comm, hb.1.symm.sup_sdiff_cancel_right, sdiff_sup_cancel ha.2, sdiff_sup_cancel hb.2] at h #align sup_sdiff_inj_on sup_sdiff_injOn -- The namespace is here to distinguish from other compressions. namespace UV /-! ### UV-compression in generalized boolean algebras -/ section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra α] [DecidableRel (@Disjoint α _ _)] [DecidableRel ((· ≤ ·) : α → α → Prop)] {s : Finset α} {u v a b : α} /-- UV-compressing `a` means removing `v` from it and adding `u` if `a` and `u` are disjoint and `v ≤ a` (it replaces the `v` part of `a` by the `u` part). Else, UV-compressing `a` doesn't do anything. This is most useful when `u` and `v` are disjoint finsets of the same size. -/ def compress (u v a : α) : α := if Disjoint u a ∧ v ≤ a then (a ⊔ u) \ v else a #align uv.compress UV.compress theorem compress_of_disjoint_of_le (hua : Disjoint u a) (hva : v ≤ a) : compress u v a = (a ⊔ u) \ v := if_pos ⟨hua, hva⟩ #align uv.compress_of_disjoint_of_le UV.compress_of_disjoint_of_le theorem compress_of_disjoint_of_le' (hva : Disjoint v a) (hua : u ≤ a) : compress u v ((a ⊔ v) \ u) = a := by rw [compress_of_disjoint_of_le disjoint_sdiff_self_right (le_sdiff.2 ⟨(le_sup_right : v ≤ a ⊔ v), hva.mono_right hua⟩), sdiff_sup_cancel (le_sup_of_le_left hua), hva.symm.sup_sdiff_cancel_right] #align uv.compress_of_disjoint_of_le' UV.compress_of_disjoint_of_le' @[simp] theorem compress_self (u a : α) : compress u u a = a := by unfold compress split_ifs with h · exact h.1.symm.sup_sdiff_cancel_right · rfl #align uv.compress_self UV.compress_self /-- An element can be compressed to any other element by removing/adding the differences. -/ @[simp] theorem compress_sdiff_sdiff (a b : α) : compress (a \ b) (b \ a) b = a := by refine (compress_of_disjoint_of_le disjoint_sdiff_self_left sdiff_le).trans ?_ rw [sup_sdiff_self_right, sup_sdiff, disjoint_sdiff_self_right.sdiff_eq_left, sup_eq_right] exact sdiff_sdiff_le #align uv.compress_sdiff_sdiff UV.compress_sdiff_sdiff /-- Compressing an element is idempotent. -/ @[simp] theorem compress_idem (u v a : α) : compress u v (compress u v a) = compress u v a := by unfold compress split_ifs with h h' · rw [le_sdiff_iff.1 h'.2, sdiff_bot, sdiff_bot, sup_assoc, sup_idem] · rfl · rfl #align uv.compress_idem UV.compress_idem variable [DecidableEq α] /-- To UV-compress a set family, we compress each of its elements, except that we don't want to reduce the cardinality, so we keep all elements whose compression is already present. -/ def compression (u v : α) (s : Finset α) := (s.filter (compress u v · ∈ s)) ∪ (s.image <| compress u v).filter (· ∉ s) #align uv.compression UV.compression @[inherit_doc] scoped[FinsetFamily] notation "𝓒 " => UV.compression open scoped FinsetFamily /-- `IsCompressed u v s` expresses that `s` is UV-compressed. -/ def IsCompressed (u v : α) (s : Finset α) := 𝓒 u v s = s #align uv.is_compressed UV.IsCompressed /-- UV-compression is injective on the sets that are not UV-compressed. -/ theorem compress_injOn : Set.InjOn (compress u v) ↑(s.filter (compress u v · ∉ s)) := by intro a ha b hb hab rw [mem_coe, mem_filter] at ha hb rw [compress] at ha hab split_ifs at ha hab with has · rw [compress] at hb hab split_ifs at hb hab with hbs · exact sup_sdiff_injOn u v has hbs hab · exact (hb.2 hb.1).elim · exact (ha.2 ha.1).elim #align uv.compress_inj_on UV.compress_injOn /-- `a` is in the UV-compressed family iff it's in the original and its compression is in the original, or it's not in the original but it's the compression of something in the original. -/ theorem mem_compression : a ∈ 𝓒 u v s ↔ a ∈ s ∧ compress u v a ∈ s ∨ a ∉ s ∧ ∃ b ∈ s, compress u v b = a := by simp_rw [compression, mem_union, mem_filter, mem_image, and_comm] #align uv.mem_compression UV.mem_compression protected theorem IsCompressed.eq (h : IsCompressed u v s) : 𝓒 u v s = s := h #align uv.is_compressed.eq UV.IsCompressed.eq @[simp] theorem compression_self (u : α) (s : Finset α) : 𝓒 u u s = s := by unfold compression convert union_empty s · ext a rw [mem_filter, compress_self, and_self_iff] · refine eq_empty_of_forall_not_mem fun a ha ↦ ?_ simp_rw [mem_filter, mem_image, compress_self] at ha obtain ⟨⟨b, hb, rfl⟩, hb'⟩ := ha exact hb' hb #align uv.compression_self UV.compression_self /-- Any family is compressed along two identical elements. -/ theorem isCompressed_self (u : α) (s : Finset α) : IsCompressed u u s := compression_self u s #align uv.is_compressed_self UV.isCompressed_self theorem compress_disjoint : Disjoint (s.filter (compress u v · ∈ s)) ((s.image <| compress u v).filter (· ∉ s)) := disjoint_left.2 fun _a ha₁ ha₂ ↦ (mem_filter.1 ha₂).2 (mem_filter.1 ha₁).1 #align uv.compress_disjoint UV.compress_disjoint theorem compress_mem_compression (ha : a ∈ s) : compress u v a ∈ 𝓒 u v s := by rw [mem_compression] by_cases h : compress u v a ∈ s · rw [compress_idem] exact Or.inl ⟨h, h⟩ · exact Or.inr ⟨h, a, ha, rfl⟩ #align uv.compress_mem_compression UV.compress_mem_compression -- This is a special case of `compress_mem_compression` once we have `compression_idem`. theorem compress_mem_compression_of_mem_compression (ha : a ∈ 𝓒 u v s) : compress u v a ∈ 𝓒 u v s := by rw [mem_compression] at ha ⊢ simp only [compress_idem, exists_prop] obtain ⟨_, ha⟩ | ⟨_, b, hb, rfl⟩ := ha · exact Or.inl ⟨ha, ha⟩ · exact Or.inr ⟨by rwa [compress_idem], b, hb, (compress_idem _ _ _).symm⟩ #align uv.compress_mem_compression_of_mem_compression UV.compress_mem_compression_of_mem_compression /-- Compressing a family is idempotent. -/ @[simp] theorem compression_idem (u v : α) (s : Finset α) : 𝓒 u v (𝓒 u v s) = 𝓒 u v s := by have h : filter (compress u v · ∉ 𝓒 u v s) (𝓒 u v s) = ∅ := filter_false_of_mem fun a ha h ↦ h <| compress_mem_compression_of_mem_compression ha rw [compression, filter_image, h, image_empty, ← h] exact filter_union_filter_neg_eq _ (compression u v s) #align uv.compression_idem UV.compression_idem /-- Compressing a family doesn't change its size. -/ @[simp] theorem card_compression (u v : α) (s : Finset α) : (𝓒 u v s).card = s.card := by rw [compression, card_union_of_disjoint compress_disjoint, filter_image, card_image_of_injOn compress_injOn, ← card_union_of_disjoint (disjoint_filter_filter_neg s _ _), filter_union_filter_neg_eq] #align uv.card_compression UV.card_compression theorem le_of_mem_compression_of_not_mem (h : a ∈ 𝓒 u v s) (ha : a ∉ s) : u ≤ a := by rw [mem_compression] at h obtain h | ⟨-, b, hb, hba⟩ := h · cases ha h.1 unfold compress at hba split_ifs at hba with h · rw [← hba, le_sdiff] exact ⟨le_sup_right, h.1.mono_right h.2⟩ · cases ne_of_mem_of_not_mem hb ha hba #align uv.le_of_mem_compression_of_not_mem UV.le_of_mem_compression_of_not_mem theorem disjoint_of_mem_compression_of_not_mem (h : a ∈ 𝓒 u v s) (ha : a ∉ s) : Disjoint v a := by rw [mem_compression] at h obtain h | ⟨-, b, hb, hba⟩ := h · cases ha h.1 unfold compress at hba split_ifs at hba · rw [← hba] exact disjoint_sdiff_self_right · cases ne_of_mem_of_not_mem hb ha hba #align uv.disjoint_of_mem_compression_of_not_mem UV.disjoint_of_mem_compression_of_not_mem theorem sup_sdiff_mem_of_mem_compression_of_not_mem (h : a ∈ 𝓒 u v s) (ha : a ∉ s) : (a ⊔ v) \ u ∈ s := by rw [mem_compression] at h obtain h | ⟨-, b, hb, hba⟩ := h · cases ha h.1 unfold compress at hba split_ifs at hba with h · rwa [← hba, sdiff_sup_cancel (le_sup_of_le_left h.2), sup_sdiff_right_self, h.1.symm.sdiff_eq_left] · cases ne_of_mem_of_not_mem hb ha hba #align uv.sup_sdiff_mem_of_mem_compression_of_not_mem UV.sup_sdiff_mem_of_mem_compression_of_not_mem /-- If `a` is in the family compression and can be compressed, then its compression is in the original family. -/
Mathlib/Combinatorics/SetFamily/Compression/UV.lean
256
271
theorem sup_sdiff_mem_of_mem_compression (ha : a ∈ 𝓒 u v s) (hva : v ≤ a) (hua : Disjoint u a) : (a ⊔ u) \ v ∈ s := by
rw [mem_compression, compress_of_disjoint_of_le hua hva] at ha obtain ⟨_, ha⟩ | ⟨_, b, hb, rfl⟩ := ha · exact ha have hu : u = ⊥ := by suffices Disjoint u (u \ v) by rwa [(hua.mono_right hva).sdiff_eq_left, disjoint_self] at this refine hua.mono_right ?_ rw [← compress_idem, compress_of_disjoint_of_le hua hva] exact sdiff_le_sdiff_right le_sup_right have hv : v = ⊥ := by rw [← disjoint_self] apply Disjoint.mono_right hva rw [← compress_idem, compress_of_disjoint_of_le hua hva] exact disjoint_sdiff_self_right rwa [hu, hv, compress_self, sup_bot_eq, sdiff_bot]
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Topology.Algebra.Ring.Ideal import Mathlib.Analysis.SpecificLimits.Normed #align_import analysis.normed_space.units from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # The group of units of a complete normed ring This file contains the basic theory for the group of units (invertible elements) of a complete normed ring (Banach algebras being a notable special case). ## Main results The constructions `Units.oneSub`, `Units.add`, and `Units.ofNearby` state, in varying forms, that perturbations of a unit are units. The latter two are not stated in their optimal form; more precise versions would use the spectral radius. The first main result is `Units.isOpen`: the group of units of a complete normed ring is an open subset of the ring. The function `Ring.inverse` (defined elsewhere), for a ring `R`, sends `a : R` to `a⁻¹` if `a` is a unit and `0` if not. The other major results of this file (notably `NormedRing.inverse_add`, `NormedRing.inverse_add_norm` and `NormedRing.inverse_add_norm_diff_nth_order`) cover the asymptotic properties of `Ring.inverse (x + t)` as `t → 0`. -/ noncomputable section open Topology variable {R : Type*} [NormedRing R] [CompleteSpace R] namespace Units /-- In a complete normed ring, a perturbation of `1` by an element `t` of distance less than `1` from `1` is a unit. Here we construct its `Units` structure. -/ @[simps val] def oneSub (t : R) (h : ‖t‖ < 1) : Rˣ where val := 1 - t inv := ∑' n : ℕ, t ^ n val_inv := mul_neg_geom_series t h inv_val := geom_series_mul_neg t h #align units.one_sub Units.oneSub #align units.coe_one_sub Units.val_oneSub /-- In a complete normed ring, a perturbation of a unit `x` by an element `t` of distance less than `‖x⁻¹‖⁻¹` from `x` is a unit. Here we construct its `Units` structure. -/ @[simps! val] def add (x : Rˣ) (t : R) (h : ‖t‖ < ‖(↑x⁻¹ : R)‖⁻¹) : Rˣ := Units.copy -- to make `add_val` true definitionally, for convenience (x * Units.oneSub (-((x⁻¹).1 * t)) (by nontriviality R using zero_lt_one have hpos : 0 < ‖(↑x⁻¹ : R)‖ := Units.norm_pos x⁻¹ calc ‖-(↑x⁻¹ * t)‖ = ‖↑x⁻¹ * t‖ := by rw [norm_neg] _ ≤ ‖(↑x⁻¹ : R)‖ * ‖t‖ := norm_mul_le (x⁻¹).1 _ _ < ‖(↑x⁻¹ : R)‖ * ‖(↑x⁻¹ : R)‖⁻¹ := by nlinarith only [h, hpos] _ = 1 := mul_inv_cancel (ne_of_gt hpos))) (x + t) (by simp [mul_add]) _ rfl #align units.add Units.add #align units.coe_add Units.val_add /-- In a complete normed ring, an element `y` of distance less than `‖x⁻¹‖⁻¹` from `x` is a unit. Here we construct its `Units` structure. -/ @[simps! val] def ofNearby (x : Rˣ) (y : R) (h : ‖y - x‖ < ‖(↑x⁻¹ : R)‖⁻¹) : Rˣ := (x.add (y - x : R) h).copy y (by simp) _ rfl #align units.unit_of_nearby Units.ofNearby #align units.coe_unit_of_nearby Units.val_ofNearby /-- The group of units of a complete normed ring is an open subset of the ring. -/ protected theorem isOpen : IsOpen { x : R | IsUnit x } := by nontriviality R rw [Metric.isOpen_iff] rintro _ ⟨x, rfl⟩ refine ⟨‖(↑x⁻¹ : R)‖⁻¹, _root_.inv_pos.mpr (Units.norm_pos x⁻¹), fun y hy ↦ ?_⟩ rw [mem_ball_iff_norm] at hy exact (x.ofNearby y hy).isUnit #align units.is_open Units.isOpen protected theorem nhds (x : Rˣ) : { x : R | IsUnit x } ∈ 𝓝 (x : R) := IsOpen.mem_nhds Units.isOpen x.isUnit #align units.nhds Units.nhds end Units namespace nonunits /-- The `nonunits` in a complete normed ring are contained in the complement of the ball of radius `1` centered at `1 : R`. -/ theorem subset_compl_ball : nonunits R ⊆ (Metric.ball (1 : R) 1)ᶜ := fun x hx h₁ ↦ hx <| sub_sub_self 1 x ▸ (Units.oneSub (1 - x) (by rwa [mem_ball_iff_norm'] at h₁)).isUnit #align nonunits.subset_compl_ball nonunits.subset_compl_ball -- The `nonunits` in a complete normed ring are a closed set protected theorem isClosed : IsClosed (nonunits R) := Units.isOpen.isClosed_compl #align nonunits.is_closed nonunits.isClosed end nonunits namespace NormedRing open scoped Classical open Asymptotics Filter Metric Finset Ring theorem inverse_one_sub (t : R) (h : ‖t‖ < 1) : inverse (1 - t) = ↑(Units.oneSub t h)⁻¹ := by rw [← inverse_unit (Units.oneSub t h), Units.val_oneSub] #align normed_ring.inverse_one_sub NormedRing.inverse_one_sub /-- The formula `Ring.inverse (x + t) = Ring.inverse (1 + x⁻¹ * t) * x⁻¹` holds for `t` sufficiently small. -/ theorem inverse_add (x : Rˣ) : ∀ᶠ t in 𝓝 0, inverse ((x : R) + t) = inverse (1 + ↑x⁻¹ * t) * ↑x⁻¹ := by nontriviality R rw [Metric.eventually_nhds_iff] refine ⟨‖(↑x⁻¹ : R)‖⁻¹, by cancel_denoms, fun t ht ↦ ?_⟩ rw [dist_zero_right] at ht rw [← x.val_add t ht, inverse_unit, Units.add, Units.copy_eq, mul_inv_rev, Units.val_mul, ← inverse_unit, Units.val_oneSub, sub_neg_eq_add] #align normed_ring.inverse_add NormedRing.inverse_add
Mathlib/Analysis/NormedSpace/Units.lean
129
135
theorem inverse_one_sub_nth_order' (n : ℕ) {t : R} (ht : ‖t‖ < 1) : inverse ((1 : R) - t) = (∑ i ∈ range n, t ^ i) + t ^ n * inverse (1 - t) := have := NormedRing.summable_geometric_of_norm_lt_one t ht calc inverse (1 - t) = ∑' i : ℕ, t ^ i := inverse_one_sub t ht _ = ∑ i ∈ range n, t ^ i + ∑' i : ℕ, t ^ (i + n) := (sum_add_tsum_nat_add _ this).symm _ = (∑ i ∈ range n, t ^ i) + t ^ n * inverse (1 - t) := by
simp only [inverse_one_sub t ht, add_comm _ n, pow_add, this.tsum_mul_left]; rfl
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Algebra.MonoidAlgebra.Support import Mathlib.Algebra.Polynomial.Basic import Mathlib.Algebra.Regular.Basic import Mathlib.Data.Nat.Choose.Sum #align_import data.polynomial.coeff from "leanprover-community/mathlib"@"2651125b48fc5c170ab1111afd0817c903b1fc6c" /-! # Theory of univariate polynomials The theorems include formulas for computing coefficients, such as `coeff_add`, `coeff_sum`, `coeff_mul` -/ set_option linter.uppercaseLean3 false noncomputable section open Finsupp Finset AddMonoidAlgebra open Polynomial namespace Polynomial universe u v variable {R : Type u} {S : Type v} {a b : R} {n m : ℕ} variable [Semiring R] {p q r : R[X]} section Coeff @[simp] theorem coeff_add (p q : R[X]) (n : ℕ) : coeff (p + q) n = coeff p n + coeff q n := by rcases p with ⟨⟩ rcases q with ⟨⟩ simp_rw [← ofFinsupp_add, coeff] exact Finsupp.add_apply _ _ _ #align polynomial.coeff_add Polynomial.coeff_add set_option linter.deprecated false in @[simp] theorem coeff_bit0 (p : R[X]) (n : ℕ) : coeff (bit0 p) n = bit0 (coeff p n) := by simp [bit0] #align polynomial.coeff_bit0 Polynomial.coeff_bit0 @[simp] theorem coeff_smul [SMulZeroClass S R] (r : S) (p : R[X]) (n : ℕ) : coeff (r • p) n = r • coeff p n := by rcases p with ⟨⟩ simp_rw [← ofFinsupp_smul, coeff] exact Finsupp.smul_apply _ _ _ #align polynomial.coeff_smul Polynomial.coeff_smul theorem support_smul [SMulZeroClass S R] (r : S) (p : R[X]) : support (r • p) ⊆ support p := by intro i hi simp? [mem_support_iff] at hi ⊢ says simp only [mem_support_iff, coeff_smul, ne_eq] at hi ⊢ contrapose! hi simp [hi] #align polynomial.support_smul Polynomial.support_smul open scoped Pointwise in theorem card_support_mul_le : (p * q).support.card ≤ p.support.card * q.support.card := by calc (p * q).support.card _ = (p.toFinsupp * q.toFinsupp).support.card := by rw [← support_toFinsupp, toFinsupp_mul] _ ≤ (p.toFinsupp.support + q.toFinsupp.support).card := Finset.card_le_card (AddMonoidAlgebra.support_mul p.toFinsupp q.toFinsupp) _ ≤ p.support.card * q.support.card := Finset.card_image₂_le .. /-- `Polynomial.sum` as a linear map. -/ @[simps] def lsum {R A M : Type*} [Semiring R] [Semiring A] [AddCommMonoid M] [Module R A] [Module R M] (f : ℕ → A →ₗ[R] M) : A[X] →ₗ[R] M where toFun p := p.sum (f · ·) map_add' p q := sum_add_index p q _ (fun n => (f n).map_zero) fun n _ _ => (f n).map_add _ _ map_smul' c p := by -- Porting note: added `dsimp only`; `beta_reduce` alone is not sufficient dsimp only rw [sum_eq_of_subset (f · ·) (fun n => (f n).map_zero) (support_smul c p)] simp only [sum_def, Finset.smul_sum, coeff_smul, LinearMap.map_smul, RingHom.id_apply] #align polynomial.lsum Polynomial.lsum #align polynomial.lsum_apply Polynomial.lsum_apply variable (R) /-- The nth coefficient, as a linear map. -/ def lcoeff (n : ℕ) : R[X] →ₗ[R] R where toFun p := coeff p n map_add' p q := coeff_add p q n map_smul' r p := coeff_smul r p n #align polynomial.lcoeff Polynomial.lcoeff variable {R} @[simp] theorem lcoeff_apply (n : ℕ) (f : R[X]) : lcoeff R n f = coeff f n := rfl #align polynomial.lcoeff_apply Polynomial.lcoeff_apply @[simp] theorem finset_sum_coeff {ι : Type*} (s : Finset ι) (f : ι → R[X]) (n : ℕ) : coeff (∑ b ∈ s, f b) n = ∑ b ∈ s, coeff (f b) n := map_sum (lcoeff R n) _ _ #align polynomial.finset_sum_coeff Polynomial.finset_sum_coeff lemma coeff_list_sum (l : List R[X]) (n : ℕ) : l.sum.coeff n = (l.map (lcoeff R n)).sum := map_list_sum (lcoeff R n) _ lemma coeff_list_sum_map {ι : Type*} (l : List ι) (f : ι → R[X]) (n : ℕ) : (l.map f).sum.coeff n = (l.map (fun a => (f a).coeff n)).sum := by simp_rw [coeff_list_sum, List.map_map, Function.comp, lcoeff_apply] theorem coeff_sum [Semiring S] (n : ℕ) (f : ℕ → R → S[X]) : coeff (p.sum f) n = p.sum fun a b => coeff (f a b) n := by rcases p with ⟨⟩ -- porting note (#10745): was `simp [Polynomial.sum, support, coeff]`. simp [Polynomial.sum, support_ofFinsupp, coeff_ofFinsupp] #align polynomial.coeff_sum Polynomial.coeff_sum /-- Decomposes the coefficient of the product `p * q` as a sum over `antidiagonal`. A version which sums over `range (n + 1)` can be obtained by using `Finset.Nat.sum_antidiagonal_eq_sum_range_succ`. -/ theorem coeff_mul (p q : R[X]) (n : ℕ) : coeff (p * q) n = ∑ x ∈ antidiagonal n, coeff p x.1 * coeff q x.2 := by rcases p with ⟨p⟩; rcases q with ⟨q⟩ simp_rw [← ofFinsupp_mul, coeff] exact AddMonoidAlgebra.mul_apply_antidiagonal p q n _ Finset.mem_antidiagonal #align polynomial.coeff_mul Polynomial.coeff_mul @[simp] theorem mul_coeff_zero (p q : R[X]) : coeff (p * q) 0 = coeff p 0 * coeff q 0 := by simp [coeff_mul] #align polynomial.mul_coeff_zero Polynomial.mul_coeff_zero /-- `constantCoeff p` returns the constant term of the polynomial `p`, defined as `coeff p 0`. This is a ring homomorphism. -/ @[simps] def constantCoeff : R[X] →+* R where toFun p := coeff p 0 map_one' := coeff_one_zero map_mul' := mul_coeff_zero map_zero' := coeff_zero 0 map_add' p q := coeff_add p q 0 #align polynomial.constant_coeff Polynomial.constantCoeff #align polynomial.constant_coeff_apply Polynomial.constantCoeff_apply theorem isUnit_C {x : R} : IsUnit (C x) ↔ IsUnit x := ⟨fun h => (congr_arg IsUnit coeff_C_zero).mp (h.map <| @constantCoeff R _), fun h => h.map C⟩ #align polynomial.is_unit_C Polynomial.isUnit_C theorem coeff_mul_X_zero (p : R[X]) : coeff (p * X) 0 = 0 := by simp #align polynomial.coeff_mul_X_zero Polynomial.coeff_mul_X_zero theorem coeff_X_mul_zero (p : R[X]) : coeff (X * p) 0 = 0 := by simp #align polynomial.coeff_X_mul_zero Polynomial.coeff_X_mul_zero theorem coeff_C_mul_X_pow (x : R) (k n : ℕ) : coeff (C x * X ^ k : R[X]) n = if n = k then x else 0 := by rw [C_mul_X_pow_eq_monomial, coeff_monomial] congr 1 simp [eq_comm] #align polynomial.coeff_C_mul_X_pow Polynomial.coeff_C_mul_X_pow theorem coeff_C_mul_X (x : R) (n : ℕ) : coeff (C x * X : R[X]) n = if n = 1 then x else 0 := by rw [← pow_one X, coeff_C_mul_X_pow] #align polynomial.coeff_C_mul_X Polynomial.coeff_C_mul_X @[simp] theorem coeff_C_mul (p : R[X]) : coeff (C a * p) n = a * coeff p n := by rcases p with ⟨p⟩ simp_rw [← monomial_zero_left, ← ofFinsupp_single, ← ofFinsupp_mul, coeff] exact AddMonoidAlgebra.single_zero_mul_apply p a n #align polynomial.coeff_C_mul Polynomial.coeff_C_mul theorem C_mul' (a : R) (f : R[X]) : C a * f = a • f := by ext rw [coeff_C_mul, coeff_smul, smul_eq_mul] #align polynomial.C_mul' Polynomial.C_mul' @[simp] theorem coeff_mul_C (p : R[X]) (n : ℕ) (a : R) : coeff (p * C a) n = coeff p n * a := by rcases p with ⟨p⟩ simp_rw [← monomial_zero_left, ← ofFinsupp_single, ← ofFinsupp_mul, coeff] exact AddMonoidAlgebra.mul_single_zero_apply p a n #align polynomial.coeff_mul_C Polynomial.coeff_mul_C @[simp] lemma coeff_mul_natCast {a k : ℕ} : coeff (p * (a : R[X])) k = coeff p k * (↑a : R) := coeff_mul_C _ _ _ @[simp] lemma coeff_natCast_mul {a k : ℕ} : coeff ((a : R[X]) * p) k = a * coeff p k := coeff_C_mul _ -- See note [no_index around OfNat.ofNat] @[simp] lemma coeff_mul_ofNat {a k : ℕ} [Nat.AtLeastTwo a] : coeff (p * (no_index (OfNat.ofNat a) : R[X])) k = coeff p k * OfNat.ofNat a := coeff_mul_C _ _ _ -- See note [no_index around OfNat.ofNat] @[simp] lemma coeff_ofNat_mul {a k : ℕ} [Nat.AtLeastTwo a] : coeff ((no_index (OfNat.ofNat a) : R[X]) * p) k = OfNat.ofNat a * coeff p k := coeff_C_mul _ @[simp] lemma coeff_mul_intCast [Ring S] {p : S[X]} {a : ℤ} {k : ℕ} : coeff (p * (a : S[X])) k = coeff p k * (↑a : S) := coeff_mul_C _ _ _ @[simp] lemma coeff_intCast_mul [Ring S] {p : S[X]} {a : ℤ} {k : ℕ} : coeff ((a : S[X]) * p) k = a * coeff p k := coeff_C_mul _ @[simp] theorem coeff_X_pow (k n : ℕ) : coeff (X ^ k : R[X]) n = if n = k then 1 else 0 := by simp only [one_mul, RingHom.map_one, ← coeff_C_mul_X_pow] #align polynomial.coeff_X_pow Polynomial.coeff_X_pow theorem coeff_X_pow_self (n : ℕ) : coeff (X ^ n : R[X]) n = 1 := by simp #align polynomial.coeff_X_pow_self Polynomial.coeff_X_pow_self section Fewnomials open Finset theorem support_binomial {k m : ℕ} (hkm : k ≠ m) {x y : R} (hx : x ≠ 0) (hy : y ≠ 0) : support (C x * X ^ k + C y * X ^ m) = {k, m} := by apply subset_antisymm (support_binomial' k m x y) simp_rw [insert_subset_iff, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul, coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm, if_neg hkm.symm, mul_zero, zero_add, add_zero, Ne, hx, hy, not_false_eq_true, and_true] #align polynomial.support_binomial Polynomial.support_binomial theorem support_trinomial {k m n : ℕ} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : support (C x * X ^ k + C y * X ^ m + C z * X ^ n) = {k, m, n} := by apply subset_antisymm (support_trinomial' k m n x y z) simp_rw [insert_subset_iff, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul, coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm.ne, if_neg hkm.ne', if_neg hmn.ne, if_neg hmn.ne', if_neg (hkm.trans hmn).ne, if_neg (hkm.trans hmn).ne', mul_zero, add_zero, zero_add, Ne, hx, hy, hz, not_false_eq_true, and_true] #align polynomial.support_trinomial Polynomial.support_trinomial theorem card_support_binomial {k m : ℕ} (h : k ≠ m) {x y : R} (hx : x ≠ 0) (hy : y ≠ 0) : card (support (C x * X ^ k + C y * X ^ m)) = 2 := by rw [support_binomial h hx hy, card_insert_of_not_mem (mt mem_singleton.mp h), card_singleton] #align polynomial.card_support_binomial Polynomial.card_support_binomial theorem card_support_trinomial {k m n : ℕ} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : card (support (C x * X ^ k + C y * X ^ m + C z * X ^ n)) = 3 := by rw [support_trinomial hkm hmn hx hy hz, card_insert_of_not_mem (mt mem_insert.mp (not_or_of_not hkm.ne (mt mem_singleton.mp (hkm.trans hmn).ne))), card_insert_of_not_mem (mt mem_singleton.mp hmn.ne), card_singleton] #align polynomial.card_support_trinomial Polynomial.card_support_trinomial end Fewnomials @[simp] theorem coeff_mul_X_pow (p : R[X]) (n d : ℕ) : coeff (p * Polynomial.X ^ n) (d + n) = coeff p d := by rw [coeff_mul, Finset.sum_eq_single (d, n), coeff_X_pow, if_pos rfl, mul_one] · rintro ⟨i, j⟩ h1 h2 rw [coeff_X_pow, if_neg, mul_zero] rintro rfl apply h2 rw [mem_antidiagonal, add_right_cancel_iff] at h1 subst h1 rfl · exact fun h1 => (h1 (mem_antidiagonal.2 rfl)).elim #align polynomial.coeff_mul_X_pow Polynomial.coeff_mul_X_pow @[simp] theorem coeff_X_pow_mul (p : R[X]) (n d : ℕ) : coeff (Polynomial.X ^ n * p) (d + n) = coeff p d := by rw [(commute_X_pow p n).eq, coeff_mul_X_pow] #align polynomial.coeff_X_pow_mul Polynomial.coeff_X_pow_mul theorem coeff_mul_X_pow' (p : R[X]) (n d : ℕ) : (p * X ^ n).coeff d = ite (n ≤ d) (p.coeff (d - n)) 0 := by split_ifs with h · rw [← tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right] · refine (coeff_mul _ _ _).trans (Finset.sum_eq_zero fun x hx => ?_) rw [coeff_X_pow, if_neg, mul_zero] exact ((le_of_add_le_right (mem_antidiagonal.mp hx).le).trans_lt <| not_le.mp h).ne #align polynomial.coeff_mul_X_pow' Polynomial.coeff_mul_X_pow' theorem coeff_X_pow_mul' (p : R[X]) (n d : ℕ) : (X ^ n * p).coeff d = ite (n ≤ d) (p.coeff (d - n)) 0 := by rw [(commute_X_pow p n).eq, coeff_mul_X_pow'] #align polynomial.coeff_X_pow_mul' Polynomial.coeff_X_pow_mul' @[simp] theorem coeff_mul_X (p : R[X]) (n : ℕ) : coeff (p * X) (n + 1) = coeff p n := by simpa only [pow_one] using coeff_mul_X_pow p 1 n #align polynomial.coeff_mul_X Polynomial.coeff_mul_X @[simp] theorem coeff_X_mul (p : R[X]) (n : ℕ) : coeff (X * p) (n + 1) = coeff p n := by rw [(commute_X p).eq, coeff_mul_X] #align polynomial.coeff_X_mul Polynomial.coeff_X_mul theorem coeff_mul_monomial (p : R[X]) (n d : ℕ) (r : R) : coeff (p * monomial n r) (d + n) = coeff p d * r := by rw [← C_mul_X_pow_eq_monomial, ← X_pow_mul, ← mul_assoc, coeff_mul_C, coeff_mul_X_pow] #align polynomial.coeff_mul_monomial Polynomial.coeff_mul_monomial theorem coeff_monomial_mul (p : R[X]) (n d : ℕ) (r : R) : coeff (monomial n r * p) (d + n) = r * coeff p d := by rw [← C_mul_X_pow_eq_monomial, mul_assoc, coeff_C_mul, X_pow_mul, coeff_mul_X_pow] #align polynomial.coeff_monomial_mul Polynomial.coeff_monomial_mul -- This can already be proved by `simp`. theorem coeff_mul_monomial_zero (p : R[X]) (d : ℕ) (r : R) : coeff (p * monomial 0 r) d = coeff p d * r := coeff_mul_monomial p 0 d r #align polynomial.coeff_mul_monomial_zero Polynomial.coeff_mul_monomial_zero -- This can already be proved by `simp`. theorem coeff_monomial_zero_mul (p : R[X]) (d : ℕ) (r : R) : coeff (monomial 0 r * p) d = r * coeff p d := coeff_monomial_mul p 0 d r #align polynomial.coeff_monomial_zero_mul Polynomial.coeff_monomial_zero_mul theorem mul_X_pow_eq_zero {p : R[X]} {n : ℕ} (H : p * X ^ n = 0) : p = 0 := ext fun k => (coeff_mul_X_pow p n k).symm.trans <| ext_iff.1 H (k + n) #align polynomial.mul_X_pow_eq_zero Polynomial.mul_X_pow_eq_zero theorem isRegular_X_pow (n : ℕ) : IsRegular (X ^ n : R[X]) := by suffices IsLeftRegular (X^n : R[X]) from ⟨this, this.right_of_commute (fun p => commute_X_pow p n)⟩ intro P Q (hPQ : X^n * P = X^n * Q) ext i rw [← coeff_X_pow_mul P n i, hPQ, coeff_X_pow_mul Q n i] @[simp] theorem isRegular_X : IsRegular (X : R[X]) := pow_one (X : R[X]) ▸ isRegular_X_pow 1 theorem coeff_X_add_C_pow (r : R) (n k : ℕ) : ((X + C r) ^ n).coeff k = r ^ (n - k) * (n.choose k : R) := by rw [(commute_X (C r : R[X])).add_pow, ← lcoeff_apply, map_sum] simp only [one_pow, mul_one, lcoeff_apply, ← C_eq_natCast, ← C_pow, coeff_mul_C, Nat.cast_id] rw [Finset.sum_eq_single k, coeff_X_pow_self, one_mul] · intro _ _ h simp [coeff_X_pow, h.symm] · simp only [coeff_X_pow_self, one_mul, not_lt, Finset.mem_range] intro h rw [Nat.choose_eq_zero_of_lt h, Nat.cast_zero, mul_zero] #align polynomial.coeff_X_add_C_pow Polynomial.coeff_X_add_C_pow theorem coeff_X_add_one_pow (R : Type*) [Semiring R] (n k : ℕ) : ((X + 1) ^ n).coeff k = (n.choose k : R) := by rw [← C_1, coeff_X_add_C_pow, one_pow, one_mul] #align polynomial.coeff_X_add_one_pow Polynomial.coeff_X_add_one_pow theorem coeff_one_add_X_pow (R : Type*) [Semiring R] (n k : ℕ) : ((1 + X) ^ n).coeff k = (n.choose k : R) := by rw [add_comm _ X, coeff_X_add_one_pow] #align polynomial.coeff_one_add_X_pow Polynomial.coeff_one_add_X_pow theorem C_dvd_iff_dvd_coeff (r : R) (φ : R[X]) : C r ∣ φ ↔ ∀ i, r ∣ φ.coeff i := by constructor · rintro ⟨φ, rfl⟩ c rw [coeff_C_mul] apply dvd_mul_right · intro h choose c hc using h classical let c' : ℕ → R := fun i => if i ∈ φ.support then c i else 0 let ψ : R[X] := ∑ i ∈ φ.support, monomial i (c' i) use ψ ext i simp only [c', ψ, coeff_C_mul, mem_support_iff, coeff_monomial, finset_sum_coeff, Finset.sum_ite_eq'] split_ifs with hi · rw [hc] · rw [Classical.not_not] at hi rwa [mul_zero] #align polynomial.C_dvd_iff_dvd_coeff Polynomial.C_dvd_iff_dvd_coeff set_option linter.deprecated false in theorem coeff_bit0_mul (P Q : R[X]) (n : ℕ) : coeff (bit0 P * Q) n = 2 * coeff (P * Q) n := by -- Porting note: `two_mul` is required. simp [bit0, add_mul, two_mul] #align polynomial.coeff_bit0_mul Polynomial.coeff_bit0_mul set_option linter.deprecated false in theorem coeff_bit1_mul (P Q : R[X]) (n : ℕ) : coeff (bit1 P * Q) n = 2 * coeff (P * Q) n + coeff Q n := by simp [bit1, add_mul, coeff_bit0_mul] #align polynomial.coeff_bit1_mul Polynomial.coeff_bit1_mul theorem smul_eq_C_mul (a : R) : a • p = C a * p := by simp [ext_iff] #align polynomial.smul_eq_C_mul Polynomial.smul_eq_C_mul theorem update_eq_add_sub_coeff {R : Type*} [Ring R] (p : R[X]) (n : ℕ) (a : R) : p.update n a = p + Polynomial.C (a - p.coeff n) * Polynomial.X ^ n := by ext rw [coeff_update_apply, coeff_add, coeff_C_mul_X_pow] split_ifs with h <;> simp [h] #align polynomial.update_eq_add_sub_coeff Polynomial.update_eq_add_sub_coeff end Coeff section cast theorem natCast_coeff_zero {n : ℕ} {R : Type*} [Semiring R] : (n : R[X]).coeff 0 = n := by simp only [coeff_natCast_ite, ite_true] #align polynomial.nat_cast_coeff_zero Polynomial.natCast_coeff_zero @[deprecated (since := "2024-04-17")] alias nat_cast_coeff_zero := natCast_coeff_zero @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this
Mathlib/Algebra/Polynomial/Coeff.lean
411
418
theorem natCast_inj {m n : ℕ} {R : Type*} [Semiring R] [CharZero R] : (↑m : R[X]) = ↑n ↔ m = n := by
constructor · intro h apply_fun fun p => p.coeff 0 at h simpa using h · rintro rfl rfl
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen, Scott Morrison, Chris Hughes, Anne Baanen -/ import Mathlib.LinearAlgebra.Dimension.Free import Mathlib.Algebra.Module.Torsion #align_import linear_algebra.dimension from "leanprover-community/mathlib"@"47a5f8186becdbc826190ced4312f8199f9db6a5" /-! # Rank of various constructions ## Main statements - `rank_quotient_add_rank_le` : `rank M/N + rank N ≤ rank M`. - `lift_rank_add_lift_rank_le_rank_prod`: `rank M × N ≤ rank M + rank N`. - `rank_span_le_of_finite`: `rank (span s) ≤ #s` for finite `s`. For free modules, we have - `rank_prod` : `rank M × N = rank M + rank N`. - `rank_finsupp` : `rank (ι →₀ M) = #ι * rank M` - `rank_directSum`: `rank (⨁ Mᵢ) = ∑ rank Mᵢ` - `rank_tensorProduct`: `rank (M ⊗ N) = rank M * rank N`. Lemmas for ranks of submodules and subalgebras are also provided. We have finrank variants for most lemmas as well. -/ noncomputable section universe u v v' u₁' w w' variable {R S : Type u} {M : Type v} {M' : Type v'} {M₁ : Type v} variable {ι : Type w} {ι' : Type w'} {η : Type u₁'} {φ : η → Type*} open Cardinal Basis Submodule Function Set FiniteDimensional DirectSum variable [Ring R] [CommRing S] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁] variable [Module R M] [Module R M'] [Module R M₁] section Quotient theorem LinearIndependent.sum_elim_of_quotient {M' : Submodule R M} {ι₁ ι₂} {f : ι₁ → M'} (hf : LinearIndependent R f) (g : ι₂ → M) (hg : LinearIndependent R (Submodule.Quotient.mk (p := M') ∘ g)) : LinearIndependent R (Sum.elim (f · : ι₁ → M) g) := by refine .sum_type (hf.map' M'.subtype M'.ker_subtype) (.of_comp M'.mkQ hg) ?_ refine disjoint_def.mpr fun x h₁ h₂ ↦ ?_ have : x ∈ M' := span_le.mpr (Set.range_subset_iff.mpr fun i ↦ (f i).prop) h₁ obtain ⟨c, rfl⟩ := Finsupp.mem_span_range_iff_exists_finsupp.mp h₂ simp_rw [← Quotient.mk_eq_zero, ← mkQ_apply, map_finsupp_sum, map_smul, mkQ_apply] at this rw [linearIndependent_iff.mp hg _ this, Finsupp.sum_zero_index] theorem LinearIndependent.union_of_quotient {M' : Submodule R M} {s : Set M} (hs : s ⊆ M') (hs' : LinearIndependent (ι := s) R Subtype.val) {t : Set M} (ht : LinearIndependent (ι := t) R (Submodule.Quotient.mk (p := M') ∘ Subtype.val)) : LinearIndependent (ι := (s ∪ t : _)) R Subtype.val := by refine (LinearIndependent.sum_elim_of_quotient (f := Set.embeddingOfSubset s M' hs) (of_comp M'.subtype (by simpa using hs')) Subtype.val ht).to_subtype_range' ?_ simp only [embeddingOfSubset_apply_coe, Sum.elim_range, Subtype.range_val] theorem rank_quotient_add_rank_le [Nontrivial R] (M' : Submodule R M) : Module.rank R (M ⧸ M') + Module.rank R M' ≤ Module.rank R M := by conv_lhs => simp only [Module.rank_def] have := nonempty_linearIndependent_set R (M ⧸ M') have := nonempty_linearIndependent_set R M' rw [Cardinal.ciSup_add_ciSup _ (bddAbove_range.{v, v} _) _ (bddAbove_range.{v, v} _)] refine ciSup_le fun ⟨s, hs⟩ ↦ ciSup_le fun ⟨t, ht⟩ ↦ ?_ choose f hf using Quotient.mk_surjective M' simpa [add_comm] using (LinearIndependent.sum_elim_of_quotient ht (fun (i : s) ↦ f i) (by simpa [Function.comp, hf] using hs)).cardinal_le_rank theorem rank_quotient_le (p : Submodule R M) : Module.rank R (M ⧸ p) ≤ Module.rank R M := (mkQ p).rank_le_of_surjective (surjective_quot_mk _) #align rank_quotient_le rank_quotient_le theorem rank_quotient_eq_of_le_torsion {R M} [CommRing R] [AddCommGroup M] [Module R M] {M' : Submodule R M} (hN : M' ≤ torsion R M) : Module.rank R (M ⧸ M') = Module.rank R M := (rank_quotient_le M').antisymm <| by nontriviality R rw [Module.rank] have := nonempty_linearIndependent_set R M refine ciSup_le fun ⟨s, hs⟩ ↦ LinearIndependent.cardinal_le_rank (v := (M'.mkQ ·)) ?_ rw [linearIndependent_iff'] at hs ⊢ simp_rw [← map_smul, ← map_sum, mkQ_apply, Quotient.mk_eq_zero] intro t g hg i hi obtain ⟨r, hg⟩ := hN hg simp_rw [Finset.smul_sum, Submonoid.smul_def, smul_smul] at hg exact r.prop _ (mul_comm (g i) r ▸ hs t _ hg i hi) end Quotient section ULift @[simp] theorem rank_ulift : Module.rank R (ULift.{w} M) = Cardinal.lift.{w} (Module.rank R M) := Cardinal.lift_injective.{v} <| Eq.symm <| (lift_lift _).trans ULift.moduleEquiv.symm.lift_rank_eq @[simp] theorem finrank_ulift : finrank R (ULift M) = finrank R M := by simp_rw [finrank, rank_ulift, toNat_lift] end ULift section Prod variable (R M M') open LinearMap in theorem lift_rank_add_lift_rank_le_rank_prod [Nontrivial R] : lift.{v'} (Module.rank R M) + lift.{v} (Module.rank R M') ≤ Module.rank R (M × M') := by convert rank_quotient_add_rank_le (ker <| LinearMap.fst R M M') · refine Eq.trans ?_ (lift_id'.{v, v'} _) rw [(quotKerEquivRange _).lift_rank_eq, rank_range_of_surjective _ fst_surjective, lift_umax.{v, v'}] · refine Eq.trans ?_ (lift_id'.{v', v} _) rw [ker_fst, ← (LinearEquiv.ofInjective _ <| inr_injective (M := M) (M₂ := M')).lift_rank_eq, lift_umax.{v', v}] theorem rank_add_rank_le_rank_prod [Nontrivial R] : Module.rank R M + Module.rank R M₁ ≤ Module.rank R (M × M₁) := by convert ← lift_rank_add_lift_rank_le_rank_prod R M M₁ <;> apply lift_id variable {R M M'} variable [StrongRankCondition R] [Module.Free R M] [Module.Free R M'] [Module.Free R M₁] open Module.Free /-- If `M` and `M'` are free, then the rank of `M × M'` is `(Module.rank R M).lift + (Module.rank R M').lift`. -/ @[simp] theorem rank_prod : Module.rank R (M × M') = Cardinal.lift.{v'} (Module.rank R M) + Cardinal.lift.{v, v'} (Module.rank R M') := by simpa [rank_eq_card_chooseBasisIndex R M, rank_eq_card_chooseBasisIndex R M', lift_umax, lift_umax'] using ((chooseBasis R M).prod (chooseBasis R M')).mk_eq_rank.symm #align rank_prod rank_prod /-- If `M` and `M'` are free (and lie in the same universe), the rank of `M × M'` is `(Module.rank R M) + (Module.rank R M')`. -/ theorem rank_prod' : Module.rank R (M × M₁) = Module.rank R M + Module.rank R M₁ := by simp #align rank_prod' rank_prod' /-- The finrank of `M × M'` is `(finrank R M) + (finrank R M')`. -/ @[simp] theorem FiniteDimensional.finrank_prod [Module.Finite R M] [Module.Finite R M'] : finrank R (M × M') = finrank R M + finrank R M' := by simp [finrank, rank_lt_aleph0 R M, rank_lt_aleph0 R M'] #align finite_dimensional.finrank_prod FiniteDimensional.finrank_prod end Prod section Finsupp variable (R M M') variable [StrongRankCondition R] [Module.Free R M] [Module.Free R M'] open Module.Free @[simp] theorem rank_finsupp (ι : Type w) : Module.rank R (ι →₀ M) = Cardinal.lift.{v} #ι * Cardinal.lift.{w} (Module.rank R M) := by obtain ⟨⟨_, bs⟩⟩ := Module.Free.exists_basis (R := R) (M := M) rw [← bs.mk_eq_rank'', ← (Finsupp.basis fun _ : ι => bs).mk_eq_rank'', Cardinal.mk_sigma, Cardinal.sum_const] #align rank_finsupp rank_finsupp theorem rank_finsupp' (ι : Type v) : Module.rank R (ι →₀ M) = #ι * Module.rank R M := by simp [rank_finsupp] #align rank_finsupp' rank_finsupp' /-- The rank of `(ι →₀ R)` is `(#ι).lift`. -/ -- Porting note, this should not be `@[simp]`, as simp can prove it. -- @[simp] theorem rank_finsupp_self (ι : Type w) : Module.rank R (ι →₀ R) = Cardinal.lift.{u} #ι := by simp [rank_finsupp] #align rank_finsupp_self rank_finsupp_self /-- If `R` and `ι` lie in the same universe, the rank of `(ι →₀ R)` is `# ι`. -/ theorem rank_finsupp_self' {ι : Type u} : Module.rank R (ι →₀ R) = #ι := by simp #align rank_finsupp_self' rank_finsupp_self' /-- The rank of the direct sum is the sum of the ranks. -/ @[simp] theorem rank_directSum {ι : Type v} (M : ι → Type w) [∀ i : ι, AddCommGroup (M i)] [∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] : Module.rank R (⨁ i, M i) = Cardinal.sum fun i => Module.rank R (M i) := by let B i := chooseBasis R (M i) let b : Basis _ R (⨁ i, M i) := DFinsupp.basis fun i => B i simp [← b.mk_eq_rank'', fun i => (B i).mk_eq_rank''] #align rank_direct_sum rank_directSum /-- If `m` and `n` are `Fintype`, the rank of `m × n` matrices is `(#m).lift * (#n).lift`. -/ @[simp] theorem rank_matrix (m : Type v) (n : Type w) [Finite m] [Finite n] : Module.rank R (Matrix m n R) = Cardinal.lift.{max v w u, v} #m * Cardinal.lift.{max v w u, w} #n := by cases nonempty_fintype m cases nonempty_fintype n have h := (Matrix.stdBasis R m n).mk_eq_rank rw [← lift_lift.{max v w u, max v w}, lift_inj] at h simpa using h.symm #align rank_matrix rank_matrix /-- If `m` and `n` are `Fintype` that lie in the same universe, the rank of `m × n` matrices is `(#n * #m).lift`. -/ @[simp high] theorem rank_matrix' (m n : Type v) [Finite m] [Finite n] : Module.rank R (Matrix m n R) = Cardinal.lift.{u} (#m * #n) := by rw [rank_matrix, lift_mul, lift_umax.{v, u}] #align rank_matrix' rank_matrix' /-- If `m` and `n` are `Fintype` that lie in the same universe as `R`, the rank of `m × n` matrices is `# m * # n`. -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem rank_matrix'' (m n : Type u) [Finite m] [Finite n] : Module.rank R (Matrix m n R) = #m * #n := by simp #align rank_matrix'' rank_matrix'' variable [Module.Finite R M] [Module.Finite R M'] open Fintype namespace FiniteDimensional @[simp] theorem finrank_finsupp {ι : Type v} [Fintype ι] : finrank R (ι →₀ M) = card ι * finrank R M := by rw [finrank, finrank, rank_finsupp, ← mk_toNat_eq_card, toNat_mul, toNat_lift, toNat_lift] /-- The finrank of `(ι →₀ R)` is `Fintype.card ι`. -/ @[simp] theorem finrank_finsupp_self {ι : Type v} [Fintype ι] : finrank R (ι →₀ R) = card ι := by rw [finrank, rank_finsupp_self, ← mk_toNat_eq_card, toNat_lift] #align finite_dimensional.finrank_finsupp FiniteDimensional.finrank_finsupp_self /-- The finrank of the direct sum is the sum of the finranks. -/ @[simp] theorem finrank_directSum {ι : Type v} [Fintype ι] (M : ι → Type w) [∀ i : ι, AddCommGroup (M i)] [∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] [∀ i : ι, Module.Finite R (M i)] : finrank R (⨁ i, M i) = ∑ i, finrank R (M i) := by letI := nontrivial_of_invariantBasisNumber R simp only [finrank, fun i => rank_eq_card_chooseBasisIndex R (M i), rank_directSum, ← mk_sigma, mk_toNat_eq_card, card_sigma] #align finite_dimensional.finrank_direct_sum FiniteDimensional.finrank_directSum /-- If `m` and `n` are `Fintype`, the finrank of `m × n` matrices is `(Fintype.card m) * (Fintype.card n)`. -/ theorem finrank_matrix (m n : Type*) [Fintype m] [Fintype n] : finrank R (Matrix m n R) = card m * card n := by simp [finrank] #align finite_dimensional.finrank_matrix FiniteDimensional.finrank_matrix end FiniteDimensional end Finsupp section Pi variable [StrongRankCondition R] [Module.Free R M] variable [∀ i, AddCommGroup (φ i)] [∀ i, Module R (φ i)] [∀ i, Module.Free R (φ i)] open Module.Free open LinearMap /-- The rank of a finite product of free modules is the sum of the ranks. -/ -- this result is not true without the freeness assumption @[simp] theorem rank_pi [Finite η] : Module.rank R (∀ i, φ i) = Cardinal.sum fun i => Module.rank R (φ i) := by cases nonempty_fintype η let B i := chooseBasis R (φ i) let b : Basis _ R (∀ i, φ i) := Pi.basis fun i => B i simp [← b.mk_eq_rank'', fun i => (B i).mk_eq_rank''] #align rank_pi rank_pi variable (R) /-- The finrank of `(ι → R)` is `Fintype.card ι`. -/ theorem FiniteDimensional.finrank_pi {ι : Type v} [Fintype ι] : finrank R (ι → R) = Fintype.card ι := by simp [finrank] #align finite_dimensional.finrank_pi FiniteDimensional.finrank_pi --TODO: this should follow from `LinearEquiv.finrank_eq`, that is over a field. /-- The finrank of a finite product is the sum of the finranks. -/ theorem FiniteDimensional.finrank_pi_fintype {ι : Type v} [Fintype ι] {M : ι → Type w} [∀ i : ι, AddCommGroup (M i)] [∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] [∀ i : ι, Module.Finite R (M i)] : finrank R (∀ i, M i) = ∑ i, finrank R (M i) := by letI := nontrivial_of_invariantBasisNumber R simp only [finrank, fun i => rank_eq_card_chooseBasisIndex R (M i), rank_pi, ← mk_sigma, mk_toNat_eq_card, Fintype.card_sigma] #align finite_dimensional.finrank_pi_fintype FiniteDimensional.finrank_pi_fintype variable {R} variable [Fintype η] theorem rank_fun {M η : Type u} [Fintype η] [AddCommGroup M] [Module R M] [Module.Free R M] : Module.rank R (η → M) = Fintype.card η * Module.rank R M := by rw [rank_pi, Cardinal.sum_const', Cardinal.mk_fintype] #align rank_fun rank_fun theorem rank_fun_eq_lift_mul : Module.rank R (η → M) = (Fintype.card η : Cardinal.{max u₁' v}) * Cardinal.lift.{u₁'} (Module.rank R M) := by rw [rank_pi, Cardinal.sum_const, Cardinal.mk_fintype, Cardinal.lift_natCast] #align rank_fun_eq_lift_mul rank_fun_eq_lift_mul theorem rank_fun' : Module.rank R (η → R) = Fintype.card η := by rw [rank_fun_eq_lift_mul, rank_self, Cardinal.lift_one, mul_one] #align rank_fun' rank_fun' theorem rank_fin_fun (n : ℕ) : Module.rank R (Fin n → R) = n := by simp [rank_fun'] #align rank_fin_fun rank_fin_fun variable (R) /-- The vector space of functions on a `Fintype ι` has finrank equal to the cardinality of `ι`. -/ @[simp] theorem FiniteDimensional.finrank_fintype_fun_eq_card : finrank R (η → R) = Fintype.card η := finrank_eq_of_rank_eq rank_fun' #align finite_dimensional.finrank_fintype_fun_eq_card FiniteDimensional.finrank_fintype_fun_eq_card /-- The vector space of functions on `Fin n` has finrank equal to `n`. -/ -- @[simp] -- Porting note (#10618): simp already proves this theorem FiniteDimensional.finrank_fin_fun {n : ℕ} : finrank R (Fin n → R) = n := by simp #align finite_dimensional.finrank_fin_fun FiniteDimensional.finrank_fin_fun variable {R} -- TODO: merge with the `Finrank` content /-- An `n`-dimensional `R`-vector space is equivalent to `Fin n → R`. -/ def finDimVectorspaceEquiv (n : ℕ) (hn : Module.rank R M = n) : M ≃ₗ[R] Fin n → R := by haveI := nontrivial_of_invariantBasisNumber R have : Cardinal.lift.{u} (n : Cardinal.{v}) = Cardinal.lift.{v} (n : Cardinal.{u}) := by simp have hn := Cardinal.lift_inj.{v, u}.2 hn rw [this] at hn rw [← @rank_fin_fun R _ _ n] at hn haveI : Module.Free R (Fin n → R) := Module.Free.pi _ _ exact Classical.choice (nonempty_linearEquiv_of_lift_rank_eq hn) #align fin_dim_vectorspace_equiv finDimVectorspaceEquiv end Pi section TensorProduct open TensorProduct variable [StrongRankCondition S] variable [Module S M] [Module.Free S M] [Module S M'] [Module.Free S M'] variable [Module S M₁] [Module.Free S M₁] open Module.Free /-- The rank of `M ⊗[R] M'` is `(Module.rank R M).lift * (Module.rank R M').lift`. -/ @[simp] theorem rank_tensorProduct : Module.rank S (M ⊗[S] M') = Cardinal.lift.{v'} (Module.rank S M) * Cardinal.lift.{v} (Module.rank S M') := by obtain ⟨⟨_, bM⟩⟩ := Module.Free.exists_basis (R := S) (M := M) obtain ⟨⟨_, bN⟩⟩ := Module.Free.exists_basis (R := S) (M := M') rw [← bM.mk_eq_rank'', ← bN.mk_eq_rank'', ← (bM.tensorProduct bN).mk_eq_rank'', Cardinal.mk_prod] #align rank_tensor_product rank_tensorProduct /-- If `M` and `M'` lie in the same universe, the rank of `M ⊗[R] M'` is `(Module.rank R M) * (Module.rank R M')`. -/ theorem rank_tensorProduct' : Module.rank S (M ⊗[S] M₁) = Module.rank S M * Module.rank S M₁ := by simp #align rank_tensor_product' rank_tensorProduct' /-- The finrank of `M ⊗[R] M'` is `(finrank R M) * (finrank R M')`. -/ @[simp] theorem FiniteDimensional.finrank_tensorProduct : finrank S (M ⊗[S] M') = finrank S M * finrank S M' := by simp [finrank] #align finite_dimensional.finrank_tensor_product FiniteDimensional.finrank_tensorProduct end TensorProduct section SubmoduleRank section open FiniteDimensional namespace Submodule theorem lt_of_le_of_finrank_lt_finrank {s t : Submodule R M} (le : s ≤ t) (lt : finrank R s < finrank R t) : s < t := lt_of_le_of_ne le fun h => ne_of_lt lt (by rw [h]) #align submodule.lt_of_le_of_finrank_lt_finrank Submodule.lt_of_le_of_finrank_lt_finrank theorem lt_top_of_finrank_lt_finrank {s : Submodule R M} (lt : finrank R s < finrank R M) : s < ⊤ := by rw [← finrank_top R M] at lt exact lt_of_le_of_finrank_lt_finrank le_top lt #align submodule.lt_top_of_finrank_lt_finrank Submodule.lt_top_of_finrank_lt_finrank end Submodule variable [StrongRankCondition R] /-- The dimension of a submodule is bounded by the dimension of the ambient space. -/ theorem Submodule.finrank_le [Module.Finite R M] (s : Submodule R M) : finrank R s ≤ finrank R M := toNat_le_toNat (rank_submodule_le s) (rank_lt_aleph0 _ _) #align submodule.finrank_le Submodule.finrank_le /-- The dimension of a quotient is bounded by the dimension of the ambient space. -/ theorem Submodule.finrank_quotient_le [Module.Finite R M] (s : Submodule R M) : finrank R (M ⧸ s) ≤ finrank R M := toNat_le_toNat ((Submodule.mkQ s).rank_le_of_surjective (surjective_quot_mk _)) (rank_lt_aleph0 _ _) #align submodule.finrank_quotient_le Submodule.finrank_quotient_le /-- Pushforwards of finite submodules have a smaller finrank. -/ theorem Submodule.finrank_map_le (f : M →ₗ[R] M') (p : Submodule R M) [Module.Finite R p] : finrank R (p.map f) ≤ finrank R p := finrank_le_finrank_of_rank_le_rank (lift_rank_map_le _ _) (rank_lt_aleph0 _ _) #align submodule.finrank_map_le Submodule.finrank_map_le theorem Submodule.finrank_le_finrank_of_le {s t : Submodule R M} [Module.Finite R t] (hst : s ≤ t) : finrank R s ≤ finrank R t := calc finrank R s = finrank R (s.comap t.subtype) := (Submodule.comapSubtypeEquivOfLe hst).finrank_eq.symm _ ≤ finrank R t := Submodule.finrank_le _ #align submodule.finrank_le_finrank_of_le Submodule.finrank_le_finrank_of_le end end SubmoduleRank section Span variable [StrongRankCondition R] theorem rank_span_le (s : Set M) : Module.rank R (span R s) ≤ #s := by rw [Finsupp.span_eq_range_total, ← lift_strictMono.le_iff_le] refine (lift_rank_range_le _).trans ?_ rw [rank_finsupp_self] simp only [lift_lift, ge_iff_le, le_refl] #align rank_span_le rank_span_le theorem rank_span_finset_le (s : Finset M) : Module.rank R (span R (s : Set M)) ≤ s.card := by simpa using rank_span_le s.toSet theorem rank_span_of_finset (s : Finset M) : Module.rank R (span R (s : Set M)) < ℵ₀ := (rank_span_finset_le s).trans_lt (Cardinal.nat_lt_aleph0 _) #align rank_span_of_finset rank_span_of_finset open Submodule FiniteDimensional variable (R) /-- The rank of a set of vectors as a natural number. -/ protected noncomputable def Set.finrank (s : Set M) : ℕ := finrank R (span R s) #align set.finrank Set.finrank variable {R} theorem finrank_span_le_card (s : Set M) [Fintype s] : finrank R (span R s) ≤ s.toFinset.card := finrank_le_of_rank_le (by simpa using rank_span_le (R := R) s) #align finrank_span_le_card finrank_span_le_card
Mathlib/LinearAlgebra/Dimension/Constructions.lean
468
471
theorem finrank_span_finset_le_card (s : Finset M) : (s : Set M).finrank R ≤ s.card := calc (s : Set M).finrank R ≤ (s : Set M).toFinset.card := finrank_span_le_card (M := M) s _ = s.card := by
simp
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Degree.Definitions import Mathlib.Algebra.Polynomial.Induction #align_import data.polynomial.eval from "leanprover-community/mathlib"@"728baa2f54e6062c5879a3e397ac6bac323e506f" /-! # Theory of univariate polynomials The main defs here are `eval₂`, `eval`, and `map`. We give several lemmas about their interaction with each other and with module operations. -/ set_option linter.uppercaseLean3 false noncomputable section open Finset AddMonoidAlgebra open Polynomial namespace Polynomial universe u v w y variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} section variable [Semiring S] variable (f : R →+* S) (x : S) /-- Evaluate a polynomial `p` given a ring hom `f` from the scalar ring to the target and a value `x` for the variable in the target -/ irreducible_def eval₂ (p : R[X]) : S := p.sum fun e a => f a * x ^ e #align polynomial.eval₂ Polynomial.eval₂ theorem eval₂_eq_sum {f : R →+* S} {x : S} : p.eval₂ f x = p.sum fun e a => f a * x ^ e := by rw [eval₂_def] #align polynomial.eval₂_eq_sum Polynomial.eval₂_eq_sum theorem eval₂_congr {R S : Type*} [Semiring R] [Semiring S] {f g : R →+* S} {s t : S} {φ ψ : R[X]} : f = g → s = t → φ = ψ → eval₂ f s φ = eval₂ g t ψ := by rintro rfl rfl rfl; rfl #align polynomial.eval₂_congr Polynomial.eval₂_congr @[simp] theorem eval₂_at_zero : p.eval₂ f 0 = f (coeff p 0) := by simp (config := { contextual := true }) only [eval₂_eq_sum, zero_pow_eq, mul_ite, mul_zero, mul_one, sum, Classical.not_not, mem_support_iff, sum_ite_eq', ite_eq_left_iff, RingHom.map_zero, imp_true_iff, eq_self_iff_true] #align polynomial.eval₂_at_zero Polynomial.eval₂_at_zero @[simp] theorem eval₂_zero : (0 : R[X]).eval₂ f x = 0 := by simp [eval₂_eq_sum] #align polynomial.eval₂_zero Polynomial.eval₂_zero @[simp] theorem eval₂_C : (C a).eval₂ f x = f a := by simp [eval₂_eq_sum] #align polynomial.eval₂_C Polynomial.eval₂_C @[simp]
Mathlib/Algebra/Polynomial/Eval.lean
73
73
theorem eval₂_X : X.eval₂ f x = x := by
simp [eval₂_eq_sum]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir -/ import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Data.Complex.Abs import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Nat.Choose.Sum #align_import data.complex.exponential from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Exponential, trigonometric and hyperbolic trigonometric functions This file contains the definitions of the real and complex exponential, sine, cosine, tangent, hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions. -/ open CauSeq Finset IsAbsoluteValue open scoped Classical ComplexConjugate namespace Complex theorem isCauSeq_abs_exp (z : ℂ) : IsCauSeq _root_.abs fun n => ∑ m ∈ range n, abs (z ^ m / m.factorial) := let ⟨n, hn⟩ := exists_nat_gt (abs z) have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (abs.nonneg _) hn IsCauSeq.series_ratio_test n (abs z / n) (div_nonneg (abs.nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff hn0, one_mul]) fun m hm => by rw [abs_abs, abs_abs, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, map_mul, map_div₀, abs_natCast] gcongr exact le_trans hm (Nat.le_succ _) #align complex.is_cau_abs_exp Complex.isCauSeq_abs_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_abs_exp z).of_abv #align complex.is_cau_exp Complex.isCauSeq_exp /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ -- Porting note (#11180): removed `@[pp_nodot]` def exp' (z : ℂ) : CauSeq ℂ Complex.abs := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ #align complex.exp' Complex.exp' /-- The complex exponential function, defined via its Taylor series -/ -- Porting note (#11180): removed `@[pp_nodot]` -- Porting note: removed `irreducible` attribute, so I can prove things def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) #align complex.exp Complex.exp /-- The complex sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sin (z : ℂ) : ℂ := (exp (-z * I) - exp (z * I)) * I / 2 #align complex.sin Complex.sin /-- The complex cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cos (z : ℂ) : ℂ := (exp (z * I) + exp (-z * I)) / 2 #align complex.cos Complex.cos /-- The complex tangent function, defined as `sin z / cos z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tan (z : ℂ) : ℂ := sin z / cos z #align complex.tan Complex.tan /-- The complex cotangent function, defined as `cos z / sin z` -/ def cot (z : ℂ) : ℂ := cos z / sin z /-- The complex hyperbolic sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sinh (z : ℂ) : ℂ := (exp z - exp (-z)) / 2 #align complex.sinh Complex.sinh /-- The complex hyperbolic cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cosh (z : ℂ) : ℂ := (exp z + exp (-z)) / 2 #align complex.cosh Complex.cosh /-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tanh (z : ℂ) : ℂ := sinh z / cosh z #align complex.tanh Complex.tanh /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def exp (x : ℝ) : ℝ := (exp x).re #align real.exp Real.exp /-- The real sine function, defined as the real part of the complex sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sin (x : ℝ) : ℝ := (sin x).re #align real.sin Real.sin /-- The real cosine function, defined as the real part of the complex cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cos (x : ℝ) : ℝ := (cos x).re #align real.cos Real.cos /-- The real tangent function, defined as the real part of the complex tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tan (x : ℝ) : ℝ := (tan x).re #align real.tan Real.tan /-- The real cotangent function, defined as the real part of the complex cotangent -/ nonrec def cot (x : ℝ) : ℝ := (cot x).re /-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sinh (x : ℝ) : ℝ := (sinh x).re #align real.sinh Real.sinh /-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cosh (x : ℝ) : ℝ := (cosh x).re #align real.cosh Real.cosh /-- The real hypebolic tangent function, defined as the real part of the complex hyperbolic tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tanh (x : ℝ) : ℝ := (tanh x).re #align real.tanh Real.tanh /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : ℂ) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) ε0 -- Porting note: ε0 : ε > 0 but goal is _ < ε cases' j with j j · exact absurd hj (not_le_of_gt zero_lt_one) · dsimp [exp'] induction' j with j ih · dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] · rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp #align complex.exp_zero Complex.exp_zero theorem exp_add : exp (x + y) = exp x * exp y := by have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) = ∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹, mul_comm (m.choose I : ℂ)] rw [inv_mul_cancel h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_abs_exp x) (isCauSeq_exp y) #align complex.exp_add Complex.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp (Multiplicative.toAdd z), map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℂ) expMonoidHom l #align complex.exp_list_sum Complex.exp_list_sum theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s #align complex.exp_multiset_sum Complex.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s #align complex.exp_sum Complex.exp_sum lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] #align complex.exp_nat_mul Complex.exp_nat_mul theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one <| by rw [← exp_zero, ← add_neg_self x, exp_add, h]; simp #align complex.exp_ne_zero Complex.exp_ne_zero theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel (exp_ne_zero x)] #align complex.exp_neg Complex.exp_neg theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] #align complex.exp_sub Complex.exp_sub theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n · simp [exp_nat_mul] · simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] #align complex.exp_int_mul Complex.exp_int_mul @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal] #align complex.exp_conj Complex.exp_conj @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] #align complex.of_real_exp_of_real_re Complex.ofReal_exp_ofReal_re @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ #align complex.of_real_exp Complex.ofReal_exp @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] #align complex.exp_of_real_im Complex.exp_ofReal_im theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl #align complex.exp_of_real_re Complex.exp_ofReal_re theorem two_sinh : 2 * sinh x = exp x - exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_sinh Complex.two_sinh theorem two_cosh : 2 * cosh x = exp x + exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cosh Complex.two_cosh @[simp] theorem sinh_zero : sinh 0 = 0 := by simp [sinh] #align complex.sinh_zero Complex.sinh_zero @[simp] theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sinh_neg Complex.sinh_neg private theorem sinh_add_aux {a b c d : ℂ} : (a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_sinh, mul_left_comm, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, ← mul_assoc, two_cosh] exact sinh_add_aux #align complex.sinh_add Complex.sinh_add @[simp] theorem cosh_zero : cosh 0 = 1 := by simp [cosh] #align complex.cosh_zero Complex.cosh_zero @[simp] theorem cosh_neg : cosh (-x) = cosh x := by simp [add_comm, cosh, exp_neg] #align complex.cosh_neg Complex.cosh_neg private theorem cosh_add_aux {a b c d : ℂ} : (a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_cosh, ← mul_assoc, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, mul_left_comm, two_sinh] exact cosh_add_aux #align complex.cosh_add Complex.cosh_add theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg] #align complex.sinh_sub Complex.sinh_sub theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg] #align complex.cosh_sub Complex.cosh_sub theorem sinh_conj : sinh (conj x) = conj (sinh x) := by rw [sinh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_sub, sinh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.sinh_conj Complex.sinh_conj @[simp] theorem ofReal_sinh_ofReal_re (x : ℝ) : ((sinh x).re : ℂ) = sinh x := conj_eq_iff_re.1 <| by rw [← sinh_conj, conj_ofReal] #align complex.of_real_sinh_of_real_re Complex.ofReal_sinh_ofReal_re @[simp, norm_cast] theorem ofReal_sinh (x : ℝ) : (Real.sinh x : ℂ) = sinh x := ofReal_sinh_ofReal_re _ #align complex.of_real_sinh Complex.ofReal_sinh @[simp] theorem sinh_ofReal_im (x : ℝ) : (sinh x).im = 0 := by rw [← ofReal_sinh_ofReal_re, ofReal_im] #align complex.sinh_of_real_im Complex.sinh_ofReal_im theorem sinh_ofReal_re (x : ℝ) : (sinh x).re = Real.sinh x := rfl #align complex.sinh_of_real_re Complex.sinh_ofReal_re theorem cosh_conj : cosh (conj x) = conj (cosh x) := by rw [cosh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_add, cosh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.cosh_conj Complex.cosh_conj theorem ofReal_cosh_ofReal_re (x : ℝ) : ((cosh x).re : ℂ) = cosh x := conj_eq_iff_re.1 <| by rw [← cosh_conj, conj_ofReal] #align complex.of_real_cosh_of_real_re Complex.ofReal_cosh_ofReal_re @[simp, norm_cast] theorem ofReal_cosh (x : ℝ) : (Real.cosh x : ℂ) = cosh x := ofReal_cosh_ofReal_re _ #align complex.of_real_cosh Complex.ofReal_cosh @[simp] theorem cosh_ofReal_im (x : ℝ) : (cosh x).im = 0 := by rw [← ofReal_cosh_ofReal_re, ofReal_im] #align complex.cosh_of_real_im Complex.cosh_ofReal_im @[simp] theorem cosh_ofReal_re (x : ℝ) : (cosh x).re = Real.cosh x := rfl #align complex.cosh_of_real_re Complex.cosh_ofReal_re theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x := rfl #align complex.tanh_eq_sinh_div_cosh Complex.tanh_eq_sinh_div_cosh @[simp] theorem tanh_zero : tanh 0 = 0 := by simp [tanh] #align complex.tanh_zero Complex.tanh_zero @[simp] theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div] #align complex.tanh_neg Complex.tanh_neg theorem tanh_conj : tanh (conj x) = conj (tanh x) := by rw [tanh, sinh_conj, cosh_conj, ← map_div₀, tanh] #align complex.tanh_conj Complex.tanh_conj @[simp] theorem ofReal_tanh_ofReal_re (x : ℝ) : ((tanh x).re : ℂ) = tanh x := conj_eq_iff_re.1 <| by rw [← tanh_conj, conj_ofReal] #align complex.of_real_tanh_of_real_re Complex.ofReal_tanh_ofReal_re @[simp, norm_cast] theorem ofReal_tanh (x : ℝ) : (Real.tanh x : ℂ) = tanh x := ofReal_tanh_ofReal_re _ #align complex.of_real_tanh Complex.ofReal_tanh @[simp] theorem tanh_ofReal_im (x : ℝ) : (tanh x).im = 0 := by rw [← ofReal_tanh_ofReal_re, ofReal_im] #align complex.tanh_of_real_im Complex.tanh_ofReal_im theorem tanh_ofReal_re (x : ℝ) : (tanh x).re = Real.tanh x := rfl #align complex.tanh_of_real_re Complex.tanh_ofReal_re @[simp] theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_add, two_cosh, two_sinh, add_add_sub_cancel, two_mul] #align complex.cosh_add_sinh Complex.cosh_add_sinh @[simp] theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh] #align complex.sinh_add_cosh Complex.sinh_add_cosh @[simp] theorem exp_sub_cosh : exp x - cosh x = sinh x := sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm #align complex.exp_sub_cosh Complex.exp_sub_cosh @[simp] theorem exp_sub_sinh : exp x - sinh x = cosh x := sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm #align complex.exp_sub_sinh Complex.exp_sub_sinh @[simp] theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_sub, two_cosh, two_sinh, add_sub_sub_cancel, two_mul] #align complex.cosh_sub_sinh Complex.cosh_sub_sinh @[simp] theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh] #align complex.sinh_sub_cosh Complex.sinh_sub_cosh @[simp] theorem cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, ← exp_add, add_neg_self, exp_zero] #align complex.cosh_sq_sub_sinh_sq Complex.cosh_sq_sub_sinh_sq theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.cosh_sq Complex.cosh_sq theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.sinh_sq Complex.sinh_sq theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [two_mul, cosh_add, sq, sq] #align complex.cosh_two_mul Complex.cosh_two_mul theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by rw [two_mul, sinh_add] ring #align complex.sinh_two_mul Complex.sinh_two_mul theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cosh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : sinh x * (2 * sinh x * cosh x) = 2 * cosh x * sinh x ^ 2 := by ring rw [h2, sinh_sq] ring #align complex.cosh_three_mul Complex.cosh_three_mul theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sinh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : cosh x * (2 * sinh x * cosh x) = 2 * sinh x * cosh x ^ 2 := by ring rw [h2, cosh_sq] ring #align complex.sinh_three_mul Complex.sinh_three_mul @[simp] theorem sin_zero : sin 0 = 0 := by simp [sin] #align complex.sin_zero Complex.sin_zero @[simp] theorem sin_neg : sin (-x) = -sin x := by simp [sin, sub_eq_add_neg, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sin_neg Complex.sin_neg theorem two_sin : 2 * sin x = (exp (-x * I) - exp (x * I)) * I := mul_div_cancel₀ _ two_ne_zero #align complex.two_sin Complex.two_sin theorem two_cos : 2 * cos x = exp (x * I) + exp (-x * I) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cos Complex.two_cos theorem sinh_mul_I : sinh (x * I) = sin x * I := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, ← mul_assoc, two_sin, mul_assoc, I_mul_I, mul_neg_one, neg_sub, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.sinh_mul_I Complex.sinh_mul_I theorem cosh_mul_I : cosh (x * I) = cos x := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, two_cos, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.cosh_mul_I Complex.cosh_mul_I theorem tanh_mul_I : tanh (x * I) = tan x * I := by rw [tanh_eq_sinh_div_cosh, cosh_mul_I, sinh_mul_I, mul_div_right_comm, tan] set_option linter.uppercaseLean3 false in #align complex.tanh_mul_I Complex.tanh_mul_I theorem cos_mul_I : cos (x * I) = cosh x := by rw [← cosh_mul_I]; ring_nf; simp set_option linter.uppercaseLean3 false in #align complex.cos_mul_I Complex.cos_mul_I theorem sin_mul_I : sin (x * I) = sinh x * I := by have h : I * sin (x * I) = -sinh x := by rw [mul_comm, ← sinh_mul_I] ring_nf simp rw [← neg_neg (sinh x), ← h] apply Complex.ext <;> simp set_option linter.uppercaseLean3 false in #align complex.sin_mul_I Complex.sin_mul_I theorem tan_mul_I : tan (x * I) = tanh x * I := by rw [tan, sin_mul_I, cos_mul_I, mul_div_right_comm, tanh_eq_sinh_div_cosh] set_option linter.uppercaseLean3 false in #align complex.tan_mul_I Complex.tan_mul_I theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, add_mul, add_mul, mul_right_comm, ← sinh_mul_I, mul_assoc, ← sinh_mul_I, ← cosh_mul_I, ← cosh_mul_I, sinh_add] #align complex.sin_add Complex.sin_add @[simp] theorem cos_zero : cos 0 = 1 := by simp [cos] #align complex.cos_zero Complex.cos_zero @[simp] theorem cos_neg : cos (-x) = cos x := by simp [cos, sub_eq_add_neg, exp_neg, add_comm] #align complex.cos_neg Complex.cos_neg private theorem cos_add_aux {a b c d : ℂ} : (a + b) * (c + d) - (b - a) * (d - c) * -1 = 2 * (a * c + b * d) := by ring theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := by rw [← cosh_mul_I, add_mul, cosh_add, cosh_mul_I, cosh_mul_I, sinh_mul_I, sinh_mul_I, mul_mul_mul_comm, I_mul_I, mul_neg_one, sub_eq_add_neg] #align complex.cos_add Complex.cos_add theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg] #align complex.sin_sub Complex.sin_sub theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg] #align complex.cos_sub Complex.cos_sub theorem sin_add_mul_I (x y : ℂ) : sin (x + y * I) = sin x * cosh y + cos x * sinh y * I := by rw [sin_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.sin_add_mul_I Complex.sin_add_mul_I theorem sin_eq (z : ℂ) : sin z = sin z.re * cosh z.im + cos z.re * sinh z.im * I := by convert sin_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.sin_eq Complex.sin_eq theorem cos_add_mul_I (x y : ℂ) : cos (x + y * I) = cos x * cosh y - sin x * sinh y * I := by rw [cos_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.cos_add_mul_I Complex.cos_add_mul_I theorem cos_eq (z : ℂ) : cos z = cos z.re * cosh z.im - sin z.re * sinh z.im * I := by convert cos_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.cos_eq Complex.cos_eq theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := by have s1 := sin_add ((x + y) / 2) ((x - y) / 2) have s2 := sin_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.sin_sub_sin Complex.sin_sub_sin theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := by have s1 := cos_add ((x + y) / 2) ((x - y) / 2) have s2 := cos_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.cos_sub_cos Complex.cos_sub_cos theorem sin_add_sin : sin x + sin y = 2 * sin ((x + y) / 2) * cos ((x - y) / 2) := by simpa using sin_sub_sin x (-y) theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := by calc cos x + cos y = cos ((x + y) / 2 + (x - y) / 2) + cos ((x + y) / 2 - (x - y) / 2) := ?_ _ = cos ((x + y) / 2) * cos ((x - y) / 2) - sin ((x + y) / 2) * sin ((x - y) / 2) + (cos ((x + y) / 2) * cos ((x - y) / 2) + sin ((x + y) / 2) * sin ((x - y) / 2)) := ?_ _ = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ?_ · congr <;> field_simp · rw [cos_add, cos_sub] ring #align complex.cos_add_cos Complex.cos_add_cos theorem sin_conj : sin (conj x) = conj (sin x) := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← RingHom.map_mul, sinh_conj, mul_neg, sinh_neg, sinh_mul_I, mul_neg] #align complex.sin_conj Complex.sin_conj @[simp] theorem ofReal_sin_ofReal_re (x : ℝ) : ((sin x).re : ℂ) = sin x := conj_eq_iff_re.1 <| by rw [← sin_conj, conj_ofReal] #align complex.of_real_sin_of_real_re Complex.ofReal_sin_ofReal_re @[simp, norm_cast] theorem ofReal_sin (x : ℝ) : (Real.sin x : ℂ) = sin x := ofReal_sin_ofReal_re _ #align complex.of_real_sin Complex.ofReal_sin @[simp] theorem sin_ofReal_im (x : ℝ) : (sin x).im = 0 := by rw [← ofReal_sin_ofReal_re, ofReal_im] #align complex.sin_of_real_im Complex.sin_ofReal_im theorem sin_ofReal_re (x : ℝ) : (sin x).re = Real.sin x := rfl #align complex.sin_of_real_re Complex.sin_ofReal_re theorem cos_conj : cos (conj x) = conj (cos x) := by rw [← cosh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← cosh_mul_I, cosh_conj, mul_neg, cosh_neg] #align complex.cos_conj Complex.cos_conj @[simp] theorem ofReal_cos_ofReal_re (x : ℝ) : ((cos x).re : ℂ) = cos x := conj_eq_iff_re.1 <| by rw [← cos_conj, conj_ofReal] #align complex.of_real_cos_of_real_re Complex.ofReal_cos_ofReal_re @[simp, norm_cast] theorem ofReal_cos (x : ℝ) : (Real.cos x : ℂ) = cos x := ofReal_cos_ofReal_re _ #align complex.of_real_cos Complex.ofReal_cos @[simp] theorem cos_ofReal_im (x : ℝ) : (cos x).im = 0 := by rw [← ofReal_cos_ofReal_re, ofReal_im] #align complex.cos_of_real_im Complex.cos_ofReal_im theorem cos_ofReal_re (x : ℝ) : (cos x).re = Real.cos x := rfl #align complex.cos_of_real_re Complex.cos_ofReal_re @[simp] theorem tan_zero : tan 0 = 0 := by simp [tan] #align complex.tan_zero Complex.tan_zero theorem tan_eq_sin_div_cos : tan x = sin x / cos x := rfl #align complex.tan_eq_sin_div_cos Complex.tan_eq_sin_div_cos theorem tan_mul_cos {x : ℂ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx] #align complex.tan_mul_cos Complex.tan_mul_cos @[simp] theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] #align complex.tan_neg Complex.tan_neg theorem tan_conj : tan (conj x) = conj (tan x) := by rw [tan, sin_conj, cos_conj, ← map_div₀, tan] #align complex.tan_conj Complex.tan_conj @[simp] theorem ofReal_tan_ofReal_re (x : ℝ) : ((tan x).re : ℂ) = tan x := conj_eq_iff_re.1 <| by rw [← tan_conj, conj_ofReal] #align complex.of_real_tan_of_real_re Complex.ofReal_tan_ofReal_re @[simp, norm_cast] theorem ofReal_tan (x : ℝ) : (Real.tan x : ℂ) = tan x := ofReal_tan_ofReal_re _ #align complex.of_real_tan Complex.ofReal_tan @[simp] theorem tan_ofReal_im (x : ℝ) : (tan x).im = 0 := by rw [← ofReal_tan_ofReal_re, ofReal_im] #align complex.tan_of_real_im Complex.tan_ofReal_im theorem tan_ofReal_re (x : ℝ) : (tan x).re = Real.tan x := rfl #align complex.tan_of_real_re Complex.tan_ofReal_re theorem cos_add_sin_I : cos x + sin x * I = exp (x * I) := by rw [← cosh_add_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_add_sin_I Complex.cos_add_sin_I theorem cos_sub_sin_I : cos x - sin x * I = exp (-x * I) := by rw [neg_mul, ← cosh_sub_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_sub_sin_I Complex.cos_sub_sin_I @[simp] theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := Eq.trans (by rw [cosh_mul_I, sinh_mul_I, mul_pow, I_sq, mul_neg_one, sub_neg_eq_add, add_comm]) (cosh_sq_sub_sinh_sq (x * I)) #align complex.sin_sq_add_cos_sq Complex.sin_sq_add_cos_sq @[simp] theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq] #align complex.cos_sq_add_sin_sq Complex.cos_sq_add_sin_sq theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := by rw [two_mul, cos_add, ← sq, ← sq] #align complex.cos_two_mul' Complex.cos_two_mul' theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := by rw [cos_two_mul', eq_sub_iff_add_eq.2 (sin_sq_add_cos_sq x), ← sub_add, sub_add_eq_add_sub, two_mul] #align complex.cos_two_mul Complex.cos_two_mul
Mathlib/Data/Complex/Exponential.lean
728
729
theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := by
rw [two_mul, sin_add, two_mul, add_mul, mul_comm]
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.Algebra.Category.ModuleCat.Free import Mathlib.Topology.Category.Profinite.CofilteredLimit import Mathlib.Topology.Category.Profinite.Product import Mathlib.Topology.LocallyConstant.Algebra import Mathlib.Init.Data.Bool.Lemmas /-! # Nöbeling's theorem This file proves Nöbeling's theorem. ## Main result * `LocallyConstant.freeOfProfinite`: Nöbeling's theorem. For `S : Profinite`, the `ℤ`-module `LocallyConstant S ℤ` is free. ## Proof idea We follow the proof of theorem 5.4 in [scholze2019condensed], in which the idea is to embed `S` in a product of `I` copies of `Bool` for some sufficiently large `I`, and then to choose a well-ordering on `I` and use ordinal induction over that well-order. Here we can let `I` be the set of clopen subsets of `S` since `S` is totally separated. The above means it suffices to prove the following statement: For a closed subset `C` of `I → Bool`, the `ℤ`-module `LocallyConstant C ℤ` is free. For `i : I`, let `e C i : LocallyConstant C ℤ` denote the map `fun f ↦ (if f.val i then 1 else 0)`. The basis will consist of products `e C iᵣ * ⋯ * e C i₁` with `iᵣ > ⋯ > i₁` which cannot be written as linear combinations of lexicographically smaller products. We call this set `GoodProducts C` What is proved by ordinal induction is that this set is linearly independent. The fact that it spans can be proved directly. ## References - [scholze2019condensed], Theorem 5.4. -/ universe u namespace Profinite namespace NobelingProof variable {I : Type u} [LinearOrder I] [IsWellOrder I (·<·)] (C : Set (I → Bool)) open Profinite ContinuousMap CategoryTheory Limits Opposite Submodule section Projections /-! ## Projection maps The purpose of this section is twofold. Firstly, in the proof that the set `GoodProducts C` spans the whole module `LocallyConstant C ℤ`, we need to project `C` down to finite discrete subsets and write `C` as a cofiltered limit of those. Secondly, in the inductive argument, we need to project `C` down to "smaller" sets satisfying the inductive hypothesis. In this section we define the relevant projection maps and prove some compatibility results. ### Main definitions * Let `J : I → Prop`. Then `Proj J : (I → Bool) → (I → Bool)` is the projection mapping everything that satisfies `J i` to itself, and everything else to `false`. * The image of `C` under `Proj J` is denoted `π C J` and the corresponding map `C → π C J` is called `ProjRestrict`. If `J` implies `K` we have a map `ProjRestricts : π C K → π C J`. * `spanCone_isLimit` establishes that when `C` is compact, it can be written as a limit of its images under the maps `Proj (· ∈ s)` where `s : Finset I`. -/ variable (J K L : I → Prop) [∀ i, Decidable (J i)] [∀ i, Decidable (K i)] [∀ i, Decidable (L i)] /-- The projection mapping everything that satisfies `J i` to itself, and everything else to `false` -/ def Proj : (I → Bool) → (I → Bool) := fun c i ↦ if J i then c i else false @[simp] theorem continuous_proj : Continuous (Proj J : (I → Bool) → (I → Bool)) := by dsimp (config := { unfoldPartialApp := true }) [Proj] apply continuous_pi intro i split · apply continuous_apply · apply continuous_const /-- The image of `Proj π J` -/ def π : Set (I → Bool) := (Proj J) '' C /-- The restriction of `Proj π J` to a subset, mapping to its image. -/ @[simps!] def ProjRestrict : C → π C J := Set.MapsTo.restrict (Proj J) _ _ (Set.mapsTo_image _ _) @[simp] theorem continuous_projRestrict : Continuous (ProjRestrict C J) := Continuous.restrict _ (continuous_proj _) theorem proj_eq_self {x : I → Bool} (h : ∀ i, x i ≠ false → J i) : Proj J x = x := by ext i simp only [Proj, ite_eq_left_iff] contrapose! simpa only [ne_comm] using h i theorem proj_prop_eq_self (hh : ∀ i x, x ∈ C → x i ≠ false → J i) : π C J = C := by ext x refine ⟨fun ⟨y, hy, h⟩ ↦ ?_, fun h ↦ ⟨x, h, ?_⟩⟩ · rwa [← h, proj_eq_self]; exact (hh · y hy) · rw [proj_eq_self]; exact (hh · x h) theorem proj_comp_of_subset (h : ∀ i, J i → K i) : (Proj J ∘ Proj K) = (Proj J : (I → Bool) → (I → Bool)) := by ext x i; dsimp [Proj]; aesop theorem proj_eq_of_subset (h : ∀ i, J i → K i) : π (π C K) J = π C J := by ext x refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · obtain ⟨y, ⟨z, hz, rfl⟩, rfl⟩ := h refine ⟨z, hz, (?_ : _ = (Proj J ∘ Proj K) z)⟩ rw [proj_comp_of_subset J K h] · obtain ⟨y, hy, rfl⟩ := h dsimp [π] rw [← Set.image_comp] refine ⟨y, hy, ?_⟩ rw [proj_comp_of_subset J K h] variable {J K L} /-- A variant of `ProjRestrict` with domain of the form `π C K` -/ @[simps!] def ProjRestricts (h : ∀ i, J i → K i) : π C K → π C J := Homeomorph.setCongr (proj_eq_of_subset C J K h) ∘ ProjRestrict (π C K) J @[simp] theorem continuous_projRestricts (h : ∀ i, J i → K i) : Continuous (ProjRestricts C h) := Continuous.comp (Homeomorph.continuous _) (continuous_projRestrict _ _) theorem surjective_projRestricts (h : ∀ i, J i → K i) : Function.Surjective (ProjRestricts C h) := (Homeomorph.surjective _).comp (Set.surjective_mapsTo_image_restrict _ _) variable (J) in theorem projRestricts_eq_id : ProjRestricts C (fun i (h : J i) ↦ h) = id := by ext ⟨x, y, hy, rfl⟩ i simp (config := { contextual := true }) only [π, Proj, ProjRestricts_coe, id_eq, if_true] theorem projRestricts_eq_comp (hJK : ∀ i, J i → K i) (hKL : ∀ i, K i → L i) : ProjRestricts C hJK ∘ ProjRestricts C hKL = ProjRestricts C (fun i ↦ hKL i ∘ hJK i) := by ext x i simp only [π, Proj, Function.comp_apply, ProjRestricts_coe] aesop theorem projRestricts_comp_projRestrict (h : ∀ i, J i → K i) : ProjRestricts C h ∘ ProjRestrict C K = ProjRestrict C J := by ext x i simp only [π, Proj, Function.comp_apply, ProjRestricts_coe, ProjRestrict_coe] aesop variable (J) /-- The objectwise map in the isomorphism `spanFunctor ≅ Profinite.indexFunctor`. -/ def iso_map : C(π C J, (IndexFunctor.obj C J)) := ⟨fun x ↦ ⟨fun i ↦ x.val i.val, by rcases x with ⟨x, y, hy, rfl⟩ refine ⟨y, hy, ?_⟩ ext ⟨i, hi⟩ simp [precomp, Proj, hi]⟩, by refine Continuous.subtype_mk (continuous_pi fun i ↦ ?_) _ exact (continuous_apply i.val).comp continuous_subtype_val⟩ lemma iso_map_bijective : Function.Bijective (iso_map C J) := by refine ⟨fun a b h ↦ ?_, fun a ↦ ?_⟩ · ext i rw [Subtype.ext_iff] at h by_cases hi : J i · exact congr_fun h ⟨i, hi⟩ · rcases a with ⟨_, c, hc, rfl⟩ rcases b with ⟨_, d, hd, rfl⟩ simp only [Proj, if_neg hi] · refine ⟨⟨fun i ↦ if hi : J i then a.val ⟨i, hi⟩ else false, ?_⟩, ?_⟩ · rcases a with ⟨_, y, hy, rfl⟩ exact ⟨y, hy, rfl⟩ · ext i exact dif_pos i.prop variable {C} (hC : IsCompact C) /-- For a given compact subset `C` of `I → Bool`, `spanFunctor` is the functor from the poset of finsets of `I` to `Profinite`, sending a finite subset set `J` to the image of `C` under the projection `Proj J`. -/ noncomputable def spanFunctor [∀ (s : Finset I) (i : I), Decidable (i ∈ s)] : (Finset I)ᵒᵖ ⥤ Profinite.{u} where obj s := @Profinite.of (π C (· ∈ (unop s))) _ (by rw [← isCompact_iff_compactSpace]; exact hC.image (continuous_proj _)) _ _ map h := ⟨(ProjRestricts C (leOfHom h.unop)), continuous_projRestricts _ _⟩ map_id J := by simp only [projRestricts_eq_id C (· ∈ (unop J))]; rfl map_comp _ _ := by dsimp; congr; dsimp; rw [projRestricts_eq_comp] /-- The limit cone on `spanFunctor` with point `C`. -/ noncomputable def spanCone [∀ (s : Finset I) (i : I), Decidable (i ∈ s)] : Cone (spanFunctor hC) where pt := @Profinite.of C _ (by rwa [← isCompact_iff_compactSpace]) _ _ π := { app := fun s ↦ ⟨ProjRestrict C (· ∈ unop s), continuous_projRestrict _ _⟩ naturality := by intro X Y h simp only [Functor.const_obj_obj, Homeomorph.setCongr, Homeomorph.homeomorph_mk_coe, Functor.const_obj_map, Category.id_comp, ← projRestricts_comp_projRestrict C (leOfHom h.unop)] rfl } /-- `spanCone` is a limit cone. -/ noncomputable def spanCone_isLimit [∀ (s : Finset I) (i : I), Decidable (i ∈ s)] : CategoryTheory.Limits.IsLimit (spanCone hC) := by refine (IsLimit.postcomposeHomEquiv (NatIso.ofComponents (fun s ↦ (Profinite.isoOfBijective _ (iso_map_bijective C (· ∈ unop s)))) ?_) (spanCone hC)) (IsLimit.ofIsoLimit (indexCone_isLimit hC) (Cones.ext (Iso.refl _) ?_)) · intro ⟨s⟩ ⟨t⟩ ⟨⟨⟨f⟩⟩⟩ ext x have : iso_map C (· ∈ t) ∘ ProjRestricts C f = IndexFunctor.map C f ∘ iso_map C (· ∈ s) := by ext _ i; exact dif_pos i.prop exact congr_fun this x · intro ⟨s⟩ ext x have : iso_map C (· ∈ s) ∘ ProjRestrict C (· ∈ s) = IndexFunctor.π_app C (· ∈ s) := by ext _ i; exact dif_pos i.prop erw [← this] rfl end Projections section Products /-! ## Defining the basis Our proposed basis consists of products `e C iᵣ * ⋯ * e C i₁` with `iᵣ > ⋯ > i₁` which cannot be written as linear combinations of lexicographically smaller products. See below for the definition of `e`. ### Main definitions * For `i : I`, we let `e C i : LocallyConstant C ℤ` denote the map `fun f ↦ (if f.val i then 1 else 0)`. * `Products I` is the type of lists of decreasing elements of `I`, so a typical element is `[i₁, i₂,..., iᵣ]` with `i₁ > i₂ > ... > iᵣ`. * `Products.eval C` is the `C`-evaluation of a list. It takes a term `[i₁, i₂,..., iᵣ] : Products I` and returns the actual product `e C i₁ ··· e C iᵣ : LocallyConstant C ℤ`. * `GoodProducts C` is the set of `Products I` such that their `C`-evaluation cannot be written as a linear combination of evaluations of lexicographically smaller lists. ### Main results * `Products.evalFacProp` and `Products.evalFacProps` establish the fact that `Products.eval`  interacts nicely with the projection maps from the previous section. * `GoodProducts.span_iff_products`: the good products span `LocallyConstant C ℤ` iff all the products span `LocallyConstant C ℤ`. -/ /-- `e C i` is the locally constant map from `C : Set (I → Bool)` to `ℤ` sending `f` to 1 if `f.val i = true`, and 0 otherwise. -/ def e (i : I) : LocallyConstant C ℤ where toFun := fun f ↦ (if f.val i then 1 else 0) isLocallyConstant := by rw [IsLocallyConstant.iff_continuous] exact (continuous_of_discreteTopology (f := fun (a : Bool) ↦ (if a then (1 : ℤ) else 0))).comp ((continuous_apply i).comp continuous_subtype_val) /-- `Products I` is the type of lists of decreasing elements of `I`, so a typical element is `[i₁, i₂, ...]` with `i₁ > i₂ > ...`. We order `Products I` lexicographically, so `[] < [i₁, ...]`, and `[i₁, i₂, ...] < [j₁, j₂, ...]` if either `i₁ < j₁`, or `i₁ = j₁` and `[i₂, ...] < [j₂, ...]`. Terms `m = [i₁, i₂, ..., iᵣ]` of this type will be used to represent products of the form `e C i₁ ··· e C iᵣ : LocallyConstant C ℤ` . The function associated to `m` is `m.eval`. -/ def Products (I : Type*) [LinearOrder I] := {l : List I // l.Chain' (·>·)} namespace Products instance : LinearOrder (Products I) := inferInstanceAs (LinearOrder {l : List I // l.Chain' (·>·)}) @[simp] theorem lt_iff_lex_lt (l m : Products I) : l < m ↔ List.Lex (·<·) l.val m.val := by cases l; cases m; rw [Subtype.mk_lt_mk]; exact Iff.rfl instance : IsWellFounded (Products I) (·<·) := by have : (· < · : Products I → _ → _) = (fun l m ↦ List.Lex (·<·) l.val m.val) := by ext; exact lt_iff_lex_lt _ _ rw [this] dsimp [Products] rw [(by rfl : (·>· : I → _) = flip (·<·))] infer_instance /-- The evaluation `e C i₁ ··· e C iᵣ : C → ℤ` of a formal product `[i₁, i₂, ..., iᵣ]`. -/ def eval (l : Products I) := (l.1.map (e C)).prod /-- The predicate on products which we prove picks out a basis of `LocallyConstant C ℤ`. We call such a product "good". -/ def isGood (l : Products I) : Prop := l.eval C ∉ Submodule.span ℤ ((Products.eval C) '' {m | m < l}) theorem rel_head!_of_mem [Inhabited I] {i : I} {l : Products I} (hi : i ∈ l.val) : i ≤ l.val.head! := List.Sorted.le_head! (List.chain'_iff_pairwise.mp l.prop) hi theorem head!_le_of_lt [Inhabited I] {q l : Products I} (h : q < l) (hq : q.val ≠ []) : q.val.head! ≤ l.val.head! := List.head!_le_of_lt l.val q.val h hq end Products /-- The set of good products. -/ def GoodProducts := {l : Products I | l.isGood C} namespace GoodProducts /-- Evaluation of good products. -/ def eval (l : {l : Products I // l.isGood C}) : LocallyConstant C ℤ := Products.eval C l.1 theorem injective : Function.Injective (eval C) := by intro ⟨a, ha⟩ ⟨b, hb⟩ h dsimp [eval] at h rcases lt_trichotomy a b with (h'|rfl|h') · exfalso; apply hb; rw [← h] exact Submodule.subset_span ⟨a, h', rfl⟩ · rfl · exfalso; apply ha; rw [h] exact Submodule.subset_span ⟨b, ⟨h',rfl⟩⟩ /-- The image of the good products in the module `LocallyConstant C ℤ`. -/ def range := Set.range (GoodProducts.eval C) /-- The type of good products is equivalent to its image. -/ noncomputable def equiv_range : GoodProducts C ≃ range C := Equiv.ofInjective (eval C) (injective C) theorem equiv_toFun_eq_eval : (equiv_range C).toFun = Set.rangeFactorization (eval C) := rfl theorem linearIndependent_iff_range : LinearIndependent ℤ (GoodProducts.eval C) ↔ LinearIndependent ℤ (fun (p : range C) ↦ p.1) := by rw [← @Set.rangeFactorization_eq _ _ (GoodProducts.eval C), ← equiv_toFun_eq_eval C] exact linearIndependent_equiv (equiv_range C) end GoodProducts namespace Products theorem eval_eq (l : Products I) (x : C) : l.eval C x = if ∀ i, i ∈ l.val → (x.val i = true) then 1 else 0 := by change LocallyConstant.evalMonoidHom x (l.eval C) = _ rw [eval, map_list_prod] split_ifs with h · simp only [List.map_map] apply List.prod_eq_one simp only [List.mem_map, Function.comp_apply] rintro _ ⟨i, hi, rfl⟩ exact if_pos (h i hi) · simp only [List.map_map, List.prod_eq_zero_iff, List.mem_map, Function.comp_apply] push_neg at h convert h with i dsimp [LocallyConstant.evalMonoidHom, e] simp only [ite_eq_right_iff, one_ne_zero] theorem evalFacProp {l : Products I} (J : I → Prop) (h : ∀ a, a ∈ l.val → J a) [∀ j, Decidable (J j)] : l.eval (π C J) ∘ ProjRestrict C J = l.eval C := by ext x dsimp [ProjRestrict] rw [Products.eval_eq, Products.eval_eq] congr apply forall_congr; intro i apply forall_congr; intro hi simp [h i hi, Proj] theorem evalFacProps {l : Products I} (J K : I → Prop) (h : ∀ a, a ∈ l.val → J a) [∀ j, Decidable (J j)] [∀ j, Decidable (K j)] (hJK : ∀ i, J i → K i) : l.eval (π C J) ∘ ProjRestricts C hJK = l.eval (π C K) := by have : l.eval (π C J) ∘ Homeomorph.setCongr (proj_eq_of_subset C J K hJK) = l.eval (π (π C K) J) := by ext; simp [Homeomorph.setCongr, Products.eval_eq] rw [ProjRestricts, ← Function.comp.assoc, this, ← evalFacProp (π C K) J h] theorem prop_of_isGood {l : Products I} (J : I → Prop) [∀ j, Decidable (J j)] (h : l.isGood (π C J)) : ∀ a, a ∈ l.val → J a := by intro i hi by_contra h' apply h suffices eval (π C J) l = 0 by rw [this] exact Submodule.zero_mem _ ext ⟨_, _, _, rfl⟩ rw [eval_eq, if_neg fun h ↦ ?_, LocallyConstant.zero_apply] simpa [Proj, h'] using h i hi end Products /-- The good products span `LocallyConstant C ℤ` if and only all the products do. -/ theorem GoodProducts.span_iff_products : ⊤ ≤ span ℤ (Set.range (eval C)) ↔ ⊤ ≤ span ℤ (Set.range (Products.eval C)) := by refine ⟨fun h ↦ le_trans h (span_mono (fun a ⟨b, hb⟩ ↦ ⟨b.val, hb⟩)), fun h ↦ le_trans h ?_⟩ rw [span_le] rintro f ⟨l, rfl⟩ let L : Products I → Prop := fun m ↦ m.eval C ∈ span ℤ (Set.range (GoodProducts.eval C)) suffices L l by assumption apply IsWellFounded.induction (·<· : Products I → Products I → Prop) intro l h dsimp by_cases hl : l.isGood C · apply subset_span exact ⟨⟨l, hl⟩, rfl⟩ · simp only [Products.isGood, not_not] at hl suffices Products.eval C '' {m | m < l} ⊆ span ℤ (Set.range (GoodProducts.eval C)) by rw [← span_le] at this exact this hl rintro a ⟨m, hm, rfl⟩ exact h m hm end Products section Span /-! ## The good products span Most of the argument is developing an API for `π C (· ∈ s)` when `s : Finset I`; then the image of `C` is finite with the discrete topology. In this case, there is a direct argument that the good products span. The general result is deduced from this. ### Main theorems * `GoodProducts.spanFin` : The good products span the locally constant functions on `π C (· ∈ s)` if `s` is finite. * `GoodProducts.span` : The good products span `LocallyConstant C ℤ` for every closed subset `C`. -/ section Fin variable (s : Finset I) /-- The `ℤ`-linear map induced by precomposition of the projection `C → π C (· ∈ s)`. -/ noncomputable def πJ : LocallyConstant (π C (· ∈ s)) ℤ →ₗ[ℤ] LocallyConstant C ℤ := LocallyConstant.comapₗ ℤ ⟨_, (continuous_projRestrict C (· ∈ s))⟩ theorem eval_eq_πJ (l : Products I) (hl : l.isGood (π C (· ∈ s))) : l.eval C = πJ C s (l.eval (π C (· ∈ s))) := by ext f simp only [πJ, LocallyConstant.comapₗ, LinearMap.coe_mk, AddHom.coe_mk, (continuous_projRestrict C (· ∈ s)), LocallyConstant.coe_comap, Function.comp_apply] exact (congr_fun (Products.evalFacProp C (· ∈ s) (Products.prop_of_isGood C (· ∈ s) hl)) _).symm /-- `π C (· ∈ s)` is finite for a finite set `s`. -/ noncomputable instance : Fintype (π C (· ∈ s)) := by let f : π C (· ∈ s) → (s → Bool) := fun x j ↦ x.val j.val refine Fintype.ofInjective f ?_ intro ⟨_, x, hx, rfl⟩ ⟨_, y, hy, rfl⟩ h ext i by_cases hi : i ∈ s · exact congrFun h ⟨i, hi⟩ · simp only [Proj, if_neg hi] open scoped Classical in /-- The Kronecker delta as a locally constant map from `π C (· ∈ s)` to `ℤ`. -/ noncomputable def spanFinBasis (x : π C (· ∈ s)) : LocallyConstant (π C (· ∈ s)) ℤ where toFun := fun y ↦ if y = x then 1 else 0 isLocallyConstant := haveI : DiscreteTopology (π C (· ∈ s)) := discrete_of_t1_of_finite IsLocallyConstant.of_discrete _ open scoped Classical in theorem spanFinBasis.span : ⊤ ≤ Submodule.span ℤ (Set.range (spanFinBasis C s)) := by intro f _ rw [Finsupp.mem_span_range_iff_exists_finsupp] use Finsupp.onFinset (Finset.univ) f.toFun (fun _ _ ↦ Finset.mem_univ _) ext x change LocallyConstant.evalₗ ℤ x _ = _ simp only [zsmul_eq_mul, map_finsupp_sum, LocallyConstant.evalₗ_apply, LocallyConstant.coe_mul, Pi.mul_apply, spanFinBasis, LocallyConstant.coe_mk, mul_ite, mul_one, mul_zero, Finsupp.sum_ite_eq, Finsupp.mem_support_iff, ne_eq, ite_not] split_ifs with h <;> [exact h.symm; rfl] /-- A certain explicit list of locally constant maps. The theorem `factors_prod_eq_basis` shows that the product of the elements in this list is the delta function `spanFinBasis C s x`. -/ def factors (x : π C (· ∈ s)) : List (LocallyConstant (π C (· ∈ s)) ℤ) := List.map (fun i ↦ if x.val i = true then e (π C (· ∈ s)) i else (1 - (e (π C (· ∈ s)) i))) (s.sort (·≥·)) theorem list_prod_apply (x : C) (l : List (LocallyConstant C ℤ)) : l.prod x = (l.map (LocallyConstant.evalMonoidHom x)).prod := by rw [← map_list_prod (LocallyConstant.evalMonoidHom x) l] rfl theorem factors_prod_eq_basis_of_eq {x y : (π C fun x ↦ x ∈ s)} (h : y = x) : (factors C s x).prod y = 1 := by rw [list_prod_apply (π C (· ∈ s)) y _] apply List.prod_eq_one simp only [h, List.mem_map, LocallyConstant.evalMonoidHom, factors] rintro _ ⟨a, ⟨b, _, rfl⟩, rfl⟩ dsimp split_ifs with hh · rw [e, LocallyConstant.coe_mk, if_pos hh] · rw [LocallyConstant.sub_apply, e, LocallyConstant.coe_mk, LocallyConstant.coe_mk, if_neg hh] simp only [LocallyConstant.toFun_eq_coe, LocallyConstant.coe_one, Pi.one_apply, sub_zero] theorem e_mem_of_eq_true {x : (π C (· ∈ s))} {a : I} (hx : x.val a = true) : e (π C (· ∈ s)) a ∈ factors C s x := by rcases x with ⟨_, z, hz, rfl⟩ simp only [factors, List.mem_map, Finset.mem_sort] refine ⟨a, ?_, if_pos hx⟩ aesop (add simp Proj) theorem one_sub_e_mem_of_false {x y : (π C (· ∈ s))} {a : I} (ha : y.val a = true) (hx : x.val a = false) : 1 - e (π C (· ∈ s)) a ∈ factors C s x := by simp only [factors, List.mem_map, Finset.mem_sort] use a simp only [hx, ite_false, and_true] rcases y with ⟨_, z, hz, rfl⟩ aesop (add simp Proj) theorem factors_prod_eq_basis_of_ne {x y : (π C (· ∈ s))} (h : y ≠ x) : (factors C s x).prod y = 0 := by rw [list_prod_apply (π C (· ∈ s)) y _] apply List.prod_eq_zero simp only [List.mem_map] obtain ⟨a, ha⟩ : ∃ a, y.val a ≠ x.val a := by contrapose! h; ext; apply h cases hx : x.val a · rw [hx, ne_eq, Bool.not_eq_false] at ha refine ⟨1 - (e (π C (· ∈ s)) a), ⟨one_sub_e_mem_of_false _ _ ha hx, ?_⟩⟩ rw [e, LocallyConstant.evalMonoidHom_apply, LocallyConstant.sub_apply, LocallyConstant.coe_one, Pi.one_apply, LocallyConstant.coe_mk, if_pos ha, sub_self] · refine ⟨e (π C (· ∈ s)) a, ⟨e_mem_of_eq_true _ _ hx, ?_⟩⟩ rw [hx] at ha rw [LocallyConstant.evalMonoidHom_apply, e, LocallyConstant.coe_mk, if_neg ha] /-- If `s` is finite, the product of the elements of the list `factors C s x` is the delta function at `x`. -/ theorem factors_prod_eq_basis (x : π C (· ∈ s)) : (factors C s x).prod = spanFinBasis C s x := by ext y dsimp [spanFinBasis] split_ifs with h <;> [exact factors_prod_eq_basis_of_eq _ _ h; exact factors_prod_eq_basis_of_ne _ _ h]
Mathlib/Topology/Category/Profinite/Nobeling.lean
580
596
theorem GoodProducts.finsupp_sum_mem_span_eval {a : I} {as : List I} (ha : List.Chain' (· > ·) (a :: as)) {c : Products I →₀ ℤ} (hc : (c.support : Set (Products I)) ⊆ {m | m.val ≤ as}) : (Finsupp.sum c fun a_1 b ↦ e (π C (· ∈ s)) a * b • Products.eval (π C (· ∈ s)) a_1) ∈ Submodule.span ℤ (Products.eval (π C (· ∈ s)) '' {m | m.val ≤ a :: as}) := by
apply Submodule.finsupp_sum_mem intro m hm have hsm := (LinearMap.mulLeft ℤ (e (π C (· ∈ s)) a)).map_smul dsimp at hsm rw [hsm] apply Submodule.smul_mem apply Submodule.subset_span have hmas : m.val ≤ as := by apply hc simpa only [Finset.mem_coe, Finsupp.mem_support_iff] using hm refine ⟨⟨a :: m.val, ha.cons_of_le m.prop hmas⟩, ⟨List.cons_le_cons a hmas, ?_⟩⟩ simp only [Products.eval, List.map, List.prod_cons]
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Probability.IdentDistrib import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.Analysis.SpecificLimits.FloorPow import Mathlib.Analysis.PSeries import Mathlib.Analysis.Asymptotics.SpecificAsymptotics #align_import probability.strong_law from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # The strong law of large numbers We prove the strong law of large numbers, in `ProbabilityTheory.strong_law_ae`: If `X n` is a sequence of independent identically distributed integrable random variables, then `∑ i ∈ range n, X i / n` converges almost surely to `𝔼[X 0]`. We give here the strong version, due to Etemadi, that only requires pairwise independence. This file also contains the Lᵖ version of the strong law of large numbers provided by `ProbabilityTheory.strong_law_Lp` which shows `∑ i ∈ range n, X i / n` converges in Lᵖ to `𝔼[X 0]` provided `X n` is independent identically distributed and is Lᵖ. ## Implementation The main point is to prove the result for real-valued random variables, as the general case of Banach-space valued random variables follows from this case and approximation by simple functions. The real version is given in `ProbabilityTheory.strong_law_ae_real`. We follow the proof by Etemadi [Etemadi, *An elementary proof of the strong law of large numbers*][etemadi_strong_law], which goes as follows. It suffices to prove the result for nonnegative `X`, as one can prove the general result by splitting a general `X` into its positive part and negative part. Consider `Xₙ` a sequence of nonnegative integrable identically distributed pairwise independent random variables. Let `Yₙ` be the truncation of `Xₙ` up to `n`. We claim that * Almost surely, `Xₙ = Yₙ` for all but finitely many indices. Indeed, `∑ ℙ (Xₙ ≠ Yₙ)` is bounded by `1 + 𝔼[X]` (see `sum_prob_mem_Ioc_le` and `tsum_prob_mem_Ioi_lt_top`). * Let `c > 1`. Along the sequence `n = c ^ k`, then `(∑_{i=0}^{n-1} Yᵢ - 𝔼[Yᵢ])/n` converges almost surely to `0`. This follows from a variance control, as ``` ∑_k ℙ (|∑_{i=0}^{c^k - 1} Yᵢ - 𝔼[Yᵢ]| > c^k ε) ≤ ∑_k (c^k ε)^{-2} ∑_{i=0}^{c^k - 1} Var[Yᵢ] (by Markov inequality) ≤ ∑_i (C/i^2) Var[Yᵢ] (as ∑_{c^k > i} 1/(c^k)^2 ≤ C/i^2) ≤ ∑_i (C/i^2) 𝔼[Yᵢ^2] ≤ 2C 𝔼[X^2] (see `sum_variance_truncation_le`) ``` * As `𝔼[Yᵢ]` converges to `𝔼[X]`, it follows from the two previous items and Cesàro that, along the sequence `n = c^k`, one has `(∑_{i=0}^{n-1} Xᵢ) / n → 𝔼[X]` almost surely. * To generalize it to all indices, we use the fact that `∑_{i=0}^{n-1} Xᵢ` is nondecreasing and that, if `c` is close enough to `1`, the gap between `c^k` and `c^(k+1)` is small. -/ noncomputable section open MeasureTheory Filter Finset Asymptotics open Set (indicator) open scoped Topology MeasureTheory ProbabilityTheory ENNReal NNReal namespace ProbabilityTheory /-! ### Prerequisites on truncations -/ section Truncation variable {α : Type*} /-- Truncating a real-valued function to the interval `(-A, A]`. -/ def truncation (f : α → ℝ) (A : ℝ) := indicator (Set.Ioc (-A) A) id ∘ f #align probability_theory.truncation ProbabilityTheory.truncation variable {m : MeasurableSpace α} {μ : Measure α} {f : α → ℝ} theorem _root_.MeasureTheory.AEStronglyMeasurable.truncation (hf : AEStronglyMeasurable f μ) {A : ℝ} : AEStronglyMeasurable (truncation f A) μ := by apply AEStronglyMeasurable.comp_aemeasurable _ hf.aemeasurable exact (stronglyMeasurable_id.indicator measurableSet_Ioc).aestronglyMeasurable #align measure_theory.ae_strongly_measurable.truncation MeasureTheory.AEStronglyMeasurable.truncation theorem abs_truncation_le_bound (f : α → ℝ) (A : ℝ) (x : α) : |truncation f A x| ≤ |A| := by simp only [truncation, Set.indicator, Set.mem_Icc, id, Function.comp_apply] split_ifs with h · exact abs_le_abs h.2 (neg_le.2 h.1.le) · simp [abs_nonneg] #align probability_theory.abs_truncation_le_bound ProbabilityTheory.abs_truncation_le_bound @[simp] theorem truncation_zero (f : α → ℝ) : truncation f 0 = 0 := by simp [truncation]; rfl #align probability_theory.truncation_zero ProbabilityTheory.truncation_zero theorem abs_truncation_le_abs_self (f : α → ℝ) (A : ℝ) (x : α) : |truncation f A x| ≤ |f x| := by simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply] split_ifs · exact le_rfl · simp [abs_nonneg] #align probability_theory.abs_truncation_le_abs_self ProbabilityTheory.abs_truncation_le_abs_self theorem truncation_eq_self {f : α → ℝ} {A : ℝ} {x : α} (h : |f x| < A) : truncation f A x = f x := by simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply, ite_eq_left_iff] intro H apply H.elim simp [(abs_lt.1 h).1, (abs_lt.1 h).2.le] #align probability_theory.truncation_eq_self ProbabilityTheory.truncation_eq_self theorem truncation_eq_of_nonneg {f : α → ℝ} {A : ℝ} (h : ∀ x, 0 ≤ f x) : truncation f A = indicator (Set.Ioc 0 A) id ∘ f := by ext x rcases (h x).lt_or_eq with (hx | hx) · simp only [truncation, indicator, hx, Set.mem_Ioc, id, Function.comp_apply, true_and_iff] by_cases h'x : f x ≤ A · have : -A < f x := by linarith [h x] simp only [this, true_and_iff] · simp only [h'x, and_false_iff] · simp only [truncation, indicator, hx, id, Function.comp_apply, ite_self] #align probability_theory.truncation_eq_of_nonneg ProbabilityTheory.truncation_eq_of_nonneg theorem truncation_nonneg {f : α → ℝ} (A : ℝ) {x : α} (h : 0 ≤ f x) : 0 ≤ truncation f A x := Set.indicator_apply_nonneg fun _ => h #align probability_theory.truncation_nonneg ProbabilityTheory.truncation_nonneg theorem _root_.MeasureTheory.AEStronglyMeasurable.memℒp_truncation [IsFiniteMeasure μ] (hf : AEStronglyMeasurable f μ) {A : ℝ} {p : ℝ≥0∞} : Memℒp (truncation f A) p μ := Memℒp.of_bound hf.truncation |A| (eventually_of_forall fun _ => abs_truncation_le_bound _ _ _) #align measure_theory.ae_strongly_measurable.mem_ℒp_truncation MeasureTheory.AEStronglyMeasurable.memℒp_truncation theorem _root_.MeasureTheory.AEStronglyMeasurable.integrable_truncation [IsFiniteMeasure μ] (hf : AEStronglyMeasurable f μ) {A : ℝ} : Integrable (truncation f A) μ := by rw [← memℒp_one_iff_integrable]; exact hf.memℒp_truncation #align measure_theory.ae_strongly_measurable.integrable_truncation MeasureTheory.AEStronglyMeasurable.integrable_truncation theorem moment_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f μ) {A : ℝ} (hA : 0 ≤ A) {n : ℕ} (hn : n ≠ 0) : ∫ x, truncation f A x ^ n ∂μ = ∫ y in -A..A, y ^ n ∂Measure.map f μ := by have M : MeasurableSet (Set.Ioc (-A) A) := measurableSet_Ioc change ∫ x, (fun z => indicator (Set.Ioc (-A) A) id z ^ n) (f x) ∂μ = _ rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le, ← integral_indicator M] · simp only [indicator, zero_pow hn, id, ite_pow] · linarith · exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable #align probability_theory.moment_truncation_eq_interval_integral ProbabilityTheory.moment_truncation_eq_intervalIntegral theorem moment_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f μ) {A : ℝ} {n : ℕ} (hn : n ≠ 0) (h'f : 0 ≤ f) : ∫ x, truncation f A x ^ n ∂μ = ∫ y in (0)..A, y ^ n ∂Measure.map f μ := by have M : MeasurableSet (Set.Ioc 0 A) := measurableSet_Ioc have M' : MeasurableSet (Set.Ioc A 0) := measurableSet_Ioc rw [truncation_eq_of_nonneg h'f] change ∫ x, (fun z => indicator (Set.Ioc 0 A) id z ^ n) (f x) ∂μ = _ rcases le_or_lt 0 A with (hA | hA) · rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le hA, ← integral_indicator M] · simp only [indicator, zero_pow hn, id, ite_pow] · exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable · rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_ge hA.le, ← integral_indicator M'] · simp only [Set.Ioc_eq_empty_of_le hA.le, zero_pow hn, Set.indicator_empty, integral_zero, zero_eq_neg] apply integral_eq_zero_of_ae have : ∀ᵐ x ∂Measure.map f μ, (0 : ℝ) ≤ x := (ae_map_iff hf.aemeasurable measurableSet_Ici).2 (eventually_of_forall h'f) filter_upwards [this] with x hx simp only [indicator, Set.mem_Ioc, Pi.zero_apply, ite_eq_right_iff, and_imp] intro _ h''x have : x = 0 := by linarith simp [this, zero_pow hn] · exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable #align probability_theory.moment_truncation_eq_interval_integral_of_nonneg ProbabilityTheory.moment_truncation_eq_intervalIntegral_of_nonneg theorem integral_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f μ) {A : ℝ} (hA : 0 ≤ A) : ∫ x, truncation f A x ∂μ = ∫ y in -A..A, y ∂Measure.map f μ := by simpa using moment_truncation_eq_intervalIntegral hf hA one_ne_zero #align probability_theory.integral_truncation_eq_interval_integral ProbabilityTheory.integral_truncation_eq_intervalIntegral theorem integral_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f μ) {A : ℝ} (h'f : 0 ≤ f) : ∫ x, truncation f A x ∂μ = ∫ y in (0)..A, y ∂Measure.map f μ := by simpa using moment_truncation_eq_intervalIntegral_of_nonneg hf one_ne_zero h'f #align probability_theory.integral_truncation_eq_interval_integral_of_nonneg ProbabilityTheory.integral_truncation_eq_intervalIntegral_of_nonneg theorem integral_truncation_le_integral_of_nonneg (hf : Integrable f μ) (h'f : 0 ≤ f) {A : ℝ} : ∫ x, truncation f A x ∂μ ≤ ∫ x, f x ∂μ := by apply integral_mono_of_nonneg (eventually_of_forall fun x => ?_) hf (eventually_of_forall fun x => ?_) · exact truncation_nonneg _ (h'f x) · calc truncation f A x ≤ |truncation f A x| := le_abs_self _ _ ≤ |f x| := abs_truncation_le_abs_self _ _ _ _ = f x := abs_of_nonneg (h'f x) #align probability_theory.integral_truncation_le_integral_of_nonneg ProbabilityTheory.integral_truncation_le_integral_of_nonneg /-- If a function is integrable, then the integral of its truncated versions converges to the integral of the whole function. -/ theorem tendsto_integral_truncation {f : α → ℝ} (hf : Integrable f μ) : Tendsto (fun A => ∫ x, truncation f A x ∂μ) atTop (𝓝 (∫ x, f x ∂μ)) := by refine tendsto_integral_filter_of_dominated_convergence (fun x => abs (f x)) ?_ ?_ ?_ ?_ · exact eventually_of_forall fun A ↦ hf.aestronglyMeasurable.truncation · filter_upwards with A filter_upwards with x rw [Real.norm_eq_abs] exact abs_truncation_le_abs_self _ _ _ · exact hf.abs · filter_upwards with x apply tendsto_const_nhds.congr' _ filter_upwards [Ioi_mem_atTop (abs (f x))] with A hA exact (truncation_eq_self hA).symm #align probability_theory.tendsto_integral_truncation ProbabilityTheory.tendsto_integral_truncation theorem IdentDistrib.truncation {β : Type*} [MeasurableSpace β] {ν : Measure β} {f : α → ℝ} {g : β → ℝ} (h : IdentDistrib f g μ ν) {A : ℝ} : IdentDistrib (truncation f A) (truncation g A) μ ν := h.comp (measurable_id.indicator measurableSet_Ioc) #align probability_theory.ident_distrib.truncation ProbabilityTheory.IdentDistrib.truncation end Truncation section StrongLawAeReal variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] section MomentEstimates theorem sum_prob_mem_Ioc_le {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) {K : ℕ} {N : ℕ} (hKN : K ≤ N) : ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N} ≤ ENNReal.ofReal (𝔼[X] + 1) := by let ρ : Measure ℝ := Measure.map X ℙ haveI : IsProbabilityMeasure ρ := isProbabilityMeasure_map hint.aemeasurable have A : ∑ j ∈ range K, ∫ _ in j..N, (1 : ℝ) ∂ρ ≤ 𝔼[X] + 1 := calc ∑ j ∈ range K, ∫ _ in j..N, (1 : ℝ) ∂ρ = ∑ j ∈ range K, ∑ i ∈ Ico j N, ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by apply sum_congr rfl fun j hj => ?_ rw [intervalIntegral.sum_integral_adjacent_intervals_Ico ((mem_range.1 hj).le.trans hKN)] intro k _ exact continuous_const.intervalIntegrable _ _ _ = ∑ i ∈ range N, ∑ j ∈ range (min (i + 1) K), ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by simp_rw [sum_sigma'] refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ <;> aesop (add simp Nat.lt_succ_iff) _ ≤ ∑ i ∈ range N, (i + 1) * ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by apply sum_le_sum fun i _ => ?_ simp only [Nat.cast_add, Nat.cast_one, sum_const, card_range, nsmul_eq_mul, Nat.cast_min] refine mul_le_mul_of_nonneg_right (min_le_left _ _) ?_ apply intervalIntegral.integral_nonneg · simp only [le_add_iff_nonneg_right, zero_le_one] · simp only [zero_le_one, imp_true_iff] _ ≤ ∑ i ∈ range N, ∫ x in i..(i + 1 : ℕ), x + 1 ∂ρ := by apply sum_le_sum fun i _ => ?_ have I : (i : ℝ) ≤ (i + 1 : ℕ) := by simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one] simp_rw [intervalIntegral.integral_of_le I, ← integral_mul_left] apply setIntegral_mono_on · exact continuous_const.integrableOn_Ioc · exact (continuous_id.add continuous_const).integrableOn_Ioc · exact measurableSet_Ioc · intro x hx simp only [Nat.cast_add, Nat.cast_one, Set.mem_Ioc] at hx simp [hx.1.le] _ = ∫ x in (0)..N, x + 1 ∂ρ := by rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_] · norm_cast · exact (continuous_id.add continuous_const).intervalIntegrable _ _ _ = ∫ x in (0)..N, x ∂ρ + ∫ x in (0)..N, 1 ∂ρ := by rw [intervalIntegral.integral_add] · exact continuous_id.intervalIntegrable _ _ · exact continuous_const.intervalIntegrable _ _ _ = 𝔼[truncation X N] + ∫ x in (0)..N, 1 ∂ρ := by rw [integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg] _ ≤ 𝔼[X] + ∫ x in (0)..N, 1 ∂ρ := (add_le_add_right (integral_truncation_le_integral_of_nonneg hint hnonneg) _) _ ≤ 𝔼[X] + 1 := by refine add_le_add le_rfl ?_ rw [intervalIntegral.integral_of_le (Nat.cast_nonneg _)] simp only [integral_const, Measure.restrict_apply', measurableSet_Ioc, Set.univ_inter, Algebra.id.smul_eq_mul, mul_one] rw [← ENNReal.one_toReal] exact ENNReal.toReal_mono ENNReal.one_ne_top prob_le_one have B : ∀ a b, ℙ {ω | X ω ∈ Set.Ioc a b} = ENNReal.ofReal (∫ _ in Set.Ioc a b, (1 : ℝ) ∂ρ) := by intro a b rw [ofReal_setIntegral_one ρ _, Measure.map_apply_of_aemeasurable hint.aemeasurable measurableSet_Ioc] rfl calc ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N} = ∑ j ∈ range K, ENNReal.ofReal (∫ _ in Set.Ioc (j : ℝ) N, (1 : ℝ) ∂ρ) := by simp_rw [B] _ = ENNReal.ofReal (∑ j ∈ range K, ∫ _ in Set.Ioc (j : ℝ) N, (1 : ℝ) ∂ρ) := by rw [ENNReal.ofReal_sum_of_nonneg] simp only [integral_const, Algebra.id.smul_eq_mul, mul_one, ENNReal.toReal_nonneg, imp_true_iff] _ = ENNReal.ofReal (∑ j ∈ range K, ∫ _ in (j : ℝ)..N, (1 : ℝ) ∂ρ) := by congr 1 refine sum_congr rfl fun j hj => ?_ rw [intervalIntegral.integral_of_le (Nat.cast_le.2 ((mem_range.1 hj).le.trans hKN))] _ ≤ ENNReal.ofReal (𝔼[X] + 1) := ENNReal.ofReal_le_ofReal A #align probability_theory.sum_prob_mem_Ioc_le ProbabilityTheory.sum_prob_mem_Ioc_le theorem tsum_prob_mem_Ioi_lt_top {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) : (∑' j : ℕ, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)}) < ∞ := by suffices ∀ K : ℕ, ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)} ≤ ENNReal.ofReal (𝔼[X] + 1) from (le_of_tendsto_of_tendsto (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds (eventually_of_forall this)).trans_lt ENNReal.ofReal_lt_top intro K have A : Tendsto (fun N : ℕ => ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N}) atTop (𝓝 (∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)})) := by refine tendsto_finset_sum _ fun i _ => ?_ have : {ω | X ω ∈ Set.Ioi (i : ℝ)} = ⋃ N : ℕ, {ω | X ω ∈ Set.Ioc (i : ℝ) N} := by apply Set.Subset.antisymm _ _ · intro ω hω obtain ⟨N, hN⟩ : ∃ N : ℕ, X ω ≤ N := exists_nat_ge (X ω) exact Set.mem_iUnion.2 ⟨N, hω, hN⟩ · simp (config := {contextual := true}) only [Set.mem_Ioc, Set.mem_Ioi, Set.iUnion_subset_iff, Set.setOf_subset_setOf, imp_true_iff] rw [this] apply tendsto_measure_iUnion intro m n hmn x hx exact ⟨hx.1, hx.2.trans (Nat.cast_le.2 hmn)⟩ apply le_of_tendsto_of_tendsto A tendsto_const_nhds filter_upwards [Ici_mem_atTop K] with N hN exact sum_prob_mem_Ioc_le hint hnonneg hN #align probability_theory.tsum_prob_mem_Ioi_lt_top ProbabilityTheory.tsum_prob_mem_Ioi_lt_top theorem sum_variance_truncation_le {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) (K : ℕ) : ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[truncation X j ^ 2] ≤ 2 * 𝔼[X] := by set Y := fun n : ℕ => truncation X n let ρ : Measure ℝ := Measure.map X ℙ have Y2 : ∀ n, 𝔼[Y n ^ 2] = ∫ x in (0)..n, x ^ 2 ∂ρ := by intro n change 𝔼[fun x => Y n x ^ 2] = _ rw [moment_truncation_eq_intervalIntegral_of_nonneg hint.1 two_ne_zero hnonneg] calc ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[Y j ^ 2] = ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * ∫ x in (0)..j, x ^ 2 ∂ρ := by simp_rw [Y2] _ = ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * ∑ k ∈ range j, ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by congr 1 with j congr 1 rw [intervalIntegral.sum_integral_adjacent_intervals] · norm_cast intro k _ exact (continuous_id.pow _).intervalIntegrable _ _ _ = ∑ k ∈ range K, (∑ j ∈ Ioo k K, ((j : ℝ) ^ 2)⁻¹) * ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by simp_rw [mul_sum, sum_mul, sum_sigma'] refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ <;> aesop (add unsafe lt_trans) _ ≤ ∑ k ∈ range K, 2 / (k + 1 : ℝ) * ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by apply sum_le_sum fun k _ => ?_ refine mul_le_mul_of_nonneg_right (sum_Ioo_inv_sq_le _ _) ?_ refine intervalIntegral.integral_nonneg_of_forall ?_ fun u => sq_nonneg _ simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one] _ ≤ ∑ k ∈ range K, ∫ x in k..(k + 1 : ℕ), 2 * x ∂ρ := by apply sum_le_sum fun k _ => ?_ have Ik : (k : ℝ) ≤ (k + 1 : ℕ) := by simp rw [← intervalIntegral.integral_const_mul, intervalIntegral.integral_of_le Ik, intervalIntegral.integral_of_le Ik] refine setIntegral_mono_on ?_ ?_ measurableSet_Ioc fun x hx => ?_ · apply Continuous.integrableOn_Ioc exact continuous_const.mul (continuous_pow 2) · apply Continuous.integrableOn_Ioc exact continuous_const.mul continuous_id' · calc ↑2 / (↑k + ↑1) * x ^ 2 = x / (k + 1) * (2 * x) := by ring _ ≤ 1 * (2 * x) := (mul_le_mul_of_nonneg_right (by convert (div_le_one _).2 hx.2 · norm_cast simp only [Nat.cast_add, Nat.cast_one] linarith only [show (0 : ℝ) ≤ k from Nat.cast_nonneg k]) (mul_nonneg zero_le_two ((Nat.cast_nonneg k).trans hx.1.le))) _ = 2 * x := by rw [one_mul] _ = 2 * ∫ x in (0 : ℝ)..K, x ∂ρ := by rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_] swap; · exact (continuous_const.mul continuous_id').intervalIntegrable _ _ rw [intervalIntegral.integral_const_mul] norm_cast _ ≤ 2 * 𝔼[X] := mul_le_mul_of_nonneg_left (by rw [← integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg] exact integral_truncation_le_integral_of_nonneg hint hnonneg) zero_le_two #align probability_theory.sum_variance_truncation_le ProbabilityTheory.sum_variance_truncation_le end MomentEstimates /-! Proof of the strong law of large numbers (almost sure version, assuming only pairwise independence) for nonnegative random variables, following Etemadi's proof. -/ section StrongLawNonneg variable (X : ℕ → Ω → ℝ) (hint : Integrable (X 0)) (hindep : Pairwise fun i j => IndepFun (X i) (X j)) (hident : ∀ i, IdentDistrib (X i) (X 0)) (hnonneg : ∀ i ω, 0 ≤ X i ω) /-- The truncation of `Xᵢ` up to `i` satisfies the strong law of large numbers (with respect to the truncated expectation) along the sequence `c^n`, for any `c > 1`, up to a given `ε > 0`. This follows from a variance control. -/ theorem strong_law_aux1 {c : ℝ} (c_one : 1 < c) {ε : ℝ} (εpos : 0 < ε) : ∀ᵐ ω, ∀ᶠ n : ℕ in atTop, |∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i ω - 𝔼[∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i]| < ε * ⌊c ^ n⌋₊ := by /- Let `S n = ∑ i ∈ range n, Y i` where `Y i = truncation (X i) i`. We should show that `|S k - 𝔼[S k]| / k ≤ ε` along the sequence of powers of `c`. For this, we apply Borel-Cantelli: it suffices to show that the converse probabilites are summable. From Chebyshev inequality, this will follow from a variance control `∑' Var[S (c^i)] / (c^i)^2 < ∞`. This is checked in `I2` using pairwise independence to expand the variance of the sum as the sum of the variances, and then a straightforward but tedious computation (essentially boiling down to the fact that the sum of `1/(c ^ i)^2` beyong a threshold `j` is comparable to `1/j^2`). Note that we have written `c^i` in the above proof sketch, but rigorously one should put integer parts everywhere, making things more painful. We write `u i = ⌊c^i⌋₊` for brevity. -/ have c_pos : 0 < c := zero_lt_one.trans c_one have hX : ∀ i, AEStronglyMeasurable (X i) ℙ := fun i => (hident i).symm.aestronglyMeasurable_snd hint.1 have A : ∀ i, StronglyMeasurable (indicator (Set.Ioc (-i : ℝ) i) id) := fun i => stronglyMeasurable_id.indicator measurableSet_Ioc set Y := fun n : ℕ => truncation (X n) n set S := fun n => ∑ i ∈ range n, Y i with hS let u : ℕ → ℕ := fun n => ⌊c ^ n⌋₊ have u_mono : Monotone u := fun i j hij => Nat.floor_mono (pow_le_pow_right c_one.le hij) have I1 : ∀ K, ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * Var[Y j] ≤ 2 * 𝔼[X 0] := by intro K calc ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * Var[Y j] ≤ ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[truncation (X 0) j ^ 2] := by apply sum_le_sum fun j _ => ?_ refine mul_le_mul_of_nonneg_left ?_ (inv_nonneg.2 (sq_nonneg _)) rw [(hident j).truncation.variance_eq] exact variance_le_expectation_sq (hX 0).truncation _ ≤ 2 * 𝔼[X 0] := sum_variance_truncation_le hint (hnonneg 0) K let C := c ^ 5 * (c - 1)⁻¹ ^ 3 * (2 * 𝔼[X 0]) have I2 : ∀ N, ∑ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * Var[S (u i)] ≤ C := by intro N calc ∑ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * Var[S (u i)] = ∑ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * ∑ j ∈ range (u i), Var[Y j] := by congr 1 with i congr 1 rw [hS, IndepFun.variance_sum] · intro j _ exact (hident j).aestronglyMeasurable_fst.memℒp_truncation · intro k _ l _ hkl exact (hindep hkl).comp (A k).measurable (A l).measurable _ = ∑ j ∈ range (u (N - 1)), (∑ i ∈ (range N).filter fun i => j < u i, ((u i : ℝ) ^ 2)⁻¹) * Var[Y j] := by simp_rw [mul_sum, sum_mul, sum_sigma'] refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ · simp only [mem_sigma, mem_range, filter_congr_decidable, mem_filter, and_imp, Sigma.forall] exact fun a b haN hb ↦ ⟨hb.trans_le <| u_mono <| Nat.le_pred_of_lt haN, haN, hb⟩ all_goals aesop _ ≤ ∑ j ∈ range (u (N - 1)), c ^ 5 * (c - 1)⁻¹ ^ 3 / ↑j ^ 2 * Var[Y j] := by apply sum_le_sum fun j hj => ?_ rcases @eq_zero_or_pos _ _ j with (rfl | hj) · simp only [Nat.cast_zero, zero_pow, Ne, bit0_eq_zero, Nat.one_ne_zero, not_false_iff, div_zero, zero_mul] simp only [Y, Nat.cast_zero, truncation_zero, variance_zero, mul_zero, le_rfl] apply mul_le_mul_of_nonneg_right _ (variance_nonneg _ _) convert sum_div_nat_floor_pow_sq_le_div_sq N (Nat.cast_pos.2 hj) c_one using 2 · simp only [Nat.cast_lt] · simp only [one_div] _ = c ^ 5 * (c - 1)⁻¹ ^ 3 * ∑ j ∈ range (u (N - 1)), ((j : ℝ) ^ 2)⁻¹ * Var[Y j] := by simp_rw [mul_sum, div_eq_mul_inv, mul_assoc] _ ≤ c ^ 5 * (c - 1)⁻¹ ^ 3 * (2 * 𝔼[X 0]) := by apply mul_le_mul_of_nonneg_left (I1 _) apply mul_nonneg (pow_nonneg c_pos.le _) exact pow_nonneg (inv_nonneg.2 (sub_nonneg.2 c_one.le)) _ have I3 : ∀ N, ∑ i ∈ range N, ℙ {ω | (u i * ε : ℝ) ≤ |S (u i) ω - 𝔼[S (u i)]|} ≤ ENNReal.ofReal (ε⁻¹ ^ 2 * C) := by intro N calc ∑ i ∈ range N, ℙ {ω | (u i * ε : ℝ) ≤ |S (u i) ω - 𝔼[S (u i)]|} ≤ ∑ i ∈ range N, ENNReal.ofReal (Var[S (u i)] / (u i * ε) ^ 2) := by refine sum_le_sum fun i _ => ?_ apply meas_ge_le_variance_div_sq · exact memℒp_finset_sum' _ fun j _ => (hident j).aestronglyMeasurable_fst.memℒp_truncation · apply mul_pos (Nat.cast_pos.2 _) εpos refine zero_lt_one.trans_le ?_ apply Nat.le_floor rw [Nat.cast_one] apply one_le_pow_of_one_le c_one.le _ = ENNReal.ofReal (∑ i ∈ range N, Var[S (u i)] / (u i * ε) ^ 2) := by rw [ENNReal.ofReal_sum_of_nonneg fun i _ => ?_] exact div_nonneg (variance_nonneg _ _) (sq_nonneg _) _ ≤ ENNReal.ofReal (ε⁻¹ ^ 2 * C) := by apply ENNReal.ofReal_le_ofReal -- Porting note: do most of the rewrites under `conv` so as not to expand `variance` conv_lhs => enter [2, i] rw [div_eq_inv_mul, ← inv_pow, mul_inv, mul_comm _ ε⁻¹, mul_pow, mul_assoc] rw [← mul_sum] refine mul_le_mul_of_nonneg_left ?_ (sq_nonneg _) conv_lhs => enter [2, i]; rw [inv_pow] exact I2 N have I4 : (∑' i, ℙ {ω | (u i * ε : ℝ) ≤ |S (u i) ω - 𝔼[S (u i)]|}) < ∞ := (le_of_tendsto_of_tendsto' (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds I3).trans_lt ENNReal.ofReal_lt_top filter_upwards [ae_eventually_not_mem I4.ne] with ω hω simp_rw [S, not_le, mul_comm, sum_apply] at hω convert hω; simp only [sum_apply] #align probability_theory.strong_law_aux1 ProbabilityTheory.strong_law_aux1 /- The truncation of `Xᵢ` up to `i` satisfies the strong law of large numbers (with respect to the truncated expectation) along the sequence `c^n`, for any `c > 1`. This follows from `strong_law_aux1` by varying `ε`. -/ theorem strong_law_aux2 {c : ℝ} (c_one : 1 < c) : ∀ᵐ ω, (fun n : ℕ => ∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i ω - 𝔼[∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i]) =o[atTop] fun n : ℕ => (⌊c ^ n⌋₊ : ℝ) := by obtain ⟨v, -, v_pos, v_lim⟩ : ∃ v : ℕ → ℝ, StrictAnti v ∧ (∀ n : ℕ, 0 < v n) ∧ Tendsto v atTop (𝓝 0) := exists_seq_strictAnti_tendsto (0 : ℝ) have := fun i => strong_law_aux1 X hint hindep hident hnonneg c_one (v_pos i) filter_upwards [ae_all_iff.2 this] with ω hω apply Asymptotics.isLittleO_iff.2 fun ε εpos => ?_ obtain ⟨i, hi⟩ : ∃ i, v i < ε := ((tendsto_order.1 v_lim).2 ε εpos).exists filter_upwards [hω i] with n hn simp only [Real.norm_eq_abs, abs_abs, Nat.abs_cast] exact hn.le.trans (mul_le_mul_of_nonneg_right hi.le (Nat.cast_nonneg _)) #align probability_theory.strong_law_aux2 ProbabilityTheory.strong_law_aux2 /-- The expectation of the truncated version of `Xᵢ` behaves asymptotically like the whole expectation. This follows from convergence and Cesàro averaging. -/ theorem strong_law_aux3 : (fun n => 𝔼[∑ i ∈ range n, truncation (X i) i] - n * 𝔼[X 0]) =o[atTop] ((↑) : ℕ → ℝ) := by have A : Tendsto (fun i => 𝔼[truncation (X i) i]) atTop (𝓝 𝔼[X 0]) := by convert (tendsto_integral_truncation hint).comp tendsto_natCast_atTop_atTop using 1 ext i exact (hident i).truncation.integral_eq convert Asymptotics.isLittleO_sum_range_of_tendsto_zero (tendsto_sub_nhds_zero_iff.2 A) using 1 ext1 n simp only [sum_sub_distrib, sum_const, card_range, nsmul_eq_mul, sum_apply, sub_left_inj] rw [integral_finset_sum _ fun i _ => ?_] exact ((hident i).symm.integrable_snd hint).1.integrable_truncation #align probability_theory.strong_law_aux3 ProbabilityTheory.strong_law_aux3 /- The truncation of `Xᵢ` up to `i` satisfies the strong law of large numbers (with respect to the original expectation) along the sequence `c^n`, for any `c > 1`. This follows from the version from the truncated expectation, and the fact that the truncated and the original expectations have the same asymptotic behavior. -/ theorem strong_law_aux4 {c : ℝ} (c_one : 1 < c) : ∀ᵐ ω, (fun n : ℕ => ∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i ω - ⌊c ^ n⌋₊ * 𝔼[X 0]) =o[atTop] fun n : ℕ => (⌊c ^ n⌋₊ : ℝ) := by filter_upwards [strong_law_aux2 X hint hindep hident hnonneg c_one] with ω hω have A : Tendsto (fun n : ℕ => ⌊c ^ n⌋₊) atTop atTop := tendsto_nat_floor_atTop.comp (tendsto_pow_atTop_atTop_of_one_lt c_one) convert hω.add ((strong_law_aux3 X hint hident).comp_tendsto A) using 1 ext1 n simp #align probability_theory.strong_law_aux4 ProbabilityTheory.strong_law_aux4 /-- The truncated and non-truncated versions of `Xᵢ` have the same asymptotic behavior, as they almost surely coincide at all but finitely many steps. This follows from a probability computation and Borel-Cantelli. -/ theorem strong_law_aux5 : ∀ᵐ ω, (fun n : ℕ => ∑ i ∈ range n, truncation (X i) i ω - ∑ i ∈ range n, X i ω) =o[atTop] fun n : ℕ => (n : ℝ) := by have A : (∑' j : ℕ, ℙ {ω | X j ω ∈ Set.Ioi (j : ℝ)}) < ∞ := by convert tsum_prob_mem_Ioi_lt_top hint (hnonneg 0) using 2 ext1 j exact (hident j).measure_mem_eq measurableSet_Ioi have B : ∀ᵐ ω, Tendsto (fun n : ℕ => truncation (X n) n ω - X n ω) atTop (𝓝 0) := by filter_upwards [ae_eventually_not_mem A.ne] with ω hω apply tendsto_const_nhds.congr' _ filter_upwards [hω, Ioi_mem_atTop 0] with n hn npos simp only [truncation, indicator, Set.mem_Ioc, id, Function.comp_apply] split_ifs with h · exact (sub_self _).symm · have : -(n : ℝ) < X n ω := by apply lt_of_lt_of_le _ (hnonneg n ω) simpa only [Right.neg_neg_iff, Nat.cast_pos] using npos simp only [this, true_and_iff, not_le] at h exact (hn h).elim filter_upwards [B] with ω hω convert isLittleO_sum_range_of_tendsto_zero hω using 1 ext n rw [sum_sub_distrib] #align probability_theory.strong_law_aux5 ProbabilityTheory.strong_law_aux5 /- `Xᵢ` satisfies the strong law of large numbers along the sequence `c^n`, for any `c > 1`. This follows from the version for the truncated `Xᵢ`, and the fact that `Xᵢ` and its truncated version have the same asymptotic behavior. -/ theorem strong_law_aux6 {c : ℝ} (c_one : 1 < c) : ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range ⌊c ^ n⌋₊, X i ω) / ⌊c ^ n⌋₊) atTop (𝓝 𝔼[X 0]) := by have H : ∀ n : ℕ, (0 : ℝ) < ⌊c ^ n⌋₊ := by intro n refine zero_lt_one.trans_le ?_ simp only [Nat.one_le_cast, Nat.one_le_floor_iff, one_le_pow_of_one_le c_one.le n] filter_upwards [strong_law_aux4 X hint hindep hident hnonneg c_one, strong_law_aux5 X hint hident hnonneg] with ω hω h'ω rw [← tendsto_sub_nhds_zero_iff, ← Asymptotics.isLittleO_one_iff ℝ] have L : (fun n : ℕ => ∑ i ∈ range ⌊c ^ n⌋₊, X i ω - ⌊c ^ n⌋₊ * 𝔼[X 0]) =o[atTop] fun n => (⌊c ^ n⌋₊ : ℝ) := by have A : Tendsto (fun n : ℕ => ⌊c ^ n⌋₊) atTop atTop := tendsto_nat_floor_atTop.comp (tendsto_pow_atTop_atTop_of_one_lt c_one) convert hω.sub (h'ω.comp_tendsto A) using 1 ext1 n simp only [Function.comp_apply, sub_sub_sub_cancel_left] convert L.mul_isBigO (isBigO_refl (fun n : ℕ => (⌊c ^ n⌋₊ : ℝ)⁻¹) atTop) using 1 <;> (ext1 n; field_simp [(H n).ne']) #align probability_theory.strong_law_aux6 ProbabilityTheory.strong_law_aux6 /-- `Xᵢ` satisfies the strong law of large numbers along all integers. This follows from the corresponding fact along the sequences `c^n`, and the fact that any integer can be sandwiched between `c^n` and `c^(n+1)` with comparably small error if `c` is close enough to `1` (which is formalized in `tendsto_div_of_monotone_of_tendsto_div_floor_pow`). -/ theorem strong_law_aux7 : ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range n, X i ω) / n) atTop (𝓝 𝔼[X 0]) := by obtain ⟨c, -, cone, clim⟩ : ∃ c : ℕ → ℝ, StrictAnti c ∧ (∀ n : ℕ, 1 < c n) ∧ Tendsto c atTop (𝓝 1) := exists_seq_strictAnti_tendsto (1 : ℝ) have : ∀ k, ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range ⌊c k ^ n⌋₊, X i ω) / ⌊c k ^ n⌋₊) atTop (𝓝 𝔼[X 0]) := fun k => strong_law_aux6 X hint hindep hident hnonneg (cone k) filter_upwards [ae_all_iff.2 this] with ω hω apply tendsto_div_of_monotone_of_tendsto_div_floor_pow _ _ _ c cone clim _ · intro m n hmn exact sum_le_sum_of_subset_of_nonneg (range_mono hmn) fun i _ _ => hnonneg i ω · exact hω #align probability_theory.strong_law_aux7 ProbabilityTheory.strong_law_aux7 end StrongLawNonneg /-- **Strong law of large numbers**, almost sure version: if `X n` is a sequence of independent identically distributed integrable real-valued random variables, then `∑ i ∈ range n, X i / n` converges almost surely to `𝔼[X 0]`. We give here the strong version, due to Etemadi, that only requires pairwise independence. Superseded by `strong_law_ae`, which works for random variables taking values in any Banach space. -/ theorem strong_law_ae_real (X : ℕ → Ω → ℝ) (hint : Integrable (X 0)) (hindep : Pairwise fun i j => IndepFun (X i) (X j)) (hident : ∀ i, IdentDistrib (X i) (X 0)) : ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range n, X i ω) / n) atTop (𝓝 𝔼[X 0]) := by let pos : ℝ → ℝ := fun x => max x 0 let neg : ℝ → ℝ := fun x => max (-x) 0 have posm : Measurable pos := measurable_id'.max measurable_const have negm : Measurable neg := measurable_id'.neg.max measurable_const have A: ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range n, (pos ∘ X i) ω) / n) atTop (𝓝 𝔼[pos ∘ X 0]) := strong_law_aux7 _ hint.pos_part (fun i j hij => (hindep hij).comp posm posm) (fun i => (hident i).comp posm) fun i ω => le_max_right _ _ have B: ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range n, (neg ∘ X i) ω) / n) atTop (𝓝 𝔼[neg ∘ X 0]) := strong_law_aux7 _ hint.neg_part (fun i j hij => (hindep hij).comp negm negm) (fun i => (hident i).comp negm) fun i ω => le_max_right _ _ filter_upwards [A, B] with ω hωpos hωneg convert hωpos.sub hωneg using 1 · simp only [pos, neg, ← sub_div, ← sum_sub_distrib, max_zero_sub_max_neg_zero_eq_self, Function.comp_apply] · simp only [← integral_sub hint.pos_part hint.neg_part, max_zero_sub_max_neg_zero_eq_self, Function.comp_apply] #align probability_theory.strong_law_ae ProbabilityTheory.strong_law_ae_real end StrongLawAeReal section StrongLawVectorSpace variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] [MeasurableSpace E] [BorelSpace E] open Set TopologicalSpace /-- Preliminary lemma for the strong law of large numbers for vector-valued random variables: the composition of the random variables with a simple function satisfies the strong law of large numbers. -/ lemma strong_law_ae_simpleFunc_comp (X : ℕ → Ω → E) (h' : Measurable (X 0)) (hindep : Pairwise (fun i j ↦ IndepFun (X i) (X j))) (hident : ∀ i, IdentDistrib (X i) (X 0)) (φ : SimpleFunc E E) : ∀ᵐ ω, Tendsto (fun n : ℕ ↦ (n : ℝ) ⁻¹ • (∑ i ∈ range n, φ (X i ω))) atTop (𝓝 𝔼[φ ∘ (X 0)]) := by -- this follows from the one-dimensional version when `φ` takes a single value, and is then -- extended to the general case by linearity. classical refine SimpleFunc.induction (P := fun ψ ↦ ∀ᵐ ω, Tendsto (fun n : ℕ ↦ (n : ℝ) ⁻¹ • (∑ i ∈ range n, ψ (X i ω))) atTop (𝓝 𝔼[ψ ∘ (X 0)])) ?_ ?_ φ · intro c s hs simp only [SimpleFunc.const_zero, SimpleFunc.coe_piecewise, SimpleFunc.coe_const, SimpleFunc.coe_zero, piecewise_eq_indicator, Function.comp_apply] let F : E → ℝ := indicator s 1 have F_meas : Measurable F := (measurable_indicator_const_iff 1).2 hs let Y : ℕ → Ω → ℝ := fun n ↦ F ∘ (X n) have : ∀ᵐ (ω : Ω), Tendsto (fun (n : ℕ) ↦ (n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, Y i ω) atTop (𝓝 𝔼[Y 0]) := by simp only [Function.const_one, smul_eq_mul, ← div_eq_inv_mul] apply strong_law_ae_real · exact SimpleFunc.integrable_of_isFiniteMeasure ((SimpleFunc.piecewise s hs (SimpleFunc.const _ (1 : ℝ)) (SimpleFunc.const _ (0 : ℝ))).comp (X 0) h') · exact fun i j hij ↦ IndepFun.comp (hindep hij) F_meas F_meas · exact fun i ↦ (hident i).comp F_meas filter_upwards [this] with ω hω have I : indicator s (Function.const E c) = (fun x ↦ (indicator s (1 : E → ℝ) x) • c) := by ext rw [← indicator_smul_const_apply] congr! 1 ext simp simp only [I, integral_smul_const] convert Tendsto.smul_const hω c using 1 simp [Y, ← sum_smul, smul_smul] · rintro φ ψ - hφ hψ filter_upwards [hφ, hψ] with ω hωφ hωψ convert hωφ.add hωψ using 1 · simp [sum_add_distrib] · congr 1 rw [← integral_add] · rfl · exact (φ.comp (X 0) h').integrable_of_isFiniteMeasure · exact (ψ.comp (X 0) h').integrable_of_isFiniteMeasure /-- Preliminary lemma for the strong law of large numbers for vector-valued random variables, assuming measurability in addition to integrability. This is weakened to ae measurability in the full version `ProbabilityTheory.strong_law_ae`. -/ lemma strong_law_ae_of_measurable (X : ℕ → Ω → E) (hint : Integrable (X 0)) (h' : StronglyMeasurable (X 0)) (hindep : Pairwise (fun i j ↦ IndepFun (X i) (X j))) (hident : ∀ i, IdentDistrib (X i) (X 0)) : ∀ᵐ ω, Tendsto (fun n : ℕ ↦ (n : ℝ) ⁻¹ • (∑ i ∈ range n, X i ω)) atTop (𝓝 𝔼[X 0]) := by /- Choose a simple function `φ` such that `φ (X 0)` approximates well enough `X 0` -- this is possible as `X 0` is strongly measurable. Then `φ (X n)` approximates well `X n`. Then the strong law for `φ (X n)` implies the strong law for `X n`, up to a small error controlled by `n⁻¹ ∑_{i=0}^{n-1} ‖X i - φ (X i)‖`. This one is also controlled thanks to the one-dimensional law of large numbers: it converges ae to `𝔼[‖X 0 - φ (X 0)‖]`, which is arbitrarily small for well chosen `φ`. -/ let s : Set E := Set.range (X 0) ∪ {0} have zero_s : 0 ∈ s := by simp [s] have : SeparableSpace s := h'.separableSpace_range_union_singleton have : Nonempty s := ⟨0, zero_s⟩ -- sequence of approximating simple functions. let φ : ℕ → SimpleFunc E E := SimpleFunc.nearestPt (fun k => Nat.casesOn k 0 ((↑) ∘ denseSeq s) : ℕ → E) let Y : ℕ → ℕ → Ω → E := fun k i ↦ (φ k) ∘ (X i) -- strong law for `φ (X n)` have A : ∀ᵐ ω, ∀ k, Tendsto (fun n : ℕ ↦ (n : ℝ) ⁻¹ • (∑ i ∈ range n, Y k i ω)) atTop (𝓝 𝔼[Y k 0]) := ae_all_iff.2 (fun k ↦ strong_law_ae_simpleFunc_comp X h'.measurable hindep hident (φ k)) -- strong law for the error `‖X i - φ (X i)‖` have B : ∀ᵐ ω, ∀ k, Tendsto (fun n : ℕ ↦ (∑ i ∈ range n, ‖(X i - Y k i) ω‖) / n) atTop (𝓝 𝔼[(fun ω ↦ ‖(X 0 - Y k 0) ω‖)]) := by apply ae_all_iff.2 (fun k ↦ ?_) let G : ℕ → E → ℝ := fun k x ↦ ‖x - φ k x‖ have G_meas : ∀ k, Measurable (G k) := fun k ↦ (measurable_id.sub_stronglyMeasurable (φ k).stronglyMeasurable).norm have I : ∀ k i, (fun ω ↦ ‖(X i - Y k i) ω‖) = (G k) ∘ (X i) := fun k i ↦ rfl apply strong_law_ae_real (fun i ω ↦ ‖(X i - Y k i) ω‖) · exact (hint.sub ((φ k).comp (X 0) h'.measurable).integrable_of_isFiniteMeasure).norm · simp_rw [I] intro i j hij exact (hindep hij).comp (G_meas k) (G_meas k) · intro i simp_rw [I] apply (hident i).comp (G_meas k) -- check that, when both convergences above hold, then the strong law is satisfied filter_upwards [A, B] with ω hω h'ω rw [tendsto_iff_norm_sub_tendsto_zero, tendsto_order] refine ⟨fun c hc ↦ eventually_of_forall (fun n ↦ hc.trans_le (norm_nonneg _)), ?_⟩ -- start with some positive `ε` (the desired precision), and fix `δ` with `3 δ < ε`. intro ε (εpos : 0 < ε) obtain ⟨δ, δpos, hδ⟩ : ∃ δ, 0 < δ ∧ δ + δ + δ < ε := ⟨ε/4, by positivity, by linarith⟩ -- choose `k` large enough so that `φₖ (X 0)` approximates well enough `X 0`, up to the -- precision `δ`. obtain ⟨k, hk⟩ : ∃ k, ∫ ω, ‖(X 0 - Y k 0) ω‖ < δ := by simp_rw [Pi.sub_apply, norm_sub_rev (X 0 _)] exact ((tendsto_order.1 (tendsto_integral_norm_approxOn_sub h'.measurable hint)).2 δ δpos).exists have : ‖𝔼[Y k 0] - 𝔼[X 0]‖ < δ := by rw [norm_sub_rev, ← integral_sub hint] · exact (norm_integral_le_integral_norm _).trans_lt hk · exact ((φ k).comp (X 0) h'.measurable).integrable_of_isFiniteMeasure -- consider `n` large enough for which the above convergences have taken place within `δ`. have I : ∀ᶠ n in atTop, (∑ i ∈ range n, ‖(X i - Y k i) ω‖) / n < δ := (tendsto_order.1 (h'ω k)).2 δ hk have J : ∀ᶠ (n : ℕ) in atTop, ‖(n : ℝ) ⁻¹ • (∑ i ∈ range n, Y k i ω) - 𝔼[Y k 0]‖ < δ := by specialize hω k rw [tendsto_iff_norm_sub_tendsto_zero] at hω exact (tendsto_order.1 hω).2 δ δpos filter_upwards [I, J] with n hn h'n -- at such an `n`, the strong law is realized up to `ε`. calc ‖(n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, X i ω - 𝔼[X 0]‖ = ‖(n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, (X i ω - Y k i ω) + ((n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, Y k i ω - 𝔼[Y k 0]) + (𝔼[Y k 0] - 𝔼[X 0])‖ := by congr simp only [Function.comp_apply, sum_sub_distrib, smul_sub] abel _ ≤ ‖(n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, (X i ω - Y k i ω)‖ + ‖(n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, Y k i ω - 𝔼[Y k 0]‖ + ‖𝔼[Y k 0] - 𝔼[X 0]‖ := norm_add₃_le _ _ _ _ ≤ (∑ i ∈ Finset.range n, ‖X i ω - Y k i ω‖) / n + δ + δ := by gcongr simp only [Function.comp_apply, norm_smul, norm_inv, RCLike.norm_natCast, div_eq_inv_mul, inv_pos, Nat.cast_pos, inv_lt_zero] gcongr exact norm_sum_le _ _ _ ≤ δ + δ + δ := by gcongr exact hn.le _ < ε := hδ /-- **Strong law of large numbers**, almost sure version: if `X n` is a sequence of independent identically distributed integrable random variables taking values in a Banach space, then `n⁻¹ • ∑ i ∈ range n, X i` converges almost surely to `𝔼[X 0]`. We give here the strong version, due to Etemadi, that only requires pairwise independence. -/ theorem strong_law_ae (X : ℕ → Ω → E) (hint : Integrable (X 0)) (hindep : Pairwise (fun i j ↦ IndepFun (X i) (X j))) (hident : ∀ i, IdentDistrib (X i) (X 0)) : ∀ᵐ ω, Tendsto (fun n : ℕ ↦ (n : ℝ) ⁻¹ • (∑ i ∈ range n, X i ω)) atTop (𝓝 𝔼[X 0]) := by -- we reduce to the case of strongly measurable random variables, by using `Y i` which is strongly -- measurable and ae equal to `X i`. have A : ∀ i, Integrable (X i) := fun i ↦ (hident i).integrable_iff.2 hint let Y : ℕ → Ω → E := fun i ↦ (A i).1.mk (X i) have B : ∀ᵐ ω, ∀ n, X n ω = Y n ω := ae_all_iff.2 (fun i ↦ AEStronglyMeasurable.ae_eq_mk (A i).1) have Yint: Integrable (Y 0) := Integrable.congr hint (AEStronglyMeasurable.ae_eq_mk (A 0).1) have C : ∀ᵐ ω, Tendsto (fun n : ℕ ↦ (n : ℝ) ⁻¹ • (∑ i ∈ range n, Y i ω)) atTop (𝓝 𝔼[Y 0]) := by apply strong_law_ae_of_measurable Y Yint ((A 0).1.stronglyMeasurable_mk) (fun i j hij ↦ IndepFun.ae_eq (hindep hij) (A i).1.ae_eq_mk (A j).1.ae_eq_mk) (fun i ↦ ((A i).1.identDistrib_mk.symm.trans (hident i)).trans (A 0).1.identDistrib_mk) filter_upwards [B, C] with ω h₁ h₂ have : 𝔼[X 0] = 𝔼[Y 0] := integral_congr_ae (AEStronglyMeasurable.ae_eq_mk (A 0).1) rw [this] apply Tendsto.congr (fun n ↦ ?_) h₂ congr with i exact (h₁ i).symm end StrongLawVectorSpace section StrongLawLp variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] [MeasurableSpace E] [BorelSpace E] /-- **Strong law of large numbers**, Lᵖ version: if `X n` is a sequence of independent identically distributed random variables in Lᵖ, then `n⁻¹ • ∑ i ∈ range n, X i` converges in `Lᵖ` to `𝔼[X 0]`. -/
Mathlib/Probability/StrongLaw.lean
830
849
theorem strong_law_Lp {p : ℝ≥0∞} (hp : 1 ≤ p) (hp' : p ≠ ∞) (X : ℕ → Ω → E) (hℒp : Memℒp (X 0) p) (hindep : Pairwise fun i j => IndepFun (X i) (X j)) (hident : ∀ i, IdentDistrib (X i) (X 0)) : Tendsto (fun (n : ℕ) => snorm (fun ω => (n : ℝ) ⁻¹ • (∑ i ∈ range n, X i ω) - 𝔼[X 0]) p ℙ) atTop (𝓝 0) := by
have hmeas : ∀ i, AEStronglyMeasurable (X i) ℙ := fun i => (hident i).aestronglyMeasurable_iff.2 hℒp.1 have hint : Integrable (X 0) ℙ := hℒp.integrable hp have havg : ∀ (n : ℕ), AEStronglyMeasurable (fun ω => (n : ℝ) ⁻¹ • (∑ i ∈ range n, X i ω)) ℙ := by intro n exact AEStronglyMeasurable.const_smul (aestronglyMeasurable_sum _ fun i _ => hmeas i) _ refine tendsto_Lp_of_tendstoInMeasure hp hp' havg (memℒp_const _) ?_ (tendstoInMeasure_of_tendsto_ae havg (strong_law_ae _ hint hindep hident)) rw [(_ : (fun (n : ℕ) ω => (n : ℝ)⁻¹ • (∑ i ∈ range n, X i ω)) = fun (n : ℕ) => (n : ℝ)⁻¹ • (∑ i ∈ range n, X i))] · apply UniformIntegrable.unifIntegrable apply uniformIntegrable_average hp exact Memℒp.uniformIntegrable_of_identDistrib hp hp' hℒp hident · ext n ω simp only [Pi.smul_apply, sum_apply]
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Algebra.Group.Int import Mathlib.Data.Nat.Dist import Mathlib.Data.Ordmap.Ordnode import Mathlib.Tactic.Abel import Mathlib.Tactic.Linarith #align_import data.ordmap.ordset from "leanprover-community/mathlib"@"47b51515e69f59bca5cf34ef456e6000fe205a69" /-! # Verification of the `Ordnode α` datatype This file proves the correctness of the operations in `Data.Ordmap.Ordnode`. The public facing version is the type `Ordset α`, which is a wrapper around `Ordnode α` which includes the correctness invariant of the type, and it exposes parallel operations like `insert` as functions on `Ordset` that do the same thing but bundle the correctness proofs. The advantage is that it is possible to, for example, prove that the result of `find` on `insert` will actually find the element, while `Ordnode` cannot guarantee this if the input tree did not satisfy the type invariants. ## Main definitions * `Ordset α`: A well formed set of values of type `α` ## Implementation notes The majority of this file is actually in the `Ordnode` namespace, because we first have to prove the correctness of all the operations (and defining what correctness means here is actually somewhat subtle). So all the actual `Ordset` operations are at the very end, once we have all the theorems. An `Ordnode α` is an inductive type which describes a tree which stores the `size` at internal nodes. The correctness invariant of an `Ordnode α` is: * `Ordnode.Sized t`: All internal `size` fields must match the actual measured size of the tree. (This is not hard to satisfy.) * `Ordnode.Balanced t`: Unless the tree has the form `()` or `((a) b)` or `(a (b))` (that is, nil or a single singleton subtree), the two subtrees must satisfy `size l ≤ δ * size r` and `size r ≤ δ * size l`, where `δ := 3` is a global parameter of the data structure (and this property must hold recursively at subtrees). This is why we say this is a "size balanced tree" data structure. * `Ordnode.Bounded lo hi t`: The members of the tree must be in strictly increasing order, meaning that if `a` is in the left subtree and `b` is the root, then `a ≤ b` and `¬ (b ≤ a)`. We enforce this using `Ordnode.Bounded` which includes also a global upper and lower bound. Because the `Ordnode` file was ported from Haskell, the correctness invariants of some of the functions have not been spelled out, and some theorems like `Ordnode.Valid'.balanceL_aux` show very intricate assumptions on the sizes, which may need to be revised if it turns out some operations violate these assumptions, because there is a decent amount of slop in the actual data structure invariants, so the theorem will go through with multiple choices of assumption. **Note:** This file is incomplete, in the sense that the intent is to have verified versions and lemmas about all the definitions in `Ordnode.lean`, but at the moment only a few operations are verified (the hard part should be out of the way, but still). Contributors are encouraged to pick this up and finish the job, if it appeals to you. ## Tags ordered map, ordered set, data structure, verified programming -/ variable {α : Type*} namespace Ordnode /-! ### delta and ratio -/ theorem not_le_delta {s} (H : 1 ≤ s) : ¬s ≤ delta * 0 := not_le_of_gt H #align ordnode.not_le_delta Ordnode.not_le_delta theorem delta_lt_false {a b : ℕ} (h₁ : delta * a < b) (h₂ : delta * b < a) : False := not_le_of_lt (lt_trans ((mul_lt_mul_left (by decide)).2 h₁) h₂) <| by simpa [mul_assoc] using Nat.mul_le_mul_right a (by decide : 1 ≤ delta * delta) #align ordnode.delta_lt_false Ordnode.delta_lt_false /-! ### `singleton` -/ /-! ### `size` and `empty` -/ /-- O(n). Computes the actual number of elements in the set, ignoring the cached `size` field. -/ def realSize : Ordnode α → ℕ | nil => 0 | node _ l _ r => realSize l + realSize r + 1 #align ordnode.real_size Ordnode.realSize /-! ### `Sized` -/ /-- The `Sized` property asserts that all the `size` fields in nodes match the actual size of the respective subtrees. -/ def Sized : Ordnode α → Prop | nil => True | node s l _ r => s = size l + size r + 1 ∧ Sized l ∧ Sized r #align ordnode.sized Ordnode.Sized theorem Sized.node' {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (node' l x r) := ⟨rfl, hl, hr⟩ #align ordnode.sized.node' Ordnode.Sized.node' theorem Sized.eq_node' {s l x r} (h : @Sized α (node s l x r)) : node s l x r = .node' l x r := by rw [h.1] #align ordnode.sized.eq_node' Ordnode.Sized.eq_node' theorem Sized.size_eq {s l x r} (H : Sized (@node α s l x r)) : size (@node α s l x r) = size l + size r + 1 := H.1 #align ordnode.sized.size_eq Ordnode.Sized.size_eq @[elab_as_elim] theorem Sized.induction {t} (hl : @Sized α t) {C : Ordnode α → Prop} (H0 : C nil) (H1 : ∀ l x r, C l → C r → C (.node' l x r)) : C t := by induction t with | nil => exact H0 | node _ _ _ _ t_ih_l t_ih_r => rw [hl.eq_node'] exact H1 _ _ _ (t_ih_l hl.2.1) (t_ih_r hl.2.2) #align ordnode.sized.induction Ordnode.Sized.induction theorem size_eq_realSize : ∀ {t : Ordnode α}, Sized t → size t = realSize t | nil, _ => rfl | node s l x r, ⟨h₁, h₂, h₃⟩ => by rw [size, h₁, size_eq_realSize h₂, size_eq_realSize h₃]; rfl #align ordnode.size_eq_real_size Ordnode.size_eq_realSize @[simp] theorem Sized.size_eq_zero {t : Ordnode α} (ht : Sized t) : size t = 0 ↔ t = nil := by cases t <;> [simp;simp [ht.1]] #align ordnode.sized.size_eq_zero Ordnode.Sized.size_eq_zero theorem Sized.pos {s l x r} (h : Sized (@node α s l x r)) : 0 < s := by rw [h.1]; apply Nat.le_add_left #align ordnode.sized.pos Ordnode.Sized.pos /-! `dual` -/ theorem dual_dual : ∀ t : Ordnode α, dual (dual t) = t | nil => rfl | node s l x r => by rw [dual, dual, dual_dual l, dual_dual r] #align ordnode.dual_dual Ordnode.dual_dual @[simp] theorem size_dual (t : Ordnode α) : size (dual t) = size t := by cases t <;> rfl #align ordnode.size_dual Ordnode.size_dual /-! `Balanced` -/ /-- The `BalancedSz l r` asserts that a hypothetical tree with children of sizes `l` and `r` is balanced: either `l ≤ δ * r` and `r ≤ δ * r`, or the tree is trivial with a singleton on one side and nothing on the other. -/ def BalancedSz (l r : ℕ) : Prop := l + r ≤ 1 ∨ l ≤ delta * r ∧ r ≤ delta * l #align ordnode.balanced_sz Ordnode.BalancedSz instance BalancedSz.dec : DecidableRel BalancedSz := fun _ _ => Or.decidable #align ordnode.balanced_sz.dec Ordnode.BalancedSz.dec /-- The `Balanced t` asserts that the tree `t` satisfies the balance invariants (at every level). -/ def Balanced : Ordnode α → Prop | nil => True | node _ l _ r => BalancedSz (size l) (size r) ∧ Balanced l ∧ Balanced r #align ordnode.balanced Ordnode.Balanced instance Balanced.dec : DecidablePred (@Balanced α) | nil => by unfold Balanced infer_instance | node _ l _ r => by unfold Balanced haveI := Balanced.dec l haveI := Balanced.dec r infer_instance #align ordnode.balanced.dec Ordnode.Balanced.dec @[symm] theorem BalancedSz.symm {l r : ℕ} : BalancedSz l r → BalancedSz r l := Or.imp (by rw [add_comm]; exact id) And.symm #align ordnode.balanced_sz.symm Ordnode.BalancedSz.symm theorem balancedSz_zero {l : ℕ} : BalancedSz l 0 ↔ l ≤ 1 := by simp (config := { contextual := true }) [BalancedSz] #align ordnode.balanced_sz_zero Ordnode.balancedSz_zero theorem balancedSz_up {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l) (H : BalancedSz l r₁) : BalancedSz l r₂ := by refine or_iff_not_imp_left.2 fun h => ?_ refine ⟨?_, h₂.resolve_left h⟩ cases H with | inl H => cases r₂ · cases h (le_trans (Nat.add_le_add_left (Nat.zero_le _) _) H) · exact le_trans (le_trans (Nat.le_add_right _ _) H) (Nat.le_add_left 1 _) | inr H => exact le_trans H.1 (Nat.mul_le_mul_left _ h₁) #align ordnode.balanced_sz_up Ordnode.balancedSz_up theorem balancedSz_down {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ l ≤ delta * r₁) (H : BalancedSz l r₂) : BalancedSz l r₁ := have : l + r₂ ≤ 1 → BalancedSz l r₁ := fun H => Or.inl (le_trans (Nat.add_le_add_left h₁ _) H) Or.casesOn H this fun H => Or.casesOn h₂ this fun h₂ => Or.inr ⟨h₂, le_trans h₁ H.2⟩ #align ordnode.balanced_sz_down Ordnode.balancedSz_down theorem Balanced.dual : ∀ {t : Ordnode α}, Balanced t → Balanced (dual t) | nil, _ => ⟨⟩ | node _ l _ r, ⟨b, bl, br⟩ => ⟨by rw [size_dual, size_dual]; exact b.symm, br.dual, bl.dual⟩ #align ordnode.balanced.dual Ordnode.Balanced.dual /-! ### `rotate` and `balance` -/ /-- Build a tree from three nodes, left associated (ignores the invariants). -/ def node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α := node' (node' l x m) y r #align ordnode.node3_l Ordnode.node3L /-- Build a tree from three nodes, right associated (ignores the invariants). -/ def node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α := node' l x (node' m y r) #align ordnode.node3_r Ordnode.node3R /-- Build a tree from three nodes, with `a () b -> (a ()) b` and `a (b c) d -> ((a b) (c d))`. -/ def node4L : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α | l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r) | l, x, nil, z, r => node3L l x nil z r #align ordnode.node4_l Ordnode.node4L -- should not happen /-- Build a tree from three nodes, with `a () b -> a (() b)` and `a (b c) d -> ((a b) (c d))`. -/ def node4R : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α | l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r) | l, x, nil, z, r => node3R l x nil z r #align ordnode.node4_r Ordnode.node4R -- should not happen /-- Concatenate two nodes, performing a left rotation `x (y z) -> ((x y) z)` if balance is upset. -/ def rotateL : Ordnode α → α → Ordnode α → Ordnode α | l, x, node _ m y r => if size m < ratio * size r then node3L l x m y r else node4L l x m y r | l, x, nil => node' l x nil #align ordnode.rotate_l Ordnode.rotateL -- Porting note (#11467): during the port we marked these lemmas with `@[eqns]` -- to emulate the old Lean 3 behaviour. theorem rotateL_node (l : Ordnode α) (x : α) (sz : ℕ) (m : Ordnode α) (y : α) (r : Ordnode α) : rotateL l x (node sz m y r) = if size m < ratio * size r then node3L l x m y r else node4L l x m y r := rfl theorem rotateL_nil (l : Ordnode α) (x : α) : rotateL l x nil = node' l x nil := rfl -- should not happen /-- Concatenate two nodes, performing a right rotation `(x y) z -> (x (y z))` if balance is upset. -/ def rotateR : Ordnode α → α → Ordnode α → Ordnode α | node _ l x m, y, r => if size m < ratio * size l then node3R l x m y r else node4R l x m y r | nil, y, r => node' nil y r #align ordnode.rotate_r Ordnode.rotateR -- Porting note (#11467): during the port we marked these lemmas with `@[eqns]` -- to emulate the old Lean 3 behaviour. theorem rotateR_node (sz : ℕ) (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : rotateR (node sz l x m) y r = if size m < ratio * size l then node3R l x m y r else node4R l x m y r := rfl theorem rotateR_nil (y : α) (r : Ordnode α) : rotateR nil y r = node' nil y r := rfl -- should not happen /-- A left balance operation. This will rebalance a concatenation, assuming the original nodes are not too far from balanced. -/ def balanceL' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α := if size l + size r ≤ 1 then node' l x r else if size l > delta * size r then rotateR l x r else node' l x r #align ordnode.balance_l' Ordnode.balanceL' /-- A right balance operation. This will rebalance a concatenation, assuming the original nodes are not too far from balanced. -/ def balanceR' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α := if size l + size r ≤ 1 then node' l x r else if size r > delta * size l then rotateL l x r else node' l x r #align ordnode.balance_r' Ordnode.balanceR' /-- The full balance operation. This is the same as `balance`, but with less manual inlining. It is somewhat easier to work with this version in proofs. -/ def balance' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α := if size l + size r ≤ 1 then node' l x r else if size r > delta * size l then rotateL l x r else if size l > delta * size r then rotateR l x r else node' l x r #align ordnode.balance' Ordnode.balance' theorem dual_node' (l : Ordnode α) (x : α) (r : Ordnode α) : dual (node' l x r) = node' (dual r) x (dual l) := by simp [node', add_comm] #align ordnode.dual_node' Ordnode.dual_node' theorem dual_node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node3L l x m y r) = node3R (dual r) y (dual m) x (dual l) := by simp [node3L, node3R, dual_node', add_comm] #align ordnode.dual_node3_l Ordnode.dual_node3L theorem dual_node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node3R l x m y r) = node3L (dual r) y (dual m) x (dual l) := by simp [node3L, node3R, dual_node', add_comm] #align ordnode.dual_node3_r Ordnode.dual_node3R theorem dual_node4L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node4L l x m y r) = node4R (dual r) y (dual m) x (dual l) := by cases m <;> simp [node4L, node4R, node3R, dual_node3L, dual_node', add_comm] #align ordnode.dual_node4_l Ordnode.dual_node4L theorem dual_node4R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node4R l x m y r) = node4L (dual r) y (dual m) x (dual l) := by cases m <;> simp [node4L, node4R, node3L, dual_node3R, dual_node', add_comm] #align ordnode.dual_node4_r Ordnode.dual_node4R theorem dual_rotateL (l : Ordnode α) (x : α) (r : Ordnode α) : dual (rotateL l x r) = rotateR (dual r) x (dual l) := by cases r <;> simp [rotateL, rotateR, dual_node']; split_ifs <;> simp [dual_node3L, dual_node4L, node3R, add_comm] #align ordnode.dual_rotate_l Ordnode.dual_rotateL theorem dual_rotateR (l : Ordnode α) (x : α) (r : Ordnode α) : dual (rotateR l x r) = rotateL (dual r) x (dual l) := by rw [← dual_dual (rotateL _ _ _), dual_rotateL, dual_dual, dual_dual] #align ordnode.dual_rotate_r Ordnode.dual_rotateR theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) : dual (balance' l x r) = balance' (dual r) x (dual l) := by simp [balance', add_comm]; split_ifs with h h_1 h_2 <;> simp [dual_node', dual_rotateL, dual_rotateR, add_comm] cases delta_lt_false h_1 h_2 #align ordnode.dual_balance' Ordnode.dual_balance' theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) : dual (balanceL l x r) = balanceR (dual r) x (dual l) := by unfold balanceL balanceR cases' r with rs rl rx rr · cases' l with ls ll lx lr; · rfl cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;> try rfl split_ifs with h <;> repeat simp [h, add_comm] · cases' l with ls ll lx lr; · rfl dsimp only [dual, id] split_ifs; swap; · simp [add_comm] cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> try rfl dsimp only [dual, id] split_ifs with h <;> simp [h, add_comm] #align ordnode.dual_balance_l Ordnode.dual_balanceL theorem dual_balanceR (l : Ordnode α) (x : α) (r : Ordnode α) : dual (balanceR l x r) = balanceL (dual r) x (dual l) := by rw [← dual_dual (balanceL _ _ _), dual_balanceL, dual_dual, dual_dual] #align ordnode.dual_balance_r Ordnode.dual_balanceR theorem Sized.node3L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) : Sized (node3L l x m y r) := (hl.node' hm).node' hr #align ordnode.sized.node3_l Ordnode.Sized.node3L theorem Sized.node3R {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) : Sized (node3R l x m y r) := hl.node' (hm.node' hr) #align ordnode.sized.node3_r Ordnode.Sized.node3R theorem Sized.node4L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) : Sized (node4L l x m y r) := by cases m <;> [exact (hl.node' hm).node' hr; exact (hl.node' hm.2.1).node' (hm.2.2.node' hr)] #align ordnode.sized.node4_l Ordnode.Sized.node4L theorem node3L_size {l x m y r} : size (@node3L α l x m y r) = size l + size m + size r + 2 := by dsimp [node3L, node', size]; rw [add_right_comm _ 1] #align ordnode.node3_l_size Ordnode.node3L_size theorem node3R_size {l x m y r} : size (@node3R α l x m y r) = size l + size m + size r + 2 := by dsimp [node3R, node', size]; rw [← add_assoc, ← add_assoc] #align ordnode.node3_r_size Ordnode.node3R_size theorem node4L_size {l x m y r} (hm : Sized m) : size (@node4L α l x m y r) = size l + size m + size r + 2 := by cases m <;> simp [node4L, node3L, node'] <;> [abel; (simp [size, hm.1]; abel)] #align ordnode.node4_l_size Ordnode.node4L_size theorem Sized.dual : ∀ {t : Ordnode α}, Sized t → Sized (dual t) | nil, _ => ⟨⟩ | node _ l _ r, ⟨rfl, sl, sr⟩ => ⟨by simp [size_dual, add_comm], Sized.dual sr, Sized.dual sl⟩ #align ordnode.sized.dual Ordnode.Sized.dual theorem Sized.dual_iff {t : Ordnode α} : Sized (.dual t) ↔ Sized t := ⟨fun h => by rw [← dual_dual t]; exact h.dual, Sized.dual⟩ #align ordnode.sized.dual_iff Ordnode.Sized.dual_iff
Mathlib/Data/Ordmap/Ordset.lean
412
416
theorem Sized.rotateL {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (rotateL l x r) := by
cases r; · exact hl.node' hr rw [Ordnode.rotateL_node]; split_ifs · exact hl.node3L hr.2.1 hr.2.2 · exact hl.node4L hr.2.1 hr.2.2
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.GCDMonoid.Finset import Mathlib.Algebra.Polynomial.CancelLeads import Mathlib.Algebra.Polynomial.EraseLead import Mathlib.Algebra.Polynomial.FieldDivision #align_import ring_theory.polynomial.content from "leanprover-community/mathlib"@"7a030ab8eb5d99f05a891dccc49c5b5b90c947d3" /-! # GCD structures on polynomials Definitions and basic results about polynomials over GCD domains, particularly their contents and primitive polynomials. ## Main Definitions Let `p : R[X]`. - `p.content` is the `gcd` of the coefficients of `p`. - `p.IsPrimitive` indicates that `p.content = 1`. ## Main Results - `Polynomial.content_mul`: If `p q : R[X]`, then `(p * q).content = p.content * q.content`. - `Polynomial.NormalizedGcdMonoid`: The polynomial ring of a GCD domain is itself a GCD domain. -/ namespace Polynomial open Polynomial section Primitive variable {R : Type*} [CommSemiring R] /-- A polynomial is primitive when the only constant polynomials dividing it are units -/ def IsPrimitive (p : R[X]) : Prop := ∀ r : R, C r ∣ p → IsUnit r #align polynomial.is_primitive Polynomial.IsPrimitive theorem isPrimitive_iff_isUnit_of_C_dvd {p : R[X]} : p.IsPrimitive ↔ ∀ r : R, C r ∣ p → IsUnit r := Iff.rfl set_option linter.uppercaseLean3 false in #align polynomial.is_primitive_iff_is_unit_of_C_dvd Polynomial.isPrimitive_iff_isUnit_of_C_dvd @[simp] theorem isPrimitive_one : IsPrimitive (1 : R[X]) := fun _ h => isUnit_C.mp (isUnit_of_dvd_one h) #align polynomial.is_primitive_one Polynomial.isPrimitive_one theorem Monic.isPrimitive {p : R[X]} (hp : p.Monic) : p.IsPrimitive := by rintro r ⟨q, h⟩ exact isUnit_of_mul_eq_one r (q.coeff p.natDegree) (by rwa [← coeff_C_mul, ← h]) #align polynomial.monic.is_primitive Polynomial.Monic.isPrimitive theorem IsPrimitive.ne_zero [Nontrivial R] {p : R[X]} (hp : p.IsPrimitive) : p ≠ 0 := by rintro rfl exact (hp 0 (dvd_zero (C 0))).ne_zero rfl #align polynomial.is_primitive.ne_zero Polynomial.IsPrimitive.ne_zero theorem isPrimitive_of_dvd {p q : R[X]} (hp : IsPrimitive p) (hq : q ∣ p) : IsPrimitive q := fun a ha => isPrimitive_iff_isUnit_of_C_dvd.mp hp a (dvd_trans ha hq) #align polynomial.is_primitive_of_dvd Polynomial.isPrimitive_of_dvd end Primitive variable {R : Type*} [CommRing R] [IsDomain R] section NormalizedGCDMonoid variable [NormalizedGCDMonoid R] /-- `p.content` is the `gcd` of the coefficients of `p`. -/ def content (p : R[X]) : R := p.support.gcd p.coeff #align polynomial.content Polynomial.content theorem content_dvd_coeff {p : R[X]} (n : ℕ) : p.content ∣ p.coeff n := by by_cases h : n ∈ p.support · apply Finset.gcd_dvd h rw [mem_support_iff, Classical.not_not] at h rw [h] apply dvd_zero #align polynomial.content_dvd_coeff Polynomial.content_dvd_coeff @[simp] theorem content_C {r : R} : (C r).content = normalize r := by rw [content] by_cases h0 : r = 0 · simp [h0] have h : (C r).support = {0} := support_monomial _ h0 simp [h] set_option linter.uppercaseLean3 false in #align polynomial.content_C Polynomial.content_C @[simp] theorem content_zero : content (0 : R[X]) = 0 := by rw [← C_0, content_C, normalize_zero] #align polynomial.content_zero Polynomial.content_zero @[simp] theorem content_one : content (1 : R[X]) = 1 := by rw [← C_1, content_C, normalize_one] #align polynomial.content_one Polynomial.content_one theorem content_X_mul {p : R[X]} : content (X * p) = content p := by rw [content, content, Finset.gcd_def, Finset.gcd_def] refine congr rfl ?_ have h : (X * p).support = p.support.map ⟨Nat.succ, Nat.succ_injective⟩ := by ext a simp only [exists_prop, Finset.mem_map, Function.Embedding.coeFn_mk, Ne, mem_support_iff] cases' a with a · simp [coeff_X_mul_zero, Nat.succ_ne_zero] rw [mul_comm, coeff_mul_X] constructor · intro h use a · rintro ⟨b, ⟨h1, h2⟩⟩ rw [← Nat.succ_injective h2] apply h1 rw [h] simp only [Finset.map_val, Function.comp_apply, Function.Embedding.coeFn_mk, Multiset.map_map] refine congr (congr rfl ?_) rfl ext a rw [mul_comm] simp [coeff_mul_X] set_option linter.uppercaseLean3 false in #align polynomial.content_X_mul Polynomial.content_X_mul @[simp] theorem content_X_pow {k : ℕ} : content ((X : R[X]) ^ k) = 1 := by induction' k with k hi · simp rw [pow_succ', content_X_mul, hi] set_option linter.uppercaseLean3 false in #align polynomial.content_X_pow Polynomial.content_X_pow @[simp] theorem content_X : content (X : R[X]) = 1 := by rw [← mul_one X, content_X_mul, content_one] set_option linter.uppercaseLean3 false in #align polynomial.content_X Polynomial.content_X theorem content_C_mul (r : R) (p : R[X]) : (C r * p).content = normalize r * p.content := by by_cases h0 : r = 0; · simp [h0] rw [content]; rw [content]; rw [← Finset.gcd_mul_left] refine congr (congr rfl ?_) ?_ <;> ext <;> simp [h0, mem_support_iff] set_option linter.uppercaseLean3 false in #align polynomial.content_C_mul Polynomial.content_C_mul @[simp] theorem content_monomial {r : R} {k : ℕ} : content (monomial k r) = normalize r := by rw [← C_mul_X_pow_eq_monomial, content_C_mul, content_X_pow, mul_one] #align polynomial.content_monomial Polynomial.content_monomial theorem content_eq_zero_iff {p : R[X]} : content p = 0 ↔ p = 0 := by rw [content, Finset.gcd_eq_zero_iff] constructor <;> intro h · ext n by_cases h0 : n ∈ p.support · rw [h n h0, coeff_zero] · rw [mem_support_iff] at h0 push_neg at h0 simp [h0] · intro x simp [h] #align polynomial.content_eq_zero_iff Polynomial.content_eq_zero_iff -- Porting note: this reduced with simp so created `normUnit_content` and put simp on it theorem normalize_content {p : R[X]} : normalize p.content = p.content := Finset.normalize_gcd #align polynomial.normalize_content Polynomial.normalize_content @[simp] theorem normUnit_content {p : R[X]} : normUnit (content p) = 1 := by by_cases hp0 : p.content = 0 · simp [hp0] · ext apply mul_left_cancel₀ hp0 erw [← normalize_apply, normalize_content, mul_one] theorem content_eq_gcd_range_of_lt (p : R[X]) (n : ℕ) (h : p.natDegree < n) : p.content = (Finset.range n).gcd p.coeff := by apply dvd_antisymm_of_normalize_eq normalize_content Finset.normalize_gcd · rw [Finset.dvd_gcd_iff] intro i _ apply content_dvd_coeff _ · apply Finset.gcd_mono intro i simp only [Nat.lt_succ_iff, mem_support_iff, Ne, Finset.mem_range] contrapose! intro h1 apply coeff_eq_zero_of_natDegree_lt (lt_of_lt_of_le h h1) #align polynomial.content_eq_gcd_range_of_lt Polynomial.content_eq_gcd_range_of_lt theorem content_eq_gcd_range_succ (p : R[X]) : p.content = (Finset.range p.natDegree.succ).gcd p.coeff := content_eq_gcd_range_of_lt _ _ (Nat.lt_succ_self _) #align polynomial.content_eq_gcd_range_succ Polynomial.content_eq_gcd_range_succ theorem content_eq_gcd_leadingCoeff_content_eraseLead (p : R[X]) : p.content = GCDMonoid.gcd p.leadingCoeff (eraseLead p).content := by by_cases h : p = 0 · simp [h] rw [← leadingCoeff_eq_zero, leadingCoeff, ← Ne, ← mem_support_iff] at h rw [content, ← Finset.insert_erase h, Finset.gcd_insert, leadingCoeff, content, eraseLead_support] refine congr rfl (Finset.gcd_congr rfl fun i hi => ?_) rw [Finset.mem_erase] at hi rw [eraseLead_coeff, if_neg hi.1] #align polynomial.content_eq_gcd_leading_coeff_content_erase_lead Polynomial.content_eq_gcd_leadingCoeff_content_eraseLead theorem dvd_content_iff_C_dvd {p : R[X]} {r : R} : r ∣ p.content ↔ C r ∣ p := by rw [C_dvd_iff_dvd_coeff] constructor · intro h i apply h.trans (content_dvd_coeff _) · intro h rw [content, Finset.dvd_gcd_iff] intro i _ apply h i set_option linter.uppercaseLean3 false in #align polynomial.dvd_content_iff_C_dvd Polynomial.dvd_content_iff_C_dvd theorem C_content_dvd (p : R[X]) : C p.content ∣ p := dvd_content_iff_C_dvd.1 dvd_rfl set_option linter.uppercaseLean3 false in #align polynomial.C_content_dvd Polynomial.C_content_dvd theorem isPrimitive_iff_content_eq_one {p : R[X]} : p.IsPrimitive ↔ p.content = 1 := by rw [← normalize_content, normalize_eq_one, IsPrimitive] simp_rw [← dvd_content_iff_C_dvd] exact ⟨fun h => h p.content (dvd_refl p.content), fun h r hdvd => isUnit_of_dvd_unit hdvd h⟩ #align polynomial.is_primitive_iff_content_eq_one Polynomial.isPrimitive_iff_content_eq_one theorem IsPrimitive.content_eq_one {p : R[X]} (hp : p.IsPrimitive) : p.content = 1 := isPrimitive_iff_content_eq_one.mp hp #align polynomial.is_primitive.content_eq_one Polynomial.IsPrimitive.content_eq_one section PrimPart /-- The primitive part of a polynomial `p` is the primitive polynomial gained by dividing `p` by `p.content`. If `p = 0`, then `p.primPart = 1`. -/ noncomputable def primPart (p : R[X]) : R[X] := letI := Classical.decEq R if p = 0 then 1 else Classical.choose (C_content_dvd p) #align polynomial.prim_part Polynomial.primPart theorem eq_C_content_mul_primPart (p : R[X]) : p = C p.content * p.primPart := by by_cases h : p = 0; · simp [h] rw [primPart, if_neg h, ← Classical.choose_spec (C_content_dvd p)] set_option linter.uppercaseLean3 false in #align polynomial.eq_C_content_mul_prim_part Polynomial.eq_C_content_mul_primPart @[simp] theorem primPart_zero : primPart (0 : R[X]) = 1 := if_pos rfl #align polynomial.prim_part_zero Polynomial.primPart_zero theorem isPrimitive_primPart (p : R[X]) : p.primPart.IsPrimitive := by by_cases h : p = 0; · simp [h] rw [← content_eq_zero_iff] at h rw [isPrimitive_iff_content_eq_one] apply mul_left_cancel₀ h conv_rhs => rw [p.eq_C_content_mul_primPart, mul_one, content_C_mul, normalize_content] #align polynomial.is_primitive_prim_part Polynomial.isPrimitive_primPart theorem content_primPart (p : R[X]) : p.primPart.content = 1 := p.isPrimitive_primPart.content_eq_one #align polynomial.content_prim_part Polynomial.content_primPart theorem primPart_ne_zero (p : R[X]) : p.primPart ≠ 0 := p.isPrimitive_primPart.ne_zero #align polynomial.prim_part_ne_zero Polynomial.primPart_ne_zero theorem natDegree_primPart (p : R[X]) : p.primPart.natDegree = p.natDegree := by by_cases h : C p.content = 0 · rw [C_eq_zero, content_eq_zero_iff] at h simp [h] conv_rhs => rw [p.eq_C_content_mul_primPart, natDegree_mul h p.primPart_ne_zero, natDegree_C, zero_add] #align polynomial.nat_degree_prim_part Polynomial.natDegree_primPart @[simp] theorem IsPrimitive.primPart_eq {p : R[X]} (hp : p.IsPrimitive) : p.primPart = p := by rw [← one_mul p.primPart, ← C_1, ← hp.content_eq_one, ← p.eq_C_content_mul_primPart] #align polynomial.is_primitive.prim_part_eq Polynomial.IsPrimitive.primPart_eq theorem isUnit_primPart_C (r : R) : IsUnit (C r).primPart := by by_cases h0 : r = 0 · simp [h0] unfold IsUnit refine ⟨⟨C ↑(normUnit r)⁻¹, C ↑(normUnit r), by rw [← RingHom.map_mul, Units.inv_mul, C_1], by rw [← RingHom.map_mul, Units.mul_inv, C_1]⟩, ?_⟩ rw [← normalize_eq_zero, ← C_eq_zero] at h0 apply mul_left_cancel₀ h0 conv_rhs => rw [← content_C, ← (C r).eq_C_content_mul_primPart] simp only [Units.val_mk, normalize_apply, RingHom.map_mul] rw [mul_assoc, ← RingHom.map_mul, Units.mul_inv, C_1, mul_one] set_option linter.uppercaseLean3 false in #align polynomial.is_unit_prim_part_C Polynomial.isUnit_primPart_C theorem primPart_dvd (p : R[X]) : p.primPart ∣ p := Dvd.intro_left (C p.content) p.eq_C_content_mul_primPart.symm #align polynomial.prim_part_dvd Polynomial.primPart_dvd theorem aeval_primPart_eq_zero {S : Type*} [Ring S] [IsDomain S] [Algebra R S] [NoZeroSMulDivisors R S] {p : R[X]} {s : S} (hpzero : p ≠ 0) (hp : aeval s p = 0) : aeval s p.primPart = 0 := by rw [eq_C_content_mul_primPart p, map_mul, aeval_C] at hp have hcont : p.content ≠ 0 := fun h => hpzero (content_eq_zero_iff.1 h) replace hcont := Function.Injective.ne (NoZeroSMulDivisors.algebraMap_injective R S) hcont rw [map_zero] at hcont exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp #align polynomial.aeval_prim_part_eq_zero Polynomial.aeval_primPart_eq_zero
Mathlib/RingTheory/Polynomial/Content.lean
321
328
theorem eval₂_primPart_eq_zero {S : Type*} [CommRing S] [IsDomain S] {f : R →+* S} (hinj : Function.Injective f) {p : R[X]} {s : S} (hpzero : p ≠ 0) (hp : eval₂ f s p = 0) : eval₂ f s p.primPart = 0 := by
rw [eq_C_content_mul_primPart p, eval₂_mul, eval₂_C] at hp have hcont : p.content ≠ 0 := fun h => hpzero (content_eq_zero_iff.1 h) replace hcont := Function.Injective.ne hinj hcont rw [map_zero] at hcont exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Analysis.SpecialFunctions.Complex.LogDeriv import Mathlib.Analysis.Calculus.FDeriv.Extend import Mathlib.Analysis.Calculus.Deriv.Prod import Mathlib.Analysis.SpecialFunctions.Log.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv #align_import analysis.special_functions.pow.deriv from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Derivatives of power function on `ℂ`, `ℝ`, `ℝ≥0`, and `ℝ≥0∞` We also prove differentiability and provide derivatives for the power functions `x ^ y`. -/ noncomputable section open scoped Classical Real Topology NNReal ENNReal Filter open Filter namespace Complex theorem hasStrictFDerivAt_cpow {p : ℂ × ℂ} (hp : p.1 ∈ slitPlane) : HasStrictFDerivAt (fun x : ℂ × ℂ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℂ ℂ ℂ + (p.1 ^ p.2 * log p.1) • ContinuousLinearMap.snd ℂ ℂ ℂ) p := by have A : p.1 ≠ 0 := slitPlane_ne_zero hp have : (fun x : ℂ × ℂ => x.1 ^ x.2) =ᶠ[𝓝 p] fun x => exp (log x.1 * x.2) := ((isOpen_ne.preimage continuous_fst).eventually_mem A).mono fun p hp => cpow_def_of_ne_zero hp _ rw [cpow_sub _ _ A, cpow_one, mul_div_left_comm, mul_smul, mul_smul] refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm simpa only [cpow_def_of_ne_zero A, div_eq_mul_inv, mul_smul, add_comm, smul_add] using ((hasStrictFDerivAt_fst.clog hp).mul hasStrictFDerivAt_snd).cexp #align complex.has_strict_fderiv_at_cpow Complex.hasStrictFDerivAt_cpow theorem hasStrictFDerivAt_cpow' {x y : ℂ} (hp : x ∈ slitPlane) : HasStrictFDerivAt (fun x : ℂ × ℂ => x.1 ^ x.2) ((y * x ^ (y - 1)) • ContinuousLinearMap.fst ℂ ℂ ℂ + (x ^ y * log x) • ContinuousLinearMap.snd ℂ ℂ ℂ) (x, y) := @hasStrictFDerivAt_cpow (x, y) hp #align complex.has_strict_fderiv_at_cpow' Complex.hasStrictFDerivAt_cpow' theorem hasStrictDerivAt_const_cpow {x y : ℂ} (h : x ≠ 0 ∨ y ≠ 0) : HasStrictDerivAt (fun y => x ^ y) (x ^ y * log x) y := by rcases em (x = 0) with (rfl | hx) · replace h := h.neg_resolve_left rfl rw [log_zero, mul_zero] refine (hasStrictDerivAt_const _ 0).congr_of_eventuallyEq ?_ exact (isOpen_ne.eventually_mem h).mono fun y hy => (zero_cpow hy).symm · simpa only [cpow_def_of_ne_zero hx, mul_one] using ((hasStrictDerivAt_id y).const_mul (log x)).cexp #align complex.has_strict_deriv_at_const_cpow Complex.hasStrictDerivAt_const_cpow theorem hasFDerivAt_cpow {p : ℂ × ℂ} (hp : p.1 ∈ slitPlane) : HasFDerivAt (fun x : ℂ × ℂ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℂ ℂ ℂ + (p.1 ^ p.2 * log p.1) • ContinuousLinearMap.snd ℂ ℂ ℂ) p := (hasStrictFDerivAt_cpow hp).hasFDerivAt #align complex.has_fderiv_at_cpow Complex.hasFDerivAt_cpow end Complex section fderiv open Complex variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : E → ℂ} {f' g' : E →L[ℂ] ℂ} {x : E} {s : Set E} {c : ℂ} theorem HasStrictFDerivAt.cpow (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasStrictFDerivAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * Complex.log (f x)) • g') x := by convert (@hasStrictFDerivAt_cpow ((fun x => (f x, g x)) x) h0).comp x (hf.prod hg) #align has_strict_fderiv_at.cpow HasStrictFDerivAt.cpow theorem HasStrictFDerivAt.const_cpow (hf : HasStrictFDerivAt f f' x) (h0 : c ≠ 0 ∨ f x ≠ 0) : HasStrictFDerivAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) • f') x := (hasStrictDerivAt_const_cpow h0).comp_hasStrictFDerivAt x hf #align has_strict_fderiv_at.const_cpow HasStrictFDerivAt.const_cpow
Mathlib/Analysis/SpecialFunctions/Pow/Deriv.lean
90
93
theorem HasFDerivAt.cpow (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasFDerivAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * Complex.log (f x)) • g') x := by
convert (@Complex.hasFDerivAt_cpow ((fun x => (f x, g x)) x) h0).comp x (hf.prod hg)
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Algebra.Group.Embedding import Mathlib.Data.Fin.Basic import Mathlib.Data.Finset.Union #align_import data.finset.image from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Image and map operations on finite sets This file provides the finite analog of `Set.image`, along with some other similar functions. Note there are two ways to take the image over a finset; via `Finset.image` which applies the function then removes duplicates (requiring `DecidableEq`), or via `Finset.map` which exploits injectivity of the function to avoid needing to deduplicate. Choosing between these is similar to choosing between `insert` and `Finset.cons`, or between `Finset.union` and `Finset.disjUnion`. ## Main definitions * `Finset.image`: Given a function `f : α → β`, `s.image f` is the image finset in `β`. * `Finset.map`: Given an embedding `f : α ↪ β`, `s.map f` is the image finset in `β`. * `Finset.filterMap` Given a function `f : α → Option β`, `s.filterMap f` is the image finset in `β`, filtering out `none`s. * `Finset.subtype`: `s.subtype p` is the finset of `Subtype p` whose elements belong to `s`. * `Finset.fin`:`s.fin n` is the finset of all elements of `s` less than `n`. ## TODO Move the material about `Finset.range` so that the `Mathlib.Algebra.Group.Embedding` import can be removed. -/ -- TODO -- assert_not_exists OrderedCommMonoid assert_not_exists MonoidWithZero assert_not_exists MulAction variable {α β γ : Type*} open Multiset open Function namespace Finset /-! ### map -/ section Map open Function /-- When `f` is an embedding of `α` in `β` and `s` is a finset in `α`, then `s.map f` is the image finset in `β`. The embedding condition guarantees that there are no duplicates in the image. -/ def map (f : α ↪ β) (s : Finset α) : Finset β := ⟨s.1.map f, s.2.map f.2⟩ #align finset.map Finset.map @[simp] theorem map_val (f : α ↪ β) (s : Finset α) : (map f s).1 = s.1.map f := rfl #align finset.map_val Finset.map_val @[simp] theorem map_empty (f : α ↪ β) : (∅ : Finset α).map f = ∅ := rfl #align finset.map_empty Finset.map_empty variable {f : α ↪ β} {s : Finset α} @[simp] theorem mem_map {b : β} : b ∈ s.map f ↔ ∃ a ∈ s, f a = b := Multiset.mem_map #align finset.mem_map Finset.mem_map -- Porting note: Higher priority to apply before `mem_map`. @[simp 1100] theorem mem_map_equiv {f : α ≃ β} {b : β} : b ∈ s.map f.toEmbedding ↔ f.symm b ∈ s := by rw [mem_map] exact ⟨by rintro ⟨a, H, rfl⟩ simpa, fun h => ⟨_, h, by simp⟩⟩ #align finset.mem_map_equiv Finset.mem_map_equiv -- The simpNF linter says that the LHS can be simplified via `Finset.mem_map`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem mem_map' (f : α ↪ β) {a} {s : Finset α} : f a ∈ s.map f ↔ a ∈ s := mem_map_of_injective f.2 #align finset.mem_map' Finset.mem_map' theorem mem_map_of_mem (f : α ↪ β) {a} {s : Finset α} : a ∈ s → f a ∈ s.map f := (mem_map' _).2 #align finset.mem_map_of_mem Finset.mem_map_of_mem theorem forall_mem_map {f : α ↪ β} {s : Finset α} {p : ∀ a, a ∈ s.map f → Prop} : (∀ y (H : y ∈ s.map f), p y H) ↔ ∀ x (H : x ∈ s), p (f x) (mem_map_of_mem _ H) := ⟨fun h y hy => h (f y) (mem_map_of_mem _ hy), fun h x hx => by obtain ⟨y, hy, rfl⟩ := mem_map.1 hx exact h _ hy⟩ #align finset.forall_mem_map Finset.forall_mem_map theorem apply_coe_mem_map (f : α ↪ β) (s : Finset α) (x : s) : f x ∈ s.map f := mem_map_of_mem f x.prop #align finset.apply_coe_mem_map Finset.apply_coe_mem_map @[simp, norm_cast] theorem coe_map (f : α ↪ β) (s : Finset α) : (s.map f : Set β) = f '' s := Set.ext (by simp only [mem_coe, mem_map, Set.mem_image, implies_true]) #align finset.coe_map Finset.coe_map theorem coe_map_subset_range (f : α ↪ β) (s : Finset α) : (s.map f : Set β) ⊆ Set.range f := calc ↑(s.map f) = f '' s := coe_map f s _ ⊆ Set.range f := Set.image_subset_range f ↑s #align finset.coe_map_subset_range Finset.coe_map_subset_range /-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect. -/ theorem map_perm {σ : Equiv.Perm α} (hs : { a | σ a ≠ a } ⊆ s) : s.map (σ : α ↪ α) = s := coe_injective <| (coe_map _ _).trans <| Set.image_perm hs #align finset.map_perm Finset.map_perm theorem map_toFinset [DecidableEq α] [DecidableEq β] {s : Multiset α} : s.toFinset.map f = (s.map f).toFinset := ext fun _ => by simp only [mem_map, Multiset.mem_map, exists_prop, Multiset.mem_toFinset] #align finset.map_to_finset Finset.map_toFinset @[simp] theorem map_refl : s.map (Embedding.refl _) = s := ext fun _ => by simpa only [mem_map, exists_prop] using exists_eq_right #align finset.map_refl Finset.map_refl @[simp] theorem map_cast_heq {α β} (h : α = β) (s : Finset α) : HEq (s.map (Equiv.cast h).toEmbedding) s := by subst h simp #align finset.map_cast_heq Finset.map_cast_heq theorem map_map (f : α ↪ β) (g : β ↪ γ) (s : Finset α) : (s.map f).map g = s.map (f.trans g) := eq_of_veq <| by simp only [map_val, Multiset.map_map]; rfl #align finset.map_map Finset.map_map theorem map_comm {β'} {f : β ↪ γ} {g : α ↪ β} {f' : α ↪ β'} {g' : β' ↪ γ} (h_comm : ∀ a, f (g a) = g' (f' a)) : (s.map g).map f = (s.map f').map g' := by simp_rw [map_map, Embedding.trans, Function.comp, h_comm] #align finset.map_comm Finset.map_comm theorem _root_.Function.Semiconj.finset_map {f : α ↪ β} {ga : α ↪ α} {gb : β ↪ β} (h : Function.Semiconj f ga gb) : Function.Semiconj (map f) (map ga) (map gb) := fun _ => map_comm h #align function.semiconj.finset_map Function.Semiconj.finset_map theorem _root_.Function.Commute.finset_map {f g : α ↪ α} (h : Function.Commute f g) : Function.Commute (map f) (map g) := Function.Semiconj.finset_map h #align function.commute.finset_map Function.Commute.finset_map @[simp] theorem map_subset_map {s₁ s₂ : Finset α} : s₁.map f ⊆ s₂.map f ↔ s₁ ⊆ s₂ := ⟨fun h x xs => (mem_map' _).1 <| h <| (mem_map' f).2 xs, fun h => by simp [subset_def, Multiset.map_subset_map h]⟩ #align finset.map_subset_map Finset.map_subset_map @[gcongr] alias ⟨_, _root_.GCongr.finsetMap_subset⟩ := map_subset_map /-- The `Finset` version of `Equiv.subset_symm_image`. -/ theorem subset_map_symm {t : Finset β} {f : α ≃ β} : s ⊆ t.map f.symm ↔ s.map f ⊆ t := by constructor <;> intro h x hx · simp only [mem_map_equiv, Equiv.symm_symm] at hx simpa using h hx · simp only [mem_map_equiv] exact h (by simp [hx]) /-- The `Finset` version of `Equiv.symm_image_subset`. -/ theorem map_symm_subset {t : Finset β} {f : α ≃ β} : t.map f.symm ⊆ s ↔ t ⊆ s.map f := by simp only [← subset_map_symm, Equiv.symm_symm] /-- Associate to an embedding `f` from `α` to `β` the order embedding that maps a finset to its image under `f`. -/ def mapEmbedding (f : α ↪ β) : Finset α ↪o Finset β := OrderEmbedding.ofMapLEIff (map f) fun _ _ => map_subset_map #align finset.map_embedding Finset.mapEmbedding @[simp] theorem map_inj {s₁ s₂ : Finset α} : s₁.map f = s₂.map f ↔ s₁ = s₂ := (mapEmbedding f).injective.eq_iff #align finset.map_inj Finset.map_inj theorem map_injective (f : α ↪ β) : Injective (map f) := (mapEmbedding f).injective #align finset.map_injective Finset.map_injective @[simp] theorem map_ssubset_map {s t : Finset α} : s.map f ⊂ t.map f ↔ s ⊂ t := (mapEmbedding f).lt_iff_lt @[gcongr] alias ⟨_, _root_.GCongr.finsetMap_ssubset⟩ := map_ssubset_map @[simp] theorem mapEmbedding_apply : mapEmbedding f s = map f s := rfl #align finset.map_embedding_apply Finset.mapEmbedding_apply theorem filter_map {p : β → Prop} [DecidablePred p] : (s.map f).filter p = (s.filter (p ∘ f)).map f := eq_of_veq (map_filter _ _ _) #align finset.filter_map Finset.filter_map lemma map_filter' (p : α → Prop) [DecidablePred p] (f : α ↪ β) (s : Finset α) [DecidablePred (∃ a, p a ∧ f a = ·)] : (s.filter p).map f = (s.map f).filter fun b => ∃ a, p a ∧ f a = b := by simp [(· ∘ ·), filter_map, f.injective.eq_iff] #align finset.map_filter' Finset.map_filter' lemma filter_attach' [DecidableEq α] (s : Finset α) (p : s → Prop) [DecidablePred p] : s.attach.filter p = (s.filter fun x => ∃ h, p ⟨x, h⟩).attach.map ⟨Subtype.map id <| filter_subset _ _, Subtype.map_injective _ injective_id⟩ := eq_of_veq <| Multiset.filter_attach' _ _ #align finset.filter_attach' Finset.filter_attach' lemma filter_attach (p : α → Prop) [DecidablePred p] (s : Finset α) : s.attach.filter (fun a : s ↦ p a) = (s.filter p).attach.map ((Embedding.refl _).subtypeMap mem_of_mem_filter) := eq_of_veq <| Multiset.filter_attach _ _ #align finset.filter_attach Finset.filter_attach theorem map_filter {f : α ≃ β} {p : α → Prop} [DecidablePred p] : (s.filter p).map f.toEmbedding = (s.map f.toEmbedding).filter (p ∘ f.symm) := by simp only [filter_map, Function.comp, Equiv.toEmbedding_apply, Equiv.symm_apply_apply] #align finset.map_filter Finset.map_filter @[simp] theorem disjoint_map {s t : Finset α} (f : α ↪ β) : Disjoint (s.map f) (t.map f) ↔ Disjoint s t := mod_cast Set.disjoint_image_iff f.injective (s := s) (t := t) #align finset.disjoint_map Finset.disjoint_map theorem map_disjUnion {f : α ↪ β} (s₁ s₂ : Finset α) (h) (h' := (disjoint_map _).mpr h) : (s₁.disjUnion s₂ h).map f = (s₁.map f).disjUnion (s₂.map f) h' := eq_of_veq <| Multiset.map_add _ _ _ #align finset.map_disj_union Finset.map_disjUnion /-- A version of `Finset.map_disjUnion` for writing in the other direction. -/ theorem map_disjUnion' {f : α ↪ β} (s₁ s₂ : Finset α) (h') (h := (disjoint_map _).mp h') : (s₁.disjUnion s₂ h).map f = (s₁.map f).disjUnion (s₂.map f) h' := map_disjUnion _ _ _ #align finset.map_disj_union' Finset.map_disjUnion' theorem map_union [DecidableEq α] [DecidableEq β] {f : α ↪ β} (s₁ s₂ : Finset α) : (s₁ ∪ s₂).map f = s₁.map f ∪ s₂.map f := mod_cast Set.image_union f s₁ s₂ #align finset.map_union Finset.map_union theorem map_inter [DecidableEq α] [DecidableEq β] {f : α ↪ β} (s₁ s₂ : Finset α) : (s₁ ∩ s₂).map f = s₁.map f ∩ s₂.map f := mod_cast Set.image_inter f.injective (s := s₁) (t := s₂) #align finset.map_inter Finset.map_inter @[simp] theorem map_singleton (f : α ↪ β) (a : α) : map f {a} = {f a} := coe_injective <| by simp only [coe_map, coe_singleton, Set.image_singleton] #align finset.map_singleton Finset.map_singleton @[simp] theorem map_insert [DecidableEq α] [DecidableEq β] (f : α ↪ β) (a : α) (s : Finset α) : (insert a s).map f = insert (f a) (s.map f) := by simp only [insert_eq, map_union, map_singleton] #align finset.map_insert Finset.map_insert @[simp] theorem map_cons (f : α ↪ β) (a : α) (s : Finset α) (ha : a ∉ s) : (cons a s ha).map f = cons (f a) (s.map f) (by simpa using ha) := eq_of_veq <| Multiset.map_cons f a s.val #align finset.map_cons Finset.map_cons @[simp] theorem map_eq_empty : s.map f = ∅ ↔ s = ∅ := (map_injective f).eq_iff' (map_empty f) #align finset.map_eq_empty Finset.map_eq_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem map_nonempty : (s.map f).Nonempty ↔ s.Nonempty := mod_cast Set.image_nonempty (f := f) (s := s) #align finset.map_nonempty Finset.map_nonempty protected alias ⟨_, Nonempty.map⟩ := map_nonempty #align finset.nonempty.map Finset.Nonempty.map @[simp] theorem map_nontrivial : (s.map f).Nontrivial ↔ s.Nontrivial := mod_cast Set.image_nontrivial f.injective (s := s) theorem attach_map_val {s : Finset α} : s.attach.map (Embedding.subtype _) = s := eq_of_veq <| by rw [map_val, attach_val]; exact Multiset.attach_map_val _ #align finset.attach_map_val Finset.attach_map_val theorem disjoint_range_addLeftEmbedding (a b : ℕ) : Disjoint (range a) (map (addLeftEmbedding a) (range b)) := by simp [disjoint_left]; omega #align finset.disjoint_range_add_left_embedding Finset.disjoint_range_addLeftEmbedding theorem disjoint_range_addRightEmbedding (a b : ℕ) : Disjoint (range a) (map (addRightEmbedding a) (range b)) := by simp [disjoint_left]; omega #align finset.disjoint_range_add_right_embedding Finset.disjoint_range_addRightEmbedding theorem map_disjiUnion {f : α ↪ β} {s : Finset α} {t : β → Finset γ} {h} : (s.map f).disjiUnion t h = s.disjiUnion (fun a => t (f a)) fun _ ha _ hb hab => h (mem_map_of_mem _ ha) (mem_map_of_mem _ hb) (f.injective.ne hab) := eq_of_veq <| Multiset.bind_map _ _ _ #align finset.map_disj_Union Finset.map_disjiUnion theorem disjiUnion_map {s : Finset α} {t : α → Finset β} {f : β ↪ γ} {h} : (s.disjiUnion t h).map f = s.disjiUnion (fun a => (t a).map f) (h.mono' fun _ _ ↦ (disjoint_map _).2) := eq_of_veq <| Multiset.map_bind _ _ _ #align finset.disj_Union_map Finset.disjiUnion_map end Map theorem range_add_one' (n : ℕ) : range (n + 1) = insert 0 ((range n).map ⟨fun i => i + 1, fun i j => by simp⟩) := by ext (⟨⟩ | ⟨n⟩) <;> simp [Nat.succ_eq_add_one, Nat.zero_lt_succ n] #align finset.range_add_one' Finset.range_add_one' /-! ### image -/ section Image variable [DecidableEq β] /-- `image f s` is the forward image of `s` under `f`. -/ def image (f : α → β) (s : Finset α) : Finset β := (s.1.map f).toFinset #align finset.image Finset.image @[simp] theorem image_val (f : α → β) (s : Finset α) : (image f s).1 = (s.1.map f).dedup := rfl #align finset.image_val Finset.image_val @[simp] theorem image_empty (f : α → β) : (∅ : Finset α).image f = ∅ := rfl #align finset.image_empty Finset.image_empty variable {f g : α → β} {s : Finset α} {t : Finset β} {a : α} {b c : β} @[simp] theorem mem_image : b ∈ s.image f ↔ ∃ a ∈ s, f a = b := by simp only [mem_def, image_val, mem_dedup, Multiset.mem_map, exists_prop] #align finset.mem_image Finset.mem_image theorem mem_image_of_mem (f : α → β) {a} (h : a ∈ s) : f a ∈ s.image f := mem_image.2 ⟨_, h, rfl⟩ #align finset.mem_image_of_mem Finset.mem_image_of_mem theorem forall_image {p : β → Prop} : (∀ b ∈ s.image f, p b) ↔ ∀ a ∈ s, p (f a) := by simp only [mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] #align finset.forall_image Finset.forall_image theorem map_eq_image (f : α ↪ β) (s : Finset α) : s.map f = s.image f := eq_of_veq (s.map f).2.dedup.symm #align finset.map_eq_image Finset.map_eq_image --@[simp] Porting note: removing simp, `simp` [Nonempty] can prove it theorem mem_image_const : c ∈ s.image (const α b) ↔ s.Nonempty ∧ b = c := by rw [mem_image] simp only [exists_prop, const_apply, exists_and_right] rfl #align finset.mem_image_const Finset.mem_image_const theorem mem_image_const_self : b ∈ s.image (const α b) ↔ s.Nonempty := mem_image_const.trans <| and_iff_left rfl #align finset.mem_image_const_self Finset.mem_image_const_self instance canLift (c) (p) [CanLift β α c p] : CanLift (Finset β) (Finset α) (image c) fun s => ∀ x ∈ s, p x where prf := by rintro ⟨⟨l⟩, hd : l.Nodup⟩ hl lift l to List α using hl exact ⟨⟨l, hd.of_map _⟩, ext fun a => by simp⟩ #align finset.can_lift Finset.canLift theorem image_congr (h : (s : Set α).EqOn f g) : Finset.image f s = Finset.image g s := by ext simp_rw [mem_image, ← bex_def] exact exists₂_congr fun x hx => by rw [h hx] #align finset.image_congr Finset.image_congr theorem _root_.Function.Injective.mem_finset_image (hf : Injective f) : f a ∈ s.image f ↔ a ∈ s := by refine ⟨fun h => ?_, Finset.mem_image_of_mem f⟩ obtain ⟨y, hy, heq⟩ := mem_image.1 h exact hf heq ▸ hy #align function.injective.mem_finset_image Function.Injective.mem_finset_image theorem filter_mem_image_eq_image (f : α → β) (s : Finset α) (t : Finset β) (h : ∀ x ∈ s, f x ∈ t) : (t.filter fun y => y ∈ s.image f) = s.image f := by ext simp only [mem_filter, mem_image, decide_eq_true_eq, and_iff_right_iff_imp, forall_exists_index, and_imp] rintro x xel rfl exact h _ xel #align finset.filter_mem_image_eq_image Finset.filter_mem_image_eq_image theorem fiber_nonempty_iff_mem_image (f : α → β) (s : Finset α) (y : β) : (s.filter fun x => f x = y).Nonempty ↔ y ∈ s.image f := by simp [Finset.Nonempty] #align finset.fiber_nonempty_iff_mem_image Finset.fiber_nonempty_iff_mem_image @[simp, norm_cast] theorem coe_image : ↑(s.image f) = f '' ↑s := Set.ext <| by simp only [mem_coe, mem_image, Set.mem_image, implies_true] #align finset.coe_image Finset.coe_image @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma image_nonempty : (s.image f).Nonempty ↔ s.Nonempty := mod_cast Set.image_nonempty (f := f) (s := (s : Set α)) #align finset.nonempty.image_iff Finset.image_nonempty protected theorem Nonempty.image (h : s.Nonempty) (f : α → β) : (s.image f).Nonempty := image_nonempty.2 h #align finset.nonempty.image Finset.Nonempty.image alias ⟨Nonempty.of_image, _⟩ := image_nonempty @[deprecated image_nonempty (since := "2023-12-29")] theorem Nonempty.image_iff (f : α → β) : (s.image f).Nonempty ↔ s.Nonempty := image_nonempty theorem image_toFinset [DecidableEq α] {s : Multiset α} : s.toFinset.image f = (s.map f).toFinset := ext fun _ => by simp only [mem_image, Multiset.mem_toFinset, exists_prop, Multiset.mem_map] #align finset.image_to_finset Finset.image_toFinset theorem image_val_of_injOn (H : Set.InjOn f s) : (image f s).1 = s.1.map f := (s.2.map_on H).dedup #align finset.image_val_of_inj_on Finset.image_val_of_injOn @[simp] theorem image_id [DecidableEq α] : s.image id = s := ext fun _ => by simp only [mem_image, exists_prop, id, exists_eq_right] #align finset.image_id Finset.image_id @[simp] theorem image_id' [DecidableEq α] : (s.image fun x => x) = s := image_id #align finset.image_id' Finset.image_id' theorem image_image [DecidableEq γ] {g : β → γ} : (s.image f).image g = s.image (g ∘ f) := eq_of_veq <| by simp only [image_val, dedup_map_dedup_eq, Multiset.map_map] #align finset.image_image Finset.image_image theorem image_comm {β'} [DecidableEq β'] [DecidableEq γ] {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ} (h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by simp_rw [image_image, comp, h_comm] #align finset.image_comm Finset.image_comm theorem _root_.Function.Semiconj.finset_image [DecidableEq α] {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ => image_comm h #align function.semiconj.finset_image Function.Semiconj.finset_image theorem _root_.Function.Commute.finset_image [DecidableEq α] {f g : α → α} (h : Function.Commute f g) : Function.Commute (image f) (image g) := Function.Semiconj.finset_image h #align function.commute.finset_image Function.Commute.finset_image theorem image_subset_image {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁.image f ⊆ s₂.image f := by simp only [subset_def, image_val, subset_dedup', dedup_subset', Multiset.map_subset_map h] #align finset.image_subset_image Finset.image_subset_image theorem image_subset_iff : s.image f ⊆ t ↔ ∀ x ∈ s, f x ∈ t := calc s.image f ⊆ t ↔ f '' ↑s ⊆ ↑t := by norm_cast _ ↔ _ := Set.image_subset_iff #align finset.image_subset_iff Finset.image_subset_iff theorem image_mono (f : α → β) : Monotone (Finset.image f) := fun _ _ => image_subset_image #align finset.image_mono Finset.image_mono lemma image_injective (hf : Injective f) : Injective (image f) := by simpa only [funext (map_eq_image _)] using map_injective ⟨f, hf⟩ lemma image_inj {t : Finset α} (hf : Injective f) : s.image f = t.image f ↔ s = t := (image_injective hf).eq_iff theorem image_subset_image_iff {t : Finset α} (hf : Injective f) : s.image f ⊆ t.image f ↔ s ⊆ t := mod_cast Set.image_subset_image_iff hf (s := s) (t := t) #align finset.image_subset_image_iff Finset.image_subset_image_iff lemma image_ssubset_image {t : Finset α} (hf : Injective f) : s.image f ⊂ t.image f ↔ s ⊂ t := by simp_rw [← lt_iff_ssubset] exact lt_iff_lt_of_le_iff_le' (image_subset_image_iff hf) (image_subset_image_iff hf) theorem coe_image_subset_range : ↑(s.image f) ⊆ Set.range f := calc ↑(s.image f) = f '' ↑s := coe_image _ ⊆ Set.range f := Set.image_subset_range f ↑s #align finset.coe_image_subset_range Finset.coe_image_subset_range theorem filter_image {p : β → Prop} [DecidablePred p] : (s.image f).filter p = (s.filter fun a ↦ p (f a)).image f := ext fun b => by simp only [mem_filter, mem_image, exists_prop] exact ⟨by rintro ⟨⟨x, h1, rfl⟩, h2⟩; exact ⟨x, ⟨h1, h2⟩, rfl⟩, by rintro ⟨x, ⟨h1, h2⟩, rfl⟩; exact ⟨⟨x, h1, rfl⟩, h2⟩⟩ #align finset.image_filter Finset.filter_image theorem image_union [DecidableEq α] {f : α → β} (s₁ s₂ : Finset α) : (s₁ ∪ s₂).image f = s₁.image f ∪ s₂.image f := mod_cast Set.image_union f s₁ s₂ #align finset.image_union Finset.image_union theorem image_inter_subset [DecidableEq α] (f : α → β) (s t : Finset α) : (s ∩ t).image f ⊆ s.image f ∩ t.image f := (image_mono f).map_inf_le s t #align finset.image_inter_subset Finset.image_inter_subset theorem image_inter_of_injOn [DecidableEq α] {f : α → β} (s t : Finset α) (hf : Set.InjOn f (s ∪ t)) : (s ∩ t).image f = s.image f ∩ t.image f := coe_injective <| by push_cast exact Set.image_inter_on fun a ha b hb => hf (Or.inr ha) <| Or.inl hb #align finset.image_inter_of_inj_on Finset.image_inter_of_injOn theorem image_inter [DecidableEq α] (s₁ s₂ : Finset α) (hf : Injective f) : (s₁ ∩ s₂).image f = s₁.image f ∩ s₂.image f := image_inter_of_injOn _ _ hf.injOn #align finset.image_inter Finset.image_inter @[simp] theorem image_singleton (f : α → β) (a : α) : image f {a} = {f a} := ext fun x => by simpa only [mem_image, exists_prop, mem_singleton, exists_eq_left] using eq_comm #align finset.image_singleton Finset.image_singleton @[simp]
Mathlib/Data/Finset/Image.lean
547
549
theorem image_insert [DecidableEq α] (f : α → β) (a : α) (s : Finset α) : (insert a s).image f = insert (f a) (s.image f) := by
simp only [insert_eq, image_singleton, image_union]
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Group.Nat import Mathlib.Algebra.Order.Sub.Canonical import Mathlib.Data.List.Perm import Mathlib.Data.Set.List import Mathlib.Init.Quot import Mathlib.Order.Hom.Basic #align_import data.multiset.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Multisets These are implemented as the quotient of a list by permutations. ## Notation We define the global infix notation `::ₘ` for `Multiset.cons`. -/ universe v open List Subtype Nat Function variable {α : Type*} {β : Type v} {γ : Type*} /-- `Multiset α` is the quotient of `List α` by list permutation. The result is a type of finite sets with duplicates allowed. -/ def Multiset.{u} (α : Type u) : Type u := Quotient (List.isSetoid α) #align multiset Multiset namespace Multiset -- Porting note: new /-- The quotient map from `List α` to `Multiset α`. -/ @[coe] def ofList : List α → Multiset α := Quot.mk _ instance : Coe (List α) (Multiset α) := ⟨ofList⟩ @[simp] theorem quot_mk_to_coe (l : List α) : @Eq (Multiset α) ⟦l⟧ l := rfl #align multiset.quot_mk_to_coe Multiset.quot_mk_to_coe @[simp] theorem quot_mk_to_coe' (l : List α) : @Eq (Multiset α) (Quot.mk (· ≈ ·) l) l := rfl #align multiset.quot_mk_to_coe' Multiset.quot_mk_to_coe' @[simp] theorem quot_mk_to_coe'' (l : List α) : @Eq (Multiset α) (Quot.mk Setoid.r l) l := rfl #align multiset.quot_mk_to_coe'' Multiset.quot_mk_to_coe'' @[simp] theorem coe_eq_coe {l₁ l₂ : List α} : (l₁ : Multiset α) = l₂ ↔ l₁ ~ l₂ := Quotient.eq #align multiset.coe_eq_coe Multiset.coe_eq_coe -- Porting note: new instance; -- Porting note (#11215): TODO: move to better place instance [DecidableEq α] (l₁ l₂ : List α) : Decidable (l₁ ≈ l₂) := inferInstanceAs (Decidable (l₁ ~ l₂)) -- Porting note: `Quotient.recOnSubsingleton₂ s₁ s₂` was in parens which broke elaboration instance decidableEq [DecidableEq α] : DecidableEq (Multiset α) | s₁, s₂ => Quotient.recOnSubsingleton₂ s₁ s₂ fun _ _ => decidable_of_iff' _ Quotient.eq #align multiset.has_decidable_eq Multiset.decidableEq /-- defines a size for a multiset by referring to the size of the underlying list -/ protected def sizeOf [SizeOf α] (s : Multiset α) : ℕ := (Quot.liftOn s SizeOf.sizeOf) fun _ _ => Perm.sizeOf_eq_sizeOf #align multiset.sizeof Multiset.sizeOf instance [SizeOf α] : SizeOf (Multiset α) := ⟨Multiset.sizeOf⟩ /-! ### Empty multiset -/ /-- `0 : Multiset α` is the empty set -/ protected def zero : Multiset α := @nil α #align multiset.zero Multiset.zero instance : Zero (Multiset α) := ⟨Multiset.zero⟩ instance : EmptyCollection (Multiset α) := ⟨0⟩ instance inhabitedMultiset : Inhabited (Multiset α) := ⟨0⟩ #align multiset.inhabited_multiset Multiset.inhabitedMultiset instance [IsEmpty α] : Unique (Multiset α) where default := 0 uniq := by rintro ⟨_ | ⟨a, l⟩⟩; exacts [rfl, isEmptyElim a] @[simp] theorem coe_nil : (@nil α : Multiset α) = 0 := rfl #align multiset.coe_nil Multiset.coe_nil @[simp] theorem empty_eq_zero : (∅ : Multiset α) = 0 := rfl #align multiset.empty_eq_zero Multiset.empty_eq_zero @[simp] theorem coe_eq_zero (l : List α) : (l : Multiset α) = 0 ↔ l = [] := Iff.trans coe_eq_coe perm_nil #align multiset.coe_eq_zero Multiset.coe_eq_zero theorem coe_eq_zero_iff_isEmpty (l : List α) : (l : Multiset α) = 0 ↔ l.isEmpty := Iff.trans (coe_eq_zero l) isEmpty_iff_eq_nil.symm #align multiset.coe_eq_zero_iff_empty Multiset.coe_eq_zero_iff_isEmpty /-! ### `Multiset.cons` -/ /-- `cons a s` is the multiset which contains `s` plus one more instance of `a`. -/ def cons (a : α) (s : Multiset α) : Multiset α := Quot.liftOn s (fun l => (a :: l : Multiset α)) fun _ _ p => Quot.sound (p.cons a) #align multiset.cons Multiset.cons @[inherit_doc Multiset.cons] infixr:67 " ::ₘ " => Multiset.cons instance : Insert α (Multiset α) := ⟨cons⟩ @[simp] theorem insert_eq_cons (a : α) (s : Multiset α) : insert a s = a ::ₘ s := rfl #align multiset.insert_eq_cons Multiset.insert_eq_cons @[simp] theorem cons_coe (a : α) (l : List α) : (a ::ₘ l : Multiset α) = (a :: l : List α) := rfl #align multiset.cons_coe Multiset.cons_coe @[simp] theorem cons_inj_left {a b : α} (s : Multiset α) : a ::ₘ s = b ::ₘ s ↔ a = b := ⟨Quot.inductionOn s fun l e => have : [a] ++ l ~ [b] ++ l := Quotient.exact e singleton_perm_singleton.1 <| (perm_append_right_iff _).1 this, congr_arg (· ::ₘ _)⟩ #align multiset.cons_inj_left Multiset.cons_inj_left @[simp] theorem cons_inj_right (a : α) : ∀ {s t : Multiset α}, a ::ₘ s = a ::ₘ t ↔ s = t := by rintro ⟨l₁⟩ ⟨l₂⟩; simp #align multiset.cons_inj_right Multiset.cons_inj_right @[elab_as_elim] protected theorem induction {p : Multiset α → Prop} (empty : p 0) (cons : ∀ (a : α) (s : Multiset α), p s → p (a ::ₘ s)) : ∀ s, p s := by rintro ⟨l⟩; induction' l with _ _ ih <;> [exact empty; exact cons _ _ ih] #align multiset.induction Multiset.induction @[elab_as_elim] protected theorem induction_on {p : Multiset α → Prop} (s : Multiset α) (empty : p 0) (cons : ∀ (a : α) (s : Multiset α), p s → p (a ::ₘ s)) : p s := Multiset.induction empty cons s #align multiset.induction_on Multiset.induction_on theorem cons_swap (a b : α) (s : Multiset α) : a ::ₘ b ::ₘ s = b ::ₘ a ::ₘ s := Quot.inductionOn s fun _ => Quotient.sound <| Perm.swap _ _ _ #align multiset.cons_swap Multiset.cons_swap section Rec variable {C : Multiset α → Sort*} /-- Dependent recursor on multisets. TODO: should be @[recursor 6], but then the definition of `Multiset.pi` fails with a stack overflow in `whnf`. -/ protected def rec (C_0 : C 0) (C_cons : ∀ a m, C m → C (a ::ₘ m)) (C_cons_heq : ∀ a a' m b, HEq (C_cons a (a' ::ₘ m) (C_cons a' m b)) (C_cons a' (a ::ₘ m) (C_cons a m b))) (m : Multiset α) : C m := Quotient.hrecOn m (@List.rec α (fun l => C ⟦l⟧) C_0 fun a l b => C_cons a ⟦l⟧ b) fun l l' h => h.rec_heq (fun hl _ ↦ by congr 1; exact Quot.sound hl) (C_cons_heq _ _ ⟦_⟧ _) #align multiset.rec Multiset.rec /-- Companion to `Multiset.rec` with more convenient argument order. -/ @[elab_as_elim] protected def recOn (m : Multiset α) (C_0 : C 0) (C_cons : ∀ a m, C m → C (a ::ₘ m)) (C_cons_heq : ∀ a a' m b, HEq (C_cons a (a' ::ₘ m) (C_cons a' m b)) (C_cons a' (a ::ₘ m) (C_cons a m b))) : C m := Multiset.rec C_0 C_cons C_cons_heq m #align multiset.rec_on Multiset.recOn variable {C_0 : C 0} {C_cons : ∀ a m, C m → C (a ::ₘ m)} {C_cons_heq : ∀ a a' m b, HEq (C_cons a (a' ::ₘ m) (C_cons a' m b)) (C_cons a' (a ::ₘ m) (C_cons a m b))} @[simp] theorem recOn_0 : @Multiset.recOn α C (0 : Multiset α) C_0 C_cons C_cons_heq = C_0 := rfl #align multiset.rec_on_0 Multiset.recOn_0 @[simp] theorem recOn_cons (a : α) (m : Multiset α) : (a ::ₘ m).recOn C_0 C_cons C_cons_heq = C_cons a m (m.recOn C_0 C_cons C_cons_heq) := Quotient.inductionOn m fun _ => rfl #align multiset.rec_on_cons Multiset.recOn_cons end Rec section Mem /-- `a ∈ s` means that `a` has nonzero multiplicity in `s`. -/ def Mem (a : α) (s : Multiset α) : Prop := Quot.liftOn s (fun l => a ∈ l) fun l₁ l₂ (e : l₁ ~ l₂) => propext <| e.mem_iff #align multiset.mem Multiset.Mem instance : Membership α (Multiset α) := ⟨Mem⟩ @[simp] theorem mem_coe {a : α} {l : List α} : a ∈ (l : Multiset α) ↔ a ∈ l := Iff.rfl #align multiset.mem_coe Multiset.mem_coe instance decidableMem [DecidableEq α] (a : α) (s : Multiset α) : Decidable (a ∈ s) := Quot.recOnSubsingleton' s fun l ↦ inferInstanceAs (Decidable (a ∈ l)) #align multiset.decidable_mem Multiset.decidableMem @[simp] theorem mem_cons {a b : α} {s : Multiset α} : a ∈ b ::ₘ s ↔ a = b ∨ a ∈ s := Quot.inductionOn s fun _ => List.mem_cons #align multiset.mem_cons Multiset.mem_cons theorem mem_cons_of_mem {a b : α} {s : Multiset α} (h : a ∈ s) : a ∈ b ::ₘ s := mem_cons.2 <| Or.inr h #align multiset.mem_cons_of_mem Multiset.mem_cons_of_mem -- @[simp] -- Porting note (#10618): simp can prove this theorem mem_cons_self (a : α) (s : Multiset α) : a ∈ a ::ₘ s := mem_cons.2 (Or.inl rfl) #align multiset.mem_cons_self Multiset.mem_cons_self theorem forall_mem_cons {p : α → Prop} {a : α} {s : Multiset α} : (∀ x ∈ a ::ₘ s, p x) ↔ p a ∧ ∀ x ∈ s, p x := Quotient.inductionOn' s fun _ => List.forall_mem_cons #align multiset.forall_mem_cons Multiset.forall_mem_cons theorem exists_cons_of_mem {s : Multiset α} {a : α} : a ∈ s → ∃ t, s = a ::ₘ t := Quot.inductionOn s fun l (h : a ∈ l) => let ⟨l₁, l₂, e⟩ := append_of_mem h e.symm ▸ ⟨(l₁ ++ l₂ : List α), Quot.sound perm_middle⟩ #align multiset.exists_cons_of_mem Multiset.exists_cons_of_mem @[simp] theorem not_mem_zero (a : α) : a ∉ (0 : Multiset α) := List.not_mem_nil _ #align multiset.not_mem_zero Multiset.not_mem_zero theorem eq_zero_of_forall_not_mem {s : Multiset α} : (∀ x, x ∉ s) → s = 0 := Quot.inductionOn s fun l H => by rw [eq_nil_iff_forall_not_mem.mpr H]; rfl #align multiset.eq_zero_of_forall_not_mem Multiset.eq_zero_of_forall_not_mem theorem eq_zero_iff_forall_not_mem {s : Multiset α} : s = 0 ↔ ∀ a, a ∉ s := ⟨fun h => h.symm ▸ fun _ => not_mem_zero _, eq_zero_of_forall_not_mem⟩ #align multiset.eq_zero_iff_forall_not_mem Multiset.eq_zero_iff_forall_not_mem theorem exists_mem_of_ne_zero {s : Multiset α} : s ≠ 0 → ∃ a : α, a ∈ s := Quot.inductionOn s fun l hl => match l, hl with | [], h => False.elim <| h rfl | a :: l, _ => ⟨a, by simp⟩ #align multiset.exists_mem_of_ne_zero Multiset.exists_mem_of_ne_zero theorem empty_or_exists_mem (s : Multiset α) : s = 0 ∨ ∃ a, a ∈ s := or_iff_not_imp_left.mpr Multiset.exists_mem_of_ne_zero #align multiset.empty_or_exists_mem Multiset.empty_or_exists_mem @[simp] theorem zero_ne_cons {a : α} {m : Multiset α} : 0 ≠ a ::ₘ m := fun h => have : a ∈ (0 : Multiset α) := h.symm ▸ mem_cons_self _ _ not_mem_zero _ this #align multiset.zero_ne_cons Multiset.zero_ne_cons @[simp] theorem cons_ne_zero {a : α} {m : Multiset α} : a ::ₘ m ≠ 0 := zero_ne_cons.symm #align multiset.cons_ne_zero Multiset.cons_ne_zero theorem cons_eq_cons {a b : α} {as bs : Multiset α} : a ::ₘ as = b ::ₘ bs ↔ a = b ∧ as = bs ∨ a ≠ b ∧ ∃ cs, as = b ::ₘ cs ∧ bs = a ::ₘ cs := by haveI : DecidableEq α := Classical.decEq α constructor · intro eq by_cases h : a = b · subst h simp_all · have : a ∈ b ::ₘ bs := eq ▸ mem_cons_self _ _ have : a ∈ bs := by simpa [h] rcases exists_cons_of_mem this with ⟨cs, hcs⟩ simp only [h, hcs, false_and, ne_eq, not_false_eq_true, cons_inj_right, exists_eq_right', true_and, false_or] have : a ::ₘ as = b ::ₘ a ::ₘ cs := by simp [eq, hcs] have : a ::ₘ as = a ::ₘ b ::ₘ cs := by rwa [cons_swap] simpa using this · intro h rcases h with (⟨eq₁, eq₂⟩ | ⟨_, cs, eq₁, eq₂⟩) · simp [*] · simp [*, cons_swap a b] #align multiset.cons_eq_cons Multiset.cons_eq_cons end Mem /-! ### Singleton -/ instance : Singleton α (Multiset α) := ⟨fun a => a ::ₘ 0⟩ instance : LawfulSingleton α (Multiset α) := ⟨fun _ => rfl⟩ @[simp] theorem cons_zero (a : α) : a ::ₘ 0 = {a} := rfl #align multiset.cons_zero Multiset.cons_zero @[simp, norm_cast] theorem coe_singleton (a : α) : ([a] : Multiset α) = {a} := rfl #align multiset.coe_singleton Multiset.coe_singleton @[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : Multiset α) ↔ b = a := by simp only [← cons_zero, mem_cons, iff_self_iff, or_false_iff, not_mem_zero] #align multiset.mem_singleton Multiset.mem_singleton theorem mem_singleton_self (a : α) : a ∈ ({a} : Multiset α) := by rw [← cons_zero] exact mem_cons_self _ _ #align multiset.mem_singleton_self Multiset.mem_singleton_self @[simp] theorem singleton_inj {a b : α} : ({a} : Multiset α) = {b} ↔ a = b := by simp_rw [← cons_zero] exact cons_inj_left _ #align multiset.singleton_inj Multiset.singleton_inj @[simp, norm_cast] theorem coe_eq_singleton {l : List α} {a : α} : (l : Multiset α) = {a} ↔ l = [a] := by rw [← coe_singleton, coe_eq_coe, List.perm_singleton] #align multiset.coe_eq_singleton Multiset.coe_eq_singleton @[simp] theorem singleton_eq_cons_iff {a b : α} (m : Multiset α) : {a} = b ::ₘ m ↔ a = b ∧ m = 0 := by rw [← cons_zero, cons_eq_cons] simp [eq_comm] #align multiset.singleton_eq_cons_iff Multiset.singleton_eq_cons_iff theorem pair_comm (x y : α) : ({x, y} : Multiset α) = {y, x} := cons_swap x y 0 #align multiset.pair_comm Multiset.pair_comm /-! ### `Multiset.Subset` -/ section Subset variable {s : Multiset α} {a : α} /-- `s ⊆ t` is the lift of the list subset relation. It means that any element with nonzero multiplicity in `s` has nonzero multiplicity in `t`, but it does not imply that the multiplicity of `a` in `s` is less or equal than in `t`; see `s ≤ t` for this relation. -/ protected def Subset (s t : Multiset α) : Prop := ∀ ⦃a : α⦄, a ∈ s → a ∈ t #align multiset.subset Multiset.Subset instance : HasSubset (Multiset α) := ⟨Multiset.Subset⟩ instance : HasSSubset (Multiset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance instIsNonstrictStrictOrder : IsNonstrictStrictOrder (Multiset α) (· ⊆ ·) (· ⊂ ·) where right_iff_left_not_left _ _ := Iff.rfl @[simp] theorem coe_subset {l₁ l₂ : List α} : (l₁ : Multiset α) ⊆ l₂ ↔ l₁ ⊆ l₂ := Iff.rfl #align multiset.coe_subset Multiset.coe_subset @[simp] theorem Subset.refl (s : Multiset α) : s ⊆ s := fun _ h => h #align multiset.subset.refl Multiset.Subset.refl theorem Subset.trans {s t u : Multiset α} : s ⊆ t → t ⊆ u → s ⊆ u := fun h₁ h₂ _ m => h₂ (h₁ m) #align multiset.subset.trans Multiset.Subset.trans theorem subset_iff {s t : Multiset α} : s ⊆ t ↔ ∀ ⦃x⦄, x ∈ s → x ∈ t := Iff.rfl #align multiset.subset_iff Multiset.subset_iff theorem mem_of_subset {s t : Multiset α} {a : α} (h : s ⊆ t) : a ∈ s → a ∈ t := @h _ #align multiset.mem_of_subset Multiset.mem_of_subset @[simp] theorem zero_subset (s : Multiset α) : 0 ⊆ s := fun a => (not_mem_nil a).elim #align multiset.zero_subset Multiset.zero_subset theorem subset_cons (s : Multiset α) (a : α) : s ⊆ a ::ₘ s := fun _ => mem_cons_of_mem #align multiset.subset_cons Multiset.subset_cons theorem ssubset_cons {s : Multiset α} {a : α} (ha : a ∉ s) : s ⊂ a ::ₘ s := ⟨subset_cons _ _, fun h => ha <| h <| mem_cons_self _ _⟩ #align multiset.ssubset_cons Multiset.ssubset_cons @[simp] theorem cons_subset {a : α} {s t : Multiset α} : a ::ₘ s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp [subset_iff, or_imp, forall_and] #align multiset.cons_subset Multiset.cons_subset theorem cons_subset_cons {a : α} {s t : Multiset α} : s ⊆ t → a ::ₘ s ⊆ a ::ₘ t := Quotient.inductionOn₂ s t fun _ _ => List.cons_subset_cons _ #align multiset.cons_subset_cons Multiset.cons_subset_cons theorem eq_zero_of_subset_zero {s : Multiset α} (h : s ⊆ 0) : s = 0 := eq_zero_of_forall_not_mem fun _ hx ↦ not_mem_zero _ (h hx) #align multiset.eq_zero_of_subset_zero Multiset.eq_zero_of_subset_zero @[simp] lemma subset_zero : s ⊆ 0 ↔ s = 0 := ⟨eq_zero_of_subset_zero, fun xeq => xeq.symm ▸ Subset.refl 0⟩ #align multiset.subset_zero Multiset.subset_zero @[simp] lemma zero_ssubset : 0 ⊂ s ↔ s ≠ 0 := by simp [ssubset_iff_subset_not_subset] @[simp] lemma singleton_subset : {a} ⊆ s ↔ a ∈ s := by simp [subset_iff] theorem induction_on' {p : Multiset α → Prop} (S : Multiset α) (h₁ : p 0) (h₂ : ∀ {a s}, a ∈ S → s ⊆ S → p s → p (insert a s)) : p S := @Multiset.induction_on α (fun T => T ⊆ S → p T) S (fun _ => h₁) (fun _ _ hps hs => let ⟨hS, sS⟩ := cons_subset.1 hs h₂ hS sS (hps sS)) (Subset.refl S) #align multiset.induction_on' Multiset.induction_on' end Subset /-! ### `Multiset.toList` -/ section ToList /-- Produces a list of the elements in the multiset using choice. -/ noncomputable def toList (s : Multiset α) := s.out' #align multiset.to_list Multiset.toList @[simp, norm_cast] theorem coe_toList (s : Multiset α) : (s.toList : Multiset α) = s := s.out_eq' #align multiset.coe_to_list Multiset.coe_toList @[simp] theorem toList_eq_nil {s : Multiset α} : s.toList = [] ↔ s = 0 := by rw [← coe_eq_zero, coe_toList] #align multiset.to_list_eq_nil Multiset.toList_eq_nil @[simp] theorem empty_toList {s : Multiset α} : s.toList.isEmpty ↔ s = 0 := isEmpty_iff_eq_nil.trans toList_eq_nil #align multiset.empty_to_list Multiset.empty_toList @[simp] theorem toList_zero : (Multiset.toList 0 : List α) = [] := toList_eq_nil.mpr rfl #align multiset.to_list_zero Multiset.toList_zero @[simp] theorem mem_toList {a : α} {s : Multiset α} : a ∈ s.toList ↔ a ∈ s := by rw [← mem_coe, coe_toList] #align multiset.mem_to_list Multiset.mem_toList @[simp]
Mathlib/Data/Multiset/Basic.lean
498
499
theorem toList_eq_singleton_iff {a : α} {m : Multiset α} : m.toList = [a] ↔ m = {a} := by
rw [← perm_singleton, ← coe_eq_coe, coe_toList, coe_singleton]
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.CategoryTheory.Limits.Shapes.Kernels import Mathlib.CategoryTheory.Limits.Shapes.NormalMono.Equalizers import Mathlib.CategoryTheory.Abelian.Images import Mathlib.CategoryTheory.Preadditive.Basic #align_import category_theory.abelian.non_preadditive from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3" /-! # Every NonPreadditiveAbelian category is preadditive In mathlib, we define an abelian category as a preadditive category with a zero object, kernels and cokernels, products and coproducts and in which every monomorphism and epimorphism is normal. While virtually every interesting abelian category has a natural preadditive structure (which is why it is included in the definition), preadditivity is not actually needed: Every category that has all of the other properties appearing in the definition of an abelian category admits a preadditive structure. This is the construction we carry out in this file. The proof proceeds in roughly five steps: 1. Prove some results (for example that all equalizers exist) that would be trivial if we already had the preadditive structure but are a bit of work without it. 2. Develop images and coimages to show that every monomorphism is the kernel of its cokernel. The results of the first two steps are also useful for the "normal" development of abelian categories, and will be used there. 3. For every object `A`, define a "subtraction" morphism `σ : A ⨯ A ⟶ A` and use it to define subtraction on morphisms as `f - g := prod.lift f g ≫ σ`. 4. Prove a small number of identities about this subtraction from the definition of `σ`. 5. From these identities, prove a large number of other identities that imply that defining `f + g := f - (0 - g)` indeed gives an abelian group structure on morphisms such that composition is bilinear. The construction is non-trivial and it is quite remarkable that this abelian group structure can be constructed purely from the existence of a few limits and colimits. Even more remarkably, since abelian categories admit exactly one preadditive structure (see `subsingletonPreadditiveOfHasBinaryBiproducts`), the construction manages to exactly reconstruct any natural preadditive structure the category may have. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section open CategoryTheory open CategoryTheory.Limits namespace CategoryTheory section universe v u variable (C : Type u) [Category.{v} C] /-- We call a category `NonPreadditiveAbelian` if it has a zero object, kernels, cokernels, binary products and coproducts, and every monomorphism and every epimorphism is normal. -/ class NonPreadditiveAbelian extends HasZeroMorphisms C, NormalMonoCategory C, NormalEpiCategory C where [has_zero_object : HasZeroObject C] [has_kernels : HasKernels C] [has_cokernels : HasCokernels C] [has_finite_products : HasFiniteProducts C] [has_finite_coproducts : HasFiniteCoproducts C] #align category_theory.non_preadditive_abelian CategoryTheory.NonPreadditiveAbelian attribute [instance] NonPreadditiveAbelian.has_zero_object attribute [instance] NonPreadditiveAbelian.has_kernels attribute [instance] NonPreadditiveAbelian.has_cokernels attribute [instance] NonPreadditiveAbelian.has_finite_products attribute [instance] NonPreadditiveAbelian.has_finite_coproducts end end CategoryTheory open CategoryTheory universe v u variable {C : Type u} [Category.{v} C] [NonPreadditiveAbelian C] namespace CategoryTheory.NonPreadditiveAbelian section Factor variable {P Q : C} (f : P ⟶ Q) /-- The map `p : P ⟶ image f` is an epimorphism -/ instance : Epi (Abelian.factorThruImage f) := let I := Abelian.image f let p := Abelian.factorThruImage f let i := kernel.ι (cokernel.π f) -- It will suffice to consider some g : I ⟶ R such that p ≫ g = 0 and show that g = 0. NormalMonoCategory.epi_of_zero_cancel _ fun R (g : I ⟶ R) (hpg : p ≫ g = 0) => by -- Since C is abelian, u := ker g ≫ i is the kernel of some morphism h. let u := kernel.ι g ≫ i haveI : Mono u := mono_comp _ _ haveI hu := normalMonoOfMono u let h := hu.g -- By hypothesis, p factors through the kernel of g via some t. obtain ⟨t, ht⟩ := kernel.lift' g p hpg have fh : f ≫ h = 0 := calc f ≫ h = (p ≫ i) ≫ h := (Abelian.image.fac f).symm ▸ rfl _ = ((t ≫ kernel.ι g) ≫ i) ≫ h := ht ▸ rfl _ = t ≫ u ≫ h := by simp only [u, Category.assoc] _ = t ≫ 0 := hu.w ▸ rfl _ = 0 := HasZeroMorphisms.comp_zero _ _ -- h factors through the cokernel of f via some l. obtain ⟨l, hl⟩ := cokernel.desc' f h fh have hih : i ≫ h = 0 := calc i ≫ h = i ≫ cokernel.π f ≫ l := hl ▸ rfl _ = 0 ≫ l := by rw [← Category.assoc, kernel.condition] _ = 0 := zero_comp -- i factors through u = ker h via some s. obtain ⟨s, hs⟩ := NormalMono.lift' u i hih have hs' : (s ≫ kernel.ι g) ≫ i = 𝟙 I ≫ i := by rw [Category.assoc, hs, Category.id_comp] haveI : Epi (kernel.ι g) := epi_of_epi_fac ((cancel_mono _).1 hs') -- ker g is an epimorphism, but ker g ≫ g = 0 = ker g ≫ 0, so g = 0 as required. exact zero_of_epi_comp _ (kernel.condition g) instance isIso_factorThruImage [Mono f] : IsIso (Abelian.factorThruImage f) := isIso_of_mono_of_epi <| Abelian.factorThruImage f #align category_theory.non_preadditive_abelian.is_iso_factor_thru_image CategoryTheory.NonPreadditiveAbelian.isIso_factorThruImage /-- The canonical morphism `i : coimage f ⟶ Q` is a monomorphism -/ instance : Mono (Abelian.factorThruCoimage f) := let I := Abelian.coimage f let i := Abelian.factorThruCoimage f let p := cokernel.π (kernel.ι f) NormalEpiCategory.mono_of_cancel_zero _ fun R (g : R ⟶ I) (hgi : g ≫ i = 0) => by -- Since C is abelian, u := p ≫ coker g is the cokernel of some morphism h. let u := p ≫ cokernel.π g haveI : Epi u := epi_comp _ _ haveI hu := normalEpiOfEpi u let h := hu.g -- By hypothesis, i factors through the cokernel of g via some t. obtain ⟨t, ht⟩ := cokernel.desc' g i hgi have hf : h ≫ f = 0 := calc h ≫ f = h ≫ p ≫ i := (Abelian.coimage.fac f).symm ▸ rfl _ = h ≫ p ≫ cokernel.π g ≫ t := ht ▸ rfl _ = h ≫ u ≫ t := by simp only [u, Category.assoc] _ = 0 ≫ t := by rw [← Category.assoc, hu.w] _ = 0 := zero_comp -- h factors through the kernel of f via some l. obtain ⟨l, hl⟩ := kernel.lift' f h hf have hhp : h ≫ p = 0 := calc h ≫ p = (l ≫ kernel.ι f) ≫ p := hl ▸ rfl _ = l ≫ 0 := by rw [Category.assoc, cokernel.condition] _ = 0 := comp_zero -- p factors through u = coker h via some s. obtain ⟨s, hs⟩ := NormalEpi.desc' u p hhp have hs' : p ≫ cokernel.π g ≫ s = p ≫ 𝟙 I := by rw [← Category.assoc, hs, Category.comp_id] haveI : Mono (cokernel.π g) := mono_of_mono_fac ((cancel_epi _).1 hs') -- coker g is a monomorphism, but g ≫ coker g = 0 = 0 ≫ coker g, so g = 0 as required. exact zero_of_comp_mono _ (cokernel.condition g) instance isIso_factorThruCoimage [Epi f] : IsIso (Abelian.factorThruCoimage f) := isIso_of_mono_of_epi _ #align category_theory.non_preadditive_abelian.is_iso_factor_thru_coimage CategoryTheory.NonPreadditiveAbelian.isIso_factorThruCoimage end Factor section CokernelOfKernel variable {X Y : C} {f : X ⟶ Y} /-- In a `NonPreadditiveAbelian` category, an epi is the cokernel of its kernel. More precisely: If `f` is an epimorphism and `s` is some limit kernel cone on `f`, then `f` is a cokernel of `Fork.ι s`. -/ def epiIsCokernelOfKernel [Epi f] (s : Fork f 0) (h : IsLimit s) : IsColimit (CokernelCofork.ofπ f (KernelFork.condition s)) := IsCokernel.cokernelIso _ _ (cokernel.ofIsoComp _ _ (Limits.IsLimit.conePointUniqueUpToIso (limit.isLimit _) h) (ConeMorphism.w (Limits.IsLimit.uniqueUpToIso (limit.isLimit _) h).hom _)) (asIso <| Abelian.factorThruCoimage f) (Abelian.coimage.fac f) #align category_theory.non_preadditive_abelian.epi_is_cokernel_of_kernel CategoryTheory.NonPreadditiveAbelian.epiIsCokernelOfKernel /-- In a `NonPreadditiveAbelian` category, a mono is the kernel of its cokernel. More precisely: If `f` is a monomorphism and `s` is some colimit cokernel cocone on `f`, then `f` is a kernel of `Cofork.π s`. -/ def monoIsKernelOfCokernel [Mono f] (s : Cofork f 0) (h : IsColimit s) : IsLimit (KernelFork.ofι f (CokernelCofork.condition s)) := IsKernel.isoKernel _ _ (kernel.ofCompIso _ _ (Limits.IsColimit.coconePointUniqueUpToIso h (colimit.isColimit _)) (CoconeMorphism.w (Limits.IsColimit.uniqueUpToIso h <| colimit.isColimit _).hom _)) (asIso <| Abelian.factorThruImage f) (Abelian.image.fac f) #align category_theory.non_preadditive_abelian.mono_is_kernel_of_cokernel CategoryTheory.NonPreadditiveAbelian.monoIsKernelOfCokernel end CokernelOfKernel section /-- The composite `A ⟶ A ⨯ A ⟶ cokernel (Δ A)`, where the first map is `(𝟙 A, 0)` and the second map is the canonical projection into the cokernel. -/ abbrev r (A : C) : A ⟶ cokernel (diag A) := prod.lift (𝟙 A) 0 ≫ cokernel.π (diag A) #align category_theory.non_preadditive_abelian.r CategoryTheory.NonPreadditiveAbelian.r instance mono_Δ {A : C} : Mono (diag A) := mono_of_mono_fac <| prod.lift_fst _ _ #align category_theory.non_preadditive_abelian.mono_Δ CategoryTheory.NonPreadditiveAbelian.mono_Δ instance mono_r {A : C} : Mono (r A) := by let hl : IsLimit (KernelFork.ofι (diag A) (cokernel.condition (diag A))) := monoIsKernelOfCokernel _ (colimit.isColimit _) apply NormalEpiCategory.mono_of_cancel_zero intro Z x hx have hxx : (x ≫ prod.lift (𝟙 A) (0 : A ⟶ A)) ≫ cokernel.π (diag A) = 0 := by rw [Category.assoc, hx] obtain ⟨y, hy⟩ := KernelFork.IsLimit.lift' hl _ hxx rw [KernelFork.ι_ofι] at hy have hyy : y = 0 := by erw [← Category.comp_id y, ← Limits.prod.lift_snd (𝟙 A) (𝟙 A), ← Category.assoc, hy, Category.assoc, prod.lift_snd, HasZeroMorphisms.comp_zero] haveI : Mono (prod.lift (𝟙 A) (0 : A ⟶ A)) := mono_of_mono_fac (prod.lift_fst _ _) apply (cancel_mono (prod.lift (𝟙 A) (0 : A ⟶ A))).1 rw [← hy, hyy, zero_comp, zero_comp] #align category_theory.non_preadditive_abelian.mono_r CategoryTheory.NonPreadditiveAbelian.mono_r instance epi_r {A : C} : Epi (r A) := by have hlp : prod.lift (𝟙 A) (0 : A ⟶ A) ≫ Limits.prod.snd = 0 := prod.lift_snd _ _ let hp1 : IsLimit (KernelFork.ofι (prod.lift (𝟙 A) (0 : A ⟶ A)) hlp) := by refine Fork.IsLimit.mk _ (fun s => Fork.ι s ≫ Limits.prod.fst) ?_ ?_ · intro s apply prod.hom_ext <;> simp · intro s m h haveI : Mono (prod.lift (𝟙 A) (0 : A ⟶ A)) := mono_of_mono_fac (prod.lift_fst _ _) apply (cancel_mono (prod.lift (𝟙 A) (0 : A ⟶ A))).1 convert h apply prod.hom_ext <;> simp let hp2 : IsColimit (CokernelCofork.ofπ (Limits.prod.snd : A ⨯ A ⟶ A) hlp) := epiIsCokernelOfKernel _ hp1 apply NormalMonoCategory.epi_of_zero_cancel intro Z z hz have h : prod.lift (𝟙 A) (0 : A ⟶ A) ≫ cokernel.π (diag A) ≫ z = 0 := by rw [← Category.assoc, hz] obtain ⟨t, ht⟩ := CokernelCofork.IsColimit.desc' hp2 _ h rw [CokernelCofork.π_ofπ] at ht have htt : t = 0 := by rw [← Category.id_comp t] change 𝟙 A ≫ t = 0 rw [← Limits.prod.lift_snd (𝟙 A) (𝟙 A), Category.assoc, ht, ← Category.assoc, cokernel.condition, zero_comp] apply (cancel_epi (cokernel.π (diag A))).1 rw [← ht, htt, comp_zero, comp_zero] #align category_theory.non_preadditive_abelian.epi_r CategoryTheory.NonPreadditiveAbelian.epi_r instance isIso_r {A : C} : IsIso (r A) := isIso_of_mono_of_epi _ #align category_theory.non_preadditive_abelian.is_iso_r CategoryTheory.NonPreadditiveAbelian.isIso_r /-- The composite `A ⨯ A ⟶ cokernel (diag A) ⟶ A` given by the natural projection into the cokernel followed by the inverse of `r`. In the category of modules, using the normal kernels and cokernels, this map is equal to the map `(a, b) ↦ a - b`, hence the name `σ` for "subtraction". -/ abbrev σ {A : C} : A ⨯ A ⟶ A := cokernel.π (diag A) ≫ inv (r A) #align category_theory.non_preadditive_abelian.σ CategoryTheory.NonPreadditiveAbelian.σ end -- Porting note (#10618): simp can prove these @[reassoc] theorem diag_σ {X : C} : diag X ≫ σ = 0 := by rw [cokernel.condition_assoc, zero_comp] #align category_theory.non_preadditive_abelian.diag_σ CategoryTheory.NonPreadditiveAbelian.diag_σ @[reassoc (attr := simp)] theorem lift_σ {X : C} : prod.lift (𝟙 X) 0 ≫ σ = 𝟙 X := by rw [← Category.assoc, IsIso.hom_inv_id] #align category_theory.non_preadditive_abelian.lift_σ CategoryTheory.NonPreadditiveAbelian.lift_σ @[reassoc] theorem lift_map {X Y : C} (f : X ⟶ Y) : prod.lift (𝟙 X) 0 ≫ Limits.prod.map f f = f ≫ prod.lift (𝟙 Y) 0 := by simp #align category_theory.non_preadditive_abelian.lift_map CategoryTheory.NonPreadditiveAbelian.lift_map /-- σ is a cokernel of Δ X. -/ def isColimitσ {X : C} : IsColimit (CokernelCofork.ofπ (σ : X ⨯ X ⟶ X) diag_σ) := cokernel.cokernelIso _ σ (asIso (r X)).symm (by rw [Iso.symm_hom, asIso_inv]) #align category_theory.non_preadditive_abelian.is_colimit_σ CategoryTheory.NonPreadditiveAbelian.isColimitσ /-- This is the key identity satisfied by `σ`. -/ theorem σ_comp {X Y : C} (f : X ⟶ Y) : σ ≫ f = Limits.prod.map f f ≫ σ := by obtain ⟨g, hg⟩ := CokernelCofork.IsColimit.desc' isColimitσ (Limits.prod.map f f ≫ σ) (by rw [prod.diag_map_assoc, diag_σ, comp_zero]) suffices hfg : f = g by rw [← hg, Cofork.π_ofπ, hfg] calc f = f ≫ prod.lift (𝟙 Y) 0 ≫ σ := by rw [lift_σ, Category.comp_id] _ = prod.lift (𝟙 X) 0 ≫ Limits.prod.map f f ≫ σ := by rw [lift_map_assoc] _ = prod.lift (𝟙 X) 0 ≫ σ ≫ g := by rw [← hg, CokernelCofork.π_ofπ] _ = g := by rw [← Category.assoc, lift_σ, Category.id_comp] #align category_theory.non_preadditive_abelian.σ_comp CategoryTheory.NonPreadditiveAbelian.σ_comp section -- We write `f - g` for `prod.lift f g ≫ σ`. /-- Subtraction of morphisms in a `NonPreadditiveAbelian` category. -/ def hasSub {X Y : C} : Sub (X ⟶ Y) := ⟨fun f g => prod.lift f g ≫ σ⟩ #align category_theory.non_preadditive_abelian.has_sub CategoryTheory.NonPreadditiveAbelian.hasSub attribute [local instance] hasSub -- We write `-f` for `0 - f`. /-- Negation of morphisms in a `NonPreadditiveAbelian` category. -/ def hasNeg {X Y : C} : Neg (X ⟶ Y) where neg := fun f => 0 - f #align category_theory.non_preadditive_abelian.has_neg CategoryTheory.NonPreadditiveAbelian.hasNeg attribute [local instance] hasNeg -- We write `f + g` for `f - (-g)`. /-- Addition of morphisms in a `NonPreadditiveAbelian` category. -/ def hasAdd {X Y : C} : Add (X ⟶ Y) := ⟨fun f g => f - -g⟩ #align category_theory.non_preadditive_abelian.has_add CategoryTheory.NonPreadditiveAbelian.hasAdd attribute [local instance] hasAdd theorem sub_def {X Y : C} (a b : X ⟶ Y) : a - b = prod.lift a b ≫ σ := rfl #align category_theory.non_preadditive_abelian.sub_def CategoryTheory.NonPreadditiveAbelian.sub_def theorem add_def {X Y : C} (a b : X ⟶ Y) : a + b = a - -b := rfl #align category_theory.non_preadditive_abelian.add_def CategoryTheory.NonPreadditiveAbelian.add_def theorem neg_def {X Y : C} (a : X ⟶ Y) : -a = 0 - a := rfl #align category_theory.non_preadditive_abelian.neg_def CategoryTheory.NonPreadditiveAbelian.neg_def theorem sub_zero {X Y : C} (a : X ⟶ Y) : a - 0 = a := by rw [sub_def] conv_lhs => congr; congr; rw [← Category.comp_id a] case a.g => rw [show 0 = a ≫ (0 : Y ⟶ Y) by simp] rw [← prod.comp_lift, Category.assoc, lift_σ, Category.comp_id] #align category_theory.non_preadditive_abelian.sub_zero CategoryTheory.NonPreadditiveAbelian.sub_zero theorem sub_self {X Y : C} (a : X ⟶ Y) : a - a = 0 := by rw [sub_def, ← Category.comp_id a, ← prod.comp_lift, Category.assoc, diag_σ, comp_zero] #align category_theory.non_preadditive_abelian.sub_self CategoryTheory.NonPreadditiveAbelian.sub_self theorem lift_sub_lift {X Y : C} (a b c d : X ⟶ Y) : prod.lift a b - prod.lift c d = prod.lift (a - c) (b - d) := by simp only [sub_def] ext · rw [Category.assoc, σ_comp, prod.lift_map_assoc, prod.lift_fst, prod.lift_fst, prod.lift_fst] · rw [Category.assoc, σ_comp, prod.lift_map_assoc, prod.lift_snd, prod.lift_snd, prod.lift_snd] #align category_theory.non_preadditive_abelian.lift_sub_lift CategoryTheory.NonPreadditiveAbelian.lift_sub_lift theorem sub_sub_sub {X Y : C} (a b c d : X ⟶ Y) : a - c - (b - d) = a - b - (c - d) := by rw [sub_def, ← lift_sub_lift, sub_def, Category.assoc, σ_comp, prod.lift_map_assoc]; rfl #align category_theory.non_preadditive_abelian.sub_sub_sub CategoryTheory.NonPreadditiveAbelian.sub_sub_sub theorem neg_sub {X Y : C} (a b : X ⟶ Y) : -a - b = -b - a := by conv_lhs => rw [neg_def, ← sub_zero b, sub_sub_sub, sub_zero, ← neg_def] #align category_theory.non_preadditive_abelian.neg_sub CategoryTheory.NonPreadditiveAbelian.neg_sub theorem neg_neg {X Y : C} (a : X ⟶ Y) : - -a = a := by rw [neg_def, neg_def] conv_lhs => congr; rw [← sub_self a] rw [sub_sub_sub, sub_zero, sub_self, sub_zero] #align category_theory.non_preadditive_abelian.neg_neg CategoryTheory.NonPreadditiveAbelian.neg_neg theorem add_comm {X Y : C} (a b : X ⟶ Y) : a + b = b + a := by rw [add_def] conv_lhs => rw [← neg_neg a] rw [neg_def, neg_def, neg_def, sub_sub_sub] conv_lhs => congr next => skip rw [← neg_def, neg_sub] rw [sub_sub_sub, add_def, ← neg_def, neg_neg b, neg_def] #align category_theory.non_preadditive_abelian.add_comm CategoryTheory.NonPreadditiveAbelian.add_comm theorem add_neg {X Y : C} (a b : X ⟶ Y) : a + -b = a - b := by rw [add_def, neg_neg] #align category_theory.non_preadditive_abelian.add_neg CategoryTheory.NonPreadditiveAbelian.add_neg theorem add_neg_self {X Y : C} (a : X ⟶ Y) : a + -a = 0 := by rw [add_neg, sub_self] #align category_theory.non_preadditive_abelian.add_neg_self CategoryTheory.NonPreadditiveAbelian.add_neg_self theorem neg_add_self {X Y : C} (a : X ⟶ Y) : -a + a = 0 := by rw [add_comm, add_neg_self] #align category_theory.non_preadditive_abelian.neg_add_self CategoryTheory.NonPreadditiveAbelian.neg_add_self theorem neg_sub' {X Y : C} (a b : X ⟶ Y) : -(a - b) = -a + b := by rw [neg_def, neg_def] conv_lhs => rw [← sub_self (0 : X ⟶ Y)] rw [sub_sub_sub, add_def, neg_def] #align category_theory.non_preadditive_abelian.neg_sub' CategoryTheory.NonPreadditiveAbelian.neg_sub' theorem neg_add {X Y : C} (a b : X ⟶ Y) : -(a + b) = -a - b := by rw [add_def, neg_sub', add_neg] #align category_theory.non_preadditive_abelian.neg_add CategoryTheory.NonPreadditiveAbelian.neg_add theorem sub_add {X Y : C} (a b c : X ⟶ Y) : a - b + c = a - (b - c) := by rw [add_def, neg_def, sub_sub_sub, sub_zero] #align category_theory.non_preadditive_abelian.sub_add CategoryTheory.NonPreadditiveAbelian.sub_add theorem add_assoc {X Y : C} (a b c : X ⟶ Y) : a + b + c = a + (b + c) := by conv_lhs => congr; rw [add_def] rw [sub_add, ← add_neg, neg_sub', neg_neg] #align category_theory.non_preadditive_abelian.add_assoc CategoryTheory.NonPreadditiveAbelian.add_assoc
Mathlib/CategoryTheory/Abelian/NonPreadditive.lean
424
424
theorem add_zero {X Y : C} (a : X ⟶ Y) : a + 0 = a := by
rw [add_def, neg_def, sub_self, sub_zero]
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv #align_import linear_algebra.affine_space.affine_subspace from "leanprover-community/mathlib"@"e96bdfbd1e8c98a09ff75f7ac6204d142debc840" /-! # Affine spaces This file defines affine subspaces (over modules) and the affine span of a set of points. ## Main definitions * `AffineSubspace k P` is the type of affine subspaces. Unlike affine spaces, affine subspaces are allowed to be empty, and lemmas that do not apply to empty affine subspaces have `Nonempty` hypotheses. There is a `CompleteLattice` structure on affine subspaces. * `AffineSubspace.direction` gives the `Submodule` spanned by the pairwise differences of points in an `AffineSubspace`. There are various lemmas relating to the set of vectors in the `direction`, and relating the lattice structure on affine subspaces to that on their directions. * `AffineSubspace.parallel`, notation `∥`, gives the property of two affine subspaces being parallel (one being a translate of the other). * `affineSpan` gives the affine subspace spanned by a set of points, with `vectorSpan` giving its direction. The `affineSpan` is defined in terms of `spanPoints`, which gives an explicit description of the points contained in the affine span; `spanPoints` itself should generally only be used when that description is required, with `affineSpan` being the main definition for other purposes. Two other descriptions of the affine span are proved equivalent: it is the `sInf` of affine subspaces containing the points, and (if `[Nontrivial k]`) it contains exactly those points that are affine combinations of points in the given set. ## Implementation notes `outParam` is used in the definition of `AddTorsor V P` to make `V` an implicit argument (deduced from `P`) in most cases. As for modules, `k` is an explicit argument rather than implied by `P` or `V`. This file only provides purely algebraic definitions and results. Those depending on analysis or topology are defined elsewhere; see `Analysis.NormedSpace.AddTorsor` and `Topology.Algebra.Affine`. ## References * https://en.wikipedia.org/wiki/Affine_space * https://en.wikipedia.org/wiki/Principal_homogeneous_space -/ noncomputable section open Affine open Set section variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] /-- The submodule spanning the differences of a (possibly empty) set of points. -/ def vectorSpan (s : Set P) : Submodule k V := Submodule.span k (s -ᵥ s) #align vector_span vectorSpan /-- The definition of `vectorSpan`, for rewriting. -/ theorem vectorSpan_def (s : Set P) : vectorSpan k s = Submodule.span k (s -ᵥ s) := rfl #align vector_span_def vectorSpan_def /-- `vectorSpan` is monotone. -/ theorem vectorSpan_mono {s₁ s₂ : Set P} (h : s₁ ⊆ s₂) : vectorSpan k s₁ ≤ vectorSpan k s₂ := Submodule.span_mono (vsub_self_mono h) #align vector_span_mono vectorSpan_mono variable (P) /-- The `vectorSpan` of the empty set is `⊥`. -/ @[simp] theorem vectorSpan_empty : vectorSpan k (∅ : Set P) = (⊥ : Submodule k V) := by rw [vectorSpan_def, vsub_empty, Submodule.span_empty] #align vector_span_empty vectorSpan_empty variable {P} /-- The `vectorSpan` of a single point is `⊥`. -/ @[simp] theorem vectorSpan_singleton (p : P) : vectorSpan k ({p} : Set P) = ⊥ := by simp [vectorSpan_def] #align vector_span_singleton vectorSpan_singleton /-- The `s -ᵥ s` lies within the `vectorSpan k s`. -/ theorem vsub_set_subset_vectorSpan (s : Set P) : s -ᵥ s ⊆ ↑(vectorSpan k s) := Submodule.subset_span #align vsub_set_subset_vector_span vsub_set_subset_vectorSpan /-- Each pairwise difference is in the `vectorSpan`. -/ theorem vsub_mem_vectorSpan {s : Set P} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : p1 -ᵥ p2 ∈ vectorSpan k s := vsub_set_subset_vectorSpan k s (vsub_mem_vsub hp1 hp2) #align vsub_mem_vector_span vsub_mem_vectorSpan /-- The points in the affine span of a (possibly empty) set of points. Use `affineSpan` instead to get an `AffineSubspace k P`. -/ def spanPoints (s : Set P) : Set P := { p | ∃ p1 ∈ s, ∃ v ∈ vectorSpan k s, p = v +ᵥ p1 } #align span_points spanPoints /-- A point in a set is in its affine span. -/ theorem mem_spanPoints (p : P) (s : Set P) : p ∈ s → p ∈ spanPoints k s | hp => ⟨p, hp, 0, Submodule.zero_mem _, (zero_vadd V p).symm⟩ #align mem_span_points mem_spanPoints /-- A set is contained in its `spanPoints`. -/ theorem subset_spanPoints (s : Set P) : s ⊆ spanPoints k s := fun p => mem_spanPoints k p s #align subset_span_points subset_spanPoints /-- The `spanPoints` of a set is nonempty if and only if that set is. -/ @[simp] theorem spanPoints_nonempty (s : Set P) : (spanPoints k s).Nonempty ↔ s.Nonempty := by constructor · contrapose rw [Set.not_nonempty_iff_eq_empty, Set.not_nonempty_iff_eq_empty] intro h simp [h, spanPoints] · exact fun h => h.mono (subset_spanPoints _ _) #align span_points_nonempty spanPoints_nonempty /-- Adding a point in the affine span and a vector in the spanning submodule produces a point in the affine span. -/ theorem vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan {s : Set P} {p : P} {v : V} (hp : p ∈ spanPoints k s) (hv : v ∈ vectorSpan k s) : v +ᵥ p ∈ spanPoints k s := by rcases hp with ⟨p2, ⟨hp2, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩ rw [hv2p, vadd_vadd] exact ⟨p2, hp2, v + v2, (vectorSpan k s).add_mem hv hv2, rfl⟩ #align vadd_mem_span_points_of_mem_span_points_of_mem_vector_span vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan /-- Subtracting two points in the affine span produces a vector in the spanning submodule. -/ theorem vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints {s : Set P} {p1 p2 : P} (hp1 : p1 ∈ spanPoints k s) (hp2 : p2 ∈ spanPoints k s) : p1 -ᵥ p2 ∈ vectorSpan k s := by rcases hp1 with ⟨p1a, ⟨hp1a, ⟨v1, ⟨hv1, hv1p⟩⟩⟩⟩ rcases hp2 with ⟨p2a, ⟨hp2a, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩ rw [hv1p, hv2p, vsub_vadd_eq_vsub_sub (v1 +ᵥ p1a), vadd_vsub_assoc, add_comm, add_sub_assoc] have hv1v2 : v1 - v2 ∈ vectorSpan k s := (vectorSpan k s).sub_mem hv1 hv2 refine (vectorSpan k s).add_mem ?_ hv1v2 exact vsub_mem_vectorSpan k hp1a hp2a #align vsub_mem_vector_span_of_mem_span_points_of_mem_span_points vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints end /-- An `AffineSubspace k P` is a subset of an `AffineSpace V P` that, if not empty, has an affine space structure induced by a corresponding subspace of the `Module k V`. -/ structure AffineSubspace (k : Type*) {V : Type*} (P : Type*) [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] where /-- The affine subspace seen as a subset. -/ carrier : Set P smul_vsub_vadd_mem : ∀ (c : k) {p1 p2 p3 : P}, p1 ∈ carrier → p2 ∈ carrier → p3 ∈ carrier → c • (p1 -ᵥ p2 : V) +ᵥ p3 ∈ carrier #align affine_subspace AffineSubspace namespace Submodule variable {k V : Type*} [Ring k] [AddCommGroup V] [Module k V] /-- Reinterpret `p : Submodule k V` as an `AffineSubspace k V`. -/ def toAffineSubspace (p : Submodule k V) : AffineSubspace k V where carrier := p smul_vsub_vadd_mem _ _ _ _ h₁ h₂ h₃ := p.add_mem (p.smul_mem _ (p.sub_mem h₁ h₂)) h₃ #align submodule.to_affine_subspace Submodule.toAffineSubspace end Submodule namespace AffineSubspace variable (k : Type*) {V : Type*} (P : Type*) [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] instance : SetLike (AffineSubspace k P) P where coe := carrier coe_injective' p q _ := by cases p; cases q; congr /-- A point is in an affine subspace coerced to a set if and only if it is in that affine subspace. -/ -- Porting note: removed `simp`, proof is `simp only [SetLike.mem_coe]` theorem mem_coe (p : P) (s : AffineSubspace k P) : p ∈ (s : Set P) ↔ p ∈ s := Iff.rfl #align affine_subspace.mem_coe AffineSubspace.mem_coe variable {k P} /-- The direction of an affine subspace is the submodule spanned by the pairwise differences of points. (Except in the case of an empty affine subspace, where the direction is the zero submodule, every vector in the direction is the difference of two points in the affine subspace.) -/ def direction (s : AffineSubspace k P) : Submodule k V := vectorSpan k (s : Set P) #align affine_subspace.direction AffineSubspace.direction /-- The direction equals the `vectorSpan`. -/ theorem direction_eq_vectorSpan (s : AffineSubspace k P) : s.direction = vectorSpan k (s : Set P) := rfl #align affine_subspace.direction_eq_vector_span AffineSubspace.direction_eq_vectorSpan /-- Alternative definition of the direction when the affine subspace is nonempty. This is defined so that the order on submodules (as used in the definition of `Submodule.span`) can be used in the proof of `coe_direction_eq_vsub_set`, and is not intended to be used beyond that proof. -/ def directionOfNonempty {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : Submodule k V where carrier := (s : Set P) -ᵥ s zero_mem' := by cases' h with p hp exact vsub_self p ▸ vsub_mem_vsub hp hp add_mem' := by rintro _ _ ⟨p1, hp1, p2, hp2, rfl⟩ ⟨p3, hp3, p4, hp4, rfl⟩ rw [← vadd_vsub_assoc] refine vsub_mem_vsub ?_ hp4 convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp3 rw [one_smul] smul_mem' := by rintro c _ ⟨p1, hp1, p2, hp2, rfl⟩ rw [← vadd_vsub (c • (p1 -ᵥ p2)) p2] refine vsub_mem_vsub ?_ hp2 exact s.smul_vsub_vadd_mem c hp1 hp2 hp2 #align affine_subspace.direction_of_nonempty AffineSubspace.directionOfNonempty /-- `direction_of_nonempty` gives the same submodule as `direction`. -/ theorem directionOfNonempty_eq_direction {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : directionOfNonempty h = s.direction := by refine le_antisymm ?_ (Submodule.span_le.2 Set.Subset.rfl) rw [← SetLike.coe_subset_coe, directionOfNonempty, direction, Submodule.coe_set_mk, AddSubmonoid.coe_set_mk] exact vsub_set_subset_vectorSpan k _ #align affine_subspace.direction_of_nonempty_eq_direction AffineSubspace.directionOfNonempty_eq_direction /-- The set of vectors in the direction of a nonempty affine subspace is given by `vsub_set`. -/ theorem coe_direction_eq_vsub_set {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : (s.direction : Set V) = (s : Set P) -ᵥ s := directionOfNonempty_eq_direction h ▸ rfl #align affine_subspace.coe_direction_eq_vsub_set AffineSubspace.coe_direction_eq_vsub_set /-- A vector is in the direction of a nonempty affine subspace if and only if it is the subtraction of two vectors in the subspace. -/ theorem mem_direction_iff_eq_vsub {s : AffineSubspace k P} (h : (s : Set P).Nonempty) (v : V) : v ∈ s.direction ↔ ∃ p1 ∈ s, ∃ p2 ∈ s, v = p1 -ᵥ p2 := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set h, Set.mem_vsub] simp only [SetLike.mem_coe, eq_comm] #align affine_subspace.mem_direction_iff_eq_vsub AffineSubspace.mem_direction_iff_eq_vsub /-- Adding a vector in the direction to a point in the subspace produces a point in the subspace. -/ theorem vadd_mem_of_mem_direction {s : AffineSubspace k P} {v : V} (hv : v ∈ s.direction) {p : P} (hp : p ∈ s) : v +ᵥ p ∈ s := by rw [mem_direction_iff_eq_vsub ⟨p, hp⟩] at hv rcases hv with ⟨p1, hp1, p2, hp2, hv⟩ rw [hv] convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp rw [one_smul] exact s.mem_coe k P _ #align affine_subspace.vadd_mem_of_mem_direction AffineSubspace.vadd_mem_of_mem_direction /-- Subtracting two points in the subspace produces a vector in the direction. -/ theorem vsub_mem_direction {s : AffineSubspace k P} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : p1 -ᵥ p2 ∈ s.direction := vsub_mem_vectorSpan k hp1 hp2 #align affine_subspace.vsub_mem_direction AffineSubspace.vsub_mem_direction /-- Adding a vector to a point in a subspace produces a point in the subspace if and only if the vector is in the direction. -/ theorem vadd_mem_iff_mem_direction {s : AffineSubspace k P} (v : V) {p : P} (hp : p ∈ s) : v +ᵥ p ∈ s ↔ v ∈ s.direction := ⟨fun h => by simpa using vsub_mem_direction h hp, fun h => vadd_mem_of_mem_direction h hp⟩ #align affine_subspace.vadd_mem_iff_mem_direction AffineSubspace.vadd_mem_iff_mem_direction /-- Adding a vector in the direction to a point produces a point in the subspace if and only if the original point is in the subspace. -/ theorem vadd_mem_iff_mem_of_mem_direction {s : AffineSubspace k P} {v : V} (hv : v ∈ s.direction) {p : P} : v +ᵥ p ∈ s ↔ p ∈ s := by refine ⟨fun h => ?_, fun h => vadd_mem_of_mem_direction hv h⟩ convert vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) h simp #align affine_subspace.vadd_mem_iff_mem_of_mem_direction AffineSubspace.vadd_mem_iff_mem_of_mem_direction /-- Given a point in an affine subspace, the set of vectors in its direction equals the set of vectors subtracting that point on the right. -/ theorem coe_direction_eq_vsub_set_right {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : (s.direction : Set V) = (· -ᵥ p) '' s := by rw [coe_direction_eq_vsub_set ⟨p, hp⟩] refine le_antisymm ?_ ?_ · rintro v ⟨p1, hp1, p2, hp2, rfl⟩ exact ⟨p1 -ᵥ p2 +ᵥ p, vadd_mem_of_mem_direction (vsub_mem_direction hp1 hp2) hp, vadd_vsub _ _⟩ · rintro v ⟨p2, hp2, rfl⟩ exact ⟨p2, hp2, p, hp, rfl⟩ #align affine_subspace.coe_direction_eq_vsub_set_right AffineSubspace.coe_direction_eq_vsub_set_right /-- Given a point in an affine subspace, the set of vectors in its direction equals the set of vectors subtracting that point on the left. -/ theorem coe_direction_eq_vsub_set_left {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : (s.direction : Set V) = (p -ᵥ ·) '' s := by ext v rw [SetLike.mem_coe, ← Submodule.neg_mem_iff, ← SetLike.mem_coe, coe_direction_eq_vsub_set_right hp, Set.mem_image, Set.mem_image] conv_lhs => congr ext rw [← neg_vsub_eq_vsub_rev, neg_inj] #align affine_subspace.coe_direction_eq_vsub_set_left AffineSubspace.coe_direction_eq_vsub_set_left /-- Given a point in an affine subspace, a vector is in its direction if and only if it results from subtracting that point on the right. -/ theorem mem_direction_iff_eq_vsub_right {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (v : V) : v ∈ s.direction ↔ ∃ p2 ∈ s, v = p2 -ᵥ p := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set_right hp] exact ⟨fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩, fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩⟩ #align affine_subspace.mem_direction_iff_eq_vsub_right AffineSubspace.mem_direction_iff_eq_vsub_right /-- Given a point in an affine subspace, a vector is in its direction if and only if it results from subtracting that point on the left. -/ theorem mem_direction_iff_eq_vsub_left {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (v : V) : v ∈ s.direction ↔ ∃ p2 ∈ s, v = p -ᵥ p2 := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set_left hp] exact ⟨fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩, fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩⟩ #align affine_subspace.mem_direction_iff_eq_vsub_left AffineSubspace.mem_direction_iff_eq_vsub_left /-- Given a point in an affine subspace, a result of subtracting that point on the right is in the direction if and only if the other point is in the subspace. -/ theorem vsub_right_mem_direction_iff_mem {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (p2 : P) : p2 -ᵥ p ∈ s.direction ↔ p2 ∈ s := by rw [mem_direction_iff_eq_vsub_right hp] simp #align affine_subspace.vsub_right_mem_direction_iff_mem AffineSubspace.vsub_right_mem_direction_iff_mem /-- Given a point in an affine subspace, a result of subtracting that point on the left is in the direction if and only if the other point is in the subspace. -/ theorem vsub_left_mem_direction_iff_mem {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (p2 : P) : p -ᵥ p2 ∈ s.direction ↔ p2 ∈ s := by rw [mem_direction_iff_eq_vsub_left hp] simp #align affine_subspace.vsub_left_mem_direction_iff_mem AffineSubspace.vsub_left_mem_direction_iff_mem /-- Two affine subspaces are equal if they have the same points. -/ theorem coe_injective : Function.Injective ((↑) : AffineSubspace k P → Set P) := SetLike.coe_injective #align affine_subspace.coe_injective AffineSubspace.coe_injective @[ext] theorem ext {p q : AffineSubspace k P} (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := SetLike.ext h #align affine_subspace.ext AffineSubspace.ext -- Porting note: removed `simp`, proof is `simp only [SetLike.ext'_iff]` theorem ext_iff (s₁ s₂ : AffineSubspace k P) : (s₁ : Set P) = s₂ ↔ s₁ = s₂ := SetLike.ext'_iff.symm #align affine_subspace.ext_iff AffineSubspace.ext_iff /-- Two affine subspaces with the same direction and nonempty intersection are equal. -/ theorem ext_of_direction_eq {s1 s2 : AffineSubspace k P} (hd : s1.direction = s2.direction) (hn : ((s1 : Set P) ∩ s2).Nonempty) : s1 = s2 := by ext p have hq1 := Set.mem_of_mem_inter_left hn.some_mem have hq2 := Set.mem_of_mem_inter_right hn.some_mem constructor · intro hp rw [← vsub_vadd p hn.some] refine vadd_mem_of_mem_direction ?_ hq2 rw [← hd] exact vsub_mem_direction hp hq1 · intro hp rw [← vsub_vadd p hn.some] refine vadd_mem_of_mem_direction ?_ hq1 rw [hd] exact vsub_mem_direction hp hq2 #align affine_subspace.ext_of_direction_eq AffineSubspace.ext_of_direction_eq -- See note [reducible non instances] /-- This is not an instance because it loops with `AddTorsor.nonempty`. -/ abbrev toAddTorsor (s : AffineSubspace k P) [Nonempty s] : AddTorsor s.direction s where vadd a b := ⟨(a : V) +ᵥ (b : P), vadd_mem_of_mem_direction a.2 b.2⟩ zero_vadd := fun a => by ext exact zero_vadd _ _ add_vadd a b c := by ext apply add_vadd vsub a b := ⟨(a : P) -ᵥ (b : P), (vsub_left_mem_direction_iff_mem a.2 _).mpr b.2⟩ vsub_vadd' a b := by ext apply AddTorsor.vsub_vadd' vadd_vsub' a b := by ext apply AddTorsor.vadd_vsub' #align affine_subspace.to_add_torsor AffineSubspace.toAddTorsor attribute [local instance] toAddTorsor @[simp, norm_cast] theorem coe_vsub (s : AffineSubspace k P) [Nonempty s] (a b : s) : ↑(a -ᵥ b) = (a : P) -ᵥ (b : P) := rfl #align affine_subspace.coe_vsub AffineSubspace.coe_vsub @[simp, norm_cast] theorem coe_vadd (s : AffineSubspace k P) [Nonempty s] (a : s.direction) (b : s) : ↑(a +ᵥ b) = (a : V) +ᵥ (b : P) := rfl #align affine_subspace.coe_vadd AffineSubspace.coe_vadd /-- Embedding of an affine subspace to the ambient space, as an affine map. -/ protected def subtype (s : AffineSubspace k P) [Nonempty s] : s →ᵃ[k] P where toFun := (↑) linear := s.direction.subtype map_vadd' _ _ := rfl #align affine_subspace.subtype AffineSubspace.subtype @[simp] theorem subtype_linear (s : AffineSubspace k P) [Nonempty s] : s.subtype.linear = s.direction.subtype := rfl #align affine_subspace.subtype_linear AffineSubspace.subtype_linear theorem subtype_apply (s : AffineSubspace k P) [Nonempty s] (p : s) : s.subtype p = p := rfl #align affine_subspace.subtype_apply AffineSubspace.subtype_apply @[simp] theorem coeSubtype (s : AffineSubspace k P) [Nonempty s] : (s.subtype : s → P) = ((↑) : s → P) := rfl #align affine_subspace.coe_subtype AffineSubspace.coeSubtype theorem injective_subtype (s : AffineSubspace k P) [Nonempty s] : Function.Injective s.subtype := Subtype.coe_injective #align affine_subspace.injective_subtype AffineSubspace.injective_subtype /-- Two affine subspaces with nonempty intersection are equal if and only if their directions are equal. -/ theorem eq_iff_direction_eq_of_mem {s₁ s₂ : AffineSubspace k P} {p : P} (h₁ : p ∈ s₁) (h₂ : p ∈ s₂) : s₁ = s₂ ↔ s₁.direction = s₂.direction := ⟨fun h => h ▸ rfl, fun h => ext_of_direction_eq h ⟨p, h₁, h₂⟩⟩ #align affine_subspace.eq_iff_direction_eq_of_mem AffineSubspace.eq_iff_direction_eq_of_mem /-- Construct an affine subspace from a point and a direction. -/ def mk' (p : P) (direction : Submodule k V) : AffineSubspace k P where carrier := { q | ∃ v ∈ direction, q = v +ᵥ p } smul_vsub_vadd_mem c p1 p2 p3 hp1 hp2 hp3 := by rcases hp1 with ⟨v1, hv1, hp1⟩ rcases hp2 with ⟨v2, hv2, hp2⟩ rcases hp3 with ⟨v3, hv3, hp3⟩ use c • (v1 - v2) + v3, direction.add_mem (direction.smul_mem c (direction.sub_mem hv1 hv2)) hv3 simp [hp1, hp2, hp3, vadd_vadd] #align affine_subspace.mk' AffineSubspace.mk' /-- An affine subspace constructed from a point and a direction contains that point. -/ theorem self_mem_mk' (p : P) (direction : Submodule k V) : p ∈ mk' p direction := ⟨0, ⟨direction.zero_mem, (zero_vadd _ _).symm⟩⟩ #align affine_subspace.self_mem_mk' AffineSubspace.self_mem_mk' /-- An affine subspace constructed from a point and a direction contains the result of adding a vector in that direction to that point. -/ theorem vadd_mem_mk' {v : V} (p : P) {direction : Submodule k V} (hv : v ∈ direction) : v +ᵥ p ∈ mk' p direction := ⟨v, hv, rfl⟩ #align affine_subspace.vadd_mem_mk' AffineSubspace.vadd_mem_mk' /-- An affine subspace constructed from a point and a direction is nonempty. -/ theorem mk'_nonempty (p : P) (direction : Submodule k V) : (mk' p direction : Set P).Nonempty := ⟨p, self_mem_mk' p direction⟩ #align affine_subspace.mk'_nonempty AffineSubspace.mk'_nonempty /-- The direction of an affine subspace constructed from a point and a direction. -/ @[simp] theorem direction_mk' (p : P) (direction : Submodule k V) : (mk' p direction).direction = direction := by ext v rw [mem_direction_iff_eq_vsub (mk'_nonempty _ _)] constructor · rintro ⟨p1, ⟨v1, hv1, hp1⟩, p2, ⟨v2, hv2, hp2⟩, hv⟩ rw [hv, hp1, hp2, vadd_vsub_vadd_cancel_right] exact direction.sub_mem hv1 hv2 · exact fun hv => ⟨v +ᵥ p, vadd_mem_mk' _ hv, p, self_mem_mk' _ _, (vadd_vsub _ _).symm⟩ #align affine_subspace.direction_mk' AffineSubspace.direction_mk' /-- A point lies in an affine subspace constructed from another point and a direction if and only if their difference is in that direction. -/ theorem mem_mk'_iff_vsub_mem {p₁ p₂ : P} {direction : Submodule k V} : p₂ ∈ mk' p₁ direction ↔ p₂ -ᵥ p₁ ∈ direction := by refine ⟨fun h => ?_, fun h => ?_⟩ · rw [← direction_mk' p₁ direction] exact vsub_mem_direction h (self_mem_mk' _ _) · rw [← vsub_vadd p₂ p₁] exact vadd_mem_mk' p₁ h #align affine_subspace.mem_mk'_iff_vsub_mem AffineSubspace.mem_mk'_iff_vsub_mem /-- Constructing an affine subspace from a point in a subspace and that subspace's direction yields the original subspace. -/ @[simp] theorem mk'_eq {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : mk' p s.direction = s := ext_of_direction_eq (direction_mk' p s.direction) ⟨p, Set.mem_inter (self_mem_mk' _ _) hp⟩ #align affine_subspace.mk'_eq AffineSubspace.mk'_eq /-- If an affine subspace contains a set of points, it contains the `spanPoints` of that set. -/ theorem spanPoints_subset_coe_of_subset_coe {s : Set P} {s1 : AffineSubspace k P} (h : s ⊆ s1) : spanPoints k s ⊆ s1 := by rintro p ⟨p1, hp1, v, hv, hp⟩ rw [hp] have hp1s1 : p1 ∈ (s1 : Set P) := Set.mem_of_mem_of_subset hp1 h refine vadd_mem_of_mem_direction ?_ hp1s1 have hs : vectorSpan k s ≤ s1.direction := vectorSpan_mono k h rw [SetLike.le_def] at hs rw [← SetLike.mem_coe] exact Set.mem_of_mem_of_subset hv hs #align affine_subspace.span_points_subset_coe_of_subset_coe AffineSubspace.spanPoints_subset_coe_of_subset_coe end AffineSubspace namespace Submodule variable {k V : Type*} [Ring k] [AddCommGroup V] [Module k V] @[simp] theorem mem_toAffineSubspace {p : Submodule k V} {x : V} : x ∈ p.toAffineSubspace ↔ x ∈ p := Iff.rfl @[simp] theorem toAffineSubspace_direction (s : Submodule k V) : s.toAffineSubspace.direction = s := by ext x; simp [← s.toAffineSubspace.vadd_mem_iff_mem_direction _ s.zero_mem] end Submodule theorem AffineMap.lineMap_mem {k V P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AddTorsor V P] {Q : AffineSubspace k P} {p₀ p₁ : P} (c : k) (h₀ : p₀ ∈ Q) (h₁ : p₁ ∈ Q) : AffineMap.lineMap p₀ p₁ c ∈ Q := by rw [AffineMap.lineMap_apply] exact Q.smul_vsub_vadd_mem c h₁ h₀ h₀ #align affine_map.line_map_mem AffineMap.lineMap_mem section affineSpan variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- The affine span of a set of points is the smallest affine subspace containing those points. (Actually defined here in terms of spans in modules.) -/ def affineSpan (s : Set P) : AffineSubspace k P where carrier := spanPoints k s smul_vsub_vadd_mem c _ _ _ hp1 hp2 hp3 := vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan k hp3 ((vectorSpan k s).smul_mem c (vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints k hp1 hp2)) #align affine_span affineSpan /-- The affine span, converted to a set, is `spanPoints`. -/ @[simp] theorem coe_affineSpan (s : Set P) : (affineSpan k s : Set P) = spanPoints k s := rfl #align coe_affine_span coe_affineSpan /-- A set is contained in its affine span. -/ theorem subset_affineSpan (s : Set P) : s ⊆ affineSpan k s := subset_spanPoints k s #align subset_affine_span subset_affineSpan /-- The direction of the affine span is the `vectorSpan`. -/ theorem direction_affineSpan (s : Set P) : (affineSpan k s).direction = vectorSpan k s := by apply le_antisymm · refine Submodule.span_le.2 ?_ rintro v ⟨p1, ⟨p2, hp2, v1, hv1, hp1⟩, p3, ⟨p4, hp4, v2, hv2, hp3⟩, rfl⟩ simp only [SetLike.mem_coe] rw [hp1, hp3, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc] exact (vectorSpan k s).sub_mem ((vectorSpan k s).add_mem hv1 (vsub_mem_vectorSpan k hp2 hp4)) hv2 · exact vectorSpan_mono k (subset_spanPoints k s) #align direction_affine_span direction_affineSpan /-- A point in a set is in its affine span. -/ theorem mem_affineSpan {p : P} {s : Set P} (hp : p ∈ s) : p ∈ affineSpan k s := mem_spanPoints k p s hp #align mem_affine_span mem_affineSpan end affineSpan namespace AffineSubspace variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [S : AffineSpace V P] instance : CompleteLattice (AffineSubspace k P) := { PartialOrder.lift ((↑) : AffineSubspace k P → Set P) coe_injective with sup := fun s1 s2 => affineSpan k (s1 ∪ s2) le_sup_left := fun s1 s2 => Set.Subset.trans Set.subset_union_left (subset_spanPoints k _) le_sup_right := fun s1 s2 => Set.Subset.trans Set.subset_union_right (subset_spanPoints k _) sup_le := fun s1 s2 s3 hs1 hs2 => spanPoints_subset_coe_of_subset_coe (Set.union_subset hs1 hs2) inf := fun s1 s2 => mk (s1 ∩ s2) fun c p1 p2 p3 hp1 hp2 hp3 => ⟨s1.smul_vsub_vadd_mem c hp1.1 hp2.1 hp3.1, s2.smul_vsub_vadd_mem c hp1.2 hp2.2 hp3.2⟩ inf_le_left := fun _ _ => Set.inter_subset_left inf_le_right := fun _ _ => Set.inter_subset_right le_sInf := fun S s1 hs1 => by -- Porting note: surely there is an easier way? refine Set.subset_sInter (t := (s1 : Set P)) ?_ rintro t ⟨s, _hs, rfl⟩ exact Set.subset_iInter (hs1 s) top := { carrier := Set.univ smul_vsub_vadd_mem := fun _ _ _ _ _ _ _ => Set.mem_univ _ } le_top := fun _ _ _ => Set.mem_univ _ bot := { carrier := ∅ smul_vsub_vadd_mem := fun _ _ _ _ => False.elim } bot_le := fun _ _ => False.elim sSup := fun s => affineSpan k (⋃ s' ∈ s, (s' : Set P)) sInf := fun s => mk (⋂ s' ∈ s, (s' : Set P)) fun c p1 p2 p3 hp1 hp2 hp3 => Set.mem_iInter₂.2 fun s2 hs2 => by rw [Set.mem_iInter₂] at * exact s2.smul_vsub_vadd_mem c (hp1 s2 hs2) (hp2 s2 hs2) (hp3 s2 hs2) le_sSup := fun _ _ h => Set.Subset.trans (Set.subset_biUnion_of_mem h) (subset_spanPoints k _) sSup_le := fun _ _ h => spanPoints_subset_coe_of_subset_coe (Set.iUnion₂_subset h) sInf_le := fun _ _ => Set.biInter_subset_of_mem le_inf := fun _ _ _ => Set.subset_inter } instance : Inhabited (AffineSubspace k P) := ⟨⊤⟩ /-- The `≤` order on subspaces is the same as that on the corresponding sets. -/ theorem le_def (s1 s2 : AffineSubspace k P) : s1 ≤ s2 ↔ (s1 : Set P) ⊆ s2 := Iff.rfl #align affine_subspace.le_def AffineSubspace.le_def /-- One subspace is less than or equal to another if and only if all its points are in the second subspace. -/ theorem le_def' (s1 s2 : AffineSubspace k P) : s1 ≤ s2 ↔ ∀ p ∈ s1, p ∈ s2 := Iff.rfl #align affine_subspace.le_def' AffineSubspace.le_def' /-- The `<` order on subspaces is the same as that on the corresponding sets. -/ theorem lt_def (s1 s2 : AffineSubspace k P) : s1 < s2 ↔ (s1 : Set P) ⊂ s2 := Iff.rfl #align affine_subspace.lt_def AffineSubspace.lt_def /-- One subspace is not less than or equal to another if and only if it has a point not in the second subspace. -/ theorem not_le_iff_exists (s1 s2 : AffineSubspace k P) : ¬s1 ≤ s2 ↔ ∃ p ∈ s1, p ∉ s2 := Set.not_subset #align affine_subspace.not_le_iff_exists AffineSubspace.not_le_iff_exists /-- If a subspace is less than another, there is a point only in the second. -/ theorem exists_of_lt {s1 s2 : AffineSubspace k P} (h : s1 < s2) : ∃ p ∈ s2, p ∉ s1 := Set.exists_of_ssubset h #align affine_subspace.exists_of_lt AffineSubspace.exists_of_lt /-- A subspace is less than another if and only if it is less than or equal to the second subspace and there is a point only in the second. -/ theorem lt_iff_le_and_exists (s1 s2 : AffineSubspace k P) : s1 < s2 ↔ s1 ≤ s2 ∧ ∃ p ∈ s2, p ∉ s1 := by rw [lt_iff_le_not_le, not_le_iff_exists] #align affine_subspace.lt_iff_le_and_exists AffineSubspace.lt_iff_le_and_exists /-- If an affine subspace is nonempty and contained in another with the same direction, they are equal. -/ theorem eq_of_direction_eq_of_nonempty_of_le {s₁ s₂ : AffineSubspace k P} (hd : s₁.direction = s₂.direction) (hn : (s₁ : Set P).Nonempty) (hle : s₁ ≤ s₂) : s₁ = s₂ := let ⟨p, hp⟩ := hn ext_of_direction_eq hd ⟨p, hp, hle hp⟩ #align affine_subspace.eq_of_direction_eq_of_nonempty_of_le AffineSubspace.eq_of_direction_eq_of_nonempty_of_le variable (k V) /-- The affine span is the `sInf` of subspaces containing the given points. -/ theorem affineSpan_eq_sInf (s : Set P) : affineSpan k s = sInf { s' : AffineSubspace k P | s ⊆ s' } := le_antisymm (spanPoints_subset_coe_of_subset_coe <| Set.subset_iInter₂ fun _ => id) (sInf_le (subset_spanPoints k _)) #align affine_subspace.affine_span_eq_Inf AffineSubspace.affineSpan_eq_sInf variable (P) /-- The Galois insertion formed by `affineSpan` and coercion back to a set. -/ protected def gi : GaloisInsertion (affineSpan k) ((↑) : AffineSubspace k P → Set P) where choice s _ := affineSpan k s gc s1 _s2 := ⟨fun h => Set.Subset.trans (subset_spanPoints k s1) h, spanPoints_subset_coe_of_subset_coe⟩ le_l_u _ := subset_spanPoints k _ choice_eq _ _ := rfl #align affine_subspace.gi AffineSubspace.gi /-- The span of the empty set is `⊥`. -/ @[simp] theorem span_empty : affineSpan k (∅ : Set P) = ⊥ := (AffineSubspace.gi k V P).gc.l_bot #align affine_subspace.span_empty AffineSubspace.span_empty /-- The span of `univ` is `⊤`. -/ @[simp] theorem span_univ : affineSpan k (Set.univ : Set P) = ⊤ := eq_top_iff.2 <| subset_spanPoints k _ #align affine_subspace.span_univ AffineSubspace.span_univ variable {k V P} theorem _root_.affineSpan_le {s : Set P} {Q : AffineSubspace k P} : affineSpan k s ≤ Q ↔ s ⊆ (Q : Set P) := (AffineSubspace.gi k V P).gc _ _ #align affine_span_le affineSpan_le variable (k V) {p₁ p₂ : P} /-- The affine span of a single point, coerced to a set, contains just that point. -/ @[simp 1001] -- Porting note: this needs to take priority over `coe_affineSpan` theorem coe_affineSpan_singleton (p : P) : (affineSpan k ({p} : Set P) : Set P) = {p} := by ext x rw [mem_coe, ← vsub_right_mem_direction_iff_mem (mem_affineSpan k (Set.mem_singleton p)) _, direction_affineSpan] simp #align affine_subspace.coe_affine_span_singleton AffineSubspace.coe_affineSpan_singleton /-- A point is in the affine span of a single point if and only if they are equal. -/ @[simp] theorem mem_affineSpan_singleton : p₁ ∈ affineSpan k ({p₂} : Set P) ↔ p₁ = p₂ := by simp [← mem_coe] #align affine_subspace.mem_affine_span_singleton AffineSubspace.mem_affineSpan_singleton @[simp] theorem preimage_coe_affineSpan_singleton (x : P) : ((↑) : affineSpan k ({x} : Set P) → P) ⁻¹' {x} = univ := eq_univ_of_forall fun y => (AffineSubspace.mem_affineSpan_singleton _ _).1 y.2 #align affine_subspace.preimage_coe_affine_span_singleton AffineSubspace.preimage_coe_affineSpan_singleton /-- The span of a union of sets is the sup of their spans. -/ theorem span_union (s t : Set P) : affineSpan k (s ∪ t) = affineSpan k s ⊔ affineSpan k t := (AffineSubspace.gi k V P).gc.l_sup #align affine_subspace.span_union AffineSubspace.span_union /-- The span of a union of an indexed family of sets is the sup of their spans. -/ theorem span_iUnion {ι : Type*} (s : ι → Set P) : affineSpan k (⋃ i, s i) = ⨆ i, affineSpan k (s i) := (AffineSubspace.gi k V P).gc.l_iSup #align affine_subspace.span_Union AffineSubspace.span_iUnion variable (P) /-- `⊤`, coerced to a set, is the whole set of points. -/ @[simp] theorem top_coe : ((⊤ : AffineSubspace k P) : Set P) = Set.univ := rfl #align affine_subspace.top_coe AffineSubspace.top_coe variable {P} /-- All points are in `⊤`. -/ @[simp] theorem mem_top (p : P) : p ∈ (⊤ : AffineSubspace k P) := Set.mem_univ p #align affine_subspace.mem_top AffineSubspace.mem_top variable (P) /-- The direction of `⊤` is the whole module as a submodule. -/ @[simp] theorem direction_top : (⊤ : AffineSubspace k P).direction = ⊤ := by cases' S.nonempty with p ext v refine ⟨imp_intro Submodule.mem_top, fun _hv => ?_⟩ have hpv : (v +ᵥ p -ᵥ p : V) ∈ (⊤ : AffineSubspace k P).direction := vsub_mem_direction (mem_top k V _) (mem_top k V _) rwa [vadd_vsub] at hpv #align affine_subspace.direction_top AffineSubspace.direction_top /-- `⊥`, coerced to a set, is the empty set. -/ @[simp] theorem bot_coe : ((⊥ : AffineSubspace k P) : Set P) = ∅ := rfl #align affine_subspace.bot_coe AffineSubspace.bot_coe theorem bot_ne_top : (⊥ : AffineSubspace k P) ≠ ⊤ := by intro contra rw [← ext_iff, bot_coe, top_coe] at contra exact Set.empty_ne_univ contra #align affine_subspace.bot_ne_top AffineSubspace.bot_ne_top instance : Nontrivial (AffineSubspace k P) := ⟨⟨⊥, ⊤, bot_ne_top k V P⟩⟩ theorem nonempty_of_affineSpan_eq_top {s : Set P} (h : affineSpan k s = ⊤) : s.Nonempty := by rw [Set.nonempty_iff_ne_empty] rintro rfl rw [AffineSubspace.span_empty] at h exact bot_ne_top k V P h #align affine_subspace.nonempty_of_affine_span_eq_top AffineSubspace.nonempty_of_affineSpan_eq_top /-- If the affine span of a set is `⊤`, then the vector span of the same set is the `⊤`. -/ theorem vectorSpan_eq_top_of_affineSpan_eq_top {s : Set P} (h : affineSpan k s = ⊤) : vectorSpan k s = ⊤ := by rw [← direction_affineSpan, h, direction_top] #align affine_subspace.vector_span_eq_top_of_affine_span_eq_top AffineSubspace.vectorSpan_eq_top_of_affineSpan_eq_top /-- For a nonempty set, the affine span is `⊤` iff its vector span is `⊤`. -/ theorem affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty {s : Set P} (hs : s.Nonempty) : affineSpan k s = ⊤ ↔ vectorSpan k s = ⊤ := by refine ⟨vectorSpan_eq_top_of_affineSpan_eq_top k V P, ?_⟩ intro h suffices Nonempty (affineSpan k s) by obtain ⟨p, hp : p ∈ affineSpan k s⟩ := this rw [eq_iff_direction_eq_of_mem hp (mem_top k V p), direction_affineSpan, h, direction_top] obtain ⟨x, hx⟩ := hs exact ⟨⟨x, mem_affineSpan k hx⟩⟩ #align affine_subspace.affine_span_eq_top_iff_vector_span_eq_top_of_nonempty AffineSubspace.affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty /-- For a non-trivial space, the affine span of a set is `⊤` iff its vector span is `⊤`. -/ theorem affineSpan_eq_top_iff_vectorSpan_eq_top_of_nontrivial {s : Set P} [Nontrivial P] : affineSpan k s = ⊤ ↔ vectorSpan k s = ⊤ := by rcases s.eq_empty_or_nonempty with hs | hs · simp [hs, subsingleton_iff_bot_eq_top, AddTorsor.subsingleton_iff V P, not_subsingleton] · rw [affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty k V P hs] #align affine_subspace.affine_span_eq_top_iff_vector_span_eq_top_of_nontrivial AffineSubspace.affineSpan_eq_top_iff_vectorSpan_eq_top_of_nontrivial theorem card_pos_of_affineSpan_eq_top {ι : Type*} [Fintype ι] {p : ι → P} (h : affineSpan k (range p) = ⊤) : 0 < Fintype.card ι := by obtain ⟨-, ⟨i, -⟩⟩ := nonempty_of_affineSpan_eq_top k V P h exact Fintype.card_pos_iff.mpr ⟨i⟩ #align affine_subspace.card_pos_of_affine_span_eq_top AffineSubspace.card_pos_of_affineSpan_eq_top attribute [local instance] toAddTorsor /-- The top affine subspace is linearly equivalent to the affine space. This is the affine version of `Submodule.topEquiv`. -/ @[simps! linear apply symm_apply_coe] def topEquiv : (⊤ : AffineSubspace k P) ≃ᵃ[k] P where toEquiv := Equiv.Set.univ P linear := .ofEq _ _ (direction_top _ _ _) ≪≫ₗ Submodule.topEquiv map_vadd' _p _v := rfl variable {P} /-- No points are in `⊥`. -/ theorem not_mem_bot (p : P) : p ∉ (⊥ : AffineSubspace k P) := Set.not_mem_empty p #align affine_subspace.not_mem_bot AffineSubspace.not_mem_bot variable (P) /-- The direction of `⊥` is the submodule `⊥`. -/ @[simp] theorem direction_bot : (⊥ : AffineSubspace k P).direction = ⊥ := by rw [direction_eq_vectorSpan, bot_coe, vectorSpan_def, vsub_empty, Submodule.span_empty] #align affine_subspace.direction_bot AffineSubspace.direction_bot variable {k V P} @[simp] theorem coe_eq_bot_iff (Q : AffineSubspace k P) : (Q : Set P) = ∅ ↔ Q = ⊥ := coe_injective.eq_iff' (bot_coe _ _ _) #align affine_subspace.coe_eq_bot_iff AffineSubspace.coe_eq_bot_iff @[simp] theorem coe_eq_univ_iff (Q : AffineSubspace k P) : (Q : Set P) = univ ↔ Q = ⊤ := coe_injective.eq_iff' (top_coe _ _ _) #align affine_subspace.coe_eq_univ_iff AffineSubspace.coe_eq_univ_iff theorem nonempty_iff_ne_bot (Q : AffineSubspace k P) : (Q : Set P).Nonempty ↔ Q ≠ ⊥ := by rw [nonempty_iff_ne_empty] exact not_congr Q.coe_eq_bot_iff #align affine_subspace.nonempty_iff_ne_bot AffineSubspace.nonempty_iff_ne_bot theorem eq_bot_or_nonempty (Q : AffineSubspace k P) : Q = ⊥ ∨ (Q : Set P).Nonempty := by rw [nonempty_iff_ne_bot] apply eq_or_ne #align affine_subspace.eq_bot_or_nonempty AffineSubspace.eq_bot_or_nonempty theorem subsingleton_of_subsingleton_span_eq_top {s : Set P} (h₁ : s.Subsingleton) (h₂ : affineSpan k s = ⊤) : Subsingleton P := by obtain ⟨p, hp⟩ := AffineSubspace.nonempty_of_affineSpan_eq_top k V P h₂ have : s = {p} := Subset.antisymm (fun q hq => h₁ hq hp) (by simp [hp]) rw [this, ← AffineSubspace.ext_iff, AffineSubspace.coe_affineSpan_singleton, AffineSubspace.top_coe, eq_comm, ← subsingleton_iff_singleton (mem_univ _)] at h₂ exact subsingleton_of_univ_subsingleton h₂ #align affine_subspace.subsingleton_of_subsingleton_span_eq_top AffineSubspace.subsingleton_of_subsingleton_span_eq_top theorem eq_univ_of_subsingleton_span_eq_top {s : Set P} (h₁ : s.Subsingleton) (h₂ : affineSpan k s = ⊤) : s = (univ : Set P) := by obtain ⟨p, hp⟩ := AffineSubspace.nonempty_of_affineSpan_eq_top k V P h₂ have : s = {p} := Subset.antisymm (fun q hq => h₁ hq hp) (by simp [hp]) rw [this, eq_comm, ← subsingleton_iff_singleton (mem_univ p), subsingleton_univ_iff] exact subsingleton_of_subsingleton_span_eq_top h₁ h₂ #align affine_subspace.eq_univ_of_subsingleton_span_eq_top AffineSubspace.eq_univ_of_subsingleton_span_eq_top /-- A nonempty affine subspace is `⊤` if and only if its direction is `⊤`. -/ @[simp]
Mathlib/LinearAlgebra/AffineSpace/AffineSubspace.lean
888
896
theorem direction_eq_top_iff_of_nonempty {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : s.direction = ⊤ ↔ s = ⊤ := by
constructor · intro hd rw [← direction_top k V P] at hd refine ext_of_direction_eq hd ?_ simp [h] · rintro rfl simp
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Johannes Hölzl, Yury G. Kudryashov, Patrick Massot -/ import Mathlib.Algebra.GeomSum import Mathlib.Order.Filter.Archimedean import Mathlib.Order.Iterate import Mathlib.Topology.Algebra.Algebra import Mathlib.Topology.Algebra.InfiniteSum.Real #align_import analysis.specific_limits.basic from "leanprover-community/mathlib"@"57ac39bd365c2f80589a700f9fbb664d3a1a30c2" /-! # A collection of specific limit computations This file, by design, is independent of `NormedSpace` in the import hierarchy. It contains important specific limit computations in metric spaces, in ordered rings/fields, and in specific instances of these such as `ℝ`, `ℝ≥0` and `ℝ≥0∞`. -/ noncomputable section open scoped Classical open Set Function Filter Finset Metric open scoped Classical open Topology Nat uniformity NNReal ENNReal variable {α : Type*} {β : Type*} {ι : Type*} theorem tendsto_inverse_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ (n : ℝ)⁻¹) atTop (𝓝 0) := tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop #align tendsto_inverse_at_top_nhds_0_nat tendsto_inverse_atTop_nhds_zero_nat @[deprecated (since := "2024-01-31")] alias tendsto_inverse_atTop_nhds_0_nat := tendsto_inverse_atTop_nhds_zero_nat theorem tendsto_const_div_atTop_nhds_zero_nat (C : ℝ) : Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by simpa only [mul_zero] using tendsto_const_nhds.mul tendsto_inverse_atTop_nhds_zero_nat #align tendsto_const_div_at_top_nhds_0_nat tendsto_const_div_atTop_nhds_zero_nat @[deprecated (since := "2024-01-31")] alias tendsto_const_div_atTop_nhds_0_nat := tendsto_const_div_atTop_nhds_zero_nat theorem tendsto_one_div_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ 1/(n : ℝ)) atTop (𝓝 0) := tendsto_const_div_atTop_nhds_zero_nat 1 @[deprecated (since := "2024-01-31")] alias tendsto_one_div_atTop_nhds_0_nat := tendsto_one_div_atTop_nhds_zero_nat theorem NNReal.tendsto_inverse_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ (n : ℝ≥0)⁻¹) atTop (𝓝 0) := by rw [← NNReal.tendsto_coe] exact _root_.tendsto_inverse_atTop_nhds_zero_nat #align nnreal.tendsto_inverse_at_top_nhds_0_nat NNReal.tendsto_inverse_atTop_nhds_zero_nat @[deprecated (since := "2024-01-31")] alias NNReal.tendsto_inverse_atTop_nhds_0_nat := NNReal.tendsto_inverse_atTop_nhds_zero_nat theorem NNReal.tendsto_const_div_atTop_nhds_zero_nat (C : ℝ≥0) : Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by simpa using tendsto_const_nhds.mul NNReal.tendsto_inverse_atTop_nhds_zero_nat #align nnreal.tendsto_const_div_at_top_nhds_0_nat NNReal.tendsto_const_div_atTop_nhds_zero_nat @[deprecated (since := "2024-01-31")] alias NNReal.tendsto_const_div_atTop_nhds_0_nat := NNReal.tendsto_const_div_atTop_nhds_zero_nat theorem tendsto_one_div_add_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ 1 / ((n : ℝ) + 1)) atTop (𝓝 0) := suffices Tendsto (fun n : ℕ ↦ 1 / (↑(n + 1) : ℝ)) atTop (𝓝 0) by simpa (tendsto_add_atTop_iff_nat 1).2 (_root_.tendsto_const_div_atTop_nhds_zero_nat 1) #align tendsto_one_div_add_at_top_nhds_0_nat tendsto_one_div_add_atTop_nhds_zero_nat @[deprecated (since := "2024-01-31")] alias tendsto_one_div_add_atTop_nhds_0_nat := tendsto_one_div_add_atTop_nhds_zero_nat theorem NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat (𝕜 : Type*) [Semiring 𝕜] [Algebra ℝ≥0 𝕜] [TopologicalSpace 𝕜] [ContinuousSMul ℝ≥0 𝕜] : Tendsto (algebraMap ℝ≥0 𝕜 ∘ fun n : ℕ ↦ (n : ℝ≥0)⁻¹) atTop (𝓝 0) := by convert (continuous_algebraMap ℝ≥0 𝕜).continuousAt.tendsto.comp tendsto_inverse_atTop_nhds_zero_nat rw [map_zero] @[deprecated (since := "2024-01-31")] alias NNReal.tendsto_algebraMap_inverse_atTop_nhds_0_nat := NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat theorem tendsto_algebraMap_inverse_atTop_nhds_zero_nat (𝕜 : Type*) [Semiring 𝕜] [Algebra ℝ 𝕜] [TopologicalSpace 𝕜] [ContinuousSMul ℝ 𝕜] : Tendsto (algebraMap ℝ 𝕜 ∘ fun n : ℕ ↦ (n : ℝ)⁻¹) atTop (𝓝 0) := NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat 𝕜 @[deprecated (since := "2024-01-31")] alias tendsto_algebraMap_inverse_atTop_nhds_0_nat := _root_.tendsto_algebraMap_inverse_atTop_nhds_zero_nat /-- The limit of `n / (n + x)` is 1, for any constant `x` (valid in `ℝ` or any topological division algebra over `ℝ`, e.g., `ℂ`). TODO: introduce a typeclass saying that `1 / n` tends to 0 at top, making it possible to get this statement simultaneously on `ℚ`, `ℝ` and `ℂ`. -/ theorem tendsto_natCast_div_add_atTop {𝕜 : Type*} [DivisionRing 𝕜] [TopologicalSpace 𝕜] [CharZero 𝕜] [Algebra ℝ 𝕜] [ContinuousSMul ℝ 𝕜] [TopologicalDivisionRing 𝕜] (x : 𝕜) : Tendsto (fun n : ℕ ↦ (n : 𝕜) / (n + x)) atTop (𝓝 1) := by convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn ↦ _)) _ · exact fun n : ℕ ↦ 1 / (1 + x / n) · field_simp [Nat.cast_ne_zero.mpr hn] · have : 𝓝 (1 : 𝕜) = 𝓝 (1 / (1 + x * (0 : 𝕜))) := by rw [mul_zero, add_zero, div_one] rw [this] refine tendsto_const_nhds.div (tendsto_const_nhds.add ?_) (by simp) simp_rw [div_eq_mul_inv] refine tendsto_const_nhds.mul ?_ have := ((continuous_algebraMap ℝ 𝕜).tendsto _).comp tendsto_inverse_atTop_nhds_zero_nat rw [map_zero, Filter.tendsto_atTop'] at this refine Iff.mpr tendsto_atTop' ?_ intros simp_all only [comp_apply, map_inv₀, map_natCast] #align tendsto_coe_nat_div_add_at_top tendsto_natCast_div_add_atTop /-! ### Powers -/ theorem tendsto_add_one_pow_atTop_atTop_of_pos [LinearOrderedSemiring α] [Archimedean α] {r : α} (h : 0 < r) : Tendsto (fun n : ℕ ↦ (r + 1) ^ n) atTop atTop := tendsto_atTop_atTop_of_monotone' (fun _ _ ↦ pow_le_pow_right <| le_add_of_nonneg_left h.le) <| not_bddAbove_iff.2 fun _ ↦ Set.exists_range_iff.2 <| add_one_pow_unbounded_of_pos _ h #align tendsto_add_one_pow_at_top_at_top_of_pos tendsto_add_one_pow_atTop_atTop_of_pos theorem tendsto_pow_atTop_atTop_of_one_lt [LinearOrderedRing α] [Archimedean α] {r : α} (h : 1 < r) : Tendsto (fun n : ℕ ↦ r ^ n) atTop atTop := sub_add_cancel r 1 ▸ tendsto_add_one_pow_atTop_atTop_of_pos (sub_pos.2 h) #align tendsto_pow_at_top_at_top_of_one_lt tendsto_pow_atTop_atTop_of_one_lt theorem Nat.tendsto_pow_atTop_atTop_of_one_lt {m : ℕ} (h : 1 < m) : Tendsto (fun n : ℕ ↦ m ^ n) atTop atTop := tsub_add_cancel_of_le (le_of_lt h) ▸ tendsto_add_one_pow_atTop_atTop_of_pos (tsub_pos_of_lt h) #align nat.tendsto_pow_at_top_at_top_of_one_lt Nat.tendsto_pow_atTop_atTop_of_one_lt theorem tendsto_pow_atTop_nhds_zero_of_lt_one {𝕜 : Type*} [LinearOrderedField 𝕜] [Archimedean 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} (h₁ : 0 ≤ r) (h₂ : r < 1) : Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) := h₁.eq_or_lt.elim (fun hr ↦ (tendsto_add_atTop_iff_nat 1).mp <| by simp [_root_.pow_succ, ← hr, tendsto_const_nhds]) (fun hr ↦ have := one_lt_inv hr h₂ |> tendsto_pow_atTop_atTop_of_one_lt (tendsto_inv_atTop_zero.comp this).congr fun n ↦ by simp) #align tendsto_pow_at_top_nhds_0_of_lt_1 tendsto_pow_atTop_nhds_zero_of_lt_one @[deprecated (since := "2024-01-31")] alias tendsto_pow_atTop_nhds_0_of_lt_1 := tendsto_pow_atTop_nhds_zero_of_lt_one @[simp] theorem tendsto_pow_atTop_nhds_zero_iff {𝕜 : Type*} [LinearOrderedField 𝕜] [Archimedean 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} : Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) ↔ |r| < 1 := by rw [tendsto_zero_iff_abs_tendsto_zero] refine ⟨fun h ↦ by_contra (fun hr_le ↦ ?_), fun h ↦ ?_⟩ · by_cases hr : 1 = |r| · replace h : Tendsto (fun n : ℕ ↦ |r|^n) atTop (𝓝 0) := by simpa only [← abs_pow, h] simp only [hr.symm, one_pow] at h exact zero_ne_one <| tendsto_nhds_unique h tendsto_const_nhds · apply @not_tendsto_nhds_of_tendsto_atTop 𝕜 ℕ _ _ _ _ atTop _ (fun n ↦ |r| ^ n) _ 0 _ · refine (pow_right_strictMono <| lt_of_le_of_ne (le_of_not_lt hr_le) hr).monotone.tendsto_atTop_atTop (fun b ↦ ?_) obtain ⟨n, hn⟩ := (pow_unbounded_of_one_lt b (lt_of_le_of_ne (le_of_not_lt hr_le) hr)) exact ⟨n, le_of_lt hn⟩ · simpa only [← abs_pow] · simpa only [← abs_pow] using (tendsto_pow_atTop_nhds_zero_of_lt_one (abs_nonneg r)) h @[deprecated (since := "2024-01-31")] alias tendsto_pow_atTop_nhds_0_iff := tendsto_pow_atTop_nhds_zero_iff theorem tendsto_pow_atTop_nhdsWithin_zero_of_lt_one {𝕜 : Type*} [LinearOrderedField 𝕜] [Archimedean 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} (h₁ : 0 < r) (h₂ : r < 1) : Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝[>] 0) := tendsto_inf.2 ⟨tendsto_pow_atTop_nhds_zero_of_lt_one h₁.le h₂, tendsto_principal.2 <| eventually_of_forall fun _ ↦ pow_pos h₁ _⟩ #align tendsto_pow_at_top_nhds_within_0_of_lt_1 tendsto_pow_atTop_nhdsWithin_zero_of_lt_one @[deprecated (since := "2024-01-31")] alias tendsto_pow_atTop_nhdsWithin_0_of_lt_1 := tendsto_pow_atTop_nhdsWithin_zero_of_lt_one theorem uniformity_basis_dist_pow_of_lt_one {α : Type*} [PseudoMetricSpace α] {r : ℝ} (h₀ : 0 < r) (h₁ : r < 1) : (uniformity α).HasBasis (fun _ : ℕ ↦ True) fun k ↦ { p : α × α | dist p.1 p.2 < r ^ k } := Metric.mk_uniformity_basis (fun _ _ ↦ pow_pos h₀ _) fun _ ε0 ↦ (exists_pow_lt_of_lt_one ε0 h₁).imp fun _ hk ↦ ⟨trivial, hk.le⟩ #align uniformity_basis_dist_pow_of_lt_1 uniformity_basis_dist_pow_of_lt_one @[deprecated (since := "2024-01-31")] alias uniformity_basis_dist_pow_of_lt_1 := uniformity_basis_dist_pow_of_lt_one theorem geom_lt {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) {n : ℕ} (hn : 0 < n) (h : ∀ k < n, c * u k < u (k + 1)) : c ^ n * u 0 < u n := by apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_le_of_lt hn _ _ h · simp · simp [_root_.pow_succ', mul_assoc, le_refl] #align geom_lt geom_lt theorem geom_le {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) (n : ℕ) (h : ∀ k < n, c * u k ≤ u (k + 1)) : c ^ n * u 0 ≤ u n := by apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ _ h <;> simp [_root_.pow_succ', mul_assoc, le_refl] #align geom_le geom_le theorem lt_geom {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) {n : ℕ} (hn : 0 < n) (h : ∀ k < n, u (k + 1) < c * u k) : u n < c ^ n * u 0 := by apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_lt_of_le hn _ h _ · simp · simp [_root_.pow_succ', mul_assoc, le_refl] #align lt_geom lt_geom theorem le_geom {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) (n : ℕ) (h : ∀ k < n, u (k + 1) ≤ c * u k) : u n ≤ c ^ n * u 0 := by apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ h _ <;> simp [_root_.pow_succ', mul_assoc, le_refl] #align le_geom le_geom /-- If a sequence `v` of real numbers satisfies `k * v n ≤ v (n+1)` with `1 < k`, then it goes to +∞. -/ theorem tendsto_atTop_of_geom_le {v : ℕ → ℝ} {c : ℝ} (h₀ : 0 < v 0) (hc : 1 < c) (hu : ∀ n, c * v n ≤ v (n + 1)) : Tendsto v atTop atTop := (tendsto_atTop_mono fun n ↦ geom_le (zero_le_one.trans hc.le) n fun k _ ↦ hu k) <| (tendsto_pow_atTop_atTop_of_one_lt hc).atTop_mul_const h₀ #align tendsto_at_top_of_geom_le tendsto_atTop_of_geom_le theorem NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝ≥0} (hr : r < 1) : Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) := NNReal.tendsto_coe.1 <| by simp only [NNReal.coe_pow, NNReal.coe_zero, _root_.tendsto_pow_atTop_nhds_zero_of_lt_one r.coe_nonneg hr] #align nnreal.tendsto_pow_at_top_nhds_0_of_lt_1 NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one @[deprecated (since := "2024-01-31")] alias NNReal.tendsto_pow_atTop_nhds_0_of_lt_1 := NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one @[simp] protected theorem NNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝ≥0} : Tendsto (fun n : ℕ => r ^ n) atTop (𝓝 0) ↔ r < 1 := ⟨fun h => by simpa [coe_pow, coe_zero, abs_eq, coe_lt_one, val_eq_coe] using tendsto_pow_atTop_nhds_zero_iff.mp <| tendsto_coe.mpr h, tendsto_pow_atTop_nhds_zero_of_lt_one⟩ theorem ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝ≥0∞} (hr : r < 1) : Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) := by rcases ENNReal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩ rw [← ENNReal.coe_zero] norm_cast at * apply NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one hr #align ennreal.tendsto_pow_at_top_nhds_0_of_lt_1 ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one @[deprecated (since := "2024-01-31")] alias ENNReal.tendsto_pow_atTop_nhds_0_of_lt_1 := ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one @[simp] protected theorem ENNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝ≥0∞} : Tendsto (fun n : ℕ => r ^ n) atTop (𝓝 0) ↔ r < 1 := by refine ⟨fun h ↦ ?_, tendsto_pow_atTop_nhds_zero_of_lt_one⟩ lift r to NNReal · refine fun hr ↦ top_ne_zero (tendsto_nhds_unique (EventuallyEq.tendsto ?_) (hr ▸ h)) exact eventually_atTop.mpr ⟨1, fun _ hn ↦ pow_eq_top_iff.mpr ⟨rfl, Nat.pos_iff_ne_zero.mp hn⟩⟩ rw [← coe_zero] at h norm_cast at h ⊢ exact NNReal.tendsto_pow_atTop_nhds_zero_iff.mp h /-! ### Geometric series-/ section Geometric theorem hasSum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : HasSum (fun n : ℕ ↦ r ^ n) (1 - r)⁻¹ := have : r ≠ 1 := ne_of_lt h₂ have : Tendsto (fun n ↦ (r ^ n - 1) * (r - 1)⁻¹) atTop (𝓝 ((0 - 1) * (r - 1)⁻¹)) := ((tendsto_pow_atTop_nhds_zero_of_lt_one h₁ h₂).sub tendsto_const_nhds).mul tendsto_const_nhds (hasSum_iff_tendsto_nat_of_nonneg (pow_nonneg h₁) _).mpr <| by simp_all [neg_inv, geom_sum_eq, div_eq_mul_inv] #align has_sum_geometric_of_lt_1 hasSum_geometric_of_lt_one @[deprecated (since := "2024-01-31")] alias hasSum_geometric_of_lt_1 := hasSum_geometric_of_lt_one theorem summable_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : Summable fun n : ℕ ↦ r ^ n := ⟨_, hasSum_geometric_of_lt_one h₁ h₂⟩ #align summable_geometric_of_lt_1 summable_geometric_of_lt_one @[deprecated (since := "2024-01-31")] alias summable_geometric_of_lt_1 := summable_geometric_of_lt_one theorem tsum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : ∑' n : ℕ, r ^ n = (1 - r)⁻¹ := (hasSum_geometric_of_lt_one h₁ h₂).tsum_eq #align tsum_geometric_of_lt_1 tsum_geometric_of_lt_one @[deprecated (since := "2024-01-31")] alias tsum_geometric_of_lt_1 := tsum_geometric_of_lt_one theorem hasSum_geometric_two : HasSum (fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n) 2 := by convert hasSum_geometric_of_lt_one _ _ <;> norm_num #align has_sum_geometric_two hasSum_geometric_two theorem summable_geometric_two : Summable fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n := ⟨_, hasSum_geometric_two⟩ #align summable_geometric_two summable_geometric_two theorem summable_geometric_two_encode {ι : Type*} [Encodable ι] : Summable fun i : ι ↦ (1 / 2 : ℝ) ^ Encodable.encode i := summable_geometric_two.comp_injective Encodable.encode_injective #align summable_geometric_two_encode summable_geometric_two_encode theorem tsum_geometric_two : (∑' n : ℕ, ((1 : ℝ) / 2) ^ n) = 2 := hasSum_geometric_two.tsum_eq #align tsum_geometric_two tsum_geometric_two theorem sum_geometric_two_le (n : ℕ) : (∑ i ∈ range n, (1 / (2 : ℝ)) ^ i) ≤ 2 := by have : ∀ i, 0 ≤ (1 / (2 : ℝ)) ^ i := by intro i apply pow_nonneg norm_num convert sum_le_tsum (range n) (fun i _ ↦ this i) summable_geometric_two exact tsum_geometric_two.symm #align sum_geometric_two_le sum_geometric_two_le theorem tsum_geometric_inv_two : (∑' n : ℕ, (2 : ℝ)⁻¹ ^ n) = 2 := (inv_eq_one_div (2 : ℝ)).symm ▸ tsum_geometric_two #align tsum_geometric_inv_two tsum_geometric_inv_two /-- The sum of `2⁻¹ ^ i` for `n ≤ i` equals `2 * 2⁻¹ ^ n`. -/ theorem tsum_geometric_inv_two_ge (n : ℕ) : (∑' i, ite (n ≤ i) ((2 : ℝ)⁻¹ ^ i) 0) = 2 * 2⁻¹ ^ n := by have A : Summable fun i : ℕ ↦ ite (n ≤ i) ((2⁻¹ : ℝ) ^ i) 0 := by simpa only [← piecewise_eq_indicator, one_div] using summable_geometric_two.indicator {i | n ≤ i} have B : ((Finset.range n).sum fun i : ℕ ↦ ite (n ≤ i) ((2⁻¹ : ℝ) ^ i) 0) = 0 := Finset.sum_eq_zero fun i hi ↦ ite_eq_right_iff.2 fun h ↦ (lt_irrefl _ ((Finset.mem_range.1 hi).trans_le h)).elim simp only [← _root_.sum_add_tsum_nat_add n A, B, if_true, zero_add, zero_le', le_add_iff_nonneg_left, pow_add, _root_.tsum_mul_right, tsum_geometric_inv_two] #align tsum_geometric_inv_two_ge tsum_geometric_inv_two_ge theorem hasSum_geometric_two' (a : ℝ) : HasSum (fun n : ℕ ↦ a / 2 / 2 ^ n) a := by convert HasSum.mul_left (a / 2) (hasSum_geometric_of_lt_one (le_of_lt one_half_pos) one_half_lt_one) using 1 · funext n simp only [one_div, inv_pow] rfl · norm_num #align has_sum_geometric_two' hasSum_geometric_two' theorem summable_geometric_two' (a : ℝ) : Summable fun n : ℕ ↦ a / 2 / 2 ^ n := ⟨a, hasSum_geometric_two' a⟩ #align summable_geometric_two' summable_geometric_two' theorem tsum_geometric_two' (a : ℝ) : ∑' n : ℕ, a / 2 / 2 ^ n = a := (hasSum_geometric_two' a).tsum_eq #align tsum_geometric_two' tsum_geometric_two' /-- **Sum of a Geometric Series** -/ theorem NNReal.hasSum_geometric {r : ℝ≥0} (hr : r < 1) : HasSum (fun n : ℕ ↦ r ^ n) (1 - r)⁻¹ := by apply NNReal.hasSum_coe.1 push_cast rw [NNReal.coe_sub (le_of_lt hr)] exact hasSum_geometric_of_lt_one r.coe_nonneg hr #align nnreal.has_sum_geometric NNReal.hasSum_geometric theorem NNReal.summable_geometric {r : ℝ≥0} (hr : r < 1) : Summable fun n : ℕ ↦ r ^ n := ⟨_, NNReal.hasSum_geometric hr⟩ #align nnreal.summable_geometric NNReal.summable_geometric theorem tsum_geometric_nnreal {r : ℝ≥0} (hr : r < 1) : ∑' n : ℕ, r ^ n = (1 - r)⁻¹ := (NNReal.hasSum_geometric hr).tsum_eq #align tsum_geometric_nnreal tsum_geometric_nnreal /-- The series `pow r` converges to `(1-r)⁻¹`. For `r < 1` the RHS is a finite number, and for `1 ≤ r` the RHS equals `∞`. -/ @[simp] theorem ENNReal.tsum_geometric (r : ℝ≥0∞) : ∑' n : ℕ, r ^ n = (1 - r)⁻¹ := by cases' lt_or_le r 1 with hr hr · rcases ENNReal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩ norm_cast at * convert ENNReal.tsum_coe_eq (NNReal.hasSum_geometric hr) rw [ENNReal.coe_inv <| ne_of_gt <| tsub_pos_iff_lt.2 hr, coe_sub, coe_one] · rw [tsub_eq_zero_iff_le.mpr hr, ENNReal.inv_zero, ENNReal.tsum_eq_iSup_nat, iSup_eq_top] refine fun a ha ↦ (ENNReal.exists_nat_gt (lt_top_iff_ne_top.1 ha)).imp fun n hn ↦ lt_of_lt_of_le hn ?_ calc (n : ℝ≥0∞) = ∑ i ∈ range n, 1 := by rw [sum_const, nsmul_one, card_range] _ ≤ ∑ i ∈ range n, r ^ i := by gcongr; apply one_le_pow_of_one_le' hr #align ennreal.tsum_geometric ENNReal.tsum_geometric theorem ENNReal.tsum_geometric_add_one (r : ℝ≥0∞) : ∑' n : ℕ, r ^ (n + 1) = r * (1 - r)⁻¹ := by simp only [_root_.pow_succ', ENNReal.tsum_mul_left, ENNReal.tsum_geometric] end Geometric /-! ### Sequences with geometrically decaying distance in metric spaces In this paragraph, we discuss sequences in metric spaces or emetric spaces for which the distance between two consecutive terms decays geometrically. We show that such sequences are Cauchy sequences, and bound their distances to the limit. We also discuss series with geometrically decaying terms. -/ section EdistLeGeometric variable [PseudoEMetricSpace α] (r C : ℝ≥0∞) (hr : r < 1) (hC : C ≠ ⊤) {f : ℕ → α} (hu : ∀ n, edist (f n) (f (n + 1)) ≤ C * r ^ n) /-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, `C ≠ ∞`, `r < 1`, then `f` is a Cauchy sequence. -/ theorem cauchySeq_of_edist_le_geometric : CauchySeq f := by refine cauchySeq_of_edist_le_of_tsum_ne_top _ hu ?_ rw [ENNReal.tsum_mul_left, ENNReal.tsum_geometric] refine ENNReal.mul_ne_top hC (ENNReal.inv_ne_top.2 ?_) exact (tsub_pos_iff_lt.2 hr).ne' #align cauchy_seq_of_edist_le_geometric cauchySeq_of_edist_le_geometric /-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from `f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/ theorem edist_le_of_edist_le_geometric_of_tendsto {a : α} (ha : Tendsto f atTop (𝓝 a)) (n : ℕ) : edist (f n) a ≤ C * r ^ n / (1 - r) := by convert edist_le_tsum_of_edist_le_of_tendsto _ hu ha _ simp only [pow_add, ENNReal.tsum_mul_left, ENNReal.tsum_geometric, div_eq_mul_inv, mul_assoc] #align edist_le_of_edist_le_geometric_of_tendsto edist_le_of_edist_le_geometric_of_tendsto /-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from `f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/ theorem edist_le_of_edist_le_geometric_of_tendsto₀ {a : α} (ha : Tendsto f atTop (𝓝 a)) : edist (f 0) a ≤ C / (1 - r) := by simpa only [_root_.pow_zero, mul_one] using edist_le_of_edist_le_geometric_of_tendsto r C hu ha 0 #align edist_le_of_edist_le_geometric_of_tendsto₀ edist_le_of_edist_le_geometric_of_tendsto₀ end EdistLeGeometric section EdistLeGeometricTwo variable [PseudoEMetricSpace α] (C : ℝ≥0∞) (hC : C ≠ ⊤) {f : ℕ → α} (hu : ∀ n, edist (f n) (f (n + 1)) ≤ C / 2 ^ n) {a : α} (ha : Tendsto f atTop (𝓝 a)) /-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then `f` is a Cauchy sequence. -/ theorem cauchySeq_of_edist_le_geometric_two : CauchySeq f := by simp only [div_eq_mul_inv, ENNReal.inv_pow] at hu refine cauchySeq_of_edist_le_geometric 2⁻¹ C ?_ hC hu simp [ENNReal.one_lt_two] #align cauchy_seq_of_edist_le_geometric_two cauchySeq_of_edist_le_geometric_two /-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from `f n` to the limit of `f` is bounded above by `2 * C * 2^-n`. -/ theorem edist_le_of_edist_le_geometric_two_of_tendsto (n : ℕ) : edist (f n) a ≤ 2 * C / 2 ^ n := by simp only [div_eq_mul_inv, ENNReal.inv_pow] at * rw [mul_assoc, mul_comm] convert edist_le_of_edist_le_geometric_of_tendsto 2⁻¹ C hu ha n using 1 rw [ENNReal.one_sub_inv_two, div_eq_mul_inv, inv_inv] #align edist_le_of_edist_le_geometric_two_of_tendsto edist_le_of_edist_le_geometric_two_of_tendsto /-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from `f 0` to the limit of `f` is bounded above by `2 * C`. -/
Mathlib/Analysis/SpecificLimits/Basic.lean
448
450
theorem edist_le_of_edist_le_geometric_two_of_tendsto₀ : edist (f 0) a ≤ 2 * C := by
simpa only [_root_.pow_zero, div_eq_mul_inv, inv_one, mul_one] using edist_le_of_edist_le_geometric_two_of_tendsto C hu ha 0
/- 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, Scott Morrison -/ import Mathlib.Algebra.BigOperators.Finsupp import Mathlib.Algebra.Module.Basic import Mathlib.Algebra.Regular.SMul import Mathlib.Data.Finset.Preimage import Mathlib.Data.Rat.BigOperators import Mathlib.GroupTheory.GroupAction.Hom import Mathlib.Data.Set.Subsingleton #align_import data.finsupp.basic from "leanprover-community/mathlib"@"f69db8cecc668e2d5894d7e9bfc491da60db3b9f" /-! # Miscellaneous definitions, lemmas, and constructions using finsupp ## Main declarations * `Finsupp.graph`: the finset of input and output pairs with non-zero outputs. * `Finsupp.mapRange.equiv`: `Finsupp.mapRange` as an equiv. * `Finsupp.mapDomain`: maps the domain of a `Finsupp` by a function and by summing. * `Finsupp.comapDomain`: postcomposition of a `Finsupp` with a function injective on the preimage of its support. * `Finsupp.some`: restrict a finitely supported function on `Option α` to a finitely supported function on `α`. * `Finsupp.filter`: `filter p f` is the finitely supported function that is `f a` if `p a` is true and 0 otherwise. * `Finsupp.frange`: the image of a finitely supported function on its support. * `Finsupp.subtype_domain`: the restriction of a finitely supported function `f` to a subtype. ## Implementation notes This file is a `noncomputable theory` and uses classical logic throughout. ## TODO * This file is currently ~1600 lines long and is quite a miscellany of definitions and lemmas, so it should be divided into smaller pieces. * Expand the list of definitions and important lemmas to the module docstring. -/ noncomputable section open Finset Function variable {α β γ ι M M' N P G H R S : Type*} namespace Finsupp /-! ### Declarations about `graph` -/ section Graph variable [Zero M] /-- The graph of a finitely supported function over its support, i.e. the finset of input and output pairs with non-zero outputs. -/ def graph (f : α →₀ M) : Finset (α × M) := f.support.map ⟨fun a => Prod.mk a (f a), fun _ _ h => (Prod.mk.inj h).1⟩ #align finsupp.graph Finsupp.graph theorem mk_mem_graph_iff {a : α} {m : M} {f : α →₀ M} : (a, m) ∈ f.graph ↔ f a = m ∧ m ≠ 0 := by simp_rw [graph, mem_map, mem_support_iff] constructor · rintro ⟨b, ha, rfl, -⟩ exact ⟨rfl, ha⟩ · rintro ⟨rfl, ha⟩ exact ⟨a, ha, rfl⟩ #align finsupp.mk_mem_graph_iff Finsupp.mk_mem_graph_iff @[simp] theorem mem_graph_iff {c : α × M} {f : α →₀ M} : c ∈ f.graph ↔ f c.1 = c.2 ∧ c.2 ≠ 0 := by cases c exact mk_mem_graph_iff #align finsupp.mem_graph_iff Finsupp.mem_graph_iff theorem mk_mem_graph (f : α →₀ M) {a : α} (ha : a ∈ f.support) : (a, f a) ∈ f.graph := mk_mem_graph_iff.2 ⟨rfl, mem_support_iff.1 ha⟩ #align finsupp.mk_mem_graph Finsupp.mk_mem_graph theorem apply_eq_of_mem_graph {a : α} {m : M} {f : α →₀ M} (h : (a, m) ∈ f.graph) : f a = m := (mem_graph_iff.1 h).1 #align finsupp.apply_eq_of_mem_graph Finsupp.apply_eq_of_mem_graph @[simp 1100] -- Porting note: change priority to appease `simpNF` theorem not_mem_graph_snd_zero (a : α) (f : α →₀ M) : (a, (0 : M)) ∉ f.graph := fun h => (mem_graph_iff.1 h).2.irrefl #align finsupp.not_mem_graph_snd_zero Finsupp.not_mem_graph_snd_zero @[simp] theorem image_fst_graph [DecidableEq α] (f : α →₀ M) : f.graph.image Prod.fst = f.support := by classical simp only [graph, map_eq_image, image_image, Embedding.coeFn_mk, (· ∘ ·), image_id'] #align finsupp.image_fst_graph Finsupp.image_fst_graph theorem graph_injective (α M) [Zero M] : Injective (@graph α M _) := by intro f g h classical have hsup : f.support = g.support := by rw [← image_fst_graph, h, image_fst_graph] refine ext_iff'.2 ⟨hsup, fun x hx => apply_eq_of_mem_graph <| h.symm ▸ ?_⟩ exact mk_mem_graph _ (hsup ▸ hx) #align finsupp.graph_injective Finsupp.graph_injective @[simp] theorem graph_inj {f g : α →₀ M} : f.graph = g.graph ↔ f = g := (graph_injective α M).eq_iff #align finsupp.graph_inj Finsupp.graph_inj @[simp] theorem graph_zero : graph (0 : α →₀ M) = ∅ := by simp [graph] #align finsupp.graph_zero Finsupp.graph_zero @[simp] theorem graph_eq_empty {f : α →₀ M} : f.graph = ∅ ↔ f = 0 := (graph_injective α M).eq_iff' graph_zero #align finsupp.graph_eq_empty Finsupp.graph_eq_empty end Graph end Finsupp /-! ### Declarations about `mapRange` -/ section MapRange namespace Finsupp section Equiv variable [Zero M] [Zero N] [Zero P] /-- `Finsupp.mapRange` as an equiv. -/ @[simps apply] def mapRange.equiv (f : M ≃ N) (hf : f 0 = 0) (hf' : f.symm 0 = 0) : (α →₀ M) ≃ (α →₀ N) where toFun := (mapRange f hf : (α →₀ M) → α →₀ N) invFun := (mapRange f.symm hf' : (α →₀ N) → α →₀ M) left_inv x := by rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.symm_comp_self] · exact mapRange_id _ · rfl right_inv x := by rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.self_comp_symm] · exact mapRange_id _ · rfl #align finsupp.map_range.equiv Finsupp.mapRange.equiv @[simp] theorem mapRange.equiv_refl : mapRange.equiv (Equiv.refl M) rfl rfl = Equiv.refl (α →₀ M) := Equiv.ext mapRange_id #align finsupp.map_range.equiv_refl Finsupp.mapRange.equiv_refl theorem mapRange.equiv_trans (f : M ≃ N) (hf : f 0 = 0) (hf') (f₂ : N ≃ P) (hf₂ : f₂ 0 = 0) (hf₂') : (mapRange.equiv (f.trans f₂) (by rw [Equiv.trans_apply, hf, hf₂]) (by rw [Equiv.symm_trans_apply, hf₂', hf']) : (α →₀ _) ≃ _) = (mapRange.equiv f hf hf').trans (mapRange.equiv f₂ hf₂ hf₂') := Equiv.ext <| mapRange_comp f₂ hf₂ f hf ((congrArg f₂ hf).trans hf₂) #align finsupp.map_range.equiv_trans Finsupp.mapRange.equiv_trans @[simp] theorem mapRange.equiv_symm (f : M ≃ N) (hf hf') : ((mapRange.equiv f hf hf').symm : (α →₀ _) ≃ _) = mapRange.equiv f.symm hf' hf := Equiv.ext fun _ => rfl #align finsupp.map_range.equiv_symm Finsupp.mapRange.equiv_symm end Equiv section ZeroHom variable [Zero M] [Zero N] [Zero P] /-- Composition with a fixed zero-preserving homomorphism is itself a zero-preserving homomorphism on functions. -/ @[simps] def mapRange.zeroHom (f : ZeroHom M N) : ZeroHom (α →₀ M) (α →₀ N) where toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N) map_zero' := mapRange_zero #align finsupp.map_range.zero_hom Finsupp.mapRange.zeroHom @[simp] theorem mapRange.zeroHom_id : mapRange.zeroHom (ZeroHom.id M) = ZeroHom.id (α →₀ M) := ZeroHom.ext mapRange_id #align finsupp.map_range.zero_hom_id Finsupp.mapRange.zeroHom_id theorem mapRange.zeroHom_comp (f : ZeroHom N P) (f₂ : ZeroHom M N) : (mapRange.zeroHom (f.comp f₂) : ZeroHom (α →₀ _) _) = (mapRange.zeroHom f).comp (mapRange.zeroHom f₂) := ZeroHom.ext <| mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero]) #align finsupp.map_range.zero_hom_comp Finsupp.mapRange.zeroHom_comp end ZeroHom section AddMonoidHom variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] variable {F : Type*} [FunLike F M N] [AddMonoidHomClass F M N] /-- Composition with a fixed additive homomorphism is itself an additive homomorphism on functions. -/ @[simps] def mapRange.addMonoidHom (f : M →+ N) : (α →₀ M) →+ α →₀ N where toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N) map_zero' := mapRange_zero map_add' a b := by dsimp only; exact mapRange_add f.map_add _ _; -- Porting note: `dsimp` needed #align finsupp.map_range.add_monoid_hom Finsupp.mapRange.addMonoidHom @[simp] theorem mapRange.addMonoidHom_id : mapRange.addMonoidHom (AddMonoidHom.id M) = AddMonoidHom.id (α →₀ M) := AddMonoidHom.ext mapRange_id #align finsupp.map_range.add_monoid_hom_id Finsupp.mapRange.addMonoidHom_id theorem mapRange.addMonoidHom_comp (f : N →+ P) (f₂ : M →+ N) : (mapRange.addMonoidHom (f.comp f₂) : (α →₀ _) →+ _) = (mapRange.addMonoidHom f).comp (mapRange.addMonoidHom f₂) := AddMonoidHom.ext <| mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero]) #align finsupp.map_range.add_monoid_hom_comp Finsupp.mapRange.addMonoidHom_comp @[simp] theorem mapRange.addMonoidHom_toZeroHom (f : M →+ N) : (mapRange.addMonoidHom f).toZeroHom = (mapRange.zeroHom f.toZeroHom : ZeroHom (α →₀ _) _) := ZeroHom.ext fun _ => rfl #align finsupp.map_range.add_monoid_hom_to_zero_hom Finsupp.mapRange.addMonoidHom_toZeroHom theorem mapRange_multiset_sum (f : F) (m : Multiset (α →₀ M)) : mapRange f (map_zero f) m.sum = (m.map fun x => mapRange f (map_zero f) x).sum := (mapRange.addMonoidHom (f : M →+ N) : (α →₀ _) →+ _).map_multiset_sum _ #align finsupp.map_range_multiset_sum Finsupp.mapRange_multiset_sum theorem mapRange_finset_sum (f : F) (s : Finset ι) (g : ι → α →₀ M) : mapRange f (map_zero f) (∑ x ∈ s, g x) = ∑ x ∈ s, mapRange f (map_zero f) (g x) := map_sum (mapRange.addMonoidHom (f : M →+ N)) _ _ #align finsupp.map_range_finset_sum Finsupp.mapRange_finset_sum /-- `Finsupp.mapRange.AddMonoidHom` as an equiv. -/ @[simps apply] def mapRange.addEquiv (f : M ≃+ N) : (α →₀ M) ≃+ (α →₀ N) := { mapRange.addMonoidHom f.toAddMonoidHom with toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N) invFun := (mapRange f.symm f.symm.map_zero : (α →₀ N) → α →₀ M) left_inv := fun x => by rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.symm_comp_self] · exact mapRange_id _ · rfl right_inv := fun x => by rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.self_comp_symm] · exact mapRange_id _ · rfl } #align finsupp.map_range.add_equiv Finsupp.mapRange.addEquiv @[simp] theorem mapRange.addEquiv_refl : mapRange.addEquiv (AddEquiv.refl M) = AddEquiv.refl (α →₀ M) := AddEquiv.ext mapRange_id #align finsupp.map_range.add_equiv_refl Finsupp.mapRange.addEquiv_refl theorem mapRange.addEquiv_trans (f : M ≃+ N) (f₂ : N ≃+ P) : (mapRange.addEquiv (f.trans f₂) : (α →₀ M) ≃+ (α →₀ P)) = (mapRange.addEquiv f).trans (mapRange.addEquiv f₂) := AddEquiv.ext (mapRange_comp _ f₂.map_zero _ f.map_zero (by simp)) #align finsupp.map_range.add_equiv_trans Finsupp.mapRange.addEquiv_trans @[simp] theorem mapRange.addEquiv_symm (f : M ≃+ N) : ((mapRange.addEquiv f).symm : (α →₀ _) ≃+ _) = mapRange.addEquiv f.symm := AddEquiv.ext fun _ => rfl #align finsupp.map_range.add_equiv_symm Finsupp.mapRange.addEquiv_symm @[simp] theorem mapRange.addEquiv_toAddMonoidHom (f : M ≃+ N) : ((mapRange.addEquiv f : (α →₀ _) ≃+ _) : _ →+ _) = (mapRange.addMonoidHom f.toAddMonoidHom : (α →₀ _) →+ _) := AddMonoidHom.ext fun _ => rfl #align finsupp.map_range.add_equiv_to_add_monoid_hom Finsupp.mapRange.addEquiv_toAddMonoidHom @[simp] theorem mapRange.addEquiv_toEquiv (f : M ≃+ N) : ↑(mapRange.addEquiv f : (α →₀ _) ≃+ _) = (mapRange.equiv (f : M ≃ N) f.map_zero f.symm.map_zero : (α →₀ _) ≃ _) := Equiv.ext fun _ => rfl #align finsupp.map_range.add_equiv_to_equiv Finsupp.mapRange.addEquiv_toEquiv end AddMonoidHom end Finsupp end MapRange /-! ### Declarations about `equivCongrLeft` -/ section EquivCongrLeft variable [Zero M] namespace Finsupp /-- Given `f : α ≃ β`, we can map `l : α →₀ M` to `equivMapDomain f l : β →₀ M` (computably) by mapping the support forwards and the function backwards. -/ def equivMapDomain (f : α ≃ β) (l : α →₀ M) : β →₀ M where support := l.support.map f.toEmbedding toFun a := l (f.symm a) mem_support_toFun a := by simp only [Finset.mem_map_equiv, mem_support_toFun]; rfl #align finsupp.equiv_map_domain Finsupp.equivMapDomain @[simp] theorem equivMapDomain_apply (f : α ≃ β) (l : α →₀ M) (b : β) : equivMapDomain f l b = l (f.symm b) := rfl #align finsupp.equiv_map_domain_apply Finsupp.equivMapDomain_apply theorem equivMapDomain_symm_apply (f : α ≃ β) (l : β →₀ M) (a : α) : equivMapDomain f.symm l a = l (f a) := rfl #align finsupp.equiv_map_domain_symm_apply Finsupp.equivMapDomain_symm_apply @[simp] theorem equivMapDomain_refl (l : α →₀ M) : equivMapDomain (Equiv.refl _) l = l := by ext x; rfl #align finsupp.equiv_map_domain_refl Finsupp.equivMapDomain_refl theorem equivMapDomain_refl' : equivMapDomain (Equiv.refl _) = @id (α →₀ M) := by ext x; rfl #align finsupp.equiv_map_domain_refl' Finsupp.equivMapDomain_refl' theorem equivMapDomain_trans (f : α ≃ β) (g : β ≃ γ) (l : α →₀ M) : equivMapDomain (f.trans g) l = equivMapDomain g (equivMapDomain f l) := by ext x; rfl #align finsupp.equiv_map_domain_trans Finsupp.equivMapDomain_trans theorem equivMapDomain_trans' (f : α ≃ β) (g : β ≃ γ) : @equivMapDomain _ _ M _ (f.trans g) = equivMapDomain g ∘ equivMapDomain f := by ext x; rfl #align finsupp.equiv_map_domain_trans' Finsupp.equivMapDomain_trans' @[simp] theorem equivMapDomain_single (f : α ≃ β) (a : α) (b : M) : equivMapDomain f (single a b) = single (f a) b := by classical ext x simp only [single_apply, Equiv.apply_eq_iff_eq_symm_apply, equivMapDomain_apply] #align finsupp.equiv_map_domain_single Finsupp.equivMapDomain_single @[simp] theorem equivMapDomain_zero {f : α ≃ β} : equivMapDomain f (0 : α →₀ M) = (0 : β →₀ M) := by ext; simp only [equivMapDomain_apply, coe_zero, Pi.zero_apply] #align finsupp.equiv_map_domain_zero Finsupp.equivMapDomain_zero @[to_additive (attr := simp)] theorem prod_equivMapDomain [CommMonoid N] (f : α ≃ β) (l : α →₀ M) (g : β → M → N): prod (equivMapDomain f l) g = prod l (fun a m => g (f a) m) := by simp [prod, equivMapDomain] /-- Given `f : α ≃ β`, the finitely supported function spaces are also in bijection: `(α →₀ M) ≃ (β →₀ M)`. This is the finitely-supported version of `Equiv.piCongrLeft`. -/ def equivCongrLeft (f : α ≃ β) : (α →₀ M) ≃ (β →₀ M) := by refine ⟨equivMapDomain f, equivMapDomain f.symm, fun f => ?_, fun f => ?_⟩ <;> ext x <;> simp only [equivMapDomain_apply, Equiv.symm_symm, Equiv.symm_apply_apply, Equiv.apply_symm_apply] #align finsupp.equiv_congr_left Finsupp.equivCongrLeft @[simp] theorem equivCongrLeft_apply (f : α ≃ β) (l : α →₀ M) : equivCongrLeft f l = equivMapDomain f l := rfl #align finsupp.equiv_congr_left_apply Finsupp.equivCongrLeft_apply @[simp] theorem equivCongrLeft_symm (f : α ≃ β) : (@equivCongrLeft _ _ M _ f).symm = equivCongrLeft f.symm := rfl #align finsupp.equiv_congr_left_symm Finsupp.equivCongrLeft_symm end Finsupp end EquivCongrLeft section CastFinsupp variable [Zero M] (f : α →₀ M) namespace Nat @[simp, norm_cast] theorem cast_finsupp_prod [CommSemiring R] (g : α → M → ℕ) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) := Nat.cast_prod _ _ #align nat.cast_finsupp_prod Nat.cast_finsupp_prod @[simp, norm_cast] theorem cast_finsupp_sum [CommSemiring R] (g : α → M → ℕ) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) := Nat.cast_sum _ _ #align nat.cast_finsupp_sum Nat.cast_finsupp_sum end Nat namespace Int @[simp, norm_cast] theorem cast_finsupp_prod [CommRing R] (g : α → M → ℤ) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) := Int.cast_prod _ _ #align int.cast_finsupp_prod Int.cast_finsupp_prod @[simp, norm_cast] theorem cast_finsupp_sum [CommRing R] (g : α → M → ℤ) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) := Int.cast_sum _ _ #align int.cast_finsupp_sum Int.cast_finsupp_sum end Int namespace Rat @[simp, norm_cast] theorem cast_finsupp_sum [DivisionRing R] [CharZero R] (g : α → M → ℚ) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) := cast_sum _ _ #align rat.cast_finsupp_sum Rat.cast_finsupp_sum @[simp, norm_cast] theorem cast_finsupp_prod [Field R] [CharZero R] (g : α → M → ℚ) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) := cast_prod _ _ #align rat.cast_finsupp_prod Rat.cast_finsupp_prod end Rat end CastFinsupp /-! ### Declarations about `mapDomain` -/ namespace Finsupp section MapDomain variable [AddCommMonoid M] {v v₁ v₂ : α →₀ M} /-- Given `f : α → β` and `v : α →₀ M`, `mapDomain f v : β →₀ M` is the finitely supported function whose value at `a : β` is the sum of `v x` over all `x` such that `f x = a`. -/ def mapDomain (f : α → β) (v : α →₀ M) : β →₀ M := v.sum fun a => single (f a) #align finsupp.map_domain Finsupp.mapDomain theorem mapDomain_apply {f : α → β} (hf : Function.Injective f) (x : α →₀ M) (a : α) : mapDomain f x (f a) = x a := by rw [mapDomain, sum_apply, sum_eq_single a, single_eq_same] · intro b _ hba exact single_eq_of_ne (hf.ne hba) · intro _ rw [single_zero, coe_zero, Pi.zero_apply] #align finsupp.map_domain_apply Finsupp.mapDomain_apply theorem mapDomain_notin_range {f : α → β} (x : α →₀ M) (a : β) (h : a ∉ Set.range f) : mapDomain f x a = 0 := by rw [mapDomain, sum_apply, sum] exact Finset.sum_eq_zero fun a' _ => single_eq_of_ne fun eq => h <| eq ▸ Set.mem_range_self _ #align finsupp.map_domain_notin_range Finsupp.mapDomain_notin_range @[simp] theorem mapDomain_id : mapDomain id v = v := sum_single _ #align finsupp.map_domain_id Finsupp.mapDomain_id theorem mapDomain_comp {f : α → β} {g : β → γ} : mapDomain (g ∘ f) v = mapDomain g (mapDomain f v) := by refine ((sum_sum_index ?_ ?_).trans ?_).symm · intro exact single_zero _ · intro exact single_add _ refine sum_congr fun _ _ => sum_single_index ?_ exact single_zero _ #align finsupp.map_domain_comp Finsupp.mapDomain_comp @[simp] theorem mapDomain_single {f : α → β} {a : α} {b : M} : mapDomain f (single a b) = single (f a) b := sum_single_index <| single_zero _ #align finsupp.map_domain_single Finsupp.mapDomain_single @[simp] theorem mapDomain_zero {f : α → β} : mapDomain f (0 : α →₀ M) = (0 : β →₀ M) := sum_zero_index #align finsupp.map_domain_zero Finsupp.mapDomain_zero theorem mapDomain_congr {f g : α → β} (h : ∀ x ∈ v.support, f x = g x) : v.mapDomain f = v.mapDomain g := Finset.sum_congr rfl fun _ H => by simp only [h _ H] #align finsupp.map_domain_congr Finsupp.mapDomain_congr theorem mapDomain_add {f : α → β} : mapDomain f (v₁ + v₂) = mapDomain f v₁ + mapDomain f v₂ := sum_add_index' (fun _ => single_zero _) fun _ => single_add _ #align finsupp.map_domain_add Finsupp.mapDomain_add @[simp] theorem mapDomain_equiv_apply {f : α ≃ β} (x : α →₀ M) (a : β) : mapDomain f x a = x (f.symm a) := by conv_lhs => rw [← f.apply_symm_apply a] exact mapDomain_apply f.injective _ _ #align finsupp.map_domain_equiv_apply Finsupp.mapDomain_equiv_apply /-- `Finsupp.mapDomain` is an `AddMonoidHom`. -/ @[simps] def mapDomain.addMonoidHom (f : α → β) : (α →₀ M) →+ β →₀ M where toFun := mapDomain f map_zero' := mapDomain_zero map_add' _ _ := mapDomain_add #align finsupp.map_domain.add_monoid_hom Finsupp.mapDomain.addMonoidHom @[simp] theorem mapDomain.addMonoidHom_id : mapDomain.addMonoidHom id = AddMonoidHom.id (α →₀ M) := AddMonoidHom.ext fun _ => mapDomain_id #align finsupp.map_domain.add_monoid_hom_id Finsupp.mapDomain.addMonoidHom_id theorem mapDomain.addMonoidHom_comp (f : β → γ) (g : α → β) : (mapDomain.addMonoidHom (f ∘ g) : (α →₀ M) →+ γ →₀ M) = (mapDomain.addMonoidHom f).comp (mapDomain.addMonoidHom g) := AddMonoidHom.ext fun _ => mapDomain_comp #align finsupp.map_domain.add_monoid_hom_comp Finsupp.mapDomain.addMonoidHom_comp theorem mapDomain_finset_sum {f : α → β} {s : Finset ι} {v : ι → α →₀ M} : mapDomain f (∑ i ∈ s, v i) = ∑ i ∈ s, mapDomain f (v i) := map_sum (mapDomain.addMonoidHom f) _ _ #align finsupp.map_domain_finset_sum Finsupp.mapDomain_finset_sum theorem mapDomain_sum [Zero N] {f : α → β} {s : α →₀ N} {v : α → N → α →₀ M} : mapDomain f (s.sum v) = s.sum fun a b => mapDomain f (v a b) := map_finsupp_sum (mapDomain.addMonoidHom f : (α →₀ M) →+ β →₀ M) _ _ #align finsupp.map_domain_sum Finsupp.mapDomain_sum theorem mapDomain_support [DecidableEq β] {f : α → β} {s : α →₀ M} : (s.mapDomain f).support ⊆ s.support.image f := Finset.Subset.trans support_sum <| Finset.Subset.trans (Finset.biUnion_mono fun a _ => support_single_subset) <| by rw [Finset.biUnion_singleton] #align finsupp.map_domain_support Finsupp.mapDomain_support theorem mapDomain_apply' (S : Set α) {f : α → β} (x : α →₀ M) (hS : (x.support : Set α) ⊆ S) (hf : Set.InjOn f S) {a : α} (ha : a ∈ S) : mapDomain f x (f a) = x a := by classical rw [mapDomain, sum_apply, sum] simp_rw [single_apply] by_cases hax : a ∈ x.support · rw [← Finset.add_sum_erase _ _ hax, if_pos rfl] convert add_zero (x a) refine Finset.sum_eq_zero fun i hi => if_neg ?_ exact (hf.mono hS).ne (Finset.mem_of_mem_erase hi) hax (Finset.ne_of_mem_erase hi) · rw [not_mem_support_iff.1 hax] refine Finset.sum_eq_zero fun i hi => if_neg ?_ exact hf.ne (hS hi) ha (ne_of_mem_of_not_mem hi hax) #align finsupp.map_domain_apply' Finsupp.mapDomain_apply' theorem mapDomain_support_of_injOn [DecidableEq β] {f : α → β} (s : α →₀ M) (hf : Set.InjOn f s.support) : (mapDomain f s).support = Finset.image f s.support := Finset.Subset.antisymm mapDomain_support <| by intro x hx simp only [mem_image, exists_prop, mem_support_iff, Ne] at hx rcases hx with ⟨hx_w, hx_h_left, rfl⟩ simp only [mem_support_iff, Ne] rw [mapDomain_apply' (↑s.support : Set _) _ _ hf] · exact hx_h_left · simp only [mem_coe, mem_support_iff, Ne] exact hx_h_left · exact Subset.refl _ #align finsupp.map_domain_support_of_inj_on Finsupp.mapDomain_support_of_injOn theorem mapDomain_support_of_injective [DecidableEq β] {f : α → β} (hf : Function.Injective f) (s : α →₀ M) : (mapDomain f s).support = Finset.image f s.support := mapDomain_support_of_injOn s hf.injOn #align finsupp.map_domain_support_of_injective Finsupp.mapDomain_support_of_injective @[to_additive] theorem prod_mapDomain_index [CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N} (h_zero : ∀ b, h b 0 = 1) (h_add : ∀ b m₁ m₂, h b (m₁ + m₂) = h b m₁ * h b m₂) : (mapDomain f s).prod h = s.prod fun a m => h (f a) m := (prod_sum_index h_zero h_add).trans <| prod_congr fun _ _ => prod_single_index (h_zero _) #align finsupp.prod_map_domain_index Finsupp.prod_mapDomain_index #align finsupp.sum_map_domain_index Finsupp.sum_mapDomain_index -- Note that in `prod_mapDomain_index`, `M` is still an additive monoid, -- so there is no analogous version in terms of `MonoidHom`. /-- A version of `sum_mapDomain_index` that takes a bundled `AddMonoidHom`, rather than separate linearity hypotheses. -/ @[simp] theorem sum_mapDomain_index_addMonoidHom [AddCommMonoid N] {f : α → β} {s : α →₀ M} (h : β → M →+ N) : ((mapDomain f s).sum fun b m => h b m) = s.sum fun a m => h (f a) m := sum_mapDomain_index (fun b => (h b).map_zero) (fun b _ _ => (h b).map_add _ _) #align finsupp.sum_map_domain_index_add_monoid_hom Finsupp.sum_mapDomain_index_addMonoidHom theorem embDomain_eq_mapDomain (f : α ↪ β) (v : α →₀ M) : embDomain f v = mapDomain f v := by ext a by_cases h : a ∈ Set.range f · rcases h with ⟨a, rfl⟩ rw [mapDomain_apply f.injective, embDomain_apply] · rw [mapDomain_notin_range, embDomain_notin_range] <;> assumption #align finsupp.emb_domain_eq_map_domain Finsupp.embDomain_eq_mapDomain @[to_additive] theorem prod_mapDomain_index_inj [CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N} (hf : Function.Injective f) : (s.mapDomain f).prod h = s.prod fun a b => h (f a) b := by rw [← Function.Embedding.coeFn_mk f hf, ← embDomain_eq_mapDomain, prod_embDomain] #align finsupp.prod_map_domain_index_inj Finsupp.prod_mapDomain_index_inj #align finsupp.sum_map_domain_index_inj Finsupp.sum_mapDomain_index_inj theorem mapDomain_injective {f : α → β} (hf : Function.Injective f) : Function.Injective (mapDomain f : (α →₀ M) → β →₀ M) := by intro v₁ v₂ eq ext a have : mapDomain f v₁ (f a) = mapDomain f v₂ (f a) := by rw [eq] rwa [mapDomain_apply hf, mapDomain_apply hf] at this #align finsupp.map_domain_injective Finsupp.mapDomain_injective /-- When `f` is an embedding we have an embedding `(α →₀ ℕ) ↪ (β →₀ ℕ)` given by `mapDomain`. -/ @[simps] def mapDomainEmbedding {α β : Type*} (f : α ↪ β) : (α →₀ ℕ) ↪ β →₀ ℕ := ⟨Finsupp.mapDomain f, Finsupp.mapDomain_injective f.injective⟩ #align finsupp.map_domain_embedding Finsupp.mapDomainEmbedding theorem mapDomain.addMonoidHom_comp_mapRange [AddCommMonoid N] (f : α → β) (g : M →+ N) : (mapDomain.addMonoidHom f).comp (mapRange.addMonoidHom g) = (mapRange.addMonoidHom g).comp (mapDomain.addMonoidHom f) := by ext simp only [AddMonoidHom.coe_comp, Finsupp.mapRange_single, Finsupp.mapDomain.addMonoidHom_apply, Finsupp.singleAddHom_apply, eq_self_iff_true, Function.comp_apply, Finsupp.mapDomain_single, Finsupp.mapRange.addMonoidHom_apply] #align finsupp.map_domain.add_monoid_hom_comp_map_range Finsupp.mapDomain.addMonoidHom_comp_mapRange /-- When `g` preserves addition, `mapRange` and `mapDomain` commute. -/ theorem mapDomain_mapRange [AddCommMonoid N] (f : α → β) (v : α →₀ M) (g : M → N) (h0 : g 0 = 0) (hadd : ∀ x y, g (x + y) = g x + g y) : mapDomain f (mapRange g h0 v) = mapRange g h0 (mapDomain f v) := let g' : M →+ N := { toFun := g map_zero' := h0 map_add' := hadd } DFunLike.congr_fun (mapDomain.addMonoidHom_comp_mapRange f g') v #align finsupp.map_domain_map_range Finsupp.mapDomain_mapRange theorem sum_update_add [AddCommMonoid α] [AddCommMonoid β] (f : ι →₀ α) (i : ι) (a : α) (g : ι → α → β) (hg : ∀ i, g i 0 = 0) (hgg : ∀ (j : ι) (a₁ a₂ : α), g j (a₁ + a₂) = g j a₁ + g j a₂) : (f.update i a).sum g + g i (f i) = f.sum g + g i a := by rw [update_eq_erase_add_single, sum_add_index' hg hgg] conv_rhs => rw [← Finsupp.update_self f i] rw [update_eq_erase_add_single, sum_add_index' hg hgg, add_assoc, add_assoc] congr 1 rw [add_comm, sum_single_index (hg _), sum_single_index (hg _)] #align finsupp.sum_update_add Finsupp.sum_update_add theorem mapDomain_injOn (S : Set α) {f : α → β} (hf : Set.InjOn f S) : Set.InjOn (mapDomain f : (α →₀ M) → β →₀ M) { w | (w.support : Set α) ⊆ S } := by intro v₁ hv₁ v₂ hv₂ eq ext a classical by_cases h : a ∈ v₁.support ∪ v₂.support · rw [← mapDomain_apply' S _ hv₁ hf _, ← mapDomain_apply' S _ hv₂ hf _, eq] <;> · apply Set.union_subset hv₁ hv₂ exact mod_cast h · simp only [not_or, mem_union, not_not, mem_support_iff] at h simp [h] #align finsupp.map_domain_inj_on Finsupp.mapDomain_injOn
Mathlib/Data/Finsupp/Basic.lean
670
671
theorem equivMapDomain_eq_mapDomain {M} [AddCommMonoid M] (f : α ≃ β) (l : α →₀ M) : equivMapDomain f l = mapDomain f l := by
ext x; simp [mapDomain_equiv_apply]
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Data.Fin.Tuple.Basic import Mathlib.Data.List.Range #align_import data.fin.vec_notation from "leanprover-community/mathlib"@"2445c98ae4b87eabebdde552593519b9b6dc350c" /-! # Matrix and vector notation This file defines notation for vectors and matrices. Given `a b c d : α`, the notation allows us to write `![a, b, c, d] : Fin 4 → α`. Nesting vectors gives coefficients of a matrix, so `![![a, b], ![c, d]] : Fin 2 → Fin 2 → α`. In later files we introduce `!![a, b; c, d]` as notation for `Matrix.of ![![a, b], ![c, d]]`. ## Main definitions * `vecEmpty` is the empty vector (or `0` by `n` matrix) `![]` * `vecCons` prepends an entry to a vector, so `![a, b]` is `vecCons a (vecCons b vecEmpty)` ## Implementation notes The `simp` lemmas require that one of the arguments is of the form `vecCons _ _`. This ensures `simp` works with entries only when (some) entries are already given. In other words, this notation will only appear in the output of `simp` if it already appears in the input. ## Notations The main new notation is `![a, b]`, which gets expanded to `vecCons a (vecCons b vecEmpty)`. ## Examples Examples of usage can be found in the `test/matrix.lean` file. -/ namespace Matrix universe u variable {α : Type u} section MatrixNotation /-- `![]` is the vector with no entries. -/ def vecEmpty : Fin 0 → α := Fin.elim0 #align matrix.vec_empty Matrix.vecEmpty /-- `vecCons h t` prepends an entry `h` to a vector `t`. The inverse functions are `vecHead` and `vecTail`. The notation `![a, b, ...]` expands to `vecCons a (vecCons b ...)`. -/ def vecCons {n : ℕ} (h : α) (t : Fin n → α) : Fin n.succ → α := Fin.cons h t #align matrix.vec_cons Matrix.vecCons /-- `![...]` notation is used to construct a vector `Fin n → α` using `Matrix.vecEmpty` and `Matrix.vecCons`. For instance, `![a, b, c] : Fin 3` is syntax for `vecCons a (vecCons b (vecCons c vecEmpty))`. Note that this should not be used as syntax for `Matrix` as it generates a term with the wrong type. The `!![a, b; c, d]` syntax (provided by `Matrix.matrixNotation`) should be used instead. -/ syntax (name := vecNotation) "![" term,* "]" : term macro_rules | `(![$term:term, $terms:term,*]) => `(vecCons $term ![$terms,*]) | `(![$term:term]) => `(vecCons $term ![]) | `(![]) => `(vecEmpty) /-- Unexpander for the `![x, y, ...]` notation. -/ @[app_unexpander vecCons] def vecConsUnexpander : Lean.PrettyPrinter.Unexpander | `($_ $term ![$term2, $terms,*]) => `(![$term, $term2, $terms,*]) | `($_ $term ![$term2]) => `(![$term, $term2]) | `($_ $term ![]) => `(![$term]) | _ => throw () /-- Unexpander for the `![]` notation. -/ @[app_unexpander vecEmpty] def vecEmptyUnexpander : Lean.PrettyPrinter.Unexpander | `($_:ident) => `(![]) | _ => throw () /-- `vecHead v` gives the first entry of the vector `v` -/ def vecHead {n : ℕ} (v : Fin n.succ → α) : α := v 0 #align matrix.vec_head Matrix.vecHead /-- `vecTail v` gives a vector consisting of all entries of `v` except the first -/ def vecTail {n : ℕ} (v : Fin n.succ → α) : Fin n → α := v ∘ Fin.succ #align matrix.vec_tail Matrix.vecTail variable {m n : ℕ} /-- Use `![...]` notation for displaying a vector `Fin n → α`, for example: ``` #eval ![1, 2] + ![3, 4] -- ![4, 6] ``` -/ instance _root_.PiFin.hasRepr [Repr α] : Repr (Fin n → α) where reprPrec f _ := Std.Format.bracket "![" (Std.Format.joinSep ((List.finRange n).map fun n => repr (f n)) ("," ++ Std.Format.line)) "]" #align pi_fin.has_repr PiFin.hasRepr end MatrixNotation variable {m n o : ℕ} {m' n' o' : Type*} theorem empty_eq (v : Fin 0 → α) : v = ![] := Subsingleton.elim _ _ #align matrix.empty_eq Matrix.empty_eq section Val @[simp] theorem head_fin_const (a : α) : (vecHead fun _ : Fin (n + 1) => a) = a := rfl #align matrix.head_fin_const Matrix.head_fin_const @[simp] theorem cons_val_zero (x : α) (u : Fin m → α) : vecCons x u 0 = x := rfl #align matrix.cons_val_zero Matrix.cons_val_zero theorem cons_val_zero' (h : 0 < m.succ) (x : α) (u : Fin m → α) : vecCons x u ⟨0, h⟩ = x := rfl #align matrix.cons_val_zero' Matrix.cons_val_zero' @[simp] theorem cons_val_succ (x : α) (u : Fin m → α) (i : Fin m) : vecCons x u i.succ = u i := by simp [vecCons] #align matrix.cons_val_succ Matrix.cons_val_succ @[simp] theorem cons_val_succ' {i : ℕ} (h : i.succ < m.succ) (x : α) (u : Fin m → α) : vecCons x u ⟨i.succ, h⟩ = u ⟨i, Nat.lt_of_succ_lt_succ h⟩ := by simp only [vecCons, Fin.cons, Fin.cases_succ'] #align matrix.cons_val_succ' Matrix.cons_val_succ' @[simp] theorem head_cons (x : α) (u : Fin m → α) : vecHead (vecCons x u) = x := rfl #align matrix.head_cons Matrix.head_cons @[simp] theorem tail_cons (x : α) (u : Fin m → α) : vecTail (vecCons x u) = u := by ext simp [vecTail] #align matrix.tail_cons Matrix.tail_cons @[simp] theorem empty_val' {n' : Type*} (j : n') : (fun i => (![] : Fin 0 → n' → α) i j) = ![] := empty_eq _ #align matrix.empty_val' Matrix.empty_val' @[simp] theorem cons_head_tail (u : Fin m.succ → α) : vecCons (vecHead u) (vecTail u) = u := Fin.cons_self_tail _ #align matrix.cons_head_tail Matrix.cons_head_tail @[simp] theorem range_cons (x : α) (u : Fin n → α) : Set.range (vecCons x u) = {x} ∪ Set.range u := Set.ext fun y => by simp [Fin.exists_fin_succ, eq_comm] #align matrix.range_cons Matrix.range_cons @[simp] theorem range_empty (u : Fin 0 → α) : Set.range u = ∅ := Set.range_eq_empty _ #align matrix.range_empty Matrix.range_empty -- @[simp] -- Porting note (#10618): simp can prove this theorem range_cons_empty (x : α) (u : Fin 0 → α) : Set.range (Matrix.vecCons x u) = {x} := by rw [range_cons, range_empty, Set.union_empty] #align matrix.range_cons_empty Matrix.range_cons_empty -- @[simp] -- Porting note (#10618): simp can prove this (up to commutativity)
Mathlib/Data/Fin/VecNotation.lean
188
190
theorem range_cons_cons_empty (x y : α) (u : Fin 0 → α) : Set.range (vecCons x <| vecCons y u) = {x, y} := by
rw [range_cons, range_cons_empty, Set.singleton_union]
/- Copyright (c) 2021 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Complex.Circle import Mathlib.Analysis.SpecialFunctions.Complex.Log #align_import analysis.special_functions.complex.circle from "leanprover-community/mathlib"@"f333194f5ecd1482191452c5ea60b37d4d6afa08" /-! # Maps on the unit circle In this file we prove some basic lemmas about `expMapCircle` and the restriction of `Complex.arg` to the unit circle. These two maps define a partial equivalence between `circle` and `ℝ`, see `circle.argPartialEquiv` and `circle.argEquiv`, that sends the whole circle to `(-π, π]`. -/ open Complex Function Set open Real namespace circle theorem injective_arg : Injective fun z : circle => arg z := fun z w h => Subtype.ext <| ext_abs_arg ((abs_coe_circle z).trans (abs_coe_circle w).symm) h #align circle.injective_arg circle.injective_arg @[simp] theorem arg_eq_arg {z w : circle} : arg z = arg w ↔ z = w := injective_arg.eq_iff #align circle.arg_eq_arg circle.arg_eq_arg end circle theorem arg_expMapCircle {x : ℝ} (h₁ : -π < x) (h₂ : x ≤ π) : arg (expMapCircle x) = x := by rw [expMapCircle_apply, exp_mul_I, arg_cos_add_sin_mul_I ⟨h₁, h₂⟩] #align arg_exp_map_circle arg_expMapCircle @[simp] theorem expMapCircle_arg (z : circle) : expMapCircle (arg z) = z := circle.injective_arg <| arg_expMapCircle (neg_pi_lt_arg _) (arg_le_pi _) #align exp_map_circle_arg expMapCircle_arg namespace circle /-- `Complex.arg ∘ (↑)` and `expMapCircle` define a partial equivalence between `circle` and `ℝ` with `source = Set.univ` and `target = Set.Ioc (-π) π`. -/ @[simps (config := .asFn)] noncomputable def argPartialEquiv : PartialEquiv circle ℝ where toFun := arg ∘ (↑) invFun := expMapCircle source := univ target := Ioc (-π) π map_source' _ _ := ⟨neg_pi_lt_arg _, arg_le_pi _⟩ map_target' := mapsTo_univ _ _ left_inv' z _ := expMapCircle_arg z right_inv' _ hx := arg_expMapCircle hx.1 hx.2 #align circle.arg_local_equiv circle.argPartialEquiv /-- `Complex.arg` and `expMapCircle` define an equivalence between `circle` and `(-π, π]`. -/ @[simps (config := .asFn)] noncomputable def argEquiv : circle ≃ Ioc (-π) π where toFun z := ⟨arg z, neg_pi_lt_arg _, arg_le_pi _⟩ invFun := expMapCircle ∘ (↑) left_inv _ := argPartialEquiv.left_inv trivial right_inv x := Subtype.ext <| argPartialEquiv.right_inv x.2 #align circle.arg_equiv circle.argEquiv end circle theorem leftInverse_expMapCircle_arg : LeftInverse expMapCircle (arg ∘ (↑)) := expMapCircle_arg #align left_inverse_exp_map_circle_arg leftInverse_expMapCircle_arg theorem invOn_arg_expMapCircle : InvOn (arg ∘ (↑)) expMapCircle (Ioc (-π) π) univ := circle.argPartialEquiv.symm.invOn #align inv_on_arg_exp_map_circle invOn_arg_expMapCircle theorem surjOn_expMapCircle_neg_pi_pi : SurjOn expMapCircle (Ioc (-π) π) univ := circle.argPartialEquiv.symm.surjOn #align surj_on_exp_map_circle_neg_pi_pi surjOn_expMapCircle_neg_pi_pi theorem expMapCircle_eq_expMapCircle {x y : ℝ} : expMapCircle x = expMapCircle y ↔ ∃ m : ℤ, x = y + m * (2 * π) := by rw [Subtype.ext_iff, expMapCircle_apply, expMapCircle_apply, exp_eq_exp_iff_exists_int] refine exists_congr fun n => ?_ rw [← mul_assoc, ← add_mul, mul_left_inj' I_ne_zero] norm_cast #align exp_map_circle_eq_exp_map_circle expMapCircle_eq_expMapCircle theorem periodic_expMapCircle : Periodic expMapCircle (2 * π) := fun z => expMapCircle_eq_expMapCircle.2 ⟨1, by rw [Int.cast_one, one_mul]⟩ #align periodic_exp_map_circle periodic_expMapCircle #adaptation_note /-- nightly-2024-04-14 The simpNF linter now times out on this lemma. See https://github.com/leanprover-community/mathlib4/issues/12229 -/ @[simp, nolint simpNF] theorem expMapCircle_two_pi : expMapCircle (2 * π) = 1 := periodic_expMapCircle.eq.trans expMapCircle_zero #align exp_map_circle_two_pi expMapCircle_two_pi theorem expMapCircle_sub_two_pi (x : ℝ) : expMapCircle (x - 2 * π) = expMapCircle x := periodic_expMapCircle.sub_eq x #align exp_map_circle_sub_two_pi expMapCircle_sub_two_pi theorem expMapCircle_add_two_pi (x : ℝ) : expMapCircle (x + 2 * π) = expMapCircle x := periodic_expMapCircle x #align exp_map_circle_add_two_pi expMapCircle_add_two_pi /-- `expMapCircle`, applied to a `Real.Angle`. -/ noncomputable def Real.Angle.expMapCircle (θ : Real.Angle) : circle := periodic_expMapCircle.lift θ #align real.angle.exp_map_circle Real.Angle.expMapCircle @[simp] theorem Real.Angle.expMapCircle_coe (x : ℝ) : Real.Angle.expMapCircle x = _root_.expMapCircle x := rfl #align real.angle.exp_map_circle_coe Real.Angle.expMapCircle_coe theorem Real.Angle.coe_expMapCircle (θ : Real.Angle) : (θ.expMapCircle : ℂ) = θ.cos + θ.sin * I := by induction θ using Real.Angle.induction_on simp [Complex.exp_mul_I] #align real.angle.coe_exp_map_circle Real.Angle.coe_expMapCircle @[simp]
Mathlib/Analysis/SpecialFunctions/Complex/Circle.lean
130
131
theorem Real.Angle.expMapCircle_zero : Real.Angle.expMapCircle 0 = 1 := by
rw [← Real.Angle.coe_zero, Real.Angle.expMapCircle_coe, _root_.expMapCircle_zero]
/- Copyright (c) 2018 Ellen Arlt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin, Lu-Ming Zhang -/ import Mathlib.Algebra.Algebra.Opposite import Mathlib.Algebra.Algebra.Pi import Mathlib.Algebra.BigOperators.Pi import Mathlib.Algebra.BigOperators.Ring import Mathlib.Algebra.BigOperators.RingEquiv import Mathlib.Algebra.Module.LinearMap.Basic import Mathlib.Algebra.Module.Pi import Mathlib.Algebra.Star.BigOperators import Mathlib.Algebra.Star.Module import Mathlib.Algebra.Star.Pi import Mathlib.Data.Fintype.BigOperators import Mathlib.GroupTheory.GroupAction.BigOperators #align_import data.matrix.basic from "leanprover-community/mathlib"@"eba5bb3155cab51d80af00e8d7d69fa271b1302b" /-! # Matrices This file defines basic properties of matrices. Matrices with rows indexed by `m`, columns indexed by `n`, and entries of type `α` are represented with `Matrix m n α`. For the typical approach of counting rows and columns, `Matrix (Fin m) (Fin n) α` can be used. ## Notation The locale `Matrix` gives the following notation: * `⬝ᵥ` for `Matrix.dotProduct` * `*ᵥ` for `Matrix.mulVec` * `ᵥ*` for `Matrix.vecMul` * `ᵀ` for `Matrix.transpose` * `ᴴ` for `Matrix.conjTranspose` ## Implementation notes For convenience, `Matrix m n α` is defined as `m → n → α`, as this allows elements of the matrix to be accessed with `A i j`. However, it is not advisable to _construct_ matrices using terms of the form `fun i j ↦ _` or even `(fun i j ↦ _ : Matrix m n α)`, as these are not recognized by Lean as having the right type. Instead, `Matrix.of` should be used. ## TODO Under various conditions, multiplication of infinite matrices makes sense. These have not yet been implemented. -/ universe u u' v w /-- `Matrix m n R` is the type of matrices with entries in `R`, whose rows are indexed by `m` and whose columns are indexed by `n`. -/ def Matrix (m : Type u) (n : Type u') (α : Type v) : Type max u u' v := m → n → α #align matrix Matrix variable {l m n o : Type*} {m' : o → Type*} {n' : o → Type*} variable {R : Type*} {S : Type*} {α : Type v} {β : Type w} {γ : Type*} namespace Matrix section Ext variable {M N : Matrix m n α} theorem ext_iff : (∀ i j, M i j = N i j) ↔ M = N := ⟨fun h => funext fun i => funext <| h i, fun h => by simp [h]⟩ #align matrix.ext_iff Matrix.ext_iff @[ext] theorem ext : (∀ i j, M i j = N i j) → M = N := ext_iff.mp #align matrix.ext Matrix.ext end Ext /-- Cast a function into a matrix. The two sides of the equivalence are definitionally equal types. We want to use an explicit cast to distinguish the types because `Matrix` has different instances to pi types (such as `Pi.mul`, which performs elementwise multiplication, vs `Matrix.mul`). If you are defining a matrix, in terms of its entries, use `of (fun i j ↦ _)`. The purpose of this approach is to ensure that terms of the form `(fun i j ↦ _) * (fun i j ↦ _)` do not appear, as the type of `*` can be misleading. Porting note: In Lean 3, it is also safe to use pattern matching in a definition as `| i j := _`, which can only be unfolded when fully-applied. leanprover/lean4#2042 means this does not (currently) work in Lean 4. -/ def of : (m → n → α) ≃ Matrix m n α := Equiv.refl _ #align matrix.of Matrix.of @[simp] theorem of_apply (f : m → n → α) (i j) : of f i j = f i j := rfl #align matrix.of_apply Matrix.of_apply @[simp] theorem of_symm_apply (f : Matrix m n α) (i j) : of.symm f i j = f i j := rfl #align matrix.of_symm_apply Matrix.of_symm_apply /-- `M.map f` is the matrix obtained by applying `f` to each entry of the matrix `M`. This is available in bundled forms as: * `AddMonoidHom.mapMatrix` * `LinearMap.mapMatrix` * `RingHom.mapMatrix` * `AlgHom.mapMatrix` * `Equiv.mapMatrix` * `AddEquiv.mapMatrix` * `LinearEquiv.mapMatrix` * `RingEquiv.mapMatrix` * `AlgEquiv.mapMatrix` -/ def map (M : Matrix m n α) (f : α → β) : Matrix m n β := of fun i j => f (M i j) #align matrix.map Matrix.map @[simp] theorem map_apply {M : Matrix m n α} {f : α → β} {i : m} {j : n} : M.map f i j = f (M i j) := rfl #align matrix.map_apply Matrix.map_apply @[simp] theorem map_id (M : Matrix m n α) : M.map id = M := by ext rfl #align matrix.map_id Matrix.map_id @[simp] theorem map_id' (M : Matrix m n α) : M.map (·) = M := map_id M @[simp] theorem map_map {M : Matrix m n α} {β γ : Type*} {f : α → β} {g : β → γ} : (M.map f).map g = M.map (g ∘ f) := by ext rfl #align matrix.map_map Matrix.map_map theorem map_injective {f : α → β} (hf : Function.Injective f) : Function.Injective fun M : Matrix m n α => M.map f := fun _ _ h => ext fun i j => hf <| ext_iff.mpr h i j #align matrix.map_injective Matrix.map_injective /-- The transpose of a matrix. -/ def transpose (M : Matrix m n α) : Matrix n m α := of fun x y => M y x #align matrix.transpose Matrix.transpose -- TODO: set as an equation lemma for `transpose`, see mathlib4#3024 @[simp] theorem transpose_apply (M : Matrix m n α) (i j) : transpose M i j = M j i := rfl #align matrix.transpose_apply Matrix.transpose_apply @[inherit_doc] scoped postfix:1024 "ᵀ" => Matrix.transpose /-- The conjugate transpose of a matrix defined in term of `star`. -/ def conjTranspose [Star α] (M : Matrix m n α) : Matrix n m α := M.transpose.map star #align matrix.conj_transpose Matrix.conjTranspose @[inherit_doc] scoped postfix:1024 "ᴴ" => Matrix.conjTranspose instance inhabited [Inhabited α] : Inhabited (Matrix m n α) := inferInstanceAs <| Inhabited <| m → n → α -- Porting note: new, Lean3 found this automatically instance decidableEq [DecidableEq α] [Fintype m] [Fintype n] : DecidableEq (Matrix m n α) := Fintype.decidablePiFintype instance {n m} [Fintype m] [DecidableEq m] [Fintype n] [DecidableEq n] (α) [Fintype α] : Fintype (Matrix m n α) := inferInstanceAs (Fintype (m → n → α)) instance {n m} [Finite m] [Finite n] (α) [Finite α] : Finite (Matrix m n α) := inferInstanceAs (Finite (m → n → α)) instance add [Add α] : Add (Matrix m n α) := Pi.instAdd instance addSemigroup [AddSemigroup α] : AddSemigroup (Matrix m n α) := Pi.addSemigroup instance addCommSemigroup [AddCommSemigroup α] : AddCommSemigroup (Matrix m n α) := Pi.addCommSemigroup instance zero [Zero α] : Zero (Matrix m n α) := Pi.instZero instance addZeroClass [AddZeroClass α] : AddZeroClass (Matrix m n α) := Pi.addZeroClass instance addMonoid [AddMonoid α] : AddMonoid (Matrix m n α) := Pi.addMonoid instance addCommMonoid [AddCommMonoid α] : AddCommMonoid (Matrix m n α) := Pi.addCommMonoid instance neg [Neg α] : Neg (Matrix m n α) := Pi.instNeg instance sub [Sub α] : Sub (Matrix m n α) := Pi.instSub instance addGroup [AddGroup α] : AddGroup (Matrix m n α) := Pi.addGroup instance addCommGroup [AddCommGroup α] : AddCommGroup (Matrix m n α) := Pi.addCommGroup instance unique [Unique α] : Unique (Matrix m n α) := Pi.unique instance subsingleton [Subsingleton α] : Subsingleton (Matrix m n α) := inferInstanceAs <| Subsingleton <| m → n → α instance nonempty [Nonempty m] [Nonempty n] [Nontrivial α] : Nontrivial (Matrix m n α) := Function.nontrivial instance smul [SMul R α] : SMul R (Matrix m n α) := Pi.instSMul instance smulCommClass [SMul R α] [SMul S α] [SMulCommClass R S α] : SMulCommClass R S (Matrix m n α) := Pi.smulCommClass instance isScalarTower [SMul R S] [SMul R α] [SMul S α] [IsScalarTower R S α] : IsScalarTower R S (Matrix m n α) := Pi.isScalarTower instance isCentralScalar [SMul R α] [SMul Rᵐᵒᵖ α] [IsCentralScalar R α] : IsCentralScalar R (Matrix m n α) := Pi.isCentralScalar instance mulAction [Monoid R] [MulAction R α] : MulAction R (Matrix m n α) := Pi.mulAction _ instance distribMulAction [Monoid R] [AddMonoid α] [DistribMulAction R α] : DistribMulAction R (Matrix m n α) := Pi.distribMulAction _ instance module [Semiring R] [AddCommMonoid α] [Module R α] : Module R (Matrix m n α) := Pi.module _ _ _ -- Porting note (#10756): added the following section with simp lemmas because `simp` fails -- to apply the corresponding lemmas in the namespace `Pi`. -- (e.g. `Pi.zero_apply` used on `OfNat.ofNat 0 i j`) section @[simp] theorem zero_apply [Zero α] (i : m) (j : n) : (0 : Matrix m n α) i j = 0 := rfl @[simp] theorem add_apply [Add α] (A B : Matrix m n α) (i : m) (j : n) : (A + B) i j = (A i j) + (B i j) := rfl @[simp] theorem smul_apply [SMul β α] (r : β) (A : Matrix m n α) (i : m) (j : n) : (r • A) i j = r • (A i j) := rfl @[simp] theorem sub_apply [Sub α] (A B : Matrix m n α) (i : m) (j : n) : (A - B) i j = (A i j) - (B i j) := rfl @[simp] theorem neg_apply [Neg α] (A : Matrix m n α) (i : m) (j : n) : (-A) i j = -(A i j) := rfl end /-! simp-normal form pulls `of` to the outside. -/ @[simp] theorem of_zero [Zero α] : of (0 : m → n → α) = 0 := rfl #align matrix.of_zero Matrix.of_zero @[simp] theorem of_add_of [Add α] (f g : m → n → α) : of f + of g = of (f + g) := rfl #align matrix.of_add_of Matrix.of_add_of @[simp] theorem of_sub_of [Sub α] (f g : m → n → α) : of f - of g = of (f - g) := rfl #align matrix.of_sub_of Matrix.of_sub_of @[simp] theorem neg_of [Neg α] (f : m → n → α) : -of f = of (-f) := rfl #align matrix.neg_of Matrix.neg_of @[simp] theorem smul_of [SMul R α] (r : R) (f : m → n → α) : r • of f = of (r • f) := rfl #align matrix.smul_of Matrix.smul_of @[simp] protected theorem map_zero [Zero α] [Zero β] (f : α → β) (h : f 0 = 0) : (0 : Matrix m n α).map f = 0 := by ext simp [h] #align matrix.map_zero Matrix.map_zero protected theorem map_add [Add α] [Add β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ + a₂) = f a₁ + f a₂) (M N : Matrix m n α) : (M + N).map f = M.map f + N.map f := ext fun _ _ => hf _ _ #align matrix.map_add Matrix.map_add protected theorem map_sub [Sub α] [Sub β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ - a₂) = f a₁ - f a₂) (M N : Matrix m n α) : (M - N).map f = M.map f - N.map f := ext fun _ _ => hf _ _ #align matrix.map_sub Matrix.map_sub theorem map_smul [SMul R α] [SMul R β] (f : α → β) (r : R) (hf : ∀ a, f (r • a) = r • f a) (M : Matrix m n α) : (r • M).map f = r • M.map f := ext fun _ _ => hf _ #align matrix.map_smul Matrix.map_smul /-- The scalar action via `Mul.toSMul` is transformed by the same map as the elements of the matrix, when `f` preserves multiplication. -/ theorem map_smul' [Mul α] [Mul β] (f : α → β) (r : α) (A : Matrix n n α) (hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) : (r • A).map f = f r • A.map f := ext fun _ _ => hf _ _ #align matrix.map_smul' Matrix.map_smul' /-- The scalar action via `mul.toOppositeSMul` is transformed by the same map as the elements of the matrix, when `f` preserves multiplication. -/ theorem map_op_smul' [Mul α] [Mul β] (f : α → β) (r : α) (A : Matrix n n α) (hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) : (MulOpposite.op r • A).map f = MulOpposite.op (f r) • A.map f := ext fun _ _ => hf _ _ #align matrix.map_op_smul' Matrix.map_op_smul' theorem _root_.IsSMulRegular.matrix [SMul R S] {k : R} (hk : IsSMulRegular S k) : IsSMulRegular (Matrix m n S) k := IsSMulRegular.pi fun _ => IsSMulRegular.pi fun _ => hk #align is_smul_regular.matrix IsSMulRegular.matrix theorem _root_.IsLeftRegular.matrix [Mul α] {k : α} (hk : IsLeftRegular k) : IsSMulRegular (Matrix m n α) k := hk.isSMulRegular.matrix #align is_left_regular.matrix IsLeftRegular.matrix instance subsingleton_of_empty_left [IsEmpty m] : Subsingleton (Matrix m n α) := ⟨fun M N => by ext i exact isEmptyElim i⟩ #align matrix.subsingleton_of_empty_left Matrix.subsingleton_of_empty_left instance subsingleton_of_empty_right [IsEmpty n] : Subsingleton (Matrix m n α) := ⟨fun M N => by ext i j exact isEmptyElim j⟩ #align matrix.subsingleton_of_empty_right Matrix.subsingleton_of_empty_right end Matrix open Matrix namespace Matrix section Diagonal variable [DecidableEq n] /-- `diagonal d` is the square matrix such that `(diagonal d) i i = d i` and `(diagonal d) i j = 0` if `i ≠ j`. Note that bundled versions exist as: * `Matrix.diagonalAddMonoidHom` * `Matrix.diagonalLinearMap` * `Matrix.diagonalRingHom` * `Matrix.diagonalAlgHom` -/ def diagonal [Zero α] (d : n → α) : Matrix n n α := of fun i j => if i = j then d i else 0 #align matrix.diagonal Matrix.diagonal -- TODO: set as an equation lemma for `diagonal`, see mathlib4#3024 theorem diagonal_apply [Zero α] (d : n → α) (i j) : diagonal d i j = if i = j then d i else 0 := rfl #align matrix.diagonal_apply Matrix.diagonal_apply @[simp] theorem diagonal_apply_eq [Zero α] (d : n → α) (i : n) : (diagonal d) i i = d i := by simp [diagonal] #align matrix.diagonal_apply_eq Matrix.diagonal_apply_eq @[simp] theorem diagonal_apply_ne [Zero α] (d : n → α) {i j : n} (h : i ≠ j) : (diagonal d) i j = 0 := by simp [diagonal, h] #align matrix.diagonal_apply_ne Matrix.diagonal_apply_ne theorem diagonal_apply_ne' [Zero α] (d : n → α) {i j : n} (h : j ≠ i) : (diagonal d) i j = 0 := diagonal_apply_ne d h.symm #align matrix.diagonal_apply_ne' Matrix.diagonal_apply_ne' @[simp] theorem diagonal_eq_diagonal_iff [Zero α] {d₁ d₂ : n → α} : diagonal d₁ = diagonal d₂ ↔ ∀ i, d₁ i = d₂ i := ⟨fun h i => by simpa using congr_arg (fun m : Matrix n n α => m i i) h, fun h => by rw [show d₁ = d₂ from funext h]⟩ #align matrix.diagonal_eq_diagonal_iff Matrix.diagonal_eq_diagonal_iff theorem diagonal_injective [Zero α] : Function.Injective (diagonal : (n → α) → Matrix n n α) := fun d₁ d₂ h => funext fun i => by simpa using Matrix.ext_iff.mpr h i i #align matrix.diagonal_injective Matrix.diagonal_injective @[simp] theorem diagonal_zero [Zero α] : (diagonal fun _ => 0 : Matrix n n α) = 0 := by ext simp [diagonal] #align matrix.diagonal_zero Matrix.diagonal_zero @[simp] theorem diagonal_transpose [Zero α] (v : n → α) : (diagonal v)ᵀ = diagonal v := by ext i j by_cases h : i = j · simp [h, transpose] · simp [h, transpose, diagonal_apply_ne' _ h] #align matrix.diagonal_transpose Matrix.diagonal_transpose @[simp] theorem diagonal_add [AddZeroClass α] (d₁ d₂ : n → α) : diagonal d₁ + diagonal d₂ = diagonal fun i => d₁ i + d₂ i := by ext i j by_cases h : i = j <;> simp [h] #align matrix.diagonal_add Matrix.diagonal_add @[simp] theorem diagonal_smul [Zero α] [SMulZeroClass R α] (r : R) (d : n → α) : diagonal (r • d) = r • diagonal d := by ext i j by_cases h : i = j <;> simp [h] #align matrix.diagonal_smul Matrix.diagonal_smul @[simp] theorem diagonal_neg [NegZeroClass α] (d : n → α) : -diagonal d = diagonal fun i => -d i := by ext i j by_cases h : i = j <;> simp [h] #align matrix.diagonal_neg Matrix.diagonal_neg @[simp] theorem diagonal_sub [SubNegZeroMonoid α] (d₁ d₂ : n → α) : diagonal d₁ - diagonal d₂ = diagonal fun i => d₁ i - d₂ i := by ext i j by_cases h : i = j <;> simp [h] instance [Zero α] [NatCast α] : NatCast (Matrix n n α) where natCast m := diagonal fun _ => m @[norm_cast] theorem diagonal_natCast [Zero α] [NatCast α] (m : ℕ) : diagonal (fun _ : n => (m : α)) = m := rfl @[norm_cast] theorem diagonal_natCast' [Zero α] [NatCast α] (m : ℕ) : diagonal ((m : n → α)) = m := rfl -- See note [no_index around OfNat.ofNat] theorem diagonal_ofNat [Zero α] [NatCast α] (m : ℕ) [m.AtLeastTwo] : diagonal (fun _ : n => no_index (OfNat.ofNat m : α)) = OfNat.ofNat m := rfl -- See note [no_index around OfNat.ofNat] theorem diagonal_ofNat' [Zero α] [NatCast α] (m : ℕ) [m.AtLeastTwo] : diagonal (no_index (OfNat.ofNat m : n → α)) = OfNat.ofNat m := rfl instance [Zero α] [IntCast α] : IntCast (Matrix n n α) where intCast m := diagonal fun _ => m @[norm_cast] theorem diagonal_intCast [Zero α] [IntCast α] (m : ℤ) : diagonal (fun _ : n => (m : α)) = m := rfl @[norm_cast] theorem diagonal_intCast' [Zero α] [IntCast α] (m : ℤ) : diagonal ((m : n → α)) = m := rfl variable (n α) /-- `Matrix.diagonal` as an `AddMonoidHom`. -/ @[simps] def diagonalAddMonoidHom [AddZeroClass α] : (n → α) →+ Matrix n n α where toFun := diagonal map_zero' := diagonal_zero map_add' x y := (diagonal_add x y).symm #align matrix.diagonal_add_monoid_hom Matrix.diagonalAddMonoidHom variable (R) /-- `Matrix.diagonal` as a `LinearMap`. -/ @[simps] def diagonalLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : (n → α) →ₗ[R] Matrix n n α := { diagonalAddMonoidHom n α with map_smul' := diagonal_smul } #align matrix.diagonal_linear_map Matrix.diagonalLinearMap variable {n α R} @[simp] theorem diagonal_map [Zero α] [Zero β] {f : α → β} (h : f 0 = 0) {d : n → α} : (diagonal d).map f = diagonal fun m => f (d m) := by ext simp only [diagonal_apply, map_apply] split_ifs <;> simp [h] #align matrix.diagonal_map Matrix.diagonal_map @[simp] theorem diagonal_conjTranspose [AddMonoid α] [StarAddMonoid α] (v : n → α) : (diagonal v)ᴴ = diagonal (star v) := by rw [conjTranspose, diagonal_transpose, diagonal_map (star_zero _)] rfl #align matrix.diagonal_conj_transpose Matrix.diagonal_conjTranspose section One variable [Zero α] [One α] instance one : One (Matrix n n α) := ⟨diagonal fun _ => 1⟩ @[simp] theorem diagonal_one : (diagonal fun _ => 1 : Matrix n n α) = 1 := rfl #align matrix.diagonal_one Matrix.diagonal_one theorem one_apply {i j} : (1 : Matrix n n α) i j = if i = j then 1 else 0 := rfl #align matrix.one_apply Matrix.one_apply @[simp] theorem one_apply_eq (i) : (1 : Matrix n n α) i i = 1 := diagonal_apply_eq _ i #align matrix.one_apply_eq Matrix.one_apply_eq @[simp] theorem one_apply_ne {i j} : i ≠ j → (1 : Matrix n n α) i j = 0 := diagonal_apply_ne _ #align matrix.one_apply_ne Matrix.one_apply_ne theorem one_apply_ne' {i j} : j ≠ i → (1 : Matrix n n α) i j = 0 := diagonal_apply_ne' _ #align matrix.one_apply_ne' Matrix.one_apply_ne' @[simp] theorem map_one [Zero β] [One β] (f : α → β) (h₀ : f 0 = 0) (h₁ : f 1 = 1) : (1 : Matrix n n α).map f = (1 : Matrix n n β) := by ext simp only [one_apply, map_apply] split_ifs <;> simp [h₀, h₁] #align matrix.map_one Matrix.map_one -- Porting note: added implicit argument `(f := fun_ => α)`, why is that needed? theorem one_eq_pi_single {i j} : (1 : Matrix n n α) i j = Pi.single (f := fun _ => α) i 1 j := by simp only [one_apply, Pi.single_apply, eq_comm] #align matrix.one_eq_pi_single Matrix.one_eq_pi_single lemma zero_le_one_elem [Preorder α] [ZeroLEOneClass α] (i j : n) : 0 ≤ (1 : Matrix n n α) i j := by by_cases hi : i = j <;> simp [hi] lemma zero_le_one_row [Preorder α] [ZeroLEOneClass α] (i : n) : 0 ≤ (1 : Matrix n n α) i := zero_le_one_elem i end One instance instAddMonoidWithOne [AddMonoidWithOne α] : AddMonoidWithOne (Matrix n n α) where natCast_zero := show diagonal _ = _ by rw [Nat.cast_zero, diagonal_zero] natCast_succ n := show diagonal _ = diagonal _ + _ by rw [Nat.cast_succ, ← diagonal_add, diagonal_one] instance instAddGroupWithOne [AddGroupWithOne α] : AddGroupWithOne (Matrix n n α) where intCast_ofNat n := show diagonal _ = diagonal _ by rw [Int.cast_natCast] intCast_negSucc n := show diagonal _ = -(diagonal _) by rw [Int.cast_negSucc, diagonal_neg] __ := addGroup __ := instAddMonoidWithOne instance instAddCommMonoidWithOne [AddCommMonoidWithOne α] : AddCommMonoidWithOne (Matrix n n α) where __ := addCommMonoid __ := instAddMonoidWithOne instance instAddCommGroupWithOne [AddCommGroupWithOne α] : AddCommGroupWithOne (Matrix n n α) where __ := addCommGroup __ := instAddGroupWithOne section Numeral set_option linter.deprecated false @[deprecated, simp] theorem bit0_apply [Add α] (M : Matrix m m α) (i : m) (j : m) : (bit0 M) i j = bit0 (M i j) := rfl #align matrix.bit0_apply Matrix.bit0_apply variable [AddZeroClass α] [One α] @[deprecated] theorem bit1_apply (M : Matrix n n α) (i : n) (j : n) : (bit1 M) i j = if i = j then bit1 (M i j) else bit0 (M i j) := by dsimp [bit1] by_cases h : i = j <;> simp [h] #align matrix.bit1_apply Matrix.bit1_apply @[deprecated, simp] theorem bit1_apply_eq (M : Matrix n n α) (i : n) : (bit1 M) i i = bit1 (M i i) := by simp [bit1_apply] #align matrix.bit1_apply_eq Matrix.bit1_apply_eq @[deprecated, simp] theorem bit1_apply_ne (M : Matrix n n α) {i j : n} (h : i ≠ j) : (bit1 M) i j = bit0 (M i j) := by simp [bit1_apply, h] #align matrix.bit1_apply_ne Matrix.bit1_apply_ne end Numeral end Diagonal section Diag /-- The diagonal of a square matrix. -/ -- @[simp] -- Porting note: simpNF does not like this. def diag (A : Matrix n n α) (i : n) : α := A i i #align matrix.diag Matrix.diag -- Porting note: new, because of removed `simp` above. -- TODO: set as an equation lemma for `diag`, see mathlib4#3024 @[simp] theorem diag_apply (A : Matrix n n α) (i) : diag A i = A i i := rfl @[simp] theorem diag_diagonal [DecidableEq n] [Zero α] (a : n → α) : diag (diagonal a) = a := funext <| @diagonal_apply_eq _ _ _ _ a #align matrix.diag_diagonal Matrix.diag_diagonal @[simp] theorem diag_transpose (A : Matrix n n α) : diag Aᵀ = diag A := rfl #align matrix.diag_transpose Matrix.diag_transpose @[simp] theorem diag_zero [Zero α] : diag (0 : Matrix n n α) = 0 := rfl #align matrix.diag_zero Matrix.diag_zero @[simp] theorem diag_add [Add α] (A B : Matrix n n α) : diag (A + B) = diag A + diag B := rfl #align matrix.diag_add Matrix.diag_add @[simp] theorem diag_sub [Sub α] (A B : Matrix n n α) : diag (A - B) = diag A - diag B := rfl #align matrix.diag_sub Matrix.diag_sub @[simp] theorem diag_neg [Neg α] (A : Matrix n n α) : diag (-A) = -diag A := rfl #align matrix.diag_neg Matrix.diag_neg @[simp] theorem diag_smul [SMul R α] (r : R) (A : Matrix n n α) : diag (r • A) = r • diag A := rfl #align matrix.diag_smul Matrix.diag_smul @[simp] theorem diag_one [DecidableEq n] [Zero α] [One α] : diag (1 : Matrix n n α) = 1 := diag_diagonal _ #align matrix.diag_one Matrix.diag_one variable (n α) /-- `Matrix.diag` as an `AddMonoidHom`. -/ @[simps] def diagAddMonoidHom [AddZeroClass α] : Matrix n n α →+ n → α where toFun := diag map_zero' := diag_zero map_add' := diag_add #align matrix.diag_add_monoid_hom Matrix.diagAddMonoidHom variable (R) /-- `Matrix.diag` as a `LinearMap`. -/ @[simps] def diagLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : Matrix n n α →ₗ[R] n → α := { diagAddMonoidHom n α with map_smul' := diag_smul } #align matrix.diag_linear_map Matrix.diagLinearMap variable {n α R} theorem diag_map {f : α → β} {A : Matrix n n α} : diag (A.map f) = f ∘ diag A := rfl #align matrix.diag_map Matrix.diag_map @[simp] theorem diag_conjTranspose [AddMonoid α] [StarAddMonoid α] (A : Matrix n n α) : diag Aᴴ = star (diag A) := rfl #align matrix.diag_conj_transpose Matrix.diag_conjTranspose @[simp] theorem diag_list_sum [AddMonoid α] (l : List (Matrix n n α)) : diag l.sum = (l.map diag).sum := map_list_sum (diagAddMonoidHom n α) l #align matrix.diag_list_sum Matrix.diag_list_sum @[simp] theorem diag_multiset_sum [AddCommMonoid α] (s : Multiset (Matrix n n α)) : diag s.sum = (s.map diag).sum := map_multiset_sum (diagAddMonoidHom n α) s #align matrix.diag_multiset_sum Matrix.diag_multiset_sum @[simp] theorem diag_sum {ι} [AddCommMonoid α] (s : Finset ι) (f : ι → Matrix n n α) : diag (∑ i ∈ s, f i) = ∑ i ∈ s, diag (f i) := map_sum (diagAddMonoidHom n α) f s #align matrix.diag_sum Matrix.diag_sum end Diag section DotProduct variable [Fintype m] [Fintype n] /-- `dotProduct v w` is the sum of the entrywise products `v i * w i` -/ def dotProduct [Mul α] [AddCommMonoid α] (v w : m → α) : α := ∑ i, v i * w i #align matrix.dot_product Matrix.dotProduct /- The precedence of 72 comes immediately after ` • ` for `SMul.smul`, so that `r₁ • a ⬝ᵥ r₂ • b` is parsed as `(r₁ • a) ⬝ᵥ (r₂ • b)` here. -/ @[inherit_doc] scoped infixl:72 " ⬝ᵥ " => Matrix.dotProduct theorem dotProduct_assoc [NonUnitalSemiring α] (u : m → α) (w : n → α) (v : Matrix m n α) : (fun j => u ⬝ᵥ fun i => v i j) ⬝ᵥ w = u ⬝ᵥ fun i => v i ⬝ᵥ w := by simpa [dotProduct, Finset.mul_sum, Finset.sum_mul, mul_assoc] using Finset.sum_comm #align matrix.dot_product_assoc Matrix.dotProduct_assoc theorem dotProduct_comm [AddCommMonoid α] [CommSemigroup α] (v w : m → α) : v ⬝ᵥ w = w ⬝ᵥ v := by simp_rw [dotProduct, mul_comm] #align matrix.dot_product_comm Matrix.dotProduct_comm @[simp] theorem dotProduct_pUnit [AddCommMonoid α] [Mul α] (v w : PUnit → α) : v ⬝ᵥ w = v ⟨⟩ * w ⟨⟩ := by simp [dotProduct] #align matrix.dot_product_punit Matrix.dotProduct_pUnit section MulOneClass variable [MulOneClass α] [AddCommMonoid α] theorem dotProduct_one (v : n → α) : v ⬝ᵥ 1 = ∑ i, v i := by simp [(· ⬝ᵥ ·)] #align matrix.dot_product_one Matrix.dotProduct_one theorem one_dotProduct (v : n → α) : 1 ⬝ᵥ v = ∑ i, v i := by simp [(· ⬝ᵥ ·)] #align matrix.one_dot_product Matrix.one_dotProduct end MulOneClass section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] (u v w : m → α) (x y : n → α) @[simp] theorem dotProduct_zero : v ⬝ᵥ 0 = 0 := by simp [dotProduct] #align matrix.dot_product_zero Matrix.dotProduct_zero @[simp] theorem dotProduct_zero' : (v ⬝ᵥ fun _ => 0) = 0 := dotProduct_zero v #align matrix.dot_product_zero' Matrix.dotProduct_zero' @[simp] theorem zero_dotProduct : 0 ⬝ᵥ v = 0 := by simp [dotProduct] #align matrix.zero_dot_product Matrix.zero_dotProduct @[simp] theorem zero_dotProduct' : (fun _ => (0 : α)) ⬝ᵥ v = 0 := zero_dotProduct v #align matrix.zero_dot_product' Matrix.zero_dotProduct' @[simp] theorem add_dotProduct : (u + v) ⬝ᵥ w = u ⬝ᵥ w + v ⬝ᵥ w := by simp [dotProduct, add_mul, Finset.sum_add_distrib] #align matrix.add_dot_product Matrix.add_dotProduct @[simp] theorem dotProduct_add : u ⬝ᵥ (v + w) = u ⬝ᵥ v + u ⬝ᵥ w := by simp [dotProduct, mul_add, Finset.sum_add_distrib] #align matrix.dot_product_add Matrix.dotProduct_add @[simp] theorem sum_elim_dotProduct_sum_elim : Sum.elim u x ⬝ᵥ Sum.elim v y = u ⬝ᵥ v + x ⬝ᵥ y := by simp [dotProduct] #align matrix.sum_elim_dot_product_sum_elim Matrix.sum_elim_dotProduct_sum_elim /-- Permuting a vector on the left of a dot product can be transferred to the right. -/ @[simp] theorem comp_equiv_symm_dotProduct (e : m ≃ n) : u ∘ e.symm ⬝ᵥ x = u ⬝ᵥ x ∘ e := (e.sum_comp _).symm.trans <| Finset.sum_congr rfl fun _ _ => by simp only [Function.comp, Equiv.symm_apply_apply] #align matrix.comp_equiv_symm_dot_product Matrix.comp_equiv_symm_dotProduct /-- Permuting a vector on the right of a dot product can be transferred to the left. -/ @[simp] theorem dotProduct_comp_equiv_symm (e : n ≃ m) : u ⬝ᵥ x ∘ e.symm = u ∘ e ⬝ᵥ x := by simpa only [Equiv.symm_symm] using (comp_equiv_symm_dotProduct u x e.symm).symm #align matrix.dot_product_comp_equiv_symm Matrix.dotProduct_comp_equiv_symm /-- Permuting vectors on both sides of a dot product is a no-op. -/ @[simp] theorem comp_equiv_dotProduct_comp_equiv (e : m ≃ n) : x ∘ e ⬝ᵥ y ∘ e = x ⬝ᵥ y := by -- Porting note: was `simp only` with all three lemmas rw [← dotProduct_comp_equiv_symm]; simp only [Function.comp, Equiv.apply_symm_apply] #align matrix.comp_equiv_dot_product_comp_equiv Matrix.comp_equiv_dotProduct_comp_equiv end NonUnitalNonAssocSemiring section NonUnitalNonAssocSemiringDecidable variable [DecidableEq m] [NonUnitalNonAssocSemiring α] (u v w : m → α) @[simp] theorem diagonal_dotProduct (i : m) : diagonal v i ⬝ᵥ w = v i * w i := by have : ∀ j ≠ i, diagonal v i j * w j = 0 := fun j hij => by simp [diagonal_apply_ne' _ hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.diagonal_dot_product Matrix.diagonal_dotProduct @[simp] theorem dotProduct_diagonal (i : m) : v ⬝ᵥ diagonal w i = v i * w i := by have : ∀ j ≠ i, v j * diagonal w i j = 0 := fun j hij => by simp [diagonal_apply_ne' _ hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.dot_product_diagonal Matrix.dotProduct_diagonal @[simp] theorem dotProduct_diagonal' (i : m) : (v ⬝ᵥ fun j => diagonal w j i) = v i * w i := by have : ∀ j ≠ i, v j * diagonal w j i = 0 := fun j hij => by simp [diagonal_apply_ne _ hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.dot_product_diagonal' Matrix.dotProduct_diagonal' @[simp] theorem single_dotProduct (x : α) (i : m) : Pi.single i x ⬝ᵥ v = x * v i := by -- Porting note: (implicit arg) added `(f := fun _ => α)` have : ∀ j ≠ i, Pi.single (f := fun _ => α) i x j * v j = 0 := fun j hij => by simp [Pi.single_eq_of_ne hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.single_dot_product Matrix.single_dotProduct @[simp] theorem dotProduct_single (x : α) (i : m) : v ⬝ᵥ Pi.single i x = v i * x := by -- Porting note: (implicit arg) added `(f := fun _ => α)` have : ∀ j ≠ i, v j * Pi.single (f := fun _ => α) i x j = 0 := fun j hij => by simp [Pi.single_eq_of_ne hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.dot_product_single Matrix.dotProduct_single end NonUnitalNonAssocSemiringDecidable section NonAssocSemiring variable [NonAssocSemiring α] @[simp] theorem one_dotProduct_one : (1 : n → α) ⬝ᵥ 1 = Fintype.card n := by simp [dotProduct] #align matrix.one_dot_product_one Matrix.one_dotProduct_one end NonAssocSemiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing α] (u v w : m → α) @[simp] theorem neg_dotProduct : -v ⬝ᵥ w = -(v ⬝ᵥ w) := by simp [dotProduct] #align matrix.neg_dot_product Matrix.neg_dotProduct @[simp] theorem dotProduct_neg : v ⬝ᵥ -w = -(v ⬝ᵥ w) := by simp [dotProduct] #align matrix.dot_product_neg Matrix.dotProduct_neg lemma neg_dotProduct_neg : -v ⬝ᵥ -w = v ⬝ᵥ w := by rw [neg_dotProduct, dotProduct_neg, neg_neg] @[simp] theorem sub_dotProduct : (u - v) ⬝ᵥ w = u ⬝ᵥ w - v ⬝ᵥ w := by simp [sub_eq_add_neg] #align matrix.sub_dot_product Matrix.sub_dotProduct @[simp] theorem dotProduct_sub : u ⬝ᵥ (v - w) = u ⬝ᵥ v - u ⬝ᵥ w := by simp [sub_eq_add_neg] #align matrix.dot_product_sub Matrix.dotProduct_sub end NonUnitalNonAssocRing section DistribMulAction variable [Monoid R] [Mul α] [AddCommMonoid α] [DistribMulAction R α] @[simp] theorem smul_dotProduct [IsScalarTower R α α] (x : R) (v w : m → α) : x • v ⬝ᵥ w = x • (v ⬝ᵥ w) := by simp [dotProduct, Finset.smul_sum, smul_mul_assoc] #align matrix.smul_dot_product Matrix.smul_dotProduct @[simp] theorem dotProduct_smul [SMulCommClass R α α] (x : R) (v w : m → α) : v ⬝ᵥ x • w = x • (v ⬝ᵥ w) := by simp [dotProduct, Finset.smul_sum, mul_smul_comm] #align matrix.dot_product_smul Matrix.dotProduct_smul end DistribMulAction section StarRing variable [NonUnitalSemiring α] [StarRing α] (v w : m → α) theorem star_dotProduct_star : star v ⬝ᵥ star w = star (w ⬝ᵥ v) := by simp [dotProduct] #align matrix.star_dot_product_star Matrix.star_dotProduct_star theorem star_dotProduct : star v ⬝ᵥ w = star (star w ⬝ᵥ v) := by simp [dotProduct] #align matrix.star_dot_product Matrix.star_dotProduct theorem dotProduct_star : v ⬝ᵥ star w = star (w ⬝ᵥ star v) := by simp [dotProduct] #align matrix.dot_product_star Matrix.dotProduct_star end StarRing end DotProduct open Matrix /-- `M * N` is the usual product of matrices `M` and `N`, i.e. we have that `(M * N) i k` is the dot product of the `i`-th row of `M` by the `k`-th column of `N`. This is currently only defined when `m` is finite. -/ -- We want to be lower priority than `instHMul`, but without this we can't have operands with -- implicit dimensions. @[default_instance 100] instance [Fintype m] [Mul α] [AddCommMonoid α] : HMul (Matrix l m α) (Matrix m n α) (Matrix l n α) where hMul M N := fun i k => (fun j => M i j) ⬝ᵥ fun j => N j k #align matrix.mul HMul.hMul theorem mul_apply [Fintype m] [Mul α] [AddCommMonoid α] {M : Matrix l m α} {N : Matrix m n α} {i k} : (M * N) i k = ∑ j, M i j * N j k := rfl #align matrix.mul_apply Matrix.mul_apply instance [Fintype n] [Mul α] [AddCommMonoid α] : Mul (Matrix n n α) where mul M N := M * N #noalign matrix.mul_eq_mul theorem mul_apply' [Fintype m] [Mul α] [AddCommMonoid α] {M : Matrix l m α} {N : Matrix m n α} {i k} : (M * N) i k = (fun j => M i j) ⬝ᵥ fun j => N j k := rfl #align matrix.mul_apply' Matrix.mul_apply' theorem sum_apply [AddCommMonoid α] (i : m) (j : n) (s : Finset β) (g : β → Matrix m n α) : (∑ c ∈ s, g c) i j = ∑ c ∈ s, g c i j := (congr_fun (s.sum_apply i g) j).trans (s.sum_apply j _) #align matrix.sum_apply Matrix.sum_apply theorem two_mul_expl {R : Type*} [CommRing R] (A B : Matrix (Fin 2) (Fin 2) R) : (A * B) 0 0 = A 0 0 * B 0 0 + A 0 1 * B 1 0 ∧ (A * B) 0 1 = A 0 0 * B 0 1 + A 0 1 * B 1 1 ∧ (A * B) 1 0 = A 1 0 * B 0 0 + A 1 1 * B 1 0 ∧ (A * B) 1 1 = A 1 0 * B 0 1 + A 1 1 * B 1 1 := by refine ⟨?_, ?_, ?_, ?_⟩ <;> · rw [Matrix.mul_apply, Finset.sum_fin_eq_sum_range, Finset.sum_range_succ, Finset.sum_range_succ] simp #align matrix.two_mul_expl Matrix.two_mul_expl section AddCommMonoid variable [AddCommMonoid α] [Mul α] @[simp] theorem smul_mul [Fintype n] [Monoid R] [DistribMulAction R α] [IsScalarTower R α α] (a : R) (M : Matrix m n α) (N : Matrix n l α) : (a • M) * N = a • (M * N) := by ext apply smul_dotProduct a #align matrix.smul_mul Matrix.smul_mul @[simp] theorem mul_smul [Fintype n] [Monoid R] [DistribMulAction R α] [SMulCommClass R α α] (M : Matrix m n α) (a : R) (N : Matrix n l α) : M * (a • N) = a • (M * N) := by ext apply dotProduct_smul #align matrix.mul_smul Matrix.mul_smul end AddCommMonoid section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] @[simp] protected theorem mul_zero [Fintype n] (M : Matrix m n α) : M * (0 : Matrix n o α) = 0 := by ext apply dotProduct_zero #align matrix.mul_zero Matrix.mul_zero @[simp] protected theorem zero_mul [Fintype m] (M : Matrix m n α) : (0 : Matrix l m α) * M = 0 := by ext apply zero_dotProduct #align matrix.zero_mul Matrix.zero_mul protected theorem mul_add [Fintype n] (L : Matrix m n α) (M N : Matrix n o α) : L * (M + N) = L * M + L * N := by ext apply dotProduct_add #align matrix.mul_add Matrix.mul_add protected theorem add_mul [Fintype m] (L M : Matrix l m α) (N : Matrix m n α) : (L + M) * N = L * N + M * N := by ext apply add_dotProduct #align matrix.add_mul Matrix.add_mul instance nonUnitalNonAssocSemiring [Fintype n] : NonUnitalNonAssocSemiring (Matrix n n α) := { Matrix.addCommMonoid with mul_zero := Matrix.mul_zero zero_mul := Matrix.zero_mul left_distrib := Matrix.mul_add right_distrib := Matrix.add_mul } @[simp] theorem diagonal_mul [Fintype m] [DecidableEq m] (d : m → α) (M : Matrix m n α) (i j) : (diagonal d * M) i j = d i * M i j := diagonal_dotProduct _ _ _ #align matrix.diagonal_mul Matrix.diagonal_mul @[simp] theorem mul_diagonal [Fintype n] [DecidableEq n] (d : n → α) (M : Matrix m n α) (i j) : (M * diagonal d) i j = M i j * d j := by rw [← diagonal_transpose] apply dotProduct_diagonal #align matrix.mul_diagonal Matrix.mul_diagonal @[simp] theorem diagonal_mul_diagonal [Fintype n] [DecidableEq n] (d₁ d₂ : n → α) : diagonal d₁ * diagonal d₂ = diagonal fun i => d₁ i * d₂ i := by ext i j by_cases h : i = j <;> simp [h] #align matrix.diagonal_mul_diagonal Matrix.diagonal_mul_diagonal theorem diagonal_mul_diagonal' [Fintype n] [DecidableEq n] (d₁ d₂ : n → α) : diagonal d₁ * diagonal d₂ = diagonal fun i => d₁ i * d₂ i := diagonal_mul_diagonal _ _ #align matrix.diagonal_mul_diagonal' Matrix.diagonal_mul_diagonal' theorem smul_eq_diagonal_mul [Fintype m] [DecidableEq m] (M : Matrix m n α) (a : α) : a • M = (diagonal fun _ => a) * M := by ext simp #align matrix.smul_eq_diagonal_mul Matrix.smul_eq_diagonal_mul theorem op_smul_eq_mul_diagonal [Fintype n] [DecidableEq n] (M : Matrix m n α) (a : α) : MulOpposite.op a • M = M * (diagonal fun _ : n => a) := by ext simp /-- Left multiplication by a matrix, as an `AddMonoidHom` from matrices to matrices. -/ @[simps] def addMonoidHomMulLeft [Fintype m] (M : Matrix l m α) : Matrix m n α →+ Matrix l n α where toFun x := M * x map_zero' := Matrix.mul_zero _ map_add' := Matrix.mul_add _ #align matrix.add_monoid_hom_mul_left Matrix.addMonoidHomMulLeft /-- Right multiplication by a matrix, as an `AddMonoidHom` from matrices to matrices. -/ @[simps] def addMonoidHomMulRight [Fintype m] (M : Matrix m n α) : Matrix l m α →+ Matrix l n α where toFun x := x * M map_zero' := Matrix.zero_mul _ map_add' _ _ := Matrix.add_mul _ _ _ #align matrix.add_monoid_hom_mul_right Matrix.addMonoidHomMulRight protected theorem sum_mul [Fintype m] (s : Finset β) (f : β → Matrix l m α) (M : Matrix m n α) : (∑ a ∈ s, f a) * M = ∑ a ∈ s, f a * M := map_sum (addMonoidHomMulRight M) f s #align matrix.sum_mul Matrix.sum_mul protected theorem mul_sum [Fintype m] (s : Finset β) (f : β → Matrix m n α) (M : Matrix l m α) : (M * ∑ a ∈ s, f a) = ∑ a ∈ s, M * f a := map_sum (addMonoidHomMulLeft M) f s #align matrix.mul_sum Matrix.mul_sum /-- This instance enables use with `smul_mul_assoc`. -/ instance Semiring.isScalarTower [Fintype n] [Monoid R] [DistribMulAction R α] [IsScalarTower R α α] : IsScalarTower R (Matrix n n α) (Matrix n n α) := ⟨fun r m n => Matrix.smul_mul r m n⟩ #align matrix.semiring.is_scalar_tower Matrix.Semiring.isScalarTower /-- This instance enables use with `mul_smul_comm`. -/ instance Semiring.smulCommClass [Fintype n] [Monoid R] [DistribMulAction R α] [SMulCommClass R α α] : SMulCommClass R (Matrix n n α) (Matrix n n α) := ⟨fun r m n => (Matrix.mul_smul m r n).symm⟩ #align matrix.semiring.smul_comm_class Matrix.Semiring.smulCommClass end NonUnitalNonAssocSemiring section NonAssocSemiring variable [NonAssocSemiring α] @[simp] protected theorem one_mul [Fintype m] [DecidableEq m] (M : Matrix m n α) : (1 : Matrix m m α) * M = M := by ext rw [← diagonal_one, diagonal_mul, one_mul] #align matrix.one_mul Matrix.one_mul @[simp] protected theorem mul_one [Fintype n] [DecidableEq n] (M : Matrix m n α) : M * (1 : Matrix n n α) = M := by ext rw [← diagonal_one, mul_diagonal, mul_one] #align matrix.mul_one Matrix.mul_one instance nonAssocSemiring [Fintype n] [DecidableEq n] : NonAssocSemiring (Matrix n n α) := { Matrix.nonUnitalNonAssocSemiring, Matrix.instAddCommMonoidWithOne with one := 1 one_mul := Matrix.one_mul mul_one := Matrix.mul_one } @[simp] theorem map_mul [Fintype n] {L : Matrix m n α} {M : Matrix n o α} [NonAssocSemiring β] {f : α →+* β} : (L * M).map f = L.map f * M.map f := by ext simp [mul_apply, map_sum] #align matrix.map_mul Matrix.map_mul theorem smul_one_eq_diagonal [DecidableEq m] (a : α) : a • (1 : Matrix m m α) = diagonal fun _ => a := by simp_rw [← diagonal_one, ← diagonal_smul, Pi.smul_def, smul_eq_mul, mul_one] theorem op_smul_one_eq_diagonal [DecidableEq m] (a : α) : MulOpposite.op a • (1 : Matrix m m α) = diagonal fun _ => a := by simp_rw [← diagonal_one, ← diagonal_smul, Pi.smul_def, op_smul_eq_mul, one_mul] variable (α n) /-- `Matrix.diagonal` as a `RingHom`. -/ @[simps] def diagonalRingHom [Fintype n] [DecidableEq n] : (n → α) →+* Matrix n n α := { diagonalAddMonoidHom n α with toFun := diagonal map_one' := diagonal_one map_mul' := fun _ _ => (diagonal_mul_diagonal' _ _).symm } #align matrix.diagonal_ring_hom Matrix.diagonalRingHom end NonAssocSemiring section NonUnitalSemiring variable [NonUnitalSemiring α] [Fintype m] [Fintype n] protected theorem mul_assoc (L : Matrix l m α) (M : Matrix m n α) (N : Matrix n o α) : L * M * N = L * (M * N) := by ext apply dotProduct_assoc #align matrix.mul_assoc Matrix.mul_assoc instance nonUnitalSemiring : NonUnitalSemiring (Matrix n n α) := { Matrix.nonUnitalNonAssocSemiring with mul_assoc := Matrix.mul_assoc } end NonUnitalSemiring section Semiring variable [Semiring α] instance semiring [Fintype n] [DecidableEq n] : Semiring (Matrix n n α) := { Matrix.nonUnitalSemiring, Matrix.nonAssocSemiring with } end Semiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing α] [Fintype n] @[simp] protected theorem neg_mul (M : Matrix m n α) (N : Matrix n o α) : (-M) * N = -(M * N) := by ext apply neg_dotProduct #align matrix.neg_mul Matrix.neg_mul @[simp] protected theorem mul_neg (M : Matrix m n α) (N : Matrix n o α) : M * (-N) = -(M * N) := by ext apply dotProduct_neg #align matrix.mul_neg Matrix.mul_neg protected theorem sub_mul (M M' : Matrix m n α) (N : Matrix n o α) : (M - M') * N = M * N - M' * N := by rw [sub_eq_add_neg, Matrix.add_mul, Matrix.neg_mul, sub_eq_add_neg] #align matrix.sub_mul Matrix.sub_mul protected theorem mul_sub (M : Matrix m n α) (N N' : Matrix n o α) : M * (N - N') = M * N - M * N' := by rw [sub_eq_add_neg, Matrix.mul_add, Matrix.mul_neg, sub_eq_add_neg] #align matrix.mul_sub Matrix.mul_sub instance nonUnitalNonAssocRing : NonUnitalNonAssocRing (Matrix n n α) := { Matrix.nonUnitalNonAssocSemiring, Matrix.addCommGroup with } end NonUnitalNonAssocRing instance instNonUnitalRing [Fintype n] [NonUnitalRing α] : NonUnitalRing (Matrix n n α) := { Matrix.nonUnitalSemiring, Matrix.addCommGroup with } #align matrix.non_unital_ring Matrix.instNonUnitalRing instance instNonAssocRing [Fintype n] [DecidableEq n] [NonAssocRing α] : NonAssocRing (Matrix n n α) := { Matrix.nonAssocSemiring, Matrix.instAddCommGroupWithOne with } #align matrix.non_assoc_ring Matrix.instNonAssocRing instance instRing [Fintype n] [DecidableEq n] [Ring α] : Ring (Matrix n n α) := { Matrix.semiring, Matrix.instAddCommGroupWithOne with } #align matrix.ring Matrix.instRing section Semiring variable [Semiring α] theorem diagonal_pow [Fintype n] [DecidableEq n] (v : n → α) (k : ℕ) : diagonal v ^ k = diagonal (v ^ k) := (map_pow (diagonalRingHom n α) v k).symm #align matrix.diagonal_pow Matrix.diagonal_pow @[simp] theorem mul_mul_left [Fintype n] (M : Matrix m n α) (N : Matrix n o α) (a : α) : (of fun i j => a * M i j) * N = a • (M * N) := smul_mul a M N #align matrix.mul_mul_left Matrix.mul_mul_left /-- The ring homomorphism `α →+* Matrix n n α` sending `a` to the diagonal matrix with `a` on the diagonal. -/ def scalar (n : Type u) [DecidableEq n] [Fintype n] : α →+* Matrix n n α := (diagonalRingHom n α).comp <| Pi.constRingHom n α #align matrix.scalar Matrix.scalar section Scalar variable [DecidableEq n] [Fintype n] @[simp] theorem scalar_apply (a : α) : scalar n a = diagonal fun _ => a := rfl #align matrix.coe_scalar Matrix.scalar_applyₓ #noalign matrix.scalar_apply_eq #noalign matrix.scalar_apply_ne theorem scalar_inj [Nonempty n] {r s : α} : scalar n r = scalar n s ↔ r = s := (diagonal_injective.comp Function.const_injective).eq_iff #align matrix.scalar_inj Matrix.scalar_inj theorem scalar_commute_iff {r : α} {M : Matrix n n α} : Commute (scalar n r) M ↔ r • M = MulOpposite.op r • M := by simp_rw [Commute, SemiconjBy, scalar_apply, ← smul_eq_diagonal_mul, ← op_smul_eq_mul_diagonal] theorem scalar_commute (r : α) (hr : ∀ r', Commute r r') (M : Matrix n n α) : Commute (scalar n r) M := scalar_commute_iff.2 <| ext fun _ _ => hr _ #align matrix.scalar.commute Matrix.scalar_commuteₓ end Scalar end Semiring section CommSemiring variable [CommSemiring α] theorem smul_eq_mul_diagonal [Fintype n] [DecidableEq n] (M : Matrix m n α) (a : α) : a • M = M * diagonal fun _ => a := by ext simp [mul_comm] #align matrix.smul_eq_mul_diagonal Matrix.smul_eq_mul_diagonal @[simp] theorem mul_mul_right [Fintype n] (M : Matrix m n α) (N : Matrix n o α) (a : α) : (M * of fun i j => a * N i j) = a • (M * N) := mul_smul M a N #align matrix.mul_mul_right Matrix.mul_mul_right end CommSemiring section Algebra variable [Fintype n] [DecidableEq n] variable [CommSemiring R] [Semiring α] [Semiring β] [Algebra R α] [Algebra R β] instance instAlgebra : Algebra R (Matrix n n α) where toRingHom := (Matrix.scalar n).comp (algebraMap R α) commutes' r x := scalar_commute _ (fun r' => Algebra.commutes _ _) _ smul_def' r x := by ext; simp [Matrix.scalar, Algebra.smul_def r] #align matrix.algebra Matrix.instAlgebra theorem algebraMap_matrix_apply {r : R} {i j : n} : algebraMap R (Matrix n n α) r i j = if i = j then algebraMap R α r else 0 := by dsimp [algebraMap, Algebra.toRingHom, Matrix.scalar] split_ifs with h <;> simp [h, Matrix.one_apply_ne] #align matrix.algebra_map_matrix_apply Matrix.algebraMap_matrix_apply theorem algebraMap_eq_diagonal (r : R) : algebraMap R (Matrix n n α) r = diagonal (algebraMap R (n → α) r) := rfl #align matrix.algebra_map_eq_diagonal Matrix.algebraMap_eq_diagonal #align matrix.algebra_map_eq_smul Algebra.algebraMap_eq_smul_one theorem algebraMap_eq_diagonalRingHom : algebraMap R (Matrix n n α) = (diagonalRingHom n α).comp (algebraMap R _) := rfl #align matrix.algebra_map_eq_diagonal_ring_hom Matrix.algebraMap_eq_diagonalRingHom @[simp] theorem map_algebraMap (r : R) (f : α → β) (hf : f 0 = 0) (hf₂ : f (algebraMap R α r) = algebraMap R β r) : (algebraMap R (Matrix n n α) r).map f = algebraMap R (Matrix n n β) r := by rw [algebraMap_eq_diagonal, algebraMap_eq_diagonal, diagonal_map hf] -- Porting note: (congr) the remaining proof was -- ``` -- congr 1 -- simp only [hf₂, Pi.algebraMap_apply] -- ``` -- But some `congr 1` doesn't quite work. simp only [Pi.algebraMap_apply, diagonal_eq_diagonal_iff] intro rw [hf₂] #align matrix.map_algebra_map Matrix.map_algebraMap variable (R) /-- `Matrix.diagonal` as an `AlgHom`. -/ @[simps] def diagonalAlgHom : (n → α) →ₐ[R] Matrix n n α := { diagonalRingHom n α with toFun := diagonal commutes' := fun r => (algebraMap_eq_diagonal r).symm } #align matrix.diagonal_alg_hom Matrix.diagonalAlgHom end Algebra end Matrix /-! ### Bundled versions of `Matrix.map` -/ namespace Equiv /-- The `Equiv` between spaces of matrices induced by an `Equiv` between their coefficients. This is `Matrix.map` as an `Equiv`. -/ @[simps apply] def mapMatrix (f : α ≃ β) : Matrix m n α ≃ Matrix m n β where toFun M := M.map f invFun M := M.map f.symm left_inv _ := Matrix.ext fun _ _ => f.symm_apply_apply _ right_inv _ := Matrix.ext fun _ _ => f.apply_symm_apply _ #align equiv.map_matrix Equiv.mapMatrix @[simp] theorem mapMatrix_refl : (Equiv.refl α).mapMatrix = Equiv.refl (Matrix m n α) := rfl #align equiv.map_matrix_refl Equiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃ β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃ _) := rfl #align equiv.map_matrix_symm Equiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃ β) (g : β ≃ γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃ _) := rfl #align equiv.map_matrix_trans Equiv.mapMatrix_trans end Equiv namespace AddMonoidHom variable [AddZeroClass α] [AddZeroClass β] [AddZeroClass γ] /-- The `AddMonoidHom` between spaces of matrices induced by an `AddMonoidHom` between their coefficients. This is `Matrix.map` as an `AddMonoidHom`. -/ @[simps] def mapMatrix (f : α →+ β) : Matrix m n α →+ Matrix m n β where toFun M := M.map f map_zero' := Matrix.map_zero f f.map_zero map_add' := Matrix.map_add f f.map_add #align add_monoid_hom.map_matrix AddMonoidHom.mapMatrix @[simp] theorem mapMatrix_id : (AddMonoidHom.id α).mapMatrix = AddMonoidHom.id (Matrix m n α) := rfl #align add_monoid_hom.map_matrix_id AddMonoidHom.mapMatrix_id @[simp] theorem mapMatrix_comp (f : β →+ γ) (g : α →+ β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n α →+ _) := rfl #align add_monoid_hom.map_matrix_comp AddMonoidHom.mapMatrix_comp end AddMonoidHom namespace AddEquiv variable [Add α] [Add β] [Add γ] /-- The `AddEquiv` between spaces of matrices induced by an `AddEquiv` between their coefficients. This is `Matrix.map` as an `AddEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃+ β) : Matrix m n α ≃+ Matrix m n β := { f.toEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm map_add' := Matrix.map_add f f.map_add } #align add_equiv.map_matrix AddEquiv.mapMatrix @[simp] theorem mapMatrix_refl : (AddEquiv.refl α).mapMatrix = AddEquiv.refl (Matrix m n α) := rfl #align add_equiv.map_matrix_refl AddEquiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃+ β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃+ _) := rfl #align add_equiv.map_matrix_symm AddEquiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃+ β) (g : β ≃+ γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃+ _) := rfl #align add_equiv.map_matrix_trans AddEquiv.mapMatrix_trans end AddEquiv namespace LinearMap variable [Semiring R] [AddCommMonoid α] [AddCommMonoid β] [AddCommMonoid γ] variable [Module R α] [Module R β] [Module R γ] /-- The `LinearMap` between spaces of matrices induced by a `LinearMap` between their coefficients. This is `Matrix.map` as a `LinearMap`. -/ @[simps] def mapMatrix (f : α →ₗ[R] β) : Matrix m n α →ₗ[R] Matrix m n β where toFun M := M.map f map_add' := Matrix.map_add f f.map_add map_smul' r := Matrix.map_smul f r (f.map_smul r) #align linear_map.map_matrix LinearMap.mapMatrix @[simp] theorem mapMatrix_id : LinearMap.id.mapMatrix = (LinearMap.id : Matrix m n α →ₗ[R] _) := rfl #align linear_map.map_matrix_id LinearMap.mapMatrix_id @[simp] theorem mapMatrix_comp (f : β →ₗ[R] γ) (g : α →ₗ[R] β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n α →ₗ[R] _) := rfl #align linear_map.map_matrix_comp LinearMap.mapMatrix_comp end LinearMap namespace LinearEquiv variable [Semiring R] [AddCommMonoid α] [AddCommMonoid β] [AddCommMonoid γ] variable [Module R α] [Module R β] [Module R γ] /-- The `LinearEquiv` between spaces of matrices induced by a `LinearEquiv` between their coefficients. This is `Matrix.map` as a `LinearEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃ₗ[R] β) : Matrix m n α ≃ₗ[R] Matrix m n β := { f.toEquiv.mapMatrix, f.toLinearMap.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } #align linear_equiv.map_matrix LinearEquiv.mapMatrix @[simp] theorem mapMatrix_refl : (LinearEquiv.refl R α).mapMatrix = LinearEquiv.refl R (Matrix m n α) := rfl #align linear_equiv.map_matrix_refl LinearEquiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃ₗ[R] β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃ₗ[R] _) := rfl #align linear_equiv.map_matrix_symm LinearEquiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃ₗ[R] β) (g : β ≃ₗ[R] γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃ₗ[R] _) := rfl #align linear_equiv.map_matrix_trans LinearEquiv.mapMatrix_trans end LinearEquiv namespace RingHom variable [Fintype m] [DecidableEq m] variable [NonAssocSemiring α] [NonAssocSemiring β] [NonAssocSemiring γ] /-- The `RingHom` between spaces of square matrices induced by a `RingHom` between their coefficients. This is `Matrix.map` as a `RingHom`. -/ @[simps] def mapMatrix (f : α →+* β) : Matrix m m α →+* Matrix m m β := { f.toAddMonoidHom.mapMatrix with toFun := fun M => M.map f map_one' := by simp map_mul' := fun L M => Matrix.map_mul } #align ring_hom.map_matrix RingHom.mapMatrix @[simp] theorem mapMatrix_id : (RingHom.id α).mapMatrix = RingHom.id (Matrix m m α) := rfl #align ring_hom.map_matrix_id RingHom.mapMatrix_id @[simp] theorem mapMatrix_comp (f : β →+* γ) (g : α →+* β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m α →+* _) := rfl #align ring_hom.map_matrix_comp RingHom.mapMatrix_comp end RingHom namespace RingEquiv variable [Fintype m] [DecidableEq m] variable [NonAssocSemiring α] [NonAssocSemiring β] [NonAssocSemiring γ] /-- The `RingEquiv` between spaces of square matrices induced by a `RingEquiv` between their coefficients. This is `Matrix.map` as a `RingEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃+* β) : Matrix m m α ≃+* Matrix m m β := { f.toRingHom.mapMatrix, f.toAddEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } #align ring_equiv.map_matrix RingEquiv.mapMatrix @[simp] theorem mapMatrix_refl : (RingEquiv.refl α).mapMatrix = RingEquiv.refl (Matrix m m α) := rfl #align ring_equiv.map_matrix_refl RingEquiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃+* β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m β ≃+* _) := rfl #align ring_equiv.map_matrix_symm RingEquiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃+* β) (g : β ≃+* γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m α ≃+* _) := rfl #align ring_equiv.map_matrix_trans RingEquiv.mapMatrix_trans end RingEquiv namespace AlgHom variable [Fintype m] [DecidableEq m] variable [CommSemiring R] [Semiring α] [Semiring β] [Semiring γ] variable [Algebra R α] [Algebra R β] [Algebra R γ] /-- The `AlgHom` between spaces of square matrices induced by an `AlgHom` between their coefficients. This is `Matrix.map` as an `AlgHom`. -/ @[simps] def mapMatrix (f : α →ₐ[R] β) : Matrix m m α →ₐ[R] Matrix m m β := { f.toRingHom.mapMatrix with toFun := fun M => M.map f commutes' := fun r => Matrix.map_algebraMap r f f.map_zero (f.commutes r) } #align alg_hom.map_matrix AlgHom.mapMatrix @[simp] theorem mapMatrix_id : (AlgHom.id R α).mapMatrix = AlgHom.id R (Matrix m m α) := rfl #align alg_hom.map_matrix_id AlgHom.mapMatrix_id @[simp] theorem mapMatrix_comp (f : β →ₐ[R] γ) (g : α →ₐ[R] β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m α →ₐ[R] _) := rfl #align alg_hom.map_matrix_comp AlgHom.mapMatrix_comp end AlgHom namespace AlgEquiv variable [Fintype m] [DecidableEq m] variable [CommSemiring R] [Semiring α] [Semiring β] [Semiring γ] variable [Algebra R α] [Algebra R β] [Algebra R γ] /-- The `AlgEquiv` between spaces of square matrices induced by an `AlgEquiv` between their coefficients. This is `Matrix.map` as an `AlgEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃ₐ[R] β) : Matrix m m α ≃ₐ[R] Matrix m m β := { f.toAlgHom.mapMatrix, f.toRingEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } #align alg_equiv.map_matrix AlgEquiv.mapMatrix @[simp] theorem mapMatrix_refl : AlgEquiv.refl.mapMatrix = (AlgEquiv.refl : Matrix m m α ≃ₐ[R] _) := rfl #align alg_equiv.map_matrix_refl AlgEquiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃ₐ[R] β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m β ≃ₐ[R] _) := rfl #align alg_equiv.map_matrix_symm AlgEquiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃ₐ[R] β) (g : β ≃ₐ[R] γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m α ≃ₐ[R] _) := rfl #align alg_equiv.map_matrix_trans AlgEquiv.mapMatrix_trans end AlgEquiv open Matrix namespace Matrix /-- For two vectors `w` and `v`, `vecMulVec w v i j` is defined to be `w i * v j`. Put another way, `vecMulVec w v` is exactly `col w * row v`. -/ def vecMulVec [Mul α] (w : m → α) (v : n → α) : Matrix m n α := of fun x y => w x * v y #align matrix.vec_mul_vec Matrix.vecMulVec -- TODO: set as an equation lemma for `vecMulVec`, see mathlib4#3024 theorem vecMulVec_apply [Mul α] (w : m → α) (v : n → α) (i j) : vecMulVec w v i j = w i * v j := rfl #align matrix.vec_mul_vec_apply Matrix.vecMulVec_apply section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] /-- `M *ᵥ v` (notation for `mulVec M v`) is the matrix-vector product of matrix `M` and vector `v`, where `v` is seen as a column vector. Put another way, `M *ᵥ v` is the vector whose entries are those of `M * col v` (see `col_mulVec`). The notation has precedence 73, which comes immediately before ` ⬝ᵥ ` for `Matrix.dotProduct`, so that `A *ᵥ v ⬝ᵥ B *ᵥ w` is parsed as `(A *ᵥ v) ⬝ᵥ (B *ᵥ w)`. -/ def mulVec [Fintype n] (M : Matrix m n α) (v : n → α) : m → α | i => (fun j => M i j) ⬝ᵥ v #align matrix.mul_vec Matrix.mulVec @[inherit_doc] scoped infixr:73 " *ᵥ " => Matrix.mulVec /-- `v ᵥ* M` (notation for `vecMul v M`) is the vector-matrix product of vector `v` and matrix `M`, where `v` is seen as a row vector. Put another way, `v ᵥ* M` is the vector whose entries are those of `row v * M` (see `row_vecMul`). The notation has precedence 73, which comes immediately before ` ⬝ᵥ ` for `Matrix.dotProduct`, so that `v ᵥ* A ⬝ᵥ w ᵥ* B` is parsed as `(v ᵥ* A) ⬝ᵥ (w ᵥ* B)`. -/ def vecMul [Fintype m] (v : m → α) (M : Matrix m n α) : n → α | j => v ⬝ᵥ fun i => M i j #align matrix.vec_mul Matrix.vecMul @[inherit_doc] scoped infixl:73 " ᵥ* " => Matrix.vecMul /-- Left multiplication by a matrix, as an `AddMonoidHom` from vectors to vectors. -/ @[simps] def mulVec.addMonoidHomLeft [Fintype n] (v : n → α) : Matrix m n α →+ m → α where toFun M := M *ᵥ v map_zero' := by ext simp [mulVec] map_add' x y := by ext m apply add_dotProduct #align matrix.mul_vec.add_monoid_hom_left Matrix.mulVec.addMonoidHomLeft /-- The `i`th row of the multiplication is the same as the `vecMul` with the `i`th row of `A`. -/ theorem mul_apply_eq_vecMul [Fintype n] (A : Matrix m n α) (B : Matrix n o α) (i : m) : (A * B) i = A i ᵥ* B := rfl theorem mulVec_diagonal [Fintype m] [DecidableEq m] (v w : m → α) (x : m) : (diagonal v *ᵥ w) x = v x * w x := diagonal_dotProduct v w x #align matrix.mul_vec_diagonal Matrix.mulVec_diagonal theorem vecMul_diagonal [Fintype m] [DecidableEq m] (v w : m → α) (x : m) : (v ᵥ* diagonal w) x = v x * w x := dotProduct_diagonal' v w x #align matrix.vec_mul_diagonal Matrix.vecMul_diagonal /-- Associate the dot product of `mulVec` to the left. -/ theorem dotProduct_mulVec [Fintype n] [Fintype m] [NonUnitalSemiring R] (v : m → R) (A : Matrix m n R) (w : n → R) : v ⬝ᵥ A *ᵥ w = v ᵥ* A ⬝ᵥ w := by simp only [dotProduct, vecMul, mulVec, Finset.mul_sum, Finset.sum_mul, mul_assoc] exact Finset.sum_comm #align matrix.dot_product_mul_vec Matrix.dotProduct_mulVec @[simp] theorem mulVec_zero [Fintype n] (A : Matrix m n α) : A *ᵥ 0 = 0 := by ext simp [mulVec] #align matrix.mul_vec_zero Matrix.mulVec_zero @[simp] theorem zero_vecMul [Fintype m] (A : Matrix m n α) : 0 ᵥ* A = 0 := by ext simp [vecMul] #align matrix.zero_vec_mul Matrix.zero_vecMul @[simp] theorem zero_mulVec [Fintype n] (v : n → α) : (0 : Matrix m n α) *ᵥ v = 0 := by ext simp [mulVec] #align matrix.zero_mul_vec Matrix.zero_mulVec @[simp] theorem vecMul_zero [Fintype m] (v : m → α) : v ᵥ* (0 : Matrix m n α) = 0 := by ext simp [vecMul] #align matrix.vec_mul_zero Matrix.vecMul_zero theorem smul_mulVec_assoc [Fintype n] [Monoid R] [DistribMulAction R α] [IsScalarTower R α α] (a : R) (A : Matrix m n α) (b : n → α) : (a • A) *ᵥ b = a • A *ᵥ b := by ext apply smul_dotProduct #align matrix.smul_mul_vec_assoc Matrix.smul_mulVec_assoc theorem mulVec_add [Fintype n] (A : Matrix m n α) (x y : n → α) : A *ᵥ (x + y) = A *ᵥ x + A *ᵥ y := by ext apply dotProduct_add #align matrix.mul_vec_add Matrix.mulVec_add theorem add_mulVec [Fintype n] (A B : Matrix m n α) (x : n → α) : (A + B) *ᵥ x = A *ᵥ x + B *ᵥ x := by ext apply add_dotProduct #align matrix.add_mul_vec Matrix.add_mulVec theorem vecMul_add [Fintype m] (A B : Matrix m n α) (x : m → α) : x ᵥ* (A + B) = x ᵥ* A + x ᵥ* B := by ext apply dotProduct_add #align matrix.vec_mul_add Matrix.vecMul_add theorem add_vecMul [Fintype m] (A : Matrix m n α) (x y : m → α) : (x + y) ᵥ* A = x ᵥ* A + y ᵥ* A := by ext apply add_dotProduct #align matrix.add_vec_mul Matrix.add_vecMul theorem vecMul_smul [Fintype n] [Monoid R] [NonUnitalNonAssocSemiring S] [DistribMulAction R S] [IsScalarTower R S S] (M : Matrix n m S) (b : R) (v : n → S) : (b • v) ᵥ* M = b • v ᵥ* M := by ext i simp only [vecMul, dotProduct, Finset.smul_sum, Pi.smul_apply, smul_mul_assoc] #align matrix.vec_mul_smul Matrix.vecMul_smul theorem mulVec_smul [Fintype n] [Monoid R] [NonUnitalNonAssocSemiring S] [DistribMulAction R S] [SMulCommClass R S S] (M : Matrix m n S) (b : R) (v : n → S) : M *ᵥ (b • v) = b • M *ᵥ v := by ext i simp only [mulVec, dotProduct, Finset.smul_sum, Pi.smul_apply, mul_smul_comm] #align matrix.mul_vec_smul Matrix.mulVec_smul @[simp] theorem mulVec_single [Fintype n] [DecidableEq n] [NonUnitalNonAssocSemiring R] (M : Matrix m n R) (j : n) (x : R) : M *ᵥ Pi.single j x = fun i => M i j * x := funext fun _ => dotProduct_single _ _ _ #align matrix.mul_vec_single Matrix.mulVec_single @[simp] theorem single_vecMul [Fintype m] [DecidableEq m] [NonUnitalNonAssocSemiring R] (M : Matrix m n R) (i : m) (x : R) : Pi.single i x ᵥ* M = fun j => x * M i j := funext fun _ => single_dotProduct _ _ _ #align matrix.single_vec_mul Matrix.single_vecMul -- @[simp] -- Porting note: not in simpNF theorem diagonal_mulVec_single [Fintype n] [DecidableEq n] [NonUnitalNonAssocSemiring R] (v : n → R) (j : n) (x : R) : diagonal v *ᵥ Pi.single j x = Pi.single j (v j * x) := by ext i rw [mulVec_diagonal] exact Pi.apply_single (fun i x => v i * x) (fun i => mul_zero _) j x i #align matrix.diagonal_mul_vec_single Matrix.diagonal_mulVec_single -- @[simp] -- Porting note: not in simpNF theorem single_vecMul_diagonal [Fintype n] [DecidableEq n] [NonUnitalNonAssocSemiring R] (v : n → R) (j : n) (x : R) : (Pi.single j x) ᵥ* (diagonal v) = Pi.single j (x * v j) := by ext i rw [vecMul_diagonal] exact Pi.apply_single (fun i x => x * v i) (fun i => zero_mul _) j x i #align matrix.single_vec_mul_diagonal Matrix.single_vecMul_diagonal end NonUnitalNonAssocSemiring section NonUnitalSemiring variable [NonUnitalSemiring α] @[simp] theorem vecMul_vecMul [Fintype n] [Fintype m] (v : m → α) (M : Matrix m n α) (N : Matrix n o α) : v ᵥ* M ᵥ* N = v ᵥ* (M * N) := by ext apply dotProduct_assoc #align matrix.vec_mul_vec_mul Matrix.vecMul_vecMul @[simp] theorem mulVec_mulVec [Fintype n] [Fintype o] (v : o → α) (M : Matrix m n α) (N : Matrix n o α) : M *ᵥ N *ᵥ v = (M * N) *ᵥ v := by ext symm apply dotProduct_assoc #align matrix.mul_vec_mul_vec Matrix.mulVec_mulVec theorem star_mulVec [Fintype n] [StarRing α] (M : Matrix m n α) (v : n → α) : star (M *ᵥ v) = star v ᵥ* Mᴴ := funext fun _ => (star_dotProduct_star _ _).symm #align matrix.star_mul_vec Matrix.star_mulVec theorem star_vecMul [Fintype m] [StarRing α] (M : Matrix m n α) (v : m → α) : star (v ᵥ* M) = Mᴴ *ᵥ star v := funext fun _ => (star_dotProduct_star _ _).symm #align matrix.star_vec_mul Matrix.star_vecMul theorem mulVec_conjTranspose [Fintype m] [StarRing α] (A : Matrix m n α) (x : m → α) : Aᴴ *ᵥ x = star (star x ᵥ* A) := funext fun _ => star_dotProduct _ _ #align matrix.mul_vec_conj_transpose Matrix.mulVec_conjTranspose theorem vecMul_conjTranspose [Fintype n] [StarRing α] (A : Matrix m n α) (x : n → α) : x ᵥ* Aᴴ = star (A *ᵥ star x) := funext fun _ => dotProduct_star _ _ #align matrix.vec_mul_conj_transpose Matrix.vecMul_conjTranspose theorem mul_mul_apply [Fintype n] (A B C : Matrix n n α) (i j : n) : (A * B * C) i j = A i ⬝ᵥ B *ᵥ (Cᵀ j) := by rw [Matrix.mul_assoc] simp only [mul_apply, dotProduct, mulVec] rfl #align matrix.mul_mul_apply Matrix.mul_mul_apply end NonUnitalSemiring section NonAssocSemiring variable [NonAssocSemiring α] theorem mulVec_one [Fintype n] (A : Matrix m n α) : A *ᵥ 1 = fun i => ∑ j, A i j := by ext; simp [mulVec, dotProduct] #align matrix.mul_vec_one Matrix.mulVec_one theorem vec_one_mul [Fintype m] (A : Matrix m n α) : 1 ᵥ* A = fun j => ∑ i, A i j := by ext; simp [vecMul, dotProduct] #align matrix.vec_one_mul Matrix.vec_one_mul variable [Fintype m] [Fintype n] [DecidableEq m] @[simp] theorem one_mulVec (v : m → α) : 1 *ᵥ v = v := by ext rw [← diagonal_one, mulVec_diagonal, one_mul] #align matrix.one_mul_vec Matrix.one_mulVec @[simp] theorem vecMul_one (v : m → α) : v ᵥ* 1 = v := by ext rw [← diagonal_one, vecMul_diagonal, mul_one] #align matrix.vec_mul_one Matrix.vecMul_one @[simp] theorem diagonal_const_mulVec (x : α) (v : m → α) : (diagonal fun _ => x) *ᵥ v = x • v := by ext; simp [mulVec_diagonal] @[simp] theorem vecMul_diagonal_const (x : α) (v : m → α) : v ᵥ* (diagonal fun _ => x) = MulOpposite.op x • v := by ext; simp [vecMul_diagonal] @[simp] theorem natCast_mulVec (x : ℕ) (v : m → α) : x *ᵥ v = (x : α) • v := diagonal_const_mulVec _ _ @[simp] theorem vecMul_natCast (x : ℕ) (v : m → α) : v ᵥ* x = MulOpposite.op (x : α) • v := vecMul_diagonal_const _ _ -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_mulVec (x : ℕ) [x.AtLeastTwo] (v : m → α) : OfNat.ofNat (no_index x) *ᵥ v = (OfNat.ofNat x : α) • v := natCast_mulVec _ _ -- See note [no_index around OfNat.ofNat] @[simp] theorem vecMul_ofNat (x : ℕ) [x.AtLeastTwo] (v : m → α) : v ᵥ* OfNat.ofNat (no_index x) = MulOpposite.op (OfNat.ofNat x : α) • v := vecMul_natCast _ _ end NonAssocSemiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing α] theorem neg_vecMul [Fintype m] (v : m → α) (A : Matrix m n α) : (-v) ᵥ* A = - (v ᵥ* A) := by ext apply neg_dotProduct #align matrix.neg_vec_mul Matrix.neg_vecMul theorem vecMul_neg [Fintype m] (v : m → α) (A : Matrix m n α) : v ᵥ* (-A) = - (v ᵥ* A) := by ext apply dotProduct_neg #align matrix.vec_mul_neg Matrix.vecMul_neg lemma neg_vecMul_neg [Fintype m] (v : m → α) (A : Matrix m n α) : (-v) ᵥ* (-A) = v ᵥ* A := by rw [vecMul_neg, neg_vecMul, neg_neg] theorem neg_mulVec [Fintype n] (v : n → α) (A : Matrix m n α) : (-A) *ᵥ v = - (A *ᵥ v) := by ext apply neg_dotProduct #align matrix.neg_mul_vec Matrix.neg_mulVec theorem mulVec_neg [Fintype n] (v : n → α) (A : Matrix m n α) : A *ᵥ (-v) = - (A *ᵥ v) := by ext apply dotProduct_neg #align matrix.mul_vec_neg Matrix.mulVec_neg lemma neg_mulVec_neg [Fintype n] (v : n → α) (A : Matrix m n α) : (-A) *ᵥ (-v) = A *ᵥ v := by rw [mulVec_neg, neg_mulVec, neg_neg] theorem mulVec_sub [Fintype n] (A : Matrix m n α) (x y : n → α) : A *ᵥ (x - y) = A *ᵥ x - A *ᵥ y := by ext apply dotProduct_sub theorem sub_mulVec [Fintype n] (A B : Matrix m n α) (x : n → α) : (A - B) *ᵥ x = A *ᵥ x - B *ᵥ x := by simp [sub_eq_add_neg, add_mulVec, neg_mulVec] #align matrix.sub_mul_vec Matrix.sub_mulVec theorem vecMul_sub [Fintype m] (A B : Matrix m n α) (x : m → α) : x ᵥ* (A - B) = x ᵥ* A - x ᵥ* B := by simp [sub_eq_add_neg, vecMul_add, vecMul_neg] #align matrix.vec_mul_sub Matrix.vecMul_sub theorem sub_vecMul [Fintype m] (A : Matrix m n α) (x y : m → α) : (x - y) ᵥ* A = x ᵥ* A - y ᵥ* A := by ext apply sub_dotProduct end NonUnitalNonAssocRing section NonUnitalCommSemiring variable [NonUnitalCommSemiring α] theorem mulVec_transpose [Fintype m] (A : Matrix m n α) (x : m → α) : Aᵀ *ᵥ x = x ᵥ* A := by ext apply dotProduct_comm #align matrix.mul_vec_transpose Matrix.mulVec_transpose theorem vecMul_transpose [Fintype n] (A : Matrix m n α) (x : n → α) : x ᵥ* Aᵀ = A *ᵥ x := by ext apply dotProduct_comm #align matrix.vec_mul_transpose Matrix.vecMul_transpose theorem mulVec_vecMul [Fintype n] [Fintype o] (A : Matrix m n α) (B : Matrix o n α) (x : o → α) : A *ᵥ (x ᵥ* B) = (A * Bᵀ) *ᵥ x := by rw [← mulVec_mulVec, mulVec_transpose] #align matrix.mul_vec_vec_mul Matrix.mulVec_vecMul theorem vecMul_mulVec [Fintype m] [Fintype n] (A : Matrix m n α) (B : Matrix m o α) (x : n → α) : (A *ᵥ x) ᵥ* B = x ᵥ* (Aᵀ * B) := by rw [← vecMul_vecMul, vecMul_transpose] #align matrix.vec_mul_mul_vec Matrix.vecMul_mulVec end NonUnitalCommSemiring section CommSemiring variable [CommSemiring α] theorem mulVec_smul_assoc [Fintype n] (A : Matrix m n α) (b : n → α) (a : α) : A *ᵥ (a • b) = a • A *ᵥ b := by ext apply dotProduct_smul #align matrix.mul_vec_smul_assoc Matrix.mulVec_smul_assoc end CommSemiring section NonAssocRing variable [NonAssocRing α] variable [Fintype m] [DecidableEq m] @[simp] theorem intCast_mulVec (x : ℤ) (v : m → α) : x *ᵥ v = (x : α) • v := diagonal_const_mulVec _ _ @[simp] theorem vecMul_intCast (x : ℤ) (v : m → α) : v ᵥ* x = MulOpposite.op (x : α) • v := vecMul_diagonal_const _ _ end NonAssocRing section Transpose open Matrix @[simp] theorem transpose_transpose (M : Matrix m n α) : Mᵀᵀ = M := by ext rfl #align matrix.transpose_transpose Matrix.transpose_transpose theorem transpose_injective : Function.Injective (transpose : Matrix m n α → Matrix n m α) := fun _ _ h => ext fun i j => ext_iff.2 h j i @[simp] theorem transpose_inj {A B : Matrix m n α} : Aᵀ = Bᵀ ↔ A = B := transpose_injective.eq_iff @[simp] theorem transpose_zero [Zero α] : (0 : Matrix m n α)ᵀ = 0 := by ext rfl #align matrix.transpose_zero Matrix.transpose_zero @[simp] theorem transpose_eq_zero [Zero α] {M : Matrix m n α} : Mᵀ = 0 ↔ M = 0 := transpose_inj @[simp] theorem transpose_one [DecidableEq n] [Zero α] [One α] : (1 : Matrix n n α)ᵀ = 1 := by ext i j rw [transpose_apply, ← diagonal_one] by_cases h : i = j · simp only [h, diagonal_apply_eq] · simp only [diagonal_apply_ne _ h, diagonal_apply_ne' _ h] #align matrix.transpose_one Matrix.transpose_one @[simp] theorem transpose_eq_one [DecidableEq n] [Zero α] [One α] {M : Matrix n n α} : Mᵀ = 1 ↔ M = 1 := (Function.Involutive.eq_iff transpose_transpose).trans <| by rw [transpose_one] @[simp] theorem transpose_add [Add α] (M : Matrix m n α) (N : Matrix m n α) : (M + N)ᵀ = Mᵀ + Nᵀ := by ext simp #align matrix.transpose_add Matrix.transpose_add @[simp] theorem transpose_sub [Sub α] (M : Matrix m n α) (N : Matrix m n α) : (M - N)ᵀ = Mᵀ - Nᵀ := by ext simp #align matrix.transpose_sub Matrix.transpose_sub @[simp] theorem transpose_mul [AddCommMonoid α] [CommSemigroup α] [Fintype n] (M : Matrix m n α) (N : Matrix n l α) : (M * N)ᵀ = Nᵀ * Mᵀ := by ext apply dotProduct_comm #align matrix.transpose_mul Matrix.transpose_mul @[simp] theorem transpose_smul {R : Type*} [SMul R α] (c : R) (M : Matrix m n α) : (c • M)ᵀ = c • Mᵀ := by ext rfl #align matrix.transpose_smul Matrix.transpose_smul @[simp] theorem transpose_neg [Neg α] (M : Matrix m n α) : (-M)ᵀ = -Mᵀ := by ext rfl #align matrix.transpose_neg Matrix.transpose_neg theorem transpose_map {f : α → β} {M : Matrix m n α} : Mᵀ.map f = (M.map f)ᵀ := by ext rfl #align matrix.transpose_map Matrix.transpose_map variable (m n α) /-- `Matrix.transpose` as an `AddEquiv` -/ @[simps apply] def transposeAddEquiv [Add α] : Matrix m n α ≃+ Matrix n m α where toFun := transpose invFun := transpose left_inv := transpose_transpose right_inv := transpose_transpose map_add' := transpose_add #align matrix.transpose_add_equiv Matrix.transposeAddEquiv @[simp] theorem transposeAddEquiv_symm [Add α] : (transposeAddEquiv m n α).symm = transposeAddEquiv n m α := rfl #align matrix.transpose_add_equiv_symm Matrix.transposeAddEquiv_symm variable {m n α} theorem transpose_list_sum [AddMonoid α] (l : List (Matrix m n α)) : l.sumᵀ = (l.map transpose).sum := map_list_sum (transposeAddEquiv m n α) l #align matrix.transpose_list_sum Matrix.transpose_list_sum theorem transpose_multiset_sum [AddCommMonoid α] (s : Multiset (Matrix m n α)) : s.sumᵀ = (s.map transpose).sum := (transposeAddEquiv m n α).toAddMonoidHom.map_multiset_sum s #align matrix.transpose_multiset_sum Matrix.transpose_multiset_sum theorem transpose_sum [AddCommMonoid α] {ι : Type*} (s : Finset ι) (M : ι → Matrix m n α) : (∑ i ∈ s, M i)ᵀ = ∑ i ∈ s, (M i)ᵀ := map_sum (transposeAddEquiv m n α) _ s #align matrix.transpose_sum Matrix.transpose_sum variable (m n R α) /-- `Matrix.transpose` as a `LinearMap` -/ @[simps apply] def transposeLinearEquiv [Semiring R] [AddCommMonoid α] [Module R α] : Matrix m n α ≃ₗ[R] Matrix n m α := { transposeAddEquiv m n α with map_smul' := transpose_smul } #align matrix.transpose_linear_equiv Matrix.transposeLinearEquiv @[simp] theorem transposeLinearEquiv_symm [Semiring R] [AddCommMonoid α] [Module R α] : (transposeLinearEquiv m n R α).symm = transposeLinearEquiv n m R α := rfl #align matrix.transpose_linear_equiv_symm Matrix.transposeLinearEquiv_symm variable {m n R α} variable (m α) /-- `Matrix.transpose` as a `RingEquiv` to the opposite ring -/ @[simps] def transposeRingEquiv [AddCommMonoid α] [CommSemigroup α] [Fintype m] : Matrix m m α ≃+* (Matrix m m α)ᵐᵒᵖ := { (transposeAddEquiv m m α).trans MulOpposite.opAddEquiv with toFun := fun M => MulOpposite.op Mᵀ invFun := fun M => M.unopᵀ map_mul' := fun M N => (congr_arg MulOpposite.op (transpose_mul M N)).trans (MulOpposite.op_mul _ _) left_inv := fun M => transpose_transpose M right_inv := fun M => MulOpposite.unop_injective <| transpose_transpose M.unop } #align matrix.transpose_ring_equiv Matrix.transposeRingEquiv variable {m α} @[simp] theorem transpose_pow [CommSemiring α] [Fintype m] [DecidableEq m] (M : Matrix m m α) (k : ℕ) : (M ^ k)ᵀ = Mᵀ ^ k := MulOpposite.op_injective <| map_pow (transposeRingEquiv m α) M k #align matrix.transpose_pow Matrix.transpose_pow theorem transpose_list_prod [CommSemiring α] [Fintype m] [DecidableEq m] (l : List (Matrix m m α)) : l.prodᵀ = (l.map transpose).reverse.prod := (transposeRingEquiv m α).unop_map_list_prod l #align matrix.transpose_list_prod Matrix.transpose_list_prod variable (R m α) /-- `Matrix.transpose` as an `AlgEquiv` to the opposite ring -/ @[simps] def transposeAlgEquiv [CommSemiring R] [CommSemiring α] [Fintype m] [DecidableEq m] [Algebra R α] : Matrix m m α ≃ₐ[R] (Matrix m m α)ᵐᵒᵖ := { (transposeAddEquiv m m α).trans MulOpposite.opAddEquiv, transposeRingEquiv m α with toFun := fun M => MulOpposite.op Mᵀ commutes' := fun r => by simp only [algebraMap_eq_diagonal, diagonal_transpose, MulOpposite.algebraMap_apply] } #align matrix.transpose_alg_equiv Matrix.transposeAlgEquiv variable {R m α} end Transpose section ConjTranspose open Matrix /-- Tell `simp` what the entries are in a conjugate transposed matrix. Compare with `mul_apply`, `diagonal_apply_eq`, etc. -/ @[simp] theorem conjTranspose_apply [Star α] (M : Matrix m n α) (i j) : M.conjTranspose j i = star (M i j) := rfl #align matrix.conj_transpose_apply Matrix.conjTranspose_apply @[simp] theorem conjTranspose_conjTranspose [InvolutiveStar α] (M : Matrix m n α) : Mᴴᴴ = M := Matrix.ext <| by simp #align matrix.conj_transpose_conj_transpose Matrix.conjTranspose_conjTranspose theorem conjTranspose_injective [InvolutiveStar α] : Function.Injective (conjTranspose : Matrix m n α → Matrix n m α) := (map_injective star_injective).comp transpose_injective @[simp] theorem conjTranspose_inj [InvolutiveStar α] {A B : Matrix m n α} : Aᴴ = Bᴴ ↔ A = B := conjTranspose_injective.eq_iff @[simp] theorem conjTranspose_zero [AddMonoid α] [StarAddMonoid α] : (0 : Matrix m n α)ᴴ = 0 := Matrix.ext <| by simp #align matrix.conj_transpose_zero Matrix.conjTranspose_zero @[simp] theorem conjTranspose_eq_zero [AddMonoid α] [StarAddMonoid α] {M : Matrix m n α} : Mᴴ = 0 ↔ M = 0 := by rw [← conjTranspose_inj (A := M), conjTranspose_zero] @[simp] theorem conjTranspose_one [DecidableEq n] [Semiring α] [StarRing α] : (1 : Matrix n n α)ᴴ = 1 := by simp [conjTranspose] #align matrix.conj_transpose_one Matrix.conjTranspose_one @[simp] theorem conjTranspose_eq_one [DecidableEq n] [Semiring α] [StarRing α] {M : Matrix n n α} : Mᴴ = 1 ↔ M = 1 := (Function.Involutive.eq_iff conjTranspose_conjTranspose).trans <| by rw [conjTranspose_one] @[simp] theorem conjTranspose_add [AddMonoid α] [StarAddMonoid α] (M N : Matrix m n α) : (M + N)ᴴ = Mᴴ + Nᴴ := Matrix.ext <| by simp #align matrix.conj_transpose_add Matrix.conjTranspose_add @[simp] theorem conjTranspose_sub [AddGroup α] [StarAddMonoid α] (M N : Matrix m n α) : (M - N)ᴴ = Mᴴ - Nᴴ := Matrix.ext <| by simp #align matrix.conj_transpose_sub Matrix.conjTranspose_sub /-- Note that `StarModule` is quite a strong requirement; as such we also provide the following variants which this lemma would not apply to: * `Matrix.conjTranspose_smul_non_comm` * `Matrix.conjTranspose_nsmul` * `Matrix.conjTranspose_zsmul` * `Matrix.conjTranspose_natCast_smul` * `Matrix.conjTranspose_intCast_smul` * `Matrix.conjTranspose_inv_natCast_smul` * `Matrix.conjTranspose_inv_intCast_smul` * `Matrix.conjTranspose_rat_smul` * `Matrix.conjTranspose_ratCast_smul` -/ @[simp] theorem conjTranspose_smul [Star R] [Star α] [SMul R α] [StarModule R α] (c : R) (M : Matrix m n α) : (c • M)ᴴ = star c • Mᴴ := Matrix.ext fun _ _ => star_smul _ _ #align matrix.conj_transpose_smul Matrix.conjTranspose_smul @[simp] theorem conjTranspose_smul_non_comm [Star R] [Star α] [SMul R α] [SMul Rᵐᵒᵖ α] (c : R) (M : Matrix m n α) (h : ∀ (r : R) (a : α), star (r • a) = MulOpposite.op (star r) • star a) : (c • M)ᴴ = MulOpposite.op (star c) • Mᴴ := Matrix.ext <| by simp [h] #align matrix.conj_transpose_smul_non_comm Matrix.conjTranspose_smul_non_comm -- @[simp] -- Porting note (#10618): simp can prove this theorem conjTranspose_smul_self [Mul α] [StarMul α] (c : α) (M : Matrix m n α) : (c • M)ᴴ = MulOpposite.op (star c) • Mᴴ := conjTranspose_smul_non_comm c M star_mul #align matrix.conj_transpose_smul_self Matrix.conjTranspose_smul_self @[simp] theorem conjTranspose_nsmul [AddMonoid α] [StarAddMonoid α] (c : ℕ) (M : Matrix m n α) : (c • M)ᴴ = c • Mᴴ := Matrix.ext <| by simp #align matrix.conj_transpose_nsmul Matrix.conjTranspose_nsmul @[simp] theorem conjTranspose_zsmul [AddGroup α] [StarAddMonoid α] (c : ℤ) (M : Matrix m n α) : (c • M)ᴴ = c • Mᴴ := Matrix.ext <| by simp #align matrix.conj_transpose_zsmul Matrix.conjTranspose_zsmul @[simp] theorem conjTranspose_natCast_smul [Semiring R] [AddCommMonoid α] [StarAddMonoid α] [Module R α] (c : ℕ) (M : Matrix m n α) : ((c : R) • M)ᴴ = (c : R) • Mᴴ := Matrix.ext <| by simp #align matrix.conj_transpose_nat_cast_smul Matrix.conjTranspose_natCast_smul -- See note [no_index around OfNat.ofNat] @[simp] theorem conjTranspose_ofNat_smul [Semiring R] [AddCommMonoid α] [StarAddMonoid α] [Module R α] (c : ℕ) [c.AtLeastTwo] (M : Matrix m n α) : ((no_index (OfNat.ofNat c : R)) • M)ᴴ = (OfNat.ofNat c : R) • Mᴴ := conjTranspose_natCast_smul c M @[simp] theorem conjTranspose_intCast_smul [Ring R] [AddCommGroup α] [StarAddMonoid α] [Module R α] (c : ℤ) (M : Matrix m n α) : ((c : R) • M)ᴴ = (c : R) • Mᴴ := Matrix.ext <| by simp #align matrix.conj_transpose_int_cast_smul Matrix.conjTranspose_intCast_smul @[simp] theorem conjTranspose_inv_natCast_smul [DivisionSemiring R] [AddCommMonoid α] [StarAddMonoid α] [Module R α] (c : ℕ) (M : Matrix m n α) : ((c : R)⁻¹ • M)ᴴ = (c : R)⁻¹ • Mᴴ := Matrix.ext <| by simp #align matrix.conj_transpose_inv_nat_cast_smul Matrix.conjTranspose_inv_natCast_smul -- See note [no_index around OfNat.ofNat] @[simp] theorem conjTranspose_inv_ofNat_smul [DivisionSemiring R] [AddCommMonoid α] [StarAddMonoid α] [Module R α] (c : ℕ) [c.AtLeastTwo] (M : Matrix m n α) : ((no_index (OfNat.ofNat c : R))⁻¹ • M)ᴴ = (OfNat.ofNat c : R)⁻¹ • Mᴴ := conjTranspose_inv_natCast_smul c M @[simp] theorem conjTranspose_inv_intCast_smul [DivisionRing R] [AddCommGroup α] [StarAddMonoid α] [Module R α] (c : ℤ) (M : Matrix m n α) : ((c : R)⁻¹ • M)ᴴ = (c : R)⁻¹ • Mᴴ := Matrix.ext <| by simp #align matrix.conj_transpose_inv_int_cast_smul Matrix.conjTranspose_inv_intCast_smul @[simp] theorem conjTranspose_ratCast_smul [DivisionRing R] [AddCommGroup α] [StarAddMonoid α] [Module R α] (c : ℚ) (M : Matrix m n α) : ((c : R) • M)ᴴ = (c : R) • Mᴴ := Matrix.ext <| by simp #align matrix.conj_transpose_rat_cast_smul Matrix.conjTranspose_ratCast_smul #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma. See https://github.com/leanprover-community/mathlib4/issues/12231 -/ @[simp, nolint simpNF] theorem conjTranspose_rat_smul [AddCommGroup α] [StarAddMonoid α] [Module ℚ α] (c : ℚ) (M : Matrix m n α) : (c • M)ᴴ = c • Mᴴ := Matrix.ext <| by simp #align matrix.conj_transpose_rat_smul Matrix.conjTranspose_rat_smul @[simp] theorem conjTranspose_mul [Fintype n] [NonUnitalSemiring α] [StarRing α] (M : Matrix m n α) (N : Matrix n l α) : (M * N)ᴴ = Nᴴ * Mᴴ := Matrix.ext <| by simp [mul_apply] #align matrix.conj_transpose_mul Matrix.conjTranspose_mul @[simp] theorem conjTranspose_neg [AddGroup α] [StarAddMonoid α] (M : Matrix m n α) : (-M)ᴴ = -Mᴴ := Matrix.ext <| by simp #align matrix.conj_transpose_neg Matrix.conjTranspose_neg theorem conjTranspose_map [Star α] [Star β] {A : Matrix m n α} (f : α → β) (hf : Function.Semiconj f star star) : Aᴴ.map f = (A.map f)ᴴ := Matrix.ext fun _ _ => hf _ #align matrix.conj_transpose_map Matrix.conjTranspose_map /-- When `star x = x` on the coefficients (such as the real numbers) `conjTranspose` and `transpose` are the same operation. -/ @[simp] theorem conjTranspose_eq_transpose_of_trivial [Star α] [TrivialStar α] (A : Matrix m n α) : Aᴴ = Aᵀ := Matrix.ext fun _ _ => star_trivial _ variable (m n α) /-- `Matrix.conjTranspose` as an `AddEquiv` -/ @[simps apply] def conjTransposeAddEquiv [AddMonoid α] [StarAddMonoid α] : Matrix m n α ≃+ Matrix n m α where toFun := conjTranspose invFun := conjTranspose left_inv := conjTranspose_conjTranspose right_inv := conjTranspose_conjTranspose map_add' := conjTranspose_add #align matrix.conj_transpose_add_equiv Matrix.conjTransposeAddEquiv @[simp] theorem conjTransposeAddEquiv_symm [AddMonoid α] [StarAddMonoid α] : (conjTransposeAddEquiv m n α).symm = conjTransposeAddEquiv n m α := rfl #align matrix.conj_transpose_add_equiv_symm Matrix.conjTransposeAddEquiv_symm variable {m n α} theorem conjTranspose_list_sum [AddMonoid α] [StarAddMonoid α] (l : List (Matrix m n α)) : l.sumᴴ = (l.map conjTranspose).sum := map_list_sum (conjTransposeAddEquiv m n α) l #align matrix.conj_transpose_list_sum Matrix.conjTranspose_list_sum theorem conjTranspose_multiset_sum [AddCommMonoid α] [StarAddMonoid α] (s : Multiset (Matrix m n α)) : s.sumᴴ = (s.map conjTranspose).sum := (conjTransposeAddEquiv m n α).toAddMonoidHom.map_multiset_sum s #align matrix.conj_transpose_multiset_sum Matrix.conjTranspose_multiset_sum theorem conjTranspose_sum [AddCommMonoid α] [StarAddMonoid α] {ι : Type*} (s : Finset ι) (M : ι → Matrix m n α) : (∑ i ∈ s, M i)ᴴ = ∑ i ∈ s, (M i)ᴴ := map_sum (conjTransposeAddEquiv m n α) _ s #align matrix.conj_transpose_sum Matrix.conjTranspose_sum variable (m n R α) /-- `Matrix.conjTranspose` as a `LinearMap` -/ @[simps apply] def conjTransposeLinearEquiv [CommSemiring R] [StarRing R] [AddCommMonoid α] [StarAddMonoid α] [Module R α] [StarModule R α] : Matrix m n α ≃ₗ⋆[R] Matrix n m α := { conjTransposeAddEquiv m n α with map_smul' := conjTranspose_smul } #align matrix.conj_transpose_linear_equiv Matrix.conjTransposeLinearEquiv @[simp] theorem conjTransposeLinearEquiv_symm [CommSemiring R] [StarRing R] [AddCommMonoid α] [StarAddMonoid α] [Module R α] [StarModule R α] : (conjTransposeLinearEquiv m n R α).symm = conjTransposeLinearEquiv n m R α := rfl #align matrix.conj_transpose_linear_equiv_symm Matrix.conjTransposeLinearEquiv_symm variable {m n R α} variable (m α) /-- `Matrix.conjTranspose` as a `RingEquiv` to the opposite ring -/ @[simps] def conjTransposeRingEquiv [Semiring α] [StarRing α] [Fintype m] : Matrix m m α ≃+* (Matrix m m α)ᵐᵒᵖ := { (conjTransposeAddEquiv m m α).trans MulOpposite.opAddEquiv with toFun := fun M => MulOpposite.op Mᴴ invFun := fun M => M.unopᴴ map_mul' := fun M N => (congr_arg MulOpposite.op (conjTranspose_mul M N)).trans (MulOpposite.op_mul _ _) } #align matrix.conj_transpose_ring_equiv Matrix.conjTransposeRingEquiv variable {m α} @[simp] theorem conjTranspose_pow [Semiring α] [StarRing α] [Fintype m] [DecidableEq m] (M : Matrix m m α) (k : ℕ) : (M ^ k)ᴴ = Mᴴ ^ k := MulOpposite.op_injective <| map_pow (conjTransposeRingEquiv m α) M k #align matrix.conj_transpose_pow Matrix.conjTranspose_pow theorem conjTranspose_list_prod [Semiring α] [StarRing α] [Fintype m] [DecidableEq m] (l : List (Matrix m m α)) : l.prodᴴ = (l.map conjTranspose).reverse.prod := (conjTransposeRingEquiv m α).unop_map_list_prod l #align matrix.conj_transpose_list_prod Matrix.conjTranspose_list_prod end ConjTranspose section Star /-- When `α` has a star operation, square matrices `Matrix n n α` have a star operation equal to `Matrix.conjTranspose`. -/ instance [Star α] : Star (Matrix n n α) where star := conjTranspose theorem star_eq_conjTranspose [Star α] (M : Matrix m m α) : star M = Mᴴ := rfl #align matrix.star_eq_conj_transpose Matrix.star_eq_conjTranspose @[simp] theorem star_apply [Star α] (M : Matrix n n α) (i j) : (star M) i j = star (M j i) := rfl #align matrix.star_apply Matrix.star_apply instance [InvolutiveStar α] : InvolutiveStar (Matrix n n α) where star_involutive := conjTranspose_conjTranspose /-- When `α` is a `*`-additive monoid, `Matrix.star` is also a `*`-additive monoid. -/ instance [AddMonoid α] [StarAddMonoid α] : StarAddMonoid (Matrix n n α) where star_add := conjTranspose_add instance [Star α] [Star β] [SMul α β] [StarModule α β] : StarModule α (Matrix n n β) where star_smul := conjTranspose_smul /-- When `α` is a `*`-(semi)ring, `Matrix.star` is also a `*`-(semi)ring. -/ instance [Fintype n] [NonUnitalSemiring α] [StarRing α] : StarRing (Matrix n n α) where star_add := conjTranspose_add star_mul := conjTranspose_mul /-- A version of `star_mul` for `*` instead of `*`. -/ theorem star_mul [Fintype n] [NonUnitalSemiring α] [StarRing α] (M N : Matrix n n α) : star (M * N) = star N * star M := conjTranspose_mul _ _ #align matrix.star_mul Matrix.star_mul end Star /-- Given maps `(r_reindex : l → m)` and `(c_reindex : o → n)` reindexing the rows and columns of a matrix `M : Matrix m n α`, the matrix `M.submatrix r_reindex c_reindex : Matrix l o α` is defined by `(M.submatrix r_reindex c_reindex) i j = M (r_reindex i) (c_reindex j)` for `(i,j) : l × o`. Note that the total number of row and columns does not have to be preserved. -/ def submatrix (A : Matrix m n α) (r_reindex : l → m) (c_reindex : o → n) : Matrix l o α := of fun i j => A (r_reindex i) (c_reindex j) #align matrix.submatrix Matrix.submatrix @[simp] theorem submatrix_apply (A : Matrix m n α) (r_reindex : l → m) (c_reindex : o → n) (i j) : A.submatrix r_reindex c_reindex i j = A (r_reindex i) (c_reindex j) := rfl #align matrix.submatrix_apply Matrix.submatrix_apply @[simp] theorem submatrix_id_id (A : Matrix m n α) : A.submatrix id id = A := ext fun _ _ => rfl #align matrix.submatrix_id_id Matrix.submatrix_id_id @[simp] theorem submatrix_submatrix {l₂ o₂ : Type*} (A : Matrix m n α) (r₁ : l → m) (c₁ : o → n) (r₂ : l₂ → l) (c₂ : o₂ → o) : (A.submatrix r₁ c₁).submatrix r₂ c₂ = A.submatrix (r₁ ∘ r₂) (c₁ ∘ c₂) := ext fun _ _ => rfl #align matrix.submatrix_submatrix Matrix.submatrix_submatrix @[simp] theorem transpose_submatrix (A : Matrix m n α) (r_reindex : l → m) (c_reindex : o → n) : (A.submatrix r_reindex c_reindex)ᵀ = Aᵀ.submatrix c_reindex r_reindex := ext fun _ _ => rfl #align matrix.transpose_submatrix Matrix.transpose_submatrix @[simp] theorem conjTranspose_submatrix [Star α] (A : Matrix m n α) (r_reindex : l → m) (c_reindex : o → n) : (A.submatrix r_reindex c_reindex)ᴴ = Aᴴ.submatrix c_reindex r_reindex := ext fun _ _ => rfl #align matrix.conj_transpose_submatrix Matrix.conjTranspose_submatrix theorem submatrix_add [Add α] (A B : Matrix m n α) : ((A + B).submatrix : (l → m) → (o → n) → Matrix l o α) = A.submatrix + B.submatrix := rfl #align matrix.submatrix_add Matrix.submatrix_add theorem submatrix_neg [Neg α] (A : Matrix m n α) : ((-A).submatrix : (l → m) → (o → n) → Matrix l o α) = -A.submatrix := rfl #align matrix.submatrix_neg Matrix.submatrix_neg theorem submatrix_sub [Sub α] (A B : Matrix m n α) : ((A - B).submatrix : (l → m) → (o → n) → Matrix l o α) = A.submatrix - B.submatrix := rfl #align matrix.submatrix_sub Matrix.submatrix_sub @[simp] theorem submatrix_zero [Zero α] : ((0 : Matrix m n α).submatrix : (l → m) → (o → n) → Matrix l o α) = 0 := rfl #align matrix.submatrix_zero Matrix.submatrix_zero theorem submatrix_smul {R : Type*} [SMul R α] (r : R) (A : Matrix m n α) : ((r • A : Matrix m n α).submatrix : (l → m) → (o → n) → Matrix l o α) = r • A.submatrix := rfl #align matrix.submatrix_smul Matrix.submatrix_smul theorem submatrix_map (f : α → β) (e₁ : l → m) (e₂ : o → n) (A : Matrix m n α) : (A.map f).submatrix e₁ e₂ = (A.submatrix e₁ e₂).map f := rfl #align matrix.submatrix_map Matrix.submatrix_map /-- Given a `(m × m)` diagonal matrix defined by a map `d : m → α`, if the reindexing map `e` is injective, then the resulting matrix is again diagonal. -/ theorem submatrix_diagonal [Zero α] [DecidableEq m] [DecidableEq l] (d : m → α) (e : l → m) (he : Function.Injective e) : (diagonal d).submatrix e e = diagonal (d ∘ e) := ext fun i j => by rw [submatrix_apply] by_cases h : i = j · rw [h, diagonal_apply_eq, diagonal_apply_eq] simp only [Function.comp_apply] -- Porting note: (simp) added this · rw [diagonal_apply_ne _ h, diagonal_apply_ne _ (he.ne h)] #align matrix.submatrix_diagonal Matrix.submatrix_diagonal theorem submatrix_one [Zero α] [One α] [DecidableEq m] [DecidableEq l] (e : l → m) (he : Function.Injective e) : (1 : Matrix m m α).submatrix e e = 1 := submatrix_diagonal _ e he #align matrix.submatrix_one Matrix.submatrix_one theorem submatrix_mul [Fintype n] [Fintype o] [Mul α] [AddCommMonoid α] {p q : Type*} (M : Matrix m n α) (N : Matrix n p α) (e₁ : l → m) (e₂ : o → n) (e₃ : q → p) (he₂ : Function.Bijective e₂) : (M * N).submatrix e₁ e₃ = M.submatrix e₁ e₂ * N.submatrix e₂ e₃ := ext fun _ _ => (he₂.sum_comp _).symm #align matrix.submatrix_mul Matrix.submatrix_mul theorem diag_submatrix (A : Matrix m m α) (e : l → m) : diag (A.submatrix e e) = A.diag ∘ e := rfl #align matrix.diag_submatrix Matrix.diag_submatrix /-! `simp` lemmas for `Matrix.submatrix`s interaction with `Matrix.diagonal`, `1`, and `Matrix.mul` for when the mappings are bundled. -/ @[simp] theorem submatrix_diagonal_embedding [Zero α] [DecidableEq m] [DecidableEq l] (d : m → α) (e : l ↪ m) : (diagonal d).submatrix e e = diagonal (d ∘ e) := submatrix_diagonal d e e.injective #align matrix.submatrix_diagonal_embedding Matrix.submatrix_diagonal_embedding @[simp] theorem submatrix_diagonal_equiv [Zero α] [DecidableEq m] [DecidableEq l] (d : m → α) (e : l ≃ m) : (diagonal d).submatrix e e = diagonal (d ∘ e) := submatrix_diagonal d e e.injective #align matrix.submatrix_diagonal_equiv Matrix.submatrix_diagonal_equiv @[simp] theorem submatrix_one_embedding [Zero α] [One α] [DecidableEq m] [DecidableEq l] (e : l ↪ m) : (1 : Matrix m m α).submatrix e e = 1 := submatrix_one e e.injective #align matrix.submatrix_one_embedding Matrix.submatrix_one_embedding @[simp] theorem submatrix_one_equiv [Zero α] [One α] [DecidableEq m] [DecidableEq l] (e : l ≃ m) : (1 : Matrix m m α).submatrix e e = 1 := submatrix_one e e.injective #align matrix.submatrix_one_equiv Matrix.submatrix_one_equiv @[simp] theorem submatrix_mul_equiv [Fintype n] [Fintype o] [AddCommMonoid α] [Mul α] {p q : Type*} (M : Matrix m n α) (N : Matrix n p α) (e₁ : l → m) (e₂ : o ≃ n) (e₃ : q → p) : M.submatrix e₁ e₂ * N.submatrix e₂ e₃ = (M * N).submatrix e₁ e₃ := (submatrix_mul M N e₁ e₂ e₃ e₂.bijective).symm #align matrix.submatrix_mul_equiv Matrix.submatrix_mul_equiv theorem submatrix_mulVec_equiv [Fintype n] [Fintype o] [NonUnitalNonAssocSemiring α] (M : Matrix m n α) (v : o → α) (e₁ : l → m) (e₂ : o ≃ n) : M.submatrix e₁ e₂ *ᵥ v = (M *ᵥ (v ∘ e₂.symm)) ∘ e₁ := funext fun _ => Eq.symm (dotProduct_comp_equiv_symm _ _ _) #align matrix.submatrix_mul_vec_equiv Matrix.submatrix_mulVec_equiv theorem submatrix_vecMul_equiv [Fintype l] [Fintype m] [NonUnitalNonAssocSemiring α] (M : Matrix m n α) (v : l → α) (e₁ : l ≃ m) (e₂ : o → n) : v ᵥ* M.submatrix e₁ e₂ = ((v ∘ e₁.symm) ᵥ* M) ∘ e₂ := funext fun _ => Eq.symm (comp_equiv_symm_dotProduct _ _ _) #align matrix.submatrix_vec_mul_equiv Matrix.submatrix_vecMul_equiv theorem mul_submatrix_one [Fintype n] [Finite o] [NonAssocSemiring α] [DecidableEq o] (e₁ : n ≃ o) (e₂ : l → o) (M : Matrix m n α) : M * (1 : Matrix o o α).submatrix e₁ e₂ = submatrix M id (e₁.symm ∘ e₂) := by cases nonempty_fintype o let A := M.submatrix id e₁.symm have : M = A.submatrix id e₁ := by simp only [A, submatrix_submatrix, Function.comp_id, submatrix_id_id, Equiv.symm_comp_self] rw [this, submatrix_mul_equiv] simp only [A, Matrix.mul_one, submatrix_submatrix, Function.comp_id, submatrix_id_id, Equiv.symm_comp_self] #align matrix.mul_submatrix_one Matrix.mul_submatrix_one theorem one_submatrix_mul [Fintype m] [Finite o] [NonAssocSemiring α] [DecidableEq o] (e₁ : l → o) (e₂ : m ≃ o) (M : Matrix m n α) : ((1 : Matrix o o α).submatrix e₁ e₂) * M = submatrix M (e₂.symm ∘ e₁) id := by cases nonempty_fintype o let A := M.submatrix e₂.symm id have : M = A.submatrix e₂ id := by simp only [A, submatrix_submatrix, Function.comp_id, submatrix_id_id, Equiv.symm_comp_self] rw [this, submatrix_mul_equiv] simp only [A, Matrix.one_mul, submatrix_submatrix, Function.comp_id, submatrix_id_id, Equiv.symm_comp_self] #align matrix.one_submatrix_mul Matrix.one_submatrix_mul /-- The natural map that reindexes a matrix's rows and columns with equivalent types is an equivalence. -/ def reindex (eₘ : m ≃ l) (eₙ : n ≃ o) : Matrix m n α ≃ Matrix l o α where toFun M := M.submatrix eₘ.symm eₙ.symm invFun M := M.submatrix eₘ eₙ left_inv M := by simp right_inv M := by simp #align matrix.reindex Matrix.reindex @[simp] theorem reindex_apply (eₘ : m ≃ l) (eₙ : n ≃ o) (M : Matrix m n α) : reindex eₘ eₙ M = M.submatrix eₘ.symm eₙ.symm := rfl #align matrix.reindex_apply Matrix.reindex_apply -- @[simp] -- Porting note (#10618): simp can prove this theorem reindex_refl_refl (A : Matrix m n α) : reindex (Equiv.refl _) (Equiv.refl _) A = A := A.submatrix_id_id #align matrix.reindex_refl_refl Matrix.reindex_refl_refl @[simp] theorem reindex_symm (eₘ : m ≃ l) (eₙ : n ≃ o) : (reindex eₘ eₙ).symm = (reindex eₘ.symm eₙ.symm : Matrix l o α ≃ _) := rfl #align matrix.reindex_symm Matrix.reindex_symm @[simp] theorem reindex_trans {l₂ o₂ : Type*} (eₘ : m ≃ l) (eₙ : n ≃ o) (eₘ₂ : l ≃ l₂) (eₙ₂ : o ≃ o₂) : (reindex eₘ eₙ).trans (reindex eₘ₂ eₙ₂) = (reindex (eₘ.trans eₘ₂) (eₙ.trans eₙ₂) : Matrix m n α ≃ _) := Equiv.ext fun A => (A.submatrix_submatrix eₘ.symm eₙ.symm eₘ₂.symm eₙ₂.symm : _) #align matrix.reindex_trans Matrix.reindex_trans theorem transpose_reindex (eₘ : m ≃ l) (eₙ : n ≃ o) (M : Matrix m n α) : (reindex eₘ eₙ M)ᵀ = reindex eₙ eₘ Mᵀ := rfl #align matrix.transpose_reindex Matrix.transpose_reindex theorem conjTranspose_reindex [Star α] (eₘ : m ≃ l) (eₙ : n ≃ o) (M : Matrix m n α) : (reindex eₘ eₙ M)ᴴ = reindex eₙ eₘ Mᴴ := rfl #align matrix.conj_transpose_reindex Matrix.conjTranspose_reindex -- @[simp] -- Porting note (#10618): simp can prove this theorem submatrix_mul_transpose_submatrix [Fintype m] [Fintype n] [AddCommMonoid α] [Mul α] (e : m ≃ n) (M : Matrix m n α) : M.submatrix id e * Mᵀ.submatrix e id = M * Mᵀ := by rw [submatrix_mul_equiv, submatrix_id_id] #align matrix.submatrix_mul_transpose_submatrix Matrix.submatrix_mul_transpose_submatrix /-- The left `n × l` part of an `n × (l+r)` matrix. -/ abbrev subLeft {m l r : Nat} (A : Matrix (Fin m) (Fin (l + r)) α) : Matrix (Fin m) (Fin l) α := submatrix A id (Fin.castAdd r) #align matrix.sub_left Matrix.subLeft /-- The right `n × r` part of an `n × (l+r)` matrix. -/ abbrev subRight {m l r : Nat} (A : Matrix (Fin m) (Fin (l + r)) α) : Matrix (Fin m) (Fin r) α := submatrix A id (Fin.natAdd l) #align matrix.sub_right Matrix.subRight /-- The top `u × n` part of a `(u+d) × n` matrix. -/ abbrev subUp {d u n : Nat} (A : Matrix (Fin (u + d)) (Fin n) α) : Matrix (Fin u) (Fin n) α := submatrix A (Fin.castAdd d) id #align matrix.sub_up Matrix.subUp /-- The bottom `d × n` part of a `(u+d) × n` matrix. -/ abbrev subDown {d u n : Nat} (A : Matrix (Fin (u + d)) (Fin n) α) : Matrix (Fin d) (Fin n) α := submatrix A (Fin.natAdd u) id #align matrix.sub_down Matrix.subDown /-- The top-right `u × r` part of a `(u+d) × (l+r)` matrix. -/ abbrev subUpRight {d u l r : Nat} (A : Matrix (Fin (u + d)) (Fin (l + r)) α) : Matrix (Fin u) (Fin r) α := subUp (subRight A) #align matrix.sub_up_right Matrix.subUpRight /-- The bottom-right `d × r` part of a `(u+d) × (l+r)` matrix. -/ abbrev subDownRight {d u l r : Nat} (A : Matrix (Fin (u + d)) (Fin (l + r)) α) : Matrix (Fin d) (Fin r) α := subDown (subRight A) #align matrix.sub_down_right Matrix.subDownRight /-- The top-left `u × l` part of a `(u+d) × (l+r)` matrix. -/ abbrev subUpLeft {d u l r : Nat} (A : Matrix (Fin (u + d)) (Fin (l + r)) α) : Matrix (Fin u) (Fin l) α := subUp (subLeft A) #align matrix.sub_up_left Matrix.subUpLeft /-- The bottom-left `d × l` part of a `(u+d) × (l+r)` matrix. -/ abbrev subDownLeft {d u l r : Nat} (A : Matrix (Fin (u + d)) (Fin (l + r)) α) : Matrix (Fin d) (Fin l) α := subDown (subLeft A) #align matrix.sub_down_left Matrix.subDownLeft end Matrix namespace RingHom variable [Fintype n] [NonAssocSemiring α] [NonAssocSemiring β] theorem map_matrix_mul (M : Matrix m n α) (N : Matrix n o α) (i : m) (j : o) (f : α →+* β) : f ((M * N) i j) = (M.map f * N.map f) i j := by simp [Matrix.mul_apply, map_sum] #align ring_hom.map_matrix_mul RingHom.map_matrix_mul theorem map_dotProduct [NonAssocSemiring R] [NonAssocSemiring S] (f : R →+* S) (v w : n → R) : f (v ⬝ᵥ w) = f ∘ v ⬝ᵥ f ∘ w := by simp only [Matrix.dotProduct, map_sum f, f.map_mul, Function.comp] #align ring_hom.map_dot_product RingHom.map_dotProduct theorem map_vecMul [NonAssocSemiring R] [NonAssocSemiring S] (f : R →+* S) (M : Matrix n m R) (v : n → R) (i : m) : f ((v ᵥ* M) i) = ((f ∘ v) ᵥ* M.map f) i := by simp only [Matrix.vecMul, Matrix.map_apply, RingHom.map_dotProduct, Function.comp] #align ring_hom.map_vec_mul RingHom.map_vecMul
Mathlib/Data/Matrix/Basic.lean
2,781
2,783
theorem map_mulVec [NonAssocSemiring R] [NonAssocSemiring S] (f : R →+* S) (M : Matrix m n R) (v : n → R) (i : m) : f ((M *ᵥ v) i) = (M.map f *ᵥ (f ∘ v)) i := by
simp only [Matrix.mulVec, Matrix.map_apply, RingHom.map_dotProduct, Function.comp]
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.SeparableClosure import Mathlib.Algebra.CharP.IntermediateField /-! # Purely inseparable extension and relative perfect closure This file contains basics about purely inseparable extensions and the relative perfect closure of fields. ## Main definitions - `IsPurelyInseparable`: typeclass for purely inseparable field extensions: an algebraic extension `E / F` is purely inseparable if and only if the minimal polynomial of every element of `E ∖ F` is not separable. - `perfectClosure`: the relative perfect closure of `F` in `E`, it consists of the elements `x` of `E` such that there exists a natural number `n` such that `x ^ (ringExpChar F) ^ n` is contained in `F`, where `ringExpChar F` is the exponential characteristic of `F`. It is also the maximal purely inseparable subextension of `E / F` (`le_perfectClosure_iff`). ## Main results - `IsPurelyInseparable.surjective_algebraMap_of_isSeparable`, `IsPurelyInseparable.bijective_algebraMap_of_isSeparable`, `IntermediateField.eq_bot_of_isPurelyInseparable_of_isSeparable`: if `E / F` is both purely inseparable and separable, then `algebraMap F E` is surjective (hence bijective). In particular, if an intermediate field of `E / F` is both purely inseparable and separable, then it is equal to `F`. - `isPurelyInseparable_iff_pow_mem`: a field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, there exists a natural number `n` such that `x ^ (q ^ n)` is contained in `F`. - `IsPurelyInseparable.trans`: if `E / F` and `K / E` are both purely inseparable extensions, then `K / F` is also purely inseparable. - `isPurelyInseparable_iff_natSepDegree_eq_one`: `E / F` is purely inseparable if and only if for every element `x` of `E`, its minimal polynomial has separable degree one. - `isPurelyInseparable_iff_minpoly_eq_X_pow_sub_C`: a field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, the minimal polynomial of `x` over `F` is of form `X ^ (q ^ n) - y` for some natural number `n` and some element `y` of `F`. - `isPurelyInseparable_iff_minpoly_eq_X_sub_C_pow`: a field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, the minimal polynomial of `x` over `F` is of form `(X - x) ^ (q ^ n)` for some natural number `n`. - `isPurelyInseparable_iff_finSepDegree_eq_one`: an algebraic extension is purely inseparable if and only if it has finite separable degree (`Field.finSepDegree`) one. **TODO:** remove the algebraic assumption. - `IsPurelyInseparable.normal`: a purely inseparable extension is normal. - `separableClosure.isPurelyInseparable`: if `E / F` is algebraic, then `E` is purely inseparable over the separable closure of `F` in `E`. - `separableClosure_le_iff`: if `E / F` is algebraic, then an intermediate field of `E / F` contains the separable closure of `F` in `E` if and only if `E` is purely inseparable over it. - `eq_separableClosure_iff`: if `E / F` is algebraic, then an intermediate field of `E / F` is equal to the separable closure of `F` in `E` if and only if it is separable over `F`, and `E` is purely inseparable over it. - `le_perfectClosure_iff`: an intermediate field of `E / F` is contained in the relative perfect closure of `F` in `E` if and only if it is purely inseparable over `F`. - `perfectClosure.perfectRing`, `perfectClosure.perfectField`: if `E` is a perfect field, then the (relative) perfect closure `perfectClosure F E` is perfect. - `IsPurelyInseparable.injective_comp_algebraMap`: if `E / F` is purely inseparable, then for any reduced ring `L`, the map `(E →+* L) → (F →+* L)` induced by `algebraMap F E` is injective. In particular, a purely inseparable field extension is an epimorphism in the category of fields. - `IntermediateField.isPurelyInseparable_adjoin_iff_pow_mem`: if `F` is of exponential characteristic `q`, then `F(S) / F` is a purely inseparable extension if and only if for any `x ∈ S`, `x ^ (q ^ n)` is contained in `F` for some `n : ℕ`. - `Field.finSepDegree_eq`: if `E / F` is algebraic, then the `Field.finSepDegree F E` is equal to `Field.sepDegree F E` as a natural number. This means that the cardinality of `Field.Emb F E` and the degree of `(separableClosure F E) / F` are both finite or infinite, and when they are finite, they coincide. - `Field.finSepDegree_mul_finInsepDegree`: the finite separable degree multiply by the finite inseparable degree is equal to the (finite) field extension degree. - `Field.lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic`: the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$. - `IntermediateField.sepDegree_adjoin_eq_of_isAlgebraic_of_isPurelyInseparable`, `IntermediateField.sepDegree_adjoin_eq_of_isAlgebraic_of_isPurelyInseparable'`: if `K / E / F` is a field extension tower, such that `E / F` is purely inseparable, then for any subset `S` of `K` such that `F(S) / F` is algebraic, the `E(S) / E` and `F(S) / F` have the same separable degree. In particular, if `S` is an intermediate field of `K / F` such that `S / F` is algebraic, the `E(S) / E` and `S / F` have the same separable degree. - `minpoly.map_eq_of_separable_of_isPurelyInseparable`: if `K / E / F` is a field extension tower, such that `E / F` is purely inseparable, then for any element `x` of `K` separable over `F`, it has the same minimal polynomials over `F` and over `E`. - `Polynomial.Separable.map_irreducible_of_isPurelyInseparable`: if `E / F` is purely inseparable, `f` is a separable irreducible polynomial over `F`, then it is also irreducible over `E`. ## Tags separable degree, degree, separable closure, purely inseparable ## TODO - `IsPurelyInseparable.of_injective_comp_algebraMap`: if `L` is an algebraically closed field containing `E`, such that the map `(E →+* L) → (F →+* L)` induced by `algebraMap F E` is injective, then `E / F` is purely inseparable. As a corollary, epimorphisms in the category of fields must be purely inseparable extensions. Need to use the fact that `Emb F E` is infinite (or just not a singleton) when `E / F` is (purely) transcendental. - Restate some intermediate result in terms of linearly disjointness. - Prove that the inseparable degrees satisfy the tower law: $[E:F]_i [K:E]_i = [K:F]_i$. Probably an argument using linearly disjointness is needed. -/ open FiniteDimensional Polynomial IntermediateField Field noncomputable section universe u v w variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E] variable (K : Type w) [Field K] [Algebra F K] section IsPurelyInseparable /-- Typeclass for purely inseparable field extensions: an algebraic extension `E / F` is purely inseparable if and only if the minimal polynomial of every element of `E ∖ F` is not separable. -/ class IsPurelyInseparable : Prop where isIntegral : Algebra.IsIntegral F E inseparable' (x : E) : (minpoly F x).Separable → x ∈ (algebraMap F E).range attribute [instance] IsPurelyInseparable.isIntegral variable {E} in theorem IsPurelyInseparable.isIntegral' [IsPurelyInseparable F E] (x : E) : IsIntegral F x := Algebra.IsIntegral.isIntegral _ theorem IsPurelyInseparable.isAlgebraic [IsPurelyInseparable F E] : Algebra.IsAlgebraic F E := inferInstance variable {E} theorem IsPurelyInseparable.inseparable [IsPurelyInseparable F E] : ∀ x : E, (minpoly F x).Separable → x ∈ (algebraMap F E).range := IsPurelyInseparable.inseparable' variable {F K} theorem isPurelyInseparable_iff : IsPurelyInseparable F E ↔ ∀ x : E, IsIntegral F x ∧ ((minpoly F x).Separable → x ∈ (algebraMap F E).range) := ⟨fun h x ↦ ⟨h.isIntegral' x, h.inseparable' x⟩, fun h ↦ ⟨⟨fun x ↦ (h x).1⟩, fun x ↦ (h x).2⟩⟩ /-- Transfer `IsPurelyInseparable` across an `AlgEquiv`. -/ theorem AlgEquiv.isPurelyInseparable (e : K ≃ₐ[F] E) [IsPurelyInseparable F K] : IsPurelyInseparable F E := by refine ⟨⟨fun _ ↦ by rw [← isIntegral_algEquiv e.symm]; exact IsPurelyInseparable.isIntegral' F _⟩, fun x h ↦ ?_⟩ rw [← minpoly.algEquiv_eq e.symm] at h simpa only [RingHom.mem_range, algebraMap_eq_apply] using IsPurelyInseparable.inseparable F _ h theorem AlgEquiv.isPurelyInseparable_iff (e : K ≃ₐ[F] E) : IsPurelyInseparable F K ↔ IsPurelyInseparable F E := ⟨fun _ ↦ e.isPurelyInseparable, fun _ ↦ e.symm.isPurelyInseparable⟩ /-- If `E / F` is an algebraic extension, `F` is separably closed, then `E / F` is purely inseparable. -/ theorem Algebra.IsAlgebraic.isPurelyInseparable_of_isSepClosed [Algebra.IsAlgebraic F E] [IsSepClosed F] : IsPurelyInseparable F E := ⟨inferInstance, fun x h ↦ minpoly.mem_range_of_degree_eq_one F x <| IsSepClosed.degree_eq_one_of_irreducible F (minpoly.irreducible (Algebra.IsIntegral.isIntegral _)) h⟩ variable (F E K) /-- If `E / F` is both purely inseparable and separable, then `algebraMap F E` is surjective. -/ theorem IsPurelyInseparable.surjective_algebraMap_of_isSeparable [IsPurelyInseparable F E] [IsSeparable F E] : Function.Surjective (algebraMap F E) := fun x ↦ IsPurelyInseparable.inseparable F x (IsSeparable.separable F x) /-- If `E / F` is both purely inseparable and separable, then `algebraMap F E` is bijective. -/ theorem IsPurelyInseparable.bijective_algebraMap_of_isSeparable [IsPurelyInseparable F E] [IsSeparable F E] : Function.Bijective (algebraMap F E) := ⟨(algebraMap F E).injective, surjective_algebraMap_of_isSeparable F E⟩ variable {F E} in /-- If an intermediate field of `E / F` is both purely inseparable and separable, then it is equal to `F`. -/ theorem IntermediateField.eq_bot_of_isPurelyInseparable_of_isSeparable (L : IntermediateField F E) [IsPurelyInseparable F L] [IsSeparable F L] : L = ⊥ := bot_unique fun x hx ↦ by obtain ⟨y, hy⟩ := IsPurelyInseparable.surjective_algebraMap_of_isSeparable F L ⟨x, hx⟩ exact ⟨y, congr_arg (algebraMap L E) hy⟩ /-- If `E / F` is purely inseparable, then the separable closure of `F` in `E` is equal to `F`. -/ theorem separableClosure.eq_bot_of_isPurelyInseparable [IsPurelyInseparable F E] : separableClosure F E = ⊥ := bot_unique fun x h ↦ IsPurelyInseparable.inseparable F x (mem_separableClosure_iff.1 h) variable {F E} in /-- If `E / F` is an algebraic extension, then the separable closure of `F` in `E` is equal to `F` if and only if `E / F` is purely inseparable. -/ theorem separableClosure.eq_bot_iff [Algebra.IsAlgebraic F E] : separableClosure F E = ⊥ ↔ IsPurelyInseparable F E := ⟨fun h ↦ isPurelyInseparable_iff.2 fun x ↦ ⟨Algebra.IsIntegral.isIntegral x, fun hs ↦ by simpa only [h] using mem_separableClosure_iff.2 hs⟩, fun _ ↦ eq_bot_of_isPurelyInseparable F E⟩ instance isPurelyInseparable_self : IsPurelyInseparable F F := ⟨inferInstance, fun x _ ↦ ⟨x, rfl⟩⟩ variable {E} /-- A field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, there exists a natural number `n` such that `x ^ (q ^ n)` is contained in `F`. -/ theorem isPurelyInseparable_iff_pow_mem (q : ℕ) [ExpChar F q] : IsPurelyInseparable F E ↔ ∀ x : E, ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by rw [isPurelyInseparable_iff] refine ⟨fun h x ↦ ?_, fun h x ↦ ?_⟩ · obtain ⟨g, h1, n, h2⟩ := (minpoly.irreducible (h x).1).hasSeparableContraction q exact ⟨n, (h _).2 <| h1.of_dvd <| minpoly.dvd F _ <| by simpa only [expand_aeval, minpoly.aeval] using congr_arg (aeval x) h2⟩ have hdeg := (minpoly.natSepDegree_eq_one_iff_pow_mem q).2 (h x) have halg : IsIntegral F x := by_contra fun h' ↦ by simp only [minpoly.eq_zero h', natSepDegree_zero, zero_ne_one] at hdeg refine ⟨halg, fun hsep ↦ ?_⟩ rw [hsep.natSepDegree_eq_natDegree, ← adjoin.finrank halg, IntermediateField.finrank_eq_one_iff] at hdeg simpa only [hdeg] using mem_adjoin_simple_self F x theorem IsPurelyInseparable.pow_mem (q : ℕ) [ExpChar F q] [IsPurelyInseparable F E] (x : E) : ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := (isPurelyInseparable_iff_pow_mem F q).1 ‹_› x end IsPurelyInseparable section perfectClosure /-- The relative perfect closure of `F` in `E`, consists of the elements `x` of `E` such that there exists a natural number `n` such that `x ^ (ringExpChar F) ^ n` is contained in `F`, where `ringExpChar F` is the exponential characteristic of `F`. It is also the maximal purely inseparable subextension of `E / F` (`le_perfectClosure_iff`). -/ def perfectClosure : IntermediateField F E where carrier := {x : E | ∃ n : ℕ, x ^ (ringExpChar F) ^ n ∈ (algebraMap F E).range} add_mem' := by rintro x y ⟨n, hx⟩ ⟨m, hy⟩ use n + m have := expChar_of_injective_algebraMap (algebraMap F E).injective (ringExpChar F) rw [add_pow_expChar_pow, pow_add, pow_mul, mul_comm (_ ^ n), pow_mul] exact add_mem (pow_mem hx _) (pow_mem hy _) mul_mem' := by rintro x y ⟨n, hx⟩ ⟨m, hy⟩ use n + m rw [mul_pow, pow_add, pow_mul, mul_comm (_ ^ n), pow_mul] exact mul_mem (pow_mem hx _) (pow_mem hy _) inv_mem' := by rintro x ⟨n, hx⟩ use n; rw [inv_pow] apply inv_mem (id hx : _ ∈ (⊥ : IntermediateField F E)) algebraMap_mem' := fun x ↦ ⟨0, by rw [pow_zero, pow_one]; exact ⟨x, rfl⟩⟩ variable {F E} theorem mem_perfectClosure_iff {x : E} : x ∈ perfectClosure F E ↔ ∃ n : ℕ, x ^ (ringExpChar F) ^ n ∈ (algebraMap F E).range := Iff.rfl theorem mem_perfectClosure_iff_pow_mem (q : ℕ) [ExpChar F q] {x : E} : x ∈ perfectClosure F E ↔ ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by rw [mem_perfectClosure_iff, ringExpChar.eq F q] /-- An element is contained in the relative perfect closure if and only if its mininal polynomial has separable degree one. -/
Mathlib/FieldTheory/PurelyInseparable.lean
287
289
theorem mem_perfectClosure_iff_natSepDegree_eq_one {x : E} : x ∈ perfectClosure F E ↔ (minpoly F x).natSepDegree = 1 := by
rw [mem_perfectClosure_iff, minpoly.natSepDegree_eq_one_iff_pow_mem (ringExpChar F)]
/- 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 Mathlib.Topology.Constructions import Mathlib.Topology.ContinuousOn #align_import topology.bases from "leanprover-community/mathlib"@"bcfa726826abd57587355b4b5b7e78ad6527b7e4" /-! # Bases of topologies. Countability axioms. A topological basis on a topological space `t` is a collection of sets, such that all open sets can be generated as unions of these sets, without the need to take finite intersections of them. This file introduces a framework for dealing with these collections, and also what more we can say under certain countability conditions on bases, which are referred to as first- and second-countable. We also briefly cover the theory of separable spaces, which are those with a countable, dense subset. If a space is second-countable, and also has a countably generated uniformity filter (for example, if `t` is a metric space), it will automatically be separable (and indeed, these conditions are equivalent in this case). ## Main definitions * `TopologicalSpace.IsTopologicalBasis s`: The topological space `t` has basis `s`. * `TopologicalSpace.SeparableSpace α`: The topological space `t` has a countable, dense subset. * `TopologicalSpace.IsSeparable s`: The set `s` is contained in the closure of a countable set. * `FirstCountableTopology α`: A topology in which `𝓝 x` is countably generated for every `x`. * `SecondCountableTopology α`: A topology which has a topological basis which is countable. ## Main results * `TopologicalSpace.FirstCountableTopology.tendsto_subseq`: In a first-countable space, cluster points are limits of subsequences. * `TopologicalSpace.SecondCountableTopology.isOpen_iUnion_countable`: In a second-countable space, the union of arbitrarily-many open sets is equal to a sub-union of only countably many of these sets. * `TopologicalSpace.SecondCountableTopology.countable_cover_nhds`: Consider `f : α → Set α` with the property that `f x ∈ 𝓝 x` for all `x`. Then there is some countable set `s` whose image covers the space. ## Implementation Notes For our applications we are interested that there exists a countable basis, but we do not need the concrete basis itself. This allows us to declare these type classes as `Prop` to use them as mixins. ### TODO: More fine grained instances for `FirstCountableTopology`, `TopologicalSpace.SeparableSpace`, and more. -/ open Set Filter Function Topology noncomputable section namespace TopologicalSpace universe u variable {α : Type u} {β : Type*} [t : TopologicalSpace α] {B : Set (Set α)} {s : Set α} /-- A topological basis is one that satisfies the necessary conditions so that it suffices to take unions of the basis sets to get a topology (without taking finite intersections as well). -/ structure IsTopologicalBasis (s : Set (Set α)) : Prop where /-- For every point `x`, the set of `t ∈ s` such that `x ∈ t` is directed downwards. -/ exists_subset_inter : ∀ t₁ ∈ s, ∀ t₂ ∈ s, ∀ x ∈ t₁ ∩ t₂, ∃ t₃ ∈ s, x ∈ t₃ ∧ t₃ ⊆ t₁ ∩ t₂ /-- The sets from `s` cover the whole space. -/ sUnion_eq : ⋃₀ s = univ /-- The topology is generated by sets from `s`. -/ eq_generateFrom : t = generateFrom s #align topological_space.is_topological_basis TopologicalSpace.IsTopologicalBasis theorem IsTopologicalBasis.insert_empty {s : Set (Set α)} (h : IsTopologicalBasis s) : IsTopologicalBasis (insert ∅ s) := by refine ⟨?_, by rw [sUnion_insert, empty_union, h.sUnion_eq], ?_⟩ · rintro t₁ (rfl | h₁) t₂ (rfl | h₂) x ⟨hx₁, hx₂⟩ · cases hx₁ · cases hx₁ · cases hx₂ · obtain ⟨t₃, h₃, hs⟩ := h.exists_subset_inter _ h₁ _ h₂ x ⟨hx₁, hx₂⟩ exact ⟨t₃, .inr h₃, hs⟩ · rw [h.eq_generateFrom] refine le_antisymm (le_generateFrom fun t => ?_) (generateFrom_anti <| subset_insert ∅ s) rintro (rfl | ht) · exact @isOpen_empty _ (generateFrom s) · exact .basic t ht #align topological_space.is_topological_basis.insert_empty TopologicalSpace.IsTopologicalBasis.insert_empty theorem IsTopologicalBasis.diff_empty {s : Set (Set α)} (h : IsTopologicalBasis s) : IsTopologicalBasis (s \ {∅}) := by refine ⟨?_, by rw [sUnion_diff_singleton_empty, h.sUnion_eq], ?_⟩ · rintro t₁ ⟨h₁, -⟩ t₂ ⟨h₂, -⟩ x hx obtain ⟨t₃, h₃, hs⟩ := h.exists_subset_inter _ h₁ _ h₂ x hx exact ⟨t₃, ⟨h₃, Nonempty.ne_empty ⟨x, hs.1⟩⟩, hs⟩ · rw [h.eq_generateFrom] refine le_antisymm (generateFrom_anti diff_subset) (le_generateFrom fun t ht => ?_) obtain rfl | he := eq_or_ne t ∅ · exact @isOpen_empty _ (generateFrom _) · exact .basic t ⟨ht, he⟩ #align topological_space.is_topological_basis.diff_empty TopologicalSpace.IsTopologicalBasis.diff_empty /-- If a family of sets `s` generates the topology, then intersections of finite subcollections of `s` form a topological basis. -/ theorem isTopologicalBasis_of_subbasis {s : Set (Set α)} (hs : t = generateFrom s) : IsTopologicalBasis ((fun f => ⋂₀ f) '' { f : Set (Set α) | f.Finite ∧ f ⊆ s }) := by subst t; letI := generateFrom s refine ⟨?_, ?_, le_antisymm (le_generateFrom ?_) <| generateFrom_anti fun t ht => ?_⟩ · rintro _ ⟨t₁, ⟨hft₁, ht₁b⟩, rfl⟩ _ ⟨t₂, ⟨hft₂, ht₂b⟩, rfl⟩ x h exact ⟨_, ⟨_, ⟨hft₁.union hft₂, union_subset ht₁b ht₂b⟩, sInter_union t₁ t₂⟩, h, Subset.rfl⟩ · rw [sUnion_image, iUnion₂_eq_univ_iff] exact fun x => ⟨∅, ⟨finite_empty, empty_subset _⟩, sInter_empty.substr <| mem_univ x⟩ · rintro _ ⟨t, ⟨hft, htb⟩, rfl⟩ exact hft.isOpen_sInter fun s hs ↦ GenerateOpen.basic _ <| htb hs · rw [← sInter_singleton t] exact ⟨{t}, ⟨finite_singleton t, singleton_subset_iff.2 ht⟩, rfl⟩ #align topological_space.is_topological_basis_of_subbasis TopologicalSpace.isTopologicalBasis_of_subbasis theorem IsTopologicalBasis.of_hasBasis_nhds {s : Set (Set α)} (h_nhds : ∀ a, (𝓝 a).HasBasis (fun t ↦ t ∈ s ∧ a ∈ t) id) : IsTopologicalBasis s where exists_subset_inter t₁ ht₁ t₂ ht₂ x hx := by simpa only [and_assoc, (h_nhds x).mem_iff] using (inter_mem ((h_nhds _).mem_of_mem ⟨ht₁, hx.1⟩) ((h_nhds _).mem_of_mem ⟨ht₂, hx.2⟩)) sUnion_eq := sUnion_eq_univ_iff.2 fun x ↦ (h_nhds x).ex_mem eq_generateFrom := ext_nhds fun x ↦ by simpa only [nhds_generateFrom, and_comm] using (h_nhds x).eq_biInf /-- If a family of open sets `s` is such that every open neighbourhood contains some member of `s`, then `s` is a topological basis. -/ theorem isTopologicalBasis_of_isOpen_of_nhds {s : Set (Set α)} (h_open : ∀ u ∈ s, IsOpen u) (h_nhds : ∀ (a : α) (u : Set α), a ∈ u → IsOpen u → ∃ v ∈ s, a ∈ v ∧ v ⊆ u) : IsTopologicalBasis s := .of_hasBasis_nhds <| fun a ↦ (nhds_basis_opens a).to_hasBasis' (by simpa [and_assoc] using h_nhds a) fun t ⟨hts, hat⟩ ↦ (h_open _ hts).mem_nhds hat #align topological_space.is_topological_basis_of_open_of_nhds TopologicalSpace.isTopologicalBasis_of_isOpen_of_nhds /-- A set `s` is in the neighbourhood of `a` iff there is some basis set `t`, which contains `a` and is itself contained in `s`. -/ theorem IsTopologicalBasis.mem_nhds_iff {a : α} {s : Set α} {b : Set (Set α)} (hb : IsTopologicalBasis b) : s ∈ 𝓝 a ↔ ∃ t ∈ b, a ∈ t ∧ t ⊆ s := by change s ∈ (𝓝 a).sets ↔ ∃ t ∈ b, a ∈ t ∧ t ⊆ s rw [hb.eq_generateFrom, nhds_generateFrom, biInf_sets_eq] · simp [and_assoc, and_left_comm] · rintro s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩ let ⟨u, hu₁, hu₂, hu₃⟩ := hb.1 _ hs₂ _ ht₂ _ ⟨hs₁, ht₁⟩ exact ⟨u, ⟨hu₂, hu₁⟩, le_principal_iff.2 (hu₃.trans inter_subset_left), le_principal_iff.2 (hu₃.trans inter_subset_right)⟩ · rcases eq_univ_iff_forall.1 hb.sUnion_eq a with ⟨i, h1, h2⟩ exact ⟨i, h2, h1⟩ #align topological_space.is_topological_basis.mem_nhds_iff TopologicalSpace.IsTopologicalBasis.mem_nhds_iff theorem IsTopologicalBasis.isOpen_iff {s : Set α} {b : Set (Set α)} (hb : IsTopologicalBasis b) : IsOpen s ↔ ∀ a ∈ s, ∃ t ∈ b, a ∈ t ∧ t ⊆ s := by simp [isOpen_iff_mem_nhds, hb.mem_nhds_iff] #align topological_space.is_topological_basis.is_open_iff TopologicalSpace.IsTopologicalBasis.isOpen_iff theorem IsTopologicalBasis.nhds_hasBasis {b : Set (Set α)} (hb : IsTopologicalBasis b) {a : α} : (𝓝 a).HasBasis (fun t : Set α => t ∈ b ∧ a ∈ t) fun t => t := ⟨fun s => hb.mem_nhds_iff.trans <| by simp only [and_assoc]⟩ #align topological_space.is_topological_basis.nhds_has_basis TopologicalSpace.IsTopologicalBasis.nhds_hasBasis protected theorem IsTopologicalBasis.isOpen {s : Set α} {b : Set (Set α)} (hb : IsTopologicalBasis b) (hs : s ∈ b) : IsOpen s := by rw [hb.eq_generateFrom] exact .basic s hs #align topological_space.is_topological_basis.is_open TopologicalSpace.IsTopologicalBasis.isOpen protected theorem IsTopologicalBasis.mem_nhds {a : α} {s : Set α} {b : Set (Set α)} (hb : IsTopologicalBasis b) (hs : s ∈ b) (ha : a ∈ s) : s ∈ 𝓝 a := (hb.isOpen hs).mem_nhds ha #align topological_space.is_topological_basis.mem_nhds TopologicalSpace.IsTopologicalBasis.mem_nhds theorem IsTopologicalBasis.exists_subset_of_mem_open {b : Set (Set α)} (hb : IsTopologicalBasis b) {a : α} {u : Set α} (au : a ∈ u) (ou : IsOpen u) : ∃ v ∈ b, a ∈ v ∧ v ⊆ u := hb.mem_nhds_iff.1 <| IsOpen.mem_nhds ou au #align topological_space.is_topological_basis.exists_subset_of_mem_open TopologicalSpace.IsTopologicalBasis.exists_subset_of_mem_open /-- Any open set is the union of the basis sets contained in it. -/ theorem IsTopologicalBasis.open_eq_sUnion' {B : Set (Set α)} (hB : IsTopologicalBasis B) {u : Set α} (ou : IsOpen u) : u = ⋃₀ { s ∈ B | s ⊆ u } := ext fun _a => ⟨fun ha => let ⟨b, hb, ab, bu⟩ := hB.exists_subset_of_mem_open ha ou ⟨b, ⟨hb, bu⟩, ab⟩, fun ⟨_b, ⟨_, bu⟩, ab⟩ => bu ab⟩ #align topological_space.is_topological_basis.open_eq_sUnion' TopologicalSpace.IsTopologicalBasis.open_eq_sUnion' theorem IsTopologicalBasis.open_eq_sUnion {B : Set (Set α)} (hB : IsTopologicalBasis B) {u : Set α} (ou : IsOpen u) : ∃ S ⊆ B, u = ⋃₀ S := ⟨{ s ∈ B | s ⊆ u }, fun _ h => h.1, hB.open_eq_sUnion' ou⟩ #align topological_space.is_topological_basis.open_eq_sUnion TopologicalSpace.IsTopologicalBasis.open_eq_sUnion theorem IsTopologicalBasis.open_iff_eq_sUnion {B : Set (Set α)} (hB : IsTopologicalBasis B) {u : Set α} : IsOpen u ↔ ∃ S ⊆ B, u = ⋃₀ S := ⟨hB.open_eq_sUnion, fun ⟨_S, hSB, hu⟩ => hu.symm ▸ isOpen_sUnion fun _s hs => hB.isOpen (hSB hs)⟩ #align topological_space.is_topological_basis.open_iff_eq_sUnion TopologicalSpace.IsTopologicalBasis.open_iff_eq_sUnion theorem IsTopologicalBasis.open_eq_iUnion {B : Set (Set α)} (hB : IsTopologicalBasis B) {u : Set α} (ou : IsOpen u) : ∃ (β : Type u) (f : β → Set α), (u = ⋃ i, f i) ∧ ∀ i, f i ∈ B := ⟨↥({ s ∈ B | s ⊆ u }), (↑), by rw [← sUnion_eq_iUnion] apply hB.open_eq_sUnion' ou, fun s => And.left s.2⟩ #align topological_space.is_topological_basis.open_eq_Union TopologicalSpace.IsTopologicalBasis.open_eq_iUnion lemma IsTopologicalBasis.subset_of_forall_subset {t : Set α} (hB : IsTopologicalBasis B) (hs : IsOpen s) (h : ∀ U ∈ B, U ⊆ s → U ⊆ t) : s ⊆ t := by rw [hB.open_eq_sUnion' hs]; simpa [sUnion_subset_iff] lemma IsTopologicalBasis.eq_of_forall_subset_iff {t : Set α} (hB : IsTopologicalBasis B) (hs : IsOpen s) (ht : IsOpen t) (h : ∀ U ∈ B, U ⊆ s ↔ U ⊆ t) : s = t := by rw [hB.open_eq_sUnion' hs, hB.open_eq_sUnion' ht] exact congr_arg _ (Set.ext fun U ↦ and_congr_right <| h _) /-- A point `a` is in the closure of `s` iff all basis sets containing `a` intersect `s`. -/ theorem IsTopologicalBasis.mem_closure_iff {b : Set (Set α)} (hb : IsTopologicalBasis b) {s : Set α} {a : α} : a ∈ closure s ↔ ∀ o ∈ b, a ∈ o → (o ∩ s).Nonempty := (mem_closure_iff_nhds_basis' hb.nhds_hasBasis).trans <| by simp only [and_imp] #align topological_space.is_topological_basis.mem_closure_iff TopologicalSpace.IsTopologicalBasis.mem_closure_iff /-- A set is dense iff it has non-trivial intersection with all basis sets. -/ theorem IsTopologicalBasis.dense_iff {b : Set (Set α)} (hb : IsTopologicalBasis b) {s : Set α} : Dense s ↔ ∀ o ∈ b, Set.Nonempty o → (o ∩ s).Nonempty := by simp only [Dense, hb.mem_closure_iff] exact ⟨fun h o hb ⟨a, ha⟩ => h a o hb ha, fun h a o hb ha => h o hb ⟨a, ha⟩⟩ #align topological_space.is_topological_basis.dense_iff TopologicalSpace.IsTopologicalBasis.dense_iff theorem IsTopologicalBasis.isOpenMap_iff {β} [TopologicalSpace β] {B : Set (Set α)} (hB : IsTopologicalBasis B) {f : α → β} : IsOpenMap f ↔ ∀ s ∈ B, IsOpen (f '' s) := by refine ⟨fun H o ho => H _ (hB.isOpen ho), fun hf o ho => ?_⟩ rw [hB.open_eq_sUnion' ho, sUnion_eq_iUnion, image_iUnion] exact isOpen_iUnion fun s => hf s s.2.1 #align topological_space.is_topological_basis.is_open_map_iff TopologicalSpace.IsTopologicalBasis.isOpenMap_iff theorem IsTopologicalBasis.exists_nonempty_subset {B : Set (Set α)} (hb : IsTopologicalBasis B) {u : Set α} (hu : u.Nonempty) (ou : IsOpen u) : ∃ v ∈ B, Set.Nonempty v ∧ v ⊆ u := let ⟨x, hx⟩ := hu let ⟨v, vB, xv, vu⟩ := hb.exists_subset_of_mem_open hx ou ⟨v, vB, ⟨x, xv⟩, vu⟩ #align topological_space.is_topological_basis.exists_nonempty_subset TopologicalSpace.IsTopologicalBasis.exists_nonempty_subset theorem isTopologicalBasis_opens : IsTopologicalBasis { U : Set α | IsOpen U } := isTopologicalBasis_of_isOpen_of_nhds (by tauto) (by tauto) #align topological_space.is_topological_basis_opens TopologicalSpace.isTopologicalBasis_opens protected theorem IsTopologicalBasis.inducing {β} [TopologicalSpace β] {f : α → β} {T : Set (Set β)} (hf : Inducing f) (h : IsTopologicalBasis T) : IsTopologicalBasis ((preimage f) '' T) := .of_hasBasis_nhds fun a ↦ by convert (hf.basis_nhds (h.nhds_hasBasis (a := f a))).to_image_id with s aesop #align topological_space.is_topological_basis.inducing TopologicalSpace.IsTopologicalBasis.inducing protected theorem IsTopologicalBasis.induced [s : TopologicalSpace β] (f : α → β) {T : Set (Set β)} (h : IsTopologicalBasis T) : IsTopologicalBasis (t := induced f s) ((preimage f) '' T) := h.inducing (t := induced f s) (inducing_induced f) protected theorem IsTopologicalBasis.inf {t₁ t₂ : TopologicalSpace β} {B₁ B₂ : Set (Set β)} (h₁ : IsTopologicalBasis (t := t₁) B₁) (h₂ : IsTopologicalBasis (t := t₂) B₂) : IsTopologicalBasis (t := t₁ ⊓ t₂) (image2 (· ∩ ·) B₁ B₂) := by refine .of_hasBasis_nhds (t := ?_) fun a ↦ ?_ rw [nhds_inf (t₁ := t₁)] convert ((h₁.nhds_hasBasis (t := t₁)).inf (h₂.nhds_hasBasis (t := t₂))).to_image_id aesop theorem IsTopologicalBasis.inf_induced {γ} [s : TopologicalSpace β] {B₁ : Set (Set α)} {B₂ : Set (Set β)} (h₁ : IsTopologicalBasis B₁) (h₂ : IsTopologicalBasis B₂) (f₁ : γ → α) (f₂ : γ → β) : IsTopologicalBasis (t := induced f₁ t ⊓ induced f₂ s) (image2 (f₁ ⁻¹' · ∩ f₂ ⁻¹' ·) B₁ B₂) := by simpa only [image2_image_left, image2_image_right] using (h₁.induced f₁).inf (h₂.induced f₂) protected theorem IsTopologicalBasis.prod {β} [TopologicalSpace β] {B₁ : Set (Set α)} {B₂ : Set (Set β)} (h₁ : IsTopologicalBasis B₁) (h₂ : IsTopologicalBasis B₂) : IsTopologicalBasis (image2 (· ×ˢ ·) B₁ B₂) := h₁.inf_induced h₂ Prod.fst Prod.snd #align topological_space.is_topological_basis.prod TopologicalSpace.IsTopologicalBasis.prod theorem isTopologicalBasis_of_cover {ι} {U : ι → Set α} (Uo : ∀ i, IsOpen (U i)) (Uc : ⋃ i, U i = univ) {b : ∀ i, Set (Set (U i))} (hb : ∀ i, IsTopologicalBasis (b i)) : IsTopologicalBasis (⋃ i : ι, image ((↑) : U i → α) '' b i) := by refine isTopologicalBasis_of_isOpen_of_nhds (fun u hu => ?_) ?_ · simp only [mem_iUnion, mem_image] at hu rcases hu with ⟨i, s, sb, rfl⟩ exact (Uo i).isOpenMap_subtype_val _ ((hb i).isOpen sb) · intro a u ha uo rcases iUnion_eq_univ_iff.1 Uc a with ⟨i, hi⟩ lift a to ↥(U i) using hi rcases (hb i).exists_subset_of_mem_open ha (uo.preimage continuous_subtype_val) with ⟨v, hvb, hav, hvu⟩ exact ⟨(↑) '' v, mem_iUnion.2 ⟨i, mem_image_of_mem _ hvb⟩, mem_image_of_mem _ hav, image_subset_iff.2 hvu⟩ #align topological_space.is_topological_basis_of_cover TopologicalSpace.isTopologicalBasis_of_cover protected theorem IsTopologicalBasis.continuous_iff {β : Type*} [TopologicalSpace β] {B : Set (Set β)} (hB : IsTopologicalBasis B) {f : α → β} : Continuous f ↔ ∀ s ∈ B, IsOpen (f ⁻¹' s) := by rw [hB.eq_generateFrom, continuous_generateFrom_iff] @[deprecated] protected theorem IsTopologicalBasis.continuous {β : Type*} [TopologicalSpace β] {B : Set (Set β)} (hB : IsTopologicalBasis B) (f : α → β) (hf : ∀ s ∈ B, IsOpen (f ⁻¹' s)) : Continuous f := hB.continuous_iff.2 hf #align topological_space.is_topological_basis.continuous TopologicalSpace.IsTopologicalBasis.continuous variable (α) /-- A separable space is one with a countable dense subset, available through `TopologicalSpace.exists_countable_dense`. If `α` is also known to be nonempty, then `TopologicalSpace.denseSeq` provides a sequence `ℕ → α` with dense range, see `TopologicalSpace.denseRange_denseSeq`. If `α` is a uniform space with countably generated uniformity filter (e.g., an `EMetricSpace`), then this condition is equivalent to `SecondCountableTopology α`. In this case the latter should be used as a typeclass argument in theorems because Lean can automatically deduce `TopologicalSpace.SeparableSpace` from `SecondCountableTopology` but it can't deduce `SecondCountableTopology` from `TopologicalSpace.SeparableSpace`. Porting note (#11215): TODO: the previous paragraph describes the state of the art in Lean 3. We can have instance cycles in Lean 4 but we might want to postpone adding them till after the port. -/ @[mk_iff] class SeparableSpace : Prop where /-- There exists a countable dense set. -/ exists_countable_dense : ∃ s : Set α, s.Countable ∧ Dense s #align topological_space.separable_space TopologicalSpace.SeparableSpace theorem exists_countable_dense [SeparableSpace α] : ∃ s : Set α, s.Countable ∧ Dense s := SeparableSpace.exists_countable_dense #align topological_space.exists_countable_dense TopologicalSpace.exists_countable_dense /-- A nonempty separable space admits a sequence with dense range. Instead of running `cases` on the conclusion of this lemma, you might want to use `TopologicalSpace.denseSeq` and `TopologicalSpace.denseRange_denseSeq`. If `α` might be empty, then `TopologicalSpace.exists_countable_dense` is the main way to use separability of `α`. -/
Mathlib/Topology/Bases.lean
338
341
theorem exists_dense_seq [SeparableSpace α] [Nonempty α] : ∃ u : ℕ → α, DenseRange u := by
obtain ⟨s : Set α, hs, s_dense⟩ := exists_countable_dense α cases' Set.countable_iff_exists_subset_range.mp hs with u hu exact ⟨u, s_dense.mono hu⟩
/- 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, Johan Commelin -/ import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.RingTheory.Localization.FractionRing #align_import data.polynomial.ring_division from "leanprover-community/mathlib"@"8efcf8022aac8e01df8d302dcebdbc25d6a886c8" /-! # Theory of univariate polynomials We define the multiset of roots of a polynomial, and prove basic results about it. ## Main definitions * `Polynomial.roots p`: The multiset containing all the roots of `p`, including their multiplicities. * `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`. ## Main statements * `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a` ranges through its roots. -/ noncomputable section namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ} section CommRing variable [CommRing R] [IsDomain R] {p q : R[X]} section Roots open Multiset Finset /-- `roots p` noncomputably gives a multiset containing all the roots of `p`, including their multiplicities. -/ noncomputable def roots (p : R[X]) : Multiset R := haveI := Classical.decEq R haveI := Classical.dec (p = 0) if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) #align polynomial.roots Polynomial.roots theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] : p.roots = if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) := by -- porting noteL `‹_›` doesn't work for instance arguments rename_i iR ip0 obtain rfl := Subsingleton.elim iR (Classical.decEq R) obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0)) rfl #align polynomial.roots_def Polynomial.roots_def @[simp] theorem roots_zero : (0 : R[X]).roots = 0 := dif_pos rfl #align polynomial.roots_zero Polynomial.roots_zero theorem card_roots (hp0 : p ≠ 0) : (Multiset.card (roots p) : WithBot ℕ) ≤ degree p := by classical unfold roots rw [dif_neg hp0] exact (Classical.choose_spec (exists_multiset_roots hp0)).1 #align polynomial.card_roots Polynomial.card_roots theorem card_roots' (p : R[X]) : Multiset.card p.roots ≤ natDegree p := by by_cases hp0 : p = 0 · simp [hp0] exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0)) #align polynomial.card_roots' Polynomial.card_roots' theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) : (Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree p := calc (Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree (p - C a) := card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm ▸ degree_C_le _ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0 set_option linter.uppercaseLean3 false in #align polynomial.card_roots_sub_C Polynomial.card_roots_sub_C theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) : Multiset.card (p - C a).roots ≤ natDegree p := WithBot.coe_le_coe.1 (le_trans (card_roots_sub_C hp0) (le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl])) set_option linter.uppercaseLean3 false in #align polynomial.card_roots_sub_C' Polynomial.card_roots_sub_C' @[simp] theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by classical by_cases hp : p = 0 · simp [hp] rw [roots_def, dif_neg hp] exact (Classical.choose_spec (exists_multiset_roots hp)).2 a #align polynomial.count_roots Polynomial.count_roots @[simp] theorem mem_roots' : a ∈ p.roots ↔ p ≠ 0 ∧ IsRoot p a := by classical rw [← count_pos, count_roots p, rootMultiplicity_pos'] #align polynomial.mem_roots' Polynomial.mem_roots' theorem mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ IsRoot p a := mem_roots'.trans <| and_iff_right hp #align polynomial.mem_roots Polynomial.mem_roots theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p ≠ 0 := (mem_roots'.1 h).1 #align polynomial.ne_zero_of_mem_roots Polynomial.ne_zero_of_mem_roots theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a := (mem_roots'.1 h).2 #align polynomial.is_root_of_mem_roots Polynomial.isRoot_of_mem_roots -- Porting note: added during port. lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p ≠ 0) : x ∈ roots p ↔ aeval x p = 0 := by rw [mem_roots w, IsRoot.def, aeval_def, eval₂_eq_eval_map] simp theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val ⊆ p.roots) : Z.card ≤ p.natDegree := (Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p) #align polynomial.card_le_degree_of_subset_roots Polynomial.card_le_degree_of_subset_roots theorem finite_setOf_isRoot {p : R[X]} (hp : p ≠ 0) : Set.Finite { x | IsRoot p x } := by classical simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp] using p.roots.toFinset.finite_toSet #align polynomial.finite_set_of_is_root Polynomial.finite_setOf_isRoot theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 := not_imp_comm.mp finite_setOf_isRoot h #align polynomial.eq_zero_of_infinite_is_root Polynomial.eq_zero_of_infinite_isRoot theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x ≤ x₀ := Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp #align polynomial.exists_max_root Polynomial.exists_max_root theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x₀ ≤ x := Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp #align polynomial.exists_min_root Polynomial.exists_min_root theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) : p = q := by rw [← sub_eq_zero] apply eq_zero_of_infinite_isRoot simpa only [IsRoot, eval_sub, sub_eq_zero] #align polynomial.eq_of_infinite_eval_eq Polynomial.eq_of_infinite_eval_eq theorem roots_mul {p q : R[X]} (hpq : p * q ≠ 0) : (p * q).roots = p.roots + q.roots := by classical exact Multiset.ext.mpr fun r => by rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq] #align polynomial.roots_mul Polynomial.roots_mul theorem roots.le_of_dvd (h : q ≠ 0) : p ∣ q → roots p ≤ roots q := by rintro ⟨k, rfl⟩ exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩ #align polynomial.roots.le_of_dvd Polynomial.roots.le_of_dvd theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p ≠ C a ∧ p.eval x = a := by rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C] set_option linter.uppercaseLean3 false in #align polynomial.mem_roots_sub_C' Polynomial.mem_roots_sub_C' theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) : x ∈ (p - C a).roots ↔ p.eval x = a := mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm ▸ degree_C_le set_option linter.uppercaseLean3 false in #align polynomial.mem_roots_sub_C Polynomial.mem_roots_sub_C @[simp] theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by classical ext s rw [count_roots, rootMultiplicity_X_sub_C, count_singleton] set_option linter.uppercaseLean3 false in #align polynomial.roots_X_sub_C Polynomial.roots_X_sub_C @[simp] theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero] set_option linter.uppercaseLean3 false in #align polynomial.roots_X Polynomial.roots_X @[simp] theorem roots_C (x : R) : (C x).roots = 0 := by classical exact if H : x = 0 then by rw [H, C_0, roots_zero] else Multiset.ext.mpr fun r => (by rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)]) set_option linter.uppercaseLean3 false in #align polynomial.roots_C Polynomial.roots_C @[simp] theorem roots_one : (1 : R[X]).roots = ∅ := roots_C 1 #align polynomial.roots_one Polynomial.roots_one @[simp] theorem roots_C_mul (p : R[X]) (ha : a ≠ 0) : (C a * p).roots = p.roots := by by_cases hp : p = 0 <;> simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C, zero_add, mul_zero] set_option linter.uppercaseLean3 false in #align polynomial.roots_C_mul Polynomial.roots_C_mul @[simp] theorem roots_smul_nonzero (p : R[X]) (ha : a ≠ 0) : (a • p).roots = p.roots := by rw [smul_eq_C_mul, roots_C_mul _ ha] #align polynomial.roots_smul_nonzero Polynomial.roots_smul_nonzero @[simp] lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)] theorem roots_list_prod (L : List R[X]) : (0 : R[X]) ∉ L → L.prod.roots = (L : Multiset R[X]).bind roots := List.recOn L (fun _ => roots_one) fun hd tl ih H => by rw [List.mem_cons, not_or] at H rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ← Multiset.cons_coe, Multiset.cons_bind, ih H.2] #align polynomial.roots_list_prod Polynomial.roots_list_prod theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) ∉ m → m.prod.roots = m.bind roots := by rcases m with ⟨L⟩ simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L #align polynomial.roots_multiset_prod Polynomial.roots_multiset_prod theorem roots_prod {ι : Type*} (f : ι → R[X]) (s : Finset ι) : s.prod f ≠ 0 → (s.prod f).roots = s.val.bind fun i => roots (f i) := by rcases s with ⟨m, hm⟩ simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f) #align polynomial.roots_prod Polynomial.roots_prod @[simp] theorem roots_pow (p : R[X]) (n : ℕ) : (p ^ n).roots = n • p.roots := by induction' n with n ihn · rw [pow_zero, roots_one, zero_smul, empty_eq_zero] · rcases eq_or_ne p 0 with (rfl | hp) · rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero] · rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul] #align polynomial.roots_pow Polynomial.roots_pow theorem roots_X_pow (n : ℕ) : (X ^ n : R[X]).roots = n • ({0} : Multiset R) := by rw [roots_pow, roots_X] set_option linter.uppercaseLean3 false in #align polynomial.roots_X_pow Polynomial.roots_X_pow theorem roots_C_mul_X_pow (ha : a ≠ 0) (n : ℕ) : Polynomial.roots (C a * X ^ n) = n • ({0} : Multiset R) := by rw [roots_C_mul _ ha, roots_X_pow] set_option linter.uppercaseLean3 false in #align polynomial.roots_C_mul_X_pow Polynomial.roots_C_mul_X_pow @[simp] theorem roots_monomial (ha : a ≠ 0) (n : ℕ) : (monomial n a).roots = n • ({0} : Multiset R) := by rw [← C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha] #align polynomial.roots_monomial Polynomial.roots_monomial theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by apply (roots_prod (fun a => X - C a) s ?_).trans · simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] · refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a) set_option linter.uppercaseLean3 false in #align polynomial.roots_prod_X_sub_C Polynomial.roots_prod_X_sub_C @[simp] theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by rw [roots_multiset_prod, Multiset.bind_map] · simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] · rw [Multiset.mem_map] rintro ⟨a, -, h⟩ exact X_sub_C_ne_zero a h set_option linter.uppercaseLean3 false in #align polynomial.roots_multiset_prod_X_sub_C Polynomial.roots_multiset_prod_X_sub_C theorem card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) : Multiset.card (roots ((X : R[X]) ^ n - C a)) ≤ n := WithBot.coe_le_coe.1 <| calc (Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot ℕ) ≤ degree ((X : R[X]) ^ n - C a) := card_roots (X_pow_sub_C_ne_zero hn a) _ = n := degree_X_pow_sub_C hn a set_option linter.uppercaseLean3 false in #align polynomial.card_roots_X_pow_sub_C Polynomial.card_roots_X_pow_sub_C section NthRoots /-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`-/ def nthRoots (n : ℕ) (a : R) : Multiset R := roots ((X : R[X]) ^ n - C a) #align polynomial.nth_roots Polynomial.nthRoots @[simp] theorem mem_nthRoots {n : ℕ} (hn : 0 < n) {a x : R} : x ∈ nthRoots n a ↔ x ^ n = a := by rw [nthRoots, mem_roots (X_pow_sub_C_ne_zero hn a), IsRoot.def, eval_sub, eval_C, eval_pow, eval_X, sub_eq_zero] #align polynomial.mem_nth_roots Polynomial.mem_nthRoots @[simp] theorem nthRoots_zero (r : R) : nthRoots 0 r = 0 := by simp only [empty_eq_zero, pow_zero, nthRoots, ← C_1, ← C_sub, roots_C] #align polynomial.nth_roots_zero Polynomial.nthRoots_zero @[simp] theorem nthRoots_zero_right {R} [CommRing R] [IsDomain R] (n : ℕ) : nthRoots n (0 : R) = Multiset.replicate n 0 := by rw [nthRoots, C.map_zero, sub_zero, roots_pow, roots_X, Multiset.nsmul_singleton] theorem card_nthRoots (n : ℕ) (a : R) : Multiset.card (nthRoots n a) ≤ n := by classical exact (if hn : n = 0 then if h : (X : R[X]) ^ n - C a = 0 then by simp [Nat.zero_le, nthRoots, roots, h, dif_pos rfl, empty_eq_zero, Multiset.card_zero] else WithBot.coe_le_coe.1 (le_trans (card_roots h) (by rw [hn, pow_zero, ← C_1, ← RingHom.map_sub] exact degree_C_le)) else by rw [← Nat.cast_le (α := WithBot ℕ)] rw [← degree_X_pow_sub_C (Nat.pos_of_ne_zero hn) a] exact card_roots (X_pow_sub_C_ne_zero (Nat.pos_of_ne_zero hn) a)) #align polynomial.card_nth_roots Polynomial.card_nthRoots @[simp] theorem nthRoots_two_eq_zero_iff {r : R} : nthRoots 2 r = 0 ↔ ¬IsSquare r := by simp_rw [isSquare_iff_exists_sq, eq_zero_iff_forall_not_mem, mem_nthRoots (by norm_num : 0 < 2), ← not_exists, eq_comm] #align polynomial.nth_roots_two_eq_zero_iff Polynomial.nthRoots_two_eq_zero_iff /-- The multiset `nthRoots ↑n (1 : R)` as a Finset. -/ def nthRootsFinset (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : Finset R := haveI := Classical.decEq R Multiset.toFinset (nthRoots n (1 : R)) #align polynomial.nth_roots_finset Polynomial.nthRootsFinset -- Porting note (#10756): new lemma lemma nthRootsFinset_def (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] [DecidableEq R] : nthRootsFinset n R = Multiset.toFinset (nthRoots n (1 : R)) := by unfold nthRootsFinset convert rfl @[simp] theorem mem_nthRootsFinset {n : ℕ} (h : 0 < n) {x : R} : x ∈ nthRootsFinset n R ↔ x ^ (n : ℕ) = 1 := by classical rw [nthRootsFinset_def, mem_toFinset, mem_nthRoots h] #align polynomial.mem_nth_roots_finset Polynomial.mem_nthRootsFinset @[simp] theorem nthRootsFinset_zero : nthRootsFinset 0 R = ∅ := by classical simp [nthRootsFinset_def] #align polynomial.nth_roots_finset_zero Polynomial.nthRootsFinset_zero theorem mul_mem_nthRootsFinset {η₁ η₂ : R} (hη₁ : η₁ ∈ nthRootsFinset n R) (hη₂ : η₂ ∈ nthRootsFinset n R) : η₁ * η₂ ∈ nthRootsFinset n R := by cases n with | zero => simp only [Nat.zero_eq, nthRootsFinset_zero, not_mem_empty] at hη₁ | succ n => rw [mem_nthRootsFinset n.succ_pos] at hη₁ hη₂ ⊢ rw [mul_pow, hη₁, hη₂, one_mul] theorem ne_zero_of_mem_nthRootsFinset {η : R} (hη : η ∈ nthRootsFinset n R) : η ≠ 0 := by nontriviality R rintro rfl cases n with | zero => simp only [Nat.zero_eq, nthRootsFinset_zero, not_mem_empty] at hη | succ n => rw [mem_nthRootsFinset n.succ_pos, zero_pow n.succ_ne_zero] at hη exact zero_ne_one hη theorem one_mem_nthRootsFinset (hn : 0 < n) : 1 ∈ nthRootsFinset n R := by rw [mem_nthRootsFinset hn, one_pow] end NthRoots theorem zero_of_eval_zero [Infinite R] (p : R[X]) (h : ∀ x, p.eval x = 0) : p = 0 := by classical by_contra hp refine @Fintype.false R _ ?_ exact ⟨p.roots.toFinset, fun x => Multiset.mem_toFinset.mpr ((mem_roots hp).mpr (h _))⟩ #align polynomial.zero_of_eval_zero Polynomial.zero_of_eval_zero theorem funext [Infinite R] {p q : R[X]} (ext : ∀ r : R, p.eval r = q.eval r) : p = q := by rw [← sub_eq_zero] apply zero_of_eval_zero intro x rw [eval_sub, sub_eq_zero, ext] #align polynomial.funext Polynomial.funext variable [CommRing T] /-- Given a polynomial `p` with coefficients in a ring `T` and a `T`-algebra `S`, `aroots p S` is the multiset of roots of `p` regarded as a polynomial over `S`. -/ noncomputable abbrev aroots (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Multiset S := (p.map (algebraMap T S)).roots theorem aroots_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : p.aroots S = (p.map (algebraMap T S)).roots := rfl theorem mem_aroots' [CommRing S] [IsDomain S] [Algebra T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p.map (algebraMap T S) ≠ 0 ∧ aeval a p = 0 := by rw [mem_roots', IsRoot.def, ← eval₂_eq_eval_map, aeval_def] theorem mem_aroots [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p ≠ 0 ∧ aeval a p = 0 := by rw [mem_aroots', Polynomial.map_ne_zero_iff] exact NoZeroSMulDivisors.algebraMap_injective T S theorem aroots_mul [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p q : T[X]} (hpq : p * q ≠ 0) : (p * q).aroots S = p.aroots S + q.aroots S := by suffices map (algebraMap T S) p * map (algebraMap T S) q ≠ 0 by rw [aroots_def, Polynomial.map_mul, roots_mul this] rwa [← Polynomial.map_mul, Polynomial.map_ne_zero_iff (NoZeroSMulDivisors.algebraMap_injective T S)] @[simp] theorem aroots_X_sub_C [CommRing S] [IsDomain S] [Algebra T S] (r : T) : aroots (X - C r) S = {algebraMap T S r} := by rw [aroots_def, Polynomial.map_sub, map_X, map_C, roots_X_sub_C] @[simp] theorem aroots_X [CommRing S] [IsDomain S] [Algebra T S] : aroots (X : T[X]) S = {0} := by rw [aroots_def, map_X, roots_X] @[simp] theorem aroots_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).aroots S = 0 := by rw [aroots_def, map_C, roots_C] @[simp] theorem aroots_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).aroots S = 0 := by rw [← C_0, aroots_C] @[simp] theorem aroots_one [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).aroots S = 0 := aroots_C 1 @[simp] theorem aroots_neg [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) : (-p).aroots S = p.aroots S := by rw [aroots, Polynomial.map_neg, roots_neg] @[simp] theorem aroots_C_mul [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) : (C a * p).aroots S = p.aroots S := by rw [aroots_def, Polynomial.map_mul, map_C, roots_C_mul] rwa [map_ne_zero_iff] exact NoZeroSMulDivisors.algebraMap_injective T S @[simp] theorem aroots_smul_nonzero [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) : (a • p).aroots S = p.aroots S := by rw [smul_eq_C_mul, aroots_C_mul _ ha] @[simp] theorem aroots_pow [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) (n : ℕ) : (p ^ n).aroots S = n • p.aroots S := by rw [aroots_def, Polynomial.map_pow, roots_pow] theorem aroots_X_pow [CommRing S] [IsDomain S] [Algebra T S] (n : ℕ) : (X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by rw [aroots_pow, aroots_X] theorem aroots_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (ha : a ≠ 0) (n : ℕ) : (C a * X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by rw [aroots_C_mul _ ha, aroots_X_pow] @[simp]
Mathlib/Algebra/Polynomial/Roots.lean
494
497
theorem aroots_monomial [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (ha : a ≠ 0) (n : ℕ) : (monomial n a).aroots S = n • ({0} : Multiset S) := by
rw [← C_mul_X_pow_eq_monomial, aroots_C_mul_X_pow ha]
/- Copyright (c) 2018 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.Topology.MetricSpace.Antilipschitz #align_import topology.metric_space.isometry from "leanprover-community/mathlib"@"b1859b6d4636fdbb78c5d5cefd24530653cfd3eb" /-! # Isometries We define isometries, i.e., maps between emetric spaces that preserve the edistance (on metric spaces, these are exactly the maps that preserve distances), and prove their basic properties. We also introduce isometric bijections. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `PseudoMetricSpace` and we specialize to `MetricSpace` when needed. -/ noncomputable section universe u v w variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} open Function Set open scoped Topology ENNReal /-- An isometry (also known as isometric embedding) is a map preserving the edistance between pseudoemetric spaces, or equivalently the distance between pseudometric space. -/ def Isometry [PseudoEMetricSpace α] [PseudoEMetricSpace β] (f : α → β) : Prop := ∀ x1 x2 : α, edist (f x1) (f x2) = edist x1 x2 #align isometry Isometry /-- On pseudometric spaces, a map is an isometry if and only if it preserves nonnegative distances. -/ theorem isometry_iff_nndist_eq [PseudoMetricSpace α] [PseudoMetricSpace β] {f : α → β} : Isometry f ↔ ∀ x y, nndist (f x) (f y) = nndist x y := by simp only [Isometry, edist_nndist, ENNReal.coe_inj] #align isometry_iff_nndist_eq isometry_iff_nndist_eq /-- On pseudometric spaces, a map is an isometry if and only if it preserves distances. -/ theorem isometry_iff_dist_eq [PseudoMetricSpace α] [PseudoMetricSpace β] {f : α → β} : Isometry f ↔ ∀ x y, dist (f x) (f y) = dist x y := by simp only [isometry_iff_nndist_eq, ← coe_nndist, NNReal.coe_inj] #align isometry_iff_dist_eq isometry_iff_dist_eq /-- An isometry preserves distances. -/ alias ⟨Isometry.dist_eq, _⟩ := isometry_iff_dist_eq #align isometry.dist_eq Isometry.dist_eq /-- A map that preserves distances is an isometry -/ alias ⟨_, Isometry.of_dist_eq⟩ := isometry_iff_dist_eq #align isometry.of_dist_eq Isometry.of_dist_eq /-- An isometry preserves non-negative distances. -/ alias ⟨Isometry.nndist_eq, _⟩ := isometry_iff_nndist_eq #align isometry.nndist_eq Isometry.nndist_eq /-- A map that preserves non-negative distances is an isometry. -/ alias ⟨_, Isometry.of_nndist_eq⟩ := isometry_iff_nndist_eq #align isometry.of_nndist_eq Isometry.of_nndist_eq namespace Isometry section PseudoEmetricIsometry variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] variable {f : α → β} {x y z : α} {s : Set α} /-- An isometry preserves edistances. -/ theorem edist_eq (hf : Isometry f) (x y : α) : edist (f x) (f y) = edist x y := hf x y #align isometry.edist_eq Isometry.edist_eq theorem lipschitz (h : Isometry f) : LipschitzWith 1 f := LipschitzWith.of_edist_le fun x y => (h x y).le #align isometry.lipschitz Isometry.lipschitz theorem antilipschitz (h : Isometry f) : AntilipschitzWith 1 f := fun x y => by simp only [h x y, ENNReal.coe_one, one_mul, le_refl] #align isometry.antilipschitz Isometry.antilipschitz /-- Any map on a subsingleton is an isometry -/ @[nontriviality] theorem _root_.isometry_subsingleton [Subsingleton α] : Isometry f := fun x y => by rw [Subsingleton.elim x y]; simp #align isometry_subsingleton isometry_subsingleton /-- The identity is an isometry -/ theorem _root_.isometry_id : Isometry (id : α → α) := fun _ _ => rfl #align isometry_id isometry_id theorem prod_map {δ} [PseudoEMetricSpace δ] {f : α → β} {g : γ → δ} (hf : Isometry f) (hg : Isometry g) : Isometry (Prod.map f g) := fun x y => by simp only [Prod.edist_eq, hf.edist_eq, hg.edist_eq, Prod.map_apply] #align isometry.prod_map Isometry.prod_map theorem _root_.isometry_dcomp {ι} [Fintype ι] {α β : ι → Type*} [∀ i, PseudoEMetricSpace (α i)] [∀ i, PseudoEMetricSpace (β i)] (f : ∀ i, α i → β i) (hf : ∀ i, Isometry (f i)) : Isometry (fun g : (i : ι) → α i => fun i => f i (g i)) := fun x y => by simp only [edist_pi_def, (hf _).edist_eq] #align isometry_dcomp isometry_dcomp /-- The composition of isometries is an isometry. -/ theorem comp {g : β → γ} {f : α → β} (hg : Isometry g) (hf : Isometry f) : Isometry (g ∘ f) := fun _ _ => (hg _ _).trans (hf _ _) #align isometry.comp Isometry.comp /-- An isometry from a metric space is a uniform continuous map -/ protected theorem uniformContinuous (hf : Isometry f) : UniformContinuous f := hf.lipschitz.uniformContinuous #align isometry.uniform_continuous Isometry.uniformContinuous /-- An isometry from a metric space is a uniform inducing map -/ protected theorem uniformInducing (hf : Isometry f) : UniformInducing f := hf.antilipschitz.uniformInducing hf.uniformContinuous #align isometry.uniform_inducing Isometry.uniformInducing theorem tendsto_nhds_iff {ι : Type*} {f : α → β} {g : ι → α} {a : Filter ι} {b : α} (hf : Isometry f) : Filter.Tendsto g a (𝓝 b) ↔ Filter.Tendsto (f ∘ g) a (𝓝 (f b)) := hf.uniformInducing.inducing.tendsto_nhds_iff #align isometry.tendsto_nhds_iff Isometry.tendsto_nhds_iff /-- An isometry is continuous. -/ protected theorem continuous (hf : Isometry f) : Continuous f := hf.lipschitz.continuous #align isometry.continuous Isometry.continuous /-- The right inverse of an isometry is an isometry. -/ theorem right_inv {f : α → β} {g : β → α} (h : Isometry f) (hg : RightInverse g f) : Isometry g := fun x y => by rw [← h, hg _, hg _] #align isometry.right_inv Isometry.right_inv theorem preimage_emetric_closedBall (h : Isometry f) (x : α) (r : ℝ≥0∞) : f ⁻¹' EMetric.closedBall (f x) r = EMetric.closedBall x r := by ext y simp [h.edist_eq] #align isometry.preimage_emetric_closed_ball Isometry.preimage_emetric_closedBall theorem preimage_emetric_ball (h : Isometry f) (x : α) (r : ℝ≥0∞) : f ⁻¹' EMetric.ball (f x) r = EMetric.ball x r := by ext y simp [h.edist_eq] #align isometry.preimage_emetric_ball Isometry.preimage_emetric_ball /-- Isometries preserve the diameter in pseudoemetric spaces. -/ theorem ediam_image (hf : Isometry f) (s : Set α) : EMetric.diam (f '' s) = EMetric.diam s := eq_of_forall_ge_iff fun d => by simp only [EMetric.diam_le_iff, forall_mem_image, hf.edist_eq] #align isometry.ediam_image Isometry.ediam_image theorem ediam_range (hf : Isometry f) : EMetric.diam (range f) = EMetric.diam (univ : Set α) := by rw [← image_univ] exact hf.ediam_image univ #align isometry.ediam_range Isometry.ediam_range theorem mapsTo_emetric_ball (hf : Isometry f) (x : α) (r : ℝ≥0∞) : MapsTo f (EMetric.ball x r) (EMetric.ball (f x) r) := (hf.preimage_emetric_ball x r).ge #align isometry.maps_to_emetric_ball Isometry.mapsTo_emetric_ball theorem mapsTo_emetric_closedBall (hf : Isometry f) (x : α) (r : ℝ≥0∞) : MapsTo f (EMetric.closedBall x r) (EMetric.closedBall (f x) r) := (hf.preimage_emetric_closedBall x r).ge #align isometry.maps_to_emetric_closed_ball Isometry.mapsTo_emetric_closedBall /-- The injection from a subtype is an isometry -/ theorem _root_.isometry_subtype_coe {s : Set α} : Isometry ((↑) : s → α) := fun _ _ => rfl #align isometry_subtype_coe isometry_subtype_coe theorem comp_continuousOn_iff {γ} [TopologicalSpace γ] (hf : Isometry f) {g : γ → α} {s : Set γ} : ContinuousOn (f ∘ g) s ↔ ContinuousOn g s := hf.uniformInducing.inducing.continuousOn_iff.symm #align isometry.comp_continuous_on_iff Isometry.comp_continuousOn_iff theorem comp_continuous_iff {γ} [TopologicalSpace γ] (hf : Isometry f) {g : γ → α} : Continuous (f ∘ g) ↔ Continuous g := hf.uniformInducing.inducing.continuous_iff.symm #align isometry.comp_continuous_iff Isometry.comp_continuous_iff end PseudoEmetricIsometry --section section EmetricIsometry variable [EMetricSpace α] [PseudoEMetricSpace β] {f : α → β} /-- An isometry from an emetric space is injective -/ protected theorem injective (h : Isometry f) : Injective f := h.antilipschitz.injective #align isometry.injective Isometry.injective /-- An isometry from an emetric space is a uniform embedding -/ protected theorem uniformEmbedding (hf : Isometry f) : UniformEmbedding f := hf.antilipschitz.uniformEmbedding hf.lipschitz.uniformContinuous #align isometry.uniform_embedding Isometry.uniformEmbedding /-- An isometry from an emetric space is an embedding -/ protected theorem embedding (hf : Isometry f) : Embedding f := hf.uniformEmbedding.embedding #align isometry.embedding Isometry.embedding /-- An isometry from a complete emetric space is a closed embedding -/ theorem closedEmbedding [CompleteSpace α] [EMetricSpace γ] {f : α → γ} (hf : Isometry f) : ClosedEmbedding f := hf.antilipschitz.closedEmbedding hf.lipschitz.uniformContinuous #align isometry.closed_embedding Isometry.closedEmbedding end EmetricIsometry --section section PseudoMetricIsometry variable [PseudoMetricSpace α] [PseudoMetricSpace β] {f : α → β} /-- An isometry preserves the diameter in pseudometric spaces. -/ theorem diam_image (hf : Isometry f) (s : Set α) : Metric.diam (f '' s) = Metric.diam s := by rw [Metric.diam, Metric.diam, hf.ediam_image] #align isometry.diam_image Isometry.diam_image theorem diam_range (hf : Isometry f) : Metric.diam (range f) = Metric.diam (univ : Set α) := by rw [← image_univ] exact hf.diam_image univ #align isometry.diam_range Isometry.diam_range theorem preimage_setOf_dist (hf : Isometry f) (x : α) (p : ℝ → Prop) : f ⁻¹' { y | p (dist y (f x)) } = { y | p (dist y x) } := by ext y simp [hf.dist_eq] #align isometry.preimage_set_of_dist Isometry.preimage_setOf_dist theorem preimage_closedBall (hf : Isometry f) (x : α) (r : ℝ) : f ⁻¹' Metric.closedBall (f x) r = Metric.closedBall x r := hf.preimage_setOf_dist x (· ≤ r) #align isometry.preimage_closed_ball Isometry.preimage_closedBall theorem preimage_ball (hf : Isometry f) (x : α) (r : ℝ) : f ⁻¹' Metric.ball (f x) r = Metric.ball x r := hf.preimage_setOf_dist x (· < r) #align isometry.preimage_ball Isometry.preimage_ball theorem preimage_sphere (hf : Isometry f) (x : α) (r : ℝ) : f ⁻¹' Metric.sphere (f x) r = Metric.sphere x r := hf.preimage_setOf_dist x (· = r) #align isometry.preimage_sphere Isometry.preimage_sphere theorem mapsTo_ball (hf : Isometry f) (x : α) (r : ℝ) : MapsTo f (Metric.ball x r) (Metric.ball (f x) r) := (hf.preimage_ball x r).ge #align isometry.maps_to_ball Isometry.mapsTo_ball theorem mapsTo_sphere (hf : Isometry f) (x : α) (r : ℝ) : MapsTo f (Metric.sphere x r) (Metric.sphere (f x) r) := (hf.preimage_sphere x r).ge #align isometry.maps_to_sphere Isometry.mapsTo_sphere theorem mapsTo_closedBall (hf : Isometry f) (x : α) (r : ℝ) : MapsTo f (Metric.closedBall x r) (Metric.closedBall (f x) r) := (hf.preimage_closedBall x r).ge #align isometry.maps_to_closed_ball Isometry.mapsTo_closedBall end PseudoMetricIsometry -- section end Isometry -- namespace /-- A uniform embedding from a uniform space to a metric space is an isometry with respect to the induced metric space structure on the source space. -/ theorem UniformEmbedding.to_isometry {α β} [UniformSpace α] [MetricSpace β] {f : α → β} (h : UniformEmbedding f) : (letI := h.comapMetricSpace f; Isometry f) := let _ := h.comapMetricSpace f Isometry.of_dist_eq fun _ _ => rfl #align uniform_embedding.to_isometry UniformEmbedding.to_isometry /-- An embedding from a topological space to a metric space is an isometry with respect to the induced metric space structure on the source space. -/ theorem Embedding.to_isometry {α β} [TopologicalSpace α] [MetricSpace β] {f : α → β} (h : Embedding f) : (letI := h.comapMetricSpace f; Isometry f) := let _ := h.comapMetricSpace f Isometry.of_dist_eq fun _ _ => rfl #align embedding.to_isometry Embedding.to_isometry -- such a bijection need not exist /-- `α` and `β` are isometric if there is an isometric bijection between them. -/ -- Porting note(#5171): was @[nolint has_nonempty_instance] structure IsometryEquiv (α : Type u) (β : Type v) [PseudoEMetricSpace α] [PseudoEMetricSpace β] extends α ≃ β where isometry_toFun : Isometry toFun #align isometry_equiv IsometryEquiv @[inherit_doc] infixl:25 " ≃ᵢ " => IsometryEquiv namespace IsometryEquiv section PseudoEMetricSpace variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] -- Porting note (#11215): TODO: add `IsometryEquivClass` theorem toEquiv_injective : Injective (toEquiv : (α ≃ᵢ β) → (α ≃ β)) | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl #align isometry_equiv.to_equiv_inj IsometryEquiv.toEquiv_injective @[simp] theorem toEquiv_inj {e₁ e₂ : α ≃ᵢ β} : e₁.toEquiv = e₂.toEquiv ↔ e₁ = e₂ := toEquiv_injective.eq_iff instance : EquivLike (α ≃ᵢ β) α β where coe e := e.toEquiv inv e := e.toEquiv.symm left_inv e := e.left_inv right_inv e := e.right_inv coe_injective' _ _ h _ := toEquiv_injective <| DFunLike.ext' h theorem coe_eq_toEquiv (h : α ≃ᵢ β) (a : α) : h a = h.toEquiv a := rfl #align isometry_equiv.coe_eq_to_equiv IsometryEquiv.coe_eq_toEquiv @[simp] theorem coe_toEquiv (h : α ≃ᵢ β) : ⇑h.toEquiv = h := rfl #align isometry_equiv.coe_to_equiv IsometryEquiv.coe_toEquiv @[simp] theorem coe_mk (e : α ≃ β) (h) : ⇑(mk e h) = e := rfl protected theorem isometry (h : α ≃ᵢ β) : Isometry h := h.isometry_toFun #align isometry_equiv.isometry IsometryEquiv.isometry protected theorem bijective (h : α ≃ᵢ β) : Bijective h := h.toEquiv.bijective #align isometry_equiv.bijective IsometryEquiv.bijective protected theorem injective (h : α ≃ᵢ β) : Injective h := h.toEquiv.injective #align isometry_equiv.injective IsometryEquiv.injective protected theorem surjective (h : α ≃ᵢ β) : Surjective h := h.toEquiv.surjective #align isometry_equiv.surjective IsometryEquiv.surjective protected theorem edist_eq (h : α ≃ᵢ β) (x y : α) : edist (h x) (h y) = edist x y := h.isometry.edist_eq x y #align isometry_equiv.edist_eq IsometryEquiv.edist_eq protected theorem dist_eq {α β : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] (h : α ≃ᵢ β) (x y : α) : dist (h x) (h y) = dist x y := h.isometry.dist_eq x y #align isometry_equiv.dist_eq IsometryEquiv.dist_eq protected theorem nndist_eq {α β : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] (h : α ≃ᵢ β) (x y : α) : nndist (h x) (h y) = nndist x y := h.isometry.nndist_eq x y #align isometry_equiv.nndist_eq IsometryEquiv.nndist_eq protected theorem continuous (h : α ≃ᵢ β) : Continuous h := h.isometry.continuous #align isometry_equiv.continuous IsometryEquiv.continuous @[simp] theorem ediam_image (h : α ≃ᵢ β) (s : Set α) : EMetric.diam (h '' s) = EMetric.diam s := h.isometry.ediam_image s #align isometry_equiv.ediam_image IsometryEquiv.ediam_image @[ext] theorem ext ⦃h₁ h₂ : α ≃ᵢ β⦄ (H : ∀ x, h₁ x = h₂ x) : h₁ = h₂ := DFunLike.ext _ _ H #align isometry_equiv.ext IsometryEquiv.ext /-- Alternative constructor for isometric bijections, taking as input an isometry, and a right inverse. -/ def mk' {α : Type u} [EMetricSpace α] (f : α → β) (g : β → α) (hfg : ∀ x, f (g x) = x) (hf : Isometry f) : α ≃ᵢ β where toFun := f invFun := g left_inv _ := hf.injective <| hfg _ right_inv := hfg isometry_toFun := hf #align isometry_equiv.mk' IsometryEquiv.mk' /-- The identity isometry of a space. -/ protected def refl (α : Type*) [PseudoEMetricSpace α] : α ≃ᵢ α := { Equiv.refl α with isometry_toFun := isometry_id } #align isometry_equiv.refl IsometryEquiv.refl /-- The composition of two isometric isomorphisms, as an isometric isomorphism. -/ protected def trans (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) : α ≃ᵢ γ := { Equiv.trans h₁.toEquiv h₂.toEquiv with isometry_toFun := h₂.isometry_toFun.comp h₁.isometry_toFun } #align isometry_equiv.trans IsometryEquiv.trans @[simp] theorem trans_apply (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) (x : α) : h₁.trans h₂ x = h₂ (h₁ x) := rfl #align isometry_equiv.trans_apply IsometryEquiv.trans_apply /-- The inverse of an isometric isomorphism, as an isometric isomorphism. -/ protected def symm (h : α ≃ᵢ β) : β ≃ᵢ α where isometry_toFun := h.isometry.right_inv h.right_inv toEquiv := h.toEquiv.symm #align isometry_equiv.symm IsometryEquiv.symm /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (h : α ≃ᵢ β) : α → β := h #align isometry_equiv.simps.apply IsometryEquiv.Simps.apply /-- See Note [custom simps projection] -/ def Simps.symm_apply (h : α ≃ᵢ β) : β → α := h.symm #align isometry_equiv.simps.symm_apply IsometryEquiv.Simps.symm_apply initialize_simps_projections IsometryEquiv (toEquiv_toFun → apply, toEquiv_invFun → symm_apply) @[simp] theorem symm_symm (h : α ≃ᵢ β) : h.symm.symm = h := rfl #align isometry_equiv.symm_symm IsometryEquiv.symm_symm theorem symm_bijective : Bijective (IsometryEquiv.symm : (α ≃ᵢ β) → β ≃ᵢ α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem apply_symm_apply (h : α ≃ᵢ β) (y : β) : h (h.symm y) = y := h.toEquiv.apply_symm_apply y #align isometry_equiv.apply_symm_apply IsometryEquiv.apply_symm_apply @[simp] theorem symm_apply_apply (h : α ≃ᵢ β) (x : α) : h.symm (h x) = x := h.toEquiv.symm_apply_apply x #align isometry_equiv.symm_apply_apply IsometryEquiv.symm_apply_apply theorem symm_apply_eq (h : α ≃ᵢ β) {x : α} {y : β} : h.symm y = x ↔ y = h x := h.toEquiv.symm_apply_eq #align isometry_equiv.symm_apply_eq IsometryEquiv.symm_apply_eq theorem eq_symm_apply (h : α ≃ᵢ β) {x : α} {y : β} : x = h.symm y ↔ h x = y := h.toEquiv.eq_symm_apply #align isometry_equiv.eq_symm_apply IsometryEquiv.eq_symm_apply theorem symm_comp_self (h : α ≃ᵢ β) : (h.symm : β → α) ∘ h = id := funext h.left_inv #align isometry_equiv.symm_comp_self IsometryEquiv.symm_comp_self theorem self_comp_symm (h : α ≃ᵢ β) : (h : α → β) ∘ h.symm = id := funext h.right_inv #align isometry_equiv.self_comp_symm IsometryEquiv.self_comp_symm @[simp] theorem range_eq_univ (h : α ≃ᵢ β) : range h = univ := h.toEquiv.range_eq_univ #align isometry_equiv.range_eq_univ IsometryEquiv.range_eq_univ theorem image_symm (h : α ≃ᵢ β) : image h.symm = preimage h := image_eq_preimage_of_inverse h.symm.toEquiv.left_inv h.symm.toEquiv.right_inv #align isometry_equiv.image_symm IsometryEquiv.image_symm theorem preimage_symm (h : α ≃ᵢ β) : preimage h.symm = image h := (image_eq_preimage_of_inverse h.toEquiv.left_inv h.toEquiv.right_inv).symm #align isometry_equiv.preimage_symm IsometryEquiv.preimage_symm @[simp] theorem symm_trans_apply (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) (x : γ) : (h₁.trans h₂).symm x = h₁.symm (h₂.symm x) := rfl #align isometry_equiv.symm_trans_apply IsometryEquiv.symm_trans_apply theorem ediam_univ (h : α ≃ᵢ β) : EMetric.diam (univ : Set α) = EMetric.diam (univ : Set β) := by rw [← h.range_eq_univ, h.isometry.ediam_range] #align isometry_equiv.ediam_univ IsometryEquiv.ediam_univ @[simp] theorem ediam_preimage (h : α ≃ᵢ β) (s : Set β) : EMetric.diam (h ⁻¹' s) = EMetric.diam s := by rw [← image_symm, ediam_image] #align isometry_equiv.ediam_preimage IsometryEquiv.ediam_preimage @[simp] theorem preimage_emetric_ball (h : α ≃ᵢ β) (x : β) (r : ℝ≥0∞) : h ⁻¹' EMetric.ball x r = EMetric.ball (h.symm x) r := by rw [← h.isometry.preimage_emetric_ball (h.symm x) r, h.apply_symm_apply] #align isometry_equiv.preimage_emetric_ball IsometryEquiv.preimage_emetric_ball @[simp] theorem preimage_emetric_closedBall (h : α ≃ᵢ β) (x : β) (r : ℝ≥0∞) : h ⁻¹' EMetric.closedBall x r = EMetric.closedBall (h.symm x) r := by rw [← h.isometry.preimage_emetric_closedBall (h.symm x) r, h.apply_symm_apply] #align isometry_equiv.preimage_emetric_closed_ball IsometryEquiv.preimage_emetric_closedBall @[simp] theorem image_emetric_ball (h : α ≃ᵢ β) (x : α) (r : ℝ≥0∞) : h '' EMetric.ball x r = EMetric.ball (h x) r := by rw [← h.preimage_symm, h.symm.preimage_emetric_ball, symm_symm] #align isometry_equiv.image_emetric_ball IsometryEquiv.image_emetric_ball @[simp] theorem image_emetric_closedBall (h : α ≃ᵢ β) (x : α) (r : ℝ≥0∞) : h '' EMetric.closedBall x r = EMetric.closedBall (h x) r := by rw [← h.preimage_symm, h.symm.preimage_emetric_closedBall, symm_symm] #align isometry_equiv.image_emetric_closed_ball IsometryEquiv.image_emetric_closedBall /-- The (bundled) homeomorphism associated to an isometric isomorphism. -/ @[simps toEquiv] protected def toHomeomorph (h : α ≃ᵢ β) : α ≃ₜ β where continuous_toFun := h.continuous continuous_invFun := h.symm.continuous toEquiv := h.toEquiv #align isometry_equiv.to_homeomorph IsometryEquiv.toHomeomorph #align isometry_equiv.to_homeomorph_to_equiv IsometryEquiv.toHomeomorph_toEquiv @[simp] theorem coe_toHomeomorph (h : α ≃ᵢ β) : ⇑h.toHomeomorph = h := rfl #align isometry_equiv.coe_to_homeomorph IsometryEquiv.coe_toHomeomorph @[simp] theorem coe_toHomeomorph_symm (h : α ≃ᵢ β) : ⇑h.toHomeomorph.symm = h.symm := rfl #align isometry_equiv.coe_to_homeomorph_symm IsometryEquiv.coe_toHomeomorph_symm @[simp] theorem comp_continuousOn_iff {γ} [TopologicalSpace γ] (h : α ≃ᵢ β) {f : γ → α} {s : Set γ} : ContinuousOn (h ∘ f) s ↔ ContinuousOn f s := h.toHomeomorph.comp_continuousOn_iff _ _ #align isometry_equiv.comp_continuous_on_iff IsometryEquiv.comp_continuousOn_iff @[simp] theorem comp_continuous_iff {γ} [TopologicalSpace γ] (h : α ≃ᵢ β) {f : γ → α} : Continuous (h ∘ f) ↔ Continuous f := h.toHomeomorph.comp_continuous_iff #align isometry_equiv.comp_continuous_iff IsometryEquiv.comp_continuous_iff @[simp] theorem comp_continuous_iff' {γ} [TopologicalSpace γ] (h : α ≃ᵢ β) {f : β → γ} : Continuous (f ∘ h) ↔ Continuous f := h.toHomeomorph.comp_continuous_iff' #align isometry_equiv.comp_continuous_iff' IsometryEquiv.comp_continuous_iff' /-- The group of isometries. -/ instance : Group (α ≃ᵢ α) where one := IsometryEquiv.refl _ mul e₁ e₂ := e₂.trans e₁ inv := IsometryEquiv.symm mul_assoc e₁ e₂ e₃ := rfl one_mul e := ext fun _ => rfl mul_one e := ext fun _ => rfl mul_left_inv e := ext e.symm_apply_apply @[simp] theorem coe_one : ⇑(1 : α ≃ᵢ α) = id := rfl #align isometry_equiv.coe_one IsometryEquiv.coe_one @[simp] theorem coe_mul (e₁ e₂ : α ≃ᵢ α) : ⇑(e₁ * e₂) = e₁ ∘ e₂ := rfl #align isometry_equiv.coe_mul IsometryEquiv.coe_mul theorem mul_apply (e₁ e₂ : α ≃ᵢ α) (x : α) : (e₁ * e₂) x = e₁ (e₂ x) := rfl #align isometry_equiv.mul_apply IsometryEquiv.mul_apply @[simp] theorem inv_apply_self (e : α ≃ᵢ α) (x : α) : e⁻¹ (e x) = x := e.symm_apply_apply x #align isometry_equiv.inv_apply_self IsometryEquiv.inv_apply_self @[simp] theorem apply_inv_self (e : α ≃ᵢ α) (x : α) : e (e⁻¹ x) = x := e.apply_symm_apply x #align isometry_equiv.apply_inv_self IsometryEquiv.apply_inv_self theorem completeSpace_iff (e : α ≃ᵢ β) : CompleteSpace α ↔ CompleteSpace β := by simp only [completeSpace_iff_isComplete_univ, ← e.range_eq_univ, ← image_univ, isComplete_image_iff e.isometry.uniformInducing] #align isometry_equiv.complete_space_iff IsometryEquiv.completeSpace_iff protected theorem completeSpace [CompleteSpace β] (e : α ≃ᵢ β) : CompleteSpace α := e.completeSpace_iff.2 ‹_› #align isometry_equiv.complete_space IsometryEquiv.completeSpace variable (ι α) /-- `Equiv.funUnique` as an `IsometryEquiv`. -/ @[simps!] def funUnique [Unique ι] [Fintype ι] : (ι → α) ≃ᵢ α where toEquiv := Equiv.funUnique ι α isometry_toFun x hx := by simp [edist_pi_def, Finset.univ_unique, Finset.sup_singleton] #align isometry_equiv.fun_unique IsometryEquiv.funUnique /-- `piFinTwoEquiv` as an `IsometryEquiv`. -/ @[simps!] def piFinTwo (α : Fin 2 → Type*) [∀ i, PseudoEMetricSpace (α i)] : (∀ i, α i) ≃ᵢ α 0 × α 1 where toEquiv := piFinTwoEquiv α isometry_toFun x hx := by simp [edist_pi_def, Fin.univ_succ, Prod.edist_eq] #align isometry_equiv.pi_fin_two IsometryEquiv.piFinTwo end PseudoEMetricSpace section PseudoMetricSpace variable [PseudoMetricSpace α] [PseudoMetricSpace β] (h : α ≃ᵢ β) @[simp] theorem diam_image (s : Set α) : Metric.diam (h '' s) = Metric.diam s := h.isometry.diam_image s #align isometry_equiv.diam_image IsometryEquiv.diam_image @[simp] theorem diam_preimage (s : Set β) : Metric.diam (h ⁻¹' s) = Metric.diam s := by rw [← image_symm, diam_image] #align isometry_equiv.diam_preimage IsometryEquiv.diam_preimage theorem diam_univ : Metric.diam (univ : Set α) = Metric.diam (univ : Set β) := congr_arg ENNReal.toReal h.ediam_univ #align isometry_equiv.diam_univ IsometryEquiv.diam_univ @[simp] theorem preimage_ball (h : α ≃ᵢ β) (x : β) (r : ℝ) : h ⁻¹' Metric.ball x r = Metric.ball (h.symm x) r := by rw [← h.isometry.preimage_ball (h.symm x) r, h.apply_symm_apply] #align isometry_equiv.preimage_ball IsometryEquiv.preimage_ball @[simp]
Mathlib/Topology/MetricSpace/Isometry.lean
614
616
theorem preimage_sphere (h : α ≃ᵢ β) (x : β) (r : ℝ) : h ⁻¹' Metric.sphere x r = Metric.sphere (h.symm x) r := by
rw [← h.isometry.preimage_sphere (h.symm x) r, h.apply_symm_apply]
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.Gluing import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.AlgebraicGeometry.AffineScheme import Mathlib.CategoryTheory.Limits.Shapes.Diagonal #align_import algebraic_geometry.pullbacks from "leanprover-community/mathlib"@"7316286ff2942aa14e540add9058c6b0aa1c8070" /-! # Fibred products of schemes In this file we construct the fibred product of schemes via gluing. We roughly follow [har77] Theorem 3.3. In particular, the main construction is to show that for an open cover `{ Uᵢ }` of `X`, if there exist fibred products `Uᵢ ×[Z] Y` for each `i`, then there exists a fibred product `X ×[Z] Y`. Then, for constructing the fibred product for arbitrary schemes `X, Y, Z`, we can use the construction to reduce to the case where `X, Y, Z` are all affine, where fibred products are constructed via tensor products. -/ set_option linter.uppercaseLean3 false universe v u noncomputable section open CategoryTheory CategoryTheory.Limits AlgebraicGeometry namespace AlgebraicGeometry.Scheme namespace Pullback variable {C : Type u} [Category.{v} C] variable {X Y Z : Scheme.{u}} (𝒰 : OpenCover.{u} X) (f : X ⟶ Z) (g : Y ⟶ Z) variable [∀ i, HasPullback (𝒰.map i ≫ f) g] /-- The intersection of `Uᵢ ×[Z] Y` and `Uⱼ ×[Z] Y` is given by (Uᵢ ×[Z] Y) ×[X] Uⱼ -/ def v (i j : 𝒰.J) : Scheme := pullback ((pullback.fst : pullback (𝒰.map i ≫ f) g ⟶ _) ≫ 𝒰.map i) (𝒰.map j) #align algebraic_geometry.Scheme.pullback.V AlgebraicGeometry.Scheme.Pullback.v /-- The canonical transition map `(Uᵢ ×[Z] Y) ×[X] Uⱼ ⟶ (Uⱼ ×[Z] Y) ×[X] Uᵢ` given by the fact that pullbacks are associative and symmetric. -/ def t (i j : 𝒰.J) : v 𝒰 f g i j ⟶ v 𝒰 f g j i := by have : HasPullback (pullback.snd ≫ 𝒰.map i ≫ f) g := hasPullback_assoc_symm (𝒰.map j) (𝒰.map i) (𝒰.map i ≫ f) g have : HasPullback (pullback.snd ≫ 𝒰.map j ≫ f) g := hasPullback_assoc_symm (𝒰.map i) (𝒰.map j) (𝒰.map j ≫ f) g refine (pullbackSymmetry ..).hom ≫ (pullbackAssoc ..).inv ≫ ?_ refine ?_ ≫ (pullbackAssoc ..).hom ≫ (pullbackSymmetry ..).hom refine pullback.map _ _ _ _ (pullbackSymmetry _ _).hom (𝟙 _) (𝟙 _) ?_ ?_ · rw [pullbackSymmetry_hom_comp_snd_assoc, pullback.condition_assoc, Category.comp_id] · rw [Category.comp_id, Category.id_comp] #align algebraic_geometry.Scheme.pullback.t AlgebraicGeometry.Scheme.Pullback.t @[simp, reassoc] theorem t_fst_fst (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.fst ≫ pullback.fst = pullback.snd := by simp only [t, Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackAssoc_hom_snd_fst, pullback.lift_fst_assoc, pullbackSymmetry_hom_comp_snd, pullbackAssoc_inv_fst_fst, pullbackSymmetry_hom_comp_fst] #align algebraic_geometry.Scheme.pullback.t_fst_fst AlgebraicGeometry.Scheme.Pullback.t_fst_fst @[simp, reassoc] theorem t_fst_snd (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.fst ≫ pullback.snd = pullback.fst ≫ pullback.snd := by simp only [t, Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackAssoc_hom_snd_snd, pullback.lift_snd, Category.comp_id, pullbackAssoc_inv_snd, pullbackSymmetry_hom_comp_snd_assoc] #align algebraic_geometry.Scheme.pullback.t_fst_snd AlgebraicGeometry.Scheme.Pullback.t_fst_snd @[simp, reassoc] theorem t_snd (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.snd = pullback.fst ≫ pullback.fst := by simp only [t, Category.assoc, pullbackSymmetry_hom_comp_snd, pullbackAssoc_hom_fst, pullback.lift_fst_assoc, pullbackSymmetry_hom_comp_fst, pullbackAssoc_inv_fst_snd, pullbackSymmetry_hom_comp_snd_assoc] #align algebraic_geometry.Scheme.pullback.t_snd AlgebraicGeometry.Scheme.Pullback.t_snd theorem t_id (i : 𝒰.J) : t 𝒰 f g i i = 𝟙 _ := by apply pullback.hom_ext <;> rw [Category.id_comp] · apply pullback.hom_ext · rw [← cancel_mono (𝒰.map i)]; simp only [pullback.condition, Category.assoc, t_fst_fst] · simp only [Category.assoc, t_fst_snd] · rw [← cancel_mono (𝒰.map i)]; simp only [pullback.condition, t_snd, Category.assoc] #align algebraic_geometry.Scheme.pullback.t_id AlgebraicGeometry.Scheme.Pullback.t_id /-- The inclusion map of `V i j = (Uᵢ ×[Z] Y) ×[X] Uⱼ ⟶ Uᵢ ×[Z] Y`-/ abbrev fV (i j : 𝒰.J) : v 𝒰 f g i j ⟶ pullback (𝒰.map i ≫ f) g := pullback.fst #align algebraic_geometry.Scheme.pullback.fV AlgebraicGeometry.Scheme.Pullback.fV /-- The map `((Xᵢ ×[Z] Y) ×[X] Xⱼ) ×[Xᵢ ×[Z] Y] ((Xᵢ ×[Z] Y) ×[X] Xₖ)` ⟶ `((Xⱼ ×[Z] Y) ×[X] Xₖ) ×[Xⱼ ×[Z] Y] ((Xⱼ ×[Z] Y) ×[X] Xᵢ)` needed for gluing -/ def t' (i j k : 𝒰.J) : pullback (fV 𝒰 f g i j) (fV 𝒰 f g i k) ⟶ pullback (fV 𝒰 f g j k) (fV 𝒰 f g j i) := by refine (pullbackRightPullbackFstIso ..).hom ≫ ?_ refine ?_ ≫ (pullbackSymmetry _ _).hom refine ?_ ≫ (pullbackRightPullbackFstIso ..).inv refine pullback.map _ _ _ _ (t 𝒰 f g i j) (𝟙 _) (𝟙 _) ?_ ?_ · simp_rw [Category.comp_id, t_fst_fst_assoc, ← pullback.condition] · rw [Category.comp_id, Category.id_comp] #align algebraic_geometry.Scheme.pullback.t' AlgebraicGeometry.Scheme.Pullback.t' @[simp, reassoc] theorem t'_fst_fst_fst (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.fst ≫ pullback.fst ≫ pullback.fst = pullback.fst ≫ pullback.snd := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackRightPullbackFstIso_inv_snd_fst_assoc, pullback.lift_fst_assoc, t_fst_fst, pullbackRightPullbackFstIso_hom_fst_assoc] #align algebraic_geometry.Scheme.pullback.t'_fst_fst_fst AlgebraicGeometry.Scheme.Pullback.t'_fst_fst_fst @[simp, reassoc] theorem t'_fst_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.fst ≫ pullback.fst ≫ pullback.snd = pullback.fst ≫ pullback.fst ≫ pullback.snd := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackRightPullbackFstIso_inv_snd_fst_assoc, pullback.lift_fst_assoc, t_fst_snd, pullbackRightPullbackFstIso_hom_fst_assoc] #align algebraic_geometry.Scheme.pullback.t'_fst_fst_snd AlgebraicGeometry.Scheme.Pullback.t'_fst_fst_snd @[simp, reassoc] theorem t'_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.fst ≫ pullback.snd = pullback.snd ≫ pullback.snd := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackRightPullbackFstIso_inv_snd_snd, pullback.lift_snd, Category.comp_id, pullbackRightPullbackFstIso_hom_snd] #align algebraic_geometry.Scheme.pullback.t'_fst_snd AlgebraicGeometry.Scheme.Pullback.t'_fst_snd @[simp, reassoc] theorem t'_snd_fst_fst (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.snd ≫ pullback.fst ≫ pullback.fst = pullback.fst ≫ pullback.snd := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_snd_assoc, pullbackRightPullbackFstIso_inv_fst_assoc, pullback.lift_fst_assoc, t_fst_fst, pullbackRightPullbackFstIso_hom_fst_assoc] #align algebraic_geometry.Scheme.pullback.t'_snd_fst_fst AlgebraicGeometry.Scheme.Pullback.t'_snd_fst_fst @[simp, reassoc] theorem t'_snd_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.snd ≫ pullback.fst ≫ pullback.snd = pullback.fst ≫ pullback.fst ≫ pullback.snd := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_snd_assoc, pullbackRightPullbackFstIso_inv_fst_assoc, pullback.lift_fst_assoc, t_fst_snd, pullbackRightPullbackFstIso_hom_fst_assoc] #align algebraic_geometry.Scheme.pullback.t'_snd_fst_snd AlgebraicGeometry.Scheme.Pullback.t'_snd_fst_snd @[simp, reassoc] theorem t'_snd_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.snd ≫ pullback.snd = pullback.fst ≫ pullback.fst ≫ pullback.fst := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_snd_assoc, pullbackRightPullbackFstIso_inv_fst_assoc, pullback.lift_fst_assoc, t_snd, pullbackRightPullbackFstIso_hom_fst_assoc] #align algebraic_geometry.Scheme.pullback.t'_snd_snd AlgebraicGeometry.Scheme.Pullback.t'_snd_snd theorem cocycle_fst_fst_fst (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.fst ≫ pullback.fst ≫ pullback.fst = pullback.fst ≫ pullback.fst ≫ pullback.fst := by simp only [t'_fst_fst_fst, t'_fst_snd, t'_snd_snd] #align algebraic_geometry.Scheme.pullback.cocycle_fst_fst_fst AlgebraicGeometry.Scheme.Pullback.cocycle_fst_fst_fst theorem cocycle_fst_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.fst ≫ pullback.fst ≫ pullback.snd = pullback.fst ≫ pullback.fst ≫ pullback.snd := by simp only [t'_fst_fst_snd] #align algebraic_geometry.Scheme.pullback.cocycle_fst_fst_snd AlgebraicGeometry.Scheme.Pullback.cocycle_fst_fst_snd theorem cocycle_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.fst ≫ pullback.snd = pullback.fst ≫ pullback.snd := by simp only [t'_fst_snd, t'_snd_snd, t'_fst_fst_fst] #align algebraic_geometry.Scheme.pullback.cocycle_fst_snd AlgebraicGeometry.Scheme.Pullback.cocycle_fst_snd theorem cocycle_snd_fst_fst (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.snd ≫ pullback.fst ≫ pullback.fst = pullback.snd ≫ pullback.fst ≫ pullback.fst := by rw [← cancel_mono (𝒰.map i)] simp only [pullback.condition_assoc, t'_snd_fst_fst, t'_fst_snd, t'_snd_snd] #align algebraic_geometry.Scheme.pullback.cocycle_snd_fst_fst AlgebraicGeometry.Scheme.Pullback.cocycle_snd_fst_fst theorem cocycle_snd_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.snd ≫ pullback.fst ≫ pullback.snd = pullback.snd ≫ pullback.fst ≫ pullback.snd := by simp only [pullback.condition_assoc, t'_snd_fst_snd] #align algebraic_geometry.Scheme.pullback.cocycle_snd_fst_snd AlgebraicGeometry.Scheme.Pullback.cocycle_snd_fst_snd theorem cocycle_snd_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.snd ≫ pullback.snd = pullback.snd ≫ pullback.snd := by simp only [t'_snd_snd, t'_fst_fst_fst, t'_fst_snd] #align algebraic_geometry.Scheme.pullback.cocycle_snd_snd AlgebraicGeometry.Scheme.Pullback.cocycle_snd_snd -- `by tidy` should solve it, but it times out. theorem cocycle (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j = 𝟙 _ := by apply pullback.hom_ext <;> rw [Category.id_comp] · apply pullback.hom_ext · apply pullback.hom_ext · simp_rw [Category.assoc, cocycle_fst_fst_fst 𝒰 f g i j k] · simp_rw [Category.assoc, cocycle_fst_fst_snd 𝒰 f g i j k] · simp_rw [Category.assoc, cocycle_fst_snd 𝒰 f g i j k] · apply pullback.hom_ext · apply pullback.hom_ext · simp_rw [Category.assoc, cocycle_snd_fst_fst 𝒰 f g i j k] · simp_rw [Category.assoc, cocycle_snd_fst_snd 𝒰 f g i j k] · simp_rw [Category.assoc, cocycle_snd_snd 𝒰 f g i j k] #align algebraic_geometry.Scheme.pullback.cocycle AlgebraicGeometry.Scheme.Pullback.cocycle /-- Given `Uᵢ ×[Z] Y`, this is the glued fibered product `X ×[Z] Y`. -/ @[simps U V f t t', simps (config := .lemmasOnly) J] def gluing : Scheme.GlueData.{u} where J := 𝒰.J U i := pullback (𝒰.map i ≫ f) g V := fun ⟨i, j⟩ => v 𝒰 f g i j -- `p⁻¹(Uᵢ ∩ Uⱼ)` where `p : Uᵢ ×[Z] Y ⟶ Uᵢ ⟶ X`. f i j := pullback.fst f_id i := inferInstance f_open := inferInstance t i j := t 𝒰 f g i j t_id i := t_id 𝒰 f g i t' i j k := t' 𝒰 f g i j k t_fac i j k := by apply pullback.hom_ext on_goal 1 => apply pullback.hom_ext all_goals simp only [t'_snd_fst_fst, t'_snd_fst_snd, t'_snd_snd, t_fst_fst, t_fst_snd, t_snd, Category.assoc] cocycle i j k := cocycle 𝒰 f g i j k #align algebraic_geometry.Scheme.pullback.gluing AlgebraicGeometry.Scheme.Pullback.gluing @[simp] lemma gluing_ι (j : 𝒰.J) : (gluing 𝒰 f g).ι j = Multicoequalizer.π (gluing 𝒰 f g).diagram j := rfl /-- The first projection from the glued scheme into `X`. -/ def p1 : (gluing 𝒰 f g).glued ⟶ X := by apply Multicoequalizer.desc (gluing 𝒰 f g).diagram _ fun i ↦ pullback.fst ≫ 𝒰.map i simp [t_fst_fst_assoc, ← pullback.condition] #align algebraic_geometry.Scheme.pullback.p1 AlgebraicGeometry.Scheme.Pullback.p1 /-- The second projection from the glued scheme into `Y`. -/ def p2 : (gluing 𝒰 f g).glued ⟶ Y := by apply Multicoequalizer.desc _ _ fun i ↦ pullback.snd simp [t_fst_snd] #align algebraic_geometry.Scheme.pullback.p2 AlgebraicGeometry.Scheme.Pullback.p2 theorem p_comm : p1 𝒰 f g ≫ f = p2 𝒰 f g ≫ g := by apply Multicoequalizer.hom_ext simp [p1, p2, pullback.condition] #align algebraic_geometry.Scheme.pullback.p_comm AlgebraicGeometry.Scheme.Pullback.p_comm variable (s : PullbackCone f g) /-- (Implementation) The canonical map `(s.X ×[X] Uᵢ) ×[s.X] (s.X ×[X] Uⱼ) ⟶ (Uᵢ ×[Z] Y) ×[X] Uⱼ` This is used in `gluedLift`. -/ def gluedLiftPullbackMap (i j : 𝒰.J) : pullback ((𝒰.pullbackCover s.fst).map i) ((𝒰.pullbackCover s.fst).map j) ⟶ (gluing 𝒰 f g).V ⟨i, j⟩ := by refine (pullbackRightPullbackFstIso _ _ _).hom ≫ ?_ refine pullback.map _ _ _ _ ?_ (𝟙 _) (𝟙 _) ?_ ?_ · exact (pullbackSymmetry _ _).hom ≫ pullback.map _ _ _ _ (𝟙 _) s.snd f (Category.id_comp _).symm s.condition · simpa using pullback.condition · simp only [Category.comp_id, Category.id_comp] #align algebraic_geometry.Scheme.pullback.glued_lift_pullback_map AlgebraicGeometry.Scheme.Pullback.gluedLiftPullbackMap @[reassoc] theorem gluedLiftPullbackMap_fst (i j : 𝒰.J) : gluedLiftPullbackMap 𝒰 f g s i j ≫ pullback.fst = pullback.fst ≫ (pullbackSymmetry _ _).hom ≫ pullback.map _ _ _ _ (𝟙 _) s.snd f (Category.id_comp _).symm s.condition := by simp [gluedLiftPullbackMap] #align algebraic_geometry.Scheme.pullback.glued_lift_pullback_map_fst AlgebraicGeometry.Scheme.Pullback.gluedLiftPullbackMap_fst @[reassoc] theorem gluedLiftPullbackMap_snd (i j : 𝒰.J) : gluedLiftPullbackMap 𝒰 f g s i j ≫ pullback.snd = pullback.snd ≫ pullback.snd := by simp [gluedLiftPullbackMap] #align algebraic_geometry.Scheme.pullback.glued_lift_pullback_map_snd AlgebraicGeometry.Scheme.Pullback.gluedLiftPullbackMap_snd /-- The lifted map `s.X ⟶ (gluing 𝒰 f g).glued` in order to show that `(gluing 𝒰 f g).glued` is indeed the pullback. Given a pullback cone `s`, we have the maps `s.fst ⁻¹' Uᵢ ⟶ Uᵢ` and `s.fst ⁻¹' Uᵢ ⟶ s.X ⟶ Y` that we may lift to a map `s.fst ⁻¹' Uᵢ ⟶ Uᵢ ×[Z] Y`. to glue these into a map `s.X ⟶ Uᵢ ×[Z] Y`, we need to show that the maps agree on `(s.fst ⁻¹' Uᵢ) ×[s.X] (s.fst ⁻¹' Uⱼ) ⟶ Uᵢ ×[Z] Y`. This is achieved by showing that both of these maps factors through `gluedLiftPullbackMap`. -/ def gluedLift : s.pt ⟶ (gluing 𝒰 f g).glued := by fapply (𝒰.pullbackCover s.fst).glueMorphisms · exact fun i ↦ (pullbackSymmetry _ _).hom ≫ pullback.map _ _ _ _ (𝟙 _) s.snd f (Category.id_comp _).symm s.condition ≫ (gluing 𝒰 f g).ι i intro i j rw [← gluedLiftPullbackMap_fst_assoc, ← gluing_f, ← (gluing 𝒰 f g).glue_condition i j, gluing_t, gluing_f] simp_rw [← Category.assoc] congr 1 apply pullback.hom_ext <;> simp_rw [Category.assoc] · rw [t_fst_fst, gluedLiftPullbackMap_snd] congr 1 rw [← Iso.inv_comp_eq, pullbackSymmetry_inv_comp_snd, pullback.lift_fst, Category.comp_id] · rw [t_fst_snd, gluedLiftPullbackMap_fst_assoc, pullback.lift_snd, pullback.lift_snd] simp_rw [pullbackSymmetry_hom_comp_snd_assoc] exact pullback.condition_assoc _ #align algebraic_geometry.Scheme.pullback.glued_lift AlgebraicGeometry.Scheme.Pullback.gluedLift theorem gluedLift_p1 : gluedLift 𝒰 f g s ≫ p1 𝒰 f g = s.fst := by rw [← cancel_epi (𝒰.pullbackCover s.fst).fromGlued] apply Multicoequalizer.hom_ext intro b simp_rw [OpenCover.fromGlued, Multicoequalizer.π_desc_assoc, gluedLift, ← Category.assoc] simp_rw [(𝒰.pullbackCover s.fst).ι_glueMorphisms] simp [p1, pullback.condition] #align algebraic_geometry.Scheme.pullback.glued_lift_p1 AlgebraicGeometry.Scheme.Pullback.gluedLift_p1 theorem gluedLift_p2 : gluedLift 𝒰 f g s ≫ p2 𝒰 f g = s.snd := by rw [← cancel_epi (𝒰.pullbackCover s.fst).fromGlued] apply Multicoequalizer.hom_ext intro b simp_rw [OpenCover.fromGlued, Multicoequalizer.π_desc_assoc, gluedLift, ← Category.assoc] simp_rw [(𝒰.pullbackCover s.fst).ι_glueMorphisms] simp [p2, pullback.condition] #align algebraic_geometry.Scheme.pullback.glued_lift_p2 AlgebraicGeometry.Scheme.Pullback.gluedLift_p2 /-- (Implementation) The canonical map `(W ×[X] Uᵢ) ×[W] (Uⱼ ×[Z] Y) ⟶ (Uⱼ ×[Z] Y) ×[X] Uᵢ = V j i` where `W` is the glued fibred product. This is used in `lift_comp_ι`. -/ def pullbackFstιToV (i j : 𝒰.J) : pullback (pullback.fst : pullback (p1 𝒰 f g) (𝒰.map i) ⟶ _) ((gluing 𝒰 f g).ι j) ⟶ v 𝒰 f g j i := (pullbackSymmetry _ _ ≪≫ pullbackRightPullbackFstIso (p1 𝒰 f g) (𝒰.map i) _).hom ≫ (pullback.congrHom (Multicoequalizer.π_desc ..) rfl).hom #align algebraic_geometry.Scheme.pullback.pullback_fst_ι_to_V AlgebraicGeometry.Scheme.Pullback.pullbackFstιToV @[simp, reassoc] theorem pullbackFstιToV_fst (i j : 𝒰.J) : pullbackFstιToV 𝒰 f g i j ≫ pullback.fst = pullback.snd := by simp [pullbackFstιToV, p1] #align algebraic_geometry.Scheme.pullback.pullback_fst_ι_to_V_fst AlgebraicGeometry.Scheme.Pullback.pullbackFstιToV_fst @[simp, reassoc] theorem pullbackFstιToV_snd (i j : 𝒰.J) : pullbackFstιToV 𝒰 f g i j ≫ pullback.snd = pullback.fst ≫ pullback.snd := by simp [pullbackFstιToV, p1] #align algebraic_geometry.Scheme.pullback.pullback_fst_ι_to_V_snd AlgebraicGeometry.Scheme.Pullback.pullbackFstιToV_snd /-- We show that the map `W ×[X] Uᵢ ⟶ Uᵢ ×[Z] Y ⟶ W` is the first projection, where the first map is given by the lift of `W ×[X] Uᵢ ⟶ Uᵢ` and `W ×[X] Uᵢ ⟶ W ⟶ Y`. It suffices to show that the two map agrees when restricted onto `Uⱼ ×[Z] Y`. In this case, both maps factor through `V j i` via `pullback_fst_ι_to_V` -/ theorem lift_comp_ι (i : 𝒰.J) : pullback.lift pullback.snd (pullback.fst ≫ p2 𝒰 f g) (by rw [← pullback.condition_assoc, Category.assoc, p_comm]) ≫ (gluing 𝒰 f g).ι i = (pullback.fst : pullback (p1 𝒰 f g) (𝒰.map i) ⟶ _) := by apply ((gluing 𝒰 f g).openCover.pullbackCover pullback.fst).hom_ext intro j dsimp only [OpenCover.pullbackCover] trans pullbackFstιToV 𝒰 f g i j ≫ fV 𝒰 f g j i ≫ (gluing 𝒰 f g).ι _ · rw [← show _ = fV 𝒰 f g j i ≫ _ from (gluing 𝒰 f g).glue_condition j i] simp_rw [← Category.assoc] congr 1 rw [gluing_f, gluing_t] apply pullback.hom_ext <;> simp_rw [Category.assoc] · simp_rw [t_fst_fst, pullback.lift_fst, pullbackFstιToV_snd, GlueData.openCover_map] · simp_rw [t_fst_snd, pullback.lift_snd, pullbackFstιToV_fst_assoc, pullback.condition_assoc, GlueData.openCover_map, p2] simp · rw [pullback.condition, ← Category.assoc] simp_rw [pullbackFstιToV_fst, GlueData.openCover_map] #align algebraic_geometry.Scheme.pullback.lift_comp_ι AlgebraicGeometry.Scheme.Pullback.lift_comp_ι /-- The canonical isomorphism between `W ×[X] Uᵢ` and `Uᵢ ×[X] Y`. That is, the preimage of `Uᵢ` in `W` along `p1` is indeed `Uᵢ ×[X] Y`. -/ def pullbackP1Iso (i : 𝒰.J) : pullback (p1 𝒰 f g) (𝒰.map i) ≅ pullback (𝒰.map i ≫ f) g := by fconstructor · exact pullback.lift pullback.snd (pullback.fst ≫ p2 𝒰 f g) (by rw [← pullback.condition_assoc, Category.assoc, p_comm]) · apply pullback.lift ((gluing 𝒰 f g).ι i) pullback.fst rw [gluing_ι, p1, Multicoequalizer.π_desc] · apply pullback.hom_ext · simpa using lift_comp_ι 𝒰 f g i · simp_rw [Category.assoc, pullback.lift_snd, pullback.lift_fst, Category.id_comp] · apply pullback.hom_ext · simp_rw [Category.assoc, pullback.lift_fst, pullback.lift_snd, Category.id_comp] · simp [p2] #align algebraic_geometry.Scheme.pullback.pullback_p1_iso AlgebraicGeometry.Scheme.Pullback.pullbackP1Iso @[simp, reassoc] theorem pullbackP1Iso_hom_fst (i : 𝒰.J) : (pullbackP1Iso 𝒰 f g i).hom ≫ pullback.fst = pullback.snd := by simp_rw [pullbackP1Iso, pullback.lift_fst] #align algebraic_geometry.Scheme.pullback.pullback_p1_iso_hom_fst AlgebraicGeometry.Scheme.Pullback.pullbackP1Iso_hom_fst @[simp, reassoc] theorem pullbackP1Iso_hom_snd (i : 𝒰.J) : (pullbackP1Iso 𝒰 f g i).hom ≫ pullback.snd = pullback.fst ≫ p2 𝒰 f g := by simp_rw [pullbackP1Iso, pullback.lift_snd] #align algebraic_geometry.Scheme.pullback.pullback_p1_iso_hom_snd AlgebraicGeometry.Scheme.Pullback.pullbackP1Iso_hom_snd @[simp, reassoc] theorem pullbackP1Iso_inv_fst (i : 𝒰.J) : (pullbackP1Iso 𝒰 f g i).inv ≫ pullback.fst = (gluing 𝒰 f g).ι i := by simp_rw [pullbackP1Iso, pullback.lift_fst] #align algebraic_geometry.Scheme.pullback.pullback_p1_iso_inv_fst AlgebraicGeometry.Scheme.Pullback.pullbackP1Iso_inv_fst @[simp, reassoc]
Mathlib/AlgebraicGeometry/Pullbacks.lean
419
421
theorem pullbackP1Iso_inv_snd (i : 𝒰.J) : (pullbackP1Iso 𝒰 f g i).inv ≫ pullback.snd = pullback.fst := by
simp_rw [pullbackP1Iso, pullback.lift_snd]
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Order.CompleteLattice import Mathlib.Order.GaloisConnection import Mathlib.Data.Set.Lattice import Mathlib.Tactic.AdaptationNote #align_import data.rel from "leanprover-community/mathlib"@"706d88f2b8fdfeb0b22796433d7a6c1a010af9f2" /-! # Relations This file defines bundled relations. A relation between `α` and `β` is a function `α → β → Prop`. Relations are also known as set-valued functions, or partial multifunctions. ## Main declarations * `Rel α β`: Relation between `α` and `β`. * `Rel.inv`: `r.inv` is the `Rel β α` obtained by swapping the arguments of `r`. * `Rel.dom`: Domain of a relation. `x ∈ r.dom` iff there exists `y` such that `r x y`. * `Rel.codom`: Codomain, aka range, of a relation. `y ∈ r.codom` iff there exists `x` such that `r x y`. * `Rel.comp`: Relation composition. Note that the arguments order follows the `CategoryTheory/` one, so `r.comp s x z ↔ ∃ y, r x y ∧ s y z`. * `Rel.image`: Image of a set under a relation. `r.image s` is the set of `f x` over all `x ∈ s`. * `Rel.preimage`: Preimage of a set under a relation. Note that `r.preimage = r.inv.image`. * `Rel.core`: Core of a set. For `s : Set β`, `r.core s` is the set of `x : α` such that all `y` related to `x` are in `s`. * `Rel.restrict_domain`: Domain-restriction of a relation to a subtype. * `Function.graph`: Graph of a function as a relation. ## TODOs The `Rel.comp` function uses the notation `r • s`, rather than the more common `r ∘ s` for things named `comp`. This is because the latter is already used for function composition, and causes a clash. A better notation should be found, perhaps a variant of `r ∘r s` or `r; s`. -/ variable {α β γ : Type*} /-- A relation on `α` and `β`, aka a set-valued function, aka a partial multifunction -/ def Rel (α β : Type*) := α → β → Prop -- deriving CompleteLattice, Inhabited #align rel Rel -- Porting note: `deriving` above doesn't work. instance : CompleteLattice (Rel α β) := show CompleteLattice (α → β → Prop) from inferInstance instance : Inhabited (Rel α β) := show Inhabited (α → β → Prop) from inferInstance namespace Rel variable (r : Rel α β) -- Porting note: required for later theorems. @[ext] theorem ext {r s : Rel α β} : (∀ a, r a = s a) → r = s := funext /-- The inverse relation : `r.inv x y ↔ r y x`. Note that this is *not* a groupoid inverse. -/ def inv : Rel β α := flip r #align rel.inv Rel.inv theorem inv_def (x : α) (y : β) : r.inv y x ↔ r x y := Iff.rfl #align rel.inv_def Rel.inv_def theorem inv_inv : inv (inv r) = r := by ext x y rfl #align rel.inv_inv Rel.inv_inv /-- Domain of a relation -/ def dom := { x | ∃ y, r x y } #align rel.dom Rel.dom theorem dom_mono {r s : Rel α β} (h : r ≤ s) : dom r ⊆ dom s := fun a ⟨b, hx⟩ => ⟨b, h a b hx⟩ #align rel.dom_mono Rel.dom_mono /-- Codomain aka range of a relation -/ def codom := { y | ∃ x, r x y } #align rel.codom Rel.codom theorem codom_inv : r.inv.codom = r.dom := by ext x rfl #align rel.codom_inv Rel.codom_inv theorem dom_inv : r.inv.dom = r.codom := by ext x rfl #align rel.dom_inv Rel.dom_inv /-- Composition of relation; note that it follows the `CategoryTheory/` order of arguments. -/ def comp (r : Rel α β) (s : Rel β γ) : Rel α γ := fun x z => ∃ y, r x y ∧ s y z #align rel.comp Rel.comp -- Porting note: the original `∘` syntax can't be overloaded here, lean considers it ambiguous. /-- Local syntax for composition of relations. -/ local infixr:90 " • " => Rel.comp theorem comp_assoc {δ : Type*} (r : Rel α β) (s : Rel β γ) (t : Rel γ δ) : (r • s) • t = r • (s • t) := by unfold comp; ext (x w); constructor · rintro ⟨z, ⟨y, rxy, syz⟩, tzw⟩; exact ⟨y, rxy, z, syz, tzw⟩ · rintro ⟨y, rxy, z, syz, tzw⟩; exact ⟨z, ⟨y, rxy, syz⟩, tzw⟩ #align rel.comp_assoc Rel.comp_assoc @[simp] theorem comp_right_id (r : Rel α β) : r • @Eq β = r := by unfold comp ext y simp #align rel.comp_right_id Rel.comp_right_id @[simp] theorem comp_left_id (r : Rel α β) : @Eq α • r = r := by unfold comp ext x simp #align rel.comp_left_id Rel.comp_left_id @[simp] theorem comp_right_bot (r : Rel α β) : r • (⊥ : Rel β γ) = ⊥ := by ext x y simp [comp, Bot.bot] @[simp] theorem comp_left_bot (r : Rel α β) : (⊥ : Rel γ α) • r = ⊥ := by ext x y simp [comp, Bot.bot] @[simp] theorem comp_right_top (r : Rel α β) : r • (⊤ : Rel β γ) = fun x _ ↦ x ∈ r.dom := by ext x z simp [comp, Top.top, dom] @[simp] theorem comp_left_top (r : Rel α β) : (⊤ : Rel γ α) • r = fun _ y ↦ y ∈ r.codom := by ext x z simp [comp, Top.top, codom] theorem inv_id : inv (@Eq α) = @Eq α := by ext x y constructor <;> apply Eq.symm #align rel.inv_id Rel.inv_id theorem inv_comp (r : Rel α β) (s : Rel β γ) : inv (r • s) = inv s • inv r := by ext x z simp [comp, inv, flip, and_comm] #align rel.inv_comp Rel.inv_comp @[simp] theorem inv_bot : (⊥ : Rel α β).inv = (⊥ : Rel β α) := by #adaptation_note /-- nightly-2024-03-16: simp was `simp [Bot.bot, inv, flip]` -/ simp [Bot.bot, inv, Function.flip_def] @[simp] theorem inv_top : (⊤ : Rel α β).inv = (⊤ : Rel β α) := by #adaptation_note /-- nightly-2024-03-16: simp was `simp [Top.top, inv, flip]` -/ simp [Top.top, inv, Function.flip_def] /-- Image of a set under a relation -/ def image (s : Set α) : Set β := { y | ∃ x ∈ s, r x y } #align rel.image Rel.image theorem mem_image (y : β) (s : Set α) : y ∈ image r s ↔ ∃ x ∈ s, r x y := Iff.rfl #align rel.mem_image Rel.mem_image theorem image_subset : ((· ⊆ ·) ⇒ (· ⊆ ·)) r.image r.image := fun _ _ h _ ⟨x, xs, rxy⟩ => ⟨x, h xs, rxy⟩ #align rel.image_subset Rel.image_subset theorem image_mono : Monotone r.image := r.image_subset #align rel.image_mono Rel.image_mono theorem image_inter (s t : Set α) : r.image (s ∩ t) ⊆ r.image s ∩ r.image t := r.image_mono.map_inf_le s t #align rel.image_inter Rel.image_inter theorem image_union (s t : Set α) : r.image (s ∪ t) = r.image s ∪ r.image t := le_antisymm (fun _y ⟨x, xst, rxy⟩ => xst.elim (fun xs => Or.inl ⟨x, ⟨xs, rxy⟩⟩) fun xt => Or.inr ⟨x, ⟨xt, rxy⟩⟩) (r.image_mono.le_map_sup s t) #align rel.image_union Rel.image_union @[simp] theorem image_id (s : Set α) : image (@Eq α) s = s := by ext x simp [mem_image] #align rel.image_id Rel.image_id theorem image_comp (s : Rel β γ) (t : Set α) : image (r • s) t = image s (image r t) := by ext z; simp only [mem_image]; constructor · rintro ⟨x, xt, y, rxy, syz⟩; exact ⟨y, ⟨x, xt, rxy⟩, syz⟩ · rintro ⟨y, ⟨x, xt, rxy⟩, syz⟩; exact ⟨x, xt, y, rxy, syz⟩ #align rel.image_comp Rel.image_comp theorem image_univ : r.image Set.univ = r.codom := by ext y simp [mem_image, codom] #align rel.image_univ Rel.image_univ @[simp] theorem image_empty : r.image ∅ = ∅ := by ext x simp [mem_image] @[simp] theorem image_bot (s : Set α) : (⊥ : Rel α β).image s = ∅ := by rw [Set.eq_empty_iff_forall_not_mem] intro x h simp [mem_image, Bot.bot] at h @[simp] theorem image_top {s : Set α} (h : Set.Nonempty s) : (⊤ : Rel α β).image s = Set.univ := Set.eq_univ_of_forall fun x ↦ ⟨h.some, by simp [h.some_mem, Top.top]⟩ /-- Preimage of a set under a relation `r`. Same as the image of `s` under `r.inv` -/ def preimage (s : Set β) : Set α := r.inv.image s #align rel.preimage Rel.preimage theorem mem_preimage (x : α) (s : Set β) : x ∈ r.preimage s ↔ ∃ y ∈ s, r x y := Iff.rfl #align rel.mem_preimage Rel.mem_preimage theorem preimage_def (s : Set β) : preimage r s = { x | ∃ y ∈ s, r x y } := Set.ext fun _ => mem_preimage _ _ _ #align rel.preimage_def Rel.preimage_def theorem preimage_mono {s t : Set β} (h : s ⊆ t) : r.preimage s ⊆ r.preimage t := image_mono _ h #align rel.preimage_mono Rel.preimage_mono theorem preimage_inter (s t : Set β) : r.preimage (s ∩ t) ⊆ r.preimage s ∩ r.preimage t := image_inter _ s t #align rel.preimage_inter Rel.preimage_inter theorem preimage_union (s t : Set β) : r.preimage (s ∪ t) = r.preimage s ∪ r.preimage t := image_union _ s t #align rel.preimage_union Rel.preimage_union theorem preimage_id (s : Set α) : preimage (@Eq α) s = s := by simp only [preimage, inv_id, image_id] #align rel.preimage_id Rel.preimage_id theorem preimage_comp (s : Rel β γ) (t : Set γ) : preimage (r • s) t = preimage r (preimage s t) := by simp only [preimage, inv_comp, image_comp] #align rel.preimage_comp Rel.preimage_comp theorem preimage_univ : r.preimage Set.univ = r.dom := by rw [preimage, image_univ, codom_inv] #align rel.preimage_univ Rel.preimage_univ @[simp] theorem preimage_empty : r.preimage ∅ = ∅ := by rw [preimage, image_empty] @[simp] theorem preimage_inv (s : Set α) : r.inv.preimage s = r.image s := by rw [preimage, inv_inv] @[simp] theorem preimage_bot (s : Set β) : (⊥ : Rel α β).preimage s = ∅ := by rw [preimage, inv_bot, image_bot] @[simp] theorem preimage_top {s : Set β} (h : Set.Nonempty s) : (⊤ : Rel α β).preimage s = Set.univ := by rwa [← inv_top, preimage, inv_inv, image_top] theorem image_eq_dom_of_codomain_subset {s : Set β} (h : r.codom ⊆ s) : r.preimage s = r.dom := by rw [← preimage_univ] apply Set.eq_of_subset_of_subset · exact image_subset _ (Set.subset_univ _) · intro x hx simp only [mem_preimage, Set.mem_univ, true_and] at hx rcases hx with ⟨y, ryx⟩ have hy : y ∈ s := h ⟨x, ryx⟩ exact ⟨y, ⟨hy, ryx⟩⟩ theorem preimage_eq_codom_of_domain_subset {s : Set α} (h : r.dom ⊆ s) : r.image s = r.codom := by apply r.inv.image_eq_dom_of_codomain_subset (by rwa [← codom_inv] at h) theorem image_inter_dom_eq (s : Set α) : r.image (s ∩ r.dom) = r.image s := by apply Set.eq_of_subset_of_subset · apply r.image_mono (by simp) · intro x h rw [mem_image] at * rcases h with ⟨y, hy, ryx⟩ use y suffices h : y ∈ r.dom by simp_all only [Set.mem_inter_iff, and_self] rw [dom, Set.mem_setOf_eq] use x @[simp] theorem preimage_inter_codom_eq (s : Set β) : r.preimage (s ∩ r.codom) = r.preimage s := by rw [← dom_inv, preimage, preimage, image_inter_dom_eq] theorem inter_dom_subset_preimage_image (s : Set α) : s ∩ r.dom ⊆ r.preimage (r.image s) := by intro x hx simp only [Set.mem_inter_iff, dom] at hx rcases hx with ⟨hx, ⟨y, rxy⟩⟩ use y simp only [image, Set.mem_setOf_eq] exact ⟨⟨x, hx, rxy⟩, rxy⟩ theorem image_preimage_subset_inter_codom (s : Set β) : s ∩ r.codom ⊆ r.image (r.preimage s) := by rw [← dom_inv, ← preimage_inv] apply inter_dom_subset_preimage_image /-- Core of a set `s : Set β` w.r.t `r : Rel α β` is the set of `x : α` that are related *only* to elements of `s`. Other generalization of `Function.preimage`. -/ def core (s : Set β) := { x | ∀ y, r x y → y ∈ s } #align rel.core Rel.core theorem mem_core (x : α) (s : Set β) : x ∈ r.core s ↔ ∀ y, r x y → y ∈ s := Iff.rfl #align rel.mem_core Rel.mem_core theorem core_subset : ((· ⊆ ·) ⇒ (· ⊆ ·)) r.core r.core := fun _s _t h _x h' y rxy => h (h' y rxy) #align rel.core_subset Rel.core_subset theorem core_mono : Monotone r.core := r.core_subset #align rel.core_mono Rel.core_mono theorem core_inter (s t : Set β) : r.core (s ∩ t) = r.core s ∩ r.core t := Set.ext (by simp [mem_core, imp_and, forall_and]) #align rel.core_inter Rel.core_inter theorem core_union (s t : Set β) : r.core s ∪ r.core t ⊆ r.core (s ∪ t) := r.core_mono.le_map_sup s t #align rel.core_union Rel.core_union @[simp] theorem core_univ : r.core Set.univ = Set.univ := Set.ext (by simp [mem_core]) #align rel.core_univ Rel.core_univ theorem core_id (s : Set α) : core (@Eq α) s = s := by simp [core] #align rel.core_id Rel.core_id theorem core_comp (s : Rel β γ) (t : Set γ) : core (r • s) t = core r (core s t) := by ext x; simp only [core, comp, forall_exists_index, and_imp, Set.mem_setOf_eq]; constructor · exact fun h y rxy z => h z y rxy · exact fun h z y rzy => h y rzy z #align rel.core_comp Rel.core_comp /-- Restrict the domain of a relation to a subtype. -/ def restrictDomain (s : Set α) : Rel { x // x ∈ s } β := fun x y => r x.val y #align rel.restrict_domain Rel.restrictDomain theorem image_subset_iff (s : Set α) (t : Set β) : image r s ⊆ t ↔ s ⊆ core r t := Iff.intro (fun h x xs _y rxy => h ⟨x, xs, rxy⟩) fun h y ⟨_x, xs, rxy⟩ => h xs y rxy #align rel.image_subset_iff Rel.image_subset_iff theorem image_core_gc : GaloisConnection r.image r.core := image_subset_iff _ #align rel.image_core_gc Rel.image_core_gc end Rel namespace Function /-- The graph of a function as a relation. -/ def graph (f : α → β) : Rel α β := fun x y => f x = y #align function.graph Function.graph @[simp] lemma graph_def (f : α → β) (x y) : f.graph x y ↔ (f x = y) := Iff.rfl theorem graph_injective : Injective (graph : (α → β) → Rel α β) := by intro _ g h ext x have h2 := congr_fun₂ h x (g x) simp only [graph_def, eq_iff_iff, iff_true] at h2 exact h2 @[simp] lemma graph_inj {f g : α → β} : f.graph = g.graph ↔ f = g := graph_injective.eq_iff theorem graph_id : graph id = @Eq α := by simp (config := { unfoldPartialApp := true }) [graph] theorem graph_comp {f : β → γ} {g : α → β} : graph (f ∘ g) = Rel.comp (graph g) (graph f) := by ext x y simp [Rel.comp] end Function
Mathlib/Data/Rel.lean
392
394
theorem Equiv.graph_inv (f : α ≃ β) : (f.symm : β → α).graph = Rel.inv (f : α → β).graph := by
ext x y aesop (add norm Rel.inv_def)
/- Copyright (c) 2022 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer, Kevin Klinge, Andrew Yang -/ import Mathlib.RingTheory.OreLocalization.OreSet import Mathlib.Algebra.Group.Submonoid.Operations #align_import ring_theory.ore_localization.basic from "leanprover-community/mathlib"@"861a26926586cd46ff80264d121cdb6fa0e35cc1" /-! # Localization over left Ore sets. This file defines the localization of a monoid over a left Ore set and proves its universal mapping property. ## Notations Introduces the notation `R[S⁻¹]` for the Ore localization of a monoid `R` at a right Ore subset `S`. Also defines a new heterogeneous division notation `r /ₒ s` for a numerator `r : R` and a denominator `s : S`. ## References * <https://ncatlab.org/nlab/show/Ore+localization> * [Zoran Škoda, *Noncommutative localization in noncommutative geometry*][skoda2006] ## Tags localization, Ore, non-commutative -/ universe u open OreLocalization namespace OreLocalization variable {R : Type*} [Monoid R] (S : Submonoid R) [OreSet S] (X) [MulAction R X] /-- The setoid on `R × S` used for the Ore localization. -/ @[to_additive AddOreLocalization.oreEqv "The setoid on `R × S` used for the Ore localization."] def oreEqv : Setoid (X × S) where r rs rs' := ∃ (u : S) (v : R), u • rs'.1 = v • rs.1 ∧ u * rs'.2 = v * rs.2 iseqv := by refine ⟨fun _ => ⟨1, 1, by simp⟩, ?_, ?_⟩ · rintro ⟨r, s⟩ ⟨r', s'⟩ ⟨u, v, hru, hsu⟩; dsimp only at * rcases oreCondition (s : R) s' with ⟨r₂, s₂, h₁⟩ rcases oreCondition r₂ u with ⟨r₃, s₃, h₂⟩ have : r₃ * v * s = s₃ * s₂ * s := by -- Porting note: the proof used `assoc_rw` rw [mul_assoc _ (s₂ : R), h₁, ← mul_assoc, h₂, mul_assoc, ← hsu, ← mul_assoc] rcases ore_right_cancel (r₃ * v) (s₃ * s₂) s this with ⟨w, hw⟩ refine ⟨w * (s₃ * s₂), w * (r₃ * u), ?_, ?_⟩ <;> simp only [Submonoid.coe_mul, Submonoid.smul_def, ← hw] · simp only [mul_smul, hru, ← Submonoid.smul_def] · simp only [mul_assoc, hsu] · rintro ⟨r₁, s₁⟩ ⟨r₂, s₂⟩ ⟨r₃, s₃⟩ ⟨u, v, hur₁, hs₁u⟩ ⟨u', v', hur₂, hs₂u⟩ rcases oreCondition v' u with ⟨r', s', h⟩; dsimp only at * refine ⟨s' * u', r' * v, ?_, ?_⟩ <;> simp only [Submonoid.smul_def, Submonoid.coe_mul, mul_smul, mul_assoc] at * · rw [hur₂, smul_smul, h, mul_smul, hur₁] · rw [hs₂u, ← mul_assoc, h, mul_assoc, hs₁u] #align ore_localization.ore_eqv OreLocalization.oreEqv end OreLocalization /-- The Ore localization of a monoid and a submonoid fulfilling the Ore condition. -/ @[to_additive AddOreLocalization "The Ore localization of an additive monoid and a submonoid fulfilling the Ore condition."] def OreLocalization {R : Type*} [Monoid R] (S : Submonoid R) [OreSet S] (X : Type*) [MulAction R X] := Quotient (OreLocalization.oreEqv S X) #align ore_localization OreLocalization namespace OreLocalization section Monoid variable {R : Type*} [Monoid R] {S : Submonoid R} variable (R S) [OreSet S] @[inherit_doc OreLocalization] scoped syntax:1075 term noWs atomic("[" term "⁻¹" noWs "]") : term macro_rules | `($R[$S⁻¹]) => ``(OreLocalization $S $R) attribute [local instance] oreEqv variable {R S} variable {X} [MulAction R X] /-- The division in the Ore localization `X[S⁻¹]`, as a fraction of an element of `X` and `S`. -/ @[to_additive "The subtraction in the Ore localization, as a difference of an element of `X` and `S`."] def oreDiv (r : X) (s : S) : X[S⁻¹] := Quotient.mk' (r, s) #align ore_localization.ore_div OreLocalization.oreDiv @[inherit_doc] infixl:70 " /ₒ " => oreDiv @[inherit_doc] infixl:65 " -ₒ " => _root_.AddOreLocalization.oreSub @[to_additive (attr := elab_as_elim)] protected theorem ind {β : X[S⁻¹] → Prop} (c : ∀ (r : X) (s : S), β (r /ₒ s)) : ∀ q, β q := by apply Quotient.ind rintro ⟨r, s⟩ exact c r s #align ore_localization.ind OreLocalization.ind @[to_additive] theorem oreDiv_eq_iff {r₁ r₂ : X} {s₁ s₂ : S} : r₁ /ₒ s₁ = r₂ /ₒ s₂ ↔ ∃ (u : S) (v : R), u • r₂ = v • r₁ ∧ u * s₂ = v * s₁ := Quotient.eq'' #align ore_localization.ore_div_eq_iff OreLocalization.oreDiv_eq_iff /-- A fraction `r /ₒ s` is equal to its expansion by an arbitrary factor `t` if `t * s ∈ S`. -/ @[to_additive "A difference `r -ₒ s` is equal to its expansion by an arbitrary translation `t` if `t + s ∈ S`."] protected theorem expand (r : X) (s : S) (t : R) (hst : t * (s : R) ∈ S) : r /ₒ s = t • r /ₒ ⟨t * s, hst⟩ := by apply Quotient.sound exact ⟨s, s * t, by rw [mul_smul, Submonoid.smul_def], by rw [← mul_assoc]⟩ #align ore_localization.expand OreLocalization.expand /-- A fraction is equal to its expansion by a factor from `S`. -/ @[to_additive "A difference is equal to its expansion by a summand from `S`."] protected theorem expand' (r : X) (s s' : S) : r /ₒ s = s' • r /ₒ (s' * s) := OreLocalization.expand r s s' (by norm_cast; apply SetLike.coe_mem) #align ore_localization.expand' OreLocalization.expand' /-- Fractions which differ by a factor of the numerator can be proven equal if those factors expand to equal elements of `R`. -/ @[to_additive "Differences whose minuends differ by a common summand can be proven equal if those summands expand to equal elements of `R`."] protected theorem eq_of_num_factor_eq {r r' r₁ r₂ : R} {s t : S} (h : t * r = t * r') : r₁ * r * r₂ /ₒ s = r₁ * r' * r₂ /ₒ s := by rcases oreCondition r₁ t with ⟨r₁', t', hr₁⟩ rw [OreLocalization.expand' _ s t', OreLocalization.expand' _ s t'] congr 1 -- Porting note (#11215): TODO: use `assoc_rw`? calc (t' : R) * (r₁ * r * r₂) = t' * r₁ * r * r₂ := by simp [← mul_assoc] _ = r₁' * t * r * r₂ := by rw [hr₁] _ = r₁' * (t * r) * r₂ := by simp [← mul_assoc] _ = r₁' * (t * r') * r₂ := by rw [h] _ = r₁' * t * r' * r₂ := by simp [← mul_assoc] _ = t' * r₁ * r' * r₂ := by rw [hr₁] _ = t' * (r₁ * r' * r₂) := by simp [← mul_assoc] #align ore_localization.eq_of_num_factor_eq OreLocalization.eq_of_num_factor_eq /-- A function or predicate over `X` and `S` can be lifted to `X[S⁻¹]` if it is invariant under expansion on the left. -/ @[to_additive "A function or predicate over `X` and `S` can be lifted to the localizaton if it is invariant under expansion on the left."] def liftExpand {C : Sort*} (P : X → S → C) (hP : ∀ (r : X) (t : R) (s : S) (ht : t * s ∈ S), P r s = P (t • r) ⟨t * s, ht⟩) : X[S⁻¹] → C := Quotient.lift (fun p : X × S => P p.1 p.2) fun (r₁, s₁) (r₂, s₂) ⟨u, v, hr₂, hs₂⟩ => by dsimp at * have s₁vS : v * s₁ ∈ S := by rw [← hs₂, ← S.coe_mul] exact SetLike.coe_mem (u * s₂) replace hs₂ : u * s₂ = ⟨_, s₁vS⟩ := by ext; simp [hs₂] rw [hP r₁ v s₁ s₁vS, hP r₂ u s₂ (by norm_cast; rwa [hs₂]), ← hr₂] simp only [← hs₂]; rfl #align ore_localization.lift_expand OreLocalization.liftExpand @[to_additive (attr := simp)] theorem liftExpand_of {C : Sort*} {P : X → S → C} {hP : ∀ (r : X) (t : R) (s : S) (ht : t * s ∈ S), P r s = P (t • r) ⟨t * s, ht⟩} (r : X) (s : S) : liftExpand P hP (r /ₒ s) = P r s := rfl #align ore_localization.lift_expand_of OreLocalization.liftExpand_of /-- A version of `liftExpand` used to simultaneously lift functions with two arguments in `X[S⁻¹]`. -/ @[to_additive "A version of `liftExpand` used to simultaneously lift functions with two arguments"] def lift₂Expand {C : Sort*} (P : X → S → X → S → C) (hP : ∀ (r₁ : X) (t₁ : R) (s₁ : S) (ht₁ : t₁ * s₁ ∈ S) (r₂ : X) (t₂ : R) (s₂ : S) (ht₂ : t₂ * s₂ ∈ S), P r₁ s₁ r₂ s₂ = P (t₁ • r₁) ⟨t₁ * s₁, ht₁⟩ (t₂ • r₂) ⟨t₂ * s₂, ht₂⟩) : X[S⁻¹] → X[S⁻¹] → C := liftExpand (fun r₁ s₁ => liftExpand (P r₁ s₁) fun r₂ t₂ s₂ ht₂ => by have := hP r₁ 1 s₁ (by simp) r₂ t₂ s₂ ht₂ simp [this]) fun r₁ t₁ s₁ ht₁ => by ext x; induction' x using OreLocalization.ind with r₂ s₂ dsimp only rw [liftExpand_of, liftExpand_of, hP r₁ t₁ s₁ ht₁ r₂ 1 s₂ (by simp)]; simp #align ore_localization.lift₂_expand OreLocalization.lift₂Expand @[to_additive (attr := simp)] theorem lift₂Expand_of {C : Sort*} {P : X → S → X → S → C} {hP : ∀ (r₁ : X) (t₁ : R) (s₁ : S) (ht₁ : t₁ * s₁ ∈ S) (r₂ : X) (t₂ : R) (s₂ : S) (ht₂ : t₂ * s₂ ∈ S), P r₁ s₁ r₂ s₂ = P (t₁ • r₁) ⟨t₁ * s₁, ht₁⟩ (t₂ • r₂) ⟨t₂ * s₂, ht₂⟩} (r₁ : X) (s₁ : S) (r₂ : X) (s₂ : S) : lift₂Expand P hP (r₁ /ₒ s₁) (r₂ /ₒ s₂) = P r₁ s₁ r₂ s₂ := rfl #align ore_localization.lift₂_expand_of OreLocalization.lift₂Expand_of @[to_additive] private def smul' (r₁ : R) (s₁ : S) (r₂ : X) (s₂ : S) : X[S⁻¹] := oreNum r₁ s₂ • r₂ /ₒ (oreDenom r₁ s₂ * s₁) @[to_additive] private theorem smul'_char (r₁ : R) (r₂ : X) (s₁ s₂ : S) (u : S) (v : R) (huv : u * r₁ = v * s₂) : OreLocalization.smul' r₁ s₁ r₂ s₂ = v • r₂ /ₒ (u * s₁) := by -- Porting note: `assoc_rw` was not ported yet simp only [smul'] have h₀ := ore_eq r₁ s₂; set v₀ := oreNum r₁ s₂; set u₀ := oreDenom r₁ s₂ rcases oreCondition (u₀ : R) u with ⟨r₃, s₃, h₃⟩ have := calc r₃ * v * s₂ = r₃ * (u * r₁) := by rw [mul_assoc, ← huv] _ = s₃ * (u₀ * r₁) := by rw [← mul_assoc, ← mul_assoc, h₃] _ = s₃ * v₀ * s₂ := by rw [mul_assoc, h₀] rcases ore_right_cancel _ _ _ this with ⟨s₄, hs₄⟩ symm; rw [oreDiv_eq_iff] use s₄ * s₃ use s₄ * r₃ simp only [Submonoid.coe_mul, Submonoid.smul_def, smul_eq_mul] constructor · rw [smul_smul, mul_assoc (c := v₀), ← hs₄] simp only [smul_smul, mul_assoc] · rw [← mul_assoc (b := (u₀ : R)), mul_assoc (c := (u₀ : R)), h₃] simp only [mul_assoc] /-- The multiplication on the Ore localization of monoids. -/ @[to_additive] private def smul'' (r : R) (s : S) : X[S⁻¹] → X[S⁻¹] := liftExpand (smul' r s) fun r₁ r₂ s' hs => by rcases oreCondition r s' with ⟨r₁', s₁', h₁⟩ rw [smul'_char _ _ _ _ _ _ h₁] rcases oreCondition r ⟨_, hs⟩ with ⟨r₂', s₂', h₂⟩ rw [smul'_char _ _ _ _ _ _ h₂] rcases oreCondition (s₁' : R) (s₂') with ⟨r₃', s₃', h₃⟩ have : s₃' * r₁' * s' = (r₃' * r₂' * r₂) * s' := by rw [mul_assoc, ← h₁, ← mul_assoc, h₃, mul_assoc, h₂] simp [mul_assoc] rcases ore_right_cancel _ _ _ this with ⟨s₄', h₄⟩ have : (s₄' * r₃') * (s₂' * s) ∈ S := by rw [mul_assoc, ← mul_assoc r₃', ← h₃] exact (s₄' * (s₃' * s₁' * s)).2 rw [OreLocalization.expand' _ _ (s₄' * s₃'), OreLocalization.expand _ (s₂' * s) _ this] simp only [Submonoid.smul_def, Submonoid.coe_mul, smul_smul, mul_assoc, h₄] congr 1 ext; simp only [Submonoid.coe_mul, ← mul_assoc] rw [mul_assoc (s₄' : R), h₃, ← mul_assoc] /-- The scalar multiplication on the Ore localization of monoids. -/ @[to_additive "the vector addition on the Ore localization of additive monoids."] protected def smul : R[S⁻¹] → X[S⁻¹] → X[S⁻¹] := liftExpand smul'' fun r₁ r₂ s hs => by ext x induction' x using OreLocalization.ind with x s₂ show OreLocalization.smul' r₁ s x s₂ = OreLocalization.smul' (r₂ * r₁) ⟨_, hs⟩ x s₂ rcases oreCondition r₁ s₂ with ⟨r₁', s₁', h₁⟩ rw [smul'_char _ _ _ _ _ _ h₁] rcases oreCondition (r₂ * r₁) s₂ with ⟨r₂', s₂', h₂⟩ rw [smul'_char _ _ _ _ _ _ h₂] rcases oreCondition (s₂' * r₂) (s₁') with ⟨r₃', s₃', h₃⟩ have : s₃' * r₂' * s₂ = r₃' * r₁' * s₂ := by rw [mul_assoc, ← h₂, ← mul_assoc _ r₂, ← mul_assoc, h₃, mul_assoc, h₁, mul_assoc] rcases ore_right_cancel _ _ _ this with ⟨s₄', h₄⟩ have : (s₄' * r₃') * (s₁' * s) ∈ S := by rw [← mul_assoc, mul_assoc _ r₃', ← h₃, ← mul_assoc, ← mul_assoc, mul_assoc] exact mul_mem (s₄' * s₃' * s₂').2 hs rw [OreLocalization.expand' (r₂' • x) _ (s₄' * s₃'), OreLocalization.expand _ _ _ this] simp only [Submonoid.smul_def, Submonoid.coe_mul, smul_smul, mul_assoc, h₄] congr 1 ext; simp only [Submonoid.coe_mul, ← mul_assoc] rw [mul_assoc _ r₃', ← h₃, ← mul_assoc, ← mul_assoc] #align ore_localization.mul OreLocalization.smul @[to_additive] instance : SMul R[S⁻¹] X[S⁻¹] := ⟨OreLocalization.smul⟩ @[to_additive] instance : Mul R[S⁻¹] := ⟨OreLocalization.smul⟩ @[to_additive] theorem oreDiv_smul_oreDiv {r₁ : R} {r₂ : X} {s₁ s₂ : S} : (r₁ /ₒ s₁) • (r₂ /ₒ s₂) = oreNum r₁ s₂ • r₂ /ₒ (oreDenom r₁ s₂ * s₁) := rfl @[to_additive] theorem oreDiv_mul_oreDiv {r₁ : R} {r₂ : R} {s₁ s₂ : S} : (r₁ /ₒ s₁) * (r₂ /ₒ s₂) = oreNum r₁ s₂ * r₂ /ₒ (oreDenom r₁ s₂ * s₁) := rfl #align ore_localization.ore_div_mul_ore_div OreLocalization.oreDiv_mul_oreDiv /-- A characterization lemma for the scalar multiplication on the Ore localization, allowing for a choice of Ore numerator and Ore denominator. -/ @[to_additive "A characterization lemma for the vector addition on the Ore localization, allowing for a choice of Ore minuend and Ore subtrahend."] theorem oreDiv_smul_char (r₁ : R) (r₂ : X) (s₁ s₂ : S) (r' : R) (s' : S) (huv : s' * r₁ = r' * s₂) : (r₁ /ₒ s₁) • (r₂ /ₒ s₂) = r' • r₂ /ₒ (s' * s₁) := smul'_char r₁ r₂ s₁ s₂ s' r' huv /-- A characterization lemma for the multiplication on the Ore localization, allowing for a choice of Ore numerator and Ore denominator. -/ @[to_additive "A characterization lemma for the addition on the Ore localization, allowing for a choice of Ore minuend and Ore subtrahend."] theorem oreDiv_mul_char (r₁ r₂ : R) (s₁ s₂ : S) (r' : R) (s' : S) (huv : s' * r₁ = r' * s₂) : r₁ /ₒ s₁ * (r₂ /ₒ s₂) = r' * r₂ /ₒ (s' * s₁) := smul'_char r₁ r₂ s₁ s₂ s' r' huv #align ore_localization.ore_div_mul_char OreLocalization.oreDiv_mul_char /-- Another characterization lemma for the scalar multiplication on the Ore localizaion delivering Ore witnesses and conditions bundled in a sigma type. -/ @[to_additive "Another characterization lemma for the vector addition on the Ore localizaion delivering Ore witnesses and conditions bundled in a sigma type."] def oreDivSMulChar' (r₁ : R) (r₂ : X) (s₁ s₂ : S) : Σ'r' : R, Σ's' : S, s' * r₁ = r' * s₂ ∧ (r₁ /ₒ s₁) • (r₂ /ₒ s₂) = r' • r₂ /ₒ (s' * s₁) := ⟨oreNum r₁ s₂, oreDenom r₁ s₂, ore_eq r₁ s₂, oreDiv_smul_oreDiv⟩ /-- Another characterization lemma for the multiplication on the Ore localizaion delivering Ore witnesses and conditions bundled in a sigma type. -/ @[to_additive "Another characterization lemma for the addition on the Ore localizaion delivering Ore witnesses and conditions bundled in a sigma type."] def oreDivMulChar' (r₁ r₂ : R) (s₁ s₂ : S) : Σ'r' : R, Σ's' : S, s' * r₁ = r' * s₂ ∧ r₁ /ₒ s₁ * (r₂ /ₒ s₂) = r' * r₂ /ₒ (s' * s₁) := ⟨oreNum r₁ s₂, oreDenom r₁ s₂, ore_eq r₁ s₂, oreDiv_mul_oreDiv⟩ #align ore_localization.ore_div_mul_char' OreLocalization.oreDivMulChar' @[to_additive AddOreLocalization.instZeroAddOreLocalization] instance : One R[S⁻¹] := ⟨1 /ₒ 1⟩ @[to_additive] protected theorem one_def : (1 : R[S⁻¹]) = 1 /ₒ 1 := rfl #align ore_localization.one_def OreLocalization.one_def @[to_additive] instance : Inhabited R[S⁻¹] := ⟨1⟩ @[to_additive (attr := simp)] protected theorem div_eq_one' {r : R} (hr : r ∈ S) : r /ₒ ⟨r, hr⟩ = 1 := by rw [OreLocalization.one_def, oreDiv_eq_iff] exact ⟨⟨r, hr⟩, 1, by simp, by simp⟩ #align ore_localization.div_eq_one' OreLocalization.div_eq_one' @[to_additive (attr := simp)] protected theorem div_eq_one {s : S} : (s : R) /ₒ s = 1 := OreLocalization.div_eq_one' _ #align ore_localization.div_eq_one OreLocalization.div_eq_one @[to_additive] protected theorem one_smul (x : X[S⁻¹]) : (1 : R[S⁻¹]) • x = x := by induction' x using OreLocalization.ind with r s simp [OreLocalization.one_def, oreDiv_smul_char 1 r 1 s 1 s (by simp)] @[to_additive] protected theorem one_mul (x : R[S⁻¹]) : 1 * x = x := OreLocalization.one_smul x #align ore_localization.one_mul OreLocalization.one_mul @[to_additive] protected theorem mul_one (x : R[S⁻¹]) : x * 1 = x := by induction' x using OreLocalization.ind with r s simp [OreLocalization.one_def, oreDiv_mul_char r (1 : R) s (1 : S) r 1 (by simp)] #align ore_localization.mul_one OreLocalization.mul_one @[to_additive] protected theorem mul_smul (x y : R[S⁻¹]) (z : X[S⁻¹]) : (x * y) • z = x • y • z := by -- Porting note: `assoc_rw` was not ported yet induction' x using OreLocalization.ind with r₁ s₁ induction' y using OreLocalization.ind with r₂ s₂ induction' z using OreLocalization.ind with r₃ s₃ rcases oreDivMulChar' r₁ r₂ s₁ s₂ with ⟨ra, sa, ha, ha'⟩; rw [ha']; clear ha' rcases oreDivSMulChar' r₂ r₃ s₂ s₃ with ⟨rb, sb, hb, hb'⟩; rw [hb']; clear hb' rcases oreCondition ra sb with ⟨rc, sc, hc⟩ rw [oreDiv_smul_char (ra * r₂) r₃ (sa * s₁) s₃ (rc * rb) sc]; swap · rw [← mul_assoc _ ra, hc, mul_assoc, hb, ← mul_assoc] rw [← mul_assoc, mul_smul] symm; apply oreDiv_smul_char rw [Submonoid.coe_mul, Submonoid.coe_mul, ← mul_assoc, ← hc, mul_assoc _ ra, ← ha, mul_assoc] @[to_additive] protected theorem mul_assoc (x y z : R[S⁻¹]) : x * y * z = x * (y * z) := OreLocalization.mul_smul x y z #align ore_localization.mul_assoc OreLocalization.mul_assoc @[to_additive] instance : Monoid R[S⁻¹] where one_mul := OreLocalization.one_mul mul_one := OreLocalization.mul_one mul_assoc := OreLocalization.mul_assoc @[to_additive] instance instMulActionOreLocalization : MulAction R[S⁻¹] X[S⁻¹] where one_smul := OreLocalization.one_smul mul_smul := OreLocalization.mul_smul @[to_additive] protected theorem mul_inv (s s' : S) : ((s : R) /ₒ s') * ((s' : R) /ₒ s) = 1 := by simp [oreDiv_mul_char (s : R) s' s' s 1 1 (by simp)] #align ore_localization.mul_inv OreLocalization.mul_inv @[to_additive (attr := simp)] protected theorem one_div_smul {r : X} {s t : S} : ((1 : R) /ₒ t) • (r /ₒ s) = r /ₒ (s * t) := by simp [oreDiv_smul_char 1 r t s 1 s (by simp)] @[to_additive (attr := simp)] protected theorem one_div_mul {r : R} {s t : S} : (1 /ₒ t) * (r /ₒ s) = r /ₒ (s * t) := by simp [oreDiv_mul_char 1 r t s 1 s (by simp)] #align ore_localization.mul_one_div OreLocalization.one_div_mul @[to_additive (attr := simp)] protected theorem smul_cancel {r : X} {s t : S} : ((s : R) /ₒ t) • (r /ₒ s) = r /ₒ t := by simp [oreDiv_smul_char s.1 r t s 1 1 (by simp)] @[to_additive (attr := simp)] protected theorem mul_cancel {r : R} {s t : S} : ((s : R) /ₒ t) * (r /ₒ s) = r /ₒ t := by simp [oreDiv_mul_char s.1 r t s 1 1 (by simp)] #align ore_localization.mul_cancel OreLocalization.mul_cancel @[to_additive (attr := simp)] protected theorem smul_cancel' {r₁ : R} {r₂ : X} {s t : S} : ((r₁ * s) /ₒ t) • (r₂ /ₒ s) = (r₁ • r₂) /ₒ t := by simp [oreDiv_smul_char (r₁ * s) r₂ t s r₁ 1 (by simp)] @[to_additive (attr := simp)] protected theorem mul_cancel' {r₁ r₂ : R} {s t : S} : ((r₁ * s) /ₒ t) * (r₂ /ₒ s) = (r₁ * r₂) /ₒ t := by simp [oreDiv_mul_char (r₁ * s) r₂ t s r₁ 1 (by simp)] #align ore_localization.mul_cancel' OreLocalization.mul_cancel' @[to_additive (attr := simp)] theorem smul_div_one {p : R} {r : X} {s : S} : (p /ₒ s) • (r /ₒ 1) = (p • r) /ₒ s := by simp [oreDiv_smul_char p r s 1 p 1 (by simp)] @[to_additive (attr := simp)] theorem mul_div_one {p r : R} {s : S} : (p /ₒ s) * (r /ₒ 1) = (p * r) /ₒ s := by --TODO use coercion r ↦ r /ₒ 1 simp [oreDiv_mul_char p r s 1 p 1 (by simp)] #align ore_localization.div_one_mul OreLocalization.mul_div_one @[to_additive] instance : SMul R X[S⁻¹] where smul r := liftExpand (fun x s ↦ oreNum r s • x /ₒ (oreDenom r s)) (by intro x r' s h dsimp only rw [← mul_one (oreDenom r s), ← oreDiv_smul_oreDiv, ← mul_one (oreDenom _ _), ← oreDiv_smul_oreDiv, ← OreLocalization.expand]) @[to_additive] theorem smul_oreDiv (r : R) (x : X) (s : S) : r • (x /ₒ s) = oreNum r s • x /ₒ (oreDenom r s) := rfl @[to_additive (attr := simp)] theorem oreDiv_one_smul (r : R) (x : X[S⁻¹]) : (r /ₒ (1 : S)) • x = r • x := by induction' x using OreLocalization.ind with r s rw [smul_oreDiv, oreDiv_smul_oreDiv, mul_one] @[to_additive] instance : MulAction R X[S⁻¹] where one_smul := OreLocalization.ind fun x s ↦ by rw [← oreDiv_one_smul, ← OreLocalization.one_def, one_smul] mul_smul r r' := OreLocalization.ind fun x s ↦ by rw [← oreDiv_one_smul, ← oreDiv_one_smul, ← oreDiv_one_smul, ← mul_div_one, mul_smul] @[to_additive] instance : IsScalarTower R R[S⁻¹] X[S⁻¹] where smul_assoc a b c := by rw [← oreDiv_one_smul, ← oreDiv_one_smul, smul_smul, smul_eq_mul] /-- The fraction `s /ₒ 1` as a unit in `R[S⁻¹]`, where `s : S`. -/ @[to_additive "The difference `s -ₒ 0` as a an additive unit."] def numeratorUnit (s : S) : Units R[S⁻¹] where val := (s : R) /ₒ 1 inv := (1 : R) /ₒ s val_inv := OreLocalization.mul_inv s 1 inv_val := OreLocalization.mul_inv 1 s #align ore_localization.numerator_unit OreLocalization.numeratorUnit /-- The multiplicative homomorphism from `R` to `R[S⁻¹]`, mapping `r : R` to the fraction `r /ₒ 1`. -/ @[to_additive "The additive homomorphism from `R` to `AddOreLocalization R S`, mapping `r : R` to the difference `r -ₒ 0`."] def numeratorHom : R →* R[S⁻¹] where toFun r := r /ₒ 1 map_one' := rfl map_mul' _ _ := mul_div_one.symm #align ore_localization.numerator_hom OreLocalization.numeratorHom @[to_additive] theorem numeratorHom_apply {r : R} : numeratorHom r = r /ₒ (1 : S) := rfl #align ore_localization.numerator_hom_apply OreLocalization.numeratorHom_apply @[to_additive] theorem numerator_isUnit (s : S) : IsUnit (numeratorHom (s : R) : R[S⁻¹]) := ⟨numeratorUnit s, rfl⟩ #align ore_localization.numerator_is_unit OreLocalization.numerator_isUnit section UMP variable {T : Type*} [Monoid T] variable (f : R →* T) (fS : S →* Units T) variable (hf : ∀ s : S, f s = fS s) /-- The universal lift from a morphism `R →* T`, which maps elements of `S` to units of `T`, to a morphism `R[S⁻¹] →* T`. -/ @[to_additive "The universal lift from a morphism `R →+ T`, which maps elements of `S` to additive-units of `T`, to a morphism `AddOreLocalization R S →+ T`."] def universalMulHom : R[S⁻¹] →* T where -- Porting note(#12129): additional beta reduction needed toFun x := x.liftExpand (fun r s => ((fS s)⁻¹ : Units T) * f r) fun r t s ht => by simp only [smul_eq_mul] have : (fS ⟨t * s, ht⟩ : T) = f t * fS s := by simp only [← hf, MonoidHom.map_mul] conv_rhs => rw [MonoidHom.map_mul, ← one_mul (f r), ← Units.val_one, ← mul_right_inv (fS s)] rw [Units.val_mul, mul_assoc, ← mul_assoc _ (fS s : T), ← this, ← mul_assoc] simp only [one_mul, Units.inv_mul] map_one' := by beta_reduce; rw [OreLocalization.one_def, liftExpand_of]; simp map_mul' x y := by -- Porting note: `simp only []` required, not just for beta reductions beta_reduce simp only [] -- TODO more! induction' x using OreLocalization.ind with r₁ s₁ induction' y using OreLocalization.ind with r₂ s₂ rcases oreDivMulChar' r₁ r₂ s₁ s₂ with ⟨ra, sa, ha, ha'⟩; rw [ha']; clear ha' rw [liftExpand_of, liftExpand_of, liftExpand_of, Units.inv_mul_eq_iff_eq_mul, map_mul, map_mul, Units.val_mul, mul_assoc, ← mul_assoc (fS s₁ : T), ← mul_assoc (fS s₁ : T), Units.mul_inv, one_mul, ← hf, ← mul_assoc, ← map_mul _ _ r₁, ha, map_mul, hf s₂, mul_assoc, ← mul_assoc (fS s₂ : T), (fS s₂).mul_inv, one_mul] #align ore_localization.universal_mul_hom OreLocalization.universalMulHom @[to_additive] theorem universalMulHom_apply {r : R} {s : S} : universalMulHom f fS hf (r /ₒ s) = ((fS s)⁻¹ : Units T) * f r := rfl #align ore_localization.universal_mul_hom_apply OreLocalization.universalMulHom_apply @[to_additive]
Mathlib/RingTheory/OreLocalization/Basic.lean
551
552
theorem universalMulHom_commutes {r : R} : universalMulHom f fS hf (numeratorHom r) = f r := by
simp [numeratorHom_apply, universalMulHom_apply]
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Inv #align_import analysis.calculus.dslope from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Slope of a differentiable function Given a function `f : 𝕜 → E` from a nontrivially normed field to a normed space over this field, `dslope f a b` is defined as `slope f a b = (b - a)⁻¹ • (f b - f a)` for `a ≠ b` and as `deriv f a` for `a = b`. In this file we define `dslope` and prove some basic lemmas about its continuity and differentiability. -/ open scoped Classical Topology Filter open Function Set Filter variable {𝕜 E : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] /-- `dslope f a b` is defined as `slope f a b = (b - a)⁻¹ • (f b - f a)` for `a ≠ b` and `deriv f a` for `a = b`. -/ noncomputable def dslope (f : 𝕜 → E) (a : 𝕜) : 𝕜 → E := update (slope f a) a (deriv f a) #align dslope dslope @[simp] theorem dslope_same (f : 𝕜 → E) (a : 𝕜) : dslope f a a = deriv f a := update_same _ _ _ #align dslope_same dslope_same variable {f : 𝕜 → E} {a b : 𝕜} {s : Set 𝕜} theorem dslope_of_ne (f : 𝕜 → E) (h : b ≠ a) : dslope f a b = slope f a b := update_noteq h _ _ #align dslope_of_ne dslope_of_ne theorem ContinuousLinearMap.dslope_comp {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] (f : E →L[𝕜] F) (g : 𝕜 → E) (a b : 𝕜) (H : a = b → DifferentiableAt 𝕜 g a) : dslope (f ∘ g) a b = f (dslope g a b) := by rcases eq_or_ne b a with (rfl | hne) · simp only [dslope_same] exact (f.hasFDerivAt.comp_hasDerivAt b (H rfl).hasDerivAt).deriv · simpa only [dslope_of_ne _ hne] using f.toLinearMap.slope_comp g a b #align continuous_linear_map.dslope_comp ContinuousLinearMap.dslope_comp theorem eqOn_dslope_slope (f : 𝕜 → E) (a : 𝕜) : EqOn (dslope f a) (slope f a) {a}ᶜ := fun _ => dslope_of_ne f #align eq_on_dslope_slope eqOn_dslope_slope theorem dslope_eventuallyEq_slope_of_ne (f : 𝕜 → E) (h : b ≠ a) : dslope f a =ᶠ[𝓝 b] slope f a := (eqOn_dslope_slope f a).eventuallyEq_of_mem (isOpen_ne.mem_nhds h) #align dslope_eventually_eq_slope_of_ne dslope_eventuallyEq_slope_of_ne theorem dslope_eventuallyEq_slope_punctured_nhds (f : 𝕜 → E) : dslope f a =ᶠ[𝓝[≠] a] slope f a := (eqOn_dslope_slope f a).eventuallyEq_of_mem self_mem_nhdsWithin #align dslope_eventually_eq_slope_punctured_nhds dslope_eventuallyEq_slope_punctured_nhds @[simp] theorem sub_smul_dslope (f : 𝕜 → E) (a b : 𝕜) : (b - a) • dslope f a b = f b - f a := by rcases eq_or_ne b a with (rfl | hne) <;> simp [dslope_of_ne, *] #align sub_smul_dslope sub_smul_dslope theorem dslope_sub_smul_of_ne (f : 𝕜 → E) (h : b ≠ a) : dslope (fun x => (x - a) • f x) a b = f b := by rw [dslope_of_ne _ h, slope_sub_smul _ h.symm] #align dslope_sub_smul_of_ne dslope_sub_smul_of_ne theorem eqOn_dslope_sub_smul (f : 𝕜 → E) (a : 𝕜) : EqOn (dslope (fun x => (x - a) • f x) a) f {a}ᶜ := fun _ => dslope_sub_smul_of_ne f #align eq_on_dslope_sub_smul eqOn_dslope_sub_smul theorem dslope_sub_smul [DecidableEq 𝕜] (f : 𝕜 → E) (a : 𝕜) : dslope (fun x => (x - a) • f x) a = update f a (deriv (fun x => (x - a) • f x) a) := eq_update_iff.2 ⟨dslope_same _ _, eqOn_dslope_sub_smul f a⟩ #align dslope_sub_smul dslope_sub_smul @[simp] theorem continuousAt_dslope_same : ContinuousAt (dslope f a) a ↔ DifferentiableAt 𝕜 f a := by simp only [dslope, continuousAt_update_same, ← hasDerivAt_deriv_iff, hasDerivAt_iff_tendsto_slope] #align continuous_at_dslope_same continuousAt_dslope_same
Mathlib/Analysis/Calculus/Dslope.lean
91
95
theorem ContinuousWithinAt.of_dslope (h : ContinuousWithinAt (dslope f a) s b) : ContinuousWithinAt f s b := by
have : ContinuousWithinAt (fun x => (x - a) • dslope f a x + f a) s b := ((continuousWithinAt_id.sub continuousWithinAt_const).smul h).add continuousWithinAt_const simpa only [sub_smul_dslope, sub_add_cancel] using this
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.Data.Matroid.Dual /-! # Matroid Restriction Given `M : Matroid α` and `R : Set α`, the independent sets of `M` that are contained in `R` are the independent sets of another matroid `M ↾ R` with ground set `R`, called the 'restriction' of `M` to `R`. For `I, R ⊆ M.E`, `I` is a basis of `R` in `M` if and only if `I` is a base of the restriction `M ↾ R`, so this construction relates `Matroid.Basis` to `Matroid.Base`. If `N M : Matroid α` satisfy `N = M ↾ R` for some `R ⊆ M.E`, then we call `N` a 'restriction of `M`', and write `N ≤r M`. This is a partial order. This file proves that the restriction is a matroid and that the `≤r` order is a partial order, and gives related API. It also proves some `Basis` analogues of `Base` lemmas that, while they could be stated in `Data.Matroid.Basic`, are hard to prove without `Matroid.restrict` API. ## Main Definitions * `M.restrict R`, written `M ↾ R`, is the restriction of `M : Matroid α` to `R : Set α`: i.e. the matroid with ground set `R` whose independent sets are the `M`-independent subsets of `R`. * `Matroid.Restriction N M`, written `N ≤r M`, means that `N = M ↾ R` for some `R ⊆ M.E`. * `Matroid.StrictRestriction N M`, written `N <r M`, means that `N = M ↾ R` for some `R ⊂ M.E`. * `Matroidᵣ α` is a type synonym for `Matroid α`, equipped with the `PartialOrder` `≤r`. ## Implementation Notes Since `R` and `M.E` are both terms in `Set α`, to define the restriction `M ↾ R`, we need to either insist that `R ⊆ M.E`, or to say what happens when `R` contains the junk outside `M.E`. It turns out that `R ⊆ M.E` is just an unnecessary hypothesis; if we say the restriction `M ↾ R` has ground set `R` and its independent sets are the `M`-independent subsets of `R`, we always get a matroid, in which the elements of `R \ M.E` aren't in any independent sets. We could instead define this matroid to always be 'smaller' than `M` by setting `(M ↾ R).E := R ∩ M.E`, but this is worse definitionally, and more generally less convenient. This makes it possible to actually restrict a matroid 'upwards'; for instance, if `M : Matroid α` satisfies `M.E = ∅`, then `M ↾ Set.univ` is the matroid on `α` whose ground set is all of `α`, where the empty set is only the independent set. (Elements of `R` outside the ground set are all 'loops' of the matroid.) This is mathematically strange, but is useful for API building. The cost of allowing a restriction of `M` to be 'bigger' than the `M` itself is that the statement `M ↾ R ≤r M` is only true with the hypothesis `R ⊆ M.E` (at least, if we want `≤r` to be a partial order). But this isn't too inconvenient in practice. Indeed `(· ⊆ M.E)` proofs can often be automatically provided by `aesop_mat`. We define the restriction order `≤r` to give a `PartialOrder` instance on the type synonym `Matroidᵣ α` rather than `Matroid α` itself, because the `PartialOrder (Matroid α)` instance is reserved for the more mathematically important 'minor' order. -/ open Set namespace Matroid variable {α : Type*} {M : Matroid α} {R I J X Y : Set α} section restrict /-- The `IndepMatroid` whose independent sets are the independent subsets of `R`. -/ @[simps] def restrictIndepMatroid (M : Matroid α) (R : Set α) : IndepMatroid α where E := R Indep I := M.Indep I ∧ I ⊆ R indep_empty := ⟨M.empty_indep, empty_subset _⟩ indep_subset := fun I J h hIJ ↦ ⟨h.1.subset hIJ, hIJ.trans h.2⟩ indep_aug := by rintro I I' ⟨hI, hIY⟩ (hIn : ¬ M.Basis' I R) (hI' : M.Basis' I' R) rw [basis'_iff_basis_inter_ground] at hIn hI' obtain ⟨B', hB', rfl⟩ := hI'.exists_base obtain ⟨B, hB, hIB, hBIB'⟩ := hI.exists_base_subset_union_base hB' rw [hB'.inter_basis_iff_compl_inter_basis_dual, diff_inter_diff] at hI' have hss : M.E \ (B' ∪ (R ∩ M.E)) ⊆ M.E \ (B ∪ (R ∩ M.E)) := by apply diff_subset_diff_right rw [union_subset_iff, and_iff_left subset_union_right, union_comm] exact hBIB'.trans (union_subset_union_left _ (subset_inter hIY hI.subset_ground)) have hi : M✶.Indep (M.E \ (B ∪ (R ∩ M.E))) := by rw [dual_indep_iff_exists] exact ⟨B, hB, disjoint_of_subset_right subset_union_left disjoint_sdiff_left⟩ have h_eq := hI'.eq_of_subset_indep hi hss (diff_subset_diff_right subset_union_right) rw [h_eq, ← diff_inter_diff, ← hB.inter_basis_iff_compl_inter_basis_dual] at hI' obtain ⟨J, hJ, hIJ⟩ := hI.subset_basis_of_subset (subset_inter hIB (subset_inter hIY hI.subset_ground)) obtain rfl := hI'.indep.eq_of_basis hJ have hIJ' : I ⊂ B ∩ (R ∩ M.E) := hIJ.ssubset_of_ne (fun he ↦ hIn (by rwa [he])) obtain ⟨e, he⟩ := exists_of_ssubset hIJ' exact ⟨e, ⟨⟨(hBIB' he.1.1).elim (fun h ↦ (he.2 h).elim) id,he.1.2⟩, he.2⟩, hI'.indep.subset (insert_subset he.1 hIJ), insert_subset he.1.2.1 hIY⟩ indep_maximal := by rintro A hAX I ⟨hI, _⟩ hIA obtain ⟨J, hJ, hIJ⟩ := hI.subset_basis'_of_subset hIA; use J rw [mem_maximals_setOf_iff, and_iff_left hJ.subset, and_iff_left hIJ, and_iff_right ⟨hJ.indep, hJ.subset.trans hAX⟩] exact fun K ⟨⟨hK, _⟩, _, hKA⟩ hJK ↦ hJ.eq_of_subset_indep hK hJK hKA subset_ground I := And.right /-- Change the ground set of a matroid to some `R : Set α`. The independent sets of the restriction are the independent subsets of the new ground set. Most commonly used when `R ⊆ M.E`, but it is convenient not to require this. The elements of `R \ M.E` become 'loops'. -/ def restrict (M : Matroid α) (R : Set α) : Matroid α := (M.restrictIndepMatroid R).matroid /-- `M ↾ R` means `M.restrict R`. -/ scoped infixl:65 " ↾ " => Matroid.restrict @[simp] theorem restrict_indep_iff : (M ↾ R).Indep I ↔ M.Indep I ∧ I ⊆ R := Iff.rfl theorem Indep.indep_restrict_of_subset (h : M.Indep I) (hIR : I ⊆ R) : (M ↾ R).Indep I := restrict_indep_iff.mpr ⟨h,hIR⟩ theorem Indep.of_restrict (hI : (M ↾ R).Indep I) : M.Indep I := (restrict_indep_iff.1 hI).1 @[simp] theorem restrict_ground_eq : (M ↾ R).E = R := rfl theorem restrict_finite {R : Set α} (hR : R.Finite) : (M ↾ R).Finite := ⟨hR⟩ @[simp] theorem restrict_dep_iff : (M ↾ R).Dep X ↔ ¬ M.Indep X ∧ X ⊆ R := by rw [Dep, restrict_indep_iff, restrict_ground_eq]; tauto @[simp] theorem restrict_ground_eq_self (M : Matroid α) : (M ↾ M.E) = M := by refine eq_of_indep_iff_indep_forall rfl ?_; aesop theorem restrict_restrict_eq {R₁ R₂ : Set α} (M : Matroid α) (hR : R₂ ⊆ R₁) : (M ↾ R₁) ↾ R₂ = M ↾ R₂ := by refine eq_of_indep_iff_indep_forall rfl ?_ simp only [restrict_ground_eq, restrict_indep_iff, and_congr_left_iff, and_iff_left_iff_imp] exact fun _ h _ _ ↦ h.trans hR @[simp] theorem restrict_idem (M : Matroid α) (R : Set α) : M ↾ R ↾ R = M ↾ R := by rw [M.restrict_restrict_eq Subset.rfl] @[simp] theorem base_restrict_iff (hX : X ⊆ M.E := by aesop_mat) : (M ↾ X).Base I ↔ M.Basis I X := by simp_rw [base_iff_maximal_indep, basis_iff', restrict_indep_iff, and_iff_left hX, and_assoc] aesop theorem base_restrict_iff' : (M ↾ X).Base I ↔ M.Basis' I X := by simp_rw [Basis', base_iff_maximal_indep, mem_maximals_setOf_iff, restrict_indep_iff] theorem Basis.restrict_base (h : M.Basis I X) : (M ↾ X).Base I := by rw [basis_iff'] at h simp_rw [base_iff_maximal_indep, restrict_indep_iff, and_imp, and_assoc, and_iff_right h.1.1, and_iff_right h.1.2.1] exact fun J hJ hJX hIJ ↦ h.1.2.2 _ hJ hIJ hJX instance restrict_finiteRk [M.FiniteRk] (R : Set α) : (M ↾ R).FiniteRk := let ⟨_, hB⟩ := (M ↾ R).exists_base hB.finiteRk_of_finite (hB.indep.of_restrict.finite) instance restrict_finitary [Finitary M] (R : Set α) : Finitary (M ↾ R) := by refine ⟨fun I hI ↦ ?_⟩ simp only [restrict_indep_iff] at * rw [indep_iff_forall_finite_subset_indep] exact ⟨fun J hJ hJfin ↦ (hI J hJ hJfin).1, fun e heI ↦ singleton_subset_iff.1 (hI _ (by simpa) (toFinite _)).2⟩ @[simp] theorem Basis.base_restrict (h : M.Basis I X) : (M ↾ X).Base I := (base_restrict_iff h.subset_ground).mpr h
Mathlib/Data/Matroid/Restrict.lean
179
180
theorem Basis.basis_restrict_of_subset (hI : M.Basis I X) (hXY : X ⊆ Y) : (M ↾ Y).Basis I X := by
rwa [← base_restrict_iff, M.restrict_restrict_eq hXY, base_restrict_iff]
/- Copyright (c) 2019 Jean Lo. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jean Lo, Yaël Dillies, Moritz Doll -/ import Mathlib.Data.Real.Pointwise import Mathlib.Analysis.Convex.Function import Mathlib.Analysis.LocallyConvex.Basic import Mathlib.Data.Real.Sqrt #align_import analysis.seminorm from "leanprover-community/mathlib"@"09079525fd01b3dda35e96adaa08d2f943e1648c" /-! # Seminorms This file defines seminorms. A seminorm is a function to the reals which is positive-semidefinite, absolutely homogeneous, and subadditive. They are closely related to convex sets, and a topological vector space is locally convex if and only if its topology is induced by a family of seminorms. ## Main declarations For a module over a normed ring: * `Seminorm`: A function to the reals that is positive-semidefinite, absolutely homogeneous, and subadditive. * `normSeminorm 𝕜 E`: The norm on `E` as a seminorm. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags seminorm, locally convex, LCTVS -/ open NormedField Set Filter open scoped NNReal Pointwise Topology Uniformity variable {R R' 𝕜 𝕜₂ 𝕜₃ 𝕝 E E₂ E₃ F G ι : Type*} /-- A seminorm on a module over a normed ring is a function to the reals that is positive semidefinite, positive homogeneous, and subadditive. -/ structure Seminorm (𝕜 : Type*) (E : Type*) [SeminormedRing 𝕜] [AddGroup E] [SMul 𝕜 E] extends AddGroupSeminorm E where /-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar and the original seminorm. -/ smul' : ∀ (a : 𝕜) (x : E), toFun (a • x) = ‖a‖ * toFun x #align seminorm Seminorm attribute [nolint docBlame] Seminorm.toAddGroupSeminorm /-- `SeminormClass F 𝕜 E` states that `F` is a type of seminorms on the `𝕜`-module `E`. You should extend this class when you extend `Seminorm`. -/ class SeminormClass (F : Type*) (𝕜 E : outParam Type*) [SeminormedRing 𝕜] [AddGroup E] [SMul 𝕜 E] [FunLike F E ℝ] extends AddGroupSeminormClass F E ℝ : Prop where /-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar and the original seminorm. -/ map_smul_eq_mul (f : F) (a : 𝕜) (x : E) : f (a • x) = ‖a‖ * f x #align seminorm_class SeminormClass export SeminormClass (map_smul_eq_mul) -- Porting note: dangerous instances no longer exist -- attribute [nolint dangerousInstance] SeminormClass.toAddGroupSeminormClass section Of /-- Alternative constructor for a `Seminorm` on an `AddCommGroup E` that is a module over a `SeminormedRing 𝕜`. -/ def Seminorm.of [SeminormedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ) (add_le : ∀ x y : E, f (x + y) ≤ f x + f y) (smul : ∀ (a : 𝕜) (x : E), f (a • x) = ‖a‖ * f x) : Seminorm 𝕜 E where toFun := f map_zero' := by rw [← zero_smul 𝕜 (0 : E), smul, norm_zero, zero_mul] add_le' := add_le smul' := smul neg' x := by rw [← neg_one_smul 𝕜, smul, norm_neg, ← smul, one_smul] #align seminorm.of Seminorm.of /-- Alternative constructor for a `Seminorm` over a normed field `𝕜` that only assumes `f 0 = 0` and an inequality for the scalar multiplication. -/ def Seminorm.ofSMulLE [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ) (map_zero : f 0 = 0) (add_le : ∀ x y, f (x + y) ≤ f x + f y) (smul_le : ∀ (r : 𝕜) (x), f (r • x) ≤ ‖r‖ * f x) : Seminorm 𝕜 E := Seminorm.of f add_le fun r x => by refine le_antisymm (smul_le r x) ?_ by_cases h : r = 0 · simp [h, map_zero] rw [← mul_le_mul_left (inv_pos.mpr (norm_pos_iff.mpr h))] rw [inv_mul_cancel_left₀ (norm_ne_zero_iff.mpr h)] specialize smul_le r⁻¹ (r • x) rw [norm_inv] at smul_le convert smul_le simp [h] #align seminorm.of_smul_le Seminorm.ofSMulLE end Of namespace Seminorm section SeminormedRing variable [SeminormedRing 𝕜] section AddGroup variable [AddGroup E] section SMul variable [SMul 𝕜 E] instance instFunLike : FunLike (Seminorm 𝕜 E) E ℝ where coe f := f.toFun coe_injective' f g h := by rcases f with ⟨⟨_⟩⟩ rcases g with ⟨⟨_⟩⟩ congr instance instSeminormClass : SeminormClass (Seminorm 𝕜 E) 𝕜 E where map_zero f := f.map_zero' map_add_le_add f := f.add_le' map_neg_eq_map f := f.neg' map_smul_eq_mul f := f.smul' #align seminorm.seminorm_class Seminorm.instSeminormClass @[ext] theorem ext {p q : Seminorm 𝕜 E} (h : ∀ x, (p : E → ℝ) x = q x) : p = q := DFunLike.ext p q h #align seminorm.ext Seminorm.ext instance instZero : Zero (Seminorm 𝕜 E) := ⟨{ AddGroupSeminorm.instZeroAddGroupSeminorm.zero with smul' := fun _ _ => (mul_zero _).symm }⟩ @[simp] theorem coe_zero : ⇑(0 : Seminorm 𝕜 E) = 0 := rfl #align seminorm.coe_zero Seminorm.coe_zero @[simp] theorem zero_apply (x : E) : (0 : Seminorm 𝕜 E) x = 0 := rfl #align seminorm.zero_apply Seminorm.zero_apply instance : Inhabited (Seminorm 𝕜 E) := ⟨0⟩ variable (p : Seminorm 𝕜 E) (c : 𝕜) (x y : E) (r : ℝ) /-- Any action on `ℝ` which factors through `ℝ≥0` applies to a seminorm. -/ instance instSMul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : SMul R (Seminorm 𝕜 E) where smul r p := { r • p.toAddGroupSeminorm with toFun := fun x => r • p x smul' := fun _ _ => by simp only [← smul_one_smul ℝ≥0 r (_ : ℝ), NNReal.smul_def, smul_eq_mul] rw [map_smul_eq_mul, mul_left_comm] } instance [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] [SMul R' ℝ] [SMul R' ℝ≥0] [IsScalarTower R' ℝ≥0 ℝ] [SMul R R'] [IsScalarTower R R' ℝ] : IsScalarTower R R' (Seminorm 𝕜 E) where smul_assoc r a p := ext fun x => smul_assoc r a (p x) theorem coe_smul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E) : ⇑(r • p) = r • ⇑p := rfl #align seminorm.coe_smul Seminorm.coe_smul @[simp] theorem smul_apply [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E) (x : E) : (r • p) x = r • p x := rfl #align seminorm.smul_apply Seminorm.smul_apply instance instAdd : Add (Seminorm 𝕜 E) where add p q := { p.toAddGroupSeminorm + q.toAddGroupSeminorm with toFun := fun x => p x + q x smul' := fun a x => by simp only [map_smul_eq_mul, map_smul_eq_mul, mul_add] } theorem coe_add (p q : Seminorm 𝕜 E) : ⇑(p + q) = p + q := rfl #align seminorm.coe_add Seminorm.coe_add @[simp] theorem add_apply (p q : Seminorm 𝕜 E) (x : E) : (p + q) x = p x + q x := rfl #align seminorm.add_apply Seminorm.add_apply instance instAddMonoid : AddMonoid (Seminorm 𝕜 E) := DFunLike.coe_injective.addMonoid _ rfl coe_add fun _ _ => by rfl instance instOrderedCancelAddCommMonoid : OrderedCancelAddCommMonoid (Seminorm 𝕜 E) := DFunLike.coe_injective.orderedCancelAddCommMonoid _ rfl coe_add fun _ _ => rfl instance instMulAction [Monoid R] [MulAction R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : MulAction R (Seminorm 𝕜 E) := DFunLike.coe_injective.mulAction _ (by intros; rfl) variable (𝕜 E) /-- `coeFn` as an `AddMonoidHom`. Helper definition for showing that `Seminorm 𝕜 E` is a module. -/ @[simps] def coeFnAddMonoidHom : AddMonoidHom (Seminorm 𝕜 E) (E → ℝ) where toFun := (↑) map_zero' := coe_zero map_add' := coe_add #align seminorm.coe_fn_add_monoid_hom Seminorm.coeFnAddMonoidHom theorem coeFnAddMonoidHom_injective : Function.Injective (coeFnAddMonoidHom 𝕜 E) := show @Function.Injective (Seminorm 𝕜 E) (E → ℝ) (↑) from DFunLike.coe_injective #align seminorm.coe_fn_add_monoid_hom_injective Seminorm.coeFnAddMonoidHom_injective variable {𝕜 E} instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : DistribMulAction R (Seminorm 𝕜 E) := (coeFnAddMonoidHom_injective 𝕜 E).distribMulAction _ (by intros; rfl) instance instModule [Semiring R] [Module R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : Module R (Seminorm 𝕜 E) := (coeFnAddMonoidHom_injective 𝕜 E).module R _ (by intros; rfl) instance instSup : Sup (Seminorm 𝕜 E) where sup p q := { p.toAddGroupSeminorm ⊔ q.toAddGroupSeminorm with toFun := p ⊔ q smul' := fun x v => (congr_arg₂ max (map_smul_eq_mul p x v) (map_smul_eq_mul q x v)).trans <| (mul_max_of_nonneg _ _ <| norm_nonneg x).symm } @[simp] theorem coe_sup (p q : Seminorm 𝕜 E) : ⇑(p ⊔ q) = (p : E → ℝ) ⊔ (q : E → ℝ) := rfl #align seminorm.coe_sup Seminorm.coe_sup theorem sup_apply (p q : Seminorm 𝕜 E) (x : E) : (p ⊔ q) x = p x ⊔ q x := rfl #align seminorm.sup_apply Seminorm.sup_apply theorem smul_sup [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p q : Seminorm 𝕜 E) : r • (p ⊔ q) = r • p ⊔ r • q := have real.smul_max : ∀ x y : ℝ, r • max x y = max (r • x) (r • y) := fun x y => by simpa only [← smul_eq_mul, ← NNReal.smul_def, smul_one_smul ℝ≥0 r (_ : ℝ)] using mul_max_of_nonneg x y (r • (1 : ℝ≥0) : ℝ≥0).coe_nonneg ext fun x => real.smul_max _ _ #align seminorm.smul_sup Seminorm.smul_sup instance instPartialOrder : PartialOrder (Seminorm 𝕜 E) := PartialOrder.lift _ DFunLike.coe_injective @[simp, norm_cast] theorem coe_le_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) ≤ q ↔ p ≤ q := Iff.rfl #align seminorm.coe_le_coe Seminorm.coe_le_coe @[simp, norm_cast] theorem coe_lt_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) < q ↔ p < q := Iff.rfl #align seminorm.coe_lt_coe Seminorm.coe_lt_coe theorem le_def {p q : Seminorm 𝕜 E} : p ≤ q ↔ ∀ x, p x ≤ q x := Iff.rfl #align seminorm.le_def Seminorm.le_def theorem lt_def {p q : Seminorm 𝕜 E} : p < q ↔ p ≤ q ∧ ∃ x, p x < q x := @Pi.lt_def _ _ _ p q #align seminorm.lt_def Seminorm.lt_def instance instSemilatticeSup : SemilatticeSup (Seminorm 𝕜 E) := Function.Injective.semilatticeSup _ DFunLike.coe_injective coe_sup end SMul end AddGroup section Module variable [SeminormedRing 𝕜₂] [SeminormedRing 𝕜₃] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] variable {σ₂₃ : 𝕜₂ →+* 𝕜₃} [RingHomIsometric σ₂₃] variable {σ₁₃ : 𝕜 →+* 𝕜₃} [RingHomIsometric σ₁₃] variable [AddCommGroup E] [AddCommGroup E₂] [AddCommGroup E₃] variable [AddCommGroup F] [AddCommGroup G] variable [Module 𝕜 E] [Module 𝕜₂ E₂] [Module 𝕜₃ E₃] [Module 𝕜 F] [Module 𝕜 G] -- Porting note: even though this instance is found immediately by typeclass search, -- it seems to be needed below!? noncomputable instance smul_nnreal_real : SMul ℝ≥0 ℝ := inferInstance variable [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] /-- Composition of a seminorm with a linear map is a seminorm. -/ def comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜 E := { p.toAddGroupSeminorm.comp f.toAddMonoidHom with toFun := fun x => p (f x) -- Porting note: the `simp only` below used to be part of the `rw`. -- I'm not sure why this change was needed, and am worried by it! -- Note: #8386 had to change `map_smulₛₗ` to `map_smulₛₗ _` smul' := fun _ _ => by simp only [map_smulₛₗ _]; rw [map_smul_eq_mul, RingHomIsometric.is_iso] } #align seminorm.comp Seminorm.comp theorem coe_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : ⇑(p.comp f) = p ∘ f := rfl #align seminorm.coe_comp Seminorm.coe_comp @[simp] theorem comp_apply (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) : (p.comp f) x = p (f x) := rfl #align seminorm.comp_apply Seminorm.comp_apply @[simp] theorem comp_id (p : Seminorm 𝕜 E) : p.comp LinearMap.id = p := ext fun _ => rfl #align seminorm.comp_id Seminorm.comp_id @[simp] theorem comp_zero (p : Seminorm 𝕜₂ E₂) : p.comp (0 : E →ₛₗ[σ₁₂] E₂) = 0 := ext fun _ => map_zero p #align seminorm.comp_zero Seminorm.comp_zero @[simp] theorem zero_comp (f : E →ₛₗ[σ₁₂] E₂) : (0 : Seminorm 𝕜₂ E₂).comp f = 0 := ext fun _ => rfl #align seminorm.zero_comp Seminorm.zero_comp theorem comp_comp [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] (p : Seminorm 𝕜₃ E₃) (g : E₂ →ₛₗ[σ₂₃] E₃) (f : E →ₛₗ[σ₁₂] E₂) : p.comp (g.comp f) = (p.comp g).comp f := ext fun _ => rfl #align seminorm.comp_comp Seminorm.comp_comp theorem add_comp (p q : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : (p + q).comp f = p.comp f + q.comp f := ext fun _ => rfl #align seminorm.add_comp Seminorm.add_comp theorem comp_add_le (p : Seminorm 𝕜₂ E₂) (f g : E →ₛₗ[σ₁₂] E₂) : p.comp (f + g) ≤ p.comp f + p.comp g := fun _ => map_add_le_add p _ _ #align seminorm.comp_add_le Seminorm.comp_add_le theorem smul_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : R) : (c • p).comp f = c • p.comp f := ext fun _ => rfl #align seminorm.smul_comp Seminorm.smul_comp theorem comp_mono {p q : Seminorm 𝕜₂ E₂} (f : E →ₛₗ[σ₁₂] E₂) (hp : p ≤ q) : p.comp f ≤ q.comp f := fun _ => hp _ #align seminorm.comp_mono Seminorm.comp_mono /-- The composition as an `AddMonoidHom`. -/ @[simps] def pullback (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜₂ E₂ →+ Seminorm 𝕜 E where toFun := fun p => p.comp f map_zero' := zero_comp f map_add' := fun p q => add_comp p q f #align seminorm.pullback Seminorm.pullback instance instOrderBot : OrderBot (Seminorm 𝕜 E) where bot := 0 bot_le := apply_nonneg @[simp] theorem coe_bot : ⇑(⊥ : Seminorm 𝕜 E) = 0 := rfl #align seminorm.coe_bot Seminorm.coe_bot theorem bot_eq_zero : (⊥ : Seminorm 𝕜 E) = 0 := rfl #align seminorm.bot_eq_zero Seminorm.bot_eq_zero theorem smul_le_smul {p q : Seminorm 𝕜 E} {a b : ℝ≥0} (hpq : p ≤ q) (hab : a ≤ b) : a • p ≤ b • q := by simp_rw [le_def] intro x exact mul_le_mul hab (hpq x) (apply_nonneg p x) (NNReal.coe_nonneg b) #align seminorm.smul_le_smul Seminorm.smul_le_smul theorem finset_sup_apply (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) : s.sup p x = ↑(s.sup fun i => ⟨p i x, apply_nonneg (p i) x⟩ : ℝ≥0) := by induction' s using Finset.cons_induction_on with a s ha ih · rw [Finset.sup_empty, Finset.sup_empty, coe_bot, _root_.bot_eq_zero, Pi.zero_apply] norm_cast · rw [Finset.sup_cons, Finset.sup_cons, coe_sup, sup_eq_max, Pi.sup_apply, sup_eq_max, NNReal.coe_max, NNReal.coe_mk, ih] #align seminorm.finset_sup_apply Seminorm.finset_sup_apply
Mathlib/Analysis/Seminorm.lean
392
396
theorem exists_apply_eq_finset_sup (p : ι → Seminorm 𝕜 E) {s : Finset ι} (hs : s.Nonempty) (x : E) : ∃ i ∈ s, s.sup p x = p i x := by
rcases Finset.exists_mem_eq_sup s hs (fun i ↦ (⟨p i x, apply_nonneg _ _⟩ : ℝ≥0)) with ⟨i, hi, hix⟩ rw [finset_sup_apply] exact ⟨i, hi, congr_arg _ hix⟩
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Group.Defs import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Data.Int.Cast.Defs import Mathlib.Tactic.Spread import Mathlib.Util.AssertExists #align_import algebra.ring.defs from "leanprover-community/mathlib"@"76de8ae01554c3b37d66544866659ff174e66e1f" /-! # Semirings and rings This file defines semirings, rings and domains. This is analogous to `Algebra.Group.Defs` and `Algebra.Group.Basic`, the difference being that the former is about `+` and `*` separately, while the present file is about their interaction. ## Main definitions * `Distrib`: Typeclass for distributivity of multiplication over addition. * `HasDistribNeg`: Typeclass for commutativity of negation and multiplication. This is useful when dealing with multiplicative submonoids which are closed under negation without being closed under addition, for example `Units`. * `(NonUnital)(NonAssoc)(Semi)Ring`: Typeclasses for possibly non-unital or non-associative rings and semirings. Some combinations are not defined yet because they haven't found use. ## Tags `Semiring`, `CommSemiring`, `Ring`, `CommRing`, domain, `IsDomain`, nonzero, units -/ universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {R : Type x} open Function /-! ### `Distrib` class -/ /-- A typeclass stating that multiplication is left and right distributive over addition. -/ class Distrib (R : Type*) extends Mul R, Add R where /-- Multiplication is left distributive over addition -/ protected left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c /-- Multiplication is right distributive over addition -/ protected right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c #align distrib Distrib /-- A typeclass stating that multiplication is left distributive over addition. -/ class LeftDistribClass (R : Type*) [Mul R] [Add R] : Prop where /-- Multiplication is left distributive over addition -/ protected left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c #align left_distrib_class LeftDistribClass /-- A typeclass stating that multiplication is right distributive over addition. -/ class RightDistribClass (R : Type*) [Mul R] [Add R] : Prop where /-- Multiplication is right distributive over addition -/ protected right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c #align right_distrib_class RightDistribClass -- see Note [lower instance priority] instance (priority := 100) Distrib.leftDistribClass (R : Type*) [Distrib R] : LeftDistribClass R := ⟨Distrib.left_distrib⟩ #align distrib.left_distrib_class Distrib.leftDistribClass -- see Note [lower instance priority] instance (priority := 100) Distrib.rightDistribClass (R : Type*) [Distrib R] : RightDistribClass R := ⟨Distrib.right_distrib⟩ #align distrib.right_distrib_class Distrib.rightDistribClass theorem left_distrib [Mul R] [Add R] [LeftDistribClass R] (a b c : R) : a * (b + c) = a * b + a * c := LeftDistribClass.left_distrib a b c #align left_distrib left_distrib alias mul_add := left_distrib #align mul_add mul_add theorem right_distrib [Mul R] [Add R] [RightDistribClass R] (a b c : R) : (a + b) * c = a * c + b * c := RightDistribClass.right_distrib a b c #align right_distrib right_distrib alias add_mul := right_distrib #align add_mul add_mul theorem distrib_three_right [Mul R] [Add R] [RightDistribClass R] (a b c d : R) : (a + b + c) * d = a * d + b * d + c * d := by simp [right_distrib] #align distrib_three_right distrib_three_right /-! ### Classes of semirings and rings We make sure that the canonical path from `NonAssocSemiring` to `Ring` passes through `Semiring`, as this is a path which is followed all the time in linear algebra where the defining semilinear map `σ : R →+* S` depends on the `NonAssocSemiring` structure of `R` and `S` while the module definition depends on the `Semiring` structure. It is not currently possible to adjust priorities by hand (see lean4#2115). Instead, the last declared instance is used, so we make sure that `Semiring` is declared after `NonAssocRing`, so that `Semiring -> NonAssocSemiring` is tried before `NonAssocRing -> NonAssocSemiring`. TODO: clean this once lean4#2115 is fixed -/ /-- A not-necessarily-unital, not-necessarily-associative semiring. -/ class NonUnitalNonAssocSemiring (α : Type u) extends AddCommMonoid α, Distrib α, MulZeroClass α #align non_unital_non_assoc_semiring NonUnitalNonAssocSemiring /-- An associative but not-necessarily unital semiring. -/ class NonUnitalSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, SemigroupWithZero α #align non_unital_semiring NonUnitalSemiring /-- A unital but not-necessarily-associative semiring. -/ class NonAssocSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, MulZeroOneClass α, AddCommMonoidWithOne α #align non_assoc_semiring NonAssocSemiring /-- A not-necessarily-unital, not-necessarily-associative ring. -/ class NonUnitalNonAssocRing (α : Type u) extends AddCommGroup α, NonUnitalNonAssocSemiring α #align non_unital_non_assoc_ring NonUnitalNonAssocRing /-- An associative but not-necessarily unital ring. -/ class NonUnitalRing (α : Type*) extends NonUnitalNonAssocRing α, NonUnitalSemiring α #align non_unital_ring NonUnitalRing /-- A unital but not-necessarily-associative ring. -/ class NonAssocRing (α : Type*) extends NonUnitalNonAssocRing α, NonAssocSemiring α, AddCommGroupWithOne α #align non_assoc_ring NonAssocRing /-- A `Semiring` is a type with addition, multiplication, a `0` and a `1` where addition is commutative and associative, multiplication is associative and left and right distributive over addition, and `0` and `1` are additive and multiplicative identities. -/ class Semiring (α : Type u) extends NonUnitalSemiring α, NonAssocSemiring α, MonoidWithZero α #align semiring Semiring /-- A `Ring` is a `Semiring` with negation making it an additive group. -/ class Ring (R : Type u) extends Semiring R, AddCommGroup R, AddGroupWithOne R #align ring Ring /-! ### Semirings -/ section DistribMulOneClass variable [Add α] [MulOneClass α] theorem add_one_mul [RightDistribClass α] (a b : α) : (a + 1) * b = a * b + b := by rw [add_mul, one_mul] #align add_one_mul add_one_mul theorem mul_add_one [LeftDistribClass α] (a b : α) : a * (b + 1) = a * b + a := by rw [mul_add, mul_one] #align mul_add_one mul_add_one theorem one_add_mul [RightDistribClass α] (a b : α) : (1 + a) * b = b + a * b := by rw [add_mul, one_mul] #align one_add_mul one_add_mul theorem mul_one_add [LeftDistribClass α] (a b : α) : a * (1 + b) = a + a * b := by rw [mul_add, mul_one] #align mul_one_add mul_one_add end DistribMulOneClass section NonAssocSemiring variable [NonAssocSemiring α] -- Porting note: was [has_add α] [mul_one_class α] [right_distrib_class α] theorem two_mul (n : α) : 2 * n = n + n := (congrArg₂ _ one_add_one_eq_two.symm rfl).trans <| (right_distrib 1 1 n).trans (by rw [one_mul]) #align two_mul two_mul -- Porting note: was [has_add α] [mul_one_class α] [right_distrib_class α] set_option linter.deprecated false in theorem bit0_eq_two_mul (n : α) : bit0 n = 2 * n := (two_mul _).symm #align bit0_eq_two_mul bit0_eq_two_mul -- Porting note: was [has_add α] [mul_one_class α] [left_distrib_class α] theorem mul_two (n : α) : n * 2 = n + n := (congrArg₂ _ rfl one_add_one_eq_two.symm).trans <| (left_distrib n 1 1).trans (by rw [mul_one]) #align mul_two mul_two end NonAssocSemiring @[to_additive] theorem mul_ite {α} [Mul α] (P : Prop) [Decidable P] (a b c : α) : (a * if P then b else c) = if P then a * b else a * c := by split_ifs <;> rfl #align mul_ite mul_ite #align add_ite add_ite @[to_additive] theorem ite_mul {α} [Mul α] (P : Prop) [Decidable P] (a b c : α) : (if P then a else b) * c = if P then a * c else b * c := by split_ifs <;> rfl #align ite_mul ite_mul #align ite_add ite_add -- We make `mul_ite` and `ite_mul` simp lemmas, -- but not `add_ite` or `ite_add`. -- The problem we're trying to avoid is dealing with -- summations of the form `∑ x ∈ s, (f x + ite P 1 0)`, -- in which `add_ite` followed by `sum_ite` would needlessly slice up -- the `f x` terms according to whether `P` holds at `x`. -- There doesn't appear to be a corresponding difficulty so far with -- `mul_ite` and `ite_mul`. attribute [simp] mul_ite ite_mul theorem ite_sub_ite {α} [Sub α] (P : Prop) [Decidable P] (a b c d : α) : ((if P then a else b) - if P then c else d) = if P then a - c else b - d := by split repeat rfl theorem ite_add_ite {α} [Add α] (P : Prop) [Decidable P] (a b c d : α) : ((if P then a else b) + if P then c else d) = if P then a + c else b + d := by split repeat rfl section MulZeroClass variable [MulZeroClass α] (P Q : Prop) [Decidable P] [Decidable Q] (a b : α) lemma ite_zero_mul : ite P a 0 * b = ite P (a * b) 0 := by simp #align ite_mul_zero_left ite_zero_mul lemma mul_ite_zero : a * ite P b 0 = ite P (a * b) 0 := by simp #align ite_mul_zero_right mul_ite_zero lemma ite_zero_mul_ite_zero : ite P a 0 * ite Q b 0 = ite (P ∧ Q) (a * b) 0 := by simp only [← ite_and, ite_mul, mul_ite, mul_zero, zero_mul, and_comm] #align ite_and_mul_zero ite_zero_mul_ite_zero end MulZeroClass -- Porting note: no @[simp] because simp proves it theorem mul_boole {α} [MulZeroOneClass α] (P : Prop) [Decidable P] (a : α) : (a * if P then 1 else 0) = if P then a else 0 := by simp #align mul_boole mul_boole -- Porting note: no @[simp] because simp proves it theorem boole_mul {α} [MulZeroOneClass α] (P : Prop) [Decidable P] (a : α) : (if P then 1 else 0) * a = if P then a else 0 := by simp #align boole_mul boole_mul /-- A not-necessarily-unital, not-necessarily-associative, but commutative semiring. -/ class NonUnitalNonAssocCommSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, CommMagma α /-- A non-unital commutative semiring is a `NonUnitalSemiring` with commutative multiplication. In other words, it is a type with the following structures: additive commutative monoid (`AddCommMonoid`), commutative semigroup (`CommSemigroup`), distributive laws (`Distrib`), and multiplication by zero law (`MulZeroClass`). -/ class NonUnitalCommSemiring (α : Type u) extends NonUnitalSemiring α, CommSemigroup α #align non_unital_comm_semiring NonUnitalCommSemiring /-- A commutative semiring is a semiring with commutative multiplication. -/ class CommSemiring (R : Type u) extends Semiring R, CommMonoid R #align comm_semiring CommSemiring -- see Note [lower instance priority] instance (priority := 100) CommSemiring.toNonUnitalCommSemiring [CommSemiring α] : NonUnitalCommSemiring α := { inferInstanceAs (CommMonoid α), inferInstanceAs (CommSemiring α) with } #align comm_semiring.to_non_unital_comm_semiring CommSemiring.toNonUnitalCommSemiring -- see Note [lower instance priority] instance (priority := 100) CommSemiring.toCommMonoidWithZero [CommSemiring α] : CommMonoidWithZero α := { inferInstanceAs (CommMonoid α), inferInstanceAs (CommSemiring α) with } #align comm_semiring.to_comm_monoid_with_zero CommSemiring.toCommMonoidWithZero section CommSemiring variable [CommSemiring α] {a b c : α} theorem add_mul_self_eq (a b : α) : (a + b) * (a + b) = a * a + 2 * a * b + b * b := by simp only [two_mul, add_mul, mul_add, add_assoc, mul_comm b] #align add_mul_self_eq add_mul_self_eq lemma add_sq (a b : α) : (a + b) ^ 2 = a ^ 2 + 2 * a * b + b ^ 2 := by simp only [sq, add_mul_self_eq] #align add_sq add_sq lemma add_sq' (a b : α) : (a + b) ^ 2 = a ^ 2 + b ^ 2 + 2 * a * b := by rw [add_sq, add_assoc, add_comm _ (b ^ 2), add_assoc] #align add_sq' add_sq' alias add_pow_two := add_sq #align add_pow_two add_pow_two end CommSemiring section HasDistribNeg /-- Typeclass for a negation operator that distributes across multiplication. This is useful for dealing with submonoids of a ring that contain `-1` without having to duplicate lemmas. -/ class HasDistribNeg (α : Type*) [Mul α] extends InvolutiveNeg α where /-- Negation is left distributive over multiplication -/ neg_mul : ∀ x y : α, -x * y = -(x * y) /-- Negation is right distributive over multiplication -/ mul_neg : ∀ x y : α, x * -y = -(x * y) #align has_distrib_neg HasDistribNeg section Mul variable [Mul α] [HasDistribNeg α] @[simp] theorem neg_mul (a b : α) : -a * b = -(a * b) := HasDistribNeg.neg_mul _ _ #align neg_mul neg_mul @[simp] theorem mul_neg (a b : α) : a * -b = -(a * b) := HasDistribNeg.mul_neg _ _ #align mul_neg mul_neg theorem neg_mul_neg (a b : α) : -a * -b = a * b := by simp #align neg_mul_neg neg_mul_neg theorem neg_mul_eq_neg_mul (a b : α) : -(a * b) = -a * b := (neg_mul _ _).symm #align neg_mul_eq_neg_mul neg_mul_eq_neg_mul theorem neg_mul_eq_mul_neg (a b : α) : -(a * b) = a * -b := (mul_neg _ _).symm #align neg_mul_eq_mul_neg neg_mul_eq_mul_neg
Mathlib/Algebra/Ring/Defs.lean
338
338
theorem neg_mul_comm (a b : α) : -a * b = a * -b := by
simp
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Nat.Lattice import Mathlib.Logic.Denumerable import Mathlib.Logic.Function.Iterate import Mathlib.Order.Hom.Basic import Mathlib.Data.Set.Subsingleton #align_import order.order_iso_nat from "leanprover-community/mathlib"@"210657c4ea4a4a7b234392f70a3a2a83346dfa90" /-! # Relation embeddings from the naturals This file allows translation from monotone functions `ℕ → α` to order embeddings `ℕ ↪ α` and defines the limit value of an eventually-constant sequence. ## Main declarations * `natLT`/`natGT`: Make an order embedding `Nat ↪ α` from an increasing/decreasing function `Nat → α`. * `monotonicSequenceLimit`: The limit of an eventually-constant monotone sequence `Nat →o α`. * `monotonicSequenceLimitIndex`: The index of the first occurrence of `monotonicSequenceLimit` in the sequence. -/ variable {α : Type*} namespace RelEmbedding variable {r : α → α → Prop} [IsStrictOrder α r] /-- If `f` is a strictly `r`-increasing sequence, then this returns `f` as an order embedding. -/ def natLT (f : ℕ → α) (H : ∀ n : ℕ, r (f n) (f (n + 1))) : ((· < ·) : ℕ → ℕ → Prop) ↪r r := ofMonotone f <| Nat.rel_of_forall_rel_succ_of_lt r H #align rel_embedding.nat_lt RelEmbedding.natLT @[simp] theorem coe_natLT {f : ℕ → α} {H : ∀ n : ℕ, r (f n) (f (n + 1))} : ⇑(natLT f H) = f := rfl #align rel_embedding.coe_nat_lt RelEmbedding.coe_natLT /-- If `f` is a strictly `r`-decreasing sequence, then this returns `f` as an order embedding. -/ def natGT (f : ℕ → α) (H : ∀ n : ℕ, r (f (n + 1)) (f n)) : ((· > ·) : ℕ → ℕ → Prop) ↪r r := haveI := IsStrictOrder.swap r RelEmbedding.swap (natLT f H) #align rel_embedding.nat_gt RelEmbedding.natGT @[simp] theorem coe_natGT {f : ℕ → α} {H : ∀ n : ℕ, r (f (n + 1)) (f n)} : ⇑(natGT f H) = f := rfl #align rel_embedding.coe_nat_gt RelEmbedding.coe_natGT theorem exists_not_acc_lt_of_not_acc {a : α} {r} (h : ¬Acc r a) : ∃ b, ¬Acc r b ∧ r b a := by contrapose! h refine ⟨_, fun b hr => ?_⟩ by_contra hb exact h b hb hr #align rel_embedding.exists_not_acc_lt_of_not_acc RelEmbedding.exists_not_acc_lt_of_not_acc /-- A value is accessible iff it isn't contained in any infinite decreasing sequence. -/ theorem acc_iff_no_decreasing_seq {x} : Acc r x ↔ IsEmpty { f : ((· > ·) : ℕ → ℕ → Prop) ↪r r // x ∈ Set.range f } := by constructor · refine fun h => h.recOn fun x _ IH => ?_ constructor rintro ⟨f, k, hf⟩ exact IsEmpty.elim' (IH (f (k + 1)) (hf ▸ f.map_rel_iff.2 (lt_add_one k))) ⟨f, _, rfl⟩ · have : ∀ x : { a // ¬Acc r a }, ∃ y : { a // ¬Acc r a }, r y.1 x.1 := by rintro ⟨x, hx⟩ cases exists_not_acc_lt_of_not_acc hx with | intro w h => exact ⟨⟨w, h.1⟩, h.2⟩ choose f h using this refine fun E => by_contradiction fun hx => E.elim' ⟨natGT (fun n => (f^[n] ⟨x, hx⟩).1) fun n => ?_, 0, rfl⟩ simp only [Function.iterate_succ'] apply h #align rel_embedding.acc_iff_no_decreasing_seq RelEmbedding.acc_iff_no_decreasing_seq theorem not_acc_of_decreasing_seq (f : ((· > ·) : ℕ → ℕ → Prop) ↪r r) (k : ℕ) : ¬Acc r (f k) := by rw [acc_iff_no_decreasing_seq, not_isEmpty_iff] exact ⟨⟨f, k, rfl⟩⟩ #align rel_embedding.not_acc_of_decreasing_seq RelEmbedding.not_acc_of_decreasing_seq /-- A relation is well-founded iff it doesn't have any infinite decreasing sequence. -/ theorem wellFounded_iff_no_descending_seq : WellFounded r ↔ IsEmpty (((· > ·) : ℕ → ℕ → Prop) ↪r r) := by constructor · rintro ⟨h⟩ exact ⟨fun f => not_acc_of_decreasing_seq f 0 (h _)⟩ · intro h exact ⟨fun x => acc_iff_no_decreasing_seq.2 inferInstance⟩ #align rel_embedding.well_founded_iff_no_descending_seq RelEmbedding.wellFounded_iff_no_descending_seq theorem not_wellFounded_of_decreasing_seq (f : ((· > ·) : ℕ → ℕ → Prop) ↪r r) : ¬WellFounded r := by rw [wellFounded_iff_no_descending_seq, not_isEmpty_iff] exact ⟨f⟩ #align rel_embedding.not_well_founded_of_decreasing_seq RelEmbedding.not_wellFounded_of_decreasing_seq end RelEmbedding namespace Nat variable (s : Set ℕ) [Infinite s] /-- An order embedding from `ℕ` to itself with a specified range -/ def orderEmbeddingOfSet [DecidablePred (· ∈ s)] : ℕ ↪o ℕ := (RelEmbedding.orderEmbeddingOfLTEmbedding (RelEmbedding.natLT (Nat.Subtype.ofNat s) fun _ => Nat.Subtype.lt_succ_self _)).trans (OrderEmbedding.subtype s) #align nat.order_embedding_of_set Nat.orderEmbeddingOfSet /-- `Nat.Subtype.ofNat` as an order isomorphism between `ℕ` and an infinite subset. See also `Nat.Nth` for a version where the subset may be finite. -/ noncomputable def Subtype.orderIsoOfNat : ℕ ≃o s := by classical exact RelIso.ofSurjective (RelEmbedding.orderEmbeddingOfLTEmbedding (RelEmbedding.natLT (Nat.Subtype.ofNat s) fun n => Nat.Subtype.lt_succ_self _)) Nat.Subtype.ofNat_surjective #align nat.subtype.order_iso_of_nat Nat.Subtype.orderIsoOfNat variable {s} @[simp] theorem coe_orderEmbeddingOfSet [DecidablePred (· ∈ s)] : ⇑(orderEmbeddingOfSet s) = (↑) ∘ Subtype.ofNat s := rfl #align nat.coe_order_embedding_of_set Nat.coe_orderEmbeddingOfSet theorem orderEmbeddingOfSet_apply [DecidablePred (· ∈ s)] {n : ℕ} : orderEmbeddingOfSet s n = Subtype.ofNat s n := rfl #align nat.order_embedding_of_set_apply Nat.orderEmbeddingOfSet_apply @[simp]
Mathlib/Order/OrderIsoNat.lean
142
144
theorem Subtype.orderIsoOfNat_apply [dP : DecidablePred (· ∈ s)] {n : ℕ} : Subtype.orderIsoOfNat s n = Subtype.ofNat s n := by
simp [orderIsoOfNat]; congr!
/- Copyright (c) 2021 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Combinatorics.SimpleGraph.Subgraph import Mathlib.Data.List.Rotate #align_import combinatorics.simple_graph.connectivity from "leanprover-community/mathlib"@"b99e2d58a5e6861833fa8de11e51a81144258db4" /-! # Graph connectivity In a simple graph, * A *walk* is a finite sequence of adjacent vertices, and can be thought of equally well as a sequence of directed edges. * A *trail* is a walk whose edges each appear no more than once. * A *path* is a trail whose vertices appear no more than once. * A *cycle* is a nonempty trail whose first and last vertices are the same and whose vertices except for the first appear no more than once. **Warning:** graph theorists mean something different by "path" than do homotopy theorists. A "walk" in graph theory is a "path" in homotopy theory. Another warning: some graph theorists use "path" and "simple path" for "walk" and "path." Some definitions and theorems have inspiration from multigraph counterparts in [Chou1994]. ## Main definitions * `SimpleGraph.Walk` (with accompanying pattern definitions `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'`) * `SimpleGraph.Walk.IsTrail`, `SimpleGraph.Walk.IsPath`, and `SimpleGraph.Walk.IsCycle`. * `SimpleGraph.Path` * `SimpleGraph.Walk.map` and `SimpleGraph.Path.map` for the induced map on walks, given an (injective) graph homomorphism. * `SimpleGraph.Reachable` for the relation of whether there exists a walk between a given pair of vertices * `SimpleGraph.Preconnected` and `SimpleGraph.Connected` are predicates on simple graphs for whether every vertex can be reached from every other, and in the latter case, whether the vertex type is nonempty. * `SimpleGraph.ConnectedComponent` is the type of connected components of a given graph. * `SimpleGraph.IsBridge` for whether an edge is a bridge edge ## Main statements * `SimpleGraph.isBridge_iff_mem_and_forall_cycle_not_mem` characterizes bridge edges in terms of there being no cycle containing them. ## Tags walks, trails, paths, circuits, cycles, bridge edges -/ open Function universe u v w namespace SimpleGraph variable {V : Type u} {V' : Type v} {V'' : Type w} variable (G : SimpleGraph V) (G' : SimpleGraph V') (G'' : SimpleGraph V'') /-- A walk is a sequence of adjacent vertices. For vertices `u v : V`, the type `walk u v` consists of all walks starting at `u` and ending at `v`. We say that a walk *visits* the vertices it contains. The set of vertices a walk visits is `SimpleGraph.Walk.support`. See `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'` for patterns that can be useful in definitions since they make the vertices explicit. -/ inductive Walk : V → V → Type u | nil {u : V} : Walk u u | cons {u v w : V} (h : G.Adj u v) (p : Walk v w) : Walk u w deriving DecidableEq #align simple_graph.walk SimpleGraph.Walk attribute [refl] Walk.nil @[simps] instance Walk.instInhabited (v : V) : Inhabited (G.Walk v v) := ⟨Walk.nil⟩ #align simple_graph.walk.inhabited SimpleGraph.Walk.instInhabited /-- The one-edge walk associated to a pair of adjacent vertices. -/ @[match_pattern, reducible] def Adj.toWalk {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Walk u v := Walk.cons h Walk.nil #align simple_graph.adj.to_walk SimpleGraph.Adj.toWalk namespace Walk variable {G} /-- Pattern to get `Walk.nil` with the vertex as an explicit argument. -/ @[match_pattern] abbrev nil' (u : V) : G.Walk u u := Walk.nil #align simple_graph.walk.nil' SimpleGraph.Walk.nil' /-- Pattern to get `Walk.cons` with the vertices as explicit arguments. -/ @[match_pattern] abbrev cons' (u v w : V) (h : G.Adj u v) (p : G.Walk v w) : G.Walk u w := Walk.cons h p #align simple_graph.walk.cons' SimpleGraph.Walk.cons' /-- Change the endpoints of a walk using equalities. This is helpful for relaxing definitional equality constraints and to be able to state otherwise difficult-to-state lemmas. While this is a simple wrapper around `Eq.rec`, it gives a canonical way to write it. The simp-normal form is for the `copy` to be pushed outward. That way calculations can occur within the "copy context." -/ protected def copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : G.Walk u' v' := hu ▸ hv ▸ p #align simple_graph.walk.copy SimpleGraph.Walk.copy @[simp] theorem copy_rfl_rfl {u v} (p : G.Walk u v) : p.copy rfl rfl = p := rfl #align simple_graph.walk.copy_rfl_rfl SimpleGraph.Walk.copy_rfl_rfl @[simp] theorem copy_copy {u v u' v' u'' v''} (p : G.Walk u v) (hu : u = u') (hv : v = v') (hu' : u' = u'') (hv' : v' = v'') : (p.copy hu hv).copy hu' hv' = p.copy (hu.trans hu') (hv.trans hv') := by subst_vars rfl #align simple_graph.walk.copy_copy SimpleGraph.Walk.copy_copy @[simp] theorem copy_nil {u u'} (hu : u = u') : (Walk.nil : G.Walk u u).copy hu hu = Walk.nil := by subst_vars rfl #align simple_graph.walk.copy_nil SimpleGraph.Walk.copy_nil theorem copy_cons {u v w u' w'} (h : G.Adj u v) (p : G.Walk v w) (hu : u = u') (hw : w = w') : (Walk.cons h p).copy hu hw = Walk.cons (hu ▸ h) (p.copy rfl hw) := by subst_vars rfl #align simple_graph.walk.copy_cons SimpleGraph.Walk.copy_cons @[simp] theorem cons_copy {u v w v' w'} (h : G.Adj u v) (p : G.Walk v' w') (hv : v' = v) (hw : w' = w) : Walk.cons h (p.copy hv hw) = (Walk.cons (hv ▸ h) p).copy rfl hw := by subst_vars rfl #align simple_graph.walk.cons_copy SimpleGraph.Walk.cons_copy theorem exists_eq_cons_of_ne {u v : V} (hne : u ≠ v) : ∀ (p : G.Walk u v), ∃ (w : V) (h : G.Adj u w) (p' : G.Walk w v), p = cons h p' | nil => (hne rfl).elim | cons h p' => ⟨_, h, p', rfl⟩ #align simple_graph.walk.exists_eq_cons_of_ne SimpleGraph.Walk.exists_eq_cons_of_ne /-- The length of a walk is the number of edges/darts along it. -/ def length {u v : V} : G.Walk u v → ℕ | nil => 0 | cons _ q => q.length.succ #align simple_graph.walk.length SimpleGraph.Walk.length /-- The concatenation of two compatible walks. -/ @[trans] def append {u v w : V} : G.Walk u v → G.Walk v w → G.Walk u w | nil, q => q | cons h p, q => cons h (p.append q) #align simple_graph.walk.append SimpleGraph.Walk.append /-- The reversed version of `SimpleGraph.Walk.cons`, concatenating an edge to the end of a walk. -/ def concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : G.Walk u w := p.append (cons h nil) #align simple_graph.walk.concat SimpleGraph.Walk.concat theorem concat_eq_append {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : p.concat h = p.append (cons h nil) := rfl #align simple_graph.walk.concat_eq_append SimpleGraph.Walk.concat_eq_append /-- The concatenation of the reverse of the first walk with the second walk. -/ protected def reverseAux {u v w : V} : G.Walk u v → G.Walk u w → G.Walk v w | nil, q => q | cons h p, q => Walk.reverseAux p (cons (G.symm h) q) #align simple_graph.walk.reverse_aux SimpleGraph.Walk.reverseAux /-- The walk in reverse. -/ @[symm] def reverse {u v : V} (w : G.Walk u v) : G.Walk v u := w.reverseAux nil #align simple_graph.walk.reverse SimpleGraph.Walk.reverse /-- Get the `n`th vertex from a walk, where `n` is generally expected to be between `0` and `p.length`, inclusive. If `n` is greater than or equal to `p.length`, the result is the path's endpoint. -/ def getVert {u v : V} : G.Walk u v → ℕ → V | nil, _ => u | cons _ _, 0 => u | cons _ q, n + 1 => q.getVert n #align simple_graph.walk.get_vert SimpleGraph.Walk.getVert @[simp] theorem getVert_zero {u v} (w : G.Walk u v) : w.getVert 0 = u := by cases w <;> rfl #align simple_graph.walk.get_vert_zero SimpleGraph.Walk.getVert_zero theorem getVert_of_length_le {u v} (w : G.Walk u v) {i : ℕ} (hi : w.length ≤ i) : w.getVert i = v := by induction w generalizing i with | nil => rfl | cons _ _ ih => cases i · cases hi · exact ih (Nat.succ_le_succ_iff.1 hi) #align simple_graph.walk.get_vert_of_length_le SimpleGraph.Walk.getVert_of_length_le @[simp] theorem getVert_length {u v} (w : G.Walk u v) : w.getVert w.length = v := w.getVert_of_length_le rfl.le #align simple_graph.walk.get_vert_length SimpleGraph.Walk.getVert_length theorem adj_getVert_succ {u v} (w : G.Walk u v) {i : ℕ} (hi : i < w.length) : G.Adj (w.getVert i) (w.getVert (i + 1)) := by induction w generalizing i with | nil => cases hi | cons hxy _ ih => cases i · simp [getVert, hxy] · exact ih (Nat.succ_lt_succ_iff.1 hi) #align simple_graph.walk.adj_get_vert_succ SimpleGraph.Walk.adj_getVert_succ @[simp] theorem cons_append {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (q : G.Walk w x) : (cons h p).append q = cons h (p.append q) := rfl #align simple_graph.walk.cons_append SimpleGraph.Walk.cons_append @[simp] theorem cons_nil_append {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h nil).append p = cons h p := rfl #align simple_graph.walk.cons_nil_append SimpleGraph.Walk.cons_nil_append @[simp] theorem append_nil {u v : V} (p : G.Walk u v) : p.append nil = p := by induction p with | nil => rfl | cons _ _ ih => rw [cons_append, ih] #align simple_graph.walk.append_nil SimpleGraph.Walk.append_nil @[simp] theorem nil_append {u v : V} (p : G.Walk u v) : nil.append p = p := rfl #align simple_graph.walk.nil_append SimpleGraph.Walk.nil_append theorem append_assoc {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk w x) : p.append (q.append r) = (p.append q).append r := by induction p with | nil => rfl | cons h p' ih => dsimp only [append] rw [ih] #align simple_graph.walk.append_assoc SimpleGraph.Walk.append_assoc @[simp] theorem append_copy_copy {u v w u' v' w'} (p : G.Walk u v) (q : G.Walk v w) (hu : u = u') (hv : v = v') (hw : w = w') : (p.copy hu hv).append (q.copy hv hw) = (p.append q).copy hu hw := by subst_vars rfl #align simple_graph.walk.append_copy_copy SimpleGraph.Walk.append_copy_copy theorem concat_nil {u v : V} (h : G.Adj u v) : nil.concat h = cons h nil := rfl #align simple_graph.walk.concat_nil SimpleGraph.Walk.concat_nil @[simp] theorem concat_cons {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (h' : G.Adj w x) : (cons h p).concat h' = cons h (p.concat h') := rfl #align simple_graph.walk.concat_cons SimpleGraph.Walk.concat_cons theorem append_concat {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (h : G.Adj w x) : p.append (q.concat h) = (p.append q).concat h := append_assoc _ _ _ #align simple_graph.walk.append_concat SimpleGraph.Walk.append_concat theorem concat_append {u v w x : V} (p : G.Walk u v) (h : G.Adj v w) (q : G.Walk w x) : (p.concat h).append q = p.append (cons h q) := by rw [concat_eq_append, ← append_assoc, cons_nil_append] #align simple_graph.walk.concat_append SimpleGraph.Walk.concat_append /-- A non-trivial `cons` walk is representable as a `concat` walk. -/ theorem exists_cons_eq_concat {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : ∃ (x : V) (q : G.Walk u x) (h' : G.Adj x w), cons h p = q.concat h' := by induction p generalizing u with | nil => exact ⟨_, nil, h, rfl⟩ | cons h' p ih => obtain ⟨y, q, h'', hc⟩ := ih h' refine ⟨y, cons h q, h'', ?_⟩ rw [concat_cons, hc] #align simple_graph.walk.exists_cons_eq_concat SimpleGraph.Walk.exists_cons_eq_concat /-- A non-trivial `concat` walk is representable as a `cons` walk. -/ theorem exists_concat_eq_cons {u v w : V} : ∀ (p : G.Walk u v) (h : G.Adj v w), ∃ (x : V) (h' : G.Adj u x) (q : G.Walk x w), p.concat h = cons h' q | nil, h => ⟨_, h, nil, rfl⟩ | cons h' p, h => ⟨_, h', Walk.concat p h, concat_cons _ _ _⟩ #align simple_graph.walk.exists_concat_eq_cons SimpleGraph.Walk.exists_concat_eq_cons @[simp] theorem reverse_nil {u : V} : (nil : G.Walk u u).reverse = nil := rfl #align simple_graph.walk.reverse_nil SimpleGraph.Walk.reverse_nil theorem reverse_singleton {u v : V} (h : G.Adj u v) : (cons h nil).reverse = cons (G.symm h) nil := rfl #align simple_graph.walk.reverse_singleton SimpleGraph.Walk.reverse_singleton @[simp] theorem cons_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk w x) (h : G.Adj w u) : (cons h p).reverseAux q = p.reverseAux (cons (G.symm h) q) := rfl #align simple_graph.walk.cons_reverse_aux SimpleGraph.Walk.cons_reverseAux @[simp] protected theorem append_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk u x) : (p.append q).reverseAux r = q.reverseAux (p.reverseAux r) := by induction p with | nil => rfl | cons h _ ih => exact ih q (cons (G.symm h) r) #align simple_graph.walk.append_reverse_aux SimpleGraph.Walk.append_reverseAux @[simp] protected theorem reverseAux_append {u v w x : V} (p : G.Walk u v) (q : G.Walk u w) (r : G.Walk w x) : (p.reverseAux q).append r = p.reverseAux (q.append r) := by induction p with | nil => rfl | cons h _ ih => simp [ih (cons (G.symm h) q)] #align simple_graph.walk.reverse_aux_append SimpleGraph.Walk.reverseAux_append protected theorem reverseAux_eq_reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk u w) : p.reverseAux q = p.reverse.append q := by simp [reverse] #align simple_graph.walk.reverse_aux_eq_reverse_append SimpleGraph.Walk.reverseAux_eq_reverse_append @[simp] theorem reverse_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).reverse = p.reverse.append (cons (G.symm h) nil) := by simp [reverse] #align simple_graph.walk.reverse_cons SimpleGraph.Walk.reverse_cons @[simp]
Mathlib/Combinatorics/SimpleGraph/Connectivity.lean
352
355
theorem reverse_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).reverse = p.reverse.copy hv hu := by
subst_vars rfl
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov -/ import Mathlib.Data.Set.Prod import Mathlib.Logic.Function.Conjugate #align_import data.set.function from "leanprover-community/mathlib"@"996b0ff959da753a555053a480f36e5f264d4207" /-! # Functions over sets ## Main definitions ### Predicate * `Set.EqOn f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`; * `Set.MapsTo f s t` : `f` sends every point of `s` to a point of `t`; * `Set.InjOn f s` : restriction of `f` to `s` is injective; * `Set.SurjOn f s t` : every point in `s` has a preimage in `s`; * `Set.BijOn f s t` : `f` is a bijection between `s` and `t`; * `Set.LeftInvOn f' f s` : for every `x ∈ s` we have `f' (f x) = x`; * `Set.RightInvOn f' f t` : for every `y ∈ t` we have `f (f' y) = y`; * `Set.InvOn f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e. we have `Set.LeftInvOn f' f s` and `Set.RightInvOn f' f t`. ### Functions * `Set.restrict f s` : restrict the domain of `f` to the set `s`; * `Set.codRestrict f s h` : given `h : ∀ x, f x ∈ s`, restrict the codomain of `f` to the set `s`; * `Set.MapsTo.restrict f s t h`: given `h : MapsTo f s t`, restrict the domain of `f` to `s` and the codomain to `t`. -/ variable {α β γ : Type*} {ι : Sort*} {π : α → Type*} open Equiv Equiv.Perm Function namespace Set /-! ### Restrict -/ section restrict /-- Restrict domain of a function `f` to a set `s`. Same as `Subtype.restrict` but this version takes an argument `↥s` instead of `Subtype s`. -/ def restrict (s : Set α) (f : ∀ a : α, π a) : ∀ a : s, π a := fun x => f x #align set.restrict Set.restrict theorem restrict_eq (f : α → β) (s : Set α) : s.restrict f = f ∘ Subtype.val := rfl #align set.restrict_eq Set.restrict_eq @[simp] theorem restrict_apply (f : α → β) (s : Set α) (x : s) : s.restrict f x = f x := rfl #align set.restrict_apply Set.restrict_apply theorem restrict_eq_iff {f : ∀ a, π a} {s : Set α} {g : ∀ a : s, π a} : restrict s f = g ↔ ∀ (a) (ha : a ∈ s), f a = g ⟨a, ha⟩ := funext_iff.trans Subtype.forall #align set.restrict_eq_iff Set.restrict_eq_iff theorem eq_restrict_iff {s : Set α} {f : ∀ a : s, π a} {g : ∀ a, π a} : f = restrict s g ↔ ∀ (a) (ha : a ∈ s), f ⟨a, ha⟩ = g a := funext_iff.trans Subtype.forall #align set.eq_restrict_iff Set.eq_restrict_iff @[simp] theorem range_restrict (f : α → β) (s : Set α) : Set.range (s.restrict f) = f '' s := (range_comp _ _).trans <| congr_arg (f '' ·) Subtype.range_coe #align set.range_restrict Set.range_restrict theorem image_restrict (f : α → β) (s t : Set α) : s.restrict f '' (Subtype.val ⁻¹' t) = f '' (t ∩ s) := by rw [restrict_eq, image_comp, image_preimage_eq_inter_range, Subtype.range_coe] #align set.image_restrict Set.image_restrict @[simp] theorem restrict_dite {s : Set α} [∀ x, Decidable (x ∈ s)] (f : ∀ a ∈ s, β) (g : ∀ a ∉ s, β) : (s.restrict fun a => if h : a ∈ s then f a h else g a h) = (fun a : s => f a a.2) := funext fun a => dif_pos a.2 #align set.restrict_dite Set.restrict_dite @[simp] theorem restrict_dite_compl {s : Set α} [∀ x, Decidable (x ∈ s)] (f : ∀ a ∈ s, β) (g : ∀ a ∉ s, β) : (sᶜ.restrict fun a => if h : a ∈ s then f a h else g a h) = (fun a : (sᶜ : Set α) => g a a.2) := funext fun a => dif_neg a.2 #align set.restrict_dite_compl Set.restrict_dite_compl @[simp] theorem restrict_ite (f g : α → β) (s : Set α) [∀ x, Decidable (x ∈ s)] : (s.restrict fun a => if a ∈ s then f a else g a) = s.restrict f := restrict_dite _ _ #align set.restrict_ite Set.restrict_ite @[simp] theorem restrict_ite_compl (f g : α → β) (s : Set α) [∀ x, Decidable (x ∈ s)] : (sᶜ.restrict fun a => if a ∈ s then f a else g a) = sᶜ.restrict g := restrict_dite_compl _ _ #align set.restrict_ite_compl Set.restrict_ite_compl @[simp] theorem restrict_piecewise (f g : α → β) (s : Set α) [∀ x, Decidable (x ∈ s)] : s.restrict (piecewise s f g) = s.restrict f := restrict_ite _ _ _ #align set.restrict_piecewise Set.restrict_piecewise @[simp] theorem restrict_piecewise_compl (f g : α → β) (s : Set α) [∀ x, Decidable (x ∈ s)] : sᶜ.restrict (piecewise s f g) = sᶜ.restrict g := restrict_ite_compl _ _ _ #align set.restrict_piecewise_compl Set.restrict_piecewise_compl theorem restrict_extend_range (f : α → β) (g : α → γ) (g' : β → γ) : (range f).restrict (extend f g g') = fun x => g x.coe_prop.choose := by classical exact restrict_dite _ _ #align set.restrict_extend_range Set.restrict_extend_range @[simp] theorem restrict_extend_compl_range (f : α → β) (g : α → γ) (g' : β → γ) : (range f)ᶜ.restrict (extend f g g') = g' ∘ Subtype.val := by classical exact restrict_dite_compl _ _ #align set.restrict_extend_compl_range Set.restrict_extend_compl_range theorem range_extend_subset (f : α → β) (g : α → γ) (g' : β → γ) : range (extend f g g') ⊆ range g ∪ g' '' (range f)ᶜ := by classical rintro _ ⟨y, rfl⟩ rw [extend_def] split_ifs with h exacts [Or.inl (mem_range_self _), Or.inr (mem_image_of_mem _ h)] #align set.range_extend_subset Set.range_extend_subset theorem range_extend {f : α → β} (hf : Injective f) (g : α → γ) (g' : β → γ) : range (extend f g g') = range g ∪ g' '' (range f)ᶜ := by refine (range_extend_subset _ _ _).antisymm ?_ rintro z (⟨x, rfl⟩ | ⟨y, hy, rfl⟩) exacts [⟨f x, hf.extend_apply _ _ _⟩, ⟨y, extend_apply' _ _ _ hy⟩] #align set.range_extend Set.range_extend /-- Restrict codomain of a function `f` to a set `s`. Same as `Subtype.coind` but this version has codomain `↥s` instead of `Subtype s`. -/ def codRestrict (f : ι → α) (s : Set α) (h : ∀ x, f x ∈ s) : ι → s := fun x => ⟨f x, h x⟩ #align set.cod_restrict Set.codRestrict @[simp] theorem val_codRestrict_apply (f : ι → α) (s : Set α) (h : ∀ x, f x ∈ s) (x : ι) : (codRestrict f s h x : α) = f x := rfl #align set.coe_cod_restrict_apply Set.val_codRestrict_apply @[simp] theorem restrict_comp_codRestrict {f : ι → α} {g : α → β} {b : Set α} (h : ∀ x, f x ∈ b) : b.restrict g ∘ b.codRestrict f h = g ∘ f := rfl #align set.restrict_comp_cod_restrict Set.restrict_comp_codRestrict @[simp] theorem injective_codRestrict {f : ι → α} {s : Set α} (h : ∀ x, f x ∈ s) : Injective (codRestrict f s h) ↔ Injective f := by simp only [Injective, Subtype.ext_iff, val_codRestrict_apply] #align set.injective_cod_restrict Set.injective_codRestrict alias ⟨_, _root_.Function.Injective.codRestrict⟩ := injective_codRestrict #align function.injective.cod_restrict Function.Injective.codRestrict end restrict /-! ### Equality on a set -/ section equality variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ f₃ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} @[simp] theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim #align set.eq_on_empty Set.eqOn_empty @[simp] theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by simp [Set.EqOn] #align set.eq_on_singleton Set.eqOn_singleton @[simp] theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by simp [EqOn, funext_iff] @[simp] theorem restrict_eq_restrict_iff : restrict s f₁ = restrict s f₂ ↔ EqOn f₁ f₂ s := restrict_eq_iff #align set.restrict_eq_restrict_iff Set.restrict_eq_restrict_iff @[symm] theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm #align set.eq_on.symm Set.EqOn.symm theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s := ⟨EqOn.symm, EqOn.symm⟩ #align set.eq_on_comm Set.eqOn_comm -- This can not be tagged as `@[refl]` with the current argument order. -- See note below at `EqOn.trans`. theorem eqOn_refl (f : α → β) (s : Set α) : EqOn f f s := fun _ _ => rfl #align set.eq_on_refl Set.eqOn_refl -- Note: this was formerly tagged with `@[trans]`, and although the `trans` attribute accepted it -- the `trans` tactic could not use it. -- An update to the trans tactic coming in mathlib4#7014 will reject this attribute. -- It can be restored by changing the argument order from `EqOn f₁ f₂ s` to `EqOn s f₁ f₂`. -- This change will be made separately: [zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Reordering.20arguments.20of.20.60Set.2EEqOn.60/near/390467581). theorem EqOn.trans (h₁ : EqOn f₁ f₂ s) (h₂ : EqOn f₂ f₃ s) : EqOn f₁ f₃ s := fun _ hx => (h₁ hx).trans (h₂ hx) #align set.eq_on.trans Set.EqOn.trans theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s := image_congr heq #align set.eq_on.image_eq Set.EqOn.image_eq /-- Variant of `EqOn.image_eq`, for one function being the identity. -/ theorem EqOn.image_eq_self {f : α → α} (h : Set.EqOn f id s) : f '' s = s := by rw [h.image_eq, image_id] theorem EqOn.inter_preimage_eq (heq : EqOn f₁ f₂ s) (t : Set β) : s ∩ f₁ ⁻¹' t = s ∩ f₂ ⁻¹' t := ext fun x => and_congr_right_iff.2 fun hx => by rw [mem_preimage, mem_preimage, heq hx] #align set.eq_on.inter_preimage_eq Set.EqOn.inter_preimage_eq theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx) #align set.eq_on.mono Set.EqOn.mono @[simp] theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ := forall₂_or_left #align set.eq_on_union Set.eqOn_union theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) := eqOn_union.2 ⟨h₁, h₂⟩ #align set.eq_on.union Set.EqOn.union theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha => congr_arg _ <| h ha #align set.eq_on.comp_left Set.EqOn.comp_left @[simp] theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} : EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f := forall_mem_range.trans <| funext_iff.symm #align set.eq_on_range Set.eqOn_range alias ⟨EqOn.comp_eq, _⟩ := eqOn_range #align set.eq_on.comp_eq Set.EqOn.comp_eq end equality /-! ### Congruence lemmas for monotonicity and antitonicity -/ section Order variable {s : Set α} {f₁ f₂ : α → β} [Preorder α] [Preorder β] theorem _root_.MonotoneOn.congr (h₁ : MonotoneOn f₁ s) (h : s.EqOn f₁ f₂) : MonotoneOn f₂ s := by intro a ha b hb hab rw [← h ha, ← h hb] exact h₁ ha hb hab #align monotone_on.congr MonotoneOn.congr theorem _root_.AntitoneOn.congr (h₁ : AntitoneOn f₁ s) (h : s.EqOn f₁ f₂) : AntitoneOn f₂ s := h₁.dual_right.congr h #align antitone_on.congr AntitoneOn.congr theorem _root_.StrictMonoOn.congr (h₁ : StrictMonoOn f₁ s) (h : s.EqOn f₁ f₂) : StrictMonoOn f₂ s := by intro a ha b hb hab rw [← h ha, ← h hb] exact h₁ ha hb hab #align strict_mono_on.congr StrictMonoOn.congr theorem _root_.StrictAntiOn.congr (h₁ : StrictAntiOn f₁ s) (h : s.EqOn f₁ f₂) : StrictAntiOn f₂ s := h₁.dual_right.congr h #align strict_anti_on.congr StrictAntiOn.congr theorem EqOn.congr_monotoneOn (h : s.EqOn f₁ f₂) : MonotoneOn f₁ s ↔ MonotoneOn f₂ s := ⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩ #align set.eq_on.congr_monotone_on Set.EqOn.congr_monotoneOn theorem EqOn.congr_antitoneOn (h : s.EqOn f₁ f₂) : AntitoneOn f₁ s ↔ AntitoneOn f₂ s := ⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩ #align set.eq_on.congr_antitone_on Set.EqOn.congr_antitoneOn theorem EqOn.congr_strictMonoOn (h : s.EqOn f₁ f₂) : StrictMonoOn f₁ s ↔ StrictMonoOn f₂ s := ⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩ #align set.eq_on.congr_strict_mono_on Set.EqOn.congr_strictMonoOn theorem EqOn.congr_strictAntiOn (h : s.EqOn f₁ f₂) : StrictAntiOn f₁ s ↔ StrictAntiOn f₂ s := ⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩ #align set.eq_on.congr_strict_anti_on Set.EqOn.congr_strictAntiOn end Order /-! ### Monotonicity lemmas-/ section Mono variable {s s₁ s₂ : Set α} {f f₁ f₂ : α → β} [Preorder α] [Preorder β] theorem _root_.MonotoneOn.mono (h : MonotoneOn f s) (h' : s₂ ⊆ s) : MonotoneOn f s₂ := fun _ hx _ hy => h (h' hx) (h' hy) #align monotone_on.mono MonotoneOn.mono theorem _root_.AntitoneOn.mono (h : AntitoneOn f s) (h' : s₂ ⊆ s) : AntitoneOn f s₂ := fun _ hx _ hy => h (h' hx) (h' hy) #align antitone_on.mono AntitoneOn.mono theorem _root_.StrictMonoOn.mono (h : StrictMonoOn f s) (h' : s₂ ⊆ s) : StrictMonoOn f s₂ := fun _ hx _ hy => h (h' hx) (h' hy) #align strict_mono_on.mono StrictMonoOn.mono theorem _root_.StrictAntiOn.mono (h : StrictAntiOn f s) (h' : s₂ ⊆ s) : StrictAntiOn f s₂ := fun _ hx _ hy => h (h' hx) (h' hy) #align strict_anti_on.mono StrictAntiOn.mono protected theorem _root_.MonotoneOn.monotone (h : MonotoneOn f s) : Monotone (f ∘ Subtype.val : s → β) := fun x y hle => h x.coe_prop y.coe_prop hle #align monotone_on.monotone MonotoneOn.monotone protected theorem _root_.AntitoneOn.monotone (h : AntitoneOn f s) : Antitone (f ∘ Subtype.val : s → β) := fun x y hle => h x.coe_prop y.coe_prop hle #align antitone_on.monotone AntitoneOn.monotone protected theorem _root_.StrictMonoOn.strictMono (h : StrictMonoOn f s) : StrictMono (f ∘ Subtype.val : s → β) := fun x y hlt => h x.coe_prop y.coe_prop hlt #align strict_mono_on.strict_mono StrictMonoOn.strictMono protected theorem _root_.StrictAntiOn.strictAnti (h : StrictAntiOn f s) : StrictAnti (f ∘ Subtype.val : s → β) := fun x y hlt => h x.coe_prop y.coe_prop hlt #align strict_anti_on.strict_anti StrictAntiOn.strictAnti end Mono variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ f₃ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} section MapsTo theorem MapsTo.restrict_commutes (f : α → β) (s : Set α) (t : Set β) (h : MapsTo f s t) : Subtype.val ∘ h.restrict f s t = f ∘ Subtype.val := rfl @[simp] theorem MapsTo.val_restrict_apply (h : MapsTo f s t) (x : s) : (h.restrict f s t x : β) = f x := rfl #align set.maps_to.coe_restrict_apply Set.MapsTo.val_restrict_apply theorem MapsTo.coe_iterate_restrict {f : α → α} (h : MapsTo f s s) (x : s) (k : ℕ) : h.restrict^[k] x = f^[k] x := by induction' k with k ih; · simp simp only [iterate_succ', comp_apply, val_restrict_apply, ih] /-- Restricting the domain and then the codomain is the same as `MapsTo.restrict`. -/ @[simp] theorem codRestrict_restrict (h : ∀ x : s, f x ∈ t) : codRestrict (s.restrict f) t h = MapsTo.restrict f s t fun x hx => h ⟨x, hx⟩ := rfl #align set.cod_restrict_restrict Set.codRestrict_restrict /-- Reverse of `Set.codRestrict_restrict`. -/ theorem MapsTo.restrict_eq_codRestrict (h : MapsTo f s t) : h.restrict f s t = codRestrict (s.restrict f) t fun x => h x.2 := rfl #align set.maps_to.restrict_eq_cod_restrict Set.MapsTo.restrict_eq_codRestrict theorem MapsTo.coe_restrict (h : Set.MapsTo f s t) : Subtype.val ∘ h.restrict f s t = s.restrict f := rfl #align set.maps_to.coe_restrict Set.MapsTo.coe_restrict theorem MapsTo.range_restrict (f : α → β) (s : Set α) (t : Set β) (h : MapsTo f s t) : range (h.restrict f s t) = Subtype.val ⁻¹' (f '' s) := Set.range_subtype_map f h #align set.maps_to.range_restrict Set.MapsTo.range_restrict theorem mapsTo_iff_exists_map_subtype : MapsTo f s t ↔ ∃ g : s → t, ∀ x : s, f x = g x := ⟨fun h => ⟨h.restrict f s t, fun _ => rfl⟩, fun ⟨g, hg⟩ x hx => by erw [hg ⟨x, hx⟩] apply Subtype.coe_prop⟩ #align set.maps_to_iff_exists_map_subtype Set.mapsTo_iff_exists_map_subtype theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t := image_subset_iff.symm #align set.maps_to' Set.mapsTo' theorem mapsTo_prod_map_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) := diagonal_subset_iff.2 fun _ => rfl #align set.maps_to_prod_map_diagonal Set.mapsTo_prod_map_diagonal theorem MapsTo.subset_preimage {f : α → β} {s : Set α} {t : Set β} (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf #align set.maps_to.subset_preimage Set.MapsTo.subset_preimage @[simp] theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t := singleton_subset_iff #align set.maps_to_singleton Set.mapsTo_singleton theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t := empty_subset _ #align set.maps_to_empty Set.mapsTo_empty @[simp] theorem mapsTo_empty_iff : MapsTo f s ∅ ↔ s = ∅ := by simp [mapsTo', subset_empty_iff] /-- If `f` maps `s` to `t` and `s` is non-empty, `t` is non-empty. -/ theorem MapsTo.nonempty (h : MapsTo f s t) (hs : s.Nonempty) : t.Nonempty := (hs.image f).mono (mapsTo'.mp h) theorem MapsTo.image_subset (h : MapsTo f s t) : f '' s ⊆ t := mapsTo'.1 h #align set.maps_to.image_subset Set.MapsTo.image_subset theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx => h hx ▸ h₁ hx #align set.maps_to.congr Set.MapsTo.congr theorem EqOn.comp_right (hg : t.EqOn g₁ g₂) (hf : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) := fun _ ha => hg <| hf ha #align set.eq_on.comp_right Set.EqOn.comp_right theorem EqOn.mapsTo_iff (H : EqOn f₁ f₂ s) : MapsTo f₁ s t ↔ MapsTo f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ #align set.eq_on.maps_to_iff Set.EqOn.mapsTo_iff theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h => h₁ (h₂ h) #align set.maps_to.comp Set.MapsTo.comp theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => id #align set.maps_to_id Set.mapsTo_id theorem MapsTo.iterate {f : α → α} {s : Set α} (h : MapsTo f s s) : ∀ n, MapsTo f^[n] s s | 0 => fun _ => id | n + 1 => (MapsTo.iterate h n).comp h #align set.maps_to.iterate Set.MapsTo.iterate theorem MapsTo.iterate_restrict {f : α → α} {s : Set α} (h : MapsTo f s s) (n : ℕ) : (h.restrict f s s)^[n] = (h.iterate n).restrict _ _ _ := by funext x rw [Subtype.ext_iff, MapsTo.val_restrict_apply] induction' n with n ihn generalizing x · rfl · simp [Nat.iterate, ihn] #align set.maps_to.iterate_restrict Set.MapsTo.iterate_restrict lemma mapsTo_of_subsingleton' [Subsingleton β] (f : α → β) (h : s.Nonempty → t.Nonempty) : MapsTo f s t := fun a ha ↦ Subsingleton.mem_iff_nonempty.2 <| h ⟨a, ha⟩ #align set.maps_to_of_subsingleton' Set.mapsTo_of_subsingleton' lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s := mapsTo_of_subsingleton' _ id #align set.maps_to_of_subsingleton Set.mapsTo_of_subsingleton theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ := fun _ hx => ht (hf <| hs hx) #align set.maps_to.mono Set.MapsTo.mono theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx => hf (hs hx) #align set.maps_to.mono_left Set.MapsTo.mono_left theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx => ht (hf hx) #align set.maps_to.mono_right Set.MapsTo.mono_right theorem MapsTo.union_union (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∪ s₂) (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => Or.inl <| h₁ hx) fun hx => Or.inr <| h₂ hx #align set.maps_to.union_union Set.MapsTo.union_union theorem MapsTo.union (h₁ : MapsTo f s₁ t) (h₂ : MapsTo f s₂ t) : MapsTo f (s₁ ∪ s₂) t := union_self t ▸ h₁.union_union h₂ #align set.maps_to.union Set.MapsTo.union @[simp] theorem mapsTo_union : MapsTo f (s₁ ∪ s₂) t ↔ MapsTo f s₁ t ∧ MapsTo f s₂ t := ⟨fun h => ⟨h.mono subset_union_left (Subset.refl t), h.mono subset_union_right (Subset.refl t)⟩, fun h => h.1.union h.2⟩ #align set.maps_to_union Set.mapsTo_union theorem MapsTo.inter (h₁ : MapsTo f s t₁) (h₂ : MapsTo f s t₂) : MapsTo f s (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx, h₂ hx⟩ #align set.maps_to.inter Set.MapsTo.inter theorem MapsTo.inter_inter (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∩ s₂) (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx.1, h₂ hx.2⟩ #align set.maps_to.inter_inter Set.MapsTo.inter_inter @[simp] theorem mapsTo_inter : MapsTo f s (t₁ ∩ t₂) ↔ MapsTo f s t₁ ∧ MapsTo f s t₂ := ⟨fun h => ⟨h.mono (Subset.refl s) inter_subset_left, h.mono (Subset.refl s) inter_subset_right⟩, fun h => h.1.inter h.2⟩ #align set.maps_to_inter Set.mapsTo_inter theorem mapsTo_univ (f : α → β) (s : Set α) : MapsTo f s univ := fun _ _ => trivial #align set.maps_to_univ Set.mapsTo_univ theorem mapsTo_range (f : α → β) (s : Set α) : MapsTo f s (range f) := (mapsTo_image f s).mono (Subset.refl s) (image_subset_range _ _) #align set.maps_to_range Set.mapsTo_range @[simp] theorem mapsTo_image_iff {f : α → β} {g : γ → α} {s : Set γ} {t : Set β} : MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t := ⟨fun h c hc => h ⟨c, hc, rfl⟩, fun h _ ⟨_, hc⟩ => hc.2 ▸ h hc.1⟩ #align set.maps_image_to Set.mapsTo_image_iff @[deprecated (since := "2023-12-25")] lemma maps_image_to (f : α → β) (g : γ → α) (s : Set γ) (t : Set β) : MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t := mapsTo_image_iff lemma MapsTo.comp_left (g : β → γ) (hf : MapsTo f s t) : MapsTo (g ∘ f) s (g '' t) := fun x hx ↦ ⟨f x, hf hx, rfl⟩ #align set.maps_to.comp_left Set.MapsTo.comp_left lemma MapsTo.comp_right {s : Set β} {t : Set γ} (hg : MapsTo g s t) (f : α → β) : MapsTo (g ∘ f) (f ⁻¹' s) t := fun _ hx ↦ hg hx #align set.maps_to.comp_right Set.MapsTo.comp_right @[simp] lemma mapsTo_univ_iff : MapsTo f univ t ↔ ∀ x, f x ∈ t := ⟨fun h _ => h (mem_univ _), fun h x _ => h x⟩ @[deprecated (since := "2023-12-25")] theorem maps_univ_to (f : α → β) (s : Set β) : MapsTo f univ s ↔ ∀ a, f a ∈ s := mapsTo_univ_iff #align set.maps_univ_to Set.maps_univ_to @[simp] lemma mapsTo_range_iff {g : ι → α} : MapsTo f (range g) t ↔ ∀ i, f (g i) ∈ t := forall_mem_range @[deprecated mapsTo_range_iff (since := "2023-12-25")] theorem maps_range_to (f : α → β) (g : γ → α) (s : Set β) : MapsTo f (range g) s ↔ MapsTo (f ∘ g) univ s := by rw [← image_univ, mapsTo_image_iff] #align set.maps_range_to Set.maps_range_to theorem surjective_mapsTo_image_restrict (f : α → β) (s : Set α) : Surjective ((mapsTo_image f s).restrict f s (f '' s)) := fun ⟨_, x, hs, hxy⟩ => ⟨⟨x, hs⟩, Subtype.ext hxy⟩ #align set.surjective_maps_to_image_restrict Set.surjective_mapsTo_image_restrict theorem MapsTo.mem_iff (h : MapsTo f s t) (hc : MapsTo f sᶜ tᶜ) {x} : f x ∈ t ↔ x ∈ s := ⟨fun ht => by_contra fun hs => hc hs ht, fun hx => h hx⟩ #align set.maps_to.mem_iff Set.MapsTo.mem_iff end MapsTo /-! ### Restriction onto preimage -/ section variable (t) variable (f s) in theorem image_restrictPreimage : t.restrictPreimage f '' (Subtype.val ⁻¹' s) = Subtype.val ⁻¹' (f '' s) := by delta Set.restrictPreimage rw [← (Subtype.coe_injective).image_injective.eq_iff, ← image_comp, MapsTo.restrict_commutes, image_comp, Subtype.image_preimage_coe, Subtype.image_preimage_coe, image_preimage_inter] variable (f) in theorem range_restrictPreimage : range (t.restrictPreimage f) = Subtype.val ⁻¹' range f := by simp only [← image_univ, ← image_restrictPreimage, preimage_univ] #align set.range_restrict_preimage Set.range_restrictPreimage variable {U : ι → Set β} lemma restrictPreimage_injective (hf : Injective f) : Injective (t.restrictPreimage f) := fun _ _ e => Subtype.coe_injective <| hf <| Subtype.mk.inj e #align set.restrict_preimage_injective Set.restrictPreimage_injective lemma restrictPreimage_surjective (hf : Surjective f) : Surjective (t.restrictPreimage f) := fun x => ⟨⟨_, ((hf x).choose_spec.symm ▸ x.2 : _ ∈ t)⟩, Subtype.ext (hf x).choose_spec⟩ #align set.restrict_preimage_surjective Set.restrictPreimage_surjective lemma restrictPreimage_bijective (hf : Bijective f) : Bijective (t.restrictPreimage f) := ⟨t.restrictPreimage_injective hf.1, t.restrictPreimage_surjective hf.2⟩ #align set.restrict_preimage_bijective Set.restrictPreimage_bijective alias _root_.Function.Injective.restrictPreimage := Set.restrictPreimage_injective alias _root_.Function.Surjective.restrictPreimage := Set.restrictPreimage_surjective alias _root_.Function.Bijective.restrictPreimage := Set.restrictPreimage_bijective #align function.bijective.restrict_preimage Function.Bijective.restrictPreimage #align function.surjective.restrict_preimage Function.Surjective.restrictPreimage #align function.injective.restrict_preimage Function.Injective.restrictPreimage end /-! ### Injectivity on a set -/ section injOn theorem Subsingleton.injOn (hs : s.Subsingleton) (f : α → β) : InjOn f s := fun _ hx _ hy _ => hs hx hy #align set.subsingleton.inj_on Set.Subsingleton.injOn @[simp] theorem injOn_empty (f : α → β) : InjOn f ∅ := subsingleton_empty.injOn f #align set.inj_on_empty Set.injOn_empty @[simp] theorem injOn_singleton (f : α → β) (a : α) : InjOn f {a} := subsingleton_singleton.injOn f #align set.inj_on_singleton Set.injOn_singleton @[simp] lemma injOn_pair {b : α} : InjOn f {a, b} ↔ f a = f b → a = b := by unfold InjOn; aesop theorem InjOn.eq_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x = f y ↔ x = y := ⟨h hx hy, fun h => h ▸ rfl⟩ #align set.inj_on.eq_iff Set.InjOn.eq_iff theorem InjOn.ne_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ≠ f y ↔ x ≠ y := (h.eq_iff hx hy).not #align set.inj_on.ne_iff Set.InjOn.ne_iff alias ⟨_, InjOn.ne⟩ := InjOn.ne_iff #align set.inj_on.ne Set.InjOn.ne theorem InjOn.congr (h₁ : InjOn f₁ s) (h : EqOn f₁ f₂ s) : InjOn f₂ s := fun _ hx _ hy => h hx ▸ h hy ▸ h₁ hx hy #align set.inj_on.congr Set.InjOn.congr theorem EqOn.injOn_iff (H : EqOn f₁ f₂ s) : InjOn f₁ s ↔ InjOn f₂ s := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ #align set.eq_on.inj_on_iff Set.EqOn.injOn_iff theorem InjOn.mono (h : s₁ ⊆ s₂) (ht : InjOn f s₂) : InjOn f s₁ := fun _ hx _ hy H => ht (h hx) (h hy) H #align set.inj_on.mono Set.InjOn.mono theorem injOn_union (h : Disjoint s₁ s₂) : InjOn f (s₁ ∪ s₂) ↔ InjOn f s₁ ∧ InjOn f s₂ ∧ ∀ x ∈ s₁, ∀ y ∈ s₂, f x ≠ f y := by refine ⟨fun H => ⟨H.mono subset_union_left, H.mono subset_union_right, ?_⟩, ?_⟩ · intro x hx y hy hxy obtain rfl : x = y := H (Or.inl hx) (Or.inr hy) hxy exact h.le_bot ⟨hx, hy⟩ · rintro ⟨h₁, h₂, h₁₂⟩ rintro x (hx | hx) y (hy | hy) hxy exacts [h₁ hx hy hxy, (h₁₂ _ hx _ hy hxy).elim, (h₁₂ _ hy _ hx hxy.symm).elim, h₂ hx hy hxy] #align set.inj_on_union Set.injOn_union theorem injOn_insert {f : α → β} {s : Set α} {a : α} (has : a ∉ s) : Set.InjOn f (insert a s) ↔ Set.InjOn f s ∧ f a ∉ f '' s := by rw [← union_singleton, injOn_union (disjoint_singleton_right.2 has)] simp #align set.inj_on_insert Set.injOn_insert theorem injective_iff_injOn_univ : Injective f ↔ InjOn f univ := ⟨fun h _ _ _ _ hxy => h hxy, fun h _ _ heq => h trivial trivial heq⟩ #align set.injective_iff_inj_on_univ Set.injective_iff_injOn_univ theorem injOn_of_injective (h : Injective f) {s : Set α} : InjOn f s := fun _ _ _ _ hxy => h hxy #align set.inj_on_of_injective Set.injOn_of_injective alias _root_.Function.Injective.injOn := injOn_of_injective #align function.injective.inj_on Function.Injective.injOn -- A specialization of `injOn_of_injective` for `Subtype.val`. theorem injOn_subtype_val {s : Set { x // p x }} : Set.InjOn Subtype.val s := Subtype.coe_injective.injOn lemma injOn_id (s : Set α) : InjOn id s := injective_id.injOn #align set.inj_on_id Set.injOn_id theorem InjOn.comp (hg : InjOn g t) (hf : InjOn f s) (h : MapsTo f s t) : InjOn (g ∘ f) s := fun _ hx _ hy heq => hf hx hy <| hg (h hx) (h hy) heq #align set.inj_on.comp Set.InjOn.comp lemma InjOn.image_of_comp (h : InjOn (g ∘ f) s) : InjOn g (f '' s) := forall_mem_image.2 fun _x hx ↦ forall_mem_image.2 fun _y hy heq ↦ congr_arg f <| h hx hy heq lemma InjOn.iterate {f : α → α} {s : Set α} (h : InjOn f s) (hf : MapsTo f s s) : ∀ n, InjOn f^[n] s | 0 => injOn_id _ | (n + 1) => (h.iterate hf n).comp h hf #align set.inj_on.iterate Set.InjOn.iterate lemma injOn_of_subsingleton [Subsingleton α] (f : α → β) (s : Set α) : InjOn f s := (injective_of_subsingleton _).injOn #align set.inj_on_of_subsingleton Set.injOn_of_subsingleton
Mathlib/Data/Set/Function.lean
701
703
theorem _root_.Function.Injective.injOn_range (h : Injective (g ∘ f)) : InjOn g (range f) := by
rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ H exact congr_arg f (h H)
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.MeasureTheory.Integral.Lebesgue /-! # Measure with a given density with respect to another measure For a measure `μ` on `α` and a function `f : α → ℝ≥0∞`, we define a new measure `μ.withDensity f`. On a measurable set `s`, that measure has value `∫⁻ a in s, f a ∂μ`. An important result about `withDensity` is the Radon-Nikodym theorem. It states that, given measures `μ, ν`, if `HaveLebesgueDecomposition μ ν` then `μ` is absolutely continuous with respect to `ν` if and only if there exists a measurable function `f : α → ℝ≥0∞` such that `μ = ν.withDensity f`. See `MeasureTheory.Measure.absolutelyContinuous_iff_withDensity_rnDeriv_eq`. -/ open Set hiding restrict restrict_apply open Filter ENNReal NNReal MeasureTheory.Measure namespace MeasureTheory variable {α : Type*} {m0 : MeasurableSpace α} {μ : Measure α} /-- Given a measure `μ : Measure α` and a function `f : α → ℝ≥0∞`, `μ.withDensity f` is the measure such that for a measurable set `s` we have `μ.withDensity f s = ∫⁻ a in s, f a ∂μ`. -/ noncomputable def Measure.withDensity {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : Measure α := Measure.ofMeasurable (fun s _ => ∫⁻ a in s, f a ∂μ) (by simp) fun s hs hd => lintegral_iUnion hs hd _ #align measure_theory.measure.with_density MeasureTheory.Measure.withDensity @[simp] theorem withDensity_apply (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := Measure.ofMeasurable_apply s hs #align measure_theory.with_density_apply MeasureTheory.withDensity_apply theorem withDensity_apply_le (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂μ ≤ μ.withDensity f s := by let t := toMeasurable (μ.withDensity f) s calc ∫⁻ a in s, f a ∂μ ≤ ∫⁻ a in t, f a ∂μ := lintegral_mono_set (subset_toMeasurable (withDensity μ f) s) _ = μ.withDensity f t := (withDensity_apply f (measurableSet_toMeasurable (withDensity μ f) s)).symm _ = μ.withDensity f s := measure_toMeasurable s /-! In the next theorem, the s-finiteness assumption is necessary. Here is a counterexample without this assumption. Let `α` be an uncountable space, let `x₀` be some fixed point, and consider the σ-algebra made of those sets which are countable and do not contain `x₀`, and of their complements. This is the σ-algebra generated by the sets `{x}` for `x ≠ x₀`. Define a measure equal to `+∞` on nonempty sets. Let `s = {x₀}` and `f` the indicator of `sᶜ`. Then * `∫⁻ a in s, f a ∂μ = 0`. Indeed, consider a simple function `g ≤ f`. It vanishes on `s`. Then `∫⁻ a in s, g a ∂μ = 0`. Taking the supremum over `g` gives the claim. * `μ.withDensity f s = +∞`. Indeed, this is the infimum of `μ.withDensity f t` over measurable sets `t` containing `s`. As `s` is not measurable, such a set `t` contains a point `x ≠ x₀`. Then `μ.withDensity f t ≥ μ.withDensity f {x} = ∫⁻ a in {x}, f a ∂μ = μ {x} = +∞`. One checks that `μ.withDensity f = μ`, while `μ.restrict s` gives zero mass to sets not containing `x₀`, and infinite mass to those that contain it. -/ theorem withDensity_apply' [SFinite μ] (f : α → ℝ≥0∞) (s : Set α) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := by apply le_antisymm ?_ (withDensity_apply_le f s) let t := toMeasurable μ s calc μ.withDensity f s ≤ μ.withDensity f t := measure_mono (subset_toMeasurable μ s) _ = ∫⁻ a in t, f a ∂μ := withDensity_apply f (measurableSet_toMeasurable μ s) _ = ∫⁻ a in s, f a ∂μ := by congr 1; exact restrict_toMeasurable_of_sFinite s @[simp] lemma withDensity_zero_left (f : α → ℝ≥0∞) : (0 : Measure α).withDensity f = 0 := by ext s hs rw [withDensity_apply _ hs] simp theorem withDensity_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : μ.withDensity f = μ.withDensity g := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, withDensity_apply _ hs] exact lintegral_congr_ae (ae_restrict_of_ae h) #align measure_theory.with_density_congr_ae MeasureTheory.withDensity_congr_ae lemma withDensity_mono {f g : α → ℝ≥0∞} (hfg : f ≤ᵐ[μ] g) : μ.withDensity f ≤ μ.withDensity g := by refine le_iff.2 fun s hs ↦ ?_ rw [withDensity_apply _ hs, withDensity_apply _ hs] refine set_lintegral_mono_ae' hs ?_ filter_upwards [hfg] with x h_le using fun _ ↦ h_le theorem withDensity_add_left {f : α → ℝ≥0∞} (hf : Measurable f) (g : α → ℝ≥0∞) : μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.add_apply, withDensity_apply _ hs, withDensity_apply _ hs, ← lintegral_add_left hf] simp only [Pi.add_apply] #align measure_theory.with_density_add_left MeasureTheory.withDensity_add_left theorem withDensity_add_right (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : Measurable g) : μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by simpa only [add_comm] using withDensity_add_left hg f #align measure_theory.with_density_add_right MeasureTheory.withDensity_add_right theorem withDensity_add_measure {m : MeasurableSpace α} (μ ν : Measure α) (f : α → ℝ≥0∞) : (μ + ν).withDensity f = μ.withDensity f + ν.withDensity f := by ext1 s hs simp only [withDensity_apply f hs, restrict_add, lintegral_add_measure, Measure.add_apply] #align measure_theory.with_density_add_measure MeasureTheory.withDensity_add_measure theorem withDensity_sum {ι : Type*} {m : MeasurableSpace α} (μ : ι → Measure α) (f : α → ℝ≥0∞) : (sum μ).withDensity f = sum fun n => (μ n).withDensity f := by ext1 s hs simp_rw [sum_apply _ hs, withDensity_apply f hs, restrict_sum μ hs, lintegral_sum_measure] #align measure_theory.with_density_sum MeasureTheory.withDensity_sum theorem withDensity_smul (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : μ.withDensity (r • f) = r • μ.withDensity f := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, ← lintegral_const_mul r hf] simp only [Pi.smul_apply, smul_eq_mul] #align measure_theory.with_density_smul MeasureTheory.withDensity_smul theorem withDensity_smul' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : μ.withDensity (r • f) = r • μ.withDensity f := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, ← lintegral_const_mul' r f hr] simp only [Pi.smul_apply, smul_eq_mul] #align measure_theory.with_density_smul' MeasureTheory.withDensity_smul' theorem withDensity_smul_measure (r : ℝ≥0∞) (f : α → ℝ≥0∞) : (r • μ).withDensity f = r • μ.withDensity f := by ext s hs rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, set_lintegral_smul_measure] theorem isFiniteMeasure_withDensity {f : α → ℝ≥0∞} (hf : ∫⁻ a, f a ∂μ ≠ ∞) : IsFiniteMeasure (μ.withDensity f) := { measure_univ_lt_top := by rwa [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ, lt_top_iff_ne_top] } #align measure_theory.is_finite_measure_with_density MeasureTheory.isFiniteMeasure_withDensity theorem withDensity_absolutelyContinuous {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : μ.withDensity f ≪ μ := by refine AbsolutelyContinuous.mk fun s hs₁ hs₂ => ?_ rw [withDensity_apply _ hs₁] exact set_lintegral_measure_zero _ _ hs₂ #align measure_theory.with_density_absolutely_continuous MeasureTheory.withDensity_absolutelyContinuous @[simp] theorem withDensity_zero : μ.withDensity 0 = 0 := by ext1 s hs simp [withDensity_apply _ hs] #align measure_theory.with_density_zero MeasureTheory.withDensity_zero @[simp] theorem withDensity_one : μ.withDensity 1 = μ := by ext1 s hs simp [withDensity_apply _ hs] #align measure_theory.with_density_one MeasureTheory.withDensity_one @[simp] theorem withDensity_const (c : ℝ≥0∞) : μ.withDensity (fun _ ↦ c) = c • μ := by ext1 s hs simp [withDensity_apply _ hs] theorem withDensity_tsum {f : ℕ → α → ℝ≥0∞} (h : ∀ i, Measurable (f i)) : μ.withDensity (∑' n, f n) = sum fun n => μ.withDensity (f n) := by ext1 s hs simp_rw [sum_apply _ hs, withDensity_apply _ hs] change ∫⁻ x in s, (∑' n, f n) x ∂μ = ∑' i : ℕ, ∫⁻ x, f i x ∂μ.restrict s rw [← lintegral_tsum fun i => (h i).aemeasurable] exact lintegral_congr fun x => tsum_apply (Pi.summable.2 fun _ => ENNReal.summable) #align measure_theory.with_density_tsum MeasureTheory.withDensity_tsum
Mathlib/MeasureTheory/Measure/WithDensity.lean
183
187
theorem withDensity_indicator {s : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) : μ.withDensity (s.indicator f) = (μ.restrict s).withDensity f := by
ext1 t ht rw [withDensity_apply _ ht, lintegral_indicator _ hs, restrict_comm hs, ← withDensity_apply _ ht]
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.FDeriv.Bilinear #align_import analysis.calculus.fderiv.mul from "leanprover-community/mathlib"@"d608fc5d4e69d4cc21885913fb573a88b0deb521" /-! # Multiplicative operations on derivatives For detailed documentation of the Fréchet derivative, see the module docstring of `Mathlib/Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of * multiplication of a function by a scalar function * product of finitely many scalar functions * taking the pointwise multiplicative inverse (i.e. `Inv.inv` or `Ring.inverse`) of a function -/ open scoped Classical open Filter Asymptotics ContinuousLinearMap Set Metric Topology NNReal ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} section CLMCompApply /-! ### Derivative of the pointwise composition/application of continuous linear maps -/ variable {H : Type*} [NormedAddCommGroup H] [NormedSpace 𝕜 H] {c : E → G →L[𝕜] H} {c' : E →L[𝕜] G →L[𝕜] H} {d : E → F →L[𝕜] G} {d' : E →L[𝕜] F →L[𝕜] G} {u : E → G} {u' : E →L[𝕜] G} @[fun_prop] theorem HasStrictFDerivAt.clm_comp (hc : HasStrictFDerivAt c c' x) (hd : HasStrictFDerivAt d d' x) : HasStrictFDerivAt (fun y => (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x := (isBoundedBilinearMap_comp.hasStrictFDerivAt (c x, d x)).comp x <| hc.prod hd #align has_strict_fderiv_at.clm_comp HasStrictFDerivAt.clm_comp @[fun_prop] theorem HasFDerivWithinAt.clm_comp (hc : HasFDerivWithinAt c c' s x) (hd : HasFDerivWithinAt d d' s x) : HasFDerivWithinAt (fun y => (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') s x := (isBoundedBilinearMap_comp.hasFDerivAt (c x, d x)).comp_hasFDerivWithinAt x <| hc.prod hd #align has_fderiv_within_at.clm_comp HasFDerivWithinAt.clm_comp @[fun_prop] theorem HasFDerivAt.clm_comp (hc : HasFDerivAt c c' x) (hd : HasFDerivAt d d' x) : HasFDerivAt (fun y => (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x := (isBoundedBilinearMap_comp.hasFDerivAt (c x, d x)).comp x <| hc.prod hd #align has_fderiv_at.clm_comp HasFDerivAt.clm_comp @[fun_prop] theorem DifferentiableWithinAt.clm_comp (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) : DifferentiableWithinAt 𝕜 (fun y => (c y).comp (d y)) s x := (hc.hasFDerivWithinAt.clm_comp hd.hasFDerivWithinAt).differentiableWithinAt #align differentiable_within_at.clm_comp DifferentiableWithinAt.clm_comp @[fun_prop] theorem DifferentiableAt.clm_comp (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : DifferentiableAt 𝕜 (fun y => (c y).comp (d y)) x := (hc.hasFDerivAt.clm_comp hd.hasFDerivAt).differentiableAt #align differentiable_at.clm_comp DifferentiableAt.clm_comp @[fun_prop] theorem DifferentiableOn.clm_comp (hc : DifferentiableOn 𝕜 c s) (hd : DifferentiableOn 𝕜 d s) : DifferentiableOn 𝕜 (fun y => (c y).comp (d y)) s := fun x hx => (hc x hx).clm_comp (hd x hx) #align differentiable_on.clm_comp DifferentiableOn.clm_comp @[fun_prop] theorem Differentiable.clm_comp (hc : Differentiable 𝕜 c) (hd : Differentiable 𝕜 d) : Differentiable 𝕜 fun y => (c y).comp (d y) := fun x => (hc x).clm_comp (hd x) #align differentiable.clm_comp Differentiable.clm_comp theorem fderivWithin_clm_comp (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) : fderivWithin 𝕜 (fun y => (c y).comp (d y)) s x = (compL 𝕜 F G H (c x)).comp (fderivWithin 𝕜 d s x) + ((compL 𝕜 F G H).flip (d x)).comp (fderivWithin 𝕜 c s x) := (hc.hasFDerivWithinAt.clm_comp hd.hasFDerivWithinAt).fderivWithin hxs #align fderiv_within_clm_comp fderivWithin_clm_comp theorem fderiv_clm_comp (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : fderiv 𝕜 (fun y => (c y).comp (d y)) x = (compL 𝕜 F G H (c x)).comp (fderiv 𝕜 d x) + ((compL 𝕜 F G H).flip (d x)).comp (fderiv 𝕜 c x) := (hc.hasFDerivAt.clm_comp hd.hasFDerivAt).fderiv #align fderiv_clm_comp fderiv_clm_comp @[fun_prop] theorem HasStrictFDerivAt.clm_apply (hc : HasStrictFDerivAt c c' x) (hu : HasStrictFDerivAt u u' x) : HasStrictFDerivAt (fun y => (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x := (isBoundedBilinearMap_apply.hasStrictFDerivAt (c x, u x)).comp x (hc.prod hu) #align has_strict_fderiv_at.clm_apply HasStrictFDerivAt.clm_apply @[fun_prop] theorem HasFDerivWithinAt.clm_apply (hc : HasFDerivWithinAt c c' s x) (hu : HasFDerivWithinAt u u' s x) : HasFDerivWithinAt (fun y => (c y) (u y)) ((c x).comp u' + c'.flip (u x)) s x := (isBoundedBilinearMap_apply.hasFDerivAt (c x, u x)).comp_hasFDerivWithinAt x (hc.prod hu) #align has_fderiv_within_at.clm_apply HasFDerivWithinAt.clm_apply @[fun_prop] theorem HasFDerivAt.clm_apply (hc : HasFDerivAt c c' x) (hu : HasFDerivAt u u' x) : HasFDerivAt (fun y => (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x := (isBoundedBilinearMap_apply.hasFDerivAt (c x, u x)).comp x (hc.prod hu) #align has_fderiv_at.clm_apply HasFDerivAt.clm_apply @[fun_prop] theorem DifferentiableWithinAt.clm_apply (hc : DifferentiableWithinAt 𝕜 c s x) (hu : DifferentiableWithinAt 𝕜 u s x) : DifferentiableWithinAt 𝕜 (fun y => (c y) (u y)) s x := (hc.hasFDerivWithinAt.clm_apply hu.hasFDerivWithinAt).differentiableWithinAt #align differentiable_within_at.clm_apply DifferentiableWithinAt.clm_apply @[fun_prop] theorem DifferentiableAt.clm_apply (hc : DifferentiableAt 𝕜 c x) (hu : DifferentiableAt 𝕜 u x) : DifferentiableAt 𝕜 (fun y => (c y) (u y)) x := (hc.hasFDerivAt.clm_apply hu.hasFDerivAt).differentiableAt #align differentiable_at.clm_apply DifferentiableAt.clm_apply @[fun_prop] theorem DifferentiableOn.clm_apply (hc : DifferentiableOn 𝕜 c s) (hu : DifferentiableOn 𝕜 u s) : DifferentiableOn 𝕜 (fun y => (c y) (u y)) s := fun x hx => (hc x hx).clm_apply (hu x hx) #align differentiable_on.clm_apply DifferentiableOn.clm_apply @[fun_prop] theorem Differentiable.clm_apply (hc : Differentiable 𝕜 c) (hu : Differentiable 𝕜 u) : Differentiable 𝕜 fun y => (c y) (u y) := fun x => (hc x).clm_apply (hu x) #align differentiable.clm_apply Differentiable.clm_apply theorem fderivWithin_clm_apply (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hu : DifferentiableWithinAt 𝕜 u s x) : fderivWithin 𝕜 (fun y => (c y) (u y)) s x = (c x).comp (fderivWithin 𝕜 u s x) + (fderivWithin 𝕜 c s x).flip (u x) := (hc.hasFDerivWithinAt.clm_apply hu.hasFDerivWithinAt).fderivWithin hxs #align fderiv_within_clm_apply fderivWithin_clm_apply theorem fderiv_clm_apply (hc : DifferentiableAt 𝕜 c x) (hu : DifferentiableAt 𝕜 u x) : fderiv 𝕜 (fun y => (c y) (u y)) x = (c x).comp (fderiv 𝕜 u x) + (fderiv 𝕜 c x).flip (u x) := (hc.hasFDerivAt.clm_apply hu.hasFDerivAt).fderiv #align fderiv_clm_apply fderiv_clm_apply end CLMCompApply section ContinuousMultilinearApplyConst /-! ### Derivative of the application of continuous multilinear maps to a constant -/ variable {ι : Type*} [Fintype ι] {M : ι → Type*} [∀ i, NormedAddCommGroup (M i)] [∀ i, NormedSpace 𝕜 (M i)] {H : Type*} [NormedAddCommGroup H] [NormedSpace 𝕜 H] {c : E → ContinuousMultilinearMap 𝕜 M H} {c' : E →L[𝕜] ContinuousMultilinearMap 𝕜 M H} @[fun_prop] theorem HasStrictFDerivAt.continuousMultilinear_apply_const (hc : HasStrictFDerivAt c c' x) (u : ∀ i, M i) : HasStrictFDerivAt (fun y ↦ (c y) u) (c'.flipMultilinear u) x := (ContinuousMultilinearMap.apply 𝕜 M H u).hasStrictFDerivAt.comp x hc @[fun_prop] theorem HasFDerivWithinAt.continuousMultilinear_apply_const (hc : HasFDerivWithinAt c c' s x) (u : ∀ i, M i) : HasFDerivWithinAt (fun y ↦ (c y) u) (c'.flipMultilinear u) s x := (ContinuousMultilinearMap.apply 𝕜 M H u).hasFDerivAt.comp_hasFDerivWithinAt x hc @[fun_prop] theorem HasFDerivAt.continuousMultilinear_apply_const (hc : HasFDerivAt c c' x) (u : ∀ i, M i) : HasFDerivAt (fun y ↦ (c y) u) (c'.flipMultilinear u) x := (ContinuousMultilinearMap.apply 𝕜 M H u).hasFDerivAt.comp x hc @[fun_prop] theorem DifferentiableWithinAt.continuousMultilinear_apply_const (hc : DifferentiableWithinAt 𝕜 c s x) (u : ∀ i, M i) : DifferentiableWithinAt 𝕜 (fun y ↦ (c y) u) s x := (hc.hasFDerivWithinAt.continuousMultilinear_apply_const u).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.continuousMultilinear_apply_const (hc : DifferentiableAt 𝕜 c x) (u : ∀ i, M i) : DifferentiableAt 𝕜 (fun y ↦ (c y) u) x := (hc.hasFDerivAt.continuousMultilinear_apply_const u).differentiableAt @[fun_prop] theorem DifferentiableOn.continuousMultilinear_apply_const (hc : DifferentiableOn 𝕜 c s) (u : ∀ i, M i) : DifferentiableOn 𝕜 (fun y ↦ (c y) u) s := fun x hx ↦ (hc x hx).continuousMultilinear_apply_const u @[fun_prop] theorem Differentiable.continuousMultilinear_apply_const (hc : Differentiable 𝕜 c) (u : ∀ i, M i) : Differentiable 𝕜 fun y ↦ (c y) u := fun x ↦ (hc x).continuousMultilinear_apply_const u theorem fderivWithin_continuousMultilinear_apply_const (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (u : ∀ i, M i) : fderivWithin 𝕜 (fun y ↦ (c y) u) s x = ((fderivWithin 𝕜 c s x).flipMultilinear u) := (hc.hasFDerivWithinAt.continuousMultilinear_apply_const u).fderivWithin hxs theorem fderiv_continuousMultilinear_apply_const (hc : DifferentiableAt 𝕜 c x) (u : ∀ i, M i) : (fderiv 𝕜 (fun y ↦ (c y) u) x) = (fderiv 𝕜 c x).flipMultilinear u := (hc.hasFDerivAt.continuousMultilinear_apply_const u).fderiv /-- Application of a `ContinuousMultilinearMap` to a constant commutes with `fderivWithin`. -/ theorem fderivWithin_continuousMultilinear_apply_const_apply (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (u : ∀ i, M i) (m : E) : (fderivWithin 𝕜 (fun y ↦ (c y) u) s x) m = (fderivWithin 𝕜 c s x) m u := by simp [fderivWithin_continuousMultilinear_apply_const hxs hc] /-- Application of a `ContinuousMultilinearMap` to a constant commutes with `fderiv`. -/ theorem fderiv_continuousMultilinear_apply_const_apply (hc : DifferentiableAt 𝕜 c x) (u : ∀ i, M i) (m : E) : (fderiv 𝕜 (fun y ↦ (c y) u) x) m = (fderiv 𝕜 c x) m u := by simp [fderiv_continuousMultilinear_apply_const hc] end ContinuousMultilinearApplyConst section SMul /-! ### Derivative of the product of a scalar-valued function and a vector-valued function If `c` is a differentiable scalar-valued function and `f` is a differentiable vector-valued function, then `fun x ↦ c x • f x` is differentiable as well. Lemmas in this section works for function `c` taking values in the base field, as well as in a normed algebra over the base field: e.g., they work for `c : E → ℂ` and `f : E → F` provided that `F` is a complex normed vector space. -/ variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F] [IsScalarTower 𝕜 𝕜' F] variable {c : E → 𝕜'} {c' : E →L[𝕜] 𝕜'} @[fun_prop] theorem HasStrictFDerivAt.smul (hc : HasStrictFDerivAt c c' x) (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun y => c y • f y) (c x • f' + c'.smulRight (f x)) x := (isBoundedBilinearMap_smul.hasStrictFDerivAt (c x, f x)).comp x <| hc.prod hf #align has_strict_fderiv_at.smul HasStrictFDerivAt.smul @[fun_prop] theorem HasFDerivWithinAt.smul (hc : HasFDerivWithinAt c c' s x) (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun y => c y • f y) (c x • f' + c'.smulRight (f x)) s x := (isBoundedBilinearMap_smul.hasFDerivAt (c x, f x)).comp_hasFDerivWithinAt x <| hc.prod hf #align has_fderiv_within_at.smul HasFDerivWithinAt.smul @[fun_prop] theorem HasFDerivAt.smul (hc : HasFDerivAt c c' x) (hf : HasFDerivAt f f' x) : HasFDerivAt (fun y => c y • f y) (c x • f' + c'.smulRight (f x)) x := (isBoundedBilinearMap_smul.hasFDerivAt (c x, f x)).comp x <| hc.prod hf #align has_fderiv_at.smul HasFDerivAt.smul @[fun_prop] theorem DifferentiableWithinAt.smul (hc : DifferentiableWithinAt 𝕜 c s x) (hf : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 (fun y => c y • f y) s x := (hc.hasFDerivWithinAt.smul hf.hasFDerivWithinAt).differentiableWithinAt #align differentiable_within_at.smul DifferentiableWithinAt.smul @[simp, fun_prop] theorem DifferentiableAt.smul (hc : DifferentiableAt 𝕜 c x) (hf : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => c y • f y) x := (hc.hasFDerivAt.smul hf.hasFDerivAt).differentiableAt #align differentiable_at.smul DifferentiableAt.smul @[fun_prop] theorem DifferentiableOn.smul (hc : DifferentiableOn 𝕜 c s) (hf : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => c y • f y) s := fun x hx => (hc x hx).smul (hf x hx) #align differentiable_on.smul DifferentiableOn.smul @[simp, fun_prop] theorem Differentiable.smul (hc : Differentiable 𝕜 c) (hf : Differentiable 𝕜 f) : Differentiable 𝕜 fun y => c y • f y := fun x => (hc x).smul (hf x) #align differentiable.smul Differentiable.smul theorem fderivWithin_smul (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hf : DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 (fun y => c y • f y) s x = c x • fderivWithin 𝕜 f s x + (fderivWithin 𝕜 c s x).smulRight (f x) := (hc.hasFDerivWithinAt.smul hf.hasFDerivWithinAt).fderivWithin hxs #align fderiv_within_smul fderivWithin_smul theorem fderiv_smul (hc : DifferentiableAt 𝕜 c x) (hf : DifferentiableAt 𝕜 f x) : fderiv 𝕜 (fun y => c y • f y) x = c x • fderiv 𝕜 f x + (fderiv 𝕜 c x).smulRight (f x) := (hc.hasFDerivAt.smul hf.hasFDerivAt).fderiv #align fderiv_smul fderiv_smul @[fun_prop] theorem HasStrictFDerivAt.smul_const (hc : HasStrictFDerivAt c c' x) (f : F) : HasStrictFDerivAt (fun y => c y • f) (c'.smulRight f) x := by simpa only [smul_zero, zero_add] using hc.smul (hasStrictFDerivAt_const f x) #align has_strict_fderiv_at.smul_const HasStrictFDerivAt.smul_const @[fun_prop] theorem HasFDerivWithinAt.smul_const (hc : HasFDerivWithinAt c c' s x) (f : F) : HasFDerivWithinAt (fun y => c y • f) (c'.smulRight f) s x := by simpa only [smul_zero, zero_add] using hc.smul (hasFDerivWithinAt_const f x s) #align has_fderiv_within_at.smul_const HasFDerivWithinAt.smul_const @[fun_prop] theorem HasFDerivAt.smul_const (hc : HasFDerivAt c c' x) (f : F) : HasFDerivAt (fun y => c y • f) (c'.smulRight f) x := by simpa only [smul_zero, zero_add] using hc.smul (hasFDerivAt_const f x) #align has_fderiv_at.smul_const HasFDerivAt.smul_const @[fun_prop] theorem DifferentiableWithinAt.smul_const (hc : DifferentiableWithinAt 𝕜 c s x) (f : F) : DifferentiableWithinAt 𝕜 (fun y => c y • f) s x := (hc.hasFDerivWithinAt.smul_const f).differentiableWithinAt #align differentiable_within_at.smul_const DifferentiableWithinAt.smul_const @[fun_prop] theorem DifferentiableAt.smul_const (hc : DifferentiableAt 𝕜 c x) (f : F) : DifferentiableAt 𝕜 (fun y => c y • f) x := (hc.hasFDerivAt.smul_const f).differentiableAt #align differentiable_at.smul_const DifferentiableAt.smul_const @[fun_prop] theorem DifferentiableOn.smul_const (hc : DifferentiableOn 𝕜 c s) (f : F) : DifferentiableOn 𝕜 (fun y => c y • f) s := fun x hx => (hc x hx).smul_const f #align differentiable_on.smul_const DifferentiableOn.smul_const @[fun_prop] theorem Differentiable.smul_const (hc : Differentiable 𝕜 c) (f : F) : Differentiable 𝕜 fun y => c y • f := fun x => (hc x).smul_const f #align differentiable.smul_const Differentiable.smul_const theorem fderivWithin_smul_const (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (f : F) : fderivWithin 𝕜 (fun y => c y • f) s x = (fderivWithin 𝕜 c s x).smulRight f := (hc.hasFDerivWithinAt.smul_const f).fderivWithin hxs #align fderiv_within_smul_const fderivWithin_smul_const theorem fderiv_smul_const (hc : DifferentiableAt 𝕜 c x) (f : F) : fderiv 𝕜 (fun y => c y • f) x = (fderiv 𝕜 c x).smulRight f := (hc.hasFDerivAt.smul_const f).fderiv #align fderiv_smul_const fderiv_smul_const end SMul section Mul /-! ### Derivative of the product of two functions -/ variable {𝔸 𝔸' : Type*} [NormedRing 𝔸] [NormedCommRing 𝔸'] [NormedAlgebra 𝕜 𝔸] [NormedAlgebra 𝕜 𝔸'] {a b : E → 𝔸} {a' b' : E →L[𝕜] 𝔸} {c d : E → 𝔸'} {c' d' : E →L[𝕜] 𝔸'} @[fun_prop] theorem HasStrictFDerivAt.mul' {x : E} (ha : HasStrictFDerivAt a a' x) (hb : HasStrictFDerivAt b b' x) : HasStrictFDerivAt (fun y => a y * b y) (a x • b' + a'.smulRight (b x)) x := ((ContinuousLinearMap.mul 𝕜 𝔸).isBoundedBilinearMap.hasStrictFDerivAt (a x, b x)).comp x (ha.prod hb) #align has_strict_fderiv_at.mul' HasStrictFDerivAt.mul' @[fun_prop] theorem HasStrictFDerivAt.mul (hc : HasStrictFDerivAt c c' x) (hd : HasStrictFDerivAt d d' x) : HasStrictFDerivAt (fun y => c y * d y) (c x • d' + d x • c') x := by convert hc.mul' hd ext z apply mul_comm #align has_strict_fderiv_at.mul HasStrictFDerivAt.mul @[fun_prop] theorem HasFDerivWithinAt.mul' (ha : HasFDerivWithinAt a a' s x) (hb : HasFDerivWithinAt b b' s x) : HasFDerivWithinAt (fun y => a y * b y) (a x • b' + a'.smulRight (b x)) s x := ((ContinuousLinearMap.mul 𝕜 𝔸).isBoundedBilinearMap.hasFDerivAt (a x, b x)).comp_hasFDerivWithinAt x (ha.prod hb) #align has_fderiv_within_at.mul' HasFDerivWithinAt.mul' @[fun_prop] theorem HasFDerivWithinAt.mul (hc : HasFDerivWithinAt c c' s x) (hd : HasFDerivWithinAt d d' s x) : HasFDerivWithinAt (fun y => c y * d y) (c x • d' + d x • c') s x := by convert hc.mul' hd ext z apply mul_comm #align has_fderiv_within_at.mul HasFDerivWithinAt.mul @[fun_prop] theorem HasFDerivAt.mul' (ha : HasFDerivAt a a' x) (hb : HasFDerivAt b b' x) : HasFDerivAt (fun y => a y * b y) (a x • b' + a'.smulRight (b x)) x := ((ContinuousLinearMap.mul 𝕜 𝔸).isBoundedBilinearMap.hasFDerivAt (a x, b x)).comp x (ha.prod hb) #align has_fderiv_at.mul' HasFDerivAt.mul' @[fun_prop] theorem HasFDerivAt.mul (hc : HasFDerivAt c c' x) (hd : HasFDerivAt d d' x) : HasFDerivAt (fun y => c y * d y) (c x • d' + d x • c') x := by convert hc.mul' hd ext z apply mul_comm #align has_fderiv_at.mul HasFDerivAt.mul @[fun_prop] theorem DifferentiableWithinAt.mul (ha : DifferentiableWithinAt 𝕜 a s x) (hb : DifferentiableWithinAt 𝕜 b s x) : DifferentiableWithinAt 𝕜 (fun y => a y * b y) s x := (ha.hasFDerivWithinAt.mul' hb.hasFDerivWithinAt).differentiableWithinAt #align differentiable_within_at.mul DifferentiableWithinAt.mul @[simp, fun_prop] theorem DifferentiableAt.mul (ha : DifferentiableAt 𝕜 a x) (hb : DifferentiableAt 𝕜 b x) : DifferentiableAt 𝕜 (fun y => a y * b y) x := (ha.hasFDerivAt.mul' hb.hasFDerivAt).differentiableAt #align differentiable_at.mul DifferentiableAt.mul @[fun_prop] theorem DifferentiableOn.mul (ha : DifferentiableOn 𝕜 a s) (hb : DifferentiableOn 𝕜 b s) : DifferentiableOn 𝕜 (fun y => a y * b y) s := fun x hx => (ha x hx).mul (hb x hx) #align differentiable_on.mul DifferentiableOn.mul @[simp, fun_prop] theorem Differentiable.mul (ha : Differentiable 𝕜 a) (hb : Differentiable 𝕜 b) : Differentiable 𝕜 fun y => a y * b y := fun x => (ha x).mul (hb x) #align differentiable.mul Differentiable.mul @[fun_prop] theorem DifferentiableWithinAt.pow (ha : DifferentiableWithinAt 𝕜 a s x) : ∀ n : ℕ, DifferentiableWithinAt 𝕜 (fun x => a x ^ n) s x | 0 => by simp only [pow_zero, differentiableWithinAt_const] | n + 1 => by simp only [pow_succ', DifferentiableWithinAt.pow ha n, ha.mul] #align differentiable_within_at.pow DifferentiableWithinAt.pow @[simp, fun_prop] theorem DifferentiableAt.pow (ha : DifferentiableAt 𝕜 a x) (n : ℕ) : DifferentiableAt 𝕜 (fun x => a x ^ n) x := differentiableWithinAt_univ.mp <| ha.differentiableWithinAt.pow n #align differentiable_at.pow DifferentiableAt.pow @[fun_prop] theorem DifferentiableOn.pow (ha : DifferentiableOn 𝕜 a s) (n : ℕ) : DifferentiableOn 𝕜 (fun x => a x ^ n) s := fun x h => (ha x h).pow n #align differentiable_on.pow DifferentiableOn.pow @[simp, fun_prop] theorem Differentiable.pow (ha : Differentiable 𝕜 a) (n : ℕ) : Differentiable 𝕜 fun x => a x ^ n := fun x => (ha x).pow n #align differentiable.pow Differentiable.pow theorem fderivWithin_mul' (hxs : UniqueDiffWithinAt 𝕜 s x) (ha : DifferentiableWithinAt 𝕜 a s x) (hb : DifferentiableWithinAt 𝕜 b s x) : fderivWithin 𝕜 (fun y => a y * b y) s x = a x • fderivWithin 𝕜 b s x + (fderivWithin 𝕜 a s x).smulRight (b x) := (ha.hasFDerivWithinAt.mul' hb.hasFDerivWithinAt).fderivWithin hxs #align fderiv_within_mul' fderivWithin_mul' theorem fderivWithin_mul (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) : fderivWithin 𝕜 (fun y => c y * d y) s x = c x • fderivWithin 𝕜 d s x + d x • fderivWithin 𝕜 c s x := (hc.hasFDerivWithinAt.mul hd.hasFDerivWithinAt).fderivWithin hxs #align fderiv_within_mul fderivWithin_mul theorem fderiv_mul' (ha : DifferentiableAt 𝕜 a x) (hb : DifferentiableAt 𝕜 b x) : fderiv 𝕜 (fun y => a y * b y) x = a x • fderiv 𝕜 b x + (fderiv 𝕜 a x).smulRight (b x) := (ha.hasFDerivAt.mul' hb.hasFDerivAt).fderiv #align fderiv_mul' fderiv_mul' theorem fderiv_mul (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : fderiv 𝕜 (fun y => c y * d y) x = c x • fderiv 𝕜 d x + d x • fderiv 𝕜 c x := (hc.hasFDerivAt.mul hd.hasFDerivAt).fderiv #align fderiv_mul fderiv_mul @[fun_prop] theorem HasStrictFDerivAt.mul_const' (ha : HasStrictFDerivAt a a' x) (b : 𝔸) : HasStrictFDerivAt (fun y => a y * b) (a'.smulRight b) x := ((ContinuousLinearMap.mul 𝕜 𝔸).flip b).hasStrictFDerivAt.comp x ha #align has_strict_fderiv_at.mul_const' HasStrictFDerivAt.mul_const' @[fun_prop] theorem HasStrictFDerivAt.mul_const (hc : HasStrictFDerivAt c c' x) (d : 𝔸') : HasStrictFDerivAt (fun y => c y * d) (d • c') x := by convert hc.mul_const' d ext z apply mul_comm #align has_strict_fderiv_at.mul_const HasStrictFDerivAt.mul_const @[fun_prop] theorem HasFDerivWithinAt.mul_const' (ha : HasFDerivWithinAt a a' s x) (b : 𝔸) : HasFDerivWithinAt (fun y => a y * b) (a'.smulRight b) s x := ((ContinuousLinearMap.mul 𝕜 𝔸).flip b).hasFDerivAt.comp_hasFDerivWithinAt x ha #align has_fderiv_within_at.mul_const' HasFDerivWithinAt.mul_const' @[fun_prop] theorem HasFDerivWithinAt.mul_const (hc : HasFDerivWithinAt c c' s x) (d : 𝔸') : HasFDerivWithinAt (fun y => c y * d) (d • c') s x := by convert hc.mul_const' d ext z apply mul_comm #align has_fderiv_within_at.mul_const HasFDerivWithinAt.mul_const @[fun_prop] theorem HasFDerivAt.mul_const' (ha : HasFDerivAt a a' x) (b : 𝔸) : HasFDerivAt (fun y => a y * b) (a'.smulRight b) x := ((ContinuousLinearMap.mul 𝕜 𝔸).flip b).hasFDerivAt.comp x ha #align has_fderiv_at.mul_const' HasFDerivAt.mul_const' @[fun_prop] theorem HasFDerivAt.mul_const (hc : HasFDerivAt c c' x) (d : 𝔸') : HasFDerivAt (fun y => c y * d) (d • c') x := by convert hc.mul_const' d ext z apply mul_comm #align has_fderiv_at.mul_const HasFDerivAt.mul_const @[fun_prop] theorem DifferentiableWithinAt.mul_const (ha : DifferentiableWithinAt 𝕜 a s x) (b : 𝔸) : DifferentiableWithinAt 𝕜 (fun y => a y * b) s x := (ha.hasFDerivWithinAt.mul_const' b).differentiableWithinAt #align differentiable_within_at.mul_const DifferentiableWithinAt.mul_const @[fun_prop] theorem DifferentiableAt.mul_const (ha : DifferentiableAt 𝕜 a x) (b : 𝔸) : DifferentiableAt 𝕜 (fun y => a y * b) x := (ha.hasFDerivAt.mul_const' b).differentiableAt #align differentiable_at.mul_const DifferentiableAt.mul_const @[fun_prop] theorem DifferentiableOn.mul_const (ha : DifferentiableOn 𝕜 a s) (b : 𝔸) : DifferentiableOn 𝕜 (fun y => a y * b) s := fun x hx => (ha x hx).mul_const b #align differentiable_on.mul_const DifferentiableOn.mul_const @[fun_prop] theorem Differentiable.mul_const (ha : Differentiable 𝕜 a) (b : 𝔸) : Differentiable 𝕜 fun y => a y * b := fun x => (ha x).mul_const b #align differentiable.mul_const Differentiable.mul_const theorem fderivWithin_mul_const' (hxs : UniqueDiffWithinAt 𝕜 s x) (ha : DifferentiableWithinAt 𝕜 a s x) (b : 𝔸) : fderivWithin 𝕜 (fun y => a y * b) s x = (fderivWithin 𝕜 a s x).smulRight b := (ha.hasFDerivWithinAt.mul_const' b).fderivWithin hxs #align fderiv_within_mul_const' fderivWithin_mul_const' theorem fderivWithin_mul_const (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (d : 𝔸') : fderivWithin 𝕜 (fun y => c y * d) s x = d • fderivWithin 𝕜 c s x := (hc.hasFDerivWithinAt.mul_const d).fderivWithin hxs #align fderiv_within_mul_const fderivWithin_mul_const theorem fderiv_mul_const' (ha : DifferentiableAt 𝕜 a x) (b : 𝔸) : fderiv 𝕜 (fun y => a y * b) x = (fderiv 𝕜 a x).smulRight b := (ha.hasFDerivAt.mul_const' b).fderiv #align fderiv_mul_const' fderiv_mul_const' theorem fderiv_mul_const (hc : DifferentiableAt 𝕜 c x) (d : 𝔸') : fderiv 𝕜 (fun y => c y * d) x = d • fderiv 𝕜 c x := (hc.hasFDerivAt.mul_const d).fderiv #align fderiv_mul_const fderiv_mul_const @[fun_prop] theorem HasStrictFDerivAt.const_mul (ha : HasStrictFDerivAt a a' x) (b : 𝔸) : HasStrictFDerivAt (fun y => b * a y) (b • a') x := ((ContinuousLinearMap.mul 𝕜 𝔸) b).hasStrictFDerivAt.comp x ha #align has_strict_fderiv_at.const_mul HasStrictFDerivAt.const_mul @[fun_prop] theorem HasFDerivWithinAt.const_mul (ha : HasFDerivWithinAt a a' s x) (b : 𝔸) : HasFDerivWithinAt (fun y => b * a y) (b • a') s x := ((ContinuousLinearMap.mul 𝕜 𝔸) b).hasFDerivAt.comp_hasFDerivWithinAt x ha #align has_fderiv_within_at.const_mul HasFDerivWithinAt.const_mul @[fun_prop] theorem HasFDerivAt.const_mul (ha : HasFDerivAt a a' x) (b : 𝔸) : HasFDerivAt (fun y => b * a y) (b • a') x := ((ContinuousLinearMap.mul 𝕜 𝔸) b).hasFDerivAt.comp x ha #align has_fderiv_at.const_mul HasFDerivAt.const_mul @[fun_prop] theorem DifferentiableWithinAt.const_mul (ha : DifferentiableWithinAt 𝕜 a s x) (b : 𝔸) : DifferentiableWithinAt 𝕜 (fun y => b * a y) s x := (ha.hasFDerivWithinAt.const_mul b).differentiableWithinAt #align differentiable_within_at.const_mul DifferentiableWithinAt.const_mul @[fun_prop] theorem DifferentiableAt.const_mul (ha : DifferentiableAt 𝕜 a x) (b : 𝔸) : DifferentiableAt 𝕜 (fun y => b * a y) x := (ha.hasFDerivAt.const_mul b).differentiableAt #align differentiable_at.const_mul DifferentiableAt.const_mul @[fun_prop] theorem DifferentiableOn.const_mul (ha : DifferentiableOn 𝕜 a s) (b : 𝔸) : DifferentiableOn 𝕜 (fun y => b * a y) s := fun x hx => (ha x hx).const_mul b #align differentiable_on.const_mul DifferentiableOn.const_mul @[fun_prop] theorem Differentiable.const_mul (ha : Differentiable 𝕜 a) (b : 𝔸) : Differentiable 𝕜 fun y => b * a y := fun x => (ha x).const_mul b #align differentiable.const_mul Differentiable.const_mul theorem fderivWithin_const_mul (hxs : UniqueDiffWithinAt 𝕜 s x) (ha : DifferentiableWithinAt 𝕜 a s x) (b : 𝔸) : fderivWithin 𝕜 (fun y => b * a y) s x = b • fderivWithin 𝕜 a s x := (ha.hasFDerivWithinAt.const_mul b).fderivWithin hxs #align fderiv_within_const_mul fderivWithin_const_mul theorem fderiv_const_mul (ha : DifferentiableAt 𝕜 a x) (b : 𝔸) : fderiv 𝕜 (fun y => b * a y) x = b • fderiv 𝕜 a x := (ha.hasFDerivAt.const_mul b).fderiv #align fderiv_const_mul fderiv_const_mul end Mul section Prod /-! ### Derivative of a finite product of functions -/ variable {ι : Type*} {𝔸 𝔸' : Type*} [NormedRing 𝔸] [NormedCommRing 𝔸'] [NormedAlgebra 𝕜 𝔸] [NormedAlgebra 𝕜 𝔸'] {u : Finset ι} {f : ι → E → 𝔸} {f' : ι → E →L[𝕜] 𝔸} {g : ι → E → 𝔸'} {g' : ι → E →L[𝕜] 𝔸'} @[fun_prop] theorem hasStrictFDerivAt_list_prod' [Fintype ι] {l : List ι} {x : ι → 𝔸} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↦ (l.map x).prod) (∑ i : Fin l.length, ((l.take i).map x).prod • smulRight (proj (l.get i)) ((l.drop (.succ i)).map x).prod) x := by induction l with | nil => simp [hasStrictFDerivAt_const] | cons a l IH => simp only [List.map_cons, List.prod_cons, ← proj_apply (R := 𝕜) (φ := fun _ : ι ↦ 𝔸) a] exact .congr_fderiv (.mul' (ContinuousLinearMap.hasStrictFDerivAt _) IH) (by ext; simp [Fin.sum_univ_succ, Finset.mul_sum, mul_assoc, add_comm]) @[fun_prop] theorem hasStrictFDerivAt_list_prod_finRange' {n : ℕ} {x : Fin n → 𝔸} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↦ ((List.finRange n).map x).prod) (∑ i : Fin n, (((List.finRange n).take i).map x).prod • smulRight (proj i) (((List.finRange n).drop (.succ i)).map x).prod) x := hasStrictFDerivAt_list_prod'.congr_fderiv <| Finset.sum_equiv (finCongr (List.length_finRange n)) (by simp) (by simp [Fin.forall_iff]) @[fun_prop] theorem hasStrictFDerivAt_list_prod_attach' [DecidableEq ι] {l : List ι} {x : {i // i ∈ l} → 𝔸} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↦ (l.attach.map x).prod) (∑ i : Fin l.length, ((l.attach.take i).map x).prod • smulRight (proj (l.attach.get (i.cast l.length_attach.symm))) ((l.attach.drop (.succ i)).map x).prod) x := hasStrictFDerivAt_list_prod'.congr_fderiv <| Eq.symm <| Finset.sum_equiv (finCongr l.length_attach.symm) (by simp) (by simp) @[fun_prop] theorem hasFDerivAt_list_prod' [Fintype ι] {l : List ι} {x : ι → 𝔸'} : HasFDerivAt (𝕜 := 𝕜) (fun x ↦ (l.map x).prod) (∑ i : Fin l.length, ((l.take i).map x).prod • smulRight (proj (l.get i)) ((l.drop (.succ i)).map x).prod) x := hasStrictFDerivAt_list_prod'.hasFDerivAt @[fun_prop] theorem hasFDerivAt_list_prod_finRange' {n : ℕ} {x : Fin n → 𝔸} : HasFDerivAt (𝕜 := 𝕜) (fun x ↦ ((List.finRange n).map x).prod) (∑ i : Fin n, (((List.finRange n).take i).map x).prod • smulRight (proj i) (((List.finRange n).drop (.succ i)).map x).prod) x := (hasStrictFDerivAt_list_prod_finRange').hasFDerivAt @[fun_prop] theorem hasFDerivAt_list_prod_attach' [DecidableEq ι] {l : List ι} {x : {i // i ∈ l} → 𝔸} : HasFDerivAt (𝕜 := 𝕜) (fun x ↦ (l.attach.map x).prod) (∑ i : Fin l.length, ((l.attach.take i).map x).prod • smulRight (proj (l.attach.get (i.cast l.length_attach.symm))) ((l.attach.drop (.succ i)).map x).prod) x := hasStrictFDerivAt_list_prod_attach'.hasFDerivAt /-- Auxiliary lemma for `hasStrictFDerivAt_multiset_prod`. For `NormedCommRing 𝔸'`, can rewrite as `Multiset` using `Multiset.prod_coe`. -/ @[fun_prop] theorem hasStrictFDerivAt_list_prod [DecidableEq ι] [Fintype ι] {l : List ι} {x : ι → 𝔸'} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↦ (l.map x).prod) (l.map fun i ↦ ((l.erase i).map x).prod • proj i).sum x := by refine .congr_fderiv hasStrictFDerivAt_list_prod' ?_ conv_rhs => arg 1; arg 2; rw [← List.finRange_map_get l] simp only [List.map_map, ← List.sum_toFinset _ (List.nodup_finRange _), List.toFinset_finRange, Function.comp_def, ((List.erase_get _).map _).prod_eq, List.eraseIdx_eq_take_drop_succ, List.map_append, List.prod_append] exact Finset.sum_congr rfl fun i _ ↦ by ext; simp only [smul_apply, smulRight_apply, smul_eq_mul]; ring @[fun_prop] theorem hasStrictFDerivAt_multiset_prod [DecidableEq ι] [Fintype ι] {u : Multiset ι} {x : ι → 𝔸'} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↦ (u.map x).prod) (u.map (fun i ↦ ((u.erase i).map x).prod • proj i)).sum x := u.inductionOn fun l ↦ by simpa using hasStrictFDerivAt_list_prod @[fun_prop] theorem hasFDerivAt_multiset_prod [DecidableEq ι] [Fintype ι] {u : Multiset ι} {x : ι → 𝔸'} : HasFDerivAt (𝕜 := 𝕜) (fun x ↦ (u.map x).prod) (Multiset.sum (u.map (fun i ↦ ((u.erase i).map x).prod • proj i))) x := hasStrictFDerivAt_multiset_prod.hasFDerivAt theorem hasStrictFDerivAt_finset_prod [DecidableEq ι] [Fintype ι] {x : ι → 𝔸'} : HasStrictFDerivAt (𝕜 := 𝕜) (∏ i ∈ u, · i) (∑ i ∈ u, (∏ j ∈ u.erase i, x j) • proj i) x := by simp only [Finset.sum_eq_multiset_sum, Finset.prod_eq_multiset_prod] exact hasStrictFDerivAt_multiset_prod theorem hasFDerivAt_finset_prod [DecidableEq ι] [Fintype ι] {x : ι → 𝔸'} : HasFDerivAt (𝕜 := 𝕜) (∏ i ∈ u, · i) (∑ i ∈ u, (∏ j ∈ u.erase i, x j) • proj i) x := hasStrictFDerivAt_finset_prod.hasFDerivAt section Comp @[fun_prop] theorem HasStrictFDerivAt.list_prod' {l : List ι} {x : E} (h : ∀ i ∈ l, HasStrictFDerivAt (f i ·) (f' i) x) : HasStrictFDerivAt (fun x ↦ (l.map (f · x)).prod) (∑ i : Fin l.length, ((l.take i).map (f · x)).prod • smulRight (f' (l.get i)) ((l.drop (.succ i)).map (f · x)).prod) x := by simp only [← List.finRange_map_get l, List.map_map] refine .congr_fderiv (hasStrictFDerivAt_list_prod_finRange'.comp x (hasStrictFDerivAt_pi.mpr fun i ↦ h (l.get i) (l.get_mem i i.isLt))) ?_ ext m simp [← Function.comp_def (f · x) (l.get ·), ← List.map_map, List.map_take, List.map_drop] /-- Unlike `HasFDerivAt.finset_prod`, supports non-commutative multiply and duplicate elements. -/ @[fun_prop] theorem HasFDerivAt.list_prod' {l : List ι} {x : E} (h : ∀ i ∈ l, HasFDerivAt (f i ·) (f' i) x) : HasFDerivAt (fun x ↦ (l.map (f · x)).prod) (∑ i : Fin l.length, ((l.take i).map (f · x)).prod • smulRight (f' (l.get i)) ((l.drop (.succ i)).map (f · x)).prod) x := by simp only [← List.finRange_map_get l, List.map_map] refine .congr_fderiv (hasFDerivAt_list_prod_finRange'.comp x (hasFDerivAt_pi.mpr fun i ↦ h (l.get i) (l.get_mem i i.isLt))) ?_ ext m simp [← Function.comp_def (f · x) (l.get ·), ← List.map_map, List.map_take, List.map_drop] @[fun_prop] theorem HasFDerivWithinAt.list_prod' {l : List ι} {x : E} (h : ∀ i ∈ l, HasFDerivWithinAt (f i ·) (f' i) s x) : HasFDerivWithinAt (fun x ↦ (l.map (f · x)).prod) (∑ i : Fin l.length, ((l.take i).map (f · x)).prod • smulRight (f' (l.get i)) ((l.drop (.succ i)).map (f · x)).prod) s x := by simp only [← List.finRange_map_get l, List.map_map] refine .congr_fderiv (hasFDerivAt_list_prod_finRange'.comp_hasFDerivWithinAt x (hasFDerivWithinAt_pi.mpr fun i ↦ h (l.get i) (l.get_mem i i.isLt))) ?_ ext m simp [← Function.comp_def (f · x) (l.get ·), ← List.map_map, List.map_take, List.map_drop] theorem fderiv_list_prod' {l : List ι} {x : E} (h : ∀ i ∈ l, DifferentiableAt 𝕜 (f i ·) x) : fderiv 𝕜 (fun x ↦ (l.map (f · x)).prod) x = ∑ i : Fin l.length, ((l.take i).map (f · x)).prod • smulRight (fderiv 𝕜 (fun x ↦ f (l.get i) x) x) ((l.drop (.succ i)).map (f · x)).prod := (HasFDerivAt.list_prod' fun i hi ↦ (h i hi).hasFDerivAt).fderiv theorem fderivWithin_list_prod' {l : List ι} {x : E} (hxs : UniqueDiffWithinAt 𝕜 s x) (h : ∀ i ∈ l, DifferentiableWithinAt 𝕜 (f i ·) s x) : fderivWithin 𝕜 (fun x ↦ (l.map (f · x)).prod) s x = ∑ i : Fin l.length, ((l.take i).map (f · x)).prod • smulRight (fderivWithin 𝕜 (fun x ↦ f (l.get i) x) s x) ((l.drop (.succ i)).map (f · x)).prod := (HasFDerivWithinAt.list_prod' fun i hi ↦ (h i hi).hasFDerivWithinAt).fderivWithin hxs @[fun_prop] theorem HasStrictFDerivAt.multiset_prod [DecidableEq ι] {u : Multiset ι} {x : E} (h : ∀ i ∈ u, HasStrictFDerivAt (g i ·) (g' i) x) : HasStrictFDerivAt (fun x ↦ (u.map (g · x)).prod) (u.map fun i ↦ ((u.erase i).map (g · x)).prod • g' i).sum x := by simp only [← Multiset.attach_map_val u, Multiset.map_map] exact .congr_fderiv (hasStrictFDerivAt_multiset_prod.comp x <| hasStrictFDerivAt_pi.mpr fun i ↦ h i i.prop) (by ext; simp [Finset.sum_multiset_map_count, u.erase_attach_map (g · x)]) /-- Unlike `HasFDerivAt.finset_prod`, supports duplicate elements. -/ @[fun_prop]
Mathlib/Analysis/Calculus/FDeriv/Mul.lean
788
795
theorem HasFDerivAt.multiset_prod [DecidableEq ι] {u : Multiset ι} {x : E} (h : ∀ i ∈ u, HasFDerivAt (g i ·) (g' i) x) : HasFDerivAt (fun x ↦ (u.map (g · x)).prod) (u.map fun i ↦ ((u.erase i).map (g · x)).prod • g' i).sum x := by
simp only [← Multiset.attach_map_val u, Multiset.map_map] exact .congr_fderiv (hasFDerivAt_multiset_prod.comp x <| hasFDerivAt_pi.mpr fun i ↦ h i i.prop) (by ext; simp [Finset.sum_multiset_map_count, u.erase_attach_map (g · x)])
/- Copyright (c) 2020 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Polynomial.Degree.TrailingDegree import Mathlib.Algebra.Polynomial.EraseLead import Mathlib.Algebra.Polynomial.Eval #align_import data.polynomial.reverse from "leanprover-community/mathlib"@"44de64f183393284a16016dfb2a48ac97382f2bd" /-! # Reverse of a univariate polynomial The main definition is `reverse`. Applying `reverse` to a polynomial `f : R[X]` produces the polynomial with a reversed list of coefficients, equivalent to `X^f.natDegree * f(1/X)`. The main result is that `reverse (f * g) = reverse f * reverse g`, provided the leading coefficients of `f` and `g` do not multiply to zero. -/ namespace Polynomial open Polynomial Finsupp Finset open Polynomial section Semiring variable {R : Type*} [Semiring R] {f : R[X]} /-- If `i ≤ N`, then `revAtFun N i` returns `N - i`, otherwise it returns `i`. This is the map used by the embedding `revAt`. -/ def revAtFun (N i : ℕ) : ℕ := ite (i ≤ N) (N - i) i #align polynomial.rev_at_fun Polynomial.revAtFun theorem revAtFun_invol {N i : ℕ} : revAtFun N (revAtFun N i) = i := by unfold revAtFun split_ifs with h j · exact tsub_tsub_cancel_of_le h · exfalso apply j exact Nat.sub_le N i · rfl #align polynomial.rev_at_fun_invol Polynomial.revAtFun_invol theorem revAtFun_inj {N : ℕ} : Function.Injective (revAtFun N) := by intro a b hab rw [← @revAtFun_invol N a, hab, revAtFun_invol] #align polynomial.rev_at_fun_inj Polynomial.revAtFun_inj /-- If `i ≤ N`, then `revAt N i` returns `N - i`, otherwise it returns `i`. Essentially, this embedding is only used for `i ≤ N`. The advantage of `revAt N i` over `N - i` is that `revAt` is an involution. -/ def revAt (N : ℕ) : Function.Embedding ℕ ℕ where toFun i := ite (i ≤ N) (N - i) i inj' := revAtFun_inj #align polynomial.rev_at Polynomial.revAt /-- We prefer to use the bundled `revAt` over unbundled `revAtFun`. -/ @[simp] theorem revAtFun_eq (N i : ℕ) : revAtFun N i = revAt N i := rfl #align polynomial.rev_at_fun_eq Polynomial.revAtFun_eq @[simp] theorem revAt_invol {N i : ℕ} : (revAt N) (revAt N i) = i := revAtFun_invol #align polynomial.rev_at_invol Polynomial.revAt_invol @[simp] theorem revAt_le {N i : ℕ} (H : i ≤ N) : revAt N i = N - i := if_pos H #align polynomial.rev_at_le Polynomial.revAt_le lemma revAt_eq_self_of_lt {N i : ℕ} (h : N < i) : revAt N i = i := by simp [revAt, Nat.not_le.mpr h] theorem revAt_add {N O n o : ℕ} (hn : n ≤ N) (ho : o ≤ O) : revAt (N + O) (n + o) = revAt N n + revAt O o := by rcases Nat.le.dest hn with ⟨n', rfl⟩ rcases Nat.le.dest ho with ⟨o', rfl⟩ repeat' rw [revAt_le (le_add_right rfl.le)] rw [add_assoc, add_left_comm n' o, ← add_assoc, revAt_le (le_add_right rfl.le)] repeat' rw [add_tsub_cancel_left] #align polynomial.rev_at_add Polynomial.revAt_add -- @[simp] -- Porting note (#10618): simp can prove this theorem revAt_zero (N : ℕ) : revAt N 0 = N := by simp #align polynomial.rev_at_zero Polynomial.revAt_zero /-- `reflect N f` is the polynomial such that `(reflect N f).coeff i = f.coeff (revAt N i)`. In other words, the terms with exponent `[0, ..., N]` now have exponent `[N, ..., 0]`. In practice, `reflect` is only used when `N` is at least as large as the degree of `f`. Eventually, it will be used with `N` exactly equal to the degree of `f`. -/ noncomputable def reflect (N : ℕ) : R[X] → R[X] | ⟨f⟩ => ⟨Finsupp.embDomain (revAt N) f⟩ #align polynomial.reflect Polynomial.reflect theorem reflect_support (N : ℕ) (f : R[X]) : (reflect N f).support = Finset.image (revAt N) f.support := by rcases f with ⟨⟩ ext1 simp only [reflect, support_ofFinsupp, support_embDomain, Finset.mem_map, Finset.mem_image] #align polynomial.reflect_support Polynomial.reflect_support @[simp] theorem coeff_reflect (N : ℕ) (f : R[X]) (i : ℕ) : coeff (reflect N f) i = f.coeff (revAt N i) := by rcases f with ⟨f⟩ simp only [reflect, coeff] calc Finsupp.embDomain (revAt N) f i = Finsupp.embDomain (revAt N) f (revAt N (revAt N i)) := by rw [revAt_invol] _ = f (revAt N i) := Finsupp.embDomain_apply _ _ _ #align polynomial.coeff_reflect Polynomial.coeff_reflect @[simp] theorem reflect_zero {N : ℕ} : reflect N (0 : R[X]) = 0 := rfl #align polynomial.reflect_zero Polynomial.reflect_zero @[simp] theorem reflect_eq_zero_iff {N : ℕ} {f : R[X]} : reflect N (f : R[X]) = 0 ↔ f = 0 := by rw [ofFinsupp_eq_zero, reflect, embDomain_eq_zero, ofFinsupp_eq_zero] #align polynomial.reflect_eq_zero_iff Polynomial.reflect_eq_zero_iff @[simp] theorem reflect_add (f g : R[X]) (N : ℕ) : reflect N (f + g) = reflect N f + reflect N g := by ext simp only [coeff_add, coeff_reflect] #align polynomial.reflect_add Polynomial.reflect_add @[simp] theorem reflect_C_mul (f : R[X]) (r : R) (N : ℕ) : reflect N (C r * f) = C r * reflect N f := by ext simp only [coeff_reflect, coeff_C_mul] set_option linter.uppercaseLean3 false in #align polynomial.reflect_C_mul Polynomial.reflect_C_mul -- @[simp] -- Porting note (#10618): simp can prove this (once `reflect_monomial` is in simp scope) theorem reflect_C_mul_X_pow (N n : ℕ) {c : R} : reflect N (C c * X ^ n) = C c * X ^ revAt N n := by ext rw [reflect_C_mul, coeff_C_mul, coeff_C_mul, coeff_X_pow, coeff_reflect] split_ifs with h · rw [h, revAt_invol, coeff_X_pow_self] · rw [not_mem_support_iff.mp] intro a rw [← one_mul (X ^ n), ← C_1] at a apply h rw [← mem_support_C_mul_X_pow a, revAt_invol] set_option linter.uppercaseLean3 false in #align polynomial.reflect_C_mul_X_pow Polynomial.reflect_C_mul_X_pow @[simp] theorem reflect_C (r : R) (N : ℕ) : reflect N (C r) = C r * X ^ N := by conv_lhs => rw [← mul_one (C r), ← pow_zero X, reflect_C_mul_X_pow, revAt_zero] set_option linter.uppercaseLean3 false in #align polynomial.reflect_C Polynomial.reflect_C @[simp]
Mathlib/Algebra/Polynomial/Reverse.lean
166
167
theorem reflect_monomial (N n : ℕ) : reflect N ((X : R[X]) ^ n) = X ^ revAt N n := by
rw [← one_mul (X ^ n), ← one_mul (X ^ revAt N n), ← C_1, reflect_C_mul_X_pow]
/- 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 Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Data.Finset.Sort import Mathlib.Data.Set.Subsingleton #align_import combinatorics.composition from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7" /-! # Compositions A composition of a natural number `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum of positive integers. Combinatorially, it corresponds to a decomposition of `{0, ..., n-1}` into non-empty blocks of consecutive integers, where the `iⱼ` are the lengths of the blocks. This notion is closely related to that of a partition of `n`, but in a composition of `n` the order of the `iⱼ`s matters. We implement two different structures covering these two viewpoints on compositions. The first one, made of a list of positive integers summing to `n`, is the main one and is called `Composition n`. The second one is useful for combinatorial arguments (for instance to show that the number of compositions of `n` is `2^(n-1)`). It is given by a subset of `{0, ..., n}` containing `0` and `n`, where the elements of the subset (other than `n`) correspond to the leftmost points of each block. The main API is built on `Composition n`, and we provide an equivalence between the two types. ## Main functions * `c : Composition n` is a structure, made of a list of integers which are all positive and add up to `n`. * `composition_card` states that the cardinality of `Composition n` is exactly `2^(n-1)`, which is proved by constructing an equiv with `CompositionAsSet n` (see below), which is itself in bijection with the subsets of `Fin (n-1)` (this holds even for `n = 0`, where `-` is nat subtraction). Let `c : Composition n` be a composition of `n`. Then * `c.blocks` is the list of blocks in `c`. * `c.length` is the number of blocks in the composition. * `c.blocks_fun : Fin c.length → ℕ` is the realization of `c.blocks` as a function on `Fin c.length`. This is the main object when using compositions to understand the composition of analytic functions. * `c.sizeUpTo : ℕ → ℕ` is the sum of the size of the blocks up to `i`.; * `c.embedding i : Fin (c.blocks_fun i) → Fin n` is the increasing embedding of the `i`-th block in `Fin n`; * `c.index j`, for `j : Fin n`, is the index of the block containing `j`. * `Composition.ones n` is the composition of `n` made of ones, i.e., `[1, ..., 1]`. * `Composition.single n (hn : 0 < n)` is the composition of `n` made of a single block of size `n`. Compositions can also be used to split lists. Let `l` be a list of length `n` and `c` a composition of `n`. * `l.splitWrtComposition c` is a list of lists, made of the slices of `l` corresponding to the blocks of `c`. * `join_splitWrtComposition` states that splitting a list and then joining it gives back the original list. * `joinSplitWrtComposition_join` states that joining a list of lists, and then splitting it back according to the right composition, gives back the original list of lists. We turn to the second viewpoint on compositions, that we realize as a finset of `Fin (n+1)`. `c : CompositionAsSet n` is a structure made of a finset of `Fin (n+1)` called `c.boundaries` and proofs that it contains `0` and `n`. (Taking a finset of `Fin n` containing `0` would not make sense in the edge case `n = 0`, while the previous description works in all cases). The elements of this set (other than `n`) correspond to leftmost points of blocks. Thus, there is an equiv between `Composition n` and `CompositionAsSet n`. We only construct basic API on `CompositionAsSet` (notably `c.length` and `c.blocks`) to be able to construct this equiv, called `compositionEquiv n`. Since there is a straightforward equiv between `CompositionAsSet n` and finsets of `{1, ..., n-1}` (obtained by removing `0` and `n` from a `CompositionAsSet` and called `compositionAsSetEquiv n`), we deduce that `CompositionAsSet n` and `Composition n` are both fintypes of cardinality `2^(n - 1)` (see `compositionAsSet_card` and `composition_card`). ## Implementation details The main motivation for this structure and its API is in the construction of the composition of formal multilinear series, and the proof that the composition of analytic functions is analytic. The representation of a composition as a list is very handy as lists are very flexible and already have a well-developed API. ## Tags Composition, partition ## References <https://en.wikipedia.org/wiki/Composition_(combinatorics)> -/ open List variable {n : ℕ} /-- A composition of `n` is a list of positive integers summing to `n`. -/ @[ext] structure Composition (n : ℕ) where /-- List of positive integers summing to `n`-/ blocks : List ℕ /-- Proof of positivity for `blocks`-/ blocks_pos : ∀ {i}, i ∈ blocks → 0 < i /-- Proof that `blocks` sums to `n`-/ blocks_sum : blocks.sum = n #align composition Composition /-- Combinatorial viewpoint on a composition of `n`, by seeing it as non-empty blocks of consecutive integers in `{0, ..., n-1}`. We register every block by its left end-point, yielding a finset containing `0`. As this does not make sense for `n = 0`, we add `n` to this finset, and get a finset of `{0, ..., n}` containing `0` and `n`. This is the data in the structure `CompositionAsSet n`. -/ @[ext] structure CompositionAsSet (n : ℕ) where /-- Combinatorial viewpoint on a composition of `n` as consecutive integers `{0, ..., n-1}`-/ boundaries : Finset (Fin n.succ) /-- Proof that `0` is a member of `boundaries`-/ zero_mem : (0 : Fin n.succ) ∈ boundaries /-- Last element of the composition-/ getLast_mem : Fin.last n ∈ boundaries #align composition_as_set CompositionAsSet instance {n : ℕ} : Inhabited (CompositionAsSet n) := ⟨⟨Finset.univ, Finset.mem_univ _, Finset.mem_univ _⟩⟩ /-! ### Compositions A composition of an integer `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum of positive integers. -/ namespace Composition variable (c : Composition n) instance (n : ℕ) : ToString (Composition n) := ⟨fun c => toString c.blocks⟩ /-- The length of a composition, i.e., the number of blocks in the composition. -/ abbrev length : ℕ := c.blocks.length #align composition.length Composition.length theorem blocks_length : c.blocks.length = c.length := rfl #align composition.blocks_length Composition.blocks_length /-- The blocks of a composition, seen as a function on `Fin c.length`. When composing analytic functions using compositions, this is the main player. -/ def blocksFun : Fin c.length → ℕ := c.blocks.get #align composition.blocks_fun Composition.blocksFun theorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks := ofFn_get _ #align composition.of_fn_blocks_fun Composition.ofFn_blocksFun theorem sum_blocksFun : ∑ i, c.blocksFun i = n := by conv_rhs => rw [← c.blocks_sum, ← ofFn_blocksFun, sum_ofFn] #align composition.sum_blocks_fun Composition.sum_blocksFun theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i ∈ c.blocks := get_mem _ _ _ #align composition.blocks_fun_mem_blocks Composition.blocksFun_mem_blocks @[simp] theorem one_le_blocks {i : ℕ} (h : i ∈ c.blocks) : 1 ≤ i := c.blocks_pos h #align composition.one_le_blocks Composition.one_le_blocks @[simp] theorem one_le_blocks' {i : ℕ} (h : i < c.length) : 1 ≤ c.blocks.get ⟨i, h⟩ := c.one_le_blocks (get_mem (blocks c) i h) #align composition.one_le_blocks' Composition.one_le_blocks' @[simp] theorem blocks_pos' (i : ℕ) (h : i < c.length) : 0 < c.blocks.get ⟨i, h⟩ := c.one_le_blocks' h #align composition.blocks_pos' Composition.blocks_pos' theorem one_le_blocksFun (i : Fin c.length) : 1 ≤ c.blocksFun i := c.one_le_blocks (c.blocksFun_mem_blocks i) #align composition.one_le_blocks_fun Composition.one_le_blocksFun theorem length_le : c.length ≤ n := by conv_rhs => rw [← c.blocks_sum] exact length_le_sum_of_one_le _ fun i hi => c.one_le_blocks hi #align composition.length_le Composition.length_le theorem length_pos_of_pos (h : 0 < n) : 0 < c.length := by apply length_pos_of_sum_pos convert h exact c.blocks_sum #align composition.length_pos_of_pos Composition.length_pos_of_pos /-- The sum of the sizes of the blocks in a composition up to `i`. -/ def sizeUpTo (i : ℕ) : ℕ := (c.blocks.take i).sum #align composition.size_up_to Composition.sizeUpTo @[simp] theorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [sizeUpTo] #align composition.size_up_to_zero Composition.sizeUpTo_zero theorem sizeUpTo_ofLength_le (i : ℕ) (h : c.length ≤ i) : c.sizeUpTo i = n := by dsimp [sizeUpTo] convert c.blocks_sum exact take_all_of_le h #align composition.size_up_to_of_length_le Composition.sizeUpTo_ofLength_le @[simp] theorem sizeUpTo_length : c.sizeUpTo c.length = n := c.sizeUpTo_ofLength_le c.length le_rfl #align composition.size_up_to_length Composition.sizeUpTo_length theorem sizeUpTo_le (i : ℕ) : c.sizeUpTo i ≤ n := by conv_rhs => rw [← c.blocks_sum, ← sum_take_add_sum_drop _ i] exact Nat.le_add_right _ _ #align composition.size_up_to_le Composition.sizeUpTo_le theorem sizeUpTo_succ {i : ℕ} (h : i < c.length) : c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks.get ⟨i, h⟩ := by simp only [sizeUpTo] rw [sum_take_succ _ _ h] #align composition.size_up_to_succ Composition.sizeUpTo_succ theorem sizeUpTo_succ' (i : Fin c.length) : c.sizeUpTo ((i : ℕ) + 1) = c.sizeUpTo i + c.blocksFun i := c.sizeUpTo_succ i.2 #align composition.size_up_to_succ' Composition.sizeUpTo_succ' theorem sizeUpTo_strict_mono {i : ℕ} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) := by rw [c.sizeUpTo_succ h] simp #align composition.size_up_to_strict_mono Composition.sizeUpTo_strict_mono theorem monotone_sizeUpTo : Monotone c.sizeUpTo := monotone_sum_take _ #align composition.monotone_size_up_to Composition.monotone_sizeUpTo /-- The `i`-th boundary of a composition, i.e., the leftmost point of the `i`-th block. We include a virtual point at the right of the last block, to make for a nice equiv with `CompositionAsSet n`. -/ def boundary : Fin (c.length + 1) ↪o Fin (n + 1) := (OrderEmbedding.ofStrictMono fun i => ⟨c.sizeUpTo i, Nat.lt_succ_of_le (c.sizeUpTo_le i)⟩) <| Fin.strictMono_iff_lt_succ.2 fun ⟨_, hi⟩ => c.sizeUpTo_strict_mono hi #align composition.boundary Composition.boundary @[simp] theorem boundary_zero : c.boundary 0 = 0 := by simp [boundary, Fin.ext_iff] #align composition.boundary_zero Composition.boundary_zero @[simp] theorem boundary_last : c.boundary (Fin.last c.length) = Fin.last n := by simp [boundary, Fin.ext_iff] #align composition.boundary_last Composition.boundary_last /-- The boundaries of a composition, i.e., the leftmost point of all the blocks. We include a virtual point at the right of the last block, to make for a nice equiv with `CompositionAsSet n`. -/ def boundaries : Finset (Fin (n + 1)) := Finset.univ.map c.boundary.toEmbedding #align composition.boundaries Composition.boundaries theorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 := by simp [boundaries] #align composition.card_boundaries_eq_succ_length Composition.card_boundaries_eq_succ_length /-- To `c : Composition n`, one can associate a `CompositionAsSet n` by registering the leftmost point of each block, and adding a virtual point at the right of the last block. -/ def toCompositionAsSet : CompositionAsSet n where boundaries := c.boundaries zero_mem := by simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map] exact ⟨0, And.intro True.intro rfl⟩ getLast_mem := by simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map] exact ⟨Fin.last c.length, And.intro True.intro c.boundary_last⟩ #align composition.to_composition_as_set Composition.toCompositionAsSet /-- The canonical increasing bijection between `Fin (c.length + 1)` and `c.boundaries` is exactly `c.boundary`. -/ theorem orderEmbOfFin_boundaries : c.boundaries.orderEmbOfFin c.card_boundaries_eq_succ_length = c.boundary := by refine (Finset.orderEmbOfFin_unique' _ ?_).symm exact fun i => (Finset.mem_map' _).2 (Finset.mem_univ _) #align composition.order_emb_of_fin_boundaries Composition.orderEmbOfFin_boundaries /-- Embedding the `i`-th block of a composition (identified with `Fin (c.blocks_fun i)`) into `Fin n` at the relevant position. -/ def embedding (i : Fin c.length) : Fin (c.blocksFun i) ↪o Fin n := (Fin.natAddOrderEmb <| c.sizeUpTo i).trans <| Fin.castLEOrderEmb <| calc c.sizeUpTo i + c.blocksFun i = c.sizeUpTo (i + 1) := (c.sizeUpTo_succ _).symm _ ≤ c.sizeUpTo c.length := monotone_sum_take _ i.2 _ = n := c.sizeUpTo_length #align composition.embedding Composition.embedding @[simp] theorem coe_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) : (c.embedding i j : ℕ) = c.sizeUpTo i + j := rfl #align composition.coe_embedding Composition.coe_embedding /-- `index_exists` asserts there is some `i` with `j < c.size_up_to (i+1)`. In the next definition `index` we use `Nat.find` to produce the minimal such index. -/ theorem index_exists {j : ℕ} (h : j < n) : ∃ i : ℕ, j < c.sizeUpTo (i + 1) ∧ i < c.length := by have n_pos : 0 < n := lt_of_le_of_lt (zero_le j) h have : 0 < c.blocks.sum := by rwa [← c.blocks_sum] at n_pos have length_pos : 0 < c.blocks.length := length_pos_of_sum_pos (blocks c) this refine ⟨c.length - 1, ?_, Nat.pred_lt (ne_of_gt length_pos)⟩ have : c.length - 1 + 1 = c.length := Nat.succ_pred_eq_of_pos length_pos simp [this, h] #align composition.index_exists Composition.index_exists /-- `c.index j` is the index of the block in the composition `c` containing `j`. -/ def index (j : Fin n) : Fin c.length := ⟨Nat.find (c.index_exists j.2), (Nat.find_spec (c.index_exists j.2)).2⟩ #align composition.index Composition.index theorem lt_sizeUpTo_index_succ (j : Fin n) : (j : ℕ) < c.sizeUpTo (c.index j).succ := (Nat.find_spec (c.index_exists j.2)).1 #align composition.lt_size_up_to_index_succ Composition.lt_sizeUpTo_index_succ theorem sizeUpTo_index_le (j : Fin n) : c.sizeUpTo (c.index j) ≤ j := by by_contra H set i := c.index j push_neg at H have i_pos : (0 : ℕ) < i := by by_contra! i_pos revert H simp [nonpos_iff_eq_zero.1 i_pos, c.sizeUpTo_zero] let i₁ := (i : ℕ).pred have i₁_lt_i : i₁ < i := Nat.pred_lt (ne_of_gt i_pos) have i₁_succ : i₁ + 1 = i := Nat.succ_pred_eq_of_pos i_pos have := Nat.find_min (c.index_exists j.2) i₁_lt_i simp [lt_trans i₁_lt_i (c.index j).2, i₁_succ] at this exact Nat.lt_le_asymm H this #align composition.size_up_to_index_le Composition.sizeUpTo_index_le /-- Mapping an element `j` of `Fin n` to the element in the block containing it, identified with `Fin (c.blocks_fun (c.index j))` through the canonical increasing bijection. -/ def invEmbedding (j : Fin n) : Fin (c.blocksFun (c.index j)) := ⟨j - c.sizeUpTo (c.index j), by rw [tsub_lt_iff_right, add_comm, ← sizeUpTo_succ'] · exact lt_sizeUpTo_index_succ _ _ · exact sizeUpTo_index_le _ _⟩ #align composition.inv_embedding Composition.invEmbedding @[simp] theorem coe_invEmbedding (j : Fin n) : (c.invEmbedding j : ℕ) = j - c.sizeUpTo (c.index j) := rfl #align composition.coe_inv_embedding Composition.coe_invEmbedding theorem embedding_comp_inv (j : Fin n) : c.embedding (c.index j) (c.invEmbedding j) = j := by rw [Fin.ext_iff] apply add_tsub_cancel_of_le (c.sizeUpTo_index_le j) #align composition.embedding_comp_inv Composition.embedding_comp_inv
Mathlib/Combinatorics/Enumerative/Composition.lean
362
378
theorem mem_range_embedding_iff {j : Fin n} {i : Fin c.length} : j ∈ Set.range (c.embedding i) ↔ c.sizeUpTo i ≤ j ∧ (j : ℕ) < c.sizeUpTo (i : ℕ).succ := by
constructor · intro h rcases Set.mem_range.2 h with ⟨k, hk⟩ rw [Fin.ext_iff] at hk dsimp at hk rw [← hk] simp [sizeUpTo_succ', k.is_lt] · intro h apply Set.mem_range.2 refine ⟨⟨j - c.sizeUpTo i, ?_⟩, ?_⟩ · rw [tsub_lt_iff_left, ← sizeUpTo_succ'] · exact h.2 · exact h.1 · rw [Fin.ext_iff] exact add_tsub_cancel_of_le h.1
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.RingTheory.IntegralClosure import Mathlib.RingTheory.FractionalIdeal.Basic #align_import ring_theory.fractional_ideal from "leanprover-community/mathlib"@"ed90a7d327c3a5caf65a6faf7e8a0d63c4605df7" /-! # More operations on fractional ideals ## Main definitions * `map` is the pushforward of a fractional ideal along an algebra morphism Let `K` be the localization of `R` at `R⁰ = R \ {0}` (i.e. the field of fractions). * `FractionalIdeal R⁰ K` is the type of fractional ideals in the field of fractions * `Div (FractionalIdeal R⁰ K)` instance: the ideal quotient `I / J` (typically written $I : J$, but a `:` operator cannot be defined) ## Main statement * `isNoetherian` states that every fractional ideal of a noetherian integral domain is noetherian ## References * https://en.wikipedia.org/wiki/Fractional_ideal ## Tags fractional ideal, fractional ideals, invertible ideal -/ open IsLocalization Pointwise nonZeroDivisors namespace FractionalIdeal open Set Submodule variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] [loc : IsLocalization S P] section variable {P' : Type*} [CommRing P'] [Algebra R P'] [loc' : IsLocalization S P'] variable {P'' : Type*} [CommRing P''] [Algebra R P''] [loc'' : IsLocalization S P''] theorem _root_.IsFractional.map (g : P →ₐ[R] P') {I : Submodule R P} : IsFractional S I → IsFractional S (Submodule.map g.toLinearMap I) | ⟨a, a_nonzero, hI⟩ => ⟨a, a_nonzero, fun b hb => by obtain ⟨b', b'_mem, hb'⟩ := Submodule.mem_map.mp hb rw [AlgHom.toLinearMap_apply] at hb' obtain ⟨x, hx⟩ := hI b' b'_mem use x rw [← g.commutes, hx, g.map_smul, hb']⟩ #align is_fractional.map IsFractional.map /-- `I.map g` is the pushforward of the fractional ideal `I` along the algebra morphism `g` -/ def map (g : P →ₐ[R] P') : FractionalIdeal S P → FractionalIdeal S P' := fun I => ⟨Submodule.map g.toLinearMap I, I.isFractional.map g⟩ #align fractional_ideal.map FractionalIdeal.map @[simp, norm_cast] theorem coe_map (g : P →ₐ[R] P') (I : FractionalIdeal S P) : ↑(map g I) = Submodule.map g.toLinearMap I := rfl #align fractional_ideal.coe_map FractionalIdeal.coe_map @[simp] theorem mem_map {I : FractionalIdeal S P} {g : P →ₐ[R] P'} {y : P'} : y ∈ I.map g ↔ ∃ x, x ∈ I ∧ g x = y := Submodule.mem_map #align fractional_ideal.mem_map FractionalIdeal.mem_map variable (I J : FractionalIdeal S P) (g : P →ₐ[R] P') @[simp] theorem map_id : I.map (AlgHom.id _ _) = I := coeToSubmodule_injective (Submodule.map_id (I : Submodule R P)) #align fractional_ideal.map_id FractionalIdeal.map_id @[simp] theorem map_comp (g' : P' →ₐ[R] P'') : I.map (g'.comp g) = (I.map g).map g' := coeToSubmodule_injective (Submodule.map_comp g.toLinearMap g'.toLinearMap I) #align fractional_ideal.map_comp FractionalIdeal.map_comp @[simp, norm_cast] theorem map_coeIdeal (I : Ideal R) : (I : FractionalIdeal S P).map g = I := by ext x simp only [mem_coeIdeal] constructor · rintro ⟨_, ⟨y, hy, rfl⟩, rfl⟩ exact ⟨y, hy, (g.commutes y).symm⟩ · rintro ⟨y, hy, rfl⟩ exact ⟨_, ⟨y, hy, rfl⟩, g.commutes y⟩ #align fractional_ideal.map_coe_ideal FractionalIdeal.map_coeIdeal @[simp] theorem map_one : (1 : FractionalIdeal S P).map g = 1 := map_coeIdeal g ⊤ #align fractional_ideal.map_one FractionalIdeal.map_one @[simp] theorem map_zero : (0 : FractionalIdeal S P).map g = 0 := map_coeIdeal g 0 #align fractional_ideal.map_zero FractionalIdeal.map_zero @[simp] theorem map_add : (I + J).map g = I.map g + J.map g := coeToSubmodule_injective (Submodule.map_sup _ _ _) #align fractional_ideal.map_add FractionalIdeal.map_add @[simp] theorem map_mul : (I * J).map g = I.map g * J.map g := by simp only [mul_def] exact coeToSubmodule_injective (Submodule.map_mul _ _ _) #align fractional_ideal.map_mul FractionalIdeal.map_mul @[simp] theorem map_map_symm (g : P ≃ₐ[R] P') : (I.map (g : P →ₐ[R] P')).map (g.symm : P' →ₐ[R] P) = I := by rw [← map_comp, g.symm_comp, map_id] #align fractional_ideal.map_map_symm FractionalIdeal.map_map_symm @[simp] theorem map_symm_map (I : FractionalIdeal S P') (g : P ≃ₐ[R] P') : (I.map (g.symm : P' →ₐ[R] P)).map (g : P →ₐ[R] P') = I := by rw [← map_comp, g.comp_symm, map_id] #align fractional_ideal.map_symm_map FractionalIdeal.map_symm_map theorem map_mem_map {f : P →ₐ[R] P'} (h : Function.Injective f) {x : P} {I : FractionalIdeal S P} : f x ∈ map f I ↔ x ∈ I := mem_map.trans ⟨fun ⟨_, hx', x'_eq⟩ => h x'_eq ▸ hx', fun h => ⟨x, h, rfl⟩⟩ #align fractional_ideal.map_mem_map FractionalIdeal.map_mem_map theorem map_injective (f : P →ₐ[R] P') (h : Function.Injective f) : Function.Injective (map f : FractionalIdeal S P → FractionalIdeal S P') := fun _ _ hIJ => ext fun _ => (map_mem_map h).symm.trans (hIJ.symm ▸ map_mem_map h) #align fractional_ideal.map_injective FractionalIdeal.map_injective /-- If `g` is an equivalence, `map g` is an isomorphism -/ def mapEquiv (g : P ≃ₐ[R] P') : FractionalIdeal S P ≃+* FractionalIdeal S P' where toFun := map g invFun := map g.symm map_add' I J := map_add I J _ map_mul' I J := map_mul I J _ left_inv I := by rw [← map_comp, AlgEquiv.symm_comp, map_id] right_inv I := by rw [← map_comp, AlgEquiv.comp_symm, map_id] #align fractional_ideal.map_equiv FractionalIdeal.mapEquiv @[simp] theorem coeFun_mapEquiv (g : P ≃ₐ[R] P') : (mapEquiv g : FractionalIdeal S P → FractionalIdeal S P') = map g := rfl #align fractional_ideal.coe_fun_map_equiv FractionalIdeal.coeFun_mapEquiv @[simp] theorem mapEquiv_apply (g : P ≃ₐ[R] P') (I : FractionalIdeal S P) : mapEquiv g I = map (↑g) I := rfl #align fractional_ideal.map_equiv_apply FractionalIdeal.mapEquiv_apply @[simp] theorem mapEquiv_symm (g : P ≃ₐ[R] P') : ((mapEquiv g).symm : FractionalIdeal S P' ≃+* _) = mapEquiv g.symm := rfl #align fractional_ideal.map_equiv_symm FractionalIdeal.mapEquiv_symm @[simp] theorem mapEquiv_refl : mapEquiv AlgEquiv.refl = RingEquiv.refl (FractionalIdeal S P) := RingEquiv.ext fun x => by simp #align fractional_ideal.map_equiv_refl FractionalIdeal.mapEquiv_refl theorem isFractional_span_iff {s : Set P} : IsFractional S (span R s) ↔ ∃ a ∈ S, ∀ b : P, b ∈ s → IsInteger R (a • b) := ⟨fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun b hb => h b (subset_span hb)⟩, fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun b hb => span_induction hb h (by rw [smul_zero] exact isInteger_zero) (fun x y hx hy => by rw [smul_add] exact isInteger_add hx hy) fun s x hx => by rw [smul_comm] exact isInteger_smul hx⟩⟩ #align fractional_ideal.is_fractional_span_iff FractionalIdeal.isFractional_span_iff theorem isFractional_of_fg {I : Submodule R P} (hI : I.FG) : IsFractional S I := by rcases hI with ⟨I, rfl⟩ rcases exist_integer_multiples_of_finset S I with ⟨⟨s, hs1⟩, hs⟩ rw [isFractional_span_iff] exact ⟨s, hs1, hs⟩ #align fractional_ideal.is_fractional_of_fg FractionalIdeal.isFractional_of_fg theorem mem_span_mul_finite_of_mem_mul {I J : FractionalIdeal S P} {x : P} (hx : x ∈ I * J) : ∃ T T' : Finset P, (T : Set P) ⊆ I ∧ (T' : Set P) ⊆ J ∧ x ∈ span R (T * T' : Set P) := Submodule.mem_span_mul_finite_of_mem_mul (by simpa using mem_coe.mpr hx) #align fractional_ideal.mem_span_mul_finite_of_mem_mul FractionalIdeal.mem_span_mul_finite_of_mem_mul variable (S) theorem coeIdeal_fg (inj : Function.Injective (algebraMap R P)) (I : Ideal R) : FG ((I : FractionalIdeal S P) : Submodule R P) ↔ I.FG := coeSubmodule_fg _ inj _ #align fractional_ideal.coe_ideal_fg FractionalIdeal.coeIdeal_fg variable {S} theorem fg_unit (I : (FractionalIdeal S P)ˣ) : FG (I : Submodule R P) := Submodule.fg_unit <| Units.map (coeSubmoduleHom S P).toMonoidHom I #align fractional_ideal.fg_unit FractionalIdeal.fg_unit theorem fg_of_isUnit (I : FractionalIdeal S P) (h : IsUnit I) : FG (I : Submodule R P) := fg_unit h.unit #align fractional_ideal.fg_of_is_unit FractionalIdeal.fg_of_isUnit theorem _root_.Ideal.fg_of_isUnit (inj : Function.Injective (algebraMap R P)) (I : Ideal R) (h : IsUnit (I : FractionalIdeal S P)) : I.FG := by rw [← coeIdeal_fg S inj I] exact FractionalIdeal.fg_of_isUnit I h #align ideal.fg_of_is_unit Ideal.fg_of_isUnit variable (S P P') /-- `canonicalEquiv f f'` is the canonical equivalence between the fractional ideals in `P` and in `P'`, which are both localizations of `R` at `S`. -/ noncomputable irreducible_def canonicalEquiv : FractionalIdeal S P ≃+* FractionalIdeal S P' := mapEquiv { ringEquivOfRingEquiv P P' (RingEquiv.refl R) (show S.map _ = S by rw [RingEquiv.toMonoidHom_refl, Submonoid.map_id]) with commutes' := fun r => ringEquivOfRingEquiv_eq _ _ } #align fractional_ideal.canonical_equiv FractionalIdeal.canonicalEquiv @[simp] theorem mem_canonicalEquiv_apply {I : FractionalIdeal S P} {x : P'} : x ∈ canonicalEquiv S P P' I ↔ ∃ y ∈ I, IsLocalization.map P' (RingHom.id R) (fun y (hy : y ∈ S) => show RingHom.id R y ∈ S from hy) (y : P) = x := by rw [canonicalEquiv, mapEquiv_apply, mem_map] exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩ #align fractional_ideal.mem_canonical_equiv_apply FractionalIdeal.mem_canonicalEquiv_apply @[simp] theorem canonicalEquiv_symm : (canonicalEquiv S P P').symm = canonicalEquiv S P' P := RingEquiv.ext fun I => SetLike.ext_iff.mpr fun x => by rw [mem_canonicalEquiv_apply, canonicalEquiv, mapEquiv_symm, mapEquiv_apply, mem_map] exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩ #align fractional_ideal.canonical_equiv_symm FractionalIdeal.canonicalEquiv_symm theorem canonicalEquiv_flip (I) : canonicalEquiv S P P' (canonicalEquiv S P' P I) = I := by rw [← canonicalEquiv_symm]; erw [RingEquiv.apply_symm_apply] #align fractional_ideal.canonical_equiv_flip FractionalIdeal.canonicalEquiv_flip @[simp] theorem canonicalEquiv_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] (I : FractionalIdeal S P) : canonicalEquiv S P' P'' (canonicalEquiv S P P' I) = canonicalEquiv S P P'' I := by ext simp only [IsLocalization.map_map, RingHomInvPair.comp_eq₂, mem_canonicalEquiv_apply, exists_prop, exists_exists_and_eq_and] #align fractional_ideal.canonical_equiv_canonical_equiv FractionalIdeal.canonicalEquiv_canonicalEquiv theorem canonicalEquiv_trans_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] : (canonicalEquiv S P P').trans (canonicalEquiv S P' P'') = canonicalEquiv S P P'' := RingEquiv.ext (canonicalEquiv_canonicalEquiv S P P' P'') #align fractional_ideal.canonical_equiv_trans_canonical_equiv FractionalIdeal.canonicalEquiv_trans_canonicalEquiv @[simp] theorem canonicalEquiv_coeIdeal (I : Ideal R) : canonicalEquiv S P P' I = I := by ext simp [IsLocalization.map_eq] #align fractional_ideal.canonical_equiv_coe_ideal FractionalIdeal.canonicalEquiv_coeIdeal @[simp] theorem canonicalEquiv_self : canonicalEquiv S P P = RingEquiv.refl _ := by rw [← canonicalEquiv_trans_canonicalEquiv S P P] convert (canonicalEquiv S P P).symm_trans_self exact (canonicalEquiv_symm S P P).symm #align fractional_ideal.canonical_equiv_self FractionalIdeal.canonicalEquiv_self end section IsFractionRing /-! ### `IsFractionRing` section This section concerns fractional ideals in the field of fractions, i.e. the type `FractionalIdeal R⁰ K` where `IsFractionRing R K`. -/ variable {K K' : Type*} [Field K] [Field K'] variable [Algebra R K] [IsFractionRing R K] [Algebra R K'] [IsFractionRing R K'] variable {I J : FractionalIdeal R⁰ K} (h : K →ₐ[R] K') /-- Nonzero fractional ideals contain a nonzero integer. -/ theorem exists_ne_zero_mem_isInteger [Nontrivial R] (hI : I ≠ 0) : ∃ x, x ≠ 0 ∧ algebraMap R K x ∈ I := by obtain ⟨y : K, y_mem, y_not_mem⟩ := SetLike.exists_of_lt (by simpa only using bot_lt_iff_ne_bot.mpr hI) have y_ne_zero : y ≠ 0 := by simpa using y_not_mem obtain ⟨z, ⟨x, hx⟩⟩ := exists_integer_multiple R⁰ y refine ⟨x, ?_, ?_⟩ · rw [Ne, ← @IsFractionRing.to_map_eq_zero_iff R _ K, hx, Algebra.smul_def] exact mul_ne_zero (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors z.2) y_ne_zero · rw [hx] exact smul_mem _ _ y_mem #align fractional_ideal.exists_ne_zero_mem_is_integer FractionalIdeal.exists_ne_zero_mem_isInteger theorem map_ne_zero [Nontrivial R] (hI : I ≠ 0) : I.map h ≠ 0 := by obtain ⟨x, x_ne_zero, hx⟩ := exists_ne_zero_mem_isInteger hI contrapose! x_ne_zero with map_eq_zero refine IsFractionRing.to_map_eq_zero_iff.mp (eq_zero_iff.mp map_eq_zero _ (mem_map.mpr ?_)) exact ⟨algebraMap R K x, hx, h.commutes x⟩ #align fractional_ideal.map_ne_zero FractionalIdeal.map_ne_zero @[simp] theorem map_eq_zero_iff [Nontrivial R] : I.map h = 0 ↔ I = 0 := ⟨not_imp_not.mp (map_ne_zero _), fun hI => hI.symm ▸ map_zero h⟩ #align fractional_ideal.map_eq_zero_iff FractionalIdeal.map_eq_zero_iff theorem coeIdeal_injective : Function.Injective (fun (I : Ideal R) ↦ (I : FractionalIdeal R⁰ K)) := coeIdeal_injective' le_rfl #align fractional_ideal.coe_ideal_injective FractionalIdeal.coeIdeal_injective theorem coeIdeal_inj {I J : Ideal R} : (I : FractionalIdeal R⁰ K) = (J : FractionalIdeal R⁰ K) ↔ I = J := coeIdeal_inj' le_rfl #align fractional_ideal.coe_ideal_inj FractionalIdeal.coeIdeal_inj @[simp] theorem coeIdeal_eq_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 0 ↔ I = ⊥ := coeIdeal_eq_zero' le_rfl #align fractional_ideal.coe_ideal_eq_zero FractionalIdeal.coeIdeal_eq_zero theorem coeIdeal_ne_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 0 ↔ I ≠ ⊥ := coeIdeal_ne_zero' le_rfl #align fractional_ideal.coe_ideal_ne_zero FractionalIdeal.coeIdeal_ne_zero @[simp] theorem coeIdeal_eq_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 1 ↔ I = 1 := by simpa only [Ideal.one_eq_top] using coeIdeal_inj #align fractional_ideal.coe_ideal_eq_one FractionalIdeal.coeIdeal_eq_one theorem coeIdeal_ne_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 1 ↔ I ≠ 1 := not_iff_not.mpr coeIdeal_eq_one #align fractional_ideal.coe_ideal_ne_one FractionalIdeal.coeIdeal_ne_one theorem num_eq_zero_iff [Nontrivial R] {I : FractionalIdeal R⁰ K} : I.num = 0 ↔ I = 0 := ⟨fun h ↦ zero_of_num_eq_bot zero_not_mem_nonZeroDivisors h, fun h ↦ h ▸ num_zero_eq (IsFractionRing.injective R K)⟩ end IsFractionRing section Quotient /-! ### `quotient` section This section defines the ideal quotient of fractional ideals. In this section we need that each non-zero `y : R` has an inverse in the localization, i.e. that the localization is a field. We satisfy this assumption by taking `S = nonZeroDivisors R`, `R`'s localization at which is a field because `R` is a domain. -/ open scoped Classical variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K] variable [Algebra R₁ K] [frac : IsFractionRing R₁ K] instance : Nontrivial (FractionalIdeal R₁⁰ K) := ⟨⟨0, 1, fun h => have this : (1 : K) ∈ (0 : FractionalIdeal R₁⁰ K) := by rw [← (algebraMap R₁ K).map_one] simpa only [h] using coe_mem_one R₁⁰ 1 one_ne_zero ((mem_zero_iff _).mp this)⟩⟩ theorem ne_zero_of_mul_eq_one (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : I ≠ 0 := fun hI => zero_ne_one' (FractionalIdeal R₁⁰ K) (by convert h simp [hI]) #align fractional_ideal.ne_zero_of_mul_eq_one FractionalIdeal.ne_zero_of_mul_eq_one variable [IsDomain R₁] theorem _root_.IsFractional.div_of_nonzero {I J : Submodule R₁ K} : IsFractional R₁⁰ I → IsFractional R₁⁰ J → J ≠ 0 → IsFractional R₁⁰ (I / J) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩, h => by obtain ⟨y, mem_J, not_mem_zero⟩ := SetLike.exists_of_lt (show 0 < J by simpa only using bot_lt_iff_ne_bot.mpr h) obtain ⟨y', hy'⟩ := hJ y mem_J use aI * y' constructor · apply (nonZeroDivisors R₁).mul_mem haI (mem_nonZeroDivisors_iff_ne_zero.mpr _) intro y'_eq_zero have : algebraMap R₁ K aJ * y = 0 := by rw [← Algebra.smul_def, ← hy', y'_eq_zero, RingHom.map_zero] have y_zero := (mul_eq_zero.mp this).resolve_left (mt ((injective_iff_map_eq_zero (algebraMap R₁ K)).1 (IsFractionRing.injective _ _) _) (mem_nonZeroDivisors_iff_ne_zero.mp haJ)) apply not_mem_zero simpa intro b hb convert hI _ (hb _ (Submodule.smul_mem _ aJ mem_J)) using 1 rw [← hy', mul_comm b, ← Algebra.smul_def, mul_smul] #align is_fractional.div_of_nonzero IsFractional.div_of_nonzero theorem fractional_div_of_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : IsFractional R₁⁰ (I / J : Submodule R₁ K) := I.isFractional.div_of_nonzero J.isFractional fun H => h <| coeToSubmodule_injective <| H.trans coe_zero.symm #align fractional_ideal.fractional_div_of_nonzero FractionalIdeal.fractional_div_of_nonzero noncomputable instance : Div (FractionalIdeal R₁⁰ K) := ⟨fun I J => if h : J = 0 then 0 else ⟨I / J, fractional_div_of_nonzero h⟩⟩ variable {I J : FractionalIdeal R₁⁰ K} @[simp] theorem div_zero {I : FractionalIdeal R₁⁰ K} : I / 0 = 0 := dif_pos rfl #align fractional_ideal.div_zero FractionalIdeal.div_zero theorem div_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : I / J = ⟨I / J, fractional_div_of_nonzero h⟩ := dif_neg h #align fractional_ideal.div_nonzero FractionalIdeal.div_nonzero @[simp] theorem coe_div {I J : FractionalIdeal R₁⁰ K} (hJ : J ≠ 0) : (↑(I / J) : Submodule R₁ K) = ↑I / (↑J : Submodule R₁ K) := congr_arg _ (dif_neg hJ) #align fractional_ideal.coe_div FractionalIdeal.coe_div theorem mem_div_iff_of_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) {x} : x ∈ I / J ↔ ∀ y ∈ J, x * y ∈ I := by rw [div_nonzero h] exact Submodule.mem_div_iff_forall_mul_mem #align fractional_ideal.mem_div_iff_of_nonzero FractionalIdeal.mem_div_iff_of_nonzero theorem mul_one_div_le_one {I : FractionalIdeal R₁⁰ K} : I * (1 / I) ≤ 1 := by by_cases hI : I = 0 · rw [hI, div_zero, mul_zero] exact zero_le 1 · rw [← coe_le_coe, coe_mul, coe_div hI, coe_one] apply Submodule.mul_one_div_le_one #align fractional_ideal.mul_one_div_le_one FractionalIdeal.mul_one_div_le_one theorem le_self_mul_one_div {I : FractionalIdeal R₁⁰ K} (hI : I ≤ (1 : FractionalIdeal R₁⁰ K)) : I ≤ I * (1 / I) := by by_cases hI_nz : I = 0 · rw [hI_nz, div_zero, mul_zero] · rw [← coe_le_coe, coe_mul, coe_div hI_nz, coe_one] rw [← coe_le_coe, coe_one] at hI exact Submodule.le_self_mul_one_div hI #align fractional_ideal.le_self_mul_one_div FractionalIdeal.le_self_mul_one_div theorem le_div_iff_of_nonzero {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) : I ≤ J / J' ↔ ∀ x ∈ I, ∀ y ∈ J', x * y ∈ J := ⟨fun h _ hx => (mem_div_iff_of_nonzero hJ').mp (h hx), fun h x hx => (mem_div_iff_of_nonzero hJ').mpr (h x hx)⟩ #align fractional_ideal.le_div_iff_of_nonzero FractionalIdeal.le_div_iff_of_nonzero theorem le_div_iff_mul_le {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) : I ≤ J / J' ↔ I * J' ≤ J := by rw [div_nonzero hJ'] -- Porting note: this used to be { convert; rw }, flipped the order. rw [← coe_le_coe (I := I * J') (J := J), coe_mul] exact Submodule.le_div_iff_mul_le #align fractional_ideal.le_div_iff_mul_le FractionalIdeal.le_div_iff_mul_le @[simp] theorem div_one {I : FractionalIdeal R₁⁰ K} : I / 1 = I := by rw [div_nonzero (one_ne_zero' (FractionalIdeal R₁⁰ K))] ext constructor <;> intro h · simpa using mem_div_iff_forall_mul_mem.mp h 1 ((algebraMap R₁ K).map_one ▸ coe_mem_one R₁⁰ 1) · apply mem_div_iff_forall_mul_mem.mpr rintro y ⟨y', _, rfl⟩ -- Porting note: this used to be { convert; rw }, flipped the order. rw [mul_comm, Algebra.linearMap_apply, ← Algebra.smul_def] exact Submodule.smul_mem _ y' h #align fractional_ideal.div_one FractionalIdeal.div_one theorem eq_one_div_of_mul_eq_one_right (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : J = 1 / I := by have hI : I ≠ 0 := ne_zero_of_mul_eq_one I J h suffices h' : I * (1 / I) = 1 from congr_arg Units.inv <| @Units.ext _ _ (Units.mkOfMulEqOne _ _ h) (Units.mkOfMulEqOne _ _ h') rfl apply le_antisymm · apply mul_le.mpr _ intro x hx y hy rw [mul_comm] exact (mem_div_iff_of_nonzero hI).mp hy x hx rw [← h] apply mul_left_mono I apply (le_div_iff_of_nonzero hI).mpr _ intro y hy x hx rw [mul_comm] exact mul_mem_mul hx hy #align fractional_ideal.eq_one_div_of_mul_eq_one_right FractionalIdeal.eq_one_div_of_mul_eq_one_right theorem mul_div_self_cancel_iff {I : FractionalIdeal R₁⁰ K} : I * (1 / I) = 1 ↔ ∃ J, I * J = 1 := ⟨fun h => ⟨1 / I, h⟩, fun ⟨J, hJ⟩ => by rwa [← eq_one_div_of_mul_eq_one_right I J hJ]⟩ #align fractional_ideal.mul_div_self_cancel_iff FractionalIdeal.mul_div_self_cancel_iff variable {K' : Type*} [Field K'] [Algebra R₁ K'] [IsFractionRing R₁ K'] @[simp] theorem map_div (I J : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : (I / J).map (h : K →ₐ[R₁] K') = I.map h / J.map h := by by_cases H : J = 0 · rw [H, div_zero, map_zero, div_zero] · -- Porting note: `simp` wouldn't apply these lemmas so do them manually using `rw` rw [← coeToSubmodule_inj, div_nonzero H, div_nonzero (map_ne_zero _ H)] simp [Submodule.map_div] #align fractional_ideal.map_div FractionalIdeal.map_div -- Porting note: doesn't need to be @[simp] because this follows from `map_one` and `map_div` theorem map_one_div (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : (1 / I).map (h : K →ₐ[R₁] K') = 1 / I.map h := by rw [map_div, map_one] #align fractional_ideal.map_one_div FractionalIdeal.map_one_div end Quotient section Field variable {R₁ K L : Type*} [CommRing R₁] [Field K] [Field L] variable [Algebra R₁ K] [IsFractionRing R₁ K] [Algebra K L] [IsFractionRing K L] theorem eq_zero_or_one (I : FractionalIdeal K⁰ L) : I = 0 ∨ I = 1 := by rw [or_iff_not_imp_left] intro hI simp_rw [@SetLike.ext_iff _ _ _ I 1, mem_one_iff] intro x constructor · intro x_mem obtain ⟨n, d, rfl⟩ := IsLocalization.mk'_surjective K⁰ x refine ⟨n / d, ?_⟩ rw [map_div₀, IsFractionRing.mk'_eq_div] · rintro ⟨x, rfl⟩ obtain ⟨y, y_ne, y_mem⟩ := exists_ne_zero_mem_isInteger hI rw [← div_mul_cancel₀ x y_ne, RingHom.map_mul, ← Algebra.smul_def] exact smul_mem (M := L) I (x / y) y_mem #align fractional_ideal.eq_zero_or_one FractionalIdeal.eq_zero_or_one theorem eq_zero_or_one_of_isField (hF : IsField R₁) (I : FractionalIdeal R₁⁰ K) : I = 0 ∨ I = 1 := letI : Field R₁ := hF.toField eq_zero_or_one I #align fractional_ideal.eq_zero_or_one_of_is_field FractionalIdeal.eq_zero_or_one_of_isField end Field section PrincipalIdeal variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K] variable [Algebra R₁ K] [IsFractionRing R₁ K] open scoped Classical variable (R₁) /-- `FractionalIdeal.span_finset R₁ s f` is the fractional ideal of `R₁` generated by `f '' s`. -/ -- Porting note: `@[simps]` generated a `Subtype.val` coercion instead of a -- `FractionalIdeal.coeToSubmodule` coercion def spanFinset {ι : Type*} (s : Finset ι) (f : ι → K) : FractionalIdeal R₁⁰ K := ⟨Submodule.span R₁ (f '' s), by obtain ⟨a', ha'⟩ := IsLocalization.exist_integer_multiples R₁⁰ s f refine ⟨a', a'.2, fun x hx => Submodule.span_induction hx ?_ ?_ ?_ ?_⟩ · rintro _ ⟨i, hi, rfl⟩ exact ha' i hi · rw [smul_zero] exact IsLocalization.isInteger_zero · intro x y hx hy rw [smul_add] exact IsLocalization.isInteger_add hx hy · intro c x hx rw [smul_comm] exact IsLocalization.isInteger_smul hx⟩ #align fractional_ideal.span_finset FractionalIdeal.spanFinset @[simp] lemma spanFinset_coe {ι : Type*} (s : Finset ι) (f : ι → K) : (spanFinset R₁ s f : Submodule R₁ K) = Submodule.span R₁ (f '' s) := rfl variable {R₁} @[simp] theorem spanFinset_eq_zero {ι : Type*} {s : Finset ι} {f : ι → K} : spanFinset R₁ s f = 0 ↔ ∀ j ∈ s, f j = 0 := by simp only [← coeToSubmodule_inj, spanFinset_coe, coe_zero, Submodule.span_eq_bot, Set.mem_image, Finset.mem_coe, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] #align fractional_ideal.span_finset_eq_zero FractionalIdeal.spanFinset_eq_zero theorem spanFinset_ne_zero {ι : Type*} {s : Finset ι} {f : ι → K} : spanFinset R₁ s f ≠ 0 ↔ ∃ j ∈ s, f j ≠ 0 := by simp #align fractional_ideal.span_finset_ne_zero FractionalIdeal.spanFinset_ne_zero open Submodule.IsPrincipal theorem isFractional_span_singleton (x : P) : IsFractional S (span R {x} : Submodule R P) := let ⟨a, ha⟩ := exists_integer_multiple S x isFractional_span_iff.mpr ⟨a, a.2, fun _ hx' => (Set.mem_singleton_iff.mp hx').symm ▸ ha⟩ #align fractional_ideal.is_fractional_span_singleton FractionalIdeal.isFractional_span_singleton variable (S) /-- `spanSingleton x` is the fractional ideal generated by `x` if `0 ∉ S` -/ irreducible_def spanSingleton (x : P) : FractionalIdeal S P := ⟨span R {x}, isFractional_span_singleton x⟩ #align fractional_ideal.span_singleton FractionalIdeal.spanSingleton -- local attribute [semireducible] span_singleton @[simp] theorem coe_spanSingleton (x : P) : (spanSingleton S x : Submodule R P) = span R {x} := by rw [spanSingleton] rfl #align fractional_ideal.coe_span_singleton FractionalIdeal.coe_spanSingleton @[simp] theorem mem_spanSingleton {x y : P} : x ∈ spanSingleton S y ↔ ∃ z : R, z • y = x := by rw [spanSingleton] exact Submodule.mem_span_singleton #align fractional_ideal.mem_span_singleton FractionalIdeal.mem_spanSingleton theorem mem_spanSingleton_self (x : P) : x ∈ spanSingleton S x := (mem_spanSingleton S).mpr ⟨1, one_smul _ _⟩ #align fractional_ideal.mem_span_singleton_self FractionalIdeal.mem_spanSingleton_self variable (P) in /-- A version of `FractionalIdeal.den_mul_self_eq_num` in terms of fractional ideals. -/ theorem den_mul_self_eq_num' (I : FractionalIdeal S P) : spanSingleton S (algebraMap R P I.den) * I = I.num := by apply coeToSubmodule_injective dsimp only rw [coe_mul, ← smul_eq_mul, coe_spanSingleton, smul_eq_mul, Submodule.span_singleton_mul] convert I.den_mul_self_eq_num using 1 ext erw [Set.mem_smul_set, Set.mem_smul_set] simp [Algebra.smul_def] variable {S} @[simp] theorem spanSingleton_le_iff_mem {x : P} {I : FractionalIdeal S P} : spanSingleton S x ≤ I ↔ x ∈ I := by rw [← coe_le_coe, coe_spanSingleton, Submodule.span_singleton_le_iff_mem, mem_coe] #align fractional_ideal.span_singleton_le_iff_mem FractionalIdeal.spanSingleton_le_iff_mem theorem spanSingleton_eq_spanSingleton [NoZeroSMulDivisors R P] {x y : P} : spanSingleton S x = spanSingleton S y ↔ ∃ z : Rˣ, z • x = y := by rw [← Submodule.span_singleton_eq_span_singleton, spanSingleton, spanSingleton] exact Subtype.mk_eq_mk #align fractional_ideal.span_singleton_eq_span_singleton FractionalIdeal.spanSingleton_eq_spanSingleton theorem eq_spanSingleton_of_principal (I : FractionalIdeal S P) [IsPrincipal (I : Submodule R P)] : I = spanSingleton S (generator (I : Submodule R P)) := by -- Porting note: this used to be `coeToSubmodule_injective (span_singleton_generator ↑I).symm` -- but Lean 4 struggled to unify everything. Turned it into an explicit `rw`. rw [spanSingleton, ← coeToSubmodule_inj, coe_mk, span_singleton_generator] #align fractional_ideal.eq_span_singleton_of_principal FractionalIdeal.eq_spanSingleton_of_principal theorem isPrincipal_iff (I : FractionalIdeal S P) : IsPrincipal (I : Submodule R P) ↔ ∃ x, I = spanSingleton S x := ⟨fun h => ⟨@generator _ _ _ _ _ (↑I) h, @eq_spanSingleton_of_principal _ _ _ _ _ _ _ I h⟩, fun ⟨x, hx⟩ => { principal' := ⟨x, Eq.trans (congr_arg _ hx) (coe_spanSingleton _ x)⟩ }⟩ #align fractional_ideal.is_principal_iff FractionalIdeal.isPrincipal_iff @[simp] theorem spanSingleton_zero : spanSingleton S (0 : P) = 0 := by ext simp [Submodule.mem_span_singleton, eq_comm] #align fractional_ideal.span_singleton_zero FractionalIdeal.spanSingleton_zero theorem spanSingleton_eq_zero_iff {y : P} : spanSingleton S y = 0 ↔ y = 0 := ⟨fun h => span_eq_bot.mp (by simpa using congr_arg Subtype.val h : span R {y} = ⊥) y (mem_singleton y), fun h => by simp [h]⟩ #align fractional_ideal.span_singleton_eq_zero_iff FractionalIdeal.spanSingleton_eq_zero_iff theorem spanSingleton_ne_zero_iff {y : P} : spanSingleton S y ≠ 0 ↔ y ≠ 0 := not_congr spanSingleton_eq_zero_iff #align fractional_ideal.span_singleton_ne_zero_iff FractionalIdeal.spanSingleton_ne_zero_iff @[simp] theorem spanSingleton_one : spanSingleton S (1 : P) = 1 := by ext refine (mem_spanSingleton S).trans ((exists_congr ?_).trans (mem_one_iff S).symm) intro x' rw [Algebra.smul_def, mul_one] #align fractional_ideal.span_singleton_one FractionalIdeal.spanSingleton_one @[simp] theorem spanSingleton_mul_spanSingleton (x y : P) : spanSingleton S x * spanSingleton S y = spanSingleton S (x * y) := by apply coeToSubmodule_injective simp only [coe_mul, coe_spanSingleton, span_mul_span, singleton_mul_singleton] #align fractional_ideal.span_singleton_mul_span_singleton FractionalIdeal.spanSingleton_mul_spanSingleton @[simp] theorem spanSingleton_pow (x : P) (n : ℕ) : spanSingleton S x ^ n = spanSingleton S (x ^ n) := by induction' n with n hn · rw [pow_zero, pow_zero, spanSingleton_one] · rw [pow_succ, hn, spanSingleton_mul_spanSingleton, pow_succ] #align fractional_ideal.span_singleton_pow FractionalIdeal.spanSingleton_pow @[simp]
Mathlib/RingTheory/FractionalIdeal/Operations.lean
722
733
theorem coeIdeal_span_singleton (x : R) : (↑(Ideal.span {x} : Ideal R) : FractionalIdeal S P) = spanSingleton S (algebraMap R P x) := by
ext y refine (mem_coeIdeal S).trans (Iff.trans ?_ (mem_spanSingleton S).symm) constructor · rintro ⟨y', hy', rfl⟩ obtain ⟨x', rfl⟩ := Submodule.mem_span_singleton.mp hy' use x' rw [smul_eq_mul, RingHom.map_mul, Algebra.smul_def] · rintro ⟨y', rfl⟩ refine ⟨y' * x, Submodule.mem_span_singleton.mpr ⟨y', rfl⟩, ?_⟩ rw [RingHom.map_mul, Algebra.smul_def]
/- Copyright (c) 2019 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Data.Bracket import Mathlib.LinearAlgebra.Basic #align_import algebra.lie.basic from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988" /-! # Lie algebras This file defines Lie rings and Lie algebras over a commutative ring together with their modules, morphisms and equivalences, as well as various lemmas to make these definitions usable. ## Main definitions * `LieRing` * `LieAlgebra` * `LieRingModule` * `LieModule` * `LieHom` * `LieEquiv` * `LieModuleHom` * `LieModuleEquiv` ## Notation Working over a fixed commutative ring `R`, we introduce the notations: * `L →ₗ⁅R⁆ L'` for a morphism of Lie algebras, * `L ≃ₗ⁅R⁆ L'` for an equivalence of Lie algebras, * `M →ₗ⁅R,L⁆ N` for a morphism of Lie algebra modules `M`, `N` over a Lie algebra `L`, * `M ≃ₗ⁅R,L⁆ N` for an equivalence of Lie algebra modules `M`, `N` over a Lie algebra `L`. ## Implementation notes Lie algebras are defined as modules with a compatible Lie ring structure and thus, like modules, are partially unbundled. ## References * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 1--3*](bourbaki1975) ## Tags lie bracket, jacobi identity, lie ring, lie algebra, lie module -/ universe u v w w₁ w₂ open Function /-- A Lie ring is an additive group with compatible product, known as the bracket, satisfying the Jacobi identity. -/ class LieRing (L : Type v) extends AddCommGroup L, Bracket L L where /-- A Lie ring bracket is additive in its first component. -/ protected add_lie : ∀ x y z : L, ⁅x + y, z⁆ = ⁅x, z⁆ + ⁅y, z⁆ /-- A Lie ring bracket is additive in its second component. -/ protected lie_add : ∀ x y z : L, ⁅x, y + z⁆ = ⁅x, y⁆ + ⁅x, z⁆ /-- A Lie ring bracket vanishes on the diagonal in L × L. -/ protected lie_self : ∀ x : L, ⁅x, x⁆ = 0 /-- A Lie ring bracket satisfies a Leibniz / Jacobi identity. -/ protected leibniz_lie : ∀ x y z : L, ⁅x, ⁅y, z⁆⁆ = ⁅⁅x, y⁆, z⁆ + ⁅y, ⁅x, z⁆⁆ #align lie_ring LieRing /-- A Lie algebra is a module with compatible product, known as the bracket, satisfying the Jacobi identity. Forgetting the scalar multiplication, every Lie algebra is a Lie ring. -/ class LieAlgebra (R : Type u) (L : Type v) [CommRing R] [LieRing L] extends Module R L where /-- A Lie algebra bracket is compatible with scalar multiplication in its second argument. The compatibility in the first argument is not a class property, but follows since every Lie algebra has a natural Lie module action on itself, see `LieModule`. -/ protected lie_smul : ∀ (t : R) (x y : L), ⁅x, t • y⁆ = t • ⁅x, y⁆ #align lie_algebra LieAlgebra /-- A Lie ring module is an additive group, together with an additive action of a Lie ring on this group, such that the Lie bracket acts as the commutator of endomorphisms. (For representations of Lie *algebras* see `LieModule`.) -/ class LieRingModule (L : Type v) (M : Type w) [LieRing L] [AddCommGroup M] extends Bracket L M where /-- A Lie ring module bracket is additive in its first component. -/ protected add_lie : ∀ (x y : L) (m : M), ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ /-- A Lie ring module bracket is additive in its second component. -/ protected lie_add : ∀ (x : L) (m n : M), ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ /-- A Lie ring module bracket satisfies a Leibniz / Jacobi identity. -/ protected leibniz_lie : ∀ (x y : L) (m : M), ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ #align lie_ring_module LieRingModule /-- A Lie module is a module over a commutative ring, together with a linear action of a Lie algebra on this module, such that the Lie bracket acts as the commutator of endomorphisms. -/ class LieModule (R : Type u) (L : Type v) (M : Type w) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] : Prop where /-- A Lie module bracket is compatible with scalar multiplication in its first argument. -/ protected smul_lie : ∀ (t : R) (x : L) (m : M), ⁅t • x, m⁆ = t • ⁅x, m⁆ /-- A Lie module bracket is compatible with scalar multiplication in its second argument. -/ protected lie_smul : ∀ (t : R) (x : L) (m : M), ⁅x, t • m⁆ = t • ⁅x, m⁆ #align lie_module LieModule section BasicProperties variable {R : Type u} {L : Type v} {M : Type w} {N : Type w₁} variable [CommRing R] [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [AddCommGroup N] [Module R N] [LieRingModule L N] [LieModule R L N] variable (t : R) (x y z : L) (m n : M) @[simp] theorem add_lie : ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ := LieRingModule.add_lie x y m #align add_lie add_lie @[simp] theorem lie_add : ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ := LieRingModule.lie_add x m n #align lie_add lie_add @[simp] theorem smul_lie : ⁅t • x, m⁆ = t • ⁅x, m⁆ := LieModule.smul_lie t x m #align smul_lie smul_lie @[simp] theorem lie_smul : ⁅x, t • m⁆ = t • ⁅x, m⁆ := LieModule.lie_smul t x m #align lie_smul lie_smul theorem leibniz_lie : ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ := LieRingModule.leibniz_lie x y m #align leibniz_lie leibniz_lie @[simp] theorem lie_zero : ⁅x, 0⁆ = (0 : M) := (AddMonoidHom.mk' _ (lie_add x)).map_zero #align lie_zero lie_zero @[simp] theorem zero_lie : ⁅(0 : L), m⁆ = 0 := (AddMonoidHom.mk' (fun x : L => ⁅x, m⁆) fun x y => add_lie x y m).map_zero #align zero_lie zero_lie @[simp] theorem lie_self : ⁅x, x⁆ = 0 := LieRing.lie_self x #align lie_self lie_self instance lieRingSelfModule : LieRingModule L L := { (inferInstance : LieRing L) with } #align lie_ring_self_module lieRingSelfModule @[simp]
Mathlib/Algebra/Lie/Basic.lean
151
153
theorem lie_skew : -⁅y, x⁆ = ⁅x, y⁆ := by
have h : ⁅x + y, x⁆ + ⁅x + y, y⁆ = 0 := by rw [← lie_add]; apply lie_self simpa [neg_eq_iff_add_eq_zero] using h
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Yaël Dillies -/ import Mathlib.Data.Finset.NAry import Mathlib.Data.Finset.Preimage import Mathlib.Data.Set.Pointwise.Finite import Mathlib.Data.Set.Pointwise.SMul import Mathlib.Data.Set.Pointwise.ListOfFn import Mathlib.GroupTheory.GroupAction.Pi import Mathlib.SetTheory.Cardinal.Finite #align_import data.finset.pointwise from "leanprover-community/mathlib"@"eba7871095e834365616b5e43c8c7bb0b37058d0" /-! # Pointwise operations of finsets This file defines pointwise algebraic operations on finsets. ## Main declarations For finsets `s` and `t`: * `0` (`Finset.zero`): The singleton `{0}`. * `1` (`Finset.one`): The singleton `{1}`. * `-s` (`Finset.neg`): Negation, finset of all `-x` where `x ∈ s`. * `s⁻¹` (`Finset.inv`): Inversion, finset of all `x⁻¹` where `x ∈ s`. * `s + t` (`Finset.add`): Addition, finset of all `x + y` where `x ∈ s` and `y ∈ t`. * `s * t` (`Finset.mul`): Multiplication, finset of all `x * y` where `x ∈ s` and `y ∈ t`. * `s - t` (`Finset.sub`): Subtraction, finset of all `x - y` where `x ∈ s` and `y ∈ t`. * `s / t` (`Finset.div`): Division, finset of all `x / y` where `x ∈ s` and `y ∈ t`. * `s +ᵥ t` (`Finset.vadd`): Scalar addition, finset of all `x +ᵥ y` where `x ∈ s` and `y ∈ t`. * `s • t` (`Finset.smul`): Scalar multiplication, finset of all `x • y` where `x ∈ s` and `y ∈ t`. * `s -ᵥ t` (`Finset.vsub`): Scalar subtraction, finset of all `x -ᵥ y` where `x ∈ s` and `y ∈ t`. * `a • s` (`Finset.smulFinset`): Scaling, finset of all `a • x` where `x ∈ s`. * `a +ᵥ s` (`Finset.vaddFinset`): Translation, finset of all `a +ᵥ x` where `x ∈ s`. For `α` a semigroup/monoid, `Finset α` is a semigroup/monoid. As an unfortunate side effect, this means that `n • s`, where `n : ℕ`, is ambiguous between pointwise scaling and repeated pointwise addition; the former has `(2 : ℕ) • {1, 2} = {2, 4}`, while the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`. See note [pointwise nat action]. ## Implementation notes We put all instances in the locale `Pointwise`, so that these instances are not available by default. Note that we do not mark them as reducible (as argued by note [reducible non-instances]) since we expect the locale to be open whenever the instances are actually used (and making the instances reducible changes the behavior of `simp`. ## Tags finset multiplication, finset addition, pointwise addition, pointwise multiplication, pointwise subtraction -/ open Function MulOpposite open scoped Pointwise variable {F α β γ : Type*} namespace Finset /-! ### `0`/`1` as finsets -/ section One variable [One α] {s : Finset α} {a : α} /-- The finset `1 : Finset α` is defined as `{1}` in locale `Pointwise`. -/ @[to_additive "The finset `0 : Finset α` is defined as `{0}` in locale `Pointwise`."] protected def one : One (Finset α) := ⟨{1}⟩ #align finset.has_one Finset.one #align finset.has_zero Finset.zero scoped[Pointwise] attribute [instance] Finset.one Finset.zero @[to_additive (attr := simp)] theorem mem_one : a ∈ (1 : Finset α) ↔ a = 1 := mem_singleton #align finset.mem_one Finset.mem_one #align finset.mem_zero Finset.mem_zero @[to_additive (attr := simp, norm_cast)] theorem coe_one : ↑(1 : Finset α) = (1 : Set α) := coe_singleton 1 #align finset.coe_one Finset.coe_one #align finset.coe_zero Finset.coe_zero @[to_additive (attr := simp, norm_cast)] lemma coe_eq_one : (s : Set α) = 1 ↔ s = 1 := coe_eq_singleton @[to_additive (attr := simp)] theorem one_subset : (1 : Finset α) ⊆ s ↔ (1 : α) ∈ s := singleton_subset_iff #align finset.one_subset Finset.one_subset #align finset.zero_subset Finset.zero_subset @[to_additive] theorem singleton_one : ({1} : Finset α) = 1 := rfl #align finset.singleton_one Finset.singleton_one #align finset.singleton_zero Finset.singleton_zero @[to_additive] theorem one_mem_one : (1 : α) ∈ (1 : Finset α) := mem_singleton_self _ #align finset.one_mem_one Finset.one_mem_one #align finset.zero_mem_zero Finset.zero_mem_zero @[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))] theorem one_nonempty : (1 : Finset α).Nonempty := ⟨1, one_mem_one⟩ #align finset.one_nonempty Finset.one_nonempty #align finset.zero_nonempty Finset.zero_nonempty @[to_additive (attr := simp)] protected theorem map_one {f : α ↪ β} : map f 1 = {f 1} := map_singleton f 1 #align finset.map_one Finset.map_one #align finset.map_zero Finset.map_zero @[to_additive (attr := simp)] theorem image_one [DecidableEq β] {f : α → β} : image f 1 = {f 1} := image_singleton _ _ #align finset.image_one Finset.image_one #align finset.image_zero Finset.image_zero @[to_additive] theorem subset_one_iff_eq : s ⊆ 1 ↔ s = ∅ ∨ s = 1 := subset_singleton_iff #align finset.subset_one_iff_eq Finset.subset_one_iff_eq #align finset.subset_zero_iff_eq Finset.subset_zero_iff_eq @[to_additive] theorem Nonempty.subset_one_iff (h : s.Nonempty) : s ⊆ 1 ↔ s = 1 := h.subset_singleton_iff #align finset.nonempty.subset_one_iff Finset.Nonempty.subset_one_iff #align finset.nonempty.subset_zero_iff Finset.Nonempty.subset_zero_iff @[to_additive (attr := simp)] theorem card_one : (1 : Finset α).card = 1 := card_singleton _ #align finset.card_one Finset.card_one #align finset.card_zero Finset.card_zero /-- The singleton operation as a `OneHom`. -/ @[to_additive "The singleton operation as a `ZeroHom`."] def singletonOneHom : OneHom α (Finset α) where toFun := singleton; map_one' := singleton_one #align finset.singleton_one_hom Finset.singletonOneHom #align finset.singleton_zero_hom Finset.singletonZeroHom @[to_additive (attr := simp)] theorem coe_singletonOneHom : (singletonOneHom : α → Finset α) = singleton := rfl #align finset.coe_singleton_one_hom Finset.coe_singletonOneHom #align finset.coe_singleton_zero_hom Finset.coe_singletonZeroHom @[to_additive (attr := simp)] theorem singletonOneHom_apply (a : α) : singletonOneHom a = {a} := rfl #align finset.singleton_one_hom_apply Finset.singletonOneHom_apply #align finset.singleton_zero_hom_apply Finset.singletonZeroHom_apply /-- Lift a `OneHom` to `Finset` via `image`. -/ @[to_additive (attr := simps) "Lift a `ZeroHom` to `Finset` via `image`"] def imageOneHom [DecidableEq β] [One β] [FunLike F α β] [OneHomClass F α β] (f : F) : OneHom (Finset α) (Finset β) where toFun := Finset.image f map_one' := by rw [image_one, map_one, singleton_one] #align finset.image_one_hom Finset.imageOneHom #align finset.image_zero_hom Finset.imageZeroHom @[to_additive (attr := simp)] lemma sup_one [SemilatticeSup β] [OrderBot β] (f : α → β) : sup 1 f = f 1 := sup_singleton @[to_additive (attr := simp)] lemma sup'_one [SemilatticeSup β] (f : α → β) : sup' 1 one_nonempty f = f 1 := rfl @[to_additive (attr := simp)] lemma inf_one [SemilatticeInf β] [OrderTop β] (f : α → β) : inf 1 f = f 1 := inf_singleton @[to_additive (attr := simp)] lemma inf'_one [SemilatticeInf β] (f : α → β) : inf' 1 one_nonempty f = f 1 := rfl @[to_additive (attr := simp)] lemma max_one [LinearOrder α] : (1 : Finset α).max = 1 := rfl @[to_additive (attr := simp)] lemma min_one [LinearOrder α] : (1 : Finset α).min = 1 := rfl @[to_additive (attr := simp)] lemma max'_one [LinearOrder α] : (1 : Finset α).max' one_nonempty = 1 := rfl @[to_additive (attr := simp)] lemma min'_one [LinearOrder α] : (1 : Finset α).min' one_nonempty = 1 := rfl end One /-! ### Finset negation/inversion -/ section Inv variable [DecidableEq α] [Inv α] {s s₁ s₂ t t₁ t₂ u : Finset α} {a b : α} /-- The pointwise inversion of finset `s⁻¹` is defined as `{x⁻¹ | x ∈ s}` in locale `Pointwise`. -/ @[to_additive "The pointwise negation of finset `-s` is defined as `{-x | x ∈ s}` in locale `Pointwise`."] protected def inv : Inv (Finset α) := ⟨image Inv.inv⟩ #align finset.has_inv Finset.inv #align finset.has_neg Finset.neg scoped[Pointwise] attribute [instance] Finset.inv Finset.neg @[to_additive] theorem inv_def : s⁻¹ = s.image fun x => x⁻¹ := rfl #align finset.inv_def Finset.inv_def #align finset.neg_def Finset.neg_def @[to_additive] theorem image_inv : (s.image fun x => x⁻¹) = s⁻¹ := rfl #align finset.image_inv Finset.image_inv #align finset.image_neg Finset.image_neg @[to_additive] theorem mem_inv {x : α} : x ∈ s⁻¹ ↔ ∃ y ∈ s, y⁻¹ = x := mem_image #align finset.mem_inv Finset.mem_inv #align finset.mem_neg Finset.mem_neg @[to_additive] theorem inv_mem_inv (ha : a ∈ s) : a⁻¹ ∈ s⁻¹ := mem_image_of_mem _ ha #align finset.inv_mem_inv Finset.inv_mem_inv #align finset.neg_mem_neg Finset.neg_mem_neg @[to_additive] theorem card_inv_le : s⁻¹.card ≤ s.card := card_image_le #align finset.card_inv_le Finset.card_inv_le #align finset.card_neg_le Finset.card_neg_le @[to_additive (attr := simp)] theorem inv_empty : (∅ : Finset α)⁻¹ = ∅ := image_empty _ #align finset.inv_empty Finset.inv_empty #align finset.neg_empty Finset.neg_empty @[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))] theorem inv_nonempty_iff : s⁻¹.Nonempty ↔ s.Nonempty := image_nonempty #align finset.inv_nonempty_iff Finset.inv_nonempty_iff #align finset.neg_nonempty_iff Finset.neg_nonempty_iff alias ⟨Nonempty.of_inv, Nonempty.inv⟩ := inv_nonempty_iff #align finset.nonempty.of_inv Finset.Nonempty.of_inv #align finset.nonempty.inv Finset.Nonempty.inv attribute [to_additive] Nonempty.inv Nonempty.of_inv @[to_additive (attr := simp)] theorem inv_eq_empty : s⁻¹ = ∅ ↔ s = ∅ := image_eq_empty @[to_additive (attr := mono)] theorem inv_subset_inv (h : s ⊆ t) : s⁻¹ ⊆ t⁻¹ := image_subset_image h #align finset.inv_subset_inv Finset.inv_subset_inv #align finset.neg_subset_neg Finset.neg_subset_neg @[to_additive (attr := simp)] theorem inv_singleton (a : α) : ({a} : Finset α)⁻¹ = {a⁻¹} := image_singleton _ _ #align finset.inv_singleton Finset.inv_singleton #align finset.neg_singleton Finset.neg_singleton @[to_additive (attr := simp)] theorem inv_insert (a : α) (s : Finset α) : (insert a s)⁻¹ = insert a⁻¹ s⁻¹ := image_insert _ _ _ #align finset.inv_insert Finset.inv_insert #align finset.neg_insert Finset.neg_insert @[to_additive (attr := simp)] lemma sup_inv [SemilatticeSup β] [OrderBot β] (s : Finset α) (f : α → β) : sup s⁻¹ f = sup s (f ·⁻¹) := sup_image .. @[to_additive (attr := simp)] lemma sup'_inv [SemilatticeSup β] {s : Finset α} (hs : s⁻¹.Nonempty) (f : α → β) : sup' s⁻¹ hs f = sup' s hs.of_inv (f ·⁻¹) := sup'_image .. @[to_additive (attr := simp)] lemma inf_inv [SemilatticeInf β] [OrderTop β] (s : Finset α) (f : α → β) : inf s⁻¹ f = inf s (f ·⁻¹) := inf_image .. @[to_additive (attr := simp)] lemma inf'_inv [SemilatticeInf β] {s : Finset α} (hs : s⁻¹.Nonempty) (f : α → β) : inf' s⁻¹ hs f = inf' s hs.of_inv (f ·⁻¹) := inf'_image .. @[to_additive] lemma image_op_inv (s : Finset α) : s⁻¹.image op = (s.image op)⁻¹ := image_comm op_inv end Inv open Pointwise section InvolutiveInv variable [DecidableEq α] [InvolutiveInv α] {s : Finset α} {a : α} @[to_additive (attr := simp)] lemma mem_inv' : a ∈ s⁻¹ ↔ a⁻¹ ∈ s := by simp [mem_inv, inv_eq_iff_eq_inv] @[to_additive (attr := simp, norm_cast)] theorem coe_inv (s : Finset α) : ↑s⁻¹ = (s : Set α)⁻¹ := coe_image.trans Set.image_inv #align finset.coe_inv Finset.coe_inv #align finset.coe_neg Finset.coe_neg @[to_additive (attr := simp)] theorem card_inv (s : Finset α) : s⁻¹.card = s.card := card_image_of_injective _ inv_injective #align finset.card_inv Finset.card_inv #align finset.card_neg Finset.card_neg @[to_additive (attr := simp)] theorem preimage_inv (s : Finset α) : s.preimage (·⁻¹) inv_injective.injOn = s⁻¹ := coe_injective <| by rw [coe_preimage, Set.inv_preimage, coe_inv] #align finset.preimage_inv Finset.preimage_inv #align finset.preimage_neg Finset.preimage_neg @[to_additive (attr := simp)] lemma inv_univ [Fintype α] : (univ : Finset α)⁻¹ = univ := by ext; simp @[to_additive (attr := simp)] lemma inv_inter (s t : Finset α) : (s ∩ t)⁻¹ = s⁻¹ ∩ t⁻¹ := coe_injective <| by simp end InvolutiveInv /-! ### Finset addition/multiplication -/ section Mul variable [DecidableEq α] [DecidableEq β] [Mul α] [Mul β] [FunLike F α β] [MulHomClass F α β] (f : F) {s s₁ s₂ t t₁ t₂ u : Finset α} {a b : α} /-- The pointwise multiplication of finsets `s * t` and `t` is defined as `{x * y | x ∈ s, y ∈ t}` in locale `Pointwise`. -/ @[to_additive "The pointwise addition of finsets `s + t` is defined as `{x + y | x ∈ s, y ∈ t}` in locale `Pointwise`."] protected def mul : Mul (Finset α) := ⟨image₂ (· * ·)⟩ #align finset.has_mul Finset.mul #align finset.has_add Finset.add scoped[Pointwise] attribute [instance] Finset.mul Finset.add @[to_additive] theorem mul_def : s * t = (s ×ˢ t).image fun p : α × α => p.1 * p.2 := rfl #align finset.mul_def Finset.mul_def #align finset.add_def Finset.add_def @[to_additive] theorem image_mul_product : ((s ×ˢ t).image fun x : α × α => x.fst * x.snd) = s * t := rfl #align finset.image_mul_product Finset.image_mul_product #align finset.image_add_product Finset.image_add_product @[to_additive] theorem mem_mul {x : α} : x ∈ s * t ↔ ∃ y ∈ s, ∃ z ∈ t, y * z = x := mem_image₂ #align finset.mem_mul Finset.mem_mul #align finset.mem_add Finset.mem_add @[to_additive (attr := simp, norm_cast)] theorem coe_mul (s t : Finset α) : (↑(s * t) : Set α) = ↑s * ↑t := coe_image₂ _ _ _ #align finset.coe_mul Finset.coe_mul #align finset.coe_add Finset.coe_add @[to_additive] theorem mul_mem_mul : a ∈ s → b ∈ t → a * b ∈ s * t := mem_image₂_of_mem #align finset.mul_mem_mul Finset.mul_mem_mul #align finset.add_mem_add Finset.add_mem_add @[to_additive] theorem card_mul_le : (s * t).card ≤ s.card * t.card := card_image₂_le _ _ _ #align finset.card_mul_le Finset.card_mul_le #align finset.card_add_le Finset.card_add_le @[to_additive] theorem card_mul_iff : (s * t).card = s.card * t.card ↔ (s ×ˢ t : Set (α × α)).InjOn fun p => p.1 * p.2 := card_image₂_iff #align finset.card_mul_iff Finset.card_mul_iff #align finset.card_add_iff Finset.card_add_iff @[to_additive (attr := simp)] theorem empty_mul (s : Finset α) : ∅ * s = ∅ := image₂_empty_left #align finset.empty_mul Finset.empty_mul #align finset.empty_add Finset.empty_add @[to_additive (attr := simp)] theorem mul_empty (s : Finset α) : s * ∅ = ∅ := image₂_empty_right #align finset.mul_empty Finset.mul_empty #align finset.add_empty Finset.add_empty @[to_additive (attr := simp)] theorem mul_eq_empty : s * t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff #align finset.mul_eq_empty Finset.mul_eq_empty #align finset.add_eq_empty Finset.add_eq_empty @[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))] theorem mul_nonempty : (s * t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff #align finset.mul_nonempty Finset.mul_nonempty #align finset.add_nonempty Finset.add_nonempty @[to_additive] theorem Nonempty.mul : s.Nonempty → t.Nonempty → (s * t).Nonempty := Nonempty.image₂ #align finset.nonempty.mul Finset.Nonempty.mul #align finset.nonempty.add Finset.Nonempty.add @[to_additive] theorem Nonempty.of_mul_left : (s * t).Nonempty → s.Nonempty := Nonempty.of_image₂_left #align finset.nonempty.of_mul_left Finset.Nonempty.of_mul_left #align finset.nonempty.of_add_left Finset.Nonempty.of_add_left @[to_additive] theorem Nonempty.of_mul_right : (s * t).Nonempty → t.Nonempty := Nonempty.of_image₂_right #align finset.nonempty.of_mul_right Finset.Nonempty.of_mul_right #align finset.nonempty.of_add_right Finset.Nonempty.of_add_right @[to_additive] theorem mul_singleton (a : α) : s * {a} = s.image (· * a) := image₂_singleton_right #align finset.mul_singleton Finset.mul_singleton #align finset.add_singleton Finset.add_singleton @[to_additive] theorem singleton_mul (a : α) : {a} * s = s.image (a * ·) := image₂_singleton_left #align finset.singleton_mul Finset.singleton_mul #align finset.singleton_add Finset.singleton_add @[to_additive (attr := simp)] theorem singleton_mul_singleton (a b : α) : ({a} : Finset α) * {b} = {a * b} := image₂_singleton #align finset.singleton_mul_singleton Finset.singleton_mul_singleton #align finset.singleton_add_singleton Finset.singleton_add_singleton @[to_additive (attr := mono)] theorem mul_subset_mul : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ * t₁ ⊆ s₂ * t₂ := image₂_subset #align finset.mul_subset_mul Finset.mul_subset_mul #align finset.add_subset_add Finset.add_subset_add @[to_additive] theorem mul_subset_mul_left : t₁ ⊆ t₂ → s * t₁ ⊆ s * t₂ := image₂_subset_left #align finset.mul_subset_mul_left Finset.mul_subset_mul_left #align finset.add_subset_add_left Finset.add_subset_add_left @[to_additive] theorem mul_subset_mul_right : s₁ ⊆ s₂ → s₁ * t ⊆ s₂ * t := image₂_subset_right #align finset.mul_subset_mul_right Finset.mul_subset_mul_right #align finset.add_subset_add_right Finset.add_subset_add_right @[to_additive] theorem mul_subset_iff : s * t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x * y ∈ u := image₂_subset_iff #align finset.mul_subset_iff Finset.mul_subset_iff #align finset.add_subset_iff Finset.add_subset_iff @[to_additive] theorem union_mul : (s₁ ∪ s₂) * t = s₁ * t ∪ s₂ * t := image₂_union_left #align finset.union_mul Finset.union_mul #align finset.union_add Finset.union_add @[to_additive] theorem mul_union : s * (t₁ ∪ t₂) = s * t₁ ∪ s * t₂ := image₂_union_right #align finset.mul_union Finset.mul_union #align finset.add_union Finset.add_union @[to_additive] theorem inter_mul_subset : s₁ ∩ s₂ * t ⊆ s₁ * t ∩ (s₂ * t) := image₂_inter_subset_left #align finset.inter_mul_subset Finset.inter_mul_subset #align finset.inter_add_subset Finset.inter_add_subset @[to_additive] theorem mul_inter_subset : s * (t₁ ∩ t₂) ⊆ s * t₁ ∩ (s * t₂) := image₂_inter_subset_right #align finset.mul_inter_subset Finset.mul_inter_subset #align finset.add_inter_subset Finset.add_inter_subset @[to_additive] theorem inter_mul_union_subset_union : s₁ ∩ s₂ * (t₁ ∪ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ := image₂_inter_union_subset_union #align finset.inter_mul_union_subset_union Finset.inter_mul_union_subset_union #align finset.inter_add_union_subset_union Finset.inter_add_union_subset_union @[to_additive] theorem union_mul_inter_subset_union : (s₁ ∪ s₂) * (t₁ ∩ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ := image₂_union_inter_subset_union #align finset.union_mul_inter_subset_union Finset.union_mul_inter_subset_union #align finset.union_add_inter_subset_union Finset.union_add_inter_subset_union /-- If a finset `u` is contained in the product of two sets `s * t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' * t'`. -/ @[to_additive "If a finset `u` is contained in the sum of two sets `s + t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' + t'`."] theorem subset_mul {s t : Set α} : ↑u ⊆ s * t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' * t' := subset_image₂ #align finset.subset_mul Finset.subset_mul #align finset.subset_add Finset.subset_add @[to_additive] theorem image_mul : (s * t).image (f : α → β) = s.image f * t.image f := image_image₂_distrib <| map_mul f #align finset.image_mul Finset.image_mul #align finset.image_add Finset.image_add /-- The singleton operation as a `MulHom`. -/ @[to_additive "The singleton operation as an `AddHom`."] def singletonMulHom : α →ₙ* Finset α where toFun := singleton; map_mul' _ _ := (singleton_mul_singleton _ _).symm #align finset.singleton_mul_hom Finset.singletonMulHom #align finset.singleton_add_hom Finset.singletonAddHom @[to_additive (attr := simp)] theorem coe_singletonMulHom : (singletonMulHom : α → Finset α) = singleton := rfl #align finset.coe_singleton_mul_hom Finset.coe_singletonMulHom #align finset.coe_singleton_add_hom Finset.coe_singletonAddHom @[to_additive (attr := simp)] theorem singletonMulHom_apply (a : α) : singletonMulHom a = {a} := rfl #align finset.singleton_mul_hom_apply Finset.singletonMulHom_apply #align finset.singleton_add_hom_apply Finset.singletonAddHom_apply /-- Lift a `MulHom` to `Finset` via `image`. -/ @[to_additive (attr := simps) "Lift an `AddHom` to `Finset` via `image`"] def imageMulHom : Finset α →ₙ* Finset β where toFun := Finset.image f map_mul' _ _ := image_mul _ #align finset.image_mul_hom Finset.imageMulHom #align finset.image_add_hom Finset.imageAddHom @[to_additive (attr := simp (default + 1))] lemma sup_mul_le [SemilatticeSup β] [OrderBot β] {s t : Finset α} {f : α → β} {a : β} : sup (s * t) f ≤ a ↔ ∀ x ∈ s, ∀ y ∈ t, f (x * y) ≤ a := sup_image₂_le @[to_additive] lemma sup_mul_left [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) : sup (s * t) f = sup s fun x ↦ sup t (f <| x * ·) := sup_image₂_left .. @[to_additive] lemma sup_mul_right [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) : sup (s * t) f = sup t fun y ↦ sup s (f <| · * y) := sup_image₂_right .. @[to_additive (attr := simp (default + 1))] lemma le_inf_mul [SemilatticeInf β] [OrderTop β] {s t : Finset α} {f : α → β} {a : β} : a ≤ inf (s * t) f ↔ ∀ x ∈ s, ∀ y ∈ t, a ≤ f (x * y) := le_inf_image₂ @[to_additive] lemma inf_mul_left [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) : inf (s * t) f = inf s fun x ↦ inf t (f <| x * ·) := inf_image₂_left .. @[to_additive] lemma inf_mul_right [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) : inf (s * t) f = inf t fun y ↦ inf s (f <| · * y) := inf_image₂_right .. end Mul /-! ### Finset subtraction/division -/ section Div variable [DecidableEq α] [Div α] {s s₁ s₂ t t₁ t₂ u : Finset α} {a b : α} /-- The pointwise division of finsets `s / t` is defined as `{x / y | x ∈ s, y ∈ t}` in locale `Pointwise`. -/ @[to_additive "The pointwise subtraction of finsets `s - t` is defined as `{x - y | x ∈ s, y ∈ t}` in locale `Pointwise`."] protected def div : Div (Finset α) := ⟨image₂ (· / ·)⟩ #align finset.has_div Finset.div #align finset.has_sub Finset.sub scoped[Pointwise] attribute [instance] Finset.div Finset.sub @[to_additive] theorem div_def : s / t = (s ×ˢ t).image fun p : α × α => p.1 / p.2 := rfl #align finset.div_def Finset.div_def #align finset.sub_def Finset.sub_def @[to_additive] theorem image_div_product : ((s ×ˢ t).image fun x : α × α => x.fst / x.snd) = s / t := rfl #align finset.image_div_prod Finset.image_div_product #align finset.add_image_prod Finset.image_sub_product @[to_additive] theorem mem_div : a ∈ s / t ↔ ∃ b ∈ s, ∃ c ∈ t, b / c = a := mem_image₂ #align finset.mem_div Finset.mem_div #align finset.mem_sub Finset.mem_sub @[to_additive (attr := simp, norm_cast)] theorem coe_div (s t : Finset α) : (↑(s / t) : Set α) = ↑s / ↑t := coe_image₂ _ _ _ #align finset.coe_div Finset.coe_div #align finset.coe_sub Finset.coe_sub @[to_additive] theorem div_mem_div : a ∈ s → b ∈ t → a / b ∈ s / t := mem_image₂_of_mem #align finset.div_mem_div Finset.div_mem_div #align finset.sub_mem_sub Finset.sub_mem_sub @[to_additive] theorem div_card_le : (s / t).card ≤ s.card * t.card := card_image₂_le _ _ _ #align finset.div_card_le Finset.div_card_le #align finset.sub_card_le Finset.sub_card_le @[to_additive (attr := simp)] theorem empty_div (s : Finset α) : ∅ / s = ∅ := image₂_empty_left #align finset.empty_div Finset.empty_div #align finset.empty_sub Finset.empty_sub @[to_additive (attr := simp)] theorem div_empty (s : Finset α) : s / ∅ = ∅ := image₂_empty_right #align finset.div_empty Finset.div_empty #align finset.sub_empty Finset.sub_empty @[to_additive (attr := simp)] theorem div_eq_empty : s / t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff #align finset.div_eq_empty Finset.div_eq_empty #align finset.sub_eq_empty Finset.sub_eq_empty @[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))] theorem div_nonempty : (s / t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff #align finset.div_nonempty Finset.div_nonempty #align finset.sub_nonempty Finset.sub_nonempty @[to_additive] theorem Nonempty.div : s.Nonempty → t.Nonempty → (s / t).Nonempty := Nonempty.image₂ #align finset.nonempty.div Finset.Nonempty.div #align finset.nonempty.sub Finset.Nonempty.sub @[to_additive] theorem Nonempty.of_div_left : (s / t).Nonempty → s.Nonempty := Nonempty.of_image₂_left #align finset.nonempty.of_div_left Finset.Nonempty.of_div_left #align finset.nonempty.of_sub_left Finset.Nonempty.of_sub_left @[to_additive] theorem Nonempty.of_div_right : (s / t).Nonempty → t.Nonempty := Nonempty.of_image₂_right #align finset.nonempty.of_div_right Finset.Nonempty.of_div_right #align finset.nonempty.of_sub_right Finset.Nonempty.of_sub_right @[to_additive (attr := simp)] theorem div_singleton (a : α) : s / {a} = s.image (· / a) := image₂_singleton_right #align finset.div_singleton Finset.div_singleton #align finset.sub_singleton Finset.sub_singleton @[to_additive (attr := simp)] theorem singleton_div (a : α) : {a} / s = s.image (a / ·) := image₂_singleton_left #align finset.singleton_div Finset.singleton_div #align finset.singleton_sub Finset.singleton_sub -- @[to_additive (attr := simp)] -- Porting note (#10618): simp can prove this & the additive version @[to_additive] theorem singleton_div_singleton (a b : α) : ({a} : Finset α) / {b} = {a / b} := image₂_singleton #align finset.singleton_div_singleton Finset.singleton_div_singleton #align finset.singleton_sub_singleton Finset.singleton_sub_singleton @[to_additive (attr := mono)] theorem div_subset_div : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ / t₁ ⊆ s₂ / t₂ := image₂_subset #align finset.div_subset_div Finset.div_subset_div #align finset.sub_subset_sub Finset.sub_subset_sub @[to_additive] theorem div_subset_div_left : t₁ ⊆ t₂ → s / t₁ ⊆ s / t₂ := image₂_subset_left #align finset.div_subset_div_left Finset.div_subset_div_left #align finset.sub_subset_sub_left Finset.sub_subset_sub_left @[to_additive] theorem div_subset_div_right : s₁ ⊆ s₂ → s₁ / t ⊆ s₂ / t := image₂_subset_right #align finset.div_subset_div_right Finset.div_subset_div_right #align finset.sub_subset_sub_right Finset.sub_subset_sub_right @[to_additive] theorem div_subset_iff : s / t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x / y ∈ u := image₂_subset_iff #align finset.div_subset_iff Finset.div_subset_iff #align finset.sub_subset_iff Finset.sub_subset_iff @[to_additive] theorem union_div : (s₁ ∪ s₂) / t = s₁ / t ∪ s₂ / t := image₂_union_left #align finset.union_div Finset.union_div #align finset.union_sub Finset.union_sub @[to_additive] theorem div_union : s / (t₁ ∪ t₂) = s / t₁ ∪ s / t₂ := image₂_union_right #align finset.div_union Finset.div_union #align finset.sub_union Finset.sub_union @[to_additive] theorem inter_div_subset : s₁ ∩ s₂ / t ⊆ s₁ / t ∩ (s₂ / t) := image₂_inter_subset_left #align finset.inter_div_subset Finset.inter_div_subset #align finset.inter_sub_subset Finset.inter_sub_subset @[to_additive] theorem div_inter_subset : s / (t₁ ∩ t₂) ⊆ s / t₁ ∩ (s / t₂) := image₂_inter_subset_right #align finset.div_inter_subset Finset.div_inter_subset #align finset.sub_inter_subset Finset.sub_inter_subset @[to_additive] theorem inter_div_union_subset_union : s₁ ∩ s₂ / (t₁ ∪ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ := image₂_inter_union_subset_union #align finset.inter_div_union_subset_union Finset.inter_div_union_subset_union #align finset.inter_sub_union_subset_union Finset.inter_sub_union_subset_union @[to_additive] theorem union_div_inter_subset_union : (s₁ ∪ s₂) / (t₁ ∩ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ := image₂_union_inter_subset_union #align finset.union_div_inter_subset_union Finset.union_div_inter_subset_union #align finset.union_sub_inter_subset_union Finset.union_sub_inter_subset_union /-- If a finset `u` is contained in the product of two sets `s / t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' / t'`. -/ @[to_additive "If a finset `u` is contained in the sum of two sets `s - t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' - t'`."] theorem subset_div {s t : Set α} : ↑u ⊆ s / t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' / t' := subset_image₂ #align finset.subset_div Finset.subset_div #align finset.subset_sub Finset.subset_sub @[to_additive (attr := simp (default + 1))] lemma sup_div_le [SemilatticeSup β] [OrderBot β] {s t : Finset α} {f : α → β} {a : β} : sup (s / t) f ≤ a ↔ ∀ x ∈ s, ∀ y ∈ t, f (x / y) ≤ a := sup_image₂_le @[to_additive] lemma sup_div_left [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) : sup (s / t) f = sup s fun x ↦ sup t (f <| x / ·) := sup_image₂_left .. @[to_additive] lemma sup_div_right [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) : sup (s / t) f = sup t fun y ↦ sup s (f <| · / y) := sup_image₂_right .. @[to_additive (attr := simp (default + 1))] lemma le_inf_div [SemilatticeInf β] [OrderTop β] {s t : Finset α} {f : α → β} {a : β} : a ≤ inf (s / t) f ↔ ∀ x ∈ s, ∀ y ∈ t, a ≤ f (x / y) := le_inf_image₂ @[to_additive] lemma inf_div_left [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) : inf (s / t) f = inf s fun x ↦ inf t (f <| x / ·) := inf_image₂_left .. @[to_additive] lemma inf_div_right [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) : inf (s / t) f = inf t fun y ↦ inf s (f <| · / y) := inf_image₂_right .. end Div /-! ### Instances -/ open Pointwise section Instances variable [DecidableEq α] [DecidableEq β] /-- Repeated pointwise addition (not the same as pointwise repeated addition!) of a `Finset`. See note [pointwise nat action]. -/ protected def nsmul [Zero α] [Add α] : SMul ℕ (Finset α) := ⟨nsmulRec⟩ #align finset.has_nsmul Finset.nsmul /-- Repeated pointwise multiplication (not the same as pointwise repeated multiplication!) of a `Finset`. See note [pointwise nat action]. -/ protected def npow [One α] [Mul α] : Pow (Finset α) ℕ := ⟨fun s n => npowRec n s⟩ #align finset.has_npow Finset.npow attribute [to_additive existing] Finset.npow /-- Repeated pointwise addition/subtraction (not the same as pointwise repeated addition/subtraction!) of a `Finset`. See note [pointwise nat action]. -/ protected def zsmul [Zero α] [Add α] [Neg α] : SMul ℤ (Finset α) := ⟨zsmulRec⟩ #align finset.has_zsmul Finset.zsmul /-- Repeated pointwise multiplication/division (not the same as pointwise repeated multiplication/division!) of a `Finset`. See note [pointwise nat action]. -/ @[to_additive existing] protected def zpow [One α] [Mul α] [Inv α] : Pow (Finset α) ℤ := ⟨fun s n => zpowRec npowRec n s⟩ #align finset.has_zpow Finset.zpow scoped[Pointwise] attribute [instance] Finset.nsmul Finset.npow Finset.zsmul Finset.zpow /-- `Finset α` is a `Semigroup` under pointwise operations if `α` is. -/ @[to_additive "`Finset α` is an `AddSemigroup` under pointwise operations if `α` is. "] protected def semigroup [Semigroup α] : Semigroup (Finset α) := coe_injective.semigroup _ coe_mul #align finset.semigroup Finset.semigroup #align finset.add_semigroup Finset.addSemigroup section CommSemigroup variable [CommSemigroup α] {s t : Finset α} /-- `Finset α` is a `CommSemigroup` under pointwise operations if `α` is. -/ @[to_additive "`Finset α` is an `AddCommSemigroup` under pointwise operations if `α` is. "] protected def commSemigroup : CommSemigroup (Finset α) := coe_injective.commSemigroup _ coe_mul #align finset.comm_semigroup Finset.commSemigroup #align finset.add_comm_semigroup Finset.addCommSemigroup @[to_additive] theorem inter_mul_union_subset : s ∩ t * (s ∪ t) ⊆ s * t := image₂_inter_union_subset mul_comm #align finset.inter_mul_union_subset Finset.inter_mul_union_subset #align finset.inter_add_union_subset Finset.inter_add_union_subset @[to_additive] theorem union_mul_inter_subset : (s ∪ t) * (s ∩ t) ⊆ s * t := image₂_union_inter_subset mul_comm #align finset.union_mul_inter_subset Finset.union_mul_inter_subset #align finset.union_add_inter_subset Finset.union_add_inter_subset end CommSemigroup section MulOneClass variable [MulOneClass α] /-- `Finset α` is a `MulOneClass` under pointwise operations if `α` is. -/ @[to_additive "`Finset α` is an `AddZeroClass` under pointwise operations if `α` is."] protected def mulOneClass : MulOneClass (Finset α) := coe_injective.mulOneClass _ (coe_singleton 1) coe_mul #align finset.mul_one_class Finset.mulOneClass #align finset.add_zero_class Finset.addZeroClass scoped[Pointwise] attribute [instance] Finset.semigroup Finset.addSemigroup Finset.commSemigroup Finset.addCommSemigroup Finset.mulOneClass Finset.addZeroClass @[to_additive] theorem subset_mul_left (s : Finset α) {t : Finset α} (ht : (1 : α) ∈ t) : s ⊆ s * t := fun a ha => mem_mul.2 ⟨a, ha, 1, ht, mul_one _⟩ #align finset.subset_mul_left Finset.subset_mul_left #align finset.subset_add_left Finset.subset_add_left @[to_additive] theorem subset_mul_right {s : Finset α} (t : Finset α) (hs : (1 : α) ∈ s) : t ⊆ s * t := fun a ha => mem_mul.2 ⟨1, hs, a, ha, one_mul _⟩ #align finset.subset_mul_right Finset.subset_mul_right #align finset.subset_add_right Finset.subset_add_right /-- The singleton operation as a `MonoidHom`. -/ @[to_additive "The singleton operation as an `AddMonoidHom`."] def singletonMonoidHom : α →* Finset α := { singletonMulHom, singletonOneHom with } #align finset.singleton_monoid_hom Finset.singletonMonoidHom #align finset.singleton_add_monoid_hom Finset.singletonAddMonoidHom @[to_additive (attr := simp)] theorem coe_singletonMonoidHom : (singletonMonoidHom : α → Finset α) = singleton := rfl #align finset.coe_singleton_monoid_hom Finset.coe_singletonMonoidHom #align finset.coe_singleton_add_monoid_hom Finset.coe_singletonAddMonoidHom @[to_additive (attr := simp)] theorem singletonMonoidHom_apply (a : α) : singletonMonoidHom a = {a} := rfl #align finset.singleton_monoid_hom_apply Finset.singletonMonoidHom_apply #align finset.singleton_add_monoid_hom_apply Finset.singletonAddMonoidHom_apply /-- The coercion from `Finset` to `Set` as a `MonoidHom`. -/ @[to_additive "The coercion from `Finset` to `set` as an `AddMonoidHom`."] noncomputable def coeMonoidHom : Finset α →* Set α where toFun := CoeTC.coe map_one' := coe_one map_mul' := coe_mul #align finset.coe_monoid_hom Finset.coeMonoidHom #align finset.coe_add_monoid_hom Finset.coeAddMonoidHom @[to_additive (attr := simp)] theorem coe_coeMonoidHom : (coeMonoidHom : Finset α → Set α) = CoeTC.coe := rfl #align finset.coe_coe_monoid_hom Finset.coe_coeMonoidHom #align finset.coe_coe_add_monoid_hom Finset.coe_coeAddMonoidHom @[to_additive (attr := simp)] theorem coeMonoidHom_apply (s : Finset α) : coeMonoidHom s = s := rfl #align finset.coe_monoid_hom_apply Finset.coeMonoidHom_apply #align finset.coe_add_monoid_hom_apply Finset.coeAddMonoidHom_apply /-- Lift a `MonoidHom` to `Finset` via `image`. -/ @[to_additive (attr := simps) "Lift an `add_monoid_hom` to `Finset` via `image`"] def imageMonoidHom [MulOneClass β] [FunLike F α β] [MonoidHomClass F α β] (f : F) : Finset α →* Finset β := { imageMulHom f, imageOneHom f with } #align finset.image_monoid_hom Finset.imageMonoidHom #align finset.image_add_monoid_hom Finset.imageAddMonoidHom end MulOneClass section Monoid variable [Monoid α] {s t : Finset α} {a : α} {m n : ℕ} @[to_additive (attr := simp, norm_cast)] theorem coe_pow (s : Finset α) (n : ℕ) : ↑(s ^ n) = (s : Set α) ^ n := by change ↑(npowRec n s) = (s: Set α) ^ n induction' n with n ih · rw [npowRec, pow_zero, coe_one] · rw [npowRec, pow_succ, coe_mul, ih] #align finset.coe_pow Finset.coe_pow /-- `Finset α` is a `Monoid` under pointwise operations if `α` is. -/ @[to_additive "`Finset α` is an `AddMonoid` under pointwise operations if `α` is. "] protected def monoid : Monoid (Finset α) := coe_injective.monoid _ coe_one coe_mul coe_pow #align finset.monoid Finset.monoid #align finset.add_monoid Finset.addMonoid scoped[Pointwise] attribute [instance] Finset.monoid Finset.addMonoid @[to_additive] theorem pow_mem_pow (ha : a ∈ s) : ∀ n : ℕ, a ^ n ∈ s ^ n | 0 => by rw [pow_zero] exact one_mem_one | n + 1 => by rw [pow_succ] exact mul_mem_mul (pow_mem_pow ha n) ha #align finset.pow_mem_pow Finset.pow_mem_pow #align finset.nsmul_mem_nsmul Finset.nsmul_mem_nsmul @[to_additive] theorem pow_subset_pow (hst : s ⊆ t) : ∀ n : ℕ, s ^ n ⊆ t ^ n | 0 => by simp [pow_zero] | n + 1 => by rw [pow_succ] exact mul_subset_mul (pow_subset_pow hst n) hst #align finset.pow_subset_pow Finset.pow_subset_pow #align finset.nsmul_subset_nsmul Finset.nsmul_subset_nsmul @[to_additive] theorem pow_subset_pow_of_one_mem (hs : (1 : α) ∈ s) : m ≤ n → s ^ m ⊆ s ^ n := by apply Nat.le_induction · exact fun _ hn => hn · intro n _ hmn rw [pow_succ] exact hmn.trans (subset_mul_left (s ^ n) hs) #align finset.pow_subset_pow_of_one_mem Finset.pow_subset_pow_of_one_mem #align finset.nsmul_subset_nsmul_of_zero_mem Finset.nsmul_subset_nsmul_of_zero_mem @[to_additive (attr := simp, norm_cast)] theorem coe_list_prod (s : List (Finset α)) : (↑s.prod : Set α) = (s.map (↑)).prod := map_list_prod (coeMonoidHom : Finset α →* Set α) _ #align finset.coe_list_prod Finset.coe_list_prod #align finset.coe_list_sum Finset.coe_list_sum @[to_additive] theorem mem_prod_list_ofFn {a : α} {s : Fin n → Finset α} : a ∈ (List.ofFn s).prod ↔ ∃ f : ∀ i : Fin n, s i, (List.ofFn fun i => (f i : α)).prod = a := by rw [← mem_coe, coe_list_prod, List.map_ofFn, Set.mem_prod_list_ofFn] rfl #align finset.mem_prod_list_of_fn Finset.mem_prod_list_ofFn #align finset.mem_sum_list_of_fn Finset.mem_sum_list_ofFn @[to_additive] theorem mem_pow {a : α} {n : ℕ} : a ∈ s ^ n ↔ ∃ f : Fin n → s, (List.ofFn fun i => ↑(f i)).prod = a := by set_option tactic.skipAssignedInstances false in simp [← mem_coe, coe_pow, Set.mem_pow] #align finset.mem_pow Finset.mem_pow #align finset.mem_nsmul Finset.mem_nsmul @[to_additive (attr := simp)] theorem empty_pow (hn : n ≠ 0) : (∅ : Finset α) ^ n = ∅ := by rw [← tsub_add_cancel_of_le (Nat.succ_le_of_lt <| Nat.pos_of_ne_zero hn), pow_succ', empty_mul] #align finset.empty_pow Finset.empty_pow #align finset.empty_nsmul Finset.empty_nsmul @[to_additive] theorem mul_univ_of_one_mem [Fintype α] (hs : (1 : α) ∈ s) : s * univ = univ := eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, hs, _, mem_univ _, one_mul _⟩ #align finset.mul_univ_of_one_mem Finset.mul_univ_of_one_mem #align finset.add_univ_of_zero_mem Finset.add_univ_of_zero_mem @[to_additive] theorem univ_mul_of_one_mem [Fintype α] (ht : (1 : α) ∈ t) : univ * t = univ := eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, mem_univ _, _, ht, mul_one _⟩ #align finset.univ_mul_of_one_mem Finset.univ_mul_of_one_mem #align finset.univ_add_of_zero_mem Finset.univ_add_of_zero_mem @[to_additive (attr := simp)] theorem univ_mul_univ [Fintype α] : (univ : Finset α) * univ = univ := mul_univ_of_one_mem <| mem_univ _ #align finset.univ_mul_univ Finset.univ_mul_univ #align finset.univ_add_univ Finset.univ_add_univ @[to_additive (attr := simp) nsmul_univ] theorem univ_pow [Fintype α] (hn : n ≠ 0) : (univ : Finset α) ^ n = univ := coe_injective <| by rw [coe_pow, coe_univ, Set.univ_pow hn] #align finset.univ_pow Finset.univ_pow #align finset.nsmul_univ Finset.nsmul_univ @[to_additive] protected theorem _root_.IsUnit.finset : IsUnit a → IsUnit ({a} : Finset α) := IsUnit.map (singletonMonoidHom : α →* Finset α) #align is_unit.finset IsUnit.finset #align is_add_unit.finset IsAddUnit.finset end Monoid section CommMonoid variable [CommMonoid α] /-- `Finset α` is a `CommMonoid` under pointwise operations if `α` is. -/ @[to_additive "`Finset α` is an `AddCommMonoid` under pointwise operations if `α` is. "] protected def commMonoid : CommMonoid (Finset α) := coe_injective.commMonoid _ coe_one coe_mul coe_pow #align finset.comm_monoid Finset.commMonoid #align finset.add_comm_monoid Finset.addCommMonoid scoped[Pointwise] attribute [instance] Finset.commMonoid Finset.addCommMonoid @[to_additive (attr := simp, norm_cast)] theorem coe_prod {ι : Type*} (s : Finset ι) (f : ι → Finset α) : ↑(∏ i ∈ s, f i) = ∏ i ∈ s, (f i : Set α) := map_prod ((coeMonoidHom) : Finset α →* Set α) _ _ #align finset.coe_prod Finset.coe_prod #align finset.coe_sum Finset.coe_sum end CommMonoid open Pointwise section DivisionMonoid variable [DivisionMonoid α] {s t : Finset α} @[to_additive (attr := simp)] theorem coe_zpow (s : Finset α) : ∀ n : ℤ, ↑(s ^ n) = (s : Set α) ^ n | Int.ofNat n => coe_pow _ _ | Int.negSucc n => by refine (coe_inv _).trans ?_ exact congr_arg Inv.inv (coe_pow _ _) #align finset.coe_zpow Finset.coe_zpow #align finset.coe_zsmul Finset.coe_zsmul @[to_additive] protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = {a} ∧ t = {b} ∧ a * b = 1 := by simp_rw [← coe_inj, coe_mul, coe_one, Set.mul_eq_one_iff, coe_singleton] #align finset.mul_eq_one_iff Finset.mul_eq_one_iff #align finset.add_eq_zero_iff Finset.add_eq_zero_iff /-- `Finset α` is a division monoid under pointwise operations if `α` is. -/ @[to_additive subtractionMonoid "`Finset α` is a subtraction monoid under pointwise operations if `α` is."] protected def divisionMonoid : DivisionMonoid (Finset α) := coe_injective.divisionMonoid _ coe_one coe_mul coe_inv coe_div coe_pow coe_zpow #align finset.division_monoid Finset.divisionMonoid #align finset.subtraction_monoid Finset.subtractionMonoid scoped[Pointwise] attribute [instance] Finset.divisionMonoid Finset.subtractionMonoid @[to_additive (attr := simp)] theorem isUnit_iff : IsUnit s ↔ ∃ a, s = {a} ∧ IsUnit a := by constructor · rintro ⟨u, rfl⟩ obtain ⟨a, b, ha, hb, h⟩ := Finset.mul_eq_one_iff.1 u.mul_inv refine ⟨a, ha, ⟨a, b, h, singleton_injective ?_⟩, rfl⟩ rw [← singleton_mul_singleton, ← ha, ← hb] exact u.inv_mul · rintro ⟨a, rfl, ha⟩ exact ha.finset #align finset.is_unit_iff Finset.isUnit_iff #align finset.is_add_unit_iff Finset.isAddUnit_iff @[to_additive (attr := simp)] theorem isUnit_coe : IsUnit (s : Set α) ↔ IsUnit s := by simp_rw [isUnit_iff, Set.isUnit_iff, coe_eq_singleton] #align finset.is_unit_coe Finset.isUnit_coe #align finset.is_add_unit_coe Finset.isAddUnit_coe @[to_additive (attr := simp)] lemma univ_div_univ [Fintype α] : (univ / univ : Finset α) = univ := by simp [div_eq_mul_inv] end DivisionMonoid /-- `Finset α` is a commutative division monoid under pointwise operations if `α` is. -/ @[to_additive subtractionCommMonoid "`Finset α` is a commutative subtraction monoid under pointwise operations if `α` is."] protected def divisionCommMonoid [DivisionCommMonoid α] : DivisionCommMonoid (Finset α) := coe_injective.divisionCommMonoid _ coe_one coe_mul coe_inv coe_div coe_pow coe_zpow #align finset.division_comm_monoid Finset.divisionCommMonoid #align finset.subtraction_comm_monoid Finset.subtractionCommMonoid /-- `Finset α` has distributive negation if `α` has. -/ protected def distribNeg [Mul α] [HasDistribNeg α] : HasDistribNeg (Finset α) := coe_injective.hasDistribNeg _ coe_neg coe_mul #align finset.has_distrib_neg Finset.distribNeg scoped[Pointwise] attribute [instance] Finset.divisionCommMonoid Finset.subtractionCommMonoid Finset.distribNeg section Distrib variable [Distrib α] (s t u : Finset α) /-! Note that `Finset α` is not a `Distrib` because `s * t + s * u` has cross terms that `s * (t + u)` lacks. ```lean -- {10, 16, 18, 20, 8, 9} #eval {1, 2} * ({3, 4} + {5, 6} : Finset ℕ) -- {10, 11, 12, 13, 14, 15, 16, 18, 20, 8, 9} #eval ({1, 2} : Finset ℕ) * {3, 4} + {1, 2} * {5, 6} ``` -/ theorem mul_add_subset : s * (t + u) ⊆ s * t + s * u := image₂_distrib_subset_left mul_add #align finset.mul_add_subset Finset.mul_add_subset theorem add_mul_subset : (s + t) * u ⊆ s * u + t * u := image₂_distrib_subset_right add_mul #align finset.add_mul_subset Finset.add_mul_subset end Distrib section MulZeroClass variable [MulZeroClass α] {s t : Finset α} /-! Note that `Finset` is not a `MulZeroClass` because `0 * ∅ ≠ 0`. -/ theorem mul_zero_subset (s : Finset α) : s * 0 ⊆ 0 := by simp [subset_iff, mem_mul] #align finset.mul_zero_subset Finset.mul_zero_subset theorem zero_mul_subset (s : Finset α) : 0 * s ⊆ 0 := by simp [subset_iff, mem_mul] #align finset.zero_mul_subset Finset.zero_mul_subset theorem Nonempty.mul_zero (hs : s.Nonempty) : s * 0 = 0 := s.mul_zero_subset.antisymm <| by simpa [mem_mul] using hs #align finset.nonempty.mul_zero Finset.Nonempty.mul_zero theorem Nonempty.zero_mul (hs : s.Nonempty) : 0 * s = 0 := s.zero_mul_subset.antisymm <| by simpa [mem_mul] using hs #align finset.nonempty.zero_mul Finset.Nonempty.zero_mul end MulZeroClass section Group variable [Group α] [DivisionMonoid β] [FunLike F α β] [MonoidHomClass F α β] variable (f : F) {s t : Finset α} {a b : α} /-! Note that `Finset` is not a `Group` because `s / s ≠ 1` in general. -/ @[to_additive (attr := simp)] theorem one_mem_div_iff : (1 : α) ∈ s / t ↔ ¬Disjoint s t := by rw [← mem_coe, ← disjoint_coe, coe_div, Set.one_mem_div_iff] #align finset.one_mem_div_iff Finset.one_mem_div_iff #align finset.zero_mem_sub_iff Finset.zero_mem_sub_iff @[to_additive] theorem not_one_mem_div_iff : (1 : α) ∉ s / t ↔ Disjoint s t := one_mem_div_iff.not_left #align finset.not_one_mem_div_iff Finset.not_one_mem_div_iff #align finset.not_zero_mem_sub_iff Finset.not_zero_mem_sub_iff @[to_additive] theorem Nonempty.one_mem_div (h : s.Nonempty) : (1 : α) ∈ s / s := let ⟨a, ha⟩ := h mem_div.2 ⟨a, ha, a, ha, div_self' _⟩ #align finset.nonempty.one_mem_div Finset.Nonempty.one_mem_div #align finset.nonempty.zero_mem_sub Finset.Nonempty.zero_mem_sub @[to_additive] theorem isUnit_singleton (a : α) : IsUnit ({a} : Finset α) := (Group.isUnit a).finset #align finset.is_unit_singleton Finset.isUnit_singleton #align finset.is_add_unit_singleton Finset.isAddUnit_singleton /- Porting note: not in simp nf; Added non-simpable part as `isUnit_iff_singleton_aux` below Left-hand side simplifies from IsUnit s to ∃ a, s = {a} ∧ IsUnit a -/ -- @[simp] theorem isUnit_iff_singleton : IsUnit s ↔ ∃ a, s = {a} := by simp only [isUnit_iff, Group.isUnit, and_true_iff] #align finset.is_unit_iff_singleton Finset.isUnit_iff_singleton @[simp] theorem isUnit_iff_singleton_aux : (∃ a, s = {a} ∧ IsUnit a) ↔ ∃ a, s = {a} := by simp only [Group.isUnit, and_true_iff] @[to_additive (attr := simp)] theorem image_mul_left : image (fun b => a * b) t = preimage t (fun b => a⁻¹ * b) (mul_right_injective _).injOn := coe_injective <| by simp #align finset.image_mul_left Finset.image_mul_left #align finset.image_add_left Finset.image_add_left @[to_additive (attr := simp)] theorem image_mul_right : image (· * b) t = preimage t (· * b⁻¹) (mul_left_injective _).injOn := coe_injective <| by simp #align finset.image_mul_right Finset.image_mul_right #align finset.image_add_right Finset.image_add_right @[to_additive] theorem image_mul_left' : image (fun b => a⁻¹ * b) t = preimage t (fun b => a * b) (mul_right_injective _).injOn := by simp #align finset.image_mul_left' Finset.image_mul_left' #align finset.image_add_left' Finset.image_add_left' @[to_additive] theorem image_mul_right' : image (· * b⁻¹) t = preimage t (· * b) (mul_left_injective _).injOn := by simp #align finset.image_mul_right' Finset.image_mul_right' #align finset.image_add_right' Finset.image_add_right' theorem image_div : (s / t).image (f : α → β) = s.image f / t.image f := image_image₂_distrib <| map_div f #align finset.image_div Finset.image_div end Group section GroupWithZero variable [GroupWithZero α] {s t : Finset α} theorem div_zero_subset (s : Finset α) : s / 0 ⊆ 0 := by simp [subset_iff, mem_div] #align finset.div_zero_subset Finset.div_zero_subset theorem zero_div_subset (s : Finset α) : 0 / s ⊆ 0 := by simp [subset_iff, mem_div] #align finset.zero_div_subset Finset.zero_div_subset theorem Nonempty.div_zero (hs : s.Nonempty) : s / 0 = 0 := s.div_zero_subset.antisymm <| by simpa [mem_div] using hs #align finset.nonempty.div_zero Finset.Nonempty.div_zero theorem Nonempty.zero_div (hs : s.Nonempty) : 0 / s = 0 := s.zero_div_subset.antisymm <| by simpa [mem_div] using hs #align finset.nonempty.zero_div Finset.Nonempty.zero_div end GroupWithZero end Instances section Group variable [Group α] {s t : Finset α} {a b : α} @[to_additive (attr := simp)] theorem preimage_mul_left_singleton : preimage {b} (a * ·) (mul_right_injective _).injOn = {a⁻¹ * b} := by classical rw [← image_mul_left', image_singleton] #align finset.preimage_mul_left_singleton Finset.preimage_mul_left_singleton #align finset.preimage_add_left_singleton Finset.preimage_add_left_singleton @[to_additive (attr := simp)] theorem preimage_mul_right_singleton : preimage {b} (· * a) (mul_left_injective _).injOn = {b * a⁻¹} := by classical rw [← image_mul_right', image_singleton] #align finset.preimage_mul_right_singleton Finset.preimage_mul_right_singleton #align finset.preimage_add_right_singleton Finset.preimage_add_right_singleton @[to_additive (attr := simp)] theorem preimage_mul_left_one : preimage 1 (a * ·) (mul_right_injective _).injOn = {a⁻¹} := by classical rw [← image_mul_left', image_one, mul_one] #align finset.preimage_mul_left_one Finset.preimage_mul_left_one #align finset.preimage_add_left_zero Finset.preimage_add_left_zero @[to_additive (attr := simp)] theorem preimage_mul_right_one : preimage 1 (· * b) (mul_left_injective _).injOn = {b⁻¹} := by classical rw [← image_mul_right', image_one, one_mul] #align finset.preimage_mul_right_one Finset.preimage_mul_right_one #align finset.preimage_add_right_zero Finset.preimage_add_right_zero @[to_additive] theorem preimage_mul_left_one' : preimage 1 (a⁻¹ * ·) (mul_right_injective _).injOn = {a} := by rw [preimage_mul_left_one, inv_inv] #align finset.preimage_mul_left_one' Finset.preimage_mul_left_one' #align finset.preimage_add_left_zero' Finset.preimage_add_left_zero' @[to_additive] theorem preimage_mul_right_one' : preimage 1 (· * b⁻¹) (mul_left_injective _).injOn = {b} := by rw [preimage_mul_right_one, inv_inv] #align finset.preimage_mul_right_one' Finset.preimage_mul_right_one' #align finset.preimage_add_right_zero' Finset.preimage_add_right_zero' end Group /-! ### Scalar addition/multiplication of finsets -/ section SMul variable [DecidableEq β] [SMul α β] {s s₁ s₂ : Finset α} {t t₁ t₂ u : Finset β} {a : α} {b : β} /-- The pointwise product of two finsets `s` and `t`: `s • t = {x • y | x ∈ s, y ∈ t}`. -/ @[to_additive "The pointwise sum of two finsets `s` and `t`: `s +ᵥ t = {x +ᵥ y | x ∈ s, y ∈ t}`."] protected def smul : SMul (Finset α) (Finset β) := ⟨image₂ (· • ·)⟩ #align finset.has_smul Finset.smul #align finset.has_vadd Finset.vadd scoped[Pointwise] attribute [instance] Finset.smul Finset.vadd @[to_additive] theorem smul_def : s • t = (s ×ˢ t).image fun p : α × β => p.1 • p.2 := rfl #align finset.smul_def Finset.smul_def #align finset.vadd_def Finset.vadd_def @[to_additive] theorem image_smul_product : ((s ×ˢ t).image fun x : α × β => x.fst • x.snd) = s • t := rfl #align finset.image_smul_product Finset.image_smul_product #align finset.image_vadd_product Finset.image_vadd_product @[to_additive] theorem mem_smul {x : β} : x ∈ s • t ↔ ∃ y ∈ s, ∃ z ∈ t, y • z = x := mem_image₂ #align finset.mem_smul Finset.mem_smul #align finset.mem_vadd Finset.mem_vadd @[to_additive (attr := simp, norm_cast)] theorem coe_smul (s : Finset α) (t : Finset β) : ↑(s • t) = (s : Set α) • (t : Set β) := coe_image₂ _ _ _ #align finset.coe_smul Finset.coe_smul #align finset.coe_vadd Finset.coe_vadd @[to_additive] theorem smul_mem_smul : a ∈ s → b ∈ t → a • b ∈ s • t := mem_image₂_of_mem #align finset.smul_mem_smul Finset.smul_mem_smul #align finset.vadd_mem_vadd Finset.vadd_mem_vadd @[to_additive] theorem smul_card_le : (s • t).card ≤ s.card • t.card := card_image₂_le _ _ _ #align finset.smul_card_le Finset.smul_card_le #align finset.vadd_card_le Finset.vadd_card_le @[to_additive (attr := simp)] theorem empty_smul (t : Finset β) : (∅ : Finset α) • t = ∅ := image₂_empty_left #align finset.empty_smul Finset.empty_smul #align finset.empty_vadd Finset.empty_vadd @[to_additive (attr := simp)] theorem smul_empty (s : Finset α) : s • (∅ : Finset β) = ∅ := image₂_empty_right #align finset.smul_empty Finset.smul_empty #align finset.vadd_empty Finset.vadd_empty @[to_additive (attr := simp)] theorem smul_eq_empty : s • t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff #align finset.smul_eq_empty Finset.smul_eq_empty #align finset.vadd_eq_empty Finset.vadd_eq_empty @[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))] theorem smul_nonempty_iff : (s • t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff #align finset.smul_nonempty_iff Finset.smul_nonempty_iff #align finset.vadd_nonempty_iff Finset.vadd_nonempty_iff @[to_additive] theorem Nonempty.smul : s.Nonempty → t.Nonempty → (s • t).Nonempty := Nonempty.image₂ #align finset.nonempty.smul Finset.Nonempty.smul #align finset.nonempty.vadd Finset.Nonempty.vadd @[to_additive] theorem Nonempty.of_smul_left : (s • t).Nonempty → s.Nonempty := Nonempty.of_image₂_left #align finset.nonempty.of_smul_left Finset.Nonempty.of_smul_left #align finset.nonempty.of_vadd_left Finset.Nonempty.of_vadd_left @[to_additive] theorem Nonempty.of_smul_right : (s • t).Nonempty → t.Nonempty := Nonempty.of_image₂_right #align finset.nonempty.of_smul_right Finset.Nonempty.of_smul_right #align finset.nonempty.of_vadd_right Finset.Nonempty.of_vadd_right @[to_additive] theorem smul_singleton (b : β) : s • ({b} : Finset β) = s.image (· • b) := image₂_singleton_right #align finset.smul_singleton Finset.smul_singleton #align finset.vadd_singleton Finset.vadd_singleton @[to_additive] theorem singleton_smul_singleton (a : α) (b : β) : ({a} : Finset α) • ({b} : Finset β) = {a • b} := image₂_singleton #align finset.singleton_smul_singleton Finset.singleton_smul_singleton #align finset.singleton_vadd_singleton Finset.singleton_vadd_singleton @[to_additive (attr := mono)] theorem smul_subset_smul : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ • t₁ ⊆ s₂ • t₂ := image₂_subset #align finset.smul_subset_smul Finset.smul_subset_smul #align finset.vadd_subset_vadd Finset.vadd_subset_vadd @[to_additive] theorem smul_subset_smul_left : t₁ ⊆ t₂ → s • t₁ ⊆ s • t₂ := image₂_subset_left #align finset.smul_subset_smul_left Finset.smul_subset_smul_left #align finset.vadd_subset_vadd_left Finset.vadd_subset_vadd_left @[to_additive] theorem smul_subset_smul_right : s₁ ⊆ s₂ → s₁ • t ⊆ s₂ • t := image₂_subset_right #align finset.smul_subset_smul_right Finset.smul_subset_smul_right #align finset.vadd_subset_vadd_right Finset.vadd_subset_vadd_right @[to_additive] theorem smul_subset_iff : s • t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a • b ∈ u := image₂_subset_iff #align finset.smul_subset_iff Finset.smul_subset_iff #align finset.vadd_subset_iff Finset.vadd_subset_iff @[to_additive] theorem union_smul [DecidableEq α] : (s₁ ∪ s₂) • t = s₁ • t ∪ s₂ • t := image₂_union_left #align finset.union_smul Finset.union_smul #align finset.union_vadd Finset.union_vadd @[to_additive] theorem smul_union : s • (t₁ ∪ t₂) = s • t₁ ∪ s • t₂ := image₂_union_right #align finset.smul_union Finset.smul_union #align finset.vadd_union Finset.vadd_union @[to_additive] theorem inter_smul_subset [DecidableEq α] : (s₁ ∩ s₂) • t ⊆ s₁ • t ∩ s₂ • t := image₂_inter_subset_left #align finset.inter_smul_subset Finset.inter_smul_subset #align finset.inter_vadd_subset Finset.inter_vadd_subset @[to_additive] theorem smul_inter_subset : s • (t₁ ∩ t₂) ⊆ s • t₁ ∩ s • t₂ := image₂_inter_subset_right #align finset.smul_inter_subset Finset.smul_inter_subset #align finset.vadd_inter_subset Finset.vadd_inter_subset @[to_additive] theorem inter_smul_union_subset_union [DecidableEq α] : (s₁ ∩ s₂) • (t₁ ∪ t₂) ⊆ s₁ • t₁ ∪ s₂ • t₂ := image₂_inter_union_subset_union #align finset.inter_smul_union_subset_union Finset.inter_smul_union_subset_union #align finset.inter_vadd_union_subset_union Finset.inter_vadd_union_subset_union @[to_additive] theorem union_smul_inter_subset_union [DecidableEq α] : (s₁ ∪ s₂) • (t₁ ∩ t₂) ⊆ s₁ • t₁ ∪ s₂ • t₂ := image₂_union_inter_subset_union #align finset.union_smul_inter_subset_union Finset.union_smul_inter_subset_union #align finset.union_vadd_inter_subset_union Finset.union_vadd_inter_subset_union /-- If a finset `u` is contained in the scalar product of two sets `s • t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' • t'`. -/ @[to_additive "If a finset `u` is contained in the scalar sum of two sets `s +ᵥ t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' +ᵥ t'`."] theorem subset_smul {s : Set α} {t : Set β} : ↑u ⊆ s • t → ∃ (s' : Finset α) (t' : Finset β), ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' • t' := subset_image₂ #align finset.subset_smul Finset.subset_smul #align finset.subset_vadd Finset.subset_vadd end SMul /-! ### Scalar subtraction of finsets -/ section VSub -- Porting note: Reordered [VSub α β] and [DecidableEq α] to make vsub less dangerous. Bad? variable [VSub α β] [DecidableEq α] {s s₁ s₂ t t₁ t₂ : Finset β} {u : Finset α} {a : α} {b c : β} /-- The pointwise subtraction of two finsets `s` and `t`: `s -ᵥ t = {x -ᵥ y | x ∈ s, y ∈ t}`. -/ protected def vsub : VSub (Finset α) (Finset β) := ⟨image₂ (· -ᵥ ·)⟩ #align finset.has_vsub Finset.vsub scoped[Pointwise] attribute [instance] Finset.vsub theorem vsub_def : s -ᵥ t = image₂ (· -ᵥ ·) s t := rfl #align finset.vsub_def Finset.vsub_def @[simp] theorem image_vsub_product : image₂ (· -ᵥ ·) s t = s -ᵥ t := rfl #align finset.image_vsub_product Finset.image_vsub_product theorem mem_vsub : a ∈ s -ᵥ t ↔ ∃ b ∈ s, ∃ c ∈ t, b -ᵥ c = a := mem_image₂ #align finset.mem_vsub Finset.mem_vsub @[simp, norm_cast] theorem coe_vsub (s t : Finset β) : (↑(s -ᵥ t) : Set α) = (s : Set β) -ᵥ t := coe_image₂ _ _ _ #align finset.coe_vsub Finset.coe_vsub theorem vsub_mem_vsub : b ∈ s → c ∈ t → b -ᵥ c ∈ s -ᵥ t := mem_image₂_of_mem #align finset.vsub_mem_vsub Finset.vsub_mem_vsub theorem vsub_card_le : (s -ᵥ t : Finset α).card ≤ s.card * t.card := card_image₂_le _ _ _ #align finset.vsub_card_le Finset.vsub_card_le @[simp] theorem empty_vsub (t : Finset β) : (∅ : Finset β) -ᵥ t = ∅ := image₂_empty_left #align finset.empty_vsub Finset.empty_vsub @[simp] theorem vsub_empty (s : Finset β) : s -ᵥ (∅ : Finset β) = ∅ := image₂_empty_right #align finset.vsub_empty Finset.vsub_empty @[simp] theorem vsub_eq_empty : s -ᵥ t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff #align finset.vsub_eq_empty Finset.vsub_eq_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem vsub_nonempty : (s -ᵥ t : Finset α).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff #align finset.vsub_nonempty Finset.vsub_nonempty theorem Nonempty.vsub : s.Nonempty → t.Nonempty → (s -ᵥ t : Finset α).Nonempty := Nonempty.image₂ #align finset.nonempty.vsub Finset.Nonempty.vsub theorem Nonempty.of_vsub_left : (s -ᵥ t : Finset α).Nonempty → s.Nonempty := Nonempty.of_image₂_left #align finset.nonempty.of_vsub_left Finset.Nonempty.of_vsub_left theorem Nonempty.of_vsub_right : (s -ᵥ t : Finset α).Nonempty → t.Nonempty := Nonempty.of_image₂_right #align finset.nonempty.of_vsub_right Finset.Nonempty.of_vsub_right @[simp] theorem vsub_singleton (b : β) : s -ᵥ ({b} : Finset β) = s.image (· -ᵥ b) := image₂_singleton_right #align finset.vsub_singleton Finset.vsub_singleton theorem singleton_vsub (a : β) : ({a} : Finset β) -ᵥ t = t.image (a -ᵥ ·) := image₂_singleton_left #align finset.singleton_vsub Finset.singleton_vsub -- @[simp] -- Porting note (#10618): simp can prove this theorem singleton_vsub_singleton (a b : β) : ({a} : Finset β) -ᵥ {b} = {a -ᵥ b} := image₂_singleton #align finset.singleton_vsub_singleton Finset.singleton_vsub_singleton @[mono] theorem vsub_subset_vsub : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ -ᵥ t₁ ⊆ s₂ -ᵥ t₂ := image₂_subset #align finset.vsub_subset_vsub Finset.vsub_subset_vsub theorem vsub_subset_vsub_left : t₁ ⊆ t₂ → s -ᵥ t₁ ⊆ s -ᵥ t₂ := image₂_subset_left #align finset.vsub_subset_vsub_left Finset.vsub_subset_vsub_left theorem vsub_subset_vsub_right : s₁ ⊆ s₂ → s₁ -ᵥ t ⊆ s₂ -ᵥ t := image₂_subset_right #align finset.vsub_subset_vsub_right Finset.vsub_subset_vsub_right theorem vsub_subset_iff : s -ᵥ t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x -ᵥ y ∈ u := image₂_subset_iff #align finset.vsub_subset_iff Finset.vsub_subset_iff section variable [DecidableEq β] theorem union_vsub : s₁ ∪ s₂ -ᵥ t = s₁ -ᵥ t ∪ (s₂ -ᵥ t) := image₂_union_left #align finset.union_vsub Finset.union_vsub theorem vsub_union : s -ᵥ (t₁ ∪ t₂) = s -ᵥ t₁ ∪ (s -ᵥ t₂) := image₂_union_right #align finset.vsub_union Finset.vsub_union theorem inter_vsub_subset : s₁ ∩ s₂ -ᵥ t ⊆ (s₁ -ᵥ t) ∩ (s₂ -ᵥ t) := image₂_inter_subset_left #align finset.inter_vsub_subset Finset.inter_vsub_subset theorem vsub_inter_subset : s -ᵥ t₁ ∩ t₂ ⊆ (s -ᵥ t₁) ∩ (s -ᵥ t₂) := image₂_inter_subset_right #align finset.vsub_inter_subset Finset.vsub_inter_subset end /-- If a finset `u` is contained in the pointwise subtraction of two sets `s -ᵥ t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' -ᵥ t'`. -/ theorem subset_vsub {s t : Set β} : ↑u ⊆ s -ᵥ t → ∃ s' t' : Finset β, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' -ᵥ t' := subset_image₂ #align finset.subset_vsub Finset.subset_vsub end VSub open Pointwise /-! ### Translation/scaling of finsets -/ section SMul variable [DecidableEq β] [SMul α β] {s s₁ s₂ t u : Finset β} {a : α} {b : β} /-- The scaling of a finset `s` by a scalar `a`: `a • s = {a • x | x ∈ s}`. -/ @[to_additive "The translation of a finset `s` by a vector `a`: `a +ᵥ s = {a +ᵥ x | x ∈ s}`."] protected def smulFinset : SMul α (Finset β) := ⟨fun a => image <| (a • ·)⟩ #align finset.has_smul_finset Finset.smulFinset #align finset.has_vadd_finset Finset.vaddFinset scoped[Pointwise] attribute [instance] Finset.smulFinset Finset.vaddFinset @[to_additive] theorem smul_finset_def : a • s = s.image (a • ·) := rfl #align finset.smul_finset_def Finset.smul_finset_def #align finset.vadd_finset_def Finset.vadd_finset_def @[to_additive] theorem image_smul : (s.image fun x => a • x) = a • s := rfl #align finset.image_smul Finset.image_smul #align finset.image_vadd Finset.image_vadd @[to_additive] theorem mem_smul_finset {x : β} : x ∈ a • s ↔ ∃ y, y ∈ s ∧ a • y = x := by simp only [Finset.smul_finset_def, and_assoc, mem_image, exists_prop, Prod.exists, mem_product] #align finset.mem_smul_finset Finset.mem_smul_finset #align finset.mem_vadd_finset Finset.mem_vadd_finset @[to_additive (attr := simp, norm_cast)] theorem coe_smul_finset (a : α) (s : Finset β) : ↑(a • s) = a • (↑s : Set β) := coe_image #align finset.coe_smul_finset Finset.coe_smul_finset #align finset.coe_vadd_finset Finset.coe_vadd_finset @[to_additive] theorem smul_mem_smul_finset : b ∈ s → a • b ∈ a • s := mem_image_of_mem _ #align finset.smul_mem_smul_finset Finset.smul_mem_smul_finset #align finset.vadd_mem_vadd_finset Finset.vadd_mem_vadd_finset @[to_additive] theorem smul_finset_card_le : (a • s).card ≤ s.card := card_image_le #align finset.smul_finset_card_le Finset.smul_finset_card_le #align finset.vadd_finset_card_le Finset.vadd_finset_card_le @[to_additive (attr := simp)] theorem smul_finset_empty (a : α) : a • (∅ : Finset β) = ∅ := image_empty _ #align finset.smul_finset_empty Finset.smul_finset_empty #align finset.vadd_finset_empty Finset.vadd_finset_empty @[to_additive (attr := simp)] theorem smul_finset_eq_empty : a • s = ∅ ↔ s = ∅ := image_eq_empty #align finset.smul_finset_eq_empty Finset.smul_finset_eq_empty #align finset.vadd_finset_eq_empty Finset.vadd_finset_eq_empty @[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))] theorem smul_finset_nonempty : (a • s).Nonempty ↔ s.Nonempty := image_nonempty #align finset.smul_finset_nonempty Finset.smul_finset_nonempty #align finset.vadd_finset_nonempty Finset.vadd_finset_nonempty @[to_additive] theorem Nonempty.smul_finset (hs : s.Nonempty) : (a • s).Nonempty := hs.image _ #align finset.nonempty.smul_finset Finset.Nonempty.smul_finset #align finset.nonempty.vadd_finset Finset.Nonempty.vadd_finset @[to_additive (attr := simp)] theorem singleton_smul (a : α) : ({a} : Finset α) • t = a • t := image₂_singleton_left #align finset.singleton_smul Finset.singleton_smul #align finset.singleton_vadd Finset.singleton_vadd @[to_additive (attr := mono)] theorem smul_finset_subset_smul_finset : s ⊆ t → a • s ⊆ a • t := image_subset_image #align finset.smul_finset_subset_smul_finset Finset.smul_finset_subset_smul_finset #align finset.vadd_finset_subset_vadd_finset Finset.vadd_finset_subset_vadd_finset @[to_additive (attr := simp)] theorem smul_finset_singleton (b : β) : a • ({b} : Finset β) = {a • b} := image_singleton _ _ #align finset.smul_finset_singleton Finset.smul_finset_singleton #align finset.vadd_finset_singleton Finset.vadd_finset_singleton @[to_additive] theorem smul_finset_union : a • (s₁ ∪ s₂) = a • s₁ ∪ a • s₂ := image_union _ _ #align finset.smul_finset_union Finset.smul_finset_union #align finset.vadd_finset_union Finset.vadd_finset_union @[to_additive] theorem smul_finset_inter_subset : a • (s₁ ∩ s₂) ⊆ a • s₁ ∩ a • s₂ := image_inter_subset _ _ _ #align finset.smul_finset_inter_subset Finset.smul_finset_inter_subset #align finset.vadd_finset_inter_subset Finset.vadd_finset_inter_subset @[to_additive] theorem smul_finset_subset_smul {s : Finset α} : a ∈ s → a • t ⊆ s • t := image_subset_image₂_right #align finset.smul_finset_subset_smul Finset.smul_finset_subset_smul #align finset.vadd_finset_subset_vadd Finset.vadd_finset_subset_vadd @[to_additive (attr := simp)] theorem biUnion_smul_finset (s : Finset α) (t : Finset β) : s.biUnion (· • t) = s • t := biUnion_image_left #align finset.bUnion_smul_finset Finset.biUnion_smul_finset #align finset.bUnion_vadd_finset Finset.biUnion_vadd_finset end SMul open Pointwise section Instances variable [DecidableEq γ] @[to_additive] instance smulCommClass_finset [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass α β (Finset γ) := ⟨fun _ _ => Commute.finset_image <| smul_comm _ _⟩ #align finset.smul_comm_class_finset Finset.smulCommClass_finset #align finset.vadd_comm_class_finset Finset.vaddCommClass_finset @[to_additive] instance smulCommClass_finset' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass α (Finset β) (Finset γ) := ⟨fun a s t => coe_injective <| by simp only [coe_smul_finset, coe_smul, smul_comm]⟩ #align finset.smul_comm_class_finset' Finset.smulCommClass_finset' #align finset.vadd_comm_class_finset' Finset.vaddCommClass_finset' @[to_additive] instance smulCommClass_finset'' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass (Finset α) β (Finset γ) := haveI := SMulCommClass.symm α β γ SMulCommClass.symm _ _ _ #align finset.smul_comm_class_finset'' Finset.smulCommClass_finset'' #align finset.vadd_comm_class_finset'' Finset.vaddCommClass_finset'' @[to_additive] instance smulCommClass [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass (Finset α) (Finset β) (Finset γ) := ⟨fun s t u => coe_injective <| by simp_rw [coe_smul, smul_comm]⟩ #align finset.smul_comm_class Finset.smulCommClass #align finset.vadd_comm_class Finset.vaddCommClass @[to_additive vaddAssocClass] instance isScalarTower [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] : IsScalarTower α β (Finset γ) := ⟨fun a b s => by simp only [← image_smul, image_image, smul_assoc, Function.comp]⟩ #align finset.is_scalar_tower Finset.isScalarTower #align finset.vadd_assoc_class Finset.vaddAssocClass variable [DecidableEq β] @[to_additive vaddAssocClass'] instance isScalarTower' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] : IsScalarTower α (Finset β) (Finset γ) := ⟨fun a s t => coe_injective <| by simp only [coe_smul_finset, coe_smul, smul_assoc]⟩ #align finset.is_scalar_tower' Finset.isScalarTower' #align finset.vadd_assoc_class' Finset.vaddAssocClass' @[to_additive vaddAssocClass''] instance isScalarTower'' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] : IsScalarTower (Finset α) (Finset β) (Finset γ) := ⟨fun a s t => coe_injective <| by simp only [coe_smul_finset, coe_smul, smul_assoc]⟩ #align finset.is_scalar_tower'' Finset.isScalarTower'' #align finset.vadd_assoc_class'' Finset.vaddAssocClass'' @[to_additive] instance isCentralScalar [SMul α β] [SMul αᵐᵒᵖ β] [IsCentralScalar α β] : IsCentralScalar α (Finset β) := ⟨fun a s => coe_injective <| by simp only [coe_smul_finset, coe_smul, op_smul_eq_smul]⟩ #align finset.is_central_scalar Finset.isCentralScalar #align finset.is_central_vadd Finset.isCentralVAdd /-- A multiplicative action of a monoid `α` on a type `β` gives a multiplicative action of `Finset α` on `Finset β`. -/ @[to_additive "An additive action of an additive monoid `α` on a type `β` gives an additive action of `Finset α` on `Finset β`"] protected def mulAction [DecidableEq α] [Monoid α] [MulAction α β] : MulAction (Finset α) (Finset β) where mul_smul _ _ _ := image₂_assoc mul_smul one_smul s := image₂_singleton_left.trans <| by simp_rw [one_smul, image_id'] #align finset.mul_action Finset.mulAction #align finset.add_action Finset.addAction /-- A multiplicative action of a monoid on a type `β` gives a multiplicative action on `Finset β`. -/ @[to_additive "An additive action of an additive monoid on a type `β` gives an additive action on `Finset β`."] protected def mulActionFinset [Monoid α] [MulAction α β] : MulAction α (Finset β) := coe_injective.mulAction _ coe_smul_finset #align finset.mul_action_finset Finset.mulActionFinset #align finset.add_action_finset Finset.addActionFinset scoped[Pointwise] attribute [instance] Finset.mulActionFinset Finset.addActionFinset Finset.mulAction Finset.addAction /-- If scalar multiplication by elements of `α` sends `(0 : β)` to zero, then the same is true for `(0 : Finset β)`. -/ protected def smulZeroClassFinset [Zero β] [SMulZeroClass α β] : SMulZeroClass α (Finset β) := coe_injective.smulZeroClass ⟨(↑), coe_zero⟩ coe_smul_finset scoped[Pointwise] attribute [instance] Finset.smulZeroClassFinset /-- If the scalar multiplication `(· • ·) : α → β → β` is distributive, then so is `(· • ·) : α → Finset β → Finset β`. -/ protected def distribSMulFinset [AddZeroClass β] [DistribSMul α β] : DistribSMul α (Finset β) := coe_injective.distribSMul coeAddMonoidHom coe_smul_finset scoped[Pointwise] attribute [instance] Finset.distribSMulFinset /-- A distributive multiplicative action of a monoid on an additive monoid `β` gives a distributive multiplicative action on `Finset β`. -/ protected def distribMulActionFinset [Monoid α] [AddMonoid β] [DistribMulAction α β] : DistribMulAction α (Finset β) := Function.Injective.distribMulAction coeAddMonoidHom coe_injective coe_smul_finset #align finset.distrib_mul_action_finset Finset.distribMulActionFinset /-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `Set β`. -/ protected def mulDistribMulActionFinset [Monoid α] [Monoid β] [MulDistribMulAction α β] : MulDistribMulAction α (Finset β) := Function.Injective.mulDistribMulAction coeMonoidHom coe_injective coe_smul_finset #align finset.mul_distrib_mul_action_finset Finset.mulDistribMulActionFinset scoped[Pointwise] attribute [instance] Finset.distribMulActionFinset Finset.mulDistribMulActionFinset instance [DecidableEq α] [Zero α] [Mul α] [NoZeroDivisors α] : NoZeroDivisors (Finset α) := Function.Injective.noZeroDivisors (↑) coe_injective coe_zero coe_mul instance noZeroSMulDivisors [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] : NoZeroSMulDivisors (Finset α) (Finset β) where eq_zero_or_eq_zero_of_smul_eq_zero {s t} := by exact_mod_cast eq_zero_or_eq_zero_of_smul_eq_zero (c := s.toSet) (x := t.toSet) instance noZeroSMulDivisors_finset [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] : NoZeroSMulDivisors α (Finset β) := Function.Injective.noZeroSMulDivisors (↑) coe_injective coe_zero coe_smul_finset #align finset.no_zero_smul_divisors_finset Finset.noZeroSMulDivisors_finset end Instances section SMul variable [DecidableEq β] [DecidableEq γ] [SMul αᵐᵒᵖ β] [SMul β γ] [SMul α γ] -- TODO: replace hypothesis and conclusion with a typeclass @[to_additive] theorem op_smul_finset_smul_eq_smul_smul_finset (a : α) (s : Finset β) (t : Finset γ) (h : ∀ (a : α) (b : β) (c : γ), (op a • b) • c = b • a • c) : (op a • s) • t = s • a • t := by ext simp [mem_smul, mem_smul_finset, h] #align finset.op_smul_finset_smul_eq_smul_smul_finset Finset.op_smul_finset_smul_eq_smul_smul_finset #align finset.op_vadd_finset_vadd_eq_vadd_vadd_finset Finset.op_vadd_finset_vadd_eq_vadd_vadd_finset end SMul section Mul variable [Mul α] [DecidableEq α] {s t u : Finset α} {a : α} @[to_additive] theorem op_smul_finset_subset_mul : a ∈ t → op a • s ⊆ s * t := image_subset_image₂_left #align finset.op_smul_finset_subset_mul Finset.op_smul_finset_subset_mul #align finset.op_vadd_finset_subset_add Finset.op_vadd_finset_subset_add @[to_additive (attr := simp)] theorem biUnion_op_smul_finset (s t : Finset α) : (t.biUnion fun a => op a • s) = s * t := biUnion_image_right #align finset.bUnion_op_smul_finset Finset.biUnion_op_smul_finset #align finset.bUnion_op_vadd_finset Finset.biUnion_op_vadd_finset @[to_additive] theorem mul_subset_iff_left : s * t ⊆ u ↔ ∀ a ∈ s, a • t ⊆ u := image₂_subset_iff_left #align finset.mul_subset_iff_left Finset.mul_subset_iff_left #align finset.add_subset_iff_left Finset.add_subset_iff_left @[to_additive] theorem mul_subset_iff_right : s * t ⊆ u ↔ ∀ b ∈ t, op b • s ⊆ u := image₂_subset_iff_right #align finset.mul_subset_iff_right Finset.mul_subset_iff_right #align finset.add_subset_iff_right Finset.add_subset_iff_right end Mul section Semigroup variable [Semigroup α] [DecidableEq α] @[to_additive] theorem op_smul_finset_mul_eq_mul_smul_finset (a : α) (s : Finset α) (t : Finset α) : op a • s * t = s * a • t := op_smul_finset_smul_eq_smul_smul_finset _ _ _ fun _ _ _ => mul_assoc _ _ _ #align finset.op_smul_finset_mul_eq_mul_smul_finset Finset.op_smul_finset_mul_eq_mul_smul_finset #align finset.op_vadd_finset_add_eq_add_vadd_finset Finset.op_vadd_finset_add_eq_add_vadd_finset end Semigroup section IsLeftCancelMul variable [Mul α] [IsLeftCancelMul α] [DecidableEq α] (s t : Finset α) (a : α) @[to_additive] theorem pairwiseDisjoint_smul_iff {s : Set α} {t : Finset α} : s.PairwiseDisjoint (· • t) ↔ (s ×ˢ t : Set (α × α)).InjOn fun p => p.1 * p.2 := by simp_rw [← pairwiseDisjoint_coe, coe_smul_finset, Set.pairwiseDisjoint_smul_iff] #align finset.pairwise_disjoint_smul_iff Finset.pairwiseDisjoint_smul_iff #align finset.pairwise_disjoint_vadd_iff Finset.pairwiseDisjoint_vadd_iff @[to_additive (attr := simp)] theorem card_singleton_mul : ({a} * t).card = t.card := card_image₂_singleton_left _ <| mul_right_injective _ #align finset.card_singleton_mul Finset.card_singleton_mul #align finset.card_singleton_add Finset.card_singleton_add @[to_additive] theorem singleton_mul_inter : {a} * (s ∩ t) = {a} * s ∩ ({a} * t) := image₂_singleton_inter _ _ <| mul_right_injective _ #align finset.singleton_mul_inter Finset.singleton_mul_inter #align finset.singleton_add_inter Finset.singleton_add_inter @[to_additive] theorem card_le_card_mul_left {s : Finset α} (hs : s.Nonempty) : t.card ≤ (s * t).card := card_le_card_image₂_left _ hs mul_right_injective #align finset.card_le_card_mul_left Finset.card_le_card_mul_left #align finset.card_le_card_add_left Finset.card_le_card_add_left end IsLeftCancelMul section variable [Mul α] [IsRightCancelMul α] [DecidableEq α] (s t : Finset α) (a : α) @[to_additive (attr := simp)] theorem card_mul_singleton : (s * {a}).card = s.card := card_image₂_singleton_right _ <| mul_left_injective _ #align finset.card_mul_singleton Finset.card_mul_singleton #align finset.card_add_singleton Finset.card_add_singleton @[to_additive] theorem inter_mul_singleton : s ∩ t * {a} = s * {a} ∩ (t * {a}) := image₂_inter_singleton _ _ <| mul_left_injective _ #align finset.inter_mul_singleton Finset.inter_mul_singleton #align finset.inter_add_singleton Finset.inter_add_singleton @[to_additive] theorem card_le_card_mul_right {t : Finset α} (ht : t.Nonempty) : s.card ≤ (s * t).card := card_le_card_image₂_right _ ht mul_left_injective #align finset.card_le_card_mul_right Finset.card_le_card_mul_right #align finset.card_le_card_add_right Finset.card_le_card_add_right end section Group variable [Group α] [DecidableEq α] {s t : Finset α} @[to_additive] lemma card_le_card_div_left (hs : s.Nonempty) : t.card ≤ (s / t).card := card_le_card_image₂_left _ hs fun _ ↦ div_right_injective @[to_additive] lemma card_le_card_div_right (ht : t.Nonempty) : s.card ≤ (s / t).card := card_le_card_image₂_right _ ht fun _ ↦ div_left_injective end Group open Pointwise @[to_additive] theorem image_smul_comm [DecidableEq β] [DecidableEq γ] [SMul α β] [SMul α γ] (f : β → γ) (a : α) (s : Finset β) : (∀ b, f (a • b) = a • f b) → (a • s).image f = a • s.image f := image_comm #align finset.image_smul_comm Finset.image_smul_comm #align finset.image_vadd_comm Finset.image_vadd_comm @[to_additive] theorem image_smul_distrib [DecidableEq α] [DecidableEq β] [Monoid α] [Monoid β] [FunLike F α β] [MonoidHomClass F α β] (f : F) (a : α) (s : Finset α) : (a • s).image f = f a • s.image f := image_comm <| map_mul _ _ #align finset.image_smul_distrib Finset.image_smul_distrib #align finset.image_vadd_distrib Finset.image_vadd_distrib section Group variable [DecidableEq β] [Group α] [MulAction α β] {s t : Finset β} {a : α} {b : β} @[to_additive (attr := simp)] theorem smul_mem_smul_finset_iff (a : α) : a • b ∈ a • s ↔ b ∈ s := (MulAction.injective _).mem_finset_image #align finset.smul_mem_smul_finset_iff Finset.smul_mem_smul_finset_iff #align finset.vadd_mem_vadd_finset_iff Finset.vadd_mem_vadd_finset_iff @[to_additive]
Mathlib/Data/Finset/Pointwise.lean
2,096
2,097
theorem inv_smul_mem_iff : a⁻¹ • b ∈ s ↔ b ∈ a • s := by
rw [← smul_mem_smul_finset_iff a, smul_inv_smul]
/- Copyright (c) 2024 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker, Devon Tuma, Kexing Ying -/ import Mathlib.Probability.Notation import Mathlib.Probability.Density import Mathlib.Probability.ConditionalProbability import Mathlib.Probability.ProbabilityMassFunction.Constructions /-! # Uniform distributions and probability mass functions This file defines two related notions of uniform distributions, which will be unified in the future. # Uniform distributions Defines the uniform distribution for any set with finite measure. ## Main definitions * `IsUniform X s ℙ μ` : A random variable `X` has uniform distribution on `s` under `ℙ` if the push-forward measure agrees with the rescaled restricted measure `μ`. # Uniform probability mass functions This file defines a number of uniform `PMF` distributions from various inputs, uniformly drawing from the corresponding object. ## Main definitions `PMF.uniformOfFinset` gives each element in the set equal probability, with `0` probability for elements not in the set. `PMF.uniformOfFintype` gives all elements equal probability, equal to the inverse of the size of the `Fintype`. `PMF.ofMultiset` draws randomly from the given `Multiset`, treating duplicate values as distinct. Each probability is given by the count of the element divided by the size of the `Multiset` # To Do: * Refactor the `PMF` definitions to come from a `uniformMeasure` on a `Finset`/`Fintype`/`Multiset`. -/ open scoped Classical MeasureTheory NNReal ENNReal -- TODO: We can't `open ProbabilityTheory` without opening the `ProbabilityTheory` locale :( open TopologicalSpace MeasureTheory.Measure PMF noncomputable section namespace MeasureTheory variable {E : Type*} [MeasurableSpace E] {m : Measure E} {μ : Measure E} namespace pdf variable {Ω : Type*} variable {_ : MeasurableSpace Ω} {ℙ : Measure Ω} /-- A random variable `X` has uniform distribution on `s` if its push-forward measure is `(μ s)⁻¹ • μ.restrict s`. -/ def IsUniform (X : Ω → E) (s : Set E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) := map X ℙ = ProbabilityTheory.cond μ s #align measure_theory.pdf.is_uniform MeasureTheory.pdf.IsUniform namespace IsUniform theorem aemeasurable {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : AEMeasurable X ℙ := by dsimp [IsUniform, ProbabilityTheory.cond] at hu by_contra h rw [map_of_not_aemeasurable h] at hu apply zero_ne_one' ℝ≥0∞ calc 0 = (0 : Measure E) Set.univ := rfl _ = _ := by rw [hu, smul_apply, restrict_apply MeasurableSet.univ, Set.univ_inter, smul_eq_mul, ENNReal.inv_mul_cancel hns hnt] theorem absolutelyContinuous {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) : map X ℙ ≪ μ := by rw [hu]; exact ProbabilityTheory.cond_absolutelyContinuous theorem measure_preimage {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) {A : Set E} (hA : MeasurableSet A) : ℙ (X ⁻¹' A) = μ (s ∩ A) / μ s := by rwa [← map_apply_of_aemeasurable (hu.aemeasurable hns hnt) hA, hu, ProbabilityTheory.cond_apply', ENNReal.div_eq_inv_mul] #align measure_theory.pdf.is_uniform.measure_preimage MeasureTheory.pdf.IsUniform.measure_preimage theorem isProbabilityMeasure {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : IsProbabilityMeasure ℙ := ⟨by have : X ⁻¹' Set.univ = Set.univ := Set.preimage_univ rw [← this, hu.measure_preimage hns hnt MeasurableSet.univ, Set.inter_univ, ENNReal.div_self hns hnt]⟩ #align measure_theory.pdf.is_uniform.is_probability_measure MeasureTheory.pdf.IsUniform.isProbabilityMeasure theorem toMeasurable_iff {X : Ω → E} {s : Set E} : IsUniform X (toMeasurable μ s) ℙ μ ↔ IsUniform X s ℙ μ := by unfold IsUniform rw [ProbabilityTheory.cond_toMeasurable_eq] protected theorem toMeasurable {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) : IsUniform X (toMeasurable μ s) ℙ μ := by unfold IsUniform at * rwa [ProbabilityTheory.cond_toMeasurable_eq] theorem hasPDF {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by let t := toMeasurable μ s apply hasPDF_of_map_eq_withDensity (hu.aemeasurable hns hnt) (t.indicator ((μ t)⁻¹ • 1)) <| (measurable_one.aemeasurable.const_smul (μ t)⁻¹).indicator (measurableSet_toMeasurable μ s) rw [hu, withDensity_indicator (measurableSet_toMeasurable μ s), withDensity_smul _ measurable_one, withDensity_one, restrict_toMeasurable hnt, measure_toMeasurable, ProbabilityTheory.cond] #align measure_theory.pdf.is_uniform.has_pdf MeasureTheory.pdf.IsUniform.hasPDF theorem pdf_eq_zero_of_measure_eq_zero_or_top {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) (hμs : μ s = 0 ∨ μ s = ∞) : pdf X ℙ μ =ᵐ[μ] 0 := by rcases hμs with H|H · simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_zero, restrict_eq_zero.mpr H, smul_zero] at hu simp [pdf, hu] · simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_top, zero_smul] at hu simp [pdf, hu] theorem pdf_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hu : IsUniform X s ℙ μ) : pdf X ℙ μ =ᵐ[μ] s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) := by by_cases hnt : μ s = ∞ · simp [pdf_eq_zero_of_measure_eq_zero_or_top hu (Or.inr hnt), hnt] by_cases hns : μ s = 0 · filter_upwards [measure_zero_iff_ae_nmem.mp hns, pdf_eq_zero_of_measure_eq_zero_or_top hu (Or.inl hns)] with x hx h'x simp [hx, h'x, hns] have : HasPDF X ℙ μ := hasPDF hns hnt hu have : IsProbabilityMeasure ℙ := isProbabilityMeasure hns hnt hu apply (eq_of_map_eq_withDensity _ _).mp · rw [hu, withDensity_indicator hms, withDensity_smul _ measurable_one, withDensity_one, ProbabilityTheory.cond] · exact (measurable_one.aemeasurable.const_smul (μ s)⁻¹).indicator hms theorem pdf_toReal_ae_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hX : IsUniform X s ℙ μ) : (fun x => (pdf X ℙ μ x).toReal) =ᵐ[μ] fun x => (s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) x).toReal := Filter.EventuallyEq.fun_comp (pdf_eq hms hX) ENNReal.toReal #align measure_theory.pdf.is_uniform.pdf_to_real_ae_eq MeasureTheory.pdf.IsUniform.pdf_toReal_ae_eq variable {X : Ω → ℝ} {s : Set ℝ} theorem mul_pdf_integrable (hcs : IsCompact s) (huX : IsUniform X s ℙ) : Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by by_cases hnt : volume s = 0 ∨ volume s = ∞ · have I : Integrable (fun x ↦ x * ENNReal.toReal (0)) := by simp apply I.congr filter_upwards [pdf_eq_zero_of_measure_eq_zero_or_top huX hnt] with x hx simp [hx] simp only [not_or] at hnt have : IsProbabilityMeasure ℙ := isProbabilityMeasure hnt.1 hnt.2 huX constructor · exact aestronglyMeasurable_id.mul (measurable_pdf X ℙ).aemeasurable.ennreal_toReal.aestronglyMeasurable refine hasFiniteIntegral_mul (pdf_eq hcs.measurableSet huX) ?_ set ind := (volume s)⁻¹ • (1 : ℝ → ℝ≥0∞) have : ∀ x, ↑‖x‖₊ * s.indicator ind x = s.indicator (fun x => ‖x‖₊ * ind x) x := fun x => (s.indicator_mul_right (fun x => ↑‖x‖₊) ind).symm simp only [ind, this, lintegral_indicator _ hcs.measurableSet, mul_one, Algebra.id.smul_eq_mul, Pi.one_apply, Pi.smul_apply] rw [lintegral_mul_const _ measurable_nnnorm.coe_nnreal_ennreal] exact (ENNReal.mul_lt_top (set_lintegral_lt_top_of_isCompact hnt.2 hcs continuous_nnnorm).ne (ENNReal.inv_lt_top.2 (pos_iff_ne_zero.mpr hnt.1)).ne).ne #align measure_theory.pdf.is_uniform.mul_pdf_integrable MeasureTheory.pdf.IsUniform.mul_pdf_integrable /-- A real uniform random variable `X` with support `s` has expectation `(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/ theorem integral_eq (huX : IsUniform X s ℙ) : ∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by rw [← smul_eq_mul, ← integral_smul_measure] dsimp only [IsUniform, ProbabilityTheory.cond] at huX rw [← huX] by_cases hX : AEMeasurable X ℙ · exact (integral_map hX aestronglyMeasurable_id).symm · rw [map_of_not_aemeasurable hX, integral_zero_measure, integral_non_aestronglyMeasurable] rwa [aestronglyMeasurable_iff_aemeasurable] #align measure_theory.pdf.is_uniform.integral_eq MeasureTheory.pdf.IsUniform.integral_eq end IsUniform variable {X : Ω → E} lemma IsUniform.cond {s : Set E} : IsUniform (id : E → E) s (ProbabilityTheory.cond μ s) μ := by unfold IsUniform rw [Measure.map_id] /-- The density of the uniform measure on a set with respect to itself. This allows us to abstract away the choice of random variable and probability space. -/ def uniformPDF (s : Set E) (x : E) (μ : Measure E := by volume_tac) : ℝ≥0∞ := s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) x /-- Check that indeed any uniform random variable has the uniformPDF. -/ lemma uniformPDF_eq_pdf {s : Set E} (hs : MeasurableSet s) (hu : pdf.IsUniform X s ℙ μ) : (fun x ↦ uniformPDF s x μ) =ᵐ[μ] pdf X ℙ μ := by unfold uniformPDF exact Filter.EventuallyEq.trans (pdf.IsUniform.pdf_eq hs hu).symm (ae_eq_refl _) /-- Alternative way of writing the uniformPDF. -/ lemma uniformPDF_ite {s : Set E} {x : E} : uniformPDF s x μ = if x ∈ s then (μ s)⁻¹ else 0 := by unfold uniformPDF unfold Set.indicator simp only [Pi.smul_apply, Pi.one_apply, smul_eq_mul, mul_one] end pdf end MeasureTheory noncomputable section namespace PMF variable {α β γ : Type*} open scoped Classical NNReal ENNReal section UniformOfFinset /-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/ def uniformOfFinset (s : Finset α) (hs : s.Nonempty) : PMF α := by refine ofFinset (fun a => if a ∈ s then s.card⁻¹ else 0) s ?_ ?_ · simp only [Finset.sum_ite_mem, Finset.inter_self, Finset.sum_const, nsmul_eq_mul] have : (s.card : ℝ≥0∞) ≠ 0 := by simpa only [Ne, Nat.cast_eq_zero, Finset.card_eq_zero] using Finset.nonempty_iff_ne_empty.1 hs exact ENNReal.mul_inv_cancel this <| ENNReal.natCast_ne_top s.card · exact fun x hx => by simp only [hx, if_false] #align pmf.uniform_of_finset PMF.uniformOfFinset variable {s : Finset α} (hs : s.Nonempty) {a : α} @[simp] theorem uniformOfFinset_apply (a : α) : uniformOfFinset s hs a = if a ∈ s then (s.card : ℝ≥0∞)⁻¹ else 0 := rfl #align pmf.uniform_of_finset_apply PMF.uniformOfFinset_apply theorem uniformOfFinset_apply_of_mem (ha : a ∈ s) : uniformOfFinset s hs a = (s.card : ℝ≥0∞)⁻¹ := by simp [ha] #align pmf.uniform_of_finset_apply_of_mem PMF.uniformOfFinset_apply_of_mem theorem uniformOfFinset_apply_of_not_mem (ha : a ∉ s) : uniformOfFinset s hs a = 0 := by simp [ha] #align pmf.uniform_of_finset_apply_of_not_mem PMF.uniformOfFinset_apply_of_not_mem @[simp] theorem support_uniformOfFinset : (uniformOfFinset s hs).support = s := Set.ext (by let ⟨a, ha⟩ := hs simp [mem_support_iff, Finset.ne_empty_of_mem ha]) #align pmf.support_uniform_of_finset PMF.support_uniformOfFinset theorem mem_support_uniformOfFinset_iff (a : α) : a ∈ (uniformOfFinset s hs).support ↔ a ∈ s := by simp #align pmf.mem_support_uniform_of_finset_iff PMF.mem_support_uniformOfFinset_iff section Measure variable (t : Set α) @[simp] theorem toOuterMeasure_uniformOfFinset_apply : (uniformOfFinset s hs).toOuterMeasure t = (s.filter (· ∈ t)).card / s.card := calc (uniformOfFinset s hs).toOuterMeasure t = ∑' x, if x ∈ t then uniformOfFinset s hs x else 0 := toOuterMeasure_apply (uniformOfFinset s hs) t _ = ∑' x, if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 := (tsum_congr fun x => by simp_rw [uniformOfFinset_apply, ← ite_and, and_comm]) _ = ∑ x ∈ s.filter (· ∈ t), if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 := (tsum_eq_sum fun x hx => if_neg fun h => hx (Finset.mem_filter.2 h)) _ = ∑ _x ∈ s.filter (· ∈ t), (s.card : ℝ≥0∞)⁻¹ := (Finset.sum_congr rfl fun x hx => by let this : x ∈ s ∧ x ∈ t := by simpa using hx simp only [this, and_self_iff, if_true]) _ = (s.filter (· ∈ t)).card / s.card := by simp only [div_eq_mul_inv, Finset.sum_const, nsmul_eq_mul] #align pmf.to_outer_measure_uniform_of_finset_apply PMF.toOuterMeasure_uniformOfFinset_apply @[simp] theorem toMeasure_uniformOfFinset_apply [MeasurableSpace α] (ht : MeasurableSet t) : (uniformOfFinset s hs).toMeasure t = (s.filter (· ∈ t)).card / s.card := (toMeasure_apply_eq_toOuterMeasure_apply _ t ht).trans (toOuterMeasure_uniformOfFinset_apply hs t) #align pmf.to_measure_uniform_of_finset_apply PMF.toMeasure_uniformOfFinset_apply end Measure end UniformOfFinset section UniformOfFintype /-- The uniform pmf taking the same uniform value on all of the fintype `α` -/ def uniformOfFintype (α : Type*) [Fintype α] [Nonempty α] : PMF α := uniformOfFinset Finset.univ Finset.univ_nonempty #align pmf.uniform_of_fintype PMF.uniformOfFintype variable [Fintype α] [Nonempty α] @[simp] theorem uniformOfFintype_apply (a : α) : uniformOfFintype α a = (Fintype.card α : ℝ≥0∞)⁻¹ := by simp [uniformOfFintype, Finset.mem_univ, if_true, uniformOfFinset_apply] #align pmf.uniform_of_fintype_apply PMF.uniformOfFintype_apply @[simp] theorem support_uniformOfFintype (α : Type*) [Fintype α] [Nonempty α] : (uniformOfFintype α).support = ⊤ := Set.ext fun x => by simp [mem_support_iff] #align pmf.support_uniform_of_fintype PMF.support_uniformOfFintype theorem mem_support_uniformOfFintype (a : α) : a ∈ (uniformOfFintype α).support := by simp #align pmf.mem_support_uniform_of_fintype PMF.mem_support_uniformOfFintype section Measure variable (s : Set α) theorem toOuterMeasure_uniformOfFintype_apply : (uniformOfFintype α).toOuterMeasure s = Fintype.card s / Fintype.card α := by rw [uniformOfFintype, toOuterMeasure_uniformOfFinset_apply,Fintype.card_ofFinset] rfl #align pmf.to_outer_measure_uniform_of_fintype_apply PMF.toOuterMeasure_uniformOfFintype_apply theorem toMeasure_uniformOfFintype_apply [MeasurableSpace α] (hs : MeasurableSet s) : (uniformOfFintype α).toMeasure s = Fintype.card s / Fintype.card α := by simp [uniformOfFintype, hs] #align pmf.to_measure_uniform_of_fintype_apply PMF.toMeasure_uniformOfFintype_apply end Measure end UniformOfFintype section OfMultiset /-- Given a non-empty multiset `s` we construct the `PMF` which sends `a` to the fraction of elements in `s` that are `a`. -/ def ofMultiset (s : Multiset α) (hs : s ≠ 0) : PMF α := ⟨fun a => s.count a / (Multiset.card s), ENNReal.summable.hasSum_iff.2 (calc (∑' b : α, (s.count b : ℝ≥0∞) / (Multiset.card s)) = (Multiset.card s : ℝ≥0∞)⁻¹ * ∑' b, (s.count b : ℝ≥0∞) := by simp_rw [ENNReal.div_eq_inv_mul, ENNReal.tsum_mul_left] _ = (Multiset.card s : ℝ≥0∞)⁻¹ * ∑ b ∈ s.toFinset, (s.count b : ℝ≥0∞) := (congr_arg (fun x => (Multiset.card s : ℝ≥0∞)⁻¹ * x) (tsum_eq_sum fun a ha => Nat.cast_eq_zero.2 <| by rwa [Multiset.count_eq_zero, ← Multiset.mem_toFinset])) _ = 1 := by rw [← Nat.cast_sum, Multiset.toFinset_sum_count_eq s, ENNReal.inv_mul_cancel (Nat.cast_ne_zero.2 (hs ∘ Multiset.card_eq_zero.1)) (ENNReal.natCast_ne_top _)] )⟩ #align pmf.of_multiset PMF.ofMultiset variable {s : Multiset α} (hs : s ≠ 0) @[simp] theorem ofMultiset_apply (a : α) : ofMultiset s hs a = s.count a / (Multiset.card s) := rfl #align pmf.of_multiset_apply PMF.ofMultiset_apply @[simp] theorem support_ofMultiset : (ofMultiset s hs).support = s.toFinset := Set.ext (by simp [mem_support_iff, hs]) #align pmf.support_of_multiset PMF.support_ofMultiset theorem mem_support_ofMultiset_iff (a : α) : a ∈ (ofMultiset s hs).support ↔ a ∈ s.toFinset := by simp #align pmf.mem_support_of_multiset_iff PMF.mem_support_ofMultiset_iff theorem ofMultiset_apply_of_not_mem {a : α} (ha : a ∉ s) : ofMultiset s hs a = 0 := by simpa only [ofMultiset_apply, ENNReal.div_eq_zero_iff, Nat.cast_eq_zero, Multiset.count_eq_zero, ENNReal.natCast_ne_top, or_false_iff] using ha #align pmf.of_multiset_apply_of_not_mem PMF.ofMultiset_apply_of_not_mem section Measure variable (t : Set α) @[simp]
Mathlib/Probability/Distributions/Uniform.lean
385
390
theorem toOuterMeasure_ofMultiset_apply : (ofMultiset s hs).toOuterMeasure t = (∑' x, (s.filter (· ∈ t)).count x : ℝ≥0∞) / (Multiset.card s) := by
simp_rw [div_eq_mul_inv, ← ENNReal.tsum_mul_right, toOuterMeasure_apply] refine tsum_congr fun x => ?_ by_cases hx : x ∈ t <;> simp [Set.indicator, hx, div_eq_mul_inv]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Data.ENNReal.Operations #align_import data.real.ennreal from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Results about division in extended non-negative reals This file establishes basic properties related to the inversion and division operations on `ℝ≥0∞`. For instance, as a consequence of being a `DivInvOneMonoid`, `ℝ≥0∞` inherits a power operation with integer exponent. ## Main results A few order isomorphisms are worthy of mention: - `OrderIso.invENNReal : ℝ≥0∞ ≃o ℝ≥0∞ᵒᵈ`: The map `x ↦ x⁻¹` as an order isomorphism to the dual. - `orderIsoIicOneBirational : ℝ≥0∞ ≃o Iic (1 : ℝ≥0∞)`: The birational order isomorphism between `ℝ≥0∞` and the unit interval `Set.Iic (1 : ℝ≥0∞)` given by `x ↦ (x⁻¹ + 1)⁻¹` with inverse `x ↦ (x⁻¹ - 1)⁻¹` - `orderIsoIicCoe (a : ℝ≥0) : Iic (a : ℝ≥0∞) ≃o Iic a`: Order isomorphism between an initial interval in `ℝ≥0∞` and an initial interval in `ℝ≥0` given by the identity map. - `orderIsoUnitIntervalBirational : ℝ≥0∞ ≃o Icc (0 : ℝ) 1`: An order isomorphism between the extended nonnegative real numbers and the unit interval. This is `orderIsoIicOneBirational` composed with the identity order isomorphism between `Iic (1 : ℝ≥0∞)` and `Icc (0 : ℝ) 1`. -/ open Set NNReal namespace ENNReal noncomputable section Inv variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} protected theorem div_eq_inv_mul : a / b = b⁻¹ * a := by rw [div_eq_mul_inv, mul_comm] #align ennreal.div_eq_inv_mul ENNReal.div_eq_inv_mul @[simp] theorem inv_zero : (0 : ℝ≥0∞)⁻¹ = ∞ := show sInf { b : ℝ≥0∞ | 1 ≤ 0 * b } = ∞ by simp #align ennreal.inv_zero ENNReal.inv_zero @[simp] theorem inv_top : ∞⁻¹ = 0 := bot_unique <| le_of_forall_le_of_dense fun a (h : 0 < a) => sInf_le <| by simp [*, h.ne', top_mul] #align ennreal.inv_top ENNReal.inv_top theorem coe_inv_le : (↑r⁻¹ : ℝ≥0∞) ≤ (↑r)⁻¹ := le_sInf fun b (hb : 1 ≤ ↑r * b) => coe_le_iff.2 <| by rintro b rfl apply NNReal.inv_le_of_le_mul rwa [← coe_mul, ← coe_one, coe_le_coe] at hb #align ennreal.coe_inv_le ENNReal.coe_inv_le @[simp, norm_cast] theorem coe_inv (hr : r ≠ 0) : (↑r⁻¹ : ℝ≥0∞) = (↑r)⁻¹ := coe_inv_le.antisymm <| sInf_le <| mem_setOf.2 <| by rw [← coe_mul, mul_inv_cancel hr, coe_one] #align ennreal.coe_inv ENNReal.coe_inv @[norm_cast] theorem coe_inv_two : ((2⁻¹ : ℝ≥0) : ℝ≥0∞) = 2⁻¹ := by rw [coe_inv _root_.two_ne_zero, coe_two] #align ennreal.coe_inv_two ENNReal.coe_inv_two @[simp, norm_cast] theorem coe_div (hr : r ≠ 0) : (↑(p / r) : ℝ≥0∞) = p / r := by rw [div_eq_mul_inv, div_eq_mul_inv, coe_mul, coe_inv hr] #align ennreal.coe_div ENNReal.coe_div lemma coe_div_le : ↑(p / r) ≤ (p / r : ℝ≥0∞) := by simpa only [div_eq_mul_inv, coe_mul] using mul_le_mul_left' coe_inv_le _ theorem div_zero (h : a ≠ 0) : a / 0 = ∞ := by simp [div_eq_mul_inv, h] #align ennreal.div_zero ENNReal.div_zero instance : DivInvOneMonoid ℝ≥0∞ := { inferInstanceAs (DivInvMonoid ℝ≥0∞) with inv_one := by simpa only [coe_inv one_ne_zero, coe_one] using coe_inj.2 inv_one } protected theorem inv_pow : ∀ {a : ℝ≥0∞} {n : ℕ}, (a ^ n)⁻¹ = a⁻¹ ^ n | _, 0 => by simp only [pow_zero, inv_one] | ⊤, n + 1 => by simp [top_pow] | (a : ℝ≥0), n + 1 => by rcases eq_or_ne a 0 with (rfl | ha) · simp [top_pow] · have := pow_ne_zero (n + 1) ha norm_cast rw [inv_pow] #align ennreal.inv_pow ENNReal.inv_pow protected theorem mul_inv_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a * a⁻¹ = 1 := by lift a to ℝ≥0 using ht norm_cast at h0; norm_cast exact mul_inv_cancel h0 #align ennreal.mul_inv_cancel ENNReal.mul_inv_cancel protected theorem inv_mul_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a⁻¹ * a = 1 := mul_comm a a⁻¹ ▸ ENNReal.mul_inv_cancel h0 ht #align ennreal.inv_mul_cancel ENNReal.inv_mul_cancel protected theorem div_mul_cancel (h0 : a ≠ 0) (hI : a ≠ ∞) : b / a * a = b := by rw [div_eq_mul_inv, mul_assoc, ENNReal.inv_mul_cancel h0 hI, mul_one] #align ennreal.div_mul_cancel ENNReal.div_mul_cancel protected theorem mul_div_cancel' (h0 : a ≠ 0) (hI : a ≠ ∞) : a * (b / a) = b := by rw [mul_comm, ENNReal.div_mul_cancel h0 hI] #align ennreal.mul_div_cancel' ENNReal.mul_div_cancel' -- Porting note: `simp only [div_eq_mul_inv, mul_comm, mul_assoc]` doesn't work in the following two protected theorem mul_comm_div : a / b * c = a * (c / b) := by simp only [div_eq_mul_inv, mul_right_comm, ← mul_assoc] #align ennreal.mul_comm_div ENNReal.mul_comm_div protected theorem mul_div_right_comm : a * b / c = a / c * b := by simp only [div_eq_mul_inv, mul_right_comm] #align ennreal.mul_div_right_comm ENNReal.mul_div_right_comm instance : InvolutiveInv ℝ≥0∞ where inv_inv a := by by_cases a = 0 <;> cases a <;> simp_all [none_eq_top, some_eq_coe, -coe_inv, (coe_inv _).symm] @[simp] protected lemma inv_eq_one : a⁻¹ = 1 ↔ a = 1 := by rw [← inv_inj, inv_inv, inv_one] @[simp] theorem inv_eq_top : a⁻¹ = ∞ ↔ a = 0 := inv_zero ▸ inv_inj #align ennreal.inv_eq_top ENNReal.inv_eq_top theorem inv_ne_top : a⁻¹ ≠ ∞ ↔ a ≠ 0 := by simp #align ennreal.inv_ne_top ENNReal.inv_ne_top @[simp] theorem inv_lt_top {x : ℝ≥0∞} : x⁻¹ < ∞ ↔ 0 < x := by simp only [lt_top_iff_ne_top, inv_ne_top, pos_iff_ne_zero] #align ennreal.inv_lt_top ENNReal.inv_lt_top theorem div_lt_top {x y : ℝ≥0∞} (h1 : x ≠ ∞) (h2 : y ≠ 0) : x / y < ∞ := mul_lt_top h1 (inv_ne_top.mpr h2) #align ennreal.div_lt_top ENNReal.div_lt_top @[simp] protected theorem inv_eq_zero : a⁻¹ = 0 ↔ a = ∞ := inv_top ▸ inv_inj #align ennreal.inv_eq_zero ENNReal.inv_eq_zero protected theorem inv_ne_zero : a⁻¹ ≠ 0 ↔ a ≠ ∞ := by simp #align ennreal.inv_ne_zero ENNReal.inv_ne_zero protected theorem div_pos (ha : a ≠ 0) (hb : b ≠ ∞) : 0 < a / b := ENNReal.mul_pos ha <| ENNReal.inv_ne_zero.2 hb #align ennreal.div_pos ENNReal.div_pos protected theorem mul_inv {a b : ℝ≥0∞} (ha : a ≠ 0 ∨ b ≠ ∞) (hb : a ≠ ∞ ∨ b ≠ 0) : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by induction' b with b · replace ha : a ≠ 0 := ha.neg_resolve_right rfl simp [ha] induction' a with a · replace hb : b ≠ 0 := coe_ne_zero.1 (hb.neg_resolve_left rfl) simp [hb] by_cases h'a : a = 0 · simp only [h'a, top_mul, ENNReal.inv_zero, ENNReal.coe_ne_top, zero_mul, Ne, not_false_iff, ENNReal.coe_zero, ENNReal.inv_eq_zero] by_cases h'b : b = 0 · simp only [h'b, ENNReal.inv_zero, ENNReal.coe_ne_top, mul_top, Ne, not_false_iff, mul_zero, ENNReal.coe_zero, ENNReal.inv_eq_zero] rw [← ENNReal.coe_mul, ← ENNReal.coe_inv, ← ENNReal.coe_inv h'a, ← ENNReal.coe_inv h'b, ← ENNReal.coe_mul, mul_inv_rev, mul_comm] simp [h'a, h'b] #align ennreal.mul_inv ENNReal.mul_inv protected theorem mul_div_mul_left (a b : ℝ≥0∞) (hc : c ≠ 0) (hc' : c ≠ ⊤) : c * a / (c * b) = a / b := by rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inl hc) (Or.inl hc'), mul_mul_mul_comm, ENNReal.mul_inv_cancel hc hc', one_mul] #align ennreal.mul_div_mul_left ENNReal.mul_div_mul_left protected theorem mul_div_mul_right (a b : ℝ≥0∞) (hc : c ≠ 0) (hc' : c ≠ ⊤) : a * c / (b * c) = a / b := by rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inr hc') (Or.inr hc), mul_mul_mul_comm, ENNReal.mul_inv_cancel hc hc', mul_one] #align ennreal.mul_div_mul_right ENNReal.mul_div_mul_right protected theorem sub_div (h : 0 < b → b < a → c ≠ 0) : (a - b) / c = a / c - b / c := by simp_rw [div_eq_mul_inv] exact ENNReal.sub_mul (by simpa using h) #align ennreal.sub_div ENNReal.sub_div @[simp] protected theorem inv_pos : 0 < a⁻¹ ↔ a ≠ ∞ := pos_iff_ne_zero.trans ENNReal.inv_ne_zero #align ennreal.inv_pos ENNReal.inv_pos theorem inv_strictAnti : StrictAnti (Inv.inv : ℝ≥0∞ → ℝ≥0∞) := by intro a b h lift a to ℝ≥0 using h.ne_top induction b; · simp rw [coe_lt_coe] at h rcases eq_or_ne a 0 with (rfl | ha); · simp [h] rw [← coe_inv h.ne_bot, ← coe_inv ha, coe_lt_coe] exact NNReal.inv_lt_inv ha h #align ennreal.inv_strict_anti ENNReal.inv_strictAnti @[simp] protected theorem inv_lt_inv : a⁻¹ < b⁻¹ ↔ b < a := inv_strictAnti.lt_iff_lt #align ennreal.inv_lt_inv ENNReal.inv_lt_inv theorem inv_lt_iff_inv_lt : a⁻¹ < b ↔ b⁻¹ < a := by simpa only [inv_inv] using @ENNReal.inv_lt_inv a b⁻¹ #align ennreal.inv_lt_iff_inv_lt ENNReal.inv_lt_iff_inv_lt theorem lt_inv_iff_lt_inv : a < b⁻¹ ↔ b < a⁻¹ := by simpa only [inv_inv] using @ENNReal.inv_lt_inv a⁻¹ b #align ennreal.lt_inv_iff_lt_inv ENNReal.lt_inv_iff_lt_inv @[simp] protected theorem inv_le_inv : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := inv_strictAnti.le_iff_le #align ennreal.inv_le_inv ENNReal.inv_le_inv theorem inv_le_iff_inv_le : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by simpa only [inv_inv] using @ENNReal.inv_le_inv a b⁻¹ #align ennreal.inv_le_iff_inv_le ENNReal.inv_le_iff_inv_le theorem le_inv_iff_le_inv : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by simpa only [inv_inv] using @ENNReal.inv_le_inv a⁻¹ b #align ennreal.le_inv_iff_le_inv ENNReal.le_inv_iff_le_inv @[gcongr] protected theorem inv_le_inv' (h : a ≤ b) : b⁻¹ ≤ a⁻¹ := ENNReal.inv_strictAnti.antitone h @[gcongr] protected theorem inv_lt_inv' (h : a < b) : b⁻¹ < a⁻¹ := ENNReal.inv_strictAnti h @[simp] protected theorem inv_le_one : a⁻¹ ≤ 1 ↔ 1 ≤ a := by rw [inv_le_iff_inv_le, inv_one] #align ennreal.inv_le_one ENNReal.inv_le_one protected theorem one_le_inv : 1 ≤ a⁻¹ ↔ a ≤ 1 := by rw [le_inv_iff_le_inv, inv_one] #align ennreal.one_le_inv ENNReal.one_le_inv @[simp] protected theorem inv_lt_one : a⁻¹ < 1 ↔ 1 < a := by rw [inv_lt_iff_inv_lt, inv_one] #align ennreal.inv_lt_one ENNReal.inv_lt_one @[simp] protected theorem one_lt_inv : 1 < a⁻¹ ↔ a < 1 := by rw [lt_inv_iff_lt_inv, inv_one] #align ennreal.one_lt_inv ENNReal.one_lt_inv /-- The inverse map `fun x ↦ x⁻¹` is an order isomorphism between `ℝ≥0∞` and its `OrderDual` -/ @[simps! apply] def _root_.OrderIso.invENNReal : ℝ≥0∞ ≃o ℝ≥0∞ᵒᵈ where map_rel_iff' := ENNReal.inv_le_inv toEquiv := (Equiv.inv ℝ≥0∞).trans OrderDual.toDual #align order_iso.inv_ennreal OrderIso.invENNReal #align order_iso.inv_ennreal_apply OrderIso.invENNReal_apply @[simp] theorem _root_.OrderIso.invENNReal_symm_apply (a : ℝ≥0∞ᵒᵈ) : OrderIso.invENNReal.symm a = (OrderDual.ofDual a)⁻¹ := rfl #align order_iso.inv_ennreal_symm_apply OrderIso.invENNReal_symm_apply @[simp] theorem div_top : a / ∞ = 0 := by rw [div_eq_mul_inv, inv_top, mul_zero] #align ennreal.div_top ENNReal.div_top -- Porting note: reordered 4 lemmas
Mathlib/Data/ENNReal/Inv.lean
273
273
theorem top_div : ∞ / a = if a = ∞ then 0 else ∞ := by
simp [div_eq_mul_inv, top_mul']
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Convex.Between import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.Topology.MetricSpace.Holder import Mathlib.Topology.MetricSpace.MetricSeparated #align_import measure_theory.measure.hausdorff from "leanprover-community/mathlib"@"3d5c4a7a5fb0d982f97ed953161264f1dbd90ead" /-! # Hausdorff measure and metric (outer) measures In this file we define the `d`-dimensional Hausdorff measure on an (extended) metric space `X` and the Hausdorff dimension of a set in an (extended) metric space. Let `μ d δ` be the maximal outer measure such that `μ d δ s ≤ (EMetric.diam s) ^ d` for every set of diameter less than `δ`. Then the Hausdorff measure `μH[d] s` of `s` is defined as `⨆ δ > 0, μ d δ s`. By Caratheodory theorem `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`, this is a Borel measure on `X`. The value of `μH[d]`, `d > 0`, on a set `s` (measurable or not) is given by ``` μH[d] s = ⨆ (r : ℝ≥0∞) (hr : 0 < r), ⨅ (t : ℕ → Set X) (hts : s ⊆ ⋃ n, t n) (ht : ∀ n, EMetric.diam (t n) ≤ r), ∑' n, EMetric.diam (t n) ^ d ``` For every set `s` for any `d < d'` we have either `μH[d] s = ∞` or `μH[d'] s = 0`, see `MeasureTheory.Measure.hausdorffMeasure_zero_or_top`. In `Mathlib.Topology.MetricSpace.HausdorffDimension` we use this fact to define the Hausdorff dimension `dimH` of a set in an (extended) metric space. We also define two generalizations of the Hausdorff measure. In one generalization (see `MeasureTheory.Measure.mkMetric`) we take any function `m (diam s)` instead of `(diam s) ^ d`. In an even more general definition (see `MeasureTheory.Measure.mkMetric'`) we use any function of `m : Set X → ℝ≥0∞`. Some authors start with a partial function `m` defined only on some sets `s : Set X` (e.g., only on balls or only on measurable sets). This is equivalent to our definition applied to `MeasureTheory.extend m`. We also define a predicate `MeasureTheory.OuterMeasure.IsMetric` which says that an outer measure is additive on metric separated pairs of sets: `μ (s ∪ t) = μ s + μ t` provided that `⨅ (x ∈ s) (y ∈ t), edist x y ≠ 0`. This is the property required for the Caratheodory theorem `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`, so we prove this theorem for any metric outer measure, then prove that outer measures constructed using `mkMetric'` are metric outer measures. ## Main definitions * `MeasureTheory.OuterMeasure.IsMetric`: an outer measure `μ` is called *metric* if `μ (s ∪ t) = μ s + μ t` for any two metric separated sets `s` and `t`. A metric outer measure in a Borel extended metric space is guaranteed to satisfy the Caratheodory condition, see `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`. * `MeasureTheory.OuterMeasure.mkMetric'` and its particular case `MeasureTheory.OuterMeasure.mkMetric`: a construction of an outer measure that is guaranteed to be metric. Both constructions are generalizations of the Hausdorff measure. The same measures interpreted as Borel measures are called `MeasureTheory.Measure.mkMetric'` and `MeasureTheory.Measure.mkMetric`. * `MeasureTheory.Measure.hausdorffMeasure` a.k.a. `μH[d]`: the `d`-dimensional Hausdorff measure. There are many definitions of the Hausdorff measure that differ from each other by a multiplicative constant. We put `μH[d] s = ⨆ r > 0, ⨅ (t : ℕ → Set X) (hts : s ⊆ ⋃ n, t n) (ht : ∀ n, EMetric.diam (t n) ≤ r), ∑' n, ⨆ (ht : ¬Set.Subsingleton (t n)), (EMetric.diam (t n)) ^ d`, see `MeasureTheory.Measure.hausdorffMeasure_apply`. In the most interesting case `0 < d` one can omit the `⨆ (ht : ¬Set.Subsingleton (t n))` part. ## Main statements ### Basic properties * `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`: if `μ` is a metric outer measure on an extended metric space `X` (that is, it is additive on pairs of metric separated sets), then every Borel set is Caratheodory measurable (hence, `μ` defines an actual `MeasureTheory.Measure`). See also `MeasureTheory.Measure.mkMetric`. * `MeasureTheory.Measure.hausdorffMeasure_mono`: `μH[d] s` is an antitone function of `d`. * `MeasureTheory.Measure.hausdorffMeasure_zero_or_top`: if `d₁ < d₂`, then for any `s`, either `μH[d₂] s = 0` or `μH[d₁] s = ∞`. Together with the previous lemma, this means that `μH[d] s` is equal to infinity on some ray `(-∞, D)` and is equal to zero on `(D, +∞)`, where `D` is a possibly infinite number called the *Hausdorff dimension* of `s`; `μH[D] s` can be zero, infinity, or anything in between. * `MeasureTheory.Measure.noAtoms_hausdorff`: Hausdorff measure has no atoms. ### Hausdorff measure in `ℝⁿ` * `MeasureTheory.hausdorffMeasure_pi_real`: for a nonempty `ι`, `μH[card ι]` on `ι → ℝ` equals Lebesgue measure. ## Notations We use the following notation localized in `MeasureTheory`. - `μH[d]` : `MeasureTheory.Measure.hausdorffMeasure d` ## Implementation notes There are a few similar constructions called the `d`-dimensional Hausdorff measure. E.g., some sources only allow coverings by balls and use `r ^ d` instead of `(diam s) ^ d`. While these construction lead to different Hausdorff measures, they lead to the same notion of the Hausdorff dimension. ## References * [Herbert Federer, Geometric Measure Theory, Chapter 2.10][Federer1996] ## Tags Hausdorff measure, measure, metric measure -/ open scoped NNReal ENNReal Topology open EMetric Set Function Filter Encodable FiniteDimensional TopologicalSpace noncomputable section variable {ι X Y : Type*} [EMetricSpace X] [EMetricSpace Y] namespace MeasureTheory namespace OuterMeasure /-! ### Metric outer measures In this section we define metric outer measures and prove Caratheodory theorem: a metric outer measure has the Caratheodory property. -/ /-- We say that an outer measure `μ` in an (e)metric space is *metric* if `μ (s ∪ t) = μ s + μ t` for any two metric separated sets `s`, `t`. -/ def IsMetric (μ : OuterMeasure X) : Prop := ∀ s t : Set X, IsMetricSeparated s t → μ (s ∪ t) = μ s + μ t #align measure_theory.outer_measure.is_metric MeasureTheory.OuterMeasure.IsMetric namespace IsMetric variable {μ : OuterMeasure X} /-- A metric outer measure is additive on a finite set of pairwise metric separated sets. -/ theorem finset_iUnion_of_pairwise_separated (hm : IsMetric μ) {I : Finset ι} {s : ι → Set X} (hI : ∀ i ∈ I, ∀ j ∈ I, i ≠ j → IsMetricSeparated (s i) (s j)) : μ (⋃ i ∈ I, s i) = ∑ i ∈ I, μ (s i) := by classical induction' I using Finset.induction_on with i I hiI ihI hI · simp simp only [Finset.mem_insert] at hI rw [Finset.set_biUnion_insert, hm, ihI, Finset.sum_insert hiI] exacts [fun i hi j hj hij => hI i (Or.inr hi) j (Or.inr hj) hij, IsMetricSeparated.finset_iUnion_right fun j hj => hI i (Or.inl rfl) j (Or.inr hj) (ne_of_mem_of_not_mem hj hiI).symm] #align measure_theory.outer_measure.is_metric.finset_Union_of_pairwise_separated MeasureTheory.OuterMeasure.IsMetric.finset_iUnion_of_pairwise_separated /-- Caratheodory theorem. If `m` is a metric outer measure, then every Borel measurable set `t` is Caratheodory measurable: for any (not necessarily measurable) set `s` we have `μ (s ∩ t) + μ (s \ t) = μ s`. -/ theorem borel_le_caratheodory (hm : IsMetric μ) : borel X ≤ μ.caratheodory := by rw [borel_eq_generateFrom_isClosed] refine MeasurableSpace.generateFrom_le fun t ht => μ.isCaratheodory_iff_le.2 fun s => ?_ set S : ℕ → Set X := fun n => {x ∈ s | (↑n)⁻¹ ≤ infEdist x t} have Ssep (n) : IsMetricSeparated (S n) t := ⟨n⁻¹, ENNReal.inv_ne_zero.2 (ENNReal.natCast_ne_top _), fun x hx y hy ↦ hx.2.trans <| infEdist_le_edist_of_mem hy⟩ have Ssep' : ∀ n, IsMetricSeparated (S n) (s ∩ t) := fun n => (Ssep n).mono Subset.rfl inter_subset_right have S_sub : ∀ n, S n ⊆ s \ t := fun n => subset_inter inter_subset_left (Ssep n).subset_compl_right have hSs : ∀ n, μ (s ∩ t) + μ (S n) ≤ μ s := fun n => calc μ (s ∩ t) + μ (S n) = μ (s ∩ t ∪ S n) := Eq.symm <| hm _ _ <| (Ssep' n).symm _ ≤ μ (s ∩ t ∪ s \ t) := μ.mono <| union_subset_union_right _ <| S_sub n _ = μ s := by rw [inter_union_diff] have iUnion_S : ⋃ n, S n = s \ t := by refine Subset.antisymm (iUnion_subset S_sub) ?_ rintro x ⟨hxs, hxt⟩ rw [mem_iff_infEdist_zero_of_closed ht] at hxt rcases ENNReal.exists_inv_nat_lt hxt with ⟨n, hn⟩ exact mem_iUnion.2 ⟨n, hxs, hn.le⟩ /- Now we have `∀ n, μ (s ∩ t) + μ (S n) ≤ μ s` and we need to prove `μ (s ∩ t) + μ (⋃ n, S n) ≤ μ s`. We can't pass to the limit because `μ` is only an outer measure. -/ by_cases htop : μ (s \ t) = ∞ · rw [htop, add_top, ← htop] exact μ.mono diff_subset suffices μ (⋃ n, S n) ≤ ⨆ n, μ (S n) by calc μ (s ∩ t) + μ (s \ t) = μ (s ∩ t) + μ (⋃ n, S n) := by rw [iUnion_S] _ ≤ μ (s ∩ t) + ⨆ n, μ (S n) := by gcongr _ = ⨆ n, μ (s ∩ t) + μ (S n) := ENNReal.add_iSup _ ≤ μ s := iSup_le hSs /- It suffices to show that `∑' k, μ (S (k + 1) \ S k) ≠ ∞`. Indeed, if we have this, then for all `N` we have `μ (⋃ n, S n) ≤ μ (S N) + ∑' k, m (S (N + k + 1) \ S (N + k))` and the second term tends to zero, see `OuterMeasure.iUnion_nat_of_monotone_of_tsum_ne_top` for details. -/ have : ∀ n, S n ⊆ S (n + 1) := fun n x hx => ⟨hx.1, le_trans (ENNReal.inv_le_inv.2 <| Nat.cast_le.2 n.le_succ) hx.2⟩ classical -- Porting note: Added this to get the next tactic to work refine (μ.iUnion_nat_of_monotone_of_tsum_ne_top this ?_).le; clear this /- While the sets `S (k + 1) \ S k` are not pairwise metric separated, the sets in each subsequence `S (2 * k + 1) \ S (2 * k)` and `S (2 * k + 2) \ S (2 * k)` are metric separated, so `m` is additive on each of those sequences. -/ rw [← tsum_even_add_odd ENNReal.summable ENNReal.summable, ENNReal.add_ne_top] suffices ∀ a, (∑' k : ℕ, μ (S (2 * k + 1 + a) \ S (2 * k + a))) ≠ ∞ from ⟨by simpa using this 0, by simpa using this 1⟩ refine fun r => ne_top_of_le_ne_top htop ?_ rw [← iUnion_S, ENNReal.tsum_eq_iSup_nat, iSup_le_iff] intro n rw [← hm.finset_iUnion_of_pairwise_separated] · exact μ.mono (iUnion_subset fun i => iUnion_subset fun _ x hx => mem_iUnion.2 ⟨_, hx.1⟩) suffices ∀ i j, i < j → IsMetricSeparated (S (2 * i + 1 + r)) (s \ S (2 * j + r)) from fun i _ j _ hij => hij.lt_or_lt.elim (fun h => (this i j h).mono inter_subset_left fun x hx => by exact ⟨hx.1.1, hx.2⟩) fun h => (this j i h).symm.mono (fun x hx => by exact ⟨hx.1.1, hx.2⟩) inter_subset_left intro i j hj have A : ((↑(2 * j + r))⁻¹ : ℝ≥0∞) < (↑(2 * i + 1 + r))⁻¹ := by rw [ENNReal.inv_lt_inv, Nat.cast_lt]; omega refine ⟨(↑(2 * i + 1 + r))⁻¹ - (↑(2 * j + r))⁻¹, by simpa [tsub_eq_zero_iff_le] using A, fun x hx y hy => ?_⟩ have : infEdist y t < (↑(2 * j + r))⁻¹ := not_le.1 fun hle => hy.2 ⟨hy.1, hle⟩ rcases infEdist_lt_iff.mp this with ⟨z, hzt, hyz⟩ have hxz : (↑(2 * i + 1 + r))⁻¹ ≤ edist x z := le_infEdist.1 hx.2 _ hzt apply ENNReal.le_of_add_le_add_right hyz.ne_top refine le_trans ?_ (edist_triangle _ _ _) refine (add_le_add le_rfl hyz.le).trans (Eq.trans_le ?_ hxz) rw [tsub_add_cancel_of_le A.le] #align measure_theory.outer_measure.is_metric.borel_le_caratheodory MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory theorem le_caratheodory [MeasurableSpace X] [BorelSpace X] (hm : IsMetric μ) : ‹MeasurableSpace X› ≤ μ.caratheodory := by rw [BorelSpace.measurable_eq (α := X)] exact hm.borel_le_caratheodory #align measure_theory.outer_measure.is_metric.le_caratheodory MeasureTheory.OuterMeasure.IsMetric.le_caratheodory end IsMetric /-! ### Constructors of metric outer measures In this section we provide constructors `MeasureTheory.OuterMeasure.mkMetric'` and `MeasureTheory.OuterMeasure.mkMetric` and prove that these outer measures are metric outer measures. We also prove basic lemmas about `map`/`comap` of these measures. -/ /-- Auxiliary definition for `OuterMeasure.mkMetric'`: given a function on sets `m : Set X → ℝ≥0∞`, returns the maximal outer measure `μ` such that `μ s ≤ m s` for any set `s` of diameter at most `r`. -/ def mkMetric'.pre (m : Set X → ℝ≥0∞) (r : ℝ≥0∞) : OuterMeasure X := boundedBy <| extend fun s (_ : diam s ≤ r) => m s #align measure_theory.outer_measure.mk_metric'.pre MeasureTheory.OuterMeasure.mkMetric'.pre /-- Given a function `m : Set X → ℝ≥0∞`, `mkMetric' m` is the supremum of `mkMetric'.pre m r` over `r > 0`. Equivalently, it is the limit of `mkMetric'.pre m r` as `r` tends to zero from the right. -/ def mkMetric' (m : Set X → ℝ≥0∞) : OuterMeasure X := ⨆ r > 0, mkMetric'.pre m r #align measure_theory.outer_measure.mk_metric' MeasureTheory.OuterMeasure.mkMetric' /-- Given a function `m : ℝ≥0∞ → ℝ≥0∞` and `r > 0`, let `μ r` be the maximal outer measure such that `μ s ≤ m (EMetric.diam s)` whenever `EMetric.diam s < r`. Then `mkMetric m = ⨆ r > 0, μ r`. -/ def mkMetric (m : ℝ≥0∞ → ℝ≥0∞) : OuterMeasure X := mkMetric' fun s => m (diam s) #align measure_theory.outer_measure.mk_metric MeasureTheory.OuterMeasure.mkMetric namespace mkMetric' variable {m : Set X → ℝ≥0∞} {r : ℝ≥0∞} {μ : OuterMeasure X} {s : Set X} theorem le_pre : μ ≤ pre m r ↔ ∀ s : Set X, diam s ≤ r → μ s ≤ m s := by simp only [pre, le_boundedBy, extend, le_iInf_iff] #align measure_theory.outer_measure.mk_metric'.le_pre MeasureTheory.OuterMeasure.mkMetric'.le_pre theorem pre_le (hs : diam s ≤ r) : pre m r s ≤ m s := (boundedBy_le _).trans <| iInf_le _ hs #align measure_theory.outer_measure.mk_metric'.pre_le MeasureTheory.OuterMeasure.mkMetric'.pre_le theorem mono_pre (m : Set X → ℝ≥0∞) {r r' : ℝ≥0∞} (h : r ≤ r') : pre m r' ≤ pre m r := le_pre.2 fun _ hs => pre_le (hs.trans h) #align measure_theory.outer_measure.mk_metric'.mono_pre MeasureTheory.OuterMeasure.mkMetric'.mono_pre theorem mono_pre_nat (m : Set X → ℝ≥0∞) : Monotone fun k : ℕ => pre m k⁻¹ := fun k l h => le_pre.2 fun s hs => pre_le (hs.trans <| by simpa) #align measure_theory.outer_measure.mk_metric'.mono_pre_nat MeasureTheory.OuterMeasure.mkMetric'.mono_pre_nat theorem tendsto_pre (m : Set X → ℝ≥0∞) (s : Set X) : Tendsto (fun r => pre m r s) (𝓝[>] 0) (𝓝 <| mkMetric' m s) := by rw [← map_coe_Ioi_atBot, tendsto_map'_iff] simp only [mkMetric', OuterMeasure.iSup_apply, iSup_subtype'] exact tendsto_atBot_iSup fun r r' hr => mono_pre _ hr _ #align measure_theory.outer_measure.mk_metric'.tendsto_pre MeasureTheory.OuterMeasure.mkMetric'.tendsto_pre theorem tendsto_pre_nat (m : Set X → ℝ≥0∞) (s : Set X) : Tendsto (fun n : ℕ => pre m n⁻¹ s) atTop (𝓝 <| mkMetric' m s) := by refine (tendsto_pre m s).comp (tendsto_inf.2 ⟨ENNReal.tendsto_inv_nat_nhds_zero, ?_⟩) refine tendsto_principal.2 (eventually_of_forall fun n => ?_) simp #align measure_theory.outer_measure.mk_metric'.tendsto_pre_nat MeasureTheory.OuterMeasure.mkMetric'.tendsto_pre_nat theorem eq_iSup_nat (m : Set X → ℝ≥0∞) : mkMetric' m = ⨆ n : ℕ, mkMetric'.pre m n⁻¹ := by ext1 s rw [iSup_apply] refine tendsto_nhds_unique (mkMetric'.tendsto_pre_nat m s) (tendsto_atTop_iSup fun k l hkl => mkMetric'.mono_pre_nat m hkl s) #align measure_theory.outer_measure.mk_metric'.eq_supr_nat MeasureTheory.OuterMeasure.mkMetric'.eq_iSup_nat /-- `MeasureTheory.OuterMeasure.mkMetric'.pre m r` is a trimmed measure provided that `m (closure s) = m s` for any set `s`. -/ theorem trim_pre [MeasurableSpace X] [OpensMeasurableSpace X] (m : Set X → ℝ≥0∞) (hcl : ∀ s, m (closure s) = m s) (r : ℝ≥0∞) : (pre m r).trim = pre m r := by refine le_antisymm (le_pre.2 fun s hs => ?_) (le_trim _) rw [trim_eq_iInf] refine iInf_le_of_le (closure s) <| iInf_le_of_le subset_closure <| iInf_le_of_le measurableSet_closure ((pre_le ?_).trans_eq (hcl _)) rwa [diam_closure] #align measure_theory.outer_measure.mk_metric'.trim_pre MeasureTheory.OuterMeasure.mkMetric'.trim_pre end mkMetric' /-- An outer measure constructed using `OuterMeasure.mkMetric'` is a metric outer measure. -/ theorem mkMetric'_isMetric (m : Set X → ℝ≥0∞) : (mkMetric' m).IsMetric := by rintro s t ⟨r, r0, hr⟩ refine tendsto_nhds_unique_of_eventuallyEq (mkMetric'.tendsto_pre _ _) ((mkMetric'.tendsto_pre _ _).add (mkMetric'.tendsto_pre _ _)) ?_ rw [← pos_iff_ne_zero] at r0 filter_upwards [Ioo_mem_nhdsWithin_Ioi ⟨le_rfl, r0⟩] rintro ε ⟨_, εr⟩ refine boundedBy_union_of_top_of_nonempty_inter ?_ rintro u ⟨x, hxs, hxu⟩ ⟨y, hyt, hyu⟩ have : ε < diam u := εr.trans_le ((hr x hxs y hyt).trans <| edist_le_diam_of_mem hxu hyu) exact iInf_eq_top.2 fun h => (this.not_le h).elim #align measure_theory.outer_measure.mk_metric'_is_metric MeasureTheory.OuterMeasure.mkMetric'_isMetric /-- If `c ∉ {0, ∞}` and `m₁ d ≤ c * m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ c • mkMetric m₂ hm₂`. -/ theorem mkMetric_mono_smul {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} {c : ℝ≥0∞} (hc : c ≠ ∞) (h0 : c ≠ 0) (hle : m₁ ≤ᶠ[𝓝[≥] 0] c • m₂) : (mkMetric m₁ : OuterMeasure X) ≤ c • mkMetric m₂ := by classical rcases (mem_nhdsWithin_Ici_iff_exists_Ico_subset' zero_lt_one).1 hle with ⟨r, hr0, hr⟩ refine fun s => le_of_tendsto_of_tendsto (mkMetric'.tendsto_pre _ s) (ENNReal.Tendsto.const_mul (mkMetric'.tendsto_pre _ s) (Or.inr hc)) (mem_of_superset (Ioo_mem_nhdsWithin_Ioi ⟨le_rfl, hr0⟩) fun r' hr' => ?_) simp only [mem_setOf_eq, mkMetric'.pre, RingHom.id_apply] rw [← smul_eq_mul, ← smul_apply, smul_boundedBy hc] refine le_boundedBy.2 (fun t => (boundedBy_le _).trans ?_) _ simp only [smul_eq_mul, Pi.smul_apply, extend, iInf_eq_if] split_ifs with ht · apply hr exact ⟨zero_le _, ht.trans_lt hr'.2⟩ · simp [h0] #align measure_theory.outer_measure.mk_metric_mono_smul MeasureTheory.OuterMeasure.mkMetric_mono_smul @[simp] theorem mkMetric_top : (mkMetric (fun _ => ∞ : ℝ≥0∞ → ℝ≥0∞) : OuterMeasure X) = ⊤ := by simp_rw [mkMetric, mkMetric', mkMetric'.pre, extend_top, boundedBy_top, eq_top_iff] rw [le_iSup_iff] intro b hb simpa using hb ⊤ #align measure_theory.outer_measure.mk_metric_top MeasureTheory.OuterMeasure.mkMetric_top /-- If `m₁ d ≤ m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ mkMetric m₂ hm₂`. -/ theorem mkMetric_mono {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} (hle : m₁ ≤ᶠ[𝓝[≥] 0] m₂) : (mkMetric m₁ : OuterMeasure X) ≤ mkMetric m₂ := by convert @mkMetric_mono_smul X _ _ m₂ _ ENNReal.one_ne_top one_ne_zero _ <;> simp [*] #align measure_theory.outer_measure.mk_metric_mono MeasureTheory.OuterMeasure.mkMetric_mono theorem isometry_comap_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) {f : X → Y} (hf : Isometry f) (H : Monotone m ∨ Surjective f) : comap f (mkMetric m) = mkMetric m := by simp only [mkMetric, mkMetric', mkMetric'.pre, inducedOuterMeasure, comap_iSup] refine surjective_id.iSup_congr id fun ε => surjective_id.iSup_congr id fun hε => ?_ rw [comap_boundedBy _ (H.imp _ id)] · congr with s : 1 apply extend_congr · simp [hf.ediam_image] · intros; simp [hf.injective.subsingleton_image_iff, hf.ediam_image] · intro h_mono s t hst simp only [extend, le_iInf_iff] intro ht apply le_trans _ (h_mono (diam_mono hst)) simp only [(diam_mono hst).trans ht, le_refl, ciInf_pos] #align measure_theory.outer_measure.isometry_comap_mk_metric MeasureTheory.OuterMeasure.isometry_comap_mkMetric
Mathlib/MeasureTheory/Measure/Hausdorff.lean
385
388
theorem mkMetric_smul (m : ℝ≥0∞ → ℝ≥0∞) {c : ℝ≥0∞} (hc : c ≠ ∞) (hc' : c ≠ 0) : (mkMetric (c • m) : OuterMeasure X) = c • mkMetric m := by
simp only [mkMetric, mkMetric', mkMetric'.pre, inducedOuterMeasure, ENNReal.smul_iSup] simp_rw [smul_iSup, smul_boundedBy hc, smul_extend _ hc', Pi.smul_apply]
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Kexing Ying -/ import Mathlib.Probability.Notation import Mathlib.Probability.Integration import Mathlib.MeasureTheory.Function.L2Space #align_import probability.variance from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Variance of random variables We define the variance of a real-valued random variable as `Var[X] = 𝔼[(X - 𝔼[X])^2]` (in the `ProbabilityTheory` locale). ## Main definitions * `ProbabilityTheory.evariance`: the variance of a real-valued random variable as an extended non-negative real. * `ProbabilityTheory.variance`: the variance of a real-valued random variable as a real number. ## Main results * `ProbabilityTheory.variance_le_expectation_sq`: the inequality `Var[X] ≤ 𝔼[X^2]`. * `ProbabilityTheory.meas_ge_le_variance_div_sq`: Chebyshev's inequality, i.e., `ℙ {ω | c ≤ |X ω - 𝔼[X]|} ≤ ENNReal.ofReal (Var[X] / c ^ 2)`. * `ProbabilityTheory.meas_ge_le_evariance_div_sq`: Chebyshev's inequality formulated with `evariance` without requiring the random variables to be L². * `ProbabilityTheory.IndepFun.variance_add`: the variance of the sum of two independent random variables is the sum of the variances. * `ProbabilityTheory.IndepFun.variance_sum`: the variance of a finite sum of pairwise independent random variables is the sum of the variances. -/ open MeasureTheory Filter Finset noncomputable section open scoped MeasureTheory ProbabilityTheory ENNReal NNReal namespace ProbabilityTheory -- Porting note: this lemma replaces `ENNReal.toReal_bit0`, which does not exist in Lean 4 private lemma coe_two : ENNReal.toReal 2 = (2 : ℝ) := rfl -- Porting note: Consider if `evariance` or `eVariance` is better. Also, -- consider `eVariationOn` in `Mathlib.Analysis.BoundedVariation`. /-- The `ℝ≥0∞`-valued variance of a real-valued random variable defined as the Lebesgue integral of `(X - 𝔼[X])^2`. -/ def evariance {Ω : Type*} {_ : MeasurableSpace Ω} (X : Ω → ℝ) (μ : Measure Ω) : ℝ≥0∞ := ∫⁻ ω, (‖X ω - μ[X]‖₊ : ℝ≥0∞) ^ 2 ∂μ #align probability_theory.evariance ProbabilityTheory.evariance /-- The `ℝ`-valued variance of a real-valued random variable defined by applying `ENNReal.toReal` to `evariance`. -/ def variance {Ω : Type*} {_ : MeasurableSpace Ω} (X : Ω → ℝ) (μ : Measure Ω) : ℝ := (evariance X μ).toReal #align probability_theory.variance ProbabilityTheory.variance variable {Ω : Type*} {m : MeasurableSpace Ω} {X : Ω → ℝ} {μ : Measure Ω} theorem _root_.MeasureTheory.Memℒp.evariance_lt_top [IsFiniteMeasure μ] (hX : Memℒp X 2 μ) : evariance X μ < ∞ := by have := ENNReal.pow_lt_top (hX.sub <| memℒp_const <| μ[X]).2 2 rw [snorm_eq_lintegral_rpow_nnnorm two_ne_zero ENNReal.two_ne_top, ← ENNReal.rpow_two] at this simp only [coe_two, Pi.sub_apply, ENNReal.one_toReal, one_div] at this rw [← ENNReal.rpow_mul, inv_mul_cancel (two_ne_zero : (2 : ℝ) ≠ 0), ENNReal.rpow_one] at this simp_rw [ENNReal.rpow_two] at this exact this #align measure_theory.mem_ℒp.evariance_lt_top MeasureTheory.Memℒp.evariance_lt_top theorem evariance_eq_top [IsFiniteMeasure μ] (hXm : AEStronglyMeasurable X μ) (hX : ¬Memℒp X 2 μ) : evariance X μ = ∞ := by by_contra h rw [← Ne, ← lt_top_iff_ne_top] at h have : Memℒp (fun ω => X ω - μ[X]) 2 μ := by refine ⟨hXm.sub aestronglyMeasurable_const, ?_⟩ rw [snorm_eq_lintegral_rpow_nnnorm two_ne_zero ENNReal.two_ne_top] simp only [coe_two, ENNReal.one_toReal, ENNReal.rpow_two, Ne] exact ENNReal.rpow_lt_top_of_nonneg (by linarith) h.ne refine hX ?_ -- Porting note: `μ[X]` without whitespace is ambiguous as it could be GetElem, -- and `convert` cannot disambiguate based on typeclass inference failure. convert this.add (memℒp_const <| μ [X]) ext ω rw [Pi.add_apply, sub_add_cancel] #align probability_theory.evariance_eq_top ProbabilityTheory.evariance_eq_top theorem evariance_lt_top_iff_memℒp [IsFiniteMeasure μ] (hX : AEStronglyMeasurable X μ) : evariance X μ < ∞ ↔ Memℒp X 2 μ := by refine ⟨?_, MeasureTheory.Memℒp.evariance_lt_top⟩ contrapose rw [not_lt, top_le_iff] exact evariance_eq_top hX #align probability_theory.evariance_lt_top_iff_mem_ℒp ProbabilityTheory.evariance_lt_top_iff_memℒp theorem _root_.MeasureTheory.Memℒp.ofReal_variance_eq [IsFiniteMeasure μ] (hX : Memℒp X 2 μ) : ENNReal.ofReal (variance X μ) = evariance X μ := by rw [variance, ENNReal.ofReal_toReal] exact hX.evariance_lt_top.ne #align measure_theory.mem_ℒp.of_real_variance_eq MeasureTheory.Memℒp.ofReal_variance_eq theorem evariance_eq_lintegral_ofReal (X : Ω → ℝ) (μ : Measure Ω) : evariance X μ = ∫⁻ ω, ENNReal.ofReal ((X ω - μ[X]) ^ 2) ∂μ := by rw [evariance] congr ext1 ω rw [pow_two, ← ENNReal.coe_mul, ← nnnorm_mul, ← pow_two] congr exact (Real.toNNReal_eq_nnnorm_of_nonneg <| sq_nonneg _).symm #align probability_theory.evariance_eq_lintegral_of_real ProbabilityTheory.evariance_eq_lintegral_ofReal theorem _root_.MeasureTheory.Memℒp.variance_eq_of_integral_eq_zero (hX : Memℒp X 2 μ) (hXint : μ[X] = 0) : variance X μ = μ[X ^ (2 : Nat)] := by rw [variance, evariance_eq_lintegral_ofReal, ← ofReal_integral_eq_lintegral_ofReal, ENNReal.toReal_ofReal (by positivity)] <;> simp_rw [hXint, sub_zero] · rfl · convert hX.integrable_norm_rpow two_ne_zero ENNReal.two_ne_top with ω simp only [Pi.sub_apply, Real.norm_eq_abs, coe_two, ENNReal.one_toReal, Real.rpow_two, sq_abs, abs_pow] · exact ae_of_all _ fun ω => pow_two_nonneg _ #align measure_theory.mem_ℒp.variance_eq_of_integral_eq_zero MeasureTheory.Memℒp.variance_eq_of_integral_eq_zero theorem _root_.MeasureTheory.Memℒp.variance_eq [IsFiniteMeasure μ] (hX : Memℒp X 2 μ) : variance X μ = μ[(X - fun _ => μ[X] :) ^ (2 : Nat)] := by rw [variance, evariance_eq_lintegral_ofReal, ← ofReal_integral_eq_lintegral_ofReal, ENNReal.toReal_ofReal (by positivity)] · rfl · -- Porting note: `μ[X]` without whitespace is ambiguous as it could be GetElem, -- and `convert` cannot disambiguate based on typeclass inference failure. convert (hX.sub <| memℒp_const (μ [X])).integrable_norm_rpow two_ne_zero ENNReal.two_ne_top with ω simp only [Pi.sub_apply, Real.norm_eq_abs, coe_two, ENNReal.one_toReal, Real.rpow_two, sq_abs, abs_pow] · exact ae_of_all _ fun ω => pow_two_nonneg _ #align measure_theory.mem_ℒp.variance_eq MeasureTheory.Memℒp.variance_eq @[simp] theorem evariance_zero : evariance 0 μ = 0 := by simp [evariance] #align probability_theory.evariance_zero ProbabilityTheory.evariance_zero theorem evariance_eq_zero_iff (hX : AEMeasurable X μ) : evariance X μ = 0 ↔ X =ᵐ[μ] fun _ => μ[X] := by rw [evariance, lintegral_eq_zero_iff'] constructor <;> intro hX <;> filter_upwards [hX] with ω hω · simpa only [Pi.zero_apply, sq_eq_zero_iff, ENNReal.coe_eq_zero, nnnorm_eq_zero, sub_eq_zero] using hω · rw [hω] simp · exact (hX.sub_const _).ennnorm.pow_const _ -- TODO `measurability` and `fun_prop` fail #align probability_theory.evariance_eq_zero_iff ProbabilityTheory.evariance_eq_zero_iff theorem evariance_mul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) : evariance (fun ω => c * X ω) μ = ENNReal.ofReal (c ^ 2) * evariance X μ := by rw [evariance, evariance, ← lintegral_const_mul' _ _ ENNReal.ofReal_lt_top.ne] congr ext1 ω rw [ENNReal.ofReal, ← ENNReal.coe_pow, ← ENNReal.coe_pow, ← ENNReal.coe_mul] congr rw [← sq_abs, ← Real.rpow_two, Real.toNNReal_rpow_of_nonneg (abs_nonneg _), NNReal.rpow_two, ← mul_pow, Real.toNNReal_mul_nnnorm _ (abs_nonneg _)] conv_rhs => rw [← nnnorm_norm, norm_mul, norm_abs_eq_norm, ← norm_mul, nnnorm_norm, mul_sub] congr rw [mul_comm] simp_rw [← smul_eq_mul, ← integral_smul_const, smul_eq_mul, mul_comm] #align probability_theory.evariance_mul ProbabilityTheory.evariance_mul scoped notation "eVar[" X "]" => ProbabilityTheory.evariance X MeasureTheory.MeasureSpace.volume @[simp] theorem variance_zero (μ : Measure Ω) : variance 0 μ = 0 := by simp only [variance, evariance_zero, ENNReal.zero_toReal] #align probability_theory.variance_zero ProbabilityTheory.variance_zero theorem variance_nonneg (X : Ω → ℝ) (μ : Measure Ω) : 0 ≤ variance X μ := ENNReal.toReal_nonneg #align probability_theory.variance_nonneg ProbabilityTheory.variance_nonneg theorem variance_mul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) : variance (fun ω => c * X ω) μ = c ^ 2 * variance X μ := by rw [variance, evariance_mul, ENNReal.toReal_mul, ENNReal.toReal_ofReal (sq_nonneg _)] rfl #align probability_theory.variance_mul ProbabilityTheory.variance_mul theorem variance_smul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) : variance (c • X) μ = c ^ 2 * variance X μ := variance_mul c X μ #align probability_theory.variance_smul ProbabilityTheory.variance_smul theorem variance_smul' {A : Type*} [CommSemiring A] [Algebra A ℝ] (c : A) (X : Ω → ℝ) (μ : Measure Ω) : variance (c • X) μ = c ^ 2 • variance X μ := by convert variance_smul (algebraMap A ℝ c) X μ using 1 · congr; simp only [algebraMap_smul] · simp only [Algebra.smul_def, map_pow] #align probability_theory.variance_smul' ProbabilityTheory.variance_smul' scoped notation "Var[" X "]" => ProbabilityTheory.variance X MeasureTheory.MeasureSpace.volume variable [MeasureSpace Ω] theorem variance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : Memℒp X 2) : Var[X] = 𝔼[X ^ 2] - 𝔼[X] ^ 2 := by rw [hX.variance_eq, sub_sq', integral_sub', integral_add']; rotate_left · exact hX.integrable_sq · convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2) · apply hX.integrable_sq.add convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2) · exact ((hX.integrable one_le_two).const_mul 2).mul_const' _ simp only [Pi.pow_apply, integral_const, measure_univ, ENNReal.one_toReal, smul_eq_mul, one_mul, Pi.mul_apply, Pi.ofNat_apply, Nat.cast_ofNat, integral_mul_right, integral_mul_left] ring #align probability_theory.variance_def' ProbabilityTheory.variance_def' theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by by_cases hX : Memℒp X 2 · rw [variance_def' hX] simp only [sq_nonneg, sub_le_self_iff] rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae] · by_cases hint : Integrable X; swap · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero] exact le_rfl · rw [integral_undef] · exact integral_nonneg fun a => sq_nonneg _ intro h have A : Memℒp (X - fun ω : Ω => 𝔼[X]) 2 ℙ := (memℒp_two_iff_integrable_sq (hint.aestronglyMeasurable.sub aestronglyMeasurable_const)).2 h have B : Memℒp (fun _ : Ω => 𝔼[X]) 2 ℙ := memℒp_const _ apply hX convert A.add B simp · exact eventually_of_forall fun x => sq_nonneg _ · exact (AEMeasurable.pow_const (hm.aemeasurable.sub_const _) _).aestronglyMeasurable #align probability_theory.variance_le_expectation_sq ProbabilityTheory.variance_le_expectation_sq theorem evariance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : AEStronglyMeasurable X ℙ) : eVar[X] = (∫⁻ ω, (‖X ω‖₊ ^ 2 :)) - ENNReal.ofReal (𝔼[X] ^ 2) := by by_cases hℒ : Memℒp X 2 · rw [← hℒ.ofReal_variance_eq, variance_def' hℒ, ENNReal.ofReal_sub _ (sq_nonneg _)] congr rw [lintegral_coe_eq_integral] · congr 2 with ω simp only [Pi.pow_apply, NNReal.coe_pow, coe_nnnorm, Real.norm_eq_abs, Even.pow_abs even_two] · exact hℒ.abs.integrable_sq · symm rw [evariance_eq_top hX hℒ, ENNReal.sub_eq_top_iff] refine ⟨?_, ENNReal.ofReal_ne_top⟩ rw [Memℒp, not_and] at hℒ specialize hℒ hX simp only [snorm_eq_lintegral_rpow_nnnorm two_ne_zero ENNReal.two_ne_top, not_lt, top_le_iff, coe_two, one_div, ENNReal.rpow_eq_top_iff, inv_lt_zero, inv_pos, and_true_iff, or_iff_not_imp_left, not_and_or, zero_lt_two] at hℒ exact mod_cast hℒ fun _ => zero_le_two #align probability_theory.evariance_def' ProbabilityTheory.evariance_def' /-- **Chebyshev's inequality** for `ℝ≥0∞`-valued variance. -/ theorem meas_ge_le_evariance_div_sq {X : Ω → ℝ} (hX : AEStronglyMeasurable X ℙ) {c : ℝ≥0} (hc : c ≠ 0) : ℙ {ω | ↑c ≤ |X ω - 𝔼[X]|} ≤ eVar[X] / c ^ 2 := by have A : (c : ℝ≥0∞) ≠ 0 := by rwa [Ne, ENNReal.coe_eq_zero] have B : AEStronglyMeasurable (fun _ : Ω => 𝔼[X]) ℙ := aestronglyMeasurable_const convert meas_ge_le_mul_pow_snorm ℙ two_ne_zero ENNReal.two_ne_top (hX.sub B) A using 1 · congr simp only [Pi.sub_apply, ENNReal.coe_le_coe, ← Real.norm_eq_abs, ← coe_nnnorm, NNReal.coe_le_coe, ENNReal.ofReal_coe_nnreal] · rw [snorm_eq_lintegral_rpow_nnnorm two_ne_zero ENNReal.two_ne_top] simp only [show ENNReal.ofNNReal (c ^ 2) = (ENNReal.ofNNReal c) ^ 2 by norm_cast, coe_two, one_div, Pi.sub_apply] rw [div_eq_mul_inv, ENNReal.inv_pow, mul_comm, ENNReal.rpow_two] congr simp_rw [← ENNReal.rpow_mul, inv_mul_cancel (two_ne_zero : (2 : ℝ) ≠ 0), ENNReal.rpow_two, ENNReal.rpow_one, evariance] #align probability_theory.meas_ge_le_evariance_div_sq ProbabilityTheory.meas_ge_le_evariance_div_sq /-- **Chebyshev's inequality**: one can control the deviation probability of a real random variable from its expectation in terms of the variance. -/ theorem meas_ge_le_variance_div_sq [@IsFiniteMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : Memℒp X 2) {c : ℝ} (hc : 0 < c) : ℙ {ω | c ≤ |X ω - 𝔼[X]|} ≤ ENNReal.ofReal (Var[X] / c ^ 2) := by rw [ENNReal.ofReal_div_of_pos (sq_pos_of_ne_zero hc.ne.symm), hX.ofReal_variance_eq] convert @meas_ge_le_evariance_div_sq _ _ _ hX.1 c.toNNReal (by simp [hc]) using 1 · simp only [Real.coe_toNNReal', max_le_iff, abs_nonneg, and_true_iff] · rw [ENNReal.ofReal_pow hc.le] rfl #align probability_theory.meas_ge_le_variance_div_sq ProbabilityTheory.meas_ge_le_variance_div_sq -- Porting note: supplied `MeasurableSpace Ω` argument of `h` by unification /-- The variance of the sum of two independent random variables is the sum of the variances. -/ theorem IndepFun.variance_add [@IsProbabilityMeasure Ω _ ℙ] {X Y : Ω → ℝ} (hX : Memℒp X 2) (hY : Memℒp Y 2) (h : @IndepFun _ _ _ (_) _ _ X Y ℙ) : Var[X + Y] = Var[X] + Var[Y] := calc Var[X + Y] = 𝔼[fun a => X a ^ 2 + Y a ^ 2 + 2 * X a * Y a] - 𝔼[X + Y] ^ 2 := by simp [variance_def' (hX.add hY), add_sq'] _ = 𝔼[X ^ 2] + 𝔼[Y ^ 2] + (2 : ℝ) * 𝔼[X * Y] - (𝔼[X] + 𝔼[Y]) ^ 2 := by simp only [Pi.add_apply, Pi.pow_apply, Pi.mul_apply, mul_assoc] rw [integral_add, integral_add, integral_add, integral_mul_left] · exact hX.integrable one_le_two · exact hY.integrable one_le_two · exact hX.integrable_sq · exact hY.integrable_sq · exact hX.integrable_sq.add hY.integrable_sq · apply Integrable.const_mul exact h.integrable_mul (hX.integrable one_le_two) (hY.integrable one_le_two) _ = 𝔼[X ^ 2] + 𝔼[Y ^ 2] + 2 * (𝔼[X] * 𝔼[Y]) - (𝔼[X] + 𝔼[Y]) ^ 2 := by congr exact h.integral_mul_of_integrable (hX.integrable one_le_two) (hY.integrable one_le_two) _ = Var[X] + Var[Y] := by simp only [variance_def', hX, hY, Pi.pow_apply]; ring #align probability_theory.indep_fun.variance_add ProbabilityTheory.IndepFun.variance_add -- Porting note: supplied `MeasurableSpace Ω` argument of `hs`, `h` by unification /-- The variance of a finite sum of pairwise independent random variables is the sum of the variances. -/
Mathlib/Probability/Variance.lean
315
372
theorem IndepFun.variance_sum [@IsProbabilityMeasure Ω _ ℙ] {ι : Type*} {X : ι → Ω → ℝ} {s : Finset ι} (hs : ∀ i ∈ s, @Memℒp _ _ _ (_) (X i) 2 ℙ) (h : Set.Pairwise ↑s fun i j => @IndepFun _ _ _ (_) _ _ (X i) (X j) ℙ) : Var[∑ i ∈ s, X i] = ∑ i ∈ s, Var[X i] := by
classical induction' s using Finset.induction_on with k s ks IH · simp only [Finset.sum_empty, variance_zero] rw [variance_def' (memℒp_finset_sum' _ hs), sum_insert ks, sum_insert ks] simp only [add_sq'] calc 𝔼[X k ^ 2 + (∑ i ∈ s, X i) ^ 2 + 2 * X k * ∑ i ∈ s, X i] - 𝔼[X k + ∑ i ∈ s, X i] ^ 2 = 𝔼[X k ^ 2] + 𝔼[(∑ i ∈ s, X i) ^ 2] + 𝔼[2 * X k * ∑ i ∈ s, X i] - (𝔼[X k] + 𝔼[∑ i ∈ s, X i]) ^ 2 := by rw [integral_add', integral_add', integral_add'] · exact Memℒp.integrable one_le_two (hs _ (mem_insert_self _ _)) · apply integrable_finset_sum' _ fun i hi => ?_ exact Memℒp.integrable one_le_two (hs _ (mem_insert_of_mem hi)) · exact Memℒp.integrable_sq (hs _ (mem_insert_self _ _)) · apply Memℒp.integrable_sq exact memℒp_finset_sum' _ fun i hi => hs _ (mem_insert_of_mem hi) · apply Integrable.add · exact Memℒp.integrable_sq (hs _ (mem_insert_self _ _)) · apply Memℒp.integrable_sq exact memℒp_finset_sum' _ fun i hi => hs _ (mem_insert_of_mem hi) · rw [mul_assoc] apply Integrable.const_mul _ (2 : ℝ) simp only [mul_sum, sum_apply, Pi.mul_apply] apply integrable_finset_sum _ fun i hi => ?_ apply IndepFun.integrable_mul _ (Memℒp.integrable one_le_two (hs _ (mem_insert_self _ _))) (Memℒp.integrable one_le_two (hs _ (mem_insert_of_mem hi))) apply h (mem_insert_self _ _) (mem_insert_of_mem hi) exact fun hki => ks (hki.symm ▸ hi) _ = Var[X k] + Var[∑ i ∈ s, X i] + (𝔼[2 * X k * ∑ i ∈ s, X i] - 2 * 𝔼[X k] * 𝔼[∑ i ∈ s, X i]) := by rw [variance_def' (hs _ (mem_insert_self _ _)), variance_def' (memℒp_finset_sum' _ fun i hi => hs _ (mem_insert_of_mem hi))] ring _ = Var[X k] + Var[∑ i ∈ s, X i] := by simp_rw [Pi.mul_apply, Pi.ofNat_apply, Nat.cast_ofNat, sum_apply, mul_sum, mul_assoc, add_right_eq_self] rw [integral_finset_sum s fun i hi => ?_]; swap · apply Integrable.const_mul _ (2 : ℝ) apply IndepFun.integrable_mul _ (Memℒp.integrable one_le_two (hs _ (mem_insert_self _ _))) (Memℒp.integrable one_le_two (hs _ (mem_insert_of_mem hi))) apply h (mem_insert_self _ _) (mem_insert_of_mem hi) exact fun hki => ks (hki.symm ▸ hi) rw [integral_finset_sum s fun i hi => Memℒp.integrable one_le_two (hs _ (mem_insert_of_mem hi)), mul_sum, mul_sum, ← sum_sub_distrib] apply Finset.sum_eq_zero fun i hi => ?_ rw [integral_mul_left, IndepFun.integral_mul', sub_self] · apply h (mem_insert_self _ _) (mem_insert_of_mem hi) exact fun hki => ks (hki.symm ▸ hi) · exact Memℒp.aestronglyMeasurable (hs _ (mem_insert_self _ _)) · exact Memℒp.aestronglyMeasurable (hs _ (mem_insert_of_mem hi)) _ = Var[X k] + ∑ i ∈ s, Var[X i] := by rw [IH (fun i hi => hs i (mem_insert_of_mem hi)) (h.mono (by simp only [coe_insert, Set.subset_insert]))]
/- Copyright (c) 2022 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer -/ import Mathlib.CategoryTheory.Preadditive.Yoneda.Projective import Mathlib.CategoryTheory.Preadditive.Yoneda.Limits import Mathlib.Algebra.Category.ModuleCat.EpiMono /-! # Projective objects in abelian categories In an abelian category, an object `P` is projective iff the functor `preadditiveCoyonedaObj (op P)` preserves finite colimits. -/ universe v u namespace CategoryTheory open Limits Projective Opposite variable {C : Type u} [Category.{v} C] [Abelian C] /-- The preadditive Co-Yoneda functor on `P` preserves finite colimits if `P` is projective. -/ noncomputable def preservesFiniteColimitsPreadditiveCoyonedaObjOfProjective (P : C) [hP : Projective P] : PreservesFiniteColimits (preadditiveCoyonedaObj (op P)) := by haveI := (projective_iff_preservesEpimorphisms_preadditiveCoyoneda_obj' P).mp hP -- Porting note: this next instance wasn't necessary in Lean 3 haveI := @Functor.preservesEpimorphisms_of_preserves_of_reflects _ _ _ _ _ _ _ _ this _ apply Functor.preservesFiniteColimitsOfPreservesEpisAndKernels #align category_theory.preserves_finite_colimits_preadditive_coyoneda_obj_of_projective CategoryTheory.preservesFiniteColimitsPreadditiveCoyonedaObjOfProjective /-- An object is projective if its preadditive Co-Yoneda functor preserves finite colimits. -/
Mathlib/CategoryTheory/Abelian/Projective.lean
37
42
theorem projective_of_preservesFiniteColimits_preadditiveCoyonedaObj (P : C) [hP : PreservesFiniteColimits (preadditiveCoyonedaObj (op P))] : Projective P := by
rw [projective_iff_preservesEpimorphisms_preadditiveCoyoneda_obj'] -- Porting note: this next line wasn't necessary in Lean 3 dsimp only [preadditiveCoyoneda] infer_instance
/- Copyright (c) 2021 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Data.Matrix.Basis import Mathlib.Data.Matrix.DMatrix import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.Tactic.FieldSimp #align_import linear_algebra.matrix.transvection from "leanprover-community/mathlib"@"0e2aab2b0d521f060f62a14d2cf2e2c54e8491d6" /-! # Transvections Transvections are matrices of the form `1 + StdBasisMatrix i j c`, where `StdBasisMatrix i j c` is the basic matrix with a `c` at position `(i, j)`. Multiplying by such a transvection on the left (resp. on the right) amounts to adding `c` times the `j`-th row to the `i`-th row (resp `c` times the `i`-th column to the `j`-th column). Therefore, they are useful to present algorithms operating on rows and columns. Transvections are a special case of *elementary matrices* (according to most references, these also contain the matrices exchanging rows, and the matrices multiplying a row by a constant). We show that, over a field, any matrix can be written as `L * D * L'`, where `L` and `L'` are products of transvections and `D` is diagonal. In other words, one can reduce a matrix to diagonal form by operations on its rows and columns, a variant of Gauss' pivot algorithm. ## Main definitions and results * `Transvection i j c` is the matrix equal to `1 + StdBasisMatrix i j c`. * `TransvectionStruct n R` is a structure containing the data of `i, j, c` and a proof that `i ≠ j`. These are often easier to manipulate than straight matrices, especially in inductive arguments. * `exists_list_transvec_mul_diagonal_mul_list_transvec` states that any matrix `M` over a field can be written in the form `t_1 * ... * t_k * D * t'_1 * ... * t'_l`, where `D` is diagonal and the `t_i`, `t'_j` are transvections. * `diagonal_transvection_induction` shows that a property which is true for diagonal matrices and transvections, and invariant under product, is true for all matrices. * `diagonal_transvection_induction_of_det_ne_zero` is the same statement over invertible matrices. ## Implementation details The proof of the reduction results is done inductively on the size of the matrices, reducing an `(r + 1) × (r + 1)` matrix to a matrix whose last row and column are zeroes, except possibly for the last diagonal entry. This step is done as follows. If all the coefficients on the last row and column are zero, there is nothing to do. Otherwise, one can put a nonzero coefficient in the last diagonal entry by a row or column operation, and then subtract this last diagonal entry from the other entries in the last row and column to make them vanish. This step is done in the type `Fin r ⊕ Unit`, where `Fin r` is useful to choose arbitrarily some order in which we cancel the coefficients, and the sum structure is useful to use the formalism of block matrices. To proceed with the induction, we reindex our matrices to reduce to the above situation. -/ universe u₁ u₂ namespace Matrix open Matrix variable (n p : Type*) (R : Type u₂) {𝕜 : Type*} [Field 𝕜] variable [DecidableEq n] [DecidableEq p] variable [CommRing R] section Transvection variable {R n} (i j : n) /-- The transvection matrix `Transvection i j c` is equal to the identity plus `c` at position `(i, j)`. Multiplying by it on the left (as in `Transvection i j c * M`) corresponds to adding `c` times the `j`-th line of `M` to its `i`-th line. Multiplying by it on the right corresponds to adding `c` times the `i`-th column to the `j`-th column. -/ def transvection (c : R) : Matrix n n R := 1 + Matrix.stdBasisMatrix i j c #align matrix.transvection Matrix.transvection @[simp]
Mathlib/LinearAlgebra/Matrix/Transvection.lean
87
87
theorem transvection_zero : transvection i j (0 : R) = 1 := by
simp [transvection]
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Finset.Prod import Mathlib.Data.Set.Finite #align_import data.finset.n_ary from "leanprover-community/mathlib"@"eba7871095e834365616b5e43c8c7bb0b37058d0" /-! # N-ary images of finsets This file defines `Finset.image₂`, the binary image of finsets. This is the finset version of `Set.image2`. This is mostly useful to define pointwise operations. ## Notes This file is very similar to `Data.Set.NAry`, `Order.Filter.NAry` and `Data.Option.NAry`. Please keep them in sync. We do not define `Finset.image₃` as its only purpose would be to prove properties of `Finset.image₂` and `Set.image2` already fulfills this task. -/ open Function Set variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*} namespace Finset variable [DecidableEq α'] [DecidableEq β'] [DecidableEq γ] [DecidableEq γ'] [DecidableEq δ] [DecidableEq δ'] [DecidableEq ε] [DecidableEq ε'] {f f' : α → β → γ} {g g' : α → β → γ → δ} {s s' : Finset α} {t t' : Finset β} {u u' : Finset γ} {a a' : α} {b b' : β} {c : γ} /-- The image of a binary function `f : α → β → γ` as a function `Finset α → Finset β → Finset γ`. Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/ def image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) : Finset γ := (s ×ˢ t).image <| uncurry f #align finset.image₂ Finset.image₂ @[simp] theorem mem_image₂ : c ∈ image₂ f s t ↔ ∃ a ∈ s, ∃ b ∈ t, f a b = c := by simp [image₂, and_assoc] #align finset.mem_image₂ Finset.mem_image₂ @[simp, norm_cast] theorem coe_image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) : (image₂ f s t : Set γ) = Set.image2 f s t := Set.ext fun _ => mem_image₂ #align finset.coe_image₂ Finset.coe_image₂ theorem card_image₂_le (f : α → β → γ) (s : Finset α) (t : Finset β) : (image₂ f s t).card ≤ s.card * t.card := card_image_le.trans_eq <| card_product _ _ #align finset.card_image₂_le Finset.card_image₂_le theorem card_image₂_iff : (image₂ f s t).card = s.card * t.card ↔ (s ×ˢ t : Set (α × β)).InjOn fun x => f x.1 x.2 := by rw [← card_product, ← coe_product] exact card_image_iff #align finset.card_image₂_iff Finset.card_image₂_iff theorem card_image₂ (hf : Injective2 f) (s : Finset α) (t : Finset β) : (image₂ f s t).card = s.card * t.card := (card_image_of_injective _ hf.uncurry).trans <| card_product _ _ #align finset.card_image₂ Finset.card_image₂ theorem mem_image₂_of_mem (ha : a ∈ s) (hb : b ∈ t) : f a b ∈ image₂ f s t := mem_image₂.2 ⟨a, ha, b, hb, rfl⟩ #align finset.mem_image₂_of_mem Finset.mem_image₂_of_mem theorem mem_image₂_iff (hf : Injective2 f) : f a b ∈ image₂ f s t ↔ a ∈ s ∧ b ∈ t := by rw [← mem_coe, coe_image₂, mem_image2_iff hf, mem_coe, mem_coe] #align finset.mem_image₂_iff Finset.mem_image₂_iff theorem image₂_subset (hs : s ⊆ s') (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s' t' := by rw [← coe_subset, coe_image₂, coe_image₂] exact image2_subset hs ht #align finset.image₂_subset Finset.image₂_subset theorem image₂_subset_left (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s t' := image₂_subset Subset.rfl ht #align finset.image₂_subset_left Finset.image₂_subset_left theorem image₂_subset_right (hs : s ⊆ s') : image₂ f s t ⊆ image₂ f s' t := image₂_subset hs Subset.rfl #align finset.image₂_subset_right Finset.image₂_subset_right theorem image_subset_image₂_left (hb : b ∈ t) : s.image (fun a => f a b) ⊆ image₂ f s t := image_subset_iff.2 fun _ ha => mem_image₂_of_mem ha hb #align finset.image_subset_image₂_left Finset.image_subset_image₂_left theorem image_subset_image₂_right (ha : a ∈ s) : t.image (fun b => f a b) ⊆ image₂ f s t := image_subset_iff.2 fun _ => mem_image₂_of_mem ha #align finset.image_subset_image₂_right Finset.image_subset_image₂_right theorem forall_image₂_iff {p : γ → Prop} : (∀ z ∈ image₂ f s t, p z) ↔ ∀ x ∈ s, ∀ y ∈ t, p (f x y) := by simp_rw [← mem_coe, coe_image₂, forall_image2_iff] #align finset.forall_image₂_iff Finset.forall_image₂_iff @[simp] theorem image₂_subset_iff : image₂ f s t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, f x y ∈ u := forall_image₂_iff #align finset.image₂_subset_iff Finset.image₂_subset_iff theorem image₂_subset_iff_left : image₂ f s t ⊆ u ↔ ∀ a ∈ s, (t.image fun b => f a b) ⊆ u := by simp_rw [image₂_subset_iff, image_subset_iff] #align finset.image₂_subset_iff_left Finset.image₂_subset_iff_left theorem image₂_subset_iff_right : image₂ f s t ⊆ u ↔ ∀ b ∈ t, (s.image fun a => f a b) ⊆ u := by simp_rw [image₂_subset_iff, image_subset_iff, @forall₂_swap α] #align finset.image₂_subset_iff_right Finset.image₂_subset_iff_right @[simp, aesop safe apply (rule_sets := [finsetNonempty])]
Mathlib/Data/Finset/NAry.lean
117
119
theorem image₂_nonempty_iff : (image₂ f s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := by
rw [← coe_nonempty, coe_image₂] exact image2_nonempty_iff
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Oliver Nash -/ import Mathlib.Data.Finset.Card #align_import data.finset.prod from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Finsets in product types This file defines finset constructions on the product type `α × β`. Beware not to confuse with the `Finset.prod` operation which computes the multiplicative product. ## Main declarations * `Finset.product`: Turns `s : Finset α`, `t : Finset β` into their product in `Finset (α × β)`. * `Finset.diag`: For `s : Finset α`, `s.diag` is the `Finset (α × α)` of pairs `(a, a)` with `a ∈ s`. * `Finset.offDiag`: For `s : Finset α`, `s.offDiag` is the `Finset (α × α)` of pairs `(a, b)` with `a, b ∈ s` and `a ≠ b`. -/ assert_not_exists MonoidWithZero open Multiset variable {α β γ : Type*} namespace Finset /-! ### prod -/ section Prod variable {s s' : Finset α} {t t' : Finset β} {a : α} {b : β} /-- `product s t` is the set of pairs `(a, b)` such that `a ∈ s` and `b ∈ t`. -/ protected def product (s : Finset α) (t : Finset β) : Finset (α × β) := ⟨_, s.nodup.product t.nodup⟩ #align finset.product Finset.product instance instSProd : SProd (Finset α) (Finset β) (Finset (α × β)) where sprod := Finset.product @[simp] theorem product_val : (s ×ˢ t).1 = s.1 ×ˢ t.1 := rfl #align finset.product_val Finset.product_val @[simp] theorem mem_product {p : α × β} : p ∈ s ×ˢ t ↔ p.1 ∈ s ∧ p.2 ∈ t := Multiset.mem_product #align finset.mem_product Finset.mem_product theorem mk_mem_product (ha : a ∈ s) (hb : b ∈ t) : (a, b) ∈ s ×ˢ t := mem_product.2 ⟨ha, hb⟩ #align finset.mk_mem_product Finset.mk_mem_product @[simp, norm_cast] theorem coe_product (s : Finset α) (t : Finset β) : (↑(s ×ˢ t) : Set (α × β)) = (s : Set α) ×ˢ t := Set.ext fun _ => Finset.mem_product #align finset.coe_product Finset.coe_product theorem subset_product_image_fst [DecidableEq α] : (s ×ˢ t).image Prod.fst ⊆ s := fun i => by simp (config := { contextual := true }) [mem_image] #align finset.subset_product_image_fst Finset.subset_product_image_fst theorem subset_product_image_snd [DecidableEq β] : (s ×ˢ t).image Prod.snd ⊆ t := fun i => by simp (config := { contextual := true }) [mem_image] #align finset.subset_product_image_snd Finset.subset_product_image_snd theorem product_image_fst [DecidableEq α] (ht : t.Nonempty) : (s ×ˢ t).image Prod.fst = s := by ext i simp [mem_image, ht.exists_mem] #align finset.product_image_fst Finset.product_image_fst theorem product_image_snd [DecidableEq β] (ht : s.Nonempty) : (s ×ˢ t).image Prod.snd = t := by ext i simp [mem_image, ht.exists_mem] #align finset.product_image_snd Finset.product_image_snd theorem subset_product [DecidableEq α] [DecidableEq β] {s : Finset (α × β)} : s ⊆ s.image Prod.fst ×ˢ s.image Prod.snd := fun _ hp => mem_product.2 ⟨mem_image_of_mem _ hp, mem_image_of_mem _ hp⟩ #align finset.subset_product Finset.subset_product @[gcongr] theorem product_subset_product (hs : s ⊆ s') (ht : t ⊆ t') : s ×ˢ t ⊆ s' ×ˢ t' := fun ⟨_, _⟩ h => mem_product.2 ⟨hs (mem_product.1 h).1, ht (mem_product.1 h).2⟩ #align finset.product_subset_product Finset.product_subset_product @[gcongr] theorem product_subset_product_left (hs : s ⊆ s') : s ×ˢ t ⊆ s' ×ˢ t := product_subset_product hs (Subset.refl _) #align finset.product_subset_product_left Finset.product_subset_product_left @[gcongr] theorem product_subset_product_right (ht : t ⊆ t') : s ×ˢ t ⊆ s ×ˢ t' := product_subset_product (Subset.refl _) ht #align finset.product_subset_product_right Finset.product_subset_product_right theorem map_swap_product (s : Finset α) (t : Finset β) : (t ×ˢ s).map ⟨Prod.swap, Prod.swap_injective⟩ = s ×ˢ t := coe_injective <| by push_cast exact Set.image_swap_prod _ _ #align finset.map_swap_product Finset.map_swap_product @[simp] theorem image_swap_product [DecidableEq (α × β)] (s : Finset α) (t : Finset β) : (t ×ˢ s).image Prod.swap = s ×ˢ t := coe_injective <| by push_cast exact Set.image_swap_prod _ _ #align finset.image_swap_product Finset.image_swap_product theorem product_eq_biUnion [DecidableEq (α × β)] (s : Finset α) (t : Finset β) : s ×ˢ t = s.biUnion fun a => t.image fun b => (a, b) := ext fun ⟨x, y⟩ => by simp only [mem_product, mem_biUnion, mem_image, exists_prop, Prod.mk.inj_iff, and_left_comm, exists_and_left, exists_eq_right, exists_eq_left] #align finset.product_eq_bUnion Finset.product_eq_biUnion theorem product_eq_biUnion_right [DecidableEq (α × β)] (s : Finset α) (t : Finset β) : s ×ˢ t = t.biUnion fun b => s.image fun a => (a, b) := ext fun ⟨x, y⟩ => by simp only [mem_product, mem_biUnion, mem_image, exists_prop, Prod.mk.inj_iff, and_left_comm, exists_and_left, exists_eq_right, exists_eq_left] #align finset.product_eq_bUnion_right Finset.product_eq_biUnion_right /-- See also `Finset.sup_product_left`. -/ @[simp] theorem product_biUnion [DecidableEq γ] (s : Finset α) (t : Finset β) (f : α × β → Finset γ) : (s ×ˢ t).biUnion f = s.biUnion fun a => t.biUnion fun b => f (a, b) := by classical simp_rw [product_eq_biUnion, biUnion_biUnion, image_biUnion] #align finset.product_bUnion Finset.product_biUnion @[simp] theorem card_product (s : Finset α) (t : Finset β) : card (s ×ˢ t) = card s * card t := Multiset.card_product _ _ #align finset.card_product Finset.card_product /-- The product of two Finsets is nontrivial iff both are nonempty at least one of them is nontrivial. -/ lemma nontrivial_prod_iff : (s ×ˢ t).Nontrivial ↔ s.Nonempty ∧ t.Nonempty ∧ (s.Nontrivial ∨ t.Nontrivial) := by simp_rw [← card_pos, ← one_lt_card_iff_nontrivial, card_product]; apply Nat.one_lt_mul_iff
Mathlib/Data/Finset/Prod.lean
153
156
theorem filter_product (p : α → Prop) (q : β → Prop) [DecidablePred p] [DecidablePred q] : ((s ×ˢ t).filter fun x : α × β => p x.1 ∧ q x.2) = s.filter p ×ˢ t.filter q := by
ext ⟨a, b⟩ simp [mem_filter, mem_product, decide_eq_true_eq, and_comm, and_left_comm, and_assoc]
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Patrick Massot -/ import Mathlib.Algebra.Algebra.Subalgebra.Operations import Mathlib.Algebra.Ring.Fin import Mathlib.RingTheory.Ideal.Quotient #align_import ring_theory.ideal.quotient_operations from "leanprover-community/mathlib"@"b88d81c84530450a8989e918608e5960f015e6c8" /-! # More operations on modules and ideals related to quotients ## Main results: - `RingHom.quotientKerEquivRange` : the **first isomorphism theorem** for commutative rings. - `RingHom.quotientKerEquivRangeS` : the **first isomorphism theorem** for a morphism from a commutative ring to a semiring. - `AlgHom.quotientKerEquivRange` : the **first isomorphism theorem** for a morphism of algebras (over a commutative semiring) - `RingHom.quotientKerEquivRangeS` : the **first isomorphism theorem** for a morphism from a commutative ring to a semiring. - `Ideal.quotientInfRingEquivPiQuotient`: the **Chinese Remainder Theorem**, version for coprime ideals (see also `ZMod.prodEquivPi` in `Data.ZMod.Quotient` for elementary versions about `ZMod`). -/ universe u v w namespace RingHom variable {R : Type u} {S : Type v} [CommRing R] [Semiring S] (f : R →+* S) /-- The induced map from the quotient by the kernel to the codomain. This is an isomorphism if `f` has a right inverse (`quotientKerEquivOfRightInverse`) / is surjective (`quotientKerEquivOfSurjective`). -/ def kerLift : R ⧸ ker f →+* S := Ideal.Quotient.lift _ f fun _ => f.mem_ker.mp #align ring_hom.ker_lift RingHom.kerLift @[simp] theorem kerLift_mk (r : R) : kerLift f (Ideal.Quotient.mk (ker f) r) = f r := Ideal.Quotient.lift_mk _ _ _ #align ring_hom.ker_lift_mk RingHom.kerLift_mk theorem lift_injective_of_ker_le_ideal (I : Ideal R) {f : R →+* S} (H : ∀ a : R, a ∈ I → f a = 0) (hI : ker f ≤ I) : Function.Injective (Ideal.Quotient.lift I f H) := by rw [RingHom.injective_iff_ker_eq_bot, RingHom.ker_eq_bot_iff_eq_zero] intro u hu obtain ⟨v, rfl⟩ := Ideal.Quotient.mk_surjective u rw [Ideal.Quotient.lift_mk] at hu rw [Ideal.Quotient.eq_zero_iff_mem] exact hI ((RingHom.mem_ker f).mpr hu) #align ring_hom.lift_injective_of_ker_le_ideal RingHom.lift_injective_of_ker_le_ideal /-- The induced map from the quotient by the kernel is injective. -/ theorem kerLift_injective : Function.Injective (kerLift f) := lift_injective_of_ker_le_ideal (ker f) (fun a => by simp only [mem_ker, imp_self]) le_rfl #align ring_hom.ker_lift_injective RingHom.kerLift_injective variable {f} /-- The **first isomorphism theorem for commutative rings**, computable version. -/ def quotientKerEquivOfRightInverse {g : S → R} (hf : Function.RightInverse g f) : R ⧸ ker f ≃+* S := { kerLift f with toFun := kerLift f invFun := Ideal.Quotient.mk (ker f) ∘ g left_inv := by rintro ⟨x⟩ apply kerLift_injective simp only [Submodule.Quotient.quot_mk_eq_mk, Ideal.Quotient.mk_eq_mk, kerLift_mk, Function.comp_apply, hf (f x)] right_inv := hf } #align ring_hom.quotient_ker_equiv_of_right_inverse RingHom.quotientKerEquivOfRightInverse @[simp] theorem quotientKerEquivOfRightInverse.apply {g : S → R} (hf : Function.RightInverse g f) (x : R ⧸ ker f) : quotientKerEquivOfRightInverse hf x = kerLift f x := rfl #align ring_hom.quotient_ker_equiv_of_right_inverse.apply RingHom.quotientKerEquivOfRightInverse.apply @[simp] theorem quotientKerEquivOfRightInverse.Symm.apply {g : S → R} (hf : Function.RightInverse g f) (x : S) : (quotientKerEquivOfRightInverse hf).symm x = Ideal.Quotient.mk (ker f) (g x) := rfl #align ring_hom.quotient_ker_equiv_of_right_inverse.symm.apply RingHom.quotientKerEquivOfRightInverse.Symm.apply variable (R) in /-- The quotient of a ring by he zero ideal is isomorphic to the ring itself. -/ def _root_.RingEquiv.quotientBot : R ⧸ (⊥ : Ideal R) ≃+* R := (Ideal.quotEquivOfEq (RingHom.ker_coe_equiv <| .refl _).symm).trans <| quotientKerEquivOfRightInverse (f := .id R) (g := _root_.id) fun _ ↦ rfl /-- The **first isomorphism theorem** for commutative rings, surjective case. -/ noncomputable def quotientKerEquivOfSurjective (hf : Function.Surjective f) : R ⧸ (ker f) ≃+* S := quotientKerEquivOfRightInverse (Classical.choose_spec hf.hasRightInverse) #align ring_hom.quotient_ker_equiv_of_surjective RingHom.quotientKerEquivOfSurjective /-- The **first isomorphism theorem** for commutative rings (`RingHom.rangeS` version). -/ noncomputable def quotientKerEquivRangeS (f : R →+* S) : R ⧸ ker f ≃+* f.rangeS := (Ideal.quotEquivOfEq f.ker_rangeSRestrict.symm).trans <| quotientKerEquivOfSurjective f.rangeSRestrict_surjective variable {S : Type v} [Ring S] (f : R →+* S) /-- The **first isomorphism theorem** for commutative rings (`RingHom.range` version). -/ noncomputable def quotientKerEquivRange (f : R →+* S) : R ⧸ ker f ≃+* f.range := (Ideal.quotEquivOfEq f.ker_rangeRestrict.symm).trans <| quotientKerEquivOfSurjective f.rangeRestrict_surjective end RingHom namespace Ideal open Function RingHom variable {R : Type u} {S : Type v} {F : Type w} [CommRing R] [Semiring S] @[simp] theorem map_quotient_self (I : Ideal R) : map (Quotient.mk I) I = ⊥ := eq_bot_iff.2 <| Ideal.map_le_iff_le_comap.2 fun _ hx => (Submodule.mem_bot (R ⧸ I)).2 <| Ideal.Quotient.eq_zero_iff_mem.2 hx #align ideal.map_quotient_self Ideal.map_quotient_self @[simp] theorem mk_ker {I : Ideal R} : ker (Quotient.mk I) = I := by ext rw [ker, mem_comap, Submodule.mem_bot, Quotient.eq_zero_iff_mem] #align ideal.mk_ker Ideal.mk_ker theorem map_mk_eq_bot_of_le {I J : Ideal R} (h : I ≤ J) : I.map (Quotient.mk J) = ⊥ := by rw [map_eq_bot_iff_le_ker, mk_ker] exact h #align ideal.map_mk_eq_bot_of_le Ideal.map_mk_eq_bot_of_le theorem ker_quotient_lift {I : Ideal R} (f : R →+* S) (H : I ≤ ker f) : ker (Ideal.Quotient.lift I f H) = f.ker.map (Quotient.mk I) := by apply Ideal.ext intro x constructor · intro hx obtain ⟨y, hy⟩ := Quotient.mk_surjective x rw [mem_ker, ← hy, Ideal.Quotient.lift_mk, ← mem_ker] at hx rw [← hy, mem_map_iff_of_surjective (Quotient.mk I) Quotient.mk_surjective] exact ⟨y, hx, rfl⟩ · intro hx rw [mem_map_iff_of_surjective (Quotient.mk I) Quotient.mk_surjective] at hx obtain ⟨y, hy⟩ := hx rw [mem_ker, ← hy.right, Ideal.Quotient.lift_mk] exact hy.left #align ideal.ker_quotient_lift Ideal.ker_quotient_lift lemma injective_lift_iff {I : Ideal R} {f : R →+* S} (H : ∀ (a : R), a ∈ I → f a = 0) : Injective (Quotient.lift I f H) ↔ ker f = I := by rw [injective_iff_ker_eq_bot, ker_quotient_lift, map_eq_bot_iff_le_ker, mk_ker] constructor · exact fun h ↦ le_antisymm h H · rintro rfl; rfl lemma ker_Pi_Quotient_mk {ι : Type*} (I : ι → Ideal R) : ker (Pi.ringHom fun i : ι ↦ Quotient.mk (I i)) = ⨅ i, I i := by simp [Pi.ker_ringHom, mk_ker] @[simp] theorem bot_quotient_isMaximal_iff (I : Ideal R) : (⊥ : Ideal (R ⧸ I)).IsMaximal ↔ I.IsMaximal := ⟨fun hI => mk_ker (I := I) ▸ comap_isMaximal_of_surjective (Quotient.mk I) Quotient.mk_surjective (K := ⊥) (H := hI), fun hI => by letI := Quotient.field I exact bot_isMaximal⟩ #align ideal.bot_quotient_is_maximal_iff Ideal.bot_quotient_isMaximal_iff /-- See also `Ideal.mem_quotient_iff_mem` in case `I ≤ J`. -/ @[simp] theorem mem_quotient_iff_mem_sup {I J : Ideal R} {x : R} : Quotient.mk I x ∈ J.map (Quotient.mk I) ↔ x ∈ J ⊔ I := by rw [← mem_comap, comap_map_of_surjective (Quotient.mk I) Quotient.mk_surjective, ← ker_eq_comap_bot, mk_ker] #align ideal.mem_quotient_iff_mem_sup Ideal.mem_quotient_iff_mem_sup /-- See also `Ideal.mem_quotient_iff_mem_sup` if the assumption `I ≤ J` is not available. -/ theorem mem_quotient_iff_mem {I J : Ideal R} (hIJ : I ≤ J) {x : R} : Quotient.mk I x ∈ J.map (Quotient.mk I) ↔ x ∈ J := by rw [mem_quotient_iff_mem_sup, sup_eq_left.mpr hIJ] #align ideal.mem_quotient_iff_mem Ideal.mem_quotient_iff_mem section ChineseRemainder open Function Quotient Finset variable {ι : Type*} /-- The homomorphism from `R/(⋂ i, f i)` to `∏ i, (R / f i)` featured in the Chinese Remainder Theorem. It is bijective if the ideals `f i` are coprime. -/ def quotientInfToPiQuotient (I : ι → Ideal R) : (R ⧸ ⨅ i, I i) →+* ∀ i, R ⧸ I i := Quotient.lift (⨅ i, I i) (Pi.ringHom fun i : ι ↦ Quotient.mk (I i)) (by simp [← RingHom.mem_ker, ker_Pi_Quotient_mk]) lemma quotientInfToPiQuotient_mk (I : ι → Ideal R) (x : R) : quotientInfToPiQuotient I (Quotient.mk _ x) = fun i : ι ↦ Quotient.mk (I i) x := rfl lemma quotientInfToPiQuotient_mk' (I : ι → Ideal R) (x : R) (i : ι) : quotientInfToPiQuotient I (Quotient.mk _ x) i = Quotient.mk (I i) x := rfl lemma quotientInfToPiQuotient_inj (I : ι → Ideal R) : Injective (quotientInfToPiQuotient I) := by rw [quotientInfToPiQuotient, injective_lift_iff, ker_Pi_Quotient_mk] lemma quotientInfToPiQuotient_surj [Finite ι] {I : ι → Ideal R} (hI : Pairwise fun i j => IsCoprime (I i) (I j)) : Surjective (quotientInfToPiQuotient I) := by classical cases nonempty_fintype ι intro g choose f hf using fun i ↦ mk_surjective (g i) have key : ∀ i, ∃ e : R, mk (I i) e = 1 ∧ ∀ j, j ≠ i → mk (I j) e = 0 := by intro i have hI' : ∀ j ∈ ({i} : Finset ι)ᶜ, IsCoprime (I i) (I j) := by intros j hj exact hI (by simpa [ne_comm, isCoprime_iff_add] using hj) rcases isCoprime_iff_exists.mp (isCoprime_biInf hI') with ⟨u, hu, e, he, hue⟩ replace he : ∀ j, j ≠ i → e ∈ I j := by simpa using he refine ⟨e, ?_, ?_⟩ · simp [eq_sub_of_add_eq' hue, map_sub, eq_zero_iff_mem.mpr hu] · exact fun j hj ↦ eq_zero_iff_mem.mpr (he j hj) choose e he using key use mk _ (∑ i, f i*e i) ext i rw [quotientInfToPiQuotient_mk', map_sum, Fintype.sum_eq_single i] · simp [(he i).1, hf] · intros j hj simp [(he j).2 i hj.symm] /-- **Chinese Remainder Theorem**. Eisenbud Ex.2.6. Similar to Atiyah-Macdonald 1.10 and Stacks 00DT -/ noncomputable def quotientInfRingEquivPiQuotient [Finite ι] (f : ι → Ideal R) (hf : Pairwise fun i j => IsCoprime (f i) (f j)) : (R ⧸ ⨅ i, f i) ≃+* ∀ i, R ⧸ f i := { Equiv.ofBijective _ ⟨quotientInfToPiQuotient_inj f, quotientInfToPiQuotient_surj hf⟩, quotientInfToPiQuotient f with } #align ideal.quotient_inf_ring_equiv_pi_quotient Ideal.quotientInfRingEquivPiQuotient /-- Corollary of Chinese Remainder Theorem: if `Iᵢ` are pairwise coprime ideals in a commutative ring then the canonical map `R → ∏ (R ⧸ Iᵢ)` is surjective. -/ lemma pi_quotient_surjective {R : Type*} [CommRing R] {ι : Type*} [Finite ι] {I : ι → Ideal R} (hf : Pairwise fun i j ↦ IsCoprime (I i) (I j)) (x : (i : ι) → R ⧸ I i) : ∃ r : R, ∀ i, r = x i := by obtain ⟨y, rfl⟩ := Ideal.quotientInfToPiQuotient_surj hf x obtain ⟨r, rfl⟩ := Ideal.Quotient.mk_surjective y exact ⟨r, fun i ↦ rfl⟩ -- variant of `IsDedekindDomain.exists_forall_sub_mem_ideal` which doesn't assume Dedekind domain! /-- Corollary of Chinese Remainder Theorem: if `Iᵢ` are pairwise coprime ideals in a commutative ring then given elements `xᵢ` you can find `r` with `r - xᵢ ∈ Iᵢ` for all `i`. -/ lemma exists_forall_sub_mem_ideal {R : Type*} [CommRing R] {ι : Type*} [Finite ι] {I : ι → Ideal R} (hI : Pairwise fun i j ↦ IsCoprime (I i) (I j)) (x : ι → R) : ∃ r : R, ∀ i, r - x i ∈ I i := by obtain ⟨y, hy⟩ := Ideal.pi_quotient_surjective hI (fun i ↦ x i) exact ⟨y, fun i ↦ (Submodule.Quotient.eq (I i)).mp <| hy i⟩ /-- **Chinese remainder theorem**, specialized to two ideals. -/ noncomputable def quotientInfEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : R ⧸ I ⊓ J ≃+* (R ⧸ I) × R ⧸ J := let f : Fin 2 → Ideal R := ![I, J] have hf : Pairwise fun i j => IsCoprime (f i) (f j) := by intro i j h fin_cases i <;> fin_cases j <;> try contradiction · assumption · exact coprime.symm (Ideal.quotEquivOfEq (by simp [f, iInf, inf_comm])).trans <| (Ideal.quotientInfRingEquivPiQuotient f hf).trans <| RingEquiv.piFinTwo fun i => R ⧸ f i #align ideal.quotient_inf_equiv_quotient_prod Ideal.quotientInfEquivQuotientProd @[simp] theorem quotientInfEquivQuotientProd_fst (I J : Ideal R) (coprime : IsCoprime I J) (x : R ⧸ I ⊓ J) : (quotientInfEquivQuotientProd I J coprime x).fst = Ideal.Quotient.factor (I ⊓ J) I inf_le_left x := Quot.inductionOn x fun _ => rfl #align ideal.quotient_inf_equiv_quotient_prod_fst Ideal.quotientInfEquivQuotientProd_fst @[simp] theorem quotientInfEquivQuotientProd_snd (I J : Ideal R) (coprime : IsCoprime I J) (x : R ⧸ I ⊓ J) : (quotientInfEquivQuotientProd I J coprime x).snd = Ideal.Quotient.factor (I ⊓ J) J inf_le_right x := Quot.inductionOn x fun _ => rfl #align ideal.quotient_inf_equiv_quotient_prod_snd Ideal.quotientInfEquivQuotientProd_snd @[simp]
Mathlib/RingTheory/Ideal/QuotientOperations.lean
294
298
theorem fst_comp_quotientInfEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : (RingHom.fst _ _).comp (quotientInfEquivQuotientProd I J coprime : R ⧸ I ⊓ J →+* (R ⧸ I) × R ⧸ J) = Ideal.Quotient.factor (I ⊓ J) I inf_le_left := by
apply Quotient.ringHom_ext; ext; rfl
/- Copyright (c) 2021 Martin Dvorak. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Martin Dvorak, Kyle Miller, Eric Wieser -/ import Mathlib.Data.Matrix.Notation import Mathlib.LinearAlgebra.BilinearMap import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.Algebra.Lie.Basic #align_import linear_algebra.cross_product from "leanprover-community/mathlib"@"91288e351d51b3f0748f0a38faa7613fb0ae2ada" /-! # Cross products This module defines the cross product of vectors in $R^3$ for $R$ a commutative ring, as a bilinear map. ## Main definitions * `crossProduct` is the cross product of pairs of vectors in $R^3$. ## Main results * `triple_product_eq_det` * `cross_dot_cross` * `jacobi_cross` ## Notation The locale `Matrix` gives the following notation: * `×₃` for the cross product ## Tags crossproduct -/ open Matrix open Matrix variable {R : Type*} [CommRing R] /-- The cross product of two vectors in $R^3$ for $R$ a commutative ring. -/ def crossProduct : (Fin 3 → R) →ₗ[R] (Fin 3 → R) →ₗ[R] Fin 3 → R := by apply LinearMap.mk₂ R fun a b : Fin 3 → R => ![a 1 * b 2 - a 2 * b 1, a 2 * b 0 - a 0 * b 2, a 0 * b 1 - a 1 * b 0] · intros simp_rw [vec3_add, Pi.add_apply] apply vec3_eq <;> ring · intros simp_rw [smul_vec3, Pi.smul_apply, smul_sub, smul_mul_assoc] · intros simp_rw [vec3_add, Pi.add_apply] apply vec3_eq <;> ring · intros simp_rw [smul_vec3, Pi.smul_apply, smul_sub, mul_smul_comm] #align cross_product crossProduct scoped[Matrix] infixl:74 " ×₃ " => crossProduct theorem cross_apply (a b : Fin 3 → R) : a ×₃ b = ![a 1 * b 2 - a 2 * b 1, a 2 * b 0 - a 0 * b 2, a 0 * b 1 - a 1 * b 0] := rfl #align cross_apply cross_apply section ProductsProperties #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma, likely due to https://github.com/leanprover/lean4/pull/3807 -/ @[simp, nolint simpNF] theorem cross_anticomm (v w : Fin 3 → R) : -(v ×₃ w) = w ×₃ v := by simp [cross_apply, mul_comm] #align cross_anticomm cross_anticomm alias neg_cross := cross_anticomm #align neg_cross neg_cross #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma, likely due to https://github.com/leanprover/lean4/pull/3807 -/ @[simp, nolint simpNF] theorem cross_anticomm' (v w : Fin 3 → R) : v ×₃ w + w ×₃ v = 0 := by rw [add_eq_zero_iff_eq_neg, cross_anticomm] #align cross_anticomm' cross_anticomm' #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma, likely due to https://github.com/leanprover/lean4/pull/3807 -/ @[simp, nolint simpNF] theorem cross_self (v : Fin 3 → R) : v ×₃ v = 0 := by simp [cross_apply, mul_comm] #align cross_self cross_self #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma, likely due to https://github.com/leanprover/lean4/pull/3807 -/ /-- The cross product of two vectors is perpendicular to the first vector. -/ @[simp 1100, nolint simpNF] -- Porting note: increase priority so that the LHS doesn't simplify theorem dot_self_cross (v w : Fin 3 → R) : v ⬝ᵥ v ×₃ w = 0 := by rw [cross_apply, vec3_dotProduct] set_option tactic.skipAssignedInstances false in norm_num ring #align dot_self_cross dot_self_cross #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma, likely due to https://github.com/leanprover/lean4/pull/3807 -/ /-- The cross product of two vectors is perpendicular to the second vector. -/ @[simp 1100, nolint simpNF] -- Porting note: increase priority so that the LHS doesn't simplify
Mathlib/LinearAlgebra/CrossProduct.lean
114
115
theorem dot_cross_self (v w : Fin 3 → R) : w ⬝ᵥ v ×₃ w = 0 := by
rw [← cross_anticomm, Matrix.dotProduct_neg, dot_self_cross, neg_zero]
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.LinearAlgebra.Matrix.Adjugate import Mathlib.RingTheory.PolynomialAlgebra #align_import linear_algebra.matrix.charpoly.basic from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Characteristic polynomials and the Cayley-Hamilton theorem We define characteristic polynomials of matrices and prove the Cayley–Hamilton theorem over arbitrary commutative rings. See the file `Mathlib/LinearAlgebra/Matrix/Charpoly/Coeff.lean` for corollaries of this theorem. ## Main definitions * `Matrix.charpoly` is the characteristic polynomial of a matrix. ## Implementation details We follow a nice proof from http://drorbn.net/AcademicPensieve/2015-12/CayleyHamilton.pdf -/ noncomputable section universe u v w namespace Matrix open Finset Matrix Polynomial variable {R S : Type*} [CommRing R] [CommRing S] variable {m n : Type*} [DecidableEq m] [DecidableEq n] [Fintype m] [Fintype n] variable (M₁₁ : Matrix m m R) (M₁₂ : Matrix m n R) (M₂₁ : Matrix n m R) (M₂₂ M : Matrix n n R) variable (i j : n) /-- The "characteristic matrix" of `M : Matrix n n R` is the matrix of polynomials $t I - M$. The determinant of this matrix is the characteristic polynomial. -/ def charmatrix (M : Matrix n n R) : Matrix n n R[X] := Matrix.scalar n (X : R[X]) - (C : R →+* R[X]).mapMatrix M #align charmatrix Matrix.charmatrix theorem charmatrix_apply : charmatrix M i j = (Matrix.diagonal fun _ : n => X) i j - C (M i j) := rfl #align charmatrix_apply Matrix.charmatrix_apply @[simp] theorem charmatrix_apply_eq : charmatrix M i i = (X : R[X]) - C (M i i) := by simp only [charmatrix, RingHom.mapMatrix_apply, sub_apply, scalar_apply, map_apply, diagonal_apply_eq] #align charmatrix_apply_eq Matrix.charmatrix_apply_eq @[simp] theorem charmatrix_apply_ne (h : i ≠ j) : charmatrix M i j = -C (M i j) := by simp only [charmatrix, RingHom.mapMatrix_apply, sub_apply, scalar_apply, diagonal_apply_ne _ h, map_apply, sub_eq_neg_self] #align charmatrix_apply_ne Matrix.charmatrix_apply_ne theorem matPolyEquiv_charmatrix : matPolyEquiv (charmatrix M) = X - C M := by ext k i j simp only [matPolyEquiv_coeff_apply, coeff_sub, Pi.sub_apply] by_cases h : i = j · subst h rw [charmatrix_apply_eq, coeff_sub] simp only [coeff_X, coeff_C] split_ifs <;> simp · rw [charmatrix_apply_ne _ _ _ h, coeff_X, coeff_neg, coeff_C, coeff_C] split_ifs <;> simp [h] #align mat_poly_equiv_charmatrix Matrix.matPolyEquiv_charmatrix theorem charmatrix_reindex (e : n ≃ m) : charmatrix (reindex e e M) = reindex e e (charmatrix M) := by ext i j x by_cases h : i = j all_goals simp [h] #align charmatrix_reindex Matrix.charmatrix_reindex lemma charmatrix_map (M : Matrix n n R) (f : R →+* S) : charmatrix (M.map f) = (charmatrix M).map (Polynomial.map f) := by ext i j by_cases h : i = j <;> simp [h, charmatrix, diagonal] lemma charmatrix_fromBlocks : charmatrix (fromBlocks M₁₁ M₁₂ M₂₁ M₂₂) = fromBlocks (charmatrix M₁₁) (- M₁₂.map C) (- M₂₁.map C) (charmatrix M₂₂) := by simp only [charmatrix] ext (i|i) (j|j) : 2 <;> simp [diagonal] /-- The characteristic polynomial of a matrix `M` is given by $\det (t I - M)$. -/ def charpoly (M : Matrix n n R) : R[X] := (charmatrix M).det #align matrix.charpoly Matrix.charpoly theorem charpoly_reindex (e : n ≃ m) (M : Matrix n n R) : (reindex e e M).charpoly = M.charpoly := by unfold Matrix.charpoly rw [charmatrix_reindex, Matrix.det_reindex_self] #align matrix.charpoly_reindex Matrix.charpoly_reindex lemma charpoly_map (M : Matrix n n R) (f : R →+* S) : (M.map f).charpoly = M.charpoly.map f := by rw [charpoly, charmatrix_map, ← Polynomial.coe_mapRingHom, charpoly, RingHom.map_det, RingHom.mapMatrix_apply] @[simp] lemma charpoly_fromBlocks_zero₁₂ : (fromBlocks M₁₁ 0 M₂₁ M₂₂).charpoly = (M₁₁.charpoly * M₂₂.charpoly) := by simp only [charpoly, charmatrix_fromBlocks, Matrix.map_zero _ (Polynomial.C_0), neg_zero, det_fromBlocks_zero₁₂] @[simp] lemma charpoly_fromBlocks_zero₂₁ : (fromBlocks M₁₁ M₁₂ 0 M₂₂).charpoly = (M₁₁.charpoly * M₂₂.charpoly) := by simp only [charpoly, charmatrix_fromBlocks, Matrix.map_zero _ (Polynomial.C_0), neg_zero, det_fromBlocks_zero₂₁] -- This proof follows http://drorbn.net/AcademicPensieve/2015-12/CayleyHamilton.pdf /-- The **Cayley-Hamilton Theorem**, that the characteristic polynomial of a matrix, applied to the matrix itself, is zero. This holds over any commutative ring. See `LinearMap.aeval_self_charpoly` for the equivalent statement about endomorphisms. -/
Mathlib/LinearAlgebra/Matrix/Charpoly/Basic.lean
134
154
theorem aeval_self_charpoly (M : Matrix n n R) : aeval M M.charpoly = 0 := by
-- We begin with the fact $χ_M(t) I = adjugate (t I - M) * (t I - M)$, -- as an identity in `Matrix n n R[X]`. have h : M.charpoly • (1 : Matrix n n R[X]) = adjugate (charmatrix M) * charmatrix M := (adjugate_mul _).symm -- Using the algebra isomorphism `Matrix n n R[X] ≃ₐ[R] Polynomial (Matrix n n R)`, -- we have the same identity in `Polynomial (Matrix n n R)`. apply_fun matPolyEquiv at h simp only [matPolyEquiv.map_mul, matPolyEquiv_charmatrix] at h -- Because the coefficient ring `Matrix n n R` is non-commutative, -- evaluation at `M` is not multiplicative. -- However, any polynomial which is a product of the form $N * (t I - M)$ -- is sent to zero, because the evaluation function puts the polynomial variable -- to the right of any coefficients, so everything telescopes. apply_fun fun p => p.eval M at h rw [eval_mul_X_sub_C] at h -- Now $χ_M (t) I$, when thought of as a polynomial of matrices -- and evaluated at some `N` is exactly $χ_M (N)$. rw [matPolyEquiv_smul_one, eval_map] at h -- Thus we have $χ_M(M) = 0$, which is the desired result. exact h
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Patrick Massot, Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.FDeriv.Measurable import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.NormedSpace.Dual import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.MeasureTheory.Integral.VitaliCaratheodory #align_import measure_theory.integral.fund_thm_calculus from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Fundamental Theorem of Calculus We prove various versions of the [fundamental theorem of calculus](https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus) for interval integrals in `ℝ`. Recall that its first version states that the function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(δu, δv) ↦ δv • f b - δu • f a` at `(a, b)` provided that `f` is continuous at `a` and `b`, and its second version states that, if `f` has an integrable derivative on `[a, b]`, then `∫ x in a..b, f' x = f b - f a`. ## Main statements ### FTC-1 for Lebesgue measure We prove several versions of FTC-1, all in the `intervalIntegral` namespace. Many of them follow the naming scheme `integral_has(Strict?)(F?)Deriv(Within?)At(_of_tendsto_ae?)(_right|_left?)`. They formulate FTC in terms of `Has(Strict?)(F?)Deriv(Within?)At`. Let us explain the meaning of each part of the name: * `Strict` means that the theorem is about strict differentiability, see `HasStrictDerivAt` and `HasStrictFDerivAt`; * `F` means that the theorem is about differentiability in both endpoints; incompatible with `_right|_left`; * `Within` means that the theorem is about one-sided derivatives, see below for details; * `_of_tendsto_ae` means that instead of continuity the theorem assumes that `f` has a finite limit almost surely as `x` tends to `a` and/or `b`; * `_right` or `_left` mean that the theorem is about differentiability in the right (resp., left) endpoint. We also reformulate these theorems in terms of `(f?)deriv(Within?)`. These theorems are named `(f?)deriv(Within?)_integral(_of_tendsto_ae?)(_right|_left?)` with the same meaning of parts of the name. ### One-sided derivatives Theorem `intervalIntegral.integral_hasFDerivWithinAt_of_tendsto_ae` states that `(u, v) ↦ ∫ x in u..v, f x` has a derivative `(δu, δv) ↦ δv • cb - δu • ca` within the set `s × t` at `(a, b)` provided that `f` tends to `ca` (resp., `cb`) almost surely at `la` (resp., `lb`), where possible values of `s`, `t`, and corresponding filters `la`, `lb` are given in the following table. | `s` | `la` | `t` | `lb` | | ------- | ---- | --- | ---- | | `Iic a` | `𝓝[≤] a` | `Iic b` | `𝓝[≤] b` | | `Ici a` | `𝓝[>] a` | `Ici b` | `𝓝[>] b` | | `{a}` | `⊥` | `{b}` | `⊥` | | `univ` | `𝓝 a` | `univ` | `𝓝 b` | We use a typeclass `intervalIntegral.FTCFilter` to make Lean automatically find `la`/`lb` based on `s`/`t`. This way we can formulate one theorem instead of `16` (or `8` if we leave only non-trivial ones not covered by `integral_hasDerivWithinAt_of_tendsto_ae_(left|right)` and `integral_hasFDerivAt_of_tendsto_ae`). Similarly, `integral_hasDerivWithinAt_of_tendsto_ae_right` works for both one-sided derivatives using the same typeclass to find an appropriate filter. ### FTC for a locally finite measure Before proving FTC for the Lebesgue measure, we prove a few statements that can be seen as FTC for any measure. The most general of them, `measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae`, states the following. Let `(la, la')` be an `intervalIntegral.FTCFilter` pair of filters around `a` (i.e., `intervalIntegral.FTCFilter a la la'`) and let `(lb, lb')` be an `intervalIntegral.FTCFilter` pair of filters around `b`. If `f` has finite limits `ca` and `cb` almost surely at `la'` and `lb'`, respectively, then $$ \int_{va}^{vb} f ∂μ - \int_{ua}^{ub} f ∂μ = \int_{ub}^{vb} cb ∂μ - \int_{ua}^{va} ca ∂μ + o(‖∫_{ua}^{va} 1 ∂μ‖ + ‖∫_{ub}^{vb} (1:ℝ) ∂μ‖) $$ as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. ### FTC-2 and corollaries We use FTC-1 to prove several versions of FTC-2 for the Lebesgue measure, using a similar naming scheme as for the versions of FTC-1. They include: * `intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le` - most general version, for functions with a right derivative * `intervalIntegral.integral_eq_sub_of_hasDerivAt` - version for functions with a derivative on an open set * `intervalIntegral.integral_deriv_eq_sub'` - version that is easiest to use when computing the integral of a specific function We then derive additional integration techniques from FTC-2: * `intervalIntegral.integral_mul_deriv_eq_deriv_mul` - integration by parts * `intervalIntegral.integral_comp_mul_deriv''` - integration by substitution Many applications of these theorems can be found in the file `Mathlib/Analysis/SpecialFunctions/Integrals.lean`. Note that the assumptions of FTC-2 are formulated in the form that `f'` is integrable. To use it in a context with the stronger assumption that `f'` is continuous, one can use `ContinuousOn.intervalIntegrable` or `ContinuousOn.integrableOn_Icc` or `ContinuousOn.integrableOn_uIcc`. ### `intervalIntegral.FTCFilter` class As explained above, many theorems in this file rely on the typeclass `intervalIntegral.FTCFilter (a : ℝ) (l l' : Filter ℝ)` to avoid code duplication. This typeclass combines four assumptions: - `pure a ≤ l`; - `l' ≤ 𝓝 a`; - `l'` has a basis of measurable sets; - if `u n` and `v n` tend to `l`, then for any `s ∈ l'`, `Ioc (u n) (v n)` is eventually included in `s`. This typeclass has the following “real” instances: `(a, pure a, ⊥)`, `(a, 𝓝[≥] a, 𝓝[>] a)`, `(a, 𝓝[≤] a, 𝓝[≤] a)`, `(a, 𝓝 a, 𝓝 a)`. Furthermore, we have the following instances that are equal to the previously mentioned instances: `(a, 𝓝[{a}] a, ⊥)` and `(a, 𝓝[univ] a, 𝓝[univ] a)`. While the difference between `Ici a` and `Ioi a` doesn't matter for theorems about Lebesgue measure, it becomes important in the versions of FTC about any locally finite measure if this measure has an atom at one of the endpoints. ### Combining one-sided and two-sided derivatives There are some `intervalIntegral.FTCFilter` instances where the fact that it is one-sided or two-sided depends on the point, namely `(x, 𝓝[Set.Icc a b] x, 𝓝[Set.Icc a b] x)` (resp. `(x, 𝓝[Set.uIcc a b] x, 𝓝[Set.uIcc a b] x)`, with `x ∈ Icc a b` (resp. `x ∈ uIcc a b`). This results in a two-sided derivatives for `x ∈ Set.Ioo a b` and one-sided derivatives for `x ∈ {a, b}`. Other instances could be added when needed (in that case, one also needs to add instances for `Filter.IsMeasurablyGenerated` and `Filter.TendstoIxxClass`). ## Tags integral, fundamental theorem of calculus, FTC-1, FTC-2, change of variables in integrals -/ set_option autoImplicit true noncomputable section open scoped Classical open MeasureTheory Set Filter Function open scoped Classical Topology Filter ENNReal Interval NNReal variable {ι 𝕜 E F A : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] namespace intervalIntegral section FTC1 /-! ### Fundamental theorem of calculus, part 1, for any measure In this section we prove a few lemmas that can be seen as versions of FTC-1 for interval integrals w.r.t. any measure. Many theorems are formulated for one or two pairs of filters related by `intervalIntegral.FTCFilter a l l'`. This typeclass has exactly four “real” instances: `(a, pure a, ⊥)`, `(a, 𝓝[≥] a, 𝓝[>] a)`, `(a, 𝓝[≤] a, 𝓝[≤] a)`, `(a, 𝓝 a, 𝓝 a)`, and two instances that are equal to the first and last “real” instances: `(a, 𝓝[{a}] a, ⊥)` and `(a, 𝓝[univ] a, 𝓝[univ] a)`. We use this approach to avoid repeating arguments in many very similar cases. Lean can automatically find both `a` and `l'` based on `l`. The most general theorem `measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae` can be seen as a generalization of lemma `integral_hasStrictFDerivAt` below which states strict differentiability of `∫ x in u..v, f x` in `(u, v)` at `(a, b)` for a measurable function `f` that is integrable on `a..b` and is continuous at `a` and `b`. The lemma is generalized in three directions: first, `measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae` deals with any locally finite measure `μ`; second, it works for one-sided limits/derivatives; third, it assumes only that `f` has finite limits almost surely at `a` and `b`. Namely, let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of `intervalIntegral.FTCFilter`s around `a`; let `(lb, lb')` be a pair of `intervalIntegral.FTCFilter`s around `b`. Suppose that `f` has finite limits `ca` and `cb` at `la' ⊓ ae μ` and `lb' ⊓ ae μ`, respectively. Then `∫ x in va..vb, f x ∂μ - ∫ x in ua..ub, f x ∂μ = ∫ x in ub..vb, cb ∂μ - ∫ x in ua..va, ca ∂μ + o(‖∫ x in ua..va, (1:ℝ) ∂μ‖ + ‖∫ x in ub..vb, (1:ℝ) ∂μ‖)` as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. This theorem is formulated with integral of constants instead of measures in the right hand sides for two reasons: first, this way we avoid `min`/`max` in the statements; second, often it is possible to write better `simp` lemmas for these integrals, see `integral_const` and `integral_const_of_cdf`. In the next subsection we apply this theorem to prove various theorems about differentiability of the integral w.r.t. Lebesgue measure. -/ /-- An auxiliary typeclass for the Fundamental theorem of calculus, part 1. It is used to formulate theorems that work simultaneously for left and right one-sided derivatives of `∫ x in u..v, f x`. -/ class FTCFilter (a : outParam ℝ) (outer : Filter ℝ) (inner : outParam <| Filter ℝ) extends TendstoIxxClass Ioc outer inner : Prop where pure_le : pure a ≤ outer le_nhds : inner ≤ 𝓝 a [meas_gen : IsMeasurablyGenerated inner] set_option linter.uppercaseLean3 false in #align interval_integral.FTC_filter intervalIntegral.FTCFilter namespace FTCFilter set_option linter.uppercaseLean3 false -- `FTC` in every name instance pure (a : ℝ) : FTCFilter a (pure a) ⊥ where pure_le := le_rfl le_nhds := bot_le #align interval_integral.FTC_filter.pure intervalIntegral.FTCFilter.pure instance nhdsWithinSingleton (a : ℝ) : FTCFilter a (𝓝[{a}] a) ⊥ := by rw [nhdsWithin, principal_singleton, inf_eq_right.2 (pure_le_nhds a)]; infer_instance #align interval_integral.FTC_filter.nhds_within_singleton intervalIntegral.FTCFilter.nhdsWithinSingleton theorem finiteAt_inner {a : ℝ} (l : Filter ℝ) {l'} [h : FTCFilter a l l'] {μ : Measure ℝ} [IsLocallyFiniteMeasure μ] : μ.FiniteAtFilter l' := (μ.finiteAt_nhds a).filter_mono h.le_nhds #align interval_integral.FTC_filter.finite_at_inner intervalIntegral.FTCFilter.finiteAt_inner instance nhds (a : ℝ) : FTCFilter a (𝓝 a) (𝓝 a) where pure_le := pure_le_nhds a le_nhds := le_rfl #align interval_integral.FTC_filter.nhds intervalIntegral.FTCFilter.nhds instance nhdsUniv (a : ℝ) : FTCFilter a (𝓝[univ] a) (𝓝 a) := by rw [nhdsWithin_univ]; infer_instance #align interval_integral.FTC_filter.nhds_univ intervalIntegral.FTCFilter.nhdsUniv instance nhdsLeft (a : ℝ) : FTCFilter a (𝓝[≤] a) (𝓝[≤] a) where pure_le := pure_le_nhdsWithin right_mem_Iic le_nhds := inf_le_left #align interval_integral.FTC_filter.nhds_left intervalIntegral.FTCFilter.nhdsLeft instance nhdsRight (a : ℝ) : FTCFilter a (𝓝[≥] a) (𝓝[>] a) where pure_le := pure_le_nhdsWithin left_mem_Ici le_nhds := inf_le_left #align interval_integral.FTC_filter.nhds_right intervalIntegral.FTCFilter.nhdsRight instance nhdsIcc {x a b : ℝ} [h : Fact (x ∈ Icc a b)] : FTCFilter x (𝓝[Icc a b] x) (𝓝[Icc a b] x) where pure_le := pure_le_nhdsWithin h.out le_nhds := inf_le_left #align interval_integral.FTC_filter.nhds_Icc intervalIntegral.FTCFilter.nhdsIcc instance nhdsUIcc {x a b : ℝ} [h : Fact (x ∈ [[a, b]])] : FTCFilter x (𝓝[[[a, b]]] x) (𝓝[[[a, b]]] x) := .nhdsIcc (h := h) #align interval_integral.FTC_filter.nhds_uIcc intervalIntegral.FTCFilter.nhdsUIcc end FTCFilter open Asymptotics section variable {f : ℝ → E} {a b : ℝ} {c ca cb : E} {l l' la la' lb lb' : Filter ℝ} {lt : Filter ι} {μ : Measure ℝ} {u v ua va ub vb : ι → ℝ} /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `TendstoIxxClass Ioc`. If `f` has a finite limit `c` at `l' ⊓ ae μ`, where `μ` is a measure finite at `l'`, then `∫ x in u..v, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, 1 ∂μ)` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae` for a version assuming `[intervalIntegral.FTCFilter a l l']` and `[MeasureTheory.IsLocallyFiniteMeasure μ]`. If `l` is one of `𝓝[≥] a`, `𝓝[≤] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version also works, e.g., for `l = l' = atTop`. We use integrals of constants instead of measures because this way it is easier to formulate a statement that works in both cases `u ≤ v` and `v ≤ u`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae' [IsMeasurablyGenerated l'] [TendstoIxxClass Ioc l l'] (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hl : μ.FiniteAtFilter l') (hu : Tendsto u lt l) (hv : Tendsto v lt l) : (fun t => (∫ x in u t..v t, f x ∂μ) - ∫ _ in u t..v t, c ∂μ) =o[lt] fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := by by_cases hE : CompleteSpace E; swap · simp [intervalIntegral, integral, hE] have A := hf.integral_sub_linear_isLittleO_ae hfm hl (hu.Ioc hv) have B := hf.integral_sub_linear_isLittleO_ae hfm hl (hv.Ioc hu) simp_rw [integral_const', sub_smul] refine ((A.trans_le fun t ↦ ?_).sub (B.trans_le fun t ↦ ?_)).congr_left fun t ↦ ?_ · cases le_total (u t) (v t) <;> simp [*] · cases le_total (u t) (v t) <;> simp [*] · simp_rw [intervalIntegral] abel #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae' intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae' variable [CompleteSpace E] /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `TendstoIxxClass Ioc`. If `f` has a finite limit `c` at `l ⊓ ae μ`, where `μ` is a measure finite at `l`, then `∫ x in u..v, f x ∂μ = μ (Ioc u v) • c + o(μ(Ioc u v))` as both `u` and `v` tend to `l` so that `u ≤ v`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le` for a version assuming `[intervalIntegral.FTCFilter a l l']` and `[MeasureTheory.IsLocallyFiniteMeasure μ]`. If `l` is one of `𝓝[≥] a`, `𝓝[≤] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version also works, e.g., for `l = l' = Filter.atTop`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' [IsMeasurablyGenerated l'] [TendstoIxxClass Ioc l l'] (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hl : μ.FiniteAtFilter l') (hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : u ≤ᶠ[lt] v) : (fun t => (∫ x in u t..v t, f x ∂μ) - (μ (Ioc (u t) (v t))).toReal • c) =o[lt] fun t => (μ <| Ioc (u t) (v t)).toReal := (measure_integral_sub_linear_isLittleO_of_tendsto_ae' hfm hf hl hu hv).congr' (huv.mono fun x hx => by simp [integral_const', hx]) (huv.mono fun x hx => by simp [integral_const', hx]) #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_le' intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `TendstoIxxClass Ioc`. If `f` has a finite limit `c` at `l ⊓ ae μ`, where `μ` is a measure finite at `l`, then `∫ x in u..v, f x ∂μ = -μ (Ioc v u) • c + o(μ(Ioc v u))` as both `u` and `v` tend to `l` so that `v ≤ u`. See also `measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge` for a version assuming `[intervalIntegral.FTCFilter a l l']` and `[MeasureTheory.IsLocallyFiniteMeasure μ]`. If `l` is one of `𝓝[≥] a`, `𝓝[≤] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version also works, e.g., for `l = l' = Filter.atTop`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge' [IsMeasurablyGenerated l'] [TendstoIxxClass Ioc l l'] (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hl : μ.FiniteAtFilter l') (hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : v ≤ᶠ[lt] u) : (fun t => (∫ x in u t..v t, f x ∂μ) + (μ (Ioc (v t) (u t))).toReal • c) =o[lt] fun t => (μ <| Ioc (v t) (u t)).toReal := (measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' hfm hf hl hv hu huv).neg_left.congr_left fun t => by simp [integral_symm (u t), add_comm] #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge' intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge' section variable [IsLocallyFiniteMeasure μ] [FTCFilter a l l'] /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `[intervalIntegral.FTCFilter a l l']`; let `μ` be a locally finite measure. If `f` has a finite limit `c` at `l' ⊓ ae μ`, then `∫ x in u..v, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, 1 ∂μ)` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae'` for a version that also works, e.g., for `l = l' = Filter.atTop`. We use integrals of constants instead of measures because this way it is easier to formulate a statement that works in both cases `u ≤ v` and `v ≤ u`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt l) (hv : Tendsto v lt l) : (fun t => (∫ x in u t..v t, f x ∂μ) - ∫ _ in u t..v t, c ∂μ) =o[lt] fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := haveI := FTCFilter.meas_gen l measure_integral_sub_linear_isLittleO_of_tendsto_ae' hfm hf (FTCFilter.finiteAt_inner l) hu hv #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `[intervalIntegral.FTCFilter a l l']`; let `μ` be a locally finite measure. If `f` has a finite limit `c` at `l' ⊓ ae μ`, then `∫ x in u..v, f x ∂μ = μ (Ioc u v) • c + o(μ(Ioc u v))` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le'` for a version that also works, e.g., for `l = l' = Filter.atTop`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : u ≤ᶠ[lt] v) : (fun t => (∫ x in u t..v t, f x ∂μ) - (μ (Ioc (u t) (v t))).toReal • c) =o[lt] fun t => (μ <| Ioc (u t) (v t)).toReal := haveI := FTCFilter.meas_gen l measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' hfm hf (FTCFilter.finiteAt_inner l) hu hv huv #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_le intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `[intervalIntegral.FTCFilter a l l']`; let `μ` be a locally finite measure. If `f` has a finite limit `c` at `l' ⊓ ae μ`, then `∫ x in u..v, f x ∂μ = -μ (Set.Ioc v u) • c + o(μ(Set.Ioc v u))` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge'` for a version that also works, e.g., for `l = l' = Filter.atTop`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : v ≤ᶠ[lt] u) : (fun t => (∫ x in u t..v t, f x ∂μ) + (μ (Ioc (v t) (u t))).toReal • c) =o[lt] fun t => (μ <| Ioc (v t) (u t)).toReal := haveI := FTCFilter.meas_gen l measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge' hfm hf (FTCFilter.finiteAt_inner l) hu hv huv #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge end variable [FTCFilter a la la'] [FTCFilter b lb lb'] [IsLocallyFiniteMeasure μ] /-- **Fundamental theorem of calculus-1**, strict derivative in both limits for a locally finite measure. Let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of `intervalIntegral.FTCFilter`s around `a`; let `(lb, lb')` be a pair of `intervalIntegral.FTCFilter`s around `b`. Suppose that `f` has finite limits `ca` and `cb` at `la' ⊓ ae μ` and `lb' ⊓ ae μ`, respectively. Then `∫ x in va..vb, f x ∂μ - ∫ x in ua..ub, f x ∂μ = ∫ x in ub..vb, cb ∂μ - ∫ x in ua..va, ca ∂μ + o(‖∫ x in ua..va, (1:ℝ) ∂μ‖ + ‖∫ x in ub..vb, (1:ℝ) ∂μ‖)` as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. -/ theorem measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae (hab : IntervalIntegrable f μ a b) (hmeas_a : StronglyMeasurableAtFilter f la' μ) (hmeas_b : StronglyMeasurableAtFilter f lb' μ) (ha_lim : Tendsto f (la' ⊓ ae μ) (𝓝 ca)) (hb_lim : Tendsto f (lb' ⊓ ae μ) (𝓝 cb)) (hua : Tendsto ua lt la) (hva : Tendsto va lt la) (hub : Tendsto ub lt lb) (hvb : Tendsto vb lt lb) : (fun t => ((∫ x in va t..vb t, f x ∂μ) - ∫ x in ua t..ub t, f x ∂μ) - ((∫ _ in ub t..vb t, cb ∂μ) - ∫ _ in ua t..va t, ca ∂μ)) =o[lt] fun t => ‖∫ _ in ua t..va t, (1 : ℝ) ∂μ‖ + ‖∫ _ in ub t..vb t, (1 : ℝ) ∂μ‖ := by haveI := FTCFilter.meas_gen la; haveI := FTCFilter.meas_gen lb refine ((measure_integral_sub_linear_isLittleO_of_tendsto_ae hmeas_a ha_lim hua hva).neg_left.add_add (measure_integral_sub_linear_isLittleO_of_tendsto_ae hmeas_b hb_lim hub hvb)).congr' ?_ EventuallyEq.rfl have A : ∀ᶠ t in lt, IntervalIntegrable f μ (ua t) (va t) := ha_lim.eventually_intervalIntegrable_ae hmeas_a (FTCFilter.finiteAt_inner la) hua hva have A' : ∀ᶠ t in lt, IntervalIntegrable f μ a (ua t) := ha_lim.eventually_intervalIntegrable_ae hmeas_a (FTCFilter.finiteAt_inner la) (tendsto_const_pure.mono_right FTCFilter.pure_le) hua have B : ∀ᶠ t in lt, IntervalIntegrable f μ (ub t) (vb t) := hb_lim.eventually_intervalIntegrable_ae hmeas_b (FTCFilter.finiteAt_inner lb) hub hvb have B' : ∀ᶠ t in lt, IntervalIntegrable f μ b (ub t) := hb_lim.eventually_intervalIntegrable_ae hmeas_b (FTCFilter.finiteAt_inner lb) (tendsto_const_pure.mono_right FTCFilter.pure_le) hub filter_upwards [A, A', B, B'] with _ ua_va a_ua ub_vb b_ub rw [← integral_interval_sub_interval_comm'] · abel exacts [ub_vb, ua_va, b_ub.symm.trans <| hab.symm.trans a_ua] #align interval_integral.measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae /-- **Fundamental theorem of calculus-1**, strict derivative in right endpoint for a locally finite measure. Let `f` be a measurable function integrable on `a..b`. Let `(lb, lb')` be a pair of `intervalIntegral.FTCFilter`s around `b`. Suppose that `f` has a finite limit `c` at `lb' ⊓ ae μ`. Then `∫ x in a..v, f x ∂μ - ∫ x in a..u, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, (1:ℝ) ∂μ)` as `u` and `v` tend to `lb`. -/ theorem measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right (hab : IntervalIntegrable f μ a b) (hmeas : StronglyMeasurableAtFilter f lb' μ) (hf : Tendsto f (lb' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt lb) (hv : Tendsto v lt lb) : (fun t => ((∫ x in a..v t, f x ∂μ) - ∫ x in a..u t, f x ∂μ) - ∫ _ in u t..v t, c ∂μ) =o[lt] fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := by simpa using measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hab stronglyMeasurableAt_bot hmeas ((tendsto_bot : Tendsto _ ⊥ (𝓝 (0 : E))).mono_left inf_le_left) hf (tendsto_const_pure : Tendsto _ _ (pure a)) tendsto_const_pure hu hv #align interval_integral.measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae_right intervalIntegral.measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right /-- **Fundamental theorem of calculus-1**, strict derivative in left endpoint for a locally finite measure. Let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of `intervalIntegral.FTCFilter`s around `a`. Suppose that `f` has a finite limit `c` at `la' ⊓ ae μ`. Then `∫ x in v..b, f x ∂μ - ∫ x in u..b, f x ∂μ = -∫ x in u..v, c ∂μ + o(∫ x in u..v, (1:ℝ) ∂μ)` as `u` and `v` tend to `la`. -/ theorem measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left (hab : IntervalIntegrable f μ a b) (hmeas : StronglyMeasurableAtFilter f la' μ) (hf : Tendsto f (la' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt la) (hv : Tendsto v lt la) : (fun t => ((∫ x in v t..b, f x ∂μ) - ∫ x in u t..b, f x ∂μ) + ∫ _ in u t..v t, c ∂μ) =o[lt] fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := by simpa using measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hab hmeas stronglyMeasurableAt_bot hf ((tendsto_bot : Tendsto _ ⊥ (𝓝 (0 : E))).mono_left inf_le_left) hu hv (tendsto_const_pure : Tendsto _ _ (pure b)) tendsto_const_pure #align interval_integral.measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae_left intervalIntegral.measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left end /-! ### Fundamental theorem of calculus-1 for Lebesgue measure In this section we restate theorems from the previous section for Lebesgue measure. In particular, we prove that `∫ x in u..v, f x` is strictly differentiable in `(u, v)` at `(a, b)` provided that `f` is integrable on `a..b` and is continuous at `a` and `b`. -/ variable [CompleteSpace E] {f : ℝ → E} {c ca cb : E} {l l' la la' lb lb' : Filter ℝ} {lt : Filter ι} {a b z : ℝ} {u v ua ub va vb : ι → ℝ} [FTCFilter a la la'] [FTCFilter b lb lb'] /-! #### Auxiliary `Asymptotics.IsLittleO` statements In this section we prove several lemmas that can be interpreted as strict differentiability of `(u, v) ↦ ∫ x in u..v, f x ∂μ` in `u` and/or `v` at a filter. The statements use `Asymptotics.isLittleO` because we have no definition of `HasStrict(F)DerivAtFilter` in the library. -/ /-- **Fundamental theorem of calculus-1**, local version. If `f` has a finite limit `c` almost surely at `l'`, where `(l, l')` is an `intervalIntegral.FTCFilter` pair around `a`, then `∫ x in u..v, f x ∂μ = (v - u) • c + o (v - u)` as both `u` and `v` tend to `l`. -/
Mathlib/MeasureTheory/Integral/FundThmCalculus.lean
510
514
theorem integral_sub_linear_isLittleO_of_tendsto_ae [FTCFilter a l l'] (hfm : StronglyMeasurableAtFilter f l') (hf : Tendsto f (l' ⊓ ae volume) (𝓝 c)) {u v : ι → ℝ} (hu : Tendsto u lt l) (hv : Tendsto v lt l) : (fun t => (∫ x in u t..v t, f x) - (v t - u t) • c) =o[lt] (v - u) := by
simpa [integral_const] using measure_integral_sub_linear_isLittleO_of_tendsto_ae hfm hf hu hv
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Option.NAry import Mathlib.Data.Seq.Computation #align_import data.seq.seq from "leanprover-community/mathlib"@"a7e36e48519ab281320c4d192da6a7b348ce40ad" /-! # Possibly infinite lists This file provides a `Seq α` type representing possibly infinite lists (referred here as sequences). It is encoded as an infinite stream of options such that if `f n = none`, then `f m = none` for all `m ≥ n`. -/ namespace Stream' universe u v w /- coinductive seq (α : Type u) : Type u | nil : seq α | cons : α → seq α → seq α -/ /-- A stream `s : Option α` is a sequence if `s.get n = none` implies `s.get (n + 1) = none`. -/ def IsSeq {α : Type u} (s : Stream' (Option α)) : Prop := ∀ {n : ℕ}, s n = none → s (n + 1) = none #align stream.is_seq Stream'.IsSeq /-- `Seq α` is the type of possibly infinite lists (referred here as sequences). It is encoded as an infinite stream of options such that if `f n = none`, then `f m = none` for all `m ≥ n`. -/ def Seq (α : Type u) : Type u := { f : Stream' (Option α) // f.IsSeq } #align stream.seq Stream'.Seq /-- `Seq1 α` is the type of nonempty sequences. -/ def Seq1 (α) := α × Seq α #align stream.seq1 Stream'.Seq1 namespace Seq variable {α : Type u} {β : Type v} {γ : Type w} /-- The empty sequence -/ def nil : Seq α := ⟨Stream'.const none, fun {_} _ => rfl⟩ #align stream.seq.nil Stream'.Seq.nil instance : Inhabited (Seq α) := ⟨nil⟩ /-- Prepend an element to a sequence -/ def cons (a : α) (s : Seq α) : Seq α := ⟨some a::s.1, by rintro (n | _) h · contradiction · exact s.2 h⟩ #align stream.seq.cons Stream'.Seq.cons @[simp] theorem val_cons (s : Seq α) (x : α) : (cons x s).val = some x::s.val := rfl #align stream.seq.val_cons Stream'.Seq.val_cons /-- Get the nth element of a sequence (if it exists) -/ def get? : Seq α → ℕ → Option α := Subtype.val #align stream.seq.nth Stream'.Seq.get? @[simp] theorem get?_mk (f hf) : @get? α ⟨f, hf⟩ = f := rfl #align stream.seq.nth_mk Stream'.Seq.get?_mk @[simp] theorem get?_nil (n : ℕ) : (@nil α).get? n = none := rfl #align stream.seq.nth_nil Stream'.Seq.get?_nil @[simp] theorem get?_cons_zero (a : α) (s : Seq α) : (cons a s).get? 0 = some a := rfl #align stream.seq.nth_cons_zero Stream'.Seq.get?_cons_zero @[simp] theorem get?_cons_succ (a : α) (s : Seq α) (n : ℕ) : (cons a s).get? (n + 1) = s.get? n := rfl #align stream.seq.nth_cons_succ Stream'.Seq.get?_cons_succ @[ext] protected theorem ext {s t : Seq α} (h : ∀ n : ℕ, s.get? n = t.get? n) : s = t := Subtype.eq <| funext h #align stream.seq.ext Stream'.Seq.ext theorem cons_injective2 : Function.Injective2 (cons : α → Seq α → Seq α) := fun x y s t h => ⟨by rw [← Option.some_inj, ← get?_cons_zero, h, get?_cons_zero], Seq.ext fun n => by simp_rw [← get?_cons_succ x s n, h, get?_cons_succ]⟩ #align stream.seq.cons_injective2 Stream'.Seq.cons_injective2 theorem cons_left_injective (s : Seq α) : Function.Injective fun x => cons x s := cons_injective2.left _ #align stream.seq.cons_left_injective Stream'.Seq.cons_left_injective theorem cons_right_injective (x : α) : Function.Injective (cons x) := cons_injective2.right _ #align stream.seq.cons_right_injective Stream'.Seq.cons_right_injective /-- A sequence has terminated at position `n` if the value at position `n` equals `none`. -/ def TerminatedAt (s : Seq α) (n : ℕ) : Prop := s.get? n = none #align stream.seq.terminated_at Stream'.Seq.TerminatedAt /-- It is decidable whether a sequence terminates at a given position. -/ instance terminatedAtDecidable (s : Seq α) (n : ℕ) : Decidable (s.TerminatedAt n) := decidable_of_iff' (s.get? n).isNone <| by unfold TerminatedAt; cases s.get? n <;> simp #align stream.seq.terminated_at_decidable Stream'.Seq.terminatedAtDecidable /-- A sequence terminates if there is some position `n` at which it has terminated. -/ def Terminates (s : Seq α) : Prop := ∃ n : ℕ, s.TerminatedAt n #align stream.seq.terminates Stream'.Seq.Terminates theorem not_terminates_iff {s : Seq α} : ¬s.Terminates ↔ ∀ n, (s.get? n).isSome := by simp only [Terminates, TerminatedAt, ← Ne.eq_def, Option.ne_none_iff_isSome, not_exists, iff_self] #align stream.seq.not_terminates_iff Stream'.Seq.not_terminates_iff /-- Functorial action of the functor `Option (α × _)` -/ @[simp] def omap (f : β → γ) : Option (α × β) → Option (α × γ) | none => none | some (a, b) => some (a, f b) #align stream.seq.omap Stream'.Seq.omap /-- Get the first element of a sequence -/ def head (s : Seq α) : Option α := get? s 0 #align stream.seq.head Stream'.Seq.head /-- Get the tail of a sequence (or `nil` if the sequence is `nil`) -/ def tail (s : Seq α) : Seq α := ⟨s.1.tail, fun n' => by cases' s with f al exact al n'⟩ #align stream.seq.tail Stream'.Seq.tail /-- member definition for `Seq`-/ protected def Mem (a : α) (s : Seq α) := some a ∈ s.1 #align stream.seq.mem Stream'.Seq.Mem instance : Membership α (Seq α) := ⟨Seq.Mem⟩ theorem le_stable (s : Seq α) {m n} (h : m ≤ n) : s.get? m = none → s.get? n = none := by cases' s with f al induction' h with n _ IH exacts [id, fun h2 => al (IH h2)] #align stream.seq.le_stable Stream'.Seq.le_stable /-- If a sequence terminated at position `n`, it also terminated at `m ≥ n`. -/ theorem terminated_stable : ∀ (s : Seq α) {m n : ℕ}, m ≤ n → s.TerminatedAt m → s.TerminatedAt n := le_stable #align stream.seq.terminated_stable Stream'.Seq.terminated_stable /-- If `s.get? n = some aₙ` for some value `aₙ`, then there is also some value `aₘ` such that `s.get? = some aₘ` for `m ≤ n`. -/ theorem ge_stable (s : Seq α) {aₙ : α} {n m : ℕ} (m_le_n : m ≤ n) (s_nth_eq_some : s.get? n = some aₙ) : ∃ aₘ : α, s.get? m = some aₘ := have : s.get? n ≠ none := by simp [s_nth_eq_some] have : s.get? m ≠ none := mt (s.le_stable m_le_n) this Option.ne_none_iff_exists'.mp this #align stream.seq.ge_stable Stream'.Seq.ge_stable theorem not_mem_nil (a : α) : a ∉ @nil α := fun ⟨_, (h : some a = none)⟩ => by injection h #align stream.seq.not_mem_nil Stream'.Seq.not_mem_nil theorem mem_cons (a : α) : ∀ s : Seq α, a ∈ cons a s | ⟨_, _⟩ => Stream'.mem_cons (some a) _ #align stream.seq.mem_cons Stream'.Seq.mem_cons theorem mem_cons_of_mem (y : α) {a : α} : ∀ {s : Seq α}, a ∈ s → a ∈ cons y s | ⟨_, _⟩ => Stream'.mem_cons_of_mem (some y) #align stream.seq.mem_cons_of_mem Stream'.Seq.mem_cons_of_mem theorem eq_or_mem_of_mem_cons {a b : α} : ∀ {s : Seq α}, a ∈ cons b s → a = b ∨ a ∈ s | ⟨f, al⟩, h => (Stream'.eq_or_mem_of_mem_cons h).imp_left fun h => by injection h #align stream.seq.eq_or_mem_of_mem_cons Stream'.Seq.eq_or_mem_of_mem_cons @[simp] theorem mem_cons_iff {a b : α} {s : Seq α} : a ∈ cons b s ↔ a = b ∨ a ∈ s := ⟨eq_or_mem_of_mem_cons, by rintro (rfl | m) <;> [apply mem_cons; exact mem_cons_of_mem _ m]⟩ #align stream.seq.mem_cons_iff Stream'.Seq.mem_cons_iff /-- Destructor for a sequence, resulting in either `none` (for `nil`) or `some (a, s)` (for `cons a s`). -/ def destruct (s : Seq α) : Option (Seq1 α) := (fun a' => (a', s.tail)) <$> get? s 0 #align stream.seq.destruct Stream'.Seq.destruct theorem destruct_eq_nil {s : Seq α} : destruct s = none → s = nil := by dsimp [destruct] induction' f0 : get? s 0 <;> intro h · apply Subtype.eq funext n induction' n with n IH exacts [f0, s.2 IH] · contradiction #align stream.seq.destruct_eq_nil Stream'.Seq.destruct_eq_nil theorem destruct_eq_cons {s : Seq α} {a s'} : destruct s = some (a, s') → s = cons a s' := by dsimp [destruct] induction' f0 : get? s 0 with a' <;> intro h · contradiction · cases' s with f al injections _ h1 h2 rw [← h2] apply Subtype.eq dsimp [tail, cons] rw [h1] at f0 rw [← f0] exact (Stream'.eta f).symm #align stream.seq.destruct_eq_cons Stream'.Seq.destruct_eq_cons @[simp] theorem destruct_nil : destruct (nil : Seq α) = none := rfl #align stream.seq.destruct_nil Stream'.Seq.destruct_nil @[simp] theorem destruct_cons (a : α) : ∀ s, destruct (cons a s) = some (a, s) | ⟨f, al⟩ => by unfold cons destruct Functor.map apply congr_arg fun s => some (a, s) apply Subtype.eq; dsimp [tail] #align stream.seq.destruct_cons Stream'.Seq.destruct_cons -- Porting note: needed universe annotation to avoid universe issues theorem head_eq_destruct (s : Seq α) : head.{u} s = Prod.fst.{u} <$> destruct.{u} s := by unfold destruct head; cases get? s 0 <;> rfl #align stream.seq.head_eq_destruct Stream'.Seq.head_eq_destruct @[simp] theorem head_nil : head (nil : Seq α) = none := rfl #align stream.seq.head_nil Stream'.Seq.head_nil @[simp] theorem head_cons (a : α) (s) : head (cons a s) = some a := by rw [head_eq_destruct, destruct_cons, Option.map_eq_map, Option.map_some'] #align stream.seq.head_cons Stream'.Seq.head_cons @[simp] theorem tail_nil : tail (nil : Seq α) = nil := rfl #align stream.seq.tail_nil Stream'.Seq.tail_nil @[simp] theorem tail_cons (a : α) (s) : tail (cons a s) = s := by cases' s with f al apply Subtype.eq dsimp [tail, cons] #align stream.seq.tail_cons Stream'.Seq.tail_cons @[simp] theorem get?_tail (s : Seq α) (n) : get? (tail s) n = get? s (n + 1) := rfl #align stream.seq.nth_tail Stream'.Seq.get?_tail /-- Recursion principle for sequences, compare with `List.recOn`. -/ def recOn {C : Seq α → Sort v} (s : Seq α) (h1 : C nil) (h2 : ∀ x s, C (cons x s)) : C s := by cases' H : destruct s with v · rw [destruct_eq_nil H] apply h1 · cases' v with a s' rw [destruct_eq_cons H] apply h2 #align stream.seq.rec_on Stream'.Seq.recOn
Mathlib/Data/Seq/Seq.lean
287
304
theorem mem_rec_on {C : Seq α → Prop} {a s} (M : a ∈ s) (h1 : ∀ b s', a = b ∨ C s' → C (cons b s')) : C s := by
cases' M with k e; unfold Stream'.get at e induction' k with k IH generalizing s · have TH : s = cons a (tail s) := by apply destruct_eq_cons unfold destruct get? Functor.map rw [← e] rfl rw [TH] apply h1 _ _ (Or.inl rfl) -- Porting note: had to reshuffle `intro` revert e; apply s.recOn _ fun b s' => _ · intro e; injection e · intro b s' e have h_eq : (cons b s').val (Nat.succ k) = s'.val k := by cases s'; rfl rw [h_eq] at e apply h1 _ _ (Or.inr (IH e))
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Manuel Candales -/ import Mathlib.Analysis.InnerProductSpace.Projection import Mathlib.Geometry.Euclidean.PerpBisector import Mathlib.Algebra.QuadraticDiscriminant #align_import geometry.euclidean.basic from "leanprover-community/mathlib"@"2de9c37fa71dde2f1c6feff19876dd6a7b1519f0" /-! # Euclidean spaces This file makes some definitions and proves very basic geometrical results about real inner product spaces and Euclidean affine spaces. Results about real inner product spaces that involve the norm and inner product but not angles generally go in `Analysis.NormedSpace.InnerProduct`. Results with longer proofs or more geometrical content generally go in separate files. ## Main definitions * `EuclideanGeometry.orthogonalProjection` is the orthogonal projection of a point onto an affine subspace. * `EuclideanGeometry.reflection` is the reflection of a point in an affine subspace. ## Implementation notes To declare `P` as the type of points in a Euclidean affine space with `V` as the type of vectors, use `[NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P]`. This works better with `outParam` to make `V` implicit in most cases than having a separate type alias for Euclidean affine spaces. Rather than requiring Euclidean affine spaces to be finite-dimensional (as in the definition on Wikipedia), this is specified only for those theorems that need it. ## References * https://en.wikipedia.org/wiki/Euclidean_space -/ noncomputable section open scoped Classical open RealInnerProductSpace namespace EuclideanGeometry /-! ### Geometrical results on Euclidean affine spaces This section develops some geometrical definitions and results on Euclidean affine spaces. -/ variable {V : Type*} {P : Type*} variable [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] variable [NormedAddTorsor V P] /-- The midpoint of the segment AB is the same distance from A as it is from B. -/ theorem dist_left_midpoint_eq_dist_right_midpoint (p1 p2 : P) : dist p1 (midpoint ℝ p1 p2) = dist p2 (midpoint ℝ p1 p2) := by rw [dist_left_midpoint (𝕜 := ℝ) p1 p2, dist_right_midpoint (𝕜 := ℝ) p1 p2] #align euclidean_geometry.dist_left_midpoint_eq_dist_right_midpoint EuclideanGeometry.dist_left_midpoint_eq_dist_right_midpoint /-- The inner product of two vectors given with `weightedVSub`, in terms of the pairwise distances. -/ theorem inner_weightedVSub {ι₁ : Type*} {s₁ : Finset ι₁} {w₁ : ι₁ → ℝ} (p₁ : ι₁ → P) (h₁ : ∑ i ∈ s₁, w₁ i = 0) {ι₂ : Type*} {s₂ : Finset ι₂} {w₂ : ι₂ → ℝ} (p₂ : ι₂ → P) (h₂ : ∑ i ∈ s₂, w₂ i = 0) : ⟪s₁.weightedVSub p₁ w₁, s₂.weightedVSub p₂ w₂⟫ = (-∑ i₁ ∈ s₁, ∑ i₂ ∈ s₂, w₁ i₁ * w₂ i₂ * (dist (p₁ i₁) (p₂ i₂) * dist (p₁ i₁) (p₂ i₂))) / 2 := by rw [Finset.weightedVSub_apply, Finset.weightedVSub_apply, inner_sum_smul_sum_smul_of_sum_eq_zero _ h₁ _ h₂] simp_rw [vsub_sub_vsub_cancel_right] rcongr (i₁ i₂) <;> rw [dist_eq_norm_vsub V (p₁ i₁) (p₂ i₂)] #align euclidean_geometry.inner_weighted_vsub EuclideanGeometry.inner_weightedVSub /-- The distance between two points given with `affineCombination`, in terms of the pairwise distances between the points in that combination. -/ theorem dist_affineCombination {ι : Type*} {s : Finset ι} {w₁ w₂ : ι → ℝ} (p : ι → P) (h₁ : ∑ i ∈ s, w₁ i = 1) (h₂ : ∑ i ∈ s, w₂ i = 1) : by have a₁ := s.affineCombination ℝ p w₁ have a₂ := s.affineCombination ℝ p w₂ exact dist a₁ a₂ * dist a₁ a₂ = (-∑ i₁ ∈ s, ∑ i₂ ∈ s, (w₁ - w₂) i₁ * (w₁ - w₂) i₂ * (dist (p i₁) (p i₂) * dist (p i₁) (p i₂))) / 2 := by dsimp only rw [dist_eq_norm_vsub V (s.affineCombination ℝ p w₁) (s.affineCombination ℝ p w₂), ← @inner_self_eq_norm_mul_norm ℝ, Finset.affineCombination_vsub] have h : (∑ i ∈ s, (w₁ - w₂) i) = 0 := by simp_rw [Pi.sub_apply, Finset.sum_sub_distrib, h₁, h₂, sub_self] exact inner_weightedVSub p h p h #align euclidean_geometry.dist_affine_combination EuclideanGeometry.dist_affineCombination -- Porting note: `inner_vsub_vsub_of_dist_eq_of_dist_eq` moved to `PerpendicularBisector` /-- The squared distance between points on a line (expressed as a multiple of a fixed vector added to a point) and another point, expressed as a quadratic. -/ theorem dist_smul_vadd_sq (r : ℝ) (v : V) (p₁ p₂ : P) : dist (r • v +ᵥ p₁) p₂ * dist (r • v +ᵥ p₁) p₂ = ⟪v, v⟫ * r * r + 2 * ⟪v, p₁ -ᵥ p₂⟫ * r + ⟪p₁ -ᵥ p₂, p₁ -ᵥ p₂⟫ := by rw [dist_eq_norm_vsub V _ p₂, ← real_inner_self_eq_norm_mul_norm, vadd_vsub_assoc, real_inner_add_add_self, real_inner_smul_left, real_inner_smul_left, real_inner_smul_right] ring #align euclidean_geometry.dist_smul_vadd_sq EuclideanGeometry.dist_smul_vadd_sq /-- The condition for two points on a line to be equidistant from another point. -/ theorem dist_smul_vadd_eq_dist {v : V} (p₁ p₂ : P) (hv : v ≠ 0) (r : ℝ) : dist (r • v +ᵥ p₁) p₂ = dist p₁ p₂ ↔ r = 0 ∨ r = -2 * ⟪v, p₁ -ᵥ p₂⟫ / ⟪v, v⟫ := by conv_lhs => rw [← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, dist_smul_vadd_sq, ← sub_eq_zero, add_sub_assoc, dist_eq_norm_vsub V p₁ p₂, ← real_inner_self_eq_norm_mul_norm, sub_self] have hvi : ⟪v, v⟫ ≠ 0 := by simpa using hv have hd : discrim ⟪v, v⟫ (2 * ⟪v, p₁ -ᵥ p₂⟫) 0 = 2 * ⟪v, p₁ -ᵥ p₂⟫ * (2 * ⟪v, p₁ -ᵥ p₂⟫) := by rw [discrim] ring rw [quadratic_eq_zero_iff hvi hd, add_left_neg, zero_div, neg_mul_eq_neg_mul, ← mul_sub_right_distrib, sub_eq_add_neg, ← mul_two, mul_assoc, mul_div_assoc, mul_div_mul_left, mul_div_assoc] norm_num #align euclidean_geometry.dist_smul_vadd_eq_dist EuclideanGeometry.dist_smul_vadd_eq_dist open AffineSubspace FiniteDimensional /-- Distances `r₁` `r₂` of `p` from two different points `c₁` `c₂` determine at most two points `p₁` `p₂` in a two-dimensional subspace containing those points (two circles intersect in at most two points). -/ theorem eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two {s : AffineSubspace ℝ P} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = 2) {c₁ c₂ p₁ p₂ p : P} (hc₁s : c₁ ∈ s) (hc₂s : c₂ ∈ s) (hp₁s : p₁ ∈ s) (hp₂s : p₂ ∈ s) (hps : p ∈ s) {r₁ r₂ : ℝ} (hc : c₁ ≠ c₂) (hp : p₁ ≠ p₂) (hp₁c₁ : dist p₁ c₁ = r₁) (hp₂c₁ : dist p₂ c₁ = r₁) (hpc₁ : dist p c₁ = r₁) (hp₁c₂ : dist p₁ c₂ = r₂) (hp₂c₂ : dist p₂ c₂ = r₂) (hpc₂ : dist p c₂ = r₂) : p = p₁ ∨ p = p₂ := by have ho : ⟪c₂ -ᵥ c₁, p₂ -ᵥ p₁⟫ = 0 := inner_vsub_vsub_of_dist_eq_of_dist_eq (hp₁c₁.trans hp₂c₁.symm) (hp₁c₂.trans hp₂c₂.symm) have hop : ⟪c₂ -ᵥ c₁, p -ᵥ p₁⟫ = 0 := inner_vsub_vsub_of_dist_eq_of_dist_eq (hp₁c₁.trans hpc₁.symm) (hp₁c₂.trans hpc₂.symm) let b : Fin 2 → V := ![c₂ -ᵥ c₁, p₂ -ᵥ p₁] have hb : LinearIndependent ℝ b := by refine linearIndependent_of_ne_zero_of_inner_eq_zero ?_ ?_ · intro i fin_cases i <;> simp [b, hc.symm, hp.symm] · intro i j hij fin_cases i <;> fin_cases j <;> try exact False.elim (hij rfl) · exact ho · rw [real_inner_comm] exact ho have hbs : Submodule.span ℝ (Set.range b) = s.direction := by refine eq_of_le_of_finrank_eq ?_ ?_ · rw [Submodule.span_le, Set.range_subset_iff] intro i fin_cases i · exact vsub_mem_direction hc₂s hc₁s · exact vsub_mem_direction hp₂s hp₁s · rw [finrank_span_eq_card hb, Fintype.card_fin, hd] have hv : ∀ v ∈ s.direction, ∃ t₁ t₂ : ℝ, v = t₁ • (c₂ -ᵥ c₁) + t₂ • (p₂ -ᵥ p₁) := by intro v hv have hr : Set.range b = {c₂ -ᵥ c₁, p₂ -ᵥ p₁} := by have hu : (Finset.univ : Finset (Fin 2)) = {0, 1} := by decide rw [← Fintype.coe_image_univ, hu] simp [b] rw [← hbs, hr, Submodule.mem_span_insert] at hv rcases hv with ⟨t₁, v', hv', hv⟩ rw [Submodule.mem_span_singleton] at hv' rcases hv' with ⟨t₂, rfl⟩ exact ⟨t₁, t₂, hv⟩ rcases hv (p -ᵥ p₁) (vsub_mem_direction hps hp₁s) with ⟨t₁, t₂, hpt⟩ simp only [hpt, inner_add_right, inner_smul_right, ho, mul_zero, add_zero, mul_eq_zero, inner_self_eq_zero, vsub_eq_zero_iff_eq, hc.symm, or_false_iff] at hop rw [hop, zero_smul, zero_add, ← eq_vadd_iff_vsub_eq] at hpt subst hpt have hp' : (p₂ -ᵥ p₁ : V) ≠ 0 := by simp [hp.symm] have hp₂ : dist ((1 : ℝ) • (p₂ -ᵥ p₁) +ᵥ p₁) c₁ = r₁ := by simp [hp₂c₁] rw [← hp₁c₁, dist_smul_vadd_eq_dist _ _ hp'] at hpc₁ hp₂ simp only [one_ne_zero, false_or_iff] at hp₂ rw [hp₂.symm] at hpc₁ cases' hpc₁ with hpc₁ hpc₁ <;> simp [hpc₁] #align euclidean_geometry.eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two EuclideanGeometry.eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two /-- Distances `r₁` `r₂` of `p` from two different points `c₁` `c₂` determine at most two points `p₁` `p₂` in two-dimensional space (two circles intersect in at most two points). -/ theorem eq_of_dist_eq_of_dist_eq_of_finrank_eq_two [FiniteDimensional ℝ V] (hd : finrank ℝ V = 2) {c₁ c₂ p₁ p₂ p : P} {r₁ r₂ : ℝ} (hc : c₁ ≠ c₂) (hp : p₁ ≠ p₂) (hp₁c₁ : dist p₁ c₁ = r₁) (hp₂c₁ : dist p₂ c₁ = r₁) (hpc₁ : dist p c₁ = r₁) (hp₁c₂ : dist p₁ c₂ = r₂) (hp₂c₂ : dist p₂ c₂ = r₂) (hpc₂ : dist p c₂ = r₂) : p = p₁ ∨ p = p₂ := haveI hd' : finrank ℝ (⊤ : AffineSubspace ℝ P).direction = 2 := by rw [direction_top, finrank_top] exact hd eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two hd' (mem_top ℝ V _) (mem_top ℝ V _) (mem_top ℝ V _) (mem_top ℝ V _) (mem_top ℝ V _) hc hp hp₁c₁ hp₂c₁ hpc₁ hp₁c₂ hp₂c₂ hpc₂ #align euclidean_geometry.eq_of_dist_eq_of_dist_eq_of_finrank_eq_two EuclideanGeometry.eq_of_dist_eq_of_dist_eq_of_finrank_eq_two /-- The orthogonal projection of a point onto a nonempty affine subspace, whose direction is complete, as an unbundled function. This definition is only intended for use in setting up the bundled version `orthogonalProjection` and should not be used once that is defined. -/ def orthogonalProjectionFn (s : AffineSubspace ℝ P) [Nonempty s] [HasOrthogonalProjection s.direction] (p : P) : P := Classical.choose <| inter_eq_singleton_of_nonempty_of_isCompl (nonempty_subtype.mp ‹_›) (mk'_nonempty p s.directionᗮ) (by rw [direction_mk' p s.directionᗮ] exact Submodule.isCompl_orthogonal_of_completeSpace) #align euclidean_geometry.orthogonal_projection_fn EuclideanGeometry.orthogonalProjectionFn /-- The intersection of the subspace and the orthogonal subspace through the given point is the `orthogonalProjectionFn` of that point onto the subspace. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem inter_eq_singleton_orthogonalProjectionFn {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] (p : P) : (s : Set P) ∩ mk' p s.directionᗮ = {orthogonalProjectionFn s p} := Classical.choose_spec <| inter_eq_singleton_of_nonempty_of_isCompl (nonempty_subtype.mp ‹_›) (mk'_nonempty p s.directionᗮ) (by rw [direction_mk' p s.directionᗮ] exact Submodule.isCompl_orthogonal_of_completeSpace) #align euclidean_geometry.inter_eq_singleton_orthogonal_projection_fn EuclideanGeometry.inter_eq_singleton_orthogonalProjectionFn /-- The `orthogonalProjectionFn` lies in the given subspace. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_mem {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] (p : P) : orthogonalProjectionFn s p ∈ s := by rw [← mem_coe, ← Set.singleton_subset_iff, ← inter_eq_singleton_orthogonalProjectionFn] exact Set.inter_subset_left #align euclidean_geometry.orthogonal_projection_fn_mem EuclideanGeometry.orthogonalProjectionFn_mem /-- The `orthogonalProjectionFn` lies in the orthogonal subspace. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_mem_orthogonal {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] (p : P) : orthogonalProjectionFn s p ∈ mk' p s.directionᗮ := by rw [← mem_coe, ← Set.singleton_subset_iff, ← inter_eq_singleton_orthogonalProjectionFn] exact Set.inter_subset_right #align euclidean_geometry.orthogonal_projection_fn_mem_orthogonal EuclideanGeometry.orthogonalProjectionFn_mem_orthogonal /-- Subtracting `p` from its `orthogonalProjectionFn` produces a result in the orthogonal direction. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_vsub_mem_direction_orthogonal {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] (p : P) : orthogonalProjectionFn s p -ᵥ p ∈ s.directionᗮ := direction_mk' p s.directionᗮ ▸ vsub_mem_direction (orthogonalProjectionFn_mem_orthogonal p) (self_mem_mk' _ _) #align euclidean_geometry.orthogonal_projection_fn_vsub_mem_direction_orthogonal EuclideanGeometry.orthogonalProjectionFn_vsub_mem_direction_orthogonal attribute [local instance] AffineSubspace.toAddTorsor /-- The orthogonal projection of a point onto a nonempty affine subspace, whose direction is complete. The corresponding linear map (mapping a vector to the difference between the projections of two points whose difference is that vector) is the `orthogonalProjection` for real inner product spaces, onto the direction of the affine subspace being projected onto. -/ nonrec def orthogonalProjection (s : AffineSubspace ℝ P) [Nonempty s] [HasOrthogonalProjection s.direction] : P →ᵃ[ℝ] s where toFun p := ⟨orthogonalProjectionFn s p, orthogonalProjectionFn_mem p⟩ linear := orthogonalProjection s.direction map_vadd' p v := by have hs : ((orthogonalProjection s.direction) v : V) +ᵥ orthogonalProjectionFn s p ∈ s := vadd_mem_of_mem_direction (orthogonalProjection s.direction v).2 (orthogonalProjectionFn_mem p) have ho : ((orthogonalProjection s.direction) v : V) +ᵥ orthogonalProjectionFn s p ∈ mk' (v +ᵥ p) s.directionᗮ := by rw [← vsub_right_mem_direction_iff_mem (self_mem_mk' _ _) _, direction_mk', vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_comm, add_sub_assoc] refine Submodule.add_mem _ (orthogonalProjectionFn_vsub_mem_direction_orthogonal p) ?_ rw [Submodule.mem_orthogonal'] intro w hw rw [← neg_sub, inner_neg_left, orthogonalProjection_inner_eq_zero _ w hw, neg_zero] have hm : ((orthogonalProjection s.direction) v : V) +ᵥ orthogonalProjectionFn s p ∈ ({orthogonalProjectionFn s (v +ᵥ p)} : Set P) := by rw [← inter_eq_singleton_orthogonalProjectionFn (v +ᵥ p)] exact Set.mem_inter hs ho rw [Set.mem_singleton_iff] at hm ext exact hm.symm #align euclidean_geometry.orthogonal_projection EuclideanGeometry.orthogonalProjection @[simp] theorem orthogonalProjectionFn_eq {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] (p : P) : orthogonalProjectionFn s p = orthogonalProjection s p := rfl #align euclidean_geometry.orthogonal_projection_fn_eq EuclideanGeometry.orthogonalProjectionFn_eq /-- The linear map corresponding to `orthogonalProjection`. -/ @[simp] theorem orthogonalProjection_linear {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] : (orthogonalProjection s).linear = _root_.orthogonalProjection s.direction := rfl #align euclidean_geometry.orthogonal_projection_linear EuclideanGeometry.orthogonalProjection_linear /-- The intersection of the subspace and the orthogonal subspace through the given point is the `orthogonalProjection` of that point onto the subspace. -/ theorem inter_eq_singleton_orthogonalProjection {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] (p : P) : (s : Set P) ∩ mk' p s.directionᗮ = {↑(orthogonalProjection s p)} := by rw [← orthogonalProjectionFn_eq] exact inter_eq_singleton_orthogonalProjectionFn p #align euclidean_geometry.inter_eq_singleton_orthogonal_projection EuclideanGeometry.inter_eq_singleton_orthogonalProjection /-- The `orthogonalProjection` lies in the given subspace. -/ theorem orthogonalProjection_mem {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] (p : P) : ↑(orthogonalProjection s p) ∈ s := (orthogonalProjection s p).2 #align euclidean_geometry.orthogonal_projection_mem EuclideanGeometry.orthogonalProjection_mem /-- The `orthogonalProjection` lies in the orthogonal subspace. -/ theorem orthogonalProjection_mem_orthogonal (s : AffineSubspace ℝ P) [Nonempty s] [HasOrthogonalProjection s.direction] (p : P) : ↑(orthogonalProjection s p) ∈ mk' p s.directionᗮ := orthogonalProjectionFn_mem_orthogonal p #align euclidean_geometry.orthogonal_projection_mem_orthogonal EuclideanGeometry.orthogonalProjection_mem_orthogonal /-- Subtracting a point in the given subspace from the `orthogonalProjection` produces a result in the direction of the given subspace. -/ theorem orthogonalProjection_vsub_mem_direction {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {p1 : P} (p2 : P) (hp1 : p1 ∈ s) : ↑(orthogonalProjection s p2 -ᵥ ⟨p1, hp1⟩ : s.direction) ∈ s.direction := (orthogonalProjection s p2 -ᵥ ⟨p1, hp1⟩ : s.direction).2 #align euclidean_geometry.orthogonal_projection_vsub_mem_direction EuclideanGeometry.orthogonalProjection_vsub_mem_direction /-- Subtracting the `orthogonalProjection` from a point in the given subspace produces a result in the direction of the given subspace. -/ theorem vsub_orthogonalProjection_mem_direction {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {p1 : P} (p2 : P) (hp1 : p1 ∈ s) : ↑((⟨p1, hp1⟩ : s) -ᵥ orthogonalProjection s p2 : s.direction) ∈ s.direction := ((⟨p1, hp1⟩ : s) -ᵥ orthogonalProjection s p2 : s.direction).2 #align euclidean_geometry.vsub_orthogonal_projection_mem_direction EuclideanGeometry.vsub_orthogonalProjection_mem_direction /-- A point equals its orthogonal projection if and only if it lies in the subspace. -/ theorem orthogonalProjection_eq_self_iff {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {p : P} : ↑(orthogonalProjection s p) = p ↔ p ∈ s := by constructor · exact fun h => h ▸ orthogonalProjection_mem p · intro h have hp : p ∈ (s : Set P) ∩ mk' p s.directionᗮ := ⟨h, self_mem_mk' p _⟩ rw [inter_eq_singleton_orthogonalProjection p] at hp symm exact hp #align euclidean_geometry.orthogonal_projection_eq_self_iff EuclideanGeometry.orthogonalProjection_eq_self_iff @[simp] theorem orthogonalProjection_mem_subspace_eq_self {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] (p : s) : orthogonalProjection s p = p := by ext rw [orthogonalProjection_eq_self_iff] exact p.2 #align euclidean_geometry.orthogonal_projection_mem_subspace_eq_self EuclideanGeometry.orthogonalProjection_mem_subspace_eq_self /-- Orthogonal projection is idempotent. -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem orthogonalProjection_orthogonalProjection (s : AffineSubspace ℝ P) [Nonempty s] [HasOrthogonalProjection s.direction] (p : P) : orthogonalProjection s (orthogonalProjection s p) = orthogonalProjection s p := by ext rw [orthogonalProjection_eq_self_iff] exact orthogonalProjection_mem p #align euclidean_geometry.orthogonal_projection_orthogonal_projection EuclideanGeometry.orthogonalProjection_orthogonalProjection theorem eq_orthogonalProjection_of_eq_subspace {s s' : AffineSubspace ℝ P} [Nonempty s] [Nonempty s'] [HasOrthogonalProjection s.direction] [HasOrthogonalProjection s'.direction] (h : s = s') (p : P) : (orthogonalProjection s p : P) = (orthogonalProjection s' p : P) := by subst h rfl #align euclidean_geometry.eq_orthogonal_projection_of_eq_subspace EuclideanGeometry.eq_orthogonalProjection_of_eq_subspace /-- The distance to a point's orthogonal projection is 0 iff it lies in the subspace. -/ theorem dist_orthogonalProjection_eq_zero_iff {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {p : P} : dist p (orthogonalProjection s p) = 0 ↔ p ∈ s := by rw [dist_comm, dist_eq_zero, orthogonalProjection_eq_self_iff] #align euclidean_geometry.dist_orthogonal_projection_eq_zero_iff EuclideanGeometry.dist_orthogonalProjection_eq_zero_iff /-- The distance between a point and its orthogonal projection is nonzero if it does not lie in the subspace. -/ theorem dist_orthogonalProjection_ne_zero_of_not_mem {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {p : P} (hp : p ∉ s) : dist p (orthogonalProjection s p) ≠ 0 := mt dist_orthogonalProjection_eq_zero_iff.mp hp #align euclidean_geometry.dist_orthogonal_projection_ne_zero_of_not_mem EuclideanGeometry.dist_orthogonalProjection_ne_zero_of_not_mem /-- Subtracting `p` from its `orthogonalProjection` produces a result in the orthogonal direction. -/ theorem orthogonalProjection_vsub_mem_direction_orthogonal (s : AffineSubspace ℝ P) [Nonempty s] [HasOrthogonalProjection s.direction] (p : P) : (orthogonalProjection s p : P) -ᵥ p ∈ s.directionᗮ := orthogonalProjectionFn_vsub_mem_direction_orthogonal p #align euclidean_geometry.orthogonal_projection_vsub_mem_direction_orthogonal EuclideanGeometry.orthogonalProjection_vsub_mem_direction_orthogonal /-- Subtracting the `orthogonalProjection` from `p` produces a result in the orthogonal direction. -/ theorem vsub_orthogonalProjection_mem_direction_orthogonal (s : AffineSubspace ℝ P) [Nonempty s] [HasOrthogonalProjection s.direction] (p : P) : p -ᵥ orthogonalProjection s p ∈ s.directionᗮ := direction_mk' p s.directionᗮ ▸ vsub_mem_direction (self_mem_mk' _ _) (orthogonalProjection_mem_orthogonal s p) #align euclidean_geometry.vsub_orthogonal_projection_mem_direction_orthogonal EuclideanGeometry.vsub_orthogonalProjection_mem_direction_orthogonal /-- Subtracting the `orthogonalProjection` from `p` produces a result in the kernel of the linear part of the orthogonal projection. -/
Mathlib/Geometry/Euclidean/Basic.lean
430
436
theorem orthogonalProjection_vsub_orthogonalProjection (s : AffineSubspace ℝ P) [Nonempty s] [HasOrthogonalProjection s.direction] (p : P) : _root_.orthogonalProjection s.direction (p -ᵥ orthogonalProjection s p) = 0 := by
apply orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero intro c hc rw [← neg_vsub_eq_vsub_rev, inner_neg_right, orthogonalProjection_vsub_mem_direction_orthogonal s p c hc, neg_zero]
/- Copyright (c) 2022 Cuma Kökmen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Cuma Kökmen, Yury Kudryashov -/ import Mathlib.MeasureTheory.Constructions.Prod.Integral import Mathlib.MeasureTheory.Integral.CircleIntegral #align_import measure_theory.integral.torus_integral from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Integral over a torus in `ℂⁿ` In this file we define the integral of a function `f : ℂⁿ → E` over a torus `{z : ℂⁿ | ∀ i, z i ∈ Metric.sphere (c i) (R i)}`. In order to do this, we define `torusMap (c : ℂⁿ) (R θ : ℝⁿ)` to be the point in `ℂⁿ` given by $z_k=c_k+R_ke^{θ_ki}$, where $i$ is the imaginary unit, then define `torusIntegral f c R` as the integral over the cube $[0, (fun _ ↦ 2π)] = \{θ\|∀ k, 0 ≤ θ_k ≤ 2π\}$ of the Jacobian of the `torusMap` multiplied by `f (torusMap c R θ)`. We also define a predicate saying that `f ∘ torusMap c R` is integrable on the cube `[0, (fun _ ↦ 2π)]`. ## Main definitions * `torusMap c R`: the generalized multidimensional exponential map from `ℝⁿ` to `ℂⁿ` that sends $θ=(θ_0,…,θ_{n-1})$ to $z=(z_0,…,z_{n-1})$, where $z_k= c_k + R_ke^{θ_k i}$; * `TorusIntegrable f c R`: a function `f : ℂⁿ → E` is integrable over the generalized torus with center `c : ℂⁿ` and radius `R : ℝⁿ` if `f ∘ torusMap c R` is integrable on the closed cube `Icc (0 : ℝⁿ) (fun _ ↦ 2 * π)`; * `torusIntegral f c R`: the integral of a function `f : ℂⁿ → E` over a torus with center `c ∈ ℂⁿ` and radius `R ∈ ℝⁿ` defined as $\iiint_{[0, 2 * π]} (∏_{k = 1}^{n} i R_k e^{θ_k * i}) • f (c + Re^{θ_k i})\,dθ_0…dθ_{k-1}$. ## Main statements * `torusIntegral_dim0`, `torusIntegral_dim1`, `torusIntegral_succ`: formulas for `torusIntegral` in cases of dimension `0`, `1`, and `n + 1`. ## Notations - `ℝ⁰`, `ℝ¹`, `ℝⁿ`, `ℝⁿ⁺¹`: local notation for `Fin 0 → ℝ`, `Fin 1 → ℝ`, `Fin n → ℝ`, and `Fin (n + 1) → ℝ`, respectively; - `ℂ⁰`, `ℂ¹`, `ℂⁿ`, `ℂⁿ⁺¹`: local notation for `Fin 0 → ℂ`, `Fin 1 → ℂ`, `Fin n → ℂ`, and `Fin (n + 1) → ℂ`, respectively; - `∯ z in T(c, R), f z`: notation for `torusIntegral f c R`; - `∮ z in C(c, R), f z`: notation for `circleIntegral f c R`, defined elsewhere; - `∏ k, f k`: notation for `Finset.prod`, defined elsewhere; - `π`: notation for `Real.pi`, defined elsewhere. ## Tags integral, torus -/ variable {n : ℕ} variable {E : Type*} [NormedAddCommGroup E] noncomputable section open Complex Set MeasureTheory Function Filter TopologicalSpace open scoped Real -- Porting note: notation copied from `./DivergenceTheorem` local macro:arg t:term:max noWs "ⁿ⁺¹" : term => `(Fin (n + 1) → $t) local macro:arg t:term:max noWs "ⁿ" : term => `(Fin n → $t) local macro:arg t:term:max noWs "⁰" : term => `(Fin 0 → $t) local macro:arg t:term:max noWs "¹" : term => `(Fin 1 → $t) /-! ### `torusMap`, a parametrization of a torus -/ /-- The n dimensional exponential map $θ_i ↦ c + R e^{θ_i*I}, θ ∈ ℝⁿ$ representing a torus in `ℂⁿ` with center `c ∈ ℂⁿ` and generalized radius `R ∈ ℝⁿ`, so we can adjust it to every n axis. -/ def torusMap (c : ℂⁿ) (R : ℝⁿ) : ℝⁿ → ℂⁿ := fun θ i => c i + R i * exp (θ i * I) #align torus_map torusMap theorem torusMap_sub_center (c : ℂⁿ) (R : ℝⁿ) (θ : ℝⁿ) : torusMap c R θ - c = torusMap 0 R θ := by ext1 i; simp [torusMap] #align torus_map_sub_center torusMap_sub_center theorem torusMap_eq_center_iff {c : ℂⁿ} {R : ℝⁿ} {θ : ℝⁿ} : torusMap c R θ = c ↔ R = 0 := by simp [funext_iff, torusMap, exp_ne_zero] #align torus_map_eq_center_iff torusMap_eq_center_iff @[simp] theorem torusMap_zero_radius (c : ℂⁿ) : torusMap c 0 = const ℝⁿ c := funext fun _ ↦ torusMap_eq_center_iff.2 rfl #align torus_map_zero_radius torusMap_zero_radius /-! ### Integrability of a function on a generalized torus -/ /-- A function `f : ℂⁿ → E` is integrable on the generalized torus if the function `f ∘ torusMap c R θ` is integrable on `Icc (0 : ℝⁿ) (fun _ ↦ 2 * π)`. -/ def TorusIntegrable (f : ℂⁿ → E) (c : ℂⁿ) (R : ℝⁿ) : Prop := IntegrableOn (fun θ : ℝⁿ => f (torusMap c R θ)) (Icc (0 : ℝⁿ) fun _ => 2 * π) volume #align torus_integrable TorusIntegrable namespace TorusIntegrable -- Porting note (#11215): TODO: restore notation; `neg`, `add` etc fail if I use notation here variable {f g : (Fin n → ℂ) → E} {c : Fin n → ℂ} {R : Fin n → ℝ} /-- Constant functions are torus integrable -/ theorem torusIntegrable_const (a : E) (c : ℂⁿ) (R : ℝⁿ) : TorusIntegrable (fun _ => a) c R := by simp [TorusIntegrable, measure_Icc_lt_top] #align torus_integrable.torus_integrable_const TorusIntegrable.torusIntegrable_const /-- If `f` is torus integrable then `-f` is torus integrable. -/ protected nonrec theorem neg (hf : TorusIntegrable f c R) : TorusIntegrable (-f) c R := hf.neg #align torus_integrable.neg TorusIntegrable.neg /-- If `f` and `g` are two torus integrable functions, then so is `f + g`. -/ protected nonrec theorem add (hf : TorusIntegrable f c R) (hg : TorusIntegrable g c R) : TorusIntegrable (f + g) c R := hf.add hg #align torus_integrable.add TorusIntegrable.add /-- If `f` and `g` are two torus integrable functions, then so is `f - g`. -/ protected nonrec theorem sub (hf : TorusIntegrable f c R) (hg : TorusIntegrable g c R) : TorusIntegrable (f - g) c R := hf.sub hg #align torus_integrable.sub TorusIntegrable.sub theorem torusIntegrable_zero_radius {f : ℂⁿ → E} {c : ℂⁿ} : TorusIntegrable f c 0 := by rw [TorusIntegrable, torusMap_zero_radius] apply torusIntegrable_const (f c) c 0 #align torus_integrable.torus_integrable_zero_radius TorusIntegrable.torusIntegrable_zero_radius /-- The function given in the definition of `torusIntegral` is integrable. -/ theorem function_integrable [NormedSpace ℂ E] (hf : TorusIntegrable f c R) : IntegrableOn (fun θ : ℝⁿ => (∏ i, R i * exp (θ i * I) * I : ℂ) • f (torusMap c R θ)) (Icc (0 : ℝⁿ) fun _ => 2 * π) volume := by refine (hf.norm.const_mul (∏ i, |R i|)).mono' ?_ ?_ · refine (Continuous.aestronglyMeasurable ?_).smul hf.1; continuity simp [norm_smul, map_prod] #align torus_integrable.function_integrable TorusIntegrable.function_integrable end TorusIntegrable variable [NormedSpace ℂ E] [CompleteSpace E] {f g : (Fin n → ℂ) → E} {c : Fin n → ℂ} {R : Fin n → ℝ} /-- The integral over a generalized torus with center `c ∈ ℂⁿ` and radius `R ∈ ℝⁿ`, defined as the `•`-product of the derivative of `torusMap` and `f (torusMap c R θ)`-/ def torusIntegral (f : ℂⁿ → E) (c : ℂⁿ) (R : ℝⁿ) := ∫ θ : ℝⁿ in Icc (0 : ℝⁿ) fun _ => 2 * π, (∏ i, R i * exp (θ i * I) * I : ℂ) • f (torusMap c R θ) #align torus_integral torusIntegral @[inherit_doc torusIntegral] notation3"∯ "(...)" in ""T("c", "R")"", "r:(scoped f => torusIntegral f c R) => r theorem torusIntegral_radius_zero (hn : n ≠ 0) (f : ℂⁿ → E) (c : ℂⁿ) : (∯ x in T(c, 0), f x) = 0 := by simp only [torusIntegral, Pi.zero_apply, ofReal_zero, mul_zero, zero_mul, Fin.prod_const, zero_pow hn, zero_smul, integral_zero] #align torus_integral_radius_zero torusIntegral_radius_zero theorem torusIntegral_neg (f : ℂⁿ → E) (c : ℂⁿ) (R : ℝⁿ) : (∯ x in T(c, R), -f x) = -∯ x in T(c, R), f x := by simp [torusIntegral, integral_neg] #align torus_integral_neg torusIntegral_neg theorem torusIntegral_add (hf : TorusIntegrable f c R) (hg : TorusIntegrable g c R) : (∯ x in T(c, R), f x + g x) = (∯ x in T(c, R), f x) + ∯ x in T(c, R), g x := by simpa only [torusIntegral, smul_add, Pi.add_apply] using integral_add hf.function_integrable hg.function_integrable #align torus_integral_add torusIntegral_add theorem torusIntegral_sub (hf : TorusIntegrable f c R) (hg : TorusIntegrable g c R) : (∯ x in T(c, R), f x - g x) = (∯ x in T(c, R), f x) - ∯ x in T(c, R), g x := by simpa only [sub_eq_add_neg, ← torusIntegral_neg] using torusIntegral_add hf hg.neg #align torus_integral_sub torusIntegral_sub
Mathlib/MeasureTheory/Integral/TorusIntegral.lean
181
183
theorem torusIntegral_smul {𝕜 : Type*} [RCLike 𝕜] [NormedSpace 𝕜 E] [SMulCommClass 𝕜 ℂ E] (a : 𝕜) (f : ℂⁿ → E) (c : ℂⁿ) (R : ℝⁿ) : (∯ x in T(c, R), a • f x) = a • ∯ x in T(c, R), f x := by
simp only [torusIntegral, integral_smul, ← smul_comm a (_ : ℂ) (_ : E)]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Algebra.Group.Indicator import Mathlib.Data.Finset.Piecewise import Mathlib.Data.Finset.Preimage #align_import algebra.big_operators.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Big operators In this file we define products and sums indexed by finite sets (specifically, `Finset`). ## Notation We introduce the following notation. Let `s` be a `Finset α`, and `f : α → β` a function. * `∏ x ∈ s, f x` is notation for `Finset.prod s f` (assuming `β` is a `CommMonoid`) * `∑ x ∈ s, f x` is notation for `Finset.sum s f` (assuming `β` is an `AddCommMonoid`) * `∏ x, f x` is notation for `Finset.prod Finset.univ f` (assuming `α` is a `Fintype` and `β` is a `CommMonoid`) * `∑ x, f x` is notation for `Finset.sum Finset.univ f` (assuming `α` is a `Fintype` and `β` is an `AddCommMonoid`) ## Implementation Notes The first arguments in all definitions and lemmas is the codomain of the function of the big operator. This is necessary for the heuristic in `@[to_additive]`. See the documentation of `to_additive.attr` for more information. -/ -- TODO -- assert_not_exists AddCommMonoidWithOne assert_not_exists MonoidWithZero assert_not_exists MulAction variable {ι κ α β γ : Type*} open Fin Function namespace Finset /-- `∏ x ∈ s, f x` is the product of `f x` as `x` ranges over the elements of the finite set `s`. -/ @[to_additive "`∑ x ∈ s, f x` is the sum of `f x` as `x` ranges over the elements of the finite set `s`."] protected def prod [CommMonoid β] (s : Finset α) (f : α → β) : β := (s.1.map f).prod #align finset.prod Finset.prod #align finset.sum Finset.sum @[to_additive (attr := simp)] theorem prod_mk [CommMonoid β] (s : Multiset α) (hs : s.Nodup) (f : α → β) : (⟨s, hs⟩ : Finset α).prod f = (s.map f).prod := rfl #align finset.prod_mk Finset.prod_mk #align finset.sum_mk Finset.sum_mk @[to_additive (attr := simp)] theorem prod_val [CommMonoid α] (s : Finset α) : s.1.prod = s.prod id := by rw [Finset.prod, Multiset.map_id] #align finset.prod_val Finset.prod_val #align finset.sum_val Finset.sum_val end Finset library_note "operator precedence of big operators"/-- There is no established mathematical convention for the operator precedence of big operators like `∏` and `∑`. We will have to make a choice. Online discussions, such as https://math.stackexchange.com/q/185538/30839 seem to suggest that `∏` and `∑` should have the same precedence, and that this should be somewhere between `*` and `+`. The latter have precedence levels `70` and `65` respectively, and we therefore choose the level `67`. In practice, this means that parentheses should be placed as follows: ```lean ∑ k ∈ K, (a k + b k) = ∑ k ∈ K, a k + ∑ k ∈ K, b k → ∏ k ∈ K, a k * b k = (∏ k ∈ K, a k) * (∏ k ∈ K, b k) ``` (Example taken from page 490 of Knuth's *Concrete Mathematics*.) -/ namespace BigOperators open Batteries.ExtendedBinder Lean Meta -- TODO: contribute this modification back to `extBinder` /-- A `bigOpBinder` is like an `extBinder` and has the form `x`, `x : ty`, or `x pred` where `pred` is a `binderPred` like `< 2`. Unlike `extBinder`, `x` is a term. -/ syntax bigOpBinder := term:max ((" : " term) <|> binderPred)? /-- A BigOperator binder in parentheses -/ syntax bigOpBinderParenthesized := " (" bigOpBinder ")" /-- A list of parenthesized binders -/ syntax bigOpBinderCollection := bigOpBinderParenthesized+ /-- A single (unparenthesized) binder, or a list of parenthesized binders -/ syntax bigOpBinders := bigOpBinderCollection <|> (ppSpace bigOpBinder) /-- Collects additional binder/Finset pairs for the given `bigOpBinder`. Note: this is not extensible at the moment, unlike the usual `bigOpBinder` expansions. -/ def processBigOpBinder (processed : (Array (Term × Term))) (binder : TSyntax ``bigOpBinder) : MacroM (Array (Term × Term)) := set_option hygiene false in withRef binder do match binder with | `(bigOpBinder| $x:term) => match x with | `(($a + $b = $n)) => -- Maybe this is too cute. return processed |>.push (← `(⟨$a, $b⟩), ← `(Finset.Nat.antidiagonal $n)) | _ => return processed |>.push (x, ← ``(Finset.univ)) | `(bigOpBinder| $x : $t) => return processed |>.push (x, ← ``((Finset.univ : Finset $t))) | `(bigOpBinder| $x ∈ $s) => return processed |>.push (x, ← `(finset% $s)) | `(bigOpBinder| $x < $n) => return processed |>.push (x, ← `(Finset.Iio $n)) | `(bigOpBinder| $x ≤ $n) => return processed |>.push (x, ← `(Finset.Iic $n)) | `(bigOpBinder| $x > $n) => return processed |>.push (x, ← `(Finset.Ioi $n)) | `(bigOpBinder| $x ≥ $n) => return processed |>.push (x, ← `(Finset.Ici $n)) | _ => Macro.throwUnsupported /-- Collects the binder/Finset pairs for the given `bigOpBinders`. -/ def processBigOpBinders (binders : TSyntax ``bigOpBinders) : MacroM (Array (Term × Term)) := match binders with | `(bigOpBinders| $b:bigOpBinder) => processBigOpBinder #[] b | `(bigOpBinders| $[($bs:bigOpBinder)]*) => bs.foldlM processBigOpBinder #[] | _ => Macro.throwUnsupported /-- Collect the binderIdents into a `⟨...⟩` expression. -/ def bigOpBindersPattern (processed : (Array (Term × Term))) : MacroM Term := do let ts := processed.map Prod.fst if ts.size == 1 then return ts[0]! else `(⟨$ts,*⟩) /-- Collect the terms into a product of sets. -/ def bigOpBindersProd (processed : (Array (Term × Term))) : MacroM Term := do if processed.isEmpty then `((Finset.univ : Finset Unit)) else if processed.size == 1 then return processed[0]!.2 else processed.foldrM (fun s p => `(SProd.sprod $(s.2) $p)) processed.back.2 (start := processed.size - 1) /-- - `∑ x, f x` is notation for `Finset.sum Finset.univ f`. It is the sum of `f x`, where `x` ranges over the finite domain of `f`. - `∑ x ∈ s, f x` is notation for `Finset.sum s f`. It is the sum of `f x`, where `x` ranges over the finite set `s` (either a `Finset` or a `Set` with a `Fintype` instance). - `∑ x ∈ s with p x, f x` is notation for `Finset.sum (Finset.filter p s) f`. - `∑ (x ∈ s) (y ∈ t), f x y` is notation for `Finset.sum (s ×ˢ t) (fun ⟨x, y⟩ ↦ f x y)`. These support destructuring, for example `∑ ⟨x, y⟩ ∈ s ×ˢ t, f x y`. Notation: `"∑" bigOpBinders* ("with" term)? "," term` -/ syntax (name := bigsum) "∑ " bigOpBinders ("with " term)? ", " term:67 : term /-- - `∏ x, f x` is notation for `Finset.prod Finset.univ f`. It is the product of `f x`, where `x` ranges over the finite domain of `f`. - `∏ x ∈ s, f x` is notation for `Finset.prod s f`. It is the product of `f x`, where `x` ranges over the finite set `s` (either a `Finset` or a `Set` with a `Fintype` instance). - `∏ x ∈ s with p x, f x` is notation for `Finset.prod (Finset.filter p s) f`. - `∏ (x ∈ s) (y ∈ t), f x y` is notation for `Finset.prod (s ×ˢ t) (fun ⟨x, y⟩ ↦ f x y)`. These support destructuring, for example `∏ ⟨x, y⟩ ∈ s ×ˢ t, f x y`. Notation: `"∏" bigOpBinders* ("with" term)? "," term` -/ syntax (name := bigprod) "∏ " bigOpBinders ("with " term)? ", " term:67 : term macro_rules (kind := bigsum) | `(∑ $bs:bigOpBinders $[with $p?]?, $v) => do let processed ← processBigOpBinders bs let x ← bigOpBindersPattern processed let s ← bigOpBindersProd processed match p? with | some p => `(Finset.sum (Finset.filter (fun $x ↦ $p) $s) (fun $x ↦ $v)) | none => `(Finset.sum $s (fun $x ↦ $v)) macro_rules (kind := bigprod) | `(∏ $bs:bigOpBinders $[with $p?]?, $v) => do let processed ← processBigOpBinders bs let x ← bigOpBindersPattern processed let s ← bigOpBindersProd processed match p? with | some p => `(Finset.prod (Finset.filter (fun $x ↦ $p) $s) (fun $x ↦ $v)) | none => `(Finset.prod $s (fun $x ↦ $v)) /-- (Deprecated, use `∑ x ∈ s, f x`) `∑ x in s, f x` is notation for `Finset.sum s f`. It is the sum of `f x`, where `x` ranges over the finite set `s`. -/ syntax (name := bigsumin) "∑ " extBinder " in " term ", " term:67 : term macro_rules (kind := bigsumin) | `(∑ $x:ident in $s, $r) => `(∑ $x:ident ∈ $s, $r) | `(∑ $x:ident : $t in $s, $r) => `(∑ $x:ident ∈ ($s : Finset $t), $r) /-- (Deprecated, use `∏ x ∈ s, f x`) `∏ x in s, f x` is notation for `Finset.prod s f`. It is the product of `f x`, where `x` ranges over the finite set `s`. -/ syntax (name := bigprodin) "∏ " extBinder " in " term ", " term:67 : term macro_rules (kind := bigprodin) | `(∏ $x:ident in $s, $r) => `(∏ $x:ident ∈ $s, $r) | `(∏ $x:ident : $t in $s, $r) => `(∏ $x:ident ∈ ($s : Finset $t), $r) open Lean Meta Parser.Term PrettyPrinter.Delaborator SubExpr open Batteries.ExtendedBinder /-- Delaborator for `Finset.prod`. The `pp.piBinderTypes` option controls whether to show the domain type when the product is over `Finset.univ`. -/ @[delab app.Finset.prod] def delabFinsetProd : Delab := whenPPOption getPPNotation <| withOverApp 5 <| do let #[_, _, _, s, f] := (← getExpr).getAppArgs | failure guard <| f.isLambda let ppDomain ← getPPOption getPPPiBinderTypes let (i, body) ← withAppArg <| withBindingBodyUnusedName fun i => do return (i, ← delab) if s.isAppOfArity ``Finset.univ 2 then let binder ← if ppDomain then let ty ← withNaryArg 0 delab `(bigOpBinder| $(.mk i):ident : $ty) else `(bigOpBinder| $(.mk i):ident) `(∏ $binder:bigOpBinder, $body) else let ss ← withNaryArg 3 <| delab `(∏ $(.mk i):ident ∈ $ss, $body) /-- Delaborator for `Finset.sum`. The `pp.piBinderTypes` option controls whether to show the domain type when the sum is over `Finset.univ`. -/ @[delab app.Finset.sum] def delabFinsetSum : Delab := whenPPOption getPPNotation <| withOverApp 5 <| do let #[_, _, _, s, f] := (← getExpr).getAppArgs | failure guard <| f.isLambda let ppDomain ← getPPOption getPPPiBinderTypes let (i, body) ← withAppArg <| withBindingBodyUnusedName fun i => do return (i, ← delab) if s.isAppOfArity ``Finset.univ 2 then let binder ← if ppDomain then let ty ← withNaryArg 0 delab `(bigOpBinder| $(.mk i):ident : $ty) else `(bigOpBinder| $(.mk i):ident) `(∑ $binder:bigOpBinder, $body) else let ss ← withNaryArg 3 <| delab `(∑ $(.mk i):ident ∈ $ss, $body) end BigOperators namespace Finset variable {s s₁ s₂ : Finset α} {a : α} {f g : α → β} @[to_additive] theorem prod_eq_multiset_prod [CommMonoid β] (s : Finset α) (f : α → β) : ∏ x ∈ s, f x = (s.1.map f).prod := rfl #align finset.prod_eq_multiset_prod Finset.prod_eq_multiset_prod #align finset.sum_eq_multiset_sum Finset.sum_eq_multiset_sum @[to_additive (attr := simp)] lemma prod_map_val [CommMonoid β] (s : Finset α) (f : α → β) : (s.1.map f).prod = ∏ a ∈ s, f a := rfl #align finset.prod_map_val Finset.prod_map_val #align finset.sum_map_val Finset.sum_map_val @[to_additive] theorem prod_eq_fold [CommMonoid β] (s : Finset α) (f : α → β) : ∏ x ∈ s, f x = s.fold ((· * ·) : β → β → β) 1 f := rfl #align finset.prod_eq_fold Finset.prod_eq_fold #align finset.sum_eq_fold Finset.sum_eq_fold @[simp] theorem sum_multiset_singleton (s : Finset α) : (s.sum fun x => {x}) = s.val := by simp only [sum_eq_multiset_sum, Multiset.sum_map_singleton] #align finset.sum_multiset_singleton Finset.sum_multiset_singleton end Finset @[to_additive (attr := simp)] theorem map_prod [CommMonoid β] [CommMonoid γ] {G : Type*} [FunLike G β γ] [MonoidHomClass G β γ] (g : G) (f : α → β) (s : Finset α) : g (∏ x ∈ s, f x) = ∏ x ∈ s, g (f x) := by simp only [Finset.prod_eq_multiset_prod, map_multiset_prod, Multiset.map_map]; rfl #align map_prod map_prod #align map_sum map_sum @[to_additive] theorem MonoidHom.coe_finset_prod [MulOneClass β] [CommMonoid γ] (f : α → β →* γ) (s : Finset α) : ⇑(∏ x ∈ s, f x) = ∏ x ∈ s, ⇑(f x) := map_prod (MonoidHom.coeFn β γ) _ _ #align monoid_hom.coe_finset_prod MonoidHom.coe_finset_prod #align add_monoid_hom.coe_finset_sum AddMonoidHom.coe_finset_sum /-- See also `Finset.prod_apply`, with the same conclusion but with the weaker hypothesis `f : α → β → γ` -/ @[to_additive (attr := simp) "See also `Finset.sum_apply`, with the same conclusion but with the weaker hypothesis `f : α → β → γ`"] theorem MonoidHom.finset_prod_apply [MulOneClass β] [CommMonoid γ] (f : α → β →* γ) (s : Finset α) (b : β) : (∏ x ∈ s, f x) b = ∏ x ∈ s, f x b := map_prod (MonoidHom.eval b) _ _ #align monoid_hom.finset_prod_apply MonoidHom.finset_prod_apply #align add_monoid_hom.finset_sum_apply AddMonoidHom.finset_sum_apply variable {s s₁ s₂ : Finset α} {a : α} {f g : α → β} namespace Finset section CommMonoid variable [CommMonoid β] @[to_additive (attr := simp)] theorem prod_empty : ∏ x ∈ ∅, f x = 1 := rfl #align finset.prod_empty Finset.prod_empty #align finset.sum_empty Finset.sum_empty @[to_additive] theorem prod_of_empty [IsEmpty α] (s : Finset α) : ∏ i ∈ s, f i = 1 := by rw [eq_empty_of_isEmpty s, prod_empty] #align finset.prod_of_empty Finset.prod_of_empty #align finset.sum_of_empty Finset.sum_of_empty @[to_additive (attr := simp)] theorem prod_cons (h : a ∉ s) : ∏ x ∈ cons a s h, f x = f a * ∏ x ∈ s, f x := fold_cons h #align finset.prod_cons Finset.prod_cons #align finset.sum_cons Finset.sum_cons @[to_additive (attr := simp)] theorem prod_insert [DecidableEq α] : a ∉ s → ∏ x ∈ insert a s, f x = f a * ∏ x ∈ s, f x := fold_insert #align finset.prod_insert Finset.prod_insert #align finset.sum_insert Finset.sum_insert /-- The product of `f` over `insert a s` is the same as the product over `s`, as long as `a` is in `s` or `f a = 1`. -/ @[to_additive (attr := simp) "The sum of `f` over `insert a s` is the same as the sum over `s`, as long as `a` is in `s` or `f a = 0`."] theorem prod_insert_of_eq_one_if_not_mem [DecidableEq α] (h : a ∉ s → f a = 1) : ∏ x ∈ insert a s, f x = ∏ x ∈ s, f x := by by_cases hm : a ∈ s · simp_rw [insert_eq_of_mem hm] · rw [prod_insert hm, h hm, one_mul] #align finset.prod_insert_of_eq_one_if_not_mem Finset.prod_insert_of_eq_one_if_not_mem #align finset.sum_insert_of_eq_zero_if_not_mem Finset.sum_insert_of_eq_zero_if_not_mem /-- The product of `f` over `insert a s` is the same as the product over `s`, as long as `f a = 1`. -/ @[to_additive (attr := simp) "The sum of `f` over `insert a s` is the same as the sum over `s`, as long as `f a = 0`."] theorem prod_insert_one [DecidableEq α] (h : f a = 1) : ∏ x ∈ insert a s, f x = ∏ x ∈ s, f x := prod_insert_of_eq_one_if_not_mem fun _ => h #align finset.prod_insert_one Finset.prod_insert_one #align finset.sum_insert_zero Finset.sum_insert_zero @[to_additive] theorem prod_insert_div {M : Type*} [CommGroup M] [DecidableEq α] (ha : a ∉ s) {f : α → M} : (∏ x ∈ insert a s, f x) / f a = ∏ x ∈ s, f x := by simp [ha] @[to_additive (attr := simp)] theorem prod_singleton (f : α → β) (a : α) : ∏ x ∈ singleton a, f x = f a := Eq.trans fold_singleton <| mul_one _ #align finset.prod_singleton Finset.prod_singleton #align finset.sum_singleton Finset.sum_singleton @[to_additive] theorem prod_pair [DecidableEq α] {a b : α} (h : a ≠ b) : (∏ x ∈ ({a, b} : Finset α), f x) = f a * f b := by rw [prod_insert (not_mem_singleton.2 h), prod_singleton] #align finset.prod_pair Finset.prod_pair #align finset.sum_pair Finset.sum_pair @[to_additive (attr := simp)] theorem prod_const_one : (∏ _x ∈ s, (1 : β)) = 1 := by simp only [Finset.prod, Multiset.map_const', Multiset.prod_replicate, one_pow] #align finset.prod_const_one Finset.prod_const_one #align finset.sum_const_zero Finset.sum_const_zero @[to_additive (attr := simp)] theorem prod_image [DecidableEq α] {s : Finset γ} {g : γ → α} : (∀ x ∈ s, ∀ y ∈ s, g x = g y → x = y) → ∏ x ∈ s.image g, f x = ∏ x ∈ s, f (g x) := fold_image #align finset.prod_image Finset.prod_image #align finset.sum_image Finset.sum_image @[to_additive (attr := simp)] theorem prod_map (s : Finset α) (e : α ↪ γ) (f : γ → β) : ∏ x ∈ s.map e, f x = ∏ x ∈ s, f (e x) := by rw [Finset.prod, Finset.map_val, Multiset.map_map]; rfl #align finset.prod_map Finset.prod_map #align finset.sum_map Finset.sum_map @[to_additive] lemma prod_attach (s : Finset α) (f : α → β) : ∏ x ∈ s.attach, f x = ∏ x ∈ s, f x := by classical rw [← prod_image Subtype.coe_injective.injOn, attach_image_val] #align finset.prod_attach Finset.prod_attach #align finset.sum_attach Finset.sum_attach @[to_additive (attr := congr)] theorem prod_congr (h : s₁ = s₂) : (∀ x ∈ s₂, f x = g x) → s₁.prod f = s₂.prod g := by rw [h]; exact fold_congr #align finset.prod_congr Finset.prod_congr #align finset.sum_congr Finset.sum_congr @[to_additive] theorem prod_eq_one {f : α → β} {s : Finset α} (h : ∀ x ∈ s, f x = 1) : ∏ x ∈ s, f x = 1 := calc ∏ x ∈ s, f x = ∏ _x ∈ s, 1 := Finset.prod_congr rfl h _ = 1 := Finset.prod_const_one #align finset.prod_eq_one Finset.prod_eq_one #align finset.sum_eq_zero Finset.sum_eq_zero @[to_additive] theorem prod_disjUnion (h) : ∏ x ∈ s₁.disjUnion s₂ h, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by refine Eq.trans ?_ (fold_disjUnion h) rw [one_mul] rfl #align finset.prod_disj_union Finset.prod_disjUnion #align finset.sum_disj_union Finset.sum_disjUnion @[to_additive] theorem prod_disjiUnion (s : Finset ι) (t : ι → Finset α) (h) : ∏ x ∈ s.disjiUnion t h, f x = ∏ i ∈ s, ∏ x ∈ t i, f x := by refine Eq.trans ?_ (fold_disjiUnion h) dsimp [Finset.prod, Multiset.prod, Multiset.fold, Finset.disjUnion, Finset.fold] congr exact prod_const_one.symm #align finset.prod_disj_Union Finset.prod_disjiUnion #align finset.sum_disj_Union Finset.sum_disjiUnion @[to_additive] theorem prod_union_inter [DecidableEq α] : (∏ x ∈ s₁ ∪ s₂, f x) * ∏ x ∈ s₁ ∩ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := fold_union_inter #align finset.prod_union_inter Finset.prod_union_inter #align finset.sum_union_inter Finset.sum_union_inter @[to_additive] theorem prod_union [DecidableEq α] (h : Disjoint s₁ s₂) : ∏ x ∈ s₁ ∪ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by rw [← prod_union_inter, disjoint_iff_inter_eq_empty.mp h]; exact (mul_one _).symm #align finset.prod_union Finset.prod_union #align finset.sum_union Finset.sum_union @[to_additive] theorem prod_filter_mul_prod_filter_not (s : Finset α) (p : α → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] (f : α → β) : (∏ x ∈ s.filter p, f x) * ∏ x ∈ s.filter fun x => ¬p x, f x = ∏ x ∈ s, f x := by have := Classical.decEq α rw [← prod_union (disjoint_filter_filter_neg s s p), filter_union_filter_neg_eq] #align finset.prod_filter_mul_prod_filter_not Finset.prod_filter_mul_prod_filter_not #align finset.sum_filter_add_sum_filter_not Finset.sum_filter_add_sum_filter_not section ToList @[to_additive (attr := simp)] theorem prod_to_list (s : Finset α) (f : α → β) : (s.toList.map f).prod = s.prod f := by rw [Finset.prod, ← Multiset.prod_coe, ← Multiset.map_coe, Finset.coe_toList] #align finset.prod_to_list Finset.prod_to_list #align finset.sum_to_list Finset.sum_to_list end ToList @[to_additive] theorem _root_.Equiv.Perm.prod_comp (σ : Equiv.Perm α) (s : Finset α) (f : α → β) (hs : { a | σ a ≠ a } ⊆ s) : (∏ x ∈ s, f (σ x)) = ∏ x ∈ s, f x := by convert (prod_map s σ.toEmbedding f).symm exact (map_perm hs).symm #align equiv.perm.prod_comp Equiv.Perm.prod_comp #align equiv.perm.sum_comp Equiv.Perm.sum_comp @[to_additive]
Mathlib/Algebra/BigOperators/Group/Finset.lean
491
494
theorem _root_.Equiv.Perm.prod_comp' (σ : Equiv.Perm α) (s : Finset α) (f : α → α → β) (hs : { a | σ a ≠ a } ⊆ s) : (∏ x ∈ s, f (σ x) x) = ∏ x ∈ s, f x (σ.symm x) := by
convert σ.prod_comp s (fun x => f x (σ.symm x)) hs rw [Equiv.symm_apply_apply]
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Yury Kudryashov -/ import Mathlib.Data.Set.Pointwise.SMul #align_import algebra.add_torsor from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Torsors of additive group actions This file defines torsors of additive group actions. ## Notations The group elements are referred to as acting on points. This file defines the notation `+ᵥ` for adding a group element to a point and `-ᵥ` for subtracting two points to produce a group element. ## Implementation notes Affine spaces are the motivating example of torsors of additive group actions. It may be appropriate to refactor in terms of the general definition of group actions, via `to_additive`, when there is a use for multiplicative torsors (currently mathlib only develops the theory of group actions for multiplicative group actions). ## Notations * `v +ᵥ p` is a notation for `VAdd.vadd`, the left action of an additive monoid; * `p₁ -ᵥ p₂` is a notation for `VSub.vsub`, difference between two points in an additive torsor as an element of the corresponding additive group; ## References * https://en.wikipedia.org/wiki/Principal_homogeneous_space * https://en.wikipedia.org/wiki/Affine_space -/ /-- An `AddTorsor G P` gives a structure to the nonempty type `P`, acted on by an `AddGroup G` with a transitive and free action given by the `+ᵥ` operation and a corresponding subtraction given by the `-ᵥ` operation. In the case of a vector space, it is an affine space. -/ class AddTorsor (G : outParam Type*) (P : Type*) [AddGroup G] extends AddAction G P, VSub G P where [nonempty : Nonempty P] /-- Torsor subtraction and addition with the same element cancels out. -/ vsub_vadd' : ∀ p₁ p₂ : P, (p₁ -ᵥ p₂ : G) +ᵥ p₂ = p₁ /-- Torsor addition and subtraction with the same element cancels out. -/ vadd_vsub' : ∀ (g : G) (p : P), g +ᵥ p -ᵥ p = g #align add_torsor AddTorsor -- Porting note(#12096): removed `nolint instance_priority`; lint not ported yet attribute [instance 100] AddTorsor.nonempty -- Porting note(#12094): removed nolint; dangerous_instance linter not ported yet --attribute [nolint dangerous_instance] AddTorsor.toVSub /-- An `AddGroup G` is a torsor for itself. -/ -- Porting note(#12096): linter not ported yet --@[nolint instance_priority] instance addGroupIsAddTorsor (G : Type*) [AddGroup G] : AddTorsor G G where vsub := Sub.sub vsub_vadd' := sub_add_cancel vadd_vsub' := add_sub_cancel_right #align add_group_is_add_torsor addGroupIsAddTorsor /-- Simplify subtraction for a torsor for an `AddGroup G` over itself. -/ @[simp] theorem vsub_eq_sub {G : Type*} [AddGroup G] (g₁ g₂ : G) : g₁ -ᵥ g₂ = g₁ - g₂ := rfl #align vsub_eq_sub vsub_eq_sub section General variable {G : Type*} {P : Type*} [AddGroup G] [T : AddTorsor G P] /-- Adding the result of subtracting from another point produces that point. -/ @[simp] theorem vsub_vadd (p₁ p₂ : P) : p₁ -ᵥ p₂ +ᵥ p₂ = p₁ := AddTorsor.vsub_vadd' p₁ p₂ #align vsub_vadd vsub_vadd /-- Adding a group element then subtracting the original point produces that group element. -/ @[simp] theorem vadd_vsub (g : G) (p : P) : g +ᵥ p -ᵥ p = g := AddTorsor.vadd_vsub' g p #align vadd_vsub vadd_vsub /-- If the same point added to two group elements produces equal results, those group elements are equal. -/ theorem vadd_right_cancel {g₁ g₂ : G} (p : P) (h : g₁ +ᵥ p = g₂ +ᵥ p) : g₁ = g₂ := by -- Porting note: vadd_vsub g₁ → vadd_vsub g₁ p rw [← vadd_vsub g₁ p, h, vadd_vsub] #align vadd_right_cancel vadd_right_cancel @[simp] theorem vadd_right_cancel_iff {g₁ g₂ : G} (p : P) : g₁ +ᵥ p = g₂ +ᵥ p ↔ g₁ = g₂ := ⟨vadd_right_cancel p, fun h => h ▸ rfl⟩ #align vadd_right_cancel_iff vadd_right_cancel_iff /-- Adding a group element to the point `p` is an injective function. -/ theorem vadd_right_injective (p : P) : Function.Injective ((· +ᵥ p) : G → P) := fun _ _ => vadd_right_cancel p #align vadd_right_injective vadd_right_injective /-- Adding a group element to a point, then subtracting another point, produces the same result as subtracting the points then adding the group element. -/ theorem vadd_vsub_assoc (g : G) (p₁ p₂ : P) : g +ᵥ p₁ -ᵥ p₂ = g + (p₁ -ᵥ p₂) := by apply vadd_right_cancel p₂ rw [vsub_vadd, add_vadd, vsub_vadd] #align vadd_vsub_assoc vadd_vsub_assoc /-- Subtracting a point from itself produces 0. -/ @[simp]
Mathlib/Algebra/AddTorsor.lean
124
125
theorem vsub_self (p : P) : p -ᵥ p = (0 : G) := by
rw [← zero_add (p -ᵥ p), ← vadd_vsub_assoc, vadd_vsub]
/- Copyright (c) 2022 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Order.ToIntervalMod import Mathlib.Algebra.Ring.AddAut import Mathlib.Data.Nat.Totient import Mathlib.GroupTheory.Divisible import Mathlib.Topology.Connected.PathConnected import Mathlib.Topology.IsLocalHomeomorph #align_import topology.instances.add_circle from "leanprover-community/mathlib"@"213b0cff7bc5ab6696ee07cceec80829ce42efec" /-! # The additive circle We define the additive circle `AddCircle p` as the quotient `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜`. See also `Circle` and `Real.angle`. For the normed group structure on `AddCircle`, see `AddCircle.NormedAddCommGroup` in a later file. ## Main definitions and results: * `AddCircle`: the additive circle `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜` * `UnitAddCircle`: the special case `ℝ ⧸ ℤ` * `AddCircle.equivAddCircle`: the rescaling equivalence `AddCircle p ≃+ AddCircle q` * `AddCircle.equivIco`: the natural equivalence `AddCircle p ≃ Ico a (a + p)` * `AddCircle.addOrderOf_div_of_gcd_eq_one`: rational points have finite order * `AddCircle.exists_gcd_eq_one_of_isOfFinAddOrder`: finite-order points are rational * `AddCircle.homeoIccQuot`: the natural topological equivalence between `AddCircle p` and `Icc a (a + p)` with its endpoints identified. * `AddCircle.liftIco_continuous`: if `f : ℝ → B` is continuous, and `f a = f (a + p)` for some `a`, then there is a continuous function `AddCircle p → B` which agrees with `f` on `Icc a (a + p)`. ## Implementation notes: Although the most important case is `𝕜 = ℝ` we wish to support other types of scalars, such as the rational circle `AddCircle (1 : ℚ)`, and so we set things up more generally. ## TODO * Link with periodicity * Lie group structure * Exponential equivalence to `Circle` -/ noncomputable section open AddCommGroup Set Function AddSubgroup TopologicalSpace open Topology variable {𝕜 B : Type*} section Continuity variable [LinearOrderedAddCommGroup 𝕜] [Archimedean 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {p : 𝕜} (hp : 0 < p) (a x : 𝕜) theorem continuous_right_toIcoMod : ContinuousWithinAt (toIcoMod hp a) (Ici x) x := by intro s h rw [Filter.mem_map, mem_nhdsWithin_iff_exists_mem_nhds_inter] haveI : Nontrivial 𝕜 := ⟨⟨0, p, hp.ne⟩⟩ simp_rw [mem_nhds_iff_exists_Ioo_subset] at h ⊢ obtain ⟨l, u, hxI, hIs⟩ := h let d := toIcoDiv hp a x • p have hd := toIcoMod_mem_Ico hp a x simp_rw [subset_def, mem_inter_iff] refine ⟨_, ⟨l + d, min (a + p) u + d, ?_, fun x => id⟩, fun y => ?_⟩ <;> simp_rw [← sub_mem_Ioo_iff_left, mem_Ioo, lt_min_iff] · exact ⟨hxI.1, hd.2, hxI.2⟩ · rintro ⟨h, h'⟩ apply hIs rw [← toIcoMod_sub_zsmul, (toIcoMod_eq_self _).2] exacts [⟨h.1, h.2.2⟩, ⟨hd.1.trans (sub_le_sub_right h' _), h.2.1⟩] #align continuous_right_to_Ico_mod continuous_right_toIcoMod theorem continuous_left_toIocMod : ContinuousWithinAt (toIocMod hp a) (Iic x) x := by rw [(funext fun y => Eq.trans (by rw [neg_neg]) <| toIocMod_neg _ _ _ : toIocMod hp a = (fun x => p - x) ∘ toIcoMod hp (-a) ∘ Neg.neg)] -- Porting note: added have : ContinuousNeg 𝕜 := TopologicalAddGroup.toContinuousNeg exact (continuous_sub_left _).continuousAt.comp_continuousWithinAt <| (continuous_right_toIcoMod _ _ _).comp continuous_neg.continuousWithinAt fun y => neg_le_neg #align continuous_left_to_Ioc_mod continuous_left_toIocMod variable {x} (hx : (x : 𝕜 ⧸ zmultiples p) ≠ a) theorem toIcoMod_eventuallyEq_toIocMod : toIcoMod hp a =ᶠ[𝓝 x] toIocMod hp a := IsOpen.mem_nhds (by rw [Ico_eq_locus_Ioc_eq_iUnion_Ioo] exact isOpen_iUnion fun i => isOpen_Ioo) <| (not_modEq_iff_toIcoMod_eq_toIocMod hp).1 <| not_modEq_iff_ne_mod_zmultiples.2 hx #align to_Ico_mod_eventually_eq_to_Ioc_mod toIcoMod_eventuallyEq_toIocMod theorem continuousAt_toIcoMod : ContinuousAt (toIcoMod hp a) x := let h := toIcoMod_eventuallyEq_toIocMod hp a hx continuousAt_iff_continuous_left_right.2 <| ⟨(continuous_left_toIocMod hp a x).congr_of_eventuallyEq (h.filter_mono nhdsWithin_le_nhds) h.eq_of_nhds, continuous_right_toIcoMod hp a x⟩ #align continuous_at_to_Ico_mod continuousAt_toIcoMod theorem continuousAt_toIocMod : ContinuousAt (toIocMod hp a) x := let h := toIcoMod_eventuallyEq_toIocMod hp a hx continuousAt_iff_continuous_left_right.2 <| ⟨continuous_left_toIocMod hp a x, (continuous_right_toIcoMod hp a x).congr_of_eventuallyEq (h.symm.filter_mono nhdsWithin_le_nhds) h.symm.eq_of_nhds⟩ #align continuous_at_to_Ioc_mod continuousAt_toIocMod end Continuity /-- The "additive circle": `𝕜 ⧸ (ℤ ∙ p)`. See also `Circle` and `Real.angle`. -/ @[nolint unusedArguments] abbrev AddCircle [LinearOrderedAddCommGroup 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] (p : 𝕜) := 𝕜 ⧸ zmultiples p #align add_circle AddCircle namespace AddCircle section LinearOrderedAddCommGroup variable [LinearOrderedAddCommGroup 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] (p : 𝕜) theorem coe_nsmul {n : ℕ} {x : 𝕜} : (↑(n • x) : AddCircle p) = n • (x : AddCircle p) := rfl #align add_circle.coe_nsmul AddCircle.coe_nsmul theorem coe_zsmul {n : ℤ} {x : 𝕜} : (↑(n • x) : AddCircle p) = n • (x : AddCircle p) := rfl #align add_circle.coe_zsmul AddCircle.coe_zsmul theorem coe_add (x y : 𝕜) : (↑(x + y) : AddCircle p) = (x : AddCircle p) + (y : AddCircle p) := rfl #align add_circle.coe_add AddCircle.coe_add theorem coe_sub (x y : 𝕜) : (↑(x - y) : AddCircle p) = (x : AddCircle p) - (y : AddCircle p) := rfl #align add_circle.coe_sub AddCircle.coe_sub theorem coe_neg {x : 𝕜} : (↑(-x) : AddCircle p) = -(x : AddCircle p) := rfl #align add_circle.coe_neg AddCircle.coe_neg theorem coe_eq_zero_iff {x : 𝕜} : (x : AddCircle p) = 0 ↔ ∃ n : ℤ, n • p = x := by simp [AddSubgroup.mem_zmultiples_iff] #align add_circle.coe_eq_zero_iff AddCircle.coe_eq_zero_iff theorem coe_eq_zero_of_pos_iff (hp : 0 < p) {x : 𝕜} (hx : 0 < x) : (x : AddCircle p) = 0 ↔ ∃ n : ℕ, n • p = x := by rw [coe_eq_zero_iff] constructor <;> rintro ⟨n, rfl⟩ · replace hx : 0 < n := by contrapose! hx simpa only [← neg_nonneg, ← zsmul_neg, zsmul_neg'] using zsmul_nonneg hp.le (neg_nonneg.2 hx) exact ⟨n.toNat, by rw [← natCast_zsmul, Int.toNat_of_nonneg hx.le]⟩ · exact ⟨(n : ℤ), by simp⟩ #align add_circle.coe_eq_zero_of_pos_iff AddCircle.coe_eq_zero_of_pos_iff theorem coe_period : (p : AddCircle p) = 0 := (QuotientAddGroup.eq_zero_iff p).2 <| mem_zmultiples p #align add_circle.coe_period AddCircle.coe_period /- Porting note (#10618): `simp` attribute removed because linter reports: simp can prove this: by simp only [@mem_zmultiples, @QuotientAddGroup.mk_add_of_mem] -/ theorem coe_add_period (x : 𝕜) : ((x + p : 𝕜) : AddCircle p) = x := by rw [coe_add, ← eq_sub_iff_add_eq', sub_self, coe_period] #align add_circle.coe_add_period AddCircle.coe_add_period @[continuity, nolint unusedArguments] protected theorem continuous_mk' : Continuous (QuotientAddGroup.mk' (zmultiples p) : 𝕜 → AddCircle p) := continuous_coinduced_rng #align add_circle.continuous_mk' AddCircle.continuous_mk' variable [hp : Fact (0 < p)] (a : 𝕜) [Archimedean 𝕜] /-- The equivalence between `AddCircle p` and the half-open interval `[a, a + p)`, whose inverse is the natural quotient map. -/ def equivIco : AddCircle p ≃ Ico a (a + p) := QuotientAddGroup.equivIcoMod hp.out a #align add_circle.equiv_Ico AddCircle.equivIco /-- The equivalence between `AddCircle p` and the half-open interval `(a, a + p]`, whose inverse is the natural quotient map. -/ def equivIoc : AddCircle p ≃ Ioc a (a + p) := QuotientAddGroup.equivIocMod hp.out a #align add_circle.equiv_Ioc AddCircle.equivIoc /-- Given a function on `𝕜`, return the unique function on `AddCircle p` agreeing with `f` on `[a, a + p)`. -/ def liftIco (f : 𝕜 → B) : AddCircle p → B := restrict _ f ∘ AddCircle.equivIco p a #align add_circle.lift_Ico AddCircle.liftIco /-- Given a function on `𝕜`, return the unique function on `AddCircle p` agreeing with `f` on `(a, a + p]`. -/ def liftIoc (f : 𝕜 → B) : AddCircle p → B := restrict _ f ∘ AddCircle.equivIoc p a #align add_circle.lift_Ioc AddCircle.liftIoc variable {p a} theorem coe_eq_coe_iff_of_mem_Ico {x y : 𝕜} (hx : x ∈ Ico a (a + p)) (hy : y ∈ Ico a (a + p)) : (x : AddCircle p) = y ↔ x = y := by refine ⟨fun h => ?_, by tauto⟩ suffices (⟨x, hx⟩ : Ico a (a + p)) = ⟨y, hy⟩ by exact Subtype.mk.inj this apply_fun equivIco p a at h rw [← (equivIco p a).right_inv ⟨x, hx⟩, ← (equivIco p a).right_inv ⟨y, hy⟩] exact h #align add_circle.coe_eq_coe_iff_of_mem_Ico AddCircle.coe_eq_coe_iff_of_mem_Ico theorem liftIco_coe_apply {f : 𝕜 → B} {x : 𝕜} (hx : x ∈ Ico a (a + p)) : liftIco p a f ↑x = f x := by have : (equivIco p a) x = ⟨x, hx⟩ := by rw [Equiv.apply_eq_iff_eq_symm_apply] rfl rw [liftIco, comp_apply, this] rfl #align add_circle.lift_Ico_coe_apply AddCircle.liftIco_coe_apply theorem liftIoc_coe_apply {f : 𝕜 → B} {x : 𝕜} (hx : x ∈ Ioc a (a + p)) : liftIoc p a f ↑x = f x := by have : (equivIoc p a) x = ⟨x, hx⟩ := by rw [Equiv.apply_eq_iff_eq_symm_apply] rfl rw [liftIoc, comp_apply, this] rfl #align add_circle.lift_Ioc_coe_apply AddCircle.liftIoc_coe_apply lemma eq_coe_Ico (a : AddCircle p) : ∃ b, b ∈ Ico 0 p ∧ ↑b = a := by let b := QuotientAddGroup.equivIcoMod hp.out 0 a exact ⟨b.1, by simpa only [zero_add] using b.2, (QuotientAddGroup.equivIcoMod hp.out 0).symm_apply_apply a⟩ lemma coe_eq_zero_iff_of_mem_Ico (ha : a ∈ Ico 0 p) : (a : AddCircle p) = 0 ↔ a = 0 := by have h0 : 0 ∈ Ico 0 (0 + p) := by simpa [zero_add, left_mem_Ico] using hp.out have ha' : a ∈ Ico 0 (0 + p) := by rwa [zero_add] rw [← AddCircle.coe_eq_coe_iff_of_mem_Ico ha' h0, QuotientAddGroup.mk_zero] variable (p a) section Continuity @[continuity] theorem continuous_equivIco_symm : Continuous (equivIco p a).symm := continuous_quotient_mk'.comp continuous_subtype_val #align add_circle.continuous_equiv_Ico_symm AddCircle.continuous_equivIco_symm @[continuity] theorem continuous_equivIoc_symm : Continuous (equivIoc p a).symm := continuous_quotient_mk'.comp continuous_subtype_val #align add_circle.continuous_equiv_Ioc_symm AddCircle.continuous_equivIoc_symm variable {x : AddCircle p} (hx : x ≠ a) theorem continuousAt_equivIco : ContinuousAt (equivIco p a) x := by induction x using QuotientAddGroup.induction_on' rw [ContinuousAt, Filter.Tendsto, QuotientAddGroup.nhds_eq, Filter.map_map] exact (continuousAt_toIcoMod hp.out a hx).codRestrict _ #align add_circle.continuous_at_equiv_Ico AddCircle.continuousAt_equivIco theorem continuousAt_equivIoc : ContinuousAt (equivIoc p a) x := by induction x using QuotientAddGroup.induction_on' rw [ContinuousAt, Filter.Tendsto, QuotientAddGroup.nhds_eq, Filter.map_map] exact (continuousAt_toIocMod hp.out a hx).codRestrict _ #align add_circle.continuous_at_equiv_Ioc AddCircle.continuousAt_equivIoc /-- The quotient map `𝕜 → AddCircle p` as a partial homeomorphism. -/ @[simps] def partialHomeomorphCoe [DiscreteTopology (zmultiples p)] : PartialHomeomorph 𝕜 (AddCircle p) where toFun := (↑) invFun := fun x ↦ equivIco p a x source := Ioo a (a + p) target := {↑a}ᶜ map_source' := by intro x hx hx' exact hx.1.ne' ((coe_eq_coe_iff_of_mem_Ico (Ioo_subset_Ico_self hx) (left_mem_Ico.mpr (lt_add_of_pos_right a hp.out))).mp hx') map_target' := by intro x hx exact (eq_left_or_mem_Ioo_of_mem_Ico (equivIco p a x).2).resolve_left (hx ∘ ((equivIco p a).symm_apply_apply x).symm.trans ∘ congrArg _) left_inv' := fun x hx ↦ congrArg _ ((equivIco p a).apply_symm_apply ⟨x, Ioo_subset_Ico_self hx⟩) right_inv' := fun x _ ↦ (equivIco p a).symm_apply_apply x open_source := isOpen_Ioo open_target := isOpen_compl_singleton continuousOn_toFun := (AddCircle.continuous_mk' p).continuousOn continuousOn_invFun := by exact ContinuousAt.continuousOn (fun _ ↦ continuousAt_subtype_val.comp ∘ continuousAt_equivIco p a) lemma isLocalHomeomorph_coe [DiscreteTopology (zmultiples p)] [DenselyOrdered 𝕜] : IsLocalHomeomorph ((↑) : 𝕜 → AddCircle p) := by intro a obtain ⟨b, hb1, hb2⟩ := exists_between (sub_lt_self a hp.out) exact ⟨partialHomeomorphCoe p b, ⟨hb2, lt_add_of_sub_right_lt hb1⟩, rfl⟩ end Continuity /-- The image of the closed-open interval `[a, a + p)` under the quotient map `𝕜 → AddCircle p` is the entire space. -/ @[simp] theorem coe_image_Ico_eq : ((↑) : 𝕜 → AddCircle p) '' Ico a (a + p) = univ := by rw [image_eq_range] exact (equivIco p a).symm.range_eq_univ #align add_circle.coe_image_Ico_eq AddCircle.coe_image_Ico_eq /-- The image of the closed-open interval `[a, a + p)` under the quotient map `𝕜 → AddCircle p` is the entire space. -/ @[simp] theorem coe_image_Ioc_eq : ((↑) : 𝕜 → AddCircle p) '' Ioc a (a + p) = univ := by rw [image_eq_range] exact (equivIoc p a).symm.range_eq_univ #align add_circle.coe_image_Ioc_eq AddCircle.coe_image_Ioc_eq /-- The image of the closed interval `[0, p]` under the quotient map `𝕜 → AddCircle p` is the entire space. -/ @[simp] theorem coe_image_Icc_eq : ((↑) : 𝕜 → AddCircle p) '' Icc a (a + p) = univ := eq_top_mono (image_subset _ Ico_subset_Icc_self) <| coe_image_Ico_eq _ _ #align add_circle.coe_image_Icc_eq AddCircle.coe_image_Icc_eq end LinearOrderedAddCommGroup section LinearOrderedField variable [LinearOrderedField 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] (p q : 𝕜) /-- The rescaling equivalence between additive circles with different periods. -/ def equivAddCircle (hp : p ≠ 0) (hq : q ≠ 0) : AddCircle p ≃+ AddCircle q := QuotientAddGroup.congr _ _ (AddAut.mulRight <| (Units.mk0 p hp)⁻¹ * Units.mk0 q hq) <| by rw [AddMonoidHom.map_zmultiples, AddMonoidHom.coe_coe, AddAut.mulRight_apply, Units.val_mul, Units.val_mk0, Units.val_inv_eq_inv_val, Units.val_mk0, mul_inv_cancel_left₀ hp] #align add_circle.equiv_add_circle AddCircle.equivAddCircle @[simp] theorem equivAddCircle_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) : equivAddCircle p q hp hq (x : 𝕜) = (x * (p⁻¹ * q) : 𝕜) := rfl #align add_circle.equiv_add_circle_apply_mk AddCircle.equivAddCircle_apply_mk @[simp] theorem equivAddCircle_symm_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) : (equivAddCircle p q hp hq).symm (x : 𝕜) = (x * (q⁻¹ * p) : 𝕜) := rfl #align add_circle.equiv_add_circle_symm_apply_mk AddCircle.equivAddCircle_symm_apply_mk /-- The rescaling homeomorphism between additive circles with different periods. -/ def homeomorphAddCircle (hp : p ≠ 0) (hq : q ≠ 0) : AddCircle p ≃ₜ AddCircle q := ⟨equivAddCircle p q hp hq, (continuous_quotient_mk'.comp (continuous_mul_right (p⁻¹ * q))).quotient_lift _, (continuous_quotient_mk'.comp (continuous_mul_right (q⁻¹ * p))).quotient_lift _⟩ @[simp] theorem homeomorphAddCircle_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) : homeomorphAddCircle p q hp hq (x : 𝕜) = (x * (p⁻¹ * q) : 𝕜) := rfl @[simp] theorem homeomorphAddCircle_symm_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) : (homeomorphAddCircle p q hp hq).symm (x : 𝕜) = (x * (q⁻¹ * p) : 𝕜) := rfl variable [hp : Fact (0 < p)] section FloorRing variable [FloorRing 𝕜] @[simp] theorem coe_equivIco_mk_apply (x : 𝕜) : (equivIco p 0 <| QuotientAddGroup.mk x : 𝕜) = Int.fract (x / p) * p := toIcoMod_eq_fract_mul _ x #align add_circle.coe_equiv_Ico_mk_apply AddCircle.coe_equivIco_mk_apply set_option backward.isDefEq.lazyProjDelta false in -- See https://github.com/leanprover-community/mathlib4/issues/12535 instance : DivisibleBy (AddCircle p) ℤ where div x n := (↑((n : 𝕜)⁻¹ * (equivIco p 0 x : 𝕜)) : AddCircle p) div_zero x := by simp only [algebraMap.coe_zero, Int.cast_zero, inv_zero, zero_mul, QuotientAddGroup.mk_zero] div_cancel {n} x hn := by replace hn : (n : 𝕜) ≠ 0 := by norm_cast change n • QuotientAddGroup.mk' _ ((n : 𝕜)⁻¹ * ↑(equivIco p 0 x)) = x rw [← map_zsmul, ← smul_mul_assoc, zsmul_eq_mul, mul_inv_cancel hn, one_mul] exact (equivIco p 0).symm_apply_apply x end FloorRing section FiniteOrderPoints variable {p} theorem addOrderOf_period_div {n : ℕ} (h : 0 < n) : addOrderOf ((p / n : 𝕜) : AddCircle p) = n := by rw [addOrderOf_eq_iff h] replace h : 0 < (n : 𝕜) := Nat.cast_pos.2 h refine ⟨?_, fun m hn h0 => ?_⟩ <;> simp only [Ne, ← coe_nsmul, nsmul_eq_mul] · rw [mul_div_cancel₀ _ h.ne', coe_period] rw [coe_eq_zero_of_pos_iff p hp.out (mul_pos (Nat.cast_pos.2 h0) <| div_pos hp.out h)] rintro ⟨k, hk⟩ rw [mul_div, eq_div_iff h.ne', nsmul_eq_mul, mul_right_comm, ← Nat.cast_mul, (mul_left_injective₀ hp.out.ne').eq_iff, Nat.cast_inj, mul_comm] at hk exact (Nat.le_of_dvd h0 ⟨_, hk.symm⟩).not_lt hn #align add_circle.add_order_of_period_div AddCircle.addOrderOf_period_div variable (p) theorem gcd_mul_addOrderOf_div_eq {n : ℕ} (m : ℕ) (hn : 0 < n) : m.gcd n * addOrderOf (↑(↑m / ↑n * p) : AddCircle p) = n := by rw [mul_comm_div, ← nsmul_eq_mul, coe_nsmul, IsOfFinAddOrder.addOrderOf_nsmul] · rw [addOrderOf_period_div hn, Nat.gcd_comm, Nat.mul_div_cancel'] exact n.gcd_dvd_left m · rwa [← addOrderOf_pos_iff, addOrderOf_period_div hn] #align add_circle.gcd_mul_add_order_of_div_eq AddCircle.gcd_mul_addOrderOf_div_eq variable {p} theorem addOrderOf_div_of_gcd_eq_one {m n : ℕ} (hn : 0 < n) (h : m.gcd n = 1) : addOrderOf (↑(↑m / ↑n * p) : AddCircle p) = n := by convert gcd_mul_addOrderOf_div_eq p m hn rw [h, one_mul] #align add_circle.add_order_of_div_of_gcd_eq_one AddCircle.addOrderOf_div_of_gcd_eq_one theorem addOrderOf_div_of_gcd_eq_one' {m : ℤ} {n : ℕ} (hn : 0 < n) (h : m.natAbs.gcd n = 1) : addOrderOf (↑(↑m / ↑n * p) : AddCircle p) = n := by induction m · simp only [Int.ofNat_eq_coe, Int.cast_natCast, Int.natAbs_ofNat] at h ⊢ exact addOrderOf_div_of_gcd_eq_one hn h · simp only [Int.cast_negSucc, neg_div, neg_mul, coe_neg, addOrderOf_neg] exact addOrderOf_div_of_gcd_eq_one hn h #align add_circle.add_order_of_div_of_gcd_eq_one' AddCircle.addOrderOf_div_of_gcd_eq_one' theorem addOrderOf_coe_rat {q : ℚ} : addOrderOf (↑(↑q * p) : AddCircle p) = q.den := by have : (↑(q.den : ℤ) : 𝕜) ≠ 0 := by norm_cast exact q.pos.ne.symm rw [← q.num_divInt_den, Rat.cast_divInt_of_ne_zero _ this, Int.cast_natCast, Rat.num_divInt_den, addOrderOf_div_of_gcd_eq_one' q.pos q.reduced] #align add_circle.add_order_of_coe_rat AddCircle.addOrderOf_coe_rat theorem addOrderOf_eq_pos_iff {u : AddCircle p} {n : ℕ} (h : 0 < n) : addOrderOf u = n ↔ ∃ m < n, m.gcd n = 1 ∧ ↑(↑m / ↑n * p) = u := by refine ⟨QuotientAddGroup.induction_on' u fun k hk => ?_, ?_⟩ · rintro ⟨m, _, h₁, rfl⟩ exact addOrderOf_div_of_gcd_eq_one h h₁ have h0 := addOrderOf_nsmul_eq_zero (k : AddCircle p) rw [hk, ← coe_nsmul, coe_eq_zero_iff] at h0 obtain ⟨a, ha⟩ := h0 have h0 : (_ : 𝕜) ≠ 0 := Nat.cast_ne_zero.2 h.ne' rw [nsmul_eq_mul, mul_comm, ← div_eq_iff h0, ← a.ediv_add_emod' n, add_smul, add_div, zsmul_eq_mul, Int.cast_mul, Int.cast_natCast, mul_assoc, ← mul_div, mul_comm _ p, mul_div_cancel_right₀ p h0] at ha have han : _ = a % n := Int.toNat_of_nonneg (Int.emod_nonneg _ <| mod_cast h.ne') have he : (↑(↑((a % n).toNat) / ↑n * p) : AddCircle p) = k := by convert congr_arg (QuotientAddGroup.mk : 𝕜 → (AddCircle p)) ha using 1 rw [coe_add, ← Int.cast_natCast, han, zsmul_eq_mul, mul_div_right_comm, eq_comm, add_left_eq_self, ← zsmul_eq_mul, coe_zsmul, coe_period, smul_zero] refine ⟨(a % n).toNat, ?_, ?_, he⟩ · rw [← Int.ofNat_lt, han] exact Int.emod_lt_of_pos _ (Int.ofNat_lt.2 h) · have := (gcd_mul_addOrderOf_div_eq p (Int.toNat (a % ↑n)) h).trans ((congr_arg addOrderOf he).trans hk).symm rw [he, Nat.mul_left_eq_self_iff] at this · exact this · rwa [hk] #align add_circle.add_order_of_eq_pos_iff AddCircle.addOrderOf_eq_pos_iff theorem exists_gcd_eq_one_of_isOfFinAddOrder {u : AddCircle p} (h : IsOfFinAddOrder u) : ∃ m : ℕ, m.gcd (addOrderOf u) = 1 ∧ m < addOrderOf u ∧ ↑((m : 𝕜) / addOrderOf u * p) = u := let ⟨m, hl, hg, he⟩ := (addOrderOf_eq_pos_iff h.addOrderOf_pos).1 rfl ⟨m, hg, hl, he⟩ #align add_circle.exists_gcd_eq_one_of_is_of_fin_add_order AddCircle.exists_gcd_eq_one_of_isOfFinAddOrder variable (p) /-- The natural bijection between points of order `n` and natural numbers less than and coprime to `n`. The inverse of the map sends `m ↦ (m/n * p : AddCircle p)` where `m` is coprime to `n` and satisfies `0 ≤ m < n`. -/ def setAddOrderOfEquiv {n : ℕ} (hn : 0 < n) : { u : AddCircle p | addOrderOf u = n } ≃ { m | m < n ∧ m.gcd n = 1 } := Equiv.symm <| Equiv.ofBijective (fun m => ⟨↑((m : 𝕜) / n * p), addOrderOf_div_of_gcd_eq_one hn m.prop.2⟩) (by refine ⟨fun m₁ m₂ h => Subtype.ext ?_, fun u => ?_⟩ · simp_rw [Subtype.ext_iff] at h rw [← sub_eq_zero, ← coe_sub, ← sub_mul, ← sub_div, ← Int.cast_natCast m₁, ← Int.cast_natCast m₂, ← Int.cast_sub, coe_eq_zero_iff] at h obtain ⟨m, hm⟩ := h rw [← mul_div_right_comm, eq_div_iff, mul_comm, ← zsmul_eq_mul, mul_smul_comm, ← nsmul_eq_mul, ← natCast_zsmul, smul_smul, (zsmul_strictMono_left hp.out).injective.eq_iff, mul_comm] at hm swap · exact Nat.cast_ne_zero.2 hn.ne' rw [← @Nat.cast_inj ℤ, ← sub_eq_zero] refine Int.eq_zero_of_abs_lt_dvd ⟨_, hm.symm⟩ (abs_sub_lt_iff.2 ⟨?_, ?_⟩) <;> apply (Int.sub_le_self _ <| Nat.cast_nonneg _).trans_lt (Nat.cast_lt.2 _) exacts [m₁.2.1, m₂.2.1] obtain ⟨m, hmn, hg, he⟩ := (addOrderOf_eq_pos_iff hn).mp u.2 exact ⟨⟨m, hmn, hg⟩, Subtype.ext he⟩) #align add_circle.set_add_order_of_equiv AddCircle.setAddOrderOfEquiv @[simp] theorem card_addOrderOf_eq_totient {n : ℕ} : Nat.card { u : AddCircle p // addOrderOf u = n } = n.totient := by rcases n.eq_zero_or_pos with (rfl | hn) · simp only [Nat.totient_zero, addOrderOf_eq_zero_iff] rcases em (∃ u : AddCircle p, ¬IsOfFinAddOrder u) with (⟨u, hu⟩ | h) · have : Infinite { u : AddCircle p // ¬IsOfFinAddOrder u } := by erw [infinite_coe_iff] exact infinite_not_isOfFinAddOrder hu exact Nat.card_eq_zero_of_infinite · have : IsEmpty { u : AddCircle p // ¬IsOfFinAddOrder u } := by simpa using h exact Nat.card_of_isEmpty · rw [← coe_setOf, Nat.card_congr (setAddOrderOfEquiv p hn), n.totient_eq_card_lt_and_coprime] simp only [Nat.gcd_comm] #align add_circle.card_add_order_of_eq_totient AddCircle.card_addOrderOf_eq_totient theorem finite_setOf_add_order_eq {n : ℕ} (hn : 0 < n) : { u : AddCircle p | addOrderOf u = n }.Finite := finite_coe_iff.mp <| Nat.finite_of_card_ne_zero <| by simp [hn.ne'] #align add_circle.finite_set_of_add_order_eq AddCircle.finite_setOf_add_order_eq end FiniteOrderPoints end LinearOrderedField variable (p : ℝ) instance pathConnectedSpace : PathConnectedSpace <| AddCircle p := (inferInstance : PathConnectedSpace (Quotient _)) /-- The "additive circle" `ℝ ⧸ (ℤ ∙ p)` is compact. -/ instance compactSpace [Fact (0 < p)] : CompactSpace <| AddCircle p := by rw [← isCompact_univ_iff, ← coe_image_Icc_eq p 0] exact isCompact_Icc.image (AddCircle.continuous_mk' p) #align add_circle.compact_space AddCircle.compactSpace /-- The action on `ℝ` by right multiplication of its the subgroup `zmultiples p` (the multiples of `p:ℝ`) is properly discontinuous. -/ instance : ProperlyDiscontinuousVAdd (zmultiples p).op ℝ := (zmultiples p).properlyDiscontinuousVAdd_opposite_of_tendsto_cofinite (AddSubgroup.tendsto_zmultiples_subtype_cofinite p) end AddCircle section UnitAddCircle instance instZeroLTOne [StrictOrderedSemiring 𝕜] : Fact ((0 : 𝕜) < 1) := ⟨zero_lt_one⟩ /-- The unit circle `ℝ ⧸ ℤ`. -/ abbrev UnitAddCircle := AddCircle (1 : ℝ) #align unit_add_circle UnitAddCircle end UnitAddCircle section IdentifyIccEnds /-! This section proves that for any `a`, the natural map from `[a, a + p] ⊂ 𝕜` to `AddCircle p` gives an identification of `AddCircle p`, as a topological space, with the quotient of `[a, a + p]` by the equivalence relation identifying the endpoints. -/ namespace AddCircle variable [LinearOrderedAddCommGroup 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] (p a : 𝕜) [hp : Fact (0 < p)] local notation "𝕋" => AddCircle p /-- The relation identifying the endpoints of `Icc a (a + p)`. -/ inductive EndpointIdent : Icc a (a + p) → Icc a (a + p) → Prop | mk : EndpointIdent ⟨a, left_mem_Icc.mpr <| le_add_of_nonneg_right hp.out.le⟩ ⟨a + p, right_mem_Icc.mpr <| le_add_of_nonneg_right hp.out.le⟩ #align add_circle.endpoint_ident AddCircle.EndpointIdent variable [Archimedean 𝕜] /-- The equivalence between `AddCircle p` and the quotient of `[a, a + p]` by the relation identifying the endpoints. -/ def equivIccQuot : 𝕋 ≃ Quot (EndpointIdent p a) where toFun x := Quot.mk _ <| inclusion Ico_subset_Icc_self (equivIco _ _ x) invFun x := Quot.liftOn x (↑) <| by rintro _ _ ⟨_⟩ exact (coe_add_period p a).symm left_inv := (equivIco p a).symm_apply_apply right_inv := Quot.ind <| by rintro ⟨x, hx⟩ rcases ne_or_eq x (a + p) with (h | rfl) · revert x dsimp only intro x hx h congr ext1 apply congr_arg Subtype.val ((equivIco p a).right_inv ⟨x, hx.1, hx.2.lt_of_ne h⟩) · rw [← Quot.sound EndpointIdent.mk] dsimp only congr ext1 apply congr_arg Subtype.val ((equivIco p a).right_inv ⟨a, le_refl a, lt_add_of_pos_right a hp.out⟩) #align add_circle.equiv_Icc_quot AddCircle.equivIccQuot theorem equivIccQuot_comp_mk_eq_toIcoMod : equivIccQuot p a ∘ Quotient.mk'' = fun x => Quot.mk _ ⟨toIcoMod hp.out a x, Ico_subset_Icc_self <| toIcoMod_mem_Ico _ _ x⟩ := rfl #align add_circle.equiv_Icc_quot_comp_mk_eq_to_Ico_mod AddCircle.equivIccQuot_comp_mk_eq_toIcoMod
Mathlib/Topology/Instances/AddCircle.lean
625
633
theorem equivIccQuot_comp_mk_eq_toIocMod : equivIccQuot p a ∘ Quotient.mk'' = fun x => Quot.mk _ ⟨toIocMod hp.out a x, Ioc_subset_Icc_self <| toIocMod_mem_Ioc _ _ x⟩ := by
rw [equivIccQuot_comp_mk_eq_toIcoMod] funext x by_cases h : a ≡ x [PMOD p] · simp_rw [(modEq_iff_toIcoMod_eq_left hp.out).1 h, (modEq_iff_toIocMod_eq_right hp.out).1 h] exact Quot.sound EndpointIdent.mk · simp_rw [(not_modEq_iff_toIcoMod_eq_toIocMod hp.out).1 h]
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Utensil Song -/ import Mathlib.Algebra.RingQuot import Mathlib.LinearAlgebra.TensorAlgebra.Basic import Mathlib.LinearAlgebra.QuadraticForm.Isometry import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv #align_import linear_algebra.clifford_algebra.basic from "leanprover-community/mathlib"@"d46774d43797f5d1f507a63a6e904f7a533ae74a" /-! # Clifford Algebras We construct the Clifford algebra of a module `M` over a commutative ring `R`, equipped with a quadratic form `Q`. ## Notation The Clifford algebra of the `R`-module `M` equipped with a quadratic form `Q` is an `R`-algebra denoted `CliffordAlgebra Q`. Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that `cond : ∀ m, f m * f m = algebraMap _ _ (Q m)`, there is a (unique) lift of `f` to an `R`-algebra morphism from `CliffordAlgebra Q` to `A`, which is denoted `CliffordAlgebra.lift Q f cond`. The canonical linear map `M → CliffordAlgebra Q` is denoted `CliffordAlgebra.ι Q`. ## Theorems The main theorems proved ensure that `CliffordAlgebra Q` satisfies the universal property of the Clifford algebra. 1. `ι_comp_lift` is the fact that the composition of `ι Q` with `lift Q f cond` agrees with `f`. 2. `lift_unique` ensures the uniqueness of `lift Q f cond` with respect to 1. ## Implementation details The Clifford algebra of `M` is constructed as a quotient of the tensor algebra, as follows. 1. We define a relation `CliffordAlgebra.Rel Q` on `TensorAlgebra R M`. This is the smallest relation which identifies squares of elements of `M` with `Q m`. 2. The Clifford algebra is the quotient of the tensor algebra by this relation. This file is almost identical to `Mathlib/LinearAlgebra/ExteriorAlgebra/Basic.lean`. -/ variable {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable (Q : QuadraticForm R M) variable {n : ℕ} namespace CliffordAlgebra open TensorAlgebra /-- `Rel` relates each `ι m * ι m`, for `m : M`, with `Q m`. The Clifford algebra of `M` is defined as the quotient modulo this relation. -/ inductive Rel : TensorAlgebra R M → TensorAlgebra R M → Prop | of (m : M) : Rel (ι R m * ι R m) (algebraMap R _ (Q m)) #align clifford_algebra.rel CliffordAlgebra.Rel end CliffordAlgebra /-- The Clifford algebra of an `R`-module `M` equipped with a quadratic_form `Q`. -/ def CliffordAlgebra := RingQuot (CliffordAlgebra.Rel Q) #align clifford_algebra CliffordAlgebra namespace CliffordAlgebra -- Porting note: Expanded `deriving Inhabited, Semiring, Algebra` instance instInhabited : Inhabited (CliffordAlgebra Q) := RingQuot.instInhabited _ #align clifford_algebra.inhabited CliffordAlgebra.instInhabited instance instRing : Ring (CliffordAlgebra Q) := RingQuot.instRing _ #align clifford_algebra.ring CliffordAlgebra.instRing instance (priority := 900) instAlgebra' {R A M} [CommSemiring R] [AddCommGroup M] [CommRing A] [Algebra R A] [Module R M] [Module A M] (Q : QuadraticForm A M) [IsScalarTower R A M] : Algebra R (CliffordAlgebra Q) := RingQuot.instAlgebra _ -- verify there are no diamonds -- but doesn't work at `reducible_and_instances` #10906 example : (algebraNat : Algebra ℕ (CliffordAlgebra Q)) = instAlgebra' _ := rfl -- but doesn't work at `reducible_and_instances` #10906 example : (algebraInt _ : Algebra ℤ (CliffordAlgebra Q)) = instAlgebra' _ := rfl -- shortcut instance, as the other instance is slow instance instAlgebra : Algebra R (CliffordAlgebra Q) := instAlgebra' _ #align clifford_algebra.algebra CliffordAlgebra.instAlgebra instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing A] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] (Q : QuadraticForm A M) [IsScalarTower R A M] [IsScalarTower S A M] : SMulCommClass R S (CliffordAlgebra Q) := RingQuot.instSMulCommClass _ instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing A] [SMul R S] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] [IsScalarTower R A M] [IsScalarTower S A M] [IsScalarTower R S A] (Q : QuadraticForm A M) : IsScalarTower R S (CliffordAlgebra Q) := RingQuot.instIsScalarTower _ /-- The canonical linear map `M →ₗ[R] CliffordAlgebra Q`. -/ def ι : M →ₗ[R] CliffordAlgebra Q := (RingQuot.mkAlgHom R _).toLinearMap.comp (TensorAlgebra.ι R) #align clifford_algebra.ι CliffordAlgebra.ι /-- As well as being linear, `ι Q` squares to the quadratic form -/ @[simp] theorem ι_sq_scalar (m : M) : ι Q m * ι Q m = algebraMap R _ (Q m) := by erw [← AlgHom.map_mul, RingQuot.mkAlgHom_rel R (Rel.of m), AlgHom.commutes] rfl #align clifford_algebra.ι_sq_scalar CliffordAlgebra.ι_sq_scalar variable {Q} {A : Type*} [Semiring A] [Algebra R A] @[simp] theorem comp_ι_sq_scalar (g : CliffordAlgebra Q →ₐ[R] A) (m : M) : g (ι Q m) * g (ι Q m) = algebraMap _ _ (Q m) := by rw [← AlgHom.map_mul, ι_sq_scalar, AlgHom.commutes] #align clifford_algebra.comp_ι_sq_scalar CliffordAlgebra.comp_ι_sq_scalar variable (Q) /-- Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition: `cond : ∀ m : M, f m * f m = Q(m)`, this is the canonical lift of `f` to a morphism of `R`-algebras from `CliffordAlgebra Q` to `A`. -/ @[simps symm_apply] def lift : { f : M →ₗ[R] A // ∀ m, f m * f m = algebraMap _ _ (Q m) } ≃ (CliffordAlgebra Q →ₐ[R] A) where toFun f := RingQuot.liftAlgHom R ⟨TensorAlgebra.lift R (f : M →ₗ[R] A), fun x y (h : Rel Q x y) => by induction h rw [AlgHom.commutes, AlgHom.map_mul, TensorAlgebra.lift_ι_apply, f.prop]⟩ invFun F := ⟨F.toLinearMap.comp (ι Q), fun m => by rw [LinearMap.comp_apply, AlgHom.toLinearMap_apply, comp_ι_sq_scalar]⟩ left_inv f := by ext x -- Porting note: removed `simp only` proof which gets stuck simplifying `LinearMap.comp_apply` exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ x) right_inv F := -- Porting note: replaced with proof derived from the one for `TensorAlgebra` RingQuot.ringQuot_ext' _ _ _ <| TensorAlgebra.hom_ext <| LinearMap.ext fun x => by exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ _) #align clifford_algebra.lift CliffordAlgebra.lift variable {Q} @[simp] theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) : (lift Q ⟨f, cond⟩).toLinearMap.comp (ι Q) = f := Subtype.mk_eq_mk.mp <| (lift Q).symm_apply_apply ⟨f, cond⟩ #align clifford_algebra.ι_comp_lift CliffordAlgebra.ι_comp_lift @[simp] theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) (x) : lift Q ⟨f, cond⟩ (ι Q x) = f x := (LinearMap.ext_iff.mp <| ι_comp_lift f cond) x #align clifford_algebra.lift_ι_apply CliffordAlgebra.lift_ι_apply @[simp] theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m : M, f m * f m = algebraMap _ _ (Q m)) (g : CliffordAlgebra Q →ₐ[R] A) : g.toLinearMap.comp (ι Q) = f ↔ g = lift Q ⟨f, cond⟩ := by convert (lift Q : _ ≃ (CliffordAlgebra Q →ₐ[R] A)).symm_apply_eq -- Porting note: added `Subtype.mk_eq_mk` rw [lift_symm_apply, Subtype.mk_eq_mk] #align clifford_algebra.lift_unique CliffordAlgebra.lift_unique @[simp] theorem lift_comp_ι (g : CliffordAlgebra Q →ₐ[R] A) : lift Q ⟨g.toLinearMap.comp (ι Q), comp_ι_sq_scalar _⟩ = g := by -- Porting note: removed `rw [lift_symm_apply]; rfl`, changed `convert` to `exact` exact (lift Q : _ ≃ (CliffordAlgebra Q →ₐ[R] A)).apply_symm_apply g #align clifford_algebra.lift_comp_ι CliffordAlgebra.lift_comp_ι /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem hom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : CliffordAlgebra Q →ₐ[R] A} : f.toLinearMap.comp (ι Q) = g.toLinearMap.comp (ι Q) → f = g := by intro h apply (lift Q).symm.injective rw [lift_symm_apply, lift_symm_apply] simp only [h] #align clifford_algebra.hom_ext CliffordAlgebra.hom_ext -- This proof closely follows `TensorAlgebra.induction` /-- If `C` holds for the `algebraMap` of `r : R` into `CliffordAlgebra Q`, the `ι` of `x : M`, and is preserved under addition and muliplication, then it holds for all of `CliffordAlgebra Q`. See also the stronger `CliffordAlgebra.left_induction` and `CliffordAlgebra.right_induction`. -/ @[elab_as_elim] theorem induction {C : CliffordAlgebra Q → Prop} (algebraMap : ∀ r, C (algebraMap R (CliffordAlgebra Q) r)) (ι : ∀ x, C (ι Q x)) (mul : ∀ a b, C a → C b → C (a * b)) (add : ∀ a b, C a → C b → C (a + b)) (a : CliffordAlgebra Q) : C a := by -- the arguments are enough to construct a subalgebra, and a mapping into it from M let s : Subalgebra R (CliffordAlgebra Q) := { carrier := C mul_mem' := @mul add_mem' := @add algebraMap_mem' := algebraMap } -- Porting note: Added `h`. `h` is needed for `of`. letI h : AddCommMonoid s := inferInstanceAs (AddCommMonoid (Subalgebra.toSubmodule s)) let of : { f : M →ₗ[R] s // ∀ m, f m * f m = _root_.algebraMap _ _ (Q m) } := ⟨(CliffordAlgebra.ι Q).codRestrict (Subalgebra.toSubmodule s) ι, fun m => Subtype.eq <| ι_sq_scalar Q m⟩ -- the mapping through the subalgebra is the identity have of_id : AlgHom.id R (CliffordAlgebra Q) = s.val.comp (lift Q of) := by ext simp [of] -- Porting note: `simp` can't apply this erw [LinearMap.codRestrict_apply] -- finding a proof is finding an element of the subalgebra -- Porting note: was `convert Subtype.prop (lift Q of a); exact AlgHom.congr_fun of_id a` rw [← AlgHom.id_apply (R := R) a, of_id] exact Subtype.prop (lift Q of a) #align clifford_algebra.induction CliffordAlgebra.induction
Mathlib/LinearAlgebra/CliffordAlgebra/Basic.lean
233
242
theorem mul_add_swap_eq_polar_of_forall_mul_self_eq {A : Type*} [Ring A] [Algebra R A] (f : M →ₗ[R] A) (hf : ∀ x, f x * f x = algebraMap _ _ (Q x)) (a b : M) : f a * f b + f b * f a = algebraMap R _ (QuadraticForm.polar Q a b) := calc f a * f b + f b * f a = f (a + b) * f (a + b) - f a * f a - f b * f b := by
rw [f.map_add, mul_add, add_mul, add_mul]; abel _ = algebraMap R _ (Q (a + b)) - algebraMap R _ (Q a) - algebraMap R _ (Q b) := by rw [hf, hf, hf] _ = algebraMap R _ (Q (a + b) - Q a - Q b) := by rw [← RingHom.map_sub, ← RingHom.map_sub] _ = algebraMap R _ (QuadraticForm.polar Q a b) := rfl
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Floris van Doorn -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.Opposites import Mathlib.Algebra.Order.GroupWithZero.Synonym import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Data.Set.Lattice import Mathlib.Tactic.Common #align_import data.set.pointwise.basic from "leanprover-community/mathlib"@"5e526d18cea33550268dcbbddcb822d5cde40654" /-! # Pointwise operations of sets This file defines pointwise algebraic operations on sets. ## Main declarations For sets `s` and `t` and scalar `a`: * `s * t`: Multiplication, set of all `x * y` where `x ∈ s` and `y ∈ t`. * `s + t`: Addition, set of all `x + y` where `x ∈ s` and `y ∈ t`. * `s⁻¹`: Inversion, set of all `x⁻¹` where `x ∈ s`. * `-s`: Negation, set of all `-x` where `x ∈ s`. * `s / t`: Division, set of all `x / y` where `x ∈ s` and `y ∈ t`. * `s - t`: Subtraction, set of all `x - y` where `x ∈ s` and `y ∈ t`. For `α` a semigroup/monoid, `Set α` is a semigroup/monoid. As an unfortunate side effect, this means that `n • s`, where `n : ℕ`, is ambiguous between pointwise scaling and repeated pointwise addition; the former has `(2 : ℕ) • {1, 2} = {2, 4}`, while the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`. See note [pointwise nat action]. Appropriate definitions and results are also transported to the additive theory via `to_additive`. ## Implementation notes * The following expressions are considered in simp-normal form in a group: `(fun h ↦ h * g) ⁻¹' s`, `(fun h ↦ g * h) ⁻¹' s`, `(fun h ↦ h * g⁻¹) ⁻¹' s`, `(fun h ↦ g⁻¹ * h) ⁻¹' s`, `s * t`, `s⁻¹`, `(1 : Set _)` (and similarly for additive variants). Expressions equal to one of these will be simplified. * We put all instances in the locale `Pointwise`, so that these instances are not available by default. Note that we do not mark them as reducible (as argued by note [reducible non-instances]) since we expect the locale to be open whenever the instances are actually used (and making the instances reducible changes the behavior of `simp`. ## Tags set multiplication, set addition, pointwise addition, pointwise multiplication, pointwise subtraction -/ library_note "pointwise nat action"/-- Pointwise monoids (`Set`, `Finset`, `Filter`) have derived pointwise actions of the form `SMul α β → SMul α (Set β)`. When `α` is `ℕ` or `ℤ`, this action conflicts with the nat or int action coming from `Set β` being a `Monoid` or `DivInvMonoid`. For example, `2 • {a, b}` can both be `{2 • a, 2 • b}` (pointwise action, pointwise repeated addition, `Set.smulSet`) and `{a + a, a + b, b + a, b + b}` (nat or int action, repeated pointwise addition, `Set.NSMul`). Because the pointwise action can easily be spelled out in such cases, we give higher priority to the nat and int actions. -/ open Function variable {F α β γ : Type*} namespace Set /-! ### `0`/`1` as sets -/ section One variable [One α] {s : Set α} {a : α} /-- The set `1 : Set α` is defined as `{1}` in locale `Pointwise`. -/ @[to_additive "The set `0 : Set α` is defined as `{0}` in locale `Pointwise`."] protected noncomputable def one : One (Set α) := ⟨{1}⟩ #align set.has_one Set.one #align set.has_zero Set.zero scoped[Pointwise] attribute [instance] Set.one Set.zero open Pointwise @[to_additive] theorem singleton_one : ({1} : Set α) = 1 := rfl #align set.singleton_one Set.singleton_one #align set.singleton_zero Set.singleton_zero @[to_additive (attr := simp)] theorem mem_one : a ∈ (1 : Set α) ↔ a = 1 := Iff.rfl #align set.mem_one Set.mem_one #align set.mem_zero Set.mem_zero @[to_additive] theorem one_mem_one : (1 : α) ∈ (1 : Set α) := Eq.refl _ #align set.one_mem_one Set.one_mem_one #align set.zero_mem_zero Set.zero_mem_zero @[to_additive (attr := simp)] theorem one_subset : 1 ⊆ s ↔ (1 : α) ∈ s := singleton_subset_iff #align set.one_subset Set.one_subset #align set.zero_subset Set.zero_subset @[to_additive] theorem one_nonempty : (1 : Set α).Nonempty := ⟨1, rfl⟩ #align set.one_nonempty Set.one_nonempty #align set.zero_nonempty Set.zero_nonempty @[to_additive (attr := simp)] theorem image_one {f : α → β} : f '' 1 = {f 1} := image_singleton #align set.image_one Set.image_one #align set.image_zero Set.image_zero @[to_additive] theorem subset_one_iff_eq : s ⊆ 1 ↔ s = ∅ ∨ s = 1 := subset_singleton_iff_eq #align set.subset_one_iff_eq Set.subset_one_iff_eq #align set.subset_zero_iff_eq Set.subset_zero_iff_eq @[to_additive] theorem Nonempty.subset_one_iff (h : s.Nonempty) : s ⊆ 1 ↔ s = 1 := h.subset_singleton_iff #align set.nonempty.subset_one_iff Set.Nonempty.subset_one_iff #align set.nonempty.subset_zero_iff Set.Nonempty.subset_zero_iff /-- The singleton operation as a `OneHom`. -/ @[to_additive "The singleton operation as a `ZeroHom`."] noncomputable def singletonOneHom : OneHom α (Set α) where toFun := singleton; map_one' := singleton_one #align set.singleton_one_hom Set.singletonOneHom #align set.singleton_zero_hom Set.singletonZeroHom @[to_additive (attr := simp)] theorem coe_singletonOneHom : (singletonOneHom : α → Set α) = singleton := rfl #align set.coe_singleton_one_hom Set.coe_singletonOneHom #align set.coe_singleton_zero_hom Set.coe_singletonZeroHom end One /-! ### Set negation/inversion -/ section Inv /-- The pointwise inversion of set `s⁻¹` is defined as `{x | x⁻¹ ∈ s}` in locale `Pointwise`. It is equal to `{x⁻¹ | x ∈ s}`, see `Set.image_inv`. -/ @[to_additive "The pointwise negation of set `-s` is defined as `{x | -x ∈ s}` in locale `Pointwise`. It is equal to `{-x | x ∈ s}`, see `Set.image_neg`."] protected def inv [Inv α] : Inv (Set α) := ⟨preimage Inv.inv⟩ #align set.has_inv Set.inv #align set.has_neg Set.neg scoped[Pointwise] attribute [instance] Set.inv Set.neg open Pointwise section Inv variable {ι : Sort*} [Inv α] {s t : Set α} {a : α} @[to_additive (attr := simp)] theorem mem_inv : a ∈ s⁻¹ ↔ a⁻¹ ∈ s := Iff.rfl #align set.mem_inv Set.mem_inv #align set.mem_neg Set.mem_neg @[to_additive (attr := simp)] theorem inv_preimage : Inv.inv ⁻¹' s = s⁻¹ := rfl #align set.inv_preimage Set.inv_preimage #align set.neg_preimage Set.neg_preimage @[to_additive (attr := simp)] theorem inv_empty : (∅ : Set α)⁻¹ = ∅ := rfl #align set.inv_empty Set.inv_empty #align set.neg_empty Set.neg_empty @[to_additive (attr := simp)] theorem inv_univ : (univ : Set α)⁻¹ = univ := rfl #align set.inv_univ Set.inv_univ #align set.neg_univ Set.neg_univ @[to_additive (attr := simp)] theorem inter_inv : (s ∩ t)⁻¹ = s⁻¹ ∩ t⁻¹ := preimage_inter #align set.inter_inv Set.inter_inv #align set.inter_neg Set.inter_neg @[to_additive (attr := simp)] theorem union_inv : (s ∪ t)⁻¹ = s⁻¹ ∪ t⁻¹ := preimage_union #align set.union_inv Set.union_inv #align set.union_neg Set.union_neg @[to_additive (attr := simp)] theorem iInter_inv (s : ι → Set α) : (⋂ i, s i)⁻¹ = ⋂ i, (s i)⁻¹ := preimage_iInter #align set.Inter_inv Set.iInter_inv #align set.Inter_neg Set.iInter_neg @[to_additive (attr := simp)] theorem iUnion_inv (s : ι → Set α) : (⋃ i, s i)⁻¹ = ⋃ i, (s i)⁻¹ := preimage_iUnion #align set.Union_inv Set.iUnion_inv #align set.Union_neg Set.iUnion_neg @[to_additive (attr := simp)] theorem compl_inv : sᶜ⁻¹ = s⁻¹ᶜ := preimage_compl #align set.compl_inv Set.compl_inv #align set.compl_neg Set.compl_neg end Inv section InvolutiveInv variable [InvolutiveInv α] {s t : Set α} {a : α} @[to_additive] theorem inv_mem_inv : a⁻¹ ∈ s⁻¹ ↔ a ∈ s := by simp only [mem_inv, inv_inv] #align set.inv_mem_inv Set.inv_mem_inv #align set.neg_mem_neg Set.neg_mem_neg @[to_additive (attr := simp)] theorem nonempty_inv : s⁻¹.Nonempty ↔ s.Nonempty := inv_involutive.surjective.nonempty_preimage #align set.nonempty_inv Set.nonempty_inv #align set.nonempty_neg Set.nonempty_neg @[to_additive] theorem Nonempty.inv (h : s.Nonempty) : s⁻¹.Nonempty := nonempty_inv.2 h #align set.nonempty.inv Set.Nonempty.inv #align set.nonempty.neg Set.Nonempty.neg @[to_additive (attr := simp)] theorem image_inv : Inv.inv '' s = s⁻¹ := congr_fun (image_eq_preimage_of_inverse inv_involutive.leftInverse inv_involutive.rightInverse) _ #align set.image_inv Set.image_inv #align set.image_neg Set.image_neg @[to_additive (attr := simp)] theorem inv_eq_empty : s⁻¹ = ∅ ↔ s = ∅ := by rw [← image_inv, image_eq_empty] @[to_additive (attr := simp)] noncomputable instance involutiveInv : InvolutiveInv (Set α) where inv := Inv.inv inv_inv s := by simp only [← inv_preimage, preimage_preimage, inv_inv, preimage_id'] @[to_additive (attr := simp)] theorem inv_subset_inv : s⁻¹ ⊆ t⁻¹ ↔ s ⊆ t := (Equiv.inv α).surjective.preimage_subset_preimage_iff #align set.inv_subset_inv Set.inv_subset_inv #align set.neg_subset_neg Set.neg_subset_neg @[to_additive] theorem inv_subset : s⁻¹ ⊆ t ↔ s ⊆ t⁻¹ := by rw [← inv_subset_inv, inv_inv] #align set.inv_subset Set.inv_subset #align set.neg_subset Set.neg_subset @[to_additive (attr := simp)] theorem inv_singleton (a : α) : ({a} : Set α)⁻¹ = {a⁻¹} := by rw [← image_inv, image_singleton] #align set.inv_singleton Set.inv_singleton #align set.neg_singleton Set.neg_singleton @[to_additive (attr := simp)] theorem inv_insert (a : α) (s : Set α) : (insert a s)⁻¹ = insert a⁻¹ s⁻¹ := by rw [insert_eq, union_inv, inv_singleton, insert_eq] #align set.inv_insert Set.inv_insert #align set.neg_insert Set.neg_insert @[to_additive] theorem inv_range {ι : Sort*} {f : ι → α} : (range f)⁻¹ = range fun i => (f i)⁻¹ := by rw [← image_inv] exact (range_comp _ _).symm #align set.inv_range Set.inv_range #align set.neg_range Set.neg_range open MulOpposite @[to_additive] theorem image_op_inv : op '' s⁻¹ = (op '' s)⁻¹ := by simp_rw [← image_inv, Function.Semiconj.set_image op_inv s] #align set.image_op_inv Set.image_op_inv #align set.image_op_neg Set.image_op_neg end InvolutiveInv end Inv open Pointwise /-! ### Set addition/multiplication -/ section Mul variable {ι : Sort*} {κ : ι → Sort*} [Mul α] {s s₁ s₂ t t₁ t₂ u : Set α} {a b : α} /-- The pointwise multiplication of sets `s * t` and `t` is defined as `{x * y | x ∈ s, y ∈ t}` in locale `Pointwise`. -/ @[to_additive "The pointwise addition of sets `s + t` is defined as `{x + y | x ∈ s, y ∈ t}` in locale `Pointwise`."] protected def mul : Mul (Set α) := ⟨image2 (· * ·)⟩ #align set.has_mul Set.mul #align set.has_add Set.add scoped[Pointwise] attribute [instance] Set.mul Set.add @[to_additive (attr := simp)] theorem image2_mul : image2 (· * ·) s t = s * t := rfl #align set.image2_mul Set.image2_mul #align set.image2_add Set.image2_add @[to_additive] theorem mem_mul : a ∈ s * t ↔ ∃ x ∈ s, ∃ y ∈ t, x * y = a := Iff.rfl #align set.mem_mul Set.mem_mul #align set.mem_add Set.mem_add @[to_additive] theorem mul_mem_mul : a ∈ s → b ∈ t → a * b ∈ s * t := mem_image2_of_mem #align set.mul_mem_mul Set.mul_mem_mul #align set.add_mem_add Set.add_mem_add @[to_additive add_image_prod] theorem image_mul_prod : (fun x : α × α => x.fst * x.snd) '' s ×ˢ t = s * t := image_prod _ #align set.image_mul_prod Set.image_mul_prod #align set.add_image_prod Set.add_image_prod @[to_additive (attr := simp)] theorem empty_mul : ∅ * s = ∅ := image2_empty_left #align set.empty_mul Set.empty_mul #align set.empty_add Set.empty_add @[to_additive (attr := simp)] theorem mul_empty : s * ∅ = ∅ := image2_empty_right #align set.mul_empty Set.mul_empty #align set.add_empty Set.add_empty @[to_additive (attr := simp)] theorem mul_eq_empty : s * t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff #align set.mul_eq_empty Set.mul_eq_empty #align set.add_eq_empty Set.add_eq_empty @[to_additive (attr := simp)] theorem mul_nonempty : (s * t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image2_nonempty_iff #align set.mul_nonempty Set.mul_nonempty #align set.add_nonempty Set.add_nonempty @[to_additive] theorem Nonempty.mul : s.Nonempty → t.Nonempty → (s * t).Nonempty := Nonempty.image2 #align set.nonempty.mul Set.Nonempty.mul #align set.nonempty.add Set.Nonempty.add @[to_additive] theorem Nonempty.of_mul_left : (s * t).Nonempty → s.Nonempty := Nonempty.of_image2_left #align set.nonempty.of_mul_left Set.Nonempty.of_mul_left #align set.nonempty.of_add_left Set.Nonempty.of_add_left @[to_additive] theorem Nonempty.of_mul_right : (s * t).Nonempty → t.Nonempty := Nonempty.of_image2_right #align set.nonempty.of_mul_right Set.Nonempty.of_mul_right #align set.nonempty.of_add_right Set.Nonempty.of_add_right @[to_additive (attr := simp)] theorem mul_singleton : s * {b} = (· * b) '' s := image2_singleton_right #align set.mul_singleton Set.mul_singleton #align set.add_singleton Set.add_singleton @[to_additive (attr := simp)] theorem singleton_mul : {a} * t = (a * ·) '' t := image2_singleton_left #align set.singleton_mul Set.singleton_mul #align set.singleton_add Set.singleton_add -- Porting note (#10618): simp can prove this @[to_additive] theorem singleton_mul_singleton : ({a} : Set α) * {b} = {a * b} := image2_singleton #align set.singleton_mul_singleton Set.singleton_mul_singleton #align set.singleton_add_singleton Set.singleton_add_singleton @[to_additive (attr := mono)] theorem mul_subset_mul : s₁ ⊆ t₁ → s₂ ⊆ t₂ → s₁ * s₂ ⊆ t₁ * t₂ := image2_subset #align set.mul_subset_mul Set.mul_subset_mul #align set.add_subset_add Set.add_subset_add @[to_additive] theorem mul_subset_mul_left : t₁ ⊆ t₂ → s * t₁ ⊆ s * t₂ := image2_subset_left #align set.mul_subset_mul_left Set.mul_subset_mul_left #align set.add_subset_add_left Set.add_subset_add_left @[to_additive] theorem mul_subset_mul_right : s₁ ⊆ s₂ → s₁ * t ⊆ s₂ * t := image2_subset_right #align set.mul_subset_mul_right Set.mul_subset_mul_right #align set.add_subset_add_right Set.add_subset_add_right @[to_additive] theorem mul_subset_iff : s * t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x * y ∈ u := image2_subset_iff #align set.mul_subset_iff Set.mul_subset_iff #align set.add_subset_iff Set.add_subset_iff @[to_additive] theorem union_mul : (s₁ ∪ s₂) * t = s₁ * t ∪ s₂ * t := image2_union_left #align set.union_mul Set.union_mul #align set.union_add Set.union_add @[to_additive] theorem mul_union : s * (t₁ ∪ t₂) = s * t₁ ∪ s * t₂ := image2_union_right #align set.mul_union Set.mul_union #align set.add_union Set.add_union @[to_additive] theorem inter_mul_subset : s₁ ∩ s₂ * t ⊆ s₁ * t ∩ (s₂ * t) := image2_inter_subset_left #align set.inter_mul_subset Set.inter_mul_subset #align set.inter_add_subset Set.inter_add_subset @[to_additive] theorem mul_inter_subset : s * (t₁ ∩ t₂) ⊆ s * t₁ ∩ (s * t₂) := image2_inter_subset_right #align set.mul_inter_subset Set.mul_inter_subset #align set.add_inter_subset Set.add_inter_subset @[to_additive] theorem inter_mul_union_subset_union : s₁ ∩ s₂ * (t₁ ∪ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ := image2_inter_union_subset_union #align set.inter_mul_union_subset_union Set.inter_mul_union_subset_union #align set.inter_add_union_subset_union Set.inter_add_union_subset_union @[to_additive] theorem union_mul_inter_subset_union : (s₁ ∪ s₂) * (t₁ ∩ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ := image2_union_inter_subset_union #align set.union_mul_inter_subset_union Set.union_mul_inter_subset_union #align set.union_add_inter_subset_union Set.union_add_inter_subset_union @[to_additive] theorem iUnion_mul_left_image : ⋃ a ∈ s, (a * ·) '' t = s * t := iUnion_image_left _ #align set.Union_mul_left_image Set.iUnion_mul_left_image #align set.Union_add_left_image Set.iUnion_add_left_image @[to_additive] theorem iUnion_mul_right_image : ⋃ a ∈ t, (· * a) '' s = s * t := iUnion_image_right _ #align set.Union_mul_right_image Set.iUnion_mul_right_image #align set.Union_add_right_image Set.iUnion_add_right_image @[to_additive] theorem iUnion_mul (s : ι → Set α) (t : Set α) : (⋃ i, s i) * t = ⋃ i, s i * t := image2_iUnion_left _ _ _ #align set.Union_mul Set.iUnion_mul #align set.Union_add Set.iUnion_add @[to_additive] theorem mul_iUnion (s : Set α) (t : ι → Set α) : (s * ⋃ i, t i) = ⋃ i, s * t i := image2_iUnion_right _ _ _ #align set.mul_Union Set.mul_iUnion #align set.add_Union Set.add_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iUnion₂_mul (s : ∀ i, κ i → Set α) (t : Set α) : (⋃ (i) (j), s i j) * t = ⋃ (i) (j), s i j * t := image2_iUnion₂_left _ _ _ #align set.Union₂_mul Set.iUnion₂_mul #align set.Union₂_add Set.iUnion₂_add /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem mul_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s * ⋃ (i) (j), t i j) = ⋃ (i) (j), s * t i j := image2_iUnion₂_right _ _ _ #align set.mul_Union₂ Set.mul_iUnion₂ #align set.add_Union₂ Set.add_iUnion₂ @[to_additive] theorem iInter_mul_subset (s : ι → Set α) (t : Set α) : (⋂ i, s i) * t ⊆ ⋂ i, s i * t := Set.image2_iInter_subset_left _ _ _ #align set.Inter_mul_subset Set.iInter_mul_subset #align set.Inter_add_subset Set.iInter_add_subset @[to_additive] theorem mul_iInter_subset (s : Set α) (t : ι → Set α) : (s * ⋂ i, t i) ⊆ ⋂ i, s * t i := image2_iInter_subset_right _ _ _ #align set.mul_Inter_subset Set.mul_iInter_subset #align set.add_Inter_subset Set.add_iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iInter₂_mul_subset (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) * t ⊆ ⋂ (i) (j), s i j * t := image2_iInter₂_subset_left _ _ _ #align set.Inter₂_mul_subset Set.iInter₂_mul_subset #align set.Inter₂_add_subset Set.iInter₂_add_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem mul_iInter₂_subset (s : Set α) (t : ∀ i, κ i → Set α) : (s * ⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), s * t i j := image2_iInter₂_subset_right _ _ _ #align set.mul_Inter₂_subset Set.mul_iInter₂_subset #align set.add_Inter₂_subset Set.add_iInter₂_subset /-- The singleton operation as a `MulHom`. -/ @[to_additive "The singleton operation as an `AddHom`."] noncomputable def singletonMulHom : α →ₙ* Set α where toFun := singleton map_mul' _ _ := singleton_mul_singleton.symm #align set.singleton_mul_hom Set.singletonMulHom #align set.singleton_add_hom Set.singletonAddHom @[to_additive (attr := simp)] theorem coe_singletonMulHom : (singletonMulHom : α → Set α) = singleton := rfl #align set.coe_singleton_mul_hom Set.coe_singletonMulHom #align set.coe_singleton_add_hom Set.coe_singletonAddHom @[to_additive (attr := simp)] theorem singletonMulHom_apply (a : α) : singletonMulHom a = {a} := rfl #align set.singleton_mul_hom_apply Set.singletonMulHom_apply #align set.singleton_add_hom_apply Set.singletonAddHom_apply open MulOpposite @[to_additive (attr := simp)] theorem image_op_mul : op '' (s * t) = op '' t * op '' s := image_image2_antidistrib op_mul #align set.image_op_mul Set.image_op_mul #align set.image_op_add Set.image_op_add end Mul /-! ### Set subtraction/division -/ section Div variable {ι : Sort*} {κ : ι → Sort*} [Div α] {s s₁ s₂ t t₁ t₂ u : Set α} {a b : α} /-- The pointwise division of sets `s / t` is defined as `{x / y | x ∈ s, y ∈ t}` in locale `Pointwise`. -/ @[to_additive "The pointwise subtraction of sets `s - t` is defined as `{x - y | x ∈ s, y ∈ t}` in locale `Pointwise`."] protected def div : Div (Set α) := ⟨image2 (· / ·)⟩ #align set.has_div Set.div #align set.has_sub Set.sub scoped[Pointwise] attribute [instance] Set.div Set.sub @[to_additive (attr := simp)] theorem image2_div : image2 Div.div s t = s / t := rfl #align set.image2_div Set.image2_div #align set.image2_sub Set.image2_sub @[to_additive] theorem mem_div : a ∈ s / t ↔ ∃ x ∈ s, ∃ y ∈ t, x / y = a := Iff.rfl #align set.mem_div Set.mem_div #align set.mem_sub Set.mem_sub @[to_additive] theorem div_mem_div : a ∈ s → b ∈ t → a / b ∈ s / t := mem_image2_of_mem #align set.div_mem_div Set.div_mem_div #align set.sub_mem_sub Set.sub_mem_sub @[to_additive sub_image_prod] theorem image_div_prod : (fun x : α × α => x.fst / x.snd) '' s ×ˢ t = s / t := image_prod _ #align set.image_div_prod Set.image_div_prod #align set.sub_image_prod Set.sub_image_prod @[to_additive (attr := simp)] theorem empty_div : ∅ / s = ∅ := image2_empty_left #align set.empty_div Set.empty_div #align set.empty_sub Set.empty_sub @[to_additive (attr := simp)] theorem div_empty : s / ∅ = ∅ := image2_empty_right #align set.div_empty Set.div_empty #align set.sub_empty Set.sub_empty @[to_additive (attr := simp)] theorem div_eq_empty : s / t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff #align set.div_eq_empty Set.div_eq_empty #align set.sub_eq_empty Set.sub_eq_empty @[to_additive (attr := simp)] theorem div_nonempty : (s / t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image2_nonempty_iff #align set.div_nonempty Set.div_nonempty #align set.sub_nonempty Set.sub_nonempty @[to_additive] theorem Nonempty.div : s.Nonempty → t.Nonempty → (s / t).Nonempty := Nonempty.image2 #align set.nonempty.div Set.Nonempty.div #align set.nonempty.sub Set.Nonempty.sub @[to_additive] theorem Nonempty.of_div_left : (s / t).Nonempty → s.Nonempty := Nonempty.of_image2_left #align set.nonempty.of_div_left Set.Nonempty.of_div_left #align set.nonempty.of_sub_left Set.Nonempty.of_sub_left @[to_additive] theorem Nonempty.of_div_right : (s / t).Nonempty → t.Nonempty := Nonempty.of_image2_right #align set.nonempty.of_div_right Set.Nonempty.of_div_right #align set.nonempty.of_sub_right Set.Nonempty.of_sub_right @[to_additive (attr := simp)] theorem div_singleton : s / {b} = (· / b) '' s := image2_singleton_right #align set.div_singleton Set.div_singleton #align set.sub_singleton Set.sub_singleton @[to_additive (attr := simp)] theorem singleton_div : {a} / t = (· / ·) a '' t := image2_singleton_left #align set.singleton_div Set.singleton_div #align set.singleton_sub Set.singleton_sub -- Porting note (#10618): simp can prove this @[to_additive] theorem singleton_div_singleton : ({a} : Set α) / {b} = {a / b} := image2_singleton #align set.singleton_div_singleton Set.singleton_div_singleton #align set.singleton_sub_singleton Set.singleton_sub_singleton @[to_additive (attr := mono)] theorem div_subset_div : s₁ ⊆ t₁ → s₂ ⊆ t₂ → s₁ / s₂ ⊆ t₁ / t₂ := image2_subset #align set.div_subset_div Set.div_subset_div #align set.sub_subset_sub Set.sub_subset_sub @[to_additive] theorem div_subset_div_left : t₁ ⊆ t₂ → s / t₁ ⊆ s / t₂ := image2_subset_left #align set.div_subset_div_left Set.div_subset_div_left #align set.sub_subset_sub_left Set.sub_subset_sub_left @[to_additive] theorem div_subset_div_right : s₁ ⊆ s₂ → s₁ / t ⊆ s₂ / t := image2_subset_right #align set.div_subset_div_right Set.div_subset_div_right #align set.sub_subset_sub_right Set.sub_subset_sub_right @[to_additive] theorem div_subset_iff : s / t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x / y ∈ u := image2_subset_iff #align set.div_subset_iff Set.div_subset_iff #align set.sub_subset_iff Set.sub_subset_iff @[to_additive] theorem union_div : (s₁ ∪ s₂) / t = s₁ / t ∪ s₂ / t := image2_union_left #align set.union_div Set.union_div #align set.union_sub Set.union_sub @[to_additive] theorem div_union : s / (t₁ ∪ t₂) = s / t₁ ∪ s / t₂ := image2_union_right #align set.div_union Set.div_union #align set.sub_union Set.sub_union @[to_additive] theorem inter_div_subset : s₁ ∩ s₂ / t ⊆ s₁ / t ∩ (s₂ / t) := image2_inter_subset_left #align set.inter_div_subset Set.inter_div_subset #align set.inter_sub_subset Set.inter_sub_subset @[to_additive] theorem div_inter_subset : s / (t₁ ∩ t₂) ⊆ s / t₁ ∩ (s / t₂) := image2_inter_subset_right #align set.div_inter_subset Set.div_inter_subset #align set.sub_inter_subset Set.sub_inter_subset @[to_additive] theorem inter_div_union_subset_union : s₁ ∩ s₂ / (t₁ ∪ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ := image2_inter_union_subset_union #align set.inter_div_union_subset_union Set.inter_div_union_subset_union #align set.inter_sub_union_subset_union Set.inter_sub_union_subset_union @[to_additive] theorem union_div_inter_subset_union : (s₁ ∪ s₂) / (t₁ ∩ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ := image2_union_inter_subset_union #align set.union_div_inter_subset_union Set.union_div_inter_subset_union #align set.union_sub_inter_subset_union Set.union_sub_inter_subset_union @[to_additive] theorem iUnion_div_left_image : ⋃ a ∈ s, (a / ·) '' t = s / t := iUnion_image_left _ #align set.Union_div_left_image Set.iUnion_div_left_image #align set.Union_sub_left_image Set.iUnion_sub_left_image @[to_additive] theorem iUnion_div_right_image : ⋃ a ∈ t, (· / a) '' s = s / t := iUnion_image_right _ #align set.Union_div_right_image Set.iUnion_div_right_image #align set.Union_sub_right_image Set.iUnion_sub_right_image @[to_additive] theorem iUnion_div (s : ι → Set α) (t : Set α) : (⋃ i, s i) / t = ⋃ i, s i / t := image2_iUnion_left _ _ _ #align set.Union_div Set.iUnion_div #align set.Union_sub Set.iUnion_sub @[to_additive] theorem div_iUnion (s : Set α) (t : ι → Set α) : (s / ⋃ i, t i) = ⋃ i, s / t i := image2_iUnion_right _ _ _ #align set.div_Union Set.div_iUnion #align set.sub_Union Set.sub_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iUnion₂_div (s : ∀ i, κ i → Set α) (t : Set α) : (⋃ (i) (j), s i j) / t = ⋃ (i) (j), s i j / t := image2_iUnion₂_left _ _ _ #align set.Union₂_div Set.iUnion₂_div #align set.Union₂_sub Set.iUnion₂_sub /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem div_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s / ⋃ (i) (j), t i j) = ⋃ (i) (j), s / t i j := image2_iUnion₂_right _ _ _ #align set.div_Union₂ Set.div_iUnion₂ #align set.sub_Union₂ Set.sub_iUnion₂ @[to_additive] theorem iInter_div_subset (s : ι → Set α) (t : Set α) : (⋂ i, s i) / t ⊆ ⋂ i, s i / t := image2_iInter_subset_left _ _ _ #align set.Inter_div_subset Set.iInter_div_subset #align set.Inter_sub_subset Set.iInter_sub_subset @[to_additive] theorem div_iInter_subset (s : Set α) (t : ι → Set α) : (s / ⋂ i, t i) ⊆ ⋂ i, s / t i := image2_iInter_subset_right _ _ _ #align set.div_Inter_subset Set.div_iInter_subset #align set.sub_Inter_subset Set.sub_iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iInter₂_div_subset (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) / t ⊆ ⋂ (i) (j), s i j / t := image2_iInter₂_subset_left _ _ _ #align set.Inter₂_div_subset Set.iInter₂_div_subset #align set.Inter₂_sub_subset Set.iInter₂_sub_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem div_iInter₂_subset (s : Set α) (t : ∀ i, κ i → Set α) : (s / ⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), s / t i j := image2_iInter₂_subset_right _ _ _ #align set.div_Inter₂_subset Set.div_iInter₂_subset #align set.sub_Inter₂_subset Set.sub_iInter₂_subset end Div open Pointwise /-- Repeated pointwise addition (not the same as pointwise repeated addition!) of a `Set`. See note [pointwise nat action]. -/ protected def NSMul [Zero α] [Add α] : SMul ℕ (Set α) := ⟨nsmulRec⟩ #align set.has_nsmul Set.NSMul /-- Repeated pointwise multiplication (not the same as pointwise repeated multiplication!) of a `Set`. See note [pointwise nat action]. -/ @[to_additive existing] protected def NPow [One α] [Mul α] : Pow (Set α) ℕ := ⟨fun s n => npowRec n s⟩ #align set.has_npow Set.NPow /-- Repeated pointwise addition/subtraction (not the same as pointwise repeated addition/subtraction!) of a `Set`. See note [pointwise nat action]. -/ protected def ZSMul [Zero α] [Add α] [Neg α] : SMul ℤ (Set α) := ⟨zsmulRec⟩ #align set.has_zsmul Set.ZSMul /-- Repeated pointwise multiplication/division (not the same as pointwise repeated multiplication/division!) of a `Set`. See note [pointwise nat action]. -/ @[to_additive existing] protected def ZPow [One α] [Mul α] [Inv α] : Pow (Set α) ℤ := ⟨fun s n => zpowRec npowRec n s⟩ #align set.has_zpow Set.ZPow scoped[Pointwise] attribute [instance] Set.NSMul Set.NPow Set.ZSMul Set.ZPow /-- `Set α` is a `Semigroup` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddSemigroup` under pointwise operations if `α` is."] protected noncomputable def semigroup [Semigroup α] : Semigroup (Set α) := { Set.mul with mul_assoc := fun _ _ _ => image2_assoc mul_assoc } #align set.semigroup Set.semigroup #align set.add_semigroup Set.addSemigroup section CommSemigroup variable [CommSemigroup α] {s t : Set α} /-- `Set α` is a `CommSemigroup` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddCommSemigroup` under pointwise operations if `α` is."] protected noncomputable def commSemigroup : CommSemigroup (Set α) := { Set.semigroup with mul_comm := fun _ _ => image2_comm mul_comm } #align set.comm_semigroup Set.commSemigroup #align set.add_comm_semigroup Set.addCommSemigroup @[to_additive] theorem inter_mul_union_subset : s ∩ t * (s ∪ t) ⊆ s * t := image2_inter_union_subset mul_comm #align set.inter_mul_union_subset Set.inter_mul_union_subset #align set.inter_add_union_subset Set.inter_add_union_subset @[to_additive] theorem union_mul_inter_subset : (s ∪ t) * (s ∩ t) ⊆ s * t := image2_union_inter_subset mul_comm #align set.union_mul_inter_subset Set.union_mul_inter_subset #align set.union_add_inter_subset Set.union_add_inter_subset end CommSemigroup section MulOneClass variable [MulOneClass α] /-- `Set α` is a `MulOneClass` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddZeroClass` under pointwise operations if `α` is."] protected noncomputable def mulOneClass : MulOneClass (Set α) := { Set.one, Set.mul with mul_one := image2_right_identity mul_one one_mul := image2_left_identity one_mul } #align set.mul_one_class Set.mulOneClass #align set.add_zero_class Set.addZeroClass scoped[Pointwise] attribute [instance] Set.mulOneClass Set.addZeroClass Set.semigroup Set.addSemigroup Set.commSemigroup Set.addCommSemigroup @[to_additive] theorem subset_mul_left (s : Set α) {t : Set α} (ht : (1 : α) ∈ t) : s ⊆ s * t := fun x hx => ⟨x, hx, 1, ht, mul_one _⟩ #align set.subset_mul_left Set.subset_mul_left #align set.subset_add_left Set.subset_add_left @[to_additive] theorem subset_mul_right {s : Set α} (t : Set α) (hs : (1 : α) ∈ s) : t ⊆ s * t := fun x hx => ⟨1, hs, x, hx, one_mul _⟩ #align set.subset_mul_right Set.subset_mul_right #align set.subset_add_right Set.subset_add_right /-- The singleton operation as a `MonoidHom`. -/ @[to_additive "The singleton operation as an `AddMonoidHom`."] noncomputable def singletonMonoidHom : α →* Set α := { singletonMulHom, singletonOneHom with } #align set.singleton_monoid_hom Set.singletonMonoidHom #align set.singleton_add_monoid_hom Set.singletonAddMonoidHom @[to_additive (attr := simp)] theorem coe_singletonMonoidHom : (singletonMonoidHom : α → Set α) = singleton := rfl #align set.coe_singleton_monoid_hom Set.coe_singletonMonoidHom #align set.coe_singleton_add_monoid_hom Set.coe_singletonAddMonoidHom @[to_additive (attr := simp)] theorem singletonMonoidHom_apply (a : α) : singletonMonoidHom a = {a} := rfl #align set.singleton_monoid_hom_apply Set.singletonMonoidHom_apply #align set.singleton_add_monoid_hom_apply Set.singletonAddMonoidHom_apply end MulOneClass section Monoid variable [Monoid α] {s t : Set α} {a : α} {m n : ℕ} /-- `Set α` is a `Monoid` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddMonoid` under pointwise operations if `α` is."] protected noncomputable def monoid : Monoid (Set α) := { Set.semigroup, Set.mulOneClass, @Set.NPow α _ _ with } #align set.monoid Set.monoid #align set.add_monoid Set.addMonoid scoped[Pointwise] attribute [instance] Set.monoid Set.addMonoid @[to_additive] theorem pow_mem_pow (ha : a ∈ s) : ∀ n : ℕ, a ^ n ∈ s ^ n | 0 => by rw [pow_zero] exact one_mem_one | n + 1 => by rw [pow_succ] exact mul_mem_mul (pow_mem_pow ha _) ha #align set.pow_mem_pow Set.pow_mem_pow #align set.nsmul_mem_nsmul Set.nsmul_mem_nsmul @[to_additive] theorem pow_subset_pow (hst : s ⊆ t) : ∀ n : ℕ, s ^ n ⊆ t ^ n | 0 => by rw [pow_zero] exact Subset.rfl | n + 1 => by rw [pow_succ] exact mul_subset_mul (pow_subset_pow hst _) hst #align set.pow_subset_pow Set.pow_subset_pow #align set.nsmul_subset_nsmul Set.nsmul_subset_nsmul @[to_additive] theorem pow_subset_pow_of_one_mem (hs : (1 : α) ∈ s) (hn : m ≤ n) : s ^ m ⊆ s ^ n := by -- Porting note: `Nat.le_induction` didn't work as an induction principle in mathlib3, this was -- `refine Nat.le_induction ...` induction' n, hn using Nat.le_induction with _ _ ih · exact Subset.rfl · dsimp only rw [pow_succ'] exact ih.trans (subset_mul_right _ hs) #align set.pow_subset_pow_of_one_mem Set.pow_subset_pow_of_one_mem #align set.nsmul_subset_nsmul_of_zero_mem Set.nsmul_subset_nsmul_of_zero_mem @[to_additive (attr := simp)] theorem empty_pow {n : ℕ} (hn : n ≠ 0) : (∅ : Set α) ^ n = ∅ := by rw [← tsub_add_cancel_of_le (Nat.succ_le_of_lt <| Nat.pos_of_ne_zero hn), pow_succ', empty_mul] #align set.empty_pow Set.empty_pow #align set.empty_nsmul Set.empty_nsmul @[to_additive] theorem mul_univ_of_one_mem (hs : (1 : α) ∈ s) : s * univ = univ := eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, hs, _, mem_univ _, one_mul _⟩ #align set.mul_univ_of_one_mem Set.mul_univ_of_one_mem #align set.add_univ_of_zero_mem Set.add_univ_of_zero_mem @[to_additive] theorem univ_mul_of_one_mem (ht : (1 : α) ∈ t) : univ * t = univ := eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, mem_univ _, _, ht, mul_one _⟩ #align set.univ_mul_of_one_mem Set.univ_mul_of_one_mem #align set.univ_add_of_zero_mem Set.univ_add_of_zero_mem @[to_additive (attr := simp)] theorem univ_mul_univ : (univ : Set α) * univ = univ := mul_univ_of_one_mem <| mem_univ _ #align set.univ_mul_univ Set.univ_mul_univ #align set.univ_add_univ Set.univ_add_univ --TODO: `to_additive` trips up on the `1 : ℕ` used in the pattern-matching. @[simp] theorem nsmul_univ {α : Type*} [AddMonoid α] : ∀ {n : ℕ}, n ≠ 0 → n • (univ : Set α) = univ | 0 => fun h => (h rfl).elim | 1 => fun _ => one_nsmul _ | n + 2 => fun _ => by rw [succ_nsmul, nsmul_univ n.succ_ne_zero, univ_add_univ] #align set.nsmul_univ Set.nsmul_univ @[to_additive existing (attr := simp) nsmul_univ] theorem univ_pow : ∀ {n : ℕ}, n ≠ 0 → (univ : Set α) ^ n = univ | 0 => fun h => (h rfl).elim | 1 => fun _ => pow_one _ | n + 2 => fun _ => by rw [pow_succ, univ_pow n.succ_ne_zero, univ_mul_univ] #align set.univ_pow Set.univ_pow @[to_additive] protected theorem _root_.IsUnit.set : IsUnit a → IsUnit ({a} : Set α) := IsUnit.map (singletonMonoidHom : α →* Set α) #align is_unit.set IsUnit.set #align is_add_unit.set IsAddUnit.set end Monoid /-- `Set α` is a `CommMonoid` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddCommMonoid` under pointwise operations if `α` is."] protected noncomputable def commMonoid [CommMonoid α] : CommMonoid (Set α) := { Set.monoid, Set.commSemigroup with } #align set.comm_monoid Set.commMonoid #align set.add_comm_monoid Set.addCommMonoid scoped[Pointwise] attribute [instance] Set.commMonoid Set.addCommMonoid open Pointwise section DivisionMonoid variable [DivisionMonoid α] {s t : Set α} @[to_additive] protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = {a} ∧ t = {b} ∧ a * b = 1 := by refine ⟨fun h => ?_, ?_⟩ · have hst : (s * t).Nonempty := h.symm.subst one_nonempty obtain ⟨a, ha⟩ := hst.of_image2_left obtain ⟨b, hb⟩ := hst.of_image2_right have H : ∀ {a b}, a ∈ s → b ∈ t → a * b = (1 : α) := fun {a b} ha hb => h.subset <| mem_image2_of_mem ha hb refine ⟨a, b, ?_, ?_, H ha hb⟩ <;> refine eq_singleton_iff_unique_mem.2 ⟨‹_›, fun x hx => ?_⟩ · exact (eq_inv_of_mul_eq_one_left <| H hx hb).trans (inv_eq_of_mul_eq_one_left <| H ha hb) · exact (eq_inv_of_mul_eq_one_right <| H ha hx).trans (inv_eq_of_mul_eq_one_right <| H ha hb) · rintro ⟨b, c, rfl, rfl, h⟩ rw [singleton_mul_singleton, h, singleton_one] #align set.mul_eq_one_iff Set.mul_eq_one_iff #align set.add_eq_zero_iff Set.add_eq_zero_iff /-- `Set α` is a division monoid under pointwise operations if `α` is. -/ @[to_additive subtractionMonoid "`Set α` is a subtraction monoid under pointwise operations if `α` is."] protected noncomputable def divisionMonoid : DivisionMonoid (Set α) := { Set.monoid, Set.involutiveInv, Set.div, @Set.ZPow α _ _ _ with mul_inv_rev := fun s t => by simp_rw [← image_inv] exact image_image2_antidistrib mul_inv_rev inv_eq_of_mul := fun s t h => by obtain ⟨a, b, rfl, rfl, hab⟩ := Set.mul_eq_one_iff.1 h rw [inv_singleton, inv_eq_of_mul_eq_one_right hab] div_eq_mul_inv := fun s t => by rw [← image_id (s / t), ← image_inv] exact image_image2_distrib_right div_eq_mul_inv } #align set.division_monoid Set.divisionMonoid #align set.subtraction_monoid Set.subtractionMonoid scoped[Pointwise] attribute [instance] Set.divisionMonoid Set.subtractionMonoid @[to_additive (attr := simp 500)] theorem isUnit_iff : IsUnit s ↔ ∃ a, s = {a} ∧ IsUnit a := by constructor · rintro ⟨u, rfl⟩ obtain ⟨a, b, ha, hb, h⟩ := Set.mul_eq_one_iff.1 u.mul_inv refine ⟨a, ha, ⟨a, b, h, singleton_injective ?_⟩, rfl⟩ rw [← singleton_mul_singleton, ← ha, ← hb] exact u.inv_mul · rintro ⟨a, rfl, ha⟩ exact ha.set #align set.is_unit_iff Set.isUnit_iff #align set.is_add_unit_iff Set.isAddUnit_iff @[to_additive (attr := simp)] lemma univ_div_univ : (univ / univ : Set α) = univ := by simp [div_eq_mul_inv] end DivisionMonoid /-- `Set α` is a commutative division monoid under pointwise operations if `α` is. -/ @[to_additive subtractionCommMonoid "`Set α` is a commutative subtraction monoid under pointwise operations if `α` is."] protected noncomputable def divisionCommMonoid [DivisionCommMonoid α] : DivisionCommMonoid (Set α) := { Set.divisionMonoid, Set.commSemigroup with } #align set.division_comm_monoid Set.divisionCommMonoid #align set.subtraction_comm_monoid Set.subtractionCommMonoid /-- `Set α` has distributive negation if `α` has. -/ protected noncomputable def hasDistribNeg [Mul α] [HasDistribNeg α] : HasDistribNeg (Set α) := { Set.involutiveNeg with neg_mul := fun _ _ => by simp_rw [← image_neg] exact image2_image_left_comm neg_mul mul_neg := fun _ _ => by simp_rw [← image_neg] exact image_image2_right_comm mul_neg } #align set.has_distrib_neg Set.hasDistribNeg scoped[Pointwise] attribute [instance] Set.divisionCommMonoid Set.subtractionCommMonoid Set.hasDistribNeg section Distrib variable [Distrib α] (s t u : Set α) /-! Note that `Set α` is not a `Distrib` because `s * t + s * u` has cross terms that `s * (t + u)` lacks. -/ theorem mul_add_subset : s * (t + u) ⊆ s * t + s * u := image2_distrib_subset_left mul_add #align set.mul_add_subset Set.mul_add_subset theorem add_mul_subset : (s + t) * u ⊆ s * u + t * u := image2_distrib_subset_right add_mul #align set.add_mul_subset Set.add_mul_subset end Distrib section MulZeroClass variable [MulZeroClass α] {s t : Set α} /-! Note that `Set` is not a `MulZeroClass` because `0 * ∅ ≠ 0`. -/ theorem mul_zero_subset (s : Set α) : s * 0 ⊆ 0 := by simp [subset_def, mem_mul] #align set.mul_zero_subset Set.mul_zero_subset
Mathlib/Data/Set/Pointwise/Basic.lean
1,146
1,146
theorem zero_mul_subset (s : Set α) : 0 * s ⊆ 0 := by
simp [subset_def, mem_mul]
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Data.ENat.Lattice import Mathlib.Order.OrderIsoNat import Mathlib.Tactic.TFAE #align_import order.height from "leanprover-community/mathlib"@"bf27744463e9620ca4e4ebe951fe83530ae6949b" /-! # Maximal length of chains This file contains lemmas to work with the maximal length of strictly descending finite sequences (chains) in a partial order. ## Main definition - `Set.subchain`: The set of strictly ascending lists of `α` contained in a `Set α`. - `Set.chainHeight`: The maximal length of a strictly ascending sequence in a partial order. This is defined as the maximum of the lengths of `Set.subchain`s, valued in `ℕ∞`. ## Main results - `Set.exists_chain_of_le_chainHeight`: For each `n : ℕ` such that `n ≤ s.chainHeight`, there exists `s.subchain` of length `n`. - `Set.chainHeight_mono`: If `s ⊆ t` then `s.chainHeight ≤ t.chainHeight`. - `Set.chainHeight_image`: If `f` is an order embedding, then `(f '' s).chainHeight = s.chainHeight`. - `Set.chainHeight_insert_of_forall_lt`: If `∀ y ∈ s, y < x`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_insert_of_forall_gt`: If `∀ y ∈ s, x < y`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_union_eq`: If `∀ x ∈ s, ∀ y ∈ t, s ≤ t`, then `(s ∪ t).chainHeight = s.chainHeight + t.chainHeight`. - `Set.wellFoundedGT_of_chainHeight_ne_top`: If `s` has finite height, then `>` is well-founded on `s`. - `Set.wellFoundedLT_of_chainHeight_ne_top`: If `s` has finite height, then `<` is well-founded on `s`. -/ open List hiding le_antisymm open OrderDual universe u v variable {α β : Type*} namespace Set section LT variable [LT α] [LT β] (s t : Set α) /-- The set of strictly ascending lists of `α` contained in a `Set α`. -/ def subchain : Set (List α) := { l | l.Chain' (· < ·) ∧ ∀ i ∈ l, i ∈ s } #align set.subchain Set.subchain @[simp] -- porting note: new `simp` theorem nil_mem_subchain : [] ∈ s.subchain := ⟨trivial, fun _ ↦ nofun⟩ #align set.nil_mem_subchain Set.nil_mem_subchain variable {s} {l : List α} {a : α} theorem cons_mem_subchain_iff : (a::l) ∈ s.subchain ↔ a ∈ s ∧ l ∈ s.subchain ∧ ∀ b ∈ l.head?, a < b := by simp only [subchain, mem_setOf_eq, forall_mem_cons, chain'_cons', and_left_comm, and_comm, and_assoc] #align set.cons_mem_subchain_iff Set.cons_mem_subchain_iff @[simp] -- Porting note (#10756): new lemma + `simp` theorem singleton_mem_subchain_iff : [a] ∈ s.subchain ↔ a ∈ s := by simp [cons_mem_subchain_iff] instance : Nonempty s.subchain := ⟨⟨[], s.nil_mem_subchain⟩⟩ variable (s) /-- The maximal length of a strictly ascending sequence in a partial order. -/ noncomputable def chainHeight : ℕ∞ := ⨆ l ∈ s.subchain, length l #align set.chain_height Set.chainHeight theorem chainHeight_eq_iSup_subtype : s.chainHeight = ⨆ l : s.subchain, ↑l.1.length := iSup_subtype' #align set.chain_height_eq_supr_subtype Set.chainHeight_eq_iSup_subtype theorem exists_chain_of_le_chainHeight {n : ℕ} (hn : ↑n ≤ s.chainHeight) : ∃ l ∈ s.subchain, length l = n := by rcases (le_top : s.chainHeight ≤ ⊤).eq_or_lt with ha | ha <;> rw [chainHeight_eq_iSup_subtype] at ha · obtain ⟨_, ⟨⟨l, h₁, h₂⟩, rfl⟩, h₃⟩ := not_bddAbove_iff'.mp (WithTop.iSup_coe_eq_top.1 ha) n exact ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take n).trans <| min_eq_left <| le_of_not_ge h₃⟩ · rw [ENat.iSup_coe_lt_top] at ha obtain ⟨⟨l, h₁, h₂⟩, e : l.length = _⟩ := Nat.sSup_mem (Set.range_nonempty _) ha refine ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take n).trans <| min_eq_left <| ?_⟩ rwa [e, ← Nat.cast_le (α := ℕ∞), sSup_range, ENat.coe_iSup ha, ← chainHeight_eq_iSup_subtype] #align set.exists_chain_of_le_chain_height Set.exists_chain_of_le_chainHeight theorem le_chainHeight_TFAE (n : ℕ) : TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by tfae_have 1 → 2; · exact s.exists_chain_of_le_chainHeight tfae_have 2 → 3; · rintro ⟨l, hls, he⟩; exact ⟨l, hls, he.ge⟩ tfae_have 3 → 1; · rintro ⟨l, hs, hn⟩; exact le_iSup₂_of_le l hs (WithTop.coe_le_coe.2 hn) tfae_finish #align set.le_chain_height_tfae Set.le_chainHeight_TFAE variable {s t} theorem le_chainHeight_iff {n : ℕ} : ↑n ≤ s.chainHeight ↔ ∃ l ∈ s.subchain, length l = n := (le_chainHeight_TFAE s n).out 0 1 #align set.le_chain_height_iff Set.le_chainHeight_iff theorem length_le_chainHeight_of_mem_subchain (hl : l ∈ s.subchain) : ↑l.length ≤ s.chainHeight := le_chainHeight_iff.mpr ⟨l, hl, rfl⟩ #align set.length_le_chain_height_of_mem_subchain Set.length_le_chainHeight_of_mem_subchain
Mathlib/Order/Height.lean
127
131
theorem chainHeight_eq_top_iff : s.chainHeight = ⊤ ↔ ∀ n, ∃ l ∈ s.subchain, length l = n := by
refine ⟨fun h n ↦ le_chainHeight_iff.1 (le_top.trans_eq h.symm), fun h ↦ ?_⟩ contrapose! h; obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 h exact ⟨n + 1, fun l hs ↦ (Nat.lt_succ_iff.2 <| Nat.cast_le.1 <| (length_le_chainHeight_of_mem_subchain hs).trans_eq hn.symm).ne⟩
/- Copyright (c) 2020 Jannis Limperg. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jannis Limperg -/ import Mathlib.Data.List.OfFn import Mathlib.Data.List.Range #align_import data.list.indexes from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1" /-! # Lemmas about List.*Idx functions. Some specification lemmas for `List.mapIdx`, `List.mapIdxM`, `List.foldlIdx` and `List.foldrIdx`. -/ assert_not_exists MonoidWithZero universe u v open Function namespace List variable {α : Type u} {β : Type v} section MapIdx -- Porting note: Add back old definition because it's easier for writing proofs. /-- Lean3 `map_with_index` helper function -/ protected def oldMapIdxCore (f : ℕ → α → β) : ℕ → List α → List β | _, [] => [] | k, a :: as => f k a :: List.oldMapIdxCore f (k + 1) as /-- Given a function `f : ℕ → α → β` and `as : List α`, `as = [a₀, a₁, ...]`, returns the list `[f 0 a₀, f 1 a₁, ...]`. -/ protected def oldMapIdx (f : ℕ → α → β) (as : List α) : List β := List.oldMapIdxCore f 0 as @[simp] theorem mapIdx_nil {α β} (f : ℕ → α → β) : mapIdx f [] = [] := rfl #align list.map_with_index_nil List.mapIdx_nil -- Porting note (#10756): new theorem. protected theorem oldMapIdxCore_eq (l : List α) (f : ℕ → α → β) (n : ℕ) : l.oldMapIdxCore f n = l.oldMapIdx fun i a ↦ f (i + n) a := by induction' l with hd tl hl generalizing f n · rfl · rw [List.oldMapIdx] simp only [List.oldMapIdxCore, hl, Nat.add_left_comm, Nat.add_comm, Nat.add_zero] #noalign list.map_with_index_core_eq -- Porting note: convert new definition to old definition. -- A few new theorems are added to achieve this -- 1. Prove that `oldMapIdxCore f (l ++ [e]) = oldMapIdxCore f l ++ [f l.length e]` -- 2. Prove that `oldMapIdx f (l ++ [e]) = oldMapIdx f l ++ [f l.length e]` -- 3. Prove list induction using `∀ l e, p [] → (p l → p (l ++ [e])) → p l` -- Porting note (#10756): new theorem. theorem list_reverse_induction (p : List α → Prop) (base : p []) (ind : ∀ (l : List α) (e : α), p l → p (l ++ [e])) : (∀ (l : List α), p l) := by let q := fun l ↦ p (reverse l) have pq : ∀ l, p (reverse l) → q l := by simp only [q, reverse_reverse]; intro; exact id have qp : ∀ l, q (reverse l) → p l := by simp only [q, reverse_reverse]; intro; exact id intro l apply qp generalize (reverse l) = l induction' l with head tail ih · apply pq; simp only [reverse_nil, base] · apply pq; simp only [reverse_cons]; apply ind; apply qp; rw [reverse_reverse]; exact ih -- Porting note (#10756): new theorem. protected theorem oldMapIdxCore_append : ∀ (f : ℕ → α → β) (n : ℕ) (l₁ l₂ : List α), List.oldMapIdxCore f n (l₁ ++ l₂) = List.oldMapIdxCore f n l₁ ++ List.oldMapIdxCore f (n + l₁.length) l₂ := by intros f n l₁ l₂ generalize e : (l₁ ++ l₂).length = len revert n l₁ l₂ induction' len with len ih <;> intros n l₁ l₂ h · have l₁_nil : l₁ = [] := by cases l₁ · rfl · contradiction have l₂_nil : l₂ = [] := by cases l₂ · rfl · rw [List.length_append] at h; contradiction simp only [l₁_nil, l₂_nil]; rfl · cases' l₁ with head tail · rfl · simp only [List.oldMapIdxCore, List.append_eq, length_cons, cons_append,cons.injEq, true_and] suffices n + Nat.succ (length tail) = n + 1 + tail.length by rw [this] apply ih (n + 1) _ _ _ simp only [cons_append, length_cons, length_append, Nat.succ.injEq] at h simp only [length_append, h] rw [Nat.add_assoc]; simp only [Nat.add_comm] -- Porting note (#10756): new theorem. protected theorem oldMapIdx_append : ∀ (f : ℕ → α → β) (l : List α) (e : α), List.oldMapIdx f (l ++ [e]) = List.oldMapIdx f l ++ [f l.length e] := by intros f l e unfold List.oldMapIdx rw [List.oldMapIdxCore_append f 0 l [e]] simp only [Nat.zero_add]; rfl -- Porting note (#10756): new theorem. theorem mapIdxGo_append : ∀ (f : ℕ → α → β) (l₁ l₂ : List α) (arr : Array β), mapIdx.go f (l₁ ++ l₂) arr = mapIdx.go f l₂ (List.toArray (mapIdx.go f l₁ arr)) := by intros f l₁ l₂ arr generalize e : (l₁ ++ l₂).length = len revert l₁ l₂ arr induction' len with len ih <;> intros l₁ l₂ arr h · have l₁_nil : l₁ = [] := by cases l₁ · rfl · contradiction have l₂_nil : l₂ = [] := by cases l₂ · rfl · rw [List.length_append] at h; contradiction rw [l₁_nil, l₂_nil]; simp only [mapIdx.go, Array.toList_eq, Array.toArray_data] · cases' l₁ with head tail <;> simp only [mapIdx.go] · simp only [nil_append, Array.toList_eq, Array.toArray_data] · simp only [List.append_eq] rw [ih] · simp only [cons_append, length_cons, length_append, Nat.succ.injEq] at h simp only [length_append, h] -- Porting note (#10756): new theorem. theorem mapIdxGo_length : ∀ (f : ℕ → α → β) (l : List α) (arr : Array β), length (mapIdx.go f l arr) = length l + arr.size := by intro f l induction' l with head tail ih · intro; simp only [mapIdx.go, Array.toList_eq, length_nil, Nat.zero_add] · intro; simp only [mapIdx.go]; rw [ih]; simp only [Array.size_push, length_cons]; simp only [Nat.add_succ, add_zero, Nat.add_comm] -- Porting note (#10756): new theorem. theorem mapIdx_append_one : ∀ (f : ℕ → α → β) (l : List α) (e : α), mapIdx f (l ++ [e]) = mapIdx f l ++ [f l.length e] := by intros f l e unfold mapIdx rw [mapIdxGo_append f l [e]] simp only [mapIdx.go, Array.size_toArray, mapIdxGo_length, length_nil, Nat.add_zero, Array.toList_eq, Array.push_data, Array.data_toArray] -- Porting note (#10756): new theorem. protected theorem new_def_eq_old_def : ∀ (f : ℕ → α → β) (l : List α), l.mapIdx f = List.oldMapIdx f l := by intro f apply list_reverse_induction · rfl · intro l e h rw [List.oldMapIdx_append, mapIdx_append_one, h] @[local simp] theorem map_enumFrom_eq_zipWith : ∀ (l : List α) (n : ℕ) (f : ℕ → α → β), map (uncurry f) (enumFrom n l) = zipWith (fun i ↦ f (i + n)) (range (length l)) l := by intro l generalize e : l.length = len revert l induction' len with len ih <;> intros l e n f · have : l = [] := by cases l · rfl · contradiction rw [this]; rfl · cases' l with head tail · contradiction · simp only [map, uncurry_apply_pair, range_succ_eq_map, zipWith, Nat.zero_add, zipWith_map_left] rw [ih] · suffices (fun i ↦ f (i + (n + 1))) = ((fun i ↦ f (i + n)) ∘ Nat.succ) by rw [this] rfl funext n' a simp only [comp, Nat.add_assoc, Nat.add_comm, Nat.add_succ] simp only [length_cons, Nat.succ.injEq] at e; exact e theorem mapIdx_eq_enum_map (l : List α) (f : ℕ → α → β) : l.mapIdx f = l.enum.map (Function.uncurry f) := by rw [List.new_def_eq_old_def] induction' l with hd tl hl generalizing f · rfl · rw [List.oldMapIdx, List.oldMapIdxCore, List.oldMapIdxCore_eq, hl] simp [map, enum_eq_zip_range, map_uncurry_zip_eq_zipWith] #align list.map_with_index_eq_enum_map List.mapIdx_eq_enum_map @[simp] theorem mapIdx_cons (l : List α) (f : ℕ → α → β) (a : α) : mapIdx f (a :: l) = f 0 a :: mapIdx (fun i ↦ f (i + 1)) l := by simp [mapIdx_eq_enum_map, enum_eq_zip_range, map_uncurry_zip_eq_zipWith, range_succ_eq_map, zipWith_map_left] #align list.map_with_index_cons List.mapIdx_cons theorem mapIdx_append (K L : List α) (f : ℕ → α → β) : (K ++ L).mapIdx f = K.mapIdx f ++ L.mapIdx fun i a ↦ f (i + K.length) a := by induction' K with a J IH generalizing f · rfl · simp [IH fun i ↦ f (i + 1), Nat.add_assoc, Nat.succ_eq_add_one] #align list.map_with_index_append List.mapIdx_append @[simp] theorem length_mapIdx (l : List α) (f : ℕ → α → β) : (l.mapIdx f).length = l.length := by induction' l with hd tl IH generalizing f · rfl · simp [IH] #align list.length_map_with_index List.length_mapIdx @[simp] theorem mapIdx_eq_nil {f : ℕ → α → β} {l : List α} : List.mapIdx f l = [] ↔ l = [] := by rw [List.mapIdx_eq_enum_map, List.map_eq_nil, List.enum_eq_nil] set_option linter.deprecated false in @[simp, deprecated (since := "2023-02-11")] theorem nthLe_mapIdx (l : List α) (f : ℕ → α → β) (i : ℕ) (h : i < l.length) (h' : i < (l.mapIdx f).length := h.trans_le (l.length_mapIdx f).ge) : (l.mapIdx f).nthLe i h' = f i (l.nthLe i h) := by simp [mapIdx_eq_enum_map, enum_eq_zip_range] #align list.nth_le_map_with_index List.nthLe_mapIdx theorem mapIdx_eq_ofFn (l : List α) (f : ℕ → α → β) : l.mapIdx f = ofFn fun i : Fin l.length ↦ f (i : ℕ) (l.get i) := by induction l generalizing f with | nil => simp | cons _ _ IH => simp [IH] #align list.map_with_index_eq_of_fn List.mapIdx_eq_ofFn end MapIdx section FoldrIdx -- Porting note: Changed argument order of `foldrIdxSpec` to align better with `foldrIdx`. /-- Specification of `foldrIdx`. -/ def foldrIdxSpec (f : ℕ → α → β → β) (b : β) (as : List α) (start : ℕ) : β := foldr (uncurry f) b <| enumFrom start as #align list.foldr_with_index_aux_spec List.foldrIdxSpecₓ theorem foldrIdxSpec_cons (f : ℕ → α → β → β) (b a as start) : foldrIdxSpec f b (a :: as) start = f start a (foldrIdxSpec f b as (start + 1)) := rfl #align list.foldr_with_index_aux_spec_cons List.foldrIdxSpec_consₓ theorem foldrIdx_eq_foldrIdxSpec (f : ℕ → α → β → β) (b as start) : foldrIdx f b as start = foldrIdxSpec f b as start := by induction as generalizing start · rfl · simp only [foldrIdx, foldrIdxSpec_cons, *] #align list.foldr_with_index_aux_eq_foldr_with_index_aux_spec List.foldrIdx_eq_foldrIdxSpecₓ theorem foldrIdx_eq_foldr_enum (f : ℕ → α → β → β) (b : β) (as : List α) : foldrIdx f b as = foldr (uncurry f) b (enum as) := by simp only [foldrIdx, foldrIdxSpec, foldrIdx_eq_foldrIdxSpec, enum] #align list.foldr_with_index_eq_foldr_enum List.foldrIdx_eq_foldr_enum end FoldrIdx theorem indexesValues_eq_filter_enum (p : α → Prop) [DecidablePred p] (as : List α) : indexesValues p as = filter (p ∘ Prod.snd) (enum as) := by simp (config := { unfoldPartialApp := true }) [indexesValues, foldrIdx_eq_foldr_enum, uncurry, filter_eq_foldr, cond_eq_if] #align list.indexes_values_eq_filter_enum List.indexesValues_eq_filter_enum theorem findIdxs_eq_map_indexesValues (p : α → Prop) [DecidablePred p] (as : List α) : findIdxs p as = map Prod.fst (indexesValues p as) := by simp (config := { unfoldPartialApp := true }) only [indexesValues_eq_filter_enum, map_filter_eq_foldr, findIdxs, uncurry, foldrIdx_eq_foldr_enum, decide_eq_true_eq, comp_apply, Bool.cond_decide] #align list.find_indexes_eq_map_indexes_values List.findIdxs_eq_map_indexesValues section FindIdx -- TODO: upstream to Batteries theorem findIdx_eq_length {p : α → Bool} {xs : List α} : xs.findIdx p = xs.length ↔ ∀ x ∈ xs, ¬p x := by induction xs with | nil => simp_all | cons x xs ih => rw [findIdx_cons, length_cons] constructor <;> intro h · have : ¬p x := by contrapose h; simp_all simp_all · simp_rw [h x (mem_cons_self x xs), cond_false, Nat.succ.injEq, ih] exact fun y hy ↦ h y <| mem_cons.mpr (Or.inr hy) theorem findIdx_le_length (p : α → Bool) {xs : List α} : xs.findIdx p ≤ xs.length := by by_cases e : ∃ x ∈ xs, p x · exact (findIdx_lt_length_of_exists e).le · push_neg at e; exact (findIdx_eq_length.mpr e).le theorem findIdx_lt_length {p : α → Bool} {xs : List α} : xs.findIdx p < xs.length ↔ ∃ x ∈ xs, p x := by rw [← not_iff_not, not_lt] have := @le_antisymm_iff _ _ (xs.findIdx p) xs.length simp only [findIdx_le_length, true_and] at this rw [← this, findIdx_eq_length, not_exists] simp only [Bool.not_eq_true, not_and] /-- `p` does not hold for elements with indices less than `xs.findIdx p`. -/ theorem not_of_lt_findIdx {p : α → Bool} {xs : List α} {i : ℕ} (h : i < xs.findIdx p) : ¬p (xs.get ⟨i, h.trans_le (findIdx_le_length p)⟩) := by revert i induction xs with | nil => intro i h; rw [findIdx_nil] at h; omega | cons x xs ih => intro i h have ho := h rw [findIdx_cons] at h have npx : ¬p x := by by_contra y; rw [y, cond_true] at h; omega simp_rw [npx, cond_false] at h cases' i.eq_zero_or_pos with e e · simpa only [e, Fin.zero_eta, get_cons_zero] · have ipm := Nat.succ_pred_eq_of_pos e have ilt := ho.trans_le (findIdx_le_length p) rw [(Fin.mk_eq_mk (h' := ipm ▸ ilt)).mpr ipm.symm, get_cons_succ] rw [← ipm, Nat.succ_lt_succ_iff] at h exact ih h theorem le_findIdx_of_not {p : α → Bool} {xs : List α} {i : ℕ} (h : i < xs.length) (h2 : ∀ j (hji : j < i), ¬p (xs.get ⟨j, hji.trans h⟩)) : i ≤ xs.findIdx p := by by_contra! f exact absurd (@findIdx_get _ p xs (f.trans h)) (h2 (xs.findIdx p) f) theorem lt_findIdx_of_not {p : α → Bool} {xs : List α} {i : ℕ} (h : i < xs.length) (h2 : ∀ j (hji : j ≤ i), ¬p (xs.get ⟨j, hji.trans_lt h⟩)) : i < xs.findIdx p := by by_contra! f exact absurd (@findIdx_get _ p xs (f.trans_lt h)) (h2 (xs.findIdx p) f) theorem findIdx_eq {p : α → Bool} {xs : List α} {i : ℕ} (h : i < xs.length) : xs.findIdx p = i ↔ p (xs.get ⟨i, h⟩) ∧ ∀ j (hji : j < i), ¬p (xs.get ⟨j, hji.trans h⟩) := by refine ⟨fun f ↦ ⟨f ▸ (@findIdx_get _ p xs (f ▸ h)), fun _ hji ↦ not_of_lt_findIdx (f ▸ hji)⟩, fun ⟨h1, h2⟩ ↦ ?_⟩ apply Nat.le_antisymm _ (le_findIdx_of_not h h2) contrapose! h1 exact not_of_lt_findIdx h1 end FindIdx section FoldlIdx -- Porting note: Changed argument order of `foldlIdxSpec` to align better with `foldlIdx`. /-- Specification of `foldlIdx`. -/ def foldlIdxSpec (f : ℕ → α → β → α) (a : α) (bs : List β) (start : ℕ) : α := foldl (fun a p ↦ f p.fst a p.snd) a <| enumFrom start bs #align list.foldl_with_index_aux_spec List.foldlIdxSpecₓ theorem foldlIdxSpec_cons (f : ℕ → α → β → α) (a b bs start) : foldlIdxSpec f a (b :: bs) start = foldlIdxSpec f (f start a b) bs (start + 1) := rfl #align list.foldl_with_index_aux_spec_cons List.foldlIdxSpec_consₓ theorem foldlIdx_eq_foldlIdxSpec (f : ℕ → α → β → α) (a bs start) : foldlIdx f a bs start = foldlIdxSpec f a bs start := by induction bs generalizing start a · rfl · simp [foldlIdxSpec, *] #align list.foldl_with_index_aux_eq_foldl_with_index_aux_spec List.foldlIdx_eq_foldlIdxSpecₓ theorem foldlIdx_eq_foldl_enum (f : ℕ → α → β → α) (a : α) (bs : List β) : foldlIdx f a bs = foldl (fun a p ↦ f p.fst a p.snd) a (enum bs) := by simp only [foldlIdx, foldlIdxSpec, foldlIdx_eq_foldlIdxSpec, enum] #align list.foldl_with_index_eq_foldl_enum List.foldlIdx_eq_foldl_enum end FoldlIdx section FoldIdxM -- Porting note: `foldrM_eq_foldr` now depends on `[LawfulMonad m]` variable {m : Type u → Type v} [Monad m] theorem foldrIdxM_eq_foldrM_enum {β} (f : ℕ → α → β → m β) (b : β) (as : List α) [LawfulMonad m] : foldrIdxM f b as = foldrM (uncurry f) b (enum as) := by simp (config := { unfoldPartialApp := true }) only [foldrIdxM, foldrM_eq_foldr, foldrIdx_eq_foldr_enum, uncurry] #align list.mfoldr_with_index_eq_mfoldr_enum List.foldrIdxM_eq_foldrM_enum
Mathlib/Data/List/Indexes.lean
378
380
theorem foldlIdxM_eq_foldlM_enum [LawfulMonad m] {β} (f : ℕ → β → α → m β) (b : β) (as : List α) : foldlIdxM f b as = List.foldlM (fun b p ↦ f p.fst b p.snd) b (enum as) := by
rw [foldlIdxM, foldlM_eq_foldl, foldlIdx_eq_foldl_enum]
/- 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 Mathlib.CategoryTheory.LiftingProperties.Basic import Mathlib.CategoryTheory.Adjunction.Basic #align_import category_theory.lifting_properties.adjunction from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514" /-! # Lifting properties and adjunction In this file, we obtain `Adjunction.HasLiftingProperty_iff`, which states that when we have an adjunction `adj : G ⊣ F` between two functors `G : C ⥤ D` and `F : D ⥤ C`, then a morphism of the form `G.map i` has the left lifting property in `D` with respect to a morphism `p` if and only the morphism `i` has the left lifting property in `C` with respect to `F.map p`. -/ namespace CategoryTheory open Category variable {C D : Type*} [Category C] [Category D] {G : C ⥤ D} {F : D ⥤ C} namespace CommSq section variable {A B : C} {X Y : D} {i : A ⟶ B} {p : X ⟶ Y} {u : G.obj A ⟶ X} {v : G.obj B ⟶ Y} (sq : CommSq u (G.map i) p v) (adj : G ⊣ F) /-- When we have an adjunction `G ⊣ F`, any commutative square where the left map is of the form `G.map i` and the right map is `p` has an "adjoint" commutative square whose left map is `i` and whose right map is `F.map p`. -/ theorem right_adjoint : CommSq (adj.homEquiv _ _ u) i (F.map p) (adj.homEquiv _ _ v) := ⟨by simp only [Adjunction.homEquiv_unit, assoc, ← F.map_comp, sq.w] rw [F.map_comp, Adjunction.unit_naturality_assoc]⟩ #align category_theory.comm_sq.right_adjoint CategoryTheory.CommSq.right_adjoint /-- The liftings of a commutative are in bijection with the liftings of its (right) adjoint square. -/ def rightAdjointLiftStructEquiv : sq.LiftStruct ≃ (sq.right_adjoint adj).LiftStruct where toFun l := { l := adj.homEquiv _ _ l.l fac_left := by rw [← adj.homEquiv_naturality_left, l.fac_left] fac_right := by rw [← Adjunction.homEquiv_naturality_right, l.fac_right] } invFun l := { l := (adj.homEquiv _ _).symm l.l fac_left := by rw [← Adjunction.homEquiv_naturality_left_symm, l.fac_left] apply (adj.homEquiv _ _).left_inv fac_right := by rw [← Adjunction.homEquiv_naturality_right_symm, l.fac_right] apply (adj.homEquiv _ _).left_inv } left_inv := by aesop_cat right_inv := by aesop_cat #align category_theory.comm_sq.right_adjoint_lift_struct_equiv CategoryTheory.CommSq.rightAdjointLiftStructEquiv /-- A square has a lifting if and only if its (right) adjoint square has a lifting. -/ theorem right_adjoint_hasLift_iff : HasLift (sq.right_adjoint adj) ↔ HasLift sq := by simp only [HasLift.iff] exact Equiv.nonempty_congr (sq.rightAdjointLiftStructEquiv adj).symm #align category_theory.comm_sq.right_adjoint_has_lift_iff CategoryTheory.CommSq.right_adjoint_hasLift_iff instance [HasLift sq] : HasLift (sq.right_adjoint adj) := by rw [right_adjoint_hasLift_iff] infer_instance end section variable {A B : C} {X Y : D} {i : A ⟶ B} {p : X ⟶ Y} {u : A ⟶ F.obj X} {v : B ⟶ F.obj Y} (sq : CommSq u i (F.map p) v) (adj : G ⊣ F) /-- When we have an adjunction `G ⊣ F`, any commutative square where the left map is of the form `i` and the right map is `F.map p` has an "adjoint" commutative square whose left map is `G.map i` and whose right map is `p`. -/ theorem left_adjoint : CommSq ((adj.homEquiv _ _).symm u) (G.map i) p ((adj.homEquiv _ _).symm v) := ⟨by simp only [Adjunction.homEquiv_counit, assoc, ← G.map_comp_assoc, ← sq.w] rw [G.map_comp, assoc, Adjunction.counit_naturality]⟩ #align category_theory.comm_sq.left_adjoint CategoryTheory.CommSq.left_adjoint /-- The liftings of a commutative are in bijection with the liftings of its (left) adjoint square. -/ def leftAdjointLiftStructEquiv : sq.LiftStruct ≃ (sq.left_adjoint adj).LiftStruct where toFun l := { l := (adj.homEquiv _ _).symm l.l fac_left := by rw [← adj.homEquiv_naturality_left_symm, l.fac_left] fac_right := by rw [← adj.homEquiv_naturality_right_symm, l.fac_right] } invFun l := { l := (adj.homEquiv _ _) l.l fac_left := by rw [← adj.homEquiv_naturality_left, l.fac_left] apply (adj.homEquiv _ _).right_inv fac_right := by rw [← adj.homEquiv_naturality_right, l.fac_right] apply (adj.homEquiv _ _).right_inv } left_inv := by aesop_cat right_inv := by aesop_cat #align category_theory.comm_sq.left_adjoint_lift_struct_equiv CategoryTheory.CommSq.leftAdjointLiftStructEquiv /-- A (left) adjoint square has a lifting if and only if the original square has a lifting. -/
Mathlib/CategoryTheory/LiftingProperties/Adjunction.lean
111
113
theorem left_adjoint_hasLift_iff : HasLift (sq.left_adjoint adj) ↔ HasLift sq := by
simp only [HasLift.iff] exact Equiv.nonempty_congr (sq.leftAdjointLiftStructEquiv adj).symm
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Cast import Mathlib.Data.Int.Cast.Lemmas import Mathlib.Data.Nat.Bitwise import Mathlib.Data.Nat.PSub import Mathlib.Data.Nat.Size import Mathlib.Data.Num.Bitwise #align_import data.num.lemmas from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # Properties of the binary representation of integers -/ /- Porting note: `bit0` and `bit1` are deprecated because it is mainly used to represent number literal in Lean3 but not in Lean4 anymore. However, this file uses them for encoding numbers so this linter is unnecessary. -/ set_option linter.deprecated false -- Porting note: Required for the notation `-[n+1]`. open Int Function attribute [local simp] add_assoc namespace PosNum variable {α : Type*} @[simp, norm_cast] theorem cast_one [One α] [Add α] : ((1 : PosNum) : α) = 1 := rfl #align pos_num.cast_one PosNum.cast_one @[simp] theorem cast_one' [One α] [Add α] : (PosNum.one : α) = 1 := rfl #align pos_num.cast_one' PosNum.cast_one' @[simp, norm_cast] theorem cast_bit0 [One α] [Add α] (n : PosNum) : (n.bit0 : α) = _root_.bit0 (n : α) := rfl #align pos_num.cast_bit0 PosNum.cast_bit0 @[simp, norm_cast] theorem cast_bit1 [One α] [Add α] (n : PosNum) : (n.bit1 : α) = _root_.bit1 (n : α) := rfl #align pos_num.cast_bit1 PosNum.cast_bit1 @[simp, norm_cast] theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : PosNum, ((n : ℕ) : α) = n | 1 => Nat.cast_one | bit0 p => (Nat.cast_bit0 _).trans <| congr_arg _root_.bit0 p.cast_to_nat | bit1 p => (Nat.cast_bit1 _).trans <| congr_arg _root_.bit1 p.cast_to_nat #align pos_num.cast_to_nat PosNum.cast_to_nat @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this theorem to_nat_to_int (n : PosNum) : ((n : ℕ) : ℤ) = n := cast_to_nat _ #align pos_num.to_nat_to_int PosNum.to_nat_to_int @[simp, norm_cast] theorem cast_to_int [AddGroupWithOne α] (n : PosNum) : ((n : ℤ) : α) = n := by rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat] #align pos_num.cast_to_int PosNum.cast_to_int theorem succ_to_nat : ∀ n, (succ n : ℕ) = n + 1 | 1 => rfl | bit0 p => rfl | bit1 p => (congr_arg _root_.bit0 (succ_to_nat p)).trans <| show ↑p + 1 + ↑p + 1 = ↑p + ↑p + 1 + 1 by simp [add_left_comm] #align pos_num.succ_to_nat PosNum.succ_to_nat theorem one_add (n : PosNum) : 1 + n = succ n := by cases n <;> rfl #align pos_num.one_add PosNum.one_add theorem add_one (n : PosNum) : n + 1 = succ n := by cases n <;> rfl #align pos_num.add_one PosNum.add_one @[norm_cast] theorem add_to_nat : ∀ m n, ((m + n : PosNum) : ℕ) = m + n | 1, b => by rw [one_add b, succ_to_nat, add_comm, cast_one] | a, 1 => by rw [add_one a, succ_to_nat, cast_one] | bit0 a, bit0 b => (congr_arg _root_.bit0 (add_to_nat a b)).trans <| add_add_add_comm _ _ _ _ | bit0 a, bit1 b => (congr_arg _root_.bit1 (add_to_nat a b)).trans <| show (a + b + (a + b) + 1 : ℕ) = a + a + (b + b + 1) by simp [add_left_comm] | bit1 a, bit0 b => (congr_arg _root_.bit1 (add_to_nat a b)).trans <| show (a + b + (a + b) + 1 : ℕ) = a + a + 1 + (b + b) by simp [add_comm, add_left_comm] | bit1 a, bit1 b => show (succ (a + b) + succ (a + b) : ℕ) = a + a + 1 + (b + b + 1) by rw [succ_to_nat, add_to_nat a b]; simp [add_left_comm] #align pos_num.add_to_nat PosNum.add_to_nat theorem add_succ : ∀ m n : PosNum, m + succ n = succ (m + n) | 1, b => by simp [one_add] | bit0 a, 1 => congr_arg bit0 (add_one a) | bit1 a, 1 => congr_arg bit1 (add_one a) | bit0 a, bit0 b => rfl | bit0 a, bit1 b => congr_arg bit0 (add_succ a b) | bit1 a, bit0 b => rfl | bit1 a, bit1 b => congr_arg bit1 (add_succ a b) #align pos_num.add_succ PosNum.add_succ theorem bit0_of_bit0 : ∀ n, _root_.bit0 n = bit0 n | 1 => rfl | bit0 p => congr_arg bit0 (bit0_of_bit0 p) | bit1 p => show bit0 (succ (_root_.bit0 p)) = _ by rw [bit0_of_bit0 p, succ] #align pos_num.bit0_of_bit0 PosNum.bit0_of_bit0 theorem bit1_of_bit1 (n : PosNum) : _root_.bit1 n = bit1 n := show _root_.bit0 n + 1 = bit1 n by rw [add_one, bit0_of_bit0, succ] #align pos_num.bit1_of_bit1 PosNum.bit1_of_bit1 @[norm_cast] theorem mul_to_nat (m) : ∀ n, ((m * n : PosNum) : ℕ) = m * n | 1 => (mul_one _).symm | bit0 p => show (↑(m * p) + ↑(m * p) : ℕ) = ↑m * (p + p) by rw [mul_to_nat m p, left_distrib] | bit1 p => (add_to_nat (bit0 (m * p)) m).trans <| show (↑(m * p) + ↑(m * p) + ↑m : ℕ) = ↑m * (p + p) + m by rw [mul_to_nat m p, left_distrib] #align pos_num.mul_to_nat PosNum.mul_to_nat theorem to_nat_pos : ∀ n : PosNum, 0 < (n : ℕ) | 1 => Nat.zero_lt_one | bit0 p => let h := to_nat_pos p add_pos h h | bit1 _p => Nat.succ_pos _ #align pos_num.to_nat_pos PosNum.to_nat_pos theorem cmp_to_nat_lemma {m n : PosNum} : (m : ℕ) < n → (bit1 m : ℕ) < bit0 n := show (m : ℕ) < n → (m + m + 1 + 1 : ℕ) ≤ n + n by intro h; rw [Nat.add_right_comm m m 1, add_assoc]; exact Nat.add_le_add h h #align pos_num.cmp_to_nat_lemma PosNum.cmp_to_nat_lemma theorem cmp_swap (m) : ∀ n, (cmp m n).swap = cmp n m := by induction' m with m IH m IH <;> intro n <;> cases' n with n n <;> unfold cmp <;> try { rfl } <;> rw [← IH] <;> cases cmp m n <;> rfl #align pos_num.cmp_swap PosNum.cmp_swap theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop) | 1, 1 => rfl | bit0 a, 1 => let h : (1 : ℕ) ≤ a := to_nat_pos a Nat.add_le_add h h | bit1 a, 1 => Nat.succ_lt_succ <| to_nat_pos <| bit0 a | 1, bit0 b => let h : (1 : ℕ) ≤ b := to_nat_pos b Nat.add_le_add h h | 1, bit1 b => Nat.succ_lt_succ <| to_nat_pos <| bit0 b | bit0 a, bit0 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.add_lt_add this this · rw [this] · exact Nat.add_lt_add this this | bit0 a, bit1 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.le_succ_of_le (Nat.add_lt_add this this) · rw [this] apply Nat.lt_succ_self · exact cmp_to_nat_lemma this | bit1 a, bit0 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact cmp_to_nat_lemma this · rw [this] apply Nat.lt_succ_self · exact Nat.le_succ_of_le (Nat.add_lt_add this this) | bit1 a, bit1 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.succ_lt_succ (Nat.add_lt_add this this) · rw [this] · exact Nat.succ_lt_succ (Nat.add_lt_add this this) #align pos_num.cmp_to_nat PosNum.cmp_to_nat @[norm_cast] theorem lt_to_nat {m n : PosNum} : (m : ℕ) < n ↔ m < n := show (m : ℕ) < n ↔ cmp m n = Ordering.lt from match cmp m n, cmp_to_nat m n with | Ordering.lt, h => by simp only at h; simp [h] | Ordering.eq, h => by simp only at h; simp [h, lt_irrefl] | Ordering.gt, h => by simp [not_lt_of_gt h] #align pos_num.lt_to_nat PosNum.lt_to_nat @[norm_cast] theorem le_to_nat {m n : PosNum} : (m : ℕ) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr lt_to_nat #align pos_num.le_to_nat PosNum.le_to_nat end PosNum namespace Num variable {α : Type*} open PosNum theorem add_zero (n : Num) : n + 0 = n := by cases n <;> rfl #align num.add_zero Num.add_zero theorem zero_add (n : Num) : 0 + n = n := by cases n <;> rfl #align num.zero_add Num.zero_add theorem add_one : ∀ n : Num, n + 1 = succ n | 0 => rfl | pos p => by cases p <;> rfl #align num.add_one Num.add_one theorem add_succ : ∀ m n : Num, m + succ n = succ (m + n) | 0, n => by simp [zero_add] | pos p, 0 => show pos (p + 1) = succ (pos p + 0) by rw [PosNum.add_one, add_zero, succ, succ'] | pos p, pos q => congr_arg pos (PosNum.add_succ _ _) #align num.add_succ Num.add_succ theorem bit0_of_bit0 : ∀ n : Num, bit0 n = n.bit0 | 0 => rfl | pos p => congr_arg pos p.bit0_of_bit0 #align num.bit0_of_bit0 Num.bit0_of_bit0 theorem bit1_of_bit1 : ∀ n : Num, bit1 n = n.bit1 | 0 => rfl | pos p => congr_arg pos p.bit1_of_bit1 #align num.bit1_of_bit1 Num.bit1_of_bit1 @[simp] theorem ofNat'_zero : Num.ofNat' 0 = 0 := by simp [Num.ofNat'] #align num.of_nat'_zero Num.ofNat'_zero theorem ofNat'_bit (b n) : ofNat' (Nat.bit b n) = cond b Num.bit1 Num.bit0 (ofNat' n) := Nat.binaryRec_eq rfl _ _ #align num.of_nat'_bit Num.ofNat'_bit @[simp] theorem ofNat'_one : Num.ofNat' 1 = 1 := by erw [ofNat'_bit true 0, cond, ofNat'_zero]; rfl #align num.of_nat'_one Num.ofNat'_one theorem bit1_succ : ∀ n : Num, n.bit1.succ = n.succ.bit0 | 0 => rfl | pos _n => rfl #align num.bit1_succ Num.bit1_succ theorem ofNat'_succ : ∀ {n}, ofNat' (n + 1) = ofNat' n + 1 := @(Nat.binaryRec (by simp [zero_add]) fun b n ih => by cases b · erw [ofNat'_bit true n, ofNat'_bit] simp only [← bit1_of_bit1, ← bit0_of_bit0, cond, _root_.bit1] -- Porting note: `cc` was not ported yet so `exact Nat.add_left_comm n 1 1` is used. · erw [show n.bit true + 1 = (n + 1).bit false by simpa [Nat.bit, _root_.bit1, _root_.bit0] using Nat.add_left_comm n 1 1, ofNat'_bit, ofNat'_bit, ih] simp only [cond, add_one, bit1_succ]) #align num.of_nat'_succ Num.ofNat'_succ @[simp] theorem add_ofNat' (m n) : Num.ofNat' (m + n) = Num.ofNat' m + Num.ofNat' n := by induction n · simp only [Nat.add_zero, ofNat'_zero, add_zero] · simp only [Nat.add_succ, Nat.add_zero, ofNat'_succ, add_one, add_succ, *] #align num.add_of_nat' Num.add_ofNat' @[simp, norm_cast] theorem cast_zero [Zero α] [One α] [Add α] : ((0 : Num) : α) = 0 := rfl #align num.cast_zero Num.cast_zero @[simp] theorem cast_zero' [Zero α] [One α] [Add α] : (Num.zero : α) = 0 := rfl #align num.cast_zero' Num.cast_zero' @[simp, norm_cast] theorem cast_one [Zero α] [One α] [Add α] : ((1 : Num) : α) = 1 := rfl #align num.cast_one Num.cast_one @[simp] theorem cast_pos [Zero α] [One α] [Add α] (n : PosNum) : (Num.pos n : α) = n := rfl #align num.cast_pos Num.cast_pos theorem succ'_to_nat : ∀ n, (succ' n : ℕ) = n + 1 | 0 => (Nat.zero_add _).symm | pos _p => PosNum.succ_to_nat _ #align num.succ'_to_nat Num.succ'_to_nat theorem succ_to_nat (n) : (succ n : ℕ) = n + 1 := succ'_to_nat n #align num.succ_to_nat Num.succ_to_nat @[simp, norm_cast] theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : Num, ((n : ℕ) : α) = n | 0 => Nat.cast_zero | pos p => p.cast_to_nat #align num.cast_to_nat Num.cast_to_nat @[norm_cast] theorem add_to_nat : ∀ m n, ((m + n : Num) : ℕ) = m + n | 0, 0 => rfl | 0, pos _q => (Nat.zero_add _).symm | pos _p, 0 => rfl | pos _p, pos _q => PosNum.add_to_nat _ _ #align num.add_to_nat Num.add_to_nat @[norm_cast] theorem mul_to_nat : ∀ m n, ((m * n : Num) : ℕ) = m * n | 0, 0 => rfl | 0, pos _q => (zero_mul _).symm | pos _p, 0 => rfl | pos _p, pos _q => PosNum.mul_to_nat _ _ #align num.mul_to_nat Num.mul_to_nat theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop) | 0, 0 => rfl | 0, pos b => to_nat_pos _ | pos a, 0 => to_nat_pos _ | pos a, pos b => by have := PosNum.cmp_to_nat a b; revert this; dsimp [cmp]; cases PosNum.cmp a b exacts [id, congr_arg pos, id] #align num.cmp_to_nat Num.cmp_to_nat @[norm_cast] theorem lt_to_nat {m n : Num} : (m : ℕ) < n ↔ m < n := show (m : ℕ) < n ↔ cmp m n = Ordering.lt from match cmp m n, cmp_to_nat m n with | Ordering.lt, h => by simp only at h; simp [h] | Ordering.eq, h => by simp only at h; simp [h, lt_irrefl] | Ordering.gt, h => by simp [not_lt_of_gt h] #align num.lt_to_nat Num.lt_to_nat @[norm_cast] theorem le_to_nat {m n : Num} : (m : ℕ) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr lt_to_nat #align num.le_to_nat Num.le_to_nat end Num namespace PosNum @[simp] theorem of_to_nat' : ∀ n : PosNum, Num.ofNat' (n : ℕ) = Num.pos n | 1 => by erw [@Num.ofNat'_bit true 0, Num.ofNat'_zero]; rfl | bit0 p => by erw [@Num.ofNat'_bit false, of_to_nat' p]; rfl | bit1 p => by erw [@Num.ofNat'_bit true, of_to_nat' p]; rfl #align pos_num.of_to_nat' PosNum.of_to_nat' end PosNum namespace Num @[simp, norm_cast] theorem of_to_nat' : ∀ n : Num, Num.ofNat' (n : ℕ) = n | 0 => ofNat'_zero | pos p => p.of_to_nat' #align num.of_to_nat' Num.of_to_nat' lemma toNat_injective : Injective (castNum : Num → ℕ) := LeftInverse.injective of_to_nat' @[norm_cast] theorem to_nat_inj {m n : Num} : (m : ℕ) = n ↔ m = n := toNat_injective.eq_iff #align num.to_nat_inj Num.to_nat_inj /-- This tactic tries to turn an (in)equality about `Num`s to one about `Nat`s by rewriting. ```lean example (n : Num) (m : Num) : n ≤ n + m := by transfer_rw exact Nat.le_add_right _ _ ``` -/ scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic| (repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat] repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero])) /-- This tactic tries to prove (in)equalities about `Num`s by transferring them to the `Nat` world and then trying to call `simp`. ```lean example (n : Num) (m : Num) : n ≤ n + m := by transfer ``` -/ scoped macro (name := transfer) "transfer" : tactic => `(tactic| (intros; transfer_rw; try simp)) instance addMonoid : AddMonoid Num where add := (· + ·) zero := 0 zero_add := zero_add add_zero := add_zero add_assoc := by transfer nsmul := nsmulRec #align num.add_monoid Num.addMonoid instance addMonoidWithOne : AddMonoidWithOne Num := { Num.addMonoid with natCast := Num.ofNat' one := 1 natCast_zero := ofNat'_zero natCast_succ := fun _ => ofNat'_succ } #align num.add_monoid_with_one Num.addMonoidWithOne instance commSemiring : CommSemiring Num where __ := Num.addMonoid __ := Num.addMonoidWithOne mul := (· * ·) npow := @npowRec Num ⟨1⟩ ⟨(· * ·)⟩ mul_zero _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, mul_zero] zero_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, zero_mul] mul_one _ := by rw [← to_nat_inj, mul_to_nat, cast_one, mul_one] one_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_one, one_mul] add_comm _ _ := by simp_rw [← to_nat_inj, add_to_nat, add_comm] mul_comm _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_comm] mul_assoc _ _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_assoc] left_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, mul_add] right_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, add_mul] #align num.comm_semiring Num.commSemiring instance orderedCancelAddCommMonoid : OrderedCancelAddCommMonoid Num where le := (· ≤ ·) lt := (· < ·) lt_iff_le_not_le a b := by simp only [← lt_to_nat, ← le_to_nat, lt_iff_le_not_le] le_refl := by transfer le_trans a b c := by transfer_rw; apply le_trans le_antisymm a b := by transfer_rw; apply le_antisymm add_le_add_left a b h c := by revert h; transfer_rw; exact fun h => add_le_add_left h c le_of_add_le_add_left a b c := by transfer_rw; apply le_of_add_le_add_left #align num.ordered_cancel_add_comm_monoid Num.orderedCancelAddCommMonoid instance linearOrderedSemiring : LinearOrderedSemiring Num := { Num.commSemiring, Num.orderedCancelAddCommMonoid with le_total := by intro a b transfer_rw apply le_total zero_le_one := by decide mul_lt_mul_of_pos_left := by intro a b c transfer_rw apply mul_lt_mul_of_pos_left mul_lt_mul_of_pos_right := by intro a b c transfer_rw apply mul_lt_mul_of_pos_right decidableLT := Num.decidableLT decidableLE := Num.decidableLE -- This is relying on an automatically generated instance name, -- generated in a `deriving` handler. -- See https://github.com/leanprover/lean4/issues/2343 decidableEq := instDecidableEqNum exists_pair_ne := ⟨0, 1, by decide⟩ } #align num.linear_ordered_semiring Num.linearOrderedSemiring @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this theorem add_of_nat (m n) : ((m + n : ℕ) : Num) = m + n := add_ofNat' _ _ #align num.add_of_nat Num.add_of_nat @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this theorem to_nat_to_int (n : Num) : ((n : ℕ) : ℤ) = n := cast_to_nat _ #align num.to_nat_to_int Num.to_nat_to_int @[simp, norm_cast] theorem cast_to_int {α} [AddGroupWithOne α] (n : Num) : ((n : ℤ) : α) = n := by rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat] #align num.cast_to_int Num.cast_to_int theorem to_of_nat : ∀ n : ℕ, ((n : Num) : ℕ) = n | 0 => by rw [Nat.cast_zero, cast_zero] | n + 1 => by rw [Nat.cast_succ, add_one, succ_to_nat, to_of_nat n] #align num.to_of_nat Num.to_of_nat @[simp, norm_cast] theorem of_natCast {α} [AddMonoidWithOne α] (n : ℕ) : ((n : Num) : α) = n := by rw [← cast_to_nat, to_of_nat] #align num.of_nat_cast Num.of_natCast @[deprecated (since := "2024-04-17")] alias of_nat_cast := of_natCast @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this theorem of_nat_inj {m n : ℕ} : (m : Num) = n ↔ m = n := ⟨fun h => Function.LeftInverse.injective to_of_nat h, congr_arg _⟩ #align num.of_nat_inj Num.of_nat_inj -- Porting note: The priority should be `high`er than `cast_to_nat`. @[simp high, norm_cast] theorem of_to_nat : ∀ n : Num, ((n : ℕ) : Num) = n := of_to_nat' #align num.of_to_nat Num.of_to_nat @[norm_cast] theorem dvd_to_nat (m n : Num) : (m : ℕ) ∣ n ↔ m ∣ n := ⟨fun ⟨k, e⟩ => ⟨k, by rw [← of_to_nat n, e]; simp⟩, fun ⟨k, e⟩ => ⟨k, by simp [e, mul_to_nat]⟩⟩ #align num.dvd_to_nat Num.dvd_to_nat end Num namespace PosNum variable {α : Type*} open Num -- Porting note: The priority should be `high`er than `cast_to_nat`. @[simp high, norm_cast] theorem of_to_nat : ∀ n : PosNum, ((n : ℕ) : Num) = Num.pos n := of_to_nat' #align pos_num.of_to_nat PosNum.of_to_nat @[norm_cast] theorem to_nat_inj {m n : PosNum} : (m : ℕ) = n ↔ m = n := ⟨fun h => Num.pos.inj <| by rw [← PosNum.of_to_nat, ← PosNum.of_to_nat, h], congr_arg _⟩ #align pos_num.to_nat_inj PosNum.to_nat_inj theorem pred'_to_nat : ∀ n, (pred' n : ℕ) = Nat.pred n | 1 => rfl | bit0 n => have : Nat.succ ↑(pred' n) = ↑n := by rw [pred'_to_nat n, Nat.succ_pred_eq_of_pos (to_nat_pos n)] match (motive := ∀ k : Num, Nat.succ ↑k = ↑n → ↑(Num.casesOn k 1 bit1 : PosNum) = Nat.pred (_root_.bit0 n)) pred' n, this with | 0, (h : ((1 : Num) : ℕ) = n) => by rw [← to_nat_inj.1 h]; rfl | Num.pos p, (h : Nat.succ ↑p = n) => by rw [← h]; exact (Nat.succ_add p p).symm | bit1 n => rfl #align pos_num.pred'_to_nat PosNum.pred'_to_nat @[simp] theorem pred'_succ' (n) : pred' (succ' n) = n := Num.to_nat_inj.1 <| by rw [pred'_to_nat, succ'_to_nat, Nat.add_one, Nat.pred_succ] #align pos_num.pred'_succ' PosNum.pred'_succ' @[simp] theorem succ'_pred' (n) : succ' (pred' n) = n := to_nat_inj.1 <| by rw [succ'_to_nat, pred'_to_nat, Nat.add_one, Nat.succ_pred_eq_of_pos (to_nat_pos _)] #align pos_num.succ'_pred' PosNum.succ'_pred' instance dvd : Dvd PosNum := ⟨fun m n => pos m ∣ pos n⟩ #align pos_num.has_dvd PosNum.dvd @[norm_cast] theorem dvd_to_nat {m n : PosNum} : (m : ℕ) ∣ n ↔ m ∣ n := Num.dvd_to_nat (pos m) (pos n) #align pos_num.dvd_to_nat PosNum.dvd_to_nat theorem size_to_nat : ∀ n, (size n : ℕ) = Nat.size n | 1 => Nat.size_one.symm | bit0 n => by rw [size, succ_to_nat, size_to_nat n, cast_bit0, Nat.size_bit0 <| ne_of_gt <| to_nat_pos n] | bit1 n => by rw [size, succ_to_nat, size_to_nat n, cast_bit1, Nat.size_bit1] #align pos_num.size_to_nat PosNum.size_to_nat theorem size_eq_natSize : ∀ n, (size n : ℕ) = natSize n | 1 => rfl | bit0 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n] | bit1 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n] #align pos_num.size_eq_nat_size PosNum.size_eq_natSize theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat] #align pos_num.nat_size_to_nat PosNum.natSize_to_nat theorem natSize_pos (n) : 0 < natSize n := by cases n <;> apply Nat.succ_pos #align pos_num.nat_size_pos PosNum.natSize_pos /-- This tactic tries to turn an (in)equality about `PosNum`s to one about `Nat`s by rewriting. ```lean example (n : PosNum) (m : PosNum) : n ≤ n + m := by transfer_rw exact Nat.le_add_right _ _ ``` -/ scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic| (repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat] repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero])) /-- This tactic tries to prove (in)equalities about `PosNum`s by transferring them to the `Nat` world and then trying to call `simp`. ```lean example (n : PosNum) (m : PosNum) : n ≤ n + m := by transfer ``` -/ scoped macro (name := transfer) "transfer" : tactic => `(tactic| (intros; transfer_rw; try simp [add_comm, add_left_comm, mul_comm, mul_left_comm])) instance addCommSemigroup : AddCommSemigroup PosNum where add := (· + ·) add_assoc := by transfer add_comm := by transfer #align pos_num.add_comm_semigroup PosNum.addCommSemigroup instance commMonoid : CommMonoid PosNum where mul := (· * ·) one := (1 : PosNum) npow := @npowRec PosNum ⟨1⟩ ⟨(· * ·)⟩ mul_assoc := by transfer one_mul := by transfer mul_one := by transfer mul_comm := by transfer #align pos_num.comm_monoid PosNum.commMonoid instance distrib : Distrib PosNum where add := (· + ·) mul := (· * ·) left_distrib := by transfer; simp [mul_add] right_distrib := by transfer; simp [mul_add, mul_comm] #align pos_num.distrib PosNum.distrib instance linearOrder : LinearOrder PosNum where lt := (· < ·) lt_iff_le_not_le := by intro a b transfer_rw apply lt_iff_le_not_le le := (· ≤ ·) le_refl := by transfer le_trans := by intro a b c transfer_rw apply le_trans le_antisymm := by intro a b transfer_rw apply le_antisymm le_total := by intro a b transfer_rw apply le_total decidableLT := by infer_instance decidableLE := by infer_instance decidableEq := by infer_instance #align pos_num.linear_order PosNum.linearOrder @[simp] theorem cast_to_num (n : PosNum) : ↑n = Num.pos n := by rw [← cast_to_nat, ← of_to_nat n] #align pos_num.cast_to_num PosNum.cast_to_num @[simp, norm_cast] theorem bit_to_nat (b n) : (bit b n : ℕ) = Nat.bit b n := by cases b <;> rfl #align pos_num.bit_to_nat PosNum.bit_to_nat @[simp, norm_cast] theorem cast_add [AddMonoidWithOne α] (m n) : ((m + n : PosNum) : α) = m + n := by rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat] #align pos_num.cast_add PosNum.cast_add @[simp 500, norm_cast] theorem cast_succ [AddMonoidWithOne α] (n : PosNum) : (succ n : α) = n + 1 := by rw [← add_one, cast_add, cast_one] #align pos_num.cast_succ PosNum.cast_succ @[simp, norm_cast] theorem cast_inj [AddMonoidWithOne α] [CharZero α] {m n : PosNum} : (m : α) = n ↔ m = n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_inj, to_nat_inj] #align pos_num.cast_inj PosNum.cast_inj @[simp] theorem one_le_cast [LinearOrderedSemiring α] (n : PosNum) : (1 : α) ≤ n := by rw [← cast_to_nat, ← Nat.cast_one, Nat.cast_le (α := α)]; apply to_nat_pos #align pos_num.one_le_cast PosNum.one_le_cast @[simp] theorem cast_pos [LinearOrderedSemiring α] (n : PosNum) : 0 < (n : α) := lt_of_lt_of_le zero_lt_one (one_le_cast n) #align pos_num.cast_pos PosNum.cast_pos @[simp, norm_cast] theorem cast_mul [Semiring α] (m n) : ((m * n : PosNum) : α) = m * n := by rw [← cast_to_nat, mul_to_nat, Nat.cast_mul, cast_to_nat, cast_to_nat] #align pos_num.cast_mul PosNum.cast_mul @[simp] theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by have := cmp_to_nat m n -- Porting note: `cases` didn't rewrite at `this`, so `revert` & `intro` are required. revert this; cases cmp m n <;> intro this <;> simp at this ⊢ <;> try { exact this } <;> simp [show m ≠ n from fun e => by rw [e] at this;exact lt_irrefl _ this] #align pos_num.cmp_eq PosNum.cmp_eq @[simp, norm_cast] theorem cast_lt [LinearOrderedSemiring α] {m n : PosNum} : (m : α) < n ↔ m < n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_lt (α := α), lt_to_nat] #align pos_num.cast_lt PosNum.cast_lt @[simp, norm_cast] theorem cast_le [LinearOrderedSemiring α] {m n : PosNum} : (m : α) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr cast_lt #align pos_num.cast_le PosNum.cast_le end PosNum namespace Num variable {α : Type*} open PosNum theorem bit_to_nat (b n) : (bit b n : ℕ) = Nat.bit b n := by cases b <;> cases n <;> rfl #align num.bit_to_nat Num.bit_to_nat theorem cast_succ' [AddMonoidWithOne α] (n) : (succ' n : α) = n + 1 := by rw [← PosNum.cast_to_nat, succ'_to_nat, Nat.cast_add_one, cast_to_nat] #align num.cast_succ' Num.cast_succ' theorem cast_succ [AddMonoidWithOne α] (n) : (succ n : α) = n + 1 := cast_succ' n #align num.cast_succ Num.cast_succ @[simp, norm_cast] theorem cast_add [Semiring α] (m n) : ((m + n : Num) : α) = m + n := by rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat] #align num.cast_add Num.cast_add @[simp, norm_cast] theorem cast_bit0 [Semiring α] (n : Num) : (n.bit0 : α) = _root_.bit0 (n : α) := by rw [← bit0_of_bit0, _root_.bit0, cast_add]; rfl #align num.cast_bit0 Num.cast_bit0 @[simp, norm_cast] theorem cast_bit1 [Semiring α] (n : Num) : (n.bit1 : α) = _root_.bit1 (n : α) := by rw [← bit1_of_bit1, _root_.bit1, bit0_of_bit0, cast_add, cast_bit0]; rfl #align num.cast_bit1 Num.cast_bit1 @[simp, norm_cast] theorem cast_mul [Semiring α] : ∀ m n, ((m * n : Num) : α) = m * n | 0, 0 => (zero_mul _).symm | 0, pos _q => (zero_mul _).symm | pos _p, 0 => (mul_zero _).symm | pos _p, pos _q => PosNum.cast_mul _ _ #align num.cast_mul Num.cast_mul theorem size_to_nat : ∀ n, (size n : ℕ) = Nat.size n | 0 => Nat.size_zero.symm | pos p => p.size_to_nat #align num.size_to_nat Num.size_to_nat theorem size_eq_natSize : ∀ n, (size n : ℕ) = natSize n | 0 => rfl | pos p => p.size_eq_natSize #align num.size_eq_nat_size Num.size_eq_natSize theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat] #align num.nat_size_to_nat Num.natSize_to_nat @[simp 999] theorem ofNat'_eq : ∀ n, Num.ofNat' n = n := Nat.binaryRec (by simp) fun b n IH => by rw [ofNat'] at IH ⊢ rw [Nat.binaryRec_eq, IH] -- Porting note: `Nat.cast_bit0` & `Nat.cast_bit1` are not `simp` theorems anymore. · cases b <;> simp [Nat.bit, bit0_of_bit0, bit1_of_bit1, Nat.cast_bit0, Nat.cast_bit1] · rfl #align num.of_nat'_eq Num.ofNat'_eq theorem zneg_toZNum (n : Num) : -n.toZNum = n.toZNumNeg := by cases n <;> rfl #align num.zneg_to_znum Num.zneg_toZNum theorem zneg_toZNumNeg (n : Num) : -n.toZNumNeg = n.toZNum := by cases n <;> rfl #align num.zneg_to_znum_neg Num.zneg_toZNumNeg theorem toZNum_inj {m n : Num} : m.toZNum = n.toZNum ↔ m = n := ⟨fun h => by cases m <;> cases n <;> cases h <;> rfl, congr_arg _⟩ #align num.to_znum_inj Num.toZNum_inj @[simp] theorem cast_toZNum [Zero α] [One α] [Add α] [Neg α] : ∀ n : Num, (n.toZNum : α) = n | 0 => rfl | Num.pos _p => rfl #align num.cast_to_znum Num.cast_toZNum @[simp] theorem cast_toZNumNeg [AddGroup α] [One α] : ∀ n : Num, (n.toZNumNeg : α) = -n | 0 => neg_zero.symm | Num.pos _p => rfl #align num.cast_to_znum_neg Num.cast_toZNumNeg @[simp] theorem add_toZNum (m n : Num) : Num.toZNum (m + n) = m.toZNum + n.toZNum := by cases m <;> cases n <;> rfl #align num.add_to_znum Num.add_toZNum end Num namespace PosNum open Num theorem pred_to_nat {n : PosNum} (h : 1 < n) : (pred n : ℕ) = Nat.pred n := by unfold pred cases e : pred' n · have : (1 : ℕ) ≤ Nat.pred n := Nat.pred_le_pred ((@cast_lt ℕ _ _ _).2 h) rw [← pred'_to_nat, e] at this exact absurd this (by decide) · rw [← pred'_to_nat, e] rfl #align pos_num.pred_to_nat PosNum.pred_to_nat theorem sub'_one (a : PosNum) : sub' a 1 = (pred' a).toZNum := by cases a <;> rfl #align pos_num.sub'_one PosNum.sub'_one theorem one_sub' (a : PosNum) : sub' 1 a = (pred' a).toZNumNeg := by cases a <;> rfl #align pos_num.one_sub' PosNum.one_sub' theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = Ordering.lt := Iff.rfl #align pos_num.lt_iff_cmp PosNum.lt_iff_cmp theorem le_iff_cmp {m n} : m ≤ n ↔ cmp m n ≠ Ordering.gt := not_congr <| lt_iff_cmp.trans <| by rw [← cmp_swap]; cases cmp m n <;> decide #align pos_num.le_iff_cmp PosNum.le_iff_cmp end PosNum namespace Num variable {α : Type*} open PosNum theorem pred_to_nat : ∀ n : Num, (pred n : ℕ) = Nat.pred n | 0 => rfl | pos p => by rw [pred, PosNum.pred'_to_nat]; rfl #align num.pred_to_nat Num.pred_to_nat theorem ppred_to_nat : ∀ n : Num, (↑) <$> ppred n = Nat.ppred n | 0 => rfl | pos p => by rw [ppred, Option.map_some, Nat.ppred_eq_some.2] rw [PosNum.pred'_to_nat, Nat.succ_pred_eq_of_pos (PosNum.to_nat_pos _)] rfl #align num.ppred_to_nat Num.ppred_to_nat theorem cmp_swap (m n) : (cmp m n).swap = cmp n m := by cases m <;> cases n <;> try { rfl }; apply PosNum.cmp_swap #align num.cmp_swap Num.cmp_swap theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by have := cmp_to_nat m n -- Porting note: `cases` didn't rewrite at `this`, so `revert` & `intro` are required. revert this; cases cmp m n <;> intro this <;> simp at this ⊢ <;> try { exact this } <;> simp [show m ≠ n from fun e => by rw [e] at this; exact lt_irrefl _ this] #align num.cmp_eq Num.cmp_eq @[simp, norm_cast] theorem cast_lt [LinearOrderedSemiring α] {m n : Num} : (m : α) < n ↔ m < n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_lt (α := α), lt_to_nat] #align num.cast_lt Num.cast_lt @[simp, norm_cast] theorem cast_le [LinearOrderedSemiring α] {m n : Num} : (m : α) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr cast_lt #align num.cast_le Num.cast_le @[simp, norm_cast] theorem cast_inj [LinearOrderedSemiring α] {m n : Num} : (m : α) = n ↔ m = n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_inj, to_nat_inj] #align num.cast_inj Num.cast_inj theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = Ordering.lt := Iff.rfl #align num.lt_iff_cmp Num.lt_iff_cmp theorem le_iff_cmp {m n} : m ≤ n ↔ cmp m n ≠ Ordering.gt := not_congr <| lt_iff_cmp.trans <| by rw [← cmp_swap]; cases cmp m n <;> decide #align num.le_iff_cmp Num.le_iff_cmp theorem castNum_eq_bitwise {f : Num → Num → Num} {g : Bool → Bool → Bool} (p : PosNum → PosNum → Num) (gff : g false false = false) (f00 : f 0 0 = 0) (f0n : ∀ n, f 0 (pos n) = cond (g false true) (pos n) 0) (fn0 : ∀ n, f (pos n) 0 = cond (g true false) (pos n) 0) (fnn : ∀ m n, f (pos m) (pos n) = p m n) (p11 : p 1 1 = cond (g true true) 1 0) (p1b : ∀ b n, p 1 (PosNum.bit b n) = bit (g true b) (cond (g false true) (pos n) 0)) (pb1 : ∀ a m, p (PosNum.bit a m) 1 = bit (g a true) (cond (g true false) (pos m) 0)) (pbb : ∀ a b m n, p (PosNum.bit a m) (PosNum.bit b n) = bit (g a b) (p m n)) : ∀ m n : Num, (f m n : ℕ) = Nat.bitwise g m n := by intros m n cases' m with m <;> cases' n with n <;> try simp only [show zero = 0 from rfl, show ((0 : Num) : ℕ) = 0 from rfl] · rw [f00, Nat.bitwise_zero]; rfl · rw [f0n, Nat.bitwise_zero_left] cases g false true <;> rfl · rw [fn0, Nat.bitwise_zero_right] cases g true false <;> rfl · rw [fnn] have : ∀ (b) (n : PosNum), (cond b (↑n) 0 : ℕ) = ↑(cond b (pos n) 0 : Num) := by intros b _; cases b <;> rfl induction' m with m IH m IH generalizing n <;> cases' n with n n any_goals simp only [show one = 1 from rfl, show pos 1 = 1 from rfl, show PosNum.bit0 = PosNum.bit false from rfl, show PosNum.bit1 = PosNum.bit true from rfl, show ((1 : Num) : ℕ) = Nat.bit true 0 from rfl] all_goals repeat rw [show ∀ b n, (pos (PosNum.bit b n) : ℕ) = Nat.bit b ↑n by intros b _; cases b <;> rfl] rw [Nat.bitwise_bit gff] any_goals rw [Nat.bitwise_zero, p11]; cases g true true <;> rfl any_goals rw [Nat.bitwise_zero_left, ← Bool.cond_eq_ite, this, ← bit_to_nat, p1b] any_goals rw [Nat.bitwise_zero_right, ← Bool.cond_eq_ite, this, ← bit_to_nat, pb1] all_goals rw [← show ∀ n : PosNum, ↑(p m n) = Nat.bitwise g ↑m ↑n from IH] rw [← bit_to_nat, pbb] #align num.bitwise_to_nat Num.castNum_eq_bitwise @[simp, norm_cast] theorem castNum_or : ∀ m n : Num, ↑(m ||| n) = (↑m ||| ↑n : ℕ) := by -- Porting note: A name of an implicit local hypothesis is not available so -- `cases_type*` is used. apply castNum_eq_bitwise fun x y => pos (PosNum.lor x y) <;> intros <;> (try cases_type* Bool) <;> rfl #align num.lor_to_nat Num.castNum_or @[simp, norm_cast] theorem castNum_and : ∀ m n : Num, ↑(m &&& n) = (↑m &&& ↑n : ℕ) := by apply castNum_eq_bitwise PosNum.land <;> intros <;> (try cases_type* Bool) <;> rfl #align num.land_to_nat Num.castNum_and @[simp, norm_cast] theorem castNum_ldiff : ∀ m n : Num, (ldiff m n : ℕ) = Nat.ldiff m n := by apply castNum_eq_bitwise PosNum.ldiff <;> intros <;> (try cases_type* Bool) <;> rfl #align num.ldiff_to_nat Num.castNum_ldiff @[simp, norm_cast] theorem castNum_xor : ∀ m n : Num, ↑(m ^^^ n) = (↑m ^^^ ↑n : ℕ) := by apply castNum_eq_bitwise PosNum.lxor <;> intros <;> (try cases_type* Bool) <;> rfl #align num.lxor_to_nat Num.castNum_ldiff @[simp, norm_cast] theorem castNum_shiftLeft (m : Num) (n : Nat) : ↑(m <<< n) = (m : ℕ) <<< (n : ℕ) := by cases m <;> dsimp only [← shiftl_eq_shiftLeft, shiftl] · symm apply Nat.zero_shiftLeft simp only [cast_pos] induction' n with n IH · rfl simp [PosNum.shiftl_succ_eq_bit0_shiftl, Nat.shiftLeft_succ, IH, Nat.bit0_val, pow_succ, ← mul_assoc, mul_comm, -shiftl_eq_shiftLeft, -PosNum.shiftl_eq_shiftLeft, shiftl] #align num.shiftl_to_nat Num.castNum_shiftLeft @[simp, norm_cast] theorem castNum_shiftRight (m : Num) (n : Nat) : ↑(m >>> n) = (m : ℕ) >>> (n : ℕ) := by cases' m with m <;> dsimp only [← shiftr_eq_shiftRight, shiftr]; · symm apply Nat.zero_shiftRight induction' n with n IH generalizing m · cases m <;> rfl cases' m with m m <;> dsimp only [PosNum.shiftr, ← PosNum.shiftr_eq_shiftRight] · rw [Nat.shiftRight_eq_div_pow] symm apply Nat.div_eq_of_lt simp · trans · apply IH change Nat.shiftRight m n = Nat.shiftRight (_root_.bit1 m) (n + 1) rw [add_comm n 1, @Nat.shiftRight_eq _ (1 + n), Nat.shiftRight_add] apply congr_arg fun x => Nat.shiftRight x n simp [Nat.shiftRight_succ, Nat.shiftRight_zero, ← Nat.div2_val] · trans · apply IH change Nat.shiftRight m n = Nat.shiftRight (_root_.bit0 m) (n + 1) rw [add_comm n 1, @Nat.shiftRight_eq _ (1 + n), Nat.shiftRight_add] apply congr_arg fun x => Nat.shiftRight x n simp [Nat.shiftRight_succ, Nat.shiftRight_zero, ← Nat.div2_val] #align num.shiftr_to_nat Num.castNum_shiftRight @[simp] theorem castNum_testBit (m n) : testBit m n = Nat.testBit m n := by -- Porting note: `unfold` → `dsimp only` cases m with dsimp only [testBit] | zero => rw [show (Num.zero : Nat) = 0 from rfl, Nat.zero_testBit] | pos m => rw [cast_pos] induction' n with n IH generalizing m <;> cases' m with m m <;> dsimp only [PosNum.testBit, Nat.zero_eq] · rfl · rw [PosNum.cast_bit1, ← Nat.bit_true, Nat.testBit_bit_zero] · rw [PosNum.cast_bit0, ← Nat.bit_false, Nat.testBit_bit_zero] · simp · rw [PosNum.cast_bit1, ← Nat.bit_true, Nat.testBit_bit_succ, IH] · rw [PosNum.cast_bit0, ← Nat.bit_false, Nat.testBit_bit_succ, IH] #align num.test_bit_to_nat Num.castNum_testBit end Num namespace ZNum variable {α : Type*} open PosNum @[simp, norm_cast] theorem cast_zero [Zero α] [One α] [Add α] [Neg α] : ((0 : ZNum) : α) = 0 := rfl #align znum.cast_zero ZNum.cast_zero @[simp] theorem cast_zero' [Zero α] [One α] [Add α] [Neg α] : (ZNum.zero : α) = 0 := rfl #align znum.cast_zero' ZNum.cast_zero' @[simp, norm_cast] theorem cast_one [Zero α] [One α] [Add α] [Neg α] : ((1 : ZNum) : α) = 1 := rfl #align znum.cast_one ZNum.cast_one @[simp] theorem cast_pos [Zero α] [One α] [Add α] [Neg α] (n : PosNum) : (pos n : α) = n := rfl #align znum.cast_pos ZNum.cast_pos @[simp] theorem cast_neg [Zero α] [One α] [Add α] [Neg α] (n : PosNum) : (neg n : α) = -n := rfl #align znum.cast_neg ZNum.cast_neg @[simp, norm_cast] theorem cast_zneg [AddGroup α] [One α] : ∀ n, ((-n : ZNum) : α) = -n | 0 => neg_zero.symm | pos _p => rfl | neg _p => (neg_neg _).symm #align znum.cast_zneg ZNum.cast_zneg theorem neg_zero : (-0 : ZNum) = 0 := rfl #align znum.neg_zero ZNum.neg_zero theorem zneg_pos (n : PosNum) : -pos n = neg n := rfl #align znum.zneg_pos ZNum.zneg_pos theorem zneg_neg (n : PosNum) : -neg n = pos n := rfl #align znum.zneg_neg ZNum.zneg_neg theorem zneg_zneg (n : ZNum) : - -n = n := by cases n <;> rfl #align znum.zneg_zneg ZNum.zneg_zneg theorem zneg_bit1 (n : ZNum) : -n.bit1 = (-n).bitm1 := by cases n <;> rfl #align znum.zneg_bit1 ZNum.zneg_bit1 theorem zneg_bitm1 (n : ZNum) : -n.bitm1 = (-n).bit1 := by cases n <;> rfl #align znum.zneg_bitm1 ZNum.zneg_bitm1 theorem zneg_succ (n : ZNum) : -n.succ = (-n).pred := by cases n <;> try { rfl }; rw [succ, Num.zneg_toZNumNeg]; rfl #align znum.zneg_succ ZNum.zneg_succ theorem zneg_pred (n : ZNum) : -n.pred = (-n).succ := by rw [← zneg_zneg (succ (-n)), zneg_succ, zneg_zneg] #align znum.zneg_pred ZNum.zneg_pred @[simp] theorem abs_to_nat : ∀ n, (abs n : ℕ) = Int.natAbs n | 0 => rfl | pos p => congr_arg Int.natAbs p.to_nat_to_int | neg p => show Int.natAbs ((p : ℕ) : ℤ) = Int.natAbs (-p) by rw [p.to_nat_to_int, Int.natAbs_neg] #align znum.abs_to_nat ZNum.abs_to_nat @[simp] theorem abs_toZNum : ∀ n : Num, abs n.toZNum = n | 0 => rfl | Num.pos _p => rfl #align znum.abs_to_znum ZNum.abs_toZNum @[simp, norm_cast] theorem cast_to_int [AddGroupWithOne α] : ∀ n : ZNum, ((n : ℤ) : α) = n | 0 => by rw [cast_zero, cast_zero, Int.cast_zero] | pos p => by rw [cast_pos, cast_pos, PosNum.cast_to_int] | neg p => by rw [cast_neg, cast_neg, Int.cast_neg, PosNum.cast_to_int] #align znum.cast_to_int ZNum.cast_to_int theorem bit0_of_bit0 : ∀ n : ZNum, bit0 n = n.bit0 | 0 => rfl | pos a => congr_arg pos a.bit0_of_bit0 | neg a => congr_arg neg a.bit0_of_bit0 #align znum.bit0_of_bit0 ZNum.bit0_of_bit0 theorem bit1_of_bit1 : ∀ n : ZNum, bit1 n = n.bit1 | 0 => rfl | pos a => congr_arg pos a.bit1_of_bit1 | neg a => show PosNum.sub' 1 (_root_.bit0 a) = _ by rw [PosNum.one_sub', a.bit0_of_bit0]; rfl #align znum.bit1_of_bit1 ZNum.bit1_of_bit1 @[simp, norm_cast] theorem cast_bit0 [AddGroupWithOne α] : ∀ n : ZNum, (n.bit0 : α) = bit0 (n : α) | 0 => (add_zero _).symm | pos p => by rw [ZNum.bit0, cast_pos, cast_pos]; rfl | neg p => by rw [ZNum.bit0, cast_neg, cast_neg, PosNum.cast_bit0, _root_.bit0, _root_.bit0, neg_add_rev] #align znum.cast_bit0 ZNum.cast_bit0 @[simp, norm_cast] theorem cast_bit1 [AddGroupWithOne α] : ∀ n : ZNum, (n.bit1 : α) = bit1 (n : α) | 0 => by simp [ZNum.bit1, _root_.bit1, _root_.bit0] | pos p => by rw [ZNum.bit1, cast_pos, cast_pos]; rfl | neg p => by rw [ZNum.bit1, cast_neg, cast_neg] cases' e : pred' p with a <;> have ep : p = _ := (succ'_pred' p).symm.trans (congr_arg Num.succ' e) · conv at ep => change p = 1 subst p simp [_root_.bit1, _root_.bit0] -- Porting note: `rw [Num.succ']` yields a `match` pattern. · dsimp only [Num.succ'] at ep subst p have : (↑(-↑a : ℤ) : α) = -1 + ↑(-↑a + 1 : ℤ) := by simp [add_comm (- ↑a : ℤ) 1] simpa [_root_.bit1, _root_.bit0] using this #align znum.cast_bit1 ZNum.cast_bit1 @[simp] theorem cast_bitm1 [AddGroupWithOne α] (n : ZNum) : (n.bitm1 : α) = bit0 (n : α) - 1 := by conv => lhs rw [← zneg_zneg n] rw [← zneg_bit1, cast_zneg, cast_bit1] have : ((-1 + n + n : ℤ) : α) = (n + n + -1 : ℤ) := by simp [add_comm, add_left_comm] simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg] using this #align znum.cast_bitm1 ZNum.cast_bitm1 theorem add_zero (n : ZNum) : n + 0 = n := by cases n <;> rfl #align znum.add_zero ZNum.add_zero theorem zero_add (n : ZNum) : 0 + n = n := by cases n <;> rfl #align znum.zero_add ZNum.zero_add theorem add_one : ∀ n : ZNum, n + 1 = succ n | 0 => rfl | pos p => congr_arg pos p.add_one | neg p => by cases p <;> rfl #align znum.add_one ZNum.add_one end ZNum namespace PosNum variable {α : Type*} theorem cast_to_znum : ∀ n : PosNum, (n : ZNum) = ZNum.pos n | 1 => rfl | bit0 p => (ZNum.bit0_of_bit0 p).trans <| congr_arg _ (cast_to_znum p) | bit1 p => (ZNum.bit1_of_bit1 p).trans <| congr_arg _ (cast_to_znum p) #align pos_num.cast_to_znum PosNum.cast_to_znum theorem cast_sub' [AddGroupWithOne α] : ∀ m n : PosNum, (sub' m n : α) = m - n | a, 1 => by rw [sub'_one, Num.cast_toZNum, ← Num.cast_to_nat, pred'_to_nat, ← Nat.sub_one] simp [PosNum.cast_pos] | 1, b => by rw [one_sub', Num.cast_toZNumNeg, ← neg_sub, neg_inj, ← Num.cast_to_nat, pred'_to_nat, ← Nat.sub_one] simp [PosNum.cast_pos] | bit0 a, bit0 b => by rw [sub', ZNum.cast_bit0, cast_sub' a b] have : ((a + -b + (a + -b) : ℤ) : α) = a + a + (-b + -b) := by simp [add_left_comm] simpa [_root_.bit0, sub_eq_add_neg] using this | bit0 a, bit1 b => by rw [sub', ZNum.cast_bitm1, cast_sub' a b] have : ((-b + (a + (-b + -1)) : ℤ) : α) = (a + -1 + (-b + -b) : ℤ) := by simp [add_comm, add_left_comm] simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg] using this | bit1 a, bit0 b => by rw [sub', ZNum.cast_bit1, cast_sub' a b] have : ((-b + (a + (-b + 1)) : ℤ) : α) = (a + 1 + (-b + -b) : ℤ) := by simp [add_comm, add_left_comm] simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg] using this | bit1 a, bit1 b => by rw [sub', ZNum.cast_bit0, cast_sub' a b] have : ((-b + (a + -b) : ℤ) : α) = a + (-b + -b) := by simp [add_left_comm] simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg] using this #align pos_num.cast_sub' PosNum.cast_sub'
Mathlib/Data/Num/Lemmas.lean
1,190
1,191
theorem to_nat_eq_succ_pred (n : PosNum) : (n : ℕ) = n.pred' + 1 := by
rw [← Num.succ'_to_nat, n.succ'_pred']
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Manuel Candales -/ import Mathlib.Analysis.InnerProductSpace.Basic import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse #align_import geometry.euclidean.angle.unoriented.basic from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Angles between vectors This file defines unoriented angles in real inner product spaces. ## Main definitions * `InnerProductGeometry.angle` is the undirected angle between two vectors. ## TODO Prove the triangle inequality for the angle. -/ assert_not_exists HasFDerivAt assert_not_exists ConformalAt noncomputable section open Real Set open Real open RealInnerProductSpace namespace InnerProductGeometry variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] {x y : V} /-- The undirected angle between two vectors. If either vector is 0, this is π/2. See `Orientation.oangle` for the corresponding oriented angle definition. -/ def angle (x y : V) : ℝ := Real.arccos (⟪x, y⟫ / (‖x‖ * ‖y‖)) #align inner_product_geometry.angle InnerProductGeometry.angle theorem continuousAt_angle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) : ContinuousAt (fun y : V × V => angle y.1 y.2) x := Real.continuous_arccos.continuousAt.comp <| continuous_inner.continuousAt.div ((continuous_norm.comp continuous_fst).mul (continuous_norm.comp continuous_snd)).continuousAt (by simp [hx1, hx2]) #align inner_product_geometry.continuous_at_angle InnerProductGeometry.continuousAt_angle theorem angle_smul_smul {c : ℝ} (hc : c ≠ 0) (x y : V) : angle (c • x) (c • y) = angle x y := by have : c * c ≠ 0 := mul_ne_zero hc hc rw [angle, angle, real_inner_smul_left, inner_smul_right, norm_smul, norm_smul, Real.norm_eq_abs, mul_mul_mul_comm _ ‖x‖, abs_mul_abs_self, ← mul_assoc c c, mul_div_mul_left _ _ this] #align inner_product_geometry.angle_smul_smul InnerProductGeometry.angle_smul_smul @[simp] theorem _root_.LinearIsometry.angle_map {E F : Type*} [NormedAddCommGroup E] [NormedAddCommGroup F] [InnerProductSpace ℝ E] [InnerProductSpace ℝ F] (f : E →ₗᵢ[ℝ] F) (u v : E) : angle (f u) (f v) = angle u v := by rw [angle, angle, f.inner_map_map, f.norm_map, f.norm_map] #align linear_isometry.angle_map LinearIsometry.angle_map @[simp, norm_cast] theorem _root_.Submodule.angle_coe {s : Submodule ℝ V} (x y : s) : angle (x : V) (y : V) = angle x y := s.subtypeₗᵢ.angle_map x y #align submodule.angle_coe Submodule.angle_coe /-- The cosine of the angle between two vectors. -/ theorem cos_angle (x y : V) : Real.cos (angle x y) = ⟪x, y⟫ / (‖x‖ * ‖y‖) := Real.cos_arccos (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1 (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2 #align inner_product_geometry.cos_angle InnerProductGeometry.cos_angle /-- The angle between two vectors does not depend on their order. -/ theorem angle_comm (x y : V) : angle x y = angle y x := by unfold angle rw [real_inner_comm, mul_comm] #align inner_product_geometry.angle_comm InnerProductGeometry.angle_comm /-- The angle between the negation of two vectors. -/ @[simp] theorem angle_neg_neg (x y : V) : angle (-x) (-y) = angle x y := by unfold angle rw [inner_neg_neg, norm_neg, norm_neg] #align inner_product_geometry.angle_neg_neg InnerProductGeometry.angle_neg_neg /-- The angle between two vectors is nonnegative. -/ theorem angle_nonneg (x y : V) : 0 ≤ angle x y := Real.arccos_nonneg _ #align inner_product_geometry.angle_nonneg InnerProductGeometry.angle_nonneg /-- The angle between two vectors is at most π. -/ theorem angle_le_pi (x y : V) : angle x y ≤ π := Real.arccos_le_pi _ #align inner_product_geometry.angle_le_pi InnerProductGeometry.angle_le_pi /-- The angle between a vector and the negation of another vector. -/ theorem angle_neg_right (x y : V) : angle x (-y) = π - angle x y := by unfold angle rw [← Real.arccos_neg, norm_neg, inner_neg_right, neg_div] #align inner_product_geometry.angle_neg_right InnerProductGeometry.angle_neg_right /-- The angle between the negation of a vector and another vector. -/ theorem angle_neg_left (x y : V) : angle (-x) y = π - angle x y := by rw [← angle_neg_neg, neg_neg, angle_neg_right] #align inner_product_geometry.angle_neg_left InnerProductGeometry.angle_neg_left proof_wanted angle_triangle (x y z : V) : angle x z ≤ angle x y + angle y z /-- The angle between the zero vector and a vector. -/ @[simp] theorem angle_zero_left (x : V) : angle 0 x = π / 2 := by unfold angle rw [inner_zero_left, zero_div, Real.arccos_zero] #align inner_product_geometry.angle_zero_left InnerProductGeometry.angle_zero_left /-- The angle between a vector and the zero vector. -/ @[simp] theorem angle_zero_right (x : V) : angle x 0 = π / 2 := by unfold angle rw [inner_zero_right, zero_div, Real.arccos_zero] #align inner_product_geometry.angle_zero_right InnerProductGeometry.angle_zero_right /-- The angle between a nonzero vector and itself. -/ @[simp] theorem angle_self {x : V} (hx : x ≠ 0) : angle x x = 0 := by unfold angle rw [← real_inner_self_eq_norm_mul_norm, div_self (inner_self_ne_zero.2 hx : ⟪x, x⟫ ≠ 0), Real.arccos_one] #align inner_product_geometry.angle_self InnerProductGeometry.angle_self /-- The angle between a nonzero vector and its negation. -/ @[simp] theorem angle_self_neg_of_nonzero {x : V} (hx : x ≠ 0) : angle x (-x) = π := by rw [angle_neg_right, angle_self hx, sub_zero] #align inner_product_geometry.angle_self_neg_of_nonzero InnerProductGeometry.angle_self_neg_of_nonzero /-- The angle between the negation of a nonzero vector and that vector. -/ @[simp] theorem angle_neg_self_of_nonzero {x : V} (hx : x ≠ 0) : angle (-x) x = π := by rw [angle_comm, angle_self_neg_of_nonzero hx] #align inner_product_geometry.angle_neg_self_of_nonzero InnerProductGeometry.angle_neg_self_of_nonzero /-- The angle between a vector and a positive multiple of a vector. -/ @[simp] theorem angle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : angle x (r • y) = angle x y := by unfold angle rw [inner_smul_right, norm_smul, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hr), ← mul_assoc, mul_comm _ r, mul_assoc, mul_div_mul_left _ _ (ne_of_gt hr)] #align inner_product_geometry.angle_smul_right_of_pos InnerProductGeometry.angle_smul_right_of_pos /-- The angle between a positive multiple of a vector and a vector. -/ @[simp] theorem angle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : angle (r • x) y = angle x y := by rw [angle_comm, angle_smul_right_of_pos y x hr, angle_comm] #align inner_product_geometry.angle_smul_left_of_pos InnerProductGeometry.angle_smul_left_of_pos /-- The angle between a vector and a negative multiple of a vector. -/ @[simp] theorem angle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) : angle x (r • y) = angle x (-y) := by rw [← neg_neg r, neg_smul, angle_neg_right, angle_smul_right_of_pos x y (neg_pos_of_neg hr), angle_neg_right] #align inner_product_geometry.angle_smul_right_of_neg InnerProductGeometry.angle_smul_right_of_neg /-- The angle between a negative multiple of a vector and a vector. -/ @[simp] theorem angle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) : angle (r • x) y = angle (-x) y := by rw [angle_comm, angle_smul_right_of_neg y x hr, angle_comm] #align inner_product_geometry.angle_smul_left_of_neg InnerProductGeometry.angle_smul_left_of_neg /-- The cosine of the angle between two vectors, multiplied by the product of their norms. -/ theorem cos_angle_mul_norm_mul_norm (x y : V) : Real.cos (angle x y) * (‖x‖ * ‖y‖) = ⟪x, y⟫ := by rw [cos_angle, div_mul_cancel_of_imp] simp (config := { contextual := true }) [or_imp] #align inner_product_geometry.cos_angle_mul_norm_mul_norm InnerProductGeometry.cos_angle_mul_norm_mul_norm /-- The sine of the angle between two vectors, multiplied by the product of their norms. -/ theorem sin_angle_mul_norm_mul_norm (x y : V) : Real.sin (angle x y) * (‖x‖ * ‖y‖) = √(⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫) := by unfold angle rw [Real.sin_arccos, ← Real.sqrt_mul_self (mul_nonneg (norm_nonneg x) (norm_nonneg y)), ← Real.sqrt_mul' _ (mul_self_nonneg _), sq, Real.sqrt_mul_self (mul_nonneg (norm_nonneg x) (norm_nonneg y)), real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm] by_cases h : ‖x‖ * ‖y‖ = 0 · rw [show ‖x‖ * ‖x‖ * (‖y‖ * ‖y‖) = ‖x‖ * ‖y‖ * (‖x‖ * ‖y‖) by ring, h, mul_zero, mul_zero, zero_sub] cases' eq_zero_or_eq_zero_of_mul_eq_zero h with hx hy · rw [norm_eq_zero] at hx rw [hx, inner_zero_left, zero_mul, neg_zero] · rw [norm_eq_zero] at hy rw [hy, inner_zero_right, zero_mul, neg_zero] · field_simp [h] ring_nf #align inner_product_geometry.sin_angle_mul_norm_mul_norm InnerProductGeometry.sin_angle_mul_norm_mul_norm /-- The angle between two vectors is zero if and only if they are nonzero and one is a positive multiple of the other. -/ theorem angle_eq_zero_iff {x y : V} : angle x y = 0 ↔ x ≠ 0 ∧ ∃ r : ℝ, 0 < r ∧ y = r • x := by rw [angle, ← real_inner_div_norm_mul_norm_eq_one_iff, Real.arccos_eq_zero, LE.le.le_iff_eq, eq_comm] exact (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2 #align inner_product_geometry.angle_eq_zero_iff InnerProductGeometry.angle_eq_zero_iff /-- The angle between two vectors is π if and only if they are nonzero and one is a negative multiple of the other. -/ theorem angle_eq_pi_iff {x y : V} : angle x y = π ↔ x ≠ 0 ∧ ∃ r : ℝ, r < 0 ∧ y = r • x := by rw [angle, ← real_inner_div_norm_mul_norm_eq_neg_one_iff, Real.arccos_eq_pi, LE.le.le_iff_eq] exact (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1 #align inner_product_geometry.angle_eq_pi_iff InnerProductGeometry.angle_eq_pi_iff /-- If the angle between two vectors is π, the angles between those vectors and a third vector add to π. -/ theorem angle_add_angle_eq_pi_of_angle_eq_pi {x y : V} (z : V) (h : angle x y = π) : angle x z + angle y z = π := by rcases angle_eq_pi_iff.1 h with ⟨_, ⟨r, ⟨hr, rfl⟩⟩⟩ rw [angle_smul_left_of_neg x z hr, angle_neg_left, add_sub_cancel] #align inner_product_geometry.angle_add_angle_eq_pi_of_angle_eq_pi InnerProductGeometry.angle_add_angle_eq_pi_of_angle_eq_pi /-- Two vectors have inner product 0 if and only if the angle between them is π/2. -/ theorem inner_eq_zero_iff_angle_eq_pi_div_two (x y : V) : ⟪x, y⟫ = 0 ↔ angle x y = π / 2 := Iff.symm <| by simp (config := { contextual := true }) [angle, or_imp] #align inner_product_geometry.inner_eq_zero_iff_angle_eq_pi_div_two InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two /-- If the angle between two vectors is π, the inner product equals the negative product of the norms. -/ theorem inner_eq_neg_mul_norm_of_angle_eq_pi {x y : V} (h : angle x y = π) : ⟪x, y⟫ = -(‖x‖ * ‖y‖) := by simp [← cos_angle_mul_norm_mul_norm, h] #align inner_product_geometry.inner_eq_neg_mul_norm_of_angle_eq_pi InnerProductGeometry.inner_eq_neg_mul_norm_of_angle_eq_pi /-- If the angle between two vectors is 0, the inner product equals the product of the norms. -/ theorem inner_eq_mul_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : ⟪x, y⟫ = ‖x‖ * ‖y‖ := by simp [← cos_angle_mul_norm_mul_norm, h] #align inner_product_geometry.inner_eq_mul_norm_of_angle_eq_zero InnerProductGeometry.inner_eq_mul_norm_of_angle_eq_zero /-- The inner product of two non-zero vectors equals the negative product of their norms if and only if the angle between the two vectors is π. -/ theorem inner_eq_neg_mul_norm_iff_angle_eq_pi {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : ⟪x, y⟫ = -(‖x‖ * ‖y‖) ↔ angle x y = π := by refine ⟨fun h => ?_, inner_eq_neg_mul_norm_of_angle_eq_pi⟩ have h₁ : ‖x‖ * ‖y‖ ≠ 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne' rw [angle, h, neg_div, div_self h₁, Real.arccos_neg_one] #align inner_product_geometry.inner_eq_neg_mul_norm_iff_angle_eq_pi InnerProductGeometry.inner_eq_neg_mul_norm_iff_angle_eq_pi /-- The inner product of two non-zero vectors equals the product of their norms if and only if the angle between the two vectors is 0. -/ theorem inner_eq_mul_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : ⟪x, y⟫ = ‖x‖ * ‖y‖ ↔ angle x y = 0 := by refine ⟨fun h => ?_, inner_eq_mul_norm_of_angle_eq_zero⟩ have h₁ : ‖x‖ * ‖y‖ ≠ 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne' rw [angle, h, div_self h₁, Real.arccos_one] #align inner_product_geometry.inner_eq_mul_norm_iff_angle_eq_zero InnerProductGeometry.inner_eq_mul_norm_iff_angle_eq_zero /-- If the angle between two vectors is π, the norm of their difference equals the sum of their norms. -/ theorem norm_sub_eq_add_norm_of_angle_eq_pi {x y : V} (h : angle x y = π) : ‖x - y‖ = ‖x‖ + ‖y‖ := by rw [← sq_eq_sq (norm_nonneg (x - y)) (add_nonneg (norm_nonneg x) (norm_nonneg y)), norm_sub_pow_two_real, inner_eq_neg_mul_norm_of_angle_eq_pi h] ring #align inner_product_geometry.norm_sub_eq_add_norm_of_angle_eq_pi InnerProductGeometry.norm_sub_eq_add_norm_of_angle_eq_pi /-- If the angle between two vectors is 0, the norm of their sum equals the sum of their norms. -/ theorem norm_add_eq_add_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : ‖x + y‖ = ‖x‖ + ‖y‖ := by rw [← sq_eq_sq (norm_nonneg (x + y)) (add_nonneg (norm_nonneg x) (norm_nonneg y)), norm_add_pow_two_real, inner_eq_mul_norm_of_angle_eq_zero h] ring #align inner_product_geometry.norm_add_eq_add_norm_of_angle_eq_zero InnerProductGeometry.norm_add_eq_add_norm_of_angle_eq_zero /-- If the angle between two vectors is 0, the norm of their difference equals the absolute value of the difference of their norms. -/
Mathlib/Geometry/Euclidean/Angle/Unoriented/Basic.lean
288
292
theorem norm_sub_eq_abs_sub_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : ‖x - y‖ = |‖x‖ - ‖y‖| := by
rw [← sq_eq_sq (norm_nonneg (x - y)) (abs_nonneg (‖x‖ - ‖y‖)), norm_sub_pow_two_real, inner_eq_mul_norm_of_angle_eq_zero h, sq_abs (‖x‖ - ‖y‖)] ring
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Rémy Degenne -/ import Mathlib.Probability.Process.Stopping import Mathlib.Tactic.AdaptationNote #align_import probability.process.hitting_time from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Hitting time Given a stochastic process, the hitting time provides the first time the process "hits" some subset of the state space. The hitting time is a stopping time in the case that the time index is discrete and the process is adapted (this is true in a far more general setting however we have only proved it for the discrete case so far). ## Main definition * `MeasureTheory.hitting`: the hitting time of a stochastic process ## Main results * `MeasureTheory.hitting_isStoppingTime`: a discrete hitting time of an adapted process is a stopping time ## Implementation notes In the definition of the hitting time, we bound the hitting time by an upper and lower bound. This is to ensure that our result is meaningful in the case we are taking the infimum of an empty set or the infimum of a set which is unbounded from below. With this, we can talk about hitting times indexed by the natural numbers or the reals. By taking the bounds to be `⊤` and `⊥`, we obtain the standard definition in the case that the index is `ℕ∞` or `ℝ≥0∞`. -/ open Filter Order TopologicalSpace open scoped Classical MeasureTheory NNReal ENNReal Topology namespace MeasureTheory variable {Ω β ι : Type*} {m : MeasurableSpace Ω} /-- Hitting time: given a stochastic process `u` and a set `s`, `hitting u s n m` is the first time `u` is in `s` after time `n` and before time `m` (if `u` does not hit `s` after time `n` and before `m` then the hitting time is simply `m`). The hitting time is a stopping time if the process is adapted and discrete. -/ noncomputable def hitting [Preorder ι] [InfSet ι] (u : ι → Ω → β) (s : Set β) (n m : ι) : Ω → ι := fun x => if ∃ j ∈ Set.Icc n m, u j x ∈ s then sInf (Set.Icc n m ∩ {i : ι | u i x ∈ s}) else m #align measure_theory.hitting MeasureTheory.hitting #adaptation_note /-- nightly-2024-03-16: added to replace simp [hitting] -/ theorem hitting_def [Preorder ι] [InfSet ι] (u : ι → Ω → β) (s : Set β) (n m : ι) : hitting u s n m = fun x => if ∃ j ∈ Set.Icc n m, u j x ∈ s then sInf (Set.Icc n m ∩ {i : ι | u i x ∈ s}) else m := rfl section Inequalities variable [ConditionallyCompleteLinearOrder ι] {u : ι → Ω → β} {s : Set β} {n i : ι} {ω : Ω} /-- This lemma is strictly weaker than `hitting_of_le`. -/ theorem hitting_of_lt {m : ι} (h : m < n) : hitting u s n m ω = m := by simp_rw [hitting] have h_not : ¬∃ (j : ι) (_ : j ∈ Set.Icc n m), u j ω ∈ s := by push_neg intro j rw [Set.Icc_eq_empty_of_lt h] simp only [Set.mem_empty_iff_false, IsEmpty.forall_iff] simp only [exists_prop] at h_not simp only [h_not, if_false] #align measure_theory.hitting_of_lt MeasureTheory.hitting_of_lt theorem hitting_le {m : ι} (ω : Ω) : hitting u s n m ω ≤ m := by simp only [hitting] split_ifs with h · obtain ⟨j, hj₁, hj₂⟩ := h change j ∈ {i | u i ω ∈ s} at hj₂ exact (csInf_le (BddBelow.inter_of_left bddBelow_Icc) (Set.mem_inter hj₁ hj₂)).trans hj₁.2 · exact le_rfl #align measure_theory.hitting_le MeasureTheory.hitting_le theorem not_mem_of_lt_hitting {m k : ι} (hk₁ : k < hitting u s n m ω) (hk₂ : n ≤ k) : u k ω ∉ s := by classical intro h have hexists : ∃ j ∈ Set.Icc n m, u j ω ∈ s := ⟨k, ⟨hk₂, le_trans hk₁.le <| hitting_le _⟩, h⟩ refine not_le.2 hk₁ ?_ simp_rw [hitting, if_pos hexists] exact csInf_le bddBelow_Icc.inter_of_left ⟨⟨hk₂, le_trans hk₁.le <| hitting_le _⟩, h⟩ #align measure_theory.not_mem_of_lt_hitting MeasureTheory.not_mem_of_lt_hitting theorem hitting_eq_end_iff {m : ι} : hitting u s n m ω = m ↔ (∃ j ∈ Set.Icc n m, u j ω ∈ s) → sInf (Set.Icc n m ∩ {i : ι | u i ω ∈ s}) = m := by rw [hitting, ite_eq_right_iff] #align measure_theory.hitting_eq_end_iff MeasureTheory.hitting_eq_end_iff theorem hitting_of_le {m : ι} (hmn : m ≤ n) : hitting u s n m ω = m := by obtain rfl | h := le_iff_eq_or_lt.1 hmn · rw [hitting, ite_eq_right_iff, forall_exists_index] conv => intro; rw [Set.mem_Icc, Set.Icc_self, and_imp, and_imp] intro i hi₁ hi₂ hi rw [Set.inter_eq_left.2, csInf_singleton] exact Set.singleton_subset_iff.2 (le_antisymm hi₂ hi₁ ▸ hi) · exact hitting_of_lt h #align measure_theory.hitting_of_le MeasureTheory.hitting_of_le theorem le_hitting {m : ι} (hnm : n ≤ m) (ω : Ω) : n ≤ hitting u s n m ω := by simp only [hitting] split_ifs with h · refine le_csInf ?_ fun b hb => ?_ · obtain ⟨k, hk_Icc, hk_s⟩ := h exact ⟨k, hk_Icc, hk_s⟩ · rw [Set.mem_inter_iff] at hb exact hb.1.1 · exact hnm #align measure_theory.le_hitting MeasureTheory.le_hitting theorem le_hitting_of_exists {m : ι} (h_exists : ∃ j ∈ Set.Icc n m, u j ω ∈ s) : n ≤ hitting u s n m ω := by refine le_hitting ?_ ω by_contra h rw [Set.Icc_eq_empty_of_lt (not_le.mp h)] at h_exists simp at h_exists #align measure_theory.le_hitting_of_exists MeasureTheory.le_hitting_of_exists theorem hitting_mem_Icc {m : ι} (hnm : n ≤ m) (ω : Ω) : hitting u s n m ω ∈ Set.Icc n m := ⟨le_hitting hnm ω, hitting_le ω⟩ #align measure_theory.hitting_mem_Icc MeasureTheory.hitting_mem_Icc theorem hitting_mem_set [IsWellOrder ι (· < ·)] {m : ι} (h_exists : ∃ j ∈ Set.Icc n m, u j ω ∈ s) : u (hitting u s n m ω) ω ∈ s := by simp_rw [hitting, if_pos h_exists] have h_nonempty : (Set.Icc n m ∩ {i : ι | u i ω ∈ s}).Nonempty := by obtain ⟨k, hk₁, hk₂⟩ := h_exists exact ⟨k, Set.mem_inter hk₁ hk₂⟩ have h_mem := csInf_mem h_nonempty rw [Set.mem_inter_iff] at h_mem exact h_mem.2 #align measure_theory.hitting_mem_set MeasureTheory.hitting_mem_set theorem hitting_mem_set_of_hitting_lt [IsWellOrder ι (· < ·)] {m : ι} (hl : hitting u s n m ω < m) : u (hitting u s n m ω) ω ∈ s := by by_cases h : ∃ j ∈ Set.Icc n m, u j ω ∈ s · exact hitting_mem_set h · simp_rw [hitting, if_neg h] at hl exact False.elim (hl.ne rfl) #align measure_theory.hitting_mem_set_of_hitting_lt MeasureTheory.hitting_mem_set_of_hitting_lt theorem hitting_le_of_mem {m : ι} (hin : n ≤ i) (him : i ≤ m) (his : u i ω ∈ s) : hitting u s n m ω ≤ i := by have h_exists : ∃ k ∈ Set.Icc n m, u k ω ∈ s := ⟨i, ⟨hin, him⟩, his⟩ simp_rw [hitting, if_pos h_exists] exact csInf_le (BddBelow.inter_of_left bddBelow_Icc) (Set.mem_inter ⟨hin, him⟩ his) #align measure_theory.hitting_le_of_mem MeasureTheory.hitting_le_of_mem
Mathlib/Probability/Process/HittingTime.lean
161
173
theorem hitting_le_iff_of_exists [IsWellOrder ι (· < ·)] {m : ι} (h_exists : ∃ j ∈ Set.Icc n m, u j ω ∈ s) : hitting u s n m ω ≤ i ↔ ∃ j ∈ Set.Icc n i, u j ω ∈ s := by
constructor <;> intro h' · exact ⟨hitting u s n m ω, ⟨le_hitting_of_exists h_exists, h'⟩, hitting_mem_set h_exists⟩ · have h'' : ∃ k ∈ Set.Icc n (min m i), u k ω ∈ s := by obtain ⟨k₁, hk₁_mem, hk₁_s⟩ := h_exists obtain ⟨k₂, hk₂_mem, hk₂_s⟩ := h' refine ⟨min k₁ k₂, ⟨le_min hk₁_mem.1 hk₂_mem.1, min_le_min hk₁_mem.2 hk₂_mem.2⟩, ?_⟩ exact min_rec' (fun j => u j ω ∈ s) hk₁_s hk₂_s obtain ⟨k, hk₁, hk₂⟩ := h'' refine le_trans ?_ (hk₁.2.trans (min_le_right _ _)) exact hitting_le_of_mem hk₁.1 (hk₁.2.trans (min_le_left _ _)) hk₂
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Data.Finset.Attr import Mathlib.Data.Multiset.FinsetOps import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Basic #align_import data.finset.basic from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Finite sets Terms of type `Finset α` are one way of talking about finite subsets of `α` in mathlib. Below, `Finset α` is defined as a structure with 2 fields: 1. `val` is a `Multiset α` of elements; 2. `nodup` is a proof that `val` has no duplicates. Finsets in Lean are constructive in that they have an underlying `List` that enumerates their elements. In particular, any function that uses the data of the underlying list cannot depend on its ordering. This is handled on the `Multiset` level by multiset API, so in most cases one needn't worry about it explicitly. Finsets give a basic foundation for defining finite sums and products over types: 1. `∑ i ∈ (s : Finset α), f i`; 2. `∏ i ∈ (s : Finset α), f i`. Lean refers to these operations as big operators. More information can be found in `Mathlib.Algebra.BigOperators.Group.Finset`. Finsets are directly used to define fintypes in Lean. A `Fintype α` instance for a type `α` consists of a universal `Finset α` containing every term of `α`, called `univ`. See `Mathlib.Data.Fintype.Basic`. There is also `univ'`, the noncomputable partner to `univ`, which is defined to be `α` as a finset if `α` is finite, and the empty finset otherwise. See `Mathlib.Data.Fintype.Basic`. `Finset.card`, the size of a finset is defined in `Mathlib.Data.Finset.Card`. This is then used to define `Fintype.card`, the size of a type. ## Main declarations ### Main definitions * `Finset`: Defines a type for the finite subsets of `α`. Constructing a `Finset` requires two pieces of data: `val`, a `Multiset α` of elements, and `nodup`, a proof that `val` has no duplicates. * `Finset.instMembershipFinset`: Defines membership `a ∈ (s : Finset α)`. * `Finset.instCoeTCFinsetSet`: Provides a coercion `s : Finset α` to `s : Set α`. * `Finset.instCoeSortFinsetType`: Coerce `s : Finset α` to the type of all `x ∈ s`. * `Finset.induction_on`: Induction on finsets. To prove a proposition about an arbitrary `Finset α`, it suffices to prove it for the empty finset, and to show that if it holds for some `Finset α`, then it holds for the finset obtained by inserting a new element. * `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate. ### Finset constructions * `Finset.instSingletonFinset`: Denoted by `{a}`; the finset consisting of one element. * `Finset.empty`: Denoted by `∅`. The finset associated to any type consisting of no elements. * `Finset.range`: For any `n : ℕ`, `range n` is equal to `{0, 1, ... , n - 1} ⊆ ℕ`. This convention is consistent with other languages and normalizes `card (range n) = n`. Beware, `n` is not in `range n`. * `Finset.attach`: Given `s : Finset α`, `attach s` forms a finset of elements of the subtype `{a // a ∈ s}`; in other words, it attaches elements to a proof of membership in the set. ### Finsets from functions * `Finset.filter`: Given a decidable predicate `p : α → Prop`, `s.filter p` is the finset consisting of those elements in `s` satisfying the predicate `p`. ### The lattice structure on subsets of finsets There is a natural lattice structure on the subsets of a set. In Lean, we use lattice notation to talk about things involving unions and intersections. See `Mathlib.Order.Lattice`. For the lattice structure on finsets, `⊥` is called `bot` with `⊥ = ∅` and `⊤` is called `top` with `⊤ = univ`. * `Finset.instHasSubsetFinset`: Lots of API about lattices, otherwise behaves as one would expect. * `Finset.instUnionFinset`: Defines `s ∪ t` (or `s ⊔ t`) as the union of `s` and `t`. See `Finset.sup`/`Finset.biUnion` for finite unions. * `Finset.instInterFinset`: Defines `s ∩ t` (or `s ⊓ t`) as the intersection of `s` and `t`. See `Finset.inf` for finite intersections. ### Operations on two or more finsets * `insert` and `Finset.cons`: For any `a : α`, `insert s a` returns `s ∪ {a}`. `cons s a h` returns the same except that it requires a hypothesis stating that `a` is not already in `s`. This does not require decidable equality on the type `α`. * `Finset.instUnionFinset`: see "The lattice structure on subsets of finsets" * `Finset.instInterFinset`: see "The lattice structure on subsets of finsets" * `Finset.erase`: For any `a : α`, `erase s a` returns `s` with the element `a` removed. * `Finset.instSDiffFinset`: Defines the set difference `s \ t` for finsets `s` and `t`. * `Finset.product`: Given finsets of `α` and `β`, defines finsets of `α × β`. For arbitrary dependent products, see `Mathlib.Data.Finset.Pi`. ### Predicates on finsets * `Disjoint`: defined via the lattice structure on finsets; two sets are disjoint if their intersection is empty. * `Finset.Nonempty`: A finset is nonempty if it has elements. This is equivalent to saying `s ≠ ∅`. ### Equivalences between finsets * The `Mathlib.Data.Equiv` files describe a general type of equivalence, so look in there for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`. TODO: examples ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen assert_not_exists Multiset.Powerset assert_not_exists CompleteLattice open Multiset Subtype Nat Function universe u variable {α : Type*} {β : Type*} {γ : Type*} /-- `Finset α` is the type of finite sets of elements of `α`. It is implemented as a multiset (a list up to permutation) which has no duplicate elements. -/ structure Finset (α : Type*) where /-- The underlying multiset -/ val : Multiset α /-- `val` contains no duplicates -/ nodup : Nodup val #align finset Finset instance Multiset.canLiftFinset {α} : CanLift (Multiset α) (Finset α) Finset.val Multiset.Nodup := ⟨fun m hm => ⟨⟨m, hm⟩, rfl⟩⟩ #align multiset.can_lift_finset Multiset.canLiftFinset namespace Finset theorem eq_of_veq : ∀ {s t : Finset α}, s.1 = t.1 → s = t | ⟨s, _⟩, ⟨t, _⟩, h => by cases h; rfl #align finset.eq_of_veq Finset.eq_of_veq theorem val_injective : Injective (val : Finset α → Multiset α) := fun _ _ => eq_of_veq #align finset.val_injective Finset.val_injective @[simp] theorem val_inj {s t : Finset α} : s.1 = t.1 ↔ s = t := val_injective.eq_iff #align finset.val_inj Finset.val_inj @[simp] theorem dedup_eq_self [DecidableEq α] (s : Finset α) : dedup s.1 = s.1 := s.2.dedup #align finset.dedup_eq_self Finset.dedup_eq_self instance decidableEq [DecidableEq α] : DecidableEq (Finset α) | _, _ => decidable_of_iff _ val_inj #align finset.has_decidable_eq Finset.decidableEq /-! ### membership -/ instance : Membership α (Finset α) := ⟨fun a s => a ∈ s.1⟩ theorem mem_def {a : α} {s : Finset α} : a ∈ s ↔ a ∈ s.1 := Iff.rfl #align finset.mem_def Finset.mem_def @[simp] theorem mem_val {a : α} {s : Finset α} : a ∈ s.1 ↔ a ∈ s := Iff.rfl #align finset.mem_val Finset.mem_val @[simp] theorem mem_mk {a : α} {s nd} : a ∈ @Finset.mk α s nd ↔ a ∈ s := Iff.rfl #align finset.mem_mk Finset.mem_mk instance decidableMem [_h : DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ s) := Multiset.decidableMem _ _ #align finset.decidable_mem Finset.decidableMem @[simp] lemma forall_mem_not_eq {s : Finset α} {a : α} : (∀ b ∈ s, ¬ a = b) ↔ a ∉ s := by aesop @[simp] lemma forall_mem_not_eq' {s : Finset α} {a : α} : (∀ b ∈ s, ¬ b = a) ↔ a ∉ s := by aesop /-! ### set coercion -/ -- Porting note (#11445): new definition /-- Convert a finset to a set in the natural way. -/ @[coe] def toSet (s : Finset α) : Set α := { a | a ∈ s } /-- Convert a finset to a set in the natural way. -/ instance : CoeTC (Finset α) (Set α) := ⟨toSet⟩ @[simp, norm_cast] theorem mem_coe {a : α} {s : Finset α} : a ∈ (s : Set α) ↔ a ∈ (s : Finset α) := Iff.rfl #align finset.mem_coe Finset.mem_coe @[simp] theorem setOf_mem {α} {s : Finset α} : { a | a ∈ s } = s := rfl #align finset.set_of_mem Finset.setOf_mem @[simp] theorem coe_mem {s : Finset α} (x : (s : Set α)) : ↑x ∈ s := x.2 #align finset.coe_mem Finset.coe_mem -- Porting note (#10618): @[simp] can prove this theorem mk_coe {s : Finset α} (x : (s : Set α)) {h} : (⟨x, h⟩ : (s : Set α)) = x := Subtype.coe_eta _ _ #align finset.mk_coe Finset.mk_coe instance decidableMem' [DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ (s : Set α)) := s.decidableMem _ #align finset.decidable_mem' Finset.decidableMem' /-! ### extensionality -/ theorem ext_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ ∀ a, a ∈ s₁ ↔ a ∈ s₂ := val_inj.symm.trans <| s₁.nodup.ext s₂.nodup #align finset.ext_iff Finset.ext_iff @[ext] theorem ext {s₁ s₂ : Finset α} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ := ext_iff.2 #align finset.ext Finset.ext @[simp, norm_cast] theorem coe_inj {s₁ s₂ : Finset α} : (s₁ : Set α) = s₂ ↔ s₁ = s₂ := Set.ext_iff.trans ext_iff.symm #align finset.coe_inj Finset.coe_inj theorem coe_injective {α} : Injective ((↑) : Finset α → Set α) := fun _s _t => coe_inj.1 #align finset.coe_injective Finset.coe_injective /-! ### type coercion -/ /-- Coercion from a finset to the corresponding subtype. -/ instance {α : Type u} : CoeSort (Finset α) (Type u) := ⟨fun s => { x // x ∈ s }⟩ -- Porting note (#10618): @[simp] can prove this protected theorem forall_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∀ x : s, p x) ↔ ∀ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align finset.forall_coe Finset.forall_coe -- Porting note (#10618): @[simp] can prove this protected theorem exists_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∃ x : s, p x) ↔ ∃ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align finset.exists_coe Finset.exists_coe instance PiFinsetCoe.canLift (ι : Type*) (α : ι → Type*) [_ne : ∀ i, Nonempty (α i)] (s : Finset ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α (· ∈ s) #align finset.pi_finset_coe.can_lift Finset.PiFinsetCoe.canLift instance PiFinsetCoe.canLift' (ι α : Type*) [_ne : Nonempty α] (s : Finset ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiFinsetCoe.canLift ι (fun _ => α) s #align finset.pi_finset_coe.can_lift' Finset.PiFinsetCoe.canLift' instance FinsetCoe.canLift (s : Finset α) : CanLift α s (↑) fun a => a ∈ s where prf a ha := ⟨⟨a, ha⟩, rfl⟩ #align finset.finset_coe.can_lift Finset.FinsetCoe.canLift @[simp, norm_cast] theorem coe_sort_coe (s : Finset α) : ((s : Set α) : Sort _) = s := rfl #align finset.coe_sort_coe Finset.coe_sort_coe /-! ### Subset and strict subset relations -/ section Subset variable {s t : Finset α} instance : HasSubset (Finset α) := ⟨fun s t => ∀ ⦃a⦄, a ∈ s → a ∈ t⟩ instance : HasSSubset (Finset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance partialOrder : PartialOrder (Finset α) where le := (· ⊆ ·) lt := (· ⊂ ·) le_refl s a := id le_trans s t u hst htu a ha := htu <| hst ha le_antisymm s t hst hts := ext fun a => ⟨@hst _, @hts _⟩ instance : IsRefl (Finset α) (· ⊆ ·) := show IsRefl (Finset α) (· ≤ ·) by infer_instance instance : IsTrans (Finset α) (· ⊆ ·) := show IsTrans (Finset α) (· ≤ ·) by infer_instance instance : IsAntisymm (Finset α) (· ⊆ ·) := show IsAntisymm (Finset α) (· ≤ ·) by infer_instance instance : IsIrrefl (Finset α) (· ⊂ ·) := show IsIrrefl (Finset α) (· < ·) by infer_instance instance : IsTrans (Finset α) (· ⊂ ·) := show IsTrans (Finset α) (· < ·) by infer_instance instance : IsAsymm (Finset α) (· ⊂ ·) := show IsAsymm (Finset α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Finset α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ theorem subset_def : s ⊆ t ↔ s.1 ⊆ t.1 := Iff.rfl #align finset.subset_def Finset.subset_def theorem ssubset_def : s ⊂ t ↔ s ⊆ t ∧ ¬t ⊆ s := Iff.rfl #align finset.ssubset_def Finset.ssubset_def @[simp] theorem Subset.refl (s : Finset α) : s ⊆ s := Multiset.Subset.refl _ #align finset.subset.refl Finset.Subset.refl protected theorem Subset.rfl {s : Finset α} : s ⊆ s := Subset.refl _ #align finset.subset.rfl Finset.Subset.rfl protected theorem subset_of_eq {s t : Finset α} (h : s = t) : s ⊆ t := h ▸ Subset.refl _ #align finset.subset_of_eq Finset.subset_of_eq theorem Subset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ := Multiset.Subset.trans #align finset.subset.trans Finset.Subset.trans theorem Superset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ := fun h' h => Subset.trans h h' #align finset.superset.trans Finset.Superset.trans theorem mem_of_subset {s₁ s₂ : Finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := Multiset.mem_of_subset #align finset.mem_of_subset Finset.mem_of_subset theorem not_mem_mono {s t : Finset α} (h : s ⊆ t) {a : α} : a ∉ t → a ∉ s := mt <| @h _ #align finset.not_mem_mono Finset.not_mem_mono theorem Subset.antisymm {s₁ s₂ : Finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ := ext fun a => ⟨@H₁ a, @H₂ a⟩ #align finset.subset.antisymm Finset.Subset.antisymm theorem subset_iff {s₁ s₂ : Finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ := Iff.rfl #align finset.subset_iff Finset.subset_iff @[simp, norm_cast] theorem coe_subset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊆ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.coe_subset Finset.coe_subset @[simp] theorem val_le_iff {s₁ s₂ : Finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ := le_iff_subset s₁.2 #align finset.val_le_iff Finset.val_le_iff theorem Subset.antisymm_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ := le_antisymm_iff #align finset.subset.antisymm_iff Finset.Subset.antisymm_iff theorem not_subset : ¬s ⊆ t ↔ ∃ x ∈ s, x ∉ t := by simp only [← coe_subset, Set.not_subset, mem_coe] #align finset.not_subset Finset.not_subset @[simp] theorem le_eq_subset : ((· ≤ ·) : Finset α → Finset α → Prop) = (· ⊆ ·) := rfl #align finset.le_eq_subset Finset.le_eq_subset @[simp] theorem lt_eq_subset : ((· < ·) : Finset α → Finset α → Prop) = (· ⊂ ·) := rfl #align finset.lt_eq_subset Finset.lt_eq_subset theorem le_iff_subset {s₁ s₂ : Finset α} : s₁ ≤ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.le_iff_subset Finset.le_iff_subset theorem lt_iff_ssubset {s₁ s₂ : Finset α} : s₁ < s₂ ↔ s₁ ⊂ s₂ := Iff.rfl #align finset.lt_iff_ssubset Finset.lt_iff_ssubset @[simp, norm_cast] theorem coe_ssubset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊂ s₂ := show (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊆ s₂ ∧ ¬s₂ ⊆ s₁ by simp only [Set.ssubset_def, Finset.coe_subset] #align finset.coe_ssubset Finset.coe_ssubset @[simp] theorem val_lt_iff {s₁ s₂ : Finset α} : s₁.1 < s₂.1 ↔ s₁ ⊂ s₂ := and_congr val_le_iff <| not_congr val_le_iff #align finset.val_lt_iff Finset.val_lt_iff lemma val_strictMono : StrictMono (val : Finset α → Multiset α) := fun _ _ ↦ val_lt_iff.2 theorem ssubset_iff_subset_ne {s t : Finset α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne _ _ s t #align finset.ssubset_iff_subset_ne Finset.ssubset_iff_subset_ne theorem ssubset_iff_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁ ⊂ s₂ ↔ ∃ x ∈ s₂, x ∉ s₁ := Set.ssubset_iff_of_subset h #align finset.ssubset_iff_of_subset Finset.ssubset_iff_of_subset theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_ssubset_of_subset hs₁s₂ hs₂s₃ #align finset.ssubset_of_ssubset_of_subset Finset.ssubset_of_ssubset_of_subset theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_subset_of_ssubset hs₁s₂ hs₂s₃ #align finset.ssubset_of_subset_of_ssubset Finset.ssubset_of_subset_of_ssubset theorem exists_of_ssubset {s₁ s₂ : Finset α} (h : s₁ ⊂ s₂) : ∃ x ∈ s₂, x ∉ s₁ := Set.exists_of_ssubset h #align finset.exists_of_ssubset Finset.exists_of_ssubset instance isWellFounded_ssubset : IsWellFounded (Finset α) (· ⊂ ·) := Subrelation.isWellFounded (InvImage _ _) val_lt_iff.2 #align finset.is_well_founded_ssubset Finset.isWellFounded_ssubset instance wellFoundedLT : WellFoundedLT (Finset α) := Finset.isWellFounded_ssubset #align finset.is_well_founded_lt Finset.wellFoundedLT end Subset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans /-! ### Order embedding from `Finset α` to `Set α` -/ /-- Coercion to `Set α` as an `OrderEmbedding`. -/ def coeEmb : Finset α ↪o Set α := ⟨⟨(↑), coe_injective⟩, coe_subset⟩ #align finset.coe_emb Finset.coeEmb @[simp] theorem coe_coeEmb : ⇑(coeEmb : Finset α ↪o Set α) = ((↑) : Finset α → Set α) := rfl #align finset.coe_coe_emb Finset.coe_coeEmb /-! ### Nonempty -/ /-- The property `s.Nonempty` expresses the fact that the finset `s` is not empty. It should be used in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks to the dot notation. -/ protected def Nonempty (s : Finset α) : Prop := ∃ x : α, x ∈ s #align finset.nonempty Finset.Nonempty -- Porting note: Much longer than in Lean3 instance decidableNonempty {s : Finset α} : Decidable s.Nonempty := Quotient.recOnSubsingleton (motive := fun s : Multiset α => Decidable (∃ a, a ∈ s)) s.1 (fun l : List α => match l with | [] => isFalse <| by simp | a::l => isTrue ⟨a, by simp⟩) #align finset.decidable_nonempty Finset.decidableNonempty @[simp, norm_cast] theorem coe_nonempty {s : Finset α} : (s : Set α).Nonempty ↔ s.Nonempty := Iff.rfl #align finset.coe_nonempty Finset.coe_nonempty -- Porting note: Left-hand side simplifies @[simp] theorem nonempty_coe_sort {s : Finset α} : Nonempty (s : Type _) ↔ s.Nonempty := nonempty_subtype #align finset.nonempty_coe_sort Finset.nonempty_coe_sort alias ⟨_, Nonempty.to_set⟩ := coe_nonempty #align finset.nonempty.to_set Finset.Nonempty.to_set alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort #align finset.nonempty.coe_sort Finset.Nonempty.coe_sort theorem Nonempty.exists_mem {s : Finset α} (h : s.Nonempty) : ∃ x : α, x ∈ s := h #align finset.nonempty.bex Finset.Nonempty.exists_mem @[deprecated (since := "2024-03-23")] alias Nonempty.bex := Nonempty.exists_mem theorem Nonempty.mono {s t : Finset α} (hst : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := Set.Nonempty.mono hst hs #align finset.nonempty.mono Finset.Nonempty.mono theorem Nonempty.forall_const {s : Finset α} (h : s.Nonempty) {p : Prop} : (∀ x ∈ s, p) ↔ p := let ⟨x, hx⟩ := h ⟨fun h => h x hx, fun h _ _ => h⟩ #align finset.nonempty.forall_const Finset.Nonempty.forall_const theorem Nonempty.to_subtype {s : Finset α} : s.Nonempty → Nonempty s := nonempty_coe_sort.2 #align finset.nonempty.to_subtype Finset.Nonempty.to_subtype theorem Nonempty.to_type {s : Finset α} : s.Nonempty → Nonempty α := fun ⟨x, _hx⟩ => ⟨x⟩ #align finset.nonempty.to_type Finset.Nonempty.to_type /-! ### empty -/ section Empty variable {s : Finset α} /-- The empty finset -/ protected def empty : Finset α := ⟨0, nodup_zero⟩ #align finset.empty Finset.empty instance : EmptyCollection (Finset α) := ⟨Finset.empty⟩ instance inhabitedFinset : Inhabited (Finset α) := ⟨∅⟩ #align finset.inhabited_finset Finset.inhabitedFinset @[simp] theorem empty_val : (∅ : Finset α).1 = 0 := rfl #align finset.empty_val Finset.empty_val @[simp] theorem not_mem_empty (a : α) : a ∉ (∅ : Finset α) := by -- Porting note: was `id`. `a ∈ List.nil` is no longer definitionally equal to `False` simp only [mem_def, empty_val, not_mem_zero, not_false_iff] #align finset.not_mem_empty Finset.not_mem_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Finset α).Nonempty := fun ⟨x, hx⟩ => not_mem_empty x hx #align finset.not_nonempty_empty Finset.not_nonempty_empty @[simp] theorem mk_zero : (⟨0, nodup_zero⟩ : Finset α) = ∅ := rfl #align finset.mk_zero Finset.mk_zero theorem ne_empty_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ≠ ∅ := fun e => not_mem_empty a <| e ▸ h #align finset.ne_empty_of_mem Finset.ne_empty_of_mem theorem Nonempty.ne_empty {s : Finset α} (h : s.Nonempty) : s ≠ ∅ := (Exists.elim h) fun _a => ne_empty_of_mem #align finset.nonempty.ne_empty Finset.Nonempty.ne_empty @[simp] theorem empty_subset (s : Finset α) : ∅ ⊆ s := zero_subset _ #align finset.empty_subset Finset.empty_subset theorem eq_empty_of_forall_not_mem {s : Finset α} (H : ∀ x, x ∉ s) : s = ∅ := eq_of_veq (eq_zero_of_forall_not_mem H) #align finset.eq_empty_of_forall_not_mem Finset.eq_empty_of_forall_not_mem theorem eq_empty_iff_forall_not_mem {s : Finset α} : s = ∅ ↔ ∀ x, x ∉ s := -- Porting note: used `id` ⟨by rintro rfl x; apply not_mem_empty, fun h => eq_empty_of_forall_not_mem h⟩ #align finset.eq_empty_iff_forall_not_mem Finset.eq_empty_iff_forall_not_mem @[simp] theorem val_eq_zero {s : Finset α} : s.1 = 0 ↔ s = ∅ := @val_inj _ s ∅ #align finset.val_eq_zero Finset.val_eq_zero theorem subset_empty {s : Finset α} : s ⊆ ∅ ↔ s = ∅ := subset_zero.trans val_eq_zero #align finset.subset_empty Finset.subset_empty @[simp] theorem not_ssubset_empty (s : Finset α) : ¬s ⊂ ∅ := fun h => let ⟨_, he, _⟩ := exists_of_ssubset h -- Porting note: was `he` not_mem_empty _ he #align finset.not_ssubset_empty Finset.not_ssubset_empty theorem nonempty_of_ne_empty {s : Finset α} (h : s ≠ ∅) : s.Nonempty := exists_mem_of_ne_zero (mt val_eq_zero.1 h) #align finset.nonempty_of_ne_empty Finset.nonempty_of_ne_empty theorem nonempty_iff_ne_empty {s : Finset α} : s.Nonempty ↔ s ≠ ∅ := ⟨Nonempty.ne_empty, nonempty_of_ne_empty⟩ #align finset.nonempty_iff_ne_empty Finset.nonempty_iff_ne_empty @[simp] theorem not_nonempty_iff_eq_empty {s : Finset α} : ¬s.Nonempty ↔ s = ∅ := nonempty_iff_ne_empty.not.trans not_not #align finset.not_nonempty_iff_eq_empty Finset.not_nonempty_iff_eq_empty theorem eq_empty_or_nonempty (s : Finset α) : s = ∅ ∨ s.Nonempty := by_cases Or.inl fun h => Or.inr (nonempty_of_ne_empty h) #align finset.eq_empty_or_nonempty Finset.eq_empty_or_nonempty @[simp, norm_cast] theorem coe_empty : ((∅ : Finset α) : Set α) = ∅ := Set.ext <| by simp #align finset.coe_empty Finset.coe_empty @[simp, norm_cast] theorem coe_eq_empty {s : Finset α} : (s : Set α) = ∅ ↔ s = ∅ := by rw [← coe_empty, coe_inj] #align finset.coe_eq_empty Finset.coe_eq_empty -- Porting note: Left-hand side simplifies @[simp] theorem isEmpty_coe_sort {s : Finset α} : IsEmpty (s : Type _) ↔ s = ∅ := by simpa using @Set.isEmpty_coe_sort α s #align finset.is_empty_coe_sort Finset.isEmpty_coe_sort instance instIsEmpty : IsEmpty (∅ : Finset α) := isEmpty_coe_sort.2 rfl /-- A `Finset` for an empty type is empty. -/ theorem eq_empty_of_isEmpty [IsEmpty α] (s : Finset α) : s = ∅ := Finset.eq_empty_of_forall_not_mem isEmptyElim #align finset.eq_empty_of_is_empty Finset.eq_empty_of_isEmpty instance : OrderBot (Finset α) where bot := ∅ bot_le := empty_subset @[simp] theorem bot_eq_empty : (⊥ : Finset α) = ∅ := rfl #align finset.bot_eq_empty Finset.bot_eq_empty @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Finset α) _ _ _).trans nonempty_iff_ne_empty.symm #align finset.empty_ssubset Finset.empty_ssubset alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset #align finset.nonempty.empty_ssubset Finset.Nonempty.empty_ssubset end Empty /-! ### singleton -/ section Singleton variable {s : Finset α} {a b : α} /-- `{a} : Finset a` is the set `{a}` containing `a` and nothing else. This differs from `insert a ∅` in that it does not require a `DecidableEq` instance for `α`. -/ instance : Singleton α (Finset α) := ⟨fun a => ⟨{a}, nodup_singleton a⟩⟩ @[simp] theorem singleton_val (a : α) : ({a} : Finset α).1 = {a} := rfl #align finset.singleton_val Finset.singleton_val @[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : Finset α) ↔ b = a := Multiset.mem_singleton #align finset.mem_singleton Finset.mem_singleton theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Finset α)) : x = y := mem_singleton.1 h #align finset.eq_of_mem_singleton Finset.eq_of_mem_singleton theorem not_mem_singleton {a b : α} : a ∉ ({b} : Finset α) ↔ a ≠ b := not_congr mem_singleton #align finset.not_mem_singleton Finset.not_mem_singleton theorem mem_singleton_self (a : α) : a ∈ ({a} : Finset α) := -- Porting note: was `Or.inl rfl` mem_singleton.mpr rfl #align finset.mem_singleton_self Finset.mem_singleton_self @[simp] theorem val_eq_singleton_iff {a : α} {s : Finset α} : s.val = {a} ↔ s = {a} := by rw [← val_inj] rfl #align finset.val_eq_singleton_iff Finset.val_eq_singleton_iff theorem singleton_injective : Injective (singleton : α → Finset α) := fun _a _b h => mem_singleton.1 (h ▸ mem_singleton_self _) #align finset.singleton_injective Finset.singleton_injective @[simp] theorem singleton_inj : ({a} : Finset α) = {b} ↔ a = b := singleton_injective.eq_iff #align finset.singleton_inj Finset.singleton_inj @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem singleton_nonempty (a : α) : ({a} : Finset α).Nonempty := ⟨a, mem_singleton_self a⟩ #align finset.singleton_nonempty Finset.singleton_nonempty @[simp] theorem singleton_ne_empty (a : α) : ({a} : Finset α) ≠ ∅ := (singleton_nonempty a).ne_empty #align finset.singleton_ne_empty Finset.singleton_ne_empty theorem empty_ssubset_singleton : (∅ : Finset α) ⊂ {a} := (singleton_nonempty _).empty_ssubset #align finset.empty_ssubset_singleton Finset.empty_ssubset_singleton @[simp, norm_cast] theorem coe_singleton (a : α) : (({a} : Finset α) : Set α) = {a} := by ext simp #align finset.coe_singleton Finset.coe_singleton @[simp, norm_cast] theorem coe_eq_singleton {s : Finset α} {a : α} : (s : Set α) = {a} ↔ s = {a} := by rw [← coe_singleton, coe_inj] #align finset.coe_eq_singleton Finset.coe_eq_singleton @[norm_cast] lemma coe_subset_singleton : (s : Set α) ⊆ {a} ↔ s ⊆ {a} := by rw [← coe_subset, coe_singleton] @[norm_cast] lemma singleton_subset_coe : {a} ⊆ (s : Set α) ↔ {a} ⊆ s := by rw [← coe_subset, coe_singleton] theorem eq_singleton_iff_unique_mem {s : Finset α} {a : α} : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a := by constructor <;> intro t · rw [t] exact ⟨Finset.mem_singleton_self _, fun _ => Finset.mem_singleton.1⟩ · ext rw [Finset.mem_singleton] exact ⟨t.right _, fun r => r.symm ▸ t.left⟩ #align finset.eq_singleton_iff_unique_mem Finset.eq_singleton_iff_unique_mem theorem eq_singleton_iff_nonempty_unique_mem {s : Finset α} {a : α} : s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a := by constructor · rintro rfl simp · rintro ⟨hne, h_uniq⟩ rw [eq_singleton_iff_unique_mem] refine ⟨?_, h_uniq⟩ rw [← h_uniq hne.choose hne.choose_spec] exact hne.choose_spec #align finset.eq_singleton_iff_nonempty_unique_mem Finset.eq_singleton_iff_nonempty_unique_mem theorem nonempty_iff_eq_singleton_default [Unique α] {s : Finset α} : s.Nonempty ↔ s = {default} := by simp [eq_singleton_iff_nonempty_unique_mem, eq_iff_true_of_subsingleton] #align finset.nonempty_iff_eq_singleton_default Finset.nonempty_iff_eq_singleton_default alias ⟨Nonempty.eq_singleton_default, _⟩ := nonempty_iff_eq_singleton_default #align finset.nonempty.eq_singleton_default Finset.Nonempty.eq_singleton_default theorem singleton_iff_unique_mem (s : Finset α) : (∃ a, s = {a}) ↔ ∃! a, a ∈ s := by simp only [eq_singleton_iff_unique_mem, ExistsUnique] #align finset.singleton_iff_unique_mem Finset.singleton_iff_unique_mem theorem singleton_subset_set_iff {s : Set α} {a : α} : ↑({a} : Finset α) ⊆ s ↔ a ∈ s := by rw [coe_singleton, Set.singleton_subset_iff] #align finset.singleton_subset_set_iff Finset.singleton_subset_set_iff @[simp] theorem singleton_subset_iff {s : Finset α} {a : α} : {a} ⊆ s ↔ a ∈ s := singleton_subset_set_iff #align finset.singleton_subset_iff Finset.singleton_subset_iff @[simp] theorem subset_singleton_iff {s : Finset α} {a : α} : s ⊆ {a} ↔ s = ∅ ∨ s = {a} := by rw [← coe_subset, coe_singleton, Set.subset_singleton_iff_eq, coe_eq_empty, coe_eq_singleton] #align finset.subset_singleton_iff Finset.subset_singleton_iff theorem singleton_subset_singleton : ({a} : Finset α) ⊆ {b} ↔ a = b := by simp #align finset.singleton_subset_singleton Finset.singleton_subset_singleton protected theorem Nonempty.subset_singleton_iff {s : Finset α} {a : α} (h : s.Nonempty) : s ⊆ {a} ↔ s = {a} := subset_singleton_iff.trans <| or_iff_right h.ne_empty #align finset.nonempty.subset_singleton_iff Finset.Nonempty.subset_singleton_iff theorem subset_singleton_iff' {s : Finset α} {a : α} : s ⊆ {a} ↔ ∀ b ∈ s, b = a := forall₂_congr fun _ _ => mem_singleton #align finset.subset_singleton_iff' Finset.subset_singleton_iff' @[simp] theorem ssubset_singleton_iff {s : Finset α} {a : α} : s ⊂ {a} ↔ s = ∅ := by rw [← coe_ssubset, coe_singleton, Set.ssubset_singleton_iff, coe_eq_empty] #align finset.ssubset_singleton_iff Finset.ssubset_singleton_iff theorem eq_empty_of_ssubset_singleton {s : Finset α} {x : α} (hs : s ⊂ {x}) : s = ∅ := ssubset_singleton_iff.1 hs #align finset.eq_empty_of_ssubset_singleton Finset.eq_empty_of_ssubset_singleton /-- A finset is nontrivial if it has at least two elements. -/ protected abbrev Nontrivial (s : Finset α) : Prop := (s : Set α).Nontrivial #align finset.nontrivial Finset.Nontrivial @[simp] theorem not_nontrivial_empty : ¬ (∅ : Finset α).Nontrivial := by simp [Finset.Nontrivial] #align finset.not_nontrivial_empty Finset.not_nontrivial_empty @[simp] theorem not_nontrivial_singleton : ¬ ({a} : Finset α).Nontrivial := by simp [Finset.Nontrivial] #align finset.not_nontrivial_singleton Finset.not_nontrivial_singleton theorem Nontrivial.ne_singleton (hs : s.Nontrivial) : s ≠ {a} := by rintro rfl; exact not_nontrivial_singleton hs #align finset.nontrivial.ne_singleton Finset.Nontrivial.ne_singleton nonrec lemma Nontrivial.exists_ne (hs : s.Nontrivial) (a : α) : ∃ b ∈ s, b ≠ a := hs.exists_ne _ theorem eq_singleton_or_nontrivial (ha : a ∈ s) : s = {a} ∨ s.Nontrivial := by rw [← coe_eq_singleton]; exact Set.eq_singleton_or_nontrivial ha #align finset.eq_singleton_or_nontrivial Finset.eq_singleton_or_nontrivial theorem nontrivial_iff_ne_singleton (ha : a ∈ s) : s.Nontrivial ↔ s ≠ {a} := ⟨Nontrivial.ne_singleton, (eq_singleton_or_nontrivial ha).resolve_left⟩ #align finset.nontrivial_iff_ne_singleton Finset.nontrivial_iff_ne_singleton theorem Nonempty.exists_eq_singleton_or_nontrivial : s.Nonempty → (∃ a, s = {a}) ∨ s.Nontrivial := fun ⟨a, ha⟩ => (eq_singleton_or_nontrivial ha).imp_left <| Exists.intro a #align finset.nonempty.exists_eq_singleton_or_nontrivial Finset.Nonempty.exists_eq_singleton_or_nontrivial instance instNontrivial [Nonempty α] : Nontrivial (Finset α) := ‹Nonempty α›.elim fun a => ⟨⟨{a}, ∅, singleton_ne_empty _⟩⟩ #align finset.nontrivial' Finset.instNontrivial instance [IsEmpty α] : Unique (Finset α) where default := ∅ uniq _ := eq_empty_of_forall_not_mem isEmptyElim instance (i : α) : Unique ({i} : Finset α) where default := ⟨i, mem_singleton_self i⟩ uniq j := Subtype.ext <| mem_singleton.mp j.2 @[simp] lemma default_singleton (i : α) : ((default : ({i} : Finset α)) : α) = i := rfl end Singleton /-! ### cons -/ section Cons variable {s t : Finset α} {a b : α} /-- `cons a s h` is the set `{a} ∪ s` containing `a` and the elements of `s`. It is the same as `insert a s` when it is defined, but unlike `insert a s` it does not require `DecidableEq α`, and the union is guaranteed to be disjoint. -/ def cons (a : α) (s : Finset α) (h : a ∉ s) : Finset α := ⟨a ::ₘ s.1, nodup_cons.2 ⟨h, s.2⟩⟩ #align finset.cons Finset.cons @[simp] theorem mem_cons {h} : b ∈ s.cons a h ↔ b = a ∨ b ∈ s := Multiset.mem_cons #align finset.mem_cons Finset.mem_cons theorem mem_cons_of_mem {a b : α} {s : Finset α} {hb : b ∉ s} (ha : a ∈ s) : a ∈ cons b s hb := Multiset.mem_cons_of_mem ha -- Porting note (#10618): @[simp] can prove this theorem mem_cons_self (a : α) (s : Finset α) {h} : a ∈ cons a s h := Multiset.mem_cons_self _ _ #align finset.mem_cons_self Finset.mem_cons_self @[simp] theorem cons_val (h : a ∉ s) : (cons a s h).1 = a ::ₘ s.1 := rfl #align finset.cons_val Finset.cons_val theorem forall_mem_cons (h : a ∉ s) (p : α → Prop) : (∀ x, x ∈ cons a s h → p x) ↔ p a ∧ ∀ x, x ∈ s → p x := by simp only [mem_cons, or_imp, forall_and, forall_eq] #align finset.forall_mem_cons Finset.forall_mem_cons /-- Useful in proofs by induction. -/ theorem forall_of_forall_cons {p : α → Prop} {h : a ∉ s} (H : ∀ x, x ∈ cons a s h → p x) (x) (h : x ∈ s) : p x := H _ <| mem_cons.2 <| Or.inr h #align finset.forall_of_forall_cons Finset.forall_of_forall_cons @[simp] theorem mk_cons {s : Multiset α} (h : (a ::ₘ s).Nodup) : (⟨a ::ₘ s, h⟩ : Finset α) = cons a ⟨s, (nodup_cons.1 h).2⟩ (nodup_cons.1 h).1 := rfl #align finset.mk_cons Finset.mk_cons @[simp] theorem cons_empty (a : α) : cons a ∅ (not_mem_empty _) = {a} := rfl #align finset.cons_empty Finset.cons_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_cons (h : a ∉ s) : (cons a s h).Nonempty := ⟨a, mem_cons.2 <| Or.inl rfl⟩ #align finset.nonempty_cons Finset.nonempty_cons @[simp] theorem nonempty_mk {m : Multiset α} {hm} : (⟨m, hm⟩ : Finset α).Nonempty ↔ m ≠ 0 := by induction m using Multiset.induction_on <;> simp #align finset.nonempty_mk Finset.nonempty_mk @[simp] theorem coe_cons {a s h} : (@cons α a s h : Set α) = insert a (s : Set α) := by ext simp #align finset.coe_cons Finset.coe_cons theorem subset_cons (h : a ∉ s) : s ⊆ s.cons a h := Multiset.subset_cons _ _ #align finset.subset_cons Finset.subset_cons theorem ssubset_cons (h : a ∉ s) : s ⊂ s.cons a h := Multiset.ssubset_cons h #align finset.ssubset_cons Finset.ssubset_cons theorem cons_subset {h : a ∉ s} : s.cons a h ⊆ t ↔ a ∈ t ∧ s ⊆ t := Multiset.cons_subset #align finset.cons_subset Finset.cons_subset @[simp] theorem cons_subset_cons {hs ht} : s.cons a hs ⊆ t.cons a ht ↔ s ⊆ t := by rwa [← coe_subset, coe_cons, coe_cons, Set.insert_subset_insert_iff, coe_subset] #align finset.cons_subset_cons Finset.cons_subset_cons theorem ssubset_iff_exists_cons_subset : s ⊂ t ↔ ∃ (a : _) (h : a ∉ s), s.cons a h ⊆ t := by refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_ssubset_of_subset (ssubset_cons _) h⟩ obtain ⟨a, hs, ht⟩ := not_subset.1 h.2 exact ⟨a, ht, cons_subset.2 ⟨hs, h.subset⟩⟩ #align finset.ssubset_iff_exists_cons_subset Finset.ssubset_iff_exists_cons_subset end Cons /-! ### disjoint -/ section Disjoint variable {f : α → β} {s t u : Finset α} {a b : α} theorem disjoint_left : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → a ∉ t := ⟨fun h a hs ht => not_mem_empty a <| singleton_subset_iff.mp (h (singleton_subset_iff.mpr hs) (singleton_subset_iff.mpr ht)), fun h _ hs ht _ ha => (h (hs ha) (ht ha)).elim⟩ #align finset.disjoint_left Finset.disjoint_left theorem disjoint_right : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ t → a ∉ s := by rw [_root_.disjoint_comm, disjoint_left] #align finset.disjoint_right Finset.disjoint_right theorem disjoint_iff_ne : Disjoint s t ↔ ∀ a ∈ s, ∀ b ∈ t, a ≠ b := by simp only [disjoint_left, imp_not_comm, forall_eq'] #align finset.disjoint_iff_ne Finset.disjoint_iff_ne @[simp] theorem disjoint_val : s.1.Disjoint t.1 ↔ Disjoint s t := disjoint_left.symm #align finset.disjoint_val Finset.disjoint_val theorem _root_.Disjoint.forall_ne_finset (h : Disjoint s t) (ha : a ∈ s) (hb : b ∈ t) : a ≠ b := disjoint_iff_ne.1 h _ ha _ hb #align disjoint.forall_ne_finset Disjoint.forall_ne_finset theorem not_disjoint_iff : ¬Disjoint s t ↔ ∃ a, a ∈ s ∧ a ∈ t := disjoint_left.not.trans <| not_forall.trans <| exists_congr fun _ => by rw [Classical.not_imp, not_not] #align finset.not_disjoint_iff Finset.not_disjoint_iff theorem disjoint_of_subset_left (h : s ⊆ u) (d : Disjoint u t) : Disjoint s t := disjoint_left.2 fun _x m₁ => (disjoint_left.1 d) (h m₁) #align finset.disjoint_of_subset_left Finset.disjoint_of_subset_left theorem disjoint_of_subset_right (h : t ⊆ u) (d : Disjoint s u) : Disjoint s t := disjoint_right.2 fun _x m₁ => (disjoint_right.1 d) (h m₁) #align finset.disjoint_of_subset_right Finset.disjoint_of_subset_right @[simp] theorem disjoint_empty_left (s : Finset α) : Disjoint ∅ s := disjoint_bot_left #align finset.disjoint_empty_left Finset.disjoint_empty_left @[simp] theorem disjoint_empty_right (s : Finset α) : Disjoint s ∅ := disjoint_bot_right #align finset.disjoint_empty_right Finset.disjoint_empty_right @[simp] theorem disjoint_singleton_left : Disjoint (singleton a) s ↔ a ∉ s := by simp only [disjoint_left, mem_singleton, forall_eq] #align finset.disjoint_singleton_left Finset.disjoint_singleton_left @[simp] theorem disjoint_singleton_right : Disjoint s (singleton a) ↔ a ∉ s := disjoint_comm.trans disjoint_singleton_left #align finset.disjoint_singleton_right Finset.disjoint_singleton_right -- Porting note: Left-hand side simplifies @[simp] theorem disjoint_singleton : Disjoint ({a} : Finset α) {b} ↔ a ≠ b := by rw [disjoint_singleton_left, mem_singleton] #align finset.disjoint_singleton Finset.disjoint_singleton theorem disjoint_self_iff_empty (s : Finset α) : Disjoint s s ↔ s = ∅ := disjoint_self #align finset.disjoint_self_iff_empty Finset.disjoint_self_iff_empty @[simp, norm_cast] theorem disjoint_coe : Disjoint (s : Set α) t ↔ Disjoint s t := by simp only [Finset.disjoint_left, Set.disjoint_left, mem_coe] #align finset.disjoint_coe Finset.disjoint_coe @[simp, norm_cast] theorem pairwiseDisjoint_coe {ι : Type*} {s : Set ι} {f : ι → Finset α} : s.PairwiseDisjoint (fun i => f i : ι → Set α) ↔ s.PairwiseDisjoint f := forall₅_congr fun _ _ _ _ _ => disjoint_coe #align finset.pairwise_disjoint_coe Finset.pairwiseDisjoint_coe end Disjoint /-! ### disjoint union -/ /-- `disjUnion s t h` is the set such that `a ∈ disjUnion s t h` iff `a ∈ s` or `a ∈ t`. It is the same as `s ∪ t`, but it does not require decidable equality on the type. The hypothesis ensures that the sets are disjoint. -/ def disjUnion (s t : Finset α) (h : Disjoint s t) : Finset α := ⟨s.1 + t.1, Multiset.nodup_add.2 ⟨s.2, t.2, disjoint_val.2 h⟩⟩ #align finset.disj_union Finset.disjUnion @[simp] theorem mem_disjUnion {α s t h a} : a ∈ @disjUnion α s t h ↔ a ∈ s ∨ a ∈ t := by rcases s with ⟨⟨s⟩⟩; rcases t with ⟨⟨t⟩⟩; apply List.mem_append #align finset.mem_disj_union Finset.mem_disjUnion @[simp, norm_cast] theorem coe_disjUnion {s t : Finset α} (h : Disjoint s t) : (disjUnion s t h : Set α) = (s : Set α) ∪ t := Set.ext <| by simp theorem disjUnion_comm (s t : Finset α) (h : Disjoint s t) : disjUnion s t h = disjUnion t s h.symm := eq_of_veq <| add_comm _ _ #align finset.disj_union_comm Finset.disjUnion_comm @[simp] theorem empty_disjUnion (t : Finset α) (h : Disjoint ∅ t := disjoint_bot_left) : disjUnion ∅ t h = t := eq_of_veq <| zero_add _ #align finset.empty_disj_union Finset.empty_disjUnion @[simp] theorem disjUnion_empty (s : Finset α) (h : Disjoint s ∅ := disjoint_bot_right) : disjUnion s ∅ h = s := eq_of_veq <| add_zero _ #align finset.disj_union_empty Finset.disjUnion_empty theorem singleton_disjUnion (a : α) (t : Finset α) (h : Disjoint {a} t) : disjUnion {a} t h = cons a t (disjoint_singleton_left.mp h) := eq_of_veq <| Multiset.singleton_add _ _ #align finset.singleton_disj_union Finset.singleton_disjUnion theorem disjUnion_singleton (s : Finset α) (a : α) (h : Disjoint s {a}) : disjUnion s {a} h = cons a s (disjoint_singleton_right.mp h) := by rw [disjUnion_comm, singleton_disjUnion] #align finset.disj_union_singleton Finset.disjUnion_singleton /-! ### insert -/ section Insert variable [DecidableEq α] {s t u v : Finset α} {a b : α} /-- `insert a s` is the set `{a} ∪ s` containing `a` and the elements of `s`. -/ instance : Insert α (Finset α) := ⟨fun a s => ⟨_, s.2.ndinsert a⟩⟩ theorem insert_def (a : α) (s : Finset α) : insert a s = ⟨_, s.2.ndinsert a⟩ := rfl #align finset.insert_def Finset.insert_def @[simp] theorem insert_val (a : α) (s : Finset α) : (insert a s).1 = ndinsert a s.1 := rfl #align finset.insert_val Finset.insert_val theorem insert_val' (a : α) (s : Finset α) : (insert a s).1 = dedup (a ::ₘ s.1) := by rw [dedup_cons, dedup_eq_self]; rfl #align finset.insert_val' Finset.insert_val' theorem insert_val_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : (insert a s).1 = a ::ₘ s.1 := by rw [insert_val, ndinsert_of_not_mem h] #align finset.insert_val_of_not_mem Finset.insert_val_of_not_mem @[simp] theorem mem_insert : a ∈ insert b s ↔ a = b ∨ a ∈ s := mem_ndinsert #align finset.mem_insert Finset.mem_insert theorem mem_insert_self (a : α) (s : Finset α) : a ∈ insert a s := mem_ndinsert_self a s.1 #align finset.mem_insert_self Finset.mem_insert_self theorem mem_insert_of_mem (h : a ∈ s) : a ∈ insert b s := mem_ndinsert_of_mem h #align finset.mem_insert_of_mem Finset.mem_insert_of_mem theorem mem_of_mem_insert_of_ne (h : b ∈ insert a s) : b ≠ a → b ∈ s := (mem_insert.1 h).resolve_left #align finset.mem_of_mem_insert_of_ne Finset.mem_of_mem_insert_of_ne theorem eq_of_not_mem_of_mem_insert (ha : b ∈ insert a s) (hb : b ∉ s) : b = a := (mem_insert.1 ha).resolve_right hb #align finset.eq_of_not_mem_of_mem_insert Finset.eq_of_not_mem_of_mem_insert /-- A version of `LawfulSingleton.insert_emptyc_eq` that works with `dsimp`. -/ @[simp, nolint simpNF] lemma insert_empty : insert a (∅ : Finset α) = {a} := rfl @[simp] theorem cons_eq_insert (a s h) : @cons α a s h = insert a s := ext fun a => by simp #align finset.cons_eq_insert Finset.cons_eq_insert @[simp, norm_cast] theorem coe_insert (a : α) (s : Finset α) : ↑(insert a s) = (insert a s : Set α) := Set.ext fun x => by simp only [mem_coe, mem_insert, Set.mem_insert_iff] #align finset.coe_insert Finset.coe_insert theorem mem_insert_coe {s : Finset α} {x y : α} : x ∈ insert y s ↔ x ∈ insert y (s : Set α) := by simp #align finset.mem_insert_coe Finset.mem_insert_coe instance : LawfulSingleton α (Finset α) := ⟨fun a => by ext; simp⟩ @[simp] theorem insert_eq_of_mem (h : a ∈ s) : insert a s = s := eq_of_veq <| ndinsert_of_mem h #align finset.insert_eq_of_mem Finset.insert_eq_of_mem @[simp] theorem insert_eq_self : insert a s = s ↔ a ∈ s := ⟨fun h => h ▸ mem_insert_self _ _, insert_eq_of_mem⟩ #align finset.insert_eq_self Finset.insert_eq_self theorem insert_ne_self : insert a s ≠ s ↔ a ∉ s := insert_eq_self.not #align finset.insert_ne_self Finset.insert_ne_self -- Porting note (#10618): @[simp] can prove this theorem pair_eq_singleton (a : α) : ({a, a} : Finset α) = {a} := insert_eq_of_mem <| mem_singleton_self _ #align finset.pair_eq_singleton Finset.pair_eq_singleton theorem Insert.comm (a b : α) (s : Finset α) : insert a (insert b s) = insert b (insert a s) := ext fun x => by simp only [mem_insert, or_left_comm] #align finset.insert.comm Finset.Insert.comm -- Porting note (#10618): @[simp] can prove this @[norm_cast] theorem coe_pair {a b : α} : (({a, b} : Finset α) : Set α) = {a, b} := by ext simp #align finset.coe_pair Finset.coe_pair @[simp, norm_cast] theorem coe_eq_pair {s : Finset α} {a b : α} : (s : Set α) = {a, b} ↔ s = {a, b} := by rw [← coe_pair, coe_inj] #align finset.coe_eq_pair Finset.coe_eq_pair theorem pair_comm (a b : α) : ({a, b} : Finset α) = {b, a} := Insert.comm a b ∅ #align finset.pair_comm Finset.pair_comm -- Porting note (#10618): @[simp] can prove this theorem insert_idem (a : α) (s : Finset α) : insert a (insert a s) = insert a s := ext fun x => by simp only [mem_insert, ← or_assoc, or_self_iff] #align finset.insert_idem Finset.insert_idem @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem insert_nonempty (a : α) (s : Finset α) : (insert a s).Nonempty := ⟨a, mem_insert_self a s⟩ #align finset.insert_nonempty Finset.insert_nonempty @[simp] theorem insert_ne_empty (a : α) (s : Finset α) : insert a s ≠ ∅ := (insert_nonempty a s).ne_empty #align finset.insert_ne_empty Finset.insert_ne_empty -- Porting note: explicit universe annotation is no longer required. instance (i : α) (s : Finset α) : Nonempty ((insert i s : Finset α) : Set α) := (Finset.coe_nonempty.mpr (s.insert_nonempty i)).to_subtype theorem ne_insert_of_not_mem (s t : Finset α) {a : α} (h : a ∉ s) : s ≠ insert a t := by contrapose! h simp [h] #align finset.ne_insert_of_not_mem Finset.ne_insert_of_not_mem theorem insert_subset_iff : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp only [subset_iff, mem_insert, forall_eq, or_imp, forall_and] #align finset.insert_subset Finset.insert_subset_iff theorem insert_subset (ha : a ∈ t) (hs : s ⊆ t) : insert a s ⊆ t := insert_subset_iff.mpr ⟨ha,hs⟩ @[simp] theorem subset_insert (a : α) (s : Finset α) : s ⊆ insert a s := fun _b => mem_insert_of_mem #align finset.subset_insert Finset.subset_insert @[gcongr] theorem insert_subset_insert (a : α) {s t : Finset α} (h : s ⊆ t) : insert a s ⊆ insert a t := insert_subset_iff.2 ⟨mem_insert_self _ _, Subset.trans h (subset_insert _ _)⟩ #align finset.insert_subset_insert Finset.insert_subset_insert @[simp] lemma insert_subset_insert_iff (ha : a ∉ s) : insert a s ⊆ insert a t ↔ s ⊆ t := by simp_rw [← coe_subset]; simp [-coe_subset, ha] theorem insert_inj (ha : a ∉ s) : insert a s = insert b s ↔ a = b := ⟨fun h => eq_of_not_mem_of_mem_insert (h.subst <| mem_insert_self _ _) ha, congr_arg (insert · s)⟩ #align finset.insert_inj Finset.insert_inj theorem insert_inj_on (s : Finset α) : Set.InjOn (fun a => insert a s) sᶜ := fun _ h _ _ => (insert_inj h).1 #align finset.insert_inj_on Finset.insert_inj_on theorem ssubset_iff : s ⊂ t ↔ ∃ a ∉ s, insert a s ⊆ t := mod_cast @Set.ssubset_iff_insert α s t #align finset.ssubset_iff Finset.ssubset_iff theorem ssubset_insert (h : a ∉ s) : s ⊂ insert a s := ssubset_iff.mpr ⟨a, h, Subset.rfl⟩ #align finset.ssubset_insert Finset.ssubset_insert @[elab_as_elim] theorem cons_induction {α : Type*} {p : Finset α → Prop} (empty : p ∅) (cons : ∀ (a : α) (s : Finset α) (h : a ∉ s), p s → p (cons a s h)) : ∀ s, p s | ⟨s, nd⟩ => by induction s using Multiset.induction with | empty => exact empty | cons a s IH => rw [mk_cons nd] exact cons a _ _ (IH _) #align finset.cons_induction Finset.cons_induction @[elab_as_elim] theorem cons_induction_on {α : Type*} {p : Finset α → Prop} (s : Finset α) (h₁ : p ∅) (h₂ : ∀ ⦃a : α⦄ {s : Finset α} (h : a ∉ s), p s → p (cons a s h)) : p s := cons_induction h₁ h₂ s #align finset.cons_induction_on Finset.cons_induction_on @[elab_as_elim] protected theorem induction {α : Type*} {p : Finset α → Prop} [DecidableEq α] (empty : p ∅) (insert : ∀ ⦃a : α⦄ {s : Finset α}, a ∉ s → p s → p (insert a s)) : ∀ s, p s := cons_induction empty fun a s ha => (s.cons_eq_insert a ha).symm ▸ insert ha #align finset.induction Finset.induction /-- To prove a proposition about an arbitrary `Finset α`, it suffices to prove it for the empty `Finset`, and to show that if it holds for some `Finset α`, then it holds for the `Finset` obtained by inserting a new element. -/ @[elab_as_elim] protected theorem induction_on {α : Type*} {p : Finset α → Prop} [DecidableEq α] (s : Finset α) (empty : p ∅) (insert : ∀ ⦃a : α⦄ {s : Finset α}, a ∉ s → p s → p (insert a s)) : p s := Finset.induction empty insert s #align finset.induction_on Finset.induction_on /-- To prove a proposition about `S : Finset α`, it suffices to prove it for the empty `Finset`, and to show that if it holds for some `Finset α ⊆ S`, then it holds for the `Finset` obtained by inserting a new element of `S`. -/ @[elab_as_elim] theorem induction_on' {α : Type*} {p : Finset α → Prop} [DecidableEq α] (S : Finset α) (h₁ : p ∅) (h₂ : ∀ {a s}, a ∈ S → s ⊆ S → a ∉ s → p s → p (insert a s)) : p S := @Finset.induction_on α (fun T => T ⊆ S → p T) _ S (fun _ => h₁) (fun _ _ has hqs hs => let ⟨hS, sS⟩ := Finset.insert_subset_iff.1 hs h₂ hS sS has (hqs sS)) (Finset.Subset.refl S) #align finset.induction_on' Finset.induction_on' /-- To prove a proposition about a nonempty `s : Finset α`, it suffices to show it holds for all singletons and that if it holds for nonempty `t : Finset α`, then it also holds for the `Finset` obtained by inserting an element in `t`. -/ @[elab_as_elim] theorem Nonempty.cons_induction {α : Type*} {p : ∀ s : Finset α, s.Nonempty → Prop} (singleton : ∀ a, p {a} (singleton_nonempty _)) (cons : ∀ a s (h : a ∉ s) (hs), p s hs → p (Finset.cons a s h) (nonempty_cons h)) {s : Finset α} (hs : s.Nonempty) : p s hs := by induction s using Finset.cons_induction with | empty => exact (not_nonempty_empty hs).elim | cons a t ha h => obtain rfl | ht := t.eq_empty_or_nonempty · exact singleton a · exact cons a t ha ht (h ht) #align finset.nonempty.cons_induction Finset.Nonempty.cons_induction lemma Nonempty.exists_cons_eq (hs : s.Nonempty) : ∃ t a ha, cons a t ha = s := hs.cons_induction (fun a ↦ ⟨∅, a, _, cons_empty _⟩) fun _ _ _ _ _ ↦ ⟨_, _, _, rfl⟩ /-- Inserting an element to a finite set is equivalent to the option type. -/ def subtypeInsertEquivOption {t : Finset α} {x : α} (h : x ∉ t) : { i // i ∈ insert x t } ≃ Option { i // i ∈ t } where toFun y := if h : ↑y = x then none else some ⟨y, (mem_insert.mp y.2).resolve_left h⟩ invFun y := (y.elim ⟨x, mem_insert_self _ _⟩) fun z => ⟨z, mem_insert_of_mem z.2⟩ left_inv y := by by_cases h : ↑y = x · simp only [Subtype.ext_iff, h, Option.elim, dif_pos, Subtype.coe_mk] · simp only [h, Option.elim, dif_neg, not_false_iff, Subtype.coe_eta, Subtype.coe_mk] right_inv := by rintro (_ | y) · simp only [Option.elim, dif_pos] · have : ↑y ≠ x := by rintro ⟨⟩ exact h y.2 simp only [this, Option.elim, Subtype.eta, dif_neg, not_false_iff, Subtype.coe_mk] #align finset.subtype_insert_equiv_option Finset.subtypeInsertEquivOption @[simp] theorem disjoint_insert_left : Disjoint (insert a s) t ↔ a ∉ t ∧ Disjoint s t := by simp only [disjoint_left, mem_insert, or_imp, forall_and, forall_eq] #align finset.disjoint_insert_left Finset.disjoint_insert_left @[simp] theorem disjoint_insert_right : Disjoint s (insert a t) ↔ a ∉ s ∧ Disjoint s t := disjoint_comm.trans <| by rw [disjoint_insert_left, _root_.disjoint_comm] #align finset.disjoint_insert_right Finset.disjoint_insert_right end Insert /-! ### Lattice structure -/ section Lattice variable [DecidableEq α] {s s₁ s₂ t t₁ t₂ u v : Finset α} {a b : α} /-- `s ∪ t` is the set such that `a ∈ s ∪ t` iff `a ∈ s` or `a ∈ t`. -/ instance : Union (Finset α) := ⟨fun s t => ⟨_, t.2.ndunion s.1⟩⟩ /-- `s ∩ t` is the set such that `a ∈ s ∩ t` iff `a ∈ s` and `a ∈ t`. -/ instance : Inter (Finset α) := ⟨fun s t => ⟨_, s.2.ndinter t.1⟩⟩ instance : Lattice (Finset α) := { Finset.partialOrder with sup := (· ∪ ·) sup_le := fun _ _ _ hs ht _ ha => (mem_ndunion.1 ha).elim (fun h => hs h) fun h => ht h le_sup_left := fun _ _ _ h => mem_ndunion.2 <| Or.inl h le_sup_right := fun _ _ _ h => mem_ndunion.2 <| Or.inr h inf := (· ∩ ·) le_inf := fun _ _ _ ht hu _ h => mem_ndinter.2 ⟨ht h, hu h⟩ inf_le_left := fun _ _ _ h => (mem_ndinter.1 h).1 inf_le_right := fun _ _ _ h => (mem_ndinter.1 h).2 } @[simp] theorem sup_eq_union : (Sup.sup : Finset α → Finset α → Finset α) = Union.union := rfl #align finset.sup_eq_union Finset.sup_eq_union @[simp] theorem inf_eq_inter : (Inf.inf : Finset α → Finset α → Finset α) = Inter.inter := rfl #align finset.inf_eq_inter Finset.inf_eq_inter theorem disjoint_iff_inter_eq_empty : Disjoint s t ↔ s ∩ t = ∅ := disjoint_iff #align finset.disjoint_iff_inter_eq_empty Finset.disjoint_iff_inter_eq_empty instance decidableDisjoint (U V : Finset α) : Decidable (Disjoint U V) := decidable_of_iff _ disjoint_left.symm #align finset.decidable_disjoint Finset.decidableDisjoint /-! #### union -/ theorem union_val_nd (s t : Finset α) : (s ∪ t).1 = ndunion s.1 t.1 := rfl #align finset.union_val_nd Finset.union_val_nd @[simp] theorem union_val (s t : Finset α) : (s ∪ t).1 = s.1 ∪ t.1 := ndunion_eq_union s.2 #align finset.union_val Finset.union_val @[simp] theorem mem_union : a ∈ s ∪ t ↔ a ∈ s ∨ a ∈ t := mem_ndunion #align finset.mem_union Finset.mem_union @[simp] theorem disjUnion_eq_union (s t h) : @disjUnion α s t h = s ∪ t := ext fun a => by simp #align finset.disj_union_eq_union Finset.disjUnion_eq_union theorem mem_union_left (t : Finset α) (h : a ∈ s) : a ∈ s ∪ t := mem_union.2 <| Or.inl h #align finset.mem_union_left Finset.mem_union_left theorem mem_union_right (s : Finset α) (h : a ∈ t) : a ∈ s ∪ t := mem_union.2 <| Or.inr h #align finset.mem_union_right Finset.mem_union_right theorem forall_mem_union {p : α → Prop} : (∀ a ∈ s ∪ t, p a) ↔ (∀ a ∈ s, p a) ∧ ∀ a ∈ t, p a := ⟨fun h => ⟨fun a => h a ∘ mem_union_left _, fun b => h b ∘ mem_union_right _⟩, fun h _ab hab => (mem_union.mp hab).elim (h.1 _) (h.2 _)⟩ #align finset.forall_mem_union Finset.forall_mem_union theorem not_mem_union : a ∉ s ∪ t ↔ a ∉ s ∧ a ∉ t := by rw [mem_union, not_or] #align finset.not_mem_union Finset.not_mem_union @[simp, norm_cast] theorem coe_union (s₁ s₂ : Finset α) : ↑(s₁ ∪ s₂) = (s₁ ∪ s₂ : Set α) := Set.ext fun _ => mem_union #align finset.coe_union Finset.coe_union theorem union_subset (hs : s ⊆ u) : t ⊆ u → s ∪ t ⊆ u := sup_le <| le_iff_subset.2 hs #align finset.union_subset Finset.union_subset theorem subset_union_left {s₁ s₂ : Finset α} : s₁ ⊆ s₁ ∪ s₂ := fun _x => mem_union_left _ #align finset.subset_union_left Finset.subset_union_left theorem subset_union_right {s₁ s₂ : Finset α} : s₂ ⊆ s₁ ∪ s₂ := fun _x => mem_union_right _ #align finset.subset_union_right Finset.subset_union_right @[gcongr] theorem union_subset_union (hsu : s ⊆ u) (htv : t ⊆ v) : s ∪ t ⊆ u ∪ v := sup_le_sup (le_iff_subset.2 hsu) htv #align finset.union_subset_union Finset.union_subset_union @[gcongr] theorem union_subset_union_left (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t := union_subset_union h Subset.rfl #align finset.union_subset_union_left Finset.union_subset_union_left @[gcongr] theorem union_subset_union_right (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ := union_subset_union Subset.rfl h #align finset.union_subset_union_right Finset.union_subset_union_right theorem union_comm (s₁ s₂ : Finset α) : s₁ ∪ s₂ = s₂ ∪ s₁ := sup_comm _ _ #align finset.union_comm Finset.union_comm instance : Std.Commutative (α := Finset α) (· ∪ ·) := ⟨union_comm⟩ @[simp] theorem union_assoc (s₁ s₂ s₃ : Finset α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ (s₂ ∪ s₃) := sup_assoc _ _ _ #align finset.union_assoc Finset.union_assoc instance : Std.Associative (α := Finset α) (· ∪ ·) := ⟨union_assoc⟩ @[simp] theorem union_idempotent (s : Finset α) : s ∪ s = s := sup_idem _ #align finset.union_idempotent Finset.union_idempotent instance : Std.IdempotentOp (α := Finset α) (· ∪ ·) := ⟨union_idempotent⟩ theorem union_subset_left (h : s ∪ t ⊆ u) : s ⊆ u := subset_union_left.trans h #align finset.union_subset_left Finset.union_subset_left theorem union_subset_right {s t u : Finset α} (h : s ∪ t ⊆ u) : t ⊆ u := Subset.trans subset_union_right h #align finset.union_subset_right Finset.union_subset_right theorem union_left_comm (s t u : Finset α) : s ∪ (t ∪ u) = t ∪ (s ∪ u) := ext fun _ => by simp only [mem_union, or_left_comm] #align finset.union_left_comm Finset.union_left_comm theorem union_right_comm (s t u : Finset α) : s ∪ t ∪ u = s ∪ u ∪ t := ext fun x => by simp only [mem_union, or_assoc, @or_comm (x ∈ t)] #align finset.union_right_comm Finset.union_right_comm theorem union_self (s : Finset α) : s ∪ s = s := union_idempotent s #align finset.union_self Finset.union_self @[simp] theorem union_empty (s : Finset α) : s ∪ ∅ = s := ext fun x => mem_union.trans <| by simp #align finset.union_empty Finset.union_empty @[simp] theorem empty_union (s : Finset α) : ∅ ∪ s = s := ext fun x => mem_union.trans <| by simp #align finset.empty_union Finset.empty_union @[aesop unsafe apply (rule_sets := [finsetNonempty])] theorem Nonempty.inl {s t : Finset α} (h : s.Nonempty) : (s ∪ t).Nonempty := h.mono subset_union_left @[aesop unsafe apply (rule_sets := [finsetNonempty])] theorem Nonempty.inr {s t : Finset α} (h : t.Nonempty) : (s ∪ t).Nonempty := h.mono subset_union_right theorem insert_eq (a : α) (s : Finset α) : insert a s = {a} ∪ s := rfl #align finset.insert_eq Finset.insert_eq @[simp] theorem insert_union (a : α) (s t : Finset α) : insert a s ∪ t = insert a (s ∪ t) := by simp only [insert_eq, union_assoc] #align finset.insert_union Finset.insert_union @[simp] theorem union_insert (a : α) (s t : Finset α) : s ∪ insert a t = insert a (s ∪ t) := by simp only [insert_eq, union_left_comm] #align finset.union_insert Finset.union_insert theorem insert_union_distrib (a : α) (s t : Finset α) : insert a (s ∪ t) = insert a s ∪ insert a t := by simp only [insert_union, union_insert, insert_idem] #align finset.insert_union_distrib Finset.insert_union_distrib @[simp] lemma union_eq_left : s ∪ t = s ↔ t ⊆ s := sup_eq_left #align finset.union_eq_left_iff_subset Finset.union_eq_left @[simp] lemma left_eq_union : s = s ∪ t ↔ t ⊆ s := by rw [eq_comm, union_eq_left] #align finset.left_eq_union_iff_subset Finset.left_eq_union @[simp] lemma union_eq_right : s ∪ t = t ↔ s ⊆ t := sup_eq_right #align finset.union_eq_right_iff_subset Finset.union_eq_right @[simp] lemma right_eq_union : s = t ∪ s ↔ t ⊆ s := by rw [eq_comm, union_eq_right] #align finset.right_eq_union_iff_subset Finset.right_eq_union -- Porting note: replaced `⊔` in RHS theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u := sup_congr_left ht hu #align finset.union_congr_left Finset.union_congr_left theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u := sup_congr_right hs ht #align finset.union_congr_right Finset.union_congr_right theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t := sup_eq_sup_iff_left #align finset.union_eq_union_iff_left Finset.union_eq_union_iff_left theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u := sup_eq_sup_iff_right #align finset.union_eq_union_iff_right Finset.union_eq_union_iff_right @[simp] theorem disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := by simp only [disjoint_left, mem_union, or_imp, forall_and] #align finset.disjoint_union_left Finset.disjoint_union_left @[simp] theorem disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := by simp only [disjoint_right, mem_union, or_imp, forall_and] #align finset.disjoint_union_right Finset.disjoint_union_right /-- To prove a relation on pairs of `Finset X`, it suffices to show that it is * symmetric, * it holds when one of the `Finset`s is empty, * it holds for pairs of singletons, * if it holds for `[a, c]` and for `[b, c]`, then it holds for `[a ∪ b, c]`. -/ theorem induction_on_union (P : Finset α → Finset α → Prop) (symm : ∀ {a b}, P a b → P b a) (empty_right : ∀ {a}, P a ∅) (singletons : ∀ {a b}, P {a} {b}) (union_of : ∀ {a b c}, P a c → P b c → P (a ∪ b) c) : ∀ a b, P a b := by intro a b refine Finset.induction_on b empty_right fun x s _xs hi => symm ?_ rw [Finset.insert_eq] apply union_of _ (symm hi) refine Finset.induction_on a empty_right fun a t _ta hi => symm ?_ rw [Finset.insert_eq] exact union_of singletons (symm hi) #align finset.induction_on_union Finset.induction_on_union /-! #### inter -/ theorem inter_val_nd (s₁ s₂ : Finset α) : (s₁ ∩ s₂).1 = ndinter s₁.1 s₂.1 := rfl #align finset.inter_val_nd Finset.inter_val_nd @[simp] theorem inter_val (s₁ s₂ : Finset α) : (s₁ ∩ s₂).1 = s₁.1 ∩ s₂.1 := ndinter_eq_inter s₁.2 #align finset.inter_val Finset.inter_val @[simp] theorem mem_inter {a : α} {s₁ s₂ : Finset α} : a ∈ s₁ ∩ s₂ ↔ a ∈ s₁ ∧ a ∈ s₂ := mem_ndinter #align finset.mem_inter Finset.mem_inter theorem mem_of_mem_inter_left {a : α} {s₁ s₂ : Finset α} (h : a ∈ s₁ ∩ s₂) : a ∈ s₁ := (mem_inter.1 h).1 #align finset.mem_of_mem_inter_left Finset.mem_of_mem_inter_left theorem mem_of_mem_inter_right {a : α} {s₁ s₂ : Finset α} (h : a ∈ s₁ ∩ s₂) : a ∈ s₂ := (mem_inter.1 h).2 #align finset.mem_of_mem_inter_right Finset.mem_of_mem_inter_right theorem mem_inter_of_mem {a : α} {s₁ s₂ : Finset α} : a ∈ s₁ → a ∈ s₂ → a ∈ s₁ ∩ s₂ := and_imp.1 mem_inter.2 #align finset.mem_inter_of_mem Finset.mem_inter_of_mem theorem inter_subset_left {s₁ s₂ : Finset α} : s₁ ∩ s₂ ⊆ s₁ := fun _a => mem_of_mem_inter_left #align finset.inter_subset_left Finset.inter_subset_left theorem inter_subset_right {s₁ s₂ : Finset α} : s₁ ∩ s₂ ⊆ s₂ := fun _a => mem_of_mem_inter_right #align finset.inter_subset_right Finset.inter_subset_right theorem subset_inter {s₁ s₂ u : Finset α} : s₁ ⊆ s₂ → s₁ ⊆ u → s₁ ⊆ s₂ ∩ u := by simp (config := { contextual := true }) [subset_iff, mem_inter] #align finset.subset_inter Finset.subset_inter @[simp, norm_cast] theorem coe_inter (s₁ s₂ : Finset α) : ↑(s₁ ∩ s₂) = (s₁ ∩ s₂ : Set α) := Set.ext fun _ => mem_inter #align finset.coe_inter Finset.coe_inter @[simp] theorem union_inter_cancel_left {s t : Finset α} : (s ∪ t) ∩ s = s := by rw [← coe_inj, coe_inter, coe_union, Set.union_inter_cancel_left] #align finset.union_inter_cancel_left Finset.union_inter_cancel_left @[simp] theorem union_inter_cancel_right {s t : Finset α} : (s ∪ t) ∩ t = t := by rw [← coe_inj, coe_inter, coe_union, Set.union_inter_cancel_right] #align finset.union_inter_cancel_right Finset.union_inter_cancel_right theorem inter_comm (s₁ s₂ : Finset α) : s₁ ∩ s₂ = s₂ ∩ s₁ := ext fun _ => by simp only [mem_inter, and_comm] #align finset.inter_comm Finset.inter_comm @[simp] theorem inter_assoc (s₁ s₂ s₃ : Finset α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ (s₂ ∩ s₃) := ext fun _ => by simp only [mem_inter, and_assoc] #align finset.inter_assoc Finset.inter_assoc theorem inter_left_comm (s₁ s₂ s₃ : Finset α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := ext fun _ => by simp only [mem_inter, and_left_comm] #align finset.inter_left_comm Finset.inter_left_comm theorem inter_right_comm (s₁ s₂ s₃ : Finset α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ := ext fun _ => by simp only [mem_inter, and_right_comm] #align finset.inter_right_comm Finset.inter_right_comm @[simp] theorem inter_self (s : Finset α) : s ∩ s = s := ext fun _ => mem_inter.trans <| and_self_iff #align finset.inter_self Finset.inter_self @[simp] theorem inter_empty (s : Finset α) : s ∩ ∅ = ∅ := ext fun _ => mem_inter.trans <| by simp #align finset.inter_empty Finset.inter_empty @[simp] theorem empty_inter (s : Finset α) : ∅ ∩ s = ∅ := ext fun _ => mem_inter.trans <| by simp #align finset.empty_inter Finset.empty_inter @[simp] theorem inter_union_self (s t : Finset α) : s ∩ (t ∪ s) = s := by rw [inter_comm, union_inter_cancel_right] #align finset.inter_union_self Finset.inter_union_self @[simp] theorem insert_inter_of_mem {s₁ s₂ : Finset α} {a : α} (h : a ∈ s₂) : insert a s₁ ∩ s₂ = insert a (s₁ ∩ s₂) := ext fun x => by have : x = a ∨ x ∈ s₂ ↔ x ∈ s₂ := or_iff_right_of_imp <| by rintro rfl; exact h simp only [mem_inter, mem_insert, or_and_left, this] #align finset.insert_inter_of_mem Finset.insert_inter_of_mem @[simp] theorem inter_insert_of_mem {s₁ s₂ : Finset α} {a : α} (h : a ∈ s₁) : s₁ ∩ insert a s₂ = insert a (s₁ ∩ s₂) := by rw [inter_comm, insert_inter_of_mem h, inter_comm] #align finset.inter_insert_of_mem Finset.inter_insert_of_mem @[simp] theorem insert_inter_of_not_mem {s₁ s₂ : Finset α} {a : α} (h : a ∉ s₂) : insert a s₁ ∩ s₂ = s₁ ∩ s₂ := ext fun x => by have : ¬(x = a ∧ x ∈ s₂) := by rintro ⟨rfl, H⟩; exact h H simp only [mem_inter, mem_insert, or_and_right, this, false_or_iff] #align finset.insert_inter_of_not_mem Finset.insert_inter_of_not_mem @[simp] theorem inter_insert_of_not_mem {s₁ s₂ : Finset α} {a : α} (h : a ∉ s₁) : s₁ ∩ insert a s₂ = s₁ ∩ s₂ := by rw [inter_comm, insert_inter_of_not_mem h, inter_comm] #align finset.inter_insert_of_not_mem Finset.inter_insert_of_not_mem @[simp] theorem singleton_inter_of_mem {a : α} {s : Finset α} (H : a ∈ s) : {a} ∩ s = {a} := show insert a ∅ ∩ s = insert a ∅ by rw [insert_inter_of_mem H, empty_inter] #align finset.singleton_inter_of_mem Finset.singleton_inter_of_mem @[simp] theorem singleton_inter_of_not_mem {a : α} {s : Finset α} (H : a ∉ s) : {a} ∩ s = ∅ := eq_empty_of_forall_not_mem <| by simp only [mem_inter, mem_singleton]; rintro x ⟨rfl, h⟩; exact H h #align finset.singleton_inter_of_not_mem Finset.singleton_inter_of_not_mem @[simp] theorem inter_singleton_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ∩ {a} = {a} := by rw [inter_comm, singleton_inter_of_mem h] #align finset.inter_singleton_of_mem Finset.inter_singleton_of_mem @[simp] theorem inter_singleton_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : s ∩ {a} = ∅ := by rw [inter_comm, singleton_inter_of_not_mem h] #align finset.inter_singleton_of_not_mem Finset.inter_singleton_of_not_mem @[mono, gcongr] theorem inter_subset_inter {x y s t : Finset α} (h : x ⊆ y) (h' : s ⊆ t) : x ∩ s ⊆ y ∩ t := by intro a a_in rw [Finset.mem_inter] at a_in ⊢ exact ⟨h a_in.1, h' a_in.2⟩ #align finset.inter_subset_inter Finset.inter_subset_inter @[gcongr] theorem inter_subset_inter_left (h : t ⊆ u) : s ∩ t ⊆ s ∩ u := inter_subset_inter Subset.rfl h #align finset.inter_subset_inter_left Finset.inter_subset_inter_left @[gcongr] theorem inter_subset_inter_right (h : s ⊆ t) : s ∩ u ⊆ t ∩ u := inter_subset_inter h Subset.rfl #align finset.inter_subset_inter_right Finset.inter_subset_inter_right theorem inter_subset_union : s ∩ t ⊆ s ∪ t := le_iff_subset.1 inf_le_sup #align finset.inter_subset_union Finset.inter_subset_union instance : DistribLattice (Finset α) := { le_sup_inf := fun a b c => by simp (config := { contextual := true }) only [sup_eq_union, inf_eq_inter, le_eq_subset, subset_iff, mem_inter, mem_union, and_imp, or_imp, true_or_iff, imp_true_iff, true_and_iff, or_true_iff] } @[simp] theorem union_left_idem (s t : Finset α) : s ∪ (s ∪ t) = s ∪ t := sup_left_idem _ _ #align finset.union_left_idem Finset.union_left_idem -- Porting note (#10618): @[simp] can prove this theorem union_right_idem (s t : Finset α) : s ∪ t ∪ t = s ∪ t := sup_right_idem _ _ #align finset.union_right_idem Finset.union_right_idem @[simp] theorem inter_left_idem (s t : Finset α) : s ∩ (s ∩ t) = s ∩ t := inf_left_idem _ _ #align finset.inter_left_idem Finset.inter_left_idem -- Porting note (#10618): @[simp] can prove this theorem inter_right_idem (s t : Finset α) : s ∩ t ∩ t = s ∩ t := inf_right_idem _ _ #align finset.inter_right_idem Finset.inter_right_idem theorem inter_union_distrib_left (s t u : Finset α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u := inf_sup_left _ _ _ #align finset.inter_distrib_left Finset.inter_union_distrib_left theorem union_inter_distrib_right (s t u : Finset α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u := inf_sup_right _ _ _ #align finset.inter_distrib_right Finset.union_inter_distrib_right theorem union_inter_distrib_left (s t u : Finset α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) := sup_inf_left _ _ _ #align finset.union_distrib_left Finset.union_inter_distrib_left theorem inter_union_distrib_right (s t u : Finset α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) := sup_inf_right _ _ _ #align finset.union_distrib_right Finset.inter_union_distrib_right -- 2024-03-22 @[deprecated] alias inter_distrib_left := inter_union_distrib_left @[deprecated] alias inter_distrib_right := union_inter_distrib_right @[deprecated] alias union_distrib_left := union_inter_distrib_left @[deprecated] alias union_distrib_right := inter_union_distrib_right theorem union_union_distrib_left (s t u : Finset α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) := sup_sup_distrib_left _ _ _ #align finset.union_union_distrib_left Finset.union_union_distrib_left theorem union_union_distrib_right (s t u : Finset α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) := sup_sup_distrib_right _ _ _ #align finset.union_union_distrib_right Finset.union_union_distrib_right theorem inter_inter_distrib_left (s t u : Finset α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) := inf_inf_distrib_left _ _ _ #align finset.inter_inter_distrib_left Finset.inter_inter_distrib_left theorem inter_inter_distrib_right (s t u : Finset α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) := inf_inf_distrib_right _ _ _ #align finset.inter_inter_distrib_right Finset.inter_inter_distrib_right theorem union_union_union_comm (s t u v : Finset α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) := sup_sup_sup_comm _ _ _ _ #align finset.union_union_union_comm Finset.union_union_union_comm theorem inter_inter_inter_comm (s t u v : Finset α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) := inf_inf_inf_comm _ _ _ _ #align finset.inter_inter_inter_comm Finset.inter_inter_inter_comm lemma union_eq_empty : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := sup_eq_bot_iff #align finset.union_eq_empty_iff Finset.union_eq_empty theorem union_subset_iff : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u := (sup_le_iff : s ⊔ t ≤ u ↔ s ≤ u ∧ t ≤ u) #align finset.union_subset_iff Finset.union_subset_iff theorem subset_inter_iff : s ⊆ t ∩ u ↔ s ⊆ t ∧ s ⊆ u := (le_inf_iff : s ≤ t ⊓ u ↔ s ≤ t ∧ s ≤ u) #align finset.subset_inter_iff Finset.subset_inter_iff @[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left #align finset.inter_eq_left_iff_subset_iff_subset Finset.inter_eq_left @[simp] lemma inter_eq_right : t ∩ s = s ↔ s ⊆ t := inf_eq_right #align finset.inter_eq_right_iff_subset Finset.inter_eq_right theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u := inf_congr_left ht hu #align finset.inter_congr_left Finset.inter_congr_left theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u := inf_congr_right hs ht #align finset.inter_congr_right Finset.inter_congr_right theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u := inf_eq_inf_iff_left #align finset.inter_eq_inter_iff_left Finset.inter_eq_inter_iff_left theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t := inf_eq_inf_iff_right #align finset.inter_eq_inter_iff_right Finset.inter_eq_inter_iff_right theorem ite_subset_union (s s' : Finset α) (P : Prop) [Decidable P] : ite P s s' ⊆ s ∪ s' := ite_le_sup s s' P #align finset.ite_subset_union Finset.ite_subset_union theorem inter_subset_ite (s s' : Finset α) (P : Prop) [Decidable P] : s ∩ s' ⊆ ite P s s' := inf_le_ite s s' P #align finset.inter_subset_ite Finset.inter_subset_ite theorem not_disjoint_iff_nonempty_inter : ¬Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff.trans <| by simp [Finset.Nonempty] #align finset.not_disjoint_iff_nonempty_inter Finset.not_disjoint_iff_nonempty_inter alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter #align finset.nonempty.not_disjoint Finset.Nonempty.not_disjoint theorem disjoint_or_nonempty_inter (s t : Finset α) : Disjoint s t ∨ (s ∩ t).Nonempty := by rw [← not_disjoint_iff_nonempty_inter] exact em _ #align finset.disjoint_or_nonempty_inter Finset.disjoint_or_nonempty_inter end Lattice instance isDirected_le : IsDirected (Finset α) (· ≤ ·) := by classical infer_instance instance isDirected_subset : IsDirected (Finset α) (· ⊆ ·) := isDirected_le /-! ### erase -/ section Erase variable [DecidableEq α] {s t u v : Finset α} {a b : α} /-- `erase s a` is the set `s - {a}`, that is, the elements of `s` which are not equal to `a`. -/ def erase (s : Finset α) (a : α) : Finset α := ⟨_, s.2.erase a⟩ #align finset.erase Finset.erase @[simp] theorem erase_val (s : Finset α) (a : α) : (erase s a).1 = s.1.erase a := rfl #align finset.erase_val Finset.erase_val @[simp] theorem mem_erase {a b : α} {s : Finset α} : a ∈ erase s b ↔ a ≠ b ∧ a ∈ s := s.2.mem_erase_iff #align finset.mem_erase Finset.mem_erase theorem not_mem_erase (a : α) (s : Finset α) : a ∉ erase s a := s.2.not_mem_erase #align finset.not_mem_erase Finset.not_mem_erase -- While this can be solved by `simp`, this lemma is eligible for `dsimp` @[nolint simpNF, simp] theorem erase_empty (a : α) : erase ∅ a = ∅ := rfl #align finset.erase_empty Finset.erase_empty protected lemma Nontrivial.erase_nonempty (hs : s.Nontrivial) : (s.erase a).Nonempty := (hs.exists_ne a).imp $ by aesop @[simp] lemma erase_nonempty (ha : a ∈ s) : (s.erase a).Nonempty ↔ s.Nontrivial := by simp only [Finset.Nonempty, mem_erase, and_comm (b := _ ∈ _)] refine ⟨?_, fun hs ↦ hs.exists_ne a⟩ rintro ⟨b, hb, hba⟩ exact ⟨_, hb, _, ha, hba⟩ @[simp] theorem erase_singleton (a : α) : ({a} : Finset α).erase a = ∅ := by ext x simp #align finset.erase_singleton Finset.erase_singleton theorem ne_of_mem_erase : b ∈ erase s a → b ≠ a := fun h => (mem_erase.1 h).1 #align finset.ne_of_mem_erase Finset.ne_of_mem_erase theorem mem_of_mem_erase : b ∈ erase s a → b ∈ s := Multiset.mem_of_mem_erase #align finset.mem_of_mem_erase Finset.mem_of_mem_erase theorem mem_erase_of_ne_of_mem : a ≠ b → a ∈ s → a ∈ erase s b := by simp only [mem_erase]; exact And.intro #align finset.mem_erase_of_ne_of_mem Finset.mem_erase_of_ne_of_mem /-- An element of `s` that is not an element of `erase s a` must be`a`. -/ theorem eq_of_mem_of_not_mem_erase (hs : b ∈ s) (hsa : b ∉ s.erase a) : b = a := by rw [mem_erase, not_and] at hsa exact not_imp_not.mp hsa hs #align finset.eq_of_mem_of_not_mem_erase Finset.eq_of_mem_of_not_mem_erase @[simp] theorem erase_eq_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : erase s a = s := eq_of_veq <| erase_of_not_mem h #align finset.erase_eq_of_not_mem Finset.erase_eq_of_not_mem @[simp] theorem erase_eq_self : s.erase a = s ↔ a ∉ s := ⟨fun h => h ▸ not_mem_erase _ _, erase_eq_of_not_mem⟩ #align finset.erase_eq_self Finset.erase_eq_self @[simp] theorem erase_insert_eq_erase (s : Finset α) (a : α) : (insert a s).erase a = s.erase a := ext fun x => by simp (config := { contextual := true }) only [mem_erase, mem_insert, and_congr_right_iff, false_or_iff, iff_self_iff, imp_true_iff] #align finset.erase_insert_eq_erase Finset.erase_insert_eq_erase theorem erase_insert {a : α} {s : Finset α} (h : a ∉ s) : erase (insert a s) a = s := by rw [erase_insert_eq_erase, erase_eq_of_not_mem h] #align finset.erase_insert Finset.erase_insert theorem erase_insert_of_ne {a b : α} {s : Finset α} (h : a ≠ b) : erase (insert a s) b = insert a (erase s b) := ext fun x => by have : x ≠ b ∧ x = a ↔ x = a := and_iff_right_of_imp fun hx => hx.symm ▸ h simp only [mem_erase, mem_insert, and_or_left, this] #align finset.erase_insert_of_ne Finset.erase_insert_of_ne theorem erase_cons_of_ne {a b : α} {s : Finset α} (ha : a ∉ s) (hb : a ≠ b) : erase (cons a s ha) b = cons a (erase s b) fun h => ha <| erase_subset _ _ h := by simp only [cons_eq_insert, erase_insert_of_ne hb] #align finset.erase_cons_of_ne Finset.erase_cons_of_ne @[simp] theorem insert_erase (h : a ∈ s) : insert a (erase s a) = s := ext fun x => by simp only [mem_insert, mem_erase, or_and_left, dec_em, true_and_iff] apply or_iff_right_of_imp rintro rfl exact h #align finset.insert_erase Finset.insert_erase lemma erase_eq_iff_eq_insert (hs : a ∈ s) (ht : a ∉ t) : erase s a = t ↔ s = insert a t := by aesop lemma insert_erase_invOn : Set.InvOn (insert a) (fun s ↦ erase s a) {s : Finset α | a ∈ s} {s : Finset α | a ∉ s} := ⟨fun _s ↦ insert_erase, fun _s ↦ erase_insert⟩ theorem erase_subset_erase (a : α) {s t : Finset α} (h : s ⊆ t) : erase s a ⊆ erase t a := val_le_iff.1 <| erase_le_erase _ <| val_le_iff.2 h #align finset.erase_subset_erase Finset.erase_subset_erase theorem erase_subset (a : α) (s : Finset α) : erase s a ⊆ s := Multiset.erase_subset _ _ #align finset.erase_subset Finset.erase_subset theorem subset_erase {a : α} {s t : Finset α} : s ⊆ t.erase a ↔ s ⊆ t ∧ a ∉ s := ⟨fun h => ⟨h.trans (erase_subset _ _), fun ha => not_mem_erase _ _ (h ha)⟩, fun h _b hb => mem_erase.2 ⟨ne_of_mem_of_not_mem hb h.2, h.1 hb⟩⟩ #align finset.subset_erase Finset.subset_erase @[simp, norm_cast] theorem coe_erase (a : α) (s : Finset α) : ↑(erase s a) = (s \ {a} : Set α) := Set.ext fun _ => mem_erase.trans <| by rw [and_comm, Set.mem_diff, Set.mem_singleton_iff, mem_coe] #align finset.coe_erase Finset.coe_erase theorem erase_ssubset {a : α} {s : Finset α} (h : a ∈ s) : s.erase a ⊂ s := calc s.erase a ⊂ insert a (s.erase a) := ssubset_insert <| not_mem_erase _ _ _ = _ := insert_erase h #align finset.erase_ssubset Finset.erase_ssubset theorem ssubset_iff_exists_subset_erase {s t : Finset α} : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t.erase a := by refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_subset_of_ssubset h <| erase_ssubset ha⟩ obtain ⟨a, ht, hs⟩ := not_subset.1 h.2 exact ⟨a, ht, subset_erase.2 ⟨h.1, hs⟩⟩ #align finset.ssubset_iff_exists_subset_erase Finset.ssubset_iff_exists_subset_erase theorem erase_ssubset_insert (s : Finset α) (a : α) : s.erase a ⊂ insert a s := ssubset_iff_exists_subset_erase.2 ⟨a, mem_insert_self _ _, erase_subset_erase _ <| subset_insert _ _⟩ #align finset.erase_ssubset_insert Finset.erase_ssubset_insert theorem erase_ne_self : s.erase a ≠ s ↔ a ∈ s := erase_eq_self.not_left #align finset.erase_ne_self Finset.erase_ne_self theorem erase_cons {s : Finset α} {a : α} (h : a ∉ s) : (s.cons a h).erase a = s := by rw [cons_eq_insert, erase_insert_eq_erase, erase_eq_of_not_mem h] #align finset.erase_cons Finset.erase_cons theorem erase_idem {a : α} {s : Finset α} : erase (erase s a) a = erase s a := by simp #align finset.erase_idem Finset.erase_idem theorem erase_right_comm {a b : α} {s : Finset α} : erase (erase s a) b = erase (erase s b) a := by ext x simp only [mem_erase, ← and_assoc] rw [@and_comm (x ≠ a)] #align finset.erase_right_comm Finset.erase_right_comm theorem subset_insert_iff {a : α} {s t : Finset α} : s ⊆ insert a t ↔ erase s a ⊆ t := by simp only [subset_iff, or_iff_not_imp_left, mem_erase, mem_insert, and_imp] exact forall_congr' fun x => forall_swap #align finset.subset_insert_iff Finset.subset_insert_iff theorem erase_insert_subset (a : α) (s : Finset α) : erase (insert a s) a ⊆ s := subset_insert_iff.1 <| Subset.rfl #align finset.erase_insert_subset Finset.erase_insert_subset theorem insert_erase_subset (a : α) (s : Finset α) : s ⊆ insert a (erase s a) := subset_insert_iff.2 <| Subset.rfl #align finset.insert_erase_subset Finset.insert_erase_subset theorem subset_insert_iff_of_not_mem (h : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t := by rw [subset_insert_iff, erase_eq_of_not_mem h] #align finset.subset_insert_iff_of_not_mem Finset.subset_insert_iff_of_not_mem theorem erase_subset_iff_of_mem (h : a ∈ t) : s.erase a ⊆ t ↔ s ⊆ t := by rw [← subset_insert_iff, insert_eq_of_mem h] #align finset.erase_subset_iff_of_mem Finset.erase_subset_iff_of_mem theorem erase_inj {x y : α} (s : Finset α) (hx : x ∈ s) : s.erase x = s.erase y ↔ x = y := by refine ⟨fun h => eq_of_mem_of_not_mem_erase hx ?_, congr_arg _⟩ rw [← h] simp #align finset.erase_inj Finset.erase_inj theorem erase_injOn (s : Finset α) : Set.InjOn s.erase s := fun _ _ _ _ => (erase_inj s ‹_›).mp #align finset.erase_inj_on Finset.erase_injOn theorem erase_injOn' (a : α) : { s : Finset α | a ∈ s }.InjOn fun s => erase s a := fun s hs t ht (h : s.erase a = _) => by rw [← insert_erase hs, ← insert_erase ht, h] #align finset.erase_inj_on' Finset.erase_injOn' end Erase lemma Nontrivial.exists_cons_eq {s : Finset α} (hs : s.Nontrivial) : ∃ t a ha b hb hab, (cons b t hb).cons a (mem_cons.not.2 <| not_or_intro hab ha) = s := by classical obtain ⟨a, ha, b, hb, hab⟩ := hs have : b ∈ s.erase a := mem_erase.2 ⟨hab.symm, hb⟩ refine ⟨(s.erase a).erase b, a, ?_, b, ?_, ?_, ?_⟩ <;> simp [insert_erase this, insert_erase ha, *] /-! ### sdiff -/ section Sdiff variable [DecidableEq α] {s t u v : Finset α} {a b : α} /-- `s \ t` is the set consisting of the elements of `s` that are not in `t`. -/ instance : SDiff (Finset α) := ⟨fun s₁ s₂ => ⟨s₁.1 - s₂.1, nodup_of_le tsub_le_self s₁.2⟩⟩ @[simp] theorem sdiff_val (s₁ s₂ : Finset α) : (s₁ \ s₂).val = s₁.val - s₂.val := rfl #align finset.sdiff_val Finset.sdiff_val @[simp] theorem mem_sdiff : a ∈ s \ t ↔ a ∈ s ∧ a ∉ t := mem_sub_of_nodup s.2 #align finset.mem_sdiff Finset.mem_sdiff @[simp] theorem inter_sdiff_self (s₁ s₂ : Finset α) : s₁ ∩ (s₂ \ s₁) = ∅ := eq_empty_of_forall_not_mem <| by simp only [mem_inter, mem_sdiff]; rintro x ⟨h, _, hn⟩; exact hn h #align finset.inter_sdiff_self Finset.inter_sdiff_self instance : GeneralizedBooleanAlgebra (Finset α) := { sup_inf_sdiff := fun x y => by simp only [ext_iff, mem_union, mem_sdiff, inf_eq_inter, sup_eq_union, mem_inter, ← and_or_left, em, and_true, implies_true] inf_inf_sdiff := fun x y => by simp only [ext_iff, inter_sdiff_self, inter_empty, inter_assoc, false_iff_iff, inf_eq_inter, not_mem_empty, bot_eq_empty, not_false_iff, implies_true] } theorem not_mem_sdiff_of_mem_right (h : a ∈ t) : a ∉ s \ t := by simp only [mem_sdiff, h, not_true, not_false_iff, and_false_iff] #align finset.not_mem_sdiff_of_mem_right Finset.not_mem_sdiff_of_mem_right theorem not_mem_sdiff_of_not_mem_left (h : a ∉ s) : a ∉ s \ t := by simp [h] #align finset.not_mem_sdiff_of_not_mem_left Finset.not_mem_sdiff_of_not_mem_left theorem union_sdiff_of_subset (h : s ⊆ t) : s ∪ t \ s = t := sup_sdiff_cancel_right h #align finset.union_sdiff_of_subset Finset.union_sdiff_of_subset theorem sdiff_union_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₂ \ s₁ ∪ s₁ = s₂ := (union_comm _ _).trans (union_sdiff_of_subset h) #align finset.sdiff_union_of_subset Finset.sdiff_union_of_subset lemma inter_sdiff_assoc (s t u : Finset α) : (s ∩ t) \ u = s ∩ (t \ u) := by ext x; simp [and_assoc] @[deprecated inter_sdiff_assoc (since := "2024-05-01")] theorem inter_sdiff (s t u : Finset α) : s ∩ (t \ u) = (s ∩ t) \ u := (inter_sdiff_assoc _ _ _).symm #align finset.inter_sdiff Finset.inter_sdiff @[simp] theorem sdiff_inter_self (s₁ s₂ : Finset α) : s₂ \ s₁ ∩ s₁ = ∅ := inf_sdiff_self_left #align finset.sdiff_inter_self Finset.sdiff_inter_self -- Porting note (#10618): @[simp] can prove this protected theorem sdiff_self (s₁ : Finset α) : s₁ \ s₁ = ∅ := _root_.sdiff_self #align finset.sdiff_self Finset.sdiff_self theorem sdiff_inter_distrib_right (s t u : Finset α) : s \ (t ∩ u) = s \ t ∪ s \ u := sdiff_inf #align finset.sdiff_inter_distrib_right Finset.sdiff_inter_distrib_right @[simp] theorem sdiff_inter_self_left (s t : Finset α) : s \ (s ∩ t) = s \ t := sdiff_inf_self_left _ _ #align finset.sdiff_inter_self_left Finset.sdiff_inter_self_left @[simp] theorem sdiff_inter_self_right (s t : Finset α) : s \ (t ∩ s) = s \ t := sdiff_inf_self_right _ _ #align finset.sdiff_inter_self_right Finset.sdiff_inter_self_right @[simp] theorem sdiff_empty : s \ ∅ = s := sdiff_bot #align finset.sdiff_empty Finset.sdiff_empty @[mono, gcongr] theorem sdiff_subset_sdiff (hst : s ⊆ t) (hvu : v ⊆ u) : s \ u ⊆ t \ v := sdiff_le_sdiff hst hvu #align finset.sdiff_subset_sdiff Finset.sdiff_subset_sdiff @[simp, norm_cast] theorem coe_sdiff (s₁ s₂ : Finset α) : ↑(s₁ \ s₂) = (s₁ \ s₂ : Set α) := Set.ext fun _ => mem_sdiff #align finset.coe_sdiff Finset.coe_sdiff @[simp] theorem union_sdiff_self_eq_union : s ∪ t \ s = s ∪ t := sup_sdiff_self_right _ _ #align finset.union_sdiff_self_eq_union Finset.union_sdiff_self_eq_union @[simp] theorem sdiff_union_self_eq_union : s \ t ∪ t = s ∪ t := sup_sdiff_self_left _ _ #align finset.sdiff_union_self_eq_union Finset.sdiff_union_self_eq_union theorem union_sdiff_left (s t : Finset α) : (s ∪ t) \ s = t \ s := sup_sdiff_left_self #align finset.union_sdiff_left Finset.union_sdiff_left theorem union_sdiff_right (s t : Finset α) : (s ∪ t) \ t = s \ t := sup_sdiff_right_self #align finset.union_sdiff_right Finset.union_sdiff_right theorem union_sdiff_cancel_left (h : Disjoint s t) : (s ∪ t) \ s = t := h.sup_sdiff_cancel_left #align finset.union_sdiff_cancel_left Finset.union_sdiff_cancel_left theorem union_sdiff_cancel_right (h : Disjoint s t) : (s ∪ t) \ t = s := h.sup_sdiff_cancel_right #align finset.union_sdiff_cancel_right Finset.union_sdiff_cancel_right theorem union_sdiff_symm : s ∪ t \ s = t ∪ s \ t := by simp [union_comm] #align finset.union_sdiff_symm Finset.union_sdiff_symm theorem sdiff_union_inter (s t : Finset α) : s \ t ∪ s ∩ t = s := sup_sdiff_inf _ _ #align finset.sdiff_union_inter Finset.sdiff_union_inter -- Porting note (#10618): @[simp] can prove this theorem sdiff_idem (s t : Finset α) : (s \ t) \ t = s \ t := _root_.sdiff_idem #align finset.sdiff_idem Finset.sdiff_idem theorem subset_sdiff : s ⊆ t \ u ↔ s ⊆ t ∧ Disjoint s u := le_iff_subset.symm.trans le_sdiff #align finset.subset_sdiff Finset.subset_sdiff @[simp] theorem sdiff_eq_empty_iff_subset : s \ t = ∅ ↔ s ⊆ t := sdiff_eq_bot_iff #align finset.sdiff_eq_empty_iff_subset Finset.sdiff_eq_empty_iff_subset theorem sdiff_nonempty : (s \ t).Nonempty ↔ ¬s ⊆ t := nonempty_iff_ne_empty.trans sdiff_eq_empty_iff_subset.not #align finset.sdiff_nonempty Finset.sdiff_nonempty @[simp] theorem empty_sdiff (s : Finset α) : ∅ \ s = ∅ := bot_sdiff #align finset.empty_sdiff Finset.empty_sdiff theorem insert_sdiff_of_not_mem (s : Finset α) {t : Finset α} {x : α} (h : x ∉ t) : insert x s \ t = insert x (s \ t) := by rw [← coe_inj, coe_insert, coe_sdiff, coe_sdiff, coe_insert] exact Set.insert_diff_of_not_mem _ h #align finset.insert_sdiff_of_not_mem Finset.insert_sdiff_of_not_mem theorem insert_sdiff_of_mem (s : Finset α) {x : α} (h : x ∈ t) : insert x s \ t = s \ t := by rw [← coe_inj, coe_sdiff, coe_sdiff, coe_insert] exact Set.insert_diff_of_mem _ h #align finset.insert_sdiff_of_mem Finset.insert_sdiff_of_mem @[simp] lemma insert_sdiff_cancel (ha : a ∉ s) : insert a s \ s = {a} := by rw [insert_sdiff_of_not_mem _ ha, Finset.sdiff_self, insert_emptyc_eq] @[simp] theorem insert_sdiff_insert (s t : Finset α) (x : α) : insert x s \ insert x t = s \ insert x t := insert_sdiff_of_mem _ (mem_insert_self _ _) #align finset.insert_sdiff_insert Finset.insert_sdiff_insert lemma insert_sdiff_insert' (hab : a ≠ b) (ha : a ∉ s) : insert a s \ insert b s = {a} := by ext; aesop lemma erase_sdiff_erase (hab : a ≠ b) (hb : b ∈ s) : s.erase a \ s.erase b = {b} := by ext; aesop lemma cons_sdiff_cons (hab : a ≠ b) (ha hb) : s.cons a ha \ s.cons b hb = {a} := by rw [cons_eq_insert, cons_eq_insert, insert_sdiff_insert' hab ha] theorem sdiff_insert_of_not_mem {x : α} (h : x ∉ s) (t : Finset α) : s \ insert x t = s \ t := by refine Subset.antisymm (sdiff_subset_sdiff (Subset.refl _) (subset_insert _ _)) fun y hy => ?_ simp only [mem_sdiff, mem_insert, not_or] at hy ⊢ exact ⟨hy.1, fun hxy => h <| hxy ▸ hy.1, hy.2⟩ #align finset.sdiff_insert_of_not_mem Finset.sdiff_insert_of_not_mem @[simp] theorem sdiff_subset {s t : Finset α} : s \ t ⊆ s := le_iff_subset.mp sdiff_le #align finset.sdiff_subset Finset.sdiff_subset theorem sdiff_ssubset (h : t ⊆ s) (ht : t.Nonempty) : s \ t ⊂ s := sdiff_lt (le_iff_subset.mpr h) ht.ne_empty #align finset.sdiff_ssubset Finset.sdiff_ssubset theorem union_sdiff_distrib (s₁ s₂ t : Finset α) : (s₁ ∪ s₂) \ t = s₁ \ t ∪ s₂ \ t := sup_sdiff #align finset.union_sdiff_distrib Finset.union_sdiff_distrib theorem sdiff_union_distrib (s t₁ t₂ : Finset α) : s \ (t₁ ∪ t₂) = s \ t₁ ∩ (s \ t₂) := sdiff_sup #align finset.sdiff_union_distrib Finset.sdiff_union_distrib theorem union_sdiff_self (s t : Finset α) : (s ∪ t) \ t = s \ t := sup_sdiff_right_self #align finset.union_sdiff_self Finset.union_sdiff_self -- TODO: Do we want to delete this lemma and `Finset.disjUnion_singleton`, -- or instead add `Finset.union_singleton`/`Finset.singleton_union`? theorem sdiff_singleton_eq_erase (a : α) (s : Finset α) : s \ singleton a = erase s a := by ext rw [mem_erase, mem_sdiff, mem_singleton, and_comm] #align finset.sdiff_singleton_eq_erase Finset.sdiff_singleton_eq_erase -- This lemma matches `Finset.insert_eq` in functionality. theorem erase_eq (s : Finset α) (a : α) : s.erase a = s \ {a} := (sdiff_singleton_eq_erase _ _).symm #align finset.erase_eq Finset.erase_eq theorem disjoint_erase_comm : Disjoint (s.erase a) t ↔ Disjoint s (t.erase a) := by simp_rw [erase_eq, disjoint_sdiff_comm] #align finset.disjoint_erase_comm Finset.disjoint_erase_comm lemma disjoint_insert_erase (ha : a ∉ t) : Disjoint (s.erase a) (insert a t) ↔ Disjoint s t := by rw [disjoint_erase_comm, erase_insert ha] lemma disjoint_erase_insert (ha : a ∉ s) : Disjoint (insert a s) (t.erase a) ↔ Disjoint s t := by rw [← disjoint_erase_comm, erase_insert ha] theorem disjoint_of_erase_left (ha : a ∉ t) (hst : Disjoint (s.erase a) t) : Disjoint s t := by rw [← erase_insert ha, ← disjoint_erase_comm, disjoint_insert_right] exact ⟨not_mem_erase _ _, hst⟩ #align finset.disjoint_of_erase_left Finset.disjoint_of_erase_left theorem disjoint_of_erase_right (ha : a ∉ s) (hst : Disjoint s (t.erase a)) : Disjoint s t := by rw [← erase_insert ha, disjoint_erase_comm, disjoint_insert_left] exact ⟨not_mem_erase _ _, hst⟩ #align finset.disjoint_of_erase_right Finset.disjoint_of_erase_right theorem inter_erase (a : α) (s t : Finset α) : s ∩ t.erase a = (s ∩ t).erase a := by simp only [erase_eq, inter_sdiff_assoc] #align finset.inter_erase Finset.inter_erase @[simp] theorem erase_inter (a : α) (s t : Finset α) : s.erase a ∩ t = (s ∩ t).erase a := by simpa only [inter_comm t] using inter_erase a t s #align finset.erase_inter Finset.erase_inter theorem erase_sdiff_comm (s t : Finset α) (a : α) : s.erase a \ t = (s \ t).erase a := by simp_rw [erase_eq, sdiff_right_comm] #align finset.erase_sdiff_comm Finset.erase_sdiff_comm theorem insert_union_comm (s t : Finset α) (a : α) : insert a s ∪ t = s ∪ insert a t := by rw [insert_union, union_insert] #align finset.insert_union_comm Finset.insert_union_comm theorem erase_inter_comm (s t : Finset α) (a : α) : s.erase a ∩ t = s ∩ t.erase a := by rw [erase_inter, inter_erase] #align finset.erase_inter_comm Finset.erase_inter_comm theorem erase_union_distrib (s t : Finset α) (a : α) : (s ∪ t).erase a = s.erase a ∪ t.erase a := by simp_rw [erase_eq, union_sdiff_distrib] #align finset.erase_union_distrib Finset.erase_union_distrib theorem insert_inter_distrib (s t : Finset α) (a : α) : insert a (s ∩ t) = insert a s ∩ insert a t := by simp_rw [insert_eq, union_inter_distrib_left] #align finset.insert_inter_distrib Finset.insert_inter_distrib theorem erase_sdiff_distrib (s t : Finset α) (a : α) : (s \ t).erase a = s.erase a \ t.erase a := by simp_rw [erase_eq, sdiff_sdiff, sup_sdiff_eq_sup le_rfl, sup_comm] #align finset.erase_sdiff_distrib Finset.erase_sdiff_distrib theorem erase_union_of_mem (ha : a ∈ t) (s : Finset α) : s.erase a ∪ t = s ∪ t := by rw [← insert_erase (mem_union_right s ha), erase_union_distrib, ← union_insert, insert_erase ha] #align finset.erase_union_of_mem Finset.erase_union_of_mem theorem union_erase_of_mem (ha : a ∈ s) (t : Finset α) : s ∪ t.erase a = s ∪ t := by rw [← insert_erase (mem_union_left t ha), erase_union_distrib, ← insert_union, insert_erase ha] #align finset.union_erase_of_mem Finset.union_erase_of_mem @[simp] theorem sdiff_singleton_eq_self (ha : a ∉ s) : s \ {a} = s := sdiff_eq_self_iff_disjoint.2 <| by simp [ha] #align finset.sdiff_singleton_eq_self Finset.sdiff_singleton_eq_self theorem Nontrivial.sdiff_singleton_nonempty {c : α} {s : Finset α} (hS : s.Nontrivial) : (s \ {c}).Nonempty := by rw [Finset.sdiff_nonempty, Finset.subset_singleton_iff] push_neg exact ⟨by rintro rfl; exact Finset.not_nontrivial_empty hS, hS.ne_singleton⟩ theorem sdiff_sdiff_left' (s t u : Finset α) : (s \ t) \ u = s \ t ∩ (s \ u) := _root_.sdiff_sdiff_left' #align finset.sdiff_sdiff_left' Finset.sdiff_sdiff_left' theorem sdiff_union_sdiff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u := sdiff_sup_sdiff_cancel hts hut #align finset.sdiff_union_sdiff_cancel Finset.sdiff_union_sdiff_cancel theorem sdiff_union_erase_cancel (hts : t ⊆ s) (ha : a ∈ t) : s \ t ∪ t.erase a = s.erase a := by simp_rw [erase_eq, sdiff_union_sdiff_cancel hts (singleton_subset_iff.2 ha)] #align finset.sdiff_union_erase_cancel Finset.sdiff_union_erase_cancel theorem sdiff_sdiff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h #align finset.sdiff_sdiff_eq_sdiff_union Finset.sdiff_sdiff_eq_sdiff_union theorem sdiff_insert (s t : Finset α) (x : α) : s \ insert x t = (s \ t).erase x := by simp_rw [← sdiff_singleton_eq_erase, insert_eq, sdiff_sdiff_left', sdiff_union_distrib, inter_comm] #align finset.sdiff_insert Finset.sdiff_insert theorem sdiff_insert_insert_of_mem_of_not_mem {s t : Finset α} {x : α} (hxs : x ∈ s) (hxt : x ∉ t) : insert x (s \ insert x t) = s \ t := by rw [sdiff_insert, insert_erase (mem_sdiff.mpr ⟨hxs, hxt⟩)] #align finset.sdiff_insert_insert_of_mem_of_not_mem Finset.sdiff_insert_insert_of_mem_of_not_mem theorem sdiff_erase (h : a ∈ s) : s \ t.erase a = insert a (s \ t) := by rw [← sdiff_singleton_eq_erase, sdiff_sdiff_eq_sdiff_union (singleton_subset_iff.2 h), insert_eq, union_comm] #align finset.sdiff_erase Finset.sdiff_erase theorem sdiff_erase_self (ha : a ∈ s) : s \ s.erase a = {a} := by rw [sdiff_erase ha, Finset.sdiff_self, insert_emptyc_eq] #align finset.sdiff_erase_self Finset.sdiff_erase_self theorem sdiff_sdiff_self_left (s t : Finset α) : s \ (s \ t) = s ∩ t := sdiff_sdiff_right_self #align finset.sdiff_sdiff_self_left Finset.sdiff_sdiff_self_left theorem sdiff_sdiff_eq_self (h : t ⊆ s) : s \ (s \ t) = t := _root_.sdiff_sdiff_eq_self h #align finset.sdiff_sdiff_eq_self Finset.sdiff_sdiff_eq_self theorem sdiff_eq_sdiff_iff_inter_eq_inter {s t₁ t₂ : Finset α} : s \ t₁ = s \ t₂ ↔ s ∩ t₁ = s ∩ t₂ := sdiff_eq_sdiff_iff_inf_eq_inf #align finset.sdiff_eq_sdiff_iff_inter_eq_inter Finset.sdiff_eq_sdiff_iff_inter_eq_inter theorem union_eq_sdiff_union_sdiff_union_inter (s t : Finset α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t := sup_eq_sdiff_sup_sdiff_sup_inf #align finset.union_eq_sdiff_union_sdiff_union_inter Finset.union_eq_sdiff_union_sdiff_union_inter theorem erase_eq_empty_iff (s : Finset α) (a : α) : s.erase a = ∅ ↔ s = ∅ ∨ s = {a} := by rw [← sdiff_singleton_eq_erase, sdiff_eq_empty_iff_subset, subset_singleton_iff] #align finset.erase_eq_empty_iff Finset.erase_eq_empty_iff --TODO@Yaël: Kill lemmas duplicate with `BooleanAlgebra` theorem sdiff_disjoint : Disjoint (t \ s) s := disjoint_left.2 fun _a ha => (mem_sdiff.1 ha).2 #align finset.sdiff_disjoint Finset.sdiff_disjoint theorem disjoint_sdiff : Disjoint s (t \ s) := sdiff_disjoint.symm #align finset.disjoint_sdiff Finset.disjoint_sdiff theorem disjoint_sdiff_inter (s t : Finset α) : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right sdiff_disjoint #align finset.disjoint_sdiff_inter Finset.disjoint_sdiff_inter theorem sdiff_eq_self_iff_disjoint : s \ t = s ↔ Disjoint s t := sdiff_eq_self_iff_disjoint' #align finset.sdiff_eq_self_iff_disjoint Finset.sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_of_disjoint (h : Disjoint s t) : s \ t = s := sdiff_eq_self_iff_disjoint.2 h #align finset.sdiff_eq_self_of_disjoint Finset.sdiff_eq_self_of_disjoint end Sdiff /-! ### Symmetric difference -/ section SymmDiff open scoped symmDiff variable [DecidableEq α] {s t : Finset α} {a b : α} theorem mem_symmDiff : a ∈ s ∆ t ↔ a ∈ s ∧ a ∉ t ∨ a ∈ t ∧ a ∉ s := by simp_rw [symmDiff, sup_eq_union, mem_union, mem_sdiff] #align finset.mem_symm_diff Finset.mem_symmDiff @[simp, norm_cast] theorem coe_symmDiff : (↑(s ∆ t) : Set α) = (s : Set α) ∆ t := Set.ext fun x => by simp [mem_symmDiff, Set.mem_symmDiff] #align finset.coe_symm_diff Finset.coe_symmDiff @[simp] lemma symmDiff_eq_empty : s ∆ t = ∅ ↔ s = t := symmDiff_eq_bot @[simp] lemma symmDiff_nonempty : (s ∆ t).Nonempty ↔ s ≠ t := nonempty_iff_ne_empty.trans symmDiff_eq_empty.not end SymmDiff /-! ### attach -/ /-- `attach s` takes the elements of `s` and forms a new set of elements of the subtype `{x // x ∈ s}`. -/ def attach (s : Finset α) : Finset { x // x ∈ s } := ⟨Multiset.attach s.1, nodup_attach.2 s.2⟩ #align finset.attach Finset.attach theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Finset α} (hx : x ∈ s) : SizeOf.sizeOf x < SizeOf.sizeOf s := by cases s dsimp [SizeOf.sizeOf, SizeOf.sizeOf, Multiset.sizeOf] rw [add_comm] refine lt_trans ?_ (Nat.lt_succ_self _) exact Multiset.sizeOf_lt_sizeOf_of_mem hx #align finset.sizeof_lt_sizeof_of_mem Finset.sizeOf_lt_sizeOf_of_mem @[simp] theorem attach_val (s : Finset α) : s.attach.1 = s.1.attach := rfl #align finset.attach_val Finset.attach_val @[simp] theorem mem_attach (s : Finset α) : ∀ x, x ∈ s.attach := Multiset.mem_attach _ #align finset.mem_attach Finset.mem_attach @[simp] theorem attach_empty : attach (∅ : Finset α) = ∅ := rfl #align finset.attach_empty Finset.attach_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem attach_nonempty_iff {s : Finset α} : s.attach.Nonempty ↔ s.Nonempty := by simp [Finset.Nonempty] #align finset.attach_nonempty_iff Finset.attach_nonempty_iff protected alias ⟨_, Nonempty.attach⟩ := attach_nonempty_iff @[simp] theorem attach_eq_empty_iff {s : Finset α} : s.attach = ∅ ↔ s = ∅ := by simp [eq_empty_iff_forall_not_mem] #align finset.attach_eq_empty_iff Finset.attach_eq_empty_iff section DecidablePiExists variable {s : Finset α} instance decidableDforallFinset {p : ∀ a ∈ s, Prop} [_hp : ∀ (a) (h : a ∈ s), Decidable (p a h)] : Decidable (∀ (a) (h : a ∈ s), p a h) := Multiset.decidableDforallMultiset #align finset.decidable_dforall_finset Finset.decidableDforallFinset -- Porting note: In lean3, `decidableDforallFinset` was picked up when decidability of `s ⊆ t` was -- needed. In lean4 it seems this is not the case. instance instDecidableRelSubset [DecidableEq α] : @DecidableRel (Finset α) (· ⊆ ·) := fun _ _ ↦ decidableDforallFinset instance instDecidableRelSSubset [DecidableEq α] : @DecidableRel (Finset α) (· ⊂ ·) := fun _ _ ↦ instDecidableAnd instance instDecidableLE [DecidableEq α] : @DecidableRel (Finset α) (· ≤ ·) := instDecidableRelSubset instance instDecidableLT [DecidableEq α] : @DecidableRel (Finset α) (· < ·) := instDecidableRelSSubset instance decidableDExistsFinset {p : ∀ a ∈ s, Prop} [_hp : ∀ (a) (h : a ∈ s), Decidable (p a h)] : Decidable (∃ (a : _) (h : a ∈ s), p a h) := Multiset.decidableDexistsMultiset #align finset.decidable_dexists_finset Finset.decidableDExistsFinset instance decidableExistsAndFinset {p : α → Prop} [_hp : ∀ (a), Decidable (p a)] : Decidable (∃ a ∈ s, p a) := decidable_of_iff (∃ (a : _) (_ : a ∈ s), p a) (by simp) instance decidableExistsAndFinsetCoe {p : α → Prop} [DecidablePred p] : Decidable (∃ a ∈ (s : Set α), p a) := decidableExistsAndFinset /-- decidable equality for functions whose domain is bounded by finsets -/ instance decidableEqPiFinset {β : α → Type*} [_h : ∀ a, DecidableEq (β a)] : DecidableEq (∀ a ∈ s, β a) := Multiset.decidableEqPiMultiset #align finset.decidable_eq_pi_finset Finset.decidableEqPiFinset end DecidablePiExists /-! ### filter -/ section Filter variable (p q : α → Prop) [DecidablePred p] [DecidablePred q] {s : Finset α} /-- `Finset.filter p s` is the set of elements of `s` that satisfy `p`. For example, one can use `s.filter (· ∈ t)` to get the intersection of `s` with `t : Set α` as a `Finset α` (when a `DecidablePred (· ∈ t)` instance is available). -/ def filter (s : Finset α) : Finset α := ⟨_, s.2.filter p⟩ #align finset.filter Finset.filter @[simp] theorem filter_val (s : Finset α) : (filter p s).1 = s.1.filter p := rfl #align finset.filter_val Finset.filter_val @[simp] theorem filter_subset (s : Finset α) : s.filter p ⊆ s := Multiset.filter_subset _ _ #align finset.filter_subset Finset.filter_subset variable {p} @[simp] theorem mem_filter {s : Finset α} {a : α} : a ∈ s.filter p ↔ a ∈ s ∧ p a := Multiset.mem_filter #align finset.mem_filter Finset.mem_filter theorem mem_of_mem_filter {s : Finset α} (x : α) (h : x ∈ s.filter p) : x ∈ s := Multiset.mem_of_mem_filter h #align finset.mem_of_mem_filter Finset.mem_of_mem_filter theorem filter_ssubset {s : Finset α} : s.filter p ⊂ s ↔ ∃ x ∈ s, ¬p x := ⟨fun h => let ⟨x, hs, hp⟩ := Set.exists_of_ssubset h ⟨x, hs, mt (fun hp => mem_filter.2 ⟨hs, hp⟩) hp⟩, fun ⟨_, hs, hp⟩ => ⟨s.filter_subset _, fun h => hp (mem_filter.1 (h hs)).2⟩⟩ #align finset.filter_ssubset Finset.filter_ssubset variable (p) theorem filter_filter (s : Finset α) : (s.filter p).filter q = s.filter fun a => p a ∧ q a := ext fun a => by simp only [mem_filter, and_assoc, Bool.decide_and, Bool.decide_coe, Bool.and_eq_true] #align finset.filter_filter Finset.filter_filter theorem filter_comm (s : Finset α) : (s.filter p).filter q = (s.filter q).filter p := by simp_rw [filter_filter, and_comm] #align finset.filter_comm Finset.filter_comm -- We can replace an application of filter where the decidability is inferred in "the wrong way". theorem filter_congr_decidable (s : Finset α) (p : α → Prop) (h : DecidablePred p) [DecidablePred p] : @filter α p h s = s.filter p := by congr #align finset.filter_congr_decidable Finset.filter_congr_decidable @[simp] theorem filter_True {h} (s : Finset α) : @filter _ (fun _ => True) h s = s := by ext; simp #align finset.filter_true Finset.filter_True @[simp] theorem filter_False {h} (s : Finset α) : @filter _ (fun _ => False) h s = ∅ := by ext; simp #align finset.filter_false Finset.filter_False variable {p q} lemma filter_eq_self : s.filter p = s ↔ ∀ x ∈ s, p x := by simp [Finset.ext_iff] #align finset.filter_eq_self Finset.filter_eq_self theorem filter_eq_empty_iff : s.filter p = ∅ ↔ ∀ ⦃x⦄, x ∈ s → ¬p x := by simp [Finset.ext_iff] #align finset.filter_eq_empty_iff Finset.filter_eq_empty_iff theorem filter_nonempty_iff : (s.filter p).Nonempty ↔ ∃ a ∈ s, p a := by simp only [nonempty_iff_ne_empty, Ne, filter_eq_empty_iff, Classical.not_not, not_forall, exists_prop] #align finset.filter_nonempty_iff Finset.filter_nonempty_iff /-- If all elements of a `Finset` satisfy the predicate `p`, `s.filter p` is `s`. -/ theorem filter_true_of_mem (h : ∀ x ∈ s, p x) : s.filter p = s := filter_eq_self.2 h #align finset.filter_true_of_mem Finset.filter_true_of_mem /-- If all elements of a `Finset` fail to satisfy the predicate `p`, `s.filter p` is `∅`. -/ theorem filter_false_of_mem (h : ∀ x ∈ s, ¬p x) : s.filter p = ∅ := filter_eq_empty_iff.2 h #align finset.filter_false_of_mem Finset.filter_false_of_mem @[simp] theorem filter_const (p : Prop) [Decidable p] (s : Finset α) : (s.filter fun _a => p) = if p then s else ∅ := by split_ifs <;> simp [*] #align finset.filter_const Finset.filter_const theorem filter_congr {s : Finset α} (H : ∀ x ∈ s, p x ↔ q x) : filter p s = filter q s := eq_of_veq <| Multiset.filter_congr H #align finset.filter_congr Finset.filter_congr variable (p q) @[simp] theorem filter_empty : filter p ∅ = ∅ := subset_empty.1 <| filter_subset _ _ #align finset.filter_empty Finset.filter_empty @[gcongr] theorem filter_subset_filter {s t : Finset α} (h : s ⊆ t) : s.filter p ⊆ t.filter p := fun _a ha => mem_filter.2 ⟨h (mem_filter.1 ha).1, (mem_filter.1 ha).2⟩ #align finset.filter_subset_filter Finset.filter_subset_filter theorem monotone_filter_left : Monotone (filter p) := fun _ _ => filter_subset_filter p #align finset.monotone_filter_left Finset.monotone_filter_left -- TODO: `@[gcongr]` doesn't accept this lemma because of the `DecidablePred` arguments theorem monotone_filter_right (s : Finset α) ⦃p q : α → Prop⦄ [DecidablePred p] [DecidablePred q] (h : p ≤ q) : s.filter p ⊆ s.filter q := Multiset.subset_of_le (Multiset.monotone_filter_right s.val h) #align finset.monotone_filter_right Finset.monotone_filter_right @[simp, norm_cast] theorem coe_filter (s : Finset α) : ↑(s.filter p) = ({ x ∈ ↑s | p x } : Set α) := Set.ext fun _ => mem_filter #align finset.coe_filter Finset.coe_filter theorem subset_coe_filter_of_subset_forall (s : Finset α) {t : Set α} (h₁ : t ⊆ s) (h₂ : ∀ x ∈ t, p x) : t ⊆ s.filter p := fun x hx => (s.coe_filter p).symm ▸ ⟨h₁ hx, h₂ x hx⟩ #align finset.subset_coe_filter_of_subset_forall Finset.subset_coe_filter_of_subset_forall theorem filter_singleton (a : α) : filter p {a} = if p a then {a} else ∅ := by classical ext x simp only [mem_singleton, forall_eq, mem_filter] split_ifs with h <;> by_cases h' : x = a <;> simp [h, h'] #align finset.filter_singleton Finset.filter_singleton theorem filter_cons_of_pos (a : α) (s : Finset α) (ha : a ∉ s) (hp : p a) : filter p (cons a s ha) = cons a (filter p s) (mem_filter.not.mpr <| mt And.left ha) := eq_of_veq <| Multiset.filter_cons_of_pos s.val hp #align finset.filter_cons_of_pos Finset.filter_cons_of_pos theorem filter_cons_of_neg (a : α) (s : Finset α) (ha : a ∉ s) (hp : ¬p a) : filter p (cons a s ha) = filter p s := eq_of_veq <| Multiset.filter_cons_of_neg s.val hp #align finset.filter_cons_of_neg Finset.filter_cons_of_neg theorem disjoint_filter {s : Finset α} {p q : α → Prop} [DecidablePred p] [DecidablePred q] : Disjoint (s.filter p) (s.filter q) ↔ ∀ x ∈ s, p x → ¬q x := by constructor <;> simp (config := { contextual := true }) [disjoint_left] #align finset.disjoint_filter Finset.disjoint_filter theorem disjoint_filter_filter {s t : Finset α} {p q : α → Prop} [DecidablePred p] [DecidablePred q] : Disjoint s t → Disjoint (s.filter p) (t.filter q) := Disjoint.mono (filter_subset _ _) (filter_subset _ _) #align finset.disjoint_filter_filter Finset.disjoint_filter_filter theorem disjoint_filter_filter' (s t : Finset α) {p q : α → Prop} [DecidablePred p] [DecidablePred q] (h : Disjoint p q) : Disjoint (s.filter p) (t.filter q) := by simp_rw [disjoint_left, mem_filter] rintro a ⟨_, hp⟩ ⟨_, hq⟩ rw [Pi.disjoint_iff] at h simpa [hp, hq] using h a #align finset.disjoint_filter_filter' Finset.disjoint_filter_filter' theorem disjoint_filter_filter_neg (s t : Finset α) (p : α → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] : Disjoint (s.filter p) (t.filter fun a => ¬p a) := disjoint_filter_filter' s t disjoint_compl_right #align finset.disjoint_filter_filter_neg Finset.disjoint_filter_filter_neg theorem filter_disj_union (s : Finset α) (t : Finset α) (h : Disjoint s t) : filter p (disjUnion s t h) = (filter p s).disjUnion (filter p t) (disjoint_filter_filter h) := eq_of_veq <| Multiset.filter_add _ _ _ #align finset.filter_disj_union Finset.filter_disj_union lemma _root_.Set.pairwiseDisjoint_filter [DecidableEq β] (f : α → β) (s : Set β) (t : Finset α) : s.PairwiseDisjoint fun x ↦ t.filter (f · = x) := by rintro i - j - h u hi hj x hx obtain ⟨-, rfl⟩ : x ∈ t ∧ f x = i := by simpa using hi hx obtain ⟨-, rfl⟩ : x ∈ t ∧ f x = j := by simpa using hj hx contradiction theorem filter_cons {a : α} (s : Finset α) (ha : a ∉ s) : filter p (cons a s ha) = (if p a then {a} else ∅ : Finset α).disjUnion (filter p s) (by split_ifs · rw [disjoint_singleton_left] exact mem_filter.not.mpr <| mt And.left ha · exact disjoint_empty_left _) := by split_ifs with h · rw [filter_cons_of_pos _ _ _ ha h, singleton_disjUnion] · rw [filter_cons_of_neg _ _ _ ha h, empty_disjUnion] #align finset.filter_cons Finset.filter_cons variable [DecidableEq α] theorem filter_union (s₁ s₂ : Finset α) : (s₁ ∪ s₂).filter p = s₁.filter p ∪ s₂.filter p := ext fun _ => by simp only [mem_filter, mem_union, or_and_right] #align finset.filter_union Finset.filter_union theorem filter_union_right (s : Finset α) : s.filter p ∪ s.filter q = s.filter fun x => p x ∨ q x := ext fun x => by simp [mem_filter, mem_union, ← and_or_left] #align finset.filter_union_right Finset.filter_union_right theorem filter_mem_eq_inter {s t : Finset α} [∀ i, Decidable (i ∈ t)] : (s.filter fun i => i ∈ t) = s ∩ t := ext fun i => by simp [mem_filter, mem_inter] #align finset.filter_mem_eq_inter Finset.filter_mem_eq_inter theorem filter_inter_distrib (s t : Finset α) : (s ∩ t).filter p = s.filter p ∩ t.filter p := by ext simp [mem_filter, mem_inter, and_assoc] #align finset.filter_inter_distrib Finset.filter_inter_distrib theorem filter_inter (s t : Finset α) : filter p s ∩ t = filter p (s ∩ t) := by ext simp only [mem_inter, mem_filter, and_right_comm] #align finset.filter_inter Finset.filter_inter
Mathlib/Data/Finset/Basic.lean
2,786
2,787
theorem inter_filter (s t : Finset α) : s ∩ filter p t = filter p (s ∩ t) := by
rw [inter_comm, filter_inter, inter_comm]
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl -/ import Mathlib.Analysis.NormedSpace.Multilinear.Basic import Mathlib.Analysis.NormedSpace.Units import Mathlib.Analysis.NormedSpace.OperatorNorm.Completeness import Mathlib.Analysis.NormedSpace.OperatorNorm.Mul #align_import analysis.normed_space.bounded_linear_maps from "leanprover-community/mathlib"@"ce11c3c2a285bbe6937e26d9792fda4e51f3fe1a" /-! # Bounded linear maps This file defines a class stating that a map between normed vector spaces is (bi)linear and continuous. Instead of asking for continuity, the definition takes the equivalent condition (because the space is normed) that `‖f x‖` is bounded by a multiple of `‖x‖`. Hence the "bounded" in the name refers to `‖f x‖/‖x‖` rather than `‖f x‖` itself. ## Main definitions * `IsBoundedLinearMap`: Class stating that a map `f : E → F` is linear and has `‖f x‖` bounded by a multiple of `‖x‖`. * `IsBoundedBilinearMap`: Class stating that a map `f : E × F → G` is bilinear and continuous, but through the simpler to provide statement that `‖f (x, y)‖` is bounded by a multiple of `‖x‖ * ‖y‖` * `IsBoundedBilinearMap.linearDeriv`: Derivative of a continuous bilinear map as a linear map. * `IsBoundedBilinearMap.deriv`: Derivative of a continuous bilinear map as a continuous linear map. The proof that it is indeed the derivative is `IsBoundedBilinearMap.hasFDerivAt` in `Analysis.Calculus.FDeriv`. ## Main theorems * `IsBoundedBilinearMap.continuous`: A bounded bilinear map is continuous. * `ContinuousLinearEquiv.isOpen`: The continuous linear equivalences are an open subset of the set of continuous linear maps between a pair of Banach spaces. Placed in this file because its proof uses `IsBoundedBilinearMap.continuous`. ## Notes The main use of this file is `IsBoundedBilinearMap`. The file `Analysis.NormedSpace.Multilinear.Basic` already expounds the theory of multilinear maps, but the `2`-variables case is sufficiently simpler to currently deserve its own treatment. `IsBoundedLinearMap` is effectively an unbundled version of `ContinuousLinearMap` (defined in `Topology.Algebra.Module.Basic`, theory over normed spaces developed in `Analysis.NormedSpace.OperatorNorm`), albeit the name disparity. A bundled `ContinuousLinearMap` is to be preferred over an `IsBoundedLinearMap` hypothesis. Historical artifact, really. -/ noncomputable section open Topology open Filter (Tendsto) open Metric ContinuousLinearMap variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] /-- A function `f` satisfies `IsBoundedLinearMap 𝕜 f` if it is linear and satisfies the inequality `‖f x‖ ≤ M * ‖x‖` for some positive constant `M`. -/ structure IsBoundedLinearMap (𝕜 : Type*) [NormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] (f : E → F) extends IsLinearMap 𝕜 f : Prop where bound : ∃ M, 0 < M ∧ ∀ x : E, ‖f x‖ ≤ M * ‖x‖ #align is_bounded_linear_map IsBoundedLinearMap theorem IsLinearMap.with_bound {f : E → F} (hf : IsLinearMap 𝕜 f) (M : ℝ) (h : ∀ x : E, ‖f x‖ ≤ M * ‖x‖) : IsBoundedLinearMap 𝕜 f := ⟨hf, by_cases (fun (this : M ≤ 0) => ⟨1, zero_lt_one, fun x => (h x).trans <| mul_le_mul_of_nonneg_right (this.trans zero_le_one) (norm_nonneg x)⟩) fun (this : ¬M ≤ 0) => ⟨M, lt_of_not_ge this, h⟩⟩ #align is_linear_map.with_bound IsLinearMap.with_bound /-- A continuous linear map satisfies `IsBoundedLinearMap` -/ theorem ContinuousLinearMap.isBoundedLinearMap (f : E →L[𝕜] F) : IsBoundedLinearMap 𝕜 f := { f.toLinearMap.isLinear with bound := f.bound } #align continuous_linear_map.is_bounded_linear_map ContinuousLinearMap.isBoundedLinearMap namespace IsBoundedLinearMap /-- Construct a linear map from a function `f` satisfying `IsBoundedLinearMap 𝕜 f`. -/ def toLinearMap (f : E → F) (h : IsBoundedLinearMap 𝕜 f) : E →ₗ[𝕜] F := IsLinearMap.mk' _ h.toIsLinearMap #align is_bounded_linear_map.to_linear_map IsBoundedLinearMap.toLinearMap /-- Construct a continuous linear map from `IsBoundedLinearMap`. -/ def toContinuousLinearMap {f : E → F} (hf : IsBoundedLinearMap 𝕜 f) : E →L[𝕜] F := { toLinearMap f hf with cont := let ⟨C, _, hC⟩ := hf.bound AddMonoidHomClass.continuous_of_bound (toLinearMap f hf) C hC } #align is_bounded_linear_map.to_continuous_linear_map IsBoundedLinearMap.toContinuousLinearMap theorem zero : IsBoundedLinearMap 𝕜 fun _ : E => (0 : F) := (0 : E →ₗ[𝕜] F).isLinear.with_bound 0 <| by simp [le_refl] #align is_bounded_linear_map.zero IsBoundedLinearMap.zero theorem id : IsBoundedLinearMap 𝕜 fun x : E => x := LinearMap.id.isLinear.with_bound 1 <| by simp [le_refl] #align is_bounded_linear_map.id IsBoundedLinearMap.id theorem fst : IsBoundedLinearMap 𝕜 fun x : E × F => x.1 := by refine (LinearMap.fst 𝕜 E F).isLinear.with_bound 1 fun x => ?_ rw [one_mul] exact le_max_left _ _ #align is_bounded_linear_map.fst IsBoundedLinearMap.fst theorem snd : IsBoundedLinearMap 𝕜 fun x : E × F => x.2 := by refine (LinearMap.snd 𝕜 E F).isLinear.with_bound 1 fun x => ?_ rw [one_mul] exact le_max_right _ _ #align is_bounded_linear_map.snd IsBoundedLinearMap.snd variable {f g : E → F} theorem smul (c : 𝕜) (hf : IsBoundedLinearMap 𝕜 f) : IsBoundedLinearMap 𝕜 (c • f) := let ⟨hlf, M, _, hM⟩ := hf (c • hlf.mk' f).isLinear.with_bound (‖c‖ * M) fun x => calc ‖c • f x‖ = ‖c‖ * ‖f x‖ := norm_smul c (f x) _ ≤ ‖c‖ * (M * ‖x‖) := mul_le_mul_of_nonneg_left (hM _) (norm_nonneg _) _ = ‖c‖ * M * ‖x‖ := (mul_assoc _ _ _).symm #align is_bounded_linear_map.smul IsBoundedLinearMap.smul theorem neg (hf : IsBoundedLinearMap 𝕜 f) : IsBoundedLinearMap 𝕜 fun e => -f e := by rw [show (fun e => -f e) = fun e => (-1 : 𝕜) • f e by funext; simp] exact smul (-1) hf #align is_bounded_linear_map.neg IsBoundedLinearMap.neg theorem add (hf : IsBoundedLinearMap 𝕜 f) (hg : IsBoundedLinearMap 𝕜 g) : IsBoundedLinearMap 𝕜 fun e => f e + g e := let ⟨hlf, Mf, _, hMf⟩ := hf let ⟨hlg, Mg, _, hMg⟩ := hg (hlf.mk' _ + hlg.mk' _).isLinear.with_bound (Mf + Mg) fun x => calc ‖f x + g x‖ ≤ Mf * ‖x‖ + Mg * ‖x‖ := norm_add_le_of_le (hMf x) (hMg x) _ ≤ (Mf + Mg) * ‖x‖ := by rw [add_mul] #align is_bounded_linear_map.add IsBoundedLinearMap.add theorem sub (hf : IsBoundedLinearMap 𝕜 f) (hg : IsBoundedLinearMap 𝕜 g) : IsBoundedLinearMap 𝕜 fun e => f e - g e := by simpa [sub_eq_add_neg] using add hf (neg hg) #align is_bounded_linear_map.sub IsBoundedLinearMap.sub theorem comp {g : F → G} (hg : IsBoundedLinearMap 𝕜 g) (hf : IsBoundedLinearMap 𝕜 f) : IsBoundedLinearMap 𝕜 (g ∘ f) := (hg.toContinuousLinearMap.comp hf.toContinuousLinearMap).isBoundedLinearMap #align is_bounded_linear_map.comp IsBoundedLinearMap.comp protected theorem tendsto (x : E) (hf : IsBoundedLinearMap 𝕜 f) : Tendsto f (𝓝 x) (𝓝 (f x)) := let ⟨hf, M, _, hM⟩ := hf tendsto_iff_norm_sub_tendsto_zero.2 <| squeeze_zero (fun e => norm_nonneg _) (fun e => calc ‖f e - f x‖ = ‖hf.mk' f (e - x)‖ := by rw [(hf.mk' _).map_sub e x]; rfl _ ≤ M * ‖e - x‖ := hM (e - x) ) (suffices Tendsto (fun e : E => M * ‖e - x‖) (𝓝 x) (𝓝 (M * 0)) by simpa tendsto_const_nhds.mul (tendsto_norm_sub_self _)) #align is_bounded_linear_map.tendsto IsBoundedLinearMap.tendsto theorem continuous (hf : IsBoundedLinearMap 𝕜 f) : Continuous f := continuous_iff_continuousAt.2 fun _ => hf.tendsto _ #align is_bounded_linear_map.continuous IsBoundedLinearMap.continuous theorem lim_zero_bounded_linear_map (hf : IsBoundedLinearMap 𝕜 f) : Tendsto f (𝓝 0) (𝓝 0) := (hf.1.mk' _).map_zero ▸ continuous_iff_continuousAt.1 hf.continuous 0 #align is_bounded_linear_map.lim_zero_bounded_linear_map IsBoundedLinearMap.lim_zero_bounded_linear_map section open Asymptotics Filter theorem isBigO_id {f : E → F} (h : IsBoundedLinearMap 𝕜 f) (l : Filter E) : f =O[l] fun x => x := let ⟨_, _, hM⟩ := h.bound IsBigO.of_bound _ (mem_of_superset univ_mem fun x _ => hM x) set_option linter.uppercaseLean3 false in #align is_bounded_linear_map.is_O_id IsBoundedLinearMap.isBigO_id theorem isBigO_comp {E : Type*} {g : F → G} (hg : IsBoundedLinearMap 𝕜 g) {f : E → F} (l : Filter E) : (fun x' => g (f x')) =O[l] f := (hg.isBigO_id ⊤).comp_tendsto le_top set_option linter.uppercaseLean3 false in #align is_bounded_linear_map.is_O_comp IsBoundedLinearMap.isBigO_comp theorem isBigO_sub {f : E → F} (h : IsBoundedLinearMap 𝕜 f) (l : Filter E) (x : E) : (fun x' => f (x' - x)) =O[l] fun x' => x' - x := isBigO_comp h l set_option linter.uppercaseLean3 false in #align is_bounded_linear_map.is_O_sub IsBoundedLinearMap.isBigO_sub end end IsBoundedLinearMap section variable {ι : Type*} [Fintype ι] /-- Taking the cartesian product of two continuous multilinear maps is a bounded linear operation. -/ theorem isBoundedLinearMap_prod_multilinear {E : ι → Type*} [∀ i, NormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] : IsBoundedLinearMap 𝕜 fun p : ContinuousMultilinearMap 𝕜 E F × ContinuousMultilinearMap 𝕜 E G => p.1.prod p.2 where map_add p₁ p₂ := by ext : 1; rfl map_smul c p := by ext : 1; rfl bound := by refine ⟨1, zero_lt_one, fun p ↦ ?_⟩ rw [one_mul] apply ContinuousMultilinearMap.opNorm_le_bound _ (norm_nonneg _) _ intro m rw [ContinuousMultilinearMap.prod_apply, norm_prod_le_iff] constructor · exact (p.1.le_opNorm m).trans (mul_le_mul_of_nonneg_right (norm_fst_le p) <| by positivity) · exact (p.2.le_opNorm m).trans (mul_le_mul_of_nonneg_right (norm_snd_le p) <| by positivity) #align is_bounded_linear_map_prod_multilinear isBoundedLinearMap_prod_multilinear /-- Given a fixed continuous linear map `g`, associating to a continuous multilinear map `f` the continuous multilinear map `f (g m₁, ..., g mₙ)` is a bounded linear operation. -/ theorem isBoundedLinearMap_continuousMultilinearMap_comp_linear (g : G →L[𝕜] E) : IsBoundedLinearMap 𝕜 fun f : ContinuousMultilinearMap 𝕜 (fun _ : ι => E) F => f.compContinuousLinearMap fun _ => g := by refine IsLinearMap.with_bound ⟨fun f₁ f₂ => by ext; rfl, fun c f => by ext; rfl⟩ (‖g‖ ^ Fintype.card ι) fun f => ?_ apply ContinuousMultilinearMap.opNorm_le_bound _ _ _ · apply_rules [mul_nonneg, pow_nonneg, norm_nonneg] intro m calc ‖f (g ∘ m)‖ ≤ ‖f‖ * ∏ i, ‖g (m i)‖ := f.le_opNorm _ _ ≤ ‖f‖ * ∏ i, ‖g‖ * ‖m i‖ := by apply mul_le_mul_of_nonneg_left _ (norm_nonneg _) exact Finset.prod_le_prod (fun i _ => norm_nonneg _) fun i _ => g.le_opNorm _ _ = ‖g‖ ^ Fintype.card ι * ‖f‖ * ∏ i, ‖m i‖ := by simp only [Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ] ring #align is_bounded_linear_map_continuous_multilinear_map_comp_linear isBoundedLinearMap_continuousMultilinearMap_comp_linear end section BilinearMap namespace ContinuousLinearMap /-! We prove some computation rules for continuous (semi-)bilinear maps in their first argument. If `f` is a continuous bilinear map, to use the corresponding rules for the second argument, use `(f _).map_add` and similar. We have to assume that `F` and `G` are normed spaces in this section, to use `ContinuousLinearMap.toNormedAddCommGroup`, but we don't need to assume this for the first argument of `f`. -/ variable {R : Type*} variable {𝕜₂ 𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NontriviallyNormedField 𝕜₂] variable {M : Type*} [TopologicalSpace M] variable {σ₁₂ : 𝕜 →+* 𝕜₂} variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜₂ G'] [NormedSpace 𝕜' G'] variable [SMulCommClass 𝕜₂ 𝕜' G'] section Semiring variable [Semiring R] [AddCommMonoid M] [Module R M] {ρ₁₂ : R →+* 𝕜'} theorem map_add₂ (f : M →SL[ρ₁₂] F →SL[σ₁₂] G') (x x' : M) (y : F) : f (x + x') y = f x y + f x' y := by rw [f.map_add, add_apply] #align continuous_linear_map.map_add₂ ContinuousLinearMap.map_add₂ theorem map_zero₂ (f : M →SL[ρ₁₂] F →SL[σ₁₂] G') (y : F) : f 0 y = 0 := by rw [f.map_zero, zero_apply] #align continuous_linear_map.map_zero₂ ContinuousLinearMap.map_zero₂ theorem map_smulₛₗ₂ (f : M →SL[ρ₁₂] F →SL[σ₁₂] G') (c : R) (x : M) (y : F) : f (c • x) y = ρ₁₂ c • f x y := by rw [f.map_smulₛₗ, smul_apply] #align continuous_linear_map.map_smulₛₗ₂ ContinuousLinearMap.map_smulₛₗ₂ end Semiring section Ring variable [Ring R] [AddCommGroup M] [Module R M] {ρ₁₂ : R →+* 𝕜'} theorem map_sub₂ (f : M →SL[ρ₁₂] F →SL[σ₁₂] G') (x x' : M) (y : F) : f (x - x') y = f x y - f x' y := by rw [f.map_sub, sub_apply] #align continuous_linear_map.map_sub₂ ContinuousLinearMap.map_sub₂
Mathlib/Analysis/NormedSpace/BoundedLinearMaps.lean
307
308
theorem map_neg₂ (f : M →SL[ρ₁₂] F →SL[σ₁₂] G') (x : M) (y : F) : f (-x) y = -f x y := by
rw [f.map_neg, neg_apply]