Context
stringlengths
227
76.5k
target
stringlengths
0
11.6k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
16
3.69k
/- Copyright (c) 2023 Yaël Dillies, 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.SimpleGraph.Triangle.Basic /-! # Construct a tripartite graph from its triangles This file contains the construction of a simple graph on `α ⊕ β ⊕ γ` from a list of triangles `(a, b, c)` (with `a` in the first component, `b` in the second, `c` in the third). We call * `t : Finset (α × β × γ)` the set of *triangle indices* (its elements are not triangles within the graph but instead index them). * *explicit* a triangle of the constructed graph coming from a triangle index. * *accidental* a triangle of the constructed graph not coming from a triangle index. The two important properties of this construction are: * `SimpleGraph.TripartiteFromTriangles.ExplicitDisjoint`: Whether the explicit triangles are edge-disjoint. * `SimpleGraph.TripartiteFromTriangles.NoAccidental`: Whether all triangles are explicit. This construction shows up unrelatedly twice in the theory of Roth numbers: * The lower bound of the Ruzsa-Szemerédi problem: From a set `s` in a finite abelian group `G` of odd order, we construct a tripartite graph on `G ⊕ G ⊕ G`. The triangle indices are `(x, x + a, x + 2 * a)` for `x` any element and `a ∈ s`. The explicit triangles are always edge-disjoint and there is no accidental triangle if `s` is 3AP-free. * The proof of the corners theorem from the triangle removal lemma: For a set `s` in a finite abelian group `G`, we construct a tripartite graph on `G ⊕ G ⊕ G`, whose vertices correspond to the horizontal, vertical and diagonal lines in `G × G`. The explicit triangles are `(h, v, d)` where `h`, `v`, `d` are horizontal, vertical, diagonal lines that intersect in an element of `s`. The explicit triangles are always edge-disjoint and there is no accidental triangle if `s` is corner-free. -/ open Finset Function Sum3 variable {α β γ 𝕜 : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] {t : Finset (α × β × γ)} {a a' : α} {b b' : β} {c c' : γ} {x : α × β × γ} namespace SimpleGraph namespace TripartiteFromTriangles /-- The underlying relation of the tripartite-from-triangles graph. Two vertices are related iff there exists a triangle index containing them both. -/ @[mk_iff] inductive Rel (t : Finset (α × β × γ)) : α ⊕ β ⊕ γ → α ⊕ β ⊕ γ → Prop | in₀₁ ⦃a b c⦄ : (a, b, c) ∈ t → Rel t (in₀ a) (in₁ b) | in₁₀ ⦃a b c⦄ : (a, b, c) ∈ t → Rel t (in₁ b) (in₀ a) | in₀₂ ⦃a b c⦄ : (a, b, c) ∈ t → Rel t (in₀ a) (in₂ c) | in₂₀ ⦃a b c⦄ : (a, b, c) ∈ t → Rel t (in₂ c) (in₀ a) | in₁₂ ⦃a b c⦄ : (a, b, c) ∈ t → Rel t (in₁ b) (in₂ c) | in₂₁ ⦃a b c⦄ : (a, b, c) ∈ t → Rel t (in₂ c) (in₁ b) open Rel lemma rel_irrefl : ∀ x, ¬ Rel t x x := fun _x hx ↦ nomatch hx lemma rel_symm : Symmetric (Rel t) := fun x y h ↦ by cases h <;> constructor <;> assumption /-- The tripartite-from-triangles graph. Two vertices are related iff there exists a triangle index containing them both. -/ def graph (t : Finset (α × β × γ)) : SimpleGraph (α ⊕ β ⊕ γ) := ⟨Rel t, rel_symm, rel_irrefl⟩ namespace Graph @[simp] lemma not_in₀₀ : ¬ (graph t).Adj (in₀ a) (in₀ a') := fun h ↦ nomatch h @[simp] lemma not_in₁₁ : ¬ (graph t).Adj (in₁ b) (in₁ b') := fun h ↦ nomatch h @[simp] lemma not_in₂₂ : ¬ (graph t).Adj (in₂ c) (in₂ c') := fun h ↦ nomatch h @[simp] lemma in₀₁_iff : (graph t).Adj (in₀ a) (in₁ b) ↔ ∃ c, (a, b, c) ∈ t := ⟨by rintro ⟨⟩; exact ⟨_, ‹_›⟩, fun ⟨_, h⟩ ↦ in₀₁ h⟩ @[simp] lemma in₁₀_iff : (graph t).Adj (in₁ b) (in₀ a) ↔ ∃ c, (a, b, c) ∈ t := ⟨by rintro ⟨⟩; exact ⟨_, ‹_›⟩, fun ⟨_, h⟩ ↦ in₁₀ h⟩ @[simp] lemma in₀₂_iff : (graph t).Adj (in₀ a) (in₂ c) ↔ ∃ b, (a, b, c) ∈ t := ⟨by rintro ⟨⟩; exact ⟨_, ‹_›⟩, fun ⟨_, h⟩ ↦ in₀₂ h⟩ @[simp] lemma in₂₀_iff : (graph t).Adj (in₂ c) (in₀ a) ↔ ∃ b, (a, b, c) ∈ t := ⟨by rintro ⟨⟩; exact ⟨_, ‹_›⟩, fun ⟨_, h⟩ ↦ in₂₀ h⟩ @[simp] lemma in₁₂_iff : (graph t).Adj (in₁ b) (in₂ c) ↔ ∃ a, (a, b, c) ∈ t := ⟨by rintro ⟨⟩; exact ⟨_, ‹_›⟩, fun ⟨_, h⟩ ↦ in₁₂ h⟩ @[simp] lemma in₂₁_iff : (graph t).Adj (in₂ c) (in₁ b) ↔ ∃ a, (a, b, c) ∈ t := ⟨by rintro ⟨⟩; exact ⟨_, ‹_›⟩, fun ⟨_, h⟩ ↦ in₂₁ h⟩ lemma in₀₁_iff' : (graph t).Adj (in₀ a) (in₁ b) ↔ ∃ x : α × β × γ, x ∈ t ∧ x.1 = a ∧ x.2.1 = b where mp := by rintro ⟨⟩; exact ⟨_, ‹_›, by simp⟩ mpr := by rintro ⟨⟨a, b, c⟩, h, rfl, rfl⟩; constructor; assumption lemma in₁₀_iff' : (graph t).Adj (in₁ b) (in₀ a) ↔ ∃ x : α × β × γ, x ∈ t ∧ x.2.1 = b ∧ x.1 = a where mp := by rintro ⟨⟩; exact ⟨_, ‹_›, by simp⟩ mpr := by rintro ⟨⟨a, b, c⟩, h, rfl, rfl⟩; constructor; assumption
lemma in₀₂_iff' : (graph t).Adj (in₀ a) (in₂ c) ↔ ∃ x : α × β × γ, x ∈ t ∧ x.1 = a ∧ x.2.2 = c where mp := by rintro ⟨⟩; exact ⟨_, ‹_›, by simp⟩ mpr := by rintro ⟨⟨a, b, c⟩, h, rfl, rfl⟩; constructor; assumption
Mathlib/Combinatorics/SimpleGraph/Triangle/Tripartite.lean
93
96
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Anne Baanen -/ import Mathlib.Data.Matrix.Basic import Mathlib.Data.Matrix.Block import Mathlib.Data.Matrix.Notation import Mathlib.Data.Matrix.RowCol import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.GroupTheory.Perm.Fin import Mathlib.LinearAlgebra.Alternating.Basic import Mathlib.LinearAlgebra.Matrix.SemiringInverse /-! # Determinant of a matrix This file defines the determinant of a matrix, `Matrix.det`, and its essential properties. ## Main definitions - `Matrix.det`: the determinant of a square matrix, as a sum over permutations - `Matrix.detRowAlternating`: the determinant, as an `AlternatingMap` in the rows of the matrix ## Main results - `det_mul`: the determinant of `A * B` is the product of determinants - `det_zero_of_row_eq`: the determinant is zero if there is a repeated row - `det_block_diagonal`: the determinant of a block diagonal matrix is a product of the blocks' determinants ## Implementation notes It is possible to configure `simp` to compute determinants. See the file `MathlibTest/matrix.lean` for some examples. -/ universe u v w z open Equiv Equiv.Perm Finset Function namespace Matrix variable {m n : Type*} [DecidableEq n] [Fintype n] [DecidableEq m] [Fintype m] variable {R : Type v} [CommRing R] local notation "ε " σ:arg => ((sign σ : ℤ) : R) /-- `det` is an `AlternatingMap` in the rows of the matrix. -/ def detRowAlternating : (n → R) [⋀^n]→ₗ[R] R := MultilinearMap.alternatization ((MultilinearMap.mkPiAlgebra R n R).compLinearMap LinearMap.proj) /-- The determinant of a matrix given by the Leibniz formula. -/ abbrev det (M : Matrix n n R) : R := detRowAlternating M theorem det_apply (M : Matrix n n R) : M.det = ∑ σ : Perm n, Equiv.Perm.sign σ • ∏ i, M (σ i) i := MultilinearMap.alternatization_apply _ M -- This is what the old definition was. We use it to avoid having to change the old proofs below theorem det_apply' (M : Matrix n n R) : M.det = ∑ σ : Perm n, ε σ * ∏ i, M (σ i) i := by simp [det_apply, Units.smul_def] theorem det_eq_detp_sub_detp (M : Matrix n n R) : M.det = M.detp 1 - M.detp (-1) := by rw [det_apply, ← Equiv.sum_comp (Equiv.inv (Perm n)), ← ofSign_disjUnion, sum_disjUnion] simp_rw [inv_apply, sign_inv, sub_eq_add_neg, detp, ← sum_neg_distrib] refine congr_arg₂ (· + ·) (sum_congr rfl fun σ hσ ↦ ?_) (sum_congr rfl fun σ hσ ↦ ?_) <;> rw [mem_ofSign.mp hσ, ← Equiv.prod_comp σ] <;> simp @[simp] theorem det_diagonal {d : n → R} : det (diagonal d) = ∏ i, d i := by rw [det_apply'] refine (Finset.sum_eq_single 1 ?_ ?_).trans ?_ · rintro σ - h2 obtain ⟨x, h3⟩ := not_forall.1 (mt Equiv.ext h2) convert mul_zero (ε σ) apply Finset.prod_eq_zero (mem_univ x) exact if_neg h3 · simp · simp theorem det_zero (_ : Nonempty n) : det (0 : Matrix n n R) = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_zero @[simp] theorem det_one : det (1 : Matrix n n R) = 1 := by rw [← diagonal_one]; simp [-diagonal_one] theorem det_isEmpty [IsEmpty n] {A : Matrix n n R} : det A = 1 := by simp [det_apply] @[simp] theorem coe_det_isEmpty [IsEmpty n] : (det : Matrix n n R → R) = Function.const _ 1 := by ext exact det_isEmpty theorem det_eq_one_of_card_eq_zero {A : Matrix n n R} (h : Fintype.card n = 0) : det A = 1 := haveI : IsEmpty n := Fintype.card_eq_zero_iff.mp h det_isEmpty /-- If `n` has only one element, the determinant of an `n` by `n` matrix is just that element. Although `Unique` implies `DecidableEq` and `Fintype`, the instances might not be syntactically equal. Thus, we need to fill in the args explicitly. -/ @[simp] theorem det_unique {n : Type*} [Unique n] [DecidableEq n] [Fintype n] (A : Matrix n n R) : det A = A default default := by simp [det_apply, univ_unique] theorem det_eq_elem_of_subsingleton [Subsingleton n] (A : Matrix n n R) (k : n) : det A = A k k := by have := uniqueOfSubsingleton k convert det_unique A theorem det_eq_elem_of_card_eq_one {A : Matrix n n R} (h : Fintype.card n = 1) (k : n) : det A = A k k := haveI : Subsingleton n := Fintype.card_le_one_iff_subsingleton.mp h.le det_eq_elem_of_subsingleton _ _ theorem det_mul_aux {M N : Matrix n n R} {p : n → n} (H : ¬Bijective p) : (∑ σ : Perm n, ε σ * ∏ x, M (σ x) (p x) * N (p x) x) = 0 := by obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j := by rw [← Finite.injective_iff_bijective, Injective] at H push_neg at H exact H exact sum_involution (fun σ _ => σ * Equiv.swap i j) (fun σ _ => by have : (∏ x, M (σ x) (p x)) = ∏ x, M ((σ * Equiv.swap i j) x) (p x) := Fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij]) simp [this, sign_swap hij, -sign_swap', prod_mul_distrib]) (fun σ _ _ => (not_congr mul_swap_eq_iff).mpr hij) (fun _ _ => mem_univ _) fun σ _ => mul_swap_involutive i j σ @[simp] theorem det_mul (M N : Matrix n n R) : det (M * N) = det M * det N := calc det (M * N) = ∑ p : n → n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := by simp only [det_apply', mul_apply, prod_univ_sum, mul_sum, Fintype.piFinset_univ] rw [Finset.sum_comm] _ = ∑ p : n → n with Bijective p, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := by refine (sum_subset (filter_subset _ _) fun f _ hbij ↦ det_mul_aux ?_).symm simpa only [true_and, mem_filter, mem_univ] using hbij _ = ∑ τ : Perm n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (τ i) * N (τ i) i := sum_bij (fun p h ↦ Equiv.ofBijective p (mem_filter.1 h).2) (fun _ _ ↦ mem_univ _) (fun _ _ _ _ h ↦ by injection h) (fun b _ ↦ ⟨b, mem_filter.2 ⟨mem_univ _, b.bijective⟩, coe_fn_injective rfl⟩) fun _ _ ↦ rfl _ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * ε τ * ∏ j, M (τ j) (σ j) := by simp only [mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc] _ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * (ε σ * ε τ) * ∏ i, M (τ i) i := (sum_congr rfl fun σ _ => Fintype.sum_equiv (Equiv.mulRight σ⁻¹) _ _ fun τ => by have : (∏ j, M (τ j) (σ j)) = ∏ j, M ((τ * σ⁻¹) j) j := by rw [← (σ⁻¹ : _ ≃ _).prod_comp] simp only [Equiv.Perm.coe_mul, apply_inv_self, Function.comp_apply] have h : ε σ * ε (τ * σ⁻¹) = ε τ := calc ε σ * ε (τ * σ⁻¹) = ε (τ * σ⁻¹ * σ) := by rw [mul_comm, sign_mul (τ * σ⁻¹)] simp only [Int.cast_mul, Units.val_mul] _ = ε τ := by simp only [inv_mul_cancel_right] simp_rw [Equiv.coe_mulRight, h] simp only [this]) _ = det M * det N := by simp only [det_apply', Finset.mul_sum, mul_comm, mul_left_comm, mul_assoc] /-- The determinant of a matrix, as a monoid homomorphism. -/ def detMonoidHom : Matrix n n R →* R where toFun := det map_one' := det_one map_mul' := det_mul @[simp] theorem coe_detMonoidHom : (detMonoidHom : Matrix n n R → R) = det := rfl /-- On square matrices, `mul_comm` applies under `det`. -/ theorem det_mul_comm (M N : Matrix m m R) : det (M * N) = det (N * M) := by rw [det_mul, det_mul, mul_comm] /-- On square matrices, `mul_left_comm` applies under `det`. -/ theorem det_mul_left_comm (M N P : Matrix m m R) : det (M * (N * P)) = det (N * (M * P)) := by rw [← Matrix.mul_assoc, ← Matrix.mul_assoc, det_mul, det_mul_comm M N, ← det_mul] /-- On square matrices, `mul_right_comm` applies under `det`. -/ theorem det_mul_right_comm (M N P : Matrix m m R) : det (M * N * P) = det (M * P * N) := by rw [Matrix.mul_assoc, Matrix.mul_assoc, det_mul, det_mul_comm N P, ← det_mul] -- TODO(https://github.com/leanprover-community/mathlib4/issues/6607): fix elaboration so `val` isn't needed theorem det_units_conj (M : (Matrix m m R)ˣ) (N : Matrix m m R) : det (M.val * N * M⁻¹.val) = det N := by rw [det_mul_right_comm, Units.mul_inv, one_mul] -- TODO(https://github.com/leanprover-community/mathlib4/issues/6607): fix elaboration so `val` isn't needed theorem det_units_conj' (M : (Matrix m m R)ˣ) (N : Matrix m m R) : det (M⁻¹.val * N * ↑M.val) = det N := det_units_conj M⁻¹ N /-- Transposing a matrix preserves the determinant. -/ @[simp] theorem det_transpose (M : Matrix n n R) : Mᵀ.det = M.det := by rw [det_apply', det_apply'] refine Fintype.sum_bijective _ inv_involutive.bijective _ _ ?_ intro σ rw [sign_inv] congr 1 apply Fintype.prod_equiv σ simp /-- Permuting the columns changes the sign of the determinant. -/ theorem det_permute (σ : Perm n) (M : Matrix n n R) : (M.submatrix σ id).det = Perm.sign σ * M.det := ((detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_perm M σ).trans (by simp [Units.smul_def]) /-- Permuting the rows changes the sign of the determinant. -/ theorem det_permute' (σ : Perm n) (M : Matrix n n R) : (M.submatrix id σ).det = Perm.sign σ * M.det := by rw [← det_transpose, transpose_submatrix, det_permute, det_transpose] /-- Permuting rows and columns with the same equivalence does not change the determinant. -/ @[simp] theorem det_submatrix_equiv_self (e : n ≃ m) (A : Matrix m m R) : det (A.submatrix e e) = det A := by rw [det_apply', det_apply'] apply Fintype.sum_equiv (Equiv.permCongr e) intro σ rw [Equiv.Perm.sign_permCongr e σ] congr 1 apply Fintype.prod_equiv e intro i rw [Equiv.permCongr_apply, Equiv.symm_apply_apply, submatrix_apply] /-- Permuting rows and columns with two equivalences does not change the absolute value of the determinant. -/ @[simp] theorem abs_det_submatrix_equiv_equiv {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (e₁ e₂ : n ≃ m) (A : Matrix m m R) : |(A.submatrix e₁ e₂).det| = |A.det| := by have hee : e₂ = e₁.trans (e₁.symm.trans e₂) := by ext; simp rw [hee] show |((A.submatrix id (e₁.symm.trans e₂)).submatrix e₁ e₁).det| = |A.det| rw [Matrix.det_submatrix_equiv_self, Matrix.det_permute', abs_mul, abs_unit_intCast, one_mul] /-- Reindexing both indices along the same equivalence preserves the determinant. For the `simp` version of this lemma, see `det_submatrix_equiv_self`; this one is unsuitable because `Matrix.reindex_apply` unfolds `reindex` first. -/ theorem det_reindex_self (e : m ≃ n) (A : Matrix m m R) : det (reindex e e A) = det A := det_submatrix_equiv_self e.symm A /-- Reindexing both indices along equivalences preserves the absolute of the determinant. For the `simp` version of this lemma, see `abs_det_submatrix_equiv_equiv`; this one is unsuitable because `Matrix.reindex_apply` unfolds `reindex` first. -/ theorem abs_det_reindex {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (e₁ e₂ : m ≃ n) (A : Matrix m m R) : |det (reindex e₁ e₂ A)| = |det A| := abs_det_submatrix_equiv_equiv e₁.symm e₂.symm A theorem det_smul (A : Matrix n n R) (c : R) : det (c • A) = c ^ Fintype.card n * det A := calc det (c • A) = det ((diagonal fun _ => c) * A) := by rw [smul_eq_diagonal_mul] _ = det (diagonal fun _ => c) * det A := det_mul _ _ _ = c ^ Fintype.card n * det A := by simp @[simp] theorem det_smul_of_tower {α} [Monoid α] [MulAction α R] [IsScalarTower α R R] [SMulCommClass α R R] (c : α) (A : Matrix n n R) : det (c • A) = c ^ Fintype.card n • det A := by rw [← smul_one_smul R c A, det_smul, smul_pow, one_pow, smul_mul_assoc, one_mul] theorem det_neg (A : Matrix n n R) : det (-A) = (-1) ^ Fintype.card n * det A := by rw [← det_smul, neg_one_smul] /-- A variant of `Matrix.det_neg` with scalar multiplication by `Units ℤ` instead of multiplication by `R`. -/ theorem det_neg_eq_smul (A : Matrix n n R) : det (-A) = (-1 : Units ℤ) ^ Fintype.card n • det A := by rw [← det_smul_of_tower, Units.neg_smul, one_smul] /-- Multiplying each row by a fixed `v i` multiplies the determinant by the product of the `v`s. -/ theorem det_mul_row (v : n → R) (A : Matrix n n R) : det (of fun i j => v j * A i j) = (∏ i, v i) * det A := calc det (of fun i j => v j * A i j) = det (A * diagonal v) := congr_arg det <| by ext simp [mul_comm] _ = (∏ i, v i) * det A := by rw [det_mul, det_diagonal, mul_comm] /-- Multiplying each column by a fixed `v j` multiplies the determinant by the product of the `v`s. -/ theorem det_mul_column (v : n → R) (A : Matrix n n R) : det (of fun i j => v i * A i j) = (∏ i, v i) * det A := MultilinearMap.map_smul_univ _ v A @[simp] theorem det_pow (M : Matrix m m R) (n : ℕ) : det (M ^ n) = det M ^ n := (detMonoidHom : Matrix m m R →* R).map_pow M n section HomMap variable {S : Type w} [CommRing S] theorem _root_.RingHom.map_det (f : R →+* S) (M : Matrix n n R) : f M.det = Matrix.det (f.mapMatrix M) := by simp [Matrix.det_apply', map_sum f, map_prod f] theorem _root_.RingEquiv.map_det (f : R ≃+* S) (M : Matrix n n R) : f M.det = Matrix.det (f.mapMatrix M) := f.toRingHom.map_det _ theorem _root_.AlgHom.map_det [Algebra R S] {T : Type z} [CommRing T] [Algebra R T] (f : S →ₐ[R] T) (M : Matrix n n S) : f M.det = Matrix.det (f.mapMatrix M) := f.toRingHom.map_det _ theorem _root_.AlgEquiv.map_det [Algebra R S] {T : Type z} [CommRing T] [Algebra R T] (f : S ≃ₐ[R] T) (M : Matrix n n S) : f M.det = Matrix.det (f.mapMatrix M) := f.toAlgHom.map_det _ @[norm_cast] theorem _root_.Int.cast_det (M : Matrix n n ℤ) : (M.det : R) = (M.map fun x ↦ (x : R)).det := Int.castRingHom R |>.map_det M @[norm_cast] theorem _root_.Rat.cast_det {F : Type*} [Field F] [CharZero F] (M : Matrix n n ℚ) : (M.det : F) = (M.map fun x ↦ (x : F)).det := Rat.castHom F |>.map_det M end HomMap @[simp] theorem det_conjTranspose [StarRing R] (M : Matrix m m R) : det Mᴴ = star (det M) := ((starRingEnd R).map_det _).symm.trans <| congr_arg star M.det_transpose section DetZero /-! ### `det_zero` section Prove that a matrix with a repeated column has determinant equal to zero. -/ theorem det_eq_zero_of_row_eq_zero {A : Matrix n n R} (i : n) (h : ∀ j, A i j = 0) : det A = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_coord_zero i (funext h) theorem det_eq_zero_of_column_eq_zero {A : Matrix n n R} (j : n) (h : ∀ i, A i j = 0) : det A = 0 := by rw [← det_transpose] exact det_eq_zero_of_row_eq_zero j h variable {M : Matrix n n R} {i j : n} /-- If a matrix has a repeated row, the determinant will be zero. -/ theorem det_zero_of_row_eq (i_ne_j : i ≠ j) (hij : M i = M j) : M.det = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_eq_zero_of_eq M hij i_ne_j /-- If a matrix has a repeated column, the determinant will be zero. -/ theorem det_zero_of_column_eq (i_ne_j : i ≠ j) (hij : ∀ k, M k i = M k j) : M.det = 0 := by rw [← det_transpose, det_zero_of_row_eq i_ne_j] exact funext hij /-- If we repeat a row of a matrix, we get a matrix of determinant zero. -/ theorem det_updateRow_eq_zero (h : i ≠ j) : (M.updateRow j (M i)).det = 0 := det_zero_of_row_eq h (by simp [h]) /-- If we repeat a column of a matrix, we get a matrix of determinant zero. -/ theorem det_updateCol_eq_zero (h : i ≠ j) :
(M.updateCol j (fun k ↦ M k i)).det = 0 := det_zero_of_column_eq h (by simp [h]) @[deprecated (since := "2024-12-11")] alias det_updateColumn_eq_zero := det_updateCol_eq_zero
Mathlib/LinearAlgebra/Matrix/Determinant/Basic.lean
374
376
/- Copyright (c) 2021 Martin Zinkevich. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Martin Zinkevich, Rémy Degenne -/ import Mathlib.Logic.Encodable.Lattice import Mathlib.MeasureTheory.MeasurableSpace.Defs import Mathlib.Order.Disjointed /-! # Induction principles for measurable sets, related to π-systems and λ-systems. ## Main statements * The main theorem of this file is Dynkin's π-λ theorem, which appears here as an induction principle `induction_on_inter`. Suppose `s` is a collection of subsets of `α` such that the intersection of two members of `s` belongs to `s` whenever it is nonempty. Let `m` be the σ-algebra generated by `s`. In order to check that a predicate `C` holds on every member of `m`, it suffices to check that `C` holds on the members of `s` and that `C` is preserved by complementation and *disjoint* countable unions. * The proof of this theorem relies on the notion of `IsPiSystem`, i.e., a collection of sets which is closed under binary non-empty intersections. Note that this is a small variation around the usual notion in the literature, which often requires that a π-system is non-empty, and closed also under disjoint intersections. This variation turns out to be convenient for the formalization. * The proof of Dynkin's π-λ theorem also requires the notion of `DynkinSystem`, i.e., a collection of sets which contains the empty set, is closed under complementation and under countable union of pairwise disjoint sets. The disjointness condition is the only difference with `σ`-algebras. * `generatePiSystem g` gives the minimal π-system containing `g`. This can be considered a Galois insertion into both measurable spaces and sets. * `generateFrom_generatePiSystem_eq` proves that if you start from a collection of sets `g`, take the generated π-system, and then the generated σ-algebra, you get the same result as the σ-algebra generated from `g`. This is useful because there are connections between independent sets that are π-systems and the generated independent spaces. * `mem_generatePiSystem_iUnion_elim` and `mem_generatePiSystem_iUnion_elim'` show that any element of the π-system generated from the union of a set of π-systems can be represented as the intersection of a finite number of elements from these sets. * `piiUnionInter` defines a new π-system from a family of π-systems `π : ι → Set (Set α)` and a set of indices `S : Set ι`. `piiUnionInter π S` is the set of sets that can be written as `⋂ x ∈ t, f x` for some finset `t ∈ S` and sets `f x ∈ π x`. ## Implementation details * `IsPiSystem` is a predicate, not a type. Thus, we don't explicitly define the galois insertion, nor do we define a complete lattice. In theory, we could define a complete lattice and galois insertion on the subtype corresponding to `IsPiSystem`. -/ open MeasurableSpace Set open MeasureTheory variable {α β : Type*} /-- A π-system is a collection of subsets of `α` that is closed under binary intersection of non-disjoint sets. Usually it is also required that the collection is nonempty, but we don't do that here. -/ def IsPiSystem (C : Set (Set α)) : Prop := ∀ᵉ (s ∈ C) (t ∈ C), (s ∩ t : Set α).Nonempty → s ∩ t ∈ C namespace MeasurableSpace theorem isPiSystem_measurableSet {α : Type*} [MeasurableSpace α] : IsPiSystem { s : Set α | MeasurableSet s } := fun _ hs _ ht _ => hs.inter ht end MeasurableSpace theorem IsPiSystem.singleton (S : Set α) : IsPiSystem ({S} : Set (Set α)) := by intro s h_s t h_t _ rw [Set.mem_singleton_iff.1 h_s, Set.mem_singleton_iff.1 h_t, Set.inter_self, Set.mem_singleton_iff] theorem IsPiSystem.insert_empty {S : Set (Set α)} (h_pi : IsPiSystem S) : IsPiSystem (insert ∅ S) := by intro s hs t ht hst rcases hs with hs | hs · simp [hs] · rcases ht with ht | ht · simp [ht] · exact Set.mem_insert_of_mem _ (h_pi s hs t ht hst) theorem IsPiSystem.insert_univ {S : Set (Set α)} (h_pi : IsPiSystem S) : IsPiSystem (insert Set.univ S) := by intro s hs t ht hst rcases hs with hs | hs · rcases ht with ht | ht <;> simp [hs, ht] · rcases ht with ht | ht · simp [hs, ht] · exact Set.mem_insert_of_mem _ (h_pi s hs t ht hst) theorem IsPiSystem.comap {α β} {S : Set (Set β)} (h_pi : IsPiSystem S) (f : α → β) : IsPiSystem { s : Set α | ∃ t ∈ S, f ⁻¹' t = s } := by rintro _ ⟨s, hs_mem, rfl⟩ _ ⟨t, ht_mem, rfl⟩ hst rw [← Set.preimage_inter] at hst ⊢ exact ⟨s ∩ t, h_pi s hs_mem t ht_mem (nonempty_of_nonempty_preimage hst), rfl⟩ theorem isPiSystem_iUnion_of_directed_le {α ι} (p : ι → Set (Set α)) (hp_pi : ∀ n, IsPiSystem (p n)) (hp_directed : Directed (· ≤ ·) p) : IsPiSystem (⋃ n, p n) := by intro t1 ht1 t2 ht2 h rw [Set.mem_iUnion] at ht1 ht2 ⊢ obtain ⟨n, ht1⟩ := ht1 obtain ⟨m, ht2⟩ := ht2 obtain ⟨k, hpnk, hpmk⟩ : ∃ k, p n ≤ p k ∧ p m ≤ p k := hp_directed n m exact ⟨k, hp_pi k t1 (hpnk ht1) t2 (hpmk ht2) h⟩ theorem isPiSystem_iUnion_of_monotone {α ι} [SemilatticeSup ι] (p : ι → Set (Set α)) (hp_pi : ∀ n, IsPiSystem (p n)) (hp_mono : Monotone p) : IsPiSystem (⋃ n, p n) := isPiSystem_iUnion_of_directed_le p hp_pi (Monotone.directed_le hp_mono) /-- Rectangles formed by π-systems form a π-system. -/ lemma IsPiSystem.prod {C : Set (Set α)} {D : Set (Set β)} (hC : IsPiSystem C) (hD : IsPiSystem D) : IsPiSystem (image2 (· ×ˢ ·) C D) := by rintro _ ⟨s₁, hs₁, t₁, ht₁, rfl⟩ _ ⟨s₂, hs₂, t₂, ht₂, rfl⟩ hst rw [prod_inter_prod] at hst ⊢; rw [prod_nonempty_iff] at hst exact mem_image2_of_mem (hC _ hs₁ _ hs₂ hst.1) (hD _ ht₁ _ ht₂ hst.2) section Order variable {ι ι' : Sort*} [LinearOrder α] theorem isPiSystem_image_Iio (s : Set α) : IsPiSystem (Iio '' s) := by rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ - exact ⟨a ⊓ b, inf_ind a b ha hb, Iio_inter_Iio.symm⟩ theorem isPiSystem_Iio : IsPiSystem (range Iio : Set (Set α)) := @image_univ α _ Iio ▸ isPiSystem_image_Iio univ theorem isPiSystem_image_Ioi (s : Set α) : IsPiSystem (Ioi '' s) := @isPiSystem_image_Iio αᵒᵈ _ s theorem isPiSystem_Ioi : IsPiSystem (range Ioi : Set (Set α)) := @image_univ α _ Ioi ▸ isPiSystem_image_Ioi univ theorem isPiSystem_image_Iic (s : Set α) : IsPiSystem (Iic '' s) := by rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ - exact ⟨a ⊓ b, inf_ind a b ha hb, Iic_inter_Iic.symm⟩ theorem isPiSystem_Iic : IsPiSystem (range Iic : Set (Set α)) := @image_univ α _ Iic ▸ isPiSystem_image_Iic univ theorem isPiSystem_image_Ici (s : Set α) : IsPiSystem (Ici '' s) := @isPiSystem_image_Iic αᵒᵈ _ s theorem isPiSystem_Ici : IsPiSystem (range Ici : Set (Set α)) := @image_univ α _ Ici ▸ isPiSystem_image_Ici univ theorem isPiSystem_Ixx_mem {Ixx : α → α → Set α} {p : α → α → Prop} (Hne : ∀ {a b}, (Ixx a b).Nonempty → p a b) (Hi : ∀ {a₁ b₁ a₂ b₂}, Ixx a₁ b₁ ∩ Ixx a₂ b₂ = Ixx (max a₁ a₂) (min b₁ b₂)) (s t : Set α) : IsPiSystem { S | ∃ᵉ (l ∈ s) (u ∈ t), p l u ∧ Ixx l u = S } := by rintro _ ⟨l₁, hls₁, u₁, hut₁, _, rfl⟩ _ ⟨l₂, hls₂, u₂, hut₂, _, rfl⟩ simp only [Hi] exact fun H => ⟨l₁ ⊔ l₂, sup_ind l₁ l₂ hls₁ hls₂, u₁ ⊓ u₂, inf_ind u₁ u₂ hut₁ hut₂, Hne H, rfl⟩ theorem isPiSystem_Ixx {Ixx : α → α → Set α} {p : α → α → Prop} (Hne : ∀ {a b}, (Ixx a b).Nonempty → p a b) (Hi : ∀ {a₁ b₁ a₂ b₂}, Ixx a₁ b₁ ∩ Ixx a₂ b₂ = Ixx (max a₁ a₂) (min b₁ b₂)) (f : ι → α) (g : ι' → α) : @IsPiSystem α { S | ∃ i j, p (f i) (g j) ∧ Ixx (f i) (g j) = S } := by simpa only [exists_range_iff] using isPiSystem_Ixx_mem (@Hne) (@Hi) (range f) (range g) theorem isPiSystem_Ioo_mem (s t : Set α) : IsPiSystem { S | ∃ᵉ (l ∈ s) (u ∈ t), l < u ∧ Ioo l u = S } := isPiSystem_Ixx_mem (Ixx := Ioo) (fun ⟨_, hax, hxb⟩ => hax.trans hxb) Ioo_inter_Ioo s t theorem isPiSystem_Ioo (f : ι → α) (g : ι' → α) : @IsPiSystem α { S | ∃ l u, f l < g u ∧ Ioo (f l) (g u) = S } := isPiSystem_Ixx (Ixx := Ioo) (fun ⟨_, hax, hxb⟩ => hax.trans hxb) Ioo_inter_Ioo f g theorem isPiSystem_Ioc_mem (s t : Set α) : IsPiSystem { S | ∃ᵉ (l ∈ s) (u ∈ t), l < u ∧ Ioc l u = S } := isPiSystem_Ixx_mem (Ixx := Ioc) (fun ⟨_, hax, hxb⟩ => hax.trans_le hxb) Ioc_inter_Ioc s t theorem isPiSystem_Ioc (f : ι → α) (g : ι' → α) : @IsPiSystem α { S | ∃ i j, f i < g j ∧ Ioc (f i) (g j) = S } := isPiSystem_Ixx (Ixx := Ioc) (fun ⟨_, hax, hxb⟩ => hax.trans_le hxb) Ioc_inter_Ioc f g theorem isPiSystem_Ico_mem (s t : Set α) : IsPiSystem { S | ∃ᵉ (l ∈ s) (u ∈ t), l < u ∧ Ico l u = S } := isPiSystem_Ixx_mem (Ixx := Ico) (fun ⟨_, hax, hxb⟩ => hax.trans_lt hxb) Ico_inter_Ico s t theorem isPiSystem_Ico (f : ι → α) (g : ι' → α) : @IsPiSystem α { S | ∃ i j, f i < g j ∧ Ico (f i) (g j) = S } := isPiSystem_Ixx (Ixx := Ico) (fun ⟨_, hax, hxb⟩ => hax.trans_lt hxb) Ico_inter_Ico f g theorem isPiSystem_Icc_mem (s t : Set α) : IsPiSystem { S | ∃ᵉ (l ∈ s) (u ∈ t), l ≤ u ∧ Icc l u = S } := isPiSystem_Ixx_mem (Ixx := Icc) nonempty_Icc.1 (by exact Icc_inter_Icc) s t theorem isPiSystem_Icc (f : ι → α) (g : ι' → α) : @IsPiSystem α { S | ∃ i j, f i ≤ g j ∧ Icc (f i) (g j) = S } := isPiSystem_Ixx (Ixx := Icc) nonempty_Icc.1 (by exact Icc_inter_Icc) f g end Order /-- Given a collection `S` of subsets of `α`, then `generatePiSystem S` is the smallest π-system containing `S`. -/ inductive generatePiSystem (S : Set (Set α)) : Set (Set α) | base {s : Set α} (h_s : s ∈ S) : generatePiSystem S s | inter {s t : Set α} (h_s : generatePiSystem S s) (h_t : generatePiSystem S t) (h_nonempty : (s ∩ t).Nonempty) : generatePiSystem S (s ∩ t) theorem isPiSystem_generatePiSystem (S : Set (Set α)) : IsPiSystem (generatePiSystem S) := fun _ h_s _ h_t h_nonempty => generatePiSystem.inter h_s h_t h_nonempty theorem subset_generatePiSystem_self (S : Set (Set α)) : S ⊆ generatePiSystem S := fun _ => generatePiSystem.base theorem generatePiSystem_subset_self {S : Set (Set α)} (h_S : IsPiSystem S) : generatePiSystem S ⊆ S := fun x h => by induction h with | base h_s => exact h_s | inter _ _ h_nonempty h_s h_u => exact h_S _ h_s _ h_u h_nonempty theorem generatePiSystem_eq {S : Set (Set α)} (h_pi : IsPiSystem S) : generatePiSystem S = S := Set.Subset.antisymm (generatePiSystem_subset_self h_pi) (subset_generatePiSystem_self S) theorem generatePiSystem_mono {S T : Set (Set α)} (hST : S ⊆ T) : generatePiSystem S ⊆ generatePiSystem T := fun t ht => by induction ht with | base h_s => exact generatePiSystem.base (Set.mem_of_subset_of_mem hST h_s) | inter _ _ h_nonempty h_s h_u => exact isPiSystem_generatePiSystem T _ h_s _ h_u h_nonempty theorem generatePiSystem_measurableSet [M : MeasurableSpace α] {S : Set (Set α)} (h_meas_S : ∀ s ∈ S, MeasurableSet s) (t : Set α) (h_in_pi : t ∈ generatePiSystem S) : MeasurableSet t := by induction h_in_pi with | base h_s => apply h_meas_S _ h_s | inter _ _ _ h_s h_u => apply MeasurableSet.inter h_s h_u theorem generateFrom_measurableSet_of_generatePiSystem {g : Set (Set α)} (t : Set α) (ht : t ∈ generatePiSystem g) : MeasurableSet[generateFrom g] t := @generatePiSystem_measurableSet α (generateFrom g) g (fun _ h_s_in_g => measurableSet_generateFrom h_s_in_g) t ht theorem generateFrom_generatePiSystem_eq {g : Set (Set α)} : generateFrom (generatePiSystem g) = generateFrom g := by apply le_antisymm <;> apply generateFrom_le · exact fun t h_t => generateFrom_measurableSet_of_generatePiSystem t h_t · exact fun t h_t => measurableSet_generateFrom (generatePiSystem.base h_t) /-- Every element of the π-system generated by the union of a family of π-systems is a finite intersection of elements from the π-systems. For an indexed union version, see `mem_generatePiSystem_iUnion_elim'`. -/ theorem mem_generatePiSystem_iUnion_elim {α β} {g : β → Set (Set α)} (h_pi : ∀ b, IsPiSystem (g b)) (t : Set α) (h_t : t ∈ generatePiSystem (⋃ b, g b)) :
∃ (T : Finset β) (f : β → Set α), (t = ⋂ b ∈ T, f b) ∧ ∀ b ∈ T, f b ∈ g b := by classical induction h_t with | @base s h_s => rcases h_s with ⟨t', ⟨⟨b, rfl⟩, h_s_in_t'⟩⟩ refine ⟨{b}, fun _ => s, ?_⟩
Mathlib/MeasureTheory/PiSystem.lean
256
261
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Alex Kontorovich, Heather Macbeth -/ import Mathlib.MeasureTheory.Group.Action import Mathlib.MeasureTheory.Group.Pointwise import Mathlib.MeasureTheory.Integral.Lebesgue.Map import Mathlib.MeasureTheory.Integral.Bochner.Set /-! # Fundamental domain of a group action A set `s` is said to be a *fundamental domain* of an action of a group `G` on a measurable space `α` with respect to a measure `μ` if * `s` is a measurable set; * the sets `g • s` over all `g : G` cover almost all points of the whole space; * the sets `g • s`, are pairwise a.e. disjoint, i.e., `μ (g₁ • s ∩ g₂ • s) = 0` whenever `g₁ ≠ g₂`; we require this for `g₂ = 1` in the definition, then deduce it for any two `g₁ ≠ g₂`. In this file we prove that in case of a countable group `G` and a measure preserving action, any two fundamental domains have the same measure, and for a `G`-invariant function, its integrals over any two fundamental domains are equal to each other. We also generate additive versions of all theorems in this file using the `to_additive` attribute. * We define the `HasFundamentalDomain` typeclass, in particular to be able to define the `covolume` of a quotient of `α` by a group `G`, which under reasonable conditions does not depend on the choice of fundamental domain. * We define the `QuotientMeasureEqMeasurePreimage` typeclass to describe a situation in which a measure `μ` on `α ⧸ G` can be computed by taking a measure `ν` on `α` of the intersection of the pullback with a fundamental domain. ## Main declarations * `MeasureTheory.IsFundamentalDomain`: Predicate for a set to be a fundamental domain of the action of a group * `MeasureTheory.fundamentalFrontier`: Fundamental frontier of a set under the action of a group. Elements of `s` that belong to some other translate of `s`. * `MeasureTheory.fundamentalInterior`: Fundamental interior of a set under the action of a group. Elements of `s` that do not belong to any other translate of `s`. -/ open scoped ENNReal Pointwise Topology NNReal ENNReal MeasureTheory open MeasureTheory MeasureTheory.Measure Set Function TopologicalSpace Filter namespace MeasureTheory /-- A measurable set `s` is a *fundamental domain* for an additive action of an additive group `G` on a measurable space `α` with respect to a measure `α` if the sets `g +ᵥ s`, `g : G`, are pairwise a.e. disjoint and cover the whole space. -/ structure IsAddFundamentalDomain (G : Type*) {α : Type*} [Zero G] [VAdd G α] [MeasurableSpace α] (s : Set α) (μ : Measure α := by volume_tac) : Prop where protected nullMeasurableSet : NullMeasurableSet s μ protected ae_covers : ∀ᵐ x ∂μ, ∃ g : G, g +ᵥ x ∈ s protected aedisjoint : Pairwise <| (AEDisjoint μ on fun g : G => g +ᵥ s) /-- A measurable set `s` is a *fundamental domain* for an action of a group `G` on a measurable space `α` with respect to a measure `α` if the sets `g • s`, `g : G`, are pairwise a.e. disjoint and cover the whole space. -/ @[to_additive IsAddFundamentalDomain] structure IsFundamentalDomain (G : Type*) {α : Type*} [One G] [SMul G α] [MeasurableSpace α] (s : Set α) (μ : Measure α := by volume_tac) : Prop where protected nullMeasurableSet : NullMeasurableSet s μ protected ae_covers : ∀ᵐ x ∂μ, ∃ g : G, g • x ∈ s protected aedisjoint : Pairwise <| (AEDisjoint μ on fun g : G => g • s) variable {G H α β E : Type*} namespace IsFundamentalDomain variable [Group G] [Group H] [MulAction G α] [MeasurableSpace α] [MulAction H β] [MeasurableSpace β] [NormedAddCommGroup E] {s t : Set α} {μ : Measure α} /-- If for each `x : α`, exactly one of `g • x`, `g : G`, belongs to a measurable set `s`, then `s` is a fundamental domain for the action of `G` on `α`. -/ @[to_additive "If for each `x : α`, exactly one of `g +ᵥ x`, `g : G`, belongs to a measurable set `s`, then `s` is a fundamental domain for the additive action of `G` on `α`."] theorem mk' (h_meas : NullMeasurableSet s μ) (h_exists : ∀ x : α, ∃! g : G, g • x ∈ s) : IsFundamentalDomain G s μ where nullMeasurableSet := h_meas ae_covers := Eventually.of_forall fun x => (h_exists x).exists aedisjoint a b hab := Disjoint.aedisjoint <| disjoint_left.2 fun x hxa hxb => by rw [mem_smul_set_iff_inv_smul_mem] at hxa hxb exact hab (inv_injective <| (h_exists x).unique hxa hxb) /-- For `s` to be a fundamental domain, it's enough to check `MeasureTheory.AEDisjoint (g • s) s` for `g ≠ 1`. -/ @[to_additive "For `s` to be a fundamental domain, it's enough to check `MeasureTheory.AEDisjoint (g +ᵥ s) s` for `g ≠ 0`."] theorem mk'' (h_meas : NullMeasurableSet s μ) (h_ae_covers : ∀ᵐ x ∂μ, ∃ g : G, g • x ∈ s) (h_ae_disjoint : ∀ g, g ≠ (1 : G) → AEDisjoint μ (g • s) s) (h_qmp : ∀ g : G, QuasiMeasurePreserving ((g • ·) : α → α) μ μ) : IsFundamentalDomain G s μ where nullMeasurableSet := h_meas ae_covers := h_ae_covers aedisjoint := pairwise_aedisjoint_of_aedisjoint_forall_ne_one h_ae_disjoint h_qmp /-- If a measurable space has a finite measure `μ` and a countable group `G` acts quasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient to check that its translates `g • s` are (almost) disjoint and that the sum `∑' g, μ (g • s)` is sufficiently large. -/ @[to_additive "If a measurable space has a finite measure `μ` and a countable additive group `G` acts quasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient to check that its translates `g +ᵥ s` are (almost) disjoint and that the sum `∑' g, μ (g +ᵥ s)` is sufficiently large."] theorem mk_of_measure_univ_le [IsFiniteMeasure μ] [Countable G] (h_meas : NullMeasurableSet s μ) (h_ae_disjoint : ∀ g ≠ (1 : G), AEDisjoint μ (g • s) s) (h_qmp : ∀ g : G, QuasiMeasurePreserving (g • · : α → α) μ μ) (h_measure_univ_le : μ (univ : Set α) ≤ ∑' g : G, μ (g • s)) : IsFundamentalDomain G s μ := have aedisjoint : Pairwise (AEDisjoint μ on fun g : G => g • s) := pairwise_aedisjoint_of_aedisjoint_forall_ne_one h_ae_disjoint h_qmp { nullMeasurableSet := h_meas aedisjoint ae_covers := by replace h_meas : ∀ g : G, NullMeasurableSet (g • s) μ := fun g => by rw [← inv_inv g, ← preimage_smul]; exact h_meas.preimage (h_qmp g⁻¹) have h_meas' : NullMeasurableSet {a | ∃ g : G, g • a ∈ s} μ := by rw [← iUnion_smul_eq_setOf_exists]; exact .iUnion h_meas rw [ae_iff_measure_eq h_meas', ← iUnion_smul_eq_setOf_exists] refine le_antisymm (measure_mono <| subset_univ _) ?_ rw [measure_iUnion₀ aedisjoint h_meas] exact h_measure_univ_le } @[to_additive] theorem iUnion_smul_ae_eq (h : IsFundamentalDomain G s μ) : ⋃ g : G, g • s =ᵐ[μ] univ := eventuallyEq_univ.2 <| h.ae_covers.mono fun _ ⟨g, hg⟩ => mem_iUnion.2 ⟨g⁻¹, _, hg, inv_smul_smul _ _⟩ @[to_additive] theorem measure_ne_zero [Countable G] [SMulInvariantMeasure G α μ] (hμ : μ ≠ 0) (h : IsFundamentalDomain G s μ) : μ s ≠ 0 := by have hc := measure_univ_pos.mpr hμ contrapose! hc rw [← measure_congr h.iUnion_smul_ae_eq] refine le_trans (measure_iUnion_le _) ?_ simp_rw [measure_smul, hc, tsum_zero, le_refl] @[to_additive] theorem mono (h : IsFundamentalDomain G s μ) {ν : Measure α} (hle : ν ≪ μ) : IsFundamentalDomain G s ν := ⟨h.1.mono_ac hle, hle h.2, h.aedisjoint.mono fun _ _ h => hle h⟩ @[to_additive] theorem preimage_of_equiv {ν : Measure β} (h : IsFundamentalDomain G s μ) {f : β → α} (hf : QuasiMeasurePreserving f ν μ) {e : G → H} (he : Bijective e) (hef : ∀ g, Semiconj f (e g • ·) (g • ·)) : IsFundamentalDomain H (f ⁻¹' s) ν where nullMeasurableSet := h.nullMeasurableSet.preimage hf ae_covers := (hf.ae h.ae_covers).mono fun x ⟨g, hg⟩ => ⟨e g, by rwa [mem_preimage, hef g x]⟩ aedisjoint a b hab := by lift e to G ≃ H using he have : (e.symm a⁻¹)⁻¹ ≠ (e.symm b⁻¹)⁻¹ := by simp [hab] have := (h.aedisjoint this).preimage hf simp only [Semiconj] at hef simpa only [onFun, ← preimage_smul_inv, preimage_preimage, ← hef, e.apply_symm_apply, inv_inv] using this @[to_additive] theorem image_of_equiv {ν : Measure β} (h : IsFundamentalDomain G s μ) (f : α ≃ β) (hf : QuasiMeasurePreserving f.symm ν μ) (e : H ≃ G) (hef : ∀ g, Semiconj f (e g • ·) (g • ·)) : IsFundamentalDomain H (f '' s) ν := by rw [f.image_eq_preimage] refine h.preimage_of_equiv hf e.symm.bijective fun g x => ?_ rcases f.surjective x with ⟨x, rfl⟩ rw [← hef _ _, f.symm_apply_apply, f.symm_apply_apply, e.apply_symm_apply] @[to_additive] theorem pairwise_aedisjoint_of_ac {ν} (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) : Pairwise fun g₁ g₂ : G => AEDisjoint ν (g₁ • s) (g₂ • s) := h.aedisjoint.mono fun _ _ H => hν H @[to_additive] theorem smul_of_comm {G' : Type*} [Group G'] [MulAction G' α] [MeasurableSpace G'] [MeasurableSMul G' α] [SMulInvariantMeasure G' α μ] [SMulCommClass G' G α] (h : IsFundamentalDomain G s μ) (g : G') : IsFundamentalDomain G (g • s) μ := h.image_of_equiv (MulAction.toPerm g) (measurePreserving_smul _ _).quasiMeasurePreserving (Equiv.refl _) <| smul_comm g variable [MeasurableSpace G] [MeasurableSMul G α] [SMulInvariantMeasure G α μ] @[to_additive] theorem nullMeasurableSet_smul (h : IsFundamentalDomain G s μ) (g : G) : NullMeasurableSet (g • s) μ := h.nullMeasurableSet.smul g @[to_additive] theorem restrict_restrict (h : IsFundamentalDomain G s μ) (g : G) (t : Set α) : (μ.restrict t).restrict (g • s) = μ.restrict (g • s ∩ t) := restrict_restrict₀ ((h.nullMeasurableSet_smul g).mono restrict_le_self) @[to_additive] theorem smul (h : IsFundamentalDomain G s μ) (g : G) : IsFundamentalDomain G (g • s) μ := h.image_of_equiv (MulAction.toPerm g) (measurePreserving_smul _ _).quasiMeasurePreserving ⟨fun g' => g⁻¹ * g' * g, fun g' => g * g' * g⁻¹, fun g' => by simp [mul_assoc], fun g' => by simp [mul_assoc]⟩ fun g' x => by simp [smul_smul, mul_assoc] variable [Countable G] {ν : Measure α} @[to_additive] theorem sum_restrict_of_ac (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) : (sum fun g : G => ν.restrict (g • s)) = ν := by rw [← restrict_iUnion_ae (h.aedisjoint.mono fun i j h => hν h) fun g => (h.nullMeasurableSet_smul g).mono_ac hν, restrict_congr_set (hν h.iUnion_smul_ae_eq), restrict_univ] @[to_additive] theorem lintegral_eq_tsum_of_ac (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂ν = ∑' g : G, ∫⁻ x in g • s, f x ∂ν := by rw [← lintegral_sum_measure, h.sum_restrict_of_ac hν] @[to_additive] theorem sum_restrict (h : IsFundamentalDomain G s μ) : (sum fun g : G => μ.restrict (g • s)) = μ := h.sum_restrict_of_ac (refl _) @[to_additive] theorem lintegral_eq_tsum (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = ∑' g : G, ∫⁻ x in g • s, f x ∂μ := h.lintegral_eq_tsum_of_ac (refl _) f @[to_additive] theorem lintegral_eq_tsum' (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = ∑' g : G, ∫⁻ x in s, f (g⁻¹ • x) ∂μ := calc ∫⁻ x, f x ∂μ = ∑' g : G, ∫⁻ x in g • s, f x ∂μ := h.lintegral_eq_tsum f _ = ∑' g : G, ∫⁻ x in g⁻¹ • s, f x ∂μ := ((Equiv.inv G).tsum_eq _).symm _ = ∑' g : G, ∫⁻ x in s, f (g⁻¹ • x) ∂μ := tsum_congr fun g => Eq.symm <| (measurePreserving_smul g⁻¹ μ).setLIntegral_comp_emb (measurableEmbedding_const_smul _) _ _ @[to_additive] lemma lintegral_eq_tsum'' (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = ∑' g : G, ∫⁻ x in s, f (g • x) ∂μ := (lintegral_eq_tsum' h f).trans ((Equiv.inv G).tsum_eq (fun g ↦ ∫⁻ (x : α) in s, f (g • x) ∂μ)) @[to_additive] theorem setLIntegral_eq_tsum (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) (t : Set α) : ∫⁻ x in t, f x ∂μ = ∑' g : G, ∫⁻ x in t ∩ g • s, f x ∂μ := calc ∫⁻ x in t, f x ∂μ = ∑' g : G, ∫⁻ x in g • s, f x ∂μ.restrict t := h.lintegral_eq_tsum_of_ac restrict_le_self.absolutelyContinuous _ _ = ∑' g : G, ∫⁻ x in t ∩ g • s, f x ∂μ := by simp only [h.restrict_restrict, inter_comm] @[to_additive] theorem setLIntegral_eq_tsum' (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) (t : Set α) : ∫⁻ x in t, f x ∂μ = ∑' g : G, ∫⁻ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := calc ∫⁻ x in t, f x ∂μ = ∑' g : G, ∫⁻ x in t ∩ g • s, f x ∂μ := h.setLIntegral_eq_tsum f t _ = ∑' g : G, ∫⁻ x in t ∩ g⁻¹ • s, f x ∂μ := ((Equiv.inv G).tsum_eq _).symm _ = ∑' g : G, ∫⁻ x in g⁻¹ • (g • t ∩ s), f x ∂μ := by simp only [smul_set_inter, inv_smul_smul] _ = ∑' g : G, ∫⁻ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := tsum_congr fun g => Eq.symm <| (measurePreserving_smul g⁻¹ μ).setLIntegral_comp_emb (measurableEmbedding_const_smul _) _ _ @[to_additive] theorem measure_eq_tsum_of_ac (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) (t : Set α) : ν t = ∑' g : G, ν (t ∩ g • s) := by have H : ν.restrict t ≪ μ := Measure.restrict_le_self.absolutelyContinuous.trans hν simpa only [setLIntegral_one, Pi.one_def, Measure.restrict_apply₀ ((h.nullMeasurableSet_smul _).mono_ac H), inter_comm] using h.lintegral_eq_tsum_of_ac H 1 @[to_additive] theorem measure_eq_tsum' (h : IsFundamentalDomain G s μ) (t : Set α) : μ t = ∑' g : G, μ (t ∩ g • s) := h.measure_eq_tsum_of_ac AbsolutelyContinuous.rfl t @[to_additive] theorem measure_eq_tsum (h : IsFundamentalDomain G s μ) (t : Set α) : μ t = ∑' g : G, μ (g • t ∩ s) := by simpa only [setLIntegral_one] using h.setLIntegral_eq_tsum' (fun _ => 1) t @[to_additive] theorem measure_zero_of_invariant (h : IsFundamentalDomain G s μ) (t : Set α) (ht : ∀ g : G, g • t = t) (hts : μ (t ∩ s) = 0) : μ t = 0 := by rw [measure_eq_tsum h]; simp [ht, hts] /-- Given a measure space with an action of a finite group `G`, the measure of any `G`-invariant set is determined by the measure of its intersection with a fundamental domain for the action of `G`. -/ @[to_additive measure_eq_card_smul_of_vadd_ae_eq_self "Given a measure space with an action of a finite additive group `G`, the measure of any `G`-invariant set is determined by the measure of its intersection with a fundamental domain for the action of `G`."] theorem measure_eq_card_smul_of_smul_ae_eq_self [Finite G] (h : IsFundamentalDomain G s μ) (t : Set α) (ht : ∀ g : G, (g • t : Set α) =ᵐ[μ] t) : μ t = Nat.card G • μ (t ∩ s) := by haveI : Fintype G := Fintype.ofFinite G rw [h.measure_eq_tsum] replace ht : ∀ g : G, (g • t ∩ s : Set α) =ᵐ[μ] (t ∩ s : Set α) := fun g => ae_eq_set_inter (ht g) (ae_eq_refl s) simp_rw [measure_congr (ht _), tsum_fintype, Finset.sum_const, Nat.card_eq_fintype_card, Finset.card_univ] @[to_additive] protected theorem setLIntegral_eq (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) (f : α → ℝ≥0∞) (hf : ∀ (g : G) (x), f (g • x) = f x) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in t, f x ∂μ := calc ∫⁻ x in s, f x ∂μ = ∑' g : G, ∫⁻ x in s ∩ g • t, f x ∂μ := ht.setLIntegral_eq_tsum _ _ _ = ∑' g : G, ∫⁻ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := by simp only [hf, inter_comm] _ = ∫⁻ x in t, f x ∂μ := (hs.setLIntegral_eq_tsum' _ _).symm @[to_additive] theorem measure_set_eq (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {A : Set α} (hA₀ : MeasurableSet A) (hA : ∀ g : G, (fun x => g • x) ⁻¹' A = A) : μ (A ∩ s) = μ (A ∩ t) := by have : ∫⁻ x in s, A.indicator 1 x ∂μ = ∫⁻ x in t, A.indicator 1 x ∂μ := by refine hs.setLIntegral_eq ht (Set.indicator A fun _ => 1) fun g x ↦ ?_ convert (Set.indicator_comp_right (g • · : α → α) (g := fun _ ↦ (1 : ℝ≥0∞))).symm rw [hA g] simpa [Measure.restrict_apply hA₀, lintegral_indicator hA₀] using this /-- If `s` and `t` are two fundamental domains of the same action, then their measures are equal. -/ @[to_additive "If `s` and `t` are two fundamental domains of the same action, then their measures are equal."] protected theorem measure_eq (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) : μ s = μ t := by simpa only [setLIntegral_one] using hs.setLIntegral_eq ht (fun _ => 1) fun _ _ => rfl @[to_additive] protected theorem aestronglyMeasurable_on_iff {β : Type*} [TopologicalSpace β] [PseudoMetrizableSpace β] (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {f : α → β} (hf : ∀ (g : G) (x), f (g • x) = f x) : AEStronglyMeasurable f (μ.restrict s) ↔ AEStronglyMeasurable f (μ.restrict t) := calc AEStronglyMeasurable f (μ.restrict s) ↔ AEStronglyMeasurable f (Measure.sum fun g : G => μ.restrict (g • t ∩ s)) := by simp only [← ht.restrict_restrict, ht.sum_restrict_of_ac restrict_le_self.absolutelyContinuous] _ ↔ ∀ g : G, AEStronglyMeasurable f (μ.restrict (g • (g⁻¹ • s ∩ t))) := by simp only [smul_set_inter, inter_comm, smul_inv_smul, aestronglyMeasurable_sum_measure_iff] _ ↔ ∀ g : G, AEStronglyMeasurable f (μ.restrict (g⁻¹ • (g⁻¹⁻¹ • s ∩ t))) := inv_surjective.forall _ ↔ ∀ g : G, AEStronglyMeasurable f (μ.restrict (g⁻¹ • (g • s ∩ t))) := by simp only [inv_inv] _ ↔ ∀ g : G, AEStronglyMeasurable f (μ.restrict (g • s ∩ t)) := by refine forall_congr' fun g => ?_ have he : MeasurableEmbedding (g⁻¹ • · : α → α) := measurableEmbedding_const_smul _ rw [← image_smul, ← ((measurePreserving_smul g⁻¹ μ).restrict_image_emb he _).aestronglyMeasurable_comp_iff he] simp only [Function.comp_def, hf] _ ↔ AEStronglyMeasurable f (μ.restrict t) := by simp only [← aestronglyMeasurable_sum_measure_iff, ← hs.restrict_restrict, hs.sum_restrict_of_ac restrict_le_self.absolutelyContinuous] @[deprecated (since := "2025-04-09")] alias aEStronglyMeasurable_on_iff := MeasureTheory.IsFundamentalDomain.aestronglyMeasurable_on_iff @[deprecated (since := "2025-04-09")] alias _root_.MeasureTheory.IsAddFundamentalDomain.aEStronglyMeasurable_on_iff := MeasureTheory.IsAddFundamentalDomain.aestronglyMeasurable_on_iff @[to_additive] protected theorem hasFiniteIntegral_on_iff (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {f : α → E} (hf : ∀ (g : G) (x), f (g • x) = f x) : HasFiniteIntegral f (μ.restrict s) ↔ HasFiniteIntegral f (μ.restrict t) := by dsimp only [HasFiniteIntegral] rw [hs.setLIntegral_eq ht] intro g x; rw [hf] @[to_additive] protected theorem integrableOn_iff (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {f : α → E} (hf : ∀ (g : G) (x), f (g • x) = f x) : IntegrableOn f s μ ↔ IntegrableOn f t μ := and_congr (hs.aestronglyMeasurable_on_iff ht hf) (hs.hasFiniteIntegral_on_iff ht hf) variable [NormedSpace ℝ E] @[to_additive] theorem integral_eq_tsum_of_ac (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) (f : α → E) (hf : Integrable f ν) : ∫ x, f x ∂ν = ∑' g : G, ∫ x in g • s, f x ∂ν := by rw [← MeasureTheory.integral_sum_measure, h.sum_restrict_of_ac hν] rw [h.sum_restrict_of_ac hν] exact hf @[to_additive] theorem integral_eq_tsum (h : IsFundamentalDomain G s μ) (f : α → E) (hf : Integrable f μ) : ∫ x, f x ∂μ = ∑' g : G, ∫ x in g • s, f x ∂μ := integral_eq_tsum_of_ac h (by rfl) f hf @[to_additive] theorem integral_eq_tsum' (h : IsFundamentalDomain G s μ) (f : α → E) (hf : Integrable f μ) : ∫ x, f x ∂μ = ∑' g : G, ∫ x in s, f (g⁻¹ • x) ∂μ := calc ∫ x, f x ∂μ = ∑' g : G, ∫ x in g • s, f x ∂μ := h.integral_eq_tsum f hf _ = ∑' g : G, ∫ x in g⁻¹ • s, f x ∂μ := ((Equiv.inv G).tsum_eq _).symm _ = ∑' g : G, ∫ x in s, f (g⁻¹ • x) ∂μ := tsum_congr fun g => (measurePreserving_smul g⁻¹ μ).setIntegral_image_emb (measurableEmbedding_const_smul _) _ _ @[to_additive] lemma integral_eq_tsum'' (h : IsFundamentalDomain G s μ) (f : α → E) (hf : Integrable f μ) : ∫ x, f x ∂μ = ∑' g : G, ∫ x in s, f (g • x) ∂μ := (integral_eq_tsum' h f hf).trans ((Equiv.inv G).tsum_eq (fun g ↦ ∫ (x : α) in s, f (g • x) ∂μ)) @[to_additive] theorem setIntegral_eq_tsum (h : IsFundamentalDomain G s μ) {f : α → E} {t : Set α} (hf : IntegrableOn f t μ) : ∫ x in t, f x ∂μ = ∑' g : G, ∫ x in t ∩ g • s, f x ∂μ := calc ∫ x in t, f x ∂μ = ∑' g : G, ∫ x in g • s, f x ∂μ.restrict t := h.integral_eq_tsum_of_ac restrict_le_self.absolutelyContinuous f hf _ = ∑' g : G, ∫ x in t ∩ g • s, f x ∂μ := by simp only [h.restrict_restrict, measure_smul, inter_comm] @[to_additive] theorem setIntegral_eq_tsum' (h : IsFundamentalDomain G s μ) {f : α → E} {t : Set α} (hf : IntegrableOn f t μ) : ∫ x in t, f x ∂μ = ∑' g : G, ∫ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := calc ∫ x in t, f x ∂μ = ∑' g : G, ∫ x in t ∩ g • s, f x ∂μ := h.setIntegral_eq_tsum hf _ = ∑' g : G, ∫ x in t ∩ g⁻¹ • s, f x ∂μ := ((Equiv.inv G).tsum_eq _).symm _ = ∑' g : G, ∫ x in g⁻¹ • (g • t ∩ s), f x ∂μ := by simp only [smul_set_inter, inv_smul_smul] _ = ∑' g : G, ∫ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := tsum_congr fun g => (measurePreserving_smul g⁻¹ μ).setIntegral_image_emb (measurableEmbedding_const_smul _) _ _ @[to_additive] protected theorem setIntegral_eq (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {f : α → E} (hf : ∀ (g : G) (x), f (g • x) = f x) : ∫ x in s, f x ∂μ = ∫ x in t, f x ∂μ := by by_cases hfs : IntegrableOn f s μ · have hft : IntegrableOn f t μ := by rwa [ht.integrableOn_iff hs hf] calc ∫ x in s, f x ∂μ = ∑' g : G, ∫ x in s ∩ g • t, f x ∂μ := ht.setIntegral_eq_tsum hfs _ = ∑' g : G, ∫ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := by simp only [hf, inter_comm] _ = ∫ x in t, f x ∂μ := (hs.setIntegral_eq_tsum' hft).symm · rw [integral_undef hfs, integral_undef] rwa [hs.integrableOn_iff ht hf] at hfs /-- If the action of a countable group `G` admits an invariant measure `μ` with a fundamental domain `s`, then every null-measurable set `t` such that the sets `g • t ∩ s` are pairwise a.e.-disjoint has measure at most `μ s`. -/ @[to_additive "If the additive action of a countable group `G` admits an invariant measure `μ` with a fundamental domain `s`, then every null-measurable set `t` such that the sets `g +ᵥ t ∩ s` are pairwise a.e.-disjoint has measure at most `μ s`."] theorem measure_le_of_pairwise_disjoint (hs : IsFundamentalDomain G s μ) (ht : NullMeasurableSet t μ) (hd : Pairwise (AEDisjoint μ on fun g : G => g • t ∩ s)) : μ t ≤ μ s := calc μ t = ∑' g : G, μ (g • t ∩ s) := hs.measure_eq_tsum t _ = μ (⋃ g : G, g • t ∩ s) := Eq.symm <| measure_iUnion₀ hd fun _ => (ht.smul _).inter hs.nullMeasurableSet _ ≤ μ s := measure_mono (iUnion_subset fun _ => inter_subset_right) /-- If the action of a countable group `G` admits an invariant measure `μ` with a fundamental domain `s`, then every null-measurable set `t` of measure strictly greater than `μ s` contains two points `x y` such that `g • x = y` for some `g ≠ 1`. -/ @[to_additive "If the additive action of a countable group `G` admits an invariant measure `μ` with a fundamental domain `s`, then every null-measurable set `t` of measure strictly greater than `μ s` contains two points `x y` such that `g +ᵥ x = y` for some `g ≠ 0`."] theorem exists_ne_one_smul_eq (hs : IsFundamentalDomain G s μ) (htm : NullMeasurableSet t μ) (ht : μ s < μ t) : ∃ x ∈ t, ∃ y ∈ t, ∃ g, g ≠ (1 : G) ∧ g • x = y := by contrapose! ht refine hs.measure_le_of_pairwise_disjoint htm (Pairwise.aedisjoint fun g₁ g₂ hne => ?_) dsimp [Function.onFun] refine (Disjoint.inf_left _ ?_).inf_right _ rw [Set.disjoint_left] rintro _ ⟨x, hx, rfl⟩ ⟨y, hy, hxy : g₂ • y = g₁ • x⟩ refine ht x hx y hy (g₂⁻¹ * g₁) (mt inv_mul_eq_one.1 hne.symm) ?_ rw [mul_smul, ← hxy, inv_smul_smul] /-- If `f` is invariant under the action of a countable group `G`, and `μ` is a `G`-invariant measure with a fundamental domain `s`, then the `essSup` of `f` restricted to `s` is the same as that of `f` on all of its domain. -/ @[to_additive "If `f` is invariant under the action of a countable additive group `G`, and `μ` is a `G`-invariant measure with a fundamental domain `s`, then the `essSup` of `f` restricted to `s` is the same as that of `f` on all of its domain."] theorem essSup_measure_restrict (hs : IsFundamentalDomain G s μ) {f : α → ℝ≥0∞} (hf : ∀ γ : G, ∀ x : α, f (γ • x) = f x) : essSup f (μ.restrict s) = essSup f μ := by refine le_antisymm (essSup_mono_measure' Measure.restrict_le_self) ?_ rw [essSup_eq_sInf (μ.restrict s) f, essSup_eq_sInf μ f]
refine sInf_le_sInf ?_ rintro a (ha : (μ.restrict s) {x : α | a < f x} = 0) rw [Measure.restrict_apply₀' hs.nullMeasurableSet] at ha refine measure_zero_of_invariant hs _ ?_ ha intro γ ext x rw [mem_smul_set_iff_inv_smul_mem]
Mathlib/MeasureTheory/Group/FundamentalDomain.lean
466
472
/- 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.Algebra.Field.Subfield.Defs import Mathlib.Algebra.Order.Group.Pointwise.Interval import Mathlib.Analysis.Normed.Ring.Basic /-! # Normed division rings and fields In this file we define normed fields, and (more generally) normed division rings. We also prove some theorems about these definitions. Some useful results that relate the topology of the normed field to the discrete topology include: * `norm_eq_one_iff_ne_zero_of_discrete` Methods for constructing a normed field instance from a given real absolute value on a field are given in: * AbsoluteValue.toNormedField -/ -- Guard against import creep. assert_not_exists AddChar comap_norm_atTop DilationEquiv Finset.sup_mul_le_mul_sup_of_nonneg IsOfFinOrder Isometry.norm_map_of_map_one NNReal.isOpen_Ico_zero Rat.norm_cast_real RestrictScalars variable {G α β ι : Type*} open Filter open scoped Topology NNReal ENNReal /-- A normed division ring is a division ring endowed with a seminorm which satisfies the equality `‖x y‖ = ‖x‖ ‖y‖`. -/ class NormedDivisionRing (α : Type*) extends Norm α, DivisionRing α, MetricSpace α where /-- The distance is induced by the norm. -/ dist_eq : ∀ x y, dist x y = norm (x - y) /-- The norm is multiplicative. -/ protected norm_mul : ∀ a b, norm (a * b) = norm a * norm b -- see Note [lower instance priority] /-- A normed division ring is a normed ring. -/ instance (priority := 100) NormedDivisionRing.toNormedRing [β : NormedDivisionRing α] : NormedRing α := { β with norm_mul_le a b := (NormedDivisionRing.norm_mul a b).le } -- see Note [lower instance priority] /-- The norm on a normed division ring is strictly multiplicative. -/ instance (priority := 100) NormedDivisionRing.toNormMulClass [NormedDivisionRing α] : NormMulClass α where norm_mul := NormedDivisionRing.norm_mul section NormedDivisionRing variable [NormedDivisionRing α] {a b : α} instance (priority := 900) NormedDivisionRing.to_normOneClass : NormOneClass α := ⟨mul_left_cancel₀ (mt norm_eq_zero.1 (one_ne_zero' α)) <| by rw [← norm_mul, mul_one, mul_one]⟩ @[simp] theorem norm_div (a b : α) : ‖a / b‖ = ‖a‖ / ‖b‖ := map_div₀ (normHom : α →*₀ ℝ) a b @[simp] theorem nnnorm_div (a b : α) : ‖a / b‖₊ = ‖a‖₊ / ‖b‖₊ := map_div₀ (nnnormHom : α →*₀ ℝ≥0) a b @[simp] theorem norm_inv (a : α) : ‖a⁻¹‖ = ‖a‖⁻¹ := map_inv₀ (normHom : α →*₀ ℝ) a @[simp] theorem nnnorm_inv (a : α) : ‖a⁻¹‖₊ = ‖a‖₊⁻¹ := NNReal.eq <| by simp @[simp] lemma enorm_inv {a : α} (ha : a ≠ 0) : ‖a⁻¹‖ₑ = ‖a‖ₑ⁻¹ := by simp [enorm, ENNReal.coe_inv, ha] @[simp] theorem norm_zpow : ∀ (a : α) (n : ℤ), ‖a ^ n‖ = ‖a‖ ^ n := map_zpow₀ (normHom : α →*₀ ℝ) @[simp] theorem nnnorm_zpow : ∀ (a : α) (n : ℤ), ‖a ^ n‖₊ = ‖a‖₊ ^ n := map_zpow₀ (nnnormHom : α →*₀ ℝ≥0) theorem dist_inv_inv₀ {z w : α} (hz : z ≠ 0) (hw : w ≠ 0) : dist z⁻¹ w⁻¹ = dist z w / (‖z‖ * ‖w‖) := by rw [dist_eq_norm, inv_sub_inv' hz hw, norm_mul, norm_mul, norm_inv, norm_inv, mul_comm ‖z‖⁻¹, mul_assoc, dist_eq_norm', div_eq_mul_inv, mul_inv] theorem nndist_inv_inv₀ {z w : α} (hz : z ≠ 0) (hw : w ≠ 0) : nndist z⁻¹ w⁻¹ = nndist z w / (‖z‖₊ * ‖w‖₊) := NNReal.eq <| dist_inv_inv₀ hz hw lemma norm_commutator_sub_one_le (ha : a ≠ 0) (hb : b ≠ 0) : ‖a * b * a⁻¹ * b⁻¹ - 1‖ ≤ 2 * ‖a‖⁻¹ * ‖b‖⁻¹ * ‖a - 1‖ * ‖b - 1‖ := by simpa using norm_commutator_units_sub_one_le (.mk0 a ha) (.mk0 b hb) lemma nnnorm_commutator_sub_one_le (ha : a ≠ 0) (hb : b ≠ 0) : ‖a * b * a⁻¹ * b⁻¹ - 1‖₊ ≤ 2 * ‖a‖₊⁻¹ * ‖b‖₊⁻¹ * ‖a - 1‖₊ * ‖b - 1‖₊ := by simpa using nnnorm_commutator_units_sub_one_le (.mk0 a ha) (.mk0 b hb) namespace NormedDivisionRing section Discrete variable {𝕜 : Type*} [NormedDivisionRing 𝕜] [DiscreteTopology 𝕜] lemma norm_eq_one_iff_ne_zero_of_discrete {x : 𝕜} : ‖x‖ = 1 ↔ x ≠ 0 := by constructor <;> intro hx · contrapose! hx simp [hx] · have : IsOpen {(0 : 𝕜)} := isOpen_discrete {0} simp_rw [Metric.isOpen_singleton_iff, dist_eq_norm, sub_zero] at this obtain ⟨ε, εpos, h'⟩ := this wlog h : ‖x‖ < 1 generalizing 𝕜 with H · push_neg at h rcases h.eq_or_lt with h|h · rw [h] replace h := norm_inv x ▸ inv_lt_one_of_one_lt₀ h rw [← inv_inj, inv_one, ← norm_inv] exact H (by simpa) h' h obtain ⟨k, hk⟩ : ∃ k : ℕ, ‖x‖ ^ k < ε := exists_pow_lt_of_lt_one εpos h rw [← norm_pow] at hk specialize h' _ hk simp [hx] at h' @[simp] lemma norm_le_one_of_discrete (x : 𝕜) : ‖x‖ ≤ 1 := by rcases eq_or_ne x 0 with rfl|hx · simp · simp [norm_eq_one_iff_ne_zero_of_discrete.mpr hx] lemma unitClosedBall_eq_univ_of_discrete : (Metric.closedBall 0 1 : Set 𝕜) = Set.univ := by ext simp @[deprecated (since := "2024-12-01")] alias discreteTopology_unit_closedBall_eq_univ := unitClosedBall_eq_univ_of_discrete end Discrete end NormedDivisionRing end NormedDivisionRing /-- A normed field is a field with a norm satisfying ‖x y‖ = ‖x‖ ‖y‖. -/ class NormedField (α : Type*) extends Norm α, Field α, MetricSpace α where /-- The distance is induced by the norm. -/ dist_eq : ∀ x y, dist x y = norm (x - y) /-- The norm is multiplicative. -/ protected norm_mul : ∀ a b, norm (a * b) = norm a * norm b /-- A nontrivially normed field is a normed field in which there is an element of norm different from `0` and `1`. This makes it possible to bring any element arbitrarily close to `0` by multiplication by the powers of any element, and thus to relate algebra and topology. -/ class NontriviallyNormedField (α : Type*) extends NormedField α where /-- The norm attains a value exceeding 1. -/ non_trivial : ∃ x : α, 1 < ‖x‖ /-- A densely normed field is a normed field for which the image of the norm is dense in `ℝ≥0`, which means it is also nontrivially normed. However, not all nontrivally normed fields are densely normed; in particular, the `Padic`s exhibit this fact. -/ class DenselyNormedField (α : Type*) extends NormedField α where /-- The range of the norm is dense in the collection of nonnegative real numbers. -/ lt_norm_lt : ∀ x y : ℝ, 0 ≤ x → x < y → ∃ a : α, x < ‖a‖ ∧ ‖a‖ < y section NormedField /-- A densely normed field is always a nontrivially normed field. See note [lower instance priority]. -/ instance (priority := 100) DenselyNormedField.toNontriviallyNormedField [DenselyNormedField α] : NontriviallyNormedField α where non_trivial := let ⟨a, h, _⟩ := DenselyNormedField.lt_norm_lt 1 2 zero_le_one one_lt_two ⟨a, h⟩ variable [NormedField α] -- see Note [lower instance priority] instance (priority := 100) NormedField.toNormedDivisionRing : NormedDivisionRing α := { ‹NormedField α› with } -- see Note [lower instance priority] instance (priority := 100) NormedField.toNormedCommRing : NormedCommRing α := { ‹NormedField α› with norm_mul_le a b := (norm_mul a b).le } end NormedField namespace NormedField section Nontrivially variable (α) [NontriviallyNormedField α] theorem exists_one_lt_norm : ∃ x : α, 1 < ‖x‖ := ‹NontriviallyNormedField α›.non_trivial theorem exists_one_lt_nnnorm : ∃ x : α, 1 < ‖x‖₊ := exists_one_lt_norm α theorem exists_one_lt_enorm : ∃ x : α, 1 < ‖x‖ₑ := exists_one_lt_nnnorm α |>.imp fun _ => ENNReal.coe_lt_coe.mpr theorem exists_lt_norm (r : ℝ) : ∃ x : α, r < ‖x‖ := let ⟨w, hw⟩ := exists_one_lt_norm α let ⟨n, hn⟩ := pow_unbounded_of_one_lt r hw ⟨w ^ n, by rwa [norm_pow]⟩ theorem exists_lt_nnnorm (r : ℝ≥0) : ∃ x : α, r < ‖x‖₊ := exists_lt_norm α r theorem exists_lt_enorm {r : ℝ≥0∞} (hr : r ≠ ∞) : ∃ x : α, r < ‖x‖ₑ := by lift r to ℝ≥0 using hr exact mod_cast exists_lt_nnnorm α r theorem exists_norm_lt {r : ℝ} (hr : 0 < r) : ∃ x : α, 0 < ‖x‖ ∧ ‖x‖ < r := let ⟨w, hw⟩ := exists_lt_norm α r⁻¹ ⟨w⁻¹, by rwa [← Set.mem_Ioo, norm_inv, ← Set.mem_inv, Set.inv_Ioo_0_left hr]⟩ theorem exists_nnnorm_lt {r : ℝ≥0} (hr : 0 < r) : ∃ x : α, 0 < ‖x‖₊ ∧ ‖x‖₊ < r := exists_norm_lt α hr /-- TODO: merge with `_root_.exists_enorm_lt`. -/ theorem exists_enorm_lt {r : ℝ≥0∞} (hr : 0 < r) : ∃ x : α, 0 < ‖x‖ₑ ∧ ‖x‖ₑ < r := match r with | ∞ => exists_one_lt_enorm α |>.imp fun _ hx => ⟨zero_le_one.trans_lt hx, ENNReal.coe_lt_top⟩ | (r : ℝ≥0) => exists_nnnorm_lt α (ENNReal.coe_pos.mp hr) |>.imp fun _ => And.imp ENNReal.coe_pos.mpr ENNReal.coe_lt_coe.mpr theorem exists_norm_lt_one : ∃ x : α, 0 < ‖x‖ ∧ ‖x‖ < 1 := exists_norm_lt α one_pos theorem exists_nnnorm_lt_one : ∃ x : α, 0 < ‖x‖₊ ∧ ‖x‖₊ < 1 := exists_norm_lt_one _ theorem exists_enorm_lt_one : ∃ x : α, 0 < ‖x‖ₑ ∧ ‖x‖ₑ < 1 := exists_enorm_lt _ one_pos variable {α} @[instance] theorem nhdsNE_neBot (x : α) : NeBot (𝓝[≠] x) := by rw [← mem_closure_iff_nhdsWithin_neBot, Metric.mem_closure_iff] rintro ε ε0 rcases exists_norm_lt α ε0 with ⟨b, hb0, hbε⟩ refine ⟨x + b, mt (Set.mem_singleton_iff.trans add_eq_left).1 <| norm_pos_iff.1 hb0, ?_⟩ rwa [dist_comm, dist_eq_norm, add_sub_cancel_left] @[deprecated (since := "2025-03-02")] alias punctured_nhds_neBot := nhdsNE_neBot @[instance] theorem nhdsWithin_isUnit_neBot : NeBot (𝓝[{ x : α | IsUnit x }] 0) := by simpa only [isUnit_iff_ne_zero] using nhdsNE_neBot (0 : α) end Nontrivially section Densely variable (α) [DenselyNormedField α] theorem exists_lt_norm_lt {r₁ r₂ : ℝ} (h₀ : 0 ≤ r₁) (h : r₁ < r₂) : ∃ x : α, r₁ < ‖x‖ ∧ ‖x‖ < r₂ := DenselyNormedField.lt_norm_lt r₁ r₂ h₀ h theorem exists_lt_nnnorm_lt {r₁ r₂ : ℝ≥0} (h : r₁ < r₂) : ∃ x : α, r₁ < ‖x‖₊ ∧ ‖x‖₊ < r₂ := mod_cast exists_lt_norm_lt α r₁.prop h instance denselyOrdered_range_norm : DenselyOrdered (Set.range (norm : α → ℝ)) where dense := by
rintro ⟨-, x, rfl⟩ ⟨-, y, rfl⟩ hxy let ⟨z, h⟩ := exists_lt_norm_lt α (norm_nonneg _) hxy exact ⟨⟨‖z‖, z, rfl⟩, h⟩
Mathlib/Analysis/Normed/Field/Basic.lean
270
272
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudryashov, Yaël Dillies -/ import Mathlib.Algebra.Order.Invertible import Mathlib.Algebra.Order.Module.OrderedSMul import Mathlib.LinearAlgebra.AffineSpace.Midpoint import Mathlib.LinearAlgebra.LinearIndependent.Lemmas import Mathlib.LinearAlgebra.Ray import Mathlib.Tactic.GCongr /-! # Segments in vector spaces In a 𝕜-vector space, we define the following objects and properties. * `segment 𝕜 x y`: Closed segment joining `x` and `y`. * `openSegment 𝕜 x y`: Open segment joining `x` and `y`. ## Notations We provide the following notation: * `[x -[𝕜] y] = segment 𝕜 x y` in locale `Convex` ## TODO Generalize all this file to affine spaces. Should we rename `segment` and `openSegment` to `convex.Icc` and `convex.Ioo`? Should we also define `clopenSegment`/`convex.Ico`/`convex.Ioc`? -/ variable {𝕜 E F G ι : Type*} {M : ι → Type*} open Function Set open Pointwise Convex section OrderedSemiring variable [Semiring 𝕜] [PartialOrder 𝕜] [AddCommMonoid E] section SMul variable (𝕜) [SMul 𝕜 E] {s : Set E} {x y : E} /-- Segments in a vector space. -/ def segment (x y : E) : Set E := { z : E | ∃ a b : 𝕜, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ a • x + b • y = z } /-- Open segment in a vector space. Note that `openSegment 𝕜 x x = {x}` instead of being `∅` when the base semiring has some element between `0` and `1`. Denoted as `[x -[𝕜] y]` within the `Convex` namespace. -/ def openSegment (x y : E) : Set E := { z : E | ∃ a b : 𝕜, 0 < a ∧ 0 < b ∧ a + b = 1 ∧ a • x + b • y = z } @[inherit_doc] scoped[Convex] notation (priority := high) "[" x " -[" 𝕜 "] " y "]" => segment 𝕜 x y theorem segment_eq_image₂ (x y : E) : [x -[𝕜] y] = (fun p : 𝕜 × 𝕜 => p.1 • x + p.2 • y) '' { p | 0 ≤ p.1 ∧ 0 ≤ p.2 ∧ p.1 + p.2 = 1 } := by simp only [segment, image, Prod.exists, mem_setOf_eq, exists_prop, and_assoc] theorem openSegment_eq_image₂ (x y : E) : openSegment 𝕜 x y = (fun p : 𝕜 × 𝕜 => p.1 • x + p.2 • y) '' { p | 0 < p.1 ∧ 0 < p.2 ∧ p.1 + p.2 = 1 } := by simp only [openSegment, image, Prod.exists, mem_setOf_eq, exists_prop, and_assoc] theorem segment_symm (x y : E) : [x -[𝕜] y] = [y -[𝕜] x] := Set.ext fun _ => ⟨fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩, fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩ theorem openSegment_symm (x y : E) : openSegment 𝕜 x y = openSegment 𝕜 y x := Set.ext fun _ => ⟨fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩, fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩ theorem openSegment_subset_segment (x y : E) : openSegment 𝕜 x y ⊆ [x -[𝕜] y] := fun _ ⟨a, b, ha, hb, hab, hz⟩ => ⟨a, b, ha.le, hb.le, hab, hz⟩ theorem segment_subset_iff : [x -[𝕜] y] ⊆ s ↔ ∀ a b : 𝕜, 0 ≤ a → 0 ≤ b → a + b = 1 → a • x + b • y ∈ s := ⟨fun H a b ha hb hab => H ⟨a, b, ha, hb, hab, rfl⟩, fun H _ ⟨a, b, ha, hb, hab, hz⟩ => hz ▸ H a b ha hb hab⟩ theorem openSegment_subset_iff : openSegment 𝕜 x y ⊆ s ↔ ∀ a b : 𝕜, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := ⟨fun H a b ha hb hab => H ⟨a, b, ha, hb, hab, rfl⟩, fun H _ ⟨a, b, ha, hb, hab, hz⟩ => hz ▸ H a b ha hb hab⟩ end SMul open Convex section MulActionWithZero variable (𝕜) variable [ZeroLEOneClass 𝕜] [MulActionWithZero 𝕜 E] theorem left_mem_segment (x y : E) : x ∈ [x -[𝕜] y] := ⟨1, 0, zero_le_one, le_refl 0, add_zero 1, by rw [zero_smul, one_smul, add_zero]⟩ theorem right_mem_segment (x y : E) : y ∈ [x -[𝕜] y] := segment_symm 𝕜 y x ▸ left_mem_segment 𝕜 y x end MulActionWithZero section Module variable (𝕜) variable [ZeroLEOneClass 𝕜] [Module 𝕜 E] {s : Set E} {x y z : E} @[simp] theorem segment_same (x : E) : [x -[𝕜] x] = {x} := Set.ext fun z => ⟨fun ⟨a, b, _, _, hab, hz⟩ => by simpa only [(add_smul _ _ _).symm, mem_singleton_iff, hab, one_smul, eq_comm] using hz, fun h => mem_singleton_iff.1 h ▸ left_mem_segment 𝕜 z z⟩ theorem insert_endpoints_openSegment (x y : E) : insert x (insert y (openSegment 𝕜 x y)) = [x -[𝕜] y] := by simp only [subset_antisymm_iff, insert_subset_iff, left_mem_segment, right_mem_segment, openSegment_subset_segment, true_and] rintro z ⟨a, b, ha, hb, hab, rfl⟩ refine hb.eq_or_gt.imp ?_ fun hb' => ha.eq_or_gt.imp ?_ fun ha' => ?_ · rintro rfl rw [← add_zero a, hab, one_smul, zero_smul, add_zero] · rintro rfl rw [← zero_add b, hab, one_smul, zero_smul, zero_add] · exact ⟨a, b, ha', hb', hab, rfl⟩ variable {𝕜} theorem mem_openSegment_of_ne_left_right (hx : x ≠ z) (hy : y ≠ z) (hz : z ∈ [x -[𝕜] y]) : z ∈ openSegment 𝕜 x y := by rw [← insert_endpoints_openSegment] at hz exact (hz.resolve_left hx.symm).resolve_left hy.symm theorem openSegment_subset_iff_segment_subset (hx : x ∈ s) (hy : y ∈ s) : openSegment 𝕜 x y ⊆ s ↔ [x -[𝕜] y] ⊆ s := by simp only [← insert_endpoints_openSegment, insert_subset_iff, *, true_and] end Module end OrderedSemiring open Convex section OrderedRing variable (𝕜) [Ring 𝕜] [PartialOrder 𝕜] [AddRightMono 𝕜] [AddCommGroup E] [AddCommGroup F] [AddCommGroup G] [Module 𝕜 E] [Module 𝕜 F] section DenselyOrdered variable [ZeroLEOneClass 𝕜] [Nontrivial 𝕜] [DenselyOrdered 𝕜] @[simp] theorem openSegment_same (x : E) : openSegment 𝕜 x x = {x} := Set.ext fun z => ⟨fun ⟨a, b, _, _, hab, hz⟩ => by simpa only [← add_smul, mem_singleton_iff, hab, one_smul, eq_comm] using hz, fun h : z = x => by obtain ⟨a, ha₀, ha₁⟩ := DenselyOrdered.dense (0 : 𝕜) 1 zero_lt_one refine ⟨a, 1 - a, ha₀, sub_pos_of_lt ha₁, add_sub_cancel _ _, ?_⟩ rw [← add_smul, add_sub_cancel, one_smul, h]⟩ end DenselyOrdered theorem segment_eq_image (x y : E) : [x -[𝕜] y] = (fun θ : 𝕜 => (1 - θ) • x + θ • y) '' Icc (0 : 𝕜) 1 := Set.ext fun _ => ⟨fun ⟨a, b, ha, hb, hab, hz⟩ => ⟨b, ⟨hb, hab ▸ le_add_of_nonneg_left ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel_right]⟩, fun ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩ => ⟨1 - θ, θ, sub_nonneg.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩ theorem openSegment_eq_image (x y : E) : openSegment 𝕜 x y = (fun θ : 𝕜 => (1 - θ) • x + θ • y) '' Ioo (0 : 𝕜) 1 := Set.ext fun _ => ⟨fun ⟨a, b, ha, hb, hab, hz⟩ => ⟨b, ⟨hb, hab ▸ lt_add_of_pos_left _ ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel_right]⟩, fun ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩ => ⟨1 - θ, θ, sub_pos.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩ theorem segment_eq_image' (x y : E) : [x -[𝕜] y] = (fun θ : 𝕜 => x + θ • (y - x)) '' Icc (0 : 𝕜) 1 := by convert segment_eq_image 𝕜 x y using 2 simp only [smul_sub, sub_smul, one_smul] abel theorem openSegment_eq_image' (x y : E) : openSegment 𝕜 x y = (fun θ : 𝕜 => x + θ • (y - x)) '' Ioo (0 : 𝕜) 1 := by convert openSegment_eq_image 𝕜 x y using 2 simp only [smul_sub, sub_smul, one_smul] abel theorem segment_eq_image_lineMap (x y : E) : [x -[𝕜] y] = AffineMap.lineMap x y '' Icc (0 : 𝕜) 1 := by convert segment_eq_image 𝕜 x y using 2 exact AffineMap.lineMap_apply_module _ _ _ theorem openSegment_eq_image_lineMap (x y : E) : openSegment 𝕜 x y = AffineMap.lineMap x y '' Ioo (0 : 𝕜) 1 := by convert openSegment_eq_image 𝕜 x y using 2 exact AffineMap.lineMap_apply_module _ _ _ @[simp] theorem image_segment (f : E →ᵃ[𝕜] F) (a b : E) : f '' [a -[𝕜] b] = [f a -[𝕜] f b] := Set.ext fun x => by simp_rw [segment_eq_image_lineMap, mem_image, exists_exists_and_eq_and, AffineMap.apply_lineMap] @[simp] theorem image_openSegment (f : E →ᵃ[𝕜] F) (a b : E) : f '' openSegment 𝕜 a b = openSegment 𝕜 (f a) (f b) := Set.ext fun x => by simp_rw [openSegment_eq_image_lineMap, mem_image, exists_exists_and_eq_and, AffineMap.apply_lineMap] @[simp] theorem vadd_segment [AddTorsor G E] [VAddCommClass G E E] (a : G) (b c : E) : a +ᵥ [b -[𝕜] c] = [a +ᵥ b -[𝕜] a +ᵥ c] := image_segment 𝕜 ⟨_, LinearMap.id, fun _ _ => vadd_comm _ _ _⟩ b c @[simp] theorem vadd_openSegment [AddTorsor G E] [VAddCommClass G E E] (a : G) (b c : E) : a +ᵥ openSegment 𝕜 b c = openSegment 𝕜 (a +ᵥ b) (a +ᵥ c) := image_openSegment 𝕜 ⟨_, LinearMap.id, fun _ _ => vadd_comm _ _ _⟩ b c @[simp] theorem mem_segment_translate (a : E) {x b c} : a + x ∈ [a + b -[𝕜] a + c] ↔ x ∈ [b -[𝕜] c] := by simp_rw [← vadd_eq_add, ← vadd_segment, vadd_mem_vadd_set_iff] @[simp] theorem mem_openSegment_translate (a : E) {x b c : E} : a + x ∈ openSegment 𝕜 (a + b) (a + c) ↔ x ∈ openSegment 𝕜 b c := by simp_rw [← vadd_eq_add, ← vadd_openSegment, vadd_mem_vadd_set_iff] theorem segment_translate_preimage (a b c : E) : (fun x => a + x) ⁻¹' [a + b -[𝕜] a + c] = [b -[𝕜] c] := Set.ext fun _ => mem_segment_translate 𝕜 a theorem openSegment_translate_preimage (a b c : E) : (fun x => a + x) ⁻¹' openSegment 𝕜 (a + b) (a + c) = openSegment 𝕜 b c := Set.ext fun _ => mem_openSegment_translate 𝕜 a theorem segment_translate_image (a b c : E) : (fun x => a + x) '' [b -[𝕜] c] = [a + b -[𝕜] a + c] := segment_translate_preimage 𝕜 a b c ▸ image_preimage_eq _ <| add_left_surjective a theorem openSegment_translate_image (a b c : E) : (fun x => a + x) '' openSegment 𝕜 b c = openSegment 𝕜 (a + b) (a + c) := openSegment_translate_preimage 𝕜 a b c ▸ image_preimage_eq _ <| add_left_surjective a lemma segment_inter_subset_endpoint_of_linearIndependent_sub {c x y : E} (h : LinearIndependent 𝕜 ![x - c, y - c]) : [c -[𝕜] x] ∩ [c -[𝕜] y] ⊆ {c} := by intro z ⟨hzt, hzs⟩ rw [segment_eq_image, mem_image] at hzt hzs rcases hzt with ⟨p, ⟨p0, p1⟩, rfl⟩ rcases hzs with ⟨q, ⟨q0, q1⟩, H⟩ have Hx : x = (x - c) + c := by abel have Hy : y = (y - c) + c := by abel rw [Hx, Hy, smul_add, smul_add] at H have : c + q • (y - c) = c + p • (x - c) := by convert H using 1 <;> simp [sub_smul] obtain ⟨rfl, rfl⟩ : p = 0 ∧ q = 0 := h.eq_zero_of_pair' ((add_right_inj c).1 this).symm simp lemma segment_inter_eq_endpoint_of_linearIndependent_sub [ZeroLEOneClass 𝕜] {c x y : E} (h : LinearIndependent 𝕜 ![x - c, y - c]) : [c -[𝕜] x] ∩ [c -[𝕜] y] = {c} := by refine (segment_inter_subset_endpoint_of_linearIndependent_sub 𝕜 h).antisymm ?_ simp [singleton_subset_iff, left_mem_segment] end OrderedRing theorem sameRay_of_mem_segment [CommRing 𝕜] [PartialOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] {x y z : E} (h : x ∈ [y -[𝕜] z]) : SameRay 𝕜 (x - y) (z - x) := by rw [segment_eq_image'] at h rcases h with ⟨θ, ⟨hθ₀, hθ₁⟩, rfl⟩ simpa only [add_sub_cancel_left, ← sub_sub, sub_smul, one_smul] using (SameRay.sameRay_nonneg_smul_left (z - y) hθ₀).nonneg_smul_right (sub_nonneg.2 hθ₁) lemma segment_inter_eq_endpoint_of_linearIndependent_of_ne [CommRing 𝕜] [PartialOrder 𝕜] [IsOrderedRing 𝕜] [NoZeroDivisors 𝕜] [AddCommGroup E] [Module 𝕜 E] {x y : E} (h : LinearIndependent 𝕜 ![x, y]) {s t : 𝕜} (hs : s ≠ t) (c : E) : [c + x -[𝕜] c + t • y] ∩ [c + x -[𝕜] c + s • y] = {c + x} := by apply segment_inter_eq_endpoint_of_linearIndependent_sub simp only [add_sub_add_left_eq_sub] suffices H : LinearIndependent 𝕜 ![(-1 : 𝕜) • x + t • y, (-1 : 𝕜) • x + s • y] by convert H using 1; simp only [neg_smul, one_smul]; abel_nf nontriviality 𝕜 rw [LinearIndependent.pair_add_smul_add_smul_iff] aesop section LinearOrderedRing variable [Ring 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] {x y : E} theorem midpoint_mem_segment [Invertible (2 : 𝕜)] (x y : E) : midpoint 𝕜 x y ∈ [x -[𝕜] y] := by rw [segment_eq_image_lineMap] exact ⟨⅟ 2, ⟨invOf_nonneg.mpr zero_le_two, invOf_le_one one_le_two⟩, rfl⟩ theorem mem_segment_sub_add [Invertible (2 : 𝕜)] (x y : E) : x ∈ [x - y -[𝕜] x + y] := by convert midpoint_mem_segment (𝕜 := 𝕜) (x - y) (x + y) rw [midpoint_sub_add] theorem mem_segment_add_sub [Invertible (2 : 𝕜)] (x y : E) : x ∈ [x + y -[𝕜] x - y] := by convert midpoint_mem_segment (𝕜 := 𝕜) (x + y) (x - y) rw [midpoint_add_sub] @[simp] theorem left_mem_openSegment_iff [DenselyOrdered 𝕜] [NoZeroSMulDivisors 𝕜 E] : x ∈ openSegment 𝕜 x y ↔ x = y := by constructor · rintro ⟨a, b, _, hb, hab, hx⟩ refine smul_right_injective _ hb.ne' ((add_right_inj (a • x)).1 ?_) rw [hx, ← add_smul, hab, one_smul] · rintro rfl rw [openSegment_same] exact mem_singleton _ @[simp] theorem right_mem_openSegment_iff [DenselyOrdered 𝕜] [NoZeroSMulDivisors 𝕜 E] : y ∈ openSegment 𝕜 x y ↔ x = y := by rw [openSegment_symm, left_mem_openSegment_iff, eq_comm] end LinearOrderedRing section LinearOrderedSemifield variable [Semifield 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] {x y z : E} theorem mem_segment_iff_div : x ∈ [y -[𝕜] z] ↔ ∃ a b : 𝕜, 0 ≤ a ∧ 0 ≤ b ∧ 0 < a + b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x := by constructor · rintro ⟨a, b, ha, hb, hab, rfl⟩ use a, b, ha, hb simp [*] · rintro ⟨a, b, ha, hb, hab, rfl⟩ refine ⟨a / (a + b), b / (a + b), by positivity, by positivity, ?_, rfl⟩ rw [← add_div, div_self hab.ne'] theorem mem_openSegment_iff_div : x ∈ openSegment 𝕜 y z ↔ ∃ a b : 𝕜, 0 < a ∧ 0 < b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x := by constructor · rintro ⟨a, b, ha, hb, hab, rfl⟩ use a, b, ha, hb rw [hab, div_one, div_one] · rintro ⟨a, b, ha, hb, rfl⟩ have hab : 0 < a + b := add_pos' ha hb refine ⟨a / (a + b), b / (a + b), by positivity, by positivity, ?_, rfl⟩ rw [← add_div, div_self hab.ne'] end LinearOrderedSemifield section LinearOrderedField variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] {x y z : E} theorem mem_segment_iff_sameRay : x ∈ [y -[𝕜] z] ↔ SameRay 𝕜 (x - y) (z - x) := by refine ⟨sameRay_of_mem_segment, fun h => ?_⟩ rcases h.exists_eq_smul_add with ⟨a, b, ha, hb, hab, hxy, hzx⟩ rw [add_comm, sub_add_sub_cancel] at hxy hzx rw [← mem_segment_translate _ (-x), neg_add_cancel] refine ⟨b, a, hb, ha, add_comm a b ▸ hab, ?_⟩ rw [← sub_eq_neg_add, ← neg_sub, hxy, ← sub_eq_neg_add, hzx, smul_neg, smul_comm, neg_add_cancel] open AffineMap /-- If `z = lineMap x y c` is a point on the line passing through `x` and `y`, then the open segment `openSegment 𝕜 x y` is included in the union of the open segments `openSegment 𝕜 x z`, `openSegment 𝕜 z y`, and the point `z`. Informally, `(x, y) ⊆ {z} ∪ (x, z) ∪ (z, y)`. -/ theorem openSegment_subset_union (x y : E) {z : E} (hz : z ∈ range (lineMap x y : 𝕜 → E)) : openSegment 𝕜 x y ⊆ insert z (openSegment 𝕜 x z ∪ openSegment 𝕜 z y) := by rcases hz with ⟨c, rfl⟩ simp only [openSegment_eq_image_lineMap, ← mapsTo'] rintro a ⟨h₀, h₁⟩ rcases lt_trichotomy a c with (hac | rfl | hca) · right left have hc : 0 < c := h₀.trans hac refine ⟨a / c, ⟨div_pos h₀ hc, (div_lt_one hc).2 hac⟩, ?_⟩ simp only [← homothety_eq_lineMap, ← homothety_mul_apply, div_mul_cancel₀ _ hc.ne'] · left rfl · right right have hc : 0 < 1 - c := sub_pos.2 (hca.trans h₁) simp only [← lineMap_apply_one_sub y] refine ⟨(a - c) / (1 - c), ⟨div_pos (sub_pos.2 hca) hc, (div_lt_one hc).2 <| sub_lt_sub_right h₁ _⟩, ?_⟩ simp only [← homothety_eq_lineMap, ← homothety_mul_apply, sub_mul, one_mul, div_mul_cancel₀ _ hc.ne', sub_sub_sub_cancel_right] end LinearOrderedField /-! #### Segments in an ordered space Relates `segment`, `openSegment` and `Set.Icc`, `Set.Ico`, `Set.Ioc`, `Set.Ioo` -/ section OrderedSemiring variable [Semiring 𝕜] [PartialOrder 𝕜] section OrderedAddCommMonoid variable [AddCommMonoid E] [PartialOrder E] [IsOrderedAddMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {x y : E} theorem segment_subset_Icc (h : x ≤ y) : [x -[𝕜] y] ⊆ Icc x y := by rintro z ⟨a, b, ha, hb, hab, rfl⟩ constructor · calc x = a • x + b • x := (Convex.combo_self hab _).symm _ ≤ a • x + b • y := by gcongr · calc a • x + b • y ≤ a • y + b • y := by gcongr _ = y := Convex.combo_self hab _ end OrderedAddCommMonoid section OrderedCancelAddCommMonoid variable [AddCommMonoid E] [PartialOrder E] [IsOrderedCancelAddMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {x y : E} theorem openSegment_subset_Ioo (h : x < y) : openSegment 𝕜 x y ⊆ Ioo x y := by rintro z ⟨a, b, ha, hb, hab, rfl⟩ constructor · calc x = a • x + b • x := (Convex.combo_self hab _).symm _ < a • x + b • y := by gcongr · calc a • x + b • y < a • y + b • y := by gcongr _ = y := Convex.combo_self hab _ end OrderedCancelAddCommMonoid section LinearOrderedAddCommMonoid variable [AddCommMonoid E] [LinearOrder E] [IsOrderedAddMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {a b : 𝕜} theorem segment_subset_uIcc (x y : E) : [x -[𝕜] y] ⊆ uIcc x y := by rcases le_total x y with h | h · rw [uIcc_of_le h] exact segment_subset_Icc h · rw [uIcc_of_ge h, segment_symm] exact segment_subset_Icc h theorem Convex.min_le_combo (x y : E) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : min x y ≤ a • x + b • y := (segment_subset_uIcc x y ⟨_, _, ha, hb, hab, rfl⟩).1 theorem Convex.combo_le_max (x y : E) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : a • x + b • y ≤ max x y := (segment_subset_uIcc x y ⟨_, _, ha, hb, hab, rfl⟩).2 end LinearOrderedAddCommMonoid end OrderedSemiring section LinearOrderedField variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] {x y z : 𝕜} theorem Icc_subset_segment : Icc x y ⊆ [x -[𝕜] y] := by rintro z ⟨hxz, hyz⟩ obtain rfl | h := (hxz.trans hyz).eq_or_lt · rw [segment_same] exact hyz.antisymm hxz rw [← sub_nonneg] at hxz hyz rw [← sub_pos] at h refine ⟨(y - z) / (y - x), (z - x) / (y - x), div_nonneg hyz h.le, div_nonneg hxz h.le, ?_, ?_⟩ · rw [← add_div, sub_add_sub_cancel, div_self h.ne'] · rw [smul_eq_mul, smul_eq_mul, ← mul_div_right_comm, ← mul_div_right_comm, ← add_div, div_eq_iff h.ne', add_comm, sub_mul, sub_mul, mul_comm x, sub_add_sub_cancel, mul_sub] @[simp] theorem segment_eq_Icc (h : x ≤ y) : [x -[𝕜] y] = Icc x y := (segment_subset_Icc h).antisymm Icc_subset_segment theorem Ioo_subset_openSegment : Ioo x y ⊆ openSegment 𝕜 x y := fun _ hz => mem_openSegment_of_ne_left_right hz.1.ne hz.2.ne' <| Icc_subset_segment <| Ioo_subset_Icc_self hz @[simp] theorem openSegment_eq_Ioo (h : x < y) : openSegment 𝕜 x y = Ioo x y := (openSegment_subset_Ioo h).antisymm Ioo_subset_openSegment theorem segment_eq_Icc' (x y : 𝕜) : [x -[𝕜] y] = Icc (min x y) (max x y) := by rcases le_total x y with h | h · rw [segment_eq_Icc h, max_eq_right h, min_eq_left h] · rw [segment_symm, segment_eq_Icc h, max_eq_left h, min_eq_right h] theorem openSegment_eq_Ioo' (hxy : x ≠ y) : openSegment 𝕜 x y = Ioo (min x y) (max x y) := by rcases hxy.lt_or_lt with h | h · rw [openSegment_eq_Ioo h, max_eq_right h.le, min_eq_left h.le] · rw [openSegment_symm, openSegment_eq_Ioo h, max_eq_left h.le, min_eq_right h.le] theorem segment_eq_uIcc (x y : 𝕜) : [x -[𝕜] y] = uIcc x y := segment_eq_Icc' _ _ /-- A point is in an `Icc` iff it can be expressed as a convex combination of the endpoints. -/ theorem Convex.mem_Icc (h : x ≤ y) : z ∈ Icc x y ↔ ∃ a b, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z := by simp only [← segment_eq_Icc h, segment, mem_setOf_eq, smul_eq_mul, exists_and_left] /-- A point is in an `Ioo` iff it can be expressed as a strict convex combination of the endpoints. -/ theorem Convex.mem_Ioo (h : x < y) : z ∈ Ioo x y ↔ ∃ a b, 0 < a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z := by simp only [← openSegment_eq_Ioo h, openSegment, smul_eq_mul, exists_and_left, mem_setOf_eq] /-- A point is in an `Ioc` iff it can be expressed as a semistrict convex combination of the endpoints. -/ theorem Convex.mem_Ioc (h : x < y) : z ∈ Ioc x y ↔ ∃ a b, 0 ≤ a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z := by refine ⟨fun hz => ?_, ?_⟩ · obtain ⟨a, b, ha, hb, hab, rfl⟩ := (Convex.mem_Icc h.le).1 (Ioc_subset_Icc_self hz) obtain rfl | hb' := hb.eq_or_lt · rw [add_zero] at hab rw [hab, one_mul, zero_mul, add_zero] at hz exact (hz.1.ne rfl).elim · exact ⟨a, b, ha, hb', hab, rfl⟩ · rintro ⟨a, b, ha, hb, hab, rfl⟩ obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab rwa [hab, one_mul, zero_mul, zero_add, right_mem_Ioc] · exact Ioo_subset_Ioc_self ((Convex.mem_Ioo h).2 ⟨a, b, ha', hb, hab, rfl⟩) /-- A point is in an `Ico` iff it can be expressed as a semistrict convex combination of the endpoints. -/ theorem Convex.mem_Ico (h : x < y) : z ∈ Ico x y ↔ ∃ a b, 0 < a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z := by refine ⟨fun hz => ?_, ?_⟩ · obtain ⟨a, b, ha, hb, hab, rfl⟩ := (Convex.mem_Icc h.le).1 (Ico_subset_Icc_self hz) obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab rw [hab, one_mul, zero_mul, zero_add] at hz exact (hz.2.ne rfl).elim · exact ⟨a, b, ha', hb, hab, rfl⟩ · rintro ⟨a, b, ha, hb, hab, rfl⟩ obtain rfl | hb' := hb.eq_or_lt · rw [add_zero] at hab rwa [hab, one_mul, zero_mul, add_zero, left_mem_Ico] · exact Ioo_subset_Ico_self ((Convex.mem_Ioo h).2 ⟨a, b, ha, hb', hab, rfl⟩) end LinearOrderedField namespace Prod
variable [Semiring 𝕜] [PartialOrder 𝕜] [AddCommMonoid E] [AddCommMonoid F] [Module 𝕜 E] [Module 𝕜 F] theorem segment_subset (x y : E × F) : segment 𝕜 x y ⊆ segment 𝕜 x.1 y.1 ×ˢ segment 𝕜 x.2 y.2 := by
Mathlib/Analysis/Convex/Segment.lean
561
564
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang, Kim Morrison, Joël Riou -/ import Mathlib.Algebra.Homology.Additive import Mathlib.CategoryTheory.Abelian.Injective.Resolution /-! # Right-derived functors We define the right-derived functors `F.rightDerived n : C ⥤ D` for any additive functor `F` out of a category with injective resolutions. We first define a functor `F.rightDerivedToHomotopyCategory : C ⥤ HomotopyCategory D (ComplexShape.up ℕ)` which is `injectiveResolutions C ⋙ F.mapHomotopyCategory _`. We show that if `X : C` and `I : InjectiveResolution X`, then `F.rightDerivedToHomotopyCategory.obj X` identifies to the image in the homotopy category of the functor `F` applied objectwise to `I.cocomplex` (this isomorphism is `I.isoRightDerivedToHomotopyCategoryObj F`). Then, the right-derived functors `F.rightDerived n : C ⥤ D` are obtained by composing `F.rightDerivedToHomotopyCategory` with the homology functors on the homotopy category. Similarly we define natural transformations between right-derived functors coming from natural transformations between the original additive functors, and show how to compute the components. ## Main results * `Functor.isZero_rightDerived_obj_injective_succ`: injective objects have no higher right derived functor. * `NatTrans.rightDerived`: the natural isomorphism between right derived functors induced by natural transformation. * `Functor.toRightDerivedZero`: the natural transformation `F ⟶ F.rightDerived 0`, which is an isomorphism when `F` is left exact (i.e. preserves finite limits), see also `Functor.rightDerivedZeroIsoSelf`. ## TODO * refactor `Functor.rightDerived` (and `Functor.leftDerived`) when the necessary material enters mathlib: derived categories, injective/projective derivability structures, existence of derived functors from derivability structures. Eventually, we shall get a right derived functor `F.rightDerivedFunctorPlus : DerivedCategory.Plus C ⥤ DerivedCategory.Plus D`, and `F.rightDerived` shall be redefined using `F.rightDerivedFunctorPlus`. -/ universe v u namespace CategoryTheory open Category Limits variable {C : Type u} [Category.{v} C] {D : Type*} [Category D] [Abelian C] [HasInjectiveResolutions C] [Abelian D] /-- When `F : C ⥤ D` is an additive functor, this is the functor `C ⥤ HomotopyCategory D (ComplexShape.up ℕ)` which sends `X : C` to `F` applied to an injective resolution of `X`. -/ noncomputable def Functor.rightDerivedToHomotopyCategory (F : C ⥤ D) [F.Additive] : C ⥤ HomotopyCategory D (ComplexShape.up ℕ) := injectiveResolutions C ⋙ F.mapHomotopyCategory _ /-- If `I : InjectiveResolution Z` and `F : C ⥤ D` is an additive functor, this is an isomorphism between `F.rightDerivedToHomotopyCategory.obj X` and the complex obtained by applying `F` to `I.cocomplex`. -/ noncomputable def InjectiveResolution.isoRightDerivedToHomotopyCategoryObj {X : C} (I : InjectiveResolution X) (F : C ⥤ D) [F.Additive] : F.rightDerivedToHomotopyCategory.obj X ≅ (F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).obj I.cocomplex := (F.mapHomotopyCategory _).mapIso I.iso ≪≫ (F.mapHomotopyCategoryFactors _).app I.cocomplex @[reassoc] lemma InjectiveResolution.isoRightDerivedToHomotopyCategoryObj_hom_naturality {X Y : C} (f : X ⟶ Y) (I : InjectiveResolution X) (J : InjectiveResolution Y) (φ : I.cocomplex ⟶ J.cocomplex) (comm : I.ι.f 0 ≫ φ.f 0 = f ≫ J.ι.f 0) (F : C ⥤ D) [F.Additive] : F.rightDerivedToHomotopyCategory.map f ≫ (J.isoRightDerivedToHomotopyCategoryObj F).hom = (I.isoRightDerivedToHomotopyCategoryObj F).hom ≫ (F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).map φ := by dsimp [Functor.rightDerivedToHomotopyCategory, isoRightDerivedToHomotopyCategoryObj] rw [← Functor.map_comp_assoc, iso_hom_naturality f I J φ comm, Functor.map_comp, assoc, assoc] erw [(F.mapHomotopyCategoryFactors (ComplexShape.up ℕ)).hom.naturality] rfl @[reassoc] lemma InjectiveResolution.isoRightDerivedToHomotopyCategoryObj_inv_naturality {X Y : C} (f : X ⟶ Y) (I : InjectiveResolution X) (J : InjectiveResolution Y) (φ : I.cocomplex ⟶ J.cocomplex) (comm : I.ι.f 0 ≫ φ.f 0 = f ≫ J.ι.f 0) (F : C ⥤ D) [F.Additive] : (I.isoRightDerivedToHomotopyCategoryObj F).inv ≫ F.rightDerivedToHomotopyCategory.map f = (F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).map φ ≫ (J.isoRightDerivedToHomotopyCategoryObj F).inv := by rw [← cancel_epi (I.isoRightDerivedToHomotopyCategoryObj F).hom, Iso.hom_inv_id_assoc] dsimp rw [← isoRightDerivedToHomotopyCategoryObj_hom_naturality_assoc f I J φ comm F, Iso.hom_inv_id, comp_id] /-- The right derived functors of an additive functor. -/ noncomputable def Functor.rightDerived (F : C ⥤ D) [F.Additive] (n : ℕ) : C ⥤ D := F.rightDerivedToHomotopyCategory ⋙ HomotopyCategory.homologyFunctor D _ n /-- We can compute a right derived functor using a chosen injective resolution. -/ noncomputable def InjectiveResolution.isoRightDerivedObj {X : C} (I : InjectiveResolution X) (F : C ⥤ D) [F.Additive] (n : ℕ) : (F.rightDerived n).obj X ≅ (HomologicalComplex.homologyFunctor D _ n).obj ((F.mapHomologicalComplex _).obj I.cocomplex) := (HomotopyCategory.homologyFunctor D _ n).mapIso (I.isoRightDerivedToHomotopyCategoryObj F) ≪≫ (HomotopyCategory.homologyFunctorFactors D (ComplexShape.up ℕ) n).app _ @[reassoc] lemma InjectiveResolution.isoRightDerivedObj_hom_naturality {X Y : C} (f : X ⟶ Y) (I : InjectiveResolution X) (J : InjectiveResolution Y) (φ : I.cocomplex ⟶ J.cocomplex) (comm : I.ι.f 0 ≫ φ.f 0 = f ≫ J.ι.f 0)
(F : C ⥤ D) [F.Additive] (n : ℕ) : (F.rightDerived n).map f ≫ (J.isoRightDerivedObj F n).hom = (I.isoRightDerivedObj F n).hom ≫ (F.mapHomologicalComplex _ ⋙ HomologicalComplex.homologyFunctor _ _ n).map φ := by dsimp [isoRightDerivedObj, Functor.rightDerived] rw [assoc, ← Functor.map_comp_assoc, InjectiveResolution.isoRightDerivedToHomotopyCategoryObj_hom_naturality f I J φ comm F, Functor.map_comp, assoc] erw [(HomotopyCategory.homologyFunctorFactors D (ComplexShape.up ℕ) n).hom.naturality] rfl @[reassoc] lemma InjectiveResolution.isoRightDerivedObj_inv_naturality {X Y : C} (f : X ⟶ Y) (I : InjectiveResolution X) (J : InjectiveResolution Y)
Mathlib/CategoryTheory/Abelian/RightDerived.lean
120
133
/- 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.Data.Set.Restrict /-! # Functions over sets This file contains basic results on the following predicates of functions and sets: * `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`. -/ variable {α β γ δ : Type*} {ι : Sort*} {π : α → Type*} open Equiv Equiv.Perm Function namespace Set /-! ### Equality on a set -/ section equality variable {s s₁ s₂ : Set α} {f₁ f₂ f₃ : α → β} {g : β → γ} {a : α} /-- This lemma exists for use by `aesop` as a forward rule. -/ @[aesop safe forward] lemma EqOn.eq_of_mem (h : s.EqOn f₁ f₂) (ha : a ∈ s) : f₁ a = f₂ a := h ha @[simp] theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim @[simp] theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by simp [Set.EqOn] @[simp] theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by simp [EqOn, funext_iff] @[symm] theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s := ⟨EqOn.symm, EqOn.symm⟩ -- 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 -- 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 https://github.com/leanprover-community/mathlib4/pull/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) theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s := image_congr heq /-- 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] theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx) @[simp] theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ := forall₂_or_left theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) := eqOn_union.2 ⟨h₁, h₂⟩ theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha => congr_arg _ <| h ha @[simp] theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} : EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f := forall_mem_range.trans <| funext_iff.symm alias ⟨EqOn.comp_eq, _⟩ := eqOn_range end equality variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} section MapsTo theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t := image_subset_iff.symm theorem mapsTo_prodMap_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) := diagonal_subset_iff.2 fun _ => rfl @[deprecated (since := "2025-04-18")] alias mapsTo_prod_map_diagonal := mapsTo_prodMap_diagonal theorem MapsTo.subset_preimage (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf theorem mapsTo_iff_subset_preimage : MapsTo f s t ↔ s ⊆ f ⁻¹' t := Iff.rfl @[simp] theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t := singleton_subset_iff theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t := empty_subset _ @[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 theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx => h hx ▸ h₁ hx 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 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⟩ theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h => h₁ (h₂ h) theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => 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 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 generalizing x with | zero => rfl | succ n ihn => simp [Nat.iterate, ihn] 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⟩ lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s := mapsTo_of_subsingleton' _ id theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ := fun _ hx => ht (hf <| hs hx) theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx => hf (hs hx) theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx => ht (hf hx) 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 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₂
@[simp] theorem mapsTo_union : MapsTo f (s₁ ∪ s₂) t ↔ MapsTo f s₁ t ∧ MapsTo f s₂ t :=
Mathlib/Data/Set/Function.lean
185
186
/- 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.Attach import Mathlib.Data.Finset.Disjoint import Mathlib.Data.Finset.Erase import Mathlib.Data.Finset.Filter import Mathlib.Data.Finset.Range import Mathlib.Data.Finset.SDiff import Mathlib.Data.Multiset.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Defs import Mathlib.Data.Set.SymmDiff /-! # Basic lemmas on finite sets This file contains lemmas on the interaction of various definitions on the `Finset` type. For an explanation of `Finset` design decisions, please see `Mathlib/Data/Finset/Defs.lean`. ## Main declarations ### Main definitions * `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. ### Equivalences between finsets * The `Mathlib/Logic/Equiv/Defs.lean` file describes 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 Multiset.powerset CompleteLattice Monoid open Multiset Subtype Function universe u variable {α : Type*} {β : Type*} {γ : Type*} namespace Finset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-02-07")] 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 [Nat.add_comm] refine lt_trans ?_ (Nat.lt_succ_self _) exact Multiset.sizeOf_lt_sizeOf_of_mem hx /-! ### Lattice structure -/ section Lattice variable [DecidableEq α] {s s₁ s₂ t t₁ t₂ u v : Finset α} {a b : α} /-! #### union -/ @[simp] theorem disjUnion_eq_union (s t h) : @disjUnion α s t h = s ∪ t := ext fun a => by simp @[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] @[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] /-! #### inter -/ theorem not_disjoint_iff_nonempty_inter : ¬Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff.trans <| by simp [Finset.Nonempty] alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter theorem disjoint_or_nonempty_inter (s t : Finset α) : Disjoint s t ∨ (s ∩ t).Nonempty := by rw [← not_disjoint_iff_nonempty_inter] exact em _ omit [DecidableEq α] in theorem disjoint_of_subset_iff_left_eq_empty (h : s ⊆ t) : Disjoint s t ↔ s = ∅ := disjoint_of_le_iff_left_eq_bot h lemma pairwiseDisjoint_iff {ι : Type*} {s : Set ι} {f : ι → Finset α} : s.PairwiseDisjoint f ↔ ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → (f i ∩ f j).Nonempty → i = j := by simp [Set.PairwiseDisjoint, Set.Pairwise, Function.onFun, not_imp_comm (a := _ = _), not_disjoint_iff_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 : α} @[simp] theorem erase_empty (a : α) : erase ∅ a = ∅ := rfl 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 @[simp] theorem erase_insert_eq_erase (s : Finset α) (a : α) : (insert a s).erase a = s.erase a := ext fun x => by simp +contextual only [mem_erase, mem_insert, and_congr_right_iff, false_or, iff_self, imp_true_iff] 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] 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] 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] @[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] apply or_iff_right_of_imp rintro rfl exact h 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_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 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⟩⟩ 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 _ _⟩ 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] 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 theorem erase_insert_subset (a : α) (s : Finset α) : erase (insert a s) a ⊆ s := subset_insert_iff.1 <| Subset.rfl theorem insert_erase_subset (a : α) (s : Finset α) : s ⊆ insert a (erase s a) := subset_insert_iff.2 <| Subset.rfl 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] 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] 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] 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 : α} lemma erase_sdiff_erase (hab : a ≠ b) (hb : b ∈ s) : s.erase a \ s.erase b = {b} := by ext; aesop -- 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 \ {a} = erase s a := by ext rw [mem_erase, mem_sdiff, mem_singleton, and_comm] -- This lemma matches `Finset.insert_eq` in functionality. theorem erase_eq (s : Finset α) (a : α) : s.erase a = s \ {a} := (sdiff_singleton_eq_erase _ _).symm theorem disjoint_erase_comm : Disjoint (s.erase a) t ↔ Disjoint s (t.erase a) := by simp_rw [erase_eq, disjoint_sdiff_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⟩ 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⟩ theorem inter_erase (a : α) (s t : Finset α) : s ∩ t.erase a = (s ∩ t).erase a := by simp only [erase_eq, inter_sdiff_assoc] @[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 theorem erase_sdiff_comm (s t : Finset α) (a : α) : s.erase a \ t = (s \ t).erase a := by simp_rw [erase_eq, sdiff_right_comm] theorem erase_inter_comm (s t : Finset α) (a : α) : s.erase a ∩ t = s ∩ t.erase a := by rw [erase_inter, inter_erase] 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] 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] 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] 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] 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] 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)] 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] 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⟩)] 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] theorem sdiff_erase_self (ha : a ∈ s) : s \ s.erase a = {a} := by rw [sdiff_erase ha, Finset.sdiff_self, insert_empty_eq] 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] --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 theorem disjoint_sdiff : Disjoint s (t \ s) := sdiff_disjoint.symm theorem disjoint_sdiff_inter (s t : Finset α) : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right sdiff_disjoint end Sdiff /-! ### attach -/ @[simp] theorem attach_empty : attach (∅ : Finset α) = ∅ := rfl @[simp] theorem attach_nonempty_iff {s : Finset α} : s.attach.Nonempty ↔ s.Nonempty := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] 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] /-! ### filter -/ section Filter variable (p q : α → Prop) [DecidablePred p] [DecidablePred q] {s t : Finset α} 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'] 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_of_mem_filter _).mt ha) := eq_of_veq <| Multiset.filter_cons_of_pos s.val hp 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 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 +contextual [disjoint_left] 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 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 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 _ _ _ theorem filter_cons {a : α} (s : Finset α) (ha : a ∉ s) : filter p (cons a s ha) = if p a then cons a (filter p s) ((mem_of_mem_filter _).mt ha) else filter p s := by split_ifs with h · rw [filter_cons_of_pos _ _ _ ha h] · rw [filter_cons_of_neg _ _ _ ha h] section 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] 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] 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] 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] 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] theorem inter_filter (s t : Finset α) : s ∩ filter p t = filter p (s ∩ t) := by rw [inter_comm, filter_inter, inter_comm] theorem filter_insert (a : α) (s : Finset α) : filter p (insert a s) = if p a then insert a (filter p s) else filter p s := by ext x split_ifs with h <;> by_cases h' : x = a <;> simp [h, h'] theorem filter_erase (a : α) (s : Finset α) : filter p (erase s a) = erase (filter p s) a := by ext x simp only [and_assoc, mem_filter, iff_self, mem_erase] theorem filter_or (s : Finset α) : (s.filter fun a => p a ∨ q a) = s.filter p ∪ s.filter q := ext fun _ => by simp [mem_filter, mem_union, and_or_left] theorem filter_and (s : Finset α) : (s.filter fun a => p a ∧ q a) = s.filter p ∩ s.filter q := ext fun _ => by simp [mem_filter, mem_inter, and_comm, and_left_comm, and_self_iff, and_assoc] theorem filter_not (s : Finset α) : (s.filter fun a => ¬p a) = s \ s.filter p := ext fun a => by simp only [Bool.decide_coe, Bool.not_eq_true', mem_filter, and_comm, mem_sdiff, not_and_or, Bool.not_eq_true, and_or_left, and_not_self, or_false] lemma filter_and_not (s : Finset α) (p q : α → Prop) [DecidablePred p] [DecidablePred q] : s.filter (fun a ↦ p a ∧ ¬ q a) = s.filter p \ s.filter q := by rw [filter_and, filter_not, ← inter_sdiff_assoc, inter_eq_left.2 (filter_subset _ _)] theorem sdiff_eq_filter (s₁ s₂ : Finset α) : s₁ \ s₂ = filter (· ∉ s₂) s₁ := ext fun _ => by simp [mem_sdiff, mem_filter] theorem subset_union_elim {s : Finset α} {t₁ t₂ : Set α} (h : ↑s ⊆ t₁ ∪ t₂) : ∃ s₁ s₂ : Finset α, s₁ ∪ s₂ = s ∧ ↑s₁ ⊆ t₁ ∧ ↑s₂ ⊆ t₂ \ t₁ := by classical refine ⟨s.filter (· ∈ t₁), s.filter (· ∉ t₁), ?_, ?_, ?_⟩ · simp [filter_union_right, em] · intro x simp · intro x simp only [not_not, coe_filter, Set.mem_setOf_eq, Set.mem_diff, and_imp] intro hx hx₂ exact ⟨Or.resolve_left (h hx) hx₂, hx₂⟩ -- This is not a good simp lemma, as it would prevent `Finset.mem_filter` from firing -- on, e.g. `x ∈ s.filter (Eq b)`. /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq'` with the equality the other way. -/ theorem filter_eq [DecidableEq β] (s : Finset β) (b : β) : s.filter (Eq b) = ite (b ∈ s) {b} ∅ := by split_ifs with h · ext simp only [mem_filter, mem_singleton, decide_eq_true_eq] refine ⟨fun h => h.2.symm, ?_⟩ rintro rfl exact ⟨h, rfl⟩ · ext simp only [mem_filter, not_and, iff_false, not_mem_empty, decide_eq_true_eq] rintro m rfl exact h m /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq` with the equality the other way. -/ theorem filter_eq' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a = b) = ite (b ∈ s) {b} ∅ := _root_.trans (filter_congr fun _ _ => by simp_rw [@eq_comm _ b]) (filter_eq s b) theorem filter_ne [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => b ≠ a) = s.erase b := by ext simp only [mem_filter, mem_erase, Ne, decide_not, Bool.not_eq_true', decide_eq_false_iff_not] tauto theorem filter_ne' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a ≠ b) = s.erase b := _root_.trans (filter_congr fun _ _ => by simp_rw [@ne_comm _ b]) (filter_ne s b) theorem filter_union_filter_of_codisjoint (s : Finset α) (h : Codisjoint p q) : s.filter p ∪ s.filter q = s := (filter_or _ _ _).symm.trans <| filter_true_of_mem fun x _ => h.top_le x trivial theorem filter_union_filter_neg_eq [∀ x, Decidable (¬p x)] (s : Finset α) : (s.filter p ∪ s.filter fun a => ¬p a) = s := filter_union_filter_of_codisjoint _ _ _ <| @codisjoint_hnot_right _ _ p end end Filter /-! ### range -/ section Range open Nat variable {n m l : ℕ} @[simp] theorem range_filter_eq {n m : ℕ} : (range n).filter (· = m) = if m < n then {m} else ∅ := by convert filter_eq (range n) m using 2 · ext rw [eq_comm] · simp end Range end Finset /-! ### dedup on list and multiset -/ namespace Multiset variable [DecidableEq α] {s t : Multiset α} @[simp] theorem toFinset_add (s t : Multiset α) : toFinset (s + t) = toFinset s ∪ toFinset t := Finset.ext <| by simp @[simp] theorem toFinset_inter (s t : Multiset α) : toFinset (s ∩ t) = toFinset s ∩ toFinset t := Finset.ext <| by simp @[simp] theorem toFinset_union (s t : Multiset α) : (s ∪ t).toFinset = s.toFinset ∪ t.toFinset := by ext; simp @[simp] theorem toFinset_eq_empty {m : Multiset α} : m.toFinset = ∅ ↔ m = 0 := Finset.val_inj.symm.trans Multiset.dedup_eq_zero @[simp] theorem toFinset_nonempty : s.toFinset.Nonempty ↔ s ≠ 0 := by simp only [toFinset_eq_empty, Ne, Finset.nonempty_iff_ne_empty] @[aesop safe apply (rule_sets := [finsetNonempty])] protected alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty @[simp] theorem toFinset_filter (s : Multiset α) (p : α → Prop) [DecidablePred p] : Multiset.toFinset (s.filter p) = s.toFinset.filter p := by ext; simp end Multiset namespace List variable [DecidableEq α] {l l' : List α} {a : α} {f : α → β} {s : Finset α} {t : Set β} {t' : Finset β} @[simp] theorem toFinset_union (l l' : List α) : (l ∪ l').toFinset = l.toFinset ∪ l'.toFinset := by ext simp @[simp] theorem toFinset_inter (l l' : List α) : (l ∩ l').toFinset = l.toFinset ∩ l'.toFinset := by ext simp @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty_iff @[simp] theorem toFinset_filter (s : List α) (p : α → Bool) : (s.filter p).toFinset = s.toFinset.filter (p ·) := by ext; simp [List.mem_filter] end List namespace Finset section ToList @[simp] theorem toList_eq_nil {s : Finset α} : s.toList = [] ↔ s = ∅ := Multiset.toList_eq_nil.trans val_eq_zero theorem empty_toList {s : Finset α} : s.toList.isEmpty ↔ s = ∅ := by simp @[simp] theorem toList_empty : (∅ : Finset α).toList = [] := toList_eq_nil.mpr rfl theorem Nonempty.toList_ne_nil {s : Finset α} (hs : s.Nonempty) : s.toList ≠ [] := mt toList_eq_nil.mp hs.ne_empty theorem Nonempty.not_empty_toList {s : Finset α} (hs : s.Nonempty) : ¬s.toList.isEmpty := mt empty_toList.mp hs.ne_empty end ToList /-! ### choose -/ section Choose variable (p : α → Prop) [DecidablePred p] (l : Finset α) /-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of `l` satisfying `p` this unique element, as an element of the corresponding subtype. -/ def chooseX (hp : ∃! a, a ∈ l ∧ p a) : { a // a ∈ l ∧ p a } := Multiset.chooseX p l.val hp /-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of `l` satisfying `p` this unique element, as an element of the ambient type. -/ def choose (hp : ∃! a, a ∈ l ∧ p a) : α := chooseX p l hp theorem choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (chooseX p l hp).property theorem choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 theorem choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end Choose end Finset namespace Equiv variable [DecidableEq α] {s t : Finset α} open Finset /-- The disjoint union of finsets is a sum -/ def Finset.union (s t : Finset α) (h : Disjoint s t) : s ⊕ t ≃ (s ∪ t : Finset α) := Equiv.setCongr (coe_union _ _) |>.trans (Equiv.Set.union (disjoint_coe.mpr h)) |>.symm @[simp] theorem Finset.union_symm_inl (h : Disjoint s t) (x : s) : Equiv.Finset.union s t h (Sum.inl x) = ⟨x, Finset.mem_union.mpr <| Or.inl x.2⟩ := rfl @[simp] theorem Finset.union_symm_inr (h : Disjoint s t) (y : t) : Equiv.Finset.union s t h (Sum.inr y) = ⟨y, Finset.mem_union.mpr <| Or.inr y.2⟩ := rfl /-- The type of dependent functions on the disjoint union of finsets `s ∪ t` is equivalent to the type of pairs of functions on `s` and on `t`. This is similar to `Equiv.sumPiEquivProdPi`. -/ def piFinsetUnion {ι} [DecidableEq ι] (α : ι → Type*) {s t : Finset ι} (h : Disjoint s t) : ((∀ i : s, α i) × ∀ i : t, α i) ≃ ∀ i : (s ∪ t : Finset ι), α i := let e := Equiv.Finset.union s t h sumPiEquivProdPi (fun b ↦ α (e b)) |>.symm.trans (.piCongrLeft (fun i : ↥(s ∪ t) ↦ α i) e) /-- A finset is equivalent to its coercion as a set. -/ def _root_.Finset.equivToSet (s : Finset α) : s ≃ s.toSet where toFun a := ⟨a.1, mem_coe.2 a.2⟩ invFun a := ⟨a.1, mem_coe.1 a.2⟩ left_inv := fun _ ↦ rfl right_inv := fun _ ↦ rfl end Equiv namespace Multiset variable [DecidableEq α] @[simp] lemma toFinset_replicate (n : ℕ) (a : α) : (replicate n a).toFinset = if n = 0 then ∅ else {a} := by ext x simp only [mem_toFinset, Finset.mem_singleton, mem_replicate] split_ifs with hn <;> simp [hn] end Multiset
Mathlib/Data/Finset/Basic.lean
1,527
1,528
/- 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.Order.Group.Nat import Mathlib.Algebra.Order.GroupWithZero.Canonical import Mathlib.Data.Nat.Cast.WithTop /-! # `WithBot ℕ` Lemmas about the type of natural numbers with a bottom element adjoined. -/ namespace Nat namespace WithBot instance : WellFoundedRelation (WithBot ℕ) where rel := (· < ·) wf := IsWellFounded.wf theorem add_eq_zero_iff {n m : WithBot ℕ} : n + m = 0 ↔ n = 0 ∧ m = 0 := by cases n · simp [WithBot.bot_add] cases m · simp [WithBot.add_bot] simp [← WithBot.coe_add, add_eq_zero_iff_of_nonneg] theorem add_eq_one_iff {n m : WithBot ℕ} : n + m = 1 ↔ n = 0 ∧ m = 1 ∨ n = 1 ∧ m = 0 := by cases n · simp only [WithBot.bot_add, WithBot.bot_ne_one, WithBot.bot_ne_zero, false_and, or_self] cases m
· simp [WithBot.add_bot] simp [← WithBot.coe_add, Nat.add_eq_one_iff] theorem add_eq_two_iff {n m : WithBot ℕ} : n + m = 2 ↔ n = 0 ∧ m = 2 ∨ n = 1 ∧ m = 1 ∨ n = 2 ∧ m = 0 := by cases n
Mathlib/Data/Nat/WithBot.lean
36
41
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Data.List.Lattice import Mathlib.Data.Bool.Basic import Mathlib.Order.Lattice /-! # Intervals in ℕ This file defines intervals of naturals. `List.Ico m n` is the list of integers greater than `m` and strictly less than `n`. ## TODO - Define `Ioo` and `Icc`, state basic lemmas about them. - Also do the versions for integers? - One could generalise even further, defining 'locally finite partial orders', for which `Set.Ico a b` is `[Finite]`, and 'locally finite total orders', for which there is a list model. - Once the above is done, get rid of `Int.range` (and maybe `List.range'`?). -/ open Nat namespace List /-- `Ico n m` is the list of natural numbers `n ≤ x < m`. (Ico stands for "interval, closed-open".) See also `Mathlib/Order/Interval/Basic.lean` for modelling intervals in general preorders, as well as sibling definitions alongside it such as `Set.Ico`, `Multiset.Ico` and `Finset.Ico` for sets, multisets and finite sets respectively. -/ def Ico (n m : ℕ) : List ℕ := range' n (m - n) namespace Ico theorem zero_bot (n : ℕ) : Ico 0 n = range n := by rw [Ico, Nat.sub_zero, range_eq_range'] @[simp] theorem length (n m : ℕ) : length (Ico n m) = m - n := by dsimp [Ico] simp [length_range'] theorem pairwise_lt (n m : ℕ) : Pairwise (· < ·) (Ico n m) := by dsimp [Ico] simp [pairwise_lt_range'] theorem nodup (n m : ℕ) : Nodup (Ico n m) := by dsimp [Ico] simp [nodup_range'] @[simp] theorem mem {n m l : ℕ} : l ∈ Ico n m ↔ n ≤ l ∧ l < m := by suffices n ≤ l ∧ l < n + (m - n) ↔ n ≤ l ∧ l < m by simp [Ico, this] omega theorem eq_nil_of_le {n m : ℕ} (h : m ≤ n) : Ico n m = [] := by simp [Ico, Nat.sub_eq_zero_iff_le.mpr h] theorem map_add (n m k : ℕ) : (Ico n m).map (k + ·) = Ico (n + k) (m + k) := by rw [Ico, Ico, map_add_range', Nat.add_sub_add_right m k, Nat.add_comm n k] theorem map_sub (n m k : ℕ) (h₁ : k ≤ n) : ((Ico n m).map fun x => x - k) = Ico (n - k) (m - k) := by rw [Ico, Ico, Nat.sub_sub_sub_cancel_right h₁, map_sub_range' h₁] @[simp] theorem self_empty {n : ℕ} : Ico n n = [] := eq_nil_of_le (le_refl n) @[simp] theorem eq_empty_iff {n m : ℕ} : Ico n m = [] ↔ m ≤ n := Iff.intro (fun h => Nat.sub_eq_zero_iff_le.mp <| by rw [← length, h, List.length]) eq_nil_of_le theorem append_consecutive {n m l : ℕ} (hnm : n ≤ m) (hml : m ≤ l) : Ico n m ++ Ico m l = Ico n l := by dsimp only [Ico] convert range'_append using 2 · rw [Nat.one_mul, Nat.add_sub_cancel' hnm] · omega @[simp] theorem inter_consecutive (n m l : ℕ) : Ico n m ∩ Ico m l = [] := by apply eq_nil_iff_forall_not_mem.2 intro a simp only [and_imp, not_and, not_lt, List.mem_inter_iff, List.Ico.mem] intro _ h₂ h₃ exfalso exact not_lt_of_ge h₃ h₂ @[simp] theorem bagInter_consecutive (n m l : Nat) : @List.bagInter ℕ instBEqOfDecidableEq (Ico n m) (Ico m l) = [] := (bagInter_nil_iff_inter_nil _ _).2 (by convert inter_consecutive n m l) @[simp] theorem succ_singleton {n : ℕ} : Ico n (n + 1) = [n] := by dsimp [Ico] simp [range', Nat.add_sub_cancel_left] theorem succ_top {n m : ℕ} (h : n ≤ m) : Ico n (m + 1) = Ico n m ++ [m] := by rwa [← succ_singleton, append_consecutive] exact Nat.le_succ _ theorem eq_cons {n m : ℕ} (h : n < m) : Ico n m = n :: Ico (n + 1) m := by rw [← append_consecutive (Nat.le_succ n) h, succ_singleton] rfl @[simp] theorem pred_singleton {m : ℕ} (h : 0 < m) : Ico (m - 1) m = [m - 1] := by simp [Ico, Nat.sub_sub_self (succ_le_of_lt h)] theorem chain'_succ (n m : ℕ) : Chain' (fun a b => b = succ a) (Ico n m) := by by_cases h : n < m · rw [eq_cons h] exact chain_succ_range' _ _ 1 · rw [eq_nil_of_le (le_of_not_gt h)] trivial theorem not_mem_top {n m : ℕ} : m ∉ Ico n m := by simp theorem filter_lt_of_top_le {n m l : ℕ} (hml : m ≤ l) : ((Ico n m).filter fun x => x < l) = Ico n m := filter_eq_self.2 fun k hk => by simp only [(lt_of_lt_of_le (mem.1 hk).2 hml), decide_true] theorem filter_lt_of_le_bot {n m l : ℕ} (hln : l ≤ n) : ((Ico n m).filter fun x => x < l) = [] := filter_eq_nil_iff.2 fun k hk => by simp only [decide_eq_true_eq, not_lt] apply le_trans hln exact (mem.1 hk).1 theorem filter_lt_of_ge {n m l : ℕ} (hlm : l ≤ m) : ((Ico n m).filter fun x => x < l) = Ico n l := by rcases le_total n l with hnl | hln · rw [← append_consecutive hnl hlm, filter_append, filter_lt_of_top_le (le_refl l), filter_lt_of_le_bot (le_refl l), append_nil] · rw [eq_nil_of_le hln, filter_lt_of_le_bot hln] @[simp] theorem filter_lt (n m l : ℕ) : ((Ico n m).filter fun x => x < l) = Ico n (min m l) := by rcases le_total m l with hml | hlm · rw [min_eq_left hml, filter_lt_of_top_le hml] · rw [min_eq_right hlm, filter_lt_of_ge hlm] theorem filter_le_of_le_bot {n m l : ℕ} (hln : l ≤ n) : ((Ico n m).filter fun x => l ≤ x) = Ico n m := filter_eq_self.2 fun k hk => by rw [decide_eq_true_eq] exact le_trans hln (mem.1 hk).1 theorem filter_le_of_top_le {n m l : ℕ} (hml : m ≤ l) : ((Ico n m).filter fun x => l ≤ x) = [] := filter_eq_nil_iff.2 fun k hk => by rw [decide_eq_true_eq] exact not_le_of_gt (lt_of_lt_of_le (mem.1 hk).2 hml) theorem filter_le_of_le {n m l : ℕ} (hnl : n ≤ l) : ((Ico n m).filter fun x => l ≤ x) = Ico l m := by rcases le_total l m with hlm | hml · rw [← append_consecutive hnl hlm, filter_append, filter_le_of_top_le (le_refl l), filter_le_of_le_bot (le_refl l), nil_append] · rw [eq_nil_of_le hml, filter_le_of_top_le hml] @[simp] theorem filter_le (n m l : ℕ) : ((Ico n m).filter fun x => l ≤ x) = Ico (max n l) m := by rcases le_total n l with hnl | hln · rw [max_eq_right hnl, filter_le_of_le hnl] · rw [max_eq_left hln, filter_le_of_le_bot hln] theorem filter_lt_of_succ_bot {n m : ℕ} (hnm : n < m) : ((Ico n m).filter fun x => x < n + 1) = [n] := by have r : min m (n + 1) = n + 1 := (@inf_eq_right _ _ m (n + 1)).mpr hnm simp [filter_lt n m (n + 1), r] @[simp] theorem filter_le_of_bot {n m : ℕ} (hnm : n < m) : ((Ico n m).filter fun x => x ≤ n) = [n] := by rw [← filter_lt_of_succ_bot hnm] exact filter_congr fun _ _ => by simpa using Nat.lt_succ_iff.symm
/-- For any natural numbers n, a, and b, one of the following holds: 1. n < a 2. n ≥ b 3. n ∈ Ico a b
Mathlib/Data/List/Intervals.lean
185
189
/- Copyright (c) 2017 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tim Baumann, Stephen Morgan, Kim Morrison, Floris van Doorn -/ import Mathlib.Tactic.CategoryTheory.Reassoc /-! # Isomorphisms This file defines isomorphisms between objects of a category. ## Main definitions - `structure Iso` : a bundled isomorphism between two objects of a category; - `class IsIso` : an unbundled version of `iso`; note that `IsIso f` is a `Prop`, and only asserts the existence of an inverse. Of course, this inverse is unique, so it doesn't cost us much to use choice to retrieve it. - `inv f`, for the inverse of a morphism with `[IsIso f]` - `asIso` : convert from `IsIso` to `Iso` (noncomputable); - `of_iso` : convert from `Iso` to `IsIso`; - standard operations on isomorphisms (composition, inverse etc) ## Notations - `X ≅ Y` : same as `Iso X Y`; - `α ≪≫ β` : composition of two isomorphisms; it is called `Iso.trans` ## Tags category, category theory, isomorphism -/ universe v u -- morphism levels before object levels. See note [CategoryTheory universes]. namespace CategoryTheory open Category /-- An isomorphism (a.k.a. an invertible morphism) between two objects of a category. The inverse morphism is bundled. See also `CategoryTheory.Core` for the category with the same objects and isomorphisms playing the role of morphisms. -/ @[stacks 0017] structure Iso {C : Type u} [Category.{v} C] (X Y : C) where /-- The forward direction of an isomorphism. -/ hom : X ⟶ Y /-- The backwards direction of an isomorphism. -/ inv : Y ⟶ X /-- Composition of the two directions of an isomorphism is the identity on the source. -/ hom_inv_id : hom ≫ inv = 𝟙 X := by aesop_cat /-- Composition of the two directions of an isomorphism in reverse order is the identity on the target. -/ inv_hom_id : inv ≫ hom = 𝟙 Y := by aesop_cat attribute [reassoc (attr := simp)] Iso.hom_inv_id Iso.inv_hom_id /-- Notation for an isomorphism in a category. -/ infixr:10 " ≅ " => Iso -- type as \cong or \iso variable {C : Type u} [Category.{v} C] {X Y Z : C} namespace Iso @[ext] theorem ext ⦃α β : X ≅ Y⦄ (w : α.hom = β.hom) : α = β := suffices α.inv = β.inv by cases α cases β cases w cases this rfl calc α.inv = α.inv ≫ β.hom ≫ β.inv := by rw [Iso.hom_inv_id, Category.comp_id] _ = (α.inv ≫ α.hom) ≫ β.inv := by rw [Category.assoc, ← w] _ = β.inv := by rw [Iso.inv_hom_id, Category.id_comp] /-- Inverse isomorphism. -/ @[symm] def symm (I : X ≅ Y) : Y ≅ X where hom := I.inv inv := I.hom @[simp] theorem symm_hom (α : X ≅ Y) : α.symm.hom = α.inv := rfl @[simp] theorem symm_inv (α : X ≅ Y) : α.symm.inv = α.hom := rfl @[simp] theorem symm_mk {X Y : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id) : Iso.symm { hom, inv, hom_inv_id := hom_inv_id, inv_hom_id := inv_hom_id } = { hom := inv, inv := hom, hom_inv_id := inv_hom_id, inv_hom_id := hom_inv_id } := rfl @[simp] theorem symm_symm_eq {X Y : C} (α : X ≅ Y) : α.symm.symm = α := rfl theorem symm_bijective {X Y : C} : Function.Bijective (symm : (X ≅ Y) → _) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm_eq, symm_symm_eq⟩ @[simp] theorem symm_eq_iff {X Y : C} {α β : X ≅ Y} : α.symm = β.symm ↔ α = β := symm_bijective.injective.eq_iff theorem nonempty_iso_symm (X Y : C) : Nonempty (X ≅ Y) ↔ Nonempty (Y ≅ X) := ⟨fun h => ⟨h.some.symm⟩, fun h => ⟨h.some.symm⟩⟩ /-- Identity isomorphism. -/ @[refl, simps] def refl (X : C) : X ≅ X where hom := 𝟙 X inv := 𝟙 X instance : Inhabited (X ≅ X) := ⟨Iso.refl X⟩ theorem nonempty_iso_refl (X : C) : Nonempty (X ≅ X) := ⟨default⟩ @[simp] theorem refl_symm (X : C) : (Iso.refl X).symm = Iso.refl X := rfl /-- Composition of two isomorphisms -/ @[simps] def trans (α : X ≅ Y) (β : Y ≅ Z) : X ≅ Z where hom := α.hom ≫ β.hom inv := β.inv ≫ α.inv @[simps] instance instTransIso : Trans (α := C) (· ≅ ·) (· ≅ ·) (· ≅ ·) where trans := trans /-- Notation for composition of isomorphisms. -/ infixr:80 " ≪≫ " => Iso.trans -- type as `\ll \gg`. @[simp] theorem trans_mk {X Y Z : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id) (hom' : Y ⟶ Z) (inv' : Z ⟶ Y) (hom_inv_id') (inv_hom_id') (hom_inv_id'') (inv_hom_id'') : Iso.trans ⟨hom, inv, hom_inv_id, inv_hom_id⟩ ⟨hom', inv', hom_inv_id', inv_hom_id'⟩ = ⟨hom ≫ hom', inv' ≫ inv, hom_inv_id'', inv_hom_id''⟩ := rfl @[simp] theorem trans_symm (α : X ≅ Y) (β : Y ≅ Z) : (α ≪≫ β).symm = β.symm ≪≫ α.symm := rfl @[simp] theorem trans_assoc {Z' : C} (α : X ≅ Y) (β : Y ≅ Z) (γ : Z ≅ Z') : (α ≪≫ β) ≪≫ γ = α ≪≫ β ≪≫ γ := by ext; simp only [trans_hom, Category.assoc] @[simp] theorem refl_trans (α : X ≅ Y) : Iso.refl X ≪≫ α = α := by ext; apply Category.id_comp @[simp] theorem trans_refl (α : X ≅ Y) : α ≪≫ Iso.refl Y = α := by ext; apply Category.comp_id @[simp] theorem symm_self_id (α : X ≅ Y) : α.symm ≪≫ α = Iso.refl Y := ext α.inv_hom_id @[simp] theorem self_symm_id (α : X ≅ Y) : α ≪≫ α.symm = Iso.refl X := ext α.hom_inv_id @[simp] theorem symm_self_id_assoc (α : X ≅ Y) (β : Y ≅ Z) : α.symm ≪≫ α ≪≫ β = β := by rw [← trans_assoc, symm_self_id, refl_trans] @[simp] theorem self_symm_id_assoc (α : X ≅ Y) (β : X ≅ Z) : α ≪≫ α.symm ≪≫ β = β := by rw [← trans_assoc, self_symm_id, refl_trans] theorem inv_comp_eq (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : α.inv ≫ f = g ↔ f = α.hom ≫ g := ⟨fun H => by simp [H.symm], fun H => by simp [H]⟩ theorem eq_inv_comp (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : g = α.inv ≫ f ↔ α.hom ≫ g = f := (inv_comp_eq α.symm).symm theorem comp_inv_eq (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ α.inv = g ↔ f = g ≫ α.hom := ⟨fun H => by simp [H.symm], fun H => by simp [H]⟩ theorem eq_comp_inv (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ α.inv ↔ g ≫ α.hom = f := (comp_inv_eq α.symm).symm theorem inv_eq_inv (f g : X ≅ Y) : f.inv = g.inv ↔ f.hom = g.hom := have : ∀ {X Y : C} (f g : X ≅ Y), f.hom = g.hom → f.inv = g.inv := fun f g h => by rw [ext h] ⟨this f.symm g.symm, this f g⟩ theorem hom_comp_eq_id (α : X ≅ Y) {f : Y ⟶ X} : α.hom ≫ f = 𝟙 X ↔ f = α.inv := by rw [← eq_inv_comp, comp_id] theorem comp_hom_eq_id (α : X ≅ Y) {f : Y ⟶ X} : f ≫ α.hom = 𝟙 Y ↔ f = α.inv := by rw [← eq_comp_inv, id_comp] theorem inv_comp_eq_id (α : X ≅ Y) {f : X ⟶ Y} : α.inv ≫ f = 𝟙 Y ↔ f = α.hom := hom_comp_eq_id α.symm theorem comp_inv_eq_id (α : X ≅ Y) {f : X ⟶ Y} : f ≫ α.inv = 𝟙 X ↔ f = α.hom := comp_hom_eq_id α.symm theorem hom_eq_inv (α : X ≅ Y) (β : Y ≅ X) : α.hom = β.inv ↔ β.hom = α.inv := by rw [← symm_inv, inv_eq_inv α.symm β, eq_comm] rfl /-- The bijection `(Z ⟶ X) ≃ (Z ⟶ Y)` induced by `α : X ≅ Y`. -/ @[simps] def homToEquiv (α : X ≅ Y) {Z : C} : (Z ⟶ X) ≃ (Z ⟶ Y) where toFun f := f ≫ α.hom invFun g := g ≫ α.inv left_inv := by aesop_cat right_inv := by aesop_cat /-- The bijection `(X ⟶ Z) ≃ (Y ⟶ Z)` induced by `α : X ≅ Y`. -/ @[simps] def homFromEquiv (α : X ≅ Y) {Z : C} : (X ⟶ Z) ≃ (Y ⟶ Z) where toFun f := α.inv ≫ f invFun g := α.hom ≫ g left_inv := by aesop_cat right_inv := by aesop_cat end Iso /-- `IsIso` typeclass expressing that a morphism is invertible. -/ class IsIso (f : X ⟶ Y) : Prop where /-- The existence of an inverse morphism. -/ out : ∃ inv : Y ⟶ X, f ≫ inv = 𝟙 X ∧ inv ≫ f = 𝟙 Y /-- The inverse of a morphism `f` when we have `[IsIso f]`. -/ noncomputable def inv (f : X ⟶ Y) [I : IsIso f] : Y ⟶ X := Classical.choose I.1 namespace IsIso @[simp] theorem hom_inv_id (f : X ⟶ Y) [I : IsIso f] : f ≫ inv f = 𝟙 X := (Classical.choose_spec I.1).left @[simp] theorem inv_hom_id (f : X ⟶ Y) [I : IsIso f] : inv f ≫ f = 𝟙 Y := (Classical.choose_spec I.1).right -- FIXME putting @[reassoc] on the `hom_inv_id` above somehow unfolds `inv` -- This happens even if we make `inv` irreducible! -- I don't understand how this is happening: it is likely a bug. -- attribute [reassoc] hom_inv_id inv_hom_id -- #print hom_inv_id_assoc -- theorem CategoryTheory.IsIso.hom_inv_id_assoc {X Y : C} (f : X ⟶ Y) [I : IsIso f] -- {Z : C} (h : X ⟶ Z), -- f ≫ Classical.choose (_ : Exists fun inv ↦ f ≫ inv = 𝟙 X ∧ inv ≫ f = 𝟙 Y) ≫ h = h := ... @[simp] theorem hom_inv_id_assoc (f : X ⟶ Y) [I : IsIso f] {Z} (g : X ⟶ Z) : f ≫ inv f ≫ g = g := by simp [← Category.assoc] @[simp] theorem inv_hom_id_assoc (f : X ⟶ Y) [I : IsIso f] {Z} (g : Y ⟶ Z) : inv f ≫ f ≫ g = g := by simp [← Category.assoc] end IsIso lemma Iso.isIso_hom (e : X ≅ Y) : IsIso e.hom := ⟨e.inv, by simp, by simp⟩ lemma Iso.isIso_inv (e : X ≅ Y) : IsIso e.inv := e.symm.isIso_hom attribute [instance] Iso.isIso_hom Iso.isIso_inv open IsIso /-- Reinterpret a morphism `f` with an `IsIso f` instance as an `Iso`. -/ noncomputable def asIso (f : X ⟶ Y) [IsIso f] : X ≅ Y := ⟨f, inv f, hom_inv_id f, inv_hom_id f⟩ -- Porting note: the `IsIso f` argument had been instance implicit, -- but we've changed it to implicit as a `rw` in `Mathlib.CategoryTheory.Closed.Functor` -- was failing to generate it by typeclass search. @[simp] theorem asIso_hom (f : X ⟶ Y) {_ : IsIso f} : (asIso f).hom = f := rfl -- Porting note: the `IsIso f` argument had been instance implicit, -- but we've changed it to implicit as a `rw` in `Mathlib.CategoryTheory.Closed.Functor` -- was failing to generate it by typeclass search. @[simp] theorem asIso_inv (f : X ⟶ Y) {_ : IsIso f} : (asIso f).inv = inv f := rfl namespace IsIso -- see Note [lower instance priority] instance (priority := 100) epi_of_iso (f : X ⟶ Y) [IsIso f] : Epi f where left_cancellation g h w := by rw [← IsIso.inv_hom_id_assoc f g, w, IsIso.inv_hom_id_assoc f h] -- see Note [lower instance priority] instance (priority := 100) mono_of_iso (f : X ⟶ Y) [IsIso f] : Mono f where right_cancellation g h w := by rw [← Category.comp_id g, ← Category.comp_id h, ← IsIso.hom_inv_id f, ← Category.assoc, w, ← Category.assoc] @[aesop apply safe (rule_sets := [CategoryTheory])] theorem inv_eq_of_hom_inv_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (hom_inv_id : f ≫ g = 𝟙 X) : inv f = g := by apply (cancel_epi f).mp simp [hom_inv_id] theorem inv_eq_of_inv_hom_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (inv_hom_id : g ≫ f = 𝟙 Y) : inv f = g := by apply (cancel_mono f).mp simp [inv_hom_id] @[aesop apply safe (rule_sets := [CategoryTheory])] theorem eq_inv_of_hom_inv_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (hom_inv_id : f ≫ g = 𝟙 X) : g = inv f := (inv_eq_of_hom_inv_id hom_inv_id).symm theorem eq_inv_of_inv_hom_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (inv_hom_id : g ≫ f = 𝟙 Y) : g = inv f := (inv_eq_of_inv_hom_id inv_hom_id).symm instance id (X : C) : IsIso (𝟙 X) := ⟨⟨𝟙 X, by simp⟩⟩ variable {f : X ⟶ Y} {h : Y ⟶ Z} instance inv_isIso [IsIso f] : IsIso (inv f) := (asIso f).isIso_inv /- The following instance has lower priority for the following reason: Suppose we are given `f : X ≅ Y` with `X Y : Type u`. Without the lower priority, typeclass inference cannot deduce `IsIso f.hom` because `f.hom` is defeq to `(fun x ↦ x) ≫ f.hom`, triggering a loop. -/ instance (priority := 900) comp_isIso [IsIso f] [IsIso h] : IsIso (f ≫ h) := (asIso f ≪≫ asIso h).isIso_hom /-- The composition of isomorphisms is an isomorphism. Here the arguments of type `IsIso` are explicit, to make this easier to use with the `refine` tactic, for instance. -/ lemma comp_isIso' (_ : IsIso f) (_ : IsIso h) : IsIso (f ≫ h) := inferInstance @[simp] theorem inv_id : inv (𝟙 X) = 𝟙 X := by apply inv_eq_of_hom_inv_id simp @[simp, reassoc] theorem inv_comp [IsIso f] [IsIso h] : inv (f ≫ h) = inv h ≫ inv f := by apply inv_eq_of_hom_inv_id simp @[simp] theorem inv_inv [IsIso f] : inv (inv f) = f := by apply inv_eq_of_hom_inv_id simp @[simp] theorem Iso.inv_inv (f : X ≅ Y) : inv f.inv = f.hom := by apply inv_eq_of_hom_inv_id simp @[simp] theorem Iso.inv_hom (f : X ≅ Y) : inv f.hom = f.inv := by apply inv_eq_of_hom_inv_id simp @[simp] theorem inv_comp_eq (α : X ⟶ Y) [IsIso α] {f : X ⟶ Z} {g : Y ⟶ Z} : inv α ≫ f = g ↔ f = α ≫ g := (asIso α).inv_comp_eq @[simp] theorem eq_inv_comp (α : X ⟶ Y) [IsIso α] {f : X ⟶ Z} {g : Y ⟶ Z} : g = inv α ≫ f ↔ α ≫ g = f := (asIso α).eq_inv_comp @[simp] theorem comp_inv_eq (α : X ⟶ Y) [IsIso α] {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ inv α = g ↔ f = g ≫ α := (asIso α).comp_inv_eq @[simp] theorem eq_comp_inv (α : X ⟶ Y) [IsIso α] {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ inv α ↔ g ≫ α = f := (asIso α).eq_comp_inv theorem of_isIso_comp_left {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso f] [IsIso (f ≫ g)] : IsIso g := by rw [← id_comp g, ← inv_hom_id f, assoc] infer_instance theorem of_isIso_comp_right {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso g] [IsIso (f ≫ g)] : IsIso f := by rw [← comp_id f, ← hom_inv_id g, ← assoc] infer_instance theorem of_isIso_fac_left {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [IsIso f] [hh : IsIso h] (w : f ≫ g = h) : IsIso g := by rw [← w] at hh haveI := hh exact of_isIso_comp_left f g theorem of_isIso_fac_right {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [IsIso g] [hh : IsIso h] (w : f ≫ g = h) : IsIso f := by rw [← w] at hh haveI := hh exact of_isIso_comp_right f g end IsIso open IsIso theorem eq_of_inv_eq_inv {f g : X ⟶ Y} [IsIso f] [IsIso g] (p : inv f = inv g) : f = g := by apply (cancel_epi (inv f)).1 rw [inv_hom_id, p, inv_hom_id] theorem IsIso.inv_eq_inv {f g : X ⟶ Y} [IsIso f] [IsIso g] : inv f = inv g ↔ f = g := Iso.inv_eq_inv (asIso f) (asIso g) theorem hom_comp_eq_id (g : X ⟶ Y) [IsIso g] {f : Y ⟶ X} : g ≫ f = 𝟙 X ↔ f = inv g := (asIso g).hom_comp_eq_id theorem comp_hom_eq_id (g : X ⟶ Y) [IsIso g] {f : Y ⟶ X} : f ≫ g = 𝟙 Y ↔ f = inv g := (asIso g).comp_hom_eq_id theorem inv_comp_eq_id (g : X ⟶ Y) [IsIso g] {f : X ⟶ Y} : inv g ≫ f = 𝟙 Y ↔ f = g := (asIso g).inv_comp_eq_id theorem comp_inv_eq_id (g : X ⟶ Y) [IsIso g] {f : X ⟶ Y} : f ≫ inv g = 𝟙 X ↔ f = g := (asIso g).comp_inv_eq_id theorem isIso_of_hom_comp_eq_id (g : X ⟶ Y) [IsIso g] {f : Y ⟶ X} (h : g ≫ f = 𝟙 X) : IsIso f := by rw [(hom_comp_eq_id _).mp h] infer_instance theorem isIso_of_comp_hom_eq_id (g : X ⟶ Y) [IsIso g] {f : Y ⟶ X} (h : f ≫ g = 𝟙 Y) : IsIso f := by rw [(comp_hom_eq_id _).mp h] infer_instance namespace Iso @[aesop apply safe (rule_sets := [CategoryTheory])] theorem inv_ext {f : X ≅ Y} {g : Y ⟶ X} (hom_inv_id : f.hom ≫ g = 𝟙 X) : f.inv = g := ((hom_comp_eq_id f).1 hom_inv_id).symm @[aesop apply safe (rule_sets := [CategoryTheory])] theorem inv_ext' {f : X ≅ Y} {g : Y ⟶ X} (hom_inv_id : f.hom ≫ g = 𝟙 X) : g = f.inv := (hom_comp_eq_id f).1 hom_inv_id /-! All these cancellation lemmas can be solved by `simp [cancel_mono]` (or `simp [cancel_epi]`), but with the current design `cancel_mono` is not a good `simp` lemma, because it generates a typeclass search. When we can see syntactically that a morphism is a `mono` or an `epi` because it came from an isomorphism, it's fine to do the cancellation via `simp`. In the longer term, it might be worth exploring making `mono` and `epi` structures, rather than typeclasses, with coercions back to `X ⟶ Y`. Presumably we could write `X ↪ Y` and `X ↠ Y`. -/ @[simp] theorem cancel_iso_hom_left {X Y Z : C} (f : X ≅ Y) (g g' : Y ⟶ Z) : f.hom ≫ g = f.hom ≫ g' ↔ g = g' := by simp only [cancel_epi] @[simp] theorem cancel_iso_inv_left {X Y Z : C} (f : Y ≅ X) (g g' : Y ⟶ Z) : f.inv ≫ g = f.inv ≫ g' ↔ g = g' := by simp only [cancel_epi] @[simp] theorem cancel_iso_hom_right {X Y Z : C} (f f' : X ⟶ Y) (g : Y ≅ Z) : f ≫ g.hom = f' ≫ g.hom ↔ f = f' := by simp only [cancel_mono] @[simp] theorem cancel_iso_inv_right {X Y Z : C} (f f' : X ⟶ Y) (g : Z ≅ Y) : f ≫ g.inv = f' ≫ g.inv ↔ f = f' := by simp only [cancel_mono] /- Unfortunately cancelling an isomorphism from the right of a chain of compositions is awkward. We would need separate lemmas for each chain length (worse: for each pair of chain lengths). We provide two more lemmas, for case of three morphisms, because this actually comes up in practice, but then stop. -/ @[simp] theorem cancel_iso_hom_right_assoc {W X X' Y Z : C} (f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X') (g' : X' ⟶ Y) (h : Y ≅ Z) : f ≫ g ≫ h.hom = f' ≫ g' ≫ h.hom ↔ f ≫ g = f' ≫ g' := by simp only [← Category.assoc, cancel_mono] @[simp] theorem cancel_iso_inv_right_assoc {W X X' Y Z : C} (f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X') (g' : X' ⟶ Y) (h : Z ≅ Y) : f ≫ g ≫ h.inv = f' ≫ g' ≫ h.inv ↔ f ≫ g = f' ≫ g' := by simp only [← Category.assoc, cancel_mono] section variable {D : Type*} [Category D] {X Y : C} (e : X ≅ Y) @[reassoc (attr := simp)] lemma map_hom_inv_id (F : C ⥤ D) : F.map e.hom ≫ F.map e.inv = 𝟙 _ := by rw [← F.map_comp, e.hom_inv_id, F.map_id] @[reassoc (attr := simp)] lemma map_inv_hom_id (F : C ⥤ D) : F.map e.inv ≫ F.map e.hom = 𝟙 _ := by rw [← F.map_comp, e.inv_hom_id, F.map_id] end end Iso
namespace Functor universe u₁ v₁ u₂ v₂
Mathlib/CategoryTheory/Iso.lean
520
522
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Ken Lee, Chris Hughes -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Data.Fintype.Basic import Mathlib.Data.Int.GCD import Mathlib.RingTheory.Coprime.Basic /-! # Additional lemmas about elements of a ring satisfying `IsCoprime` and elements of a monoid satisfying `IsRelPrime` These lemmas are in a separate file to the definition of `IsCoprime` or `IsRelPrime` as they require more imports. Notably, this includes lemmas about `Finset.prod` as this requires importing BigOperators, and lemmas about `Pow` since these are easiest to prove via `Finset.prod`. -/ universe u v open scoped Function -- required for scoped `on` notation section IsCoprime variable {R : Type u} {I : Type v} [CommSemiring R] {x y z : R} {s : I → R} {t : Finset I} section theorem Int.isCoprime_iff_gcd_eq_one {m n : ℤ} : IsCoprime m n ↔ Int.gcd m n = 1 := by constructor · rintro ⟨a, b, h⟩ refine Nat.dvd_one.mp (Int.gcd_dvd_iff.mpr ⟨a, b, ?_⟩) rwa [mul_comm m, mul_comm n, eq_comm] · rw [← Int.ofNat_inj, IsCoprime, Int.gcd_eq_gcd_ab, mul_comm m, mul_comm n, Nat.cast_one] intro h exact ⟨_, _, h⟩ theorem Nat.isCoprime_iff_coprime {m n : ℕ} : IsCoprime (m : ℤ) n ↔ Nat.Coprime m n := by rw [Int.isCoprime_iff_gcd_eq_one, Int.gcd_natCast_natCast] alias ⟨IsCoprime.nat_coprime, Nat.Coprime.isCoprime⟩ := Nat.isCoprime_iff_coprime theorem Nat.Coprime.cast {R : Type*} [CommRing R] {a b : ℕ} (h : Nat.Coprime a b) : IsCoprime (a : R) (b : R) := by rw [← isCoprime_iff_coprime] at h rw [← Int.cast_natCast a, ← Int.cast_natCast b] exact IsCoprime.intCast h theorem ne_zero_or_ne_zero_of_nat_coprime {A : Type u} [CommRing A] [Nontrivial A] {a b : ℕ} (h : Nat.Coprime a b) : (a : A) ≠ 0 ∨ (b : A) ≠ 0 := IsCoprime.ne_zero_or_ne_zero (R := A) <| by
simpa only [map_natCast] using IsCoprime.map (Nat.Coprime.isCoprime h) (Int.castRingHom A) theorem IsCoprime.prod_left : (∀ i ∈ t, IsCoprime (s i) x) → IsCoprime (∏ i ∈ t, s i) x := by classical
Mathlib/RingTheory/Coprime/Lemmas.lean
56
59
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kevin Kappelmann -/ import Mathlib.Algebra.Order.Floor.Defs import Mathlib.Algebra.Order.Floor.Ring import Mathlib.Algebra.Order.Floor.Semiring deprecated_module (since := "2025-04-13")
Mathlib/Algebra/Order/Floor.lean
857
857
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Yaël Dillies -/ import Mathlib.Order.Cover import Mathlib.Order.Interval.Finset.Defs /-! # Intervals as finsets This file provides basic results about all the `Finset.Ixx`, which are defined in `Order.Interval.Finset.Defs`. In addition, it shows that in a locally finite order `≤` and `<` are the transitive closures of, respectively, `⩿` and `⋖`, which then leads to a characterization of monotone and strictly functions whose domain is a locally finite order. In particular, this file proves: * `le_iff_transGen_wcovBy`: `≤` is the transitive closure of `⩿` * `lt_iff_transGen_covBy`: `<` is the transitive closure of `⋖` * `monotone_iff_forall_wcovBy`: Characterization of monotone functions * `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions ## TODO This file was originally only about `Finset.Ico a b` where `a b : ℕ`. No care has yet been taken to generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general, what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure. Complete the API. See https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235 for some ideas. -/ assert_not_exists MonoidWithZero Finset.sum open Function OrderDual open FinsetInterval variable {ι α : Type*} {a a₁ a₂ b b₁ b₂ c x : α} namespace Finset section Preorder variable [Preorder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := by rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Icc_of_le⟩ := nonempty_Icc @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ico_of_lt⟩ := nonempty_Ico @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioc_of_lt⟩ := nonempty_Ioc -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo] @[simp] theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff] @[simp] theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff] @[simp] theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff] -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff] alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and, le_rfl] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and, le_refl] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true, le_rfl] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true, le_rfl] theorem left_not_mem_Ioc : a ∉ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1 theorem left_not_mem_Ioo : a ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1 theorem right_not_mem_Ico : b ∉ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2 theorem right_not_mem_Ioo : b ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2 @[gcongr] theorem Icc_subset_Icc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := by simpa [← coe_subset] using Set.Icc_subset_Icc ha hb @[gcongr] theorem Ico_subset_Ico (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := by simpa [← coe_subset] using Set.Ico_subset_Ico ha hb @[gcongr] theorem Ioc_subset_Ioc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := by simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb @[gcongr] theorem Ioo_subset_Ioo (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := by simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h theorem Ico_subset_Ioo_left (h : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := by rw [← coe_subset, coe_Ico, coe_Ioo] exact Set.Ico_subset_Ioo_left h theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := by rw [← coe_subset, coe_Ioc, coe_Ioo] exact Set.Ioc_subset_Ioo_right h theorem Icc_subset_Ico_right (h : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := by rw [← coe_subset, coe_Icc, coe_Ico] exact Set.Icc_subset_Ico_right h theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := by rw [← coe_subset, coe_Ioo, coe_Ico] exact Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := by rw [← coe_subset, coe_Ioo, coe_Ioc] exact Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := by rw [← coe_subset, coe_Ico, coe_Icc] exact Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := by rw [← coe_subset, coe_Ioc, coe_Icc] exact Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Ioo_subset_Ico_self.trans Ico_subset_Icc_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [← coe_subset, coe_Icc, coe_Icc, Set.Icc_subset_Icc_iff h₁] theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ioo, Set.Icc_subset_Ioo_iff h₁] theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ico, Set.Icc_subset_Ico_iff h₁] theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := (Icc_subset_Ico_iff h₁.dual).trans and_comm --TODO: `Ico_subset_Ioo_iff`, `Ioc_subset_Ioo_iff` theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_left hI ha hb theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_right hI ha hb @[simp] theorem Ioc_disjoint_Ioc_of_le {d : α} (hbc : b ≤ c) : Disjoint (Ioc a b) (Ioc c d) := disjoint_left.2 fun _ h1 h2 ↦ not_and_of_not_left _ ((mem_Ioc.1 h1).2.trans hbc).not_lt (mem_Ioc.1 h2) variable (a) theorem Ico_self : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ theorem Ioc_self : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ theorem Ioo_self : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ variable {a} /-- A set with upper and lower bounds in a locally finite order is a fintype -/ def _root_.Set.fintypeOfMemBounds {s : Set α} [DecidablePred (· ∈ s)] (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) : Fintype s := Set.fintypeSubset (Set.Icc a b) fun _ hx => ⟨ha hx, hb hx⟩ section Filter theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) : {x ∈ Ico a b | x < c} = ∅ := filter_false_of_mem fun _ hx => (hca.trans (mem_Ico.1 hx).1).not_lt theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) : {x ∈ Ico a b | x < c} = Ico a b := filter_true_of_mem fun _ hx => (mem_Ico.1 hx).2.trans_le hbc theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) : {x ∈ Ico a b | x < c} = Ico a c := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_right_comm] exact and_iff_left_of_imp fun h => h.2.trans_le hcb theorem Ico_filter_le_of_le_left {a b c : α} [DecidablePred (c ≤ ·)] (hca : c ≤ a) : {x ∈ Ico a b | c ≤ x} = Ico a b := filter_true_of_mem fun _ hx => hca.trans (mem_Ico.1 hx).1 theorem Ico_filter_le_of_right_le {a b : α} [DecidablePred (b ≤ ·)] : {x ∈ Ico a b | b ≤ x} = ∅ := filter_false_of_mem fun _ hx => (mem_Ico.1 hx).2.not_le theorem Ico_filter_le_of_left_le {a b c : α} [DecidablePred (c ≤ ·)] (hac : a ≤ c) : {x ∈ Ico a b | c ≤ x} = Ico c b := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_comm, and_left_comm] exact and_iff_right_of_imp fun h => hac.trans h.1 theorem Icc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : {x ∈ Icc a b | x < c} = Icc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Icc.1 hx).2 h theorem Ioc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : {x ∈ Ioc a b | x < c} = Ioc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Ioc.1 hx).2 h theorem Iic_filter_lt_of_lt_right {α} [Preorder α] [LocallyFiniteOrderBot α] {a c : α} [DecidablePred (· < c)] (h : a < c) : {x ∈ Iic a | x < c} = Iic a := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Iic.1 hx) h variable (a b) [Fintype α] theorem filter_lt_lt_eq_Ioo [DecidablePred fun j => a < j ∧ j < b] : ({j | a < j ∧ j < b} : Finset _) = Ioo a b := by ext; simp theorem filter_lt_le_eq_Ioc [DecidablePred fun j => a < j ∧ j ≤ b] : ({j | a < j ∧ j ≤ b} : Finset _) = Ioc a b := by ext; simp theorem filter_le_lt_eq_Ico [DecidablePred fun j => a ≤ j ∧ j < b] : ({j | a ≤ j ∧ j < b} : Finset _) = Ico a b := by ext; simp theorem filter_le_le_eq_Icc [DecidablePred fun j => a ≤ j ∧ j ≤ b] : ({j | a ≤ j ∧ j ≤ b} : Finset _) = Icc a b := by ext; simp end Filter end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] @[simp] theorem Ioi_eq_empty : Ioi a = ∅ ↔ IsMax a := by rw [← coe_eq_empty, coe_Ioi, Set.Ioi_eq_empty_iff] @[simp] alias ⟨_, _root_.IsMax.finsetIoi_eq⟩ := Ioi_eq_empty @[simp] lemma Ioi_nonempty : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [nonempty_iff_ne_empty] theorem Ioi_top [OrderTop α] : Ioi (⊤ : α) = ∅ := Ioi_eq_empty.mpr isMax_top @[simp] theorem Ici_bot [OrderBot α] [Fintype α] : Ici (⊥ : α) = univ := by ext a; simp only [mem_Ici, bot_le, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ici : (Ici a).Nonempty := ⟨a, mem_Ici.2 le_rfl⟩ lemma nonempty_Ioi : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioi_of_not_isMax⟩ := nonempty_Ioi @[simp] theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_subset_Ici⟩ := Ici_subset_Ici @[simp] theorem Ici_ssubset_Ici : Ici a ⊂ Ici b ↔ b < a := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_ssubset_Ici⟩ := Ici_ssubset_Ici @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioi_subset_Ioi h @[gcongr] theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b ⊂ Ioi a := by simpa [← coe_ssubset] using Set.Ioi_ssubset_Ioi h variable [LocallyFiniteOrder α] theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := by simpa [← coe_subset] using Set.Icc_subset_Ici_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := by simpa [← coe_subset] using Set.Ico_subset_Ici_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioo_subset_Ioi_self theorem Ioc_subset_Ici_self : Ioc a b ⊆ Ici a := Ioc_subset_Icc_self.trans Icc_subset_Ici_self theorem Ioo_subset_Ici_self : Ioo a b ⊆ Ici a := Ioo_subset_Ico_self.trans Ico_subset_Ici_self end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] @[simp] theorem Iio_eq_empty : Iio a = ∅ ↔ IsMin a := Ioi_eq_empty (α := αᵒᵈ) @[simp] alias ⟨_, _root_.IsMin.finsetIio_eq⟩ := Iio_eq_empty @[simp] lemma Iio_nonempty : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [nonempty_iff_ne_empty] theorem Iio_bot [OrderBot α] : Iio (⊥ : α) = ∅ := Iio_eq_empty.mpr isMin_bot
@[simp]
Mathlib/Order/Interval/Finset/Basic.lean
404
405
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yaël Dillies -/ import Mathlib.Algebra.Module.BigOperators import Mathlib.GroupTheory.Perm.Basic import Mathlib.GroupTheory.Perm.Finite import Mathlib.GroupTheory.Perm.List import Mathlib.GroupTheory.Perm.Sign /-! # Cycles of a permutation This file starts the theory of cycles in permutations. ## Main definitions In the following, `f : Equiv.Perm β`. * `Equiv.Perm.SameCycle`: `f.SameCycle x y` when `x` and `y` are in the same cycle of `f`. * `Equiv.Perm.IsCycle`: `f` is a cycle if any two nonfixed points of `f` are related by repeated applications of `f`, and `f` is not the identity. * `Equiv.Perm.IsCycleOn`: `f` is a cycle on a set `s` when any two points of `s` are related by repeated applications of `f`. ## Notes `Equiv.Perm.IsCycle` and `Equiv.Perm.IsCycleOn` are different in three ways: * `IsCycle` is about the entire type while `IsCycleOn` is restricted to a set. * `IsCycle` forbids the identity while `IsCycleOn` allows it (if `s` is a subsingleton). * `IsCycleOn` forbids fixed points on `s` (if `s` is nontrivial), while `IsCycle` allows them. -/ open Equiv Function Finset variable {ι α β : Type*} namespace Equiv.Perm /-! ### `SameCycle` -/ section SameCycle variable {f g : Perm α} {p : α → Prop} {x y z : α} /-- The equivalence relation indicating that two points are in the same cycle of a permutation. -/ def SameCycle (f : Perm α) (x y : α) : Prop := ∃ i : ℤ, (f ^ i) x = y @[refl] theorem SameCycle.refl (f : Perm α) (x : α) : SameCycle f x x := ⟨0, rfl⟩ theorem SameCycle.rfl : SameCycle f x x := SameCycle.refl _ _ protected theorem _root_.Eq.sameCycle (h : x = y) (f : Perm α) : f.SameCycle x y := by rw [h] @[symm] theorem SameCycle.symm : SameCycle f x y → SameCycle f y x := fun ⟨i, hi⟩ => ⟨-i, by rw [zpow_neg, ← hi, inv_apply_self]⟩ theorem sameCycle_comm : SameCycle f x y ↔ SameCycle f y x := ⟨SameCycle.symm, SameCycle.symm⟩ @[trans] theorem SameCycle.trans : SameCycle f x y → SameCycle f y z → SameCycle f x z := fun ⟨i, hi⟩ ⟨j, hj⟩ => ⟨j + i, by rw [zpow_add, mul_apply, hi, hj]⟩ variable (f) in theorem SameCycle.equivalence : Equivalence (SameCycle f) := ⟨SameCycle.refl f, SameCycle.symm, SameCycle.trans⟩ /-- The setoid defined by the `SameCycle` relation. -/ def SameCycle.setoid (f : Perm α) : Setoid α where r := f.SameCycle iseqv := SameCycle.equivalence f @[simp] theorem sameCycle_one : SameCycle 1 x y ↔ x = y := by simp [SameCycle] @[simp] theorem sameCycle_inv : SameCycle f⁻¹ x y ↔ SameCycle f x y := (Equiv.neg _).exists_congr_left.trans <| by simp [SameCycle] alias ⟨SameCycle.of_inv, SameCycle.inv⟩ := sameCycle_inv @[simp] theorem sameCycle_conj : SameCycle (g * f * g⁻¹) x y ↔ SameCycle f (g⁻¹ x) (g⁻¹ y) := exists_congr fun i => by simp [conj_zpow, eq_inv_iff_eq] theorem SameCycle.conj : SameCycle f x y → SameCycle (g * f * g⁻¹) (g x) (g y) := by simp [sameCycle_conj] theorem SameCycle.apply_eq_self_iff : SameCycle f x y → (f x = x ↔ f y = y) := fun ⟨i, hi⟩ => by rw [← hi, ← mul_apply, ← zpow_one_add, add_comm, zpow_add_one, mul_apply, (f ^ i).injective.eq_iff] theorem SameCycle.eq_of_left (h : SameCycle f x y) (hx : IsFixedPt f x) : x = y := let ⟨_, hn⟩ := h (hx.perm_zpow _).eq.symm.trans hn theorem SameCycle.eq_of_right (h : SameCycle f x y) (hy : IsFixedPt f y) : x = y := h.eq_of_left <| h.apply_eq_self_iff.2 hy @[simp] theorem sameCycle_apply_left : SameCycle f (f x) y ↔ SameCycle f x y := (Equiv.addRight 1).exists_congr_left.trans <| by simp [zpow_sub, SameCycle, Int.add_neg_one, Function.comp] @[simp] theorem sameCycle_apply_right : SameCycle f x (f y) ↔ SameCycle f x y := by rw [sameCycle_comm, sameCycle_apply_left, sameCycle_comm] @[simp] theorem sameCycle_inv_apply_left : SameCycle f (f⁻¹ x) y ↔ SameCycle f x y := by rw [← sameCycle_apply_left, apply_inv_self] @[simp] theorem sameCycle_inv_apply_right : SameCycle f x (f⁻¹ y) ↔ SameCycle f x y := by rw [← sameCycle_apply_right, apply_inv_self] @[simp] theorem sameCycle_zpow_left {n : ℤ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := (Equiv.addRight (n : ℤ)).exists_congr_left.trans <| by simp [SameCycle, zpow_add] @[simp] theorem sameCycle_zpow_right {n : ℤ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by rw [sameCycle_comm, sameCycle_zpow_left, sameCycle_comm] @[simp] theorem sameCycle_pow_left {n : ℕ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := by rw [← zpow_natCast, sameCycle_zpow_left] @[simp] theorem sameCycle_pow_right {n : ℕ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by rw [← zpow_natCast, sameCycle_zpow_right] alias ⟨SameCycle.of_apply_left, SameCycle.apply_left⟩ := sameCycle_apply_left alias ⟨SameCycle.of_apply_right, SameCycle.apply_right⟩ := sameCycle_apply_right alias ⟨SameCycle.of_inv_apply_left, SameCycle.inv_apply_left⟩ := sameCycle_inv_apply_left alias ⟨SameCycle.of_inv_apply_right, SameCycle.inv_apply_right⟩ := sameCycle_inv_apply_right alias ⟨SameCycle.of_pow_left, SameCycle.pow_left⟩ := sameCycle_pow_left alias ⟨SameCycle.of_pow_right, SameCycle.pow_right⟩ := sameCycle_pow_right alias ⟨SameCycle.of_zpow_left, SameCycle.zpow_left⟩ := sameCycle_zpow_left alias ⟨SameCycle.of_zpow_right, SameCycle.zpow_right⟩ := sameCycle_zpow_right theorem SameCycle.of_pow {n : ℕ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ => ⟨n * m, by simp [zpow_mul, h]⟩ theorem SameCycle.of_zpow {n : ℤ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ => ⟨n * m, by simp [zpow_mul, h]⟩ @[simp] theorem sameCycle_subtypePerm {h} {x y : { x // p x }} : (f.subtypePerm h).SameCycle x y ↔ f.SameCycle x y := exists_congr fun n => by simp [Subtype.ext_iff] alias ⟨_, SameCycle.subtypePerm⟩ := sameCycle_subtypePerm @[simp] theorem sameCycle_extendDomain {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} : SameCycle (g.extendDomain f) (f x) (f y) ↔ g.SameCycle x y := exists_congr fun n => by rw [← extendDomain_zpow, extendDomain_apply_image, Subtype.coe_inj, f.injective.eq_iff] alias ⟨_, SameCycle.extendDomain⟩ := sameCycle_extendDomain theorem SameCycle.exists_pow_eq' [Finite α] : SameCycle f x y → ∃ i < orderOf f, (f ^ i) x = y := by rintro ⟨k, rfl⟩ use (k % orderOf f).natAbs have h₀ := Int.natCast_pos.mpr (orderOf_pos f) have h₁ := Int.emod_nonneg k h₀.ne' rw [← zpow_natCast, Int.natAbs_of_nonneg h₁, zpow_mod_orderOf] refine ⟨?_, by rfl⟩ rw [← Int.ofNat_lt, Int.natAbs_of_nonneg h₁] exact Int.emod_lt_of_pos _ h₀ theorem SameCycle.exists_pow_eq'' [Finite α] (h : SameCycle f x y) : ∃ i : ℕ, 0 < i ∧ i ≤ orderOf f ∧ (f ^ i) x = y := by obtain ⟨_ | i, hi, rfl⟩ := h.exists_pow_eq' · refine ⟨orderOf f, orderOf_pos f, le_rfl, ?_⟩ rw [pow_orderOf_eq_one, pow_zero] · exact ⟨i.succ, i.zero_lt_succ, hi.le, by rfl⟩ theorem SameCycle.exists_fin_pow_eq [Finite α] (h : SameCycle f x y) : ∃ i : Fin (orderOf f), (f ^ (i : ℕ)) x = y := by obtain ⟨i, hi, hx⟩ := SameCycle.exists_pow_eq' h exact ⟨⟨i, hi⟩, hx⟩ theorem SameCycle.exists_nat_pow_eq [Finite α] (h : SameCycle f x y) : ∃ i : ℕ, (f ^ i) x = y := by obtain ⟨i, _, hi⟩ := h.exists_pow_eq' exact ⟨i, hi⟩ instance (f : Perm α) [DecidableRel (SameCycle f)] : DecidableRel (SameCycle f⁻¹) := fun x y => decidable_of_iff (f.SameCycle x y) (sameCycle_inv).symm instance (priority := 100) [DecidableEq α] : DecidableRel (SameCycle (1 : Perm α)) := fun x y => decidable_of_iff (x = y) sameCycle_one.symm end SameCycle /-! ### `IsCycle` -/ section IsCycle variable {f g : Perm α} {x y : α} /-- A cycle is a non identity permutation where any two nonfixed points of the permutation are related by repeated application of the permutation. -/ def IsCycle (f : Perm α) : Prop := ∃ x, f x ≠ x ∧ ∀ ⦃y⦄, f y ≠ y → SameCycle f x y theorem IsCycle.ne_one (h : IsCycle f) : f ≠ 1 := fun hf => by simp [hf, IsCycle] at h @[simp] theorem not_isCycle_one : ¬(1 : Perm α).IsCycle := fun H => H.ne_one rfl protected theorem IsCycle.sameCycle (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) : SameCycle f x y := let ⟨g, hg⟩ := hf let ⟨a, ha⟩ := hg.2 hx let ⟨b, hb⟩ := hg.2 hy ⟨b - a, by rw [← ha, ← mul_apply, ← zpow_add, sub_add_cancel, hb]⟩ theorem IsCycle.exists_zpow_eq : IsCycle f → f x ≠ x → f y ≠ y → ∃ i : ℤ, (f ^ i) x = y := IsCycle.sameCycle theorem IsCycle.inv (hf : IsCycle f) : IsCycle f⁻¹ := hf.imp fun _ ⟨hx, h⟩ => ⟨inv_eq_iff_eq.not.2 hx.symm, fun _ hy => (h <| inv_eq_iff_eq.not.2 hy.symm).inv⟩ @[simp] theorem isCycle_inv : IsCycle f⁻¹ ↔ IsCycle f := ⟨fun h => h.inv, IsCycle.inv⟩ theorem IsCycle.conj : IsCycle f → IsCycle (g * f * g⁻¹) := by rintro ⟨x, hx, h⟩ refine ⟨g x, by simp [coe_mul, inv_apply_self, hx], fun y hy => ?_⟩ rw [← apply_inv_self g y] exact (h <| eq_inv_iff_eq.not.2 hy).conj protected theorem IsCycle.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) : IsCycle g → IsCycle (g.extendDomain f) := by rintro ⟨a, ha, ha'⟩ refine ⟨f a, ?_, fun b hb => ?_⟩ · rw [extendDomain_apply_image] exact Subtype.coe_injective.ne (f.injective.ne ha) have h : b = f (f.symm ⟨b, of_not_not <| hb ∘ extendDomain_apply_not_subtype _ _⟩) := by rw [apply_symm_apply, Subtype.coe_mk] rw [h] at hb ⊢ simp only [extendDomain_apply_image, Subtype.coe_injective.ne_iff, f.injective.ne_iff] at hb exact (ha' hb).extendDomain theorem isCycle_iff_sameCycle (hx : f x ≠ x) : IsCycle f ↔ ∀ {y}, SameCycle f x y ↔ f y ≠ y := ⟨fun hf y => ⟨fun ⟨i, hi⟩ hy => hx <| by rw [← zpow_apply_eq_self_of_apply_eq_self hy i, (f ^ i).injective.eq_iff] at hi rw [hi, hy], hf.exists_zpow_eq hx⟩, fun h => ⟨x, hx, fun _ hy => h.2 hy⟩⟩ section Finite variable [Finite α] theorem IsCycle.exists_pow_eq (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) : ∃ i : ℕ, (f ^ i) x = y := by let ⟨n, hn⟩ := hf.exists_zpow_eq hx hy classical exact ⟨(n % orderOf f).toNat, by {have := n.emod_nonneg (Int.natCast_ne_zero.mpr (ne_of_gt (orderOf_pos f))) rwa [← zpow_natCast, Int.toNat_of_nonneg this, zpow_mod_orderOf]}⟩ end Finite
variable [DecidableEq α] theorem isCycle_swap (hxy : x ≠ y) : IsCycle (swap x y) := ⟨y, by rwa [swap_apply_right], fun a (ha : ite (a = x) y (ite (a = y) x a) ≠ a) => if hya : y = a then ⟨0, hya⟩
Mathlib/GroupTheory/Perm/Cycle/Basic.lean
291
296
/- 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.Group.Equiv.Basic import Mathlib.Data.ENat.Lattice import Mathlib.Data.Part import Mathlib.Tactic.NormNum /-! # Natural numbers with infinity The natural numbers and an extra `top` element `⊤`. This implementation uses `Part ℕ` as an implementation. Use `ℕ∞` instead unless you care about computability. ## Main definitions The following instances are defined: * `OrderedAddCommMonoid PartENat` * `CanonicallyOrderedAdd PartENat` * `CompleteLinearOrder PartENat` There is no additive analogue of `MonoidWithZero`; if there were then `PartENat` could be an `AddMonoidWithTop`. * `toWithTop` : the map from `PartENat` to `ℕ∞`, with theorems that it plays well with `+` and `≤`. * `withTopAddEquiv : PartENat ≃+ ℕ∞` * `withTopOrderIso : PartENat ≃o ℕ∞` ## Implementation details `PartENat` is defined to be `Part ℕ`. `+` and `≤` are defined on `PartENat`, but there is an issue with `*` because it's not clear what `0 * ⊤` should be. `mul` is hence left undefined. Similarly `⊤ - ⊤` is ambiguous so there is no `-` defined on `PartENat`. Before the `open scoped Classical` line, various proofs are made with decidability assumptions. This can cause issues -- see for example the non-simp lemma `toWithTopZero` proved by `rfl`, followed by `@[simp] lemma toWithTopZero'` whose proof uses `convert`. ## Tags PartENat, ℕ∞ -/ open Part hiding some /-- Type of natural numbers with infinity (`⊤`) -/ def PartENat : Type := Part ℕ namespace PartENat /-- The computable embedding `ℕ → PartENat`. This coincides with the coercion `coe : ℕ → PartENat`, see `PartENat.some_eq_natCast`. -/ @[coe] def some : ℕ → PartENat := Part.some instance : Zero PartENat := ⟨some 0⟩ instance : Inhabited PartENat := ⟨0⟩ instance : One PartENat := ⟨some 1⟩ instance : Add PartENat := ⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => get x h.1 + get y h.2⟩⟩ instance (n : ℕ) : Decidable (some n).Dom := isTrue trivial @[simp] theorem dom_some (x : ℕ) : (some x).Dom := trivial instance addCommMonoid : AddCommMonoid PartENat where add := (· + ·) zero := 0 add_comm _ _ := Part.ext' and_comm fun _ _ => add_comm _ _ zero_add _ := Part.ext' (iff_of_eq (true_and _)) fun _ _ => zero_add _ add_zero _ := Part.ext' (iff_of_eq (and_true _)) fun _ _ => add_zero _ add_assoc _ _ _ := Part.ext' and_assoc fun _ _ => add_assoc _ _ _ nsmul := nsmulRec instance : AddCommMonoidWithOne PartENat := { PartENat.addCommMonoid with one := 1 natCast := some natCast_zero := rfl natCast_succ := fun _ => Part.ext' (iff_of_eq (true_and _)).symm fun _ _ => rfl } theorem some_eq_natCast (n : ℕ) : some n = n := rfl instance : CharZero PartENat where cast_injective := Part.some_injective /-- Alias of `Nat.cast_inj` specialized to `PartENat` -/ theorem natCast_inj {x y : ℕ} : (x : PartENat) = y ↔ x = y := Nat.cast_inj @[simp] theorem dom_natCast (x : ℕ) : (x : PartENat).Dom := trivial @[simp] theorem dom_ofNat (x : ℕ) [x.AtLeastTwo] : (ofNat(x) : PartENat).Dom := trivial @[simp] theorem dom_zero : (0 : PartENat).Dom := trivial @[simp] theorem dom_one : (1 : PartENat).Dom := trivial instance : CanLift PartENat ℕ (↑) Dom := ⟨fun n hn => ⟨n.get hn, Part.some_get _⟩⟩ instance : LE PartENat := ⟨fun x y => ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy⟩ instance : Top PartENat := ⟨none⟩ instance : Bot PartENat := ⟨0⟩ instance : Max PartENat := ⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => x.get h.1 ⊔ y.get h.2⟩⟩ theorem le_def (x y : PartENat) : x ≤ y ↔ ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy := Iff.rfl @[elab_as_elim] protected theorem casesOn' {P : PartENat → Prop} : ∀ a : PartENat, P ⊤ → (∀ n : ℕ, P (some n)) → P a := Part.induction_on @[elab_as_elim] protected theorem casesOn {P : PartENat → Prop} : ∀ a : PartENat, P ⊤ → (∀ n : ℕ, P n) → P a := by exact PartENat.casesOn' -- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later theorem top_add (x : PartENat) : ⊤ + x = ⊤ := Part.ext' (iff_of_eq (false_and _)) fun h => h.left.elim -- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later theorem add_top (x : PartENat) : x + ⊤ = ⊤ := by rw [add_comm, top_add] @[simp] theorem natCast_get {x : PartENat} (h : x.Dom) : (x.get h : PartENat) = x := by exact Part.ext' (iff_of_true trivial h) fun _ _ => rfl @[simp, norm_cast] theorem get_natCast' (x : ℕ) (h : (x : PartENat).Dom) : get (x : PartENat) h = x := by rw [← natCast_inj, natCast_get] theorem get_natCast {x : ℕ} : get (x : PartENat) (dom_natCast x) = x := get_natCast' _ _ theorem coe_add_get {x : ℕ} {y : PartENat} (h : ((x : PartENat) + y).Dom) : get ((x : PartENat) + y) h = x + get y h.2 := by rfl @[simp] theorem get_add {x y : PartENat} (h : (x + y).Dom) : get (x + y) h = x.get h.1 + y.get h.2 := rfl @[simp] theorem get_zero (h : (0 : PartENat).Dom) : (0 : PartENat).get h = 0 := rfl @[simp] theorem get_one (h : (1 : PartENat).Dom) : (1 : PartENat).get h = 1 := rfl @[simp] theorem get_ofNat' (x : ℕ) [x.AtLeastTwo] (h : (ofNat(x) : PartENat).Dom) : Part.get (ofNat(x) : PartENat) h = ofNat(x) := get_natCast' x h nonrec theorem get_eq_iff_eq_some {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = some b := get_eq_iff_eq_some theorem get_eq_iff_eq_coe {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = b := by rw [get_eq_iff_eq_some] rfl theorem dom_of_le_of_dom {x y : PartENat} : x ≤ y → y.Dom → x.Dom := fun ⟨h, _⟩ => h theorem dom_of_le_some {x : PartENat} {y : ℕ} (h : x ≤ some y) : x.Dom := dom_of_le_of_dom h trivial theorem dom_of_le_natCast {x : PartENat} {y : ℕ} (h : x ≤ y) : x.Dom := by exact dom_of_le_some h instance decidableLe (x y : PartENat) [Decidable x.Dom] [Decidable y.Dom] : Decidable (x ≤ y) := if hx : x.Dom then decidable_of_decidable_of_iff (le_def x y).symm else if hy : y.Dom then isFalse fun h => hx <| dom_of_le_of_dom h hy else isTrue ⟨fun h => (hy h).elim, fun h => (hy h).elim⟩ instance partialOrder : PartialOrder PartENat where le := (· ≤ ·) le_refl _ := ⟨id, fun _ => le_rfl⟩ le_trans := fun _ _ _ ⟨hxy₁, hxy₂⟩ ⟨hyz₁, hyz₂⟩ => ⟨hxy₁ ∘ hyz₁, fun _ => le_trans (hxy₂ _) (hyz₂ _)⟩ lt_iff_le_not_le _ _ := Iff.rfl le_antisymm := fun _ _ ⟨hxy₁, hxy₂⟩ ⟨hyx₁, hyx₂⟩ => Part.ext' ⟨hyx₁, hxy₁⟩ fun _ _ => le_antisymm (hxy₂ _) (hyx₂ _) theorem lt_def (x y : PartENat) : x < y ↔ ∃ hx : x.Dom, ∀ hy : y.Dom, x.get hx < y.get hy := by rw [lt_iff_le_not_le, le_def, le_def, not_exists] constructor · rintro ⟨⟨hyx, H⟩, h⟩ by_cases hx : x.Dom · use hx intro hy specialize H hy specialize h fun _ => hy rw [not_forall] at h obtain ⟨hx', h⟩ := h rw [not_le] at h exact h · specialize h fun hx' => (hx hx').elim rw [not_forall] at h obtain ⟨hx', h⟩ := h exact (hx hx').elim · rintro ⟨hx, H⟩ exact ⟨⟨fun _ => hx, fun hy => (H hy).le⟩, fun hxy h => not_lt_of_le (h _) (H _)⟩ noncomputable instance isOrderedAddMonoid : IsOrderedAddMonoid PartENat := { add_le_add_left := fun a b ⟨h₁, h₂⟩ c => PartENat.casesOn c (by simp [top_add]) fun c => ⟨fun h => And.intro (dom_natCast _) (h₁ h.2), fun h => by simpa only [coe_add_get] using add_le_add_left (h₂ _) c⟩ } instance semilatticeSup : SemilatticeSup PartENat := { PartENat.partialOrder with sup := (· ⊔ ·) le_sup_left := fun _ _ => ⟨And.left, fun _ => le_sup_left⟩ le_sup_right := fun _ _ => ⟨And.right, fun _ => le_sup_right⟩ sup_le := fun _ _ _ ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ => ⟨fun hz => ⟨hx₁ hz, hy₁ hz⟩, fun _ => sup_le (hx₂ _) (hy₂ _)⟩ } instance orderBot : OrderBot PartENat where bot := ⊥ bot_le _ := ⟨fun _ => trivial, fun _ => Nat.zero_le _⟩ instance orderTop : OrderTop PartENat where top := ⊤ le_top _ := ⟨fun h => False.elim h, fun hy => False.elim hy⟩ instance : ZeroLEOneClass PartENat where zero_le_one := bot_le /-- Alias of `Nat.cast_le` specialized to `PartENat` -/ theorem coe_le_coe {x y : ℕ} : (x : PartENat) ≤ y ↔ x ≤ y := Nat.cast_le /-- Alias of `Nat.cast_lt` specialized to `PartENat` -/ theorem coe_lt_coe {x y : ℕ} : (x : PartENat) < y ↔ x < y := Nat.cast_lt @[simp] theorem get_le_get {x y : PartENat} {hx : x.Dom} {hy : y.Dom} : x.get hx ≤ y.get hy ↔ x ≤ y := by conv => lhs rw [← coe_le_coe, natCast_get, natCast_get] theorem le_coe_iff (x : PartENat) (n : ℕ) : x ≤ n ↔ ∃ h : x.Dom, x.get h ≤ n := by show (∃ h : True → x.Dom, _) ↔ ∃ h : x.Dom, x.get h ≤ n simp only [forall_prop_of_true, dom_natCast, get_natCast'] theorem lt_coe_iff (x : PartENat) (n : ℕ) : x < n ↔ ∃ h : x.Dom, x.get h < n := by simp only [lt_def, forall_prop_of_true, get_natCast', dom_natCast] theorem coe_le_iff (n : ℕ) (x : PartENat) : (n : PartENat) ≤ x ↔ ∀ h : x.Dom, n ≤ x.get h := by rw [← some_eq_natCast] simp only [le_def, exists_prop_of_true, dom_some, forall_true_iff] rfl theorem coe_lt_iff (n : ℕ) (x : PartENat) : (n : PartENat) < x ↔ ∀ h : x.Dom, n < x.get h := by rw [← some_eq_natCast] simp only [lt_def, exists_prop_of_true, dom_some, forall_true_iff] rfl nonrec theorem eq_zero_iff {x : PartENat} : x = 0 ↔ x ≤ 0 := eq_bot_iff theorem ne_zero_iff {x : PartENat} : x ≠ 0 ↔ ⊥ < x := bot_lt_iff_ne_bot.symm theorem dom_of_lt {x y : PartENat} : x < y → x.Dom := PartENat.casesOn x not_top_lt fun _ _ => dom_natCast _ theorem top_eq_none : (⊤ : PartENat) = Part.none := rfl @[simp] theorem natCast_lt_top (x : ℕ) : (x : PartENat) < ⊤ := Ne.lt_top fun h => absurd (congr_arg Dom h) <| by simp only [dom_natCast]; exact true_ne_false @[simp] theorem zero_lt_top : (0 : PartENat) < ⊤ := natCast_lt_top 0 @[simp] theorem one_lt_top : (1 : PartENat) < ⊤ := natCast_lt_top 1 @[simp] theorem ofNat_lt_top (x : ℕ) [x.AtLeastTwo] : (ofNat(x) : PartENat) < ⊤ := natCast_lt_top x @[simp] theorem natCast_ne_top (x : ℕ) : (x : PartENat) ≠ ⊤ := ne_of_lt (natCast_lt_top x) @[simp] theorem zero_ne_top : (0 : PartENat) ≠ ⊤ := natCast_ne_top 0 @[simp] theorem one_ne_top : (1 : PartENat) ≠ ⊤ := natCast_ne_top 1 @[simp] theorem ofNat_ne_top (x : ℕ) [x.AtLeastTwo] : (ofNat(x) : PartENat) ≠ ⊤ := natCast_ne_top x theorem not_isMax_natCast (x : ℕ) : ¬IsMax (x : PartENat) := not_isMax_of_lt (natCast_lt_top x) theorem ne_top_iff {x : PartENat} : x ≠ ⊤ ↔ ∃ n : ℕ, x = n := by simpa only [← some_eq_natCast] using Part.ne_none_iff theorem ne_top_iff_dom {x : PartENat} : x ≠ ⊤ ↔ x.Dom := by classical exact not_iff_comm.1 Part.eq_none_iff'.symm theorem not_dom_iff_eq_top {x : PartENat} : ¬x.Dom ↔ x = ⊤ := Iff.not_left ne_top_iff_dom.symm theorem ne_top_of_lt {x y : PartENat} (h : x < y) : x ≠ ⊤ := ne_of_lt <| lt_of_lt_of_le h le_top theorem eq_top_iff_forall_lt (x : PartENat) : x = ⊤ ↔ ∀ n : ℕ, (n : PartENat) < x := by constructor · rintro rfl n exact natCast_lt_top _ · contrapose! rw [ne_top_iff] rintro ⟨n, rfl⟩ exact ⟨n, irrefl _⟩ theorem eq_top_iff_forall_le (x : PartENat) : x = ⊤ ↔ ∀ n : ℕ, (n : PartENat) ≤ x := (eq_top_iff_forall_lt x).trans ⟨fun h n => (h n).le, fun h n => lt_of_lt_of_le (coe_lt_coe.mpr n.lt_succ_self) (h (n + 1))⟩ theorem pos_iff_one_le {x : PartENat} : 0 < x ↔ 1 ≤ x := PartENat.casesOn x (by simp only [le_top, natCast_lt_top, ← @Nat.cast_zero PartENat]) fun n => by rw [← Nat.cast_zero, ← Nat.cast_one, PartENat.coe_lt_coe, PartENat.coe_le_coe] rfl instance isTotal : IsTotal PartENat (· ≤ ·) where total x y := PartENat.casesOn (P := fun z => z ≤ y ∨ y ≤ z) x (Or.inr le_top) (PartENat.casesOn y (fun _ => Or.inl le_top) fun x y => (le_total x y).elim (Or.inr ∘ coe_le_coe.2) (Or.inl ∘ coe_le_coe.2)) noncomputable instance linearOrder : LinearOrder PartENat := { PartENat.partialOrder with le_total := IsTotal.total toDecidableLE := Classical.decRel _ max := (· ⊔ ·) max_def a b := congr_fun₂ (@sup_eq_maxDefault PartENat _ (_) _) _ _ } instance boundedOrder : BoundedOrder PartENat := { PartENat.orderTop, PartENat.orderBot with } noncomputable instance lattice : Lattice PartENat := { PartENat.semilatticeSup with inf := min inf_le_left := min_le_left inf_le_right := min_le_right le_inf := fun _ _ _ => le_min } instance : CanonicallyOrderedAdd PartENat := { le_self_add := fun a b => PartENat.casesOn b (le_top.trans_eq (add_top _).symm) fun _ => PartENat.casesOn a (top_add _).ge fun _ => (coe_le_coe.2 le_self_add).trans_eq (Nat.cast_add _ _) exists_add_of_le := fun {a b} => PartENat.casesOn b (fun _ => ⟨⊤, (add_top _).symm⟩) fun b => PartENat.casesOn a (fun h => ((natCast_lt_top _).not_le h).elim) fun a h => ⟨(b - a : ℕ), by rw [← Nat.cast_add, natCast_inj, add_comm, tsub_add_cancel_of_le (coe_le_coe.1 h)]⟩ } theorem eq_natCast_sub_of_add_eq_natCast {x y : PartENat} {n : ℕ} (h : x + y = n) : x = ↑(n - y.get (dom_of_le_natCast ((le_add_left le_rfl).trans_eq h))) := by lift x to ℕ using dom_of_le_natCast ((le_add_right le_rfl).trans_eq h) lift y to ℕ using dom_of_le_natCast ((le_add_left le_rfl).trans_eq h) rw [← Nat.cast_add, natCast_inj] at h rw [get_natCast, natCast_inj, eq_tsub_of_add_eq h] protected theorem add_lt_add_right {x y z : PartENat} (h : x < y) (hz : z ≠ ⊤) : x + z < y + z := by rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ rcases ne_top_iff.mp hz with ⟨k, rfl⟩ induction y using PartENat.casesOn · rw [top_add] exact_mod_cast natCast_lt_top _ norm_cast at h exact_mod_cast add_lt_add_right h _ protected theorem add_lt_add_iff_right {x y z : PartENat} (hz : z ≠ ⊤) : x + z < y + z ↔ x < y := ⟨lt_of_add_lt_add_right, fun h => PartENat.add_lt_add_right h hz⟩ protected theorem add_lt_add_iff_left {x y z : PartENat} (hz : z ≠ ⊤) : z + x < z + y ↔ x < y := by rw [add_comm z, add_comm z, PartENat.add_lt_add_iff_right hz] protected theorem lt_add_iff_pos_right {x y : PartENat} (hx : x ≠ ⊤) : x < x + y ↔ 0 < y := by conv_rhs => rw [← PartENat.add_lt_add_iff_left hx] rw [add_zero] theorem lt_add_one {x : PartENat} (hx : x ≠ ⊤) : x < x + 1 := by rw [PartENat.lt_add_iff_pos_right hx] norm_cast theorem le_of_lt_add_one {x y : PartENat} (h : x < y + 1) : x ≤ y := by induction y using PartENat.casesOn · apply le_top rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ exact_mod_cast Nat.le_of_lt_succ (by norm_cast at h) theorem add_one_le_of_lt {x y : PartENat} (h : x < y) : x + 1 ≤ y := by induction y using PartENat.casesOn · apply le_top rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ exact_mod_cast Nat.succ_le_of_lt (by norm_cast at h) theorem add_one_le_iff_lt {x y : PartENat} (hx : x ≠ ⊤) : x + 1 ≤ y ↔ x < y := by refine ⟨fun h => ?_, add_one_le_of_lt⟩ rcases ne_top_iff.mp hx with ⟨m, rfl⟩ induction y using PartENat.casesOn · apply natCast_lt_top exact_mod_cast Nat.lt_of_succ_le (by norm_cast at h) theorem coe_succ_le_iff {n : ℕ} {e : PartENat} : ↑n.succ ≤ e ↔ ↑n < e := by rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, add_one_le_iff_lt (natCast_ne_top n)] theorem lt_add_one_iff_lt {x y : PartENat} (hx : x ≠ ⊤) : x < y + 1 ↔ x ≤ y := by refine ⟨le_of_lt_add_one, fun h => ?_⟩ rcases ne_top_iff.mp hx with ⟨m, rfl⟩ induction y using PartENat.casesOn · rw [top_add] apply natCast_lt_top exact_mod_cast Nat.lt_succ_of_le (by norm_cast at h) lemma lt_coe_succ_iff_le {x : PartENat} {n : ℕ} (hx : x ≠ ⊤) : x < n.succ ↔ x ≤ n := by rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, lt_add_one_iff_lt hx] theorem add_eq_top_iff {a b : PartENat} : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := by refine PartENat.casesOn a ?_ ?_ <;> refine PartENat.casesOn b ?_ ?_ <;> simp [top_add, add_top] simp only [← Nat.cast_add, PartENat.natCast_ne_top, forall_const, not_false_eq_true] protected theorem add_right_cancel_iff {a b c : PartENat} (hc : c ≠ ⊤) : a + c = b + c ↔ a = b := by rcases ne_top_iff.1 hc with ⟨c, rfl⟩ refine PartENat.casesOn a ?_ ?_ <;> refine PartENat.casesOn b ?_ ?_ <;> simp [add_eq_top_iff, natCast_ne_top, @eq_comm _ (⊤ : PartENat), top_add] simp only [← Nat.cast_add, add_left_cancel_iff, PartENat.natCast_inj, add_comm, forall_const] protected theorem add_left_cancel_iff {a b c : PartENat} (ha : a ≠ ⊤) : a + b = a + c ↔ b = c := by rw [add_comm a, add_comm a, PartENat.add_right_cancel_iff ha] section WithTop /-- Computably converts a `PartENat` to a `ℕ∞`. -/ def toWithTop (x : PartENat) [Decidable x.Dom] : ℕ∞ := x.toOption theorem toWithTop_top : have : Decidable (⊤ : PartENat).Dom := Part.noneDecidable toWithTop ⊤ = ⊤ := rfl @[simp] theorem toWithTop_top' {h : Decidable (⊤ : PartENat).Dom} : toWithTop ⊤ = ⊤ := by convert toWithTop_top theorem toWithTop_zero : have : Decidable (0 : PartENat).Dom := someDecidable 0 toWithTop 0 = 0 := rfl @[simp] theorem toWithTop_zero' {h : Decidable (0 : PartENat).Dom} : toWithTop 0 = 0 := by convert toWithTop_zero theorem toWithTop_one : have : Decidable (1 : PartENat).Dom := someDecidable 1 toWithTop 1 = 1 := rfl @[simp] theorem toWithTop_one' {h : Decidable (1 : PartENat).Dom} : toWithTop 1 = 1 := by convert toWithTop_one theorem toWithTop_some (n : ℕ) : toWithTop (some n) = n := rfl theorem toWithTop_natCast (n : ℕ) {_ : Decidable (n : PartENat).Dom} : toWithTop n = n := by simp only [← toWithTop_some] congr @[simp] theorem toWithTop_natCast' (n : ℕ) {_ : Decidable (n : PartENat).Dom} : toWithTop (n : PartENat) = n := by rw [toWithTop_natCast n] @[simp] theorem toWithTop_ofNat (n : ℕ) [n.AtLeastTwo] {_ : Decidable (OfNat.ofNat n : PartENat).Dom} : toWithTop (ofNat(n) : PartENat) = OfNat.ofNat n := toWithTop_natCast' n @[simp] theorem toWithTop_le {x y : PartENat} [hx : Decidable x.Dom] [hy : Decidable y.Dom] : toWithTop x ≤ toWithTop y ↔ x ≤ y := by induction y using PartENat.casesOn generalizing hy · simp induction x using PartENat.casesOn generalizing hx · simp · simp @[simp] theorem toWithTop_lt {x y : PartENat} [Decidable x.Dom] [Decidable y.Dom] : toWithTop x < toWithTop y ↔ x < y := lt_iff_lt_of_le_iff_le toWithTop_le end WithTop /-- Coercion from `ℕ∞` to `PartENat`. -/ @[coe] def ofENat : ℕ∞ → PartENat := fun x => match x with | Option.none => none | Option.some n => some n instance : Coe ℕ∞ PartENat := ⟨ofENat⟩ example (n : ℕ) : ((n : ℕ∞) : PartENat) = ↑n := rfl @[simp, norm_cast] lemma ofENat_top : ofENat ⊤ = ⊤ := rfl @[simp, norm_cast] lemma ofENat_coe (n : ℕ) : ofENat n = n := rfl @[simp, norm_cast] theorem ofENat_zero : ofENat 0 = 0 := rfl @[simp, norm_cast] theorem ofENat_one : ofENat 1 = 1 := rfl @[simp, norm_cast] theorem ofENat_ofNat (n : Nat) [n.AtLeastTwo] : ofENat ofNat(n) = OfNat.ofNat n := rfl @[simp, norm_cast] theorem toWithTop_ofENat (n : ℕ∞) {_ : Decidable (n : PartENat).Dom} : toWithTop (↑n) = n := by cases n with | top => simp | coe n => simp @[simp, norm_cast] theorem ofENat_toWithTop (x : PartENat) {_ : Decidable (x : PartENat).Dom} : toWithTop x = x := by induction x using PartENat.casesOn <;> simp @[simp, norm_cast] theorem ofENat_le {x y : ℕ∞} : ofENat x ≤ ofENat y ↔ x ≤ y := by classical rw [← toWithTop_le, toWithTop_ofENat, toWithTop_ofENat] @[simp, norm_cast] theorem ofENat_lt {x y : ℕ∞} : ofENat x < ofENat y ↔ x < y := by classical rw [← toWithTop_lt, toWithTop_ofENat, toWithTop_ofENat] section WithTopEquiv open scoped Classical in @[simp] theorem toWithTop_add {x y : PartENat} : toWithTop (x + y) = toWithTop x + toWithTop y := by refine PartENat.casesOn y ?_ ?_ <;> refine PartENat.casesOn x ?_ ?_ <;> simp [add_top, top_add, ← Nat.cast_add, ← ENat.coe_add] open scoped Classical in /-- `Equiv` between `PartENat` and `ℕ∞` (for the order isomorphism see `withTopOrderIso`). -/ @[simps] noncomputable def withTopEquiv : PartENat ≃ ℕ∞ where toFun x := toWithTop x invFun x := ↑x left_inv x := by simp right_inv x := by simp theorem withTopEquiv_top : withTopEquiv ⊤ = ⊤ := by simp theorem withTopEquiv_natCast (n : Nat) : withTopEquiv n = n := by simp theorem withTopEquiv_zero : withTopEquiv 0 = 0 := by simp theorem withTopEquiv_one : withTopEquiv 1 = 1 := by simp theorem withTopEquiv_ofNat (n : Nat) [n.AtLeastTwo] : withTopEquiv ofNat(n) = OfNat.ofNat n := by simp theorem withTopEquiv_le {x y : PartENat} : withTopEquiv x ≤ withTopEquiv y ↔ x ≤ y := by simp theorem withTopEquiv_lt {x y : PartENat} : withTopEquiv x < withTopEquiv y ↔ x < y := by simp theorem withTopEquiv_symm_top : withTopEquiv.symm ⊤ = ⊤ := by simp theorem withTopEquiv_symm_coe (n : Nat) : withTopEquiv.symm n = n := by simp theorem withTopEquiv_symm_zero : withTopEquiv.symm 0 = 0 := by simp theorem withTopEquiv_symm_one : withTopEquiv.symm 1 = 1 := by simp theorem withTopEquiv_symm_ofNat (n : Nat) [n.AtLeastTwo] : withTopEquiv.symm ofNat(n) = OfNat.ofNat n := by simp theorem withTopEquiv_symm_le {x y : ℕ∞} : withTopEquiv.symm x ≤ withTopEquiv.symm y ↔ x ≤ y := by simp theorem withTopEquiv_symm_lt {x y : ℕ∞} : withTopEquiv.symm x < withTopEquiv.symm y ↔ x < y := by simp /-- `toWithTop` induces an order isomorphism between `PartENat` and `ℕ∞`. -/ noncomputable def withTopOrderIso : PartENat ≃o ℕ∞ := { withTopEquiv with map_rel_iff' := @fun _ _ => withTopEquiv_le } /-- `toWithTop` induces an additive monoid isomorphism between `PartENat` and `ℕ∞`. -/ noncomputable def withTopAddEquiv : PartENat ≃+ ℕ∞ := { withTopEquiv with map_add' := fun x y => by simp only [withTopEquiv] exact toWithTop_add } end WithTopEquiv theorem lt_wf : @WellFounded PartENat (· < ·) := by classical change WellFounded fun a b : PartENat => a < b simp_rw [← withTopEquiv_lt] exact InvImage.wf _ wellFounded_lt instance : WellFoundedLT PartENat := ⟨lt_wf⟩ instance wellFoundedRelation : WellFoundedRelation PartENat := ⟨(· < ·), lt_wf⟩ section Find variable (P : ℕ → Prop) [DecidablePred P] /-- The smallest `PartENat` satisfying a (decidable) predicate `P : ℕ → Prop` -/ def find : PartENat := ⟨∃ n, P n, Nat.find⟩ @[simp] theorem find_get (h : (find P).Dom) : (find P).get h = Nat.find h := rfl theorem find_dom (h : ∃ n, P n) : (find P).Dom := h theorem lt_find (n : ℕ) (h : ∀ m ≤ n, ¬P m) : (n : PartENat) < find P := by rw [coe_lt_iff] intro h₁ rw [find_get] have h₂ := @Nat.find_spec P _ h₁ revert h₂ contrapose! exact h _ theorem lt_find_iff (n : ℕ) : (n : PartENat) < find P ↔ ∀ m ≤ n, ¬P m := by refine ⟨?_, lt_find P n⟩ intro h m hm by_cases H : (find P).Dom · apply Nat.find_min H rw [coe_lt_iff] at h specialize h H exact lt_of_le_of_lt hm h · exact not_exists.mp H m theorem find_le (n : ℕ) (h : P n) : find P ≤ n := by rw [le_coe_iff] exact ⟨⟨_, h⟩, @Nat.find_min' P _ _ _ h⟩ theorem find_eq_top_iff : find P = ⊤ ↔ ∀ n, ¬P n := (eq_top_iff_forall_lt _).trans ⟨fun h n => (lt_find_iff P n).mp (h n) _ le_rfl, fun h n => lt_find P n fun _ _ => h _⟩ end Find noncomputable instance : LinearOrderedAddCommMonoidWithTop PartENat := { PartENat.linearOrder, PartENat.isOrderedAddMonoid, PartENat.orderTop with top_add' := top_add } noncomputable instance : CompleteLinearOrder PartENat := { lattice, withTopOrderIso.symm.toGaloisInsertion.liftCompleteLattice, linearOrder, LinearOrder.toBiheytingAlgebra with } end PartENat
Mathlib/Data/Nat/PartENat.lean
753
754
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Data.List.Lattice import Mathlib.Data.Bool.Basic import Mathlib.Order.Lattice /-! # Intervals in ℕ This file defines intervals of naturals. `List.Ico m n` is the list of integers greater than `m` and strictly less than `n`. ## TODO - Define `Ioo` and `Icc`, state basic lemmas about them. - Also do the versions for integers? - One could generalise even further, defining 'locally finite partial orders', for which `Set.Ico a b` is `[Finite]`, and 'locally finite total orders', for which there is a list model. - Once the above is done, get rid of `Int.range` (and maybe `List.range'`?). -/ open Nat namespace List /-- `Ico n m` is the list of natural numbers `n ≤ x < m`. (Ico stands for "interval, closed-open".) See also `Mathlib/Order/Interval/Basic.lean` for modelling intervals in general preorders, as well as sibling definitions alongside it such as `Set.Ico`, `Multiset.Ico` and `Finset.Ico` for sets, multisets and finite sets respectively. -/ def Ico (n m : ℕ) : List ℕ := range' n (m - n) namespace Ico theorem zero_bot (n : ℕ) : Ico 0 n = range n := by rw [Ico, Nat.sub_zero, range_eq_range'] @[simp] theorem length (n m : ℕ) : length (Ico n m) = m - n := by dsimp [Ico] simp [length_range'] theorem pairwise_lt (n m : ℕ) : Pairwise (· < ·) (Ico n m) := by dsimp [Ico] simp [pairwise_lt_range'] theorem nodup (n m : ℕ) : Nodup (Ico n m) := by dsimp [Ico] simp [nodup_range'] @[simp] theorem mem {n m l : ℕ} : l ∈ Ico n m ↔ n ≤ l ∧ l < m := by suffices n ≤ l ∧ l < n + (m - n) ↔ n ≤ l ∧ l < m by simp [Ico, this] omega theorem eq_nil_of_le {n m : ℕ} (h : m ≤ n) : Ico n m = [] := by simp [Ico, Nat.sub_eq_zero_iff_le.mpr h] theorem map_add (n m k : ℕ) : (Ico n m).map (k + ·) = Ico (n + k) (m + k) := by rw [Ico, Ico, map_add_range', Nat.add_sub_add_right m k, Nat.add_comm n k] theorem map_sub (n m k : ℕ) (h₁ : k ≤ n) : ((Ico n m).map fun x => x - k) = Ico (n - k) (m - k) := by rw [Ico, Ico, Nat.sub_sub_sub_cancel_right h₁, map_sub_range' h₁] @[simp] theorem self_empty {n : ℕ} : Ico n n = [] := eq_nil_of_le (le_refl n) @[simp] theorem eq_empty_iff {n m : ℕ} : Ico n m = [] ↔ m ≤ n := Iff.intro (fun h => Nat.sub_eq_zero_iff_le.mp <| by rw [← length, h, List.length]) eq_nil_of_le theorem append_consecutive {n m l : ℕ} (hnm : n ≤ m) (hml : m ≤ l) : Ico n m ++ Ico m l = Ico n l := by dsimp only [Ico] convert range'_append using 2 · rw [Nat.one_mul, Nat.add_sub_cancel' hnm] · omega @[simp] theorem inter_consecutive (n m l : ℕ) : Ico n m ∩ Ico m l = [] := by apply eq_nil_iff_forall_not_mem.2 intro a simp only [and_imp, not_and, not_lt, List.mem_inter_iff, List.Ico.mem] intro _ h₂ h₃ exfalso exact not_lt_of_ge h₃ h₂
@[simp] theorem bagInter_consecutive (n m l : Nat) : @List.bagInter ℕ instBEqOfDecidableEq (Ico n m) (Ico m l) = [] := (bagInter_nil_iff_inter_nil _ _).2 (by convert inter_consecutive n m l) @[simp]
Mathlib/Data/List/Intervals.lean
95
100
/- 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, Kim Morrison -/ import Mathlib.Algebra.BigOperators.Finsupp.Basic import Mathlib.Algebra.BigOperators.Group.Finset.Preimage import Mathlib.Algebra.Module.Defs import Mathlib.Data.Rat.BigOperators /-! # 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⟩ 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⟩ @[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 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⟩ 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 @[simp 1100] -- Higher priority shortcut instance for `mem_graph_iff`. theorem not_mem_graph_snd_zero (a : α) (f : α →₀ M) : (a, (0 : M)) ∉ f.graph := fun h => (mem_graph_iff.1 h).2.irrefl @[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, Function.comp_def, image_id'] 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) @[simp] theorem graph_inj {f g : α →₀ M} : f.graph = g.graph ↔ f = g := (graph_injective α M).eq_iff @[simp] theorem graph_zero : graph (0 : α →₀ M) = ∅ := by simp [graph] @[simp] theorem graph_eq_empty {f : α →₀ M} : f.graph = ∅ ↔ f = 0 := (graph_injective α M).eq_iff' graph_zero 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 @[simp] theorem mapRange.equiv_refl : mapRange.equiv (Equiv.refl M) rfl rfl = Equiv.refl (α →₀ M) := Equiv.ext mapRange_id 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₂) @[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 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 @[simp] theorem mapRange.zeroHom_id : mapRange.zeroHom (ZeroHom.id M) = ZeroHom.id (α →₀ M) := ZeroHom.ext mapRange_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]) 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 -- Porting note: need either `dsimp only` or to specify `hf`: -- see also: https://github.com/leanprover-community/mathlib4/issues/12129 map_add' := mapRange_add (hf := f.map_zero) f.map_add @[simp] theorem mapRange.addMonoidHom_id : mapRange.addMonoidHom (AddMonoidHom.id M) = AddMonoidHom.id (α →₀ M) := AddMonoidHom.ext mapRange_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]) @[simp] theorem mapRange.addMonoidHom_toZeroHom (f : M →+ N) : (mapRange.addMonoidHom f).toZeroHom = (mapRange.zeroHom f.toZeroHom : ZeroHom (α →₀ _) _) := ZeroHom.ext fun _ => rfl 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 _ 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)) _ _ /-- `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 } @[simp] theorem mapRange.addEquiv_refl : mapRange.addEquiv (AddEquiv.refl M) = AddEquiv.refl (α →₀ M) := AddEquiv.ext mapRange_id 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)) @[simp] theorem mapRange.addEquiv_symm (f : M ≃+ N) : ((mapRange.addEquiv f).symm : (α →₀ _) ≃+ _) = mapRange.addEquiv f.symm := AddEquiv.ext fun _ => rfl @[simp] theorem mapRange.addEquiv_toAddMonoidHom (f : M ≃+ N) : ((mapRange.addEquiv f : (α →₀ _) ≃+ _) : _ →+ _) = (mapRange.addMonoidHom f.toAddMonoidHom : (α →₀ _) →+ _) := AddMonoidHom.ext fun _ => rfl @[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 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 @[simp] theorem equivMapDomain_apply (f : α ≃ β) (l : α →₀ M) (b : β) : equivMapDomain f l b = l (f.symm b) := rfl theorem equivMapDomain_symm_apply (f : α ≃ β) (l : β →₀ M) (a : α) : equivMapDomain f.symm l a = l (f a) := rfl @[simp] theorem equivMapDomain_refl (l : α →₀ M) : equivMapDomain (Equiv.refl _) l = l := by ext x; rfl theorem equivMapDomain_refl' : equivMapDomain (Equiv.refl _) = @id (α →₀ M) := by ext x; rfl theorem equivMapDomain_trans (f : α ≃ β) (g : β ≃ γ) (l : α →₀ M) : equivMapDomain (f.trans g) l = equivMapDomain g (equivMapDomain f l) := by ext x; rfl theorem equivMapDomain_trans' (f : α ≃ β) (g : β ≃ γ) : @equivMapDomain _ _ M _ (f.trans g) = equivMapDomain g ∘ equivMapDomain f := by ext x; rfl @[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] @[simp] theorem equivMapDomain_zero {f : α ≃ β} : equivMapDomain f (0 : α →₀ M) = (0 : β →₀ M) := by ext; simp only [equivMapDomain_apply, coe_zero, Pi.zero_apply] @[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] @[simp] theorem equivCongrLeft_apply (f : α ≃ β) (l : α →₀ M) : equivCongrLeft f l = equivMapDomain f l := rfl @[simp] theorem equivCongrLeft_symm (f : α ≃ β) : (@equivCongrLeft _ _ M _ f).symm = equivCongrLeft f.symm := rfl end Finsupp end EquivCongrLeft section CastFinsupp variable [Zero M] (f : α →₀ M) namespace Nat @[simp, norm_cast] theorem cast_finsuppProd [CommSemiring R] (g : α → M → ℕ) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) := Nat.cast_prod _ _ @[deprecated (since := "2025-04-06")] alias cast_finsupp_prod := cast_finsuppProd @[simp, norm_cast] theorem cast_finsupp_sum [AddCommMonoidWithOne R] (g : α → M → ℕ) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) := Nat.cast_sum _ _ end Nat namespace Int @[simp, norm_cast] theorem cast_finsuppProd [CommRing R] (g : α → M → ℤ) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) := Int.cast_prod _ _ @[deprecated (since := "2025-04-06")] alias cast_finsupp_prod := cast_finsuppProd @[simp, norm_cast] theorem cast_finsupp_sum [AddCommGroupWithOne R] (g : α → M → ℤ) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) := Int.cast_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 _ _ @[simp, norm_cast] theorem cast_finsuppProd [Field R] [CharZero R] (g : α → M → ℚ) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) := cast_prod _ _ @[deprecated (since := "2025-04-06")] alias cast_finsupp_prod := cast_finsuppProd 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) 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] 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 _ @[simp] theorem mapDomain_id : mapDomain id v = v := sum_single _ 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 _ @[simp] theorem mapDomain_single {f : α → β} {a : α} {b : M} : mapDomain f (single a b) = single (f a) b := sum_single_index <| single_zero _ @[simp] theorem mapDomain_zero {f : α → β} : mapDomain f (0 : α →₀ M) = (0 : β →₀ M) := sum_zero_index 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] theorem mapDomain_add {f : α → β} : mapDomain f (v₁ + v₂) = mapDomain f v₁ + mapDomain f v₂ := sum_add_index' (fun _ => single_zero _) fun _ => single_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 _ _ /-- `Finsupp.mapDomain` is an `AddMonoidHom`. -/ @[simps] def mapDomain.addMonoidHom (f : α → β) : (α →₀ M) →+ β →₀ M where toFun := mapDomain f map_zero' := mapDomain_zero map_add' _ _ := mapDomain_add @[simp] theorem mapDomain.addMonoidHom_id : mapDomain.addMonoidHom id = AddMonoidHom.id (α →₀ M) := AddMonoidHom.ext fun _ => mapDomain_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 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) _ _ 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_finsuppSum (mapDomain.addMonoidHom f : (α →₀ M) →+ β →₀ M) _ _ 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 _ _ => support_single_subset) <| by rw [Finset.biUnion_singleton] 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) 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 _ 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 @[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 _) -- 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 _ _) 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
@[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]
Mathlib/Data/Finsupp/Basic.lean
537
541
/- 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, Yury Kudryashov -/ import Mathlib.Analysis.Normed.Module.Convex import Mathlib.Analysis.Normed.Module.Ray import Mathlib.Analysis.NormedSpace.Pointwise /-! # Strictly convex spaces This file defines strictly convex spaces. A normed space is strictly convex if all closed balls are strictly convex. This does **not** mean that the norm is strictly convex (in fact, it never is). ## Main definitions `StrictConvexSpace`: a typeclass saying that a given normed space over a normed linear ordered field (e.g., `ℝ` or `ℚ`) is strictly convex. The definition requires strict convexity of a closed ball of positive radius with center at the origin; strict convexity of any other closed ball follows from this assumption. ## Main results In a strictly convex space, we prove - `strictConvex_closedBall`: a closed ball is strictly convex. - `combo_mem_ball_of_ne`, `openSegment_subset_ball_of_ne`, `norm_combo_lt_of_ne`: a nontrivial convex combination of two points in a closed ball belong to the corresponding open ball; - `norm_add_lt_of_not_sameRay`, `sameRay_iff_norm_add`, `dist_add_dist_eq_iff`: the triangle inequality `dist x y + dist y z ≤ dist x z` is a strict inequality unless `y` belongs to the segment `[x -[ℝ] z]`. - `Isometry.affineIsometryOfStrictConvexSpace`: an isometry of `NormedAddTorsor`s for real normed spaces, strictly convex in the case of the codomain, is an affine isometry. We also provide several lemmas that can be used as alternative constructors for `StrictConvex ℝ E`: - `StrictConvexSpace.of_strictConvex_unitClosedBall`: if `closed_ball (0 : E) 1` is strictly convex, then `E` is a strictly convex space; - `StrictConvexSpace.of_norm_add`: if `‖x + y‖ = ‖x‖ + ‖y‖` implies `SameRay ℝ x y` for all nonzero `x y : E`, then `E` is a strictly convex space. ## Implementation notes While the definition is formulated for any normed linear ordered field, most of the lemmas are formulated only for the case `𝕜 = ℝ`. ## Tags convex, strictly convex -/ open Convex Pointwise Set Metric /-- A *strictly convex space* is a normed space where the closed balls are strictly convex. We only require balls of positive radius with center at the origin to be strictly convex in the definition, then prove that any closed ball is strictly convex in `strictConvex_closedBall` below. See also `StrictConvexSpace.of_strictConvex_unitClosedBall`. -/ @[mk_iff] class StrictConvexSpace (𝕜 E : Type*) [NormedField 𝕜] [PartialOrder 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] : Prop where strictConvex_closedBall : ∀ r : ℝ, 0 < r → StrictConvex 𝕜 (closedBall (0 : E) r) variable (𝕜 : Type*) {E : Type*} [NormedField 𝕜] [PartialOrder 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] /-- A closed ball in a strictly convex space is strictly convex. -/ theorem strictConvex_closedBall [StrictConvexSpace 𝕜 E] (x : E) (r : ℝ) : StrictConvex 𝕜 (closedBall x r) := by rcases le_or_lt r 0 with hr | hr · exact (subsingleton_closedBall x hr).strictConvex rw [← vadd_closedBall_zero] exact (StrictConvexSpace.strictConvex_closedBall r hr).vadd _ variable [NormedSpace ℝ E] /-- A real normed vector space is strictly convex provided that the unit ball is strictly convex. -/ theorem StrictConvexSpace.of_strictConvex_unitClosedBall [LinearMap.CompatibleSMul E E 𝕜 ℝ] (h : StrictConvex 𝕜 (closedBall (0 : E) 1)) : StrictConvexSpace 𝕜 E := ⟨fun r hr => by simpa only [smul_unitClosedBall_of_nonneg hr.le] using h.smul r⟩ @[deprecated (since := "2024-12-01")] alias StrictConvexSpace.of_strictConvex_closed_unit_ball := StrictConvexSpace.of_strictConvex_unitClosedBall /-- Strict convexity is equivalent to `‖a • x + b • y‖ < 1` for all `x` and `y` of norm at most `1` and all strictly positive `a` and `b` such that `a + b = 1`. This lemma shows that it suffices to check this for points of norm one and some `a`, `b` such that `a + b = 1`. -/ theorem StrictConvexSpace.of_norm_combo_lt_one (h : ∀ x y : E, ‖x‖ = 1 → ‖y‖ = 1 → x ≠ y → ∃ a b : ℝ, a + b = 1 ∧ ‖a • x + b • y‖ < 1) : StrictConvexSpace ℝ E := by refine StrictConvexSpace.of_strictConvex_unitClosedBall ℝ ((convex_closedBall _ _).strictConvex' fun x hx y hy hne => ?_) rw [interior_closedBall (0 : E) one_ne_zero, closedBall_diff_ball, mem_sphere_zero_iff_norm] at hx hy rcases h x y hx hy hne with ⟨a, b, hab, hlt⟩ use b rwa [AffineMap.lineMap_apply_module, interior_closedBall (0 : E) one_ne_zero, mem_ball_zero_iff, sub_eq_iff_eq_add.2 hab.symm] theorem StrictConvexSpace.of_norm_combo_ne_one (h : ∀ x y : E, ‖x‖ = 1 → ‖y‖ = 1 → x ≠ y → ∃ a b : ℝ, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ ‖a • x + b • y‖ ≠ 1) : StrictConvexSpace ℝ E := by refine StrictConvexSpace.of_strictConvex_unitClosedBall ℝ ((convex_closedBall _ _).strictConvex ?_) simp only [interior_closedBall _ one_ne_zero, closedBall_diff_ball, Set.Pairwise, frontier_closedBall _ one_ne_zero, mem_sphere_zero_iff_norm] intro x hx y hy hne rcases h x y hx hy hne with ⟨a, b, ha, hb, hab, hne'⟩ exact ⟨_, ⟨a, b, ha, hb, hab, rfl⟩, mt mem_sphere_zero_iff_norm.1 hne'⟩ theorem StrictConvexSpace.of_norm_add_ne_two (h : ∀ ⦃x y : E⦄, ‖x‖ = 1 → ‖y‖ = 1 → x ≠ y → ‖x + y‖ ≠ 2) : StrictConvexSpace ℝ E := by refine StrictConvexSpace.of_norm_combo_ne_one fun x y hx hy hne => ⟨1 / 2, 1 / 2, one_half_pos.le, one_half_pos.le, add_halves _, ?_⟩ rw [← smul_add, norm_smul, Real.norm_of_nonneg one_half_pos.le, one_div, ← div_eq_inv_mul, Ne, div_eq_one_iff_eq (two_ne_zero' ℝ)] exact h hx hy hne theorem StrictConvexSpace.of_pairwise_sphere_norm_ne_two (h : (sphere (0 : E) 1).Pairwise fun x y => ‖x + y‖ ≠ 2) : StrictConvexSpace ℝ E := StrictConvexSpace.of_norm_add_ne_two fun _ _ hx hy => h (mem_sphere_zero_iff_norm.2 hx) (mem_sphere_zero_iff_norm.2 hy) /-- If `‖x + y‖ = ‖x‖ + ‖y‖` implies that `x y : E` are in the same ray, then `E` is a strictly convex space. See also a more -/ theorem StrictConvexSpace.of_norm_add (h : ∀ x y : E, ‖x‖ = 1 → ‖y‖ = 1 → ‖x + y‖ = 2 → SameRay ℝ x y) : StrictConvexSpace ℝ E := by refine StrictConvexSpace.of_pairwise_sphere_norm_ne_two fun x hx y hy => mt fun h₂ => ?_ rw [mem_sphere_zero_iff_norm] at hx hy exact (sameRay_iff_of_norm_eq (hx.trans hy.symm)).1 (h x y hx hy h₂) variable [StrictConvexSpace ℝ E] {x y z : E} {a b r : ℝ} /-- If `x ≠ y` belong to the same closed ball, then a convex combination of `x` and `y` with positive coefficients belongs to the corresponding open ball. -/ theorem combo_mem_ball_of_ne (hx : x ∈ closedBall z r) (hy : y ∈ closedBall z r) (hne : x ≠ y) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : a • x + b • y ∈ ball z r := by rcases eq_or_ne r 0 with (rfl | hr) · rw [closedBall_zero, mem_singleton_iff] at hx hy exact (hne (hx.trans hy.symm)).elim · simp only [← interior_closedBall _ hr] at hx hy ⊢ exact strictConvex_closedBall ℝ z r hx hy hne ha hb hab /-- If `x ≠ y` belong to the same closed ball, then the open segment with endpoints `x` and `y` is included in the corresponding open ball. -/ theorem openSegment_subset_ball_of_ne (hx : x ∈ closedBall z r) (hy : y ∈ closedBall z r) (hne : x ≠ y) : openSegment ℝ x y ⊆ ball z r := (openSegment_subset_iff _).2 fun _ _ => combo_mem_ball_of_ne hx hy hne /-- If `x` and `y` are two distinct vectors of norm at most `r`, then a convex combination of `x` and `y` with positive coefficients has norm strictly less than `r`. -/ theorem norm_combo_lt_of_ne (hx : ‖x‖ ≤ r) (hy : ‖y‖ ≤ r) (hne : x ≠ y) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : ‖a • x + b • y‖ < r := by simp only [← mem_ball_zero_iff, ← mem_closedBall_zero_iff] at hx hy ⊢ exact combo_mem_ball_of_ne hx hy hne ha hb hab /-- In a strictly convex space, if `x` and `y` are not in the same ray, then `‖x + y‖ < ‖x‖ + ‖y‖`. -/ theorem norm_add_lt_of_not_sameRay (h : ¬SameRay ℝ x y) : ‖x + y‖ < ‖x‖ + ‖y‖ := by simp only [sameRay_iff_inv_norm_smul_eq, not_or, ← Ne.eq_def] at h rcases h with ⟨hx, hy, hne⟩ rw [← norm_pos_iff] at hx hy have hxy : 0 < ‖x‖ + ‖y‖ := add_pos hx hy have := combo_mem_ball_of_ne (inv_norm_smul_mem_unitClosedBall x) (inv_norm_smul_mem_unitClosedBall y) hne (div_pos hx hxy) (div_pos hy hxy) (by rw [← add_div, div_self hxy.ne']) rwa [mem_ball_zero_iff, div_eq_inv_mul, div_eq_inv_mul, mul_smul, mul_smul, smul_inv_smul₀ hx.ne', smul_inv_smul₀ hy.ne', ← smul_add, norm_smul, Real.norm_of_nonneg (inv_pos.2 hxy).le, ← div_eq_inv_mul, div_lt_one hxy] at this theorem lt_norm_sub_of_not_sameRay (h : ¬SameRay ℝ x y) : ‖x‖ - ‖y‖ < ‖x - y‖ := by nth_rw 1 [← sub_add_cancel x y] at h ⊢ exact sub_lt_iff_lt_add.2 (norm_add_lt_of_not_sameRay fun H' => h <| H'.add_left SameRay.rfl) theorem abs_lt_norm_sub_of_not_sameRay (h : ¬SameRay ℝ x y) : |‖x‖ - ‖y‖| < ‖x - y‖ := by refine abs_sub_lt_iff.2 ⟨lt_norm_sub_of_not_sameRay h, ?_⟩ rw [norm_sub_rev] exact lt_norm_sub_of_not_sameRay (mt SameRay.symm h) /-- In a strictly convex space, two vectors `x`, `y` are in the same ray if and only if the triangle inequality for `x` and `y` becomes an equality. -/ theorem sameRay_iff_norm_add : SameRay ℝ x y ↔ ‖x + y‖ = ‖x‖ + ‖y‖ := ⟨SameRay.norm_add, fun h => Classical.not_not.1 fun h' => (norm_add_lt_of_not_sameRay h').ne h⟩ /-- If `x` and `y` are two vectors in a strictly convex space have the same norm and the norm of their sum is equal to the sum of their norms, then they are equal. -/ theorem eq_of_norm_eq_of_norm_add_eq (h₁ : ‖x‖ = ‖y‖) (h₂ : ‖x + y‖ = ‖x‖ + ‖y‖) : x = y := (sameRay_iff_norm_add.mpr h₂).eq_of_norm_eq h₁ /-- In a strictly convex space, two vectors `x`, `y` are not in the same ray if and only if the triangle inequality for `x` and `y` is strict. -/ theorem not_sameRay_iff_norm_add_lt : ¬SameRay ℝ x y ↔ ‖x + y‖ < ‖x‖ + ‖y‖ := sameRay_iff_norm_add.not.trans (norm_add_le _ _).lt_iff_ne.symm theorem sameRay_iff_norm_sub : SameRay ℝ x y ↔ ‖x - y‖ = |‖x‖ - ‖y‖| := ⟨SameRay.norm_sub, fun h => Classical.not_not.1 fun h' => (abs_lt_norm_sub_of_not_sameRay h').ne' h⟩ theorem not_sameRay_iff_abs_lt_norm_sub : ¬SameRay ℝ x y ↔ |‖x‖ - ‖y‖| < ‖x - y‖ := sameRay_iff_norm_sub.not.trans <| ne_comm.trans (abs_norm_sub_norm_le _ _).lt_iff_ne.symm theorem norm_midpoint_lt_iff (h : ‖x‖ = ‖y‖) : ‖(1 / 2 : ℝ) • (x + y)‖ < ‖x‖ ↔ x ≠ y := by rw [norm_smul, Real.norm_of_nonneg (one_div_nonneg.2 zero_le_two), ← inv_eq_one_div, ← div_eq_inv_mul, div_lt_iff₀ (zero_lt_two' ℝ), mul_two, ← not_sameRay_iff_of_norm_eq h, not_sameRay_iff_norm_add_lt, h]
Mathlib/Analysis/Convex/StrictConvexSpace.lean
230
233
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Chris Hughes, Floris van Doorn, Yaël Dillies -/ import Mathlib.Data.Nat.Basic import Mathlib.Tactic.GCongr.CoreAttrs import Mathlib.Tactic.Common import Mathlib.Tactic.Monotonicity.Attr /-! # Factorial and variants This file defines the factorial, along with the ascending and descending variants. For the proof that the factorial of `n` counts the permutations of an `n`-element set, see `Fintype.card_perm`. ## Main declarations * `Nat.factorial`: The factorial. * `Nat.ascFactorial`: The ascending factorial. It is the product of natural numbers from `n` to `n + k - 1`. * `Nat.descFactorial`: The descending factorial. It is the product of natural numbers from `n - k + 1` to `n`. -/ namespace Nat /-- `Nat.factorial n` is the factorial of `n`. -/ def factorial : ℕ → ℕ | 0 => 1 | succ n => succ n * factorial n /-- factorial notation `(n)!` for `Nat.factorial n`. In Lean, names can end with exclamation marks (e.g. `List.get!`), so you cannot write `n!` in Lean, but must write `(n)!` or `n !` instead. The former is preferred, since Lean can confuse the `!` in `n !` as the (prefix) boolean negation operation in some cases. For numerals the parentheses are not required, so e.g. `0!` or `1!` work fine. Todo: replace occurrences of `n !` with `(n)!` in Mathlib. -/ scoped notation:10000 n "!" => Nat.factorial n section Factorial variable {m n : ℕ} @[simp] theorem factorial_zero : 0! = 1 := rfl theorem factorial_succ (n : ℕ) : (n + 1)! = (n + 1) * n ! := rfl @[simp] theorem factorial_one : 1! = 1 := rfl @[simp] theorem factorial_two : 2! = 2 := rfl theorem mul_factorial_pred (hn : n ≠ 0) : n * (n - 1)! = n ! := Nat.sub_add_cancel (one_le_iff_ne_zero.mpr hn) ▸ rfl theorem factorial_pos : ∀ n, 0 < n ! | 0 => Nat.zero_lt_one | succ n => Nat.mul_pos (succ_pos _) (factorial_pos n) theorem factorial_ne_zero (n : ℕ) : n ! ≠ 0 := ne_of_gt (factorial_pos _) theorem factorial_dvd_factorial {m n} (h : m ≤ n) : m ! ∣ n ! := by induction h with | refl => exact Nat.dvd_refl _ | step _ ih => exact Nat.dvd_trans ih (Nat.dvd_mul_left _ _) theorem dvd_factorial : ∀ {m n}, 0 < m → m ≤ n → m ∣ n ! | succ _, _, _, h => Nat.dvd_trans (Nat.dvd_mul_right _ _) (factorial_dvd_factorial h) @[mono, gcongr] theorem factorial_le {m n} (h : m ≤ n) : m ! ≤ n ! := le_of_dvd (factorial_pos _) (factorial_dvd_factorial h) theorem factorial_mul_pow_le_factorial : ∀ {m n : ℕ}, m ! * (m + 1) ^ n ≤ (m + n)! | m, 0 => by simp | m, n + 1 => by rw [← Nat.add_assoc, factorial_succ, Nat.mul_comm (_ + 1), Nat.pow_succ, ← Nat.mul_assoc] exact Nat.mul_le_mul factorial_mul_pow_le_factorial (succ_le_succ (le_add_right _ _)) theorem factorial_lt (hn : 0 < n) : n ! < m ! ↔ n < m := by refine ⟨fun h => not_le.mp fun hmn => Nat.not_le_of_lt h (factorial_le hmn), fun h => ?_⟩ have : ∀ {n}, 0 < n → n ! < (n + 1)! := by intro k hk rw [factorial_succ, succ_mul, Nat.lt_add_left_iff_pos] exact Nat.mul_pos hk k.factorial_pos induction h generalizing hn with | refl => exact this hn | step hnk ih => exact lt_trans (ih hn) <| this <| lt_trans hn <| lt_of_succ_le hnk @[gcongr] lemma factorial_lt_of_lt {m n : ℕ} (hn : 0 < n) (h : n < m) : n ! < m ! := (factorial_lt hn).mpr h @[simp] lemma one_lt_factorial : 1 < n ! ↔ 1 < n := factorial_lt Nat.one_pos @[simp] theorem factorial_eq_one : n ! = 1 ↔ n ≤ 1 := by constructor · intro h rw [← not_lt, ← one_lt_factorial, h] apply lt_irrefl · rintro (_|_|_) <;> rfl theorem factorial_inj (hn : 1 < n) : n ! = m ! ↔ n = m := by refine ⟨fun h => ?_, congr_arg _⟩ obtain hnm | rfl | hnm := lt_trichotomy n m · rw [← factorial_lt <| lt_of_succ_lt hn, h] at hnm cases lt_irrefl _ hnm · rfl rw [← one_lt_factorial, h, one_lt_factorial] at hn rw [← factorial_lt <| lt_of_succ_lt hn, h] at hnm cases lt_irrefl _ hnm theorem factorial_inj' (h : 1 < n ∨ 1 < m) : n ! = m ! ↔ n = m := by obtain hn|hm := h · exact factorial_inj hn · rw [eq_comm, factorial_inj hm, eq_comm] theorem self_le_factorial : ∀ n : ℕ, n ≤ n ! | 0 => Nat.zero_le _ | k + 1 => Nat.le_mul_of_pos_right _ (Nat.one_le_of_lt k.factorial_pos) theorem lt_factorial_self {n : ℕ} (hi : 3 ≤ n) : n < n ! := by have : 0 < n := by omega have hn : 1 < pred n := le_pred_of_lt (succ_le_iff.mp hi) rw [← succ_pred_eq_of_pos ‹0 < n›, factorial_succ] exact (Nat.lt_mul_iff_one_lt_right (pred n).succ_pos).2 ((Nat.lt_of_lt_of_le hn (self_le_factorial _))) theorem add_factorial_succ_lt_factorial_add_succ {i : ℕ} (n : ℕ) (hi : 2 ≤ i) : i + (n + 1)! < (i + n + 1)! := by rw [factorial_succ (i + _), Nat.add_mul, Nat.one_mul] have := (i + n).self_le_factorial refine Nat.add_lt_add_of_lt_of_le (Nat.lt_of_le_of_lt ?_ ((Nat.lt_mul_iff_one_lt_right ?_).2 ?_)) (factorial_le ?_) <;> omega theorem add_factorial_lt_factorial_add {i n : ℕ} (hi : 2 ≤ i) (hn : 1 ≤ n) : i + n ! < (i + n)! := by cases hn · rw [factorial_one] exact lt_factorial_self (succ_le_succ hi) exact add_factorial_succ_lt_factorial_add_succ _ hi theorem add_factorial_succ_le_factorial_add_succ (i : ℕ) (n : ℕ) : i + (n + 1)! ≤ (i + (n + 1))! := by cases (le_or_lt (2 : ℕ) i) · rw [← Nat.add_assoc] apply Nat.le_of_lt apply add_factorial_succ_lt_factorial_add_succ assumption · match i with | 0 => simp | 1 => rw [← Nat.add_assoc, factorial_succ (1 + n), Nat.add_mul, Nat.one_mul, Nat.add_comm 1 n, Nat.add_le_add_iff_right] exact Nat.mul_pos n.succ_pos n.succ.factorial_pos | succ (succ n) => contradiction theorem add_factorial_le_factorial_add (i : ℕ) {n : ℕ} (n1 : 1 ≤ n) : i + n ! ≤ (i + n)! := by rcases n1 with - | @h · exact self_le_factorial _ exact add_factorial_succ_le_factorial_add_succ i h theorem factorial_mul_pow_sub_le_factorial {n m : ℕ} (hnm : n ≤ m) : n ! * n ^ (m - n) ≤ m ! := by calc _ ≤ n ! * (n + 1) ^ (m - n) := Nat.mul_le_mul_left _ (Nat.pow_le_pow_left n.le_succ _) _ ≤ _ := by simpa [hnm] using @Nat.factorial_mul_pow_le_factorial n (m - n) lemma factorial_le_pow : ∀ n, n ! ≤ n ^ n | 0 => le_refl _ | n + 1 => calc _ ≤ (n + 1) * n ^ n := Nat.mul_le_mul_left _ n.factorial_le_pow _ ≤ (n + 1) * (n + 1) ^ n := Nat.mul_le_mul_left _ (Nat.pow_le_pow_left n.le_succ _) _ = _ := by rw [pow_succ'] end Factorial /-! ### Ascending and descending factorials -/ section AscFactorial /-- `n.ascFactorial k = n (n + 1) ⋯ (n + k - 1)`. This is closely related to `ascPochhammer`, but much less general. -/ def ascFactorial (n : ℕ) : ℕ → ℕ | 0 => 1 | k + 1 => (n + k) * ascFactorial n k @[simp] theorem ascFactorial_zero (n : ℕ) : n.ascFactorial 0 = 1 := rfl theorem ascFactorial_succ {n k : ℕ} : n.ascFactorial k.succ = (n + k) * n.ascFactorial k := rfl theorem zero_ascFactorial : ∀ (k : ℕ), (0 : ℕ).ascFactorial k.succ = 0 | 0 => by rw [ascFactorial_succ, ascFactorial_zero, Nat.zero_add, Nat.zero_mul] | (k+1) => by rw [ascFactorial_succ, zero_ascFactorial k, Nat.mul_zero] @[simp] theorem one_ascFactorial : ∀ (k : ℕ), (1 : ℕ).ascFactorial k = k.factorial | 0 => ascFactorial_zero 1 | (k+1) => by rw [ascFactorial_succ, one_ascFactorial k, Nat.add_comm, factorial_succ] theorem succ_ascFactorial (n : ℕ) : ∀ k, n * n.succ.ascFactorial k = (n + k) * n.ascFactorial k | 0 => by rw [Nat.add_zero, ascFactorial_zero, ascFactorial_zero] | k + 1 => by rw [ascFactorial, Nat.mul_left_comm, succ_ascFactorial n k, ascFactorial, succ_add, ← Nat.add_assoc] /-- `(n + 1).ascFactorial k = (n + k) ! / n !` but without ℕ-division. See `Nat.ascFactorial_eq_div` for the version with ℕ-division. -/ theorem factorial_mul_ascFactorial (n : ℕ) : ∀ k, n ! * (n + 1).ascFactorial k = (n + k)! | 0 => by rw [ascFactorial_zero, Nat.add_zero, Nat.mul_one] | k + 1 => by rw [ascFactorial_succ, ← Nat.add_assoc, factorial_succ, Nat.mul_comm (n + 1 + k), ← Nat.mul_assoc, factorial_mul_ascFactorial n k, Nat.mul_comm, Nat.add_right_comm] /-- `n.ascFactorial k = (n + k - 1)! / (n - 1)!` for `n > 0` but without ℕ-division. See `Nat.ascFactorial_eq_div` for the version with ℕ-division. Consider using `factorial_mul_ascFactorial` to avoid complications of ℕ-subtraction. -/ theorem factorial_mul_ascFactorial' (n k : ℕ) (h : 0 < n) : (n - 1) ! * n.ascFactorial k = (n + k - 1)! := by rw [Nat.sub_add_comm h, Nat.sub_one] nth_rw 2 [Nat.eq_add_of_sub_eq h rfl] rw [Nat.sub_one, factorial_mul_ascFactorial] theorem ascFactorial_mul_ascFactorial (n l k : ℕ) : n.ascFactorial l * (n + l).ascFactorial k = n.ascFactorial (l + k) := by cases n with | zero => cases l · simp only [ascFactorial_zero, Nat.add_zero, Nat.one_mul, Nat.zero_add] · simp only [Nat.add_right_comm, zero_ascFactorial, Nat.zero_add, Nat.zero_mul] | succ n' => apply Nat.mul_left_cancel (factorial_pos n') simp only [Nat.add_assoc, ← Nat.mul_assoc, factorial_mul_ascFactorial] rw [Nat.add_comm 1 l, ← Nat.add_assoc, factorial_mul_ascFactorial, Nat.add_assoc] /-- Avoid in favor of `Nat.factorial_mul_ascFactorial` if you can. ℕ-division isn't worth it. -/ theorem ascFactorial_eq_div (n k : ℕ) : (n + 1).ascFactorial k = (n + k)! / n ! := Nat.eq_div_of_mul_eq_right n.factorial_ne_zero (factorial_mul_ascFactorial _ _) /-- Avoid in favor of `Nat.factorial_mul_ascFactorial'` if you can. ℕ-division isn't worth it. -/ theorem ascFactorial_eq_div' (n k : ℕ) (h : 0 < n) : n.ascFactorial k = (n + k - 1)! / (n - 1) ! := Nat.eq_div_of_mul_eq_right (n - 1).factorial_ne_zero (factorial_mul_ascFactorial' _ _ h) theorem ascFactorial_of_sub {n k : ℕ} : (n - k) * (n - k + 1).ascFactorial k = (n - k).ascFactorial (k + 1) := by rw [succ_ascFactorial, ascFactorial_succ] theorem pow_succ_le_ascFactorial (n : ℕ) : ∀ k : ℕ, n ^ k ≤ n.ascFactorial k | 0 => by rw [ascFactorial_zero, Nat.pow_zero] | k + 1 => by rw [Nat.pow_succ, Nat.mul_comm, ascFactorial_succ, ← succ_ascFactorial] exact Nat.mul_le_mul (Nat.le_refl n) (Nat.le_trans (Nat.pow_le_pow_left (le_succ n) k) (pow_succ_le_ascFactorial n.succ k)) theorem pow_lt_ascFactorial' (n k : ℕ) : (n + 1) ^ (k + 2) < (n + 1).ascFactorial (k + 2) := by rw [Nat.pow_succ, ascFactorial, Nat.mul_comm] exact Nat.mul_lt_mul_of_lt_of_le' (Nat.lt_add_of_pos_right k.succ_pos) (pow_succ_le_ascFactorial n.succ _) (Nat.pow_pos n.succ_pos) theorem pow_lt_ascFactorial (n : ℕ) : ∀ {k : ℕ}, 2 ≤ k → (n + 1) ^ k < (n + 1).ascFactorial k | 0 => by rintro ⟨⟩ | 1 => by intro; contradiction | k + 2 => fun _ => pow_lt_ascFactorial' n k theorem ascFactorial_le_pow_add (n : ℕ) : ∀ k : ℕ, (n+1).ascFactorial k ≤ (n + k) ^ k | 0 => by rw [ascFactorial_zero, Nat.pow_zero] | k + 1 => by rw [ascFactorial_succ, Nat.pow_succ, Nat.mul_comm, ← Nat.add_assoc, Nat.add_right_comm n 1 k] exact Nat.mul_le_mul_right _ (Nat.le_trans (ascFactorial_le_pow_add _ k) (Nat.pow_le_pow_left (le_succ _) _)) theorem ascFactorial_lt_pow_add (n : ℕ) : ∀ {k : ℕ}, 2 ≤ k → (n + 1).ascFactorial k < (n + k) ^ k | 0 => by rintro ⟨⟩ | 1 => by intro; contradiction | k + 2 => fun _ => by rw [Nat.pow_succ, Nat.mul_comm, ascFactorial_succ, succ_add_eq_add_succ n (k + 1)] exact Nat.mul_lt_mul_of_le_of_lt (le_refl _) (Nat.lt_of_le_of_lt (ascFactorial_le_pow_add n _) (Nat.pow_lt_pow_left (Nat.lt_succ_self _) k.succ_ne_zero)) (succ_pos _) theorem ascFactorial_pos (n k : ℕ) : 0 < (n + 1).ascFactorial k := Nat.lt_of_lt_of_le (Nat.pow_pos n.succ_pos) (pow_succ_le_ascFactorial (n + 1) k) end AscFactorial section DescFactorial /-- `n.descFactorial k = n! / (n - k)!` (as seen in `Nat.descFactorial_eq_div`), but implemented recursively to allow for "quick" computation when using `norm_num`. This is closely related to `descPochhammer`, but much less general. -/ def descFactorial (n : ℕ) : ℕ → ℕ | 0 => 1 | k + 1 => (n - k) * descFactorial n k @[simp] theorem descFactorial_zero (n : ℕ) : n.descFactorial 0 = 1 := rfl @[simp] theorem descFactorial_succ (n k : ℕ) : n.descFactorial (k + 1) = (n - k) * n.descFactorial k := rfl theorem zero_descFactorial_succ (k : ℕ) : (0 : ℕ).descFactorial (k + 1) = 0 := by rw [descFactorial_succ, Nat.zero_sub, Nat.zero_mul] theorem descFactorial_one (n : ℕ) : n.descFactorial 1 = n := by simp theorem succ_descFactorial_succ (n : ℕ) : ∀ k : ℕ, (n + 1).descFactorial (k + 1) = (n + 1) * n.descFactorial k | 0 => by rw [descFactorial_zero, descFactorial_one, Nat.mul_one] | succ k => by rw [descFactorial_succ, succ_descFactorial_succ _ k, descFactorial_succ, succ_sub_succ, Nat.mul_left_comm] theorem succ_descFactorial (n : ℕ) : ∀ k, (n + 1 - k) * (n + 1).descFactorial k = (n + 1) * n.descFactorial k | 0 => by rw [Nat.sub_zero, descFactorial_zero, descFactorial_zero] | k + 1 => by rw [descFactorial, succ_descFactorial _ k, descFactorial_succ, succ_sub_succ, Nat.mul_left_comm] theorem descFactorial_self : ∀ n : ℕ, n.descFactorial n = n ! | 0 => by rw [descFactorial_zero, factorial_zero] | succ n => by rw [succ_descFactorial_succ, descFactorial_self n, factorial_succ] @[simp] theorem descFactorial_eq_zero_iff_lt {n : ℕ} : ∀ {k : ℕ}, n.descFactorial k = 0 ↔ n < k | 0 => by simp only [descFactorial_zero, Nat.one_ne_zero, Nat.not_lt_zero] | succ k => by rw [descFactorial_succ, mul_eq_zero, descFactorial_eq_zero_iff_lt, Nat.lt_succ_iff, Nat.sub_eq_zero_iff_le, Nat.lt_iff_le_and_ne, or_iff_left_iff_imp, and_imp] exact fun h _ => h alias ⟨_, descFactorial_of_lt⟩ := descFactorial_eq_zero_iff_lt theorem add_descFactorial_eq_ascFactorial (n : ℕ) : ∀ k : ℕ, (n + k).descFactorial k = (n + 1).ascFactorial k | 0 => by rw [ascFactorial_zero, descFactorial_zero] | succ k => by rw [Nat.add_succ, succ_descFactorial_succ, ascFactorial_succ, add_descFactorial_eq_ascFactorial _ k, Nat.add_right_comm] theorem add_descFactorial_eq_ascFactorial' (n : ℕ) : ∀ k : ℕ, (n + k - 1).descFactorial k = n.ascFactorial k | 0 => by rw [ascFactorial_zero, descFactorial_zero] | succ k => by rw [descFactorial_succ, ascFactorial_succ, ← succ_add_eq_add_succ, add_descFactorial_eq_ascFactorial' _ k, ← succ_ascFactorial, succ_add_sub_one, Nat.add_sub_cancel] /-- `n.descFactorial k = n! / (n - k)!` but without ℕ-division. See `Nat.descFactorial_eq_div` for the version using ℕ-division. -/ theorem factorial_mul_descFactorial : ∀ {n k : ℕ}, k ≤ n → (n - k)! * n.descFactorial k = n ! | n, 0 => fun _ => by rw [descFactorial_zero, Nat.mul_one, Nat.sub_zero] | 0, succ k => fun h => by exfalso exact not_succ_le_zero k h | succ n, succ k => fun h => by rw [succ_descFactorial_succ, succ_sub_succ, ← Nat.mul_assoc, Nat.mul_comm (n - k)!, Nat.mul_assoc, factorial_mul_descFactorial (Nat.succ_le_succ_iff.1 h), factorial_succ] theorem descFactorial_mul_descFactorial {k m n : ℕ} (hkm : k ≤ m) : (n - k).descFactorial (m - k) * n.descFactorial k = n.descFactorial m := by by_cases hmn : m ≤ n · apply Nat.mul_left_cancel (n - m).factorial_pos rw [factorial_mul_descFactorial hmn, show n - m = (n - k) - (m - k) by omega, ← Nat.mul_assoc, factorial_mul_descFactorial (show m - k ≤ n - k by omega), factorial_mul_descFactorial (le_trans hkm hmn)] · rw [descFactorial_eq_zero_iff_lt.mpr (show n < m by omega)] by_cases hkn : k ≤ n · rw [descFactorial_eq_zero_iff_lt.mpr (show n - k < m - k by omega), Nat.zero_mul] · rw [descFactorial_eq_zero_iff_lt.mpr (show n < k by omega), Nat.mul_zero] /-- Avoid in favor of `Nat.factorial_mul_descFactorial` if you can. ℕ-division isn't worth it. -/ theorem descFactorial_eq_div {n k : ℕ} (h : k ≤ n) : n.descFactorial k = n ! / (n - k)! := by apply Nat.mul_left_cancel (n - k).factorial_pos rw [factorial_mul_descFactorial h] exact (Nat.mul_div_cancel' <| factorial_dvd_factorial <| Nat.sub_le n k).symm theorem descFactorial_le (n : ℕ) {k m : ℕ} (h : k ≤ m) : k.descFactorial n ≤ m.descFactorial n := by induction n with | zero => rfl | succ n ih => rw [descFactorial_succ, descFactorial_succ] exact Nat.mul_le_mul (Nat.sub_le_sub_right h n) ih theorem pow_sub_le_descFactorial (n : ℕ) : ∀ k : ℕ, (n + 1 - k) ^ k ≤ n.descFactorial k | 0 => by rw [descFactorial_zero, Nat.pow_zero] | k + 1 => by rw [descFactorial_succ, Nat.pow_succ, succ_sub_succ, Nat.mul_comm] apply Nat.mul_le_mul_left exact (le_trans (Nat.pow_le_pow_left (Nat.sub_le_sub_right n.le_succ _) k) (pow_sub_le_descFactorial n k)) theorem pow_sub_lt_descFactorial' {n : ℕ} : ∀ {k : ℕ}, k + 2 ≤ n → (n - (k + 1)) ^ (k + 2) < n.descFactorial (k + 2) | 0, h => by
rw [descFactorial_succ, Nat.pow_succ, Nat.pow_one, descFactorial_one] exact Nat.mul_lt_mul_of_pos_left (by omega) (Nat.sub_pos_of_lt h) | k + 1, h => by rw [descFactorial_succ, Nat.pow_succ, Nat.mul_comm] refine Nat.mul_lt_mul_of_pos_left ?_ (Nat.sub_pos_of_lt h) refine Nat.lt_of_le_of_lt (Nat.pow_le_pow_left (Nat.sub_le_sub_right n.le_succ _) _) ?_ rw [succ_sub_succ]
Mathlib/Data/Nat/Factorial/Basic.lean
414
420
/- Copyright (c) 2024 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Kernel.Composition.IntegralCompProd import Mathlib.Probability.Kernel.Disintegration.StandardBorel /-! # Lebesgue and Bochner integrals of conditional kernels Integrals of `ProbabilityTheory.Kernel.condKernel` and `MeasureTheory.Measure.condKernel`. ## Main statements * `ProbabilityTheory.setIntegral_condKernel`: the integral `∫ b in s, ∫ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a)` is equal to `∫ x in s ×ˢ t, f x ∂(κ a)`. * `MeasureTheory.Measure.setIntegral_condKernel`: `∫ b in s, ∫ ω in t, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫ x in s ×ˢ t, f x ∂ρ` Corresponding statements for the Lebesgue integral and/or without the sets `s` and `t` are also provided. -/ open MeasureTheory ProbabilityTheory MeasurableSpace open scoped ENNReal namespace ProbabilityTheory variable {α β Ω : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} [MeasurableSpace Ω] [StandardBorelSpace Ω] [Nonempty Ω] section Lintegral variable [CountableOrCountablyGenerated α β] {κ : Kernel α (β × Ω)} [IsFiniteKernel κ] {f : β × Ω → ℝ≥0∞} lemma lintegral_condKernel_mem (a : α) {s : Set (β × Ω)} (hs : MeasurableSet s) : ∫⁻ x, Kernel.condKernel κ (a, x) (Prod.mk x ⁻¹' s) ∂(Kernel.fst κ a) = κ a s := by conv_rhs => rw [← κ.disintegrate κ.condKernel] simp_rw [Kernel.compProd_apply hs] lemma setLIntegral_condKernel_eq_measure_prod (a : α) {s : Set β} (hs : MeasurableSet s) {t : Set Ω} (ht : MeasurableSet t) : ∫⁻ b in s, Kernel.condKernel κ (a, b) t ∂(Kernel.fst κ a) = κ a (s ×ˢ t) := by have : κ a (s ×ˢ t) = (Kernel.fst κ ⊗ₖ Kernel.condKernel κ) a (s ×ˢ t) := by congr; exact (κ.disintegrate _).symm rw [this, Kernel.compProd_apply (hs.prod ht)] classical have : ∀ b, Kernel.condKernel κ (a, b) {c | (b, c) ∈ s ×ˢ t} = s.indicator (fun b ↦ Kernel.condKernel κ (a, b) t) b := by intro b by_cases hb : b ∈ s <;> simp [hb] simp_rw [Set.preimage, this] rw [lintegral_indicator hs] lemma lintegral_condKernel (hf : Measurable f) (a : α) : ∫⁻ b, ∫⁻ ω, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫⁻ x, f x ∂(κ a) := by conv_rhs => rw [← κ.disintegrate κ.condKernel] rw [Kernel.lintegral_compProd _ _ _ hf] lemma setLIntegral_condKernel (hf : Measurable f) (a : α) {s : Set β} (hs : MeasurableSet s) {t : Set Ω} (ht : MeasurableSet t) : ∫⁻ b in s, ∫⁻ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫⁻ x in s ×ˢ t, f x ∂(κ a) := by conv_rhs => rw [← κ.disintegrate κ.condKernel] rw [Kernel.setLIntegral_compProd _ _ _ hf hs ht] lemma setLIntegral_condKernel_univ_right (hf : Measurable f) (a : α) {s : Set β} (hs : MeasurableSet s) : ∫⁻ b in s, ∫⁻ ω, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫⁻ x in s ×ˢ Set.univ, f x ∂(κ a) := by rw [← setLIntegral_condKernel hf a hs MeasurableSet.univ]; simp_rw [Measure.restrict_univ]
lemma setLIntegral_condKernel_univ_left (hf : Measurable f) (a : α) {t : Set Ω} (ht : MeasurableSet t) : ∫⁻ b, ∫⁻ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫⁻ x in Set.univ ×ˢ t, f x ∂(κ a) := by
Mathlib/Probability/Kernel/Disintegration/Integral.lean
76
80
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Data.Complex.Basic import Mathlib.Data.Nat.Prime.Basic import Mathlib.Data.Real.Archimedean import Mathlib.NumberTheory.Zsqrtd.Basic /-! # Gaussian integers The Gaussian integers are complex integer, complex numbers whose real and imaginary parts are both integers. ## Main definitions The Euclidean domain structure on `ℤ[i]` is defined in this file. The homomorphism `GaussianInt.toComplex` into the complex numbers is also defined in this file. ## See also See `NumberTheory.Zsqrtd.QuadraticReciprocity` for: * `prime_iff_mod_four_eq_three_of_nat_prime`: A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4` ## Notations This file uses the local notation `ℤ[i]` for `GaussianInt` ## Implementation notes Gaussian integers are implemented using the more general definition `Zsqrtd`, the type of integers adjoined a square root of `d`, in this case `-1`. The definition is reducible, so that properties and definitions about `Zsqrtd` can easily be used. -/ open Zsqrtd Complex open scoped ComplexConjugate /-- The Gaussian integers, defined as `ℤ√(-1)`. -/ abbrev GaussianInt : Type := Zsqrtd (-1) local notation "ℤ[i]" => GaussianInt namespace GaussianInt instance : Repr ℤ[i] := ⟨fun x _ => "⟨" ++ repr x.re ++ ", " ++ repr x.im ++ "⟩"⟩ instance instCommRing : CommRing ℤ[i] := Zsqrtd.commRing section attribute [-instance] Complex.instField -- Avoid making things noncomputable unnecessarily. /-- The embedding of the Gaussian integers into the complex numbers, as a ring homomorphism. -/ def toComplex : ℤ[i] →+* ℂ := Zsqrtd.lift ⟨I, by simp⟩ end instance : Coe ℤ[i] ℂ := ⟨toComplex⟩ theorem toComplex_def (x : ℤ[i]) : (x : ℂ) = x.re + x.im * I := rfl theorem toComplex_def' (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ) = x + y * I := by simp [toComplex_def] theorem toComplex_def₂ (x : ℤ[i]) : (x : ℂ) = ⟨x.re, x.im⟩ := by apply Complex.ext <;> simp [toComplex_def] @[simp] theorem to_real_re (x : ℤ[i]) : ((x.re : ℤ) : ℝ) = (x : ℂ).re := by simp [toComplex_def] @[simp] theorem to_real_im (x : ℤ[i]) : ((x.im : ℤ) : ℝ) = (x : ℂ).im := by simp [toComplex_def] @[simp] theorem toComplex_re (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).re = x := by simp [toComplex_def] @[simp] theorem toComplex_im (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).im = y := by simp [toComplex_def] theorem toComplex_add (x y : ℤ[i]) : ((x + y : ℤ[i]) : ℂ) = x + y := toComplex.map_add _ _ theorem toComplex_mul (x y : ℤ[i]) : ((x * y : ℤ[i]) : ℂ) = x * y := toComplex.map_mul _ _
Mathlib/NumberTheory/Zsqrtd/GaussianInt.lean
97
97
/- 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.Algebra.FreeMonoid.Basic import Mathlib.Algebra.Group.TypeTags.Basic /-! # `List.count` as a bundled homomorphism In this file we define `FreeMonoid.countP`, `FreeMonoid.count`, `FreeAddMonoid.countP`, and `FreeAddMonoid.count`. These are `List.countP` and `List.count` bundled as multiplicative and additive homomorphisms from `FreeMonoid` and `FreeAddMonoid`. We do not use `to_additive` too much because it can't map `Multiplicative ℕ` to `ℕ`. -/ variable {α : Type*} (p : α → Prop) [DecidablePred p] namespace FreeMonoid /-- `List.countP` lifted to free monoids -/ @[to_additive "`List.countP` lifted to free additive monoids"] def countP' (l : FreeMonoid α) : ℕ := l.toList.countP p @[to_additive] lemma countP'_one : (1 : FreeMonoid α).countP' p = 0 := rfl @[to_additive] lemma countP'_mul (l₁ l₂ : FreeMonoid α) : (l₁ * l₂).countP' p = l₁.countP' p + l₂.countP' p := by dsimp [countP'] simp only [List.countP_append] /-- `List.countP` as a bundled multiplicative monoid homomorphism. -/ def countP : FreeMonoid α →* Multiplicative ℕ where toFun := .ofAdd ∘ FreeMonoid.countP' p map_one' := by simp [countP'_one p] map_mul' x y := by simp [countP'_mul p] theorem countP_apply (l : FreeMonoid α) : l.countP p = .ofAdd (l.toList.countP p) := rfl lemma countP_of (x : α) : (of x).countP p = if p x then Multiplicative.ofAdd 1 else Multiplicative.ofAdd 0 := by rw [countP_apply, toList_of, List.countP_singleton, apply_ite (Multiplicative.ofAdd)] simp only [decide_eq_true_eq] /-- `List.count` as a bundled additive monoid homomorphism. -/ def count [DecidableEq α] (x : α) : FreeMonoid α →* Multiplicative ℕ := countP (· = x) theorem count_apply [DecidableEq α] (x : α) (l : FreeAddMonoid α) : count x l = Multiplicative.ofAdd (l.toList.count x) := rfl theorem count_of [DecidableEq α] (x y : α) : count x (of y) = Pi.mulSingle (f := fun _ => Multiplicative ℕ) x (Multiplicative.ofAdd 1) y := by simp only [count, eq_comm, countP_of, ofAdd_zero, Pi.mulSingle_apply] end FreeMonoid
namespace FreeAddMonoid /-- `List.countP` as a bundled additive monoid homomorphism. -/
Mathlib/Algebra/FreeMonoid/Count.lean
61
64
/- 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.Data.Set.Lattice import Mathlib.Data.Set.Pairwise.Basic /-! # Relations holding pairwise In this file we prove many facts about `Pairwise` and the set lattice. -/ open Function Set Order variable {α ι ι' : Type*} {κ : Sort*} {r : α → α → Prop} section Pairwise variable {f : ι → α} {s : Set α} namespace Set theorem pairwise_iUnion {f : κ → Set α} (h : Directed (· ⊆ ·) f) : (⋃ n, f n).Pairwise r ↔ ∀ n, (f n).Pairwise r := by constructor · intro H n exact Pairwise.mono (subset_iUnion _ _) H · intro H i hi j hj hij rcases mem_iUnion.1 hi with ⟨m, hm⟩ rcases mem_iUnion.1 hj with ⟨n, hn⟩ rcases h m n with ⟨p, mp, np⟩ exact H p (mp hm) (np hn) hij theorem pairwise_sUnion {r : α → α → Prop} {s : Set (Set α)} (h : DirectedOn (· ⊆ ·) s) : (⋃₀ s).Pairwise r ↔ ∀ a ∈ s, Set.Pairwise a r := by rw [sUnion_eq_iUnion, pairwise_iUnion h.directed_val, SetCoe.forall] end Set end Pairwise namespace Set section PartialOrderBot variable [PartialOrder α] [OrderBot α] {s : Set ι} {f : ι → α} theorem pairwiseDisjoint_iUnion {g : ι' → Set ι} (h : Directed (· ⊆ ·) g) : (⋃ n, g n).PairwiseDisjoint f ↔ ∀ ⦃n⦄, (g n).PairwiseDisjoint f := pairwise_iUnion h theorem pairwiseDisjoint_sUnion {s : Set (Set ι)} (h : DirectedOn (· ⊆ ·) s) : (⋃₀ s).PairwiseDisjoint f ↔ ∀ ⦃a⦄, a ∈ s → Set.PairwiseDisjoint a f := pairwise_sUnion h end PartialOrderBot section CompleteLattice variable [CompleteLattice α] {s : Set ι} {t : Set ι'} /-- Bind operation for `Set.PairwiseDisjoint`. If you want to only consider finsets of indices, you can use `Set.PairwiseDisjoint.biUnion_finset`. -/ theorem PairwiseDisjoint.biUnion {s : Set ι'} {g : ι' → Set ι} {f : ι → α} (hs : s.PairwiseDisjoint fun i' : ι' => ⨆ i ∈ g i', f i) (hg : ∀ i ∈ s, (g i).PairwiseDisjoint f) : (⋃ i ∈ s, g i).PairwiseDisjoint f := by rintro a ha b hb hab simp_rw [Set.mem_iUnion] at ha hb obtain ⟨c, hc, ha⟩ := ha obtain ⟨d, hd, hb⟩ := hb obtain hcd | hcd := eq_or_ne (g c) (g d) · exact hg d hd (hcd ▸ ha) hb hab · exact (hs hc hd <| ne_of_apply_ne _ hcd).mono (le_iSup₂ (f := fun i _ => f i) a ha) (le_iSup₂ (f := fun i _ => f i) b hb) /-- If the suprema of columns are pairwise disjoint and suprema of rows as well, then everything is pairwise disjoint. Not to be confused with `Set.PairwiseDisjoint.prod`. -/ theorem PairwiseDisjoint.prod_left {f : ι × ι' → α} (hs : s.PairwiseDisjoint fun i => ⨆ i' ∈ t, f (i, i')) (ht : t.PairwiseDisjoint fun i' => ⨆ i ∈ s, f (i, i')) : (s ×ˢ t : Set (ι × ι')).PairwiseDisjoint f := by rintro ⟨i, i'⟩ hi ⟨j, j'⟩ hj h rw [mem_prod] at hi hj obtain rfl | hij := eq_or_ne i j · refine (ht hi.2 hj.2 <| (Prod.mk_right_injective _).ne_iff.1 h).mono ?_ ?_ · convert le_iSup₂ (α := α) i hi.1; rfl · convert le_iSup₂ (α := α) i hj.1; rfl · refine (hs hi.1 hj.1 hij).mono ?_ ?_ · convert le_iSup₂ (α := α) i' hi.2; rfl · convert le_iSup₂ (α := α) j' hj.2; rfl end CompleteLattice section Frame variable [Frame α] theorem pairwiseDisjoint_prod_left {s : Set ι} {t : Set ι'} {f : ι × ι' → α} : (s ×ˢ t : Set (ι × ι')).PairwiseDisjoint f ↔ (s.PairwiseDisjoint fun i => ⨆ i' ∈ t, f (i, i')) ∧ t.PairwiseDisjoint fun i' => ⨆ i ∈ s, f (i, i') := by refine ⟨fun h => ⟨fun i hi j hj hij => ?_, fun i hi j hj hij => ?_⟩, fun h => h.1.prod_left h.2⟩ <;> simp_rw [Function.onFun, iSup_disjoint_iff, disjoint_iSup_iff] <;> intro i' hi' j' hj' · exact h (mk_mem_prod hi hi') (mk_mem_prod hj hj') (ne_of_apply_ne Prod.fst hij) · exact h (mk_mem_prod hi' hi) (mk_mem_prod hj' hj) (ne_of_apply_ne Prod.snd hij) end Frame theorem biUnion_diff_biUnion_eq {s t : Set ι} {f : ι → Set α} (h : (s ∪ t).PairwiseDisjoint f) : ((⋃ i ∈ s, f i) \ ⋃ i ∈ t, f i) = ⋃ i ∈ s \ t, f i := by refine (biUnion_diff_biUnion_subset f s t).antisymm (iUnion₂_subset fun i hi a ha => (mem_diff _).2 ⟨mem_biUnion hi.1 ha, ?_⟩) rw [mem_iUnion₂]; rintro ⟨j, hj, haj⟩ exact (h (Or.inl hi.1) (Or.inr hj) (ne_of_mem_of_not_mem hj hi.2).symm).le_bot ⟨ha, haj⟩ /-- Equivalence between a disjoint bounded union and a dependent sum. -/
noncomputable def biUnionEqSigmaOfDisjoint {s : Set ι} {f : ι → Set α} (h : s.PairwiseDisjoint f) : (⋃ i ∈ s, f i) ≃ Σi : s, f i := (Equiv.setCongr (biUnion_eq_iUnion _ _)).trans <| unionEqSigmaOfDisjoint fun ⟨_i, hi⟩ ⟨_j, hj⟩ ne => h hi hj fun eq => ne <| Subtype.eq eq end Set
Mathlib/Data/Set/Pairwise/Lattice.lean
124
130
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.Category.Ring.Basic import Mathlib.CategoryTheory.Limits.HasLimits /-! # The category of commutative rings has all colimits. This file uses a "pre-automated" approach, just as for `Mathlib/Algebra/Category/MonCat/Colimits.lean`. It is a very uniform approach, that conceivably could be synthesised directly by a tactic that analyses the shape of `CommRing` and `RingHom`. -/ universe u v open CategoryTheory Limits namespace RingCat.Colimits /-! We build the colimit of a diagram in `RingCat` by constructing the free ring on the disjoint union of all the rings in the diagram, then taking the quotient by the ring laws within each ring, and the identifications given by the morphisms in the diagram. -/ variable {J : Type v} [SmallCategory J] (F : J ⥤ RingCat.{v}) /-- An inductive type representing all ring expressions (without Relations) on a collection of types indexed by the objects of `J`. -/ inductive Prequotient -- There's always `of` | of : ∀ (j : J) (_ : F.obj j), Prequotient -- Then one generator for each operation | zero : Prequotient | one : Prequotient | neg : Prequotient → Prequotient | add : Prequotient → Prequotient → Prequotient | mul : Prequotient → Prequotient → Prequotient instance : Inhabited (Prequotient F) := ⟨Prequotient.zero⟩ open Prequotient /-- The Relation on `Prequotient` saying when two expressions are equal because of the ring laws, or because one element is mapped to another by a morphism in the diagram. -/ inductive Relation : Prequotient F → Prequotient F → Prop -- Make it an equivalence Relation: | refl : ∀ x, Relation x x | symm : ∀ (x y) (_ : Relation x y), Relation y x | trans : ∀ (x y z) (_ : Relation x y) (_ : Relation y z), Relation x z -- There's always a `map` Relation | map : ∀ (j j' : J) (f : j ⟶ j') (x : F.obj j), Relation (Prequotient.of j' (F.map f x)) (Prequotient.of j x) -- Then one Relation per operation, describing the interaction with `of` | zero : ∀ j, Relation (Prequotient.of j 0) zero | one : ∀ j, Relation (Prequotient.of j 1) one | neg : ∀ (j) (x : F.obj j), Relation (Prequotient.of j (-x)) (neg (Prequotient.of j x)) | add : ∀ (j) (x y : F.obj j), Relation (Prequotient.of j (x + y)) (add (Prequotient.of j x) (Prequotient.of j y)) | mul : ∀ (j) (x y : F.obj j), Relation (Prequotient.of j (x * y)) (mul (Prequotient.of j x) (Prequotient.of j y)) -- Then one Relation per argument of each operation | neg_1 : ∀ (x x') (_ : Relation x x'), Relation (neg x) (neg x') | add_1 : ∀ (x x' y) (_ : Relation x x'), Relation (add x y) (add x' y) | add_2 : ∀ (x y y') (_ : Relation y y'), Relation (add x y) (add x y') | mul_1 : ∀ (x x' y) (_ : Relation x x'), Relation (mul x y) (mul x' y) | mul_2 : ∀ (x y y') (_ : Relation y y'), Relation (mul x y) (mul x y') -- And one Relation per axiom | zero_add : ∀ x, Relation (add zero x) x | add_zero : ∀ x, Relation (add x zero) x | one_mul : ∀ x, Relation (mul one x) x | mul_one : ∀ x, Relation (mul x one) x | neg_add_cancel : ∀ x, Relation (add (neg x) x) zero | add_comm : ∀ x y, Relation (add x y) (add y x) | add_assoc : ∀ x y z, Relation (add (add x y) z) (add x (add y z)) | mul_assoc : ∀ x y z, Relation (mul (mul x y) z) (mul x (mul y z)) | left_distrib : ∀ x y z, Relation (mul x (add y z)) (add (mul x y) (mul x z)) | right_distrib : ∀ x y z, Relation (mul (add x y) z) (add (mul x z) (mul y z)) | zero_mul : ∀ x, Relation (mul zero x) zero | mul_zero : ∀ x, Relation (mul x zero) zero /-- The setoid corresponding to commutative expressions modulo monoid Relations and identifications. -/ def colimitSetoid : Setoid (Prequotient F) where r := Relation F iseqv := ⟨Relation.refl, Relation.symm _ _, Relation.trans _ _ _⟩ attribute [instance] colimitSetoid /-- The underlying type of the colimit of a diagram in `CommRingCat`. -/ def ColimitType : Type v := Quotient (colimitSetoid F) instance ColimitType.instZero : Zero (ColimitType F) where zero := Quotient.mk _ zero instance ColimitType.instAdd : Add (ColimitType F) where add := Quotient.map₂ add <| fun _x x' rx y _y' ry => Setoid.trans (Relation.add_1 _ _ y rx) (Relation.add_2 x' _ _ ry) instance ColimitType.instNeg : Neg (ColimitType F) where neg := Quotient.map neg Relation.neg_1 instance ColimitType.AddGroup : AddGroup (ColimitType F) where neg := Quotient.map neg Relation.neg_1 zero_add := Quotient.ind <| fun _ => Quotient.sound <| Relation.zero_add _ add_zero := Quotient.ind <| fun _ => Quotient.sound <| Relation.add_zero _ neg_add_cancel := Quotient.ind <| fun _ => Quotient.sound <| Relation.neg_add_cancel _ add_assoc := Quotient.ind <| fun _ => Quotient.ind₂ <| fun _ _ => Quotient.sound <| Relation.add_assoc _ _ _ nsmul := nsmulRec zsmul := zsmulRec instance InhabitedColimitType : Inhabited <| ColimitType F where default := 0 instance ColimitType.AddGroupWithOne : AddGroupWithOne (ColimitType F) := { ColimitType.AddGroup F with one := Quotient.mk _ one } instance : Ring (ColimitType.{v} F) := { ColimitType.AddGroupWithOne F with mul := Quot.map₂ Prequotient.mul Relation.mul_2 Relation.mul_1 one_mul := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.one_mul _ mul_one := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.mul_one _ add_comm := fun x y => Quot.induction_on₂ x y fun _ _ => Quot.sound <| Relation.add_comm _ _ mul_assoc := fun x y z => Quot.induction_on₃ x y z fun x y z => by simp only [(· * ·)] exact Quot.sound (Relation.mul_assoc _ _ _) mul_zero := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.mul_zero _ zero_mul := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.zero_mul _ left_distrib := fun x y z => Quot.induction_on₃ x y z fun x y z => by simp only [(· + ·), (· * ·), Add.add] exact Quot.sound (Relation.left_distrib _ _ _) right_distrib := fun x y z => Quot.induction_on₃ x y z fun x y z => by simp only [(· + ·), (· * ·), Add.add] exact Quot.sound (Relation.right_distrib _ _ _) } @[simp] theorem quot_zero : Quot.mk Setoid.r zero = (0 : ColimitType F) := rfl @[simp] theorem quot_one : Quot.mk Setoid.r one = (1 : ColimitType F) := rfl @[simp] theorem quot_neg (x : Prequotient F) : Quot.mk Setoid.r (neg x) = -(show ColimitType F from Quot.mk Setoid.r x) := rfl @[simp] theorem quot_add (x y) : Quot.mk Setoid.r (add x y) = (show ColimitType F from Quot.mk _ x) + (show ColimitType F from Quot.mk _ y) := rfl @[simp] theorem quot_mul (x y) : Quot.mk Setoid.r (mul x y) = (show ColimitType F from Quot.mk _ x) * (show ColimitType F from Quot.mk _ y) := rfl /-- The bundled ring giving the colimit of a diagram. -/ def colimit : RingCat := RingCat.of (ColimitType F) /-- The function from a given ring in the diagram to the colimit ring. -/ def coconeFun (j : J) (x : F.obj j) : ColimitType F := Quot.mk _ (Prequotient.of j x) /-- The ring homomorphism from a given ring in the diagram to the colimit ring. -/ def coconeMorphism (j : J) : F.obj j ⟶ colimit F := ofHom { toFun := coconeFun F j map_one' := by apply Quot.sound; apply Relation.one map_mul' := by intros; apply Quot.sound; apply Relation.mul map_zero' := by apply Quot.sound; apply Relation.zero map_add' := by intros; apply Quot.sound; apply Relation.add } @[simp] theorem cocone_naturality {j j' : J} (f : j ⟶ j') : F.map f ≫ coconeMorphism F j' = coconeMorphism F j := by ext apply Quot.sound
apply Relation.map @[simp] theorem cocone_naturality_components (j j' : J) (f : j ⟶ j') (x : F.obj j) : (coconeMorphism F j') (F.map f x) = (coconeMorphism F j) x := by
Mathlib/Algebra/Category/Ring/Colimits.lean
199
203
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Data.Vector.Basic /-! # The `zipWith` operation on vectors. -/ namespace List namespace Vector section ZipWith variable {α β γ : Type*} {n : ℕ} (f : α → β → γ) /-- Apply the function `f : α → β → γ` to each corresponding pair of elements from two vectors. -/ def zipWith : Vector α n → Vector β n → Vector γ n := fun x y => ⟨List.zipWith f x.1 y.1, by simp⟩ @[simp] theorem zipWith_toList (x : Vector α n) (y : Vector β n) : (Vector.zipWith f x y).toList = List.zipWith f x.toList y.toList := rfl @[simp] theorem zipWith_get (x : Vector α n) (y : Vector β n) (i) : (Vector.zipWith f x y).get i = f (x.get i) (y.get i) := by dsimp only [Vector.zipWith, Vector.get] simp @[simp] theorem zipWith_tail (x : Vector α n) (y : Vector β n) : (Vector.zipWith f x y).tail = Vector.zipWith f x.tail y.tail := by ext simp [get_tail]
@[to_additive] theorem prod_mul_prod_eq_prod_zipWith [CommMonoid α] (x y : Vector α n) : x.toList.prod * y.toList.prod = (Vector.zipWith (· * ·) x y).toList.prod := List.prod_mul_prod_eq_prod_zipWith_of_length_eq x.toList y.toList
Mathlib/Data/Vector/Zip.lean
40
43
/- 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.BoxIntegral.Partition.Basic /-! # Split a box along one or more hyperplanes ## Main definitions A hyperplane `{x : ι → ℝ | x i = a}` splits a rectangular box `I : BoxIntegral.Box ι` into two smaller boxes. If `a ∉ Ioo (I.lower i, I.upper i)`, then one of these boxes is empty, so it is not a box in the sense of `BoxIntegral.Box`. We introduce the following definitions. * `BoxIntegral.Box.splitLower I i a` and `BoxIntegral.Box.splitUpper I i a` are these boxes (as `WithBot (BoxIntegral.Box ι)`); * `BoxIntegral.Prepartition.split I i a` is the partition of `I` made of these two boxes (or of one box `I` if one of these boxes is empty); * `BoxIntegral.Prepartition.splitMany I s`, where `s : Finset (ι × ℝ)` is a finite set of hyperplanes `{x : ι → ℝ | x i = a}` encoded as pairs `(i, a)`, is the partition of `I` made by cutting it along all the hyperplanes in `s`. ## Main results The main result `BoxIntegral.Prepartition.exists_iUnion_eq_diff` says that any prepartition `π` of `I` admits a prepartition `π'` of `I` that covers exactly `I \ π.iUnion`. One of these prepartitions is available as `BoxIntegral.Prepartition.compl`. ## Tags rectangular box, partition, hyperplane -/ noncomputable section open Function Set Filter namespace BoxIntegral variable {ι M : Type*} {n : ℕ} namespace Box variable {I : Box ι} {i : ι} {x : ℝ} {y : ι → ℝ} open scoped Classical in /-- Given a box `I` and `x ∈ (I.lower i, I.upper i)`, the hyperplane `{y : ι → ℝ | y i = x}` splits `I` into two boxes. `BoxIntegral.Box.splitLower I i x` is the box `I ∩ {y | y i ≤ x}` (if it is nonempty). As usual, we represent a box that may be empty as `WithBot (BoxIntegral.Box ι)`. -/ def splitLower (I : Box ι) (i : ι) (x : ℝ) : WithBot (Box ι) := mk' I.lower (update I.upper i (min x (I.upper i))) @[simp] theorem coe_splitLower : (splitLower I i x : Set (ι → ℝ)) = ↑I ∩ { y | y i ≤ x } := by rw [splitLower, coe_mk'] ext y simp only [mem_univ_pi, mem_Ioc, mem_inter_iff, mem_coe, mem_setOf_eq, forall_and, ← Pi.le_def, le_update_iff, le_min_iff, and_assoc, and_forall_ne (p := fun j => y j ≤ upper I j) i, mem_def] rw [and_comm (a := y i ≤ x)] theorem splitLower_le : I.splitLower i x ≤ I := withBotCoe_subset_iff.1 <| by simp @[simp] theorem splitLower_eq_bot {i x} : I.splitLower i x = ⊥ ↔ x ≤ I.lower i := by classical rw [splitLower, mk'_eq_bot, exists_update_iff I.upper fun j y => y ≤ I.lower j] simp [(I.lower_lt_upper _).not_le] @[simp] theorem splitLower_eq_self : I.splitLower i x = I ↔ I.upper i ≤ x := by simp [splitLower, update_eq_iff] theorem splitLower_def [DecidableEq ι] {i x} (h : x ∈ Ioo (I.lower i) (I.upper i)) (h' : ∀ j, I.lower j < update I.upper i x j := (forall_update_iff I.upper fun j y => I.lower j < y).2 ⟨h.1, fun _ _ => I.lower_lt_upper _⟩) : I.splitLower i x = (⟨I.lower, update I.upper i x, h'⟩ : Box ι) := by simp +unfoldPartialApp only [splitLower, mk'_eq_coe, min_eq_left h.2.le, update, and_self] open scoped Classical in /-- Given a box `I` and `x ∈ (I.lower i, I.upper i)`, the hyperplane `{y : ι → ℝ | y i = x}` splits `I` into two boxes. `BoxIntegral.Box.splitUpper I i x` is the box `I ∩ {y | x < y i}` (if it is nonempty). As usual, we represent a box that may be empty as `WithBot (BoxIntegral.Box ι)`. -/ def splitUpper (I : Box ι) (i : ι) (x : ℝ) : WithBot (Box ι) := mk' (update I.lower i (max x (I.lower i))) I.upper @[simp] theorem coe_splitUpper : (splitUpper I i x : Set (ι → ℝ)) = ↑I ∩ { y | x < y i } := by classical rw [splitUpper, coe_mk'] ext y simp only [mem_univ_pi, mem_Ioc, mem_inter_iff, mem_coe, mem_setOf_eq, forall_and, forall_update_iff I.lower fun j z => z < y j, max_lt_iff, and_assoc (a := x < y i), and_forall_ne (p := fun j => lower I j < y j) i, mem_def] exact and_comm theorem splitUpper_le : I.splitUpper i x ≤ I := withBotCoe_subset_iff.1 <| by simp @[simp] theorem splitUpper_eq_bot {i x} : I.splitUpper i x = ⊥ ↔ I.upper i ≤ x := by classical rw [splitUpper, mk'_eq_bot, exists_update_iff I.lower fun j y => I.upper j ≤ y] simp [(I.lower_lt_upper _).not_le] @[simp] theorem splitUpper_eq_self : I.splitUpper i x = I ↔ x ≤ I.lower i := by simp [splitUpper, update_eq_iff] theorem splitUpper_def [DecidableEq ι] {i x} (h : x ∈ Ioo (I.lower i) (I.upper i)) (h' : ∀ j, update I.lower i x j < I.upper j := (forall_update_iff I.lower fun j y => y < I.upper j).2 ⟨h.2, fun _ _ => I.lower_lt_upper _⟩) : I.splitUpper i x = (⟨update I.lower i x, I.upper, h'⟩ : Box ι) := by simp +unfoldPartialApp only [splitUpper, mk'_eq_coe, max_eq_left h.1.le, update, and_self] theorem disjoint_splitLower_splitUpper (I : Box ι) (i : ι) (x : ℝ) : Disjoint (I.splitLower i x) (I.splitUpper i x) := by rw [← disjoint_withBotCoe, coe_splitLower, coe_splitUpper] refine (Disjoint.inf_left' _ ?_).inf_right' _ rw [Set.disjoint_left] exact fun y (hle : y i ≤ x) hlt => not_lt_of_le hle hlt theorem splitLower_ne_splitUpper (I : Box ι) (i : ι) (x : ℝ) : I.splitLower i x ≠ I.splitUpper i x := by rcases le_or_lt x (I.lower i) with h | _ · rw [splitUpper_eq_self.2 h, splitLower_eq_bot.2 h] exact WithBot.bot_ne_coe · refine (disjoint_splitLower_splitUpper I i x).ne ?_ rwa [Ne, splitLower_eq_bot, not_le] end Box namespace Prepartition variable {I J : Box ι} {i : ι} {x : ℝ} open scoped Classical in /-- The partition of `I : Box ι` into the boxes `I ∩ {y | y ≤ x i}` and `I ∩ {y | x i < y}`. One of these boxes can be empty, then this partition is just the single-box partition `⊤`. -/ def split (I : Box ι) (i : ι) (x : ℝ) : Prepartition I := ofWithBot {I.splitLower i x, I.splitUpper i x} (by simp only [Finset.mem_insert, Finset.mem_singleton] rintro J (rfl | rfl) exacts [Box.splitLower_le, Box.splitUpper_le]) (by simp only [Finset.coe_insert, Finset.coe_singleton, true_and, Set.mem_singleton_iff, pairwise_insert_of_symmetric symmetric_disjoint, pairwise_singleton] rintro J rfl - exact I.disjoint_splitLower_splitUpper i x) @[simp] theorem mem_split_iff : J ∈ split I i x ↔ ↑J = I.splitLower i x ∨ ↑J = I.splitUpper i x := by simp [split] theorem mem_split_iff' : J ∈ split I i x ↔ (J : Set (ι → ℝ)) = ↑I ∩ { y | y i ≤ x } ∨ (J : Set (ι → ℝ)) = ↑I ∩ { y | x < y i } := by simp [mem_split_iff, ← Box.withBotCoe_inj] @[simp] theorem iUnion_split (I : Box ι) (i : ι) (x : ℝ) : (split I i x).iUnion = I := by simp [split, ← inter_union_distrib_left, ← setOf_or, le_or_lt] theorem isPartitionSplit (I : Box ι) (i : ι) (x : ℝ) : IsPartition (split I i x) := isPartition_iff_iUnion_eq.2 <| iUnion_split I i x theorem sum_split_boxes {M : Type*} [AddCommMonoid M] (I : Box ι) (i : ι) (x : ℝ) (f : Box ι → M) : (∑ J ∈ (split I i x).boxes, f J) = (I.splitLower i x).elim' 0 f + (I.splitUpper i x).elim' 0 f := by classical rw [split, sum_ofWithBot, Finset.sum_pair (I.splitLower_ne_splitUpper i x)] /-- If `x ∉ (I.lower i, I.upper i)`, then the hyperplane `{y | y i = x}` does not split `I`. -/ theorem split_of_not_mem_Ioo (h : x ∉ Ioo (I.lower i) (I.upper i)) : split I i x = ⊤ := by refine ((isPartitionTop I).eq_of_boxes_subset fun J hJ => ?_).symm rcases mem_top.1 hJ with rfl; clear hJ rw [mem_boxes, mem_split_iff] rw [mem_Ioo, not_and_or, not_lt, not_lt] at h cases h <;> [right; left] · rwa [eq_comm, Box.splitUpper_eq_self] · rwa [eq_comm, Box.splitLower_eq_self] theorem coe_eq_of_mem_split_of_mem_le {y : ι → ℝ} (h₁ : J ∈ split I i x) (h₂ : y ∈ J) (h₃ : y i ≤ x) : (J : Set (ι → ℝ)) = ↑I ∩ { y | y i ≤ x } := by refine (mem_split_iff'.1 h₁).resolve_right fun H => ?_ rw [← Box.mem_coe, H] at h₂ exact h₃.not_lt h₂.2 theorem coe_eq_of_mem_split_of_lt_mem {y : ι → ℝ} (h₁ : J ∈ split I i x) (h₂ : y ∈ J) (h₃ : x < y i) : (J : Set (ι → ℝ)) = ↑I ∩ { y | x < y i } := by refine (mem_split_iff'.1 h₁).resolve_left fun H => ?_ rw [← Box.mem_coe, H] at h₂ exact h₃.not_le h₂.2 @[simp] theorem restrict_split (h : I ≤ J) (i : ι) (x : ℝ) : (split J i x).restrict I = split I i x := by refine ((isPartitionSplit J i x).restrict h).eq_of_boxes_subset ?_ simp only [Finset.subset_iff, mem_boxes, mem_restrict', exists_prop, mem_split_iff'] have : ∀ s, (I ∩ s : Set (ι → ℝ)) ⊆ J := fun s => inter_subset_left.trans h rintro J₁ ⟨J₂, H₂ | H₂, H₁⟩ <;> [left; right] <;> simp [H₁, H₂, inter_left_comm (I : Set (ι → ℝ)), this] theorem inf_split (π : Prepartition I) (i : ι) (x : ℝ) : π ⊓ split I i x = π.biUnion fun J => split J i x := biUnion_congr_of_le rfl fun _ hJ => restrict_split hJ i x /-- Split a box along many hyperplanes `{y | y i = x}`; each hyperplane is given by the pair `(i x)`. -/ def splitMany (I : Box ι) (s : Finset (ι × ℝ)) : Prepartition I := s.inf fun p => split I p.1 p.2 @[simp] theorem splitMany_empty (I : Box ι) : splitMany I ∅ = ⊤ := Finset.inf_empty open scoped Classical in @[simp] theorem splitMany_insert (I : Box ι) (s : Finset (ι × ℝ)) (p : ι × ℝ) : splitMany I (insert p s) = splitMany I s ⊓ split I p.1 p.2 := by rw [splitMany, Finset.inf_insert, inf_comm, splitMany] theorem splitMany_le_split (I : Box ι) {s : Finset (ι × ℝ)} {p : ι × ℝ} (hp : p ∈ s) : splitMany I s ≤ split I p.1 p.2 := Finset.inf_le hp theorem isPartition_splitMany (I : Box ι) (s : Finset (ι × ℝ)) : IsPartition (splitMany I s) := by classical exact Finset.induction_on s (by simp only [splitMany_empty, isPartitionTop]) fun a s _ hs => by simpa only [splitMany_insert, inf_split] using hs.biUnion fun J _ => isPartitionSplit _ _ _ @[simp] theorem iUnion_splitMany (I : Box ι) (s : Finset (ι × ℝ)) : (splitMany I s).iUnion = I := (isPartition_splitMany I s).iUnion_eq theorem inf_splitMany {I : Box ι} (π : Prepartition I) (s : Finset (ι × ℝ)) : π ⊓ splitMany I s = π.biUnion fun J => splitMany J s := by classical induction' s using Finset.induction_on with p s _ ihp · simp · simp_rw [splitMany_insert, ← inf_assoc, ihp, inf_split, biUnion_assoc] open scoped Classical in /-- Let `s : Finset (ι × ℝ)` be a set of hyperplanes `{x : ι → ℝ | x i = r}` in `ι → ℝ` encoded as pairs `(i, r)`. Suppose that this set contains all faces of a box `J`. The hyperplanes of `s` split a box `I` into subboxes. Let `Js` be one of them. If `J` and `Js` have nonempty intersection, then `Js` is a subbox of `J`. -/ theorem not_disjoint_imp_le_of_subset_of_mem_splitMany {I J Js : Box ι} {s : Finset (ι × ℝ)} (H : ∀ i, {(i, J.lower i), (i, J.upper i)} ⊆ s) (HJs : Js ∈ splitMany I s) (Hn : ¬Disjoint (J : WithBot (Box ι)) Js) : Js ≤ J := by simp only [Finset.insert_subset_iff, Finset.singleton_subset_iff] at H rcases Box.not_disjoint_coe_iff_nonempty_inter.mp Hn with ⟨x, hx, hxs⟩ refine fun y hy i => ⟨?_, ?_⟩ · rcases splitMany_le_split I (H i).1 HJs with ⟨Jl, Hmem : Jl ∈ split I i (J.lower i), Hle⟩ have := Hle hxs rw [← Box.coe_subset_coe, coe_eq_of_mem_split_of_lt_mem Hmem this (hx i).1] at Hle exact (Hle hy).2 · rcases splitMany_le_split I (H i).2 HJs with ⟨Jl, Hmem : Jl ∈ split I i (J.upper i), Hle⟩ have := Hle hxs rw [← Box.coe_subset_coe, coe_eq_of_mem_split_of_mem_le Hmem this (hx i).2] at Hle exact (Hle hy).2 section Finite variable [Finite ι] /-- Let `s` be a finite set of boxes in `ℝⁿ = ι → ℝ`. Then there exists a finite set `t₀` of hyperplanes (namely, the set of all hyperfaces of boxes in `s`) such that for any `t ⊇ t₀` and any box `I` in `ℝⁿ` the following holds. The hyperplanes from `t` split `I` into subboxes. Let `J'` be one of them, and let `J` be one of the boxes in `s`. If these boxes have a nonempty intersection, then `J' ≤ J`. -/ theorem eventually_not_disjoint_imp_le_of_mem_splitMany (s : Finset (Box ι)) : ∀ᶠ t : Finset (ι × ℝ) in atTop, ∀ (I : Box ι), ∀ J ∈ s, ∀ J' ∈ splitMany I t, ¬Disjoint (J : WithBot (Box ι)) J' → J' ≤ J := by classical cases nonempty_fintype ι refine eventually_atTop.2 ⟨s.biUnion fun J => Finset.univ.biUnion fun i => {(i, J.lower i), (i, J.upper i)}, fun t ht I J hJ J' hJ' => not_disjoint_imp_le_of_subset_of_mem_splitMany (fun i => ?_) hJ'⟩ exact fun p hp => ht (Finset.mem_biUnion.2 ⟨J, hJ, Finset.mem_biUnion.2 ⟨i, Finset.mem_univ _, hp⟩⟩) theorem eventually_splitMany_inf_eq_filter (π : Prepartition I) : ∀ᶠ t : Finset (ι × ℝ) in atTop, π ⊓ splitMany I t = (splitMany I t).filter fun J => ↑J ⊆ π.iUnion := by refine (eventually_not_disjoint_imp_le_of_mem_splitMany π.boxes).mono fun t ht => ?_ refine le_antisymm ((biUnion_le_iff _).2 fun J hJ => ?_) (le_inf (fun J hJ => ?_) (filter_le _ _)) · refine ofWithBot_mono ?_ simp only [Finset.mem_image, exists_prop, mem_boxes, mem_filter] rintro _ ⟨J₁, h₁, rfl⟩ hne refine ⟨_, ⟨J₁, ⟨h₁, Subset.trans ?_ (π.subset_iUnion hJ)⟩, rfl⟩, le_rfl⟩ exact ht I J hJ J₁ h₁ (mt disjoint_iff.1 hne) · rw [mem_filter] at hJ rcases Set.mem_iUnion₂.1 (hJ.2 J.upper_mem) with ⟨J', hJ', hmem⟩ refine ⟨J', hJ', ht I _ hJ' _ hJ.1 <| Box.not_disjoint_coe_iff_nonempty_inter.2 ?_⟩ exact ⟨J.upper, hmem, J.upper_mem⟩ theorem exists_splitMany_inf_eq_filter_of_finite (s : Set (Prepartition I)) (hs : s.Finite) : ∃ t : Finset (ι × ℝ), ∀ π ∈ s, π ⊓ splitMany I t = (splitMany I t).filter fun J => ↑J ⊆ π.iUnion := haveI := fun π (_ : π ∈ s) => eventually_splitMany_inf_eq_filter π (hs.eventually_all.2 this).exists /-- If `π` is a partition of `I`, then there exists a finite set `s` of hyperplanes such that `splitMany I s ≤ π`. -/ theorem IsPartition.exists_splitMany_le {I : Box ι} {π : Prepartition I} (h : IsPartition π) : ∃ s, splitMany I s ≤ π := by refine (eventually_splitMany_inf_eq_filter π).exists.imp fun s hs => ?_ rwa [h.iUnion_eq, filter_of_true, inf_eq_right] at hs exact fun J hJ => le_of_mem _ hJ /-- For every prepartition `π` of `I` there exists a prepartition that covers exactly `I \ π.iUnion`. -/ theorem exists_iUnion_eq_diff (π : Prepartition I) : ∃ π' : Prepartition I, π'.iUnion = ↑I \ π.iUnion := by rcases π.eventually_splitMany_inf_eq_filter.exists with ⟨s, hs⟩ use (splitMany I s).filter fun J => ¬(J : Set (ι → ℝ)) ⊆ π.iUnion simp [← hs] /-- If `π` is a prepartition of `I`, then `π.compl` is a prepartition of `I` such that `π.compl.iUnion = I \ π.iUnion`. -/ def compl (π : Prepartition I) : Prepartition I := π.exists_iUnion_eq_diff.choose @[simp] theorem iUnion_compl (π : Prepartition I) : π.compl.iUnion = ↑I \ π.iUnion := π.exists_iUnion_eq_diff.choose_spec /-- Since the definition of `BoxIntegral.Prepartition.compl` uses `Exists.choose`, the result depends only on `π.iUnion`. -/ theorem compl_congr {π₁ π₂ : Prepartition I} (h : π₁.iUnion = π₂.iUnion) : π₁.compl = π₂.compl := by dsimp only [compl] congr 1 rw [h] theorem IsPartition.compl_eq_bot {π : Prepartition I} (h : IsPartition π) : π.compl = ⊥ := by rw [← iUnion_eq_empty, iUnion_compl, h.iUnion_eq, diff_self] @[simp] theorem compl_top : (⊤ : Prepartition I).compl = ⊥ := (isPartitionTop I).compl_eq_bot end Finite end Prepartition end BoxIntegral
Mathlib/Analysis/BoxIntegral/Partition/Split.lean
381
382
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Chris Hughes -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.FieldTheory.Minpoly.Basic import Mathlib.RingTheory.Adjoin.Basic import Mathlib.RingTheory.FinitePresentation import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.Ideal.Quotient.Noetherian import Mathlib.RingTheory.PowerBasis import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.RingTheory.Polynomial.Quotient /-! # Adjoining roots of polynomials This file defines the commutative ring `AdjoinRoot f`, the ring R[X]/(f) obtained from a commutative ring `R` and a polynomial `f : R[X]`. If furthermore `R` is a field and `f` is irreducible, the field structure on `AdjoinRoot f` is constructed. We suggest stating results on `IsAdjoinRoot` instead of `AdjoinRoot` to achieve higher generality, since `IsAdjoinRoot` works for all different constructions of `R[α]` including `AdjoinRoot f = R[X]/(f)` itself. ## Main definitions and results The main definitions are in the `AdjoinRoot` namespace. * `mk f : R[X] →+* AdjoinRoot f`, the natural ring homomorphism. * `of f : R →+* AdjoinRoot f`, the natural ring homomorphism. * `root f : AdjoinRoot f`, the image of X in R[X]/(f). * `lift (i : R →+* S) (x : S) (h : f.eval₂ i x = 0) : (AdjoinRoot f) →+* S`, the ring homomorphism from R[X]/(f) to S extending `i : R →+* S` and sending `X` to `x`. * `lift_hom (x : S) (hfx : aeval x f = 0) : AdjoinRoot f →ₐ[R] S`, the algebra homomorphism from R[X]/(f) to S extending `algebraMap R S` and sending `X` to `x` * `equiv : (AdjoinRoot f →ₐ[F] E) ≃ {x // x ∈ f.aroots E}` a bijection between algebra homomorphisms from `AdjoinRoot` and roots of `f` in `S` -/ noncomputable section open Polynomial universe u v w variable {R : Type u} {S : Type v} {K : Type w} open Polynomial Ideal /-- Adjoin a root of a polynomial `f` to a commutative ring `R`. We define the new ring as the quotient of `R[X]` by the principal ideal generated by `f`. -/ def AdjoinRoot [CommRing R] (f : R[X]) : Type u := Polynomial R ⧸ (span {f} : Ideal R[X]) namespace AdjoinRoot section CommRing variable [CommRing R] (f : R[X]) instance instCommRing : CommRing (AdjoinRoot f) := Ideal.Quotient.commRing _ instance : Inhabited (AdjoinRoot f) := ⟨0⟩ instance : DecidableEq (AdjoinRoot f) := Classical.decEq _ protected theorem nontrivial [IsDomain R] (h : degree f ≠ 0) : Nontrivial (AdjoinRoot f) := Ideal.Quotient.nontrivial (by simp_rw [Ne, span_singleton_eq_top, Polynomial.isUnit_iff, not_exists, not_and] rintro x hx rfl exact h (degree_C hx.ne_zero)) /-- Ring homomorphism from `R[x]` to `AdjoinRoot f` sending `X` to the `root`. -/ def mk : R[X] →+* AdjoinRoot f := Ideal.Quotient.mk _ @[elab_as_elim] theorem induction_on {C : AdjoinRoot f → Prop} (x : AdjoinRoot f) (ih : ∀ p : R[X], C (mk f p)) : C x := Quotient.inductionOn' x ih /-- Embedding of the original ring `R` into `AdjoinRoot f`. -/ def of : R →+* AdjoinRoot f := (mk f).comp C instance instSMulAdjoinRoot [DistribSMul S R] [IsScalarTower S R R] : SMul S (AdjoinRoot f) := Submodule.Quotient.instSMul' _ instance [DistribSMul S R] [IsScalarTower S R R] : DistribSMul S (AdjoinRoot f) := Submodule.Quotient.distribSMul' _ @[simp] theorem smul_mk [DistribSMul S R] [IsScalarTower S R R] (a : S) (x : R[X]) : a • mk f x = mk f (a • x) := rfl theorem smul_of [DistribSMul S R] [IsScalarTower S R R] (a : S) (x : R) : a • of f x = of f (a • x) := by rw [of, RingHom.comp_apply, RingHom.comp_apply, smul_mk, smul_C] instance (R₁ R₂ : Type*) [SMul R₁ R₂] [DistribSMul R₁ R] [DistribSMul R₂ R] [IsScalarTower R₁ R R] [IsScalarTower R₂ R R] [IsScalarTower R₁ R₂ R] (f : R[X]) : IsScalarTower R₁ R₂ (AdjoinRoot f) := Submodule.Quotient.isScalarTower _ _ instance (R₁ R₂ : Type*) [DistribSMul R₁ R] [DistribSMul R₂ R] [IsScalarTower R₁ R R] [IsScalarTower R₂ R R] [SMulCommClass R₁ R₂ R] (f : R[X]) : SMulCommClass R₁ R₂ (AdjoinRoot f) := Submodule.Quotient.smulCommClass _ _ instance isScalarTower_right [DistribSMul S R] [IsScalarTower S R R] : IsScalarTower S (AdjoinRoot f) (AdjoinRoot f) := Ideal.Quotient.isScalarTower_right instance [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (f : R[X]) : DistribMulAction S (AdjoinRoot f) := Submodule.Quotient.distribMulAction' _ /-- `R[x]/(f)` is `R`-algebra -/ @[stacks 09FX "second part"] instance [CommSemiring S] [Algebra S R] : Algebra S (AdjoinRoot f) := Ideal.Quotient.algebra S @[simp] theorem algebraMap_eq : algebraMap R (AdjoinRoot f) = of f := rfl variable (S) in theorem algebraMap_eq' [CommSemiring S] [Algebra S R] : algebraMap S (AdjoinRoot f) = (of f).comp (algebraMap S R) := rfl theorem finiteType : Algebra.FiniteType R (AdjoinRoot f) := (Algebra.FiniteType.polynomial R).of_surjective _ (Ideal.Quotient.mkₐ_surjective R _) theorem finitePresentation : Algebra.FinitePresentation R (AdjoinRoot f) := (Algebra.FinitePresentation.polynomial R).quotient (Submodule.fg_span_singleton f) /-- The adjoined root. -/ def root : AdjoinRoot f := mk f X variable {f} instance hasCoeT : CoeTC R (AdjoinRoot f) := ⟨of f⟩ /-- Two `R`-`AlgHom` from `AdjoinRoot f` to the same `R`-algebra are the same iff they agree on `root f`. -/ @[ext] theorem algHom_ext [Semiring S] [Algebra R S] {g₁ g₂ : AdjoinRoot f →ₐ[R] S} (h : g₁ (root f) = g₂ (root f)) : g₁ = g₂ := Ideal.Quotient.algHom_ext R <| Polynomial.algHom_ext h @[simp] theorem mk_eq_mk {g h : R[X]} : mk f g = mk f h ↔ f ∣ g - h := Ideal.Quotient.eq.trans Ideal.mem_span_singleton @[simp] theorem mk_eq_zero {g : R[X]} : mk f g = 0 ↔ f ∣ g := mk_eq_mk.trans <| by rw [sub_zero] @[simp] theorem mk_self : mk f f = 0 := Quotient.sound' <| QuotientAddGroup.leftRel_apply.mpr (mem_span_singleton.2 <| by simp) @[simp] theorem mk_C (x : R) : mk f (C x) = x := rfl @[simp] theorem mk_X : mk f X = root f := rfl theorem mk_ne_zero_of_degree_lt (hf : Monic f) {g : R[X]} (h0 : g ≠ 0) (hd : degree g < degree f) : mk f g ≠ 0 := mk_eq_zero.not.2 <| hf.not_dvd_of_degree_lt h0 hd theorem mk_ne_zero_of_natDegree_lt (hf : Monic f) {g : R[X]} (h0 : g ≠ 0) (hd : natDegree g < natDegree f) : mk f g ≠ 0 := mk_eq_zero.not.2 <| hf.not_dvd_of_natDegree_lt h0 hd @[simp] theorem aeval_eq (p : R[X]) : aeval (root f) p = mk f p := Polynomial.induction_on p (fun x => by rw [aeval_C] rfl) (fun p q ihp ihq => by rw [map_add, RingHom.map_add, ihp, ihq]) fun n x _ => by rw [map_mul, aeval_C, map_pow, aeval_X, RingHom.map_mul, mk_C, RingHom.map_pow, mk_X] rfl theorem adjoinRoot_eq_top : Algebra.adjoin R ({root f} : Set (AdjoinRoot f)) = ⊤ := by refine Algebra.eq_top_iff.2 fun x => ?_ induction x using AdjoinRoot.induction_on with | ih p => exact (Algebra.adjoin_singleton_eq_range_aeval R (root f)).symm ▸ ⟨p, aeval_eq p⟩ @[simp] theorem eval₂_root (f : R[X]) : f.eval₂ (of f) (root f) = 0 := by rw [← algebraMap_eq, ← aeval_def, aeval_eq, mk_self] theorem isRoot_root (f : R[X]) : IsRoot (f.map (of f)) (root f) := by rw [IsRoot, eval_map, eval₂_root] theorem isAlgebraic_root (hf : f ≠ 0) : IsAlgebraic R (root f) := ⟨f, hf, eval₂_root f⟩ theorem of.injective_of_degree_ne_zero [IsDomain R] (hf : f.degree ≠ 0) : Function.Injective (AdjoinRoot.of f) := by rw [injective_iff_map_eq_zero] intro p hp rw [AdjoinRoot.of, RingHom.comp_apply, AdjoinRoot.mk_eq_zero] at hp by_cases h : f = 0 · exact C_eq_zero.mp (eq_zero_of_zero_dvd (by rwa [h] at hp)) · contrapose! hf with h_contra rw [← degree_C h_contra] apply le_antisymm (degree_le_of_dvd hp (by rwa [Ne, C_eq_zero])) _ rwa [degree_C h_contra, zero_le_degree_iff] variable [CommRing S] /-- Lift a ring homomorphism `i : R →+* S` to `AdjoinRoot f →+* S`. -/ def lift (i : R →+* S) (x : S) (h : f.eval₂ i x = 0) : AdjoinRoot f →+* S := by apply Ideal.Quotient.lift _ (eval₂RingHom i x) intro g H rcases mem_span_singleton.1 H with ⟨y, hy⟩ rw [hy, RingHom.map_mul, coe_eval₂RingHom, h, zero_mul] variable {i : R →+* S} {a : S} (h : f.eval₂ i a = 0) @[simp] theorem lift_mk (g : R[X]) : lift i a h (mk f g) = g.eval₂ i a := Ideal.Quotient.lift_mk _ _ _ @[simp] theorem lift_root : lift i a h (root f) = a := by rw [root, lift_mk, eval₂_X] @[simp] theorem lift_of {x : R} : lift i a h x = i x := by rw [← mk_C x, lift_mk, eval₂_C] @[simp] theorem lift_comp_of : (lift i a h).comp (of f) = i := RingHom.ext fun _ => @lift_of _ _ _ _ _ _ _ h _ variable (f) [Algebra R S] /-- Produce an algebra homomorphism `AdjoinRoot f →ₐ[R] S` sending `root f` to a root of `f` in `S`. -/ def liftHom (x : S) (hfx : aeval x f = 0) : AdjoinRoot f →ₐ[R] S := { lift (algebraMap R S) x hfx with commutes' := fun r => show lift _ _ hfx r = _ from lift_of hfx } @[simp] theorem coe_liftHom (x : S) (hfx : aeval x f = 0) : (liftHom f x hfx : AdjoinRoot f →+* S) = lift (algebraMap R S) x hfx := rfl @[simp] theorem aeval_algHom_eq_zero (ϕ : AdjoinRoot f →ₐ[R] S) : aeval (ϕ (root f)) f = 0 := by have h : ϕ.toRingHom.comp (of f) = algebraMap R S := RingHom.ext_iff.mpr ϕ.commutes rw [aeval_def, ← h, ← RingHom.map_zero ϕ.toRingHom, ← eval₂_root f, hom_eval₂] rfl @[simp] theorem liftHom_eq_algHom (f : R[X]) (ϕ : AdjoinRoot f →ₐ[R] S) : liftHom f (ϕ (root f)) (aeval_algHom_eq_zero f ϕ) = ϕ := by suffices AlgHom.equalizer ϕ (liftHom f (ϕ (root f)) (aeval_algHom_eq_zero f ϕ)) = ⊤ by exact (AlgHom.ext fun x => (SetLike.ext_iff.mp this x).mpr Algebra.mem_top).symm rw [eq_top_iff, ← adjoinRoot_eq_top, Algebra.adjoin_le_iff, Set.singleton_subset_iff] exact (@lift_root _ _ _ _ _ _ _ (aeval_algHom_eq_zero f ϕ)).symm variable (hfx : aeval a f = 0) @[simp] theorem liftHom_mk {g : R[X]} : liftHom f a hfx (mk f g) = aeval a g := lift_mk hfx g @[simp] theorem liftHom_root : liftHom f a hfx (root f) = a := lift_root hfx @[simp] theorem liftHom_of {x : R} : liftHom f a hfx (of f x) = algebraMap _ _ x := lift_of hfx section AdjoinInv @[simp] theorem root_isInv (r : R) : of _ r * root (C r * X - 1) = 1 := by convert sub_eq_zero.1 ((eval₂_sub _).symm.trans <| eval₂_root <| C r * X - 1) <;> simp only [eval₂_mul, eval₂_C, eval₂_X, eval₂_one] theorem algHom_subsingleton {S : Type*} [CommRing S] [Algebra R S] {r : R} : Subsingleton (AdjoinRoot (C r * X - 1) →ₐ[R] S) := ⟨fun f g => algHom_ext (@inv_unique _ _ (algebraMap R S r) _ _ (by rw [← f.commutes, ← map_mul, algebraMap_eq, root_isInv, map_one]) (by rw [← g.commutes, ← map_mul, algebraMap_eq, root_isInv, map_one]))⟩ end AdjoinInv section Prime variable {f} theorem isDomain_of_prime (hf : Prime f) : IsDomain (AdjoinRoot f) := (Ideal.Quotient.isDomain_iff_prime (span {f} : Ideal R[X])).mpr <| (Ideal.span_singleton_prime hf.ne_zero).mpr hf theorem noZeroSMulDivisors_of_prime_of_degree_ne_zero [IsDomain R] (hf : Prime f) (hf' : f.degree ≠ 0) : NoZeroSMulDivisors R (AdjoinRoot f) := haveI := isDomain_of_prime hf NoZeroSMulDivisors.iff_algebraMap_injective.mpr (of.injective_of_degree_ne_zero hf') end Prime end CommRing section Irreducible variable [Field K] {f : K[X]} instance span_maximal_of_irreducible [Fact (Irreducible f)] : (span {f}).IsMaximal := PrincipalIdealRing.isMaximal_of_irreducible <| Fact.out noncomputable instance instGroupWithZero [Fact (Irreducible f)] : GroupWithZero (AdjoinRoot f) := Quotient.groupWithZero (span {f} : Ideal K[X]) /-- If `R` is a field and `f` is irreducible, then `AdjoinRoot f` is a field -/ @[stacks 09FX "first part, see also 09FI"] noncomputable instance instField [Fact (Irreducible f)] : Field (AdjoinRoot f) where __ := instCommRing _ __ := instGroupWithZero nnqsmul := (· • ·) qsmul := (· • ·) nnratCast_def q := by rw [← map_natCast (of f), ← map_natCast (of f), ← map_div₀, ← NNRat.cast_def]; rfl ratCast_def q := by rw [← map_natCast (of f), ← map_intCast (of f), ← map_div₀, ← Rat.cast_def]; rfl nnqsmul_def q x := AdjoinRoot.induction_on f (C := fun y ↦ q • y = (of f) q * y) x fun p ↦ by simp only [smul_mk, of, RingHom.comp_apply, ← (mk f).map_mul, Polynomial.nnqsmul_eq_C_mul] qsmul_def q x := -- Porting note: I gave the explicit motive and changed `rw` to `simp`. AdjoinRoot.induction_on f (C := fun y ↦ q • y = (of f) q * y) x fun p ↦ by simp only [smul_mk, of, RingHom.comp_apply, ← (mk f).map_mul, Polynomial.qsmul_eq_C_mul] theorem coe_injective (h : degree f ≠ 0) : Function.Injective ((↑) : K → AdjoinRoot f) := have := AdjoinRoot.nontrivial f h (of f).injective theorem coe_injective' [Fact (Irreducible f)] : Function.Injective ((↑) : K → AdjoinRoot f) := (of f).injective variable (f) theorem mul_div_root_cancel [Fact (Irreducible f)] : (X - C (root f)) * ((f.map (of f)) / (X - C (root f))) = f.map (of f) := mul_div_eq_iff_isRoot.2 <| isRoot_root _ end Irreducible section IsNoetherianRing instance [CommRing R] [IsNoetherianRing R] {f : R[X]} : IsNoetherianRing (AdjoinRoot f) := Ideal.Quotient.isNoetherianRing _ end IsNoetherianRing section PowerBasis variable [CommRing R] {g : R[X]} theorem isIntegral_root' (hg : g.Monic) : IsIntegral R (root g) := ⟨g, hg, eval₂_root g⟩ /-- `AdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`. This is a well-defined right inverse to `AdjoinRoot.mk`, see `AdjoinRoot.mk_leftInverse`. -/ def modByMonicHom (hg : g.Monic) : AdjoinRoot g →ₗ[R] R[X] := (Submodule.liftQ _ (Polynomial.modByMonicHom g) fun f (hf : f ∈ (Ideal.span {g}).restrictScalars R) => (mem_ker_modByMonic hg).mpr (Ideal.mem_span_singleton.mp hf)).comp <| (Submodule.Quotient.restrictScalarsEquiv R (Ideal.span {g} : Ideal R[X])).symm.toLinearMap @[simp] theorem modByMonicHom_mk (hg : g.Monic) (f : R[X]) : modByMonicHom hg (mk g f) = f %ₘ g := rfl theorem mk_leftInverse (hg : g.Monic) : Function.LeftInverse (mk g) (modByMonicHom hg) := by intro f induction f using AdjoinRoot.induction_on rw [modByMonicHom_mk hg, mk_eq_mk, modByMonic_eq_sub_mul_div _ hg, sub_sub_cancel_left, dvd_neg] apply dvd_mul_right theorem mk_surjective : Function.Surjective (mk g) := Ideal.Quotient.mk_surjective /-- The elements `1, root g, ..., root g ^ (d - 1)` form a basis for `AdjoinRoot g`, where `g` is a monic polynomial of degree `d`. -/ def powerBasisAux' (hg : g.Monic) : Basis (Fin g.natDegree) R (AdjoinRoot g) := Basis.ofEquivFun { toFun := fun f i => (modByMonicHom hg f).coeff i invFun := fun c => mk g <| ∑ i : Fin g.natDegree, monomial i (c i) map_add' := fun f₁ f₂ => funext fun i => by simp only [(modByMonicHom hg).map_add, coeff_add, Pi.add_apply] map_smul' := fun f₁ f₂ => funext fun i => by simp only [(modByMonicHom hg).map_smul, coeff_smul, Pi.smul_apply, RingHom.id_apply] -- Porting note: another proof that I converted to tactic mode left_inv := by intro f induction f using AdjoinRoot.induction_on simp only [modByMonicHom_mk, sum_modByMonic_coeff hg degree_le_natDegree] refine (mk_eq_mk.mpr ?_).symm rw [modByMonic_eq_sub_mul_div _ hg, sub_sub_cancel] exact dvd_mul_right _ _ right_inv := fun x => funext fun i => by nontriviality R simp only [modByMonicHom_mk] rw [(modByMonic_eq_self_iff hg).mpr, finset_sum_coeff] · simp_rw [coeff_monomial, Fin.val_eq_val, Finset.sum_ite_eq', if_pos (Finset.mem_univ _)] · simp_rw [← C_mul_X_pow_eq_monomial] exact (degree_eq_natDegree <| hg.ne_zero).symm ▸ degree_sum_fin_lt _ } -- This lemma could be autogenerated by `@[simps]` but unfortunately that would require -- unfolding that causes a timeout. -- This lemma should have the simp tag but this causes a lint issue. theorem powerBasisAux'_repr_symm_apply (hg : g.Monic) (c : Fin g.natDegree →₀ R) : (powerBasisAux' hg).repr.symm c = mk g (∑ i : Fin _, monomial i (c i)) := rfl -- This lemma could be autogenerated by `@[simps]` but unfortunately that would require -- unfolding that causes a timeout. @[simp] theorem powerBasisAux'_repr_apply_to_fun (hg : g.Monic) (f : AdjoinRoot g) (i : Fin g.natDegree) : (powerBasisAux' hg).repr f i = (modByMonicHom hg f).coeff ↑i := rfl /-- The power basis `1, root g, ..., root g ^ (d - 1)` for `AdjoinRoot g`, where `g` is a monic polynomial of degree `d`. -/ @[simps] def powerBasis' (hg : g.Monic) : PowerBasis R (AdjoinRoot g) where gen := root g dim := g.natDegree basis := powerBasisAux' hg basis_eq_pow i := by simp only [powerBasisAux', Basis.coe_ofEquivFun, LinearEquiv.coe_symm_mk] rw [Finset.sum_eq_single i] · rw [Pi.single_eq_same, monomial_one_right_eq_X_pow, (mk g).map_pow, mk_X] · intro j _ hj rw [← monomial_zero_right _, Pi.single_eq_of_ne hj] -- Fix `DecidableEq` mismatch · intros have := Finset.mem_univ i contradiction lemma _root_.Polynomial.Monic.free_adjoinRoot (hg : g.Monic) : Module.Free R (AdjoinRoot g) := .of_basis (powerBasis' hg).basis lemma _root_.Polynomial.Monic.finite_adjoinRoot (hg : g.Monic) : Module.Finite R (AdjoinRoot g) := .of_basis (powerBasis' hg).basis /-- An unwrapped version of `AdjoinRoot.free_of_monic` for better discoverability. -/ lemma _root_.Polynomial.Monic.free_quotient (hg : g.Monic) : Module.Free R (R[X] ⧸ Ideal.span {g}) := hg.free_adjoinRoot /-- An unwrapped version of `AdjoinRoot.finite_of_monic` for better discoverability. -/ lemma _root_.Polynomial.Monic.finite_quotient (hg : g.Monic) : Module.Finite R (R[X] ⧸ Ideal.span {g}) := hg.finite_adjoinRoot variable [Field K] {f : K[X]} theorem isIntegral_root (hf : f ≠ 0) : IsIntegral K (root f) := (isAlgebraic_root hf).isIntegral theorem minpoly_root (hf : f ≠ 0) : minpoly K (root f) = f * C f.leadingCoeff⁻¹ := by have f'_monic : Monic _ := monic_mul_leadingCoeff_inv hf refine (minpoly.unique K _ f'_monic ?_ ?_).symm · rw [map_mul, aeval_eq, mk_self, zero_mul] intro q q_monic q_aeval have commutes : (lift (algebraMap K (AdjoinRoot f)) (root f) q_aeval).comp (mk q) = mk f := by ext · simp only [RingHom.comp_apply, mk_C, lift_of] rfl · simp only [RingHom.comp_apply, mk_X, lift_root] rw [degree_eq_natDegree f'_monic.ne_zero, degree_eq_natDegree q_monic.ne_zero, Nat.cast_le, natDegree_mul hf, natDegree_C, add_zero] · apply natDegree_le_of_dvd · have : mk f q = 0 := by rw [← commutes, RingHom.comp_apply, mk_self, RingHom.map_zero] exact mk_eq_zero.1 this · exact q_monic.ne_zero · rwa [Ne, C_eq_zero, inv_eq_zero, leadingCoeff_eq_zero] /-- The elements `1, root f, ..., root f ^ (d - 1)` form a basis for `AdjoinRoot f`, where `f` is an irreducible polynomial over a field of degree `d`. -/ def powerBasisAux (hf : f ≠ 0) : Basis (Fin f.natDegree) K (AdjoinRoot f) := by let f' := f * C f.leadingCoeff⁻¹ have deg_f' : f'.natDegree = f.natDegree := by rw [natDegree_mul hf, natDegree_C, add_zero] · rwa [Ne, C_eq_zero, inv_eq_zero, leadingCoeff_eq_zero] have minpoly_eq : minpoly K (root f) = f' := minpoly_root hf apply Basis.mk (v := fun i : Fin f.natDegree ↦ root f ^ i.val) · rw [← deg_f', ← minpoly_eq] exact linearIndependent_pow (root f) · rintro y - rw [← deg_f', ← minpoly_eq] apply (isIntegral_root hf).mem_span_pow obtain ⟨g⟩ := y use g rw [aeval_eq] rfl /-- The power basis `1, root f, ..., root f ^ (d - 1)` for `AdjoinRoot f`, where `f` is an irreducible polynomial over a field of degree `d`. -/ @[simps!] def powerBasis (hf : f ≠ 0) : PowerBasis K (AdjoinRoot f) where gen := root f dim := f.natDegree basis := powerBasisAux hf basis_eq_pow := by simp [powerBasisAux] theorem minpoly_powerBasis_gen (hf : f ≠ 0) : minpoly K (powerBasis hf).gen = f * C f.leadingCoeff⁻¹ := by rw [powerBasis_gen, minpoly_root hf] theorem minpoly_powerBasis_gen_of_monic (hf : f.Monic) (hf' : f ≠ 0 := hf.ne_zero) : minpoly K (powerBasis hf').gen = f := by rw [minpoly_powerBasis_gen hf', hf.leadingCoeff, inv_one, C.map_one, mul_one] end PowerBasis section Equiv section minpoly variable [CommRing R] [CommRing S] [Algebra R S] (x : S) (R) open Algebra Polynomial /-- The surjective algebra morphism `R[X]/(minpoly R x) → R[x]`. If `R` is a integrally closed domain and `x` is integral, this is an isomorphism, see `minpoly.equivAdjoin`. -/ @[simps!] def Minpoly.toAdjoin : AdjoinRoot (minpoly R x) →ₐ[R] adjoin R ({x} : Set S) := liftHom _ ⟨x, self_mem_adjoin_singleton R x⟩ (by simp [← Subalgebra.coe_eq_zero, aeval_subalgebra_coe]) variable {R x} theorem Minpoly.toAdjoin_apply' (a : AdjoinRoot (minpoly R x)) : Minpoly.toAdjoin R x a = liftHom (minpoly R x) (⟨x, self_mem_adjoin_singleton R x⟩ : adjoin R ({x} : Set S)) (by simp [← Subalgebra.coe_eq_zero, aeval_subalgebra_coe]) a := rfl theorem Minpoly.toAdjoin.apply_X : Minpoly.toAdjoin R x (mk (minpoly R x) X) = ⟨x, self_mem_adjoin_singleton R x⟩ := by simp [toAdjoin] variable (R x) theorem Minpoly.toAdjoin.surjective : Function.Surjective (Minpoly.toAdjoin R x) := by rw [← AlgHom.range_eq_top, _root_.eq_top_iff, ← adjoin_adjoin_coe_preimage] exact adjoin_le fun ⟨y₁, y₂⟩ h ↦ ⟨mk (minpoly R x) X, by simpa [toAdjoin] using h.symm⟩ end minpoly section Equiv' variable [CommRing R] [CommRing S] [Algebra R S] variable (g : R[X]) (pb : PowerBasis R S) /-- If `S` is an extension of `R` with power basis `pb` and `g` is a monic polynomial over `R` such that `pb.gen` has a minimal polynomial `g`, then `S` is isomorphic to `AdjoinRoot g`. Compare `PowerBasis.equivOfRoot`, which would require
`h₂ : aeval pb.gen (minpoly R (root g)) = 0`; that minimal polynomial is not guaranteed to be identical to `g`. -/ @[simps -fullyApplied]
Mathlib/RingTheory/AdjoinRoot.lean
595
597
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Basic import Mathlib.RingTheory.MvPowerSeries.Basic import Mathlib.Tactic.MoveAdd import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.RingTheory.Ideal.Basic /-! # Formal power series (in one variable) This file defines (univariate) formal power series and develops the basic properties of these objects. A formal power series is to a polynomial like an infinite sum is to a finite sum. Formal power series in one variable are defined from multivariate power series as `PowerSeries R := MvPowerSeries Unit R`. The file sets up the (semi)ring structure on univariate power series. We provide the natural inclusion from polynomials to formal power series. Additional results can be found in: * `Mathlib.RingTheory.PowerSeries.Trunc`, truncation of power series; * `Mathlib.RingTheory.PowerSeries.Inverse`, about inverses of power series, and the fact that power series over a local ring form a local ring; * `Mathlib.RingTheory.PowerSeries.Order`, the order of a power series at 0, and application to the fact that power series over an integral domain form an integral domain. ## Implementation notes Because of its definition, `PowerSeries R := MvPowerSeries Unit R`. a lot of proofs and properties from the multivariate case can be ported to the single variable case. However, it means that formal power series are indexed by `Unit →₀ ℕ`, which is of course canonically isomorphic to `ℕ`. We then build some glue to treat formal power series as if they were indexed by `ℕ`. Occasionally this leads to proofs that are uglier than expected. -/ noncomputable section open Finset (antidiagonal mem_antidiagonal) /-- Formal power series over a coefficient type `R` -/ abbrev PowerSeries (R : Type*) := MvPowerSeries Unit R namespace PowerSeries open Finsupp (single) variable {R : Type*} section -- Porting note: not available in Lean 4 -- local reducible PowerSeries /-- `R⟦X⟧` is notation for `PowerSeries R`, the semiring of formal power series in one variable over a semiring `R`. -/ scoped notation:9000 R "⟦X⟧" => PowerSeries R instance [Inhabited R] : Inhabited R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Zero R] : Zero R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddMonoid R] : AddMonoid R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddGroup R] : AddGroup R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddCommMonoid R] : AddCommMonoid R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddCommGroup R] : AddCommGroup R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Semiring R] : Semiring R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [CommSemiring R] : CommSemiring R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Ring R] : Ring R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [CommRing R] : CommRing R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Nontrivial R] : Nontrivial R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R A⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance {A S} [Semiring R] [Semiring S] [AddCommMonoid A] [Module R A] [Module S A] [SMul R S] [IsScalarTower R S A] : IsScalarTower R S A⟦X⟧ := Pi.isScalarTower instance {A} [Semiring A] [CommSemiring R] [Algebra R A] : Algebra R A⟦X⟧ := by dsimp only [PowerSeries] infer_instance end section Semiring variable (R) [Semiring R] /-- The `n`th coefficient of a formal power series. -/ def coeff (n : ℕ) : R⟦X⟧ →ₗ[R] R := MvPowerSeries.coeff R (single () n) /-- The `n`th monomial with coefficient `a` as formal power series. -/ def monomial (n : ℕ) : R →ₗ[R] R⟦X⟧ := MvPowerSeries.monomial R (single () n) variable {R} theorem coeff_def {s : Unit →₀ ℕ} {n : ℕ} (h : s () = n) : coeff R n = MvPowerSeries.coeff R s := by rw [coeff, ← h, ← Finsupp.unique_single s] /-- Two formal power series are equal if all their coefficients are equal. -/ @[ext] theorem ext {φ ψ : R⟦X⟧} (h : ∀ n, coeff R n φ = coeff R n ψ) : φ = ψ := MvPowerSeries.ext fun n => by rw [← coeff_def] · apply h rfl @[simp] theorem forall_coeff_eq_zero (φ : R⟦X⟧) : (∀ n, coeff R n φ = 0) ↔ φ = 0 := ⟨fun h => ext h, fun h => by simp [h]⟩ /-- Two formal power series are equal if all their coefficients are equal. -/ add_decl_doc PowerSeries.ext_iff instance [Subsingleton R] : Subsingleton R⟦X⟧ := by simp only [subsingleton_iff, PowerSeries.ext_iff] subsingleton /-- Constructor for formal power series. -/ def mk {R} (f : ℕ → R) : R⟦X⟧ := fun s => f (s ()) @[simp] theorem coeff_mk (n : ℕ) (f : ℕ → R) : coeff R n (mk f) = f n := congr_arg f Finsupp.single_eq_same theorem coeff_monomial (m n : ℕ) (a : R) : coeff R m (monomial R n a) = if m = n then a else 0 := calc coeff R m (monomial R n a) = _ := MvPowerSeries.coeff_monomial _ _ _ _ = if m = n then a else 0 := by simp only [Finsupp.unique_single_eq_iff] theorem monomial_eq_mk (n : ℕ) (a : R) : monomial R n a = mk fun m => if m = n then a else 0 := ext fun m => by rw [coeff_monomial, coeff_mk] @[simp] theorem coeff_monomial_same (n : ℕ) (a : R) : coeff R n (monomial R n a) = a := MvPowerSeries.coeff_monomial_same _ _ @[simp] theorem coeff_comp_monomial (n : ℕ) : (coeff R n).comp (monomial R n) = LinearMap.id := LinearMap.ext <| coeff_monomial_same n variable (R) /-- The constant coefficient of a formal power series. -/ def constantCoeff : R⟦X⟧ →+* R := MvPowerSeries.constantCoeff Unit R /-- The constant formal power series. -/ def C : R →+* R⟦X⟧ := MvPowerSeries.C Unit R @[simp] lemma algebraMap_eq {R : Type*} [CommSemiring R] : algebraMap R R⟦X⟧ = C R := rfl variable {R} /-- The variable of the formal power series ring. -/ def X : R⟦X⟧ := MvPowerSeries.X () theorem commute_X (φ : R⟦X⟧) : Commute φ X := MvPowerSeries.commute_X _ _ theorem X_mul {φ : R⟦X⟧} : X * φ = φ * X := MvPowerSeries.X_mul theorem commute_X_pow (φ : R⟦X⟧) (n : ℕ) : Commute φ (X ^ n) := MvPowerSeries.commute_X_pow _ _ _ theorem X_pow_mul {φ : R⟦X⟧} {n : ℕ} : X ^ n * φ = φ * X ^ n := MvPowerSeries.X_pow_mul @[simp] theorem coeff_zero_eq_constantCoeff : ⇑(coeff R 0) = constantCoeff R := by rw [coeff, Finsupp.single_zero] rfl theorem coeff_zero_eq_constantCoeff_apply (φ : R⟦X⟧) : coeff R 0 φ = constantCoeff R φ := by rw [coeff_zero_eq_constantCoeff] @[simp] theorem monomial_zero_eq_C : ⇑(monomial R 0) = C R := by -- This used to be `rw`, but we need `rw; rfl` after https://github.com/leanprover/lean4/pull/2644 rw [monomial, Finsupp.single_zero, MvPowerSeries.monomial_zero_eq_C] rfl theorem monomial_zero_eq_C_apply (a : R) : monomial R 0 a = C R a := by simp theorem coeff_C (n : ℕ) (a : R) : coeff R n (C R a : R⟦X⟧) = if n = 0 then a else 0 := by rw [← monomial_zero_eq_C_apply, coeff_monomial] @[simp] theorem coeff_zero_C (a : R) : coeff R 0 (C R a) = a := by rw [coeff_C, if_pos rfl] theorem coeff_ne_zero_C {a : R} {n : ℕ} (h : n ≠ 0) : coeff R n (C R a) = 0 := by rw [coeff_C, if_neg h] @[simp] theorem coeff_succ_C {a : R} {n : ℕ} : coeff R (n + 1) (C R a) = 0 := coeff_ne_zero_C n.succ_ne_zero theorem C_injective : Function.Injective (C R) := by intro a b H simp_rw [PowerSeries.ext_iff] at H simpa only [coeff_zero_C] using H 0 protected theorem subsingleton_iff : Subsingleton R⟦X⟧ ↔ Subsingleton R := by refine ⟨fun h ↦ ?_, fun _ ↦ inferInstance⟩ rw [subsingleton_iff] at h ⊢ exact fun a b ↦ C_injective (h (C R a) (C R b)) theorem X_eq : (X : R⟦X⟧) = monomial R 1 1 := rfl theorem coeff_X (n : ℕ) : coeff R n (X : R⟦X⟧) = if n = 1 then 1 else 0 := by rw [X_eq, coeff_monomial] @[simp] theorem coeff_zero_X : coeff R 0 (X : R⟦X⟧) = 0 := by rw [coeff, Finsupp.single_zero, X, MvPowerSeries.coeff_zero_X] @[simp] theorem coeff_one_X : coeff R 1 (X : R⟦X⟧) = 1 := by rw [coeff_X, if_pos rfl] @[simp] theorem X_ne_zero [Nontrivial R] : (X : R⟦X⟧) ≠ 0 := fun H => by simpa only [coeff_one_X, one_ne_zero, map_zero] using congr_arg (coeff R 1) H theorem X_pow_eq (n : ℕ) : (X : R⟦X⟧) ^ n = monomial R n 1 := MvPowerSeries.X_pow_eq _ n theorem coeff_X_pow (m n : ℕ) : coeff R m ((X : R⟦X⟧) ^ n) = if m = n then 1 else 0 := by rw [X_pow_eq, coeff_monomial] @[simp] theorem coeff_X_pow_self (n : ℕ) : coeff R n ((X : R⟦X⟧) ^ n) = 1 := by rw [coeff_X_pow, if_pos rfl] @[simp] theorem coeff_one (n : ℕ) : coeff R n (1 : R⟦X⟧) = if n = 0 then 1 else 0 := coeff_C n 1 theorem coeff_zero_one : coeff R 0 (1 : R⟦X⟧) = 1 := coeff_zero_C 1 theorem coeff_mul (n : ℕ) (φ ψ : R⟦X⟧) : coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := by -- `rw` can't see that `PowerSeries = MvPowerSeries Unit`, so use `.trans` refine (MvPowerSeries.coeff_mul _ φ ψ).trans ?_ rw [Finsupp.antidiagonal_single, Finset.sum_map] rfl @[simp] theorem coeff_mul_C (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff R n (φ * C R a) = coeff R n φ * a := MvPowerSeries.coeff_mul_C _ φ a @[simp] theorem coeff_C_mul (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff R n (C R a * φ) = a * coeff R n φ := MvPowerSeries.coeff_C_mul _ φ a @[simp] theorem coeff_smul {S : Type*} [Semiring S] [Module R S] (n : ℕ) (φ : PowerSeries S) (a : R) : coeff S n (a • φ) = a • coeff S n φ := rfl @[simp] theorem constantCoeff_smul {S : Type*} [Semiring S] [Module R S] (φ : PowerSeries S) (a : R) : constantCoeff S (a • φ) = a • constantCoeff S φ := rfl theorem smul_eq_C_mul (f : R⟦X⟧) (a : R) : a • f = C R a * f := by ext simp @[simp] theorem coeff_succ_mul_X (n : ℕ) (φ : R⟦X⟧) : coeff R (n + 1) (φ * X) = coeff R n φ := by simp only [coeff, Finsupp.single_add] convert φ.coeff_add_mul_monomial (single () n) (single () 1) _ rw [mul_one] @[simp] theorem coeff_succ_X_mul (n : ℕ) (φ : R⟦X⟧) : coeff R (n + 1) (X * φ) = coeff R n φ := by simp only [coeff, Finsupp.single_add, add_comm n 1] convert φ.coeff_add_monomial_mul (single () 1) (single () n) _ rw [one_mul] theorem mul_X_cancel {φ ψ : R⟦X⟧} (h : φ * X = ψ * X) : φ = ψ := by rw [PowerSeries.ext_iff] at h ⊢ intro n simpa using h (n + 1) theorem mul_X_injective : Function.Injective (· * X : R⟦X⟧ → R⟦X⟧) := fun _ _ ↦ mul_X_cancel theorem mul_X_inj {φ ψ : R⟦X⟧} : φ * X = ψ * X ↔ φ = ψ := mul_X_injective.eq_iff theorem X_mul_cancel {φ ψ : R⟦X⟧} (h : X * φ = X * ψ) : φ = ψ := by rw [PowerSeries.ext_iff] at h ⊢ intro n simpa using h (n + 1) theorem X_mul_injective : Function.Injective (X * · : R⟦X⟧ → R⟦X⟧) := fun _ _ ↦ X_mul_cancel theorem X_mul_inj {φ ψ : R⟦X⟧} : X * φ = X * ψ ↔ φ = ψ := X_mul_injective.eq_iff @[simp]
theorem constantCoeff_C (a : R) : constantCoeff R (C R a) = a := rfl
Mathlib/RingTheory/PowerSeries/Basic.lean
361
363
/- Copyright (c) 2018 Louis Carlin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Louis Carlin, Mario Carneiro -/ import Mathlib.Algebra.EuclideanDomain.Defs import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Algebra.Ring.Regular import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Ring.Basic /-! # Lemmas about Euclidean domains ## Main statements * `gcd_eq_gcd_ab`: states Bézout's lemma for Euclidean domains. -/ universe u namespace EuclideanDomain variable {R : Type u} variable [EuclideanDomain R] /-- The well founded relation in a Euclidean Domain satisfying `a % b ≺ b` for `b ≠ 0` -/ local infixl:50 " ≺ " => EuclideanDomain.r -- See note [lower instance priority] instance (priority := 100) toMulDivCancelClass : MulDivCancelClass R where mul_div_cancel a b hb := by refine (eq_of_sub_eq_zero ?_).symm by_contra h have := mul_right_not_lt b h rw [sub_mul, mul_comm (_ / _), sub_eq_iff_eq_add'.2 (div_add_mod (a * b) b).symm] at this exact this (mod_lt _ hb) theorem mod_eq_sub_mul_div {R : Type*} [EuclideanDomain R] (a b : R) : a % b = a - b * (a / b) := calc a % b = b * (a / b) + a % b - b * (a / b) := (add_sub_cancel_left _ _).symm _ = a - b * (a / b) := by rw [div_add_mod] theorem val_dvd_le : ∀ a b : R, b ∣ a → a ≠ 0 → ¬a ≺ b | _, b, ⟨d, rfl⟩, ha => mul_left_not_lt b (mt (by rintro rfl; exact mul_zero _) ha) @[simp] theorem mod_eq_zero {a b : R} : a % b = 0 ↔ b ∣ a := ⟨fun h => by rw [← div_add_mod a b, h, add_zero] exact dvd_mul_right _ _, fun ⟨c, e⟩ => by rw [e, ← add_left_cancel_iff, div_add_mod, add_zero] haveI := Classical.dec by_cases b0 : b = 0 · simp only [b0, zero_mul] · rw [mul_div_cancel_left₀ _ b0]⟩ @[simp] theorem mod_self (a : R) : a % a = 0 := mod_eq_zero.2 dvd_rfl theorem dvd_mod_iff {a b c : R} (h : c ∣ b) : c ∣ a % b ↔ c ∣ a := by rw [← dvd_add_right (h.mul_right _), div_add_mod] @[simp] theorem mod_one (a : R) : a % 1 = 0 := mod_eq_zero.2 (one_dvd _) @[simp] theorem zero_mod (b : R) : 0 % b = 0 := mod_eq_zero.2 (dvd_zero _) @[simp] theorem zero_div {a : R} : 0 / a = 0 := by_cases (fun a0 : a = 0 => a0.symm ▸ div_zero 0) fun a0 => by simpa only [zero_mul] using mul_div_cancel_right₀ 0 a0 @[simp] theorem div_self {a : R} (a0 : a ≠ 0) : a / a = 1 := by simpa only [one_mul] using mul_div_cancel_right₀ 1 a0 theorem eq_div_of_mul_eq_left {a b c : R} (hb : b ≠ 0) (h : a * b = c) : a = c / b := by rw [← h, mul_div_cancel_right₀ _ hb] theorem eq_div_of_mul_eq_right {a b c : R} (ha : a ≠ 0) (h : a * b = c) : b = c / a := by rw [← h, mul_div_cancel_left₀ _ ha] theorem mul_div_assoc (x : R) {y z : R} (h : z ∣ y) : x * y / z = x * (y / z) := by by_cases hz : z = 0 · subst hz rw [div_zero, div_zero, mul_zero] rcases h with ⟨p, rfl⟩ rw [mul_div_cancel_left₀ _ hz, mul_left_comm, mul_div_cancel_left₀ _ hz]
protected theorem mul_div_cancel' {a b : R} (hb : b ≠ 0) (hab : b ∣ a) : b * (a / b) = a := by rw [← mul_div_assoc _ hab, mul_div_cancel_left₀ _ hb] -- This generalizes `Int.div_one`, see note [simp-normal form] @[simp]
Mathlib/Algebra/EuclideanDomain/Basic.lean
96
101
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.Order.Filter.Bases.Finite import Mathlib.Topology.Algebra.Group.Defs import Mathlib.Topology.Algebra.Monoid import Mathlib.Topology.Homeomorph.Lemmas /-! # Topological groups This file defines the following typeclasses: * `IsTopologicalGroup`, `IsTopologicalAddGroup`: multiplicative and additive topological groups, i.e., groups with continuous `(*)` and `(⁻¹)` / `(+)` and `(-)`; * `ContinuousSub G` means that `G` has a continuous subtraction operation. There is an instance deducing `ContinuousSub` from `IsTopologicalGroup` but we use a separate typeclass because, e.g., `ℕ` and `ℝ≥0` have continuous subtraction but are not additive groups. We also define `Homeomorph` versions of several `Equiv`s: `Homeomorph.mulLeft`, `Homeomorph.mulRight`, `Homeomorph.inv`, and prove a few facts about neighbourhood filters in groups. ## Tags topological space, group, topological group -/ open Set Filter TopologicalSpace Function Topology MulOpposite Pointwise universe u v w x variable {G : Type w} {H : Type x} {α : Type u} {β : Type v} section ContinuousMulGroup /-! ### Groups with continuous multiplication In this section we prove a few statements about groups with continuous `(*)`. -/ variable [TopologicalSpace G] [Group G] [ContinuousMul G] /-- Multiplication from the left in a topological group as a homeomorphism. -/ @[to_additive "Addition from the left in a topological additive group as a homeomorphism."] protected def Homeomorph.mulLeft (a : G) : G ≃ₜ G := { Equiv.mulLeft a with continuous_toFun := continuous_const.mul continuous_id continuous_invFun := continuous_const.mul continuous_id } @[to_additive (attr := simp)] theorem Homeomorph.coe_mulLeft (a : G) : ⇑(Homeomorph.mulLeft a) = (a * ·) := rfl @[to_additive] theorem Homeomorph.mulLeft_symm (a : G) : (Homeomorph.mulLeft a).symm = Homeomorph.mulLeft a⁻¹ := by ext rfl @[to_additive] lemma isOpenMap_mul_left (a : G) : IsOpenMap (a * ·) := (Homeomorph.mulLeft a).isOpenMap @[to_additive IsOpen.left_addCoset] theorem IsOpen.leftCoset {U : Set G} (h : IsOpen U) (x : G) : IsOpen (x • U) := isOpenMap_mul_left x _ h @[to_additive] lemma isClosedMap_mul_left (a : G) : IsClosedMap (a * ·) := (Homeomorph.mulLeft a).isClosedMap @[to_additive IsClosed.left_addCoset] theorem IsClosed.leftCoset {U : Set G} (h : IsClosed U) (x : G) : IsClosed (x • U) := isClosedMap_mul_left x _ h /-- Multiplication from the right in a topological group as a homeomorphism. -/ @[to_additive "Addition from the right in a topological additive group as a homeomorphism."] protected def Homeomorph.mulRight (a : G) : G ≃ₜ G := { Equiv.mulRight a with continuous_toFun := continuous_id.mul continuous_const continuous_invFun := continuous_id.mul continuous_const } @[to_additive (attr := simp)] lemma Homeomorph.coe_mulRight (a : G) : ⇑(Homeomorph.mulRight a) = (· * a) := rfl @[to_additive] theorem Homeomorph.mulRight_symm (a : G) : (Homeomorph.mulRight a).symm = Homeomorph.mulRight a⁻¹ := by ext rfl @[to_additive] theorem isOpenMap_mul_right (a : G) : IsOpenMap (· * a) := (Homeomorph.mulRight a).isOpenMap @[to_additive IsOpen.right_addCoset] theorem IsOpen.rightCoset {U : Set G} (h : IsOpen U) (x : G) : IsOpen (op x • U) := isOpenMap_mul_right x _ h @[to_additive] theorem isClosedMap_mul_right (a : G) : IsClosedMap (· * a) := (Homeomorph.mulRight a).isClosedMap @[to_additive IsClosed.right_addCoset] theorem IsClosed.rightCoset {U : Set G} (h : IsClosed U) (x : G) : IsClosed (op x • U) := isClosedMap_mul_right x _ h @[to_additive] theorem discreteTopology_of_isOpen_singleton_one (h : IsOpen ({1} : Set G)) : DiscreteTopology G := by rw [← singletons_open_iff_discrete] intro g suffices {g} = (g⁻¹ * ·) ⁻¹' {1} by rw [this] exact (continuous_mul_left g⁻¹).isOpen_preimage _ h simp only [mul_one, Set.preimage_mul_left_singleton, eq_self_iff_true, inv_inv, Set.singleton_eq_singleton_iff] @[to_additive] theorem discreteTopology_iff_isOpen_singleton_one : DiscreteTopology G ↔ IsOpen ({1} : Set G) := ⟨fun h => forall_open_iff_discrete.mpr h {1}, discreteTopology_of_isOpen_singleton_one⟩ end ContinuousMulGroup /-! ### `ContinuousInv` and `ContinuousNeg` -/ section ContinuousInv variable [TopologicalSpace G] [Inv G] [ContinuousInv G] @[to_additive] theorem ContinuousInv.induced {α : Type*} {β : Type*} {F : Type*} [FunLike F α β] [Group α] [DivisionMonoid β] [MonoidHomClass F α β] [tβ : TopologicalSpace β] [ContinuousInv β] (f : F) : @ContinuousInv α (tβ.induced f) _ := by let _tα := tβ.induced f refine ⟨continuous_induced_rng.2 ?_⟩ simp only [Function.comp_def, map_inv] fun_prop @[to_additive] protected theorem Specializes.inv {x y : G} (h : x ⤳ y) : (x⁻¹) ⤳ (y⁻¹) := h.map continuous_inv @[to_additive] protected theorem Inseparable.inv {x y : G} (h : Inseparable x y) : Inseparable (x⁻¹) (y⁻¹) := h.map continuous_inv @[to_additive] protected theorem Specializes.zpow {G : Type*} [DivInvMonoid G] [TopologicalSpace G] [ContinuousMul G] [ContinuousInv G] {x y : G} (h : x ⤳ y) : ∀ m : ℤ, (x ^ m) ⤳ (y ^ m) | .ofNat n => by simpa using h.pow n | .negSucc n => by simpa using (h.pow (n + 1)).inv @[to_additive] protected theorem Inseparable.zpow {G : Type*} [DivInvMonoid G] [TopologicalSpace G] [ContinuousMul G] [ContinuousInv G] {x y : G} (h : Inseparable x y) (m : ℤ) : Inseparable (x ^ m) (y ^ m) := (h.specializes.zpow m).antisymm (h.specializes'.zpow m) @[to_additive] instance : ContinuousInv (ULift G) := ⟨continuous_uliftUp.comp (continuous_inv.comp continuous_uliftDown)⟩ @[to_additive] theorem continuousOn_inv {s : Set G} : ContinuousOn Inv.inv s := continuous_inv.continuousOn @[to_additive] theorem continuousWithinAt_inv {s : Set G} {x : G} : ContinuousWithinAt Inv.inv s x := continuous_inv.continuousWithinAt @[to_additive] theorem continuousAt_inv {x : G} : ContinuousAt Inv.inv x := continuous_inv.continuousAt @[to_additive] theorem tendsto_inv (a : G) : Tendsto Inv.inv (𝓝 a) (𝓝 a⁻¹) := continuousAt_inv variable [TopologicalSpace α] {f : α → G} {s : Set α} {x : α} @[to_additive] instance OrderDual.instContinuousInv : ContinuousInv Gᵒᵈ := ‹ContinuousInv G› @[to_additive] instance Prod.continuousInv [TopologicalSpace H] [Inv H] [ContinuousInv H] : ContinuousInv (G × H) := ⟨continuous_inv.fst'.prodMk continuous_inv.snd'⟩ variable {ι : Type*} @[to_additive] instance Pi.continuousInv {C : ι → Type*} [∀ i, TopologicalSpace (C i)] [∀ i, Inv (C i)] [∀ i, ContinuousInv (C i)] : ContinuousInv (∀ i, C i) where continuous_inv := continuous_pi fun i => (continuous_apply i).inv /-- A version of `Pi.continuousInv` for non-dependent functions. It is needed because sometimes Lean fails to use `Pi.continuousInv` for non-dependent functions. -/ @[to_additive "A version of `Pi.continuousNeg` for non-dependent functions. It is needed because sometimes Lean fails to use `Pi.continuousNeg` for non-dependent functions."] instance Pi.has_continuous_inv' : ContinuousInv (ι → G) := Pi.continuousInv @[to_additive] instance (priority := 100) continuousInv_of_discreteTopology [TopologicalSpace H] [Inv H] [DiscreteTopology H] : ContinuousInv H := ⟨continuous_of_discreteTopology⟩ section PointwiseLimits variable (G₁ G₂ : Type*) [TopologicalSpace G₂] [T2Space G₂] @[to_additive] theorem isClosed_setOf_map_inv [Inv G₁] [Inv G₂] [ContinuousInv G₂] : IsClosed { f : G₁ → G₂ | ∀ x, f x⁻¹ = (f x)⁻¹ } := by simp only [setOf_forall] exact isClosed_iInter fun i => isClosed_eq (continuous_apply _) (continuous_apply _).inv end PointwiseLimits instance [TopologicalSpace H] [Inv H] [ContinuousInv H] : ContinuousNeg (Additive H) where continuous_neg := @continuous_inv H _ _ _ instance [TopologicalSpace H] [Neg H] [ContinuousNeg H] : ContinuousInv (Multiplicative H) where continuous_inv := @continuous_neg H _ _ _ end ContinuousInv section ContinuousInvolutiveInv variable [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] {s : Set G} @[to_additive] theorem IsCompact.inv (hs : IsCompact s) : IsCompact s⁻¹ := by rw [← image_inv_eq_inv] exact hs.image continuous_inv variable (G) /-- Inversion in a topological group as a homeomorphism. -/ @[to_additive "Negation in a topological group as a homeomorphism."] protected def Homeomorph.inv (G : Type*) [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] : G ≃ₜ G := { Equiv.inv G with continuous_toFun := continuous_inv continuous_invFun := continuous_inv } @[to_additive (attr := simp)] lemma Homeomorph.coe_inv {G : Type*} [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] : ⇑(Homeomorph.inv G) = Inv.inv := rfl @[to_additive] theorem nhds_inv (a : G) : 𝓝 a⁻¹ = (𝓝 a)⁻¹ := ((Homeomorph.inv G).map_nhds_eq a).symm @[to_additive] theorem isOpenMap_inv : IsOpenMap (Inv.inv : G → G) := (Homeomorph.inv _).isOpenMap @[to_additive] theorem isClosedMap_inv : IsClosedMap (Inv.inv : G → G) := (Homeomorph.inv _).isClosedMap variable {G} @[to_additive] theorem IsOpen.inv (hs : IsOpen s) : IsOpen s⁻¹ := hs.preimage continuous_inv @[to_additive] theorem IsClosed.inv (hs : IsClosed s) : IsClosed s⁻¹ := hs.preimage continuous_inv @[to_additive] theorem inv_closure : ∀ s : Set G, (closure s)⁻¹ = closure s⁻¹ := (Homeomorph.inv G).preimage_closure variable [TopologicalSpace α] {f : α → G} {s : Set α} {x : α} @[to_additive (attr := simp)] lemma continuous_inv_iff : Continuous f⁻¹ ↔ Continuous f := (Homeomorph.inv G).comp_continuous_iff @[to_additive (attr := simp)] lemma continuousAt_inv_iff : ContinuousAt f⁻¹ x ↔ ContinuousAt f x := (Homeomorph.inv G).comp_continuousAt_iff _ _ @[to_additive (attr := simp)] lemma continuousOn_inv_iff : ContinuousOn f⁻¹ s ↔ ContinuousOn f s := (Homeomorph.inv G).comp_continuousOn_iff _ _ @[to_additive] alias ⟨Continuous.of_inv, _⟩ := continuous_inv_iff @[to_additive] alias ⟨ContinuousAt.of_inv, _⟩ := continuousAt_inv_iff @[to_additive] alias ⟨ContinuousOn.of_inv, _⟩ := continuousOn_inv_iff end ContinuousInvolutiveInv section LatticeOps variable {ι' : Sort*} [Inv G] @[to_additive] theorem continuousInv_sInf {ts : Set (TopologicalSpace G)} (h : ∀ t ∈ ts, @ContinuousInv G t _) : @ContinuousInv G (sInf ts) _ := letI := sInf ts { continuous_inv := continuous_sInf_rng.2 fun t ht => continuous_sInf_dom ht (@ContinuousInv.continuous_inv G t _ (h t ht)) } @[to_additive] theorem continuousInv_iInf {ts' : ι' → TopologicalSpace G} (h' : ∀ i, @ContinuousInv G (ts' i) _) : @ContinuousInv G (⨅ i, ts' i) _ := by rw [← sInf_range] exact continuousInv_sInf (Set.forall_mem_range.mpr h') @[to_additive] theorem continuousInv_inf {t₁ t₂ : TopologicalSpace G} (h₁ : @ContinuousInv G t₁ _) (h₂ : @ContinuousInv G t₂ _) : @ContinuousInv G (t₁ ⊓ t₂) _ := by rw [inf_eq_iInf] refine continuousInv_iInf fun b => ?_ cases b <;> assumption end LatticeOps @[to_additive] theorem Topology.IsInducing.continuousInv {G H : Type*} [Inv G] [Inv H] [TopologicalSpace G] [TopologicalSpace H] [ContinuousInv H] {f : G → H} (hf : IsInducing f) (hf_inv : ∀ x, f x⁻¹ = (f x)⁻¹) : ContinuousInv G := ⟨hf.continuous_iff.2 <| by simpa only [Function.comp_def, hf_inv] using hf.continuous.inv⟩ @[deprecated (since := "2024-10-28")] alias Inducing.continuousInv := IsInducing.continuousInv section IsTopologicalGroup /-! ### Topological groups A topological group is a group in which the multiplication and inversion operations are continuous. Topological additive groups are defined in the same way. Equivalently, we can require that the division operation `x y ↦ x * y⁻¹` (resp., subtraction) is continuous. -/ section Conj instance ConjAct.units_continuousConstSMul {M} [Monoid M] [TopologicalSpace M] [ContinuousMul M] : ContinuousConstSMul (ConjAct Mˣ) M := ⟨fun _ => (continuous_const.mul continuous_id).mul continuous_const⟩ variable [TopologicalSpace G] [Inv G] [Mul G] [ContinuousMul G] /-- Conjugation is jointly continuous on `G × G` when both `mul` and `inv` are continuous. -/ @[to_additive continuous_addConj_prod "Conjugation is jointly continuous on `G × G` when both `add` and `neg` are continuous."] theorem IsTopologicalGroup.continuous_conj_prod [ContinuousInv G] : Continuous fun g : G × G => g.fst * g.snd * g.fst⁻¹ := continuous_mul.mul (continuous_inv.comp continuous_fst) @[deprecated (since := "2025-03-11")] alias IsTopologicalAddGroup.continuous_conj_sum := IsTopologicalAddGroup.continuous_addConj_prod /-- Conjugation by a fixed element is continuous when `mul` is continuous. -/ @[to_additive (attr := continuity) "Conjugation by a fixed element is continuous when `add` is continuous."] theorem IsTopologicalGroup.continuous_conj (g : G) : Continuous fun h : G => g * h * g⁻¹ := (continuous_mul_right g⁻¹).comp (continuous_mul_left g) /-- Conjugation acting on fixed element of the group is continuous when both `mul` and `inv` are continuous. -/ @[to_additive (attr := continuity) "Conjugation acting on fixed element of the additive group is continuous when both `add` and `neg` are continuous."] theorem IsTopologicalGroup.continuous_conj' [ContinuousInv G] (h : G) : Continuous fun g : G => g * h * g⁻¹ := (continuous_mul_right h).mul continuous_inv end Conj variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] [TopologicalSpace α] {f : α → G} {s : Set α} {x : α} instance : IsTopologicalGroup (ULift G) where section ZPow @[to_additive (attr := continuity, fun_prop)] theorem continuous_zpow : ∀ z : ℤ, Continuous fun a : G => a ^ z | Int.ofNat n => by simpa using continuous_pow n | Int.negSucc n => by simpa using (continuous_pow (n + 1)).inv instance AddGroup.continuousConstSMul_int {A} [AddGroup A] [TopologicalSpace A] [IsTopologicalAddGroup A] : ContinuousConstSMul ℤ A := ⟨continuous_zsmul⟩ instance AddGroup.continuousSMul_int {A} [AddGroup A] [TopologicalSpace A] [IsTopologicalAddGroup A] : ContinuousSMul ℤ A := ⟨continuous_prod_of_discrete_left.mpr continuous_zsmul⟩ @[to_additive (attr := continuity, fun_prop)] theorem Continuous.zpow {f : α → G} (h : Continuous f) (z : ℤ) : Continuous fun b => f b ^ z := (continuous_zpow z).comp h @[to_additive] theorem continuousOn_zpow {s : Set G} (z : ℤ) : ContinuousOn (fun x => x ^ z) s := (continuous_zpow z).continuousOn @[to_additive] theorem continuousAt_zpow (x : G) (z : ℤ) : ContinuousAt (fun x => x ^ z) x := (continuous_zpow z).continuousAt @[to_additive] theorem Filter.Tendsto.zpow {α} {l : Filter α} {f : α → G} {x : G} (hf : Tendsto f l (𝓝 x)) (z : ℤ) : Tendsto (fun x => f x ^ z) l (𝓝 (x ^ z)) := (continuousAt_zpow _ _).tendsto.comp hf @[to_additive] theorem ContinuousWithinAt.zpow {f : α → G} {x : α} {s : Set α} (hf : ContinuousWithinAt f s x) (z : ℤ) : ContinuousWithinAt (fun x => f x ^ z) s x := Filter.Tendsto.zpow hf z @[to_additive (attr := fun_prop)] theorem ContinuousAt.zpow {f : α → G} {x : α} (hf : ContinuousAt f x) (z : ℤ) : ContinuousAt (fun x => f x ^ z) x := Filter.Tendsto.zpow hf z @[to_additive (attr := fun_prop)] theorem ContinuousOn.zpow {f : α → G} {s : Set α} (hf : ContinuousOn f s) (z : ℤ) : ContinuousOn (fun x => f x ^ z) s := fun x hx => (hf x hx).zpow z end ZPow section OrderedCommGroup variable [TopologicalSpace H] [CommGroup H] [PartialOrder H] [IsOrderedMonoid H] [ContinuousInv H] @[to_additive] theorem tendsto_inv_nhdsGT {a : H} : Tendsto Inv.inv (𝓝[>] a) (𝓝[<] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ioi := tendsto_neg_nhdsGT @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ioi := tendsto_inv_nhdsGT @[to_additive] theorem tendsto_inv_nhdsLT {a : H} : Tendsto Inv.inv (𝓝[<] a) (𝓝[>] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iio := tendsto_neg_nhdsLT @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iio := tendsto_inv_nhdsLT @[to_additive] theorem tendsto_inv_nhdsGT_inv {a : H} : Tendsto Inv.inv (𝓝[>] a⁻¹) (𝓝[<] a) := by simpa only [inv_inv] using tendsto_inv_nhdsGT (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ioi_neg := tendsto_neg_nhdsGT_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ioi_inv := tendsto_inv_nhdsGT_inv @[to_additive] theorem tendsto_inv_nhdsLT_inv {a : H} : Tendsto Inv.inv (𝓝[<] a⁻¹) (𝓝[>] a) := by simpa only [inv_inv] using tendsto_inv_nhdsLT (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iio_neg := tendsto_neg_nhdsLT_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iio_inv := tendsto_inv_nhdsLT_inv @[to_additive] theorem tendsto_inv_nhdsGE {a : H} : Tendsto Inv.inv (𝓝[≥] a) (𝓝[≤] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ici := tendsto_neg_nhdsGE @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ici := tendsto_inv_nhdsGE @[to_additive] theorem tendsto_inv_nhdsLE {a : H} : Tendsto Inv.inv (𝓝[≤] a) (𝓝[≥] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iic := tendsto_neg_nhdsLE @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iic := tendsto_inv_nhdsLE @[to_additive] theorem tendsto_inv_nhdsGE_inv {a : H} : Tendsto Inv.inv (𝓝[≥] a⁻¹) (𝓝[≤] a) := by simpa only [inv_inv] using tendsto_inv_nhdsGE (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ici_neg := tendsto_neg_nhdsGE_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ici_inv := tendsto_inv_nhdsGE_inv @[to_additive] theorem tendsto_inv_nhdsLE_inv {a : H} : Tendsto Inv.inv (𝓝[≤] a⁻¹) (𝓝[≥] a) := by simpa only [inv_inv] using tendsto_inv_nhdsLE (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iic_neg := tendsto_neg_nhdsLE_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iic_inv := tendsto_inv_nhdsLE_inv end OrderedCommGroup @[to_additive] instance Prod.instIsTopologicalGroup [TopologicalSpace H] [Group H] [IsTopologicalGroup H] : IsTopologicalGroup (G × H) where continuous_inv := continuous_inv.prodMap continuous_inv @[to_additive] instance OrderDual.instIsTopologicalGroup : IsTopologicalGroup Gᵒᵈ where @[to_additive] instance Pi.topologicalGroup {C : β → Type*} [∀ b, TopologicalSpace (C b)] [∀ b, Group (C b)] [∀ b, IsTopologicalGroup (C b)] : IsTopologicalGroup (∀ b, C b) where continuous_inv := continuous_pi fun i => (continuous_apply i).inv open MulOpposite @[to_additive] instance [Inv α] [ContinuousInv α] : ContinuousInv αᵐᵒᵖ := opHomeomorph.symm.isInducing.continuousInv unop_inv /-- If multiplication is continuous in `α`, then it also is in `αᵐᵒᵖ`. -/ @[to_additive "If addition is continuous in `α`, then it also is in `αᵃᵒᵖ`."] instance [Group α] [IsTopologicalGroup α] : IsTopologicalGroup αᵐᵒᵖ where variable (G) @[to_additive] theorem nhds_one_symm : comap Inv.inv (𝓝 (1 : G)) = 𝓝 (1 : G) := ((Homeomorph.inv G).comap_nhds_eq _).trans (congr_arg nhds inv_one) @[to_additive] theorem nhds_one_symm' : map Inv.inv (𝓝 (1 : G)) = 𝓝 (1 : G) := ((Homeomorph.inv G).map_nhds_eq _).trans (congr_arg nhds inv_one) @[to_additive] theorem inv_mem_nhds_one {S : Set G} (hS : S ∈ (𝓝 1 : Filter G)) : S⁻¹ ∈ 𝓝 (1 : G) := by rwa [← nhds_one_symm'] at hS /-- The map `(x, y) ↦ (x, x * y)` as a homeomorphism. This is a shear mapping. -/ @[to_additive "The map `(x, y) ↦ (x, x + y)` as a homeomorphism. This is a shear mapping."] protected def Homeomorph.shearMulRight : G × G ≃ₜ G × G := { Equiv.prodShear (Equiv.refl _) Equiv.mulLeft with continuous_toFun := by dsimp; fun_prop continuous_invFun := by dsimp; fun_prop } @[to_additive (attr := simp)] theorem Homeomorph.shearMulRight_coe : ⇑(Homeomorph.shearMulRight G) = fun z : G × G => (z.1, z.1 * z.2) := rfl @[to_additive (attr := simp)] theorem Homeomorph.shearMulRight_symm_coe : ⇑(Homeomorph.shearMulRight G).symm = fun z : G × G => (z.1, z.1⁻¹ * z.2) := rfl variable {G} @[to_additive] protected theorem Topology.IsInducing.topologicalGroup {F : Type*} [Group H] [TopologicalSpace H] [FunLike F H G] [MonoidHomClass F H G] (f : F) (hf : IsInducing f) : IsTopologicalGroup H := { toContinuousMul := hf.continuousMul _ toContinuousInv := hf.continuousInv (map_inv f) } @[deprecated (since := "2024-10-28")] alias Inducing.topologicalGroup := IsInducing.topologicalGroup @[to_additive] theorem topologicalGroup_induced {F : Type*} [Group H] [FunLike F H G] [MonoidHomClass F H G] (f : F) : @IsTopologicalGroup H (induced f ‹_›) _ := letI := induced f ‹_› IsInducing.topologicalGroup f ⟨rfl⟩ namespace Subgroup @[to_additive] instance (S : Subgroup G) : IsTopologicalGroup S := IsInducing.subtypeVal.topologicalGroup S.subtype end Subgroup /-- The (topological-space) closure of a subgroup of a topological group is itself a subgroup. -/ @[to_additive "The (topological-space) closure of an additive subgroup of an additive topological group is itself an additive subgroup."] def Subgroup.topologicalClosure (s : Subgroup G) : Subgroup G := { s.toSubmonoid.topologicalClosure with carrier := _root_.closure (s : Set G) inv_mem' := fun {g} hg => by simpa only [← Set.mem_inv, inv_closure, inv_coe_set] using hg } @[to_additive (attr := simp)] theorem Subgroup.topologicalClosure_coe {s : Subgroup G} : (s.topologicalClosure : Set G) = _root_.closure s := rfl @[to_additive] theorem Subgroup.le_topologicalClosure (s : Subgroup G) : s ≤ s.topologicalClosure := _root_.subset_closure @[to_additive] theorem Subgroup.isClosed_topologicalClosure (s : Subgroup G) : IsClosed (s.topologicalClosure : Set G) := isClosed_closure @[to_additive] theorem Subgroup.topologicalClosure_minimal (s : Subgroup G) {t : Subgroup G} (h : s ≤ t) (ht : IsClosed (t : Set G)) : s.topologicalClosure ≤ t := closure_minimal h ht @[to_additive] theorem DenseRange.topologicalClosure_map_subgroup [Group H] [TopologicalSpace H] [IsTopologicalGroup H] {f : G →* H} (hf : Continuous f) (hf' : DenseRange f) {s : Subgroup G} (hs : s.topologicalClosure = ⊤) : (s.map f).topologicalClosure = ⊤ := by rw [SetLike.ext'_iff] at hs ⊢ simp only [Subgroup.topologicalClosure_coe, Subgroup.coe_top, ← dense_iff_closure_eq] at hs ⊢ exact hf'.dense_image hf hs /-- The topological closure of a normal subgroup is normal. -/ @[to_additive "The topological closure of a normal additive subgroup is normal."] theorem Subgroup.is_normal_topologicalClosure {G : Type*} [TopologicalSpace G] [Group G] [IsTopologicalGroup G] (N : Subgroup G) [N.Normal] : (Subgroup.topologicalClosure N).Normal where conj_mem n hn g := by apply map_mem_closure (IsTopologicalGroup.continuous_conj g) hn exact fun m hm => Subgroup.Normal.conj_mem inferInstance m hm g @[to_additive] theorem mul_mem_connectedComponent_one {G : Type*} [TopologicalSpace G] [MulOneClass G] [ContinuousMul G] {g h : G} (hg : g ∈ connectedComponent (1 : G)) (hh : h ∈ connectedComponent (1 : G)) : g * h ∈ connectedComponent (1 : G) := by rw [connectedComponent_eq hg] have hmul : g ∈ connectedComponent (g * h) := by apply Continuous.image_connectedComponent_subset (continuous_mul_left g) rw [← connectedComponent_eq hh] exact ⟨(1 : G), mem_connectedComponent, by simp only [mul_one]⟩ simpa [← connectedComponent_eq hmul] using mem_connectedComponent @[to_additive] theorem inv_mem_connectedComponent_one {G : Type*} [TopologicalSpace G] [DivisionMonoid G] [ContinuousInv G] {g : G} (hg : g ∈ connectedComponent (1 : G)) : g⁻¹ ∈ connectedComponent (1 : G) := by rw [← inv_one] exact Continuous.image_connectedComponent_subset continuous_inv _ ((Set.mem_image _ _ _).mp ⟨g, hg, rfl⟩) /-- The connected component of 1 is a subgroup of `G`. -/ @[to_additive "The connected component of 0 is a subgroup of `G`."] def Subgroup.connectedComponentOfOne (G : Type*) [TopologicalSpace G] [Group G] [IsTopologicalGroup G] : Subgroup G where carrier := connectedComponent (1 : G) one_mem' := mem_connectedComponent mul_mem' hg hh := mul_mem_connectedComponent_one hg hh inv_mem' hg := inv_mem_connectedComponent_one hg /-- If a subgroup of a topological group is commutative, then so is its topological closure. See note [reducible non-instances]. -/ @[to_additive "If a subgroup of an additive topological group is commutative, then so is its topological closure. See note [reducible non-instances]."] abbrev Subgroup.commGroupTopologicalClosure [T2Space G] (s : Subgroup G) (hs : ∀ x y : s, x * y = y * x) : CommGroup s.topologicalClosure := { s.topologicalClosure.toGroup, s.toSubmonoid.commMonoidTopologicalClosure hs with } variable (G) in @[to_additive] lemma Subgroup.coe_topologicalClosure_bot : ((⊥ : Subgroup G).topologicalClosure : Set G) = _root_.closure ({1} : Set G) := by simp @[to_additive exists_nhds_half_neg] theorem exists_nhds_split_inv {s : Set G} (hs : s ∈ 𝓝 (1 : G)) : ∃ V ∈ 𝓝 (1 : G), ∀ v ∈ V, ∀ w ∈ V, v / w ∈ s := by have : (fun p : G × G => p.1 * p.2⁻¹) ⁻¹' s ∈ 𝓝 ((1, 1) : G × G) := continuousAt_fst.mul continuousAt_snd.inv (by simpa) simpa only [div_eq_mul_inv, nhds_prod_eq, mem_prod_self_iff, prod_subset_iff, mem_preimage] using this @[to_additive] theorem nhds_translation_mul_inv (x : G) : comap (· * x⁻¹) (𝓝 1) = 𝓝 x := ((Homeomorph.mulRight x⁻¹).comap_nhds_eq 1).trans <| show 𝓝 (1 * x⁻¹⁻¹) = 𝓝 x by simp @[to_additive (attr := simp)] theorem map_mul_left_nhds (x y : G) : map (x * ·) (𝓝 y) = 𝓝 (x * y) := (Homeomorph.mulLeft x).map_nhds_eq y @[to_additive] theorem map_mul_left_nhds_one (x : G) : map (x * ·) (𝓝 1) = 𝓝 x := by simp @[to_additive (attr := simp)] theorem map_mul_right_nhds (x y : G) : map (· * x) (𝓝 y) = 𝓝 (y * x) := (Homeomorph.mulRight x).map_nhds_eq y @[to_additive] theorem map_mul_right_nhds_one (x : G) : map (· * x) (𝓝 1) = 𝓝 x := by simp @[to_additive] theorem Filter.HasBasis.nhds_of_one {ι : Sort*} {p : ι → Prop} {s : ι → Set G} (hb : HasBasis (𝓝 1 : Filter G) p s) (x : G) : HasBasis (𝓝 x) p fun i => { y | y / x ∈ s i } := by rw [← nhds_translation_mul_inv] simp_rw [div_eq_mul_inv] exact hb.comap _ @[to_additive] theorem mem_closure_iff_nhds_one {x : G} {s : Set G} : x ∈ closure s ↔ ∀ U ∈ (𝓝 1 : Filter G), ∃ y ∈ s, y / x ∈ U := by rw [mem_closure_iff_nhds_basis ((𝓝 1 : Filter G).basis_sets.nhds_of_one x)] simp_rw [Set.mem_setOf, id] /-- A monoid homomorphism (a bundled morphism of a type that implements `MonoidHomClass`) from a topological group to a topological monoid is continuous provided that it is continuous at one. See also `uniformContinuous_of_continuousAt_one`. -/ @[to_additive "An additive monoid homomorphism (a bundled morphism of a type that implements `AddMonoidHomClass`) from an additive topological group to an additive topological monoid is continuous provided that it is continuous at zero. See also `uniformContinuous_of_continuousAt_zero`."] theorem continuous_of_continuousAt_one {M hom : Type*} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] [FunLike hom G M] [MonoidHomClass hom G M] (f : hom) (hf : ContinuousAt f 1) : Continuous f := continuous_iff_continuousAt.2 fun x => by simpa only [ContinuousAt, ← map_mul_left_nhds_one x, tendsto_map'_iff, Function.comp_def, map_mul, map_one, mul_one] using hf.tendsto.const_mul (f x) @[to_additive continuous_of_continuousAt_zero₂] theorem continuous_of_continuousAt_one₂ {H M : Type*} [CommMonoid M] [TopologicalSpace M] [ContinuousMul M] [Group H] [TopologicalSpace H] [IsTopologicalGroup H] (f : G →* H →* M) (hf : ContinuousAt (fun x : G × H ↦ f x.1 x.2) (1, 1)) (hl : ∀ x, ContinuousAt (f x) 1) (hr : ∀ y, ContinuousAt (f · y) 1) : Continuous (fun x : G × H ↦ f x.1 x.2) := continuous_iff_continuousAt.2 fun (x, y) => by simp only [ContinuousAt, nhds_prod_eq, ← map_mul_left_nhds_one x, ← map_mul_left_nhds_one y, prod_map_map_eq, tendsto_map'_iff, Function.comp_def, map_mul, MonoidHom.mul_apply] at * refine ((tendsto_const_nhds.mul ((hr y).comp tendsto_fst)).mul (((hl x).comp tendsto_snd).mul hf)).mono_right (le_of_eq ?_) simp only [map_one, mul_one, MonoidHom.one_apply] @[to_additive] lemma IsTopologicalGroup.isInducing_iff_nhds_one {H : Type*} [Group H] [TopologicalSpace H] [IsTopologicalGroup H] {F : Type*} [FunLike F G H] [MonoidHomClass F G H] {f : F} : Topology.IsInducing f ↔ 𝓝 (1 : G) = (𝓝 (1 : H)).comap f := by rw [Topology.isInducing_iff_nhds] refine ⟨(map_one f ▸ · 1), fun hf x ↦ ?_⟩ rw [← nhds_translation_mul_inv, ← nhds_translation_mul_inv (f x), Filter.comap_comap, hf, Filter.comap_comap] congr 1 ext; simp @[to_additive] lemma TopologicalGroup.isOpenMap_iff_nhds_one {H : Type*} [Monoid H] [TopologicalSpace H] [ContinuousConstSMul H H] {F : Type*} [FunLike F G H] [MonoidHomClass F G H] {f : F} : IsOpenMap f ↔ 𝓝 1 ≤ .map f (𝓝 1) := by refine ⟨fun H ↦ map_one f ▸ H.nhds_le 1, fun h ↦ IsOpenMap.of_nhds_le fun x ↦ ?_⟩ have : Filter.map (f x * ·) (𝓝 1) = 𝓝 (f x) := by simpa [-Homeomorph.map_nhds_eq, Units.smul_def] using (Homeomorph.smul ((toUnits x).map (MonoidHomClass.toMonoidHom f))).map_nhds_eq (1 : H) rw [← map_mul_left_nhds_one x, Filter.map_map, Function.comp_def, ← this] refine (Filter.map_mono h).trans ?_ simp [Function.comp_def] -- TODO: unify with `QuotientGroup.isOpenQuotientMap_mk` /-- Let `A` and `B` be topological groups, and let `φ : A → B` be a continuous surjective group homomorphism. Assume furthermore that `φ` is a quotient map (i.e., `V ⊆ B` is open iff `φ⁻¹ V` is open). Then `φ` is an open quotient map, and in particular an open map. -/ @[to_additive "Let `A` and `B` be topological additive groups, and let `φ : A → B` be a continuous surjective additive group homomorphism. Assume furthermore that `φ` is a quotient map (i.e., `V ⊆ B` is open iff `φ⁻¹ V` is open). Then `φ` is an open quotient map, and in particular an open map."] lemma MonoidHom.isOpenQuotientMap_of_isQuotientMap {A : Type*} [Group A] [TopologicalSpace A] [ContinuousMul A] {B : Type*} [Group B] [TopologicalSpace B] {F : Type*} [FunLike F A B] [MonoidHomClass F A B] {φ : F} (hφ : IsQuotientMap φ) : IsOpenQuotientMap φ where surjective := hφ.surjective continuous := hφ.continuous isOpenMap := by -- We need to check that if `U ⊆ A` is open then `φ⁻¹ (φ U)` is open. intro U hU rw [← hφ.isOpen_preimage] -- It suffices to show that `φ⁻¹ (φ U) = ⋃ (U * k⁻¹)` as `k` runs through the kernel of `φ`, -- as `U * k⁻¹` is open because `x ↦ x * k` is continuous. -- Remark: here is where we use that we have groups not monoids (you cannot avoid -- using both `k` and `k⁻¹` at this point). suffices ⇑φ ⁻¹' (⇑φ '' U) = ⋃ k ∈ ker (φ : A →* B), (fun x ↦ x * k) ⁻¹' U by exact this ▸ isOpen_biUnion (fun k _ ↦ Continuous.isOpen_preimage (by fun_prop) _ hU) ext x -- But this is an elementary calculation. constructor · rintro ⟨y, hyU, hyx⟩ apply Set.mem_iUnion_of_mem (x⁻¹ * y) simp_all · rintro ⟨_, ⟨k, rfl⟩, _, ⟨(hk : φ k = 1), rfl⟩, hx⟩ use x * k, hx rw [map_mul, hk, mul_one] @[to_additive] theorem IsTopologicalGroup.ext {G : Type*} [Group G] {t t' : TopologicalSpace G} (tg : @IsTopologicalGroup G t _) (tg' : @IsTopologicalGroup G t' _) (h : @nhds G t 1 = @nhds G t' 1) : t = t' := TopologicalSpace.ext_nhds fun x ↦ by rw [← @nhds_translation_mul_inv G t _ _ x, ← @nhds_translation_mul_inv G t' _ _ x, ← h] @[to_additive] theorem IsTopologicalGroup.ext_iff {G : Type*} [Group G] {t t' : TopologicalSpace G} (tg : @IsTopologicalGroup G t _) (tg' : @IsTopologicalGroup G t' _) : t = t' ↔ @nhds G t 1 = @nhds G t' 1 := ⟨fun h => h ▸ rfl, tg.ext tg'⟩ @[to_additive] theorem ContinuousInv.of_nhds_one {G : Type*} [Group G] [TopologicalSpace G] (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (fun x : G => x₀ * x) (𝓝 1)) (hconj : ∀ x₀ : G, Tendsto (fun x : G => x₀ * x * x₀⁻¹) (𝓝 1) (𝓝 1)) : ContinuousInv G := by refine ⟨continuous_iff_continuousAt.2 fun x₀ => ?_⟩ have : Tendsto (fun x => x₀⁻¹ * (x₀ * x⁻¹ * x₀⁻¹)) (𝓝 1) (map (x₀⁻¹ * ·) (𝓝 1)) := (tendsto_map.comp <| hconj x₀).comp hinv simpa only [ContinuousAt, hleft x₀, hleft x₀⁻¹, tendsto_map'_iff, Function.comp_def, mul_assoc, mul_inv_rev, inv_mul_cancel_left] using this @[to_additive] theorem IsTopologicalGroup.of_nhds_one' {G : Type u} [Group G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((· * ·) : G → G → G)) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (fun x => x₀ * x) (𝓝 1)) (hright : ∀ x₀ : G, 𝓝 x₀ = map (fun x => x * x₀) (𝓝 1)) : IsTopologicalGroup G := { toContinuousMul := ContinuousMul.of_nhds_one hmul hleft hright toContinuousInv := ContinuousInv.of_nhds_one hinv hleft fun x₀ => le_of_eq (by rw [show (fun x => x₀ * x * x₀⁻¹) = (fun x => x * x₀⁻¹) ∘ fun x => x₀ * x from rfl, ← map_map, ← hleft, hright, map_map] simp [(· ∘ ·)]) } @[to_additive] theorem IsTopologicalGroup.of_nhds_one {G : Type u} [Group G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((· * ·) : G → G → G)) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (x₀ * ·) (𝓝 1)) (hconj : ∀ x₀ : G, Tendsto (x₀ * · * x₀⁻¹) (𝓝 1) (𝓝 1)) : IsTopologicalGroup G := by refine IsTopologicalGroup.of_nhds_one' hmul hinv hleft fun x₀ => ?_ replace hconj : ∀ x₀ : G, map (x₀ * · * x₀⁻¹) (𝓝 1) = 𝓝 1 := fun x₀ => map_eq_of_inverse (x₀⁻¹ * · * x₀⁻¹⁻¹) (by ext; simp [mul_assoc]) (hconj _) (hconj _) rw [← hconj x₀] simpa [Function.comp_def] using hleft _ @[to_additive] theorem IsTopologicalGroup.of_comm_of_nhds_one {G : Type u} [CommGroup G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((· * ·) : G → G → G)) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (x₀ * ·) (𝓝 1)) : IsTopologicalGroup G := IsTopologicalGroup.of_nhds_one hmul hinv hleft (by simpa using tendsto_id) variable (G) in /-- Any first countable topological group has an antitone neighborhood basis `u : ℕ → Set G` for which `(u (n + 1)) ^ 2 ⊆ u n`. The existence of such a neighborhood basis is a key tool for `QuotientGroup.completeSpace` -/ @[to_additive "Any first countable topological additive group has an antitone neighborhood basis `u : ℕ → set G` for which `u (n + 1) + u (n + 1) ⊆ u n`. The existence of such a neighborhood basis is a key tool for `QuotientAddGroup.completeSpace`"] theorem IsTopologicalGroup.exists_antitone_basis_nhds_one [FirstCountableTopology G] : ∃ u : ℕ → Set G, (𝓝 1).HasAntitoneBasis u ∧ ∀ n, u (n + 1) * u (n + 1) ⊆ u n := by rcases (𝓝 (1 : G)).exists_antitone_basis with ⟨u, hu, u_anti⟩ have := ((hu.prod_nhds hu).tendsto_iff hu).mp (by simpa only [mul_one] using continuous_mul.tendsto ((1, 1) : G × G)) simp only [and_self_iff, mem_prod, and_imp, Prod.forall, exists_true_left, Prod.exists, forall_true_left] at this have event_mul : ∀ n : ℕ, ∀ᶠ m in atTop, u m * u m ⊆ u n := by intro n rcases this n with ⟨j, k, -, h⟩ refine atTop_basis.eventually_iff.mpr ⟨max j k, True.intro, fun m hm => ?_⟩ rintro - ⟨a, ha, b, hb, rfl⟩ exact h a b (u_anti ((le_max_left _ _).trans hm) ha) (u_anti ((le_max_right _ _).trans hm) hb) obtain ⟨φ, -, hφ, φ_anti_basis⟩ := HasAntitoneBasis.subbasis_with_rel ⟨hu, u_anti⟩ event_mul exact ⟨u ∘ φ, φ_anti_basis, fun n => hφ n.lt_succ_self⟩ end IsTopologicalGroup section ContinuousDiv variable [TopologicalSpace G] [Div G] [ContinuousDiv G] @[to_additive const_sub] theorem Filter.Tendsto.const_div' (b : G) {c : G} {f : α → G} {l : Filter α} (h : Tendsto f l (𝓝 c)) : Tendsto (fun k : α => b / f k) l (𝓝 (b / c)) := tendsto_const_nhds.div' h @[to_additive] lemma Filter.tendsto_const_div_iff {G : Type*} [CommGroup G] [TopologicalSpace G] [ContinuousDiv G] (b : G) {c : G} {f : α → G} {l : Filter α} : Tendsto (fun k : α ↦ b / f k) l (𝓝 (b / c)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, Filter.Tendsto.const_div' b⟩ convert h.const_div' b with k <;> rw [div_div_cancel] @[to_additive sub_const] theorem Filter.Tendsto.div_const' {c : G} {f : α → G} {l : Filter α} (h : Tendsto f l (𝓝 c)) (b : G) : Tendsto (f · / b) l (𝓝 (c / b)) := h.div' tendsto_const_nhds lemma Filter.tendsto_div_const_iff {G : Type*} [CommGroupWithZero G] [TopologicalSpace G] [ContinuousDiv G] {b : G} (hb : b ≠ 0) {c : G} {f : α → G} {l : Filter α} : Tendsto (f · / b) l (𝓝 (c / b)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, fun h ↦ Filter.Tendsto.div_const' h b⟩ convert h.div_const' b⁻¹ with k <;> rw [div_div, mul_inv_cancel₀ hb, div_one] lemma Filter.tendsto_sub_const_iff {G : Type*} [AddCommGroup G] [TopologicalSpace G] [ContinuousSub G] (b : G) {c : G} {f : α → G} {l : Filter α} : Tendsto (f · - b) l (𝓝 (c - b)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, fun h ↦ Filter.Tendsto.sub_const h b⟩ convert h.sub_const (-b) with k <;> rw [sub_sub, ← sub_eq_add_neg, sub_self, sub_zero] variable [TopologicalSpace α] {f g : α → G} {s : Set α} {x : α} @[to_additive (attr := continuity) continuous_sub_left] lemma continuous_div_left' (a : G) : Continuous (a / ·) := continuous_const.div' continuous_id @[to_additive (attr := continuity) continuous_sub_right] lemma continuous_div_right' (a : G) : Continuous (· / a) := continuous_id.div' continuous_const end ContinuousDiv section DivInvTopologicalGroup variable [Group G] [TopologicalSpace G] [IsTopologicalGroup G] /-- A version of `Homeomorph.mulLeft a b⁻¹` that is defeq to `a / b`. -/ @[to_additive (attr := simps! +simpRhs) "A version of `Homeomorph.addLeft a (-b)` that is defeq to `a - b`."] def Homeomorph.divLeft (x : G) : G ≃ₜ G := { Equiv.divLeft x with continuous_toFun := continuous_const.div' continuous_id continuous_invFun := continuous_inv.mul continuous_const } @[to_additive] theorem isOpenMap_div_left (a : G) : IsOpenMap (a / ·) := (Homeomorph.divLeft _).isOpenMap @[to_additive] theorem isClosedMap_div_left (a : G) : IsClosedMap (a / ·) := (Homeomorph.divLeft _).isClosedMap /-- A version of `Homeomorph.mulRight a⁻¹ b` that is defeq to `b / a`. -/ @[to_additive (attr := simps! +simpRhs) "A version of `Homeomorph.addRight (-a) b` that is defeq to `b - a`. "] def Homeomorph.divRight (x : G) : G ≃ₜ G := { Equiv.divRight x with continuous_toFun := continuous_id.div' continuous_const continuous_invFun := continuous_id.mul continuous_const } @[to_additive] lemma isOpenMap_div_right (a : G) : IsOpenMap (· / a) := (Homeomorph.divRight a).isOpenMap @[to_additive] lemma isClosedMap_div_right (a : G) : IsClosedMap (· / a) := (Homeomorph.divRight a).isClosedMap @[to_additive] theorem tendsto_div_nhds_one_iff {α : Type*} {l : Filter α} {x : G} {u : α → G} : Tendsto (u · / x) l (𝓝 1) ↔ Tendsto u l (𝓝 x) := haveI A : Tendsto (fun _ : α => x) l (𝓝 x) := tendsto_const_nhds ⟨fun h => by simpa using h.mul A, fun h => by simpa using h.div' A⟩ @[to_additive] theorem nhds_translation_div (x : G) : comap (· / x) (𝓝 1) = 𝓝 x := by simpa only [div_eq_mul_inv] using nhds_translation_mul_inv x end DivInvTopologicalGroup section FilterMul section variable (G) [TopologicalSpace G] [Group G] [ContinuousMul G] @[to_additive] theorem IsTopologicalGroup.t1Space (h : @IsClosed G _ {1}) : T1Space G := ⟨fun x => by simpa using isClosedMap_mul_right x _ h⟩ end section variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] variable (S : Subgroup G) [Subgroup.Normal S] [IsClosed (S : Set G)] /-- A subgroup `S` of a topological group `G` acts on `G` properly discontinuously on the left, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`.) -/ @[to_additive "A subgroup `S` of an additive topological group `G` acts on `G` properly discontinuously on the left, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`."] theorem Subgroup.properlyDiscontinuousSMul_of_tendsto_cofinite (S : Subgroup G) (hS : Tendsto S.subtype cofinite (cocompact G)) : ProperlyDiscontinuousSMul S G := { finite_disjoint_inter_image := by intro K L hK hL have H : Set.Finite _ := hS ((hL.prod hK).image continuous_div').compl_mem_cocompact rw [preimage_compl, compl_compl] at H convert H ext x simp only [image_smul, mem_setOf_eq, coe_subtype, mem_preimage, mem_image, Prod.exists] exact Set.smul_inter_ne_empty_iff' } /-- A subgroup `S` of a topological group `G` acts on `G` properly discontinuously on the right, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`.) If `G` is Hausdorff, this can be combined with `t2Space_of_properlyDiscontinuousSMul_of_t2Space` to show that the quotient group `G ⧸ S` is Hausdorff. -/ @[to_additive "A subgroup `S` of an additive topological group `G` acts on `G` properly discontinuously on the right, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`.) If `G` is Hausdorff, this can be combined with `t2Space_of_properlyDiscontinuousVAdd_of_t2Space` to show that the quotient group `G ⧸ S` is Hausdorff."] theorem Subgroup.properlyDiscontinuousSMul_opposite_of_tendsto_cofinite (S : Subgroup G) (hS : Tendsto S.subtype cofinite (cocompact G)) : ProperlyDiscontinuousSMul S.op G := { finite_disjoint_inter_image := by intro K L hK hL have : Continuous fun p : G × G => (p.1⁻¹, p.2) := continuous_inv.prodMap continuous_id have H : Set.Finite _ := hS ((hK.prod hL).image (continuous_mul.comp this)).compl_mem_cocompact simp only [preimage_compl, compl_compl, coe_subtype, comp_apply] at H apply Finite.of_preimage _ (equivOp S).surjective convert H using 1 ext x simp only [image_smul, mem_setOf_eq, coe_subtype, mem_preimage, mem_image, Prod.exists] exact Set.op_smul_inter_ne_empty_iff } end section /-! Some results about an open set containing the product of two sets in a topological group. -/ variable [TopologicalSpace G] [MulOneClass G] [ContinuousMul G] /-- Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `1` such that `K * V ⊆ U`. -/ @[to_additive "Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `0` such that `K + V ⊆ U`."] theorem compact_open_separated_mul_right {K U : Set G} (hK : IsCompact K) (hU : IsOpen U) (hKU : K ⊆ U) : ∃ V ∈ 𝓝 (1 : G), K * V ⊆ U := by refine hK.induction_on ?_ ?_ ?_ ?_ · exact ⟨univ, by simp⟩ · rintro s t hst ⟨V, hV, hV'⟩ exact ⟨V, hV, (mul_subset_mul_right hst).trans hV'⟩ · rintro s t ⟨V, V_in, hV'⟩ ⟨W, W_in, hW'⟩ use V ∩ W, inter_mem V_in W_in rw [union_mul] exact union_subset ((mul_subset_mul_left V.inter_subset_left).trans hV') ((mul_subset_mul_left V.inter_subset_right).trans hW') · intro x hx have := tendsto_mul (show U ∈ 𝓝 (x * 1) by simpa using hU.mem_nhds (hKU hx)) rw [nhds_prod_eq, mem_map, mem_prod_iff] at this rcases this with ⟨t, ht, s, hs, h⟩ rw [← image_subset_iff, image_mul_prod] at h exact ⟨t, mem_nhdsWithin_of_mem_nhds ht, s, hs, h⟩ open MulOpposite /-- Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `1` such that `V * K ⊆ U`. -/ @[to_additive "Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `0` such that `V + K ⊆ U`."] theorem compact_open_separated_mul_left {K U : Set G} (hK : IsCompact K) (hU : IsOpen U) (hKU : K ⊆ U) : ∃ V ∈ 𝓝 (1 : G), V * K ⊆ U := by rcases compact_open_separated_mul_right (hK.image continuous_op) (opHomeomorph.isOpenMap U hU) (image_subset op hKU) with ⟨V, hV : V ∈ 𝓝 (op (1 : G)), hV' : op '' K * V ⊆ op '' U⟩ refine ⟨op ⁻¹' V, continuous_op.continuousAt hV, ?_⟩ rwa [← image_preimage_eq V op_surjective, ← image_op_mul, image_subset_iff, preimage_image_eq _ op_injective] at hV' end section variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] /-- A compact set is covered by finitely many left multiplicative translates of a set with non-empty interior. -/ @[to_additive "A compact set is covered by finitely many left additive translates of a set with non-empty interior."] theorem compact_covered_by_mul_left_translates {K V : Set G} (hK : IsCompact K) (hV : (interior V).Nonempty) : ∃ t : Finset G, K ⊆ ⋃ g ∈ t, (g * ·) ⁻¹' V := by obtain ⟨t, ht⟩ : ∃ t : Finset G, K ⊆ ⋃ x ∈ t, interior ((x * ·) ⁻¹' V) := by refine hK.elim_finite_subcover (fun x => interior <| (x * ·) ⁻¹' V) (fun x => isOpen_interior) ?_ obtain ⟨g₀, hg₀⟩ := hV refine fun g _ => mem_iUnion.2 ⟨g₀ * g⁻¹, ?_⟩ refine preimage_interior_subset_interior_preimage (continuous_const.mul continuous_id) ?_ rwa [mem_preimage, Function.id_def, inv_mul_cancel_right] exact ⟨t, Subset.trans ht <| iUnion₂_mono fun g _ => interior_subset⟩ /-- Every weakly locally compact separable topological group is σ-compact. Note: this is not true if we drop the topological group hypothesis. -/ @[to_additive SeparableWeaklyLocallyCompactAddGroup.sigmaCompactSpace "Every weakly locally compact separable topological additive group is σ-compact. Note: this is not true if we drop the topological group hypothesis."] instance (priority := 100) SeparableWeaklyLocallyCompactGroup.sigmaCompactSpace [SeparableSpace G] [WeaklyLocallyCompactSpace G] : SigmaCompactSpace G := by obtain ⟨L, hLc, hL1⟩ := exists_compact_mem_nhds (1 : G) refine ⟨⟨fun n => (fun x => x * denseSeq G n) ⁻¹' L, ?_, ?_⟩⟩ · intro n exact (Homeomorph.mulRight _).isCompact_preimage.mpr hLc · refine iUnion_eq_univ_iff.2 fun x => ?_ obtain ⟨_, ⟨n, rfl⟩, hn⟩ : (range (denseSeq G) ∩ (fun y => x * y) ⁻¹' L).Nonempty := by rw [← (Homeomorph.mulLeft x).apply_symm_apply 1] at hL1 exact (denseRange_denseSeq G).inter_nhds_nonempty ((Homeomorph.mulLeft x).continuous.continuousAt <| hL1) exact ⟨n, hn⟩ /-- Given two compact sets in a noncompact topological group, there is a translate of the second one that is disjoint from the first one. -/ @[to_additive "Given two compact sets in a noncompact additive topological group, there is a translate of the second one that is disjoint from the first one."] theorem exists_disjoint_smul_of_isCompact [NoncompactSpace G] {K L : Set G} (hK : IsCompact K) (hL : IsCompact L) : ∃ g : G, Disjoint K (g • L) := by have A : ¬K * L⁻¹ = univ := (hK.mul hL.inv).ne_univ obtain ⟨g, hg⟩ : ∃ g, g ∉ K * L⁻¹ := by contrapose! A exact eq_univ_iff_forall.2 A refine ⟨g, ?_⟩ refine disjoint_left.2 fun a ha h'a => hg ?_ rcases h'a with ⟨b, bL, rfl⟩ refine ⟨g * b, ha, b⁻¹, by simpa only [Set.mem_inv, inv_inv] using bL, ?_⟩ simp only [smul_eq_mul, mul_inv_cancel_right] end section variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] @[to_additive] theorem nhds_mul (x y : G) : 𝓝 (x * y) = 𝓝 x * 𝓝 y := calc 𝓝 (x * y) = map (x * ·) (map (· * y) (𝓝 1 * 𝓝 1)) := by simp _ = map₂ (fun a b => x * (a * b * y)) (𝓝 1) (𝓝 1) := by rw [← map₂_mul, map_map₂, map_map₂] _ = map₂ (fun a b => x * a * (b * y)) (𝓝 1) (𝓝 1) := by simp only [mul_assoc] _ = 𝓝 x * 𝓝 y := by rw [← map_mul_left_nhds_one x, ← map_mul_right_nhds_one y, ← map₂_mul, map₂_map_left, map₂_map_right] /-- On a topological group, `𝓝 : G → Filter G` can be promoted to a `MulHom`. -/ @[to_additive (attr := simps) "On an additive topological group, `𝓝 : G → Filter G` can be promoted to an `AddHom`."] def nhdsMulHom : G →ₙ* Filter G where toFun := 𝓝 map_mul' _ _ := nhds_mul _ _ end end FilterMul instance {G} [TopologicalSpace G] [Group G] [IsTopologicalGroup G] : IsTopologicalAddGroup (Additive G) where continuous_neg := @continuous_inv G _ _ _ instance {G} [TopologicalSpace G] [AddGroup G] [IsTopologicalAddGroup G] : IsTopologicalGroup (Multiplicative G) where continuous_inv := @continuous_neg G _ _ _ /-- If `G` is a group with topological `⁻¹`, then it is homeomorphic to its units. -/ @[to_additive "If `G` is an additive group with topological negation, then it is homeomorphic to its additive units."] def toUnits_homeomorph [Group G] [TopologicalSpace G] [ContinuousInv G] : G ≃ₜ Gˣ where toEquiv := toUnits.toEquiv continuous_toFun := Units.continuous_iff.2 ⟨continuous_id, continuous_inv⟩ continuous_invFun := Units.continuous_val @[to_additive] theorem Units.isEmbedding_val [Group G] [TopologicalSpace G] [ContinuousInv G] : IsEmbedding (val : Gˣ → G) := toUnits_homeomorph.symm.isEmbedding @[deprecated (since := "2024-10-26")] alias Units.embedding_val := Units.isEmbedding_val lemma Continuous.of_coeHom_comp [Group G] [Monoid H] [TopologicalSpace G] [TopologicalSpace H] [ContinuousInv G] {f : G →* Hˣ} (hf : Continuous ((Units.coeHom H).comp f)) : Continuous f := by apply continuous_induced_rng.mpr ?_ refine continuous_prodMk.mpr ⟨hf, ?_⟩ simp_rw [← map_inv] exact MulOpposite.continuous_op.comp (hf.comp continuous_inv) namespace Units open MulOpposite (continuous_op continuous_unop) variable [Monoid α] [TopologicalSpace α] [Monoid β] [TopologicalSpace β] @[to_additive] instance [ContinuousMul α] : IsTopologicalGroup αˣ where continuous_inv := Units.continuous_iff.2 <| ⟨continuous_coe_inv, continuous_val⟩ /-- The topological group isomorphism between the units of a product of two monoids, and the product of the units of each monoid. -/ @[to_additive prodAddUnits "The topological group isomorphism between the additive units of a product of two additive monoids, and the product of the additive units of each additive monoid."] def _root_.Homeomorph.prodUnits : (α × β)ˣ ≃ₜ αˣ × βˣ where continuous_toFun := (continuous_fst.units_map (MonoidHom.fst α β)).prodMk (continuous_snd.units_map (MonoidHom.snd α β)) continuous_invFun := Units.continuous_iff.2 ⟨continuous_val.fst'.prodMk continuous_val.snd', continuous_coe_inv.fst'.prodMk continuous_coe_inv.snd'⟩ toEquiv := MulEquiv.prodUnits.toEquiv @[deprecated (since := "2025-02-21")] alias Homeomorph.sumAddUnits := Homeomorph.prodAddUnits @[deprecated (since := "2025-02-21")] protected alias Homeomorph.prodUnits := Homeomorph.prodUnits end Units section LatticeOps variable {ι : Sort*} [Group G] @[to_additive] theorem topologicalGroup_sInf {ts : Set (TopologicalSpace G)} (h : ∀ t ∈ ts, @IsTopologicalGroup G t _) : @IsTopologicalGroup G (sInf ts) _ := letI := sInf ts { toContinuousInv := @continuousInv_sInf _ _ _ fun t ht => @IsTopologicalGroup.toContinuousInv G t _ <| h t ht toContinuousMul := @continuousMul_sInf _ _ _ fun t ht => @IsTopologicalGroup.toContinuousMul G t _ <| h t ht } @[to_additive] theorem topologicalGroup_iInf {ts' : ι → TopologicalSpace G} (h' : ∀ i, @IsTopologicalGroup G (ts' i) _) : @IsTopologicalGroup G (⨅ i, ts' i) _ := by rw [← sInf_range] exact topologicalGroup_sInf (Set.forall_mem_range.mpr h') @[to_additive] theorem topologicalGroup_inf {t₁ t₂ : TopologicalSpace G} (h₁ : @IsTopologicalGroup G t₁ _) (h₂ : @IsTopologicalGroup G t₂ _) : @IsTopologicalGroup G (t₁ ⊓ t₂) _ := by rw [inf_eq_iInf] refine topologicalGroup_iInf fun b => ?_ cases b <;> assumption end LatticeOps
Mathlib/Topology/Algebra/Group/Basic.lean
1,507
1,508
/- Copyright (c) 2023 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.CartanSubalgebra import Mathlib.Algebra.Lie.Weights.Basic /-! # Weights and roots of Lie modules and Lie algebras with respect to Cartan subalgebras Given a Lie algebra `L` which is not necessarily nilpotent, it may be useful to study its representations by restricting them to a nilpotent subalgebra (e.g., a Cartan subalgebra). In the particular case when we view `L` as a module over itself via the adjoint action, the weight spaces of `L` restricted to a nilpotent subalgebra are known as root spaces. Basic definitions and properties of the above ideas are provided in this file. ## Main definitions * `LieAlgebra.rootSpace` * `LieAlgebra.corootSpace` * `LieAlgebra.rootSpaceWeightSpaceProduct` * `LieAlgebra.rootSpaceProduct` * `LieAlgebra.zeroRootSubalgebra_eq_iff_is_cartan` -/ suppress_compilation open Set variable {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] (H : LieSubalgebra R L) [LieRing.IsNilpotent H] {M : Type*} [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] namespace LieAlgebra open scoped TensorProduct open TensorProduct.LieModule LieModule /-- Given a nilpotent Lie subalgebra `H ⊆ L`, the root space of a map `χ : H → R` is the weight space of `L` regarded as a module of `H` via the adjoint action. -/ abbrev rootSpace (χ : H → R) : LieSubmodule R H L := genWeightSpace L χ theorem zero_rootSpace_eq_top_of_nilpotent [LieRing.IsNilpotent L] : rootSpace (⊤ : LieSubalgebra R L) 0 = ⊤ := zero_genWeightSpace_eq_top_of_nilpotent L @[simp] theorem rootSpace_comap_eq_genWeightSpace (χ : H → R) : (rootSpace H χ).comap H.incl' = genWeightSpace H χ := comap_genWeightSpace_eq_of_injective Subtype.coe_injective variable {H} theorem lie_mem_genWeightSpace_of_mem_genWeightSpace {χ₁ χ₂ : H → R} {x : L} {m : M} (hx : x ∈ rootSpace H χ₁) (hm : m ∈ genWeightSpace M χ₂) : ⁅x, m⁆ ∈ genWeightSpace M (χ₁ + χ₂) := by rw [genWeightSpace, LieSubmodule.mem_iInf] intro y replace hx : x ∈ genWeightSpaceOf L (χ₁ y) y := by rw [rootSpace, genWeightSpace, LieSubmodule.mem_iInf] at hx; exact hx y replace hm : m ∈ genWeightSpaceOf M (χ₂ y) y := by rw [genWeightSpace, LieSubmodule.mem_iInf] at hm; exact hm y exact lie_mem_maxGenEigenspace_toEnd hx hm lemma toEnd_pow_apply_mem {χ₁ χ₂ : H → R} {x : L} {m : M} (hx : x ∈ rootSpace H χ₁) (hm : m ∈ genWeightSpace M χ₂) (n) : (toEnd R L M x ^ n : Module.End R M) m ∈ genWeightSpace M (n • χ₁ + χ₂) := by
induction n with | zero => simpa using hm | succ n IH => simp only [pow_succ', Module.End.mul_apply, toEnd_apply_apply, Nat.cast_add, Nat.cast_one, rootSpace] convert lie_mem_genWeightSpace_of_mem_genWeightSpace hx IH using 2 rw [succ_nsmul, ← add_assoc, add_comm (n • _)] variable (R L H M)
Mathlib/Algebra/Lie/Weights/Cartan.lean
72
81
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kenny Lau -/ import Mathlib.Data.List.Forall2 /-! # zip & unzip This file provides results about `List.zipWith`, `List.zip` and `List.unzip` (definitions are in core Lean). `zipWith f l₁ l₂` applies `f : α → β → γ` pointwise to a list `l₁ : List α` and `l₂ : List β`. It applies, until one of the lists is exhausted. For example, `zipWith f [0, 1, 2] [6.28, 31] = [f 0 6.28, f 1 31]`. `zip` is `zipWith` applied to `Prod.mk`. For example, `zip [a₁, a₂] [b₁, b₂, b₃] = [(a₁, b₁), (a₂, b₂)]`. `unzip` undoes `zip`. For example, `unzip [(a₁, b₁), (a₂, b₂)] = ([a₁, a₂], [b₁, b₂])`. -/ -- Make sure we don't import algebra assert_not_exists Monoid universe u open Nat namespace List variable {α : Type u} {β γ δ ε : Type*} @[simp] theorem zip_swap : ∀ (l₁ : List α) (l₂ : List β), (zip l₁ l₂).map Prod.swap = zip l₂ l₁ | [], _ => zip_nil_right.symm | l₁, [] => by rw [zip_nil_right]; rfl | a :: l₁, b :: l₂ => by simp only [zip_cons_cons, map_cons, zip_swap l₁ l₂, Prod.swap_prod_mk] theorem forall_zipWith {f : α → β → γ} {p : γ → Prop} : ∀ {l₁ : List α} {l₂ : List β}, length l₁ = length l₂ → (Forall p (zipWith f l₁ l₂) ↔ Forall₂ (fun x y => p (f x y)) l₁ l₂) | [], [], _ => by simp | a :: l₁, b :: l₂, h => by simp only [length_cons, succ_inj] at h simp [forall_zipWith h] theorem unzip_swap (l : List (α × β)) : unzip (l.map Prod.swap) = (unzip l).swap := by simp only [unzip_eq_map, map_map] rfl @[congr] theorem zipWith_congr (f g : α → β → γ) (la : List α) (lb : List β) (h : List.Forall₂ (fun a b => f a b = g a b) la lb) : zipWith f la lb = zipWith g la lb := by induction h with | nil => rfl | cons hfg _ ih => exact congr_arg₂ _ hfg ih theorem zipWith_zipWith_left (f : δ → γ → ε) (g : α → β → δ) : ∀ (la : List α) (lb : List β) (lc : List γ), zipWith f (zipWith g la lb) lc = zipWith3 (fun a b c => f (g a b) c) la lb lc | [], _, _ => rfl | _ :: _, [], _ => rfl | _ :: _, _ :: _, [] => rfl | _ :: as, _ :: bs, _ :: cs => congr_arg (cons _) <| zipWith_zipWith_left f g as bs cs theorem zipWith_zipWith_right (f : α → δ → ε) (g : β → γ → δ) : ∀ (la : List α) (lb : List β) (lc : List γ), zipWith f la (zipWith g lb lc) = zipWith3 (fun a b c => f a (g b c)) la lb lc | [], _, _ => rfl | _ :: _, [], _ => rfl | _ :: _, _ :: _, [] => rfl | _ :: as, _ :: bs, _ :: cs => congr_arg (cons _) <| zipWith_zipWith_right f g as bs cs @[simp] theorem zipWith3_same_left (f : α → α → β → γ) : ∀ (la : List α) (lb : List β), zipWith3 f la la lb = zipWith (fun a b => f a a b) la lb | [], _ => rfl | _ :: _, [] => rfl | _ :: as, _ :: bs => congr_arg (cons _) <| zipWith3_same_left f as bs @[simp] theorem zipWith3_same_mid (f : α → β → α → γ) : ∀ (la : List α) (lb : List β), zipWith3 f la lb la = zipWith (fun a b => f a b a) la lb | [], _ => rfl | _ :: _, [] => rfl | _ :: as, _ :: bs => congr_arg (cons _) <| zipWith3_same_mid f as bs @[simp] theorem zipWith3_same_right (f : α → β → β → γ) : ∀ (la : List α) (lb : List β), zipWith3 f la lb lb = zipWith (fun a b => f a b b) la lb | [], _ => rfl | _ :: _, [] => rfl | _ :: as, _ :: bs => congr_arg (cons _) <| zipWith3_same_right f as bs instance (f : α → α → β) [IsSymmOp f] : IsSymmOp (zipWith f) := ⟨fun _ _ => zipWith_comm_of_comm IsSymmOp.symm_op⟩ @[simp] theorem length_revzip (l : List α) : length (revzip l) = length l := by simp only [revzip, length_zip, length_reverse, min_self] @[simp] theorem unzip_revzip (l : List α) : (revzip l).unzip = (l, l.reverse) := unzip_zip length_reverse.symm @[simp] theorem revzip_map_fst (l : List α) : (revzip l).map Prod.fst = l := by rw [← unzip_fst, unzip_revzip] @[simp] theorem revzip_map_snd (l : List α) : (revzip l).map Prod.snd = l.reverse := by rw [← unzip_snd, unzip_revzip] theorem reverse_revzip (l : List α) : reverse l.revzip = revzip l.reverse := by rw [← zip_unzip (revzip l).reverse] simp [unzip_eq_map, revzip, map_reverse, map_fst_zip, map_snd_zip] theorem revzip_swap (l : List α) : (revzip l).map Prod.swap = revzip l.reverse := by simp [revzip] @[deprecated (since := "2025-02-14")] alias get?_zipWith' := getElem?_zipWith' @[deprecated (since := "2025-02-14")] alias get?_zipWith_eq_some := getElem?_zipWith_eq_some @[deprecated (since := "2025-02-14")] alias get?_zip_eq_some := getElem?_zip_eq_some theorem mem_zip_inits_tails {l : List α} {init tail : List α} : (init, tail) ∈ zip l.inits l.tails ↔ init ++ tail = l := by induction' l with hd tl ih generalizing init tail <;> simp_rw [tails, inits, zip_cons_cons] · simp · constructor <;> rw [mem_cons, zip_map_left, mem_map, Prod.exists] · rintro (⟨rfl, rfl⟩ | ⟨_, _, h, rfl, rfl⟩) · simp · simp [ih.mp h] · rcases init with - | ⟨hd', tl'⟩ · rintro rfl simp · intro h right use tl', tail simp_all end List
Mathlib/Data/List/Zip.lean
366
373
/- Copyright (c) 2018 Michael Jendrusch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Jendrusch, Kim Morrison, Bhavik Mehta, Jakob von Raumer -/ import Mathlib.CategoryTheory.EqToHom import Mathlib.CategoryTheory.Functor.Trifunctor import Mathlib.CategoryTheory.Products.Basic /-! # Monoidal categories A monoidal category is a category equipped with a tensor product, unitors, and an associator. In the definition, we provide the tensor product as a pair of functions * `tensorObj : C → C → C` * `tensorHom : (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))` and allow use of the overloaded notation `⊗` for both. The unitors and associator are provided componentwise. The tensor product can be expressed as a functor via `tensor : C × C ⥤ C`. The unitors and associator are gathered together as natural isomorphisms in `leftUnitor_nat_iso`, `rightUnitor_nat_iso` and `associator_nat_iso`. Some consequences of the definition are proved in other files after proving the coherence theorem, e.g. `(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom` in `CategoryTheory.Monoidal.CoherenceLemmas`. ## Implementation notes In the definition of monoidal categories, we also provide the whiskering operators: * `whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : X ⊗ Y₁ ⟶ X ⊗ Y₂`, denoted by `X ◁ f`, * `whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : X₁ ⊗ Y ⟶ X₂ ⊗ Y`, denoted by `f ▷ Y`. These are products of an object and a morphism (the terminology "whiskering" is borrowed from 2-category theory). The tensor product of morphisms `tensorHom` can be defined in terms of the whiskerings. There are two possible such definitions, which are related by the exchange property of the whiskerings. These two definitions are accessed by `tensorHom_def` and `tensorHom_def'`. By default, `tensorHom` is defined so that `tensorHom_def` holds definitionally. If you want to provide `tensorHom` and define `whiskerLeft` and `whiskerRight` in terms of it, you can use the alternative constructor `CategoryTheory.MonoidalCategory.ofTensorHom`. The whiskerings are useful when considering simp-normal forms of morphisms in monoidal categories. ### Simp-normal form for morphisms Rewriting involving associators and unitors could be very complicated. We try to ease this complexity by putting carefully chosen simp lemmas that rewrite any morphisms into the simp-normal form defined below. Rewriting into simp-normal form is especially useful in preprocessing performed by the `coherence` tactic. The simp-normal form of morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of morphisms like `f₁ ≫ f₂ ≫ f₃ ≫ f₄ ≫ f₅` such that each `fᵢ` is either a structural morphisms (morphisms made up only of identities, associators, unitors) or non-structural morphisms, and 2. each non-structural morphism in the composition is of the form `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅`, where each `Xᵢ` is a object that is not the identity or a tensor and `f` is a non-structural morphisms that is not the identity or a composite. Note that `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅` is actually `X₁ ◁ (X₂ ◁ (X₃ ◁ ((f ▷ X₄) ▷ X₅)))`. Currently, the simp lemmas don't rewrite `𝟙 X ⊗ f` and `f ⊗ 𝟙 Y` into `X ◁ f` and `f ▷ Y`, respectively, since it requires a huge refactoring. We hope to add these simp lemmas soon. ## References * Tensor categories, Etingof, Gelaki, Nikshych, Ostrik, http://www-math.mit.edu/~etingof/egnobookfinal.pdf * <https://stacks.math.columbia.edu/tag/0FFK>. -/ universe v u open CategoryTheory.Category open CategoryTheory.Iso namespace CategoryTheory /-- Auxiliary structure to carry only the data fields of (and provide notation for) `MonoidalCategory`. -/ class MonoidalCategoryStruct (C : Type u) [𝒞 : Category.{v} C] where /-- curried tensor product of objects -/ tensorObj : C → C → C /-- left whiskering for morphisms -/ whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂ /-- right whiskering for morphisms -/ whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ -- By default, it is defined in terms of whiskerings. tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂) := whiskerRight f X₂ ≫ whiskerLeft Y₁ g /-- The tensor unity in the monoidal structure `𝟙_ C` -/ tensorUnit (C) : C /-- The associator isomorphism `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ associator : ∀ X Y Z : C, tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z) /-- The left unitor: `𝟙_ C ⊗ X ≃ X` -/ leftUnitor : ∀ X : C, tensorObj tensorUnit X ≅ X /-- The right unitor: `X ⊗ 𝟙_ C ≃ X` -/ rightUnitor : ∀ X : C, tensorObj X tensorUnit ≅ X namespace MonoidalCategory export MonoidalCategoryStruct (tensorObj whiskerLeft whiskerRight tensorHom tensorUnit associator leftUnitor rightUnitor) end MonoidalCategory namespace MonoidalCategory /-- Notation for `tensorObj`, the tensor product of objects in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorObj /-- Notation for the `whiskerLeft` operator of monoidal categories -/ scoped infixr:81 " ◁ " => MonoidalCategoryStruct.whiskerLeft /-- Notation for the `whiskerRight` operator of monoidal categories -/ scoped infixl:81 " ▷ " => MonoidalCategoryStruct.whiskerRight /-- Notation for `tensorHom`, the tensor product of morphisms in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorHom /-- Notation for `tensorUnit`, the two-sided identity of `⊗` -/ scoped notation "𝟙_ " C:arg => MonoidalCategoryStruct.tensorUnit C /-- Notation for the monoidal `associator`: `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ scoped notation "α_" => MonoidalCategoryStruct.associator /-- Notation for the `leftUnitor`: `𝟙_C ⊗ X ≃ X` -/ scoped notation "λ_" => MonoidalCategoryStruct.leftUnitor /-- Notation for the `rightUnitor`: `X ⊗ 𝟙_C ≃ X` -/ scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor /-- The property that the pentagon relation is satisfied by four objects in a category equipped with a `MonoidalCategoryStruct`. -/ def Pentagon {C : Type u} [Category.{v} C] [MonoidalCategoryStruct C] (Y₁ Y₂ Y₃ Y₄ : C) : Prop := (α_ Y₁ Y₂ Y₃).hom ▷ Y₄ ≫ (α_ Y₁ (Y₂ ⊗ Y₃) Y₄).hom ≫ Y₁ ◁ (α_ Y₂ Y₃ Y₄).hom = (α_ (Y₁ ⊗ Y₂) Y₃ Y₄).hom ≫ (α_ Y₁ Y₂ (Y₃ ⊗ Y₄)).hom end MonoidalCategory open MonoidalCategory /-- In a monoidal category, we can take the tensor product of objects, `X ⊗ Y` and of morphisms `f ⊗ g`. Tensor product does not need to be strictly associative on objects, but there is a specified associator, `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)`. There is a tensor unit `𝟙_ C`, with specified left and right unitor isomorphisms `λ_ X : 𝟙_ C ⊗ X ≅ X` and `ρ_ X : X ⊗ 𝟙_ C ≅ X`. These associators and unitors satisfy the pentagon and triangle equations. -/ @[stacks 0FFK] -- Porting note: The Mathport did not translate the temporary notation class MonoidalCategory (C : Type u) [𝒞 : Category.{v} C] extends MonoidalCategoryStruct C where tensorHom_def {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : f ⊗ g = (f ▷ X₂) ≫ (Y₁ ◁ g) := by aesop_cat /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ tensor_id : ∀ X₁ X₂ : C, 𝟙 X₁ ⊗ 𝟙 X₂ = 𝟙 (X₁ ⊗ X₂) := by aesop_cat /-- Tensor product of compositions is composition of tensor products: `(f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂)` -/ tensor_comp : ∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂), (f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂) := by aesop_cat whiskerLeft_id : ∀ (X Y : C), X ◁ 𝟙 Y = 𝟙 (X ⊗ Y) := by aesop_cat id_whiskerRight : ∀ (X Y : C), 𝟙 X ▷ Y = 𝟙 (X ⊗ Y) := by aesop_cat /-- Naturality of the associator isomorphism: `(f₁ ⊗ f₂) ⊗ f₃ ≃ f₁ ⊗ (f₂ ⊗ f₃)` -/ associator_naturality : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃), ((f₁ ⊗ f₂) ⊗ f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗ (f₂ ⊗ f₃)) := by aesop_cat /-- Naturality of the left unitor, commutativity of `𝟙_ C ⊗ X ⟶ 𝟙_ C ⊗ Y ⟶ Y` and `𝟙_ C ⊗ X ⟶ X ⟶ Y` -/ leftUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), 𝟙_ _ ◁ f ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by aesop_cat /-- Naturality of the right unitor: commutativity of `X ⊗ 𝟙_ C ⟶ Y ⊗ 𝟙_ C ⟶ Y` and `X ⊗ 𝟙_ C ⟶ X ⟶ Y` -/ rightUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), f ▷ 𝟙_ _ ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by aesop_cat /-- The pentagon identity relating the isomorphism between `X ⊗ (Y ⊗ (Z ⊗ W))` and `((X ⊗ Y) ⊗ Z) ⊗ W` -/ pentagon : ∀ W X Y Z : C, (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom = (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom := by aesop_cat /-- The identity relating the isomorphisms between `X ⊗ (𝟙_ C ⊗ Y)`, `(X ⊗ 𝟙_ C) ⊗ Y` and `X ⊗ Y` -/ triangle : ∀ X Y : C, (α_ X (𝟙_ _) Y).hom ≫ X ◁ (λ_ Y).hom = (ρ_ X).hom ▷ Y := by aesop_cat attribute [reassoc] MonoidalCategory.tensorHom_def attribute [reassoc, simp] MonoidalCategory.whiskerLeft_id attribute [reassoc, simp] MonoidalCategory.id_whiskerRight attribute [reassoc] MonoidalCategory.tensor_comp attribute [simp] MonoidalCategory.tensor_comp attribute [reassoc] MonoidalCategory.associator_naturality attribute [reassoc] MonoidalCategory.leftUnitor_naturality attribute [reassoc] MonoidalCategory.rightUnitor_naturality attribute [reassoc (attr := simp)] MonoidalCategory.pentagon attribute [reassoc (attr := simp)] MonoidalCategory.triangle namespace MonoidalCategory variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C] @[simp] theorem id_tensorHom (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : 𝟙 X ⊗ f = X ◁ f := by simp [tensorHom_def] @[simp] theorem tensorHom_id {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : f ⊗ 𝟙 Y = f ▷ Y := by simp [tensorHom_def] @[reassoc, simp] theorem whiskerLeft_comp (W : C) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : W ◁ (f ≫ g) = W ◁ f ≫ W ◁ g := by simp only [← id_tensorHom, ← tensor_comp, comp_id] @[reassoc, simp] theorem id_whiskerLeft {X Y : C} (f : X ⟶ Y) : 𝟙_ C ◁ f = (λ_ X).hom ≫ f ≫ (λ_ Y).inv := by rw [← assoc, ← leftUnitor_naturality]; simp [id_tensorHom] @[reassoc, simp] theorem tensor_whiskerLeft (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f = (α_ X Y Z).hom ≫ X ◁ Y ◁ f ≫ (α_ X Y Z').inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc, simp] theorem comp_whiskerRight {W X Y : C} (f : W ⟶ X) (g : X ⟶ Y) (Z : C) : (f ≫ g) ▷ Z = f ▷ Z ≫ g ▷ Z := by simp only [← tensorHom_id, ← tensor_comp, id_comp] @[reassoc, simp] theorem whiskerRight_id {X Y : C} (f : X ⟶ Y) : f ▷ 𝟙_ C = (ρ_ X).hom ≫ f ≫ (ρ_ Y).inv := by rw [← assoc, ← rightUnitor_naturality]; simp [tensorHom_id] @[reassoc, simp] theorem whiskerRight_tensor {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ (Y ⊗ Z) = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom := by simp only [← id_tensorHom, ← tensorHom_id] rw [associator_naturality] simp [tensor_id] @[reassoc, simp] theorem whisker_assoc (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : (X ◁ f) ▷ Z = (α_ X Y Z).hom ≫ X ◁ f ▷ Z ≫ (α_ X Y' Z).inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc] theorem whisker_exchange {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) : W ◁ g ≫ f ▷ Z = f ▷ Y ≫ X ◁ g := by simp only [← id_tensorHom, ← tensorHom_id, ← tensor_comp, id_comp, comp_id] @[reassoc] theorem tensorHom_def' {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : f ⊗ g = X₁ ◁ g ≫ f ▷ Y₂ := whisker_exchange f g ▸ tensorHom_def f g @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.hom ≫ X ◁ f.inv = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.hom ▷ Z ≫ f.inv ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.inv ≫ X ◁ f.hom = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.inv ▷ Z ≫ f.hom ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ f ≫ X ◁ inv f = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, IsIso.hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : f ▷ Z ≫ inv f ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, IsIso.hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ inv f ≫ X ◁ f = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, IsIso.inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : inv f ▷ Z ≫ f ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, IsIso.inv_hom_id, id_whiskerRight] /-- The left whiskering of an isomorphism is an isomorphism. -/ @[simps] def whiskerLeftIso (X : C) {Y Z : C} (f : Y ≅ Z) : X ⊗ Y ≅ X ⊗ Z where hom := X ◁ f.hom inv := X ◁ f.inv instance whiskerLeft_isIso (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : IsIso (X ◁ f) := (whiskerLeftIso X (asIso f)).isIso_hom @[simp] theorem inv_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : inv (X ◁ f) = X ◁ inv f := by aesop_cat @[simp] lemma whiskerLeftIso_refl (W X : C) : whiskerLeftIso W (Iso.refl X) = Iso.refl (W ⊗ X) := Iso.ext (whiskerLeft_id W X) @[simp] lemma whiskerLeftIso_trans (W : C) {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) : whiskerLeftIso W (f ≪≫ g) = whiskerLeftIso W f ≪≫ whiskerLeftIso W g := Iso.ext (whiskerLeft_comp W f.hom g.hom) @[simp] lemma whiskerLeftIso_symm (W : C) {X Y : C} (f : X ≅ Y) : (whiskerLeftIso W f).symm = whiskerLeftIso W f.symm := rfl /-- The right whiskering of an isomorphism is an isomorphism. -/ @[simps!] def whiskerRightIso {X Y : C} (f : X ≅ Y) (Z : C) : X ⊗ Z ≅ Y ⊗ Z where hom := f.hom ▷ Z inv := f.inv ▷ Z instance whiskerRight_isIso {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : IsIso (f ▷ Z) := (whiskerRightIso (asIso f) Z).isIso_hom @[simp] theorem inv_whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : inv (f ▷ Z) = inv f ▷ Z := by aesop_cat @[simp] lemma whiskerRightIso_refl (X W : C) : whiskerRightIso (Iso.refl X) W = Iso.refl (X ⊗ W) := Iso.ext (id_whiskerRight X W) @[simp] lemma whiskerRightIso_trans {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) (W : C) : whiskerRightIso (f ≪≫ g) W = whiskerRightIso f W ≪≫ whiskerRightIso g W := Iso.ext (comp_whiskerRight f.hom g.hom W) @[simp] lemma whiskerRightIso_symm {X Y : C} (f : X ≅ Y) (W : C) : (whiskerRightIso f W).symm = whiskerRightIso f.symm W := rfl /-- The tensor product of two isomorphisms is an isomorphism. -/ @[simps] def tensorIso {X Y X' Y' : C} (f : X ≅ Y) (g : X' ≅ Y') : X ⊗ X' ≅ Y ⊗ Y' where hom := f.hom ⊗ g.hom inv := f.inv ⊗ g.inv hom_inv_id := by rw [← tensor_comp, Iso.hom_inv_id, Iso.hom_inv_id, ← tensor_id] inv_hom_id := by rw [← tensor_comp, Iso.inv_hom_id, Iso.inv_hom_id, ← tensor_id] /-- Notation for `tensorIso`, the tensor product of isomorphisms -/ scoped infixr:70 " ⊗ " => tensorIso theorem tensorIso_def {X Y X' Y' : C} (f : X ≅ Y) (g : X' ≅ Y') : f ⊗ g = whiskerRightIso f X' ≪≫ whiskerLeftIso Y g := Iso.ext (tensorHom_def f.hom g.hom) theorem tensorIso_def' {X Y X' Y' : C} (f : X ≅ Y) (g : X' ≅ Y') : f ⊗ g = whiskerLeftIso X g ≪≫ whiskerRightIso f Y' := Iso.ext (tensorHom_def' f.hom g.hom) instance tensor_isIso {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : IsIso (f ⊗ g) := (asIso f ⊗ asIso g).isIso_hom @[simp] theorem inv_tensor {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : inv (f ⊗ g) = inv f ⊗ inv g := by simp [tensorHom_def ,whisker_exchange] variable {W X Y Z : C} theorem whiskerLeft_dite {P : Prop} [Decidable P] (X : C) {Y Z : C} (f : P → (Y ⟶ Z)) (f' : ¬P → (Y ⟶ Z)) : X ◁ (if h : P then f h else f' h) = if h : P then X ◁ f h else X ◁ f' h := by split_ifs <;> rfl theorem dite_whiskerRight {P : Prop} [Decidable P] {X Y : C} (f : P → (X ⟶ Y)) (f' : ¬P → (X ⟶ Y)) (Z : C) : (if h : P then f h else f' h) ▷ Z = if h : P then f h ▷ Z else f' h ▷ Z := by split_ifs <;> rfl theorem tensor_dite {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (f ⊗ if h : P then g h else g' h) = if h : P then f ⊗ g h else f ⊗ g' h := by split_ifs <;> rfl theorem dite_tensor {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (if h : P then g h else g' h) ⊗ f = if h : P then g h ⊗ f else g' h ⊗ f := by split_ifs <;> rfl @[simp] theorem whiskerLeft_eqToHom (X : C) {Y Z : C} (f : Y = Z) : X ◁ eqToHom f = eqToHom (congr_arg₂ tensorObj rfl f) := by cases f simp only [whiskerLeft_id, eqToHom_refl] @[simp] theorem eqToHom_whiskerRight {X Y : C} (f : X = Y) (Z : C) : eqToHom f ▷ Z = eqToHom (congr_arg₂ tensorObj f rfl) := by cases f simp only [id_whiskerRight, eqToHom_refl] @[reassoc] theorem associator_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) := by simp @[reassoc] theorem associator_inv_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z := by simp @[reassoc] theorem whiskerRight_tensor_symm {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ Y ▷ Z = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv := by simp @[reassoc] theorem associator_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom = (α_ X Y Z).hom ≫ X ◁ f ▷ Z := by simp @[reassoc] theorem associator_inv_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : X ◁ f ▷ Z ≫ (α_ X Y' Z).inv = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z := by simp @[reassoc] theorem whisker_assoc_symm (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : X ◁ f ▷ Z = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom := by simp @[reassoc] theorem associator_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom = (α_ X Y Z).hom ≫ X ◁ Y ◁ f := by simp @[reassoc] theorem associator_inv_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f ≫ (α_ X Y Z').inv = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f := by simp @[reassoc] theorem tensor_whiskerLeft_symm (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom := by simp @[reassoc] theorem leftUnitor_inv_naturality {X Y : C} (f : X ⟶ Y) : f ≫ (λ_ Y).inv = (λ_ X).inv ≫ _ ◁ f := by simp @[reassoc] theorem id_whiskerLeft_symm {X X' : C} (f : X ⟶ X') : f = (λ_ X).inv ≫ 𝟙_ C ◁ f ≫ (λ_ X').hom := by simp only [id_whiskerLeft, assoc, inv_hom_id, comp_id, inv_hom_id_assoc] @[reassoc] theorem rightUnitor_inv_naturality {X X' : C} (f : X ⟶ X') : f ≫ (ρ_ X').inv = (ρ_ X).inv ≫ f ▷ _ := by simp @[reassoc] theorem whiskerRight_id_symm {X Y : C} (f : X ⟶ Y) : f = (ρ_ X).inv ≫ f ▷ 𝟙_ C ≫ (ρ_ Y).hom := by simp theorem whiskerLeft_iff {X Y : C} (f g : X ⟶ Y) : 𝟙_ C ◁ f = 𝟙_ C ◁ g ↔ f = g := by simp theorem whiskerRight_iff {X Y : C} (f g : X ⟶ Y) : f ▷ 𝟙_ C = g ▷ 𝟙_ C ↔ f = g := by simp /-! The lemmas in the next section are true by coherence, but we prove them directly as they are used in proving the coherence theorem. -/ section @[reassoc (attr := simp)] theorem pentagon_inv : W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z = (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv : (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom = W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv := by rw [← cancel_epi (W ◁ (α_ X Y Z).inv), ← cancel_mono (α_ (W ⊗ X) Y Z).inv] simp @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_inv : (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom = (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_inv : W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv = (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z := by simp [← cancel_epi (W ◁ (α_ X Y Z).inv)] @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_hom_hom : (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv = (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_hom : (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv = (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z := by rw [← cancel_epi (α_ W X (Y ⊗ Z)).inv, ← cancel_mono ((α_ W X Y).inv ▷ Z)] simp @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_inv_hom : (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv = (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_hom : (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom = (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom := by simp [← cancel_epi ((α_ W X Y).hom ▷ Z)] @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_inv_inv : (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z = W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem triangle_assoc_comp_right (X Y : C) : (α_ X (𝟙_ C) Y).inv ≫ ((ρ_ X).hom ▷ Y) = X ◁ (λ_ Y).hom := by rw [← triangle, Iso.inv_hom_id_assoc] @[reassoc (attr := simp)] theorem triangle_assoc_comp_right_inv (X Y : C) : (ρ_ X).inv ▷ Y ≫ (α_ X (𝟙_ C) Y).hom = X ◁ (λ_ Y).inv := by simp [← cancel_mono (X ◁ (λ_ Y).hom)] @[reassoc (attr := simp)] theorem triangle_assoc_comp_left_inv (X Y : C) : (X ◁ (λ_ Y).inv) ≫ (α_ X (𝟙_ C) Y).inv = (ρ_ X).inv ▷ Y := by simp [← cancel_mono ((ρ_ X).hom ▷ Y)] /-- We state it as a simp lemma, which is regarded as an involved version of `id_whiskerRight X Y : 𝟙 X ▷ Y = 𝟙 (X ⊗ Y)`. -/ @[reassoc, simp] theorem leftUnitor_whiskerRight (X Y : C) : (λ_ X).hom ▷ Y = (α_ (𝟙_ C) X Y).hom ≫ (λ_ (X ⊗ Y)).hom := by rw [← whiskerLeft_iff, whiskerLeft_comp, ← cancel_epi (α_ _ _ _).hom, ← cancel_epi ((α_ _ _ _).hom ▷ _), pentagon_assoc, triangle, ← associator_naturality_middle, ← comp_whiskerRight_assoc, triangle, associator_naturality_left] @[reassoc, simp] theorem leftUnitor_inv_whiskerRight (X Y : C) : (λ_ X).inv ▷ Y = (λ_ (X ⊗ Y)).inv ≫ (α_ (𝟙_ C) X Y).inv := eq_of_inv_eq_inv (by simp) @[reassoc, simp] theorem whiskerLeft_rightUnitor (X Y : C) : X ◁ (ρ_ Y).hom = (α_ X Y (𝟙_ C)).inv ≫ (ρ_ (X ⊗ Y)).hom := by rw [← whiskerRight_iff, comp_whiskerRight, ← cancel_epi (α_ _ _ _).inv, ← cancel_epi (X ◁ (α_ _ _ _).inv), pentagon_inv_assoc, triangle_assoc_comp_right, ← associator_inv_naturality_middle, ← whiskerLeft_comp_assoc, triangle_assoc_comp_right, associator_inv_naturality_right] @[reassoc, simp] theorem whiskerLeft_rightUnitor_inv (X Y : C) : X ◁ (ρ_ Y).inv = (ρ_ (X ⊗ Y)).inv ≫ (α_ X Y (𝟙_ C)).hom := eq_of_inv_eq_inv (by simp) @[reassoc] theorem leftUnitor_tensor (X Y : C) : (λ_ (X ⊗ Y)).hom = (α_ (𝟙_ C) X Y).inv ≫ (λ_ X).hom ▷ Y := by simp @[reassoc] theorem leftUnitor_tensor_inv (X Y : C) : (λ_ (X ⊗ Y)).inv = (λ_ X).inv ▷ Y ≫ (α_ (𝟙_ C) X Y).hom := by simp @[reassoc] theorem rightUnitor_tensor (X Y : C) : (ρ_ (X ⊗ Y)).hom = (α_ X Y (𝟙_ C)).hom ≫ X ◁ (ρ_ Y).hom := by simp @[reassoc] theorem rightUnitor_tensor_inv (X Y : C) : (ρ_ (X ⊗ Y)).inv = X ◁ (ρ_ Y).inv ≫ (α_ X Y (𝟙_ C)).inv := by simp end @[reassoc] theorem associator_inv_naturality {X Y Z X' Y' Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : (f ⊗ g ⊗ h) ≫ (α_ X' Y' Z').inv = (α_ X Y Z).inv ≫ ((f ⊗ g) ⊗ h) := by simp [tensorHom_def] @[reassoc, simp] theorem associator_conjugation {X X' Y Y' Z Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : (f ⊗ g) ⊗ h = (α_ X Y Z).hom ≫ (f ⊗ g ⊗ h) ≫ (α_ X' Y' Z').inv := by rw [associator_inv_naturality, hom_inv_id_assoc] @[reassoc] theorem associator_inv_conjugation {X X' Y Y' Z Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : f ⊗ g ⊗ h = (α_ X Y Z).inv ≫ ((f ⊗ g) ⊗ h) ≫ (α_ X' Y' Z').hom := by rw [associator_naturality, inv_hom_id_assoc] -- TODO these next two lemmas aren't so fundamental, and perhaps could be removed -- (replacing their usages by their proofs). @[reassoc] theorem id_tensor_associator_naturality {X Y Z Z' : C} (h : Z ⟶ Z') : (𝟙 (X ⊗ Y) ⊗ h) ≫ (α_ X Y Z').hom = (α_ X Y Z).hom ≫ (𝟙 X ⊗ 𝟙 Y ⊗ h) := by rw [← tensor_id, associator_naturality] @[reassoc] theorem id_tensor_associator_inv_naturality {X Y Z X' : C} (f : X ⟶ X') : (f ⊗ 𝟙 (Y ⊗ Z)) ≫ (α_ X' Y Z).inv = (α_ X Y Z).inv ≫ ((f ⊗ 𝟙 Y) ⊗ 𝟙 Z) := by rw [← tensor_id, associator_inv_naturality] @[reassoc (attr := simp)] theorem hom_inv_id_tensor {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) : (f.hom ⊗ g) ≫ (f.inv ⊗ h) = (𝟙 V ⊗ g) ≫ (𝟙 V ⊗ h) := by rw [← tensor_comp, f.hom_inv_id]; simp [id_tensorHom] @[reassoc (attr := simp)] theorem inv_hom_id_tensor {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) : (f.inv ⊗ g) ≫ (f.hom ⊗ h) = (𝟙 W ⊗ g) ≫ (𝟙 W ⊗ h) := by rw [← tensor_comp, f.inv_hom_id]; simp [id_tensorHom] @[reassoc (attr := simp)] theorem tensor_hom_inv_id {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) : (g ⊗ f.hom) ≫ (h ⊗ f.inv) = (g ⊗ 𝟙 V) ≫ (h ⊗ 𝟙 V) := by rw [← tensor_comp, f.hom_inv_id]; simp [tensorHom_id] @[reassoc (attr := simp)] theorem tensor_inv_hom_id {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) : (g ⊗ f.inv) ≫ (h ⊗ f.hom) = (g ⊗ 𝟙 W) ≫ (h ⊗ 𝟙 W) := by rw [← tensor_comp, f.inv_hom_id]; simp [tensorHom_id] @[reassoc (attr := simp)] theorem hom_inv_id_tensor' {V W X Y Z : C} (f : V ⟶ W) [IsIso f] (g : X ⟶ Y) (h : Y ⟶ Z) : (f ⊗ g) ≫ (inv f ⊗ h) = (𝟙 V ⊗ g) ≫ (𝟙 V ⊗ h) := by rw [← tensor_comp, IsIso.hom_inv_id]; simp [id_tensorHom] @[reassoc (attr := simp)] theorem inv_hom_id_tensor' {V W X Y Z : C} (f : V ⟶ W) [IsIso f] (g : X ⟶ Y) (h : Y ⟶ Z) : (inv f ⊗ g) ≫ (f ⊗ h) = (𝟙 W ⊗ g) ≫ (𝟙 W ⊗ h) := by rw [← tensor_comp, IsIso.inv_hom_id]; simp [id_tensorHom] @[reassoc (attr := simp)] theorem tensor_hom_inv_id' {V W X Y Z : C} (f : V ⟶ W) [IsIso f] (g : X ⟶ Y) (h : Y ⟶ Z) : (g ⊗ f) ≫ (h ⊗ inv f) = (g ⊗ 𝟙 V) ≫ (h ⊗ 𝟙 V) := by rw [← tensor_comp, IsIso.hom_inv_id]; simp [tensorHom_id] @[reassoc (attr := simp)] theorem tensor_inv_hom_id' {V W X Y Z : C} (f : V ⟶ W) [IsIso f] (g : X ⟶ Y) (h : Y ⟶ Z) : (g ⊗ inv f) ≫ (h ⊗ f) = (g ⊗ 𝟙 W) ≫ (h ⊗ 𝟙 W) := by rw [← tensor_comp, IsIso.inv_hom_id]; simp [tensorHom_id] /-- A constructor for monoidal categories that requires `tensorHom` instead of `whiskerLeft` and `whiskerRight`. -/ abbrev ofTensorHom [MonoidalCategoryStruct C] (tensor_id : ∀ X₁ X₂ : C, tensorHom (𝟙 X₁) (𝟙 X₂) = 𝟙 (tensorObj X₁ X₂) := by aesop_cat) (id_tensorHom : ∀ (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂), tensorHom (𝟙 X) f = whiskerLeft X f := by aesop_cat) (tensorHom_id : ∀ {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C), tensorHom f (𝟙 Y) = whiskerRight f Y := by aesop_cat) (tensor_comp : ∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂), tensorHom (f₁ ≫ g₁) (f₂ ≫ g₂) = tensorHom f₁ f₂ ≫ tensorHom g₁ g₂ := by aesop_cat) (associator_naturality : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃), tensorHom (tensorHom f₁ f₂) f₃ ≫ (associator Y₁ Y₂ Y₃).hom = (associator X₁ X₂ X₃).hom ≫ tensorHom f₁ (tensorHom f₂ f₃) := by aesop_cat) (leftUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), tensorHom (𝟙 (𝟙_ C)) f ≫ (leftUnitor Y).hom = (leftUnitor X).hom ≫ f := by aesop_cat) (rightUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), tensorHom f (𝟙 (𝟙_ C)) ≫ (rightUnitor Y).hom = (rightUnitor X).hom ≫ f := by aesop_cat) (pentagon : ∀ W X Y Z : C, tensorHom (associator W X Y).hom (𝟙 Z) ≫ (associator W (tensorObj X Y) Z).hom ≫ tensorHom (𝟙 W) (associator X Y Z).hom = (associator (tensorObj W X) Y Z).hom ≫ (associator W X (tensorObj Y Z)).hom := by aesop_cat) (triangle : ∀ X Y : C, (associator X (𝟙_ C) Y).hom ≫ tensorHom (𝟙 X) (leftUnitor Y).hom = tensorHom (rightUnitor X).hom (𝟙 Y) := by aesop_cat) : MonoidalCategory C where tensorHom_def := by intros; simp [← id_tensorHom, ← tensorHom_id, ← tensor_comp] whiskerLeft_id := by intros; simp [← id_tensorHom, ← tensor_id] id_whiskerRight := by intros; simp [← tensorHom_id, tensor_id] pentagon := by intros; simp [← id_tensorHom, ← tensorHom_id, pentagon] triangle := by intros; simp [← id_tensorHom, ← tensorHom_id, triangle] @[reassoc] theorem comp_tensor_id (f : W ⟶ X) (g : X ⟶ Y) : f ≫ g ⊗ 𝟙 Z = (f ⊗ 𝟙 Z) ≫ (g ⊗ 𝟙 Z) := by simp @[reassoc] theorem id_tensor_comp (f : W ⟶ X) (g : X ⟶ Y) : 𝟙 Z ⊗ f ≫ g = (𝟙 Z ⊗ f) ≫ (𝟙 Z ⊗ g) := by simp @[reassoc] theorem id_tensor_comp_tensor_id (f : W ⟶ X) (g : Y ⟶ Z) : (𝟙 Y ⊗ f) ≫ (g ⊗ 𝟙 X) = g ⊗ f := by rw [← tensor_comp] simp @[reassoc] theorem tensor_id_comp_id_tensor (f : W ⟶ X) (g : Y ⟶ Z) : (g ⊗ 𝟙 W) ≫ (𝟙 Z ⊗ f) = g ⊗ f := by rw [← tensor_comp] simp theorem tensor_left_iff {X Y : C} (f g : X ⟶ Y) : 𝟙 (𝟙_ C) ⊗ f = 𝟙 (𝟙_ C) ⊗ g ↔ f = g := by simp theorem tensor_right_iff {X Y : C} (f g : X ⟶ Y) : f ⊗ 𝟙 (𝟙_ C) = g ⊗ 𝟙 (𝟙_ C) ↔ f = g := by simp section variable (C) attribute [local simp] whisker_exchange /-- The tensor product expressed as a functor. -/ @[simps] def tensor : C × C ⥤ C where obj X := X.1 ⊗ X.2 map {X Y : C × C} (f : X ⟶ Y) := f.1 ⊗ f.2 /-- The left-associated triple tensor product as a functor. -/ def leftAssocTensor : C × C × C ⥤ C where obj X := (X.1 ⊗ X.2.1) ⊗ X.2.2 map {X Y : C × C × C} (f : X ⟶ Y) := (f.1 ⊗ f.2.1) ⊗ f.2.2 @[simp] theorem leftAssocTensor_obj (X) : (leftAssocTensor C).obj X = (X.1 ⊗ X.2.1) ⊗ X.2.2 := rfl @[simp] theorem leftAssocTensor_map {X Y} (f : X ⟶ Y) : (leftAssocTensor C).map f = (f.1 ⊗ f.2.1) ⊗ f.2.2 := rfl /-- The right-associated triple tensor product as a functor. -/ def rightAssocTensor : C × C × C ⥤ C where obj X := X.1 ⊗ X.2.1 ⊗ X.2.2 map {X Y : C × C × C} (f : X ⟶ Y) := f.1 ⊗ f.2.1 ⊗ f.2.2 @[simp] theorem rightAssocTensor_obj (X) : (rightAssocTensor C).obj X = X.1 ⊗ X.2.1 ⊗ X.2.2 := rfl @[simp] theorem rightAssocTensor_map {X Y} (f : X ⟶ Y) : (rightAssocTensor C).map f = f.1 ⊗ f.2.1 ⊗ f.2.2 := rfl /-- The tensor product bifunctor `C ⥤ C ⥤ C` of a monoidal category. -/ @[simps] def curriedTensor : C ⥤ C ⥤ C where obj X := { obj := fun Y => X ⊗ Y map := fun g => X ◁ g } map f := { app := fun Y => f ▷ Y } variable {C} /-- Tensoring on the left with a fixed object, as a functor. -/ @[simps!] def tensorLeft (X : C) : C ⥤ C := (curriedTensor C).obj X /-- Tensoring on the right with a fixed object, as a functor. -/ @[simps!] def tensorRight (X : C) : C ⥤ C := (curriedTensor C).flip.obj X variable (C) /-- The functor `fun X ↦ 𝟙_ C ⊗ X`. -/ abbrev tensorUnitLeft : C ⥤ C := tensorLeft (𝟙_ C) /-- The functor `fun X ↦ X ⊗ 𝟙_ C`. -/ abbrev tensorUnitRight : C ⥤ C := tensorRight (𝟙_ C) -- We can express the associator and the unitors, given componentwise above, -- as natural isomorphisms. /-- The associator as a natural isomorphism. -/ @[simps!] def associatorNatIso : leftAssocTensor C ≅ rightAssocTensor C := NatIso.ofComponents (fun _ => MonoidalCategory.associator _ _ _) /-- The left unitor as a natural isomorphism. -/ @[simps!] def leftUnitorNatIso : tensorUnitLeft C ≅ 𝟭 C := NatIso.ofComponents MonoidalCategory.leftUnitor /-- The right unitor as a natural isomorphism. -/ @[simps!] def rightUnitorNatIso : tensorUnitRight C ≅ 𝟭 C := NatIso.ofComponents MonoidalCategory.rightUnitor /-- The associator as a natural isomorphism between trifunctors `C ⥤ C ⥤ C ⥤ C`. -/ @[simps!] def curriedAssociatorNatIso : bifunctorComp₁₂ (curriedTensor C) (curriedTensor C) ≅ bifunctorComp₂₃ (curriedTensor C) (curriedTensor C) := NatIso.ofComponents (fun X₁ => NatIso.ofComponents (fun X₂ => NatIso.ofComponents (fun X₃ => α_ X₁ X₂ X₃))) section variable {C} /-- Tensoring on the left with `X ⊗ Y` is naturally isomorphic to tensoring on the left with `Y`, and then again with `X`. -/ def tensorLeftTensor (X Y : C) : tensorLeft (X ⊗ Y) ≅ tensorLeft Y ⋙ tensorLeft X := NatIso.ofComponents (associator _ _) fun {Z} {Z'} f => by simp @[simp] theorem tensorLeftTensor_hom_app (X Y Z : C) : (tensorLeftTensor X Y).hom.app Z = (associator X Y Z).hom := rfl @[simp] theorem tensorLeftTensor_inv_app (X Y Z : C) : (tensorLeftTensor X Y).inv.app Z = (associator X Y Z).inv := by simp [tensorLeftTensor] variable (C) /-- Tensoring on the left, as a functor from `C` into endofunctors of `C`. TODO: show this is an op-monoidal functor. -/ abbrev tensoringLeft : C ⥤ C ⥤ C := curriedTensor C instance : (tensoringLeft C).Faithful where map_injective {X} {Y} f g h := by injections h replace h := congr_fun h (𝟙_ C) simpa using h /-- Tensoring on the right, as a functor from `C` into endofunctors of `C`. We later show this is a monoidal functor. -/ abbrev tensoringRight : C ⥤ C ⥤ C := (curriedTensor C).flip instance : (tensoringRight C).Faithful where map_injective {X} {Y} f g h := by injections h replace h := congr_fun h (𝟙_ C) simpa using h variable {C} /-- Tensoring on the right with `X ⊗ Y` is naturally isomorphic to tensoring on the right with `X`, and then again with `Y`. -/ def tensorRightTensor (X Y : C) : tensorRight (X ⊗ Y) ≅ tensorRight X ⋙ tensorRight Y := NatIso.ofComponents (fun Z => (associator Z X Y).symm) fun {Z} {Z'} f => by simp @[simp] theorem tensorRightTensor_hom_app (X Y Z : C) : (tensorRightTensor X Y).hom.app Z = (associator Z X Y).inv := rfl @[simp] theorem tensorRightTensor_inv_app (X Y Z : C) : (tensorRightTensor X Y).inv.app Z = (associator Z X Y).hom := by simp [tensorRightTensor] end end section universe v₁ v₂ u₁ u₂ variable (C₁ : Type u₁) [Category.{v₁} C₁] [MonoidalCategory.{v₁} C₁] variable (C₂ : Type u₂) [Category.{v₂} C₂] [MonoidalCategory.{v₂} C₂] attribute [local simp] associator_naturality leftUnitor_naturality rightUnitor_naturality pentagon @[simps! tensorObj tensorHom tensorUnit whiskerLeft whiskerRight associator] instance prodMonoidal : MonoidalCategory (C₁ × C₂) where tensorObj X Y := (X.1 ⊗ Y.1, X.2 ⊗ Y.2) tensorHom f g := (f.1 ⊗ g.1, f.2 ⊗ g.2) whiskerLeft X _ _ f := (whiskerLeft X.1 f.1, whiskerLeft X.2 f.2) whiskerRight f X := (whiskerRight f.1 X.1, whiskerRight f.2 X.2) tensorHom_def := by simp [tensorHom_def] tensorUnit := (𝟙_ C₁, 𝟙_ C₂) associator X Y Z := (α_ X.1 Y.1 Z.1).prod (α_ X.2 Y.2 Z.2) leftUnitor := fun ⟨X₁, X₂⟩ => (λ_ X₁).prod (λ_ X₂) rightUnitor := fun ⟨X₁, X₂⟩ => (ρ_ X₁).prod (ρ_ X₂) @[simp] theorem prodMonoidal_leftUnitor_hom_fst (X : C₁ × C₂) : ((λ_ X).hom : 𝟙_ _ ⊗ X ⟶ X).1 = (λ_ X.1).hom := by cases X rfl @[simp] theorem prodMonoidal_leftUnitor_hom_snd (X : C₁ × C₂) : ((λ_ X).hom : 𝟙_ _ ⊗ X ⟶ X).2 = (λ_ X.2).hom := by cases X rfl @[simp] theorem prodMonoidal_leftUnitor_inv_fst (X : C₁ × C₂) : ((λ_ X).inv : X ⟶ 𝟙_ _ ⊗ X).1 = (λ_ X.1).inv := by cases X rfl @[simp] theorem prodMonoidal_leftUnitor_inv_snd (X : C₁ × C₂) : ((λ_ X).inv : X ⟶ 𝟙_ _ ⊗ X).2 = (λ_ X.2).inv := by cases X rfl @[simp] theorem prodMonoidal_rightUnitor_hom_fst (X : C₁ × C₂) : ((ρ_ X).hom : X ⊗ 𝟙_ _ ⟶ X).1 = (ρ_ X.1).hom := by cases X rfl @[simp] theorem prodMonoidal_rightUnitor_hom_snd (X : C₁ × C₂) : ((ρ_ X).hom : X ⊗ 𝟙_ _ ⟶ X).2 = (ρ_ X.2).hom := by cases X rfl @[simp] theorem prodMonoidal_rightUnitor_inv_fst (X : C₁ × C₂) : ((ρ_ X).inv : X ⟶ X ⊗ 𝟙_ _).1 = (ρ_ X.1).inv := by cases X rfl @[simp] theorem prodMonoidal_rightUnitor_inv_snd (X : C₁ × C₂) : ((ρ_ X).inv : X ⟶ X ⊗ 𝟙_ _).2 = (ρ_ X.2).inv := by cases X rfl end end MonoidalCategory namespace NatTrans variable {J : Type*} [Category J] {C : Type*} [Category C] [MonoidalCategory C] {F G F' G' : J ⥤ C} (α : F ⟶ F') (β : G ⟶ G') @[reassoc] lemma tensor_naturality {X Y X' Y' : J} (f : X ⟶ Y) (g : X' ⟶ Y') : (F.map f ⊗ G.map g) ≫ (α.app Y ⊗ β.app Y') = (α.app X ⊗ β.app X') ≫ (F'.map f ⊗ G'.map g) := by simp only [← tensor_comp, naturality] @[reassoc] lemma whiskerRight_app_tensor_app {X Y : J} (f : X ⟶ Y) (X' : J) : F.map f ▷ G.obj X' ≫ (α.app Y ⊗ β.app X') = (α.app X ⊗ β.app X') ≫ F'.map f ▷ (G'.obj X') := by simpa using tensor_naturality α β f (𝟙 X') @[reassoc] lemma whiskerLeft_app_tensor_app {X' Y' : J} (f : X' ⟶ Y') (X : J) : F.obj X ◁ G.map f ≫ (α.app X ⊗ β.app Y') = (α.app X ⊗ β.app X') ≫ F'.obj X ◁ G'.map f := by simpa using tensor_naturality α β (𝟙 X) f end NatTrans end CategoryTheory
Mathlib/CategoryTheory/Monoidal/Category.lean
1,026
1,029
/- 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.Data.Set.Restrict /-! # Functions over sets This file contains basic results on the following predicates of functions and sets: * `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`. -/ variable {α β γ δ : Type*} {ι : Sort*} {π : α → Type*} open Equiv Equiv.Perm Function namespace Set /-! ### Equality on a set -/ section equality variable {s s₁ s₂ : Set α} {f₁ f₂ f₃ : α → β} {g : β → γ} {a : α} /-- This lemma exists for use by `aesop` as a forward rule. -/ @[aesop safe forward] lemma EqOn.eq_of_mem (h : s.EqOn f₁ f₂) (ha : a ∈ s) : f₁ a = f₂ a := h ha @[simp] theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim @[simp] theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by simp [Set.EqOn] @[simp] theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by simp [EqOn, funext_iff] @[symm] theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s := ⟨EqOn.symm, EqOn.symm⟩ -- 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 -- 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 https://github.com/leanprover-community/mathlib4/pull/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) theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s := image_congr heq /-- 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] theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx) @[simp] theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ := forall₂_or_left theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) := eqOn_union.2 ⟨h₁, h₂⟩ theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha => congr_arg _ <| h ha @[simp] theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} : EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f := forall_mem_range.trans <| funext_iff.symm alias ⟨EqOn.comp_eq, _⟩ := eqOn_range end equality variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} section MapsTo theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t := image_subset_iff.symm theorem mapsTo_prodMap_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) := diagonal_subset_iff.2 fun _ => rfl @[deprecated (since := "2025-04-18")] alias mapsTo_prod_map_diagonal := mapsTo_prodMap_diagonal theorem MapsTo.subset_preimage (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf theorem mapsTo_iff_subset_preimage : MapsTo f s t ↔ s ⊆ f ⁻¹' t := Iff.rfl @[simp] theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t := singleton_subset_iff theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t := empty_subset _ @[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 theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx => h hx ▸ h₁ hx 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 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⟩ theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h => h₁ (h₂ h) theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => 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 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 generalizing x with | zero => rfl | succ n ihn => simp [Nat.iterate, ihn] 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⟩ lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s := mapsTo_of_subsingleton' _ id theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ := fun _ hx => ht (hf <| hs hx) theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx => hf (hs hx) theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx => ht (hf hx) 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 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₂ @[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⟩ theorem MapsTo.inter (h₁ : MapsTo f s t₁) (h₂ : MapsTo f s t₂) : MapsTo f s (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx, h₂ hx⟩ lemma MapsTo.insert (h : MapsTo f s t) (x : α) : MapsTo f (insert x s) (insert (f x) t) := by simpa [← singleton_union] using h.mono_right subset_union_right 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⟩ @[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⟩ theorem mapsTo_univ (f : α → β) (s : Set α) : MapsTo f s univ := fun _ _ => trivial theorem mapsTo_range (f : α → β) (s : Set α) : MapsTo f s (range f) := (mapsTo_image f s).mono (Subset.refl s) (image_subset_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⟩ lemma MapsTo.comp_left (g : β → γ) (hf : MapsTo f s t) : MapsTo (g ∘ f) s (g '' t) := fun x hx ↦ ⟨f x, hf hx, rfl⟩ lemma MapsTo.comp_right {s : Set β} {t : Set γ} (hg : MapsTo g s t) (f : α → β) : MapsTo (g ∘ f) (f ⁻¹' s) t := fun _ hx ↦ hg hx @[simp] lemma mapsTo_univ_iff : MapsTo f univ t ↔ ∀ x, f x ∈ t := ⟨fun h _ => h (mem_univ _), fun h x _ => h x⟩ @[simp] lemma mapsTo_range_iff {g : ι → α} : MapsTo f (range g) t ↔ ∀ i, f (g i) ∈ t := forall_mem_range 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⟩ end MapsTo /-! ### Injectivity on a set -/ section injOn theorem Subsingleton.injOn (hs : s.Subsingleton) (f : α → β) : InjOn f s := fun _ hx _ hy _ => hs hx hy @[simp] theorem injOn_empty (f : α → β) : InjOn f ∅ := subsingleton_empty.injOn f @[simp] theorem injOn_singleton (f : α → β) (a : α) : InjOn f {a} := subsingleton_singleton.injOn f @[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⟩ 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 alias ⟨_, InjOn.ne⟩ := InjOn.ne_iff 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 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⟩ theorem InjOn.mono (h : s₁ ⊆ s₂) (ht : InjOn f s₂) : InjOn f s₁ := fun _ hx _ hy H => ht (h hx) (h hy) H 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] 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 theorem injective_iff_injOn_univ : Injective f ↔ InjOn f univ := ⟨fun h _ _ _ _ hxy => h hxy, fun h _ _ heq => h trivial trivial heq⟩ theorem injOn_of_injective (h : Injective f) {s : Set α} : InjOn f s := fun _ _ _ _ hxy => h hxy alias _root_.Function.Injective.injOn := injOn_of_injective -- 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 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 lemma InjOn.of_comp (h : InjOn (g ∘ f) s) : InjOn f s := fun _ hx _ hy heq ↦ h hx hy (by simp [heq]) 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.comp_iff (hf : InjOn f s) : InjOn (g ∘ f) s ↔ InjOn g (f '' s) := ⟨image_of_comp, fun h ↦ InjOn.comp h hf <| mapsTo_image f s⟩ 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 lemma injOn_of_subsingleton [Subsingleton α] (f : α → β) (s : Set α) : InjOn f s := (injective_of_subsingleton _).injOn 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) theorem _root_.Set.InjOn.injective_iff (s : Set β) (h : InjOn g s) (hs : range f ⊆ s) : Injective (g ∘ f) ↔ Injective f := ⟨(·.of_comp), fun h _ ↦ by aesop⟩ theorem exists_injOn_iff_injective [Nonempty β] : (∃ f : α → β, InjOn f s) ↔ ∃ f : s → β, Injective f := ⟨fun ⟨_, hf⟩ => ⟨_, hf.injective⟩, fun ⟨f, hf⟩ => by lift f to α → β using trivial exact ⟨f, injOn_iff_injective.2 hf⟩⟩ theorem injOn_preimage {B : Set (Set β)} (hB : B ⊆ 𝒫 range f) : InjOn (preimage f) B := fun _ hs _ ht hst => (preimage_eq_preimage' (hB hs) (hB ht)).1 hst theorem InjOn.mem_of_mem_image {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (h : x ∈ s) (h₁ : f x ∈ f '' s₁) : x ∈ s₁ := let ⟨_, h', Eq⟩ := h₁ hf (hs h') h Eq ▸ h' theorem InjOn.mem_image_iff {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (hx : x ∈ s) : f x ∈ f '' s₁ ↔ x ∈ s₁ := ⟨hf.mem_of_mem_image hs hx, mem_image_of_mem f⟩ theorem InjOn.preimage_image_inter (hf : InjOn f s) (hs : s₁ ⊆ s) : f ⁻¹' (f '' s₁) ∩ s = s₁ := ext fun _ => ⟨fun ⟨h₁, h₂⟩ => hf.mem_of_mem_image hs h₂ h₁, fun h => ⟨mem_image_of_mem _ h, hs h⟩⟩ theorem EqOn.cancel_left (h : s.EqOn (g ∘ f₁) (g ∘ f₂)) (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn f₁ f₂ := fun _ ha => hg (hf₁ ha) (hf₂ ha) (h ha) theorem InjOn.cancel_left (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn (g ∘ f₁) (g ∘ f₂) ↔ s.EqOn f₁ f₂ := ⟨fun h => h.cancel_left hg hf₁ hf₂, EqOn.comp_left⟩ lemma InjOn.image_inter {s t u : Set α} (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : f '' (s ∩ t) = f '' s ∩ f '' t := by apply Subset.antisymm (image_inter_subset _ _ _) intro x ⟨⟨y, ys, hy⟩, ⟨z, zt, hz⟩⟩ have : y = z := by apply hf (hs ys) (ht zt) rwa [← hz] at hy rw [← this] at zt exact ⟨y, ⟨ys, zt⟩, hy⟩ lemma InjOn.image (h : s.InjOn f) : s.powerset.InjOn (image f) := fun s₁ hs₁ s₂ hs₂ h' ↦ by rw [← h.preimage_image_inter hs₁, h', h.preimage_image_inter hs₂] theorem InjOn.image_eq_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ = f '' s₂ ↔ s₁ = s₂ := h.image.eq_iff h₁ h₂ lemma InjOn.image_subset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊆ f '' s₂ ↔ s₁ ⊆ s₂ := by refine ⟨fun h' ↦ ?_, image_subset _⟩ rw [← h.preimage_image_inter h₁, ← h.preimage_image_inter h₂] exact inter_subset_inter_left _ (preimage_mono h') lemma InjOn.image_ssubset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊂ f '' s₂ ↔ s₁ ⊂ s₂ := by simp_rw [ssubset_def, h.image_subset_image_iff h₁ h₂, h.image_subset_image_iff h₂ h₁] -- TODO: can this move to a better place? theorem _root_.Disjoint.image {s t u : Set α} {f : α → β} (h : Disjoint s t) (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : Disjoint (f '' s) (f '' t) := by rw [disjoint_iff_inter_eq_empty] at h ⊢ rw [← hf.image_inter hs ht, h, image_empty] lemma InjOn.image_diff {t : Set α} (h : s.InjOn f) : f '' (s \ t) = f '' s \ f '' (s ∩ t) := by refine subset_antisymm (subset_diff.2 ⟨image_subset f diff_subset, ?_⟩) (diff_subset_iff.2 (by rw [← image_union, inter_union_diff])) exact Disjoint.image disjoint_sdiff_inter h diff_subset inter_subset_left lemma InjOn.image_diff_subset {f : α → β} {t : Set α} (h : InjOn f s) (hst : t ⊆ s) : f '' (s \ t) = f '' s \ f '' t := by rw [h.image_diff, inter_eq_self_of_subset_right hst] alias image_diff_of_injOn := InjOn.image_diff_subset theorem InjOn.imageFactorization_injective (h : InjOn f s) : Injective (s.imageFactorization f) := fun ⟨x, hx⟩ ⟨y, hy⟩ h' ↦ by simpa [imageFactorization, h.eq_iff hx hy] using h' @[simp] theorem imageFactorization_injective_iff : Injective (s.imageFactorization f) ↔ InjOn f s := ⟨fun h x hx y hy _ ↦ by simpa using @h ⟨x, hx⟩ ⟨y, hy⟩ (by simpa [imageFactorization]), InjOn.imageFactorization_injective⟩ end injOn section graphOn variable {x : α × β} lemma graphOn_univ_inj {g : α → β} : univ.graphOn f = univ.graphOn g ↔ f = g := by simp lemma graphOn_univ_injective : Injective (univ.graphOn : (α → β) → Set (α × β)) := fun _f _g ↦ graphOn_univ_inj.1 lemma exists_eq_graphOn_image_fst [Nonempty β] {s : Set (α × β)} : (∃ f : α → β, s = graphOn f (Prod.fst '' s)) ↔ InjOn Prod.fst s := by refine ⟨?_, fun h ↦ ?_⟩ · rintro ⟨f, hf⟩ rw [hf] exact InjOn.image_of_comp <| injOn_id _ · have : ∀ x ∈ Prod.fst '' s, ∃ y, (x, y) ∈ s := forall_mem_image.2 fun (x, y) h ↦ ⟨y, h⟩ choose! f hf using this rw [forall_mem_image] at hf use f rw [graphOn, image_image, EqOn.image_eq_self] exact fun x hx ↦ h (hf hx) hx rfl lemma exists_eq_graphOn [Nonempty β] {s : Set (α × β)} : (∃ f t, s = graphOn f t) ↔ InjOn Prod.fst s := .trans ⟨fun ⟨f, t, hs⟩ ↦ ⟨f, by rw [hs, image_fst_graphOn]⟩, fun ⟨f, hf⟩ ↦ ⟨f, _, hf⟩⟩ exists_eq_graphOn_image_fst end graphOn /-! ### Surjectivity on a set -/ section surjOn theorem SurjOn.subset_range (h : SurjOn f s t) : t ⊆ range f := Subset.trans h <| image_subset_range f s theorem surjOn_iff_exists_map_subtype : SurjOn f s t ↔ ∃ (t' : Set β) (g : s → t'), t ⊆ t' ∧ Surjective g ∧ ∀ x : s, f x = g x := ⟨fun h => ⟨_, (mapsTo_image f s).restrict f s _, h, surjective_mapsTo_image_restrict _ _, fun _ => rfl⟩, fun ⟨t', g, htt', hg, hfg⟩ y hy => let ⟨x, hx⟩ := hg ⟨y, htt' hy⟩ ⟨x, x.2, by rw [hfg, hx, Subtype.coe_mk]⟩⟩ theorem surjOn_empty (f : α → β) (s : Set α) : SurjOn f s ∅ := empty_subset _ @[simp] theorem surjOn_empty_iff : SurjOn f ∅ t ↔ t = ∅ := by simp [SurjOn, subset_empty_iff] @[simp] lemma surjOn_singleton : SurjOn f s {b} ↔ b ∈ f '' s := singleton_subset_iff theorem surjOn_image (f : α → β) (s : Set α) : SurjOn f s (f '' s) := Subset.rfl theorem SurjOn.comap_nonempty (h : SurjOn f s t) (ht : t.Nonempty) : s.Nonempty := (ht.mono h).of_image theorem SurjOn.congr (h : SurjOn f₁ s t) (H : EqOn f₁ f₂ s) : SurjOn f₂ s t := by rwa [SurjOn, ← H.image_eq] theorem EqOn.surjOn_iff (h : EqOn f₁ f₂ s) : SurjOn f₁ s t ↔ SurjOn f₂ s t := ⟨fun H => H.congr h, fun H => H.congr h.symm⟩ theorem SurjOn.mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (hf : SurjOn f s₁ t₂) : SurjOn f s₂ t₁ := Subset.trans ht <| Subset.trans hf <| image_subset _ hs theorem SurjOn.union (h₁ : SurjOn f s t₁) (h₂ : SurjOn f s t₂) : SurjOn f s (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => h₁ hx) fun hx => h₂ hx theorem SurjOn.union_union (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) : SurjOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := (h₁.mono subset_union_left (Subset.refl _)).union (h₂.mono subset_union_right (Subset.refl _)) theorem SurjOn.inter_inter (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := by intro y hy rcases h₁ hy.1 with ⟨x₁, hx₁, rfl⟩ rcases h₂ hy.2 with ⟨x₂, hx₂, heq⟩ obtain rfl : x₁ = x₂ := h (Or.inl hx₁) (Or.inr hx₂) heq.symm exact mem_image_of_mem f ⟨hx₁, hx₂⟩ theorem SurjOn.inter (h₁ : SurjOn f s₁ t) (h₂ : SurjOn f s₂ t) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) t := inter_self t ▸ h₁.inter_inter h₂ h lemma surjOn_id (s : Set α) : SurjOn id s s := by simp [SurjOn] theorem SurjOn.comp (hg : SurjOn g t p) (hf : SurjOn f s t) : SurjOn (g ∘ f) s p := Subset.trans hg <| Subset.trans (image_subset g hf) <| image_comp g f s ▸ Subset.refl _ lemma SurjOn.of_comp (h : SurjOn (g ∘ f) s p) (hr : MapsTo f s t) : SurjOn g t p := by intro z hz obtain ⟨x, hx, rfl⟩ := h hz exact ⟨f x, hr hx, rfl⟩ lemma surjOn_comp_iff : SurjOn (g ∘ f) s p ↔ SurjOn g (f '' s) p := ⟨fun h ↦ h.of_comp <| mapsTo_image f s, fun h ↦ h.comp <| surjOn_image _ _⟩ lemma SurjOn.iterate {f : α → α} {s : Set α} (h : SurjOn f s s) : ∀ n, SurjOn f^[n] s s | 0 => surjOn_id _ | (n + 1) => (h.iterate n).comp h lemma SurjOn.comp_left (hf : SurjOn f s t) (g : β → γ) : SurjOn (g ∘ f) s (g '' t) := by rw [SurjOn, image_comp g f]; exact image_subset _ hf lemma SurjOn.comp_right {s : Set β} {t : Set γ} (hf : Surjective f) (hg : SurjOn g s t) : SurjOn (g ∘ f) (f ⁻¹' s) t := by rwa [SurjOn, image_comp g f, image_preimage_eq _ hf] lemma surjOn_of_subsingleton' [Subsingleton β] (f : α → β) (h : t.Nonempty → s.Nonempty) : SurjOn f s t := fun _ ha ↦ Subsingleton.mem_iff_nonempty.2 <| (h ⟨_, ha⟩).image _ lemma surjOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : SurjOn f s s := surjOn_of_subsingleton' _ id theorem surjective_iff_surjOn_univ : Surjective f ↔ SurjOn f univ univ := by simp [Surjective, SurjOn, subset_def] theorem SurjOn.image_eq_of_mapsTo (h₁ : SurjOn f s t) (h₂ : MapsTo f s t) : f '' s = t := eq_of_subset_of_subset h₂.image_subset h₁ theorem image_eq_iff_surjOn_mapsTo : f '' s = t ↔ s.SurjOn f t ∧ s.MapsTo f t := by refine ⟨?_, fun h => h.1.image_eq_of_mapsTo h.2⟩ rintro rfl exact ⟨s.surjOn_image f, s.mapsTo_image f⟩ lemma SurjOn.image_preimage (h : Set.SurjOn f s t) (ht : t₁ ⊆ t) : f '' (f ⁻¹' t₁) = t₁ := image_preimage_eq_iff.2 fun _ hx ↦ mem_range_of_mem_image f s <| h <| ht hx theorem SurjOn.mapsTo_compl (h : SurjOn f s t) (h' : Injective f) : MapsTo f sᶜ tᶜ := fun _ hs ht => let ⟨_, hx', HEq⟩ := h ht hs <| h' HEq ▸ hx' theorem MapsTo.surjOn_compl (h : MapsTo f s t) (h' : Surjective f) : SurjOn f sᶜ tᶜ := h'.forall.2 fun _ ht => (mem_image_of_mem _) fun hs => ht (h hs) theorem EqOn.cancel_right (hf : s.EqOn (g₁ ∘ f) (g₂ ∘ f)) (hf' : s.SurjOn f t) : t.EqOn g₁ g₂ := by intro b hb obtain ⟨a, ha, rfl⟩ := hf' hb exact hf ha theorem SurjOn.cancel_right (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ t.EqOn g₁ g₂ := ⟨fun h => h.cancel_right hf, fun h => h.comp_right hf'⟩ theorem eqOn_comp_right_iff : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ (f '' s).EqOn g₁ g₂ := (s.surjOn_image f).cancel_right <| s.mapsTo_image f theorem SurjOn.forall {p : β → Prop} (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : (∀ y ∈ t, p y) ↔ (∀ x ∈ s, p (f x)) := ⟨fun H x hx ↦ H (f x) (hf' hx), fun H _y hy ↦ let ⟨x, hx, hxy⟩ := hf hy; hxy ▸ H x hx⟩ end surjOn /-! ### Bijectivity -/ section bijOn theorem BijOn.mapsTo (h : BijOn f s t) : MapsTo f s t := h.left theorem BijOn.injOn (h : BijOn f s t) : InjOn f s := h.right.left theorem BijOn.surjOn (h : BijOn f s t) : SurjOn f s t := h.right.right theorem BijOn.mk (h₁ : MapsTo f s t) (h₂ : InjOn f s) (h₃ : SurjOn f s t) : BijOn f s t := ⟨h₁, h₂, h₃⟩ theorem bijOn_empty (f : α → β) : BijOn f ∅ ∅ := ⟨mapsTo_empty f ∅, injOn_empty f, surjOn_empty f ∅⟩ @[simp] theorem bijOn_empty_iff_left : BijOn f s ∅ ↔ s = ∅ := ⟨fun h ↦ by simpa using h.mapsTo, by rintro rfl; exact bijOn_empty f⟩ @[simp] theorem bijOn_empty_iff_right : BijOn f ∅ t ↔ t = ∅ := ⟨fun h ↦ by simpa using h.surjOn, by rintro rfl; exact bijOn_empty f⟩ @[simp] lemma bijOn_singleton : BijOn f {a} {b} ↔ f a = b := by simp [BijOn, eq_comm] theorem BijOn.inter_mapsTo (h₁ : BijOn f s₁ t₁) (h₂ : MapsTo f s₂ t₂) (h₃ : s₁ ∩ f ⁻¹' t₂ ⊆ s₂) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂, h₁.injOn.mono inter_subset_left, fun _ hy => let ⟨x, hx, hxy⟩ := h₁.surjOn hy.1 ⟨x, ⟨hx, h₃ ⟨hx, hxy.symm.subst hy.2⟩⟩, hxy⟩⟩ theorem MapsTo.inter_bijOn (h₁ : MapsTo f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h₃ : s₂ ∩ f ⁻¹' t₁ ⊆ s₁) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := inter_comm s₂ s₁ ▸ inter_comm t₂ t₁ ▸ h₂.inter_mapsTo h₁ h₃ theorem BijOn.inter (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂.mapsTo, h₁.injOn.mono inter_subset_left, h₁.surjOn.inter_inter h₂.surjOn h⟩ theorem BijOn.union (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := ⟨h₁.mapsTo.union_union h₂.mapsTo, h, h₁.surjOn.union_union h₂.surjOn⟩ theorem BijOn.subset_range (h : BijOn f s t) : t ⊆ range f := h.surjOn.subset_range theorem InjOn.bijOn_image (h : InjOn f s) : BijOn f s (f '' s) := BijOn.mk (mapsTo_image f s) h (Subset.refl _) theorem BijOn.congr (h₁ : BijOn f₁ s t) (h : EqOn f₁ f₂ s) : BijOn f₂ s t := BijOn.mk (h₁.mapsTo.congr h) (h₁.injOn.congr h) (h₁.surjOn.congr h) theorem EqOn.bijOn_iff (H : EqOn f₁ f₂ s) : BijOn f₁ s t ↔ BijOn f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem BijOn.image_eq (h : BijOn f s t) : f '' s = t := h.surjOn.image_eq_of_mapsTo h.mapsTo lemma BijOn.forall {p : β → Prop} (hf : BijOn f s t) : (∀ b ∈ t, p b) ↔ ∀ a ∈ s, p (f a) where mp h _ ha := h _ <| hf.mapsTo ha mpr h b hb := by obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact h _ ha lemma BijOn.exists {p : β → Prop} (hf : BijOn f s t) : (∃ b ∈ t, p b) ↔ ∃ a ∈ s, p (f a) where mp := by rintro ⟨b, hb, h⟩; obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact ⟨a, ha, h⟩ mpr := by rintro ⟨a, ha, h⟩; exact ⟨f a, hf.mapsTo ha, h⟩ lemma _root_.Equiv.image_eq_iff_bijOn (e : α ≃ β) : e '' s = t ↔ BijOn e s t := ⟨fun h ↦ ⟨(mapsTo_image e s).mono_right h.subset, e.injective.injOn, h ▸ surjOn_image e s⟩, BijOn.image_eq⟩ lemma bijOn_id (s : Set α) : BijOn id s s := ⟨s.mapsTo_id, s.injOn_id, s.surjOn_id⟩ theorem BijOn.comp (hg : BijOn g t p) (hf : BijOn f s t) : BijOn (g ∘ f) s p := BijOn.mk (hg.mapsTo.comp hf.mapsTo) (hg.injOn.comp hf.injOn hf.mapsTo) (hg.surjOn.comp hf.surjOn) /-- If `f : α → β` and `g : β → γ` and if `f` is injective on `s`, then `f ∘ g` is a bijection on `s` iff `g` is a bijection on `f '' s`. -/ theorem bijOn_comp_iff (hf : InjOn f s) : BijOn (g ∘ f) s p ↔ BijOn g (f '' s) p := by simp only [BijOn, InjOn.comp_iff, surjOn_comp_iff, mapsTo_image_iff, hf] /-- If we have a commutative square ``` α --f--> β | | p₁ p₂ | | \/ \/ γ --g--> δ ``` and `f` induces a bijection from `s : Set α` to `t : Set β`, then `g` induces a bijection from the image of `s` to the image of `t`, as long as `g` is is injective on the image of `s`. -/ theorem bijOn_image_image {p₁ : α → γ} {p₂ : β → δ} {g : γ → δ} (comm : ∀ a, p₂ (f a) = g (p₁ a)) (hbij : BijOn f s t) (hinj: InjOn g (p₁ '' s)) : BijOn g (p₁ '' s) (p₂ '' t) := by obtain ⟨h1, h2, h3⟩ := hbij refine ⟨?_, hinj, ?_⟩ · rintro _ ⟨a, ha, rfl⟩ exact ⟨f a, h1 ha, by rw [comm a]⟩ · rintro _ ⟨b, hb, rfl⟩ obtain ⟨a, ha, rfl⟩ := h3 hb rw [← image_comp, comm] exact ⟨a, ha, rfl⟩ lemma BijOn.iterate {f : α → α} {s : Set α} (h : BijOn f s s) : ∀ n, BijOn f^[n] s s | 0 => s.bijOn_id | (n + 1) => (h.iterate n).comp h lemma bijOn_of_subsingleton' [Subsingleton α] [Subsingleton β] (f : α → β) (h : s.Nonempty ↔ t.Nonempty) : BijOn f s t := ⟨mapsTo_of_subsingleton' _ h.1, injOn_of_subsingleton _ _, surjOn_of_subsingleton' _ h.2⟩ lemma bijOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : BijOn f s s := bijOn_of_subsingleton' _ Iff.rfl theorem BijOn.bijective (h : BijOn f s t) : Bijective (h.mapsTo.restrict f s t) := ⟨fun x y h' => Subtype.ext <| h.injOn x.2 y.2 <| Subtype.ext_iff.1 h', fun ⟨_, hy⟩ => let ⟨x, hx, hxy⟩ := h.surjOn hy ⟨⟨x, hx⟩, Subtype.eq hxy⟩⟩ theorem bijective_iff_bijOn_univ : Bijective f ↔ BijOn f univ univ := Iff.intro (fun h => let ⟨inj, surj⟩ := h ⟨mapsTo_univ f _, inj.injOn, Iff.mp surjective_iff_surjOn_univ surj⟩) fun h => let ⟨_map, inj, surj⟩ := h ⟨Iff.mpr injective_iff_injOn_univ inj, Iff.mpr surjective_iff_surjOn_univ surj⟩ alias ⟨_root_.Function.Bijective.bijOn_univ, _⟩ := bijective_iff_bijOn_univ theorem BijOn.compl (hst : BijOn f s t) (hf : Bijective f) : BijOn f sᶜ tᶜ := ⟨hst.surjOn.mapsTo_compl hf.1, hf.1.injOn, hst.mapsTo.surjOn_compl hf.2⟩ theorem BijOn.subset_right {r : Set β} (hf : BijOn f s t) (hrt : r ⊆ t) : BijOn f (s ∩ f ⁻¹' r) r := by refine ⟨inter_subset_right, hf.injOn.mono inter_subset_left, fun x hx ↦ ?_⟩ obtain ⟨y, hy, rfl⟩ := hf.surjOn (hrt hx) exact ⟨y, ⟨hy, hx⟩, rfl⟩ theorem BijOn.subset_left {r : Set α} (hf : BijOn f s t) (hrs : r ⊆ s) : BijOn f r (f '' r) := (hf.injOn.mono hrs).bijOn_image theorem BijOn.insert_iff (ha : a ∉ s) (hfa : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) ↔ BijOn f s t where mp h := by have := congrArg (· \ {f a}) (image_insert_eq ▸ h.image_eq) simp only [mem_singleton_iff, insert_diff_of_mem] at this rw [diff_singleton_eq_self hfa, diff_singleton_eq_self] at this · exact ⟨by simp [← this, mapsTo'], h.injOn.mono (subset_insert ..), by simp [← this, surjOn_image]⟩ simp only [mem_image, not_exists, not_and] intro x hx rw [h.injOn.eq_iff (by simp [hx]) (by simp)] exact ha ∘ (· ▸ hx) mpr h := by repeat rw [insert_eq] refine (bijOn_singleton.mpr rfl).union h ?_ simp only [singleton_union, injOn_insert fun x ↦ (hfa (h.mapsTo x)), h.injOn, mem_image, not_exists, not_and, true_and] exact fun _ hx h₂ ↦ hfa (h₂ ▸ h.mapsTo hx) theorem BijOn.insert (h₁ : BijOn f s t) (h₂ : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) := (insert_iff (h₂ <| h₁.mapsTo ·) h₂).mpr h₁ theorem BijOn.sdiff_singleton (h₁ : BijOn f s t) (h₂ : a ∈ s) : BijOn f (s \ {a}) (t \ {f a}) := by convert h₁.subset_left diff_subset simp [h₁.injOn.image_diff, h₁.image_eq, h₂, inter_eq_self_of_subset_right] end bijOn /-! ### left inverse -/ namespace LeftInvOn theorem eqOn (h : LeftInvOn f' f s) : EqOn (f' ∘ f) id s := h theorem eq (h : LeftInvOn f' f s) {x} (hx : x ∈ s) : f' (f x) = x := h hx theorem congr_left (h₁ : LeftInvOn f₁' f s) {t : Set β} (h₁' : MapsTo f s t) (heq : EqOn f₁' f₂' t) : LeftInvOn f₂' f s := fun _ hx => heq (h₁' hx) ▸ h₁ hx theorem congr_right (h₁ : LeftInvOn f₁' f₁ s) (heq : EqOn f₁ f₂ s) : LeftInvOn f₁' f₂ s := fun _ hx => heq hx ▸ h₁ hx theorem injOn (h : LeftInvOn f₁' f s) : InjOn f s := fun x₁ h₁ x₂ h₂ heq => calc x₁ = f₁' (f x₁) := Eq.symm <| h h₁ _ = f₁' (f x₂) := congr_arg f₁' heq _ = x₂ := h h₂ theorem surjOn (h : LeftInvOn f' f s) (hf : MapsTo f s t) : SurjOn f' t s := fun x hx => ⟨f x, hf hx, h hx⟩ theorem mapsTo (h : LeftInvOn f' f s) (hf : SurjOn f s t) : MapsTo f' t s := fun y hy => by let ⟨x, hs, hx⟩ := hf hy rwa [← hx, h hs] lemma _root_.Set.leftInvOn_id (s : Set α) : LeftInvOn id id s := fun _ _ ↦ rfl theorem comp (hf' : LeftInvOn f' f s) (hg' : LeftInvOn g' g t) (hf : MapsTo f s t) : LeftInvOn (f' ∘ g') (g ∘ f) s := fun x h => calc (f' ∘ g') ((g ∘ f) x) = f' (f x) := congr_arg f' (hg' (hf h)) _ = x := hf' h theorem mono (hf : LeftInvOn f' f s) (ht : s₁ ⊆ s) : LeftInvOn f' f s₁ := fun _ hx => hf (ht hx) theorem image_inter' (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' s₁ ∩ f '' s := by apply Subset.antisymm · rintro _ ⟨x, ⟨h₁, h⟩, rfl⟩ exact ⟨by rwa [mem_preimage, hf h], mem_image_of_mem _ h⟩ · rintro _ ⟨h₁, ⟨x, h, rfl⟩⟩ exact mem_image_of_mem _ ⟨by rwa [← hf h], h⟩ theorem image_inter (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' (s₁ ∩ s) ∩ f '' s := by rw [hf.image_inter'] refine Subset.antisymm ?_ (inter_subset_inter_left _ (preimage_mono inter_subset_left)) rintro _ ⟨h₁, x, hx, rfl⟩; exact ⟨⟨h₁, by rwa [hf hx]⟩, mem_image_of_mem _ hx⟩ theorem image_image (hf : LeftInvOn f' f s) : f' '' (f '' s) = s := by rw [Set.image_image, image_congr hf, image_id'] theorem image_image' (hf : LeftInvOn f' f s) (hs : s₁ ⊆ s) : f' '' (f '' s₁) = s₁ := (hf.mono hs).image_image end LeftInvOn /-! ### Right inverse -/ section RightInvOn namespace RightInvOn theorem eqOn (h : RightInvOn f' f t) : EqOn (f ∘ f') id t := h theorem eq (h : RightInvOn f' f t) {y} (hy : y ∈ t) : f (f' y) = y := h hy theorem _root_.Set.LeftInvOn.rightInvOn_image (h : LeftInvOn f' f s) : RightInvOn f' f (f '' s) := fun _y ⟨_x, hx, heq⟩ => heq ▸ (congr_arg f <| h.eq hx) theorem congr_left (h₁ : RightInvOn f₁' f t) (heq : EqOn f₁' f₂' t) : RightInvOn f₂' f t := h₁.congr_right heq theorem congr_right (h₁ : RightInvOn f' f₁ t) (hg : MapsTo f' t s) (heq : EqOn f₁ f₂ s) : RightInvOn f' f₂ t := LeftInvOn.congr_left h₁ hg heq theorem surjOn (hf : RightInvOn f' f t) (hf' : MapsTo f' t s) : SurjOn f s t := LeftInvOn.surjOn hf hf' theorem mapsTo (h : RightInvOn f' f t) (hf : SurjOn f' t s) : MapsTo f s t := LeftInvOn.mapsTo h hf lemma _root_.Set.rightInvOn_id (s : Set α) : RightInvOn id id s := fun _ _ ↦ rfl theorem comp (hf : RightInvOn f' f t) (hg : RightInvOn g' g p) (g'pt : MapsTo g' p t) : RightInvOn (f' ∘ g') (g ∘ f) p := LeftInvOn.comp hg hf g'pt theorem mono (hf : RightInvOn f' f t) (ht : t₁ ⊆ t) : RightInvOn f' f t₁ := LeftInvOn.mono hf ht end RightInvOn theorem InjOn.rightInvOn_of_leftInvOn (hf : InjOn f s) (hf' : LeftInvOn f f' t) (h₁ : MapsTo f s t) (h₂ : MapsTo f' t s) : RightInvOn f f' s := fun _ h => hf (h₂ <| h₁ h) h (hf' (h₁ h)) theorem eqOn_of_leftInvOn_of_rightInvOn (h₁ : LeftInvOn f₁' f s) (h₂ : RightInvOn f₂' f t) (h : MapsTo f₂' t s) : EqOn f₁' f₂' t := fun y hy => calc f₁' y = (f₁' ∘ f ∘ f₂') y := congr_arg f₁' (h₂ hy).symm _ = f₂' y := h₁ (h hy) theorem SurjOn.leftInvOn_of_rightInvOn (hf : SurjOn f s t) (hf' : RightInvOn f f' s) : LeftInvOn f f' t := fun y hy => by let ⟨x, hx, heq⟩ := hf hy rw [← heq, hf' hx] end RightInvOn /-! ### Two-side inverses -/ namespace InvOn lemma _root_.Set.invOn_id (s : Set α) : InvOn id id s s := ⟨s.leftInvOn_id, s.rightInvOn_id⟩ lemma comp (hf : InvOn f' f s t) (hg : InvOn g' g t p) (fst : MapsTo f s t) (g'pt : MapsTo g' p t) : InvOn (f' ∘ g') (g ∘ f) s p := ⟨hf.1.comp hg.1 fst, hf.2.comp hg.2 g'pt⟩ @[symm] theorem symm (h : InvOn f' f s t) : InvOn f f' t s := ⟨h.right, h.left⟩ theorem mono (h : InvOn f' f s t) (hs : s₁ ⊆ s) (ht : t₁ ⊆ t) : InvOn f' f s₁ t₁ := ⟨h.1.mono hs, h.2.mono ht⟩ /-- If functions `f'` and `f` are inverse on `s` and `t`, `f` maps `s` into `t`, and `f'` maps `t` into `s`, then `f` is a bijection between `s` and `t`. The `mapsTo` arguments can be deduced from `surjOn` statements using `LeftInvOn.mapsTo` and `RightInvOn.mapsTo`. -/ theorem bijOn (h : InvOn f' f s t) (hf : MapsTo f s t) (hf' : MapsTo f' t s) : BijOn f s t := ⟨hf, h.left.injOn, h.right.surjOn hf'⟩ end InvOn end Set /-! ### `invFunOn` is a left/right inverse -/ namespace Function variable {s : Set α} {f : α → β} {a : α} {b : β} /-- Construct the inverse for a function `f` on domain `s`. This function is a right inverse of `f` on `f '' s`. For a computable version, see `Function.Embedding.invOfMemRange`. -/ noncomputable def invFunOn [Nonempty α] (f : α → β) (s : Set α) (b : β) : α := open scoped Classical in if h : ∃ a, a ∈ s ∧ f a = b then Classical.choose h else Classical.choice ‹Nonempty α› variable [Nonempty α] theorem invFunOn_pos (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s ∧ f (invFunOn f s b) = b := by rw [invFunOn, dif_pos h] exact Classical.choose_spec h theorem invFunOn_mem (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s := (invFunOn_pos h).left theorem invFunOn_eq (h : ∃ a ∈ s, f a = b) : f (invFunOn f s b) = b := (invFunOn_pos h).right theorem invFunOn_neg (h : ¬∃ a ∈ s, f a = b) : invFunOn f s b = Classical.choice ‹Nonempty α› := by rw [invFunOn, dif_neg h] @[simp] theorem invFunOn_apply_mem (h : a ∈ s) : invFunOn f s (f a) ∈ s := invFunOn_mem ⟨a, h, rfl⟩ theorem invFunOn_apply_eq (h : a ∈ s) : f (invFunOn f s (f a)) = f a := invFunOn_eq ⟨a, h, rfl⟩ end Function open Function namespace Set variable {s s₁ s₂ : Set α} {t : Set β} {f : α → β} theorem InjOn.leftInvOn_invFunOn [Nonempty α] (h : InjOn f s) : LeftInvOn (invFunOn f s) f s := fun _a ha => h (invFunOn_apply_mem ha) ha (invFunOn_apply_eq ha) theorem InjOn.invFunOn_image [Nonempty α] (h : InjOn f s₂) (ht : s₁ ⊆ s₂) : invFunOn f s₂ '' (f '' s₁) = s₁ := h.leftInvOn_invFunOn.image_image' ht theorem _root_.Function.leftInvOn_invFunOn_of_subset_image_image [Nonempty α] (h : s ⊆ (invFunOn f s) '' (f '' s)) : LeftInvOn (invFunOn f s) f s := fun x hx ↦ by obtain ⟨-, ⟨x, hx', rfl⟩, rfl⟩ := h hx rw [invFunOn_apply_eq (f := f) hx'] theorem injOn_iff_invFunOn_image_image_eq_self [Nonempty α] : InjOn f s ↔ (invFunOn f s) '' (f '' s) = s := ⟨fun h ↦ h.invFunOn_image Subset.rfl, fun h ↦ (Function.leftInvOn_invFunOn_of_subset_image_image h.symm.subset).injOn⟩ theorem _root_.Function.invFunOn_injOn_image [Nonempty α] (f : α → β) (s : Set α) : Set.InjOn (invFunOn f s) (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨x', hx', rfl⟩ he rw [← invFunOn_apply_eq (f := f) hx, he, invFunOn_apply_eq (f := f) hx'] theorem _root_.Function.invFunOn_image_image_subset [Nonempty α] (f : α → β) (s : Set α) : (invFunOn f s) '' (f '' s) ⊆ s := by rintro _ ⟨_, ⟨x,hx,rfl⟩, rfl⟩; exact invFunOn_apply_mem hx theorem SurjOn.rightInvOn_invFunOn [Nonempty α] (h : SurjOn f s t) : RightInvOn (invFunOn f s) f t := fun _y hy => invFunOn_eq <| h hy theorem BijOn.invOn_invFunOn [Nonempty α] (h : BijOn f s t) : InvOn (invFunOn f s) f s t := ⟨h.injOn.leftInvOn_invFunOn, h.surjOn.rightInvOn_invFunOn⟩ theorem SurjOn.invOn_invFunOn [Nonempty α] (h : SurjOn f s t) : InvOn (invFunOn f s) f (invFunOn f s '' t) t := by refine ⟨?_, h.rightInvOn_invFunOn⟩ rintro _ ⟨y, hy, rfl⟩ rw [h.rightInvOn_invFunOn hy] theorem SurjOn.mapsTo_invFunOn [Nonempty α] (h : SurjOn f s t) : MapsTo (invFunOn f s) t s := fun _y hy => mem_preimage.2 <| invFunOn_mem <| h hy /-- This lemma is a special case of `rightInvOn_invFunOn.image_image'`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image_of_subset [Nonempty α] {r : Set β} (hf : SurjOn f s t) (hrt : r ⊆ t) : f '' (f.invFunOn s '' r) = r := hf.rightInvOn_invFunOn.image_image' hrt /-- This lemma is a special case of `rightInvOn_invFunOn.image_image`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image [Nonempty α] (hf : SurjOn f s t) : f '' (f.invFunOn s '' t) = t := hf.rightInvOn_invFunOn.image_image theorem SurjOn.bijOn_subset [Nonempty α] (h : SurjOn f s t) : BijOn f (invFunOn f s '' t) t := by refine h.invOn_invFunOn.bijOn ?_ (mapsTo_image _ _) rintro _ ⟨y, hy, rfl⟩ rwa [h.rightInvOn_invFunOn hy] theorem surjOn_iff_exists_bijOn_subset : SurjOn f s t ↔ ∃ s' ⊆ s, BijOn f s' t := by constructor · rcases eq_empty_or_nonempty t with (rfl | ht) · exact fun _ => ⟨∅, empty_subset _, bijOn_empty f⟩ · intro h haveI : Nonempty α := ⟨Classical.choose (h.comap_nonempty ht)⟩ exact ⟨_, h.mapsTo_invFunOn.image_subset, h.bijOn_subset⟩ · rintro ⟨s', hs', hfs'⟩ exact hfs'.surjOn.mono hs' (Subset.refl _) alias ⟨SurjOn.exists_bijOn_subset, _⟩ := Set.surjOn_iff_exists_bijOn_subset variable (f s) lemma exists_subset_bijOn : ∃ s' ⊆ s, BijOn f s' (f '' s) := surjOn_iff_exists_bijOn_subset.mp (surjOn_image f s) lemma exists_image_eq_and_injOn : ∃ u, f '' u = f '' s ∧ InjOn f u := let ⟨u, _, hfu⟩ := exists_subset_bijOn s f ⟨u, hfu.image_eq, hfu.injOn⟩ variable {f s} lemma exists_image_eq_injOn_of_subset_range (ht : t ⊆ range f) : ∃ s, f '' s = t ∧ InjOn f s := image_preimage_eq_of_subset ht ▸ exists_image_eq_and_injOn _ _ /-- If `f` maps `s` bijectively to `t` and a set `t'` is contained in the image of some `s₁ ⊇ s`, then `s₁` has a subset containing `s` that `f` maps bijectively to `t'`. -/ theorem BijOn.exists_extend_of_subset {t' : Set β} (h : BijOn f s t) (hss₁ : s ⊆ s₁) (htt' : t ⊆ t') (ht' : SurjOn f s₁ t') : ∃ s', s ⊆ s' ∧ s' ⊆ s₁ ∧ Set.BijOn f s' t' := by obtain ⟨r, hrss, hbij⟩ := exists_subset_bijOn ((s₁ ∩ f ⁻¹' t') \ f ⁻¹' t) f rw [image_diff_preimage, image_inter_preimage] at hbij refine ⟨s ∪ r, subset_union_left, ?_, ?_, ?_, fun y hyt' ↦ ?_⟩ · exact union_subset hss₁ <| hrss.trans <| diff_subset.trans inter_subset_left · rw [mapsTo', image_union, hbij.image_eq, h.image_eq, union_subset_iff] exact ⟨htt', diff_subset.trans inter_subset_right⟩ · rw [injOn_union, and_iff_right h.injOn, and_iff_right hbij.injOn] · refine fun x hxs y hyr hxy ↦ (hrss hyr).2 ?_ rw [← h.image_eq] exact ⟨x, hxs, hxy⟩ exact (subset_diff.1 hrss).2.symm.mono_left h.mapsTo rw [image_union, h.image_eq, hbij.image_eq, union_diff_self] exact .inr ⟨ht' hyt', hyt'⟩ /-- If `f` maps `s` bijectively to `t`, and `t'` is a superset of `t` contained in the range of `f`, then `f` maps some superset of `s` bijectively to `t'`. -/ theorem BijOn.exists_extend {t' : Set β} (h : BijOn f s t) (htt' : t ⊆ t') (ht' : t' ⊆ range f) : ∃ s', s ⊆ s' ∧ BijOn f s' t' := by simpa using h.exists_extend_of_subset (subset_univ s) htt' (by simpa [SurjOn]) theorem InjOn.exists_subset_injOn_subset_range_eq {r : Set α} (hinj : InjOn f r) (hrs : r ⊆ s) : ∃ u : Set α, r ⊆ u ∧ u ⊆ s ∧ f '' u = f '' s ∧ InjOn f u := by obtain ⟨u, hru, hus, h⟩ := hinj.bijOn_image.exists_extend_of_subset hrs (image_subset f hrs) Subset.rfl exact ⟨u, hru, hus, h.image_eq, h.injOn⟩ theorem preimage_invFun_of_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∈ s) : invFun f ⁻¹' s = f '' s ∪ (range f)ᶜ := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · simp only [mem_preimage, mem_union, mem_compl_iff, mem_range_self, not_true, or_false, leftInverse_invFun hf _, hf.mem_set_image] · simp only [mem_preimage, invFun_neg hx, h, hx, mem_union, mem_compl_iff, not_false_iff, or_true] theorem preimage_invFun_of_not_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∉ s) : invFun f ⁻¹' s = f '' s := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · rw [mem_preimage, leftInverse_invFun hf, hf.mem_set_image] · have : x ∉ f '' s := fun h' => hx (image_subset_range _ _ h') simp only [mem_preimage, invFun_neg hx, h, this] lemma BijOn.symm {g : β → α} (h : InvOn f g t s) (hf : BijOn f s t) : BijOn g t s := ⟨h.2.mapsTo hf.surjOn, h.1.injOn, h.2.surjOn hf.mapsTo⟩ lemma bijOn_comm {g : β → α} (h : InvOn f g t s) : BijOn f s t ↔ BijOn g t s := ⟨BijOn.symm h, BijOn.symm h.symm⟩ end Set namespace Function open Set variable {fa : α → α} {fb : β → β} {f : α → β} {g : β → γ} {s t : Set α} theorem Injective.comp_injOn (hg : Injective g) (hf : s.InjOn f) : s.InjOn (g ∘ f) := hg.injOn.comp hf (mapsTo_univ _ _) theorem Surjective.surjOn (hf : Surjective f) (s : Set β) : SurjOn f univ s := (surjective_iff_surjOn_univ.1 hf).mono (Subset.refl _) (subset_univ _) theorem LeftInverse.leftInvOn {g : β → α} (h : LeftInverse f g) (s : Set β) : LeftInvOn f g s := fun x _ => h x theorem RightInverse.rightInvOn {g : β → α} (h : RightInverse f g) (s : Set α) : RightInvOn f g s := fun x _ => h x theorem LeftInverse.rightInvOn_range {g : β → α} (h : LeftInverse f g) : RightInvOn f g (range g) := forall_mem_range.2 fun i => congr_arg g (h i) namespace Semiconj theorem mapsTo_image (h : Semiconj f fa fb) (ha : MapsTo fa s t) : MapsTo fb (f '' s) (f '' t) := fun _y ⟨x, hx, hy⟩ => hy ▸ ⟨fa x, ha hx, h x⟩ theorem mapsTo_image_right {t : Set β} (h : Semiconj f fa fb) (hst : MapsTo f s t) : MapsTo f (fa '' s) (fb '' t) := mapsTo_image_iff.2 fun x hx ↦ ⟨f x, hst hx, (h x).symm⟩ theorem mapsTo_range (h : Semiconj f fa fb) : MapsTo fb (range f) (range f) := fun _y ⟨x, hy⟩ => hy ▸ ⟨fa x, h x⟩ theorem surjOn_image (h : Semiconj f fa fb) (ha : SurjOn fa s t) : SurjOn fb (f '' s) (f '' t) := by rintro y ⟨x, hxt, rfl⟩ rcases ha hxt with ⟨x, hxs, rfl⟩ rw [h x] exact mem_image_of_mem _ (mem_image_of_mem _ hxs) theorem surjOn_range (h : Semiconj f fa fb) (ha : Surjective fa) : SurjOn fb (range f) (range f) := by rw [← image_univ] exact h.surjOn_image (ha.surjOn univ) theorem injOn_image (h : Semiconj f fa fb) (ha : InjOn fa s) (hf : InjOn f (fa '' s)) : InjOn fb (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ H simp only [← h.eq] at H exact congr_arg f (ha hx hy <| hf (mem_image_of_mem fa hx) (mem_image_of_mem fa hy) H) theorem injOn_range (h : Semiconj f fa fb) (ha : Injective fa) (hf : InjOn f (range fa)) : InjOn fb (range f) := by rw [← image_univ] at * exact h.injOn_image ha.injOn hf theorem bijOn_image (h : Semiconj f fa fb) (ha : BijOn fa s t) (hf : InjOn f t) : BijOn fb (f '' s) (f '' t) := ⟨h.mapsTo_image ha.mapsTo, h.injOn_image ha.injOn (ha.image_eq.symm ▸ hf), h.surjOn_image ha.surjOn⟩ theorem bijOn_range (h : Semiconj f fa fb) (ha : Bijective fa) (hf : Injective f) : BijOn fb (range f) (range f) := by rw [← image_univ] exact h.bijOn_image (bijective_iff_bijOn_univ.1 ha) hf.injOn theorem mapsTo_preimage (h : Semiconj f fa fb) {s t : Set β} (hb : MapsTo fb s t) : MapsTo fa (f ⁻¹' s) (f ⁻¹' t) := fun x hx => by simp only [mem_preimage, h x, hb hx] theorem injOn_preimage (h : Semiconj f fa fb) {s : Set β} (hb : InjOn fb s) (hf : InjOn f (f ⁻¹' s)) : InjOn fa (f ⁻¹' s) := by intro x hx y hy H have := congr_arg f H rw [h.eq, h.eq] at this exact hf hx hy (hb hx hy this) end Semiconj theorem update_comp_eq_of_not_mem_range' {α : Sort*} {β : Type*} {γ : β → Sort*} [DecidableEq β] (g : ∀ b, γ b) {f : α → β} {i : β} (a : γ i) (h : i ∉ Set.range f) : (fun j => update g i a (f j)) = fun j => g (f j) := (update_comp_eq_of_forall_ne' _ _) fun x hx => h ⟨x, hx⟩ /-- Non-dependent version of `Function.update_comp_eq_of_not_mem_range'` -/ theorem update_comp_eq_of_not_mem_range {α : Sort*} {β : Type*} {γ : Sort*} [DecidableEq β] (g : β → γ) {f : α → β} {i : β} (a : γ) (h : i ∉ Set.range f) : update g i a ∘ f = g ∘ f := update_comp_eq_of_not_mem_range' g a h theorem insert_injOn (s : Set α) : sᶜ.InjOn fun a => insert a s := fun _a ha _ _ => (insert_inj ha).1 lemma apply_eq_of_range_eq_singleton {f : α → β} {b : β} (h : range f = {b}) (a : α) : f a = b := by simpa only [h, mem_singleton_iff] using mem_range_self (f := f) a end Function /-! ### Equivalences, permutations -/ namespace Set variable {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} {g g₁ g₂ : Perm α} {s t : Set α} protected lemma MapsTo.extendDomain (h : MapsTo g s t) : MapsTo (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩; exact ⟨_, h ha, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩ protected lemma SurjOn.extendDomain (h : SurjOn g s t) : SurjOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩ obtain ⟨b, hb, rfl⟩ := h ha exact ⟨_, ⟨_, hb, rfl⟩, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩ protected lemma BijOn.extendDomain (h : BijOn g s t) : BijOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := ⟨h.mapsTo.extendDomain, (g.extendDomain f).injective.injOn, h.surjOn.extendDomain⟩ protected lemma LeftInvOn.extendDomain (h : LeftInvOn g₁ g₂ s) : LeftInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) := by rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha] protected lemma RightInvOn.extendDomain (h : RightInvOn g₁ g₂ t) : RightInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha] protected lemma InvOn.extendDomain (h : InvOn g₁ g₂ s t) : InvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := ⟨h.1.extendDomain, h.2.extendDomain⟩ end Set namespace Set variable {α₁ α₂ β₁ β₂ : Type*} {s₁ : Set α₁} {s₂ : Set α₂} {t₁ : Set β₁} {t₂ : Set β₂} {f₁ : α₁ → β₁} {f₂ : α₂ → β₂} {g₁ : β₁ → α₁} {g₂ : β₂ → α₂} lemma InjOn.prodMap (h₁ : s₁.InjOn f₁) (h₂ : s₂.InjOn f₂) : (s₁ ×ˢ s₂).InjOn fun x ↦ (f₁ x.1, f₂ x.2) := fun x hx y hy ↦ by simp_rw [Prod.ext_iff]; exact And.imp (h₁ hx.1 hy.1) (h₂ hx.2 hy.2) lemma SurjOn.prodMap (h₁ : SurjOn f₁ s₁ t₁) (h₂ : SurjOn f₂ s₂ t₂) : SurjOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := by rintro x hx obtain ⟨a₁, ha₁, hx₁⟩ := h₁ hx.1 obtain ⟨a₂, ha₂, hx₂⟩ := h₂ hx.2 exact ⟨(a₁, a₂), ⟨ha₁, ha₂⟩, Prod.ext hx₁ hx₂⟩ lemma MapsTo.prodMap (h₁ : MapsTo f₁ s₁ t₁) (h₂ : MapsTo f₂ s₂ t₂) : MapsTo (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := fun _x hx ↦ ⟨h₁ hx.1, h₂ hx.2⟩ lemma BijOn.prodMap (h₁ : BijOn f₁ s₁ t₁) (h₂ : BijOn f₂ s₂ t₂) : BijOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := ⟨h₁.mapsTo.prodMap h₂.mapsTo, h₁.injOn.prodMap h₂.injOn, h₁.surjOn.prodMap h₂.surjOn⟩ lemma LeftInvOn.prodMap (h₁ : LeftInvOn g₁ f₁ s₁) (h₂ : LeftInvOn g₂ f₂ s₂) : LeftInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) := fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2) lemma RightInvOn.prodMap (h₁ : RightInvOn g₁ f₁ t₁) (h₂ : RightInvOn g₂ f₂ t₂) : RightInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (t₁ ×ˢ t₂) := fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2) lemma InvOn.prodMap (h₁ : InvOn g₁ f₁ s₁ t₁) (h₂ : InvOn g₂ f₂ s₂ t₂) : InvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := ⟨h₁.1.prodMap h₂.1, h₁.2.prodMap h₂.2⟩ end Set namespace Equiv open Set variable (e : α ≃ β) {s : Set α} {t : Set β} lemma bijOn' (h₁ : MapsTo e s t) (h₂ : MapsTo e.symm t s) : BijOn e s t := ⟨h₁, e.injective.injOn, fun b hb ↦ ⟨e.symm b, h₂ hb, apply_symm_apply _ _⟩⟩ protected lemma bijOn (h : ∀ a, e a ∈ t ↔ a ∈ s) : BijOn e s t := e.bijOn' (fun _ ↦ (h _).2) fun b hb ↦ (h _).1 <| by rwa [apply_symm_apply] lemma invOn : InvOn e e.symm t s := ⟨e.rightInverse_symm.leftInvOn _, e.leftInverse_symm.leftInvOn _⟩ lemma bijOn_image : BijOn e s (e '' s) := e.injective.injOn.bijOn_image lemma bijOn_symm_image : BijOn e.symm (e '' s) s := e.bijOn_image.symm e.invOn variable {e} @[simp] lemma bijOn_symm : BijOn e.symm t s ↔ BijOn e s t := bijOn_comm e.symm.invOn alias ⟨_root_.Set.BijOn.of_equiv_symm, _root_.Set.BijOn.equiv_symm⟩ := bijOn_symm variable [DecidableEq α] {a b : α} lemma bijOn_swap (ha : a ∈ s) (hb : b ∈ s) : BijOn (swap a b) s s := (swap a b).bijOn fun x ↦ by obtain rfl | hxa := eq_or_ne x a <;> obtain rfl | hxb := eq_or_ne x b <;> simp [*, swap_apply_of_ne_of_ne] end Equiv
Mathlib/Data/Set/Function.lean
1,973
1,978
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Topology.Order.ProjIcc /-! # Inverse trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse tan function. (This is delayed as it is easier to set up after developing complex trigonometric functions.) Basic inequalities on trigonometric functions. -/ noncomputable section open Topology Filter Set Filter Real namespace Real variable {x y : ℝ} /-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`. It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/ @[pp_nodot] noncomputable def arcsin : ℝ → ℝ := Subtype.val ∘ IccExtend (neg_le_self zero_le_one) sinOrderIso.symm theorem arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := Subtype.coe_prop _ @[simp] theorem range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) := by rw [arcsin, range_comp Subtype.val] simp [Icc] theorem arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2 theorem neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1 theorem arcsin_projIcc (x : ℝ) : arcsin (projIcc (-1) 1 (neg_le_self zero_le_one) x) = arcsin x := by rw [arcsin, Function.comp_apply, IccExtend_val, Function.comp_apply, IccExtend, Function.comp_apply] theorem sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x := by simpa [arcsin, IccExtend_of_mem _ _ hx, -OrderIso.apply_symm_apply] using Subtype.ext_iff.1 (sinOrderIso.apply_symm_apply ⟨x, hx⟩) theorem sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x := sin_arcsin' ⟨hx₁, hx₂⟩ theorem arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x := injOn_sin (arcsin_mem_Icc _) hx <| by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)] theorem arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x := arcsin_sin' ⟨hx₁, hx₂⟩ theorem strictMonoOn_arcsin : StrictMonoOn arcsin (Icc (-1) 1) := (Subtype.strictMono_coe _).comp_strictMonoOn <| sinOrderIso.symm.strictMono.strictMonoOn_IccExtend _ @[gcongr] theorem arcsin_lt_arcsin {x y : ℝ} (hx : -1 ≤ x) (hlt : x < y) (hy : y ≤ 1) : arcsin x < arcsin y := strictMonoOn_arcsin ⟨hx, hlt.le.trans hy⟩ ⟨hx.trans hlt.le, hy⟩ hlt theorem monotone_arcsin : Monotone arcsin := (Subtype.mono_coe _).comp <| sinOrderIso.symm.monotone.IccExtend _ @[gcongr] theorem arcsin_le_arcsin {x y : ℝ} (h : x ≤ y) : arcsin x ≤ arcsin y := monotone_arcsin h theorem injOn_arcsin : InjOn arcsin (Icc (-1) 1) := strictMonoOn_arcsin.injOn theorem arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) : arcsin x = arcsin y ↔ x = y := injOn_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ @[continuity, fun_prop] theorem continuous_arcsin : Continuous arcsin := continuous_subtype_val.comp sinOrderIso.symm.continuous.Icc_extend' @[fun_prop] theorem continuousAt_arcsin {x : ℝ} : ContinuousAt arcsin x := continuous_arcsin.continuousAt theorem arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin y = x := by subst y exact injOn_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x)) @[simp] theorem arcsin_zero : arcsin 0 = 0 := arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩ @[simp] theorem arcsin_one : arcsin 1 = π / 2 := arcsin_eq_of_sin_eq sin_pi_div_two <| right_mem_Icc.2 (neg_le_self pi_div_two_pos.le) theorem arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 := by rw [← arcsin_projIcc, projIcc_of_right_le _ hx, Subtype.coe_mk, arcsin_one] theorem arcsin_neg_one : arcsin (-1) = -(π / 2) := arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) <| left_mem_Icc.2 (neg_le_self pi_div_two_pos.le) theorem arcsin_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) := by rw [← arcsin_projIcc, projIcc_of_le_left _ hx, Subtype.coe_mk, arcsin_neg_one] @[simp] theorem arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x := by rcases le_total x (-1) with hx₁ | hx₁ · rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] rcases le_total 1 x with hx₂ | hx₂ · rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)] refine arcsin_eq_of_sin_eq ?_ ?_ · rw [sin_neg, sin_arcsin hx₁ hx₂] · exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ theorem arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := by rw [← arcsin_sin' hy, strictMonoOn_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy] theorem arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := by rcases le_total x (-1) with hx₁ | hx₁ · simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] rcases lt_or_le 1 x with hx₂ | hx₂ · simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂] exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy) theorem le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x ≤ arcsin y ↔ sin x ≤ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩, sin_neg, neg_le_neg_iff] theorem le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) : x ≤ arcsin y ↔ sin x ≤ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩, sin_neg, neg_le_neg_iff] theorem arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le hy hx).trans not_le theorem arcsin_lt_iff_lt_sin' {x y : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le' hy).trans not_le theorem lt_arcsin_iff_sin_lt {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x < arcsin y ↔ sin x < y := not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin hy hx).trans not_le theorem lt_arcsin_iff_sin_lt' {x y : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) : x < arcsin y ↔ sin x < y := not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin' hx).trans not_le theorem arcsin_eq_iff_eq_sin {x y : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) : arcsin x = y ↔ x = sin y := by simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy), le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)] @[simp] theorem arcsin_nonneg {x : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x := (le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans <| by rw [sin_zero] @[simp] theorem arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 := neg_nonneg.symm.trans <| arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg @[simp] theorem arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 := by simp [le_antisymm_iff] @[simp] theorem zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 := eq_comm.trans arcsin_eq_zero_iff @[simp] theorem arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x := lt_iff_lt_of_le_iff_le arcsin_nonpos @[simp] theorem arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 := lt_iff_lt_of_le_iff_le arcsin_nonneg @[simp] theorem arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ x < 1 := (arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 <| neg_lt_self pi_div_two_pos)).trans <| by rw [sin_pi_div_two] @[simp] theorem neg_pi_div_two_lt_arcsin {x : ℝ} : -(π / 2) < arcsin x ↔ -1 < x := (lt_arcsin_iff_sin_lt' <| left_mem_Ico.2 <| neg_lt_self pi_div_two_pos).trans <| by rw [sin_neg, sin_pi_div_two] @[simp] theorem arcsin_eq_pi_div_two {x : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x := ⟨fun h => not_lt.1 fun h' => (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩ @[simp] theorem pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x := eq_comm.trans arcsin_eq_pi_div_two @[simp] theorem pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ x := (arcsin_le_pi_div_two x).le_iff_eq.trans pi_div_two_eq_arcsin @[simp] theorem arcsin_eq_neg_pi_div_two {x : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 := ⟨fun h => not_lt.1 fun h' => (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩ @[simp] theorem neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 := eq_comm.trans arcsin_eq_neg_pi_div_two @[simp] theorem arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -1 := (neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two @[simp] theorem pi_div_four_le_arcsin {x} : π / 4 ≤ arcsin x ↔ √2 / 2 ≤ x := by rw [← sin_pi_div_four, le_arcsin_iff_sin_le'] have := pi_pos constructor <;> linarith theorem mapsTo_sin_Ioo : MapsTo sin (Ioo (-(π / 2)) (π / 2)) (Ioo (-1) 1) := fun x h => by rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin, arcsin_sin h.1.le h.2.le] /-- `Real.sin` as a `PartialHomeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/ @[simp] def sinPartialHomeomorph : PartialHomeomorph ℝ ℝ where toFun := sin invFun := arcsin source := Ioo (-(π / 2)) (π / 2) target := Ioo (-1) 1 map_source' := mapsTo_sin_Ioo map_target' _ hy := ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩ left_inv' _ hx := arcsin_sin hx.1.le hx.2.le right_inv' _ hy := sin_arcsin hy.1.le hy.2.le open_source := isOpen_Ioo open_target := isOpen_Ioo continuousOn_toFun := continuous_sin.continuousOn continuousOn_invFun := continuous_arcsin.continuousOn theorem cos_arcsin_nonneg (x : ℝ) : 0 ≤ cos (arcsin x) := cos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩ -- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`. theorem cos_arcsin (x : ℝ) : cos (arcsin x) = √(1 - x ^ 2) := by by_cases hx₁ : -1 ≤ x; swap · rw [not_le] at hx₁ rw [arcsin_of_le_neg_one hx₁.le, cos_neg, cos_pi_div_two, sqrt_eq_zero_of_nonpos] nlinarith by_cases hx₂ : x ≤ 1; swap · rw [not_le] at hx₂ rw [arcsin_of_one_le hx₂.le, cos_pi_div_two, sqrt_eq_zero_of_nonpos] nlinarith have : sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x) rw [← eq_sub_iff_add_eq', ← sqrt_inj (sq_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))), sq, sqrt_mul_self (cos_arcsin_nonneg _)] at this rw [this, sin_arcsin hx₁ hx₂] -- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`. theorem tan_arcsin (x : ℝ) : tan (arcsin x) = x / √(1 - x ^ 2) := by rw [tan_eq_sin_div_cos, cos_arcsin] by_cases hx₁ : -1 ≤ x; swap · have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith) rw [h] simp by_cases hx₂ : x ≤ 1; swap · have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith) rw [h] simp rw [sin_arcsin hx₁ hx₂] /-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`. It defaults to `π` on `(-∞, -1)` and to `0` to `(1, ∞)`. -/ @[pp_nodot] noncomputable def arccos (x : ℝ) : ℝ := π / 2 - arcsin x theorem arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x := rfl theorem arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x := by simp [arccos] theorem arccos_le_pi (x : ℝ) : arccos x ≤ π := by unfold arccos; linarith [neg_pi_div_two_le_arcsin x] theorem arccos_nonneg (x : ℝ) : 0 ≤ arccos x := by unfold arccos; linarith [arcsin_le_pi_div_two x] @[simp] theorem arccos_pos {x : ℝ} : 0 < arccos x ↔ x < 1 := by simp [arccos] theorem cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x := by
rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂] theorem arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x := by rw [arccos, ← sin_pi_div_two_sub, arcsin_sin] <;> simp [sub_eq_add_neg] <;> linarith lemma arccos_eq_of_eq_cos (hy₀ : 0 ≤ y) (hy₁ : y ≤ π) (hxy : x = cos y) : arccos x = y := by rw [hxy, arccos_cos hy₀ hy₁] theorem strictAntiOn_arccos : StrictAntiOn arccos (Icc (-1) 1) := fun _ hx _ hy h => sub_lt_sub_left (strictMonoOn_arcsin hx hy h) _ @[gcongr] lemma arccos_lt_arccos {x y : ℝ} (hx : -1 ≤ x) (hlt : x < y) (hy : y ≤ 1) :
Mathlib/Analysis/SpecialFunctions/Trigonometric/Inverse.lean
306
318
/- 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 /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open Real ComplexConjugate 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 noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl 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, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] 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)] theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] @[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] @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] @[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] @[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, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log, Complex.arg_ofReal_of_neg hx, 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 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) _ @[bound] theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] 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, *] 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 _ 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] @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def] theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 := by by_cases h : x = 0 <;> simp [h, zero_le_one] theorem zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x := by by_cases h : x = 0 <;> simp [h, zero_le_one] @[bound] 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 _)] 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] @[bound] 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 _) 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] lemma rpow_inv_log (hx₀ : 0 < x) (hx₁ : x ≠ 1) : x ^ (log x)⁻¹ = exp 1 := by rw [rpow_def_of_pos hx₀, mul_inv_cancel₀] exact log_ne_zero.2 ⟨hx₀.ne', hx₁, (hx₀.trans' <| by norm_num).ne'⟩ /-- See `Real.rpow_inv_log` for the equality when `x ≠ 1` is strictly positive. -/ lemma rpow_inv_log_le_exp_one : x ^ (log x)⁻¹ ≤ exp 1 := by calc _ ≤ |x ^ (log x)⁻¹| := le_abs_self _ _ ≤ |x| ^ (log x)⁻¹ := abs_rpow_le_abs_rpow .. rw [← log_abs] obtain hx | hx := (abs_nonneg x).eq_or_gt · simp [hx] · rw [rpow_def_of_pos hx] gcongr exact mul_inv_le_one 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 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] 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 _ _ /-- 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) /-- 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] 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 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)] 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] 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] 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] protected theorem _root_.HasCompactSupport.rpow_const {α : Type*} [TopologicalSpace α] {f : α → ℝ} (hf : HasCompactSupport f) {r : ℝ} (hr : r ≠ 0) : HasCompactSupport (fun x ↦ f x ^ r) := hf.comp_left (g := (· ^ r)) (Real.zero_rpow hr) 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] 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, norm_neg, arg_ofReal_of_neg hlt, ← ofReal_neg, arg_ofReal_of_nonneg (neg_nonneg.2 hx), ofReal_zero, zero_mul, add_zero] lemma cpow_ofReal (x : ℂ) (y : ℝ) : x ^ (y : ℂ) = ↑(‖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 [norm_pos_iff] lemma cpow_ofReal_re (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).re = ‖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 = ‖x‖ ^ y * Real.sin (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.sin] theorem norm_cpow_of_ne_zero {z : ℂ} (hz : z ≠ 0) (w : ℂ) : ‖z ^ w‖ = ‖z‖ ^ w.re / Real.exp (arg z * im w) := by rw [cpow_def_of_ne_zero hz, norm_exp, mul_re, log_re, log_im, Real.exp_sub, Real.rpow_def_of_pos (norm_pos_iff.mpr hz)] theorem norm_cpow_of_imp {z w : ℂ} (h : z = 0 → w.re = 0 → w = 0) : ‖z ^ w‖ = ‖z‖ ^ w.re / Real.exp (arg z * im w) := by rcases ne_or_eq z 0 with (hz | rfl) <;> [exact norm_cpow_of_ne_zero hz w; rw [norm_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, norm_zero] exact ne_of_apply_ne re hw theorem norm_cpow_le (z w : ℂ) : ‖z ^ w‖ ≤ ‖z‖ ^ w.re / Real.exp (arg z * im w) := by by_cases h : z = 0 → w.re = 0 → w = 0 · exact (norm_cpow_of_imp h).le · push_neg at h simp [h] @[simp] theorem norm_cpow_real (x : ℂ) (y : ℝ) : ‖x ^ (y : ℂ)‖ = ‖x‖ ^ y := by rw [norm_cpow_of_imp] <;> simp @[simp] theorem norm_cpow_inv_nat (x : ℂ) (n : ℕ) : ‖x ^ (n⁻¹ : ℂ)‖ = ‖x‖ ^ (n⁻¹ : ℝ) := by rw [← norm_cpow_real]; simp theorem norm_cpow_eq_rpow_re_of_pos {x : ℝ} (hx : 0 < x) (y : ℂ) : ‖(x : ℂ) ^ y‖ = x ^ y.re := by rw [norm_cpow_of_ne_zero (ofReal_ne_zero.mpr hx.ne'), arg_ofReal_of_nonneg hx.le, zero_mul, Real.exp_zero, div_one, Complex.norm_of_nonneg hx.le] theorem norm_cpow_eq_rpow_re_of_nonneg {x : ℝ} (hx : 0 ≤ x) {y : ℂ} (hy : re y ≠ 0) : ‖(x : ℂ) ^ y‖ = x ^ re y := by rw [norm_cpow_of_imp] <;> simp [*, arg_ofReal_of_nonneg, abs_of_nonneg] @[deprecated (since := "2025-02-17")] alias abs_cpow_of_ne_zero := norm_cpow_of_ne_zero @[deprecated (since := "2025-02-17")] alias abs_cpow_of_imp := norm_cpow_of_imp @[deprecated (since := "2025-02-17")] alias abs_cpow_le := norm_cpow_le @[deprecated (since := "2025-02-17")] alias abs_cpow_real := norm_cpow_real @[deprecated (since := "2025-02-17")] alias abs_cpow_inv_nat := norm_cpow_inv_nat @[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_pos := norm_cpow_eq_rpow_re_of_pos @[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_nonneg := norm_cpow_eq_rpow_re_of_nonneg open Filter in lemma norm_ofReal_cpow_eventually_eq_atTop (c : ℂ) : (fun t : ℝ ↦ ‖(t : ℂ) ^ c‖) =ᶠ[atTop] fun t ↦ t ^ c.re := by filter_upwards [eventually_gt_atTop 0] with t ht rw [norm_cpow_eq_rpow_re_of_pos ht] lemma norm_natCast_cpow_of_re_ne_zero (n : ℕ) {s : ℂ} (hs : s.re ≠ 0) : ‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by rw [← ofReal_natCast, norm_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 [← ofReal_natCast, norm_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 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] lemma rpow_pow_comm {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (n : ℕ) : (x ^ y) ^ n = (x ^ n) ^ y := by simp_rw [← rpow_natCast, ← rpow_mul hx, mul_comm y] lemma rpow_zpow_comm {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (n : ℤ) : (x ^ y) ^ n = (x ^ n) ^ y := by simp_rw [← rpow_intCast, ← rpow_mul hx, mul_comm y] lemma rpow_add_intCast {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] lemma rpow_add_natCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y + n) = x ^ y * x ^ n := by simpa using rpow_add_intCast hx y n lemma rpow_sub_intCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_add_intCast hx y (-n) lemma rpow_sub_natCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_sub_intCast hx y n lemma rpow_add_intCast' (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_natCast' (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_intCast' (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_natCast' (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_natCast hx y 1 theorem rpow_sub_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by simpa using rpow_sub_natCast hx y 1 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] 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] 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 theorem inv_rpow (hx : 0 ≤ x) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by simp only [← rpow_neg_one, ← rpow_mul hx, mul_comm] 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] 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] 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] 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] 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, bound] 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; rcases 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 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, bound] 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₂') 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⟩ 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 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 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 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 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 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) @[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) 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 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 theorem antitoneOn_rpow_Ioi_of_exponent_nonpos {r : ℝ} (hr : r ≤ 0) : AntitoneOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_le_rpow_of_exponent_nonpos ha hab hr @[simp] theorem rpow_le_rpow_left_iff (hx : 1 < x) : x ^ y ≤ x ^ z ↔ y ≤ z := by have x_pos : 0 < x := lt_trans zero_lt_one hx rw [← log_le_log_iff (rpow_pos_of_pos x_pos y) (rpow_pos_of_pos x_pos z), log_rpow x_pos, log_rpow x_pos, mul_le_mul_right (log_pos hx)] @[simp] theorem rpow_lt_rpow_left_iff (hx : 1 < x) : x ^ y < x ^ z ↔ y < z := by rw [lt_iff_not_le, rpow_le_rpow_left_iff hx, lt_iff_not_le] theorem rpow_lt_rpow_of_exponent_gt (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_lt_exp]; exact mul_lt_mul_of_neg_left hyz (log_neg hx0 hx1) theorem rpow_le_rpow_of_exponent_ge (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_le_exp]; exact mul_le_mul_of_nonpos_left hyz (log_nonpos (le_of_lt hx0) hx1) @[simp] theorem rpow_le_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) : x ^ y ≤ x ^ z ↔ z ≤ y := by rw [← log_le_log_iff (rpow_pos_of_pos hx0 y) (rpow_pos_of_pos hx0 z), log_rpow hx0, log_rpow hx0, mul_le_mul_right_of_neg (log_neg hx0 hx1)] @[simp] theorem rpow_lt_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) : x ^ y < x ^ z ↔ z < y := by rw [lt_iff_not_le, rpow_le_rpow_left_iff_of_base_lt_one hx0 hx1, lt_iff_not_le] theorem rpow_lt_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x < 1) (hz : 0 < z) : x ^ z < 1 := by rw [← one_rpow z] exact rpow_lt_rpow hx1 hx2 hz theorem rpow_le_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := by rw [← one_rpow z] exact rpow_le_rpow hx1 hx2 hz theorem rpow_lt_one_of_one_lt_of_neg {x z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := by convert rpow_lt_rpow_of_exponent_lt hx hz exact (rpow_zero x).symm theorem rpow_le_one_of_one_le_of_nonpos {x z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x ^ z ≤ 1 := by convert rpow_le_rpow_of_exponent_le hx hz exact (rpow_zero x).symm theorem one_lt_rpow {x z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := by rw [← one_rpow z] exact rpow_lt_rpow zero_le_one hx hz theorem one_le_rpow {x z : ℝ} (hx : 1 ≤ x) (hz : 0 ≤ z) : 1 ≤ x ^ z := by rw [← one_rpow z] exact rpow_le_rpow zero_le_one hx hz theorem one_lt_rpow_of_pos_of_lt_one_of_neg (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) : 1 < x ^ z := by convert rpow_lt_rpow_of_exponent_gt hx1 hx2 hz exact (rpow_zero x).symm theorem one_le_rpow_of_pos_of_le_one_of_nonpos (hx1 : 0 < x) (hx2 : x ≤ 1) (hz : z ≤ 0) : 1 ≤ x ^ z := by convert rpow_le_rpow_of_exponent_ge hx1 hx2 hz exact (rpow_zero x).symm theorem rpow_lt_one_iff_of_pos (hx : 0 < x) : x ^ y < 1 ↔ 1 < x ∧ y < 0 ∨ x < 1 ∧ 0 < y := by rw [rpow_def_of_pos hx, exp_lt_one_iff, mul_neg_iff, log_pos_iff hx.le, log_neg_iff hx] theorem rpow_lt_one_iff (hx : 0 ≤ x) : x ^ y < 1 ↔ x = 0 ∧ y ≠ 0 ∨ 1 < x ∧ y < 0 ∨ x < 1 ∧ 0 < y := by rcases hx.eq_or_lt with (rfl | hx) · rcases _root_.em (y = 0) with (rfl | hy) <;> simp [*, lt_irrefl, zero_lt_one] · simp [rpow_lt_one_iff_of_pos hx, hx.ne.symm] theorem rpow_lt_one_iff' {x y : ℝ} (hx : 0 ≤ x) (hy : 0 < y) : x ^ y < 1 ↔ x < 1 := by rw [← Real.rpow_lt_rpow_iff hx zero_le_one hy, Real.one_rpow] theorem one_lt_rpow_iff_of_pos (hx : 0 < x) : 1 < x ^ y ↔ 1 < x ∧ 0 < y ∨ x < 1 ∧ y < 0 := by rw [rpow_def_of_pos hx, one_lt_exp_iff, mul_pos_iff, log_pos_iff hx.le, log_neg_iff hx] theorem one_lt_rpow_iff (hx : 0 ≤ x) : 1 < x ^ y ↔ 1 < x ∧ 0 < y ∨ 0 < x ∧ x < 1 ∧ y < 0 := by rcases hx.eq_or_lt with (rfl | hx) · rcases _root_.em (y = 0) with (rfl | hy) <;> simp [*, lt_irrefl, (zero_lt_one' ℝ).not_lt] · simp [one_lt_rpow_iff_of_pos hx, hx] /-- This is a more general but less convenient version of `rpow_le_rpow_of_exponent_ge`. This version allows `x = 0`, so it explicitly forbids `x = y = 0`, `z ≠ 0`. -/ theorem rpow_le_rpow_of_exponent_ge_of_imp (hx0 : 0 ≤ x) (hx1 : x ≤ 1) (hyz : z ≤ y) (h : x = 0 → y = 0 → z = 0) : x ^ y ≤ x ^ z := by rcases eq_or_lt_of_le hx0 with (rfl | hx0') · rcases eq_or_ne y 0 with rfl | hy0 · rw [h rfl rfl] · rw [zero_rpow hy0] apply zero_rpow_nonneg · exact rpow_le_rpow_of_exponent_ge hx0' hx1 hyz /-- This version of `rpow_le_rpow_of_exponent_ge` allows `x = 0` but requires `0 ≤ z`. See also `rpow_le_rpow_of_exponent_ge_of_imp` for the most general version. -/ theorem rpow_le_rpow_of_exponent_ge' (hx0 : 0 ≤ x) (hx1 : x ≤ 1) (hz : 0 ≤ z) (hyz : z ≤ y) : x ^ y ≤ x ^ z := rpow_le_rpow_of_exponent_ge_of_imp hx0 hx1 hyz fun _ hy ↦ le_antisymm (hyz.trans_eq hy) hz lemma rpow_max {x y p : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) (hp : 0 ≤ p) : (max x y) ^ p = max (x ^ p) (y ^ p) := by rcases le_total x y with hxy | hxy · rw [max_eq_right hxy, max_eq_right (rpow_le_rpow hx hxy hp)] · rw [max_eq_left hxy, max_eq_left (rpow_le_rpow hy hxy hp)] theorem self_le_rpow_of_le_one (h₁ : 0 ≤ x) (h₂ : x ≤ 1) (h₃ : y ≤ 1) : x ≤ x ^ y := by simpa only [rpow_one] using rpow_le_rpow_of_exponent_ge_of_imp h₁ h₂ h₃ fun _ ↦ (absurd · one_ne_zero) theorem self_le_rpow_of_one_le (h₁ : 1 ≤ x) (h₂ : 1 ≤ y) : x ≤ x ^ y := by simpa only [rpow_one] using rpow_le_rpow_of_exponent_le h₁ h₂ theorem rpow_le_self_of_le_one (h₁ : 0 ≤ x) (h₂ : x ≤ 1) (h₃ : 1 ≤ y) : x ^ y ≤ x := by simpa only [rpow_one] using rpow_le_rpow_of_exponent_ge_of_imp h₁ h₂ h₃ fun _ ↦ (absurd · (one_pos.trans_le h₃).ne') theorem rpow_le_self_of_one_le (h₁ : 1 ≤ x) (h₂ : y ≤ 1) : x ^ y ≤ x := by simpa only [rpow_one] using rpow_le_rpow_of_exponent_le h₁ h₂ theorem self_lt_rpow_of_lt_one (h₁ : 0 < x) (h₂ : x < 1) (h₃ : y < 1) : x < x ^ y := by simpa only [rpow_one] using rpow_lt_rpow_of_exponent_gt h₁ h₂ h₃ theorem self_lt_rpow_of_one_lt (h₁ : 1 < x) (h₂ : 1 < y) : x < x ^ y := by simpa only [rpow_one] using rpow_lt_rpow_of_exponent_lt h₁ h₂ theorem rpow_lt_self_of_lt_one (h₁ : 0 < x) (h₂ : x < 1) (h₃ : 1 < y) : x ^ y < x := by simpa only [rpow_one] using rpow_lt_rpow_of_exponent_gt h₁ h₂ h₃ theorem rpow_lt_self_of_one_lt (h₁ : 1 < x) (h₂ : y < 1) : x ^ y < x := by simpa only [rpow_one] using rpow_lt_rpow_of_exponent_lt h₁ h₂ theorem rpow_left_injOn {x : ℝ} (hx : x ≠ 0) : InjOn (fun y : ℝ => y ^ x) { y : ℝ | 0 ≤ y } := by rintro y hy z hz (hyz : y ^ x = z ^ x) rw [← rpow_one y, ← rpow_one z, ← mul_inv_cancel₀ hx, rpow_mul hy, rpow_mul hz, hyz] lemma rpow_left_inj (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : z ≠ 0) : x ^ z = y ^ z ↔ x = y := (rpow_left_injOn hz).eq_iff hx hy lemma rpow_inv_eq (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : z ≠ 0) : x ^ z⁻¹ = y ↔ x = y ^ z := by rw [← rpow_left_inj _ hy hz, rpow_inv_rpow hx hz]; positivity lemma eq_rpow_inv (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : z ≠ 0) : x = y ^ z⁻¹ ↔ x ^ z = y := by rw [← rpow_left_inj hx _ hz, rpow_inv_rpow hy hz]; positivity theorem le_rpow_iff_log_le (hx : 0 < x) (hy : 0 < y) : x ≤ y ^ z ↔ log x ≤ z * log y := by rw [← log_le_log_iff hx (rpow_pos_of_pos hy z), log_rpow hy] lemma le_pow_iff_log_le (hx : 0 < x) (hy : 0 < y) : x ≤ y ^ n ↔ log x ≤ n * log y := rpow_natCast _ _ ▸ le_rpow_iff_log_le hx hy lemma le_zpow_iff_log_le {n : ℤ} (hx : 0 < x) (hy : 0 < y) : x ≤ y ^ n ↔ log x ≤ n * log y := rpow_intCast _ _ ▸ le_rpow_iff_log_le hx hy lemma le_rpow_of_log_le (hy : 0 < y) (h : log x ≤ z * log y) : x ≤ y ^ z := by obtain hx | hx := le_or_lt x 0 · exact hx.trans (rpow_pos_of_pos hy _).le · exact (le_rpow_iff_log_le hx hy).2 h lemma le_pow_of_log_le (hy : 0 < y) (h : log x ≤ n * log y) : x ≤ y ^ n := rpow_natCast _ _ ▸ le_rpow_of_log_le hy h lemma le_zpow_of_log_le {n : ℤ} (hy : 0 < y) (h : log x ≤ n * log y) : x ≤ y ^ n := rpow_intCast _ _ ▸ le_rpow_of_log_le hy h theorem lt_rpow_iff_log_lt (hx : 0 < x) (hy : 0 < y) : x < y ^ z ↔ log x < z * log y := by rw [← log_lt_log_iff hx (rpow_pos_of_pos hy z), log_rpow hy] lemma lt_pow_iff_log_lt (hx : 0 < x) (hy : 0 < y) : x < y ^ n ↔ log x < n * log y := rpow_natCast _ _ ▸ lt_rpow_iff_log_lt hx hy lemma lt_zpow_iff_log_lt {n : ℤ} (hx : 0 < x) (hy : 0 < y) : x < y ^ n ↔ log x < n * log y := rpow_intCast _ _ ▸ lt_rpow_iff_log_lt hx hy lemma lt_rpow_of_log_lt (hy : 0 < y) (h : log x < z * log y) : x < y ^ z := by obtain hx | hx := le_or_lt x 0 · exact hx.trans_lt (rpow_pos_of_pos hy _) · exact (lt_rpow_iff_log_lt hx hy).2 h lemma lt_pow_of_log_lt (hy : 0 < y) (h : log x < n * log y) : x < y ^ n := rpow_natCast _ _ ▸ lt_rpow_of_log_lt hy h lemma lt_zpow_of_log_lt {n : ℤ} (hy : 0 < y) (h : log x < n * log y) : x < y ^ n := rpow_intCast _ _ ▸ lt_rpow_of_log_lt hy h lemma rpow_le_iff_le_log (hx : 0 < x) (hy : 0 < y) : x ^ z ≤ y ↔ z * log x ≤ log y := by rw [← log_le_log_iff (rpow_pos_of_pos hx _) hy, log_rpow hx] lemma pow_le_iff_le_log (hx : 0 < x) (hy : 0 < y) : x ^ n ≤ y ↔ n * log x ≤ log y := by rw [← rpow_le_iff_le_log hx hy, rpow_natCast] lemma zpow_le_iff_le_log {n : ℤ} (hx : 0 < x) (hy : 0 < y) : x ^ n ≤ y ↔ n * log x ≤ log y := by rw [← rpow_le_iff_le_log hx hy, rpow_intCast] lemma le_log_of_rpow_le (hx : 0 < x) (h : x ^ z ≤ y) : z * log x ≤ log y := log_rpow hx _ ▸ log_le_log (by positivity) h lemma le_log_of_pow_le (hx : 0 < x) (h : x ^ n ≤ y) : n * log x ≤ log y := le_log_of_rpow_le hx (rpow_natCast _ _ ▸ h) lemma le_log_of_zpow_le {n : ℤ} (hx : 0 < x) (h : x ^ n ≤ y) : n * log x ≤ log y := le_log_of_rpow_le hx (rpow_intCast _ _ ▸ h) lemma rpow_le_of_le_log (hy : 0 < y) (h : log x ≤ z * log y) : x ≤ y ^ z := by obtain hx | hx := le_or_lt x 0 · exact hx.trans (rpow_pos_of_pos hy _).le · exact (le_rpow_iff_log_le hx hy).2 h lemma pow_le_of_le_log (hy : 0 < y) (h : log x ≤ n * log y) : x ≤ y ^ n := rpow_natCast _ _ ▸ rpow_le_of_le_log hy h lemma zpow_le_of_le_log {n : ℤ} (hy : 0 < y) (h : log x ≤ n * log y) : x ≤ y ^ n := rpow_intCast _ _ ▸ rpow_le_of_le_log hy h lemma rpow_lt_iff_lt_log (hx : 0 < x) (hy : 0 < y) : x ^ z < y ↔ z * log x < log y := by rw [← log_lt_log_iff (rpow_pos_of_pos hx _) hy, log_rpow hx] lemma pow_lt_iff_lt_log (hx : 0 < x) (hy : 0 < y) : x ^ n < y ↔ n * log x < log y := by rw [← rpow_lt_iff_lt_log hx hy, rpow_natCast] lemma zpow_lt_iff_lt_log {n : ℤ} (hx : 0 < x) (hy : 0 < y) : x ^ n < y ↔ n * log x < log y := by rw [← rpow_lt_iff_lt_log hx hy, rpow_intCast] lemma lt_log_of_rpow_lt (hx : 0 < x) (h : x ^ z < y) : z * log x < log y := log_rpow hx _ ▸ log_lt_log (by positivity) h lemma lt_log_of_pow_lt (hx : 0 < x) (h : x ^ n < y) : n * log x < log y := lt_log_of_rpow_lt hx (rpow_natCast _ _ ▸ h) lemma lt_log_of_zpow_lt {n : ℤ} (hx : 0 < x) (h : x ^ n < y) : n * log x < log y := lt_log_of_rpow_lt hx (rpow_intCast _ _ ▸ h) lemma rpow_lt_of_lt_log (hy : 0 < y) (h : log x < z * log y) : x < y ^ z := by obtain hx | hx := le_or_lt x 0 · exact hx.trans_lt (rpow_pos_of_pos hy _) · exact (lt_rpow_iff_log_lt hx hy).2 h lemma pow_lt_of_lt_log (hy : 0 < y) (h : log x < n * log y) : x < y ^ n := rpow_natCast _ _ ▸ rpow_lt_of_lt_log hy h lemma zpow_lt_of_lt_log {n : ℤ} (hy : 0 < y) (h : log x < n * log y) : x < y ^ n := rpow_intCast _ _ ▸ rpow_lt_of_lt_log hy h theorem rpow_le_one_iff_of_pos (hx : 0 < x) : x ^ y ≤ 1 ↔ 1 ≤ x ∧ y ≤ 0 ∨ x ≤ 1 ∧ 0 ≤ y := by rw [rpow_def_of_pos hx, exp_le_one_iff, mul_nonpos_iff, log_nonneg_iff hx, log_nonpos_iff hx.le] /-- Bound for `|log x * x ^ t|` in the interval `(0, 1]`, for positive real `t`. -/ theorem abs_log_mul_self_rpow_lt (x t : ℝ) (h1 : 0 < x) (h2 : x ≤ 1) (ht : 0 < t) : |log x * x ^ t| < 1 / t := by rw [lt_div_iff₀ ht] have := abs_log_mul_self_lt (x ^ t) (rpow_pos_of_pos h1 t) (rpow_le_one h1.le h2 ht.le) rwa [log_rpow h1, mul_assoc, abs_mul, abs_of_pos ht, mul_comm] at this /-- `log x` is bounded above by a multiple of every power of `x` with positive exponent. -/ lemma log_le_rpow_div {x ε : ℝ} (hx : 0 ≤ x) (hε : 0 < ε) : log x ≤ x ^ ε / ε := by rcases hx.eq_or_lt with rfl | h · rw [log_zero, zero_rpow hε.ne', zero_div] rw [le_div_iff₀' hε] exact (log_rpow h ε).symm.trans_le <| (log_le_sub_one_of_pos <| rpow_pos_of_pos h ε).trans (sub_one_lt _).le /-- The (real) logarithm of a natural number `n` is bounded by a multiple of every power of `n` with positive exponent. -/ lemma log_natCast_le_rpow_div (n : ℕ) {ε : ℝ} (hε : 0 < ε) : log n ≤ n ^ ε / ε := log_le_rpow_div n.cast_nonneg hε lemma strictMono_rpow_of_base_gt_one {b : ℝ} (hb : 1 < b) : StrictMono (b ^ · : ℝ → ℝ) := by simp_rw [Real.rpow_def_of_pos (zero_lt_one.trans hb)] exact exp_strictMono.comp <| StrictMono.const_mul strictMono_id <| Real.log_pos hb lemma monotone_rpow_of_base_ge_one {b : ℝ} (hb : 1 ≤ b) : Monotone (b ^ · : ℝ → ℝ) := by rcases lt_or_eq_of_le hb with hb | rfl case inl => exact (strictMono_rpow_of_base_gt_one hb).monotone case inr => intro _ _ _; simp lemma strictAnti_rpow_of_base_lt_one {b : ℝ} (hb₀ : 0 < b) (hb₁ : b < 1) : StrictAnti (b ^ · : ℝ → ℝ) := by simp_rw [Real.rpow_def_of_pos hb₀] exact exp_strictMono.comp_strictAnti <| StrictMono.const_mul_of_neg strictMono_id <| Real.log_neg hb₀ hb₁ lemma antitone_rpow_of_base_le_one {b : ℝ} (hb₀ : 0 < b) (hb₁ : b ≤ 1) :
Antitone (b ^ · : ℝ → ℝ) := by rcases lt_or_eq_of_le hb₁ with hb₁ | rfl case inl => exact (strictAnti_rpow_of_base_lt_one hb₀ hb₁).antitone case inr => intro _ _ _; simp lemma rpow_right_inj (hx₀ : 0 < x) (hx₁ : x ≠ 1) : x ^ y = x ^ z ↔ y = z := by refine ⟨fun H ↦ ?_, fun H ↦ by rw [H]⟩
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
908
914
/- Copyright (c) 2023 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.Algebra.Polynomial.Bivariate import Mathlib.AlgebraicGeometry.EllipticCurve.Weierstrass import Mathlib.AlgebraicGeometry.EllipticCurve.VariableChange /-! # Affine coordinates for Weierstrass curves This file defines the type of points on a Weierstrass curve as an inductive, consisting of the point at infinity and affine points satisfying a Weierstrass equation with a nonsingular condition. This file also defines the negation and addition operations of the group law for this type, and proves that they respect the Weierstrass equation and the nonsingular condition. The fact that they form an abelian group is proven in `Mathlib/AlgebraicGeometry/EllipticCurve/Group.lean`. ## Mathematical background Let `W` be a Weierstrass curve over a field `F` with coefficients `aᵢ`. An *affine point* on `W` is a tuple `(x, y)` of elements in `R` satisfying the *Weierstrass equation* `W(X, Y) = 0` in *affine coordinates*, where `W(X, Y) := Y² + a₁XY + a₃Y - (X³ + a₂X² + a₄X + a₆)`. It is *nonsingular* if its partial derivatives `W_X(x, y)` and `W_Y(x, y)` do not vanish simultaneously. The nonsingular affine points on `W` can be given negation and addition operations defined by a secant-and-tangent process. * Given a nonsingular affine point `P`, its *negation* `-P` is defined to be the unique third nonsingular point of intersection between `W` and the vertical line through `P`. Explicitly, if `P` is `(x, y)`, then `-P` is `(x, -y - a₁x - a₃)`. * Given two nonsingular affine points `P` and `Q`, their *addition* `P + Q` is defined to be the negation of the unique third nonsingular point of intersection between `W` and the line `L` through `P` and `Q`. Explicitly, let `P` be `(x₁, y₁)` and let `Q` be `(x₂, y₂)`. * If `x₁ = x₂` and `y₁ = -y₂ - a₁x₂ - a₃`, then `L` is vertical. * If `x₁ = x₂` and `y₁ ≠ -y₂ - a₁x₂ - a₃`, then `L` is the tangent of `W` at `P = Q`, and has slope `ℓ := (3x₁² + 2a₂x₁ + a₄ - a₁y₁) / (2y₁ + a₁x₁ + a₃)`. * Otherwise `x₁ ≠ x₂`, then `L` is the secant of `W` through `P` and `Q`, and has slope `ℓ := (y₁ - y₂) / (x₁ - x₂)`. In the last two cases, the `X`-coordinate of `P + Q` is then the unique third solution of the equation obtained by substituting the line `Y = ℓ(X - x₁) + y₁` into the Weierstrass equation, and can be written down explicitly as `x := ℓ² + a₁ℓ - a₂ - x₁ - x₂` by inspecting the coefficients of `X²`. The `Y`-coordinate of `P + Q`, after applying the final negation that maps `Y` to `-Y - a₁X - a₃`, is precisely `y := -(ℓ(x - x₁) + y₁) - a₁x - a₃`. The type of nonsingular points `W⟮F⟯` in affine coordinates is an inductive, consisting of the unique point at infinity `𝓞` and nonsingular affine points `(x, y)`. Then `W⟮F⟯` can be endowed with a group law, with `𝓞` as the identity nonsingular point, which is uniquely determined by these formulae. ## Main definitions * `WeierstrassCurve.Affine.Equation`: the Weierstrass equation of an affine Weierstrass curve. * `WeierstrassCurve.Affine.Nonsingular`: the nonsingular condition on an affine Weierstrass curve. * `WeierstrassCurve.Affine.Point`: a nonsingular rational point on an affine Weierstrass curve. * `WeierstrassCurve.Affine.Point.neg`: the negation operation on an affine Weierstrass curve. * `WeierstrassCurve.Affine.Point.add`: the addition operation on an affine Weierstrass curve. ## Main statements * `WeierstrassCurve.Affine.equation_neg`: negation preserves the Weierstrass equation. * `WeierstrassCurve.Affine.equation_add`: addition preserves the Weierstrass equation. * `WeierstrassCurve.Affine.nonsingular_neg`: negation preserves the nonsingular condition. * `WeierstrassCurve.Affine.nonsingular_add`: addition preserves the nonsingular condition. * `WeierstrassCurve.Affine.nonsingular_of_Δ_ne_zero`: an affine Weierstrass curve is nonsingular at every point if its discriminant is non-zero. * `WeierstrassCurve.Affine.nonsingular`: an affine elliptic curve is nonsingular at every point. ## Notations * `W⟮K⟯`: the group of nonsingular rational points on `W` base changed to `K`. ## References [J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009] ## Tags elliptic curve, rational point, affine coordinates -/ open Polynomial open scoped Polynomial.Bivariate local macro "C_simp" : tactic => `(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow]) local macro "derivative_simp" : tactic => `(tactic| simp only [derivative_C, derivative_X, derivative_X_pow, derivative_neg, derivative_add, derivative_sub, derivative_mul, derivative_sq]) local macro "eval_simp" : tactic => `(tactic| simp only [eval_C, eval_X, eval_neg, eval_add, eval_sub, eval_mul, eval_pow, evalEval]) local macro "map_simp" : tactic => `(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow, map_div₀, Polynomial.map_ofNat, map_C, map_X, Polynomial.map_neg, Polynomial.map_add, Polynomial.map_sub, Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_div, coe_mapRingHom, WeierstrassCurve.map]) universe r s u v w /-! ## Weierstrass curves -/ namespace WeierstrassCurve variable {R : Type r} {S : Type s} {A F : Type u} {B K : Type v} {L : Type w} variable (R) in /-- An abbreviation for a Weierstrass curve in affine coordinates. -/ abbrev Affine : Type r := WeierstrassCurve R /-- The conversion from a Weierstrass curve to affine coordinates. -/ abbrev toAffine (W : WeierstrassCurve R) : Affine R := W namespace Affine variable [CommRing R] [CommRing S] [CommRing A] [CommRing B] [Field F] [Field K] [Field L] {W' : Affine R} {W : Affine F} section Equation /-! ### Weierstrass equations -/ variable (W') in /-- The polynomial `W(X, Y) := Y² + a₁XY + a₃Y - (X³ + a₂X² + a₄X + a₆)` associated to a Weierstrass curve `W` over a ring `R` in affine coordinates. For ease of polynomial manipulation, this is represented as a term of type `R[X][X]`, where the inner variable represents `X` and the outer variable represents `Y`. For clarity, the alternative notations `Y` and `R[X][Y]` are provided in the `Polynomial.Bivariate` scope to represent the outer variable and the bivariate polynomial ring `R[X][X]` respectively. -/ noncomputable def polynomial : R[X][Y] := Y ^ 2 + C (C W'.a₁ * X + C W'.a₃) * Y - C (X ^ 3 + C W'.a₂ * X ^ 2 + C W'.a₄ * X + C W'.a₆) lemma polynomial_eq : W'.polynomial = Cubic.toPoly ⟨0, 1, Cubic.toPoly ⟨0, 0, W'.a₁, W'.a₃⟩, Cubic.toPoly ⟨-1, -W'.a₂, -W'.a₄, -W'.a₆⟩⟩ := by simp only [polynomial, Cubic.toPoly] C_simp ring1 lemma polynomial_ne_zero [Nontrivial R] : W'.polynomial ≠ 0 := by rw [polynomial_eq] exact Cubic.ne_zero_of_b_ne_zero one_ne_zero @[simp] lemma degree_polynomial [Nontrivial R] : W'.polynomial.degree = 2 := by rw [polynomial_eq] exact Cubic.degree_of_b_ne_zero' one_ne_zero @[simp] lemma natDegree_polynomial [Nontrivial R] : W'.polynomial.natDegree = 2 := by rw [polynomial_eq] exact Cubic.natDegree_of_b_ne_zero' one_ne_zero lemma monic_polynomial : W'.polynomial.Monic := by nontriviality R simpa only [polynomial_eq] using Cubic.monic_of_b_eq_one' lemma irreducible_polynomial [IsDomain R] : Irreducible W'.polynomial := by by_contra h rcases (monic_polynomial.not_irreducible_iff_exists_add_mul_eq_coeff natDegree_polynomial).mp h with ⟨f, g, h0, h1⟩ simp only [polynomial_eq, Cubic.coeff_eq_c, Cubic.coeff_eq_d] at h0 h1 apply_fun degree at h0 h1 rw [Cubic.degree_of_a_ne_zero' <| neg_ne_zero.mpr <| one_ne_zero' R, degree_mul] at h0 apply (h1.symm.le.trans Cubic.degree_of_b_eq_zero').not_lt rcases Nat.WithBot.add_eq_three_iff.mp h0.symm with h | h | h | h iterate 2 rw [degree_add_eq_right_of_degree_lt] <;> simp only [h] <;> decide iterate 2 rw [degree_add_eq_left_of_degree_lt] <;> simp only [h] <;> decide lemma evalEval_polynomial (x y : R) : W'.polynomial.evalEval x y = y ^ 2 + W'.a₁ * x * y + W'.a₃ * y - (x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆) := by simp only [polynomial] eval_simp rw [add_mul, ← add_assoc] @[simp] lemma evalEval_polynomial_zero : W'.polynomial.evalEval 0 0 = -W'.a₆ := by simp only [evalEval_polynomial, zero_add, zero_sub, mul_zero, zero_pow <| Nat.succ_ne_zero _] variable (W') in /-- The proposition that an affine point `(x, y)` lies in a Weierstrass curve `W`. In other words, it satisfies the Weierstrass equation `W(X, Y) = 0`. -/ def Equation (x y : R) : Prop := W'.polynomial.evalEval x y = 0 lemma equation_iff' (x y : R) : W'.Equation x y ↔ y ^ 2 + W'.a₁ * x * y + W'.a₃ * y - (x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆) = 0 := by rw [Equation, evalEval_polynomial] lemma equation_iff (x y : R) : W'.Equation x y ↔ y ^ 2 + W'.a₁ * x * y + W'.a₃ * y = x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆ := by rw [equation_iff', sub_eq_zero] @[simp] lemma equation_zero : W'.Equation 0 0 ↔ W'.a₆ = 0 := by rw [Equation, evalEval_polynomial_zero, neg_eq_zero] lemma equation_iff_variableChange (x y : R) : W'.Equation x y ↔ (VariableChange.mk 1 x 0 y • W').toAffine.Equation 0 0 := by rw [equation_iff', ← neg_eq_zero, equation_zero, variableChange_a₆, inv_one, Units.val_one] congr! 1 ring1 end Equation section Nonsingular /-! ### Nonsingular Weierstrass equations -/ variable (W') in /-- The partial derivative `W_X(X, Y)` with respect to `X` of the polynomial `W(X, Y)` associated to a Weierstrass curve `W` in affine coordinates. -/ -- TODO: define this in terms of `Polynomial.derivative`. noncomputable def polynomialX : R[X][Y] := C (C W'.a₁) * Y - C (C 3 * X ^ 2 + C (2 * W'.a₂) * X + C W'.a₄) lemma evalEval_polynomialX (x y : R) : W'.polynomialX.evalEval x y = W'.a₁ * y - (3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄) := by simp only [polynomialX] eval_simp @[simp] lemma evalEval_polynomialX_zero : W'.polynomialX.evalEval 0 0 = -W'.a₄ := by simp only [evalEval_polynomialX, zero_add, zero_sub, mul_zero, zero_pow <| Nat.succ_ne_zero _] variable (W') in /-- The partial derivative `W_Y(X, Y)` with respect to `Y` of the polynomial `W(X, Y)` associated to a Weierstrass curve `W` in affine coordinates. -/ -- TODO: define this in terms of `Polynomial.derivative`. noncomputable def polynomialY : R[X][Y] := C (C 2) * Y + C (C W'.a₁ * X + C W'.a₃) lemma evalEval_polynomialY (x y : R) : W'.polynomialY.evalEval x y = 2 * y + W'.a₁ * x + W'.a₃ := by simp only [polynomialY] eval_simp rw [← add_assoc] @[simp] lemma evalEval_polynomialY_zero : W'.polynomialY.evalEval 0 0 = W'.a₃ := by simp only [evalEval_polynomialY, zero_add, mul_zero] variable (W') in /-- The proposition that an affine point `(x, y)` on a Weierstrass curve `W` is nonsingular. In other words, either `W_X(x, y) ≠ 0` or `W_Y(x, y) ≠ 0`. Note that this definition is only mathematically accurate for fields. -/ -- TODO: generalise this definition to be mathematically accurate for a larger class of rings. def Nonsingular (x y : R) : Prop := W'.Equation x y ∧ (W'.polynomialX.evalEval x y ≠ 0 ∨ W'.polynomialY.evalEval x y ≠ 0) lemma nonsingular_iff' (x y : R) : W'.Nonsingular x y ↔ W'.Equation x y ∧ (W'.a₁ * y - (3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄) ≠ 0 ∨ 2 * y + W'.a₁ * x + W'.a₃ ≠ 0) := by rw [Nonsingular, equation_iff', evalEval_polynomialX, evalEval_polynomialY] lemma nonsingular_iff (x y : R) : W'.Nonsingular x y ↔ W'.Equation x y ∧ (W'.a₁ * y ≠ 3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄ ∨ y ≠ -y - W'.a₁ * x - W'.a₃) := by rw [nonsingular_iff', sub_ne_zero, ← sub_ne_zero (a := y)] congr! 3 ring1 @[simp] lemma nonsingular_zero : W'.Nonsingular 0 0 ↔ W'.a₆ = 0 ∧ (W'.a₃ ≠ 0 ∨ W'.a₄ ≠ 0) := by rw [Nonsingular, equation_zero, evalEval_polynomialX_zero, neg_ne_zero, evalEval_polynomialY_zero, or_comm] lemma nonsingular_iff_variableChange (x y : R) : W'.Nonsingular x y ↔ (VariableChange.mk 1 x 0 y • W').toAffine.Nonsingular 0 0 := by rw [nonsingular_iff', equation_iff_variableChange, equation_zero, ← neg_ne_zero, or_comm, nonsingular_zero, variableChange_a₃, variableChange_a₄, inv_one, Units.val_one] simp only [variableChange_def] congr! 3 <;> ring1 private lemma equation_zero_iff_nonsingular_zero_of_Δ_ne_zero (hΔ : W'.Δ ≠ 0) : W'.Equation 0 0 ↔ W'.Nonsingular 0 0 := by simp only [equation_zero, nonsingular_zero, iff_self_and] contrapose! hΔ simp only [b₂, b₄, b₆, b₈, Δ, hΔ] ring1 /-- A Weierstrass curve is nonsingular at every point if its discriminant is non-zero. -/ lemma equation_iff_nonsingular_of_Δ_ne_zero {x y : R} (hΔ : W'.Δ ≠ 0) : W'.Equation x y ↔ W'.Nonsingular x y := by rw [equation_iff_variableChange, nonsingular_iff_variableChange, equation_zero_iff_nonsingular_zero_of_Δ_ne_zero <| by rwa [variableChange_Δ, inv_one, Units.val_one, one_pow, one_mul]] /-- An elliptic curve is nonsingular at every point. -/ lemma equation_iff_nonsingular [Nontrivial R] [W'.IsElliptic] {x y : R} : W'.toAffine.Equation x y ↔ W'.toAffine.Nonsingular x y := W'.toAffine.equation_iff_nonsingular_of_Δ_ne_zero <| W'.coe_Δ' ▸ W'.Δ'.ne_zero @[deprecated (since := "2025-03-01")] alias nonsingular_zero_of_Δ_ne_zero := equation_iff_nonsingular_of_Δ_ne_zero @[deprecated (since := "2025-03-01")] alias nonsingular_of_Δ_ne_zero := equation_iff_nonsingular_of_Δ_ne_zero @[deprecated (since := "2025-03-01")] alias nonsingular := equation_iff_nonsingular end Nonsingular section Ring /-! ### Group operation polynomials over a ring -/ variable (W') in /-- The negation polynomial `-Y - a₁X - a₃` associated to the negation of a nonsingular affine point on a Weierstrass curve. -/ noncomputable def negPolynomial : R[X][Y] := -(Y : R[X][Y]) - C (C W'.a₁ * X + C W'.a₃) lemma Y_sub_polynomialY : Y - W'.polynomialY = W'.negPolynomial := by rw [polynomialY, negPolynomial] C_simp ring1 lemma Y_sub_negPolynomial : Y - W'.negPolynomial = W'.polynomialY := by rw [← Y_sub_polynomialY, sub_sub_cancel] variable (W') in /-- The `Y`-coordinate of `-(x, y)` for a nonsingular affine point `(x, y)` on a Weierstrass curve `W`. This depends on `W`, and has argument order: `x`, `y`. -/ @[simp] def negY (x y : R) : R := -y - W'.a₁ * x - W'.a₃ lemma negY_negY (x y : R) : W'.negY x (W'.negY x y) = y := by simp only [negY] ring1 lemma evalEval_negPolynomial (x y : R) : W'.negPolynomial.evalEval x y = W'.negY x y := by rw [negY, sub_sub, negPolynomial] eval_simp @[deprecated (since := "2025-03-05")] alias eval_negPolynomial := evalEval_negPolynomial /-- The line polynomial `ℓ(X - x) + y` associated to the line `Y = ℓ(X - x) + y` that passes through a nonsingular affine point `(x, y)` on a Weierstrass curve `W` with a slope of `ℓ`. This does not depend on `W`, and has argument order: `x`, `y`, `ℓ`. -/ noncomputable def linePolynomial (x y ℓ : R) : R[X] := C ℓ * (X - C x) + C y variable (W') in /-- The addition polynomial obtained by substituting the line `Y = ℓ(X - x) + y` into the polynomial `W(X, Y)` associated to a Weierstrass curve `W`. If such a line intersects `W` at another nonsingular affine point `(x', y')` on `W`, then the roots of this polynomial are precisely `x`, `x'`, and the `X`-coordinate of the addition of `(x, y)` and `(x', y')`. This depends on `W`, and has argument order: `x`, `y`, `ℓ`. -/ noncomputable def addPolynomial (x y ℓ : R) : R[X] := W'.polynomial.eval <| linePolynomial x y ℓ lemma C_addPolynomial (x y ℓ : R) : C (W'.addPolynomial x y ℓ) = (Y - C (linePolynomial x y ℓ)) * (W'.negPolynomial - C (linePolynomial x y ℓ)) + W'.polynomial := by rw [addPolynomial, linePolynomial, polynomial, negPolynomial] eval_simp C_simp ring1 lemma addPolynomial_eq (x y ℓ : R) : W'.addPolynomial x y ℓ = -Cubic.toPoly ⟨1, -ℓ ^ 2 - W'.a₁ * ℓ + W'.a₂, 2 * x * ℓ ^ 2 + (W'.a₁ * x - 2 * y - W'.a₃) * ℓ + (-W'.a₁ * y + W'.a₄), -x ^ 2 * ℓ ^ 2 + (2 * x * y + W'.a₃ * x) * ℓ - (y ^ 2 + W'.a₃ * y - W'.a₆)⟩ := by rw [addPolynomial, linePolynomial, polynomial, Cubic.toPoly] eval_simp C_simp ring1 variable (W') in /-- The `X`-coordinate of `(x₁, y₁) + (x₂, y₂)` for two nonsingular affine points `(x₁, y₁)` and `(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`. This depends on `W`, and has argument order: `x₁`, `x₂`, `ℓ`. -/ @[simp] def addX (x₁ x₂ ℓ : R) : R := ℓ ^ 2 + W'.a₁ * ℓ - W'.a₂ - x₁ - x₂ variable (W') in /-- The `Y`-coordinate of `-((x₁, y₁) + (x₂, y₂))` for two nonsingular affine points `(x₁, y₁)` and `(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`. This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `ℓ`. -/ @[simp] def negAddY (x₁ x₂ y₁ ℓ : R) : R := ℓ * (W'.addX x₁ x₂ ℓ - x₁) + y₁ variable (W') in /-- The `Y`-coordinate of `(x₁, y₁) + (x₂, y₂)` for two nonsingular affine points `(x₁, y₁)` and `(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`. This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `ℓ`. -/ @[simp] def addY (x₁ x₂ y₁ ℓ : R) : R := W'.negY (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ) lemma equation_neg (x y : R) : W'.Equation x (W'.negY x y) ↔ W'.Equation x y := by rw [equation_iff, equation_iff, negY] congr! 1 ring1 @[deprecated (since := "2025-02-01")] alias equation_neg_of := equation_neg @[deprecated (since := "2025-02-01")] alias equation_neg_iff := equation_neg lemma nonsingular_neg (x y : R) : W'.Nonsingular x (W'.negY x y) ↔ W'.Nonsingular x y := by rw [nonsingular_iff, equation_neg, ← negY, negY_negY, ← @ne_comm _ y, nonsingular_iff] exact and_congr_right' <| (iff_congr not_and_or.symm not_and_or.symm).mpr <| not_congr <| and_congr_left fun h => by rw [← h] @[deprecated (since := "2025-02-01")] alias nonsingular_neg_of := nonsingular_neg @[deprecated (since := "2025-02-01")] alias nonsingular_neg_iff := nonsingular_neg lemma equation_add_iff (x₁ x₂ y₁ ℓ : R) : W'.Equation (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ) ↔ (W'.addPolynomial x₁ y₁ ℓ).eval (W'.addX x₁ x₂ ℓ) = 0 := by rw [Equation, negAddY, addPolynomial, linePolynomial, polynomial] eval_simp lemma nonsingular_negAdd_of_eval_derivative_ne_zero {x₁ x₂ y₁ ℓ : R} (hx' : W'.Equation (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ)) (hx : (W'.addPolynomial x₁ y₁ ℓ).derivative.eval (W'.addX x₁ x₂ ℓ) ≠ 0) : W'.Nonsingular (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ) := by rw [Nonsingular, and_iff_right hx', negAddY, polynomialX, polynomialY] eval_simp contrapose! hx rw [addPolynomial, linePolynomial, polynomial] eval_simp derivative_simp simp only [zero_add, add_zero, sub_zero, zero_mul, mul_one] eval_simp linear_combination (norm := (norm_num1; ring1)) hx.left + ℓ * hx.right end Ring section Field /-! ### Group operation polynomials over a field -/ open Classical in variable (W) in /-- The slope of the line through two nonsingular affine points `(x₁, y₁)` and `(x₂, y₂)` on a Weierstrass curve `W`. If `x₁ ≠ x₂`, then this line is the secant of `W` through `(x₁, y₁)` and `(x₂, y₂)`, and has slope `(y₁ - y₂) / (x₁ - x₂)`. Otherwise, if `y₁ ≠ -y₁ - a₁x₁ - a₃`, then this line is the tangent of `W` at `(x₁, y₁) = (x₂, y₂)`, and has slope `(3x₁² + 2a₂x₁ + a₄ - a₁y₁) / (2y₁ + a₁x₁ + a₃)`. Otherwise, this line is vertical, in which case this returns the value `0`. This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `y₂`. -/ noncomputable def slope (x₁ x₂ y₁ y₂ : F) : F := if x₁ = x₂ then if y₁ = W.negY x₂ y₂ then 0 else (3 * x₁ ^ 2 + 2 * W.a₂ * x₁ + W.a₄ - W.a₁ * y₁) / (y₁ - W.negY x₁ y₁) else (y₁ - y₂) / (x₁ - x₂) @[simp] lemma slope_of_Y_eq {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ = W.negY x₂ y₂) : W.slope x₁ x₂ y₁ y₂ = 0 := by rw [slope, if_pos hx, if_pos hy] @[simp] lemma slope_of_Y_ne {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) : W.slope x₁ x₂ y₁ y₂ = (3 * x₁ ^ 2 + 2 * W.a₂ * x₁ + W.a₄ - W.a₁ * y₁) / (y₁ - W.negY x₁ y₁) := by rw [slope, if_pos hx, if_neg hy] @[simp] lemma slope_of_X_ne {x₁ x₂ y₁ y₂ : F} (hx : x₁ ≠ x₂) : W.slope x₁ x₂ y₁ y₂ = (y₁ - y₂) / (x₁ - x₂) := by rw [slope, if_neg hx] lemma slope_of_Y_ne_eq_evalEval {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) : W.slope x₁ x₂ y₁ y₂ = -W.polynomialX.evalEval x₁ y₁ / W.polynomialY.evalEval x₁ y₁ := by rw [slope_of_Y_ne hx hy, evalEval_polynomialX, neg_sub] congr 1 rw [negY, evalEval_polynomialY] ring1 @[deprecated (since := "2025-03-05")] alias slope_of_Y_ne_eq_eval := slope_of_Y_ne_eq_evalEval lemma Y_eq_of_X_eq {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hx : x₁ = x₂) : y₁ = y₂ ∨ y₁ = W.negY x₂ y₂ := by rw [equation_iff] at h₁ h₂ rw [← sub_eq_zero, ← sub_eq_zero (a := y₁), ← mul_eq_zero, negY] linear_combination (norm := (rw [hx]; ring1)) h₁ - h₂ lemma Y_eq_of_Y_ne {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) : y₁ = y₂ := (Y_eq_of_X_eq h₁ h₂ hx).resolve_right hy lemma addPolynomial_slope {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.addPolynomial x₁ y₁ (W.slope x₁ x₂ y₁ y₂) = -((X - C x₁) * (X - C x₂) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by rw [addPolynomial_eq, neg_inj, Cubic.prod_X_sub_C_eq, Cubic.toPoly_injective] by_cases hx : x₁ = x₂ · have hy : y₁ ≠ W.negY x₂ y₂ := fun h => hxy ⟨hx, h⟩ rcases hx, Y_eq_of_Y_ne h₁ h₂ hx hy with ⟨rfl, rfl⟩ rw [equation_iff] at h₁ h₂ rw [slope_of_Y_ne rfl hy] rw [negY, ← sub_ne_zero] at hy ext · rfl · simp only [addX] ring1 · field_simp [hy] ring1 · linear_combination (norm := (field_simp [hy]; ring1)) -h₁ · rw [equation_iff] at h₁ h₂ rw [slope_of_X_ne hx] rw [← sub_eq_zero] at hx ext · rfl · simp only [addX] ring1 · apply mul_right_injective₀ hx linear_combination (norm := (field_simp [hx]; ring1)) h₂ - h₁ · apply mul_right_injective₀ hx linear_combination (norm := (field_simp [hx]; ring1)) x₂ * h₁ - x₁ * h₂ /-- The negated addition of two affine points in `W` on a sloped line lies in `W`. -/ lemma equation_negAdd {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.Equation (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.negAddY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := by rw [equation_add_iff, addPolynomial_slope h₁ h₂ hxy] eval_simp rw [neg_eq_zero, sub_self, mul_zero] /-- The addition of two affine points in `W` on a sloped line lies in `W`. -/ lemma equation_add {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.Equation (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.addY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := (equation_neg ..).mpr <| equation_negAdd h₁ h₂ hxy lemma C_addPolynomial_slope {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : C (W.addPolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) = -(C (X - C x₁) * C (X - C x₂) * C (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by rw [addPolynomial_slope h₁ h₂ hxy] map_simp lemma derivative_addPolynomial_slope {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : derivative (W.addPolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) = -((X - C x₁) * (X - C x₂) + (X - C x₁) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂)) + (X - C x₂) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by rw [addPolynomial_slope h₁ h₂ hxy] derivative_simp ring1 /-- The negated addition of two nonsingular affine points in `W` on a sloped line is nonsingular. -/ lemma nonsingular_negAdd {x₁ x₂ y₁ y₂ : F} (h₁ : W.Nonsingular x₁ y₁) (h₂ : W.Nonsingular x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.Nonsingular (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.negAddY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := by by_cases hx₁ : W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = x₁ · rwa [negAddY, hx₁, sub_self, mul_zero, zero_add] · by_cases hx₂ : W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = x₂ · by_cases hx : x₁ = x₂ · subst hx contradiction · rwa [negAddY, ← neg_sub, mul_neg, hx₂, slope_of_X_ne hx, div_mul_cancel₀ _ <| sub_ne_zero_of_ne hx, neg_sub, sub_add_cancel] · apply nonsingular_negAdd_of_eval_derivative_ne_zero <| equation_negAdd h₁.left h₂.left hxy rw [derivative_addPolynomial_slope h₁.left h₂.left hxy] eval_simp simp only [neg_ne_zero, sub_self, mul_zero, add_zero] exact mul_ne_zero (sub_ne_zero_of_ne hx₁) (sub_ne_zero_of_ne hx₂) /-- The addition of two nonsingular affine points in `W` on a sloped line is nonsingular. -/ lemma nonsingular_add {x₁ x₂ y₁ y₂ : F} (h₁ : W.Nonsingular x₁ y₁) (h₂ : W.Nonsingular x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.Nonsingular (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.addY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := (nonsingular_neg ..).mpr <| nonsingular_negAdd h₁ h₂ hxy /-- The formula `x(P₁ + P₂) = x(P₁ - P₂) - ψ(P₁)ψ(P₂) / (x(P₂) - x(P₁))²`, where `ψ(x,y) = 2y + a₁x + a₃`. -/ lemma addX_eq_addX_negY_sub {x₁ x₂ : F} (y₁ y₂ : F) (hx : x₁ ≠ x₂) : W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = W.addX x₁ x₂ (W.slope x₁ x₂ y₁ <| W.negY x₂ y₂) - (y₁ - W.negY x₁ y₁) * (y₂ - W.negY x₂ y₂) / (x₂ - x₁) ^ 2 := by simp_rw [slope_of_X_ne hx, addX, negY, ← neg_sub x₁, neg_sq] field_simp [sub_ne_zero.mpr hx] ring1 /-- The formula `y(P₁)(x(P₂) - x(P₃)) + y(P₂)(x(P₃) - x(P₁)) + y(P₃)(x(P₁) - x(P₂)) = 0`, assuming that `P₁ + P₂ + P₃ = O`. -/ lemma cyclic_sum_Y_mul_X_sub_X {x₁ x₂ : F} (y₁ y₂ : F) (hx : x₁ ≠ x₂) : let x₃ := W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) y₁ * (x₂ - x₃) + y₂ * (x₃ - x₁) + W.negAddY x₁ x₂ y₁ (W.slope x₁ x₂ y₁ y₂) * (x₁ - x₂) = 0 := by simp_rw [slope_of_X_ne hx, negAddY, addX] field_simp [sub_ne_zero.mpr hx] ring1 /-- The formula `ψ(P₁ + P₂) = (ψ(P₂)(x(P₁) - x(P₃)) - ψ(P₁)(x(P₂) - x(P₃))) / (x(P₂) - x(P₁))`, where `ψ(x,y) = 2y + a₁x + a₃`. -/ lemma addY_sub_negY_addY {x₁ x₂ : F} (y₁ y₂ : F) (hx : x₁ ≠ x₂) : let x₃ := W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) let y₃ := W.addY x₁ x₂ y₁ (W.slope x₁ x₂ y₁ y₂) y₃ - W.negY x₃ y₃ = ((y₂ - W.negY x₂ y₂) * (x₁ - x₃) - (y₁ - W.negY x₁ y₁) * (x₂ - x₃)) / (x₂ - x₁) := by simp_rw [addY, negY, eq_div_iff (sub_ne_zero.mpr hx.symm)] linear_combination (norm := ring1) 2 * cyclic_sum_Y_mul_X_sub_X y₁ y₂ hx end Field section Group /-! ### Nonsingular points -/ variable (W') in /-- A nonsingular point on a Weierstrass curve `W` in affine coordinates. This is either the unique point at infinity `WeierstrassCurve.Affine.Point.zero` or a nonsingular affine point `WeierstrassCurve.Affine.Point.some (x, y)` satisfying the Weierstrass equation of `W`. -/ inductive Point | zero | some {x y : R} (h : W'.Nonsingular x y) /-- For an algebraic extension `S` of a ring `R`, the type of nonsingular `S`-points on a Weierstrass curve `W` over `R` in affine coordinates. -/ scoped notation3:max W' "⟮" S "⟯" => Affine.Point <| baseChange W' S namespace Point /-! ### Group operations -/ instance : Inhabited W'.Point := ⟨.zero⟩ instance : Zero W'.Point := ⟨.zero⟩ lemma zero_def : 0 = (.zero : W'.Point) := rfl lemma some_ne_zero {x y : R} (h : W'.Nonsingular x y) : Point.some h ≠ 0 := by rintro (_ | _) /-- The negation of a nonsingular point on a Weierstrass curve in affine coordinates. Given a nonsingular point `P` in affine coordinates, use `-P` instead of `neg P`. -/ def neg : W'.Point → W'.Point | 0 => 0 | some h => some <| (nonsingular_neg ..).mpr h instance : Neg W'.Point := ⟨neg⟩ lemma neg_def (P : W'.Point) : -P = P.neg := rfl @[simp] lemma neg_zero : (-0 : W'.Point) = 0 := rfl @[simp] lemma neg_some {x y : R} (h : W'.Nonsingular x y) : -some h = some ((nonsingular_neg ..).mpr h) := rfl instance : InvolutiveNeg W'.Point where neg_neg := by rintro (_ | _) · rfl · simp only [neg_some, negY_negY] open Classical in /-- The addition of two nonsingular points on a Weierstrass curve in affine coordinates. Given two nonsingular points `P` and `Q` in affine coordinates, use `P + Q` instead of `add P Q`. -/ noncomputable def add : W.Point → W.Point → W.Point | 0, P => P | P, 0 => P | @some _ _ _ x₁ y₁ h₁, @some _ _ _ x₂ y₂ h₂ => if hxy : x₁ = x₂ ∧ y₁ = W.negY x₂ y₂ then 0 else some <| nonsingular_add h₁ h₂ hxy noncomputable instance : Add W.Point := ⟨add⟩ noncomputable instance : AddZeroClass W.Point := ⟨by rintro (_ | _) <;> rfl, by rintro (_ | _) <;> rfl⟩ lemma add_def (P Q : W.Point) : P + Q = P.add Q := rfl lemma add_some {x₁ x₂ y₁ y₂ : F} (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂} : some h₁ + some h₂ = some (nonsingular_add h₁ h₂ hxy) := by simp only [add_def, add, dif_neg hxy] @[deprecated (since := "2025-02-28")] alias add_of_imp := add_some @[simp] lemma add_of_Y_eq {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂} (hx : x₁ = x₂) (hy : y₁ = W.negY x₂ y₂) : some h₁ + some h₂ = 0 := by simpa only [add_def, add] using dif_pos ⟨hx, hy⟩ @[simp] lemma add_self_of_Y_eq {x₁ y₁ : F} {h₁ : W.Nonsingular x₁ y₁} (hy : y₁ = W.negY x₁ y₁) : some h₁ + some h₁ = 0 := add_of_Y_eq rfl hy @[simp] lemma add_of_Y_ne {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂} (hy : y₁ ≠ W.negY x₂ y₂) : some h₁ + some h₂ = some (nonsingular_add h₁ h₂ fun hxy => hy hxy.right) := add_some fun hxy => hy hxy.right lemma add_of_Y_ne' {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂} (hy : y₁ ≠ W.negY x₂ y₂) : some h₁ + some h₂ = -some (nonsingular_negAdd h₁ h₂ fun hxy => hy hxy.right) := add_of_Y_ne hy @[simp] lemma add_self_of_Y_ne {x₁ y₁ : F} {h₁ : W.Nonsingular x₁ y₁} (hy : y₁ ≠ W.negY x₁ y₁) : some h₁ + some h₁ = some (nonsingular_add h₁ h₁ fun hxy => hy hxy.right) := add_of_Y_ne hy lemma add_self_of_Y_ne' {x₁ y₁ : F} {h₁ : W.Nonsingular x₁ y₁} (hy : y₁ ≠ W.negY x₁ y₁) : some h₁ + some h₁ = -some (nonsingular_negAdd h₁ h₁ fun hxy => hy hxy.right) := add_of_Y_ne hy @[simp] lemma add_of_X_ne {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂} (hx : x₁ ≠ x₂) : some h₁ + some h₂ = some (nonsingular_add h₁ h₂ fun hxy => hx hxy.left) := add_some fun hxy => hx hxy.left lemma add_of_X_ne' {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂} (hx : x₁ ≠ x₂) : some h₁ + some h₂ = -some (nonsingular_negAdd h₁ h₂ fun hxy => hx hxy.left) := add_of_X_ne hx end Point end Group section Map /-! ### Maps across ring homomorphisms -/ variable (f : R →+* S) (x y x₁ y₁ x₂ y₂ ℓ : R) lemma map_polynomial : (W'.map f).toAffine.polynomial = W'.polynomial.map (mapRingHom f) := by simp only [polynomial] map_simp lemma evalEval_baseChange_polynomial : (W'.baseChange R[X][Y]).toAffine.polynomial.evalEval (C X) Y = W'.polynomial := by rw [map_polynomial, evalEval, eval_map, eval_C_X_eval₂_map_C_X] @[deprecated (since := "2025-03-05")] alias evalEval_baseChange_polynomial_X_Y := evalEval_baseChange_polynomial variable {x y} in lemma Equation.map {x y : R} (h : W'.Equation x y) : (W'.map f).toAffine.Equation (f x) (f y) := by rw [Equation, map_polynomial, map_mapRingHom_evalEval, h, map_zero] variable {f} in lemma map_equation (hf : Function.Injective f) : (W'.map f).toAffine.Equation (f x) (f y) ↔ W'.Equation x y := by simp only [Equation, map_polynomial, map_mapRingHom_evalEval, map_eq_zero_iff f hf] lemma map_polynomialX : (W'.map f).toAffine.polynomialX = W'.polynomialX.map (mapRingHom f) := by simp only [polynomialX] map_simp lemma map_polynomialY : (W'.map f).toAffine.polynomialY = W'.polynomialY.map (mapRingHom f) := by simp only [polynomialY] map_simp variable {f} in lemma map_nonsingular (hf : Function.Injective f) : (W'.map f).toAffine.Nonsingular (f x) (f y) ↔ W'.Nonsingular x y := by simp only [Nonsingular, evalEval, map_equation _ _ hf, map_polynomialX, map_polynomialY, map_mapRingHom_evalEval, map_ne_zero_iff f hf] lemma map_negPolynomial : (W'.map f).toAffine.negPolynomial = W'.negPolynomial.map (mapRingHom f) := by simp only [negPolynomial] map_simp lemma map_negY : (W'.map f).toAffine.negY (f x) (f y) = f (W'.negY x y) := by simp only [negY] map_simp lemma map_linePolynomial : linePolynomial (f x) (f y) (f ℓ) = (linePolynomial x y ℓ).map f := by simp only [linePolynomial] map_simp lemma map_addPolynomial : (W'.map f).toAffine.addPolynomial (f x) (f y) (f ℓ) = (W'.addPolynomial x y ℓ).map f := by rw [addPolynomial, map_polynomial, eval_map, linePolynomial, addPolynomial, ← coe_mapRingHom, ← eval₂_hom, linePolynomial] map_simp lemma map_addX : (W'.map f).toAffine.addX (f x₁) (f x₂) (f ℓ) = f (W'.addX x₁ x₂ ℓ) := by simp only [addX] map_simp lemma map_negAddY : (W'.map f).toAffine.negAddY (f x₁) (f x₂) (f y₁) (f ℓ) = f (W'.negAddY x₁ x₂ y₁ ℓ) := by simp only [negAddY, map_addX] map_simp lemma map_addY : (W'.map f).toAffine.addY (f x₁) (f x₂) (f y₁) (f ℓ) = f (W'.toAffine.addY x₁ x₂ y₁ ℓ) := by simp only [addY, map_negAddY, map_addX, map_negY] lemma map_slope (f : F →+* K) (x₁ x₂ y₁ y₂ : F) : (W.map f).toAffine.slope (f x₁) (f x₂) (f y₁) (f y₂) = f (W.slope x₁ x₂ y₁ y₂) := by by_cases hx : x₁ = x₂ · by_cases hy : y₁ = W.negY x₂ y₂ · rw [slope_of_Y_eq (congr_arg f hx) <| by rw [hy, map_negY], slope_of_Y_eq hx hy, map_zero] · rw [slope_of_Y_ne (congr_arg f hx) <| map_negY f x₂ y₂ ▸ fun h => hy <| f.injective h, map_negY, slope_of_Y_ne hx hy] map_simp · rw [slope_of_X_ne fun h => hx <| f.injective h, slope_of_X_ne hx] map_simp end Map section BaseChange /-! ### Base changes across algebra homomorphisms -/ variable [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] [Algebra R B] [Algebra S B] [IsScalarTower R S B] (f : A →ₐ[S] B) (x y x₁ y₁ x₂ y₂ ℓ : A) lemma baseChange_polynomial : (W'.baseChange B).toAffine.polynomial = (W'.baseChange A).toAffine.polynomial.map (mapRingHom f) := by rw [← map_polynomial, map_baseChange] variable {x y} in lemma Equation.baseChange (h : (W'.baseChange A).toAffine.Equation x y) : (W'.baseChange B).toAffine.Equation (f x) (f y) := by convert Equation.map f.toRingHom h using 1 rw [AlgHom.toRingHom_eq_coe, map_baseChange] variable {f} in lemma baseChange_equation (hf : Function.Injective f) : (W'.baseChange B).toAffine.Equation (f x) (f y) ↔ (W'.baseChange A).toAffine.Equation x y := by rw [← map_equation _ _ hf, AlgHom.toRingHom_eq_coe, map_baseChange, RingHom.coe_coe] lemma baseChange_polynomialX : (W'.baseChange B).toAffine.polynomialX = (W'.baseChange A).toAffine.polynomialX.map (mapRingHom f) := by rw [← map_polynomialX, map_baseChange] lemma baseChange_polynomialY : (W'.baseChange B).toAffine.polynomialY = (W'.baseChange A).toAffine.polynomialY.map (mapRingHom f) := by rw [← map_polynomialY, map_baseChange] variable {f} in lemma baseChange_nonsingular (hf : Function.Injective f) : (W'.baseChange B).toAffine.Nonsingular (f x) (f y) ↔ (W'.baseChange A).toAffine.Nonsingular x y := by rw [← map_nonsingular _ _ hf, AlgHom.toRingHom_eq_coe, map_baseChange, RingHom.coe_coe] lemma baseChange_negPolynomial : (W'.baseChange B).toAffine.negPolynomial = (W'.baseChange A).toAffine.negPolynomial.map (mapRingHom f) := by rw [← map_negPolynomial, map_baseChange] lemma baseChange_negY : (W'.baseChange B).toAffine.negY (f x) (f y) = f ((W'.baseChange A).toAffine.negY x y) := by rw [← RingHom.coe_coe, ← map_negY, map_baseChange] lemma baseChange_addPolynomial : (W'.baseChange B).toAffine.addPolynomial (f x) (f y) (f ℓ) = ((W'.baseChange A).toAffine.addPolynomial x y ℓ).map f := by rw [← RingHom.coe_coe, ← map_addPolynomial, map_baseChange] lemma baseChange_addX : (W'.baseChange B).toAffine.addX (f x₁) (f x₂) (f ℓ) = f ((W'.baseChange A).toAffine.addX x₁ x₂ ℓ) := by rw [← RingHom.coe_coe, ← map_addX, map_baseChange] lemma baseChange_negAddY : (W'.baseChange B).toAffine.negAddY (f x₁) (f x₂) (f y₁) (f ℓ) = f ((W'.baseChange A).toAffine.negAddY x₁ x₂ y₁ ℓ) := by rw [← RingHom.coe_coe, ← map_negAddY, map_baseChange] lemma baseChange_addY : (W'.baseChange B).toAffine.addY (f x₁) (f x₂) (f y₁) (f ℓ) = f ((W'.baseChange A).toAffine.addY x₁ x₂ y₁ ℓ) := by rw [← RingHom.coe_coe, ← map_addY, map_baseChange] lemma baseChange_slope [Algebra R F] [Algebra S F] [IsScalarTower R S F] [Algebra R K] [Algebra S K] [IsScalarTower R S K] (f : F →ₐ[S] K) (x₁ x₂ y₁ y₂ : F) : (W'.baseChange K).toAffine.slope (f x₁) (f x₂) (f y₁) (f y₂) = f ((W'.baseChange F).toAffine.slope x₁ x₂ y₁ y₂) := by rw [← RingHom.coe_coe, ← map_slope, map_baseChange] end BaseChange namespace Point variable [Algebra R S] [Algebra R F] [Algebra S F] [IsScalarTower R S F] [Algebra R K] [Algebra S K] [IsScalarTower R S K] [Algebra R L] [Algebra S L] [IsScalarTower R S L] (f : F →ₐ[S] K) (g : K →ₐ[S] L) /-- The group homomorphism from `W⟮F⟯` to `W⟮K⟯` induced by an algebra homomorphism `f : F →ₐ[S] K`, where `W` is defined over a subring of a ring `S`, and `F` and `K` are field extensions of `S`. -/ def map : W'⟮F⟯ →+ W'⟮K⟯ where toFun P := match P with | 0 => 0 | some h => some <| (baseChange_nonsingular _ _ f.injective).mpr h map_zero' := rfl map_add' := by rintro (_ | @⟨x₁, y₁, _⟩) (_ | @⟨x₂, y₂, _⟩) any_goals rfl by_cases hxy : x₁ = x₂ ∧ y₁ = (W'.baseChange F).toAffine.negY x₂ y₂ · simp only [add_of_Y_eq hxy.left hxy.right] rw [add_of_Y_eq (congr_arg _ hxy.left) <| by rw [hxy.right, baseChange_negY]] · simp only [add_some hxy, ← baseChange_addX, ← baseChange_addY, ← baseChange_slope] rw [add_some fun h => hxy ⟨f.injective h.1, f.injective (W'.baseChange_negY f .. ▸ h).2⟩] @[deprecated (since := "2025-03-01")] alias mapFun := map lemma map_zero : map f (0 : W'⟮F⟯) = 0 := rfl lemma map_some {x y : F} (h : (W'.baseChange F).toAffine.Nonsingular x y) : map f (some h) = some ((W'.baseChange_nonsingular _ _ f.injective).mpr h) := rfl lemma map_id (P : W'⟮F⟯) : map (Algebra.ofId F F) P = P := by cases P <;> rfl lemma map_map (P : W'⟮F⟯) : map g (map f P) = map (g.comp f) P := by cases P <;> rfl lemma map_injective : Function.Injective <| map (W' := W') f := by rintro (_ | _) (_ | _) h any_goals contradiction · rfl · simpa only [some.injEq] using ⟨f.injective (some.inj h).left, f.injective (some.inj h).right⟩ variable (F K) in /-- The group homomorphism from `W⟮F⟯` to `W⟮K⟯` induced by the base change from `F` to `K`, where `W` is defined over a subring of a ring `S`, and `F` and `K` are field extensions of `S`. -/ abbrev baseChange [Algebra F K] [IsScalarTower R F K] : W'⟮F⟯ →+ W'⟮K⟯ := map <| Algebra.ofId F K lemma map_baseChange [Algebra F K] [IsScalarTower R F K] [Algebra F L] [IsScalarTower R F L] (f : K →ₐ[F] L) (P : W'⟮F⟯) : map f (baseChange F K P) = baseChange F L P := by have : Subsingleton (F →ₐ[F] L) := inferInstance convert map_map (Algebra.ofId F K) f P end Point end Affine end WeierstrassCurve
Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean
1,066
1,069
/- 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.IsPrimePow import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Ring.Int import Mathlib.Algebra.Ring.CharZero import Mathlib.Data.Nat.Cast.Order.Ring import Mathlib.Data.Nat.PrimeFin import Mathlib.Order.Interval.Finset.Nat /-! # Divisor Finsets This file defines sets of divisors of a natural number. This is particularly useful as background for defining Dirichlet convolution. ## Main Definitions Let `n : ℕ`. All of the following definitions are in the `Nat` namespace: * `divisors n` is the `Finset` of natural numbers that divide `n`. * `properDivisors n` is the `Finset` of natural numbers that divide `n`, other than `n`. * `divisorsAntidiagonal n` is the `Finset` of pairs `(x,y)` such that `x * y = n`. * `Perfect n` is true when `n` is positive and the sum of `properDivisors n` is `n`. ## Conventions Since `0` has infinitely many divisors, none of the definitions in this file make sense for it. Therefore we adopt the convention that `Nat.divisors 0`, `Nat.properDivisors 0`, `Nat.divisorsAntidiagonal 0` and `Int.divisorsAntidiag 0` are all `∅`. ## Tags divisors, perfect numbers -/ open Finset namespace Nat variable (n : ℕ) /-- `divisors n` is the `Finset` of divisors of `n`. By convention, we set `divisors 0 = ∅`. -/ def divisors : Finset ℕ := {d ∈ Ico 1 (n + 1) | d ∣ n} /-- `properDivisors n` is the `Finset` of divisors of `n`, other than `n`. By convention, we set `properDivisors 0 = ∅`. -/ def properDivisors : Finset ℕ := {d ∈ Ico 1 n | d ∣ n} /-- Pairs of divisors of a natural number as a finset. `n.divisorsAntidiagonal` is the finset of pairs `(a, b) : ℕ × ℕ` such that `a * b = n`. By convention, we set `Nat.divisorsAntidiagonal 0 = ∅`. O(n). -/ def divisorsAntidiagonal : Finset (ℕ × ℕ) := (Icc 1 n).filterMap (fun x ↦ let y := n / x; if x * y = n then some (x, y) else none) fun x₁ x₂ (x, y) hx₁ hx₂ ↦ by aesop /-- Pairs of divisors of a natural number, as a list. `n.divisorsAntidiagonalList` is the list of pairs `(a, b) : ℕ × ℕ` such that `a * b = n`, ordered by increasing `a`. By convention, we set `Nat.divisorsAntidiagonalList 0 = []`. -/ def divisorsAntidiagonalList (n : ℕ) : List (ℕ × ℕ) := (List.range' 1 n).filterMap (fun x ↦ let y := n / x; if x * y = n then some (x, y) else none) variable {n} @[simp] theorem filter_dvd_eq_divisors (h : n ≠ 0) : {d ∈ range n.succ | d ∣ n} = n.divisors := by ext simp only [divisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self] exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt) @[simp] theorem filter_dvd_eq_properDivisors (h : n ≠ 0) : {d ∈ range n | d ∣ n} = n.properDivisors := by ext simp only [properDivisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self] exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt) theorem properDivisors.not_self_mem : ¬n ∈ properDivisors n := by simp [properDivisors] @[simp] theorem mem_properDivisors {m : ℕ} : n ∈ properDivisors m ↔ n ∣ m ∧ n < m := by rcases eq_or_ne m 0 with (rfl | hm); · simp [properDivisors] simp only [and_comm, ← filter_dvd_eq_properDivisors hm, mem_filter, mem_range] theorem insert_self_properDivisors (h : n ≠ 0) : insert n (properDivisors n) = divisors n := by rw [divisors, properDivisors, Ico_succ_right_eq_insert_Ico (one_le_iff_ne_zero.2 h), Finset.filter_insert, if_pos (dvd_refl n)] theorem cons_self_properDivisors (h : n ≠ 0) : cons n (properDivisors n) properDivisors.not_self_mem = divisors n := by rw [cons_eq_insert, insert_self_properDivisors h] @[simp] theorem mem_divisors {m : ℕ} : n ∈ divisors m ↔ n ∣ m ∧ m ≠ 0 := by rcases eq_or_ne m 0 with (rfl | hm); · simp [divisors] simp only [hm, Ne, not_false_iff, and_true, ← filter_dvd_eq_divisors hm, mem_filter, mem_range, and_iff_right_iff_imp, Nat.lt_succ_iff] exact le_of_dvd hm.bot_lt theorem one_mem_divisors : 1 ∈ divisors n ↔ n ≠ 0 := by simp theorem mem_divisors_self (n : ℕ) (h : n ≠ 0) : n ∈ n.divisors := mem_divisors.2 ⟨dvd_rfl, h⟩ theorem dvd_of_mem_divisors {m : ℕ} (h : n ∈ divisors m) : n ∣ m := by cases m · apply dvd_zero · simp [mem_divisors.1 h] @[simp] theorem mem_divisorsAntidiagonal {x : ℕ × ℕ} : x ∈ divisorsAntidiagonal n ↔ x.fst * x.snd = n ∧ n ≠ 0 := by obtain ⟨a, b⟩ := x simp only [divisorsAntidiagonal, mul_div_eq_iff_dvd, mem_filterMap, mem_Icc, one_le_iff_ne_zero, Option.ite_none_right_eq_some, Option.some.injEq, Prod.ext_iff, and_left_comm, exists_eq_left] constructor · rintro ⟨han, ⟨ha, han'⟩, rfl⟩ simp [Nat.mul_div_eq_iff_dvd, han] omega · rintro ⟨rfl, hab⟩ rw [mul_ne_zero_iff] at hab simpa [hab.1, hab.2] using Nat.le_mul_of_pos_right _ hab.2.bot_lt @[simp] lemma divisorsAntidiagonalList_zero : divisorsAntidiagonalList 0 = [] := rfl @[simp] lemma divisorsAntidiagonalList_one : divisorsAntidiagonalList 1 = [(1, 1)] := rfl @[simp] lemma toFinset_divisorsAntidiagonalList {n : ℕ} : n.divisorsAntidiagonalList.toFinset = n.divisorsAntidiagonal := by rw [divisorsAntidiagonalList, divisorsAntidiagonal, List.toFinset_filterMap (f_inj := by aesop), List.toFinset_range'_1_1] lemma sorted_divisorsAntidiagonalList_fst {n : ℕ} : n.divisorsAntidiagonalList.Sorted (·.fst < ·.fst) := by refine (List.sorted_lt_range' _ _ Nat.one_ne_zero).filterMap fun a b c d h h' ha => ?_ rw [Option.ite_none_right_eq_some, Option.some.injEq] at h h' simpa [← h.right, ← h'.right] lemma sorted_divisorsAntidiagonalList_snd {n : ℕ} : n.divisorsAntidiagonalList.Sorted (·.snd > ·.snd) := by obtain rfl | hn := eq_or_ne n 0 · simp refine (List.sorted_lt_range' _ _ Nat.one_ne_zero).filterMap ?_ simp only [Option.ite_none_right_eq_some, Option.some.injEq, gt_iff_lt, and_imp, Prod.forall, Prod.mk.injEq] rintro a b _ _ _ _ ha rfl rfl hb rfl rfl hab rwa [Nat.div_lt_div_left hn ⟨_, hb.symm⟩ ⟨_, ha.symm⟩] lemma nodup_divisorsAntidiagonalList {n : ℕ} : n.divisorsAntidiagonalList.Nodup := have : IsIrrefl (ℕ × ℕ) (·.fst < ·.fst) := ⟨by simp⟩ sorted_divisorsAntidiagonalList_fst.nodup /-- The `Finset` and `List` versions agree by definition. -/ @[simp] theorem val_divisorsAntidiagonal (n : ℕ) : (divisorsAntidiagonal n).val = divisorsAntidiagonalList n := rfl @[simp] lemma mem_divisorsAntidiagonalList {n : ℕ} {a : ℕ × ℕ} : a ∈ n.divisorsAntidiagonalList ↔ a.1 * a.2 = n ∧ n ≠ 0 := by rw [← List.mem_toFinset, toFinset_divisorsAntidiagonalList, mem_divisorsAntidiagonal] @[simp high] lemma swap_mem_divisorsAntidiagonalList {a : ℕ × ℕ} : a.swap ∈ n.divisorsAntidiagonalList ↔ a ∈ n.divisorsAntidiagonalList := by simp [mul_comm] lemma reverse_divisorsAntidiagonalList (n : ℕ) : n.divisorsAntidiagonalList.reverse = n.divisorsAntidiagonalList.map .swap := by have : IsAsymm (ℕ × ℕ) (·.snd < ·.snd) := ⟨fun _ _ ↦ lt_asymm⟩ refine List.eq_of_perm_of_sorted ?_ sorted_divisorsAntidiagonalList_snd.reverse <| sorted_divisorsAntidiagonalList_fst.map _ fun _ _ ↦ id simp [List.reverse_perm', List.perm_ext_iff_of_nodup nodup_divisorsAntidiagonalList (nodup_divisorsAntidiagonalList.map Prod.swap_injective), mul_comm] lemma ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) : p.1 ≠ 0 ∧ p.2 ≠ 0 := by obtain ⟨hp₁, hp₂⟩ := Nat.mem_divisorsAntidiagonal.mp hp exact mul_ne_zero_iff.mp (hp₁.symm ▸ hp₂) lemma left_ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) : p.1 ≠ 0 := (ne_zero_of_mem_divisorsAntidiagonal hp).1 lemma right_ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) : p.2 ≠ 0 := (ne_zero_of_mem_divisorsAntidiagonal hp).2 theorem divisor_le {m : ℕ} : n ∈ divisors m → n ≤ m := by rcases m with - | m · simp · simp only [mem_divisors, Nat.succ_ne_zero m, and_true, Ne, not_false_iff] exact Nat.le_of_dvd (Nat.succ_pos m) theorem divisors_subset_of_dvd {m : ℕ} (hzero : n ≠ 0) (h : m ∣ n) : divisors m ⊆ divisors n := Finset.subset_iff.2 fun _x hx => Nat.mem_divisors.mpr ⟨(Nat.mem_divisors.mp hx).1.trans h, hzero⟩ theorem card_divisors_le_self (n : ℕ) : #n.divisors ≤ n := calc _ ≤ #(Ico 1 (n + 1)) := by apply card_le_card simp only [divisors, filter_subset] _ = n := by rw [card_Ico, add_tsub_cancel_right] theorem divisors_subset_properDivisors {m : ℕ} (hzero : n ≠ 0) (h : m ∣ n) (hdiff : m ≠ n) : divisors m ⊆ properDivisors n := by apply Finset.subset_iff.2 intro x hx exact Nat.mem_properDivisors.2 ⟨(Nat.mem_divisors.1 hx).1.trans h, lt_of_le_of_lt (divisor_le hx) (lt_of_le_of_ne (divisor_le (Nat.mem_divisors.2 ⟨h, hzero⟩)) hdiff)⟩ lemma divisors_filter_dvd_of_dvd {n m : ℕ} (hn : n ≠ 0) (hm : m ∣ n) : {d ∈ n.divisors | d ∣ m} = m.divisors := by ext k simp_rw [mem_filter, mem_divisors] exact ⟨fun ⟨_, hkm⟩ ↦ ⟨hkm, ne_zero_of_dvd_ne_zero hn hm⟩, fun ⟨hk, _⟩ ↦ ⟨⟨hk.trans hm, hn⟩, hk⟩⟩ @[simp] theorem divisors_zero : divisors 0 = ∅ := by ext simp @[simp] theorem properDivisors_zero : properDivisors 0 = ∅ := by ext simp @[simp] lemma nonempty_divisors : (divisors n).Nonempty ↔ n ≠ 0 := ⟨fun ⟨m, hm⟩ hn ↦ by simp [hn] at hm, fun hn ↦ ⟨1, one_mem_divisors.2 hn⟩⟩ @[simp] lemma divisors_eq_empty : divisors n = ∅ ↔ n = 0 := not_nonempty_iff_eq_empty.symm.trans nonempty_divisors.not_left theorem properDivisors_subset_divisors : properDivisors n ⊆ divisors n := filter_subset_filter _ <| Ico_subset_Ico_right n.le_succ @[simp] theorem divisors_one : divisors 1 = {1} := by ext simp @[simp] theorem properDivisors_one : properDivisors 1 = ∅ := by rw [properDivisors, Ico_self, filter_empty] theorem pos_of_mem_divisors {m : ℕ} (h : m ∈ n.divisors) : 0 < m := by cases m · rw [mem_divisors, zero_dvd_iff (a := n)] at h cases h.2 h.1 apply Nat.succ_pos theorem pos_of_mem_properDivisors {m : ℕ} (h : m ∈ n.properDivisors) : 0 < m := pos_of_mem_divisors (properDivisors_subset_divisors h) theorem one_mem_properDivisors_iff_one_lt : 1 ∈ n.properDivisors ↔ 1 < n := by rw [mem_properDivisors, and_iff_right (one_dvd _)] @[simp] lemma sup_divisors_id (n : ℕ) : n.divisors.sup id = n := by refine le_antisymm (Finset.sup_le fun _ ↦ divisor_le) ?_ rcases Decidable.eq_or_ne n 0 with rfl | hn · apply zero_le · exact Finset.le_sup (f := id) <| mem_divisors_self n hn lemma one_lt_of_mem_properDivisors {m n : ℕ} (h : m ∈ n.properDivisors) : 1 < n := lt_of_le_of_lt (pos_of_mem_properDivisors h) (mem_properDivisors.1 h).2 lemma one_lt_div_of_mem_properDivisors {m n : ℕ} (h : m ∈ n.properDivisors) : 1 < n / m := by obtain ⟨h_dvd, h_lt⟩ := mem_properDivisors.mp h rwa [Nat.lt_div_iff_mul_lt' h_dvd, mul_one] /-- See also `Nat.mem_properDivisors`. -/ lemma mem_properDivisors_iff_exists {m n : ℕ} (hn : n ≠ 0) : m ∈ n.properDivisors ↔ ∃ k > 1, n = m * k := by refine ⟨fun h ↦ ⟨n / m, one_lt_div_of_mem_properDivisors h, ?_⟩, ?_⟩ · exact (Nat.mul_div_cancel' (mem_properDivisors.mp h).1).symm · rintro ⟨k, hk, rfl⟩ rw [mul_ne_zero_iff] at hn exact mem_properDivisors.mpr ⟨⟨k, rfl⟩, lt_mul_of_one_lt_right (Nat.pos_of_ne_zero hn.1) hk⟩ @[simp] lemma nonempty_properDivisors : n.properDivisors.Nonempty ↔ 1 < n := ⟨fun ⟨_m, hm⟩ ↦ one_lt_of_mem_properDivisors hm, fun hn ↦ ⟨1, one_mem_properDivisors_iff_one_lt.2 hn⟩⟩ @[simp] lemma properDivisors_eq_empty : n.properDivisors = ∅ ↔ n ≤ 1 := by rw [← not_nonempty_iff_eq_empty, nonempty_properDivisors, not_lt] @[simp] theorem divisorsAntidiagonal_zero : divisorsAntidiagonal 0 = ∅ := by ext simp @[simp] theorem divisorsAntidiagonal_one : divisorsAntidiagonal 1 = {(1, 1)} := by ext simp [mul_eq_one, Prod.ext_iff] @[simp high] theorem swap_mem_divisorsAntidiagonal {x : ℕ × ℕ} : x.swap ∈ divisorsAntidiagonal n ↔ x ∈ divisorsAntidiagonal n := by rw [mem_divisorsAntidiagonal, mem_divisorsAntidiagonal, mul_comm, Prod.swap] /-- `Nat.swap_mem_divisorsAntidiagonal` with the LHS in simp normal form. -/ @[deprecated swap_mem_divisorsAntidiagonal (since := "2025-02-17")] theorem swap_mem_divisorsAntidiagonal_aux {x : ℕ × ℕ} : x.snd * x.fst = n ∧ ¬n = 0 ↔ x ∈ divisorsAntidiagonal n := by rw [mem_divisorsAntidiagonal, mul_comm] lemma prodMk_mem_divisorsAntidiag {x y : ℕ} (hn : n ≠ 0) : (x, y) ∈ n.divisorsAntidiagonal ↔ x * y = n := by simp [hn] theorem fst_mem_divisors_of_mem_antidiagonal {x : ℕ × ℕ} (h : x ∈ divisorsAntidiagonal n) : x.fst ∈ divisors n := by rw [mem_divisorsAntidiagonal] at h simp [Dvd.intro _ h.1, h.2] theorem snd_mem_divisors_of_mem_antidiagonal {x : ℕ × ℕ} (h : x ∈ divisorsAntidiagonal n) : x.snd ∈ divisors n := by rw [mem_divisorsAntidiagonal] at h simp [Dvd.intro_left _ h.1, h.2] @[simp] theorem map_swap_divisorsAntidiagonal : (divisorsAntidiagonal n).map (Equiv.prodComm _ _).toEmbedding = divisorsAntidiagonal n := by rw [← coe_inj, coe_map, Equiv.coe_toEmbedding, Equiv.coe_prodComm, Set.image_swap_eq_preimage_swap] ext exact swap_mem_divisorsAntidiagonal @[simp] theorem image_fst_divisorsAntidiagonal : (divisorsAntidiagonal n).image Prod.fst = divisors n := by ext simp [Dvd.dvd, @eq_comm _ n (_ * _)] @[simp] theorem image_snd_divisorsAntidiagonal : (divisorsAntidiagonal n).image Prod.snd = divisors n := by rw [← map_swap_divisorsAntidiagonal, map_eq_image, image_image] exact image_fst_divisorsAntidiagonal theorem map_div_right_divisors : n.divisors.map ⟨fun d => (d, n / d), fun _ _ => congr_arg Prod.fst⟩ = n.divisorsAntidiagonal := by ext ⟨d, nd⟩ simp only [mem_map, mem_divisorsAntidiagonal, Function.Embedding.coeFn_mk, mem_divisors, Prod.ext_iff, exists_prop, and_left_comm, exists_eq_left] constructor · rintro ⟨⟨⟨k, rfl⟩, hn⟩, rfl⟩ rw [Nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt] exact ⟨rfl, hn⟩ · rintro ⟨rfl, hn⟩ exact ⟨⟨dvd_mul_right _ _, hn⟩, Nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt⟩ theorem map_div_left_divisors : n.divisors.map ⟨fun d => (n / d, d), fun _ _ => congr_arg Prod.snd⟩ = n.divisorsAntidiagonal := by apply Finset.map_injective (Equiv.prodComm _ _).toEmbedding ext rw [map_swap_divisorsAntidiagonal, ← map_div_right_divisors, Finset.map_map] simp theorem sum_divisors_eq_sum_properDivisors_add_self : ∑ i ∈ divisors n, i = (∑ i ∈ properDivisors n, i) + n := by rcases Decidable.eq_or_ne n 0 with (rfl | hn) · simp · rw [← cons_self_properDivisors hn, Finset.sum_cons, add_comm] /-- `n : ℕ` is perfect if and only the sum of the proper divisors of `n` is `n` and `n` is positive. -/ def Perfect (n : ℕ) : Prop := ∑ i ∈ properDivisors n, i = n ∧ 0 < n theorem perfect_iff_sum_properDivisors (h : 0 < n) : Perfect n ↔ ∑ i ∈ properDivisors n, i = n := and_iff_left h theorem perfect_iff_sum_divisors_eq_two_mul (h : 0 < n) : Perfect n ↔ ∑ i ∈ divisors n, i = 2 * n := by rw [perfect_iff_sum_properDivisors h, sum_divisors_eq_sum_properDivisors_add_self, two_mul] constructor <;> intro h · rw [h] · apply add_right_cancel h theorem mem_divisors_prime_pow {p : ℕ} (pp : p.Prime) (k : ℕ) {x : ℕ} : x ∈ divisors (p ^ k) ↔ ∃ j ≤ k, x = p ^ j := by rw [mem_divisors, Nat.dvd_prime_pow pp, and_iff_left (ne_of_gt (pow_pos pp.pos k))] theorem Prime.divisors {p : ℕ} (pp : p.Prime) : divisors p = {1, p} := by ext rw [mem_divisors, dvd_prime pp, and_iff_left pp.ne_zero, Finset.mem_insert, Finset.mem_singleton] theorem Prime.properDivisors {p : ℕ} (pp : p.Prime) : properDivisors p = {1} := by rw [← erase_insert properDivisors.not_self_mem, insert_self_properDivisors pp.ne_zero, pp.divisors, pair_comm, erase_insert fun con => pp.ne_one (mem_singleton.1 con)] theorem divisors_prime_pow {p : ℕ} (pp : p.Prime) (k : ℕ) : divisors (p ^ k) = (Finset.range (k + 1)).map ⟨(p ^ ·), Nat.pow_right_injective pp.two_le⟩ := by ext a rw [mem_divisors_prime_pow pp] simp [Nat.lt_succ, eq_comm] theorem divisors_injective : Function.Injective divisors := Function.LeftInverse.injective sup_divisors_id @[simp] theorem divisors_inj {a b : ℕ} : a.divisors = b.divisors ↔ a = b := divisors_injective.eq_iff theorem eq_properDivisors_of_subset_of_sum_eq_sum {s : Finset ℕ} (hsub : s ⊆ n.properDivisors) : ((∑ x ∈ s, x) = ∑ x ∈ n.properDivisors, x) → s = n.properDivisors := by cases n · rw [properDivisors_zero, subset_empty] at hsub simp [hsub] classical rw [← sum_sdiff hsub] intro h apply Subset.antisymm hsub rw [← sdiff_eq_empty_iff_subset] contrapose h rw [← Ne, ← nonempty_iff_ne_empty] at h apply ne_of_lt rw [← zero_add (∑ x ∈ s, x), ← add_assoc, add_zero] apply add_lt_add_right
have hlt := sum_lt_sum_of_nonempty h fun x hx => pos_of_mem_properDivisors (sdiff_subset hx)
Mathlib/NumberTheory/Divisors.lean
434
435
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Eric Wieser -/ import Mathlib.Algebra.DirectSum.Internal import Mathlib.Algebra.GradedMonoid import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.Algebra.MvPolynomial.Variables import Mathlib.Algebra.Polynomial.Roots import Mathlib.RingTheory.MvPolynomial.WeightedHomogeneous import Mathlib.SetTheory.Cardinal.Basic /-! # Homogeneous polynomials A multivariate polynomial `φ` is homogeneous of degree `n` if all monomials occurring in `φ` have degree `n`. ## Main definitions/lemmas * `IsHomogeneous φ n`: a predicate that asserts that `φ` is homogeneous of degree `n`. * `homogeneousSubmodule σ R n`: the submodule of homogeneous polynomials of degree `n`. * `homogeneousComponent n`: the additive morphism that projects polynomials onto their summand that is homogeneous of degree `n`. * `sum_homogeneousComponent`: every polynomial is the sum of its homogeneous components. -/ namespace MvPolynomial variable {σ : Type*} {τ : Type*} {R : Type*} {S : Type*} /- TODO * show that `MvPolynomial σ R ≃ₐ[R] ⨁ i, homogeneousSubmodule σ R i` -/ open Finsupp /-- A multivariate polynomial `φ` is homogeneous of degree `n` if all monomials occurring in `φ` have degree `n`. -/ def IsHomogeneous [CommSemiring R] (φ : MvPolynomial σ R) (n : ℕ) := IsWeightedHomogeneous 1 φ n variable [CommSemiring R] theorem weightedTotalDegree_one (φ : MvPolynomial σ R) : weightedTotalDegree (1 : σ → ℕ) φ = φ.totalDegree := by simp only [totalDegree, weightedTotalDegree, weight, LinearMap.toAddMonoidHom_coe, linearCombination, Pi.one_apply, Finsupp.coe_lsum, LinearMap.coe_smulRight, LinearMap.id_coe, id, Algebra.id.smul_eq_mul, mul_one] theorem weightedTotalDegree_rename_of_injective {σ τ : Type*} {e : σ → τ} {w : τ → ℕ} {P : MvPolynomial σ R} (he : Function.Injective e) : weightedTotalDegree w (rename e P) = weightedTotalDegree (w ∘ e) P := by classical unfold weightedTotalDegree rw [support_rename_of_injective he, Finset.sup_image] congr; ext; unfold weight; simp variable (σ R) /-- The submodule of homogeneous `MvPolynomial`s of degree `n`. -/ def homogeneousSubmodule (n : ℕ) : Submodule R (MvPolynomial σ R) where carrier := { x | x.IsHomogeneous n } smul_mem' r a ha c hc := by rw [coeff_smul] at hc apply ha intro h apply hc rw [h] exact smul_zero r zero_mem' _ hd := False.elim (hd <| coeff_zero _) add_mem' {a b} ha hb c hc := by rw [coeff_add] at hc obtain h | h : coeff c a ≠ 0 ∨ coeff c b ≠ 0 := by contrapose! hc simp only [hc, add_zero] · exact ha h · exact hb h @[simp] lemma weightedHomogeneousSubmodule_one (n : ℕ) : weightedHomogeneousSubmodule R 1 n = homogeneousSubmodule σ R n := rfl variable {σ R} @[simp] theorem mem_homogeneousSubmodule (n : ℕ) (p : MvPolynomial σ R) : p ∈ homogeneousSubmodule σ R n ↔ p.IsHomogeneous n := Iff.rfl variable (σ R) /-- While equal, the former has a convenient definitional reduction. -/ theorem homogeneousSubmodule_eq_finsupp_supported (n : ℕ) : homogeneousSubmodule σ R n = Finsupp.supported _ R { d | d.degree = n } := by simp_rw [degree_eq_weight_one] exact weightedHomogeneousSubmodule_eq_finsupp_supported R 1 n variable {σ R} theorem homogeneousSubmodule_mul (m n : ℕ) : homogeneousSubmodule σ R m * homogeneousSubmodule σ R n ≤ homogeneousSubmodule σ R (m + n) := weightedHomogeneousSubmodule_mul 1 m n section theorem isHomogeneous_monomial {d : σ →₀ ℕ} (r : R) {n : ℕ} (hn : d.degree = n) : IsHomogeneous (monomial d r) n := by rw [degree_eq_weight_one] at hn exact isWeightedHomogeneous_monomial 1 d r hn variable (σ) theorem totalDegree_eq_zero_iff (p : MvPolynomial σ R) : p.totalDegree = 0 ↔ ∀ (m : σ →₀ ℕ) (_ : m ∈ p.support) (x : σ), m x = 0 := by rw [← weightedTotalDegree_one, weightedTotalDegree_eq_zero_iff _ p] exact nonTorsionWeight_of (Function.const σ one_ne_zero) theorem totalDegree_zero_iff_isHomogeneous {p : MvPolynomial σ R} : p.totalDegree = 0 ↔ IsHomogeneous p 0 := by rw [← weightedTotalDegree_one, ← isWeightedHomogeneous_zero_iff_weightedTotalDegree_eq_zero, IsHomogeneous] alias ⟨isHomogeneous_of_totalDegree_zero, _⟩ := totalDegree_zero_iff_isHomogeneous theorem isHomogeneous_C (r : R) : IsHomogeneous (C r : MvPolynomial σ R) 0 := by apply isHomogeneous_monomial simp only [Finsupp.degree, Finsupp.zero_apply, Finset.sum_const_zero] variable (R) theorem isHomogeneous_zero (n : ℕ) : IsHomogeneous (0 : MvPolynomial σ R) n := (homogeneousSubmodule σ R n).zero_mem theorem isHomogeneous_one : IsHomogeneous (1 : MvPolynomial σ R) 0 := isHomogeneous_C _ _ variable {σ} theorem isHomogeneous_X (i : σ) : IsHomogeneous (X i : MvPolynomial σ R) 1 := by apply isHomogeneous_monomial rw [Finsupp.degree, Finsupp.support_single_ne_zero _ one_ne_zero, Finset.sum_singleton] exact Finsupp.single_eq_same end namespace IsHomogeneous variable [CommSemiring S] {φ ψ : MvPolynomial σ R} {m n : ℕ} theorem coeff_eq_zero (hφ : IsHomogeneous φ n) {d : σ →₀ ℕ} (hd : d.degree ≠ n) : coeff d φ = 0 := by rw [degree_eq_weight_one] at hd exact IsWeightedHomogeneous.coeff_eq_zero hφ d hd theorem inj_right (hm : IsHomogeneous φ m) (hn : IsHomogeneous φ n) (hφ : φ ≠ 0) : m = n := by obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero hφ rw [← hm hd, ← hn hd] theorem add (hφ : IsHomogeneous φ n) (hψ : IsHomogeneous ψ n) : IsHomogeneous (φ + ψ) n := (homogeneousSubmodule σ R n).add_mem hφ hψ theorem sum {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : ℕ) (h : ∀ i ∈ s, IsHomogeneous (φ i) n) : IsHomogeneous (∑ i ∈ s, φ i) n := (homogeneousSubmodule σ R n).sum_mem h theorem mul (hφ : IsHomogeneous φ m) (hψ : IsHomogeneous ψ n) : IsHomogeneous (φ * ψ) (m + n) := homogeneousSubmodule_mul m n <| Submodule.mul_mem_mul hφ hψ theorem prod {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : ι → ℕ) (h : ∀ i ∈ s, IsHomogeneous (φ i) (n i)) : IsHomogeneous (∏ i ∈ s, φ i) (∑ i ∈ s, n i) := by classical revert h refine Finset.induction_on s ?_ ?_ · intro simp only [isHomogeneous_one, Finset.sum_empty, Finset.prod_empty] · intro i s his IH h simp only [his, Finset.prod_insert, Finset.sum_insert, not_false_iff] apply (h i (Finset.mem_insert_self _ _)).mul (IH _) intro j hjs exact h j (Finset.mem_insert_of_mem hjs) lemma C_mul (hφ : φ.IsHomogeneous m) (r : R) : (C r * φ).IsHomogeneous m := by simpa only [zero_add] using (isHomogeneous_C _ _).mul hφ lemma _root_.MvPolynomial.isHomogeneous_C_mul_X (r : R) (i : σ) : (C r * X i).IsHomogeneous 1 := (isHomogeneous_X _ _).C_mul _ lemma pow (hφ : φ.IsHomogeneous m) (n : ℕ) : (φ ^ n).IsHomogeneous (m * n) := by rw [show φ ^ n = ∏ _i ∈ Finset.range n, φ by simp] rw [show m * n = ∑ _i ∈ Finset.range n, m by simp [mul_comm]] apply IsHomogeneous.prod _ _ _ (fun _ _ ↦ hφ) lemma _root_.MvPolynomial.isHomogeneous_X_pow (i : σ) (n : ℕ) : (X (R := R) i ^ n).IsHomogeneous n := by simpa only [one_mul] using (isHomogeneous_X _ _).pow n lemma _root_.MvPolynomial.isHomogeneous_C_mul_X_pow (r : R) (i : σ) (n : ℕ) : (C r * X i ^ n).IsHomogeneous n := (isHomogeneous_X_pow _ _).C_mul _ lemma eval₂ (hφ : φ.IsHomogeneous m) (f : R →+* MvPolynomial τ S) (g : σ → MvPolynomial τ S) (hf : ∀ r, (f r).IsHomogeneous 0) (hg : ∀ i, (g i).IsHomogeneous n) : (eval₂ f g φ).IsHomogeneous (n * m) := by apply IsHomogeneous.sum intro i hi rw [← zero_add (n * m)] apply IsHomogeneous.mul (hf _) _ convert IsHomogeneous.prod _ _ (fun k ↦ n * i k) _ · rw [Finsupp.mem_support_iff] at hi rw [← Finset.mul_sum, ← hφ hi, weight_apply] simp_rw [smul_eq_mul, Finsupp.sum, Pi.one_apply, mul_one] · rintro k - apply (hg k).pow lemma map (hφ : φ.IsHomogeneous n) (f : R →+* S) : (map f φ).IsHomogeneous n := by simpa only [one_mul] using hφ.eval₂ _ _ (fun r ↦ isHomogeneous_C _ (f r)) (isHomogeneous_X _) lemma aeval [Algebra R S] (hφ : φ.IsHomogeneous m) (g : σ → MvPolynomial τ S) (hg : ∀ i, (g i).IsHomogeneous n) : (aeval g φ).IsHomogeneous (n * m) := hφ.eval₂ _ _ (fun _ ↦ isHomogeneous_C _ _) hg section CommRing -- In this section we shadow the semiring `R` with a ring `R`. variable {R σ : Type*} [CommRing R] {φ ψ : MvPolynomial σ R} {n : ℕ} theorem neg (hφ : IsHomogeneous φ n) : IsHomogeneous (-φ) n := (homogeneousSubmodule σ R n).neg_mem hφ theorem sub (hφ : IsHomogeneous φ n) (hψ : IsHomogeneous ψ n) : IsHomogeneous (φ - ψ) n := (homogeneousSubmodule σ R n).sub_mem hφ hψ end CommRing /-- The homogeneous degree bounds the total degree. See also `MvPolynomial.IsHomogeneous.totalDegree` when `φ` is non-zero. -/ lemma totalDegree_le (hφ : IsHomogeneous φ n) : φ.totalDegree ≤ n := by apply Finset.sup_le intro d hd rw [mem_support_iff] at hd simp_rw [Finsupp.sum, ← hφ hd, weight_apply, Pi.one_apply, smul_eq_mul, mul_one, Finsupp.sum, le_rfl] theorem totalDegree (hφ : IsHomogeneous φ n) (h : φ ≠ 0) : totalDegree φ = n := by apply le_antisymm hφ.totalDegree_le obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero h simp only [← hφ hd, MvPolynomial.totalDegree, Finsupp.sum] replace hd := Finsupp.mem_support_iff.mpr hd simp only [weight_apply, Pi.one_apply, smul_eq_mul, mul_one] -- Porting note: Original proof did not define `f`
exact Finset.le_sup (f := fun s ↦ ∑ x ∈ s.support, s x) hd theorem rename_isHomogeneous {f : σ → τ} (h : φ.IsHomogeneous n) : (rename f φ).IsHomogeneous n := by rw [← φ.support_sum_monomial_coeff, map_sum]; simp_rw [rename_monomial] apply IsHomogeneous.sum _ _ _ fun d hd ↦ isHomogeneous_monomial _ _ intro d hd apply (Finsupp.sum_mapDomain_index_addMonoidHom fun _ ↦ .id ℕ).trans convert h (mem_support_iff.mp hd) simp only [weight_apply, AddMonoidHom.id_apply, Pi.one_apply, smul_eq_mul, mul_one]
Mathlib/RingTheory/MvPolynomial/Homogeneous.lean
260
269
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Topology.UniformSpace.UniformConvergenceTopology /-! # Equicontinuity of a family of functions Let `X` be a topological space and `α` a `UniformSpace`. A family of functions `F : ι → X → α` is said to be *equicontinuous at a point `x₀ : X`* when, for any entourage `U` in `α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V`, and *for all `i`*, `F i x` is `U`-close to `F i x₀`. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x, ∀ i, dist x₀ x < δ → dist (F i x₀) (F i x) < ε`. `F` is said to be *equicontinuous* if it is equicontinuous at each point. A closely related concept is that of ***uniform*** *equicontinuity* of a family of functions `F : ι → β → α` between uniform spaces, which means that, for any entourage `U` in `α`, there is an entourage `V` in `β` such that, if `x` and `y` are `V`-close, then *for all `i`*, `F i x` and `F i y` are `U`-close. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ xy in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x y, ∀ i, dist x y < δ → dist (F i x₀) (F i x) < ε`. ## Main definitions * `EquicontinuousAt`: equicontinuity of a family of functions at a point * `Equicontinuous`: equicontinuity of a family of functions on the whole domain * `UniformEquicontinuous`: uniform equicontinuity of a family of functions on the whole domain We also introduce relative versions, namely `EquicontinuousWithinAt`, `EquicontinuousOn` and `UniformEquicontinuousOn`, akin to `ContinuousWithinAt`, `ContinuousOn` and `UniformContinuousOn` respectively. ## Main statements * `equicontinuous_iff_continuous`: equicontinuity can be expressed as a simple continuity condition between well-chosen function spaces. This is really useful for building up the theory. * `Equicontinuous.closure`: if a set of functions is equicontinuous, its closure *for the topology of pointwise convergence* is also equicontinuous. ## Notations Throughout this file, we use : - `ι`, `κ` for indexing types - `X`, `Y`, `Z` for topological spaces - `α`, `β`, `γ` for uniform spaces ## Implementation details We choose to express equicontinuity as a properties of indexed families of functions rather than sets of functions for the following reasons: - it is really easy to express equicontinuity of `H : Set (X → α)` using our setup: it is just equicontinuity of the family `(↑) : ↥H → (X → α)`. On the other hand, going the other way around would require working with the range of the family, which is always annoying because it introduces useless existentials. - in most applications, one doesn't work with bare functions but with a more specific hom type `hom`. Equicontinuity of a set `H : Set hom` would then have to be expressed as equicontinuity of `coe_fn '' H`, which is super annoying to work with. This is much simpler with families, because equicontinuity of a family `𝓕 : ι → hom` would simply be expressed as equicontinuity of `coe_fn ∘ 𝓕`, which doesn't introduce any nasty existentials. To simplify statements, we do provide abbreviations `Set.EquicontinuousAt`, `Set.Equicontinuous` and `Set.UniformEquicontinuous` asserting the corresponding fact about the family `(↑) : ↥H → (X → α)` where `H : Set (X → α)`. Note however that these won't work for sets of hom types, and in that case one should go back to the family definition rather than using `Set.image`. ## References * [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966] ## Tags equicontinuity, uniform convergence, ascoli -/ section open UniformSpace Filter Set Uniformity Topology UniformConvergence Function variable {ι κ X X' Y α α' β β' γ : Type*} [tX : TopologicalSpace X] [tY : TopologicalSpace Y] [uα : UniformSpace α] [uβ : UniformSpace β] [uγ : UniformSpace γ] /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousAt (F : ι → X → α) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point. -/ protected abbrev Set.EquicontinuousAt (H : Set <| X → α) (x₀ : X) : Prop := EquicontinuousAt ((↑) : H → X → α) x₀ /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X` within `S : Set X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` within `S` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousWithinAt (F : ι → X → α) (S : Set X) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝[S] x₀, ∀ i, (F i x₀, F i x) ∈ U /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point within a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point within that same subset. -/ protected abbrev Set.EquicontinuousWithinAt (H : Set <| X → α) (S : Set X) (x₀ : X) : Prop := EquicontinuousWithinAt ((↑) : H → X → α) S x₀ /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous* on all of `X` if it is equicontinuous at each point of `X`. -/ def Equicontinuous (F : ι → X → α) : Prop := ∀ x₀, EquicontinuousAt F x₀ /-- We say that a set `H : Set (X → α)` of functions is equicontinuous if the family `(↑) : ↥H → (X → α)` is equicontinuous. -/ protected abbrev Set.Equicontinuous (H : Set <| X → α) : Prop := Equicontinuous ((↑) : H → X → α) /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous on `S : Set X`* if it is equicontinuous *within `S`* at each point of `S`. -/ def EquicontinuousOn (F : ι → X → α) (S : Set X) : Prop := ∀ x₀ ∈ S, EquicontinuousWithinAt F S x₀ /-- We say that a set `H : Set (X → α)` of functions is equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous on that subset. -/ protected abbrev Set.EquicontinuousOn (H : Set <| X → α) (S : Set X) : Prop := EquicontinuousOn ((↑) : H → X → α) S /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous* if, for all entourages `U ∈ 𝓤 α`, there is an entourage `V ∈ 𝓤 β` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuous (F : ι → β → α) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous. -/ protected abbrev Set.UniformEquicontinuous (H : Set <| β → α) : Prop := UniformEquicontinuous ((↑) : H → β → α) /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous on `S : Set β`* if, for all entourages `U ∈ 𝓤 α`, there is a relative entourage `V ∈ 𝓤 β ⊓ 𝓟 (S ×ˢ S)` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuousOn (F : ι → β → α) (S : Set β) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β ⊓ 𝓟 (S ×ˢ S), ∀ i, (F i xy.1, F i xy.2) ∈ U /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous on that subset. -/ protected abbrev Set.UniformEquicontinuousOn (H : Set <| β → α) (S : Set β) : Prop := UniformEquicontinuousOn ((↑) : H → β → α) S lemma EquicontinuousAt.equicontinuousWithinAt {F : ι → X → α} {x₀ : X} (H : EquicontinuousAt F x₀) (S : Set X) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma EquicontinuousWithinAt.mono {F : ι → X → α} {x₀ : X} {S T : Set X} (H : EquicontinuousWithinAt F T x₀) (hST : S ⊆ T) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono <| nhdsWithin_mono x₀ hST @[simp] lemma equicontinuousWithinAt_univ (F : ι → X → α) (x₀ : X) : EquicontinuousWithinAt F univ x₀ ↔ EquicontinuousAt F x₀ := by rw [EquicontinuousWithinAt, EquicontinuousAt, nhdsWithin_univ] lemma equicontinuousAt_restrict_iff (F : ι → X → α) {S : Set X} (x₀ : S) : EquicontinuousAt (S.restrict ∘ F) x₀ ↔ EquicontinuousWithinAt F S x₀ := by simp [EquicontinuousWithinAt, EquicontinuousAt, ← eventually_nhds_subtype_iff] lemma Equicontinuous.equicontinuousOn {F : ι → X → α} (H : Equicontinuous F) (S : Set X) : EquicontinuousOn F S := fun x _ ↦ (H x).equicontinuousWithinAt S lemma EquicontinuousOn.mono {F : ι → X → α} {S T : Set X} (H : EquicontinuousOn F T) (hST : S ⊆ T) : EquicontinuousOn F S := fun x hx ↦ (H x (hST hx)).mono hST lemma equicontinuousOn_univ (F : ι → X → α) : EquicontinuousOn F univ ↔ Equicontinuous F := by simp [EquicontinuousOn, Equicontinuous] lemma equicontinuous_restrict_iff (F : ι → X → α) {S : Set X} : Equicontinuous (S.restrict ∘ F) ↔ EquicontinuousOn F S := by simp [Equicontinuous, EquicontinuousOn, equicontinuousAt_restrict_iff] lemma UniformEquicontinuous.uniformEquicontinuousOn {F : ι → β → α} (H : UniformEquicontinuous F) (S : Set β) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma UniformEquicontinuousOn.mono {F : ι → β → α} {S T : Set β} (H : UniformEquicontinuousOn F T) (hST : S ⊆ T) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono <| by gcongr lemma uniformEquicontinuousOn_univ (F : ι → β → α) : UniformEquicontinuousOn F univ ↔ UniformEquicontinuous F := by simp [UniformEquicontinuousOn, UniformEquicontinuous] lemma uniformEquicontinuous_restrict_iff (F : ι → β → α) {S : Set β} : UniformEquicontinuous (S.restrict ∘ F) ↔ UniformEquicontinuousOn F S := by rw [UniformEquicontinuous, UniformEquicontinuousOn] conv in _ ⊓ _ => rw [← Subtype.range_val (s := S), ← range_prodMap, ← map_comap] rfl /-! ### Empty index type -/ @[simp] lemma equicontinuousAt_empty [h : IsEmpty ι] (F : ι → X → α) (x₀ : X) : EquicontinuousAt F x₀ := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuousWithinAt_empty [h : IsEmpty ι] (F : ι → X → α) (S : Set X) (x₀ : X) : EquicontinuousWithinAt F S x₀ := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuous_empty [IsEmpty ι] (F : ι → X → α) : Equicontinuous F := equicontinuousAt_empty F @[simp] lemma equicontinuousOn_empty [IsEmpty ι] (F : ι → X → α) (S : Set X) : EquicontinuousOn F S := fun x₀ _ ↦ equicontinuousWithinAt_empty F S x₀ @[simp] lemma uniformEquicontinuous_empty [h : IsEmpty ι] (F : ι → β → α) : UniformEquicontinuous F := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma uniformEquicontinuousOn_empty [h : IsEmpty ι] (F : ι → β → α) (S : Set β) : UniformEquicontinuousOn F S := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) /-! ### Finite index type -/ theorem equicontinuousAt_finite [Finite ι] {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ i, ContinuousAt (F i) x₀ := by simp [EquicontinuousAt, ContinuousAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuousWithinAt_finite [Finite ι] {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ∀ i, ContinuousWithinAt (F i) S x₀ := by simp [EquicontinuousWithinAt, ContinuousWithinAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuous_finite [Finite ι] {F : ι → X → α} : Equicontinuous F ↔ ∀ i, Continuous (F i) := by simp only [Equicontinuous, equicontinuousAt_finite, continuous_iff_continuousAt, @forall_swap ι] theorem equicontinuousOn_finite [Finite ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ∀ i, ContinuousOn (F i) S := by simp only [EquicontinuousOn, equicontinuousWithinAt_finite, ContinuousOn, @forall_swap ι] theorem uniformEquicontinuous_finite [Finite ι] {F : ι → β → α} : UniformEquicontinuous F ↔ ∀ i, UniformContinuous (F i) := by simp only [UniformEquicontinuous, eventually_all, @forall_swap _ ι]; rfl theorem uniformEquicontinuousOn_finite [Finite ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ ∀ i, UniformContinuousOn (F i) S := by simp only [UniformEquicontinuousOn, eventually_all, @forall_swap _ ι]; rfl /-! ### Index type with a unique element -/ theorem equicontinuousAt_unique [Unique ι] {F : ι → X → α} {x : X} : EquicontinuousAt F x ↔ ContinuousAt (F default) x := equicontinuousAt_finite.trans Unique.forall_iff theorem equicontinuousWithinAt_unique [Unique ι] {F : ι → X → α} {S : Set X} {x : X} : EquicontinuousWithinAt F S x ↔ ContinuousWithinAt (F default) S x := equicontinuousWithinAt_finite.trans Unique.forall_iff theorem equicontinuous_unique [Unique ι] {F : ι → X → α} : Equicontinuous F ↔ Continuous (F default) := equicontinuous_finite.trans Unique.forall_iff theorem equicontinuousOn_unique [Unique ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (F default) S := equicontinuousOn_finite.trans Unique.forall_iff theorem uniformEquicontinuous_unique [Unique ι] {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (F default) := uniformEquicontinuous_finite.trans Unique.forall_iff theorem uniformEquicontinuousOn_unique [Unique ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformContinuousOn (F default) S := uniformEquicontinuousOn_finite.trans Unique.forall_iff /-- Reformulation of equicontinuity at `x₀` within a set `S`, comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousWithinAt_iff_pair {F : ι → X → α} {S : Set X} {x₀ : X} (hx₀ : x₀ ∈ S) : EquicontinuousWithinAt F S x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝[S] x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by constructor <;> intro H U hU · rcases comp_symm_mem_uniformity_sets hU with ⟨V, hV, hVsymm, hVU⟩ refine ⟨_, H V hV, fun x hx y hy i => hVU (prodMk_mem_compRel ?_ (hy i))⟩ exact hVsymm.mk_mem_comm.mp (hx i) · rcases H U hU with ⟨V, hV, hVU⟩ filter_upwards [hV] using fun x hx i => hVU x₀ (mem_of_mem_nhdsWithin hx₀ hV) x hx i /-- Reformulation of equicontinuity at `x₀` comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousAt_iff_pair {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝 x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by simp_rw [← equicontinuousWithinAt_univ, equicontinuousWithinAt_iff_pair (mem_univ x₀), nhdsWithin_univ] /-- Uniform equicontinuity implies equicontinuity. -/ theorem UniformEquicontinuous.equicontinuous {F : ι → β → α} (h : UniformEquicontinuous F) : Equicontinuous F := fun x₀ U hU ↦ mem_of_superset (ball_mem_nhds x₀ (h U hU)) fun _ hx i ↦ hx i /-- Uniform equicontinuity on a subset implies equicontinuity on that subset. -/ theorem UniformEquicontinuousOn.equicontinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) : EquicontinuousOn F S := fun _ hx₀ U hU ↦ mem_of_superset (ball_mem_nhdsWithin hx₀ (h U hU)) fun _ hx i ↦ hx i /-- Each function of a family equicontinuous at `x₀` is continuous at `x₀`. -/ theorem EquicontinuousAt.continuousAt {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (i : ι) : ContinuousAt (F i) x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i /-- Each function of a family equicontinuous at `x₀` within `S` is continuous at `x₀` within `S`. -/ theorem EquicontinuousWithinAt.continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (i : ι) : ContinuousWithinAt (F i) S x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i protected theorem Set.EquicontinuousAt.continuousAt_of_mem {H : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) {f : X → α} (hf : f ∈ H) : ContinuousAt f x₀ := h.continuousAt ⟨f, hf⟩ protected theorem Set.EquicontinuousWithinAt.continuousWithinAt_of_mem {H : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) {f : X → α} (hf : f ∈ H) : ContinuousWithinAt f S x₀ := h.continuousWithinAt ⟨f, hf⟩ /-- Each function of an equicontinuous family is continuous. -/ theorem Equicontinuous.continuous {F : ι → X → α} (h : Equicontinuous F) (i : ι) : Continuous (F i) := continuous_iff_continuousAt.mpr fun x => (h x).continuousAt i /-- Each function of a family equicontinuous on `S` is continuous on `S`. -/ theorem EquicontinuousOn.continuousOn {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (i : ι) : ContinuousOn (F i) S := fun x hx ↦ (h x hx).continuousWithinAt i protected theorem Set.Equicontinuous.continuous_of_mem {H : Set <| X → α} (h : H.Equicontinuous) {f : X → α} (hf : f ∈ H) : Continuous f := h.continuous ⟨f, hf⟩ protected theorem Set.EquicontinuousOn.continuousOn_of_mem {H : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) {f : X → α} (hf : f ∈ H) : ContinuousOn f S := h.continuousOn ⟨f, hf⟩ /-- Each function of a uniformly equicontinuous family is uniformly continuous. -/ theorem UniformEquicontinuous.uniformContinuous {F : ι → β → α} (h : UniformEquicontinuous F) (i : ι) : UniformContinuous (F i) := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) /-- Each function of a family uniformly equicontinuous on `S` is uniformly continuous on `S`. -/ theorem UniformEquicontinuousOn.uniformContinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (i : ι) : UniformContinuousOn (F i) S := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) protected theorem Set.UniformEquicontinuous.uniformContinuous_of_mem {H : Set <| β → α} (h : H.UniformEquicontinuous) {f : β → α} (hf : f ∈ H) : UniformContinuous f := h.uniformContinuous ⟨f, hf⟩ protected theorem Set.UniformEquicontinuousOn.uniformContinuousOn_of_mem {H : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) {f : β → α} (hf : f ∈ H) : UniformContinuousOn f S := h.uniformContinuousOn ⟨f, hf⟩ /-- Taking sub-families preserves equicontinuity at a point. -/ theorem EquicontinuousAt.comp {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (u : κ → ι) : EquicontinuousAt (F ∘ u) x₀ := fun U hU => (h U hU).mono fun _ H k => H (u k) /-- Taking sub-families preserves equicontinuity at a point within a subset. -/ theorem EquicontinuousWithinAt.comp {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (u : κ → ι) : EquicontinuousWithinAt (F ∘ u) S x₀ := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.EquicontinuousAt.mono {H H' : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) (hH : H' ⊆ H) : H'.EquicontinuousAt x₀ := h.comp (inclusion hH) protected theorem Set.EquicontinuousWithinAt.mono {H H' : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) (hH : H' ⊆ H) : H'.EquicontinuousWithinAt S x₀ := h.comp (inclusion hH) /-- Taking sub-families preserves equicontinuity. -/ theorem Equicontinuous.comp {F : ι → X → α} (h : Equicontinuous F) (u : κ → ι) : Equicontinuous (F ∘ u) := fun x => (h x).comp u /-- Taking sub-families preserves equicontinuity on a subset. -/ theorem EquicontinuousOn.comp {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (u : κ → ι) : EquicontinuousOn (F ∘ u) S := fun x hx ↦ (h x hx).comp u protected theorem Set.Equicontinuous.mono {H H' : Set <| X → α} (h : H.Equicontinuous) (hH : H' ⊆ H) : H'.Equicontinuous := h.comp (inclusion hH) protected theorem Set.EquicontinuousOn.mono {H H' : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) (hH : H' ⊆ H) : H'.EquicontinuousOn S := h.comp (inclusion hH) /-- Taking sub-families preserves uniform equicontinuity. -/ theorem UniformEquicontinuous.comp {F : ι → β → α} (h : UniformEquicontinuous F) (u : κ → ι) : UniformEquicontinuous (F ∘ u) := fun U hU => (h U hU).mono fun _ H k => H (u k) /-- Taking sub-families preserves uniform equicontinuity on a subset. -/ theorem UniformEquicontinuousOn.comp {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (u : κ → ι) : UniformEquicontinuousOn (F ∘ u) S := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.UniformEquicontinuous.mono {H H' : Set <| β → α} (h : H.UniformEquicontinuous) (hH : H' ⊆ H) : H'.UniformEquicontinuous := h.comp (inclusion hH) protected theorem Set.UniformEquicontinuousOn.mono {H H' : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) (hH : H' ⊆ H) : H'.UniformEquicontinuousOn S := h.comp (inclusion hH) /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff `range 𝓕` is equicontinuous at `x₀`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀`. -/ theorem equicontinuousAt_iff_range {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ EquicontinuousAt ((↑) : range F → X → α) x₀ := by simp only [EquicontinuousAt, forall_subtype_range_iff] /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff `range 𝓕` is equicontinuous at `x₀` within `S`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀` within `S`. -/ theorem equicontinuousWithinAt_iff_range {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ EquicontinuousWithinAt ((↑) : range F → X → α) S x₀ := by simp only [EquicontinuousWithinAt, forall_subtype_range_iff] /-- A family `𝓕 : ι → X → α` is equicontinuous iff `range 𝓕` is equicontinuous, i.e the family `(↑) : range F → X → α` is equicontinuous. -/ theorem equicontinuous_iff_range {F : ι → X → α} : Equicontinuous F ↔ Equicontinuous ((↑) : range F → X → α) := forall_congr' fun _ => equicontinuousAt_iff_range /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff `range 𝓕` is equicontinuous on `S`, i.e the family `(↑) : range F → X → α` is equicontinuous on `S`. -/ theorem equicontinuousOn_iff_range {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ EquicontinuousOn ((↑) : range F → X → α) S := forall_congr' fun _ ↦ forall_congr' fun _ ↦ equicontinuousWithinAt_iff_range /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff `range 𝓕` is uniformly equicontinuous, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous. -/ theorem uniformEquicontinuous_iff_range {F : ι → β → α} : UniformEquicontinuous F ↔ UniformEquicontinuous ((↑) : range F → β → α) := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff `range 𝓕` is uniformly equicontinuous on `S`, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous on `S`. -/ theorem uniformEquicontinuousOn_iff_range {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformEquicontinuousOn ((↑) : range F → β → α) S := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ section open UniformFun /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousAt_iff_continuousAt {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ContinuousAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) x₀ := by rw [ContinuousAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` within `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousWithinAt_iff_continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ContinuousWithinAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) S x₀ := by rw [ContinuousWithinAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl /-- A family `𝓕 : ι → X → α` is equicontinuous iff the function `swap 𝓕 : X → ι → α` is continuous *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuous_iff_continuous {F : ι → X → α} : Equicontinuous F ↔ Continuous (ofFun ∘ Function.swap F : X → ι →ᵤ α) := by simp_rw [Equicontinuous, continuous_iff_continuousAt, equicontinuousAt_iff_continuousAt] /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff the function `swap 𝓕 : X → ι → α` is continuous on `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousOn_iff_continuousOn {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (ofFun ∘ Function.swap F : X → ι →ᵤ α) S := by simp_rw [EquicontinuousOn, ContinuousOn, equicontinuousWithinAt_iff_continuousWithinAt] /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff the function `swap 𝓕 : β → ι → α` is uniformly continuous *when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem uniformEquicontinuous_iff_uniformContinuous {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (ofFun ∘ Function.swap F : β → ι →ᵤ α) := by rw [UniformContinuous, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff] rfl /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff the function `swap 𝓕 : β → ι → α` is uniformly continuous on `S` *when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem uniformEquicontinuousOn_iff_uniformContinuousOn {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformContinuousOn (ofFun ∘ Function.swap F : β → ι →ᵤ α) S := by rw [UniformContinuousOn, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff] rfl theorem equicontinuousWithinAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {S : Set X} {x₀ : X} : EquicontinuousWithinAt (uα := ⨅ k, u k) F S x₀ ↔ ∀ k, EquicontinuousWithinAt (uα := u k) F S x₀ := by simp only [equicontinuousWithinAt_iff_continuousWithinAt (uα := _), topologicalSpace] unfold ContinuousWithinAt rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, nhds_iInf, tendsto_iInf] theorem equicontinuousAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {x₀ : X} : EquicontinuousAt (uα := ⨅ k, u k) F x₀ ↔ ∀ k, EquicontinuousAt (uα := u k) F x₀ := by simp only [← equicontinuousWithinAt_univ (uα := _), equicontinuousWithinAt_iInf_rng] theorem equicontinuous_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} : Equicontinuous (uα := ⨅ k, u k) F ↔ ∀ k, Equicontinuous (uα := u k) F := by simp_rw [equicontinuous_iff_continuous (uα := _), UniformFun.topologicalSpace] rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, continuous_iInf_rng] theorem equicontinuousOn_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {S : Set X} : EquicontinuousOn (uα := ⨅ k, u k) F S ↔ ∀ k, EquicontinuousOn (uα := u k) F S := by simp_rw [EquicontinuousOn, equicontinuousWithinAt_iInf_rng, @forall_swap _ κ] theorem uniformEquicontinuous_iInf_rng {u : κ → UniformSpace α'} {F : ι → β → α'} : UniformEquicontinuous (uα := ⨅ k, u k) F ↔ ∀ k, UniformEquicontinuous (uα := u k) F := by simp_rw [uniformEquicontinuous_iff_uniformContinuous (uα := _)] rw [UniformFun.iInf_eq, uniformContinuous_iInf_rng] theorem uniformEquicontinuousOn_iInf_rng {u : κ → UniformSpace α'} {F : ι → β → α'} {S : Set β} : UniformEquicontinuousOn (uα := ⨅ k, u k) F S ↔ ∀ k, UniformEquicontinuousOn (uα := u k) F S := by simp_rw [uniformEquicontinuousOn_iff_uniformContinuousOn (uα := _)] unfold UniformContinuousOn rw [UniformFun.iInf_eq, iInf_uniformity, tendsto_iInf] theorem equicontinuousWithinAt_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α} {S : Set X'} {x₀ : X'} {k : κ} (hk : EquicontinuousWithinAt (tX := t k) F S x₀) : EquicontinuousWithinAt (tX := ⨅ k, t k) F S x₀ := by simp only [equicontinuousWithinAt_iff_continuousWithinAt (tX := _)] at hk ⊢ unfold ContinuousWithinAt nhdsWithin at hk ⊢ rw [nhds_iInf] exact hk.mono_left <| inf_le_inf_right _ <| iInf_le _ k theorem equicontinuousAt_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α} {x₀ : X'} {k : κ} (hk : EquicontinuousAt (tX := t k) F x₀) : EquicontinuousAt (tX := ⨅ k, t k) F x₀ := by rw [← equicontinuousWithinAt_univ (tX := _)] at hk ⊢ exact equicontinuousWithinAt_iInf_dom hk theorem equicontinuous_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α} {k : κ} (hk : Equicontinuous (tX := t k) F) : Equicontinuous (tX := ⨅ k, t k) F := fun x ↦ equicontinuousAt_iInf_dom (hk x) theorem equicontinuousOn_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α} {S : Set X'} {k : κ} (hk : EquicontinuousOn (tX := t k) F S) : EquicontinuousOn (tX := ⨅ k, t k) F S := fun x hx ↦ equicontinuousWithinAt_iInf_dom (hk x hx) theorem uniformEquicontinuous_iInf_dom {u : κ → UniformSpace β'} {F : ι → β' → α} {k : κ} (hk : UniformEquicontinuous (uβ := u k) F) : UniformEquicontinuous (uβ := ⨅ k, u k) F := by simp_rw [uniformEquicontinuous_iff_uniformContinuous (uβ := _)] at hk ⊢ exact uniformContinuous_iInf_dom hk theorem uniformEquicontinuousOn_iInf_dom {u : κ → UniformSpace β'} {F : ι → β' → α} {S : Set β'} {k : κ} (hk : UniformEquicontinuousOn (uβ := u k) F S) : UniformEquicontinuousOn (uβ := ⨅ k, u k) F S := by simp_rw [uniformEquicontinuousOn_iff_uniformContinuousOn (uβ := _)] at hk ⊢ unfold UniformContinuousOn rw [iInf_uniformity] exact hk.mono_left <| inf_le_inf_right _ <| iInf_le _ k theorem Filter.HasBasis.equicontinuousAt_iff_left {p : κ → Prop} {s : κ → Set X} {F : ι → X → α} {x₀ : X} (hX : (𝓝 x₀).HasBasis p s) : EquicontinuousAt F x₀ ↔ ∀ U ∈ 𝓤 α, ∃ k, p k ∧ ∀ x ∈ s k, ∀ i, (F i x₀, F i x) ∈ U := by rw [equicontinuousAt_iff_continuousAt, ContinuousAt, hX.tendsto_iff (UniformFun.hasBasis_nhds ι α _)] rfl theorem Filter.HasBasis.equicontinuousWithinAt_iff_left {p : κ → Prop} {s : κ → Set X} {F : ι → X → α} {S : Set X} {x₀ : X} (hX : (𝓝[S] x₀).HasBasis p s) : EquicontinuousWithinAt F S x₀ ↔ ∀ U ∈ 𝓤 α, ∃ k, p k ∧ ∀ x ∈ s k, ∀ i, (F i x₀, F i x) ∈ U := by rw [equicontinuousWithinAt_iff_continuousWithinAt, ContinuousWithinAt, hX.tendsto_iff (UniformFun.hasBasis_nhds ι α _)] rfl theorem Filter.HasBasis.equicontinuousAt_iff_right {p : κ → Prop} {s : κ → Set (α × α)} {F : ι → X → α} {x₀ : X} (hα : (𝓤 α).HasBasis p s) : EquicontinuousAt F x₀ ↔ ∀ k, p k → ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ s k := by rw [equicontinuousAt_iff_continuousAt, ContinuousAt, (UniformFun.hasBasis_nhds_of_basis ι α _ hα).tendsto_right_iff] rfl theorem Filter.HasBasis.equicontinuousWithinAt_iff_right {p : κ → Prop} {s : κ → Set (α × α)} {F : ι → X → α} {S : Set X} {x₀ : X} (hα : (𝓤 α).HasBasis p s) : EquicontinuousWithinAt F S x₀ ↔ ∀ k, p k → ∀ᶠ x in 𝓝[S] x₀, ∀ i, (F i x₀, F i x) ∈ s k := by rw [equicontinuousWithinAt_iff_continuousWithinAt, ContinuousWithinAt, (UniformFun.hasBasis_nhds_of_basis ι α _ hα).tendsto_right_iff] rfl theorem Filter.HasBasis.equicontinuousAt_iff {κ₁ κ₂ : Type*} {p₁ : κ₁ → Prop} {s₁ : κ₁ → Set X} {p₂ : κ₂ → Prop} {s₂ : κ₂ → Set (α × α)} {F : ι → X → α} {x₀ : X} (hX : (𝓝 x₀).HasBasis p₁ s₁) (hα : (𝓤 α).HasBasis p₂ s₂) : EquicontinuousAt F x₀ ↔ ∀ k₂, p₂ k₂ → ∃ k₁, p₁ k₁ ∧ ∀ x ∈ s₁ k₁, ∀ i, (F i x₀, F i x) ∈ s₂ k₂ := by rw [equicontinuousAt_iff_continuousAt, ContinuousAt, hX.tendsto_iff (UniformFun.hasBasis_nhds_of_basis ι α _ hα)] rfl theorem Filter.HasBasis.equicontinuousWithinAt_iff {κ₁ κ₂ : Type*} {p₁ : κ₁ → Prop} {s₁ : κ₁ → Set X} {p₂ : κ₂ → Prop} {s₂ : κ₂ → Set (α × α)} {F : ι → X → α} {S : Set X} {x₀ : X} (hX : (𝓝[S] x₀).HasBasis p₁ s₁) (hα : (𝓤 α).HasBasis p₂ s₂) : EquicontinuousWithinAt F S x₀ ↔ ∀ k₂, p₂ k₂ → ∃ k₁, p₁ k₁ ∧ ∀ x ∈ s₁ k₁, ∀ i, (F i x₀, F i x) ∈ s₂ k₂ := by rw [equicontinuousWithinAt_iff_continuousWithinAt, ContinuousWithinAt, hX.tendsto_iff (UniformFun.hasBasis_nhds_of_basis ι α _ hα)] rfl theorem Filter.HasBasis.uniformEquicontinuous_iff_left {p : κ → Prop} {s : κ → Set (β × β)} {F : ι → β → α} (hβ : (𝓤 β).HasBasis p s) : UniformEquicontinuous F ↔ ∀ U ∈ 𝓤 α, ∃ k, p k ∧ ∀ x y, (x, y) ∈ s k → ∀ i, (F i x, F i y) ∈ U := by rw [uniformEquicontinuous_iff_uniformContinuous, UniformContinuous, hβ.tendsto_iff (UniformFun.hasBasis_uniformity ι α)] simp only [Prod.forall] rfl theorem Filter.HasBasis.uniformEquicontinuousOn_iff_left {p : κ → Prop} {s : κ → Set (β × β)} {F : ι → β → α} {S : Set β} (hβ : (𝓤 β ⊓ 𝓟 (S ×ˢ S)).HasBasis p s) : UniformEquicontinuousOn F S ↔ ∀ U ∈ 𝓤 α, ∃ k, p k ∧ ∀ x y, (x, y) ∈ s k → ∀ i, (F i x, F i y) ∈ U := by rw [uniformEquicontinuousOn_iff_uniformContinuousOn, UniformContinuousOn, hβ.tendsto_iff (UniformFun.hasBasis_uniformity ι α)] simp only [Prod.forall] rfl theorem Filter.HasBasis.uniformEquicontinuous_iff_right {p : κ → Prop} {s : κ → Set (α × α)} {F : ι → β → α} (hα : (𝓤 α).HasBasis p s) : UniformEquicontinuous F ↔ ∀ k, p k → ∀ᶠ xy : β × β in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ s k := by rw [uniformEquicontinuous_iff_uniformContinuous, UniformContinuous, (UniformFun.hasBasis_uniformity_of_basis ι α hα).tendsto_right_iff] rfl theorem Filter.HasBasis.uniformEquicontinuousOn_iff_right {p : κ → Prop} {s : κ → Set (α × α)} {F : ι → β → α} {S : Set β} (hα : (𝓤 α).HasBasis p s) : UniformEquicontinuousOn F S ↔ ∀ k, p k → ∀ᶠ xy : β × β in 𝓤 β ⊓ 𝓟 (S ×ˢ S), ∀ i, (F i xy.1, F i xy.2) ∈ s k := by rw [uniformEquicontinuousOn_iff_uniformContinuousOn, UniformContinuousOn, (UniformFun.hasBasis_uniformity_of_basis ι α hα).tendsto_right_iff] rfl theorem Filter.HasBasis.uniformEquicontinuous_iff {κ₁ κ₂ : Type*} {p₁ : κ₁ → Prop} {s₁ : κ₁ → Set (β × β)} {p₂ : κ₂ → Prop} {s₂ : κ₂ → Set (α × α)} {F : ι → β → α} (hβ : (𝓤 β).HasBasis p₁ s₁) (hα : (𝓤 α).HasBasis p₂ s₂) : UniformEquicontinuous F ↔ ∀ k₂, p₂ k₂ → ∃ k₁, p₁ k₁ ∧ ∀ x y, (x, y) ∈ s₁ k₁ → ∀ i, (F i x, F i y) ∈ s₂ k₂ := by rw [uniformEquicontinuous_iff_uniformContinuous, UniformContinuous, hβ.tendsto_iff (UniformFun.hasBasis_uniformity_of_basis ι α hα)] simp only [Prod.forall] rfl theorem Filter.HasBasis.uniformEquicontinuousOn_iff {κ₁ κ₂ : Type*} {p₁ : κ₁ → Prop} {s₁ : κ₁ → Set (β × β)} {p₂ : κ₂ → Prop} {s₂ : κ₂ → Set (α × α)} {F : ι → β → α} {S : Set β} (hβ : (𝓤 β ⊓ 𝓟 (S ×ˢ S)).HasBasis p₁ s₁) (hα : (𝓤 α).HasBasis p₂ s₂) : UniformEquicontinuousOn F S ↔ ∀ k₂, p₂ k₂ → ∃ k₁, p₁ k₁ ∧ ∀ x y, (x, y) ∈ s₁ k₁ → ∀ i, (F i x, F i y) ∈ s₂ k₂ := by rw [uniformEquicontinuousOn_iff_uniformContinuousOn, UniformContinuousOn, hβ.tendsto_iff (UniformFun.hasBasis_uniformity_of_basis ι α hα)] simp only [Prod.forall] rfl /-- Given `u : α → β` a uniform inducing map, a family `𝓕 : ι → X → α` is equicontinuous at a point `x₀ : X` iff the family `𝓕'`, obtained by composing each function of `𝓕` by `u`, is equicontinuous at `x₀`. -/ theorem IsUniformInducing.equicontinuousAt_iff {F : ι → X → α} {x₀ : X} {u : α → β} (hu : IsUniformInducing u) : EquicontinuousAt F x₀ ↔ EquicontinuousAt ((u ∘ ·) ∘ F) x₀ := by have := (UniformFun.postcomp_isUniformInducing (α := ι) hu).isInducing rw [equicontinuousAt_iff_continuousAt, equicontinuousAt_iff_continuousAt, this.continuousAt_iff] rfl /-- Given `u : α → β` a uniform inducing map, a family `𝓕 : ι → X → α` is equicontinuous at a point `x₀ : X` within a subset `S : Set X` iff the family `𝓕'`, obtained by composing each function of `𝓕` by `u`, is equicontinuous at `x₀` within `S`. -/ lemma IsUniformInducing.equicontinuousWithinAt_iff {F : ι → X → α} {S : Set X} {x₀ : X} {u : α → β} (hu : IsUniformInducing u) : EquicontinuousWithinAt F S x₀ ↔ EquicontinuousWithinAt ((u ∘ ·) ∘ F) S x₀ := by have := (UniformFun.postcomp_isUniformInducing (α := ι) hu).isInducing simp only [equicontinuousWithinAt_iff_continuousWithinAt, this.continuousWithinAt_iff] rfl /-- Given `u : α → β` a uniform inducing map, a family `𝓕 : ι → X → α` is equicontinuous iff the family `𝓕'`, obtained by composing each function of `𝓕` by `u`, is equicontinuous. -/ lemma IsUniformInducing.equicontinuous_iff {F : ι → X → α} {u : α → β} (hu : IsUniformInducing u) : Equicontinuous F ↔ Equicontinuous ((u ∘ ·) ∘ F) := by congrm ∀ x, ?_ rw [hu.equicontinuousAt_iff] /-- Given `u : α → β` a uniform inducing map, a family `𝓕 : ι → X → α` is equicontinuous on a subset `S : Set X` iff the family `𝓕'`, obtained by composing each function of `𝓕` by `u`, is equicontinuous on `S`. -/ theorem IsUniformInducing.equicontinuousOn_iff {F : ι → X → α} {S : Set X} {u : α → β} (hu : IsUniformInducing u) : EquicontinuousOn F S ↔ EquicontinuousOn ((u ∘ ·) ∘ F) S := by congrm ∀ x ∈ S, ?_ rw [hu.equicontinuousWithinAt_iff] /-- Given `u : α → γ` a uniform inducing map, a family `𝓕 : ι → β → α` is uniformly equicontinuous iff the family `𝓕'`, obtained by composing each function of `𝓕` by `u`, is uniformly equicontinuous. -/ theorem IsUniformInducing.uniformEquicontinuous_iff {F : ι → β → α} {u : α → γ} (hu : IsUniformInducing u) : UniformEquicontinuous F ↔ UniformEquicontinuous ((u ∘ ·) ∘ F) := by have := UniformFun.postcomp_isUniformInducing (α := ι) hu simp only [uniformEquicontinuous_iff_uniformContinuous, this.uniformContinuous_iff] rfl /-- Given `u : α → γ` a uniform inducing map, a family `𝓕 : ι → β → α` is uniformly equicontinuous on a subset `S : Set β` iff the family `𝓕'`, obtained by composing each function of `𝓕` by `u`, is uniformly equicontinuous on `S`. -/ theorem IsUniformInducing.uniformEquicontinuousOn_iff {F : ι → β → α} {S : Set β} {u : α → γ} (hu : IsUniformInducing u) : UniformEquicontinuousOn F S ↔ UniformEquicontinuousOn ((u ∘ ·) ∘ F) S := by have := UniformFun.postcomp_isUniformInducing (α := ι) hu simp only [uniformEquicontinuousOn_iff_uniformContinuousOn, this.uniformContinuousOn_iff] rfl /-- If a set of functions is equicontinuous at some `x₀` within a set `S`, the same is true for its closure in *any* topology for which evaluation at any `x ∈ S ∪ {x₀}` is continuous. Since this will be applied to `DFunLike` types, we state it for any topological space with a map
to `X → α` satisfying the right continuity conditions. See also `Set.EquicontinuousWithinAt.closure` for a more familiar (but weaker) statement. Note: This could *technically* be called `EquicontinuousWithinAt.closure` without name clashes
Mathlib/Topology/UniformSpace/Equicontinuity.lean
760
763
/- 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.Attach import Mathlib.Data.Finset.Disjoint import Mathlib.Data.Finset.Erase import Mathlib.Data.Finset.Filter import Mathlib.Data.Finset.Range import Mathlib.Data.Finset.SDiff import Mathlib.Data.Multiset.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Defs import Mathlib.Data.Set.SymmDiff /-! # Basic lemmas on finite sets This file contains lemmas on the interaction of various definitions on the `Finset` type. For an explanation of `Finset` design decisions, please see `Mathlib/Data/Finset/Defs.lean`. ## Main declarations ### Main definitions * `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. ### Equivalences between finsets * The `Mathlib/Logic/Equiv/Defs.lean` file describes 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 Multiset.powerset CompleteLattice Monoid open Multiset Subtype Function universe u variable {α : Type*} {β : Type*} {γ : Type*} namespace Finset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-02-07")] 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 [Nat.add_comm] refine lt_trans ?_ (Nat.lt_succ_self _) exact Multiset.sizeOf_lt_sizeOf_of_mem hx /-! ### Lattice structure -/ section Lattice variable [DecidableEq α] {s s₁ s₂ t t₁ t₂ u v : Finset α} {a b : α} /-! #### union -/ @[simp] theorem disjUnion_eq_union (s t h) : @disjUnion α s t h = s ∪ t := ext fun a => by simp @[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] @[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] /-! #### inter -/ theorem not_disjoint_iff_nonempty_inter : ¬Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff.trans <| by simp [Finset.Nonempty] alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter theorem disjoint_or_nonempty_inter (s t : Finset α) : Disjoint s t ∨ (s ∩ t).Nonempty := by rw [← not_disjoint_iff_nonempty_inter] exact em _ omit [DecidableEq α] in theorem disjoint_of_subset_iff_left_eq_empty (h : s ⊆ t) : Disjoint s t ↔ s = ∅ := disjoint_of_le_iff_left_eq_bot h lemma pairwiseDisjoint_iff {ι : Type*} {s : Set ι} {f : ι → Finset α} : s.PairwiseDisjoint f ↔ ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → (f i ∩ f j).Nonempty → i = j := by simp [Set.PairwiseDisjoint, Set.Pairwise, Function.onFun, not_imp_comm (a := _ = _), not_disjoint_iff_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 : α} @[simp] theorem erase_empty (a : α) : erase ∅ a = ∅ := rfl 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 @[simp] theorem erase_insert_eq_erase (s : Finset α) (a : α) : (insert a s).erase a = s.erase a := ext fun x => by simp +contextual only [mem_erase, mem_insert, and_congr_right_iff, false_or, iff_self, imp_true_iff] 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] 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] 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] @[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] apply or_iff_right_of_imp rintro rfl exact h 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_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 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⟩⟩ 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 _ _⟩ 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] 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 theorem erase_insert_subset (a : α) (s : Finset α) : erase (insert a s) a ⊆ s := subset_insert_iff.1 <| Subset.rfl theorem insert_erase_subset (a : α) (s : Finset α) : s ⊆ insert a (erase s a) := subset_insert_iff.2 <| Subset.rfl 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] 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] 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] 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 : α} lemma erase_sdiff_erase (hab : a ≠ b) (hb : b ∈ s) : s.erase a \ s.erase b = {b} := by ext; aesop -- 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 \ {a} = erase s a := by ext rw [mem_erase, mem_sdiff, mem_singleton, and_comm] -- This lemma matches `Finset.insert_eq` in functionality. theorem erase_eq (s : Finset α) (a : α) : s.erase a = s \ {a} := (sdiff_singleton_eq_erase _ _).symm theorem disjoint_erase_comm : Disjoint (s.erase a) t ↔ Disjoint s (t.erase a) := by simp_rw [erase_eq, disjoint_sdiff_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⟩ 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⟩ theorem inter_erase (a : α) (s t : Finset α) : s ∩ t.erase a = (s ∩ t).erase a := by simp only [erase_eq, inter_sdiff_assoc] @[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 theorem erase_sdiff_comm (s t : Finset α) (a : α) : s.erase a \ t = (s \ t).erase a := by simp_rw [erase_eq, sdiff_right_comm] theorem erase_inter_comm (s t : Finset α) (a : α) : s.erase a ∩ t = s ∩ t.erase a := by rw [erase_inter, inter_erase] 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] 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] 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] 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] 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] 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)] 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] 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⟩)] 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] theorem sdiff_erase_self (ha : a ∈ s) : s \ s.erase a = {a} := by rw [sdiff_erase ha, Finset.sdiff_self, insert_empty_eq] 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] --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 theorem disjoint_sdiff : Disjoint s (t \ s) := sdiff_disjoint.symm theorem disjoint_sdiff_inter (s t : Finset α) : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right sdiff_disjoint end Sdiff /-! ### attach -/ @[simp] theorem attach_empty : attach (∅ : Finset α) = ∅ := rfl @[simp] theorem attach_nonempty_iff {s : Finset α} : s.attach.Nonempty ↔ s.Nonempty := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] 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] /-! ### filter -/ section Filter variable (p q : α → Prop) [DecidablePred p] [DecidablePred q] {s t : Finset α} 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'] 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_of_mem_filter _).mt ha) := eq_of_veq <| Multiset.filter_cons_of_pos s.val hp 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 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 +contextual [disjoint_left] 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 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 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 _ _ _ theorem filter_cons {a : α} (s : Finset α) (ha : a ∉ s) : filter p (cons a s ha) = if p a then cons a (filter p s) ((mem_of_mem_filter _).mt ha) else filter p s := by split_ifs with h · rw [filter_cons_of_pos _ _ _ ha h] · rw [filter_cons_of_neg _ _ _ ha h] section 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] 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] 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] 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] 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] theorem inter_filter (s t : Finset α) : s ∩ filter p t = filter p (s ∩ t) := by rw [inter_comm, filter_inter, inter_comm] theorem filter_insert (a : α) (s : Finset α) : filter p (insert a s) = if p a then insert a (filter p s) else filter p s := by ext x split_ifs with h <;> by_cases h' : x = a <;> simp [h, h'] theorem filter_erase (a : α) (s : Finset α) : filter p (erase s a) = erase (filter p s) a := by ext x simp only [and_assoc, mem_filter, iff_self, mem_erase] theorem filter_or (s : Finset α) : (s.filter fun a => p a ∨ q a) = s.filter p ∪ s.filter q := ext fun _ => by simp [mem_filter, mem_union, and_or_left] theorem filter_and (s : Finset α) : (s.filter fun a => p a ∧ q a) = s.filter p ∩ s.filter q := ext fun _ => by simp [mem_filter, mem_inter, and_comm, and_left_comm, and_self_iff, and_assoc] theorem filter_not (s : Finset α) : (s.filter fun a => ¬p a) = s \ s.filter p := ext fun a => by simp only [Bool.decide_coe, Bool.not_eq_true', mem_filter, and_comm, mem_sdiff, not_and_or, Bool.not_eq_true, and_or_left, and_not_self, or_false] lemma filter_and_not (s : Finset α) (p q : α → Prop) [DecidablePred p] [DecidablePred q] : s.filter (fun a ↦ p a ∧ ¬ q a) = s.filter p \ s.filter q := by rw [filter_and, filter_not, ← inter_sdiff_assoc, inter_eq_left.2 (filter_subset _ _)] theorem sdiff_eq_filter (s₁ s₂ : Finset α) : s₁ \ s₂ = filter (· ∉ s₂) s₁ := ext fun _ => by simp [mem_sdiff, mem_filter] theorem subset_union_elim {s : Finset α} {t₁ t₂ : Set α} (h : ↑s ⊆ t₁ ∪ t₂) : ∃ s₁ s₂ : Finset α, s₁ ∪ s₂ = s ∧ ↑s₁ ⊆ t₁ ∧ ↑s₂ ⊆ t₂ \ t₁ := by classical refine ⟨s.filter (· ∈ t₁), s.filter (· ∉ t₁), ?_, ?_, ?_⟩ · simp [filter_union_right, em] · intro x simp · intro x simp only [not_not, coe_filter, Set.mem_setOf_eq, Set.mem_diff, and_imp] intro hx hx₂ exact ⟨Or.resolve_left (h hx) hx₂, hx₂⟩ -- This is not a good simp lemma, as it would prevent `Finset.mem_filter` from firing -- on, e.g. `x ∈ s.filter (Eq b)`. /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq'` with the equality the other way. -/ theorem filter_eq [DecidableEq β] (s : Finset β) (b : β) : s.filter (Eq b) = ite (b ∈ s) {b} ∅ := by split_ifs with h · ext simp only [mem_filter, mem_singleton, decide_eq_true_eq] refine ⟨fun h => h.2.symm, ?_⟩ rintro rfl exact ⟨h, rfl⟩ · ext simp only [mem_filter, not_and, iff_false, not_mem_empty, decide_eq_true_eq] rintro m rfl exact h m /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq` with the equality the other way. -/ theorem filter_eq' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a = b) = ite (b ∈ s) {b} ∅ := _root_.trans (filter_congr fun _ _ => by simp_rw [@eq_comm _ b]) (filter_eq s b) theorem filter_ne [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => b ≠ a) = s.erase b := by ext simp only [mem_filter, mem_erase, Ne, decide_not, Bool.not_eq_true', decide_eq_false_iff_not] tauto theorem filter_ne' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a ≠ b) = s.erase b := _root_.trans (filter_congr fun _ _ => by simp_rw [@ne_comm _ b]) (filter_ne s b) theorem filter_union_filter_of_codisjoint (s : Finset α) (h : Codisjoint p q) : s.filter p ∪ s.filter q = s := (filter_or _ _ _).symm.trans <| filter_true_of_mem fun x _ => h.top_le x trivial theorem filter_union_filter_neg_eq [∀ x, Decidable (¬p x)] (s : Finset α) : (s.filter p ∪ s.filter fun a => ¬p a) = s := filter_union_filter_of_codisjoint _ _ _ <| @codisjoint_hnot_right _ _ p end end Filter /-! ### range -/ section Range open Nat variable {n m l : ℕ} @[simp] theorem range_filter_eq {n m : ℕ} : (range n).filter (· = m) = if m < n then {m} else ∅ := by convert filter_eq (range n) m using 2 · ext rw [eq_comm] · simp end Range end Finset /-! ### dedup on list and multiset -/ namespace Multiset variable [DecidableEq α] {s t : Multiset α} @[simp] theorem toFinset_add (s t : Multiset α) : toFinset (s + t) = toFinset s ∪ toFinset t := Finset.ext <| by simp @[simp] theorem toFinset_inter (s t : Multiset α) : toFinset (s ∩ t) = toFinset s ∩ toFinset t := Finset.ext <| by simp @[simp] theorem toFinset_union (s t : Multiset α) : (s ∪ t).toFinset = s.toFinset ∪ t.toFinset := by ext; simp @[simp] theorem toFinset_eq_empty {m : Multiset α} : m.toFinset = ∅ ↔ m = 0 := Finset.val_inj.symm.trans Multiset.dedup_eq_zero @[simp] theorem toFinset_nonempty : s.toFinset.Nonempty ↔ s ≠ 0 := by simp only [toFinset_eq_empty, Ne, Finset.nonempty_iff_ne_empty] @[aesop safe apply (rule_sets := [finsetNonempty])] protected alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty @[simp] theorem toFinset_filter (s : Multiset α) (p : α → Prop) [DecidablePred p] : Multiset.toFinset (s.filter p) = s.toFinset.filter p := by ext; simp end Multiset namespace List variable [DecidableEq α] {l l' : List α} {a : α} {f : α → β} {s : Finset α} {t : Set β} {t' : Finset β} @[simp] theorem toFinset_union (l l' : List α) : (l ∪ l').toFinset = l.toFinset ∪ l'.toFinset := by ext simp @[simp] theorem toFinset_inter (l l' : List α) : (l ∩ l').toFinset = l.toFinset ∩ l'.toFinset := by ext simp @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty_iff @[simp] theorem toFinset_filter (s : List α) (p : α → Bool) : (s.filter p).toFinset = s.toFinset.filter (p ·) := by ext; simp [List.mem_filter] end List namespace Finset section ToList @[simp] theorem toList_eq_nil {s : Finset α} : s.toList = [] ↔ s = ∅ := Multiset.toList_eq_nil.trans val_eq_zero theorem empty_toList {s : Finset α} : s.toList.isEmpty ↔ s = ∅ := by simp @[simp] theorem toList_empty : (∅ : Finset α).toList = [] := toList_eq_nil.mpr rfl theorem Nonempty.toList_ne_nil {s : Finset α} (hs : s.Nonempty) : s.toList ≠ [] := mt toList_eq_nil.mp hs.ne_empty theorem Nonempty.not_empty_toList {s : Finset α} (hs : s.Nonempty) : ¬s.toList.isEmpty := mt empty_toList.mp hs.ne_empty end ToList /-! ### choose -/ section Choose variable (p : α → Prop) [DecidablePred p] (l : Finset α) /-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of `l` satisfying `p` this unique element, as an element of the corresponding subtype. -/ def chooseX (hp : ∃! a, a ∈ l ∧ p a) : { a // a ∈ l ∧ p a } := Multiset.chooseX p l.val hp /-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of `l` satisfying `p` this unique element, as an element of the ambient type. -/ def choose (hp : ∃! a, a ∈ l ∧ p a) : α := chooseX p l hp theorem choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (chooseX p l hp).property theorem choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 theorem choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end Choose end Finset namespace Equiv variable [DecidableEq α] {s t : Finset α} open Finset /-- The disjoint union of finsets is a sum -/ def Finset.union (s t : Finset α) (h : Disjoint s t) : s ⊕ t ≃ (s ∪ t : Finset α) := Equiv.setCongr (coe_union _ _) |>.trans (Equiv.Set.union (disjoint_coe.mpr h)) |>.symm @[simp] theorem Finset.union_symm_inl (h : Disjoint s t) (x : s) : Equiv.Finset.union s t h (Sum.inl x) = ⟨x, Finset.mem_union.mpr <| Or.inl x.2⟩ := rfl @[simp] theorem Finset.union_symm_inr (h : Disjoint s t) (y : t) : Equiv.Finset.union s t h (Sum.inr y) = ⟨y, Finset.mem_union.mpr <| Or.inr y.2⟩ := rfl /-- The type of dependent functions on the disjoint union of finsets `s ∪ t` is equivalent to the type of pairs of functions on `s` and on `t`. This is similar to `Equiv.sumPiEquivProdPi`. -/ def piFinsetUnion {ι} [DecidableEq ι] (α : ι → Type*) {s t : Finset ι} (h : Disjoint s t) : ((∀ i : s, α i) × ∀ i : t, α i) ≃ ∀ i : (s ∪ t : Finset ι), α i := let e := Equiv.Finset.union s t h sumPiEquivProdPi (fun b ↦ α (e b)) |>.symm.trans (.piCongrLeft (fun i : ↥(s ∪ t) ↦ α i) e) /-- A finset is equivalent to its coercion as a set. -/ def _root_.Finset.equivToSet (s : Finset α) : s ≃ s.toSet where toFun a := ⟨a.1, mem_coe.2 a.2⟩ invFun a := ⟨a.1, mem_coe.1 a.2⟩ left_inv := fun _ ↦ rfl right_inv := fun _ ↦ rfl end Equiv namespace Multiset variable [DecidableEq α] @[simp] lemma toFinset_replicate (n : ℕ) (a : α) : (replicate n a).toFinset = if n = 0 then ∅ else {a} := by ext x simp only [mem_toFinset, Finset.mem_singleton, mem_replicate] split_ifs with hn <;> simp [hn] end Multiset
Mathlib/Data/Finset/Basic.lean
2,390
2,392
/- Copyright (c) 2019 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, Sébastien Gouëzel, Yury Kudryashov, Yuyang Zhao -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Comp import Mathlib.Analysis.Calculus.FDeriv.RestrictScalars /-! # One-dimensional derivatives of compositions of functions In this file we prove the chain rule for the following cases: * `HasDerivAt.comp` etc: `f : 𝕜' → 𝕜'` composed with `g : 𝕜 → 𝕜'`; * `HasDerivAt.scomp` etc: `f : 𝕜' → E` composed with `g : 𝕜 → 𝕜'`; * `HasFDerivAt.comp_hasDerivAt` etc: `f : E → F` composed with `g : 𝕜 → E`; Here `𝕜` is the base normed field, `E` and `F` are normed spaces over `𝕜` and `𝕜'` is an algebra over `𝕜` (e.g., `𝕜'=𝕜` or `𝕜=ℝ`, `𝕜'=ℂ`). We also give versions with the `of_eq` suffix, which require an equality proof instead of definitional equality of the different points used in the composition. These versions are often more flexible to use. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `analysis/calculus/deriv/basic`. ## Keywords derivative, chain rule -/ universe u v w open scoped Topology Filter ENNReal open Filter Asymptotics Set open ContinuousLinearMap (smulRight smulRight_one_eq_iff) variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f : 𝕜 → F} variable {f' : F} variable {x : 𝕜} variable {s : Set 𝕜} variable {L : Filter 𝕜} section Composition /-! ### Derivative of the composition of a vector function and a scalar function We use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp` in lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also because the `comp` version with the shorter name will show up much more often in applications). The formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to usual multiplication in `comp` lemmas. -/ /- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to get confused since there are too many possibilities for composition -/ variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F] [IsScalarTower 𝕜 𝕜' F] {s' t' : Set 𝕜'} {h : 𝕜 → 𝕜'} {h₂ : 𝕜' → 𝕜'} {h' h₂' : 𝕜'} {g₁ : 𝕜' → F} {g₁' : F} {L' : Filter 𝕜'} {y : 𝕜'} (x) theorem HasDerivAtFilter.scomp (hg : HasDerivAtFilter g₁ g₁' (h x) L') (hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') : HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by simpa using ((hg.restrictScalars 𝕜).comp x hh hL).hasDerivAtFilter theorem HasDerivAtFilter.scomp_of_eq (hg : HasDerivAtFilter g₁ g₁' y L') (hh : HasDerivAtFilter h h' x L) (hy : y = h x) (hL : Tendsto h L L') : HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by rw [hy] at hg; exact hg.scomp x hh hL theorem HasDerivWithinAt.scomp_hasDerivAt (hg : HasDerivWithinAt g₁ g₁' s' (h x)) (hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') : HasDerivAt (g₁ ∘ h) (h' • g₁') x := hg.scomp x hh <| tendsto_inf.2 ⟨hh.continuousAt, tendsto_principal.2 <| Eventually.of_forall hs⟩ theorem HasDerivWithinAt.scomp_hasDerivAt_of_eq (hg : HasDerivWithinAt g₁ g₁' s' y) (hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') (hy : y = h x) : HasDerivAt (g₁ ∘ h) (h' • g₁') x := by rw [hy] at hg; exact hg.scomp_hasDerivAt x hh hs nonrec theorem HasDerivWithinAt.scomp (hg : HasDerivWithinAt g₁ g₁' t' (h x)) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := hg.scomp x hh <| hh.continuousWithinAt.tendsto_nhdsWithin hst theorem HasDerivWithinAt.scomp_of_eq (hg : HasDerivWithinAt g₁ g₁' t' y) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') (hy : y = h x) : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by rw [hy] at hg; exact hg.scomp x hh hst /-- The chain rule. -/ nonrec theorem HasDerivAt.scomp (hg : HasDerivAt g₁ g₁' (h x)) (hh : HasDerivAt h h' x) : HasDerivAt (g₁ ∘ h) (h' • g₁') x := hg.scomp x hh hh.continuousAt /-- The chain rule. -/ theorem HasDerivAt.scomp_of_eq (hg : HasDerivAt g₁ g₁' y) (hh : HasDerivAt h h' x) (hy : y = h x) : HasDerivAt (g₁ ∘ h) (h' • g₁') x := by rw [hy] at hg; exact hg.scomp x hh theorem HasStrictDerivAt.scomp (hg : HasStrictDerivAt g₁ g₁' (h x)) (hh : HasStrictDerivAt h h' x) : HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by simpa using ((hg.restrictScalars 𝕜).comp x hh).hasStrictDerivAt theorem HasStrictDerivAt.scomp_of_eq (hg : HasStrictDerivAt g₁ g₁' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) : HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by rw [hy] at hg; exact hg.scomp x hh theorem HasDerivAt.scomp_hasDerivWithinAt (hg : HasDerivAt g₁ g₁' (h x)) (hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh (mapsTo_univ _ _) theorem HasDerivAt.scomp_hasDerivWithinAt_of_eq (hg : HasDerivAt g₁ g₁' y) (hh : HasDerivWithinAt h h' s x) (hy : y = h x) : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by rw [hy] at hg; exact hg.scomp_hasDerivWithinAt x hh theorem derivWithin.scomp (hg : DifferentiableWithinAt 𝕜' g₁ t' (h x)) (hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t') : derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh.hasDerivWithinAt hs).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] theorem derivWithin.scomp_of_eq (hg : DifferentiableWithinAt 𝕜' g₁ t' y) (hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t') (hy : y = h x) : derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := by rw [hy] at hg; exact derivWithin.scomp x hg hh hs theorem deriv.scomp (hg : DifferentiableAt 𝕜' g₁ (h x)) (hh : DifferentiableAt 𝕜 h x) : deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) := (HasDerivAt.scomp x hg.hasDerivAt hh.hasDerivAt).deriv theorem deriv.scomp_of_eq (hg : DifferentiableAt 𝕜' g₁ y) (hh : DifferentiableAt 𝕜 h x) (hy : y = h x) : deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) := by rw [hy] at hg; exact deriv.scomp x hg hh /-! ### Derivative of the composition of a scalar and vector functions -/ theorem HasDerivAtFilter.comp_hasFDerivAtFilter {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E} (hh₂ : HasDerivAtFilter h₂ h₂' (f x) L') (hf : HasFDerivAtFilter f f' x L'') (hL : Tendsto f L'' L') : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by convert (hh₂.restrictScalars 𝕜).comp x hf hL ext x simp [mul_comm] theorem HasDerivAtFilter.comp_hasFDerivAtFilter_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E} (hh₂ : HasDerivAtFilter h₂ h₂' y L') (hf : HasFDerivAtFilter f f' x L'') (hL : Tendsto f L'' L') (hy : y = f x) : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by rw [hy] at hh₂; exact hh₂.comp_hasFDerivAtFilter x hf hL theorem HasStrictDerivAt.comp_hasStrictFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) (hh : HasStrictDerivAt h₂ h₂' (f x)) (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by rw [HasStrictDerivAt] at hh convert (hh.restrictScalars 𝕜).comp x hf ext x simp [mul_comm] theorem HasStrictDerivAt.comp_hasStrictFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) (hh : HasStrictDerivAt h₂ h₂' y) (hf : HasStrictFDerivAt f f' x) (hy : y = f x) : HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by rw [hy] at hh; exact hh.comp_hasStrictFDerivAt x hf theorem HasDerivAt.comp_hasFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) (hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivAt f f' x) : HasFDerivAt (h₂ ∘ f) (h₂' • f') x := hh.comp_hasFDerivAtFilter x hf hf.continuousAt theorem HasDerivAt.comp_hasFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) (hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivAt f f' x) (hy : y = f x) : HasFDerivAt (h₂ ∘ f) (h₂' • f') x := by rw [hy] at hh; exact hh.comp_hasFDerivAt x hf theorem HasDerivAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x) (hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := hh.comp_hasFDerivAtFilter x hf hf.continuousWithinAt theorem HasDerivAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x) (hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivWithinAt f f' s x) (hy : y = f x) : HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf theorem HasDerivWithinAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x) (hh : HasDerivWithinAt h₂ h₂' t (f x)) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t) : HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := hh.comp_hasFDerivAtFilter x hf <| hf.continuousWithinAt.tendsto_nhdsWithin hst theorem HasDerivWithinAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x) (hh : HasDerivWithinAt h₂ h₂' t y) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t) (hy : y = f x) : HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf hst /-! ### Derivative of the composition of two scalar functions -/ theorem HasDerivAtFilter.comp (hh₂ : HasDerivAtFilter h₂ h₂' (h x) L') (hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') : HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by rw [mul_comm] exact hh₂.scomp x hh hL theorem HasDerivAtFilter.comp_of_eq (hh₂ : HasDerivAtFilter h₂ h₂' y L') (hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') (hy : y = h x) : HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by rw [hy] at hh₂; exact hh₂.comp x hh hL theorem HasDerivWithinAt.comp (hh₂ : HasDerivWithinAt h₂ h₂' s' (h x)) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s s') : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by rw [mul_comm] exact hh₂.scomp x hh hst theorem HasDerivWithinAt.comp_of_eq (hh₂ : HasDerivWithinAt h₂ h₂' s' y) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s s') (hy : y = h x) : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by rw [hy] at hh₂; exact hh₂.comp x hh hst /-- The chain rule. Note that the function `h₂` is a function on an algebra. If you are looking for the chain rule with `h₂` taking values in a vector space, use `HasDerivAt.scomp`. -/ nonrec theorem HasDerivAt.comp (hh₂ : HasDerivAt h₂ h₂' (h x)) (hh : HasDerivAt h h' x) : HasDerivAt (h₂ ∘ h) (h₂' * h') x := hh₂.comp x hh hh.continuousAt /-- The chain rule. Note that the function `h₂` is a function on an algebra. If you are looking for the chain rule with `h₂` taking values in a vector space, use `HasDerivAt.scomp_of_eq`. -/ theorem HasDerivAt.comp_of_eq (hh₂ : HasDerivAt h₂ h₂' y) (hh : HasDerivAt h h' x) (hy : y = h x) : HasDerivAt (h₂ ∘ h) (h₂' * h') x := by rw [hy] at hh₂; exact hh₂.comp x hh theorem HasStrictDerivAt.comp (hh₂ : HasStrictDerivAt h₂ h₂' (h x)) (hh : HasStrictDerivAt h h' x) : HasStrictDerivAt (h₂ ∘ h) (h₂' * h') x := by rw [mul_comm] exact hh₂.scomp x hh theorem HasStrictDerivAt.comp_of_eq (hh₂ : HasStrictDerivAt h₂ h₂' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) : HasStrictDerivAt (h₂ ∘ h) (h₂' * h') x := by rw [hy] at hh₂; exact hh₂.comp x hh theorem HasDerivAt.comp_hasDerivWithinAt (hh₂ : HasDerivAt h₂ h₂' (h x)) (hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := hh₂.hasDerivWithinAt.comp x hh (mapsTo_univ _ _) theorem HasDerivAt.comp_hasDerivWithinAt_of_eq (hh₂ : HasDerivAt h₂ h₂' y) (hh : HasDerivWithinAt h h' s x) (hy : y = h x) : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by rw [hy] at hh₂; exact hh₂.comp_hasDerivWithinAt x hh theorem derivWithin_comp (hh₂ : DifferentiableWithinAt 𝕜' h₂ s' (h x)) (hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s s') : derivWithin (h₂ ∘ h) s x = derivWithin h₂ s' (h x) * derivWithin h s x := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (hh₂.hasDerivWithinAt.comp x hh.hasDerivWithinAt hs).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] @[deprecated (since := "2024-10-31")] alias derivWithin.comp := derivWithin_comp theorem derivWithin_comp_of_eq (hh₂ : DifferentiableWithinAt 𝕜' h₂ s' y) (hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s s') (hy : h x = y) : derivWithin (h₂ ∘ h) s x = derivWithin h₂ s' (h x) * derivWithin h s x := by subst hy; exact derivWithin_comp x hh₂ hh hs @[deprecated (since := "2024-10-31")] alias derivWithin.comp_of_eq := derivWithin_comp_of_eq theorem deriv_comp (hh₂ : DifferentiableAt 𝕜' h₂ (h x)) (hh : DifferentiableAt 𝕜 h x) : deriv (h₂ ∘ h) x = deriv h₂ (h x) * deriv h x := (hh₂.hasDerivAt.comp x hh.hasDerivAt).deriv @[deprecated (since := "2024-10-31")] alias deriv.comp := deriv_comp theorem deriv_comp_of_eq (hh₂ : DifferentiableAt 𝕜' h₂ y) (hh : DifferentiableAt 𝕜 h x) (hy : h x = y) : deriv (h₂ ∘ h) x = deriv h₂ (h x) * deriv h x := by subst hy; exact deriv_comp x hh₂ hh @[deprecated (since := "2024-10-31")] alias deriv.comp_of_eq := deriv_comp_of_eq protected nonrec theorem HasDerivAtFilter.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasDerivAtFilter f f' x L) (hL : Tendsto f L L) (hx : f x = x) (n : ℕ) : HasDerivAtFilter f^[n] (f' ^ n) x L := by have := hf.iterate hL hx n rwa [ContinuousLinearMap.smulRight_one_pow] at this protected nonrec theorem HasDerivAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasDerivAt f f' x) (hx : f x = x) (n : ℕ) : HasDerivAt f^[n] (f' ^ n) x := hf.iterate _ (have := hf.tendsto_nhds le_rfl; by rwa [hx] at this) hx n protected theorem HasDerivWithinAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasDerivWithinAt f f' s x) (hx : f x = x) (hs : MapsTo f s s) (n : ℕ) : HasDerivWithinAt f^[n] (f' ^ n) s x := by have := HasFDerivWithinAt.iterate hf hx hs n rwa [ContinuousLinearMap.smulRight_one_pow] at this protected nonrec theorem HasStrictDerivAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasStrictDerivAt f f' x) (hx : f x = x) (n : ℕ) : HasStrictDerivAt f^[n] (f' ^ n) x := by have := hf.iterate hx n rwa [ContinuousLinearMap.smulRight_one_pow] at this end Composition section CompositionVector /-! ### Derivative of the composition of a function between vector spaces and a function on `𝕜` -/ open ContinuousLinearMap
variable {l : F → E} {l' : F →L[𝕜] E} {y : F} variable (x) /-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative within a set equal to the Fréchet derivative of `l` applied to the derivative of `f`. -/
Mathlib/Analysis/Calculus/Deriv/Comp.lean
328
332
/- 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.Algebra.Order.Module.Defs import Mathlib.Data.DFinsupp.Module /-! # Pointwise order on finitely supported dependent functions This file lifts order structures on the `α i` to `Π₀ i, α i`. ## Main declarations * `DFinsupp.orderEmbeddingToFun`: The order embedding from finitely supported dependent functions to functions. -/ open Finset variable {ι : Type*} {α : ι → Type*} namespace DFinsupp /-! ### Order structures -/ section Zero variable [∀ i, Zero (α i)] section LE variable [∀ i, LE (α i)] {f g : Π₀ i, α i} instance : LE (Π₀ i, α i) := ⟨fun f g ↦ ∀ i, f i ≤ g i⟩ lemma le_def : f ≤ g ↔ ∀ i, f i ≤ g i := Iff.rfl @[simp, norm_cast] lemma coe_le_coe : ⇑f ≤ g ↔ f ≤ g := Iff.rfl /-- The order on `DFinsupp`s over a partial order embeds into the order on functions -/ def orderEmbeddingToFun : (Π₀ i, α i) ↪o ∀ i, α i where toFun := DFunLike.coe inj' := DFunLike.coe_injective map_rel_iff' := Iff.rfl @[simp, norm_cast] lemma coe_orderEmbeddingToFun : ⇑(orderEmbeddingToFun (α := α)) = DFunLike.coe := rfl theorem orderEmbeddingToFun_apply {f : Π₀ i, α i} {i : ι} : orderEmbeddingToFun f i = f i := rfl end LE section Preorder variable [∀ i, Preorder (α i)] {f g : Π₀ i, α i} instance : Preorder (Π₀ i, α i) := { (inferInstance : LE (DFinsupp α)) with le_refl := fun _ _ ↦ le_rfl le_trans := fun _ _ _ hfg hgh i ↦ (hfg i).trans (hgh i) } lemma lt_def : f < g ↔ f ≤ g ∧ ∃ i, f i < g i := Pi.lt_def @[simp, norm_cast] lemma coe_lt_coe : ⇑f < g ↔ f < g := Iff.rfl lemma coe_mono : Monotone ((⇑) : (Π₀ i, α i) → ∀ i, α i) := fun _ _ ↦ id lemma coe_strictMono : Monotone ((⇑) : (Π₀ i, α i) → ∀ i, α i) := fun _ _ ↦ id end Preorder instance [∀ i, PartialOrder (α i)] : PartialOrder (Π₀ i, α i) := { (inferInstance : Preorder (DFinsupp α)) with le_antisymm := fun _ _ hfg hgf ↦ ext fun i ↦ (hfg i).antisymm (hgf i) } instance [∀ i, SemilatticeInf (α i)] : SemilatticeInf (Π₀ i, α i) := { (inferInstance : PartialOrder (DFinsupp α)) with inf := zipWith (fun _ ↦ (· ⊓ ·)) fun _ ↦ inf_idem _ inf_le_left := fun _ _ _ ↦ inf_le_left inf_le_right := fun _ _ _ ↦ inf_le_right le_inf := fun _ _ _ hf hg i ↦ le_inf (hf i) (hg i) } @[simp, norm_cast] lemma coe_inf [∀ i, SemilatticeInf (α i)] (f g : Π₀ i, α i) : f ⊓ g = ⇑f ⊓ g := rfl theorem inf_apply [∀ i, SemilatticeInf (α i)] (f g : Π₀ i, α i) (i : ι) : (f ⊓ g) i = f i ⊓ g i := zipWith_apply _ _ _ _ _ instance [∀ i, SemilatticeSup (α i)] : SemilatticeSup (Π₀ i, α i) := { (inferInstance : PartialOrder (DFinsupp α)) with sup := zipWith (fun _ ↦ (· ⊔ ·)) fun _ ↦ sup_idem _ le_sup_left := fun _ _ _ ↦ le_sup_left le_sup_right := fun _ _ _ ↦ le_sup_right sup_le := fun _ _ _ hf hg i ↦ sup_le (hf i) (hg i) } @[simp, norm_cast] lemma coe_sup [∀ i, SemilatticeSup (α i)] (f g : Π₀ i, α i) : f ⊔ g = ⇑f ⊔ g := rfl theorem sup_apply [∀ i, SemilatticeSup (α i)] (f g : Π₀ i, α i) (i : ι) : (f ⊔ g) i = f i ⊔ g i := zipWith_apply _ _ _ _ _ section Lattice variable [∀ i, Lattice (α i)] (f g : Π₀ i, α i) instance lattice : Lattice (Π₀ i, α i) := { (inferInstance : SemilatticeInf (DFinsupp α)), (inferInstance : SemilatticeSup (DFinsupp α)) with } variable [DecidableEq ι] [∀ (i) (x : α i), Decidable (x ≠ 0)] theorem support_inf_union_support_sup : (f ⊓ g).support ∪ (f ⊔ g).support = f.support ∪ g.support := coe_injective <| compl_injective <| by ext; simp [inf_eq_and_sup_eq_iff] theorem support_sup_union_support_inf : (f ⊔ g).support ∪ (f ⊓ g).support = f.support ∪ g.support := (union_comm _ _).trans <| support_inf_union_support_sup _ _ end Lattice end Zero /-! ### Algebraic order structures -/ instance (α : ι → Type*) [∀ i, AddCommMonoid (α i)] [∀ i, PartialOrder (α i)] [∀ i, IsOrderedAddMonoid (α i)] : IsOrderedAddMonoid (Π₀ i, α i) := { add_le_add_left := fun _ _ h c i ↦ add_le_add_left (h i) (c i) } instance (α : ι → Type*) [∀ i, AddCommMonoid (α i)] [∀ i, PartialOrder (α i)] [∀ i, IsOrderedCancelAddMonoid (α i)] : IsOrderedCancelAddMonoid (Π₀ i, α i) := { le_of_add_le_add_left := fun _ _ _ H i ↦ le_of_add_le_add_left (H i) } instance [∀ i, AddCommMonoid (α i)] [∀ i, PartialOrder (α i)] [∀ i, AddLeftReflectLE (α i)] : AddLeftReflectLE (Π₀ i, α i) := ⟨fun _ _ _ H i ↦ le_of_add_le_add_left (H i)⟩ section Module variable {α : Type*} {β : ι → Type*} [Semiring α] [Preorder α] [∀ i, AddCommMonoid (β i)] [∀ i, Preorder (β i)] [∀ i, Module α (β i)] instance instPosSMulMono [∀ i, PosSMulMono α (β i)] : PosSMulMono α (Π₀ i, β i) := PosSMulMono.lift _ coe_le_coe coe_smul instance instSMulPosMono [∀ i, SMulPosMono α (β i)] : SMulPosMono α (Π₀ i, β i) := SMulPosMono.lift _ coe_le_coe coe_smul coe_zero instance instPosSMulReflectLE [∀ i, PosSMulReflectLE α (β i)] : PosSMulReflectLE α (Π₀ i, β i) := PosSMulReflectLE.lift _ coe_le_coe coe_smul instance instSMulPosReflectLE [∀ i, SMulPosReflectLE α (β i)] : SMulPosReflectLE α (Π₀ i, β i) := SMulPosReflectLE.lift _ coe_le_coe coe_smul coe_zero end Module section Module variable {α : Type*} {β : ι → Type*} [Semiring α] [PartialOrder α] [∀ i, AddCommMonoid (β i)] [∀ i, PartialOrder (β i)] [∀ i, Module α (β i)] instance instPosSMulStrictMono [∀ i, PosSMulStrictMono α (β i)] : PosSMulStrictMono α (Π₀ i, β i) := PosSMulStrictMono.lift _ coe_le_coe coe_smul instance instSMulPosStrictMono [∀ i, SMulPosStrictMono α (β i)] : SMulPosStrictMono α (Π₀ i, β i) := SMulPosStrictMono.lift _ coe_le_coe coe_smul coe_zero -- Note: There is no interesting instance for `PosSMulReflectLT α (Π₀ i, β i)` that's not already -- implied by the other instances instance instSMulPosReflectLT [∀ i, SMulPosReflectLT α (β i)] : SMulPosReflectLT α (Π₀ i, β i) := SMulPosReflectLT.lift _ coe_le_coe coe_smul coe_zero end Module section PartialOrder variable (α) [∀ i, AddCommMonoid (α i)] [∀ i, PartialOrder (α i)] [∀ i, CanonicallyOrderedAdd (α i)] instance : OrderBot (Π₀ i, α i) where bot := 0 bot_le := by simp only [le_def, coe_zero, Pi.zero_apply, imp_true_iff, zero_le] variable {α} protected theorem bot_eq_zero : (⊥ : Π₀ i, α i) = 0 := rfl @[simp] theorem add_eq_zero_iff (f g : Π₀ i, α i) : f + g = 0 ↔ f = 0 ∧ g = 0 := by simp [DFunLike.ext_iff, forall_and] section LE variable [DecidableEq ι] section variable [∀ (i) (x : α i), Decidable (x ≠ 0)] {f g : Π₀ i, α i} {s : Finset ι} theorem le_iff' (hf : f.support ⊆ s) : f ≤ g ↔ ∀ i ∈ s, f i ≤ g i := ⟨fun h s _ ↦ h s, fun h s ↦ if H : s ∈ f.support then h s (hf H) else (not_mem_support_iff.1 H).symm ▸ zero_le (g s)⟩ theorem le_iff : f ≤ g ↔ ∀ i ∈ f.support, f i ≤ g i := le_iff' <| Subset.refl _
lemma support_monotone : Monotone (support (ι := ι) (β := α)) :=
Mathlib/Data/DFinsupp/Order.lean
205
206
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Homotopy import Mathlib.Algebra.Ring.NegOnePow import Mathlib.Algebra.Category.Grp.Preadditive import Mathlib.Tactic.Linarith import Mathlib.CategoryTheory.Linear.LinearFunctor /-! The cochain complex of homomorphisms between cochain complexes If `F` and `G` are cochain complexes (indexed by `ℤ`) in a preadditive category, there is a cochain complex of abelian groups whose `0`-cocycles identify to morphisms `F ⟶ G`. Informally, in degree `n`, this complex shall consist of cochains of degree `n` from `F` to `G`, i.e. arbitrary families for morphisms `F.X p ⟶ G.X (p + n)`. This complex shall be denoted `HomComplex F G`. In order to avoid type theoretic issues, a cochain of degree `n : ℤ` (i.e. a term of type of `Cochain F G n`) shall be defined here as the data of a morphism `F.X p ⟶ G.X q` for all triplets `⟨p, q, hpq⟩` where `p` and `q` are integers and `hpq : p + n = q`. If `α : Cochain F G n`, we shall define `α.v p q hpq : F.X p ⟶ G.X q`. We follow the signs conventions appearing in the introduction of [Brian Conrad's book *Grothendieck duality and base change*][conrad2000]. ## References * [Brian Conrad, Grothendieck duality and base change][conrad2000] -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category Limits Preadditive universe v u variable {C : Type u} [Category.{v} C] [Preadditive C] {R : Type*} [Ring R] [Linear R C] namespace CochainComplex variable {F G K L : CochainComplex C ℤ} (n m : ℤ) namespace HomComplex /-- A term of type `HomComplex.Triplet n` consists of two integers `p` and `q` such that `p + n = q`. (This type is introduced so that the instance `AddCommGroup (Cochain F G n)` defined below can be found automatically.) -/ structure Triplet (n : ℤ) where /-- a first integer -/ p : ℤ /-- a second integer -/ q : ℤ /-- the condition on the two integers -/ hpq : p + n = q variable (F G) /-- A cochain of degree `n : ℤ` between to cochain complexes `F` and `G` consists of a family of morphisms `F.X p ⟶ G.X q` whenever `p + n = q`, i.e. for all triplets in `HomComplex.Triplet n`. -/ def Cochain := ∀ (T : Triplet n), F.X T.p ⟶ G.X T.q instance : AddCommGroup (Cochain F G n) := by dsimp only [Cochain] infer_instance instance : Module R (Cochain F G n) := by dsimp only [Cochain] infer_instance namespace Cochain variable {F G n} /-- A practical constructor for cochains. -/ def mk (v : ∀ (p q : ℤ) (_ : p + n = q), F.X p ⟶ G.X q) : Cochain F G n := fun ⟨p, q, hpq⟩ => v p q hpq /-- The value of a cochain on a triplet `⟨p, q, hpq⟩`. -/ def v (γ : Cochain F G n) (p q : ℤ) (hpq : p + n = q) : F.X p ⟶ G.X q := γ ⟨p, q, hpq⟩ @[simp] lemma mk_v (v : ∀ (p q : ℤ) (_ : p + n = q), F.X p ⟶ G.X q) (p q : ℤ) (hpq : p + n = q) : (Cochain.mk v).v p q hpq = v p q hpq := rfl lemma congr_v {z₁ z₂ : Cochain F G n} (h : z₁ = z₂) (p q : ℤ) (hpq : p + n = q) : z₁.v p q hpq = z₂.v p q hpq := by subst h; rfl @[ext] lemma ext (z₁ z₂ : Cochain F G n) (h : ∀ (p q hpq), z₁.v p q hpq = z₂.v p q hpq) : z₁ = z₂ := by funext ⟨p, q, hpq⟩ apply h @[ext 1100] lemma ext₀ (z₁ z₂ : Cochain F G 0) (h : ∀ (p : ℤ), z₁.v p p (add_zero p) = z₂.v p p (add_zero p)) : z₁ = z₂ := by ext p q hpq obtain rfl : q = p := by rw [← hpq, add_zero] exact h q @[simp] lemma zero_v {n : ℤ} (p q : ℤ) (hpq : p + n = q) : (0 : Cochain F G n).v p q hpq = 0 := rfl @[simp] lemma add_v {n : ℤ} (z₁ z₂ : Cochain F G n) (p q : ℤ) (hpq : p + n = q) : (z₁ + z₂).v p q hpq = z₁.v p q hpq + z₂.v p q hpq := rfl @[simp] lemma sub_v {n : ℤ} (z₁ z₂ : Cochain F G n) (p q : ℤ) (hpq : p + n = q) : (z₁ - z₂).v p q hpq = z₁.v p q hpq - z₂.v p q hpq := rfl @[simp] lemma neg_v {n : ℤ} (z : Cochain F G n) (p q : ℤ) (hpq : p + n = q) : (-z).v p q hpq = - (z.v p q hpq) := rfl @[simp] lemma smul_v {n : ℤ} (k : R) (z : Cochain F G n) (p q : ℤ) (hpq : p + n = q) : (k • z).v p q hpq = k • (z.v p q hpq) := rfl @[simp] lemma units_smul_v {n : ℤ} (k : Rˣ) (z : Cochain F G n) (p q : ℤ) (hpq : p + n = q) : (k • z).v p q hpq = k • (z.v p q hpq) := rfl /-- A cochain of degree `0` from `F` to `G` can be constructed from a family of morphisms `F.X p ⟶ G.X p` for all `p : ℤ`. -/ def ofHoms (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) : Cochain F G 0 := Cochain.mk (fun p q hpq => ψ p ≫ eqToHom (by rw [← hpq, add_zero])) @[simp] lemma ofHoms_v (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) (p : ℤ) : (ofHoms ψ).v p p (add_zero p) = ψ p := by
simp only [ofHoms, mk_v, eqToHom_refl, comp_id]
Mathlib/Algebra/Homology/HomotopyCategory/HomComplex.lean
138
139
/- Copyright (c) 2021 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, David Kurniadi Angdinata -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.CubicDiscriminant import Mathlib.RingTheory.Nilpotent.Defs import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.LinearCombination /-! # Weierstrass equations of elliptic curves This file defines the structure of an elliptic curve as a nonsingular Weierstrass curve given by a Weierstrass equation, which is mathematically accurate in many cases but also good for computation. ## Mathematical background Let `S` be a scheme. The actual category of elliptic curves over `S` is a large category, whose objects are schemes `E` equipped with a map `E → S`, a section `S → E`, and some axioms (the map is smooth and proper and the fibres are geometrically-connected one-dimensional group varieties). In the special case where `S` is the spectrum of some commutative ring `R` whose Picard group is zero (this includes all fields, all PIDs, and many other commutative rings) it can be shown (using a lot of algebro-geometric machinery) that every elliptic curve `E` is a projective plane cubic isomorphic to a Weierstrass curve given by the equation `Y² + a₁XY + a₃Y = X³ + a₂X² + a₄X + a₆` for some `aᵢ` in `R`, and such that a certain quantity called the discriminant of `E` is a unit in `R`. If `R` is a field, this quantity divides the discriminant of a cubic polynomial whose roots over a splitting field of `R` are precisely the `X`-coordinates of the non-zero 2-torsion points of `E`. ## Main definitions * `WeierstrassCurve`: a Weierstrass curve over a commutative ring. * `WeierstrassCurve.Δ`: the discriminant of a Weierstrass curve. * `WeierstrassCurve.map`: the Weierstrass curve mapped over a ring homomorphism. * `WeierstrassCurve.twoTorsionPolynomial`: the 2-torsion polynomial of a Weierstrass curve. * `WeierstrassCurve.IsElliptic`: typeclass asserting that a Weierstrass curve is an elliptic curve. * `WeierstrassCurve.j`: the j-invariant of an elliptic curve. ## Main statements * `WeierstrassCurve.twoTorsionPolynomial_disc`: the discriminant of a Weierstrass curve is a constant factor of the cubic discriminant of its 2-torsion polynomial. ## Implementation notes The definition of elliptic curves in this file makes sense for all commutative rings `R`, but it only gives a type which can be beefed up to a category which is equivalent to the category of elliptic curves over the spectrum `Spec(R)` of `R` in the case that `R` has trivial Picard group `Pic(R)` or, slightly more generally, when its 12-torsion is trivial. The issue is that for a general ring `R`, there might be elliptic curves over `Spec(R)` in the sense of algebraic geometry which are not globally defined by a cubic equation valid over the entire base. ## References * [N Katz and B Mazur, *Arithmetic Moduli of Elliptic Curves*][katz_mazur] * [P Deligne, *Courbes Elliptiques: Formulaire (d'après J. Tate)*][deligne_formulaire] * [J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009] ## Tags elliptic curve, weierstrass equation, j invariant -/ local macro "map_simp" : tactic => `(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow]) universe s u v w /-! ## Weierstrass curves -/ /-- A Weierstrass curve `Y² + a₁XY + a₃Y = X³ + a₂X² + a₄X + a₆` with parameters `aᵢ`. -/ @[ext] structure WeierstrassCurve (R : Type u) where /-- The `a₁` coefficient of a Weierstrass curve. -/ a₁ : R /-- The `a₂` coefficient of a Weierstrass curve. -/ a₂ : R /-- The `a₃` coefficient of a Weierstrass curve. -/ a₃ : R /-- The `a₄` coefficient of a Weierstrass curve. -/ a₄ : R /-- The `a₆` coefficient of a Weierstrass curve. -/ a₆ : R namespace WeierstrassCurve instance {R : Type u} [Inhabited R] : Inhabited <| WeierstrassCurve R := ⟨⟨default, default, default, default, default⟩⟩ variable {R : Type u} [CommRing R] (W : WeierstrassCurve R) section Quantity /-! ### Standard quantities -/ /-- The `b₂` coefficient of a Weierstrass curve. -/ def b₂ : R := W.a₁ ^ 2 + 4 * W.a₂ /-- The `b₄` coefficient of a Weierstrass curve. -/ def b₄ : R := 2 * W.a₄ + W.a₁ * W.a₃ /-- The `b₆` coefficient of a Weierstrass curve. -/ def b₆ : R := W.a₃ ^ 2 + 4 * W.a₆ /-- The `b₈` coefficient of a Weierstrass curve. -/ def b₈ : R := W.a₁ ^ 2 * W.a₆ + 4 * W.a₂ * W.a₆ - W.a₁ * W.a₃ * W.a₄ + W.a₂ * W.a₃ ^ 2 - W.a₄ ^ 2 lemma b_relation : 4 * W.b₈ = W.b₂ * W.b₆ - W.b₄ ^ 2 := by simp only [b₂, b₄, b₆, b₈] ring1 /-- The `c₄` coefficient of a Weierstrass curve. -/ def c₄ : R := W.b₂ ^ 2 - 24 * W.b₄ /-- The `c₆` coefficient of a Weierstrass curve. -/ def c₆ : R := -W.b₂ ^ 3 + 36 * W.b₂ * W.b₄ - 216 * W.b₆ /-- The discriminant `Δ` of a Weierstrass curve. If `R` is a field, then this polynomial vanishes if and only if the cubic curve cut out by this equation is singular. Sometimes only defined up to sign in the literature; we choose the sign used by the LMFDB. For more discussion, see [the LMFDB page on discriminants](https://www.lmfdb.org/knowledge/show/ec.discriminant). -/ def Δ : R := -W.b₂ ^ 2 * W.b₈ - 8 * W.b₄ ^ 3 - 27 * W.b₆ ^ 2 + 9 * W.b₂ * W.b₄ * W.b₆ lemma c_relation : 1728 * W.Δ = W.c₄ ^ 3 - W.c₆ ^ 2 := by simp only [b₂, b₄, b₆, b₈, c₄, c₆, Δ] ring1 section CharTwo
variable [CharP R 2]
Mathlib/AlgebraicGeometry/EllipticCurve/Weierstrass.lean
137
139
/- 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.ModEq import Mathlib.Data.Nat.Prime.Basic import Mathlib.NumberTheory.Zsqrtd.Basic /-! # Pell's equation and Matiyasevic's theorem This file solves Pell's equation, i.e. integer solutions to `x ^ 2 - d * y ^ 2 = 1` *in the special case that `d = a ^ 2 - 1`*. This is then applied to prove Matiyasevic's theorem that the power function is Diophantine, which is the last key ingredient in the solution to Hilbert's tenth problem. For the definition of Diophantine function, see `NumberTheory.Dioph`. For results on Pell's equation for arbitrary (positive, non-square) `d`, see `NumberTheory.Pell`. ## Main definition * `pell` is a function assigning to a natural number `n` the `n`-th solution to Pell's equation constructed recursively from the initial solution `(0, 1)`. ## Main statements * `eq_pell` shows that every solution to Pell's equation is recursively obtained using `pell` * `matiyasevic` shows that a certain system of Diophantine equations has a solution if and only if the first variable is the `x`-component in a solution to Pell's equation - the key step towards Hilbert's tenth problem in Davis' version of Matiyasevic's theorem. * `eq_pow_of_pell` shows that the power function is Diophantine. ## Implementation notes The proof of Matiyasevic's theorem doesn't follow Matiyasevic's original account of using Fibonacci numbers but instead Davis' variant of using solutions to Pell's equation. ## References * [M. Carneiro, _A Lean formalization of Matiyasevič's theorem_][carneiro2018matiyasevic] * [M. Davis, _Hilbert's tenth problem is unsolvable_][MR317916] ## Tags Pell's equation, Matiyasevic's theorem, Hilbert's tenth problem -/ namespace Pell open Nat section variable {d : ℤ} /-- The property of being a solution to the Pell equation, expressed as a property of elements of `ℤ√d`. -/ def IsPell : ℤ√d → Prop | ⟨x, y⟩ => x * x - d * y * y = 1 theorem isPell_norm : ∀ {b : ℤ√d}, IsPell b ↔ b * star b = 1 | ⟨x, y⟩ => by simp [Zsqrtd.ext_iff, IsPell, mul_comm]; ring_nf theorem isPell_iff_mem_unitary : ∀ {b : ℤ√d}, IsPell b ↔ b ∈ unitary (ℤ√d) | ⟨x, y⟩ => by rw [unitary.mem_iff, isPell_norm, mul_comm (star _), and_self_iff] theorem isPell_mul {b c : ℤ√d} (hb : IsPell b) (hc : IsPell c) : IsPell (b * c) := isPell_norm.2 (by simp [mul_comm, mul_left_comm c, mul_assoc, star_mul, isPell_norm.1 hb, isPell_norm.1 hc]) theorem isPell_star : ∀ {b : ℤ√d}, IsPell b ↔ IsPell (star b) | ⟨x, y⟩ => by simp [IsPell, Zsqrtd.star_mk] end section variable {a : ℕ} (a1 : 1 < a) private def d (_a1 : 1 < a) := a * a - 1 @[simp] theorem d_pos : 0 < d a1 := tsub_pos_of_lt (mul_lt_mul a1 (le_of_lt a1) (by decide) (Nat.zero_le _) : 1 * 1 < a * a) -- TODO(lint): Fix double namespace issue /-- The Pell sequences, i.e. the sequence of integer solutions to `x ^ 2 - d * y ^ 2 = 1`, where `d = a ^ 2 - 1`, defined together in mutual recursion. -/ --@[nolint dup_namespace] def pell : ℕ → ℕ × ℕ | 0 => (1, 0) | n+1 => ((pell n).1 * a + d a1 * (pell n).2, (pell n).1 + (pell n).2 * a) /-- The Pell `x` sequence. -/ def xn (n : ℕ) : ℕ := (pell a1 n).1 /-- The Pell `y` sequence. -/ def yn (n : ℕ) : ℕ := (pell a1 n).2 @[simp] theorem pell_val (n : ℕ) : pell a1 n = (xn a1 n, yn a1 n) := show pell a1 n = ((pell a1 n).1, (pell a1 n).2) from match pell a1 n with | (_, _) => rfl @[simp] theorem xn_zero : xn a1 0 = 1 := rfl @[simp] theorem yn_zero : yn a1 0 = 0 := rfl @[simp] theorem xn_succ (n : ℕ) : xn a1 (n + 1) = xn a1 n * a + d a1 * yn a1 n := rfl @[simp] theorem yn_succ (n : ℕ) : yn a1 (n + 1) = xn a1 n + yn a1 n * a := rfl theorem xn_one : xn a1 1 = a := by simp theorem yn_one : yn a1 1 = 1 := by simp /-- The Pell `x` sequence, considered as an integer sequence. -/ def xz (n : ℕ) : ℤ := xn a1 n /-- The Pell `y` sequence, considered as an integer sequence. -/ def yz (n : ℕ) : ℤ := yn a1 n section /-- The element `a` such that `d = a ^ 2 - 1`, considered as an integer. -/ def az (a : ℕ) : ℤ := a end include a1 in theorem asq_pos : 0 < a * a := le_trans (le_of_lt a1) (by have := @Nat.mul_le_mul_left 1 a a (le_of_lt a1); rwa [mul_one] at this) theorem dz_val : ↑(d a1) = az a * az a - 1 := have : 1 ≤ a * a := asq_pos a1 by rw [Pell.d, Int.ofNat_sub this]; rfl @[simp] theorem xz_succ (n : ℕ) : (xz a1 (n + 1)) = xz a1 n * az a + d a1 * yz a1 n := rfl @[simp] theorem yz_succ (n : ℕ) : yz a1 (n + 1) = xz a1 n + yz a1 n * az a := rfl /-- The Pell sequence can also be viewed as an element of `ℤ√d` -/ def pellZd (n : ℕ) : ℤ√(d a1) := ⟨xn a1 n, yn a1 n⟩ @[simp] theorem pellZd_re (n : ℕ) : (pellZd a1 n).re = xn a1 n := rfl @[simp] theorem pellZd_im (n : ℕ) : (pellZd a1 n).im = yn a1 n := rfl theorem isPell_nat {x y : ℕ} : IsPell (⟨x, y⟩ : ℤ√(d a1)) ↔ x * x - d a1 * y * y = 1 := ⟨fun h => (Nat.cast_inj (R := ℤ)).1 (by rw [Int.ofNat_sub (Int.le_of_ofNat_le_ofNat <| Int.le.intro_sub _ h)]; exact h), fun h => show ((x * x : ℕ) - (d a1 * y * y : ℕ) : ℤ) = 1 by rw [← Int.ofNat_sub <| le_of_lt <| Nat.lt_of_sub_eq_succ h, h]; rfl⟩ @[simp] theorem pellZd_succ (n : ℕ) : pellZd a1 (n + 1) = pellZd a1 n * ⟨a, 1⟩ := by ext <;> simp theorem isPell_one : IsPell (⟨a, 1⟩ : ℤ√(d a1)) := show az a * az a - d a1 * 1 * 1 = 1 by simp [dz_val] theorem isPell_pellZd : ∀ n : ℕ, IsPell (pellZd a1 n) | 0 => rfl | n + 1 => by let o := isPell_one a1 simpa using Pell.isPell_mul (isPell_pellZd n) o @[simp] theorem pell_eqz (n : ℕ) : xz a1 n * xz a1 n - d a1 * yz a1 n * yz a1 n = 1 := isPell_pellZd a1 n @[simp] theorem pell_eq (n : ℕ) : xn a1 n * xn a1 n - d a1 * yn a1 n * yn a1 n = 1 := let pn := pell_eqz a1 n have h : (↑(xn a1 n * xn a1 n) : ℤ) - ↑(d a1 * yn a1 n * yn a1 n) = 1 := by repeat' rw [Int.natCast_mul]; exact pn have hl : d a1 * yn a1 n * yn a1 n ≤ xn a1 n * xn a1 n := Nat.cast_le.1 <| Int.le.intro _ <| add_eq_of_eq_sub' <| Eq.symm h (Nat.cast_inj (R := ℤ)).1 (by rw [Int.ofNat_sub hl]; exact h) instance dnsq : Zsqrtd.Nonsquare (d a1) := ⟨fun n h => have : n * n + 1 = a * a := by rw [← h]; exact Nat.succ_pred_eq_of_pos (asq_pos a1) have na : n < a := Nat.mul_self_lt_mul_self_iff.1 (by rw [← this]; exact Nat.lt_succ_self _) have : (n + 1) * (n + 1) ≤ n * n + 1 := by rw [this]; exact Nat.mul_self_le_mul_self na have : n + n ≤ 0 := @Nat.le_of_add_le_add_right _ (n * n + 1) _ (by ring_nf at this ⊢; assumption) Nat.ne_of_gt (d_pos a1) <| by rwa [Nat.eq_zero_of_le_zero ((Nat.le_add_left _ _).trans this)] at h⟩ theorem xn_ge_a_pow : ∀ n : ℕ, a ^ n ≤ xn a1 n | 0 => le_refl 1 | n + 1 => by simp only [_root_.pow_succ, xn_succ] exact le_trans (Nat.mul_le_mul_right _ (xn_ge_a_pow n)) (Nat.le_add_right _ _) theorem n_lt_xn (n) : n < xn a1 n := lt_of_lt_of_le (Nat.lt_pow_self a1) (xn_ge_a_pow a1 n) theorem x_pos (n) : 0 < xn a1 n := lt_of_le_of_lt (Nat.zero_le n) (n_lt_xn a1 n) theorem eq_pell_lem : ∀ (n) (b : ℤ√(d a1)), 1 ≤ b → IsPell b → b ≤ pellZd a1 n → ∃ n, b = pellZd a1 n | 0, _ => fun h1 _ hl => ⟨0, @Zsqrtd.le_antisymm _ (dnsq a1) _ _ hl h1⟩ | n + 1, b => fun h1 hp h => have a1p : (0 : ℤ√(d a1)) ≤ ⟨a, 1⟩ := trivial have am1p : (0 : ℤ√(d a1)) ≤ ⟨a, -1⟩ := show (_ : Nat) ≤ _ by simp; exact Nat.pred_le _ have a1m : (⟨a, 1⟩ * ⟨a, -1⟩ : ℤ√(d a1)) = 1 := isPell_norm.1 (isPell_one a1) if ha : (⟨↑a, 1⟩ : ℤ√(d a1)) ≤ b then let ⟨m, e⟩ := eq_pell_lem n (b * ⟨a, -1⟩) (by rw [← a1m]; exact mul_le_mul_of_nonneg_right ha am1p) (isPell_mul hp (isPell_star.1 (isPell_one a1))) (by have t := mul_le_mul_of_nonneg_right h am1p rwa [pellZd_succ, mul_assoc, a1m, mul_one] at t) ⟨m + 1, by rw [show b = b * ⟨a, -1⟩ * ⟨a, 1⟩ by rw [mul_assoc, Eq.trans (mul_comm _ _) a1m]; simp, pellZd_succ, e]⟩ else suffices ¬1 < b from ⟨0, show b = 1 from (Or.resolve_left (lt_or_eq_of_le h1) this).symm⟩ fun h1l => by obtain ⟨x, y⟩ := b exact by have bm : (_ * ⟨_, _⟩ : ℤ√d a1) = 1 := Pell.isPell_norm.1 hp have y0l : (0 : ℤ√d a1) < ⟨x - x, y - -y⟩ := sub_lt_sub h1l fun hn : (1 : ℤ√d a1) ≤ ⟨x, -y⟩ => by have t := mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1) rw [bm, mul_one] at t exact h1l t have yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩ := show (⟨x, y⟩ - ⟨x, -y⟩ : ℤ√d a1) < ⟨a, 1⟩ - ⟨a, -1⟩ from sub_lt_sub ha fun hn : (⟨x, -y⟩ : ℤ√d a1) ≤ ⟨a, -1⟩ => by have t := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1)) a1p rw [bm, one_mul, mul_assoc, Eq.trans (mul_comm _ _) a1m, mul_one] at t exact ha t simp only [sub_self, sub_neg_eq_add] at y0l; simp only [Zsqrtd.neg_re, add_neg_cancel, Zsqrtd.neg_im, neg_neg] at yl2 exact match y, y0l, (yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩) with | 0, y0l, _ => y0l (le_refl 0) | (y + 1 : ℕ), _, yl2 => yl2 (Zsqrtd.le_of_le_le (by simp [sub_eq_add_neg]) (let t := Int.ofNat_le_ofNat_of_le (Nat.succ_pos y) add_le_add t t)) | Int.negSucc _, y0l, _ => y0l trivial theorem eq_pellZd (b : ℤ√(d a1)) (b1 : 1 ≤ b) (hp : IsPell b) : ∃ n, b = pellZd a1 n := let ⟨n, h⟩ := @Zsqrtd.le_arch (d a1) b eq_pell_lem a1 n b b1 hp <| h.trans <| by rw [Zsqrtd.natCast_val] exact Zsqrtd.le_of_le_le (Int.ofNat_le_ofNat_of_le <| le_of_lt <| n_lt_xn _ _) (Int.ofNat_zero_le _) /-- Every solution to **Pell's equation** is recursively obtained from the initial solution `(1,0)` using the recursion `pell`. -/ theorem eq_pell {x y : ℕ} (hp : x * x - d a1 * y * y = 1) : ∃ n, x = xn a1 n ∧ y = yn a1 n := have : (1 : ℤ√(d a1)) ≤ ⟨x, y⟩ := match x, hp with | 0, (hp : 0 - _ = 1) => by rw [zero_tsub] at hp; contradiction | x + 1, _hp => Zsqrtd.le_of_le_le (Int.ofNat_le_ofNat_of_le <| Nat.succ_pos x) (Int.ofNat_zero_le _) let ⟨m, e⟩ := eq_pellZd a1 ⟨x, y⟩ this ((isPell_nat a1).2 hp) ⟨m, match x, y, e with | _, _, rfl => ⟨rfl, rfl⟩⟩ theorem pellZd_add (m) : ∀ n, pellZd a1 (m + n) = pellZd a1 m * pellZd a1 n | 0 => (mul_one _).symm | n + 1 => by rw [← add_assoc, pellZd_succ, pellZd_succ, pellZd_add _ n, ← mul_assoc] theorem xn_add (m n) : xn a1 (m + n) = xn a1 m * xn a1 n + d a1 * yn a1 m * yn a1 n := by injection pellZd_add a1 m n with h _ zify rw [h] simp [pellZd] theorem yn_add (m n) : yn a1 (m + n) = xn a1 m * yn a1 n + yn a1 m * xn a1 n := by injection pellZd_add a1 m n with _ h zify rw [h] simp [pellZd] theorem pellZd_sub {m n} (h : n ≤ m) : pellZd a1 (m - n) = pellZd a1 m * star (pellZd a1 n) := by let t := pellZd_add a1 n (m - n) rw [add_tsub_cancel_of_le h] at t rw [t, mul_comm (pellZd _ n) _, mul_assoc, isPell_norm.1 (isPell_pellZd _ _), mul_one] theorem xz_sub {m n} (h : n ≤ m) : xz a1 (m - n) = xz a1 m * xz a1 n - d a1 * yz a1 m * yz a1 n := by rw [sub_eq_add_neg, ← mul_neg] exact congr_arg Zsqrtd.re (pellZd_sub a1 h) theorem yz_sub {m n} (h : n ≤ m) : yz a1 (m - n) = xz a1 n * yz a1 m - xz a1 m * yz a1 n := by rw [sub_eq_add_neg, ← mul_neg, mul_comm, add_comm] exact congr_arg Zsqrtd.im (pellZd_sub a1 h) theorem xy_coprime (n) : (xn a1 n).Coprime (yn a1 n) := Nat.coprime_of_dvd' fun k _ kx ky => by let p := pell_eq a1 n rw [← p] exact Nat.dvd_sub (kx.mul_left _) (ky.mul_left _) theorem strictMono_y : StrictMono (yn a1) | _, 0, h => absurd h <| Nat.not_lt_zero _ | m, n + 1, h => by have : yn a1 m ≤ yn a1 n := Or.elim (lt_or_eq_of_le <| Nat.le_of_succ_le_succ h) (fun hl => le_of_lt <| strictMono_y hl) fun e => by rw [e] simp only [yn_succ, gt_iff_lt]; refine lt_of_le_of_lt ?_ (Nat.lt_add_of_pos_left <| x_pos a1 n) rw [← mul_one (yn a1 m)] exact mul_le_mul this (le_of_lt a1) (Nat.zero_le _) (Nat.zero_le _) theorem strictMono_x : StrictMono (xn a1) | _, 0, h => absurd h <| Nat.not_lt_zero _ | m, n + 1, h => by have : xn a1 m ≤ xn a1 n := Or.elim (lt_or_eq_of_le <| Nat.le_of_succ_le_succ h) (fun hl => le_of_lt <| strictMono_x hl) fun e => by rw [e] simp only [xn_succ, gt_iff_lt] refine lt_of_lt_of_le (lt_of_le_of_lt this ?_) (Nat.le_add_right _ _) have t := Nat.mul_lt_mul_of_pos_left a1 (x_pos a1 n) rwa [mul_one] at t theorem yn_ge_n : ∀ n, n ≤ yn a1 n | 0 => Nat.zero_le _ | n + 1 => show n < yn a1 (n + 1) from lt_of_le_of_lt (yn_ge_n n) (strictMono_y a1 <| Nat.lt_succ_self n) theorem y_mul_dvd (n) : ∀ k, yn a1 n ∣ yn a1 (n * k) | 0 => dvd_zero _ | k + 1 => by rw [Nat.mul_succ, yn_add]; exact dvd_add (dvd_mul_left _ _) ((y_mul_dvd _ k).mul_right _) theorem y_dvd_iff (m n) : yn a1 m ∣ yn a1 n ↔ m ∣ n := ⟨fun h => Nat.dvd_of_mod_eq_zero <| (Nat.eq_zero_or_pos _).resolve_right fun hp => by have co : Nat.Coprime (yn a1 m) (xn a1 (m * (n / m))) := Nat.Coprime.symm <| (xy_coprime a1 _).coprime_dvd_right (y_mul_dvd a1 m (n / m)) have m0 : 0 < m := m.eq_zero_or_pos.resolve_left fun e => by rw [e, Nat.mod_zero] at hp;rw [e] at h exact _root_.ne_of_lt (strictMono_y a1 hp) (eq_zero_of_zero_dvd h).symm rw [← Nat.mod_add_div n m, yn_add] at h exact not_le_of_gt (strictMono_y _ <| Nat.mod_lt n m0) (Nat.le_of_dvd (strictMono_y _ hp) <| co.dvd_of_dvd_mul_right <| (Nat.dvd_add_iff_right <| (y_mul_dvd _ _ _).mul_left _).2 h), fun ⟨k, e⟩ => by rw [e]; apply y_mul_dvd⟩ theorem xy_modEq_yn (n) : ∀ k, xn a1 (n * k) ≡ xn a1 n ^ k [MOD yn a1 n ^ 2] ∧ yn a1 (n * k) ≡ k * xn a1 n ^ (k - 1) * yn a1 n [MOD yn a1 n ^ 3] | 0 => by constructor <;> simpa using Nat.ModEq.refl _ | k + 1 => by let ⟨hx, hy⟩ := xy_modEq_yn n k have L : xn a1 (n * k) * xn a1 n + d a1 * yn a1 (n * k) * yn a1 n ≡ xn a1 n ^ k * xn a1 n + 0 [MOD yn a1 n ^ 2] := (hx.mul_right _).add <| modEq_zero_iff_dvd.2 <| by rw [_root_.pow_succ] exact mul_dvd_mul_right (dvd_mul_of_dvd_right (modEq_zero_iff_dvd.1 <| (hy.of_dvd <| by simp [_root_.pow_succ]).trans <| modEq_zero_iff_dvd.2 <| by simp) _) _ have R : xn a1 (n * k) * yn a1 n + yn a1 (n * k) * xn a1 n ≡ xn a1 n ^ k * yn a1 n + k * xn a1 n ^ k * yn a1 n [MOD yn a1 n ^ 3] := ModEq.add (by rw [_root_.pow_succ] exact hx.mul_right' _) <| by have : k * xn a1 n ^ (k - 1) * yn a1 n * xn a1 n = k * xn a1 n ^ k * yn a1 n := by rcases k with - | k <;> simp [_root_.pow_succ]; ring_nf rw [← this] exact hy.mul_right _ rw [add_tsub_cancel_right, Nat.mul_succ, xn_add, yn_add, pow_succ (xn _ n), Nat.succ_mul, add_comm (k * xn _ n ^ k) (xn _ n ^ k), right_distrib] exact ⟨L, R⟩ theorem ysq_dvd_yy (n) : yn a1 n * yn a1 n ∣ yn a1 (n * yn a1 n) := modEq_zero_iff_dvd.1 <| ((xy_modEq_yn a1 n (yn a1 n)).right.of_dvd <| by simp [_root_.pow_succ]).trans (modEq_zero_iff_dvd.2 <| by simp [mul_dvd_mul_left, mul_assoc]) theorem dvd_of_ysq_dvd {n t} (h : yn a1 n * yn a1 n ∣ yn a1 t) : yn a1 n ∣ t := have nt : n ∣ t := (y_dvd_iff a1 n t).1 <| dvd_of_mul_left_dvd h n.eq_zero_or_pos.elim (fun n0 => by rwa [n0] at nt ⊢) fun n0l : 0 < n => by let ⟨k, ke⟩ := nt have : yn a1 n ∣ k * xn a1 n ^ (k - 1) := Nat.dvd_of_mul_dvd_mul_right (strictMono_y a1 n0l) <| modEq_zero_iff_dvd.1 <| by have xm := (xy_modEq_yn a1 n k).right; rw [← ke] at xm exact (xm.of_dvd <| by simp [_root_.pow_succ]).symm.trans h.modEq_zero_nat rw [ke] exact dvd_mul_of_dvd_right (((xy_coprime _ _).pow_left _).symm.dvd_of_dvd_mul_right this) _ theorem pellZd_succ_succ (n) : pellZd a1 (n + 2) + pellZd a1 n = (2 * a : ℕ) * pellZd a1 (n + 1) := by have : (1 : ℤ√(d a1)) + ⟨a, 1⟩ * ⟨a, 1⟩ = ⟨a, 1⟩ * (2 * a) := by rw [Zsqrtd.natCast_val] change (⟨_, _⟩ : ℤ√(d a1)) = ⟨_, _⟩ rw [dz_val] dsimp [az] ext <;> dsimp <;> ring_nf simpa [mul_add, mul_comm, mul_left_comm, add_comm] using congr_arg (· * pellZd a1 n) this theorem xy_succ_succ (n) : xn a1 (n + 2) + xn a1 n = 2 * a * xn a1 (n + 1) ∧ yn a1 (n + 2) + yn a1 n = 2 * a * yn a1 (n + 1) := by have := pellZd_succ_succ a1 n; unfold pellZd at this rw [Zsqrtd.nsmul_val (2 * a : ℕ)] at this injection this with h₁ h₂ constructor <;> apply Int.ofNat.inj <;> [simpa using h₁; simpa using h₂] theorem xn_succ_succ (n) : xn a1 (n + 2) + xn a1 n = 2 * a * xn a1 (n + 1) := (xy_succ_succ a1 n).1 theorem yn_succ_succ (n) : yn a1 (n + 2) + yn a1 n = 2 * a * yn a1 (n + 1) := (xy_succ_succ a1 n).2 theorem xz_succ_succ (n) : xz a1 (n + 2) = (2 * a : ℕ) * xz a1 (n + 1) - xz a1 n := eq_sub_of_add_eq <| by delta xz; rw [← Int.natCast_add, ← Int.natCast_mul, xn_succ_succ] theorem yz_succ_succ (n) : yz a1 (n + 2) = (2 * a : ℕ) * yz a1 (n + 1) - yz a1 n := eq_sub_of_add_eq <| by delta yz; rw [← Int.natCast_add, ← Int.natCast_mul, yn_succ_succ] theorem yn_modEq_a_sub_one : ∀ n, yn a1 n ≡ n [MOD a - 1] | 0 => by simp [Nat.ModEq.refl] | 1 => by simp [Nat.ModEq.refl] | n + 2 => (yn_modEq_a_sub_one n).add_right_cancel <| by rw [yn_succ_succ, (by ring : n + 2 + n = 2 * (n + 1))] exact ((modEq_sub a1.le).mul_left 2).mul (yn_modEq_a_sub_one (n + 1)) theorem yn_modEq_two : ∀ n, yn a1 n ≡ n [MOD 2] | 0 => by rfl | 1 => by simp; rfl | n + 2 => (yn_modEq_two n).add_right_cancel <| by rw [yn_succ_succ, mul_assoc, (by ring : n + 2 + n = 2 * (n + 1))] exact (dvd_mul_right 2 _).modEq_zero_nat.trans (dvd_mul_right 2 _).zero_modEq_nat section theorem x_sub_y_dvd_pow_lem (y2 y1 y0 yn1 yn0 xn1 xn0 ay a2 : ℤ) : (a2 * yn1 - yn0) * ay + y2 - (a2 * xn1 - xn0) = y2 - a2 * y1 + y0 + a2 * (yn1 * ay + y1 - xn1) - (yn0 * ay + y0 - xn0) := by ring end theorem x_sub_y_dvd_pow (y : ℕ) : ∀ n, (2 * a * y - y * y - 1 : ℤ) ∣ yz a1 n * (a - y) + ↑(y ^ n) - xz a1 n | 0 => by simp [xz, yz, Int.ofNat_zero, Int.ofNat_one] | 1 => by simp [xz, yz, Int.ofNat_zero, Int.ofNat_one] | n + 2 => by have : (2 * a * y - y * y - 1 : ℤ) ∣ ↑(y ^ (n + 2)) - ↑(2 * a) * ↑(y ^ (n + 1)) + ↑(y ^ n) := ⟨-↑(y ^ n), by simp [_root_.pow_succ, mul_add, Int.natCast_mul, show ((2 : ℕ) : ℤ) = 2 from rfl, mul_comm, mul_left_comm] ring⟩ rw [xz_succ_succ, yz_succ_succ, x_sub_y_dvd_pow_lem ↑(y ^ (n + 2)) ↑(y ^ (n + 1)) ↑(y ^ n)] exact _root_.dvd_sub (dvd_add this <| (x_sub_y_dvd_pow _ (n + 1)).mul_left _) (x_sub_y_dvd_pow _ n) theorem xn_modEq_x2n_add_lem (n j) : xn a1 n ∣ d a1 * yn a1 n * (yn a1 n * xn a1 j) + xn a1 j := by have h1 : d a1 * yn a1 n * (yn a1 n * xn a1 j) + xn a1 j = (d a1 * yn a1 n * yn a1 n + 1) * xn a1 j := by simp [add_mul, mul_assoc] have h2 : d a1 * yn a1 n * yn a1 n + 1 = xn a1 n * xn a1 n := by zify at * apply add_eq_of_eq_sub' (Eq.symm (pell_eqz a1 n)) rw [h2] at h1; rw [h1, mul_assoc]; exact dvd_mul_right _ _ theorem xn_modEq_x2n_add (n j) : xn a1 (2 * n + j) + xn a1 j ≡ 0 [MOD xn a1 n] := by rw [two_mul, add_assoc, xn_add, add_assoc, ← zero_add 0] refine (dvd_mul_right (xn a1 n) (xn a1 (n + j))).modEq_zero_nat.add ?_ rw [yn_add, left_distrib, add_assoc, ← zero_add 0] exact ((dvd_mul_right _ _).mul_left _).modEq_zero_nat.add (xn_modEq_x2n_add_lem _ _ _).modEq_zero_nat theorem xn_modEq_x2n_sub_lem {n j} (h : j ≤ n) : xn a1 (2 * n - j) + xn a1 j ≡ 0 [MOD xn a1 n] := by have h1 : xz a1 n ∣ d a1 * yz a1 n * yz a1 (n - j) + xz a1 j := by rw [yz_sub _ h, mul_sub_left_distrib, sub_add_eq_add_sub] exact dvd_sub (by delta xz; delta yz rw [mul_comm (xn _ _ : ℤ)] exact mod_cast (xn_modEq_x2n_add_lem _ n j)) ((dvd_mul_right _ _).mul_left _) rw [two_mul, add_tsub_assoc_of_le h, xn_add, add_assoc, ← zero_add 0] exact (dvd_mul_right _ _).modEq_zero_nat.add (Int.natCast_dvd_natCast.1 <| by simpa [xz, yz] using h1).modEq_zero_nat theorem xn_modEq_x2n_sub {n j} (h : j ≤ 2 * n) : xn a1 (2 * n - j) + xn a1 j ≡ 0 [MOD xn a1 n] := (le_total j n).elim (xn_modEq_x2n_sub_lem a1) fun jn => by have : 2 * n - j + j ≤ n + j := by
rw [tsub_add_cancel_of_le h, two_mul]; exact Nat.add_le_add_left jn _ let t := xn_modEq_x2n_sub_lem a1 (Nat.le_of_add_le_add_right this)
Mathlib/NumberTheory/PellMatiyasevic.lean
539
540
/- 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.Algebra.Pi import Mathlib.LinearAlgebra.Finsupp.SumProd import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.LinearAlgebra.LinearIndependent.Lemmas /-! # The standard basis This file defines the standard basis `Pi.basis (s : ∀ j, Basis (ι j) R (M j))`, which is the `Σ j, ι j`-indexed basis of `Π j, M j`. The basis vectors are given by `Pi.basis s ⟨j, i⟩ j' = Pi.single j' (s j) i = if j = j' then s i else 0`. The standard basis on `R^η`, i.e. `η → R` is called `Pi.basisFun`. To give a concrete example, `Pi.single (i : Fin 3) (1 : R)` gives the `i`th unit basis vector in `R³`, and `Pi.basisFun R (Fin 3)` proves this is a basis over `Fin 3 → R`. ## Main definitions - `Pi.basis s`: given a basis `s i` for each `M i`, the standard basis on `Π i, M i` - `Pi.basisFun R η`: the standard basis on `R^η`, i.e. `η → R`, given by `Pi.basisFun R η i j = Pi.single i 1 j = if i = j then 1 else 0`. - `Matrix.stdBasis R n m`: the standard basis on `Matrix n m R`, given by `Matrix.stdBasis R n m (i, j) i' j' = if (i, j) = (i', j') then 1 else 0`. -/ open Function Set Submodule namespace Pi open LinearMap open Set variable {R : Type*} section Module variable {η : Type*} {ιs : η → Type*} {Ms : η → Type*} theorem linearIndependent_single [Ring R] [∀ i, AddCommGroup (Ms i)] [∀ i, Module R (Ms i)] [DecidableEq η] (v : ∀ j, ιs j → Ms j) (hs : ∀ i, LinearIndependent R (v i)) : LinearIndependent R fun ji : Σj, ιs j ↦ Pi.single ji.1 (v ji.1 ji.2) := by have hs' : ∀ j : η, LinearIndependent R fun i : ιs j => LinearMap.single R Ms j (v j i) := by intro j exact (hs j).map' _ (LinearMap.ker_single _ _ _) apply linearIndependent_iUnion_finite hs' intro j J _ hiJ have h₀ : ∀ j, span R (range fun i : ιs j => LinearMap.single R Ms j (v j i)) ≤ LinearMap.range (LinearMap.single R Ms j) := by intro j rw [span_le, LinearMap.range_coe] apply range_comp_subset_range have h₁ : span R (range fun i : ιs j => LinearMap.single R Ms j (v j i)) ≤ ⨆ i ∈ ({j} : Set _), LinearMap.range (LinearMap.single R Ms i) := by rw [@iSup_singleton _ _ _ fun i => LinearMap.range (LinearMap.single R (Ms) i)] apply h₀ have h₂ : ⨆ j ∈ J, span R (range fun i : ιs j => LinearMap.single R Ms j (v j i)) ≤ ⨆ j ∈ J, LinearMap.range (LinearMap.single R (fun j : η => Ms j) j) := iSup₂_mono fun i _ => h₀ i have h₃ : Disjoint (fun i : η => i ∈ ({j} : Set _)) J := by convert Set.disjoint_singleton_left.2 hiJ using 0 exact (disjoint_single_single _ _ _ _ h₃).mono h₁ h₂ theorem linearIndependent_single_one (ι R : Type*) [Ring R] [DecidableEq ι] : LinearIndependent R (fun i : ι ↦ Pi.single i (1 : R)) := by rw [← linearIndependent_equiv (Equiv.sigmaPUnit ι)] exact Pi.linearIndependent_single (fun (_ : ι) (_ : Unit) ↦ (1 : R)) <| by simp +contextual [Fintype.linearIndependent_iff] lemma linearIndependent_single_of_ne_zero {ι R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M] [DecidableEq ι] {v : ι → M} (hv : ∀ i, v i ≠ 0) : LinearIndependent R fun i : ι ↦ Pi.single i (v i) := by rw [← linearIndependent_equiv (Equiv.sigmaPUnit ι)] exact linearIndependent_single (fun i (_ : Unit) ↦ v i) <| by simp +contextual [Fintype.linearIndependent_iff, hv] @[deprecated linearIndependent_single_of_ne_zero (since := "2025-04-14")] theorem linearIndependent_single_ne_zero {ι R : Type*} [Ring R] [NoZeroDivisors R] [DecidableEq ι] {v : ι → R} (hv : ∀ i, v i ≠ 0) : LinearIndependent R (fun i : ι ↦ Pi.single i (v i)) := linearIndependent_single_of_ne_zero hv variable [Semiring R] [∀ i, AddCommMonoid (Ms i)] [∀ i, Module R (Ms i)] section Fintype variable [Fintype η] open LinearEquiv /-- `Pi.basis (s : ∀ j, Basis (ιs j) R (Ms j))` is the `Σ j, ιs j`-indexed basis on `Π j, Ms j` given by `s j` on each component. For the standard basis over `R` on the finite-dimensional space `η → R` see `Pi.basisFun`. -/ protected noncomputable def basis (s : ∀ j, Basis (ιs j) R (Ms j)) : Basis (Σj, ιs j) R (∀ j, Ms j) := Basis.ofRepr ((LinearEquiv.piCongrRight fun j => (s j).repr) ≪≫ₗ (Finsupp.sigmaFinsuppLEquivPiFinsupp R).symm) @[simp] theorem basis_repr_single [DecidableEq η] (s : ∀ j, Basis (ιs j) R (Ms j)) (j i) : (Pi.basis s).repr (Pi.single j (s j i)) = Finsupp.single ⟨j, i⟩ 1 := by classical ext ⟨j', i'⟩ by_cases hj : j = j' · subst hj simp only [Pi.basis, LinearEquiv.trans_apply, Basis.repr_self, Pi.single_eq_same, LinearEquiv.piCongrRight, Finsupp.sigmaFinsuppLEquivPiFinsupp_symm_apply, Basis.repr_symm_apply, LinearEquiv.coe_mk, ne_eq, Sigma.mk.inj_iff, heq_eq_eq, true_and] symm simp [Finsupp.single_apply] simp only [Pi.basis, LinearEquiv.trans_apply, Finsupp.sigmaFinsuppLEquivPiFinsupp_symm_apply, LinearEquiv.piCongrRight, coe_single] dsimp rw [Pi.single_eq_of_ne (Ne.symm hj), LinearEquiv.map_zero, Finsupp.zero_apply, Finsupp.single_eq_of_ne] rintro ⟨⟩ contradiction @[simp] theorem basis_apply [DecidableEq η] (s : ∀ j, Basis (ιs j) R (Ms j)) (ji) : Pi.basis s ji = Pi.single ji.1 (s ji.1 ji.2) := Basis.apply_eq_iff.mpr (by simp) @[simp] theorem basis_repr (s : ∀ j, Basis (ιs j) R (Ms j)) (x) (ji) :
(Pi.basis s).repr x ji = (s ji.1).repr (x ji.1) ji.2 := rfl end Fintype section variable [Finite η] variable (R η) /-- The basis on `η → R` where the `i`th basis vector is `Function.update 0 i 1`. -/ noncomputable def basisFun : Basis η R (η → R) := Basis.ofEquivFun (LinearEquiv.refl _ _)
Mathlib/LinearAlgebra/StdBasis.lean
140
153
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Data.Setoid.Basic import Mathlib.GroupTheory.Congruence.Hom /-! # Congruence relations This file proves basic properties of the quotient of a type by a congruence relation. The second half of the file concerns congruence relations on monoids, in which case the quotient by the congruence relation is also a monoid. There are results about the universal property of quotients of monoids, and the isomorphism theorems for monoids. ## Implementation notes A congruence relation on a monoid `M` can be thought of as a submonoid of `M × M` for which membership is an equivalence relation, but whilst this fact is established in the file, it is not used, since this perspective adds more layers of definitional unfolding. ## Tags congruence, congruence relation, quotient, quotient by congruence relation, monoid, quotient monoid, isomorphism theorems -/ variable (M : Type*) {N : Type*} {P : Type*} open Function Setoid variable {M} namespace Con section variable [Mul M] [Mul N] [Mul P] (c : Con M) variable {c} /-- Given types with multiplications `M, N`, the product of two congruence relations `c` on `M` and `d` on `N`: `(x₁, x₂), (y₁, y₂) ∈ M × N` are related by `c.prod d` iff `x₁` is related to `y₁` by `c` and `x₂` is related to `y₂` by `d`. -/ @[to_additive prod "Given types with additions `M, N`, the product of two congruence relations `c` on `M` and `d` on `N`: `(x₁, x₂), (y₁, y₂) ∈ M × N` are related by `c.prod d` iff `x₁` is related to `y₁` by `c` and `x₂` is related to `y₂` by `d`."] protected def prod (c : Con M) (d : Con N) : Con (M × N) := { c.toSetoid.prod d.toSetoid with mul' := fun h1 h2 => ⟨c.mul h1.1 h2.1, d.mul h1.2 h2.2⟩ } /-- The product of an indexed collection of congruence relations. -/ @[to_additive "The product of an indexed collection of additive congruence relations."] def pi {ι : Type*} {f : ι → Type*} [∀ i, Mul (f i)] (C : ∀ i, Con (f i)) : Con (∀ i, f i) := { @piSetoid _ _ fun i => (C i).toSetoid with mul' := fun h1 h2 i => (C i).mul (h1 i) (h2 i) } /-- Makes an isomorphism of quotients by two congruence relations, given that the relations are equal. -/ @[to_additive "Makes an additive isomorphism of quotients by two additive congruence relations, given that the relations are equal."] protected def congr {c d : Con M} (h : c = d) : c.Quotient ≃* d.Quotient := { Quotient.congr (Equiv.refl M) <| by apply Con.ext_iff.mp h with map_mul' := fun x y => by rcases x with ⟨⟩; rcases y with ⟨⟩; rfl } @[to_additive (attr := simp)] theorem congr_mk {c d : Con M} (h : c = d) (a : M) : Con.congr h (a : c.Quotient) = (a : d.Quotient) := rfl @[to_additive] theorem le_comap_conGen {M N : Type*} [Mul M] [Mul N] (f : M → N) (H : ∀ (x y : M), f (x * y) = f x * f y) (rel : N → N → Prop) : conGen (fun x y ↦ rel (f x) (f y)) ≤ Con.comap f H (conGen rel) := by intro x y h simp only [Con.comap_rel] exact .rec (fun x y h ↦ .of (f x) (f y) h) (fun x ↦ .refl (f x)) (fun _ h ↦ .symm h) (fun _ _ h1 h2 ↦ h1.trans h2) (fun {w x y z} _ _ h1 h2 ↦ (congrArg (fun a ↦ conGen rel a (f (x * z))) (H w y)).mpr (((congrArg (fun a ↦ conGen rel (f w * f y) a) (H x z))).mpr (.mul h1 h2))) h @[to_additive] theorem comap_conGen_equiv {M N : Type*} [Mul M] [Mul N] (f : MulEquiv M N) (rel : N → N → Prop) : Con.comap f (map_mul f) (conGen rel) = conGen (fun x y ↦ rel (f x) (f y)) := by apply le_antisymm _ (le_comap_conGen f (map_mul f) rel) intro a b h simp only [Con.comap_rel] at h have H : ∀ n1 n2, (conGen rel) n1 n2 → ∀ a b, f a = n1 → f b = n2 → (conGen fun x y ↦ rel (f x) (f y)) a b := by intro n1 n2 h induction h with | of x y h => intro _ _ fa fb apply ConGen.Rel.of rwa [fa, fb] | refl x => intro _ _ fc fd rw [f.injective (fc.trans fd.symm)] exact ConGen.Rel.refl _ | symm _ h => exact fun a b fs fb ↦ ConGen.Rel.symm (h b a fb fs) | trans _ _ ih ih1 => exact fun a b fa fb ↦ Exists.casesOn (f.surjective _) fun c' hc' ↦ ConGen.Rel.trans (ih a c' fa hc') (ih1 c' b hc' fb) | mul _ _ ih ih1 => rename_i w x y z _ _ intro a b fa fb rw [← f.eq_symm_apply, map_mul] at fa fb rw [fa, fb] exact ConGen.Rel.mul (ih (f.symm w) (f.symm x) (by simp) (by simp)) (ih1 (f.symm y) (f.symm z) (by simp) (by simp)) exact H (f a) (f b) h a b (refl _) (refl _) @[to_additive] theorem comap_conGen_of_bijective {M N : Type*} [Mul M] [Mul N] (f : M → N) (hf : Function.Bijective f) (H : ∀ (x y : M), f (x * y) = f x * f y) (rel : N → N → Prop) : Con.comap f H (conGen rel) = conGen (fun x y ↦ rel (f x) (f y)) := comap_conGen_equiv (MulEquiv.ofBijective (MulHom.mk f H) hf) rel end section MulOneClass variable [MulOneClass M] [MulOneClass N] [MulOneClass P] (c : Con M) /-- The submonoid of `M × M` defined by a congruence relation on a monoid `M`. -/ @[to_additive (attr := coe) "The `AddSubmonoid` of `M × M` defined by an additive congruence relation on an `AddMonoid` `M`."] protected def submonoid : Submonoid (M × M) where carrier := { x | c x.1 x.2 } one_mem' := c.iseqv.1 1 mul_mem' := c.mul variable {c} /-- The congruence relation on a monoid `M` from a submonoid of `M × M` for which membership is an equivalence relation. -/ @[to_additive "The additive congruence relation on an `AddMonoid` `M` from an `AddSubmonoid` of `M × M` for which membership is an equivalence relation."] def ofSubmonoid (N : Submonoid (M × M)) (H : Equivalence fun x y => (x, y) ∈ N) : Con M where r x y := (x, y) ∈ N iseqv := H mul' := N.mul_mem /-- Coercion from a congruence relation `c` on a monoid `M` to the submonoid of `M × M` whose elements are `(x, y)` such that `x` is related to `y` by `c`. -/ @[to_additive "Coercion from a congruence relation `c` on an `AddMonoid` `M` to the `AddSubmonoid` of `M × M` whose elements are `(x, y)` such that `x` is related to `y` by `c`."] instance toSubmonoid : Coe (Con M) (Submonoid (M × M)) := ⟨fun c => c.submonoid⟩ @[to_additive] theorem mem_coe {c : Con M} {x y} : (x, y) ∈ (↑c : Submonoid (M × M)) ↔ (x, y) ∈ c := Iff.rfl @[to_additive] theorem to_submonoid_inj (c d : Con M) (H : (c : Submonoid (M × M)) = d) : c = d := ext fun x y => show (x, y) ∈ c.submonoid ↔ (x, y) ∈ d from H ▸ Iff.rfl @[to_additive] theorem le_iff {c d : Con M} : c ≤ d ↔ (c : Submonoid (M × M)) ≤ d := ⟨fun h _ H => h H, fun h x y hc => h <| show (x, y) ∈ c from hc⟩ variable (x y : M) @[to_additive (attr := simp)] -- Porting note: removed dot notation theorem mrange_mk' : MonoidHom.mrange c.mk' = ⊤ := MonoidHom.mrange_eq_top.2 mk'_surjective variable {f : M →* P} /-- Given a congruence relation `c` on a monoid and a homomorphism `f` constant on `c`'s equivalence classes, `f` has the same image as the homomorphism that `f` induces on the quotient. -/ @[to_additive "Given an additive congruence relation `c` on an `AddMonoid` and a homomorphism `f` constant on `c`'s equivalence classes, `f` has the same image as the homomorphism that `f` induces on the quotient."] theorem lift_range (H : c ≤ ker f) : MonoidHom.mrange (c.lift f H) = MonoidHom.mrange f := Submonoid.ext fun x => ⟨by rintro ⟨⟨y⟩, hy⟩; exact ⟨y, hy⟩, fun ⟨y, hy⟩ => ⟨↑y, hy⟩⟩
/-- Given a monoid homomorphism `f`, the induced homomorphism on the quotient by `f`'s kernel has the same image as `f`. -/
Mathlib/GroupTheory/Congruence/Basic.lean
186
187
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Chris Hughes, Floris van Doorn, Yaël Dillies -/ import Mathlib.Data.Nat.Basic import Mathlib.Tactic.GCongr.CoreAttrs import Mathlib.Tactic.Common import Mathlib.Tactic.Monotonicity.Attr /-! # Factorial and variants This file defines the factorial, along with the ascending and descending variants. For the proof that the factorial of `n` counts the permutations of an `n`-element set, see `Fintype.card_perm`. ## Main declarations * `Nat.factorial`: The factorial. * `Nat.ascFactorial`: The ascending factorial. It is the product of natural numbers from `n` to `n + k - 1`. * `Nat.descFactorial`: The descending factorial. It is the product of natural numbers from `n - k + 1` to `n`. -/ namespace Nat /-- `Nat.factorial n` is the factorial of `n`. -/ def factorial : ℕ → ℕ | 0 => 1 | succ n => succ n * factorial n /-- factorial notation `(n)!` for `Nat.factorial n`. In Lean, names can end with exclamation marks (e.g. `List.get!`), so you cannot write `n!` in Lean, but must write `(n)!` or `n !` instead. The former is preferred, since Lean can confuse the `!` in `n !` as the (prefix) boolean negation operation in some cases. For numerals the parentheses are not required, so e.g. `0!` or `1!` work fine. Todo: replace occurrences of `n !` with `(n)!` in Mathlib. -/ scoped notation:10000 n "!" => Nat.factorial n section Factorial variable {m n : ℕ} @[simp] theorem factorial_zero : 0! = 1 := rfl theorem factorial_succ (n : ℕ) : (n + 1)! = (n + 1) * n ! := rfl @[simp] theorem factorial_one : 1! = 1 := rfl @[simp] theorem factorial_two : 2! = 2 := rfl theorem mul_factorial_pred (hn : n ≠ 0) : n * (n - 1)! = n ! := Nat.sub_add_cancel (one_le_iff_ne_zero.mpr hn) ▸ rfl theorem factorial_pos : ∀ n, 0 < n ! | 0 => Nat.zero_lt_one | succ n => Nat.mul_pos (succ_pos _) (factorial_pos n) theorem factorial_ne_zero (n : ℕ) : n ! ≠ 0 := ne_of_gt (factorial_pos _) theorem factorial_dvd_factorial {m n} (h : m ≤ n) : m ! ∣ n ! := by induction h with
| refl => exact Nat.dvd_refl _ | step _ ih => exact Nat.dvd_trans ih (Nat.dvd_mul_left _ _) theorem dvd_factorial : ∀ {m n}, 0 < m → m ≤ n → m ∣ n !
Mathlib/Data/Nat/Factorial/Basic.lean
73
76
/- 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.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.Cover import Mathlib.Order.Iterate /-! # Successor and predecessor This file defines successor and predecessor orders. `succ a`, the successor of an element `a : α` is the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples include `ℕ`, `ℤ`, `ℕ+`, `Fin n`, but also `ENat`, the lexicographic order of a successor/predecessor order... ## Typeclasses * `SuccOrder`: Order equipped with a sensible successor function. * `PredOrder`: Order equipped with a sensible predecessor function. ## Implementation notes Maximal elements don't have a sensible successor. Thus the naïve typeclass ```lean class NaiveSuccOrder (α : Type*) [Preorder α] where (succ : α → α) (succ_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (lt_succ_iff : ∀ {a b}, a < succ b ↔ a ≤ b) ``` can't apply to an `OrderTop` because plugging in `a = b = ⊤` into either of `succ_le_iff` and `lt_succ_iff` yields `⊤ < ⊤` (or more generally `m < m` for a maximal element `m`). The solution taken here is to remove the implications `≤ → <` and instead require that `a < succ a` for all non maximal elements (enforced by the combination of `le_succ` and the contrapositive of `max_of_succ_le`). The stricter condition of every element having a sensible successor can be obtained through the combination of `SuccOrder α` and `NoMaxOrder α`. -/ open Function OrderDual Set variable {α β : Type*} /-- Order equipped with a sensible successor function. -/ @[ext] class SuccOrder (α : Type*) [Preorder α] where /-- Successor function -/ succ : α → α /-- Proof of basic ordering with respect to `succ` -/ le_succ : ∀ a, a ≤ succ a /-- Proof of interaction between `succ` and maximal element -/ max_of_succ_le {a} : succ a ≤ a → IsMax a /-- Proof that `succ a` is the least element greater than `a` -/ succ_le_of_lt {a b} : a < b → succ a ≤ b /-- Order equipped with a sensible predecessor function. -/ @[ext] class PredOrder (α : Type*) [Preorder α] where /-- Predecessor function -/ pred : α → α /-- Proof of basic ordering with respect to `pred` -/ pred_le : ∀ a, pred a ≤ a /-- Proof of interaction between `pred` and minimal element -/ min_of_le_pred {a} : a ≤ pred a → IsMin a /-- Proof that `pred b` is the greatest element less than `b` -/ le_pred_of_lt {a b} : a < b → a ≤ pred b instance [Preorder α] [SuccOrder α] : PredOrder αᵒᵈ where pred := toDual ∘ SuccOrder.succ ∘ ofDual pred_le := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, SuccOrder.le_succ, implies_true] min_of_le_pred h := by apply SuccOrder.max_of_succ_le h le_pred_of_lt := by intro a b h; exact SuccOrder.succ_le_of_lt h instance [Preorder α] [PredOrder α] : SuccOrder αᵒᵈ where succ := toDual ∘ PredOrder.pred ∘ ofDual le_succ := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, PredOrder.pred_le, implies_true] max_of_succ_le h := by apply PredOrder.min_of_le_pred h succ_le_of_lt := by intro a b h; exact PredOrder.le_pred_of_lt h section Preorder variable [Preorder α] /-- A constructor for `SuccOrder α` usable when `α` has no maximal element. -/ def SuccOrder.ofSuccLeIff (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) : SuccOrder α := { succ le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim succ_le_of_lt := fun h => hsucc_le_iff.2 h } /-- A constructor for `PredOrder α` usable when `α` has no minimal element. -/ def PredOrder.ofLePredIff (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) : PredOrder α := { pred pred_le := fun _ => (hle_pred_iff.1 le_rfl).le min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim le_pred_of_lt := fun h => hle_pred_iff.2 h } end Preorder section LinearOrder variable [LinearOrder α] /-- A constructor for `SuccOrder α` for `α` a linear order. -/ @[simps] def SuccOrder.ofCore (succ : α → α) (hn : ∀ {a}, ¬IsMax a → ∀ b, a < b ↔ succ a ≤ b) (hm : ∀ a, IsMax a → succ a = a) : SuccOrder α := { succ succ_le_of_lt := fun {a b} => by_cases (fun h hab => (hm a h).symm ▸ hab.le) fun h => (hn h b).mp le_succ := fun a => by_cases (fun h => (hm a h).symm.le) fun h => le_of_lt <| by simpa using (hn h a).not max_of_succ_le := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } /-- A constructor for `PredOrder α` for `α` a linear order. -/ @[simps] def PredOrder.ofCore (pred : α → α) (hn : ∀ {a}, ¬IsMin a → ∀ b, b ≤ pred a ↔ b < a) (hm : ∀ a, IsMin a → pred a = a) : PredOrder α := { pred le_pred_of_lt := fun {a b} => by_cases (fun h hab => (hm b h).symm ▸ hab.le) fun h => (hn h a).mpr pred_le := fun a => by_cases (fun h => (hm a h).le) fun h => le_of_lt <| by simpa using (hn h a).not min_of_le_pred := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } variable (α) open Classical in /-- A well-order is a `SuccOrder`. -/ noncomputable def SuccOrder.ofLinearWellFoundedLT [WellFoundedLT α] : SuccOrder α := ofCore (fun a ↦ if h : (Ioi a).Nonempty then wellFounded_lt.min _ h else a) (fun ha _ ↦ by rw [not_isMax_iff] at ha simp_rw [Set.Nonempty, mem_Ioi, dif_pos ha] exact ⟨(wellFounded_lt.min_le · ha), lt_of_lt_of_le (wellFounded_lt.min_mem _ ha)⟩) fun _ ha ↦ dif_neg (not_not_intro ha <| not_isMax_iff.mpr ·) /-- A linear order with well-founded greater-than relation is a `PredOrder`. -/ noncomputable def PredOrder.ofLinearWellFoundedGT (α) [LinearOrder α] [WellFoundedGT α] : PredOrder α := letI := SuccOrder.ofLinearWellFoundedLT αᵒᵈ; inferInstanceAs (PredOrder αᵒᵈᵒᵈ) end LinearOrder /-! ### Successor order -/ namespace Order section Preorder variable [Preorder α] [SuccOrder α] {a b : α} /-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater than `a`. If `a` is maximal, then `succ a = a`. -/ def succ : α → α := SuccOrder.succ theorem le_succ : ∀ a : α, a ≤ succ a := SuccOrder.le_succ theorem max_of_succ_le {a : α} : succ a ≤ a → IsMax a := SuccOrder.max_of_succ_le theorem succ_le_of_lt {a b : α} : a < b → succ a ≤ b := SuccOrder.succ_le_of_lt alias _root_.LT.lt.succ_le := succ_le_of_lt @[simp] theorem succ_le_iff_isMax : succ a ≤ a ↔ IsMax a := ⟨max_of_succ_le, fun h => h <| le_succ _⟩ alias ⟨_root_.IsMax.of_succ_le, _root_.IsMax.succ_le⟩ := succ_le_iff_isMax @[simp] theorem lt_succ_iff_not_isMax : a < succ a ↔ ¬IsMax a := ⟨not_isMax_of_lt, fun ha => (le_succ a).lt_of_not_le fun h => ha <| max_of_succ_le h⟩ alias ⟨_, lt_succ_of_not_isMax⟩ := lt_succ_iff_not_isMax theorem wcovBy_succ (a : α) : a ⩿ succ a := ⟨le_succ a, fun _ hb => (succ_le_of_lt hb).not_lt⟩ theorem covBy_succ_of_not_isMax (h : ¬IsMax a) : a ⋖ succ a := (wcovBy_succ a).covBy_of_lt <| lt_succ_of_not_isMax h theorem lt_succ_of_le_of_not_isMax (hab : b ≤ a) (ha : ¬IsMax a) : b < succ a := hab.trans_lt <| lt_succ_of_not_isMax ha theorem succ_le_iff_of_not_isMax (ha : ¬IsMax a) : succ a ≤ b ↔ a < b := ⟨(lt_succ_of_not_isMax ha).trans_le, succ_le_of_lt⟩ lemma succ_lt_succ_of_not_isMax (h : a < b) (hb : ¬ IsMax b) : succ a < succ b := lt_succ_of_le_of_not_isMax (succ_le_of_lt h) hb @[simp, mono, gcongr] theorem succ_le_succ (h : a ≤ b) : succ a ≤ succ b := by by_cases hb : IsMax b · by_cases hba : b ≤ a · exact (hb <| hba.trans <| le_succ _).trans (le_succ _) · exact succ_le_of_lt ((h.lt_of_not_le hba).trans_le <| le_succ b) · rw [succ_le_iff_of_not_isMax fun ha => hb <| ha.mono h] apply lt_succ_of_le_of_not_isMax h hb theorem succ_mono : Monotone (succ : α → α) := fun _ _ => succ_le_succ /-- See also `Order.succ_eq_of_covBy`. -/ lemma le_succ_of_wcovBy (h : a ⩿ b) : b ≤ succ a := by obtain hab | ⟨-, hba⟩ := h.covBy_or_le_and_le · by_contra hba exact h.2 (lt_succ_of_not_isMax hab.lt.not_isMax) <| hab.lt.succ_le.lt_of_not_le hba · exact hba.trans (le_succ _) alias _root_.WCovBy.le_succ := le_succ_of_wcovBy theorem le_succ_iterate (k : ℕ) (x : α) : x ≤ succ^[k] x := id_le_iterate_of_id_le le_succ _ _ theorem isMax_iterate_succ_of_eq_of_lt {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_lt : n < m) : IsMax (succ^[n] a) := by refine max_of_succ_le (le_trans ?_ h_eq.symm.le) rw [← iterate_succ_apply' succ] have h_le : n + 1 ≤ m := Nat.succ_le_of_lt h_lt exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le theorem isMax_iterate_succ_of_eq_of_ne {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_ne : n ≠ m) : IsMax (succ^[n] a) := by rcases le_total n m with h | h · exact isMax_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne) · rw [h_eq] exact isMax_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm) theorem Iic_subset_Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iic a ⊆ Iio (succ a) := fun _ => (lt_succ_of_le_of_not_isMax · ha) theorem Ici_succ_of_not_isMax (ha : ¬IsMax a) : Ici (succ a) = Ioi a := Set.ext fun _ => succ_le_iff_of_not_isMax ha theorem Icc_subset_Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Icc a b ⊆ Ico a (succ b) := by rw [← Ici_inter_Iio, ← Ici_inter_Iic] gcongr intro _ h apply lt_succ_of_le_of_not_isMax h hb theorem Ioc_subset_Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioc a b ⊆ Ioo a (succ b) := by rw [← Ioi_inter_Iio, ← Ioi_inter_Iic] gcongr intro _ h apply Iic_subset_Iio_succ_of_not_isMax hb h theorem Icc_succ_left_of_not_isMax (ha : ¬IsMax a) : Icc (succ a) b = Ioc a b := by rw [← Ici_inter_Iic, Ici_succ_of_not_isMax ha, Ioi_inter_Iic] theorem Ico_succ_left_of_not_isMax (ha : ¬IsMax a) : Ico (succ a) b = Ioo a b := by rw [← Ici_inter_Iio, Ici_succ_of_not_isMax ha, Ioi_inter_Iio] section NoMaxOrder variable [NoMaxOrder α] theorem lt_succ (a : α) : a < succ a := lt_succ_of_not_isMax <| not_isMax a @[simp] theorem lt_succ_of_le : a ≤ b → a < succ b := (lt_succ_of_le_of_not_isMax · <| not_isMax b) @[simp] theorem succ_le_iff : succ a ≤ b ↔ a < b := succ_le_iff_of_not_isMax <| not_isMax a @[gcongr] theorem succ_lt_succ (hab : a < b) : succ a < succ b := by simp [hab] theorem succ_strictMono : StrictMono (succ : α → α) := fun _ _ => succ_lt_succ theorem covBy_succ (a : α) : a ⋖ succ a := covBy_succ_of_not_isMax <| not_isMax a theorem Iic_subset_Iio_succ (a : α) : Iic a ⊆ Iio (succ a) := by simp @[simp] theorem Ici_succ (a : α) : Ici (succ a) = Ioi a := Ici_succ_of_not_isMax <| not_isMax _ @[simp] theorem Icc_subset_Ico_succ_right (a b : α) : Icc a b ⊆ Ico a (succ b) := Icc_subset_Ico_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem Ioc_subset_Ioo_succ_right (a b : α) : Ioc a b ⊆ Ioo a (succ b) := Ioc_subset_Ioo_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem Icc_succ_left (a b : α) : Icc (succ a) b = Ioc a b := Icc_succ_left_of_not_isMax <| not_isMax _ @[simp] theorem Ico_succ_left (a b : α) : Ico (succ a) b = Ioo a b := Ico_succ_left_of_not_isMax <| not_isMax _ end NoMaxOrder end Preorder section PartialOrder variable [PartialOrder α] [SuccOrder α] {a b : α} @[simp] theorem succ_eq_iff_isMax : succ a = a ↔ IsMax a := ⟨fun h => max_of_succ_le h.le, fun h => h.eq_of_ge <| le_succ _⟩ alias ⟨_, _root_.IsMax.succ_eq⟩ := succ_eq_iff_isMax lemma le_iff_eq_or_succ_le : a ≤ b ↔ a = b ∨ succ a ≤ b := by by_cases ha : IsMax a · simpa [ha.succ_eq] using le_of_eq · rw [succ_le_iff_of_not_isMax ha, le_iff_eq_or_lt] theorem le_le_succ_iff : a ≤ b ∧ b ≤ succ a ↔ b = a ∨ b = succ a := by refine ⟨fun h => or_iff_not_imp_left.2 fun hba : b ≠ a => h.2.antisymm (succ_le_of_lt <| h.1.lt_of_ne <| hba.symm), ?_⟩ rintro (rfl | rfl) · exact ⟨le_rfl, le_succ b⟩ · exact ⟨le_succ a, le_rfl⟩ /-- See also `Order.le_succ_of_wcovBy`. -/ lemma succ_eq_of_covBy (h : a ⋖ b) : succ a = b := (succ_le_of_lt h.lt).antisymm h.wcovBy.le_succ alias _root_.CovBy.succ_eq := succ_eq_of_covBy theorem _root_.OrderIso.map_succ [PartialOrder β] [SuccOrder β] (f : α ≃o β) (a : α) : f (succ a) = succ (f a) := by by_cases h : IsMax a · rw [h.succ_eq, (f.isMax_apply.2 h).succ_eq] · exact (f.map_covBy.2 <| covBy_succ_of_not_isMax h).succ_eq.symm section NoMaxOrder variable [NoMaxOrder α] theorem succ_eq_iff_covBy : succ a = b ↔ a ⋖ b := ⟨by rintro rfl; exact covBy_succ _, CovBy.succ_eq⟩ end NoMaxOrder section OrderTop variable [OrderTop α] @[simp] theorem succ_top : succ (⊤ : α) = ⊤ := by rw [succ_eq_iff_isMax, isMax_iff_eq_top] theorem succ_le_iff_eq_top : succ a ≤ a ↔ a = ⊤ := succ_le_iff_isMax.trans isMax_iff_eq_top theorem lt_succ_iff_ne_top : a < succ a ↔ a ≠ ⊤ := lt_succ_iff_not_isMax.trans not_isMax_iff_ne_top end OrderTop section OrderBot variable [OrderBot α] [Nontrivial α] theorem bot_lt_succ (a : α) : ⊥ < succ a := (lt_succ_of_not_isMax not_isMax_bot).trans_le <| succ_mono bot_le theorem succ_ne_bot (a : α) : succ a ≠ ⊥ := (bot_lt_succ a).ne' end OrderBot end PartialOrder section LinearOrder variable [LinearOrder α] [SuccOrder α] {a b : α} theorem le_of_lt_succ {a b : α} : a < succ b → a ≤ b := fun h ↦ by by_contra! nh exact (h.trans_le (succ_le_of_lt nh)).false theorem lt_succ_iff_of_not_isMax (ha : ¬IsMax a) : b < succ a ↔ b ≤ a := ⟨le_of_lt_succ, fun h => h.trans_lt <| lt_succ_of_not_isMax ha⟩ theorem succ_lt_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a < succ b ↔ a < b := by rw [lt_succ_iff_of_not_isMax hb, succ_le_iff_of_not_isMax ha] theorem succ_le_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a ≤ succ b ↔ a ≤ b := by rw [succ_le_iff_of_not_isMax ha, lt_succ_iff_of_not_isMax hb] theorem Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iio (succ a) = Iic a := Set.ext fun _ => lt_succ_iff_of_not_isMax ha theorem Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Ico a (succ b) = Icc a b := by rw [← Ici_inter_Iio, Iio_succ_of_not_isMax hb, Ici_inter_Iic] theorem Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioo a (succ b) = Ioc a b := by rw [← Ioi_inter_Iio, Iio_succ_of_not_isMax hb, Ioi_inter_Iic] theorem succ_eq_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a = succ b ↔ a = b := by rw [eq_iff_le_not_lt, eq_iff_le_not_lt, succ_le_succ_iff_of_not_isMax ha hb, succ_lt_succ_iff_of_not_isMax ha hb] theorem le_succ_iff_eq_or_le : a ≤ succ b ↔ a = succ b ∨ a ≤ b := by by_cases hb : IsMax b · rw [hb.succ_eq, or_iff_right_of_imp le_of_eq] · rw [← lt_succ_iff_of_not_isMax hb, le_iff_eq_or_lt] theorem lt_succ_iff_eq_or_lt_of_not_isMax (hb : ¬IsMax b) : a < succ b ↔ a = b ∨ a < b := (lt_succ_iff_of_not_isMax hb).trans le_iff_eq_or_lt
theorem not_isMin_succ [Nontrivial α] (a : α) : ¬ IsMin (succ a) := by obtain ha | ha := (le_succ a).eq_or_lt · exact (ha ▸ succ_eq_iff_isMax.1 ha.symm).not_isMin · exact not_isMin_of_lt ha
Mathlib/Order/SuccPred/Basic.lean
431
434
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Data.List.Nodup import Mathlib.Data.Set.Prod /-! # Finite products of types This file defines the product of types over a list. For `l : List ι` and `α : ι → Type v` we define `List.TProd α l = l.foldr (fun i β ↦ α i × β) PUnit`. This type should not be used if `∀ i, α i` or `∀ i ∈ l, α i` can be used instead (in the last expression, we could also replace the list `l` by a set or a finset). This type is used as an intermediary between binary products and finitary products. The application of this type is finitary product measures, but it could be used in any construction/theorem that is easier to define/prove on binary products than on finitary products. * Once we have the construction on binary products (like binary product measures in `MeasureTheory.prod`), we can easily define a finitary version on the type `TProd l α` by iterating. Properties can also be easily extended from the binary case to the finitary case by iterating. * Then we can use the equivalence `List.TProd.piEquivTProd` below (or enhanced versions of it, like a `MeasurableEquiv` for product measures) to get the construction on `∀ i : ι, α i`, at least when assuming `[Fintype ι] [Encodable ι]` (using `Encodable.sortedUniv`). Using `attribute [local instance] Fintype.toEncodable` we can get rid of the argument `[Encodable ι]`. ## Main definitions * We have the equivalence `TProd.piEquivTProd : (∀ i, α i) ≃ TProd α l` if `l` contains every element of `ι` exactly once. * The product of sets is `Set.tprod : (∀ i, Set (α i)) → Set (TProd α l)`. -/ open List Function universe u v variable {ι : Type u} {α : ι → Type v} {i j : ι} {l : List ι} namespace List variable (α) in /-- The product of a family of types over a list. -/ abbrev TProd (l : List ι) : Type v := l.foldr (fun i β => α i × β) PUnit namespace TProd open List /-- Turning a function `f : ∀ i, α i` into an element of the iterated product `TProd α l`. -/ protected def mk : ∀ (l : List ι) (_f : ∀ i, α i), TProd α l | [] => fun _ => PUnit.unit | i :: is => fun f => (f i, TProd.mk is f) instance [∀ i, Inhabited (α i)] : Inhabited (TProd α l) := ⟨TProd.mk l default⟩ @[simp] theorem fst_mk (i : ι) (l : List ι) (f : ∀ i, α i) : (TProd.mk (i :: l) f).1 = f i := rfl @[simp] theorem snd_mk (i : ι) (l : List ι) (f : ∀ i, α i) : (TProd.mk.{u,v} (i :: l) f).2 = TProd.mk.{u,v} l f := rfl variable [DecidableEq ι] /-- Given an element of the iterated product `l.Prod α`, take a projection into direction `i`. If `i` appears multiple times in `l`, this chooses the first component in direction `i`. -/ protected def elim : ∀ {l : List ι} (_ : TProd α l) {i : ι} (_ : i ∈ l), α i | i :: is, v, j, hj => if hji : j = i then by subst hji exact v.1 else TProd.elim v.2 ((List.mem_cons.mp hj).resolve_left hji) @[simp] theorem elim_self (v : TProd α (i :: l)) : v.elim mem_cons_self = v.1 := by simp [TProd.elim] @[simp] theorem elim_of_ne (hj : j ∈ i :: l) (hji : j ≠ i) (v : TProd α (i :: l)) : v.elim hj = TProd.elim v.2 ((List.mem_cons.mp hj).resolve_left hji) := by simp [TProd.elim, hji] @[simp] theorem elim_of_mem (hl : (i :: l).Nodup) (hj : j ∈ l) (v : TProd α (i :: l)) : v.elim (mem_cons_of_mem _ hj) = TProd.elim v.2 hj := by apply elim_of_ne rintro rfl exact hl.not_mem hj theorem elim_mk : ∀ (l : List ι) (f : ∀ i, α i) {i : ι} (hi : i ∈ l), (TProd.mk l f).elim hi = f i | i :: is, f, j, hj => by by_cases hji : j = i · subst hji simp · rw [TProd.elim_of_ne _ hji, snd_mk, elim_mk is] @[ext] theorem ext : ∀ {l : List ι} (_ : l.Nodup) {v w : TProd α l} (_ : ∀ (i) (hi : i ∈ l), v.elim hi = w.elim hi), v = w | [], _, v, w, _ => PUnit.ext v w | i :: is, hl, v, w, hvw => by apply Prod.ext · rw [← elim_self v, hvw, elim_self] refine ext (nodup_cons.mp hl).2 fun j hj => ?_ rw [← elim_of_mem hl, hvw, elim_of_mem hl] /-- A version of `TProd.elim` when `l` contains all elements. In this case we get a function into `Π i, α i`. -/ @[simp] protected def elim' (h : ∀ i, i ∈ l) (v : TProd α l) (i : ι) : α i := v.elim (h i) theorem mk_elim (hnd : l.Nodup) (h : ∀ i, i ∈ l) (v : TProd α l) : TProd.mk l (v.elim' h) = v := TProd.ext hnd fun i hi => by simp [elim_mk] /-- Pi-types are equivalent to iterated products. -/ def piEquivTProd (hnd : l.Nodup) (h : ∀ i, i ∈ l) : (∀ i, α i) ≃ TProd α l := ⟨TProd.mk l, TProd.elim' h, fun f => funext fun i => elim_mk l f (h i), mk_elim hnd h⟩ end TProd end List namespace Set open List /-- A product of sets in `TProd α l`. -/ @[simp] protected def tprod : ∀ (l : List ι) (_t : ∀ i, Set (α i)), Set (TProd α l) | [], _ => univ | i :: is, t => t i ×ˢ Set.tprod is t theorem mk_preimage_tprod : ∀ (l : List ι) (t : ∀ i, Set (α i)), TProd.mk l ⁻¹' Set.tprod l t = { i | i ∈ l }.pi t | [], t => by simp [Set.tprod] | i :: l, t => by ext f have h : TProd.mk l f ∈ Set.tprod l t ↔ ∀ i : ι, i ∈ l → f i ∈ t i := by change f ∈ TProd.mk l ⁻¹' Set.tprod l t ↔ f ∈ { x | x ∈ l }.pi t rw [mk_preimage_tprod l t] -- `simp [Set.TProd, TProd.mk, this]` can close this goal but is slow. rw [Set.tprod, TProd.mk, mem_preimage, mem_pi, prodMk_mem_set_prod_eq] simp_rw [mem_setOf_eq, mem_cons] rw [forall_eq_or_imp, and_congr_right_iff] exact fun _ => h theorem elim_preimage_pi [DecidableEq ι] {l : List ι} (hnd : l.Nodup) (h : ∀ i, i ∈ l) (t : ∀ i, Set (α i)) : TProd.elim' h ⁻¹' pi univ t = Set.tprod l t := by have h2 : { i | i ∈ l } = univ := by ext i simp [h] rw [← h2, ← mk_preimage_tprod, preimage_preimage] simp only [TProd.mk_elim hnd h] dsimp end Set
Mathlib/Data/Prod/TProd.lean
173
180
/- 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.BigOperators.Group.Finset.Indicator import Mathlib.Algebra.Module.BigOperators import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.Tactic.FinCases /-! # 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 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) @[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] /-- 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] lemma weightedVSubOfPoint_vadd (s : Finset ι) (w : ι → k) (p : ι → P) (b : P) (v : V) : s.weightedVSubOfPoint (v +ᵥ p) b w = s.weightedVSubOfPoint p (-v +ᵥ b) w := by simp [vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, add_comm] lemma weightedVSubOfPoint_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] (s : Finset ι) (w : ι → k) (p : ι → V) (b : V) (a : G) : s.weightedVSubOfPoint (a • p) b w = a • s.weightedVSubOfPoint p (a⁻¹ • b) w := by simp [smul_sum, smul_sub, smul_comm a (w _)] /-- `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] /-- 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] /-- 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] /-- 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 rw [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] /-- 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] /-- 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] /-- 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 _ /-- 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 _ _ _ /-- 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] /-- 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] /-- 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] /-- 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] /-- 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] /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ 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) = {x ∈ s | pred x}.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_subtype_eq_sum_filter] /-- A weighted sum over `{x ∈ s | pred x}` 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) : {x ∈ s | pred x}.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 /-- 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] /-- 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) /-- 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] /-- `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 _ _ /-- 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] /-- 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] lemma weightedVSub_vadd {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → P) (v : V) : s.weightedVSub (v +ᵥ p) w = s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_vadd, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] lemma weightedVSub_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → V) (a : G) : s.weightedVSub (a • p) w = a • s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_smul, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] /-- `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 _ /-- 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 /-- 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 _ _ _ _ /-- 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 _ _ _ _ /-- 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] /-- 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] /-- 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 _ _ _ /-- 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 _ _ _ /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ 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) = {x ∈ s | pred x}.weightedVSub p w := s.weightedVSubOfPoint_subtype_eq_filter _ _ _ _ /-- A weighted sum over `{x ∈ s | pred x}` 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) : {x ∈ s | pred x}.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_filter_of_ne _ _ _ h /-- 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 _ _ _ _ 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] /-- The linear map corresponding to `affineCombination` is `weightedVSub`. -/ @[simp] theorem affineCombination_linear (p : ι → P) : (s.affineCombination k p).linear = s.weightedVSub p := rfl 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 /-- 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] /-- `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] /-- `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 _ _ /-- 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] /-- 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] 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 [g₁, g₂] rw [hgf, sum_image] · simp only [g₁, g₂,Function.comp_apply] · exact fun _ _ _ _ hxy => hf hxy 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] /-- 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] /-- 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] /-- 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] /-- 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] /-- 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] /-- 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 _ _ _ _ /-- 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] /-- 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] /-- 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 _ _ /-- 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) : {x ∈ s | x ≠ 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 /-- An affine combination over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ 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) = {x ∈ s | pred x}.affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_subtype_eq_filter] /-- An affine combination over `{x ∈ s | pred x}` 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) : {x ∈ s | pred x}.affineCombination k p w = s.affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, s.weightedVSubOfPoint_filter_of_ne _ _ _ h] /-- 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. -/
Mathlib/LinearAlgebra/AffineSpace/Combination.lean
526
530
/- 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 -/ import Mathlib.Data.Matrix.Basic import Mathlib.Data.Matrix.Composition import Mathlib.Data.Matrix.ConjTranspose /-! # Block Matrices ## Main definitions * `Matrix.fromBlocks`: build a block matrix out of 4 blocks * `Matrix.toBlocks₁₁`, `Matrix.toBlocks₁₂`, `Matrix.toBlocks₂₁`, `Matrix.toBlocks₂₂`: extract each of the four blocks from `Matrix.fromBlocks`. * `Matrix.blockDiagonal`: block diagonal of equally sized blocks. On square blocks, this is a ring homomorphisms, `Matrix.blockDiagonalRingHom`. * `Matrix.blockDiag`: extract the blocks from the diagonal of a block diagonal matrix. * `Matrix.blockDiagonal'`: block diagonal of unequally sized blocks. On square blocks, this is a ring homomorphisms, `Matrix.blockDiagonal'RingHom`. * `Matrix.blockDiag'`: extract the blocks from the diagonal of a block diagonal matrix. -/ variable {l m n o p q : Type*} {m' n' p' : o → Type*} variable {R : Type*} {S : Type*} {α : Type*} {β : Type*} open Matrix namespace Matrix theorem dotProduct_block [Fintype m] [Fintype n] [Mul α] [AddCommMonoid α] (v w : m ⊕ n → α) : v ⬝ᵥ w = v ∘ Sum.inl ⬝ᵥ w ∘ Sum.inl + v ∘ Sum.inr ⬝ᵥ w ∘ Sum.inr := Fintype.sum_sum_type _ section BlockMatrices /-- We can form a single large matrix by flattening smaller 'block' matrices of compatible dimensions. -/ @[pp_nodot] def fromBlocks (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : Matrix (n ⊕ o) (l ⊕ m) α := of <| Sum.elim (fun i => Sum.elim (A i) (B i)) (fun j => Sum.elim (C j) (D j)) @[simp] theorem fromBlocks_apply₁₁ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (i : n) (j : l) : fromBlocks A B C D (Sum.inl i) (Sum.inl j) = A i j := rfl @[simp] theorem fromBlocks_apply₁₂ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (i : n) (j : m) : fromBlocks A B C D (Sum.inl i) (Sum.inr j) = B i j := rfl @[simp] theorem fromBlocks_apply₂₁ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (i : o) (j : l) : fromBlocks A B C D (Sum.inr i) (Sum.inl j) = C i j := rfl @[simp] theorem fromBlocks_apply₂₂ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (i : o) (j : m) : fromBlocks A B C D (Sum.inr i) (Sum.inr j) = D i j := rfl /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "top left" submatrix. -/ def toBlocks₁₁ (M : Matrix (n ⊕ o) (l ⊕ m) α) : Matrix n l α := of fun i j => M (Sum.inl i) (Sum.inl j) /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "top right" submatrix. -/ def toBlocks₁₂ (M : Matrix (n ⊕ o) (l ⊕ m) α) : Matrix n m α := of fun i j => M (Sum.inl i) (Sum.inr j) /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "bottom left" submatrix. -/ def toBlocks₂₁ (M : Matrix (n ⊕ o) (l ⊕ m) α) : Matrix o l α := of fun i j => M (Sum.inr i) (Sum.inl j) /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "bottom right" submatrix. -/ def toBlocks₂₂ (M : Matrix (n ⊕ o) (l ⊕ m) α) : Matrix o m α := of fun i j => M (Sum.inr i) (Sum.inr j) theorem fromBlocks_toBlocks (M : Matrix (n ⊕ o) (l ⊕ m) α) : fromBlocks M.toBlocks₁₁ M.toBlocks₁₂ M.toBlocks₂₁ M.toBlocks₂₂ = M := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> rfl @[simp] theorem toBlocks_fromBlocks₁₁ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).toBlocks₁₁ = A := rfl @[simp] theorem toBlocks_fromBlocks₁₂ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).toBlocks₁₂ = B := rfl @[simp] theorem toBlocks_fromBlocks₂₁ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).toBlocks₂₁ = C := rfl @[simp] theorem toBlocks_fromBlocks₂₂ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).toBlocks₂₂ = D := rfl /-- Two block matrices are equal if their blocks are equal. -/ theorem ext_iff_blocks {A B : Matrix (n ⊕ o) (l ⊕ m) α} : A = B ↔ A.toBlocks₁₁ = B.toBlocks₁₁ ∧ A.toBlocks₁₂ = B.toBlocks₁₂ ∧ A.toBlocks₂₁ = B.toBlocks₂₁ ∧ A.toBlocks₂₂ = B.toBlocks₂₂ := ⟨fun h => h ▸ ⟨rfl, rfl, rfl, rfl⟩, fun ⟨h₁₁, h₁₂, h₂₁, h₂₂⟩ => by rw [← fromBlocks_toBlocks A, ← fromBlocks_toBlocks B, h₁₁, h₁₂, h₂₁, h₂₂]⟩ @[simp] theorem fromBlocks_inj {A : Matrix n l α} {B : Matrix n m α} {C : Matrix o l α} {D : Matrix o m α} {A' : Matrix n l α} {B' : Matrix n m α} {C' : Matrix o l α} {D' : Matrix o m α} : fromBlocks A B C D = fromBlocks A' B' C' D' ↔ A = A' ∧ B = B' ∧ C = C' ∧ D = D' := ext_iff_blocks theorem fromBlocks_map (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (f : α → β) : (fromBlocks A B C D).map f = fromBlocks (A.map f) (B.map f) (C.map f) (D.map f) := by ext i j; rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [fromBlocks] theorem fromBlocks_transpose (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D)ᵀ = fromBlocks Aᵀ Cᵀ Bᵀ Dᵀ := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [fromBlocks] theorem fromBlocks_conjTranspose [Star α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D)ᴴ = fromBlocks Aᴴ Cᴴ Bᴴ Dᴴ := by simp only [conjTranspose, fromBlocks_transpose, fromBlocks_map] @[simp] theorem fromBlocks_submatrix_sum_swap_left (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (f : p → l ⊕ m) : (fromBlocks A B C D).submatrix Sum.swap f = (fromBlocks C D A B).submatrix id f := by ext i j cases i <;> dsimp <;> cases f j <;> rfl @[simp] theorem fromBlocks_submatrix_sum_swap_right (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (f : p → n ⊕ o) : (fromBlocks A B C D).submatrix f Sum.swap = (fromBlocks B A D C).submatrix f id := by ext i j cases j <;> dsimp <;> cases f i <;> rfl theorem fromBlocks_submatrix_sum_swap_sum_swap {l m n o α : Type*} (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).submatrix Sum.swap Sum.swap = fromBlocks D C B A := by simp /-- A 2x2 block matrix is block diagonal if the blocks outside of the diagonal vanish -/ def IsTwoBlockDiagonal [Zero α] (A : Matrix (n ⊕ o) (l ⊕ m) α) : Prop := toBlocks₁₂ A = 0 ∧ toBlocks₂₁ A = 0 /-- Let `p` pick out certain rows and `q` pick out certain columns of a matrix `M`. Then `toBlock M p q` is the corresponding block matrix. -/ def toBlock (M : Matrix m n α) (p : m → Prop) (q : n → Prop) : Matrix { a // p a } { a // q a } α := M.submatrix (↑) (↑) @[simp] theorem toBlock_apply (M : Matrix m n α) (p : m → Prop) (q : n → Prop) (i : { a // p a }) (j : { a // q a }) : toBlock M p q i j = M ↑i ↑j := rfl /-- Let `p` pick out certain rows and columns of a square matrix `M`. Then `toSquareBlockProp M p` is the corresponding block matrix. -/ def toSquareBlockProp (M : Matrix m m α) (p : m → Prop) : Matrix { a // p a } { a // p a } α := toBlock M _ _ theorem toSquareBlockProp_def (M : Matrix m m α) (p : m → Prop) : toSquareBlockProp M p = of (fun i j : { a // p a } => M ↑i ↑j) := rfl /-- Let `b` map rows and columns of a square matrix `M` to blocks. Then `toSquareBlock M b k` is the block `k` matrix. -/ def toSquareBlock (M : Matrix m m α) (b : m → β) (k : β) : Matrix { a // b a = k } { a // b a = k } α := toSquareBlockProp M _ theorem toSquareBlock_def (M : Matrix m m α) (b : m → β) (k : β) : toSquareBlock M b k = of (fun i j : { a // b a = k } => M ↑i ↑j) := rfl theorem fromBlocks_smul [SMul R α] (x : R) (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : x • fromBlocks A B C D = fromBlocks (x • A) (x • B) (x • C) (x • D) := by ext i j; rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [fromBlocks] theorem fromBlocks_neg [Neg R] (A : Matrix n l R) (B : Matrix n m R) (C : Matrix o l R) (D : Matrix o m R) : -fromBlocks A B C D = fromBlocks (-A) (-B) (-C) (-D) := by ext i j cases i <;> cases j <;> simp [fromBlocks] @[simp] theorem fromBlocks_zero [Zero α] : fromBlocks (0 : Matrix n l α) 0 0 (0 : Matrix o m α) = 0 := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> rfl theorem fromBlocks_add [Add α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (A' : Matrix n l α) (B' : Matrix n m α) (C' : Matrix o l α) (D' : Matrix o m α) : fromBlocks A B C D + fromBlocks A' B' C' D' = fromBlocks (A + A') (B + B') (C + C') (D + D') := by ext i j; rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> rfl theorem fromBlocks_multiply [Fintype l] [Fintype m] [NonUnitalNonAssocSemiring α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (A' : Matrix l p α) (B' : Matrix l q α) (C' : Matrix m p α) (D' : Matrix m q α) : fromBlocks A B C D * fromBlocks A' B' C' D' = fromBlocks (A * A' + B * C') (A * B' + B * D') (C * A' + D * C') (C * B' + D * D') := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp only [fromBlocks, mul_apply, of_apply, Sum.elim_inr, Fintype.sum_sum_type, Sum.elim_inl, add_apply] theorem fromBlocks_mulVec [Fintype l] [Fintype m] [NonUnitalNonAssocSemiring α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (x : l ⊕ m → α) : (fromBlocks A B C D) *ᵥ x = Sum.elim (A *ᵥ (x ∘ Sum.inl) + B *ᵥ (x ∘ Sum.inr)) (C *ᵥ (x ∘ Sum.inl) + D *ᵥ (x ∘ Sum.inr)) := by ext i cases i <;> simp [mulVec, dotProduct] theorem vecMul_fromBlocks [Fintype n] [Fintype o] [NonUnitalNonAssocSemiring α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (x : n ⊕ o → α) : x ᵥ* fromBlocks A B C D = Sum.elim ((x ∘ Sum.inl) ᵥ* A + (x ∘ Sum.inr) ᵥ* C) ((x ∘ Sum.inl) ᵥ* B + (x ∘ Sum.inr) ᵥ* D) := by ext i cases i <;> simp [vecMul, dotProduct] variable [DecidableEq l] [DecidableEq m] section Zero variable [Zero α] theorem toBlock_diagonal_self (d : m → α) (p : m → Prop) : Matrix.toBlock (diagonal d) p p = diagonal fun i : Subtype p => d ↑i := by ext i j by_cases h : i = j · simp [h] · simp [One.one, h, Subtype.val_injective.ne h] theorem toBlock_diagonal_disjoint (d : m → α) {p q : m → Prop} (hpq : Disjoint p q) : Matrix.toBlock (diagonal d) p q = 0 := by ext ⟨i, hi⟩ ⟨j, hj⟩ have : i ≠ j := fun heq => hpq.le_bot i ⟨hi, heq.symm ▸ hj⟩ simp [diagonal_apply_ne d this] @[simp] theorem fromBlocks_diagonal (d₁ : l → α) (d₂ : m → α) : fromBlocks (diagonal d₁) 0 0 (diagonal d₂) = diagonal (Sum.elim d₁ d₂) := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [diagonal] @[simp] lemma toBlocks₁₁_diagonal (v : l ⊕ m → α) : toBlocks₁₁ (diagonal v) = diagonal (fun i => v (Sum.inl i)) := by unfold toBlocks₁₁ funext i j simp only [ne_eq, Sum.inl.injEq, of_apply, diagonal_apply] @[simp] lemma toBlocks₂₂_diagonal (v : l ⊕ m → α) : toBlocks₂₂ (diagonal v) = diagonal (fun i => v (Sum.inr i)) := by unfold toBlocks₂₂ funext i j simp only [ne_eq, Sum.inr.injEq, of_apply, diagonal_apply] @[simp] lemma toBlocks₁₂_diagonal (v : l ⊕ m → α) : toBlocks₁₂ (diagonal v) = 0 := rfl @[simp] lemma toBlocks₂₁_diagonal (v : l ⊕ m → α) : toBlocks₂₁ (diagonal v) = 0 := rfl end Zero section HasZeroHasOne variable [Zero α] [One α] @[simp] theorem fromBlocks_one : fromBlocks (1 : Matrix l l α) 0 0 (1 : Matrix m m α) = 1 := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [one_apply] @[simp] theorem toBlock_one_self (p : m → Prop) : Matrix.toBlock (1 : Matrix m m α) p p = 1 := toBlock_diagonal_self _ p theorem toBlock_one_disjoint {p q : m → Prop} (hpq : Disjoint p q) : Matrix.toBlock (1 : Matrix m m α) p q = 0 := toBlock_diagonal_disjoint _ hpq end HasZeroHasOne end BlockMatrices section BlockDiagonal variable [DecidableEq o] section Zero variable [Zero α] [Zero β] /-- `Matrix.blockDiagonal M` turns a homogeneously-indexed collection of matrices `M : o → Matrix m n α'` into an `m × o`-by-`n × o` block matrix which has the entries of `M` along the diagonal and zero elsewhere. See also `Matrix.blockDiagonal'` if the matrices may not have the same size everywhere. -/ def blockDiagonal (M : o → Matrix m n α) : Matrix (m × o) (n × o) α := of <| (fun ⟨i, k⟩ ⟨j, k'⟩ => if k = k' then M k i j else 0 : m × o → n × o → α) -- TODO: set as an equation lemma for `blockDiagonal`, see https://github.com/leanprover-community/mathlib4/pull/3024 theorem blockDiagonal_apply' (M : o → Matrix m n α) (i k j k') : blockDiagonal M ⟨i, k⟩ ⟨j, k'⟩ = if k = k' then M k i j else 0 := rfl theorem blockDiagonal_apply (M : o → Matrix m n α) (ik jk) : blockDiagonal M ik jk = if ik.2 = jk.2 then M ik.2 ik.1 jk.1 else 0 := by cases ik cases jk rfl @[simp] theorem blockDiagonal_apply_eq (M : o → Matrix m n α) (i j k) : blockDiagonal M (i, k) (j, k) = M k i j := if_pos rfl theorem blockDiagonal_apply_ne (M : o → Matrix m n α) (i j) {k k'} (h : k ≠ k') : blockDiagonal M (i, k) (j, k') = 0 := if_neg h theorem blockDiagonal_map (M : o → Matrix m n α) (f : α → β) (hf : f 0 = 0) : (blockDiagonal M).map f = blockDiagonal fun k => (M k).map f := by ext simp only [map_apply, blockDiagonal_apply, eq_comm] rw [apply_ite f, hf] @[simp] theorem blockDiagonal_transpose (M : o → Matrix m n α) : (blockDiagonal M)ᵀ = blockDiagonal fun k => (M k)ᵀ := by ext simp only [transpose_apply, blockDiagonal_apply, eq_comm] split_ifs with h · rw [h] · rfl @[simp] theorem blockDiagonal_conjTranspose {α : Type*} [AddMonoid α] [StarAddMonoid α] (M : o → Matrix m n α) : (blockDiagonal M)ᴴ = blockDiagonal fun k => (M k)ᴴ := by simp only [conjTranspose, blockDiagonal_transpose] rw [blockDiagonal_map _ star (star_zero α)] @[simp] theorem blockDiagonal_zero : blockDiagonal (0 : o → Matrix m n α) = 0 := by ext simp [blockDiagonal_apply] @[simp] theorem blockDiagonal_diagonal [DecidableEq m] (d : o → m → α) : (blockDiagonal fun k => diagonal (d k)) = diagonal fun ik => d ik.2 ik.1 := by ext ⟨i, k⟩ ⟨j, k'⟩ simp only [blockDiagonal_apply, diagonal_apply, Prod.mk_inj, ← ite_and] congr 1 rw [and_comm] @[simp] theorem blockDiagonal_one [DecidableEq m] [One α] : blockDiagonal (1 : o → Matrix m m α) = 1 := show (blockDiagonal fun _ : o => diagonal fun _ : m => (1 : α)) = diagonal fun _ => 1 by rw [blockDiagonal_diagonal] end Zero @[simp] theorem blockDiagonal_add [AddZeroClass α] (M N : o → Matrix m n α) : blockDiagonal (M + N) = blockDiagonal M + blockDiagonal N := by ext simp only [blockDiagonal_apply, Pi.add_apply, add_apply] split_ifs <;> simp section variable (o m n α) /-- `Matrix.blockDiagonal` as an `AddMonoidHom`. -/ @[simps] def blockDiagonalAddMonoidHom [AddZeroClass α] : (o → Matrix m n α) →+ Matrix (m × o) (n × o) α where toFun := blockDiagonal map_zero' := blockDiagonal_zero map_add' := blockDiagonal_add end @[simp] theorem blockDiagonal_neg [AddGroup α] (M : o → Matrix m n α) : blockDiagonal (-M) = -blockDiagonal M := map_neg (blockDiagonalAddMonoidHom m n o α) M @[simp] theorem blockDiagonal_sub [AddGroup α] (M N : o → Matrix m n α) : blockDiagonal (M - N) = blockDiagonal M - blockDiagonal N := map_sub (blockDiagonalAddMonoidHom m n o α) M N @[simp] theorem blockDiagonal_mul [Fintype n] [Fintype o] [NonUnitalNonAssocSemiring α] (M : o → Matrix m n α) (N : o → Matrix n p α) : (blockDiagonal fun k => M k * N k) = blockDiagonal M * blockDiagonal N := by ext ⟨i, k⟩ ⟨j, k'⟩ simp only [blockDiagonal_apply, mul_apply, ← Finset.univ_product_univ, Finset.sum_product] split_ifs with h <;> simp [h] section variable (α m o) /-- `Matrix.blockDiagonal` as a `RingHom`. -/ @[simps] def blockDiagonalRingHom [DecidableEq m] [Fintype o] [Fintype m] [NonAssocSemiring α] : (o → Matrix m m α) →+* Matrix (m × o) (m × o) α := { blockDiagonalAddMonoidHom m m o α with toFun := blockDiagonal map_one' := blockDiagonal_one map_mul' := blockDiagonal_mul } end @[simp] theorem blockDiagonal_pow [DecidableEq m] [Fintype o] [Fintype m] [Semiring α] (M : o → Matrix m m α) (n : ℕ) : blockDiagonal (M ^ n) = blockDiagonal M ^ n := map_pow (blockDiagonalRingHom m o α) M n @[simp] theorem blockDiagonal_smul {R : Type*} [Zero α] [SMulZeroClass R α] (x : R) (M : o → Matrix m n α) : blockDiagonal (x • M) = x • blockDiagonal M := by ext simp only [blockDiagonal_apply, Pi.smul_apply, smul_apply] split_ifs <;> simp end BlockDiagonal section BlockDiag /-- Extract a block from the diagonal of a block diagonal matrix. This is the block form of `Matrix.diag`, and the left-inverse of `Matrix.blockDiagonal`. -/ def blockDiag (M : Matrix (m × o) (n × o) α) (k : o) : Matrix m n α := of fun i j => M (i, k) (j, k) -- TODO: set as an equation lemma for `blockDiag`, see https://github.com/leanprover-community/mathlib4/pull/3024 theorem blockDiag_apply (M : Matrix (m × o) (n × o) α) (k : o) (i j) : blockDiag M k i j = M (i, k) (j, k) := rfl theorem blockDiag_map (M : Matrix (m × o) (n × o) α) (f : α → β) : blockDiag (M.map f) = fun k => (blockDiag M k).map f := rfl @[simp] theorem blockDiag_transpose (M : Matrix (m × o) (n × o) α) (k : o) : blockDiag Mᵀ k = (blockDiag M k)ᵀ := ext fun _ _ => rfl @[simp] theorem blockDiag_conjTranspose {α : Type*} [Star α] (M : Matrix (m × o) (n × o) α) (k : o) : blockDiag Mᴴ k = (blockDiag M k)ᴴ := ext fun _ _ => rfl section Zero variable [Zero α] [Zero β] @[simp] theorem blockDiag_zero : blockDiag (0 : Matrix (m × o) (n × o) α) = 0 := rfl @[simp] theorem blockDiag_diagonal [DecidableEq o] [DecidableEq m] (d : m × o → α) (k : o) : blockDiag (diagonal d) k = diagonal fun i => d (i, k) := ext fun i j => by obtain rfl | hij := Decidable.eq_or_ne i j · rw [blockDiag_apply, diagonal_apply_eq, diagonal_apply_eq] · rw [blockDiag_apply, diagonal_apply_ne _ hij, diagonal_apply_ne _ (mt _ hij)] exact Prod.fst_eq_iff.mpr @[simp] theorem blockDiag_blockDiagonal [DecidableEq o] (M : o → Matrix m n α) : blockDiag (blockDiagonal M) = M := funext fun _ => ext fun i j => blockDiagonal_apply_eq M i j _ theorem blockDiagonal_injective [DecidableEq o] : Function.Injective (blockDiagonal : (o → Matrix m n α) → Matrix _ _ α) := Function.LeftInverse.injective blockDiag_blockDiagonal @[simp] theorem blockDiagonal_inj [DecidableEq o] {M N : o → Matrix m n α} : blockDiagonal M = blockDiagonal N ↔ M = N := blockDiagonal_injective.eq_iff @[simp] theorem blockDiag_one [DecidableEq o] [DecidableEq m] [One α] : blockDiag (1 : Matrix (m × o) (m × o) α) = 1 := funext <| blockDiag_diagonal _ end Zero @[simp] theorem blockDiag_add [Add α] (M N : Matrix (m × o) (n × o) α) : blockDiag (M + N) = blockDiag M + blockDiag N := rfl section variable (o m n α) /-- `Matrix.blockDiag` as an `AddMonoidHom`. -/ @[simps] def blockDiagAddMonoidHom [AddZeroClass α] : Matrix (m × o) (n × o) α →+ o → Matrix m n α where toFun := blockDiag map_zero' := blockDiag_zero map_add' := blockDiag_add end @[simp] theorem blockDiag_neg [AddGroup α] (M : Matrix (m × o) (n × o) α) : blockDiag (-M) = -blockDiag M := map_neg (blockDiagAddMonoidHom m n o α) M @[simp] theorem blockDiag_sub [AddGroup α] (M N : Matrix (m × o) (n × o) α) : blockDiag (M - N) = blockDiag M - blockDiag N := map_sub (blockDiagAddMonoidHom m n o α) M N @[simp] theorem blockDiag_smul {R : Type*} [SMul R α] (x : R) (M : Matrix (m × o) (n × o) α) : blockDiag (x • M) = x • blockDiag M := rfl end BlockDiag section BlockDiagonal' variable [DecidableEq o] section Zero variable [Zero α] [Zero β] /-- `Matrix.blockDiagonal' M` turns `M : Π i, Matrix (m i) (n i) α` into a `Σ i, m i`-by-`Σ i, n i` block matrix which has the entries of `M` along the diagonal and zero elsewhere. This is the dependently-typed version of `Matrix.blockDiagonal`. -/ def blockDiagonal' (M : ∀ i, Matrix (m' i) (n' i) α) : Matrix (Σ i, m' i) (Σ i, n' i) α := of <| (fun ⟨k, i⟩ ⟨k', j⟩ => if h : k = k' then M k i (cast (congr_arg n' h.symm) j) else 0 : (Σ i, m' i) → (Σ i, n' i) → α) -- TODO: set as an equation lemma for `blockDiagonal'`, see https://github.com/leanprover-community/mathlib4/pull/3024 theorem blockDiagonal'_apply' (M : ∀ i, Matrix (m' i) (n' i) α) (k i k' j) : blockDiagonal' M ⟨k, i⟩ ⟨k', j⟩ = if h : k = k' then M k i (cast (congr_arg n' h.symm) j) else 0 := rfl theorem blockDiagonal'_eq_blockDiagonal (M : o → Matrix m n α) {k k'} (i j) : blockDiagonal M (i, k) (j, k') = blockDiagonal' M ⟨k, i⟩ ⟨k', j⟩ := rfl theorem blockDiagonal'_submatrix_eq_blockDiagonal (M : o → Matrix m n α) : (blockDiagonal' M).submatrix (Prod.toSigma ∘ Prod.swap) (Prod.toSigma ∘ Prod.swap) = blockDiagonal M := Matrix.ext fun ⟨_, _⟩ ⟨_, _⟩ => rfl theorem blockDiagonal'_apply (M : ∀ i, Matrix (m' i) (n' i) α) (ik jk) : blockDiagonal' M ik jk = if h : ik.1 = jk.1 then M ik.1 ik.2 (cast (congr_arg n' h.symm) jk.2) else 0 := by cases ik cases jk rfl @[simp] theorem blockDiagonal'_apply_eq (M : ∀ i, Matrix (m' i) (n' i) α) (k i j) : blockDiagonal' M ⟨k, i⟩ ⟨k, j⟩ = M k i j := dif_pos rfl theorem blockDiagonal'_apply_ne (M : ∀ i, Matrix (m' i) (n' i) α) {k k'} (i j) (h : k ≠ k') : blockDiagonal' M ⟨k, i⟩ ⟨k', j⟩ = 0 := dif_neg h theorem blockDiagonal'_map (M : ∀ i, Matrix (m' i) (n' i) α) (f : α → β) (hf : f 0 = 0) : (blockDiagonal' M).map f = blockDiagonal' fun k => (M k).map f := by ext simp only [map_apply, blockDiagonal'_apply, eq_comm] rw [apply_dite f, hf] @[simp] theorem blockDiagonal'_transpose (M : ∀ i, Matrix (m' i) (n' i) α) : (blockDiagonal' M)ᵀ = blockDiagonal' fun k => (M k)ᵀ := by ext ⟨ii, ix⟩ ⟨ji, jx⟩ simp only [transpose_apply, blockDiagonal'_apply] split_ifs <;> cc @[simp] theorem blockDiagonal'_conjTranspose {α} [AddMonoid α] [StarAddMonoid α] (M : ∀ i, Matrix (m' i) (n' i) α) : (blockDiagonal' M)ᴴ = blockDiagonal' fun k => (M k)ᴴ := by simp only [conjTranspose, blockDiagonal'_transpose] exact blockDiagonal'_map _ star (star_zero α) @[simp] theorem blockDiagonal'_zero : blockDiagonal' (0 : ∀ i, Matrix (m' i) (n' i) α) = 0 := by ext simp [blockDiagonal'_apply] @[simp] theorem blockDiagonal'_diagonal [∀ i, DecidableEq (m' i)] (d : ∀ i, m' i → α) : (blockDiagonal' fun k => diagonal (d k)) = diagonal fun ik => d ik.1 ik.2 := by ext ⟨i, k⟩ ⟨j, k'⟩ simp only [blockDiagonal'_apply, diagonal] obtain rfl | hij := Decidable.eq_or_ne i j · simp · simp [hij] @[simp] theorem blockDiagonal'_one [∀ i, DecidableEq (m' i)] [One α] : blockDiagonal' (1 : ∀ i, Matrix (m' i) (m' i) α) = 1 := show (blockDiagonal' fun i : o => diagonal fun _ : m' i => (1 : α)) = diagonal fun _ => 1 by rw [blockDiagonal'_diagonal] end Zero @[simp] theorem blockDiagonal'_add [AddZeroClass α] (M N : ∀ i, Matrix (m' i) (n' i) α) : blockDiagonal' (M + N) = blockDiagonal' M + blockDiagonal' N := by ext simp only [blockDiagonal'_apply, Pi.add_apply, add_apply] split_ifs <;> simp section variable (m' n' α) /-- `Matrix.blockDiagonal'` as an `AddMonoidHom`. -/ @[simps] def blockDiagonal'AddMonoidHom [AddZeroClass α] : (∀ i, Matrix (m' i) (n' i) α) →+ Matrix (Σ i, m' i) (Σ i, n' i) α where toFun := blockDiagonal' map_zero' := blockDiagonal'_zero map_add' := blockDiagonal'_add end @[simp] theorem blockDiagonal'_neg [AddGroup α] (M : ∀ i, Matrix (m' i) (n' i) α) : blockDiagonal' (-M) = -blockDiagonal' M := map_neg (blockDiagonal'AddMonoidHom m' n' α) M @[simp] theorem blockDiagonal'_sub [AddGroup α] (M N : ∀ i, Matrix (m' i) (n' i) α) : blockDiagonal' (M - N) = blockDiagonal' M - blockDiagonal' N := map_sub (blockDiagonal'AddMonoidHom m' n' α) M N @[simp] theorem blockDiagonal'_mul [NonUnitalNonAssocSemiring α] [∀ i, Fintype (n' i)] [Fintype o] (M : ∀ i, Matrix (m' i) (n' i) α) (N : ∀ i, Matrix (n' i) (p' i) α) : (blockDiagonal' fun k => M k * N k) = blockDiagonal' M * blockDiagonal' N := by ext ⟨k, i⟩ ⟨k', j⟩ simp only [blockDiagonal'_apply, mul_apply, ← Finset.univ_sigma_univ, Finset.sum_sigma] rw [Fintype.sum_eq_single k] · simp only [if_pos, dif_pos] split_ifs <;> simp · intro j' hj' exact Finset.sum_eq_zero fun _ _ => by rw [dif_neg hj'.symm, zero_mul] section variable (α m') /-- `Matrix.blockDiagonal'` as a `RingHom`. -/ @[simps] def blockDiagonal'RingHom [∀ i, DecidableEq (m' i)] [Fintype o] [∀ i, Fintype (m' i)] [NonAssocSemiring α] : (∀ i, Matrix (m' i) (m' i) α) →+* Matrix (Σ i, m' i) (Σ i, m' i) α := { blockDiagonal'AddMonoidHom m' m' α with toFun := blockDiagonal' map_one' := blockDiagonal'_one map_mul' := blockDiagonal'_mul }
end @[simp] theorem blockDiagonal'_pow [∀ i, DecidableEq (m' i)] [Fintype o] [∀ i, Fintype (m' i)] [Semiring α]
Mathlib/Data/Matrix/Block.lean
693
697
/- 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 Kudryashov, Patrick Massot -/ import Mathlib.Algebra.GeomSum import Mathlib.Order.Filter.AtTopBot.Archimedean import Mathlib.Order.Iterate import Mathlib.Topology.Algebra.Algebra import Mathlib.Topology.Algebra.InfiniteSum.Real import Mathlib.Topology.Instances.EReal.Lemmas /-! # 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∞`. -/ assert_not_exists Basis NormedSpace noncomputable section open Set Function Filter Finset Metric 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 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 theorem tendsto_one_div_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ 1/(n : ℝ)) atTop (𝓝 0) := tendsto_const_div_atTop_nhds_zero_nat 1 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 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 theorem EReal.tendsto_const_div_atTop_nhds_zero_nat {C : EReal} (h : C ≠ ⊥) (h' : C ≠ ⊤) : Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by have : (fun n : ℕ ↦ C / n) = fun n : ℕ ↦ ((C.toReal / n : ℝ) : EReal) := by ext n nth_rw 1 [← coe_toReal h' h, ← coe_coe_eq_natCast n, ← coe_div C.toReal n] rw [this, ← coe_zero, tendsto_coe] exact _root_.tendsto_const_div_atTop_nhds_zero_nat C.toReal 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) theorem NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat (𝕜 : Type*) [Semiring 𝕜]
Mathlib/Analysis/SpecificLimits/Basic.lean
59
61
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Neil Strickland -/ import Mathlib.Data.Nat.Prime.Defs import Mathlib.Data.PNat.Basic /-! # Primality and GCD on pnat This file extends the theory of `ℕ+` with `gcd`, `lcm` and `Prime` functions, analogous to those on `Nat`. -/ namespace Nat.Primes /-- The canonical map from `Nat.Primes` to `ℕ+` -/ @[coe] def toPNat : Nat.Primes → ℕ+ := fun p => ⟨(p : ℕ), p.property.pos⟩ instance coePNat : Coe Nat.Primes ℕ+ := ⟨toPNat⟩ @[norm_cast] theorem coe_pnat_nat (p : Nat.Primes) : ((p : ℕ+) : ℕ) = p := rfl theorem coe_pnat_injective : Function.Injective ((↑) : Nat.Primes → ℕ+) := fun p q h => Subtype.ext (by injection h) @[norm_cast] theorem coe_pnat_inj (p q : Nat.Primes) : (p : ℕ+) = (q : ℕ+) ↔ p = q := coe_pnat_injective.eq_iff end Nat.Primes namespace PNat open Nat /-- The greatest common divisor (gcd) of two positive natural numbers, viewed as positive natural number. -/ def gcd (n m : ℕ+) : ℕ+ := ⟨Nat.gcd (n : ℕ) (m : ℕ), Nat.gcd_pos_of_pos_left (m : ℕ) n.pos⟩ /-- The least common multiple (lcm) of two positive natural numbers, viewed as positive natural number. -/ def lcm (n m : ℕ+) : ℕ+ := ⟨Nat.lcm (n : ℕ) (m : ℕ), by let h := mul_pos n.pos m.pos rw [← gcd_mul_lcm (n : ℕ) (m : ℕ), mul_comm] at h exact pos_of_dvd_of_pos (Dvd.intro (Nat.gcd (n : ℕ) (m : ℕ)) rfl) h⟩ @[simp, norm_cast] theorem gcd_coe (n m : ℕ+) : (gcd n m : ℕ) = Nat.gcd n m := rfl @[simp, norm_cast] theorem lcm_coe (n m : ℕ+) : (lcm n m : ℕ) = Nat.lcm n m := rfl theorem gcd_dvd_left (n m : ℕ+) : gcd n m ∣ n := dvd_iff.2 (Nat.gcd_dvd_left (n : ℕ) (m : ℕ)) theorem gcd_dvd_right (n m : ℕ+) : gcd n m ∣ m := dvd_iff.2 (Nat.gcd_dvd_right (n : ℕ) (m : ℕ)) theorem dvd_gcd {m n k : ℕ+} (hm : k ∣ m) (hn : k ∣ n) : k ∣ gcd m n := dvd_iff.2 (Nat.dvd_gcd (dvd_iff.1 hm) (dvd_iff.1 hn)) theorem dvd_lcm_left (n m : ℕ+) : n ∣ lcm n m := dvd_iff.2 (Nat.dvd_lcm_left (n : ℕ) (m : ℕ)) theorem dvd_lcm_right (n m : ℕ+) : m ∣ lcm n m := dvd_iff.2 (Nat.dvd_lcm_right (n : ℕ) (m : ℕ)) theorem lcm_dvd {m n k : ℕ+} (hm : m ∣ k) (hn : n ∣ k) : lcm m n ∣ k := dvd_iff.2 (@Nat.lcm_dvd (m : ℕ) (n : ℕ) (k : ℕ) (dvd_iff.1 hm) (dvd_iff.1 hn)) theorem gcd_mul_lcm (n m : ℕ+) : gcd n m * lcm n m = n * m := Subtype.eq (Nat.gcd_mul_lcm (n : ℕ) (m : ℕ)) theorem eq_one_of_lt_two {n : ℕ+} : n < 2 → n = 1 := by intro h; apply le_antisymm; swap · apply PNat.one_le · exact PNat.lt_add_one_iff.1 h section Prime /-! ### Prime numbers -/ /-- Primality predicate for `ℕ+`, defined in terms of `Nat.Prime`. -/ def Prime (p : ℕ+) : Prop := (p : ℕ).Prime theorem Prime.one_lt {p : ℕ+} : p.Prime → 1 < p := Nat.Prime.one_lt theorem prime_two : (2 : ℕ+).Prime := Nat.prime_two instance {p : ℕ+} [h : Fact p.Prime] : Fact (p : ℕ).Prime := h instance fact_prime_two : Fact (2 : ℕ+).Prime := ⟨prime_two⟩ theorem prime_three : (3 : ℕ+).Prime := Nat.prime_three instance fact_prime_three : Fact (3 : ℕ+).Prime := ⟨prime_three⟩ theorem prime_five : (5 : ℕ+).Prime := Nat.prime_five instance fact_prime_five : Fact (5 : ℕ+).Prime := ⟨prime_five⟩ theorem dvd_prime {p m : ℕ+} (pp : p.Prime) : m ∣ p ↔ m = 1 ∨ m = p := by rw [PNat.dvd_iff] rw [Nat.dvd_prime pp] simp theorem Prime.ne_one {p : ℕ+} : p.Prime → p ≠ 1 := by intro pp intro contra apply Nat.Prime.ne_one pp rw [PNat.coe_eq_one_iff] apply contra @[simp] theorem not_prime_one : ¬(1 : ℕ+).Prime := Nat.not_prime_one theorem Prime.not_dvd_one {p : ℕ+} : p.Prime → ¬p ∣ 1 := fun pp : p.Prime => by rw [dvd_iff] apply Nat.Prime.not_dvd_one pp theorem exists_prime_and_dvd {n : ℕ+} (hn : n ≠ 1) : ∃ p : ℕ+, p.Prime ∧ p ∣ n := by obtain ⟨p, hp⟩ := Nat.exists_prime_and_dvd (mt coe_eq_one_iff.mp hn) exists (⟨p, Nat.Prime.pos hp.left⟩ : ℕ+); rw [dvd_iff]; apply hp end Prime section Coprime /-! ### Coprime numbers and gcd -/ /-- Two pnats are coprime if their gcd is 1. -/ def Coprime (m n : ℕ+) : Prop := m.gcd n = 1 @[simp, norm_cast] theorem coprime_coe {m n : ℕ+} : Nat.Coprime ↑m ↑n ↔ m.Coprime n := by unfold Nat.Coprime Coprime rw [← coe_inj] simp theorem Coprime.mul {k m n : ℕ+} : m.Coprime k → n.Coprime k → (m * n).Coprime k := by repeat rw [← coprime_coe] rw [mul_coe] apply Nat.Coprime.mul theorem Coprime.mul_right {k m n : ℕ+} : k.Coprime m → k.Coprime n → k.Coprime (m * n) := by repeat rw [← coprime_coe] rw [mul_coe] apply Nat.Coprime.mul_right theorem gcd_comm {m n : ℕ+} : m.gcd n = n.gcd m := by apply eq simp only [gcd_coe] apply Nat.gcd_comm theorem gcd_eq_left_iff_dvd {m n : ℕ+} : m.gcd n = m ↔ m ∣ n := by rw [dvd_iff, ← Nat.gcd_eq_left_iff_dvd, ← coe_inj] simp theorem gcd_eq_right_iff_dvd {m n : ℕ+} : n.gcd m = m ↔ m ∣ n := by rw [gcd_comm] apply gcd_eq_left_iff_dvd theorem Coprime.gcd_mul_left_cancel (m : ℕ+) {n k : ℕ+} : k.Coprime n → (k * m).gcd n = m.gcd n := by intro h; apply eq; simp only [gcd_coe, mul_coe] apply Nat.Coprime.gcd_mul_left_cancel; simpa theorem Coprime.gcd_mul_right_cancel (m : ℕ+) {n k : ℕ+} : k.Coprime n → (m * k).gcd n = m.gcd n := by rw [mul_comm]; apply Coprime.gcd_mul_left_cancel theorem Coprime.gcd_mul_left_cancel_right (m : ℕ+) {n k : ℕ+} : k.Coprime m → m.gcd (k * n) = m.gcd n := by intro h; iterate 2 rw [gcd_comm]; symm apply Coprime.gcd_mul_left_cancel _ h theorem Coprime.gcd_mul_right_cancel_right (m : ℕ+) {n k : ℕ+} : k.Coprime m → m.gcd (n * k) = m.gcd n := by rw [mul_comm] apply Coprime.gcd_mul_left_cancel_right @[simp] theorem one_gcd {n : ℕ+} : gcd 1 n = 1 := by rw [gcd_eq_left_iff_dvd] apply one_dvd @[simp] theorem gcd_one {n : ℕ+} : gcd n 1 = 1 := by rw [gcd_comm] apply one_gcd @[symm] theorem Coprime.symm {m n : ℕ+} : m.Coprime n → n.Coprime m := by unfold Coprime rw [gcd_comm] simp @[simp] theorem one_coprime {n : ℕ+} : (1 : ℕ+).Coprime n := one_gcd @[simp] theorem coprime_one {n : ℕ+} : n.Coprime 1 := Coprime.symm one_coprime theorem Coprime.coprime_dvd_left {m k n : ℕ+} : m ∣ k → k.Coprime n → m.Coprime n := by rw [dvd_iff] repeat rw [← coprime_coe] apply Nat.Coprime.coprime_dvd_left theorem Coprime.factor_eq_gcd_left {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m) (bn : b ∣ n) : a = (a * b).gcd m := by rw [← gcd_eq_left_iff_dvd] at am conv_lhs => rw [← am] rw [eq_comm] apply Coprime.gcd_mul_right_cancel a apply Coprime.coprime_dvd_left bn cop.symm theorem Coprime.factor_eq_gcd_right {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m) (bn : b ∣ n) : a = (b * a).gcd m := by rw [mul_comm]; apply Coprime.factor_eq_gcd_left cop am bn theorem Coprime.factor_eq_gcd_left_right {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m) (bn : b ∣ n) : a = m.gcd (a * b) := by rw [gcd_comm]; apply Coprime.factor_eq_gcd_left cop am bn theorem Coprime.factor_eq_gcd_right_right {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m) (bn : b ∣ n) : a = m.gcd (b * a) := by rw [gcd_comm] apply Coprime.factor_eq_gcd_right cop am bn theorem Coprime.gcd_mul (k : ℕ+) {m n : ℕ+} (h : m.Coprime n) : k.gcd (m * n) = k.gcd m * k.gcd n := by rw [← coprime_coe] at h; apply eq simp only [gcd_coe, mul_coe]; apply Nat.Coprime.gcd_mul k h theorem gcd_eq_left {m n : ℕ+} : m ∣ n → m.gcd n = m := by rw [dvd_iff] intro h apply eq simp only [gcd_coe] apply Nat.gcd_eq_left h theorem Coprime.pow {m n : ℕ+} (k l : ℕ) (h : m.Coprime n) : (m ^ k : ℕ).Coprime (n ^ l) := by rw [← coprime_coe] at *; apply Nat.Coprime.pow; apply h end Coprime end PNat
Mathlib/Data/PNat/Prime.lean
279
285
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Antoine Chambert-Loir -/ import Mathlib.Algebra.DirectSum.Finsupp import Mathlib.LinearAlgebra.DirectSum.TensorProduct import Mathlib.LinearAlgebra.Finsupp.SumProd /-! # Results on finitely supported functions. * `TensorProduct.finsuppLeft`, the tensor product of `ι →₀ M` and `N` is linearly equivalent to `ι →₀ M ⊗[R] N` * `TensorProduct.finsuppScalarLeft`, the tensor product of `ι →₀ R` and `N` is linearly equivalent to `ι →₀ N` * `TensorProduct.finsuppRight`, the tensor product of `M` and `ι →₀ N` is linearly equivalent to `ι →₀ M ⊗[R] N` * `TensorProduct.finsuppScalarRight`, the tensor product of `M` and `ι →₀ R` is linearly equivalent to `ι →₀ N` * `TensorProduct.finsuppLeft'`, if `M` is an `S`-module, then the tensor product of `ι →₀ M` and `N` is `S`-linearly equivalent to `ι →₀ M ⊗[R] N` * `finsuppTensorFinsupp`, the tensor product of `ι →₀ M` and `κ →₀ N` is linearly equivalent to `(ι × κ) →₀ (M ⊗ N)`. ## Case of MvPolynomial These functions apply to `MvPolynomial`, one can define ``` noncomputable def MvPolynomial.rTensor' : MvPolynomial σ S ⊗[R] N ≃ₗ[S] (σ →₀ ℕ) →₀ (S ⊗[R] N) := TensorProduct.finsuppLeft' noncomputable def MvPolynomial.rTensor : MvPolynomial σ R ⊗[R] N ≃ₗ[R] (σ →₀ ℕ) →₀ N := TensorProduct.finsuppScalarLeft ``` However, to be actually usable, these definitions need lemmas to be given in companion PR. ## Case of `Polynomial` `Polynomial` is a structure containing a `Finsupp`, so these functions can't be applied directly to `Polynomial`. Some linear equivs need to be added to mathlib for that. This belongs to a companion PR. ## TODO * generalize to `MonoidAlgebra`, `AlgHom ` * reprove `TensorProduct.finsuppLeft'` using existing heterobasic version of `TensorProduct.congr` -/ noncomputable section open DirectSum TensorProduct open Set LinearMap Submodule section TensorProduct variable (R : Type*) [CommSemiring R] (M : Type*) [AddCommMonoid M] [Module R M] (N : Type*) [AddCommMonoid N] [Module R N] namespace TensorProduct variable (ι : Type*) [DecidableEq ι] /-- The tensor product of `ι →₀ M` and `N` is linearly equivalent to `ι →₀ M ⊗[R] N` -/ noncomputable def finsuppLeft : (ι →₀ M) ⊗[R] N ≃ₗ[R] ι →₀ M ⊗[R] N := congr (finsuppLEquivDirectSum R M ι) (.refl R N) ≪≫ₗ directSumLeft R (fun _ ↦ M) N ≪≫ₗ (finsuppLEquivDirectSum R _ ι).symm variable {R M N ι} lemma finsuppLeft_apply_tmul (p : ι →₀ M) (n : N) : finsuppLeft R M N ι (p ⊗ₜ[R] n) = p.sum fun i m ↦ Finsupp.single i (m ⊗ₜ[R] n) := by induction p using Finsupp.induction_linear with | zero => simp | add f g hf hg => simp [add_tmul, map_add, hf, hg, Finsupp.sum_add_index] | single => simp [finsuppLeft] @[simp] lemma finsuppLeft_apply_tmul_apply (p : ι →₀ M) (n : N) (i : ι) :
finsuppLeft R M N ι (p ⊗ₜ[R] n) i = p i ⊗ₜ[R] n := by rw [finsuppLeft_apply_tmul, Finsupp.sum_apply, Finsupp.sum_eq_single i (fun _ _ ↦ Finsupp.single_eq_of_ne) (by simp), Finsupp.single_eq_same] theorem finsuppLeft_apply (t : (ι →₀ M) ⊗[R] N) (i : ι) :
Mathlib/LinearAlgebra/DirectSum/Finsupp.lean
96
100
/- Copyright (c) 2022 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Group.Nat.Even import Mathlib.Data.Nat.Cast.Basic import Mathlib.Data.Nat.Cast.Commute import Mathlib.Data.Set.Operations import Mathlib.Logic.Function.Iterate /-! # Even and odd elements in rings This file defines odd elements and proves some general facts about even and odd elements of rings. As opposed to `Even`, `Odd` does not have a multiplicative counterpart. ## TODO Try to generalize `Even` lemmas further. For example, there are still a few lemmas whose `Semiring` assumptions I (DT) am not convinced are necessary. If that turns out to be true, they could be moved to `Mathlib.Algebra.Group.Even`. ## See also `Mathlib.Algebra.Group.Even` for the definition of even elements. -/ assert_not_exists DenselyOrdered OrderedRing open MulOpposite variable {F α β : Type*} section Monoid variable [Monoid α] [HasDistribNeg α] {n : ℕ} {a : α} @[simp] lemma Even.neg_pow : Even n → ∀ a : α, (-a) ^ n = a ^ n := by rintro ⟨c, rfl⟩ a simp_rw [← two_mul, pow_mul, neg_sq] lemma Even.neg_one_pow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_pow, one_pow] end Monoid section DivisionMonoid variable [DivisionMonoid α] [HasDistribNeg α] {a : α} {n : ℤ} lemma Even.neg_zpow : Even n → ∀ a : α, (-a) ^ n = a ^ n := by rintro ⟨c, rfl⟩ a; simp_rw [← Int.two_mul, zpow_mul, zpow_two, neg_mul_neg] lemma Even.neg_one_zpow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_zpow, one_zpow] end DivisionMonoid @[simp] lemma IsSquare.zero [MulZeroClass α] : IsSquare (0 : α) := ⟨0, (mul_zero _).symm⟩ section Semiring variable [Semiring α] [Semiring β] {a b : α} {m n : ℕ} lemma even_iff_exists_two_mul : Even a ↔ ∃ b, a = 2 * b := by simp [even_iff_exists_two_nsmul] lemma even_iff_two_dvd : Even a ↔ 2 ∣ a := by simp [Even, Dvd.dvd, two_mul] alias ⟨Even.two_dvd, _⟩ := even_iff_two_dvd lemma Even.trans_dvd (ha : Even a) (hab : a ∣ b) : Even b := even_iff_two_dvd.2 <| ha.two_dvd.trans hab lemma Dvd.dvd.even (hab : a ∣ b) (ha : Even a) : Even b := ha.trans_dvd hab @[simp] lemma range_two_mul (α) [NonAssocSemiring α] : Set.range (fun x : α ↦ 2 * x) = {a | Even a} := by ext x simp [eq_comm, two_mul, Even] @[simp] lemma even_two : Even (2 : α) := ⟨1, by rw [one_add_one_eq_two]⟩ @[simp] lemma Even.mul_left (ha : Even a) (b) : Even (b * a) := ha.map (AddMonoidHom.mulLeft _) @[simp] lemma Even.mul_right (ha : Even a) (b) : Even (a * b) := ha.map (AddMonoidHom.mulRight _) lemma even_two_mul (a : α) : Even (2 * a) := ⟨a, two_mul _⟩ lemma Even.pow_of_ne_zero (ha : Even a) : ∀ {n : ℕ}, n ≠ 0 → Even (a ^ n) | n + 1, _ => by rw [pow_succ]; exact ha.mul_left _ /-- An element `a` of a semiring is odd if there exists `k` such `a = 2*k + 1`. -/ def Odd (a : α) : Prop := ∃ k, a = 2 * k + 1 lemma odd_iff_exists_bit1 : Odd a ↔ ∃ b, a = 2 * b + 1 := exists_congr fun b ↦ by rw [two_mul] alias ⟨Odd.exists_bit1, _⟩ := odd_iff_exists_bit1 @[simp] lemma range_two_mul_add_one (α : Type*) [Semiring α] : Set.range (fun x : α ↦ 2 * x + 1) = {a | Odd a} := by ext x; simp [Odd, eq_comm] lemma Even.add_odd : Even a → Odd b → Odd (a + b) := by rintro ⟨a, rfl⟩ ⟨b, rfl⟩; exact ⟨a + b, by rw [mul_add, ← two_mul, add_assoc]⟩ lemma Even.odd_add (ha : Even a) (hb : Odd b) : Odd (b + a) := add_comm a b ▸ ha.add_odd hb lemma Odd.add_even (ha : Odd a) (hb : Even b) : Odd (a + b) := add_comm a b ▸ hb.add_odd ha lemma Odd.add_odd : Odd a → Odd b → Even (a + b) := by rintro ⟨a, rfl⟩ ⟨b, rfl⟩ refine ⟨a + b + 1, ?_⟩ rw [two_mul, two_mul] ac_rfl @[simp] lemma odd_one : Odd (1 : α) := ⟨0, (zero_add _).symm.trans (congr_arg (· + (1 : α)) (mul_zero _).symm)⟩ @[simp] lemma Even.add_one (h : Even a) : Odd (a + 1) := h.add_odd odd_one @[simp] lemma Even.one_add (h : Even a) : Odd (1 + a) := h.odd_add odd_one @[simp] lemma Odd.add_one (h : Odd a) : Even (a + 1) := h.add_odd odd_one @[simp] lemma Odd.one_add (h : Odd a) : Even (1 + a) := odd_one.add_odd h lemma odd_two_mul_add_one (a : α) : Odd (2 * a + 1) := ⟨_, rfl⟩ @[simp] lemma odd_add_self_one' : Odd (a + (a + 1)) := by simp [← add_assoc] @[simp] lemma odd_add_one_self : Odd (a + 1 + a) := by simp [add_comm _ a] @[simp] lemma odd_add_one_self' : Odd (a + (1 + a)) := by simp [add_comm 1 a] lemma Odd.map [FunLike F α β] [RingHomClass F α β] (f : F) : Odd a → Odd (f a) := by rintro ⟨a, rfl⟩; exact ⟨f a, by simp [two_mul]⟩ lemma Odd.natCast {R : Type*} [Semiring R] {n : ℕ} (hn : Odd n) : Odd (n : R) := hn.map <| Nat.castRingHom R @[simp] lemma Odd.mul : Odd a → Odd b → Odd (a * b) := by rintro ⟨a, rfl⟩ ⟨b, rfl⟩ refine ⟨2 * a * b + b + a, ?_⟩ rw [mul_add, add_mul, mul_one, ← add_assoc, one_mul, mul_assoc, ← mul_add, ← mul_add, ← mul_assoc, ← Nat.cast_two, ← Nat.cast_comm] lemma Odd.pow (ha : Odd a) : ∀ {n : ℕ}, Odd (a ^ n) | 0 => by rw [pow_zero] exact odd_one | n + 1 => by rw [pow_succ]; exact ha.pow.mul ha lemma Odd.pow_add_pow_eq_zero [IsCancelAdd α] (hn : Odd n) (hab : a + b = 0) : a ^ n + b ^ n = 0 := by obtain ⟨k, rfl⟩ := hn induction k with | zero => simpa | succ k ih => ?_ have : a ^ 2 = b ^ 2 := add_right_cancel <| calc a ^ 2 + a * b = 0 := by rw [sq, ← mul_add, hab, mul_zero] _ = b ^ 2 + a * b := by rw [sq, ← add_mul, add_comm, hab, zero_mul] refine add_right_cancel (b := b ^ (2 * k + 1) * a ^ 2) ?_ calc _ = (a ^ (2 * k + 1) + b ^ (2 * k + 1)) * a ^ 2 + b ^ (2 * k + 3) := by rw [add_mul, ← pow_add, add_right_comm]; rfl _ = _ := by rw [ih, zero_mul, zero_add, zero_add, this, ← pow_add] end Semiring section Monoid variable [Monoid α] [HasDistribNeg α] {n : ℕ} lemma Odd.neg_pow : Odd n → ∀ a : α, (-a) ^ n = -a ^ n := by rintro ⟨c, rfl⟩ a; simp_rw [pow_add, pow_mul, neg_sq, pow_one, mul_neg] @[simp] lemma Odd.neg_one_pow (h : Odd n) : (-1 : α) ^ n = -1 := by rw [h.neg_pow, one_pow] end Monoid section Ring variable [Ring α] {a b : α} {n : ℕ} lemma even_neg_two : Even (-2 : α) := by simp only [even_neg, even_two]
lemma Odd.neg (hp : Odd a) : Odd (-a) := by obtain ⟨k, hk⟩ := hp use -(k + 1) rw [mul_neg, mul_add, neg_add, add_assoc, two_mul (1 : α), neg_add, neg_add_cancel_right, ← neg_add, hk]
Mathlib/Algebra/Ring/Parity.lean
174
178
/- 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.CharP.Basic import Mathlib.Algebra.Module.End import Mathlib.Algebra.Ring.Prod import Mathlib.Data.Fintype.Units import Mathlib.GroupTheory.GroupAction.SubMulAction import Mathlib.GroupTheory.OrderOfElement import Mathlib.Tactic.FinCases /-! # 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 * 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 Field Submodule TwoSidedIdeal open Function ZMod namespace ZMod /-- For non-zero `n : ℕ`, the ring `Fin n` is equivalent to `ZMod n`. -/ def finEquiv : ∀ (n : ℕ) [NeZero n], Fin n ≃+* ZMod n | 0, h => (h.ne _ rfl).elim | _ + 1, _ => .refl _ 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) → ℕ) 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 theorem val_le {n : ℕ} [NeZero n] (a : ZMod n) : a.val ≤ n := a.val_lt.le @[simp] theorem val_zero : ∀ {n}, (0 : ZMod n).val = 0 | 0 => rfl | _ + 1 => rfl @[simp] theorem val_one' : (1 : ZMod 0).val = 1 := rfl @[simp] theorem val_neg' {n : ZMod 0} : (-n).val = n.val := Int.natAbs_neg n @[simp] theorem val_mul' {m n : ZMod 0} : (m * n).val = m.val * n.val := Int.natAbs_mul m n @[simp] theorem val_natCast (n a : ℕ) : (a : ZMod n).val = a % n := by cases n · rw [Nat.mod_zero] exact Int.natAbs_natCast a · apply Fin.val_natCast lemma val_natCast_of_lt {n a : ℕ} (h : a < n) : (a : ZMod n).val = a := by rwa [val_natCast, Nat.mod_eq_of_lt] lemma val_ofNat (n a : ℕ) [a.AtLeastTwo] : (ofNat(a) : ZMod n).val = ofNat(a) % n := val_natCast .. lemma val_ofNat_of_lt {n a : ℕ} [a.AtLeastTwo] (han : a < n) : (ofNat(a) : ZMod n).val = ofNat(a) := val_natCast_of_lt han 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]
Mathlib/Data/ZMod/Basic.lean
101
102
/- 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.Subalgebra import Mathlib.LinearAlgebra.Finsupp.Span /-! # Lie submodules of a Lie algebra In this file we define Lie submodules, we construct the lattice structure on Lie submodules and we use it to define various important operations, notably the Lie span of a subset of a Lie module. ## Main definitions * `LieSubmodule` * `LieSubmodule.wellFounded_of_noetherian` * `LieSubmodule.lieSpan` * `LieSubmodule.map` * `LieSubmodule.comap` ## Tags lie algebra, lie submodule, lie ideal, lattice structure -/ universe u v w w₁ w₂ section LieSubmodule variable (R : Type u) (L : Type v) (M : Type w) variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] /-- A Lie submodule of a Lie module is a submodule that is closed under the Lie bracket. This is a sufficient condition for the subset itself to form a Lie module. -/ structure LieSubmodule extends Submodule R M where lie_mem : ∀ {x : L} {m : M}, m ∈ carrier → ⁅x, m⁆ ∈ carrier attribute [nolint docBlame] LieSubmodule.toSubmodule attribute [coe] LieSubmodule.toSubmodule namespace LieSubmodule variable {R L M} variable (N N' : LieSubmodule R L M) instance : SetLike (LieSubmodule R L M) M where coe s := s.carrier coe_injective' N O h := by cases N; cases O; congr; exact SetLike.coe_injective' h instance : AddSubgroupClass (LieSubmodule R L M) M where add_mem {N} _ _ := N.add_mem' zero_mem N := N.zero_mem' neg_mem {N} x hx := show -x ∈ N.toSubmodule from neg_mem hx instance instSMulMemClass : SMulMemClass (LieSubmodule R L M) R M where smul_mem {s} c _ h := s.smul_mem' c h /-- The zero module is a Lie submodule of any Lie module. -/ instance : Zero (LieSubmodule R L M) := ⟨{ (0 : Submodule R M) with lie_mem := fun {x m} h ↦ by rw [(Submodule.mem_bot R).1 h]; apply lie_zero }⟩ instance : Inhabited (LieSubmodule R L M) := ⟨0⟩ instance (priority := high) coeSort : CoeSort (LieSubmodule R L M) (Type w) where coe N := { x : M // x ∈ N } instance (priority := mid) coeSubmodule : CoeOut (LieSubmodule R L M) (Submodule R M) := ⟨toSubmodule⟩ instance : CanLift (Submodule R M) (LieSubmodule R L M) (·) (fun N ↦ ∀ {x : L} {m : M}, m ∈ N → ⁅x, m⁆ ∈ N) where prf N hN := ⟨⟨N, hN⟩, rfl⟩ @[norm_cast] theorem coe_toSubmodule : ((N : Submodule R M) : Set M) = N := rfl theorem mem_carrier {x : M} : x ∈ N.carrier ↔ x ∈ (N : Set M) := Iff.rfl theorem mem_mk_iff (S : Set M) (h₁ h₂ h₃ h₄) {x : M} : x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) ↔ x ∈ S := Iff.rfl @[simp] theorem mem_mk_iff' (p : Submodule R M) (h) {x : M} : x ∈ (⟨p, h⟩ : LieSubmodule R L M) ↔ x ∈ p := Iff.rfl @[simp] theorem mem_toSubmodule {x : M} : x ∈ (N : Submodule R M) ↔ x ∈ N := Iff.rfl @[deprecated (since := "2024-12-30")] alias mem_coeSubmodule := mem_toSubmodule theorem mem_coe {x : M} : x ∈ (N : Set M) ↔ x ∈ N := Iff.rfl @[simp] protected theorem zero_mem : (0 : M) ∈ N := zero_mem N @[simp] theorem mk_eq_zero {x} (h : x ∈ N) : (⟨x, h⟩ : N) = 0 ↔ x = 0 := Subtype.ext_iff_val @[simp] theorem coe_toSet_mk (S : Set M) (h₁ h₂ h₃ h₄) : ((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) : Set M) = S := rfl theorem toSubmodule_mk (p : Submodule R M) (h) : (({ p with lie_mem := h } : LieSubmodule R L M) : Submodule R M) = p := by cases p; rfl @[deprecated (since := "2024-12-30")] alias coe_toSubmodule_mk := toSubmodule_mk theorem toSubmodule_injective : Function.Injective (toSubmodule : LieSubmodule R L M → Submodule R M) := fun x y h ↦ by cases x; cases y; congr @[deprecated (since := "2024-12-30")] alias coeSubmodule_injective := toSubmodule_injective @[ext] theorem ext (h : ∀ m, m ∈ N ↔ m ∈ N') : N = N' := SetLike.ext h @[simp] theorem toSubmodule_inj : (N : Submodule R M) = (N' : Submodule R M) ↔ N = N' := toSubmodule_injective.eq_iff @[deprecated (since := "2024-12-30")] alias coe_toSubmodule_inj := toSubmodule_inj @[deprecated (since := "2024-12-29")] alias toSubmodule_eq_iff := toSubmodule_inj /-- Copy of a `LieSubmodule` with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (s : Set M) (hs : s = ↑N) : LieSubmodule R L M where carrier := s zero_mem' := by simp [hs] add_mem' x y := by rw [hs] at x y ⊢; exact N.add_mem' x y smul_mem' := by exact hs.symm ▸ N.smul_mem' lie_mem := by exact hs.symm ▸ N.lie_mem @[simp] theorem coe_copy (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : (S.copy s hs : Set M) = s := rfl theorem copy_eq (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs instance : LieRingModule L N where bracket (x : L) (m : N) := ⟨⁅x, m.val⁆, N.lie_mem m.property⟩ add_lie := by intro x y m; apply SetCoe.ext; apply add_lie lie_add := by intro x m n; apply SetCoe.ext; apply lie_add leibniz_lie := by intro x y m; apply SetCoe.ext; apply leibniz_lie @[simp, norm_cast] theorem coe_zero : ((0 : N) : M) = (0 : M) := rfl @[simp, norm_cast] theorem coe_add (m m' : N) : (↑(m + m') : M) = (m : M) + (m' : M) := rfl @[simp, norm_cast] theorem coe_neg (m : N) : (↑(-m) : M) = -(m : M) := rfl @[simp, norm_cast] theorem coe_sub (m m' : N) : (↑(m - m') : M) = (m : M) - (m' : M) := rfl @[simp, norm_cast] theorem coe_smul (t : R) (m : N) : (↑(t • m) : M) = t • (m : M) := rfl @[simp, norm_cast] theorem coe_bracket (x : L) (m : N) : (↑⁅x, m⁆ : M) = ⁅x, ↑m⁆ := rfl -- Copying instances from `Submodule` for correct discrimination keys instance [IsNoetherian R M] (N : LieSubmodule R L M) : IsNoetherian R N := inferInstanceAs <| IsNoetherian R N.toSubmodule instance [IsArtinian R M] (N : LieSubmodule R L M) : IsArtinian R N := inferInstanceAs <| IsArtinian R N.toSubmodule instance [NoZeroSMulDivisors R M] : NoZeroSMulDivisors R N := inferInstanceAs <| NoZeroSMulDivisors R N.toSubmodule variable [LieAlgebra R L] [LieModule R L M] instance instLieModule : LieModule R L N where lie_smul := by intro t x y; apply SetCoe.ext; apply lie_smul smul_lie := by intro t x y; apply SetCoe.ext; apply smul_lie instance [Subsingleton M] : Unique (LieSubmodule R L M) := ⟨⟨0⟩, fun _ ↦ (toSubmodule_inj _ _).mp (Subsingleton.elim _ _)⟩ end LieSubmodule variable {R M} theorem Submodule.exists_lieSubmodule_coe_eq_iff (p : Submodule R M) : (∃ N : LieSubmodule R L M, ↑N = p) ↔ ∀ (x : L) (m : M), m ∈ p → ⁅x, m⁆ ∈ p := by constructor · rintro ⟨N, rfl⟩ _ _; exact N.lie_mem · intro h; use { p with lie_mem := @h } namespace LieSubalgebra variable {L} variable [LieAlgebra R L] variable (K : LieSubalgebra R L) /-- Given a Lie subalgebra `K ⊆ L`, if we view `L` as a `K`-module by restriction, it contains a distinguished Lie submodule for the action of `K`, namely `K` itself. -/ def toLieSubmodule : LieSubmodule R K L := { (K : Submodule R L) with lie_mem := fun {x _} hy ↦ K.lie_mem x.property hy } @[simp] theorem coe_toLieSubmodule : (K.toLieSubmodule : Submodule R L) = K := rfl variable {K} @[simp] theorem mem_toLieSubmodule (x : L) : x ∈ K.toLieSubmodule ↔ x ∈ K := Iff.rfl end LieSubalgebra end LieSubmodule namespace LieSubmodule variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] variable (N N' : LieSubmodule R L M) section LatticeStructure open Set theorem coe_injective : Function.Injective ((↑) : LieSubmodule R L M → Set M) := SetLike.coe_injective @[simp, norm_cast] theorem toSubmodule_le_toSubmodule : (N : Submodule R M) ≤ N' ↔ N ≤ N' := Iff.rfl @[deprecated (since := "2024-12-30")] alias coeSubmodule_le_coeSubmodule := toSubmodule_le_toSubmodule instance : Bot (LieSubmodule R L M) := ⟨0⟩ instance instUniqueBot : Unique (⊥ : LieSubmodule R L M) := inferInstanceAs <| Unique (⊥ : Submodule R M) @[simp] theorem bot_coe : ((⊥ : LieSubmodule R L M) : Set M) = {0} := rfl @[simp] theorem bot_toSubmodule : ((⊥ : LieSubmodule R L M) : Submodule R M) = ⊥ := rfl @[deprecated (since := "2024-12-30")] alias bot_coeSubmodule := bot_toSubmodule @[simp] theorem toSubmodule_eq_bot : (N : Submodule R M) = ⊥ ↔ N = ⊥ := by rw [← toSubmodule_inj, bot_toSubmodule] @[deprecated (since := "2024-12-30")] alias coeSubmodule_eq_bot_iff := toSubmodule_eq_bot @[simp] theorem mk_eq_bot_iff {N : Submodule R M} {h} : (⟨N, h⟩ : LieSubmodule R L M) = ⊥ ↔ N = ⊥ := by rw [← toSubmodule_inj, bot_toSubmodule] @[simp] theorem mem_bot (x : M) : x ∈ (⊥ : LieSubmodule R L M) ↔ x = 0 := mem_singleton_iff instance : Top (LieSubmodule R L M) := ⟨{ (⊤ : Submodule R M) with lie_mem := fun {x m} _ ↦ mem_univ ⁅x, m⁆ }⟩ @[simp] theorem top_coe : ((⊤ : LieSubmodule R L M) : Set M) = univ := rfl @[simp] theorem top_toSubmodule : ((⊤ : LieSubmodule R L M) : Submodule R M) = ⊤ := rfl @[deprecated (since := "2024-12-30")] alias top_coeSubmodule := top_toSubmodule @[simp] theorem toSubmodule_eq_top : (N : Submodule R M) = ⊤ ↔ N = ⊤ := by rw [← toSubmodule_inj, top_toSubmodule] @[deprecated (since := "2024-12-30")] alias coeSubmodule_eq_top_iff := toSubmodule_eq_top @[simp] theorem mk_eq_top_iff {N : Submodule R M} {h} : (⟨N, h⟩ : LieSubmodule R L M) = ⊤ ↔ N = ⊤ := by rw [← toSubmodule_inj, top_toSubmodule] @[simp] theorem mem_top (x : M) : x ∈ (⊤ : LieSubmodule R L M) := mem_univ x instance : Min (LieSubmodule R L M) := ⟨fun N N' ↦ { (N ⊓ N' : Submodule R M) with lie_mem := fun h ↦ mem_inter (N.lie_mem h.1) (N'.lie_mem h.2) }⟩ instance : InfSet (LieSubmodule R L M) := ⟨fun S ↦ { toSubmodule := sInf {(s : Submodule R M) | s ∈ S} lie_mem := fun {x m} h ↦ by simp only [Submodule.mem_carrier, mem_iInter, Submodule.sInf_coe, mem_setOf_eq, forall_apply_eq_imp_iff₂, forall_exists_index, and_imp] at h ⊢ intro N hN; apply N.lie_mem (h N hN) }⟩ @[simp] theorem inf_coe : (↑(N ⊓ N') : Set M) = ↑N ∩ ↑N' := rfl @[norm_cast, simp] theorem inf_toSubmodule : (↑(N ⊓ N') : Submodule R M) = (N : Submodule R M) ⊓ (N' : Submodule R M) := rfl @[deprecated (since := "2024-12-30")] alias inf_coe_toSubmodule := inf_toSubmodule @[simp] theorem sInf_toSubmodule (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Submodule R M) = sInf {(s : Submodule R M) | s ∈ S} := rfl @[deprecated (since := "2024-12-30")] alias sInf_coe_toSubmodule := sInf_toSubmodule theorem sInf_toSubmodule_eq_iInf (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Submodule R M) = ⨅ N ∈ S, (N : Submodule R M) := by rw [sInf_toSubmodule, ← Set.image, sInf_image] @[deprecated (since := "2024-12-30")] alias sInf_coe_toSubmodule' := sInf_toSubmodule_eq_iInf @[simp] theorem iInf_toSubmodule {ι} (p : ι → LieSubmodule R L M) : (↑(⨅ i, p i) : Submodule R M) = ⨅ i, (p i : Submodule R M) := by rw [iInf, sInf_toSubmodule]; ext; simp @[deprecated (since := "2024-12-30")] alias iInf_coe_toSubmodule := iInf_toSubmodule @[simp] theorem sInf_coe (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Set M) = ⋂ s ∈ S, (s : Set M) := by rw [← LieSubmodule.coe_toSubmodule, sInf_toSubmodule, Submodule.sInf_coe] ext m simp only [mem_iInter, mem_setOf_eq, forall_apply_eq_imp_iff₂, exists_imp, and_imp, SetLike.mem_coe, mem_toSubmodule] @[simp] theorem iInf_coe {ι} (p : ι → LieSubmodule R L M) : (↑(⨅ i, p i) : Set M) = ⋂ i, ↑(p i) := by rw [iInf, sInf_coe]; simp only [Set.mem_range, Set.iInter_exists, Set.iInter_iInter_eq'] @[simp] theorem mem_iInf {ι} (p : ι → LieSubmodule R L M) {x} : (x ∈ ⨅ i, p i) ↔ ∀ i, x ∈ p i := by rw [← SetLike.mem_coe, iInf_coe, Set.mem_iInter]; rfl instance : Max (LieSubmodule R L M) where max N N' := { toSubmodule := (N : Submodule R M) ⊔ (N' : Submodule R M) lie_mem := by rintro x m (hm : m ∈ (N : Submodule R M) ⊔ (N' : Submodule R M)) change ⁅x, m⁆ ∈ (N : Submodule R M) ⊔ (N' : Submodule R M) rw [Submodule.mem_sup] at hm ⊢ obtain ⟨y, hy, z, hz, rfl⟩ := hm exact ⟨⁅x, y⁆, N.lie_mem hy, ⁅x, z⁆, N'.lie_mem hz, (lie_add _ _ _).symm⟩ } instance : SupSet (LieSubmodule R L M) where sSup S := { toSubmodule := sSup {(p : Submodule R M) | p ∈ S} lie_mem := by intro x m (hm : m ∈ sSup {(p : Submodule R M) | p ∈ S}) change ⁅x, m⁆ ∈ sSup {(p : Submodule R M) | p ∈ S} obtain ⟨s, hs, hsm⟩ := Submodule.mem_sSup_iff_exists_finset.mp hm clear hm classical induction s using Finset.induction_on generalizing m with | empty => replace hsm : m = 0 := by simpa using hsm simp [hsm] | insert q t hqt ih => rw [Finset.iSup_insert] at hsm obtain ⟨m', hm', u, hu, rfl⟩ := Submodule.mem_sup.mp hsm
rw [lie_add] refine add_mem ?_ (ih (Subset.trans (by simp) hs) hu) obtain ⟨p, hp, rfl⟩ : ∃ p ∈ S, ↑p = q := hs (Finset.mem_insert_self q t)
Mathlib/Algebra/Lie/Submodule.lean
404
406
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Topology.GDelta.Basic /-! # Baire spaces A topological space is called a *Baire space* if a countable intersection of dense open subsets is dense. Baire theorems say that all completely metrizable spaces and all locally compact regular spaces are Baire spaces. We prove the theorems in `Mathlib/Topology/Baire/CompleteMetrizable` and `Mathlib/Topology/Baire/LocallyCompactRegular`. In this file we prove various corollaries of Baire theorems. The good concept underlying the theorems is that of a Gδ set, i.e., a countable intersection of open sets. Then Baire theorem can also be formulated as the fact that a countable intersection of dense Gδ sets is a dense Gδ set. We deduce this version from Baire property. We also prove the important consequence that, if the space is covered by a countable union of closed sets, then the union of their interiors is dense. We also prove that in Baire spaces, the `residual` sets are exactly those containing a dense Gδ set. -/ noncomputable section open scoped Topology open Filter Set TopologicalSpace variable {X α : Type*} {ι : Sort*} section BaireTheorem variable [TopologicalSpace X] [BaireSpace X] /-- Definition of a Baire space. -/ theorem dense_iInter_of_isOpen_nat {f : ℕ → Set X} (ho : ∀ n, IsOpen (f n)) (hd : ∀ n, Dense (f n)) : Dense (⋂ n, f n) := BaireSpace.baire_property f ho hd /-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with ⋂₀. -/ theorem dense_sInter_of_isOpen {S : Set (Set X)} (ho : ∀ s ∈ S, IsOpen s) (hS : S.Countable) (hd : ∀ s ∈ S, Dense s) : Dense (⋂₀ S) := by rcases S.eq_empty_or_nonempty with h | h · simp [h] · rcases hS.exists_eq_range h with ⟨f, rfl⟩ exact dense_iInter_of_isOpen_nat (forall_mem_range.1 ho) (forall_mem_range.1 hd) /-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with an index set which is a countable set in any type. -/ theorem dense_biInter_of_isOpen {S : Set α} {f : α → Set X} (ho : ∀ s ∈ S, IsOpen (f s)) (hS : S.Countable) (hd : ∀ s ∈ S, Dense (f s)) : Dense (⋂ s ∈ S, f s) := by rw [← sInter_image] refine dense_sInter_of_isOpen ?_ (hS.image _) ?_ <;> rwa [forall_mem_image] /-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with an index set which is a countable type. -/ theorem dense_iInter_of_isOpen [Countable ι] {f : ι → Set X} (ho : ∀ i, IsOpen (f i)) (hd : ∀ i, Dense (f i)) : Dense (⋂ s, f s) := dense_sInter_of_isOpen (forall_mem_range.2 ho) (countable_range _) (forall_mem_range.2 hd) /-- A set is residual (comeagre) if and only if it includes a dense `Gδ` set. -/ theorem mem_residual {s : Set X} : s ∈ residual X ↔ ∃ t ⊆ s, IsGδ t ∧ Dense t := by constructor · rw [mem_residual_iff] rintro ⟨S, hSo, hSd, Sct, Ss⟩ refine ⟨_, Ss, ⟨_, fun t ht => hSo _ ht, Sct, rfl⟩, ?_⟩ exact dense_sInter_of_isOpen hSo Sct hSd rintro ⟨t, ts, ho, hd⟩ exact mem_of_superset (residual_of_dense_Gδ ho hd) ts /-- A property holds on a residual (comeagre) set if and only if it holds on some dense `Gδ` set. -/ theorem eventually_residual {p : X → Prop} : (∀ᶠ x in residual X, p x) ↔ ∃ t : Set X, IsGδ t ∧ Dense t ∧ ∀ x ∈ t, p x := by simp only [Filter.Eventually, mem_residual, subset_def, mem_setOf_eq] tauto theorem dense_of_mem_residual {s : Set X} (hs : s ∈ residual X) : Dense s := let ⟨_, hts, _, hd⟩ := mem_residual.1 hs hd.mono hts /-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with ⋂₀. -/ theorem dense_sInter_of_Gδ {S : Set (Set X)} (ho : ∀ s ∈ S, IsGδ s) (hS : S.Countable) (hd : ∀ s ∈ S, Dense s) : Dense (⋂₀ S) := dense_of_mem_residual ((countable_sInter_mem hS).mpr (fun _ hs => residual_of_dense_Gδ (ho _ hs) (hd _ hs))) /-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with an index set which is a countable type. -/ theorem dense_iInter_of_Gδ [Countable ι] {f : ι → Set X} (ho : ∀ s, IsGδ (f s)) (hd : ∀ s, Dense (f s)) : Dense (⋂ s, f s) := dense_sInter_of_Gδ (forall_mem_range.2 ‹_›) (countable_range _) (forall_mem_range.2 ‹_›) /-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with an index set which is a countable set in any type. -/ theorem dense_biInter_of_Gδ {S : Set α} {f : ∀ x ∈ S, Set X} (ho : ∀ s (H : s ∈ S), IsGδ (f s H)) (hS : S.Countable) (hd : ∀ s (H : s ∈ S), Dense (f s H)) : Dense (⋂ s ∈ S, f s ‹_›) := by rw [biInter_eq_iInter] haveI := hS.to_subtype exact dense_iInter_of_Gδ (fun s => ho s s.2) fun s => hd s s.2 /-- Baire theorem: the intersection of two dense Gδ sets is dense. -/ theorem Dense.inter_of_Gδ {s t : Set X} (hs : IsGδ s) (ht : IsGδ t) (hsc : Dense s) (htc : Dense t) : Dense (s ∩ t) := by rw [inter_eq_iInter] apply dense_iInter_of_Gδ <;> simp [Bool.forall_bool, *] /-- If a countable family of closed sets cover a dense `Gδ` set, then the union of their interiors is dense. Formulated here with `⋃`. -/ theorem IsGδ.dense_iUnion_interior_of_closed [Countable ι] {s : Set X} (hs : IsGδ s) (hd : Dense s) {f : ι → Set X} (hc : ∀ i, IsClosed (f i)) (hU : s ⊆ ⋃ i, f i) : Dense (⋃ i, interior (f i)) := by let g i := (frontier (f i))ᶜ have hgo : ∀ i, IsOpen (g i) := fun i => isClosed_frontier.isOpen_compl have hgd : Dense (⋂ i, g i) := by refine dense_iInter_of_isOpen hgo fun i x => ?_ rw [closure_compl, interior_frontier (hc _)] exact id refine (hd.inter_of_Gδ hs (.iInter_of_isOpen fun i => (hgo i)) hgd).mono ?_ rintro x ⟨hxs, hxg⟩ rw [mem_iInter] at hxg rcases mem_iUnion.1 (hU hxs) with ⟨i, hi⟩ exact mem_iUnion.2 ⟨i, self_diff_frontier (f i) ▸ ⟨hi, hxg _⟩⟩ /-- If a countable family of closed sets cover a dense `Gδ` set, then the union of their interiors is dense. Formulated here with a union over a countable set in any type. -/ theorem IsGδ.dense_biUnion_interior_of_closed {t : Set α} {s : Set X} (hs : IsGδ s) (hd : Dense s) (ht : t.Countable) {f : α → Set X} (hc : ∀ i ∈ t, IsClosed (f i)) (hU : s ⊆ ⋃ i ∈ t, f i) : Dense (⋃ i ∈ t, interior (f i)) := by haveI := ht.to_subtype simp only [biUnion_eq_iUnion, SetCoe.forall'] at * exact hs.dense_iUnion_interior_of_closed hd hc hU /-- If a countable family of closed sets cover a dense `Gδ` set, then the union of their interiors is dense. Formulated here with `⋃₀`. -/ theorem IsGδ.dense_sUnion_interior_of_closed {T : Set (Set X)} {s : Set X} (hs : IsGδ s) (hd : Dense s) (hc : T.Countable) (hc' : ∀ t ∈ T, IsClosed t) (hU : s ⊆ ⋃₀ T) : Dense (⋃ t ∈ T, interior t) := hs.dense_biUnion_interior_of_closed hd hc hc' <| by rwa [← sUnion_eq_biUnion] /-- Baire theorem: if countably many closed sets cover the whole space, then their interiors are dense. Formulated here with an index set which is a countable set in any type. -/ theorem dense_biUnion_interior_of_closed {S : Set α} {f : α → Set X} (hc : ∀ s ∈ S, IsClosed (f s)) (hS : S.Countable) (hU : ⋃ s ∈ S, f s = univ) : Dense (⋃ s ∈ S, interior (f s)) := IsGδ.univ.dense_biUnion_interior_of_closed dense_univ hS hc hU.ge
/-- Baire theorem: if countably many closed sets cover the whole space, then their interiors are dense. Formulated here with `⋃₀`. -/ theorem dense_sUnion_interior_of_closed {S : Set (Set X)} (hc : ∀ s ∈ S, IsClosed s) (hS : S.Countable) (hU : ⋃₀ S = univ) : Dense (⋃ s ∈ S, interior s) := IsGδ.univ.dense_sUnion_interior_of_closed dense_univ hS hc hU.ge
Mathlib/Topology/Baire/Lemmas.lean
151
156
/- Copyright (c) 2024 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.Data.Matroid.Constructions import Mathlib.Data.Set.Notation /-! # Maps between matroids This file defines maps and comaps, which move a matroid on one type to a matroid on another using a function between the types. The constructions are (up to isomorphism) just combinations of restrictions and parallel extensions, so are not mathematically difficult. Because a matroid `M : Matroid α` is defined with am embedded ground set `M.E : Set α` which contains all the structure of `M`, there are several types of map and comap one could reasonably ask for; for instance, we could map `M : Matroid α` to a `Matroid β` using either a function `f : α → β`, a function `f : ↑M.E → β` or indeed a function `f : ↑M.E → ↑E` for some `E : Set β`. We attempt to give definitions that capture most reasonable use cases. `Matroid.map` and `Matroid.comap` are defined in terms of bare functions rather than functions defined on subtypes, so are often easier to work in practice than the subtype variants. In fact, the statement that `N = Matroid.map M f _` for some `f : α → β` is equivalent to the existence of an isomorphism from `M` to `N`, except in the trivial degenerate case where `M` is an empty matroid on a nonempty type and `N` is an empty matroid on an empty type. This can be simpler to use than an actual formal isomorphism, which requires subtypes. ## Main definitions In the definitions below, `M` and `N` are matroids on `α` and `β` respectively. * For `f : α → β`, `Matroid.comap N f` is the matroid on `α` with ground set `f ⁻¹' N.E` in which each `I` is independent if and only if `f` is injective on `I` and `f '' I` is independent in `N`. (For each nonloop `x` of `N`, the set `f ⁻¹' {x}` is a parallel class of `N.comap f`) * `Matroid.comapOn N f E` is the restriction of `N.comap f` to `E` for some `E : Set α`. * For an embedding `f : M.E ↪ β` defined on the subtype `↑M.E`, `Matroid.mapSetEmbedding M f` is the matroid on `β` with ground set `range f` whose independent sets are the images of those in `M`. This matroid is isomorphic to `M`. * For a function `f : α → β` and a proof `hf` that `f` is injective on `M.E`, `Matroid.map f hf` is the matroid on `β` with ground set `f '' M.E` whose independent sets are the images of those in `M`. This matroid is isomorphic to `M`, and does not depend on the values `f` takes outside `M.E`. * `Matroid.mapEmbedding f` is a version of `Matroid.map` where `f : α ↪ β` is a bundled embedding. It is defined separately because the global injectivity of `f` gives some nicer `simp` lemmas. * `Matroid.mapEquiv f` is a version of `Matroid.map` where `f : α ≃ β` is a bundled equivalence. It is defined separately because we get even nicer `simp` lemmas. * `Matroid.mapSetEquiv f` is a version of `Matroid.map` where `f : M.E ≃ E` is an equivalence on subtypes. It gives a matroid on `β` with ground set `E`. * For `X : Set α`, `Matroid.restrictSubtype M X` is the `Matroid ↥X` with ground set `univ : Set ↥X`. This matroid is isomorphic to `M ↾ X`. ## Implementation details The definition of `comap` is the only place where we need to actually define a matroid from scratch. After `comap` is defined, we can define `map` and its variants indirectly in terms of `comap`. If `f : α → β` is injective on `M.E`, the independent sets of `M.map f hf` are the images of the independent set of `M`; i.e. `(M.map f hf).Indep I ↔ ∃ I₀, M.Indep I₀ ∧ I = f '' I₀`. But if `f` is globally injective, we can phrase this more directly; indeed, `(M.map f _).Indep I ↔ M.Indep (f ⁻¹' I) ∧ I ⊆ range f`. If `f` is an equivalence we have `(M.map f _).Indep I ↔ M.Indep (f.symm '' I)`. In order that these stronger statements can be `@[simp]`, we define `mapEmbedding` and `mapEquiv` separately from `map`. ## Notes For finite matroids, both maps and comaps are a special case of a construction of Perfect [perfect1969matroid] in which a matroid structure can be transported across an arbitrary bipartite graph that may not correspond to a function at all (See [oxley2011], Theorem 11.2.12). It would have been nice to use this more general construction as a basis for the definition of both `Matroid.map` and `Matroid.comap`. Unfortunately, we can't do this, because the construction doesn't extend to infinite matroids. Specifically, if `M₁` and `M₂` are matroids on the same type `α`, and `f` is the natural function from `α ⊕ α` to `α`, then the images under `f` of the independent sets of the direct sum `M₁ ⊕ M₂` are the independent sets of a matroid if and only if the union of `M₁` and `M₂` is a matroid, and unions do not exist for some pairs of infinite matroids: see [aignerhorev2012infinite]. For this reason, `Matroid.map` requires injectivity to be well-defined in general. ## TODO * Bundled matroid isomorphisms. * Maps of finite matroids across bipartite graphs. ## References * [E. Aigner-Horev, J. Carmesin, J. Fröhlic, Infinite Matroid Union][aignerhorev2012infinite] * [H. Perfect, Independence Spaces and Combinatorial Problems][perfect1969matroid] * [J. Oxley, Matroid Theory][oxley2011] -/ assert_not_exists Field open Set Function Set.Notation namespace Matroid variable {α β : Type*} {f : α → β} {E I : Set α} {M : Matroid α} {N : Matroid β} section comap /-- The pullback of a matroid on `β` by a function `f : α → β` to a matroid on `α`. Elements with the same (nonloop) image are parallel and the ground set is `f ⁻¹' M.E`. The matroids `M.comap f` and `M ↾ range f` have isomorphic simplifications; the preimage of each nonloop of `M ↾ range f` is a parallel class. -/ def comap (N : Matroid β) (f : α → β) : Matroid α := IndepMatroid.matroid <| { E := f ⁻¹' N.E Indep := fun I ↦ N.Indep (f '' I) ∧ InjOn f I indep_empty := by simp indep_subset := fun _ _ h hIJ ↦ ⟨h.1.subset (image_subset _ hIJ), InjOn.mono hIJ h.2⟩ indep_aug := by rintro I B ⟨hI, hIinj⟩ hImax hBmax obtain ⟨I', hII', hI', hI'inj⟩ := (not_maximal_subset_iff ⟨hI, hIinj⟩).1 hImax have h₁ : ¬(N ↾ range f).IsBase (f '' I) := by refine fun hB ↦ hII'.ne ?_ have h_im := hB.eq_of_subset_indep (by simpa) (image_subset _ hII'.subset) rwa [hI'inj.image_eq_image_iff hII'.subset Subset.rfl] at h_im have h₂ : (N ↾ range f).IsBase (f '' B) := by refine Indep.isBase_of_forall_insert (by simpa using hBmax.1.1) ?_ rintro _ ⟨⟨e, heB, rfl⟩, hfe⟩ hi rw [restrict_indep_iff, ← image_insert_eq] at hi have hinj : InjOn f (insert e B) := by rw [injOn_insert (fun heB ↦ hfe (mem_image_of_mem f heB))] exact ⟨hBmax.1.2, hfe⟩ refine hBmax.not_prop_of_ssuperset (t := insert e B) (ssubset_insert ?_) ⟨hi.1, hinj⟩ exact fun heB ↦ hfe <| mem_image_of_mem f heB obtain ⟨_, ⟨⟨e, he, rfl⟩, he'⟩, hei⟩ := Indep.exists_insert_of_not_isBase (by simpa) h₁ h₂ have heI : e ∉ I := fun heI ↦ he' (mem_image_of_mem f heI) rw [← image_insert_eq, restrict_indep_iff] at hei exact ⟨e, ⟨he, heI⟩, hei.1, (injOn_insert heI).2 ⟨hIinj, he'⟩⟩ indep_maximal := by rintro X - I ⟨hI, hIinj⟩ hIX obtain ⟨J, hJ⟩ := (N ↾ range f).existsMaximalSubsetProperty_indep (f '' X) (by simp) (f '' I) (by simpa) (image_subset _ hIX) simp only [restrict_indep_iff, image_subset_iff, maximal_subset_iff, mem_setOf_eq, and_imp, and_assoc] at hJ ⊢ obtain ⟨hIJ, hJ, hJf, hJX, hJmax⟩ := hJ obtain ⟨J₀, hIJ₀, hJ₀X, hbj⟩ := hIinj.bijOn_image.exists_extend_of_subset hIX (image_subset f hIJ) (image_subset_iff.2 <| preimage_mono hJX) obtain rfl : f '' J₀ = J := by rw [← image_preimage_eq_of_subset hJf, hbj.image_eq] refine ⟨J₀, hIJ₀, hJ, hbj.injOn, hJ₀X, fun K hK hKinj hKX hJ₀K ↦ ?_⟩ rw [← hKinj.image_eq_image_iff hJ₀K Subset.rfl, hJmax hK (image_subset_range _ _) (image_subset f hKX) (image_subset f hJ₀K)] subset_ground := fun _ hI e heI ↦ hI.1.subset_ground ⟨e, heI, rfl⟩ } @[simp] lemma comap_indep_iff : (N.comap f).Indep I ↔ N.Indep (f '' I) ∧ InjOn f I := Iff.rfl @[simp] lemma comap_ground_eq (N : Matroid β) (f : α → β) : (N.comap f).E = f ⁻¹' N.E := rfl @[simp] lemma comap_dep_iff : (N.comap f).Dep I ↔ N.Dep (f '' I) ∨ (N.Indep (f '' I) ∧ ¬ InjOn f I) := by rw [Dep, comap_indep_iff, not_and, comap_ground_eq, Dep, image_subset_iff] refine ⟨fun ⟨hi, h⟩ ↦ ?_, ?_⟩ · rw [and_iff_left h, ← imp_iff_not_or] exact fun hI ↦ ⟨hI, hi hI⟩ rintro (⟨hI, hIE⟩ | hI) · exact ⟨fun h ↦ (hI h).elim, hIE⟩ rw [iff_true_intro hI.1, iff_true_intro hI.2, implies_true, true_and] simpa using hI.1.subset_ground @[simp] lemma comap_id (N : Matroid β) : N.comap id = N := ext_indep rfl <| by simp [injective_id.injOn] lemma comap_indep_iff_of_injOn (hf : InjOn f (f ⁻¹' N.E)) : (N.comap f).Indep I ↔ N.Indep (f '' I) := by rw [comap_indep_iff, and_iff_left_iff_imp] refine fun hi ↦ hf.mono <| subset_trans ?_ (preimage_mono hi.subset_ground) apply subset_preimage_image @[simp] lemma comap_emptyOn (f : α → β) : comap (emptyOn β) f = emptyOn α := by simp [← ground_eq_empty_iff] @[simp] lemma comap_loopyOn (f : α → β) (E : Set β) : comap (loopyOn E) f = loopyOn (f ⁻¹' E) := by rw [eq_loopyOn_iff]; aesop @[simp] lemma comap_isBasis_iff {I X : Set α} : (N.comap f).IsBasis I X ↔ N.IsBasis (f '' I) (f '' X) ∧ I.InjOn f ∧ I ⊆ X := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · obtain ⟨hI, hinj⟩ := comap_indep_iff.1 h.indep refine ⟨hI.isBasis_of_forall_insert (image_subset f h.subset) fun e he ↦ ?_, hinj, h.subset⟩ simp only [mem_diff, mem_image, not_exists, not_and, and_imp, forall_exists_index, forall_apply_eq_imp_iff₂] at he obtain ⟨⟨e, heX, rfl⟩, he⟩ := he have heI : e ∉ I := fun heI ↦ (he e heI rfl) replace h := h.insert_dep ⟨heX, heI⟩ simp only [comap_dep_iff, image_insert_eq, or_iff_not_imp_right, injOn_insert heI, hinj, mem_image, not_exists, not_and, true_and, not_forall, Classical.not_imp, not_not] at h exact h (fun _ ↦ he) refine Indep.isBasis_of_forall_insert ?_ h.2.2 fun e ⟨heX, heI⟩ ↦ ?_ · simp [comap_indep_iff, h.1.indep, h.2] have hIE : insert e I ⊆ (N.comap f).E := by simp_rw [comap_ground_eq, ← image_subset_iff] exact (image_subset _ (insert_subset heX h.2.2)).trans h.1.subset_ground suffices N.Indep (insert (f e) (f '' I)) → ∃ x ∈ I, f x = f e by simpa [← not_indep_iff hIE, injOn_insert heI, h.2.1, image_insert_eq] exact h.1.mem_of_insert_indep (mem_image_of_mem f heX) @[simp] lemma comap_isBase_iff {B : Set α} : (N.comap f).IsBase B ↔ N.IsBasis (f '' B) (f '' (f ⁻¹' N.E)) ∧ B.InjOn f ∧ B ⊆ f ⁻¹' N.E := by rw [← isBasis_ground_iff, comap_isBasis_iff]; rfl @[simp] lemma comap_isBasis'_iff {I X : Set α} : (N.comap f).IsBasis' I X ↔ N.IsBasis' (f '' I) (f '' X) ∧ I.InjOn f ∧ I ⊆ X := by simp only [isBasis'_iff_isBasis_inter_ground, comap_ground_eq, comap_isBasis_iff, image_inter_preimage, subset_inter_iff, ← and_assoc, and_congr_left_iff, and_iff_left_iff_imp, and_imp] exact fun h _ _ ↦ (image_subset_iff.1 h.indep.subset_ground) instance comap_finitary (N : Matroid β) [N.Finitary] (f : α → β) : (N.comap f).Finitary := by refine ⟨fun I hI ↦ ?_⟩ rw [comap_indep_iff, indep_iff_forall_finite_subset_indep] simp only [forall_subset_image_iff] refine ⟨fun J hJ hfin ↦ ?_, fun x hx y hy ↦ (hI _ (pair_subset hx hy) (by simp)).2 (by simp) (by simp)⟩ obtain ⟨J', hJ'J, hJ'⟩ := (surjOn_image f J).exists_bijOn_subset rw [← hJ'.image_eq] at hfin ⊢ exact (hI J' (hJ'J.trans hJ) (hfin.of_finite_image hJ'.injOn)).1 instance comap_rankFinite (N : Matroid β) [N.RankFinite] (f : α → β) : (N.comap f).RankFinite := by obtain ⟨B, hB⟩ := (N.comap f).exists_isBase refine hB.rankFinite_of_finite ?_ simp only [comap_isBase_iff] at hB exact (hB.1.indep.finite.of_finite_image hB.2.1) end comap section comapOn variable {E B I : Set α} /-- The pullback of a matroid on `β` by a function `f : α → β` to a matroid on `α`, restricted to a ground set `E`. The matroids `M.comapOn f E` and `M ↾ (f '' E)` have isomorphic simplifications; elements with the same nonloop image are parallel. -/ def comapOn (N : Matroid β) (E : Set α) (f : α → β) : Matroid α := (N.comap f) ↾ E lemma comapOn_preimage_eq (N : Matroid β) (f : α → β) : N.comapOn (f ⁻¹' N.E) f = N.comap f := by rw [comapOn, restrict_eq_self_iff]; rfl @[simp] lemma comapOn_indep_iff : (N.comapOn E f).Indep I ↔ (N.Indep (f '' I) ∧ InjOn f I ∧ I ⊆ E) := by simp [comapOn, and_assoc] @[simp] lemma comapOn_ground_eq : (N.comapOn E f).E = E := rfl lemma comapOn_isBase_iff : (N.comapOn E f).IsBase B ↔ N.IsBasis' (f '' B) (f '' E) ∧ B.InjOn f ∧ B ⊆ E := by rw [comapOn, isBase_restrict_iff', comap_isBasis'_iff] lemma comapOn_isBase_iff_of_surjOn (h : SurjOn f E N.E) : (N.comapOn E f).IsBase B ↔ (N.IsBase (f '' B) ∧ InjOn f B ∧ B ⊆ E) := by simp_rw [comapOn_isBase_iff, and_congr_left_iff, and_imp, isBasis'_iff_isBasis_inter_ground, inter_eq_self_of_subset_right h, isBasis_ground_iff, implies_true] lemma comapOn_isBase_iff_of_bijOn (h : BijOn f E N.E) : (N.comapOn E f).IsBase B ↔ N.IsBase (f '' B) ∧ B ⊆ E := by rw [← and_iff_left_of_imp (IsBase.subset_ground (M := N.comapOn E f) (B := B)), comapOn_ground_eq, and_congr_left_iff] suffices h' : B ⊆ E → InjOn f B from fun hB ↦ by simp [hB, comapOn_isBase_iff_of_surjOn h.surjOn, h'] exact fun hBE ↦ h.injOn.mono hBE
lemma comapOn_dual_eq_of_bijOn (h : BijOn f E N.E) : (N.comapOn E f)✶ = N✶.comapOn E f := by refine ext_isBase (by simp) (fun B hB ↦ ?_) rw [comapOn_isBase_iff_of_bijOn (by simpa), dual_isBase_iff, comapOn_isBase_iff_of_bijOn h, dual_isBase_iff _, comapOn_ground_eq, and_iff_left diff_subset, and_iff_left (by simpa), h.injOn.image_diff_subset (by simpa), h.image_eq] exact (h.mapsTo.mono_left (show B ⊆ E by simpa)).image_subset
Mathlib/Data/Matroid/Map.lean
280
286
/- Copyright (c) 2022 Yaël Dillies, 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.Algebra.Order.Field.Basic import Mathlib.Combinatorics.SimpleGraph.Basic import Mathlib.Data.Rat.Cast.Order import Mathlib.Order.Partition.Finpartition import Mathlib.Tactic.GCongr import Mathlib.Tactic.NormNum import Mathlib.Tactic.Positivity import Mathlib.Tactic.Ring /-! # Edge density This file defines the number and density of edges of a relation/graph. ## Main declarations Between two finsets of vertices, * `Rel.interedges`: Finset of edges of a relation. * `Rel.edgeDensity`: Edge density of a relation. * `SimpleGraph.interedges`: Finset of edges of a graph. * `SimpleGraph.edgeDensity`: Edge density of a graph. -/ open Finset variable {𝕜 ι κ α β : Type*} /-! ### Density of a relation -/ namespace Rel section Asymmetric variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] (r : α → β → Prop) [∀ a, DecidablePred (r a)] {s s₁ s₂ : Finset α} {t t₁ t₂ : Finset β} {a : α} {b : β} {δ : 𝕜} /-- Finset of edges of a relation between two finsets of vertices. -/ def interedges (s : Finset α) (t : Finset β) : Finset (α × β) := {e ∈ s ×ˢ t | r e.1 e.2} /-- Edge density of a relation between two finsets of vertices. -/ def edgeDensity (s : Finset α) (t : Finset β) : ℚ := #(interedges r s t) / (#s * #t) variable {r} theorem mem_interedges_iff {x : α × β} : x ∈ interedges r s t ↔ x.1 ∈ s ∧ x.2 ∈ t ∧ r x.1 x.2 := by rw [interedges, mem_filter, Finset.mem_product, and_assoc] theorem mk_mem_interedges_iff : (a, b) ∈ interedges r s t ↔ a ∈ s ∧ b ∈ t ∧ r a b := mem_interedges_iff @[simp] theorem interedges_empty_left (t : Finset β) : interedges r ∅ t = ∅ := by rw [interedges, Finset.empty_product, filter_empty] theorem interedges_mono (hs : s₂ ⊆ s₁) (ht : t₂ ⊆ t₁) : interedges r s₂ t₂ ⊆ interedges r s₁ t₁ := fun x ↦ by simp_rw [mem_interedges_iff] exact fun h ↦ ⟨hs h.1, ht h.2.1, h.2.2⟩ variable (r) theorem card_interedges_add_card_interedges_compl (s : Finset α) (t : Finset β) : #(interedges r s t) + #(interedges (fun x y ↦ ¬r x y) s t) = #s * #t := by classical rw [← card_product, interedges, interedges, ← card_union_of_disjoint, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ ↦ Classical.not_not.2 theorem interedges_disjoint_left {s s' : Finset α} (hs : Disjoint s s') (t : Finset β) : Disjoint (interedges r s t) (interedges r s' t) := by rw [Finset.disjoint_left] at hs ⊢ intro _ hx hy rw [mem_interedges_iff] at hx hy exact hs hx.1 hy.1 theorem interedges_disjoint_right (s : Finset α) {t t' : Finset β} (ht : Disjoint t t') : Disjoint (interedges r s t) (interedges r s t') := by rw [Finset.disjoint_left] at ht ⊢ intro _ hx hy rw [mem_interedges_iff] at hx hy exact ht hx.2.1 hy.2.1 section DecidableEq variable [DecidableEq α] [DecidableEq β] lemma interedges_eq_biUnion : interedges r s t = s.biUnion fun x ↦ {y ∈ t | r x y}.map ⟨(x, ·), Prod.mk_right_injective x⟩ := by ext ⟨x, y⟩; simp [mem_interedges_iff] theorem interedges_biUnion_left (s : Finset ι) (t : Finset β) (f : ι → Finset α) : interedges r (s.biUnion f) t = s.biUnion fun a ↦ interedges r (f a) t := by ext simp only [mem_biUnion, mem_interedges_iff, exists_and_right, ← and_assoc] theorem interedges_biUnion_right (s : Finset α) (t : Finset ι) (f : ι → Finset β) : interedges r s (t.biUnion f) = t.biUnion fun b ↦ interedges r s (f b) := by
ext a simp only [mem_interedges_iff, mem_biUnion] exact ⟨fun ⟨x₁, ⟨x₂, x₃, x₄⟩, x₅⟩ ↦ ⟨x₂, x₃, x₁, x₄, x₅⟩,
Mathlib/Combinatorics/SimpleGraph/Density.lean
105
107
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.Homology import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Preadditive.Opposite /-! # Homology of preadditive categories In this file, it is shown that if `C` is a preadditive category, then `ShortComplex C` is a preadditive category. -/ namespace CategoryTheory open Category Limits Preadditive variable {C : Type*} [Category C] [Preadditive C] namespace ShortComplex variable {S₁ S₂ S₃ : ShortComplex C} attribute [local simp] Hom.comm₁₂ Hom.comm₂₃ instance : Add (S₁ ⟶ S₂) where add φ φ' := { τ₁ := φ.τ₁ + φ'.τ₁ τ₂ := φ.τ₂ + φ'.τ₂ τ₃ := φ.τ₃ + φ'.τ₃ } instance : Sub (S₁ ⟶ S₂) where sub φ φ' := { τ₁ := φ.τ₁ - φ'.τ₁ τ₂ := φ.τ₂ - φ'.τ₂ τ₃ := φ.τ₃ - φ'.τ₃ } instance : Neg (S₁ ⟶ S₂) where neg φ := { τ₁ := -φ.τ₁ τ₂ := -φ.τ₂ τ₃ := -φ.τ₃ } instance : AddCommGroup (S₁ ⟶ S₂) where add_assoc := fun a b c => by ext <;> apply add_assoc add_zero := fun a => by ext <;> apply add_zero zero_add := fun a => by ext <;> apply zero_add neg_add_cancel := fun a => by ext <;> apply neg_add_cancel add_comm := fun a b => by ext <;> apply add_comm sub_eq_add_neg := fun a b => by ext <;> apply sub_eq_add_neg nsmul := nsmulRec zsmul := zsmulRec @[simp] lemma add_τ₁ (φ φ' : S₁ ⟶ S₂) : (φ + φ').τ₁ = φ.τ₁ + φ'.τ₁ := rfl @[simp] lemma add_τ₂ (φ φ' : S₁ ⟶ S₂) : (φ + φ').τ₂ = φ.τ₂ + φ'.τ₂ := rfl @[simp] lemma add_τ₃ (φ φ' : S₁ ⟶ S₂) : (φ + φ').τ₃ = φ.τ₃ + φ'.τ₃ := rfl @[simp] lemma sub_τ₁ (φ φ' : S₁ ⟶ S₂) : (φ - φ').τ₁ = φ.τ₁ - φ'.τ₁ := rfl @[simp] lemma sub_τ₂ (φ φ' : S₁ ⟶ S₂) : (φ - φ').τ₂ = φ.τ₂ - φ'.τ₂ := rfl @[simp] lemma sub_τ₃ (φ φ' : S₁ ⟶ S₂) : (φ - φ').τ₃ = φ.τ₃ - φ'.τ₃ := rfl @[simp] lemma neg_τ₁ (φ : S₁ ⟶ S₂) : (-φ).τ₁ = -φ.τ₁ := rfl @[simp] lemma neg_τ₂ (φ : S₁ ⟶ S₂) : (-φ).τ₂ = -φ.τ₂ := rfl @[simp] lemma neg_τ₃ (φ : S₁ ⟶ S₂) : (-φ).τ₃ = -φ.τ₃ := rfl instance : Preadditive (ShortComplex C) where section LeftHomology variable {φ φ' : S₁ ⟶ S₂} {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} namespace LeftHomologyMapData variable (γ : LeftHomologyMapData φ h₁ h₂) (γ' : LeftHomologyMapData φ' h₁ h₂) /-- Given a left homology map data for morphism `φ`, this is the induced left homology map data for `-φ`. -/ @[simps] def neg : LeftHomologyMapData (-φ) h₁ h₂ where φK := -γ.φK φH := -γ.φH /-- Given left homology map data for morphisms `φ` and `φ'`, this is the induced left homology map data for `φ + φ'`. -/ @[simps] def add : LeftHomologyMapData (φ + φ') h₁ h₂ where φK := γ.φK + γ'.φK φH := γ.φH + γ'.φH end LeftHomologyMapData variable (h₁ h₂) @[simp] lemma leftHomologyMap'_neg : leftHomologyMap' (-φ) h₁ h₂ = -leftHomologyMap' φ h₁ h₂ := by have γ : LeftHomologyMapData φ h₁ h₂ := default simp only [γ.leftHomologyMap'_eq, γ.neg.leftHomologyMap'_eq, LeftHomologyMapData.neg_φH] @[simp] lemma cyclesMap'_neg : cyclesMap' (-φ) h₁ h₂ = -cyclesMap' φ h₁ h₂ := by have γ : LeftHomologyMapData φ h₁ h₂ := default simp only [γ.cyclesMap'_eq, γ.neg.cyclesMap'_eq, LeftHomologyMapData.neg_φK] @[simp] lemma leftHomologyMap'_add : leftHomologyMap' (φ + φ') h₁ h₂ = leftHomologyMap' φ h₁ h₂ + leftHomologyMap' φ' h₁ h₂ := by have γ : LeftHomologyMapData φ h₁ h₂ := default have γ' : LeftHomologyMapData φ' h₁ h₂ := default simp only [γ.leftHomologyMap'_eq, γ'.leftHomologyMap'_eq, (γ.add γ').leftHomologyMap'_eq, LeftHomologyMapData.add_φH] @[simp] lemma cyclesMap'_add : cyclesMap' (φ + φ') h₁ h₂ = cyclesMap' φ h₁ h₂ + cyclesMap' φ' h₁ h₂ := by have γ : LeftHomologyMapData φ h₁ h₂ := default have γ' : LeftHomologyMapData φ' h₁ h₂ := default simp only [γ.cyclesMap'_eq, γ'.cyclesMap'_eq, (γ.add γ').cyclesMap'_eq, LeftHomologyMapData.add_φK] @[simp] lemma leftHomologyMap'_sub : leftHomologyMap' (φ - φ') h₁ h₂ = leftHomologyMap' φ h₁ h₂ - leftHomologyMap' φ' h₁ h₂ := by simp only [sub_eq_add_neg, leftHomologyMap'_add, leftHomologyMap'_neg] @[simp] lemma cyclesMap'_sub : cyclesMap' (φ - φ') h₁ h₂ = cyclesMap' φ h₁ h₂ - cyclesMap' φ' h₁ h₂ := by simp only [sub_eq_add_neg, cyclesMap'_add, cyclesMap'_neg] variable (φ φ') section variable [S₁.HasLeftHomology] [S₂.HasLeftHomology] @[simp] lemma leftHomologyMap_neg : leftHomologyMap (-φ) = -leftHomologyMap φ := leftHomologyMap'_neg _ _ @[simp] lemma cyclesMap_neg : cyclesMap (-φ) = -cyclesMap φ := cyclesMap'_neg _ _ @[simp] lemma leftHomologyMap_add : leftHomologyMap (φ + φ') = leftHomologyMap φ + leftHomologyMap φ' := leftHomologyMap'_add _ _ @[simp] lemma cyclesMap_add : cyclesMap (φ + φ') = cyclesMap φ + cyclesMap φ' := cyclesMap'_add _ _ @[simp] lemma leftHomologyMap_sub : leftHomologyMap (φ - φ') = leftHomologyMap φ - leftHomologyMap φ' := leftHomologyMap'_sub _ _ @[simp] lemma cyclesMap_sub : cyclesMap (φ - φ') = cyclesMap φ - cyclesMap φ' := cyclesMap'_sub _ _ end instance leftHomologyFunctor_additive [HasKernels C] [HasCokernels C] : (leftHomologyFunctor C).Additive where instance cyclesFunctor_additive [HasKernels C] [HasCokernels C] : (cyclesFunctor C).Additive where end LeftHomology section RightHomology variable {φ φ' : S₁ ⟶ S₂} {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} namespace RightHomologyMapData variable (γ : RightHomologyMapData φ h₁ h₂) (γ' : RightHomologyMapData φ' h₁ h₂) /-- Given a right homology map data for morphism `φ`, this is the induced right homology map data for `-φ`. -/ @[simps] def neg : RightHomologyMapData (-φ) h₁ h₂ where φQ := -γ.φQ φH := -γ.φH /-- Given right homology map data for morphisms `φ` and `φ'`, this is the induced right homology map data for `φ + φ'`. -/ @[simps] def add : RightHomologyMapData (φ + φ') h₁ h₂ where φQ := γ.φQ + γ'.φQ φH := γ.φH + γ'.φH end RightHomologyMapData variable (h₁ h₂) @[simp] lemma rightHomologyMap'_neg : rightHomologyMap' (-φ) h₁ h₂ = -rightHomologyMap' φ h₁ h₂ := by have γ : RightHomologyMapData φ h₁ h₂ := default simp only [γ.rightHomologyMap'_eq, γ.neg.rightHomologyMap'_eq, RightHomologyMapData.neg_φH] @[simp] lemma opcyclesMap'_neg : opcyclesMap' (-φ) h₁ h₂ = -opcyclesMap' φ h₁ h₂ := by have γ : RightHomologyMapData φ h₁ h₂ := default simp only [γ.opcyclesMap'_eq, γ.neg.opcyclesMap'_eq, RightHomologyMapData.neg_φQ] @[simp] lemma rightHomologyMap'_add : rightHomologyMap' (φ + φ') h₁ h₂ = rightHomologyMap' φ h₁ h₂ + rightHomologyMap' φ' h₁ h₂ := by have γ : RightHomologyMapData φ h₁ h₂ := default have γ' : RightHomologyMapData φ' h₁ h₂ := default simp only [γ.rightHomologyMap'_eq, γ'.rightHomologyMap'_eq, (γ.add γ').rightHomologyMap'_eq, RightHomologyMapData.add_φH] @[simp] lemma opcyclesMap'_add : opcyclesMap' (φ + φ') h₁ h₂ = opcyclesMap' φ h₁ h₂ + opcyclesMap' φ' h₁ h₂ := by have γ : RightHomologyMapData φ h₁ h₂ := default have γ' : RightHomologyMapData φ' h₁ h₂ := default simp only [γ.opcyclesMap'_eq, γ'.opcyclesMap'_eq, (γ.add γ').opcyclesMap'_eq, RightHomologyMapData.add_φQ] @[simp] lemma rightHomologyMap'_sub : rightHomologyMap' (φ - φ') h₁ h₂ = rightHomologyMap' φ h₁ h₂ - rightHomologyMap' φ' h₁ h₂ := by simp only [sub_eq_add_neg, rightHomologyMap'_add, rightHomologyMap'_neg] @[simp] lemma opcyclesMap'_sub : opcyclesMap' (φ - φ') h₁ h₂ = opcyclesMap' φ h₁ h₂ - opcyclesMap' φ' h₁ h₂ := by simp only [sub_eq_add_neg, opcyclesMap'_add, opcyclesMap'_neg] variable (φ φ') section variable [S₁.HasRightHomology] [S₂.HasRightHomology] @[simp] lemma rightHomologyMap_neg : rightHomologyMap (-φ) = -rightHomologyMap φ := rightHomologyMap'_neg _ _ @[simp] lemma opcyclesMap_neg : opcyclesMap (-φ) = -opcyclesMap φ := opcyclesMap'_neg _ _ @[simp] lemma rightHomologyMap_add : rightHomologyMap (φ + φ') = rightHomologyMap φ + rightHomologyMap φ' := rightHomologyMap'_add _ _ @[simp] lemma opcyclesMap_add : opcyclesMap (φ + φ') = opcyclesMap φ + opcyclesMap φ' := opcyclesMap'_add _ _ @[simp] lemma rightHomologyMap_sub : rightHomologyMap (φ - φ') = rightHomologyMap φ - rightHomologyMap φ' := rightHomologyMap'_sub _ _ @[simp] lemma opcyclesMap_sub : opcyclesMap (φ - φ') = opcyclesMap φ - opcyclesMap φ' := opcyclesMap'_sub _ _ end instance rightHomologyFunctor_additive [HasKernels C] [HasCokernels C] : (rightHomologyFunctor C).Additive where instance opcyclesFunctor_additive [HasKernels C] [HasCokernels C] : (opcyclesFunctor C).Additive where end RightHomology section Homology variable {φ φ' : S₁ ⟶ S₂} {h₁ : S₁.HomologyData} {h₂ : S₂.HomologyData} namespace HomologyMapData variable (γ : HomologyMapData φ h₁ h₂) (γ' : HomologyMapData φ' h₁ h₂) /-- Given a homology map data for a morphism `φ`, this is the induced homology map data for `-φ`. -/ @[simps] def neg : HomologyMapData (-φ) h₁ h₂ where left := γ.left.neg right := γ.right.neg /-- Given homology map data for morphisms `φ` and `φ'`, this is the induced homology map data for `φ + φ'`. -/ @[simps] def add : HomologyMapData (φ + φ') h₁ h₂ where left := γ.left.add γ'.left right := γ.right.add γ'.right end HomologyMapData variable (h₁ h₂) @[simp] lemma homologyMap'_neg : homologyMap' (-φ) h₁ h₂ = -homologyMap' φ h₁ h₂ := leftHomologyMap'_neg _ _ @[simp] lemma homologyMap'_add : homologyMap' (φ + φ') h₁ h₂ = homologyMap' φ h₁ h₂ + homologyMap' φ' h₁ h₂ := leftHomologyMap'_add _ _ @[simp] lemma homologyMap'_sub : homologyMap' (φ - φ') h₁ h₂ = homologyMap' φ h₁ h₂ - homologyMap' φ' h₁ h₂ := leftHomologyMap'_sub _ _ variable (φ φ') section variable [S₁.HasHomology] [S₂.HasHomology] @[simp] lemma homologyMap_neg : homologyMap (-φ) = -homologyMap φ := homologyMap'_neg _ _ @[simp] lemma homologyMap_add : homologyMap (φ + φ') = homologyMap φ + homologyMap φ' := homologyMap'_add _ _ @[simp] lemma homologyMap_sub : homologyMap (φ - φ') = homologyMap φ - homologyMap φ' := homologyMap'_sub _ _ end instance homologyFunctor_additive [CategoryWithHomology C] : (homologyFunctor C).Additive where end Homology section Homotopy variable (φ₁ φ₂ φ₃ φ₄ : S₁ ⟶ S₂) /-- A homotopy between two morphisms of short complexes `S₁ ⟶ S₂` consists of various maps and conditions which will be sufficient to show that they induce the same morphism in homology. -/ @[ext] structure Homotopy where /-- a morphism `S₁.X₁ ⟶ S₂.X₁` -/ h₀ : S₁.X₁ ⟶ S₂.X₁ h₀_f : h₀ ≫ S₂.f = 0 := by aesop_cat /-- a morphism `S₁.X₂ ⟶ S₂.X₁` -/ h₁ : S₁.X₂ ⟶ S₂.X₁ /-- a morphism `S₁.X₃ ⟶ S₂.X₂` -/ h₂ : S₁.X₃ ⟶ S₂.X₂ /-- a morphism `S₁.X₃ ⟶ S₂.X₃` -/ h₃ : S₁.X₃ ⟶ S₂.X₃ g_h₃ : S₁.g ≫ h₃ = 0 := by aesop_cat comm₁ : φ₁.τ₁ = S₁.f ≫ h₁ + h₀ + φ₂.τ₁ := by aesop_cat comm₂ : φ₁.τ₂ = S₁.g ≫ h₂ + h₁ ≫ S₂.f + φ₂.τ₂ := by aesop_cat comm₃ : φ₁.τ₃ = h₃ + h₂ ≫ S₂.g + φ₂.τ₃ := by aesop_cat attribute [reassoc (attr := simp)] Homotopy.h₀_f Homotopy.g_h₃ variable (S₁ S₂) /-- Constructor for null homotopic morphisms, see also `Homotopy.ofNullHomotopic` and `Homotopy.eq_add_nullHomotopic`. -/ @[simps] def nullHomotopic (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : S₁ ⟶ S₂ where τ₁ := h₀ + S₁.f ≫ h₁ τ₂ := h₁ ≫ S₂.f + S₁.g ≫ h₂ τ₃ := h₂ ≫ S₂.g + h₃ namespace Homotopy attribute [local simp] neg_comp variable {S₁ S₂ φ₁ φ₂ φ₃ φ₄} /-- The obvious homotopy between two equal morphisms of short complexes. -/ @[simps] def ofEq (h : φ₁ = φ₂) : Homotopy φ₁ φ₂ where h₀ := 0 h₁ := 0 h₂ := 0 h₃ := 0 /-- The obvious homotopy between a morphism of short complexes and itself. -/ @[simps!] def refl (φ : S₁ ⟶ S₂) : Homotopy φ φ := ofEq rfl /-- The symmetry of homotopy between morphisms of short complexes. -/ @[simps] def symm (h : Homotopy φ₁ φ₂) : Homotopy φ₂ φ₁ where h₀ := -h.h₀ h₁ := -h.h₁ h₂ := -h.h₂ h₃ := -h.h₃ comm₁ := by rw [h.comm₁, comp_neg]; abel comm₂ := by rw [h.comm₂, comp_neg, neg_comp]; abel comm₃ := by rw [h.comm₃, neg_comp]; abel /-- If two maps of short complexes are homotopic, their opposites also are. -/ @[simps] def neg (h : Homotopy φ₁ φ₂) : Homotopy (-φ₁) (-φ₂) where h₀ := -h.h₀ h₁ := -h.h₁ h₂ := -h.h₂ h₃ := -h.h₃ comm₁ := by rw [neg_τ₁, neg_τ₁, h.comm₁, neg_add_rev, comp_neg]; abel comm₂ := by rw [neg_τ₂, neg_τ₂, h.comm₂, neg_add_rev, comp_neg, neg_comp]; abel comm₃ := by rw [neg_τ₃, neg_τ₃, h.comm₃, neg_comp]; abel /-- The transitivity of homotopy between morphisms of short complexes. -/ @[simps] def trans (h₁₂ : Homotopy φ₁ φ₂) (h₂₃ : Homotopy φ₂ φ₃) : Homotopy φ₁ φ₃ where h₀ := h₁₂.h₀ + h₂₃.h₀ h₁ := h₁₂.h₁ + h₂₃.h₁ h₂ := h₁₂.h₂ + h₂₃.h₂ h₃ := h₁₂.h₃ + h₂₃.h₃ comm₁ := by rw [h₁₂.comm₁, h₂₃.comm₁, comp_add]; abel comm₂ := by rw [h₁₂.comm₂, h₂₃.comm₂, comp_add, add_comp]; abel comm₃ := by rw [h₁₂.comm₃, h₂₃.comm₃, add_comp]; abel /-- Homotopy between morphisms of short complexes is compatible with addition. -/ @[simps] def add (h : Homotopy φ₁ φ₂) (h' : Homotopy φ₃ φ₄) : Homotopy (φ₁ + φ₃) (φ₂ + φ₄) where h₀ := h.h₀ + h'.h₀ h₁ := h.h₁ + h'.h₁ h₂ := h.h₂ + h'.h₂ h₃ := h.h₃ + h'.h₃ comm₁ := by rw [add_τ₁, add_τ₁, h.comm₁, h'.comm₁, comp_add]; abel comm₂ := by rw [add_τ₂, add_τ₂, h.comm₂, h'.comm₂, comp_add, add_comp]; abel comm₃ := by rw [add_τ₃, add_τ₃, h.comm₃, h'.comm₃, add_comp]; abel /-- Homotopy between morphisms of short complexes is compatible with subtraction. -/ @[simps] def sub (h : Homotopy φ₁ φ₂) (h' : Homotopy φ₃ φ₄) : Homotopy (φ₁ - φ₃) (φ₂ - φ₄) where h₀ := h.h₀ - h'.h₀ h₁ := h.h₁ - h'.h₁ h₂ := h.h₂ - h'.h₂ h₃ := h.h₃ - h'.h₃ comm₁ := by rw [sub_τ₁, sub_τ₁, h.comm₁, h'.comm₁, comp_sub]; abel comm₂ := by rw [sub_τ₂, sub_τ₂, h.comm₂, h'.comm₂, comp_sub, sub_comp]; abel comm₃ := by rw [sub_τ₃, sub_τ₃, h.comm₃, h'.comm₃, sub_comp]; abel /-- Homotopy between morphisms of short complexes is compatible with precomposition. -/ @[simps] def compLeft (h : Homotopy φ₁ φ₂) (ψ : S₃ ⟶ S₁) : Homotopy (ψ ≫ φ₁) (ψ ≫ φ₂) where h₀ := ψ.τ₁ ≫ h.h₀ h₁ := ψ.τ₂ ≫ h.h₁ h₂ := ψ.τ₃ ≫ h.h₂ h₃ := ψ.τ₃ ≫ h.h₃ g_h₃ := by rw [← ψ.comm₂₃_assoc, h.g_h₃, comp_zero] comm₁ := by rw [comp_τ₁, comp_τ₁, h.comm₁, comp_add, comp_add, add_left_inj, ψ.comm₁₂_assoc] comm₂ := by rw [comp_τ₂, comp_τ₂, h.comm₂, comp_add, comp_add, assoc, ψ.comm₂₃_assoc] comm₃ := by rw [comp_τ₃, comp_τ₃, h.comm₃, comp_add, comp_add, assoc] /-- Homotopy between morphisms of short complexes is compatible with postcomposition. -/ @[simps] def compRight (h : Homotopy φ₁ φ₂) (ψ : S₂ ⟶ S₃) : Homotopy (φ₁ ≫ ψ) (φ₂ ≫ ψ) where h₀ := h.h₀ ≫ ψ.τ₁ h₁ := h.h₁ ≫ ψ.τ₁ h₂ := h.h₂ ≫ ψ.τ₂ h₃ := h.h₃ ≫ ψ.τ₃ comm₁ := by rw [comp_τ₁, comp_τ₁, h.comm₁, add_comp, add_comp, assoc] comm₂ := by rw [comp_τ₂, comp_τ₂, h.comm₂, add_comp, add_comp, assoc, assoc, assoc, ψ.comm₁₂] comm₃ := by rw [comp_τ₃, comp_τ₃, h.comm₃, add_comp, add_comp, assoc, assoc, ψ.comm₂₃] /-- Homotopy between morphisms of short complexes is compatible with composition. -/ @[simps!] def comp (h : Homotopy φ₁ φ₂) {ψ₁ ψ₂ : S₂ ⟶ S₃} (h' : Homotopy ψ₁ ψ₂) : Homotopy (φ₁ ≫ ψ₁) (φ₂ ≫ ψ₂) := (h.compRight ψ₁).trans (h'.compLeft φ₂) /-- The homotopy between morphisms in `ShortComplex Cᵒᵖ` that is induced by a homotopy between morphisms in `ShortComplex C`. -/ @[simps] def op (h : Homotopy φ₁ φ₂) : Homotopy (opMap φ₁) (opMap φ₂) where h₀ := h.h₃.op h₁ := h.h₂.op h₂ := h.h₁.op h₃ := h.h₀.op h₀_f := Quiver.Hom.unop_inj h.g_h₃ g_h₃ := Quiver.Hom.unop_inj h.h₀_f comm₁ := Quiver.Hom.unop_inj (by dsimp; rw [h.comm₃]; abel) comm₂ := Quiver.Hom.unop_inj (by dsimp; rw [h.comm₂]; abel) comm₃ := Quiver.Hom.unop_inj (by dsimp; rw [h.comm₁]; abel) /-- The homotopy between morphisms in `ShortComplex C` that is induced by a homotopy between morphisms in `ShortComplex Cᵒᵖ`. -/ @[simps] def unop {S₁ S₂ : ShortComplex Cᵒᵖ} {φ₁ φ₂ : S₁ ⟶ S₂} (h : Homotopy φ₁ φ₂) : Homotopy (unopMap φ₁) (unopMap φ₂) where h₀ := h.h₃.unop h₁ := h.h₂.unop h₂ := h.h₁.unop h₃ := h.h₀.unop h₀_f := Quiver.Hom.op_inj h.g_h₃ g_h₃ := Quiver.Hom.op_inj h.h₀_f comm₁ := Quiver.Hom.op_inj (by dsimp; rw [h.comm₃]; abel) comm₂ := Quiver.Hom.op_inj (by dsimp; rw [h.comm₂]; abel) comm₃ := Quiver.Hom.op_inj (by dsimp; rw [h.comm₁]; abel) variable (φ₁ φ₂) /-- Equivalence expressing that two morphisms are homotopic iff their difference is homotopic to zero. -/ @[simps] def equivSubZero : Homotopy φ₁ φ₂ ≃ Homotopy (φ₁ - φ₂) 0 where toFun h := (h.sub (refl φ₂)).trans (ofEq (sub_self φ₂)) invFun h := ((ofEq (sub_add_cancel φ₁ φ₂).symm).trans (h.add (refl φ₂))).trans (ofEq (zero_add φ₂)) left_inv := by aesop_cat right_inv := by aesop_cat variable {φ₁ φ₂} lemma eq_add_nullHomotopic (h : Homotopy φ₁ φ₂) : φ₁ = φ₂ + nullHomotopic _ _ h.h₀ h.h₀_f h.h₁ h.h₂ h.h₃ h.g_h₃ := by ext · dsimp; rw [h.comm₁]; abel · dsimp; rw [h.comm₂]; abel · dsimp; rw [h.comm₃]; abel variable (S₁ S₂) /-- A morphism constructed with `nullHomotopic` is homotopic to zero. -/ @[simps] def ofNullHomotopic (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : Homotopy (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) 0 where h₀ := h₀ h₁ := h₁ h₂ := h₂ h₃ := h₃ h₀_f := h₀_f g_h₃ := g_h₃ comm₁ := by rw [nullHomotopic_τ₁, zero_τ₁, add_zero]; abel comm₂ := by rw [nullHomotopic_τ₂, zero_τ₂, add_zero]; abel comm₃ := by rw [nullHomotopic_τ₃, zero_τ₃, add_zero]; abel end Homotopy variable {S₁ S₂} /-- The left homology map data expressing that null homotopic maps induce the zero morphism in left homology. -/ def LeftHomologyMapData.ofNullHomotopic (H₁ : S₁.LeftHomologyData) (H₂ : S₂.LeftHomologyData) (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : LeftHomologyMapData (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) H₁ H₂ where φK := H₂.liftK (H₁.i ≫ h₁ ≫ S₂.f) (by simp) φH := 0 commf' := by rw [← cancel_mono H₂.i, assoc, LeftHomologyData.liftK_i, LeftHomologyData.f'_i_assoc, nullHomotopic_τ₁, add_comp, add_comp, assoc, assoc, assoc, LeftHomologyData.f'_i, right_eq_add, h₀_f] commπ := by rw [H₂.liftK_π_eq_zero_of_boundary (H₁.i ≫ h₁ ≫ S₂.f) (H₁.i ≫ h₁) (by rw [assoc]), comp_zero] /-- The right homology map data expressing that null homotopic maps induce the zero morphism in right homology. -/ def RightHomologyMapData.ofNullHomotopic (H₁ : S₁.RightHomologyData) (H₂ : S₂.RightHomologyData) (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : RightHomologyMapData (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) H₁ H₂ where φQ := H₁.descQ (S₁.g ≫ h₂ ≫ H₂.p) (by simp) φH := 0 commg' := by rw [← cancel_epi H₁.p, RightHomologyData.p_descQ_assoc, RightHomologyData.p_g'_assoc, nullHomotopic_τ₃, comp_add, assoc, assoc, RightHomologyData.p_g', g_h₃, add_zero] commι := by rw [H₁.ι_descQ_eq_zero_of_boundary (S₁.g ≫ h₂ ≫ H₂.p) (h₂ ≫ H₂.p) rfl, zero_comp] @[simp] lemma leftHomologyMap'_nullHomotopic (H₁ : S₁.LeftHomologyData) (H₂ : S₂.LeftHomologyData) (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : leftHomologyMap' (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) H₁ H₂ = 0 := (LeftHomologyMapData.ofNullHomotopic H₁ H₂ h₀ h₀_f h₁ h₂ h₃ g_h₃).leftHomologyMap'_eq @[simp] lemma rightHomologyMap'_nullHomotopic (H₁ : S₁.RightHomologyData) (H₂ : S₂.RightHomologyData) (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : rightHomologyMap' (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) H₁ H₂ = 0 := (RightHomologyMapData.ofNullHomotopic H₁ H₂ h₀ h₀_f h₁ h₂ h₃ g_h₃).rightHomologyMap'_eq @[simp] lemma homologyMap'_nullHomotopic (H₁ : S₁.HomologyData) (H₂ : S₂.HomologyData) (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : homologyMap' (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) H₁ H₂ = 0 := by apply leftHomologyMap'_nullHomotopic variable (S₁ S₂) @[simp] lemma leftHomologyMap_nullHomotopic [S₁.HasLeftHomology] [S₂.HasLeftHomology] (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : leftHomologyMap (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) = 0 := by apply leftHomologyMap'_nullHomotopic @[simp] lemma rightHomologyMap_nullHomotopic [S₁.HasRightHomology] [S₂.HasRightHomology] (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : rightHomologyMap (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) = 0 := by apply rightHomologyMap'_nullHomotopic @[simp] lemma homologyMap_nullHomotopic [S₁.HasHomology] [S₂.HasHomology] (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : homologyMap (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) = 0 := by apply homologyMap'_nullHomotopic namespace Homotopy variable {φ₁ φ₂ S₁ S₂} lemma leftHomologyMap'_congr (h : Homotopy φ₁ φ₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : leftHomologyMap' φ₁ h₁ h₂ = leftHomologyMap' φ₂ h₁ h₂ := by rw [h.eq_add_nullHomotopic, leftHomologyMap'_add, leftHomologyMap'_nullHomotopic, add_zero] lemma rightHomologyMap'_congr (h : Homotopy φ₁ φ₂) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : rightHomologyMap' φ₁ h₁ h₂ = rightHomologyMap' φ₂ h₁ h₂ := by rw [h.eq_add_nullHomotopic, rightHomologyMap'_add, rightHomologyMap'_nullHomotopic, add_zero]
lemma homologyMap'_congr (h : Homotopy φ₁ φ₂) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) : homologyMap' φ₁ h₁ h₂ = homologyMap' φ₂ h₁ h₂ := by rw [h.eq_add_nullHomotopic, homologyMap'_add, homologyMap'_nullHomotopic, add_zero]
Mathlib/Algebra/Homology/ShortComplex/Preadditive.lean
655
657
/- Copyright (c) 2020 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Algebra.Group.Conj import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.Group.Subgroup.Ker /-! # Basic results on subgroups We prove basic results on the definitions of subgroups. The bundled subgroups use bundled monoid homomorphisms. Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration. ## Main definitions Notation used here: - `G N` are `Group`s - `A` is an `AddGroup` - `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A` - `x` is an element of type `G` or type `A` - `f g : N →* G` are group homomorphisms - `s k` are sets of elements of type `G` Definitions in the file: * `Subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H × K` is a subgroup of `G × N` ## Implementation notes Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as membership of a subgroup's underlying set. ## Tags subgroup, subgroups -/ assert_not_exists OrderedAddCommMonoid Multiset Ring open Function open scoped Int variable {G G' G'' : Type*} [Group G] [Group G'] [Group G''] variable {A : Type*} [AddGroup A] section SubgroupClass variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S} variable [SetLike S G] [SubgroupClass S G] @[to_additive] theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := inv_div b a ▸ inv_mem_iff end SubgroupClass namespace Subgroup variable (H K : Subgroup G) @[to_additive] protected theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := div_mem_comm_iff variable {k : Set G} open Set variable {N : Type*} [Group N] {P : Type*} [Group P] /-- Given `Subgroup`s `H`, `K` of groups `G`, `N` respectively, `H × K` as a subgroup of `G × N`. -/ @[to_additive prod "Given `AddSubgroup`s `H`, `K` of `AddGroup`s `A`, `B` respectively, `H × K` as an `AddSubgroup` of `A × B`."] def prod (H : Subgroup G) (K : Subgroup N) : Subgroup (G × N) := { Submonoid.prod H.toSubmonoid K.toSubmonoid with inv_mem' := fun hx => ⟨H.inv_mem' hx.1, K.inv_mem' hx.2⟩ } @[to_additive coe_prod] theorem coe_prod (H : Subgroup G) (K : Subgroup N) : (H.prod K : Set (G × N)) = (H : Set G) ×ˢ (K : Set N) := rfl @[to_additive mem_prod] theorem mem_prod {H : Subgroup G} {K : Subgroup N} {p : G × N} : p ∈ H.prod K ↔ p.1 ∈ H ∧ p.2 ∈ K := Iff.rfl open scoped Relator in @[to_additive prod_mono] theorem prod_mono : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) (@prod G _ N _) (@prod G _ N _) := fun _s _s' hs _t _t' ht => Set.prod_mono hs ht @[to_additive prod_mono_right] theorem prod_mono_right (K : Subgroup G) : Monotone fun t : Subgroup N => K.prod t := prod_mono (le_refl K) @[to_additive prod_mono_left] theorem prod_mono_left (H : Subgroup N) : Monotone fun K : Subgroup G => K.prod H := fun _ _ hs => prod_mono hs (le_refl H) @[to_additive prod_top] theorem prod_top (K : Subgroup G) : K.prod (⊤ : Subgroup N) = K.comap (MonoidHom.fst G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] @[to_additive top_prod] theorem top_prod (H : Subgroup N) : (⊤ : Subgroup G).prod H = H.comap (MonoidHom.snd G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] @[to_additive (attr := simp) top_prod_top] theorem top_prod_top : (⊤ : Subgroup G).prod (⊤ : Subgroup N) = ⊤ := (top_prod _).trans <| comap_top _ @[to_additive (attr := simp) bot_prod_bot] theorem bot_prod_bot : (⊥ : Subgroup G).prod (⊥ : Subgroup N) = ⊥ := SetLike.coe_injective <| by simp [coe_prod] @[deprecated (since := "2025-03-11")] alias _root_.AddSubgroup.bot_sum_bot := AddSubgroup.bot_prod_bot @[to_additive le_prod_iff] theorem le_prod_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : J ≤ H.prod K ↔ map (MonoidHom.fst G N) J ≤ H ∧ map (MonoidHom.snd G N) J ≤ K := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.le_prod_iff @[to_additive prod_le_iff] theorem prod_le_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : H.prod K ≤ J ↔ map (MonoidHom.inl G N) H ≤ J ∧ map (MonoidHom.inr G N) K ≤ J := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.prod_le_iff @[to_additive (attr := simp) prod_eq_bot_iff] theorem prod_eq_bot_iff {H : Subgroup G} {K : Subgroup N} : H.prod K = ⊥ ↔ H = ⊥ ∧ K = ⊥ := by simpa only [← Subgroup.toSubmonoid_inj] using Submonoid.prod_eq_bot_iff @[to_additive closure_prod] theorem closure_prod {s : Set G} {t : Set N} (hs : 1 ∈ s) (ht : 1 ∈ t) : closure (s ×ˢ t) = (closure s).prod (closure t) := le_antisymm (closure_le _ |>.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨subset_closure, subset_closure⟩) (prod_le_iff.2 ⟨ map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _x hx => subset_closure ⟨hx, ht⟩, map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _y hy => subset_closure ⟨hs, hy⟩⟩) /-- Product of subgroups is isomorphic to their product as groups. -/ @[to_additive prodEquiv "Product of additive subgroups is isomorphic to their product as additive groups"] def prodEquiv (H : Subgroup G) (K : Subgroup N) : H.prod K ≃* H × K := { Equiv.Set.prod (H : Set G) (K : Set N) with map_mul' := fun _ _ => rfl } section Pi variable {η : Type*} {f : η → Type*} -- defined here and not in Algebra.Group.Submonoid.Operations to have access to Algebra.Group.Pi /-- A version of `Set.pi` for submonoids. Given an index set `I` and a family of submodules `s : Π i, Submonoid f i`, `pi I s` is the submonoid of dependent functions `f : Π i, f i` such that `f i` belongs to `Pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubmonoid`s. Given an index set `I` and a family of submodules `s : Π i, AddSubmonoid f i`, `pi I s` is the `AddSubmonoid` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def _root_.Submonoid.pi [∀ i, MulOneClass (f i)] (I : Set η) (s : ∀ i, Submonoid (f i)) : Submonoid (∀ i, f i) where carrier := I.pi fun i => (s i).carrier one_mem' i _ := (s i).one_mem mul_mem' hp hq i hI := (s i).mul_mem (hp i hI) (hq i hI) variable [∀ i, Group (f i)] /-- A version of `Set.pi` for subgroups. Given an index set `I` and a family of submodules `s : Π i, Subgroup f i`, `pi I s` is the subgroup of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubgroup`s. Given an index set `I` and a family of submodules `s : Π i, AddSubgroup f i`, `pi I s` is the `AddSubgroup` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def pi (I : Set η) (H : ∀ i, Subgroup (f i)) : Subgroup (∀ i, f i) := { Submonoid.pi I fun i => (H i).toSubmonoid with inv_mem' := fun hp i hI => (H i).inv_mem (hp i hI) } @[to_additive] theorem coe_pi (I : Set η) (H : ∀ i, Subgroup (f i)) : (pi I H : Set (∀ i, f i)) = Set.pi I fun i => (H i : Set (f i)) := rfl @[to_additive] theorem mem_pi (I : Set η) {H : ∀ i, Subgroup (f i)} {p : ∀ i, f i} : p ∈ pi I H ↔ ∀ i : η, i ∈ I → p i ∈ H i := Iff.rfl @[to_additive] theorem pi_top (I : Set η) : (pi I fun i => (⊤ : Subgroup (f i))) = ⊤ := ext fun x => by simp [mem_pi] @[to_additive] theorem pi_empty (H : ∀ i, Subgroup (f i)) : pi ∅ H = ⊤ := ext fun x => by simp [mem_pi] @[to_additive] theorem pi_bot : (pi Set.univ fun i => (⊥ : Subgroup (f i))) = ⊥ := (eq_bot_iff_forall _).mpr fun p hp => by simp only [mem_pi, mem_bot] at * ext j exact hp j trivial @[to_additive] theorem le_pi_iff {I : Set η} {H : ∀ i, Subgroup (f i)} {J : Subgroup (∀ i, f i)} : J ≤ pi I H ↔ ∀ i : η, i ∈ I → map (Pi.evalMonoidHom f i) J ≤ H i := by constructor · intro h i hi rintro _ ⟨x, hx, rfl⟩ exact (h hx) _ hi · intro h x hx i hi exact h i hi ⟨_, hx, rfl⟩ @[to_additive (attr := simp)] theorem mulSingle_mem_pi [DecidableEq η] {I : Set η} {H : ∀ i, Subgroup (f i)} (i : η) (x : f i) : Pi.mulSingle i x ∈ pi I H ↔ i ∈ I → x ∈ H i := by constructor · intro h hi simpa using h i hi · intro h j hj by_cases heq : j = i · subst heq simpa using h hj · simp [heq, one_mem] @[to_additive] theorem pi_eq_bot_iff (H : ∀ i, Subgroup (f i)) : pi Set.univ H = ⊥ ↔ ∀ i, H i = ⊥ := by classical simp only [eq_bot_iff_forall] constructor · intro h i x hx have : MonoidHom.mulSingle f i x = 1 := h (MonoidHom.mulSingle f i x) ((mulSingle_mem_pi i x).mpr fun _ => hx) simpa using congr_fun this i · exact fun h x hx => funext fun i => h _ _ (hx i trivial) end Pi end Subgroup namespace Subgroup variable {H K : Subgroup G} variable (H) /-- A subgroup is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/ structure Characteristic : Prop where /-- `H` is fixed by all automorphisms -/ fixed : ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H attribute [class] Characteristic instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal := ⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (MulAut.conj b)) a).mpr ha⟩ end Subgroup namespace AddSubgroup variable (H : AddSubgroup A) /-- An `AddSubgroup` is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/ structure Characteristic : Prop where /-- `H` is fixed by all automorphisms -/ fixed : ∀ ϕ : A ≃+ A, H.comap ϕ.toAddMonoidHom = H attribute [to_additive] Subgroup.Characteristic attribute [class] Characteristic instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal := ⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (AddAut.conj b)) a).mpr ha⟩ end AddSubgroup namespace Subgroup variable {H K : Subgroup G} @[to_additive] theorem characteristic_iff_comap_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H := ⟨Characteristic.fixed, Characteristic.mk⟩ @[to_additive] theorem characteristic_iff_comap_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom ≤ H := characteristic_iff_comap_eq.trans ⟨fun h ϕ => le_of_eq (h ϕ), fun h ϕ => le_antisymm (h ϕ) fun g hg => h ϕ.symm ((congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mpr hg)⟩ @[to_additive] theorem characteristic_iff_le_comap : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.comap ϕ.toMonoidHom := characteristic_iff_comap_eq.trans ⟨fun h ϕ => ge_of_eq (h ϕ), fun h ϕ => le_antisymm (fun g hg => (congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mp (h ϕ.symm hg)) (h ϕ)⟩ @[to_additive] theorem characteristic_iff_map_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom = H := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_comap_eq.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ @[to_additive] theorem characteristic_iff_map_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom ≤ H := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_comap_le.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ @[to_additive] theorem characteristic_iff_le_map : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.map ϕ.toMonoidHom := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_le_comap.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ @[to_additive] instance botCharacteristic : Characteristic (⊥ : Subgroup G) := characteristic_iff_le_map.mpr fun _ϕ => bot_le @[to_additive] instance topCharacteristic : Characteristic (⊤ : Subgroup G) := characteristic_iff_map_le.mpr fun _ϕ => le_top variable (H) section Normalizer variable {H} @[to_additive] theorem normalizer_eq_top_iff : H.normalizer = ⊤ ↔ H.Normal := eq_top_iff.trans ⟨fun h => ⟨fun a ha b => (h (mem_top b) a).mp ha⟩, fun h a _ha b => ⟨fun hb => h.conj_mem b hb a, fun hb => by rwa [h.mem_comm_iff, inv_mul_cancel_left] at hb⟩⟩ variable (H) in @[to_additive] theorem normalizer_eq_top [h : H.Normal] : H.normalizer = ⊤ := normalizer_eq_top_iff.mpr h variable {N : Type*} [Group N] /-- The preimage of the normalizer is contained in the normalizer of the preimage. -/ @[to_additive "The preimage of the normalizer is contained in the normalizer of the preimage."] theorem le_normalizer_comap (f : N →* G) : H.normalizer.comap f ≤ (H.comap f).normalizer := fun x => by simp only [mem_normalizer_iff, mem_comap] intro h n simp [h (f n)] /-- The image of the normalizer is contained in the normalizer of the image. -/ @[to_additive "The image of the normalizer is contained in the normalizer of the image."] theorem le_normalizer_map (f : G →* N) : H.normalizer.map f ≤ (H.map f).normalizer := fun _ => by simp only [and_imp, exists_prop, mem_map, exists_imp, mem_normalizer_iff] rintro x hx rfl n constructor · rintro ⟨y, hy, rfl⟩ use x * y * x⁻¹, (hx y).1 hy simp · rintro ⟨y, hyH, hy⟩ use x⁻¹ * y * x rw [hx] simp [hy, hyH, mul_assoc] @[to_additive] theorem comap_normalizer_eq_of_le_range {f : N →* G} (h : H ≤ f.range) : comap f H.normalizer = (comap f H).normalizer := by apply le_antisymm (le_normalizer_comap f) rw [← map_le_iff_le_comap] apply (le_normalizer_map f).trans rw [map_comap_eq_self h] @[to_additive] theorem subgroupOf_normalizer_eq {H N : Subgroup G} (h : H ≤ N) : H.normalizer.subgroupOf N = (H.subgroupOf N).normalizer := comap_normalizer_eq_of_le_range (h.trans_eq N.range_subtype.symm) @[to_additive] theorem normal_subgroupOf_iff_le_normalizer (h : H ≤ K) : (H.subgroupOf K).Normal ↔ K ≤ H.normalizer := by rw [← subgroupOf_eq_top, subgroupOf_normalizer_eq h, normalizer_eq_top_iff] @[to_additive] theorem normal_subgroupOf_iff_le_normalizer_inf : (H.subgroupOf K).Normal ↔ K ≤ (H ⊓ K).normalizer := inf_subgroupOf_right H K ▸ normal_subgroupOf_iff_le_normalizer inf_le_right @[to_additive] instance (priority := 100) normal_in_normalizer : (H.subgroupOf H.normalizer).Normal := (normal_subgroupOf_iff_le_normalizer H.le_normalizer).mpr le_rfl @[to_additive] theorem le_normalizer_of_normal_subgroupOf [hK : (H.subgroupOf K).Normal] (HK : H ≤ K) : K ≤ H.normalizer := (normal_subgroupOf_iff_le_normalizer HK).mp hK @[to_additive] theorem subset_normalizer_of_normal {S : Set G} [hH : H.Normal] : S ⊆ H.normalizer := (@normalizer_eq_top _ _ H hH) ▸ le_top @[to_additive] theorem le_normalizer_of_normal [H.Normal] : K ≤ H.normalizer := subset_normalizer_of_normal @[to_additive] theorem inf_normalizer_le_normalizer_inf : H.normalizer ⊓ K.normalizer ≤ (H ⊓ K).normalizer := fun _ h g ↦ and_congr (h.1 g) (h.2 g) variable (G) in /-- Every proper subgroup `H` of `G` is a proper normal subgroup of the normalizer of `H` in `G`. -/ def _root_.NormalizerCondition := ∀ H : Subgroup G, H < ⊤ → H < normalizer H /-- Alternative phrasing of the normalizer condition: Only the full group is self-normalizing. This may be easier to work with, as it avoids inequalities and negations. -/ theorem _root_.normalizerCondition_iff_only_full_group_self_normalizing : NormalizerCondition G ↔ ∀ H : Subgroup G, H.normalizer = H → H = ⊤ := by apply forall_congr'; intro H simp only [lt_iff_le_and_ne, le_normalizer, le_top, Ne] tauto variable (H) end Normalizer end Subgroup namespace Group variable {s : Set G} /-- Given a set `s`, `conjugatesOfSet s` is the set of all conjugates of the elements of `s`. -/ def conjugatesOfSet (s : Set G) : Set G := ⋃ a ∈ s, conjugatesOf a theorem mem_conjugatesOfSet_iff {x : G} : x ∈ conjugatesOfSet s ↔ ∃ a ∈ s, IsConj a x := by rw [conjugatesOfSet, Set.mem_iUnion₂] simp only [conjugatesOf, isConj_iff, Set.mem_setOf_eq, exists_prop] theorem subset_conjugatesOfSet : s ⊆ conjugatesOfSet s := fun (x : G) (h : x ∈ s) => mem_conjugatesOfSet_iff.2 ⟨x, h, IsConj.refl _⟩ theorem conjugatesOfSet_mono {s t : Set G} (h : s ⊆ t) : conjugatesOfSet s ⊆ conjugatesOfSet t := Set.biUnion_subset_biUnion_left h theorem conjugates_subset_normal {N : Subgroup G} [tn : N.Normal] {a : G} (h : a ∈ N) : conjugatesOf a ⊆ N := by rintro a hc obtain ⟨c, rfl⟩ := isConj_iff.1 hc exact tn.conj_mem a h c theorem conjugatesOfSet_subset {s : Set G} {N : Subgroup G} [N.Normal] (h : s ⊆ N) : conjugatesOfSet s ⊆ N := Set.iUnion₂_subset fun _x H => conjugates_subset_normal (h H) /-- The set of conjugates of `s` is closed under conjugation. -/ theorem conj_mem_conjugatesOfSet {x c : G} : x ∈ conjugatesOfSet s → c * x * c⁻¹ ∈ conjugatesOfSet s := fun H => by rcases mem_conjugatesOfSet_iff.1 H with ⟨a, h₁, h₂⟩ exact mem_conjugatesOfSet_iff.2 ⟨a, h₁, h₂.trans (isConj_iff.2 ⟨c, rfl⟩)⟩ end Group namespace Subgroup open Group variable {s : Set G} /-- The normal closure of a set `s` is the subgroup closure of all the conjugates of elements of `s`. It is the smallest normal subgroup containing `s`. -/ def normalClosure (s : Set G) : Subgroup G := closure (conjugatesOfSet s) theorem conjugatesOfSet_subset_normalClosure : conjugatesOfSet s ⊆ normalClosure s := subset_closure theorem subset_normalClosure : s ⊆ normalClosure s := Set.Subset.trans subset_conjugatesOfSet conjugatesOfSet_subset_normalClosure theorem le_normalClosure {H : Subgroup G} : H ≤ normalClosure ↑H := fun _ h => subset_normalClosure h /-- The normal closure of `s` is a normal subgroup. -/ instance normalClosure_normal : (normalClosure s).Normal := ⟨fun n h g => by refine Subgroup.closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_) (fun x _ ihx => ?_) h · exact conjugatesOfSet_subset_normalClosure (conj_mem_conjugatesOfSet hx) · simpa using (normalClosure s).one_mem · rw [← conj_mul] exact mul_mem ihx ihy · rw [← conj_inv] exact inv_mem ihx⟩ /-- The normal closure of `s` is the smallest normal subgroup containing `s`. -/ theorem normalClosure_le_normal {N : Subgroup G} [N.Normal] (h : s ⊆ N) : normalClosure s ≤ N := by intro a w refine closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_) (fun x _ ihx => ?_) w · exact conjugatesOfSet_subset h hx · exact one_mem _ · exact mul_mem ihx ihy · exact inv_mem ihx theorem normalClosure_subset_iff {N : Subgroup G} [N.Normal] : s ⊆ N ↔ normalClosure s ≤ N := ⟨normalClosure_le_normal, Set.Subset.trans subset_normalClosure⟩ @[gcongr] theorem normalClosure_mono {s t : Set G} (h : s ⊆ t) : normalClosure s ≤ normalClosure t := normalClosure_le_normal (Set.Subset.trans h subset_normalClosure) theorem normalClosure_eq_iInf : normalClosure s = ⨅ (N : Subgroup G) (_ : Normal N) (_ : s ⊆ N), N := le_antisymm (le_iInf fun _ => le_iInf fun _ => le_iInf normalClosure_le_normal) (iInf_le_of_le (normalClosure s) (iInf_le_of_le (by infer_instance) (iInf_le_of_le subset_normalClosure le_rfl))) @[simp] theorem normalClosure_eq_self (H : Subgroup G) [H.Normal] : normalClosure ↑H = H := le_antisymm (normalClosure_le_normal rfl.subset) le_normalClosure theorem normalClosure_idempotent : normalClosure ↑(normalClosure s) = normalClosure s := normalClosure_eq_self _ theorem closure_le_normalClosure {s : Set G} : closure s ≤ normalClosure s := by simp only [subset_normalClosure, closure_le] @[simp] theorem normalClosure_closure_eq_normalClosure {s : Set G} : normalClosure ↑(closure s) = normalClosure s := le_antisymm (normalClosure_le_normal closure_le_normalClosure) (normalClosure_mono subset_closure) /-- The normal core of a subgroup `H` is the largest normal subgroup of `G` contained in `H`, as shown by `Subgroup.normalCore_eq_iSup`. -/ def normalCore (H : Subgroup G) : Subgroup G where carrier := { a : G | ∀ b : G, b * a * b⁻¹ ∈ H } one_mem' a := by rw [mul_one, mul_inv_cancel]; exact H.one_mem inv_mem' {_} h b := (congr_arg (· ∈ H) conj_inv).mp (H.inv_mem (h b)) mul_mem' {_ _} ha hb c := (congr_arg (· ∈ H) conj_mul).mp (H.mul_mem (ha c) (hb c)) theorem normalCore_le (H : Subgroup G) : H.normalCore ≤ H := fun a h => by rw [← mul_one a, ← inv_one, ← one_mul a] exact h 1 instance normalCore_normal (H : Subgroup G) : H.normalCore.Normal := ⟨fun a h b c => by rw [mul_assoc, mul_assoc, ← mul_inv_rev, ← mul_assoc, ← mul_assoc]; exact h (c * b)⟩ theorem normal_le_normalCore {H : Subgroup G} {N : Subgroup G} [hN : N.Normal] : N ≤ H.normalCore ↔ N ≤ H := ⟨ge_trans H.normalCore_le, fun h_le n hn g => h_le (hN.conj_mem n hn g)⟩ theorem normalCore_mono {H K : Subgroup G} (h : H ≤ K) : H.normalCore ≤ K.normalCore := normal_le_normalCore.mpr (H.normalCore_le.trans h) theorem normalCore_eq_iSup (H : Subgroup G) : H.normalCore = ⨆ (N : Subgroup G) (_ : Normal N) (_ : N ≤ H), N := le_antisymm (le_iSup_of_le H.normalCore (le_iSup_of_le H.normalCore_normal (le_iSup_of_le H.normalCore_le le_rfl))) (iSup_le fun _ => iSup_le fun _ => iSup_le normal_le_normalCore.mpr) @[simp] theorem normalCore_eq_self (H : Subgroup G) [H.Normal] : H.normalCore = H := le_antisymm H.normalCore_le (normal_le_normalCore.mpr le_rfl) theorem normalCore_idempotent (H : Subgroup G) : H.normalCore.normalCore = H.normalCore := H.normalCore.normalCore_eq_self end Subgroup namespace MonoidHom variable {N : Type*} {P : Type*} [Group N] [Group P] (K : Subgroup G) open Subgroup section Ker variable {M : Type*} [MulOneClass M] @[to_additive prodMap_comap_prod] theorem prodMap_comap_prod {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G →* N) (g : G' →* N') (S : Subgroup N) (S' : Subgroup N') : (S.prod S').comap (prodMap f g) = (S.comap f).prod (S'.comap g) := SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _ @[deprecated (since := "2025-03-11")] alias _root_.AddMonoidHom.sumMap_comap_sum := AddMonoidHom.prodMap_comap_prod @[to_additive ker_prodMap] theorem ker_prodMap {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G →* N) (g : G' →* N') : (prodMap f g).ker = f.ker.prod g.ker := by rw [← comap_bot, ← comap_bot, ← comap_bot, ← prodMap_comap_prod, bot_prod_bot] @[deprecated (since := "2025-03-11")] alias _root_.AddMonoidHom.ker_sumMap := AddMonoidHom.ker_prodMap @[to_additive (attr := simp)] lemma ker_fst : ker (fst G G') = .prod ⊥ ⊤ := SetLike.ext fun _ => (iff_of_eq (and_true _)).symm @[to_additive (attr := simp)] lemma ker_snd : ker (snd G G') = .prod ⊤ ⊥ := SetLike.ext fun _ => (iff_of_eq (true_and _)).symm end Ker end MonoidHom namespace Subgroup variable {N : Type*} [Group N] (H : Subgroup G) @[to_additive] theorem Normal.map {H : Subgroup G} (h : H.Normal) (f : G →* N) (hf : Function.Surjective f) : (H.map f).Normal := by rw [← normalizer_eq_top_iff, ← top_le_iff, ← f.range_eq_top_of_surjective hf, f.range_eq_map, ← H.normalizer_eq_top] exact le_normalizer_map _ end Subgroup namespace Subgroup open MonoidHom variable {N : Type*} [Group N] (f : G →* N) /-- The preimage of the normalizer is equal to the normalizer of the preimage of a surjective function. -/ @[to_additive "The preimage of the normalizer is equal to the normalizer of the preimage of a surjective function."] theorem comap_normalizer_eq_of_surjective (H : Subgroup G) {f : N →* G} (hf : Function.Surjective f) : H.normalizer.comap f = (H.comap f).normalizer := comap_normalizer_eq_of_le_range fun x _ ↦ hf x @[deprecated (since := "2025-03-13")] alias comap_normalizer_eq_of_injective_of_le_range := comap_normalizer_eq_of_le_range @[deprecated (since := "2025-03-13")] alias _root_.AddSubgroup.comap_normalizer_eq_of_injective_of_le_range := AddSubgroup.comap_normalizer_eq_of_le_range /-- The image of the normalizer is equal to the normalizer of the image of an isomorphism. -/ @[to_additive "The image of the normalizer is equal to the normalizer of the image of an isomorphism."] theorem map_equiv_normalizer_eq (H : Subgroup G) (f : G ≃* N) : H.normalizer.map f.toMonoidHom = (H.map f.toMonoidHom).normalizer := by ext x simp only [mem_normalizer_iff, mem_map_equiv] rw [f.toEquiv.forall_congr] intro simp /-- The image of the normalizer is equal to the normalizer of the image of a bijective function. -/ @[to_additive "The image of the normalizer is equal to the normalizer of the image of a bijective function."] theorem map_normalizer_eq_of_bijective (H : Subgroup G) {f : G →* N} (hf : Function.Bijective f) : H.normalizer.map f = (H.map f).normalizer := map_equiv_normalizer_eq H (MulEquiv.ofBijective f hf) end Subgroup namespace MonoidHom variable {G₁ G₂ G₃ : Type*} [Group G₁] [Group G₂] [Group G₃] variable (f : G₁ →* G₂) (f_inv : G₂ → G₁) /-- Auxiliary definition used to define `liftOfRightInverse` -/ @[to_additive "Auxiliary definition used to define `liftOfRightInverse`"] def liftOfRightInverseAux (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) : G₂ →* G₃ where toFun b := g (f_inv b) map_one' := hg (hf 1) map_mul' := by intro x y rw [← g.map_mul, ← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker] apply hg rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one, f.map_mul] simp only [hf _] @[to_additive (attr := simp)] theorem liftOfRightInverseAux_comp_apply (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) (x : G₁) : (f.liftOfRightInverseAux f_inv hf g hg) (f x) = g x := by dsimp [liftOfRightInverseAux] rw [← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker] apply hg rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one] simp only [hf _] /-- `liftOfRightInverse f hf g hg` is the unique group homomorphism `φ` * such that `φ.comp f = g` (`MonoidHom.liftOfRightInverse_comp`), * where `f : G₁ →+* G₂` has a RightInverse `f_inv` (`hf`), * and `g : G₂ →+* G₃` satisfies `hg : f.ker ≤ g.ker`. See `MonoidHom.eq_liftOfRightInverse` for the uniqueness lemma. ``` G₁. | \ f | \ g | \ v \⌟ G₂----> G₃ ∃!φ ``` -/ @[to_additive "`liftOfRightInverse f f_inv hf g hg` is the unique additive group homomorphism `φ` * such that `φ.comp f = g` (`AddMonoidHom.liftOfRightInverse_comp`), * where `f : G₁ →+ G₂` has a RightInverse `f_inv` (`hf`), * and `g : G₂ →+ G₃` satisfies `hg : f.ker ≤ g.ker`. See `AddMonoidHom.eq_liftOfRightInverse` for the uniqueness lemma. ``` G₁. | \\ f | \\ g | \\ v \\⌟ G₂----> G₃ ∃!φ ```"] def liftOfRightInverse (hf : Function.RightInverse f_inv f) : { g : G₁ →* G₃ // f.ker ≤ g.ker } ≃ (G₂ →* G₃) where toFun g := f.liftOfRightInverseAux f_inv hf g.1 g.2 invFun φ := ⟨φ.comp f, fun x hx ↦ mem_ker.mpr <| by simp [mem_ker.mp hx]⟩ left_inv g := by ext simp only [comp_apply, liftOfRightInverseAux_comp_apply, Subtype.coe_mk] right_inv φ := by ext b simp [liftOfRightInverseAux, hf b] /-- A non-computable version of `MonoidHom.liftOfRightInverse` for when no computable right inverse is available, that uses `Function.surjInv`. -/ @[to_additive (attr := simp) "A non-computable version of `AddMonoidHom.liftOfRightInverse` for when no computable right inverse is available."] noncomputable abbrev liftOfSurjective (hf : Function.Surjective f) : { g : G₁ →* G₃ // f.ker ≤ g.ker } ≃ (G₂ →* G₃) := f.liftOfRightInverse (Function.surjInv hf) (Function.rightInverse_surjInv hf) @[to_additive (attr := simp)] theorem liftOfRightInverse_comp_apply (hf : Function.RightInverse f_inv f) (g : { g : G₁ →* G₃ // f.ker ≤ g.ker }) (x : G₁) : (f.liftOfRightInverse f_inv hf g) (f x) = g.1 x := f.liftOfRightInverseAux_comp_apply f_inv hf g.1 g.2 x @[to_additive (attr := simp)] theorem liftOfRightInverse_comp (hf : Function.RightInverse f_inv f) (g : { g : G₁ →* G₃ // f.ker ≤ g.ker }) : (f.liftOfRightInverse f_inv hf g).comp f = g := MonoidHom.ext <| f.liftOfRightInverse_comp_apply f_inv hf g @[to_additive] theorem eq_liftOfRightInverse (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) (h : G₂ →* G₃) (hh : h.comp f = g) : h = f.liftOfRightInverse f_inv hf ⟨g, hg⟩ := by simp_rw [← hh] exact ((f.liftOfRightInverse f_inv hf).apply_symm_apply _).symm end MonoidHom variable {N : Type*} [Group N] namespace Subgroup -- Here `H.Normal` is an explicit argument so we can use dot notation with `comap`. @[to_additive] theorem Normal.comap {H : Subgroup N} (hH : H.Normal) (f : G →* N) : (H.comap f).Normal := ⟨fun _ => by simp +contextual [Subgroup.mem_comap, hH.conj_mem]⟩ @[to_additive] instance (priority := 100) normal_comap {H : Subgroup N} [nH : H.Normal] (f : G →* N) : (H.comap f).Normal := nH.comap _ -- Here `H.Normal` is an explicit argument so we can use dot notation with `subgroupOf`. @[to_additive] theorem Normal.subgroupOf {H : Subgroup G} (hH : H.Normal) (K : Subgroup G) : (H.subgroupOf K).Normal := hH.comap _ @[to_additive] instance (priority := 100) normal_subgroupOf {H N : Subgroup G} [N.Normal] : (N.subgroupOf H).Normal := Subgroup.normal_comap _ theorem map_normalClosure (s : Set G) (f : G →* N) (hf : Surjective f) : (normalClosure s).map f = normalClosure (f '' s) := by have : Normal (map f (normalClosure s)) := Normal.map inferInstance f hf apply le_antisymm · simp [map_le_iff_le_comap, normalClosure_le_normal, coe_comap, ← Set.image_subset_iff, subset_normalClosure] · exact normalClosure_le_normal (Set.image_subset f subset_normalClosure) theorem comap_normalClosure (s : Set N) (f : G ≃* N) : normalClosure (f ⁻¹' s) = (normalClosure s).comap f := by have := Set.preimage_equiv_eq_image_symm s f.toEquiv simp_all [comap_equiv_eq_map_symm, map_normalClosure s (f.symm : N →* G) f.symm.surjective] lemma Normal.of_map_injective {G H : Type*} [Group G] [Group H] {φ : G →* H} (hφ : Function.Injective φ) {L : Subgroup G} (n : (L.map φ).Normal) : L.Normal := L.comap_map_eq_self_of_injective hφ ▸ n.comap φ theorem Normal.of_map_subtype {K : Subgroup G} {L : Subgroup K} (n : (Subgroup.map K.subtype L).Normal) : L.Normal := n.of_map_injective K.subtype_injective end Subgroup namespace Subgroup section SubgroupNormal @[to_additive] theorem normal_subgroupOf_iff {H K : Subgroup G} (hHK : H ≤ K) : (H.subgroupOf K).Normal ↔ ∀ h k, h ∈ H → k ∈ K → k * h * k⁻¹ ∈ H := ⟨fun hN h k hH hK => hN.conj_mem ⟨h, hHK hH⟩ hH ⟨k, hK⟩, fun hN => { conj_mem := fun h hm k => hN h.1 k.1 hm k.2 }⟩ @[to_additive prod_addSubgroupOf_prod_normal] instance prod_subgroupOf_prod_normal {H₁ K₁ : Subgroup G} {H₂ K₂ : Subgroup N} [h₁ : (H₁.subgroupOf K₁).Normal] [h₂ : (H₂.subgroupOf K₂).Normal] : ((H₁.prod H₂).subgroupOf (K₁.prod K₂)).Normal where conj_mem n hgHK g := ⟨h₁.conj_mem ⟨(n : G × N).fst, (mem_prod.mp n.2).1⟩ hgHK.1 ⟨(g : G × N).fst, (mem_prod.mp g.2).1⟩, h₂.conj_mem ⟨(n : G × N).snd, (mem_prod.mp n.2).2⟩ hgHK.2 ⟨(g : G × N).snd, (mem_prod.mp g.2).2⟩⟩ @[deprecated (since := "2025-03-11")] alias _root_.AddSubgroup.sum_addSubgroupOf_sum_normal := AddSubgroup.prod_addSubgroupOf_prod_normal @[to_additive prod_normal] instance prod_normal (H : Subgroup G) (K : Subgroup N) [hH : H.Normal] [hK : K.Normal] : (H.prod K).Normal where conj_mem n hg g := ⟨hH.conj_mem n.fst (Subgroup.mem_prod.mp hg).1 g.fst, hK.conj_mem n.snd (Subgroup.mem_prod.mp hg).2 g.snd⟩ @[deprecated (since := "2025-03-11")] alias _root_.AddSubgroup.sum_normal := AddSubgroup.prod_normal @[to_additive] theorem inf_subgroupOf_inf_normal_of_right (A B' B : Subgroup G) [hN : (B'.subgroupOf B).Normal] : ((A ⊓ B').subgroupOf (A ⊓ B)).Normal := by rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊢ rw [inf_inf_inf_comm, inf_idem] exact le_trans (inf_le_inf A.le_normalizer hN) (inf_normalizer_le_normalizer_inf) @[to_additive] theorem inf_subgroupOf_inf_normal_of_left {A' A : Subgroup G} (B : Subgroup G) [hN : (A'.subgroupOf A).Normal] : ((A' ⊓ B).subgroupOf (A ⊓ B)).Normal := by rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊢ rw [inf_inf_inf_comm, inf_idem] exact le_trans (inf_le_inf hN B.le_normalizer) (inf_normalizer_le_normalizer_inf) @[to_additive] instance normal_inf_normal (H K : Subgroup G) [hH : H.Normal] [hK : K.Normal] : (H ⊓ K).Normal := ⟨fun n hmem g => ⟨hH.conj_mem n hmem.1 g, hK.conj_mem n hmem.2 g⟩⟩ @[to_additive] theorem normal_iInf_normal {ι : Type*} {a : ι → Subgroup G} (norm : ∀ i : ι, (a i).Normal) : (iInf a).Normal := by constructor intro g g_in_iInf h rw [Subgroup.mem_iInf] at g_in_iInf ⊢ intro i exact (norm i).conj_mem g (g_in_iInf i) h @[to_additive] theorem SubgroupNormal.mem_comm {H K : Subgroup G} (hK : H ≤ K) [hN : (H.subgroupOf K).Normal] {a b : G} (hb : b ∈ K) (h : a * b ∈ H) : b * a ∈ H := by have := (normal_subgroupOf_iff hK).mp hN (a * b) b h hb rwa [mul_assoc, mul_assoc, mul_inv_cancel, mul_one] at this /-- Elements of disjoint, normal subgroups commute. -/ @[to_additive "Elements of disjoint, normal subgroups commute."] theorem commute_of_normal_of_disjoint (H₁ H₂ : Subgroup G) (hH₁ : H₁.Normal) (hH₂ : H₂.Normal) (hdis : Disjoint H₁ H₂) (x y : G) (hx : x ∈ H₁) (hy : y ∈ H₂) : Commute x y := by suffices x * y * x⁻¹ * y⁻¹ = 1 by show x * y = y * x · rw [mul_assoc, mul_eq_one_iff_eq_inv] at this simpa apply hdis.le_bot constructor · suffices x * (y * x⁻¹ * y⁻¹) ∈ H₁ by simpa [mul_assoc] exact H₁.mul_mem hx (hH₁.conj_mem _ (H₁.inv_mem hx) _) · show x * y * x⁻¹ * y⁻¹ ∈ H₂ apply H₂.mul_mem _ (H₂.inv_mem hy) apply hH₂.conj_mem _ hy @[to_additive] theorem normal_subgroupOf_of_le_normalizer {H N : Subgroup G} (hLE : H ≤ N.normalizer) : (N.subgroupOf H).Normal := by rw [normal_subgroupOf_iff_le_normalizer_inf] exact (le_inf hLE H.le_normalizer).trans inf_normalizer_le_normalizer_inf @[to_additive] theorem normal_subgroupOf_sup_of_le_normalizer {H N : Subgroup G} (hLE : H ≤ N.normalizer) : (N.subgroupOf (H ⊔ N)).Normal := by rw [normal_subgroupOf_iff_le_normalizer le_sup_right] exact sup_le hLE le_normalizer end SubgroupNormal end Subgroup namespace IsConj open Subgroup theorem normalClosure_eq_top_of {N : Subgroup G} [hn : N.Normal] {g g' : G} {hg : g ∈ N} {hg' : g' ∈ N} (hc : IsConj g g') (ht : normalClosure ({⟨g, hg⟩} : Set N) = ⊤) : normalClosure ({⟨g', hg'⟩} : Set N) = ⊤ := by obtain ⟨c, rfl⟩ := isConj_iff.1 hc have h : ∀ x : N, (MulAut.conj c) x ∈ N := by rintro ⟨x, hx⟩ exact hn.conj_mem _ hx c have hs : Function.Surjective (((MulAut.conj c).toMonoidHom.restrict N).codRestrict _ h) := by rintro ⟨x, hx⟩ refine ⟨⟨c⁻¹ * x * c, ?_⟩, ?_⟩ · have h := hn.conj_mem _ hx c⁻¹ rwa [inv_inv] at h simp only [MonoidHom.codRestrict_apply, MulEquiv.coe_toMonoidHom, MulAut.conj_apply, coe_mk, MonoidHom.restrict_apply, Subtype.mk_eq_mk, ← mul_assoc, mul_inv_cancel, one_mul] rw [mul_assoc, mul_inv_cancel, mul_one] rw [eq_top_iff, ← MonoidHom.range_eq_top.2 hs, MonoidHom.range_eq_map] refine le_trans (map_mono (eq_top_iff.1 ht)) (map_le_iff_le_comap.2 (normalClosure_le_normal ?_)) rw [Set.singleton_subset_iff, SetLike.mem_coe] simp only [MonoidHom.codRestrict_apply, MulEquiv.coe_toMonoidHom, MulAut.conj_apply, coe_mk, MonoidHom.restrict_apply, mem_comap] exact subset_normalClosure (Set.mem_singleton _) end IsConj namespace ConjClasses /-- The conjugacy classes that are not trivial. -/ def noncenter (G : Type*) [Monoid G] : Set (ConjClasses G) := {x | x.carrier.Nontrivial} @[simp] lemma mem_noncenter {G} [Monoid G] (g : ConjClasses G) : g ∈ noncenter G ↔ g.carrier.Nontrivial := Iff.rfl end ConjClasses /-- Suppose `G` acts on `M` and `I` is a subgroup of `M`. The inertia subgroup of `I` is the subgroup of `G` whose action is trivial mod `I`. -/ def AddSubgroup.inertia {M : Type*} [AddGroup M] (I : AddSubgroup M) (G : Type*) [Group G] [MulAction G M] : Subgroup G where carrier := { σ | ∀ x, σ • x - x ∈ I } mul_mem' {a b} ha hb x := by simpa [mul_smul] using add_mem (ha (b • x)) (hb x) one_mem' := by simp [zero_mem] inv_mem' {a} ha x := by simpa using sub_mem_comm_iff.mp (ha (a⁻¹ • x)) @[simp] lemma AddSubgroup.mem_inertia {M : Type*} [AddGroup M] {I : AddSubgroup M} {G : Type*} [Group G] [MulAction G M] {σ : G} : σ ∈ I.inertia G ↔ ∀ x, σ • x - x ∈ I := .rfl
Mathlib/Algebra/Group/Subgroup/Basic.lean
3,164
3,173
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jeremy Avigad -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Notation.Pi import Mathlib.Data.Set.Lattice import Mathlib.Order.Filter.Defs /-! # Theory of filters on sets A *filter* on a type `α` is a collection of sets of `α` which contains the whole `α`, is upwards-closed, and is stable under intersection. They are mostly used to abstract two related kinds of ideas: * *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions at a point or at infinity, etc... * *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough a point `x`, or for close enough pairs of points, or things happening almost everywhere in the sense of measure theory. Dually, filters can also express the idea of *things happening often*: for arbitrarily large `n`, or at a point in any neighborhood of given a point etc... ## Main definitions In this file, we endow `Filter α` it with a complete lattice structure. This structure is lifted from the lattice structure on `Set (Set X)` using the Galois insertion which maps a filter to its elements in one direction, and an arbitrary set of sets to the smallest filter containing it in the other direction. We also prove `Filter` is a monadic functor, with a push-forward operation `Filter.map` and a pull-back operation `Filter.comap` that form a Galois connections for the order on filters. The examples of filters appearing in the description of the two motivating ideas are: * `(Filter.atTop : Filter ℕ)` : made of sets of `ℕ` containing `{n | n ≥ N}` for some `N` * `𝓝 x` : made of neighborhoods of `x` in a topological space (defined in topology.basic) * `𝓤 X` : made of entourages of a uniform space (those space are generalizations of metric spaces defined in `Mathlib/Topology/UniformSpace/Basic.lean`) * `MeasureTheory.ae` : made of sets whose complement has zero measure with respect to `μ` (defined in `Mathlib/MeasureTheory/OuterMeasure/AE`) The predicate "happening eventually" is `Filter.Eventually`, and "happening often" is `Filter.Frequently`, whose definitions are immediate after `Filter` is defined (but they come rather late in this file in order to immediately relate them to the lattice structure). ## Notations * `∀ᶠ x in f, p x` : `f.Eventually p`; * `∃ᶠ x in f, p x` : `f.Frequently p`; * `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`; * `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`; * `𝓟 s` : `Filter.Principal s`, localized in `Filter`. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element `⊥` for its lattice structure, at the cost of including the assumption `[NeBot f]` in a number of lemmas and definitions. -/ assert_not_exists OrderedSemiring Fintype open Function Set Order open scoped symmDiff universe u v w x y namespace Filter variable {α : Type u} {f g : Filter α} {s t : Set α} instance inhabitedMem : Inhabited { s : Set α // s ∈ f } := ⟨⟨univ, f.univ_sets⟩⟩ theorem filter_eq_iff : f = g ↔ f.sets = g.sets := ⟨congr_arg _, filter_eq⟩ @[simp] theorem sets_subset_sets : f.sets ⊆ g.sets ↔ g ≤ f := .rfl @[simp] theorem sets_ssubset_sets : f.sets ⊂ g.sets ↔ g < f := .rfl /-- An extensionality lemma that is useful for filters with good lemmas about `sᶜ ∈ f` (e.g., `Filter.comap`, `Filter.coprod`, `Filter.Coprod`, `Filter.cofinite`). -/ protected theorem coext (h : ∀ s, sᶜ ∈ f ↔ sᶜ ∈ g) : f = g := Filter.ext <| compl_surjective.forall.2 h instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where trans h₁ h₂ := mem_of_superset h₂ h₁ instance : Trans Membership.mem (· ⊆ ·) (Membership.mem : Filter α → Set α → Prop) where trans h₁ h₂ := mem_of_superset h₁ h₂ @[simp] theorem inter_mem_iff {s t : Set α} : s ∩ t ∈ f ↔ s ∈ f ∧ t ∈ f := ⟨fun h => ⟨mem_of_superset h inter_subset_left, mem_of_superset h inter_subset_right⟩, and_imp.2 inter_mem⟩ theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f := inter_mem hs ht theorem congr_sets (h : { x | x ∈ s ↔ x ∈ t } ∈ f) : s ∈ f ↔ t ∈ f := ⟨fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mp), fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mpr)⟩ lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem /-- Weaker version of `Filter.biInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/ theorem biInter_mem' {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Subsingleton) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := by apply Subsingleton.induction_on hf <;> simp /-- Weaker version of `Filter.iInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/ theorem iInter_mem' {β : Sort v} {s : β → Set α} [Subsingleton β] : (⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f := by rw [← sInter_range, sInter_eq_biInter, biInter_mem' (subsingleton_range s), forall_mem_range] theorem exists_mem_subset_iff : (∃ t ∈ f, t ⊆ s) ↔ s ∈ f := ⟨fun ⟨_, ht, ts⟩ => mem_of_superset ht ts, fun hs => ⟨s, hs, Subset.rfl⟩⟩ theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h => mem_of_superset h hst theorem exists_mem_and_iff {P : Set α → Prop} {Q : Set α → Prop} (hP : Antitone P) (hQ : Antitone Q) : ((∃ u ∈ f, P u) ∧ ∃ u ∈ f, Q u) ↔ ∃ u ∈ f, P u ∧ Q u := by constructor · rintro ⟨⟨u, huf, hPu⟩, v, hvf, hQv⟩ exact ⟨u ∩ v, inter_mem huf hvf, hP inter_subset_left hPu, hQ inter_subset_right hQv⟩ · rintro ⟨u, huf, hPu, hQu⟩ exact ⟨⟨u, huf, hPu⟩, u, huf, hQu⟩ theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} : (∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b := Set.forall_in_swap end Filter namespace Filter variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x} theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl section Lattice variable {f g : Filter α} {s t : Set α} protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop] /-- `GenerateSets g s`: `s` is in the filter closure of `g`. -/ inductive GenerateSets (g : Set (Set α)) : Set α → Prop | basic {s : Set α} : s ∈ g → GenerateSets g s | univ : GenerateSets g univ | superset {s t : Set α} : GenerateSets g s → s ⊆ t → GenerateSets g t | inter {s t : Set α} : GenerateSets g s → GenerateSets g t → GenerateSets g (s ∩ t) /-- `generate g` is the largest filter containing the sets `g`. -/ def generate (g : Set (Set α)) : Filter α where sets := {s | GenerateSets g s} univ_sets := GenerateSets.univ sets_of_superset := GenerateSets.superset inter_sets := GenerateSets.inter lemma mem_generate_of_mem {s : Set <| Set α} {U : Set α} (h : U ∈ s) : U ∈ generate s := GenerateSets.basic h theorem le_generate_iff {s : Set (Set α)} {f : Filter α} : f ≤ generate s ↔ s ⊆ f.sets := Iff.intro (fun h _ hu => h <| GenerateSets.basic <| hu) fun h _ hu => hu.recOn (fun h' => h h') univ_mem (fun _ hxy hx => mem_of_superset hx hxy) fun _ _ hx hy => inter_mem hx hy @[simp] lemma generate_singleton (s : Set α) : generate {s} = 𝓟 s := le_antisymm (fun _t ht ↦ mem_of_superset (mem_generate_of_mem <| mem_singleton _) ht) <| le_generate_iff.2 <| singleton_subset_iff.2 Subset.rfl /-- `mkOfClosure s hs` constructs a filter on `α` whose elements set is exactly `s : Set (Set α)`, provided one gives the assumption `hs : (generate s).sets = s`. -/ protected def mkOfClosure (s : Set (Set α)) (hs : (generate s).sets = s) : Filter α where sets := s univ_sets := hs ▸ univ_mem sets_of_superset := hs ▸ mem_of_superset inter_sets := hs ▸ inter_mem theorem mkOfClosure_sets {s : Set (Set α)} {hs : (generate s).sets = s} : Filter.mkOfClosure s hs = generate s := Filter.ext fun u => show u ∈ (Filter.mkOfClosure s hs).sets ↔ u ∈ (generate s).sets from hs.symm ▸ Iff.rfl /-- Galois insertion from sets of sets into filters. -/ def giGenerate (α : Type*) : @GaloisInsertion (Set (Set α)) (Filter α)ᵒᵈ _ _ Filter.generate Filter.sets where gc _ _ := le_generate_iff le_l_u _ _ h := GenerateSets.basic h choice s hs := Filter.mkOfClosure s (le_antisymm hs <| le_generate_iff.1 <| le_rfl) choice_eq _ _ := mkOfClosure_sets theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ := Iff.rfl theorem mem_inf_of_left {f g : Filter α} {s : Set α} (h : s ∈ f) : s ∈ f ⊓ g := ⟨s, h, univ, univ_mem, (inter_univ s).symm⟩ theorem mem_inf_of_right {f g : Filter α} {s : Set α} (h : s ∈ g) : s ∈ f ⊓ g := ⟨univ, univ_mem, s, h, (univ_inter s).symm⟩ theorem inter_mem_inf {α : Type u} {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∩ t ∈ f ⊓ g := ⟨s, hs, t, ht, rfl⟩ theorem mem_inf_of_inter {f g : Filter α} {s t u : Set α} (hs : s ∈ f) (ht : t ∈ g) (h : s ∩ t ⊆ u) : u ∈ f ⊓ g := mem_of_superset (inter_mem_inf hs ht) h theorem mem_inf_iff_superset {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ∩ t₂ ⊆ s := ⟨fun ⟨t₁, h₁, t₂, h₂, Eq⟩ => ⟨t₁, h₁, t₂, h₂, Eq ▸ Subset.rfl⟩, fun ⟨_, h₁, _, h₂, sub⟩ => mem_inf_of_inter h₁ h₂ sub⟩ section CompleteLattice /-- Complete lattice structure on `Filter α`. -/ instance instCompleteLatticeFilter : CompleteLattice (Filter α) where inf a b := min a b sup a b := max a b le_sup_left _ _ _ h := h.1 le_sup_right _ _ _ h := h.2 sup_le _ _ _ h₁ h₂ _ h := ⟨h₁ h, h₂ h⟩ inf_le_left _ _ _ := mem_inf_of_left inf_le_right _ _ _ := mem_inf_of_right le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb) le_sSup _ _ h₁ _ h₂ := h₂ h₁ sSup_le _ _ h₁ _ h₂ _ h₃ := h₁ _ h₃ h₂ sInf_le _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds]; exact fun _ h₃ ↦ h₃ h₁ h₂ le_sInf _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds] at h₂; exact h₂ h₁ le_top _ _ := univ_mem' bot_le _ _ _ := trivial instance : Inhabited (Filter α) := ⟨⊥⟩ end CompleteLattice theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne' @[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g := ⟨ne_bot_of_le_ne_bot hf.1 hg⟩ theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g := hf.mono hg @[simp] theorem sup_neBot {f g : Filter α} : NeBot (f ⊔ g) ↔ NeBot f ∨ NeBot g := by simp only [neBot_iff, not_and_or, Ne, sup_eq_bot_iff] theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff] theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl /-- Either `f = ⊥` or `Filter.NeBot f`. This is a version of `eq_or_ne` that uses `Filter.NeBot` as the second alternative, to be used as an instance. -/ theorem eq_or_neBot (f : Filter α) : f = ⊥ ∨ NeBot f := (eq_or_ne f ⊥).imp_right NeBot.mk theorem sup_sets_eq {f g : Filter α} : (f ⊔ g).sets = f.sets ∩ g.sets := (giGenerate α).gc.u_inf theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets := (giGenerate α).gc.u_sInf theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets := (giGenerate α).gc.u_iInf theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) := (giGenerate α).gc.l_bot theorem generate_univ : Filter.generate univ = (⊥ : Filter α) := bot_unique fun _ _ => GenerateSets.basic (mem_univ _) theorem generate_union {s t : Set (Set α)} : Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t := (giGenerate α).gc.l_sup theorem generate_iUnion {s : ι → Set (Set α)} : Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) := (giGenerate α).gc.l_iSup @[simp] theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g := Iff.rfl theorem union_mem_sup {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∪ t ∈ f ⊔ g := ⟨mem_of_superset hs subset_union_left, mem_of_superset ht subset_union_right⟩ @[simp] theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by simp only [← Filter.mem_sets, iSup_sets_eq, mem_iInter] @[simp] theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by simp [neBot_iff] theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) := eq_of_forall_le_iff fun _ ↦ by simp [le_generate_iff] theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i := iInf_le f i hs @[simp] theorem le_principal_iff {s : Set α} {f : Filter α} : f ≤ 𝓟 s ↔ s ∈ f := ⟨fun h => h Subset.rfl, fun hs _ ht => mem_of_superset hs ht⟩ theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } := Set.ext fun _ => le_principal_iff theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by simp only [le_principal_iff, mem_principal] @[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono @[mono] theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2 @[simp] theorem principal_eq_iff_eq {s t : Set α} : 𝓟 s = 𝓟 t ↔ s = t := by simp only [le_antisymm_iff, le_principal_iff, mem_principal]; rfl @[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl @[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ := top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true] @[simp] theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ := bot_unique fun _ _ => empty_subset _ theorem generate_eq_biInf (S : Set (Set α)) : generate S = ⨅ s ∈ S, 𝓟 s := eq_of_forall_le_iff fun f => by simp [le_generate_iff, le_principal_iff, subset_def] /-! ### Lattice equations -/ theorem empty_mem_iff_bot {f : Filter α} : ∅ ∈ f ↔ f = ⊥ := ⟨fun h => bot_unique fun s _ => mem_of_superset h (empty_subset s), fun h => h.symm ▸ mem_bot⟩ theorem nonempty_of_mem {f : Filter α} [hf : NeBot f] {s : Set α} (hs : s ∈ f) : s.Nonempty := s.eq_empty_or_nonempty.elim (fun h => absurd hs (h.symm ▸ mt empty_mem_iff_bot.mp hf.1)) id theorem NeBot.nonempty_of_mem {f : Filter α} (hf : NeBot f) {s : Set α} (hs : s ∈ f) : s.Nonempty := @Filter.nonempty_of_mem α f hf s hs @[simp] theorem empty_not_mem (f : Filter α) [NeBot f] : ¬∅ ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α := nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f) theorem compl_not_mem {f : Filter α} {s : Set α} [NeBot f] (h : s ∈ f) : sᶜ ∉ f := fun hsc => (nonempty_of_mem (inter_mem h hsc)).ne_empty <| inter_compl_self s theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ := empty_mem_iff_bot.mp <| univ_mem' isEmptyElim protected lemma disjoint_iff {f g : Filter α} : Disjoint f g ↔ ∃ s ∈ f, ∃ t ∈ g, Disjoint s t := by simp only [disjoint_iff, ← empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty, @eq_comm _ ∅] theorem disjoint_of_disjoint_of_mem {f g : Filter α} {s t : Set α} (h : Disjoint s t) (hs : s ∈ f) (ht : t ∈ g) : Disjoint f g := Filter.disjoint_iff.mpr ⟨s, hs, t, ht, h⟩ theorem NeBot.not_disjoint (hf : f.NeBot) (hs : s ∈ f) (ht : t ∈ f) : ¬Disjoint s t := fun h => not_disjoint_self_iff.2 hf <| Filter.disjoint_iff.2 ⟨s, hs, t, ht, h⟩ theorem inf_eq_bot_iff {f g : Filter α} : f ⊓ g = ⊥ ↔ ∃ U ∈ f, ∃ V ∈ g, U ∩ V = ∅ := by simp only [← disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty] /-- There is exactly one filter on an empty type. -/ instance unique [IsEmpty α] : Unique (Filter α) where default := ⊥ uniq := filter_eq_bot_of_isEmpty theorem NeBot.nonempty (f : Filter α) [hf : f.NeBot] : Nonempty α := not_isEmpty_iff.mp fun _ ↦ hf.ne (Subsingleton.elim _ _) /-- There are only two filters on a `Subsingleton`: `⊥` and `⊤`. If the type is empty, then they are equal. -/ theorem eq_top_of_neBot [Subsingleton α] (l : Filter α) [NeBot l] : l = ⊤ := by refine top_unique fun s hs => ?_ obtain rfl : s = univ := Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs) exact univ_mem theorem forall_mem_nonempty_iff_neBot {f : Filter α} : (∀ s : Set α, s ∈ f → s.Nonempty) ↔ NeBot f := ⟨fun h => ⟨fun hf => not_nonempty_empty (h ∅ <| hf.symm ▸ mem_bot)⟩, @nonempty_of_mem _ _⟩ instance instNeBotTop [Nonempty α] : NeBot (⊤ : Filter α) := forall_mem_nonempty_iff_neBot.1 fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty] instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) := ⟨⟨⊤, ⊥, instNeBotTop.ne⟩⟩ theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α := ⟨fun _ => by_contra fun h' => haveI := not_nonempty_iff.1 h' not_subsingleton (Filter α) inferInstance, @Filter.instNontrivialFilter α⟩ theorem eq_sInf_of_mem_iff_exists_mem {S : Set (Filter α)} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ f ∈ S, s ∈ f) : l = sInf S := le_antisymm (le_sInf fun f hf _ hs => h.2 ⟨f, hf, hs⟩) fun _ hs => let ⟨_, hf, hs⟩ := h.1 hs; (sInf_le hf) hs theorem eq_iInf_of_mem_iff_exists_mem {f : ι → Filter α} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, s ∈ f i) : l = iInf f := eq_sInf_of_mem_iff_exists_mem <| h.trans (exists_range_iff (p := (_ ∈ ·))).symm theorem eq_biInf_of_mem_iff_exists_mem {f : ι → Filter α} {p : ι → Prop} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, p i ∧ s ∈ f i) : l = ⨅ (i) (_ : p i), f i := by rw [iInf_subtype'] exact eq_iInf_of_mem_iff_exists_mem fun {_} => by simp only [Subtype.exists, h, exists_prop] theorem iInf_sets_eq {f : ι → Filter α} (h : Directed (· ≥ ·) f) [ne : Nonempty ι] : (iInf f).sets = ⋃ i, (f i).sets := let ⟨i⟩ := ne let u := { sets := ⋃ i, (f i).sets univ_sets := mem_iUnion.2 ⟨i, univ_mem⟩ sets_of_superset := by simp only [mem_iUnion, exists_imp] exact fun i hx hxy => ⟨i, mem_of_superset hx hxy⟩ inter_sets := by simp only [mem_iUnion, exists_imp] intro x y a hx b hy rcases h a b with ⟨c, ha, hb⟩ exact ⟨c, inter_mem (ha hx) (hb hy)⟩ } have : u = iInf f := eq_iInf_of_mem_iff_exists_mem mem_iUnion congr_arg Filter.sets this.symm theorem mem_iInf_of_directed {f : ι → Filter α} (h : Directed (· ≥ ·) f) [Nonempty ι] (s) : s ∈ iInf f ↔ ∃ i, s ∈ f i := by simp only [← Filter.mem_sets, iInf_sets_eq h, mem_iUnion] theorem mem_biInf_of_directed {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) {t : Set α} : (t ∈ ⨅ i ∈ s, f i) ↔ ∃ i ∈ s, t ∈ f i := by haveI := ne.to_subtype simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop] theorem biInf_sets_eq {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) : (⨅ i ∈ s, f i).sets = ⋃ i ∈ s, (f i).sets := ext fun t => by simp [mem_biInf_of_directed h ne] @[simp] theorem sup_join {f₁ f₂ : Filter (Filter α)} : join f₁ ⊔ join f₂ = join (f₁ ⊔ f₂) := Filter.ext fun x => by simp only [mem_sup, mem_join] @[simp] theorem iSup_join {ι : Sort w} {f : ι → Filter (Filter α)} : ⨆ x, join (f x) = join (⨆ x, f x) := Filter.ext fun x => by simp only [mem_iSup, mem_join] instance : DistribLattice (Filter α) := { Filter.instCompleteLatticeFilter with le_sup_inf := by intro x y z s simp only [and_assoc, mem_inf_iff, mem_sup, exists_prop, exists_imp, and_imp] rintro hs t₁ ht₁ t₂ ht₂ rfl exact ⟨t₁, x.sets_of_superset hs inter_subset_left, ht₁, t₂, x.sets_of_superset hs inter_subset_right, ht₂, rfl⟩ } /-- If `f : ι → Filter α` is directed, `ι` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed` for a version assuming `Nonempty α` instead of `Nonempty ι`. -/ theorem iInf_neBot_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : (∀ i, NeBot (f i)) → NeBot (iInf f) := not_imp_not.1 <| by simpa only [not_forall, not_neBot, ← empty_mem_iff_bot, mem_iInf_of_directed hd] using id /-- If `f : ι → Filter α` is directed, `α` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed'` for a version assuming `Nonempty ι` instead of `Nonempty α`. -/ theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f) (hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by cases isEmpty_or_nonempty ι · constructor simp [iInf_of_empty f, top_ne_bot] · exact iInf_neBot_of_directed' hd hb theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ @iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩ theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩ /-! #### `principal` equations -/ @[simp] theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) := le_antisymm (by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩) (by simp [le_inf_iff, inter_subset_left, inter_subset_right]) @[simp] theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) := Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal] @[simp] theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) := Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff] @[simp] theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ := empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff @[simp] theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty := neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) := IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by rw [sup_principal, union_compl_self, principal_univ] theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal, ← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl] lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq] lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by ext simp only [mem_iSup, mem_inf_principal] theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by rw [← empty_mem_iff_bot, mem_inf_principal] simp only [mem_empty_iff_false, imp_false, compl_def] theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by rwa [inf_principal_eq_bot, compl_compl] at h theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) : s \ t ∈ f ⊓ 𝓟 tᶜ := inter_mem_inf hs <| mem_principal_self tᶜ theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by simp_rw [le_def, mem_principal] end Lattice @[mono, gcongr] theorem join_mono {f₁ f₂ : Filter (Filter α)} (h : f₁ ≤ f₂) : join f₁ ≤ join f₂ := fun _ hs => h hs /-! ### Eventually -/ theorem eventually_iff {f : Filter α} {P : α → Prop} : (∀ᶠ x in f, P x) ↔ { x | P x } ∈ f := Iff.rfl @[simp] theorem eventually_mem_set {s : Set α} {l : Filter α} : (∀ᶠ x in l, x ∈ s) ↔ s ∈ l := Iff.rfl protected theorem ext' {f₁ f₂ : Filter α} (h : ∀ p : α → Prop, (∀ᶠ x in f₁, p x) ↔ ∀ᶠ x in f₂, p x) : f₁ = f₂ := Filter.ext h theorem Eventually.filter_mono {f₁ f₂ : Filter α} (h : f₁ ≤ f₂) {p : α → Prop} (hp : ∀ᶠ x in f₂, p x) : ∀ᶠ x in f₁, p x := h hp theorem eventually_of_mem {f : Filter α} {P : α → Prop} {U : Set α} (hU : U ∈ f) (h : ∀ x ∈ U, P x) : ∀ᶠ x in f, P x := mem_of_superset hU h protected theorem Eventually.and {p q : α → Prop} {f : Filter α} : f.Eventually p → f.Eventually q → ∀ᶠ x in f, p x ∧ q x := inter_mem @[simp] theorem eventually_true (f : Filter α) : ∀ᶠ _ in f, True := univ_mem theorem Eventually.of_forall {p : α → Prop} {f : Filter α} (hp : ∀ x, p x) : ∀ᶠ x in f, p x := univ_mem' hp @[simp] theorem eventually_false_iff_eq_bot {f : Filter α} : (∀ᶠ _ in f, False) ↔ f = ⊥ := empty_mem_iff_bot @[simp] theorem eventually_const {f : Filter α} [t : NeBot f] {p : Prop} : (∀ᶠ _ in f, p) ↔ p := by by_cases h : p <;> simp [h, t.ne] theorem eventually_iff_exists_mem {p : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x) ↔ ∃ v ∈ f, ∀ y ∈ v, p y := exists_mem_subset_iff.symm theorem Eventually.exists_mem {p : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) : ∃ v ∈ f, ∀ y ∈ v, p y := eventually_iff_exists_mem.1 hp theorem Eventually.mp {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ᶠ x in f, p x → q x) : ∀ᶠ x in f, q x := mp_mem hp hq theorem Eventually.mono {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ x, p x → q x) : ∀ᶠ x in f, q x := hp.mp (Eventually.of_forall hq) theorem forall_eventually_of_eventually_forall {f : Filter α} {p : α → β → Prop} (h : ∀ᶠ x in f, ∀ y, p x y) : ∀ y, ∀ᶠ x in f, p x y := fun y => h.mono fun _ h => h y @[simp] theorem eventually_and {p q : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x ∧ q x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in f, q x := inter_mem_iff theorem Eventually.congr {f : Filter α} {p q : α → Prop} (h' : ∀ᶠ x in f, p x) (h : ∀ᶠ x in f, p x ↔ q x) : ∀ᶠ x in f, q x := h'.mp (h.mono fun _ hx => hx.mp) theorem eventually_congr {f : Filter α} {p q : α → Prop} (h : ∀ᶠ x in f, p x ↔ q x) : (∀ᶠ x in f, p x) ↔ ∀ᶠ x in f, q x := ⟨fun hp => hp.congr h, fun hq => hq.congr <| by simpa only [Iff.comm] using h⟩ @[simp] theorem eventually_or_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p ∨ q x) ↔ p ∨ ∀ᶠ x in f, q x := by_cases (fun h : p => by simp [h]) fun h => by simp [h] @[simp] theorem eventually_or_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x ∨ q) ↔ (∀ᶠ x in f, p x) ∨ q := by simp only [@or_comm _ q, eventually_or_distrib_left] theorem eventually_imp_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p → q x) ↔ p → ∀ᶠ x in f, q x := by simp only [imp_iff_not_or, eventually_or_distrib_left] @[simp] theorem eventually_bot {p : α → Prop} : ∀ᶠ x in ⊥, p x := ⟨⟩ @[simp] theorem eventually_top {p : α → Prop} : (∀ᶠ x in ⊤, p x) ↔ ∀ x, p x := Iff.rfl @[simp] theorem eventually_sup {p : α → Prop} {f g : Filter α} : (∀ᶠ x in f ⊔ g, p x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in g, p x := Iff.rfl @[simp] theorem eventually_sSup {p : α → Prop} {fs : Set (Filter α)} : (∀ᶠ x in sSup fs, p x) ↔ ∀ f ∈ fs, ∀ᶠ x in f, p x := Iff.rfl @[simp] theorem eventually_iSup {p : α → Prop} {fs : ι → Filter α} : (∀ᶠ x in ⨆ b, fs b, p x) ↔ ∀ b, ∀ᶠ x in fs b, p x := mem_iSup @[simp] theorem eventually_principal {a : Set α} {p : α → Prop} : (∀ᶠ x in 𝓟 a, p x) ↔ ∀ x ∈ a, p x := Iff.rfl theorem Eventually.forall_mem {α : Type*} {f : Filter α} {s : Set α} {P : α → Prop} (hP : ∀ᶠ x in f, P x) (hf : 𝓟 s ≤ f) : ∀ x ∈ s, P x := Filter.eventually_principal.mp (hP.filter_mono hf) theorem eventually_inf {f g : Filter α} {p : α → Prop} : (∀ᶠ x in f ⊓ g, p x) ↔ ∃ s ∈ f, ∃ t ∈ g, ∀ x ∈ s ∩ t, p x := mem_inf_iff_superset theorem eventually_inf_principal {f : Filter α} {p : α → Prop} {s : Set α} : (∀ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∀ᶠ x in f, x ∈ s → p x := mem_inf_principal theorem eventually_iff_all_subsets {f : Filter α} {p : α → Prop} : (∀ᶠ x in f, p x) ↔ ∀ (s : Set α), ∀ᶠ x in f, x ∈ s → p x where mp h _ := by filter_upwards [h] with _ pa _ using pa mpr h := by filter_upwards [h univ] with _ pa using pa (by simp) /-! ### Frequently -/ theorem Eventually.frequently {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ᶠ x in f, p x) : ∃ᶠ x in f, p x := compl_not_mem h theorem Frequently.of_forall {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ x, p x) : ∃ᶠ x in f, p x := Eventually.frequently (Eventually.of_forall h) theorem Frequently.mp {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ᶠ x in f, p x → q x) : ∃ᶠ x in f, q x := mt (fun hq => hq.mp <| hpq.mono fun _ => mt) h lemma frequently_congr {p q : α → Prop} {f : Filter α} (h : ∀ᶠ x in f, p x ↔ q x) : (∃ᶠ x in f, p x) ↔ ∃ᶠ x in f, q x := ⟨fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mp), fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mpr)⟩ theorem Frequently.filter_mono {p : α → Prop} {f g : Filter α} (h : ∃ᶠ x in f, p x) (hle : f ≤ g) : ∃ᶠ x in g, p x := mt (fun h' => h'.filter_mono hle) h theorem Frequently.mono {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ x, p x → q x) : ∃ᶠ x in f, q x := h.mp (Eventually.of_forall hpq) theorem Frequently.and_eventually {p q : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) (hq : ∀ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by refine mt (fun h => hq.mp <| h.mono ?_) hp exact fun x hpq hq hp => hpq ⟨hp, hq⟩ theorem Eventually.and_frequently {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∃ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by simpa only [and_comm] using hq.and_eventually hp theorem Frequently.exists {p : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) : ∃ x, p x := by by_contra H replace H : ∀ᶠ x in f, ¬p x := Eventually.of_forall (not_exists.1 H) exact hp H theorem Eventually.exists {p : α → Prop} {f : Filter α} [NeBot f] (hp : ∀ᶠ x in f, p x) : ∃ x, p x := hp.frequently.exists lemma frequently_iff_neBot {l : Filter α} {p : α → Prop} : (∃ᶠ x in l, p x) ↔ NeBot (l ⊓ 𝓟 {x | p x}) := by rw [neBot_iff, Ne, inf_principal_eq_bot]; rfl lemma frequently_mem_iff_neBot {l : Filter α} {s : Set α} : (∃ᶠ x in l, x ∈ s) ↔ NeBot (l ⊓ 𝓟 s) := frequently_iff_neBot theorem frequently_iff_forall_eventually_exists_and {p : α → Prop} {f : Filter α} : (∃ᶠ x in f, p x) ↔ ∀ {q : α → Prop}, (∀ᶠ x in f, q x) → ∃ x, p x ∧ q x := ⟨fun hp _ hq => (hp.and_eventually hq).exists, fun H hp => by simpa only [and_not_self_iff, exists_false] using H hp⟩ theorem frequently_iff {f : Filter α} {P : α → Prop} : (∃ᶠ x in f, P x) ↔ ∀ {U}, U ∈ f → ∃ x ∈ U, P x := by simp only [frequently_iff_forall_eventually_exists_and, @and_comm (P _)] rfl @[simp] theorem not_eventually {p : α → Prop} {f : Filter α} : (¬∀ᶠ x in f, p x) ↔ ∃ᶠ x in f, ¬p x := by simp [Filter.Frequently] @[simp] theorem not_frequently {p : α → Prop} {f : Filter α} : (¬∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, ¬p x := by simp only [Filter.Frequently, not_not] @[simp] theorem frequently_true_iff_neBot (f : Filter α) : (∃ᶠ _ in f, True) ↔ NeBot f := by simp [frequently_iff_neBot] @[simp] theorem frequently_false (f : Filter α) : ¬∃ᶠ _ in f, False := by simp @[simp] theorem frequently_const {f : Filter α} [NeBot f] {p : Prop} : (∃ᶠ _ in f, p) ↔ p := by by_cases p <;> simp [*] @[simp] theorem frequently_or_distrib {f : Filter α} {p q : α → Prop} : (∃ᶠ x in f, p x ∨ q x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in f, q x := by simp only [Filter.Frequently, ← not_and_or, not_or, eventually_and] theorem frequently_or_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p ∨ q x) ↔ p ∨ ∃ᶠ x in f, q x := by simp theorem frequently_or_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x ∨ q) ↔ (∃ᶠ x in f, p x) ∨ q := by simp theorem frequently_imp_distrib {f : Filter α} {p q : α → Prop} : (∃ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∃ᶠ x in f, q x := by simp [imp_iff_not_or] theorem frequently_imp_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p → q x) ↔ p → ∃ᶠ x in f, q x := by simp [frequently_imp_distrib] theorem frequently_imp_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x → q) ↔ (∀ᶠ x in f, p x) → q := by simp only [frequently_imp_distrib, frequently_const] theorem eventually_imp_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x → q) ↔ (∃ᶠ x in f, p x) → q := by simp only [imp_iff_not_or, eventually_or_distrib_right, not_frequently] @[simp] theorem frequently_and_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p ∧ q x) ↔ p ∧ ∃ᶠ x in f, q x := by simp only [Filter.Frequently, not_and, eventually_imp_distrib_left, Classical.not_imp] @[simp] theorem frequently_and_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x ∧ q) ↔ (∃ᶠ x in f, p x) ∧ q := by simp only [@and_comm _ q, frequently_and_distrib_left] @[simp] theorem frequently_bot {p : α → Prop} : ¬∃ᶠ x in ⊥, p x := by simp @[simp] theorem frequently_top {p : α → Prop} : (∃ᶠ x in ⊤, p x) ↔ ∃ x, p x := by simp [Filter.Frequently] @[simp] theorem frequently_principal {a : Set α} {p : α → Prop} : (∃ᶠ x in 𝓟 a, p x) ↔ ∃ x ∈ a, p x := by simp [Filter.Frequently, not_forall] theorem frequently_inf_principal {f : Filter α} {s : Set α} {p : α → Prop} : (∃ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∃ᶠ x in f, x ∈ s ∧ p x := by simp only [Filter.Frequently, eventually_inf_principal, not_and] alias ⟨Frequently.of_inf_principal, Frequently.inf_principal⟩ := frequently_inf_principal theorem frequently_sup {p : α → Prop} {f g : Filter α} : (∃ᶠ x in f ⊔ g, p x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in g, p x := by simp only [Filter.Frequently, eventually_sup, not_and_or] @[simp] theorem frequently_sSup {p : α → Prop} {fs : Set (Filter α)} : (∃ᶠ x in sSup fs, p x) ↔ ∃ f ∈ fs, ∃ᶠ x in f, p x := by simp only [Filter.Frequently, not_forall, eventually_sSup, exists_prop] @[simp] theorem frequently_iSup {p : α → Prop} {fs : β → Filter α} : (∃ᶠ x in ⨆ b, fs b, p x) ↔ ∃ b, ∃ᶠ x in fs b, p x := by simp only [Filter.Frequently, eventually_iSup, not_forall] theorem Eventually.choice {r : α → β → Prop} {l : Filter α} [l.NeBot] (h : ∀ᶠ x in l, ∃ y, r x y) : ∃ f : α → β, ∀ᶠ x in l, r x (f x) := by haveI : Nonempty β := let ⟨_, hx⟩ := h.exists; hx.nonempty choose! f hf using fun x (hx : ∃ y, r x y) => hx exact ⟨f, h.mono hf⟩ lemma skolem {ι : Type*} {α : ι → Type*} [∀ i, Nonempty (α i)] {P : ∀ i : ι, α i → Prop} {F : Filter ι} : (∀ᶠ i in F, ∃ b, P i b) ↔ ∃ b : (Π i, α i), ∀ᶠ i in F, P i (b i) := by classical refine ⟨fun H ↦ ?_, fun ⟨b, hb⟩ ↦ hb.mp (.of_forall fun x a ↦ ⟨_, a⟩)⟩ refine ⟨fun i ↦ if h : ∃ b, P i b then h.choose else Nonempty.some inferInstance, ?_⟩ filter_upwards [H] with i hi exact dif_pos hi ▸ hi.choose_spec /-! ### Relation “eventually equal” -/ section EventuallyEq variable {l : Filter α} {f g : α → β} theorem EventuallyEq.eventually (h : f =ᶠ[l] g) : ∀ᶠ x in l, f x = g x := h @[simp] lemma eventuallyEq_top : f =ᶠ[⊤] g ↔ f = g := by simp [EventuallyEq, funext_iff] theorem EventuallyEq.rw {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (p : α → β → Prop) (hf : ∀ᶠ x in l, p x (f x)) : ∀ᶠ x in l, p x (g x) := hf.congr <| h.mono fun _ hx => hx ▸ Iff.rfl theorem eventuallyEq_set {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ s ↔ x ∈ t := eventually_congr <| Eventually.of_forall fun _ ↦ eq_iff_iff alias ⟨EventuallyEq.mem_iff, Eventually.set_eq⟩ := eventuallyEq_set @[simp] theorem eventuallyEq_univ {s : Set α} {l : Filter α} : s =ᶠ[l] univ ↔ s ∈ l := by simp [eventuallyEq_set] theorem EventuallyEq.exists_mem {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) : ∃ s ∈ l, EqOn f g s := Eventually.exists_mem h theorem eventuallyEq_of_mem {l : Filter α} {f g : α → β} {s : Set α} (hs : s ∈ l) (h : EqOn f g s) : f =ᶠ[l] g := eventually_of_mem hs h theorem eventuallyEq_iff_exists_mem {l : Filter α} {f g : α → β} : f =ᶠ[l] g ↔ ∃ s ∈ l, EqOn f g s := eventually_iff_exists_mem theorem EventuallyEq.filter_mono {l l' : Filter α} {f g : α → β} (h₁ : f =ᶠ[l] g) (h₂ : l' ≤ l) : f =ᶠ[l'] g := h₂ h₁ @[refl, simp] theorem EventuallyEq.refl (l : Filter α) (f : α → β) : f =ᶠ[l] f := Eventually.of_forall fun _ => rfl protected theorem EventuallyEq.rfl {l : Filter α} {f : α → β} : f =ᶠ[l] f := EventuallyEq.refl l f theorem EventuallyEq.of_eq {l : Filter α} {f g : α → β} (h : f = g) : f =ᶠ[l] g := h ▸ .rfl alias _root_.Eq.eventuallyEq := EventuallyEq.of_eq @[symm] theorem EventuallyEq.symm {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) : g =ᶠ[l] f := H.mono fun _ => Eq.symm lemma eventuallyEq_comm {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ g =ᶠ[l] f := ⟨.symm, .symm⟩ @[trans] theorem EventuallyEq.trans {l : Filter α} {f g h : α → β} (H₁ : f =ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f =ᶠ[l] h := H₂.rw (fun x y => f x = y) H₁ theorem EventuallyEq.congr_left {l : Filter α} {f g h : α → β} (H : f =ᶠ[l] g) : f =ᶠ[l] h ↔ g =ᶠ[l] h := ⟨H.symm.trans, H.trans⟩ theorem EventuallyEq.congr_right {l : Filter α} {f g h : α → β} (H : g =ᶠ[l] h) : f =ᶠ[l] g ↔ f =ᶠ[l] h := ⟨(·.trans H), (·.trans H.symm)⟩ instance {l : Filter α} : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· =ᶠ[l] ·) where trans := EventuallyEq.trans theorem EventuallyEq.prodMk {l} {f f' : α → β} (hf : f =ᶠ[l] f') {g g' : α → γ} (hg : g =ᶠ[l] g') : (fun x => (f x, g x)) =ᶠ[l] fun x => (f' x, g' x) := hf.mp <| hg.mono <| by intros simp only [*] @[deprecated (since := "2025-03-10")] alias EventuallyEq.prod_mk := EventuallyEq.prodMk -- See `EventuallyEq.comp_tendsto` further below for a similar statement w.r.t. -- composition on the right. theorem EventuallyEq.fun_comp {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) (h : β → γ) : h ∘ f =ᶠ[l] h ∘ g := H.mono fun _ hx => congr_arg h hx theorem EventuallyEq.comp₂ {δ} {f f' : α → β} {g g' : α → γ} {l} (Hf : f =ᶠ[l] f') (h : β → γ → δ) (Hg : g =ᶠ[l] g') : (fun x => h (f x) (g x)) =ᶠ[l] fun x => h (f' x) (g' x) := (Hf.prodMk Hg).fun_comp (uncurry h) @[to_additive] theorem EventuallyEq.mul [Mul β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : (fun x => f x * f' x) =ᶠ[l] fun x => g x * g' x := h.comp₂ (· * ·) h' @[to_additive const_smul] theorem EventuallyEq.pow_const {γ} [Pow β γ] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) (c : γ) : (fun x => f x ^ c) =ᶠ[l] fun x => g x ^ c := h.fun_comp (· ^ c) @[to_additive] theorem EventuallyEq.inv [Inv β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) : (fun x => (f x)⁻¹) =ᶠ[l] fun x => (g x)⁻¹ := h.fun_comp Inv.inv @[to_additive] theorem EventuallyEq.div [Div β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : (fun x => f x / f' x) =ᶠ[l] fun x => g x / g' x := h.comp₂ (· / ·) h' attribute [to_additive] EventuallyEq.const_smul @[to_additive] theorem EventuallyEq.smul {𝕜} [SMul 𝕜 β] {l : Filter α} {f f' : α → 𝕜} {g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x • g x) =ᶠ[l] fun x => f' x • g' x := hf.comp₂ (· • ·) hg theorem EventuallyEq.sup [Max β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x ⊔ g x) =ᶠ[l] fun x => f' x ⊔ g' x := hf.comp₂ (· ⊔ ·) hg theorem EventuallyEq.inf [Min β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x ⊓ g x) =ᶠ[l] fun x => f' x ⊓ g' x := hf.comp₂ (· ⊓ ·) hg theorem EventuallyEq.preimage {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (s : Set β) : f ⁻¹' s =ᶠ[l] g ⁻¹' s := h.fun_comp s theorem EventuallyEq.inter {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∩ s' : Set α) =ᶠ[l] (t ∩ t' : Set α) := h.comp₂ (· ∧ ·) h' theorem EventuallyEq.union {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∪ s' : Set α) =ᶠ[l] (t ∪ t' : Set α) := h.comp₂ (· ∨ ·) h' theorem EventuallyEq.compl {s t : Set α} {l : Filter α} (h : s =ᶠ[l] t) : (sᶜ : Set α) =ᶠ[l] (tᶜ : Set α) := h.fun_comp Not theorem EventuallyEq.diff {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s \ s' : Set α) =ᶠ[l] (t \ t' : Set α) := h.inter h'.compl protected theorem EventuallyEq.symmDiff {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∆ s' : Set α) =ᶠ[l] (t ∆ t' : Set α) := (h.diff h').union (h'.diff h) theorem eventuallyEq_empty {s : Set α} {l : Filter α} : s =ᶠ[l] (∅ : Set α) ↔ ∀ᶠ x in l, x ∉ s := eventuallyEq_set.trans <| by simp theorem inter_eventuallyEq_left {s t : Set α} {l : Filter α} : (s ∩ t : Set α) =ᶠ[l] s ↔ ∀ᶠ x in l, x ∈ s → x ∈ t := by simp only [eventuallyEq_set, mem_inter_iff, and_iff_left_iff_imp] theorem inter_eventuallyEq_right {s t : Set α} {l : Filter α} : (s ∩ t : Set α) =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ t → x ∈ s := by rw [inter_comm, inter_eventuallyEq_left] @[simp] theorem eventuallyEq_principal {s : Set α} {f g : α → β} : f =ᶠ[𝓟 s] g ↔ EqOn f g s := Iff.rfl theorem eventuallyEq_inf_principal_iff {F : Filter α} {s : Set α} {f g : α → β} : f =ᶠ[F ⊓ 𝓟 s] g ↔ ∀ᶠ x in F, x ∈ s → f x = g x := eventually_inf_principal theorem EventuallyEq.sub_eq [AddGroup β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) : f - g =ᶠ[l] 0 := by simpa using ((EventuallyEq.refl l f).sub h).symm theorem eventuallyEq_iff_sub [AddGroup β] {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ f - g =ᶠ[l] 0 := ⟨fun h => h.sub_eq, fun h => by simpa using h.add (EventuallyEq.refl l g)⟩ theorem eventuallyEq_iff_all_subsets {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ ∀ s : Set α, ∀ᶠ x in l, x ∈ s → f x = g x := eventually_iff_all_subsets section LE variable [LE β] {l : Filter α} theorem EventuallyLE.congr {f f' g g' : α → β} (H : f ≤ᶠ[l] g) (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : f' ≤ᶠ[l] g' := H.mp <| hg.mp <| hf.mono fun x hf hg H => by rwa [hf, hg] at H theorem eventuallyLE_congr {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : f ≤ᶠ[l] g ↔ f' ≤ᶠ[l] g' := ⟨fun H => H.congr hf hg, fun H => H.congr hf.symm hg.symm⟩ theorem eventuallyLE_iff_all_subsets {f g : α → β} {l : Filter α} : f ≤ᶠ[l] g ↔ ∀ s : Set α, ∀ᶠ x in l, x ∈ s → f x ≤ g x := eventually_iff_all_subsets end LE section Preorder variable [Preorder β] {l : Filter α} {f g h : α → β} theorem EventuallyEq.le (h : f =ᶠ[l] g) : f ≤ᶠ[l] g := h.mono fun _ => le_of_eq @[refl] theorem EventuallyLE.refl (l : Filter α) (f : α → β) : f ≤ᶠ[l] f := EventuallyEq.rfl.le theorem EventuallyLE.rfl : f ≤ᶠ[l] f := EventuallyLE.refl l f @[trans] theorem EventuallyLE.trans (H₁ : f ≤ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h := H₂.mp <| H₁.mono fun _ => le_trans instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyLE.trans @[trans] theorem EventuallyEq.trans_le (H₁ : f =ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h := H₁.le.trans H₂ instance : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyEq.trans_le @[trans] theorem EventuallyLE.trans_eq (H₁ : f ≤ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f ≤ᶠ[l] h := H₁.trans H₂.le instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyLE.trans_eq end Preorder variable {l : Filter α} theorem EventuallyLE.antisymm [PartialOrder β] {l : Filter α} {f g : α → β} (h₁ : f ≤ᶠ[l] g) (h₂ : g ≤ᶠ[l] f) : f =ᶠ[l] g := h₂.mp <| h₁.mono fun _ => le_antisymm theorem eventuallyLE_antisymm_iff [PartialOrder β] {l : Filter α} {f g : α → β} : f =ᶠ[l] g ↔ f ≤ᶠ[l] g ∧ g ≤ᶠ[l] f := by simp only [EventuallyEq, EventuallyLE, le_antisymm_iff, eventually_and] theorem EventuallyLE.le_iff_eq [PartialOrder β] {l : Filter α} {f g : α → β} (h : f ≤ᶠ[l] g) : g ≤ᶠ[l] f ↔ g =ᶠ[l] f := ⟨fun h' => h'.antisymm h, EventuallyEq.le⟩ theorem Eventually.ne_of_lt [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ᶠ x in l, f x < g x) : ∀ᶠ x in l, f x ≠ g x := h.mono fun _ hx => hx.ne theorem Eventually.ne_top_of_lt [Preorder β] [OrderTop β] {l : Filter α} {f g : α → β} (h : ∀ᶠ x in l, f x < g x) : ∀ᶠ x in l, f x ≠ ⊤ := h.mono fun _ hx => hx.ne_top theorem Eventually.lt_top_of_ne [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β} (h : ∀ᶠ x in l, f x ≠ ⊤) : ∀ᶠ x in l, f x < ⊤ := h.mono fun _ hx => hx.lt_top theorem Eventually.lt_top_iff_ne_top [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β} : (∀ᶠ x in l, f x < ⊤) ↔ ∀ᶠ x in l, f x ≠ ⊤ := ⟨Eventually.ne_of_lt, Eventually.lt_top_of_ne⟩ @[mono] theorem EventuallyLE.inter {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') : (s ∩ s' : Set α) ≤ᶠ[l] (t ∩ t' : Set α) := h'.mp <| h.mono fun _ => And.imp @[mono] theorem EventuallyLE.union {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') : (s ∪ s' : Set α) ≤ᶠ[l] (t ∪ t' : Set α) := h'.mp <| h.mono fun _ => Or.imp @[mono] theorem EventuallyLE.compl {s t : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) : (tᶜ : Set α) ≤ᶠ[l] (sᶜ : Set α) := h.mono fun _ => mt @[mono] theorem EventuallyLE.diff {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : t' ≤ᶠ[l] s') : (s \ s' : Set α) ≤ᶠ[l] (t \ t' : Set α) := h.inter h'.compl theorem set_eventuallyLE_iff_mem_inf_principal {s t : Set α} {l : Filter α} : s ≤ᶠ[l] t ↔ t ∈ l ⊓ 𝓟 s := eventually_inf_principal.symm theorem set_eventuallyLE_iff_inf_principal_le {s t : Set α} {l : Filter α} : s ≤ᶠ[l] t ↔ l ⊓ 𝓟 s ≤ l ⊓ 𝓟 t := set_eventuallyLE_iff_mem_inf_principal.trans <| by simp only [le_inf_iff, inf_le_left, true_and, le_principal_iff] theorem set_eventuallyEq_iff_inf_principal {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ l ⊓ 𝓟 s = l ⊓ 𝓟 t := by simp only [eventuallyLE_antisymm_iff, le_antisymm_iff, set_eventuallyLE_iff_inf_principal_le] theorem EventuallyLE.sup [SemilatticeSup β] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) : f₁ ⊔ g₁ ≤ᶠ[l] f₂ ⊔ g₂ := by filter_upwards [hf, hg] with x hfx hgx using sup_le_sup hfx hgx theorem EventuallyLE.sup_le [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hf : f ≤ᶠ[l] h) (hg : g ≤ᶠ[l] h) : f ⊔ g ≤ᶠ[l] h := by filter_upwards [hf, hg] with x hfx hgx using _root_.sup_le hfx hgx theorem EventuallyLE.le_sup_of_le_left [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hf : h ≤ᶠ[l] f) : h ≤ᶠ[l] f ⊔ g := hf.mono fun _ => _root_.le_sup_of_le_left theorem EventuallyLE.le_sup_of_le_right [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hg : h ≤ᶠ[l] g) : h ≤ᶠ[l] f ⊔ g := hg.mono fun _ => _root_.le_sup_of_le_right theorem join_le {f : Filter (Filter α)} {l : Filter α} (h : ∀ᶠ m in f, m ≤ l) : join f ≤ l := fun _ hs => h.mono fun _ hm => hm hs end EventuallyEq end Filter open Filter theorem Set.EqOn.eventuallyEq {α β} {s : Set α} {f g : α → β} (h : EqOn f g s) : f =ᶠ[𝓟 s] g := h theorem Set.EqOn.eventuallyEq_of_mem {α β} {s : Set α} {l : Filter α} {f g : α → β} (h : EqOn f g s) (hl : s ∈ l) : f =ᶠ[l] g := h.eventuallyEq.filter_mono <| Filter.le_principal_iff.2 hl theorem HasSubset.Subset.eventuallyLE {α} {l : Filter α} {s t : Set α} (h : s ⊆ t) : s ≤ᶠ[l] t := Filter.Eventually.of_forall h variable {α β : Type*} {F : Filter α} {G : Filter β} namespace Filter lemma compl_mem_comk {p : Set α → Prop} {he hmono hunion s} : sᶜ ∈ comk p he hmono hunion ↔ p s := by simp end Filter
Mathlib/Order/Filter/Basic.lean
3,237
3,239
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Algebra.Ring.Regular import Mathlib.Algebra.Equiv.TransferInstance import Mathlib.Algebra.BigOperators.Pi import Mathlib.Algebra.BigOperators.Ring.Finset /-! # Characters from additive to multiplicative monoids Let `A` be an additive monoid, and `M` a multiplicative one. An *additive character* of `A` with values in `M` is simply a map `A → M` which intertwines the addition operation on `A` with the multiplicative operation on `M`. We define these objects, using the namespace `AddChar`, and show that if `A` is a commutative group under addition, then the additive characters are also a group (written multiplicatively). Note that we do not need `M` to be a group here. We also include some constructions specific to the case when `A = R` is a ring; then we define `mulShift ψ r`, where `ψ : AddChar R M` and `r : R`, to be the character defined by `x ↦ ψ (r * x)`. For more refined results of a number-theoretic nature (primitive characters, Gauss sums, etc) see `Mathlib.NumberTheory.LegendreSymbol.AddCharacter`. # Implementation notes Due to their role as the dual of an additive group, additive characters must themselves be an additive group. This contrasts to their pointwise operations which make them a multiplicative group. We simply define both the additive and multiplicative group structures and prove them equal. For more information on this design decision, see the following zulip thread: https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Additive.20characters ## Tags additive character -/ /-! ### Definitions related to and results on additive characters -/ open Function Multiplicative open Finset hiding card open Fintype (card) section AddCharDef -- The domain of our additive characters variable (A : Type*) [AddMonoid A] -- The target variable (M : Type*) [Monoid M] /-- `AddChar A M` is the type of maps `A → M`, for `A` an additive monoid and `M` a multiplicative monoid, which intertwine addition in `A` with multiplication in `M`. We only put the typeclasses needed for the definition, although in practice we are usually interested in much more specific cases (e.g. when `A` is a group and `M` a commutative ring). -/ structure AddChar where /-- The underlying function. Do not use this function directly. Instead use the coercion coming from the `FunLike` instance. -/ toFun : A → M /-- The function maps `0` to `1`. Do not use this directly. Instead use `AddChar.map_zero_eq_one`. -/ map_zero_eq_one' : toFun 0 = 1 /-- The function maps addition in `A` to multiplication in `M`. Do not use this directly. Instead use `AddChar.map_add_eq_mul`. -/ map_add_eq_mul' : ∀ a b : A, toFun (a + b) = toFun a * toFun b end AddCharDef namespace AddChar section Basic -- results which don't require commutativity or inverses variable {A B M N : Type*} [AddMonoid A] [AddMonoid B] [Monoid M] [Monoid N] {ψ : AddChar A M} /-- Define coercion to a function. -/ instance instFunLike : FunLike (AddChar A M) A M where coe := AddChar.toFun coe_injective' φ ψ h := by cases φ; cases ψ; congr @[ext] lemma ext (f g : AddChar A M) (h : ∀ x : A, f x = g x) : f = g := DFunLike.ext f g h @[simp] lemma coe_mk (f : A → M) (map_zero_eq_one' : f 0 = 1) (map_add_eq_mul' : ∀ a b : A, f (a + b) = f a * f b) : AddChar.mk f map_zero_eq_one' map_add_eq_mul' = f := by rfl /-- An additive character maps `0` to `1`. -/ @[simp] lemma map_zero_eq_one (ψ : AddChar A M) : ψ 0 = 1 := ψ.map_zero_eq_one' /-- An additive character maps sums to products. -/ lemma map_add_eq_mul (ψ : AddChar A M) (x y : A) : ψ (x + y) = ψ x * ψ y := ψ.map_add_eq_mul' x y /-- Interpret an additive character as a monoid homomorphism. -/ def toMonoidHom (φ : AddChar A M) : Multiplicative A →* M where toFun := φ.toFun map_one' := φ.map_zero_eq_one' map_mul' := φ.map_add_eq_mul' -- this instance was a bad idea and conflicted with `instFunLike` above @[simp] lemma toMonoidHom_apply (ψ : AddChar A M) (a : Multiplicative A) : ψ.toMonoidHom a = ψ a.toAdd := rfl /-- An additive character maps multiples by natural numbers to powers. -/ lemma map_nsmul_eq_pow (ψ : AddChar A M) (n : ℕ) (x : A) : ψ (n • x) = ψ x ^ n := ψ.toMonoidHom.map_pow x n /-- Additive characters `A → M` are the same thing as monoid homomorphisms from `Multiplicative A` to `M`. -/ def toMonoidHomEquiv : AddChar A M ≃ (Multiplicative A →* M) where toFun φ := φ.toMonoidHom invFun f := { toFun := f.toFun map_zero_eq_one' := f.map_one' map_add_eq_mul' := f.map_mul' } left_inv _ := rfl right_inv _ := rfl @[simp, norm_cast] lemma coe_toMonoidHomEquiv (ψ : AddChar A M) : ⇑(toMonoidHomEquiv ψ) = ψ ∘ Multiplicative.toAdd := rfl @[simp, norm_cast] lemma coe_toMonoidHomEquiv_symm (ψ : Multiplicative A →* M) : ⇑(toMonoidHomEquiv.symm ψ) = ψ ∘ Multiplicative.ofAdd := rfl @[simp] lemma toMonoidHomEquiv_apply (ψ : AddChar A M) (a : Multiplicative A) : toMonoidHomEquiv ψ a = ψ a.toAdd := rfl @[simp] lemma toMonoidHomEquiv_symm_apply (ψ : Multiplicative A →* M) (a : A) : toMonoidHomEquiv.symm ψ a = ψ (Multiplicative.ofAdd a) := rfl /-- Interpret an additive character as a monoid homomorphism. -/ def toAddMonoidHom (φ : AddChar A M) : A →+ Additive M where toFun := φ.toFun map_zero' := φ.map_zero_eq_one' map_add' := φ.map_add_eq_mul' @[simp] lemma coe_toAddMonoidHom (ψ : AddChar A M) : ⇑ψ.toAddMonoidHom = Additive.ofMul ∘ ψ := rfl @[simp] lemma toAddMonoidHom_apply (ψ : AddChar A M) (a : A) : ψ.toAddMonoidHom a = Additive.ofMul (ψ a) := rfl /-- Additive characters `A → M` are the same thing as additive homomorphisms from `A` to `Additive M`. -/ def toAddMonoidHomEquiv : AddChar A M ≃ (A →+ Additive M) where toFun φ := φ.toAddMonoidHom invFun f := { toFun := f.toFun map_zero_eq_one' := f.map_zero' map_add_eq_mul' := f.map_add' } left_inv _ := rfl right_inv _ := rfl @[simp, norm_cast] lemma coe_toAddMonoidHomEquiv (ψ : AddChar A M) : ⇑(toAddMonoidHomEquiv ψ) = Additive.ofMul ∘ ψ := rfl @[simp, norm_cast] lemma coe_toAddMonoidHomEquiv_symm (ψ : A →+ Additive M) : ⇑(toAddMonoidHomEquiv.symm ψ) = Additive.toMul ∘ ψ := rfl @[simp] lemma toAddMonoidHomEquiv_apply (ψ : AddChar A M) (a : A) : toAddMonoidHomEquiv ψ a = Additive.ofMul (ψ a) := rfl @[simp] lemma toAddMonoidHomEquiv_symm_apply (ψ : A →+ Additive M) (a : A) : toAddMonoidHomEquiv.symm ψ a = (ψ a).toMul := rfl /-- The trivial additive character (sending everything to `1`). -/ instance instOne : One (AddChar A M) := toMonoidHomEquiv.one /-- The trivial additive character (sending everything to `1`). -/ instance instZero : Zero (AddChar A M) := ⟨1⟩ @[simp, norm_cast] lemma coe_one : ⇑(1 : AddChar A M) = 1 := rfl @[simp, norm_cast] lemma coe_zero : ⇑(0 : AddChar A M) = 1 := rfl @[simp] lemma one_apply (a : A) : (1 : AddChar A M) a = 1 := rfl @[simp] lemma zero_apply (a : A) : (0 : AddChar A M) a = 1 := rfl lemma one_eq_zero : (1 : AddChar A M) = (0 : AddChar A M) := rfl @[simp, norm_cast] lemma coe_eq_one : ⇑ψ = 1 ↔ ψ = 0 := by rw [← coe_zero, DFunLike.coe_fn_eq] @[simp] lemma toMonoidHomEquiv_zero : toMonoidHomEquiv (0 : AddChar A M) = 1 := rfl @[simp] lemma toMonoidHomEquiv_symm_one : toMonoidHomEquiv.symm (1 : Multiplicative A →* M) = 0 := rfl @[simp] lemma toAddMonoidHomEquiv_zero : toAddMonoidHomEquiv (0 : AddChar A M) = 0 := rfl @[simp] lemma toAddMonoidHomEquiv_symm_zero : toAddMonoidHomEquiv.symm (0 : A →+ Additive M) = 0 := rfl instance instInhabited : Inhabited (AddChar A M) := ⟨1⟩ /-- Composing a `MonoidHom` with an `AddChar` yields another `AddChar`. -/ def _root_.MonoidHom.compAddChar {N : Type*} [Monoid N] (f : M →* N) (φ : AddChar A M) : AddChar A N := toMonoidHomEquiv.symm (f.comp φ.toMonoidHom) @[simp, norm_cast] lemma _root_.MonoidHom.coe_compAddChar {N : Type*} [Monoid N] (f : M →* N) (φ : AddChar A M) : f.compAddChar φ = f ∘ φ := rfl @[simp, norm_cast] lemma _root_.MonoidHom.compAddChar_apply (f : M →* N) (φ : AddChar A M) : f.compAddChar φ = f ∘ φ := rfl lemma _root_.MonoidHom.compAddChar_injective_left (ψ : AddChar A M) (hψ : Surjective ψ) : Injective fun f : M →* N ↦ f.compAddChar ψ := by rintro f g h; rw [DFunLike.ext'_iff] at h ⊢; exact hψ.injective_comp_right h lemma _root_.MonoidHom.compAddChar_injective_right (f : M →* N) (hf : Injective f) : Injective fun ψ : AddChar B M ↦ f.compAddChar ψ := by rintro ψ χ h; rw [DFunLike.ext'_iff] at h ⊢; exact hf.comp_left h /-- Composing an `AddChar` with an `AddMonoidHom` yields another `AddChar`. -/
def compAddMonoidHom (φ : AddChar B M) (f : A →+ B) : AddChar A M := toAddMonoidHomEquiv.symm (φ.toAddMonoidHom.comp f) @[simp, norm_cast]
Mathlib/Algebra/Group/AddChar.lean
229
232
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import Mathlib.Algebra.Field.NegOnePow import Mathlib.Algebra.Field.Periodic import Mathlib.Algebra.QuadraticDiscriminant import Mathlib.Analysis.SpecialFunctions.Exp /-! # Trigonometric functions ## Main definitions This file contains the definition of `π`. See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions. See also `Analysis.SpecialFunctions.Complex.Arg` and `Analysis.SpecialFunctions.Complex.Log` for the complex argument function and the complex logarithm. ## Main statements Many basic inequalities on the real trigonometric functions are established. The continuity of the usual trigonometric functions is proved. Several facts about the real trigonometric functions have the proofs deferred to `Analysis.SpecialFunctions.Trigonometric.Complex`, as they are most easily proved by appealing to the corresponding fact for complex trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas in terms of Chebyshev polynomials. ## Tags sin, cos, tan, angle -/ noncomputable section open Topology Filter Set namespace Complex @[continuity, fun_prop] theorem continuous_sin : Continuous sin := by change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2 fun_prop @[fun_prop] theorem continuousOn_sin {s : Set ℂ} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := by change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2 fun_prop @[fun_prop] theorem continuousOn_cos {s : Set ℂ} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := by change Continuous fun z => (exp z - exp (-z)) / 2 fun_prop @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := by change Continuous fun z => (exp z + exp (-z)) / 2 fun_prop end Complex namespace Real variable {x y z : ℝ} @[continuity, fun_prop] theorem continuous_sin : Continuous sin := Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_sin {s} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_cos {s} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal) @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal) end Real namespace Real theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 := intermediate_value_Icc' (by norm_num) continuousOn_cos ⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩ /-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from which one can derive all its properties. For explicit bounds on π, see `Data.Real.Pi.Bounds`. Denoted `π`, once the `Real` namespace is opened. -/ protected noncomputable def pi : ℝ := 2 * Classical.choose exists_cos_eq_zero @[inherit_doc] scoped notation "π" => Real.pi @[simp] theorem cos_pi_div_two : cos (π / 2) = 0 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).2 theorem one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.1 theorem pi_div_two_le_two : π / 2 ≤ 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.2 theorem two_le_pi : (2 : ℝ) ≤ π := (div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1 (by rw [div_self (two_ne_zero' ℝ)]; exact one_le_pi_div_two) theorem pi_le_four : π ≤ 4 := (div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1 (calc π / 2 ≤ 2 := pi_div_two_le_two _ = 4 / 2 := by norm_num) @[bound] theorem pi_pos : 0 < π := lt_of_lt_of_le (by norm_num) two_le_pi @[bound] theorem pi_nonneg : 0 ≤ π := pi_pos.le theorem pi_ne_zero : π ≠ 0 := pi_pos.ne' theorem pi_div_two_pos : 0 < π / 2 := half_pos pi_pos theorem two_pi_pos : 0 < 2 * π := by linarith [pi_pos] end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `π` is always positive. -/ @[positivity Real.pi] def evalRealPi : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.pi) => assertInstancesCommute pure (.positive q(Real.pi_pos)) | _, _, _ => throwError "not Real.pi" end Mathlib.Meta.Positivity namespace NNReal open Real open Real NNReal /-- `π` considered as a nonnegative real. -/ noncomputable def pi : ℝ≥0 := ⟨π, Real.pi_pos.le⟩ @[simp] theorem coe_real_pi : (pi : ℝ) = π := rfl theorem pi_pos : 0 < pi := mod_cast Real.pi_pos theorem pi_ne_zero : pi ≠ 0 := pi_pos.ne' end NNReal namespace Real @[simp] theorem sin_pi : sin π = 0 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two]; simp @[simp] theorem cos_pi : cos π = -1 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two] norm_num @[simp] theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add] theorem sin_periodic : Function.Periodic sin (2 * π) := sin_antiperiodic.periodic_two_mul @[simp] theorem sin_add_pi (x : ℝ) : sin (x + π) = -sin x := sin_antiperiodic x @[simp] theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x := sin_periodic x @[simp] theorem sin_sub_pi (x : ℝ) : sin (x - π) = -sin x := sin_antiperiodic.sub_eq x @[simp] theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x := sin_periodic.sub_eq x @[simp] theorem sin_pi_sub (x : ℝ) : sin (π - x) = sin x := neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq' @[simp] theorem sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x := sin_neg x ▸ sin_periodic.sub_eq' @[simp] theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x := sin_periodic.nat_mul n x @[simp] theorem sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x := sin_periodic.int_mul n x @[simp] theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_nat_mul_eq n @[simp] theorem sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_int_mul_eq n @[simp] theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.nat_mul_sub_eq n @[simp] theorem sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.int_mul_sub_eq n theorem sin_add_int_mul_pi (x : ℝ) (n : ℤ) : sin (x + n * π) = (-1) ^ n * sin x := n.cast_negOnePow ℝ ▸ sin_antiperiodic.add_int_mul_eq n theorem sin_add_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x + n * π) = (-1) ^ n * sin x := sin_antiperiodic.add_nat_mul_eq n theorem sin_sub_int_mul_pi (x : ℝ) (n : ℤ) : sin (x - n * π) = (-1) ^ n * sin x := n.cast_negOnePow ℝ ▸ sin_antiperiodic.sub_int_mul_eq n theorem sin_sub_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x - n * π) = (-1) ^ n * sin x := sin_antiperiodic.sub_nat_mul_eq n theorem sin_int_mul_pi_sub (x : ℝ) (n : ℤ) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg, Int.cast_negOnePow] using sin_antiperiodic.int_mul_sub_eq n theorem sin_nat_mul_pi_sub (x : ℝ) (n : ℕ) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add] theorem cos_periodic : Function.Periodic cos (2 * π) := cos_antiperiodic.periodic_two_mul @[simp] theorem abs_cos_int_mul_pi (k : ℤ) : |cos (k * π)| = 1 := by simp [abs_cos_eq_sqrt_one_sub_sin_sq] @[simp] theorem cos_add_pi (x : ℝ) : cos (x + π) = -cos x := cos_antiperiodic x @[simp] theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x := cos_periodic x @[simp] theorem cos_sub_pi (x : ℝ) : cos (x - π) = -cos x := cos_antiperiodic.sub_eq x @[simp] theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x := cos_periodic.sub_eq x @[simp] theorem cos_pi_sub (x : ℝ) : cos (π - x) = -cos x := cos_neg x ▸ cos_antiperiodic.sub_eq' @[simp] theorem cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x := cos_neg x ▸ cos_periodic.sub_eq' @[simp] theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero @[simp] theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero @[simp] theorem cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x := cos_periodic.nat_mul n x @[simp] theorem cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x := cos_periodic.int_mul n x @[simp] theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_nat_mul_eq n @[simp] theorem cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_int_mul_eq n @[simp] theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.nat_mul_sub_eq n @[simp] theorem cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.int_mul_sub_eq n theorem cos_add_int_mul_pi (x : ℝ) (n : ℤ) : cos (x + n * π) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▸ cos_antiperiodic.add_int_mul_eq n theorem cos_add_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x + n * π) = (-1) ^ n * cos x := cos_antiperiodic.add_nat_mul_eq n theorem cos_sub_int_mul_pi (x : ℝ) (n : ℤ) : cos (x - n * π) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▸ cos_antiperiodic.sub_int_mul_eq n theorem cos_sub_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x - n * π) = (-1) ^ n * cos x := cos_antiperiodic.sub_nat_mul_eq n theorem cos_int_mul_pi_sub (x : ℝ) (n : ℤ) : cos (n * π - x) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▸ cos_neg x ▸ cos_antiperiodic.int_mul_sub_eq n theorem cos_nat_mul_pi_sub (x : ℝ) (n : ℕ) : cos (n * π - x) = (-1) ^ n * cos x := cos_neg x ▸ cos_antiperiodic.nat_mul_sub_eq n theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x := if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2 else have : (2 : ℝ) + 2 = 4 := by norm_num have : π - x ≤ 2 := sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)) sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x := sin_pos_of_pos_of_lt_pi hx.1 hx.2 theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x := by rw [← closure_Ioo pi_ne_zero.symm] at hx exact closure_lt_subset_le continuous_const continuous_sin (closure_mono (fun y => sin_pos_of_mem_Ioo) hx) theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x := sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩ theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 := neg_pos.1 <| sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx) theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 := neg_nonneg.1 <| sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx) @[simp] theorem sin_pi_div_two : sin (π / 2) = 1 := have : sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2) this.resolve_right fun h => show ¬(0 : ℝ) < -1 by norm_num <| h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos) theorem sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add] theorem sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] theorem sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] theorem cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add] theorem cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] theorem cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] theorem cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x := sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x := sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) : 0 ≤ cos x := cos_nonneg_of_mem_Icc ⟨hl, hu⟩ theorem cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 := neg_pos.1 <| cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩ theorem cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) : cos x ≤ 0 := neg_nonneg.1 <| cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩ theorem sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) : sin x = √(1 - cos x ^ 2) := by rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)] theorem cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) : cos x = √(1 - sin x ^ 2) := by rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)] lemma cos_half {x : ℝ} (hl : -π ≤ x) (hr : x ≤ π) : cos (x / 2) = sqrt ((1 + cos x) / 2) := by have : 0 ≤ cos (x / 2) := cos_nonneg_of_mem_Icc <| by constructor <;> linarith rw [← sqrt_sq this, cos_sq, add_div, two_mul, add_halves] lemma abs_sin_half (x : ℝ) : |sin (x / 2)| = sqrt ((1 - cos x) / 2) := by rw [← sqrt_sq_eq_abs, sin_sq_eq_half_sub, two_mul, add_halves, sub_div] lemma sin_half_eq_sqrt {x : ℝ} (hl : 0 ≤ x) (hr : x ≤ 2 * π) : sin (x / 2) = sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonneg] apply sin_nonneg_of_nonneg_of_le_pi <;> linarith lemma sin_half_eq_neg_sqrt {x : ℝ} (hl : -(2 * π) ≤ x) (hr : x ≤ 0) : sin (x / 2) = -sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonpos, neg_neg] apply sin_nonpos_of_nonnpos_of_neg_pi_le <;> linarith theorem sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) : sin x = 0 ↔ x = 0 := ⟨fun h => by contrapose! h cases h.lt_or_lt with | inl h0 => exact (sin_neg_of_neg_of_neg_pi_lt h0 hx₁).ne | inr h0 => exact (sin_pos_of_pos_of_lt_pi h0 hx₂).ne', fun h => by simp [h]⟩ theorem sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x := ⟨fun h => ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (Int.sub_floor_div_mul_nonneg _ pi_pos)) (sub_nonpos.1 <| le_of_not_gt fun h₃ => (sin_pos_of_pos_of_lt_pi h₃ (Int.sub_floor_div_mul_lt _ pi_pos)).ne (by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩, fun ⟨_, hn⟩ => hn ▸ sin_int_mul_pi _⟩ theorem sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x := by rw [← not_exists, not_iff_not, sin_eq_zero_iff] theorem sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, sq, sq, ← sub_eq_iff_eq_add, sub_self] exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ theorem cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x := ⟨fun h => let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (Or.inl h)) ⟨n / 2, (Int.emod_two_eq_zero_or_one n).elim (fun hn0 => by rwa [← mul_assoc, ← @Int.cast_two ℝ, ← Int.cast_mul, Int.ediv_mul_cancel (Int.dvd_iff_emod_eq_zero.2 hn0)]) fun hn1 => by rw [← Int.emod_add_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm, mul_comm (2 : ℤ), Int.cast_mul, mul_assoc, Int.cast_two] at hn rw [← hn, cos_int_mul_two_pi_add_pi] at h exact absurd h (by norm_num)⟩, fun ⟨_, hn⟩ => hn ▸ cos_int_mul_two_pi _⟩ theorem cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) : cos x = 1 ↔ x = 0 := ⟨fun h => by rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩ rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂ rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁ norm_cast at hx₁ hx₂ obtain rfl : n = 0 := le_antisymm (by omega) (by omega) simp, fun h => by simp [h]⟩ theorem sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y := by rw [← sub_pos, sin_sub_sin] have : 0 < sin ((y - x) / 2) := by apply sin_pos_of_pos_of_lt_pi <;> linarith have : 0 < cos ((y + x) / 2) := by refine cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith positivity theorem strictMonoOn_sin : StrictMonoOn sin (Icc (-(π / 2)) (π / 2)) := fun _ hx _ hy hxy => sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy theorem cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) : cos y < cos x := by rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub] apply sin_lt_sin_of_lt_of_le_pi_div_two <;> linarith theorem cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : cos y < cos x := cos_lt_cos_of_nonneg_of_le_pi hx₁ (hy₂.trans (by linarith)) hxy theorem strictAntiOn_cos : StrictAntiOn cos (Icc 0 π) := fun _ hx _ hy hxy => cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy theorem cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) : cos y ≤ cos x := (strictAntiOn_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy theorem sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y := (strictMonoOn_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy theorem injOn_sin : InjOn sin (Icc (-(π / 2)) (π / 2)) := strictMonoOn_sin.injOn theorem injOn_cos : InjOn cos (Icc 0 π) := strictAntiOn_cos.injOn theorem surjOn_sin : SurjOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := by simpa only [sin_neg, sin_pi_div_two] using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuousOn theorem surjOn_cos : SurjOn cos (Icc 0 π) (Icc (-1) 1) := by simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuousOn theorem sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩ theorem cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩ theorem mapsTo_sin (s : Set ℝ) : MapsTo sin s (Icc (-1 : ℝ) 1) := fun x _ => sin_mem_Icc x theorem mapsTo_cos (s : Set ℝ) : MapsTo cos s (Icc (-1 : ℝ) 1) := fun x _ => cos_mem_Icc x theorem bijOn_sin : BijOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := ⟨mapsTo_sin _, injOn_sin, surjOn_sin⟩ theorem bijOn_cos : BijOn cos (Icc 0 π) (Icc (-1) 1) := ⟨mapsTo_cos _, injOn_cos, surjOn_cos⟩ @[simp] theorem range_cos : range cos = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 cos_mem_Icc) surjOn_cos.subset_range @[simp] theorem range_sin : range sin = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 sin_mem_Icc) surjOn_sin.subset_range theorem range_cos_infinite : (range Real.cos).Infinite := by rw [Real.range_cos] exact Icc_infinite (by norm_num) theorem range_sin_infinite : (range Real.sin).Infinite := by rw [Real.range_sin] exact Icc_infinite (by norm_num) section CosDivSq variable (x : ℝ) /-- the series `sqrtTwoAddSeries x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots, starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrtTwoAddSeries 0 n / 2` -/ @[simp] noncomputable def sqrtTwoAddSeries (x : ℝ) : ℕ → ℝ | 0 => x | n + 1 => √(2 + sqrtTwoAddSeries x n) theorem sqrtTwoAddSeries_zero : sqrtTwoAddSeries x 0 = x := by simp theorem sqrtTwoAddSeries_one : sqrtTwoAddSeries 0 1 = √2 := by simp theorem sqrtTwoAddSeries_two : sqrtTwoAddSeries 0 2 = √(2 + √2) := by simp theorem sqrtTwoAddSeries_zero_nonneg : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries 0 n | 0 => le_refl 0 | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_nonneg {x : ℝ} (h : 0 ≤ x) : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries x n | 0 => h | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_lt_two : ∀ n : ℕ, sqrtTwoAddSeries 0 n < 2 | 0 => by norm_num | n + 1 => by refine lt_of_lt_of_le ?_ (sqrt_sq zero_lt_two.le).le rw [sqrtTwoAddSeries, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt'] · refine (sqrtTwoAddSeries_lt_two n).trans_le ?_ norm_num · exact add_nonneg zero_le_two (sqrtTwoAddSeries_zero_nonneg n) theorem sqrtTwoAddSeries_succ (x : ℝ) : ∀ n : ℕ, sqrtTwoAddSeries x (n + 1) = sqrtTwoAddSeries (√(2 + x)) n | 0 => rfl | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries_succ _ _, sqrtTwoAddSeries] theorem sqrtTwoAddSeries_monotone_left {x y : ℝ} (h : x ≤ y) : ∀ n : ℕ, sqrtTwoAddSeries x n ≤ sqrtTwoAddSeries y n | 0 => h | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries] exact sqrt_le_sqrt (add_le_add_left (sqrtTwoAddSeries_monotone_left h _) _) @[simp] theorem cos_pi_over_two_pow : ∀ n : ℕ, cos (π / 2 ^ (n + 1)) = sqrtTwoAddSeries 0 n / 2 | 0 => by simp | n + 1 => by have A : (1 : ℝ) < 2 ^ (n + 1) := one_lt_pow₀ one_lt_two n.succ_ne_zero have B : π / 2 ^ (n + 1) < π := div_lt_self pi_pos A have C : 0 < π / 2 ^ (n + 1) := by positivity rw [pow_succ, div_mul_eq_div_div, cos_half, cos_pi_over_two_pow n, sqrtTwoAddSeries, add_div_eq_mul_add_div, one_mul, ← div_mul_eq_div_div, sqrt_div, sqrt_mul_self] <;> linarith [sqrtTwoAddSeries_nonneg le_rfl n] theorem sin_sq_pi_over_two_pow (n : ℕ) : sin (π / 2 ^ (n + 1)) ^ 2 = 1 - (sqrtTwoAddSeries 0 n / 2) ^ 2 := by rw [sin_sq, cos_pi_over_two_pow] theorem sin_sq_pi_over_two_pow_succ (n : ℕ) : sin (π / 2 ^ (n + 2)) ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 := by rw [sin_sq_pi_over_two_pow, sqrtTwoAddSeries, div_pow, sq_sqrt, add_div, ← sub_sub] · congr · norm_num · norm_num · exact add_nonneg two_pos.le (sqrtTwoAddSeries_zero_nonneg _) @[simp] theorem sin_pi_over_two_pow_succ (n : ℕ) : sin (π / 2 ^ (n + 2)) = √(2 - sqrtTwoAddSeries 0 n) / 2 := by rw [eq_div_iff_mul_eq two_ne_zero, eq_comm, sqrt_eq_iff_eq_sq, mul_pow, sin_sq_pi_over_two_pow_succ, sub_mul] · congr <;> norm_num · rw [sub_nonneg] exact (sqrtTwoAddSeries_lt_two _).le refine mul_nonneg (sin_nonneg_of_nonneg_of_le_pi ?_ ?_) zero_le_two · positivity · exact div_le_self pi_pos.le <| one_le_pow₀ one_le_two @[simp] theorem cos_pi_div_four : cos (π / 4) = √2 / 2 := by trans cos (π / 2 ^ 2) · congr norm_num · simp @[simp] theorem sin_pi_div_four : sin (π / 4) = √2 / 2 := by trans sin (π / 2 ^ 2) · congr norm_num · simp @[simp] theorem cos_pi_div_eight : cos (π / 8) = √(2 + √2) / 2 := by trans cos (π / 2 ^ 3) · congr norm_num · simp @[simp] theorem sin_pi_div_eight : sin (π / 8) = √(2 - √2) / 2 := by trans sin (π / 2 ^ 3) · congr norm_num · simp @[simp] theorem cos_pi_div_sixteen : cos (π / 16) = √(2 + √(2 + √2)) / 2 := by trans cos (π / 2 ^ 4) · congr norm_num · simp @[simp] theorem sin_pi_div_sixteen : sin (π / 16) = √(2 - √(2 + √2)) / 2 := by trans sin (π / 2 ^ 4) · congr norm_num · simp @[simp] theorem cos_pi_div_thirty_two : cos (π / 32) = √(2 + √(2 + √(2 + √2))) / 2 := by trans cos (π / 2 ^ 5) · congr norm_num · simp @[simp] theorem sin_pi_div_thirty_two : sin (π / 32) = √(2 - √(2 + √(2 + √2))) / 2 := by trans sin (π / 2 ^ 5) · congr norm_num · simp -- This section is also a convenient location for other explicit values of `sin` and `cos`. /-- The cosine of `π / 3` is `1 / 2`. -/ @[simp] theorem cos_pi_div_three : cos (π / 3) = 1 / 2 := by have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 := by have : cos (3 * (π / 3)) = cos π := by congr 1 ring linarith [cos_pi, cos_three_mul (π / 3)] rcases mul_eq_zero.mp h₁ with h | h · linarith [pow_eq_zero h] · have : cos π < cos (π / 3) := by refine cos_lt_cos_of_nonneg_of_le_pi ?_ le_rfl ?_ <;> linarith [pi_pos] linarith [cos_pi] /-- The cosine of `π / 6` is `√3 / 2`. -/ @[simp] theorem cos_pi_div_six : cos (π / 6) = √3 / 2 := by rw [show (6 : ℝ) = 3 * 2 by norm_num, div_mul_eq_div_div, cos_half, cos_pi_div_three, one_add_div, ← div_mul_eq_div_div, two_add_one_eq_three, sqrt_div, sqrt_mul_self] <;> linarith [pi_pos] /-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 := by rw [cos_pi_div_six, div_pow, sq_sqrt] <;> norm_num /-- The sine of `π / 6` is `1 / 2`. -/ @[simp] theorem sin_pi_div_six : sin (π / 6) = 1 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_three] congr ring /-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 := by rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six] congr ring /-- The sine of `π / 3` is `√3 / 2`. -/ @[simp] theorem sin_pi_div_three : sin (π / 3) = √3 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_six] congr ring theorem quadratic_root_cos_pi_div_five : letI c := cos (π / 5) 4 * c ^ 2 - 2 * c - 1 = 0 := by set θ := π / 5 with hθ set c := cos θ set s := sin θ suffices 2 * c = 4 * c ^ 2 - 1 by simp [this] have hs : s ≠ 0 := by rw [ne_eq, sin_eq_zero_iff, hθ] push_neg intro n hn replace hn : n * 5 = 1 := by field_simp [mul_comm _ π, mul_assoc] at hn; norm_cast at hn omega suffices s * (2 * c) = s * (4 * c ^ 2 - 1) from mul_left_cancel₀ hs this calc s * (2 * c) = 2 * s * c := by rw [← mul_assoc, mul_comm 2] _ = sin (2 * θ) := by rw [sin_two_mul] _ = sin (π - 2 * θ) := by rw [sin_pi_sub] _ = sin (2 * θ + θ) := by congr; field_simp [hθ]; linarith _ = sin (2 * θ) * c + cos (2 * θ) * s := sin_add (2 * θ) θ _ = 2 * s * c * c + cos (2 * θ) * s := by rw [sin_two_mul] _ = 2 * s * c * c + (2 * c ^ 2 - 1) * s := by rw [cos_two_mul] _ = s * (2 * c * c) + s * (2 * c ^ 2 - 1) := by linarith _ = s * (4 * c ^ 2 - 1) := by linarith open Polynomial in theorem Polynomial.isRoot_cos_pi_div_five : (4 • X ^ 2 - 2 • X - C 1 : ℝ[X]).IsRoot (cos (π / 5)) := by simpa using quadratic_root_cos_pi_div_five /-- The cosine of `π / 5` is `(1 + √5) / 4`. -/ @[simp] theorem cos_pi_div_five : cos (π / 5) = (1 + √5) / 4 := by set c := cos (π / 5) have : 4 * (c * c) + (-2) * c + (-1) = 0 := by rw [← sq, neg_mul, ← sub_eq_add_neg, ← sub_eq_add_neg] exact quadratic_root_cos_pi_div_five have hd : discrim 4 (-2) (-1) = (2 * √5) * (2 * √5) := by norm_num [discrim, mul_mul_mul_comm] rcases (quadratic_eq_zero_iff (by norm_num) hd c).mp this with h | h · field_simp [h]; linarith · absurd (show 0 ≤ c from cos_nonneg_of_mem_Icc <| by constructor <;> linarith [pi_pos.le]) rw [not_le, h] exact div_neg_of_neg_of_pos (by norm_num [lt_sqrt]) (by positivity) end CosDivSq /-- `Real.sin` as an `OrderIso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/ def sinOrderIso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1 : ℝ) 1 := (strictMonoOn_sin.orderIso _ _).trans <| OrderIso.setCongr _ _ bijOn_sin.image_eq @[simp] theorem coe_sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : (sinOrderIso x : ℝ) = sin x := rfl theorem sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : sinOrderIso x = ⟨sin x, sin_mem_Icc x⟩ := rfl @[simp] theorem tan_pi_div_four : tan (π / 4) = 1 := by rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four] have h : √2 / 2 > 0 := by positivity exact div_self (ne_of_gt h) @[simp] theorem tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos] @[simp] theorem tan_pi_div_six : tan (π / 6) = 1 / sqrt 3 := by rw [tan_eq_sin_div_cos, sin_pi_div_six, cos_pi_div_six] ring @[simp] theorem tan_pi_div_three : tan (π / 3) = sqrt 3 := by rw [tan_eq_sin_div_cos, sin_pi_div_three, cos_pi_div_three] ring theorem tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x := by rw [tan_eq_sin_div_cos] exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith)) (cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩) theorem tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x := match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with | Or.inl hx0, Or.inl hxp => le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp) | Or.inl _, Or.inr hxp => by simp [hxp, tan_eq_sin_div_cos] | Or.inr hx0, _ => by simp [hx0.symm] theorem tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 := neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos])) theorem tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) : tan x ≤ 0 := neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith)) theorem strictMonoOn_tan : StrictMonoOn tan (Ioo (-(π / 2)) (π / 2)) := by rintro x hx y hy hlt rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, div_lt_div_iff₀ (cos_pos_of_mem_Ioo hx) (cos_pos_of_mem_Ioo hy), mul_comm, ← sub_pos, ← sin_sub] exact sin_pos_of_pos_of_lt_pi (sub_pos.2 hlt) <| by linarith [hx.1, hy.2] theorem tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := strictMonoOn_tan ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩ hxy theorem tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := tan_lt_tan_of_lt_of_lt_pi_div_two (by linarith) hy₂ hxy theorem injOn_tan : InjOn tan (Ioo (-(π / 2)) (π / 2)) := strictMonoOn_tan.injOn theorem tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) (hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y := injOn_tan ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ hxy theorem tan_periodic : Function.Periodic tan π := by simpa only [Function.Periodic, tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic @[simp] theorem tan_pi : tan π = 0 := by rw [tan_periodic.eq, tan_zero] theorem tan_add_pi (x : ℝ) : tan (x + π) = tan x := tan_periodic x theorem tan_sub_pi (x : ℝ) : tan (x - π) = tan x := tan_periodic.sub_eq x theorem tan_pi_sub (x : ℝ) : tan (π - x) = -tan x := tan_neg x ▸ tan_periodic.sub_eq' theorem tan_pi_div_two_sub (x : ℝ) : tan (π / 2 - x) = (tan x)⁻¹ := by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub] theorem tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 := tan_zero ▸ tan_periodic.nat_mul_eq n theorem tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 := tan_zero ▸ tan_periodic.int_mul_eq n theorem tan_add_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x + n * π) = tan x := tan_periodic.nat_mul n x theorem tan_add_int_mul_pi (x : ℝ) (n : ℤ) : tan (x + n * π) = tan x := tan_periodic.int_mul n x theorem tan_sub_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x - n * π) = tan x := tan_periodic.sub_nat_mul_eq n theorem tan_sub_int_mul_pi (x : ℝ) (n : ℤ) : tan (x - n * π) = tan x := tan_periodic.sub_int_mul_eq n theorem tan_nat_mul_pi_sub (x : ℝ) (n : ℕ) : tan (n * π - x) = -tan x := tan_neg x ▸ tan_periodic.nat_mul_sub_eq n theorem tan_int_mul_pi_sub (x : ℝ) (n : ℤ) : tan (n * π - x) = -tan x := tan_neg x ▸ tan_periodic.int_mul_sub_eq n theorem tendsto_sin_pi_div_two : Tendsto sin (𝓝[<] (π / 2)) (𝓝 1) := by convert continuous_sin.continuousWithinAt.tendsto simp theorem tendsto_cos_pi_div_two : Tendsto cos (𝓝[<] (π / 2)) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · convert continuous_cos.continuousWithinAt.tendsto simp · filter_upwards [Ioo_mem_nhdsLT (neg_lt_self pi_div_two_pos)] with x hx exact cos_pos_of_mem_Ioo hx theorem tendsto_tan_pi_div_two : Tendsto tan (𝓝[<] (π / 2)) atTop := by convert tendsto_cos_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_pos zero_lt_one tendsto_sin_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] theorem tendsto_sin_neg_pi_div_two : Tendsto sin (𝓝[>] (-(π / 2))) (𝓝 (-1)) := by convert continuous_sin.continuousWithinAt.tendsto using 2 simp theorem tendsto_cos_neg_pi_div_two : Tendsto cos (𝓝[>] (-(π / 2))) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · convert continuous_cos.continuousWithinAt.tendsto simp · filter_upwards [Ioo_mem_nhdsGT (neg_lt_self pi_div_two_pos)] with x hx exact cos_pos_of_mem_Ioo hx theorem tendsto_tan_neg_pi_div_two : Tendsto tan (𝓝[>] (-(π / 2))) atBot := by convert tendsto_cos_neg_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_neg (by norm_num) tendsto_sin_neg_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] end Real namespace Complex open Real theorem sin_eq_zero_iff_cos_eq {z : ℂ} : sin z = 0 ↔ cos z = 1 ∨ cos z = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, ← sub_eq_iff_eq_add, sub_self] exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ @[simp] theorem cos_pi_div_two : cos (π / 2) = 0 := calc cos (π / 2) = Real.cos (π / 2) := by rw [ofReal_cos]; simp _ = 0 := by simp @[simp] theorem sin_pi_div_two : sin (π / 2) = 1 := calc sin (π / 2) = Real.sin (π / 2) := by rw [ofReal_sin]; simp _ = 1 := by simp @[simp] theorem sin_pi : sin π = 0 := by rw [← ofReal_sin, Real.sin_pi]; simp @[simp] theorem cos_pi : cos π = -1 := by rw [← ofReal_cos, Real.cos_pi]; simp @[simp] theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add] theorem sin_periodic : Function.Periodic sin (2 * π) := sin_antiperiodic.periodic_two_mul
theorem sin_add_pi (x : ℂ) : sin (x + π) = -sin x :=
Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean
1,019
1,020
/- Copyright (c) 2021 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Joël Riou -/ import Mathlib.CategoryTheory.Adjunction.Restrict import Mathlib.CategoryTheory.Adjunction.Whiskering import Mathlib.CategoryTheory.Sites.PreservesSheafification /-! In this file, we show that an adjunction `G ⊣ F` induces an adjunction between categories of sheaves. We also show that `G` preserves sheafification. -/ namespace CategoryTheory open GrothendieckTopology CategoryTheory Limits Opposite universe v₁ v₂ u₁ u₂ variable {C : Type u₁} [Category.{v₁} C] (J : GrothendieckTopology C) variable {D : Type u₂} [Category.{v₂} D] variable {E : Type*} [Category E] variable {F : D ⥤ E} {G : E ⥤ D} /-- The forgetful functor from `Sheaf J D` to sheaves of types, for a concrete category `D` whose forgetful functor preserves the correct limits. -/ abbrev sheafForget [HasForget D] [HasSheafCompose J (forget D)] : Sheaf J D ⥤ Sheaf J (Type _) := sheafCompose J (forget D) namespace Sheaf noncomputable section /-- An adjunction `adj : G ⊣ F` with `F : D ⥤ E` and `G : E ⥤ D` induces an adjunction between `Sheaf J D` and `Sheaf J E`, in contexts where one can sheafify `D`-valued presheaves, and postcomposing with `F` preserves the property of being a sheaf. -/ def adjunction [HasWeakSheafify J D] [HasSheafCompose J F] (adj : G ⊣ F) : composeAndSheafify J G ⊣ sheafCompose J F := Adjunction.restrictFullyFaithful ((adj.whiskerRight Cᵒᵖ).comp (sheafificationAdjunction J D)) (fullyFaithfulSheafToPresheaf J E) (Functor.FullyFaithful.id _) (Iso.refl _) (Iso.refl _) @[simp] lemma adjunction_unit_app_val [HasWeakSheafify J D] [HasSheafCompose J F] (adj : G ⊣ F) (X : Sheaf J E) : ((adjunction J adj).unit.app X).val = (adj.whiskerRight Cᵒᵖ).unit.app _ ≫ whiskerRight (toSheafify J (X.val ⋙ G)) F := by change (sheafToPresheaf _ _).map ((adjunction J adj).unit.app X) = _ simp only [Functor.id_obj, Functor.comp_obj, whiskeringRight_obj_obj, adjunction, Adjunction.map_restrictFullyFaithful_unit_app, Adjunction.comp_unit_app, sheafificationAdjunction_unit_app, whiskeringRight_obj_map, Iso.refl_hom, NatTrans.id_app, Functor.comp_map, Functor.map_id, whiskerRight_id', Category.comp_id] rfl @[simp] lemma adjunction_counit_app_val [HasWeakSheafify J D] [HasSheafCompose J F] (adj : G ⊣ F) (Y : Sheaf J D) : ((adjunction J adj).counit.app Y).val = sheafifyLift J (((adj.whiskerRight Cᵒᵖ).counit.app Y.val)) Y.cond := by change ((𝟭 (Sheaf _ _)).map ((adjunction J adj).counit.app Y)).val = _ simp only [Functor.comp_obj, sheafToPresheaf_obj, sheafCompose_obj_val, whiskeringRight_obj_obj, adjunction, Adjunction.map_restrictFullyFaithful_counit_app, Iso.refl_inv, NatTrans.id_app, Functor.comp_map, whiskeringRight_obj_map, Adjunction.comp_counit_app, instCategorySheaf_comp_val, instCategorySheaf_id_val, sheafificationAdjunction_counit_app_val, sheafifyMap_sheafifyLift, Functor.id_obj, whiskerRight_id', Category.comp_id, Category.id_comp] instance [HasWeakSheafify J D] [F.IsRightAdjoint] : (sheafCompose J F).IsRightAdjoint := (adjunction J (Adjunction.ofIsRightAdjoint F)).isRightAdjoint instance [HasWeakSheafify J D] [G.IsLeftAdjoint] : (composeAndSheafify J G).IsLeftAdjoint := (adjunction J (Adjunction.ofIsLeftAdjoint G)).isLeftAdjoint lemma preservesSheafification_of_adjunction (adj : G ⊣ F) : J.PreservesSheafification G where le P Q f hf := by have := adj.isRightAdjoint rw [MorphismProperty.inverseImage_iff] dsimp intro R hR rw [← ((adj.whiskerRight Cᵒᵖ).homEquiv P R).comp_bijective] convert (((adj.whiskerRight Cᵒᵖ).homEquiv Q R).trans (hf.homEquiv (R ⋙ F) ((sheafCompose J F).obj ⟨R, hR⟩).cond)).bijective ext g X -- The rest of this proof was -- `dsimp [Adjunction.whiskerRight, Adjunction.mkOfUnitCounit]; simp` before https://github.com/leanprover-community/mathlib4/pull/16317. dsimp rw [← NatTrans.comp_app] congr exact Adjunction.homEquiv_naturality_left _ _ _ instance [G.IsLeftAdjoint] : J.PreservesSheafification G := preservesSheafification_of_adjunction J (Adjunction.ofIsLeftAdjoint G) section ForgetToType variable [HasWeakSheafify J D] [HasForget D] [HasSheafCompose J (forget D)] @[deprecated (since := "2024-11-26")] alias composeAndSheafifyFromTypes := composeAndSheafify /-- The adjunction `composeAndSheafify J G ⊣ sheafForget J`. -/ @[deprecated Sheaf.adjunction (since := "2024-11-26")] abbrev adjunctionToTypes {G : Type max v₁ u₁ ⥤ D} (adj : G ⊣ forget D) : composeAndSheafify J G ⊣ sheafForget J := adjunction _ adj example [(forget D).IsRightAdjoint] : (sheafForget.{_, _, _, _, max u₁ v₁} (D := D) J).IsRightAdjoint := by infer_instance end ForgetToType end end Sheaf end CategoryTheory
Mathlib/CategoryTheory/Sites/Adjunction.lean
136
143
/- Copyright (c) 2021 Benjamin Davidson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog import Mathlib.Analysis.SpecialFunctions.NonIntegrable import Mathlib.Analysis.SpecialFunctions.Pow.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts /-! # Integration of specific interval integrals This file contains proofs of the integrals of various specific functions. This includes: * Integrals of simple functions, such as `id`, `pow`, `inv`, `exp`, `log` * Integrals of some trigonometric functions, such as `sin`, `cos`, `1 / (1 + x^2)` * The integral of `cos x ^ 2 - sin x ^ 2` * Reduction formulae for the integrals of `sin x ^ n` and `cos x ^ n` for `n ≥ 2` * The computation of `∫ x in 0..π, sin x ^ n` as a product for even and odd `n` (used in proving the Wallis product for pi) * Integrals of the form `sin x ^ m * cos x ^ n` With these lemmas, many simple integrals can be computed by `simp` or `norm_num`. This file also contains some facts about the interval integrability of specific functions. This file is still being developed. ## Tags integrate, integration, integrable, integrability -/ open Real Set Finset open scoped Real Interval variable {a b : ℝ} (n : ℕ) namespace intervalIntegral open MeasureTheory variable {f : ℝ → ℝ} {μ : Measure ℝ} [IsLocallyFiniteMeasure μ] (c d : ℝ) /-! ### Interval integrability -/ @[simp] theorem intervalIntegrable_pow : IntervalIntegrable (fun x => x ^ n) μ a b := (continuous_pow n).intervalIntegrable a b theorem intervalIntegrable_zpow {n : ℤ} (h : 0 ≤ n ∨ (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable (fun x => x ^ n) μ a b := (continuousOn_id.zpow₀ n fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable /-- See `intervalIntegrable_rpow'` for a version with a weaker hypothesis on `r`, but assuming the measure is volume. -/ theorem intervalIntegrable_rpow {r : ℝ} (h : 0 ≤ r ∨ (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable (fun x => x ^ r) μ a b := (continuousOn_id.rpow_const fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable /-- See `intervalIntegrable_rpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_rpow' {r : ℝ} (h : -1 < r) : IntervalIntegrable (fun x => x ^ r) volume a b := by suffices ∀ c : ℝ, IntervalIntegrable (fun x => x ^ r) volume 0 c by exact IntervalIntegrable.trans (this a).symm (this b) have : ∀ c : ℝ, 0 ≤ c → IntervalIntegrable (fun x => x ^ r) volume 0 c := by intro c hc rw [intervalIntegrable_iff, uIoc_of_le hc] have hderiv : ∀ x ∈ Ioo 0 c, HasDerivAt (fun x : ℝ => x ^ (r + 1) / (r + 1)) (x ^ r) x := by intro x hx convert (Real.hasDerivAt_rpow_const (p := r + 1) (Or.inl hx.1.ne')).div_const (r + 1) using 1 field_simp [(by linarith : r + 1 ≠ 0)] apply integrableOn_deriv_of_nonneg _ hderiv · intro x hx; apply rpow_nonneg hx.1.le · refine (continuousOn_id.rpow_const ?_).div_const _; intro x _; right; linarith intro c; rcases le_total 0 c with (hc | hc) · exact this c hc · rw [IntervalIntegrable.iff_comp_neg, neg_zero] have m := (this (-c) (by linarith)).smul (cos (r * π)) rw [intervalIntegrable_iff] at m ⊢ refine m.congr_fun ?_ measurableSet_Ioc; intro x hx rw [uIoc_of_le (by linarith : 0 ≤ -c)] at hx simp only [Pi.smul_apply, Algebra.id.smul_eq_mul, log_neg_eq_log, mul_comm, rpow_def_of_pos hx.1, rpow_def_of_neg (by linarith [hx.1] : -x < 0)] /-- The power function `x ↦ x^s` is integrable on `(0, t)` iff `-1 < s`. -/ lemma integrableOn_Ioo_rpow_iff {s t : ℝ} (ht : 0 < t) : IntegrableOn (fun x ↦ x ^ s) (Ioo (0 : ℝ) t) ↔ -1 < s := by refine ⟨fun h ↦ ?_, fun h ↦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le] using intervalIntegrable_rpow' h (a := 0) (b := t)⟩ contrapose! h intro H have I : 0 < min 1 t := lt_min zero_lt_one ht have H' : IntegrableOn (fun x ↦ x ^ s) (Ioo 0 (min 1 t)) := H.mono (Set.Ioo_subset_Ioo le_rfl (min_le_right _ _)) le_rfl have : IntegrableOn (fun x ↦ x⁻¹) (Ioo 0 (min 1 t)) := by apply H'.mono' measurable_inv.aestronglyMeasurable filter_upwards [ae_restrict_mem measurableSet_Ioo] with x hx simp only [norm_inv, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hx.1)] rwa [← Real.rpow_neg_one x, Real.rpow_le_rpow_left_iff_of_base_lt_one hx.1] exact lt_of_lt_of_le hx.2 (min_le_left _ _) have : IntervalIntegrable (fun x ↦ x⁻¹) volume 0 (min 1 t) := by rwa [intervalIntegrable_iff_integrableOn_Ioo_of_le I.le] simp [intervalIntegrable_inv_iff, I.ne] at this /-- See `intervalIntegrable_cpow'` for a version with a weaker hypothesis on `r`, but assuming the measure is volume. -/ theorem intervalIntegrable_cpow {r : ℂ} (h : 0 ≤ r.re ∨ (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable (fun x : ℝ => (x : ℂ) ^ r) μ a b := by by_cases h2 : (0 : ℝ) ∉ [[a, b]] · -- Easy case #1: 0 ∉ [a, b] -- use continuity. refine (continuousOn_of_forall_continuousAt fun x hx => ?_).intervalIntegrable exact Complex.continuousAt_ofReal_cpow_const _ _ (Or.inr <| ne_of_mem_of_not_mem hx h2) rw [eq_false h2, or_false] at h rcases lt_or_eq_of_le h with (h' | h') · -- Easy case #2: 0 < re r -- again use continuity exact (Complex.continuous_ofReal_cpow_const h').intervalIntegrable _ _ -- Now the hard case: re r = 0 and 0 is in the interval. refine (IntervalIntegrable.intervalIntegrable_norm_iff ?_).mp ?_ · refine (measurable_of_continuousOn_compl_singleton (0 : ℝ) ?_).aestronglyMeasurable exact continuousOn_of_forall_continuousAt fun x hx => Complex.continuousAt_ofReal_cpow_const x r (Or.inr hx) -- reduce to case of integral over `[0, c]` suffices ∀ c : ℝ, IntervalIntegrable (fun x : ℝ => ‖(x : ℂ) ^ r‖) μ 0 c from (this a).symm.trans (this b) intro c rcases le_or_lt 0 c with (hc | hc) · -- case `0 ≤ c`: integrand is identically 1 have : IntervalIntegrable (fun _ => 1 : ℝ → ℝ) μ 0 c := intervalIntegrable_const rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc] at this ⊢ refine IntegrableOn.congr_fun this (fun x hx => ?_) measurableSet_Ioc dsimp only rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1, ← h', rpow_zero] · -- case `c < 0`: integrand is identically constant, *except* at `x = 0` if `r ≠ 0`. apply IntervalIntegrable.symm rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc.le] rw [← Ioo_union_right hc, integrableOn_union, and_comm]; constructor · refine integrableOn_singleton_iff.mpr (Or.inr ?_) exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_singleton · have : ∀ x : ℝ, x ∈ Ioo c 0 → ‖Complex.exp (↑π * Complex.I * r)‖ = ‖(x : ℂ) ^ r‖ := by intro x hx rw [Complex.ofReal_cpow_of_nonpos hx.2.le, norm_mul, ← Complex.ofReal_neg, Complex.norm_cpow_eq_rpow_re_of_pos (neg_pos.mpr hx.2), ← h', rpow_zero, one_mul] refine IntegrableOn.congr_fun ?_ this measurableSet_Ioo rw [integrableOn_const] refine Or.inr ((measure_mono Set.Ioo_subset_Icc_self).trans_lt ?_) exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_Icc /-- See `intervalIntegrable_cpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_cpow' {r : ℂ} (h : -1 < r.re) : IntervalIntegrable (fun x : ℝ => (x : ℂ) ^ r) volume a b := by suffices ∀ c : ℝ, IntervalIntegrable (fun x => (x : ℂ) ^ r) volume 0 c by exact IntervalIntegrable.trans (this a).symm (this b) have : ∀ c : ℝ, 0 ≤ c → IntervalIntegrable (fun x => (x : ℂ) ^ r) volume 0 c := by intro c hc rw [← IntervalIntegrable.intervalIntegrable_norm_iff] · rw [intervalIntegrable_iff] apply IntegrableOn.congr_fun · rw [← intervalIntegrable_iff]; exact intervalIntegral.intervalIntegrable_rpow' h · intro x hx rw [uIoc_of_le hc] at hx dsimp only rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1] · exact measurableSet_uIoc · refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_uIoc refine continuousOn_of_forall_continuousAt fun x hx => ?_ rw [uIoc_of_le hc] at hx refine (continuousAt_cpow_const (Or.inl ?_)).comp Complex.continuous_ofReal.continuousAt rw [Complex.ofReal_re] exact hx.1 intro c; rcases le_total 0 c with (hc | hc) · exact this c hc · rw [IntervalIntegrable.iff_comp_neg, neg_zero] have m := (this (-c) (by linarith)).const_mul (Complex.exp (π * Complex.I * r)) rw [intervalIntegrable_iff, uIoc_of_le (by linarith : 0 ≤ -c)] at m ⊢ refine m.congr_fun (fun x hx => ?_) measurableSet_Ioc dsimp only have : -x ≤ 0 := by linarith [hx.1] rw [Complex.ofReal_cpow_of_nonpos this, mul_comm] simp /-- The complex power function `x ↦ x^s` is integrable on `(0, t)` iff `-1 < s.re`. -/ theorem integrableOn_Ioo_cpow_iff {s : ℂ} {t : ℝ} (ht : 0 < t) : IntegrableOn (fun x : ℝ ↦ (x : ℂ) ^ s) (Ioo (0 : ℝ) t) ↔ -1 < s.re := by refine ⟨fun h ↦ ?_, fun h ↦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le] using intervalIntegrable_cpow' h (a := 0) (b := t)⟩ have B : IntegrableOn (fun a ↦ a ^ s.re) (Ioo 0 t) := by apply (integrableOn_congr_fun _ measurableSet_Ioo).1 h.norm intro a ha simp [Complex.norm_cpow_eq_rpow_re_of_pos ha.1] rwa [integrableOn_Ioo_rpow_iff ht] at B @[simp] theorem intervalIntegrable_id : IntervalIntegrable (fun x => x) μ a b := continuous_id.intervalIntegrable a b theorem intervalIntegrable_const : IntervalIntegrable (fun _ => c) μ a b := continuous_const.intervalIntegrable a b theorem intervalIntegrable_one_div (h : ∀ x : ℝ, x ∈ [[a, b]] → f x ≠ 0) (hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => 1 / f x) μ a b := (continuousOn_const.div hf h).intervalIntegrable @[simp] theorem intervalIntegrable_inv (h : ∀ x : ℝ, x ∈ [[a, b]] → f x ≠ 0) (hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => (f x)⁻¹) μ a b := by simpa only [one_div] using intervalIntegrable_one_div h hf @[simp] theorem intervalIntegrable_exp : IntervalIntegrable exp μ a b := continuous_exp.intervalIntegrable a b @[simp] theorem _root_.IntervalIntegrable.log (hf : ContinuousOn f [[a, b]]) (h : ∀ x : ℝ, x ∈ [[a, b]] → f x ≠ 0) : IntervalIntegrable (fun x => log (f x)) μ a b := (ContinuousOn.log hf h).intervalIntegrable /-- See `intervalIntegrable_log'` for a version without any hypothesis on the interval, but assuming the measure is volume. -/ @[simp] theorem intervalIntegrable_log (h : (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable log μ a b := IntervalIntegrable.log continuousOn_id fun _ hx => ne_of_mem_of_not_mem hx h /-- The real logarithm is interval integrable (with respect to the volume measure) on every interval. See `intervalIntegrable_log` for a version applying to any locally finite measure, but with an additional hypothesis on the interval. -/ @[simp] theorem intervalIntegrable_log' : IntervalIntegrable log volume a b := by -- Log is even, so it suffices to consider the case 0 < a and b = 0 apply intervalIntegrable_of_even (log_neg_eq_log · |>.symm) intro x hx -- Split integral apply IntervalIntegrable.trans (b := 1) · -- Show integrability on [0…1] using non-negativity of the derivative rw [← neg_neg log] apply IntervalIntegrable.neg apply intervalIntegrable_deriv_of_nonneg (g := fun x ↦ -(x * log x - x)) · exact (continuous_mul_log.continuousOn.sub continuous_id.continuousOn).neg · intro s ⟨hs, _⟩ norm_num at * simpa using (hasDerivAt_id s).sub (hasDerivAt_mul_log hs.ne.symm) · intro s ⟨hs₁, hs₂⟩ norm_num at * exact (log_nonpos_iff hs₁.le).mpr hs₂.le · -- Show integrability on [1…t] by continuity apply ContinuousOn.intervalIntegrable apply Real.continuousOn_log.mono apply Set.not_mem_uIcc_of_lt zero_lt_one at hx simpa @[simp] theorem intervalIntegrable_sin : IntervalIntegrable sin μ a b := continuous_sin.intervalIntegrable a b @[simp] theorem intervalIntegrable_cos : IntervalIntegrable cos μ a b := continuous_cos.intervalIntegrable a b theorem intervalIntegrable_one_div_one_add_sq : IntervalIntegrable (fun x : ℝ => 1 / (↑1 + x ^ 2)) μ a b := by refine (continuous_const.div ?_ fun x => ?_).intervalIntegrable a b · fun_prop · nlinarith @[simp] theorem intervalIntegrable_inv_one_add_sq : IntervalIntegrable (fun x : ℝ => (↑1 + x ^ 2)⁻¹) μ a b := by field_simp; exact mod_cast intervalIntegrable_one_div_one_add_sq /-! ### Integrals of the form `c * ∫ x in a..b, f (c * x + d)` -/ section @[simp] theorem mul_integral_comp_mul_right : (c * ∫ x in a..b, f (x * c)) = ∫ x in a * c..b * c, f x := smul_integral_comp_mul_right f c @[simp] theorem mul_integral_comp_mul_left : (c * ∫ x in a..b, f (c * x)) = ∫ x in c * a..c * b, f x := smul_integral_comp_mul_left f c @[simp] theorem inv_mul_integral_comp_div : (c⁻¹ * ∫ x in a..b, f (x / c)) = ∫ x in a / c..b / c, f x := inv_smul_integral_comp_div f c @[simp] theorem mul_integral_comp_mul_add : (c * ∫ x in a..b, f (c * x + d)) = ∫ x in c * a + d..c * b + d, f x := smul_integral_comp_mul_add f c d @[simp] theorem mul_integral_comp_add_mul : (c * ∫ x in a..b, f (d + c * x)) = ∫ x in d + c * a..d + c * b, f x := smul_integral_comp_add_mul f c d @[simp] theorem inv_mul_integral_comp_div_add : (c⁻¹ * ∫ x in a..b, f (x / c + d)) = ∫ x in a / c + d..b / c + d, f x := inv_smul_integral_comp_div_add f c d @[simp] theorem inv_mul_integral_comp_add_div : (c⁻¹ * ∫ x in a..b, f (d + x / c)) = ∫ x in d + a / c..d + b / c, f x := inv_smul_integral_comp_add_div f c d @[simp] theorem mul_integral_comp_mul_sub : (c * ∫ x in a..b, f (c * x - d)) = ∫ x in c * a - d..c * b - d, f x := smul_integral_comp_mul_sub f c d @[simp] theorem mul_integral_comp_sub_mul : (c * ∫ x in a..b, f (d - c * x)) = ∫ x in d - c * b..d - c * a, f x := smul_integral_comp_sub_mul f c d @[simp] theorem inv_mul_integral_comp_div_sub : (c⁻¹ * ∫ x in a..b, f (x / c - d)) = ∫ x in a / c - d..b / c - d, f x := inv_smul_integral_comp_div_sub f c d @[simp] theorem inv_mul_integral_comp_sub_div : (c⁻¹ * ∫ x in a..b, f (d - x / c)) = ∫ x in d - b / c..d - a / c, f x := inv_smul_integral_comp_sub_div f c d end end intervalIntegral open intervalIntegral /-! ### Integrals of simple functions -/ theorem integral_cpow {r : ℂ} (h : -1 < r.re ∨ r ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]]) : (∫ x : ℝ in a..b, (x : ℂ) ^ r) = ((b : ℂ) ^ (r + 1) - (a : ℂ) ^ (r + 1)) / (r + 1) := by rw [sub_div] have hr : r + 1 ≠ 0 := by rcases h with h | h · apply_fun Complex.re rw [Complex.add_re, Complex.one_re, Complex.zero_re, Ne, add_eq_zero_iff_eq_neg] exact h.ne' · rw [Ne, ← add_eq_zero_iff_eq_neg] at h; exact h.1 by_cases hab : (0 : ℝ) ∉ [[a, b]] · apply integral_eq_sub_of_hasDerivAt (fun x hx => ?_) (intervalIntegrable_cpow (r := r) <| Or.inr hab) refine hasDerivAt_ofReal_cpow_const' (ne_of_mem_of_not_mem hx hab) ?_ contrapose! hr; rwa [add_eq_zero_iff_eq_neg] replace h : -1 < r.re := by tauto suffices ∀ c : ℝ, (∫ x : ℝ in (0)..c, (x : ℂ) ^ r) = (c : ℂ) ^ (r + 1) / (r + 1) - (0 : ℂ) ^ (r + 1) / (r + 1) by rw [← integral_add_adjacent_intervals (@intervalIntegrable_cpow' a 0 r h) (@intervalIntegrable_cpow' 0 b r h), integral_symm, this a, this b, Complex.zero_cpow hr] ring intro c apply integral_eq_sub_of_hasDeriv_right · refine ((Complex.continuous_ofReal_cpow_const ?_).div_const _).continuousOn rwa [Complex.add_re, Complex.one_re, ← neg_lt_iff_pos_add] · refine fun x hx => (hasDerivAt_ofReal_cpow_const' ?_ ?_).hasDerivWithinAt · rcases le_total c 0 with (hc | hc) · rw [max_eq_left hc] at hx; exact hx.2.ne · rw [min_eq_left hc] at hx; exact hx.1.ne' · contrapose! hr; rw [hr]; ring · exact intervalIntegrable_cpow' h theorem integral_rpow {r : ℝ} (h : -1 < r ∨ r ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]]) : ∫ x in a..b, x ^ r = (b ^ (r + 1) - a ^ (r + 1)) / (r + 1) := by have h' : -1 < (r : ℂ).re ∨ (r : ℂ) ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]] := by cases h · left; rwa [Complex.ofReal_re] · right; rwa [← Complex.ofReal_one, ← Complex.ofReal_neg, Ne, Complex.ofReal_inj] have : (∫ x in a..b, (x : ℂ) ^ (r : ℂ)) = ((b : ℂ) ^ (r + 1 : ℂ) - (a : ℂ) ^ (r + 1 : ℂ)) / (r + 1) := integral_cpow h' apply_fun Complex.re at this; convert this · simp_rw [intervalIntegral_eq_integral_uIoc, Complex.real_smul, Complex.re_ofReal_mul, rpow_def, ← RCLike.re_eq_complex_re, smul_eq_mul] rw [integral_re] refine intervalIntegrable_iff.mp ?_ rcases h' with h' | h' · exact intervalIntegrable_cpow' h' · exact intervalIntegrable_cpow (Or.inr h'.2) · rw [(by push_cast; rfl : (r : ℂ) + 1 = ((r + 1 : ℝ) : ℂ))] simp_rw [div_eq_inv_mul, ← Complex.ofReal_inv, Complex.re_ofReal_mul, Complex.sub_re, rpow_def] theorem integral_zpow {n : ℤ} (h : 0 ≤ n ∨ n ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]]) : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by replace h : -1 < (n : ℝ) ∨ (n : ℝ) ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]] := mod_cast h exact mod_cast integral_rpow h @[simp] theorem integral_pow : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by simpa only [← Int.natCast_succ, zpow_natCast] using integral_zpow (Or.inl n.cast_nonneg) /-- Integral of `|x - a| ^ n` over `Ι a b`. This integral appears in the proof of the Picard-Lindelöf/Cauchy-Lipschitz theorem. -/ theorem integral_pow_abs_sub_uIoc : ∫ x in Ι a b, |x - a| ^ n = |b - a| ^ (n + 1) / (n + 1) := by rcases le_or_lt a b with hab | hab · calc ∫ x in Ι a b, |x - a| ^ n = ∫ x in a..b, |x - a| ^ n := by rw [uIoc_of_le hab, ← integral_of_le hab] _ = ∫ x in (0)..(b - a), x ^ n := by simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self] refine integral_congr fun x hx => congr_arg₂ Pow.pow (abs_of_nonneg <| ?_) rfl rw [uIcc_of_le (sub_nonneg.2 hab)] at hx exact hx.1 _ = |b - a| ^ (n + 1) / (n + 1) := by simp [abs_of_nonneg (sub_nonneg.2 hab)] · calc ∫ x in Ι a b, |x - a| ^ n = ∫ x in b..a, |x - a| ^ n := by rw [uIoc_of_ge hab.le, ← integral_of_le hab.le] _ = ∫ x in b - a..0, (-x) ^ n := by simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self] refine integral_congr fun x hx => congr_arg₂ Pow.pow (abs_of_nonpos <| ?_) rfl rw [uIcc_of_le (sub_nonpos.2 hab.le)] at hx exact hx.2 _ = |b - a| ^ (n + 1) / (n + 1) := by simp [integral_comp_neg fun x => x ^ n, abs_of_neg (sub_neg.2 hab)] @[simp] theorem integral_id : ∫ x in a..b, x = (b ^ 2 - a ^ 2) / 2 := by have := @integral_pow a b 1 norm_num at this exact this theorem integral_one : (∫ _ in a..b, (1 : ℝ)) = b - a := by simp only [mul_one, smul_eq_mul, integral_const] theorem integral_const_on_unit_interval : ∫ _ in a..a + 1, b = b := by simp @[simp] theorem integral_inv (h : (0 : ℝ) ∉ [[a, b]]) : ∫ x in a..b, x⁻¹ = log (b / a) := by have h' := fun x (hx : x ∈ [[a, b]]) => ne_of_mem_of_not_mem hx h rw [integral_deriv_eq_sub' _ deriv_log' (fun x hx => differentiableAt_log (h' x hx)) (continuousOn_inv₀.mono <| subset_compl_singleton_iff.mpr h), log_div (h' b right_mem_uIcc) (h' a left_mem_uIcc)] @[simp] theorem integral_inv_of_pos (ha : 0 < a) (hb : 0 < b) : ∫ x in a..b, x⁻¹ = log (b / a) := integral_inv <| not_mem_uIcc_of_lt ha hb @[simp] theorem integral_inv_of_neg (ha : a < 0) (hb : b < 0) : ∫ x in a..b, x⁻¹ = log (b / a) := integral_inv <| not_mem_uIcc_of_gt ha hb theorem integral_one_div (h : (0 : ℝ) ∉ [[a, b]]) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv h] theorem integral_one_div_of_pos (ha : 0 < a) (hb : 0 < b) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv_of_pos ha hb] theorem integral_one_div_of_neg (ha : a < 0) (hb : b < 0) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv_of_neg ha hb] @[simp] theorem integral_exp : ∫ x in a..b, exp x = exp b - exp a := by rw [integral_deriv_eq_sub'] · simp · exact fun _ _ => differentiableAt_exp · exact continuousOn_exp theorem integral_exp_mul_complex {c : ℂ} (hc : c ≠ 0) : (∫ x in a..b, Complex.exp (c * x)) = (Complex.exp (c * b) - Complex.exp (c * a)) / c := by have D : ∀ x : ℝ, HasDerivAt (fun y : ℝ => Complex.exp (c * y) / c) (Complex.exp (c * x)) x := by intro x conv => congr rw [← mul_div_cancel_right₀ (Complex.exp (c * x)) hc] apply ((Complex.hasDerivAt_exp _).comp x _).div_const c simpa only [mul_one] using ((hasDerivAt_id (x : ℂ)).const_mul _).comp_ofReal rw [integral_deriv_eq_sub' _ (funext fun x => (D x).deriv) fun x _ => (D x).differentiableAt] · ring · fun_prop /-- Helper lemma for `integral_log`: case where `a = 0` and `b` is positive. -/ lemma integral_log_from_zero_of_pos (ht : 0 < b) : ∫ s in (0)..b, log s = b * log b - b := by -- Compute the integral by giving a primitive and considering it limit as x approaches 0 from the -- right. The following lines were suggested by Gareth Ma on Zulip. rw [integral_eq_sub_of_hasDerivAt_of_tendsto (f := fun x ↦ x * log x - x) (fa := 0) (fb := b * log b - b) (hint := intervalIntegrable_log')] · abel · exact ht · intro s ⟨hs, _ ⟩ simpa using (hasDerivAt_mul_log hs.ne.symm).sub (hasDerivAt_id s) · simpa [mul_comm] using ((tendsto_log_mul_rpow_nhdsGT_zero zero_lt_one).sub (tendsto_nhdsWithin_of_tendsto_nhds Filter.tendsto_id)) · exact tendsto_nhdsWithin_of_tendsto_nhds (ContinuousAt.tendsto (by fun_prop)) /-- Helper lemma for `integral_log`: case where `a = 0`. -/ lemma integral_log_from_zero {b : ℝ} : ∫ s in (0)..b, log s = b * log b - b := by rcases lt_trichotomy b 0 with h | h | h · -- If t is negative, use that log is an even function to reduce to the positive case. conv => arg 1; arg 1; intro t; rw [← log_neg_eq_log] rw [intervalIntegral.integral_comp_neg, intervalIntegral.integral_symm, neg_zero, integral_log_from_zero_of_pos (Left.neg_pos_iff.mpr h), log_neg_eq_log] ring · simp [h] · exact integral_log_from_zero_of_pos h @[simp] theorem integral_log : ∫ s in a..b, log s = b * log b - a * log a - b + a := by rw [← intervalIntegral.integral_add_adjacent_intervals (b := 0)] · rw [intervalIntegral.integral_symm, integral_log_from_zero, integral_log_from_zero] ring all_goals exact intervalIntegrable_log' @[deprecated (since := "2025-01-12")] alias integral_log_of_pos := integral_log @[deprecated (since := "2025-01-12")] alias integral_log_of_neg := integral_log @[simp] theorem integral_sin : ∫ x in a..b, sin x = cos a - cos b := by rw [integral_deriv_eq_sub' fun x => -cos x] · ring · norm_num · simp only [differentiableAt_neg_iff, differentiableAt_cos, implies_true] · exact continuousOn_sin @[simp] theorem integral_cos : ∫ x in a..b, cos x = sin b - sin a := by rw [integral_deriv_eq_sub'] · norm_num · simp only [differentiableAt_sin, implies_true] · exact continuousOn_cos theorem integral_cos_mul_complex {z : ℂ} (hz : z ≠ 0) (a b : ℝ) : (∫ x in a..b, Complex.cos (z * x)) = Complex.sin (z * b) / z - Complex.sin (z * a) / z := by apply integral_eq_sub_of_hasDerivAt swap · apply Continuous.intervalIntegrable exact Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal) intro x _ have a := Complex.hasDerivAt_sin (↑x * z) have b : HasDerivAt (fun y => y * z : ℂ → ℂ) z ↑x := hasDerivAt_mul_const _ have c : HasDerivAt (Complex.sin ∘ fun y : ℂ => (y * z)) _ ↑x := HasDerivAt.comp (𝕜 := ℂ) x a b have d := HasDerivAt.comp_ofReal (c.div_const z) simp only [mul_comm] at d convert d using 1 conv_rhs => arg 1; rw [mul_comm] rw [mul_div_cancel_right₀ _ hz] theorem integral_cos_sq_sub_sin_sq : ∫ x in a..b, cos x ^ 2 - sin x ^ 2 = sin b * cos b - sin a * cos a := by simpa only [sq, sub_eq_add_neg, neg_mul_eq_mul_neg] using integral_deriv_mul_eq_sub (fun x _ => hasDerivAt_sin x) (fun x _ => hasDerivAt_cos x) continuousOn_cos.intervalIntegrable continuousOn_sin.neg.intervalIntegrable theorem integral_one_div_one_add_sq : (∫ x : ℝ in a..b, ↑1 / (↑1 + x ^ 2)) = arctan b - arctan a := by refine integral_deriv_eq_sub' _ Real.deriv_arctan (fun _ _ => differentiableAt_arctan _) (continuous_const.div ?_ fun x => ?_).continuousOn · fun_prop · nlinarith @[simp] theorem integral_inv_one_add_sq : (∫ x : ℝ in a..b, (↑1 + x ^ 2)⁻¹) = arctan b - arctan a := by simp only [← one_div, integral_one_div_one_add_sq] section RpowCpow open Complex theorem integral_mul_cpow_one_add_sq {t : ℂ} (ht : t ≠ -1) : (∫ x : ℝ in a..b, (x : ℂ) * ((1 : ℂ) + ↑x ^ 2) ^ t) = ((1 : ℂ) + (b : ℂ) ^ 2) ^ (t + 1) / (2 * (t + ↑1)) - ((1 : ℂ) + (a : ℂ) ^ 2) ^ (t + 1) / (2 * (t + ↑1)) := by have : t + 1 ≠ 0 := by contrapose! ht; rwa [add_eq_zero_iff_eq_neg] at ht apply integral_eq_sub_of_hasDerivAt · intro x _ have f : HasDerivAt (fun y : ℂ => 1 + y ^ 2) (2 * x : ℂ) x := by convert (hasDerivAt_pow 2 (x : ℂ)).const_add 1 simp have g : ∀ {z : ℂ}, 0 < z.re → HasDerivAt (fun z => z ^ (t + 1) / (2 * (t + 1))) (z ^ t / 2) z := by intro z hz convert (HasDerivAt.cpow_const (c := t + 1) (hasDerivAt_id _) (Or.inl hz)).div_const (2 * (t + 1)) using 1 field_simp ring convert (HasDerivAt.comp (↑x) (g _) f).comp_ofReal using 1 · field_simp; ring · exact mod_cast add_pos_of_pos_of_nonneg zero_lt_one (sq_nonneg x) · apply Continuous.intervalIntegrable refine continuous_ofReal.mul ?_ apply Continuous.cpow · exact continuous_const.add (continuous_ofReal.pow 2) · exact continuous_const · intro a norm_cast exact ofReal_mem_slitPlane.2 <| add_pos_of_pos_of_nonneg one_pos <| sq_nonneg a theorem integral_mul_rpow_one_add_sq {t : ℝ} (ht : t ≠ -1) : (∫ x : ℝ in a..b, x * (↑1 + x ^ 2) ^ t) = (↑1 + b ^ 2) ^ (t + 1) / (↑2 * (t + ↑1)) - (↑1 + a ^ 2) ^ (t + 1) / (↑2 * (t + ↑1)) := by have : ∀ x s : ℝ, (((↑1 + x ^ 2) ^ s : ℝ) : ℂ) = (1 + (x : ℂ) ^ 2) ^ (s : ℂ) := by intro x s norm_cast rw [ofReal_cpow, ofReal_add, ofReal_pow, ofReal_one] exact add_nonneg zero_le_one (sq_nonneg x) rw [← ofReal_inj] convert integral_mul_cpow_one_add_sq (_ : (t : ℂ) ≠ -1) · rw [← intervalIntegral.integral_ofReal] congr with x : 1 rw [ofReal_mul, this x t] · simp_rw [ofReal_sub, ofReal_div, this a (t + 1), this b (t + 1)] push_cast; rfl · rw [← ofReal_one, ← ofReal_neg, Ne, ofReal_inj] exact ht end RpowCpow open Nat /-! ### Integral of `sin x ^ n` -/ theorem integral_sin_pow_aux : (∫ x in a..b, sin x ^ (n + 2)) = (sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b + (↑n + 1) * ∫ x in a..b, sin x ^ n) - (↑n + 1) * ∫ x in a..b, sin x ^ (n + 2) := by let C := sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b have h : ∀ α β γ : ℝ, β * α * γ * α = β * (α * α * γ) := fun α β γ => by ring have hu : ∀ x ∈ [[a, b]], HasDerivAt (fun y => sin y ^ (n + 1)) ((n + 1 : ℕ) * cos x * sin x ^ n) x := fun x _ => by simpa only [mul_right_comm] using (hasDerivAt_sin x).pow (n + 1) have hv : ∀ x ∈ [[a, b]], HasDerivAt (-cos) (sin x) x := fun x _ => by simpa only [neg_neg] using (hasDerivAt_cos x).neg have H := integral_mul_deriv_eq_deriv_mul hu hv ?_ ?_ · calc (∫ x in a..b, sin x ^ (n + 2)) = ∫ x in a..b, sin x ^ (n + 1) * sin x := by simp only [_root_.pow_succ] _ = C + (↑n + 1) * ∫ x in a..b, cos x ^ 2 * sin x ^ n := by simp [H, h, sq]; ring _ = C + (↑n + 1) * ∫ x in a..b, sin x ^ n - sin x ^ (n + 2) := by simp [cos_sq', sub_mul, ← pow_add, add_comm] _ = (C + (↑n + 1) * ∫ x in a..b, sin x ^ n) - (↑n + 1) * ∫ x in a..b, sin x ^ (n + 2) := by rw [integral_sub, mul_sub, add_sub_assoc] <;> apply Continuous.intervalIntegrable <;> fun_prop all_goals apply Continuous.intervalIntegrable; fun_prop /-- The reduction formula for the integral of `sin x ^ n` for any natural `n ≥ 2`. -/ theorem integral_sin_pow : (∫ x in a..b, sin x ^ (n + 2)) = (sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b) / (n + 2) + (n + 1) / (n + 2) * ∫ x in a..b, sin x ^ n := by field_simp convert eq_sub_iff_add_eq.mp (integral_sin_pow_aux n) using 1 ring @[simp] theorem integral_sin_sq : ∫ x in a..b, sin x ^ 2 = (sin a * cos a - sin b * cos b + b - a) / 2 := by field_simp [integral_sin_pow, add_sub_assoc] theorem integral_sin_pow_odd : (∫ x in (0)..π, sin x ^ (2 * n + 1)) = 2 * ∏ i ∈ range n, (2 * (i : ℝ) + 2) / (2 * i + 3) := by induction' n with k ih; · norm_num rw [prod_range_succ_comm, mul_left_comm, ← ih, mul_succ, integral_sin_pow] norm_cast simp [-cast_add, field_simps] theorem integral_sin_pow_even : (∫ x in (0)..π, sin x ^ (2 * n)) = π * ∏ i ∈ range n, (2 * (i : ℝ) + 1) / (2 * i + 2) := by induction' n with k ih; · simp rw [prod_range_succ_comm, mul_left_comm, ← ih, mul_succ, integral_sin_pow] norm_cast simp [-cast_add, field_simps] theorem integral_sin_pow_pos : 0 < ∫ x in (0)..π, sin x ^ n := by rcases even_or_odd' n with ⟨k, rfl | rfl⟩ <;> simp only [integral_sin_pow_even, integral_sin_pow_odd] <;> refine mul_pos (by norm_num [pi_pos]) (prod_pos fun n _ => div_pos ?_ ?_) <;> norm_cast <;> omega theorem integral_sin_pow_succ_le : (∫ x in (0)..π, sin x ^ (n + 1)) ≤ ∫ x in (0)..π, sin x ^ n := by let H x h := pow_le_pow_of_le_one (sin_nonneg_of_mem_Icc h) (sin_le_one x) (n.le_add_right 1) refine integral_mono_on pi_pos.le ?_ ?_ H <;> exact (continuous_sin.pow _).intervalIntegrable 0 π theorem integral_sin_pow_antitone : Antitone fun n : ℕ => ∫ x in (0)..π, sin x ^ n := antitone_nat_of_succ_le integral_sin_pow_succ_le /-! ### Integral of `cos x ^ n` -/ theorem integral_cos_pow_aux : (∫ x in a..b, cos x ^ (n + 2)) = (cos b ^ (n + 1) * sin b - cos a ^ (n + 1) * sin a + (n + 1) * ∫ x in a..b, cos x ^ n) - (n + 1) * ∫ x in a..b, cos x ^ (n + 2) := by let C := cos b ^ (n + 1) * sin b - cos a ^ (n + 1) * sin a have h : ∀ α β γ : ℝ, β * α * γ * α = β * (α * α * γ) := fun α β γ => by ring have hu : ∀ x ∈ [[a, b]], HasDerivAt (fun y => cos y ^ (n + 1)) (-(n + 1 : ℕ) * sin x * cos x ^ n) x := fun x _ => by simpa only [mul_right_comm, neg_mul, mul_neg] using (hasDerivAt_cos x).pow (n + 1) have hv : ∀ x ∈ [[a, b]], HasDerivAt sin (cos x) x := fun x _ => hasDerivAt_sin x have H := integral_mul_deriv_eq_deriv_mul hu hv ?_ ?_ · calc (∫ x in a..b, cos x ^ (n + 2)) = ∫ x in a..b, cos x ^ (n + 1) * cos x := by simp only [_root_.pow_succ] _ = C + (n + 1) * ∫ x in a..b, sin x ^ 2 * cos x ^ n := by simp [C, H, h, sq, -neg_add_rev] _ = C + (n + 1) * ∫ x in a..b, cos x ^ n - cos x ^ (n + 2) := by simp [sin_sq, sub_mul, ← pow_add, add_comm] _ = (C + (n + 1) * ∫ x in a..b, cos x ^ n) - (n + 1) * ∫ x in a..b, cos x ^ (n + 2) := by rw [integral_sub, mul_sub, add_sub_assoc] <;> apply Continuous.intervalIntegrable <;> fun_prop all_goals apply Continuous.intervalIntegrable; fun_prop /-- The reduction formula for the integral of `cos x ^ n` for any natural `n ≥ 2`. -/ theorem integral_cos_pow : (∫ x in a..b, cos x ^ (n + 2)) = (cos b ^ (n + 1) * sin b - cos a ^ (n + 1) * sin a) / (n + 2) + (n + 1) / (n + 2) * ∫ x in a..b, cos x ^ n := by field_simp convert eq_sub_iff_add_eq.mp (integral_cos_pow_aux n) using 1 ring @[simp] theorem integral_cos_sq : ∫ x in a..b, cos x ^ 2 = (cos b * sin b - cos a * sin a + b - a) / 2 := by field_simp [integral_cos_pow, add_sub_assoc] /-! ### Integral of `sin x ^ m * cos x ^ n` -/ /-- Simplification of the integral of `sin x ^ m * cos x ^ n`, case `n` is odd. -/ theorem integral_sin_pow_mul_cos_pow_odd (m n : ℕ) : (∫ x in a..b, sin x ^ m * cos x ^ (2 * n + 1)) = ∫ u in sin a..sin b, u^m * (↑1 - u ^ 2) ^ n := have hc : Continuous fun u : ℝ => u ^ m * (↑1 - u ^ 2) ^ n := by fun_prop calc (∫ x in a..b, sin x ^ m * cos x ^ (2 * n + 1)) = ∫ x in a..b, sin x ^ m * (↑1 - sin x ^ 2) ^ n * cos x := by simp only [_root_.pow_zero, _root_.pow_succ, mul_assoc, pow_mul, one_mul] congr! 5 rw [← sq, ← sq, cos_sq'] _ = ∫ u in sin a..sin b, u ^ m * (1 - u ^ 2) ^ n := by -- Note(kmill): Didn't need `by exact`, but elaboration order seems to matter here. exact integral_comp_mul_deriv (fun x _ => hasDerivAt_sin x) continuousOn_cos hc /-- The integral of `sin x * cos x`, given in terms of sin². See `integral_sin_mul_cos₂` below for the integral given in terms of cos². -/ @[simp] theorem integral_sin_mul_cos₁ : ∫ x in a..b, sin x * cos x = (sin b ^ 2 - sin a ^ 2) / 2 := by simpa using integral_sin_pow_mul_cos_pow_odd 1 0 @[simp] theorem integral_sin_sq_mul_cos : ∫ x in a..b, sin x ^ 2 * cos x = (sin b ^ 3 - sin a ^ 3) / 3 := by have := @integral_sin_pow_mul_cos_pow_odd a b 2 0 norm_num at this; exact this @[simp] theorem integral_cos_pow_three : ∫ x in a..b, cos x ^ 3 = sin b - sin a - (sin b ^ 3 - sin a ^ 3) / 3 := by have := @integral_sin_pow_mul_cos_pow_odd a b 0 1 norm_num at this; exact this /-- Simplification of the integral of `sin x ^ m * cos x ^ n`, case `m` is odd. -/ theorem integral_sin_pow_odd_mul_cos_pow (m n : ℕ) : (∫ x in a..b, sin x ^ (2 * m + 1) * cos x ^ n) = ∫ u in cos b..cos a, u^n * (↑1 - u ^ 2) ^ m := have hc : Continuous fun u : ℝ => u ^ n * (↑1 - u ^ 2) ^ m := by fun_prop calc (∫ x in a..b, sin x ^ (2 * m + 1) * cos x ^ n) = -∫ x in b..a, sin x ^ (2 * m + 1) * cos x ^ n := by rw [integral_symm] _ = ∫ x in b..a, (↑1 - cos x ^ 2) ^ m * -sin x * cos x ^ n := by simp only [_root_.pow_succ, pow_mul, _root_.pow_zero, one_mul, mul_neg, neg_mul, integral_neg, neg_inj] congr! 5 rw [← sq, ← sq, sin_sq] _ = ∫ x in b..a, cos x ^ n * (↑1 - cos x ^ 2) ^ m * -sin x := by congr; ext; ring _ = ∫ u in cos b..cos a, u ^ n * (↑1 - u ^ 2) ^ m := integral_comp_mul_deriv (fun x _ => hasDerivAt_cos x) continuousOn_sin.neg hc /-- The integral of `sin x * cos x`, given in terms of cos². See `integral_sin_mul_cos₁` above for the integral given in terms of sin². -/ theorem integral_sin_mul_cos₂ : ∫ x in a..b, sin x * cos x = (cos a ^ 2 - cos b ^ 2) / 2 := by simpa using integral_sin_pow_odd_mul_cos_pow 0 1 @[simp] theorem integral_sin_mul_cos_sq : ∫ x in a..b, sin x * cos x ^ 2 = (cos a ^ 3 - cos b ^ 3) / 3 := by have := @integral_sin_pow_odd_mul_cos_pow a b 0 2 norm_num at this; exact this @[simp] theorem integral_sin_pow_three : ∫ x in a..b, sin x ^ 3 = cos a - cos b - (cos a ^ 3 - cos b ^ 3) / 3 := by have := @integral_sin_pow_odd_mul_cos_pow a b 1 0 norm_num at this; exact this /-- Simplification of the integral of `sin x ^ m * cos x ^ n`, case `m` and `n` are both even. -/ theorem integral_sin_pow_even_mul_cos_pow_even (m n : ℕ) : (∫ x in a..b, sin x ^ (2 * m) * cos x ^ (2 * n)) = ∫ x in a..b, ((1 - cos (2 * x)) / 2) ^ m * ((1 + cos (2 * x)) / 2) ^ n := by field_simp [pow_mul, sin_sq, cos_sq, ← sub_sub, (by ring : (2 : ℝ) - 1 = 1)] @[simp] theorem integral_sin_sq_mul_cos_sq : ∫ x in a..b, sin x ^ 2 * cos x ^ 2 = (b - a) / 8 - (sin (4 * b) - sin (4 * a)) / 32 := by convert integral_sin_pow_even_mul_cos_pow_even 1 1 using 1 have h1 : ∀ c : ℝ, (↑1 - c) / ↑2 * ((↑1 + c) / ↑2) = (↑1 - c ^ 2) / 4 := fun c => by ring have h2 : Continuous fun x => cos (2 * x) ^ 2 := by fun_prop have h3 : ∀ x, cos x * sin x = sin (2 * x) / 2 := by intro; rw [sin_two_mul]; ring have h4 : ∀ d : ℝ, 2 * (2 * d) = 4 * d := fun d => by ring simp [h1, h2.intervalIntegrable, integral_comp_mul_left fun x => cos x ^ 2, h3, h4] ring /-! ### Integral of miscellaneous functions -/ theorem integral_sqrt_one_sub_sq : ∫ x in (-1 : ℝ)..1, √(1 - x ^ 2 : ℝ) = π / 2 := calc _ = ∫ x in sin (-(π / 2)).. sin (π / 2), √(1 - x ^ 2 : ℝ) := by rw [sin_neg, sin_pi_div_two] _ = ∫ x in (-(π / 2))..(π / 2), √(1 - sin x ^ 2 : ℝ) * cos x := (integral_comp_mul_deriv (fun x _ => hasDerivAt_sin x) continuousOn_cos (by fun_prop)).symm _ = ∫ x in (-(π / 2))..(π / 2), cos x ^ 2 := by refine integral_congr_ae (MeasureTheory.ae_of_all _ fun _ h => ?_) rw [uIoc_of_le (neg_le_self (le_of_lt (half_pos Real.pi_pos))), Set.mem_Ioc] at h rw [← Real.cos_eq_sqrt_one_sub_sin_sq (le_of_lt h.1) h.2, pow_two] _ = π / 2 := by simp
Mathlib/Analysis/SpecialFunctions/Integrals.lean
833
836
/- 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, Johannes Hölzl, Rémy Degenne -/ import Mathlib.Order.ConditionallyCompleteLattice.Indexed import Mathlib.Order.Filter.IsBounded import Mathlib.Order.Hom.CompleteLattice /-! # liminfs and limsups of functions and filters Defines the liminf/limsup of a function taking values in a conditionally complete lattice, with respect to an arbitrary filter. We define `limsSup f` (`limsInf f`) where `f` is a filter taking values in a conditionally complete lattice. `limsSup f` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for `limsInf f`). To work with the Limsup along a function `u` use `limsSup (map u f)`. Usually, one defines the Limsup as `inf (sup s)` where the Inf is taken over all sets in the filter. For instance, in ℕ along a function `u`, this is `inf_n (sup_{k ≥ n} u k)` (and the latter quantity decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible that `u` is not bounded on the whole space, only eventually (think of `limsup (fun x ↦ 1/x)` on ℝ. Then there is no guarantee that the quantity above really decreases (the value of the `sup` beforehand is not really well defined, as one can not use ∞), so that the Inf could be anything. So one can not use this `inf sup ...` definition in conditionally complete lattices, and one has to use a less tractable definition. In conditionally complete lattices, the definition is only useful for filters which are eventually bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the space either). We start with definitions of these concepts for arbitrary filters, before turning to the definitions of Limsup and Liminf. In complete lattices, however, it coincides with the `Inf Sup` definition. -/ open Filter Set Function variable {α β γ ι ι' : Type*} namespace Filter section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] {s : Set α} {u : β → α} /-- The `limsSup` of a filter `f` is the infimum of the `a` such that, eventually for `f`, holds `x ≤ a`. -/ def limsSup (f : Filter α) : α := sInf { a | ∀ᶠ n in f, n ≤ a } /-- The `limsInf` of a filter `f` is the supremum of the `a` such that, eventually for `f`, holds `x ≥ a`. -/ def limsInf (f : Filter α) : α := sSup { a | ∀ᶠ n in f, a ≤ n } /-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that, eventually for `f`, holds `u x ≤ a`. -/ def limsup (u : β → α) (f : Filter β) : α := limsSup (map u f) /-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that, eventually for `f`, holds `u x ≥ a`. -/ def liminf (u : β → α) (f : Filter β) : α := limsInf (map u f) /-- The `blimsup` of a function `u` along a filter `f`, bounded by a predicate `p`, is the infimum of the `a` such that, eventually for `f`, `u x ≤ a` whenever `p x` holds. -/ def blimsup (u : β → α) (f : Filter β) (p : β → Prop) := sInf { a | ∀ᶠ x in f, p x → u x ≤ a } /-- The `bliminf` of a function `u` along a filter `f`, bounded by a predicate `p`, is the supremum of the `a` such that, eventually for `f`, `a ≤ u x` whenever `p x` holds. -/ def bliminf (u : β → α) (f : Filter β) (p : β → Prop) := sSup { a | ∀ᶠ x in f, p x → a ≤ u x } section variable {f : Filter β} {u : β → α} {p : β → Prop} theorem limsup_eq : limsup u f = sInf { a | ∀ᶠ n in f, u n ≤ a } := rfl theorem liminf_eq : liminf u f = sSup { a | ∀ᶠ n in f, a ≤ u n } := rfl theorem blimsup_eq : blimsup u f p = sInf { a | ∀ᶠ x in f, p x → u x ≤ a } := rfl theorem bliminf_eq : bliminf u f p = sSup { a | ∀ᶠ x in f, p x → a ≤ u x } := rfl lemma liminf_comp (u : β → α) (v : γ → β) (f : Filter γ) : liminf (u ∘ v) f = liminf u (map v f) := rfl lemma limsup_comp (u : β → α) (v : γ → β) (f : Filter γ) : limsup (u ∘ v) f = limsup u (map v f) := rfl end @[simp] theorem blimsup_true (f : Filter β) (u : β → α) : (blimsup u f fun _ => True) = limsup u f := by simp [blimsup_eq, limsup_eq] @[simp] theorem bliminf_true (f : Filter β) (u : β → α) : (bliminf u f fun _ => True) = liminf u f := by simp [bliminf_eq, liminf_eq] lemma blimsup_eq_limsup {f : Filter β} {u : β → α} {p : β → Prop} : blimsup u f p = limsup u (f ⊓ 𝓟 {x | p x}) := by simp only [blimsup_eq, limsup_eq, eventually_inf_principal, mem_setOf_eq] lemma bliminf_eq_liminf {f : Filter β} {u : β → α} {p : β → Prop} : bliminf u f p = liminf u (f ⊓ 𝓟 {x | p x}) := blimsup_eq_limsup (α := αᵒᵈ) theorem blimsup_eq_limsup_subtype {f : Filter β} {u : β → α} {p : β → Prop} : blimsup u f p = limsup (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := by rw [blimsup_eq_limsup, limsup, limsup, ← map_map, map_comap_setCoe_val] theorem bliminf_eq_liminf_subtype {f : Filter β} {u : β → α} {p : β → Prop} : bliminf u f p = liminf (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := blimsup_eq_limsup_subtype (α := αᵒᵈ) theorem limsSup_le_of_le {f : Filter α} {a} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (h : ∀ᶠ n in f, n ≤ a) : limsSup f ≤ a := csInf_le hf h theorem le_limsInf_of_le {f : Filter α} {a} (hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : ∀ᶠ n in f, a ≤ n) : a ≤ limsInf f := le_csSup hf h theorem limsup_le_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h : ∀ᶠ n in f, u n ≤ a) : limsup u f ≤ a := csInf_le hf h theorem le_liminf_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h : ∀ᶠ n in f, a ≤ u n) : a ≤ liminf u f := le_csSup hf h theorem le_limsSup_of_le {f : Filter α} {a} (hf : f.IsBounded (· ≤ ·) := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) : a ≤ limsSup f := le_csInf hf h theorem limsInf_le_of_le {f : Filter α} {a} (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) : limsInf f ≤ a := csSup_le hf h theorem le_limsup_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, u n ≤ b) → a ≤ b) : a ≤ limsup u f := le_csInf hf h theorem liminf_le_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, b ≤ u n) → b ≤ a) : liminf u f ≤ a := csSup_le hf h theorem limsInf_le_limsSup {f : Filter α} [NeBot f] (h₁ : f.IsBounded (· ≤ ·) := by isBoundedDefault) (h₂ : f.IsBounded (· ≥ ·) := by isBoundedDefault) : limsInf f ≤ limsSup f := liminf_le_of_le h₂ fun a₀ ha₀ => le_limsup_of_le h₁ fun a₁ ha₁ => show a₀ ≤ a₁ from let ⟨_, hb₀, hb₁⟩ := (ha₀.and ha₁).exists le_trans hb₀ hb₁ theorem liminf_le_limsup {f : Filter β} [NeBot f] {u : β → α} (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ limsup u f := limsInf_le_limsSup h h' theorem limsSup_le_limsSup {f g : Filter α} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) (h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : limsSup f ≤ limsSup g := csInf_le_csInf hf hg h theorem limsInf_le_limsInf {f g : Filter α} (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : limsInf f ≤ limsInf g := csSup_le_csSup hg hf h theorem limsup_le_limsup {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : u ≤ᶠ[f] v) (hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hv : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) : limsup u f ≤ limsup v f := limsSup_le_limsSup hu hv fun _ => h.trans theorem liminf_le_liminf {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a ≤ v a) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hv : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault) : liminf u f ≤ liminf v f := limsup_le_limsup (β := βᵒᵈ) h hv hu theorem limsSup_le_limsSup_of_le {f g : Filter α} (h : f ≤ g) (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) : limsSup f ≤ limsSup g := limsSup_le_limsSup hf hg fun _ ha => h ha theorem limsInf_le_limsInf_of_le {f g : Filter α} (h : g ≤ f) (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) : limsInf f ≤ limsInf g := limsInf_le_limsInf hf hg fun _ ha => h ha theorem limsup_le_limsup_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : f ≤ g) {u : α → β} (hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hg : g.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : limsup u f ≤ limsup u g := limsSup_le_limsSup_of_le (map_mono h) hf hg theorem liminf_le_liminf_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : g ≤ f) {u : α → β} (hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hg : g.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ liminf u g := limsInf_le_limsInf_of_le (map_mono h) hf hg lemma limsSup_principal_eq_csSup (h : BddAbove s) (hs : s.Nonempty) : limsSup (𝓟 s) = sSup s := by simp only [limsSup, eventually_principal]; exact csInf_upperBounds_eq_csSup h hs lemma limsInf_principal_eq_csSup (h : BddBelow s) (hs : s.Nonempty) : limsInf (𝓟 s) = sInf s := limsSup_principal_eq_csSup (α := αᵒᵈ) h hs lemma limsup_top_eq_ciSup [Nonempty β] (hu : BddAbove (range u)) : limsup u ⊤ = ⨆ i, u i := by rw [limsup, map_top, limsSup_principal_eq_csSup hu (range_nonempty _), sSup_range] lemma liminf_top_eq_ciInf [Nonempty β] (hu : BddBelow (range u)) : liminf u ⊤ = ⨅ i, u i := by rw [liminf, map_top, limsInf_principal_eq_csSup hu (range_nonempty _), sInf_range] theorem limsup_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a = v a) : limsup u f = limsup v f := by rw [limsup_eq] congr with b exact eventually_congr (h.mono fun x hx => by simp [hx]) theorem blimsup_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) : blimsup u f p = blimsup v f p := by simpa only [blimsup_eq_limsup] using limsup_congr <| eventually_inf_principal.2 h theorem bliminf_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) : bliminf u f p = bliminf v f p := blimsup_congr (α := αᵒᵈ) h theorem liminf_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a = v a) : liminf u f = liminf v f := limsup_congr (β := βᵒᵈ) h @[simp] theorem limsup_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f] (b : β) : limsup (fun _ => b) f = b := by simpa only [limsup_eq, eventually_const] using csInf_Ici @[simp] theorem liminf_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f] (b : β) : liminf (fun _ => b) f = b := limsup_const (β := βᵒᵈ) b theorem HasBasis.liminf_eq_sSup_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) : liminf f v = sSup (⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i)) := by simp_rw [liminf_eq, hv.eventually_iff] congr ext x simp only [mem_setOf_eq, iInter_coe_set, mem_iUnion, mem_iInter, mem_Iic, Subtype.exists, exists_prop] theorem HasBasis.liminf_eq_sSup_univ_of_empty {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) : liminf f v = sSup univ := by simp [hv.eq_bot_iff.2 ⟨i, hi, h'i⟩, liminf_eq] theorem HasBasis.limsup_eq_sInf_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) : limsup f v = sInf (⋃ (j : Subtype p), ⋂ (i : s j), Ici (f i)) := HasBasis.liminf_eq_sSup_iUnion_iInter (α := αᵒᵈ) hv theorem HasBasis.limsup_eq_sInf_univ_of_empty {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) : limsup f v = sInf univ := HasBasis.liminf_eq_sSup_univ_of_empty (α := αᵒᵈ) hv i hi h'i @[simp] theorem liminf_nat_add (f : ℕ → α) (k : ℕ) : liminf (fun i => f (i + k)) atTop = liminf f atTop := by rw [← Function.comp_def, liminf, liminf, ← map_map, map_add_atTop_eq_nat] @[simp] theorem limsup_nat_add (f : ℕ → α) (k : ℕ) : limsup (fun i => f (i + k)) atTop = limsup f atTop := @liminf_nat_add αᵒᵈ _ f k end ConditionallyCompleteLattice section CompleteLattice variable [CompleteLattice α] @[simp] theorem limsSup_bot : limsSup (⊥ : Filter α) = ⊥ := bot_unique <| sInf_le <| by simp @[simp] theorem limsup_bot (f : β → α) : limsup f ⊥ = ⊥ := by simp [limsup] @[simp] theorem limsInf_bot : limsInf (⊥ : Filter α) = ⊤ := top_unique <| le_sSup <| by simp @[simp] theorem liminf_bot (f : β → α) : liminf f ⊥ = ⊤ := by simp [liminf] @[simp] theorem limsSup_top : limsSup (⊤ : Filter α) = ⊤ := top_unique <| le_sInf <| by simpa [eq_univ_iff_forall] using fun b hb => top_unique <| hb _ @[simp] theorem limsInf_top : limsInf (⊤ : Filter α) = ⊥ := bot_unique <| sSup_le <| by simpa [eq_univ_iff_forall] using fun b hb => bot_unique <| hb _ @[simp] theorem blimsup_false {f : Filter β} {u : β → α} : (blimsup u f fun _ => False) = ⊥ := by simp [blimsup_eq] @[simp] theorem bliminf_false {f : Filter β} {u : β → α} : (bliminf u f fun _ => False) = ⊤ := by simp [bliminf_eq] /-- Same as limsup_const applied to `⊥` but without the `NeBot f` assumption -/ @[simp] theorem limsup_const_bot {f : Filter β} : limsup (fun _ : β => (⊥ : α)) f = (⊥ : α) := by rw [limsup_eq, eq_bot_iff] exact sInf_le (Eventually.of_forall fun _ => le_rfl) /-- Same as limsup_const applied to `⊤` but without the `NeBot f` assumption -/ @[simp] theorem liminf_const_top {f : Filter β} : liminf (fun _ : β => (⊤ : α)) f = (⊤ : α) := limsup_const_bot (α := αᵒᵈ) theorem HasBasis.limsSup_eq_iInf_sSup {ι} {p : ι → Prop} {s} {f : Filter α} (h : f.HasBasis p s) : limsSup f = ⨅ (i) (_ : p i), sSup (s i) := le_antisymm (le_iInf₂ fun i hi => sInf_le <| h.eventually_iff.2 ⟨i, hi, fun _ => le_sSup⟩) (le_sInf fun _ ha => let ⟨_, hi, ha⟩ := h.eventually_iff.1 ha iInf₂_le_of_le _ hi <| sSup_le ha) theorem HasBasis.limsInf_eq_iSup_sInf {p : ι → Prop} {s : ι → Set α} {f : Filter α} (h : f.HasBasis p s) : limsInf f = ⨆ (i) (_ : p i), sInf (s i) := HasBasis.limsSup_eq_iInf_sSup (α := αᵒᵈ) h theorem limsSup_eq_iInf_sSup {f : Filter α} : limsSup f = ⨅ s ∈ f, sSup s := f.basis_sets.limsSup_eq_iInf_sSup theorem limsInf_eq_iSup_sInf {f : Filter α} : limsInf f = ⨆ s ∈ f, sInf s := limsSup_eq_iInf_sSup (α := αᵒᵈ) theorem limsup_le_iSup {f : Filter β} {u : β → α} : limsup u f ≤ ⨆ n, u n := limsup_le_of_le (by isBoundedDefault) (Eventually.of_forall (le_iSup u)) theorem iInf_le_liminf {f : Filter β} {u : β → α} : ⨅ n, u n ≤ liminf u f := le_liminf_of_le (by isBoundedDefault) (Eventually.of_forall (iInf_le u)) /-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter of the supremum of the function over `s` -/ theorem limsup_eq_iInf_iSup {f : Filter β} {u : β → α} : limsup u f = ⨅ s ∈ f, ⨆ a ∈ s, u a := (f.basis_sets.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id] theorem limsup_eq_iInf_iSup_of_nat {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i ≥ n, u i := (atTop_basis.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, iInf_const]; rfl theorem limsup_eq_iInf_iSup_of_nat' {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i : ℕ, u (i + n) := by simp only [limsup_eq_iInf_iSup_of_nat, iSup_ge_eq_iSup_nat_add] theorem HasBasis.limsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (h : f.HasBasis p s) : limsup u f = ⨅ (i) (_ : p i), ⨆ a ∈ s i, u a := (h.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id] lemma limsSup_principal_eq_sSup (s : Set α) : limsSup (𝓟 s) = sSup s := by simpa only [limsSup, eventually_principal] using sInf_upperBounds_eq_csSup s lemma limsInf_principal_eq_sInf (s : Set α) : limsInf (𝓟 s) = sInf s := by simpa only [limsInf, eventually_principal] using sSup_lowerBounds_eq_sInf s @[simp] lemma limsup_top_eq_iSup (u : β → α) : limsup u ⊤ = ⨆ i, u i := by rw [limsup, map_top, limsSup_principal_eq_sSup, sSup_range] @[simp] lemma liminf_top_eq_iInf (u : β → α) : liminf u ⊤ = ⨅ i, u i := by rw [liminf, map_top, limsInf_principal_eq_sInf, sInf_range] theorem blimsup_congr' {f : Filter β} {p q : β → Prop} {u : β → α} (h : ∀ᶠ x in f, u x ≠ ⊥ → (p x ↔ q x)) : blimsup u f p = blimsup u f q := by simp only [blimsup_eq] congr with a refine eventually_congr (h.mono fun b hb => ?_) rcases eq_or_ne (u b) ⊥ with hu | hu; · simp [hu] rw [hb hu] theorem bliminf_congr' {f : Filter β} {p q : β → Prop} {u : β → α} (h : ∀ᶠ x in f, u x ≠ ⊤ → (p x ↔ q x)) : bliminf u f p = bliminf u f q := blimsup_congr' (α := αᵒᵈ) h lemma HasBasis.blimsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (hf : f.HasBasis p s) {q : β → Prop} : blimsup u f q = ⨅ (i) (_ : p i), ⨆ a ∈ s i, ⨆ (_ : q a), u a := by simp only [blimsup_eq_limsup, (hf.inf_principal _).limsup_eq_iInf_iSup, mem_inter_iff, iSup_and, mem_setOf_eq] theorem blimsup_eq_iInf_biSup {f : Filter β} {p : β → Prop} {u : β → α} : blimsup u f p = ⨅ s ∈ f, ⨆ (b) (_ : p b ∧ b ∈ s), u b := by simp only [f.basis_sets.blimsup_eq_iInf_iSup, iSup_and', id, and_comm] theorem blimsup_eq_iInf_biSup_of_nat {p : ℕ → Prop} {u : ℕ → α} : blimsup u atTop p = ⨅ i, ⨆ (j) (_ : p j ∧ i ≤ j), u j := by simp only [atTop_basis.blimsup_eq_iInf_iSup, @and_comm (p _), iSup_and, mem_Ici, iInf_true] /-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter of the supremum of the function over `s` -/ theorem liminf_eq_iSup_iInf {f : Filter β} {u : β → α} : liminf u f = ⨆ s ∈ f, ⨅ a ∈ s, u a := limsup_eq_iInf_iSup (α := αᵒᵈ) theorem liminf_eq_iSup_iInf_of_nat {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i ≥ n, u i := @limsup_eq_iInf_iSup_of_nat αᵒᵈ _ u theorem liminf_eq_iSup_iInf_of_nat' {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i : ℕ, u (i + n) := @limsup_eq_iInf_iSup_of_nat' αᵒᵈ _ _ theorem HasBasis.liminf_eq_iSup_iInf {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (h : f.HasBasis p s) : liminf u f = ⨆ (i) (_ : p i), ⨅ a ∈ s i, u a := HasBasis.limsup_eq_iInf_iSup (α := αᵒᵈ) h theorem bliminf_eq_iSup_biInf {f : Filter β} {p : β → Prop} {u : β → α} : bliminf u f p = ⨆ s ∈ f, ⨅ (b) (_ : p b ∧ b ∈ s), u b := @blimsup_eq_iInf_biSup αᵒᵈ β _ f p u theorem bliminf_eq_iSup_biInf_of_nat {p : ℕ → Prop} {u : ℕ → α} : bliminf u atTop p = ⨆ i, ⨅ (j) (_ : p j ∧ i ≤ j), u j := @blimsup_eq_iInf_biSup_of_nat αᵒᵈ _ p u theorem limsup_eq_sInf_sSup {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) : limsup a F = sInf ((fun I => sSup (a '' I)) '' F.sets) := by apply le_antisymm · rw [limsup_eq] refine sInf_le_sInf fun x hx => ?_ rcases (mem_image _ F.sets x).mp hx with ⟨I, ⟨I_mem_F, hI⟩⟩ filter_upwards [I_mem_F] with i hi exact hI ▸ le_sSup (mem_image_of_mem _ hi) · refine le_sInf fun b hb => sInf_le_of_le (mem_image_of_mem _ hb) <| sSup_le ?_ rintro _ ⟨_, h, rfl⟩ exact h theorem liminf_eq_sSup_sInf {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) : liminf a F = sSup ((fun I => sInf (a '' I)) '' F.sets) := @Filter.limsup_eq_sInf_sSup ι (OrderDual R) _ _ a theorem liminf_le_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, u a ≤ x) : liminf u f ≤ x := by rw [liminf_eq] refine sSup_le fun b hb => ?_ have hbx : ∃ᶠ _ in f, b ≤ x := by revert h rw [← not_imp_not, not_frequently, not_frequently] exact fun h => hb.mp (h.mono fun a hbx hba hax => hbx (hba.trans hax)) exact hbx.exists.choose_spec theorem le_limsup_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, x ≤ u a) : x ≤ limsup u f := liminf_le_of_frequently_le' (β := βᵒᵈ) h /-- If `f : α → α` is a morphism of complete lattices, then the limsup of its iterates of any `a : α` is a fixed point. -/ @[simp] theorem _root_.CompleteLatticeHom.apply_limsup_iterate (f : CompleteLatticeHom α α) (a : α) : f (limsup (fun n => f^[n] a) atTop) = limsup (fun n => f^[n] a) atTop := by rw [limsup_eq_iInf_iSup_of_nat', map_iInf] simp_rw [_root_.map_iSup, ← Function.comp_apply (f := f), ← Function.iterate_succ' f, ← Nat.add_succ] conv_rhs => rw [iInf_split _ (0 < ·)] simp only [not_lt, Nat.le_zero, iInf_iInf_eq_left, add_zero, iInf_nat_gt_zero_eq, left_eq_inf] refine (iInf_le (fun i => ⨆ j, f^[j + (i + 1)] a) 0).trans ?_ simp only [zero_add, Function.comp_apply, iSup_le_iff] exact fun i => le_iSup (fun i => f^[i] a) (i + 1) /-- If `f : α → α` is a morphism of complete lattices, then the liminf of its iterates of any `a : α` is a fixed point. -/ theorem _root_.CompleteLatticeHom.apply_liminf_iterate (f : CompleteLatticeHom α α) (a : α) : f (liminf (fun n => f^[n] a) atTop) = liminf (fun n => f^[n] a) atTop := (CompleteLatticeHom.dual f).apply_limsup_iterate _ variable {f g : Filter β} {p q : β → Prop} {u v : β → α} theorem blimsup_mono (h : ∀ x, p x → q x) : blimsup u f p ≤ blimsup u f q := sInf_le_sInf fun a ha => ha.mono <| by tauto theorem bliminf_antitone (h : ∀ x, p x → q x) : bliminf u f q ≤ bliminf u f p := sSup_le_sSup fun a ha => ha.mono <| by tauto theorem mono_blimsup' (h : ∀ᶠ x in f, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p := sInf_le_sInf fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.2 hx').trans (hx.1 hx') theorem mono_blimsup (h : ∀ x, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p := mono_blimsup' <| Eventually.of_forall h theorem mono_bliminf' (h : ∀ᶠ x in f, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p := sSup_le_sSup fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.1 hx').trans (hx.2 hx') theorem mono_bliminf (h : ∀ x, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p := mono_bliminf' <| Eventually.of_forall h theorem bliminf_antitone_filter (h : f ≤ g) : bliminf u g p ≤ bliminf u f p := sSup_le_sSup fun _ ha => ha.filter_mono h theorem blimsup_monotone_filter (h : f ≤ g) : blimsup u f p ≤ blimsup u g p := sInf_le_sInf fun _ ha => ha.filter_mono h theorem blimsup_and_le_inf : (blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p ⊓ blimsup u f q := le_inf (blimsup_mono <| by tauto) (blimsup_mono <| by tauto) @[simp] theorem bliminf_sup_le_inf_aux_left : (blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p := blimsup_and_le_inf.trans inf_le_left @[simp] theorem bliminf_sup_le_inf_aux_right : (blimsup u f fun x => p x ∧ q x) ≤ blimsup u f q := blimsup_and_le_inf.trans inf_le_right theorem bliminf_sup_le_and : bliminf u f p ⊔ bliminf u f q ≤ bliminf u f fun x => p x ∧ q x := blimsup_and_le_inf (α := αᵒᵈ) @[simp] theorem bliminf_sup_le_and_aux_left : bliminf u f p ≤ bliminf u f fun x => p x ∧ q x := le_sup_left.trans bliminf_sup_le_and @[simp] theorem bliminf_sup_le_and_aux_right : bliminf u f q ≤ bliminf u f fun x => p x ∧ q x := le_sup_right.trans bliminf_sup_le_and /-- See also `Filter.blimsup_or_eq_sup`. -/ theorem blimsup_sup_le_or : blimsup u f p ⊔ blimsup u f q ≤ blimsup u f fun x => p x ∨ q x := sup_le (blimsup_mono <| by tauto) (blimsup_mono <| by tauto) @[simp] theorem bliminf_sup_le_or_aux_left : blimsup u f p ≤ blimsup u f fun x => p x ∨ q x := le_sup_left.trans blimsup_sup_le_or @[simp] theorem bliminf_sup_le_or_aux_right : blimsup u f q ≤ blimsup u f fun x => p x ∨ q x := le_sup_right.trans blimsup_sup_le_or /-- See also `Filter.bliminf_or_eq_inf`. -/ theorem bliminf_or_le_inf : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p ⊓ bliminf u f q := blimsup_sup_le_or (α := αᵒᵈ) @[simp] theorem bliminf_or_le_inf_aux_left : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p := bliminf_or_le_inf.trans inf_le_left @[simp] theorem bliminf_or_le_inf_aux_right : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f q := bliminf_or_le_inf.trans inf_le_right theorem _root_.OrderIso.apply_blimsup [CompleteLattice γ] (e : α ≃o γ) : e (blimsup u f p) = blimsup (e ∘ u) f p := by simp only [blimsup_eq, map_sInf, Function.comp_apply, e.image_eq_preimage, Set.preimage_setOf_eq, e.le_symm_apply] theorem _root_.OrderIso.apply_bliminf [CompleteLattice γ] (e : α ≃o γ) : e (bliminf u f p) = bliminf (e ∘ u) f p := e.dual.apply_blimsup theorem _root_.sSupHom.apply_blimsup_le [CompleteLattice γ] (g : sSupHom α γ) : g (blimsup u f p) ≤ blimsup (g ∘ u) f p := by simp only [blimsup_eq_iInf_biSup, Function.comp] refine ((OrderHomClass.mono g).map_iInf₂_le _).trans ?_ simp only [_root_.map_iSup, le_refl] theorem _root_.sInfHom.le_apply_bliminf [CompleteLattice γ] (g : sInfHom α γ) : bliminf (g ∘ u) f p ≤ g (bliminf u f p) := (sInfHom.dual g).apply_blimsup_le end CompleteLattice section CompleteDistribLattice variable [CompleteDistribLattice α] {f : Filter β} {p q : β → Prop} {u : β → α} lemma limsup_sup_filter {g} : limsup u (f ⊔ g) = limsup u f ⊔ limsup u g := by refine le_antisymm ?_ (sup_le (limsup_le_limsup_of_le le_sup_left) (limsup_le_limsup_of_le le_sup_right)) simp_rw [limsup_eq, sInf_sup_eq, sup_sInf_eq, mem_setOf_eq, le_iInf₂_iff] intro a ha b hb exact sInf_le ⟨ha.mono fun _ h ↦ h.trans le_sup_left, hb.mono fun _ h ↦ h.trans le_sup_right⟩ lemma liminf_sup_filter {g} : liminf u (f ⊔ g) = liminf u f ⊓ liminf u g := limsup_sup_filter (α := αᵒᵈ) @[simp] theorem blimsup_or_eq_sup : (blimsup u f fun x => p x ∨ q x) = blimsup u f p ⊔ blimsup u f q := by simp only [blimsup_eq_limsup, ← limsup_sup_filter, ← inf_sup_left, sup_principal, setOf_or] @[simp] theorem bliminf_or_eq_inf : (bliminf u f fun x => p x ∨ q x) = bliminf u f p ⊓ bliminf u f q := blimsup_or_eq_sup (α := αᵒᵈ) @[simp] lemma blimsup_sup_not : blimsup u f p ⊔ blimsup u f (¬p ·) = limsup u f := by simp_rw [← blimsup_or_eq_sup, or_not, blimsup_true] @[simp] lemma bliminf_inf_not : bliminf u f p ⊓ bliminf u f (¬p ·) = liminf u f := blimsup_sup_not (α := αᵒᵈ) @[simp] lemma blimsup_not_sup : blimsup u f (¬p ·) ⊔ blimsup u f p = limsup u f := by simpa only [not_not] using blimsup_sup_not (p := (¬p ·)) @[simp] lemma bliminf_not_inf : bliminf u f (¬p ·) ⊓ bliminf u f p = liminf u f := blimsup_not_sup (α := αᵒᵈ) lemma limsup_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} : limsup (s.piecewise u v) f = blimsup u f (· ∈ s) ⊔ blimsup v f (· ∉ s) := by rw [← blimsup_sup_not (p := (· ∈ s))] refine congr_arg₂ _ (blimsup_congr ?_) (blimsup_congr ?_) <;> filter_upwards with _ h using by simp [h] lemma liminf_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} : liminf (s.piecewise u v) f = bliminf u f (· ∈ s) ⊓ bliminf v f (· ∉ s) := limsup_piecewise (α := αᵒᵈ) theorem sup_limsup [NeBot f] (a : α) : a ⊔ limsup u f = limsup (fun x => a ⊔ u x) f := by simp only [limsup_eq_iInf_iSup, iSup_sup_eq, sup_iInf₂_eq] congr; ext s; congr; ext hs; congr exact (biSup_const (nonempty_of_mem hs)).symm theorem inf_liminf [NeBot f] (a : α) : a ⊓ liminf u f = liminf (fun x => a ⊓ u x) f := sup_limsup (α := αᵒᵈ) a theorem sup_liminf (a : α) : a ⊔ liminf u f = liminf (fun x => a ⊔ u x) f := by simp only [liminf_eq_iSup_iInf] rw [sup_comm, biSup_sup (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)] simp_rw [iInf₂_sup_eq, sup_comm (a := a)] theorem inf_limsup (a : α) : a ⊓ limsup u f = limsup (fun x => a ⊓ u x) f := sup_liminf (α := αᵒᵈ) a end CompleteDistribLattice section CompleteBooleanAlgebra variable [CompleteBooleanAlgebra α] (f : Filter β) (u : β → α) theorem limsup_compl : (limsup u f)ᶜ = liminf (compl ∘ u) f := by simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply] theorem liminf_compl : (liminf u f)ᶜ = limsup (compl ∘ u) f := by simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply] theorem limsup_sdiff (a : α) : limsup u f \ a = limsup (fun b => u b \ a) f := by simp only [limsup_eq_iInf_iSup, sdiff_eq] rw [biInf_inf (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)] simp_rw [inf_comm, inf_iSup₂_eq, inf_comm] theorem liminf_sdiff [NeBot f] (a : α) : liminf u f \ a = liminf (fun b => u b \ a) f := by simp only [sdiff_eq, inf_comm _ aᶜ, inf_liminf] theorem sdiff_limsup [NeBot f] (a : α) : a \ limsup u f = liminf (fun b => a \ u b) f := by rw [← compl_inj_iff] simp only [sdiff_eq, liminf_compl, comp_def, compl_inf, compl_compl, sup_limsup] theorem sdiff_liminf (a : α) : a \ liminf u f = limsup (fun b => a \ u b) f := by rw [← compl_inj_iff] simp only [sdiff_eq, limsup_compl, comp_def, compl_inf, compl_compl, sup_liminf] end CompleteBooleanAlgebra section SetLattice variable {p : ι → Prop} {s : ι → Set α} {𝓕 : Filter ι} {a : α} lemma mem_liminf_iff_eventually_mem : (a ∈ liminf s 𝓕) ↔ (∀ᶠ i in 𝓕, a ∈ s i) := by simpa only [liminf_eq_iSup_iInf, iSup_eq_iUnion, iInf_eq_iInter, mem_iUnion, mem_iInter] using ⟨fun ⟨S, hS, hS'⟩ ↦ mem_of_superset hS (by tauto), fun h ↦ ⟨{i | a ∈ s i}, h, by tauto⟩⟩ lemma mem_limsup_iff_frequently_mem : (a ∈ limsup s 𝓕) ↔ (∃ᶠ i in 𝓕, a ∈ s i) := by simp only [Filter.Frequently, iff_not_comm, ← mem_compl_iff, limsup_compl, comp_apply, mem_liminf_iff_eventually_mem] theorem cofinite.blimsup_set_eq : blimsup s cofinite p = { x | { n | p n ∧ x ∈ s n }.Infinite } := by simp only [blimsup_eq, le_eq_subset, eventually_cofinite, not_forall, sInf_eq_sInter, exists_prop] ext x refine ⟨fun h => ?_, fun hx t h => ?_⟩ <;> contrapose! h · simp only [mem_sInter, mem_setOf_eq, not_forall, exists_prop] exact ⟨{x}ᶜ, by simpa using h, by simp⟩ · exact hx.mono fun i hi => ⟨hi.1, fun hit => h (hit hi.2)⟩ theorem cofinite.bliminf_set_eq : bliminf s cofinite p = { x | { n | p n ∧ x ∉ s n }.Finite } := by rw [← compl_inj_iff] simp only [bliminf_eq_iSup_biInf, compl_iInf, compl_iSup, ← blimsup_eq_iInf_biSup, cofinite.blimsup_set_eq] rfl /-- In other words, `limsup cofinite s` is the set of elements lying inside the family `s` infinitely often. -/ theorem cofinite.limsup_set_eq : limsup s cofinite = { x | { n | x ∈ s n }.Infinite } := by simp only [← cofinite.blimsup_true s, cofinite.blimsup_set_eq, true_and] /-- In other words, `liminf cofinite s` is the set of elements lying outside the family `s` finitely often. -/ theorem cofinite.liminf_set_eq : liminf s cofinite = { x | { n | x ∉ s n }.Finite } := by simp only [← cofinite.bliminf_true s, cofinite.bliminf_set_eq, true_and] theorem exists_forall_mem_of_hasBasis_mem_blimsup {l : Filter β} {b : ι → Set β} {q : ι → Prop} (hl : l.HasBasis q b) {u : β → Set α} {p : β → Prop} {x : α} (hx : x ∈ blimsup u l p) : ∃ f : { i | q i } → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by rw [blimsup_eq_iInf_biSup] at hx simp only [iSup_eq_iUnion, iInf_eq_iInter, mem_iInter, mem_iUnion, exists_prop] at hx choose g hg hg' using hx refine ⟨fun i : { i | q i } => g (b i) (hl.mem_of_mem i.2), fun i => ⟨?_, ?_⟩⟩ · exact hg' (b i) (hl.mem_of_mem i.2) · exact hg (b i) (hl.mem_of_mem i.2) theorem exists_forall_mem_of_hasBasis_mem_blimsup' {l : Filter β} {b : ι → Set β} (hl : l.HasBasis (fun _ => True) b) {u : β → Set α} {p : β → Prop} {x : α} (hx : x ∈ blimsup u l p) : ∃ f : ι → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by obtain ⟨f, hf⟩ := exists_forall_mem_of_hasBasis_mem_blimsup hl hx exact ⟨fun i => f ⟨i, trivial⟩, fun i => hf ⟨i, trivial⟩⟩ end SetLattice section ConditionallyCompleteLinearOrder theorem frequently_lt_of_lt_limsSup {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (h : a < limsSup f) : ∃ᶠ n in f, a < n := by contrapose! h simp only [not_frequently, not_lt] at h exact limsSup_le_of_le hf h theorem frequently_lt_of_limsInf_lt {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α} (hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : limsInf f < a) : ∃ᶠ n in f, n < a := frequently_lt_of_lt_limsSup (α := OrderDual α) hf h theorem eventually_lt_of_lt_liminf {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β} {b : β} (h : b < liminf u f) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : ∀ᶠ a in f, b < u a := by obtain ⟨c, hc, hbc⟩ : ∃ (c : β) (_ : c ∈ { c : β | ∀ᶠ n : α in f, c ≤ u n }), b < c := by simp_rw [exists_prop] exact exists_lt_of_lt_csSup hu h exact hc.mono fun x hx => lt_of_lt_of_le hbc hx theorem eventually_lt_of_limsup_lt {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β} {b : β} (h : limsup u f < b) (hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : ∀ᶠ a in f, u a < b := eventually_lt_of_lt_liminf (β := βᵒᵈ) h hu section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] /-- If `Filter.limsup u atTop ≤ x`, then for all `ε > 0`, eventually we have `u b < x + ε`. -/ theorem eventually_lt_add_pos_of_limsup_le [Preorder β] [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : β → α} (hu_bdd : IsBoundedUnder LE.le atTop u) (hu : Filter.limsup u atTop ≤ x) (hε : 0 < ε) : ∀ᶠ b : β in atTop, u b < x + ε := eventually_lt_of_limsup_lt (lt_of_le_of_lt hu (lt_add_of_pos_right x hε)) hu_bdd /-- If `x ≤ Filter.liminf u atTop`, then for all `ε < 0`, eventually we have `x + ε < u b`. -/ theorem eventually_add_neg_lt_of_le_liminf [Preorder β] [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : β → α} (hu_bdd : IsBoundedUnder GE.ge atTop u) (hu : x ≤ Filter.liminf u atTop) (hε : ε < 0) : ∀ᶠ b : β in atTop, x + ε < u b := eventually_lt_of_lt_liminf (lt_of_lt_of_le (add_lt_of_neg_right x hε) hu) hu_bdd /-- If `Filter.limsup u atTop ≤ x`, then for all `ε > 0`, there exists a positive natural number `n` such that `u n < x + ε`. -/ theorem exists_lt_of_limsup_le [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : ℕ → α} (hu_bdd : IsBoundedUnder LE.le atTop u) (hu : Filter.limsup u atTop ≤ x) (hε : 0 < ε) : ∃ n : PNat, u n < x + ε := by have h : ∀ᶠ n : ℕ in atTop, u n < x + ε := eventually_lt_add_pos_of_limsup_le hu_bdd hu hε simp only [eventually_atTop] at h obtain ⟨n, hn⟩ := h exact ⟨⟨n + 1, Nat.succ_pos _⟩, hn (n + 1) (Nat.le_succ _)⟩ /-- If `x ≤ Filter.liminf u atTop`, then for all `ε < 0`, there exists a positive natural number `n` such that ` x + ε < u n`. -/ theorem exists_lt_of_le_liminf [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : ℕ → α} (hu_bdd : IsBoundedUnder GE.ge atTop u) (hu : x ≤ Filter.liminf u atTop) (hε : ε < 0) : ∃ n : PNat, x + ε < u n := by have h : ∀ᶠ n : ℕ in atTop, x + ε < u n := eventually_add_neg_lt_of_le_liminf hu_bdd hu hε simp only [eventually_atTop] at h obtain ⟨n, hn⟩ := h exact ⟨⟨n + 1, Nat.succ_pos _⟩, hn (n + 1) (Nat.le_succ _)⟩ end ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder β] {f : Filter α} {u : α → β} theorem le_limsup_of_frequently_le {b : β} (hu_le : ∃ᶠ x in f, b ≤ u x) (hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : b ≤ limsup u f := by revert hu_le rw [← not_imp_not, not_frequently] simp_rw [← lt_iff_not_ge] exact fun h => eventually_lt_of_limsup_lt h hu theorem liminf_le_of_frequently_le {b : β} (hu_le : ∃ᶠ x in f, u x ≤ b) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ b := le_limsup_of_frequently_le (β := βᵒᵈ) hu_le hu theorem frequently_lt_of_lt_limsup {b : β} (hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h : b < limsup u f) : ∃ᶠ x in f, b < u x := by contrapose! h apply limsSup_le_of_le hu simpa using h theorem frequently_lt_of_liminf_lt {b : β} (hu : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h : liminf u f < b) : ∃ᶠ x in f, u x < b := frequently_lt_of_lt_limsup (β := βᵒᵈ) hu h theorem limsup_le_iff {x : β} (h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : limsup u f ≤ x ↔ ∀ y > x, ∀ᶠ a in f, u a < y := by refine ⟨fun h _ h' ↦ eventually_lt_of_limsup_lt (h.trans_lt h') h₂, fun h ↦ ?_⟩ --Two cases: Either `x` is a cluster point from above, or it is not. --In the first case, we use `forall_lt_iff_le'` and split an interval. --In the second case, the function `u` must eventually be smaller or equal to `x`. by_cases h' : ∀ y > x, ∃ z, x < z ∧ z < y · rw [← forall_lt_iff_le'] intro y x_y rcases h' y x_y with ⟨z, x_z, z_y⟩ exact (limsup_le_of_le h₁ ((h z x_z).mono (fun _ ↦ le_of_lt))).trans_lt z_y · apply limsup_le_of_le h₁ set_option push_neg.use_distrib true in push_neg at h' rcases h' with ⟨z, x_z, hz⟩ exact (h z x_z).mono <| fun w hw ↦ (or_iff_left (not_le_of_lt hw)).1 (hz (u w)) /- A version of `limsup_le_iff` with large inequalities in densely ordered spaces.-/ lemma limsup_le_iff' [DenselyOrdered β] {x : β} (h₁ : IsCoboundedUnder (· ≤ ·) f u := by isBoundedDefault) (h₂ : IsBoundedUnder (· ≤ ·) f u := by isBoundedDefault) : limsup u f ≤ x ↔ ∀ y > x, ∀ᶠ (a : α) in f, u a ≤ y := by refine ⟨fun h _ h' ↦ (eventually_lt_of_limsup_lt (h.trans_lt h') h₂).mono fun _ ↦ le_of_lt, ?_⟩ rw [← forall_lt_iff_le'] intro h y x_y obtain ⟨z, x_z, z_y⟩ := exists_between x_y exact (limsup_le_of_le h₁ (h z x_z)).trans_lt z_y theorem le_limsup_iff {x : β} (h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : x ≤ limsup u f ↔ ∀ y < x, ∃ᶠ a in f, y < u a := by refine ⟨fun h _ h' ↦ frequently_lt_of_lt_limsup h₁ (h'.trans_le h), fun h ↦ ?_⟩ --Two cases: Either `x` is a cluster point from below, or it is not. --In the first case, we use `forall_lt_iff_le` and split an interval. --In the second case, the function `u` must frequently be larger or equal to `x`. by_cases h' : ∀ y < x, ∃ z, y < z ∧ z < x · rw [← forall_lt_iff_le] intro y y_x obtain ⟨z, y_z, z_x⟩ := h' y y_x exact y_z.trans_le (le_limsup_of_frequently_le ((h z z_x).mono (fun _ ↦ le_of_lt)) h₂) · apply le_limsup_of_frequently_le _ h₂ set_option push_neg.use_distrib true in push_neg at h' rcases h' with ⟨z, z_x, hz⟩ exact (h z z_x).mono <| fun w hw ↦ (or_iff_right (not_le_of_lt hw)).1 (hz (u w)) /- A version of `le_limsup_iff` with large inequalities in densely ordered spaces.-/ lemma le_limsup_iff' [DenselyOrdered β] {x : β} (h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : x ≤ limsup u f ↔ ∀ y < x, ∃ᶠ a in f, y ≤ u a := by refine ⟨fun h _ h' ↦ (frequently_lt_of_lt_limsup h₁ (h'.trans_le h)).mono fun _ ↦ le_of_lt, ?_⟩ rw [← forall_lt_iff_le] intro h y y_x obtain ⟨z, y_z, z_x⟩ := exists_between y_x exact y_z.trans_le (le_limsup_of_frequently_le (h z z_x) h₂) theorem le_liminf_iff {x : β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : x ≤ liminf u f ↔ ∀ y < x, ∀ᶠ a in f, y < u a := limsup_le_iff (β := βᵒᵈ) h₁ h₂ /- A version of `le_liminf_iff` with large inequalities in densely ordered spaces.-/ theorem le_liminf_iff' [DenselyOrdered β] {x : β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : x ≤ liminf u f ↔ ∀ y < x, ∀ᶠ a in f, y ≤ u a := limsup_le_iff' (β := βᵒᵈ) h₁ h₂ theorem liminf_le_iff {x : β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ x ↔ ∀ y > x, ∃ᶠ a in f, u a < y := le_limsup_iff (β := βᵒᵈ) h₁ h₂ /- A version of `liminf_le_iff` with large inequalities in densely ordered spaces.-/ theorem liminf_le_iff' [DenselyOrdered β] {x : β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ x ↔ ∀ y > x, ∃ᶠ a in f, u a ≤ y := le_limsup_iff' (β := βᵒᵈ) h₁ h₂ lemma liminf_le_limsup_of_frequently_le {v : α → β} (h : ∃ᶠ x in f, u x ≤ v x) (h₁ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) : liminf u f ≤ limsup v f := by rcases f.eq_or_neBot with rfl | _ · exact (frequently_bot h).rec have h₃ : f.IsCoboundedUnder (· ≥ ·) u := by obtain ⟨a, ha⟩ := h₂.eventually_le apply IsCoboundedUnder.of_frequently_le (a := a) exact (h.and_eventually ha).mono fun x ⟨u_x, v_x⟩ ↦ u_x.trans v_x have h₄ : f.IsCoboundedUnder (· ≤ ·) v := by obtain ⟨a, ha⟩ := h₁.eventually_ge apply IsCoboundedUnder.of_frequently_ge (a := a) exact (ha.and_frequently h).mono fun x ⟨u_x, v_x⟩ ↦ u_x.trans v_x refine (le_limsup_iff h₄ h₂).2 fun y y_v ↦ ?_ have := (le_liminf_iff h₃ h₁).1 (le_refl (liminf u f)) y y_v exact (h.and_eventually this).mono fun x ⟨ux_vx, y_ux⟩ ↦ y_ux.trans_le ux_vx variable [ConditionallyCompleteLinearOrder α] {f : Filter α} {b : α} -- The linter erroneously claims that I'm not referring to `c` set_option linter.unusedVariables false in theorem lt_mem_sets_of_limsSup_lt (h : f.IsBounded (· ≤ ·)) (l : f.limsSup < b) : ∀ᶠ a in f, a < b := let ⟨c, (h : ∀ᶠ a in f, a ≤ c), hcb⟩ := exists_lt_of_csInf_lt h l mem_of_superset h fun _a => hcb.trans_le' theorem gt_mem_sets_of_limsInf_gt : f.IsBounded (· ≥ ·) → b < f.limsInf → ∀ᶠ a in f, b < a := @lt_mem_sets_of_limsSup_lt αᵒᵈ _ _ _ section Classical open Classical in /-- Given an indexed family of sets `s j` over `j : Subtype p` and a function `f`, then `liminf_reparam j` is equal to `j` if `f` is bounded below on `s j`, and otherwise to some index `k` such that `f` is bounded below on `s k` (if there exists one). To ensure good measurability behavior, this index `k` is chosen as the minimal suitable index. This function is used to write down a liminf in a measurable way, in `Filter.HasBasis.liminf_eq_ciSup_ciInf` and `Filter.HasBasis.liminf_eq_ite`. -/ noncomputable def liminf_reparam (f : ι → α) (s : ι' → Set ι) (p : ι' → Prop) [Countable (Subtype p)] [Nonempty (Subtype p)] (j : Subtype p) : Subtype p := let m : Set (Subtype p) := {j | BddBelow (range (fun (i : s j) ↦ f i))} let g : ℕ → Subtype p := (exists_surjective_nat _).choose have Z : ∃ n, g n ∈ m ∨ ∀ j, j ∉ m := by by_cases H : ∃ j, j ∈ m · rcases H with ⟨j, hj⟩ rcases (exists_surjective_nat (Subtype p)).choose_spec j with ⟨n, rfl⟩ exact ⟨n, Or.inl hj⟩ · push_neg at H exact ⟨0, Or.inr H⟩ if j ∈ m then j else g (Nat.find Z) /-- Writing a liminf as a supremum of infimum, in a (possibly non-complete) conditionally complete linear order. A reparametrization trick is needed to avoid taking the infimum of sets which are not bounded below. -/ theorem HasBasis.liminf_eq_ciSup_ciInf {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) {f : ι → α} (hs : ∀ (j : Subtype p), (s j).Nonempty) (H : ∃ (j : Subtype p), BddBelow (range (fun (i : s j) ↦ f i))) : liminf f v = ⨆ (j : Subtype p), ⨅ (i : s (liminf_reparam f s p j)), f i := by classical rcases H with ⟨j0, hj0⟩ let m : Set (Subtype p) := {j | BddBelow (range (fun (i : s j) ↦ f i))} have : ∀ (j : Subtype p), Nonempty (s j) := fun j ↦ Nonempty.coe_sort (hs j) have A : ⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i) = ⋃ (j : Subtype p), ⋂ (i : s (liminf_reparam f s p j)), Iic (f i) := by apply Subset.antisymm · apply iUnion_subset (fun j ↦ ?_) by_cases hj : j ∈ m · have : j = liminf_reparam f s p j := by simp only [m, liminf_reparam, hj, ite_true] conv_lhs => rw [this] apply subset_iUnion _ j · simp only [m, mem_setOf_eq, ← nonempty_iInter_Iic_iff, not_nonempty_iff_eq_empty] at hj simp only [hj, empty_subset] · apply iUnion_subset (fun j ↦ ?_) exact subset_iUnion (fun (k : Subtype p) ↦ (⋂ (i : s k), Iic (f i))) (liminf_reparam f s p j) have B : ∀ (j : Subtype p), ⋂ (i : s (liminf_reparam f s p j)), Iic (f i) = Iic (⨅ (i : s (liminf_reparam f s p j)), f i) := by intro j apply (Iic_ciInf _).symm change liminf_reparam f s p j ∈ m by_cases Hj : j ∈ m · simpa only [m, liminf_reparam, if_pos Hj] using Hj · simp only [m, liminf_reparam, if_neg Hj] have Z : ∃ n, (exists_surjective_nat (Subtype p)).choose n ∈ m ∨ ∀ j, j ∉ m := by rcases (exists_surjective_nat (Subtype p)).choose_spec j0 with ⟨n, rfl⟩ exact ⟨n, Or.inl hj0⟩ rcases Nat.find_spec Z with hZ|hZ · exact hZ · exact (hZ j0 hj0).elim simp_rw [hv.liminf_eq_sSup_iUnion_iInter, A, B, sSup_iUnion_Iic] open Classical in /-- Writing a liminf as a supremum of infimum, in a (possibly non-complete) conditionally complete linear order. A reparametrization trick is needed to avoid taking the infimum of sets which are not bounded below. -/ theorem HasBasis.liminf_eq_ite {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) (f : ι → α) : liminf f v = if ∃ (j : Subtype p), s j = ∅ then sSup univ else if ∀ (j : Subtype p), ¬BddBelow (range (fun (i : s j) ↦ f i)) then sSup ∅ else ⨆ (j : Subtype p), ⨅ (i : s (liminf_reparam f s p j)), f i := by by_cases H : ∃ (j : Subtype p), s j = ∅ · rw [if_pos H] rcases H with ⟨j, hj⟩ simp [hv.liminf_eq_sSup_univ_of_empty j j.2 hj] rw [if_neg H] by_cases H' : ∀ (j : Subtype p), ¬BddBelow (range (fun (i : s j) ↦ f i)) · have A : ∀ (j : Subtype p), ⋂ (i : s j), Iic (f i) = ∅ := by simp_rw [← not_nonempty_iff_eq_empty, nonempty_iInter_Iic_iff] exact H' simp_rw [if_pos H', hv.liminf_eq_sSup_iUnion_iInter, A, iUnion_empty] rw [if_neg H'] apply hv.liminf_eq_ciSup_ciInf · push_neg at H simpa only [nonempty_iff_ne_empty] using H · push_neg at H' exact H' /-- Given an indexed family of sets `s j` and a function `f`, then `limsup_reparam j` is equal to `j` if `f` is bounded above on `s j`, and otherwise to some index `k` such that `f` is bounded above on `s k` (if there exists one). To ensure good measurability behavior, this index `k` is chosen as the minimal suitable index. This function is used to write down a limsup in a measurable way, in `Filter.HasBasis.limsup_eq_ciInf_ciSup` and `Filter.HasBasis.limsup_eq_ite`. -/ noncomputable def limsup_reparam (f : ι → α) (s : ι' → Set ι) (p : ι' → Prop) [Countable (Subtype p)] [Nonempty (Subtype p)] (j : Subtype p) : Subtype p := liminf_reparam (α := αᵒᵈ) f s p j /-- Writing a limsup as an infimum of supremum, in a (possibly non-complete) conditionally complete linear order. A reparametrization trick is needed to avoid taking the supremum of sets which are not bounded above. -/ theorem HasBasis.limsup_eq_ciInf_ciSup {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) {f : ι → α} (hs : ∀ (j : Subtype p), (s j).Nonempty) (H : ∃ (j : Subtype p), BddAbove (range (fun (i : s j) ↦ f i))) : limsup f v = ⨅ (j : Subtype p), ⨆ (i : s (limsup_reparam f s p j)), f i := HasBasis.liminf_eq_ciSup_ciInf (α := αᵒᵈ) hv hs H open Classical in /-- Writing a limsup as an infimum of supremum, in a (possibly non-complete) conditionally complete linear order. A reparametrization trick is needed to avoid taking the supremum of sets which are not bounded below. -/ theorem HasBasis.limsup_eq_ite {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) (f : ι → α) : limsup f v = if ∃ (j : Subtype p), s j = ∅ then sInf univ else if ∀ (j : Subtype p), ¬BddAbove (range (fun (i : s j) ↦ f i)) then sInf ∅ else ⨅ (j : Subtype p), ⨆ (i : s (limsup_reparam f s p j)), f i := HasBasis.liminf_eq_ite (α := αᵒᵈ) hv f end Classical end ConditionallyCompleteLinearOrder end Filter section Order theorem GaloisConnection.l_limsup_le [ConditionallyCompleteLattice β] [ConditionallyCompleteLattice γ] {f : Filter α} {v : α → β} {l : β → γ} {u : γ → β} (gc : GaloisConnection l u) (hlv : f.IsBoundedUnder (· ≤ ·) fun x => l (v x) := by isBoundedDefault) (hv_co : f.IsCoboundedUnder (· ≤ ·) v := by isBoundedDefault) : l (limsup v f) ≤ limsup (fun x => l (v x)) f := by refine le_limsSup_of_le hlv fun c hc => ?_ rw [Filter.eventually_map] at hc simp_rw [gc _ _] at hc ⊢ exact limsSup_le_of_le hv_co hc theorem OrderIso.limsup_apply {γ} [ConditionallyCompleteLattice β] [ConditionallyCompleteLattice γ] {f : Filter α} {u : α → β} (g : β ≃o γ) (hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (hu_co : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hgu : f.IsBoundedUnder (· ≤ ·) fun x => g (u x) := by isBoundedDefault) (hgu_co : f.IsCoboundedUnder (· ≤ ·) fun x => g (u x) := by isBoundedDefault) : g (limsup u f) = limsup (fun x => g (u x)) f := by refine le_antisymm ((OrderIso.to_galoisConnection g).l_limsup_le hgu hu_co) ?_ rw [← g.symm.symm_apply_apply <| limsup (fun x => g (u x)) f, g.symm_symm] refine g.monotone ?_ have hf : u = fun i => g.symm (g (u i)) := funext fun i => (g.symm_apply_apply (u i)).symm nth_rw 2 [hf] refine (OrderIso.to_galoisConnection g.symm).l_limsup_le ?_ hgu_co simp_rw [g.symm_apply_apply] exact hu theorem OrderIso.liminf_apply {γ} [ConditionallyCompleteLattice β] [ConditionallyCompleteLattice γ] {f : Filter α} {u : α → β} (g : β ≃o γ) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hu_co : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (hgu : f.IsBoundedUnder (· ≥ ·) fun x => g (u x) := by isBoundedDefault) (hgu_co : f.IsCoboundedUnder (· ≥ ·) fun x => g (u x) := by isBoundedDefault) : g (liminf u f) = liminf (fun x => g (u x)) f := OrderIso.limsup_apply (β := βᵒᵈ) (γ := γᵒᵈ) g.dual hu hu_co hgu hgu_co end Order section MinMax open Filter theorem limsup_max [ConditionallyCompleteLinearOrder β] {f : Filter α} {u v : α → β} (h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h₂ : f.IsCoboundedUnder (· ≤ ·) v := by isBoundedDefault) (h₃ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h₄ : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) : limsup (fun a ↦ max (u a) (v a)) f = max (limsup u f) (limsup v f) := by have bddmax := IsBoundedUnder.sup h₃ h₄ have cobddmax := isCoboundedUnder_le_max (v := v) (Or.inl h₁) apply le_antisymm · refine (limsup_le_iff cobddmax bddmax).2 (fun b hb ↦ ?_) have hu := eventually_lt_of_limsup_lt (lt_of_le_of_lt (le_max_left _ _) hb) h₃ have hv := eventually_lt_of_limsup_lt (lt_of_le_of_lt (le_max_right _ _) hb) h₄ refine mem_of_superset (inter_mem hu hv) (fun _ ↦ by simp) · exact max_le (c := limsup (fun a ↦ max (u a) (v a)) f) (limsup_le_limsup (Eventually.of_forall (fun a : α ↦ le_max_left (u a) (v a))) h₁ bddmax) (limsup_le_limsup (Eventually.of_forall (fun a : α ↦ le_max_right (u a) (v a))) h₂ bddmax) theorem liminf_min [ConditionallyCompleteLinearOrder β] {f : Filter α} {u v : α → β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault) (h₃ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (h₄ : f.IsBoundedUnder (· ≥ ·) v := by isBoundedDefault) : liminf (fun a ↦ min (u a) (v a)) f = min (liminf u f) (liminf v f) := limsup_max (β := βᵒᵈ) h₁ h₂ h₃ h₄ open Finset theorem limsup_finset_sup' [ConditionallyCompleteLinearOrder β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (hs : s.Nonempty) (h₁ : ∀ i ∈ s, f.IsCoboundedUnder (· ≤ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) (h₂ : ∀ i ∈ s, f.IsBoundedUnder (· ≤ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) : limsup (fun a ↦ sup' s hs (fun i ↦ F i a)) f = sup' s hs (fun i ↦ limsup (F i) f) := by have bddsup := isBoundedUnder_le_finset_sup' hs h₂ apply le_antisymm · have h₃ : ∃ i ∈ s, f.IsCoboundedUnder (· ≤ ·) (F i) := by rcases hs with ⟨i, i_s⟩ use i, i_s exact h₁ i i_s have cobddsup := isCoboundedUnder_le_finset_sup' hs h₃ refine (limsup_le_iff cobddsup bddsup).2 (fun b hb ↦ ?_) rw [eventually_iff_exists_mem] use ⋂ i ∈ s, {a | F i a < b} split_ands · rw [biInter_finset_mem] suffices key : ∀ i ∈ s, ∀ᶠ a in f, F i a < b from fun i i_s ↦ eventually_iff.1 (key i i_s) intro i i_s apply eventually_lt_of_limsup_lt _ (h₂ i i_s) exact lt_of_le_of_lt (Finset.le_sup' (f := fun i ↦ limsup (F i) f) i_s) hb · simp only [mem_iInter, mem_setOf_eq, Finset.sup'_apply, sup'_lt_iff, imp_self, implies_true] · apply Finset.sup'_le hs (fun i ↦ limsup (F i) f) refine fun i i_s ↦ limsup_le_limsup (Eventually.of_forall (fun a ↦ ?_)) (h₁ i i_s) bddsup simp only [Finset.sup'_apply, le_sup'_iff] use i, i_s theorem limsup_finset_sup [ConditionallyCompleteLinearOrder β] [OrderBot β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (h₁ : ∀ i ∈ s, f.IsCoboundedUnder (· ≤ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) (h₂ : ∀ i ∈ s, f.IsBoundedUnder (· ≤ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) : limsup (fun a ↦ sup s (fun i ↦ F i a)) f = sup s (fun i ↦ limsup (F i) f) := by rcases eq_or_neBot f with (rfl | _) · simp [limsup_eq, csInf_univ] rcases Finset.eq_empty_or_nonempty s with (rfl | s_nemp) · simp only [Finset.sup_apply, sup_empty, limsup_const] rw [← Finset.sup'_eq_sup s_nemp fun i ↦ limsup (F i) f, ← limsup_finset_sup' s_nemp h₁ h₂] congr ext a exact Eq.symm (Finset.sup'_eq_sup s_nemp (fun i ↦ F i a)) theorem liminf_finset_inf' [ConditionallyCompleteLinearOrder β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (hs : s.Nonempty) (h₁ : ∀ i ∈ s, f.IsCoboundedUnder (· ≥ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) (h₂ : ∀ i ∈ s, f.IsBoundedUnder (· ≥ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) : liminf (fun a ↦ inf' s hs (fun i ↦ F i a)) f = inf' s hs (fun i ↦ liminf (F i) f) := limsup_finset_sup' (β := βᵒᵈ) hs h₁ h₂ theorem liminf_finset_inf [ConditionallyCompleteLinearOrder β] [OrderTop β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (h₁ : ∀ i ∈ s, f.IsCoboundedUnder (· ≥ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) (h₂ : ∀ i ∈ s, f.IsBoundedUnder (· ≥ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) : liminf (fun a ↦ inf s (fun i ↦ F i a)) f = inf s (fun i ↦ liminf (F i) f) := limsup_finset_sup (β := βᵒᵈ) h₁ h₂ end MinMax
Mathlib/Order/LiminfLimsup.lean
1,217
1,221
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Eric Wieser -/ import Mathlib.Data.Fin.Tuple.Basic /-! # 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 `MathlibTest/matrix.lean` file. -/ namespace Matrix universe u variable {α : Type u} section MatrixNotation /-- `![]` is the vector with no entries. -/ def vecEmpty : Fin 0 → α := Fin.elim0 /-- `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 /-- `![...]` 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 /-- `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 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)) "]" end MatrixNotation variable {m n o : ℕ} theorem empty_eq (v : Fin 0 → α) : v = ![] := Subsingleton.elim _ _ section Val @[simp] theorem head_fin_const (a : α) : (vecHead fun _ : Fin (n + 1) => a) = a := rfl @[simp] theorem cons_val_zero (x : α) (u : Fin m → α) : vecCons x u 0 = x := rfl theorem cons_val_zero' (h : 0 < m.succ) (x : α) (u : Fin m → α) : vecCons x u ⟨0, h⟩ = x := rfl @[simp] theorem cons_val_succ (x : α) (u : Fin m → α) (i : Fin m) : vecCons x u i.succ = u i := by simp [vecCons] @[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'] section simprocs open Lean Qq /-- Parses a chain of `Matrix.vecCons` calls into elements, leaving everything else in the tail. `let ⟨xs, tailn, tail⟩ ← matchVecConsPrefix n e` decomposes `e : Fin n → _` in the form `vecCons x₀ <| ... <| vecCons xₙ <| tail` where `tail : Fin tailn → _`. -/ partial def matchVecConsPrefix (n : Q(Nat)) (e : Expr) : MetaM <| List Expr × Q(Nat) × Expr := do match_expr ← Meta.whnfR e with | Matrix.vecCons _ n x xs => do let (elems, n', tail) ← matchVecConsPrefix n xs return (x :: elems, n', tail) | _ => return ([], n, e) open Qq in /-- A simproc that handles terms of the form `Matrix.vecCons a f i` where `i` is a numeric literal. In practice, this is most effective at handling `![a, b, c] i`-style terms. -/ dsimproc cons_val (Matrix.vecCons _ _ _) := fun e => do let_expr Matrix.vecCons α en x xs' ei := ← Meta.whnfR e | return .continue let some i := ei.int? | return .continue let (xs, etailn, tail) ← matchVecConsPrefix en xs' let xs := x :: xs -- Determine if the tail is a numeral or only an offset. let (tailn, variadic, etailn) ← do let etailn_whnf : Q(ℕ) ← Meta.whnfD etailn if let Expr.lit (.natVal length) := etailn_whnf then pure (length, false, q(OfNat.ofNat $etailn_whnf)) else if let .some ((base : Q(ℕ)), offset) ← (Meta.isOffset? etailn_whnf).run then let offset_e : Q(ℕ) := mkNatLit offset pure (offset, true, q($base + $offset)) else pure (0, true, etailn) -- Wrap the index if possible, and abort if not let wrapped_i ← if variadic then -- can't wrap as we don't know the length unless 0 ≤ i ∧ i < xs.length + tailn do return .continue pure i.toNat else pure (i % (xs.length + tailn)).toNat if h : wrapped_i < xs.length then return .continue xs[wrapped_i] else -- Within the `tail`
let _ ← synthInstanceQ q(NeZero $etailn) have i_lit : Q(ℕ) := mkRawNatLit (wrapped_i - xs.length)
Mathlib/Data/Fin/VecNotation.lean
183
184
/- Copyright (c) 2023 Xavier Généreux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Généreux -/ import Mathlib.Analysis.SpecialFunctions.Pow.Deriv import Mathlib.Analysis.Complex.PhragmenLindelof /-! # Hadamard three-lines Theorem In this file we present a proof of Hadamard's three-lines Theorem. ## Main result - `norm_le_interp_of_mem_verticalClosedStrip` : Hadamard three-line theorem: If `f` is a bounded function, continuous on `re ⁻¹' [l, u]` and differentiable on `re ⁻¹' (l, u)`, then for `M(x) := sup ((norm ∘ f) '' (re ⁻¹' {x}))`, that is `M(x)` is the supremum of the absolute value of `f` along the vertical lines `re z = x`, we have that `∀ z ∈ re ⁻¹' [l, u]` the inequality `‖f(z)‖ ≤ M(0) ^ (1 - ((z.re - l) / (u - l))) * M(1) ^ ((z.re - l) / (u - l))` holds. This can be seen to be equivalent to the statement that `log M(re z)` is a convex function on `[0, 1]`. - `norm_le_interp_of_mem_verticalClosedStrip'` : Variant of the above lemma in simpler terms. In particular, it makes no mention of the helper functions defined in this file. ## Main definitions - `Complex.HadamardThreeLines.verticalStrip` : The vertical strip defined by : `re ⁻¹' Ioo a b` - `Complex.HadamardThreeLines.verticalClosedStrip` : The vertical strip defined by : `re ⁻¹' Icc a b` - `Complex.HadamardThreeLines.sSupNormIm` : The supremum function on vertical lines defined by : `sSup {|f(z)| : z.re = x}` - `Complex.HadamardThreeLines.interpStrip` : The interpolation between the `sSupNormIm` on the edges of the vertical strip `re⁻¹ [0, 1]`. - `Complex.HadamardThreeLines.interpStrip` : The interpolation between the `sSupNormIm` on the edges of any vertical strip. - `Complex.HadamardThreeLines.invInterpStrip` : Inverse of the interpolation between the `sSupNormIm` on the edges of the vertical strip `re⁻¹ [0, 1]`. - `Complex.HadamardThreeLines.F` : Function defined by `f` times `invInterpStrip`. Convenient form for proofs. ## Note The proof follows from Phragmén-Lindelöf when both frontiers are not everywhere zero. We then use a limit argument to cover the case when either of the sides are `0`. -/ open Set Filter Function Complex Topology namespace Complex namespace HadamardThreeLines /-- The vertical strip in the complex plane containing all `z ∈ ℂ` such that `z.re ∈ Ioo a b`. -/ def verticalStrip (a : ℝ) (b : ℝ) : Set ℂ := re ⁻¹' Ioo a b /-- The vertical strip in the complex plane containing all `z ∈ ℂ` such that `z.re ∈ Icc a b`. -/ def verticalClosedStrip (a : ℝ) (b : ℝ) : Set ℂ := re ⁻¹' Icc a b /-- The supremum of the norm of `f` on imaginary lines. (Fixed real part) This is also known as the function `M` -/ noncomputable def sSupNormIm {E : Type*} [NormedAddCommGroup E] (f : ℂ → E) (x : ℝ) : ℝ := sSup ((norm ∘ f) '' (re ⁻¹' {x})) section invInterpStrip variable {E : Type*} [NormedAddCommGroup E] (f : ℂ → E) (z : ℂ) /-- The inverse of the interpolation of `sSupNormIm` on the two boundaries. In other words, this is the inverse of the right side of the target inequality: `|f(z)| ≤ |M(0) ^ (1-z)| * |M(1) ^ z|`. Shifting this by a positive epsilon allows us to prove the case when either of the boundaries is zero. -/ noncomputable def invInterpStrip (ε : ℝ) : ℂ := (ε + sSupNormIm f 0) ^ (z - 1) * (ε + sSupNormIm f 1) ^ (-z) /-- A function useful for the proofs steps. We will aim to show that it is bounded by 1. -/ noncomputable def F [NormedSpace ℂ E] (ε : ℝ) := fun z ↦ invInterpStrip f z ε • f z /-- `sSup` of `norm` is nonneg applied to the image of `f` on the vertical line `re z = x` -/ lemma sSupNormIm_nonneg (x : ℝ) : 0 ≤ sSupNormIm f x := by apply Real.sSup_nonneg rintro y ⟨z1, _, hz2⟩ simp only [← hz2, comp, norm_nonneg] /-- `sSup` of `norm` translated by `ε > 0` is positive applied to the image of `f` on the vertical line `re z = x` -/ lemma sSupNormIm_eps_pos {ε : ℝ} (hε : ε > 0) (x : ℝ) : 0 < ε + sSupNormIm f x := by linarith [sSupNormIm_nonneg f x] /-- Useful rewrite for the absolute value of `invInterpStrip` -/ lemma norm_invInterpStrip {ε : ℝ} (hε : ε > 0) : ‖invInterpStrip f z ε‖ = (ε + sSupNormIm f 0) ^ (z.re - 1) * (ε + sSupNormIm f 1) ^ (-z.re) := by simp only [invInterpStrip, norm_mul] repeat rw [← ofReal_add] repeat rw [norm_cpow_eq_rpow_re_of_pos (sSupNormIm_eps_pos f hε _) _] simp @[deprecated (since := "2025-02-17")] alias abs_invInterpStrip := norm_invInterpStrip /-- The function `invInterpStrip` is `diffContOnCl`. -/ lemma diffContOnCl_invInterpStrip {ε : ℝ} (hε : ε > 0) : DiffContOnCl ℂ (fun z ↦ invInterpStrip f z ε) (verticalStrip 0 1) := by apply Differentiable.diffContOnCl apply Differentiable.mul · apply Differentiable.const_cpow (Differentiable.sub_const (differentiable_id') 1) _ left rw [← ofReal_add, ofReal_ne_zero] simp only [ne_eq, ne_of_gt (sSupNormIm_eps_pos f hε 0), not_false_eq_true] · apply Differentiable.const_cpow (Differentiable.neg differentiable_id') apply Or.inl rw [← ofReal_add, ofReal_ne_zero] exact (ne_of_gt (sSupNormIm_eps_pos f hε 1)) /-- If `f` is bounded on the unit vertical strip, then `f` is bounded by `sSupNormIm` there. -/ lemma norm_le_sSupNormIm (f : ℂ → E) (z : ℂ) (hD : z ∈ verticalClosedStrip 0 1) (hB : BddAbove ((norm ∘ f) '' verticalClosedStrip 0 1)) : ‖f z‖ ≤ sSupNormIm f (z.re) := by refine le_csSup ?_ ?_ · apply BddAbove.mono (image_subset (norm ∘ f) _) hB exact preimage_mono (singleton_subset_iff.mpr hD) · apply mem_image_of_mem (norm ∘ f) simp only [mem_preimage, mem_singleton] /-- Alternative version of `norm_le_sSupNormIm` with a strict inequality and a positive `ε`. -/ lemma norm_lt_sSupNormIm_eps (f : ℂ → E) (ε : ℝ) (hε : ε > 0) (z : ℂ) (hD : z ∈ verticalClosedStrip 0 1) (hB : BddAbove ((norm ∘ f) '' verticalClosedStrip 0 1)) : ‖f z‖ < ε + sSupNormIm f (z.re) := lt_add_of_pos_of_le hε (norm_le_sSupNormIm f z hD hB) variable [NormedSpace ℂ E] /-- When the function `f` is bounded above on a vertical strip, then so is `F`. -/ lemma F_BddAbove (f : ℂ → E) (ε : ℝ) (hε : ε > 0) (hB : BddAbove ((norm ∘ f) '' verticalClosedStrip 0 1)) : BddAbove ((norm ∘ (F f ε)) '' verticalClosedStrip 0 1) := by -- Rewriting goal simp only [F, image_congr, comp_apply, map_mul, invInterpStrip] rw [bddAbove_def] at * rcases hB with ⟨B, hB⟩ -- Using bound use ((max 1 ((ε + sSupNormIm f 0) ^ (-(1 : ℝ)))) * max 1 ((ε + sSupNormIm f 1) ^ (-(1 : ℝ)))) * B simp only [mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] intros z hset specialize hB (‖f z‖) (by simpa [image_congr, mem_image, comp_apply] using ⟨z, hset, rfl⟩) -- Proof that the bound is correct simp only [norm_smul, norm_mul, ← ofReal_add] gcongr -- Bounding individual terms · by_cases hM0_one : 1 ≤ ε + sSupNormIm f 0 -- `1 ≤ sSupNormIm f 0` · apply le_trans _ (le_max_left _ _) simp only [norm_cpow_eq_rpow_re_of_pos (sSupNormIm_eps_pos f hε 0), sub_re, one_re, Real.rpow_le_one_of_one_le_of_nonpos hM0_one (sub_nonpos.mpr hset.2)] -- `0 < sSupNormIm f 0 < 1` · rw [not_le] at hM0_one; apply le_trans _ (le_max_right _ _) simp only [norm_cpow_eq_rpow_re_of_pos (sSupNormIm_eps_pos f hε 0), sub_re, one_re] apply Real.rpow_le_rpow_of_exponent_ge (sSupNormIm_eps_pos f hε 0) (le_of_lt hM0_one) _ simp only [neg_le_sub_iff_le_add, le_add_iff_nonneg_left, hset.1] · by_cases hM1_one : 1 ≤ ε + sSupNormIm f 1 -- `1 ≤ sSupNormIm f 1` · apply le_trans _ (le_max_left _ _) simp only [norm_cpow_eq_rpow_re_of_pos (sSupNormIm_eps_pos f hε 1), sub_re, one_re, neg_re, Real.rpow_le_one_of_one_le_of_nonpos hM1_one (Right.neg_nonpos_iff.mpr hset.1)] -- `0 < sSupNormIm f 1 < 1` · rw [not_le] at hM1_one; apply le_trans _ (le_max_right _ _) simp only [norm_cpow_eq_rpow_re_of_pos (sSupNormIm_eps_pos f hε 1), sub_re, one_re, neg_re, Real.rpow_le_rpow_of_exponent_ge (sSupNormIm_eps_pos f hε 1) (le_of_lt hM1_one) (neg_le_neg_iff.mpr hset.2)] /-- Proof that `F` is bounded by one one the edges. -/ lemma F_edge_le_one (f : ℂ → E) (ε : ℝ) (hε : ε > 0) (z : ℂ) (hB : BddAbove ((norm ∘ f) '' verticalClosedStrip 0 1)) (hz : z ∈ re ⁻¹' {0, 1}) : ‖F f ε z‖ ≤ 1 := by simp only [F, norm_smul, norm_mul, norm_cpow_eq_rpow_re_of_pos, norm_invInterpStrip f z hε, sSupNormIm_eps_pos f hε 1, sub_re, one_re, neg_re] rcases hz with hz0 | hz1 -- `z.re = 0` · simp only [hz0, zero_sub, Real.rpow_neg_one, neg_zero, Real.rpow_zero, mul_one, inv_mul_le_iff₀ (sSupNormIm_eps_pos f hε 0)] rw [← hz0] apply le_of_lt (norm_lt_sSupNormIm_eps f ε hε _ _ hB) simp only [verticalClosedStrip, mem_preimage, zero_le_one, left_mem_Icc, hz0] -- `z.re = 1` · rw [mem_singleton_iff] at hz1 simp only [hz1, one_mul, Real.rpow_zero, sub_self, Real.rpow_neg_one, inv_mul_le_iff₀ (sSupNormIm_eps_pos f hε 1), mul_one] rw [← hz1] apply le_of_lt (norm_lt_sSupNormIm_eps f ε hε _ _ hB) simp only [verticalClosedStrip, mem_preimage, zero_le_one, hz1, right_mem_Icc] theorem norm_mul_invInterpStrip_le_one_of_mem_verticalClosedStrip (f : ℂ → E) (ε : ℝ) (hε : 0 < ε) (z : ℂ) (hd : DiffContOnCl ℂ f (verticalStrip 0 1)) (hB : BddAbove ((norm ∘ f) '' verticalClosedStrip 0 1)) (hz : z ∈ verticalClosedStrip 0 1) : ‖F f ε z‖ ≤ 1 := by apply PhragmenLindelof.vertical_strip (DiffContOnCl.smul (diffContOnCl_invInterpStrip f hε) hd) _ (fun x hx ↦ F_edge_le_one f ε hε x hB (Or.inl hx)) (fun x hx ↦ F_edge_le_one f ε hε x hB (Or.inr hx)) hz.1 hz.2 use 0 rw [sub_zero, div_one] refine ⟨ Real.pi_pos, ?_⟩ obtain ⟨BF, hBF⟩ := F_BddAbove f ε hε hB simp only [comp_apply, mem_upperBounds, mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] at hBF use BF rw [Asymptotics.isBigO_iff] use 1 rw [eventually_inf_principal] apply Eventually.of_forall intro x hx norm_num exact (hBF x ((preimage_mono Ioo_subset_Icc_self) hx)).trans ((le_of_lt (lt_add_one BF)).trans (Real.add_one_le_exp BF)) end invInterpStrip ----- variable {E : Type*} [NormedAddCommGroup E] (f : ℂ → E) /-- The interpolation of `sSupNormIm` on the two boundaries. In other words, this is the right side of the target inequality: `|f(z)| ≤ |M(0) ^ (1-z)| * |M(1) ^ z|`.
Note that if `sSupNormIm f 0 = 0 ∨ sSupNormIm f 1 = 0` then the power is not continuous since `0 ^ 0 = 1`. Hence the use of `ite`. -/ noncomputable def interpStrip (z : ℂ) : ℂ :=
Mathlib/Analysis/Complex/Hadamard.lean
244
247
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker -/ import Mathlib.Algebra.Ring.Associated import Mathlib.Algebra.Ring.Regular /-! # Monoids with normalization functions, `gcd`, and `lcm` This file defines extra structures on `CancelCommMonoidWithZero`s, including `IsDomain`s. ## Main Definitions * `NormalizationMonoid` * `GCDMonoid` * `NormalizedGCDMonoid` * `gcdMonoidOfGCD`, `gcdMonoidOfExistsGCD`, `normalizedGCDMonoidOfGCD`, `normalizedGCDMonoidOfExistsGCD` * `gcdMonoidOfLCM`, `gcdMonoidOfExistsLCM`, `normalizedGCDMonoidOfLCM`, `normalizedGCDMonoidOfExistsLCM` For the `NormalizedGCDMonoid` instances on `ℕ` and `ℤ`, see `Mathlib.Algebra.GCDMonoid.Nat`. ## Implementation Notes * `NormalizationMonoid` is defined by assigning to each element a `normUnit` such that multiplying by that unit normalizes the monoid, and `normalize` is an idempotent monoid homomorphism. This definition as currently implemented does casework on `0`. * `GCDMonoid` contains the definitions of `gcd` and `lcm` with the usual properties. They are both determined up to a unit. * `NormalizedGCDMonoid` extends `NormalizationMonoid`, so the `gcd` and `lcm` are always normalized. This makes `gcd`s of polynomials easier to work with, but excludes Euclidean domains, and monoids without zero. * `gcdMonoidOfGCD` and `normalizedGCDMonoidOfGCD` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from the `gcd` and its properties. * `gcdMonoidOfExistsGCD` and `normalizedGCDMonoidOfExistsGCD` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements have a (not necessarily normalized) `gcd`. * `gcdMonoidOfLCM` and `normalizedGCDMonoidOfLCM` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from the `lcm` and its properties. * `gcdMonoidOfExistsLCM` and `normalizedGCDMonoidOfExistsLCM` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements have a (not necessarily normalized) `lcm`. ## TODO * Port GCD facts about nats, definition of coprime * Generalize normalization monoids to commutative (cancellative) monoids with or without zero ## Tags divisibility, gcd, lcm, normalize -/ variable {α : Type*} /-- Normalization monoid: multiplying with `normUnit` gives a normal form for associated elements. -/ class NormalizationMonoid (α : Type*) [CancelCommMonoidWithZero α] where /-- `normUnit` assigns to each element of the monoid a unit of the monoid. -/ normUnit : α → αˣ /-- The proposition that `normUnit` maps `0` to the identity. -/ normUnit_zero : normUnit 0 = 1 /-- The proposition that `normUnit` respects multiplication of non-zero elements. -/ normUnit_mul : ∀ {a b}, a ≠ 0 → b ≠ 0 → normUnit (a * b) = normUnit a * normUnit b /-- The proposition that `normUnit` maps units to their inverses. -/ normUnit_coe_units : ∀ u : αˣ, normUnit u = u⁻¹ export NormalizationMonoid (normUnit normUnit_zero normUnit_mul normUnit_coe_units) attribute [simp] normUnit_coe_units normUnit_zero normUnit_mul section NormalizationMonoid variable [CancelCommMonoidWithZero α] [NormalizationMonoid α] @[simp] theorem normUnit_one : normUnit (1 : α) = 1 := normUnit_coe_units 1 /-- Chooses an element of each associate class, by multiplying by `normUnit` -/ def normalize : α →*₀ α where toFun x := x * normUnit x map_zero' := by simp only [normUnit_zero] exact mul_one (0 : α) map_one' := by rw [normUnit_one, one_mul]; rfl map_mul' x y := (by_cases fun hx : x = 0 => by rw [hx, zero_mul, zero_mul, zero_mul]) fun hx => (by_cases fun hy : y = 0 => by rw [hy, mul_zero, zero_mul, mul_zero]) fun hy => by simp only [normUnit_mul hx hy, Units.val_mul]; simp only [mul_assoc, mul_left_comm y] theorem associated_normalize (x : α) : Associated x (normalize x) := ⟨_, rfl⟩ theorem normalize_associated (x : α) : Associated (normalize x) x := (associated_normalize _).symm theorem associated_normalize_iff {x y : α} : Associated x (normalize y) ↔ Associated x y := ⟨fun h => h.trans (normalize_associated y), fun h => h.trans (associated_normalize y)⟩ theorem normalize_associated_iff {x y : α} : Associated (normalize x) y ↔ Associated x y := ⟨fun h => (associated_normalize _).trans h, fun h => (normalize_associated _).trans h⟩ theorem Associates.mk_normalize (x : α) : Associates.mk (normalize x) = Associates.mk x := Associates.mk_eq_mk_iff_associated.2 (normalize_associated _) theorem normalize_apply (x : α) : normalize x = x * normUnit x := rfl theorem normalize_zero : normalize (0 : α) = 0 := normalize.map_zero theorem normalize_one : normalize (1 : α) = 1 := normalize.map_one theorem normalize_coe_units (u : αˣ) : normalize (u : α) = 1 := by simp [normalize_apply] theorem normalize_eq_zero {x : α} : normalize x = 0 ↔ x = 0 := ⟨fun hx => (associated_zero_iff_eq_zero x).1 <| hx ▸ associated_normalize _, by rintro rfl; exact normalize_zero⟩ theorem normalize_eq_one {x : α} : normalize x = 1 ↔ IsUnit x := ⟨fun hx => isUnit_iff_exists_inv.2 ⟨_, hx⟩, fun ⟨u, hu⟩ => hu ▸ normalize_coe_units u⟩ @[simp] theorem normUnit_mul_normUnit (a : α) : normUnit (a * normUnit a) = 1 := by nontriviality α using Subsingleton.elim a 0 obtain rfl | h := eq_or_ne a 0 · rw [normUnit_zero, zero_mul, normUnit_zero] · rw [normUnit_mul h (Units.ne_zero _), normUnit_coe_units, mul_inv_eq_one] @[simp] theorem normalize_idem (x : α) : normalize (normalize x) = normalize x := by simp [normalize_apply] theorem normalize_eq_normalize {a b : α} (hab : a ∣ b) (hba : b ∣ a) : normalize a = normalize b := by nontriviality α rcases associated_of_dvd_dvd hab hba with ⟨u, rfl⟩ refine by_cases (by rintro rfl; simp only [zero_mul]) fun ha : a ≠ 0 => ?_ suffices a * ↑(normUnit a) = a * ↑u * ↑(normUnit a) * ↑u⁻¹ by simpa only [normalize_apply, mul_assoc, normUnit_mul ha u.ne_zero, normUnit_coe_units] calc a * ↑(normUnit a) = a * ↑(normUnit a) * ↑u * ↑u⁻¹ := (Units.mul_inv_cancel_right _ _).symm _ = a * ↑u * ↑(normUnit a) * ↑u⁻¹ := by rw [mul_right_comm a] theorem normalize_eq_normalize_iff {x y : α} : normalize x = normalize y ↔ x ∣ y ∧ y ∣ x := ⟨fun h => ⟨Units.dvd_mul_right.1 ⟨_, h.symm⟩, Units.dvd_mul_right.1 ⟨_, h⟩⟩, fun ⟨hxy, hyx⟩ => normalize_eq_normalize hxy hyx⟩ theorem dvd_antisymm_of_normalize_eq {a b : α} (ha : normalize a = a) (hb : normalize b = b) (hab : a ∣ b) (hba : b ∣ a) : a = b := ha ▸ hb ▸ normalize_eq_normalize hab hba theorem Associated.eq_of_normalized {a b : α} (h : Associated a b) (ha : normalize a = a) (hb : normalize b = b) : a = b := dvd_antisymm_of_normalize_eq ha hb h.dvd h.dvd' @[simp] theorem dvd_normalize_iff {a b : α} : a ∣ normalize b ↔ a ∣ b := Units.dvd_mul_right @[simp] theorem normalize_dvd_iff {a b : α} : normalize a ∣ b ↔ a ∣ b := Units.mul_right_dvd end NormalizationMonoid namespace Associates variable [CancelCommMonoidWithZero α] [NormalizationMonoid α] /-- Maps an element of `Associates` back to the normalized element of its associate class -/ protected def out : Associates α → α := (Quotient.lift (normalize : α → α)) fun a _ ⟨_, hu⟩ => hu ▸ normalize_eq_normalize ⟨_, rfl⟩ (Units.mul_right_dvd.2 <| dvd_refl a) @[simp] theorem out_mk (a : α) : (Associates.mk a).out = normalize a := rfl @[simp] theorem out_one : (1 : Associates α).out = 1 := normalize_one theorem out_mul (a b : Associates α) : (a * b).out = a.out * b.out := Quotient.inductionOn₂ a b fun _ _ => by simp only [Associates.quotient_mk_eq_mk, out_mk, mk_mul_mk, normalize.map_mul] theorem dvd_out_iff (a : α) (b : Associates α) : a ∣ b.out ↔ Associates.mk a ≤ b := Quotient.inductionOn b <| by simp [Associates.out_mk, Associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd] theorem out_dvd_iff (a : α) (b : Associates α) : b.out ∣ a ↔ b ≤ Associates.mk a := Quotient.inductionOn b <| by simp [Associates.out_mk, Associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd] @[simp] theorem out_top : (⊤ : Associates α).out = 0 := normalize_zero @[simp] theorem normalize_out (a : Associates α) : normalize a.out = a.out := Quotient.inductionOn a normalize_idem @[simp] theorem mk_out (a : Associates α) : Associates.mk a.out = a := Quotient.inductionOn a mk_normalize theorem out_injective : Function.Injective (Associates.out : _ → α) := Function.LeftInverse.injective mk_out end Associates /-- GCD monoid: a `CancelCommMonoidWithZero` with `gcd` (greatest common divisor) and `lcm` (least common multiple) operations, determined up to a unit. The type class focuses on `gcd` and we derive the corresponding `lcm` facts from `gcd`. -/ class GCDMonoid (α : Type*) [CancelCommMonoidWithZero α] where /-- The greatest common divisor between two elements. -/ gcd : α → α → α /-- The least common multiple between two elements. -/ lcm : α → α → α /-- The GCD is a divisor of the first element. -/ gcd_dvd_left : ∀ a b, gcd a b ∣ a /-- The GCD is a divisor of the second element. -/ gcd_dvd_right : ∀ a b, gcd a b ∣ b /-- Any common divisor of both elements is a divisor of the GCD. -/ dvd_gcd : ∀ {a b c}, a ∣ c → a ∣ b → a ∣ gcd c b /-- The product of two elements is `Associated` with the product of their GCD and LCM. -/ gcd_mul_lcm : ∀ a b, Associated (gcd a b * lcm a b) (a * b) /-- `0` is left-absorbing. -/ lcm_zero_left : ∀ a, lcm 0 a = 0 /-- `0` is right-absorbing. -/ lcm_zero_right : ∀ a, lcm a 0 = 0 /-- Normalized GCD monoid: a `CancelCommMonoidWithZero` with normalization and `gcd` (greatest common divisor) and `lcm` (least common multiple) operations. In this setting `gcd` and `lcm` form a bounded lattice on the associated elements where `gcd` is the infimum, `lcm` is the supremum, `1` is bottom, and `0` is top. The type class focuses on `gcd` and we derive the corresponding `lcm` facts from `gcd`. -/ class NormalizedGCDMonoid (α : Type*) [CancelCommMonoidWithZero α] extends NormalizationMonoid α, GCDMonoid α where /-- The GCD is normalized to itself. -/ normalize_gcd : ∀ a b, normalize (gcd a b) = gcd a b /-- The LCM is normalized to itself. -/ normalize_lcm : ∀ a b, normalize (lcm a b) = lcm a b export GCDMonoid (gcd lcm gcd_dvd_left gcd_dvd_right dvd_gcd lcm_zero_left lcm_zero_right) attribute [simp] lcm_zero_left lcm_zero_right section GCDMonoid variable [CancelCommMonoidWithZero α] instance [NormalizationMonoid α] : Nonempty (NormalizationMonoid α) := ⟨‹_›⟩ instance [GCDMonoid α] : Nonempty (GCDMonoid α) := ⟨‹_›⟩ instance [NormalizedGCDMonoid α] : Nonempty (NormalizedGCDMonoid α) := ⟨‹_›⟩ instance [h : Nonempty (NormalizedGCDMonoid α)] : Nonempty (NormalizationMonoid α) := h.elim fun _ ↦ inferInstance instance [h : Nonempty (NormalizedGCDMonoid α)] : Nonempty (GCDMonoid α) := h.elim fun _ ↦ inferInstance theorem gcd_isUnit_iff_isRelPrime [GCDMonoid α] {a b : α} : IsUnit (gcd a b) ↔ IsRelPrime a b := ⟨fun h _ ha hb ↦ isUnit_of_dvd_unit (dvd_gcd ha hb) h, (· (gcd_dvd_left a b) (gcd_dvd_right a b))⟩ @[simp] theorem normalize_gcd [NormalizedGCDMonoid α] : ∀ a b : α, normalize (gcd a b) = gcd a b := NormalizedGCDMonoid.normalize_gcd theorem gcd_mul_lcm [GCDMonoid α] : ∀ a b : α, Associated (gcd a b * lcm a b) (a * b) := GCDMonoid.gcd_mul_lcm section GCD theorem dvd_gcd_iff [GCDMonoid α] (a b c : α) : a ∣ gcd b c ↔ a ∣ b ∧ a ∣ c := Iff.intro (fun h => ⟨h.trans (gcd_dvd_left _ _), h.trans (gcd_dvd_right _ _)⟩) fun ⟨hab, hac⟩ => dvd_gcd hab hac theorem gcd_comm [NormalizedGCDMonoid α] (a b : α) : gcd a b = gcd b a := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) theorem gcd_comm' [GCDMonoid α] (a b : α) : Associated (gcd a b) (gcd b a) := associated_of_dvd_dvd (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) theorem gcd_assoc [NormalizedGCDMonoid α] (m n k : α) : gcd (gcd m n) k = gcd m (gcd n k) := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n)) (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k))) (dvd_gcd (dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k))) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k))) theorem gcd_assoc' [GCDMonoid α] (m n k : α) : Associated (gcd (gcd m n) k) (gcd m (gcd n k)) := associated_of_dvd_dvd (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n)) (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k))) (dvd_gcd (dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k))) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k))) instance [NormalizedGCDMonoid α] : Std.Commutative (α := α) gcd where comm := gcd_comm instance [NormalizedGCDMonoid α] : Std.Associative (α := α) gcd where assoc := gcd_assoc theorem gcd_eq_normalize [NormalizedGCDMonoid α] {a b c : α} (habc : gcd a b ∣ c) (hcab : c ∣ gcd a b) : gcd a b = normalize c := normalize_gcd a b ▸ normalize_eq_normalize habc hcab @[simp] theorem gcd_zero_left [NormalizedGCDMonoid α] (a : α) : gcd 0 a = normalize a := gcd_eq_normalize (gcd_dvd_right 0 a) (dvd_gcd (dvd_zero _) (dvd_refl a)) theorem gcd_zero_left' [GCDMonoid α] (a : α) : Associated (gcd 0 a) a := associated_of_dvd_dvd (gcd_dvd_right 0 a) (dvd_gcd (dvd_zero _) (dvd_refl a)) @[simp] theorem gcd_zero_right [NormalizedGCDMonoid α] (a : α) : gcd a 0 = normalize a := gcd_eq_normalize (gcd_dvd_left a 0) (dvd_gcd (dvd_refl a) (dvd_zero _)) theorem gcd_zero_right' [GCDMonoid α] (a : α) : Associated (gcd a 0) a := associated_of_dvd_dvd (gcd_dvd_left a 0) (dvd_gcd (dvd_refl a) (dvd_zero _)) @[simp] theorem gcd_eq_zero_iff [GCDMonoid α] (a b : α) : gcd a b = 0 ↔ a = 0 ∧ b = 0 := Iff.intro (fun h => by let ⟨ca, ha⟩ := gcd_dvd_left a b let ⟨cb, hb⟩ := gcd_dvd_right a b rw [h, zero_mul] at ha hb exact ⟨ha, hb⟩) fun ⟨ha, hb⟩ => by rw [ha, hb, ← zero_dvd_iff] apply dvd_gcd <;> rfl theorem gcd_ne_zero_of_left [GCDMonoid α] {a b : α} (ha : a ≠ 0) : gcd a b ≠ 0 := by simp_all theorem gcd_ne_zero_of_right [GCDMonoid α] {a b : α} (hb : b ≠ 0) : gcd a b ≠ 0 := by simp_all @[simp] theorem gcd_one_left [NormalizedGCDMonoid α] (a : α) : gcd 1 a = 1 := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_left _ _) (one_dvd _) @[simp] theorem isUnit_gcd_one_left [GCDMonoid α] (a : α) : IsUnit (gcd 1 a) := isUnit_of_dvd_one (gcd_dvd_left _ _) theorem gcd_one_left' [GCDMonoid α] (a : α) : Associated (gcd 1 a) 1 := by simp @[simp] theorem gcd_one_right [NormalizedGCDMonoid α] (a : α) : gcd a 1 = 1 := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_right _ _) (one_dvd _) @[simp] theorem isUnit_gcd_one_right [GCDMonoid α] (a : α) : IsUnit (gcd a 1) := isUnit_of_dvd_one (gcd_dvd_right _ _) theorem gcd_one_right' [GCDMonoid α] (a : α) : Associated (gcd a 1) 1 := by simp theorem gcd_dvd_gcd [GCDMonoid α] {a b c d : α} (hab : a ∣ b) (hcd : c ∣ d) : gcd a c ∣ gcd b d := dvd_gcd ((gcd_dvd_left _ _).trans hab) ((gcd_dvd_right _ _).trans hcd) protected theorem Associated.gcd [GCDMonoid α] {a₁ a₂ b₁ b₂ : α} (ha : Associated a₁ a₂) (hb : Associated b₁ b₂) : Associated (gcd a₁ b₁) (gcd a₂ b₂) := associated_of_dvd_dvd (gcd_dvd_gcd ha.dvd hb.dvd) (gcd_dvd_gcd ha.dvd' hb.dvd') @[simp] theorem gcd_same [NormalizedGCDMonoid α] (a : α) : gcd a a = normalize a := gcd_eq_normalize (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) (dvd_refl a)) @[simp] theorem gcd_mul_left [NormalizedGCDMonoid α] (a b c : α) : gcd (a * b) (a * c) = normalize a * gcd b c := (by_cases (by rintro rfl; simp only [zero_mul, gcd_zero_left, normalize_zero])) fun ha : a ≠ 0 => suffices gcd (a * b) (a * c) = normalize (a * gcd b c) by simpa let ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c) gcd_eq_normalize (eq.symm ▸ mul_dvd_mul_left a (show d ∣ gcd b c from dvd_gcd ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_left _ _)
((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_right _ _))) (dvd_gcd (mul_dvd_mul_left a <| gcd_dvd_left _ _) (mul_dvd_mul_left a <| gcd_dvd_right _ _)) theorem gcd_mul_left' [GCDMonoid α] (a b c : α) : Associated (gcd (a * b) (a * c)) (a * gcd b c) := by obtain rfl | ha := eq_or_ne a 0 · simp only [zero_mul, gcd_zero_left'] obtain ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c) apply associated_of_dvd_dvd · rw [eq]
Mathlib/Algebra/GCDMonoid/Basic.lean
403
412
/- Copyright (c) 2019 Calle Sönne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Calle Sönne -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Normed.Group.AddCircle import Mathlib.Algebra.CharZero.Quotient import Mathlib.Topology.Instances.Sign /-! # The type of angles In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas about trigonometric functions and angles. -/ open Real noncomputable section namespace Real /-- The type of angles -/ def Angle : Type := AddCircle (2 * π) -- The `NormedAddCommGroup, Inhabited` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 namespace Angle instance : NormedAddCommGroup Angle := inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π))) instance : Inhabited Angle := inferInstanceAs (Inhabited (AddCircle (2 * π))) /-- The canonical map from `ℝ` to the quotient `Angle`. -/ @[coe] protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r instance : Coe ℝ Angle := ⟨Angle.coe⟩ instance : CircularOrder Real.Angle := QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩) @[continuity] theorem continuous_coe : Continuous ((↑) : ℝ → Angle) := continuous_quotient_mk' /-- Coercion `ℝ → Angle` as an additive homomorphism. -/ def coeHom : ℝ →+ Angle := QuotientAddGroup.mk' _ @[simp] theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) := rfl /-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with `induction θ using Real.Angle.induction_on`. -/ @[elab_as_elim] protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ := Quotient.inductionOn' θ h @[simp] theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) := rfl @[simp] theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) := rfl @[simp] theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) := rfl @[simp] theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) := rfl theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) := rfl theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) := rfl theorem coe_eq_zero_iff {x : ℝ} : (x : Angle) = 0 ↔ ∃ n : ℤ, n • (2 * π) = x := AddCircle.coe_eq_zero_iff (2 * π) @[simp, norm_cast] theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n @[simp, norm_cast] theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] rw [Angle.coe, Angle.coe, QuotientAddGroup.eq] simp only [AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] @[simp] theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) := angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩ @[simp] theorem neg_coe_pi : -(π : Angle) = π := by rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub] use -1 simp [two_mul, sub_eq_add_neg] @[simp] theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_nsmul, two_nsmul, add_halves] @[simp] theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_zsmul, two_zsmul, add_halves] theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi] theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two] theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by rw [sub_eq_add_neg, neg_coe_pi] @[simp] theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul] @[simp] theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul] @[simp] theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi] theorem zsmul_eq_iff {ψ θ : Angle} {z : ℤ} (hz : z ≠ 0) : z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ) := QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) : n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) := QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by have : Int.natAbs 2 = 2 := rfl rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero, Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two, mul_div_cancel_left₀ (_ : ℝ) two_ne_zero] theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff] theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by convert two_nsmul_eq_iff <;> simp theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_nsmul_eq_zero_iff] theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff] theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_zsmul_eq_zero_iff] theorem eq_neg_self_iff {θ : Angle} : θ = -θ ↔ θ = 0 ∨ θ = π := by rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff] theorem ne_neg_self_iff {θ : Angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← eq_neg_self_iff.not] theorem neg_eq_self_iff {θ : Angle} : -θ = θ ↔ θ = 0 ∨ θ = π := by rw [eq_comm, eq_neg_self_iff] theorem neg_ne_self_iff {θ : Angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← neg_eq_self_iff.not] theorem two_nsmul_eq_pi_iff {θ : Angle} : (2 : ℕ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by have h : (π : Angle) = ((2 : ℕ) • (π / 2 : ℝ):) := by rw [two_nsmul, add_halves] nth_rw 1 [h] rw [coe_nsmul, two_nsmul_eq_iff] -- Porting note: `congr` didn't simplify the goal of iff of `Or`s convert Iff.rfl rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc, add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero] theorem two_zsmul_eq_pi_iff {θ : Angle} : (2 : ℤ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff] theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) = -ψ := by constructor · intro Hcos rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false (two_ne_zero' ℝ), false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩) · right rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero] · left rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero, zero_add] · rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero] rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] theorem sin_eq_iff_coe_eq_or_add_eq_pi {θ ψ : ℝ} : sin θ = sin ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) + ψ = π := by constructor · intro Hsin rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h | h · left rw [coe_sub, coe_sub] at h exact sub_right_inj.1 h right rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h exact h.symm · rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] have H' : θ + ψ = 2 * k * π + π := by rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ← mul_assoc] at H rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : Angle) = ψ := by rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc | hc; · exact hc rcases sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs | hs; · exact hs rw [eq_neg_iff_add_eq_zero, hs] at hc obtain ⟨n, hn⟩ : ∃ n, n • _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc) rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero, eq_false (ne_of_gt pi_pos), or_false, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one, ← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn have : (n * 2 + 1) % (2 : ℤ) = 0 % (2 : ℤ) := congr_arg (· % (2 : ℤ)) hn rw [add_comm, Int.add_mul_emod_self_right] at this exact absurd this one_ne_zero /-- The sine of a `Real.Angle`. -/ def sin (θ : Angle) : ℝ := sin_periodic.lift θ @[simp] theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x := rfl @[continuity] theorem continuous_sin : Continuous sin := Real.continuous_sin.quotient_liftOn' _ /-- The cosine of a `Real.Angle`. -/ def cos (θ : Angle) : ℝ := cos_periodic.lift θ @[simp] theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x := rfl @[continuity] theorem continuous_cos : Continuous cos := Real.continuous_cos.quotient_liftOn' _ theorem cos_eq_real_cos_iff_eq_or_eq_neg {θ : Angle} {ψ : ℝ} : cos θ = Real.cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction θ using Real.Angle.induction_on exact cos_eq_iff_coe_eq_or_eq_neg theorem cos_eq_iff_eq_or_eq_neg {θ ψ : Angle} : cos θ = cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction ψ using Real.Angle.induction_on exact cos_eq_real_cos_iff_eq_or_eq_neg theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {θ : Angle} {ψ : ℝ} : sin θ = Real.sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction θ using Real.Angle.induction_on exact sin_eq_iff_coe_eq_or_add_eq_pi theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : Angle} : sin θ = sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction ψ using Real.Angle.induction_on exact sin_eq_real_sin_iff_eq_or_add_eq_pi @[simp] theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero] theorem sin_coe_pi : sin (π : Angle) = 0 := by rw [sin_coe, Real.sin_pi] theorem sin_eq_zero_iff {θ : Angle} : sin θ = 0 ↔ θ = 0 ∨ θ = π := by nth_rw 1 [← sin_zero] rw [sin_eq_iff_eq_or_add_eq_pi] simp theorem sin_ne_zero_iff {θ : Angle} : sin θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← sin_eq_zero_iff] @[simp] theorem sin_neg (θ : Angle) : sin (-θ) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.sin_neg _ theorem sin_antiperiodic : Function.Antiperiodic sin (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.sin_antiperiodic _ @[simp] theorem sin_add_pi (θ : Angle) : sin (θ + π) = -sin θ := sin_antiperiodic θ @[simp] theorem sin_sub_pi (θ : Angle) : sin (θ - π) = -sin θ := sin_antiperiodic.sub_eq θ @[simp] theorem cos_zero : cos (0 : Angle) = 1 := by rw [← coe_zero, cos_coe, Real.cos_zero] theorem cos_coe_pi : cos (π : Angle) = -1 := by rw [cos_coe, Real.cos_pi] @[simp] theorem cos_neg (θ : Angle) : cos (-θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.cos_neg _ theorem cos_antiperiodic : Function.Antiperiodic cos (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.cos_antiperiodic _ @[simp] theorem cos_add_pi (θ : Angle) : cos (θ + π) = -cos θ := cos_antiperiodic θ @[simp] theorem cos_sub_pi (θ : Angle) : cos (θ - π) = -cos θ := cos_antiperiodic.sub_eq θ theorem cos_eq_zero_iff {θ : Angle} : cos θ = 0 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [← cos_pi_div_two, ← cos_coe, cos_eq_iff_eq_or_eq_neg, ← coe_neg, ← neg_div] theorem sin_add (θ₁ θ₂ : Real.Angle) : sin (θ₁ + θ₂) = sin θ₁ * cos θ₂ + cos θ₁ * sin θ₂ := by induction θ₁ using Real.Angle.induction_on induction θ₂ using Real.Angle.induction_on exact Real.sin_add _ _ theorem cos_add (θ₁ θ₂ : Real.Angle) : cos (θ₁ + θ₂) = cos θ₁ * cos θ₂ - sin θ₁ * sin θ₂ := by induction θ₂ using Real.Angle.induction_on induction θ₁ using Real.Angle.induction_on exact Real.cos_add _ _ @[simp] theorem cos_sq_add_sin_sq (θ : Real.Angle) : cos θ ^ 2 + sin θ ^ 2 = 1 := by induction θ using Real.Angle.induction_on exact Real.cos_sq_add_sin_sq _ theorem sin_add_pi_div_two (θ : Angle) : sin (θ + ↑(π / 2)) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_add_pi_div_two _ theorem sin_sub_pi_div_two (θ : Angle) : sin (θ - ↑(π / 2)) = -cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_sub_pi_div_two _ theorem sin_pi_div_two_sub (θ : Angle) : sin (↑(π / 2) - θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_pi_div_two_sub _ theorem cos_add_pi_div_two (θ : Angle) : cos (θ + ↑(π / 2)) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_add_pi_div_two _ theorem cos_sub_pi_div_two (θ : Angle) : cos (θ - ↑(π / 2)) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_sub_pi_div_two _ theorem cos_pi_div_two_sub (θ : Angle) : cos (↑(π / 2) - θ) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_pi_div_two_sub _ theorem abs_sin_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |sin θ| = |sin ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [sin_add_pi, abs_neg] theorem abs_sin_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |sin θ| = |sin ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h
exact abs_sin_eq_of_two_nsmul_eq h
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
402
402
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Simon Hudon -/ import Mathlib.Control.Functor.Multivariate import Mathlib.Data.PFunctor.Multivariate.Basic import Mathlib.Data.PFunctor.Multivariate.M import Mathlib.Data.QPF.Multivariate.Basic /-! # The final co-algebra of a multivariate qpf is again a qpf. For a `(n+1)`-ary QPF `F (α₀,..,αₙ)`, we take the least fixed point of `F` with regards to its last argument `αₙ`. The result is an `n`-ary functor: `Fix F (α₀,..,αₙ₋₁)`. Making `Fix F` into a functor allows us to take the fixed point, compose with other functors and take a fixed point again. ## Main definitions * `Cofix.mk` - constructor * `Cofix.dest` - destructor * `Cofix.corec` - corecursor: useful for formulating infinite, productive computations * `Cofix.bisim` - bisimulation: proof technique to show the equality of possibly infinite values of `Cofix F α` ## Implementation notes For `F` a QPF, we define `Cofix F α` in terms of the M-type of the polynomial functor `P` of `F`. We define the relation `Mcongr` and take its quotient as the definition of `Cofix F α`. `Mcongr` is taken as the weakest bisimulation on M-type. See [avigad-carneiro-hudon2019] for more details. ## Reference * Jeremy Avigad, Mario M. Carneiro and Simon Hudon. [*Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019] -/ universe u open MvFunctor namespace MvQPF open TypeVec MvPFunctor open MvFunctor (LiftP LiftR) variable {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] /-- `corecF` is used as a basis for defining the corecursor of `Cofix F α`. `corecF` uses corecursion to construct the M-type generated by `q.P` and uses function on `F` as a corecursive step -/ def corecF {α : TypeVec n} {β : Type u} (g : β → F (α.append1 β)) : β → q.P.M α := M.corec _ fun x => repr (g x) theorem corecF_eq {α : TypeVec n} {β : Type u} (g : β → F (α.append1 β)) (x : β) : M.dest q.P (corecF g x) = appendFun id (corecF g) <$$> repr (g x) := by rw [corecF, M.dest_corec] /-- Characterization of desirable equivalence relations on M-types -/ def IsPrecongr {α : TypeVec n} (r : q.P.M α → q.P.M α → Prop) : Prop := ∀ ⦃x y⦄, r x y → abs (appendFun id (Quot.mk r) <$$> M.dest q.P x) = abs (appendFun id (Quot.mk r) <$$> M.dest q.P y) /-- Equivalence relation on M-types representing a value of type `Cofix F` -/ def Mcongr {α : TypeVec n} (x y : q.P.M α) : Prop := ∃ r, IsPrecongr r ∧ r x y /-- Greatest fixed point of functor F. The result is a functor with one fewer parameters than the input. For `F a b c` a ternary functor, fix F is a binary functor such that ```lean Cofix F a b = F a b (Cofix F a b) ``` -/ def Cofix (F : TypeVec (n + 1) → Type u) [MvQPF F] (α : TypeVec n) := Quot (@Mcongr _ F _ α) instance {α : TypeVec n} [Inhabited q.P.A] [∀ i : Fin2 n, Inhabited (α i)] : Inhabited (Cofix F α) := ⟨Quot.mk _ default⟩ /-- maps every element of the W type to a canonical representative -/ def mRepr {α : TypeVec n} : q.P.M α → q.P.M α := corecF (abs ∘ M.dest q.P) /-- the map function for the functor `Cofix F` -/ def Cofix.map {α β : TypeVec n} (g : α ⟹ β) : Cofix F α → Cofix F β := Quot.lift (fun x : q.P.M α => Quot.mk Mcongr (g <$$> x)) (by rintro aa₁ aa₂ ⟨r, pr, ra₁a₂⟩; apply Quot.sound let r' b₁ b₂ := ∃ a₁ a₂ : q.P.M α, r a₁ a₂ ∧ b₁ = g <$$> a₁ ∧ b₂ = g <$$> a₂ use r'; constructor · show IsPrecongr r' rintro b₁ b₂ ⟨a₁, a₂, ra₁a₂, b₁eq, b₂eq⟩ let u : Quot r → Quot r' := Quot.lift (fun x : q.P.M α => Quot.mk r' (g <$$> x)) (by intro a₁ a₂ ra₁a₂ apply Quot.sound exact ⟨a₁, a₂, ra₁a₂, rfl, rfl⟩) have hu : (Quot.mk r' ∘ fun x : q.P.M α => g <$$> x) = u ∘ Quot.mk r := by ext x rfl rw [b₁eq, b₂eq, M.dest_map, M.dest_map, ← q.P.comp_map, ← q.P.comp_map] rw [← appendFun_comp, id_comp, hu, ← comp_id g, appendFun_comp] rw [q.P.comp_map, q.P.comp_map, abs_map, pr ra₁a₂, ← abs_map] show r' (g <$$> aa₁) (g <$$> aa₂); exact ⟨aa₁, aa₂, ra₁a₂, rfl, rfl⟩) instance Cofix.mvfunctor : MvFunctor (Cofix F) where map := @Cofix.map _ _ _ /-- Corecursor for `Cofix F` -/ def Cofix.corec {α : TypeVec n} {β : Type u} (g : β → F (α.append1 β)) : β → Cofix F α := fun x => Quot.mk _ (corecF g x) /-- Destructor for `Cofix F` -/ def Cofix.dest {α : TypeVec n} : Cofix F α → F (α.append1 (Cofix F α)) := Quot.lift (fun x => appendFun id (Quot.mk Mcongr) <$$> abs (M.dest q.P x)) (by rintro x y ⟨r, pr, rxy⟩ dsimp have : ∀ x y, r x y → Mcongr x y := by intro x y h exact ⟨r, pr, h⟩ rw [← Quot.factor_mk_eq _ _ this] conv => lhs rw [appendFun_comp_id, comp_map, ← abs_map, pr rxy, abs_map, ← comp_map, ← appendFun_comp_id]) /-- Abstraction function for `cofix F α` -/ def Cofix.abs {α} : q.P.M α → Cofix F α := Quot.mk _ /-- Representation function for `Cofix F α` -/ def Cofix.repr {α} : Cofix F α → q.P.M α := M.corec _ <| q.repr ∘ Cofix.dest /-- Corecursor for `Cofix F` -/ def Cofix.corec'₁ {α : TypeVec n} {β : Type u} (g : ∀ {X}, (β → X) → F (α.append1 X)) (x : β) : Cofix F α := Cofix.corec (fun _ => g id) x /-- More flexible corecursor for `Cofix F`. Allows the return of a fully formed value instead of making a recursive call -/ def Cofix.corec' {α : TypeVec n} {β : Type u} (g : β → F (α.append1 (Cofix F α ⊕ β))) (x : β) : Cofix F α := let f : (α ::: Cofix F α) ⟹ (α ::: (Cofix F α ⊕ β)) := id ::: Sum.inl Cofix.corec (Sum.elim (MvFunctor.map f ∘ Cofix.dest) g) (Sum.inr x : Cofix F α ⊕ β) /-- Corecursor for `Cofix F`. The shape allows recursive calls to look like recursive calls. -/ def Cofix.corec₁ {α : TypeVec n} {β : Type u} (g : ∀ {X}, (Cofix F α → X) → (β → X) → β → F (α ::: X)) (x : β) : Cofix F α := Cofix.corec' (fun x => g Sum.inl Sum.inr x) x theorem Cofix.dest_corec {α : TypeVec n} {β : Type u} (g : β → F (α.append1 β)) (x : β) : Cofix.dest (Cofix.corec g x) = appendFun id (Cofix.corec g) <$$> g x := by conv => lhs rw [Cofix.dest, Cofix.corec] dsimp rw [corecF_eq, abs_map, abs_repr, ← comp_map, ← appendFun_comp]; rfl /-- constructor for `Cofix F` -/ def Cofix.mk {α : TypeVec n} : F (α.append1 <| Cofix F α) → Cofix F α := Cofix.corec fun x => (appendFun id fun i : Cofix F α => Cofix.dest.{u} i) <$$> x /-! ## Bisimulation principles for `Cofix F` The following theorems are bisimulation principles. The general idea is to use a bisimulation relation to prove the equality between specific values of type `Cofix F α`. A bisimulation relation `R` for values `x y : Cofix F α`: * holds for `x y`: `R x y` * for any values `x y` that satisfy `R`, their root has the same shape and their children can be paired in such a way that they satisfy `R`. -/ private theorem Cofix.bisim_aux {α : TypeVec n} (r : Cofix F α → Cofix F α → Prop) (h' : ∀ x, r x x) (h : ∀ x y, r x y → appendFun id (Quot.mk r) <$$> Cofix.dest x = appendFun id (Quot.mk r) <$$> Cofix.dest y) : ∀ x y, r x y → x = y := by intro x rcases x; clear x; rename M (P F) α => x intro y rcases y; clear y; rename M (P F) α => y intro rxy apply Quot.sound let r' := fun x y => r (Quot.mk _ x) (Quot.mk _ y) have hr' : r' = fun x y => r (Quot.mk _ x) (Quot.mk _ y) := rfl have : IsPrecongr r' := by intro a b r'ab have h₀ : appendFun id (Quot.mk r ∘ Quot.mk Mcongr) <$$> MvQPF.abs (M.dest q.P a) = appendFun id (Quot.mk r ∘ Quot.mk Mcongr) <$$> MvQPF.abs (M.dest q.P b) := by rw [appendFun_comp_id, comp_map, comp_map]; exact h _ _ r'ab have h₁ : ∀ u v : q.P.M α, Mcongr u v → Quot.mk r' u = Quot.mk r' v := by intro u v cuv apply Quot.sound dsimp [r', hr'] rw [Quot.sound cuv] apply h' let f : Quot r → Quot r' := Quot.lift (Quot.lift (Quot.mk r') h₁) (by intro c apply Quot.inductionOn (motive := fun c => ∀b, r c b → Quot.lift (Quot.mk r') h₁ c = Quot.lift (Quot.mk r') h₁ b) c clear c intro c d apply Quot.inductionOn (motive := fun d => r (Quot.mk Mcongr c) d → Quot.lift (Quot.mk r') h₁ (Quot.mk Mcongr c) = Quot.lift (Quot.mk r') h₁ d) d clear d intro d rcd; apply Quot.sound; apply rcd) have : f ∘ Quot.mk r ∘ Quot.mk Mcongr = Quot.mk r' := rfl rw [← this, appendFun_comp_id, q.P.comp_map, q.P.comp_map, abs_map, abs_map, abs_map, abs_map, h₀] exact ⟨r', this, rxy⟩ /-- Bisimulation principle using `map` and `Quot.mk` to match and relate children of two trees. -/ theorem Cofix.bisim_rel {α : TypeVec n} (r : Cofix F α → Cofix F α → Prop) (h : ∀ x y, r x y → appendFun id (Quot.mk r) <$$> Cofix.dest x = appendFun id (Quot.mk r) <$$> Cofix.dest y) : ∀ x y, r x y → x = y := by let r' (x y) := x = y ∨ r x y intro x y rxy apply Cofix.bisim_aux r' · intro x left rfl · intro x y r'xy cases r'xy with | inl h => rw [h] | inr r'xy => have : ∀ x y, r x y → r' x y := fun x y h => Or.inr h rw [← Quot.factor_mk_eq _ _ this] dsimp [r'] rw [appendFun_comp_id] rw [@comp_map _ _ q _ _ _ (appendFun id (Quot.mk r)), @comp_map _ _ q _ _ _ (appendFun id (Quot.mk r))] rw [h _ _ r'xy] right; exact rxy /-- Bisimulation principle using `LiftR` to match and relate children of two trees. -/ theorem Cofix.bisim {α : TypeVec n} (r : Cofix F α → Cofix F α → Prop) (h : ∀ x y, r x y → LiftR (RelLast α r) (Cofix.dest x) (Cofix.dest y)) : ∀ x y, r x y → x = y := by apply Cofix.bisim_rel intro x y rxy rcases (liftR_iff (fun a b => RelLast α r b) (dest x) (dest y)).mp (h x y rxy) with ⟨a, f₀, f₁, dxeq, dyeq, h'⟩ rw [dxeq, dyeq, ← abs_map, ← abs_map, MvPFunctor.map_eq, MvPFunctor.map_eq] rw [← split_dropFun_lastFun f₀, ← split_dropFun_lastFun f₁] rw [appendFun_comp_splitFun, appendFun_comp_splitFun] rw [id_comp, id_comp] congr 2 with (i j); rcases i with - | i · apply Quot.sound apply h' _ j · change f₀ _ j = f₁ _ j apply h' _ j open MvFunctor /-- Bisimulation principle using `LiftR'` to match and relate children of two trees. -/ theorem Cofix.bisim₂ {α : TypeVec n} (r : Cofix F α → Cofix F α → Prop) (h : ∀ x y, r x y → LiftR' (RelLast' α r) (Cofix.dest x) (Cofix.dest y)) : ∀ x y, r x y → x = y := Cofix.bisim r <| by intros; rw [← LiftR_RelLast_iff]; apply h; assumption /-- Bisimulation principle the values `⟨a,f⟩` of the polynomial functor representing `Cofix F α` as well as an invariant `Q : β → Prop` and a state `β` generating the left-hand side and right-hand side of the equality through functions `u v : β → Cofix F α` -/ theorem Cofix.bisim' {α : TypeVec n} {β : Type*} (Q : β → Prop) (u v : β → Cofix F α) (h : ∀ x, Q x → ∃ a f' f₀ f₁, Cofix.dest (u x) = q.abs ⟨a, q.P.appendContents f' f₀⟩ ∧ Cofix.dest (v x) = q.abs ⟨a, q.P.appendContents f' f₁⟩ ∧ ∀ i, ∃ x', Q x' ∧ f₀ i = u x' ∧ f₁ i = v x') : ∀ x, Q x → u x = v x := fun x Qx => let R := fun w z : Cofix F α => ∃ x', Q x' ∧ w = u x' ∧ z = v x' Cofix.bisim R (fun x y ⟨x', Qx', xeq, yeq⟩ => by rcases h x' Qx' with ⟨a, f', f₀, f₁, ux'eq, vx'eq, h'⟩ rw [liftR_iff] refine ⟨a, q.P.appendContents f' f₀, q.P.appendContents f' f₁, xeq.symm ▸ ux'eq, yeq.symm ▸ vx'eq, ?_⟩ intro i; cases i · apply h' · intro j apply Eq.refl) _ _ ⟨x, Qx, rfl, rfl⟩ theorem Cofix.mk_dest {α : TypeVec n} (x : Cofix F α) : Cofix.mk (Cofix.dest x) = x := by apply Cofix.bisim_rel (fun x y : Cofix F α => x = Cofix.mk (Cofix.dest y)) _ _ _ rfl dsimp intro x y h rw [h] conv => lhs congr rfl rw [Cofix.mk] rw [Cofix.dest_corec] rw [← comp_map, ← appendFun_comp, id_comp] rw [← comp_map, ← appendFun_comp, id_comp, ← Cofix.mk] congr apply congrArg funext x apply Quot.sound rfl theorem Cofix.dest_mk {α : TypeVec n} (x : F (α.append1 <| Cofix F α)) : Cofix.dest (Cofix.mk x) = x := by have : Cofix.mk ∘ Cofix.dest = @_root_.id (Cofix F α) := funext Cofix.mk_dest rw [Cofix.mk, Cofix.dest_corec, ← comp_map, ← Cofix.mk, ← appendFun_comp, this, id_comp, appendFun_id_id, MvFunctor.id_map] theorem Cofix.ext {α : TypeVec n} (x y : Cofix F α) (h : x.dest = y.dest) : x = y := by rw [← Cofix.mk_dest x, h, Cofix.mk_dest] theorem Cofix.ext_mk {α : TypeVec n} (x y : F (α ::: Cofix F α)) (h : Cofix.mk x = Cofix.mk y) : x = y := by rw [← Cofix.dest_mk x, h, Cofix.dest_mk] /-! `liftR_map`, `liftR_map_last` and `liftR_map_last'` are useful for reasoning about the induction step in bisimulation proofs. -/ section LiftRMap theorem liftR_map {α β : TypeVec n} {F' : TypeVec n → Type u} [MvFunctor F'] [LawfulMvFunctor F'] (R : β ⊗ β ⟹ «repeat» n Prop) (x : F' α) (f g : α ⟹ β) (h : α ⟹ Subtype_ R) (hh : subtypeVal _ ⊚ h = (f ⊗' g) ⊚ prod.diag) : LiftR' R (f <$$> x) (g <$$> x) := by rw [LiftR_def] exists h <$$> x rw [MvFunctor.map_map, comp_assoc, hh, ← comp_assoc, fst_prod_mk, comp_assoc, fst_diag] rw [MvFunctor.map_map, comp_assoc, hh, ← comp_assoc, snd_prod_mk, comp_assoc, snd_diag] dsimp [LiftR']; constructor <;> rfl open Function theorem liftR_map_last [lawful : LawfulMvFunctor F] {α : TypeVec n} {ι ι'} (R : ι' → ι' → Prop) (x : F (α ::: ι)) (f g : ι → ι') (hh : ∀ x : ι, R (f x) (g x)) : LiftR' (RelLast' _ R) ((id ::: f) <$$> x) ((id ::: g) <$$> x) := let h : ι → { x : ι' × ι' // uncurry R x } := fun x => ⟨(f x, g x), hh x⟩ let b : (α ::: ι) ⟹ _ := @diagSub n α ::: h let c : (Subtype_ α.repeatEq ::: { x // uncurry R x }) ⟹ ((fun i : Fin2 n => { x // ofRepeat (α.RelLast' R i.fs x) }) ::: Subtype (uncurry R)) := ofSubtype _ ::: id have hh : subtypeVal _ ⊚ toSubtype _ ⊚ fromAppend1DropLast ⊚ c ⊚ b = ((id ::: f) ⊗' (id ::: g)) ⊚ prod.diag := by dsimp [b] apply eq_of_drop_last_eq · dsimp simp only [prod_map_id, dropFun_prod, dropFun_appendFun, dropFun_diag, TypeVec.id_comp, dropFun_toSubtype] erw [toSubtype_of_subtype_assoc, TypeVec.id_comp] clear liftR_map_last q lawful F x R f g hh h b c ext (i x) : 2 induction i with | fz => rfl | fs _ ih => apply ih simp only [lastFun_from_append1_drop_last, lastFun_toSubtype, lastFun_appendFun, lastFun_subtypeVal, Function.id_comp, lastFun_comp, lastFun_prod] ext1 rfl liftR_map _ _ _ _ (toSubtype _ ⊚ fromAppend1DropLast ⊚ c ⊚ b) hh theorem liftR_map_last' [LawfulMvFunctor F] {α : TypeVec n} {ι} (R : ι → ι → Prop) (x : F (α ::: ι)) (f : ι → ι) (hh : ∀ x : ι, R (f x) x) : LiftR' (RelLast' _ R) ((id ::: f) <$$> x) x := by have := liftR_map_last R x f id hh rwa [appendFun_id_id, MvFunctor.id_map] at this end LiftRMap variable {F : TypeVec (n + 1) → Type u} [q : MvQPF F] theorem Cofix.abs_repr {α} (x : Cofix F α) : Quot.mk _ (Cofix.repr x) = x := by let R := fun x y : Cofix F α => abs (repr y) = x refine Cofix.bisim₂ R ?_ _ _ rfl clear x rintro x y h subst h dsimp [Cofix.dest, Cofix.abs] induction y using Quot.ind simp only [Cofix.repr, M.dest_corec, abs_map, MvQPF.abs_repr, Function.comp] conv => congr; rfl; rw [Cofix.dest] rw [MvFunctor.map_map, MvFunctor.map_map, ← appendFun_comp_id, ← appendFun_comp_id] apply liftR_map_last intros rfl end MvQPF namespace Mathlib.Tactic.MvBisim open Lean Expr Elab Term Tactic Meta Qq /-- tactic for proof by bisimulation -/ syntax "mv_bisim" (ppSpace colGt term) (" with" (ppSpace colGt binderIdent)+)? : tactic
elab_rules : tactic | `(tactic| mv_bisim $e $[ with $ids:binderIdent*]?) => do let ids : TSyntaxArray `Lean.binderIdent := ids.getD #[] let idsn (n : ℕ) : Name :=
Mathlib/Data/QPF/Multivariate/Constructions/Cofix.lean
422
425
/- 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.RingEquiv import Mathlib.Data.Finite.Prod import Mathlib.Data.Matrix.Mul import Mathlib.LinearAlgebra.Pi /-! # Matrices This file contains basic results on matrices including bundled versions of matrix operators. ## 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. -/ assert_not_exists Star universe u u' v w variable {l m n o : Type*} {m' : o → Type*} {n' : o → Type*} variable {R : Type*} {S : Type*} {α : Type v} {β : Type w} {γ : Type*} namespace Matrix 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 → α)) section variable (R) /-- This is `Matrix.of` bundled as a linear equivalence. -/ def ofLinearEquiv [Semiring R] [AddCommMonoid α] [Module R α] : (m → n → α) ≃ₗ[R] Matrix m n α where __ := ofAddEquiv map_smul' _ _ := rfl @[simp] lemma coe_ofLinearEquiv [Semiring R] [AddCommMonoid α] [Module R α] : ⇑(ofLinearEquiv _ : (m → n → α) ≃ₗ[R] Matrix m n α) = of := rfl @[simp] lemma coe_ofLinearEquiv_symm [Semiring R] [AddCommMonoid α] [Module R α] : ⇑((ofLinearEquiv _).symm : Matrix m n α ≃ₗ[R] (m → n → α)) = of.symm := rfl end 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 _) end Matrix open Matrix namespace Matrix section Diagonal variable [DecidableEq n] 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 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 } variable {n α R} section One variable [Zero α] [One α] lemma zero_le_one_elem [Preorder α] [ZeroLEOneClass α] (i j : n) : 0 ≤ (1 : Matrix n n α) i j := by by_cases hi : i = j · subst hi simp · simp [hi] lemma zero_le_one_row [Preorder α] [ZeroLEOneClass α] (i : n) : 0 ≤ (1 : Matrix n n α) i := zero_le_one_elem i end One end Diagonal section Diag 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 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 } variable {n α R} @[simp] theorem diag_list_sum [AddMonoid α] (l : List (Matrix n n α)) : diag l.sum = (l.map diag).sum := map_list_sum (diagAddMonoidHom n α) l @[simp] theorem diag_multiset_sum [AddCommMonoid α] (s : Multiset (Matrix n n α)) : diag s.sum = (s.map diag).sum := map_multiset_sum (diagAddMonoidHom n α) s @[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 end Diag open Matrix section AddCommMonoid variable [AddCommMonoid α] [Mul α] end AddCommMonoid section NonAssocSemiring variable [NonAssocSemiring α] 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 } end NonAssocSemiring 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 /-- 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 α section Scalar variable [DecidableEq n] [Fintype n] @[simp] theorem scalar_apply (a : α) : scalar n a = diagonal fun _ => a := rfl theorem scalar_inj [Nonempty n] {r s : α} : scalar n r = scalar n s ↔ r = s := (diagonal_injective.comp Function.const_injective).eq_iff 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 _ end Scalar end Semiring section Algebra variable [Fintype n] [DecidableEq n] variable [CommSemiring R] [Semiring α] [Semiring β] [Algebra R α] [Algebra R β] instance instAlgebra : Algebra R (Matrix n n α) where algebraMap := (Matrix.scalar n).comp (algebraMap R α) commutes' _ _ := scalar_commute _ (fun _ => Algebra.commutes _ _) _ smul_def' r x := by ext; simp [Matrix.scalar, Algebra.smul_def r] 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.algebraMap, Matrix.scalar] split_ifs with h <;> simp [h, Matrix.one_apply_ne] theorem algebraMap_eq_diagonal (r : R) : algebraMap R (Matrix n n α) r = diagonal (algebraMap R (n → α) r) := rfl theorem algebraMap_eq_diagonalRingHom : algebraMap R (Matrix n n α) = (diagonalRingHom n α).comp (algebraMap R _) := rfl @[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] simp [hf₂] 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 } end Algebra section AddHom variable [Add α] variable (R α) in /-- Extracting entries from a matrix as an additive homomorphism. -/ @[simps] def entryAddHom (i : m) (j : n) : AddHom (Matrix m n α) α where toFun M := M i j map_add' _ _ := rfl -- It is necessary to spell out the name of the coercion explicitly on the RHS -- for unification to succeed lemma entryAddHom_eq_comp {i : m} {j : n} : entryAddHom α i j = ((Pi.evalAddHom (fun _ => α) j).comp (Pi.evalAddHom _ i)).comp (AddHomClass.toAddHom ofAddEquiv.symm) := rfl end AddHom section AddMonoidHom variable [AddZeroClass α] variable (R α) in /-- Extracting entries from a matrix as an additive monoid homomorphism. Note this cannot be upgraded to a ring homomorphism, as it does not respect multiplication. -/ @[simps] def entryAddMonoidHom (i : m) (j : n) : Matrix m n α →+ α where toFun M := M i j map_add' _ _ := rfl map_zero' := rfl -- It is necessary to spell out the name of the coercion explicitly on the RHS -- for unification to succeed lemma entryAddMonoidHom_eq_comp {i : m} {j : n} : entryAddMonoidHom α i j = ((Pi.evalAddMonoidHom (fun _ => α) j).comp (Pi.evalAddMonoidHom _ i)).comp (AddMonoidHomClass.toAddMonoidHom ofAddEquiv.symm) := by rfl @[simp] lemma evalAddMonoidHom_comp_diagAddMonoidHom (i : m) : (Pi.evalAddMonoidHom _ i).comp (diagAddMonoidHom m α) = entryAddMonoidHom α i i := by simp [AddMonoidHom.ext_iff] @[simp] lemma entryAddMonoidHom_toAddHom {i : m} {j : n} : (entryAddMonoidHom α i j : AddHom _ _) = entryAddHom α i j := rfl end AddMonoidHom section LinearMap variable [Semiring R] [AddCommMonoid α] [Module R α] variable (R α) in /-- Extracting entries from a matrix as a linear map. Note this cannot be upgraded to an algebra homomorphism, as it does not respect multiplication. -/ @[simps] def entryLinearMap (i : m) (j : n) : Matrix m n α →ₗ[R] α where toFun M := M i j map_add' _ _ := rfl map_smul' _ _ := rfl -- It is necessary to spell out the name of the coercion explicitly on the RHS -- for unification to succeed lemma entryLinearMap_eq_comp {i : m} {j : n} : entryLinearMap R α i j = LinearMap.proj j ∘ₗ LinearMap.proj i ∘ₗ (ofLinearEquiv R).symm.toLinearMap := by rfl @[simp] lemma proj_comp_diagLinearMap (i : m) : LinearMap.proj i ∘ₗ diagLinearMap m R α = entryLinearMap R α i i := by simp [LinearMap.ext_iff] @[simp] lemma entryLinearMap_toAddMonoidHom {i : m} {j : n} : (entryLinearMap R α i j : _ →+ _) = entryAddMonoidHom α i j := rfl @[simp] lemma entryLinearMap_toAddHom {i : m} {j : n} : (entryLinearMap R α i j : AddHom _ _) = entryAddHom α i j := rfl end LinearMap 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 _ @[simp] theorem mapMatrix_refl : (Equiv.refl α).mapMatrix = Equiv.refl (Matrix m n α) := rfl @[simp] theorem mapMatrix_symm (f : α ≃ β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃ _) := rfl @[simp] theorem mapMatrix_trans (f : α ≃ β) (g : β ≃ γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃ _) := rfl 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 @[simp] theorem mapMatrix_id : (AddMonoidHom.id α).mapMatrix = AddMonoidHom.id (Matrix m n α) := rfl @[simp] theorem mapMatrix_comp (f : β →+ γ) (g : α →+ β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n α →+ _) := rfl @[simp] lemma entryAddMonoidHom_comp_mapMatrix (f : α →+ β) (i : m) (j : n) : (entryAddMonoidHom β i j).comp f.mapMatrix = f.comp (entryAddMonoidHom α i j) := rfl 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 (map_add f) } @[simp] theorem mapMatrix_refl : (AddEquiv.refl α).mapMatrix = AddEquiv.refl (Matrix m n α) := rfl @[simp] theorem mapMatrix_symm (f : α ≃+ β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃+ _) := rfl @[simp] theorem mapMatrix_trans (f : α ≃+ β) (g : β ≃+ γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃+ _) := rfl @[simp] lemma entryAddHom_comp_mapMatrix (f : α ≃+ β) (i : m) (j : n) : (entryAddHom β i j).comp (AddHomClass.toAddHom f.mapMatrix) = (f : AddHom α β).comp (entryAddHom _ i j) := rfl 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) @[simp] theorem mapMatrix_id : LinearMap.id.mapMatrix = (LinearMap.id : Matrix m n α →ₗ[R] _) := rfl @[simp] theorem mapMatrix_comp (f : β →ₗ[R] γ) (g : α →ₗ[R] β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n α →ₗ[R] _) := rfl @[simp] lemma entryLinearMap_comp_mapMatrix (f : α →ₗ[R] β) (i : m) (j : n) : entryLinearMap R _ i j ∘ₗ f.mapMatrix = f ∘ₗ entryLinearMap R _ i j := rfl 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 } @[simp] theorem mapMatrix_refl : (LinearEquiv.refl R α).mapMatrix = LinearEquiv.refl R (Matrix m n α) := rfl @[simp] theorem mapMatrix_symm (f : α ≃ₗ[R] β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃ₗ[R] _) := rfl @[simp] theorem mapMatrix_trans (f : α ≃ₗ[R] β) (g : β ≃ₗ[R] γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃ₗ[R] _) := rfl @[simp] lemma mapMatrix_toLinearMap (f : α ≃ₗ[R] β) : (f.mapMatrix : _ ≃ₗ[R] Matrix m n β).toLinearMap = f.toLinearMap.mapMatrix := by rfl @[simp] lemma entryLinearMap_comp_mapMatrix (f : α ≃ₗ[R] β) (i : m) (j : n) : entryLinearMap R _ i j ∘ₗ f.mapMatrix.toLinearMap = f.toLinearMap ∘ₗ entryLinearMap R _ i j := by simp only [mapMatrix_toLinearMap, LinearMap.entryLinearMap_comp_mapMatrix] 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 _ _ => Matrix.map_mul } @[simp] theorem mapMatrix_id : (RingHom.id α).mapMatrix = RingHom.id (Matrix m m α) := rfl @[simp] theorem mapMatrix_comp (f : β →+* γ) (g : α →+* β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m α →+* _) := rfl 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 } @[simp] theorem mapMatrix_refl : (RingEquiv.refl α).mapMatrix = RingEquiv.refl (Matrix m m α) := rfl @[simp] theorem mapMatrix_symm (f : α ≃+* β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m β ≃+* _) := rfl @[simp] theorem mapMatrix_trans (f : α ≃+* β) (g : β ≃+* γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m α ≃+* _) := rfl open MulOpposite in /-- For any ring `R`, we have ring isomorphism `Matₙₓₙ(Rᵒᵖ) ≅ (Matₙₓₙ(R))ᵒᵖ` given by transpose. -/ @[simps apply symm_apply] def mopMatrix : Matrix m m αᵐᵒᵖ ≃+* (Matrix m m α)ᵐᵒᵖ where toFun M := op (M.transpose.map unop) invFun M := M.unop.transpose.map op left_inv _ := by aesop right_inv _ := by aesop map_mul' _ _ := unop_injective <| by ext; simp [transpose, mul_apply] map_add' _ _ := by aesop 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 (map_zero _) (f.commutes r) } @[simp] theorem mapMatrix_id : (AlgHom.id R α).mapMatrix = AlgHom.id R (Matrix m m α) := rfl @[simp] theorem mapMatrix_comp (f : β →ₐ[R] γ) (g : α →ₐ[R] β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m α →ₐ[R] _) := rfl 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 } @[simp] theorem mapMatrix_refl : AlgEquiv.refl.mapMatrix = (AlgEquiv.refl : Matrix m m α ≃ₐ[R] _) := rfl @[simp] theorem mapMatrix_symm (f : α ≃ₐ[R] β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m β ≃ₐ[R] _) := rfl @[simp] theorem mapMatrix_trans (f : α ≃ₐ[R] β) (g : β ≃ₐ[R] γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m α ≃ₐ[R] _) := rfl /-- For any algebra `α` over a ring `R`, we have an `R`-algebra isomorphism `Matₙₓₙ(αᵒᵖ) ≅ (Matₙₓₙ(R))ᵒᵖ` given by transpose. If `α` is commutative, we can get rid of the `ᵒᵖ` in the left-hand side, see `Matrix.transposeAlgEquiv`. -/ @[simps!] def mopMatrix : Matrix m m αᵐᵒᵖ ≃ₐ[R] (Matrix m m α)ᵐᵒᵖ where __ := RingEquiv.mopMatrix commutes' _ := MulOpposite.unop_injective <| by ext; simp [algebraMap_matrix_apply, eq_comm, apply_ite MulOpposite.unop] end AlgEquiv open Matrix namespace Matrix section Transpose open Matrix 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 @[simp] theorem transposeAddEquiv_symm [Add α] : (transposeAddEquiv m n α).symm = transposeAddEquiv n m α := rfl 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 theorem transpose_multiset_sum [AddCommMonoid α] (s : Multiset (Matrix m n α)) : s.sumᵀ = (s.map transpose).sum := (transposeAddEquiv m n α).toAddMonoidHom.map_multiset_sum s 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 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 } @[simp] theorem transposeLinearEquiv_symm [Semiring R] [AddCommMonoid α] [Module R α] : (transposeLinearEquiv m n R α).symm = transposeLinearEquiv n m R α := rfl 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 } 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 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 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] } variable {R m α} end Transpose end Matrix
Mathlib/Data/Matrix/Basic.lean
2,320
2,324
/- 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.Data.Nat.ModEq /-! # Congruences modulo an integer This file defines the equivalence relation `a ≡ b [ZMOD n]` on the integers, similarly to how `Data.Nat.ModEq` defines them for the natural numbers. The notation is short for `n.ModEq a b`, which is defined to be `a % n = b % n` for integers `a b n`. ## Tags modeq, congruence, mod, MOD, modulo, integers -/ namespace Int /-- `a ≡ b [ZMOD n]` when `a % n = b % n`. -/ def ModEq (n a b : ℤ) := a % n = b % n @[inherit_doc] notation:50 a " ≡ " b " [ZMOD " n "]" => ModEq n a b variable {m n a b c d : ℤ} instance : Decidable (ModEq n a b) := decEq (a % n) (b % n) namespace ModEq @[refl, simp] protected theorem refl (a : ℤ) : a ≡ a [ZMOD n] := @rfl _ _ protected theorem rfl : a ≡ a [ZMOD n] := ModEq.refl _ instance : IsRefl _ (ModEq n) := ⟨ModEq.refl⟩ @[symm] protected theorem symm : a ≡ b [ZMOD n] → b ≡ a [ZMOD n] := Eq.symm @[trans] protected theorem trans : a ≡ b [ZMOD n] → b ≡ c [ZMOD n] → a ≡ c [ZMOD n] := Eq.trans instance : IsTrans ℤ (ModEq n) where trans := @Int.ModEq.trans n protected theorem eq : a ≡ b [ZMOD n] → a % n = b % n := id end ModEq theorem modEq_comm : a ≡ b [ZMOD n] ↔ b ≡ a [ZMOD n] := ⟨ModEq.symm, ModEq.symm⟩ theorem natCast_modEq_iff {a b n : ℕ} : a ≡ b [ZMOD n] ↔ a ≡ b [MOD n] := by unfold ModEq Nat.ModEq; rw [← Int.ofNat_inj]; simp [natCast_mod] theorem modEq_zero_iff_dvd : a ≡ 0 [ZMOD n] ↔ n ∣ a := by rw [ModEq, zero_emod, dvd_iff_emod_eq_zero] theorem _root_.Dvd.dvd.modEq_zero_int (h : n ∣ a) : a ≡ 0 [ZMOD n] := modEq_zero_iff_dvd.2 h theorem _root_.Dvd.dvd.zero_modEq_int (h : n ∣ a) : 0 ≡ a [ZMOD n] := h.modEq_zero_int.symm theorem modEq_iff_dvd : a ≡ b [ZMOD n] ↔ n ∣ b - a := by rw [ModEq, eq_comm] simp [emod_eq_emod_iff_emod_sub_eq_zero, dvd_iff_emod_eq_zero] theorem modEq_iff_add_fac {a b n : ℤ} : a ≡ b [ZMOD n] ↔ ∃ t, b = a + n * t := by rw [modEq_iff_dvd] exact exists_congr fun t => sub_eq_iff_eq_add' alias ⟨ModEq.dvd, modEq_of_dvd⟩ := modEq_iff_dvd theorem mod_modEq (a n) : a % n ≡ a [ZMOD n] := emod_emod _ _ @[simp] theorem neg_modEq_neg : -a ≡ -b [ZMOD n] ↔ a ≡ b [ZMOD n] := by simp only [modEq_iff_dvd, (by omega : -b - -a = -(b - a)), Int.dvd_neg] @[simp] theorem modEq_neg : a ≡ b [ZMOD -n] ↔ a ≡ b [ZMOD n] := by simp [modEq_iff_dvd] namespace ModEq protected theorem of_dvd (d : m ∣ n) (h : a ≡ b [ZMOD n]) : a ≡ b [ZMOD m] := modEq_iff_dvd.2 <| d.trans h.dvd protected theorem mul_left' (h : a ≡ b [ZMOD n]) : c * a ≡ c * b [ZMOD c * n] := by obtain hc | rfl | hc := lt_trichotomy c 0 · rw [← neg_modEq_neg, ← modEq_neg, ← Int.neg_mul, ← Int.neg_mul, ← Int.neg_mul] simp only [ModEq, mul_emod_mul_of_pos _ _ (neg_pos.2 hc), h.eq] · simp only [Int.zero_mul, ModEq.rfl] · simp only [ModEq, mul_emod_mul_of_pos _ _ hc, h.eq] protected theorem mul_right' (h : a ≡ b [ZMOD n]) : a * c ≡ b * c [ZMOD n * c] := by rw [mul_comm a, mul_comm b, mul_comm n]; exact h.mul_left' @[gcongr] protected theorem add (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a + c ≡ b + d [ZMOD n] := modEq_iff_dvd.2 <| by convert Int.dvd_add h₁.dvd h₂.dvd using 1; omega @[gcongr] protected theorem add_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c + a ≡ c + b [ZMOD n] := ModEq.rfl.add h @[gcongr] protected theorem add_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a + c ≡ b + c [ZMOD n] := h.add ModEq.rfl protected theorem add_left_cancel (h₁ : a ≡ b [ZMOD n]) (h₂ : a + c ≡ b + d [ZMOD n]) : c ≡ d [ZMOD n] := have : d - c = b + d - (a + c) - (b - a) := by omega modEq_iff_dvd.2 <| by rw [this] exact Int.dvd_sub h₂.dvd h₁.dvd protected theorem add_left_cancel' (c : ℤ) (h : c + a ≡ c + b [ZMOD n]) : a ≡ b [ZMOD n] := ModEq.rfl.add_left_cancel h protected theorem add_right_cancel (h₁ : c ≡ d [ZMOD n]) (h₂ : a + c ≡ b + d [ZMOD n]) : a ≡ b [ZMOD n] := by rw [add_comm a, add_comm b] at h₂ exact h₁.add_left_cancel h₂ protected theorem add_right_cancel' (c : ℤ) (h : a + c ≡ b + c [ZMOD n]) : a ≡ b [ZMOD n] := ModEq.rfl.add_right_cancel h @[gcongr] protected theorem neg (h : a ≡ b [ZMOD n]) : -a ≡ -b [ZMOD n] := h.add_left_cancel (by simp_rw [← sub_eq_add_neg, sub_self]; rfl) @[gcongr] protected theorem sub (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a - c ≡ b - d [ZMOD n] := by rw [sub_eq_add_neg, sub_eq_add_neg] exact h₁.add h₂.neg @[gcongr] protected theorem sub_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c - a ≡ c - b [ZMOD n] := ModEq.rfl.sub h @[gcongr] protected theorem sub_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a - c ≡ b - c [ZMOD n] := h.sub ModEq.rfl @[gcongr] protected theorem mul_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c * a ≡ c * b [ZMOD n] := h.mul_left'.of_dvd <| dvd_mul_left _ _ @[gcongr] protected theorem mul_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a * c ≡ b * c [ZMOD n] := h.mul_right'.of_dvd <| dvd_mul_right _ _ @[gcongr] protected theorem mul (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a * c ≡ b * d [ZMOD n] := (h₂.mul_left _).trans (h₁.mul_right _) @[gcongr] protected theorem pow (m : ℕ) (h : a ≡ b [ZMOD n]) : a ^ m ≡ b ^ m [ZMOD n] := by induction' m with d hd; · rfl rw [pow_succ, pow_succ] exact hd.mul h lemma of_mul_left (m : ℤ) (h : a ≡ b [ZMOD m * n]) : a ≡ b [ZMOD n] := by rw [modEq_iff_dvd] at *; exact (dvd_mul_left n m).trans h lemma of_mul_right (m : ℤ) : a ≡ b [ZMOD n * m] → a ≡ b [ZMOD n] := mul_comm m n ▸ of_mul_left _ /-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c`. -/ theorem cancel_right_div_gcd (hm : 0 < m) (h : a * c ≡ b * c [ZMOD m]) : a ≡ b [ZMOD m / gcd m c] := by letI d := gcd m c rw [modEq_iff_dvd] at h ⊢ refine Int.dvd_of_dvd_mul_right_of_gcd_one (?_ : m / d ∣ c / d * (b - a)) ?_ · rw [mul_comm, ← Int.mul_ediv_assoc (b - a) gcd_dvd_right, Int.sub_mul] exact Int.ediv_dvd_ediv gcd_dvd_left h · rw [gcd_div gcd_dvd_left gcd_dvd_right, natAbs_natCast, Nat.div_self (gcd_pos_of_ne_zero_left c hm.ne')] /-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c`. -/ theorem cancel_left_div_gcd (hm : 0 < m) (h : c * a ≡ c * b [ZMOD m]) : a ≡ b [ZMOD m / gcd m c] := cancel_right_div_gcd hm <| by simpa [mul_comm] using h theorem of_div (h : a / c ≡ b / c [ZMOD m / c]) (ha : c ∣ a) (ha : c ∣ b) (ha : c ∣ m) : a ≡ b [ZMOD m] := by convert h.mul_left' <;> rwa [Int.mul_ediv_cancel'] end ModEq theorem modEq_one : a ≡ b [ZMOD 1] := modEq_of_dvd (one_dvd _) theorem modEq_sub (a b : ℤ) : a ≡ b [ZMOD a - b] := (modEq_of_dvd dvd_rfl).symm @[simp] theorem modEq_zero_iff : a ≡ b [ZMOD 0] ↔ a = b := by rw [ModEq, emod_zero, emod_zero] @[simp] theorem add_modEq_left : n + a ≡ a [ZMOD n] := ModEq.symm <| modEq_iff_dvd.2 <| by simp @[simp] theorem add_modEq_right : a + n ≡ a [ZMOD n] := ModEq.symm <| modEq_iff_dvd.2 <| by simp theorem modEq_and_modEq_iff_modEq_mul {a b m n : ℤ} (hmn : m.natAbs.Coprime n.natAbs) : a ≡ b [ZMOD m] ∧ a ≡ b [ZMOD n] ↔ a ≡ b [ZMOD m * n] := ⟨fun h => by rw [modEq_iff_dvd, modEq_iff_dvd] at h rw [modEq_iff_dvd, ← natAbs_dvd, ← dvd_natAbs, natCast_dvd_natCast, natAbs_mul] refine hmn.mul_dvd_of_dvd_of_dvd ?_ ?_ <;> rw [← natCast_dvd_natCast, natAbs_dvd, dvd_natAbs] <;> tauto, fun h => ⟨h.of_mul_right _, h.of_mul_left _⟩⟩ theorem gcd_a_modEq (a b : ℕ) : (a : ℤ) * Nat.gcdA a b ≡ Nat.gcd a b [ZMOD b] := by rw [← add_zero ((a : ℤ) * _), Nat.gcd_eq_gcd_ab] exact (dvd_mul_right _ _).zero_modEq_int.add_left _ theorem modEq_add_fac {a b n : ℤ} (c : ℤ) (ha : a ≡ b [ZMOD n]) : a + n * c ≡ b [ZMOD n] := calc a + n * c ≡ b + n * c [ZMOD n] := ha.add_right _ _ ≡ b + 0 [ZMOD n] := (dvd_mul_right _ _).modEq_zero_int.add_left _ _ ≡ b [ZMOD n] := by rw [add_zero] theorem modEq_sub_fac {a b n : ℤ} (c : ℤ) (ha : a ≡ b [ZMOD n]) : a - n * c ≡ b [ZMOD n] := by convert Int.modEq_add_fac (-c) ha using 1; rw [Int.mul_neg, sub_eq_add_neg] theorem modEq_add_fac_self {a t n : ℤ} : a + n * t ≡ a [ZMOD n] := modEq_add_fac _ ModEq.rfl theorem mod_coprime {a b : ℕ} (hab : Nat.Coprime a b) : ∃ y : ℤ, a * y ≡ 1 [ZMOD b] := ⟨Nat.gcdA a b, have hgcd : Nat.gcd a b = 1 := Nat.Coprime.gcd_eq_one hab calc ↑a * Nat.gcdA a b ≡ ↑a * Nat.gcdA a b + ↑b * Nat.gcdB a b [ZMOD ↑b] := ModEq.symm <| modEq_add_fac _ <| ModEq.refl _ _ ≡ 1 [ZMOD ↑b] := by rw [← Nat.gcd_eq_gcd_ab, hgcd]; rfl ⟩ theorem existsUnique_equiv (a : ℤ) {b : ℤ} (hb : 0 < b) : ∃ z : ℤ, 0 ≤ z ∧ z < b ∧ z ≡ a [ZMOD b] := ⟨a % b, emod_nonneg _ (ne_of_gt hb), by have : a % b < |b| := emod_lt_abs _ (ne_of_gt hb) rwa [abs_of_pos hb] at this, by simp [ModEq]⟩ @[deprecated (since := "2024-12-17")] alias exists_unique_equiv := existsUnique_equiv theorem existsUnique_equiv_nat (a : ℤ) {b : ℤ} (hb : 0 < b) : ∃ z : ℕ, ↑z < b ∧ ↑z ≡ a [ZMOD b] := let ⟨z, hz1, hz2, hz3⟩ := existsUnique_equiv a hb ⟨z.natAbs, by constructor <;> rw [natAbs_of_nonneg hz1] <;> assumption⟩ @[deprecated (since := "2024-12-17")] alias exists_unique_equiv_nat := existsUnique_equiv_nat theorem mod_mul_right_mod (a b c : ℤ) : a % (b * c) % b = a % b := (mod_modEq _ _).of_mul_right _ theorem mod_mul_left_mod (a b c : ℤ) : a % (b * c) % c = a % c := (mod_modEq _ _).of_mul_left _ end Int
Mathlib/Data/Int/ModEq.lean
311
314
/- 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.Analytic.Uniqueness import Mathlib.Analysis.Calculus.DiffContOnCl import Mathlib.Analysis.Calculus.DSlope import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Complex.ReImTopology import Mathlib.Data.Real.Cardinality import Mathlib.MeasureTheory.Integral.CircleIntegral import Mathlib.MeasureTheory.Integral.DivergenceTheorem import Mathlib.MeasureTheory.Measure.Lebesgue.Complex /-! # Cauchy integral formula In this file we prove the Cauchy-Goursat theorem and the Cauchy integral formula for integrals over circles. Most results are formulated for a function `f : ℂ → E` that takes values in a complex Banach space with second countable topology. ## Main statements In the following theorems, if the name ends with `off_countable`, then the actual theorem assumes differentiability at all but countably many points of the set mentioned below. * `Complex.integral_boundary_rect_of_hasFDerivAt_real_off_countable`: If a function `f : ℂ → E` is continuous on a closed rectangle and *real* differentiable on its interior, then its integral over the boundary of this rectangle is equal to the integral of `I • f' (x + y * I) 1 - f' (x + y * I) I` over the rectangle, where `f' z w : E` is the derivative of `f` at `z` in the direction `w` and `I = Complex.I` is the imaginary unit. * `Complex.integral_boundary_rect_eq_zero_of_differentiable_on_off_countable`: If a function `f : ℂ → E` is continuous on a closed rectangle and is *complex* differentiable on its interior, then its integral over the boundary of this rectangle is equal to zero. * `Complex.circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable`: If a function `f : ℂ → E` is continuous on a closed annulus `{z | r ≤ |z - c| ≤ R}` and is complex differentiable on its interior `{z | r < |z - c| < R}`, then the integrals of `(z - c)⁻¹ • f z` over the outer boundary and over the inner boundary are equal. * `Complex.circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto`, `Complex.circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable`: If a function `f : ℂ → E` is continuous on a punctured closed disc `{z | |z - c| ≤ R ∧ z ≠ c}`, is complex differentiable on the corresponding punctured open disc, and tends to `y` as `z → c`, `z ≠ c`, then the integral of `(z - c)⁻¹ • f z` over the circle `|z - c| = R` is equal to `2πiy`. In particular, if `f` is continuous on the whole closed disc and is complex differentiable on the corresponding open disc, then this integral is equal to `2πif(c)`. * `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable`, `Complex.two_pi_I_inv_smul_circleIntegral_sub_inv_smul_of_differentiable_on_off_countable` **Cauchy integral formula**: if `f : ℂ → E` is continuous on a closed disc of radius `R` and is complex differentiable on the corresponding open disc, then for any `w` in the corresponding open disc the integral of `(z - w)⁻¹ • f z` over the boundary of the disc is equal to `2πif(w)`. Two versions of the lemma put the multiplier `2πi` at the different sides of the equality. * `Complex.hasFPowerSeriesOnBall_of_differentiable_off_countable`: If `f : ℂ → E` is continuous on a closed disc of positive radius and is complex differentiable on the corresponding open disc, then it is analytic on the corresponding open disc, and the coefficients of the power series are given by Cauchy integral formulas. * `DifferentiableOn.hasFPowerSeriesOnBall`: If `f : ℂ → E` is complex differentiable on a closed disc of positive radius, then it is analytic on the corresponding open disc, and the coefficients of the power series are given by Cauchy integral formulas. * `DifferentiableOn.analyticAt`, `Differentiable.analyticAt`: If `f : ℂ → E` is differentiable on a neighborhood of a point, then it is analytic at this point. In particular, if `f : ℂ → E` is differentiable on the whole `ℂ`, then it is analytic at every point `z : ℂ`. * `Differentiable.hasFPowerSeriesOnBall`: If `f : ℂ → E` is differentiable everywhere then the `cauchyPowerSeries f z R` is a formal power series representing `f` at `z` with infinite radius of convergence (this holds for any choice of `0 < R`). ## Implementation details The proof of the Cauchy integral formula in this file is based on a very general version of the divergence theorem, see `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable` (a version for functions defined on `Fin (n + 1) → ℝ`), `MeasureTheory.integral_divergence_prod_Icc_of_hasFDerivWithinAt_off_countable_of_le`, and `MeasureTheory.integral2_divergence_prod_of_hasFDerivWithinAt_off_countable` (versions for functions defined on `ℝ × ℝ`). Usually, the divergence theorem is formulated for a $C^1$ smooth function. The theorems formulated above deal with a function that is * continuous on a closed box/rectangle; * differentiable at all but countably many points of its interior; * have divergence integrable over the closed box/rectangle. First, we reformulate the theorem for a *real*-differentiable map `ℂ → E`, and relate the integral of `f` over the boundary of a rectangle in `ℂ` to the integral of the derivative $\frac{\partial f}{\partial \bar z}$ over the interior of this box. In particular, for a *complex* differentiable function, the latter derivative is zero, hence the integral over the boundary of a rectangle is zero. Thus we get the Cauchy-Goursat theorem for a rectangle in `ℂ`. Next, we apply this theorem to the function $F(z)=f(c+e^{z})$ on the rectangle $[\ln r, \ln R]\times [0, 2\pi]$ to prove that $$ \oint_{|z-c|=r}\frac{f(z)\,dz}{z-c}=\oint_{|z-c|=R}\frac{f(z)\,dz}{z-c} $$ provided that `f` is continuous on the closed annulus `r ≤ |z - c| ≤ R` and is complex differentiable on its interior `r < |z - c| < R` (possibly, at all but countably many points). Here and below, we write $\frac{f(z)}{z-c}$ in the documentation while the actual lemmas use `(z - c)⁻¹ • f z` because `f z` belongs to some Banach space over `ℂ` and `f z / (z - c)` is undefined. Taking the limit of this equality as `r` tends to `𝓝[>] 0`, we prove $$ \oint_{|z-c|=R}\frac{f(z)\,dz}{z-c}=2\pi if(c) $$ provided that `f` is continuous on the closed disc `|z - c| ≤ R` and is differentiable at all but countably many points of its interior. This is the Cauchy integral formula for the center of a circle. In particular, if we apply this function to `F z = (z - c) • f z`, then we get $$ \oint_{|z-c|=R} f(z)\,dz=0. $$ In order to deduce the Cauchy integral formula for any point `w`, `|w - c| < R`, we consider the slope function `g : ℂ → E` given by `g z = (z - w)⁻¹ • (f z - f w)` if `z ≠ w` and `g w = f' w`. This function satisfies assumptions of the previous theorem, so we have $$ \oint_{|z-c|=R} \frac{f(z)\,dz}{z-w}=\oint_{|z-c|=R} \frac{f(w)\,dz}{z-w}= \left(\oint_{|z-c|=R} \frac{dz}{z-w}\right)f(w). $$ The latter integral was computed in `circleIntegral.integral_sub_inv_of_mem_ball` and is equal to `2 * π * Complex.I`. There is one more step in the actual proof. Since we allow `f` to be non-differentiable on a countable set `s`, we cannot immediately claim that `g` is continuous at `w` if `w ∈ s`. So, we use the proof outlined in the previous paragraph for `w ∉ s` (see `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable_aux`), then use continuity of both sides of the formula and density of `sᶜ` to prove the formula for all points of the open ball, see `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable`. Finally, we use the properties of the Cauchy integrals established elsewhere (see `hasFPowerSeriesOn_cauchy_integral`) and Cauchy integral formula to prove that the original function is analytic on the open ball. ## Tags Cauchy-Goursat theorem, Cauchy integral formula -/ open TopologicalSpace Set MeasureTheory intervalIntegral Metric Filter Function open scoped Interval Real NNReal ENNReal Topology noncomputable section universe u variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℂ E] namespace Complex /-- Suppose that a function `f : ℂ → E` is continuous on a closed rectangle with opposite corners at `z w : ℂ`, is *real* differentiable at all but countably many points of the corresponding open rectangle, and $\frac{\partial f}{\partial \bar z}$ is integrable on this rectangle. Then the integral of `f` over the boundary of the rectangle is equal to the integral of $2i\frac{\partial f}{\partial \bar z}=i\frac{\partial f}{\partial x}-\frac{\partial f}{\partial y}$ over the rectangle. -/ theorem integral_boundary_rect_of_hasFDerivAt_real_off_countable (f : ℂ → E) (f' : ℂ → ℂ →L[ℝ] E) (z w : ℂ) (s : Set ℂ) (hs : s.Countable) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : ∀ x ∈ Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im) \ s, HasFDerivAt f (f' x) x) (Hi : IntegrableOn (fun z => I • f' z 1 - f' z I) ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • ∫ y : ℝ in z.im..w.im, f (re z + y * I) = ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • f' (x + y * I) 1 - f' (x + y * I) I := by set e : (ℝ × ℝ) ≃L[ℝ] ℂ := equivRealProdCLM.symm have he : ∀ x y : ℝ, ↑x + ↑y * I = e (x, y) := fun x y => (mk_eq_add_mul_I x y).symm have he₁ : e (1, 0) = 1 := rfl; have he₂ : e (0, 1) = I := rfl simp only [he] at * set F : ℝ × ℝ → E := f ∘ e set F' : ℝ × ℝ → ℝ × ℝ →L[ℝ] E := fun p => (f' (e p)).comp (e : ℝ × ℝ →L[ℝ] ℂ) have hF' : ∀ p : ℝ × ℝ, (-(I • F' p)) (1, 0) + F' p (0, 1) = -(I • f' (e p) 1 - f' (e p) I) := by rintro ⟨x, y⟩ simp only [F', ContinuousLinearMap.neg_apply, ContinuousLinearMap.smul_apply, ContinuousLinearMap.comp_apply, ContinuousLinearEquiv.coe_coe, he₁, he₂, neg_add_eq_sub, neg_sub] set R : Set (ℝ × ℝ) := [[z.re, w.re]] ×ˢ [[w.im, z.im]] set t : Set (ℝ × ℝ) := e ⁻¹' s rw [uIcc_comm z.im] at Hc Hi; rw [min_comm z.im, max_comm z.im] at Hd have hR : e ⁻¹' ([[z.re, w.re]] ×ℂ [[w.im, z.im]]) = R := rfl have htc : ContinuousOn F R := Hc.comp e.continuousOn hR.ge have htd : ∀ p ∈ Ioo (min z.re w.re) (max z.re w.re) ×ˢ Ioo (min w.im z.im) (max w.im z.im) \ t, HasFDerivAt F (F' p) p := fun p hp => (Hd (e p) hp).comp p e.hasFDerivAt simp_rw [← intervalIntegral.integral_smul, intervalIntegral.integral_symm w.im z.im, ← intervalIntegral.integral_neg, ← hF'] refine (integral2_divergence_prod_of_hasFDerivWithinAt_off_countable (fun p => -(I • F p)) F (fun p => -(I • F' p)) F' z.re w.im w.re z.im t (hs.preimage e.injective) (htc.const_smul _).neg htc (fun p hp => ((htd p hp).const_smul I).neg) htd ?_).symm rw [← (volume_preserving_equiv_real_prod.symm _).integrableOn_comp_preimage (MeasurableEquiv.measurableEmbedding _)] at Hi simpa only [hF'] using Hi.neg /-- Suppose that a function `f : ℂ → E` is continuous on a closed rectangle with opposite corners at `z w : ℂ`, is *real* differentiable on the corresponding open rectangle, and $\frac{\partial f}{\partial \bar z}$ is integrable on this rectangle. Then the integral of `f` over the boundary of the rectangle is equal to the integral of $2i\frac{\partial f}{\partial \bar z}=i\frac{\partial f}{\partial x}-\frac{\partial f}{\partial y}$ over the rectangle. -/ theorem integral_boundary_rect_of_continuousOn_of_hasFDerivAt_real (f : ℂ → E) (f' : ℂ → ℂ →L[ℝ] E) (z w : ℂ) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : ∀ x ∈ Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im), HasFDerivAt f (f' x) x) (Hi : IntegrableOn (fun z => I • f' z 1 - f' z I) ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • f' (x + y * I) 1 - f' (x + y * I) I := integral_boundary_rect_of_hasFDerivAt_real_off_countable f f' z w ∅ countable_empty Hc (fun x hx => Hd x hx.1) Hi /-- Suppose that a function `f : ℂ → E` is *real* differentiable on a closed rectangle with opposite corners at `z w : ℂ` and $\frac{\partial f}{\partial \bar z}$ is integrable on this rectangle. Then the integral of `f` over the boundary of the rectangle is equal to the integral of $2i\frac{\partial f}{\partial \bar z}=i\frac{\partial f}{\partial x}-\frac{\partial f}{\partial y}$ over the rectangle. -/ theorem integral_boundary_rect_of_differentiableOn_real (f : ℂ → E) (z w : ℂ) (Hd : DifferentiableOn ℝ f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hi : IntegrableOn (fun z => I • fderiv ℝ f z 1 - fderiv ℝ f z I) ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • fderiv ℝ f (x + y * I) 1 - fderiv ℝ f (x + y * I) I := integral_boundary_rect_of_hasFDerivAt_real_off_countable f (fderiv ℝ f) z w ∅ countable_empty Hd.continuousOn (fun x hx => Hd.hasFDerivAt <| by simpa only [← mem_interior_iff_mem_nhds, interior_reProdIm, uIcc, interior_Icc] using hx.1) Hi /-- **Cauchy-Goursat theorem** for a rectangle: the integral of a complex differentiable function over the boundary of a rectangle equals zero. More precisely, if `f` is continuous on a closed rectangle and is complex differentiable at all but countably many points of the corresponding open rectangle, then its integral over the boundary of the rectangle equals zero. -/ theorem integral_boundary_rect_eq_zero_of_differentiable_on_off_countable (f : ℂ → E) (z w : ℂ) (s : Set ℂ) (hs : s.Countable) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : ∀ x ∈ Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im) \ s, DifferentiableAt ℂ f x) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = 0 := by refine (integral_boundary_rect_of_hasFDerivAt_real_off_countable f (fun z => (fderiv ℂ f z).restrictScalars ℝ) z w s hs Hc (fun x hx => (Hd x hx).hasFDerivAt.restrictScalars ℝ) ?_).trans ?_ <;> simp [← ContinuousLinearMap.map_smul] /-- **Cauchy-Goursat theorem for a rectangle**: the integral of a complex differentiable function over the boundary of a rectangle equals zero. More precisely, if `f` is continuous on a closed rectangle and is complex differentiable on the corresponding open rectangle, then its integral over the boundary of the rectangle equals zero. -/ theorem integral_boundary_rect_eq_zero_of_continuousOn_of_differentiableOn (f : ℂ → E) (z w : ℂ) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : DifferentiableOn ℂ f (Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im))) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = 0 := integral_boundary_rect_eq_zero_of_differentiable_on_off_countable f z w ∅ countable_empty Hc fun _x hx => Hd.differentiableAt <| (isOpen_Ioo.reProdIm isOpen_Ioo).mem_nhds hx.1 /-- **Cauchy-Goursat theorem** for a rectangle: the integral of a complex differentiable function over the boundary of a rectangle equals zero. More precisely, if `f` is complex differentiable on a closed rectangle, then its integral over the boundary of the rectangle equals zero. -/ theorem integral_boundary_rect_eq_zero_of_differentiableOn (f : ℂ → E) (z w : ℂ) (H : DifferentiableOn ℂ f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = 0 := integral_boundary_rect_eq_zero_of_continuousOn_of_differentiableOn f z w H.continuousOn <| H.mono <| inter_subset_inter (preimage_mono Ioo_subset_Icc_self) (preimage_mono Ioo_subset_Icc_self) /-- If `f : ℂ → E` is continuous on the closed annulus `r ≤ ‖z - c‖ ≤ R`, `0 < r ≤ R`, and is complex differentiable at all but countably many points of its interior, then the integrals of `f z / (z - c)` (formally, `(z - c)⁻¹ • f z`) over the circles `‖z - c‖ = r` and `‖z - c‖ = R` are equal to each other. -/ theorem circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable {c : ℂ} {r R : ℝ} (h0 : 0 < r) (hle : r ≤ R) {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R \ ball c r)) (hd : ∀ z ∈ (ball c R \ closedBall c r) \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), (z - c)⁻¹ • f z) = ∮ z in C(c, r), (z - c)⁻¹ • f z := by /- We apply the previous lemma to `fun z ↦ f (c + exp z)` on the rectangle `[log r, log R] × [0, 2 * π]`. -/ set A := closedBall c R \ ball c r obtain ⟨a, rfl⟩ : ∃ a, Real.exp a = r := ⟨Real.log r, Real.exp_log h0⟩ obtain ⟨b, rfl⟩ : ∃ b, Real.exp b = R := ⟨Real.log R, Real.exp_log (h0.trans_le hle)⟩ rw [Real.exp_le_exp] at hle -- Unfold definition of `circleIntegral` and cancel some terms. suffices (∫ θ in (0)..2 * π, I • f (circleMap c (Real.exp b) θ)) = ∫ θ in (0)..2 * π, I • f (circleMap c (Real.exp a) θ) by simpa only [circleIntegral, add_sub_cancel_left, ofReal_exp, ← exp_add, smul_smul, ← div_eq_mul_inv, mul_div_cancel_left₀ _ (circleMap_ne_center (Real.exp_pos _).ne'), circleMap_sub_center, deriv_circleMap] set R := [[a, b]] ×ℂ [[0, 2 * π]] set g : ℂ → ℂ := (c + exp ·) have hdg : Differentiable ℂ g := differentiable_exp.const_add _ replace hs : (g ⁻¹' s).Countable := (hs.preimage (add_right_injective c)).preimage_cexp have h_maps : MapsTo g R A := by rintro z ⟨h, -⟩; simpa [g, A, dist_eq, norm_exp, hle] using h.symm replace hc : ContinuousOn (f ∘ g) R := hc.comp hdg.continuous.continuousOn h_maps replace hd : ∀ z ∈ Ioo (min a b) (max a b) ×ℂ Ioo (min 0 (2 * π)) (max 0 (2 * π)) \ g ⁻¹' s, DifferentiableAt ℂ (f ∘ g) z := by refine fun z hz => (hd (g z) ⟨?_, hz.2⟩).comp z (hdg _) simpa [g, dist_eq, norm_exp, hle, and_comm] using hz.1.1 simpa [g, circleMap, exp_periodic _, sub_eq_zero, ← exp_add] using integral_boundary_rect_eq_zero_of_differentiable_on_off_countable _ ⟨a, 0⟩ ⟨b, 2 * π⟩ _ hs hc hd /-- **Cauchy-Goursat theorem** for an annulus. If `f : ℂ → E` is continuous on the closed annulus `r ≤ ‖z - c‖ ≤ R`, `0 < r ≤ R`, and is complex differentiable at all but countably many points of its interior, then the integrals of `f` over the circles `‖z - c‖ = r` and `‖z - c‖ = R` are equal to each other. -/ theorem circleIntegral_eq_of_differentiable_on_annulus_off_countable {c : ℂ} {r R : ℝ} (h0 : 0 < r) (hle : r ≤ R) {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R \ ball c r)) (hd : ∀ z ∈ (ball c R \ closedBall c r) \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), f z) = ∮ z in C(c, r), f z := calc (∮ z in C(c, R), f z) = ∮ z in C(c, R), (z - c)⁻¹ • (z - c) • f z := (circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _).symm _ = ∮ z in C(c, r), (z - c)⁻¹ • (z - c) • f z := (circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable h0 hle hs ((continuousOn_id.sub continuousOn_const).smul hc) fun z hz => (differentiableAt_id.sub_const _).smul (hd z hz)) _ = ∮ z in C(c, r), f z := circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _ variable [CompleteSpace E] /-- **Cauchy integral formula** for the value at the center of a disc. If `f` is continuous on a punctured closed disc of radius `R`, is differentiable at all but countably many points of the interior of this disc, and has a limit `y` at the center of the disc, then the integral $\oint_{‖z-c‖=R} \frac{f(z)}{z-c}\,dz$ is equal to `2πiy`. -/ theorem circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto {c : ℂ} {R : ℝ} (h0 : 0 < R) {f : ℂ → E} {y : E} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R \ {c})) (hd : ∀ z ∈ (ball c R \ {c}) \ s, DifferentiableAt ℂ f z) (hy : Tendsto f (𝓝[{c}ᶜ] c) (𝓝 y)) : (∮ z in C(c, R), (z - c)⁻¹ • f z) = (2 * π * I : ℂ) • y := by rw [← sub_eq_zero, ← norm_le_zero_iff] refine le_of_forall_gt_imp_ge_of_dense fun ε ε0 => ?_ obtain ⟨δ, δ0, hδ⟩ : ∃ δ > (0 : ℝ), ∀ z ∈ closedBall c δ \ {c}, dist (f z) y < ε / (2 * π) := ((nhdsWithin_hasBasis nhds_basis_closedBall _).tendsto_iff nhds_basis_ball).1 hy _ (div_pos ε0 Real.two_pi_pos) obtain ⟨r, hr0, hrδ, hrR⟩ : ∃ r, 0 < r ∧ r ≤ δ ∧ r ≤ R := ⟨min δ R, lt_min δ0 h0, min_le_left _ _, min_le_right _ _⟩ have hsub : closedBall c R \ ball c r ⊆ closedBall c R \ {c} := diff_subset_diff_right (singleton_subset_iff.2 <| mem_ball_self hr0) have hsub' : ball c R \ closedBall c r ⊆ ball c R \ {c} := diff_subset_diff_right (singleton_subset_iff.2 <| mem_closedBall_self hr0.le) have hzne : ∀ z ∈ sphere c r, z ≠ c := fun z hz => ne_of_mem_of_not_mem hz fun h => hr0.ne' <| dist_self c ▸ Eq.symm h /- The integral `∮ z in C(c, r), f z / (z - c)` does not depend on `0 < r ≤ R` and tends to `2πIy` as `r → 0`. -/ calc ‖(∮ z in C(c, R), (z - c)⁻¹ • f z) - (2 * ↑π * I) • y‖ = ‖(∮ z in C(c, r), (z - c)⁻¹ • f z) - ∮ z in C(c, r), (z - c)⁻¹ • y‖ := by congr 2 · exact circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable hr0 hrR hs (hc.mono hsub) fun z hz => hd z ⟨hsub' hz.1, hz.2⟩ · simp [hr0.ne'] _ = ‖∮ z in C(c, r), (z - c)⁻¹ • (f z - y)‖ := by simp only [smul_sub] have hc' : ContinuousOn (fun z => (z - c)⁻¹) (sphere c r) := (continuousOn_id.sub continuousOn_const).inv₀ fun z hz => sub_ne_zero.2 <| hzne _ hz rw [circleIntegral.integral_sub] <;> refine (hc'.smul ?_).circleIntegrable hr0.le · exact hc.mono <| subset_inter (sphere_subset_closedBall.trans <| closedBall_subset_closedBall hrR) hzne · exact continuousOn_const _ ≤ 2 * π * r * (r⁻¹ * (ε / (2 * π))) := by refine circleIntegral.norm_integral_le_of_norm_le_const hr0.le fun z hz => ?_ specialize hzne z hz rw [mem_sphere, dist_eq_norm] at hz rw [norm_smul, norm_inv, hz, ← dist_eq_norm] refine mul_le_mul_of_nonneg_left (hδ _ ⟨?_, hzne⟩).le (inv_nonneg.2 hr0.le) rwa [mem_closedBall_iff_norm, hz] _ = ε := by field_simp [hr0.ne', Real.two_pi_pos.ne']; ac_rfl /-- **Cauchy integral formula** for the value at the center of a disc. If `f : ℂ → E` is continuous on a closed disc of radius `R` and is complex differentiable at all but countably many points of its interior, then the integral $\oint_{|z-c|=R} \frac{f(z)}{z-c}\,dz$ is equal to `2πiy`. -/ theorem circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable {R : ℝ} (h0 : 0 < R) {f : ℂ → E} {c : ℂ} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ z ∈ ball c R \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), (z - c)⁻¹ • f z) = (2 * π * I : ℂ) • f c := circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto h0 hs (hc.mono diff_subset) (fun z hz => hd z ⟨hz.1.1, hz.2⟩) (hc.continuousAt <| closedBall_mem_nhds _ h0).continuousWithinAt omit [CompleteSpace E] in /-- **Cauchy-Goursat theorem** for a disk: if `f : ℂ → E` is continuous on a closed disk `{z | ‖z - c‖ ≤ R}` and is complex differentiable at all but countably many points of its interior, then the integral $\oint_{|z-c|=R}f(z)\,dz$ equals zero. -/ theorem circleIntegral_eq_zero_of_differentiable_on_off_countable {R : ℝ} (h0 : 0 ≤ R) {f : ℂ → E} {c : ℂ} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ z ∈ ball c R \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), f z) = 0 := by wlog hE : CompleteSpace E generalizing · simp [circleIntegral, intervalIntegral, integral, hE] rcases h0.eq_or_lt with (rfl | h0); · apply circleIntegral.integral_radius_zero calc (∮ z in C(c, R), f z) = ∮ z in C(c, R), (z - c)⁻¹ • (z - c) • f z := (circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _).symm _ = (2 * ↑π * I : ℂ) • (c - c) • f c := (circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable h0 hs ((continuousOn_id.sub continuousOn_const).smul hc) fun z hz => (differentiableAt_id.sub_const _).smul (hd z hz)) _ = 0 := by rw [sub_self, zero_smul, smul_zero] /-- An auxiliary lemma for `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable`. This lemma assumes `w ∉ s` while the main lemma drops this assumption. -/ theorem circleIntegral_sub_inv_smul_of_differentiable_on_off_countable_aux {R : ℝ} {c w : ℂ} {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hw : w ∈ ball c R \ s) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ x ∈ ball c R \ s, DifferentiableAt ℂ f x) : (∮ z in C(c, R), (z - w)⁻¹ • f z) = (2 * π * I : ℂ) • f w := by have hR : 0 < R := dist_nonneg.trans_lt hw.1 set F : ℂ → E := dslope f w have hws : (insert w s).Countable := hs.insert w have hcF : ContinuousOn F (closedBall c R) := (continuousOn_dslope <| closedBall_mem_nhds_of_mem hw.1).2 ⟨hc, hd _ hw⟩ have hdF : ∀ z ∈ ball (c : ℂ) R \ insert w s, DifferentiableAt ℂ F z := fun z hz => (differentiableAt_dslope_of_ne (ne_of_mem_of_not_mem (mem_insert _ _) hz.2).symm).2 (hd _ (diff_subset_diff_right (subset_insert _ _) hz)) have HI := circleIntegral_eq_zero_of_differentiable_on_off_countable hR.le hws hcF hdF have hne : ∀ z ∈ sphere c R, z ≠ w := fun z hz => ne_of_mem_of_not_mem hz (ne_of_lt hw.1) have hFeq : EqOn F (fun z => (z - w)⁻¹ • f z - (z - w)⁻¹ • f w) (sphere c R) := fun z hz ↦ calc F z = (z - w)⁻¹ • (f z - f w) := update_of_ne (hne z hz) .. _ = (z - w)⁻¹ • f z - (z - w)⁻¹ • f w := smul_sub _ _ _ have hc' : ContinuousOn (fun z => (z - w)⁻¹) (sphere c R) := (continuousOn_id.sub continuousOn_const).inv₀ fun z hz => sub_ne_zero.2 <| hne z hz rw [← circleIntegral.integral_sub_inv_of_mem_ball hw.1, ← circleIntegral.integral_smul_const, ← sub_eq_zero, ← circleIntegral.integral_sub, ← circleIntegral.integral_congr hR.le hFeq, HI] exacts [(hc'.smul (hc.mono sphere_subset_closedBall)).circleIntegrable hR.le, (hc'.smul continuousOn_const).circleIntegrable hR.le] /-- **Cauchy integral formula**: if `f : ℂ → E` is continuous on a closed disc of radius `R` and is complex differentiable at all but countably many points of its interior, then for any `w` in this interior we have $\frac{1}{2πi}\oint_{|z-c|=R}(z-w)^{-1}f(z)\,dz=f(w)$. -/ theorem two_pi_I_inv_smul_circleIntegral_sub_inv_smul_of_differentiable_on_off_countable {R : ℝ} {c w : ℂ} {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hw : w ∈ ball c R) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ x ∈ ball c R \ s, DifferentiableAt ℂ f x) : ((2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z) = f w := by have hR : 0 < R := dist_nonneg.trans_lt hw suffices w ∈ closure (ball c R \ s) by lift R to ℝ≥0 using hR.le have A : ContinuousAt (fun w => (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z) w := by have := hasFPowerSeriesOn_cauchy_integral ((hc.mono sphere_subset_closedBall).circleIntegrable R.coe_nonneg) hR refine this.continuousOn.continuousAt (EMetric.isOpen_ball.mem_nhds ?_) rwa [Metric.emetric_ball_nnreal] have B : ContinuousAt f w := hc.continuousAt (closedBall_mem_nhds_of_mem hw) refine tendsto_nhds_unique_of_frequently_eq A B ((mem_closure_iff_frequently.1 this).mono ?_) intro z hz rw [circleIntegral_sub_inv_smul_of_differentiable_on_off_countable_aux hs hz hc hd, inv_smul_smul₀] simp [Real.pi_ne_zero, I_ne_zero] refine mem_closure_iff_nhds.2 fun t ht => ?_ -- TODO: generalize to any vector space over `ℝ` set g : ℝ → ℂ := fun x => w + ofReal x have : Tendsto g (𝓝 0) (𝓝 w) := (continuous_const.add continuous_ofReal).tendsto' 0 w (add_zero _) rcases mem_nhds_iff_exists_Ioo_subset.1 (this <| inter_mem ht <| isOpen_ball.mem_nhds hw) with ⟨l, u, hlu₀, hlu_sub⟩ obtain ⟨x, hx⟩ : (Ioo l u \ g ⁻¹' s).Nonempty := by refine diff_nonempty.2 fun hsub => ?_ have : (Ioo l u).Countable := (hs.preimage ((add_right_injective w).comp ofReal_injective)).mono hsub rw [← Cardinal.le_aleph0_iff_set_countable, Cardinal.mk_Ioo_real (hlu₀.1.trans hlu₀.2)] at this exact this.not_lt Cardinal.aleph0_lt_continuum exact ⟨g x, (hlu_sub hx.1).1, (hlu_sub hx.1).2, hx.2⟩ /-- **Cauchy integral formula**: if `f : ℂ → E` is continuous on a closed disc of radius `R` and is complex differentiable at all but countably many points of its interior, then for any `w` in this interior we have $\oint_{|z-c|=R}(z-w)^{-1}f(z)\,dz=2πif(w)$. -/ theorem circleIntegral_sub_inv_smul_of_differentiable_on_off_countable {R : ℝ} {c w : ℂ} {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hw : w ∈ ball c R) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ x ∈ ball c R \ s, DifferentiableAt ℂ f x) : (∮ z in C(c, R), (z - w)⁻¹ • f z) = (2 * π * I : ℂ) • f w := by rw [← two_pi_I_inv_smul_circleIntegral_sub_inv_smul_of_differentiable_on_off_countable hs hw hc hd, smul_inv_smul₀] simp [Real.pi_ne_zero, I_ne_zero] /-- **Cauchy integral formula**: if `f : ℂ → E` is complex differentiable on an open disc and is continuous on its closure, then for any `w` in this open ball we have
$\oint_{|z-c|=R}(z-w)^{-1}f(z)\,dz=2πif(w)$. -/ theorem _root_.DiffContOnCl.circleIntegral_sub_inv_smul {R : ℝ} {c w : ℂ} {f : ℂ → E} (h : DiffContOnCl ℂ f (ball c R)) (hw : w ∈ ball c R) : (∮ z in C(c, R), (z - w)⁻¹ • f z) = (2 * π * I : ℂ) • f w := circleIntegral_sub_inv_smul_of_differentiable_on_off_countable countable_empty hw h.continuousOn_ball fun _x hx => h.differentiableAt isOpen_ball hx.1
Mathlib/Analysis/Complex/CauchyIntegral.lean
496
502
/- Copyright (c) 2022 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.Algebra.DirectSum.Algebra import Mathlib.Analysis.Complex.UpperHalfPlane.FunctionsBoundedAtInfty import Mathlib.Analysis.Complex.UpperHalfPlane.Manifold import Mathlib.Geometry.Manifold.MFDeriv.SpecificFunctions import Mathlib.NumberTheory.ModularForms.SlashInvariantForms /-! # Modular forms This file defines modular forms and proves some basic properties about them. Including constructing the graded ring of modular forms. We begin by defining modular forms and cusp forms as extension of `SlashInvariantForm`s then we define the space of modular forms, cusp forms and prove that the product of two modular forms is a modular form. -/ open Complex UpperHalfPlane open scoped Topology Manifold MatrixGroups noncomputable section section ModularForm open ModularForm variable (F : Type*) (Γ : Subgroup SL(2, ℤ)) (k : ℤ) open scoped ModularForm /-- These are `SlashInvariantForm`'s that are holomorphic and bounded at infinity. -/ structure ModularForm extends SlashInvariantForm Γ k where holo' : MDifferentiable 𝓘(ℂ) 𝓘(ℂ) (toSlashInvariantForm : ℍ → ℂ) bdd_at_infty' : ∀ A : SL(2, ℤ), IsBoundedAtImInfty (toSlashInvariantForm ∣[k] A) /-- The `SlashInvariantForm` associated to a `ModularForm`. -/ add_decl_doc ModularForm.toSlashInvariantForm /-- These are `SlashInvariantForm`s that are holomorphic and zero at infinity. -/ structure CuspForm extends SlashInvariantForm Γ k where holo' : MDifferentiable 𝓘(ℂ) 𝓘(ℂ) (toSlashInvariantForm : ℍ → ℂ) zero_at_infty' : ∀ A : SL(2, ℤ), IsZeroAtImInfty (toSlashInvariantForm ∣[k] A) /-- The `SlashInvariantForm` associated to a `CuspForm`. -/ add_decl_doc CuspForm.toSlashInvariantForm /-- `ModularFormClass F Γ k` says that `F` is a type of bundled functions that extend `SlashInvariantFormClass` by requiring that the functions be holomorphic and bounded at infinity. -/ class ModularFormClass (F : Type*) (Γ : outParam <| Subgroup (SL(2, ℤ))) (k : outParam ℤ) [FunLike F ℍ ℂ] : Prop extends SlashInvariantFormClass F Γ k where holo : ∀ f : F, MDifferentiable 𝓘(ℂ) 𝓘(ℂ) (f : ℍ → ℂ) bdd_at_infty : ∀ (f : F) (A : SL(2, ℤ)), IsBoundedAtImInfty (f ∣[k] A) /-- `CuspFormClass F Γ k` says that `F` is a type of bundled functions that extend `SlashInvariantFormClass` by requiring that the functions be holomorphic and zero at infinity. -/ class CuspFormClass (F : Type*) (Γ : outParam <| Subgroup (SL(2, ℤ))) (k : outParam ℤ) [FunLike F ℍ ℂ] : Prop extends SlashInvariantFormClass F Γ k where holo : ∀ f : F, MDifferentiable 𝓘(ℂ) 𝓘(ℂ) (f : ℍ → ℂ) zero_at_infty : ∀ (f : F) (A : SL(2, ℤ)), IsZeroAtImInfty (f ∣[k] A) instance (priority := 100) ModularForm.funLike : FunLike (ModularForm Γ k) ℍ ℂ where coe f := f.toFun coe_injective' f g h := by cases f; cases g; congr; exact DFunLike.ext' h instance (priority := 100) ModularFormClass.modularForm : ModularFormClass (ModularForm Γ k) Γ k where slash_action_eq f := f.slash_action_eq' holo := ModularForm.holo' bdd_at_infty := ModularForm.bdd_at_infty' instance (priority := 100) CuspForm.funLike : FunLike (CuspForm Γ k) ℍ ℂ where coe f := f.toFun coe_injective' f g h := by cases f; cases g; congr; exact DFunLike.ext' h instance (priority := 100) CuspFormClass.cuspForm : CuspFormClass (CuspForm Γ k) Γ k where slash_action_eq f := f.slash_action_eq' holo := CuspForm.holo' zero_at_infty := CuspForm.zero_at_infty' variable {F Γ k} theorem ModularForm.toFun_eq_coe (f : ModularForm Γ k) : f.toFun = (f : ℍ → ℂ) := rfl @[simp] theorem ModularForm.toSlashInvariantForm_coe (f : ModularForm Γ k) : ⇑f.1 = f := rfl theorem CuspForm.toFun_eq_coe {f : CuspForm Γ k} : f.toFun = (f : ℍ → ℂ) := rfl @[simp] theorem CuspForm.toSlashInvariantForm_coe (f : CuspForm Γ k) : ⇑f.1 = f := rfl @[ext] theorem ModularForm.ext {f g : ModularForm Γ k} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h @[ext] theorem CuspForm.ext {f g : CuspForm Γ k} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h /-- Copy of a `ModularForm` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def ModularForm.copy (f : ModularForm Γ k) (f' : ℍ → ℂ) (h : f' = ⇑f) : ModularForm Γ k where toSlashInvariantForm := f.1.copy f' h holo' := h.symm ▸ f.holo' bdd_at_infty' A := h.symm ▸ f.bdd_at_infty' A /-- Copy of a `CuspForm` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def CuspForm.copy (f : CuspForm Γ k) (f' : ℍ → ℂ) (h : f' = ⇑f) : CuspForm Γ k where toSlashInvariantForm := f.1.copy f' h holo' := h.symm ▸ f.holo' zero_at_infty' A := h.symm ▸ f.zero_at_infty' A end ModularForm namespace ModularForm open SlashInvariantForm variable {Γ : Subgroup SL(2, ℤ)} {k : ℤ} instance add : Add (ModularForm Γ k) := ⟨fun f g => { toSlashInvariantForm := f + g holo' := f.holo'.add g.holo' bdd_at_infty' := fun A => by simpa using (f.bdd_at_infty' A).add (g.bdd_at_infty' A) }⟩ @[simp] theorem coe_add (f g : ModularForm Γ k) : ⇑(f + g) = f + g := rfl @[simp] theorem add_apply (f g : ModularForm Γ k) (z : ℍ) : (f + g) z = f z + g z := rfl instance instZero : Zero (ModularForm Γ k) := ⟨ { toSlashInvariantForm := 0 holo' := fun _ => mdifferentiableAt_const bdd_at_infty' := fun A => by simpa using zero_form_isBoundedAtImInfty } ⟩ @[simp] theorem coe_zero : ⇑(0 : ModularForm Γ k) = (0 : ℍ → ℂ) := rfl @[simp] theorem zero_apply (z : ℍ) : (0 : ModularForm Γ k) z = 0 := rfl section variable {α : Type*} [SMul α ℂ] [IsScalarTower α ℂ ℂ] instance instSMul : SMul α (ModularForm Γ k) := ⟨fun c f => { toSlashInvariantForm := c • f.1 holo' := by simpa using f.holo'.const_smul (c • (1 : ℂ)) bdd_at_infty' := fun A => by simpa using (f.bdd_at_infty' A).const_smul_left (c • (1 : ℂ)) }⟩ @[simp] theorem coe_smul (f : ModularForm Γ k) (n : α) : ⇑(n • f) = n • ⇑f := rfl @[simp] theorem smul_apply (f : ModularForm Γ k) (n : α) (z : ℍ) : (n • f) z = n • f z := rfl end instance instNeg : Neg (ModularForm Γ k) := ⟨fun f => { toSlashInvariantForm := -f.1 holo' := f.holo'.neg bdd_at_infty' := fun A => by simpa using (f.bdd_at_infty' A).neg }⟩ @[simp] theorem coe_neg (f : ModularForm Γ k) : ⇑(-f) = -f := rfl @[simp] theorem neg_apply (f : ModularForm Γ k) (z : ℍ) : (-f) z = -f z := rfl instance instSub : Sub (ModularForm Γ k) := ⟨fun f g => f + -g⟩ @[simp] theorem coe_sub (f g : ModularForm Γ k) : ⇑(f - g) = f - g := rfl @[simp] theorem sub_apply (f g : ModularForm Γ k) (z : ℍ) : (f - g) z = f z - g z := rfl instance : AddCommGroup (ModularForm Γ k) := DFunLike.coe_injective.addCommGroup _ rfl coe_add coe_neg coe_sub coe_smul coe_smul /-- Additive coercion from `ModularForm` to `ℍ → ℂ`. -/ @[simps] def coeHom : ModularForm Γ k →+ ℍ → ℂ where toFun f := f map_zero' := coe_zero map_add' _ _ := rfl instance : Module ℂ (ModularForm Γ k) := Function.Injective.module ℂ coeHom DFunLike.coe_injective fun _ _ => rfl instance : Inhabited (ModularForm Γ k) := ⟨0⟩ /-- The modular form of weight `k_1 + k_2` given by the product of two modular forms of weights `k_1` and `k_2`. -/ def mul {k_1 k_2 : ℤ} {Γ : Subgroup SL(2, ℤ)} (f : ModularForm Γ k_1) (g : ModularForm Γ k_2) : ModularForm Γ (k_1 + k_2) where toSlashInvariantForm := f.1.mul g.1 holo' := f.holo'.mul g.holo' bdd_at_infty' A := by simpa only [coe_mul, mul_slash_SL2] using (f.bdd_at_infty' A).mul (g.bdd_at_infty' A) @[simp] theorem mul_coe {k_1 k_2 : ℤ} {Γ : Subgroup SL(2, ℤ)} (f : ModularForm Γ k_1) (g : ModularForm Γ k_2) : (f.mul g : ℍ → ℂ) = f * g := rfl /-- The constant function with value `x : ℂ` as a modular form of weight 0 and any level. -/ def const (x : ℂ) : ModularForm Γ 0 where toSlashInvariantForm := .const x holo' _ := mdifferentiableAt_const bdd_at_infty' A := by simpa only [SlashInvariantForm.const_toFun, ModularForm.is_invariant_const] using atImInfty.const_boundedAtFilter x @[simp] lemma const_apply (x : ℂ) (τ : ℍ) : (const x : ModularForm Γ 0) τ = x := rfl instance : One (ModularForm Γ 0) where one := { const 1 with toSlashInvariantForm := 1 } @[simp] theorem one_coe_eq_one : ⇑(1 : ModularForm Γ 0) = 1 := rfl instance (Γ : Subgroup SL(2, ℤ)) : NatCast (ModularForm Γ 0) where natCast n := const n @[simp, norm_cast] lemma coe_natCast (Γ : Subgroup SL(2, ℤ)) (n : ℕ) : ⇑(n : ModularForm Γ 0) = n := rfl lemma toSlashInvariantForm_natCast (Γ : Subgroup SL(2, ℤ)) (n : ℕ) : (n : ModularForm Γ 0).toSlashInvariantForm = n := rfl instance (Γ : Subgroup SL(2, ℤ)) : IntCast (ModularForm Γ 0) where intCast z := const z @[simp, norm_cast] lemma coe_intCast (Γ : Subgroup SL(2, ℤ)) (z : ℤ) : ⇑(z : ModularForm Γ 0) = z := rfl lemma toSlashInvariantForm_intCast (Γ : Subgroup SL(2, ℤ)) (z : ℤ) : (z : ModularForm Γ 0).toSlashInvariantForm = z := rfl end ModularForm namespace CuspForm open ModularForm variable {F : Type*} {Γ : Subgroup SL(2, ℤ)} {k : ℤ} instance hasAdd : Add (CuspForm Γ k) := ⟨fun f g => { toSlashInvariantForm := f + g holo' := f.holo'.add g.holo' zero_at_infty' := fun A => by simpa using (f.zero_at_infty' A).add (g.zero_at_infty' A) }⟩ @[simp] theorem coe_add (f g : CuspForm Γ k) : ⇑(f + g) = f + g := rfl @[simp] theorem add_apply (f g : CuspForm Γ k) (z : ℍ) : (f + g) z = f z + g z := rfl instance instZero : Zero (CuspForm Γ k) := ⟨ { toSlashInvariantForm := 0 holo' := fun _ => mdifferentiableAt_const zero_at_infty' := by simpa using Filter.zero_zeroAtFilter _ } ⟩ @[simp] theorem coe_zero : ⇑(0 : CuspForm Γ k) = (0 : ℍ → ℂ) := rfl @[simp] theorem zero_apply (z : ℍ) : (0 : CuspForm Γ k) z = 0 := rfl section variable {α : Type*} [SMul α ℂ] [IsScalarTower α ℂ ℂ] instance instSMul : SMul α (CuspForm Γ k) := ⟨fun c f => { toSlashInvariantForm := c • f.1 holo' := by simpa using f.holo'.const_smul (c • (1 : ℂ)) zero_at_infty' := fun A => by simpa using (f.zero_at_infty' A).smul (c • (1 : ℂ)) }⟩ @[simp] theorem coe_smul (f : CuspForm Γ k) (n : α) : ⇑(n • f) = n • ⇑f := rfl @[simp] theorem smul_apply (f : CuspForm Γ k) (n : α) {z : ℍ} : (n • f) z = n • f z := rfl end instance instNeg : Neg (CuspForm Γ k) := ⟨fun f => { toSlashInvariantForm := -f.1 holo' := f.holo'.neg zero_at_infty' := fun A => by simpa using (f.zero_at_infty' A).neg }⟩ @[simp] theorem coe_neg (f : CuspForm Γ k) : ⇑(-f) = -f := rfl @[simp] theorem neg_apply (f : CuspForm Γ k) (z : ℍ) : (-f) z = -f z := rfl instance instSub : Sub (CuspForm Γ k) := ⟨fun f g => f + -g⟩ @[simp] theorem coe_sub (f g : CuspForm Γ k) : ⇑(f - g) = f - g := rfl @[simp] theorem sub_apply (f g : CuspForm Γ k) (z : ℍ) : (f - g) z = f z - g z := rfl instance : AddCommGroup (CuspForm Γ k) := DFunLike.coe_injective.addCommGroup _ rfl coe_add coe_neg coe_sub coe_smul coe_smul /-- Additive coercion from `CuspForm` to `ℍ → ℂ`. -/ @[simps] def coeHom : CuspForm Γ k →+ ℍ → ℂ where toFun f := f map_zero' := CuspForm.coe_zero map_add' _ _ := rfl instance : Module ℂ (CuspForm Γ k) := Function.Injective.module ℂ coeHom DFunLike.coe_injective fun _ _ => rfl instance : Inhabited (CuspForm Γ k) := ⟨0⟩ instance (priority := 99) [FunLike F ℍ ℂ] [CuspFormClass F Γ k] : ModularFormClass F Γ k where slash_action_eq := SlashInvariantFormClass.slash_action_eq holo := CuspFormClass.holo bdd_at_infty _ _ := (CuspFormClass.zero_at_infty _ _).boundedAtFilter end CuspForm namespace ModularForm section GradedRing /-- Cast for modular forms, which is useful for avoiding `Heq`s. -/ def mcast {a b : ℤ} {Γ : Subgroup SL(2, ℤ)} (h : a = b) (f : ModularForm Γ a) : ModularForm Γ b where toFun := (f : ℍ → ℂ) slash_action_eq' A := h ▸ f.slash_action_eq' A holo' := f.holo' bdd_at_infty' A := h ▸ f.bdd_at_infty' A @[ext (iff := false)] theorem gradedMonoid_eq_of_cast {Γ : Subgroup SL(2, ℤ)} {a b : GradedMonoid (ModularForm Γ)} (h : a.fst = b.fst) (h2 : mcast h a.snd = b.snd) : a = b := by obtain ⟨i, a⟩ := a obtain ⟨j, b⟩ := b cases h exact congr_arg _ h2 instance (Γ : Subgroup SL(2, ℤ)) : GradedMonoid.GOne (ModularForm Γ) where one := 1 instance (Γ : Subgroup SL(2, ℤ)) : GradedMonoid.GMul (ModularForm Γ) where mul f g := f.mul g instance instGCommRing (Γ : Subgroup SL(2, ℤ)) : DirectSum.GCommRing (ModularForm Γ) where one_mul _ := gradedMonoid_eq_of_cast (zero_add _) (ext fun _ => one_mul _) mul_one _ := gradedMonoid_eq_of_cast (add_zero _) (ext fun _ => mul_one _) mul_assoc _ _ _ := gradedMonoid_eq_of_cast (add_assoc _ _ _) (ext fun _ => mul_assoc _ _ _) mul_zero {_ _} _ := ext fun _ => mul_zero _ zero_mul {_ _} _ := ext fun _ => zero_mul _ mul_add {_ _} _ _ _ := ext fun _ => mul_add _ _ _ add_mul {_ _} _ _ _ := ext fun _ => add_mul _ _ _ mul_comm _ _ := gradedMonoid_eq_of_cast (add_comm _ _) (ext fun _ => mul_comm _ _) natCast := Nat.cast natCast_zero := ext fun _ => Nat.cast_zero natCast_succ _ := ext fun _ => Nat.cast_succ _ intCast := Int.cast intCast_ofNat _ := ext fun _ => AddGroupWithOne.intCast_ofNat _ intCast_negSucc_ofNat _ := ext fun _ => AddGroupWithOne.intCast_negSucc _ instance instGAlgebra (Γ : Subgroup SL(2, ℤ)) : DirectSum.GAlgebra ℂ (ModularForm Γ) where toFun := { toFun := const, map_zero' := rfl, map_add' := fun _ _ => rfl } map_one := rfl map_mul _x _y := rfl commutes _c _x := gradedMonoid_eq_of_cast (add_comm _ _) (ext fun _ => mul_comm _ _) smul_def _x _x := gradedMonoid_eq_of_cast (zero_add _).symm (ext fun _ => rfl) open scoped DirectSum in example (Γ : Subgroup SL(2, ℤ)) : Algebra ℂ (⨁ i, ModularForm Γ i) := inferInstance end GradedRing end ModularForm
Mathlib/NumberTheory/ModularForms/Basic.lean
445
450
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Patrick Massot -/ import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic import Mathlib.MeasureTheory.Measure.Real import Mathlib.Order.Filter.IndicatorFunction /-! # The dominated convergence theorem This file collects various results related to the Lebesgue dominated convergence theorem for the Bochner integral. ## Main results - `MeasureTheory.tendsto_integral_of_dominated_convergence`: the Lebesgue dominated convergence theorem for the Bochner integral - `MeasureTheory.hasSum_integral_of_dominated_convergence`: the Lebesgue dominated convergence theorem for series - `MeasureTheory.integral_tsum`, `MeasureTheory.integral_tsum_of_summable_integral_norm`: the integral and `tsum`s commute, if the norms of the functions form a summable series - `intervalIntegral.hasSum_integral_of_dominated_convergence`: the Lebesgue dominated convergence theorem for parametric interval integrals - `intervalIntegral.continuous_of_dominated_interval`: continuity of the interval integral w.r.t. a parameter - `intervalIntegral.continuous_primitive` and friends: primitives of interval integrable measurable functions are continuous -/ open MeasureTheory Metric /-! ## The Lebesgue dominated convergence theorem for the Bochner integral -/ section DominatedConvergenceTheorem open Set Filter TopologicalSpace ENNReal open scoped Topology Interval namespace MeasureTheory variable {α E G : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup G] [NormedSpace ℝ G] {m : MeasurableSpace α} {μ : Measure α} /-- **Lebesgue dominated convergence theorem** provides sufficient conditions under which almost everywhere convergence of a sequence of functions implies the convergence of their integrals. We could weaken the condition `bound_integrable` to require `HasFiniteIntegral bound μ` instead (i.e. not requiring that `bound` is measurable), but in all applications proving integrability is easier. -/ theorem tendsto_integral_of_dominated_convergence {F : ℕ → α → G} {f : α → G} (bound : α → ℝ) (F_measurable : ∀ n, AEStronglyMeasurable (F n) μ) (bound_integrable : Integrable bound μ) (h_bound : ∀ n, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : Tendsto (fun n => ∫ a, F n a ∂μ) atTop (𝓝 <| ∫ a, f a ∂μ) := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact tendsto_setToFun_of_dominated_convergence (dominatedFinMeasAdditive_weightedSMul μ) bound F_measurable bound_integrable h_bound h_lim · simp [integral, hG] /-- Lebesgue dominated convergence theorem for filters with a countable basis -/
theorem tendsto_integral_filter_of_dominated_convergence {ι} {l : Filter ι} [l.IsCountablyGenerated] {F : ι → α → G} {f : α → G} (bound : α → ℝ) (hF_meas : ∀ᶠ n in l, AEStronglyMeasurable (F n) μ) (h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a) (bound_integrable : Integrable bound μ) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) l (𝓝 (f a))) : Tendsto (fun n => ∫ a, F n a ∂μ) l (𝓝 <| ∫ a, f a ∂μ) := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact tendsto_setToFun_filter_of_dominated_convergence (dominatedFinMeasAdditive_weightedSMul μ) bound hF_meas h_bound bound_integrable h_lim · simp [integral, hG, tendsto_const_nhds]
Mathlib/MeasureTheory/Integral/DominatedConvergence.lean
66
75
/- Copyright (c) 2021 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.Adapted import Mathlib.MeasureTheory.Constructions.BorelSpace.Order /-! # Stopping times, stopped processes and stopped values Definition and properties of stopping times. ## Main definitions * `MeasureTheory.IsStoppingTime`: a stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is `f i`-measurable * `MeasureTheory.IsStoppingTime.measurableSpace`: the σ-algebra associated with a stopping time ## Main results * `ProgMeasurable.stoppedProcess`: the stopped process of a progressively measurable process is progressively measurable. * `memLp_stoppedProcess`: if a process belongs to `ℒp` at every time in `ℕ`, then its stopped process belongs to `ℒp` as well. ## Tags stopping time, stochastic process -/ open Filter Order TopologicalSpace open scoped MeasureTheory NNReal ENNReal Topology namespace MeasureTheory variable {Ω β ι : Type*} {m : MeasurableSpace Ω} /-! ### Stopping times -/ /-- A stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is measurable with respect to `f i`. Intuitively, the stopping time `τ` describes some stopping rule such that at time `i`, we may determine it with the information we have at time `i`. -/ def IsStoppingTime [Preorder ι] (f : Filtration ι m) (τ : Ω → ι) := ∀ i : ι, MeasurableSet[f i] <| {ω | τ ω ≤ i} theorem isStoppingTime_const [Preorder ι] (f : Filtration ι m) (i : ι) : IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.const] section MeasurableSet section Preorder variable [Preorder ι] {f : Filtration ι m} {τ : Ω → ι} protected theorem IsStoppingTime.measurableSet_le (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω ≤ i} := hτ i theorem IsStoppingTime.measurableSet_lt_of_pred [PredOrder ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by by_cases hi_min : IsMin i · suffices {ω : Ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 ω simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false] rw [isMin_iff_forall_not_lt] at hi_min exact hi_min (τ ω) have : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iic (pred i) := by ext; simp [Iic_pred_of_not_isMin hi_min] rw [this] exact f.mono (pred_le i) _ (hτ.measurableSet_le <| pred i) end Preorder section CountableStoppingTime namespace IsStoppingTime variable [PartialOrder ι] {τ : Ω → ι} {f : Filtration ι m} protected theorem measurableSet_eq_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := by have : {ω | τ ω = i} = {ω | τ ω ≤ i} \ ⋃ (j ∈ Set.range τ) (_ : j < i), {ω | τ ω ≤ j} := by ext1 a simp only [Set.mem_setOf_eq, Set.mem_range, Set.iUnion_exists, Set.iUnion_iUnion_eq', Set.mem_diff, Set.mem_iUnion, exists_prop, not_exists, not_and, not_le] constructor <;> intro h · simp only [h, lt_iff_le_not_le, le_refl, and_imp, imp_self, imp_true_iff, and_self_iff] · exact h.1.eq_or_lt.resolve_right fun h_lt => h.2 a h_lt le_rfl rw [this] refine (hτ.measurableSet_le i).diff ?_ refine MeasurableSet.biUnion h_countable fun j _ => ?_ classical rw [Set.iUnion_eq_if] split_ifs with hji · exact f.mono hji.le _ (hτ.measurableSet_le j) · exact @MeasurableSet.empty _ (f i) protected theorem measurableSet_eq_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := hτ.measurableSet_eq_of_countable_range (Set.to_countable _) i protected theorem measurableSet_lt_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω; simp [lt_iff_le_and_ne] rw [this] exact (hτ.measurableSet_le i).diff (hτ.measurableSet_eq_of_countable_range h_countable i) protected theorem measurableSet_lt_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := hτ.measurableSet_lt_of_countable_range (Set.to_countable _) i protected theorem measurableSet_ge_of_countable_range {ι} [LinearOrder ι] {τ : Ω → ι} {f : Filtration ι m} (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hτ.measurableSet_lt_of_countable_range h_countable i).compl protected theorem measurableSet_ge_of_countable {ι} [LinearOrder ι] {τ : Ω → ι} {f : Filtration ι m} [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := hτ.measurableSet_ge_of_countable_range (Set.to_countable _) i end IsStoppingTime end CountableStoppingTime section LinearOrder variable [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} theorem IsStoppingTime.measurableSet_gt (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i < τ ω} := by have : {ω | i < τ ω} = {ω | τ ω ≤ i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_le] rw [this] exact (hτ.measurableSet_le i).compl section TopologicalSpace variable [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] /-- Auxiliary lemma for `MeasureTheory.IsStoppingTime.measurableSet_lt`. -/ theorem IsStoppingTime.measurableSet_lt_of_isLUB (hτ : IsStoppingTime f τ) (i : ι) (h_lub : IsLUB (Set.Iio i) i) : MeasurableSet[f i] {ω | τ ω < i} := by by_cases hi_min : IsMin i · suffices {ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 ω simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false] exact isMin_iff_forall_not_lt.mp hi_min (τ ω) obtain ⟨seq, -, -, h_tendsto, h_bound⟩ : ∃ seq : ℕ → ι, Monotone seq ∧ (∀ j, seq j ≤ i) ∧ Tendsto seq atTop (𝓝 i) ∧ ∀ j, seq j < i := h_lub.exists_seq_monotone_tendsto (not_isMin_iff.mp hi_min) have h_Ioi_eq_Union : Set.Iio i = ⋃ j, {k | k ≤ seq j} := by ext1 k simp only [Set.mem_Iio, Set.mem_iUnion, Set.mem_setOf_eq] refine ⟨fun hk_lt_i => ?_, fun h_exists_k_le_seq => ?_⟩ · rw [tendsto_atTop'] at h_tendsto have h_nhds : Set.Ici k ∈ 𝓝 i := mem_nhds_iff.mpr ⟨Set.Ioi k, Set.Ioi_subset_Ici le_rfl, isOpen_Ioi, hk_lt_i⟩ obtain ⟨a, ha⟩ : ∃ a : ℕ, ∀ b : ℕ, b ≥ a → k ≤ seq b := h_tendsto (Set.Ici k) h_nhds exact ⟨a, ha a le_rfl⟩ · obtain ⟨j, hk_seq_j⟩ := h_exists_k_le_seq exact hk_seq_j.trans_lt (h_bound j) have h_lt_eq_preimage : {ω | τ ω < i} = τ ⁻¹' Set.Iio i := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_preimage, Set.mem_Iio] rw [h_lt_eq_preimage, h_Ioi_eq_Union] simp only [Set.preimage_iUnion, Set.preimage_setOf_eq] exact MeasurableSet.iUnion fun n => f.mono (h_bound n).le _ (hτ.measurableSet_le (seq n)) theorem IsStoppingTime.measurableSet_lt (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by obtain ⟨i', hi'_lub⟩ : ∃ i', IsLUB (Set.Iio i) i' := exists_lub_Iio i rcases lub_Iio_eq_self_or_Iio_eq_Iic i hi'_lub with hi'_eq_i | h_Iio_eq_Iic · rw [← hi'_eq_i] at hi'_lub ⊢ exact hτ.measurableSet_lt_of_isLUB i' hi'_lub · have h_lt_eq_preimage : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iio i := rfl rw [h_lt_eq_preimage, h_Iio_eq_Iic] exact f.mono (lub_Iio_le i hi'_lub) _ (hτ.measurableSet_le i') theorem IsStoppingTime.measurableSet_ge (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hτ.measurableSet_lt i).compl theorem IsStoppingTime.measurableSet_eq (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := by have : {ω | τ ω = i} = {ω | τ ω ≤ i} ∩ {ω | τ ω ≥ i} := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_inter_iff, le_antisymm_iff] rw [this] exact (hτ.measurableSet_le i).inter (hτ.measurableSet_ge i) theorem IsStoppingTime.measurableSet_eq_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) : MeasurableSet[f j] {ω | τ ω = i} := f.mono hle _ <| hτ.measurableSet_eq i theorem IsStoppingTime.measurableSet_lt_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) : MeasurableSet[f j] {ω | τ ω < i} := f.mono hle _ <| hτ.measurableSet_lt i end TopologicalSpace end LinearOrder section Countable theorem isStoppingTime_of_measurableSet_eq [Preorder ι] [Countable ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : ∀ i, MeasurableSet[f i] {ω | τ ω = i}) : IsStoppingTime f τ := by intro i rw [show {ω | τ ω ≤ i} = ⋃ k ≤ i, {ω | τ ω = k} by ext; simp] refine MeasurableSet.biUnion (Set.to_countable _) fun k hk => ?_ exact f.mono hk _ (hτ k) end Countable end MeasurableSet namespace IsStoppingTime protected theorem max [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f fun ω => max (τ ω) (π ω) := by intro i simp_rw [max_le_iff, Set.setOf_and] exact (hτ i).inter (hπ i) protected theorem max_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => max (τ ω) i := hτ.max (isStoppingTime_const f i) protected theorem min [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f fun ω => min (τ ω) (π ω) := by intro i simp_rw [min_le_iff, Set.setOf_or] exact (hτ i).union (hπ i) protected theorem min_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => min (τ ω) i := hτ.min (isStoppingTime_const f i) theorem add_const [AddGroup ι] [Preorder ι] [AddRightMono ι] [AddLeftMono ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) {i : ι} (hi : 0 ≤ i) : IsStoppingTime f fun ω => τ ω + i := by intro j simp_rw [← le_sub_iff_add_le] exact f.mono (sub_le_self j hi) _ (hτ (j - i)) theorem add_const_nat {f : Filtration ℕ m} {τ : Ω → ℕ} (hτ : IsStoppingTime f τ) {i : ℕ} : IsStoppingTime f fun ω => τ ω + i := by refine isStoppingTime_of_measurableSet_eq fun j => ?_ by_cases hij : i ≤ j · simp_rw [eq_comm, ← Nat.sub_eq_iff_eq_add hij, eq_comm] exact f.mono (j.sub_le i) _ (hτ.measurableSet_eq (j - i)) · rw [not_le] at hij convert @MeasurableSet.empty _ (f.1 j) ext ω simp only [Set.mem_empty_iff_false, iff_false, Set.mem_setOf] omega -- generalize to certain countable type? theorem add {f : Filtration ℕ m} {τ π : Ω → ℕ} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f (τ + π) := by intro i rw [(_ : {ω | (τ + π) ω ≤ i} = ⋃ k ≤ i, {ω | π ω = k} ∩ {ω | τ ω + k ≤ i})] · exact MeasurableSet.iUnion fun k => MeasurableSet.iUnion fun hk => (hπ.measurableSet_eq_le hk).inter (hτ.add_const_nat i) ext ω simp only [Pi.add_apply, Set.mem_setOf_eq, Set.mem_iUnion, Set.mem_inter_iff, exists_prop] refine ⟨fun h => ⟨π ω, by omega, rfl, h⟩, ?_⟩ rintro ⟨j, hj, rfl, h⟩ assumption section Preorder variable [Preorder ι] {f : Filtration ι m} {τ π : Ω → ι} /-- The associated σ-algebra with a stopping time. -/ protected def measurableSpace (hτ : IsStoppingTime f τ) : MeasurableSpace Ω where MeasurableSet' s := ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) measurableSet_empty i := (Set.empty_inter {ω | τ ω ≤ i}).symm ▸ @MeasurableSet.empty _ (f i) measurableSet_compl s hs i := by rw [(_ : sᶜ ∩ {ω | τ ω ≤ i} = (sᶜ ∪ {ω | τ ω ≤ i}ᶜ) ∩ {ω | τ ω ≤ i})] · refine MeasurableSet.inter ?_ ?_ · rw [← Set.compl_inter] exact (hs i).compl · exact hτ i · rw [Set.union_inter_distrib_right] simp only [Set.compl_inter_self, Set.union_empty] measurableSet_iUnion s hs i := by rw [forall_swap] at hs rw [Set.iUnion_inter] exact MeasurableSet.iUnion (hs i) protected theorem measurableSet (hτ : IsStoppingTime f τ) (s : Set Ω) : MeasurableSet[hτ.measurableSpace] s ↔ ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) := Iff.rfl theorem measurableSpace_mono (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (hle : τ ≤ π) : hτ.measurableSpace ≤ hπ.measurableSpace := by intro s hs i rw [(_ : s ∩ {ω | π ω ≤ i} = s ∩ {ω | τ ω ≤ i} ∩ {ω | π ω ≤ i})] · exact (hs i).inter (hπ i) · ext simp only [Set.mem_inter_iff, iff_self_and, and_congr_left_iff, Set.mem_setOf_eq] intro hle' _ exact le_trans (hle _) hle' theorem measurableSpace_le_of_countable [Countable ι] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs rw [(_ : s = ⋃ i, s ∩ {ω | τ ω ≤ i})] · exact MeasurableSet.iUnion fun i => f.le i _ (hs i) · ext ω; constructor <;> rw [Set.mem_iUnion] · exact fun hx => ⟨τ ω, hx, le_rfl⟩ · rintro ⟨_, hx, _⟩ exact hx theorem measurableSpace_le [IsCountablyGenerated (atTop : Filter ι)] [IsDirected ι (· ≤ ·)] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by intro s hs cases isEmpty_or_nonempty ι · haveI : IsEmpty Ω := ⟨fun ω => IsEmpty.false (τ ω)⟩ apply Subsingleton.measurableSet · change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs obtain ⟨seq : ℕ → ι, h_seq_tendsto⟩ := (atTop : Filter ι).exists_seq_tendsto rw [(_ : s = ⋃ n, s ∩ {ω | τ ω ≤ seq n})] · exact MeasurableSet.iUnion fun i => f.le (seq i) _ (hs (seq i)) · ext ω; constructor <;> rw [Set.mem_iUnion] · intro hx suffices ∃ i, τ ω ≤ seq i from ⟨this.choose, hx, this.choose_spec⟩ rw [tendsto_atTop] at h_seq_tendsto exact (h_seq_tendsto (τ ω)).exists · rintro ⟨_, hx, _⟩ exact hx @[deprecated (since := "2024-12-25")] alias measurableSpace_le' := measurableSpace_le example {f : Filtration ℕ m} {τ : Ω → ℕ} (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := hτ.measurableSpace_le example {f : Filtration ℝ m} {τ : Ω → ℝ} (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := hτ.measurableSpace_le @[simp] theorem measurableSpace_const (f : Filtration ι m) (i : ι) : (isStoppingTime_const f i).measurableSpace = f i := by ext1 s change MeasurableSet[(isStoppingTime_const f i).measurableSpace] s ↔ MeasurableSet[f i] s rw [IsStoppingTime.measurableSet] constructor <;> intro h · specialize h i simpa only [le_refl, Set.setOf_true, Set.inter_univ] using h · intro j by_cases hij : i ≤ j · simp only [hij, Set.setOf_true, Set.inter_univ] exact f.mono hij _ h · simp only [hij, Set.setOf_false, Set.inter_empty, @MeasurableSet.empty _ (f.1 j)] theorem measurableSet_inter_eq_iff (hτ : IsStoppingTime f τ) (s : Set Ω) (i : ι) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω = i}) ↔ MeasurableSet[f i] (s ∩ {ω | τ ω = i}) := by have : ∀ j, {ω : Ω | τ ω = i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω = i} ∩ {_ω | i ≤ j} := by intro j ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq, and_congr_right_iff] intro hxi rw [hxi] constructor <;> intro h · specialize h i simpa only [Set.inter_assoc, this, le_refl, Set.setOf_true, Set.inter_univ] using h · intro j rw [Set.inter_assoc, this] by_cases hij : i ≤ j · simp only [hij, Set.setOf_true, Set.inter_univ] exact f.mono hij _ h · simp [hij] theorem measurableSpace_le_of_le_const (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, τ ω ≤ i) : hτ.measurableSpace ≤ f i := (measurableSpace_mono hτ _ hτ_le).trans (measurableSpace_const _ _).le theorem measurableSpace_le_of_le (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : hτ.measurableSpace ≤ m := (hτ.measurableSpace_le_of_le_const hτ_le).trans (f.le n) theorem le_measurableSpace_of_const_le (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, i ≤ τ ω) : f i ≤ hτ.measurableSpace := (measurableSpace_const _ _).symm.le.trans (measurableSpace_mono _ hτ hτ_le) end Preorder instance sigmaFinite_stopping_time {ι} [SemilatticeSup ι] [OrderBot ι] [(Filter.atTop : Filter ι).IsCountablyGenerated] {μ : Measure Ω} {f : Filtration ι m} {τ : Ω → ι} [SigmaFiniteFiltration μ f] (hτ : IsStoppingTime f τ) : SigmaFinite (μ.trim hτ.measurableSpace_le) := by refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_ · exact f ⊥ · exact hτ.le_measurableSpace_of_const_le fun _ => bot_le · infer_instance instance sigmaFinite_stopping_time_of_le {ι} [SemilatticeSup ι] [OrderBot ι] {μ : Measure Ω} {f : Filtration ι m} {τ : Ω → ι} [SigmaFiniteFiltration μ f] (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le)) := by refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_ · exact f ⊥ · exact hτ.le_measurableSpace_of_const_le fun _ => bot_le · infer_instance section LinearOrder variable [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} protected theorem measurableSet_le' (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω ≤ i} := by intro j have : {ω : Ω | τ ω ≤ i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω ≤ min i j} := by ext1 ω; simp only [Set.mem_inter_iff, Set.mem_setOf_eq, le_min_iff] rw [this] exact f.mono (min_le_right i j) _ (hτ _) protected theorem measurableSet_gt' (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i < τ ω} := by have : {ω : Ω | i < τ ω} = {ω : Ω | τ ω ≤ i}ᶜ := by ext1 ω; simp rw [this] exact (hτ.measurableSet_le' i).compl protected theorem measurableSet_eq' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter] exact hτ.measurableSet_eq i protected theorem measurableSet_ge' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by ext1 ω simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union] rw [@eq_comm _ i, or_comm] rw [this] exact (hτ.measurableSet_eq' i).union (hτ.measurableSet_gt' i) protected theorem measurableSet_lt' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff] rw [this] exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq' i) section Countable protected theorem measurableSet_eq_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter] exact hτ.measurableSet_eq_of_countable_range h_countable i protected theorem measurableSet_eq_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := hτ.measurableSet_eq_of_countable_range' (Set.to_countable _) i protected theorem measurableSet_ge_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by ext1 ω simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union] rw [@eq_comm _ i, or_comm] rw [this] exact (hτ.measurableSet_eq_of_countable_range' h_countable i).union (hτ.measurableSet_gt' i) protected theorem measurableSet_ge_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := hτ.measurableSet_ge_of_countable_range' (Set.to_countable _) i protected theorem measurableSet_lt_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff] rw [this] exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq_of_countable_range' h_countable i) protected theorem measurableSet_lt_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := hτ.measurableSet_lt_of_countable_range' (Set.to_countable _) i protected theorem measurableSpace_le_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs rw [(_ : s = ⋃ i ∈ Set.range τ, s ∩ {ω | τ ω ≤ i})] · exact MeasurableSet.biUnion h_countable fun i _ => f.le i _ (hs i) · ext ω constructor <;> rw [Set.mem_iUnion] · exact fun hx => ⟨τ ω, by simpa using hx⟩ · rintro ⟨i, hx⟩ simp only [Set.mem_range, Set.iUnion_exists, Set.mem_iUnion, Set.mem_inter_iff, Set.mem_setOf_eq, exists_prop, exists_and_right] at hx exact hx.2.1 end Countable protected theorem measurable [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) : Measurable[hτ.measurableSpace] τ := @measurable_of_Iic ι Ω _ _ _ hτ.measurableSpace _ _ _ _ fun i => hτ.measurableSet_le' i protected theorem measurable_of_le [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, τ ω ≤ i) : Measurable[f i] τ := hτ.measurable.mono (measurableSpace_le_of_le_const _ hτ_le) le_rfl theorem measurableSpace_min (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : (hτ.min hπ).measurableSpace = hτ.measurableSpace ⊓ hπ.measurableSpace := by refine le_antisymm ?_ ?_ · exact le_inf (measurableSpace_mono _ hτ fun _ => min_le_left _ _) (measurableSpace_mono _ hπ fun _ => min_le_right _ _) · intro s change MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s → MeasurableSet[(hτ.min hπ).measurableSpace] s simp_rw [IsStoppingTime.measurableSet] have : ∀ i, {ω | min (τ ω) (π ω) ≤ i} = {ω | τ ω ≤ i} ∪ {ω | π ω ≤ i} := by intro i; ext1 ω; simp simp_rw [this, Set.inter_union_distrib_left] exact fun h i => (h.left i).union (h.right i) theorem measurableSet_min_iff (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) : MeasurableSet[(hτ.min hπ).measurableSpace] s ↔ MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s := by rw [measurableSpace_min hτ hπ]; rfl theorem measurableSpace_min_const (hτ : IsStoppingTime f τ) {i : ι} : (hτ.min_const i).measurableSpace = hτ.measurableSpace ⊓ f i := by rw [hτ.measurableSpace_min (isStoppingTime_const _ i), measurableSpace_const] theorem measurableSet_min_const_iff (hτ : IsStoppingTime f τ) (s : Set Ω) {i : ι} : MeasurableSet[(hτ.min_const i).measurableSpace] s ↔ MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[f i] s := by rw [measurableSpace_min_const hτ]; apply MeasurableSpace.measurableSet_inf theorem measurableSet_inter_le [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) (hs : MeasurableSet[hτ.measurableSpace] s) : MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by simp_rw [IsStoppingTime.measurableSet] at hs ⊢ intro i have : s ∩ {ω | τ ω ≤ π ω} ∩ {ω | min (τ ω) (π ω) ≤ i} = s ∩ {ω | τ ω ≤ i} ∩ {ω | min (τ ω) (π ω) ≤ i} ∩ {ω | min (τ ω) i ≤ min (min (τ ω) (π ω)) i} := by ext1 ω simp only [min_le_iff, Set.mem_inter_iff, Set.mem_setOf_eq, le_min_iff, le_refl, true_and, true_or] by_cases hτi : τ ω ≤ i · simp only [hτi, true_or, and_true, and_congr_right_iff] intro constructor <;> intro h · exact Or.inl h · rcases h with h | h · exact h · exact hτi.trans h simp only [hτi, false_or, and_false, false_and, iff_false, not_and, not_le, and_imp] refine fun _ hτ_le_π => lt_of_lt_of_le ?_ hτ_le_π rw [← not_le] exact hτi rw [this] refine ((hs i).inter ((hτ.min hπ) i)).inter ?_ apply @measurableSet_le _ _ _ _ _ (Filtration.seq f i) _ _ _ _ _ ?_ ?_ · exact (hτ.min_const i).measurable_of_le fun _ => min_le_right _ _ · exact ((hτ.min hπ).min_const i).measurable_of_le fun _ => min_le_right _ _ theorem measurableSet_inter_le_iff [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) ↔ MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by constructor <;> intro h · have : s ∩ {ω | τ ω ≤ π ω} = s ∩ {ω | τ ω ≤ π ω} ∩ {ω | τ ω ≤ π ω} := by rw [Set.inter_assoc, Set.inter_self] rw [this] exact measurableSet_inter_le _ hπ _ h · rw [measurableSet_min_iff hτ hπ] at h exact h.1 theorem measurableSet_inter_le_const_iff (hτ : IsStoppingTime f τ) (s : Set Ω) (i : ι) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω ≤ i}) ↔ MeasurableSet[(hτ.min_const i).measurableSpace] (s ∩ {ω | τ ω ≤ i}) := by rw [IsStoppingTime.measurableSet_min_iff hτ (isStoppingTime_const _ i), IsStoppingTime.measurableSpace_const, IsStoppingTime.measurableSet] refine ⟨fun h => ⟨h, ?_⟩, fun h j => h.1 j⟩ specialize h i rwa [Set.inter_assoc, Set.inter_self] at h theorem measurableSet_le_stopping_time [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω ≤ π ω} := by rw [hτ.measurableSet] intro j have : {ω | τ ω ≤ π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j ≤ min (π ω) j} ∩ {ω | τ ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq, min_le_iff, le_min_iff, le_refl, and_congr_left_iff] intro h simp only [h, or_self_iff, and_true] rw [Iff.comm, or_iff_left_iff_imp] exact h.trans rw [this] refine MeasurableSet.inter ?_ (hτ.measurableSet_le j) apply @measurableSet_le _ _ _ _ _ (Filtration.seq f j) _ _ _ _ _ ?_ ?_ · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _ theorem measurableSet_stopping_time_le [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hπ.measurableSpace] {ω | τ ω ≤ π ω} := by suffices MeasurableSet[(hτ.min hπ).measurableSpace] {ω : Ω | τ ω ≤ π ω} by rw [measurableSet_min_iff hτ hπ] at this; exact this.2 rw [← Set.univ_inter {ω : Ω | τ ω ≤ π ω}, ← hτ.measurableSet_inter_le_iff hπ, Set.univ_inter] exact measurableSet_le_stopping_time hτ hπ theorem measurableSet_eq_stopping_time [AddGroup ι] [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [MeasurableSingletonClass ι] [SecondCountableTopology ι] [MeasurableSub₂ ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = π ω} := by rw [hτ.measurableSet] intro j have : {ω | τ ω = π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j = min (π ω) j} ∩ {ω | τ ω ≤ j} ∩ {ω | π ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq] refine ⟨fun h => ⟨⟨?_, h.2⟩, ?_⟩, fun h => ⟨?_, h.1.2⟩⟩ · rw [h.1] · rw [← h.1]; exact h.2 · obtain ⟨h', hσ_le⟩ := h obtain ⟨h_eq, hτ_le⟩ := h' rwa [min_eq_left hτ_le, min_eq_left hσ_le] at h_eq rw [this] refine MeasurableSet.inter (MeasurableSet.inter ?_ (hτ.measurableSet_le j)) (hπ.measurableSet_le j) apply measurableSet_eq_fun · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _ theorem measurableSet_eq_stopping_time_of_countable [Countable ι] [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [MeasurableSingletonClass ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = π ω} := by rw [hτ.measurableSet] intro j have : {ω | τ ω = π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j = min (π ω) j} ∩ {ω | τ ω ≤ j} ∩ {ω | π ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq] refine ⟨fun h => ⟨⟨?_, h.2⟩, ?_⟩, fun h => ⟨?_, h.1.2⟩⟩ · rw [h.1] · rw [← h.1]; exact h.2 · obtain ⟨h', hπ_le⟩ := h obtain ⟨h_eq, hτ_le⟩ := h' rwa [min_eq_left hτ_le, min_eq_left hπ_le] at h_eq rw [this] refine MeasurableSet.inter (MeasurableSet.inter ?_ (hτ.measurableSet_le j)) (hπ.measurableSet_le j) apply measurableSet_eq_fun_of_countable · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _ end LinearOrder end IsStoppingTime section LinearOrder /-! ## Stopped value and stopped process -/ /-- Given a map `u : ι → Ω → E`, its stopped value with respect to the stopping time `τ` is the map `x ↦ u (τ ω) ω`. -/ def stoppedValue (u : ι → Ω → β) (τ : Ω → ι) : Ω → β := fun ω => u (τ ω) ω theorem stoppedValue_const (u : ι → Ω → β) (i : ι) : (stoppedValue u fun _ => i) = u i := rfl variable [LinearOrder ι] /-- Given a map `u : ι → Ω → E`, the stopped process with respect to `τ` is `u i ω` if `i ≤ τ ω`, and `u (τ ω) ω` otherwise. Intuitively, the stopped process stops evolving once the stopping time has occurred. -/ def stoppedProcess (u : ι → Ω → β) (τ : Ω → ι) : ι → Ω → β := fun i ω => u (min i (τ ω)) ω theorem stoppedProcess_eq_stoppedValue {u : ι → Ω → β} {τ : Ω → ι} : stoppedProcess u τ = fun i => stoppedValue u fun ω => min i (τ ω) := rfl theorem stoppedValue_stoppedProcess {u : ι → Ω → β} {τ σ : Ω → ι} : stoppedValue (stoppedProcess u τ) σ = stoppedValue u fun ω => min (σ ω) (τ ω) := rfl theorem stoppedProcess_eq_of_le {u : ι → Ω → β} {τ : Ω → ι} {i : ι} {ω : Ω} (h : i ≤ τ ω) : stoppedProcess u τ i ω = u i ω := by simp [stoppedProcess, min_eq_left h] theorem stoppedProcess_eq_of_ge {u : ι → Ω → β} {τ : Ω → ι} {i : ι} {ω : Ω} (h : τ ω ≤ i) : stoppedProcess u τ i ω = u (τ ω) ω := by simp [stoppedProcess, min_eq_right h] section ProgMeasurable variable [MeasurableSpace ι] [TopologicalSpace ι] [OrderTopology ι] [SecondCountableTopology ι] [BorelSpace ι] [TopologicalSpace β] {u : ι → Ω → β} {τ : Ω → ι} {f : Filtration ι m} theorem progMeasurable_min_stopping_time [MetrizableSpace ι] (hτ : IsStoppingTime f τ) : ProgMeasurable f fun i ω => min i (τ ω) := by intro i let m_prod : MeasurableSpace (Set.Iic i × Ω) := Subtype.instMeasurableSpace.prod (f i) let m_set : ∀ t : Set (Set.Iic i × Ω), MeasurableSpace t := fun _ => @Subtype.instMeasurableSpace (Set.Iic i × Ω) _ m_prod let s := {p : Set.Iic i × Ω | τ p.2 ≤ i} have hs : MeasurableSet[m_prod] s := @measurable_snd (Set.Iic i) Ω _ (f i) _ (hτ i) have h_meas_fst : ∀ t : Set (Set.Iic i × Ω), Measurable[m_set t] fun x : t => ((x : Set.Iic i × Ω).fst : ι) := fun t => (@measurable_subtype_coe (Set.Iic i × Ω) m_prod _).fst.subtype_val apply Measurable.stronglyMeasurable refine measurable_of_restrict_of_restrict_compl hs ?_ ?_ · refine @Measurable.min _ _ _ _ _ (m_set s) _ _ _ _ _ (h_meas_fst s) ?_ refine @measurable_of_Iic ι s _ _ _ (m_set s) _ _ _ _ fun j => ?_ have h_set_eq : (fun x : s => τ (x : Set.Iic i × Ω).snd) ⁻¹' Set.Iic j = (fun x : s => (x : Set.Iic i × Ω).snd) ⁻¹' {ω | τ ω ≤ min i j} := by ext1 ω simp only [Set.mem_preimage, Set.mem_Iic, iff_and_self, le_min_iff, Set.mem_setOf_eq] exact fun _ => ω.prop rw [h_set_eq] suffices h_meas : @Measurable _ _ (m_set s) (f i) fun x : s ↦ (x : Set.Iic i × Ω).snd from h_meas (f.mono (min_le_left _ _) _ (hτ.measurableSet_le (min i j))) exact measurable_snd.comp (@measurable_subtype_coe _ m_prod _) · letI sc := sᶜ suffices h_min_eq_left : (fun x : sc => min (↑(x : Set.Iic i × Ω).fst) (τ (x : Set.Iic i × Ω).snd)) = fun x : sc => ↑(x : Set.Iic i × Ω).fst by simp +unfoldPartialApp only [sc, Set.restrict, h_min_eq_left] exact h_meas_fst _ ext1 ω rw [min_eq_left] have hx_fst_le : ↑(ω : Set.Iic i × Ω).fst ≤ i := (ω : Set.Iic i × Ω).fst.prop refine hx_fst_le.trans (le_of_lt ?_) convert ω.prop simp only [sc, s, not_le, Set.mem_compl_iff, Set.mem_setOf_eq] theorem ProgMeasurable.stoppedProcess [MetrizableSpace ι] (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ) : ProgMeasurable f (stoppedProcess u τ) := h.comp (progMeasurable_min_stopping_time hτ) fun _ _ => min_le_left _ _ theorem ProgMeasurable.adapted_stoppedProcess [MetrizableSpace ι] (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ) : Adapted f (MeasureTheory.stoppedProcess u τ) := (h.stoppedProcess hτ).adapted theorem ProgMeasurable.stronglyMeasurable_stoppedProcess [MetrizableSpace ι] (hu : ProgMeasurable f u) (hτ : IsStoppingTime f τ) (i : ι) : StronglyMeasurable (MeasureTheory.stoppedProcess u τ i) := (hu.adapted_stoppedProcess hτ i).mono (f.le _) theorem stronglyMeasurable_stoppedValue_of_le (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : StronglyMeasurable[f n] (stoppedValue u τ) := by have : stoppedValue u τ = (fun p : Set.Iic n × Ω => u (↑p.fst) p.snd) ∘ fun ω => (⟨τ ω, hτ_le ω⟩, ω) := by ext1 ω; simp only [stoppedValue, Function.comp_apply, Subtype.coe_mk] rw [this] refine StronglyMeasurable.comp_measurable (h n) ?_ exact (hτ.measurable_of_le hτ_le).subtype_mk.prodMk measurable_id theorem measurable_stoppedValue [MetrizableSpace β] [MeasurableSpace β] [BorelSpace β] (hf_prog : ProgMeasurable f u) (hτ : IsStoppingTime f τ) : Measurable[hτ.measurableSpace] (stoppedValue u τ) := by have h_str_meas : ∀ i, StronglyMeasurable[f i] (stoppedValue u fun ω => min (τ ω) i) := fun i => stronglyMeasurable_stoppedValue_of_le hf_prog (hτ.min_const i) fun _ => min_le_right _ _ intro t ht i suffices stoppedValue u τ ⁻¹' t ∩ {ω : Ω | τ ω ≤ i} = (stoppedValue u fun ω => min (τ ω) i) ⁻¹' t ∩ {ω : Ω | τ ω ≤ i} by rw [this]; exact ((h_str_meas i).measurable ht).inter (hτ.measurableSet_le i) ext1 ω simp only [stoppedValue, Set.mem_inter_iff, Set.mem_preimage, Set.mem_setOf_eq, and_congr_left_iff] intro h rw [min_eq_left h] end ProgMeasurable end LinearOrder section StoppedValueOfMemFinset variable {μ : Measure Ω} {τ : Ω → ι} {E : Type*} {p : ℝ≥0∞} {u : ι → Ω → E} theorem stoppedValue_eq_of_mem_finset [AddCommMonoid E] {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) : stoppedValue u τ = ∑ i ∈ s, Set.indicator {ω | τ ω = i} (u i) := by ext y classical rw [stoppedValue, Finset.sum_apply, Finset.sum_indicator_eq_sum_filter] suffices {i ∈ s | y ∈ {ω : Ω | τ ω = i}} = ({τ y} : Finset ι) by rw [this, Finset.sum_singleton] ext1 ω simp only [Set.mem_setOf_eq, Finset.mem_filter, Finset.mem_singleton] constructor <;> intro h · exact h.2.symm · refine ⟨?_, h.symm⟩; rw [h]; exact hbdd y theorem stoppedValue_eq' [Preorder ι] [LocallyFiniteOrderBot ι] [AddCommMonoid E] {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : stoppedValue u τ = ∑ i ∈ Finset.Iic N, Set.indicator {ω | τ ω = i} (u i) := stoppedValue_eq_of_mem_finset fun ω => Finset.mem_Iic.mpr (hbdd ω) theorem stoppedProcess_eq_of_mem_finset [LinearOrder ι] [AddCommMonoid E] {s : Finset ι} (n : ι) (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) + ∑ i ∈ s with i < n, Set.indicator {ω | τ ω = i} (u i) := by ext ω rw [Pi.add_apply, Finset.sum_apply] rcases le_or_lt n (τ ω) with h | h · rw [stoppedProcess_eq_of_le h, Set.indicator_of_mem, Finset.sum_eq_zero, add_zero] · intro m hm refine Set.indicator_of_not_mem ?_ _ rw [Finset.mem_filter] at hm exact (hm.2.trans_le h).ne' · exact h · rw [stoppedProcess_eq_of_ge (le_of_lt h), Finset.sum_eq_single_of_mem (τ ω)] · rw [Set.indicator_of_not_mem, zero_add, Set.indicator_of_mem] <;> rw [Set.mem_setOf] exact not_le.2 h · rw [Finset.mem_filter] exact ⟨hbdd ω h, h⟩ · intro b _ hneq rw [Set.indicator_of_not_mem] rw [Set.mem_setOf] exact hneq.symm theorem stoppedProcess_eq'' [LinearOrder ι] [LocallyFiniteOrderBot ι] [AddCommMonoid E] (n : ι) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) + ∑ i ∈ Finset.Iio n, Set.indicator {ω | τ ω = i} (u i) := by have h_mem : ∀ ω, τ ω < n → τ ω ∈ Finset.Iio n := fun ω h => Finset.mem_Iio.mpr h rw [stoppedProcess_eq_of_mem_finset n h_mem] congr with i simp section StoppedValue variable [PartialOrder ι] {ℱ : Filtration ι m} [NormedAddCommGroup E] theorem memLp_stoppedValue_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, MemLp (u n) p μ) {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) : MemLp (stoppedValue u τ) p μ := by rw [stoppedValue_eq_of_mem_finset hbdd] refine memLp_finset_sum' _ fun i _ => MemLp.indicator ?_ (hu i) refine ℱ.le i {a : Ω | τ a = i} (hτ.measurableSet_eq_of_countable_range ?_ i) refine ((Finset.finite_toSet s).subset fun ω hω => ?_).countable obtain ⟨y, rfl⟩ := hω exact hbdd y theorem memLp_stoppedValue [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, MemLp (u n) p μ) {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : MemLp (stoppedValue u τ) p μ := memLp_stoppedValue_of_mem_finset hτ hu fun ω => Finset.mem_Iic.mpr (hbdd ω) theorem integrable_stoppedValue_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) : Integrable (stoppedValue u τ) μ := by simp_rw [← memLp_one_iff_integrable] at hu ⊢ exact memLp_stoppedValue_of_mem_finset hτ hu hbdd variable (ι) theorem integrable_stoppedValue [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : Integrable (stoppedValue u τ) μ := integrable_stoppedValue_of_mem_finset hτ hu fun ω => Finset.mem_Iic.mpr (hbdd ω) end StoppedValue section StoppedProcess variable [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] {ℱ : Filtration ι m} [NormedAddCommGroup E] theorem memLp_stoppedProcess_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, MemLp (u n) p μ) (n : ι) {s : Finset ι} (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : MemLp (stoppedProcess u τ n) p μ := by rw [stoppedProcess_eq_of_mem_finset n hbdd] refine MemLp.add ?_ ?_ · exact MemLp.indicator (ℱ.le n {a : Ω | n ≤ τ a} (hτ.measurableSet_ge n)) (hu n) · suffices MemLp (fun ω => ∑ i ∈ s with i < n, {a : Ω | τ a = i}.indicator (u i) ω) p μ by convert this using 1; ext1 ω; simp only [Finset.sum_apply] refine memLp_finset_sum _ fun i _ => MemLp.indicator ?_ (hu i) exact ℱ.le i {a : Ω | τ a = i} (hτ.measurableSet_eq i) theorem memLp_stoppedProcess [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, MemLp (u n) p μ) (n : ι) : MemLp (stoppedProcess u τ n) p μ := memLp_stoppedProcess_of_mem_finset hτ hu n fun _ h => Finset.mem_Iio.mpr h theorem integrable_stoppedProcess_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) (n : ι) {s : Finset ι} (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : Integrable (stoppedProcess u τ n) μ := by simp_rw [← memLp_one_iff_integrable] at hu ⊢ exact memLp_stoppedProcess_of_mem_finset hτ hu n hbdd theorem integrable_stoppedProcess [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) (n : ι) : Integrable (stoppedProcess u τ n) μ := integrable_stoppedProcess_of_mem_finset hτ hu n fun _ h => Finset.mem_Iio.mpr h end StoppedProcess end StoppedValueOfMemFinset section AdaptedStoppedProcess variable [TopologicalSpace β] [PseudoMetrizableSpace β] [LinearOrder ι] [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] {f : Filtration ι m} {u : ι → Ω → β} {τ : Ω → ι} /-- The stopped process of an adapted process with continuous paths is adapted. -/ theorem Adapted.stoppedProcess [MetrizableSpace ι] (hu : Adapted f u) (hu_cont : ∀ ω, Continuous fun i => u i ω) (hτ : IsStoppingTime f τ) : Adapted f (stoppedProcess u τ) := ((hu.progMeasurable_of_continuous hu_cont).stoppedProcess hτ).adapted /-- If the indexing order has the discrete topology, then the stopped process of an adapted process is adapted. -/ theorem Adapted.stoppedProcess_of_discrete [DiscreteTopology ι] (hu : Adapted f u) (hτ : IsStoppingTime f τ) : Adapted f (MeasureTheory.stoppedProcess u τ) := (hu.progMeasurable_of_discrete.stoppedProcess hτ).adapted theorem Adapted.stronglyMeasurable_stoppedProcess [MetrizableSpace ι] (hu : Adapted f u) (hu_cont : ∀ ω, Continuous fun i => u i ω) (hτ : IsStoppingTime f τ) (n : ι) : StronglyMeasurable (MeasureTheory.stoppedProcess u τ n) := (hu.progMeasurable_of_continuous hu_cont).stronglyMeasurable_stoppedProcess hτ n theorem Adapted.stronglyMeasurable_stoppedProcess_of_discrete [DiscreteTopology ι] (hu : Adapted f u) (hτ : IsStoppingTime f τ) (n : ι) : StronglyMeasurable (MeasureTheory.stoppedProcess u τ n) := hu.progMeasurable_of_discrete.stronglyMeasurable_stoppedProcess hτ n end AdaptedStoppedProcess section Nat /-! ### Filtrations indexed by `ℕ` -/ open Filtration variable {u : ℕ → Ω → β} {τ π : Ω → ℕ} theorem stoppedValue_sub_eq_sum [AddCommGroup β] (hle : τ ≤ π) : stoppedValue u π - stoppedValue u τ = fun ω => (∑ i ∈ Finset.Ico (τ ω) (π ω), (u (i + 1) - u i)) ω := by ext ω rw [Finset.sum_Ico_eq_sub _ (hle ω), Finset.sum_range_sub, Finset.sum_range_sub] simp [stoppedValue] theorem stoppedValue_sub_eq_sum' [AddCommGroup β] (hle : τ ≤ π) {N : ℕ} (hbdd : ∀ ω, π ω ≤ N) : stoppedValue u π - stoppedValue u τ = fun ω => (∑ i ∈ Finset.range (N + 1), Set.indicator {ω | τ ω ≤ i ∧ i < π ω} (u (i + 1) - u i)) ω := by rw [stoppedValue_sub_eq_sum hle] ext ω simp only [Finset.sum_apply, Finset.sum_indicator_eq_sum_filter] refine Finset.sum_congr ?_ fun _ _ => rfl ext i simp only [Finset.mem_filter, Set.mem_setOf_eq, Finset.mem_range, Finset.mem_Ico] exact ⟨fun h => ⟨lt_trans h.2 (Nat.lt_succ_iff.2 <| hbdd _), h⟩, fun h => h.2⟩ section AddCommMonoid variable [AddCommMonoid β] theorem stoppedValue_eq {N : ℕ} (hbdd : ∀ ω, τ ω ≤ N) : stoppedValue u τ = fun x => (∑ i ∈ Finset.range (N + 1), Set.indicator {ω | τ ω = i} (u i)) x := stoppedValue_eq_of_mem_finset fun ω => Finset.mem_range_succ_iff.mpr (hbdd ω) theorem stoppedProcess_eq (n : ℕ) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) + ∑ i ∈ Finset.range n, Set.indicator {ω | τ ω = i} (u i) := by rw [stoppedProcess_eq'' n] congr with i rw [Finset.mem_Iio, Finset.mem_range] theorem stoppedProcess_eq' (n : ℕ) : stoppedProcess u τ n = Set.indicator {a | n + 1 ≤ τ a} (u n) + ∑ i ∈ Finset.range (n + 1), Set.indicator {a | τ a = i} (u i) := by have : {a | n ≤ τ a}.indicator (u n) = {a | n + 1 ≤ τ a}.indicator (u n) + {a | τ a = n}.indicator (u n) := by ext x rw [add_comm, Pi.add_apply, ← Set.indicator_union_of_not_mem_inter] · simp_rw [@eq_comm _ _ n, @le_iff_eq_or_lt _ _ n, Nat.succ_le_iff, Set.setOf_or] · rintro ⟨h₁, h₂⟩ rw [Set.mem_setOf] at h₁ h₂ exact (Nat.succ_le_iff.1 h₂).ne h₁.symm rw [stoppedProcess_eq, this, Finset.sum_range_succ_comm, ← add_assoc] end AddCommMonoid end Nat section PiecewiseConst variable [Preorder ι] {𝒢 : Filtration ι m} {τ η : Ω → ι} {i j : ι} {s : Set Ω} [DecidablePred (· ∈ s)] /-- Given stopping times `τ` and `η` which are bounded below, `Set.piecewise s τ η` is also a stopping time with respect to the same filtration. -/ theorem IsStoppingTime.piecewise_of_le (hτ_st : IsStoppingTime 𝒢 τ) (hη_st : IsStoppingTime 𝒢 η) (hτ : ∀ ω, i ≤ τ ω) (hη : ∀ ω, i ≤ η ω) (hs : MeasurableSet[𝒢 i] s) : IsStoppingTime 𝒢 (s.piecewise τ η) := by intro n have : {ω | s.piecewise τ η ω ≤ n} = s ∩ {ω | τ ω ≤ n} ∪ sᶜ ∩ {ω | η ω ≤ n} := by ext1 ω simp only [Set.piecewise, Set.mem_inter_iff, Set.mem_setOf_eq, and_congr_right_iff] by_cases hx : ω ∈ s <;> simp [hx] rw [this] by_cases hin : i ≤ n · have hs_n : MeasurableSet[𝒢 n] s := 𝒢.mono hin _ hs exact (hs_n.inter (hτ_st n)).union (hs_n.compl.inter (hη_st n)) · have hτn : ∀ ω, ¬τ ω ≤ n := fun ω hτn => hin ((hτ ω).trans hτn) have hηn : ∀ ω, ¬η ω ≤ n := fun ω hηn => hin ((hη ω).trans hηn) simp [hτn, hηn, @MeasurableSet.empty _ _] theorem isStoppingTime_piecewise_const (hij : i ≤ j) (hs : MeasurableSet[𝒢 i] s) : IsStoppingTime 𝒢 (s.piecewise (fun _ => i) fun _ => j) := (isStoppingTime_const 𝒢 i).piecewise_of_le (isStoppingTime_const 𝒢 j) (fun _ => le_rfl) (fun _ => hij) hs theorem stoppedValue_piecewise_const {ι' : Type*} {i j : ι'} {f : ι' → Ω → ℝ} : stoppedValue f (s.piecewise (fun _ => i) fun _ => j) = s.piecewise (f i) (f j) := by ext ω; rw [stoppedValue]; by_cases hx : ω ∈ s <;> simp [hx] theorem stoppedValue_piecewise_const' {ι' : Type*} {i j : ι'} {f : ι' → Ω → ℝ} : stoppedValue f (s.piecewise (fun _ => i) fun _ => j) = s.indicator (f i) + sᶜ.indicator (f j) := by ext ω; rw [stoppedValue]; by_cases hx : ω ∈ s <;> simp [hx] end PiecewiseConst section Condexp /-! ### Conditional expectation with respect to the σ-algebra generated by a stopping time -/ variable [LinearOrder ι] {μ : Measure Ω} {ℱ : Filtration ι m} {τ σ : Ω → ι} {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : Ω → E} theorem condExp_stopping_time_ae_eq_restrict_eq_of_countable_range [SigmaFiniteFiltration μ ℱ] (hτ : IsStoppingTime ℱ τ) (h_countable : (Set.range τ).Countable) [SigmaFinite (μ.trim (hτ.measurableSpace_le_of_countable_range h_countable))] (i : ι) : μ[f|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] μ[f|ℱ i] := by refine condExp_ae_eq_restrict_of_measurableSpace_eq_on (hτ.measurableSpace_le_of_countable_range h_countable) (ℱ.le i) (hτ.measurableSet_eq_of_countable_range' h_countable i) fun t => ?_ rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff] @[deprecated (since := "2025-01-21")] alias condexp_stopping_time_ae_eq_restrict_eq_of_countable_range := condExp_stopping_time_ae_eq_restrict_eq_of_countable_range
theorem condExp_stopping_time_ae_eq_restrict_eq_of_countable [Countable ι] [SigmaFiniteFiltration μ ℱ] (hτ : IsStoppingTime ℱ τ) [SigmaFinite (μ.trim hτ.measurableSpace_le_of_countable)] (i : ι) : μ[f|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] μ[f|ℱ i] := condExp_stopping_time_ae_eq_restrict_eq_of_countable_range hτ (Set.to_countable _) i @[deprecated (since := "2025-01-21")] alias condexp_stopping_time_ae_eq_restrict_eq_of_countable := condExp_stopping_time_ae_eq_restrict_eq_of_countable
Mathlib/Probability/Process/Stopping.lean
1,064
1,073
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Justus Springer -/ import Mathlib.Geometry.RingedSpace.LocallyRingedSpace import Mathlib.AlgebraicGeometry.StructureSheaf import Mathlib.RingTheory.Localization.LocalizationLocalization import Mathlib.Topology.Sheaves.SheafCondition.Sites import Mathlib.Topology.Sheaves.Functors import Mathlib.Algebra.Module.LocalizedModule.Basic /-! # $Spec$ as a functor to locally ringed spaces. We define the functor $Spec$ from commutative rings to locally ringed spaces. ## Implementation notes We define $Spec$ in three consecutive steps, each with more structure than the last: 1. `Spec.toTop`, valued in the category of topological spaces, 2. `Spec.toSheafedSpace`, valued in the category of sheafed spaces and 3. `Spec.toLocallyRingedSpace`, valued in the category of locally ringed spaces. Additionally, we provide `Spec.toPresheafedSpace` as a composition of `Spec.toSheafedSpace` with a forgetful functor. ## Related results The adjunction `Γ ⊣ Spec` is constructed in `Mathlib/AlgebraicGeometry/GammaSpecAdjunction.lean`. -/ -- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737 noncomputable section universe u v namespace AlgebraicGeometry open Opposite open CategoryTheory open StructureSheaf open Spec (structureSheaf) /-- The spectrum of a commutative ring, as a topological space. -/ def Spec.topObj (R : CommRingCat.{u}) : TopCat := TopCat.of (PrimeSpectrum R) @[simp] theorem Spec.topObj_forget {R} : ToType (Spec.topObj R) = PrimeSpectrum R := rfl /-- The induced map of a ring homomorphism on the ring spectra, as a morphism of topological spaces. -/ def Spec.topMap {R S : CommRingCat.{u}} (f : R ⟶ S) : Spec.topObj S ⟶ Spec.topObj R := TopCat.ofHom (PrimeSpectrum.comap f.hom) @[simp] theorem Spec.topMap_id (R : CommRingCat.{u}) : Spec.topMap (𝟙 R) = 𝟙 (Spec.topObj R) := rfl @[simp] theorem Spec.topMap_comp {R S T : CommRingCat.{u}} (f : R ⟶ S) (g : S ⟶ T) : Spec.topMap (f ≫ g) = Spec.topMap g ≫ Spec.topMap f := rfl -- Porting note: `simps!` generate some garbage lemmas, so choose manually, -- if more is needed, add them here /-- The spectrum, as a contravariant functor from commutative rings to topological spaces. -/ @[simps!] def Spec.toTop : CommRingCat.{u}ᵒᵖ ⥤ TopCat where obj R := Spec.topObj (unop R) map {_ _} f := Spec.topMap f.unop /-- The spectrum of a commutative ring, as a `SheafedSpace`. -/ @[simps] def Spec.sheafedSpaceObj (R : CommRingCat.{u}) : SheafedSpace CommRingCat where carrier := Spec.topObj R presheaf := (structureSheaf R).1 IsSheaf := (structureSheaf R).2 /-- The induced map of a ring homomorphism on the ring spectra, as a morphism of sheafed spaces. -/ @[simps base c_app] def Spec.sheafedSpaceMap {R S : CommRingCat.{u}} (f : R ⟶ S) : Spec.sheafedSpaceObj S ⟶ Spec.sheafedSpaceObj R where base := Spec.topMap f c := { app := fun U => CommRingCat.ofHom <| comap f.hom (unop U) ((TopologicalSpace.Opens.map (Spec.topMap f)).obj (unop U)) fun _ => id naturality := fun {_ _} _ => by ext; rfl } @[simp] theorem Spec.sheafedSpaceMap_id {R : CommRingCat.{u}} : Spec.sheafedSpaceMap (𝟙 R) = 𝟙 (Spec.sheafedSpaceObj R) := AlgebraicGeometry.PresheafedSpace.Hom.ext _ _ (Spec.topMap_id R) <| by ext dsimp rw [comap_id (by simp)] simp rfl theorem Spec.sheafedSpaceMap_comp {R S T : CommRingCat.{u}} (f : R ⟶ S) (g : S ⟶ T) : Spec.sheafedSpaceMap (f ≫ g) = Spec.sheafedSpaceMap g ≫ Spec.sheafedSpaceMap f := AlgebraicGeometry.PresheafedSpace.Hom.ext _ _ (Spec.topMap_comp f g) <| by ext -- Porting note: was one liner -- `dsimp, rw category_theory.functor.map_id, rw category.comp_id, erw comap_comp f g, refl` rw [NatTrans.comp_app, sheafedSpaceMap_c_app, whiskerRight_app, eqToHom_refl] erw [(sheafedSpaceObj T).presheaf.map_id] dsimp only [CommRingCat.hom_comp, RingHom.coe_comp, Function.comp_apply] rw [comap_comp] rfl /-- Spec, as a contravariant functor from commutative rings to sheafed spaces. -/ @[simps] def Spec.toSheafedSpace : CommRingCat.{u}ᵒᵖ ⥤ SheafedSpace CommRingCat where obj R := Spec.sheafedSpaceObj (unop R)
map f := Spec.sheafedSpaceMap f.unop map_comp f g := by simp [Spec.sheafedSpaceMap_comp] /-- Spec, as a contravariant functor from commutative rings to presheafed spaces. -/ def Spec.toPresheafedSpace : CommRingCat.{u}ᵒᵖ ⥤ PresheafedSpace CommRingCat := Spec.toSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace @[simp]
Mathlib/AlgebraicGeometry/Spec.lean
129
137
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Analytic.Within import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Calculus.ContDiff.FTaylorSeries /-! # Higher differentiability A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous. By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or, equivalently, if it is `C^1` and its derivative is `C^{n-1}`. It is `C^∞` if it is `C^n` for all n. Finally, it is `C^ω` if it is analytic (as well as all its derivative, which is automatic if the space is complete). We formalize these notions with predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and `ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set and on the whole space respectively. To avoid the issue of choice when choosing a derivative in sets where the derivative is not necessarily unique, `ContDiffOn` is not defined directly in terms of the regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the existence of a nice sequence of derivatives, expressed with a predicate `HasFTaylorSeriesUpToOn` defined in the file `FTaylorSeries`. We prove basic properties of these notions. ## Main definitions and results Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`. * `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to rank `n`. * `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`. * `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`. * `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`. In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≤ n`. In the whole space, `ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f` for `m ≤ n`. ## Implementation notes The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more complicated than the naive definitions one would guess from the intuition over the real or complex numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity in general. In the usual situations, they coincide with the usual definitions. ### Definition of `C^n` functions in domains One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n` functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`. This definition still has the problem that a function which is locally `C^n` would not need to be `C^n`, as different choices of sequences of derivatives around different points might possibly not be glued together to give a globally defined sequence of derivatives. (Note that this issue can not happen over reals, thanks to partition of unity, but the behavior over a general field is not so clear, and we want a definition for general fields). Also, there are locality problems for the order parameter: one could image a function which, for each `n`, has a nice sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore not be glued to give rise to an infinite sequence of derivatives. This would give a function which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`. The resulting definition is slightly more complicated to work with (in fact not so much), but it gives rise to completely satisfactory theorems. For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)` for each natural `m` is by definition `C^∞` at `0`. There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x` within `s`. However, this does not imply continuity or differentiability within `s` of the function at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file). ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `(⊤ : ℕ∞) : WithTop ℕ∞` with `∞`, and `⊤ : WithTop ℕ∞` with `ω`. To avoid ambiguities with the two tops, the theorems name use either `infty` or `omega`. These notations are scoped in `ContDiff`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable section open Set Fin Filter Function open scoped NNReal Topology ContDiff universe u uE uF uG uX variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : WithTop ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Smooth functions within a set around a point -/ variable (𝕜) in /-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s ∪ {x}`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). For `n = ω`, we require the function to be analytic within `s` at `x`. The precise definition we give (all the derivatives should be analytic) is more involved to work around issues when the space is not complete, but it is equivalent when the space is complete. For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not better, is `C^∞` at `0` within `univ`. -/ def ContDiffWithinAt (n : WithTop ℕ∞) (f : E → F) (s : Set E) (x : E) : Prop := match n with | ω => ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn ω f p u ∧ ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u | (n : ℕ∞) => ∀ m : ℕ, m ≤ n → ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn m f p u lemma HasFTaylorSeriesUpToOn.analyticOn (hf : HasFTaylorSeriesUpToOn ω f p s) (h : AnalyticOn 𝕜 (fun x ↦ p x 0) s) : AnalyticOn 𝕜 f s := by have : AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryFin0 𝕜 E F) (p x 0)) s := (LinearIsometryEquiv.analyticOnNhd _ _ ).comp_analyticOn h (Set.mapsTo_univ _ _) exact this.congr (fun y hy ↦ (hf.zero_eq _ hy).symm) lemma ContDiffWithinAt.analyticOn (h : ContDiffWithinAt 𝕜 ω f s x) : ∃ u ∈ 𝓝[insert x s] x, AnalyticOn 𝕜 f u := by obtain ⟨u, hu, p, hp, h'p⟩ := h exact ⟨u, hu, hp.analyticOn (h'p 0)⟩ lemma ContDiffWithinAt.analyticWithinAt (h : ContDiffWithinAt 𝕜 ω f s x) : AnalyticWithinAt 𝕜 f s x := by obtain ⟨u, hu, hf⟩ := h.analyticOn have xu : x ∈ u := mem_of_mem_nhdsWithin (by simp) hu exact (hf x xu).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu) theorem contDiffWithinAt_omega_iff_analyticWithinAt [CompleteSpace F] : ContDiffWithinAt 𝕜 ω f s x ↔ AnalyticWithinAt 𝕜 f s x := by refine ⟨fun h ↦ h.analyticWithinAt, fun h ↦ ?_⟩ obtain ⟨u, hu, p, hp, h'p⟩ := h.exists_hasFTaylorSeriesUpToOn ω exact ⟨u, hu, p, hp.of_le le_top, fun i ↦ h'p i⟩ theorem contDiffWithinAt_nat {n : ℕ} : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u := ⟨fun H => H n le_rfl, fun ⟨u, hu, p, hp⟩ _m hm => ⟨u, hu, p, hp.of_le (mod_cast hm)⟩⟩ /-- When `n` is either a natural number or `ω`, one can characterize the property of being `C^n` as the existence of a neighborhood on which there is a Taylor series up to order `n`, requiring in addition that its terms are analytic in the `ω` case. -/ lemma contDiffWithinAt_iff_of_ne_infty (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u ∧ (n = ω → ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u) := by match n with | ω => simp [ContDiffWithinAt] | ∞ => simp at hn | (n : ℕ) => simp [contDiffWithinAt_nat] theorem ContDiffWithinAt.of_le (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m ≤ n) : ContDiffWithinAt 𝕜 m f s x := by match n with | ω => match m with | ω => exact h | (m : ℕ∞) => intro k _ obtain ⟨u, hu, p, hp, -⟩ := h exact ⟨u, hu, p, hp.of_le le_top⟩ | (n : ℕ∞) => match m with | ω => simp at hmn | (m : ℕ∞) => exact fun k hk ↦ h k (le_trans hk (mod_cast hmn)) /-- In a complete space, a function which is analytic within a set at a point is also `C^ω` there. Note that the same statement for `AnalyticOn` does not require completeness, see `AnalyticOn.contDiffOn`. -/ theorem AnalyticWithinAt.contDiffWithinAt [CompleteSpace F] (h : AnalyticWithinAt 𝕜 f s x) : ContDiffWithinAt 𝕜 n f s x := (contDiffWithinAt_omega_iff_analyticWithinAt.2 h).of_le le_top theorem contDiffWithinAt_iff_forall_nat_le {n : ℕ∞} : ContDiffWithinAt 𝕜 n f s x ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffWithinAt 𝕜 m f s x := ⟨fun H _ hm => H.of_le (mod_cast hm), fun H m hm => H m hm _ le_rfl⟩ theorem contDiffWithinAt_infty : ContDiffWithinAt 𝕜 ∞ f s x ↔ ∀ n : ℕ, ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_iff_forall_nat_le.trans <| by simp only [forall_prop_of_true, le_top] @[deprecated (since := "2024-11-25")] alias contDiffWithinAt_top := contDiffWithinAt_infty theorem ContDiffWithinAt.continuousWithinAt (h : ContDiffWithinAt 𝕜 n f s x) : ContinuousWithinAt f s x := by have := h.of_le (zero_le _) simp only [ContDiffWithinAt, nonpos_iff_eq_zero, Nat.cast_eq_zero, mem_pure, forall_eq, CharP.cast_eq_zero] at this rcases this with ⟨u, hu, p, H⟩ rw [mem_nhdsWithin_insert] at hu exact (H.continuousOn.continuousWithinAt hu.1).mono_of_mem_nhdsWithin hu.2 theorem ContDiffWithinAt.congr_of_eventuallyEq (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := by match n with | ω => obtain ⟨u, hu, p, H, H'⟩ := h exact ⟨{x ∈ u | f₁ x = f x}, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p, (H.mono (sep_subset _ _)).congr fun _ ↦ And.right, fun i ↦ (H' i).mono (sep_subset _ _)⟩ | (n : ℕ∞) => intro m hm let ⟨u, hu, p, H⟩ := h m hm exact ⟨{ x ∈ u | f₁ x = f x }, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p, (H.mono (sep_subset _ _)).congr fun _ ↦ And.right⟩ theorem Filter.EventuallyEq.congr_contDiffWithinAt (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq h₁.symm hx.symm, fun H ↦ H.congr_of_eventuallyEq h₁ hx⟩ theorem ContDiffWithinAt.congr_of_eventuallyEq_insert (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (nhdsWithin_mono x (subset_insert x s) h₁) (mem_of_mem_nhdsWithin (mem_insert x s) h₁ :) theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_insert (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq_insert h₁.symm, fun H ↦ H.congr_of_eventuallyEq_insert h₁⟩ theorem ContDiffWithinAt.congr_of_eventuallyEq_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq h₁ <| h₁.self_of_nhdsWithin hx theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_mem (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s): ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq_of_mem h₁.symm hx, fun H ↦ H.congr_of_eventuallyEq_of_mem h₁ hx⟩ theorem ContDiffWithinAt.congr (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (Filter.eventuallyEq_of_mem self_mem_nhdsWithin h₁) hx theorem contDiffWithinAt_congr (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun h' ↦ h'.congr (fun x hx ↦ (h₁ x hx).symm) hx.symm, fun h' ↦ h'.congr h₁ hx⟩ theorem ContDiffWithinAt.congr_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr h₁ (h₁ _ hx) theorem contDiffWithinAt_congr_of_mem (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr h₁ (h₁ x hx) theorem ContDiffWithinAt.congr_of_insert (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem contDiffWithinAt_congr_of_insert (h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem ContDiffWithinAt.mono_of_mem_nhdsWithin (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := by match n with | ω => obtain ⟨u, hu, p, H, H'⟩ := h exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H, H'⟩ | (n : ℕ∞) => intro m hm rcases h m hm with ⟨u, hu, p, H⟩ exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H⟩ @[deprecated (since := "2024-10-30")] alias ContDiffWithinAt.mono_of_mem := ContDiffWithinAt.mono_of_mem_nhdsWithin theorem ContDiffWithinAt.mono (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : t ⊆ s) : ContDiffWithinAt 𝕜 n f t x := h.mono_of_mem_nhdsWithin <| Filter.mem_of_superset self_mem_nhdsWithin hst theorem ContDiffWithinAt.congr_mono (h : ContDiffWithinAt 𝕜 n f s x) (h' : EqOn f₁ f s₁) (h₁ : s₁ ⊆ s) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s₁ x := (h.mono h₁).congr h' hx theorem ContDiffWithinAt.congr_set (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f t x := by rw [← nhdsWithin_eq_iff_eventuallyEq] at hst apply h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin @[deprecated (since := "2024-10-23")] alias ContDiffWithinAt.congr_nhds := ContDiffWithinAt.congr_set theorem contDiffWithinAt_congr_set {t : Set E} (hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f s x ↔ ContDiffWithinAt 𝕜 n f t x := ⟨fun h => h.congr_set hst, fun h => h.congr_set hst.symm⟩ @[deprecated (since := "2024-10-23")] alias contDiffWithinAt_congr_nhds := contDiffWithinAt_congr_set theorem contDiffWithinAt_inter' (h : t ∈ 𝓝[s] x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr_set (mem_nhdsWithin_iff_eventuallyEq.1 h).symm theorem contDiffWithinAt_inter (h : t ∈ 𝓝 x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds h) theorem contDiffWithinAt_insert_self : ContDiffWithinAt 𝕜 n f (insert x s) x ↔ ContDiffWithinAt 𝕜 n f s x := by match n with | ω => simp [ContDiffWithinAt] | (n : ℕ∞) => simp_rw [ContDiffWithinAt, insert_idem] theorem contDiffWithinAt_insert {y : E} : ContDiffWithinAt 𝕜 n f (insert y s) x ↔ ContDiffWithinAt 𝕜 n f s x := by rcases eq_or_ne x y with (rfl | hx) · exact contDiffWithinAt_insert_self refine ⟨fun h ↦ h.mono (subset_insert _ _), fun h ↦ ?_⟩ apply h.mono_of_mem_nhdsWithin simp [nhdsWithin_insert_of_ne hx, self_mem_nhdsWithin] alias ⟨ContDiffWithinAt.of_insert, ContDiffWithinAt.insert'⟩ := contDiffWithinAt_insert protected theorem ContDiffWithinAt.insert (h : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n f (insert x s) x := h.insert' theorem contDiffWithinAt_diff_singleton {y : E} : ContDiffWithinAt 𝕜 n f (s \ {y}) x ↔ ContDiffWithinAt 𝕜 n f s x := by rw [← contDiffWithinAt_insert, insert_diff_singleton, contDiffWithinAt_insert] /-- If a function is `C^n` within a set at a point, with `n ≥ 1`, then it is differentiable within this set at this point. -/ theorem ContDiffWithinAt.differentiableWithinAt' (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f (insert x s) x := by rcases contDiffWithinAt_nat.1 (h.of_le hn) with ⟨u, hu, p, H⟩ rcases mem_nhdsWithin.1 hu with ⟨t, t_open, xt, tu⟩ rw [inter_comm] at tu exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 <| ((H.mono tu).differentiableOn le_rfl) x ⟨mem_insert x s, xt⟩ theorem ContDiffWithinAt.differentiableWithinAt (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f s x := (h.differentiableWithinAt' hn).mono (subset_insert x s) /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n` (and moreover the function is analytic when `n = ω`). -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffWithinAt 𝕜 n f' u x := by have h'n : n + 1 ≠ ∞ := by simpa using hn constructor · intro h rcases (contDiffWithinAt_iff_of_ne_infty h'n).1 h with ⟨u, hu, p, Hp, H'p⟩ refine ⟨u, hu, ?_, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1), fun y hy => Hp.hasFDerivWithinAt le_add_self hy, ?_⟩ · rintro rfl exact Hp.analyticOn (H'p rfl 0) apply (contDiffWithinAt_iff_of_ne_infty hn).2 refine ⟨u, ?_, fun y : E => (p y).shift, ?_⟩ · convert @self_mem_nhdsWithin _ _ x u have : x ∈ insert x s := by simp exact insert_eq_of_mem (mem_of_mem_nhdsWithin this hu) · rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp refine ⟨Hp.2.2, ?_⟩ rintro rfl i change AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryRightEquiv' 𝕜 i E F) (p x (i + 1))) u apply (LinearIsometryEquiv.analyticOnNhd _ _).comp_analyticOn ?_ (Set.mapsTo_univ _ _) exact H'p rfl _ · rintro ⟨u, hu, hf, f', f'_eq_deriv, Hf'⟩ rw [contDiffWithinAt_iff_of_ne_infty h'n] rcases (contDiffWithinAt_iff_of_ne_infty hn).1 Hf' with ⟨v, hv, p', Hp', p'_an⟩ refine ⟨v ∩ u, ?_, fun x => (p' x).unshift (f x), ?_, ?_⟩ · apply Filter.inter_mem _ hu apply nhdsWithin_le_of_mem hu exact nhdsWithin_mono _ (subset_insert x u) hv · rw [hasFTaylorSeriesUpToOn_succ_iff_right] refine ⟨fun y _ => rfl, fun y hy => ?_, ?_⟩ · change HasFDerivWithinAt (fun z => (continuousMultilinearCurryFin0 𝕜 E F).symm (f z)) (FormalMultilinearSeries.unshift (p' y) (f y) 1).curryLeft (v ∩ u) y rw [← Function.comp_def _ f, LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] convert (f'_eq_deriv y hy.2).mono inter_subset_right rw [← Hp'.zero_eq y hy.1] ext z change ((p' y 0) (init (@cons 0 (fun _ => E) z 0))) (@cons 0 (fun _ => E) z 0 (last 0)) = ((p' y 0) 0) z congr norm_num [eq_iff_true_of_subsingleton] · convert (Hp'.mono inter_subset_left).congr fun x hx => Hp'.zero_eq x hx.1 using 1 · ext x y change p' x 0 (init (@snoc 0 (fun _ : Fin 1 => E) 0 y)) y = p' x 0 0 y rw [init_snoc] · ext x k v y change p' x k (init (@snoc k (fun _ : Fin k.succ => E) v y)) (@snoc k (fun _ : Fin k.succ => E) v y (last k)) = p' x k v y rw [snoc_last, init_snoc] · intro h i simp only [WithTop.add_eq_top, WithTop.one_ne_top, or_false] at h match i with | 0 => simp only [FormalMultilinearSeries.unshift] apply AnalyticOnNhd.comp_analyticOn _ ((hf h).mono inter_subset_right) (Set.mapsTo_univ _ _) exact LinearIsometryEquiv.analyticOnNhd _ _ | i + 1 => simp only [FormalMultilinearSeries.unshift, Nat.succ_eq_add_one] apply AnalyticOnNhd.comp_analyticOn _ ((p'_an h i).mono inter_subset_left) (Set.mapsTo_univ _ _) exact LinearIsometryEquiv.analyticOnNhd _ _ /-- A version of `contDiffWithinAt_succ_iff_hasFDerivWithinAt` where all derivatives are taken within the same set. -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt' (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) s x) ∧ ContDiffWithinAt 𝕜 n f' s x := by refine ⟨fun hf => ?_, ?_⟩ · obtain ⟨u, hu, f_an, f', huf', hf'⟩ := (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).mp hf obtain ⟨w, hw, hxw, hwu⟩ := mem_nhdsWithin.mp hu rw [inter_comm] at hwu refine ⟨insert x s ∩ w, inter_mem_nhdsWithin _ (hw.mem_nhds hxw), inter_subset_left, ?_, f', fun y hy => ?_, ?_⟩ · intro h apply (f_an h).mono hwu · refine ((huf' y <| hwu hy).mono hwu).mono_of_mem_nhdsWithin ?_ refine mem_of_superset ?_ (inter_subset_inter_left _ (subset_insert _ _)) exact inter_mem_nhdsWithin _ (hw.mem_nhds hy.2) · exact hf'.mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu) · rw [← contDiffWithinAt_insert, contDiffWithinAt_succ_iff_hasFDerivWithinAt hn, insert_eq_of_mem (mem_insert _ _)] rintro ⟨u, hu, hus, f_an, f', huf', hf'⟩ exact ⟨u, hu, f_an, f', fun y hy => (huf' y hy).insert'.mono hus, hf'.insert.mono hus⟩ /-! ### Smooth functions within a set -/ variable (𝕜) in /-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). -/ def ContDiffOn (n : WithTop ℕ∞) (f : E → F) (s : Set E) : Prop := ∀ x ∈ s, ContDiffWithinAt 𝕜 n f s x theorem HasFTaylorSeriesUpToOn.contDiffOn {n : ℕ∞} {f' : E → FormalMultilinearSeries 𝕜 E F} (hf : HasFTaylorSeriesUpToOn n f f' s) : ContDiffOn 𝕜 n f s := by intro x hx m hm use s simp only [Set.insert_eq_of_mem hx, self_mem_nhdsWithin, true_and] exact ⟨f', hf.of_le (mod_cast hm)⟩ theorem ContDiffOn.contDiffWithinAt (h : ContDiffOn 𝕜 n f s) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f s x := h x hx theorem ContDiffOn.of_le (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) : ContDiffOn 𝕜 m f s := fun x hx => (h x hx).of_le hmn theorem ContDiffWithinAt.contDiffOn' (hm : m ≤ n) (h' : m = ∞ → n = ω) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 m f (insert x s ∩ u) := by rcases eq_or_ne n ω with rfl | hn · obtain ⟨t, ht, p, hp, h'p⟩ := h rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩ rw [inter_comm] at hut refine ⟨u, huo, hxu, ?_⟩ suffices ContDiffOn 𝕜 ω f (insert x s ∩ u) from this.of_le le_top intro y hy refine ⟨insert x s ∩ u, ?_, p, hp.mono hut, fun i ↦ (h'p i).mono hut⟩ simp only [insert_eq_of_mem, hy, self_mem_nhdsWithin] · match m with | ω => simp [hn] at hm | ∞ => exact (hn (h' rfl)).elim | (m : ℕ) => rcases contDiffWithinAt_nat.1 (h.of_le hm) with ⟨t, ht, p, hp⟩ rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩ rw [inter_comm] at hut exact ⟨u, huo, hxu, (hp.mono hut).contDiffOn⟩ theorem ContDiffWithinAt.contDiffOn (hm : m ≤ n) (h' : m = ∞ → n = ω) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ContDiffOn 𝕜 m f u := by obtain ⟨_u, uo, xu, h⟩ := h.contDiffOn' hm h' exact ⟨_, inter_mem_nhdsWithin _ (uo.mem_nhds xu), inter_subset_left, h⟩ theorem ContDiffOn.analyticOn (h : ContDiffOn 𝕜 ω f s) : AnalyticOn 𝕜 f s := fun x hx ↦ (h x hx).analyticWithinAt /-- A function is `C^n` within a set at a point, for `n : ℕ`, if and only if it is `C^n` on a neighborhood of this point. -/ theorem contDiffWithinAt_iff_contDiffOn_nhds (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ContDiffOn 𝕜 n f u := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, h'u⟩ exact ⟨u, hu, h'u.2⟩ · rcases h with ⟨u, u_mem, hu⟩ have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert x s) u_mem exact (hu x this).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert x s) u_mem) protected theorem ContDiffWithinAt.eventually (h : ContDiffWithinAt 𝕜 n f s x) (hn : n ≠ ∞) : ∀ᶠ y in 𝓝[insert x s] x, ContDiffWithinAt 𝕜 n f s y := by rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, _, hd⟩ have : ∀ᶠ y : E in 𝓝[insert x s] x, u ∈ 𝓝[insert x s] y ∧ y ∈ u := (eventually_eventually_nhdsWithin.2 hu).and hu refine this.mono fun y hy => (hd y hy.2).mono_of_mem_nhdsWithin ?_ exact nhdsWithin_mono y (subset_insert _ _) hy.1 theorem ContDiffOn.of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 n f s := h.of_le le_self_add theorem ContDiffOn.one_of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 1 f s := h.of_le le_add_self theorem contDiffOn_iff_forall_nat_le {n : ℕ∞} : ContDiffOn 𝕜 n f s ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffOn 𝕜 m f s := ⟨fun H _ hm => H.of_le (mod_cast hm), fun H x hx m hm => H m hm x hx m le_rfl⟩ theorem contDiffOn_infty : ContDiffOn 𝕜 ∞ f s ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := contDiffOn_iff_forall_nat_le.trans <| by simp only [le_top, forall_prop_of_true] @[deprecated (since := "2024-11-27")] alias contDiffOn_top := contDiffOn_infty @[deprecated (since := "2024-11-27")] alias contDiffOn_infty_iff_contDiffOn_omega := contDiffOn_infty theorem contDiffOn_all_iff_nat : (∀ (n : ℕ∞), ContDiffOn 𝕜 n f s) ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := by refine ⟨fun H n => H n, ?_⟩ rintro H (_ | n) exacts [contDiffOn_infty.2 H, H n] theorem ContDiffOn.continuousOn (h : ContDiffOn 𝕜 n f s) : ContinuousOn f s := fun x hx => (h x hx).continuousWithinAt theorem ContDiffOn.congr (h : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s := fun x hx => (h x hx).congr h₁ (h₁ x hx) theorem contDiffOn_congr (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s ↔ ContDiffOn 𝕜 n f s := ⟨fun H => H.congr fun x hx => (h₁ x hx).symm, fun H => H.congr h₁⟩ theorem ContDiffOn.mono (h : ContDiffOn 𝕜 n f s) {t : Set E} (hst : t ⊆ s) : ContDiffOn 𝕜 n f t := fun x hx => (h x (hst hx)).mono hst theorem ContDiffOn.congr_mono (hf : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s₁, f₁ x = f x) (hs : s₁ ⊆ s) : ContDiffOn 𝕜 n f₁ s₁ := (hf.mono hs).congr h₁ /-- If a function is `C^n` on a set with `n ≥ 1`, then it is differentiable there. -/ theorem ContDiffOn.differentiableOn (h : ContDiffOn 𝕜 n f s) (hn : 1 ≤ n) : DifferentiableOn 𝕜 f s := fun x hx => (h x hx).differentiableWithinAt hn /-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/ theorem contDiffOn_of_locally_contDiffOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 n f (s ∩ u)) : ContDiffOn 𝕜 n f s := by intro x xs rcases h x xs with ⟨u, u_open, xu, hu⟩ apply (contDiffWithinAt_inter _).1 (hu x ⟨xs, xu⟩) exact IsOpen.mem_nhds u_open xu /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/ theorem contDiffOn_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) : ContDiffOn 𝕜 (n + 1) f s ↔ ∀ x ∈ s, ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffOn 𝕜 n f' u := by constructor · intro h x hx rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).1 (h x hx) with ⟨u, hu, f_an, f', hf', Hf'⟩ rcases Hf'.contDiffOn le_rfl (by simp [hn]) with ⟨v, vu, v'u, hv⟩ rw [insert_eq_of_mem hx] at hu ⊢ have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu rw [insert_eq_of_mem xu] at vu v'u exact ⟨v, nhdsWithin_le_of_mem hu vu, fun h ↦ (f_an h).mono v'u, f', fun y hy ↦ (hf' y (v'u hy)).mono v'u, hv⟩ · intro h x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn] rcases h x hx with ⟨u, u_nhbd, f_an, f', hu, hf'⟩ have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert _ _) u_nhbd exact ⟨u, u_nhbd, f_an, f', hu, hf' x this⟩ /-! ### Iterated derivative within a set -/ @[simp] theorem contDiffOn_zero : ContDiffOn 𝕜 0 f s ↔ ContinuousOn f s := by refine ⟨fun H => H.continuousOn, fun H => fun x hx m hm ↦ ?_⟩ have : (m : WithTop ℕ∞) = 0 := le_antisymm (mod_cast hm) bot_le rw [this] refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ rw [hasFTaylorSeriesUpToOn_zero_iff] exact ⟨by rwa [insert_eq_of_mem hx], fun x _ => by simp [ftaylorSeriesWithin]⟩ theorem contDiffWithinAt_zero (hx : x ∈ s) : ContDiffWithinAt 𝕜 0 f s x ↔ ∃ u ∈ 𝓝[s] x, ContinuousOn f (s ∩ u) := by constructor · intro h obtain ⟨u, H, p, hp⟩ := h 0 le_rfl refine ⟨u, ?_, ?_⟩ · simpa [hx] using H · simp only [Nat.cast_zero, hasFTaylorSeriesUpToOn_zero_iff] at hp exact hp.1.mono inter_subset_right · rintro ⟨u, H, hu⟩ rw [← contDiffWithinAt_inter' H] have h' : x ∈ s ∩ u := ⟨hx, mem_of_mem_nhdsWithin hx H⟩ exact (contDiffOn_zero.mpr hu).contDiffWithinAt h' /-- When a function is `C^n` in a set `s` of unique differentiability, it admits `ftaylorSeriesWithin 𝕜 f s` as a Taylor series up to order `n` in `s`. -/ protected theorem ContDiffOn.ftaylorSeriesWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) : HasFTaylorSeriesUpToOn n f (ftaylorSeriesWithin 𝕜 f s) s := by constructor · intro x _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply, iteratedFDerivWithin_zero_apply] · intro m hm x hx have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hm rcases (h x hx).of_le this _ le_rfl with ⟨u, hu, p, Hp⟩ rw [insert_eq_of_mem hx] at hu rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [inter_comm] at ho have : p x m.succ = ftaylorSeriesWithin 𝕜 f s x m.succ := by change p x m.succ = iteratedFDerivWithin 𝕜 m.succ f s x rw [← iteratedFDerivWithin_inter_open o_open xo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hx, xo⟩ rw [← this, ← hasFDerivWithinAt_inter (IsOpen.mem_nhds o_open xo)] have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟨hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn (mod_cast Nat.le_succ m) (hs.inter o_open) ⟨hy, yo⟩ exact ((Hp.mono ho).fderivWithin m (mod_cast lt_add_one m) x ⟨hx, xo⟩).congr (fun y hy => (A y hy).symm) (A x ⟨hx, xo⟩).symm · intro m hm apply continuousOn_of_locally_continuousOn intro x hx rcases (h x hx).of_le hm _ le_rfl with ⟨u, hu, p, Hp⟩ rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [insert_eq_of_mem hx] at ho rw [inter_comm] at ho refine ⟨o, o_open, xo, ?_⟩ have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟨hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hy, yo⟩ exact ((Hp.mono ho).cont m le_rfl).congr fun y hy => (A y hy).symm theorem iteratedFDerivWithin_subset {n : ℕ} (st : s ⊆ t) (hs : UniqueDiffOn 𝕜 s) (ht : UniqueDiffOn 𝕜 t) (h : ContDiffOn 𝕜 n f t) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 n f s x = iteratedFDerivWithin 𝕜 n f t x := (((h.ftaylorSeriesWithin ht).mono st).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl hs hx).symm theorem ContDiffWithinAt.eventually_hasFTaylorSeriesUpToOn {f : E → F} {s : Set E} {a : E} (h : ContDiffWithinAt 𝕜 n f s a) (hs : UniqueDiffOn 𝕜 s) (ha : a ∈ s) {m : ℕ} (hm : m ≤ n) : ∀ᶠ t in (𝓝[s] a).smallSets, HasFTaylorSeriesUpToOn m f (ftaylorSeriesWithin 𝕜 f s) t := by rcases h.contDiffOn' hm (by simp) with ⟨U, hUo, haU, hfU⟩ have : ∀ᶠ t in (𝓝[s] a).smallSets, t ⊆ s ∩ U := by rw [eventually_smallSets_subset] exact inter_mem_nhdsWithin _ <| hUo.mem_nhds haU refine this.mono fun t ht ↦ .mono ?_ ht rw [insert_eq_of_mem ha] at hfU refine (hfU.ftaylorSeriesWithin (hs.inter hUo)).congr_series fun k hk x hx ↦ ?_ exact iteratedFDerivWithin_inter_open hUo hx.2 /-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its successive derivatives are also analytic. This does not require completeness of the space. See also `AnalyticOn.contDiffOn_of_completeSpace`. -/ theorem AnalyticOn.contDiffOn (h : AnalyticOn 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s := by suffices ContDiffOn 𝕜 ω f s from this.of_le le_top rcases h.exists_hasFTaylorSeriesUpToOn hs with ⟨p, hp⟩ intro x hx refine ⟨s, ?_, p, hp⟩ rw [insert_eq_of_mem hx] exact self_mem_nhdsWithin /-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its successive derivatives are also analytic. This does not require completeness of the space. See also `AnalyticOnNhd.contDiffOn_of_completeSpace`. -/ theorem AnalyticOnNhd.contDiffOn (h : AnalyticOnNhd 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s := h.analyticOn.contDiffOn hs /-- An analytic function is automatically `C^ω` in a complete space -/ theorem AnalyticOn.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOn 𝕜 f s) : ContDiffOn 𝕜 n f s := fun x hx ↦ (h x hx).contDiffWithinAt /-- An analytic function is automatically `C^ω` in a complete space -/ theorem AnalyticOnNhd.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOnNhd 𝕜 f s) : ContDiffOn 𝕜 n f s := h.analyticOn.contDiffOn_of_completeSpace theorem contDiffOn_of_continuousOn_differentiableOn {n : ℕ∞} (Hcont : ∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) (Hdiff : ∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s) : ContDiffOn 𝕜 n f s := by intro x hx m hm rw [insert_eq_of_mem hx] refine ⟨s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ constructor · intro y _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply, iteratedFDerivWithin_zero_apply] · intro k hk y hy convert (Hdiff k (lt_of_lt_of_le (mod_cast hk) (mod_cast hm)) y hy).hasFDerivWithinAt · intro k hk exact Hcont k (le_trans (mod_cast hk) (mod_cast hm)) theorem contDiffOn_of_differentiableOn {n : ℕ∞} (h : ∀ m : ℕ, m ≤ n → DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) : ContDiffOn 𝕜 n f s := contDiffOn_of_continuousOn_differentiableOn (fun m hm => (h m hm).continuousOn) fun m hm => h m (le_of_lt hm) theorem contDiffOn_of_analyticOn_iteratedFDerivWithin (h : ∀ m, AnalyticOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) : ContDiffOn 𝕜 n f s := by suffices ContDiffOn 𝕜 ω f s from this.of_le le_top intro x hx refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_, ?_⟩ · rw [insert_eq_of_mem hx] constructor · intro y _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply, iteratedFDerivWithin_zero_apply] · intro k _ y hy exact ((h k).differentiableOn y hy).hasFDerivWithinAt · intro k _ exact (h k).continuousOn · intro i rw [insert_eq_of_mem hx] exact h i theorem contDiffOn_omega_iff_analyticOn (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 ω f s ↔ AnalyticOn 𝕜 f s := ⟨fun h m ↦ h.analyticOn m, fun h ↦ h.contDiffOn hs⟩ theorem ContDiffOn.continuousOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) (hs : UniqueDiffOn 𝕜 s) : ContinuousOn (iteratedFDerivWithin 𝕜 m f s) s := ((h.of_le hmn).ftaylorSeriesWithin hs).cont m le_rfl theorem ContDiffOn.differentiableOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : m < n) (hs : UniqueDiffOn 𝕜 s) : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s := by intro x hx have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hmn apply (((h.of_le this).ftaylorSeriesWithin hs).fderivWithin m ?_ x hx).differentiableWithinAt exact_mod_cast lt_add_one m theorem ContDiffWithinAt.differentiableWithinAt_iteratedFDerivWithin {m : ℕ} (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m < n) (hs : UniqueDiffOn 𝕜 (insert x s)) : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f s) s x := by have : (m + 1 : WithTop ℕ∞) ≠ ∞ := Ne.symm (ne_of_beq_false rfl) rcases h.contDiffOn' (ENat.add_one_natCast_le_withTop_of_lt hmn) (by simp [this]) with ⟨u, uo, xu, hu⟩ set t := insert x s ∩ u have A : t =ᶠ[𝓝[≠] x] s := by simp only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter'] rw [← inter_assoc, nhdsWithin_inter_of_mem', ← diff_eq_compl_inter, insert_diff_of_mem, diff_eq_compl_inter] exacts [rfl, mem_nhdsWithin_of_mem_nhds (uo.mem_nhds xu)] have B : iteratedFDerivWithin 𝕜 m f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 m f t := iteratedFDerivWithin_eventually_congr_set' _ A.symm _ have C : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f t) t x := hu.differentiableOn_iteratedFDerivWithin (Nat.cast_lt.2 m.lt_succ_self) (hs.inter uo) x ⟨mem_insert _ _, xu⟩ rw [differentiableWithinAt_congr_set' _ A] at C exact C.congr_of_eventuallyEq (B.filter_mono inf_le_left) B.self_of_nhds theorem contDiffOn_iff_continuousOn_differentiableOn {n : ℕ∞} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s ↔ (∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧ ∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := ⟨fun h => ⟨fun _m hm => h.continuousOn_iteratedFDerivWithin (mod_cast hm) hs, fun _m hm => h.differentiableOn_iteratedFDerivWithin (mod_cast hm) hs⟩, fun h => contDiffOn_of_continuousOn_differentiableOn h.1 h.2⟩ theorem contDiffOn_nat_iff_continuousOn_differentiableOn {n : ℕ} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s ↔ (∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧ ∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := by rw [← WithTop.coe_natCast, contDiffOn_iff_continuousOn_differentiableOn hs] simp theorem contDiffOn_succ_of_fderivWithin (hf : DifferentiableOn 𝕜 f s) (h' : n = ω → AnalyticOn 𝕜 f s) (h : ContDiffOn 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 (n + 1) f s := by rcases eq_or_ne n ∞ with rfl | hn · rw [ENat.coe_top_add_one, contDiffOn_infty] intro m x hx apply ContDiffWithinAt.of_le _ (show (m : WithTop ℕ∞) ≤ m + 1 from le_self_add) rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt (by simp), insert_eq_of_mem hx] exact ⟨s, self_mem_nhdsWithin, (by simp), fderivWithin 𝕜 f s, fun y hy => (hf y hy).hasFDerivWithinAt, (h x hx).of_le (mod_cast le_top)⟩ · intro x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn, insert_eq_of_mem hx] exact ⟨s, self_mem_nhdsWithin, h', fderivWithin 𝕜 f s, fun y hy => (hf y hy).hasFDerivWithinAt, h x hx⟩ theorem contDiffOn_of_analyticOn_of_fderivWithin (hf : AnalyticOn 𝕜 f s) (h : ContDiffOn 𝕜 ω (fun y ↦ fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 n f s := by suffices ContDiffOn 𝕜 (ω + 1) f s from this.of_le le_top exact contDiffOn_succ_of_fderivWithin hf.differentiableOn (fun _ ↦ hf) h /-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (expressed with `fderivWithin`) is `C^n`. -/ theorem contDiffOn_succ_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1) f s ↔ DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧ ContDiffOn 𝕜 n (fderivWithin 𝕜 f s) s := by refine ⟨fun H => ?_, fun h => contDiffOn_succ_of_fderivWithin h.1 h.2.1 h.2.2⟩ refine ⟨H.differentiableOn le_add_self, ?_, fun x hx => ?_⟩ · rintro rfl exact H.analyticOn have A (m : ℕ) (hm : m ≤ n) : ContDiffWithinAt 𝕜 m (fun y => fderivWithin 𝕜 f s y) s x := by rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt (n := m) (ne_of_beq_false rfl)).1 (H.of_le (add_le_add_right hm 1) x hx) with ⟨u, hu, -, f', hff', hf'⟩ rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [inter_comm, insert_eq_of_mem hx] at ho have := hf'.mono ho rw [contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds o_open xo))] at this apply this.congr_of_eventuallyEq_of_mem _ hx have : o ∩ s ∈ 𝓝[s] x := mem_nhdsWithin.2 ⟨o, o_open, xo, Subset.refl _⟩ rw [inter_comm] at this refine Filter.eventuallyEq_of_mem this fun y hy => ?_ have A : fderivWithin 𝕜 f (s ∩ o) y = f' y := ((hff' y (ho hy)).mono ho).fderivWithin (hs.inter o_open y hy) rwa [fderivWithin_inter (o_open.mem_nhds hy.2)] at A match n with | ω => exact (H.analyticOn.fderivWithin hs).contDiffOn hs (n := ω) x hx | ∞ => exact contDiffWithinAt_infty.2 (fun m ↦ A m (mod_cast le_top)) | (n : ℕ) => exact A n le_rfl theorem contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1) f s ↔ (n = ω → AnalyticOn 𝕜 f s) ∧ ∃ f' : E → E →L[𝕜] F, ContDiffOn 𝕜 n f' s ∧ ∀ x, x ∈ s → HasFDerivWithinAt f (f' x) s x := by rw [contDiffOn_succ_iff_fderivWithin hs] refine ⟨fun h => ⟨h.2.1, fderivWithin 𝕜 f s, h.2.2, fun x hx => (h.1 x hx).hasFDerivWithinAt⟩, fun ⟨f_an, h⟩ => ?_⟩ rcases h with ⟨f', h1, h2⟩ refine ⟨fun x hx => (h2 x hx).differentiableWithinAt, f_an, fun x hx => ?_⟩ exact (h1 x hx).congr_of_mem (fun y hy => (h2 y hy).fderivWithin (hs y hy)) hx @[deprecated (since := "2024-11-27")] alias contDiffOn_succ_iff_hasFDerivWithin := contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn theorem contDiffOn_infty_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderivWithin 𝕜 f s) s := by rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderivWithin hs] simp @[deprecated (since := "2024-11-27")] alias contDiffOn_top_iff_fderivWithin := contDiffOn_infty_iff_fderivWithin /-- A function is `C^(n + 1)` on an open domain if and only if it is differentiable there, and its derivative (expressed with `fderiv`) is `C^n`. -/ theorem contDiffOn_succ_iff_fderiv_of_isOpen (hs : IsOpen s) : ContDiffOn 𝕜 (n + 1) f s ↔ DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧ ContDiffOn 𝕜 n (fderiv 𝕜 f) s := by rw [contDiffOn_succ_iff_fderivWithin hs.uniqueDiffOn, contDiffOn_congr fun x hx ↦ fderivWithin_of_isOpen hs hx] theorem contDiffOn_infty_iff_fderiv_of_isOpen (hs : IsOpen s) : ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderiv 𝕜 f) s := by rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderiv_of_isOpen hs] simp @[deprecated (since := "2024-11-27")] alias contDiffOn_top_iff_fderiv_of_isOpen := contDiffOn_infty_iff_fderiv_of_isOpen protected theorem ContDiffOn.fderivWithin (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fderivWithin 𝕜 f s) s := ((contDiffOn_succ_iff_fderivWithin hs).1 (hf.of_le hmn)).2.2 theorem ContDiffOn.fderiv_of_isOpen (hf : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fderiv 𝕜 f) s := (hf.fderivWithin hs.uniqueDiffOn hmn).congr fun _ hx => (fderivWithin_of_isOpen hs hx).symm theorem ContDiffOn.continuousOn_fderivWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hn : 1 ≤ n) : ContinuousOn (fderivWithin 𝕜 f s) s := ((contDiffOn_succ_iff_fderivWithin hs).1 (h.of_le (show 0 + (1 : WithTop ℕ∞) ≤ n from hn))).2.2.continuousOn theorem ContDiffOn.continuousOn_fderiv_of_isOpen (h : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hn : 1 ≤ n) : ContinuousOn (fderiv 𝕜 f) s := ((contDiffOn_succ_iff_fderiv_of_isOpen hs).1 (h.of_le (show 0 + (1 : WithTop ℕ∞) ≤ n from hn))).2.2.continuousOn /-! ### Smooth functions at a point -/ variable (𝕜) in /-- A function is continuously differentiable up to `n` at a point `x` if, for any integer `k ≤ n`, there is a neighborhood of `x` where `f` admits derivatives up to order `n`, which are continuous. -/ def ContDiffAt (n : WithTop ℕ∞) (f : E → F) (x : E) : Prop := ContDiffWithinAt 𝕜 n f univ x theorem contDiffWithinAt_univ : ContDiffWithinAt 𝕜 n f univ x ↔ ContDiffAt 𝕜 n f x := Iff.rfl theorem contDiffAt_infty : ContDiffAt 𝕜 ∞ f x ↔ ∀ n : ℕ, ContDiffAt 𝕜 n f x := by simp [← contDiffWithinAt_univ, contDiffWithinAt_infty] @[deprecated (since := "2024-11-27")] alias contDiffAt_top := contDiffAt_infty theorem ContDiffAt.contDiffWithinAt (h : ContDiffAt 𝕜 n f x) : ContDiffWithinAt 𝕜 n f s x := h.mono (subset_univ _) theorem ContDiffWithinAt.contDiffAt (h : ContDiffWithinAt 𝕜 n f s x) (hx : s ∈ 𝓝 x) : ContDiffAt 𝕜 n f x := by rwa [ContDiffAt, ← contDiffWithinAt_inter hx, univ_inter] theorem contDiffWithinAt_iff_contDiffAt (h : s ∈ 𝓝 x) : ContDiffWithinAt 𝕜 n f s x ↔ ContDiffAt 𝕜 n f x := by rw [← univ_inter s, contDiffWithinAt_inter h, contDiffWithinAt_univ] theorem IsOpen.contDiffOn_iff (hs : IsOpen s) : ContDiffOn 𝕜 n f s ↔ ∀ ⦃a⦄, a ∈ s → ContDiffAt 𝕜 n f a := forall₂_congr fun _ => contDiffWithinAt_iff_contDiffAt ∘ hs.mem_nhds theorem ContDiffOn.contDiffAt (h : ContDiffOn 𝕜 n f s) (hx : s ∈ 𝓝 x) : ContDiffAt 𝕜 n f x := (h _ (mem_of_mem_nhds hx)).contDiffAt hx theorem ContDiffAt.congr_of_eventuallyEq (h : ContDiffAt 𝕜 n f x) (hg : f₁ =ᶠ[𝓝 x] f) : ContDiffAt 𝕜 n f₁ x := h.congr_of_eventuallyEq_of_mem (by rwa [nhdsWithin_univ]) (mem_univ x) theorem ContDiffAt.of_le (h : ContDiffAt 𝕜 n f x) (hmn : m ≤ n) : ContDiffAt 𝕜 m f x := ContDiffWithinAt.of_le h hmn theorem ContDiffAt.continuousAt (h : ContDiffAt 𝕜 n f x) : ContinuousAt f x := by simpa [continuousWithinAt_univ] using h.continuousWithinAt theorem ContDiffAt.analyticAt (h : ContDiffAt 𝕜 ω f x) : AnalyticAt 𝕜 f x := by rw [← contDiffWithinAt_univ] at h rw [← analyticWithinAt_univ] exact h.analyticWithinAt /-- In a complete space, a function which is analytic at a point is also `C^ω` there. Note that the same statement for `AnalyticOn` does not require completeness, see `AnalyticOn.contDiffOn`. -/ theorem AnalyticAt.contDiffAt [CompleteSpace F] (h : AnalyticAt 𝕜 f x) : ContDiffAt 𝕜 n f x := by rw [← contDiffWithinAt_univ] rw [← analyticWithinAt_univ] at h exact h.contDiffWithinAt @[simp] theorem contDiffWithinAt_compl_self : ContDiffWithinAt 𝕜 n f {x}ᶜ x ↔ ContDiffAt 𝕜 n f x := by rw [compl_eq_univ_diff, contDiffWithinAt_diff_singleton, contDiffWithinAt_univ] /-- If a function is `C^n` with `n ≥ 1` at a point, then it is differentiable there. -/ theorem ContDiffAt.differentiableAt (h : ContDiffAt 𝕜 n f x) (hn : 1 ≤ n) : DifferentiableAt 𝕜 f x := by simpa [hn, differentiableWithinAt_univ] using h.differentiableWithinAt nonrec lemma ContDiffAt.contDiffOn (h : ContDiffAt 𝕜 n f x) (hm : m ≤ n) (h' : m = ∞ → n = ω): ∃ u ∈ 𝓝 x, ContDiffOn 𝕜 m f u := by simpa [nhdsWithin_univ] using h.contDiffOn hm h' /-- A function is `C^(n + 1)` at a point iff locally, it has a derivative which is `C^n`. -/ theorem contDiffAt_succ_iff_hasFDerivAt {n : ℕ} : ContDiffAt 𝕜 (n + 1) f x ↔ ∃ f' : E → E →L[𝕜] F, (∃ u ∈ 𝓝 x, ∀ x ∈ u, HasFDerivAt f (f' x) x) ∧ ContDiffAt 𝕜 n f' x := by rw [← contDiffWithinAt_univ, contDiffWithinAt_succ_iff_hasFDerivWithinAt (by simp)] simp only [nhdsWithin_univ, exists_prop, mem_univ, insert_eq_of_mem] constructor · rintro ⟨u, H, -, f', h_fderiv, h_cont_diff⟩ rcases mem_nhds_iff.mp H with ⟨t, htu, ht, hxt⟩ refine ⟨f', ⟨t, ?_⟩, h_cont_diff.contDiffAt H⟩ refine ⟨mem_nhds_iff.mpr ⟨t, Subset.rfl, ht, hxt⟩, ?_⟩ intro y hyt refine (h_fderiv y (htu hyt)).hasFDerivAt ?_ exact mem_nhds_iff.mpr ⟨t, htu, ht, hyt⟩ · rintro ⟨f', ⟨u, H, h_fderiv⟩, h_cont_diff⟩ refine ⟨u, H, by simp, f', fun x hxu ↦ ?_, h_cont_diff.contDiffWithinAt⟩ exact (h_fderiv x hxu).hasFDerivWithinAt protected theorem ContDiffAt.eventually (h : ContDiffAt 𝕜 n f x) (h' : n ≠ ∞) : ∀ᶠ y in 𝓝 x, ContDiffAt 𝕜 n f y := by simpa [nhdsWithin_univ] using ContDiffWithinAt.eventually h h' theorem iteratedFDerivWithin_eq_iteratedFDeriv {n : ℕ} (hs : UniqueDiffOn 𝕜 s) (h : ContDiffAt 𝕜 n f x) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 n f s x = iteratedFDeriv 𝕜 n f x := by rw [← iteratedFDerivWithin_univ] rcases h.contDiffOn' le_rfl (by simp) with ⟨u, u_open, xu, hu⟩ rw [← iteratedFDerivWithin_inter_open u_open xu, ← iteratedFDerivWithin_inter_open u_open xu (s := univ)] apply iteratedFDerivWithin_subset · exact inter_subset_inter_left _ (subset_univ _) · exact hs.inter u_open · apply uniqueDiffOn_univ.inter u_open · simpa using hu · exact ⟨hx, xu⟩ /-! ### Smooth functions -/ variable (𝕜) in /-- A function is continuously differentiable up to `n` if it admits derivatives up to order `n`, which are continuous. Contrary to the case of definitions in domains (where derivatives might not be unique) we do not need to localize the definition in space or time. -/ def ContDiff (n : WithTop ℕ∞) (f : E → F) : Prop := match n with | ω => ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpTo ⊤ f p ∧ ∀ i, AnalyticOnNhd 𝕜 (fun x ↦ p x i) univ | (n : ℕ∞) => ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpTo n f p /-- If `f` has a Taylor series up to `n`, then it is `C^n`. -/ theorem HasFTaylorSeriesUpTo.contDiff {n : ℕ∞} {f' : E → FormalMultilinearSeries 𝕜 E F} (hf : HasFTaylorSeriesUpTo n f f') : ContDiff 𝕜 n f := ⟨f', hf⟩ theorem contDiffOn_univ : ContDiffOn 𝕜 n f univ ↔ ContDiff 𝕜 n f := by match n with | ω => constructor · intro H use ftaylorSeriesWithin 𝕜 f univ rw [← hasFTaylorSeriesUpToOn_univ_iff] refine ⟨H.ftaylorSeriesWithin uniqueDiffOn_univ, fun i ↦ ?_⟩ rw [← analyticOn_univ] exact H.analyticOn.iteratedFDerivWithin uniqueDiffOn_univ _ · rintro ⟨p, hp, h'p⟩ x _ exact ⟨univ, Filter.univ_sets _, p, (hp.hasFTaylorSeriesUpToOn univ).of_le le_top, fun i ↦ (h'p i).analyticOn⟩ | (n : ℕ∞) => constructor · intro H use ftaylorSeriesWithin 𝕜 f univ rw [← hasFTaylorSeriesUpToOn_univ_iff] exact H.ftaylorSeriesWithin uniqueDiffOn_univ · rintro ⟨p, hp⟩ x _ m hm exact ⟨univ, Filter.univ_sets _, p, (hp.hasFTaylorSeriesUpToOn univ).of_le (mod_cast hm)⟩ theorem contDiff_iff_contDiffAt : ContDiff 𝕜 n f ↔ ∀ x, ContDiffAt 𝕜 n f x := by simp [← contDiffOn_univ, ContDiffOn, ContDiffAt] theorem ContDiff.contDiffAt (h : ContDiff 𝕜 n f) : ContDiffAt 𝕜 n f x := contDiff_iff_contDiffAt.1 h x theorem ContDiff.contDiffWithinAt (h : ContDiff 𝕜 n f) : ContDiffWithinAt 𝕜 n f s x := h.contDiffAt.contDiffWithinAt theorem contDiff_infty : ContDiff 𝕜 ∞ f ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by simp [contDiffOn_univ.symm, contDiffOn_infty] @[deprecated (since := "2024-11-25")] alias contDiff_top := contDiff_infty @[deprecated (since := "2024-11-25")] alias contDiff_infty_iff_contDiff_omega := contDiff_infty theorem contDiff_all_iff_nat : (∀ n : ℕ∞, ContDiff 𝕜 n f) ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by simp only [← contDiffOn_univ, contDiffOn_all_iff_nat] theorem ContDiff.contDiffOn (h : ContDiff 𝕜 n f) : ContDiffOn 𝕜 n f s := (contDiffOn_univ.2 h).mono (subset_univ _) @[simp] theorem contDiff_zero : ContDiff 𝕜 0 f ↔ Continuous f := by rw [← contDiffOn_univ, continuous_iff_continuousOn_univ] exact contDiffOn_zero theorem contDiffAt_zero : ContDiffAt 𝕜 0 f x ↔ ∃ u ∈ 𝓝 x, ContinuousOn f u := by rw [← contDiffWithinAt_univ]; simp [contDiffWithinAt_zero, nhdsWithin_univ] theorem contDiffAt_one_iff : ContDiffAt 𝕜 1 f x ↔ ∃ f' : E → E →L[𝕜] F, ∃ u ∈ 𝓝 x, ContinuousOn f' u ∧ ∀ x ∈ u, HasFDerivAt f (f' x) x := by rw [show (1 : WithTop ℕ∞) = (0 : ℕ) + 1 from rfl] simp_rw [contDiffAt_succ_iff_hasFDerivAt, show ((0 : ℕ) : WithTop ℕ∞) = 0 from rfl, contDiffAt_zero, exists_mem_and_iff antitone_bforall antitone_continuousOn, and_comm] theorem ContDiff.of_le (h : ContDiff 𝕜 n f) (hmn : m ≤ n) : ContDiff 𝕜 m f := contDiffOn_univ.1 <| (contDiffOn_univ.2 h).of_le hmn theorem ContDiff.of_succ (h : ContDiff 𝕜 (n + 1) f) : ContDiff 𝕜 n f := h.of_le le_self_add theorem ContDiff.one_of_succ (h : ContDiff 𝕜 (n + 1) f) : ContDiff 𝕜 1 f := by apply h.of_le le_add_self theorem ContDiff.continuous (h : ContDiff 𝕜 n f) : Continuous f := contDiff_zero.1 (h.of_le bot_le) /-- If a function is `C^n` with `n ≥ 1`, then it is differentiable. -/ theorem ContDiff.differentiable (h : ContDiff 𝕜 n f) (hn : 1 ≤ n) : Differentiable 𝕜 f := differentiableOn_univ.1 <| (contDiffOn_univ.2 h).differentiableOn hn theorem contDiff_iff_forall_nat_le {n : ℕ∞} : ContDiff 𝕜 n f ↔ ∀ m : ℕ, ↑m ≤ n → ContDiff 𝕜 m f := by simp_rw [← contDiffOn_univ]; exact contDiffOn_iff_forall_nat_le /-- A function is `C^(n+1)` iff it has a `C^n` derivative. -/ theorem contDiff_succ_iff_hasFDerivAt {n : ℕ} : ContDiff 𝕜 (n + 1) f ↔ ∃ f' : E → E →L[𝕜] F, ContDiff 𝕜 n f' ∧ ∀ x, HasFDerivAt f (f' x) x := by simp only [← contDiffOn_univ, ← hasFDerivWithinAt_univ, Set.mem_univ, forall_true_left, contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn uniqueDiffOn_univ, WithTop.natCast_ne_top, analyticOn_univ, false_implies, true_and] theorem contDiff_one_iff_hasFDerivAt : ContDiff 𝕜 1 f ↔ ∃ f' : E → E →L[𝕜] F, Continuous f' ∧ ∀ x, HasFDerivAt f (f' x) x := by convert contDiff_succ_iff_hasFDerivAt using 4; simp theorem AnalyticOn.contDiff (hf : AnalyticOn 𝕜 f univ) : ContDiff 𝕜 n f := by rw [← contDiffOn_univ] exact hf.contDiffOn (n := n) uniqueDiffOn_univ theorem AnalyticOnNhd.contDiff (hf : AnalyticOnNhd 𝕜 f univ) : ContDiff 𝕜 n f := hf.analyticOn.contDiff theorem ContDiff.analyticOnNhd (h : ContDiff 𝕜 ω f) : AnalyticOnNhd 𝕜 f s := by rw [← contDiffOn_univ] at h have := h.analyticOn rw [analyticOn_univ] at this exact this.mono (subset_univ _) theorem contDiff_omega_iff_analyticOnNhd : ContDiff 𝕜 ω f ↔ AnalyticOnNhd 𝕜 f univ := ⟨fun h ↦ h.analyticOnNhd, fun h ↦ h.contDiff⟩ /-! ### Iterated derivative -/ /-- When a function is `C^n`, it admits `ftaylorSeries 𝕜 f` as a Taylor series up to order `n` in `s`. -/ theorem ContDiff.ftaylorSeries (hf : ContDiff 𝕜 n f) : HasFTaylorSeriesUpTo n f (ftaylorSeries 𝕜 f) := by simp only [← contDiffOn_univ, ← hasFTaylorSeriesUpToOn_univ_iff, ← ftaylorSeriesWithin_univ] at hf ⊢ exact ContDiffOn.ftaylorSeriesWithin hf uniqueDiffOn_univ /-- For `n : ℕ∞`, a function is `C^n` iff it admits `ftaylorSeries 𝕜 f` as a Taylor series up to order `n`. -/ theorem contDiff_iff_ftaylorSeries {n : ℕ∞} : ContDiff 𝕜 n f ↔ HasFTaylorSeriesUpTo n f (ftaylorSeries 𝕜 f) := by constructor · rw [← contDiffOn_univ, ← hasFTaylorSeriesUpToOn_univ_iff, ← ftaylorSeriesWithin_univ] exact fun h ↦ ContDiffOn.ftaylorSeriesWithin h uniqueDiffOn_univ · exact fun h ↦ ⟨ftaylorSeries 𝕜 f, h⟩ theorem contDiff_iff_continuous_differentiable {n : ℕ∞} : ContDiff 𝕜 n f ↔ (∀ m : ℕ, m ≤ n → Continuous fun x => iteratedFDeriv 𝕜 m f x) ∧ ∀ m : ℕ, m < n → Differentiable 𝕜 fun x => iteratedFDeriv 𝕜 m f x := by simp [contDiffOn_univ.symm, continuous_iff_continuousOn_univ, differentiableOn_univ.symm, iteratedFDerivWithin_univ, contDiffOn_iff_continuousOn_differentiableOn uniqueDiffOn_univ] theorem contDiff_nat_iff_continuous_differentiable {n : ℕ} : ContDiff 𝕜 n f ↔ (∀ m : ℕ, m ≤ n → Continuous fun x => iteratedFDeriv 𝕜 m f x) ∧ ∀ m : ℕ, m < n → Differentiable 𝕜 fun x => iteratedFDeriv 𝕜 m f x := by rw [← WithTop.coe_natCast, contDiff_iff_continuous_differentiable] simp /-- If `f` is `C^n` then its `m`-times iterated derivative is continuous for `m ≤ n`. -/ theorem ContDiff.continuous_iteratedFDeriv {m : ℕ} (hm : m ≤ n) (hf : ContDiff 𝕜 n f) : Continuous fun x => iteratedFDeriv 𝕜 m f x := (contDiff_iff_continuous_differentiable.mp (hf.of_le hm)).1 m le_rfl /-- If `f` is `C^n` then its `m`-times iterated derivative is differentiable for `m < n`. -/ theorem ContDiff.differentiable_iteratedFDeriv {m : ℕ} (hm : m < n) (hf : ContDiff 𝕜 n f) : Differentiable 𝕜 fun x => iteratedFDeriv 𝕜 m f x := (contDiff_iff_continuous_differentiable.mp (hf.of_le (ENat.add_one_natCast_le_withTop_of_lt hm))).2 m (mod_cast lt_add_one m) theorem contDiff_of_differentiable_iteratedFDeriv {n : ℕ∞} (h : ∀ m : ℕ, m ≤ n → Differentiable 𝕜 (iteratedFDeriv 𝕜 m f)) : ContDiff 𝕜 n f := contDiff_iff_continuous_differentiable.2 ⟨fun m hm => (h m hm).continuous, fun m hm => h m (le_of_lt hm)⟩ /-- A function is `C^(n + 1)` if and only if it is differentiable, and its derivative (formulated in terms of `fderiv`) is `C^n`. -/ theorem contDiff_succ_iff_fderiv : ContDiff 𝕜 (n + 1) f ↔ Differentiable 𝕜 f ∧ (n = ω → AnalyticOnNhd 𝕜 f univ) ∧ ContDiff 𝕜 n (fderiv 𝕜 f) := by simp only [← contDiffOn_univ, ← differentiableOn_univ, ← fderivWithin_univ, contDiffOn_succ_iff_fderivWithin uniqueDiffOn_univ, analyticOn_univ] theorem contDiff_one_iff_fderiv : ContDiff 𝕜 1 f ↔ Differentiable 𝕜 f ∧ Continuous (fderiv 𝕜 f) := by rw [← zero_add 1, contDiff_succ_iff_fderiv] simp theorem contDiff_infty_iff_fderiv : ContDiff 𝕜 ∞ f ↔ Differentiable 𝕜 f ∧ ContDiff 𝕜 ∞ (fderiv 𝕜 f) := by rw [← ENat.coe_top_add_one, contDiff_succ_iff_fderiv] simp @[deprecated (since := "2024-11-27")] alias contDiff_top_iff_fderiv := contDiff_infty_iff_fderiv theorem ContDiff.continuous_fderiv (h : ContDiff 𝕜 n f) (hn : 1 ≤ n) : Continuous (fderiv 𝕜 f) := (contDiff_one_iff_fderiv.1 (h.of_le hn)).2 /-- If a function is at least `C^1`, its bundled derivative (mapping `(x, v)` to `Df(x) v`) is continuous. -/ theorem ContDiff.continuous_fderiv_apply (h : ContDiff 𝕜 n f) (hn : 1 ≤ n) : Continuous fun p : E × E => (fderiv 𝕜 f p.1 : E → F) p.2 := have A : Continuous fun q : (E →L[𝕜] F) × E => q.1 q.2 := isBoundedBilinearMap_apply.continuous have B : Continuous fun p : E × E => (fderiv 𝕜 f p.1, p.2) := ((h.continuous_fderiv hn).comp continuous_fst).prodMk continuous_snd A.comp B
Mathlib/Analysis/Calculus/ContDiff/Defs.lean
1,303
1,306
/- 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.Data.Set.Restrict /-! # Functions over sets This file contains basic results on the following predicates of functions and sets: * `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`. -/ variable {α β γ δ : Type*} {ι : Sort*} {π : α → Type*} open Equiv Equiv.Perm Function namespace Set /-! ### Equality on a set -/ section equality variable {s s₁ s₂ : Set α} {f₁ f₂ f₃ : α → β} {g : β → γ} {a : α} /-- This lemma exists for use by `aesop` as a forward rule. -/ @[aesop safe forward] lemma EqOn.eq_of_mem (h : s.EqOn f₁ f₂) (ha : a ∈ s) : f₁ a = f₂ a := h ha @[simp] theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim @[simp] theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by simp [Set.EqOn] @[simp] theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by simp [EqOn, funext_iff] @[symm] theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s := ⟨EqOn.symm, EqOn.symm⟩ -- 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 -- 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 https://github.com/leanprover-community/mathlib4/pull/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) theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s := image_congr heq /-- 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] theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx) @[simp] theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ := forall₂_or_left theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) := eqOn_union.2 ⟨h₁, h₂⟩ theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha => congr_arg _ <| h ha @[simp] theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} : EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f := forall_mem_range.trans <| funext_iff.symm alias ⟨EqOn.comp_eq, _⟩ := eqOn_range end equality variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} section MapsTo theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t := image_subset_iff.symm theorem mapsTo_prodMap_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) := diagonal_subset_iff.2 fun _ => rfl @[deprecated (since := "2025-04-18")] alias mapsTo_prod_map_diagonal := mapsTo_prodMap_diagonal theorem MapsTo.subset_preimage (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf theorem mapsTo_iff_subset_preimage : MapsTo f s t ↔ s ⊆ f ⁻¹' t := Iff.rfl @[simp] theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t := singleton_subset_iff theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t := empty_subset _ @[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 theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx => h hx ▸ h₁ hx 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 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⟩ theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h => h₁ (h₂ h) theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => 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 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 generalizing x with | zero => rfl | succ n ihn => simp [Nat.iterate, ihn] 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⟩ lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s := mapsTo_of_subsingleton' _ id theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ := fun _ hx => ht (hf <| hs hx) theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx => hf (hs hx) theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx => ht (hf hx) 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 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₂ @[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⟩ theorem MapsTo.inter (h₁ : MapsTo f s t₁) (h₂ : MapsTo f s t₂) : MapsTo f s (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx, h₂ hx⟩ lemma MapsTo.insert (h : MapsTo f s t) (x : α) : MapsTo f (insert x s) (insert (f x) t) := by simpa [← singleton_union] using h.mono_right subset_union_right 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⟩ @[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⟩ theorem mapsTo_univ (f : α → β) (s : Set α) : MapsTo f s univ := fun _ _ => trivial theorem mapsTo_range (f : α → β) (s : Set α) : MapsTo f s (range f) := (mapsTo_image f s).mono (Subset.refl s) (image_subset_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⟩ lemma MapsTo.comp_left (g : β → γ) (hf : MapsTo f s t) : MapsTo (g ∘ f) s (g '' t) := fun x hx ↦ ⟨f x, hf hx, rfl⟩ lemma MapsTo.comp_right {s : Set β} {t : Set γ} (hg : MapsTo g s t) (f : α → β) : MapsTo (g ∘ f) (f ⁻¹' s) t := fun _ hx ↦ hg hx @[simp] lemma mapsTo_univ_iff : MapsTo f univ t ↔ ∀ x, f x ∈ t := ⟨fun h _ => h (mem_univ _), fun h x _ => h x⟩ @[simp] lemma mapsTo_range_iff {g : ι → α} : MapsTo f (range g) t ↔ ∀ i, f (g i) ∈ t := forall_mem_range 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⟩ end MapsTo /-! ### Injectivity on a set -/ section injOn theorem Subsingleton.injOn (hs : s.Subsingleton) (f : α → β) : InjOn f s := fun _ hx _ hy _ => hs hx hy @[simp] theorem injOn_empty (f : α → β) : InjOn f ∅ := subsingleton_empty.injOn f @[simp] theorem injOn_singleton (f : α → β) (a : α) : InjOn f {a} := subsingleton_singleton.injOn f @[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⟩ 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 alias ⟨_, InjOn.ne⟩ := InjOn.ne_iff 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 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⟩ theorem InjOn.mono (h : s₁ ⊆ s₂) (ht : InjOn f s₂) : InjOn f s₁ := fun _ hx _ hy H => ht (h hx) (h hy) H 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] 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 theorem injective_iff_injOn_univ : Injective f ↔ InjOn f univ := ⟨fun h _ _ _ _ hxy => h hxy, fun h _ _ heq => h trivial trivial heq⟩ theorem injOn_of_injective (h : Injective f) {s : Set α} : InjOn f s := fun _ _ _ _ hxy => h hxy alias _root_.Function.Injective.injOn := injOn_of_injective -- 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 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 lemma InjOn.of_comp (h : InjOn (g ∘ f) s) : InjOn f s := fun _ hx _ hy heq ↦ h hx hy (by simp [heq]) 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.comp_iff (hf : InjOn f s) : InjOn (g ∘ f) s ↔ InjOn g (f '' s) := ⟨image_of_comp, fun h ↦ InjOn.comp h hf <| mapsTo_image f s⟩ 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 lemma injOn_of_subsingleton [Subsingleton α] (f : α → β) (s : Set α) : InjOn f s := (injective_of_subsingleton _).injOn 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) theorem _root_.Set.InjOn.injective_iff (s : Set β) (h : InjOn g s) (hs : range f ⊆ s) : Injective (g ∘ f) ↔ Injective f := ⟨(·.of_comp), fun h _ ↦ by aesop⟩ theorem exists_injOn_iff_injective [Nonempty β] : (∃ f : α → β, InjOn f s) ↔ ∃ f : s → β, Injective f := ⟨fun ⟨_, hf⟩ => ⟨_, hf.injective⟩, fun ⟨f, hf⟩ => by lift f to α → β using trivial exact ⟨f, injOn_iff_injective.2 hf⟩⟩ theorem injOn_preimage {B : Set (Set β)} (hB : B ⊆ 𝒫 range f) : InjOn (preimage f) B := fun _ hs _ ht hst => (preimage_eq_preimage' (hB hs) (hB ht)).1 hst theorem InjOn.mem_of_mem_image {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (h : x ∈ s) (h₁ : f x ∈ f '' s₁) : x ∈ s₁ := let ⟨_, h', Eq⟩ := h₁ hf (hs h') h Eq ▸ h' theorem InjOn.mem_image_iff {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (hx : x ∈ s) : f x ∈ f '' s₁ ↔ x ∈ s₁ := ⟨hf.mem_of_mem_image hs hx, mem_image_of_mem f⟩ theorem InjOn.preimage_image_inter (hf : InjOn f s) (hs : s₁ ⊆ s) : f ⁻¹' (f '' s₁) ∩ s = s₁ := ext fun _ => ⟨fun ⟨h₁, h₂⟩ => hf.mem_of_mem_image hs h₂ h₁, fun h => ⟨mem_image_of_mem _ h, hs h⟩⟩ theorem EqOn.cancel_left (h : s.EqOn (g ∘ f₁) (g ∘ f₂)) (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn f₁ f₂ := fun _ ha => hg (hf₁ ha) (hf₂ ha) (h ha) theorem InjOn.cancel_left (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn (g ∘ f₁) (g ∘ f₂) ↔ s.EqOn f₁ f₂ := ⟨fun h => h.cancel_left hg hf₁ hf₂, EqOn.comp_left⟩ lemma InjOn.image_inter {s t u : Set α} (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : f '' (s ∩ t) = f '' s ∩ f '' t := by apply Subset.antisymm (image_inter_subset _ _ _) intro x ⟨⟨y, ys, hy⟩, ⟨z, zt, hz⟩⟩ have : y = z := by apply hf (hs ys) (ht zt) rwa [← hz] at hy rw [← this] at zt exact ⟨y, ⟨ys, zt⟩, hy⟩ lemma InjOn.image (h : s.InjOn f) : s.powerset.InjOn (image f) := fun s₁ hs₁ s₂ hs₂ h' ↦ by rw [← h.preimage_image_inter hs₁, h', h.preimage_image_inter hs₂] theorem InjOn.image_eq_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ = f '' s₂ ↔ s₁ = s₂ := h.image.eq_iff h₁ h₂ lemma InjOn.image_subset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊆ f '' s₂ ↔ s₁ ⊆ s₂ := by refine ⟨fun h' ↦ ?_, image_subset _⟩ rw [← h.preimage_image_inter h₁, ← h.preimage_image_inter h₂] exact inter_subset_inter_left _ (preimage_mono h') lemma InjOn.image_ssubset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊂ f '' s₂ ↔ s₁ ⊂ s₂ := by simp_rw [ssubset_def, h.image_subset_image_iff h₁ h₂, h.image_subset_image_iff h₂ h₁] -- TODO: can this move to a better place? theorem _root_.Disjoint.image {s t u : Set α} {f : α → β} (h : Disjoint s t) (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : Disjoint (f '' s) (f '' t) := by rw [disjoint_iff_inter_eq_empty] at h ⊢ rw [← hf.image_inter hs ht, h, image_empty] lemma InjOn.image_diff {t : Set α} (h : s.InjOn f) : f '' (s \ t) = f '' s \ f '' (s ∩ t) := by refine subset_antisymm (subset_diff.2 ⟨image_subset f diff_subset, ?_⟩) (diff_subset_iff.2 (by rw [← image_union, inter_union_diff])) exact Disjoint.image disjoint_sdiff_inter h diff_subset inter_subset_left lemma InjOn.image_diff_subset {f : α → β} {t : Set α} (h : InjOn f s) (hst : t ⊆ s) : f '' (s \ t) = f '' s \ f '' t := by rw [h.image_diff, inter_eq_self_of_subset_right hst] alias image_diff_of_injOn := InjOn.image_diff_subset theorem InjOn.imageFactorization_injective (h : InjOn f s) : Injective (s.imageFactorization f) := fun ⟨x, hx⟩ ⟨y, hy⟩ h' ↦ by simpa [imageFactorization, h.eq_iff hx hy] using h' @[simp] theorem imageFactorization_injective_iff : Injective (s.imageFactorization f) ↔ InjOn f s := ⟨fun h x hx y hy _ ↦ by simpa using @h ⟨x, hx⟩ ⟨y, hy⟩ (by simpa [imageFactorization]), InjOn.imageFactorization_injective⟩ end injOn section graphOn variable {x : α × β} lemma graphOn_univ_inj {g : α → β} : univ.graphOn f = univ.graphOn g ↔ f = g := by simp lemma graphOn_univ_injective : Injective (univ.graphOn : (α → β) → Set (α × β)) := fun _f _g ↦ graphOn_univ_inj.1 lemma exists_eq_graphOn_image_fst [Nonempty β] {s : Set (α × β)} : (∃ f : α → β, s = graphOn f (Prod.fst '' s)) ↔ InjOn Prod.fst s := by refine ⟨?_, fun h ↦ ?_⟩ · rintro ⟨f, hf⟩ rw [hf] exact InjOn.image_of_comp <| injOn_id _ · have : ∀ x ∈ Prod.fst '' s, ∃ y, (x, y) ∈ s := forall_mem_image.2 fun (x, y) h ↦ ⟨y, h⟩ choose! f hf using this rw [forall_mem_image] at hf use f rw [graphOn, image_image, EqOn.image_eq_self] exact fun x hx ↦ h (hf hx) hx rfl lemma exists_eq_graphOn [Nonempty β] {s : Set (α × β)} : (∃ f t, s = graphOn f t) ↔ InjOn Prod.fst s := .trans ⟨fun ⟨f, t, hs⟩ ↦ ⟨f, by rw [hs, image_fst_graphOn]⟩, fun ⟨f, hf⟩ ↦ ⟨f, _, hf⟩⟩ exists_eq_graphOn_image_fst end graphOn /-! ### Surjectivity on a set -/ section surjOn theorem SurjOn.subset_range (h : SurjOn f s t) : t ⊆ range f := Subset.trans h <| image_subset_range f s theorem surjOn_iff_exists_map_subtype : SurjOn f s t ↔ ∃ (t' : Set β) (g : s → t'), t ⊆ t' ∧ Surjective g ∧ ∀ x : s, f x = g x := ⟨fun h => ⟨_, (mapsTo_image f s).restrict f s _, h, surjective_mapsTo_image_restrict _ _, fun _ => rfl⟩, fun ⟨t', g, htt', hg, hfg⟩ y hy => let ⟨x, hx⟩ := hg ⟨y, htt' hy⟩ ⟨x, x.2, by rw [hfg, hx, Subtype.coe_mk]⟩⟩ theorem surjOn_empty (f : α → β) (s : Set α) : SurjOn f s ∅ := empty_subset _ @[simp] theorem surjOn_empty_iff : SurjOn f ∅ t ↔ t = ∅ := by simp [SurjOn, subset_empty_iff] @[simp] lemma surjOn_singleton : SurjOn f s {b} ↔ b ∈ f '' s := singleton_subset_iff theorem surjOn_image (f : α → β) (s : Set α) : SurjOn f s (f '' s) := Subset.rfl theorem SurjOn.comap_nonempty (h : SurjOn f s t) (ht : t.Nonempty) : s.Nonempty := (ht.mono h).of_image theorem SurjOn.congr (h : SurjOn f₁ s t) (H : EqOn f₁ f₂ s) : SurjOn f₂ s t := by rwa [SurjOn, ← H.image_eq] theorem EqOn.surjOn_iff (h : EqOn f₁ f₂ s) : SurjOn f₁ s t ↔ SurjOn f₂ s t := ⟨fun H => H.congr h, fun H => H.congr h.symm⟩ theorem SurjOn.mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (hf : SurjOn f s₁ t₂) : SurjOn f s₂ t₁ := Subset.trans ht <| Subset.trans hf <| image_subset _ hs theorem SurjOn.union (h₁ : SurjOn f s t₁) (h₂ : SurjOn f s t₂) : SurjOn f s (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => h₁ hx) fun hx => h₂ hx theorem SurjOn.union_union (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) : SurjOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := (h₁.mono subset_union_left (Subset.refl _)).union (h₂.mono subset_union_right (Subset.refl _)) theorem SurjOn.inter_inter (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := by intro y hy rcases h₁ hy.1 with ⟨x₁, hx₁, rfl⟩ rcases h₂ hy.2 with ⟨x₂, hx₂, heq⟩ obtain rfl : x₁ = x₂ := h (Or.inl hx₁) (Or.inr hx₂) heq.symm exact mem_image_of_mem f ⟨hx₁, hx₂⟩ theorem SurjOn.inter (h₁ : SurjOn f s₁ t) (h₂ : SurjOn f s₂ t) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) t := inter_self t ▸ h₁.inter_inter h₂ h lemma surjOn_id (s : Set α) : SurjOn id s s := by simp [SurjOn] theorem SurjOn.comp (hg : SurjOn g t p) (hf : SurjOn f s t) : SurjOn (g ∘ f) s p := Subset.trans hg <| Subset.trans (image_subset g hf) <| image_comp g f s ▸ Subset.refl _ lemma SurjOn.of_comp (h : SurjOn (g ∘ f) s p) (hr : MapsTo f s t) : SurjOn g t p := by intro z hz obtain ⟨x, hx, rfl⟩ := h hz exact ⟨f x, hr hx, rfl⟩ lemma surjOn_comp_iff : SurjOn (g ∘ f) s p ↔ SurjOn g (f '' s) p := ⟨fun h ↦ h.of_comp <| mapsTo_image f s, fun h ↦ h.comp <| surjOn_image _ _⟩ lemma SurjOn.iterate {f : α → α} {s : Set α} (h : SurjOn f s s) : ∀ n, SurjOn f^[n] s s | 0 => surjOn_id _ | (n + 1) => (h.iterate n).comp h lemma SurjOn.comp_left (hf : SurjOn f s t) (g : β → γ) : SurjOn (g ∘ f) s (g '' t) := by rw [SurjOn, image_comp g f]; exact image_subset _ hf lemma SurjOn.comp_right {s : Set β} {t : Set γ} (hf : Surjective f) (hg : SurjOn g s t) : SurjOn (g ∘ f) (f ⁻¹' s) t := by rwa [SurjOn, image_comp g f, image_preimage_eq _ hf] lemma surjOn_of_subsingleton' [Subsingleton β] (f : α → β) (h : t.Nonempty → s.Nonempty) : SurjOn f s t := fun _ ha ↦ Subsingleton.mem_iff_nonempty.2 <| (h ⟨_, ha⟩).image _ lemma surjOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : SurjOn f s s := surjOn_of_subsingleton' _ id theorem surjective_iff_surjOn_univ : Surjective f ↔ SurjOn f univ univ := by simp [Surjective, SurjOn, subset_def] theorem SurjOn.image_eq_of_mapsTo (h₁ : SurjOn f s t) (h₂ : MapsTo f s t) : f '' s = t := eq_of_subset_of_subset h₂.image_subset h₁ theorem image_eq_iff_surjOn_mapsTo : f '' s = t ↔ s.SurjOn f t ∧ s.MapsTo f t := by refine ⟨?_, fun h => h.1.image_eq_of_mapsTo h.2⟩ rintro rfl exact ⟨s.surjOn_image f, s.mapsTo_image f⟩ lemma SurjOn.image_preimage (h : Set.SurjOn f s t) (ht : t₁ ⊆ t) : f '' (f ⁻¹' t₁) = t₁ := image_preimage_eq_iff.2 fun _ hx ↦ mem_range_of_mem_image f s <| h <| ht hx theorem SurjOn.mapsTo_compl (h : SurjOn f s t) (h' : Injective f) : MapsTo f sᶜ tᶜ := fun _ hs ht => let ⟨_, hx', HEq⟩ := h ht hs <| h' HEq ▸ hx' theorem MapsTo.surjOn_compl (h : MapsTo f s t) (h' : Surjective f) : SurjOn f sᶜ tᶜ := h'.forall.2 fun _ ht => (mem_image_of_mem _) fun hs => ht (h hs) theorem EqOn.cancel_right (hf : s.EqOn (g₁ ∘ f) (g₂ ∘ f)) (hf' : s.SurjOn f t) : t.EqOn g₁ g₂ := by intro b hb obtain ⟨a, ha, rfl⟩ := hf' hb exact hf ha theorem SurjOn.cancel_right (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ t.EqOn g₁ g₂ := ⟨fun h => h.cancel_right hf, fun h => h.comp_right hf'⟩ theorem eqOn_comp_right_iff : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ (f '' s).EqOn g₁ g₂ := (s.surjOn_image f).cancel_right <| s.mapsTo_image f theorem SurjOn.forall {p : β → Prop} (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : (∀ y ∈ t, p y) ↔ (∀ x ∈ s, p (f x)) := ⟨fun H x hx ↦ H (f x) (hf' hx), fun H _y hy ↦ let ⟨x, hx, hxy⟩ := hf hy; hxy ▸ H x hx⟩ end surjOn /-! ### Bijectivity -/ section bijOn theorem BijOn.mapsTo (h : BijOn f s t) : MapsTo f s t := h.left theorem BijOn.injOn (h : BijOn f s t) : InjOn f s := h.right.left theorem BijOn.surjOn (h : BijOn f s t) : SurjOn f s t := h.right.right theorem BijOn.mk (h₁ : MapsTo f s t) (h₂ : InjOn f s) (h₃ : SurjOn f s t) : BijOn f s t := ⟨h₁, h₂, h₃⟩ theorem bijOn_empty (f : α → β) : BijOn f ∅ ∅ := ⟨mapsTo_empty f ∅, injOn_empty f, surjOn_empty f ∅⟩ @[simp] theorem bijOn_empty_iff_left : BijOn f s ∅ ↔ s = ∅ := ⟨fun h ↦ by simpa using h.mapsTo, by rintro rfl; exact bijOn_empty f⟩ @[simp] theorem bijOn_empty_iff_right : BijOn f ∅ t ↔ t = ∅ := ⟨fun h ↦ by simpa using h.surjOn, by rintro rfl; exact bijOn_empty f⟩ @[simp] lemma bijOn_singleton : BijOn f {a} {b} ↔ f a = b := by simp [BijOn, eq_comm] theorem BijOn.inter_mapsTo (h₁ : BijOn f s₁ t₁) (h₂ : MapsTo f s₂ t₂) (h₃ : s₁ ∩ f ⁻¹' t₂ ⊆ s₂) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂, h₁.injOn.mono inter_subset_left, fun _ hy => let ⟨x, hx, hxy⟩ := h₁.surjOn hy.1 ⟨x, ⟨hx, h₃ ⟨hx, hxy.symm.subst hy.2⟩⟩, hxy⟩⟩ theorem MapsTo.inter_bijOn (h₁ : MapsTo f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h₃ : s₂ ∩ f ⁻¹' t₁ ⊆ s₁) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := inter_comm s₂ s₁ ▸ inter_comm t₂ t₁ ▸ h₂.inter_mapsTo h₁ h₃ theorem BijOn.inter (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂.mapsTo, h₁.injOn.mono inter_subset_left, h₁.surjOn.inter_inter h₂.surjOn h⟩ theorem BijOn.union (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := ⟨h₁.mapsTo.union_union h₂.mapsTo, h, h₁.surjOn.union_union h₂.surjOn⟩ theorem BijOn.subset_range (h : BijOn f s t) : t ⊆ range f := h.surjOn.subset_range theorem InjOn.bijOn_image (h : InjOn f s) : BijOn f s (f '' s) := BijOn.mk (mapsTo_image f s) h (Subset.refl _) theorem BijOn.congr (h₁ : BijOn f₁ s t) (h : EqOn f₁ f₂ s) : BijOn f₂ s t := BijOn.mk (h₁.mapsTo.congr h) (h₁.injOn.congr h) (h₁.surjOn.congr h) theorem EqOn.bijOn_iff (H : EqOn f₁ f₂ s) : BijOn f₁ s t ↔ BijOn f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem BijOn.image_eq (h : BijOn f s t) : f '' s = t := h.surjOn.image_eq_of_mapsTo h.mapsTo lemma BijOn.forall {p : β → Prop} (hf : BijOn f s t) : (∀ b ∈ t, p b) ↔ ∀ a ∈ s, p (f a) where mp h _ ha := h _ <| hf.mapsTo ha mpr h b hb := by obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact h _ ha lemma BijOn.exists {p : β → Prop} (hf : BijOn f s t) : (∃ b ∈ t, p b) ↔ ∃ a ∈ s, p (f a) where mp := by rintro ⟨b, hb, h⟩; obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact ⟨a, ha, h⟩ mpr := by rintro ⟨a, ha, h⟩; exact ⟨f a, hf.mapsTo ha, h⟩ lemma _root_.Equiv.image_eq_iff_bijOn (e : α ≃ β) : e '' s = t ↔ BijOn e s t := ⟨fun h ↦ ⟨(mapsTo_image e s).mono_right h.subset, e.injective.injOn, h ▸ surjOn_image e s⟩, BijOn.image_eq⟩ lemma bijOn_id (s : Set α) : BijOn id s s := ⟨s.mapsTo_id, s.injOn_id, s.surjOn_id⟩ theorem BijOn.comp (hg : BijOn g t p) (hf : BijOn f s t) : BijOn (g ∘ f) s p := BijOn.mk (hg.mapsTo.comp hf.mapsTo) (hg.injOn.comp hf.injOn hf.mapsTo) (hg.surjOn.comp hf.surjOn) /-- If `f : α → β` and `g : β → γ` and if `f` is injective on `s`, then `f ∘ g` is a bijection on `s` iff `g` is a bijection on `f '' s`. -/ theorem bijOn_comp_iff (hf : InjOn f s) : BijOn (g ∘ f) s p ↔ BijOn g (f '' s) p := by simp only [BijOn, InjOn.comp_iff, surjOn_comp_iff, mapsTo_image_iff, hf] /-- If we have a commutative square ``` α --f--> β | | p₁ p₂ | | \/ \/ γ --g--> δ ``` and `f` induces a bijection from `s : Set α` to `t : Set β`, then `g` induces a bijection from the image of `s` to the image of `t`, as long as `g` is is injective on the image of `s`. -/ theorem bijOn_image_image {p₁ : α → γ} {p₂ : β → δ} {g : γ → δ} (comm : ∀ a, p₂ (f a) = g (p₁ a)) (hbij : BijOn f s t) (hinj: InjOn g (p₁ '' s)) : BijOn g (p₁ '' s) (p₂ '' t) := by obtain ⟨h1, h2, h3⟩ := hbij refine ⟨?_, hinj, ?_⟩ · rintro _ ⟨a, ha, rfl⟩ exact ⟨f a, h1 ha, by rw [comm a]⟩ · rintro _ ⟨b, hb, rfl⟩ obtain ⟨a, ha, rfl⟩ := h3 hb rw [← image_comp, comm] exact ⟨a, ha, rfl⟩ lemma BijOn.iterate {f : α → α} {s : Set α} (h : BijOn f s s) : ∀ n, BijOn f^[n] s s | 0 => s.bijOn_id | (n + 1) => (h.iterate n).comp h lemma bijOn_of_subsingleton' [Subsingleton α] [Subsingleton β] (f : α → β) (h : s.Nonempty ↔ t.Nonempty) : BijOn f s t := ⟨mapsTo_of_subsingleton' _ h.1, injOn_of_subsingleton _ _, surjOn_of_subsingleton' _ h.2⟩ lemma bijOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : BijOn f s s := bijOn_of_subsingleton' _ Iff.rfl theorem BijOn.bijective (h : BijOn f s t) : Bijective (h.mapsTo.restrict f s t) := ⟨fun x y h' => Subtype.ext <| h.injOn x.2 y.2 <| Subtype.ext_iff.1 h', fun ⟨_, hy⟩ => let ⟨x, hx, hxy⟩ := h.surjOn hy ⟨⟨x, hx⟩, Subtype.eq hxy⟩⟩ theorem bijective_iff_bijOn_univ : Bijective f ↔ BijOn f univ univ := Iff.intro (fun h => let ⟨inj, surj⟩ := h ⟨mapsTo_univ f _, inj.injOn, Iff.mp surjective_iff_surjOn_univ surj⟩) fun h => let ⟨_map, inj, surj⟩ := h ⟨Iff.mpr injective_iff_injOn_univ inj, Iff.mpr surjective_iff_surjOn_univ surj⟩ alias ⟨_root_.Function.Bijective.bijOn_univ, _⟩ := bijective_iff_bijOn_univ theorem BijOn.compl (hst : BijOn f s t) (hf : Bijective f) : BijOn f sᶜ tᶜ := ⟨hst.surjOn.mapsTo_compl hf.1, hf.1.injOn, hst.mapsTo.surjOn_compl hf.2⟩ theorem BijOn.subset_right {r : Set β} (hf : BijOn f s t) (hrt : r ⊆ t) : BijOn f (s ∩ f ⁻¹' r) r := by refine ⟨inter_subset_right, hf.injOn.mono inter_subset_left, fun x hx ↦ ?_⟩ obtain ⟨y, hy, rfl⟩ := hf.surjOn (hrt hx) exact ⟨y, ⟨hy, hx⟩, rfl⟩ theorem BijOn.subset_left {r : Set α} (hf : BijOn f s t) (hrs : r ⊆ s) : BijOn f r (f '' r) := (hf.injOn.mono hrs).bijOn_image theorem BijOn.insert_iff (ha : a ∉ s) (hfa : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) ↔ BijOn f s t where mp h := by have := congrArg (· \ {f a}) (image_insert_eq ▸ h.image_eq) simp only [mem_singleton_iff, insert_diff_of_mem] at this rw [diff_singleton_eq_self hfa, diff_singleton_eq_self] at this · exact ⟨by simp [← this, mapsTo'], h.injOn.mono (subset_insert ..), by simp [← this, surjOn_image]⟩ simp only [mem_image, not_exists, not_and] intro x hx rw [h.injOn.eq_iff (by simp [hx]) (by simp)] exact ha ∘ (· ▸ hx) mpr h := by repeat rw [insert_eq] refine (bijOn_singleton.mpr rfl).union h ?_ simp only [singleton_union, injOn_insert fun x ↦ (hfa (h.mapsTo x)), h.injOn, mem_image, not_exists, not_and, true_and] exact fun _ hx h₂ ↦ hfa (h₂ ▸ h.mapsTo hx) theorem BijOn.insert (h₁ : BijOn f s t) (h₂ : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) := (insert_iff (h₂ <| h₁.mapsTo ·) h₂).mpr h₁ theorem BijOn.sdiff_singleton (h₁ : BijOn f s t) (h₂ : a ∈ s) : BijOn f (s \ {a}) (t \ {f a}) := by convert h₁.subset_left diff_subset simp [h₁.injOn.image_diff, h₁.image_eq, h₂, inter_eq_self_of_subset_right] end bijOn /-! ### left inverse -/ namespace LeftInvOn theorem eqOn (h : LeftInvOn f' f s) : EqOn (f' ∘ f) id s := h theorem eq (h : LeftInvOn f' f s) {x} (hx : x ∈ s) : f' (f x) = x := h hx theorem congr_left (h₁ : LeftInvOn f₁' f s) {t : Set β} (h₁' : MapsTo f s t) (heq : EqOn f₁' f₂' t) : LeftInvOn f₂' f s := fun _ hx => heq (h₁' hx) ▸ h₁ hx theorem congr_right (h₁ : LeftInvOn f₁' f₁ s) (heq : EqOn f₁ f₂ s) : LeftInvOn f₁' f₂ s := fun _ hx => heq hx ▸ h₁ hx theorem injOn (h : LeftInvOn f₁' f s) : InjOn f s := fun x₁ h₁ x₂ h₂ heq => calc x₁ = f₁' (f x₁) := Eq.symm <| h h₁ _ = f₁' (f x₂) := congr_arg f₁' heq _ = x₂ := h h₂ theorem surjOn (h : LeftInvOn f' f s) (hf : MapsTo f s t) : SurjOn f' t s := fun x hx => ⟨f x, hf hx, h hx⟩ theorem mapsTo (h : LeftInvOn f' f s) (hf : SurjOn f s t) : MapsTo f' t s := fun y hy => by let ⟨x, hs, hx⟩ := hf hy rwa [← hx, h hs] lemma _root_.Set.leftInvOn_id (s : Set α) : LeftInvOn id id s := fun _ _ ↦ rfl theorem comp (hf' : LeftInvOn f' f s) (hg' : LeftInvOn g' g t) (hf : MapsTo f s t) : LeftInvOn (f' ∘ g') (g ∘ f) s := fun x h => calc (f' ∘ g') ((g ∘ f) x) = f' (f x) := congr_arg f' (hg' (hf h)) _ = x := hf' h theorem mono (hf : LeftInvOn f' f s) (ht : s₁ ⊆ s) : LeftInvOn f' f s₁ := fun _ hx => hf (ht hx) theorem image_inter' (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' s₁ ∩ f '' s := by apply Subset.antisymm · rintro _ ⟨x, ⟨h₁, h⟩, rfl⟩ exact ⟨by rwa [mem_preimage, hf h], mem_image_of_mem _ h⟩ · rintro _ ⟨h₁, ⟨x, h, rfl⟩⟩ exact mem_image_of_mem _ ⟨by rwa [← hf h], h⟩ theorem image_inter (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' (s₁ ∩ s) ∩ f '' s := by rw [hf.image_inter'] refine Subset.antisymm ?_ (inter_subset_inter_left _ (preimage_mono inter_subset_left)) rintro _ ⟨h₁, x, hx, rfl⟩; exact ⟨⟨h₁, by rwa [hf hx]⟩, mem_image_of_mem _ hx⟩ theorem image_image (hf : LeftInvOn f' f s) : f' '' (f '' s) = s := by rw [Set.image_image, image_congr hf, image_id'] theorem image_image' (hf : LeftInvOn f' f s) (hs : s₁ ⊆ s) : f' '' (f '' s₁) = s₁ := (hf.mono hs).image_image end LeftInvOn /-! ### Right inverse -/ section RightInvOn namespace RightInvOn theorem eqOn (h : RightInvOn f' f t) : EqOn (f ∘ f') id t := h theorem eq (h : RightInvOn f' f t) {y} (hy : y ∈ t) : f (f' y) = y := h hy theorem _root_.Set.LeftInvOn.rightInvOn_image (h : LeftInvOn f' f s) : RightInvOn f' f (f '' s) := fun _y ⟨_x, hx, heq⟩ => heq ▸ (congr_arg f <| h.eq hx) theorem congr_left (h₁ : RightInvOn f₁' f t) (heq : EqOn f₁' f₂' t) : RightInvOn f₂' f t := h₁.congr_right heq theorem congr_right (h₁ : RightInvOn f' f₁ t) (hg : MapsTo f' t s) (heq : EqOn f₁ f₂ s) : RightInvOn f' f₂ t := LeftInvOn.congr_left h₁ hg heq theorem surjOn (hf : RightInvOn f' f t) (hf' : MapsTo f' t s) : SurjOn f s t := LeftInvOn.surjOn hf hf' theorem mapsTo (h : RightInvOn f' f t) (hf : SurjOn f' t s) : MapsTo f s t := LeftInvOn.mapsTo h hf lemma _root_.Set.rightInvOn_id (s : Set α) : RightInvOn id id s := fun _ _ ↦ rfl theorem comp (hf : RightInvOn f' f t) (hg : RightInvOn g' g p) (g'pt : MapsTo g' p t) : RightInvOn (f' ∘ g') (g ∘ f) p := LeftInvOn.comp hg hf g'pt theorem mono (hf : RightInvOn f' f t) (ht : t₁ ⊆ t) : RightInvOn f' f t₁ := LeftInvOn.mono hf ht end RightInvOn theorem InjOn.rightInvOn_of_leftInvOn (hf : InjOn f s) (hf' : LeftInvOn f f' t) (h₁ : MapsTo f s t) (h₂ : MapsTo f' t s) : RightInvOn f f' s := fun _ h => hf (h₂ <| h₁ h) h (hf' (h₁ h)) theorem eqOn_of_leftInvOn_of_rightInvOn (h₁ : LeftInvOn f₁' f s) (h₂ : RightInvOn f₂' f t) (h : MapsTo f₂' t s) : EqOn f₁' f₂' t := fun y hy => calc f₁' y = (f₁' ∘ f ∘ f₂') y := congr_arg f₁' (h₂ hy).symm _ = f₂' y := h₁ (h hy) theorem SurjOn.leftInvOn_of_rightInvOn (hf : SurjOn f s t) (hf' : RightInvOn f f' s) : LeftInvOn f f' t := fun y hy => by let ⟨x, hx, heq⟩ := hf hy rw [← heq, hf' hx] end RightInvOn /-! ### Two-side inverses -/ namespace InvOn lemma _root_.Set.invOn_id (s : Set α) : InvOn id id s s := ⟨s.leftInvOn_id, s.rightInvOn_id⟩ lemma comp (hf : InvOn f' f s t) (hg : InvOn g' g t p) (fst : MapsTo f s t) (g'pt : MapsTo g' p t) : InvOn (f' ∘ g') (g ∘ f) s p := ⟨hf.1.comp hg.1 fst, hf.2.comp hg.2 g'pt⟩ @[symm] theorem symm (h : InvOn f' f s t) : InvOn f f' t s := ⟨h.right, h.left⟩ theorem mono (h : InvOn f' f s t) (hs : s₁ ⊆ s) (ht : t₁ ⊆ t) : InvOn f' f s₁ t₁ := ⟨h.1.mono hs, h.2.mono ht⟩ /-- If functions `f'` and `f` are inverse on `s` and `t`, `f` maps `s` into `t`, and `f'` maps `t` into `s`, then `f` is a bijection between `s` and `t`. The `mapsTo` arguments can be deduced from `surjOn` statements using `LeftInvOn.mapsTo` and `RightInvOn.mapsTo`. -/ theorem bijOn (h : InvOn f' f s t) (hf : MapsTo f s t) (hf' : MapsTo f' t s) : BijOn f s t := ⟨hf, h.left.injOn, h.right.surjOn hf'⟩ end InvOn end Set /-! ### `invFunOn` is a left/right inverse -/ namespace Function variable {s : Set α} {f : α → β} {a : α} {b : β} /-- Construct the inverse for a function `f` on domain `s`. This function is a right inverse of `f` on `f '' s`. For a computable version, see `Function.Embedding.invOfMemRange`. -/ noncomputable def invFunOn [Nonempty α] (f : α → β) (s : Set α) (b : β) : α := open scoped Classical in if h : ∃ a, a ∈ s ∧ f a = b then Classical.choose h else Classical.choice ‹Nonempty α› variable [Nonempty α] theorem invFunOn_pos (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s ∧ f (invFunOn f s b) = b := by rw [invFunOn, dif_pos h] exact Classical.choose_spec h theorem invFunOn_mem (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s := (invFunOn_pos h).left theorem invFunOn_eq (h : ∃ a ∈ s, f a = b) : f (invFunOn f s b) = b := (invFunOn_pos h).right theorem invFunOn_neg (h : ¬∃ a ∈ s, f a = b) : invFunOn f s b = Classical.choice ‹Nonempty α› := by rw [invFunOn, dif_neg h] @[simp] theorem invFunOn_apply_mem (h : a ∈ s) : invFunOn f s (f a) ∈ s := invFunOn_mem ⟨a, h, rfl⟩ theorem invFunOn_apply_eq (h : a ∈ s) : f (invFunOn f s (f a)) = f a := invFunOn_eq ⟨a, h, rfl⟩ end Function open Function namespace Set variable {s s₁ s₂ : Set α} {t : Set β} {f : α → β} theorem InjOn.leftInvOn_invFunOn [Nonempty α] (h : InjOn f s) : LeftInvOn (invFunOn f s) f s := fun _a ha => h (invFunOn_apply_mem ha) ha (invFunOn_apply_eq ha) theorem InjOn.invFunOn_image [Nonempty α] (h : InjOn f s₂) (ht : s₁ ⊆ s₂) : invFunOn f s₂ '' (f '' s₁) = s₁ := h.leftInvOn_invFunOn.image_image' ht theorem _root_.Function.leftInvOn_invFunOn_of_subset_image_image [Nonempty α] (h : s ⊆ (invFunOn f s) '' (f '' s)) : LeftInvOn (invFunOn f s) f s := fun x hx ↦ by obtain ⟨-, ⟨x, hx', rfl⟩, rfl⟩ := h hx rw [invFunOn_apply_eq (f := f) hx'] theorem injOn_iff_invFunOn_image_image_eq_self [Nonempty α] : InjOn f s ↔ (invFunOn f s) '' (f '' s) = s := ⟨fun h ↦ h.invFunOn_image Subset.rfl, fun h ↦ (Function.leftInvOn_invFunOn_of_subset_image_image h.symm.subset).injOn⟩ theorem _root_.Function.invFunOn_injOn_image [Nonempty α] (f : α → β) (s : Set α) : Set.InjOn (invFunOn f s) (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨x', hx', rfl⟩ he rw [← invFunOn_apply_eq (f := f) hx, he, invFunOn_apply_eq (f := f) hx'] theorem _root_.Function.invFunOn_image_image_subset [Nonempty α] (f : α → β) (s : Set α) : (invFunOn f s) '' (f '' s) ⊆ s := by rintro _ ⟨_, ⟨x,hx,rfl⟩, rfl⟩; exact invFunOn_apply_mem hx theorem SurjOn.rightInvOn_invFunOn [Nonempty α] (h : SurjOn f s t) : RightInvOn (invFunOn f s) f t := fun _y hy => invFunOn_eq <| h hy theorem BijOn.invOn_invFunOn [Nonempty α] (h : BijOn f s t) : InvOn (invFunOn f s) f s t := ⟨h.injOn.leftInvOn_invFunOn, h.surjOn.rightInvOn_invFunOn⟩ theorem SurjOn.invOn_invFunOn [Nonempty α] (h : SurjOn f s t) : InvOn (invFunOn f s) f (invFunOn f s '' t) t := by refine ⟨?_, h.rightInvOn_invFunOn⟩ rintro _ ⟨y, hy, rfl⟩ rw [h.rightInvOn_invFunOn hy] theorem SurjOn.mapsTo_invFunOn [Nonempty α] (h : SurjOn f s t) : MapsTo (invFunOn f s) t s := fun _y hy => mem_preimage.2 <| invFunOn_mem <| h hy /-- This lemma is a special case of `rightInvOn_invFunOn.image_image'`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image_of_subset [Nonempty α] {r : Set β} (hf : SurjOn f s t) (hrt : r ⊆ t) : f '' (f.invFunOn s '' r) = r := hf.rightInvOn_invFunOn.image_image' hrt /-- This lemma is a special case of `rightInvOn_invFunOn.image_image`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image [Nonempty α] (hf : SurjOn f s t) : f '' (f.invFunOn s '' t) = t := hf.rightInvOn_invFunOn.image_image theorem SurjOn.bijOn_subset [Nonempty α] (h : SurjOn f s t) : BijOn f (invFunOn f s '' t) t := by refine h.invOn_invFunOn.bijOn ?_ (mapsTo_image _ _) rintro _ ⟨y, hy, rfl⟩ rwa [h.rightInvOn_invFunOn hy] theorem surjOn_iff_exists_bijOn_subset : SurjOn f s t ↔ ∃ s' ⊆ s, BijOn f s' t := by constructor · rcases eq_empty_or_nonempty t with (rfl | ht) · exact fun _ => ⟨∅, empty_subset _, bijOn_empty f⟩ · intro h haveI : Nonempty α := ⟨Classical.choose (h.comap_nonempty ht)⟩ exact ⟨_, h.mapsTo_invFunOn.image_subset, h.bijOn_subset⟩ · rintro ⟨s', hs', hfs'⟩ exact hfs'.surjOn.mono hs' (Subset.refl _) alias ⟨SurjOn.exists_bijOn_subset, _⟩ := Set.surjOn_iff_exists_bijOn_subset variable (f s) lemma exists_subset_bijOn : ∃ s' ⊆ s, BijOn f s' (f '' s) := surjOn_iff_exists_bijOn_subset.mp (surjOn_image f s) lemma exists_image_eq_and_injOn : ∃ u, f '' u = f '' s ∧ InjOn f u := let ⟨u, _, hfu⟩ := exists_subset_bijOn s f ⟨u, hfu.image_eq, hfu.injOn⟩ variable {f s} lemma exists_image_eq_injOn_of_subset_range (ht : t ⊆ range f) : ∃ s, f '' s = t ∧ InjOn f s := image_preimage_eq_of_subset ht ▸ exists_image_eq_and_injOn _ _ /-- If `f` maps `s` bijectively to `t` and a set `t'` is contained in the image of some `s₁ ⊇ s`, then `s₁` has a subset containing `s` that `f` maps bijectively to `t'`. -/ theorem BijOn.exists_extend_of_subset {t' : Set β} (h : BijOn f s t) (hss₁ : s ⊆ s₁) (htt' : t ⊆ t') (ht' : SurjOn f s₁ t') : ∃ s', s ⊆ s' ∧ s' ⊆ s₁ ∧ Set.BijOn f s' t' := by obtain ⟨r, hrss, hbij⟩ := exists_subset_bijOn ((s₁ ∩ f ⁻¹' t') \ f ⁻¹' t) f rw [image_diff_preimage, image_inter_preimage] at hbij refine ⟨s ∪ r, subset_union_left, ?_, ?_, ?_, fun y hyt' ↦ ?_⟩ · exact union_subset hss₁ <| hrss.trans <| diff_subset.trans inter_subset_left · rw [mapsTo', image_union, hbij.image_eq, h.image_eq, union_subset_iff] exact ⟨htt', diff_subset.trans inter_subset_right⟩ · rw [injOn_union, and_iff_right h.injOn, and_iff_right hbij.injOn] · refine fun x hxs y hyr hxy ↦ (hrss hyr).2 ?_ rw [← h.image_eq] exact ⟨x, hxs, hxy⟩ exact (subset_diff.1 hrss).2.symm.mono_left h.mapsTo rw [image_union, h.image_eq, hbij.image_eq, union_diff_self] exact .inr ⟨ht' hyt', hyt'⟩ /-- If `f` maps `s` bijectively to `t`, and `t'` is a superset of `t` contained in the range of `f`, then `f` maps some superset of `s` bijectively to `t'`. -/ theorem BijOn.exists_extend {t' : Set β} (h : BijOn f s t) (htt' : t ⊆ t') (ht' : t' ⊆ range f) : ∃ s', s ⊆ s' ∧ BijOn f s' t' := by simpa using h.exists_extend_of_subset (subset_univ s) htt' (by simpa [SurjOn]) theorem InjOn.exists_subset_injOn_subset_range_eq {r : Set α} (hinj : InjOn f r) (hrs : r ⊆ s) : ∃ u : Set α, r ⊆ u ∧ u ⊆ s ∧ f '' u = f '' s ∧ InjOn f u := by obtain ⟨u, hru, hus, h⟩ := hinj.bijOn_image.exists_extend_of_subset hrs (image_subset f hrs) Subset.rfl exact ⟨u, hru, hus, h.image_eq, h.injOn⟩ theorem preimage_invFun_of_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∈ s) : invFun f ⁻¹' s = f '' s ∪ (range f)ᶜ := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · simp only [mem_preimage, mem_union, mem_compl_iff, mem_range_self, not_true, or_false, leftInverse_invFun hf _, hf.mem_set_image] · simp only [mem_preimage, invFun_neg hx, h, hx, mem_union, mem_compl_iff, not_false_iff, or_true] theorem preimage_invFun_of_not_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∉ s) : invFun f ⁻¹' s = f '' s := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · rw [mem_preimage, leftInverse_invFun hf, hf.mem_set_image] · have : x ∉ f '' s := fun h' => hx (image_subset_range _ _ h') simp only [mem_preimage, invFun_neg hx, h, this] lemma BijOn.symm {g : β → α} (h : InvOn f g t s) (hf : BijOn f s t) : BijOn g t s := ⟨h.2.mapsTo hf.surjOn, h.1.injOn, h.2.surjOn hf.mapsTo⟩ lemma bijOn_comm {g : β → α} (h : InvOn f g t s) : BijOn f s t ↔ BijOn g t s := ⟨BijOn.symm h, BijOn.symm h.symm⟩ end Set namespace Function open Set variable {fa : α → α} {fb : β → β} {f : α → β} {g : β → γ} {s t : Set α} theorem Injective.comp_injOn (hg : Injective g) (hf : s.InjOn f) : s.InjOn (g ∘ f) := hg.injOn.comp hf (mapsTo_univ _ _) theorem Surjective.surjOn (hf : Surjective f) (s : Set β) : SurjOn f univ s := (surjective_iff_surjOn_univ.1 hf).mono (Subset.refl _) (subset_univ _) theorem LeftInverse.leftInvOn {g : β → α} (h : LeftInverse f g) (s : Set β) : LeftInvOn f g s := fun x _ => h x theorem RightInverse.rightInvOn {g : β → α} (h : RightInverse f g) (s : Set α) : RightInvOn f g s := fun x _ => h x theorem LeftInverse.rightInvOn_range {g : β → α} (h : LeftInverse f g) : RightInvOn f g (range g) := forall_mem_range.2 fun i => congr_arg g (h i) namespace Semiconj theorem mapsTo_image (h : Semiconj f fa fb) (ha : MapsTo fa s t) : MapsTo fb (f '' s) (f '' t) := fun _y ⟨x, hx, hy⟩ => hy ▸ ⟨fa x, ha hx, h x⟩ theorem mapsTo_image_right {t : Set β} (h : Semiconj f fa fb) (hst : MapsTo f s t) : MapsTo f (fa '' s) (fb '' t) := mapsTo_image_iff.2 fun x hx ↦ ⟨f x, hst hx, (h x).symm⟩ theorem mapsTo_range (h : Semiconj f fa fb) : MapsTo fb (range f) (range f) := fun _y ⟨x, hy⟩ => hy ▸ ⟨fa x, h x⟩ theorem surjOn_image (h : Semiconj f fa fb) (ha : SurjOn fa s t) : SurjOn fb (f '' s) (f '' t) := by rintro y ⟨x, hxt, rfl⟩ rcases ha hxt with ⟨x, hxs, rfl⟩ rw [h x] exact mem_image_of_mem _ (mem_image_of_mem _ hxs) theorem surjOn_range (h : Semiconj f fa fb) (ha : Surjective fa) : SurjOn fb (range f) (range f) := by rw [← image_univ] exact h.surjOn_image (ha.surjOn univ) theorem injOn_image (h : Semiconj f fa fb) (ha : InjOn fa s) (hf : InjOn f (fa '' s)) : InjOn fb (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ H simp only [← h.eq] at H exact congr_arg f (ha hx hy <| hf (mem_image_of_mem fa hx) (mem_image_of_mem fa hy) H) theorem injOn_range (h : Semiconj f fa fb) (ha : Injective fa) (hf : InjOn f (range fa)) : InjOn fb (range f) := by rw [← image_univ] at * exact h.injOn_image ha.injOn hf theorem bijOn_image (h : Semiconj f fa fb) (ha : BijOn fa s t) (hf : InjOn f t) : BijOn fb (f '' s) (f '' t) := ⟨h.mapsTo_image ha.mapsTo, h.injOn_image ha.injOn (ha.image_eq.symm ▸ hf), h.surjOn_image ha.surjOn⟩ theorem bijOn_range (h : Semiconj f fa fb) (ha : Bijective fa) (hf : Injective f) : BijOn fb (range f) (range f) := by rw [← image_univ] exact h.bijOn_image (bijective_iff_bijOn_univ.1 ha) hf.injOn theorem mapsTo_preimage (h : Semiconj f fa fb) {s t : Set β} (hb : MapsTo fb s t) : MapsTo fa (f ⁻¹' s) (f ⁻¹' t) := fun x hx => by simp only [mem_preimage, h x, hb hx] theorem injOn_preimage (h : Semiconj f fa fb) {s : Set β} (hb : InjOn fb s) (hf : InjOn f (f ⁻¹' s)) : InjOn fa (f ⁻¹' s) := by intro x hx y hy H have := congr_arg f H rw [h.eq, h.eq] at this exact hf hx hy (hb hx hy this) end Semiconj theorem update_comp_eq_of_not_mem_range' {α : Sort*} {β : Type*} {γ : β → Sort*} [DecidableEq β] (g : ∀ b, γ b) {f : α → β} {i : β} (a : γ i) (h : i ∉ Set.range f) : (fun j => update g i a (f j)) = fun j => g (f j) := (update_comp_eq_of_forall_ne' _ _) fun x hx => h ⟨x, hx⟩ /-- Non-dependent version of `Function.update_comp_eq_of_not_mem_range'` -/ theorem update_comp_eq_of_not_mem_range {α : Sort*} {β : Type*} {γ : Sort*} [DecidableEq β] (g : β → γ) {f : α → β} {i : β} (a : γ) (h : i ∉ Set.range f) : update g i a ∘ f = g ∘ f := update_comp_eq_of_not_mem_range' g a h theorem insert_injOn (s : Set α) : sᶜ.InjOn fun a => insert a s := fun _a ha _ _ => (insert_inj ha).1 lemma apply_eq_of_range_eq_singleton {f : α → β} {b : β} (h : range f = {b}) (a : α) : f a = b := by simpa only [h, mem_singleton_iff] using mem_range_self (f := f) a end Function /-! ### Equivalences, permutations -/ namespace Set variable {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} {g g₁ g₂ : Perm α} {s t : Set α} protected lemma MapsTo.extendDomain (h : MapsTo g s t) : MapsTo (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩; exact ⟨_, h ha, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩ protected lemma SurjOn.extendDomain (h : SurjOn g s t) : SurjOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩ obtain ⟨b, hb, rfl⟩ := h ha exact ⟨_, ⟨_, hb, rfl⟩, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩ protected lemma BijOn.extendDomain (h : BijOn g s t) : BijOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := ⟨h.mapsTo.extendDomain, (g.extendDomain f).injective.injOn, h.surjOn.extendDomain⟩ protected lemma LeftInvOn.extendDomain (h : LeftInvOn g₁ g₂ s) : LeftInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) := by rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha] protected lemma RightInvOn.extendDomain (h : RightInvOn g₁ g₂ t) : RightInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha] protected lemma InvOn.extendDomain (h : InvOn g₁ g₂ s t) : InvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := ⟨h.1.extendDomain, h.2.extendDomain⟩ end Set namespace Set variable {α₁ α₂ β₁ β₂ : Type*} {s₁ : Set α₁} {s₂ : Set α₂} {t₁ : Set β₁} {t₂ : Set β₂} {f₁ : α₁ → β₁} {f₂ : α₂ → β₂} {g₁ : β₁ → α₁} {g₂ : β₂ → α₂} lemma InjOn.prodMap (h₁ : s₁.InjOn f₁) (h₂ : s₂.InjOn f₂) : (s₁ ×ˢ s₂).InjOn fun x ↦ (f₁ x.1, f₂ x.2) := fun x hx y hy ↦ by simp_rw [Prod.ext_iff]; exact And.imp (h₁ hx.1 hy.1) (h₂ hx.2 hy.2) lemma SurjOn.prodMap (h₁ : SurjOn f₁ s₁ t₁) (h₂ : SurjOn f₂ s₂ t₂) : SurjOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := by rintro x hx obtain ⟨a₁, ha₁, hx₁⟩ := h₁ hx.1 obtain ⟨a₂, ha₂, hx₂⟩ := h₂ hx.2 exact ⟨(a₁, a₂), ⟨ha₁, ha₂⟩, Prod.ext hx₁ hx₂⟩ lemma MapsTo.prodMap (h₁ : MapsTo f₁ s₁ t₁) (h₂ : MapsTo f₂ s₂ t₂) : MapsTo (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := fun _x hx ↦ ⟨h₁ hx.1, h₂ hx.2⟩ lemma BijOn.prodMap (h₁ : BijOn f₁ s₁ t₁) (h₂ : BijOn f₂ s₂ t₂) : BijOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := ⟨h₁.mapsTo.prodMap h₂.mapsTo, h₁.injOn.prodMap h₂.injOn, h₁.surjOn.prodMap h₂.surjOn⟩ lemma LeftInvOn.prodMap (h₁ : LeftInvOn g₁ f₁ s₁) (h₂ : LeftInvOn g₂ f₂ s₂) : LeftInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) := fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2) lemma RightInvOn.prodMap (h₁ : RightInvOn g₁ f₁ t₁) (h₂ : RightInvOn g₂ f₂ t₂) : RightInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (t₁ ×ˢ t₂) := fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2) lemma InvOn.prodMap (h₁ : InvOn g₁ f₁ s₁ t₁) (h₂ : InvOn g₂ f₂ s₂ t₂) : InvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := ⟨h₁.1.prodMap h₂.1, h₁.2.prodMap h₂.2⟩ end Set namespace Equiv open Set variable (e : α ≃ β) {s : Set α} {t : Set β} lemma bijOn' (h₁ : MapsTo e s t) (h₂ : MapsTo e.symm t s) : BijOn e s t := ⟨h₁, e.injective.injOn, fun b hb ↦ ⟨e.symm b, h₂ hb, apply_symm_apply _ _⟩⟩ protected lemma bijOn (h : ∀ a, e a ∈ t ↔ a ∈ s) : BijOn e s t := e.bijOn' (fun _ ↦ (h _).2) fun b hb ↦ (h _).1 <| by rwa [apply_symm_apply] lemma invOn : InvOn e e.symm t s := ⟨e.rightInverse_symm.leftInvOn _, e.leftInverse_symm.leftInvOn _⟩ lemma bijOn_image : BijOn e s (e '' s) := e.injective.injOn.bijOn_image lemma bijOn_symm_image : BijOn e.symm (e '' s) s := e.bijOn_image.symm e.invOn variable {e} @[simp] lemma bijOn_symm : BijOn e.symm t s ↔ BijOn e s t := bijOn_comm e.symm.invOn alias ⟨_root_.Set.BijOn.of_equiv_symm, _root_.Set.BijOn.equiv_symm⟩ := bijOn_symm variable [DecidableEq α] {a b : α} lemma bijOn_swap (ha : a ∈ s) (hb : b ∈ s) : BijOn (swap a b) s s := (swap a b).bijOn fun x ↦ by obtain rfl | hxa := eq_or_ne x a <;> obtain rfl | hxb := eq_or_ne x b <;> simp [*, swap_apply_of_ne_of_ne] end Equiv
Mathlib/Data/Set/Function.lean
1,479
1,493
/- 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.IsPrimePow import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Ring.Int import Mathlib.Algebra.Ring.CharZero import Mathlib.Data.Nat.Cast.Order.Ring import Mathlib.Data.Nat.PrimeFin import Mathlib.Order.Interval.Finset.Nat /-! # Divisor Finsets This file defines sets of divisors of a natural number. This is particularly useful as background for defining Dirichlet convolution. ## Main Definitions Let `n : ℕ`. All of the following definitions are in the `Nat` namespace: * `divisors n` is the `Finset` of natural numbers that divide `n`. * `properDivisors n` is the `Finset` of natural numbers that divide `n`, other than `n`. * `divisorsAntidiagonal n` is the `Finset` of pairs `(x,y)` such that `x * y = n`. * `Perfect n` is true when `n` is positive and the sum of `properDivisors n` is `n`. ## Conventions Since `0` has infinitely many divisors, none of the definitions in this file make sense for it. Therefore we adopt the convention that `Nat.divisors 0`, `Nat.properDivisors 0`, `Nat.divisorsAntidiagonal 0` and `Int.divisorsAntidiag 0` are all `∅`. ## Tags divisors, perfect numbers -/ open Finset namespace Nat variable (n : ℕ) /-- `divisors n` is the `Finset` of divisors of `n`. By convention, we set `divisors 0 = ∅`. -/ def divisors : Finset ℕ := {d ∈ Ico 1 (n + 1) | d ∣ n} /-- `properDivisors n` is the `Finset` of divisors of `n`, other than `n`. By convention, we set `properDivisors 0 = ∅`. -/ def properDivisors : Finset ℕ := {d ∈ Ico 1 n | d ∣ n} /-- Pairs of divisors of a natural number as a finset. `n.divisorsAntidiagonal` is the finset of pairs `(a, b) : ℕ × ℕ` such that `a * b = n`. By convention, we set `Nat.divisorsAntidiagonal 0 = ∅`. O(n). -/ def divisorsAntidiagonal : Finset (ℕ × ℕ) := (Icc 1 n).filterMap (fun x ↦ let y := n / x; if x * y = n then some (x, y) else none) fun x₁ x₂ (x, y) hx₁ hx₂ ↦ by aesop /-- Pairs of divisors of a natural number, as a list. `n.divisorsAntidiagonalList` is the list of pairs `(a, b) : ℕ × ℕ` such that `a * b = n`, ordered by increasing `a`. By convention, we set `Nat.divisorsAntidiagonalList 0 = []`. -/ def divisorsAntidiagonalList (n : ℕ) : List (ℕ × ℕ) := (List.range' 1 n).filterMap (fun x ↦ let y := n / x; if x * y = n then some (x, y) else none) variable {n} @[simp] theorem filter_dvd_eq_divisors (h : n ≠ 0) : {d ∈ range n.succ | d ∣ n} = n.divisors := by ext simp only [divisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self] exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt) @[simp] theorem filter_dvd_eq_properDivisors (h : n ≠ 0) : {d ∈ range n | d ∣ n} = n.properDivisors := by ext simp only [properDivisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self] exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt) theorem properDivisors.not_self_mem : ¬n ∈ properDivisors n := by simp [properDivisors] @[simp] theorem mem_properDivisors {m : ℕ} : n ∈ properDivisors m ↔ n ∣ m ∧ n < m := by rcases eq_or_ne m 0 with (rfl | hm); · simp [properDivisors] simp only [and_comm, ← filter_dvd_eq_properDivisors hm, mem_filter, mem_range] theorem insert_self_properDivisors (h : n ≠ 0) : insert n (properDivisors n) = divisors n := by rw [divisors, properDivisors, Ico_succ_right_eq_insert_Ico (one_le_iff_ne_zero.2 h), Finset.filter_insert, if_pos (dvd_refl n)] theorem cons_self_properDivisors (h : n ≠ 0) : cons n (properDivisors n) properDivisors.not_self_mem = divisors n := by rw [cons_eq_insert, insert_self_properDivisors h] @[simp] theorem mem_divisors {m : ℕ} : n ∈ divisors m ↔ n ∣ m ∧ m ≠ 0 := by rcases eq_or_ne m 0 with (rfl | hm); · simp [divisors] simp only [hm, Ne, not_false_iff, and_true, ← filter_dvd_eq_divisors hm, mem_filter, mem_range, and_iff_right_iff_imp, Nat.lt_succ_iff] exact le_of_dvd hm.bot_lt theorem one_mem_divisors : 1 ∈ divisors n ↔ n ≠ 0 := by simp theorem mem_divisors_self (n : ℕ) (h : n ≠ 0) : n ∈ n.divisors := mem_divisors.2 ⟨dvd_rfl, h⟩ theorem dvd_of_mem_divisors {m : ℕ} (h : n ∈ divisors m) : n ∣ m := by cases m · apply dvd_zero · simp [mem_divisors.1 h] @[simp] theorem mem_divisorsAntidiagonal {x : ℕ × ℕ} : x ∈ divisorsAntidiagonal n ↔ x.fst * x.snd = n ∧ n ≠ 0 := by obtain ⟨a, b⟩ := x simp only [divisorsAntidiagonal, mul_div_eq_iff_dvd, mem_filterMap, mem_Icc, one_le_iff_ne_zero, Option.ite_none_right_eq_some, Option.some.injEq, Prod.ext_iff, and_left_comm, exists_eq_left] constructor · rintro ⟨han, ⟨ha, han'⟩, rfl⟩ simp [Nat.mul_div_eq_iff_dvd, han] omega · rintro ⟨rfl, hab⟩ rw [mul_ne_zero_iff] at hab simpa [hab.1, hab.2] using Nat.le_mul_of_pos_right _ hab.2.bot_lt @[simp] lemma divisorsAntidiagonalList_zero : divisorsAntidiagonalList 0 = [] := rfl @[simp] lemma divisorsAntidiagonalList_one : divisorsAntidiagonalList 1 = [(1, 1)] := rfl @[simp] lemma toFinset_divisorsAntidiagonalList {n : ℕ} : n.divisorsAntidiagonalList.toFinset = n.divisorsAntidiagonal := by rw [divisorsAntidiagonalList, divisorsAntidiagonal, List.toFinset_filterMap (f_inj := by aesop), List.toFinset_range'_1_1] lemma sorted_divisorsAntidiagonalList_fst {n : ℕ} : n.divisorsAntidiagonalList.Sorted (·.fst < ·.fst) := by refine (List.sorted_lt_range' _ _ Nat.one_ne_zero).filterMap fun a b c d h h' ha => ?_ rw [Option.ite_none_right_eq_some, Option.some.injEq] at h h' simpa [← h.right, ← h'.right] lemma sorted_divisorsAntidiagonalList_snd {n : ℕ} : n.divisorsAntidiagonalList.Sorted (·.snd > ·.snd) := by obtain rfl | hn := eq_or_ne n 0 · simp refine (List.sorted_lt_range' _ _ Nat.one_ne_zero).filterMap ?_ simp only [Option.ite_none_right_eq_some, Option.some.injEq, gt_iff_lt, and_imp, Prod.forall, Prod.mk.injEq] rintro a b _ _ _ _ ha rfl rfl hb rfl rfl hab rwa [Nat.div_lt_div_left hn ⟨_, hb.symm⟩ ⟨_, ha.symm⟩] lemma nodup_divisorsAntidiagonalList {n : ℕ} : n.divisorsAntidiagonalList.Nodup := have : IsIrrefl (ℕ × ℕ) (·.fst < ·.fst) := ⟨by simp⟩ sorted_divisorsAntidiagonalList_fst.nodup /-- The `Finset` and `List` versions agree by definition. -/ @[simp] theorem val_divisorsAntidiagonal (n : ℕ) : (divisorsAntidiagonal n).val = divisorsAntidiagonalList n := rfl @[simp] lemma mem_divisorsAntidiagonalList {n : ℕ} {a : ℕ × ℕ} : a ∈ n.divisorsAntidiagonalList ↔ a.1 * a.2 = n ∧ n ≠ 0 := by rw [← List.mem_toFinset, toFinset_divisorsAntidiagonalList, mem_divisorsAntidiagonal] @[simp high] lemma swap_mem_divisorsAntidiagonalList {a : ℕ × ℕ} : a.swap ∈ n.divisorsAntidiagonalList ↔ a ∈ n.divisorsAntidiagonalList := by simp [mul_comm] lemma reverse_divisorsAntidiagonalList (n : ℕ) : n.divisorsAntidiagonalList.reverse = n.divisorsAntidiagonalList.map .swap := by have : IsAsymm (ℕ × ℕ) (·.snd < ·.snd) := ⟨fun _ _ ↦ lt_asymm⟩ refine List.eq_of_perm_of_sorted ?_ sorted_divisorsAntidiagonalList_snd.reverse <| sorted_divisorsAntidiagonalList_fst.map _ fun _ _ ↦ id simp [List.reverse_perm', List.perm_ext_iff_of_nodup nodup_divisorsAntidiagonalList (nodup_divisorsAntidiagonalList.map Prod.swap_injective), mul_comm] lemma ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) : p.1 ≠ 0 ∧ p.2 ≠ 0 := by obtain ⟨hp₁, hp₂⟩ := Nat.mem_divisorsAntidiagonal.mp hp exact mul_ne_zero_iff.mp (hp₁.symm ▸ hp₂) lemma left_ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) : p.1 ≠ 0 := (ne_zero_of_mem_divisorsAntidiagonal hp).1 lemma right_ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) : p.2 ≠ 0 := (ne_zero_of_mem_divisorsAntidiagonal hp).2 theorem divisor_le {m : ℕ} : n ∈ divisors m → n ≤ m := by rcases m with - | m · simp · simp only [mem_divisors, Nat.succ_ne_zero m, and_true, Ne, not_false_iff] exact Nat.le_of_dvd (Nat.succ_pos m) theorem divisors_subset_of_dvd {m : ℕ} (hzero : n ≠ 0) (h : m ∣ n) : divisors m ⊆ divisors n := Finset.subset_iff.2 fun _x hx => Nat.mem_divisors.mpr ⟨(Nat.mem_divisors.mp hx).1.trans h, hzero⟩ theorem card_divisors_le_self (n : ℕ) : #n.divisors ≤ n := calc _ ≤ #(Ico 1 (n + 1)) := by apply card_le_card simp only [divisors, filter_subset] _ = n := by rw [card_Ico, add_tsub_cancel_right] theorem divisors_subset_properDivisors {m : ℕ} (hzero : n ≠ 0) (h : m ∣ n) (hdiff : m ≠ n) : divisors m ⊆ properDivisors n := by apply Finset.subset_iff.2 intro x hx exact Nat.mem_properDivisors.2 ⟨(Nat.mem_divisors.1 hx).1.trans h, lt_of_le_of_lt (divisor_le hx) (lt_of_le_of_ne (divisor_le (Nat.mem_divisors.2 ⟨h, hzero⟩)) hdiff)⟩ lemma divisors_filter_dvd_of_dvd {n m : ℕ} (hn : n ≠ 0) (hm : m ∣ n) : {d ∈ n.divisors | d ∣ m} = m.divisors := by ext k simp_rw [mem_filter, mem_divisors] exact ⟨fun ⟨_, hkm⟩ ↦ ⟨hkm, ne_zero_of_dvd_ne_zero hn hm⟩, fun ⟨hk, _⟩ ↦ ⟨⟨hk.trans hm, hn⟩, hk⟩⟩ @[simp] theorem divisors_zero : divisors 0 = ∅ := by ext simp @[simp] theorem properDivisors_zero : properDivisors 0 = ∅ := by ext simp @[simp] lemma nonempty_divisors : (divisors n).Nonempty ↔ n ≠ 0 := ⟨fun ⟨m, hm⟩ hn ↦ by simp [hn] at hm, fun hn ↦ ⟨1, one_mem_divisors.2 hn⟩⟩ @[simp] lemma divisors_eq_empty : divisors n = ∅ ↔ n = 0 := not_nonempty_iff_eq_empty.symm.trans nonempty_divisors.not_left theorem properDivisors_subset_divisors : properDivisors n ⊆ divisors n := filter_subset_filter _ <| Ico_subset_Ico_right n.le_succ @[simp] theorem divisors_one : divisors 1 = {1} := by ext simp @[simp] theorem properDivisors_one : properDivisors 1 = ∅ := by rw [properDivisors, Ico_self, filter_empty] theorem pos_of_mem_divisors {m : ℕ} (h : m ∈ n.divisors) : 0 < m := by cases m · rw [mem_divisors, zero_dvd_iff (a := n)] at h cases h.2 h.1 apply Nat.succ_pos theorem pos_of_mem_properDivisors {m : ℕ} (h : m ∈ n.properDivisors) : 0 < m := pos_of_mem_divisors (properDivisors_subset_divisors h) theorem one_mem_properDivisors_iff_one_lt : 1 ∈ n.properDivisors ↔ 1 < n := by rw [mem_properDivisors, and_iff_right (one_dvd _)] @[simp] lemma sup_divisors_id (n : ℕ) : n.divisors.sup id = n := by refine le_antisymm (Finset.sup_le fun _ ↦ divisor_le) ?_ rcases Decidable.eq_or_ne n 0 with rfl | hn · apply zero_le · exact Finset.le_sup (f := id) <| mem_divisors_self n hn lemma one_lt_of_mem_properDivisors {m n : ℕ} (h : m ∈ n.properDivisors) : 1 < n := lt_of_le_of_lt (pos_of_mem_properDivisors h) (mem_properDivisors.1 h).2 lemma one_lt_div_of_mem_properDivisors {m n : ℕ} (h : m ∈ n.properDivisors) : 1 < n / m := by obtain ⟨h_dvd, h_lt⟩ := mem_properDivisors.mp h rwa [Nat.lt_div_iff_mul_lt' h_dvd, mul_one] /-- See also `Nat.mem_properDivisors`. -/ lemma mem_properDivisors_iff_exists {m n : ℕ} (hn : n ≠ 0) : m ∈ n.properDivisors ↔ ∃ k > 1, n = m * k := by refine ⟨fun h ↦ ⟨n / m, one_lt_div_of_mem_properDivisors h, ?_⟩, ?_⟩ · exact (Nat.mul_div_cancel' (mem_properDivisors.mp h).1).symm · rintro ⟨k, hk, rfl⟩ rw [mul_ne_zero_iff] at hn exact mem_properDivisors.mpr ⟨⟨k, rfl⟩, lt_mul_of_one_lt_right (Nat.pos_of_ne_zero hn.1) hk⟩ @[simp] lemma nonempty_properDivisors : n.properDivisors.Nonempty ↔ 1 < n := ⟨fun ⟨_m, hm⟩ ↦ one_lt_of_mem_properDivisors hm, fun hn ↦ ⟨1, one_mem_properDivisors_iff_one_lt.2 hn⟩⟩ @[simp] lemma properDivisors_eq_empty : n.properDivisors = ∅ ↔ n ≤ 1 := by rw [← not_nonempty_iff_eq_empty, nonempty_properDivisors, not_lt] @[simp] theorem divisorsAntidiagonal_zero : divisorsAntidiagonal 0 = ∅ := by ext simp @[simp] theorem divisorsAntidiagonal_one : divisorsAntidiagonal 1 = {(1, 1)} := by ext simp [mul_eq_one, Prod.ext_iff] @[simp high] theorem swap_mem_divisorsAntidiagonal {x : ℕ × ℕ} : x.swap ∈ divisorsAntidiagonal n ↔ x ∈ divisorsAntidiagonal n := by rw [mem_divisorsAntidiagonal, mem_divisorsAntidiagonal, mul_comm, Prod.swap] /-- `Nat.swap_mem_divisorsAntidiagonal` with the LHS in simp normal form. -/ @[deprecated swap_mem_divisorsAntidiagonal (since := "2025-02-17")] theorem swap_mem_divisorsAntidiagonal_aux {x : ℕ × ℕ} : x.snd * x.fst = n ∧ ¬n = 0 ↔ x ∈ divisorsAntidiagonal n := by rw [mem_divisorsAntidiagonal, mul_comm] lemma prodMk_mem_divisorsAntidiag {x y : ℕ} (hn : n ≠ 0) : (x, y) ∈ n.divisorsAntidiagonal ↔ x * y = n := by simp [hn] theorem fst_mem_divisors_of_mem_antidiagonal {x : ℕ × ℕ} (h : x ∈ divisorsAntidiagonal n) : x.fst ∈ divisors n := by rw [mem_divisorsAntidiagonal] at h simp [Dvd.intro _ h.1, h.2] theorem snd_mem_divisors_of_mem_antidiagonal {x : ℕ × ℕ} (h : x ∈ divisorsAntidiagonal n) : x.snd ∈ divisors n := by rw [mem_divisorsAntidiagonal] at h simp [Dvd.intro_left _ h.1, h.2] @[simp] theorem map_swap_divisorsAntidiagonal : (divisorsAntidiagonal n).map (Equiv.prodComm _ _).toEmbedding = divisorsAntidiagonal n := by rw [← coe_inj, coe_map, Equiv.coe_toEmbedding, Equiv.coe_prodComm, Set.image_swap_eq_preimage_swap] ext exact swap_mem_divisorsAntidiagonal @[simp] theorem image_fst_divisorsAntidiagonal : (divisorsAntidiagonal n).image Prod.fst = divisors n := by ext simp [Dvd.dvd, @eq_comm _ n (_ * _)] @[simp] theorem image_snd_divisorsAntidiagonal : (divisorsAntidiagonal n).image Prod.snd = divisors n := by rw [← map_swap_divisorsAntidiagonal, map_eq_image, image_image] exact image_fst_divisorsAntidiagonal theorem map_div_right_divisors : n.divisors.map ⟨fun d => (d, n / d), fun _ _ => congr_arg Prod.fst⟩ = n.divisorsAntidiagonal := by ext ⟨d, nd⟩ simp only [mem_map, mem_divisorsAntidiagonal, Function.Embedding.coeFn_mk, mem_divisors, Prod.ext_iff, exists_prop, and_left_comm, exists_eq_left] constructor · rintro ⟨⟨⟨k, rfl⟩, hn⟩, rfl⟩ rw [Nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt] exact ⟨rfl, hn⟩ · rintro ⟨rfl, hn⟩ exact ⟨⟨dvd_mul_right _ _, hn⟩, Nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt⟩ theorem map_div_left_divisors : n.divisors.map ⟨fun d => (n / d, d), fun _ _ => congr_arg Prod.snd⟩ = n.divisorsAntidiagonal := by apply Finset.map_injective (Equiv.prodComm _ _).toEmbedding ext rw [map_swap_divisorsAntidiagonal, ← map_div_right_divisors, Finset.map_map] simp theorem sum_divisors_eq_sum_properDivisors_add_self : ∑ i ∈ divisors n, i = (∑ i ∈ properDivisors n, i) + n := by rcases Decidable.eq_or_ne n 0 with (rfl | hn) · simp · rw [← cons_self_properDivisors hn, Finset.sum_cons, add_comm] /-- `n : ℕ` is perfect if and only the sum of the proper divisors of `n` is `n` and `n` is positive. -/ def Perfect (n : ℕ) : Prop := ∑ i ∈ properDivisors n, i = n ∧ 0 < n theorem perfect_iff_sum_properDivisors (h : 0 < n) : Perfect n ↔ ∑ i ∈ properDivisors n, i = n := and_iff_left h theorem perfect_iff_sum_divisors_eq_two_mul (h : 0 < n) : Perfect n ↔ ∑ i ∈ divisors n, i = 2 * n := by rw [perfect_iff_sum_properDivisors h, sum_divisors_eq_sum_properDivisors_add_self, two_mul] constructor <;> intro h · rw [h] · apply add_right_cancel h theorem mem_divisors_prime_pow {p : ℕ} (pp : p.Prime) (k : ℕ) {x : ℕ} : x ∈ divisors (p ^ k) ↔ ∃ j ≤ k, x = p ^ j := by
rw [mem_divisors, Nat.dvd_prime_pow pp, and_iff_left (ne_of_gt (pow_pos pp.pos k))] theorem Prime.divisors {p : ℕ} (pp : p.Prime) : divisors p = {1, p} := by ext rw [mem_divisors, dvd_prime pp, and_iff_left pp.ne_zero, Finset.mem_insert, Finset.mem_singleton] theorem Prime.properDivisors {p : ℕ} (pp : p.Prime) : properDivisors p = {1} := by rw [← erase_insert properDivisors.not_self_mem, insert_self_properDivisors pp.ne_zero, pp.divisors, pair_comm, erase_insert fun con => pp.ne_one (mem_singleton.1 con)] theorem divisors_prime_pow {p : ℕ} (pp : p.Prime) (k : ℕ) : divisors (p ^ k) = (Finset.range (k + 1)).map ⟨(p ^ ·), Nat.pow_right_injective pp.two_le⟩ := by ext a rw [mem_divisors_prime_pow pp] simp [Nat.lt_succ, eq_comm] theorem divisors_injective : Function.Injective divisors := Function.LeftInverse.injective sup_divisors_id
Mathlib/NumberTheory/Divisors.lean
396
414
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne -/ import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/ @[pp_nodot] noncomputable def logb (b x : ℝ) : ℝ := log x / log b theorem log_div_log : log x / log b = logb b x := rfl @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] theorem logb_zero_left : logb 0 x = 0 := by simp only [← log_div_log, log_zero, div_zero] @[simp] theorem logb_zero_left_eq_zero : logb 0 = 0 := by ext; rw [logb_zero_left, Pi.zero_apply] theorem logb_one_left : logb 1 x = 0 := by simp only [← log_div_log, log_one, div_zero] @[simp] theorem logb_one_left_eq_zero : logb 1 = 0 := by ext; rw [logb_one_left, Pi.zero_apply] @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b ≠ 0 ∧ b ≠ 1 ∧ b ≠ -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] theorem logb_mul (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] theorem logb_div (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] theorem inv_logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ h₂ theorem inv_logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ h₂ theorem logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ h₂ c, inv_inv] theorem logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ h₂ c, inv_inv] theorem mul_logb {a b c : ℝ} (h₁ : b ≠ 0) (h₂ : b ≠ 1) (h₃ : b ≠ -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel₀ (log_ne_zero.mpr ⟨h₁, h₂, h₃⟩)] theorem div_logb {a b c : ℝ} (h₁ : c ≠ 0) (h₂ : c ≠ 1) (h₃ : c ≠ -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, h₂, h₃⟩ theorem logb_rpow_eq_mul_logb_of_pos (hx : 0 < x) : logb b (x ^ y) = y * logb b x := by rw [logb, log_rpow hx, logb, mul_div_assoc] theorem logb_pow (b x : ℝ) (k : ℕ) : logb b (x ^ k) = k * logb b x := by rw [logb, logb, log_pow, mul_div_assoc] section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b ≠ 1) include b_pos b_ne_one private theorem log_b_ne_zero : log b ≠ 0 := by have b_ne_zero : b ≠ 0 := by linarith have b_ne_minus_one : b ≠ -1 := by linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos]
exact log_b_ne_zero b_pos b_ne_one theorem rpow_logb_eq_abs (hx : x ≠ 0) : b ^ logb b x = |x| := by apply log_injOn_pos
Mathlib/Analysis/SpecialFunctions/Log/Base.lean
126
129
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Moritz Doll -/ import Mathlib.LinearAlgebra.Prod /-! # Partially defined linear maps A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. We define a `SemilatticeInf` with `OrderBot` instance on this, and define three operations: * `mkSpanSingleton` defines a partial linear map defined on the span of a singleton. * `sup` takes two partial linear maps `f`, `g` that agree on the intersection of their domains, and returns the unique partial linear map on `f.domain ⊔ g.domain` that extends both `f` and `g`. * `sSup` takes a `DirectedOn (· ≤ ·)` set of partial linear maps, and returns the unique partial linear map on the `sSup` of their domains that extends all these maps. Moreover, we define * `LinearPMap.graph` is the graph of the partial linear map viewed as a submodule of `E × F`. Partially defined maps are currently used in `Mathlib` to prove Hahn-Banach theorem and its variations. Namely, `LinearPMap.sSup` implies that every chain of `LinearPMap`s is bounded above. They are also the basis for the theory of unbounded operators. -/ universe u v w /-- A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. -/ structure LinearPMap (R : Type u) [Ring R] (E : Type v) [AddCommGroup E] [Module R E] (F : Type w) [AddCommGroup F] [Module R F] where domain : Submodule R E toFun : domain →ₗ[R] F @[inherit_doc] notation:25 E " →ₗ.[" R:25 "] " F:0 => LinearPMap R E F variable {R : Type*} [Ring R] {E : Type*} [AddCommGroup E] [Module R E] {F : Type*} [AddCommGroup F] [Module R F] {G : Type*} [AddCommGroup G] [Module R G] namespace LinearPMap open Submodule @[coe] def toFun' (f : E →ₗ.[R] F) : f.domain → F := f.toFun instance : CoeFun (E →ₗ.[R] F) fun f : E →ₗ.[R] F => f.domain → F := ⟨toFun'⟩ @[simp] theorem toFun_eq_coe (f : E →ₗ.[R] F) (x : f.domain) : f.toFun x = f x := rfl @[ext (iff := false)] theorem ext {f g : E →ₗ.[R] F} (h : f.domain = g.domain) (h' : ∀ ⦃x : E⦄ ⦃hf : x ∈ f.domain⦄ ⦃hg : x ∈ g.domain⦄, f ⟨x, hf⟩ = g ⟨x, hg⟩) : f = g := by rcases f with ⟨f_dom, f⟩ rcases g with ⟨g_dom, g⟩ obtain rfl : f_dom = g_dom := h congr apply LinearMap.ext intro x apply h' /-- A dependent version of `ext`. -/ theorem dExt {f g : E →ₗ.[R] F} (h : f.domain = g.domain) (h' : ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y) : f = g := ext h fun _ _ _ ↦ h' rfl @[simp] theorem map_zero (f : E →ₗ.[R] F) : f 0 = 0 := f.toFun.map_zero theorem ext_iff {f g : E →ₗ.[R] F} : f = g ↔ f.domain = g.domain ∧ ∀ ⦃x : E⦄ ⦃hf : x ∈ f.domain⦄ ⦃hg : x ∈ g.domain⦄, f ⟨x, hf⟩ = g ⟨x, hg⟩ := ⟨by rintro rfl; simp, fun ⟨deq, feq⟩ ↦ ext deq feq⟩ theorem dExt_iff {f g : E →ₗ.[R] F} : f = g ↔ ∃ _domain_eq : f.domain = g.domain, ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y := ⟨fun EQ => EQ ▸ ⟨rfl, fun x y h => by congr exact mod_cast h⟩, fun ⟨deq, feq⟩ => dExt deq feq⟩ theorem ext' {s : Submodule R E} {f g : s →ₗ[R] F} (h : f = g) : mk s f = mk s g := h ▸ rfl theorem map_add (f : E →ₗ.[R] F) (x y : f.domain) : f (x + y) = f x + f y := f.toFun.map_add x y theorem map_neg (f : E →ₗ.[R] F) (x : f.domain) : f (-x) = -f x := f.toFun.map_neg x theorem map_sub (f : E →ₗ.[R] F) (x y : f.domain) : f (x - y) = f x - f y := f.toFun.map_sub x y theorem map_smul (f : E →ₗ.[R] F) (c : R) (x : f.domain) : f (c • x) = c • f x := f.toFun.map_smul c x @[simp] theorem mk_apply (p : Submodule R E) (f : p →ₗ[R] F) (x : p) : mk p f x = f x := rfl /-- The unique `LinearPMap` on `R ∙ x` that sends `x` to `y`. This version works for modules over rings, and requires a proof of `∀ c, c • x = 0 → c • y = 0`. -/ noncomputable def mkSpanSingleton' (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) : E →ₗ.[R] F where domain := R ∙ x toFun := have H : ∀ c₁ c₂ : R, c₁ • x = c₂ • x → c₁ • y = c₂ • y := by intro c₁ c₂ h rw [← sub_eq_zero, ← sub_smul] at h ⊢ exact H _ h { toFun z := Classical.choose (mem_span_singleton.1 z.prop) • y map_add' y z := by rw [← add_smul, H] have (w : R ∙ x) := Classical.choose_spec (mem_span_singleton.1 w.prop) simp only [add_smul, sub_smul, this, ← coe_add] map_smul' c z := by rw [smul_smul, H] have (w : R ∙ x) := Classical.choose_spec (mem_span_singleton.1 w.prop) simp only [mul_smul, this] apply coe_smul } @[simp] theorem domain_mkSpanSingleton (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) : (mkSpanSingleton' x y H).domain = R ∙ x := rfl @[simp] theorem mkSpanSingleton'_apply (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (c : R) (h) : mkSpanSingleton' x y H ⟨c • x, h⟩ = c • y := by dsimp [mkSpanSingleton'] rw [← sub_eq_zero, ← sub_smul] apply H simp only [sub_smul, one_smul, sub_eq_zero] apply Classical.choose_spec (mem_span_singleton.1 h) @[simp] theorem mkSpanSingleton'_apply_self (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (h) : mkSpanSingleton' x y H ⟨x, h⟩ = y := by conv_rhs => rw [← one_smul R y] rw [← mkSpanSingleton'_apply x y H 1 ?_] · congr rw [one_smul] · rwa [one_smul] /-- The unique `LinearPMap` on `span R {x}` that sends a non-zero vector `x` to `y`. This version works for modules over division rings. -/ noncomputable abbrev mkSpanSingleton {K E F : Type*} [DivisionRing K] [AddCommGroup E] [Module K E] [AddCommGroup F] [Module K F] (x : E) (y : F) (hx : x ≠ 0) : E →ₗ.[K] F := mkSpanSingleton' x y fun c hc => (smul_eq_zero.1 hc).elim (fun hc => by rw [hc, zero_smul]) fun hx' => absurd hx' hx theorem mkSpanSingleton_apply (K : Type*) {E F : Type*} [DivisionRing K] [AddCommGroup E] [Module K E] [AddCommGroup F] [Module K F] {x : E} (hx : x ≠ 0) (y : F) : mkSpanSingleton x y hx ⟨x, (Submodule.mem_span_singleton_self x : x ∈ Submodule.span K {x})⟩ = y := LinearPMap.mkSpanSingleton'_apply_self _ _ _ _ /-- Projection to the first coordinate as a `LinearPMap` -/ protected def fst (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] E where domain := p.prod p' toFun := (LinearMap.fst R E F).comp (p.prod p').subtype @[simp] theorem fst_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') : LinearPMap.fst p p' x = (x : E × F).1 := rfl /-- Projection to the second coordinate as a `LinearPMap` -/ protected def snd (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] F where domain := p.prod p' toFun := (LinearMap.snd R E F).comp (p.prod p').subtype @[simp] theorem snd_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') : LinearPMap.snd p p' x = (x : E × F).2 := rfl instance le : LE (E →ₗ.[R] F) := ⟨fun f g => f.domain ≤ g.domain ∧ ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y⟩ theorem apply_comp_inclusion {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) : T x = S (Submodule.inclusion h.1 x) := h.2 rfl theorem exists_of_le {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) : ∃ y : S.domain, (x : E) = y ∧ T x = S y := ⟨⟨x.1, h.1 x.2⟩, ⟨rfl, h.2 rfl⟩⟩ theorem eq_of_le_of_domain_eq {f g : E →ₗ.[R] F} (hle : f ≤ g) (heq : f.domain = g.domain) : f = g := dExt heq hle.2 /-- Given two partial linear maps `f`, `g`, the set of points `x` such that both `f` and `g` are defined at `x` and `f x = g x` form a submodule. -/ def eqLocus (f g : E →ₗ.[R] F) : Submodule R E where carrier := { x | ∃ (hf : x ∈ f.domain) (hg : x ∈ g.domain), f ⟨x, hf⟩ = g ⟨x, hg⟩ } zero_mem' := ⟨zero_mem _, zero_mem _, f.map_zero.trans g.map_zero.symm⟩ add_mem' {x y} := fun ⟨hfx, hgx, hx⟩ ⟨hfy, hgy, hy⟩ ↦ ⟨add_mem hfx hfy, add_mem hgx hgy, by simp_all [← AddMemClass.mk_add_mk, f.map_add, g.map_add]⟩ smul_mem' c x := fun ⟨hfx, hgx, hx⟩ ↦ ⟨smul_mem _ c hfx, smul_mem _ c hgx, by have {f : E →ₗ.[R] F} (hfx) : (⟨c • x, smul_mem _ c hfx⟩ : f.domain) = c • ⟨x, hfx⟩ := by simp rw [this hfx, this hgx, f.map_smul, g.map_smul, hx]⟩ instance bot : Bot (E →ₗ.[R] F) := ⟨⟨⊥, 0⟩⟩ instance inhabited : Inhabited (E →ₗ.[R] F) := ⟨⊥⟩ instance semilatticeInf : SemilatticeInf (E →ₗ.[R] F) where le := (· ≤ ·) le_refl f := ⟨le_refl f.domain, fun _ _ h => Subtype.eq h ▸ rfl⟩ le_trans := fun _ _ _ ⟨fg_le, fg_eq⟩ ⟨gh_le, gh_eq⟩ => ⟨le_trans fg_le gh_le, fun x _ hxz => have hxy : (x : E) = inclusion fg_le x := rfl (fg_eq hxy).trans (gh_eq <| hxy.symm.trans hxz)⟩ le_antisymm _ _ fg gf := eq_of_le_of_domain_eq fg (le_antisymm fg.1 gf.1) inf f g := ⟨f.eqLocus g, f.toFun.comp <| inclusion fun _x hx => hx.fst⟩ le_inf := by intro f g h ⟨fg_le, fg_eq⟩ ⟨fh_le, fh_eq⟩ exact ⟨fun x hx => ⟨fg_le hx, fh_le hx, (fg_eq (x := ⟨x, hx⟩) rfl).symm.trans (fh_eq rfl)⟩, fun x ⟨y, yg, hy⟩ h => fg_eq h⟩ inf_le_left f _ := ⟨fun _ hx => hx.fst, fun _ _ h => congr_arg f <| Subtype.eq <| h⟩ inf_le_right _ g := ⟨fun _ hx => hx.snd.fst, fun ⟨_, _, _, hx⟩ _ h => hx.trans <| congr_arg g <| Subtype.eq <| h⟩ instance orderBot : OrderBot (E →ₗ.[R] F) where bot := ⊥ bot_le f := ⟨bot_le, fun x y h => by have hx : x = 0 := Subtype.eq ((mem_bot R).1 x.2) have hy : y = 0 := Subtype.eq (h.symm.trans (congr_arg _ hx)) rw [hx, hy, map_zero, map_zero]⟩ theorem le_of_eqLocus_ge {f g : E →ₗ.[R] F} (H : f.domain ≤ f.eqLocus g) : f ≤ g := suffices f ≤ f ⊓ g from le_trans this inf_le_right ⟨H, fun _x _y hxy => ((inf_le_left : f ⊓ g ≤ f).2 hxy.symm).symm⟩ theorem domain_mono : StrictMono (@domain R _ E _ _ F _ _) := fun _f _g hlt => lt_of_le_of_ne hlt.1.1 fun heq => ne_of_lt hlt <| eq_of_le_of_domain_eq (le_of_lt hlt) heq private theorem sup_aux (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : ∃ fg : ↥(f.domain ⊔ g.domain) →ₗ[R] F, ∀ (x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)), (x : E) + y = ↑z → fg z = f x + g y := by choose x hx y hy hxy using fun z : ↥(f.domain ⊔ g.domain) => mem_sup.1 z.prop set fg := fun z => f ⟨x z, hx z⟩ + g ⟨y z, hy z⟩ have fg_eq : ∀ (x' : f.domain) (y' : g.domain) (z' : ↥(f.domain ⊔ g.domain)) (_H : (x' : E) + y' = z'), fg z' = f x' + g y' := by intro x' y' z' H dsimp [fg] rw [add_comm, ← sub_eq_sub_iff_add_eq_add, eq_comm, ← map_sub, ← map_sub] apply h simp only [← eq_sub_iff_add_eq] at hxy simp only [AddSubgroupClass.coe_sub, coe_mk, coe_mk, hxy, ← sub_add, ← sub_sub, sub_self, zero_sub, ← H] apply neg_add_eq_sub use { toFun := fg, map_add' := ?_, map_smul' := ?_ }, fg_eq · rintro ⟨z₁, hz₁⟩ ⟨z₂, hz₂⟩ rw [← add_assoc, add_right_comm (f _), ← map_add, add_assoc, ← map_add] apply fg_eq simp only [coe_add, coe_mk, ← add_assoc] rw [add_right_comm (x _), hxy, add_assoc, hxy, coe_mk, coe_mk] · intro c z rw [smul_add, ← map_smul, ← map_smul] apply fg_eq simp only [coe_smul, coe_mk, ← smul_add, hxy, RingHom.id_apply] /-- Given two partial linear maps that agree on the intersection of their domains, `f.sup g h` is the unique partial linear map on `f.domain ⊔ g.domain` that agrees with `f` and `g`. -/ protected noncomputable def sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : E →ₗ.[R] F := ⟨_, Classical.choose (sup_aux f g h)⟩ @[simp] theorem domain_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : (f.sup g h).domain = f.domain ⊔ g.domain := rfl theorem sup_apply {f g : E →ₗ.[R] F} (H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) (x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)) (hz : (↑x : E) + ↑y = ↑z) : f.sup g H z = f x + g y := Classical.choose_spec (sup_aux f g H) x y z hz protected theorem left_le_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : f ≤ f.sup g h := by refine ⟨le_sup_left, fun z₁ z₂ hz => ?_⟩ rw [← add_zero (f _), ← g.map_zero] refine (sup_apply h _ _ _ ?_).symm simpa protected theorem right_le_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : g ≤ f.sup g h := by refine ⟨le_sup_right, fun z₁ z₂ hz => ?_⟩ rw [← zero_add (g _), ← f.map_zero] refine (sup_apply h _ _ _ ?_).symm simpa protected theorem sup_le {f g h : E →ₗ.[R] F} (H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) (fh : f ≤ h) (gh : g ≤ h) : f.sup g H ≤ h := have Hf : f ≤ f.sup g H ⊓ h := le_inf (f.left_le_sup g H) fh have Hg : g ≤ f.sup g H ⊓ h := le_inf (f.right_le_sup g H) gh le_of_eqLocus_ge <| sup_le Hf.1 Hg.1 /-- Hypothesis for `LinearPMap.sup` holds, if `f.domain` is disjoint with `g.domain`. -/ theorem sup_h_of_disjoint (f g : E →ₗ.[R] F) (h : Disjoint f.domain g.domain) (x : f.domain) (y : g.domain) (hxy : (x : E) = y) : f x = g y := by rw [disjoint_def] at h have hy : y = 0 := Subtype.eq (h y (hxy ▸ x.2) y.2) have hx : x = 0 := Subtype.eq (hxy.trans <| congr_arg _ hy) simp [*] /-! ### Algebraic operations -/ section Zero instance instZero : Zero (E →ₗ.[R] F) := ⟨⊤, 0⟩ @[simp] theorem zero_domain : (0 : E →ₗ.[R] F).domain = ⊤ := rfl @[simp] theorem zero_apply (x : (⊤ : Submodule R E)) : (0 : E →ₗ.[R] F) x = 0 := rfl
end Zero section SMul variable {M N : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass R M F]
Mathlib/LinearAlgebra/LinearPMap.lean
346
351
/- 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.Algebra.BigOperators.Option import Mathlib.Analysis.BoxIntegral.Box.Basic import Mathlib.Data.Set.Pairwise.Lattice /-! # Partitions of rectangular boxes in `ℝⁿ` In this file we define (pre)partitions of rectangular boxes in `ℝⁿ`. A partition of a box `I` in `ℝⁿ` (see `BoxIntegral.Prepartition` and `BoxIntegral.Prepartition.IsPartition`) is a finite set of pairwise disjoint boxes such that their union is exactly `I`. We use `boxes : Finset (Box ι)` to store the set of boxes. Many lemmas about box integrals deal with pairwise disjoint collections of subboxes, so we define a structure `BoxIntegral.Prepartition (I : BoxIntegral.Box ι)` that stores a collection of boxes such that * each box `J ∈ boxes` is a subbox of `I`; * the boxes are pairwise disjoint as sets in `ℝⁿ`. Then we define a predicate `BoxIntegral.Prepartition.IsPartition`; `π.IsPartition` means that the boxes of `π` actually cover the whole `I`. We also define some operations on prepartitions: * `BoxIntegral.Prepartition.biUnion`: split each box of a partition into smaller boxes; * `BoxIntegral.Prepartition.restrict`: restrict a partition to a smaller box. We also define a `SemilatticeInf` structure on `BoxIntegral.Prepartition I` for all `I : BoxIntegral.Box ι`. ## Tags rectangular box, partition -/ open Set Finset Function open scoped NNReal noncomputable section namespace BoxIntegral variable {ι : Type*} /-- A prepartition of `I : BoxIntegral.Box ι` is a finite set of pairwise disjoint subboxes of `I`. -/ structure Prepartition (I : Box ι) where /-- The underlying set of boxes -/ boxes : Finset (Box ι) /-- Each box is a sub-box of `I` -/ le_of_mem' : ∀ J ∈ boxes, J ≤ I /-- The boxes in a prepartition are pairwise disjoint. -/ pairwiseDisjoint : Set.Pairwise (↑boxes) (Disjoint on ((↑) : Box ι → Set (ι → ℝ))) namespace Prepartition variable {I J J₁ J₂ : Box ι} (π : Prepartition I) {π₁ π₂ : Prepartition I} {x : ι → ℝ} instance : Membership (Box ι) (Prepartition I) := ⟨fun π J => J ∈ π.boxes⟩ @[simp] theorem mem_boxes : J ∈ π.boxes ↔ J ∈ π := Iff.rfl @[simp] theorem mem_mk {s h₁ h₂} : J ∈ (mk s h₁ h₂ : Prepartition I) ↔ J ∈ s := Iff.rfl theorem disjoint_coe_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (h : J₁ ≠ J₂) : Disjoint (J₁ : Set (ι → ℝ)) J₂ := π.pairwiseDisjoint h₁ h₂ h theorem eq_of_mem_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hx₁ : x ∈ J₁) (hx₂ : x ∈ J₂) : J₁ = J₂ := by_contra fun H => (π.disjoint_coe_of_mem h₁ h₂ H).le_bot ⟨hx₁, hx₂⟩ theorem eq_of_le_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle₁ : J ≤ J₁) (hle₂ : J ≤ J₂) : J₁ = J₂ := π.eq_of_mem_of_mem h₁ h₂ (hle₁ J.upper_mem) (hle₂ J.upper_mem) theorem eq_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle : J₁ ≤ J₂) : J₁ = J₂ := π.eq_of_le_of_le h₁ h₂ le_rfl hle theorem le_of_mem (hJ : J ∈ π) : J ≤ I := π.le_of_mem' J hJ theorem lower_le_lower (hJ : J ∈ π) : I.lower ≤ J.lower := Box.antitone_lower (π.le_of_mem hJ) theorem upper_le_upper (hJ : J ∈ π) : J.upper ≤ I.upper := Box.monotone_upper (π.le_of_mem hJ) theorem injective_boxes : Function.Injective (boxes : Prepartition I → Finset (Box ι)) := by rintro ⟨s₁, h₁, h₁'⟩ ⟨s₂, h₂, h₂'⟩ (rfl : s₁ = s₂) rfl @[ext] theorem ext (h : ∀ J, J ∈ π₁ ↔ J ∈ π₂) : π₁ = π₂ := injective_boxes <| Finset.ext h /-- The singleton prepartition `{J}`, `J ≤ I`. -/ @[simps] def single (I J : Box ι) (h : J ≤ I) : Prepartition I := ⟨{J}, by simpa, by simp⟩ @[simp] theorem mem_single {J'} (h : J ≤ I) : J' ∈ single I J h ↔ J' = J := mem_singleton /-- We say that `π ≤ π'` if each box of `π` is a subbox of some box of `π'`. -/ instance : LE (Prepartition I) := ⟨fun π π' => ∀ ⦃I⦄, I ∈ π → ∃ I' ∈ π', I ≤ I'⟩ instance partialOrder : PartialOrder (Prepartition I) where le := (· ≤ ·) le_refl _ I hI := ⟨I, hI, le_rfl⟩ le_trans _ _ _ h₁₂ h₂₃ _ hI₁ := let ⟨_, hI₂, hI₁₂⟩ := h₁₂ hI₁ let ⟨I₃, hI₃, hI₂₃⟩ := h₂₃ hI₂ ⟨I₃, hI₃, hI₁₂.trans hI₂₃⟩ le_antisymm := by suffices ∀ {π₁ π₂ : Prepartition I}, π₁ ≤ π₂ → π₂ ≤ π₁ → π₁.boxes ⊆ π₂.boxes from fun π₁ π₂ h₁ h₂ => injective_boxes (Subset.antisymm (this h₁ h₂) (this h₂ h₁)) intro π₁ π₂ h₁ h₂ J hJ rcases h₁ hJ with ⟨J', hJ', hle⟩; rcases h₂ hJ' with ⟨J'', hJ'', hle'⟩ obtain rfl : J = J'' := π₁.eq_of_le hJ hJ'' (hle.trans hle') obtain rfl : J' = J := le_antisymm ‹_› ‹_› assumption instance : OrderTop (Prepartition I) where top := single I I le_rfl le_top π _ hJ := ⟨I, by simp, π.le_of_mem hJ⟩ instance : OrderBot (Prepartition I) where bot := ⟨∅, fun _ hJ => (Finset.not_mem_empty _ hJ).elim, fun _ hJ => (Set.not_mem_empty _ <| Finset.coe_empty ▸ hJ).elim⟩ bot_le _ _ hJ := (Finset.not_mem_empty _ hJ).elim instance : Inhabited (Prepartition I) := ⟨⊤⟩ theorem le_def : π₁ ≤ π₂ ↔ ∀ J ∈ π₁, ∃ J' ∈ π₂, J ≤ J' := Iff.rfl @[simp] theorem mem_top : J ∈ (⊤ : Prepartition I) ↔ J = I := mem_singleton @[simp] theorem top_boxes : (⊤ : Prepartition I).boxes = {I} := rfl @[simp] theorem not_mem_bot : J ∉ (⊥ : Prepartition I) := Finset.not_mem_empty _ @[simp] theorem bot_boxes : (⊥ : Prepartition I).boxes = ∅ := rfl /-- An auxiliary lemma used to prove that the same point can't belong to more than `2 ^ Fintype.card ι` closed boxes of a prepartition. -/ theorem injOn_setOf_mem_Icc_setOf_lower_eq (x : ι → ℝ) : InjOn (fun J : Box ι => { i | J.lower i = x i }) { J | J ∈ π ∧ x ∈ Box.Icc J } := by rintro J₁ ⟨h₁, hx₁⟩ J₂ ⟨h₂, hx₂⟩ (H : { i | J₁.lower i = x i } = { i | J₂.lower i = x i }) suffices ∀ i, (Ioc (J₁.lower i) (J₁.upper i) ∩ Ioc (J₂.lower i) (J₂.upper i)).Nonempty by choose y hy₁ hy₂ using this exact π.eq_of_mem_of_mem h₁ h₂ hy₁ hy₂ intro i simp only [Set.ext_iff, mem_setOf] at H rcases (hx₁.1 i).eq_or_lt with hi₁ | hi₁ · have hi₂ : J₂.lower i = x i := (H _).1 hi₁ have H₁ : x i < J₁.upper i := by simpa only [hi₁] using J₁.lower_lt_upper i have H₂ : x i < J₂.upper i := by simpa only [hi₂] using J₂.lower_lt_upper i rw [Set.Ioc_inter_Ioc, hi₁, hi₂, sup_idem, Set.nonempty_Ioc] exact lt_min H₁ H₂ · have hi₂ : J₂.lower i < x i := (hx₂.1 i).lt_of_ne (mt (H _).2 hi₁.ne) exact ⟨x i, ⟨hi₁, hx₁.2 i⟩, ⟨hi₂, hx₂.2 i⟩⟩ open scoped Classical in /-- The set of boxes of a prepartition that contain `x` in their closures has cardinality at most `2 ^ Fintype.card ι`. -/ theorem card_filter_mem_Icc_le [Fintype ι] (x : ι → ℝ) : #{J ∈ π.boxes | x ∈ Box.Icc J} ≤ 2 ^ Fintype.card ι := by rw [← Fintype.card_set] refine Finset.card_le_card_of_injOn (fun J : Box ι => { i | J.lower i = x i }) (fun _ _ => Finset.mem_univ _) ?_ simpa using π.injOn_setOf_mem_Icc_setOf_lower_eq x /-- Given a prepartition `π : BoxIntegral.Prepartition I`, `π.iUnion` is the part of `I` covered by the boxes of `π`. -/ protected def iUnion : Set (ι → ℝ) := ⋃ J ∈ π, ↑J theorem iUnion_def : π.iUnion = ⋃ J ∈ π, ↑J := rfl theorem iUnion_def' : π.iUnion = ⋃ J ∈ π.boxes, ↑J := rfl -- Porting note: Previous proof was `:= Set.mem_iUnion₂` @[simp] theorem mem_iUnion : x ∈ π.iUnion ↔ ∃ J ∈ π, x ∈ J := by convert Set.mem_iUnion₂ rw [Box.mem_coe, exists_prop] @[simp] theorem iUnion_single (h : J ≤ I) : (single I J h).iUnion = J := by simp [iUnion_def] @[simp] theorem iUnion_top : (⊤ : Prepartition I).iUnion = I := by simp [Prepartition.iUnion] @[simp] theorem iUnion_eq_empty : π₁.iUnion = ∅ ↔ π₁ = ⊥ := by simp [← injective_boxes.eq_iff, Finset.ext_iff, Prepartition.iUnion, imp_false] @[simp] theorem iUnion_bot : (⊥ : Prepartition I).iUnion = ∅ := iUnion_eq_empty.2 rfl theorem subset_iUnion (h : J ∈ π) : ↑J ⊆ π.iUnion := subset_biUnion_of_mem h theorem iUnion_subset : π.iUnion ⊆ I := iUnion₂_subset π.le_of_mem' @[mono] theorem iUnion_mono (h : π₁ ≤ π₂) : π₁.iUnion ⊆ π₂.iUnion := fun _ hx => let ⟨_, hJ₁, hx⟩ := π₁.mem_iUnion.1 hx let ⟨J₂, hJ₂, hle⟩ := h hJ₁ π₂.mem_iUnion.2 ⟨J₂, hJ₂, hle hx⟩ theorem disjoint_boxes_of_disjoint_iUnion (h : Disjoint π₁.iUnion π₂.iUnion) : Disjoint π₁.boxes π₂.boxes := Finset.disjoint_left.2 fun J h₁ h₂ => Disjoint.le_bot (h.mono (π₁.subset_iUnion h₁) (π₂.subset_iUnion h₂)) ⟨J.upper_mem, J.upper_mem⟩ theorem le_iff_nonempty_imp_le_and_iUnion_subset : π₁ ≤ π₂ ↔ (∀ J ∈ π₁, ∀ J' ∈ π₂, (J ∩ J' : Set (ι → ℝ)).Nonempty → J ≤ J') ∧ π₁.iUnion ⊆ π₂.iUnion := by constructor · refine fun H => ⟨fun J hJ J' hJ' Hne => ?_, iUnion_mono H⟩ rcases H hJ with ⟨J'', hJ'', Hle⟩ rcases Hne with ⟨x, hx, hx'⟩ rwa [π₂.eq_of_mem_of_mem hJ' hJ'' hx' (Hle hx)] · rintro ⟨H, HU⟩ J hJ simp only [Set.subset_def, mem_iUnion] at HU rcases HU J.upper ⟨J, hJ, J.upper_mem⟩ with ⟨J₂, hJ₂, hx⟩ exact ⟨J₂, hJ₂, H _ hJ _ hJ₂ ⟨_, J.upper_mem, hx⟩⟩ theorem eq_of_boxes_subset_iUnion_superset (h₁ : π₁.boxes ⊆ π₂.boxes) (h₂ : π₂.iUnion ⊆ π₁.iUnion) : π₁ = π₂ := le_antisymm (fun J hJ => ⟨J, h₁ hJ, le_rfl⟩) <| le_iff_nonempty_imp_le_and_iUnion_subset.2 ⟨fun _ hJ₁ _ hJ₂ Hne => (π₂.eq_of_mem_of_mem hJ₁ (h₁ hJ₂) Hne.choose_spec.1 Hne.choose_spec.2).le, h₂⟩ open scoped Classical in /-- Given a prepartition `π` of a box `I` and a collection of prepartitions `πi J` of all boxes `J ∈ π`, returns the prepartition of `I` into the union of the boxes of all `πi J`. Though we only use the values of `πi` on the boxes of `π`, we require `πi` to be a globally defined function. -/ @[simps] def biUnion (πi : ∀ J : Box ι, Prepartition J) : Prepartition I where boxes := π.boxes.biUnion fun J => (πi J).boxes le_of_mem' J hJ := by simp only [Finset.mem_biUnion, exists_prop, mem_boxes] at hJ rcases hJ with ⟨J', hJ', hJ⟩ exact ((πi J').le_of_mem hJ).trans (π.le_of_mem hJ') pairwiseDisjoint := by simp only [Set.Pairwise, Finset.mem_coe, Finset.mem_biUnion] rintro J₁' ⟨J₁, hJ₁, hJ₁'⟩ J₂' ⟨J₂, hJ₂, hJ₂'⟩ Hne rw [Function.onFun, Set.disjoint_left] rintro x hx₁ hx₂; apply Hne obtain rfl : J₁ = J₂ := π.eq_of_mem_of_mem hJ₁ hJ₂ ((πi J₁).le_of_mem hJ₁' hx₁) ((πi J₂).le_of_mem hJ₂' hx₂) exact (πi J₁).eq_of_mem_of_mem hJ₁' hJ₂' hx₁ hx₂ variable {πi πi₁ πi₂ : ∀ J : Box ι, Prepartition J} @[simp] theorem mem_biUnion : J ∈ π.biUnion πi ↔ ∃ J' ∈ π, J ∈ πi J' := by simp [biUnion] theorem biUnion_le (πi : ∀ J, Prepartition J) : π.biUnion πi ≤ π := fun _ hJ => let ⟨J', hJ', hJ⟩ := π.mem_biUnion.1 hJ ⟨J', hJ', (πi J').le_of_mem hJ⟩ @[simp] theorem biUnion_top : (π.biUnion fun _ => ⊤) = π := by ext simp @[congr] theorem biUnion_congr (h : π₁ = π₂) (hi : ∀ J ∈ π₁, πi₁ J = πi₂ J) : π₁.biUnion πi₁ = π₂.biUnion πi₂ := by subst π₂ ext J simp only [mem_biUnion] constructor <;> exact fun ⟨J', h₁, h₂⟩ => ⟨J', h₁, hi J' h₁ ▸ h₂⟩ theorem biUnion_congr_of_le (h : π₁ = π₂) (hi : ∀ J ≤ I, πi₁ J = πi₂ J) : π₁.biUnion πi₁ = π₂.biUnion πi₂ := biUnion_congr h fun J hJ => hi J (π₁.le_of_mem hJ) @[simp] theorem iUnion_biUnion (πi : ∀ J : Box ι, Prepartition J) : (π.biUnion πi).iUnion = ⋃ J ∈ π, (πi J).iUnion := by simp [Prepartition.iUnion] open scoped Classical in @[simp] theorem sum_biUnion_boxes {M : Type*} [AddCommMonoid M] (π : Prepartition I) (πi : ∀ J, Prepartition J) (f : Box ι → M) : (∑ J ∈ π.boxes.biUnion fun J => (πi J).boxes, f J) = ∑ J ∈ π.boxes, ∑ J' ∈ (πi J).boxes, f J' := by refine Finset.sum_biUnion fun J₁ h₁ J₂ h₂ hne => Finset.disjoint_left.2 fun J' h₁' h₂' => ?_ exact hne (π.eq_of_le_of_le h₁ h₂ ((πi J₁).le_of_mem h₁') ((πi J₂).le_of_mem h₂')) open scoped Classical in /-- Given a box `J ∈ π.biUnion πi`, returns the box `J' ∈ π` such that `J ∈ πi J'`. For `J ∉ π.biUnion πi`, returns `I`. -/ def biUnionIndex (πi : ∀ (J : Box ι), Prepartition J) (J : Box ι) : Box ι := if hJ : J ∈ π.biUnion πi then (π.mem_biUnion.1 hJ).choose else I theorem biUnionIndex_mem (hJ : J ∈ π.biUnion πi) : π.biUnionIndex πi J ∈ π := by rw [biUnionIndex, dif_pos hJ] exact (π.mem_biUnion.1 hJ).choose_spec.1 theorem biUnionIndex_le (πi : ∀ J, Prepartition J) (J : Box ι) : π.biUnionIndex πi J ≤ I := by by_cases hJ : J ∈ π.biUnion πi · exact π.le_of_mem (π.biUnionIndex_mem hJ) · rw [biUnionIndex, dif_neg hJ] theorem mem_biUnionIndex (hJ : J ∈ π.biUnion πi) : J ∈ πi (π.biUnionIndex πi J) := by convert (π.mem_biUnion.1 hJ).choose_spec.2 <;> exact dif_pos hJ theorem le_biUnionIndex (hJ : J ∈ π.biUnion πi) : J ≤ π.biUnionIndex πi J := le_of_mem _ (π.mem_biUnionIndex hJ) /-- Uniqueness property of `BoxIntegral.Prepartition.biUnionIndex`. -/ theorem biUnionIndex_of_mem (hJ : J ∈ π) {J'} (hJ' : J' ∈ πi J) : π.biUnionIndex πi J' = J := have : J' ∈ π.biUnion πi := π.mem_biUnion.2 ⟨J, hJ, hJ'⟩ π.eq_of_le_of_le (π.biUnionIndex_mem this) hJ (π.le_biUnionIndex this) (le_of_mem _ hJ') theorem biUnion_assoc (πi : ∀ J, Prepartition J) (πi' : Box ι → ∀ J : Box ι, Prepartition J) : (π.biUnion fun J => (πi J).biUnion (πi' J)) = (π.biUnion πi).biUnion fun J => πi' (π.biUnionIndex πi J) J := by ext J simp only [mem_biUnion, exists_prop] constructor · rintro ⟨J₁, hJ₁, J₂, hJ₂, hJ⟩ refine ⟨J₂, ⟨J₁, hJ₁, hJ₂⟩, ?_⟩ rwa [π.biUnionIndex_of_mem hJ₁ hJ₂] · rintro ⟨J₁, ⟨J₂, hJ₂, hJ₁⟩, hJ⟩ refine ⟨J₂, hJ₂, J₁, hJ₁, ?_⟩ rwa [π.biUnionIndex_of_mem hJ₂ hJ₁] at hJ /-- Create a `BoxIntegral.Prepartition` from a collection of possibly empty boxes by filtering out the empty one if it exists. -/ def ofWithBot (boxes : Finset (WithBot (Box ι))) (le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) : Prepartition I where boxes := Finset.eraseNone boxes le_of_mem' J hJ := by rw [mem_eraseNone] at hJ simpa only [WithBot.some_eq_coe, WithBot.coe_le_coe] using le_of_mem _ hJ pairwiseDisjoint J₁ h₁ J₂ h₂ hne := by simp only [mem_coe, mem_eraseNone] at h₁ h₂ exact Box.disjoint_coe.1 (pairwise_disjoint h₁ h₂ (mt Option.some_inj.1 hne)) @[simp] theorem mem_ofWithBot {boxes : Finset (WithBot (Box ι))} {h₁ h₂} : J ∈ (ofWithBot boxes h₁ h₂ : Prepartition I) ↔ (J : WithBot (Box ι)) ∈ boxes := mem_eraseNone @[simp] theorem iUnion_ofWithBot (boxes : Finset (WithBot (Box ι))) (le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) : (ofWithBot boxes le_of_mem pairwise_disjoint).iUnion = ⋃ J ∈ boxes, ↑J := by suffices ⋃ (J : Box ι) (_ : ↑J ∈ boxes), ↑J = ⋃ J ∈ boxes, (J : Set (ι → ℝ)) by simpa [ofWithBot, Prepartition.iUnion] simp only [← Box.biUnion_coe_eq_coe, @iUnion_comm _ _ (Box ι), @iUnion_comm _ _ (@Eq _ _ _), iUnion_iUnion_eq_right] theorem ofWithBot_le {boxes : Finset (WithBot (Box ι))} {le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I} {pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint} (H : ∀ J ∈ boxes, J ≠ ⊥ → ∃ J' ∈ π, J ≤ ↑J') : ofWithBot boxes le_of_mem pairwise_disjoint ≤ π := by have : ∀ J : Box ι, ↑J ∈ boxes → ∃ J' ∈ π, J ≤ J' := fun J hJ => by simpa only [WithBot.coe_le_coe] using H J hJ WithBot.coe_ne_bot simpa [ofWithBot, le_def] theorem le_ofWithBot {boxes : Finset (WithBot (Box ι))} {le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I} {pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint} (H : ∀ J ∈ π, ∃ J' ∈ boxes, ↑J ≤ J') : π ≤ ofWithBot boxes le_of_mem pairwise_disjoint := by intro J hJ rcases H J hJ with ⟨J', J'mem, hle⟩ lift J' to Box ι using ne_bot_of_le_ne_bot WithBot.coe_ne_bot hle exact ⟨J', mem_ofWithBot.2 J'mem, WithBot.coe_le_coe.1 hle⟩ theorem ofWithBot_mono {boxes₁ : Finset (WithBot (Box ι))} {le_of_mem₁ : ∀ J ∈ boxes₁, (J : WithBot (Box ι)) ≤ I} {pairwise_disjoint₁ : Set.Pairwise (boxes₁ : Set (WithBot (Box ι))) Disjoint} {boxes₂ : Finset (WithBot (Box ι))} {le_of_mem₂ : ∀ J ∈ boxes₂, (J : WithBot (Box ι)) ≤ I} {pairwise_disjoint₂ : Set.Pairwise (boxes₂ : Set (WithBot (Box ι))) Disjoint} (H : ∀ J ∈ boxes₁, J ≠ ⊥ → ∃ J' ∈ boxes₂, J ≤ J') : ofWithBot boxes₁ le_of_mem₁ pairwise_disjoint₁ ≤ ofWithBot boxes₂ le_of_mem₂ pairwise_disjoint₂ := le_ofWithBot _ fun J hJ => H J (mem_ofWithBot.1 hJ) WithBot.coe_ne_bot theorem sum_ofWithBot {M : Type*} [AddCommMonoid M] (boxes : Finset (WithBot (Box ι))) (le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) (f : Box ι → M) : (∑ J ∈ (ofWithBot boxes le_of_mem pairwise_disjoint).boxes, f J) = ∑ J ∈ boxes, Option.elim' 0 f J := Finset.sum_eraseNone _ _ open scoped Classical in /-- Restrict a prepartition to a box. -/ def restrict (π : Prepartition I) (J : Box ι) : Prepartition J := ofWithBot (π.boxes.image fun J' : Box ι => J ⊓ J') (fun J' hJ' => by rcases Finset.mem_image.1 hJ' with ⟨J', -, rfl⟩ exact inf_le_left) (by simp only [Set.Pairwise, onFun, Finset.mem_coe, Finset.mem_image] rintro _ ⟨J₁, h₁, rfl⟩ _ ⟨J₂, h₂, rfl⟩ Hne have : J₁ ≠ J₂ := by rintro rfl exact Hne rfl exact ((Box.disjoint_coe.2 <| π.disjoint_coe_of_mem h₁ h₂ this).inf_left' _).inf_right' _) @[simp] theorem mem_restrict : J₁ ∈ π.restrict J ↔ ∃ J' ∈ π, (J₁ : WithBot (Box ι)) = ↑J ⊓ ↑J' := by simp [restrict, eq_comm] theorem mem_restrict' : J₁ ∈ π.restrict J ↔ ∃ J' ∈ π, (J₁ : Set (ι → ℝ)) = ↑J ∩ ↑J' := by simp only [mem_restrict, ← Box.withBotCoe_inj, Box.coe_inf, Box.coe_coe] @[mono] theorem restrict_mono {π₁ π₂ : Prepartition I} (Hle : π₁ ≤ π₂) : π₁.restrict J ≤ π₂.restrict J := by classical refine ofWithBot_mono fun J₁ hJ₁ hne => ?_ rw [Finset.mem_image] at hJ₁; rcases hJ₁ with ⟨J₁, hJ₁, rfl⟩ rcases Hle hJ₁ with ⟨J₂, hJ₂, hle⟩ exact ⟨_, Finset.mem_image_of_mem _ hJ₂, inf_le_inf_left _ <| WithBot.coe_le_coe.2 hle⟩ theorem monotone_restrict : Monotone fun π : Prepartition I => restrict π J := fun _ _ => restrict_mono /-- Restricting to a larger box does not change the set of boxes. We cannot claim equality of prepartitions because they have different types. -/ theorem restrict_boxes_of_le (π : Prepartition I) (h : I ≤ J) : (π.restrict J).boxes = π.boxes := by classical simp only [restrict, ofWithBot, eraseNone_eq_biUnion] refine Finset.image_biUnion.trans ?_ refine (Finset.biUnion_congr rfl ?_).trans Finset.biUnion_singleton_eq_self intro J' hJ' rw [inf_of_le_right, ← WithBot.some_eq_coe, Option.toFinset_some] exact WithBot.coe_le_coe.2 ((π.le_of_mem hJ').trans h) @[simp] theorem restrict_self : π.restrict I = π := injective_boxes <| restrict_boxes_of_le π le_rfl @[simp] theorem iUnion_restrict : (π.restrict J).iUnion = (J : Set (ι → ℝ)) ∩ (π.iUnion) := by simp [restrict, ← inter_iUnion, ← iUnion_def] @[simp] theorem restrict_biUnion (πi : ∀ J, Prepartition J) (hJ : J ∈ π) : (π.biUnion πi).restrict J = πi J := by refine (eq_of_boxes_subset_iUnion_superset (fun J₁ h₁ => ?_) ?_).symm · refine (mem_restrict _).2 ⟨J₁, π.mem_biUnion.2 ⟨J, hJ, h₁⟩, (inf_of_le_right ?_).symm⟩ exact WithBot.coe_le_coe.2 (le_of_mem _ h₁) · simp only [iUnion_restrict, iUnion_biUnion, Set.subset_def, Set.mem_inter_iff, Set.mem_iUnion] rintro x ⟨hxJ, J₁, h₁, hx⟩ obtain rfl : J = J₁ := π.eq_of_mem_of_mem hJ h₁ hxJ (iUnion_subset _ hx) exact hx theorem biUnion_le_iff {πi : ∀ J, Prepartition J} {π' : Prepartition I} : π.biUnion πi ≤ π' ↔ ∀ J ∈ π, πi J ≤ π'.restrict J := by constructor <;> intro H J hJ · rw [← π.restrict_biUnion πi hJ] exact restrict_mono H · rw [mem_biUnion] at hJ rcases hJ with ⟨J₁, h₁, hJ⟩ rcases H J₁ h₁ hJ with ⟨J₂, h₂, Hle⟩ rcases π'.mem_restrict.mp h₂ with ⟨J₃, h₃, H⟩ exact ⟨J₃, h₃, Hle.trans <| WithBot.coe_le_coe.1 <| H.trans_le inf_le_right⟩ theorem le_biUnion_iff {πi : ∀ J, Prepartition J} {π' : Prepartition I} : π' ≤ π.biUnion πi ↔ π' ≤ π ∧ ∀ J ∈ π, π'.restrict J ≤ πi J := by refine ⟨fun H => ⟨H.trans (π.biUnion_le πi), fun J hJ => ?_⟩, ?_⟩ · rw [← π.restrict_biUnion πi hJ] exact restrict_mono H · rintro ⟨H, Hi⟩ J' hJ' rcases H hJ' with ⟨J, hJ, hle⟩ have : J' ∈ π'.restrict J := π'.mem_restrict.2 ⟨J', hJ', (inf_of_le_right <| WithBot.coe_le_coe.2 hle).symm⟩ rcases Hi J hJ this with ⟨Ji, hJi, hlei⟩ exact ⟨Ji, π.mem_biUnion.2 ⟨J, hJ, hJi⟩, hlei⟩ instance : SemilatticeInf (Prepartition I) := { inf := fun π₁ π₂ => π₁.biUnion fun J => π₂.restrict J inf_le_left := fun π₁ _ => π₁.biUnion_le _ inf_le_right := fun _ _ => (biUnion_le_iff _).2 fun _ _ => le_rfl le_inf := fun _ π₁ _ h₁ h₂ => π₁.le_biUnion_iff.2 ⟨h₁, fun _ _ => restrict_mono h₂⟩ } theorem inf_def (π₁ π₂ : Prepartition I) : π₁ ⊓ π₂ = π₁.biUnion fun J => π₂.restrict J := rfl @[simp] theorem mem_inf {π₁ π₂ : Prepartition I} :
J ∈ π₁ ⊓ π₂ ↔ ∃ J₁ ∈ π₁, ∃ J₂ ∈ π₂, (J : WithBot (Box ι)) = ↑J₁ ⊓ ↑J₂ := by simp only [inf_def, mem_biUnion, mem_restrict] @[simp] theorem iUnion_inf (π₁ π₂ : Prepartition I) : (π₁ ⊓ π₂).iUnion = π₁.iUnion ∩ π₂.iUnion := by simp only [inf_def, iUnion_biUnion, iUnion_restrict, ← iUnion_inter, ← iUnion_def]
Mathlib/Analysis/BoxIntegral/Partition/Basic.lean
513
519
/- Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Order.Ring.Int import Mathlib.Data.Nat.Cast.Order.Basic import Mathlib.Order.Interval.Set.OrdConnected import Mathlib.Order.Nat import Mathlib.Order.UpperLower.Basic /-! # Images of intervals under `Nat.cast : ℕ → ℤ` In this file we prove that the image of each `Set.Ixx` interval under `Nat.cast : ℕ → ℤ` is the corresponding interval in `ℤ`. -/ open Set namespace Nat @[simp] theorem range_cast_int : range ((↑) : ℕ → ℤ) = Ici 0 := Subset.antisymm (range_subset_iff.2 Int.ofNat_nonneg) CanLift.prf theorem image_cast_int_Icc (a b : ℕ) : (↑) '' Icc a b = Icc (a : ℤ) b := (castOrderEmbedding (α := ℤ)).image_Icc (by simp [ordConnected_Ici]) a b theorem image_cast_int_Ico (a b : ℕ) : (↑) '' Ico a b = Ico (a : ℤ) b := (castOrderEmbedding (α := ℤ)).image_Ico (by simp [ordConnected_Ici]) a b theorem image_cast_int_Ioc (a b : ℕ) : (↑) '' Ioc a b = Ioc (a : ℤ) b := (castOrderEmbedding (α := ℤ)).image_Ioc (by simp [ordConnected_Ici]) a b theorem image_cast_int_Ioo (a b : ℕ) : (↑) '' Ioo a b = Ioo (a : ℤ) b := (castOrderEmbedding (α := ℤ)).image_Ioo (by simp [ordConnected_Ici]) a b theorem image_cast_int_Iic (a : ℕ) : (↑) '' Iic a = Icc (0 : ℤ) a := by rw [← Icc_bot, image_cast_int_Icc]; rfl theorem image_cast_int_Iio (a : ℕ) : (↑) '' Iio a = Ico (0 : ℤ) a := by rw [← Ico_bot, image_cast_int_Ico]; rfl theorem image_cast_int_Ici (a : ℕ) : (↑) '' Ici a = Ici (a : ℤ) :=
(castOrderEmbedding (α := ℤ)).image_Ici (by simp [isUpperSet_Ici]) a
Mathlib/Data/Nat/Cast/SetInterval.lean
46
47
/- 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, Johan Commelin, Mario Carneiro -/ import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.Algebra.MonoidAlgebra.Support import Mathlib.Algebra.Regular.Pow import Mathlib.Data.Finsupp.Antidiagonal import Mathlib.Order.SymmDiff /-! # Multivariate polynomials This file defines polynomial rings over a base ring (or even semiring), with variables from a general type `σ` (which could be infinite). ## Important definitions Let `R` be a commutative ring (or a semiring) and let `σ` be an arbitrary type. This file creates the type `MvPolynomial σ R`, which mathematicians might denote $R[X_i : i \in σ]$. It is the type of multivariate (a.k.a. multivariable) polynomials, with variables corresponding to the terms in `σ`, and coefficients in `R`. ### Notation In the definitions below, we use the following notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ### Definitions * `MvPolynomial σ R` : the type of polynomials with variables of type `σ` and coefficients in the commutative semiring `R` * `monomial s a` : the monomial which mathematically would be denoted `a * X^s` * `C a` : the constant polynomial with value `a` * `X i` : the degree one monomial corresponding to i; mathematically this might be denoted `Xᵢ`. * `coeff s p` : the coefficient of `s` in `p`. ## Implementation notes Recall that if `Y` has a zero, then `X →₀ Y` is the type of functions from `X` to `Y` with finite support, i.e. such that only finitely many elements of `X` get sent to non-zero terms in `Y`. The definition of `MvPolynomial σ R` is `(σ →₀ ℕ) →₀ R`; here `σ →₀ ℕ` denotes the space of all monomials in the variables, and the function to `R` sends a monomial to its coefficient in the polynomial being represented. ## Tags polynomial, multivariate polynomial, multivariable polynomial -/ noncomputable section open Set Function Finsupp AddMonoidAlgebra open scoped Pointwise universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} /-- Multivariate polynomial, where `σ` is the index set of the variables and `R` is the coefficient ring -/ def MvPolynomial (σ : Type*) (R : Type*) [CommSemiring R] := AddMonoidAlgebra R (σ →₀ ℕ) namespace MvPolynomial -- Porting note: because of `MvPolynomial.C` and `MvPolynomial.X` this linter throws -- tons of warnings in this file, and it's easier to just disable them globally in the file variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} section CommSemiring section Instances instance decidableEqMvPolynomial [CommSemiring R] [DecidableEq σ] [DecidableEq R] : DecidableEq (MvPolynomial σ R) := Finsupp.instDecidableEq instance commSemiring [CommSemiring R] : CommSemiring (MvPolynomial σ R) := AddMonoidAlgebra.commSemiring instance inhabited [CommSemiring R] : Inhabited (MvPolynomial σ R) := ⟨0⟩ instance distribuMulAction [Monoid R] [CommSemiring S₁] [DistribMulAction R S₁] : DistribMulAction R (MvPolynomial σ S₁) := AddMonoidAlgebra.distribMulAction instance smulZeroClass [CommSemiring S₁] [SMulZeroClass R S₁] : SMulZeroClass R (MvPolynomial σ S₁) := AddMonoidAlgebra.smulZeroClass instance faithfulSMul [CommSemiring S₁] [SMulZeroClass R S₁] [FaithfulSMul R S₁] : FaithfulSMul R (MvPolynomial σ S₁) := AddMonoidAlgebra.faithfulSMul instance module [Semiring R] [CommSemiring S₁] [Module R S₁] : Module R (MvPolynomial σ S₁) := AddMonoidAlgebra.module instance isScalarTower [CommSemiring S₂] [SMul R S₁] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂] [IsScalarTower R S₁ S₂] : IsScalarTower R S₁ (MvPolynomial σ S₂) := AddMonoidAlgebra.isScalarTower instance smulCommClass [CommSemiring S₂] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂] [SMulCommClass R S₁ S₂] : SMulCommClass R S₁ (MvPolynomial σ S₂) := AddMonoidAlgebra.smulCommClass instance isCentralScalar [CommSemiring S₁] [SMulZeroClass R S₁] [SMulZeroClass Rᵐᵒᵖ S₁] [IsCentralScalar R S₁] : IsCentralScalar R (MvPolynomial σ S₁) := AddMonoidAlgebra.isCentralScalar instance algebra [CommSemiring R] [CommSemiring S₁] [Algebra R S₁] : Algebra R (MvPolynomial σ S₁) := AddMonoidAlgebra.algebra instance isScalarTower_right [CommSemiring S₁] [DistribSMul R S₁] [IsScalarTower R S₁ S₁] : IsScalarTower R (MvPolynomial σ S₁) (MvPolynomial σ S₁) := AddMonoidAlgebra.isScalarTower_self _ instance smulCommClass_right [CommSemiring S₁] [DistribSMul R S₁] [SMulCommClass R S₁ S₁] : SMulCommClass R (MvPolynomial σ S₁) (MvPolynomial σ S₁) := AddMonoidAlgebra.smulCommClass_self _ /-- If `R` is a subsingleton, then `MvPolynomial σ R` has a unique element -/ instance unique [CommSemiring R] [Subsingleton R] : Unique (MvPolynomial σ R) := AddMonoidAlgebra.unique end Instances variable [CommSemiring R] [CommSemiring S₁] {p q : MvPolynomial σ R} /-- `monomial s a` is the monomial with coefficient `a` and exponents given by `s` -/ def monomial (s : σ →₀ ℕ) : R →ₗ[R] MvPolynomial σ R := AddMonoidAlgebra.lsingle s theorem one_def : (1 : MvPolynomial σ R) = monomial 0 1 := rfl theorem single_eq_monomial (s : σ →₀ ℕ) (a : R) : Finsupp.single s a = monomial s a := rfl theorem mul_def : p * q = p.sum fun m a => q.sum fun n b => monomial (m + n) (a * b) := AddMonoidAlgebra.mul_def /-- `C a` is the constant polynomial with value `a` -/ def C : R →+* MvPolynomial σ R := { singleZeroRingHom with toFun := monomial 0 } variable (R σ) @[simp] theorem algebraMap_eq : algebraMap R (MvPolynomial σ R) = C := rfl variable {R σ} /-- `X n` is the degree `1` monomial $X_n$. -/ def X (n : σ) : MvPolynomial σ R := monomial (Finsupp.single n 1) 1 theorem monomial_left_injective {r : R} (hr : r ≠ 0) : Function.Injective fun s : σ →₀ ℕ => monomial s r := Finsupp.single_left_injective hr @[simp] theorem monomial_left_inj {s t : σ →₀ ℕ} {r : R} (hr : r ≠ 0) : monomial s r = monomial t r ↔ s = t := Finsupp.single_left_inj hr theorem C_apply : (C a : MvPolynomial σ R) = monomial 0 a := rfl @[simp] theorem C_0 : C 0 = (0 : MvPolynomial σ R) := map_zero _ @[simp] theorem C_1 : C 1 = (1 : MvPolynomial σ R) := rfl theorem C_mul_monomial : C a * monomial s a' = monomial s (a * a') := by -- Porting note: this `show` feels like defeq abuse, but I can't find the appropriate lemmas show AddMonoidAlgebra.single _ _ * AddMonoidAlgebra.single _ _ = AddMonoidAlgebra.single _ _ simp [C_apply, single_mul_single] @[simp] theorem C_add : (C (a + a') : MvPolynomial σ R) = C a + C a' := Finsupp.single_add _ _ _ @[simp] theorem C_mul : (C (a * a') : MvPolynomial σ R) = C a * C a' := C_mul_monomial.symm @[simp] theorem C_pow (a : R) (n : ℕ) : (C (a ^ n) : MvPolynomial σ R) = C a ^ n := map_pow _ _ _ theorem C_injective (σ : Type*) (R : Type*) [CommSemiring R] : Function.Injective (C : R → MvPolynomial σ R) := Finsupp.single_injective _ theorem C_surjective {R : Type*} [CommSemiring R] (σ : Type*) [IsEmpty σ] : Function.Surjective (C : R → MvPolynomial σ R) := by refine fun p => ⟨p.toFun 0, Finsupp.ext fun a => ?_⟩ simp only [C_apply, ← single_eq_monomial, (Finsupp.ext isEmptyElim (α := σ) : a = 0), single_eq_same] rfl @[simp] theorem C_inj {σ : Type*} (R : Type*) [CommSemiring R] (r s : R) : (C r : MvPolynomial σ R) = C s ↔ r = s := (C_injective σ R).eq_iff @[simp] lemma C_eq_zero : (C a : MvPolynomial σ R) = 0 ↔ a = 0 := by rw [← map_zero C, C_inj] lemma C_ne_zero : (C a : MvPolynomial σ R) ≠ 0 ↔ a ≠ 0 := C_eq_zero.ne instance nontrivial_of_nontrivial (σ : Type*) (R : Type*) [CommSemiring R] [Nontrivial R] : Nontrivial (MvPolynomial σ R) := inferInstanceAs (Nontrivial <| AddMonoidAlgebra R (σ →₀ ℕ)) instance infinite_of_infinite (σ : Type*) (R : Type*) [CommSemiring R] [Infinite R] : Infinite (MvPolynomial σ R) := Infinite.of_injective C (C_injective _ _) instance infinite_of_nonempty (σ : Type*) (R : Type*) [Nonempty σ] [CommSemiring R] [Nontrivial R] : Infinite (MvPolynomial σ R) := Infinite.of_injective ((fun s : σ →₀ ℕ => monomial s 1) ∘ Finsupp.single (Classical.arbitrary σ)) <| (monomial_left_injective one_ne_zero).comp (Finsupp.single_injective _)
theorem C_eq_coe_nat (n : ℕ) : (C ↑n : MvPolynomial σ R) = n := by induction n <;> simp [*] theorem C_mul' : MvPolynomial.C a * p = a • p := (Algebra.smul_def a p).symm
Mathlib/Algebra/MvPolynomial/Basic.lean
243
248
/- Copyright (c) 2021 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Combinatorics.Hall.Basic import Mathlib.Data.Matrix.Rank import Mathlib.LinearAlgebra.Projectivization.Constructions /-! # Configurations of Points and lines This file introduces abstract configurations of points and lines, and proves some basic properties. ## Main definitions * `Configuration.Nondegenerate`: Excludes certain degenerate configurations, and imposes uniqueness of intersection points. * `Configuration.HasPoints`: A nondegenerate configuration in which every pair of lines has an intersection point. * `Configuration.HasLines`: A nondegenerate configuration in which every pair of points has a line through them. * `Configuration.lineCount`: The number of lines through a given point. * `Configuration.pointCount`: The number of lines through a given line. ## Main statements * `Configuration.HasLines.card_le`: `HasLines` implies `|P| ≤ |L|`. * `Configuration.HasPoints.card_le`: `HasPoints` implies `|L| ≤ |P|`. * `Configuration.HasLines.hasPoints`: `HasLines` and `|P| = |L|` implies `HasPoints`. * `Configuration.HasPoints.hasLines`: `HasPoints` and `|P| = |L|` implies `HasLines`. Together, these four statements say that any two of the following properties imply the third: (a) `HasLines`, (b) `HasPoints`, (c) `|P| = |L|`. -/ open Finset namespace Configuration variable (P L : Type*) [Membership P L] /-- A type synonym. -/ def Dual := P instance [h : Inhabited P] : Inhabited (Dual P) := h instance [Finite P] : Finite (Dual P) := ‹Finite P› instance [h : Fintype P] : Fintype (Dual P) := h set_option synthInstance.checkSynthOrder false in instance : Membership (Dual L) (Dual P) := ⟨Function.swap (Membership.mem : L → P → Prop)⟩ /-- A configuration is nondegenerate if: 1) there does not exist a line that passes through all of the points, 2) there does not exist a point that is on all of the lines, 3) there is at most one line through any two points, 4) any two lines have at most one intersection point. Conditions 3 and 4 are equivalent. -/ class Nondegenerate : Prop where exists_point : ∀ l : L, ∃ p, p ∉ l exists_line : ∀ p, ∃ l : L, p ∉ l eq_or_eq : ∀ {p₁ p₂ : P} {l₁ l₂ : L}, p₁ ∈ l₁ → p₂ ∈ l₁ → p₁ ∈ l₂ → p₂ ∈ l₂ → p₁ = p₂ ∨ l₁ = l₂ /-- A nondegenerate configuration in which every pair of lines has an intersection point. -/ class HasPoints extends Nondegenerate P L where /-- Intersection of two lines -/ mkPoint : ∀ {l₁ l₂ : L}, l₁ ≠ l₂ → P mkPoint_ax : ∀ {l₁ l₂ : L} (h : l₁ ≠ l₂), mkPoint h ∈ l₁ ∧ mkPoint h ∈ l₂ /-- A nondegenerate configuration in which every pair of points has a line through them. -/ class HasLines extends Nondegenerate P L where /-- Line through two points -/ mkLine : ∀ {p₁ p₂ : P}, p₁ ≠ p₂ → L mkLine_ax : ∀ {p₁ p₂ : P} (h : p₁ ≠ p₂), p₁ ∈ mkLine h ∧ p₂ ∈ mkLine h open Nondegenerate open HasPoints (mkPoint mkPoint_ax) open HasLines (mkLine mkLine_ax) instance Dual.Nondegenerate [Nondegenerate P L] : Nondegenerate (Dual L) (Dual P) where exists_point := @exists_line P L _ _ exists_line := @exists_point P L _ _ eq_or_eq := @fun l₁ l₂ p₁ p₂ h₁ h₂ h₃ h₄ => (@eq_or_eq P L _ _ p₁ p₂ l₁ l₂ h₁ h₃ h₂ h₄).symm instance Dual.hasLines [HasPoints P L] : HasLines (Dual L) (Dual P) := { Dual.Nondegenerate _ _ with mkLine := @mkPoint P L _ _ mkLine_ax := @mkPoint_ax P L _ _ } instance Dual.hasPoints [HasLines P L] : HasPoints (Dual L) (Dual P) := { Dual.Nondegenerate _ _ with mkPoint := @mkLine P L _ _ mkPoint_ax := @mkLine_ax P L _ _ } theorem HasPoints.existsUnique_point [HasPoints P L] (l₁ l₂ : L) (hl : l₁ ≠ l₂) : ∃! p, p ∈ l₁ ∧ p ∈ l₂ := ⟨mkPoint hl, mkPoint_ax hl, fun _ hp => (eq_or_eq hp.1 (mkPoint_ax hl).1 hp.2 (mkPoint_ax hl).2).resolve_right hl⟩ theorem HasLines.existsUnique_line [HasLines P L] (p₁ p₂ : P) (hp : p₁ ≠ p₂) : ∃! l : L, p₁ ∈ l ∧ p₂ ∈ l := HasPoints.existsUnique_point (Dual L) (Dual P) p₁ p₂ hp variable {P L} /-- If a nondegenerate configuration has at least as many points as lines, then there exists an injective function `f` from lines to points, such that `f l` does not lie on `l`. -/ theorem Nondegenerate.exists_injective_of_card_le [Nondegenerate P L] [Fintype P] [Fintype L] (h : Fintype.card L ≤ Fintype.card P) : ∃ f : L → P, Function.Injective f ∧ ∀ l, f l ∉ l := by classical let t : L → Finset P := fun l => Set.toFinset { p | p ∉ l } suffices ∀ s : Finset L, #s ≤ (s.biUnion t).card by -- Hall's marriage theorem obtain ⟨f, hf1, hf2⟩ := (Finset.all_card_le_biUnion_card_iff_exists_injective t).mp this exact ⟨f, hf1, fun l => Set.mem_toFinset.mp (hf2 l)⟩ intro s by_cases hs₀ : #s = 0 -- If `s = ∅`, then `#s = 0 ≤ #(s.bUnion t)` · simp_rw [hs₀, zero_le] by_cases hs₁ : #s = 1 -- If `s = {l}`, then pick a point `p ∉ l` · obtain ⟨l, rfl⟩ := Finset.card_eq_one.mp hs₁ obtain ⟨p, hl⟩ := exists_point (P := P) l rw [Finset.card_singleton, Finset.singleton_biUnion, Nat.one_le_iff_ne_zero] exact Finset.card_ne_zero_of_mem (Set.mem_toFinset.mpr hl) suffices #(s.biUnion t)ᶜ ≤ #sᶜ by -- Rephrase in terms of complements (uses `h`) rw [Finset.card_compl, Finset.card_compl, tsub_le_iff_left] at this replace := h.trans this rwa [← add_tsub_assoc_of_le s.card_le_univ, le_tsub_iff_left (le_add_left s.card_le_univ), add_le_add_iff_right] at this have hs₂ : #(s.biUnion t)ᶜ ≤ 1 := by -- At most one line through two points of `s` refine Finset.card_le_one_iff.mpr @fun p₁ p₂ hp₁ hp₂ => ?_ simp_rw [t, Finset.mem_compl, Finset.mem_biUnion, not_exists, not_and, Set.mem_toFinset, Set.mem_setOf_eq, Classical.not_not] at hp₁ hp₂ obtain ⟨l₁, l₂, hl₁, hl₂, hl₃⟩ := Finset.one_lt_card_iff.mp (Nat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨hs₀, hs₁⟩) exact (eq_or_eq (hp₁ l₁ hl₁) (hp₂ l₁ hl₁) (hp₁ l₂ hl₂) (hp₂ l₂ hl₂)).resolve_right hl₃ by_cases hs₃ : #sᶜ = 0 · rw [hs₃, Nat.le_zero] rw [Finset.card_compl, tsub_eq_zero_iff_le, LE.le.le_iff_eq (Finset.card_le_univ _), eq_comm, Finset.card_eq_iff_eq_univ] at hs₃ ⊢ rw [hs₃] rw [Finset.eq_univ_iff_forall] at hs₃ ⊢ exact fun p => Exists.elim (exists_line p)-- If `s = univ`, then show `s.bUnion t = univ` fun l hl => Finset.mem_biUnion.mpr ⟨l, Finset.mem_univ l, Set.mem_toFinset.mpr hl⟩ · exact hs₂.trans (Nat.one_le_iff_ne_zero.mpr hs₃) -- If `s < univ`, then consequence of `hs₂` variable (L) /-- Number of points on a given line. -/ noncomputable def lineCount (p : P) : ℕ := Nat.card { l : L // p ∈ l } variable (P) {L} /-- Number of lines through a given point. -/ noncomputable def pointCount (l : L) : ℕ := Nat.card { p : P // p ∈ l } variable (L) theorem sum_lineCount_eq_sum_pointCount [Fintype P] [Fintype L] : ∑ p : P, lineCount L p = ∑ l : L, pointCount P l := by classical simp only [lineCount, pointCount, Nat.card_eq_fintype_card, ← Fintype.card_sigma] apply Fintype.card_congr calc (Σp, { l : L // p ∈ l }) ≃ { x : P × L // x.1 ∈ x.2 } := (Equiv.subtypeProdEquivSigmaSubtype (· ∈ ·)).symm _ ≃ { x : L × P // x.2 ∈ x.1 } := (Equiv.prodComm P L).subtypeEquiv fun x => Iff.rfl _ ≃ Σl, { p // p ∈ l } := Equiv.subtypeProdEquivSigmaSubtype fun (l : L) (p : P) => p ∈ l variable {P L} theorem HasLines.pointCount_le_lineCount [HasLines P L] {p : P} {l : L} (h : p ∉ l) [Finite { l : L // p ∈ l }] : pointCount P l ≤ lineCount L p := by by_cases hf : Infinite { p : P // p ∈ l } · exact (le_of_eq Nat.card_eq_zero_of_infinite).trans (zero_le (lineCount L p)) haveI := fintypeOfNotInfinite hf cases nonempty_fintype { l : L // p ∈ l } rw [lineCount, pointCount, Nat.card_eq_fintype_card, Nat.card_eq_fintype_card] have : ∀ p' : { p // p ∈ l }, p ≠ p' := fun p' hp' => h ((congr_arg (· ∈ l) hp').mpr p'.2) exact Fintype.card_le_of_injective (fun p' => ⟨mkLine (this p'), (mkLine_ax (this p')).1⟩) fun p₁ p₂ hp => Subtype.ext ((eq_or_eq p₁.2 p₂.2 (mkLine_ax (this p₁)).2 ((congr_arg (_ ∈ ·) (Subtype.ext_iff.mp hp)).mpr (mkLine_ax (this p₂)).2)).resolve_right fun h' => (congr_arg (¬p ∈ ·) h').mp h (mkLine_ax (this p₁)).1) theorem HasPoints.lineCount_le_pointCount [HasPoints P L] {p : P} {l : L} (h : p ∉ l) [hf : Finite { p : P // p ∈ l }] : lineCount L p ≤ pointCount P l := @HasLines.pointCount_le_lineCount (Dual L) (Dual P) _ _ l p h hf variable (P L) /-- If a nondegenerate configuration has a unique line through any two points, then `|P| ≤ |L|`. -/ theorem HasLines.card_le [HasLines P L] [Fintype P] [Fintype L] : Fintype.card P ≤ Fintype.card L := by classical by_contra hc₂ obtain ⟨f, hf₁, hf₂⟩ := Nondegenerate.exists_injective_of_card_le (le_of_not_le hc₂) have := calc ∑ p, lineCount L p = ∑ l, pointCount P l := sum_lineCount_eq_sum_pointCount P L _ ≤ ∑ l, lineCount L (f l) := (Finset.sum_le_sum fun l _ => HasLines.pointCount_le_lineCount (hf₂ l)) _ = ∑ p ∈ univ.map ⟨f, hf₁⟩, lineCount L p := by rw [sum_map]; dsimp _ < ∑ p, lineCount L p := by obtain ⟨p, hp⟩ := not_forall.mp (mt (Fintype.card_le_of_surjective f) hc₂) refine sum_lt_sum_of_subset (subset_univ _) (mem_univ p) ?_ ?_ fun p _ _ ↦ zero_le _ · simpa only [Finset.mem_map, exists_prop, Finset.mem_univ, true_and] · rw [lineCount, Nat.card_eq_fintype_card, Fintype.card_pos_iff] obtain ⟨l, _⟩ := @exists_line P L _ _ p exact let this := not_exists.mp hp l ⟨⟨mkLine this, (mkLine_ax this).2⟩⟩ exact lt_irrefl _ this /-- If a nondegenerate configuration has a unique point on any two lines, then `|L| ≤ |P|`. -/ theorem HasPoints.card_le [HasPoints P L] [Fintype P] [Fintype L] : Fintype.card L ≤ Fintype.card P := @HasLines.card_le (Dual L) (Dual P) _ _ _ _ variable {P L} theorem HasLines.exists_bijective_of_card_eq [HasLines P L] [Fintype P] [Fintype L] (h : Fintype.card P = Fintype.card L) : ∃ f : L → P, Function.Bijective f ∧ ∀ l, pointCount P l = lineCount L (f l) := by classical obtain ⟨f, hf1, hf2⟩ := Nondegenerate.exists_injective_of_card_le (ge_of_eq h) have hf3 := (Fintype.bijective_iff_injective_and_card f).mpr ⟨hf1, h.symm⟩ exact ⟨f, hf3, fun l ↦ (sum_eq_sum_iff_of_le fun l _ ↦ pointCount_le_lineCount (hf2 l)).1 ((hf3.sum_comp _).trans (sum_lineCount_eq_sum_pointCount P L)).symm _ <| mem_univ _⟩ theorem HasLines.lineCount_eq_pointCount [HasLines P L] [Fintype P] [Fintype L] (hPL : Fintype.card P = Fintype.card L) {p : P} {l : L} (hpl : p ∉ l) : lineCount L p = pointCount P l := by classical obtain ⟨f, hf1, hf2⟩ := HasLines.exists_bijective_of_card_eq hPL let s : Finset (P × L) := Set.toFinset { i | i.1 ∈ i.2 } have step1 : ∑ i : P × L, lineCount L i.1 = ∑ i : P × L, pointCount P i.2 := by rw [← Finset.univ_product_univ, Finset.sum_product_right, Finset.sum_product] simp_rw [Finset.sum_const, Finset.card_univ, hPL, sum_lineCount_eq_sum_pointCount] have step2 : ∑ i ∈ s, lineCount L i.1 = ∑ i ∈ s, pointCount P i.2 := by rw [s.sum_finset_product Finset.univ fun p => Set.toFinset { l | p ∈ l }] on_goal 1 => rw [s.sum_finset_product_right Finset.univ fun l => Set.toFinset { p | p ∈ l }, eq_comm] · refine sum_bijective _ hf1 (by simp) fun l _ ↦ ?_ simp_rw [hf2, sum_const, Set.toFinset_card, ← Nat.card_eq_fintype_card] change pointCount P l • _ = lineCount L (f l) • _ rw [hf2] all_goals simp_rw [s, Finset.mem_univ, true_and, Set.mem_toFinset]; exact fun p => Iff.rfl have step3 : ∑ i ∈ sᶜ, lineCount L i.1 = ∑ i ∈ sᶜ, pointCount P i.2 := by rwa [← s.sum_add_sum_compl, ← s.sum_add_sum_compl, step2, add_left_cancel_iff] at step1 rw [← Set.toFinset_compl] at step3 exact ((Finset.sum_eq_sum_iff_of_le fun i hi => HasLines.pointCount_le_lineCount (by exact Set.mem_toFinset.mp hi)).mp step3.symm (p, l) (Set.mem_toFinset.mpr hpl)).symm theorem HasPoints.lineCount_eq_pointCount [HasPoints P L] [Fintype P] [Fintype L] (hPL : Fintype.card P = Fintype.card L) {p : P} {l : L} (hpl : p ∉ l) : lineCount L p = pointCount P l := (@HasLines.lineCount_eq_pointCount (Dual L) (Dual P) _ _ _ _ hPL.symm l p hpl).symm /-- If a nondegenerate configuration has a unique line through any two points, and if `|P| = |L|`, then there is a unique point on any two lines. -/ noncomputable def HasLines.hasPoints [HasLines P L] [Fintype P] [Fintype L] (h : Fintype.card P = Fintype.card L) : HasPoints P L := let this : ∀ l₁ l₂ : L, l₁ ≠ l₂ → ∃ p : P, p ∈ l₁ ∧ p ∈ l₂ := fun l₁ l₂ hl => by classical obtain ⟨f, _, hf2⟩ := HasLines.exists_bijective_of_card_eq h haveI : Nontrivial L := ⟨⟨l₁, l₂, hl⟩⟩ haveI := Fintype.one_lt_card_iff_nontrivial.mp ((congr_arg _ h).mpr Fintype.one_lt_card) have h₁ : ∀ p : P, 0 < lineCount L p := fun p => Exists.elim (exists_ne p) fun q hq => (congr_arg _ Nat.card_eq_fintype_card).mpr (Fintype.card_pos_iff.mpr ⟨⟨mkLine hq, (mkLine_ax hq).2⟩⟩) have h₂ : ∀ l : L, 0 < pointCount P l := fun l => (congr_arg _ (hf2 l)).mpr (h₁ (f l)) obtain ⟨p, hl₁⟩ := Fintype.card_pos_iff.mp ((congr_arg _ Nat.card_eq_fintype_card).mp (h₂ l₁)) by_cases hl₂ : p ∈ l₂ · exact ⟨p, hl₁, hl₂⟩ have key' : Fintype.card { q : P // q ∈ l₂ } = Fintype.card { l : L // p ∈ l } := ((HasLines.lineCount_eq_pointCount h hl₂).trans Nat.card_eq_fintype_card).symm.trans Nat.card_eq_fintype_card have : ∀ q : { q // q ∈ l₂ }, p ≠ q := fun q hq => hl₂ ((congr_arg (· ∈ l₂) hq).mpr q.2) let f : { q : P // q ∈ l₂ } → { l : L // p ∈ l } := fun q => ⟨mkLine (this q), (mkLine_ax (this q)).1⟩ have hf : Function.Injective f := fun q₁ q₂ hq => Subtype.ext ((eq_or_eq q₁.2 q₂.2 (mkLine_ax (this q₁)).2 ((congr_arg (_ ∈ ·) (Subtype.ext_iff.mp hq)).mpr (mkLine_ax (this q₂)).2)).resolve_right fun h => (congr_arg (¬p ∈ ·) h).mp hl₂ (mkLine_ax (this q₁)).1) have key' := ((Fintype.bijective_iff_injective_and_card f).mpr ⟨hf, key'⟩).2 obtain ⟨q, hq⟩ := key' ⟨l₁, hl₁⟩ exact ⟨q, (congr_arg (_ ∈ ·) (Subtype.ext_iff.mp hq)).mp (mkLine_ax (this q)).2, q.2⟩ { ‹HasLines P L› with mkPoint := fun {l₁ l₂} hl => Classical.choose (this l₁ l₂ hl) mkPoint_ax := fun {l₁ l₂} hl => Classical.choose_spec (this l₁ l₂ hl) } /-- If a nondegenerate configuration has a unique point on any two lines, and if `|P| = |L|`, then there is a unique line through any two points. -/ noncomputable def HasPoints.hasLines [HasPoints P L] [Fintype P] [Fintype L] (h : Fintype.card P = Fintype.card L) : HasLines P L := let this := @HasLines.hasPoints (Dual L) (Dual P) _ _ _ _ h.symm { ‹HasPoints P L› with mkLine := @fun _ _ => this.mkPoint mkLine_ax := @fun _ _ => this.mkPoint_ax } variable (P L) /-- A projective plane is a nondegenerate configuration in which every pair of lines has an intersection point, every pair of points has a line through them, and which has three points in general position. -/ class ProjectivePlane extends HasPoints P L, HasLines P L where exists_config : ∃ (p₁ p₂ p₃ : P) (l₁ l₂ l₃ : L), p₁ ∉ l₂ ∧ p₁ ∉ l₃ ∧ p₂ ∉ l₁ ∧ p₂ ∈ l₂ ∧ p₂ ∈ l₃ ∧ p₃ ∉ l₁ ∧ p₃ ∈ l₂ ∧ p₃ ∉ l₃ namespace ProjectivePlane variable [ProjectivePlane P L] instance : ProjectivePlane (Dual L) (Dual P) := { Dual.hasPoints _ _, Dual.hasLines _ _ with exists_config := let ⟨p₁, p₂, p₃, l₁, l₂, l₃, h₁₂, h₁₃, h₂₁, h₂₂, h₂₃, h₃₁, h₃₂, h₃₃⟩ := @exists_config P L _ _ ⟨l₁, l₂, l₃, p₁, p₂, p₃, h₂₁, h₃₁, h₁₂, h₂₂, h₃₂, h₁₃, h₂₃, h₃₃⟩ } /-- The order of a projective plane is one less than the number of lines through an arbitrary point. Equivalently, it is one less than the number of points on an arbitrary line. -/ noncomputable def order : ℕ := lineCount L (Classical.choose (@exists_config P L _ _)) - 1 theorem card_points_eq_card_lines [Fintype P] [Fintype L] : Fintype.card P = Fintype.card L := le_antisymm (HasLines.card_le P L) (HasPoints.card_le P L) variable {P} theorem lineCount_eq_lineCount [Finite P] [Finite L] (p q : P) : lineCount L p = lineCount L q := by cases nonempty_fintype P cases nonempty_fintype L obtain ⟨p₁, p₂, p₃, l₁, l₂, l₃, h₁₂, h₁₃, h₂₁, h₂₂, h₂₃, h₃₁, h₃₂, h₃₃⟩ := @exists_config P L _ _ have h := card_points_eq_card_lines P L let n := lineCount L p₂ have hp₂ : lineCount L p₂ = n := rfl have hl₁ : pointCount P l₁ = n := (HasLines.lineCount_eq_pointCount h h₂₁).symm.trans hp₂ have hp₃ : lineCount L p₃ = n := (HasLines.lineCount_eq_pointCount h h₃₁).trans hl₁ have hl₃ : pointCount P l₃ = n := (HasLines.lineCount_eq_pointCount h h₃₃).symm.trans hp₃ have hp₁ : lineCount L p₁ = n := (HasLines.lineCount_eq_pointCount h h₁₃).trans hl₃ have hl₂ : pointCount P l₂ = n := (HasLines.lineCount_eq_pointCount h h₁₂).symm.trans hp₁ suffices ∀ p : P, lineCount L p = n by exact (this p).trans (this q).symm refine fun p => or_not.elim (fun h₂ => ?_) fun h₂ => (HasLines.lineCount_eq_pointCount h h₂).trans hl₂ refine or_not.elim (fun h₃ => ?_) fun h₃ => (HasLines.lineCount_eq_pointCount h h₃).trans hl₃ rw [(eq_or_eq h₂ h₂₂ h₃ h₂₃).resolve_right fun h => h₃₃ ((congr_arg (p₃ ∈ ·) h).mp h₃₂)] variable (P) {L} theorem pointCount_eq_pointCount [Finite P] [Finite L] (l m : L) : pointCount P l = pointCount P m := by apply lineCount_eq_lineCount (Dual P) variable {P} theorem lineCount_eq_pointCount [Finite P] [Finite L] (p : P) (l : L) : lineCount L p = pointCount P l := Exists.elim (exists_point l) fun q hq => (lineCount_eq_lineCount L p q).trans <| by cases nonempty_fintype P cases nonempty_fintype L exact HasLines.lineCount_eq_pointCount (card_points_eq_card_lines P L) hq variable (P L) theorem Dual.order [Finite P] [Finite L] : order (Dual L) (Dual P) = order P L := congr_arg (fun n => n - 1) (lineCount_eq_pointCount _ _) variable {P} theorem lineCount_eq [Finite P] [Finite L] (p : P) : lineCount L p = order P L + 1 := by classical obtain ⟨q, -, -, l, -, -, -, -, h, -⟩ := Classical.choose_spec (@exists_config P L _ _) cases nonempty_fintype { l : L // q ∈ l } rw [order, lineCount_eq_lineCount L p q, lineCount_eq_lineCount L (Classical.choose _) q, lineCount, Nat.card_eq_fintype_card, Nat.sub_add_cancel] exact Fintype.card_pos_iff.mpr ⟨⟨l, h⟩⟩
variable (P) {L} theorem pointCount_eq [Finite P] [Finite L] (l : L) : pointCount P l = order P L + 1 :=
Mathlib/Combinatorics/Configuration.lean
400
402
/- Copyright (c) 2023 Sophie Morel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sophie Morel -/ import Mathlib.Analysis.Analytic.Constructions import Mathlib.Analysis.Analytic.CPolynomialDef /-! # Properties of continuously polynomial functions We expand the API around continuously polynomial functions. Notably, we show that this class is stable under the usual operations (addition, subtraction, negation). We also prove that continuous multilinear maps are continuously polynomial, and so are continuous linear maps into continuous multilinear maps. In particular, such maps are analytic. -/ variable {𝕜 E F G : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] open scoped Topology open Set Filter Asymptotics NNReal ENNReal variable {f g : E → F} {p pf pg : FormalMultilinearSeries 𝕜 E F} {x : E} {r r' : ℝ≥0∞} {n m : ℕ} theorem hasFiniteFPowerSeriesOnBall_const {c : F} {e : E} : HasFiniteFPowerSeriesOnBall (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e 1 ⊤ := ⟨hasFPowerSeriesOnBall_const, fun n hn ↦ constFormalMultilinearSeries_apply (id hn : 0 < n).ne'⟩ theorem hasFiniteFPowerSeriesAt_const {c : F} {e : E} : HasFiniteFPowerSeriesAt (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e 1 := ⟨⊤, hasFiniteFPowerSeriesOnBall_const⟩ theorem CPolynomialAt_const {v : F} : CPolynomialAt 𝕜 (fun _ => v) x := ⟨constFormalMultilinearSeries 𝕜 E v, 1, hasFiniteFPowerSeriesAt_const⟩ theorem CPolynomialOn_const {v : F} {s : Set E} : CPolynomialOn 𝕜 (fun _ => v) s := fun _ _ => CPolynomialAt_const theorem HasFiniteFPowerSeriesOnBall.add (hf : HasFiniteFPowerSeriesOnBall f pf x n r) (hg : HasFiniteFPowerSeriesOnBall g pg x m r) : HasFiniteFPowerSeriesOnBall (f + g) (pf + pg) x (max n m) r := ⟨hf.1.add hg.1, fun N hN ↦ by rw [Pi.add_apply, hf.finite _ ((le_max_left n m).trans hN), hg.finite _ ((le_max_right n m).trans hN), zero_add]⟩ theorem HasFiniteFPowerSeriesAt.add (hf : HasFiniteFPowerSeriesAt f pf x n) (hg : HasFiniteFPowerSeriesAt g pg x m) : HasFiniteFPowerSeriesAt (f + g) (pf + pg) x (max n m) := by rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩ exact ⟨r, hr.1.add hr.2⟩ theorem CPolynomialAt.add (hf : CPolynomialAt 𝕜 f x) (hg : CPolynomialAt 𝕜 g x) : CPolynomialAt 𝕜 (f + g) x := let ⟨_, _, hpf⟩ := hf let ⟨_, _, hqf⟩ := hg (hpf.add hqf).cpolynomialAt theorem HasFiniteFPowerSeriesOnBall.neg (hf : HasFiniteFPowerSeriesOnBall f pf x n r) : HasFiniteFPowerSeriesOnBall (-f) (-pf) x n r := ⟨hf.1.neg, fun m hm ↦ by rw [Pi.neg_apply, hf.finite m hm, neg_zero]⟩ theorem HasFiniteFPowerSeriesAt.neg (hf : HasFiniteFPowerSeriesAt f pf x n) : HasFiniteFPowerSeriesAt (-f) (-pf) x n := let ⟨_, hrf⟩ := hf hrf.neg.hasFiniteFPowerSeriesAt theorem CPolynomialAt.neg (hf : CPolynomialAt 𝕜 f x) : CPolynomialAt 𝕜 (-f) x := let ⟨_, _, hpf⟩ := hf hpf.neg.cpolynomialAt theorem HasFiniteFPowerSeriesOnBall.sub (hf : HasFiniteFPowerSeriesOnBall f pf x n r) (hg : HasFiniteFPowerSeriesOnBall g pg x m r) : HasFiniteFPowerSeriesOnBall (f - g) (pf - pg) x (max n m) r := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem HasFiniteFPowerSeriesAt.sub (hf : HasFiniteFPowerSeriesAt f pf x n) (hg : HasFiniteFPowerSeriesAt g pg x m) : HasFiniteFPowerSeriesAt (f - g) (pf - pg) x (max n m) := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem CPolynomialAt.sub (hf : CPolynomialAt 𝕜 f x) (hg : CPolynomialAt 𝕜 g x) : CPolynomialAt 𝕜 (f - g) x := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem CPolynomialOn.add {s : Set E} (hf : CPolynomialOn 𝕜 f s) (hg : CPolynomialOn 𝕜 g s) : CPolynomialOn 𝕜 (f + g) s := fun z hz => (hf z hz).add (hg z hz) theorem CPolynomialOn.sub {s : Set E} (hf : CPolynomialOn 𝕜 f s) (hg : CPolynomialOn 𝕜 g s) : CPolynomialOn 𝕜 (f - g) s := fun z hz => (hf z hz).sub (hg z hz) /-! ### Continuous multilinear maps We show that continuous multilinear maps are continuously polynomial, and therefore analytic. -/ namespace ContinuousMultilinearMap variable {ι : Type*} {Em : ι → Type*} [∀ i, NormedAddCommGroup (Em i)] [∀ i, NormedSpace 𝕜 (Em i)] [Fintype ι] (f : ContinuousMultilinearMap 𝕜 Em F) {x : Π i, Em i} {s : Set (Π i, Em i)} open FormalMultilinearSeries protected theorem hasFiniteFPowerSeriesOnBall : HasFiniteFPowerSeriesOnBall f f.toFormalMultilinearSeries 0 (Fintype.card ι + 1) ⊤ := .mk' (fun _ hm ↦ dif_neg (Nat.succ_le_iff.mp hm).ne) ENNReal.zero_lt_top fun y _ ↦ by rw [Finset.sum_eq_single_of_mem _ (Finset.self_mem_range_succ _), zero_add] · rw [toFormalMultilinearSeries, dif_pos rfl]; rfl · intro m _ ne; rw [toFormalMultilinearSeries, dif_neg ne.symm]; rfl lemma cpolynomialAt : CPolynomialAt 𝕜 f x := f.hasFiniteFPowerSeriesOnBall.cpolynomialAt_of_mem (by simp only [Metric.emetric_ball_top, Set.mem_univ]) lemma cpolynomialOn : CPolynomialOn 𝕜 f s := fun _ _ ↦ f.cpolynomialAt @[deprecated (since := "2025-02-15")] alias cpolyomialOn := cpolynomialOn lemma analyticOnNhd : AnalyticOnNhd 𝕜 f s := f.cpolynomialOn.analyticOnNhd lemma analyticOn : AnalyticOn 𝕜 f s := f.analyticOnNhd.analyticOn lemma analyticAt : AnalyticAt 𝕜 f x := f.cpolynomialAt.analyticAt lemma analyticWithinAt : AnalyticWithinAt 𝕜 f s x := f.analyticAt.analyticWithinAt end ContinuousMultilinearMap /-! ### Continuous linear maps into continuous multilinear maps We show that a continuous linear map into continuous multilinear maps is continuously polynomial (as a function of two variables, i.e., uncurried). Therefore, it is also analytic. -/ namespace ContinuousLinearMap variable {ι : Type*} {Em : ι → Type*} [∀ i, NormedAddCommGroup (Em i)] [∀ i, NormedSpace 𝕜 (Em i)] [Fintype ι] (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 Em F) {s : Set (G × (Π i, Em i))} {x : G × (Π i, Em i)} /-- Formal multilinear series associated to a linear map into multilinear maps. -/ noncomputable def toFormalMultilinearSeriesOfMultilinear : FormalMultilinearSeries 𝕜 (G × (Π i, Em i)) F := fun n ↦ if h : Fintype.card (Option ι) = n then (f.continuousMultilinearMapOption).domDomCongr (Fintype.equivFinOfCardEq h) else 0 protected theorem hasFiniteFPowerSeriesOnBall_uncurry_of_multilinear : HasFiniteFPowerSeriesOnBall (fun (p : G × (Π i, Em i)) ↦ f p.1 p.2) f.toFormalMultilinearSeriesOfMultilinear 0 (Fintype.card (Option ι) + 1) ⊤ := by apply HasFiniteFPowerSeriesOnBall.mk' ?_ ENNReal.zero_lt_top ?_ · intro m hm apply dif_neg exact Nat.ne_of_lt hm · intro y _ rw [Finset.sum_eq_single_of_mem _ (Finset.self_mem_range_succ _), zero_add] · rw [toFormalMultilinearSeriesOfMultilinear, dif_pos rfl]; rfl · intro m _ ne; rw [toFormalMultilinearSeriesOfMultilinear, dif_neg ne.symm]; rfl lemma cpolynomialAt_uncurry_of_multilinear : CPolynomialAt 𝕜 (fun (p : G × (Π i, Em i)) ↦ f p.1 p.2) x := f.hasFiniteFPowerSeriesOnBall_uncurry_of_multilinear.cpolynomialAt_of_mem (by simp only [Metric.emetric_ball_top, Set.mem_univ]) lemma cpolyomialOn_uncurry_of_multilinear : CPolynomialOn 𝕜 (fun (p : G × (Π i, Em i)) ↦ f p.1 p.2) s := fun _ _ ↦ f.cpolynomialAt_uncurry_of_multilinear lemma analyticOnNhd_uncurry_of_multilinear : AnalyticOnNhd 𝕜 (fun (p : G × (Π i, Em i)) ↦ f p.1 p.2) s := f.cpolyomialOn_uncurry_of_multilinear.analyticOnNhd lemma analyticOn_uncurry_of_multilinear : AnalyticOn 𝕜 (fun (p : G × (Π i, Em i)) ↦ f p.1 p.2) s := f.analyticOnNhd_uncurry_of_multilinear.analyticOn lemma analyticAt_uncurry_of_multilinear : AnalyticAt 𝕜 (fun (p : G × (Π i, Em i)) ↦ f p.1 p.2) x := f.cpolynomialAt_uncurry_of_multilinear.analyticAt lemma analyticWithinAt_uncurry_of_multilinear : AnalyticWithinAt 𝕜 (fun (p : G × (Π i, Em i)) ↦ f p.1 p.2) s x := f.analyticAt_uncurry_of_multilinear.analyticWithinAt end ContinuousLinearMap
Mathlib/Analysis/Analytic/CPolynomial.lean
284
294
/- 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.Data.Countable.Basic import Mathlib.Data.Set.Finite.Basic import Mathlib.Data.Set.Subsingleton import Mathlib.Logic.Equiv.List /-! # Countable sets In this file we define `Set.Countable s` as `Countable s` and prove basic properties of this definition. Note that this definition does not provide a computable encoding. For a noncomputable conversion to `Encodable s`, use `Set.Countable.nonempty_encodable`. ## Keywords sets, countable set -/ assert_not_exists Monoid Multiset.sort noncomputable section open Function Set Encodable universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} namespace Set /-- A set `s` is countable if the corresponding subtype is countable, i.e., there exists an injective map `f : s → ℕ`. Note that this is an abbreviation, so `hs : Set.Countable s` in the proof context is the same as an instance `Countable s`. For a constructive version, see `Encodable`. -/ protected def Countable (s : Set α) : Prop := Countable s @[simp] theorem countable_coe_iff {s : Set α} : Countable s ↔ s.Countable := .rfl /-- Prove `Set.Countable` from a `Countable` instance on the subtype. -/ theorem to_countable (s : Set α) [Countable s] : s.Countable := ‹_› /-- Restate `Set.Countable` as a `Countable` instance. -/ alias ⟨_root_.Countable.to_set, Countable.to_subtype⟩ := countable_coe_iff protected theorem countable_iff_exists_injective {s : Set α} : s.Countable ↔ ∃ f : s → ℕ, Injective f := countable_iff_exists_injective s /-- A set `s : Set α` is countable if and only if there exists a function `α → ℕ` injective on `s`. -/ theorem countable_iff_exists_injOn {s : Set α} : s.Countable ↔ ∃ f : α → ℕ, InjOn f s := Set.countable_iff_exists_injective.trans exists_injOn_iff_injective.symm theorem countable_iff_nonempty_encodable {s : Set α} : s.Countable ↔ Nonempty (Encodable s) := Encodable.nonempty_encodable.symm alias ⟨Countable.nonempty_encodable, _⟩ := countable_iff_nonempty_encodable /-- Convert `Set.Countable s` to `Encodable s` (noncomputable). -/ protected def Countable.toEncodable {s : Set α} (hs : s.Countable) : Encodable s := Classical.choice hs.nonempty_encodable section Enumerate /-- Noncomputably enumerate elements in a set. The `default` value is used to extend the domain to all of `ℕ`. -/ def enumerateCountable {s : Set α} (h : s.Countable) (default : α) : ℕ → α := fun n => match @Encodable.decode s h.toEncodable n with | some y => y | none => default theorem subset_range_enumerate {s : Set α} (h : s.Countable) (default : α) : s ⊆ range (enumerateCountable h default) := fun x hx => ⟨@Encodable.encode s h.toEncodable ⟨x, hx⟩, by letI := h.toEncodable simp [enumerateCountable, Encodable.encodek]⟩ lemma range_enumerateCountable_subset {s : Set α} (h : s.Countable) (default : α) : range (enumerateCountable h default) ⊆ insert default s := by refine range_subset_iff.mpr (fun n ↦ ?_) rw [enumerateCountable] match @decode s (Countable.toEncodable h) n with | none => exact mem_insert _ _ | some val => simp lemma range_enumerateCountable_of_mem {s : Set α} (h : s.Countable) {default : α} (h_mem : default ∈ s) : range (enumerateCountable h default) = s := subset_antisymm ((range_enumerateCountable_subset h _).trans_eq (insert_eq_of_mem h_mem)) (subset_range_enumerate h default) lemma enumerateCountable_mem {s : Set α} (h : s.Countable) {default : α} (h_mem : default ∈ s) (n : ℕ) : enumerateCountable h default n ∈ s := by convert mem_range_self n exact (range_enumerateCountable_of_mem h h_mem).symm end Enumerate theorem Countable.mono {s₁ s₂ : Set α} (h : s₁ ⊆ s₂) (hs : s₂.Countable) : s₁.Countable := have := hs.to_subtype; (inclusion_injective h).countable theorem countable_range [Countable ι] (f : ι → β) : (range f).Countable := surjective_onto_range.countable.to_set theorem countable_iff_exists_subset_range [Nonempty α] {s : Set α} : s.Countable ↔ ∃ f : ℕ → α, s ⊆ range f := ⟨fun h => by inhabit α exact ⟨enumerateCountable h default, subset_range_enumerate _ _⟩, fun ⟨f, hsf⟩ => (countable_range f).mono hsf⟩ /-- A non-empty set is countable iff there exists a surjection from the natural numbers onto the subtype induced by the set. -/ protected theorem countable_iff_exists_surjective {s : Set α} (hs : s.Nonempty) : s.Countable ↔ ∃ f : ℕ → s, Surjective f := @countable_iff_exists_surjective s hs.to_subtype alias ⟨Countable.exists_surjective, _⟩ := Set.countable_iff_exists_surjective theorem countable_univ_iff : (univ : Set α).Countable ↔ Countable α := countable_coe_iff.symm.trans (Equiv.Set.univ _).countable_iff theorem countable_univ [Countable α] : (univ : Set α).Countable := to_countable univ theorem not_countable_univ_iff : ¬ (univ : Set α).Countable ↔ Uncountable α := by rw [countable_univ_iff, not_countable_iff] theorem not_countable_univ [Uncountable α] : ¬ (univ : Set α).Countable := not_countable_univ_iff.2 ‹_› /-- If `s : Set α` is a nonempty countable set, then there exists a map `f : ℕ → α` such that `s = range f`. -/ theorem Countable.exists_eq_range {s : Set α} (hc : s.Countable) (hs : s.Nonempty) : ∃ f : ℕ → α, s = range f := by rcases hc.exists_surjective hs with ⟨f, hf⟩ refine ⟨(↑) ∘ f, ?_⟩ rw [hf.range_comp, Subtype.range_coe] @[simp] theorem countable_empty : (∅ : Set α).Countable := to_countable _ @[simp] theorem countable_singleton (a : α) : ({a} : Set α).Countable := to_countable _ theorem Countable.image {s : Set α} (hs : s.Countable) (f : α → β) : (f '' s).Countable := by
rw [image_eq_range] have := hs.to_subtype apply countable_range theorem MapsTo.countable_of_injOn {s : Set α} {t : Set β} {f : α → β} (hf : MapsTo f s t)
Mathlib/Data/Set/Countable.lean
157
161
/- 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.Topology.Sets.Opens import Mathlib.Topology.Clopen /-! # Closed sets We define a few types of closed sets in a topological space. ## Main Definitions For a topological space `α`, * `TopologicalSpace.Closeds α`: The type of closed sets. * `TopologicalSpace.Clopens α`: The type of clopen sets. -/ open Order OrderDual Set variable {ι α β : Type*} [TopologicalSpace α] [TopologicalSpace β] namespace TopologicalSpace /-! ### Closed sets -/ /-- The type of closed subsets of a topological space. -/ structure Closeds (α : Type*) [TopologicalSpace α] where /-- the carrier set, i.e. the points in this set -/ carrier : Set α isClosed' : IsClosed carrier namespace Closeds instance : SetLike (Closeds α) α where coe := Closeds.carrier coe_injective' s t h := by cases s; cases t; congr instance : CanLift (Set α) (Closeds α) (↑) IsClosed where prf s hs := ⟨⟨s, hs⟩, rfl⟩ theorem isClosed (s : Closeds α) : IsClosed (s : Set α) := s.isClosed' @[deprecated (since := "2025-04-20")] alias closed := isClosed /-- See Note [custom simps projection]. -/ def Simps.coe (s : Closeds α) : Set α := s initialize_simps_projections Closeds (carrier → coe, as_prefix coe) @[ext] protected theorem ext {s t : Closeds α} (h : (s : Set α) = t) : s = t := SetLike.ext' h @[simp] theorem coe_mk (s : Set α) (h) : (mk s h : Set α) = s := rfl /-- The closure of a set, as an element of `TopologicalSpace.Closeds`. -/ @[simps] protected def closure (s : Set α) : Closeds α := ⟨closure s, isClosed_closure⟩ @[simp] theorem mem_closure {s : Set α} {x : α} : x ∈ Closeds.closure s ↔ x ∈ closure s := .rfl theorem gc : GaloisConnection Closeds.closure ((↑) : Closeds α → Set α) := fun _ U => ⟨subset_closure.trans, fun h => closure_minimal h U.isClosed⟩ /-- The galois insertion between sets and closeds. -/ def gi : GaloisInsertion (@Closeds.closure α _) (↑) where choice s hs := ⟨s, closure_eq_iff_isClosed.1 <| hs.antisymm subset_closure⟩ gc := gc le_l_u _ := subset_closure choice_eq _s hs := SetLike.coe_injective <| subset_closure.antisymm hs instance instCompleteLattice : CompleteLattice (Closeds α) := CompleteLattice.copy (GaloisInsertion.liftCompleteLattice gi) -- le _ rfl -- top ⟨univ, isClosed_univ⟩ rfl -- bot ⟨∅, isClosed_empty⟩ (SetLike.coe_injective closure_empty.symm) -- sup (fun s t => ⟨s ∪ t, s.2.union t.2⟩) (funext fun s => funext fun t => SetLike.coe_injective (s.2.union t.2).closure_eq.symm) -- inf (fun s t => ⟨s ∩ t, s.2.inter t.2⟩) rfl -- sSup _ rfl -- sInf (fun S => ⟨⋂ s ∈ S, ↑s, isClosed_biInter fun s _ => s.2⟩) (funext fun _ => SetLike.coe_injective sInf_image.symm) /-- The type of closed sets is inhabited, with default element the empty set. -/ instance : Inhabited (Closeds α) := ⟨⊥⟩ @[simp, norm_cast] theorem coe_sup (s t : Closeds α) : (↑(s ⊔ t) : Set α) = ↑s ∪ ↑t := by rfl @[simp, norm_cast] theorem coe_inf (s t : Closeds α) : (↑(s ⊓ t) : Set α) = ↑s ∩ ↑t := rfl @[simp, norm_cast] theorem coe_top : (↑(⊤ : Closeds α) : Set α) = univ := rfl @[simp, norm_cast] theorem coe_eq_univ {s : Closeds α} : (s : Set α) = univ ↔ s = ⊤ := SetLike.coe_injective.eq_iff' rfl @[simp, norm_cast] theorem coe_bot : (↑(⊥ : Closeds α) : Set α) = ∅ := rfl @[simp, norm_cast] theorem coe_eq_empty {s : Closeds α} : (s : Set α) = ∅ ↔ s = ⊥ := SetLike.coe_injective.eq_iff' rfl theorem coe_nonempty {s : Closeds α} : (s : Set α).Nonempty ↔ s ≠ ⊥ := nonempty_iff_ne_empty.trans coe_eq_empty.not @[simp, norm_cast] theorem coe_sInf {S : Set (Closeds α)} : (↑(sInf S) : Set α) = ⋂ i ∈ S, ↑i := rfl @[simp] lemma coe_sSup {S : Set (Closeds α)} : ((sSup S : Closeds α) : Set α) = closure (⋃₀ ((↑) '' S)) := by rfl @[simp, norm_cast] theorem coe_finset_sup (f : ι → Closeds α) (s : Finset ι) : (↑(s.sup f) : Set α) = s.sup ((↑) ∘ f) := map_finset_sup (⟨⟨(↑), coe_sup⟩, coe_bot⟩ : SupBotHom (Closeds α) (Set α)) _ _ @[simp, norm_cast] theorem coe_finset_inf (f : ι → Closeds α) (s : Finset ι) : (↑(s.inf f) : Set α) = s.inf ((↑) ∘ f) := map_finset_inf (⟨⟨(↑), coe_inf⟩, coe_top⟩ : InfTopHom (Closeds α) (Set α)) _ _ @[simp] theorem mem_sInf {S : Set (Closeds α)} {x : α} : x ∈ sInf S ↔ ∀ s ∈ S, x ∈ s := mem_iInter₂ @[simp] theorem mem_iInf {ι} {x : α} {s : ι → Closeds α} : x ∈ iInf s ↔ ∀ i, x ∈ s i := by simp [iInf] @[simp, norm_cast] theorem coe_iInf {ι} (s : ι → Closeds α) : ((⨅ i, s i : Closeds α) : Set α) = ⋂ i, s i := by ext; simp theorem iInf_def {ι} (s : ι → Closeds α) : ⨅ i, s i = ⟨⋂ i, s i, isClosed_iInter fun i => (s i).2⟩ := by ext1; simp @[simp] theorem iInf_mk {ι} (s : ι → Set α) (h : ∀ i, IsClosed (s i)) : (⨅ i, ⟨s i, h i⟩ : Closeds α) = ⟨⋂ i, s i, isClosed_iInter h⟩ := iInf_def _ /-- Closed sets in a topological space form a coframe. -/ def coframeMinimalAxioms : Coframe.MinimalAxioms (Closeds α) where iInf_sup_le_sup_sInf a s := (SetLike.coe_injective <| by simp only [coe_sup, coe_iInf, coe_sInf, Set.union_iInter₂]).le instance instCoframe : Coframe (Closeds α) := .ofMinimalAxioms coframeMinimalAxioms /-- The term of `TopologicalSpace.Closeds α` corresponding to a singleton. -/ @[simps] def singleton [T1Space α] (x : α) : Closeds α := ⟨{x}, isClosed_singleton⟩ @[simp] lemma mem_singleton [T1Space α] {a b : α} : a ∈ singleton b ↔ a = b := Iff.rfl end Closeds /-- The complement of a closed set as an open set. -/ @[simps] def Closeds.compl (s : Closeds α) : Opens α := ⟨sᶜ, s.2.isOpen_compl⟩ /-- The complement of an open set as a closed set. -/ @[simps] def Opens.compl (s : Opens α) : Closeds α := ⟨sᶜ, s.2.isClosed_compl⟩ nonrec theorem Closeds.compl_compl (s : Closeds α) : s.compl.compl = s := Closeds.ext (compl_compl (s : Set α)) nonrec theorem Opens.compl_compl (s : Opens α) : s.compl.compl = s := Opens.ext (compl_compl (s : Set α)) theorem Closeds.compl_bijective : Function.Bijective (@Closeds.compl α _) := Function.bijective_iff_has_inverse.mpr ⟨Opens.compl, Closeds.compl_compl, Opens.compl_compl⟩ theorem Opens.compl_bijective : Function.Bijective (@Opens.compl α _) := Function.bijective_iff_has_inverse.mpr ⟨Closeds.compl, Opens.compl_compl, Closeds.compl_compl⟩ variable (α) /-- `TopologicalSpace.Closeds.compl` as an `OrderIso` to the order dual of `TopologicalSpace.Opens α`. -/ @[simps] def Closeds.complOrderIso : Closeds α ≃o (Opens α)ᵒᵈ where toFun := OrderDual.toDual ∘ Closeds.compl invFun := Opens.compl ∘ OrderDual.ofDual left_inv s := by simp [Closeds.compl_compl] right_inv s := by simp [Opens.compl_compl] map_rel_iff' := (@OrderDual.toDual_le_toDual (Opens α)).trans compl_subset_compl /-- `TopologicalSpace.Opens.compl` as an `OrderIso` to the order dual of `TopologicalSpace.Closeds α`. -/ @[simps] def Opens.complOrderIso : Opens α ≃o (Closeds α)ᵒᵈ where toFun := OrderDual.toDual ∘ Opens.compl invFun := Closeds.compl ∘ OrderDual.ofDual left_inv s := by simp [Opens.compl_compl] right_inv s := by simp [Closeds.compl_compl] map_rel_iff' := (@OrderDual.toDual_le_toDual (Closeds α)).trans compl_subset_compl variable {α} lemma Closeds.coe_eq_singleton_of_isAtom [T0Space α] {s : Closeds α} (hs : IsAtom s) : ∃ a, (s : Set α) = {a} := by refine minimal_nonempty_closed_eq_singleton s.2 (coe_nonempty.2 hs.1) fun t hts ht ht' ↦ ?_ lift t to Closeds α using ht' exact SetLike.coe_injective.eq_iff.2 <| (hs.le_iff_eq <| coe_nonempty.1 ht).1 hts @[simp, norm_cast] lemma Closeds.isAtom_coe [T1Space α] {s : Closeds α} : IsAtom (s : Set α) ↔ IsAtom s := Closeds.gi.isAtom_iff' rfl (fun t ht ↦ by obtain ⟨x, rfl⟩ := Set.isAtom_iff.1 ht; exact closure_singleton) s /-- in a `T1Space`, atoms of `TopologicalSpace.Closeds α` are precisely the `TopologicalSpace.Closeds.singleton`s. -/ theorem Closeds.isAtom_iff [T1Space α] {s : Closeds α} : IsAtom s ↔ ∃ x, s = Closeds.singleton x := by simp [← Closeds.isAtom_coe, Set.isAtom_iff, SetLike.ext_iff, Set.ext_iff] /-- in a `T1Space`, coatoms of `TopologicalSpace.Opens α` are precisely complements of singletons: `(TopologicalSpace.Closeds.singleton x).compl`. -/ theorem Opens.isCoatom_iff [T1Space α] {s : Opens α} : IsCoatom s ↔ ∃ x, s = (Closeds.singleton x).compl := by rw [← s.compl_compl, ← isAtom_dual_iff_isCoatom] change IsAtom (Closeds.complOrderIso α s.compl) ↔ _ simp only [(Closeds.complOrderIso α).isAtom_iff, Closeds.isAtom_iff, Closeds.compl_bijective.injective.eq_iff]
/-! ### Clopen sets -/ /-- The type of clopen sets of a topological space. -/
Mathlib/Topology/Sets/Closeds.lean
256
260
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.Exact import Mathlib.CategoryTheory.ComposableArrows /-! # Exact sequences A sequence of `n` composable arrows `S : ComposableArrows C` (i.e. a functor `S : Fin (n + 1) ⥤ C`) is said to be exact (`S.Exact`) if the composition of two consecutive arrows are zero (`S.IsComplex`) and the diagram is exact at each `i` for `1 ≤ i < n`. Together with the inductive construction of composable arrows `ComposableArrows.precomp`, this is useful in order to state that certain finite sequences of morphisms are exact (e.g the snake lemma), even though in the applications it would usually be more convenient to use individual lemmas expressing the exactness at a particular object. This implementation is a refactor of `exact_seq` with appeared in the Liquid Tensor Experiment as a property of lists in `Arrow C`. -/ namespace CategoryTheory open Limits variable {C : Type*} [Category C] [HasZeroMorphisms C] /-- The composable arrows associated to a short complex. -/ @[simps!] def ShortComplex.toComposableArrows (S : ShortComplex C) : ComposableArrows C 2 := ComposableArrows.mk₂ S.f S.g /-- A map of short complexes induces a map of composable arrows with the same data. -/ def ShortComplex.mapToComposableArrows {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) : S₁.toComposableArrows ⟶ S₂.toComposableArrows := ComposableArrows.homMk₂ φ.τ₁ φ.τ₂ φ.τ₃ φ.comm₁₂.symm φ.comm₂₃.symm @[simp] theorem ShortComplex.mapToComposableArrows_app_0 {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) : (ShortComplex.mapToComposableArrows φ).app 0 = φ.τ₁ := rfl @[simp] theorem ShortComplex.mapToComposableArrows_app_1 {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) : (ShortComplex.mapToComposableArrows φ).app 1 = φ.τ₂ := rfl @[simp] theorem ShortComplex.mapToComposableArrows_app_2 {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) : (ShortComplex.mapToComposableArrows φ).app 2 = φ.τ₃ := rfl @[simp] theorem ShortComplex.mapToComposableArrows_id {S₁ : ShortComplex C} : (ShortComplex.mapToComposableArrows (𝟙 S₁)) = 𝟙 S₁.toComposableArrows := by aesop_cat @[simp] theorem ShortComplex.mapToComposableArrows_comp {S₁ S₂ S₃ : ShortComplex C} (φ : S₁ ⟶ S₂) (ψ : S₂ ⟶ S₃) : ShortComplex.mapToComposableArrows (φ ≫ ψ) = ShortComplex.mapToComposableArrows φ ≫ ShortComplex.mapToComposableArrows ψ := by aesop_cat namespace ComposableArrows variable {n : ℕ} (S : ComposableArrows C n) /-- `F : ComposableArrows C n` is a complex if all compositions of two consecutive arrows are zero. -/ structure IsComplex : Prop where /-- the composition of two consecutive arrows is zero -/ zero (i : ℕ) (hi : i + 2 ≤ n := by omega) : S.map' i (i + 1) ≫ S.map' (i + 1) (i + 2) = 0 attribute [reassoc] IsComplex.zero variable {S} @[reassoc] lemma IsComplex.zero' (hS : S.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : S.map' i j ≫ S.map' j k = 0 := by subst hij hjk exact hS.zero i hk lemma isComplex_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.IsComplex) : S₂.IsComplex where zero i hi := by rw [← cancel_epi (ComposableArrows.app' e.hom i), comp_zero, ← NatTrans.naturality_assoc, ← NatTrans.naturality, reassoc_of% (h₁.zero i hi), zero_comp] lemma isComplex_iff_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) : S₁.IsComplex ↔ S₂.IsComplex := ⟨isComplex_of_iso e, isComplex_of_iso e.symm⟩ lemma isComplex₀ (S : ComposableArrows C 0) : S.IsComplex where -- See https://github.com/leanprover/lean4/issues/2862 -- Without `decide := true`, simp gets stuck at `hi : autoParam False _auto✝` zero i hi := by simp +decide at hi lemma isComplex₁ (S : ComposableArrows C 1) : S.IsComplex where zero i hi := by omega variable (S) /-- The short complex consisting of maps `S.map' i j` and `S.map' j k` when we know that `S : ComposableArrows C n` satisfies `S.IsComplex`. -/ abbrev sc' (hS : S.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : ShortComplex C := ShortComplex.mk (S.map' i j) (S.map' j k) (hS.zero' i j k) /-- The short complex consisting of maps `S.map' i (i + 1)` and `S.map' (i + 1) (i + 2)` when we know that `S : ComposableArrows C n` satisfies `S.IsComplex`. -/ abbrev sc (hS : S.IsComplex) (i : ℕ) (hi : i + 2 ≤ n := by omega) : ShortComplex C := S.sc' hS i (i + 1) (i + 2) /-- `F : ComposableArrows C n` is exact if it is a complex and that all short complexes consisting of two consecutive arrows are exact. -/ structure Exact : Prop extends S.IsComplex where exact (i : ℕ) (hi : i + 2 ≤ n := by omega) : (S.sc toIsComplex i).Exact variable {S} lemma Exact.exact' (hS : S.Exact) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : (S.sc' hS.toIsComplex i j k).Exact := by subst hij hjk exact hS.exact i hk /-- Functoriality maps for `ComposableArrows.sc'`. -/ @[simps] def sc'Map {S₁ S₂ : ComposableArrows C n} (φ : S₁ ⟶ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : S₁.sc' h₁ i j k ⟶ S₂.sc' h₂ i j k where τ₁ := φ.app _ τ₂ := φ.app _ τ₃ := φ.app _ /-- Functoriality maps for `ComposableArrows.sc`. -/ @[simps!] def scMap {S₁ S₂ : ComposableArrows C n} (φ : S₁ ⟶ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i : ℕ) (hi : i + 2 ≤ n := by omega) : S₁.sc h₁ i ⟶ S₂.sc h₂ i := sc'Map φ h₁ h₂ i (i + 1) (i + 2) /-- The isomorphism `S₁.sc' _ i j k ≅ S₂.sc' _ i j k` induced by an isomorphism `S₁ ≅ S₂` in `ComposableArrows C n`. -/ @[simps] def sc'MapIso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : S₁.sc' h₁ i j k ≅ S₂.sc' h₂ i j k where hom := sc'Map e.hom h₁ h₂ i j k inv := sc'Map e.inv h₂ h₁ i j k hom_inv_id := by ext <;> dsimp <;> simp inv_hom_id := by ext <;> dsimp <;> simp /-- The isomorphism `S₁.sc _ i ≅ S₂.sc _ i` induced by an isomorphism `S₁ ≅ S₂` in `ComposableArrows C n`. -/ @[simps] def scMapIso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i : ℕ) (hi : i + 2 ≤ n := by omega) : S₁.sc h₁ i ≅ S₂.sc h₂ i where hom := scMap e.hom h₁ h₂ i inv := scMap e.inv h₂ h₁ i hom_inv_id := by ext <;> dsimp <;> simp inv_hom_id := by ext <;> dsimp <;> simp lemma exact_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.Exact) : S₂.Exact where toIsComplex := isComplex_of_iso e h₁.toIsComplex exact i hi := ShortComplex.exact_of_iso (scMapIso e h₁.toIsComplex (isComplex_of_iso e h₁.toIsComplex) i) (h₁.exact i hi) lemma exact_iff_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) : S₁.Exact ↔ S₂.Exact := ⟨exact_of_iso e, exact_of_iso e.symm⟩ lemma exact₀ (S : ComposableArrows C 0) : S.Exact where toIsComplex := S.isComplex₀ -- See https://github.com/leanprover/lean4/issues/2862 exact i hi := by simp at hi lemma exact₁ (S : ComposableArrows C 1) : S.Exact where toIsComplex := S.isComplex₁ exact i hi := by exfalso; omega lemma isComplex₂_iff (S : ComposableArrows C 2) : S.IsComplex ↔ S.map' 0 1 ≫ S.map' 1 2 = 0 := by constructor · intro h exact h.zero 0 (by omega) · intro h refine IsComplex.mk (fun i hi => ?_) obtain rfl : i = 0 := by omega exact h lemma isComplex₂_mk (S : ComposableArrows C 2) (w : S.map' 0 1 ≫ S.map' 1 2 = 0) : S.IsComplex := S.isComplex₂_iff.2 w #adaptation_note /-- nightly-2024-03-11 We turn off simprocs here. Ideally someone will investigate whether `simp` lemmas can be rearranged so that this works without the `set_option`, *or* come up with a proposal regarding finer control of disabling simprocs. -/ set_option simprocs false in lemma _root_.CategoryTheory.ShortComplex.isComplex_toComposableArrows (S : ShortComplex C) : S.toComposableArrows.IsComplex := isComplex₂_mk _ (by simp) lemma exact₂_iff (S : ComposableArrows C 2) (hS : S.IsComplex) : S.Exact ↔ (S.sc' hS 0 1 2).Exact := by constructor · intro h exact h.exact 0 (by omega) · intro h refine Exact.mk hS (fun i hi => ?_) obtain rfl : i = 0 := by omega exact h lemma exact₂_mk (S : ComposableArrows C 2) (w : S.map' 0 1 ≫ S.map' 1 2 = 0) (h : (ShortComplex.mk _ _ w).Exact) : S.Exact := (S.exact₂_iff (S.isComplex₂_mk w)).2 h lemma _root_.CategoryTheory.ShortComplex.Exact.exact_toComposableArrows {S : ShortComplex C} (hS : S.Exact) : S.toComposableArrows.Exact := exact₂_mk _ _ hS lemma _root_.CategoryTheory.ShortComplex.exact_iff_exact_toComposableArrows (S : ShortComplex C) : S.Exact ↔ S.toComposableArrows.Exact := (S.toComposableArrows.exact₂_iff S.isComplex_toComposableArrows).symm lemma exact_iff_δ₀ (S : ComposableArrows C (n + 2)) : S.Exact ↔ (mk₂ (S.map' 0 1) (S.map' 1 2)).Exact ∧ S.δ₀.Exact := by constructor · intro h constructor · rw [exact₂_iff]; swap
· rw [isComplex₂_iff] exact h.toIsComplex.zero 0 exact h.exact 0 (by omega) · exact Exact.mk (IsComplex.mk (fun i hi => h.toIsComplex.zero (i + 1))) (fun i hi => h.exact (i + 1)) · rintro ⟨h, h₀⟩ refine Exact.mk (IsComplex.mk (fun i hi => ?_)) (fun i hi => ?_) · obtain _ | i := i · exact h.toIsComplex.zero 0 · exact h₀.toIsComplex.zero i · obtain _ | i := i · exact h.exact 0 · exact h₀.exact i lemma Exact.δ₀ {S : ComposableArrows C (n + 2)} (hS : S.Exact) : S.δ₀.Exact := by rw [exact_iff_δ₀] at hS exact hS.2 /-- If `S : ComposableArrows C (n + 2)` is such that the first two arrows form an exact sequence and that the tail `S.δ₀` is exact, then `S` is also exact.
Mathlib/Algebra/Homology/ExactSequence.lean
250
270
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Eric Wieser -/ import Mathlib.Algebra.Group.Fin.Tuple import Mathlib.Data.Matrix.RowCol import Mathlib.Data.Fin.VecNotation import Mathlib.Tactic.FinCases import Mathlib.Algebra.BigOperators.Fin /-! # Matrix and vector notation This file includes `simp` lemmas for applying operations in `Data.Matrix.Basic` to values built out of the matrix notation `![a, b] = vecCons a (vecCons b vecEmpty)` defined in `Data.Fin.VecNotation`. This also provides the new notation `!![a, b; c, d] = Matrix.of ![![a, b], ![c, d]]`. This notation also works for empty matrices; `!![,,,] : Matrix (Fin 0) (Fin 3)` and `!![;;;] : Matrix (Fin 3) (Fin 0)`. ## 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 This file provide notation `!![a, b; c, d]` for matrices, which corresponds to `Matrix.of ![![a, b], ![c, d]]`. ## Examples Examples of usage can be found in the `MathlibTest/matrix.lean` file. -/ namespace Matrix universe u uₘ uₙ uₒ variable {α : Type u} {o n m : ℕ} {m' : Type uₘ} {n' : Type uₙ} {o' : Type uₒ} open Matrix section toExpr open Lean Qq open Qq in /-- `Matrix.mkLiteralQ !![a, b; c, d]` produces the term `q(!![$a, $b; $c, $d])`. -/ def mkLiteralQ {u : Level} {α : Q(Type u)} {m n : Nat} (elems : Matrix (Fin m) (Fin n) Q($α)) : Q(Matrix (Fin $m) (Fin $n) $α) := let elems := PiFin.mkLiteralQ (α := q(Fin $n → $α)) fun i => PiFin.mkLiteralQ fun j => elems i j q(Matrix.of $elems) /-- Matrices can be reflected whenever their entries can. We insert a `Matrix.of` to prevent immediate decay to a function. -/ protected instance toExpr [ToLevel.{u}] [ToLevel.{uₘ}] [ToLevel.{uₙ}] [Lean.ToExpr α] [Lean.ToExpr m'] [Lean.ToExpr n'] [Lean.ToExpr (m' → n' → α)] : Lean.ToExpr (Matrix m' n' α) := have eα : Q(Type $(toLevel.{u})) := toTypeExpr α have em' : Q(Type $(toLevel.{uₘ})) := toTypeExpr m' have en' : Q(Type $(toLevel.{uₙ})) := toTypeExpr n' { toTypeExpr := q(Matrix $eα $em' $en') toExpr := fun M => have eM : Q($em' → $en' → $eα) := toExpr (show m' → n' → α from M) q(Matrix.of $eM) } end toExpr section Parser open Lean Meta Elab Term Macro TSyntax PrettyPrinter.Delaborator SubExpr /-- Notation for m×n matrices, aka `Matrix (Fin m) (Fin n) α`. For instance: * `!![a, b, c; d, e, f]` is the matrix with two rows and three columns, of type `Matrix (Fin 2) (Fin 3) α` * `!![a, b, c]` is a row vector of type `Matrix (Fin 1) (Fin 3) α` (see also `Matrix.row`). * `!![a; b; c]` is a column vector of type `Matrix (Fin 3) (Fin 1) α` (see also `Matrix.col`). This notation implements some special cases: * `![,,]`, with `n` `,`s, is a term of type `Matrix (Fin 0) (Fin n) α` * `![;;]`, with `m` `;`s, is a term of type `Matrix (Fin m) (Fin 0) α` * `![]` is the 0×0 matrix Note that vector notation is provided elsewhere (by `Matrix.vecNotation`) as `![a, b, c]`. Under the hood, `!![a, b, c; d, e, f]` is syntax for `Matrix.of ![![a, b, c], ![d, e, f]]`. -/ syntax (name := matrixNotation) "!![" ppRealGroup(sepBy1(ppGroup(term,+,?), ";", "; ", allowTrailingSep)) "]" : term @[inherit_doc matrixNotation] syntax (name := matrixNotationRx0) "!![" ";"+ "]" : term @[inherit_doc matrixNotation] syntax (name := matrixNotation0xC) "!![" ","* "]" : term macro_rules | `(!![$[$[$rows],*];*]) => do let m := rows.size let n := if h : 0 < m then rows[0].size else 0 let rowVecs ← rows.mapM fun row : Array Term => do unless row.size = n do Macro.throwErrorAt (mkNullNode row) s!"\ Rows must be of equal length; this row has {row.size} items, \ the previous rows have {n}" `(![$row,*]) `(@Matrix.of (Fin $(quote m)) (Fin $(quote n)) _ ![$rowVecs,*]) | `(!![$[;%$semicolons]*]) => do let emptyVec ← `(![]) let emptyVecs := semicolons.map (fun _ => emptyVec) `(@Matrix.of (Fin $(quote semicolons.size)) (Fin 0) _ ![$emptyVecs,*]) | `(!![$[,%$commas]*]) => `(@Matrix.of (Fin 0) (Fin $(quote commas.size)) _ ![]) /-- Delaborator for the `!![]` notation. -/ @[app_delab DFunLike.coe] def delabMatrixNotation : Delab := whenNotPPOption getPPExplicit <| whenPPOption getPPNotation <| withOverApp 6 do let mkApp3 (.const ``Matrix.of _) (.app (.const ``Fin _) em) (.app (.const ``Fin _) en) _ := (← getExpr).appFn!.appArg! | failure let some m ← withNatValue em (pure ∘ some) | failure let some n ← withNatValue en (pure ∘ some) | failure withAppArg do if m = 0 then guard <| (← getExpr).isAppOfArity ``vecEmpty 1 let commas := .replicate n (mkAtom ",") `(!![$[,%$commas]*]) else if n = 0 then let `(![$[![]%$evecs],*]) ← delab | failure `(!![$[;%$evecs]*]) else let `(![$[![$[$melems],*]],*]) ← delab | failure `(!![$[$[$melems],*];*]) end Parser variable (a b : ℕ) /-- Use `![...]` notation for displaying a `Fin`-indexed matrix, for example: ``` #eval !![1, 2; 3, 4] + !![3, 4; 5, 6] -- !![4, 6; 8, 10] ``` -/ instance repr [Repr α] : Repr (Matrix (Fin m) (Fin n) α) where reprPrec f _p := (Std.Format.bracket "!![" · "]") <| (Std.Format.joinSep · (";" ++ Std.Format.line)) <| (List.finRange m).map fun i => Std.Format.fill <| -- wrap line in a single place rather than all at once (Std.Format.joinSep · ("," ++ Std.Format.line)) <| (List.finRange n).map fun j => _root_.repr (f i j) @[simp] theorem cons_val' (v : n' → α) (B : Fin m → n' → α) (i j) : vecCons v B i j = vecCons (v j) (fun i => B i j) i := by refine Fin.cases ?_ ?_ i <;> simp @[simp] theorem head_val' (B : Fin m.succ → n' → α) (j : n') : (vecHead fun i => B i j) = vecHead B j := rfl @[simp] theorem tail_val' (B : Fin m.succ → n' → α) (j : n') : (vecTail fun i => B i j) = fun i => vecTail B i j := rfl section DotProduct variable [AddCommMonoid α] [Mul α] @[simp] theorem dotProduct_empty (v w : Fin 0 → α) : dotProduct v w = 0 := Finset.sum_empty @[simp] theorem cons_dotProduct (x : α) (v : Fin n → α) (w : Fin n.succ → α) : dotProduct (vecCons x v) w = x * vecHead w + dotProduct v (vecTail w) := by simp [dotProduct, Fin.sum_univ_succ, vecHead, vecTail] @[simp] theorem dotProduct_cons (v : Fin n.succ → α) (x : α) (w : Fin n → α) : dotProduct v (vecCons x w) = vecHead v * x + dotProduct (vecTail v) w := by simp [dotProduct, Fin.sum_univ_succ, vecHead, vecTail] theorem cons_dotProduct_cons (x : α) (v : Fin n → α) (y : α) (w : Fin n → α) : dotProduct (vecCons x v) (vecCons y w) = x * y + dotProduct v w := by simp end DotProduct section ColRow variable {ι : Type*} @[simp] theorem replicateCol_empty (v : Fin 0 → α) : replicateCol ι v = vecEmpty := empty_eq _ @[deprecated (since := "2025-03-20")] alias col_empty := replicateCol_empty @[simp] theorem replicateCol_cons (x : α) (u : Fin m → α) : replicateCol ι (vecCons x u) = of (vecCons (fun _ => x) (replicateCol ι u)) := by ext i j refine Fin.cases ?_ ?_ i <;> simp [vecHead, vecTail] @[deprecated (since := "2025-03-20")] alias col_cons := replicateCol_cons @[simp] theorem replicateRow_empty : replicateRow ι (vecEmpty : Fin 0 → α) = of fun _ => vecEmpty := rfl @[deprecated (since := "2025-03-20")] alias row_empty := replicateRow_empty @[simp] theorem replicateRow_cons (x : α) (u : Fin m → α) : replicateRow ι (vecCons x u) = of fun _ => vecCons x u := rfl @[deprecated (since := "2025-03-20")] alias row_cons := replicateRow_cons end ColRow section Transpose @[simp] theorem transpose_empty_rows (A : Matrix m' (Fin 0) α) : Aᵀ = of ![] := empty_eq _ @[simp] theorem transpose_empty_cols (A : Matrix (Fin 0) m' α) : Aᵀ = of fun _ => ![] := funext fun _ => empty_eq _ @[simp] theorem cons_transpose (v : n' → α) (A : Matrix (Fin m) n' α) : (of (vecCons v A))ᵀ = of fun i => vecCons (v i) (Aᵀ i) := by ext i j refine Fin.cases ?_ ?_ j <;> simp @[simp] theorem head_transpose (A : Matrix m' (Fin n.succ) α) : vecHead (of.symm Aᵀ) = vecHead ∘ of.symm A := rfl @[simp] theorem tail_transpose (A : Matrix m' (Fin n.succ) α) : vecTail (of.symm Aᵀ) = (vecTail ∘ A)ᵀ := by ext i j rfl end Transpose section Mul variable [NonUnitalNonAssocSemiring α] @[simp] theorem empty_mul [Fintype n'] (A : Matrix (Fin 0) n' α) (B : Matrix n' o' α) : A * B = of ![] := empty_eq _ @[simp] theorem empty_mul_empty (A : Matrix m' (Fin 0) α) (B : Matrix (Fin 0) o' α) : A * B = 0 := rfl @[simp] theorem mul_empty [Fintype n'] (A : Matrix m' n' α) (B : Matrix n' (Fin 0) α) : A * B = of fun _ => ![] := funext fun _ => empty_eq _ theorem mul_val_succ [Fintype n'] (A : Matrix (Fin m.succ) n' α) (B : Matrix n' o' α) (i : Fin m) (j : o') : (A * B) i.succ j = (of (vecTail (of.symm A)) * B) i j := rfl @[simp] theorem cons_mul [Fintype n'] (v : n' → α) (A : Fin m → n' → α) (B : Matrix n' o' α) : of (vecCons v A) * B = of (vecCons (v ᵥ* B) (of.symm (of A * B))) := by ext i j refine Fin.cases ?_ ?_ i · rfl simp [mul_val_succ] end Mul section VecMul variable [NonUnitalNonAssocSemiring α] @[simp] theorem empty_vecMul (v : Fin 0 → α) (B : Matrix (Fin 0) o' α) : v ᵥ* B = 0 := rfl @[simp] theorem vecMul_empty [Fintype n'] (v : n' → α) (B : Matrix n' (Fin 0) α) : v ᵥ* B = ![] := empty_eq _ @[simp] theorem cons_vecMul (x : α) (v : Fin n → α) (B : Fin n.succ → o' → α) : vecCons x v ᵥ* of B = x • vecHead B + v ᵥ* of (vecTail B) := by ext i simp [vecMul] @[simp] theorem vecMul_cons (v : Fin n.succ → α) (w : o' → α) (B : Fin n → o' → α) : v ᵥ* of (vecCons w B) = vecHead v • w + vecTail v ᵥ* of B := by ext i simp [vecMul] theorem cons_vecMul_cons (x : α) (v : Fin n → α) (w : o' → α) (B : Fin n → o' → α) : vecCons x v ᵥ* of (vecCons w B) = x • w + v ᵥ* of B := by simp end VecMul section MulVec variable [NonUnitalNonAssocSemiring α] @[simp] theorem empty_mulVec [Fintype n'] (A : Matrix (Fin 0) n' α) (v : n' → α) : A *ᵥ v = ![] := empty_eq _ @[simp] theorem mulVec_empty (A : Matrix m' (Fin 0) α) (v : Fin 0 → α) : A *ᵥ v = 0 := rfl @[simp] theorem cons_mulVec [Fintype n'] (v : n' → α) (A : Fin m → n' → α) (w : n' → α) : (of <| vecCons v A) *ᵥ w = vecCons (dotProduct v w) (of A *ᵥ w) := by ext i refine Fin.cases ?_ ?_ i <;> simp [mulVec] @[simp] theorem mulVec_cons {α} [NonUnitalCommSemiring α] (A : m' → Fin n.succ → α) (x : α) (v : Fin n → α) : (of A) *ᵥ (vecCons x v) = x • vecHead ∘ A + (of (vecTail ∘ A)) *ᵥ v := by ext i simp [mulVec, mul_comm] end MulVec section VecMulVec variable [NonUnitalNonAssocSemiring α] @[simp] theorem empty_vecMulVec (v : Fin 0 → α) (w : n' → α) : vecMulVec v w = ![] := empty_eq _ @[simp] theorem vecMulVec_empty (v : m' → α) (w : Fin 0 → α) : vecMulVec v w = of fun _ => ![] := funext fun _ => empty_eq _ @[simp] theorem cons_vecMulVec (x : α) (v : Fin m → α) (w : n' → α) : vecMulVec (vecCons x v) w = vecCons (x • w) (vecMulVec v w) := by ext i refine Fin.cases ?_ ?_ i <;> simp [vecMulVec] @[simp] theorem vecMulVec_cons (v : m' → α) (x : α) (w : Fin n → α) : vecMulVec v (vecCons x w) = of fun i => v i • vecCons x w := rfl end VecMulVec section SMul variable [NonUnitalNonAssocSemiring α] theorem smul_mat_empty {m' : Type*} (x : α) (A : Fin 0 → m' → α) : x • A = ![] := empty_eq _ theorem smul_mat_cons (x : α) (v : n' → α) (A : Fin m → n' → α) : x • vecCons v A = vecCons (x • v) (x • A) := by ext i refine Fin.cases ?_ ?_ i <;> simp end SMul
section Submatrix @[simp] theorem submatrix_empty (A : Matrix m' n' α) (row : Fin 0 → m') (col : o' → n') :
Mathlib/Data/Matrix/Notation.lean
379
382
/- 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.Ordmap.Invariants /-! # Verification of `Ordnode` This file uses the invariants defined in `Mathlib.Data.Ordmap.Invariants` to construct `Ordset α`, a wrapper around `Ordnode α` which includes the correctness invariant of the type. 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 * `Ordnode.Valid`: The validity predicate for an `Ordnode` subtree. * `Ordset α`: A well formed set of values of type `α`. ## Implementation notes 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. -/ variable {α : Type*} namespace Ordnode section Valid variable [Preorder α] /-- The validity predicate for an `Ordnode` subtree. This asserts that the `size` fields are correct, the tree is balanced, and the elements of the tree are organized according to the ordering. This version of `Valid` also puts all elements in the tree in the interval `(lo, hi)`. -/ structure Valid' (lo : WithBot α) (t : Ordnode α) (hi : WithTop α) : Prop where ord : t.Bounded lo hi sz : t.Sized bal : t.Balanced /-- The validity predicate for an `Ordnode` subtree. This asserts that the `size` fields are correct, the tree is balanced, and the elements of the tree are organized according to the ordering. -/ def Valid (t : Ordnode α) : Prop := Valid' ⊥ t ⊤ theorem Valid'.mono_left {x y : α} (xy : x ≤ y) {t : Ordnode α} {o} (h : Valid' y t o) : Valid' x t o := ⟨h.1.mono_left xy, h.2, h.3⟩ theorem Valid'.mono_right {x y : α} (xy : x ≤ y) {t : Ordnode α} {o} (h : Valid' o t x) : Valid' o t y := ⟨h.1.mono_right xy, h.2, h.3⟩ theorem Valid'.trans_left {t₁ t₂ : Ordnode α} {x : α} {o₁ o₂} (h : Bounded t₁ o₁ x) (H : Valid' x t₂ o₂) : Valid' o₁ t₂ o₂ := ⟨h.trans_left H.1, H.2, H.3⟩ theorem Valid'.trans_right {t₁ t₂ : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t₁ x) (h : Bounded t₂ x o₂) : Valid' o₁ t₁ o₂ := ⟨H.1.trans_right h, H.2, H.3⟩ theorem Valid'.of_lt {t : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t o₂) (h₁ : Bounded nil o₁ x) (h₂ : All (· < x) t) : Valid' o₁ t x := ⟨H.1.of_lt h₁ h₂, H.2, H.3⟩ theorem Valid'.of_gt {t : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t o₂) (h₁ : Bounded nil x o₂) (h₂ : All (· > x) t) : Valid' x t o₂ := ⟨H.1.of_gt h₁ h₂, H.2, H.3⟩ theorem Valid'.valid {t o₁ o₂} (h : @Valid' α _ o₁ t o₂) : Valid t := ⟨h.1.weak, h.2, h.3⟩ theorem valid'_nil {o₁ o₂} (h : Bounded nil o₁ o₂) : Valid' o₁ (@nil α) o₂ := ⟨h, ⟨⟩, ⟨⟩⟩ theorem valid_nil : Valid (@nil α) := valid'_nil ⟨⟩ theorem Valid'.node {s l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : BalancedSz (size l) (size r)) (hs : s = size l + size r + 1) : Valid' o₁ (@node α s l x r) o₂ := ⟨⟨hl.1, hr.1⟩, ⟨hs, hl.2, hr.2⟩, ⟨H, hl.3, hr.3⟩⟩ theorem Valid'.dual : ∀ {t : Ordnode α} {o₁ o₂}, Valid' o₁ t o₂ → @Valid' αᵒᵈ _ o₂ (dual t) o₁ | .nil, _, _, h => valid'_nil h.1.dual | .node _ l _ r, _, _, ⟨⟨ol, Or⟩, ⟨rfl, sl, sr⟩, ⟨b, bl, br⟩⟩ => let ⟨ol', sl', bl'⟩ := Valid'.dual ⟨ol, sl, bl⟩ let ⟨or', sr', br'⟩ := Valid'.dual ⟨Or, sr, br⟩ ⟨⟨or', ol'⟩, ⟨by simp [size_dual, add_comm], sr', sl'⟩, ⟨by rw [size_dual, size_dual]; exact b.symm, br', bl'⟩⟩ theorem Valid'.dual_iff {t : Ordnode α} {o₁ o₂} : Valid' o₁ t o₂ ↔ @Valid' αᵒᵈ _ o₂ (.dual t) o₁ := ⟨Valid'.dual, fun h => by have := Valid'.dual h; rwa [dual_dual, OrderDual.Preorder.dual_dual] at this⟩ theorem Valid.dual {t : Ordnode α} : Valid t → @Valid αᵒᵈ _ (.dual t) := Valid'.dual theorem Valid.dual_iff {t : Ordnode α} : Valid t ↔ @Valid αᵒᵈ _ (.dual t) := Valid'.dual_iff theorem Valid'.left {s l x r o₁ o₂} (H : Valid' o₁ (@Ordnode.node α s l x r) o₂) : Valid' o₁ l x := ⟨H.1.1, H.2.2.1, H.3.2.1⟩ theorem Valid'.right {s l x r o₁ o₂} (H : Valid' o₁ (@Ordnode.node α s l x r) o₂) : Valid' x r o₂ := ⟨H.1.2, H.2.2.2, H.3.2.2⟩ nonrec theorem Valid.left {s l x r} (H : Valid (@node α s l x r)) : Valid l := H.left.valid nonrec theorem Valid.right {s l x r} (H : Valid (@node α s l x r)) : Valid r := H.right.valid theorem Valid.size_eq {s l x r} (H : Valid (@node α s l x r)) : size (@node α s l x r) = size l + size r + 1 := H.2.1 theorem Valid'.node' {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : BalancedSz (size l) (size r)) : Valid' o₁ (@node' α l x r) o₂ := hl.node hr H rfl theorem valid'_singleton {x : α} {o₁ o₂} (h₁ : Bounded nil o₁ x) (h₂ : Bounded nil x o₂) : Valid' o₁ (singleton x : Ordnode α) o₂ := (valid'_nil h₁).node (valid'_nil h₂) (Or.inl zero_le_one) rfl theorem valid_singleton {x : α} : Valid (singleton x : Ordnode α) := valid'_singleton ⟨⟩ ⟨⟩ theorem Valid'.node3L {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y) (hr : Valid' y r o₂) (H1 : BalancedSz (size l) (size m)) (H2 : BalancedSz (size l + size m + 1) (size r)) : Valid' o₁ (@node3L α l x m y r) o₂ := (hl.node' hm H1).node' hr H2 theorem Valid'.node3R {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y) (hr : Valid' y r o₂) (H1 : BalancedSz (size l) (size m + size r + 1)) (H2 : BalancedSz (size m) (size r)) : Valid' o₁ (@node3R α l x m y r) o₂ := hl.node' (hm.node' hr H2) H1 theorem Valid'.node4L_lemma₁ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9) (mr₂ : b + c + 1 ≤ 3 * d) (mm₁ : b ≤ 3 * c) : b < 3 * a + 1 := by omega theorem Valid'.node4L_lemma₂ {b c d : ℕ} (mr₂ : b + c + 1 ≤ 3 * d) : c ≤ 3 * d := by omega theorem Valid'.node4L_lemma₃ {b c d : ℕ} (mr₁ : 2 * d ≤ b + c + 1) (mm₁ : b ≤ 3 * c) : d ≤ 3 * c := by omega theorem Valid'.node4L_lemma₄ {a b c d : ℕ} (lr₁ : 3 * a ≤ b + c + 1 + d) (mr₂ : b + c + 1 ≤ 3 * d) (mm₁ : b ≤ 3 * c) : a + b + 1 ≤ 3 * (c + d + 1) := by omega theorem Valid'.node4L_lemma₅ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9) (mr₁ : 2 * d ≤ b + c + 1) (mm₂ : c ≤ 3 * b) : c + d + 1 ≤ 3 * (a + b + 1) := by omega theorem Valid'.node4L {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y) (hr : Valid' (↑y) r o₂) (Hm : 0 < size m) (H : size l = 0 ∧ size m = 1 ∧ size r ≤ 1 ∨ 0 < size l ∧ ratio * size r ≤ size m ∧ delta * size l ≤ size m + size r ∧ 3 * (size m + size r) ≤ 16 * size l + 9 ∧ size m ≤ delta * size r) : Valid' o₁ (@node4L α l x m y r) o₂ := by obtain - | ⟨s, ml, z, mr⟩ := m; · cases Hm suffices BalancedSz (size l) (size ml) ∧ BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1) from Valid'.node' (hl.node' hm.left this.1) (hm.right.node' hr this.2.1) this.2.2 rcases H with (⟨l0, m1, r0⟩ | ⟨l0, mr₁, lr₁, lr₂, mr₂⟩) · rw [hm.2.size_eq, Nat.succ_inj, add_eq_zero] at m1 rw [l0, m1.1, m1.2]; revert r0; rcases size r with (_ | _ | _) <;> [decide; decide; (intro r0; unfold BalancedSz delta; omega)] · rcases Nat.eq_zero_or_pos (size r) with r0 | r0 · rw [r0] at mr₂; cases not_le_of_lt Hm mr₂ rw [hm.2.size_eq] at lr₁ lr₂ mr₁ mr₂ by_cases mm : size ml + size mr ≤ 1 · have r1 := le_antisymm ((mul_le_mul_left (by decide)).1 (le_trans mr₁ (Nat.succ_le_succ mm) : _ ≤ ratio * 1)) r0 rw [r1, add_assoc] at lr₁ have l1 := le_antisymm ((mul_le_mul_left (by decide)).1 (le_trans lr₁ (add_le_add_right mm 2) : _ ≤ delta * 1)) l0 rw [l1, r1] revert mm; cases size ml <;> cases size mr <;> intro mm · decide · rw [zero_add] at mm; rcases mm with (_ | ⟨⟨⟩⟩) decide · rcases mm with (_ | ⟨⟨⟩⟩); decide · rw [Nat.succ_add] at mm; rcases mm with (_ | ⟨⟨⟩⟩) rcases hm.3.1.resolve_left mm with ⟨mm₁, mm₂⟩ rcases Nat.eq_zero_or_pos (size ml) with ml0 | ml0 · rw [ml0, mul_zero, Nat.le_zero] at mm₂ rw [ml0, mm₂] at mm; cases mm (by decide) have : 2 * size l ≤ size ml + size mr + 1 := by have := Nat.mul_le_mul_left ratio lr₁ rw [mul_left_comm, mul_add] at this have := le_trans this (add_le_add_left mr₁ _) rw [← Nat.succ_mul] at this exact (mul_le_mul_left (by decide)).1 this refine ⟨Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩⟩ · refine (mul_le_mul_left (by decide)).1 (le_trans this ?_) rw [two_mul, Nat.succ_le_iff] refine add_lt_add_of_lt_of_le ?_ mm₂ simpa using (mul_lt_mul_right ml0).2 (by decide : 1 < 3) · exact Nat.le_of_lt_succ (Valid'.node4L_lemma₁ lr₂ mr₂ mm₁) · exact Valid'.node4L_lemma₂ mr₂ · exact Valid'.node4L_lemma₃ mr₁ mm₁ · exact Valid'.node4L_lemma₄ lr₁ mr₂ mm₁ · exact Valid'.node4L_lemma₅ lr₂ mr₁ mm₂ theorem Valid'.rotateL_lemma₁ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (hb₂ : c ≤ 3 * b) : a ≤ 3 * b := by omega theorem Valid'.rotateL_lemma₂ {a b c : ℕ} (H3 : 2 * (b + c) ≤ 9 * a + 3) (h : b < 2 * c) : b < 3 * a + 1 := by omega theorem Valid'.rotateL_lemma₃ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (h : b < 2 * c) : a + b < 3 * c := by omega theorem Valid'.rotateL_lemma₄ {a b : ℕ} (H3 : 2 * b ≤ 9 * a + 3) : 3 * b ≤ 16 * a + 9 := by omega theorem Valid'.rotateL {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H1 : ¬size l + size r ≤ 1) (H2 : delta * size l < size r) (H3 : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3) : Valid' o₁ (@rotateL α l x r) o₂ := by obtain - | ⟨rs, rl, rx, rr⟩ := r; · cases H2 rw [hr.2.size_eq, Nat.lt_succ_iff] at H2 rw [hr.2.size_eq] at H3 replace H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2 := H3.imp (@Nat.le_of_add_le_add_right _ 2 _) Nat.le_of_succ_le_succ have H3_0 : size l = 0 → size rl + size rr ≤ 2 := by intro l0; rw [l0] at H3 exact (or_iff_right_of_imp fun h => (mul_le_mul_left (by decide)).1 (le_trans h (by decide))).1 H3 have H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3 := fun l0 : 1 ≤ size l => (or_iff_left_of_imp <| by omega).1 H3 have ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1 := by omega have hlp : size l > 0 → ¬size rl + size rr ≤ 1 := fun l0 hb => absurd (le_trans (le_trans (Nat.mul_le_mul_left _ l0) H2) hb) (by decide) rw [Ordnode.rotateL_node]; split_ifs with h · have rr0 : size rr > 0 := (mul_lt_mul_left (by decide)).1 (lt_of_le_of_lt (Nat.zero_le _) h : ratio * 0 < _) suffices BalancedSz (size l) (size rl) ∧ BalancedSz (size l + size rl + 1) (size rr) by exact hl.node3L hr.left hr.right this.1 this.2 rcases Nat.eq_zero_or_pos (size l) with l0 | l0 · rw [l0]; replace H3 := H3_0 l0 have := hr.3.1 rcases Nat.eq_zero_or_pos (size rl) with rl0 | rl0 · rw [rl0] at this ⊢ rw [le_antisymm (balancedSz_zero.1 this.symm) rr0] decide have rr1 : size rr = 1 := le_antisymm (ablem rl0 H3) rr0 rw [add_comm] at H3 rw [rr1, show size rl = 1 from le_antisymm (ablem rr0 H3) rl0] decide replace H3 := H3p l0 rcases hr.3.1.resolve_left (hlp l0) with ⟨_, hb₂⟩ refine ⟨Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩⟩ · exact Valid'.rotateL_lemma₁ H2 hb₂ · exact Nat.le_of_lt_succ (Valid'.rotateL_lemma₂ H3 h) · exact Valid'.rotateL_lemma₃ H2 h · exact le_trans hb₂ (Nat.mul_le_mul_left _ <| le_trans (Nat.le_add_left _ _) (Nat.le_add_right _ _)) · rcases Nat.eq_zero_or_pos (size rl) with rl0 | rl0 · rw [rl0, not_lt, Nat.le_zero, Nat.mul_eq_zero] at h replace h := h.resolve_left (by decide) rw [rl0, h, Nat.le_zero, Nat.mul_eq_zero] at H2 rw [hr.2.size_eq, rl0, h, H2.resolve_left (by decide)] at H1 cases H1 (by decide) refine hl.node4L hr.left hr.right rl0 ?_ rcases Nat.eq_zero_or_pos (size l) with l0 | l0 · replace H3 := H3_0 l0 rcases Nat.eq_zero_or_pos (size rr) with rr0 | rr0 · have := hr.3.1 rw [rr0] at this exact Or.inl ⟨l0, le_antisymm (balancedSz_zero.1 this) rl0, rr0.symm ▸ zero_le_one⟩ exact Or.inl ⟨l0, le_antisymm (ablem rr0 <| by rwa [add_comm]) rl0, ablem rl0 H3⟩ exact Or.inr ⟨l0, not_lt.1 h, H2, Valid'.rotateL_lemma₄ (H3p l0), (hr.3.1.resolve_left (hlp l0)).1⟩ theorem Valid'.rotateR {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H1 : ¬size l + size r ≤ 1) (H2 : delta * size r < size l) (H3 : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@rotateR α l x r) o₂ := by refine Valid'.dual_iff.2 ?_ rw [dual_rotateR] refine hr.dual.rotateL hl.dual ?_ ?_ ?_ · rwa [size_dual, size_dual, add_comm] · rwa [size_dual, size_dual] · rwa [size_dual, size_dual] theorem Valid'.balance'_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H₁ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3) (H₂ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@balance' α l x r) o₂ := by rw [balance']; split_ifs with h h_1 h_2 · exact hl.node' hr (Or.inl h) · exact hl.rotateL hr h h_1 H₁ · exact hl.rotateR hr h h_2 H₂ · exact hl.node' hr (Or.inr ⟨not_lt.1 h_2, not_lt.1 h_1⟩) theorem Valid'.balance'_lemma {α l l' r r'} (H1 : BalancedSz l' r') (H2 : Nat.dist (@size α l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l') : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3 := by suffices @size α r ≤ 3 * (size l + 1) by omega rcases H2 with (⟨hl, rfl⟩ | ⟨hr, rfl⟩) <;> rcases H1 with (h | ⟨_, h₂⟩) · exact le_trans (Nat.le_add_left _ _) (le_trans h (Nat.le_add_left _ _)) · exact le_trans h₂ (Nat.mul_le_mul_left _ <| le_trans (Nat.dist_tri_right _ _) (Nat.add_le_add_left hl _)) · exact le_trans (Nat.dist_tri_left' _ _) (le_trans (add_le_add hr (le_trans (Nat.le_add_left _ _) h)) (by omega)) · rw [Nat.mul_succ] exact le_trans (Nat.dist_tri_right' _ _) (add_le_add h₂ (le_trans hr (by decide))) theorem Valid'.balance' {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : ∃ l' r', BalancedSz l' r' ∧ (Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')) : Valid' o₁ (@balance' α l x r) o₂ := let ⟨_, _, H1, H2⟩ := H Valid'.balance'_aux hl hr (Valid'.balance'_lemma H1 H2) (Valid'.balance'_lemma H1.symm H2.symm) theorem Valid'.balance {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : ∃ l' r', BalancedSz l' r' ∧ (Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')) : Valid' o₁ (@balance α l x r) o₂ := by rw [balance_eq_balance' hl.3 hr.3 hl.2 hr.2]; exact hl.balance' hr H theorem Valid'.balanceL_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H₁ : size l = 0 → size r ≤ 1) (H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) (H₃ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@balanceL α l x r) o₂ := by rw [balanceL_eq_balance hl.2 hr.2 H₁ H₂, balance_eq_balance' hl.3 hr.3 hl.2 hr.2] refine hl.balance'_aux hr (Or.inl ?_) H₃ rcases Nat.eq_zero_or_pos (size r) with r0 | r0 · rw [r0]; exact Nat.zero_le _ rcases Nat.eq_zero_or_pos (size l) with l0 | l0 · rw [l0]; exact le_trans (Nat.mul_le_mul_left _ (H₁ l0)) (by decide) replace H₂ : _ ≤ 3 * _ := H₂ l0 r0; omega theorem Valid'.balanceL {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r') : Valid' o₁ (@balanceL α l x r) o₂ := by rw [balanceL_eq_balance' hl.3 hr.3 hl.2 hr.2 H] refine hl.balance' hr ?_ rcases H with (⟨l', e, H⟩ | ⟨r', e, H⟩) · exact ⟨_, _, H, Or.inl ⟨e.dist_le', rfl⟩⟩ · exact ⟨_, _, H, Or.inr ⟨e.dist_le, rfl⟩⟩ theorem Valid'.balanceR_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H₁ : size r = 0 → size l ≤ 1) (H₂ : 1 ≤ size r → 1 ≤ size l → size l ≤ delta * size r) (H₃ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3) : Valid' o₁ (@balanceR α l x r) o₂ := by rw [Valid'.dual_iff, dual_balanceR] have := hr.dual.balanceL_aux hl.dual rw [size_dual, size_dual] at this exact this H₁ H₂ H₃ theorem Valid'.balanceR {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised r' (size r) ∧ BalancedSz (size l) r') : Valid' o₁ (@balanceR α l x r) o₂ := by rw [Valid'.dual_iff, dual_balanceR]; exact hr.dual.balanceL hl.dual (balance_sz_dual H) theorem Valid'.eraseMax_aux {s l x r o₁ o₂} (H : Valid' o₁ (.node s l x r) o₂) : Valid' o₁ (@eraseMax α (.node' l x r)) ↑(findMax' x r) ∧ size (.node' l x r) = size (eraseMax (.node' l x r)) + 1 := by have := H.2.eq_node'; rw [this] at H; clear this induction r generalizing l x o₁ with | nil => exact ⟨H.left, rfl⟩ | node rs rl rx rr _ IHrr => have := H.2.2.2.eq_node'; rw [this] at H ⊢ rcases IHrr H.right with ⟨h, e⟩ refine ⟨Valid'.balanceL H.left h (Or.inr ⟨_, Or.inr e, H.3.1⟩), ?_⟩ rw [eraseMax, size_balanceL H.3.2.1 h.3 H.2.2.1 h.2 (Or.inr ⟨_, Or.inr e, H.3.1⟩)] rw [size_node, e]; rfl theorem Valid'.eraseMin_aux {s l} {x : α} {r o₁ o₂} (H : Valid' o₁ (.node s l x r) o₂) : Valid' ↑(findMin' l x) (@eraseMin α (.node' l x r)) o₂ ∧ size (.node' l x r) = size (eraseMin (.node' l x r)) + 1 := by have := H.dual.eraseMax_aux rwa [← dual_node', size_dual, ← dual_eraseMin, size_dual, ← Valid'.dual_iff, findMax'_dual] at this theorem eraseMin.valid : ∀ {t}, @Valid α _ t → Valid (eraseMin t) | nil, _ => valid_nil | node _ l x r, h => by rw [h.2.eq_node']; exact h.eraseMin_aux.1.valid theorem eraseMax.valid {t} (h : @Valid α _ t) : Valid (eraseMax t) := by rw [Valid.dual_iff, dual_eraseMax]; exact eraseMin.valid h.dual theorem Valid'.glue_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂) (sep : l.All fun x => r.All fun y => x < y) (bal : BalancedSz (size l) (size r)) : Valid' o₁ (@glue α l r) o₂ ∧ size (glue l r) = size l + size r := by obtain - | ⟨ls, ll, lx, lr⟩ := l; · exact ⟨hr, (zero_add _).symm⟩ obtain - | ⟨rs, rl, rx, rr⟩ := r; · exact ⟨hl, rfl⟩ dsimp [glue]; split_ifs · rw [splitMax_eq] · obtain ⟨v, e⟩ := Valid'.eraseMax_aux hl suffices H : _ by refine ⟨Valid'.balanceR v (hr.of_gt ?_ ?_) H, ?_⟩ · refine findMax'_all (P := fun a : α => Bounded nil (a : WithTop α) o₂) lx lr hl.1.2.to_nil (sep.2.2.imp ?_) exact fun x h => hr.1.2.to_nil.mono_left (le_of_lt h.2.1) · exact @findMax'_all _ (fun a => All (· > a) (.node rs rl rx rr)) lx lr sep.2.1 sep.2.2 · rw [size_balanceR v.3 hr.3 v.2 hr.2 H, add_right_comm, ← e, hl.2.1]; rfl refine Or.inl ⟨_, Or.inr e, ?_⟩ rwa [hl.2.eq_node'] at bal · rw [splitMin_eq] · obtain ⟨v, e⟩ := Valid'.eraseMin_aux hr suffices H : _ by refine ⟨Valid'.balanceL (hl.of_lt ?_ ?_) v H, ?_⟩ · refine @findMin'_all (P := fun a : α => Bounded nil o₁ (a : WithBot α)) _ rl rx (sep.2.1.1.imp ?_) hr.1.1.to_nil exact fun y h => hl.1.1.to_nil.mono_right (le_of_lt h) · exact @findMin'_all _ (fun a => All (· < a) (.node ls ll lx lr)) rl rx (all_iff_forall.2 fun x hx => sep.imp fun y hy => all_iff_forall.1 hy.1 _ hx) (sep.imp fun y hy => hy.2.1) · rw [size_balanceL hl.3 v.3 hl.2 v.2 H, add_assoc, ← e, hr.2.1]; rfl refine Or.inr ⟨_, Or.inr e, ?_⟩ rwa [hr.2.eq_node'] at bal theorem Valid'.glue {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) : BalancedSz (size l) (size r) → Valid' o₁ (@glue α l r) o₂ ∧ size (@glue α l r) = size l + size r := Valid'.glue_aux (hl.trans_right hr.1) (hr.trans_left hl.1) (hl.1.to_sep hr.1) theorem Valid'.merge_lemma {a b c : ℕ} (h₁ : 3 * a < b + c + 1) (h₂ : b ≤ 3 * c) : 2 * (a + b) ≤ 9 * c + 5 := by omega theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t} (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂) (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) : Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by rw [hl.2.1] at e rw [hl.2.1, hr.2.1, delta] at h rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · omega suffices H₂ : _ by suffices H₁ : _ by refine ⟨Valid'.balanceL_aux v hr.right H₁ H₂ ?_, ?_⟩ · rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁) · rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2, size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1] abel · rw [e, add_right_comm]; rintro ⟨⟩ intro _ _; rw [e]; unfold delta at hr₂ ⊢; omega theorem Valid'.merge_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂) (sep : l.All fun x => r.All fun y => x < y) : Valid' o₁ (@merge α l r) o₂ ∧ size (merge l r) = size l + size r := by induction l generalizing o₁ o₂ r with | nil => exact ⟨hr, (zero_add _).symm⟩ | node ls ll lx lr _ IHlr => ?_ induction r generalizing o₁ o₂ with | nil => exact ⟨hl, rfl⟩ | node rs rl rx rr IHrl _ => ?_ rw [merge_node]; split_ifs with h h_1 · obtain ⟨v, e⟩ := IHrl (hl.of_lt hr.1.1.to_nil <| sep.imp fun x h => h.2.1) hr.left (sep.imp fun x h => h.1) exact Valid'.merge_aux₁ hl hr h v e · obtain ⟨v, e⟩ := IHlr hl.right (hr.of_gt hl.1.2.to_nil sep.2.1) sep.2.2 have := Valid'.merge_aux₁ hr.dual hl.dual h_1 v.dual rw [size_dual, add_comm, size_dual, ← dual_balanceR, ← Valid'.dual_iff, size_dual, add_comm rs] at this exact this e · refine Valid'.glue_aux hl hr sep (Or.inr ⟨not_lt.1 h_1, not_lt.1 h⟩) theorem Valid.merge {l r} (hl : Valid l) (hr : Valid r) (sep : l.All fun x => r.All fun y => x < y) : Valid (@merge α l r) := (Valid'.merge_aux hl hr sep).1 theorem insertWith.valid_aux [IsTotal α (· ≤ ·)] [DecidableLE α] (f : α → α) (x : α) (hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) : ∀ {t o₁ o₂}, Valid' o₁ t o₂ → Bounded nil o₁ x → Bounded nil x o₂ → Valid' o₁ (insertWith f x t) o₂ ∧ Raised (size t) (size (insertWith f x t)) | nil, _, _, _, bl, br => ⟨valid'_singleton bl br, Or.inr rfl⟩ | node sz l y r, o₁, o₂, h, bl, br => by rw [insertWith, cmpLE] split_ifs with h_1 h_2 <;> dsimp only · rcases h with ⟨⟨lx, xr⟩, hs, hb⟩ rcases hf _ ⟨h_1, h_2⟩ with ⟨xf, fx⟩ refine ⟨⟨⟨lx.mono_right (le_trans h_2 xf), xr.mono_left (le_trans fx h_1)⟩, hs, hb⟩, Or.inl rfl⟩ · rcases insertWith.valid_aux f x hf h.left bl (lt_of_le_not_le h_1 h_2) with ⟨vl, e⟩ suffices H : _ by refine ⟨vl.balanceL h.right H, ?_⟩ rw [size_balanceL vl.3 h.3.2.2 vl.2 h.2.2.2 H, h.2.size_eq] exact (e.add_right _).add_right _ exact Or.inl ⟨_, e, h.3.1⟩ · have : y < x := lt_of_le_not_le ((total_of (· ≤ ·) _ _).resolve_left h_1) h_1 rcases insertWith.valid_aux f x hf h.right this br with ⟨vr, e⟩ suffices H : _ by refine ⟨h.left.balanceR vr H, ?_⟩ rw [size_balanceR h.3.2.1 vr.3 h.2.2.1 vr.2 H, h.2.size_eq] exact (e.add_left _).add_right _ exact Or.inr ⟨_, e, h.3.1⟩ theorem insertWith.valid [IsTotal α (· ≤ ·)] [DecidableLE α] (f : α → α) (x : α) (hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) {t} (h : Valid t) : Valid (insertWith f x t) := (insertWith.valid_aux _ _ hf h ⟨⟩ ⟨⟩).1 theorem insert_eq_insertWith [DecidableLE α] (x : α) : ∀ t, Ordnode.insert x t = insertWith (fun _ => x) x t
| nil => rfl | node _ l y r => by unfold Ordnode.insert insertWith; cases cmpLE x y <;> simp [insert_eq_insertWith]
Mathlib/Data/Ordmap/Ordset.lean
518
520
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Kexing Ying, Moritz Doll -/ import Mathlib.Algebra.GroupWithZero.Action.Opposite import Mathlib.LinearAlgebra.Finsupp.VectorSpace import Mathlib.LinearAlgebra.Matrix.Basis import Mathlib.LinearAlgebra.Matrix.Nondegenerate import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv import Mathlib.LinearAlgebra.SesquilinearForm import Mathlib.LinearAlgebra.Basis.Bilinear /-! # Sesquilinear form This file defines the conversion between sesquilinear maps and matrices. ## Main definitions * `Matrix.toLinearMap₂` given a basis define a bilinear map * `Matrix.toLinearMap₂'` define the bilinear map on `n → R` * `LinearMap.toMatrix₂`: calculate the matrix coefficients of a bilinear map * `LinearMap.toMatrix₂'`: calculate the matrix coefficients of a bilinear map on `n → R` ## TODO At the moment this is quite a literal port from `Matrix.BilinearForm`. Everything should be generalized to fully semibilinear forms. ## Tags Sesquilinear form, Sesquilinear map, matrix, basis -/ variable {R R₁ S₁ R₂ S₂ M₁ M₂ M₁' M₂' N₂ n m n' m' ι : Type*} open Finset LinearMap Matrix open Matrix open scoped RightActions section AuxToLinearMap variable [Semiring R₁] [Semiring S₁] [Semiring R₂] [Semiring S₂] [AddCommMonoid N₂] [Module S₁ N₂] [Module S₂ N₂] [SMulCommClass S₂ S₁ N₂] variable [Fintype n] [Fintype m] variable (σ₁ : R₁ →+* S₁) (σ₂ : R₂ →+* S₂) /-- The map from `Matrix n n R` to bilinear maps on `n → R`. This is an auxiliary definition for the equivalence `Matrix.toLinearMap₂'`. -/ def Matrix.toLinearMap₂'Aux (f : Matrix n m N₂) : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂ := -- porting note: we don't seem to have `∑ i j` as valid notation yet mk₂'ₛₗ σ₁ σ₂ (fun (v : n → R₁) (w : m → R₂) => ∑ i, ∑ j, σ₂ (w j) • σ₁ (v i) • f i j) (fun _ _ _ => by simp only [Pi.add_apply, map_add, smul_add, sum_add_distrib, add_smul]) (fun c v w => by simp only [Pi.smul_apply, smul_sum, smul_eq_mul, σ₁.map_mul, ← smul_comm _ (σ₁ c), MulAction.mul_smul]) (fun _ _ _ => by simp only [Pi.add_apply, map_add, add_smul, smul_add, sum_add_distrib]) (fun _ v w => by simp only [Pi.smul_apply, smul_eq_mul, map_mul, MulAction.mul_smul, smul_sum]) variable [DecidableEq n] [DecidableEq m] theorem Matrix.toLinearMap₂'Aux_single (f : Matrix n m N₂) (i : n) (j : m) : f.toLinearMap₂'Aux σ₁ σ₂ (Pi.single i 1) (Pi.single j 1) = f i j := by rw [Matrix.toLinearMap₂'Aux, mk₂'ₛₗ_apply] have : (∑ i', ∑ j', (if i = i' then (1 : S₁) else (0 : S₁)) • (if j = j' then (1 : S₂) else (0 : S₂)) • f i' j') = f i j := by simp_rw [← Finset.smul_sum] simp only [op_smul_eq_smul, ite_smul, one_smul, zero_smul, sum_ite_eq, mem_univ, ↓reduceIte] rw [← this] exact Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by aesop end AuxToLinearMap section AuxToMatrix section CommSemiring variable [CommSemiring R] [Semiring R₁] [Semiring S₁] [Semiring R₂] [Semiring S₂] variable [AddCommMonoid M₁] [Module R₁ M₁] [AddCommMonoid M₂] [Module R₂ M₂] [AddCommMonoid N₂] [Module R N₂] [Module S₁ N₂] [Module S₂ N₂] [SMulCommClass S₁ R N₂] [SMulCommClass S₂ R N₂] [SMulCommClass S₂ S₁ N₂] variable {σ₁ : R₁ →+* S₁} {σ₂ : R₂ →+* S₂} variable (R) /-- The linear map from sesquilinear maps to `Matrix n m N₂` given an `n`-indexed basis for `M₁` and an `m`-indexed basis for `M₂`. This is an auxiliary definition for the equivalence `Matrix.toLinearMapₛₗ₂'`. -/ def LinearMap.toMatrix₂Aux (b₁ : n → M₁) (b₂ : m → M₂) : (M₁ →ₛₗ[σ₁] M₂ →ₛₗ[σ₂] N₂) →ₗ[R] Matrix n m N₂ where toFun f := of fun i j => f (b₁ i) (b₂ j) map_add' _f _g := rfl map_smul' _f _g := rfl @[simp] theorem LinearMap.toMatrix₂Aux_apply (f : M₁ →ₛₗ[σ₁] M₂ →ₛₗ[σ₂] N₂) (b₁ : n → M₁) (b₂ : m → M₂) (i : n) (j : m) : LinearMap.toMatrix₂Aux R b₁ b₂ f i j = f (b₁ i) (b₂ j) := rfl variable [Fintype n] [Fintype m] variable [DecidableEq n] [DecidableEq m] theorem LinearMap.toLinearMap₂'Aux_toMatrix₂Aux (f : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) : Matrix.toLinearMap₂'Aux σ₁ σ₂ (LinearMap.toMatrix₂Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) f) = f := by refine ext_basis (Pi.basisFun R₁ n) (Pi.basisFun R₂ m) fun i j => ?_ simp_rw [Pi.basisFun_apply, Matrix.toLinearMap₂'Aux_single, LinearMap.toMatrix₂Aux_apply] theorem Matrix.toMatrix₂Aux_toLinearMap₂'Aux (f : Matrix n m N₂) : LinearMap.toMatrix₂Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) (f.toLinearMap₂'Aux σ₁ σ₂) = f := by ext i j simp_rw [LinearMap.toMatrix₂Aux_apply, Matrix.toLinearMap₂'Aux_single] end CommSemiring end AuxToMatrix section ToMatrix' /-! ### Bilinear maps over `n → R` This section deals with the conversion between matrices and sesquilinear maps on `n → R`. -/ variable [CommSemiring R] [AddCommMonoid N₂] [Module R N₂] [Semiring R₁] [Semiring R₂] [Semiring S₁] [Semiring S₂] [Module S₁ N₂] [Module S₂ N₂] [SMulCommClass S₁ R N₂] [SMulCommClass S₂ R N₂] [SMulCommClass S₂ S₁ N₂] variable {σ₁ : R₁ →+* S₁} {σ₂ : R₂ →+* S₂} variable [Fintype n] [Fintype m] variable [DecidableEq n] [DecidableEq m] variable (R) /-- The linear equivalence between sesquilinear maps and `n × m` matrices -/ def LinearMap.toMatrixₛₗ₂' : ((n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) ≃ₗ[R] Matrix n m N₂ := { LinearMap.toMatrix₂Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) with toFun := LinearMap.toMatrix₂Aux R _ _ invFun := Matrix.toLinearMap₂'Aux σ₁ σ₂ left_inv := LinearMap.toLinearMap₂'Aux_toMatrix₂Aux R right_inv := Matrix.toMatrix₂Aux_toLinearMap₂'Aux R } /-- The linear equivalence between bilinear maps and `n × m` matrices -/ def LinearMap.toMatrix₂' : ((n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) ≃ₗ[R] Matrix n m N₂ := LinearMap.toMatrixₛₗ₂' R variable (σ₁ σ₂) /-- The linear equivalence between `n × n` matrices and sesquilinear maps on `n → R` -/ def Matrix.toLinearMapₛₗ₂' : Matrix n m N₂ ≃ₗ[R] (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂ := (LinearMap.toMatrixₛₗ₂' R).symm /-- The linear equivalence between `n × n` matrices and bilinear maps on `n → R` -/ def Matrix.toLinearMap₂' : Matrix n m N₂ ≃ₗ[R] (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂ := (LinearMap.toMatrix₂' R).symm variable {R} theorem Matrix.toLinearMapₛₗ₂'_aux_eq (M : Matrix n m N₂) : Matrix.toLinearMap₂'Aux σ₁ σ₂ M = Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M := rfl theorem Matrix.toLinearMapₛₗ₂'_apply (M : Matrix n m N₂) (x : n → R₁) (y : m → R₂) : -- porting note: we don't seem to have `∑ i j` as valid notation yet Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M x y = ∑ i, ∑ j, σ₁ (x i) • σ₂ (y j) • M i j := by rw [toLinearMapₛₗ₂', toMatrixₛₗ₂', LinearEquiv.coe_symm_mk, toLinearMap₂'Aux, mk₂'ₛₗ_apply] apply Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by rw [smul_comm] theorem Matrix.toLinearMap₂'_apply (M : Matrix n m N₂) (x : n → S₁) (y : m → S₂) : -- porting note: we don't seem to have `∑ i j` as valid notation yet Matrix.toLinearMap₂' R M x y = ∑ i, ∑ j, x i • y j • M i j := Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by rw [RingHom.id_apply, RingHom.id_apply, smul_comm] theorem Matrix.toLinearMap₂'_apply' {T : Type*} [CommSemiring T] (M : Matrix n m T) (v : n → T) (w : m → T) : Matrix.toLinearMap₂' T M v w = dotProduct v (M *ᵥ w) := by simp_rw [Matrix.toLinearMap₂'_apply, dotProduct, Matrix.mulVec, dotProduct] refine Finset.sum_congr rfl fun _ _ => ?_ rw [Finset.mul_sum] refine Finset.sum_congr rfl fun _ _ => ?_ rw [smul_eq_mul, smul_eq_mul, mul_comm (w _), ← mul_assoc] @[simp] theorem Matrix.toLinearMapₛₗ₂'_single (M : Matrix n m N₂) (i : n) (j : m) : Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M (Pi.single i 1) (Pi.single j 1) = M i j := Matrix.toLinearMap₂'Aux_single σ₁ σ₂ M i j @[simp] theorem Matrix.toLinearMap₂'_single (M : Matrix n m N₂) (i : n) (j : m) : Matrix.toLinearMap₂' R M (Pi.single i 1) (Pi.single j 1) = M i j := Matrix.toLinearMap₂'Aux_single _ _ M i j @[simp] theorem LinearMap.toMatrixₛₗ₂'_symm : ((LinearMap.toMatrixₛₗ₂' R).symm : Matrix n m N₂ ≃ₗ[R] _) = Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ := rfl @[simp] theorem Matrix.toLinearMapₛₗ₂'_symm : ((Matrix.toLinearMapₛₗ₂' R σ₁ σ₂).symm : _ ≃ₗ[R] Matrix n m N₂) = LinearMap.toMatrixₛₗ₂' R := (LinearMap.toMatrixₛₗ₂' R).symm_symm @[simp] theorem Matrix.toLinearMapₛₗ₂'_toMatrix' (B : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) : Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ (LinearMap.toMatrixₛₗ₂' R B) = B := (Matrix.toLinearMapₛₗ₂' R σ₁ σ₂).apply_symm_apply B @[simp] theorem Matrix.toLinearMap₂'_toMatrix' (B : (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) : Matrix.toLinearMap₂' R (LinearMap.toMatrix₂' R B) = B := (Matrix.toLinearMap₂' R).apply_symm_apply B @[simp] theorem LinearMap.toMatrix'_toLinearMapₛₗ₂' (M : Matrix n m N₂) : LinearMap.toMatrixₛₗ₂' R (Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M) = M := (LinearMap.toMatrixₛₗ₂' R).apply_symm_apply M @[simp] theorem LinearMap.toMatrix'_toLinearMap₂' (M : Matrix n m N₂) : LinearMap.toMatrix₂' R (Matrix.toLinearMap₂' R (S₁ := S₁) (S₂ := S₂) M) = M := (LinearMap.toMatrixₛₗ₂' R).apply_symm_apply M @[simp] theorem LinearMap.toMatrixₛₗ₂'_apply (B : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) (i : n) (j : m) : LinearMap.toMatrixₛₗ₂' R B i j = B (Pi.single i 1) (Pi.single j 1) := rfl @[simp] theorem LinearMap.toMatrix₂'_apply (B : (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) (i : n) (j : m) : LinearMap.toMatrix₂' R B i j = B (Pi.single i 1) (Pi.single j 1) := rfl end ToMatrix' section CommToMatrix' -- TODO: Introduce matrix multiplication by matrices of scalars variable {R : Type*} [CommSemiring R] variable [Fintype n] [Fintype m] variable [DecidableEq n] [DecidableEq m] variable [Fintype n'] [Fintype m'] variable [DecidableEq n'] [DecidableEq m'] @[simp] theorem LinearMap.toMatrix₂'_compl₁₂ (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (l : (n' → R) →ₗ[R] n → R) (r : (m' → R) →ₗ[R] m → R) : toMatrix₂' R (B.compl₁₂ l r) = (toMatrix' l)ᵀ * toMatrix₂' R B * toMatrix' r := by ext i j simp only [LinearMap.toMatrix₂'_apply, LinearMap.compl₁₂_apply, transpose_apply, Matrix.mul_apply, LinearMap.toMatrix', LinearEquiv.coe_mk, sum_mul] rw [sum_comm] conv_lhs => rw [← LinearMap.sum_repr_mul_repr_mul (Pi.basisFun R n) (Pi.basisFun R m) (l _) (r _)] rw [Finsupp.sum_fintype] · apply sum_congr rfl rintro i' - rw [Finsupp.sum_fintype] · apply sum_congr rfl rintro j' - simp only [smul_eq_mul, Pi.basisFun_repr, mul_assoc, mul_comm, mul_left_comm, Pi.basisFun_apply, of_apply] · intros simp only [zero_smul, smul_zero] · intros simp only [zero_smul, Finsupp.sum_zero] theorem LinearMap.toMatrix₂'_comp (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (f : (n' → R) →ₗ[R] n → R) : toMatrix₂' R (B.comp f) = (toMatrix' f)ᵀ * toMatrix₂' R B := by rw [← LinearMap.compl₂_id (B.comp f), ← LinearMap.compl₁₂] simp theorem LinearMap.toMatrix₂'_compl₂ (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (f : (m' → R) →ₗ[R] m → R) : toMatrix₂' R (B.compl₂ f) = toMatrix₂' R B * toMatrix' f := by rw [← LinearMap.comp_id B, ← LinearMap.compl₁₂] simp theorem LinearMap.mul_toMatrix₂'_mul (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix n' n R) (N : Matrix m m' R) : M * toMatrix₂' R B * N = toMatrix₂' R (B.compl₁₂ (toLin' Mᵀ) (toLin' N)) := by simp theorem LinearMap.mul_toMatrix' (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix n' n R) : M * toMatrix₂' R B = toMatrix₂' R (B.comp <| toLin' Mᵀ) := by simp only [B.toMatrix₂'_comp, transpose_transpose, toMatrix'_toLin'] theorem LinearMap.toMatrix₂'_mul (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix m m' R) : toMatrix₂' R B * M = toMatrix₂' R (B.compl₂ <| toLin' M) := by simp only [B.toMatrix₂'_compl₂, toMatrix'_toLin'] theorem Matrix.toLinearMap₂'_comp (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) : LinearMap.compl₁₂ (Matrix.toLinearMap₂' R M) (toLin' P) (toLin' Q) = toLinearMap₂' R (Pᵀ * M * Q) := (LinearMap.toMatrix₂' R).injective (by simp) end CommToMatrix' section ToMatrix /-! ### Bilinear maps over arbitrary vector spaces This section deals with the conversion between matrices and bilinear maps on a module with a fixed basis. -/ variable [CommSemiring R] variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] [AddCommMonoid N₂] [Module R N₂] variable [DecidableEq n] [Fintype n] variable [DecidableEq m] [Fintype m] section variable (b₁ : Basis n R M₁) (b₂ : Basis m R M₂) /-- `LinearMap.toMatrix₂ b₁ b₂` is the equivalence between `R`-bilinear maps on `M` and `n`-by-`m` matrices with entries in `R`, if `b₁` and `b₂` are `R`-bases for `M₁` and `M₂`, respectively. -/ noncomputable def LinearMap.toMatrix₂ : (M₁ →ₗ[R] M₂ →ₗ[R] N₂) ≃ₗ[R] Matrix n m N₂ := (b₁.equivFun.arrowCongr (b₂.equivFun.arrowCongr (LinearEquiv.refl R N₂))).trans (LinearMap.toMatrix₂' R) /-- `Matrix.toLinearMap₂ b₁ b₂` is the equivalence between `R`-bilinear maps on `M` and `n`-by-`m` matrices with entries in `R`, if `b₁` and `b₂` are `R`-bases for `M₁` and `M₂`, respectively; this is the reverse direction of `LinearMap.toMatrix₂ b₁ b₂`. -/ noncomputable def Matrix.toLinearMap₂ : Matrix n m N₂ ≃ₗ[R] M₁ →ₗ[R] M₂ →ₗ[R] N₂ := (LinearMap.toMatrix₂ b₁ b₂).symm -- We make this and not `LinearMap.toMatrix₂` a `simp` lemma to avoid timeouts @[simp] theorem LinearMap.toMatrix₂_apply (B : M₁ →ₗ[R] M₂ →ₗ[R] N₂) (i : n) (j : m) : LinearMap.toMatrix₂ b₁ b₂ B i j = B (b₁ i) (b₂ j) := by simp only [toMatrix₂, LinearEquiv.trans_apply, toMatrix₂'_apply, LinearEquiv.arrowCongr_apply, Basis.equivFun_symm_apply, Pi.single_apply, ite_smul, one_smul, zero_smul, sum_ite_eq', mem_univ, ↓reduceIte, LinearEquiv.refl_apply] @[simp] theorem Matrix.toLinearMap₂_apply (M : Matrix n m N₂) (x : M₁) (y : M₂) : Matrix.toLinearMap₂ b₁ b₂ M x y = ∑ i, ∑ j, b₁.repr x i • b₂.repr y j • M i j := Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => smul_algebra_smul_comm ((RingHom.id R) ((Basis.equivFun b₁) x _)) ((RingHom.id R) ((Basis.equivFun b₂) y _)) (M _ _) -- Not a `simp` lemma since `LinearMap.toMatrix₂` needs an extra argument theorem LinearMap.toMatrix₂Aux_eq (B : M₁ →ₗ[R] M₂ →ₗ[R] N₂) : LinearMap.toMatrix₂Aux R b₁ b₂ B = LinearMap.toMatrix₂ b₁ b₂ B := Matrix.ext fun i j => by rw [LinearMap.toMatrix₂_apply, LinearMap.toMatrix₂Aux_apply] @[simp] theorem LinearMap.toMatrix₂_symm : (LinearMap.toMatrix₂ b₁ b₂).symm = Matrix.toLinearMap₂ (N₂ := N₂) b₁ b₂ := rfl @[simp] theorem Matrix.toLinearMap₂_symm : (Matrix.toLinearMap₂ b₁ b₂).symm = LinearMap.toMatrix₂ (N₂ := N₂) b₁ b₂ := (LinearMap.toMatrix₂ b₁ b₂).symm_symm theorem Matrix.toLinearMap₂_basisFun : Matrix.toLinearMap₂ (Pi.basisFun R n) (Pi.basisFun R m) = Matrix.toLinearMap₂' R (N₂ := N₂) := by ext M simp only [coe_comp, coe_single, Function.comp_apply, toLinearMap₂_apply, Pi.basisFun_repr, toLinearMap₂'_apply] theorem LinearMap.toMatrix₂_basisFun : LinearMap.toMatrix₂ (Pi.basisFun R n) (Pi.basisFun R m) = LinearMap.toMatrix₂' R (N₂ := N₂) := by ext B rw [LinearMap.toMatrix₂_apply, LinearMap.toMatrix₂'_apply, Pi.basisFun_apply, Pi.basisFun_apply] @[simp] theorem Matrix.toLinearMap₂_toMatrix₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] N₂) : Matrix.toLinearMap₂ b₁ b₂ (LinearMap.toMatrix₂ b₁ b₂ B) = B := (Matrix.toLinearMap₂ b₁ b₂).apply_symm_apply B @[simp] theorem LinearMap.toMatrix₂_toLinearMap₂ (M : Matrix n m N₂) : LinearMap.toMatrix₂ b₁ b₂ (Matrix.toLinearMap₂ b₁ b₂ M) = M := (LinearMap.toMatrix₂ b₁ b₂).apply_symm_apply M variable (b₁ : Basis n R M₁) (b₂ : Basis m R M₂) variable [AddCommMonoid M₁'] [Module R M₁'] variable [AddCommMonoid M₂'] [Module R M₂'] variable (b₁' : Basis n' R M₁') variable (b₂' : Basis m' R M₂') variable [Fintype n'] [Fintype m'] variable [DecidableEq n'] [DecidableEq m'] -- Cannot be a `simp` lemma because `b₁` and `b₂` must be inferred. theorem LinearMap.toMatrix₂_compl₁₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (l : M₁' →ₗ[R] M₁) (r : M₂' →ₗ[R] M₂) : LinearMap.toMatrix₂ b₁' b₂' (B.compl₁₂ l r) = (toMatrix b₁' b₁ l)ᵀ * LinearMap.toMatrix₂ b₁ b₂ B * toMatrix b₂' b₂ r := by ext i j simp only [LinearMap.toMatrix₂_apply, compl₁₂_apply, transpose_apply, Matrix.mul_apply, LinearMap.toMatrix_apply, LinearEquiv.coe_mk, sum_mul] rw [sum_comm] conv_lhs => rw [← LinearMap.sum_repr_mul_repr_mul b₁ b₂] rw [Finsupp.sum_fintype] · apply sum_congr rfl rintro i' - rw [Finsupp.sum_fintype] · apply sum_congr rfl rintro j' - simp only [smul_eq_mul, LinearMap.toMatrix_apply, Basis.equivFun_apply, mul_assoc, mul_comm, mul_left_comm] · intros simp only [zero_smul, smul_zero] · intros simp only [zero_smul, Finsupp.sum_zero] theorem LinearMap.toMatrix₂_comp (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (f : M₁' →ₗ[R] M₁) : LinearMap.toMatrix₂ b₁' b₂ (B.comp f) = (toMatrix b₁' b₁ f)ᵀ * LinearMap.toMatrix₂ b₁ b₂ B := by rw [← LinearMap.compl₂_id (B.comp f), ← LinearMap.compl₁₂, LinearMap.toMatrix₂_compl₁₂ b₁ b₂] simp theorem LinearMap.toMatrix₂_compl₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (f : M₂' →ₗ[R] M₂) : LinearMap.toMatrix₂ b₁ b₂' (B.compl₂ f) = LinearMap.toMatrix₂ b₁ b₂ B * toMatrix b₂' b₂ f := by rw [← LinearMap.comp_id B, ← LinearMap.compl₁₂, LinearMap.toMatrix₂_compl₁₂ b₁ b₂] simp @[simp] theorem LinearMap.toMatrix₂_mul_basis_toMatrix (c₁ : Basis n' R M₁) (c₂ : Basis m' R M₂) (B : M₁ →ₗ[R] M₂ →ₗ[R] R) : (b₁.toMatrix c₁)ᵀ * LinearMap.toMatrix₂ b₁ b₂ B * b₂.toMatrix c₂ = LinearMap.toMatrix₂ c₁ c₂ B := by simp_rw [← LinearMap.toMatrix_id_eq_basis_toMatrix] rw [← LinearMap.toMatrix₂_compl₁₂, LinearMap.compl₁₂_id_id] theorem LinearMap.mul_toMatrix₂_mul (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (M : Matrix n' n R) (N : Matrix m m' R) : M * LinearMap.toMatrix₂ b₁ b₂ B * N = LinearMap.toMatrix₂ b₁' b₂' (B.compl₁₂ (toLin b₁' b₁ Mᵀ) (toLin b₂' b₂ N)) := by simp_rw [LinearMap.toMatrix₂_compl₁₂ b₁ b₂, toMatrix_toLin, transpose_transpose] theorem LinearMap.mul_toMatrix₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (M : Matrix n' n R) : M * LinearMap.toMatrix₂ b₁ b₂ B = LinearMap.toMatrix₂ b₁' b₂ (B.comp (toLin b₁' b₁ Mᵀ)) := by rw [LinearMap.toMatrix₂_comp b₁, toMatrix_toLin, transpose_transpose] theorem LinearMap.toMatrix₂_mul (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (M : Matrix m m' R) : LinearMap.toMatrix₂ b₁ b₂ B * M = LinearMap.toMatrix₂ b₁ b₂' (B.compl₂ (toLin b₂' b₂ M)) := by rw [LinearMap.toMatrix₂_compl₂ b₁ b₂, toMatrix_toLin] theorem Matrix.toLinearMap₂_compl₁₂ (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) : (Matrix.toLinearMap₂ b₁ b₂ M).compl₁₂ (toLin b₁' b₁ P) (toLin b₂' b₂ Q) = Matrix.toLinearMap₂ b₁' b₂' (Pᵀ * M * Q) := (LinearMap.toMatrix₂ b₁' b₂').injective (by simp only [LinearMap.toMatrix₂_compl₁₂ b₁ b₂, LinearMap.toMatrix₂_toLinearMap₂, toMatrix_toLin]) end end ToMatrix /-! ### Adjoint pairs -/ section MatrixAdjoints open Matrix variable [CommRing R] variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] variable [Fintype n] [Fintype n'] variable (b₁ : Basis n R M₁) (b₂ : Basis n' R M₂) variable (J J₂ : Matrix n n R) (J' : Matrix n' n' R) variable (A : Matrix n' n R) (A' : Matrix n n' R) variable (A₁ A₂ : Matrix n n R) /-- The condition for the matrices `A`, `A'` to be an adjoint pair with respect to the square matrices `J`, `J₃`. -/ def Matrix.IsAdjointPair := Aᵀ * J' = J * A' /-- The condition for a square matrix `A` to be self-adjoint with respect to the square matrix `J`. -/ def Matrix.IsSelfAdjoint := Matrix.IsAdjointPair J J A₁ A₁ /-- The condition for a square matrix `A` to be skew-adjoint with respect to the square matrix `J`. -/ def Matrix.IsSkewAdjoint := Matrix.IsAdjointPair J J A₁ (-A₁) variable [DecidableEq n] [DecidableEq n'] @[simp] theorem isAdjointPair_toLinearMap₂' : LinearMap.IsAdjointPair (Matrix.toLinearMap₂' R J) (Matrix.toLinearMap₂' R J') (Matrix.toLin' A) (Matrix.toLin' A') ↔ Matrix.IsAdjointPair J J' A A' := by rw [isAdjointPair_iff_comp_eq_compl₂] have h : ∀ B B' : (n → R) →ₗ[R] (n' → R) →ₗ[R] R, B = B' ↔ LinearMap.toMatrix₂' R B = LinearMap.toMatrix₂' R B' := by intro B B' constructor <;> intro h · rw [h] · exact (LinearMap.toMatrix₂' R).injective h simp_rw [h, LinearMap.toMatrix₂'_comp, LinearMap.toMatrix₂'_compl₂, LinearMap.toMatrix'_toLin', LinearMap.toMatrix'_toLinearMap₂'] rfl @[simp] theorem isAdjointPair_toLinearMap₂ : LinearMap.IsAdjointPair (Matrix.toLinearMap₂ b₁ b₁ J) (Matrix.toLinearMap₂ b₂ b₂ J') (Matrix.toLin b₁ b₂ A) (Matrix.toLin b₂ b₁ A') ↔ Matrix.IsAdjointPair J J' A A' := by rw [isAdjointPair_iff_comp_eq_compl₂] have h : ∀ B B' : M₁ →ₗ[R] M₂ →ₗ[R] R, B = B' ↔ LinearMap.toMatrix₂ b₁ b₂ B = LinearMap.toMatrix₂ b₁ b₂ B' := by intro B B' constructor <;> intro h · rw [h] · exact (LinearMap.toMatrix₂ b₁ b₂).injective h simp_rw [h, LinearMap.toMatrix₂_comp b₂ b₂, LinearMap.toMatrix₂_compl₂ b₁ b₁, LinearMap.toMatrix_toLin, LinearMap.toMatrix₂_toLinearMap₂] rfl theorem Matrix.isAdjointPair_equiv (P : Matrix n n R) (h : IsUnit P) : (Pᵀ * J * P).IsAdjointPair (Pᵀ * J * P) A₁ A₂ ↔ J.IsAdjointPair J (P * A₁ * P⁻¹) (P * A₂ * P⁻¹) := by have h' : IsUnit P.det := P.isUnit_iff_isUnit_det.mp h let u := P.nonsingInvUnit h' let v := Pᵀ.nonsingInvUnit (P.isUnit_det_transpose h') let x := A₁ᵀ * Pᵀ * J let y := J * P * A₂ suffices x * u = v * y ↔ v⁻¹ * x = y * u⁻¹ by dsimp only [Matrix.IsAdjointPair] simp only [Matrix.transpose_mul] simp only [← mul_assoc, P.transpose_nonsing_inv] convert this using 2 · rw [mul_assoc, mul_assoc, ← mul_assoc J] rfl · rw [mul_assoc, mul_assoc, ← mul_assoc _ _ J] rfl rw [Units.eq_mul_inv_iff_mul_eq] conv_rhs => rw [mul_assoc] rw [v.inv_mul_eq_iff_eq_mul] /-- The submodule of pair-self-adjoint matrices with respect to bilinear forms corresponding to given matrices `J`, `J₂`. -/ def pairSelfAdjointMatricesSubmodule : Submodule R (Matrix n n R) := (isPairSelfAdjointSubmodule (Matrix.toLinearMap₂' R J) (Matrix.toLinearMap₂' R J₂)).map ((LinearMap.toMatrix' : ((n → R) →ₗ[R] n → R) ≃ₗ[R] Matrix n n R) : ((n → R) →ₗ[R] n → R) →ₗ[R] Matrix n n R) @[simp] theorem mem_pairSelfAdjointMatricesSubmodule : A₁ ∈ pairSelfAdjointMatricesSubmodule J J₂ ↔ Matrix.IsAdjointPair J J₂ A₁ A₁ := by simp only [pairSelfAdjointMatricesSubmodule, LinearEquiv.coe_coe, LinearMap.toMatrix'_apply, Submodule.mem_map, mem_isPairSelfAdjointSubmodule] constructor · rintro ⟨f, hf, hA⟩ have hf' : f = toLin' A₁ := by rw [← hA, Matrix.toLin'_toMatrix'] rw [hf'] at hf rw [← isAdjointPair_toLinearMap₂'] exact hf · intro h refine ⟨toLin' A₁, ?_, LinearMap.toMatrix'_toLin' _⟩ exact (isAdjointPair_toLinearMap₂' _ _ _ _).mpr h /-- The submodule of self-adjoint matrices with respect to the bilinear form corresponding to the matrix `J`. -/ def selfAdjointMatricesSubmodule : Submodule R (Matrix n n R) := pairSelfAdjointMatricesSubmodule J J @[simp] theorem mem_selfAdjointMatricesSubmodule : A₁ ∈ selfAdjointMatricesSubmodule J ↔ J.IsSelfAdjoint A₁ := by erw [mem_pairSelfAdjointMatricesSubmodule] rfl /-- The submodule of skew-adjoint matrices with respect to the bilinear form corresponding to the matrix `J`. -/ def skewAdjointMatricesSubmodule : Submodule R (Matrix n n R) := pairSelfAdjointMatricesSubmodule (-J) J @[simp] theorem mem_skewAdjointMatricesSubmodule : A₁ ∈ skewAdjointMatricesSubmodule J ↔ J.IsSkewAdjoint A₁ := by erw [mem_pairSelfAdjointMatricesSubmodule] simp [Matrix.IsSkewAdjoint, Matrix.IsAdjointPair] end MatrixAdjoints namespace LinearMap /-! ### Nondegenerate bilinear forms -/ section Det open Matrix variable [CommRing R₁] [AddCommMonoid M₁] [Module R₁ M₁] variable [DecidableEq ι] [Fintype ι] theorem _root_.Matrix.separatingLeft_toLinearMap₂'_iff_separatingLeft_toLinearMap₂ {M : Matrix ι ι R₁} (b : Basis ι R₁ M₁) : (Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) ↔ (Matrix.toLinearMap₂ b b M).SeparatingLeft := (separatingLeft_congr_iff b.equivFun.symm b.equivFun.symm).symm -- Lemmas transferring nondegeneracy between a matrix and its associated bilinear form theorem _root_.Matrix.Nondegenerate.toLinearMap₂' {M : Matrix ι ι R₁} (h : M.Nondegenerate) : (Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) := fun x hx => h.eq_zero_of_ortho fun y => by simpa only [toLinearMap₂'_apply'] using hx y @[simp] theorem _root_.Matrix.separatingLeft_toLinearMap₂'_iff {M : Matrix ι ι R₁} : (Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) ↔ M.Nondegenerate := ⟨fun h v hv => h v fun w => (M.toLinearMap₂'_apply' _ _).trans <| hv w, Matrix.Nondegenerate.toLinearMap₂'⟩ theorem _root_.Matrix.Nondegenerate.toLinearMap₂ {M : Matrix ι ι R₁} (h : M.Nondegenerate) (b : Basis ι R₁ M₁) : (toLinearMap₂ b b M).SeparatingLeft := (Matrix.separatingLeft_toLinearMap₂'_iff_separatingLeft_toLinearMap₂ b).mp h.toLinearMap₂' @[simp] theorem _root_.Matrix.separatingLeft_toLinearMap₂_iff {M : Matrix ι ι R₁} (b : Basis ι R₁ M₁) : (toLinearMap₂ b b M).SeparatingLeft ↔ M.Nondegenerate := by rw [← Matrix.separatingLeft_toLinearMap₂'_iff_separatingLeft_toLinearMap₂, Matrix.separatingLeft_toLinearMap₂'_iff] -- Lemmas transferring nondegeneracy between a bilinear form and its associated matrix @[simp] theorem nondegenerate_toMatrix₂'_iff {B : (ι → R₁) →ₗ[R₁] (ι → R₁) →ₗ[R₁] R₁} : (LinearMap.toMatrix₂' R₁ B).Nondegenerate ↔ B.SeparatingLeft := Matrix.separatingLeft_toLinearMap₂'_iff.symm.trans <| (Matrix.toLinearMap₂'_toMatrix' (R := R₁) B).symm ▸ Iff.rfl theorem SeparatingLeft.toMatrix₂' {B : (ι → R₁) →ₗ[R₁] (ι → R₁) →ₗ[R₁] R₁} (h : B.SeparatingLeft) : (LinearMap.toMatrix₂' R₁ B).Nondegenerate := nondegenerate_toMatrix₂'_iff.mpr h @[simp] theorem nondegenerate_toMatrix_iff {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (b : Basis ι R₁ M₁) : (toMatrix₂ b b B).Nondegenerate ↔ B.SeparatingLeft := (Matrix.separatingLeft_toLinearMap₂_iff b).symm.trans <| (Matrix.toLinearMap₂_toMatrix₂ b b B).symm ▸ Iff.rfl theorem SeparatingLeft.toMatrix₂ {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (h : B.SeparatingLeft) (b : Basis ι R₁ M₁) : (toMatrix₂ b b B).Nondegenerate := (nondegenerate_toMatrix_iff b).mpr h -- Some shorthands for combining the above with `Matrix.nondegenerate_of_det_ne_zero` variable [IsDomain R₁] theorem separatingLeft_toLinearMap₂'_iff_det_ne_zero {M : Matrix ι ι R₁} : (Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) ↔ M.det ≠ 0 := by rw [Matrix.separatingLeft_toLinearMap₂'_iff, Matrix.nondegenerate_iff_det_ne_zero] theorem separatingLeft_toLinearMap₂'_of_det_ne_zero' (M : Matrix ι ι R₁) (h : M.det ≠ 0) : (Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) := separatingLeft_toLinearMap₂'_iff_det_ne_zero.mpr h theorem separatingLeft_iff_det_ne_zero {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (b : Basis ι R₁ M₁) : B.SeparatingLeft ↔ (toMatrix₂ b b B).det ≠ 0 := by rw [← Matrix.nondegenerate_iff_det_ne_zero, nondegenerate_toMatrix_iff] theorem separatingLeft_of_det_ne_zero {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (b : Basis ι R₁ M₁) (h : (toMatrix₂ b b B).det ≠ 0) : B.SeparatingLeft := (separatingLeft_iff_det_ne_zero b).mpr h end Det end LinearMap
Mathlib/LinearAlgebra/Matrix/SesquilinearForm.lean
722
724