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) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Topology.Order.IsLUB /-! # Monotone functions on an order topology This file contains lemmas about limits and continuity for monotone / antitone functions on linearly-ordered sets (with the order topology). For example, we prove that a monotone function has left and right limits at any point (`Monotone.tendsto_nhdsLT`, `Monotone.tendsto_nhdsGT`). -/ open Set Filter TopologicalSpace Topology Function open OrderDual (toDual ofDual) variable {α β : Type*} section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderClosedTopology β] /-- A monotone function continuous at the supremum of a nonempty set sends this supremum to the supremum of the image of this set. -/ theorem MonotoneOn.map_csSup_of_continuousWithinAt {f : α → β} {A : Set α} (Cf : ContinuousWithinAt f A (sSup A)) (Mf : MonotoneOn f A) (A_nonemp : A.Nonempty) (A_bdd : BddAbove A := by bddDefault) : f (sSup A) = sSup (f '' A) := --This is a particular case of the more general `IsLUB.isLUB_of_tendsto` .symm <| ((isLUB_csSup A_nonemp A_bdd).isLUB_of_tendsto Mf A_nonemp <| Cf.mono_left fun ⦃_⦄ a ↦ a).csSup_eq (A_nonemp.image f) /-- A monotone function continuous at the supremum of a nonempty set sends this supremum to the supremum of the image of this set. -/ theorem Monotone.map_csSup_of_continuousAt {f : α → β} {A : Set α} (Cf : ContinuousAt f (sSup A)) (Mf : Monotone f) (A_nonemp : A.Nonempty) (A_bdd : BddAbove A := by bddDefault) : f (sSup A) = sSup (f '' A) := MonotoneOn.map_csSup_of_continuousWithinAt Cf.continuousWithinAt (Mf.monotoneOn _) A_nonemp A_bdd /-- A monotone function continuous at the indexed supremum over a nonempty `Sort` sends this indexed supremum to the indexed supremum of the composition. -/ theorem Monotone.map_ciSup_of_continuousAt {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α} (Cf : ContinuousAt f (iSup g)) (Mf : Monotone f) (bdd : BddAbove (range g) := by bddDefault) : f (⨆ i, g i) = ⨆ i, f (g i) := by rw [iSup, Monotone.map_csSup_of_continuousAt Cf Mf (range_nonempty g) bdd, ← range_comp, iSup, comp_def] /-- A monotone function continuous at the infimum of a nonempty set sends this infimum to the infimum of the image of this set. -/ theorem MonotoneOn.map_csInf_of_continuousWithinAt {f : α → β} {A : Set α} (Cf : ContinuousWithinAt f A (sInf A)) (Mf : MonotoneOn f A) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) : f (sInf A) = sInf (f '' A) := MonotoneOn.map_csSup_of_continuousWithinAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual A_nonemp A_bdd /-- A monotone function continuous at the infimum of a nonempty set sends this infimum to the infimum of the image of this set. -/ theorem Monotone.map_csInf_of_continuousAt {f : α → β} {A : Set α} (Cf : ContinuousAt f (sInf A)) (Mf : Monotone f) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) : f (sInf A) = sInf (f '' A) := Monotone.map_csSup_of_continuousAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual A_nonemp A_bdd /-- A monotone function continuous at the indexed infimum over a nonempty `Sort` sends this indexed infimum to the indexed infimum of the composition. -/ theorem Monotone.map_ciInf_of_continuousAt {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α} (Cf : ContinuousAt f (iInf g)) (Mf : Monotone f) (bdd : BddBelow (range g) := by bddDefault) : f (⨅ i, g i) = ⨅ i, f (g i) := by rw [iInf, Monotone.map_csInf_of_continuousAt Cf Mf (range_nonempty g) bdd, ← range_comp, iInf, comp_def] /-- An antitone function continuous at the infimum of a nonempty set sends this infimum to the supremum of the image of this set. -/ theorem AntitoneOn.map_csInf_of_continuousWithinAt {f : α → β} {A : Set α} (Cf : ContinuousWithinAt f A (sInf A)) (Af : AntitoneOn f A) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) : f (sInf A) = sSup (f '' A) := MonotoneOn.map_csInf_of_continuousWithinAt (β := βᵒᵈ) Cf Af.dual_right A_nonemp A_bdd /-- An antitone function continuous at the infimum of a nonempty set sends this infimum to the supremum of the image of this set. -/ theorem Antitone.map_csInf_of_continuousAt {f : α → β} {A : Set α} (Cf : ContinuousAt f (sInf A)) (Af : Antitone f) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) : f (sInf A) = sSup (f '' A) := Monotone.map_csInf_of_continuousAt (β := βᵒᵈ) Cf Af.dual_right A_nonemp A_bdd /-- An antitone function continuous at the indexed infimum over a nonempty `Sort` sends this indexed infimum to the indexed supremum of the composition. -/ theorem Antitone.map_ciInf_of_continuousAt {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α} (Cf : ContinuousAt f (iInf g)) (Af : Antitone f) (bdd : BddBelow (range g) := by bddDefault) : f (⨅ i, g i) = ⨆ i, f (g i) := by rw [iInf, Antitone.map_csInf_of_continuousAt Cf Af (range_nonempty g) bdd, ← range_comp, iSup, comp_def] /-- An antitone function continuous at the supremum of a nonempty set sends this supremum to the infimum of the image of this set. -/ theorem AntitoneOn.map_csSup_of_continuousWithinAt {f : α → β} {A : Set α} (Cf : ContinuousWithinAt f A (sSup A)) (Af : AntitoneOn f A) (A_nonemp : A.Nonempty) (A_bdd : BddAbove A := by bddDefault) : f (sSup A) = sInf (f '' A) := MonotoneOn.map_csSup_of_continuousWithinAt (β := βᵒᵈ) Cf Af.dual_right A_nonemp A_bdd /-- An antitone function continuous at the supremum of a nonempty set sends this supremum to the infimum of the image of this set. -/ theorem Antitone.map_csSup_of_continuousAt {f : α → β} {A : Set α} (Cf : ContinuousAt f (sSup A)) (Af : Antitone f) (A_nonemp : A.Nonempty) (A_bdd : BddAbove A := by bddDefault) : f (sSup A) = sInf (f '' A) := Monotone.map_csSup_of_continuousAt (β := βᵒᵈ) Cf Af.dual_right A_nonemp A_bdd /-- An antitone function continuous at the indexed supremum over a nonempty `Sort` sends this indexed supremum to the indexed infimum of the composition. -/ theorem Antitone.map_ciSup_of_continuousAt {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α} (Cf : ContinuousAt f (iSup g)) (Af : Antitone f) (bdd : BddAbove (range g) := by bddDefault) : f (⨆ i, g i) = ⨅ i, f (g i) := by rw [iSup, Antitone.map_csSup_of_continuousAt Cf Af (range_nonempty g) bdd, ← range_comp, iInf, comp_def] end ConditionallyCompleteLinearOrder section CompleteLinearOrder variable [CompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α] [CompleteLinearOrder β] [TopologicalSpace β] [OrderClosedTopology β] theorem sSup_mem_closure {s : Set α} (hs : s.Nonempty) : sSup s ∈ closure s := (isLUB_sSup s).mem_closure hs theorem sInf_mem_closure {s : Set α} (hs : s.Nonempty) : sInf s ∈ closure s := (isGLB_sInf s).mem_closure hs theorem IsClosed.sSup_mem {s : Set α} (hs : s.Nonempty) (hc : IsClosed s) : sSup s ∈ s := (isLUB_sSup s).mem_of_isClosed hs hc theorem IsClosed.sInf_mem {s : Set α} (hs : s.Nonempty) (hc : IsClosed s) : sInf s ∈ s := (isGLB_sInf s).mem_of_isClosed hs hc /-- A monotone function `f` sending `bot` to `bot` and continuous at the supremum of a set sends this supremum to the supremum of the image of this set. -/ theorem MonotoneOn.map_sSup_of_continuousWithinAt {f : α → β} {s : Set α} (Cf : ContinuousWithinAt f s (sSup s)) (Mf : MonotoneOn f s) (fbot : f ⊥ = ⊥) : f (sSup s) = sSup (f '' s) := by rcases s.eq_empty_or_nonempty with h | h · simp [h, fbot] · exact Mf.map_csSup_of_continuousWithinAt Cf h /-- A monotone function `f` sending `bot` to `bot` and continuous at the supremum of a set sends this supremum to the supremum of the image of this set. -/ theorem Monotone.map_sSup_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sSup s)) (Mf : Monotone f) (fbot : f ⊥ = ⊥) : f (sSup s) = sSup (f '' s) := MonotoneOn.map_sSup_of_continuousWithinAt Cf.continuousWithinAt (Mf.monotoneOn _) fbot /-- If a monotone function sending `bot` to `bot` is continuous at the indexed supremum over a `Sort`, then it sends this indexed supremum to the indexed supremum of the composition. -/ theorem Monotone.map_iSup_of_continuousAt {ι : Sort*} {f : α → β} {g : ι → α} (Cf : ContinuousAt f (iSup g)) (Mf : Monotone f) (fbot : f ⊥ = ⊥) : f (⨆ i, g i) = ⨆ i, f (g i) := by rw [iSup, Mf.map_sSup_of_continuousAt Cf fbot, ← range_comp, iSup, comp_def] /-- A monotone function `f` sending `top` to `top` and continuous at the infimum of a set sends this infimum to the infimum of the image of this set. -/ theorem MonotoneOn.map_sInf_of_continuousWithinAt {f : α → β} {s : Set α} (Cf : ContinuousWithinAt f s (sInf s)) (Mf : MonotoneOn f s) (ftop : f ⊤ = ⊤) : f (sInf s) = sInf (f '' s) := MonotoneOn.map_sSup_of_continuousWithinAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual ftop /-- A monotone function `f` sending `top` to `top` and continuous at the infimum of a set sends this infimum to the infimum of the image of this set. -/ theorem Monotone.map_sInf_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sInf s)) (Mf : Monotone f) (ftop : f ⊤ = ⊤) : f (sInf s) = sInf (f '' s) := Monotone.map_sSup_of_continuousAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual ftop /-- If a monotone function sending `top` to `top` is continuous at the indexed infimum over a `Sort`, then it sends this indexed infimum to the indexed infimum of the composition. -/ theorem Monotone.map_iInf_of_continuousAt {ι : Sort*} {f : α → β} {g : ι → α} (Cf : ContinuousAt f (iInf g)) (Mf : Monotone f) (ftop : f ⊤ = ⊤) : f (iInf g) = iInf (f ∘ g) := Monotone.map_iSup_of_continuousAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual ftop /-- An antitone function `f` sending `bot` to `top` and continuous at the supremum of a set sends this supremum to the infimum of the image of this set. -/ theorem AntitoneOn.map_sSup_of_continuousWithinAt {f : α → β} {s : Set α} (Cf : ContinuousWithinAt f s (sSup s)) (Af : AntitoneOn f s) (fbot : f ⊥ = ⊤) : f (sSup s) = sInf (f '' s) := MonotoneOn.map_sSup_of_continuousWithinAt (show ContinuousWithinAt (OrderDual.toDual ∘ f) s (sSup s) from Cf) Af fbot /-- An antitone function `f` sending `bot` to `top` and continuous at the supremum of a set sends this supremum to the infimum of the image of this set. -/ theorem Antitone.map_sSup_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sSup s)) (Af : Antitone f) (fbot : f ⊥ = ⊤) : f (sSup s) = sInf (f '' s) := Monotone.map_sSup_of_continuousAt (show ContinuousAt (OrderDual.toDual ∘ f) (sSup s) from Cf) Af fbot /-- An antitone function sending `bot` to `top` is continuous at the indexed supremum over a `Sort`, then it sends this indexed supremum to the indexed supremum of the composition. -/ theorem Antitone.map_iSup_of_continuousAt {ι : Sort*} {f : α → β} {g : ι → α} (Cf : ContinuousAt f (iSup g)) (Af : Antitone f) (fbot : f ⊥ = ⊤) : f (⨆ i, g i) = ⨅ i, f (g i) := Monotone.map_iSup_of_continuousAt (show ContinuousAt (OrderDual.toDual ∘ f) (iSup g) from Cf) Af fbot /-- An antitone function `f` sending `top` to `bot` and continuous at the infimum of a set sends this infimum to the supremum of the image of this set. -/ theorem AntitoneOn.map_sInf_of_continuousWithinAt {f : α → β} {s : Set α} (Cf : ContinuousWithinAt f s (sInf s)) (Af : AntitoneOn f s) (ftop : f ⊤ = ⊥) : f (sInf s) = sSup (f '' s) := MonotoneOn.map_sInf_of_continuousWithinAt (show ContinuousWithinAt (OrderDual.toDual ∘ f) s (sInf s) from Cf) Af ftop /-- An antitone function `f` sending `top` to `bot` and continuous at the infimum of a set sends this infimum to the supremum of the image of this set. -/ theorem Antitone.map_sInf_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sInf s)) (Af : Antitone f) (ftop : f ⊤ = ⊥) : f (sInf s) = sSup (f '' s) := Monotone.map_sInf_of_continuousAt (show ContinuousAt (OrderDual.toDual ∘ f) (sInf s) from Cf) Af ftop
/-- If an antitone function sending `top` to `bot` is continuous at the indexed infimum over a `Sort`, then it sends this indexed infimum to the indexed supremum of the composition. -/ theorem Antitone.map_iInf_of_continuousAt {ι : Sort*} {f : α → β} {g : ι → α} (Cf : ContinuousAt f (iInf g)) (Af : Antitone f) (ftop : f ⊤ = ⊥) : f (iInf g) = iSup (f ∘ g) := Monotone.map_iInf_of_continuousAt (show ContinuousAt (OrderDual.toDual ∘ f) (iInf g) from Cf) Af
Mathlib/Topology/Order/Monotone.lean
221
225
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis -/ import Mathlib.NumberTheory.Padics.PadicVal.Basic /-! # p-adic norm This file defines the `p`-adic norm on `ℚ`. The `p`-adic valuation on `ℚ` is the difference of the multiplicities of `p` in the numerator and denominator of `q`. This function obeys the standard properties of a valuation, with the appropriate assumptions on `p`. The valuation induces a norm on `ℚ`. This norm is a nonarchimedean absolute value. It takes values in {0} ∪ {1/p^k | k ∈ ℤ}. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking `[Fact p.Prime]` as a type class argument. ## References * [F. Q. Gouvêa, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, norm, valuation -/ /-- If `q ≠ 0`, the `p`-adic norm of a rational `q` is `p ^ (-padicValRat p q)`. If `q = 0`, the `p`-adic norm of `q` is `0`. -/ def padicNorm (p : ℕ) (q : ℚ) : ℚ := if q = 0 then 0 else (p : ℚ) ^ (-padicValRat p q) namespace padicNorm open padicValRat variable {p : ℕ} /-- Unfolds the definition of the `p`-adic norm of `q` when `q ≠ 0`. -/ @[simp] protected theorem eq_zpow_of_nonzero {q : ℚ} (hq : q ≠ 0) : padicNorm p q = (p : ℚ) ^ (-padicValRat p q) := by simp [hq, padicNorm] /-- The `p`-adic norm is nonnegative. -/ protected theorem nonneg (q : ℚ) : 0 ≤ padicNorm p q := if hq : q = 0 then by simp [hq, padicNorm] else by unfold padicNorm split_ifs apply zpow_nonneg exact mod_cast Nat.zero_le _ /-- The `p`-adic norm of `0` is `0`. -/ @[simp] protected theorem zero : padicNorm p 0 = 0 := by simp [padicNorm] /-- The `p`-adic norm of `1` is `1`. -/ protected theorem one : padicNorm p 1 = 1 := by simp [padicNorm] /-- The `p`-adic norm of `p` is `p⁻¹` if `p > 1`. See also `padicNorm.padicNorm_p_of_prime` for a version assuming `p` is prime. -/ theorem padicNorm_p (hp : 1 < p) : padicNorm p p = (p : ℚ)⁻¹ := by simp [padicNorm, (pos_of_gt hp).ne', padicValNat.self hp] /-- The `p`-adic norm of `p` is `p⁻¹` if `p` is prime. See also `padicNorm.padicNorm_p` for a version assuming `1 < p`. -/ @[simp] theorem padicNorm_p_of_prime [Fact p.Prime] : padicNorm p p = (p : ℚ)⁻¹ := padicNorm_p <| Nat.Prime.one_lt Fact.out /-- The `p`-adic norm of `q` is `1` if `q` is prime and not equal to `p`. -/ theorem padicNorm_of_prime_of_ne {q : ℕ} [p_prime : Fact p.Prime] [q_prime : Fact q.Prime] (neq : p ≠ q) : padicNorm p q = 1 := by have p : padicValRat p q = 0 := mod_cast padicValNat_primes neq rw [padicNorm, p] simp [q_prime.1.ne_zero] /-- The `p`-adic norm of `p` is less than `1` if `1 < p`. See also `padicNorm.padicNorm_p_lt_one_of_prime` for a version assuming `p` is prime. -/ theorem padicNorm_p_lt_one (hp : 1 < p) : padicNorm p p < 1 := by rw [padicNorm_p hp, inv_lt_one_iff₀] exact mod_cast Or.inr hp /-- The `p`-adic norm of `p` is less than `1` if `p` is prime. See also `padicNorm.padicNorm_p_lt_one` for a version assuming `1 < p`. -/ theorem padicNorm_p_lt_one_of_prime [Fact p.Prime] : padicNorm p p < 1 := padicNorm_p_lt_one <| Nat.Prime.one_lt Fact.out /-- `padicNorm p q` takes discrete values `p ^ -z` for `z : ℤ`. -/ protected theorem values_discrete {q : ℚ} (hq : q ≠ 0) : ∃ z : ℤ, padicNorm p q = (p : ℚ) ^ (-z) :=
⟨padicValRat p q, by simp [padicNorm, hq]⟩ /-- `padicNorm p` is symmetric. -/
Mathlib/NumberTheory/Padics/PadicNorm.lean
104
106
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.MorphismProperty.Composition import Mathlib.CategoryTheory.MorphismProperty.IsInvertedBy import Mathlib.CategoryTheory.Category.Quiv /-! # Construction of the localized category This file constructs the localized category, obtained by formally inverting a class of maps `W : MorphismProperty C` in a category `C`. We first construct a quiver `LocQuiver W` whose objects are the same as those of `C` and whose maps are the maps in `C` and placeholders for the formal inverses of the maps in `W`. The localized category `W.Localization` is obtained by taking the quotient of the path category of `LocQuiver W` by the congruence generated by four types of relations. The obvious functor `Q W : C ⥤ W.Localization` satisfies the universal property of the localization. Indeed, if `G : C ⥤ D` sends morphisms in `W` to isomorphisms in `D` (i.e. we have `hG : W.IsInvertedBy G`), then there exists a unique functor `G' : W.Localization ⥤ D` such that `Q W ≫ G' = G`. This `G'` is `lift G hG`. The expected property of `lift G hG` if expressed by the lemma `fac` and the uniqueness is expressed by `uniq`. ## References * [P. Gabriel, M. Zisman, *Calculus of fractions and homotopy theory*][gabriel-zisman-1967] -/ noncomputable section open CategoryTheory.Category namespace CategoryTheory -- category universes first for convenience universe uC' uD' uC uD variable {C : Type uC} [Category.{uC'} C] (W : MorphismProperty C) {D : Type uD} [Category.{uD'} D] namespace Localization namespace Construction /-- If `W : MorphismProperty C`, `LocQuiver W` is a quiver with the same objects as `C`, and whose morphisms are those in `C` and placeholders for formal inverses of the morphisms in `W`. -/ structure LocQuiver (W : MorphismProperty C) where /-- underlying object -/ obj : C instance : Quiver (LocQuiver W) where Hom A B := (A.obj ⟶ B.obj) ⊕ { f : B.obj ⟶ A.obj // W f } /-- The object in the path category of `LocQuiver W` attached to an object in the category `C` -/ def ιPaths (X : C) : Paths (LocQuiver W) := ⟨X⟩ /-- The morphism in the path category associated to a morphism in the original category. -/ @[simp] def ψ₁ {X Y : C} (f : X ⟶ Y) : ιPaths W X ⟶ ιPaths W Y := (Paths.of _).map (Sum.inl f) /-- The morphism in the path category corresponding to a formal inverse. -/ @[simp] def ψ₂ {X Y : C} (w : X ⟶ Y) (hw : W w) : ιPaths W Y ⟶ ιPaths W X := (Paths.of _).map (Sum.inr ⟨w, hw⟩) /-- The relations by which we take the quotient in order to get the localized category. -/ inductive relations : HomRel (Paths (LocQuiver W)) | id (X : C) : relations (ψ₁ W (𝟙 X)) (𝟙 _) | comp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : relations (ψ₁ W (f ≫ g)) (ψ₁ W f ≫ ψ₁ W g) | Winv₁ {X Y : C} (w : X ⟶ Y) (hw : W w) : relations (ψ₁ W w ≫ ψ₂ W w hw) (𝟙 _) | Winv₂ {X Y : C} (w : X ⟶ Y) (hw : W w) : relations (ψ₂ W w hw ≫ ψ₁ W w) (𝟙 _) end Construction end Localization namespace MorphismProperty open Localization.Construction /-- The localized category obtained by formally inverting the morphisms in `W : MorphismProperty C` -/ def Localization := CategoryTheory.Quotient (Localization.Construction.relations W) instance : Category (Localization W) := by dsimp only [Localization] infer_instance /-- The obvious functor `C ⥤ W.Localization` -/ def Q : C ⥤ W.Localization where obj X := (Quotient.functor _).obj ((Paths.of _).obj ⟨X⟩) map f := (Quotient.functor _).map (ψ₁ W f) map_id X := Quotient.sound _ (relations.id X) map_comp f g := Quotient.sound _ (relations.comp f g) end MorphismProperty namespace Localization namespace Construction variable {W} /-- The isomorphism in `W.Localization` associated to a morphism `w` in W -/ def wIso {X Y : C} (w : X ⟶ Y) (hw : W w) : Iso (W.Q.obj X) (W.Q.obj Y) where hom := W.Q.map w inv := (Quotient.functor _).map (by dsimp; exact (Paths.of _).map (Sum.inr ⟨w, hw⟩)) hom_inv_id := Quotient.sound _ (relations.Winv₁ w hw) inv_hom_id := Quotient.sound _ (relations.Winv₂ w hw) /-- The formal inverse in `W.Localization` of a morphism `w` in `W`. -/ abbrev wInv {X Y : C} (w : X ⟶ Y) (hw : W w) := (wIso w hw).inv variable (W) in theorem _root_.CategoryTheory.MorphismProperty.Q_inverts : W.IsInvertedBy W.Q := fun _ _ w hw => (Localization.Construction.wIso w hw).isIso_hom variable (G : C ⥤ D) (hG : W.IsInvertedBy G) /-- The lifting of a functor to the path category of `LocQuiver W` -/ @[simps!] def liftToPathCategory : Paths (LocQuiver W) ⥤ D := Quiv.lift { obj := fun X => G.obj X.obj map := by intros X Y rintro (f | ⟨g, hg⟩) · exact G.map f · haveI := hG g hg exact inv (G.map g) } /-- The lifting of a functor `C ⥤ D` inverting `W` as a functor `W.Localization ⥤ D` -/ @[simps!] def lift : W.Localization ⥤ D := Quotient.lift (relations W) (liftToPathCategory G hG) (by rintro ⟨X⟩ ⟨Y⟩ f₁ f₂ r -- Porting note: rest of proof was `rcases r with ⟨⟩; tidy` rcases r with (_|_|⟨f,hf⟩|⟨f,hf⟩) · aesop_cat · simp all_goals dsimp haveI := hG f hf simp rfl) @[simp] theorem fac : W.Q ⋙ lift G hG = G := Functor.ext (fun _ => rfl) (by intro X Y f simp only [Functor.comp_map, eqToHom_refl, comp_id, id_comp] dsimp [MorphismProperty.Q, Quot.liftOn, Quotient.functor] rw [composePath_toPath]) theorem uniq (G₁ G₂ : W.Localization ⥤ D) (h : W.Q ⋙ G₁ = W.Q ⋙ G₂) : G₁ = G₂ := by suffices h' : Quotient.functor _ ⋙ G₁ = Quotient.functor _ ⋙ G₂ by refine Functor.ext ?_ ?_ · rintro ⟨⟨X⟩⟩ apply Functor.congr_obj h · rintro ⟨⟨X⟩⟩ ⟨⟨Y⟩⟩ ⟨f⟩ apply Functor.congr_hom h' refine Paths.ext_functor ?_ ?_ · ext X cases X apply Functor.congr_obj h · rintro ⟨X⟩ ⟨Y⟩ (f | ⟨w, hw⟩) · simpa only using Functor.congr_hom h f · have hw : W.Q.map w = (wIso w hw).hom := rfl have hw' := Functor.congr_hom h w simp only [Functor.comp_map, hw] at hw' refine Functor.congr_inv_of_congr_hom _ _ _ ?_ ?_ hw' all_goals apply Functor.congr_obj h variable (W) in /-- The canonical bijection between objects in a category and its localization with respect to a morphism_property `W` -/ @[simps] def objEquiv : C ≃ W.Localization where toFun := W.Q.obj invFun X := X.as.obj left_inv _ := rfl right_inv := by rintro ⟨⟨X⟩⟩ rfl /-- A `MorphismProperty` in `W.Localization` is satisfied by all morphisms in the localized category if it contains the image of the morphisms in the original category, the inverses of the morphisms in `W` and if it is stable under composition -/ theorem morphismProperty_is_top (P : MorphismProperty W.Localization) [P.IsStableUnderComposition] (hP₁ : ∀ ⦃X Y : C⦄ (f : X ⟶ Y), P (W.Q.map f)) (hP₂ : ∀ ⦃X Y : C⦄ (w : X ⟶ Y) (hw : W w), P (wInv w hw)) : P = ⊤ := by funext X Y f ext constructor · intro apply MorphismProperty.top_apply · intro let G : _ ⥤ W.Localization := Quotient.functor _ haveI : G.Full := Quotient.full_functor _ suffices ∀ (X₁ X₂ : Paths (LocQuiver W)) (f : X₁ ⟶ X₂), P (G.map f) by rcases X with ⟨⟨X⟩⟩ rcases Y with ⟨⟨Y⟩⟩ simpa only [Functor.map_preimage] using this _ _ (G.preimage f) intros X₁ X₂ p induction p with | nil => simpa only [Functor.map_id] using hP₁ (𝟙 X₁.obj) | @cons X₂ X₃ p g hp => let p' : X₁ ⟶X₂ := p rw [show p'.cons g = p' ≫ Quiver.Hom.toPath g by rfl, G.map_comp] refine P.comp_mem _ _ hp ?_ rcases g with (g | ⟨g, hg⟩) · apply hP₁ · apply hP₂ /-- A `MorphismProperty` in `W.Localization` is satisfied by all morphisms in the localized category if it contains the image of the morphisms in the original category, if is stable under composition and if the property is stable by passing to inverses. -/ theorem morphismProperty_is_top' (P : MorphismProperty W.Localization) [P.IsStableUnderComposition] (hP₁ : ∀ ⦃X Y : C⦄ (f : X ⟶ Y), P (W.Q.map f)) (hP₂ : ∀ ⦃X Y : W.Localization⦄ (e : X ≅ Y) (_ : P e.hom), P e.inv) : P = ⊤ := morphismProperty_is_top P hP₁ (fun _ _ w _ => hP₂ _ (hP₁ w)) namespace NatTransExtension variable {F₁ F₂ : W.Localization ⥤ D} (τ : W.Q ⋙ F₁ ⟶ W.Q ⋙ F₂) /-- If `F₁` and `F₂` are functors `W.Localization ⥤ D` and if we have `τ : W.Q ⋙ F₁ ⟶ W.Q ⋙ F₂`, we shall define a natural transformation `F₁ ⟶ F₂`. This is the `app` field of this natural transformation. -/ def app (X : W.Localization) : F₁.obj X ⟶ F₂.obj X := eqToHom (congr_arg F₁.obj ((objEquiv W).right_inv X).symm) ≫ τ.app ((objEquiv W).invFun X) ≫ eqToHom (congr_arg F₂.obj ((objEquiv W).right_inv X)) @[simp] theorem app_eq (X : C) : (app τ) (W.Q.obj X) = τ.app X := by simp only [app, eqToHom_refl, comp_id, id_comp] rfl end NatTransExtension /-- If `F₁` and `F₂` are functors `W.Localization ⥤ D`, a natural transformation `F₁ ⟶ F₂` can be obtained from a natural transformation `W.Q ⋙ F₁ ⟶ W.Q ⋙ F₂`. -/ @[simps] def natTransExtension {F₁ F₂ : W.Localization ⥤ D} (τ : W.Q ⋙ F₁ ⟶ W.Q ⋙ F₂) : F₁ ⟶ F₂ where app := NatTransExtension.app τ naturality := by suffices MorphismProperty.naturalityProperty (NatTransExtension.app τ) = ⊤ by intro X Y f simpa only [← this] using MorphismProperty.top_apply f refine morphismProperty_is_top' (MorphismProperty.naturalityProperty (NatTransExtension.app τ)) ?_ (MorphismProperty.naturalityProperty.stableUnderInverse _) intros X Y f dsimp simpa only [NatTransExtension.app_eq] using τ.naturality f @[simp] theorem whiskerLeft_natTransExtension {F G : W.Localization ⥤ D} (τ : W.Q ⋙ F ⟶ W.Q ⋙ G) : whiskerLeft W.Q (natTransExtension τ) = τ := by aesop_cat -- This is not a simp lemma, because the simp norm form of the left-hand side uses `whiskerLeft`. theorem natTransExtension_hcomp {F G : W.Localization ⥤ D} (τ : W.Q ⋙ F ⟶ W.Q ⋙ G) : 𝟙 W.Q ◫ natTransExtension τ = τ := by aesop_cat theorem natTrans_hcomp_injective {F G : W.Localization ⥤ D} {τ₁ τ₂ : F ⟶ G} (h : 𝟙 W.Q ◫ τ₁ = 𝟙 W.Q ◫ τ₂) : τ₁ = τ₂ := by ext X have eq := (objEquiv W).right_inv X simp only [objEquiv] at eq rw [← eq, ← NatTrans.id_hcomp_app, ← NatTrans.id_hcomp_app, h] variable (W D) namespace WhiskeringLeftEquivalence /-- The functor `(W.Localization ⥤ D) ⥤ (W.FunctorsInverting D)` induced by the composition with `W.Q : C ⥤ W.Localization`. -/ @[simps!] def functor : (W.Localization ⥤ D) ⥤ W.FunctorsInverting D := ObjectProperty.lift _ ((whiskeringLeft _ _ D).obj W.Q) fun _ => MorphismProperty.IsInvertedBy.of_comp W W.Q W.Q_inverts _ /-- The function `(W.FunctorsInverting D) ⥤ (W.Localization ⥤ D)` induced by `Construction.lift`. -/ @[simps!] def inverse : W.FunctorsInverting D ⥤ W.Localization ⥤ D where obj G := lift G.obj G.property map τ := natTransExtension (eqToHom (by rw [fac]) ≫ τ ≫ eqToHom (by rw [fac])) map_id G := natTrans_hcomp_injective
(by rw [natTransExtension_hcomp]
Mathlib/CategoryTheory/Localization/Construction.lean
307
308
/- Copyright (c) 2022 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez -/ import Mathlib.Algebra.IsPrimePow import Mathlib.SetTheory.Cardinal.Arithmetic import Mathlib.Tactic.WLOG /-! # Cardinal Divisibility We show basic results about divisibility in the cardinal numbers. This relation can be characterised in the following simple way: if `a` and `b` are both less than `ℵ₀`, then `a ∣ b` iff they are divisible as natural numbers. If `b` is greater than `ℵ₀`, then `a ∣ b` iff `a ≤ b`. This furthermore shows that all infinite cardinals are prime; recall that `a * b = max a b` if `ℵ₀ ≤ a * b`; therefore `a ∣ b * c = a ∣ max b c` and therefore clearly either `a ∣ b` or `a ∣ c`. Note furthermore that no infinite cardinal is irreducible (`Cardinal.not_irreducible_of_aleph0_le`), showing that the cardinal numbers do not form a `CancelCommMonoidWithZero`. ## Main results * `Cardinal.prime_of_aleph0_le`: a `Cardinal` is prime if it is infinite. * `Cardinal.is_prime_iff`: a `Cardinal` is prime iff it is infinite or a prime natural number. * `Cardinal.isPrimePow_iff`: a `Cardinal` is a prime power iff it is infinite or a natural number which is itself a prime power. -/ namespace Cardinal universe u variable {a b : Cardinal.{u}} {n m : ℕ} /-- Alias of `isUnit_iff_eq_one` for discoverability. -/ theorem isUnit_iff : IsUnit a ↔ a = 1 := by refine ⟨fun h => ?_, by rintro rfl exact isUnit_one⟩ rcases eq_or_ne a 0 with (rfl | ha) · exact (not_isUnit_zero h).elim rw [isUnit_iff_forall_dvd] at h obtain ⟨t, ht⟩ := h 1 rw [eq_comm, mul_eq_one_iff_of_one_le] at ht · exact ht.1 · exact one_le_iff_ne_zero.mpr ha · apply one_le_iff_ne_zero.mpr intro h rw [h, mul_zero] at ht exact zero_ne_one ht instance : Unique Cardinal.{u}ˣ where default := 1 uniq a := Units.val_eq_one.mp <| isUnit_iff.mp a.isUnit theorem le_of_dvd : ∀ {a b : Cardinal}, b ≠ 0 → a ∣ b → a ≤ b | a, x, b0, ⟨b, hab⟩ => by simpa only [hab, mul_one] using mul_le_mul_left' (one_le_iff_ne_zero.2 fun h : b = 0 => b0 (by rwa [h, mul_zero] at hab)) a
theorem dvd_of_le_of_aleph0_le (ha : a ≠ 0) (h : a ≤ b) (hb : ℵ₀ ≤ b) : a ∣ b := ⟨b, (mul_eq_right hb h ha).symm⟩ @[simp]
Mathlib/SetTheory/Cardinal/Divisibility.lean
65
68
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.RingTheory.HahnSeries.Multiplication /-! # Summable families of Hahn Series We introduce a notion of formal summability for families of Hahn series, and define a formal sum function. This theory is applied to characterize invertible Hahn series whose coefficients are in a commutative domain. ## Main Definitions * A `HahnSeries.SummableFamily` is a family of Hahn series such that the union of the supports is partially well-ordered and only finitely many are nonzero at any given coefficient. Note that this is different from `Summable` in the valuation topology, because there are topologically summable families that do not satisfy the axioms of `HahnSeries.SummableFamily`, and formally summable families whose sums do not converge topologically. * The formal sum, `HahnSeries.SummableFamily.hsum` can be bundled as a `LinearMap` via `HahnSeries.SummableFamily.lsum`. ## Main results * If `R` is a commutative domain, and `Γ` is a linearly ordered additive commutative group, then a Hahn series is a unit if and only if its leading term is a unit in `R`. ## TODO * Remove unnecessary domain hypotheses. * More general summable families, e.g., define the evaluation homomorphism from a power series ring taking `X` to a positive order element. ## References - [J. van der Hoeven, *Operators on Generalized Power Series*][van_der_hoeven] -/ open Finset Function open Pointwise noncomputable section variable {Γ Γ' R V α β : Type*} namespace HahnSeries section /-- A family of Hahn series whose formal coefficient-wise sum is a Hahn series. For each coefficient of the sum to be well-defined, we require that only finitely many series are nonzero at any given coefficient. For the formal sum to be a Hahn series, we require that the union of the supports of the constituent series is partially well-ordered. -/ structure SummableFamily (Γ) (R) [PartialOrder Γ] [AddCommMonoid R] (α : Type*) where /-- A parametrized family of Hahn series. -/ toFun : α → HahnSeries Γ R isPWO_iUnion_support' : Set.IsPWO (⋃ a : α, (toFun a).support) finite_co_support' : ∀ g : Γ, { a | (toFun a).coeff g ≠ 0 }.Finite end namespace SummableFamily section AddCommMonoid variable [PartialOrder Γ] [AddCommMonoid R] instance : FunLike (SummableFamily Γ R α) α (HahnSeries Γ R) where coe := toFun coe_injective' | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl theorem isPWO_iUnion_support (s : SummableFamily Γ R α) : Set.IsPWO (⋃ a : α, (s a).support) := s.isPWO_iUnion_support' theorem finite_co_support (s : SummableFamily Γ R α) (g : Γ) : (Function.support fun a => (s a).coeff g).Finite := s.finite_co_support' g theorem coe_injective : @Function.Injective (SummableFamily Γ R α) (α → HahnSeries Γ R) (⇑) := DFunLike.coe_injective @[ext] theorem ext {s t : SummableFamily Γ R α} (h : ∀ a : α, s a = t a) : s = t := DFunLike.ext s t h instance : Add (SummableFamily Γ R α) := ⟨fun x y => { toFun := x + y isPWO_iUnion_support' := (x.isPWO_iUnion_support.union y.isPWO_iUnion_support).mono (by rw [← Set.iUnion_union_distrib] exact Set.iUnion_mono fun a => support_add_subset) finite_co_support' := fun g => ((x.finite_co_support g).union (y.finite_co_support g)).subset (by intro a ha change (x a).coeff g + (y a).coeff g ≠ 0 at ha rw [Set.mem_union, Function.mem_support, Function.mem_support] contrapose! ha rw [ha.1, ha.2, add_zero]) }⟩ instance : Zero (SummableFamily Γ R α) := ⟨⟨0, by simp, by simp⟩⟩ instance : Inhabited (SummableFamily Γ R α) := ⟨0⟩ @[simp] theorem coe_add {s t : SummableFamily Γ R α} : ⇑(s + t) = s + t := rfl theorem add_apply {s t : SummableFamily Γ R α} {a : α} : (s + t) a = s a + t a := rfl @[simp] theorem coe_zero : ((0 : SummableFamily Γ R α) : α → HahnSeries Γ R) = 0 := rfl theorem zero_apply {a : α} : (0 : SummableFamily Γ R α) a = 0 := rfl instance : AddCommMonoid (SummableFamily Γ R α) where zero := 0 nsmul := nsmulRec zero_add s := by ext apply zero_add add_zero s := by ext apply add_zero add_comm s t := by ext apply add_comm add_assoc r s t := by ext apply add_assoc /-- The coefficient function of a summable family, as a finsupp on the parameter type. -/ @[simps] def coeff (s : SummableFamily Γ R α) (g : Γ) : α →₀ R where support := (s.finite_co_support g).toFinset toFun a := (s a).coeff g mem_support_toFun a := by simp @[simp] theorem coeff_def (s : SummableFamily Γ R α) (a : α) (g : Γ) : s.coeff g a = (s a).coeff g := rfl /-- The infinite sum of a `SummableFamily` of Hahn series. -/ def hsum (s : SummableFamily Γ R α) : HahnSeries Γ R where coeff g := ∑ᶠ i, (s i).coeff g isPWO_support' := s.isPWO_iUnion_support.mono fun g => by contrapose rw [Set.mem_iUnion, not_exists, Function.mem_support, Classical.not_not] simp_rw [mem_support, Classical.not_not] intro h rw [finsum_congr h, finsum_zero] @[simp] theorem coeff_hsum {s : SummableFamily Γ R α} {g : Γ} : s.hsum.coeff g = ∑ᶠ i, (s i).coeff g := rfl @[deprecated (since := "2025-01-31")] alias hsum_coeff := coeff_hsum theorem support_hsum_subset {s : SummableFamily Γ R α} : s.hsum.support ⊆ ⋃ a : α, (s a).support := fun g hg => by rw [mem_support, coeff_hsum, finsum_eq_sum _ (s.finite_co_support _)] at hg obtain ⟨a, _, h2⟩ := exists_ne_zero_of_sum_ne_zero hg rw [Set.mem_iUnion] exact ⟨a, h2⟩ @[simp] theorem hsum_add {s t : SummableFamily Γ R α} : (s + t).hsum = s.hsum + t.hsum := by ext g simp only [coeff_hsum, coeff_add, add_apply] exact finsum_add_distrib (s.finite_co_support _) (t.finite_co_support _) theorem coeff_hsum_eq_sum_of_subset {s : SummableFamily Γ R α} {g : Γ} {t : Finset α} (h : { a | (s a).coeff g ≠ 0 } ⊆ t) : s.hsum.coeff g = ∑ i ∈ t, (s i).coeff g := by simp only [coeff_hsum, finsum_eq_sum _ (s.finite_co_support _)] exact sum_subset (Set.Finite.toFinset_subset.mpr h) (by simp) @[deprecated (since := "2025-01-31")] alias hsum_coeff_eq_sum_of_subset := coeff_hsum_eq_sum_of_subset theorem coeff_hsum_eq_sum {s : SummableFamily Γ R α} {g : Γ} : s.hsum.coeff g = ∑ i ∈ (s.coeff g).support, (s i).coeff g := by simp only [coeff_hsum, finsum_eq_sum _ (s.finite_co_support _), coeff_support] @[deprecated (since := "2025-01-31")] alias hsum_coeff_eq_sum := coeff_hsum_eq_sum /-- The summable family made of a single Hahn series. -/ @[simps] def single (x : HahnSeries Γ R) : SummableFamily Γ R Unit where toFun _ := x isPWO_iUnion_support' := Eq.mpr (congrArg (fun s ↦ s.IsPWO) (Set.iUnion_const x.support)) x.isPWO_support finite_co_support' g := Set.toFinite {a | ((fun _ ↦ x) a).coeff g ≠ 0} @[simp] theorem hsum_single (x : HahnSeries Γ R) : (single x).hsum = x := by ext g simp only [coeff_hsum, single_toFun, finsum_unique] /-- A summable family induced by an equivalence of the parametrizing type. -/ @[simps] def Equiv (e : α ≃ β) (s : SummableFamily Γ R α) : SummableFamily Γ R β where toFun b := s (e.symm b) isPWO_iUnion_support' := by refine Set.IsPWO.mono s.isPWO_iUnion_support fun g => ?_ simp only [Set.mem_iUnion, mem_support, ne_eq, forall_exists_index] exact fun b hg => Exists.intro (e.symm b) hg finite_co_support' g := (Equiv.set_finite_iff e.subtypeEquivOfSubtype').mp <| s.finite_co_support' g @[simp] theorem hsum_equiv (e : α ≃ β) (s : SummableFamily Γ R α) : (Equiv e s).hsum = s.hsum := by ext g simp only [coeff_hsum, Equiv_toFun] exact finsum_eq_of_bijective e.symm (Equiv.bijective e.symm) fun x => rfl /-- The summable family given by multiplying every series in a summable family by a scalar. -/ @[simps] def smulFamily [AddCommMonoid V] [SMulWithZero R V] (f : α → R) (s : SummableFamily Γ V α) : SummableFamily Γ V α where toFun a := (f a) • s a isPWO_iUnion_support' := by refine Set.IsPWO.mono s.isPWO_iUnion_support fun g hg => ?_ simp_all only [Set.mem_iUnion, mem_support, coeff_smul, ne_eq] obtain ⟨i, hi⟩ := hg exact Exists.intro i <| right_ne_zero_of_smul hi finite_co_support' g := by refine Set.Finite.subset (s.finite_co_support g) fun i hi => ?_ simp_all only [coeff_smul, ne_eq, Set.mem_setOf_eq, Function.mem_support] exact right_ne_zero_of_smul hi theorem hsum_smulFamily [AddCommMonoid V] [SMulWithZero R V] (f : α → R) (s : SummableFamily Γ V α) (g : Γ) : (smulFamily f s).hsum.coeff g = ∑ᶠ i, (f i) • ((s i).coeff g) := rfl end AddCommMonoid section AddCommGroup variable [PartialOrder Γ] [AddCommGroup R] {s t : SummableFamily Γ R α} {a : α} instance : Neg (SummableFamily Γ R α) := ⟨fun s => { toFun := fun a => -s a isPWO_iUnion_support' := by simp_rw [support_neg] exact s.isPWO_iUnion_support finite_co_support' := fun g => by simp only [coeff_neg', Pi.neg_apply, Ne, neg_eq_zero] exact s.finite_co_support g }⟩ instance : AddCommGroup (SummableFamily Γ R α) := { inferInstanceAs (AddCommMonoid (SummableFamily Γ R α)) with zsmul := zsmulRec neg_add_cancel := fun a => by ext apply neg_add_cancel } @[simp] theorem coe_neg : ⇑(-s) = -s := rfl theorem neg_apply : (-s) a = -s a := rfl @[simp] theorem coe_sub : ⇑(s - t) = s - t := rfl theorem sub_apply : (s - t) a = s a - t a := rfl end AddCommGroup section SMul variable [PartialOrder Γ] [PartialOrder Γ'] [AddCommMonoid V] instance [Zero R] [SMulWithZero R V] : SMul R (SummableFamily Γ' V β) := ⟨fun r t => { toFun := r • t isPWO_iUnion_support' := t.isPWO_iUnion_support.mono (Set.iUnion_mono fun i => Pi.smul_apply r t i ▸ Function.support_const_smul_subset r _) finite_co_support' := by intro g refine (t.finite_co_support g).subset ?_ intro i hi simp only [Pi.smul_apply, coeff_smul, ne_eq, Set.mem_setOf_eq] at hi simp only [Function.mem_support, ne_eq] exact right_ne_zero_of_smul hi } ⟩ variable [AddCommMonoid R] [SMulWithZero R V] theorem smul_support_subset_prod (s : SummableFamily Γ R α) (t : SummableFamily Γ' V β) (gh : Γ × Γ') : (Function.support fun (i : α × β) ↦ (s i.1).coeff gh.1 • (t i.2).coeff gh.2) ⊆ ((s.finite_co_support' gh.1).prod (t.finite_co_support' gh.2)).toFinset := by intro _ hab simp_all only [Function.mem_support, ne_eq, Set.Finite.coe_toFinset, Set.mem_prod, Set.mem_setOf_eq] exact ⟨left_ne_zero_of_smul hab, right_ne_zero_of_smul hab⟩ theorem smul_support_finite (s : SummableFamily Γ R α) (t : SummableFamily Γ' V β) (gh : Γ × Γ') : (Function.support fun (i : α × β) ↦ (s i.1).coeff gh.1 • (t i.2).coeff gh.2).Finite := Set.Finite.subset (Set.toFinite ((s.finite_co_support' gh.1).prod (t.finite_co_support' gh.2)).toFinset) (smul_support_subset_prod s t gh) variable [VAdd Γ Γ'] [IsOrderedCancelVAdd Γ Γ'] open HahnModule theorem isPWO_iUnion_support_prod_smul {s : α → HahnSeries Γ R} {t : β → HahnSeries Γ' V} (hs : (⋃ a, (s a).support).IsPWO) (ht : (⋃ b, (t b).support).IsPWO) : (⋃ (a : α × β), ((fun a ↦ (of R).symm ((s a.1) • (of R) (t a.2))) a).support).IsPWO := by apply (hs.vadd ht).mono have hsupp : ∀ ab : α × β, support ((fun ab ↦ (of R).symm (s ab.1 • (of R) (t ab.2))) ab) ⊆ (s ab.1).support +ᵥ (t ab.2).support := by intro ab refine Set.Subset.trans (fun x hx => ?_) (support_vaddAntidiagonal_subset_vadd (hs := (s ab.1).isPWO_support) (ht := (t ab.2).isPWO_support)) contrapose! hx simp only [Set.mem_setOf_eq, not_nonempty_iff_eq_empty] at hx rw [mem_support, not_not, HahnModule.coeff_smul, hx, sum_empty] refine Set.Subset.trans (Set.iUnion_mono fun a => (hsupp a)) ?_ simp_all only [Set.iUnion_subset_iff, Prod.forall] exact fun a b => Set.vadd_subset_vadd (Set.subset_iUnion_of_subset a fun x y ↦ y) (Set.subset_iUnion_of_subset b fun x y ↦ y) theorem finite_co_support_prod_smul (s : SummableFamily Γ R α) (t : SummableFamily Γ' V β) (g : Γ') : Finite {(ab : α × β) | ((fun (ab : α × β) ↦ (of R).symm (s ab.1 • (of R) (t ab.2))) ab).coeff g ≠ 0} := by apply ((VAddAntidiagonal s.isPWO_iUnion_support t.isPWO_iUnion_support g).finite_toSet.biUnion' (fun gh _ => smul_support_finite s t gh)).subset _ exact fun ab hab => by simp only [coeff_smul, ne_eq, Set.mem_setOf_eq] at hab obtain ⟨ij, hij⟩ := Finset.exists_ne_zero_of_sum_ne_zero hab simp only [mem_coe, mem_vaddAntidiagonal, Set.mem_iUnion, mem_support, ne_eq, Function.mem_support, exists_prop, Prod.exists] exact ⟨ij.1, ij.2, ⟨⟨ab.1, left_ne_zero_of_smul hij.2⟩, ⟨ab.2, right_ne_zero_of_smul hij.2⟩, ((mem_vaddAntidiagonal _ _ _).mp hij.1).2.2⟩, hij.2⟩ /-- An elementwise scalar multiplication of one summable family on another. -/ @[simps] def smul (s : SummableFamily Γ R α) (t : SummableFamily Γ' V β) : SummableFamily Γ' V (α × β) where toFun ab := (of R).symm (s (ab.1) • ((of R) (t (ab.2)))) isPWO_iUnion_support' := isPWO_iUnion_support_prod_smul s.isPWO_iUnion_support t.isPWO_iUnion_support finite_co_support' g := finite_co_support_prod_smul s t g @[deprecated (since := "2024-11-17")] noncomputable alias FamilySMul := smul theorem sum_vAddAntidiagonal_eq (s : SummableFamily Γ R α) (t : SummableFamily Γ' V β) (g : Γ') (a : α × β) : ∑ x ∈ VAddAntidiagonal (s a.1).isPWO_support' (t a.2).isPWO_support' g, (s a.1).coeff x.1 • (t a.2).coeff x.2 = ∑ x ∈ VAddAntidiagonal s.isPWO_iUnion_support' t.isPWO_iUnion_support' g, (s a.1).coeff x.1 • (t a.2).coeff x.2 := by refine sum_subset (fun gh hgh => ?_) fun gh hgh h => ?_ · simp_all only [mem_vaddAntidiagonal, Function.mem_support, Set.mem_iUnion, mem_support] exact ⟨Exists.intro a.1 hgh.1, Exists.intro a.2 hgh.2.1, trivial⟩ · by_cases hs : (s a.1).coeff gh.1 = 0 · exact smul_eq_zero_of_left hs ((t a.2).coeff gh.2) · simp_all theorem coeff_smul {R} {V} [Semiring R] [AddCommMonoid V] [Module R V] (s : SummableFamily Γ R α) (t : SummableFamily Γ' V β) (g : Γ') : (smul s t).hsum.coeff g = ∑ gh ∈ VAddAntidiagonal s.isPWO_iUnion_support t.isPWO_iUnion_support g, (s.hsum.coeff gh.1) • (t.hsum.coeff gh.2) := by rw [coeff_hsum] simp only [coeff_hsum_eq_sum, smul_toFun, HahnModule.coeff_smul, Equiv.symm_apply_apply] simp_rw [sum_vAddAntidiagonal_eq, Finset.smul_sum, Finset.sum_smul] rw [← sum_finsum_comm _ _ <| fun gh _ => smul_support_finite s t gh] refine sum_congr rfl fun gh _ => ?_ rw [finsum_eq_sum _ (smul_support_finite s t gh), ← sum_product_right'] refine sum_subset (fun ab hab => ?_) (fun ab _ hab => by simp_all) have hsupp := smul_support_subset_prod s t gh simp_all only [mem_vaddAntidiagonal, Set.mem_iUnion, mem_support, ne_eq, Set.Finite.mem_toFinset, Function.mem_support, Set.Finite.coe_toFinset, support_subset_iff, Set.mem_prod, Set.mem_setOf_eq, Prod.forall, coeff_support, mem_product] exact hsupp ab.1 ab.2 hab @[deprecated (since := "2024-11-17")] alias family_smul_coeff := coeff_smul theorem smul_hsum {R} {V} [Semiring R] [AddCommMonoid V] [Module R V] (s : SummableFamily Γ R α) (t : SummableFamily Γ' V β) : (smul s t).hsum = (of R).symm (s.hsum • (of R) (t.hsum)) := by ext g rw [coeff_smul s t g, HahnModule.coeff_smul, Equiv.symm_apply_apply] refine Eq.symm (sum_of_injOn (fun a ↦ a) (fun _ _ _ _ h ↦ h) (fun _ hgh => ?_) (fun gh _ hgh => ?_) fun _ _ => by simp) · simp_all only [mem_coe, mem_vaddAntidiagonal, mem_support, ne_eq, Set.mem_iUnion, and_true] constructor · rw [coeff_hsum_eq_sum] at hgh have h' := Finset.exists_ne_zero_of_sum_ne_zero hgh.1 simpa using h' · by_contra hi simp_all · simp only [Set.image_id', mem_coe, mem_vaddAntidiagonal, mem_support, ne_eq, not_and] at hgh by_cases h : s.hsum.coeff gh.1 = 0 · exact smul_eq_zero_of_left h (t.hsum.coeff gh.2) · simp_all @[deprecated (since := "2024-11-17")] alias hsum_family_smul := smul_hsum instance [AddCommMonoid R] [SMulWithZero R V] : SMul (HahnSeries Γ R) (SummableFamily Γ' V β) where smul x t := Equiv (Equiv.punitProd β) <| smul (single x) t theorem smul_eq {x : HahnSeries Γ R} {t : SummableFamily Γ' V β} : x • t = Equiv (Equiv.punitProd β) (smul (single x) t) := rfl @[simp] theorem smul_apply {x : HahnSeries Γ R} {s : SummableFamily Γ' V α} {a : α} : (x • s) a = (of R).symm (x • of R (s a)) := rfl @[simp] theorem hsum_smul_module {R} {V} [Semiring R] [AddCommMonoid V] [Module R V] {x : HahnSeries Γ R} {s : SummableFamily Γ' V α} : (x • s).hsum = (of R).symm (x • of R s.hsum) := by rw [smul_eq, hsum_equiv, smul_hsum, hsum_single] end SMul section Semiring variable [AddCommMonoid Γ] [PartialOrder Γ] [IsOrderedCancelAddMonoid Γ] [PartialOrder Γ'] [AddAction Γ Γ'] [IsOrderedCancelVAdd Γ Γ'] [Semiring R] instance [AddCommMonoid V] [Module R V] : Module (HahnSeries Γ R) (SummableFamily Γ' V α) where smul := (· • ·) smul_zero _ := ext fun _ => by simp zero_smul _ := ext fun _ => by simp one_smul _ := ext fun _ => by rw [smul_apply, HahnModule.one_smul', Equiv.symm_apply_apply] add_smul _ _ _ := ext fun _ => by simp [add_smul] smul_add _ _ _ := ext fun _ => by simp mul_smul _ _ _ := ext fun _ => by simp [HahnModule.instModule.mul_smul] theorem hsum_smul {x : HahnSeries Γ R} {s : SummableFamily Γ R α} : (x • s).hsum = x * s.hsum := by rw [hsum_smul_module, of_symm_smul_of_eq_mul] /-- The summation of a `summable_family` as a `LinearMap`. -/ @[simps] def lsum : SummableFamily Γ R α →ₗ[HahnSeries Γ R] HahnSeries Γ R where toFun := hsum map_add' _ _ := hsum_add map_smul' _ _ := hsum_smul @[simp] theorem hsum_sub {R : Type*} [Ring R] {s t : SummableFamily Γ R α} : (s - t).hsum = s.hsum - t.hsum := by rw [← lsum_apply, LinearMap.map_sub, lsum_apply, lsum_apply] theorem isPWO_iUnion_support_prod_mul {s : α → HahnSeries Γ R} {t : β → HahnSeries Γ R} (hs : (⋃ a, (s a).support).IsPWO) (ht : (⋃ b, (t b).support).IsPWO) : (⋃ (a : α × β), ((fun a ↦ ((s a.1) * (t a.2))) a).support).IsPWO := isPWO_iUnion_support_prod_smul hs ht theorem finite_co_support_prod_mul (s : SummableFamily Γ R α) (t : SummableFamily Γ R β) (g : Γ) : Finite {(a : α × β) | ((fun (a : α × β) ↦ (s a.1 * t a.2)) a).coeff g ≠ 0} := finite_co_support_prod_smul s t g /-- A summable family given by pointwise multiplication of a pair of summable families. -/ @[simps] def mul (s : SummableFamily Γ R α) (t : SummableFamily Γ R β) : (SummableFamily Γ R (α × β)) where toFun a := s (a.1) * t (a.2) isPWO_iUnion_support' := isPWO_iUnion_support_prod_mul s.isPWO_iUnion_support t.isPWO_iUnion_support finite_co_support' g := finite_co_support_prod_mul s t g theorem mul_eq_smul {β : Type*} (s : SummableFamily Γ R α) (t : SummableFamily Γ R β) : mul s t = smul s t := rfl theorem coeff_hsum_mul {β : Type*} (s : SummableFamily Γ R α) (t : SummableFamily Γ R β) (g : Γ) : (mul s t).hsum.coeff g = ∑ gh ∈ addAntidiagonal s.isPWO_iUnion_support t.isPWO_iUnion_support g, (s.hsum.coeff gh.1) * (t.hsum.coeff gh.2) := by simp_rw [← smul_eq_mul, mul_eq_smul] exact coeff_smul s t g @[deprecated (since := "2025-01-31")] alias mul_coeff := coeff_hsum_mul theorem hsum_mul {β : Type*} (s : SummableFamily Γ R α) (t : SummableFamily Γ R β) : (mul s t).hsum = s.hsum * t.hsum := by rw [← smul_eq_mul, mul_eq_smul] exact smul_hsum s t end Semiring section OfFinsupp variable [PartialOrder Γ] [AddCommMonoid R] {α : Type*} /-- A family with only finitely many nonzero elements is summable. -/ def ofFinsupp (f : α →₀ HahnSeries Γ R) : SummableFamily Γ R α where toFun := f isPWO_iUnion_support' := by apply (f.support.isPWO_bUnion.2 fun a _ => (f a).isPWO_support).mono refine Set.iUnion_subset_iff.2 fun a g hg => ?_ have haf : a ∈ f.support := by rw [Finsupp.mem_support_iff, ← support_nonempty_iff] exact ⟨g, hg⟩ exact Set.mem_biUnion haf hg finite_co_support' g := by refine f.support.finite_toSet.subset fun a ha => ?_
simp only [coeff.addMonoidHom_apply, mem_coe, Finsupp.mem_support_iff, Ne, Function.mem_support] contrapose! ha simp [ha]
Mathlib/RingTheory/HahnSeries/Summable.lean
518
521
/- Copyright (c) 2021 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots import Mathlib.NumberTheory.NumberField.Basic import Mathlib.FieldTheory.Galois.Basic /-! # Cyclotomic extensions Let `A` and `B` be commutative rings with `Algebra A B`. For `S : Set ℕ+`, we define a class `IsCyclotomicExtension S A B` expressing the fact that `B` is obtained from `A` by adding `n`-th primitive roots of unity, for all `n ∈ S`. ## Main definitions * `IsCyclotomicExtension S A B` : means that `B` is obtained from `A` by adding `n`-th primitive roots of unity, for all `n ∈ S`. * `CyclotomicField`: given `n : ℕ+` and a field `K`, we define `CyclotomicField n K` as the splitting field of `cyclotomic n K`. If `n` is nonzero in `K`, it has the instance `IsCyclotomicExtension {n} K (CyclotomicField n K)`. * `CyclotomicRing` : if `A` is a domain with fraction field `K` and `n : ℕ+`, we define `CyclotomicRing n A K` as the `A`-subalgebra of `CyclotomicField n K` generated by the roots of `X ^ n - 1`. If `n` is nonzero in `A`, it has the instance `IsCyclotomicExtension {n} A (CyclotomicRing n A K)`. ## Main results * `IsCyclotomicExtension.trans` : if `IsCyclotomicExtension S A B` and `IsCyclotomicExtension T B C`, then `IsCyclotomicExtension (S ∪ T) A C` if `Function.Injective (algebraMap B C)`. * `IsCyclotomicExtension.union_right` : given `IsCyclotomicExtension (S ∪ T) A B`, then `IsCyclotomicExtension T (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }) B`. * `IsCyclotomicExtension.union_left` : given `IsCyclotomicExtension T A B` and `S ⊆ T`, then `IsCyclotomicExtension S A (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 })`. * `IsCyclotomicExtension.finite` : if `S` is finite and `IsCyclotomicExtension S A B`, then `B` is a finite `A`-algebra. * `IsCyclotomicExtension.numberField` : a finite cyclotomic extension of a number field is a number field. * `IsCyclotomicExtension.isSplittingField_X_pow_sub_one` : if `IsCyclotomicExtension {n} K L`, then `L` is the splitting field of `X ^ n - 1`. * `IsCyclotomicExtension.splitting_field_cyclotomic` : if `IsCyclotomicExtension {n} K L`, then `L` is the splitting field of `cyclotomic n K`. ## Implementation details Our definition of `IsCyclotomicExtension` is very general, to allow rings of any characteristic and infinite extensions, but it will mainly be used in the case `S = {n}` and for integral domains. All results are in the `IsCyclotomicExtension` namespace. Note that some results, for example `IsCyclotomicExtension.trans`, `IsCyclotomicExtension.finite`, `IsCyclotomicExtension.numberField`, `IsCyclotomicExtension.finiteDimensional`, `IsCyclotomicExtension.isGalois` and `CyclotomicField.algebraBase` are lemmas, but they can be made local instances. Some of them are included in the `Cyclotomic` locale. -/ open Polynomial Algebra Module Set universe u v w z variable (n : ℕ+) (S T : Set ℕ+) (A : Type u) (B : Type v) (K : Type w) (L : Type z) variable [CommRing A] [CommRing B] [Algebra A B] variable [Field K] [Field L] [Algebra K L] noncomputable section /-- Given an `A`-algebra `B` and `S : Set ℕ+`, we define `IsCyclotomicExtension S A B` requiring that there is an `n`-th primitive root of unity in `B` for all `n ∈ S` and that `B` is generated over `A` by the roots of `X ^ n - 1`. -/ @[mk_iff] class IsCyclotomicExtension : Prop where /-- For all `n ∈ S`, there exists a primitive `n`-th root of unity in `B`. -/ exists_prim_root {n : ℕ+} (ha : n ∈ S) : ∃ r : B, IsPrimitiveRoot r n /-- The `n`-th roots of unity, for `n ∈ S`, generate `B` as an `A`-algebra. -/ adjoin_roots : ∀ x : B, x ∈ adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} namespace IsCyclotomicExtension section Basic /-- A reformulation of `IsCyclotomicExtension` that uses `⊤`. -/ theorem iff_adjoin_eq_top : IsCyclotomicExtension S A B ↔ (∀ n : ℕ+, n ∈ S → ∃ r : B, IsPrimitiveRoot r n) ∧ adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} = ⊤ := ⟨fun h => ⟨fun _ => h.exists_prim_root, Algebra.eq_top_iff.2 h.adjoin_roots⟩, fun h => ⟨h.1 _, Algebra.eq_top_iff.1 h.2⟩⟩ /-- A reformulation of `IsCyclotomicExtension` in the case `S` is a singleton. -/ theorem iff_singleton : IsCyclotomicExtension {n} A B ↔ (∃ r : B, IsPrimitiveRoot r n) ∧ ∀ x, x ∈ adjoin A {b : B | b ^ (n : ℕ) = 1} := by simp [isCyclotomicExtension_iff] /-- If `IsCyclotomicExtension ∅ A B`, then the image of `A` in `B` equals `B`. -/ theorem empty [h : IsCyclotomicExtension ∅ A B] : (⊥ : Subalgebra A B) = ⊤ := by simpa [Algebra.eq_top_iff, isCyclotomicExtension_iff] using h /-- If `IsCyclotomicExtension {1} A B`, then the image of `A` in `B` equals `B`. -/ theorem singleton_one [h : IsCyclotomicExtension {1} A B] : (⊥ : Subalgebra A B) = ⊤ := Algebra.eq_top_iff.2 fun x => by simpa [adjoin_singleton_one] using ((isCyclotomicExtension_iff _ _ _).1 h).2 x variable {A B} /-- If `(⊥ : SubAlgebra A B) = ⊤`, then `IsCyclotomicExtension ∅ A B`. -/ theorem singleton_zero_of_bot_eq_top (h : (⊥ : Subalgebra A B) = ⊤) : IsCyclotomicExtension ∅ A B := by refine (iff_adjoin_eq_top _ _ _).2 ⟨fun s hs => by simp at hs, _root_.eq_top_iff.2 fun x hx => ?_⟩ rw [← h] at hx simpa using hx variable (A B) /-- Transitivity of cyclotomic extensions. -/ theorem trans (C : Type w) [CommRing C] [Algebra A C] [Algebra B C] [IsScalarTower A B C] [hS : IsCyclotomicExtension S A B] [hT : IsCyclotomicExtension T B C] (h : Function.Injective (algebraMap B C)) : IsCyclotomicExtension (S ∪ T) A C := by refine ⟨fun hn => ?_, fun x => ?_⟩ · rcases hn with hn | hn · obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 hS).1 hn refine ⟨algebraMap B C b, ?_⟩ exact hb.map_of_injective h · exact ((isCyclotomicExtension_iff _ _ _).1 hT).1 hn · refine adjoin_induction (hx := ((isCyclotomicExtension_iff T B _).1 hT).2 x) (fun c ⟨n, hn⟩ => subset_adjoin ⟨n, Or.inr hn.1, hn.2⟩) (fun b => ?_) (fun x y _ _ hx hy => Subalgebra.add_mem _ hx hy) fun x y _ _ hx hy => Subalgebra.mul_mem _ hx hy let f := IsScalarTower.toAlgHom A B C have hb : f b ∈ (adjoin A {b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1}).map f := ⟨b, ((isCyclotomicExtension_iff _ _ _).1 hS).2 b, rfl⟩ rw [IsScalarTower.toAlgHom_apply, ← adjoin_image] at hb refine adjoin_mono (fun y hy => ?_) hb obtain ⟨b₁, ⟨⟨n, hn⟩, h₁⟩⟩ := hy exact ⟨n, ⟨mem_union_left T hn.1, by rw [← h₁, ← map_pow, hn.2, map_one]⟩⟩ @[nontriviality] theorem subsingleton_iff [Subsingleton B] : IsCyclotomicExtension S A B ↔ S = { } ∨ S = {1} := by have : Subsingleton (Subalgebra A B) := inferInstance constructor · rintro ⟨hprim, -⟩ rw [← subset_singleton_iff_eq] intro t ht obtain ⟨ζ, hζ⟩ := hprim ht rw [mem_singleton_iff, ← PNat.coe_eq_one_iff] exact mod_cast hζ.unique (IsPrimitiveRoot.of_subsingleton ζ) · rintro (rfl | rfl) · exact ⟨fun h => h.elim, fun x => by convert (mem_top : x ∈ ⊤)⟩ · rw [iff_singleton] exact ⟨⟨0, IsPrimitiveRoot.of_subsingleton 0⟩, fun x => by convert (mem_top (R := A) : x ∈ ⊤)⟩ /-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `S ∪ T`, then `B` is a cyclotomic extension of `adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }` given by roots of unity of order in `T`. -/ theorem union_right [h : IsCyclotomicExtension (S ∪ T) A B] : IsCyclotomicExtension T (adjoin A {b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1}) B := by have : {b : B | ∃ n : ℕ+, n ∈ S ∪ T ∧ b ^ (n : ℕ) = 1} = {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} ∪ {b : B | ∃ n : ℕ+, n ∈ T ∧ b ^ (n : ℕ) = 1} := by refine le_antisymm ?_ ?_ · rintro x ⟨n, hn₁ | hn₂, hnpow⟩ · left; exact ⟨n, hn₁, hnpow⟩ · right; exact ⟨n, hn₂, hnpow⟩ · rintro x (⟨n, hn⟩ | ⟨n, hn⟩) · exact ⟨n, Or.inl hn.1, hn.2⟩ · exact ⟨n, Or.inr hn.1, hn.2⟩ refine ⟨fun hn => ((isCyclotomicExtension_iff _ A _).1 h).1 (mem_union_right S hn), fun b => ?_⟩ replace h := ((isCyclotomicExtension_iff _ _ _).1 h).2 b rwa [this, adjoin_union_eq_adjoin_adjoin, Subalgebra.mem_restrictScalars] at h /-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `T` and `S ⊆ T`, then `adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }` is a cyclotomic extension of `B` given by roots of unity of order in `S`. -/ theorem union_left [h : IsCyclotomicExtension T A B] (hS : S ⊆ T) : IsCyclotomicExtension S A (adjoin A {b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1}) := by refine ⟨@fun n hn => ?_, fun b => ?_⟩ · obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 h).1 (hS hn) refine ⟨⟨b, subset_adjoin ⟨n, hn, hb.pow_eq_one⟩⟩, ?_⟩ rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk] · convert mem_top (R := A) (x := b) rw [← adjoin_adjoin_coe_preimage, preimage_setOf_eq] norm_cast variable {n S} /-- If `∀ s ∈ S, n ∣ s` and `S` is not empty, then `IsCyclotomicExtension S A B` implies `IsCyclotomicExtension (S ∪ {n}) A B`. -/ theorem of_union_of_dvd (h : ∀ s ∈ S, n ∣ s) (hS : S.Nonempty) [H : IsCyclotomicExtension S A B] : IsCyclotomicExtension (S ∪ {n}) A B := by refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ?_, ?_⟩ · rw [mem_union, mem_singleton_iff] at hs obtain hs | rfl := hs · exact H.exists_prim_root hs · obtain ⟨m, hm⟩ := hS obtain ⟨x, rfl⟩ := h m hm obtain ⟨ζ, hζ⟩ := H.exists_prim_root hm refine ⟨ζ ^ (x : ℕ), ?_⟩ convert hζ.pow_of_dvd x.ne_zero (dvd_mul_left (x : ℕ) s) simp only [PNat.mul_coe, Nat.mul_div_left, PNat.pos] · refine _root_.eq_top_iff.2 ?_ rw [← ((iff_adjoin_eq_top S A B).1 H).2] refine adjoin_mono fun x hx => ?_ simp only [union_singleton, mem_insert_iff, mem_setOf_eq] at hx ⊢ obtain ⟨m, hm⟩ := hx exact ⟨m, ⟨Or.inr hm.1, hm.2⟩⟩ /-- If `∀ s ∈ S, n ∣ s` and `S` is not empty, then `IsCyclotomicExtension S A B` if and only if `IsCyclotomicExtension (S ∪ {n}) A B`. -/ theorem iff_union_of_dvd (h : ∀ s ∈ S, n ∣ s) (hS : S.Nonempty) : IsCyclotomicExtension S A B ↔ IsCyclotomicExtension (S ∪ {n}) A B := by refine ⟨fun H => of_union_of_dvd A B h hS, fun H => (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ?_, ?_⟩⟩ · exact H.exists_prim_root (subset_union_left hs) · rw [_root_.eq_top_iff, ← ((iff_adjoin_eq_top _ A B).1 H).2] refine adjoin_mono fun x hx => ?_ simp only [union_singleton, mem_insert_iff, mem_setOf_eq] at hx ⊢ obtain ⟨m, rfl | hm, hxpow⟩ := hx · obtain ⟨y, hy⟩ := hS refine ⟨y, ⟨hy, ?_⟩⟩ obtain ⟨z, rfl⟩ := h y hy simp only [PNat.mul_coe, pow_mul, hxpow, one_pow] · exact ⟨m, ⟨hm, hxpow⟩⟩
variable (n S) /-- `IsCyclotomicExtension S A B` is equivalent to `IsCyclotomicExtension (S ∪ {1}) A B`. -/ theorem iff_union_singleton_one : IsCyclotomicExtension S A B ↔ IsCyclotomicExtension (S ∪ {1}) A B := by obtain hS | rfl := S.eq_empty_or_nonempty.symm · exact iff_union_of_dvd _ _ (fun s _ => one_dvd _) hS rw [empty_union] refine ⟨fun H => ?_, fun H => ?_⟩ · refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ⟨1, by simp [mem_singleton_iff.1 hs]⟩, ?_⟩ simp [adjoin_singleton_one, empty] · refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => (not_mem_empty s hs).elim, ?_⟩ simp [@singleton_one A B _ _ _ H]
Mathlib/NumberTheory/Cyclotomic/Basic.lean
231
244
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Order.Group.Finset import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Algebra.Polynomial.Eval.SMul import Mathlib.Algebra.Polynomial.Roots import Mathlib.RingTheory.EuclideanDomain import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors /-! # Theory of univariate polynomials This file starts looking like the ring theory of $R[X]$ -/ noncomputable section open Polynomial namespace Polynomial universe u v w y z variable {R : Type u} {S : Type v} {k : Type y} {A : Type z} {a b : R} {n : ℕ} section CommRing variable [CommRing R] theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero (p : R[X]) (t : R) (hnezero : derivative p ≠ 0) : p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t := (le_rootMultiplicity_iff hnezero).2 <| pow_sub_one_dvd_derivative_of_pow_dvd (p.pow_rootMultiplicity_dvd t) theorem derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors {p : R[X]} {t : R} (hpt : Polynomial.IsRoot p t) (hnzd : (p.rootMultiplicity t : R) ∈ nonZeroDivisors R) : (derivative p).rootMultiplicity t = p.rootMultiplicity t - 1 := by by_cases h : p = 0 · simp only [h, map_zero, rootMultiplicity_zero] obtain ⟨g, hp, hndvd⟩ := p.exists_eq_pow_rootMultiplicity_mul_and_not_dvd h t set m := p.rootMultiplicity t have hm : m - 1 + 1 = m := Nat.sub_add_cancel <| (rootMultiplicity_pos h).2 hpt have hndvd : ¬(X - C t) ^ m ∣ derivative p := by rw [hp, derivative_mul, dvd_add_left (dvd_mul_right _ _), derivative_X_sub_C_pow, ← hm, pow_succ, hm, mul_comm (C _), mul_assoc, dvd_cancel_left_mem_nonZeroDivisors (monic_X_sub_C t |>.pow _ |>.mem_nonZeroDivisors)] rw [dvd_iff_isRoot, IsRoot] at hndvd ⊢ rwa [eval_mul, eval_C, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd] have hnezero : derivative p ≠ 0 := fun h ↦ hndvd (by rw [h]; exact dvd_zero _) exact le_antisymm (by rwa [rootMultiplicity_le_iff hnezero, hm]) (rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero _ t hnezero) theorem isRoot_iterate_derivative_of_lt_rootMultiplicity {p : R[X]} {t : R} {n : ℕ} (hn : n < p.rootMultiplicity t) : (derivative^[n] p).IsRoot t := dvd_iff_isRoot.mp <| (dvd_pow_self _ <| Nat.sub_ne_zero_of_lt hn).trans (pow_sub_dvd_iterate_derivative_of_pow_dvd _ <| p.pow_rootMultiplicity_dvd t) open Finset in theorem eval_iterate_derivative_rootMultiplicity {p : R[X]} {t : R} : (derivative^[p.rootMultiplicity t] p).eval t = (p.rootMultiplicity t).factorial • (p /ₘ (X - C t) ^ p.rootMultiplicity t).eval t := by set m := p.rootMultiplicity t with hm conv_lhs => rw [← p.pow_mul_divByMonic_rootMultiplicity_eq t, ← hm] rw [iterate_derivative_mul, eval_finset_sum, sum_eq_single_of_mem _ (mem_range.mpr m.succ_pos)] · rw [m.choose_zero_right, one_smul, eval_mul, m.sub_zero, iterate_derivative_X_sub_pow_self, eval_natCast, nsmul_eq_mul]; rfl · intro b hb hb0 rw [iterate_derivative_X_sub_pow, eval_smul, eval_mul, eval_smul, eval_pow, Nat.sub_sub_self (mem_range_succ_iff.mp hb), eval_sub, eval_X, eval_C, sub_self, zero_pow hb0, smul_zero, zero_mul, smul_zero] theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) (hnzd : (n.factorial : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t := by by_contra! h' replace hroot := hroot _ h' simp only [IsRoot, eval_iterate_derivative_rootMultiplicity] at hroot obtain ⟨q, hq⟩ := Nat.cast_dvd_cast (α := R) <| Nat.factorial_dvd_factorial h' rw [hq, mul_mem_nonZeroDivisors] at hnzd rw [nsmul_eq_mul, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd.1] at hroot exact eval_divByMonic_pow_rootMultiplicity_ne_zero t h hroot theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) (hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t := by apply lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot clear hroot induction n with | zero => simp only [Nat.factorial_zero, Nat.cast_one] exact Submonoid.one_mem _ | succ n ih => rw [Nat.factorial_succ, Nat.cast_mul, mul_mem_nonZeroDivisors] exact ⟨hnzd _ le_rfl n.succ_ne_zero, ih fun m h ↦ hnzd m (h.trans n.le_succ)⟩ theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hnzd : (n.factorial : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t := ⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| hm.trans_lt hn, fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hr hnzd⟩ theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors' {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t := ⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn, fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' h hr hnzd⟩ theorem one_lt_rootMultiplicity_iff_isRoot_iterate_derivative {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ ∀ m ≤ 1, (derivative^[m] p).IsRoot t := lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors h (by rw [Nat.factorial_one, Nat.cast_one]; exact Submonoid.one_mem _) theorem one_lt_rootMultiplicity_iff_isRoot {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ p.IsRoot t ∧ (derivative p).IsRoot t := by rw [one_lt_rootMultiplicity_iff_isRoot_iterate_derivative h] refine ⟨fun h ↦ ⟨h 0 (by norm_num), h 1 (by norm_num)⟩, fun ⟨h0, h1⟩ m hm ↦ ?_⟩ obtain (_|_|m) := m exacts [h0, h1, by omega] end CommRing section IsDomain variable [CommRing R] [IsDomain R] theorem one_lt_rootMultiplicity_iff_isRoot_gcd [GCDMonoid R[X]] {p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ (gcd p (derivative p)).IsRoot t := by simp_rw [one_lt_rootMultiplicity_iff_isRoot h, ← dvd_iff_isRoot, dvd_gcd_iff] theorem derivative_rootMultiplicity_of_root [CharZero R] {p : R[X]} {t : R} (hpt : p.IsRoot t) : p.derivative.rootMultiplicity t = p.rootMultiplicity t - 1 := by by_cases h : p = 0
Mathlib/Algebra/Polynomial/FieldDivision.lean
143
148
/- Copyright (c) 2021 Benjamin Davidson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Benjamin Davidson, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Calculus.Deriv.Polynomial import Mathlib.Topology.Algebra.Polynomial /-! # Rolle's Theorem for polynomials In this file we use Rolle's Theorem to relate the number of real roots of a real polynomial and its derivative. Namely, we prove the following facts. * `Polynomial.card_roots_toFinset_le_card_roots_derivative_diff_roots_succ`: the number of roots of a real polynomial `p` is at most the number of roots of its derivative that are not roots of `p` plus one. * `Polynomial.card_roots_toFinset_le_derivative`, `Polynomial.card_rootSet_le_derivative`: the number of roots of a real polynomial is at most the number of roots of its derivative plus one. * `Polynomial.card_roots_le_derivative`: same, but the roots are counted with multiplicities. ## Keywords polynomial, Rolle's Theorem, root -/ namespace Polynomial /-- The number of roots of a real polynomial `p` is at most the number of roots of its derivative that are not roots of `p` plus one. -/ theorem card_roots_toFinset_le_card_roots_derivative_diff_roots_succ (p : ℝ[X]) : p.roots.toFinset.card ≤ (p.derivative.roots.toFinset \ p.roots.toFinset).card + 1 := by rcases eq_or_ne (derivative p) 0 with hp' | hp' · rw [eq_C_of_derivative_eq_zero hp', roots_C, Multiset.toFinset_zero, Finset.card_empty] exact zero_le _ have hp : p ≠ 0 := ne_of_apply_ne derivative (by rwa [derivative_zero]) refine Finset.card_le_diff_of_interleaved fun x hx y hy hxy hxy' => ?_ rw [Multiset.mem_toFinset, mem_roots hp] at hx hy obtain ⟨z, hz1, hz2⟩ := exists_deriv_eq_zero hxy p.continuousOn (hx.trans hy.symm) refine ⟨z, ?_, hz1⟩ rwa [Multiset.mem_toFinset, mem_roots hp', IsRoot, ← p.deriv] /-- The number of roots of a real polynomial is at most the number of roots of its derivative plus one. -/ theorem card_roots_toFinset_le_derivative (p : ℝ[X]) : p.roots.toFinset.card ≤ p.derivative.roots.toFinset.card + 1 := p.card_roots_toFinset_le_card_roots_derivative_diff_roots_succ.trans <| add_le_add_right (Finset.card_mono Finset.sdiff_subset) _ /-- The number of roots of a real polynomial (counted with multiplicities) is at most the number of roots of its derivative (counted with multiplicities) plus one. -/ theorem card_roots_le_derivative (p : ℝ[X]) : Multiset.card p.roots ≤ Multiset.card (derivative p).roots + 1 := calc Multiset.card p.roots = ∑ x ∈ p.roots.toFinset, p.roots.count x := (Multiset.toFinset_sum_count_eq _).symm
_ = ∑ x ∈ p.roots.toFinset, (p.roots.count x - 1 + 1) := (Eq.symm <| Finset.sum_congr rfl fun _ hx => tsub_add_cancel_of_le <| Nat.succ_le_iff.2 <| Multiset.count_pos.2 <| Multiset.mem_toFinset.1 hx) _ = (∑ x ∈ p.roots.toFinset, (p.rootMultiplicity x - 1)) + p.roots.toFinset.card := by simp only [Finset.sum_add_distrib, Finset.card_eq_sum_ones, count_roots] _ ≤ (∑ x ∈ p.roots.toFinset, p.derivative.rootMultiplicity x) + ((p.derivative.roots.toFinset \ p.roots.toFinset).card + 1) := (add_le_add (Finset.sum_le_sum fun _ _ => rootMultiplicity_sub_one_le_derivative_rootMultiplicity _ _) p.card_roots_toFinset_le_card_roots_derivative_diff_roots_succ) _ ≤ (∑ x ∈ p.roots.toFinset, p.derivative.roots.count x) + ((∑ x ∈ p.derivative.roots.toFinset \ p.roots.toFinset, p.derivative.roots.count x) + 1) := by simp only [← count_roots] refine add_le_add_left (add_le_add_right ((Finset.card_eq_sum_ones _).trans_le ?_) _) _ refine Finset.sum_le_sum fun x hx => Nat.succ_le_iff.2 <| ?_ rw [Multiset.count_pos, ← Multiset.mem_toFinset] exact (Finset.mem_sdiff.1 hx).1 _ = Multiset.card (derivative p).roots + 1 := by rw [← add_assoc, ← Finset.sum_union Finset.disjoint_sdiff, Finset.union_sdiff_self_eq_union, ← Multiset.toFinset_sum_count_eq, ← Finset.sum_subset Finset.subset_union_right] intro x _ hx₂ simpa only [Multiset.mem_toFinset, Multiset.count_eq_zero] using hx₂ /-- The number of real roots of a polynomial is at most the number of roots of its derivative plus one. -/ theorem card_rootSet_le_derivative {F : Type*} [CommRing F] [Algebra F ℝ] (p : F[X]) : Fintype.card (p.rootSet ℝ) ≤ Fintype.card (p.derivative.rootSet ℝ) + 1 := by
Mathlib/Analysis/Calculus/LocalExtr/Polynomial.lean
60
87
/- Copyright (c) 2020 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Computation.Basic import Mathlib.Algebra.ContinuedFractions.Translations import Mathlib.Algebra.Order.Floor.Ring /-! # Basic Translation Lemmas Between Structures Defined for Computing Continued Fractions ## Summary This is a collection of simple lemmas between the different structures used for the computation of continued fractions defined in `Mathlib.Algebra.ContinuedFractions.Computation.Basic`. The file consists of three sections: 1. Recurrences and inversion lemmas for `IntFractPair.stream`: these lemmas give us inversion rules and recurrences for the computation of the stream of integer and fractional parts of a value. 2. Translation lemmas for the head term: these lemmas show us that the head term of the computed continued fraction of a value `v` is `⌊v⌋` and how this head term is moved along the structures used in the computation process. 3. Translation lemmas for the sequence: these lemmas show how the sequences of the involved structures (`IntFractPair.stream`, `IntFractPair.seq1`, and `GenContFract.of`) are connected, i.e. how the values are moved along the structures and the termination of one sequence implies the termination of another sequence. ## Main Theorems - `succ_nth_stream_eq_some_iff` gives as a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of non-termination. - `succ_nth_stream_eq_none_iff` gives as a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of termination. - `get?_of_eq_some_of_succ_get?_intFractPair_stream` and `get?_of_eq_some_of_get?_intFractPair_stream_fr_ne_zero` show how the entries of the sequence of the computed continued fraction can be obtained from the stream of integer and fractional parts. -/ assert_not_exists Finset namespace GenContFract open GenContFract (of) -- Fix a discrete linear ordered division ring with `floor` function and a value `v`. variable {K : Type*} [DivisionRing K] [LinearOrder K] [FloorRing K] {v : K} namespace IntFractPair /-! ### Recurrences and Inversion Lemmas for `IntFractPair.stream` Here we state some lemmas that give us inversion rules and recurrences for the computation of the stream of integer and fractional parts of a value. -/ theorem stream_zero (v : K) : IntFractPair.stream v 0 = some (IntFractPair.of v) := rfl variable {n : ℕ} theorem stream_eq_none_of_fr_eq_zero {ifp_n : IntFractPair K} (stream_nth_eq : IntFractPair.stream v n = some ifp_n) (nth_fr_eq_zero : ifp_n.fr = 0) : IntFractPair.stream v (n + 1) = none := by obtain ⟨_, fr⟩ := ifp_n change fr = 0 at nth_fr_eq_zero simp [IntFractPair.stream, stream_nth_eq, nth_fr_eq_zero] /-- Gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of termination. -/ theorem succ_nth_stream_eq_none_iff : IntFractPair.stream v (n + 1) = none ↔ IntFractPair.stream v n = none ∨ ∃ ifp, IntFractPair.stream v n = some ifp ∧ ifp.fr = 0 := by rw [IntFractPair.stream] cases IntFractPair.stream v n <;> simp [imp_false] /-- Gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of non-termination. -/ theorem succ_nth_stream_eq_some_iff {ifp_succ_n : IntFractPair K} : IntFractPair.stream v (n + 1) = some ifp_succ_n ↔ ∃ ifp_n : IntFractPair K, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n := by simp [IntFractPair.stream, ite_eq_iff, Option.bind_eq_some_iff] /-- An easier to use version of one direction of `GenContFract.IntFractPair.succ_nth_stream_eq_some_iff`. -/ theorem stream_succ_of_some {p : IntFractPair K} (h : IntFractPair.stream v n = some p) (h' : p.fr ≠ 0) : IntFractPair.stream v (n + 1) = some (IntFractPair.of p.fr⁻¹) := succ_nth_stream_eq_some_iff.mpr ⟨p, h, h', rfl⟩ /-- The stream of `IntFractPair`s of an integer stops after the first term. -/ theorem stream_succ_of_int [IsStrictOrderedRing K] (a : ℤ) (n : ℕ) : IntFractPair.stream (a : K) (n + 1) = none := by induction n with | zero => refine IntFractPair.stream_eq_none_of_fr_eq_zero (IntFractPair.stream_zero (a : K)) ?_ simp only [IntFractPair.of, Int.fract_intCast] | succ n ih => exact IntFractPair.succ_nth_stream_eq_none_iff.mpr (Or.inl ih) theorem exists_succ_nth_stream_of_fr_zero {ifp_succ_n : IntFractPair K} (stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) (succ_nth_fr_eq_zero : ifp_succ_n.fr = 0) : ∃ ifp_n : IntFractPair K, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr⁻¹ = ⌊ifp_n.fr⁻¹⌋ := by -- get the witness from `succ_nth_stream_eq_some_iff` and prove that it has the additional -- properties rcases succ_nth_stream_eq_some_iff.mp stream_succ_nth_eq with ⟨ifp_n, seq_nth_eq, _, rfl⟩ refine ⟨ifp_n, seq_nth_eq, ?_⟩ simpa only [IntFractPair.of, Int.fract, sub_eq_zero] using succ_nth_fr_eq_zero /-- A recurrence relation that expresses the `(n+1)`th term of the stream of `IntFractPair`s of `v` for non-integer `v` in terms of the `n`th term of the stream associated to the inverse of the fractional part of `v`. -/ theorem stream_succ (h : Int.fract v ≠ 0) (n : ℕ) : IntFractPair.stream v (n + 1) = IntFractPair.stream (Int.fract v)⁻¹ n := by induction n with | zero => have H : (IntFractPair.of v).fr = Int.fract v := by simp [IntFractPair.of] rw [stream_zero, stream_succ_of_some (stream_zero v) (ne_of_eq_of_ne H h), H] | succ n ih => rcases eq_or_ne (IntFractPair.stream (Int.fract v)⁻¹ n) none with hnone | hsome · rw [hnone] at ih rw [succ_nth_stream_eq_none_iff.mpr (Or.inl hnone), succ_nth_stream_eq_none_iff.mpr (Or.inl ih)] · obtain ⟨p, hp⟩ := Option.ne_none_iff_exists'.mp hsome rw [hp] at ih rcases eq_or_ne p.fr 0 with hz | hnz · rw [stream_eq_none_of_fr_eq_zero hp hz, stream_eq_none_of_fr_eq_zero ih hz] · rw [stream_succ_of_some hp hnz, stream_succ_of_some ih hnz] end IntFractPair section Head /-! ### Translation of the Head Term Here we state some lemmas that show us that the head term of the computed continued fraction of a value `v` is `⌊v⌋` and how this head term is moved along the structures used in the computation process. -/ /-- The head term of the sequence with head of `v` is just the integer part of `v`. -/ @[simp] theorem IntFractPair.seq1_fst_eq_of : (IntFractPair.seq1 v).fst = IntFractPair.of v := rfl theorem of_h_eq_intFractPair_seq1_fst_b : (of v).h = (IntFractPair.seq1 v).fst.b := by cases aux_seq_eq : IntFractPair.seq1 v simp [of, aux_seq_eq] /-- The head term of the gcf of `v` is `⌊v⌋`. -/ @[simp]
theorem of_h_eq_floor : (of v).h = ⌊v⌋ := by simp [of_h_eq_intFractPair_seq1_fst_b, IntFractPair.of]
Mathlib/Algebra/ContinuedFractions/Computation/Translations.lean
163
165
/- 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, Peter Nelson -/ import Mathlib.Order.Antichain /-! # Minimality and Maximality This file proves basic facts about minimality and maximality of an element with respect to a predicate `P` on an ordered type `α`. ## Implementation Details This file underwent a refactor from a version where minimality and maximality were defined using sets rather than predicates, and with an unbundled order relation rather than a `LE` instance. A side effect is that it has become less straightforward to state that something is minimal with respect to a relation that is *not* defeq to the default `LE`. One possible way would be with a type synonym, and another would be with an ad hoc `LE` instance and `@` notation. This was not an issue in practice anywhere in mathlib at the time of the refactor, but it may be worth re-examining this to make it easier in the future; see the TODO below. ## TODO * In the linearly ordered case, versions of lemmas like `minimal_mem_image` will hold with `MonotoneOn`/`AntitoneOn` assumptions rather than the stronger `x ≤ y ↔ f x ≤ f y` assumptions. * `Set.maximal_iff_forall_insert` and `Set.minimal_iff_forall_diff_singleton` will generalize to lemmas about covering in the case of an `IsStronglyAtomic`/`IsStronglyCoatomic` order. * `Finset` versions of the lemmas about sets. * API to allow for easily expressing min/maximality with respect to an arbitrary non-`LE` relation. * API for `MinimalFor`/`MaximalFor` -/ assert_not_exists CompleteLattice open Set OrderDual variable {α : Type*} {P Q : α → Prop} {a x y : α} section LE variable [LE α] @[simp] theorem minimal_toDual : Minimal (fun x ↦ P (ofDual x)) (toDual x) ↔ Maximal P x := Iff.rfl alias ⟨Minimal.of_dual, Minimal.dual⟩ := minimal_toDual @[simp] theorem maximal_toDual : Maximal (fun x ↦ P (ofDual x)) (toDual x) ↔ Minimal P x := Iff.rfl alias ⟨Maximal.of_dual, Maximal.dual⟩ := maximal_toDual @[simp] theorem minimal_false : ¬ Minimal (fun _ ↦ False) x := by simp [Minimal] @[simp] theorem maximal_false : ¬ Maximal (fun _ ↦ False) x := by simp [Maximal] @[simp] theorem minimal_true : Minimal (fun _ ↦ True) x ↔ IsMin x := by simp [IsMin, Minimal] @[simp] theorem maximal_true : Maximal (fun _ ↦ True) x ↔ IsMax x := minimal_true (α := αᵒᵈ) @[simp] theorem minimal_subtype {x : Subtype Q} : Minimal (fun x ↦ P x.1) x ↔ Minimal (P ⊓ Q) x := by obtain ⟨x, hx⟩ := x simp only [Minimal, Subtype.forall, Subtype.mk_le_mk, Pi.inf_apply, inf_Prop_eq] tauto @[simp] theorem maximal_subtype {x : Subtype Q} : Maximal (fun x ↦ P x.1) x ↔ Maximal (P ⊓ Q) x := minimal_subtype (α := αᵒᵈ) theorem maximal_true_subtype {x : Subtype P} : Maximal (fun _ ↦ True) x ↔ Maximal P x := by obtain ⟨x, hx⟩ := x simp [Maximal, hx] theorem minimal_true_subtype {x : Subtype P} : Minimal (fun _ ↦ True) x ↔ Minimal P x := by obtain ⟨x, hx⟩ := x simp [Minimal, hx] @[simp] theorem minimal_minimal : Minimal (Minimal P) x ↔ Minimal P x := ⟨fun h ↦ h.prop, fun h ↦ ⟨h, fun _ hy hyx ↦ h.le_of_le hy.prop hyx⟩⟩ @[simp] theorem maximal_maximal : Maximal (Maximal P) x ↔ Maximal P x := minimal_minimal (α := αᵒᵈ) /-- If `P` is down-closed, then minimal elements satisfying `P` are exactly the globally minimal elements satisfying `P`. -/ theorem minimal_iff_isMin (hP : ∀ ⦃x y⦄, P y → x ≤ y → P x) : Minimal P x ↔ P x ∧ IsMin x := ⟨fun h ↦ ⟨h.prop, fun _ h' ↦ h.le_of_le (hP h.prop h') h'⟩, fun h ↦ ⟨h.1, fun _ _ h' ↦ h.2 h'⟩⟩ /-- If `P` is up-closed, then maximal elements satisfying `P` are exactly the globally maximal elements satisfying `P`. -/ theorem maximal_iff_isMax (hP : ∀ ⦃x y⦄, P y → y ≤ x → P x) : Maximal P x ↔ P x ∧ IsMax x := ⟨fun h ↦ ⟨h.prop, fun _ h' ↦ h.le_of_ge (hP h.prop h') h'⟩, fun h ↦ ⟨h.1, fun _ _ h' ↦ h.2 h'⟩⟩ theorem Minimal.mono (h : Minimal P x) (hle : Q ≤ P) (hQ : Q x) : Minimal Q x := ⟨hQ, fun y hQy ↦ h.le_of_le (hle y hQy)⟩ theorem Maximal.mono (h : Maximal P x) (hle : Q ≤ P) (hQ : Q x) : Maximal Q x := ⟨hQ, fun y hQy ↦ h.le_of_ge (hle y hQy)⟩ theorem Minimal.and_right (h : Minimal P x) (hQ : Q x) : Minimal (fun x ↦ P x ∧ Q x) x := h.mono (fun _ ↦ And.left) ⟨h.prop, hQ⟩ theorem Minimal.and_left (h : Minimal P x) (hQ : Q x) : Minimal (fun x ↦ (Q x ∧ P x)) x := h.mono (fun _ ↦ And.right) ⟨hQ, h.prop⟩ theorem Maximal.and_right (h : Maximal P x) (hQ : Q x) : Maximal (fun x ↦ (P x ∧ Q x)) x := h.mono (fun _ ↦ And.left) ⟨h.prop, hQ⟩ theorem Maximal.and_left (h : Maximal P x) (hQ : Q x) : Maximal (fun x ↦ (Q x ∧ P x)) x := h.mono (fun _ ↦ And.right) ⟨hQ, h.prop⟩ @[simp] theorem minimal_eq_iff : Minimal (· = y) x ↔ x = y := by simp +contextual [Minimal] @[simp] theorem maximal_eq_iff : Maximal (· = y) x ↔ x = y := by simp +contextual [Maximal] theorem not_minimal_iff (hx : P x) : ¬ Minimal P x ↔ ∃ y, P y ∧ y ≤ x ∧ ¬ (x ≤ y) := by simp [Minimal, hx] theorem not_maximal_iff (hx : P x) : ¬ Maximal P x ↔ ∃ y, P y ∧ x ≤ y ∧ ¬ (y ≤ x) := not_minimal_iff (α := αᵒᵈ) hx theorem Minimal.or (h : Minimal (fun x ↦ P x ∨ Q x) x) : Minimal P x ∨ Minimal Q x := by obtain ⟨h | h, hmin⟩ := h · exact .inl ⟨h, fun y hy hyx ↦ hmin (Or.inl hy) hyx⟩ exact .inr ⟨h, fun y hy hyx ↦ hmin (Or.inr hy) hyx⟩ theorem Maximal.or (h : Maximal (fun x ↦ P x ∨ Q x) x) : Maximal P x ∨ Maximal Q x := Minimal.or (α := αᵒᵈ) h theorem minimal_and_iff_right_of_imp (hPQ : ∀ ⦃x⦄, P x → Q x) : Minimal (fun x ↦ P x ∧ Q x) x ↔ (Minimal P x) ∧ Q x := by simp_rw [and_iff_left_of_imp (fun x ↦ hPQ x), iff_self_and] exact fun h ↦ hPQ h.prop theorem minimal_and_iff_left_of_imp (hPQ : ∀ ⦃x⦄, P x → Q x) : Minimal (fun x ↦ Q x ∧ P x) x ↔ Q x ∧ (Minimal P x) := by simp_rw [iff_comm, and_comm, minimal_and_iff_right_of_imp hPQ, and_comm] theorem maximal_and_iff_right_of_imp (hPQ : ∀ ⦃x⦄, P x → Q x) : Maximal (fun x ↦ P x ∧ Q x) x ↔ (Maximal P x) ∧ Q x := minimal_and_iff_right_of_imp (α := αᵒᵈ) hPQ theorem maximal_and_iff_left_of_imp (hPQ : ∀ ⦃x⦄, P x → Q x) : Maximal (fun x ↦ Q x ∧ P x) x ↔ Q x ∧ (Maximal P x) := minimal_and_iff_left_of_imp (α := αᵒᵈ) hPQ end LE section Preorder variable [Preorder α] theorem minimal_iff_forall_lt : Minimal P x ↔ P x ∧ ∀ ⦃y⦄, y < x → ¬ P y := by simp [Minimal, lt_iff_le_not_le, not_imp_not, imp.swap] theorem maximal_iff_forall_gt : Maximal P x ↔ P x ∧ ∀ ⦃y⦄, x < y → ¬ P y := minimal_iff_forall_lt (α := αᵒᵈ) theorem Minimal.not_prop_of_lt (h : Minimal P x) (hlt : y < x) : ¬ P y := (minimal_iff_forall_lt.1 h).2 hlt theorem Maximal.not_prop_of_gt (h : Maximal P x) (hlt : x < y) : ¬ P y := (maximal_iff_forall_gt.1 h).2 hlt theorem Minimal.not_lt (h : Minimal P x) (hy : P y) : ¬ (y < x) := fun hlt ↦ h.not_prop_of_lt hlt hy theorem Maximal.not_gt (h : Maximal P x) (hy : P y) : ¬ (x < y) := fun hlt ↦ h.not_prop_of_gt hlt hy @[simp] theorem minimal_le_iff : Minimal (· ≤ y) x ↔ x ≤ y ∧ IsMin x := minimal_iff_isMin (fun _ _ h h' ↦ h'.trans h) @[simp] theorem maximal_ge_iff : Maximal (y ≤ ·) x ↔ y ≤ x ∧ IsMax x := minimal_le_iff (α := αᵒᵈ) @[simp] theorem minimal_lt_iff : Minimal (· < y) x ↔ x < y ∧ IsMin x := minimal_iff_isMin (fun _ _ h h' ↦ h'.trans_lt h) @[simp] theorem maximal_gt_iff : Maximal (y < ·) x ↔ y < x ∧ IsMax x := minimal_lt_iff (α := αᵒᵈ) theorem not_minimal_iff_exists_lt (hx : P x) : ¬ Minimal P x ↔ ∃ y, y < x ∧ P y := by simp_rw [not_minimal_iff hx, lt_iff_le_not_le, and_comm] alias ⟨exists_lt_of_not_minimal, _⟩ := not_minimal_iff_exists_lt theorem not_maximal_iff_exists_gt (hx : P x) : ¬ Maximal P x ↔ ∃ y, x < y ∧ P y := not_minimal_iff_exists_lt (α := αᵒᵈ) hx alias ⟨exists_gt_of_not_maximal, _⟩ := not_maximal_iff_exists_gt end Preorder section PartialOrder variable [PartialOrder α] theorem Minimal.eq_of_ge (hx : Minimal P x) (hy : P y) (hge : y ≤ x) : x = y := (hx.2 hy hge).antisymm hge theorem Minimal.eq_of_le (hx : Minimal P x) (hy : P y) (hle : y ≤ x) : y = x := (hx.eq_of_ge hy hle).symm theorem Maximal.eq_of_le (hx : Maximal P x) (hy : P y) (hle : x ≤ y) : x = y := hle.antisymm <| hx.2 hy hle theorem Maximal.eq_of_ge (hx : Maximal P x) (hy : P y) (hge : x ≤ y) : y = x := (hx.eq_of_le hy hge).symm theorem minimal_iff : Minimal P x ↔ P x ∧ ∀ ⦃y⦄, P y → y ≤ x → x = y := ⟨fun h ↦ ⟨h.1, fun _ ↦ h.eq_of_ge⟩, fun h ↦ ⟨h.1, fun _ hy hle ↦ (h.2 hy hle).le⟩⟩ theorem maximal_iff : Maximal P x ↔ P x ∧ ∀ ⦃y⦄, P y → x ≤ y → x = y := minimal_iff (α := αᵒᵈ) theorem minimal_mem_iff {s : Set α} : Minimal (· ∈ s) x ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → y ≤ x → x = y := minimal_iff theorem maximal_mem_iff {s : Set α} : Maximal (· ∈ s) x ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → x ≤ y → x = y := maximal_iff /-- If `P y` holds, and everything satisfying `P` is above `y`, then `y` is the unique minimal element satisfying `P`. -/ theorem minimal_iff_eq (hy : P y) (hP : ∀ ⦃x⦄, P x → y ≤ x) : Minimal P x ↔ x = y := ⟨fun h ↦ h.eq_of_ge hy (hP h.prop), by rintro rfl; exact ⟨hy, fun z hz _ ↦ hP hz⟩⟩ /-- If `P y` holds, and everything satisfying `P` is below `y`, then `y` is the unique maximal element satisfying `P`. -/ theorem maximal_iff_eq (hy : P y) (hP : ∀ ⦃x⦄, P x → x ≤ y) : Maximal P x ↔ x = y := minimal_iff_eq (α := αᵒᵈ) hy hP @[simp] theorem minimal_ge_iff : Minimal (y ≤ ·) x ↔ x = y := minimal_iff_eq rfl.le fun _ ↦ id @[simp] theorem maximal_le_iff : Maximal (· ≤ y) x ↔ x = y := maximal_iff_eq rfl.le fun _ ↦ id theorem minimal_iff_minimal_of_imp_of_forall (hPQ : ∀ ⦃x⦄, Q x → P x) (h : ∀ ⦃x⦄, P x → ∃ y, y ≤ x ∧ Q y) : Minimal P x ↔ Minimal Q x := by refine ⟨fun h' ↦ ⟨?_, fun y hy hyx ↦ h'.le_of_le (hPQ hy) hyx⟩, fun h' ↦ ⟨hPQ h'.prop, fun y hy hyx ↦ ?_⟩⟩ · obtain ⟨y, hyx, hy⟩ := h h'.prop rwa [((h'.le_of_le (hPQ hy)) hyx).antisymm hyx] obtain ⟨z, hzy, hz⟩ := h hy exact (h'.le_of_le hz (hzy.trans hyx)).trans hzy theorem maximal_iff_maximal_of_imp_of_forall (hPQ : ∀ ⦃x⦄, Q x → P x) (h : ∀ ⦃x⦄, P x → ∃ y, x ≤ y ∧ Q y) : Maximal P x ↔ Maximal Q x := minimal_iff_minimal_of_imp_of_forall (α := αᵒᵈ) hPQ h end PartialOrder section Subset variable {P : Set α → Prop} {s t : Set α} theorem Minimal.eq_of_superset (h : Minimal P s) (ht : P t) (hts : t ⊆ s) : s = t := h.eq_of_ge ht hts theorem Maximal.eq_of_subset (h : Maximal P s) (ht : P t) (hst : s ⊆ t) : s = t := h.eq_of_le ht hst theorem Minimal.eq_of_subset (h : Minimal P s) (ht : P t) (hts : t ⊆ s) : t = s := h.eq_of_le ht hts theorem Maximal.eq_of_superset (h : Maximal P s) (ht : P t) (hst : s ⊆ t) : t = s := h.eq_of_ge ht hst theorem minimal_subset_iff : Minimal P s ↔ P s ∧ ∀ ⦃t⦄, P t → t ⊆ s → s = t := _root_.minimal_iff theorem maximal_subset_iff : Maximal P s ↔ P s ∧ ∀ ⦃t⦄, P t → s ⊆ t → s = t := _root_.maximal_iff theorem minimal_subset_iff' : Minimal P s ↔ P s ∧ ∀ ⦃t⦄, P t → t ⊆ s → s ⊆ t := Iff.rfl theorem maximal_subset_iff' : Maximal P s ↔ P s ∧ ∀ ⦃t⦄, P t → s ⊆ t → t ⊆ s := Iff.rfl theorem not_minimal_subset_iff (hs : P s) : ¬ Minimal P s ↔ ∃ t, t ⊂ s ∧ P t := not_minimal_iff_exists_lt hs theorem not_maximal_subset_iff (hs : P s) : ¬ Maximal P s ↔ ∃ t, s ⊂ t ∧ P t := not_maximal_iff_exists_gt hs theorem Set.minimal_iff_forall_ssubset : Minimal P s ↔ P s ∧ ∀ ⦃t⦄, t ⊂ s → ¬ P t := minimal_iff_forall_lt theorem Minimal.not_prop_of_ssubset (h : Minimal P s) (ht : t ⊂ s) : ¬ P t := (minimal_iff_forall_lt.1 h).2 ht theorem Minimal.not_ssubset (h : Minimal P s) (ht : P t) : ¬ t ⊂ s := h.not_lt ht theorem Maximal.mem_of_prop_insert (h : Maximal P s) (hx : P (insert x s)) : x ∈ s := h.eq_of_subset hx (subset_insert _ _) ▸ mem_insert .. theorem Minimal.not_mem_of_prop_diff_singleton (h : Minimal P s) (hx : P (s \ {x})) : x ∉ s := fun hxs ↦ ((h.eq_of_superset hx diff_subset).subset hxs).2 rfl theorem Set.minimal_iff_forall_diff_singleton (hP : ∀ ⦃s t⦄, P t → t ⊆ s → P s) : Minimal P s ↔ P s ∧ ∀ x ∈ s, ¬ P (s \ {x}) := ⟨fun h ↦ ⟨h.1, fun _ hx hP ↦ h.not_mem_of_prop_diff_singleton hP hx⟩, fun h ↦ ⟨h.1, fun _ ht hts x hxs ↦ by_contra fun hxt ↦ h.2 x hxs (hP ht <| subset_diff_singleton hts hxt)⟩⟩ theorem Set.exists_diff_singleton_of_not_minimal (hP : ∀ ⦃s t⦄, P t → t ⊆ s → P s) (hs : P s) (h : ¬ Minimal P s) : ∃ x ∈ s, P (s \ {x}) := by simpa [Set.minimal_iff_forall_diff_singleton hP, hs] using h theorem Set.maximal_iff_forall_ssuperset : Maximal P s ↔ P s ∧ ∀ ⦃t⦄, s ⊂ t → ¬ P t := maximal_iff_forall_gt theorem Maximal.not_prop_of_ssuperset (h : Maximal P s) (ht : s ⊂ t) : ¬ P t := (maximal_iff_forall_gt.1 h).2 ht theorem Maximal.not_ssuperset (h : Maximal P s) (ht : P t) : ¬ s ⊂ t := h.not_gt ht theorem Set.maximal_iff_forall_insert (hP : ∀ ⦃s t⦄, P t → s ⊆ t → P s) : Maximal P s ↔ P s ∧ ∀ x ∉ s, ¬ P (insert x s) := by simp only [not_imp_not] exact ⟨fun h ↦ ⟨h.1, fun x ↦ h.mem_of_prop_insert⟩, fun h ↦ ⟨h.1, fun t ht hst x hxt ↦ h.2 x (hP ht <| insert_subset hxt hst)⟩⟩ theorem Set.exists_insert_of_not_maximal (hP : ∀ ⦃s t⦄, P t → s ⊆ t → P s) (hs : P s) (h : ¬ Maximal P s) : ∃ x ∉ s, P (insert x s) := by simpa [Set.maximal_iff_forall_insert hP, hs] using h /- TODO : generalize `minimal_iff_forall_diff_singleton` and `maximal_iff_forall_insert` to `IsStronglyCoatomic`/`IsStronglyAtomic` orders. -/ end Subset section Set variable {s t : Set α} section Preorder variable [Preorder α] theorem setOf_minimal_subset (s : Set α) : {x | Minimal (· ∈ s) x} ⊆ s := sep_subset .. theorem setOf_maximal_subset (s : Set α) : {x | Maximal (· ∈ s) x} ⊆ s := sep_subset .. theorem Set.Subsingleton.maximal_mem_iff (h : s.Subsingleton) : Maximal (· ∈ s) x ↔ x ∈ s := by obtain (rfl | ⟨x, rfl⟩) := h.eq_empty_or_singleton <;> simp theorem Set.Subsingleton.minimal_mem_iff (h : s.Subsingleton) : Minimal (· ∈ s) x ↔ x ∈ s := by obtain (rfl | ⟨x, rfl⟩) := h.eq_empty_or_singleton <;> simp theorem IsLeast.minimal (h : IsLeast s x) : Minimal (· ∈ s) x := ⟨h.1, fun _b hb _ ↦ h.2 hb⟩ theorem IsGreatest.maximal (h : IsGreatest s x) : Maximal (· ∈ s) x := ⟨h.1, fun _b hb _ ↦ h.2 hb⟩ theorem IsAntichain.minimal_mem_iff (hs : IsAntichain (· ≤ ·) s) : Minimal (· ∈ s) x ↔ x ∈ s := ⟨fun h ↦ h.prop, fun h ↦ ⟨h, fun _ hys hyx ↦ (hs.eq hys h hyx).symm.le⟩⟩ theorem IsAntichain.maximal_mem_iff (hs : IsAntichain (· ≤ ·) s) : Maximal (· ∈ s) x ↔ x ∈ s := hs.to_dual.minimal_mem_iff /-- If `t` is an antichain shadowing and including the set of maximal elements of `s`, then `t` *is* the set of maximal elements of `s`. -/ theorem IsAntichain.eq_setOf_maximal (ht : IsAntichain (· ≤ ·) t) (h : ∀ x, Maximal (· ∈ s) x → x ∈ t) (hs : ∀ a ∈ t, ∃ b, b ≤ a ∧ Maximal (· ∈ s) b) : {x | Maximal (· ∈ s) x} = t := by refine Set.ext fun x ↦ ⟨h _, fun hx ↦ ?_⟩ obtain ⟨y, hyx, hy⟩ := hs x hx rwa [← ht.eq (h y hy) hx hyx] /-- If `t` is an antichain shadowed by and including the set of minimal elements of `s`, then `t` *is* the set of minimal elements of `s`. -/ theorem IsAntichain.eq_setOf_minimal (ht : IsAntichain (· ≤ ·) t) (h : ∀ x, Minimal (· ∈ s) x → x ∈ t) (hs : ∀ a ∈ t, ∃ b, a ≤ b ∧ Minimal (· ∈ s) b) : {x | Minimal (· ∈ s) x} = t := ht.to_dual.eq_setOf_maximal h hs end Preorder section PartialOrder variable [PartialOrder α] theorem setOf_maximal_antichain (P : α → Prop) : IsAntichain (· ≤ ·) {x | Maximal P x} := fun _ hx _ ⟨hy, _⟩ hne hle ↦ hne (hle.antisymm <| hx.2 hy hle) theorem setOf_minimal_antichain (P : α → Prop) : IsAntichain (· ≤ ·) {x | Minimal P x} := (setOf_maximal_antichain (α := αᵒᵈ) P).swap theorem IsLeast.minimal_iff (h : IsLeast s a) : Minimal (· ∈ s) x ↔ x = a := ⟨fun h' ↦ h'.eq_of_ge h.1 (h.2 h'.prop), fun h' ↦ h' ▸ h.minimal⟩ theorem IsGreatest.maximal_iff (h : IsGreatest s a) : Maximal (· ∈ s) x ↔ x = a := ⟨fun h' ↦ h'.eq_of_le h.1 (h.2 h'.prop), fun h' ↦ h' ▸ h.maximal⟩ end PartialOrder end Set section Image variable [Preorder α] {β : Type*} [Preorder β] {s : Set α} {t : Set β} section Function variable {f : α → β} theorem minimal_mem_image_monotone (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ x ≤ y)) (hx : Minimal (· ∈ s) x) : Minimal (· ∈ f '' s) (f x) := by refine ⟨mem_image_of_mem f hx.prop, ?_⟩ rintro _ ⟨y, hy, rfl⟩ rw [hf hx.prop hy, hf hy hx.prop] exact hx.le_of_le hy theorem maximal_mem_image_monotone (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ x ≤ y)) (hx : Maximal (· ∈ s) x) : Maximal (· ∈ f '' s) (f x) := minimal_mem_image_monotone (α := αᵒᵈ) (β := βᵒᵈ) (s := s) (fun _ _ hx hy ↦ hf hy hx) hx theorem minimal_mem_image_monotone_iff (ha : a ∈ s) (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ x ≤ y)) : Minimal (· ∈ f '' s) (f a) ↔ Minimal (· ∈ s) a := by refine ⟨fun h ↦ ⟨ha, fun y hys ↦ ?_⟩, minimal_mem_image_monotone hf⟩ rw [← hf ha hys, ← hf hys ha] exact h.le_of_le (mem_image_of_mem f hys) theorem maximal_mem_image_monotone_iff (ha : a ∈ s) (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ x ≤ y)) : Maximal (· ∈ f '' s) (f a) ↔ Maximal (· ∈ s) a := minimal_mem_image_monotone_iff (α := αᵒᵈ) (β := βᵒᵈ) (s := s) ha fun _ _ hx hy ↦ hf hy hx theorem minimal_mem_image_antitone (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ y ≤ x)) (hx : Minimal (· ∈ s) x) : Maximal (· ∈ f '' s) (f x) := minimal_mem_image_monotone (β := βᵒᵈ) (fun _ _ h h' ↦ hf h' h) hx theorem maximal_mem_image_antitone (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ y ≤ x)) (hx : Maximal (· ∈ s) x) : Minimal (· ∈ f '' s) (f x) := maximal_mem_image_monotone (β := βᵒᵈ) (fun _ _ h h' ↦ hf h' h) hx theorem minimal_mem_image_antitone_iff (ha : a ∈ s) (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ y ≤ x)) : Minimal (· ∈ f '' s) (f a) ↔ Maximal (· ∈ s) a := maximal_mem_image_monotone_iff (β := βᵒᵈ) ha (fun _ _ h h' ↦ hf h' h) theorem maximal_mem_image_antitone_iff (ha : a ∈ s) (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ y ≤ x)) : Maximal (· ∈ f '' s) (f a) ↔ Minimal (· ∈ s) a := minimal_mem_image_monotone_iff (β := βᵒᵈ) ha (fun _ _ h h' ↦ hf h' h) theorem image_monotone_setOf_minimal (hf : ∀ ⦃x y⦄, P x → P y → (f x ≤ f y ↔ x ≤ y)) : f '' {x | Minimal P x} = {x | Minimal (∃ x₀, P x₀ ∧ f x₀ = ·) x} := by refine Set.ext fun x ↦ ⟨?_, fun h ↦ ?_⟩ · rintro ⟨x, (hx : Minimal _ x), rfl⟩ exact (minimal_mem_image_monotone_iff hx.prop hf).2 hx obtain ⟨y, hy, rfl⟩ := (mem_setOf_eq ▸ h).prop
exact mem_image_of_mem _ <| (minimal_mem_image_monotone_iff (s := setOf P) hy hf).1 h theorem image_monotone_setOf_maximal (hf : ∀ ⦃x y⦄, P x → P y → (f x ≤ f y ↔ x ≤ y)) : f '' {x | Maximal P x} = {x | Maximal (∃ x₀, P x₀ ∧ f x₀ = ·) x} := image_monotone_setOf_minimal (α := αᵒᵈ) (β := βᵒᵈ) (fun _ _ hx hy ↦ hf hy hx)
Mathlib/Order/Minimal.lean
474
478
/- 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.MeasureTheory.Measure.Content import Mathlib.MeasureTheory.Group.Prod import Mathlib.Topology.Algebra.Group.Compact /-! # Haar measure In this file we prove the existence of Haar measure for a locally compact Hausdorff topological group. We follow the write-up by Jonathan Gleason, *Existence and Uniqueness of Haar Measure*. This is essentially the same argument as in https://en.wikipedia.org/wiki/Haar_measure#A_construction_using_compact_subsets. We construct the Haar measure first on compact sets. For this we define `(K : U)` as the (smallest) number of left-translates of `U` that are needed to cover `K` (`index` in the formalization). Then we define a function `h` on compact sets as `lim_U (K : U) / (K₀ : U)`, where `U` becomes a smaller and smaller open neighborhood of `1`, and `K₀` is a fixed compact set with nonempty interior. This function is `chaar` in the formalization, and we define the limit formally using Tychonoff's theorem. This function `h` forms a content, which we can extend to an outer measure and then a measure (`haarMeasure`). We normalize the Haar measure so that the measure of `K₀` is `1`. Note that `μ` need not coincide with `h` on compact sets, according to [halmos1950measure, ch. X, §53 p.233]. However, we know that `h(K)` lies between `μ(Kᵒ)` and `μ(K)`, where `ᵒ` denotes the interior. We also give a form of uniqueness of Haar measure, for σ-finite measures on second-countable locally compact groups. For more involved statements not assuming second-countability, see the file `Mathlib/MeasureTheory/Measure/Haar/Unique.lean`. ## Main Declarations * `haarMeasure`: the Haar measure on a locally compact Hausdorff group. This is a left invariant regular measure. It takes as argument a compact set of the group (with non-empty interior), and is normalized so that the measure of the given set is 1. * `haarMeasure_self`: the Haar measure is normalized. * `isMulLeftInvariant_haarMeasure`: the Haar measure is left invariant. * `regular_haarMeasure`: the Haar measure is a regular measure. * `isHaarMeasure_haarMeasure`: the Haar measure satisfies the `IsHaarMeasure` typeclass, i.e., it is invariant and gives finite mass to compact sets and positive mass to nonempty open sets. * `haar` : some choice of a Haar measure, on a locally compact Hausdorff group, constructed as `haarMeasure K` where `K` is some arbitrary choice of a compact set with nonempty interior. * `haarMeasure_unique`: Every σ-finite left invariant measure on a second-countable locally compact Hausdorff group is a scalar multiple of the Haar measure. ## References * Paul Halmos (1950), Measure Theory, §53 * Jonathan Gleason, Existence and Uniqueness of Haar Measure - Note: step 9, page 8 contains a mistake: the last defined `μ` does not extend the `μ` on compact sets, see Halmos (1950) p. 233, bottom of the page. This makes some other steps (like step 11) invalid. * https://en.wikipedia.org/wiki/Haar_measure -/ noncomputable section open Set Inv Function TopologicalSpace MeasurableSpace open scoped NNReal ENNReal Pointwise Topology namespace MeasureTheory namespace Measure section Group variable {G : Type*} [Group G] /-! We put the internal functions in the construction of the Haar measure in a namespace, so that the chosen names don't clash with other declarations. We first define a couple of the functions before proving the properties (that require that `G` is a topological group). -/ namespace haar /-- The index or Haar covering number or ratio of `K` w.r.t. `V`, denoted `(K : V)`: it is the smallest number of (left) translates of `V` that is necessary to cover `K`. It is defined to be 0 if no finite number of translates cover `K`. -/ @[to_additive addIndex "additive version of `MeasureTheory.Measure.haar.index`"] noncomputable def index (K V : Set G) : ℕ := sInf <| Finset.card '' { t : Finset G | K ⊆ ⋃ g ∈ t, (fun h => g * h) ⁻¹' V } @[to_additive addIndex_empty] theorem index_empty {V : Set G} : index ∅ V = 0 := by simp [index] variable [TopologicalSpace G] /-- `prehaar K₀ U K` is a weighted version of the index, defined as `(K : U)/(K₀ : U)`. In the applications `K₀` is compact with non-empty interior, `U` is open containing `1`, and `K` is any compact set. The argument `K` is a (bundled) compact set, so that we can consider `prehaar K₀ U` as an element of `haarProduct` (below). -/ @[to_additive "additive version of `MeasureTheory.Measure.haar.prehaar`"] noncomputable def prehaar (K₀ U : Set G) (K : Compacts G) : ℝ := (index (K : Set G) U : ℝ) / index K₀ U @[to_additive] theorem prehaar_empty (K₀ : PositiveCompacts G) {U : Set G} : prehaar (K₀ : Set G) U ⊥ = 0 := by rw [prehaar, Compacts.coe_bot, index_empty, Nat.cast_zero, zero_div] @[to_additive] theorem prehaar_nonneg (K₀ : PositiveCompacts G) {U : Set G} (K : Compacts G) : 0 ≤ prehaar (K₀ : Set G) U K := by apply div_nonneg <;> norm_cast <;> apply zero_le /-- `haarProduct K₀` is the product of intervals `[0, (K : K₀)]`, for all compact sets `K`. For all `U`, we can show that `prehaar K₀ U ∈ haarProduct K₀`. -/ @[to_additive "additive version of `MeasureTheory.Measure.haar.haarProduct`"] def haarProduct (K₀ : Set G) : Set (Compacts G → ℝ) := pi univ fun K => Icc 0 <| index (K : Set G) K₀ @[to_additive (attr := simp)] theorem mem_prehaar_empty {K₀ : Set G} {f : Compacts G → ℝ} : f ∈ haarProduct K₀ ↔ ∀ K : Compacts G, f K ∈ Icc (0 : ℝ) (index (K : Set G) K₀) := by simp only [haarProduct, Set.pi, forall_prop_of_true, mem_univ, mem_setOf_eq] /-- The closure of the collection of elements of the form `prehaar K₀ U`, for `U` open neighbourhoods of `1`, contained in `V`. The closure is taken in the space `compacts G → ℝ`, with the topology of pointwise convergence. We show that the intersection of all these sets is nonempty, and the Haar measure on compact sets is defined to be an element in the closure of this intersection. -/ @[to_additive "additive version of `MeasureTheory.Measure.haar.clPrehaar`"] def clPrehaar (K₀ : Set G) (V : OpenNhdsOf (1 : G)) : Set (Compacts G → ℝ) := closure <| prehaar K₀ '' { U : Set G | U ⊆ V.1 ∧ IsOpen U ∧ (1 : G) ∈ U } variable [IsTopologicalGroup G] /-! ### Lemmas about `index` -/ /-- If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined, there is a finite set `t` satisfying the desired properties. -/ @[to_additive addIndex_defined "If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined, there is a finite set `t` satisfying the desired properties."] theorem index_defined {K V : Set G} (hK : IsCompact K) (hV : (interior V).Nonempty) : ∃ n : ℕ, n ∈ Finset.card '' { t : Finset G | K ⊆ ⋃ g ∈ t, (fun h => g * h) ⁻¹' V } := by rcases compact_covered_by_mul_left_translates hK hV with ⟨t, ht⟩; exact ⟨t.card, t, ht, rfl⟩ @[to_additive addIndex_elim] theorem index_elim {K V : Set G} (hK : IsCompact K) (hV : (interior V).Nonempty) : ∃ t : Finset G, (K ⊆ ⋃ g ∈ t, (fun h => g * h) ⁻¹' V) ∧ Finset.card t = index K V := by have := Nat.sInf_mem (index_defined hK hV); rwa [mem_image] at this @[to_additive le_addIndex_mul] theorem le_index_mul (K₀ : PositiveCompacts G) (K : Compacts G) {V : Set G} (hV : (interior V).Nonempty) : index (K : Set G) V ≤ index (K : Set G) K₀ * index (K₀ : Set G) V := by classical obtain ⟨s, h1s, h2s⟩ := index_elim K.isCompact K₀.interior_nonempty obtain ⟨t, h1t, h2t⟩ := index_elim K₀.isCompact hV rw [← h2s, ← h2t, mul_comm] refine le_trans ?_ Finset.card_mul_le apply Nat.sInf_le; refine ⟨_, ?_, rfl⟩; rw [mem_setOf_eq]; refine Subset.trans h1s ?_ apply iUnion₂_subset; intro g₁ hg₁; rw [preimage_subset_iff]; intro g₂ hg₂ have := h1t hg₂ rcases this with ⟨_, ⟨g₃, rfl⟩, A, ⟨hg₃, rfl⟩, h2V⟩; rw [mem_preimage, ← mul_assoc] at h2V exact mem_biUnion (Finset.mul_mem_mul hg₃ hg₁) h2V @[to_additive addIndex_pos] theorem index_pos (K : PositiveCompacts G) {V : Set G} (hV : (interior V).Nonempty) : 0 < index (K : Set G) V := by classical rw [index, Nat.sInf_def, Nat.find_pos, mem_image] · rintro ⟨t, h1t, h2t⟩; rw [Finset.card_eq_zero] at h2t; subst h2t obtain ⟨g, hg⟩ := K.interior_nonempty show g ∈ (∅ : Set G) convert h1t (interior_subset hg); symm simp only [Finset.not_mem_empty, iUnion_of_empty, iUnion_empty] · exact index_defined K.isCompact hV @[to_additive addIndex_mono] theorem index_mono {K K' V : Set G} (hK' : IsCompact K') (h : K ⊆ K') (hV : (interior V).Nonempty) : index K V ≤ index K' V := by rcases index_elim hK' hV with ⟨s, h1s, h2s⟩ apply Nat.sInf_le; rw [mem_image]; exact ⟨s, Subset.trans h h1s, h2s⟩ @[to_additive addIndex_union_le] theorem index_union_le (K₁ K₂ : Compacts G) {V : Set G} (hV : (interior V).Nonempty) : index (K₁.1 ∪ K₂.1) V ≤ index K₁.1 V + index K₂.1 V := by classical rcases index_elim K₁.2 hV with ⟨s, h1s, h2s⟩ rcases index_elim K₂.2 hV with ⟨t, h1t, h2t⟩ rw [← h2s, ← h2t] refine le_trans ?_ (Finset.card_union_le _ _) apply Nat.sInf_le; refine ⟨_, ?_, rfl⟩; rw [mem_setOf_eq] apply union_subset <;> refine Subset.trans (by assumption) ?_ <;> apply biUnion_subset_biUnion_left <;> intro g hg <;> simp only [mem_def] at hg <;> simp only [mem_def, Multiset.mem_union, Finset.union_val, hg, or_true, true_or] @[to_additive addIndex_union_eq] theorem index_union_eq (K₁ K₂ : Compacts G) {V : Set G} (hV : (interior V).Nonempty) (h : Disjoint (K₁.1 * V⁻¹) (K₂.1 * V⁻¹)) : index (K₁.1 ∪ K₂.1) V = index K₁.1 V + index K₂.1 V := by classical apply le_antisymm (index_union_le K₁ K₂ hV) rcases index_elim (K₁.2.union K₂.2) hV with ⟨s, h1s, h2s⟩; rw [← h2s] have (K : Set G) (hK : K ⊆ ⋃ g ∈ s, (g * ·) ⁻¹' V) : index K V ≤ {g ∈ s | ((g * ·) ⁻¹' V ∩ K).Nonempty}.card := by apply Nat.sInf_le; refine ⟨_, ?_, rfl⟩; rw [mem_setOf_eq] intro g hg; rcases hK hg with ⟨_, ⟨g₀, rfl⟩, _, ⟨h1g₀, rfl⟩, h2g₀⟩ simp only [mem_preimage] at h2g₀ simp only [mem_iUnion]; use g₀; constructor; swap · simp only [Finset.mem_filter, h1g₀, true_and]; use g simp [hg, h2g₀] exact h2g₀ refine le_trans (add_le_add (this K₁.1 <| Subset.trans subset_union_left h1s) (this K₂.1 <| Subset.trans subset_union_right h1s)) ?_ rw [← Finset.card_union_of_disjoint, Finset.filter_union_right] · exact s.card_filter_le _ apply Finset.disjoint_filter.mpr rintro g₁ _ ⟨g₂, h1g₂, h2g₂⟩ ⟨g₃, h1g₃, h2g₃⟩ simp only [mem_preimage] at h1g₃ h1g₂ refine h.le_bot (?_ : g₁⁻¹ ∈ _) constructor <;> simp only [Set.mem_inv, Set.mem_mul, exists_exists_and_eq_and, exists_and_left] · refine ⟨_, h2g₂, (g₁ * g₂)⁻¹, ?_, ?_⟩ · simp only [inv_inv, h1g₂] · simp only [mul_inv_rev, mul_inv_cancel_left] · refine ⟨_, h2g₃, (g₁ * g₃)⁻¹, ?_, ?_⟩ · simp only [inv_inv, h1g₃] · simp only [mul_inv_rev, mul_inv_cancel_left] @[to_additive add_left_addIndex_le] theorem mul_left_index_le {K : Set G} (hK : IsCompact K) {V : Set G} (hV : (interior V).Nonempty) (g : G) : index ((fun h => g * h) '' K) V ≤ index K V := by rcases index_elim hK hV with ⟨s, h1s, h2s⟩; rw [← h2s] apply Nat.sInf_le; rw [mem_image] refine ⟨s.map (Equiv.mulRight g⁻¹).toEmbedding, ?_, Finset.card_map _⟩ simp only [mem_setOf_eq]; refine Subset.trans (image_subset _ h1s) ?_ rintro _ ⟨g₁, ⟨_, ⟨g₂, rfl⟩, ⟨_, ⟨hg₂, rfl⟩, hg₁⟩⟩, rfl⟩ simp only [mem_preimage] at hg₁ simp only [exists_prop, mem_iUnion, Finset.mem_map, Equiv.coe_mulRight, exists_exists_and_eq_and, mem_preimage, Equiv.toEmbedding_apply] refine ⟨_, hg₂, ?_⟩; simp only [mul_assoc, hg₁, inv_mul_cancel_left] @[to_additive is_left_invariant_addIndex] theorem is_left_invariant_index {K : Set G} (hK : IsCompact K) (g : G) {V : Set G} (hV : (interior V).Nonempty) : index ((fun h => g * h) '' K) V = index K V := by refine le_antisymm (mul_left_index_le hK hV g) ?_ convert mul_left_index_le (hK.image <| continuous_mul_left g) hV g⁻¹ rw [image_image]; symm; convert image_id' _ with h; apply inv_mul_cancel_left /-! ### Lemmas about `prehaar` -/ @[to_additive add_prehaar_le_addIndex] theorem prehaar_le_index (K₀ : PositiveCompacts G) {U : Set G} (K : Compacts G) (hU : (interior U).Nonempty) : prehaar (K₀ : Set G) U K ≤ index (K : Set G) K₀ := by unfold prehaar; rw [div_le_iff₀] <;> norm_cast · apply le_index_mul K₀ K hU · exact index_pos K₀ hU @[to_additive] theorem prehaar_pos (K₀ : PositiveCompacts G) {U : Set G} (hU : (interior U).Nonempty) {K : Set G} (h1K : IsCompact K) (h2K : (interior K).Nonempty) : 0 < prehaar (K₀ : Set G) U ⟨K, h1K⟩ := by apply div_pos <;> norm_cast · apply index_pos ⟨⟨K, h1K⟩, h2K⟩ hU · exact index_pos K₀ hU @[to_additive] theorem prehaar_mono {K₀ : PositiveCompacts G} {U : Set G} (hU : (interior U).Nonempty) {K₁ K₂ : Compacts G} (h : (K₁ : Set G) ⊆ K₂.1) : prehaar (K₀ : Set G) U K₁ ≤ prehaar (K₀ : Set G) U K₂ := by simp only [prehaar]; rw [div_le_div_iff_of_pos_right] · exact mod_cast index_mono K₂.2 h hU · exact mod_cast index_pos K₀ hU @[to_additive] theorem prehaar_self {K₀ : PositiveCompacts G} {U : Set G} (hU : (interior U).Nonempty) : prehaar (K₀ : Set G) U K₀.toCompacts = 1 := div_self <| ne_of_gt <| mod_cast index_pos K₀ hU @[to_additive] theorem prehaar_sup_le {K₀ : PositiveCompacts G} {U : Set G} (K₁ K₂ : Compacts G) (hU : (interior U).Nonempty) : prehaar (K₀ : Set G) U (K₁ ⊔ K₂) ≤ prehaar (K₀ : Set G) U K₁ + prehaar (K₀ : Set G) U K₂ := by simp only [prehaar]; rw [div_add_div_same, div_le_div_iff_of_pos_right] · exact mod_cast index_union_le K₁ K₂ hU · exact mod_cast index_pos K₀ hU @[to_additive] theorem prehaar_sup_eq {K₀ : PositiveCompacts G} {U : Set G} {K₁ K₂ : Compacts G} (hU : (interior U).Nonempty) (h : Disjoint (K₁.1 * U⁻¹) (K₂.1 * U⁻¹)) : prehaar (K₀ : Set G) U (K₁ ⊔ K₂) = prehaar (K₀ : Set G) U K₁ + prehaar (K₀ : Set G) U K₂ := by simp only [prehaar]; rw [div_add_div_same] -- Porting note: Here was `congr`, but `to_additive` failed to generate a theorem. refine congr_arg (fun x : ℝ => x / index K₀ U) ?_ exact mod_cast index_union_eq K₁ K₂ hU h @[to_additive] theorem is_left_invariant_prehaar {K₀ : PositiveCompacts G} {U : Set G} (hU : (interior U).Nonempty) (g : G) (K : Compacts G) : prehaar (K₀ : Set G) U (K.map _ <| continuous_mul_left g) = prehaar (K₀ : Set G) U K := by simp only [prehaar, Compacts.coe_map, is_left_invariant_index K.isCompact _ hU] /-! ### Lemmas about `haarProduct` -/ @[to_additive] theorem prehaar_mem_haarProduct (K₀ : PositiveCompacts G) {U : Set G} (hU : (interior U).Nonempty) : prehaar (K₀ : Set G) U ∈ haarProduct (K₀ : Set G) := by rintro ⟨K, hK⟩ _; rw [mem_Icc]; exact ⟨prehaar_nonneg K₀ _, prehaar_le_index K₀ _ hU⟩ @[to_additive] theorem nonempty_iInter_clPrehaar (K₀ : PositiveCompacts G) : (haarProduct (K₀ : Set G) ∩ ⋂ V : OpenNhdsOf (1 : G), clPrehaar K₀ V).Nonempty := by have : IsCompact (haarProduct (K₀ : Set G)) := by apply isCompact_univ_pi; intro K; apply isCompact_Icc refine this.inter_iInter_nonempty (clPrehaar K₀) (fun s => isClosed_closure) fun t => ?_ let V₀ := ⋂ V ∈ t, (V : OpenNhdsOf (1 : G)).carrier have h1V₀ : IsOpen V₀ := isOpen_biInter_finset <| by rintro ⟨⟨V, hV₁⟩, hV₂⟩ _; exact hV₁ have h2V₀ : (1 : G) ∈ V₀ := by simp only [V₀, mem_iInter]; rintro ⟨⟨V, hV₁⟩, hV₂⟩ _; exact hV₂ refine ⟨prehaar K₀ V₀, ?_⟩ constructor · apply prehaar_mem_haarProduct K₀; use 1; rwa [h1V₀.interior_eq] · simp only [mem_iInter]; rintro ⟨V, hV⟩ h2V; apply subset_closure apply mem_image_of_mem; rw [mem_setOf_eq] exact ⟨Subset.trans (iInter_subset _ ⟨V, hV⟩) (iInter_subset _ h2V), h1V₀, h2V₀⟩ /-! ### Lemmas about `chaar` -/ /-- This is the "limit" of `prehaar K₀ U K` as `U` becomes a smaller and smaller open neighborhood of `(1 : G)`. More precisely, it is defined to be an arbitrary element in the intersection of all the sets `clPrehaar K₀ V` in `haarProduct K₀`. This is roughly equal to the Haar measure on compact sets, but it can differ slightly. We do know that `haarMeasure K₀ (interior K) ≤ chaar K₀ K ≤ haarMeasure K₀ K`. -/ @[to_additive addCHaar "additive version of `MeasureTheory.Measure.haar.chaar`"] noncomputable def chaar (K₀ : PositiveCompacts G) (K : Compacts G) : ℝ := Classical.choose (nonempty_iInter_clPrehaar K₀) K @[to_additive addCHaar_mem_addHaarProduct] theorem chaar_mem_haarProduct (K₀ : PositiveCompacts G) : chaar K₀ ∈ haarProduct (K₀ : Set G) := (Classical.choose_spec (nonempty_iInter_clPrehaar K₀)).1 @[to_additive addCHaar_mem_clAddPrehaar] theorem chaar_mem_clPrehaar (K₀ : PositiveCompacts G) (V : OpenNhdsOf (1 : G)) : chaar K₀ ∈ clPrehaar (K₀ : Set G) V := by have := (Classical.choose_spec (nonempty_iInter_clPrehaar K₀)).2; rw [mem_iInter] at this exact this V @[to_additive addCHaar_nonneg] theorem chaar_nonneg (K₀ : PositiveCompacts G) (K : Compacts G) : 0 ≤ chaar K₀ K := by have := chaar_mem_haarProduct K₀ K (mem_univ _); rw [mem_Icc] at this; exact this.1 @[to_additive addCHaar_empty] theorem chaar_empty (K₀ : PositiveCompacts G) : chaar K₀ ⊥ = 0 := by let eval : (Compacts G → ℝ) → ℝ := fun f => f ⊥ have : Continuous eval := continuous_apply ⊥ show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)} apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤) unfold clPrehaar; rw [IsClosed.closure_subset_iff] · rintro _ ⟨U, _, rfl⟩; apply prehaar_empty · apply continuous_iff_isClosed.mp this; exact isClosed_singleton @[to_additive addCHaar_self] theorem chaar_self (K₀ : PositiveCompacts G) : chaar K₀ K₀.toCompacts = 1 := by let eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts have : Continuous eval := continuous_apply _ show chaar K₀ ∈ eval ⁻¹' {(1 : ℝ)} apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤) unfold clPrehaar; rw [IsClosed.closure_subset_iff] · rintro _ ⟨U, ⟨_, h2U, h3U⟩, rfl⟩; apply prehaar_self rw [h2U.interior_eq]; exact ⟨1, h3U⟩ · apply continuous_iff_isClosed.mp this; exact isClosed_singleton @[to_additive addCHaar_mono] theorem chaar_mono {K₀ : PositiveCompacts G} {K₁ K₂ : Compacts G} (h : (K₁ : Set G) ⊆ K₂) : chaar K₀ K₁ ≤ chaar K₀ K₂ := by let eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁ have : Continuous eval := (continuous_apply K₂).sub (continuous_apply K₁) rw [← sub_nonneg]; show chaar K₀ ∈ eval ⁻¹' Ici (0 : ℝ) apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤) unfold clPrehaar; rw [IsClosed.closure_subset_iff] · rintro _ ⟨U, ⟨_, h2U, h3U⟩, rfl⟩; simp only [eval, mem_preimage, mem_Ici, sub_nonneg] apply prehaar_mono _ h; rw [h2U.interior_eq]; exact ⟨1, h3U⟩ · apply continuous_iff_isClosed.mp this; exact isClosed_Ici @[to_additive addCHaar_sup_le] theorem chaar_sup_le {K₀ : PositiveCompacts G} (K₁ K₂ : Compacts G) : chaar K₀ (K₁ ⊔ K₂) ≤ chaar K₀ K₁ + chaar K₀ K₂ := by let eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂) have : Continuous eval := by exact ((continuous_apply K₁).add (continuous_apply K₂)).sub (continuous_apply (K₁ ⊔ K₂)) rw [← sub_nonneg]; show chaar K₀ ∈ eval ⁻¹' Ici (0 : ℝ) apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤) unfold clPrehaar; rw [IsClosed.closure_subset_iff] · rintro _ ⟨U, ⟨_, h2U, h3U⟩, rfl⟩; simp only [eval, mem_preimage, mem_Ici, sub_nonneg] apply prehaar_sup_le; rw [h2U.interior_eq]; exact ⟨1, h3U⟩ · apply continuous_iff_isClosed.mp this; exact isClosed_Ici @[to_additive addCHaar_sup_eq] theorem chaar_sup_eq {K₀ : PositiveCompacts G} {K₁ K₂ : Compacts G} (h : Disjoint K₁.1 K₂.1) (h₂ : IsClosed K₂.1) : chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂ := by rcases SeparatedNhds.of_isCompact_isCompact_isClosed K₁.2 K₂.2 h₂ h with ⟨U₁, U₂, h1U₁, h1U₂, h2U₁, h2U₂, hU⟩ rcases compact_open_separated_mul_right K₁.2 h1U₁ h2U₁ with ⟨L₁, h1L₁, h2L₁⟩ rcases mem_nhds_iff.mp h1L₁ with ⟨V₁, h1V₁, h2V₁, h3V₁⟩ replace h2L₁ := Subset.trans (mul_subset_mul_left h1V₁) h2L₁ rcases compact_open_separated_mul_right K₂.2 h1U₂ h2U₂ with ⟨L₂, h1L₂, h2L₂⟩ rcases mem_nhds_iff.mp h1L₂ with ⟨V₂, h1V₂, h2V₂, h3V₂⟩ replace h2L₂ := Subset.trans (mul_subset_mul_left h1V₂) h2L₂ let eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂) have : Continuous eval := ((continuous_apply K₁).add (continuous_apply K₂)).sub (continuous_apply (K₁ ⊔ K₂)) rw [eq_comm, ← sub_eq_zero]; show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)} let V := V₁ ∩ V₂ apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⟨⟨V⁻¹, (h2V₁.inter h2V₂).preimage continuous_inv⟩, by simp only [V, mem_inv, inv_one, h3V₁, h3V₂, mem_inter_iff, true_and]⟩) unfold clPrehaar; rw [IsClosed.closure_subset_iff] · rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩ simp only [eval, mem_preimage, sub_eq_zero, mem_singleton_iff]; rw [eq_comm] apply prehaar_sup_eq · rw [h2U.interior_eq]; exact ⟨1, h3U⟩ · refine disjoint_of_subset ?_ ?_ hU · refine Subset.trans (mul_subset_mul Subset.rfl ?_) h2L₁ exact Subset.trans (inv_subset.mpr h1U) inter_subset_left · refine Subset.trans (mul_subset_mul Subset.rfl ?_) h2L₂ exact Subset.trans (inv_subset.mpr h1U) inter_subset_right · apply continuous_iff_isClosed.mp this; exact isClosed_singleton @[to_additive is_left_invariant_addCHaar] theorem is_left_invariant_chaar {K₀ : PositiveCompacts G} (g : G) (K : Compacts G) : chaar K₀ (K.map _ <| continuous_mul_left g) = chaar K₀ K := by let eval : (Compacts G → ℝ) → ℝ := fun f => f (K.map _ <| continuous_mul_left g) - f K
have : Continuous eval := (continuous_apply (K.map _ _)).sub (continuous_apply K) rw [← sub_eq_zero]; show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)} apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤) unfold clPrehaar; rw [IsClosed.closure_subset_iff] · rintro _ ⟨U, ⟨_, h2U, h3U⟩, rfl⟩ simp only [eval, mem_singleton_iff, mem_preimage, sub_eq_zero] apply is_left_invariant_prehaar; rw [h2U.interior_eq]; exact ⟨1, h3U⟩ · apply continuous_iff_isClosed.mp this; exact isClosed_singleton
Mathlib/MeasureTheory/Measure/Haar/Basic.lean
448
456
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Joël Riou -/ import Mathlib.Algebra.Homology.Homotopy import Mathlib.Algebra.Homology.ShortComplex.Retract import Mathlib.CategoryTheory.MorphismProperty.Composition /-! # Quasi-isomorphisms A chain map is a quasi-isomorphism if it induces isomorphisms on homology. -/ open CategoryTheory Limits universe v u open HomologicalComplex section variable {ι : Type*} {C : Type u} [Category.{v} C] [HasZeroMorphisms C] {c : ComplexShape ι} {K L M K' L' : HomologicalComplex C c} /-- A morphism of homological complexes `f : K ⟶ L` is a quasi-isomorphism in degree `i` when it induces a quasi-isomorphism of short complexes `K.sc i ⟶ L.sc i`. -/ class QuasiIsoAt (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] : Prop where quasiIso : ShortComplex.QuasiIso ((shortComplexFunctor C c i).map f) lemma quasiIsoAt_iff (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] : QuasiIsoAt f i ↔ ShortComplex.QuasiIso ((shortComplexFunctor C c i).map f) := by constructor · intro h exact h.quasiIso · intro h exact ⟨h⟩ instance quasiIsoAt_of_isIso (f : K ⟶ L) [IsIso f] (i : ι) [K.HasHomology i] [L.HasHomology i] : QuasiIsoAt f i := by rw [quasiIsoAt_iff] infer_instance lemma quasiIsoAt_iff' (f : K ⟶ L) (i j k : ι) (hi : c.prev j = i) (hk : c.next j = k) [K.HasHomology j] [L.HasHomology j] [(K.sc' i j k).HasHomology] [(L.sc' i j k).HasHomology] : QuasiIsoAt f j ↔ ShortComplex.QuasiIso ((shortComplexFunctor' C c i j k).map f) := by rw [quasiIsoAt_iff] exact ShortComplex.quasiIso_iff_of_arrow_mk_iso _ _ (Arrow.isoOfNatIso (natIsoSc' C c i j k hi hk) (Arrow.mk f)) lemma quasiIsoAt_of_retract {f : K ⟶ L} {f' : K' ⟶ L'} (h : RetractArrow f f') (i : ι) [K.HasHomology i] [L.HasHomology i] [K'.HasHomology i] [L'.HasHomology i] [hf' : QuasiIsoAt f' i] : QuasiIsoAt f i := by rw [quasiIsoAt_iff] at hf' ⊢ have : RetractArrow ((shortComplexFunctor C c i).map f) ((shortComplexFunctor C c i).map f') := h.map (shortComplexFunctor C c i).mapArrow exact ShortComplex.quasiIso_of_retract this lemma quasiIsoAt_iff_isIso_homologyMap (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] : QuasiIsoAt f i ↔ IsIso (homologyMap f i) := by rw [quasiIsoAt_iff, ShortComplex.quasiIso_iff] rfl lemma quasiIsoAt_iff_exactAt (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] (hK : K.ExactAt i) : QuasiIsoAt f i ↔ L.ExactAt i := by simp only [quasiIsoAt_iff, ShortComplex.quasiIso_iff, exactAt_iff, ShortComplex.exact_iff_isZero_homology] at hK ⊢ constructor · intro h exact IsZero.of_iso hK (@asIso _ _ _ _ _ h).symm · intro hL exact ⟨⟨0, IsZero.eq_of_src hK _ _, IsZero.eq_of_tgt hL _ _⟩⟩ lemma quasiIsoAt_iff_exactAt' (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] (hL : L.ExactAt i) : QuasiIsoAt f i ↔ K.ExactAt i := by simp only [quasiIsoAt_iff, ShortComplex.quasiIso_iff, exactAt_iff, ShortComplex.exact_iff_isZero_homology] at hL ⊢ constructor · intro h exact IsZero.of_iso hL (@asIso _ _ _ _ _ h) · intro hK exact ⟨⟨0, IsZero.eq_of_src hK _ _, IsZero.eq_of_tgt hL _ _⟩⟩ lemma exactAt_iff_of_quasiIsoAt (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [QuasiIsoAt f i] : K.ExactAt i ↔ L.ExactAt i := ⟨fun hK => (quasiIsoAt_iff_exactAt f i hK).1 inferInstance, fun hL => (quasiIsoAt_iff_exactAt' f i hL).1 inferInstance⟩ instance (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [hf : QuasiIsoAt f i] : IsIso (homologyMap f i) := by simpa only [quasiIsoAt_iff, ShortComplex.quasiIso_iff] using hf /-- The isomorphism `K.homology i ≅ L.homology i` induced by a morphism `f : K ⟶ L` such that `[QuasiIsoAt f i]` holds. -/ @[simps! hom] noncomputable def isoOfQuasiIsoAt (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [QuasiIsoAt f i] : K.homology i ≅ L.homology i := asIso (homologyMap f i) @[reassoc (attr := simp)] lemma isoOfQuasiIsoAt_hom_inv_id (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [QuasiIsoAt f i] : homologyMap f i ≫ (isoOfQuasiIsoAt f i).inv = 𝟙 _ := (isoOfQuasiIsoAt f i).hom_inv_id @[reassoc (attr := simp)] lemma isoOfQuasiIsoAt_inv_hom_id (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [QuasiIsoAt f i] : (isoOfQuasiIsoAt f i).inv ≫ homologyMap f i = 𝟙 _ := (isoOfQuasiIsoAt f i).inv_hom_id
lemma CochainComplex.quasiIsoAt₀_iff {K L : CochainComplex C ℕ} (f : K ⟶ L) [K.HasHomology 0] [L.HasHomology 0] [(K.sc' 0 0 1).HasHomology] [(L.sc' 0 0 1).HasHomology] : QuasiIsoAt f 0 ↔ ShortComplex.QuasiIso ((HomologicalComplex.shortComplexFunctor' C _ 0 0 1).map f) := quasiIsoAt_iff' _ _ _ _ (by simp) (by simp)
Mathlib/Algebra/Homology/QuasiIso.lean
122
127
/- 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, Patrick Massot, Casper Putz, Anne Baanen -/ import Mathlib.Algebra.Algebra.Subalgebra.Tower import Mathlib.Data.Finite.Sum import Mathlib.Data.Matrix.Block import Mathlib.Data.Matrix.Notation import Mathlib.LinearAlgebra.Basis.Basic import Mathlib.LinearAlgebra.Basis.Fin import Mathlib.LinearAlgebra.Basis.Prod import Mathlib.LinearAlgebra.Basis.SMul import Mathlib.LinearAlgebra.Matrix.StdBasis import Mathlib.RingTheory.AlgebraTower import Mathlib.RingTheory.Ideal.Span /-! # Linear maps and matrices This file defines the maps to send matrices to a linear map, and to send linear maps between modules with a finite bases to matrices. This defines a linear equivalence between linear maps between finite-dimensional vector spaces and matrices indexed by the respective bases. ## Main definitions In the list below, and in all this file, `R` is a commutative ring (semiring is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite types used for indexing. * `LinearMap.toMatrix`: given bases `v₁ : ι → M₁` and `v₂ : κ → M₂`, the `R`-linear equivalence from `M₁ →ₗ[R] M₂` to `Matrix κ ι R` * `Matrix.toLin`: the inverse of `LinearMap.toMatrix` * `LinearMap.toMatrix'`: the `R`-linear equivalence from `(m → R) →ₗ[R] (n → R)` to `Matrix m n R` (with the standard basis on `m → R` and `n → R`) * `Matrix.toLin'`: the inverse of `LinearMap.toMatrix'` * `algEquivMatrix`: given a basis indexed by `n`, the `R`-algebra equivalence between `R`-endomorphisms of `M` and `Matrix n n R` ## Issues This file was originally written without attention to non-commutative rings, and so mostly only works in the commutative setting. This should be fixed. In particular, `Matrix.mulVec` gives us a linear equivalence `Matrix m n R ≃ₗ[R] (n → R) →ₗ[Rᵐᵒᵖ] (m → R)` while `Matrix.vecMul` gives us a linear equivalence `Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] (n → R)`. At present, the first equivalence is developed in detail but only for commutative rings (and we omit the distinction between `Rᵐᵒᵖ` and `R`), while the second equivalence is developed only in brief, but for not-necessarily-commutative rings. Naming is slightly inconsistent between the two developments. In the original (commutative) development `linear` is abbreviated to `lin`, although this is not consistent with the rest of mathlib. In the new (non-commutative) development `linear` is not abbreviated, and declarations use `_right` to indicate they use the right action of matrices on vectors (via `Matrix.vecMul`). When the two developments are made uniform, the names should be made uniform, too, by choosing between `linear` and `lin` consistently, and (presumably) adding `_left` where necessary. ## Tags linear_map, matrix, linear_equiv, diagonal, det, trace -/ noncomputable section open LinearMap Matrix Set Submodule section ToMatrixRight variable {R : Type*} [Semiring R] variable {l m n : Type*} /-- `Matrix.vecMul M` is a linear map. -/ def Matrix.vecMulLinear [Fintype m] (M : Matrix m n R) : (m → R) →ₗ[R] n → R where toFun x := x ᵥ* M map_add' _ _ := funext fun _ ↦ add_dotProduct _ _ _ map_smul' _ _ := funext fun _ ↦ smul_dotProduct _ _ _ @[simp] theorem Matrix.vecMulLinear_apply [Fintype m] (M : Matrix m n R) (x : m → R) : M.vecMulLinear x = x ᵥ* M := rfl theorem Matrix.coe_vecMulLinear [Fintype m] (M : Matrix m n R) : (M.vecMulLinear : _ → _) = M.vecMul := rfl variable [Fintype m] theorem range_vecMulLinear (M : Matrix m n R) : LinearMap.range M.vecMulLinear = span R (range M.row) := by letI := Classical.decEq m simp_rw [range_eq_map, ← iSup_range_single, Submodule.map_iSup, range_eq_map, ← Ideal.span_singleton_one, Ideal.span, Submodule.map_span, image_image, image_singleton, Matrix.vecMulLinear_apply, iSup_span, range_eq_iUnion, iUnion_singleton_eq_range, LinearMap.single, LinearMap.coe_mk, AddHom.coe_mk, row_def] unfold vecMul simp_rw [single_dotProduct, one_mul] theorem Matrix.vecMul_injective_iff {R : Type*} [Ring R] {M : Matrix m n R} : Function.Injective M.vecMul ↔ LinearIndependent R M.row := by rw [← coe_vecMulLinear] simp only [← LinearMap.ker_eq_bot, Fintype.linearIndependent_iff, Submodule.eq_bot_iff, LinearMap.mem_ker, vecMulLinear_apply, row_def] refine ⟨fun h c h0 ↦ congr_fun <| h c ?_, fun h c h0 ↦ funext <| h c ?_⟩ · rw [← h0] ext i simp [vecMul, dotProduct] · rw [← h0] ext j simp [vecMul, dotProduct] lemma Matrix.linearIndependent_rows_of_isUnit {R : Type*} [Ring R] {A : Matrix m m R} [DecidableEq m] (ha : IsUnit A) : LinearIndependent R A.row := by rw [← Matrix.vecMul_injective_iff] exact Matrix.vecMul_injective_of_isUnit ha section variable [DecidableEq m] /-- Linear maps `(m → R) →ₗ[R] (n → R)` are linearly equivalent over `Rᵐᵒᵖ` to `Matrix m n R`, by having matrices act by right multiplication. -/ def LinearMap.toMatrixRight' : ((m → R) →ₗ[R] n → R) ≃ₗ[Rᵐᵒᵖ] Matrix m n R where toFun f i j := f (single R (fun _ ↦ R) i 1) j invFun := Matrix.vecMulLinear right_inv M := by ext i j simp left_inv f := by apply (Pi.basisFun R m).ext intro j; ext i simp map_add' f g := by ext i j simp only [Pi.add_apply, LinearMap.add_apply, Matrix.add_apply] map_smul' c f := by ext i j simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, Matrix.smul_apply] /-- A `Matrix m n R` is linearly equivalent over `Rᵐᵒᵖ` to a linear map `(m → R) →ₗ[R] (n → R)`, by having matrices act by right multiplication. -/ abbrev Matrix.toLinearMapRight' [DecidableEq m] : Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] n → R := LinearEquiv.symm LinearMap.toMatrixRight' @[simp] theorem Matrix.toLinearMapRight'_apply (M : Matrix m n R) (v : m → R) : (Matrix.toLinearMapRight') M v = v ᵥ* M := rfl @[simp] theorem Matrix.toLinearMapRight'_mul [Fintype l] [DecidableEq l] (M : Matrix l m R) (N : Matrix m n R) : Matrix.toLinearMapRight' (M * N) = (Matrix.toLinearMapRight' N).comp (Matrix.toLinearMapRight' M) := LinearMap.ext fun _x ↦ (vecMul_vecMul _ M N).symm theorem Matrix.toLinearMapRight'_mul_apply [Fintype l] [DecidableEq l] (M : Matrix l m R) (N : Matrix m n R) (x) : Matrix.toLinearMapRight' (M * N) x = Matrix.toLinearMapRight' N (Matrix.toLinearMapRight' M x) := (vecMul_vecMul _ M N).symm @[simp] theorem Matrix.toLinearMapRight'_one : Matrix.toLinearMapRight' (1 : Matrix m m R) = LinearMap.id := by ext simp [Module.End.one_apply] /-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `n → A` and `m → A` corresponding to `M.vecMul` and `M'.vecMul`. -/ @[simps] def Matrix.toLinearEquivRight'OfInv [Fintype n] [DecidableEq n] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (n → R) ≃ₗ[R] m → R := { LinearMap.toMatrixRight'.symm M' with toFun := Matrix.toLinearMapRight' M' invFun := Matrix.toLinearMapRight' M left_inv := fun x ↦ by rw [← Matrix.toLinearMapRight'_mul_apply, hM'M, Matrix.toLinearMapRight'_one, id_apply] right_inv := fun x ↦ by rw [← Matrix.toLinearMapRight'_mul_apply, hMM', Matrix.toLinearMapRight'_one, id_apply] } end end ToMatrixRight /-! From this point on, we only work with commutative rings, and fail to distinguish between `Rᵐᵒᵖ` and `R`. This should eventually be remedied. -/ section mulVec variable {R : Type*} [CommSemiring R] variable {k l m n : Type*} /-- `Matrix.mulVec M` is a linear map. -/ def Matrix.mulVecLin [Fintype n] (M : Matrix m n R) : (n → R) →ₗ[R] m → R where toFun := M.mulVec map_add' _ _ := funext fun _ ↦ dotProduct_add _ _ _ map_smul' _ _ := funext fun _ ↦ dotProduct_smul _ _ _ theorem Matrix.coe_mulVecLin [Fintype n] (M : Matrix m n R) : (M.mulVecLin : _ → _) = M.mulVec := rfl @[simp] theorem Matrix.mulVecLin_apply [Fintype n] (M : Matrix m n R) (v : n → R) : M.mulVecLin v = M *ᵥ v := rfl @[simp] theorem Matrix.mulVecLin_zero [Fintype n] : Matrix.mulVecLin (0 : Matrix m n R) = 0 := LinearMap.ext zero_mulVec @[simp] theorem Matrix.mulVecLin_add [Fintype n] (M N : Matrix m n R) : (M + N).mulVecLin = M.mulVecLin + N.mulVecLin := LinearMap.ext fun _ ↦ add_mulVec _ _ _ @[simp] theorem Matrix.mulVecLin_transpose [Fintype m] (M : Matrix m n R) : Mᵀ.mulVecLin = M.vecMulLinear := by ext; simp [mulVec_transpose] @[simp] theorem Matrix.vecMulLinear_transpose [Fintype n] (M : Matrix m n R) : Mᵀ.vecMulLinear = M.mulVecLin := by ext; simp [vecMul_transpose] theorem Matrix.mulVecLin_submatrix [Fintype n] [Fintype l] (f₁ : m → k) (e₂ : n ≃ l) (M : Matrix k l R) : (M.submatrix f₁ e₂).mulVecLin = funLeft R R f₁ ∘ₗ M.mulVecLin ∘ₗ funLeft _ _ e₂.symm := LinearMap.ext fun _ ↦ submatrix_mulVec_equiv _ _ _ _ /-- A variant of `Matrix.mulVecLin_submatrix` that keeps around `LinearEquiv`s. -/ theorem Matrix.mulVecLin_reindex [Fintype n] [Fintype l] (e₁ : k ≃ m) (e₂ : l ≃ n) (M : Matrix k l R) : (reindex e₁ e₂ M).mulVecLin = ↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ M.mulVecLin ∘ₗ ↑(LinearEquiv.funCongrLeft R R e₂) := Matrix.mulVecLin_submatrix _ _ _ variable [Fintype n] @[simp] theorem Matrix.mulVecLin_one [DecidableEq n] : Matrix.mulVecLin (1 : Matrix n n R) = LinearMap.id := by ext; simp [Matrix.one_apply, Pi.single_apply, eq_comm] @[simp] theorem Matrix.mulVecLin_mul [Fintype m] (M : Matrix l m R) (N : Matrix m n R) : Matrix.mulVecLin (M * N) = (Matrix.mulVecLin M).comp (Matrix.mulVecLin N) := LinearMap.ext fun _ ↦ (mulVec_mulVec _ _ _).symm theorem Matrix.ker_mulVecLin_eq_bot_iff {M : Matrix m n R} : (LinearMap.ker M.mulVecLin) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 := by simp only [Submodule.eq_bot_iff, LinearMap.mem_ker, Matrix.mulVecLin_apply] theorem Matrix.range_mulVecLin (M : Matrix m n R) : LinearMap.range M.mulVecLin = span R (range M.col) := by rw [← vecMulLinear_transpose, range_vecMulLinear, row_transpose] theorem Matrix.mulVec_injective_iff {R : Type*} [CommRing R] {M : Matrix m n R} : Function.Injective M.mulVec ↔ LinearIndependent R M.col := by change Function.Injective (fun x ↦ _) ↔ _ simp_rw [← M.vecMul_transpose, vecMul_injective_iff, row_transpose] lemma Matrix.linearIndependent_cols_of_isUnit {R : Type*} [CommRing R] [Fintype m] {A : Matrix m m R} [DecidableEq m] (ha : IsUnit A) : LinearIndependent R A.col := by rw [← Matrix.mulVec_injective_iff] exact Matrix.mulVec_injective_of_isUnit ha end mulVec section ToMatrix' variable {R : Type*} [CommSemiring R] variable {k l m n : Type*} [DecidableEq n] [Fintype n] /-- Linear maps `(n → R) →ₗ[R] (m → R)` are linearly equivalent to `Matrix m n R`. -/ def LinearMap.toMatrix' : ((n → R) →ₗ[R] m → R) ≃ₗ[R] Matrix m n R where toFun f := of fun i j ↦ f (Pi.single j 1) i invFun := Matrix.mulVecLin right_inv M := by ext i j simp only [Matrix.mulVec_single_one, Matrix.mulVecLin_apply, of_apply, transpose_apply] left_inv f := by apply (Pi.basisFun R n).ext intro j; ext i simp only [Pi.basisFun_apply, Matrix.mulVec_single_one, Matrix.mulVecLin_apply, of_apply, transpose_apply] map_add' f g := by ext i j simp only [Pi.add_apply, LinearMap.add_apply, of_apply, Matrix.add_apply] map_smul' c f := by ext i j simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, of_apply, Matrix.smul_apply] /-- A `Matrix m n R` is linearly equivalent to a linear map `(n → R) →ₗ[R] (m → R)`. Note that the forward-direction does not require `DecidableEq` and is `Matrix.vecMulLin`. -/ def Matrix.toLin' : Matrix m n R ≃ₗ[R] (n → R) →ₗ[R] m → R := LinearMap.toMatrix'.symm theorem Matrix.toLin'_apply' (M : Matrix m n R) : Matrix.toLin' M = M.mulVecLin := rfl @[simp] theorem LinearMap.toMatrix'_symm : (LinearMap.toMatrix'.symm : Matrix m n R ≃ₗ[R] _) = Matrix.toLin' := rfl @[simp] theorem Matrix.toLin'_symm : (Matrix.toLin'.symm : ((n → R) →ₗ[R] m → R) ≃ₗ[R] _) = LinearMap.toMatrix' := rfl @[simp] theorem LinearMap.toMatrix'_toLin' (M : Matrix m n R) : LinearMap.toMatrix' (Matrix.toLin' M) = M := LinearMap.toMatrix'.apply_symm_apply M @[simp] theorem Matrix.toLin'_toMatrix' (f : (n → R) →ₗ[R] m → R) : Matrix.toLin' (LinearMap.toMatrix' f) = f := Matrix.toLin'.apply_symm_apply f @[simp] theorem LinearMap.toMatrix'_apply (f : (n → R) →ₗ[R] m → R) (i j) : LinearMap.toMatrix' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by simp only [LinearMap.toMatrix', LinearEquiv.coe_mk, of_apply] congr! with i split_ifs with h · rw [h, Pi.single_eq_same] apply Pi.single_eq_of_ne h @[simp] theorem Matrix.toLin'_apply (M : Matrix m n R) (v : n → R) : Matrix.toLin' M v = M *ᵥ v := rfl @[simp] theorem Matrix.toLin'_one : Matrix.toLin' (1 : Matrix n n R) = LinearMap.id := Matrix.mulVecLin_one @[simp] theorem LinearMap.toMatrix'_id : LinearMap.toMatrix' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 := by ext rw [Matrix.one_apply, LinearMap.toMatrix'_apply, id_apply] @[simp] theorem LinearMap.toMatrix'_one : LinearMap.toMatrix' (1 : (n → R) →ₗ[R] n → R) = 1 := LinearMap.toMatrix'_id @[simp] theorem Matrix.toLin'_mul [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R) : Matrix.toLin' (M * N) = (Matrix.toLin' M).comp (Matrix.toLin' N) := Matrix.mulVecLin_mul _ _ @[simp] theorem Matrix.toLin'_submatrix [Fintype l] [DecidableEq l] (f₁ : m → k) (e₂ : n ≃ l) (M : Matrix k l R) : Matrix.toLin' (M.submatrix f₁ e₂) = funLeft R R f₁ ∘ₗ (Matrix.toLin' M) ∘ₗ funLeft _ _ e₂.symm := Matrix.mulVecLin_submatrix _ _ _ /-- A variant of `Matrix.toLin'_submatrix` that keeps around `LinearEquiv`s. -/ theorem Matrix.toLin'_reindex [Fintype l] [DecidableEq l] (e₁ : k ≃ m) (e₂ : l ≃ n) (M : Matrix k l R) : Matrix.toLin' (reindex e₁ e₂ M) = ↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ (Matrix.toLin' M) ∘ₗ ↑(LinearEquiv.funCongrLeft R R e₂) := Matrix.mulVecLin_reindex _ _ _ /-- Shortcut lemma for `Matrix.toLin'_mul` and `LinearMap.comp_apply` -/ theorem Matrix.toLin'_mul_apply [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R) (x) : Matrix.toLin' (M * N) x = Matrix.toLin' M (Matrix.toLin' N x) := by rw [Matrix.toLin'_mul, LinearMap.comp_apply] theorem LinearMap.toMatrix'_comp [Fintype l] [DecidableEq l] (f : (n → R) →ₗ[R] m → R) (g : (l → R) →ₗ[R] n → R) : LinearMap.toMatrix' (f.comp g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g := by suffices f.comp g = Matrix.toLin' (LinearMap.toMatrix' f * LinearMap.toMatrix' g) by rw [this, LinearMap.toMatrix'_toLin'] rw [Matrix.toLin'_mul, Matrix.toLin'_toMatrix', Matrix.toLin'_toMatrix'] theorem LinearMap.toMatrix'_mul [Fintype m] [DecidableEq m] (f g : (m → R) →ₗ[R] m → R) : LinearMap.toMatrix' (f * g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g := LinearMap.toMatrix'_comp f g @[simp] theorem LinearMap.toMatrix'_algebraMap (x : R) : LinearMap.toMatrix' (algebraMap R (Module.End R (n → R)) x) = scalar n x := by simp [Module.algebraMap_end_eq_smul_id, smul_eq_diagonal_mul] theorem Matrix.ker_toLin'_eq_bot_iff {M : Matrix n n R} : LinearMap.ker (Matrix.toLin' M) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 := Matrix.ker_mulVecLin_eq_bot_iff theorem Matrix.range_toLin' (M : Matrix m n R) : LinearMap.range (Matrix.toLin' M) = span R (range M.col) := Matrix.range_mulVecLin _ /-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `m → A` and `n → A` corresponding to `M.mulVec` and `M'.mulVec`. -/ @[simps] def Matrix.toLin'OfInv [Fintype m] [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (m → R) ≃ₗ[R] n → R := { Matrix.toLin' M' with toFun := Matrix.toLin' M' invFun := Matrix.toLin' M left_inv := fun x ↦ by rw [← Matrix.toLin'_mul_apply, hMM', Matrix.toLin'_one, id_apply] right_inv := fun x ↦ by rw [← Matrix.toLin'_mul_apply, hM'M, Matrix.toLin'_one, id_apply] } /-- Linear maps `(n → R) →ₗ[R] (n → R)` are algebra equivalent to `Matrix n n R`. -/ def LinearMap.toMatrixAlgEquiv' : ((n → R) →ₗ[R] n → R) ≃ₐ[R] Matrix n n R := AlgEquiv.ofLinearEquiv LinearMap.toMatrix' LinearMap.toMatrix'_one LinearMap.toMatrix'_mul /-- A `Matrix n n R` is algebra equivalent to a linear map `(n → R) →ₗ[R] (n → R)`. -/ def Matrix.toLinAlgEquiv' : Matrix n n R ≃ₐ[R] (n → R) →ₗ[R] n → R := LinearMap.toMatrixAlgEquiv'.symm @[simp] theorem LinearMap.toMatrixAlgEquiv'_symm : (LinearMap.toMatrixAlgEquiv'.symm : Matrix n n R ≃ₐ[R] _) = Matrix.toLinAlgEquiv' := rfl @[simp] theorem Matrix.toLinAlgEquiv'_symm : (Matrix.toLinAlgEquiv'.symm : ((n → R) →ₗ[R] n → R) ≃ₐ[R] _) = LinearMap.toMatrixAlgEquiv' := rfl @[simp] theorem LinearMap.toMatrixAlgEquiv'_toLinAlgEquiv' (M : Matrix n n R) : LinearMap.toMatrixAlgEquiv' (Matrix.toLinAlgEquiv' M) = M := LinearMap.toMatrixAlgEquiv'.apply_symm_apply M @[simp] theorem Matrix.toLinAlgEquiv'_toMatrixAlgEquiv' (f : (n → R) →ₗ[R] n → R) : Matrix.toLinAlgEquiv' (LinearMap.toMatrixAlgEquiv' f) = f := Matrix.toLinAlgEquiv'.apply_symm_apply f @[simp] theorem LinearMap.toMatrixAlgEquiv'_apply (f : (n → R) →ₗ[R] n → R) (i j) : LinearMap.toMatrixAlgEquiv' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by simp [LinearMap.toMatrixAlgEquiv'] @[simp] theorem Matrix.toLinAlgEquiv'_apply (M : Matrix n n R) (v : n → R) : Matrix.toLinAlgEquiv' M v = M *ᵥ v := rfl theorem Matrix.toLinAlgEquiv'_one : Matrix.toLinAlgEquiv' (1 : Matrix n n R) = LinearMap.id := Matrix.toLin'_one @[simp] theorem LinearMap.toMatrixAlgEquiv'_id : LinearMap.toMatrixAlgEquiv' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 := LinearMap.toMatrix'_id theorem LinearMap.toMatrixAlgEquiv'_comp (f g : (n → R) →ₗ[R] n → R) : LinearMap.toMatrixAlgEquiv' (f.comp g) = LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g := LinearMap.toMatrix'_comp _ _ theorem LinearMap.toMatrixAlgEquiv'_mul (f g : (n → R) →ₗ[R] n → R) : LinearMap.toMatrixAlgEquiv' (f * g) = LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g := LinearMap.toMatrixAlgEquiv'_comp f g end ToMatrix' section ToMatrix section Finite variable {R : Type*} [CommSemiring R] variable {l m n : Type*} [Fintype n] [Finite m] [DecidableEq n] variable {M₁ M₂ : Type*} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] variable (v₁ : Basis n R M₁) (v₂ : Basis m R M₂) /-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear equivalence between linear maps `M₁ →ₗ M₂` and matrices over `R` indexed by the bases. -/ def LinearMap.toMatrix : (M₁ →ₗ[R] M₂) ≃ₗ[R] Matrix m n R := LinearEquiv.trans (LinearEquiv.arrowCongr v₁.equivFun v₂.equivFun) LinearMap.toMatrix' /-- `LinearMap.toMatrix'` is a particular case of `LinearMap.toMatrix`, for the standard basis `Pi.basisFun R n`. -/ theorem LinearMap.toMatrix_eq_toMatrix' : LinearMap.toMatrix (Pi.basisFun R n) (Pi.basisFun R n) = LinearMap.toMatrix' := rfl /-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear equivalence between matrices over `R` indexed by the bases and linear maps `M₁ →ₗ M₂`. -/ def Matrix.toLin : Matrix m n R ≃ₗ[R] M₁ →ₗ[R] M₂ := (LinearMap.toMatrix v₁ v₂).symm /-- `Matrix.toLin'` is a particular case of `Matrix.toLin`, for the standard basis `Pi.basisFun R n`. -/ theorem Matrix.toLin_eq_toLin' : Matrix.toLin (Pi.basisFun R n) (Pi.basisFun R m) = Matrix.toLin' := rfl @[simp] theorem LinearMap.toMatrix_symm : (LinearMap.toMatrix v₁ v₂).symm = Matrix.toLin v₁ v₂ := rfl @[simp] theorem Matrix.toLin_symm : (Matrix.toLin v₁ v₂).symm = LinearMap.toMatrix v₁ v₂ := rfl @[simp] theorem Matrix.toLin_toMatrix (f : M₁ →ₗ[R] M₂) : Matrix.toLin v₁ v₂ (LinearMap.toMatrix v₁ v₂ f) = f := by rw [← Matrix.toLin_symm, LinearEquiv.apply_symm_apply] @[simp] theorem LinearMap.toMatrix_toLin (M : Matrix m n R) : LinearMap.toMatrix v₁ v₂ (Matrix.toLin v₁ v₂ M) = M := by rw [← Matrix.toLin_symm, LinearEquiv.symm_apply_apply] theorem LinearMap.toMatrix_apply (f : M₁ →ₗ[R] M₂) (i : m) (j : n) : LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i := by rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearMap.toMatrix'_apply, LinearEquiv.arrowCongr_apply, Basis.equivFun_symm_apply, Finset.sum_eq_single j, if_pos rfl, one_smul, Basis.equivFun_apply] · intro j' _ hj' rw [if_neg hj', zero_smul] · intro hj have := Finset.mem_univ j contradiction theorem LinearMap.toMatrix_transpose_apply (f : M₁ →ₗ[R] M₂) (j : n) : (LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) := funext fun i ↦ f.toMatrix_apply _ _ i j theorem LinearMap.toMatrix_apply' (f : M₁ →ₗ[R] M₂) (i : m) (j : n) : LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i := LinearMap.toMatrix_apply v₁ v₂ f i j theorem LinearMap.toMatrix_transpose_apply' (f : M₁ →ₗ[R] M₂) (j : n) : (LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) := LinearMap.toMatrix_transpose_apply v₁ v₂ f j /-- This will be a special case of `LinearMap.toMatrix_id_eq_basis_toMatrix`. -/ theorem LinearMap.toMatrix_id : LinearMap.toMatrix v₁ v₁ id = 1 := by ext i j simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm] @[simp] theorem LinearMap.toMatrix_one : LinearMap.toMatrix v₁ v₁ 1 = 1 := LinearMap.toMatrix_id v₁ @[simp] lemma LinearMap.toMatrix_singleton {ι : Type*} [Unique ι] (f : R →ₗ[R] R) (i j : ι) : f.toMatrix (.singleton ι R) (.singleton ι R) i j = f 1 := by simp [toMatrix, Subsingleton.elim j default] @[simp] theorem Matrix.toLin_one : Matrix.toLin v₁ v₁ 1 = LinearMap.id := by rw [← LinearMap.toMatrix_id v₁, Matrix.toLin_toMatrix] theorem LinearMap.toMatrix_reindexRange [DecidableEq M₁] (f : M₁ →ₗ[R] M₂) (k : m) (i : n) : LinearMap.toMatrix v₁.reindexRange v₂.reindexRange f ⟨v₂ k, Set.mem_range_self k⟩ ⟨v₁ i, Set.mem_range_self i⟩ = LinearMap.toMatrix v₁ v₂ f k i := by simp_rw [LinearMap.toMatrix_apply, Basis.reindexRange_self, Basis.reindexRange_repr] @[simp] theorem LinearMap.toMatrix_algebraMap (x : R) : LinearMap.toMatrix v₁ v₁ (algebraMap R (Module.End R M₁) x) = scalar n x := by simp [Module.algebraMap_end_eq_smul_id, LinearMap.toMatrix_id, smul_eq_diagonal_mul] theorem LinearMap.toMatrix_mulVec_repr (f : M₁ →ₗ[R] M₂) (x : M₁) : LinearMap.toMatrix v₁ v₂ f *ᵥ v₁.repr x = v₂.repr (f x) := by ext i rw [← Matrix.toLin'_apply, LinearMap.toMatrix, LinearEquiv.trans_apply, Matrix.toLin'_toMatrix', LinearEquiv.arrowCongr_apply, v₂.equivFun_apply] congr exact v₁.equivFun.symm_apply_apply x @[simp] theorem LinearMap.toMatrix_basis_equiv [Fintype l] [DecidableEq l] (b : Basis l R M₁) (b' : Basis l R M₂) : LinearMap.toMatrix b' b (b'.equiv b (Equiv.refl l) : M₂ →ₗ[R] M₁) = 1 := by ext i j simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm] theorem LinearMap.toMatrix_smulBasis_left {G} [Group G] [DistribMulAction G M₁] [SMulCommClass G R M₁] (g : G) (f : M₁ →ₗ[R] M₂) : LinearMap.toMatrix (g • v₁) v₂ f = LinearMap.toMatrix v₁ v₂ (f ∘ₗ DistribMulAction.toLinearMap _ _ g) := by ext rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply] dsimp theorem LinearMap.toMatrix_smulBasis_right {G} [Group G] [DistribMulAction G M₂] [SMulCommClass G R M₂] (g : G) (f : M₁ →ₗ[R] M₂) : LinearMap.toMatrix v₁ (g • v₂) f = LinearMap.toMatrix v₁ v₂ (DistribMulAction.toLinearMap _ _ g⁻¹ ∘ₗ f) := by ext rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply] dsimp end Finite variable {R : Type*} [CommSemiring R] variable {l m n : Type*} [Fintype n] [Fintype m] [DecidableEq n] variable {M₁ M₂ : Type*} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] variable (v₁ : Basis n R M₁) (v₂ : Basis m R M₂) theorem Matrix.toLin_apply (M : Matrix m n R) (v : M₁) : Matrix.toLin v₁ v₂ M v = ∑ j, (M *ᵥ v₁.repr v) j • v₂ j := show v₂.equivFun.symm (Matrix.toLin' M (v₁.repr v)) = _ by rw [Matrix.toLin'_apply, v₂.equivFun_symm_apply] @[simp] theorem Matrix.toLin_self (M : Matrix m n R) (i : n) : Matrix.toLin v₁ v₂ M (v₁ i) = ∑ j, M j i • v₂ j := by rw [Matrix.toLin_apply, Finset.sum_congr rfl fun j _hj ↦ ?_] rw [Basis.repr_self, Matrix.mulVec, dotProduct, Finset.sum_eq_single i, Finsupp.single_eq_same, mul_one] · intro i' _ i'_ne rw [Finsupp.single_eq_of_ne i'_ne.symm, mul_zero] · intros have := Finset.mem_univ i contradiction variable {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (v₃ : Basis l R M₃) theorem LinearMap.toMatrix_comp [Finite l] [DecidableEq m] (f : M₂ →ₗ[R] M₃) (g : M₁ →ₗ[R] M₂) : LinearMap.toMatrix v₁ v₃ (f.comp g) = LinearMap.toMatrix v₂ v₃ f * LinearMap.toMatrix v₁ v₂ g := by simp_rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearEquiv.arrowCongr_comp _ v₂.equivFun, LinearMap.toMatrix'_comp] theorem LinearMap.toMatrix_mul (f g : M₁ →ₗ[R] M₁) : LinearMap.toMatrix v₁ v₁ (f * g) = LinearMap.toMatrix v₁ v₁ f * LinearMap.toMatrix v₁ v₁ g := by rw [Module.End.mul_eq_comp, LinearMap.toMatrix_comp v₁ v₁ v₁ f g] lemma LinearMap.toMatrix_pow (f : M₁ →ₗ[R] M₁) (k : ℕ) : (toMatrix v₁ v₁ f) ^ k = toMatrix v₁ v₁ (f ^ k) := by induction k with | zero => simp | succ k ih => rw [pow_succ, pow_succ, ih, ← toMatrix_mul] theorem Matrix.toLin_mul [Finite l] [DecidableEq m] (A : Matrix l m R) (B : Matrix m n R) : Matrix.toLin v₁ v₃ (A * B) = (Matrix.toLin v₂ v₃ A).comp (Matrix.toLin v₁ v₂ B) := by apply (LinearMap.toMatrix v₁ v₃).injective haveI : DecidableEq l := fun _ _ ↦ Classical.propDecidable _ rw [LinearMap.toMatrix_comp v₁ v₂ v₃] repeat' rw [LinearMap.toMatrix_toLin] /-- Shortcut lemma for `Matrix.toLin_mul` and `LinearMap.comp_apply`. -/ theorem Matrix.toLin_mul_apply [Finite l] [DecidableEq m] (A : Matrix l m R) (B : Matrix m n R) (x) : Matrix.toLin v₁ v₃ (A * B) x = (Matrix.toLin v₂ v₃ A) (Matrix.toLin v₁ v₂ B x) := by rw [Matrix.toLin_mul v₁ v₂, LinearMap.comp_apply] /-- If `M` and `M` are each other's inverse matrices, `Matrix.toLin M` and `Matrix.toLin M'` form a linear equivalence. -/ @[simps] def Matrix.toLinOfInv [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : M₁ ≃ₗ[R] M₂ := { Matrix.toLin v₁ v₂ M with toFun := Matrix.toLin v₁ v₂ M invFun := Matrix.toLin v₂ v₁ M' left_inv := fun x ↦ by rw [← Matrix.toLin_mul_apply, hM'M, Matrix.toLin_one, id_apply] right_inv := fun x ↦ by rw [← Matrix.toLin_mul_apply, hMM', Matrix.toLin_one, id_apply] } /-- Given a basis of a module `M₁` over a commutative ring `R`, we get an algebra equivalence between linear maps `M₁ →ₗ M₁` and square matrices over `R` indexed by the basis. -/ def LinearMap.toMatrixAlgEquiv : (M₁ →ₗ[R] M₁) ≃ₐ[R] Matrix n n R := AlgEquiv.ofLinearEquiv (LinearMap.toMatrix v₁ v₁) (LinearMap.toMatrix_one v₁) (LinearMap.toMatrix_mul v₁) /-- Given a basis of a module `M₁` over a commutative ring `R`, we get an algebra equivalence between square matrices over `R` indexed by the basis and linear maps `M₁ →ₗ M₁`. -/ def Matrix.toLinAlgEquiv : Matrix n n R ≃ₐ[R] M₁ →ₗ[R] M₁ := (LinearMap.toMatrixAlgEquiv v₁).symm @[simp] theorem LinearMap.toMatrixAlgEquiv_symm : (LinearMap.toMatrixAlgEquiv v₁).symm = Matrix.toLinAlgEquiv v₁ := rfl @[simp] theorem Matrix.toLinAlgEquiv_symm : (Matrix.toLinAlgEquiv v₁).symm = LinearMap.toMatrixAlgEquiv v₁ := rfl @[simp] theorem Matrix.toLinAlgEquiv_toMatrixAlgEquiv (f : M₁ →ₗ[R] M₁) : Matrix.toLinAlgEquiv v₁ (LinearMap.toMatrixAlgEquiv v₁ f) = f := by rw [← Matrix.toLinAlgEquiv_symm, AlgEquiv.apply_symm_apply] @[simp] theorem LinearMap.toMatrixAlgEquiv_toLinAlgEquiv (M : Matrix n n R) : LinearMap.toMatrixAlgEquiv v₁ (Matrix.toLinAlgEquiv v₁ M) = M := by rw [← Matrix.toLinAlgEquiv_symm, AlgEquiv.symm_apply_apply] theorem LinearMap.toMatrixAlgEquiv_apply (f : M₁ →ₗ[R] M₁) (i j : n) : LinearMap.toMatrixAlgEquiv v₁ f i j = v₁.repr (f (v₁ j)) i := by simp [LinearMap.toMatrixAlgEquiv, LinearMap.toMatrix_apply] theorem LinearMap.toMatrixAlgEquiv_transpose_apply (f : M₁ →ₗ[R] M₁) (j : n) : (LinearMap.toMatrixAlgEquiv v₁ f)ᵀ j = v₁.repr (f (v₁ j)) := funext fun i ↦ f.toMatrix_apply _ _ i j theorem LinearMap.toMatrixAlgEquiv_apply' (f : M₁ →ₗ[R] M₁) (i j : n) : LinearMap.toMatrixAlgEquiv v₁ f i j = v₁.repr (f (v₁ j)) i := LinearMap.toMatrixAlgEquiv_apply v₁ f i j theorem LinearMap.toMatrixAlgEquiv_transpose_apply' (f : M₁ →ₗ[R] M₁) (j : n) : (LinearMap.toMatrixAlgEquiv v₁ f)ᵀ j = v₁.repr (f (v₁ j)) := LinearMap.toMatrixAlgEquiv_transpose_apply v₁ f j theorem Matrix.toLinAlgEquiv_apply (M : Matrix n n R) (v : M₁) : Matrix.toLinAlgEquiv v₁ M v = ∑ j, (M *ᵥ v₁.repr v) j • v₁ j := show v₁.equivFun.symm (Matrix.toLinAlgEquiv' M (v₁.repr v)) = _ by rw [Matrix.toLinAlgEquiv'_apply, v₁.equivFun_symm_apply] @[simp] theorem Matrix.toLinAlgEquiv_self (M : Matrix n n R) (i : n) : Matrix.toLinAlgEquiv v₁ M (v₁ i) = ∑ j, M j i • v₁ j := Matrix.toLin_self _ _ _ _ theorem LinearMap.toMatrixAlgEquiv_id : LinearMap.toMatrixAlgEquiv v₁ id = 1 := by simp_rw [LinearMap.toMatrixAlgEquiv, AlgEquiv.ofLinearEquiv_apply, LinearMap.toMatrix_id] theorem Matrix.toLinAlgEquiv_one : Matrix.toLinAlgEquiv v₁ 1 = LinearMap.id := by rw [← LinearMap.toMatrixAlgEquiv_id v₁, Matrix.toLinAlgEquiv_toMatrixAlgEquiv] theorem LinearMap.toMatrixAlgEquiv_reindexRange [DecidableEq M₁] (f : M₁ →ₗ[R] M₁) (k i : n) : LinearMap.toMatrixAlgEquiv v₁.reindexRange f ⟨v₁ k, Set.mem_range_self k⟩ ⟨v₁ i, Set.mem_range_self i⟩ = LinearMap.toMatrixAlgEquiv v₁ f k i := by simp_rw [LinearMap.toMatrixAlgEquiv_apply, Basis.reindexRange_self, Basis.reindexRange_repr] theorem LinearMap.toMatrixAlgEquiv_comp (f g : M₁ →ₗ[R] M₁) : LinearMap.toMatrixAlgEquiv v₁ (f.comp g) = LinearMap.toMatrixAlgEquiv v₁ f * LinearMap.toMatrixAlgEquiv v₁ g := by simp [LinearMap.toMatrixAlgEquiv, LinearMap.toMatrix_comp v₁ v₁ v₁ f g] theorem LinearMap.toMatrixAlgEquiv_mul (f g : M₁ →ₗ[R] M₁) : LinearMap.toMatrixAlgEquiv v₁ (f * g) = LinearMap.toMatrixAlgEquiv v₁ f * LinearMap.toMatrixAlgEquiv v₁ g := by rw [Module.End.mul_eq_comp, LinearMap.toMatrixAlgEquiv_comp v₁ f g] theorem Matrix.toLinAlgEquiv_mul (A B : Matrix n n R) : Matrix.toLinAlgEquiv v₁ (A * B) = (Matrix.toLinAlgEquiv v₁ A).comp (Matrix.toLinAlgEquiv v₁ B) := by convert Matrix.toLin_mul v₁ v₁ v₁ A B @[simp] theorem Matrix.toLin_finTwoProd_apply (a b c d : R) (x : R × R) : Matrix.toLin (Basis.finTwoProd R) (Basis.finTwoProd R) !![a, b; c, d] x = (a * x.fst + b * x.snd, c * x.fst + d * x.snd) := by simp [Matrix.toLin_apply, Matrix.mulVec, dotProduct] theorem Matrix.toLin_finTwoProd (a b c d : R) : Matrix.toLin (Basis.finTwoProd R) (Basis.finTwoProd R) !![a, b; c, d] = (a • LinearMap.fst R R R + b • LinearMap.snd R R R).prod (c • LinearMap.fst R R R + d • LinearMap.snd R R R) := LinearMap.ext <| Matrix.toLin_finTwoProd_apply _ _ _ _ @[simp] theorem toMatrix_distrib_mul_action_toLinearMap (x : R) : LinearMap.toMatrix v₁ v₁ (DistribMulAction.toLinearMap R M₁ x) = Matrix.diagonal fun _ ↦ x := by ext rw [LinearMap.toMatrix_apply, DistribMulAction.toLinearMap_apply, LinearEquiv.map_smul, Basis.repr_self, Finsupp.smul_single_one, Finsupp.single_eq_pi_single, Matrix.diagonal_apply, Pi.single_apply] lemma LinearMap.toMatrix_prodMap [DecidableEq m] [DecidableEq (n ⊕ m)] (φ₁ : Module.End R M₁) (φ₂ : Module.End R M₂) : toMatrix (v₁.prod v₂) (v₁.prod v₂) (φ₁.prodMap φ₂) = Matrix.fromBlocks (toMatrix v₁ v₁ φ₁) 0 0 (toMatrix v₂ v₂ φ₂) := by ext (i|i) (j|j) <;> simp [toMatrix] end ToMatrix namespace Algebra section Lmul variable {R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S] variable {m : Type*} [Fintype m] [DecidableEq m] (b : Basis m R S) theorem toMatrix_lmul' (x : S) (i j) : LinearMap.toMatrix b b (lmul R S x) i j = b.repr (x * b j) i := by simp only [LinearMap.toMatrix_apply', coe_lmul_eq_mul, LinearMap.mul_apply'] @[simp] theorem toMatrix_lsmul (x : R) : LinearMap.toMatrix b b (Algebra.lsmul R R S x) = Matrix.diagonal fun _ ↦ x := toMatrix_distrib_mul_action_toLinearMap b x /-- `leftMulMatrix b x` is the matrix corresponding to the linear map `fun y ↦ x * y`. `leftMulMatrix_eq_repr_mul` gives a formula for the entries of `leftMulMatrix`. This definition is useful for doing (more) explicit computations with `LinearMap.mulLeft`, such as the trace form or norm map for algebras. -/ noncomputable def leftMulMatrix : S →ₐ[R] Matrix m m R where toFun x := LinearMap.toMatrix b b (Algebra.lmul R S x) map_zero' := by
rw [map_zero, LinearEquiv.map_zero] map_one' := by
Mathlib/LinearAlgebra/Matrix/ToLin.lean
809
810
/- 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
1,053
1,054
/- 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, Julian Kuelshammer -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Algebra.Group.Pointwise.Set.Finite import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Algebra.Module.NatInt import Mathlib.Algebra.Order.Group.Action import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Data.Int.ModEq import Mathlib.Dynamics.PeriodicPts.Lemmas import Mathlib.GroupTheory.Index import Mathlib.NumberTheory.Divisors import Mathlib.Order.Interval.Set.Infinite /-! # Order of an element This file defines the order of an element of a finite group. For a finite group `G` the order of `x ∈ G` is the minimal `n ≥ 1` such that `x ^ n = 1`. ## Main definitions * `IsOfFinOrder` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite order. * `IsOfFinAddOrder` is the additive analogue of `IsOfFinOrder`. * `orderOf x` defines the order of an element `x` of a monoid `G`, by convention its value is `0` if `x` has infinite order. * `addOrderOf` is the additive analogue of `orderOf`. ## Tags order of an element -/ assert_not_exists Field open Function Fintype Nat Pointwise Subgroup Submonoid open scoped Finset variable {G H A α β : Type*} section Monoid variable [Monoid G] {a b x y : G} {n m : ℕ} section IsOfFinOrder -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed @[to_additive] theorem isPeriodicPt_mul_iff_pow_eq_one (x : G) : IsPeriodicPt (x * ·) n 1 ↔ x ^ n = 1 := by rw [IsPeriodicPt, IsFixedPt, mul_left_iterate]; beta_reduce; rw [mul_one] /-- `IsOfFinOrder` is a predicate on an element `x` of a monoid to be of finite order, i.e. there exists `n ≥ 1` such that `x ^ n = 1`. -/ @[to_additive "`IsOfFinAddOrder` is a predicate on an element `a` of an additive monoid to be of finite order, i.e. there exists `n ≥ 1` such that `n • a = 0`."] def IsOfFinOrder (x : G) : Prop := (1 : G) ∈ periodicPts (x * ·) theorem isOfFinAddOrder_ofMul_iff : IsOfFinAddOrder (Additive.ofMul x) ↔ IsOfFinOrder x := Iff.rfl theorem isOfFinOrder_ofAdd_iff {α : Type*} [AddMonoid α] {x : α} : IsOfFinOrder (Multiplicative.ofAdd x) ↔ IsOfFinAddOrder x := Iff.rfl @[to_additive] theorem isOfFinOrder_iff_pow_eq_one : IsOfFinOrder x ↔ ∃ n, 0 < n ∧ x ^ n = 1 := by simp [IsOfFinOrder, mem_periodicPts, isPeriodicPt_mul_iff_pow_eq_one] @[to_additive] alias ⟨IsOfFinOrder.exists_pow_eq_one, _⟩ := isOfFinOrder_iff_pow_eq_one @[to_additive] lemma isOfFinOrder_iff_zpow_eq_one {G} [DivisionMonoid G] {x : G} : IsOfFinOrder x ↔ ∃ (n : ℤ), n ≠ 0 ∧ x ^ n = 1 := by rw [isOfFinOrder_iff_pow_eq_one] refine ⟨fun ⟨n, hn, hn'⟩ ↦ ⟨n, Int.natCast_ne_zero_iff_pos.mpr hn, zpow_natCast x n ▸ hn'⟩, fun ⟨n, hn, hn'⟩ ↦ ⟨n.natAbs, Int.natAbs_pos.mpr hn, ?_⟩⟩ rcases (Int.natAbs_eq_iff (a := n)).mp rfl with h | h · rwa [h, zpow_natCast] at hn' · rwa [h, zpow_neg, inv_eq_one, zpow_natCast] at hn' /-- See also `injective_pow_iff_not_isOfFinOrder`. -/ @[to_additive "See also `injective_nsmul_iff_not_isOfFinAddOrder`."] theorem not_isOfFinOrder_of_injective_pow {x : G} (h : Injective fun n : ℕ => x ^ n) : ¬IsOfFinOrder x := by simp_rw [isOfFinOrder_iff_pow_eq_one, not_exists, not_and] intro n hn_pos hnx rw [← pow_zero x] at hnx rw [h hnx] at hn_pos exact irrefl 0 hn_pos /-- 1 is of finite order in any monoid. -/ @[to_additive (attr := simp) "0 is of finite order in any additive monoid."] theorem IsOfFinOrder.one : IsOfFinOrder (1 : G) := isOfFinOrder_iff_pow_eq_one.mpr ⟨1, Nat.one_pos, one_pow 1⟩ @[to_additive] lemma IsOfFinOrder.pow {n : ℕ} : IsOfFinOrder a → IsOfFinOrder (a ^ n) := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨m, hm, ha⟩ exact ⟨m, hm, by simp [pow_right_comm _ n, ha]⟩ @[to_additive] lemma IsOfFinOrder.of_pow {n : ℕ} (h : IsOfFinOrder (a ^ n)) (hn : n ≠ 0) : IsOfFinOrder a := by rw [isOfFinOrder_iff_pow_eq_one] at * rcases h with ⟨m, hm, ha⟩ exact ⟨n * m, mul_pos hn.bot_lt hm, by rwa [pow_mul]⟩ @[to_additive (attr := simp)] lemma isOfFinOrder_pow {n : ℕ} : IsOfFinOrder (a ^ n) ↔ IsOfFinOrder a ∨ n = 0 := by rcases Decidable.eq_or_ne n 0 with rfl | hn · simp · exact ⟨fun h ↦ .inl <| h.of_pow hn, fun h ↦ (h.resolve_right hn).pow⟩ /-- Elements of finite order are of finite order in submonoids. -/ @[to_additive "Elements of finite order are of finite order in submonoids."] theorem Submonoid.isOfFinOrder_coe {H : Submonoid G} {x : H} : IsOfFinOrder (x : G) ↔ IsOfFinOrder x := by rw [isOfFinOrder_iff_pow_eq_one, isOfFinOrder_iff_pow_eq_one] norm_cast theorem IsConj.isOfFinOrder (h : IsConj x y) : IsOfFinOrder x → IsOfFinOrder y := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨n, n_gt_0, eq'⟩ exact ⟨n, n_gt_0, by rw [← isConj_one_right, ← eq']; exact h.pow n⟩ /-- The image of an element of finite order has finite order. -/ @[to_additive "The image of an element of finite additive order has finite additive order."] theorem MonoidHom.isOfFinOrder [Monoid H] (f : G →* H) {x : G} (h : IsOfFinOrder x) : IsOfFinOrder <| f x := isOfFinOrder_iff_pow_eq_one.mpr <| by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact ⟨n, npos, by rw [← f.map_pow, hn, f.map_one]⟩ /-- If a direct product has finite order then so does each component. -/ @[to_additive "If a direct product has finite additive order then so does each component."] theorem IsOfFinOrder.apply {η : Type*} {Gs : η → Type*} [∀ i, Monoid (Gs i)] {x : ∀ i, Gs i} (h : IsOfFinOrder x) : ∀ i, IsOfFinOrder (x i) := by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact fun _ => isOfFinOrder_iff_pow_eq_one.mpr ⟨n, npos, (congr_fun hn.symm _).symm⟩ /-- The submonoid generated by an element is a group if that element has finite order. -/ @[to_additive "The additive submonoid generated by an element is an additive group if that element has finite order."] noncomputable abbrev IsOfFinOrder.groupPowers (hx : IsOfFinOrder x) : Group (Submonoid.powers x) := by obtain ⟨hpos, hx⟩ := hx.exists_pow_eq_one.choose_spec exact Submonoid.groupPowers hpos hx end IsOfFinOrder /-- `orderOf x` is the order of the element `x`, i.e. the `n ≥ 1`, s.t. `x ^ n = 1` if it exists. Otherwise, i.e. if `x` is of infinite order, then `orderOf x` is `0` by convention. -/ @[to_additive "`addOrderOf a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `n • a = 0` if it exists. Otherwise, i.e. if `a` is of infinite order, then `addOrderOf a` is `0` by convention."] noncomputable def orderOf (x : G) : ℕ := minimalPeriod (x * ·) 1 @[simp] theorem addOrderOf_ofMul_eq_orderOf (x : G) : addOrderOf (Additive.ofMul x) = orderOf x := rfl @[simp] lemma orderOf_ofAdd_eq_addOrderOf {α : Type*} [AddMonoid α] (a : α) : orderOf (Multiplicative.ofAdd a) = addOrderOf a := rfl @[to_additive] protected lemma IsOfFinOrder.orderOf_pos (h : IsOfFinOrder x) : 0 < orderOf x := minimalPeriod_pos_of_mem_periodicPts h @[to_additive addOrderOf_nsmul_eq_zero] theorem pow_orderOf_eq_one (x : G) : x ^ orderOf x = 1 := by convert Eq.trans _ (isPeriodicPt_minimalPeriod (x * ·) 1) -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed in the middle of the rewrite rw [orderOf, mul_left_iterate]; beta_reduce; rw [mul_one] @[to_additive] theorem orderOf_eq_zero (h : ¬IsOfFinOrder x) : orderOf x = 0 := by rwa [orderOf, minimalPeriod, dif_neg] @[to_additive] theorem orderOf_eq_zero_iff : orderOf x = 0 ↔ ¬IsOfFinOrder x := ⟨fun h H ↦ H.orderOf_pos.ne' h, orderOf_eq_zero⟩ @[to_additive] theorem orderOf_eq_zero_iff' : orderOf x = 0 ↔ ∀ n : ℕ, 0 < n → x ^ n ≠ 1 := by simp_rw [orderOf_eq_zero_iff, isOfFinOrder_iff_pow_eq_one, not_exists, not_and] @[to_additive] theorem orderOf_eq_iff {n} (h : 0 < n) : orderOf x = n ↔ x ^ n = 1 ∧ ∀ m, m < n → 0 < m → x ^ m ≠ 1 := by simp_rw [Ne, ← isPeriodicPt_mul_iff_pow_eq_one, orderOf, minimalPeriod] split_ifs with h1 · classical rw [find_eq_iff] simp only [h, true_and] push_neg rfl · rw [iff_false_left h.ne] rintro ⟨h', -⟩ exact h1 ⟨n, h, h'⟩ /-- A group element has finite order iff its order is positive. -/ @[to_additive "A group element has finite additive order iff its order is positive."] theorem orderOf_pos_iff : 0 < orderOf x ↔ IsOfFinOrder x := by rw [iff_not_comm.mp orderOf_eq_zero_iff, pos_iff_ne_zero] @[to_additive] theorem IsOfFinOrder.mono [Monoid β] {y : β} (hx : IsOfFinOrder x) (h : orderOf y ∣ orderOf x) : IsOfFinOrder y := by rw [← orderOf_pos_iff] at hx ⊢; exact Nat.pos_of_dvd_of_pos h hx @[to_additive] theorem pow_ne_one_of_lt_orderOf (n0 : n ≠ 0) (h : n < orderOf x) : x ^ n ≠ 1 := fun j => not_isPeriodicPt_of_pos_of_lt_minimalPeriod n0 h ((isPeriodicPt_mul_iff_pow_eq_one x).mpr j) @[to_additive] theorem orderOf_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : orderOf x ≤ n := IsPeriodicPt.minimalPeriod_le hn (by rwa [isPeriodicPt_mul_iff_pow_eq_one]) @[to_additive (attr := simp)] theorem orderOf_one : orderOf (1 : G) = 1 := by rw [orderOf, ← minimalPeriod_id (x := (1 : G)), ← one_mul_eq_id] @[to_additive (attr := simp) AddMonoid.addOrderOf_eq_one_iff] theorem orderOf_eq_one_iff : orderOf x = 1 ↔ x = 1 := by rw [orderOf, minimalPeriod_eq_one_iff_isFixedPt, IsFixedPt, mul_one] @[to_additive (attr := simp) mod_addOrderOf_nsmul] lemma pow_mod_orderOf (x : G) (n : ℕ) : x ^ (n % orderOf x) = x ^ n := calc x ^ (n % orderOf x) = x ^ (n % orderOf x + orderOf x * (n / orderOf x)) := by simp [pow_add, pow_mul, pow_orderOf_eq_one] _ = x ^ n := by rw [Nat.mod_add_div] @[to_additive] theorem orderOf_dvd_of_pow_eq_one (h : x ^ n = 1) : orderOf x ∣ n := IsPeriodicPt.minimalPeriod_dvd ((isPeriodicPt_mul_iff_pow_eq_one _).mpr h) @[to_additive] theorem orderOf_dvd_iff_pow_eq_one {n : ℕ} : orderOf x ∣ n ↔ x ^ n = 1 := ⟨fun h => by rw [← pow_mod_orderOf, Nat.mod_eq_zero_of_dvd h, _root_.pow_zero], orderOf_dvd_of_pow_eq_one⟩ @[to_additive addOrderOf_smul_dvd] theorem orderOf_pow_dvd (n : ℕ) : orderOf (x ^ n) ∣ orderOf x := by rw [orderOf_dvd_iff_pow_eq_one, pow_right_comm, pow_orderOf_eq_one, one_pow] @[to_additive] lemma pow_injOn_Iio_orderOf : (Set.Iio <| orderOf x).InjOn (x ^ ·) := by simpa only [mul_left_iterate, mul_one] using iterate_injOn_Iio_minimalPeriod (f := (x * ·)) (x := 1) @[to_additive] protected lemma IsOfFinOrder.mem_powers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : y ∈ Submonoid.powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := Finset.mem_range_iff_mem_finset_range_of_mod_eq' hx.orderOf_pos <| pow_mod_orderOf _ @[to_additive] protected lemma IsOfFinOrder.powers_eq_image_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : (Submonoid.powers x : Set G) = (Finset.range (orderOf x)).image (x ^ ·) := Set.ext fun _ ↦ hx.mem_powers_iff_mem_range_orderOf @[to_additive] theorem pow_eq_one_iff_modEq : x ^ n = 1 ↔ n ≡ 0 [MOD orderOf x] := by rw [modEq_zero_iff_dvd, orderOf_dvd_iff_pow_eq_one] @[to_additive] theorem orderOf_map_dvd {H : Type*} [Monoid H] (ψ : G →* H) (x : G) : orderOf (ψ x) ∣ orderOf x := by apply orderOf_dvd_of_pow_eq_one rw [← map_pow, pow_orderOf_eq_one] apply map_one @[to_additive] theorem exists_pow_eq_self_of_coprime (h : n.Coprime (orderOf x)) : ∃ m : ℕ, (x ^ n) ^ m = x := by by_cases h0 : orderOf x = 0 · rw [h0, coprime_zero_right] at h exact ⟨1, by rw [h, pow_one, pow_one]⟩ by_cases h1 : orderOf x = 1 · exact ⟨0, by rw [orderOf_eq_one_iff.mp h1, one_pow, one_pow]⟩ obtain ⟨m, h⟩ := exists_mul_emod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, h1⟩) exact ⟨m, by rw [← pow_mul, ← pow_mod_orderOf, h, pow_one]⟩ /-- If `x^n = 1`, but `x^(n/p) ≠ 1` for all prime factors `p` of `n`, then `x` has order `n` in `G`. -/ @[to_additive addOrderOf_eq_of_nsmul_and_div_prime_nsmul "If `n * x = 0`, but `n/p * x ≠ 0` for all prime factors `p` of `n`, then `x` has order `n` in `G`."] theorem orderOf_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x ^ n = 1) (hd : ∀ p : ℕ, p.Prime → p ∣ n → x ^ (n / p) ≠ 1) : orderOf x = n := by -- Let `a` be `n/(orderOf x)`, and show `a = 1` obtain ⟨a, ha⟩ := exists_eq_mul_right_of_dvd (orderOf_dvd_of_pow_eq_one hx) suffices a = 1 by simp [this, ha] -- Assume `a` is not one... by_contra h have a_min_fac_dvd_p_sub_one : a.minFac ∣ n := by obtain ⟨b, hb⟩ : ∃ b : ℕ, a = b * a.minFac := exists_eq_mul_left_of_dvd a.minFac_dvd rw [hb, ← mul_assoc] at ha exact Dvd.intro_left (orderOf x * b) ha.symm -- Use the minimum prime factor of `a` as `p`. refine hd a.minFac (Nat.minFac_prime h) a_min_fac_dvd_p_sub_one ?_ rw [← orderOf_dvd_iff_pow_eq_one, Nat.dvd_div_iff_mul_dvd a_min_fac_dvd_p_sub_one, ha, mul_comm, Nat.mul_dvd_mul_iff_left (IsOfFinOrder.orderOf_pos _)] · exact Nat.minFac_dvd a · rw [isOfFinOrder_iff_pow_eq_one] exact Exists.intro n (id ⟨hn, hx⟩) @[to_additive] theorem orderOf_eq_orderOf_iff {H : Type*} [Monoid H] {y : H} : orderOf x = orderOf y ↔ ∀ n : ℕ, x ^ n = 1 ↔ y ^ n = 1 := by simp_rw [← isPeriodicPt_mul_iff_pow_eq_one, ← minimalPeriod_eq_minimalPeriod_iff, orderOf] /-- An injective homomorphism of monoids preserves orders of elements. -/ @[to_additive "An injective homomorphism of additive monoids preserves orders of elements."] theorem orderOf_injective {H : Type*} [Monoid H] (f : G →* H) (hf : Function.Injective f) (x : G) : orderOf (f x) = orderOf x := by simp_rw [orderOf_eq_orderOf_iff, ← f.map_pow, ← f.map_one, hf.eq_iff, forall_const] /-- A multiplicative equivalence preserves orders of elements. -/ @[to_additive (attr := simp) "An additive equivalence preserves orders of elements."] lemma MulEquiv.orderOf_eq {H : Type*} [Monoid H] (e : G ≃* H) (x : G) : orderOf (e x) = orderOf x := orderOf_injective e.toMonoidHom e.injective x @[to_additive] theorem Function.Injective.isOfFinOrder_iff [Monoid H] {f : G →* H} (hf : Injective f) : IsOfFinOrder (f x) ↔ IsOfFinOrder x := by rw [← orderOf_pos_iff, orderOf_injective f hf x, ← orderOf_pos_iff] @[to_additive (attr := norm_cast, simp)] theorem orderOf_submonoid {H : Submonoid G} (y : H) : orderOf (y : G) = orderOf y := orderOf_injective H.subtype Subtype.coe_injective y @[to_additive] theorem orderOf_units {y : Gˣ} : orderOf (y : G) = orderOf y := orderOf_injective (Units.coeHom G) Units.ext y /-- If the order of `x` is finite, then `x` is a unit with inverse `x ^ (orderOf x - 1)`. -/ @[to_additive (attr := simps) "If the additive order of `x` is finite, then `x` is an additive unit with inverse `(addOrderOf x - 1) • x`. "] noncomputable def IsOfFinOrder.unit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : Mˣ := ⟨x, x ^ (orderOf x - 1), by rw [← _root_.pow_succ', tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one], by rw [← _root_.pow_succ, tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one]⟩ @[to_additive] lemma IsOfFinOrder.isUnit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : IsUnit x := ⟨hx.unit, rfl⟩ variable (x) @[to_additive] theorem orderOf_pow' (h : n ≠ 0) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd h, mul_left_iterate] @[to_additive] lemma orderOf_pow_of_dvd {x : G} {n : ℕ} (hn : n ≠ 0) (dvd : n ∣ orderOf x) : orderOf (x ^ n) = orderOf x / n := by rw [orderOf_pow' _ hn, Nat.gcd_eq_right dvd] @[to_additive] lemma orderOf_pow_orderOf_div {x : G} {n : ℕ} (hx : orderOf x ≠ 0) (hn : n ∣ orderOf x) : orderOf (x ^ (orderOf x / n)) = n := by rw [orderOf_pow_of_dvd _ (Nat.div_dvd_of_dvd hn), Nat.div_div_self hn hx] rw [← Nat.div_mul_cancel hn] at hx; exact left_ne_zero_of_mul hx variable (n) @[to_additive] protected lemma IsOfFinOrder.orderOf_pow (h : IsOfFinOrder x) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd' h, mul_left_iterate] @[to_additive] lemma Nat.Coprime.orderOf_pow (h : (orderOf y).Coprime m) : orderOf (y ^ m) = orderOf y := by by_cases hg : IsOfFinOrder y · rw [hg.orderOf_pow y m , h.gcd_eq_one, Nat.div_one] · rw [m.coprime_zero_left.1 (orderOf_eq_zero hg ▸ h), pow_one] @[to_additive] lemma IsOfFinOrder.natCard_powers_le_orderOf (ha : IsOfFinOrder a) : Nat.card (powers a : Set G) ≤ orderOf a := by classical simpa [ha.powers_eq_image_range_orderOf, Finset.card_range, Nat.Iio_eq_range] using Finset.card_image_le (s := Finset.range (orderOf a)) @[to_additive] lemma IsOfFinOrder.finite_powers (ha : IsOfFinOrder a) : (powers a : Set G).Finite := by classical rw [ha.powers_eq_image_range_orderOf]; exact Finset.finite_toSet _ namespace Commute variable {x} @[to_additive] theorem orderOf_mul_dvd_lcm (h : Commute x y) : orderOf (x * y) ∣ Nat.lcm (orderOf x) (orderOf y) := by rw [orderOf, ← comp_mul_left] exact Function.Commute.minimalPeriod_of_comp_dvd_lcm h.function_commute_mul_left @[to_additive] theorem orderOf_dvd_lcm_mul (h : Commute x y): orderOf y ∣ Nat.lcm (orderOf x) (orderOf (x * y)) := by by_cases h0 : orderOf x = 0 · rw [h0, lcm_zero_left] apply dvd_zero conv_lhs => rw [← one_mul y, ← pow_orderOf_eq_one x, ← succ_pred_eq_of_pos (Nat.pos_of_ne_zero h0), _root_.pow_succ, mul_assoc] exact (((Commute.refl x).mul_right h).pow_left _).orderOf_mul_dvd_lcm.trans (lcm_dvd_iff.2 ⟨(orderOf_pow_dvd _).trans (dvd_lcm_left _ _), dvd_lcm_right _ _⟩) @[to_additive addOrderOf_add_dvd_mul_addOrderOf] theorem orderOf_mul_dvd_mul_orderOf (h : Commute x y): orderOf (x * y) ∣ orderOf x * orderOf y := dvd_trans h.orderOf_mul_dvd_lcm (lcm_dvd_mul _ _) @[to_additive addOrderOf_add_eq_mul_addOrderOf_of_coprime] theorem orderOf_mul_eq_mul_orderOf_of_coprime (h : Commute x y) (hco : (orderOf x).Coprime (orderOf y)) : orderOf (x * y) = orderOf x * orderOf y := by rw [orderOf, ← comp_mul_left] exact h.function_commute_mul_left.minimalPeriod_of_comp_eq_mul_of_coprime hco /-- Commuting elements of finite order are closed under multiplication. -/ @[to_additive "Commuting elements of finite additive order are closed under addition."] theorem isOfFinOrder_mul (h : Commute x y) (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) := orderOf_pos_iff.mp <| pos_of_dvd_of_pos h.orderOf_mul_dvd_mul_orderOf <| mul_pos hx.orderOf_pos hy.orderOf_pos /-- If each prime factor of `orderOf x` has higher multiplicity in `orderOf y`, and `x` commutes with `y`, then `x * y` has the same order as `y`. -/ @[to_additive addOrderOf_add_eq_right_of_forall_prime_mul_dvd "If each prime factor of `addOrderOf x` has higher multiplicity in `addOrderOf y`, and `x` commutes with `y`, then `x + y` has the same order as `y`."] theorem orderOf_mul_eq_right_of_forall_prime_mul_dvd (h : Commute x y) (hy : IsOfFinOrder y) (hdvd : ∀ p : ℕ, p.Prime → p ∣ orderOf x → p * orderOf x ∣ orderOf y) : orderOf (x * y) = orderOf y := by have hoy := hy.orderOf_pos have hxy := dvd_of_forall_prime_mul_dvd hdvd apply orderOf_eq_of_pow_and_pow_div_prime hoy <;> simp only [Ne, ← orderOf_dvd_iff_pow_eq_one] · exact h.orderOf_mul_dvd_lcm.trans (lcm_dvd hxy dvd_rfl) refine fun p hp hpy hd => hp.ne_one ?_ rw [← Nat.dvd_one, ← mul_dvd_mul_iff_right hoy.ne', one_mul, ← dvd_div_iff_mul_dvd hpy] refine (orderOf_dvd_lcm_mul h).trans (lcm_dvd ((dvd_div_iff_mul_dvd hpy).2 ?_) hd) by_cases h : p ∣ orderOf x exacts [hdvd p hp h, (hp.coprime_iff_not_dvd.2 h).mul_dvd_of_dvd_of_dvd hpy hxy] end Commute section PPrime variable {x n} {p : ℕ} [hp : Fact p.Prime] @[to_additive] theorem orderOf_eq_prime_iff : orderOf x = p ↔ x ^ p = 1 ∧ x ≠ 1 := by rw [orderOf, minimalPeriod_eq_prime_iff, isPeriodicPt_mul_iff_pow_eq_one, IsFixedPt, mul_one] /-- The backward direction of `orderOf_eq_prime_iff`. -/ @[to_additive "The backward direction of `addOrderOf_eq_prime_iff`."] theorem orderOf_eq_prime (hg : x ^ p = 1) (hg1 : x ≠ 1) : orderOf x = p := orderOf_eq_prime_iff.mpr ⟨hg, hg1⟩ @[to_additive addOrderOf_eq_prime_pow] theorem orderOf_eq_prime_pow (hnot : ¬x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) : orderOf x = p ^ (n + 1) := by apply minimalPeriod_eq_prime_pow <;> rwa [isPeriodicPt_mul_iff_pow_eq_one] @[to_additive exists_addOrderOf_eq_prime_pow_iff] theorem exists_orderOf_eq_prime_pow_iff : (∃ k : ℕ, orderOf x = p ^ k) ↔ ∃ m : ℕ, x ^ (p : ℕ) ^ m = 1 := ⟨fun ⟨k, hk⟩ => ⟨k, by rw [← hk, pow_orderOf_eq_one]⟩, fun ⟨_, hm⟩ => by obtain ⟨k, _, hk⟩ := (Nat.dvd_prime_pow hp.elim).mp (orderOf_dvd_of_pow_eq_one hm) exact ⟨k, hk⟩⟩ end PPrime /-- The equivalence between `Fin (orderOf x)` and `Submonoid.powers x`, sending `i` to `x ^ i` -/ @[to_additive "The equivalence between `Fin (addOrderOf a)` and `AddSubmonoid.multiples a`, sending `i` to `i • a`"] noncomputable def finEquivPowers {x : G} (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ powers x := Equiv.ofBijective (fun n ↦ ⟨x ^ (n : ℕ), ⟨n, rfl⟩⟩) ⟨fun ⟨_, h₁⟩ ⟨_, h₂⟩ ij ↦ Fin.ext (pow_injOn_Iio_orderOf h₁ h₂ (Subtype.mk_eq_mk.1 ij)), fun ⟨_, i, rfl⟩ ↦ ⟨⟨i % orderOf x, mod_lt _ hx.orderOf_pos⟩, Subtype.eq <| pow_mod_orderOf _ _⟩⟩ @[to_additive (attr := simp)] lemma finEquivPowers_apply {x : G} (hx : IsOfFinOrder x) {n : Fin (orderOf x)} : finEquivPowers hx n = ⟨x ^ (n : ℕ), n, rfl⟩ := rfl @[to_additive (attr := simp)] lemma finEquivPowers_symm_apply {x : G} (hx : IsOfFinOrder x) (n : ℕ) : (finEquivPowers hx).symm ⟨x ^ n, _, rfl⟩ = ⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by rw [Equiv.symm_apply_eq, finEquivPowers_apply, Subtype.mk_eq_mk, ← pow_mod_orderOf, Fin.val_mk] variable {x n} (hx : IsOfFinOrder x) include hx @[to_additive] theorem IsOfFinOrder.pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by wlog hmn : m ≤ n generalizing m n · rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [pow_add, (hx.isUnit.pow _).mul_eq_left, pow_eq_one_iff_modEq] exact ⟨fun h ↦ Nat.ModEq.add_left _ h, fun h ↦ Nat.ModEq.add_left_cancel' _ h⟩ @[to_additive] lemma IsOfFinOrder.pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := hx.pow_eq_pow_iff_modEq end Monoid section CancelMonoid variable [LeftCancelMonoid G] {x y : G} {a : G} {m n : ℕ} @[to_additive] theorem pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by wlog hmn : m ≤ n generalizing m n · rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [← mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modEq] exact ⟨fun h => Nat.ModEq.add_left _ h, fun h => Nat.ModEq.add_left_cancel' _ h⟩ @[to_additive (attr := simp)] lemma injective_pow_iff_not_isOfFinOrder : Injective (fun n : ℕ ↦ x ^ n) ↔ ¬IsOfFinOrder x := by refine ⟨fun h => not_isOfFinOrder_of_injective_pow h, fun h n m hnm => ?_⟩ rwa [pow_eq_pow_iff_modEq, orderOf_eq_zero_iff.mpr h, modEq_zero_iff] at hnm @[to_additive] lemma pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := pow_eq_pow_iff_modEq @[to_additive] theorem pow_inj_iff_of_orderOf_eq_zero (h : orderOf x = 0) {n m : ℕ} : x ^ n = x ^ m ↔ n = m := by rw [pow_eq_pow_iff_modEq, h, modEq_zero_iff] @[to_additive] theorem infinite_not_isOfFinOrder {x : G} (h : ¬IsOfFinOrder x) : { y : G | ¬IsOfFinOrder y }.Infinite := by let s := { n | 0 < n }.image fun n : ℕ => x ^ n have hs : s ⊆ { y : G | ¬IsOfFinOrder y } := by rintro - ⟨n, hn : 0 < n, rfl⟩ (contra : IsOfFinOrder (x ^ n)) apply h rw [isOfFinOrder_iff_pow_eq_one] at contra ⊢ obtain ⟨m, hm, hm'⟩ := contra exact ⟨n * m, mul_pos hn hm, by rwa [pow_mul]⟩ suffices s.Infinite by exact this.mono hs contrapose! h have : ¬Injective fun n : ℕ => x ^ n := by have := Set.not_injOn_infinite_finite_image (Set.Ioi_infinite 0) (Set.not_infinite.mp h) contrapose! this exact Set.injOn_of_injective this rwa [injective_pow_iff_not_isOfFinOrder, Classical.not_not] at this @[to_additive (attr := simp)] lemma finite_powers : (powers a : Set G).Finite ↔ IsOfFinOrder a := by refine ⟨fun h ↦ ?_, IsOfFinOrder.finite_powers⟩ obtain ⟨m, n, hmn, ha⟩ := h.exists_lt_map_eq_of_forall_mem (f := fun n : ℕ ↦ a ^ n) (fun n ↦ by simp [mem_powers_iff]) refine isOfFinOrder_iff_pow_eq_one.2 ⟨n - m, tsub_pos_iff_lt.2 hmn, ?_⟩ rw [← mul_left_cancel_iff (a := a ^ m), ← pow_add, add_tsub_cancel_of_le hmn.le, ha, mul_one] @[to_additive (attr := simp)] lemma infinite_powers : (powers a : Set G).Infinite ↔ ¬ IsOfFinOrder a := finite_powers.not /-- See also `orderOf_eq_card_powers`. -/ @[to_additive "See also `addOrder_eq_card_multiples`."] lemma Nat.card_submonoidPowers : Nat.card (powers a) = orderOf a := by classical by_cases ha : IsOfFinOrder a · exact (Nat.card_congr (finEquivPowers ha).symm).trans <| by simp · have := (infinite_powers.2 ha).to_subtype rw [orderOf_eq_zero ha, Nat.card_eq_zero_of_infinite] end CancelMonoid section Group variable [Group G] {x y : G} {i : ℤ} /-- Inverses of elements of finite order have finite order. -/ @[to_additive (attr := simp) "Inverses of elements of finite additive order have finite additive order."] theorem isOfFinOrder_inv_iff {x : G} : IsOfFinOrder x⁻¹ ↔ IsOfFinOrder x := by simp [isOfFinOrder_iff_pow_eq_one] @[to_additive] alias ⟨IsOfFinOrder.of_inv, IsOfFinOrder.inv⟩ := isOfFinOrder_inv_iff @[to_additive] theorem orderOf_dvd_iff_zpow_eq_one : (orderOf x : ℤ) ∣ i ↔ x ^ i = 1 := by rcases Int.eq_nat_or_neg i with ⟨i, rfl | rfl⟩ · rw [Int.natCast_dvd_natCast, orderOf_dvd_iff_pow_eq_one, zpow_natCast] · rw [dvd_neg, Int.natCast_dvd_natCast, zpow_neg, inv_eq_one, zpow_natCast, orderOf_dvd_iff_pow_eq_one] @[to_additive (attr := simp)] theorem orderOf_inv (x : G) : orderOf x⁻¹ = orderOf x := by simp [orderOf_eq_orderOf_iff] @[to_additive] theorem orderOf_dvd_sub_iff_zpow_eq_zpow {a b : ℤ} : (orderOf x : ℤ) ∣ a - b ↔ x ^ a = x ^ b := by rw [orderOf_dvd_iff_zpow_eq_one, zpow_sub, mul_inv_eq_one] namespace Subgroup variable {H : Subgroup G} @[to_additive (attr := norm_cast)] lemma orderOf_coe (a : H) : orderOf (a : G) = orderOf a := orderOf_injective H.subtype Subtype.coe_injective _ @[to_additive (attr := simp)] lemma orderOf_mk (a : G) (ha) : orderOf (⟨a, ha⟩ : H) = orderOf a := (orderOf_coe _).symm end Subgroup @[to_additive mod_addOrderOf_zsmul] lemma zpow_mod_orderOf (x : G) (z : ℤ) : x ^ (z % (orderOf x : ℤ)) = x ^ z := calc x ^ (z % (orderOf x : ℤ)) = x ^ (z % orderOf x + orderOf x * (z / orderOf x) : ℤ) := by simp [zpow_add, zpow_mul, pow_orderOf_eq_one] _ = x ^ z := by rw [Int.emod_add_ediv] @[to_additive (attr := simp) zsmul_smul_addOrderOf] theorem zpow_pow_orderOf : (x ^ i) ^ orderOf x = 1 := by by_cases h : IsOfFinOrder x · rw [← zpow_natCast, ← zpow_mul, mul_comm, zpow_mul, zpow_natCast, pow_orderOf_eq_one, one_zpow] · rw [orderOf_eq_zero h, _root_.pow_zero] @[to_additive] theorem IsOfFinOrder.zpow (h : IsOfFinOrder x) {i : ℤ} : IsOfFinOrder (x ^ i) := isOfFinOrder_iff_pow_eq_one.mpr ⟨orderOf x, h.orderOf_pos, zpow_pow_orderOf⟩ @[to_additive] theorem IsOfFinOrder.of_mem_zpowers (h : IsOfFinOrder x) (h' : y ∈ Subgroup.zpowers x) : IsOfFinOrder y := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp h' exact h.zpow @[to_additive] theorem orderOf_dvd_of_mem_zpowers (h : y ∈ Subgroup.zpowers x) : orderOf y ∣ orderOf x := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp h rw [orderOf_dvd_iff_pow_eq_one] exact zpow_pow_orderOf theorem smul_eq_self_of_mem_zpowers {α : Type*} [MulAction G α] (hx : x ∈ Subgroup.zpowers y) {a : α} (hs : y • a = a) : x • a = a := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp hx rw [← MulAction.toPerm_apply, ← MulAction.toPermHom_apply, MonoidHom.map_zpow _ y k, MulAction.toPermHom_apply] exact Function.IsFixedPt.perm_zpow (by exact hs) k -- Porting note: help elab'n with `by exact` theorem vadd_eq_self_of_mem_zmultiples {α G : Type*} [AddGroup G] [AddAction G α] {x y : G} (hx : x ∈ AddSubgroup.zmultiples y) {a : α} (hs : y +ᵥ a = a) : x +ᵥ a = a := @smul_eq_self_of_mem_zpowers (Multiplicative G) _ _ _ α _ hx a hs attribute [to_additive existing] smul_eq_self_of_mem_zpowers @[to_additive] lemma IsOfFinOrder.mem_powers_iff_mem_zpowers (hx : IsOfFinOrder x) : y ∈ powers x ↔ y ∈ zpowers x := ⟨fun ⟨n, hn⟩ ↦ ⟨n, by simp_all⟩, fun ⟨i, hi⟩ ↦ ⟨(i % orderOf x).natAbs, by dsimp only rwa [← zpow_natCast, Int.natAbs_of_nonneg <| Int.emod_nonneg _ <| Int.natCast_ne_zero_iff_pos.2 <| hx.orderOf_pos, zpow_mod_orderOf]⟩⟩ @[to_additive] lemma IsOfFinOrder.powers_eq_zpowers (hx : IsOfFinOrder x) : (powers x : Set G) = zpowers x := Set.ext fun _ ↦ hx.mem_powers_iff_mem_zpowers @[to_additive] lemma IsOfFinOrder.mem_zpowers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : y ∈ zpowers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := hx.mem_powers_iff_mem_zpowers.symm.trans hx.mem_powers_iff_mem_range_orderOf /-- The equivalence between `Fin (orderOf x)` and `Subgroup.zpowers x`, sending `i` to `x ^ i`. -/ @[to_additive "The equivalence between `Fin (addOrderOf a)` and `Subgroup.zmultiples a`, sending `i` to `i • a`."] noncomputable def finEquivZPowers (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ zpowers x := (finEquivPowers hx).trans <| Equiv.setCongr hx.powers_eq_zpowers @[to_additive] lemma finEquivZPowers_apply (hx : IsOfFinOrder x) {n : Fin (orderOf x)} : finEquivZPowers hx n = ⟨x ^ (n : ℕ), n, zpow_natCast x n⟩ := rfl @[to_additive] lemma finEquivZPowers_symm_apply (hx : IsOfFinOrder x) (n : ℕ) : (finEquivZPowers hx).symm ⟨x ^ n, ⟨n, by simp⟩⟩ = ⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by rw [finEquivZPowers, Equiv.symm_trans_apply]; exact finEquivPowers_symm_apply _ n end Group section CommMonoid variable [CommMonoid G] {x y : G} /-- Elements of finite order are closed under multiplication. -/ @[to_additive "Elements of finite additive order are closed under addition."] theorem IsOfFinOrder.mul (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) := (Commute.all x y).isOfFinOrder_mul hx hy end CommMonoid
section FiniteMonoid variable [Monoid G] {x : G} {n : ℕ}
Mathlib/GroupTheory/OrderOfElement.lean
706
709
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.ModelTheory.ElementarySubstructures /-! # Skolem Functions and Downward Löwenheim–Skolem ## Main Definitions - `FirstOrder.Language.skolem₁` is a language consisting of Skolem functions for another language. ## Main Results - `FirstOrder.Language.exists_elementarySubstructure_card_eq` is the Downward Löwenheim–Skolem theorem: If `s` is a set in an `L`-structure `M` and `κ` an infinite cardinal such that `max (#s, L.card) ≤ κ` and `κ ≤ # M`, then `M` has an elementary substructure containing `s` of cardinality `κ`. ## TODO - Use `skolem₁` recursively to construct an actual Skolemization of a language. -/ universe u v w w' namespace FirstOrder namespace Language open Structure Cardinal open Cardinal variable (L : Language.{u, v}) {M : Type w} [Nonempty M] [L.Structure M] /-- A language consisting of Skolem functions for another language. Called `skolem₁` because it is the first step in building a Skolemization of a language. -/ @[simps] def skolem₁ : Language := ⟨fun n => L.BoundedFormula Empty (n + 1), fun _ => Empty⟩ variable {L} theorem card_functions_sum_skolem₁ : #(Σ n, (L.sum L.skolem₁).Functions n) = #(Σ n, L.BoundedFormula Empty (n + 1)) := by
simp only [card_functions_sum, skolem₁_Functions, mk_sigma, sum_add_distrib'] conv_lhs => enter [2, 1, i]; rw [lift_id'.{u, v}] rw [add_comm, add_eq_max, max_eq_left] · refine sum_le_sum _ _ fun n => ?_ rw [← lift_le.{_, max u v}, lift_lift, lift_mk_le.{v}] refine ⟨⟨fun f => (func f default).bdEqual (func f default), fun f g h => ?_⟩⟩ rcases h with ⟨rfl, ⟨rfl⟩⟩ rfl · rw [← mk_sigma] exact infinite_iff.1 (Infinite.of_injective (fun n => ⟨n, ⊥⟩) fun x y xy => (Sigma.mk.inj_iff.1 xy).1) theorem card_functions_sum_skolem₁_le : #(Σ n, (L.sum L.skolem₁).Functions n) ≤ max ℵ₀ L.card := by
Mathlib/ModelTheory/Skolem.lean
50
62
/- 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.Minor.Restrict /-! # Some constructions of matroids This file defines some very elementary examples of matroids, namely those with at most one base. ## Main definitions * `emptyOn α` is the matroid on `α` with empty ground set. For `E : Set α`, ... * `loopyOn E` is the matroid on `E` whose elements are all loops, or equivalently in which `∅` is the only base. * `freeOn E` is the 'free matroid' whose ground set `E` is the only base. * For `I ⊆ E`, `uniqueBaseOn I E` is the matroid with ground set `E` in which `I` is the only base. ## Implementation details To avoid the tedious process of certifying the matroid axioms for each of these easy examples, we bootstrap the definitions starting with `emptyOn α` (which `simp` can prove is a matroid) and then construct the other examples using duality and restriction. -/ assert_not_exists Field variable {α : Type*} {M : Matroid α} {E B I X R J : Set α} namespace Matroid open Set section EmptyOn /-- The `Matroid α` with empty ground set. -/ def emptyOn (α : Type*) : Matroid α where E := ∅ IsBase := (· = ∅) Indep := (· = ∅) indep_iff' := by simp [subset_empty_iff] exists_isBase := ⟨∅, rfl⟩ isBase_exchange := by rintro _ _ rfl; simp maximality := by rintro _ _ _ rfl -; exact ⟨∅, by simp [Maximal]⟩ subset_ground := by simp @[simp] theorem emptyOn_ground : (emptyOn α).E = ∅ := rfl @[simp] theorem emptyOn_isBase_iff : (emptyOn α).IsBase B ↔ B = ∅ := Iff.rfl @[simp] theorem emptyOn_indep_iff : (emptyOn α).Indep I ↔ I = ∅ := Iff.rfl theorem ground_eq_empty_iff : (M.E = ∅) ↔ M = emptyOn α := by simp only [emptyOn, ext_iff_indep, iff_self_and] exact fun h ↦ by simp [h, subset_empty_iff] @[simp] theorem emptyOn_dual_eq : (emptyOn α)✶ = emptyOn α := by rw [← ground_eq_empty_iff]; rfl @[simp] theorem restrict_empty (M : Matroid α) : M ↾ (∅ : Set α) = emptyOn α := by simp [← ground_eq_empty_iff] theorem eq_emptyOn_or_nonempty (M : Matroid α) : M = emptyOn α ∨ Matroid.Nonempty M := by rw [← ground_eq_empty_iff] exact M.E.eq_empty_or_nonempty.elim Or.inl (fun h ↦ Or.inr ⟨h⟩) theorem eq_emptyOn [IsEmpty α] (M : Matroid α) : M = emptyOn α := by rw [← ground_eq_empty_iff] exact M.E.eq_empty_of_isEmpty instance finite_emptyOn (α : Type*) : (emptyOn α).Finite := ⟨finite_empty⟩ end EmptyOn section LoopyOn /-- The `Matroid α` with ground set `E` whose only base is `∅`. The elements are all 'loops' - see `Matroid.IsLoop` and `Matroid.loopyOn_isLoop_iff`. -/ def loopyOn (E : Set α) : Matroid α := emptyOn α ↾ E @[simp] theorem loopyOn_ground (E : Set α) : (loopyOn E).E = E := rfl @[simp] theorem loopyOn_empty (α : Type*) : loopyOn (∅ : Set α) = emptyOn α := by rw [← ground_eq_empty_iff, loopyOn_ground] @[simp] theorem loopyOn_indep_iff : (loopyOn E).Indep I ↔ I = ∅ := by simp only [loopyOn, restrict_indep_iff, emptyOn_indep_iff, and_iff_left_iff_imp] rintro rfl; apply empty_subset theorem eq_loopyOn_iff : M = loopyOn E ↔ M.E = E ∧ ∀ X ⊆ M.E, M.Indep X → X = ∅ := by simp only [ext_iff_indep, loopyOn_ground, loopyOn_indep_iff, and_congr_right_iff] rintro rfl refine ⟨fun h I hI ↦ (h hI).1, fun h I hIE ↦ ⟨h I hIE, by rintro rfl; simp⟩⟩ @[simp] theorem loopyOn_isBase_iff : (loopyOn E).IsBase B ↔ B = ∅ := by simp [Maximal, isBase_iff_maximal_indep] @[simp] theorem loopyOn_isBasis_iff : (loopyOn E).IsBasis I X ↔ I = ∅ ∧ X ⊆ E := ⟨fun h ↦ ⟨loopyOn_indep_iff.mp h.indep, h.subset_ground⟩, by rintro ⟨rfl, hX⟩; rw [isBasis_iff]; simp⟩ instance : RankFinite (loopyOn E) := ⟨⟨∅, loopyOn_isBase_iff.2 rfl, finite_empty⟩⟩ theorem Finite.loopyOn_finite (hE : E.Finite) : Matroid.Finite (loopyOn E) := ⟨hE⟩ @[simp] theorem loopyOn_restrict (E R : Set α) : (loopyOn E) ↾ R = loopyOn R := by refine ext_indep rfl ?_ simp only [restrict_ground_eq, restrict_indep_iff, loopyOn_indep_iff, and_iff_left_iff_imp] exact fun _ h _ ↦ h theorem empty_isBase_iff : M.IsBase ∅ ↔ M = loopyOn M.E := by simp only [isBase_iff_maximal_indep, Maximal, empty_indep, le_eq_subset, empty_subset, subset_empty_iff, true_implies, true_and, ext_iff_indep, loopyOn_ground, loopyOn_indep_iff] exact ⟨fun h I _ ↦ ⟨@h _, fun hI ↦ by simp [hI]⟩, fun h I hI ↦ (h hI.subset_ground).1 hI⟩ theorem eq_loopyOn_or_rankPos (M : Matroid α) : M = loopyOn M.E ∨ RankPos M := by rw [← empty_isBase_iff, rankPos_iff]; apply em theorem not_rankPos_iff : ¬RankPos M ↔ M = loopyOn M.E := by rw [rankPos_iff, not_iff_comm, empty_isBase_iff] instance loopyOn_rankFinite : RankFinite (loopyOn E) := ⟨∅, by simp⟩ end LoopyOn section FreeOn /-- The `Matroid α` with ground set `E` whose only base is `E`. -/ def freeOn (E : Set α) : Matroid α := (loopyOn E)✶ @[simp] theorem freeOn_ground : (freeOn E).E = E := rfl @[simp] theorem freeOn_dual_eq : (freeOn E)✶ = loopyOn E := by rw [freeOn, dual_dual] @[simp] theorem loopyOn_dual_eq : (loopyOn E)✶ = freeOn E := rfl @[simp] theorem freeOn_empty (α : Type*) : freeOn (∅ : Set α) = emptyOn α := by simp [freeOn] @[simp] theorem freeOn_isBase_iff : (freeOn E).IsBase B ↔ B = E := by simp only [freeOn, loopyOn_ground, dual_isBase_iff', loopyOn_isBase_iff, diff_eq_empty, ← subset_antisymm_iff, eq_comm (a := E)]
@[simp] theorem freeOn_indep_iff : (freeOn E).Indep I ↔ I ⊆ E := by simp [indep_iff] theorem freeOn_indep (hIE : I ⊆ E) : (freeOn E).Indep I :=
Mathlib/Data/Matroid/Constructions.lean
156
159
/- 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, María Inés de Frutos-Fernández, Filippo A. E. Nuccio -/ import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.RingTheory.DiscreteValuationRing.Basic import Mathlib.RingTheory.MvPowerSeries.Inverse import Mathlib.RingTheory.PowerSeries.NoZeroDivisors import Mathlib.RingTheory.LocalRing.ResidueField.Defs import Mathlib.RingTheory.UniqueFactorizationDomain.Multiplicity import Mathlib.Data.ENat.Lattice /-! # Formal power series - Inverses If the constant coefficient of a formal (univariate) power series is invertible, then this formal power series is invertible. (See the discussion in `Mathlib.RingTheory.MvPowerSeries.Inverse` for the construction.) Formal (univariate) power series over a local ring form a local ring. Formal (univariate) power series over a field form a discrete valuation ring, and a normalization monoid. The definition `residueFieldOfPowerSeries` provides the isomorphism between the residue field of `k⟦X⟧` and `k`, when `k` is a field. -/ noncomputable section open Polynomial open Finset (antidiagonal mem_antidiagonal) namespace PowerSeries open Finsupp (single) variable {R : Type*} section Ring variable [Ring R] /-- Auxiliary function used for computing inverse of a power series -/ protected def inv.aux : R → R⟦X⟧ → R⟦X⟧ := MvPowerSeries.inv.aux theorem coeff_inv_aux (n : ℕ) (a : R) (φ : R⟦X⟧) : coeff R n (inv.aux a φ) = if n = 0 then a else -a * ∑ x ∈ antidiagonal n, if x.2 < n then coeff R x.1 φ * coeff R x.2 (inv.aux a φ) else 0 := by rw [coeff, inv.aux, MvPowerSeries.coeff_inv_aux] simp only [Finsupp.single_eq_zero] split_ifs; · rfl congr 1 symm apply Finset.sum_nbij' (fun (a, b) ↦ (single () a, single () b)) fun (f, g) ↦ (f (), g ()) · aesop · aesop · aesop · aesop · rintro ⟨i, j⟩ _hij obtain H | H := le_or_lt n j · aesop rw [if_pos H, if_pos] · rfl refine ⟨?_, fun hh ↦ H.not_le ?_⟩ · rintro ⟨⟩ simpa [Finsupp.single_eq_same] using le_of_lt H · simpa [Finsupp.single_eq_same] using hh () /-- A formal power series is invertible if the constant coefficient is invertible. -/ def invOfUnit (φ : R⟦X⟧) (u : Rˣ) : R⟦X⟧ := MvPowerSeries.invOfUnit φ u theorem coeff_invOfUnit (n : ℕ) (φ : R⟦X⟧) (u : Rˣ) : coeff R n (invOfUnit φ u) = if n = 0 then ↑u⁻¹ else -↑u⁻¹ * ∑ x ∈ antidiagonal n, if x.2 < n then coeff R x.1 φ * coeff R x.2 (invOfUnit φ u) else 0 := coeff_inv_aux n (↑u⁻¹ : R) φ @[simp] theorem constantCoeff_invOfUnit (φ : R⟦X⟧) (u : Rˣ) : constantCoeff R (invOfUnit φ u) = ↑u⁻¹ := by rw [← coeff_zero_eq_constantCoeff_apply, coeff_invOfUnit, if_pos rfl] @[simp] theorem mul_invOfUnit (φ : R⟦X⟧) (u : Rˣ) (h : constantCoeff R φ = u) : φ * invOfUnit φ u = 1 := MvPowerSeries.mul_invOfUnit φ u <| h @[simp] theorem invOfUnit_mul (φ : R⟦X⟧) (u : Rˣ) (h : constantCoeff R φ = u) : invOfUnit φ u * φ = 1 := MvPowerSeries.invOfUnit_mul φ u h theorem isUnit_iff_constantCoeff {φ : R⟦X⟧} : IsUnit φ ↔ IsUnit (constantCoeff R φ) := MvPowerSeries.isUnit_iff_constantCoeff /-- Two ways of removing the constant coefficient of a power series are the same. -/ theorem sub_const_eq_shift_mul_X (φ : R⟦X⟧) : φ - C R (constantCoeff R φ) = (mk fun p ↦ coeff R (p + 1) φ) * X := sub_eq_iff_eq_add.mpr (eq_shift_mul_X_add_const φ) theorem sub_const_eq_X_mul_shift (φ : R⟦X⟧) : φ - C R (constantCoeff R φ) = X * mk fun p ↦ coeff R (p + 1) φ := sub_eq_iff_eq_add.mpr (eq_X_mul_shift_add_const φ) end Ring section Field variable {k : Type*} [Field k] /-- The inverse 1/f of a power series f defined over a field -/ protected def inv : k⟦X⟧ → k⟦X⟧ := MvPowerSeries.inv instance : Inv k⟦X⟧ := ⟨PowerSeries.inv⟩ theorem inv_eq_inv_aux (φ : k⟦X⟧) : φ⁻¹ = inv.aux (constantCoeff k φ)⁻¹ φ := rfl theorem coeff_inv (n) (φ : k⟦X⟧) : coeff k n φ⁻¹ = if n = 0 then (constantCoeff k φ)⁻¹ else -(constantCoeff k φ)⁻¹ * ∑ x ∈ antidiagonal n, if x.2 < n then coeff k x.1 φ * coeff k x.2 φ⁻¹ else 0 := by rw [inv_eq_inv_aux, coeff_inv_aux n (constantCoeff k φ)⁻¹ φ] @[simp] theorem constantCoeff_inv (φ : k⟦X⟧) : constantCoeff k φ⁻¹ = (constantCoeff k φ)⁻¹ := MvPowerSeries.constantCoeff_inv φ theorem inv_eq_zero {φ : k⟦X⟧} : φ⁻¹ = 0 ↔ constantCoeff k φ = 0 := MvPowerSeries.inv_eq_zero theorem zero_inv : (0 : k⟦X⟧)⁻¹ = 0 := MvPowerSeries.zero_inv @[simp] theorem invOfUnit_eq (φ : k⟦X⟧) (h : constantCoeff k φ ≠ 0) : invOfUnit φ (Units.mk0 _ h) = φ⁻¹ := MvPowerSeries.invOfUnit_eq _ _ @[simp] theorem invOfUnit_eq' (φ : k⟦X⟧) (u : Units k) (h : constantCoeff k φ = u) : invOfUnit φ u = φ⁻¹ := MvPowerSeries.invOfUnit_eq' φ _ h @[simp] protected theorem mul_inv_cancel (φ : k⟦X⟧) (h : constantCoeff k φ ≠ 0) : φ * φ⁻¹ = 1 := MvPowerSeries.mul_inv_cancel φ h @[simp] protected theorem inv_mul_cancel (φ : k⟦X⟧) (h : constantCoeff k φ ≠ 0) : φ⁻¹ * φ = 1 := MvPowerSeries.inv_mul_cancel φ h theorem eq_mul_inv_iff_mul_eq {φ₁ φ₂ φ₃ : k⟦X⟧} (h : constantCoeff k φ₃ ≠ 0) : φ₁ = φ₂ * φ₃⁻¹ ↔ φ₁ * φ₃ = φ₂ := MvPowerSeries.eq_mul_inv_iff_mul_eq h theorem eq_inv_iff_mul_eq_one {φ ψ : k⟦X⟧} (h : constantCoeff k ψ ≠ 0) : φ = ψ⁻¹ ↔ φ * ψ = 1 := MvPowerSeries.eq_inv_iff_mul_eq_one h theorem inv_eq_iff_mul_eq_one {φ ψ : k⟦X⟧} (h : constantCoeff k ψ ≠ 0) : ψ⁻¹ = φ ↔ φ * ψ = 1 := MvPowerSeries.inv_eq_iff_mul_eq_one h protected theorem mul_inv_rev (φ ψ : k⟦X⟧) : (φ * ψ)⁻¹ = ψ⁻¹ * φ⁻¹ := MvPowerSeries.mul_inv_rev _ _ instance : InvOneClass k⟦X⟧ := { inferInstanceAs <| InvOneClass <| MvPowerSeries Unit k with } @[simp] theorem C_inv (r : k) : (C k r)⁻¹ = C k r⁻¹ := MvPowerSeries.C_inv _ @[simp] theorem X_inv : (X : k⟦X⟧)⁻¹ = 0 := MvPowerSeries.X_inv _ theorem smul_inv (r : k) (φ : k⟦X⟧) : (r • φ)⁻¹ = r⁻¹ • φ⁻¹ := MvPowerSeries.smul_inv _ _ /-- `firstUnitCoeff` is the non-zero coefficient whose index is `f.order`, seen as a unit of the field. It is obtained using `divided_by_X_pow_order`, defined in `PowerSeries.Order`. -/ def firstUnitCoeff {f : k⟦X⟧} (hf : f ≠ 0) : kˣ := have : Invertible (constantCoeff k (divXPowOrder f)) := by apply invertibleOfNonzero simpa [constantCoeff_divXPowOrder_eq_zero_iff.not] unitOfInvertible (constantCoeff k (divXPowOrder f)) /-- `Inv_divided_by_X_pow_order` is the inverse of the element obtained by diving a non-zero power series by the largest power of `X` dividing it. Useful to create a term of type `Units`, done in `Unit_divided_by_X_pow_order` -/ def Inv_divided_by_X_pow_order {f : k⟦X⟧} (hf : f ≠ 0) : k⟦X⟧ := invOfUnit (divXPowOrder f) (firstUnitCoeff hf) @[simp] theorem Inv_divided_by_X_pow_order_rightInv {f : k⟦X⟧} (hf : f ≠ 0) : divXPowOrder f * Inv_divided_by_X_pow_order hf = 1 := mul_invOfUnit (divXPowOrder f) (firstUnitCoeff hf) rfl @[simp] theorem Inv_divided_by_X_pow_order_leftInv {f : k⟦X⟧} (hf : f ≠ 0) : Inv_divided_by_X_pow_order hf * divXPowOrder f = 1 := by rw [mul_comm] exact mul_invOfUnit (divXPowOrder f) (firstUnitCoeff hf) rfl open scoped Classical in /-- `Unit_of_divided_by_X_pow_order` is the unit power series obtained by dividing a non-zero power series by the largest power of `X` that divides it. -/ def Unit_of_divided_by_X_pow_order (f : k⟦X⟧) : k⟦X⟧ˣ := if hf : f = 0 then 1 else { val := divXPowOrder f inv := Inv_divided_by_X_pow_order hf val_inv := Inv_divided_by_X_pow_order_rightInv hf inv_val := Inv_divided_by_X_pow_order_leftInv hf } theorem isUnit_divided_by_X_pow_order {f : k⟦X⟧} (hf : f ≠ 0) : IsUnit (divXPowOrder f) := ⟨Unit_of_divided_by_X_pow_order f, by simp only [Unit_of_divided_by_X_pow_order, dif_neg hf, Units.val_mk]⟩ theorem Unit_of_divided_by_X_pow_order_nonzero {f : k⟦X⟧} (hf : f ≠ 0) : ↑(Unit_of_divided_by_X_pow_order f) = divXPowOrder f := by simp only [Unit_of_divided_by_X_pow_order, dif_neg hf, Units.val_mk] @[simp] theorem Unit_of_divided_by_X_pow_order_zero : Unit_of_divided_by_X_pow_order (0 : k⟦X⟧) = 1 := by simp only [Unit_of_divided_by_X_pow_order, dif_pos] theorem eq_divided_by_X_pow_order_Iff_Unit {f : k⟦X⟧} (hf : f ≠ 0) : f = divXPowOrder f ↔ IsUnit f :=
⟨fun h ↦ by rw [h]; exact isUnit_divided_by_X_pow_order hf, fun h ↦ by have : f.order = 0 := by simp [order_zero_of_unit h] conv_lhs => rw [← X_pow_order_mul_divXPowOrder (f := f), this, ENat.toNat_zero,
Mathlib/RingTheory/PowerSeries/Inverse.lean
253
256
/- 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, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard, Amelia Livingston, Yury Kudryashov -/ import Mathlib.Algebra.Group.Action.Faithful import Mathlib.Algebra.Group.Nat.Defs import Mathlib.Algebra.Group.Prod import Mathlib.Algebra.Group.Submonoid.Basic import Mathlib.Algebra.Group.Submonoid.MulAction import Mathlib.Algebra.Group.TypeTags.Basic /-! # Operations on `Submonoid`s In this file we define various operations on `Submonoid`s and `MonoidHom`s. ## Main definitions ### Conversion between multiplicative and additive definitions * `Submonoid.toAddSubmonoid`, `Submonoid.toAddSubmonoid'`, `AddSubmonoid.toSubmonoid`, `AddSubmonoid.toSubmonoid'`: convert between multiplicative and additive submonoids of `M`, `Multiplicative M`, and `Additive M`. These are stated as `OrderIso`s. ### (Commutative) monoid structure on a submonoid * `Submonoid.toMonoid`, `Submonoid.toCommMonoid`: a submonoid inherits a (commutative) monoid structure. ### Group actions by submonoids * `Submonoid.MulAction`, `Submonoid.DistribMulAction`: a submonoid inherits (distributive) multiplicative actions. ### Operations on submonoids * `Submonoid.comap`: preimage of a submonoid under a monoid homomorphism as a submonoid of the domain; * `Submonoid.map`: image of a submonoid under a monoid homomorphism as a submonoid of the codomain; * `Submonoid.prod`: product of two submonoids `s : Submonoid M` and `t : Submonoid N` as a submonoid of `M × N`; ### Monoid homomorphisms between submonoid * `Submonoid.subtype`: embedding of a submonoid into the ambient monoid. * `Submonoid.inclusion`: given two submonoids `S`, `T` such that `S ≤ T`, `S.inclusion T` is the inclusion of `S` into `T` as a monoid homomorphism; * `MulEquiv.submonoidCongr`: converts a proof of `S = T` into a monoid isomorphism between `S` and `T`. * `Submonoid.prodEquiv`: monoid isomorphism between `s.prod t` and `s × t`; ### Operations on `MonoidHom`s * `MonoidHom.mrange`: range of a monoid homomorphism as a submonoid of the codomain; * `MonoidHom.mker`: kernel of a monoid homomorphism as a submonoid of the domain; * `MonoidHom.restrict`: restrict a monoid homomorphism to a submonoid; * `MonoidHom.codRestrict`: restrict the codomain of a monoid homomorphism to a submonoid; * `MonoidHom.mrangeRestrict`: restrict a monoid homomorphism to its range; ## Tags submonoid, range, product, map, comap -/ assert_not_exists MonoidWithZero open Function variable {M N P : Type*} [MulOneClass M] [MulOneClass N] [MulOneClass P] (S : Submonoid M) /-! ### Conversion to/from `Additive`/`Multiplicative` -/ section /-- Submonoids of monoid `M` are isomorphic to additive submonoids of `Additive M`. -/ @[simps] def Submonoid.toAddSubmonoid : Submonoid M ≃o AddSubmonoid (Additive M) where toFun S := { carrier := Additive.toMul ⁻¹' S zero_mem' := S.one_mem' add_mem' := fun ha hb => S.mul_mem' ha hb } invFun S := { carrier := Additive.ofMul ⁻¹' S one_mem' := S.zero_mem' mul_mem' := fun ha hb => S.add_mem' ha hb} left_inv x := by cases x; rfl right_inv x := by cases x; rfl map_rel_iff' := Iff.rfl /-- Additive submonoids of an additive monoid `Additive M` are isomorphic to submonoids of `M`. -/ abbrev AddSubmonoid.toSubmonoid' : AddSubmonoid (Additive M) ≃o Submonoid M := Submonoid.toAddSubmonoid.symm theorem Submonoid.toAddSubmonoid_closure (S : Set M) : Submonoid.toAddSubmonoid (Submonoid.closure S) = AddSubmonoid.closure (Additive.toMul ⁻¹' S) := le_antisymm (Submonoid.toAddSubmonoid.le_symm_apply.1 <| Submonoid.closure_le.2 (AddSubmonoid.subset_closure (M := Additive M))) (AddSubmonoid.closure_le.2 <| Submonoid.subset_closure (M := M)) theorem AddSubmonoid.toSubmonoid'_closure (S : Set (Additive M)) : AddSubmonoid.toSubmonoid' (AddSubmonoid.closure S) = Submonoid.closure (Additive.ofMul ⁻¹' S) := le_antisymm (AddSubmonoid.toSubmonoid'.le_symm_apply.1 <| AddSubmonoid.closure_le.2 (Submonoid.subset_closure (M := M))) (Submonoid.closure_le.2 <| AddSubmonoid.subset_closure (M := Additive M)) end section variable {A : Type*} [AddZeroClass A] /-- Additive submonoids of an additive monoid `A` are isomorphic to multiplicative submonoids of `Multiplicative A`. -/ @[simps] def AddSubmonoid.toSubmonoid : AddSubmonoid A ≃o Submonoid (Multiplicative A) where toFun S := { carrier := Multiplicative.toAdd ⁻¹' S one_mem' := S.zero_mem' mul_mem' := fun ha hb => S.add_mem' ha hb } invFun S := { carrier := Multiplicative.ofAdd ⁻¹' S zero_mem' := S.one_mem' add_mem' := fun ha hb => S.mul_mem' ha hb} left_inv x := by cases x; rfl right_inv x := by cases x; rfl map_rel_iff' := Iff.rfl /-- Submonoids of a monoid `Multiplicative A` are isomorphic to additive submonoids of `A`. -/ abbrev Submonoid.toAddSubmonoid' : Submonoid (Multiplicative A) ≃o AddSubmonoid A := AddSubmonoid.toSubmonoid.symm theorem AddSubmonoid.toSubmonoid_closure (S : Set A) : (AddSubmonoid.toSubmonoid) (AddSubmonoid.closure S) = Submonoid.closure (Multiplicative.toAdd ⁻¹' S) := le_antisymm (AddSubmonoid.toSubmonoid.to_galoisConnection.l_le <| AddSubmonoid.closure_le.2 <| Submonoid.subset_closure (M := Multiplicative A)) (Submonoid.closure_le.2 <| AddSubmonoid.subset_closure (M := A)) theorem Submonoid.toAddSubmonoid'_closure (S : Set (Multiplicative A)) : Submonoid.toAddSubmonoid' (Submonoid.closure S) = AddSubmonoid.closure (Multiplicative.ofAdd ⁻¹' S) := le_antisymm (Submonoid.toAddSubmonoid'.to_galoisConnection.l_le <| Submonoid.closure_le.2 <| AddSubmonoid.subset_closure (M := A)) (AddSubmonoid.closure_le.2 <| Submonoid.subset_closure (M := Multiplicative A)) end namespace Submonoid variable {F : Type*} [FunLike F M N] [mc : MonoidHomClass F M N] open Set /-! ### `comap` and `map` -/ /-- The preimage of a submonoid along a monoid homomorphism is a submonoid. -/ @[to_additive "The preimage of an `AddSubmonoid` along an `AddMonoid` homomorphism is an `AddSubmonoid`."] def comap (f : F) (S : Submonoid N) : Submonoid M where carrier := f ⁻¹' S one_mem' := show f 1 ∈ S by rw [map_one]; exact S.one_mem mul_mem' ha hb := show f (_ * _) ∈ S by rw [map_mul]; exact S.mul_mem ha hb @[to_additive (attr := simp)] theorem coe_comap (S : Submonoid N) (f : F) : (S.comap f : Set M) = f ⁻¹' S := rfl @[to_additive (attr := simp)] theorem mem_comap {S : Submonoid N} {f : F} {x : M} : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl @[to_additive] theorem comap_comap (S : Submonoid P) (g : N →* P) (f : M →* N) : (S.comap g).comap f = S.comap (g.comp f) := rfl @[to_additive (attr := simp)] theorem comap_id (S : Submonoid P) : S.comap (MonoidHom.id P) = S := ext (by simp) /-- The image of a submonoid along a monoid homomorphism is a submonoid. -/ @[to_additive "The image of an `AddSubmonoid` along an `AddMonoid` homomorphism is an `AddSubmonoid`."] def map (f : F) (S : Submonoid M) : Submonoid N where carrier := f '' S one_mem' := ⟨1, S.one_mem, map_one f⟩ mul_mem' := by rintro _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩ exact ⟨x * y, S.mul_mem hx hy, by rw [map_mul]⟩ @[to_additive (attr := simp)] theorem coe_map (f : F) (S : Submonoid M) : (S.map f : Set N) = f '' S := rfl @[to_additive (attr := simp)] theorem map_coe_toMonoidHom (f : F) (S : Submonoid M) : S.map (f : M →* N) = S.map f := rfl @[to_additive (attr := simp)] theorem map_coe_toMulEquiv {F} [EquivLike F M N] [MulEquivClass F M N] (f : F) (S : Submonoid M) : S.map (f : M ≃* N) = S.map f := rfl @[to_additive (attr := simp)] theorem mem_map {f : F} {S : Submonoid M} {y : N} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y := Iff.rfl @[to_additive] theorem mem_map_of_mem (f : F) {S : Submonoid M} {x : M} (hx : x ∈ S) : f x ∈ S.map f := mem_image_of_mem f hx @[to_additive] theorem apply_coe_mem_map (f : F) (S : Submonoid M) (x : S) : f x ∈ S.map f := mem_map_of_mem f x.2 @[to_additive] theorem map_map (g : N →* P) (f : M →* N) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| image_image _ _ _ -- The simpNF linter says that the LHS can be simplified via `Submonoid.mem_map`. -- However this is a higher priority lemma. -- It seems the side condition `hf` is not applied by `simpNF`. -- https://github.com/leanprover/std4/issues/207 @[to_additive (attr := simp 1100, nolint simpNF)] theorem mem_map_iff_mem {f : F} (hf : Function.Injective f) {S : Submonoid M} {x : M} : f x ∈ S.map f ↔ x ∈ S := hf.mem_set_image @[to_additive] theorem map_le_iff_le_comap {f : F} {S : Submonoid M} {T : Submonoid N} : S.map f ≤ T ↔ S ≤ T.comap f := image_subset_iff @[to_additive] theorem gc_map_comap (f : F) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap @[to_additive] theorem map_le_of_le_comap {T : Submonoid N} {f : F} : S ≤ T.comap f → S.map f ≤ T := (gc_map_comap f).l_le @[to_additive] theorem le_comap_of_map_le {T : Submonoid N} {f : F} : S.map f ≤ T → S ≤ T.comap f := (gc_map_comap f).le_u @[to_additive] theorem le_comap_map {f : F} : S ≤ (S.map f).comap f := (gc_map_comap f).le_u_l _ @[to_additive] theorem map_comap_le {S : Submonoid N} {f : F} : (S.comap f).map f ≤ S := (gc_map_comap f).l_u_le _ @[to_additive] theorem monotone_map {f : F} : Monotone (map f) := (gc_map_comap f).monotone_l @[to_additive] theorem monotone_comap {f : F} : Monotone (comap f) := (gc_map_comap f).monotone_u @[to_additive (attr := simp)] theorem map_comap_map {f : F} : ((S.map f).comap f).map f = S.map f := (gc_map_comap f).l_u_l_eq_l _ @[to_additive (attr := simp)] theorem comap_map_comap {S : Submonoid N} {f : F} : ((S.comap f).map f).comap f = S.comap f := (gc_map_comap f).u_l_u_eq_u _ @[to_additive] theorem map_sup (S T : Submonoid M) (f : F) : (S ⊔ T).map f = S.map f ⊔ T.map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup @[to_additive] theorem map_iSup {ι : Sort*} (f : F) (s : ι → Submonoid M) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup @[to_additive] theorem map_inf (S T : Submonoid M) (f : F) (hf : Function.Injective f) : (S ⊓ T).map f = S.map f ⊓ T.map f := SetLike.coe_injective (Set.image_inter hf) @[to_additive] theorem map_iInf {ι : Sort*} [Nonempty ι] (f : F) (hf : Function.Injective f) (s : ι → Submonoid M) : (iInf s).map f = ⨅ i, (s i).map f := by apply SetLike.coe_injective simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ s) @[to_additive] theorem comap_inf (S T : Submonoid N) (f : F) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f := (gc_map_comap f : GaloisConnection (map f) (comap f)).u_inf @[to_additive] theorem comap_iInf {ι : Sort*} (f : F) (s : ι → Submonoid N) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf @[to_additive (attr := simp)] theorem map_bot (f : F) : (⊥ : Submonoid M).map f = ⊥ := (gc_map_comap f).l_bot @[to_additive (attr := simp)] theorem comap_top (f : F) : (⊤ : Submonoid N).comap f = ⊤ := (gc_map_comap f).u_top @[to_additive (attr := simp)] theorem map_id (S : Submonoid M) : S.map (MonoidHom.id M) = S := ext fun _ => ⟨fun ⟨_, h, rfl⟩ => h, fun h => ⟨_, h, rfl⟩⟩ section GaloisCoinsertion variable {ι : Type*} {f : F} /-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/ @[to_additive "`map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective."] def gciMapComap (hf : Function.Injective f) : GaloisCoinsertion (map f) (comap f) := (gc_map_comap f).toGaloisCoinsertion fun S x => by simp [mem_comap, mem_map, hf.eq_iff] variable (hf : Function.Injective f) include hf @[to_additive] theorem comap_map_eq_of_injective (S : Submonoid M) : (S.map f).comap f = S := (gciMapComap hf).u_l_eq _ @[to_additive] theorem comap_surjective_of_injective : Function.Surjective (comap f) := (gciMapComap hf).u_surjective @[to_additive] theorem map_injective_of_injective : Function.Injective (map f) := (gciMapComap hf).l_injective @[to_additive] theorem comap_inf_map_of_injective (S T : Submonoid M) : (S.map f ⊓ T.map f).comap f = S ⊓ T := (gciMapComap hf).u_inf_l _ _ @[to_additive] theorem comap_iInf_map_of_injective (S : ι → Submonoid M) : (⨅ i, (S i).map f).comap f = iInf S := (gciMapComap hf).u_iInf_l _ @[to_additive] theorem comap_sup_map_of_injective (S T : Submonoid M) : (S.map f ⊔ T.map f).comap f = S ⊔ T := (gciMapComap hf).u_sup_l _ _ @[to_additive] theorem comap_iSup_map_of_injective (S : ι → Submonoid M) : (⨆ i, (S i).map f).comap f = iSup S := (gciMapComap hf).u_iSup_l _ @[to_additive] theorem map_le_map_iff_of_injective {S T : Submonoid M} : S.map f ≤ T.map f ↔ S ≤ T := (gciMapComap hf).l_le_l_iff @[to_additive] theorem map_strictMono_of_injective : StrictMono (map f) := (gciMapComap hf).strictMono_l end GaloisCoinsertion section GaloisInsertion variable {ι : Type*} {f : F} /-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/ @[to_additive "`map f` and `comap f` form a `GaloisInsertion` when `f` is surjective."] def giMapComap (hf : Function.Surjective f) : GaloisInsertion (map f) (comap f) := (gc_map_comap f).toGaloisInsertion fun S x h => let ⟨y, hy⟩ := hf x mem_map.2 ⟨y, by simp [hy, h]⟩ variable (hf : Function.Surjective f) include hf @[to_additive] theorem map_comap_eq_of_surjective (S : Submonoid N) : (S.comap f).map f = S := (giMapComap hf).l_u_eq _ @[to_additive] theorem map_surjective_of_surjective : Function.Surjective (map f) := (giMapComap hf).l_surjective @[to_additive] theorem comap_injective_of_surjective : Function.Injective (comap f) := (giMapComap hf).u_injective @[to_additive] theorem map_inf_comap_of_surjective (S T : Submonoid N) : (S.comap f ⊓ T.comap f).map f = S ⊓ T := (giMapComap hf).l_inf_u _ _ @[to_additive] theorem map_iInf_comap_of_surjective (S : ι → Submonoid N) : (⨅ i, (S i).comap f).map f = iInf S := (giMapComap hf).l_iInf_u _ @[to_additive] theorem map_sup_comap_of_surjective (S T : Submonoid N) : (S.comap f ⊔ T.comap f).map f = S ⊔ T := (giMapComap hf).l_sup_u _ _ @[to_additive] theorem map_iSup_comap_of_surjective (S : ι → Submonoid N) : (⨆ i, (S i).comap f).map f = iSup S := (giMapComap hf).l_iSup_u _ @[to_additive] theorem comap_le_comap_iff_of_surjective {S T : Submonoid N} : S.comap f ≤ T.comap f ↔ S ≤ T := (giMapComap hf).u_le_u_iff @[to_additive] theorem comap_strictMono_of_surjective : StrictMono (comap f) := (giMapComap hf).strictMono_u end GaloisInsertion variable {M : Type*} [MulOneClass M] (S : Submonoid M) /-- The top submonoid is isomorphic to the monoid. -/ @[to_additive (attr := simps) "The top additive submonoid is isomorphic to the additive monoid."] def topEquiv : (⊤ : Submonoid M) ≃* M where toFun x := x invFun x := ⟨x, mem_top x⟩ left_inv x := x.eta _ right_inv _ := rfl map_mul' _ _ := rfl @[to_additive (attr := simp)] theorem topEquiv_toMonoidHom : ((topEquiv : _ ≃* M) : _ →* M) = (⊤ : Submonoid M).subtype := rfl /-- A subgroup is isomorphic to its image under an injective function. If you have an isomorphism, use `MulEquiv.submonoidMap` for better definitional equalities. -/ @[to_additive "An additive subgroup is isomorphic to its image under an injective function. If you have an isomorphism, use `AddEquiv.addSubmonoidMap` for better definitional equalities."] noncomputable def equivMapOfInjective (f : M →* N) (hf : Function.Injective f) : S ≃* S.map f := { Equiv.Set.image f S hf with map_mul' := fun _ _ => Subtype.ext (f.map_mul _ _) } @[to_additive (attr := simp)] theorem coe_equivMapOfInjective_apply (f : M →* N) (hf : Function.Injective f) (x : S) : (equivMapOfInjective S f hf x : N) = f x := rfl @[to_additive (attr := simp)] theorem closure_closure_coe_preimage {s : Set M} : closure (((↑) : closure s → M) ⁻¹' s) = ⊤ := eq_top_iff.2 fun x _ ↦ Subtype.recOn x fun _ hx' ↦ closure_induction (fun _ h ↦ subset_closure h) (one_mem _) (fun _ _ _ _ ↦ mul_mem) hx' /-- Given submonoids `s`, `t` of monoids `M`, `N` respectively, `s × t` as a submonoid of `M × N`. -/ @[to_additive prod "Given `AddSubmonoid`s `s`, `t` of `AddMonoid`s `A`, `B` respectively, `s × t` as an `AddSubmonoid` of `A × B`."] def prod (s : Submonoid M) (t : Submonoid N) : Submonoid (M × N) where carrier := s ×ˢ t one_mem' := ⟨s.one_mem, t.one_mem⟩ mul_mem' hp hq := ⟨s.mul_mem hp.1 hq.1, t.mul_mem hp.2 hq.2⟩ @[to_additive coe_prod] theorem coe_prod (s : Submonoid M) (t : Submonoid N) : (s.prod t : Set (M × N)) = (s : Set M) ×ˢ (t : Set N) := rfl @[to_additive mem_prod] theorem mem_prod {s : Submonoid M} {t : Submonoid N} {p : M × N} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := Iff.rfl @[to_additive prod_mono] theorem prod_mono {s₁ s₂ : Submonoid M} {t₁ t₂ : Submonoid N} (hs : s₁ ≤ s₂) (ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ := Set.prod_mono hs ht @[to_additive prod_top] theorem prod_top (s : Submonoid M) : s.prod (⊤ : Submonoid N) = s.comap (MonoidHom.fst M N) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] @[to_additive top_prod] theorem top_prod (s : Submonoid N) : (⊤ : Submonoid M).prod s = s.comap (MonoidHom.snd M N) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] @[to_additive (attr := simp) top_prod_top] theorem top_prod_top : (⊤ : Submonoid M).prod (⊤ : Submonoid N) = ⊤ := (top_prod _).trans <| comap_top _ @[to_additive bot_prod_bot] theorem bot_prod_bot : (⊥ : Submonoid M).prod (⊥ : Submonoid N) = ⊥ := SetLike.coe_injective <| by simp [coe_prod] /-- The product of submonoids is isomorphic to their product as monoids. -/ @[to_additive prodEquiv "The product of additive submonoids is isomorphic to their product as additive monoids"] def prodEquiv (s : Submonoid M) (t : Submonoid N) : s.prod t ≃* s × t := { (Equiv.Set.prod (s : Set M) (t : Set N)) with map_mul' := fun _ _ => rfl } open MonoidHom @[to_additive] theorem map_inl (s : Submonoid M) : s.map (inl M N) = s.prod ⊥ := ext fun p => ⟨fun ⟨_, hx, hp⟩ => hp ▸ ⟨hx, Set.mem_singleton 1⟩, fun ⟨hps, hp1⟩ => ⟨p.1, hps, Prod.ext rfl <| (Set.eq_of_mem_singleton hp1).symm⟩⟩ @[to_additive] theorem map_inr (s : Submonoid N) : s.map (inr M N) = prod ⊥ s := ext fun p => ⟨fun ⟨_, hx, hp⟩ => hp ▸ ⟨Set.mem_singleton 1, hx⟩, fun ⟨hp1, hps⟩ => ⟨p.2, hps, Prod.ext (Set.eq_of_mem_singleton hp1).symm rfl⟩⟩ @[to_additive (attr := simp) prod_bot_sup_bot_prod] theorem prod_bot_sup_bot_prod (s : Submonoid M) (t : Submonoid N) : (prod s ⊥) ⊔ (prod ⊥ t) = prod s t := (le_antisymm (sup_le (prod_mono (le_refl s) bot_le) (prod_mono bot_le (le_refl t)))) fun p hp => Prod.fst_mul_snd p ▸ mul_mem ((le_sup_left : prod s ⊥ ≤ prod s ⊥ ⊔ prod ⊥ t) ⟨hp.1, Set.mem_singleton 1⟩) ((le_sup_right : prod ⊥ t ≤ prod s ⊥ ⊔ prod ⊥ t) ⟨Set.mem_singleton 1, hp.2⟩) @[to_additive] theorem mem_map_equiv {f : M ≃* N} {K : Submonoid M} {x : N} : x ∈ K.map f.toMonoidHom ↔ f.symm x ∈ K := Set.mem_image_equiv @[to_additive] theorem map_equiv_eq_comap_symm (f : M ≃* N) (K : Submonoid M) : K.map f = K.comap f.symm := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) @[to_additive] theorem comap_equiv_eq_map_symm (f : N ≃* M) (K : Submonoid M) : K.comap f = K.map f.symm := (map_equiv_eq_comap_symm f.symm K).symm @[to_additive (attr := simp)] theorem map_equiv_top (f : M ≃* N) : (⊤ : Submonoid M).map f = ⊤ := SetLike.coe_injective <| Set.image_univ.trans f.surjective.range_eq @[to_additive le_prod_iff] theorem le_prod_iff {s : Submonoid M} {t : Submonoid N} {u : Submonoid (M × N)} : u ≤ s.prod t ↔ u.map (fst M N) ≤ s ∧ u.map (snd M N) ≤ t := by constructor · intro h constructor · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).1 · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).2 · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ h exact ⟨hH ⟨_, h, rfl⟩, hK ⟨_, h, rfl⟩⟩ @[to_additive prod_le_iff] theorem prod_le_iff {s : Submonoid M} {t : Submonoid N} {u : Submonoid (M × N)} : s.prod t ≤ u ↔ s.map (inl M N) ≤ u ∧ t.map (inr M N) ≤ u := by constructor · intro h constructor · rintro _ ⟨x, hx, rfl⟩ apply h exact ⟨hx, Submonoid.one_mem _⟩ · rintro _ ⟨x, hx, rfl⟩ apply h exact ⟨Submonoid.one_mem _, hx⟩ · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ ⟨h1, h2⟩ have h1' : inl M N x1 ∈ u := by apply hH simpa using h1 have h2' : inr M N x2 ∈ u := by apply hK simpa using h2 simpa using Submonoid.mul_mem _ h1' h2' @[to_additive closure_prod] theorem closure_prod {s : Set M} {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_of_le_comap _ <| closure_le.2 fun _x hx => subset_closure ⟨hx, ht⟩, map_le_of_le_comap _ <| closure_le.2 fun _y hy => subset_closure ⟨hs, hy⟩⟩) @[to_additive (attr := simp) closure_prod_zero] lemma closure_prod_one (s : Set M) : closure (s ×ˢ ({1} : Set N)) = (closure s).prod ⊥ := le_antisymm (closure_le.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨subset_closure, .rfl⟩) (prod_le_iff.2 ⟨ map_le_of_le_comap _ <| closure_le.2 fun _x hx => subset_closure ⟨hx, rfl⟩, by simp⟩) @[to_additive (attr := simp) closure_zero_prod] lemma closure_one_prod (t : Set N) : closure (({1} : Set M) ×ˢ t) = .prod ⊥ (closure t) := le_antisymm (closure_le.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨.rfl, subset_closure⟩) (prod_le_iff.2 ⟨by simp, map_le_of_le_comap _ <| closure_le.2 fun _y hy => subset_closure ⟨rfl, hy⟩⟩) end Submonoid namespace MonoidHom variable {F : Type*} [FunLike F M N] [mc : MonoidHomClass F M N] open Submonoid library_note "range copy pattern"/-- For many categories (monoids, modules, rings, ...) the set-theoretic image of a morphism `f` is a subobject of the codomain. When this is the case, it is useful to define the range of a morphism in such a way that the underlying carrier set of the range subobject is definitionally `Set.range f`. In particular this means that the types `↥(Set.range f)` and `↥f.range` are interchangeable without proof obligations. A convenient candidate definition for range which is mathematically correct is `map ⊤ f`, just as `Set.range` could have been defined as `f '' Set.univ`. However, this lacks the desired definitional convenience, in that it both does not match `Set.range`, and that it introduces a redundant `x ∈ ⊤` term which clutters proofs. In such a case one may resort to the `copy` pattern. A `copy` function converts the definitional problem for the carrier set of a subobject into a one-off propositional proof obligation which one discharges while writing the definition of the definitionally convenient range (the parameter `hs` in the example below). A good example is the case of a morphism of monoids. A convenient definition for `MonoidHom.mrange` would be `(⊤ : Submonoid M).map f`. However since this lacks the required definitional convenience, we first define `Submonoid.copy` as follows: ```lean protected def copy (S : Submonoid M) (s : Set M) (hs : s = S) : Submonoid M := { carrier := s, one_mem' := hs.symm ▸ S.one_mem', mul_mem' := hs.symm ▸ S.mul_mem' } ``` and then finally define: ```lean def mrange (f : M →* N) : Submonoid N := ((⊤ : Submonoid M).map f).copy (Set.range f) Set.image_univ.symm ``` -/ /-- The range of a monoid homomorphism is a submonoid. See Note [range copy pattern]. -/ @[to_additive "The range of an `AddMonoidHom` is an `AddSubmonoid`."] def mrange (f : F) : Submonoid N := ((⊤ : Submonoid M).map f).copy (Set.range f) Set.image_univ.symm @[to_additive (attr := simp)] theorem coe_mrange (f : F) : (mrange f : Set N) = Set.range f := rfl @[to_additive (attr := simp)] theorem mem_mrange {f : F} {y : N} : y ∈ mrange f ↔ ∃ x, f x = y := Iff.rfl @[to_additive] lemma mrange_comp {O : Type*} [MulOneClass O] (f : N →* O) (g : M →* N) : mrange (f.comp g) = (mrange g).map f := SetLike.coe_injective <| Set.range_comp f _ @[to_additive] theorem mrange_eq_map (f : F) : mrange f = (⊤ : Submonoid M).map f := Submonoid.copy_eq _ @[to_additive (attr := simp)] theorem mrange_id : mrange (MonoidHom.id M) = ⊤ := by simp [mrange_eq_map] @[to_additive] theorem map_mrange (g : N →* P) (f : M →* N) : (mrange f).map g = mrange (comp g f) := by simpa only [mrange_eq_map] using (⊤ : Submonoid M).map_map g f @[to_additive] theorem mrange_eq_top {f : F} : mrange f = (⊤ : Submonoid N) ↔ Surjective f := SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_mrange, coe_top]) Set.range_eq_univ @[deprecated (since := "2024-11-11")] alias mrange_top_iff_surjective := mrange_eq_top /-- The range of a surjective monoid hom is the whole of the codomain. -/ @[to_additive (attr := simp) "The range of a surjective `AddMonoid` hom is the whole of the codomain."] theorem mrange_eq_top_of_surjective (f : F) (hf : Function.Surjective f) : mrange f = (⊤ : Submonoid N) := mrange_eq_top.2 hf @[deprecated (since := "2024-11-11")] alias mrange_top_of_surjective := mrange_eq_top_of_surjective @[to_additive] theorem mclosure_preimage_le (f : F) (s : Set N) : closure (f ⁻¹' s) ≤ (closure s).comap f := closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx /-- The image under a monoid hom of the submonoid generated by a set equals the submonoid generated by the image of the set. -/ @[to_additive "The image under an `AddMonoid` hom of the `AddSubmonoid` generated by a set equals the `AddSubmonoid` generated by the image of the set."] theorem map_mclosure (f : F) (s : Set M) : (closure s).map f = closure (f '' s) := Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) (Submonoid.gi N).gc (Submonoid.gi M).gc fun _ ↦ rfl @[to_additive (attr := simp)] theorem mclosure_range (f : F) : closure (Set.range f) = mrange f := by rw [← Set.image_univ, ← map_mclosure, mrange_eq_map, closure_univ] /-- Restriction of a monoid hom to a submonoid of the domain. -/ @[to_additive "Restriction of an `AddMonoid` hom to an `AddSubmonoid` of the domain."] def restrict {N S : Type*} [MulOneClass N] [SetLike S M] [SubmonoidClass S M] (f : M →* N) (s : S) : s →* N := f.comp (SubmonoidClass.subtype _) @[to_additive (attr := simp)] theorem restrict_apply {N S : Type*} [MulOneClass N] [SetLike S M] [SubmonoidClass S M] (f : M →* N) (s : S) (x : s) : f.restrict s x = f x := rfl @[to_additive (attr := simp)] theorem restrict_mrange (f : M →* N) : mrange (f.restrict S) = S.map f := by simp [SetLike.ext_iff] /-- Restriction of a monoid hom to a submonoid of the codomain. -/ @[to_additive (attr := simps apply) "Restriction of an `AddMonoid` hom to an `AddSubmonoid` of the codomain."] def codRestrict {S} [SetLike S N] [SubmonoidClass S N] (f : M →* N) (s : S) (h : ∀ x, f x ∈ s) : M →* s where toFun n := ⟨f n, h n⟩ map_one' := Subtype.eq f.map_one map_mul' x y := Subtype.eq (f.map_mul x y) @[to_additive (attr := simp)] lemma injective_codRestrict {S} [SetLike S N] [SubmonoidClass S N] (f : M →* N) (s : S) (h : ∀ x, f x ∈ s) : Function.Injective (f.codRestrict s h) ↔ Function.Injective f := ⟨fun H _ _ hxy ↦ H <| Subtype.eq hxy, fun H _ _ hxy ↦ H (congr_arg Subtype.val hxy)⟩ /-- Restriction of a monoid hom to its range interpreted as a submonoid. -/ @[to_additive "Restriction of an `AddMonoid` hom to its range interpreted as a submonoid."] def mrangeRestrict {N} [MulOneClass N] (f : M →* N) : M →* (mrange f) := (f.codRestrict (mrange f)) fun x => ⟨x, rfl⟩ @[to_additive (attr := simp)] theorem coe_mrangeRestrict {N} [MulOneClass N] (f : M →* N) (x : M) : (f.mrangeRestrict x : N) = f x := rfl @[to_additive] theorem mrangeRestrict_surjective (f : M →* N) : Function.Surjective f.mrangeRestrict := fun ⟨_, ⟨x, rfl⟩⟩ => ⟨x, rfl⟩ /-- The multiplicative kernel of a monoid hom is the submonoid of elements `x : G` such that `f x = 1` -/ @[to_additive "The additive kernel of an `AddMonoid` hom is the `AddSubmonoid` of elements such that `f x = 0`"] def mker (f : F) : Submonoid M := (⊥ : Submonoid N).comap f @[to_additive (attr := simp)] theorem mem_mker {f : F} {x : M} : x ∈ mker f ↔ f x = 1 := Iff.rfl @[to_additive] theorem coe_mker (f : F) : (mker f : Set M) = (f : M → N) ⁻¹' {1} := rfl @[to_additive] instance decidableMemMker [DecidableEq N] (f : F) : DecidablePred (· ∈ mker f) := fun x => decidable_of_iff (f x = 1) mem_mker @[to_additive] theorem comap_mker (g : N →* P) (f : M →* N) : (mker g).comap f = mker (comp g f) := rfl @[to_additive (attr := simp)] theorem comap_bot' (f : F) : (⊥ : Submonoid N).comap f = mker f := rfl @[to_additive (attr := simp)] theorem restrict_mker (f : M →* N) : mker (f.restrict S) = (MonoidHom.mker f).comap S.subtype := rfl @[to_additive] theorem mrangeRestrict_mker (f : M →* N) : mker (mrangeRestrict f) = mker f := by ext x change (⟨f x, _⟩ : mrange f) = ⟨1, _⟩ ↔ f x = 1 simp @[to_additive (attr := simp)] theorem mker_one : mker (1 : M →* N) = ⊤ := by ext simp [mem_mker] @[to_additive prod_map_comap_prod'] theorem prod_map_comap_prod' {M' : Type*} {N' : Type*} [MulOneClass M'] [MulOneClass N'] (f : M →* N) (g : M' →* N') (S : Submonoid N) (S' : Submonoid 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 _ _ @[to_additive mker_prod_map] theorem mker_prod_map {M' : Type*} {N' : Type*} [MulOneClass M'] [MulOneClass N'] (f : M →* N) (g : M' →* N') : mker (prodMap f g) = (mker f).prod (mker g) := by rw [← comap_bot', ← comap_bot', ← comap_bot', ← prod_map_comap_prod', bot_prod_bot] @[to_additive (attr := simp)] theorem mker_inl : mker (inl M N) = ⊥ := by ext x simp [mem_mker] @[to_additive (attr := simp)] theorem mker_inr : mker (inr M N) = ⊥ := by ext x simp [mem_mker] @[to_additive (attr := simp)] lemma mker_fst : mker (fst M N) = .prod ⊥ ⊤ := SetLike.ext fun _ => (iff_of_eq (and_true _)).symm @[to_additive (attr := simp)] lemma mker_snd : mker (snd M N) = .prod ⊤ ⊥ := SetLike.ext fun _ => (iff_of_eq (true_and _)).symm /-- The `MonoidHom` from the preimage of a submonoid to itself. -/ @[to_additive (attr := simps) "the `AddMonoidHom` from the preimage of an additive submonoid to itself."] def submonoidComap (f : M →* N) (N' : Submonoid N) : N'.comap f →* N' where toFun x := ⟨f x, x.2⟩ map_one' := Subtype.eq f.map_one map_mul' x y := Subtype.eq (f.map_mul x y) @[to_additive] lemma submonoidComap_surjective_of_surjective (f : M →* N) (N' : Submonoid N) (hf : Surjective f) : Surjective (f.submonoidComap N') := fun y ↦ by obtain ⟨x, hx⟩ := hf y use ⟨x, mem_comap.mpr (hx ▸ y.2)⟩ apply Subtype.val_injective simp [hx] /-- The `MonoidHom` from a submonoid to its image. See `MulEquiv.SubmonoidMap` for a variant for `MulEquiv`s. -/ @[to_additive (attr := simps) "the `AddMonoidHom` from an additive submonoid to its image. See `AddEquiv.AddSubmonoidMap` for a variant for `AddEquiv`s."] def submonoidMap (f : M →* N) (M' : Submonoid M) : M' →* M'.map f where toFun x := ⟨f x, ⟨x, x.2, rfl⟩⟩ map_one' := Subtype.eq <| f.map_one map_mul' x y := Subtype.eq <| f.map_mul x y @[to_additive] theorem submonoidMap_surjective (f : M →* N) (M' : Submonoid M) : Function.Surjective (f.submonoidMap M') := by rintro ⟨_, x, hx, rfl⟩ exact ⟨⟨x, hx⟩, rfl⟩ end MonoidHom namespace Submonoid open MonoidHom @[to_additive] theorem mrange_inl : mrange (inl M N) = prod ⊤ ⊥ := by simpa only [mrange_eq_map] using map_inl ⊤ @[to_additive] theorem mrange_inr : mrange (inr M N) = prod ⊥ ⊤ := by simpa only [mrange_eq_map] using map_inr ⊤ @[to_additive] theorem mrange_inl' : mrange (inl M N) = comap (snd M N) ⊥ := mrange_inl.trans (top_prod _) @[to_additive] theorem mrange_inr' : mrange (inr M N) = comap (fst M N) ⊥ := mrange_inr.trans (prod_top _) @[to_additive (attr := simp)] theorem mrange_fst : mrange (fst M N) = ⊤ := mrange_eq_top_of_surjective (fst M N) <| @Prod.fst_surjective _ _ ⟨1⟩ @[to_additive (attr := simp)] theorem mrange_snd : mrange (snd M N) = ⊤ := mrange_eq_top_of_surjective (snd M N) <| @Prod.snd_surjective _ _ ⟨1⟩ @[to_additive prod_eq_bot_iff] theorem prod_eq_bot_iff {s : Submonoid M} {t : Submonoid N} : s.prod t = ⊥ ↔ s = ⊥ ∧ t = ⊥ := by simp only [eq_bot_iff, prod_le_iff, (gc_map_comap _).le_iff_le, comap_bot', mker_inl, mker_inr] @[to_additive prod_eq_top_iff] theorem prod_eq_top_iff {s : Submonoid M} {t : Submonoid N} : s.prod t = ⊤ ↔ s = ⊤ ∧ t = ⊤ := by simp only [eq_top_iff, le_prod_iff, ← (gc_map_comap _).le_iff_le, ← mrange_eq_map, mrange_fst, mrange_snd] @[to_additive (attr := simp)] theorem mrange_inl_sup_mrange_inr : mrange (inl M N) ⊔ mrange (inr M N) = ⊤ := by simp only [mrange_inl, mrange_inr, prod_bot_sup_bot_prod, top_prod_top] /-- The monoid hom associated to an inclusion of submonoids. -/ @[to_additive "The `AddMonoid` hom associated to an inclusion of submonoids."] def inclusion {S T : Submonoid M} (h : S ≤ T) : S →* T := S.subtype.codRestrict _ fun x => h x.2 @[to_additive (attr := simp)] theorem mrange_subtype (s : Submonoid M) : mrange s.subtype = s := SetLike.coe_injective <| (coe_mrange _).trans <| Subtype.range_coe -- `alias` doesn't add the deprecation suggestion to the `to_additive` version -- see https://github.com/leanprover-community/mathlib4/issues/19424 @[to_additive] alias range_subtype := mrange_subtype attribute [deprecated mrange_subtype (since := "2024-11-25")] range_subtype attribute [deprecated AddSubmonoid.mrange_subtype (since := "2024-11-25")] AddSubmonoid.range_subtype @[to_additive] theorem eq_top_iff' : S = ⊤ ↔ ∀ x : M, x ∈ S := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ @[to_additive] theorem eq_bot_iff_forall : S = ⊥ ↔ ∀ x ∈ S, x = (1 : M) := SetLike.ext_iff.trans <| by simp +contextual [iff_def, S.one_mem] @[to_additive] theorem eq_bot_of_subsingleton [Subsingleton S] : S = ⊥ := by rw [eq_bot_iff_forall] intro y hy simpa using congr_arg ((↑) : S → M) <| Subsingleton.elim (⟨y, hy⟩ : S) 1 @[to_additive] theorem nontrivial_iff_exists_ne_one (S : Submonoid M) : Nontrivial S ↔ ∃ x ∈ S, x ≠ (1 : M) := calc Nontrivial S ↔ ∃ x : S, x ≠ 1 := nontrivial_iff_exists_ne 1 _ ↔ ∃ (x : _) (hx : x ∈ S), (⟨x, hx⟩ : S) ≠ ⟨1, S.one_mem⟩ := Subtype.exists _ ↔ ∃ x ∈ S, x ≠ (1 : M) := by simp [Ne] /-- A submonoid is either the trivial submonoid or nontrivial. -/ @[to_additive "An additive submonoid is either the trivial additive submonoid or nontrivial."] theorem bot_or_nontrivial (S : Submonoid M) : S = ⊥ ∨ Nontrivial S := by simp only [eq_bot_iff_forall, nontrivial_iff_exists_ne_one, ← not_forall, ← Classical.not_imp, Classical.em] /-- A submonoid is either the trivial submonoid or contains a nonzero element. -/ @[to_additive "An additive submonoid is either the trivial additive submonoid or contains a nonzero element."] theorem bot_or_exists_ne_one (S : Submonoid M) : S = ⊥ ∨ ∃ x ∈ S, x ≠ (1 : M) := S.bot_or_nontrivial.imp_right S.nontrivial_iff_exists_ne_one.mp end Submonoid namespace MulEquiv variable {S} {T : Submonoid M} /-- Makes the identity isomorphism from a proof that two submonoids of a multiplicative monoid are equal. -/ @[to_additive "Makes the identity additive isomorphism from a proof two submonoids of an additive monoid are equal."] def submonoidCongr (h : S = T) : S ≃* T := { Equiv.setCongr <| congr_arg _ h with map_mul' := fun _ _ => rfl } -- this name is primed so that the version to `f.range` instead of `f.mrange` can be unprimed. /-- A monoid homomorphism `f : M →* N` with a left-inverse `g : N → M` defines a multiplicative equivalence between `M` and `f.mrange`. This is a bidirectional version of `MonoidHom.mrange_restrict`. -/ @[to_additive (attr := simps +simpRhs) "An additive monoid homomorphism `f : M →+ N` with a left-inverse `g : N → M` defines an additive equivalence between `M` and `f.mrange`. This is a bidirectional version of `AddMonoidHom.mrange_restrict`. "] def ofLeftInverse' (f : M →* N) {g : N → M} (h : Function.LeftInverse g f) : M ≃* MonoidHom.mrange f := { f.mrangeRestrict with toFun := f.mrangeRestrict invFun := g ∘ (MonoidHom.mrange f).subtype left_inv := h right_inv := fun x => Subtype.ext <| let ⟨x', hx'⟩ := MonoidHom.mem_mrange.mp x.2 show f (g x) = x by rw [← hx', h x'] } /-- A `MulEquiv` `φ` between two monoids `M` and `N` induces a `MulEquiv` between a submonoid `S ≤ M` and the submonoid `φ(S) ≤ N`. See `MonoidHom.submonoidMap` for a variant for `MonoidHom`s. -/ @[to_additive "An `AddEquiv` `φ` between two additive monoids `M` and `N` induces an `AddEquiv` between a submonoid `S ≤ M` and the submonoid `φ(S) ≤ N`. See `AddMonoidHom.addSubmonoidMap` for a variant for `AddMonoidHom`s."] def submonoidMap (e : M ≃* N) (S : Submonoid M) : S ≃* S.map e := { (e : M ≃ N).image S with map_mul' := fun _ _ => Subtype.ext (map_mul e _ _) } @[to_additive (attr := simp)] theorem coe_submonoidMap_apply (e : M ≃* N) (S : Submonoid M) (g : S) : ((submonoidMap e S g : S.map (e : M →* N)) : N) = e g := rfl @[to_additive (attr := simp) AddEquiv.add_submonoid_map_symm_apply] theorem submonoidMap_symm_apply (e : M ≃* N) (S : Submonoid M) (g : S.map (e : M →* N)) : (e.submonoidMap S).symm g = ⟨e.symm g, SetLike.mem_coe.1 <| Set.mem_image_equiv.1 g.2⟩ := rfl end MulEquiv @[to_additive (attr := simp)] theorem Submonoid.equivMapOfInjective_coe_mulEquiv (e : M ≃* N) : S.equivMapOfInjective (e : M →* N) (EquivLike.injective e) = e.submonoidMap S := by ext rfl @[to_additive] instance Submonoid.faithfulSMul {M' α : Type*} [MulOneClass M'] [SMul M' α] {S : Submonoid M'} [FaithfulSMul M' α] : FaithfulSMul S α := ⟨fun h => Subtype.ext <| eq_of_smul_eq_smul h⟩ section Units namespace Submonoid /-- The multiplicative equivalence between the type of units of `M` and the submonoid of unit elements of `M`. -/ @[to_additive (attr := simps!) " The additive equivalence between the type of additive units of `M` and the additive submonoid whose elements are the additive units of `M`. "] noncomputable def unitsTypeEquivIsUnitSubmonoid [Monoid M] : Mˣ ≃* IsUnit.submonoid M where toFun x := ⟨x, Units.isUnit x⟩ invFun x := x.prop.unit left_inv _ := IsUnit.unit_of_val_units _ right_inv x := by simp_rw [IsUnit.unit_spec] map_mul' x y := by simp_rw [Units.val_mul]; rfl end Submonoid end Units open AddSubmonoid Set namespace Nat @[simp] lemma addSubmonoid_closure_one : closure ({1} : Set ℕ) = ⊤ := by refine (eq_top_iff' _).2 <| Nat.rec (zero_mem _) ?_ simp_rw [Nat.succ_eq_add_one] exact fun n hn ↦ AddSubmonoid.add_mem _ hn <| subset_closure <| Set.mem_singleton _ end Nat namespace Submonoid variable {F : Type*} [FunLike F M N] [mc : MonoidHomClass F M N] @[to_additive] theorem map_comap_eq (f : F) (S : Submonoid N) : (S.comap f).map f = S ⊓ MonoidHom.mrange f := SetLike.coe_injective Set.image_preimage_eq_inter_range @[to_additive] theorem map_comap_eq_self {f : F} {S : Submonoid N} (h : S ≤ MonoidHom.mrange f) : (S.comap f).map f = S := by simpa only [inf_of_le_left h] using map_comap_eq f S @[to_additive] theorem map_comap_eq_self_of_surjective {f : F} (h : Function.Surjective f) {S : Submonoid N} : map f (comap f S) = S := map_comap_eq_self (MonoidHom.mrange_eq_top_of_surjective _ h ▸ le_top) end Submonoid
Mathlib/Algebra/Group/Submonoid/Operations.lean
1,225
1,225
/- Copyright (c) 2021 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Ines Wright, Joachim Breitner -/ import Mathlib.GroupTheory.Solvable import Mathlib.GroupTheory.Sylow import Mathlib.Algebra.Group.Subgroup.Order import Mathlib.GroupTheory.Commutator.Finite /-! # Nilpotent groups An API for nilpotent groups, that is, groups for which the upper central series reaches `⊤`. ## Main definitions Recall that if `H K : Subgroup G` then `⁅H, K⁆ : Subgroup G` is the subgroup of `G` generated by the commutators `hkh⁻¹k⁻¹`. Recall also Lean's conventions that `⊤` denotes the subgroup `G` of `G`, and `⊥` denotes the trivial subgroup `{1}`. * `upperCentralSeries G : ℕ → Subgroup G` : the upper central series of a group `G`. This is an increasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊥` and `H (n + 1) / H n` is the centre of `G / H n`. * `lowerCentralSeries G : ℕ → Subgroup G` : the lower central series of a group `G`. This is a decreasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊤` and `H (n + 1) = ⁅H n, G⁆`. * `IsNilpotent` : A group G is nilpotent if its upper central series reaches `⊤`, or equivalently if its lower central series reaches `⊥`. * `Group.nilpotencyClass` : the length of the upper central series of a nilpotent group. * `IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop` and * `IsDescendingCentralSeries (H : ℕ → Subgroup G) : Prop` : Note that in the literature a "central series" for a group is usually defined to be a *finite* sequence of normal subgroups `H 0`, `H 1`, ..., starting at `⊤`, finishing at `⊥`, and with each `H n / H (n + 1)` central in `G / H (n + 1)`. In this formalisation it is convenient to have two weaker predicates on an infinite sequence of subgroups `H n` of `G`: we say a sequence is a *descending central series* if it starts at `G` and `⁅H n, ⊤⁆ ⊆ H (n + 1)` for all `n`. Note that this series may not terminate at `⊥`, and the `H i` need not be normal. Similarly a sequence is an *ascending central series* if `H 0 = ⊥` and `⁅H (n + 1), ⊤⁆ ⊆ H n` for all `n`, again with no requirement that the series reaches `⊤` or that the `H i` are normal. ## Main theorems `G` is *defined* to be nilpotent if the upper central series reaches `⊤`. * `nilpotent_iff_finite_ascending_central_series` : `G` is nilpotent iff some ascending central series reaches `⊤`. * `nilpotent_iff_finite_descending_central_series` : `G` is nilpotent iff some descending central series reaches `⊥`. * `nilpotent_iff_lower` : `G` is nilpotent iff the lower central series reaches `⊥`. * The `Group.nilpotencyClass` can likewise be obtained from these equivalent definitions, see `least_ascending_central_series_length_eq_nilpotencyClass`, `least_descending_central_series_length_eq_nilpotencyClass` and `lowerCentralSeries_length_eq_nilpotencyClass`. * If `G` is nilpotent, then so are its subgroups, images, quotients and preimages. Binary and finite products of nilpotent groups are nilpotent. Infinite products are nilpotent if their nilpotent class is bounded. Corresponding lemmas about the `Group.nilpotencyClass` are provided. * The `Group.nilpotencyClass` of `G ⧸ center G` is given explicitly, and an induction principle is derived from that. * `IsNilpotent.to_isSolvable`: If `G` is nilpotent, it is solvable. ## Warning A "central series" is usually defined to be a finite sequence of normal subgroups going from `⊥` to `⊤` with the property that each subquotient is contained within the centre of the associated quotient of `G`. This means that if `G` is not nilpotent, then none of what we have called `upperCentralSeries G`, `lowerCentralSeries G` or the sequences satisfying `IsAscendingCentralSeries` or `IsDescendingCentralSeries` are actually central series. Note that the fact that the upper and lower central series are not central series if `G` is not nilpotent is a standard abuse of notation. -/ open Subgroup section WithGroup variable {G : Type*} [Group G] (H : Subgroup G) [Normal H] /-- If `H` is a normal subgroup of `G`, then the set `{x : G | ∀ y : G, x*y*x⁻¹*y⁻¹ ∈ H}` is a subgroup of `G` (because it is the preimage in `G` of the centre of the quotient group `G/H`.) -/ def upperCentralSeriesStep : Subgroup G where carrier := { x : G | ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ H } one_mem' y := by simp [Subgroup.one_mem] mul_mem' {a b} ha hb y := by convert Subgroup.mul_mem _ (ha (b * y * b⁻¹)) (hb y) using 1 group inv_mem' {x} hx y := by specialize hx y⁻¹ rw [mul_assoc, inv_inv] at hx ⊢ exact Subgroup.Normal.mem_comm inferInstance hx theorem mem_upperCentralSeriesStep (x : G) : x ∈ upperCentralSeriesStep H ↔ ∀ y, x * y * x⁻¹ * y⁻¹ ∈ H := Iff.rfl open QuotientGroup /-- The proof that `upperCentralSeriesStep H` is the preimage of the centre of `G/H` under the canonical surjection. -/ theorem upperCentralSeriesStep_eq_comap_center : upperCentralSeriesStep H = Subgroup.comap (mk' H) (center (G ⧸ H)) := by ext rw [mem_comap, mem_center_iff, forall_mk] apply forall_congr' intro y rw [coe_mk', ← QuotientGroup.mk_mul, ← QuotientGroup.mk_mul, eq_comm, eq_iff_div_mem, div_eq_mul_inv, mul_inv_rev, mul_assoc] instance : Normal (upperCentralSeriesStep H) := by rw [upperCentralSeriesStep_eq_comap_center] infer_instance variable (G) /-- An auxiliary type-theoretic definition defining both the upper central series of a group, and a proof that it is normal, all in one go. -/ def upperCentralSeriesAux : ℕ → Σ'H : Subgroup G, Normal H | 0 => ⟨⊥, inferInstance⟩ | n + 1 => let un := upperCentralSeriesAux n let _un_normal := un.2 ⟨upperCentralSeriesStep un.1, inferInstance⟩ /-- `upperCentralSeries G n` is the `n`th term in the upper central series of `G`. -/ def upperCentralSeries (n : ℕ) : Subgroup G := (upperCentralSeriesAux G n).1 instance upperCentralSeries_normal (n : ℕ) : Normal (upperCentralSeries G n) := (upperCentralSeriesAux G n).2 @[simp] theorem upperCentralSeries_zero : upperCentralSeries G 0 = ⊥ := rfl @[simp] theorem upperCentralSeries_one : upperCentralSeries G 1 = center G := by ext simp only [upperCentralSeries, upperCentralSeriesAux, upperCentralSeriesStep, Subgroup.mem_center_iff, mem_mk, mem_bot, Set.mem_setOf_eq] exact forall_congr' fun y => by rw [mul_inv_eq_one, mul_inv_eq_iff_eq_mul, eq_comm] variable {G} /-- The `n+1`st term of the upper central series `H i` has underlying set equal to the `x` such that `⁅x,G⁆ ⊆ H n`. -/ theorem mem_upperCentralSeries_succ_iff {n : ℕ} {x : G} : x ∈ upperCentralSeries G (n + 1) ↔ ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ upperCentralSeries G n := Iff.rfl @[simp] lemma comap_upperCentralSeries {H : Type*} [Group H] (e : H ≃* G) : ∀ n, (upperCentralSeries G n).comap e = upperCentralSeries H n | 0 => by simpa [MonoidHom.ker_eq_bot_iff] using e.injective | n + 1 => by ext simp [mem_upperCentralSeries_succ_iff, ← comap_upperCentralSeries e n, ← e.toEquiv.forall_congr_right] namespace Group variable (G) in -- `IsNilpotent` is already defined in the root namespace (for elements of rings). -- TODO: Rename it to `IsNilpotentElement`? /-- A group `G` is nilpotent if its upper central series is eventually `G`. -/ @[mk_iff] class IsNilpotent (G : Type*) [Group G] : Prop where nilpotent' : ∃ n : ℕ, upperCentralSeries G n = ⊤ lemma IsNilpotent.nilpotent (G : Type*) [Group G] [IsNilpotent G] : ∃ n : ℕ, upperCentralSeries G n = ⊤ := Group.IsNilpotent.nilpotent' lemma isNilpotent_congr {H : Type*} [Group H] (e : G ≃* H) : IsNilpotent G ↔ IsNilpotent H := by simp_rw [isNilpotent_iff] refine exists_congr fun n ↦ ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · simp [← Subgroup.comap_top e.symm.toMonoidHom, ← h] · simp [← Subgroup.comap_top e.toMonoidHom, ← h] @[simp] lemma isNilpotent_top : IsNilpotent (⊤ : Subgroup G) ↔ IsNilpotent G := isNilpotent_congr Subgroup.topEquiv variable (G) in /-- A group `G` is virtually nilpotent if it has a nilpotent cofinite subgroup `N`. -/ def IsVirtuallyNilpotent : Prop := ∃ N : Subgroup G, IsNilpotent N ∧ FiniteIndex N lemma IsNilpotent.isVirtuallyNilpotent (hG : IsNilpotent G) : IsVirtuallyNilpotent G := ⟨⊤, by simpa, inferInstance⟩ end Group open Group /-- A sequence of subgroups of `G` is an ascending central series if `H 0` is trivial and `⁅H (n + 1), G⁆ ⊆ H n` for all `n`. Note that we do not require that `H n = G` for some `n`. -/ def IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop := H 0 = ⊥ ∧ ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H n /-- A sequence of subgroups of `G` is a descending central series if `H 0` is `G` and `⁅H n, G⁆ ⊆ H (n + 1)` for all `n`. Note that we do not require that `H n = {1}` for some `n`. -/ def IsDescendingCentralSeries (H : ℕ → Subgroup G) := H 0 = ⊤ ∧ ∀ (x : G) (n : ℕ), x ∈ H n → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) /-- Any ascending central series for a group is bounded above by the upper central series. -/ theorem ascending_central_series_le_upper (H : ℕ → Subgroup G) (hH : IsAscendingCentralSeries H) : ∀ n : ℕ, H n ≤ upperCentralSeries G n | 0 => hH.1.symm ▸ le_refl ⊥ | n + 1 => by intro x hx rw [mem_upperCentralSeries_succ_iff] exact fun y => ascending_central_series_le_upper H hH n (hH.2 x n hx y) variable (G) /-- The upper central series of a group is an ascending central series. -/ theorem upperCentralSeries_isAscendingCentralSeries : IsAscendingCentralSeries (upperCentralSeries G) := ⟨rfl, fun _x _n h => h⟩ theorem upperCentralSeries_mono : Monotone (upperCentralSeries G) := by refine monotone_nat_of_le_succ ?_ intro n x hx y rw [mul_assoc, mul_assoc, ← mul_assoc y x⁻¹ y⁻¹] exact mul_mem hx (Normal.conj_mem (upperCentralSeries_normal G n) x⁻¹ (inv_mem hx) y) /-- A group `G` is nilpotent iff there exists an ascending central series which reaches `G` in finitely many steps. -/ theorem nilpotent_iff_finite_ascending_central_series : IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsAscendingCentralSeries H ∧ H n = ⊤ := by constructor · rintro ⟨n, nH⟩ exact ⟨_, _, upperCentralSeries_isAscendingCentralSeries G, nH⟩ · rintro ⟨n, H, hH, hn⟩ use n rw [eq_top_iff, ← hn] exact ascending_central_series_le_upper H hH n theorem is_descending_rev_series_of_is_ascending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊤) (hasc : IsAscendingCentralSeries H) : IsDescendingCentralSeries fun m : ℕ => H (n - m) := by obtain ⟨h0, hH⟩ := hasc refine ⟨hn, fun x m hx g => ?_⟩ dsimp at hx by_cases hm : n ≤ m · rw [tsub_eq_zero_of_le hm, h0, Subgroup.mem_bot] at hx subst hx rw [show (1 : G) * g * (1⁻¹ : G) * g⁻¹ = 1 by group] exact Subgroup.one_mem _ · push_neg at hm apply hH convert hx using 1 rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right] @[deprecated (since := "2024-12-25")] alias is_decending_rev_series_of_is_ascending := is_descending_rev_series_of_is_ascending theorem is_ascending_rev_series_of_is_descending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊥) (hdesc : IsDescendingCentralSeries H) : IsAscendingCentralSeries fun m : ℕ => H (n - m) := by obtain ⟨h0, hH⟩ := hdesc refine ⟨hn, fun x m hx g => ?_⟩ dsimp only at hx ⊢ by_cases hm : n ≤ m · have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm rw [hnm, h0] exact mem_top _ · push_neg at hm convert hH x _ hx g using 1 rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right] /-- A group `G` is nilpotent iff there exists a descending central series which reaches the trivial group in a finite time. -/ theorem nilpotent_iff_finite_descending_central_series : IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsDescendingCentralSeries H ∧ H n = ⊥ := by rw [nilpotent_iff_finite_ascending_central_series] constructor · rintro ⟨n, H, hH, hn⟩ refine ⟨n, fun m => H (n - m), is_descending_rev_series_of_is_ascending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 · rintro ⟨n, H, hH, hn⟩ refine ⟨n, fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 /-- The lower central series of a group `G` is a sequence `H n` of subgroups of `G`, defined by `H 0` is all of `G` and for `n≥1`, `H (n + 1) = ⁅H n, G⁆` -/ def lowerCentralSeries (G : Type*) [Group G] : ℕ → Subgroup G | 0 => ⊤ | n + 1 => ⁅lowerCentralSeries G n, ⊤⁆ variable {G} @[simp] theorem lowerCentralSeries_zero : lowerCentralSeries G 0 = ⊤ := rfl @[simp] theorem lowerCentralSeries_one : lowerCentralSeries G 1 = commutator G := rfl theorem mem_lowerCentralSeries_succ_iff (n : ℕ) (q : G) : q ∈ lowerCentralSeries G (n + 1) ↔ q ∈ closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } := Iff.rfl theorem lowerCentralSeries_succ (n : ℕ) : lowerCentralSeries G (n + 1) = closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } := rfl instance lowerCentralSeries_normal (n : ℕ) : Normal (lowerCentralSeries G n) := by induction' n with d hd · exact (⊤ : Subgroup G).normal_of_characteristic · exact @Subgroup.commutator_normal _ _ (lowerCentralSeries G d) ⊤ hd _ theorem lowerCentralSeries_antitone : Antitone (lowerCentralSeries G) := by refine antitone_nat_of_succ_le fun n x hx => ?_ simp only [mem_lowerCentralSeries_succ_iff, exists_prop, mem_top, exists_true_left, true_and] at hx refine closure_induction ?_ (Subgroup.one_mem _) (fun _ _ _ _ ↦ mul_mem) (fun _ _ ↦ inv_mem) hx rintro y ⟨z, hz, a, ha⟩ rw [← ha, mul_assoc, mul_assoc, ← mul_assoc a z⁻¹ a⁻¹] exact mul_mem hz (Normal.conj_mem (lowerCentralSeries_normal n) z⁻¹ (inv_mem hz) a) /-- The lower central series of a group is a descending central series. -/ theorem lowerCentralSeries_isDescendingCentralSeries : IsDescendingCentralSeries (lowerCentralSeries G) := by constructor · rfl intro x n hxn g exact commutator_mem_commutator hxn (mem_top g) /-- Any descending central series for a group is bounded below by the lower central series. -/ theorem descending_central_series_ge_lower (H : ℕ → Subgroup G) (hH : IsDescendingCentralSeries H) : ∀ n : ℕ, lowerCentralSeries G n ≤ H n | 0 => hH.1.symm ▸ le_refl ⊤ | n + 1 => commutator_le.mpr fun x hx q _ => hH.2 x n (descending_central_series_ge_lower H hH n hx) q /-- A group is nilpotent if and only if its lower central series eventually reaches the trivial subgroup. -/ theorem nilpotent_iff_lowerCentralSeries : IsNilpotent G ↔ ∃ n, lowerCentralSeries G n = ⊥ := by rw [nilpotent_iff_finite_descending_central_series] constructor · rintro ⟨n, H, ⟨h0, hs⟩, hn⟩ use n rw [eq_bot_iff, ← hn] exact descending_central_series_ge_lower H ⟨h0, hs⟩ n · rintro ⟨n, hn⟩ exact ⟨n, lowerCentralSeries G, lowerCentralSeries_isDescendingCentralSeries, hn⟩ section Classical variable [hG : IsNilpotent G] variable (G) in open scoped Classical in /-- The nilpotency class of a nilpotent group is the smallest natural `n` such that the `n`'th term of the upper central series is `G`. -/ noncomputable def Group.nilpotencyClass : ℕ := Nat.find (IsNilpotent.nilpotent G) open scoped Classical in @[simp] theorem upperCentralSeries_nilpotencyClass : upperCentralSeries G (Group.nilpotencyClass G) = ⊤ := Nat.find_spec (IsNilpotent.nilpotent G) theorem upperCentralSeries_eq_top_iff_nilpotencyClass_le {n : ℕ} : upperCentralSeries G n = ⊤ ↔ Group.nilpotencyClass G ≤ n := by classical constructor · intro h exact Nat.find_le h · intro h rw [eq_top_iff, ← upperCentralSeries_nilpotencyClass] exact upperCentralSeries_mono _ h open scoped Classical in /-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which an ascending central series reaches `G` in its `n`'th term. -/ theorem least_ascending_central_series_length_eq_nilpotencyClass : Nat.find ((nilpotent_iff_finite_ascending_central_series G).mp hG) = Group.nilpotencyClass G := by refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_) · intro n hn exact ⟨upperCentralSeries G, upperCentralSeries_isAscendingCentralSeries G, hn⟩ · rintro n ⟨H, ⟨hH, hn⟩⟩ rw [← top_le_iff, ← hn] exact ascending_central_series_le_upper H hH n open scoped Classical in /-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which the descending central series reaches `⊥` in its `n`'th term. -/ theorem least_descending_central_series_length_eq_nilpotencyClass : Nat.find ((nilpotent_iff_finite_descending_central_series G).mp hG) = Group.nilpotencyClass G := by rw [← least_ascending_central_series_length_eq_nilpotencyClass] refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_) · rintro n ⟨H, ⟨hH, hn⟩⟩ refine ⟨fun m => H (n - m), is_descending_rev_series_of_is_ascending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 · rintro n ⟨H, ⟨hH, hn⟩⟩ refine ⟨fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 open scoped Classical in /-- The nilpotency class of a nilpotent `G` is equal to the length of the lower central series. -/ theorem lowerCentralSeries_length_eq_nilpotencyClass : Nat.find (nilpotent_iff_lowerCentralSeries.mp hG) = Group.nilpotencyClass (G := G) := by rw [← least_descending_central_series_length_eq_nilpotencyClass] refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_) · rintro n ⟨H, ⟨hH, hn⟩⟩ rw [← le_bot_iff, ← hn] exact descending_central_series_ge_lower H hH n · rintro n h exact ⟨lowerCentralSeries G, ⟨lowerCentralSeries_isDescendingCentralSeries, h⟩⟩ @[simp] theorem lowerCentralSeries_nilpotencyClass : lowerCentralSeries G (Group.nilpotencyClass G) = ⊥ := by classical rw [← lowerCentralSeries_length_eq_nilpotencyClass] exact Nat.find_spec (nilpotent_iff_lowerCentralSeries.mp hG) theorem lowerCentralSeries_eq_bot_iff_nilpotencyClass_le {n : ℕ} : lowerCentralSeries G n = ⊥ ↔ Group.nilpotencyClass G ≤ n := by classical constructor · intro h rw [← lowerCentralSeries_length_eq_nilpotencyClass] exact Nat.find_le h · intro h rw [eq_bot_iff, ← lowerCentralSeries_nilpotencyClass] exact lowerCentralSeries_antitone h end Classical theorem lowerCentralSeries_map_subtype_le (H : Subgroup G) (n : ℕ) : (lowerCentralSeries H n).map H.subtype ≤ lowerCentralSeries G n := by induction' n with d hd · simp · rw [lowerCentralSeries_succ, lowerCentralSeries_succ, MonoidHom.map_closure] apply Subgroup.closure_mono rintro x1 ⟨x2, ⟨x3, hx3, x4, _hx4, rfl⟩, rfl⟩ exact ⟨x3, hd (mem_map.mpr ⟨x3, hx3, rfl⟩), x4, by simp⟩ /-- A subgroup of a nilpotent group is nilpotent -/ instance Subgroup.isNilpotent (H : Subgroup G) [hG : IsNilpotent G] : IsNilpotent H := by rw [nilpotent_iff_lowerCentralSeries] at * rcases hG with ⟨n, hG⟩ use n have := lowerCentralSeries_map_subtype_le H n simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩) /-- The nilpotency class of a subgroup is less or equal to the nilpotency class of the group -/ theorem Subgroup.nilpotencyClass_le (H : Subgroup G) [hG : IsNilpotent G] : Group.nilpotencyClass H ≤ Group.nilpotencyClass G := by repeat rw [← lowerCentralSeries_length_eq_nilpotencyClass] classical apply Nat.find_mono intro n hG have := lowerCentralSeries_map_subtype_le H n simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩) instance (priority := 100) Group.isNilpotent_of_subsingleton [Subsingleton G] : IsNilpotent G := nilpotent_iff_lowerCentralSeries.2 ⟨0, Subsingleton.elim ⊤ ⊥⟩ theorem upperCentralSeries.map {H : Type*} [Group H] {f : G →* H} (h : Function.Surjective f) (n : ℕ) : Subgroup.map f (upperCentralSeries G n) ≤ upperCentralSeries H n := by induction' n with d hd · simp · rintro _ ⟨x, hx : x ∈ upperCentralSeries G d.succ, rfl⟩ y' rcases h y' with ⟨y, rfl⟩ simpa using hd (mem_map_of_mem f (hx y)) theorem lowerCentralSeries.map {H : Type*} [Group H] (f : G →* H) (n : ℕ) : Subgroup.map f (lowerCentralSeries G n) ≤ lowerCentralSeries H n := by induction' n with d hd · simp · rintro a ⟨x, hx : x ∈ lowerCentralSeries G d.succ, rfl⟩ refine closure_induction (hx := hx) ?_ (by simp [f.map_one, Subgroup.one_mem _]) (fun y z _ _ hy hz => by simp [MonoidHom.map_mul, Subgroup.mul_mem _ hy hz]) (fun y _ hy => by rw [f.map_inv]; exact Subgroup.inv_mem _ hy) rintro a ⟨y, hy, z, ⟨-, rfl⟩⟩ apply mem_closure.mpr exact fun K hK => hK ⟨f y, hd (mem_map_of_mem f hy), by simp [commutatorElement_def]⟩ theorem lowerCentralSeries_succ_eq_bot {n : ℕ} (h : lowerCentralSeries G n ≤ center G) : lowerCentralSeries G (n + 1) = ⊥ := by rw [lowerCentralSeries_succ, closure_eq_bot_iff, Set.subset_singleton_iff] rintro x ⟨y, hy1, z, ⟨⟩, rfl⟩ rw [mul_assoc, ← mul_inv_rev, mul_inv_eq_one, eq_comm] exact mem_center_iff.mp (h hy1) z /-- The preimage of a nilpotent group is nilpotent if the kernel of the homomorphism is contained in the center -/ theorem isNilpotent_of_ker_le_center {H : Type*} [Group H] (f : G →* H) (hf1 : f.ker ≤ center G) (hH : IsNilpotent H) : IsNilpotent G := by rw [nilpotent_iff_lowerCentralSeries] at * rcases hH with ⟨n, hn⟩ use n + 1 refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1) exact eq_bot_iff.mpr (hn ▸ lowerCentralSeries.map f n) theorem nilpotencyClass_le_of_ker_le_center {H : Type*} [Group H] (f : G →* H) (hf1 : f.ker ≤ center G) (hH : IsNilpotent H) : Group.nilpotencyClass (hG := isNilpotent_of_ker_le_center f hf1 hH) ≤ Group.nilpotencyClass H + 1 := by haveI : IsNilpotent G := isNilpotent_of_ker_le_center f hf1 hH rw [← lowerCentralSeries_length_eq_nilpotencyClass] classical apply Nat.find_min' refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1) rw [eq_bot_iff] apply le_trans (lowerCentralSeries.map f _) simp only [lowerCentralSeries_nilpotencyClass, le_bot_iff] /-- The range of a surjective homomorphism from a nilpotent group is nilpotent -/ theorem nilpotent_of_surjective {G' : Type*} [Group G'] [h : IsNilpotent G] (f : G →* G') (hf : Function.Surjective f) : IsNilpotent G' := by rcases h with ⟨n, hn⟩ use n apply eq_top_iff.mpr calc ⊤ = f.range := symm (f.range_eq_top_of_surjective hf) _ = Subgroup.map f ⊤ := MonoidHom.range_eq_map _ _ = Subgroup.map f (upperCentralSeries G n) := by rw [hn] _ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n /-- The nilpotency class of the range of a surjective homomorphism from a nilpotent group is less or equal the nilpotency class of the domain -/ theorem nilpotencyClass_le_of_surjective {G' : Type*} [Group G'] (f : G →* G') (hf : Function.Surjective f) [h : IsNilpotent G] : Group.nilpotencyClass (hG := nilpotent_of_surjective _ hf) ≤ Group.nilpotencyClass G := by classical apply Nat.find_mono intro n hn rw [eq_top_iff] calc ⊤ = f.range := symm (f.range_eq_top_of_surjective hf) _ = Subgroup.map f ⊤ := MonoidHom.range_eq_map _ _ = Subgroup.map f (upperCentralSeries G n) := by rw [hn] _ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n /-- Nilpotency respects isomorphisms -/ theorem nilpotent_of_mulEquiv {G' : Type*} [Group G'] [_h : IsNilpotent G] (f : G ≃* G') : IsNilpotent G' := nilpotent_of_surjective f.toMonoidHom (MulEquiv.surjective f) /-- A quotient of a nilpotent group is nilpotent -/ instance nilpotent_quotient_of_nilpotent (H : Subgroup G) [H.Normal] [_h : IsNilpotent G] : IsNilpotent (G ⧸ H) := nilpotent_of_surjective (QuotientGroup.mk' H) QuotientGroup.mk_surjective /-- The nilpotency class of a quotient of `G` is less or equal the nilpotency class of `G` -/ theorem nilpotencyClass_quotient_le (H : Subgroup G) [H.Normal] [_h : IsNilpotent G] : Group.nilpotencyClass (G ⧸ H) ≤ Group.nilpotencyClass G := nilpotencyClass_le_of_surjective (QuotientGroup.mk' H) QuotientGroup.mk_surjective -- This technical lemma helps with rewriting the subgroup, which occurs in indices private theorem comap_center_subst {H₁ H₂ : Subgroup G} [Normal H₁] [Normal H₂] (h : H₁ = H₂) : comap (mk' H₁) (center (G ⧸ H₁)) = comap (mk' H₂) (center (G ⧸ H₂)) := by subst h; rfl theorem comap_upperCentralSeries_quotient_center (n : ℕ) : comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) n) = upperCentralSeries G n.succ := by induction' n with n ih · simp only [upperCentralSeries_zero, MonoidHom.comap_bot, ker_mk', (upperCentralSeries_one G).symm] · let Hn := upperCentralSeries (G ⧸ center G) n calc comap (mk' (center G)) (upperCentralSeriesStep Hn) = comap (mk' (center G)) (comap (mk' Hn) (center ((G ⧸ center G) ⧸ Hn))) := by rw [upperCentralSeriesStep_eq_comap_center] _ = comap (mk' (comap (mk' (center G)) Hn)) (center (G ⧸ comap (mk' (center G)) Hn)) := QuotientGroup.comap_comap_center _ = comap (mk' (upperCentralSeries G n.succ)) (center (G ⧸ upperCentralSeries G n.succ)) := (comap_center_subst ih) _ = upperCentralSeriesStep (upperCentralSeries G n.succ) := symm (upperCentralSeriesStep_eq_comap_center _) theorem nilpotencyClass_zero_iff_subsingleton [IsNilpotent G] : Group.nilpotencyClass G = 0 ↔ Subsingleton G := by classical rw [Group.nilpotencyClass, Nat.find_eq_zero, upperCentralSeries_zero, subsingleton_iff_bot_eq_top, Subgroup.subsingleton_iff] /-- Quotienting the `center G` reduces the nilpotency class by 1 -/ theorem nilpotencyClass_quotient_center [hH : IsNilpotent G] : Group.nilpotencyClass (G ⧸ center G) = Group.nilpotencyClass G - 1 := by generalize hn : Group.nilpotencyClass G = n rcases n with (rfl | n) · simp [nilpotencyClass_zero_iff_subsingleton] at * exact Quotient.instSubsingletonQuotient (leftRel (center G)) · suffices Group.nilpotencyClass (G ⧸ center G) = n by simpa apply le_antisymm · apply upperCentralSeries_eq_top_iff_nilpotencyClass_le.mp apply comap_injective (f := (mk' (center G))) Quot.mk_surjective rw [comap_upperCentralSeries_quotient_center, comap_top, Nat.succ_eq_add_one, ← hn] exact upperCentralSeries_nilpotencyClass · apply le_of_add_le_add_right calc n + 1 = Group.nilpotencyClass G := hn.symm _ ≤ Group.nilpotencyClass (G ⧸ center G) + 1 := nilpotencyClass_le_of_ker_le_center _ (le_of_eq (ker_mk' _)) _ /-- The nilpotency class of a non-trivial group is one more than its quotient by the center -/ theorem nilpotencyClass_eq_quotient_center_plus_one [hH : IsNilpotent G] [Nontrivial G] : Group.nilpotencyClass G = Group.nilpotencyClass (G ⧸ center G) + 1 := by rw [nilpotencyClass_quotient_center] rcases h : Group.nilpotencyClass G with ⟨⟩ · exfalso rw [nilpotencyClass_zero_iff_subsingleton] at h apply false_of_nontrivial_of_subsingleton G · simp /-- If the quotient by `center G` is nilpotent, then so is G. -/ theorem of_quotient_center_nilpotent (h : IsNilpotent (G ⧸ center G)) : IsNilpotent G := by obtain ⟨n, hn⟩ := h.nilpotent use n.succ simp [← comap_upperCentralSeries_quotient_center, hn] /-- A custom induction principle for nilpotent groups. The base case is a trivial group (`subsingleton G`), and in the induction step, one can assume the hypothesis for the group quotiented by its center. -/ @[elab_as_elim] theorem nilpotent_center_quotient_ind {P : ∀ (G) [Group G] [IsNilpotent G], Prop} (G : Type*) [Group G] [IsNilpotent G] (hbase : ∀ (G) [Group G] [Subsingleton G], P G) (hstep : ∀ (G) [Group G] [IsNilpotent G], P (G ⧸ center G) → P G) : P G := by obtain ⟨n, h⟩ : ∃ n, Group.nilpotencyClass G = n := ⟨_, rfl⟩ induction' n with n ih generalizing G · haveI := nilpotencyClass_zero_iff_subsingleton.mp h exact hbase _ · have hn : Group.nilpotencyClass (G ⧸ center G) = n := by simp [nilpotencyClass_quotient_center, h] exact hstep _ (ih _ hn) theorem derived_le_lower_central (n : ℕ) : derivedSeries G n ≤ lowerCentralSeries G n := by induction' n with i ih · simp · apply commutator_mono ih simp /-- Abelian groups are nilpotent -/ instance (priority := 100) CommGroup.isNilpotent {G : Type*} [CommGroup G] : IsNilpotent G := by use 1 rw [upperCentralSeries_one] apply CommGroup.center_eq_top /-- Abelian groups have nilpotency class at most one -/ theorem CommGroup.nilpotencyClass_le_one {G : Type*} [CommGroup G] : Group.nilpotencyClass G ≤ 1 := by rw [← upperCentralSeries_eq_top_iff_nilpotencyClass_le, upperCentralSeries_one]
apply CommGroup.center_eq_top /-- Groups with nilpotency class at most one are abelian -/ def commGroupOfNilpotencyClass [IsNilpotent G] (h : Group.nilpotencyClass G ≤ 1) : CommGroup G := Group.commGroupOfCenterEqTop <| by rw [← upperCentralSeries_one] exact upperCentralSeries_eq_top_iff_nilpotencyClass_le.mpr h section Prod variable {G₁ G₂ : Type*} [Group G₁] [Group G₂]
Mathlib/GroupTheory/Nilpotent.lean
659
669
/- Copyright (c) 2017 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Stephen Morgan, Kim Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Functor.Const import Mathlib.CategoryTheory.Discrete.Basic import Mathlib.CategoryTheory.Yoneda import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic /-! # Cones and cocones We define `Cone F`, a cone over a functor `F`, and `F.cones : Cᵒᵖ ⥤ Type`, the functor associating to `X` the cones over `F` with cone point `X`. A cone `c` is defined by specifying its cone point `c.pt` and a natural transformation `c.π` from the constant `c.pt` valued functor to `F`. We provide `c.w f : c.π.app j ≫ F.map f = c.π.app j'` for any `f : j ⟶ j'` as a wrapper for `c.π.naturality f` avoiding unneeded identity morphisms. We define `c.extend f`, where `c : cone F` and `f : Y ⟶ c.pt` for some other `Y`, which replaces the cone point by `Y` and inserts `f` into each of the components of the cone. Similarly we have `c.whisker F` producing a `Cone (E ⋙ F)` We define morphisms of cones, and the category of cones. We define `Cone.postcompose α : cone F ⥤ cone G` for `α` a natural transformation `F ⟶ G`. And, of course, we dualise all this to cocones as well. For more results about the category of cones, see `cone_category.lean`. -/ -- morphism levels before object levels. See note [CategoryTheory universes]. universe v₁ v₂ v₃ v₄ v₅ u₁ u₂ u₃ u₄ u₅ open CategoryTheory variable {J : Type u₁} [Category.{v₁} J] variable {K : Type u₂} [Category.{v₂} K] variable {C : Type u₃} [Category.{v₃} C] variable {D : Type u₄} [Category.{v₄} D] variable {E : Type u₅} [Category.{v₅} E] open CategoryTheory open CategoryTheory.Category open CategoryTheory.Functor open Opposite namespace CategoryTheory namespace Functor variable (F : J ⥤ C) /-- If `F : J ⥤ C` then `F.cones` is the functor assigning to an object `X : C` the type of natural transformations from the constant functor with value `X` to `F`. An object representing this functor is a limit of `F`. -/ @[simps!] def cones : Cᵒᵖ ⥤ Type max u₁ v₃ := (const J).op ⋙ yoneda.obj F /-- If `F : J ⥤ C` then `F.cocones` is the functor assigning to an object `(X : C)` the type of natural transformations from `F` to the constant functor with value `X`. An object corepresenting this functor is a colimit of `F`. -/ @[simps!] def cocones : C ⥤ Type max u₁ v₃ := const J ⋙ coyoneda.obj (op F) end Functor section variable (J C) /-- Functorially associated to each functor `J ⥤ C`, we have the `C`-presheaf consisting of cones with a given cone point. -/ @[simps!] def cones : (J ⥤ C) ⥤ Cᵒᵖ ⥤ Type max u₁ v₃ where obj := Functor.cones map f := whiskerLeft (const J).op (yoneda.map f) /-- Contravariantly associated to each functor `J ⥤ C`, we have the `C`-copresheaf consisting of cocones with a given cocone point. -/ @[simps!] def cocones : (J ⥤ C)ᵒᵖ ⥤ C ⥤ Type max u₁ v₃ where obj F := Functor.cocones (unop F) map f := whiskerLeft (const J) (coyoneda.map f) end namespace Limits section /-- A `c : Cone F` is: * an object `c.pt` and * a natural transformation `c.π : c.pt ⟶ F` from the constant `c.pt` functor to `F`. Example: if `J` is a category coming from a poset then the data required to make a term of type `Cone F` is morphisms `πⱼ : c.pt ⟶ F j` for all `j : J` and, for all `i ≤ j` in `J`, morphisms `πᵢⱼ : F i ⟶ F j` such that `πᵢ ≫ πᵢⱼ = πᵢ`. `Cone F` is equivalent, via `cone.equiv` below, to `Σ X, F.cones.obj X`. -/ structure Cone (F : J ⥤ C) where /-- An object of `C` -/ pt : C /-- A natural transformation from the constant functor at `X` to `F` -/ π : (const J).obj pt ⟶ F instance inhabitedCone (F : Discrete PUnit ⥤ C) : Inhabited (Cone F) := ⟨{ pt := F.obj ⟨⟨⟩⟩ π := { app := fun ⟨⟨⟩⟩ => 𝟙 _ naturality := by intro X Y f match X, Y, f with | .mk A, .mk B, .up g => aesop_cat } }⟩ @[reassoc (attr := simp)] theorem Cone.w {F : J ⥤ C} (c : Cone F) {j j' : J} (f : j ⟶ j') : c.π.app j ≫ F.map f = c.π.app j' := by rw [← c.π.naturality f] apply id_comp /-- A `c : Cocone F` is * an object `c.pt` and * a natural transformation `c.ι : F ⟶ c.pt` from `F` to the constant `c.pt` functor. For example, if the source `J` of `F` is a partially ordered set, then to give `c : Cocone F` is to give a collection of morphisms `ιⱼ : F j ⟶ c.pt` and, for all `j ≤ k` in `J`, morphisms `ιⱼₖ : F j ⟶ F k` such that `Fⱼₖ ≫ Fₖ = Fⱼ` for all `j ≤ k`. `Cocone F` is equivalent, via `Cone.equiv` below, to `Σ X, F.cocones.obj X`. -/ structure Cocone (F : J ⥤ C) where /-- An object of `C` -/ pt : C /-- A natural transformation from `F` to the constant functor at `pt` -/ ι : F ⟶ (const J).obj pt instance inhabitedCocone (F : Discrete PUnit ⥤ C) : Inhabited (Cocone F) := ⟨{ pt := F.obj ⟨⟨⟩⟩ ι := { app := fun ⟨⟨⟩⟩ => 𝟙 _ naturality := by intro X Y f match X, Y, f with | .mk A, .mk B, .up g => simp } }⟩ @[reassoc] theorem Cocone.w {F : J ⥤ C} (c : Cocone F) {j j' : J} (f : j ⟶ j') : F.map f ≫ c.ι.app j' = c.ι.app j := by rw [c.ι.naturality f] apply comp_id end variable {F : J ⥤ C} namespace Cone /-- The isomorphism between a cone on `F` and an element of the functor `F.cones`. -/ @[simps!] def equiv (F : J ⥤ C) : Cone F ≅ ΣX, F.cones.obj X where hom c := ⟨op c.pt, c.π⟩ inv c := { pt := c.1.unop π := c.2 } hom_inv_id := by funext X cases X rfl inv_hom_id := by funext X cases X rfl /-- A map to the vertex of a cone naturally induces a cone by composition. -/ @[simps] def extensions (c : Cone F) : yoneda.obj c.pt ⋙ uliftFunctor.{u₁} ⟶ F.cones where app _ f := (const J).map f.down ≫ c.π /-- A map to the vertex of a cone induces a cone by composition. -/ @[simps] def extend (c : Cone F) {X : C} (f : X ⟶ c.pt) : Cone F := { pt := X π := c.extensions.app (op X) ⟨f⟩ } /-- Whisker a cone by precomposition of a functor. -/ @[simps] def whisker (E : K ⥤ J) (c : Cone F) : Cone (E ⋙ F) where pt := c.pt π := whiskerLeft E c.π end Cone namespace Cocone /-- The isomorphism between a cocone on `F` and an element of the functor `F.cocones`. -/ def equiv (F : J ⥤ C) : Cocone F ≅ ΣX, F.cocones.obj X where hom c := ⟨c.pt, c.ι⟩ inv c := { pt := c.1 ι := c.2 } hom_inv_id := by funext X cases X rfl inv_hom_id := by funext X cases X rfl /-- A map from the vertex of a cocone naturally induces a cocone by composition. -/ @[simps] def extensions (c : Cocone F) : coyoneda.obj (op c.pt) ⋙ uliftFunctor.{u₁} ⟶ F.cocones where app _ f := c.ι ≫ (const J).map f.down /-- A map from the vertex of a cocone induces a cocone by composition. -/ @[simps] def extend (c : Cocone F) {Y : C} (f : c.pt ⟶ Y) : Cocone F where pt := Y ι := c.extensions.app Y ⟨f⟩ /-- Whisker a cocone by precomposition of a functor. See `whiskering` for a functorial version. -/ @[simps] def whisker (E : K ⥤ J) (c : Cocone F) : Cocone (E ⋙ F) where pt := c.pt ι := whiskerLeft E c.ι end Cocone /-- A cone morphism between two cones for the same diagram is a morphism of the cone points which commutes with the cone legs. -/ structure ConeMorphism (A B : Cone F) where /-- A morphism between the two vertex objects of the cones -/ hom : A.pt ⟶ B.pt /-- The triangle consisting of the two natural transformations and `hom` commutes -/ w : ∀ j : J, hom ≫ B.π.app j = A.π.app j := by aesop_cat attribute [reassoc (attr := simp)] ConeMorphism.w instance inhabitedConeMorphism (A : Cone F) : Inhabited (ConeMorphism A A) := ⟨{ hom := 𝟙 _ }⟩ /-- The category of cones on a given diagram. -/ @[simps] instance Cone.category : Category (Cone F) where Hom A B := ConeMorphism A B comp f g := { hom := f.hom ≫ g.hom } id B := { hom := 𝟙 B.pt } -- Porting note: if we do not have `simps` automatically generate the lemma for simplifying -- the hom field of a category, we need to write the `ext` lemma in terms of the categorical -- morphism, rather than the underlying structure. @[ext] theorem ConeMorphism.ext {c c' : Cone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr namespace Cones /-- To give an isomorphism between cones, it suffices to give an isomorphism between their vertices which commutes with the cone maps. -/ @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {c c' : Cone F} (φ : c.pt ≅ c'.pt) (w : ∀ j, c.π.app j = φ.hom ≫ c'.π.app j := by aesop_cat) : c ≅ c' where hom := { hom := φ.hom } inv := { hom := φ.inv w := fun j => φ.inv_comp_eq.mpr (w j) } /-- Eta rule for cones. -/ @[simps!] def eta (c : Cone F) : c ≅ ⟨c.pt, c.π⟩ := Cones.ext (Iso.refl _) /-- Given a cone morphism whose object part is an isomorphism, produce an isomorphism of cones. -/ theorem cone_iso_of_hom_iso {K : J ⥤ C} {c d : Cone K} (f : c ⟶ d) [i : IsIso f.hom] : IsIso f := ⟨⟨{ hom := inv f.hom w := fun j => (asIso f.hom).inv_comp_eq.2 (f.w j).symm }, by aesop_cat⟩⟩ /-- There is a morphism from an extended cone to the original cone. -/ @[simps] def extend (s : Cone F) {X : C} (f : X ⟶ s.pt) : s.extend f ⟶ s where hom := f /-- Extending a cone by the identity does nothing. -/ @[simps!] def extendId (s : Cone F) : s.extend (𝟙 s.pt) ≅ s := Cones.ext (Iso.refl _) /-- Extending a cone by a composition is the same as extending the cone twice. -/ @[simps!] def extendComp (s : Cone F) {X Y : C} (f : X ⟶ Y) (g : Y ⟶ s.pt) : s.extend (f ≫ g) ≅ (s.extend g).extend f := Cones.ext (Iso.refl _) /-- A cone extended by an isomorphism is isomorphic to the original cone. -/ @[simps] def extendIso (s : Cone F) {X : C} (f : X ≅ s.pt) : s.extend f.hom ≅ s where hom := { hom := f.hom } inv := { hom := f.inv } instance {s : Cone F} {X : C} (f : X ⟶ s.pt) [IsIso f] : IsIso (Cones.extend s f) := ⟨(extendIso s (asIso f)).inv, by aesop_cat⟩ /-- Functorially postcompose a cone for `F` by a natural transformation `F ⟶ G` to give a cone for `G`. -/ @[simps] def postcompose {G : J ⥤ C} (α : F ⟶ G) : Cone F ⥤ Cone G where obj c := { pt := c.pt π := c.π ≫ α } map f := { hom := f.hom } /-- Postcomposing a cone by the composite natural transformation `α ≫ β` is the same as postcomposing by `α` and then by `β`. -/ @[simps!] def postcomposeComp {G H : J ⥤ C} (α : F ⟶ G) (β : G ⟶ H) : postcompose (α ≫ β) ≅ postcompose α ⋙ postcompose β := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) /-- Postcomposing by the identity does not change the cone up to isomorphism. -/ @[simps!] def postcomposeId : postcompose (𝟙 F) ≅ 𝟭 (Cone F) := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) /-- If `F` and `G` are naturally isomorphic functors, then they have equivalent categories of cones. -/ @[simps] def postcomposeEquivalence {G : J ⥤ C} (α : F ≅ G) : Cone F ≌ Cone G where functor := postcompose α.hom inverse := postcompose α.inv unitIso := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) /-- Whiskering on the left by `E : K ⥤ J` gives a functor from `Cone F` to `Cone (E ⋙ F)`. -/ @[simps] def whiskering (E : K ⥤ J) : Cone F ⥤ Cone (E ⋙ F) where obj c := c.whisker E map f := { hom := f.hom } /-- Whiskering by an equivalence gives an equivalence between categories of cones. -/ @[simps] def whiskeringEquivalence (e : K ≌ J) : Cone F ≌ Cone (e.functor ⋙ F) where functor := whiskering e.functor inverse := whiskering e.inverse ⋙ postcompose (e.invFunIdAssoc F).hom unitIso := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) (by intro k simpa [e.counit_app_functor] using s.w (e.unitInv.app k)) /-- The categories of cones over `F` and `G` are equivalent if `F` and `G` are naturally isomorphic (possibly after changing the indexing category by an equivalence). -/ @[simps! functor inverse unitIso counitIso] def equivalenceOfReindexing {G : K ⥤ C} (e : K ≌ J) (α : e.functor ⋙ F ≅ G) : Cone F ≌ Cone G := (whiskeringEquivalence e).trans (postcomposeEquivalence α) section variable (F) /-- Forget the cone structure and obtain just the cone point. -/ @[simps] def forget : Cone F ⥤ C where obj t := t.pt map f := f.hom variable (G : C ⥤ D) /-- A functor `G : C ⥤ D` sends cones over `F` to cones over `F ⋙ G` functorially. -/ @[simps] def functoriality : Cone F ⥤ Cone (F ⋙ G) where obj A := { pt := G.obj A.pt π := { app := fun j => G.map (A.π.app j) naturality := by intros; erw [← G.map_comp]; simp } } map f := { hom := G.map f.hom w := fun j => by simp [-ConeMorphism.w, ← f.w j] } /-- Functoriality is functorial. -/ def functorialityCompFunctoriality (H : D ⥤ E) : functoriality F G ⋙ functoriality (F ⋙ G) H ≅ functoriality F (G ⋙ H) := NatIso.ofComponents (fun _ ↦ Iso.refl _) (by simp [functoriality]) instance functoriality_full [G.Full] [G.Faithful] : (functoriality F G).Full where map_surjective t := ⟨{ hom := G.preimage t.hom w := fun j => G.map_injective (by simpa using t.w j) }, by aesop_cat⟩ instance functoriality_faithful [G.Faithful] : (Cones.functoriality F G).Faithful where map_injective {_X} {_Y} f g h := ConeMorphism.ext f g <| G.map_injective <| congr_arg ConeMorphism.hom h /-- If `e : C ≌ D` is an equivalence of categories, then `functoriality F e.functor` induces an equivalence between cones over `F` and cones over `F ⋙ e.functor`. -/ @[simps] def functorialityEquivalence (e : C ≌ D) : Cone F ≌ Cone (F ⋙ e.functor) := let f : (F ⋙ e.functor) ⋙ e.inverse ≅ F := Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ e.unitIso.symm ≪≫ Functor.rightUnitor _ { functor := functoriality F e.functor inverse := functoriality (F ⋙ e.functor) e.inverse ⋙ (postcomposeEquivalence f).functor unitIso := NatIso.ofComponents fun c => Cones.ext (e.unitIso.app _) counitIso := NatIso.ofComponents fun c => Cones.ext (e.counitIso.app _) } /-- If `F` reflects isomorphisms, then `Cones.functoriality F` reflects isomorphisms as well. -/ instance reflects_cone_isomorphism (F : C ⥤ D) [F.ReflectsIsomorphisms] (K : J ⥤ C) : (Cones.functoriality K F).ReflectsIsomorphisms := by constructor intro A B f _ haveI : IsIso (F.map f.hom) := (Cones.forget (K ⋙ F)).map_isIso ((Cones.functoriality K F).map f) haveI := ReflectsIsomorphisms.reflects F f.hom apply cone_iso_of_hom_iso end end Cones /-- A cocone morphism between two cocones for the same diagram is a morphism of the cocone points which commutes with the cocone legs. -/ structure CoconeMorphism (A B : Cocone F) where /-- A morphism between the (co)vertex objects in `C` -/ hom : A.pt ⟶ B.pt /-- The triangle made from the two natural transformations and `hom` commutes -/ w : ∀ j : J, A.ι.app j ≫ hom = B.ι.app j := by aesop_cat instance inhabitedCoconeMorphism (A : Cocone F) : Inhabited (CoconeMorphism A A) := ⟨{ hom := 𝟙 _ }⟩ attribute [reassoc (attr := simp)] CoconeMorphism.w @[simps] instance Cocone.category : Category (Cocone F) where Hom A B := CoconeMorphism A B comp f g := { hom := f.hom ≫ g.hom } id B := { hom := 𝟙 B.pt } -- Porting note: if we do not have `simps` automatically generate the lemma for simplifying -- the hom field of a category, we need to write the `ext` lemma in terms of the categorical -- morphism, rather than the underlying structure. @[ext] theorem CoconeMorphism.ext {c c' : Cocone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr namespace Cocones /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {c c' : Cocone F} (φ : c.pt ≅ c'.pt) (w : ∀ j, c.ι.app j ≫ φ.hom = c'.ι.app j := by aesop_cat) : c ≅ c' where hom := { hom := φ.hom } inv := { hom := φ.inv w := fun j => φ.comp_inv_eq.mpr (w j).symm } /-- Eta rule for cocones. -/ @[simps!] def eta (c : Cocone F) : c ≅ ⟨c.pt, c.ι⟩ := Cocones.ext (Iso.refl _) /-- Given a cocone morphism whose object part is an isomorphism, produce an isomorphism of cocones. -/ theorem cocone_iso_of_hom_iso {K : J ⥤ C} {c d : Cocone K} (f : c ⟶ d) [i : IsIso f.hom] : IsIso f := ⟨⟨{ hom := inv f.hom w := fun j => (asIso f.hom).comp_inv_eq.2 (f.w j).symm }, by aesop_cat⟩⟩ /-- There is a morphism from a cocone to its extension. -/ @[simps] def extend (s : Cocone F) {X : C} (f : s.pt ⟶ X) : s ⟶ s.extend f where hom := f /-- Extending a cocone by the identity does nothing. -/ @[simps!] def extendId (s : Cocone F) : s ≅ s.extend (𝟙 s.pt) := Cocones.ext (Iso.refl _) /-- Extending a cocone by a composition is the same as extending the cone twice. -/ @[simps!] def extendComp (s : Cocone F) {X Y : C} (f : s.pt ⟶ X) (g : X ⟶ Y) : s.extend (f ≫ g) ≅ (s.extend f).extend g :=
Cocones.ext (Iso.refl _) /-- A cocone extended by an isomorphism is isomorphic to the original cone. -/ @[simps]
Mathlib/CategoryTheory/Limits/Cones.lean
525
528
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Bhavik Mehta, Eric Wieser -/ import Mathlib.Algebra.BigOperators.Group.Multiset.Basic import Mathlib.Algebra.BigOperators.Ring.List import Mathlib.Data.Multiset.Antidiagonal import Mathlib.Data.Multiset.Sections /-! # Lemmas about `Multiset.sum` and `Multiset.prod` requiring extra algebra imports -/ variable {ι α β : Type*} namespace Multiset section CommMonoid variable [CommMonoid α] [HasDistribNeg α] @[simp] lemma prod_map_neg (s : Multiset α) : (s.map Neg.neg).prod = (-1) ^ card s * s.prod := Quotient.inductionOn s (by simp) end CommMonoid section CommMonoidWithZero variable [CommMonoidWithZero α] {s : Multiset α} lemma prod_eq_zero (h : (0 : α) ∈ s) : s.prod = 0 := by rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩; simp [hs', Multiset.prod_cons] variable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α} @[simp] lemma prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s := Quotient.inductionOn s fun l ↦ by rw [quot_mk_to_coe, prod_coe]; exact List.prod_eq_zero_iff lemma prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 := mt prod_eq_zero_iff.1 h end CommMonoidWithZero section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α} lemma sum_map_mul_left : sum (s.map fun i ↦ a * f i) = a * sum (s.map f) := Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add] lemma sum_map_mul_right : sum (s.map fun i ↦ f i * a) = sum (s.map f) * a := Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul] end NonUnitalNonAssocSemiring section NonUnitalSemiring variable [NonUnitalSemiring α] {s : Multiset α} {a : α} lemma dvd_sum : (∀ x ∈ s, a ∣ x) → a ∣ s.sum := Multiset.induction_on s (fun _ ↦ dvd_zero _) fun x s ih h ↦ by rw [sum_cons] exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy ↦ h _ <| mem_cons.2 <| Or.inr hy) end NonUnitalSemiring section CommSemiring
variable [CommSemiring α] lemma prod_map_sum {s : Multiset (Multiset α)} : prod (s.map sum) = sum ((Sections s).map prod) :=
Mathlib/Algebra/BigOperators/Ring/Multiset.lean
62
65
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Algebra.Bilinear import Mathlib.Algebra.Algebra.Opposite import Mathlib.Algebra.Group.Pointwise.Finset.Basic import Mathlib.Algebra.Group.Pointwise.Set.BigOperators import Mathlib.Algebra.Module.Submodule.Pointwise import Mathlib.Algebra.Ring.NonZeroDivisors import Mathlib.Algebra.Ring.Submonoid.Pointwise import Mathlib.Data.Set.Semiring import Mathlib.GroupTheory.GroupAction.SubMulAction.Pointwise /-! # Multiplication and division of submodules of an algebra. An interface for multiplication and division of sub-R-modules of an R-algebra A is developed. ## Main definitions Let `R` be a commutative ring (or semiring) and let `A` be an `R`-algebra. * `1 : Submodule R A` : the R-submodule R of the R-algebra A * `Mul (Submodule R A)` : multiplication of two sub-R-modules M and N of A is defined to be the smallest submodule containing all the products `m * n`. * `Div (Submodule R A)` : `I / J` is defined to be the submodule consisting of all `a : A` such that `a • J ⊆ I` It is proved that `Submodule R A` is a semiring, and also an algebra over `Set A`. Additionally, in the `Pointwise` locale we promote `Submodule.pointwiseDistribMulAction` to a `MulSemiringAction` as `Submodule.pointwiseMulSemiringAction`. When `R` is not necessarily commutative, and `A` is merely a `R`-module with a ring structure such that `IsScalarTower R A A` holds (equivalent to the data of a ring homomorphism `R →+* A` by `ringHomEquivModuleIsScalarTower`), we can still define `1 : Submodule R A` and `Mul (Submodule R A)`, but `1` is only a left identity, not necessarily a right one. ## Tags multiplication of submodules, division of submodules, submodule semiring -/ universe uι u v open Algebra Set MulOpposite open Pointwise namespace SubMulAction variable {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A] theorem algebraMap_mem (r : R) : algebraMap R A r ∈ (1 : SubMulAction R A) := ⟨r, (algebraMap_eq_smul_one r).symm⟩ theorem mem_one' {x : A} : x ∈ (1 : SubMulAction R A) ↔ ∃ y, algebraMap R A y = x := exists_congr fun r => by rw [algebraMap_eq_smul_one] end SubMulAction namespace Submodule section Module variable {R : Type u} [Semiring R] {A : Type v} [Semiring A] [Module R A] -- TODO: Why is this in a file about `Algebra`? -- TODO: potentially change this back to `LinearMap.range (Algebra.linearMap R A)` -- once a version of `Algebra` without the `commutes'` field is introduced. -- See issue https://github.com/leanprover-community/mathlib4/issues/18110. /-- `1 : Submodule R A` is the submodule `R ∙ 1` of `A`. -/ instance one : One (Submodule R A) := ⟨LinearMap.range (LinearMap.toSpanSingleton R A 1)⟩ theorem one_eq_span : (1 : Submodule R A) = R ∙ 1 := (LinearMap.span_singleton_eq_range _ _ _).symm theorem le_one_toAddSubmonoid : 1 ≤ (1 : Submodule R A).toAddSubmonoid := by rintro x ⟨n, rfl⟩ exact ⟨n, show (n : R) • (1 : A) = n by rw [Nat.cast_smul_eq_nsmul, nsmul_one]⟩ @[simp] theorem toSubMulAction_one : (1 : Submodule R A).toSubMulAction = 1 := SetLike.ext fun _ ↦ by rw [one_eq_span, SubMulAction.mem_one]; exact mem_span_singleton theorem one_eq_span_one_set : (1 : Submodule R A) = span R 1 := one_eq_span @[simp] theorem one_le {P : Submodule R A} : (1 : Submodule R A) ≤ P ↔ (1 : A) ∈ P := by simp [one_eq_span] variable {M : Type*} [AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M] instance : SMul (Submodule R A) (Submodule R M) where smul A' M' := { __ := A'.toAddSubmonoid • M'.toAddSubmonoid smul_mem' := fun r m hm ↦ AddSubmonoid.smul_induction_on hm (fun a ha m hm ↦ by rw [← smul_assoc]; exact AddSubmonoid.smul_mem_smul (A'.smul_mem r ha) hm) fun m₁ m₂ h₁ h₂ ↦ by rw [smul_add]; exact (A'.1 • M'.1).add_mem h₁ h₂ } section variable {I J : Submodule R A} {N P : Submodule R M} theorem smul_toAddSubmonoid : (I • N).toAddSubmonoid = I.toAddSubmonoid • N.toAddSubmonoid := rfl theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N := AddSubmonoid.smul_mem_smul hr hn theorem smul_le : I • N ≤ P ↔ ∀ r ∈ I, ∀ n ∈ N, r • n ∈ P := AddSubmonoid.smul_le @[simp, norm_cast] lemma coe_set_smul : (I : Set A) • N = I • N := set_smul_eq_of_le _ _ _ (fun _ _ hr hx ↦ smul_mem_smul hr hx) (smul_le.mpr fun _ hr _ hx ↦ mem_set_smul_of_mem_mem hr hx) @[elab_as_elim] theorem smul_induction_on {p : M → Prop} {x} (H : x ∈ I • N) (smul : ∀ r ∈ I, ∀ n ∈ N, p (r • n)) (add : ∀ x y, p x → p y → p (x + y)) : p x := AddSubmonoid.smul_induction_on H smul add /-- Dependent version of `Submodule.smul_induction_on`. -/ @[elab_as_elim] theorem smul_induction_on' {x : M} (hx : x ∈ I • N) {p : ∀ x, x ∈ I • N → Prop} (smul : ∀ (r : A) (hr : r ∈ I) (n : M) (hn : n ∈ N), p (r • n) (smul_mem_smul hr hn)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (add_mem ‹_› ‹_›)) : p x hx := by refine Exists.elim ?_ fun (h : x ∈ I • N) (H : p x h) ↦ H exact smul_induction_on hx (fun a ha x hx ↦ ⟨_, smul _ ha _ hx⟩) fun x y ⟨_, hx⟩ ⟨_, hy⟩ ↦ ⟨_, add _ _ _ _ hx hy⟩ theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P := AddSubmonoid.smul_le_smul hij hnp theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N := smul_mono h le_rfl instance : CovariantClass (Submodule R A) (Submodule R M) HSMul.hSMul LE.le := ⟨fun _ _ => smul_mono le_rfl⟩ variable (I J N P) @[simp] theorem smul_bot : I • (⊥ : Submodule R M) = ⊥ := toAddSubmonoid_injective <| AddSubmonoid.addSubmonoid_smul_bot _ @[simp] theorem bot_smul : (⊥ : Submodule R A) • N = ⊥ := le_bot_iff.mp <| smul_le.mpr <| by rintro _ rfl _ _; rw [zero_smul]; exact zero_mem _ theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P := toAddSubmonoid_injective <| by simp only [smul_toAddSubmonoid, sup_toAddSubmonoid, AddSubmonoid.addSubmonoid_smul_sup] theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N := le_antisymm (smul_le.mpr fun mn hmn p hp ↦ by obtain ⟨m, hm, n, hn, rfl⟩ := mem_sup.mp hmn rw [add_smul]; exact add_mem_sup (smul_mem_smul hm hp) <| smul_mem_smul hn hp) (sup_le (smul_mono_left le_sup_left) <| smul_mono_left le_sup_right) protected theorem smul_assoc {B} [Semiring B] [Module R B] [Module A B] [Module B M] [IsScalarTower R A B] [IsScalarTower R B M] [IsScalarTower A B M] (I : Submodule R A) (J : Submodule R B) (N : Submodule R M) : (I • J) • N = I • J • N := le_antisymm (smul_le.2 fun _ hrsij t htn ↦ smul_induction_on hrsij (fun r hr s hs ↦ smul_assoc r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn)) fun x y ↦ (add_smul x y t).symm ▸ add_mem) (smul_le.2 fun r hr _ hsn ↦ smul_induction_on hsn (fun j hj n hn ↦ (smul_assoc r j n).symm ▸ smul_mem_smul (smul_mem_smul hr hj) hn) fun m₁ m₂ ↦ (smul_add r m₁ m₂) ▸ add_mem) theorem smul_iSup {ι : Sort*} {I : Submodule R A} {t : ι → Submodule R M} : I • (⨆ i, t i)= ⨆ i, I • t i := toAddSubmonoid_injective <| by simp only [smul_toAddSubmonoid, iSup_toAddSubmonoid, AddSubmonoid.smul_iSup] theorem iSup_smul {ι : Sort*} {t : ι → Submodule R A} {N : Submodule R M} : (⨆ i, t i) • N = ⨆ i, t i • N := le_antisymm (smul_le.mpr fun t ht s hs ↦ iSup_induction _ (motive := (· • s ∈ _)) ht (fun i t ht ↦ mem_iSup_of_mem i <| smul_mem_smul ht hs) (by simp_rw [zero_smul]; apply zero_mem) fun x y ↦ by simp_rw [add_smul]; apply add_mem) (iSup_le fun i ↦ Submodule.smul_mono_left <| le_iSup _ i) protected theorem one_smul : (1 : Submodule R A) • N = N := by refine le_antisymm (smul_le.mpr fun r hr m hm ↦ ?_) fun m hm ↦ ?_ · obtain ⟨r, rfl⟩ := hr rw [LinearMap.toSpanSingleton_apply, smul_one_smul]; exact N.smul_mem r hm · rw [← one_smul A m]; exact smul_mem_smul (one_le.mp le_rfl) hm theorem smul_subset_smul : (↑I : Set A) • (↑N : Set M) ⊆ (↑(I • N) : Set M) := AddSubmonoid.smul_subset_smul end variable [IsScalarTower R A A] /-- Multiplication of sub-R-modules of an R-module A that is also a semiring. The submodule `M * N` consists of finite sums of elements `m * n` for `m ∈ M` and `n ∈ N`. -/ instance mul : Mul (Submodule R A) where mul := (· • ·) variable (S T : Set A) {M N P Q : Submodule R A} {m n : A} theorem mul_mem_mul (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N := smul_mem_smul hm hn theorem mul_le : M * N ≤ P ↔ ∀ m ∈ M, ∀ n ∈ N, m * n ∈ P := smul_le theorem mul_toAddSubmonoid (M N : Submodule R A) : (M * N).toAddSubmonoid = M.toAddSubmonoid * N.toAddSubmonoid := rfl @[elab_as_elim] protected theorem mul_induction_on {C : A → Prop} {r : A} (hr : r ∈ M * N) (hm : ∀ m ∈ M, ∀ n ∈ N, C (m * n)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := smul_induction_on hr hm ha /-- A dependent version of `mul_induction_on`. -/ @[elab_as_elim] protected theorem mul_induction_on' {C : ∀ r, r ∈ M * N → Prop} (mem_mul_mem : ∀ m (hm : m ∈ M) n (hn : n ∈ N), C (m * n) (mul_mem_mul hm hn)) (add : ∀ x hx y hy, C x hx → C y hy → C (x + y) (add_mem hx hy)) {r : A} (hr : r ∈ M * N) : C r hr := smul_induction_on' hr mem_mul_mem add variable (M) @[simp] theorem mul_bot : M * ⊥ = ⊥ := smul_bot _ @[simp] theorem bot_mul : ⊥ * M = ⊥ := bot_smul _ protected theorem one_mul : (1 : Submodule R A) * M = M := Submodule.one_smul _ variable {M} @[mono] theorem mul_le_mul (hmp : M ≤ P) (hnq : N ≤ Q) : M * N ≤ P * Q := smul_mono hmp hnq theorem mul_le_mul_left (h : M ≤ N) : M * P ≤ N * P := smul_mono_left h theorem mul_le_mul_right (h : N ≤ P) : M * N ≤ M * P := smul_mono_right _ h theorem mul_comm_of_commute (h : ∀ m ∈ M, ∀ n ∈ N, Commute m n) : M * N = N * M := toAddSubmonoid_injective <| AddSubmonoid.mul_comm_of_commute h variable (M N P) theorem mul_sup : M * (N ⊔ P) = M * N ⊔ M * P := smul_sup _ _ _ theorem sup_mul : (M ⊔ N) * P = M * P ⊔ N * P := sup_smul _ _ _ theorem mul_subset_mul : (↑M : Set A) * (↑N : Set A) ⊆ (↑(M * N) : Set A) := smul_subset_smul _ _ lemma restrictScalars_mul {A B C} [Semiring A] [Semiring B] [Semiring C] [SMul A B] [Module A C] [Module B C] [IsScalarTower A C C] [IsScalarTower B C C] [IsScalarTower A B C] {I J : Submodule B C} : (I * J).restrictScalars A = I.restrictScalars A * J.restrictScalars A := rfl variable {ι : Sort uι} theorem iSup_mul (s : ι → Submodule R A) (t : Submodule R A) : (⨆ i, s i) * t = ⨆ i, s i * t := iSup_smul theorem mul_iSup (t : Submodule R A) (s : ι → Submodule R A) : (t * ⨆ i, s i) = ⨆ i, t * s i := smul_iSup /-- Sub-`R`-modules of an `R`-module form an idempotent semiring. -/ instance : NonUnitalSemiring (Submodule R A) where __ := toAddSubmonoid_injective.semigroup _ mul_toAddSubmonoid zero_mul := bot_mul mul_zero := mul_bot left_distrib := mul_sup right_distrib := sup_mul instance : Pow (Submodule R A) ℕ where pow s n := npowRec n s theorem pow_eq_npowRec {n : ℕ} : M ^ n = npowRec n M := rfl protected theorem pow_zero : M ^ 0 = 1 := rfl protected theorem pow_succ {n : ℕ} : M ^ (n + 1) = M ^ n * M := rfl protected theorem pow_add {m n : ℕ} (h : n ≠ 0) : M ^ (m + n) = M ^ m * M ^ n := npowRec_add m n h _ M.one_mul protected theorem pow_one : M ^ 1 = M := by rw [Submodule.pow_succ, Submodule.pow_zero, Submodule.one_mul] /-- `Submodule.pow_succ` with the right hand side commuted. -/ protected theorem pow_succ' {n : ℕ} (h : n ≠ 0) : M ^ (n + 1) = M * M ^ n := by rw [add_comm, M.pow_add h, Submodule.pow_one] theorem pow_toAddSubmonoid {n : ℕ} (h : n ≠ 0) : (M ^ n).toAddSubmonoid = M.toAddSubmonoid ^ n := by induction n with | zero => exact (h rfl).elim | succ n ih => rw [Submodule.pow_succ, pow_succ, mul_toAddSubmonoid] cases n with | zero => rw [Submodule.pow_zero, pow_zero, one_mul, ← mul_toAddSubmonoid, Submodule.one_mul] | succ n => rw [ih n.succ_ne_zero] theorem le_pow_toAddSubmonoid {n : ℕ} : M.toAddSubmonoid ^ n ≤ (M ^ n).toAddSubmonoid := by obtain rfl | hn := Decidable.eq_or_ne n 0 · rw [Submodule.pow_zero, pow_zero] exact le_one_toAddSubmonoid · exact (pow_toAddSubmonoid M hn).ge theorem pow_subset_pow {n : ℕ} : (↑M : Set A) ^ n ⊆ ↑(M ^ n : Submodule R A) := trans AddSubmonoid.pow_subset_pow (le_pow_toAddSubmonoid M) theorem pow_mem_pow {x : A} (hx : x ∈ M) (n : ℕ) : x ^ n ∈ M ^ n := pow_subset_pow _ <| Set.pow_mem_pow hx lemma restrictScalars_pow {A B C : Type*} [Semiring A] [Semiring B] [Semiring C] [SMul A B] [Module A C] [Module B C] [IsScalarTower A C C] [IsScalarTower B C C] [IsScalarTower A B C] {I : Submodule B C} : ∀ {n : ℕ}, (hn : n ≠ 0) → (I ^ n).restrictScalars A = I.restrictScalars A ^ n | 1, _ => by simp [Submodule.pow_one] | n + 2, _ => by simp [Submodule.pow_succ (n := n + 1), restrictScalars_mul, restrictScalars_pow n.succ_ne_zero] end Module variable {ι : Sort uι} variable {R : Type u} [CommSemiring R] section AlgebraSemiring variable {A : Type v} [Semiring A] [Algebra R A] variable (S T : Set A) {M N P Q : Submodule R A} {m n : A} theorem one_eq_range : (1 : Submodule R A) = LinearMap.range (Algebra.linearMap R A) := by rw [one_eq_span, LinearMap.span_singleton_eq_range, LinearMap.toSpanSingleton_eq_algebra_linearMap] theorem algebraMap_mem (r : R) : algebraMap R A r ∈ (1 : Submodule R A) := by simp [one_eq_range] @[simp] theorem mem_one {x : A} : x ∈ (1 : Submodule R A) ↔ ∃ y, algebraMap R A y = x := by simp [one_eq_range] protected theorem map_one {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') : map f.toLinearMap (1 : Submodule R A) = 1 := by ext simp @[simp] theorem map_op_one : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (1 : Submodule R A) = 1 := by ext x induction x simp @[simp] theorem comap_op_one : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (1 : Submodule R Aᵐᵒᵖ) = 1 := by ext simp @[simp] theorem map_unop_one : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (1 : Submodule R Aᵐᵒᵖ) = 1 := by rw [← comap_equiv_eq_map_symm, comap_op_one] @[simp] theorem comap_unop_one : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (1 : Submodule R A) = 1 := by rw [← map_equiv_eq_comap_symm, map_op_one] theorem mul_eq_map₂ : M * N = map₂ (LinearMap.mul R A) M N := le_antisymm (mul_le.mpr fun _m hm _n ↦ apply_mem_map₂ _ hm) (map₂_le.mpr fun _m hm _n ↦ mul_mem_mul hm) variable (R M N) theorem span_mul_span : span R S * span R T = span R (S * T) := by rw [mul_eq_map₂]; apply map₂_span_span lemma mul_def : M * N = span R (M * N : Set A) := by simp [← span_mul_span] variable {R} (P Q) protected theorem mul_one : M * 1 = M := by conv_lhs => rw [one_eq_span, ← span_eq M] rw [span_mul_span] simp protected theorem map_mul {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') : map f.toLinearMap (M * N) = map f.toLinearMap M * map f.toLinearMap N := calc map f.toLinearMap (M * N) = ⨆ i : M, (N.map (LinearMap.mul R A i)).map f.toLinearMap := by rw [mul_eq_map₂]; apply map_iSup _ = map f.toLinearMap M * map f.toLinearMap N := by rw [mul_eq_map₂] apply congr_arg sSup ext S constructor <;> rintro ⟨y, hy⟩ · use ⟨f y, mem_map.mpr ⟨y.1, y.2, rfl⟩⟩ refine Eq.trans ?_ hy ext simp · obtain ⟨y', hy', fy_eq⟩ := mem_map.mp y.2 use ⟨y', hy'⟩ refine Eq.trans ?_ hy rw [f.toLinearMap_apply] at fy_eq ext simp [fy_eq] theorem map_op_mul : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M * N) = map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) N * map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M := by apply le_antisymm · simp_rw [map_le_iff_le_comap] refine mul_le.2 fun m hm n hn => ?_ rw [mem_comap, map_equiv_eq_comap_symm, map_equiv_eq_comap_symm] show op n * op m ∈ _ exact mul_mem_mul hn hm · refine mul_le.2 (MulOpposite.rec' fun m hm => MulOpposite.rec' fun n hn => ?_) rw [Submodule.mem_map_equiv] at hm hn ⊢ exact mul_mem_mul hn hm theorem comap_unop_mul : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M * N) = comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) N * comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M := by simp_rw [← map_equiv_eq_comap_symm, map_op_mul] theorem map_unop_mul (M N : Submodule R Aᵐᵒᵖ) : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M * N) = map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) N * map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M := have : Function.Injective (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) := LinearEquiv.injective _ map_injective_of_injective this <| by rw [← map_comp, map_op_mul, ← map_comp, ← map_comp, LinearEquiv.comp_coe, LinearEquiv.symm_trans_self, LinearEquiv.refl_toLinearMap, map_id, map_id, map_id] theorem comap_op_mul (M N : Submodule R Aᵐᵒᵖ) : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M * N) = comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) N * comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M := by simp_rw [comap_equiv_eq_map_symm, map_unop_mul] section variable {α : Type*} [Monoid α] [DistribMulAction α A] [SMulCommClass α R A] instance [IsScalarTower α A A] : IsScalarTower α (Submodule R A) (Submodule R A) where smul_assoc a S T := by rw [← S.span_eq, ← T.span_eq, smul_span, smul_eq_mul, smul_eq_mul, span_mul_span, span_mul_span, smul_span, smul_mul_assoc] instance [SMulCommClass α A A] : SMulCommClass α (Submodule R A) (Submodule R A) where smul_comm a S T := by rw [← S.span_eq, ← T.span_eq, smul_span, smul_eq_mul, smul_eq_mul, span_mul_span, span_mul_span, smul_span, mul_smul_comm] instance [SMulCommClass A α A] : SMulCommClass (Submodule R A) α (Submodule R A) := have := SMulCommClass.symm A α A; .symm .. end section open Pointwise /-- `Submodule.pointwiseNeg` distributes over multiplication. This is available as an instance in the `Pointwise` locale. -/ protected def hasDistribPointwiseNeg {A} [Ring A] [Algebra R A] : HasDistribNeg (Submodule R A) := toAddSubmonoid_injective.hasDistribNeg _ neg_toAddSubmonoid mul_toAddSubmonoid scoped[Pointwise] attribute [instance] Submodule.hasDistribPointwiseNeg end section DecidableEq theorem mem_span_mul_finite_of_mem_span_mul {R A} [Semiring R] [AddCommMonoid A] [Mul A] [Module R A] {S : Set A} {S' : Set A} {x : A} (hx : x ∈ span R (S * S')) : ∃ T T' : Finset A, ↑T ⊆ S ∧ ↑T' ⊆ S' ∧ x ∈ span R (T * T' : Set A) := by classical obtain ⟨U, h, hU⟩ := mem_span_finite_of_mem_span hx obtain ⟨T, T', hS, hS', h⟩ := Finset.subset_mul h use T, T', hS, hS' have h' : (U : Set A) ⊆ T * T' := by assumption_mod_cast have h'' := span_mono h' hU assumption end DecidableEq theorem mul_eq_span_mul_set (s t : Submodule R A) : s * t = span R ((s : Set A) * (t : Set A)) := by rw [mul_eq_map₂]; exact map₂_eq_span_image2 _ s t theorem mem_span_mul_finite_of_mem_mul {P Q : Submodule R A} {x : A} (hx : x ∈ P * Q) : ∃ T T' : Finset A, (T : Set A) ⊆ P ∧ (T' : Set A) ⊆ Q ∧ x ∈ span R (T * T' : Set A) := Submodule.mem_span_mul_finite_of_mem_span_mul (by rwa [← Submodule.span_eq P, ← Submodule.span_eq Q, Submodule.span_mul_span] at hx) variable {M N P} theorem mem_span_singleton_mul {x y : A} : x ∈ span R {y} * P ↔ ∃ z ∈ P, y * z = x := by simp_rw [mul_eq_map₂, map₂_span_singleton_eq_map, mem_map, LinearMap.mul_apply_apply] theorem mem_mul_span_singleton {x y : A} : x ∈ P * span R {y} ↔ ∃ z ∈ P, z * y = x := by simp_rw [mul_eq_map₂, map₂_span_singleton_eq_map_flip, mem_map, LinearMap.flip_apply, LinearMap.mul_apply_apply] lemma span_singleton_mul {x : A} {p : Submodule R A} : Submodule.span R {x} * p = x • p := ext fun _ ↦ mem_span_singleton_mul lemma mem_smul_iff_inv_mul_mem {S} [DivisionSemiring S] [Algebra R S] {x : S} {p : Submodule R S} {y : S} (hx : x ≠ 0) : y ∈ x • p ↔ x⁻¹ * y ∈ p := by constructor · rintro ⟨a, ha : a ∈ p, rfl⟩; simpa [inv_mul_cancel_left₀ hx] · exact fun h ↦ ⟨_, h, by simp [mul_inv_cancel_left₀ hx]⟩ lemma mul_mem_smul_iff {S} [CommRing S] [Algebra R S] {x : S} {p : Submodule R S} {y : S} (hx : x ∈ nonZeroDivisors S) : x * y ∈ x • p ↔ y ∈ p := by simp [mem_smul_pointwise_iff_exists, mul_cancel_left_mem_nonZeroDivisors hx] variable (M N) in theorem mul_smul_mul_eq_smul_mul_smul (x y : R) : (x * y) • (M * N) = (x • M) * (y • N) := by ext refine ⟨?_, fun hx ↦ Submodule.mul_induction_on hx ?_ fun _ _ hx hy ↦ Submodule.add_mem _ hx hy⟩ · rintro ⟨_, hx, rfl⟩ rw [DistribMulAction.toLinearMap_apply] refine Submodule.mul_induction_on hx (fun m hm n hn ↦ ?_) (fun _ _ hn hm ↦ ?_) · rw [mul_smul_mul_comm] exact mul_mem_mul (smul_mem_pointwise_smul m x M hm) (smul_mem_pointwise_smul n y N hn) · rw [smul_add] exact Submodule.add_mem _ hn hm · rintro _ ⟨m, hm, rfl⟩ _ ⟨n, hn, rfl⟩ simp_rw [DistribMulAction.toLinearMap_apply, smul_mul_smul_comm] exact smul_mem_pointwise_smul _ _ _ (mul_mem_mul hm hn) /-- Sub-R-modules of an R-algebra form an idempotent semiring. -/ instance idemSemiring : IdemSemiring (Submodule R A) where __ := instNonUnitalSemiring one_mul := Submodule.one_mul mul_one := Submodule.mul_one bot_le _ := bot_le variable (M) theorem span_pow (s : Set A) : ∀ n : ℕ, span R s ^ n = span R (s ^ n) | 0 => by rw [pow_zero, pow_zero, one_eq_span_one_set] | n + 1 => by rw [pow_succ, pow_succ, span_pow s n, span_mul_span] theorem pow_eq_span_pow_set (n : ℕ) : M ^ n = span R ((M : Set A) ^ n) := by rw [← span_pow, span_eq] /-- Dependent version of `Submodule.pow_induction_on_left`. -/ @[elab_as_elim] protected theorem pow_induction_on_left' {C : ∀ (n : ℕ) (x), x ∈ M ^ n → Prop} (algebraMap : ∀ r : R, C 0 (algebraMap _ _ r) (algebraMap_mem r)) (add : ∀ x y i hx hy, C i x hx → C i y hy → C i (x + y) (add_mem ‹_› ‹_›)) (mem_mul : ∀ m (hm : m ∈ M), ∀ (i x hx), C i x hx → C i.succ (m * x) ((pow_succ' M i).symm ▸ (mul_mem_mul hm hx))) {n : ℕ} {x : A} (hx : x ∈ M ^ n) : C n x hx := by induction n generalizing x with | zero => rw [pow_zero] at hx obtain ⟨r, rfl⟩ := mem_one.mp hx exact algebraMap r | succ n n_ih => revert hx simp_rw [pow_succ'] exact fun hx ↦ Submodule.mul_induction_on' (fun m hm x ih => mem_mul _ hm _ _ _ (n_ih ih)) (fun x hx y hy Cx Cy => add _ _ _ _ _ Cx Cy) hx /-- Dependent version of `Submodule.pow_induction_on_right`. -/ @[elab_as_elim] protected theorem pow_induction_on_right' {C : ∀ (n : ℕ) (x), x ∈ M ^ n → Prop} (algebraMap : ∀ r : R, C 0 (algebraMap _ _ r) (algebraMap_mem r)) (add : ∀ x y i hx hy, C i x hx → C i y hy → C i (x + y) (add_mem ‹_› ‹_›)) (mul_mem : ∀ i x hx, C i x hx → ∀ m (hm : m ∈ M), C i.succ (x * m) (mul_mem_mul hx hm)) {n : ℕ} {x : A} (hx : x ∈ M ^ n) : C n x hx := by induction n generalizing x with | zero => rw [pow_zero] at hx obtain ⟨r, rfl⟩ := mem_one.mp hx exact algebraMap r | succ n n_ih => revert hx simp_rw [pow_succ] exact fun hx ↦ Submodule.mul_induction_on' (fun m hm x ih => mul_mem _ _ hm (n_ih _) _ ih) (fun x hx y hy Cx Cy => add _ _ _ _ _ Cx Cy) hx /-- To show a property on elements of `M ^ n` holds, it suffices to show that it holds for scalars, is closed under addition, and holds for `m * x` where `m ∈ M` and it holds for `x` -/ @[elab_as_elim] protected theorem pow_induction_on_left {C : A → Prop} (hr : ∀ r : R, C (algebraMap _ _ r)) (hadd : ∀ x y, C x → C y → C (x + y)) (hmul : ∀ m ∈ M, ∀ (x), C x → C (m * x)) {x : A} {n : ℕ} (hx : x ∈ M ^ n) : C x := Submodule.pow_induction_on_left' M (C := fun _ a _ => C a) hr (fun x y _i _hx _hy => hadd x y) (fun _m hm _i _x _hx => hmul _ hm _) hx /-- To show a property on elements of `M ^ n` holds, it suffices to show that it holds for scalars, is closed under addition, and holds for `x * m` where `m ∈ M` and it holds for `x` -/ @[elab_as_elim] protected theorem pow_induction_on_right {C : A → Prop} (hr : ∀ r : R, C (algebraMap _ _ r)) (hadd : ∀ x y, C x → C y → C (x + y)) (hmul : ∀ x, C x → ∀ m ∈ M, C (x * m)) {x : A} {n : ℕ} (hx : x ∈ M ^ n) : C x := Submodule.pow_induction_on_right' (M := M) (C := fun _ a _ => C a) hr (fun x y _i _hx _hy => hadd x y) (fun _i _x _hx => hmul _) hx /-- `Submonoid.map` as a `RingHom`, when applied to an `AlgHom`. -/ @[simps] def mapHom {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') : Submodule R A →+* Submodule R A' where toFun := map f.toLinearMap map_zero' := Submodule.map_bot _
map_add' := (Submodule.map_sup · · _) map_one' := Submodule.map_one _ map_mul' := (Submodule.map_mul · · _) theorem mapHom_id : mapHom (.id R A) = .id _ := RingHom.ext map_id /-- The ring of submodules of the opposite algebra is isomorphic to the opposite ring of
Mathlib/Algebra/Algebra/Operations.lean
643
649
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.Algebra.EuclideanDomain.Basic import Mathlib.RingTheory.FractionalIdeal.Basic import Mathlib.RingTheory.IntegralClosure.IsIntegral.Basic import Mathlib.RingTheory.LocalRing.Basic import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Tactic.FieldSimp /-! # More operations on fractional ideals ## Main definitions * `map` is the pushforward of a fractional ideal along an algebra morphism Let `K` be the localization of `R` at `R⁰ = R \ {0}` (i.e. the field of fractions). * `FractionalIdeal R⁰ K` is the type of fractional ideals in the field of fractions * `Div (FractionalIdeal R⁰ K)` instance: the ideal quotient `I / J` (typically written $I : J$, but a `:` operator cannot be defined) ## Main statement * `isNoetherian` states that every fractional ideal of a noetherian integral domain is noetherian ## References * https://en.wikipedia.org/wiki/Fractional_ideal ## Tags fractional ideal, fractional ideals, invertible ideal -/ open IsLocalization Pointwise nonZeroDivisors namespace FractionalIdeal open Set Submodule variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] section variable {P' : Type*} [CommRing P'] [Algebra R P'] variable {P'' : Type*} [CommRing P''] [Algebra R P''] theorem _root_.IsFractional.map (g : P →ₐ[R] P') {I : Submodule R P} : IsFractional S I → IsFractional S (Submodule.map g.toLinearMap I) | ⟨a, a_nonzero, hI⟩ => ⟨a, a_nonzero, fun b hb => by obtain ⟨b', b'_mem, hb'⟩ := Submodule.mem_map.mp hb rw [AlgHom.toLinearMap_apply] at hb' obtain ⟨x, hx⟩ := hI b' b'_mem use x rw [← g.commutes, hx, map_smul, hb']⟩ /-- `I.map g` is the pushforward of the fractional ideal `I` along the algebra morphism `g` -/ def map (g : P →ₐ[R] P') : FractionalIdeal S P → FractionalIdeal S P' := fun I => ⟨Submodule.map g.toLinearMap I, I.isFractional.map g⟩ @[simp, norm_cast] theorem coe_map (g : P →ₐ[R] P') (I : FractionalIdeal S P) : ↑(map g I) = Submodule.map g.toLinearMap I := rfl @[simp] theorem mem_map {I : FractionalIdeal S P} {g : P →ₐ[R] P'} {y : P'} : y ∈ I.map g ↔ ∃ x, x ∈ I ∧ g x = y := Submodule.mem_map variable (I J : FractionalIdeal S P) (g : P →ₐ[R] P') @[simp] theorem map_id : I.map (AlgHom.id _ _) = I := coeToSubmodule_injective (Submodule.map_id (I : Submodule R P)) @[simp] theorem map_comp (g' : P' →ₐ[R] P'') : I.map (g'.comp g) = (I.map g).map g' := coeToSubmodule_injective (Submodule.map_comp g.toLinearMap g'.toLinearMap I) @[simp, norm_cast] theorem map_coeIdeal (I : Ideal R) : (I : FractionalIdeal S P).map g = I := by ext x simp only [mem_coeIdeal] constructor · rintro ⟨_, ⟨y, hy, rfl⟩, rfl⟩ exact ⟨y, hy, (g.commutes y).symm⟩ · rintro ⟨y, hy, rfl⟩ exact ⟨_, ⟨y, hy, rfl⟩, g.commutes y⟩ @[simp] protected theorem map_one : (1 : FractionalIdeal S P).map g = 1 := map_coeIdeal g ⊤ @[simp] protected theorem map_zero : (0 : FractionalIdeal S P).map g = 0 := map_coeIdeal g 0 @[simp] protected theorem map_add : (I + J).map g = I.map g + J.map g := coeToSubmodule_injective (Submodule.map_sup _ _ _) @[simp] protected theorem map_mul : (I * J).map g = I.map g * J.map g := by simp only [mul_def] exact coeToSubmodule_injective (Submodule.map_mul _ _ _) @[simp] theorem map_map_symm (g : P ≃ₐ[R] P') : (I.map (g : P →ₐ[R] P')).map (g.symm : P' →ₐ[R] P) = I := by rw [← map_comp, g.symm_comp, map_id] @[simp] theorem map_symm_map (I : FractionalIdeal S P') (g : P ≃ₐ[R] P') : (I.map (g.symm : P' →ₐ[R] P)).map (g : P →ₐ[R] P') = I := by rw [← map_comp, g.comp_symm, map_id] theorem map_mem_map {f : P →ₐ[R] P'} (h : Function.Injective f) {x : P} {I : FractionalIdeal S P} : f x ∈ map f I ↔ x ∈ I := mem_map.trans ⟨fun ⟨_, hx', x'_eq⟩ => h x'_eq ▸ hx', fun h => ⟨x, h, rfl⟩⟩ theorem map_injective (f : P →ₐ[R] P') (h : Function.Injective f) : Function.Injective (map f : FractionalIdeal S P → FractionalIdeal S P') := fun _ _ hIJ => ext fun _ => (map_mem_map h).symm.trans (hIJ.symm ▸ map_mem_map h) /-- If `g` is an equivalence, `map g` is an isomorphism -/ def mapEquiv (g : P ≃ₐ[R] P') : FractionalIdeal S P ≃+* FractionalIdeal S P' where toFun := map g invFun := map g.symm map_add' I J := FractionalIdeal.map_add I J _ map_mul' I J := FractionalIdeal.map_mul I J _ left_inv I := by rw [← map_comp, AlgEquiv.symm_comp, map_id] right_inv I := by rw [← map_comp, AlgEquiv.comp_symm, map_id] @[simp] theorem coeFun_mapEquiv (g : P ≃ₐ[R] P') : (mapEquiv g : FractionalIdeal S P → FractionalIdeal S P') = map g := rfl @[simp] theorem mapEquiv_apply (g : P ≃ₐ[R] P') (I : FractionalIdeal S P) : mapEquiv g I = map (↑g) I := rfl @[simp] theorem mapEquiv_symm (g : P ≃ₐ[R] P') : ((mapEquiv g).symm : FractionalIdeal S P' ≃+* _) = mapEquiv g.symm := rfl @[simp] theorem mapEquiv_refl : mapEquiv AlgEquiv.refl = RingEquiv.refl (FractionalIdeal S P) := RingEquiv.ext fun x => by simp theorem isFractional_span_iff {s : Set P} : IsFractional S (span R s) ↔ ∃ a ∈ S, ∀ b : P, b ∈ s → IsInteger R (a • b) := ⟨fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun b hb => h b (subset_span hb)⟩, fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun _ hb => span_induction (hx := hb) h (by rw [smul_zero] exact isInteger_zero) (fun x y _ _ hx hy => by rw [smul_add] exact isInteger_add hx hy) fun s x _ hx => by rw [smul_comm] exact isInteger_smul hx⟩⟩ theorem isFractional_of_fg [IsLocalization S P] {I : Submodule R P} (hI : I.FG) : IsFractional S I := by rcases hI with ⟨I, rfl⟩ rcases exist_integer_multiples_of_finset S I with ⟨⟨s, hs1⟩, hs⟩ rw [isFractional_span_iff] exact ⟨s, hs1, hs⟩ theorem mem_span_mul_finite_of_mem_mul {I J : FractionalIdeal S P} {x : P} (hx : x ∈ I * J) : ∃ T T' : Finset P, (T : Set P) ⊆ I ∧ (T' : Set P) ⊆ J ∧ x ∈ span R (T * T' : Set P) := Submodule.mem_span_mul_finite_of_mem_mul (by simpa using mem_coe.mpr hx) variable (S) in theorem coeIdeal_fg (inj : Function.Injective (algebraMap R P)) (I : Ideal R) : FG ((I : FractionalIdeal S P) : Submodule R P) ↔ I.FG := coeSubmodule_fg _ inj _ theorem fg_unit (I : (FractionalIdeal S P)ˣ) : FG (I : Submodule R P) := Submodule.fg_unit <| Units.map (coeSubmoduleHom S P).toMonoidHom I theorem fg_of_isUnit (I : FractionalIdeal S P) (h : IsUnit I) : FG (I : Submodule R P) := fg_unit h.unit theorem _root_.Ideal.fg_of_isUnit (inj : Function.Injective (algebraMap R P)) (I : Ideal R) (h : IsUnit (I : FractionalIdeal S P)) : I.FG := by rw [← coeIdeal_fg S inj I] exact FractionalIdeal.fg_of_isUnit (R := R) I h variable (S P P') variable [IsLocalization S P] [IsLocalization S P'] /-- `canonicalEquiv f f'` is the canonical equivalence between the fractional ideals in `P` and in `P'`, which are both localizations of `R` at `S`. -/ noncomputable irreducible_def canonicalEquiv : FractionalIdeal S P ≃+* FractionalIdeal S P' := mapEquiv { ringEquivOfRingEquiv P P' (RingEquiv.refl R) (show S.map _ = S by rw [RingEquiv.toMonoidHom_refl, Submonoid.map_id]) with commutes' := fun _ => ringEquivOfRingEquiv_eq _ _ } @[simp] theorem mem_canonicalEquiv_apply {I : FractionalIdeal S P} {x : P'} : x ∈ canonicalEquiv S P P' I ↔ ∃ y ∈ I, IsLocalization.map P' (RingHom.id R) (fun y (hy : y ∈ S) => show RingHom.id R y ∈ S from hy) (y : P) = x := by rw [canonicalEquiv, mapEquiv_apply, mem_map] exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩ @[simp] theorem canonicalEquiv_symm : (canonicalEquiv S P P').symm = canonicalEquiv S P' P := RingEquiv.ext fun I => SetLike.ext_iff.mpr fun x => by rw [mem_canonicalEquiv_apply, canonicalEquiv, mapEquiv_symm, mapEquiv_apply, mem_map] exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩ theorem canonicalEquiv_flip (I) : canonicalEquiv S P P' (canonicalEquiv S P' P I) = I := by rw [← canonicalEquiv_symm, RingEquiv.symm_apply_apply] @[simp] theorem canonicalEquiv_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] (I : FractionalIdeal S P) : canonicalEquiv S P' P'' (canonicalEquiv S P P' I) = canonicalEquiv S P P'' I := by ext simp only [IsLocalization.map_map, RingHomInvPair.comp_eq₂, mem_canonicalEquiv_apply, exists_prop, exists_exists_and_eq_and] theorem canonicalEquiv_trans_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] : (canonicalEquiv S P P').trans (canonicalEquiv S P' P'') = canonicalEquiv S P P'' := RingEquiv.ext (canonicalEquiv_canonicalEquiv S P P' P'') @[simp] theorem canonicalEquiv_coeIdeal (I : Ideal R) : canonicalEquiv S P P' I = I := by ext simp [IsLocalization.map_eq] @[simp] theorem canonicalEquiv_self : canonicalEquiv S P P = RingEquiv.refl _ := by rw [← canonicalEquiv_trans_canonicalEquiv S P P] convert (canonicalEquiv S P P).symm_trans_self exact (canonicalEquiv_symm S P P).symm end section IsFractionRing /-! ### `IsFractionRing` section This section concerns fractional ideals in the field of fractions, i.e. the type `FractionalIdeal R⁰ K` where `IsFractionRing R K`. -/ variable {K K' : Type*} [Field K] [Field K'] variable [Algebra R K] [IsFractionRing R K] [Algebra R K'] [IsFractionRing R K'] variable {I J : FractionalIdeal R⁰ K} (h : K →ₐ[R] K') /-- Nonzero fractional ideals contain a nonzero integer. -/ theorem exists_ne_zero_mem_isInteger [Nontrivial R] (hI : I ≠ 0) : ∃ x, x ≠ 0 ∧ algebraMap R K x ∈ I := by obtain ⟨y : K, y_mem, y_not_mem⟩ := SetLike.exists_of_lt (by simpa only using bot_lt_iff_ne_bot.mpr hI) have y_ne_zero : y ≠ 0 := by simpa using y_not_mem obtain ⟨z, ⟨x, hx⟩⟩ := exists_integer_multiple R⁰ y refine ⟨x, ?_, ?_⟩ · rw [Ne, ← @IsFractionRing.to_map_eq_zero_iff R _ K, hx, Algebra.smul_def] exact mul_ne_zero (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors z.2) y_ne_zero · rw [hx] exact smul_mem _ _ y_mem theorem map_ne_zero [Nontrivial R] (hI : I ≠ 0) : I.map h ≠ 0 := by obtain ⟨x, x_ne_zero, hx⟩ := exists_ne_zero_mem_isInteger hI contrapose! x_ne_zero with map_eq_zero refine IsFractionRing.to_map_eq_zero_iff.mp (eq_zero_iff.mp map_eq_zero _ (mem_map.mpr ?_)) exact ⟨algebraMap R K x, hx, h.commutes x⟩ @[simp] theorem map_eq_zero_iff [Nontrivial R] : I.map h = 0 ↔ I = 0 := ⟨not_imp_not.mp (map_ne_zero _), fun hI => hI.symm ▸ FractionalIdeal.map_zero h⟩ theorem coeIdeal_injective : Function.Injective (fun (I : Ideal R) ↦ (I : FractionalIdeal R⁰ K)) := coeIdeal_injective' le_rfl theorem coeIdeal_inj {I J : Ideal R} : (I : FractionalIdeal R⁰ K) = (J : FractionalIdeal R⁰ K) ↔ I = J := coeIdeal_inj' le_rfl @[simp] theorem coeIdeal_eq_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 0 ↔ I = ⊥ := coeIdeal_eq_zero' le_rfl theorem coeIdeal_ne_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 0 ↔ I ≠ ⊥ := coeIdeal_ne_zero' le_rfl @[simp] theorem coeIdeal_eq_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 1 ↔ I = 1 := by simpa only [Ideal.one_eq_top] using coeIdeal_inj theorem coeIdeal_ne_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 1 ↔ I ≠ 1 := not_iff_not.mpr coeIdeal_eq_one theorem num_eq_zero_iff [Nontrivial R] {I : FractionalIdeal R⁰ K} : I.num = 0 ↔ I = 0 := ⟨fun h ↦ zero_of_num_eq_bot zero_not_mem_nonZeroDivisors h, fun h ↦ h ▸ num_zero_eq (IsFractionRing.injective R K)⟩ end IsFractionRing section Quotient /-! ### `quotient` section This section defines the ideal quotient of fractional ideals. In this section we need that each non-zero `y : R` has an inverse in the localization, i.e. that the localization is a field. We satisfy this assumption by taking `S = nonZeroDivisors R`, `R`'s localization at which is a field because `R` is a domain. -/ variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K] variable [Algebra R₁ K] instance : Nontrivial (FractionalIdeal R₁⁰ K) := ⟨⟨0, 1, fun h => have this : (1 : K) ∈ (0 : FractionalIdeal R₁⁰ K) := by rw [← (algebraMap R₁ K).map_one] simpa only [h] using coe_mem_one R₁⁰ 1 one_ne_zero ((mem_zero_iff _).mp this)⟩⟩ theorem ne_zero_of_mul_eq_one (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : I ≠ 0 := fun hI => zero_ne_one' (FractionalIdeal R₁⁰ K) (by convert h simp [hI]) variable [IsFractionRing R₁ K] [IsDomain R₁] theorem _root_.IsFractional.div_of_nonzero {I J : Submodule R₁ K} : IsFractional R₁⁰ I → IsFractional R₁⁰ J → J ≠ 0 → IsFractional R₁⁰ (I / J) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩, h => by obtain ⟨y, mem_J, not_mem_zero⟩ := SetLike.exists_of_lt (show 0 < J by simpa only using bot_lt_iff_ne_bot.mpr h) obtain ⟨y', hy'⟩ := hJ y mem_J use aI * y' constructor · apply (nonZeroDivisors R₁).mul_mem haI (mem_nonZeroDivisors_iff_ne_zero.mpr _) intro y'_eq_zero have : algebraMap R₁ K aJ * y = 0 := by rw [← Algebra.smul_def, ← hy', y'_eq_zero, RingHom.map_zero] have y_zero := (mul_eq_zero.mp this).resolve_left (mt ((injective_iff_map_eq_zero (algebraMap R₁ K)).1 (IsFractionRing.injective _ _) _) (mem_nonZeroDivisors_iff_ne_zero.mp haJ)) apply not_mem_zero simpa intro b hb convert hI _ (hb _ (Submodule.smul_mem _ aJ mem_J)) using 1 rw [← hy', mul_comm b, ← Algebra.smul_def, mul_smul] theorem fractional_div_of_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : IsFractional R₁⁰ (I / J : Submodule R₁ K) := I.isFractional.div_of_nonzero J.isFractional fun H => h <| coeToSubmodule_injective <| H.trans coe_zero.symm open Classical in noncomputable instance : Div (FractionalIdeal R₁⁰ K) := ⟨fun I J => if h : J = 0 then 0 else ⟨I / J, fractional_div_of_nonzero h⟩⟩ variable {I J : FractionalIdeal R₁⁰ K} @[simp] theorem div_zero {I : FractionalIdeal R₁⁰ K} : I / 0 = 0 := dif_pos rfl
theorem div_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : I / J = ⟨I / J, fractional_div_of_nonzero h⟩ := dif_neg h @[simp]
Mathlib/RingTheory/FractionalIdeal/Operations.lean
390
394
/- 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) :
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
636
641
/- 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.Group.Unbundled.Int import Mathlib.Algebra.Order.Nonneg.Basic import Mathlib.Algebra.Order.Ring.Unbundled.Rat import Mathlib.Algebra.Ring.Rat import Mathlib.Data.Set.Operations import Mathlib.Order.Bounds.Defs import Mathlib.Order.GaloisConnection.Defs /-! # Nonnegative rationals This file defines the nonnegative rationals as a subtype of `Rat` and provides its basic algebraic order structure. Note that `NNRat` is not declared as a `Semifield` here. See `Mathlib.Algebra.Field.Rat` for that instance. We also define an instance `CanLift ℚ ℚ≥0`. This instance can be used by the `lift` tactic to replace `x : ℚ` and `hx : 0 ≤ x` in the proof context with `x : ℚ≥0` while replacing all occurrences of `x` with `↑x`. This tactic also works for a function `f : α → ℚ` with a hypothesis `hf : ∀ x, 0 ≤ f x`. ## Notation `ℚ≥0` is notation for `NNRat` in locale `NNRat`. ## Huge warning Whenever you state a lemma about the coercion `ℚ≥0 → ℚ`, check that Lean inserts `NNRat.cast`, not `Subtype.val`. Else your lemma will never apply. -/ assert_not_exists CompleteLattice OrderedCommMonoid library_note "specialised high priority simp lemma" /-- It sometimes happens that a `@[simp]` lemma declared early in the library can be proved by `simp` using later, more general simp lemmas. In that case, the following reasons might be arguments for the early lemma to be tagged `@[simp high]` (rather than `@[simp, nolint simpNF]` or un``@[simp]``ed): 1. There is a significant portion of the library which needs the early lemma to be available via `simp` and which doesn't have access to the more general lemmas. 2. The more general lemmas have more complicated typeclass assumptions, causing rewrites with them to be slower. -/ open Function instance Rat.instZeroLEOneClass : ZeroLEOneClass ℚ where zero_le_one := rfl instance Rat.instPosMulMono : PosMulMono ℚ where elim := fun r p q h => by simp only [mul_comm] simpa [sub_mul, sub_nonneg] using Rat.mul_nonneg (sub_nonneg.2 h) r.2 deriving instance CommSemiring for NNRat deriving instance LinearOrder for NNRat deriving instance Sub for NNRat deriving instance Inhabited for NNRat namespace NNRat variable {p q : ℚ≥0} instance instNontrivial : Nontrivial ℚ≥0 where exists_pair_ne := ⟨1, 0, by decide⟩ instance instOrderBot : OrderBot ℚ≥0 where bot := 0 bot_le q := q.2 @[simp] lemma val_eq_cast (q : ℚ≥0) : q.1 = q := rfl instance instCharZero : CharZero ℚ≥0 where cast_injective a b hab := by simpa using congr_arg num hab instance canLift : CanLift ℚ ℚ≥0 (↑) fun q ↦ 0 ≤ q where prf q hq := ⟨⟨q, hq⟩, rfl⟩ @[ext] theorem ext : (p : ℚ) = (q : ℚ) → p = q := Subtype.ext protected theorem coe_injective : Injective ((↑) : ℚ≥0 → ℚ) := Subtype.coe_injective -- See note [specialised high priority simp lemma] @[simp high, norm_cast] theorem coe_inj : (p : ℚ) = q ↔ p = q := Subtype.coe_inj theorem ne_iff {x y : ℚ≥0} : (x : ℚ) ≠ (y : ℚ) ↔ x ≠ y := NNRat.coe_inj.not -- TODO: We have to write `NNRat.cast` explicitly, else the statement picks up `Subtype.val` instead @[simp, norm_cast] lemma coe_mk (q : ℚ) (hq) : NNRat.cast ⟨q, hq⟩ = q := rfl lemma «forall» {p : ℚ≥0 → Prop} : (∀ q, p q) ↔ ∀ q hq, p ⟨q, hq⟩ := Subtype.forall lemma «exists» {p : ℚ≥0 → Prop} : (∃ q, p q) ↔ ∃ q hq, p ⟨q, hq⟩ := Subtype.exists /-- Reinterpret a rational number `q` as a non-negative rational number. Returns `0` if `q ≤ 0`. -/ def _root_.Rat.toNNRat (q : ℚ) : ℚ≥0 := ⟨max q 0, le_max_right _ _⟩ theorem _root_.Rat.coe_toNNRat (q : ℚ) (hq : 0 ≤ q) : (q.toNNRat : ℚ) = q := max_eq_left hq theorem _root_.Rat.le_coe_toNNRat (q : ℚ) : q ≤ q.toNNRat := le_max_left _ _ open Rat (toNNRat) @[simp] theorem coe_nonneg (q : ℚ≥0) : (0 : ℚ) ≤ q := q.2 @[simp, norm_cast] lemma coe_zero : ((0 : ℚ≥0) : ℚ) = 0 := rfl @[simp] lemma num_zero : num 0 = 0 := rfl @[simp] lemma den_zero : den 0 = 1 := rfl @[simp, norm_cast] lemma coe_one : ((1 : ℚ≥0) : ℚ) = 1 := rfl @[simp] lemma num_one : num 1 = 1 := rfl @[simp] lemma den_one : den 1 = 1 := rfl @[simp, norm_cast] theorem coe_add (p q : ℚ≥0) : ((p + q : ℚ≥0) : ℚ) = p + q := rfl @[simp, norm_cast] theorem coe_mul (p q : ℚ≥0) : ((p * q : ℚ≥0) : ℚ) = p * q := rfl @[simp, norm_cast] lemma coe_pow (q : ℚ≥0) (n : ℕ) : (↑(q ^ n) : ℚ) = (q : ℚ) ^ n := rfl @[simp] lemma num_pow (q : ℚ≥0) (n : ℕ) : (q ^ n).num = q.num ^ n := by simp [num, Int.natAbs_pow] @[simp] lemma den_pow (q : ℚ≥0) (n : ℕ) : (q ^ n).den = q.den ^ n := rfl @[simp, norm_cast] theorem coe_sub (h : q ≤ p) : ((p - q : ℚ≥0) : ℚ) = p - q := max_eq_left <| le_sub_comm.2 <| by rwa [sub_zero] -- See note [specialised high priority simp lemma] @[simp high] theorem coe_eq_zero : (q : ℚ) = 0 ↔ q = 0 := by norm_cast theorem coe_ne_zero : (q : ℚ) ≠ 0 ↔ q ≠ 0 := coe_eq_zero.not @[norm_cast] theorem coe_le_coe : (p : ℚ) ≤ q ↔ p ≤ q := Iff.rfl @[norm_cast] theorem coe_lt_coe : (p : ℚ) < q ↔ p < q := Iff.rfl @[norm_cast] theorem coe_pos : (0 : ℚ) < q ↔ 0 < q := Iff.rfl theorem coe_mono : Monotone ((↑) : ℚ≥0 → ℚ) := fun _ _ ↦ coe_le_coe.2 theorem toNNRat_mono : Monotone toNNRat := fun _ _ h ↦ max_le_max h le_rfl @[simp] theorem toNNRat_coe (q : ℚ≥0) : toNNRat q = q := ext <| max_eq_left q.2 @[simp] theorem toNNRat_coe_nat (n : ℕ) : toNNRat n = n := ext <| by simp only [Nat.cast_nonneg', Rat.coe_toNNRat]; rfl /-- `toNNRat` and `(↑) : ℚ≥0 → ℚ` form a Galois insertion. -/ protected def gi : GaloisInsertion toNNRat (↑) := GaloisInsertion.monotoneIntro coe_mono toNNRat_mono Rat.le_coe_toNNRat toNNRat_coe /-- Coercion `ℚ≥0 → ℚ` as a `RingHom`. -/ def coeHom : ℚ≥0 →+* ℚ where toFun := (↑) map_one' := coe_one map_mul' := coe_mul map_zero' := coe_zero map_add' := coe_add @[simp, norm_cast] lemma coe_natCast (n : ℕ) : (↑(↑n : ℚ≥0) : ℚ) = n := rfl @[simp] theorem mk_natCast (n : ℕ) : @Eq ℚ≥0 (⟨(n : ℚ), Nat.cast_nonneg' n⟩ : ℚ≥0) n := rfl @[simp] theorem coe_coeHom : ⇑coeHom = ((↑) : ℚ≥0 → ℚ) := rfl @[norm_cast] theorem nsmul_coe (q : ℚ≥0) (n : ℕ) : ↑(n • q) = n • (q : ℚ) := coeHom.toAddMonoidHom.map_nsmul _ _ theorem bddAbove_coe {s : Set ℚ≥0} : BddAbove ((↑) '' s : Set ℚ) ↔ BddAbove s := ⟨fun ⟨b, hb⟩ ↦ ⟨toNNRat b, fun ⟨y, _⟩ hys ↦ show y ≤ max b 0 from (hb <| Set.mem_image_of_mem _ hys).trans <| le_max_left _ _⟩, fun ⟨b, hb⟩ ↦ ⟨b, fun _ ⟨_, hx, Eq⟩ ↦ Eq ▸ hb hx⟩⟩ theorem bddBelow_coe (s : Set ℚ≥0) : BddBelow (((↑) : ℚ≥0 → ℚ) '' s) := ⟨0, fun _ ⟨q, _, h⟩ ↦ h ▸ q.2⟩ @[norm_cast] theorem coe_max (x y : ℚ≥0) : ((max x y : ℚ≥0) : ℚ) = max (x : ℚ) (y : ℚ) := coe_mono.map_max @[norm_cast] theorem coe_min (x y : ℚ≥0) : ((min x y : ℚ≥0) : ℚ) = min (x : ℚ) (y : ℚ) := coe_mono.map_min theorem sub_def (p q : ℚ≥0) : p - q = toNNRat (p - q) := rfl @[simp] theorem abs_coe (q : ℚ≥0) : |(q : ℚ)| = q := abs_of_nonneg q.2 -- See note [specialised high priority simp lemma] @[simp high] theorem nonpos_iff_eq_zero (q : ℚ≥0) : q ≤ 0 ↔ q = 0 := ⟨fun h => le_antisymm h q.2, fun h => h.symm ▸ q.2⟩ end NNRat open NNRat namespace Rat variable {p q : ℚ} @[simp] theorem toNNRat_zero : toNNRat 0 = 0 := rfl @[simp] theorem toNNRat_one : toNNRat 1 = 1 := rfl @[simp] theorem toNNRat_pos : 0 < toNNRat q ↔ 0 < q := by simp [toNNRat, ← coe_lt_coe] @[simp] theorem toNNRat_eq_zero : toNNRat q = 0 ↔ q ≤ 0 := by simpa [-toNNRat_pos] using (@toNNRat_pos q).not alias ⟨_, toNNRat_of_nonpos⟩ := toNNRat_eq_zero @[simp] theorem toNNRat_le_toNNRat_iff (hp : 0 ≤ p) : toNNRat q ≤ toNNRat p ↔ q ≤ p := by simp [← coe_le_coe, toNNRat, hp] @[simp] theorem toNNRat_lt_toNNRat_iff' : toNNRat q < toNNRat p ↔ q < p ∧ 0 < p := by simp [← coe_lt_coe, toNNRat, lt_irrefl] theorem toNNRat_lt_toNNRat_iff (h : 0 < p) : toNNRat q < toNNRat p ↔ q < p := toNNRat_lt_toNNRat_iff'.trans (and_iff_left h) theorem toNNRat_lt_toNNRat_iff_of_nonneg (hq : 0 ≤ q) : toNNRat q < toNNRat p ↔ q < p := toNNRat_lt_toNNRat_iff'.trans ⟨And.left, fun h ↦ ⟨h, hq.trans_lt h⟩⟩ @[simp] theorem toNNRat_add (hq : 0 ≤ q) (hp : 0 ≤ p) : toNNRat (q + p) = toNNRat q + toNNRat p := NNRat.ext <| by simp [toNNRat, hq, hp, add_nonneg] theorem toNNRat_add_le : toNNRat (q + p) ≤ toNNRat q + toNNRat p := coe_le_coe.1 <| max_le (add_le_add (le_max_left _ _) (le_max_left _ _)) <| coe_nonneg _ theorem toNNRat_le_iff_le_coe {p : ℚ≥0} : toNNRat q ≤ p ↔ q ≤ ↑p := NNRat.gi.gc q p theorem le_toNNRat_iff_coe_le {q : ℚ≥0} (hp : 0 ≤ p) : q ≤ toNNRat p ↔ ↑q ≤ p := by rw [← coe_le_coe, Rat.coe_toNNRat p hp] theorem le_toNNRat_iff_coe_le' {q : ℚ≥0} (hq : 0 < q) : q ≤ toNNRat p ↔ ↑q ≤ p := (le_or_lt 0 p).elim le_toNNRat_iff_coe_le fun hp ↦ by simp only [(hp.trans_le q.coe_nonneg).not_le, toNNRat_eq_zero.2 hp.le, hq.not_le] theorem toNNRat_lt_iff_lt_coe {p : ℚ≥0} (hq : 0 ≤ q) : toNNRat q < p ↔ q < ↑p := by rw [← coe_lt_coe, Rat.coe_toNNRat q hq] theorem lt_toNNRat_iff_coe_lt {q : ℚ≥0} : q < toNNRat p ↔ ↑q < p := NNRat.gi.gc.lt_iff_lt theorem toNNRat_mul (hp : 0 ≤ p) : toNNRat (p * q) = toNNRat p * toNNRat q := by rcases le_total 0 q with hq | hq · ext; simp [toNNRat, hp, hq, max_eq_left, mul_nonneg] · have hpq := mul_nonpos_of_nonneg_of_nonpos hp hq rw [toNNRat_eq_zero.2 hq, toNNRat_eq_zero.2 hpq, mul_zero] end Rat /-- The absolute value on `ℚ` as a map to `ℚ≥0`. -/ @[pp_nodot] def Rat.nnabs (x : ℚ) : ℚ≥0 := ⟨abs x, abs_nonneg x⟩ @[norm_cast, simp] theorem Rat.coe_nnabs (x : ℚ) : (Rat.nnabs x : ℚ) = abs x := rfl /-! ### Numerator and denominator -/ namespace NNRat variable {p q : ℚ≥0} @[norm_cast] lemma num_coe (q : ℚ≥0) : (q : ℚ).num = q.num := by simp only [num, Int.natCast_natAbs, Rat.num_nonneg, coe_nonneg, abs_of_nonneg] theorem natAbs_num_coe : (q : ℚ).num.natAbs = q.num := rfl @[norm_cast] lemma den_coe : (q : ℚ).den = q.den := rfl @[simp] lemma num_ne_zero : q.num ≠ 0 ↔ q ≠ 0 := by simp [num] @[simp] lemma num_pos : 0 < q.num ↔ 0 < q := by simpa [num, -nonpos_iff_eq_zero] using nonpos_iff_eq_zero _ |>.not.symm @[simp] lemma den_pos (q : ℚ≥0) : 0 < q.den := Rat.den_pos _ @[simp] lemma den_ne_zero (q : ℚ≥0) : q.den ≠ 0 := Rat.den_ne_zero _ lemma coprime_num_den (q : ℚ≥0) : q.num.Coprime q.den := by simpa [num, den] using Rat.reduced _ -- TODO: Rename `Rat.coe_nat_num`, `Rat.intCast_den`, `Rat.ofNat_num`, `Rat.ofNat_den` @[simp, norm_cast] lemma num_natCast (n : ℕ) : num n = n := rfl @[simp, norm_cast] lemma den_natCast (n : ℕ) : den n = 1 := rfl @[simp] lemma num_ofNat (n : ℕ) [n.AtLeastTwo] : num ofNat(n) = OfNat.ofNat n := rfl @[simp] lemma den_ofNat (n : ℕ) [n.AtLeastTwo] : den ofNat(n) = 1 := rfl theorem ext_num_den (hn : p.num = q.num) (hd : p.den = q.den) : p = q := by refine ext <| Rat.ext ?_ hd simpa [num_coe] theorem ext_num_den_iff : p = q ↔ p.num = q.num ∧ p.den = q.den := ⟨by rintro rfl; exact ⟨rfl, rfl⟩, fun h ↦ ext_num_den h.1 h.2⟩ /-- Form the quotient `n / d` where `n d : ℕ`. See also `Rat.divInt` and `mkRat`. -/ def divNat (n d : ℕ) : ℚ≥0 := ⟨.divInt n d, Rat.divInt_nonneg (Int.ofNat_zero_le n) (Int.ofNat_zero_le d)⟩ variable {n₁ n₂ d₁ d₂ : ℕ} @[simp, norm_cast] lemma coe_divNat (n d : ℕ) : (divNat n d : ℚ) = .divInt n d := rfl lemma mk_divInt (n d : ℕ) : ⟨.divInt n d, Rat.divInt_nonneg (Int.ofNat_zero_le n) (Int.ofNat_zero_le d)⟩ = divNat n d := rfl lemma divNat_inj (h₁ : d₁ ≠ 0) (h₂ : d₂ ≠ 0) : divNat n₁ d₁ = divNat n₂ d₂ ↔ n₁ * d₂ = n₂ * d₁ := by rw [← coe_inj]; simp [Rat.mkRat_eq_iff, h₁, h₂]; norm_cast @[simp] lemma divNat_zero (n : ℕ) : divNat n 0 = 0 := by simp [divNat]; rfl @[simp] lemma num_divNat_den (q : ℚ≥0) : divNat q.num q.den = q := ext <| by rw [← (q : ℚ).mkRat_num_den']; simp [num_coe, den_coe] lemma natCast_eq_divNat (n : ℕ) : (n : ℚ≥0) = divNat n 1 := (num_divNat_den _).symm lemma divNat_mul_divNat (n₁ n₂ : ℕ) {d₁ d₂} (hd₁ : d₁ ≠ 0) (hd₂ : d₂ ≠ 0) : divNat n₁ d₁ * divNat n₂ d₂ = divNat (n₁ * n₂) (d₁ * d₂) := by ext; push_cast; exact Rat.divInt_mul_divInt _ _ (mod_cast hd₁) (mod_cast hd₂) lemma divNat_mul_left {a : ℕ} (ha : a ≠ 0) (n d : ℕ) : divNat (a * n) (a * d) = divNat n d := by ext; push_cast; exact Rat.divInt_mul_left (mod_cast ha) lemma divNat_mul_right {a : ℕ} (ha : a ≠ 0) (n d : ℕ) : divNat (n * a) (d * a) = divNat n d := by ext; push_cast; exact Rat.divInt_mul_right (mod_cast ha) @[simp] lemma mul_den_eq_num (q : ℚ≥0) : q * q.den = q.num := by ext push_cast rw [← Int.cast_natCast, ← den_coe, ← Int.cast_natCast q.num, ← num_coe] exact Rat.mul_den_eq_num _ @[simp] lemma den_mul_eq_num (q : ℚ≥0) : q.den * q = q.num := by rw [mul_comm, mul_den_eq_num] /-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with nonnegative rational numbers of the form `n / d` with `d ≠ 0` and `n`, `d` coprime. -/ @[elab_as_elim] def numDenCasesOn.{u} {C : ℚ≥0 → Sort u} (q) (H : ∀ n d, d ≠ 0 → n.Coprime d → C (divNat n d)) : C q := by rw [← q.num_divNat_den]; exact H _ _ q.den_ne_zero q.coprime_num_den lemma add_def (q r : ℚ≥0) : q + r = divNat (q.num * r.den + r.num * q.den) (q.den * r.den) := by ext; simp [Rat.add_def', Rat.mkRat_eq_divInt, num_coe, den_coe] lemma mul_def (q r : ℚ≥0) : q * r = divNat (q.num * r.num) (q.den * r.den) := by ext; simp [Rat.mul_eq_mkRat, Rat.mkRat_eq_divInt, num_coe, den_coe] theorem lt_def {p q : ℚ≥0} : p < q ↔ p.num * q.den < q.num * p.den := by rw [← NNRat.coe_lt_coe, Rat.lt_def]; norm_cast theorem le_def {p q : ℚ≥0} : p ≤ q ↔ p.num * q.den ≤ q.num * p.den := by rw [← NNRat.coe_le_coe, Rat.le_def]; norm_cast end NNRat namespace Mathlib.Tactic.Qify @[qify_simps] lemma nnratCast_eq (a b : ℚ≥0) : a = b ↔ (a : ℚ) = (b : ℚ) := NNRat.coe_inj.symm @[qify_simps] lemma nnratCast_le (a b : ℚ≥0) : a ≤ b ↔ (a : ℚ) ≤ (b : ℚ) := NNRat.coe_le_coe.symm @[qify_simps] lemma nnratCast_lt (a b : ℚ≥0) : a < b ↔ (a : ℚ) < (b : ℚ) := NNRat.coe_lt_coe.symm @[qify_simps] lemma nnratCast_ne (a b : ℚ≥0) : a ≠ b ↔ (a : ℚ) ≠ (b : ℚ) := NNRat.ne_iff.symm end Mathlib.Tactic.Qify
Mathlib/Data/NNRat/Defs.lean
420
421
/- 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.Bool.Basic import Mathlib.Order.Monotone.Basic import Mathlib.Order.ULift import Mathlib.Tactic.GCongr.CoreAttrs /-! # (Semi-)lattices Semilattices are partially ordered sets with join (least upper bound, or `sup`) or meet (greatest lower bound, or `inf`) operations. Lattices are posets that are both join-semilattices and meet-semilattices. Distributive lattices are lattices which satisfy any of four equivalent distributivity properties, of `sup` over `inf`, on the left or on the right. ## Main declarations * `SemilatticeSup`: a type class for join semilattices * `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `⊔` is commutative, associative and idempotent. * `SemilatticeInf`: a type class for meet semilattices * `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `⊓` is commutative, associative and idempotent. * `Lattice`: a type class for lattices * `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `⊔` and `⊓` are commutative, associative and satisfy a pair of "absorption laws". * `DistribLattice`: a type class for distributive lattices. ## Notations * `a ⊔ b`: the supremum or join of `a` and `b` * `a ⊓ b`: the infimum or meet of `a` and `b` ## TODO * (Semi-)lattice homomorphisms * Alternative constructors for distributive lattices from the other distributive properties ## Tags semilattice, lattice -/ /-- See if the term is `a ⊂ b` and the goal is `a ⊆ b`. -/ @[gcongr_forward] def exactSubsetOfSSubset : Mathlib.Tactic.GCongr.ForwardExt where eval h goal := do goal.assignIfDefEq (← Lean.Meta.mkAppM ``subset_of_ssubset #[h]) universe u v w variable {α : Type u} {β : Type v} /-! ### Join-semilattices -/ -- TODO: automatic construction of dual definitions / theorems /-- A `SemilatticeSup` is a join-semilattice, that is, a partial order with a join (a.k.a. lub / least upper bound, sup / supremum) operation `⊔` which is the least element larger than both factors. -/ class SemilatticeSup (α : Type u) extends PartialOrder α where /-- The binary supremum, used to derive `Max α` -/ sup : α → α → α /-- The supremum is an upper bound on the first argument -/ protected le_sup_left : ∀ a b : α, a ≤ sup a b /-- The supremum is an upper bound on the second argument -/ protected le_sup_right : ∀ a b : α, b ≤ sup a b /-- The supremum is the *least* upper bound -/ protected sup_le : ∀ a b c : α, a ≤ c → b ≤ c → sup a b ≤ c instance SemilatticeSup.toMax [SemilatticeSup α] : Max α where max a b := SemilatticeSup.sup a b /-- A type with a commutative, associative and idempotent binary `sup` operation has the structure of a join-semilattice. The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`. -/ def SemilatticeSup.mk' {α : Type*} [Max α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a) (sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ a : α, a ⊔ a = a) : SemilatticeSup α where sup := (· ⊔ ·) le a b := a ⊔ b = b le_refl := sup_idem le_trans a b c hab hbc := by rw [← hbc, ← sup_assoc, hab] le_antisymm a b hab hba := by rwa [← hba, sup_comm] le_sup_left a b := by rw [← sup_assoc, sup_idem] le_sup_right a b := by rw [sup_comm, sup_assoc, sup_idem] sup_le a b c hac hbc := by rwa [sup_assoc, hbc] section SemilatticeSup variable [SemilatticeSup α] {a b c d : α} @[simp] theorem le_sup_left : a ≤ a ⊔ b := SemilatticeSup.le_sup_left a b @[simp] theorem le_sup_right : b ≤ a ⊔ b := SemilatticeSup.le_sup_right a b theorem le_sup_of_le_left (h : c ≤ a) : c ≤ a ⊔ b := le_trans h le_sup_left theorem le_sup_of_le_right (h : c ≤ b) : c ≤ a ⊔ b := le_trans h le_sup_right theorem lt_sup_of_lt_left (h : c < a) : c < a ⊔ b := h.trans_le le_sup_left theorem lt_sup_of_lt_right (h : c < b) : c < a ⊔ b := h.trans_le le_sup_right theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c := SemilatticeSup.sup_le a b c @[simp] theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c := ⟨fun h : a ⊔ b ≤ c => ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩, fun ⟨h₁, h₂⟩ => sup_le h₁ h₂⟩ @[simp] theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a := le_antisymm_iff.trans <| by simp [le_rfl] @[simp] theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b := le_antisymm_iff.trans <| by simp [le_rfl] @[simp] theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a := eq_comm.trans sup_eq_left @[simp] theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b := eq_comm.trans sup_eq_right alias ⟨_, sup_of_le_left⟩ := sup_eq_left alias ⟨le_of_sup_eq, sup_of_le_right⟩ := sup_eq_right attribute [simp] sup_of_le_left sup_of_le_right @[simp] theorem left_lt_sup : a < a ⊔ b ↔ ¬b ≤ a := le_sup_left.lt_iff_ne.trans <| not_congr left_eq_sup @[simp] theorem right_lt_sup : b < a ⊔ b ↔ ¬a ≤ b := le_sup_right.lt_iff_ne.trans <| not_congr right_eq_sup
theorem left_or_right_lt_sup (h : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b :=
Mathlib/Order/Lattice.lean
159
160
/- Copyright (c) 2023 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.NormedSpace.HahnBanach.Extension import Mathlib.Analysis.NormedSpace.HahnBanach.Separation import Mathlib.Analysis.NormedSpace.Multilinear.Basic import Mathlib.Analysis.NormedSpace.OperatorNorm.Completeness import Mathlib.LinearAlgebra.Dual.Lemmas /-! # Spaces with separating dual We introduce a typeclass `SeparatingDual R V`, registering that the points of the topological module `V` over `R` can be separated by continuous linear forms. This property is satisfied for normed spaces over `ℝ` or `ℂ` (by the analytic Hahn-Banach theorem) and for locally convex topological spaces over `ℝ` (by the geometric Hahn-Banach theorem). Under the assumption `SeparatingDual R V`, we show in `SeparatingDual.exists_continuousLinearMap_apply_eq` that the group of continuous linear equivalences acts transitively on the set of nonzero vectors. -/ /-- When `E` is a topological module over a topological ring `R`, the class `SeparatingDual R E` registers that continuous linear forms on `E` separate points of `E`. -/ @[mk_iff separatingDual_def] class SeparatingDual (R V : Type*) [Ring R] [AddCommGroup V] [TopologicalSpace V] [TopologicalSpace R] [Module R V] : Prop where /-- Any nonzero vector can be mapped by a continuous linear map to a nonzero scalar. -/ exists_ne_zero' : ∀ (x : V), x ≠ 0 → ∃ f : V →L[R] R, f x ≠ 0 instance {E : Type*} [TopologicalSpace E] [AddCommGroup E] [IsTopologicalAddGroup E] [Module ℝ E] [ContinuousSMul ℝ E] [LocallyConvexSpace ℝ E] [T1Space E] : SeparatingDual ℝ E := ⟨fun x hx ↦ by rcases geometric_hahn_banach_point_point hx.symm with ⟨f, hf⟩ simp only [map_zero] at hf exact ⟨f, hf.ne'⟩⟩ instance {E 𝕜 : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] : SeparatingDual 𝕜 E := ⟨fun x hx ↦ by rcases exists_dual_vector 𝕜 x hx with ⟨f, -, hf⟩ refine ⟨f, ?_⟩ simpa [hf] using hx⟩ namespace SeparatingDual section Ring variable {R V : Type*} [Ring R] [AddCommGroup V] [TopologicalSpace V] [TopologicalSpace R] [Module R V] [SeparatingDual R V] lemma exists_ne_zero {x : V} (hx : x ≠ 0) : ∃ f : V →L[R] R, f x ≠ 0 := exists_ne_zero' x hx theorem exists_separating_of_ne {x y : V} (h : x ≠ y) : ∃ f : V →L[R] R, f x ≠ f y := by rcases exists_ne_zero (R := R) (sub_ne_zero_of_ne h) with ⟨f, hf⟩ exact ⟨f, by simpa [sub_ne_zero] using hf⟩ protected theorem t1Space [T1Space R] : T1Space V := by apply t1Space_iff_exists_open.2 (fun x y hxy ↦ ?_) rcases exists_separating_of_ne (R := R) hxy with ⟨f, hf⟩ exact ⟨f ⁻¹' {f y}ᶜ, isOpen_compl_singleton.preimage f.continuous, hf, by simp⟩ protected theorem t2Space [T2Space R] : T2Space V := by apply (t2Space_iff _).2 (fun {x} {y} hxy ↦ ?_) rcases exists_separating_of_ne (R := R) hxy with ⟨f, hf⟩ exact separated_by_continuous f.continuous hf end Ring section Field variable {R V : Type*} [Field R] [AddCommGroup V] [TopologicalSpace R] [TopologicalSpace V] [IsTopologicalRing R] [Module R V] -- TODO (@alreadydone): this could generalize to CommRing R if we were to add a section theorem _root_.separatingDual_iff_injective : SeparatingDual R V ↔ Function.Injective (ContinuousLinearMap.coeLM (R := R) R (M := V) (N₃ := R)).flip := by simp_rw [separatingDual_def, Ne, injective_iff_map_eq_zero] congrm ∀ v, ?_ rw [not_imp_comm, LinearMap.ext_iff] push_neg; rfl variable [SeparatingDual R V] open Function in /-- Given a finite-dimensional subspace `W` of a space `V` with separating dual, any linear functional on `W` extends to a continuous linear functional on `V`. This is stated more generally for an injective linear map from `W` to `V`. -/ theorem dualMap_surjective_iff {W} [AddCommGroup W] [Module R W] [FiniteDimensional R W] {f : W →ₗ[R] V} : Surjective (f.dualMap ∘ ContinuousLinearMap.toLinearMap) ↔ Injective f := by constructor <;> intro hf · exact LinearMap.dualMap_surjective_iff.mp hf.of_comp have := (separatingDual_iff_injective.mp ‹_›).comp hf rw [← LinearMap.coe_comp] at this exact LinearMap.flip_surjective_iff₁.mpr this lemma exists_eq_one {x : V} (hx : x ≠ 0) : ∃ f : V →L[R] R, f x = 1 := by rcases exists_ne_zero (R := R) hx with ⟨f, hf⟩ exact ⟨(f x)⁻¹ • f, inv_mul_cancel₀ hf⟩ theorem exists_eq_one_ne_zero_of_ne_zero_pair {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : ∃ f : V →L[R] R, f x = 1 ∧ f y ≠ 0 := by obtain ⟨u, ux⟩ : ∃ u : V →L[R] R, u x = 1 := exists_eq_one hx rcases ne_or_eq (u y) 0 with uy|uy · exact ⟨u, ux, uy⟩ obtain ⟨v, vy⟩ : ∃ v : V →L[R] R, v y = 1 := exists_eq_one hy rcases ne_or_eq (v x) 0 with vx|vx · exact ⟨(v x)⁻¹ • v, inv_mul_cancel₀ vx, show (v x)⁻¹ * v y ≠ 0 by simp [vx, vy]⟩ · exact ⟨u + v, by simp [ux, vx], by simp [uy, vy]⟩ variable [IsTopologicalAddGroup V] /-- In a topological vector space with separating dual, the group of continuous linear equivalences acts transitively on the set of nonzero vectors: given two nonzero vectors `x` and `y`, there exists `A : V ≃L[R] V` mapping `x` to `y`. -/ theorem exists_continuousLinearEquiv_apply_eq [ContinuousSMul R V] {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : ∃ A : V ≃L[R] V, A x = y := by obtain ⟨G, Gx, Gy⟩ : ∃ G : V →L[R] R, G x = 1 ∧ G y ≠ 0 := exists_eq_one_ne_zero_of_ne_zero_pair hx hy let A : V ≃L[R] V := { toFun := fun z ↦ z + G z • (y - x) invFun := fun z ↦ z + ((G y) ⁻¹ * G z) • (x - y) map_add' := fun a b ↦ by simp [add_smul]; abel map_smul' := by simp [smul_smul] left_inv := fun z ↦ by simp only [id_eq, eq_mpr_eq_cast, RingHom.id_apply, smul_eq_mul, AddHom.toFun_eq_coe, -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to change `map_smulₛₗ` into `map_smulₛₗ _` AddHom.coe_mk, map_add, map_smulₛₗ _, map_sub, Gx, mul_sub, mul_one, add_sub_cancel] rw [mul_comm (G z), ← mul_assoc, inv_mul_cancel₀ Gy] simp only [smul_sub, one_mul] abel right_inv := fun z ↦ by -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to change `map_smulₛₗ` into `map_smulₛₗ _` simp only [map_add, map_smulₛₗ _, map_mul, map_inv₀, RingHom.id_apply, map_sub, Gx, smul_eq_mul, mul_sub, mul_one] rw [mul_comm _ (G y), ← mul_assoc, mul_inv_cancel₀ Gy] simp only [smul_sub, one_mul, add_sub_cancel] abel continuous_toFun := continuous_id.add (G.continuous.smul continuous_const) continuous_invFun := continuous_id.add ((continuous_const.mul G.continuous).smul continuous_const) } exact ⟨A, show x + G x • (y - x) = y by simp [Gx]⟩ open Filter open scoped Topology section variable (𝕜 E F : Type*) [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [SeparatingDual 𝕜 E] [Nontrivial E] /-- If a space of linear maps from `E` to `F` is complete, and `E` is nontrivial, then `F` is complete. -/ lemma completeSpace_of_completeSpace_continuousLinearMap [CompleteSpace (E →L[𝕜] F)] : CompleteSpace F := by refine Metric.complete_of_cauchySeq_tendsto fun f hf => ?_ obtain ⟨v, hv⟩ : ∃ (v : E), v ≠ 0 := exists_ne 0 obtain ⟨φ, hφ⟩ : ∃ φ : E →L[𝕜] 𝕜, φ v = 1 := exists_eq_one hv let g : ℕ → (E →L[𝕜] F) := fun n ↦ ContinuousLinearMap.smulRightL 𝕜 E F φ (f n) have : CauchySeq g := (ContinuousLinearMap.smulRightL 𝕜 E F φ).lipschitz.cauchySeq_comp hf obtain ⟨a, ha⟩ : ∃ a, Tendsto g atTop (𝓝 a) := cauchy_iff_exists_le_nhds.mp this refine ⟨a v, ?_⟩ have : Tendsto (fun n ↦ g n v) atTop (𝓝 (a v)) := by have : Continuous (fun (i : E →L[𝕜] F) ↦ i v) := by fun_prop exact (this.tendsto _).comp ha simpa [g, ContinuousLinearMap.smulRightL, hφ] lemma completeSpace_continuousLinearMap_iff : CompleteSpace (E →L[𝕜] F) ↔ CompleteSpace F := ⟨fun _h ↦ completeSpace_of_completeSpace_continuousLinearMap 𝕜 E F, fun _h ↦ inferInstance⟩
open ContinuousMultilinearMap variable {ι : Type*} [Finite ι] {M : ι → Type*} [∀ i, NormedAddCommGroup (M i)] [∀ i, NormedSpace 𝕜 (M i)] [∀ i, SeparatingDual 𝕜 (M i)] /-- If a space of multilinear maps from `Π i, E i` to `F` is complete, and each `E i` has a nonzero element, then `F` is complete. -/ lemma completeSpace_of_completeSpace_continuousMultilinearMap [CompleteSpace (ContinuousMultilinearMap 𝕜 M F)] {m : ∀ i, M i} (hm : ∀ i, m i ≠ 0) : CompleteSpace F := by refine Metric.complete_of_cauchySeq_tendsto fun f hf => ?_ have : ∀ i, ∃ φ : M i →L[𝕜] 𝕜, φ (m i) = 1 := fun i ↦ exists_eq_one (hm i) choose φ hφ using this cases nonempty_fintype ι let g : ℕ → (ContinuousMultilinearMap 𝕜 M F) := fun n ↦ compContinuousLinearMapL φ (ContinuousMultilinearMap.smulRightL 𝕜 _ F ((ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι 𝕜)) (f n)) have : CauchySeq g := by
Mathlib/Analysis/NormedSpace/HahnBanach/SeparatingDual.lean
178
195
/- Copyright (c) 2023 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth, Floris van Doorn -/ import Mathlib.Geometry.Manifold.Algebra.LieGroup import Mathlib.Geometry.Manifold.MFDeriv.Basic import Mathlib.Topology.ContinuousMap.Basic import Mathlib.Geometry.Manifold.VectorBundle.Basic /-! # `C^n` sections In this file we define the type `ContMDiffSection` of `n` times continuously differentiable sections of a vector bundle over a manifold `M` and prove that it's a module. -/ open Bundle Filter Function open scoped Bundle Manifold ContDiff variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M : Type*} [TopologicalSpace M] [ChartedSpace H M] variable (F : Type*) [NormedAddCommGroup F] [NormedSpace 𝕜 F] -- `F` model fiber (n : WithTop ℕ∞) (V : M → Type*) [TopologicalSpace (TotalSpace F V)] -- `V` vector bundle [∀ x : M, TopologicalSpace (V x)] [FiberBundle F V] /-- Bundled `n` times continuously differentiable sections of a vector bundle. Denoted as `Cₛ^n⟮I; F, V⟯` within the `Manifold` namespace. -/ structure ContMDiffSection where /-- the underlying function of this section -/ protected toFun : ∀ x, V x /-- proof that this section is `C^n` -/ protected contMDiff_toFun : ContMDiff I (I.prod 𝓘(𝕜, F)) n fun x ↦ TotalSpace.mk' F x (toFun x) @[deprecated (since := "2024-11-21")] alias SmoothSection := ContMDiffSection @[inherit_doc] scoped[Manifold] notation "Cₛ^" n "⟮" I "; " F ", " V "⟯" => ContMDiffSection I F n V namespace ContMDiffSection variable {I} {n} {F} {V} instance : DFunLike Cₛ^n⟮I; F, V⟯ M V where coe := ContMDiffSection.toFun coe_injective' := by rintro ⟨⟩ ⟨⟩ h; congr variable {s t : Cₛ^n⟮I; F, V⟯} @[simp] theorem coeFn_mk (s : ∀ x, V x) (hs : ContMDiff I (I.prod 𝓘(𝕜, F)) n fun x => TotalSpace.mk x (s x)) : (mk s hs : ∀ x, V x) = s := rfl protected theorem contMDiff (s : Cₛ^n⟮I; F, V⟯) : ContMDiff I (I.prod 𝓘(𝕜, F)) n fun x => TotalSpace.mk' F x (s x : V x) := s.contMDiff_toFun @[deprecated (since := "2024-11-21")] alias smooth := ContMDiffSection.contMDiff theorem coe_inj ⦃s t : Cₛ^n⟮I; F, V⟯⦄ (h : (s : ∀ x, V x) = t) : s = t := DFunLike.ext' h theorem coe_injective : Injective ((↑) : Cₛ^n⟮I; F, V⟯ → ∀ x, V x) := coe_inj @[ext] theorem ext (h : ∀ x, s x = t x) : s = t := DFunLike.ext _ _ h section variable [∀ x, AddCommGroup (V x)] [∀ x, Module 𝕜 (V x)] [VectorBundle 𝕜 F V] instance instAdd : Add Cₛ^n⟮I; F, V⟯ := by refine ⟨fun s t => ⟨s + t, ?_⟩⟩ intro x₀ have hs := s.contMDiff x₀ have ht := t.contMDiff x₀ rw [contMDiffAt_section] at hs ht ⊢ set e := trivializationAt F V x₀ refine (hs.add ht).congr_of_eventuallyEq ?_ refine eventually_of_mem (e.open_baseSet.mem_nhds <| mem_baseSet_trivializationAt F V x₀) ?_ intro x hx apply (e.linear 𝕜 hx).1 @[simp] theorem coe_add (s t : Cₛ^n⟮I; F, V⟯) : ⇑(s + t) = ⇑s + t := rfl instance instSub : Sub Cₛ^n⟮I; F, V⟯ := by refine ⟨fun s t => ⟨s - t, ?_⟩⟩ intro x₀ have hs := s.contMDiff x₀ have ht := t.contMDiff x₀ rw [contMDiffAt_section] at hs ht ⊢ set e := trivializationAt F V x₀ refine (hs.sub ht).congr_of_eventuallyEq ?_ refine eventually_of_mem (e.open_baseSet.mem_nhds <| mem_baseSet_trivializationAt F V x₀) ?_ intro x hx apply (e.linear 𝕜 hx).map_sub @[simp] theorem coe_sub (s t : Cₛ^n⟮I; F, V⟯) : ⇑(s - t) = s - t := rfl instance instZero : Zero Cₛ^n⟮I; F, V⟯ := ⟨⟨fun _ => 0, (contMDiff_zeroSection 𝕜 V).of_le le_top⟩⟩ instance inhabited : Inhabited Cₛ^n⟮I; F, V⟯ := ⟨0⟩ @[simp] theorem coe_zero : ⇑(0 : Cₛ^n⟮I; F, V⟯) = 0 := rfl instance instNeg : Neg Cₛ^n⟮I; F, V⟯ := by refine ⟨fun s => ⟨-s, ?_⟩⟩ intro x₀ have hs := s.contMDiff x₀ rw [contMDiffAt_section] at hs ⊢ set e := trivializationAt F V x₀ refine hs.neg.congr_of_eventuallyEq ?_ refine eventually_of_mem (e.open_baseSet.mem_nhds <| mem_baseSet_trivializationAt F V x₀) ?_ intro x hx apply (e.linear 𝕜 hx).map_neg @[simp] theorem coe_neg (s : Cₛ^n⟮I; F, V⟯) : ⇑(-s : Cₛ^n⟮I; F, V⟯) = -s := rfl instance instNSMul : SMul ℕ Cₛ^n⟮I; F, V⟯ := ⟨nsmulRec⟩ @[simp] theorem coe_nsmul (s : Cₛ^n⟮I; F, V⟯) (k : ℕ) : ⇑(k • s : Cₛ^n⟮I; F, V⟯) = k • ⇑s := by induction' k with k ih · simp_rw [zero_smul]; rfl simp_rw [succ_nsmul, ← ih]; rfl instance instZSMul : SMul ℤ Cₛ^n⟮I; F, V⟯ := ⟨zsmulRec⟩ @[simp] theorem coe_zsmul (s : Cₛ^n⟮I; F, V⟯) (z : ℤ) : ⇑(z • s : Cₛ^n⟮I; F, V⟯) = z • ⇑s := by rcases z with n | n · refine (coe_nsmul s n).trans ?_ simp only [Int.ofNat_eq_coe, natCast_zsmul] · refine (congr_arg Neg.neg (coe_nsmul s (n + 1))).trans ?_ simp only [negSucc_zsmul, neg_inj] instance instAddCommGroup : AddCommGroup Cₛ^n⟮I; F, V⟯ := coe_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub coe_nsmul coe_zsmul instance instSMul : SMul 𝕜 Cₛ^n⟮I; F, V⟯ := by refine ⟨fun c s => ⟨c • ⇑s, ?_⟩⟩ intro x₀ have hs := s.contMDiff x₀ rw [contMDiffAt_section] at hs ⊢ set e := trivializationAt F V x₀ refine ((contMDiffAt_const (c := c)).smul hs).congr_of_eventuallyEq ?_ refine eventually_of_mem (e.open_baseSet.mem_nhds <| mem_baseSet_trivializationAt F V x₀) ?_ intro x hx apply (e.linear 𝕜 hx).2 @[simp] theorem coe_smul (r : 𝕜) (s : Cₛ^n⟮I; F, V⟯) : ⇑(r • s : Cₛ^n⟮I; F, V⟯) = r • ⇑s := rfl variable (I F V n) in /-- The additive morphism from `C^n` sections to dependent maps. -/ def coeAddHom : Cₛ^n⟮I; F, V⟯ →+ ∀ x, V x where toFun := (↑) map_zero' := coe_zero map_add' := coe_add @[simp] theorem coeAddHom_apply (s : Cₛ^n⟮I; F, V⟯) : coeAddHom I F n V s = s := rfl instance instModule : Module 𝕜 Cₛ^n⟮I; F, V⟯ := coe_injective.module 𝕜 (coeAddHom I F n V) coe_smul end protected theorem mdifferentiable' (s : Cₛ^n⟮I; F, V⟯) (hn : 1 ≤ n) : MDifferentiable I (I.prod 𝓘(𝕜, F)) fun x => TotalSpace.mk' F x (s x : V x) := s.contMDiff.mdifferentiable hn protected theorem mdifferentiable (s : Cₛ^∞⟮I; F, V⟯) : MDifferentiable I (I.prod 𝓘(𝕜, F)) fun x => TotalSpace.mk' F x (s x : V x) := s.contMDiff.mdifferentiable (mod_cast le_top) protected theorem mdifferentiableAt (s : Cₛ^∞⟮I; F, V⟯) {x} : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x => TotalSpace.mk' F x (s x : V x)) x :=
s.mdifferentiable x end ContMDiffSection
Mathlib/Geometry/Manifold/VectorBundle/SmoothSection.lean
201
204
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Analysis.InnerProductSpace.Projection import Mathlib.MeasureTheory.Function.ConditionalExpectation.Unique import Mathlib.MeasureTheory.Function.L2Space /-! # Conditional expectation in L2 This file contains one step of the construction of the conditional expectation, which is completed in `MeasureTheory.Function.ConditionalExpectation.Basic`. See that file for a description of the full process. We build the conditional expectation of an `L²` function, as an element of `L²`. This is the orthogonal projection on the subspace of almost everywhere `m`-measurable functions. ## Main definitions * `condExpL2`: Conditional expectation of a function in L2 with respect to a sigma-algebra: it is the orthogonal projection on the subspace `lpMeas`. ## Implementation notes Most of the results in this file are valid for a complete real normed space `F`. However, some lemmas also use `𝕜 : RCLike`: * `condExpL2` is defined only for an `InnerProductSpace` for now, and we use `𝕜` for its field. * results about scalar multiplication are stated not only for `ℝ` but also for `𝕜` if we happen to have `NormedSpace 𝕜 F`. -/ open TopologicalSpace Filter ContinuousLinearMap open scoped ENNReal Topology MeasureTheory namespace MeasureTheory variable {α E E' F G G' 𝕜 : Type*} [RCLike 𝕜] -- 𝕜 for ℝ or ℂ -- E for an inner product space [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [CompleteSpace E] -- E' for an inner product space on which we compute integrals [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] [CompleteSpace E'] [NormedSpace ℝ E'] -- F for a Lp submodule [NormedAddCommGroup F] [NormedSpace 𝕜 F] -- G for a Lp add_subgroup [NormedAddCommGroup G] -- G' for integrals on a Lp add_subgroup [NormedAddCommGroup G'] [NormedSpace ℝ G'] [CompleteSpace G'] variable {m m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α} local notation "⟪" x ", " y "⟫" => @inner 𝕜 E _ x y local notation "⟪" x ", " y "⟫₂" => @inner 𝕜 (α →₂[μ] E) _ x y variable (E 𝕜) /-- Conditional expectation of a function in L2 with respect to a sigma-algebra -/ noncomputable def condExpL2 (hm : m ≤ m0) : (α →₂[μ] E) →L[𝕜] lpMeas E 𝕜 m 2 μ := haveI : Fact (m ≤ m0) := ⟨hm⟩ (lpMeas E 𝕜 m 2 μ).orthogonalProjection @[deprecated (since := "2025-01-21")] alias condexpL2 := condExpL2 variable {E 𝕜} theorem aestronglyMeasurable_condExpL2 (hm : m ≤ m0) (f : α →₂[μ] E) : AEStronglyMeasurable[m] (condExpL2 E 𝕜 hm f : α → E) μ := lpMeas.aestronglyMeasurable _ @[deprecated (since := "2025-01-24")] alias aeStronglyMeasurable'_condExpL2 := aestronglyMeasurable_condExpL2 @[deprecated (since := "2025-01-24")] alias aeStronglyMeasurable'_condexpL2 := aestronglyMeasurable_condExpL2 theorem integrableOn_condExpL2_of_measure_ne_top (hm : m ≤ m0) (hμs : μ s ≠ ∞) (f : α →₂[μ] E) : IntegrableOn (ε := E) (condExpL2 E 𝕜 hm f) s μ := integrableOn_Lp_of_measure_ne_top (condExpL2 E 𝕜 hm f : α →₂[μ] E) fact_one_le_two_ennreal.elim hμs @[deprecated (since := "2025-01-21")] alias integrableOn_condexpL2_of_measure_ne_top := integrableOn_condExpL2_of_measure_ne_top theorem integrable_condExpL2_of_isFiniteMeasure (hm : m ≤ m0) [IsFiniteMeasure μ] {f : α →₂[μ] E} : Integrable (ε := E) (condExpL2 E 𝕜 hm f) μ := integrableOn_univ.mp <| integrableOn_condExpL2_of_measure_ne_top hm (measure_ne_top _ _) f @[deprecated (since := "2025-01-21")] alias integrable_condexpL2_of_isFiniteMeasure := integrable_condExpL2_of_isFiniteMeasure theorem norm_condExpL2_le_one (hm : m ≤ m0) : ‖@condExpL2 α E 𝕜 _ _ _ _ _ _ μ hm‖ ≤ 1 := haveI : Fact (m ≤ m0) := ⟨hm⟩ Submodule.orthogonalProjection_norm_le _ @[deprecated (since := "2025-01-21")] alias norm_condexpL2_le_one := norm_condExpL2_le_one
theorem norm_condExpL2_le (hm : m ≤ m0) (f : α →₂[μ] E) : ‖condExpL2 E 𝕜 hm f‖ ≤ ‖f‖ := ((@condExpL2 _ E 𝕜 _ _ _ _ _ _ μ hm).le_opNorm f).trans (mul_le_of_le_one_left (norm_nonneg _) (norm_condExpL2_le_one hm)) @[deprecated (since := "2025-01-21")] alias norm_condexpL2_le := norm_condExpL2_le
Mathlib/MeasureTheory/Function/ConditionalExpectation/CondexpL2.lean
106
110
/- Copyright (c) 2019 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard -/ import Mathlib.Data.EReal.Basic deprecated_module (since := "2025-04-13")
Mathlib/Data/Real/EReal.lean
1,248
1,281
/- 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.Order.Filter.SmallSets import Mathlib.Topology.UniformSpace.Defs import Mathlib.Topology.ContinuousOn /-! # Basic results on uniform spaces Uniform spaces are a generalization of metric spaces and topological groups. ## Main definitions In this file we define a complete lattice structure on the type `UniformSpace X` of uniform structures on `X`, as well as the pullback (`UniformSpace.comap`) of uniform structures coming from the pullback of filters. Like distance functions, uniform structures cannot be pushed forward in general. ## Notations Localized in `Uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`, and `○` for composition of relations, seen as terms with type `Set (X × X)`. ## References The formalization uses the books: * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] But it makes a more systematic use of the filter library. -/ open Set Filter Topology universe u v ua ub uc ud /-! ### Relations, seen as `Set (α × α)` -/ variable {α : Type ua} {β : Type ub} {γ : Type uc} {δ : Type ud} {ι : Sort*} open Uniformity section UniformSpace variable [UniformSpace α] /-- If `s ∈ 𝓤 α`, then for any natural `n`, for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ○ ... ○ t ⊆ s` (`n` compositions). -/ theorem eventually_uniformity_iterate_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) (n : ℕ) : ∀ᶠ t in (𝓤 α).smallSets, (t ○ ·)^[n] t ⊆ s := by suffices ∀ᶠ t in (𝓤 α).smallSets, t ⊆ s ∧ (t ○ ·)^[n] t ⊆ s from (eventually_and.1 this).2 induction n generalizing s with | zero => simpa | succ _ ihn => rcases comp_mem_uniformity_sets hs with ⟨t, htU, hts⟩ refine (ihn htU).mono fun U hU => ?_ rw [Function.iterate_succ_apply'] exact ⟨hU.1.trans <| (subset_comp_self <| refl_le_uniformity htU).trans hts, (compRel_mono hU.1 hU.2).trans hts⟩ /-- If `s ∈ 𝓤 α`, then for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ⊆ s`. -/ theorem eventually_uniformity_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∀ᶠ t in (𝓤 α).smallSets, t ○ t ⊆ s := eventually_uniformity_iterate_comp_subset hs 1 /-! ### Balls in uniform spaces -/ namespace UniformSpace open UniformSpace (ball) lemma isOpen_ball (x : α) {V : Set (α × α)} (hV : IsOpen V) : IsOpen (ball x V) := hV.preimage <| .prodMk_right _ lemma isClosed_ball (x : α) {V : Set (α × α)} (hV : IsClosed V) : IsClosed (ball x V) := hV.preimage <| .prodMk_right _ /-! ### Neighborhoods in uniform spaces -/ theorem hasBasis_nhds_prod (x y : α) : HasBasis (𝓝 (x, y)) (fun s => s ∈ 𝓤 α ∧ IsSymmetricRel s) fun s => ball x s ×ˢ ball y s := by rw [nhds_prod_eq] apply (hasBasis_nhds x).prod_same_index (hasBasis_nhds y) rintro U V ⟨U_in, U_symm⟩ ⟨V_in, V_symm⟩ exact ⟨U ∩ V, ⟨(𝓤 α).inter_sets U_in V_in, U_symm.inter V_symm⟩, ball_inter_left x U V, ball_inter_right y U V⟩ end UniformSpace open UniformSpace theorem nhds_eq_uniformity_prod {a b : α} : 𝓝 (a, b) = (𝓤 α).lift' fun s : Set (α × α) => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ s } := by rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'] · exact fun s => monotone_const.set_prod monotone_preimage · refine fun t => Monotone.set_prod ?_ monotone_const exact monotone_preimage (f := fun y => (y, a)) theorem nhdset_of_mem_uniformity {d : Set (α × α)} (s : Set (α × α)) (hd : d ∈ 𝓤 α) : ∃ t : Set (α × α), IsOpen t ∧ s ⊆ t ∧ t ⊆ { p | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } := by let cl_d := { p : α × α | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } have : ∀ p ∈ s, ∃ t, t ⊆ cl_d ∧ IsOpen t ∧ p ∈ t := fun ⟨x, y⟩ hp => mem_nhds_iff.mp <| show cl_d ∈ 𝓝 (x, y) by rw [nhds_eq_uniformity_prod, mem_lift'_sets] · exact ⟨d, hd, fun ⟨a, b⟩ ⟨ha, hb⟩ => ⟨x, y, ha, hp, hb⟩⟩ · exact fun _ _ h _ h' => ⟨h h'.1, h h'.2⟩ choose t ht using this exact ⟨(⋃ p : α × α, ⋃ h : p ∈ s, t p h : Set (α × α)), isOpen_iUnion fun p : α × α => isOpen_iUnion fun hp => (ht p hp).right.left, fun ⟨a, b⟩ hp => by simp only [mem_iUnion, Prod.exists]; exact ⟨a, b, hp, (ht (a, b) hp).right.right⟩, iUnion_subset fun p => iUnion_subset fun hp => (ht p hp).left⟩ /-- Entourages are neighborhoods of the diagonal. -/ theorem nhds_le_uniformity (x : α) : 𝓝 (x, x) ≤ 𝓤 α := by intro V V_in rcases comp_symm_mem_uniformity_sets V_in with ⟨w, w_in, w_symm, w_sub⟩ have : ball x w ×ˢ ball x w ∈ 𝓝 (x, x) := by rw [nhds_prod_eq] exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in) apply mem_of_superset this rintro ⟨u, v⟩ ⟨u_in, v_in⟩ exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in) /-- Entourages are neighborhoods of the diagonal. -/ theorem iSup_nhds_le_uniformity : ⨆ x : α, 𝓝 (x, x) ≤ 𝓤 α := iSup_le nhds_le_uniformity /-- Entourages are neighborhoods of the diagonal. -/ theorem nhdsSet_diagonal_le_uniformity : 𝓝ˢ (diagonal α) ≤ 𝓤 α := (nhdsSet_diagonal α).trans_le iSup_nhds_le_uniformity section variable (α) theorem UniformSpace.has_seq_basis [IsCountablyGenerated <| 𝓤 α] : ∃ V : ℕ → Set (α × α), HasAntitoneBasis (𝓤 α) V ∧ ∀ n, IsSymmetricRel (V n) := let ⟨U, hsym, hbasis⟩ := (@UniformSpace.hasBasis_symmetric α _).exists_antitone_subbasis ⟨U, hbasis, fun n => (hsym n).2⟩ end /-! ### Closure and interior in uniform spaces -/ theorem closure_eq_uniformity (s : Set <| α × α) : closure s = ⋂ V ∈ { V | V ∈ 𝓤 α ∧ IsSymmetricRel V }, V ○ s ○ V := by ext ⟨x, y⟩ simp +contextual only [mem_closure_iff_nhds_basis (UniformSpace.hasBasis_nhds_prod x y), mem_iInter, mem_setOf_eq, and_imp, mem_comp_comp, exists_prop, ← mem_inter_iff, inter_comm, Set.Nonempty] theorem uniformity_hasBasis_closed : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsClosed V) id := by refine Filter.hasBasis_self.2 fun t h => ?_ rcases comp_comp_symm_mem_uniformity_sets h with ⟨w, w_in, w_symm, r⟩ refine ⟨closure w, mem_of_superset w_in subset_closure, isClosed_closure, ?_⟩ refine Subset.trans ?_ r rw [closure_eq_uniformity] apply iInter_subset_of_subset apply iInter_subset exact ⟨w_in, w_symm⟩ theorem uniformity_eq_uniformity_closure : 𝓤 α = (𝓤 α).lift' closure := Eq.symm <| uniformity_hasBasis_closed.lift'_closure_eq_self fun _ => And.right theorem Filter.HasBasis.uniformity_closure {p : ι → Prop} {U : ι → Set (α × α)} (h : (𝓤 α).HasBasis p U) : (𝓤 α).HasBasis p fun i => closure (U i) := (@uniformity_eq_uniformity_closure α _).symm ▸ h.lift'_closure /-- Closed entourages form a basis of the uniformity filter. -/ theorem uniformity_hasBasis_closure : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α) closure := (𝓤 α).basis_sets.uniformity_closure theorem closure_eq_inter_uniformity {t : Set (α × α)} : closure t = ⋂ d ∈ 𝓤 α, d ○ (t ○ d) := calc closure t = ⋂ (V) (_ : V ∈ 𝓤 α ∧ IsSymmetricRel V), V ○ t ○ V := closure_eq_uniformity t _ = ⋂ V ∈ 𝓤 α, V ○ t ○ V := Eq.symm <| UniformSpace.hasBasis_symmetric.biInter_mem fun _ _ hV => compRel_mono (compRel_mono hV Subset.rfl) hV _ = ⋂ V ∈ 𝓤 α, V ○ (t ○ V) := by simp only [compRel_assoc] theorem uniformity_eq_uniformity_interior : 𝓤 α = (𝓤 α).lift' interior := le_antisymm (le_iInf₂ fun d hd => by let ⟨s, hs, hs_comp⟩ := comp3_mem_uniformity hd let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs have : s ⊆ interior d := calc s ⊆ t := hst _ ⊆ interior d := ht.subset_interior_iff.mpr fun x (hx : x ∈ t) => let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp hx hs_comp ⟨x, h₁, y, h₂, h₃⟩ have : interior d ∈ 𝓤 α := by filter_upwards [hs] using this simp [this]) fun _ hs => ((𝓤 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset theorem interior_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : interior s ∈ 𝓤 α := by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs theorem mem_uniformity_isClosed {s : Set (α × α)} (h : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsClosed t ∧ t ⊆ s := let ⟨t, ⟨ht_mem, htc⟩, hts⟩ := uniformity_hasBasis_closed.mem_iff.1 h ⟨t, ht_mem, htc, hts⟩ theorem isOpen_iff_isOpen_ball_subset {s : Set α} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, IsOpen V ∧ ball x V ⊆ s := by rw [isOpen_iff_ball_subset] constructor <;> intro h x hx · obtain ⟨V, hV, hV'⟩ := h x hx exact ⟨interior V, interior_mem_uniformity hV, isOpen_interior, (ball_mono interior_subset x).trans hV'⟩ · obtain ⟨V, hV, -, hV'⟩ := h x hx exact ⟨V, hV, hV'⟩ @[deprecated (since := "2024-11-18")] alias isOpen_iff_open_ball_subset := isOpen_iff_isOpen_ball_subset /-- The uniform neighborhoods of all points of a dense set cover the whole space. -/ theorem Dense.biUnion_uniformity_ball {s : Set α} {U : Set (α × α)} (hs : Dense s) (hU : U ∈ 𝓤 α) : ⋃ x ∈ s, ball x U = univ := by refine iUnion₂_eq_univ_iff.2 fun y => ?_ rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with ⟨x, hxs, hxy : (x, y) ∈ U⟩ exact ⟨x, hxs, hxy⟩ /-- The uniform neighborhoods of all points of a dense indexed collection cover the whole space. -/ lemma DenseRange.iUnion_uniformity_ball {ι : Type*} {xs : ι → α} (xs_dense : DenseRange xs) {U : Set (α × α)} (hU : U ∈ uniformity α) : ⋃ i, UniformSpace.ball (xs i) U = univ := by rw [← biUnion_range (f := xs) (g := fun x ↦ UniformSpace.ball x U)] exact Dense.biUnion_uniformity_ball xs_dense hU /-! ### Uniformity bases -/ /-- Open elements of `𝓤 α` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V) id := hasBasis_self.2 fun s hs => ⟨interior s, interior_mem_uniformity hs, isOpen_interior, interior_subset⟩ theorem Filter.HasBasis.mem_uniformity_iff {p : β → Prop} {s : β → Set (α × α)} (h : (𝓤 α).HasBasis p s) {t : Set (α × α)} : t ∈ 𝓤 α ↔ ∃ i, p i ∧ ∀ a b, (a, b) ∈ s i → (a, b) ∈ t := h.mem_iff.trans <| by simp only [Prod.forall, subset_def] /-- Open elements `s : Set (α × α)` of `𝓤 α` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open_symmetric : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V ∧ IsSymmetricRel V) id := by simp only [← and_assoc] refine uniformity_hasBasis_open.restrict fun s hs => ⟨symmetrizeRel s, ?_⟩ exact ⟨⟨symmetrize_mem_uniformity hs.1, IsOpen.inter hs.2 (hs.2.preimage continuous_swap)⟩, symmetric_symmetrizeRel s, symmetrizeRel_subset_self s⟩ theorem comp_open_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsOpen t ∧ IsSymmetricRel t ∧ t ○ t ⊆ s := by obtain ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs obtain ⟨u, ⟨hu₁, hu₂, hu₃⟩, hu₄ : u ⊆ t⟩ := uniformity_hasBasis_open_symmetric.mem_iff.mp ht₁ exact ⟨u, hu₁, hu₂, hu₃, (compRel_mono hu₄ hu₄).trans ht₂⟩ end UniformSpace open uniformity section Constructions instance : PartialOrder (UniformSpace α) := PartialOrder.lift (fun u => 𝓤[u]) fun _ _ => UniformSpace.ext protected theorem UniformSpace.le_def {u₁ u₂ : UniformSpace α} : u₁ ≤ u₂ ↔ 𝓤[u₁] ≤ 𝓤[u₂] := Iff.rfl instance : InfSet (UniformSpace α) := ⟨fun s => UniformSpace.ofCore { uniformity := ⨅ u ∈ s, 𝓤[u] refl := le_iInf fun u => le_iInf fun _ => u.toCore.refl symm := le_iInf₂ fun u hu => le_trans (map_mono <| iInf_le_of_le _ <| iInf_le _ hu) u.symm comp := le_iInf₂ fun u hu => le_trans (lift'_mono (iInf_le_of_le _ <| iInf_le _ hu) <| le_rfl) u.comp }⟩ protected theorem UniformSpace.sInf_le {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : t ∈ tt) : sInf tt ≤ t := show ⨅ u ∈ tt, 𝓤[u] ≤ 𝓤[t] from iInf₂_le t h protected theorem UniformSpace.le_sInf {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : ∀ t' ∈ tt, t ≤ t') : t ≤ sInf tt := show 𝓤[t] ≤ ⨅ u ∈ tt, 𝓤[u] from le_iInf₂ h instance : Top (UniformSpace α) := ⟨@UniformSpace.mk α ⊤ ⊤ le_top le_top fun x ↦ by simp only [nhds_top, comap_top]⟩ instance : Bot (UniformSpace α) := ⟨{ toTopologicalSpace := ⊥ uniformity := 𝓟 idRel symm := by simp [Tendsto] comp := lift'_le (mem_principal_self _) <| principal_mono.2 id_compRel.subset nhds_eq_comap_uniformity := fun s => by let _ : TopologicalSpace α := ⊥; have := discreteTopology_bot α simp [idRel] }⟩ instance : Min (UniformSpace α) := ⟨fun u₁ u₂ => { uniformity := 𝓤[u₁] ⊓ 𝓤[u₂] symm := u₁.symm.inf u₂.symm comp := (lift'_inf_le _ _ _).trans <| inf_le_inf u₁.comp u₂.comp toTopologicalSpace := u₁.toTopologicalSpace ⊓ u₂.toTopologicalSpace nhds_eq_comap_uniformity := fun _ ↦ by rw [@nhds_inf _ u₁.toTopologicalSpace _, @nhds_eq_comap_uniformity _ u₁, @nhds_eq_comap_uniformity _ u₂, comap_inf] }⟩ instance : CompleteLattice (UniformSpace α) := { inferInstanceAs (PartialOrder (UniformSpace α)) with sup := fun a b => sInf { x | a ≤ x ∧ b ≤ x } le_sup_left := fun _ _ => UniformSpace.le_sInf fun _ ⟨h, _⟩ => h le_sup_right := fun _ _ => UniformSpace.le_sInf fun _ ⟨_, h⟩ => h sup_le := fun _ _ _ h₁ h₂ => UniformSpace.sInf_le ⟨h₁, h₂⟩ inf := (· ⊓ ·) le_inf := fun a _ _ h₁ h₂ => show a.uniformity ≤ _ from le_inf h₁ h₂ inf_le_left := fun a _ => show _ ≤ a.uniformity from inf_le_left inf_le_right := fun _ b => show _ ≤ b.uniformity from inf_le_right top := ⊤ le_top := fun a => show a.uniformity ≤ ⊤ from le_top bot := ⊥ bot_le := fun u => u.toCore.refl sSup := fun tt => sInf { t | ∀ t' ∈ tt, t' ≤ t } le_sSup := fun _ _ h => UniformSpace.le_sInf fun _ h' => h' _ h sSup_le := fun _ _ h => UniformSpace.sInf_le h sInf := sInf le_sInf := fun _ _ hs => UniformSpace.le_sInf hs sInf_le := fun _ _ ha => UniformSpace.sInf_le ha } theorem iInf_uniformity {ι : Sort*} {u : ι → UniformSpace α} : 𝓤[iInf u] = ⨅ i, 𝓤[u i] := iInf_range theorem inf_uniformity {u v : UniformSpace α} : 𝓤[u ⊓ v] = 𝓤[u] ⊓ 𝓤[v] := rfl lemma bot_uniformity : 𝓤[(⊥ : UniformSpace α)] = 𝓟 idRel := rfl lemma top_uniformity : 𝓤[(⊤ : UniformSpace α)] = ⊤ := rfl instance inhabitedUniformSpace : Inhabited (UniformSpace α) := ⟨⊥⟩ instance inhabitedUniformSpaceCore : Inhabited (UniformSpace.Core α) := ⟨@UniformSpace.toCore _ default⟩ instance [Subsingleton α] : Unique (UniformSpace α) where uniq u := bot_unique <| le_principal_iff.2 <| by rw [idRel, ← diagonal, diagonal_eq_univ]; exact univ_mem /-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f` is the inverse image in the filter sense of the induced function `α × α → β × β`. See note [reducible non-instances]. -/ abbrev UniformSpace.comap (f : α → β) (u : UniformSpace β) : UniformSpace α where uniformity := 𝓤[u].comap fun p : α × α => (f p.1, f p.2) symm := by simp only [tendsto_comap_iff, Prod.swap, (· ∘ ·)] exact tendsto_swap_uniformity.comp tendsto_comap comp := le_trans (by rw [comap_lift'_eq, comap_lift'_eq2] · exact lift'_mono' fun s _ ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩ => ⟨f x, h₁, h₂⟩ · exact monotone_id.compRel monotone_id) (comap_mono u.comp) toTopologicalSpace := u.toTopologicalSpace.induced f nhds_eq_comap_uniformity x := by simp only [nhds_induced, nhds_eq_comap_uniformity, comap_comap, Function.comp_def] theorem uniformity_comap {_ : UniformSpace β} (f : α → β) : 𝓤[UniformSpace.comap f ‹_›] = comap (Prod.map f f) (𝓤 β) := rfl lemma ball_preimage {f : α → β} {U : Set (β × β)} {x : α} : UniformSpace.ball x (Prod.map f f ⁻¹' U) = f ⁻¹' UniformSpace.ball (f x) U := by ext : 1 simp only [UniformSpace.ball, mem_preimage, Prod.map_apply] @[simp] theorem uniformSpace_comap_id {α : Type*} : UniformSpace.comap (id : α → α) = id := by ext : 2 rw [uniformity_comap, Prod.map_id, comap_id] theorem UniformSpace.comap_comap {α β γ} {uγ : UniformSpace γ} {f : α → β} {g : β → γ} : UniformSpace.comap (g ∘ f) uγ = UniformSpace.comap f (UniformSpace.comap g uγ) := by ext1 simp only [uniformity_comap, Filter.comap_comap, Prod.map_comp_map] theorem UniformSpace.comap_inf {α γ} {u₁ u₂ : UniformSpace γ} {f : α → γ} : (u₁ ⊓ u₂).comap f = u₁.comap f ⊓ u₂.comap f := UniformSpace.ext Filter.comap_inf theorem UniformSpace.comap_iInf {ι α γ} {u : ι → UniformSpace γ} {f : α → γ} : (⨅ i, u i).comap f = ⨅ i, (u i).comap f := by ext : 1 simp [uniformity_comap, iInf_uniformity] theorem UniformSpace.comap_mono {α γ} {f : α → γ} : Monotone fun u : UniformSpace γ => u.comap f := fun _ _ hu => Filter.comap_mono hu theorem uniformContinuous_iff {α β} {uα : UniformSpace α} {uβ : UniformSpace β} {f : α → β} : UniformContinuous f ↔ uα ≤ uβ.comap f := Filter.map_le_iff_le_comap theorem le_iff_uniformContinuous_id {u v : UniformSpace α} : u ≤ v ↔ @UniformContinuous _ _ u v id := by rw [uniformContinuous_iff, uniformSpace_comap_id, id] theorem uniformContinuous_comap {f : α → β} [u : UniformSpace β] : @UniformContinuous α β (UniformSpace.comap f u) u f := tendsto_comap theorem uniformContinuous_comap' {f : γ → β} {g : α → γ} [v : UniformSpace β] [u : UniformSpace α] (h : UniformContinuous (f ∘ g)) : @UniformContinuous α γ u (UniformSpace.comap f v) g := tendsto_comap_iff.2 h namespace UniformSpace theorem to_nhds_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) (a : α) : @nhds _ (@UniformSpace.toTopologicalSpace _ u₁) a ≤ @nhds _ (@UniformSpace.toTopologicalSpace _ u₂) a := by rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact lift'_mono h le_rfl theorem toTopologicalSpace_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) : @UniformSpace.toTopologicalSpace _ u₁ ≤ @UniformSpace.toTopologicalSpace _ u₂ := le_of_nhds_le_nhds <| to_nhds_mono h theorem toTopologicalSpace_comap {f : α → β} {u : UniformSpace β} : @UniformSpace.toTopologicalSpace _ (UniformSpace.comap f u) = TopologicalSpace.induced f (@UniformSpace.toTopologicalSpace β u) := rfl lemma uniformSpace_eq_bot {u : UniformSpace α} : u = ⊥ ↔ idRel ∈ 𝓤[u] := le_bot_iff.symm.trans le_principal_iff protected lemma _root_.Filter.HasBasis.uniformSpace_eq_bot {ι p} {s : ι → Set (α × α)} {u : UniformSpace α} (h : 𝓤[u].HasBasis p s) : u = ⊥ ↔ ∃ i, p i ∧ Pairwise fun x y : α ↦ (x, y) ∉ s i := by simp [uniformSpace_eq_bot, h.mem_iff, subset_def, Pairwise, not_imp_not] theorem toTopologicalSpace_bot : @UniformSpace.toTopologicalSpace α ⊥ = ⊥ := rfl theorem toTopologicalSpace_top : @UniformSpace.toTopologicalSpace α ⊤ = ⊤ := rfl theorem toTopologicalSpace_iInf {ι : Sort*} {u : ι → UniformSpace α} : (iInf u).toTopologicalSpace = ⨅ i, (u i).toTopologicalSpace := TopologicalSpace.ext_nhds fun a ↦ by simp only [@nhds_eq_comap_uniformity _ (iInf u), nhds_iInf, iInf_uniformity, @nhds_eq_comap_uniformity _ (u _), Filter.comap_iInf] theorem toTopologicalSpace_sInf {s : Set (UniformSpace α)} : (sInf s).toTopologicalSpace = ⨅ i ∈ s, @UniformSpace.toTopologicalSpace α i := by rw [sInf_eq_iInf] simp only [← toTopologicalSpace_iInf] theorem toTopologicalSpace_inf {u v : UniformSpace α} : (u ⊓ v).toTopologicalSpace = u.toTopologicalSpace ⊓ v.toTopologicalSpace := rfl end UniformSpace theorem UniformContinuous.continuous [UniformSpace α] [UniformSpace β] {f : α → β} (hf : UniformContinuous f) : Continuous f := continuous_iff_le_induced.mpr <| UniformSpace.toTopologicalSpace_mono <| uniformContinuous_iff.1 hf /-- Uniform space structure on `ULift α`. -/ instance ULift.uniformSpace [UniformSpace α] : UniformSpace (ULift α) := UniformSpace.comap ULift.down ‹_› /-- Uniform space structure on `αᵒᵈ`. -/ instance OrderDual.instUniformSpace [UniformSpace α] : UniformSpace (αᵒᵈ) := ‹UniformSpace α› section UniformContinuousInfi -- TODO: add an `iff` lemma? theorem UniformContinuous.inf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ u₃ : UniformSpace β} (h₁ : UniformContinuous[u₁, u₂] f) (h₂ : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁, u₂ ⊓ u₃] f := tendsto_inf.mpr ⟨h₁, h₂⟩ theorem UniformContinuous.inf_dom_left {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_left hf theorem UniformContinuous.inf_dom_right {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₂, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_right hf theorem uniformContinuous_sInf_dom {f : α → β} {u₁ : Set (UniformSpace α)} {u₂ : UniformSpace β} {u : UniformSpace α} (h₁ : u ∈ u₁) (hf : UniformContinuous[u, u₂] f) : UniformContinuous[sInf u₁, u₂] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity] exact tendsto_iInf' ⟨u, h₁⟩ hf theorem uniformContinuous_sInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : Set (UniformSpace β)} : UniformContinuous[u₁, sInf u₂] f ↔ ∀ u ∈ u₂, UniformContinuous[u₁, u] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity, tendsto_iInf, SetCoe.forall] theorem uniformContinuous_iInf_dom {f : α → β} {u₁ : ι → UniformSpace α} {u₂ : UniformSpace β} {i : ι} (hf : UniformContinuous[u₁ i, u₂] f) : UniformContinuous[iInf u₁, u₂] f := by delta UniformContinuous rw [iInf_uniformity] exact tendsto_iInf' i hf theorem uniformContinuous_iInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : ι → UniformSpace β} : UniformContinuous[u₁, iInf u₂] f ↔ ∀ i, UniformContinuous[u₁, u₂ i] f := by delta UniformContinuous rw [iInf_uniformity, tendsto_iInf] end UniformContinuousInfi /-- A uniform space with the discrete uniformity has the discrete topology. -/ theorem discreteTopology_of_discrete_uniformity [hα : UniformSpace α] (h : uniformity α = 𝓟 idRel) : DiscreteTopology α := ⟨(UniformSpace.ext h.symm : ⊥ = hα) ▸ rfl⟩ instance : UniformSpace Empty := ⊥ instance : UniformSpace PUnit := ⊥ instance : UniformSpace Bool := ⊥ instance : UniformSpace ℕ := ⊥ instance : UniformSpace ℤ := ⊥ section variable [UniformSpace α] open Additive Multiplicative instance : UniformSpace (Additive α) := ‹UniformSpace α› instance : UniformSpace (Multiplicative α) := ‹UniformSpace α› theorem uniformContinuous_ofMul : UniformContinuous (ofMul : α → Additive α) := uniformContinuous_id theorem uniformContinuous_toMul : UniformContinuous (toMul : Additive α → α) := uniformContinuous_id theorem uniformContinuous_ofAdd : UniformContinuous (ofAdd : α → Multiplicative α) := uniformContinuous_id theorem uniformContinuous_toAdd : UniformContinuous (toAdd : Multiplicative α → α) := uniformContinuous_id theorem uniformity_additive : 𝓤 (Additive α) = (𝓤 α).map (Prod.map ofMul ofMul) := rfl theorem uniformity_multiplicative : 𝓤 (Multiplicative α) = (𝓤 α).map (Prod.map ofAdd ofAdd) := rfl end instance instUniformSpaceSubtype {p : α → Prop} [t : UniformSpace α] : UniformSpace (Subtype p) := UniformSpace.comap Subtype.val t theorem uniformity_subtype {p : α → Prop} [UniformSpace α] : 𝓤 (Subtype p) = comap (fun q : Subtype p × Subtype p => (q.1.1, q.2.1)) (𝓤 α) := rfl theorem uniformity_setCoe {s : Set α} [UniformSpace α] : 𝓤 s = comap (Prod.map ((↑) : s → α) ((↑) : s → α)) (𝓤 α) := rfl theorem map_uniformity_set_coe {s : Set α} [UniformSpace α] : map (Prod.map (↑) (↑)) (𝓤 s) = 𝓤 α ⊓ 𝓟 (s ×ˢ s) := by rw [uniformity_setCoe, map_comap, range_prodMap, Subtype.range_val] theorem uniformContinuous_subtype_val {p : α → Prop} [UniformSpace α] : UniformContinuous (Subtype.val : { a : α // p a } → α) := uniformContinuous_comap theorem UniformContinuous.subtype_mk {p : α → Prop} [UniformSpace α] [UniformSpace β] {f : β → α} (hf : UniformContinuous f) (h : ∀ x, p (f x)) : UniformContinuous (fun x => ⟨f x, h x⟩ : β → Subtype p) := uniformContinuous_comap' hf theorem uniformContinuousOn_iff_restrict [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ UniformContinuous (s.restrict f) := by delta UniformContinuousOn UniformContinuous rw [← map_uniformity_set_coe, tendsto_map'_iff]; rfl theorem tendsto_of_uniformContinuous_subtype [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} {a : α} (hf : UniformContinuous fun x : s => f x.val) (ha : s ∈ 𝓝 a) : Tendsto f (𝓝 a) (𝓝 (f a)) := by rw [(@map_nhds_subtype_coe_eq_nhds α _ s a (mem_of_mem_nhds ha) ha).symm] exact tendsto_map' hf.continuous.continuousAt theorem UniformContinuousOn.continuousOn [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} (h : UniformContinuousOn f s) : ContinuousOn f s := by rw [uniformContinuousOn_iff_restrict] at h rw [continuousOn_iff_continuous_restrict] exact h.continuous @[to_additive] instance [UniformSpace α] : UniformSpace αᵐᵒᵖ := UniformSpace.comap MulOpposite.unop ‹_› @[to_additive] theorem uniformity_mulOpposite [UniformSpace α] : 𝓤 αᵐᵒᵖ = comap (fun q : αᵐᵒᵖ × αᵐᵒᵖ => (q.1.unop, q.2.unop)) (𝓤 α) := rfl @[to_additive (attr := simp)] theorem comap_uniformity_mulOpposite [UniformSpace α] : comap (fun p : α × α => (MulOpposite.op p.1, MulOpposite.op p.2)) (𝓤 αᵐᵒᵖ) = 𝓤 α := by simpa [uniformity_mulOpposite, comap_comap, (· ∘ ·)] using comap_id namespace MulOpposite @[to_additive] theorem uniformContinuous_unop [UniformSpace α] : UniformContinuous (unop : αᵐᵒᵖ → α) := uniformContinuous_comap @[to_additive] theorem uniformContinuous_op [UniformSpace α] : UniformContinuous (op : α → αᵐᵒᵖ) := uniformContinuous_comap' uniformContinuous_id end MulOpposite section Prod open UniformSpace /- a similar product space is possible on the function space (uniformity of pointwise convergence), but we want to have the uniformity of uniform convergence on function spaces -/ instance instUniformSpaceProd [u₁ : UniformSpace α] [u₂ : UniformSpace β] : UniformSpace (α × β) := u₁.comap Prod.fst ⊓ u₂.comap Prod.snd -- check the above produces no diamond for `simp` and typeclass search example [UniformSpace α] [UniformSpace β] : (instTopologicalSpaceProd : TopologicalSpace (α × β)) = UniformSpace.toTopologicalSpace := by with_reducible_and_instances rfl theorem uniformity_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = ((𝓤 α).comap fun p : (α × β) × α × β => (p.1.1, p.2.1)) ⊓ (𝓤 β).comap fun p : (α × β) × α × β => (p.1.2, p.2.2) := rfl instance [UniformSpace α] [IsCountablyGenerated (𝓤 α)] [UniformSpace β] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (α × β)) := by rw [uniformity_prod] infer_instance theorem uniformity_prod_eq_comap_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = comap (fun p : (α × β) × α × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by simp_rw [uniformity_prod, prod_eq_inf, Filter.comap_inf, Filter.comap_comap, Function.comp_def] theorem uniformity_prod_eq_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = map (fun p : (α × α) × β × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by rw [map_swap4_eq_comap, uniformity_prod_eq_comap_prod] theorem mem_uniformity_of_uniformContinuous_invariant [UniformSpace α] [UniformSpace β] {s : Set (β × β)} {f : α → α → β} (hf : UniformContinuous fun p : α × α => f p.1 p.2) (hs : s ∈ 𝓤 β) : ∃ u ∈ 𝓤 α, ∀ a b c, (a, b) ∈ u → (f a c, f b c) ∈ s := by rw [UniformContinuous, uniformity_prod_eq_prod, tendsto_map'_iff] at hf rcases mem_prod_iff.1 (mem_map.1 <| hf hs) with ⟨u, hu, v, hv, huvt⟩ exact ⟨u, hu, fun a b c hab => @huvt ((_, _), (_, _)) ⟨hab, refl_mem_uniformity hv⟩⟩ /-- An entourage of the diagonal in `α` and an entourage in `β` yield an entourage in `α × β` once we permute coordinates. -/ def entourageProd (u : Set (α × α)) (v : Set (β × β)) : Set ((α × β) × α × β) := {((a₁, b₁),(a₂, b₂)) | (a₁, a₂) ∈ u ∧ (b₁, b₂) ∈ v} theorem mem_entourageProd {u : Set (α × α)} {v : Set (β × β)} {p : (α × β) × α × β} : p ∈ entourageProd u v ↔ (p.1.1, p.2.1) ∈ u ∧ (p.1.2, p.2.2) ∈ v := Iff.rfl theorem entourageProd_mem_uniformity [t₁ : UniformSpace α] [t₂ : UniformSpace β] {u : Set (α × α)} {v : Set (β × β)} (hu : u ∈ 𝓤 α) (hv : v ∈ 𝓤 β) : entourageProd u v ∈ 𝓤 (α × β) := by rw [uniformity_prod]; exact inter_mem_inf (preimage_mem_comap hu) (preimage_mem_comap hv) theorem ball_entourageProd (u : Set (α × α)) (v : Set (β × β)) (x : α × β) : ball x (entourageProd u v) = ball x.1 u ×ˢ ball x.2 v := by ext p; simp only [ball, entourageProd, Set.mem_setOf_eq, Set.mem_prod, Set.mem_preimage] lemma IsSymmetricRel.entourageProd {u : Set (α × α)} {v : Set (β × β)} (hu : IsSymmetricRel u) (hv : IsSymmetricRel v) : IsSymmetricRel (entourageProd u v) := Set.ext fun _ ↦ and_congr hu.mk_mem_comm hv.mk_mem_comm theorem Filter.HasBasis.uniformity_prod {ιa ιb : Type*} [UniformSpace α] [UniformSpace β] {pa : ιa → Prop} {pb : ιb → Prop} {sa : ιa → Set (α × α)} {sb : ιb → Set (β × β)} (ha : (𝓤 α).HasBasis pa sa) (hb : (𝓤 β).HasBasis pb sb) : (𝓤 (α × β)).HasBasis (fun i : ιa × ιb ↦ pa i.1 ∧ pb i.2) (fun i ↦ entourageProd (sa i.1) (sb i.2)) := (ha.comap _).inf (hb.comap _) theorem entourageProd_subset [UniformSpace α] [UniformSpace β] {s : Set ((α × β) × α × β)} (h : s ∈ 𝓤 (α × β)) : ∃ u ∈ 𝓤 α, ∃ v ∈ 𝓤 β, entourageProd u v ⊆ s := by rcases (((𝓤 α).basis_sets.uniformity_prod (𝓤 β).basis_sets).mem_iff' s).1 h with ⟨w, hw⟩ use w.1, hw.1.1, w.2, hw.1.2, hw.2 theorem tendsto_prod_uniformity_fst [UniformSpace α] [UniformSpace β] : Tendsto (fun p : (α × β) × α × β => (p.1.1, p.2.1)) (𝓤 (α × β)) (𝓤 α) := le_trans (map_mono inf_le_left) map_comap_le theorem tendsto_prod_uniformity_snd [UniformSpace α] [UniformSpace β] : Tendsto (fun p : (α × β) × α × β => (p.1.2, p.2.2)) (𝓤 (α × β)) (𝓤 β) := le_trans (map_mono inf_le_right) map_comap_le theorem uniformContinuous_fst [UniformSpace α] [UniformSpace β] : UniformContinuous fun p : α × β => p.1 := tendsto_prod_uniformity_fst theorem uniformContinuous_snd [UniformSpace α] [UniformSpace β] : UniformContinuous fun p : α × β => p.2 :=
tendsto_prod_uniformity_snd variable [UniformSpace α] [UniformSpace β] [UniformSpace γ]
Mathlib/Topology/UniformSpace/Basic.lean
732
734
/- Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn -/ import Mathlib.Data.Fin.VecNotation import Mathlib.SetTheory.Cardinal.Basic /-! # Basics on First-Order Structures This file defines first-order languages and structures in the style of the [Flypitch project](https://flypitch.github.io/), as well as several important maps between structures. ## Main Definitions - A `FirstOrder.Language` defines a language as a pair of functions from the natural numbers to `Type l`. One sends `n` to the type of `n`-ary functions, and the other sends `n` to the type of `n`-ary relations. - A `FirstOrder.Language.Structure` interprets the symbols of a given `FirstOrder.Language` in the context of a given type. - A `FirstOrder.Language.Hom`, denoted `M →[L] N`, is a map from the `L`-structure `M` to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves the interpretations of relations (although only in the forward direction). - A `FirstOrder.Language.Embedding`, denoted `M ↪[L] N`, is an embedding from the `L`-structure `M` to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves the interpretations of relations in both directions. - A `FirstOrder.Language.Equiv`, denoted `M ≃[L] N`, is an equivalence from the `L`-structure `M` to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves the interpretations of relations in both directions. ## References For the Flypitch project: - [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*] [flypitch_cpp] - [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of the continuum hypothesis*][flypitch_itp] -/ universe u v u' v' w w' open Cardinal namespace FirstOrder /-! ### Languages and Structures -/ -- intended to be used with explicit universe parameters /-- A first-order language consists of a type of functions of every natural-number arity and a type of relations of every natural-number arity. -/ @[nolint checkUnivs] structure Language where /-- For every arity, a `Type*` of functions of that arity -/ Functions : ℕ → Type u /-- For every arity, a `Type*` of relations of that arity -/ Relations : ℕ → Type v namespace Language variable (L : Language.{u, v}) /-- A language is relational when it has no function symbols. -/ abbrev IsRelational : Prop := ∀ n, IsEmpty (L.Functions n) /-- A language is algebraic when it has no relation symbols. -/ abbrev IsAlgebraic : Prop := ∀ n, IsEmpty (L.Relations n) /-- The empty language has no symbols. -/ protected def empty : Language := ⟨fun _ => Empty, fun _ => Empty⟩ deriving IsAlgebraic, IsRelational instance : Inhabited Language := ⟨Language.empty⟩ /-- The sum of two languages consists of the disjoint union of their symbols. -/ protected def sum (L' : Language.{u', v'}) : Language := ⟨fun n => L.Functions n ⊕ L'.Functions n, fun n => L.Relations n ⊕ L'.Relations n⟩ /-- The type of constants in a given language. -/ protected abbrev Constants := L.Functions 0 /-- The type of symbols in a given language. -/ abbrev Symbols := (Σ l, L.Functions l) ⊕ (Σ l, L.Relations l) /-- The cardinality of a language is the cardinality of its type of symbols. -/ def card : Cardinal := #L.Symbols variable {L} {L' : Language.{u', v'}} theorem card_eq_card_functions_add_card_relations : L.card = (Cardinal.sum fun l => Cardinal.lift.{v} #(L.Functions l)) + Cardinal.sum fun l => Cardinal.lift.{u} #(L.Relations l) := by simp only [card, mk_sum, mk_sigma, lift_sum] instance isRelational_sum [L.IsRelational] [L'.IsRelational] : IsRelational (L.sum L') := fun _ => instIsEmptySum instance isAlgebraic_sum [L.IsAlgebraic] [L'.IsAlgebraic] : IsAlgebraic (L.sum L') := fun _ => instIsEmptySum @[simp] theorem card_empty : Language.empty.card = 0 := by simp only [card, mk_sum, mk_sigma, mk_eq_zero, sum_const, mk_eq_aleph0, lift_id', mul_zero, add_zero] @[deprecated (since := "2025-02-05")] alias empty_card := card_empty instance isEmpty_empty : IsEmpty Language.empty.Symbols := by simp only [Language.Symbols, isEmpty_sum, isEmpty_sigma] exact ⟨fun _ => inferInstance, fun _ => inferInstance⟩ instance Countable.countable_functions [h : Countable L.Symbols] : Countable (Σl, L.Functions l) := @Function.Injective.countable _ _ h _ Sum.inl_injective @[simp] theorem card_functions_sum (i : ℕ) : #((L.sum L').Functions i) = (Cardinal.lift.{u'} #(L.Functions i) + Cardinal.lift.{u} #(L'.Functions i) : Cardinal) := by simp [Language.sum] @[simp] theorem card_relations_sum (i : ℕ) : #((L.sum L').Relations i) = Cardinal.lift.{v'} #(L.Relations i) + Cardinal.lift.{v} #(L'.Relations i) := by simp [Language.sum] theorem card_sum : (L.sum L').card = Cardinal.lift.{max u' v'} L.card + Cardinal.lift.{max u v} L'.card := by simp only [card, mk_sum, mk_sigma, card_functions_sum, sum_add_distrib', lift_add, lift_sum, lift_lift, card_relations_sum, add_assoc, add_comm (Cardinal.sum fun i => (#(L'.Functions i)).lift)] /-- Passes a `DecidableEq` instance on a type of function symbols through the `Language` constructor. Despite the fact that this is proven by `inferInstance`, it is still needed - see the `example`s in `ModelTheory/Ring/Basic`. -/ instance instDecidableEqFunctions {f : ℕ → Type*} {R : ℕ → Type*} (n : ℕ) [DecidableEq (f n)] : DecidableEq ((⟨f, R⟩ : Language).Functions n) := inferInstance /-- Passes a `DecidableEq` instance on a type of relation symbols through the `Language` constructor. Despite the fact that this is proven by `inferInstance`, it is still needed - see the `example`s in `ModelTheory/Ring/Basic`. -/ instance instDecidableEqRelations {f : ℕ → Type*} {R : ℕ → Type*} (n : ℕ) [DecidableEq (R n)] : DecidableEq ((⟨f, R⟩ : Language).Relations n) := inferInstance variable (L) (M : Type w) /-- A first-order structure on a type `M` consists of interpretations of all the symbols in a given language. Each function of arity `n` is interpreted as a function sending tuples of length `n` (modeled as `(Fin n → M)`) to `M`, and a relation of arity `n` is a function from tuples of length `n` to `Prop`. -/ @[ext] class Structure where /-- Interpretation of the function symbols -/ funMap : ∀ {n}, L.Functions n → (Fin n → M) → M := by exact fun {n} => isEmptyElim /-- Interpretation of the relation symbols -/ RelMap : ∀ {n}, L.Relations n → (Fin n → M) → Prop := by exact fun {n} => isEmptyElim variable (N : Type w') [L.Structure M] [L.Structure N] open Structure /-- Used for defining `FirstOrder.Language.Theory.ModelType.instInhabited`. -/ def Inhabited.trivialStructure {α : Type*} [Inhabited α] : L.Structure α := ⟨default, default⟩ /-! ### Maps -/ /-- A homomorphism between first-order structures is a function that commutes with the interpretations of functions and maps tuples in one structure where a given relation is true to tuples in the second structure where that relation is still true. -/ structure Hom where /-- The underlying function of a homomorphism of structures -/ toFun : M → N /-- The homomorphism commutes with the interpretations of the function symbols -/ -- Porting note: -- The autoparam here used to be `obviously`. We would like to replace it with `aesop` -- but that isn't currently sufficient. -- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Aesop.20and.20cases -- If that can be improved, we should change this to `by aesop` and remove the proofs below. map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by intros; trivial /-- The homomorphism sends related elements to related elements -/ map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r x → RelMap r (toFun ∘ x) := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial @[inherit_doc] scoped[FirstOrder] notation:25 A " →[" L "] " B => FirstOrder.Language.Hom L A B /-- An embedding of first-order structures is an embedding that commutes with the interpretations of functions and relations. -/ structure Embedding extends M ↪ N where map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r (toFun ∘ x) ↔ RelMap r x := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial @[inherit_doc] scoped[FirstOrder] notation:25 A " ↪[" L "] " B => FirstOrder.Language.Embedding L A B /-- An equivalence of first-order structures is an equivalence that commutes with the interpretations of functions and relations. -/ structure Equiv extends M ≃ N where map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r (toFun ∘ x) ↔ RelMap r x := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial @[inherit_doc] scoped[FirstOrder] notation:25 A " ≃[" L "] " B => FirstOrder.Language.Equiv L A B variable {L M N} {P : Type*} [L.Structure P] {Q : Type*} [L.Structure Q] /-- Interpretation of a constant symbol -/ @[coe] def constantMap (c : L.Constants) : M := funMap c default instance : CoeTC L.Constants M := ⟨constantMap⟩ theorem funMap_eq_coe_constants {c : L.Constants} {x : Fin 0 → M} : funMap c x = c := congr rfl (funext finZeroElim) /-- Given a language with a nonempty type of constants, any structure will be nonempty. This cannot be a global instance, because `L` becomes a metavariable. -/ theorem nonempty_of_nonempty_constants [h : Nonempty L.Constants] : Nonempty M := h.map (↑) /-- `HomClass L F M N` states that `F` is a type of `L`-homomorphisms. You should extend this typeclass when you extend `FirstOrder.Language.Hom`. -/ class HomClass (L : outParam Language) (F : Type*) (M N : outParam Type*) [FunLike F M N] [L.Structure M] [L.Structure N] : Prop where map_fun : ∀ (φ : F) {n} (f : L.Functions n) (x), φ (funMap f x) = funMap f (φ ∘ x) map_rel : ∀ (φ : F) {n} (r : L.Relations n) (x), RelMap r x → RelMap r (φ ∘ x) /-- `StrongHomClass L F M N` states that `F` is a type of `L`-homomorphisms which preserve relations in both directions. -/ class StrongHomClass (L : outParam Language) (F : Type*) (M N : outParam Type*) [FunLike F M N] [L.Structure M] [L.Structure N] : Prop where map_fun : ∀ (φ : F) {n} (f : L.Functions n) (x), φ (funMap f x) = funMap f (φ ∘ x) map_rel : ∀ (φ : F) {n} (r : L.Relations n) (x), RelMap r (φ ∘ x) ↔ RelMap r x instance (priority := 100) StrongHomClass.homClass {F : Type*} [L.Structure M] [L.Structure N] [FunLike F M N] [StrongHomClass L F M N] : HomClass L F M N where map_fun := StrongHomClass.map_fun map_rel φ _ R x := (StrongHomClass.map_rel φ R x).2 /-- Not an instance to avoid a loop. -/ theorem HomClass.strongHomClassOfIsAlgebraic [L.IsAlgebraic] {F M N} [L.Structure M] [L.Structure N] [FunLike F M N] [HomClass L F M N] : StrongHomClass L F M N where map_fun := HomClass.map_fun map_rel _ _ := isEmptyElim theorem HomClass.map_constants {F M N} [L.Structure M] [L.Structure N] [FunLike F M N] [HomClass L F M N] (φ : F) (c : L.Constants) : φ c = c := (HomClass.map_fun φ c default).trans (congr rfl (funext default)) attribute [inherit_doc FirstOrder.Language.Hom.map_fun'] FirstOrder.Language.Embedding.map_fun' FirstOrder.Language.HomClass.map_fun FirstOrder.Language.StrongHomClass.map_fun FirstOrder.Language.Equiv.map_fun' attribute [inherit_doc FirstOrder.Language.Hom.map_rel'] FirstOrder.Language.Embedding.map_rel' FirstOrder.Language.HomClass.map_rel FirstOrder.Language.StrongHomClass.map_rel FirstOrder.Language.Equiv.map_rel' namespace Hom instance instFunLike : FunLike (M →[L] N) M N where coe := Hom.toFun coe_injective' f g h := by cases f; cases g; cases h; rfl instance homClass : HomClass L (M →[L] N) M N where map_fun := map_fun' map_rel := map_rel' instance [L.IsAlgebraic] : StrongHomClass L (M →[L] N) M N := HomClass.strongHomClassOfIsAlgebraic @[simp] theorem toFun_eq_coe {f : M →[L] N} : f.toFun = (f : M → N) := rfl @[ext] theorem ext ⦃f g : M →[L] N⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h @[simp] theorem map_fun (φ : M →[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) : φ (funMap f x) = funMap f (φ ∘ x) := HomClass.map_fun φ f x @[simp] theorem map_constants (φ : M →[L] N) (c : L.Constants) : φ c = c := HomClass.map_constants φ c @[simp] theorem map_rel (φ : M →[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) : RelMap r x → RelMap r (φ ∘ x) := HomClass.map_rel φ r x variable (L) (M) /-- The identity map from a structure to itself. -/ @[refl] def id : M →[L] M where toFun m := m variable {L} {M} instance : Inhabited (M →[L] M) := ⟨id L M⟩ @[simp] theorem id_apply (x : M) : id L M x = x := rfl /-- Composition of first-order homomorphisms. -/ @[trans] def comp (hnp : N →[L] P) (hmn : M →[L] N) : M →[L] P where toFun := hnp ∘ hmn -- Porting note: should be done by autoparam? map_fun' _ _ := by simp; rfl -- Porting note: should be done by autoparam? map_rel' _ _ h := map_rel _ _ _ (map_rel _ _ _ h) @[simp] theorem comp_apply (g : N →[L] P) (f : M →[L] N) (x : M) : g.comp f x = g (f x) := rfl /-- Composition of first-order homomorphisms is associative. -/ theorem comp_assoc (f : M →[L] N) (g : N →[L] P) (h : P →[L] Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[simp] theorem comp_id (f : M →[L] N) : f.comp (id L M) = f := rfl @[simp] theorem id_comp (f : M →[L] N) : (id L N).comp f = f := rfl end Hom /-- Any element of a `HomClass` can be realized as a first_order homomorphism. -/ @[simps] def HomClass.toHom {F M N} [L.Structure M] [L.Structure N] [FunLike F M N] [HomClass L F M N] : F → M →[L] N := fun φ => ⟨φ, HomClass.map_fun φ, HomClass.map_rel φ⟩ namespace Embedding instance funLike : FunLike (M ↪[L] N) M N where coe f := f.toFun coe_injective' f g h := by cases f cases g congr ext x exact funext_iff.1 h x instance embeddingLike : EmbeddingLike (M ↪[L] N) M N where injective' f := f.toEmbedding.injective instance strongHomClass : StrongHomClass L (M ↪[L] N) M N where map_fun := map_fun' map_rel := map_rel' @[simp] theorem map_fun (φ : M ↪[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) : φ (funMap f x) = funMap f (φ ∘ x) := HomClass.map_fun φ f x @[simp] theorem map_constants (φ : M ↪[L] N) (c : L.Constants) : φ c = c := HomClass.map_constants φ c @[simp] theorem map_rel (φ : M ↪[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) : RelMap r (φ ∘ x) ↔ RelMap r x := StrongHomClass.map_rel φ r x /-- A first-order embedding is also a first-order homomorphism. -/ def toHom : (M ↪[L] N) → M →[L] N := HomClass.toHom @[simp] theorem coe_toHom {f : M ↪[L] N} : (f.toHom : M → N) = f := rfl theorem coe_injective : @Function.Injective (M ↪[L] N) (M → N) (↑) | f, g, h => by cases f cases g congr ext x exact funext_iff.1 h x @[ext] theorem ext ⦃f g : M ↪[L] N⦄ (h : ∀ x, f x = g x) : f = g := coe_injective (funext h) theorem toHom_injective : @Function.Injective (M ↪[L] N) (M →[L] N) (·.toHom) := by intro f f' h ext exact congr_fun (congr_arg (↑) h) _ @[simp] theorem toHom_inj {f g : M ↪[L] N} : f.toHom = g.toHom ↔ f = g := ⟨fun h ↦ toHom_injective h, fun h ↦ congr_arg (·.toHom) h⟩ theorem injective (f : M ↪[L] N) : Function.Injective f := f.toEmbedding.injective /-- In an algebraic language, any injective homomorphism is an embedding. -/ @[simps!] def ofInjective [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) : M ↪[L] N := { f with inj' := hf map_rel' := fun {_} r x => StrongHomClass.map_rel f r x } @[simp] theorem coeFn_ofInjective [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) : (ofInjective hf : M → N) = f := rfl @[simp] theorem ofInjective_toHom [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) : (ofInjective hf).toHom = f := by ext; simp variable (L) (M) /-- The identity embedding from a structure to itself. -/ @[refl] def refl : M ↪[L] M where toEmbedding := Function.Embedding.refl M variable {L} {M} instance : Inhabited (M ↪[L] M) := ⟨refl L M⟩ @[simp] theorem refl_apply (x : M) : refl L M x = x := rfl /-- Composition of first-order embeddings. -/ @[trans] def comp (hnp : N ↪[L] P) (hmn : M ↪[L] N) : M ↪[L] P where toFun := hnp ∘ hmn inj' := hnp.injective.comp hmn.injective -- Porting note: should be done by autoparam? map_fun' := by intros; simp only [Function.comp_apply, map_fun]; trivial -- Porting note: should be done by autoparam? map_rel' := by intros; rw [Function.comp_assoc, map_rel, map_rel] @[simp] theorem comp_apply (g : N ↪[L] P) (f : M ↪[L] N) (x : M) : g.comp f x = g (f x) := rfl /-- Composition of first-order embeddings is associative. -/ theorem comp_assoc (f : M ↪[L] N) (g : N ↪[L] P) (h : P ↪[L] Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl theorem comp_injective (h : N ↪[L] P) : Function.Injective (h.comp : (M ↪[L] N) → (M ↪[L] P)) := by intro f g hfg ext x; exact h.injective (DFunLike.congr_fun hfg x) @[simp] theorem comp_inj (h : N ↪[L] P) (f g : M ↪[L] N) : h.comp f = h.comp g ↔ f = g := ⟨fun eq ↦ h.comp_injective eq, congr_arg h.comp⟩ theorem toHom_comp_injective (h : N ↪[L] P) : Function.Injective (h.toHom.comp : (M →[L] N) → (M →[L] P)) := by intro f g hfg ext x; exact h.injective (DFunLike.congr_fun hfg x) @[simp] theorem toHom_comp_inj (h : N ↪[L] P) (f g : M →[L] N) : h.toHom.comp f = h.toHom.comp g ↔ f = g := ⟨fun eq ↦ h.toHom_comp_injective eq, congr_arg h.toHom.comp⟩ @[simp] theorem comp_toHom (hnp : N ↪[L] P) (hmn : M ↪[L] N) : (hnp.comp hmn).toHom = hnp.toHom.comp hmn.toHom := rfl @[simp] theorem comp_refl (f : M ↪[L] N) : f.comp (refl L M) = f := DFunLike.coe_injective rfl @[simp] theorem refl_comp (f : M ↪[L] N) : (refl L N).comp f = f := DFunLike.coe_injective rfl @[simp] theorem refl_toHom : (refl L M).toHom = Hom.id L M := rfl end Embedding /-- Any element of an injective `StrongHomClass` can be realized as a first_order embedding. -/ @[simps] def StrongHomClass.toEmbedding {F M N} [L.Structure M] [L.Structure N] [FunLike F M N] [EmbeddingLike F M N] [StrongHomClass L F M N] : F → M ↪[L] N := fun φ => ⟨⟨φ, EmbeddingLike.injective φ⟩, StrongHomClass.map_fun φ, StrongHomClass.map_rel φ⟩ namespace Equiv instance : EquivLike (M ≃[L] N) M N where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' f g h₁ h₂ := by cases f cases g simp only [mk.injEq] ext x exact funext_iff.1 h₁ x instance : StrongHomClass L (M ≃[L] N) M N where map_fun := map_fun' map_rel := map_rel' /-- The inverse of a first-order equivalence is a first-order equivalence. -/ @[symm] def symm (f : M ≃[L] N) : N ≃[L] M := { f.toEquiv.symm with map_fun' := fun n f' {x} => by simp only [Equiv.toFun_as_coe] rw [Equiv.symm_apply_eq] refine Eq.trans ?_ (f.map_fun' f' (f.toEquiv.symm ∘ x)).symm rw [← Function.comp_assoc, Equiv.toFun_as_coe, Equiv.self_comp_symm, Function.id_comp] map_rel' := fun n r {x} => by simp only [Equiv.toFun_as_coe] refine (f.map_rel' r (f.toEquiv.symm ∘ x)).symm.trans ?_ rw [← Function.comp_assoc, Equiv.toFun_as_coe, Equiv.self_comp_symm, Function.id_comp] } @[simp] theorem symm_symm (f : M ≃[L] N) : f.symm.symm = f := rfl theorem symm_bijective : Function.Bijective (symm : (M ≃[L] N) → _) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem apply_symm_apply (f : M ≃[L] N) (a : N) : f (f.symm a) = a := f.toEquiv.apply_symm_apply a @[simp] theorem symm_apply_apply (f : M ≃[L] N) (a : M) : f.symm (f a) = a := f.toEquiv.symm_apply_apply a @[simp] theorem map_fun (φ : M ≃[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) : φ (funMap f x) = funMap f (φ ∘ x) := HomClass.map_fun φ f x @[simp] theorem map_constants (φ : M ≃[L] N) (c : L.Constants) : φ c = c := HomClass.map_constants φ c @[simp] theorem map_rel (φ : M ≃[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) : RelMap r (φ ∘ x) ↔ RelMap r x := StrongHomClass.map_rel φ r x /-- A first-order equivalence is also a first-order embedding. -/ def toEmbedding : (M ≃[L] N) → M ↪[L] N := StrongHomClass.toEmbedding /-- A first-order equivalence is also a first-order homomorphism. -/ def toHom : (M ≃[L] N) → M →[L] N := HomClass.toHom @[simp] theorem toEmbedding_toHom (f : M ≃[L] N) : f.toEmbedding.toHom = f.toHom := rfl @[simp] theorem coe_toHom {f : M ≃[L] N} : (f.toHom : M → N) = (f : M → N) := rfl @[simp] theorem coe_toEmbedding (f : M ≃[L] N) : (f.toEmbedding : M → N) = (f : M → N) := rfl theorem injective_toEmbedding : Function.Injective (toEmbedding : (M ≃[L] N) → M ↪[L] N) := by intro _ _ h; apply DFunLike.coe_injective; exact congr_arg (DFunLike.coe ∘ Embedding.toHom) h theorem coe_injective : @Function.Injective (M ≃[L] N) (M → N) (↑) := DFunLike.coe_injective @[ext] theorem ext ⦃f g : M ≃[L] N⦄ (h : ∀ x, f x = g x) : f = g := coe_injective (funext h) theorem bijective (f : M ≃[L] N) : Function.Bijective f := EquivLike.bijective f theorem injective (f : M ≃[L] N) : Function.Injective f := EquivLike.injective f theorem surjective (f : M ≃[L] N) : Function.Surjective f := EquivLike.surjective f variable (L) (M) /-- The identity equivalence from a structure to itself. -/ @[refl] def refl : M ≃[L] M where toEquiv := _root_.Equiv.refl M variable {L} {M} instance : Inhabited (M ≃[L] M) := ⟨refl L M⟩ @[simp] theorem refl_apply (x : M) : refl L M x = x := by simp [refl]; rfl /-- Composition of first-order equivalences. -/ @[trans] def comp (hnp : N ≃[L] P) (hmn : M ≃[L] N) : M ≃[L] P := { hmn.toEquiv.trans hnp.toEquiv with toFun := hnp ∘ hmn -- Porting note: should be done by autoparam? map_fun' := by intros; simp only [Function.comp_apply, map_fun]; trivial -- Porting note: should be done by autoparam? map_rel' := by intros; rw [Function.comp_assoc, map_rel, map_rel] } @[simp] theorem comp_apply (g : N ≃[L] P) (f : M ≃[L] N) (x : M) : g.comp f x = g (f x) := rfl @[simp] theorem comp_refl (g : M ≃[L] N) : g.comp (refl L M) = g := rfl @[simp] theorem refl_comp (g : M ≃[L] N) : (refl L N).comp g = g := rfl @[simp] theorem refl_toEmbedding : (refl L M).toEmbedding = Embedding.refl L M := rfl @[simp] theorem refl_toHom : (refl L M).toHom = Hom.id L M := rfl /-- Composition of first-order homomorphisms is associative. -/ theorem comp_assoc (f : M ≃[L] N) (g : N ≃[L] P) (h : P ≃[L] Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl theorem injective_comp (h : N ≃[L] P) : Function.Injective (h.comp : (M ≃[L] N) → (M ≃[L] P)) := by intro f g hfg ext x; exact h.injective (congr_fun (congr_arg DFunLike.coe hfg) x) @[simp] theorem comp_toHom (hnp : N ≃[L] P) (hmn : M ≃[L] N) : (hnp.comp hmn).toHom = hnp.toHom.comp hmn.toHom := rfl @[simp] theorem comp_toEmbedding (hnp : N ≃[L] P) (hmn : M ≃[L] N) : (hnp.comp hmn).toEmbedding = hnp.toEmbedding.comp hmn.toEmbedding := rfl @[simp] theorem self_comp_symm (f : M ≃[L] N) : f.comp f.symm = refl L N := by ext; rw [comp_apply, apply_symm_apply, refl_apply] @[simp] theorem symm_comp_self (f : M ≃[L] N) : f.symm.comp f = refl L M := by ext; rw [comp_apply, symm_apply_apply, refl_apply] @[simp] theorem symm_comp_self_toEmbedding (f : M ≃[L] N) : f.symm.toEmbedding.comp f.toEmbedding = Embedding.refl L M := by rw [← comp_toEmbedding, symm_comp_self, refl_toEmbedding] @[simp] theorem self_comp_symm_toEmbedding (f : M ≃[L] N) : f.toEmbedding.comp f.symm.toEmbedding = Embedding.refl L N := by rw [← comp_toEmbedding, self_comp_symm, refl_toEmbedding] @[simp] theorem symm_comp_self_toHom (f : M ≃[L] N) : f.symm.toHom.comp f.toHom = Hom.id L M := by rw [← comp_toHom, symm_comp_self, refl_toHom] @[simp] theorem self_comp_symm_toHom (f : M ≃[L] N) : f.toHom.comp f.symm.toHom = Hom.id L N := by rw [← comp_toHom, self_comp_symm, refl_toHom] @[simp] theorem comp_symm (f : M ≃[L] N) (g : N ≃[L] P) : (g.comp f).symm = f.symm.comp g.symm := rfl theorem comp_right_injective (h : M ≃[L] N) : Function.Injective (fun f ↦ f.comp h : (N ≃[L] P) → (M ≃[L] P)) := by intro f g hfg convert (congr_arg (fun r : (M ≃[L] P) ↦ r.comp h.symm) hfg) <;> rw [comp_assoc, self_comp_symm, comp_refl] @[simp] theorem comp_right_inj (h : M ≃[L] N) (f g : N ≃[L] P) : f.comp h = g.comp h ↔ f = g := ⟨fun eq ↦ h.comp_right_injective eq, congr_arg (fun (r : N ≃[L] P) ↦ r.comp h)⟩ end Equiv /-- Any element of a bijective `StrongHomClass` can be realized as a first_order isomorphism. -/ @[simps] def StrongHomClass.toEquiv {F M N} [L.Structure M] [L.Structure N] [EquivLike F M N] [StrongHomClass L F M N] : F → M ≃[L] N := fun φ => ⟨⟨φ, EquivLike.inv φ, EquivLike.left_inv φ, EquivLike.right_inv φ⟩, StrongHomClass.map_fun φ, StrongHomClass.map_rel φ⟩ section SumStructure variable (L₁ L₂ : Language) (S : Type*) [L₁.Structure S] [L₂.Structure S] instance sumStructure : (L₁.sum L₂).Structure S where funMap := Sum.elim funMap funMap RelMap := Sum.elim RelMap RelMap variable {L₁ L₂ S} @[simp] theorem funMap_sumInl {n : ℕ} (f : L₁.Functions n) : @funMap (L₁.sum L₂) S _ n (Sum.inl f) = funMap f := rfl @[simp] theorem funMap_sumInr {n : ℕ} (f : L₂.Functions n) : @funMap (L₁.sum L₂) S _ n (Sum.inr f) = funMap f := rfl @[simp] theorem relMap_sumInl {n : ℕ} (R : L₁.Relations n) : @RelMap (L₁.sum L₂) S _ n (Sum.inl R) = RelMap R := rfl @[simp] theorem relMap_sumInr {n : ℕ} (R : L₂.Relations n) : @RelMap (L₁.sum L₂) S _ n (Sum.inr R) = RelMap R := rfl @[deprecated (since := "2025-02-21")] alias funMap_sum_inl := funMap_sumInl @[deprecated (since := "2025-02-21")] alias funMap_sum_inr := funMap_sumInr @[deprecated (since := "2025-02-21")] alias relMap_sum_inl := relMap_sumInl @[deprecated (since := "2025-02-21")] alias relMap_sum_inr := relMap_sumInr end SumStructure section Empty /-- Any type can be made uniquely into a structure over the empty language. -/ def emptyStructure : Language.empty.Structure M where instance : Unique (Language.empty.Structure M) := ⟨⟨Language.emptyStructure⟩, fun a => by ext _ f <;> exact Empty.elim f⟩ variable [Language.empty.Structure M] [Language.empty.Structure N] instance (priority := 100) strongHomClassEmpty {F} [FunLike F M N] : StrongHomClass Language.empty F M N := ⟨fun _ _ f => Empty.elim f, fun _ _ r => Empty.elim r⟩ @[simp] theorem empty.nonempty_embedding_iff : Nonempty (M ↪[Language.empty] N) ↔ Cardinal.lift.{w'} #M ≤ Cardinal.lift.{w} #N := _root_.trans ⟨Nonempty.map fun f => f.toEmbedding, Nonempty.map StrongHomClass.toEmbedding⟩ Cardinal.lift_mk_le'.symm @[simp] theorem empty.nonempty_equiv_iff : Nonempty (M ≃[Language.empty] N) ↔ Cardinal.lift.{w'} #M = Cardinal.lift.{w} #N := _root_.trans ⟨Nonempty.map fun f => f.toEquiv, Nonempty.map fun f => { toEquiv := f }⟩ Cardinal.lift_mk_eq'.symm /-- Makes a `Language.empty.Hom` out of any function. This is only needed because there is no instance of `FunLike (M → N) M N`, and thus no instance of `Language.empty.HomClass M N`. -/ @[simps] def _root_.Function.emptyHom (f : M → N) : M →[Language.empty] N where toFun := f end Empty end Language end FirstOrder namespace Equiv open FirstOrder FirstOrder.Language FirstOrder.Language.Structure open FirstOrder variable {L : Language} {M : Type*} {N : Type*} [L.Structure M] /-- A structure induced by a bijection. -/ @[simps!] def inducedStructure (e : M ≃ N) : L.Structure N := ⟨fun f x => e (funMap f (e.symm ∘ x)), fun r x => RelMap r (e.symm ∘ x)⟩ /-- A bijection as a first-order isomorphism with the induced structure on the codomain. -/ def inducedStructureEquiv (e : M ≃ N) : @Language.Equiv L M N _ (inducedStructure e) := by letI : L.Structure N := inducedStructure e exact { e with map_fun' := @fun n f x => by simp [← Function.comp_assoc e.symm e x] map_rel' := @fun n r x => by simp [← Function.comp_assoc e.symm e x] } @[simp] theorem toEquiv_inducedStructureEquiv (e : M ≃ N) : @Language.Equiv.toEquiv L M N _ (inducedStructure e) (inducedStructureEquiv e) = e := rfl @[simp] theorem toFun_inducedStructureEquiv (e : M ≃ N) : DFunLike.coe (@inducedStructureEquiv L M N _ e) = e := rfl @[simp] theorem toFun_inducedStructureEquiv_Symm (e : M ≃ N) : (by letI : L.Structure N := inducedStructure e exact DFunLike.coe (@inducedStructureEquiv L M N _ e).symm) = (e.symm : N → M) := rfl end Equiv
Mathlib/ModelTheory/Basic.lean
873
874
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.GeomSum import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.RingTheory.Noetherian.Basic /-! # Ring-theoretic supplement of Algebra.Polynomial. ## Main results * `MvPolynomial.isDomain`: If a ring is an integral domain, then so is its polynomial ring over finitely many variables. * `Polynomial.isNoetherianRing`: Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring. -/ noncomputable section open Polynomial open Finset universe u v w variable {R : Type u} {S : Type*} namespace Polynomial section Semiring variable [Semiring R] instance instCharP (p : ℕ) [h : CharP R p] : CharP R[X] p := let ⟨h⟩ := h ⟨fun n => by rw [← map_natCast C, ← C_0, C_inj, h]⟩ instance instExpChar (p : ℕ) [h : ExpChar R p] : ExpChar R[X] p := by cases h; exacts [ExpChar.zero, ExpChar.prime ‹_›] variable (R) /-- The `R`-submodule of `R[X]` consisting of polynomials of degree ≤ `n`. -/ def degreeLE (n : WithBot ℕ) : Submodule R R[X] := ⨅ k : ℕ, ⨅ _ : ↑k > n, LinearMap.ker (lcoeff R k) /-- The `R`-submodule of `R[X]` consisting of polynomials of degree < `n`. -/ def degreeLT (n : ℕ) : Submodule R R[X] := ⨅ k : ℕ, ⨅ (_ : k ≥ n), LinearMap.ker (lcoeff R k) variable {R} theorem mem_degreeLE {n : WithBot ℕ} {f : R[X]} : f ∈ degreeLE R n ↔ degree f ≤ n := by simp only [degreeLE, Submodule.mem_iInf, degree_le_iff_coeff_zero, LinearMap.mem_ker]; rfl @[mono] theorem degreeLE_mono {m n : WithBot ℕ} (H : m ≤ n) : degreeLE R m ≤ degreeLE R n := fun _ hf => mem_degreeLE.2 (le_trans (mem_degreeLE.1 hf) H) theorem degreeLE_eq_span_X_pow [DecidableEq R] {n : ℕ} : degreeLE R n = Submodule.span R ↑((Finset.range (n + 1)).image fun n => (X : R[X]) ^ n) := by apply le_antisymm · intro p hp replace hp := mem_degreeLE.1 hp rw [← Polynomial.sum_monomial_eq p, Polynomial.sum] refine Submodule.sum_mem _ fun k hk => ?_ have := WithBot.coe_le_coe.1 (Finset.sup_le_iff.1 hp k hk) rw [← C_mul_X_pow_eq_monomial, C_mul'] refine Submodule.smul_mem _ _ (Submodule.subset_span <| Finset.mem_coe.2 <| Finset.mem_image.2 ⟨_, Finset.mem_range.2 (Nat.lt_succ_of_le this), rfl⟩) rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff] intro k hk apply mem_degreeLE.2 exact (degree_X_pow_le _).trans (WithBot.coe_le_coe.2 <| Nat.le_of_lt_succ <| Finset.mem_range.1 hk) theorem mem_degreeLT {n : ℕ} {f : R[X]} : f ∈ degreeLT R n ↔ degree f < n := by rw [degreeLT, Submodule.mem_iInf] conv_lhs => intro i; rw [Submodule.mem_iInf] rw [degree, Finset.max_eq_sup_coe] rw [Finset.sup_lt_iff ?_] rotate_left · apply WithBot.bot_lt_coe conv_rhs => simp only [mem_support_iff] intro b rw [Nat.cast_withBot, WithBot.coe_lt_coe, lt_iff_not_le, Ne, not_imp_not] rfl @[mono] theorem degreeLT_mono {m n : ℕ} (H : m ≤ n) : degreeLT R m ≤ degreeLT R n := fun _ hf => mem_degreeLT.2 (lt_of_lt_of_le (mem_degreeLT.1 hf) <| WithBot.coe_le_coe.2 H) theorem degreeLT_eq_span_X_pow [DecidableEq R] {n : ℕ} : degreeLT R n = Submodule.span R ↑((Finset.range n).image fun n => X ^ n : Finset R[X]) := by apply le_antisymm · intro p hp replace hp := mem_degreeLT.1 hp rw [← Polynomial.sum_monomial_eq p, Polynomial.sum] refine Submodule.sum_mem _ fun k hk => ?_ have := WithBot.coe_lt_coe.1 ((Finset.sup_lt_iff <| WithBot.bot_lt_coe n).1 hp k hk) rw [← C_mul_X_pow_eq_monomial, C_mul'] refine Submodule.smul_mem _ _ (Submodule.subset_span <| Finset.mem_coe.2 <| Finset.mem_image.2 ⟨_, Finset.mem_range.2 this, rfl⟩) rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff] intro k hk apply mem_degreeLT.2 exact lt_of_le_of_lt (degree_X_pow_le _) (WithBot.coe_lt_coe.2 <| Finset.mem_range.1 hk) /-- The first `n` coefficients on `degreeLT n` form a linear equivalence with `Fin n → R`. -/ def degreeLTEquiv (R) [Semiring R] (n : ℕ) : degreeLT R n ≃ₗ[R] Fin n → R where toFun p n := (↑p : R[X]).coeff n invFun f := ⟨∑ i : Fin n, monomial i (f i), (degreeLT R n).sum_mem fun i _ => mem_degreeLT.mpr (lt_of_le_of_lt (degree_monomial_le i (f i)) (WithBot.coe_lt_coe.mpr i.is_lt))⟩ map_add' p q := by ext dsimp rw [coeff_add] map_smul' x p := by ext dsimp rw [coeff_smul] rfl left_inv := by rintro ⟨p, hp⟩ ext1 simp only [Submodule.coe_mk] by_cases hp0 : p = 0 · subst hp0 simp only [coeff_zero, LinearMap.map_zero, Finset.sum_const_zero] rw [mem_degreeLT, degree_eq_natDegree hp0, Nat.cast_lt] at hp conv_rhs => rw [p.as_sum_range' n hp, ← Fin.sum_univ_eq_sum_range] right_inv f := by ext i simp only [finset_sum_coeff, Submodule.coe_mk] rw [Finset.sum_eq_single i, coeff_monomial, if_pos rfl] · rintro j - hji rw [coeff_monomial, if_neg] rwa [← Fin.ext_iff] · intro h exact (h (Finset.mem_univ _)).elim theorem degreeLTEquiv_eq_zero_iff_eq_zero {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) : degreeLTEquiv _ _ ⟨p, hp⟩ = 0 ↔ p = 0 := by simp theorem eval_eq_sum_degreeLTEquiv {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) (x : R) : p.eval x = ∑ i, degreeLTEquiv _ _ ⟨p, hp⟩ i * x ^ (i : ℕ) := by simp_rw [eval_eq_sum] exact (sum_fin _ (by simp_rw [zero_mul, forall_const]) (mem_degreeLT.mp hp)).symm theorem degreeLT_succ_eq_degreeLE {n : ℕ} : degreeLT R (n + 1) = degreeLE R n := by ext x by_cases x_zero : x = 0 · simp_rw [x_zero, Submodule.zero_mem] · rw [mem_degreeLT, mem_degreeLE, ← natDegree_lt_iff_degree_lt (by rwa [ne_eq]), ← natDegree_le_iff_degree_le, Nat.lt_succ] /-- The equivalence between monic polynomials of degree `n` and polynomials of degree less than `n`, formed by adding a term `X ^ n`. -/ def monicEquivDegreeLT [Nontrivial R] (n : ℕ) : { p : R[X] // p.Monic ∧ p.natDegree = n } ≃ degreeLT R n where toFun p := ⟨p.1.eraseLead, by rcases p with ⟨p, hp, rfl⟩ simp only [mem_degreeLT] refine lt_of_lt_of_le ?_ degree_le_natDegree exact degree_eraseLead_lt (ne_zero_of_ne_zero_of_monic one_ne_zero hp)⟩ invFun := fun p => ⟨X^n + p.1, monic_X_pow_add (mem_degreeLT.1 p.2), by rw [natDegree_add_eq_left_of_degree_lt] · simp · simp [mem_degreeLT.1 p.2]⟩ left_inv := by rintro ⟨p, hp, rfl⟩ ext1 simp only conv_rhs => rw [← eraseLead_add_C_mul_X_pow p] simp [Monic.def.1 hp, add_comm] right_inv := by rintro ⟨p, hp⟩ ext1 simp only rw [eraseLead_add_of_degree_lt_left] · simp · simp [mem_degreeLT.1 hp] /-- For every polynomial `p` in the span of a set `s : Set R[X]`, there exists a polynomial of `p' ∈ s` with higher degree. See also `Polynomial.exists_degree_le_of_mem_span_of_finite`. -/ theorem exists_degree_le_of_mem_span {s : Set R[X]} {p : R[X]} (hs : s.Nonempty) (hp : p ∈ Submodule.span R s) : ∃ p' ∈ s, degree p ≤ degree p' := by by_contra! h by_cases hp_zero : p = 0 · rw [hp_zero, degree_zero] at h rcases hs with ⟨x, hx⟩ exact not_lt_bot (h x hx) · have : p ∈ degreeLT R (natDegree p) := by refine (Submodule.span_le.mpr fun p' p'_mem => ?_) hp rw [SetLike.mem_coe, mem_degreeLT, Nat.cast_withBot] exact lt_of_lt_of_le (h p' p'_mem) degree_le_natDegree rwa [mem_degreeLT, Nat.cast_withBot, degree_eq_natDegree hp_zero, Nat.cast_withBot, lt_self_iff_false] at this /-- A stronger version of `Polynomial.exists_degree_le_of_mem_span` under the assumption that the set `s : R[X]` is finite. There exists a polynomial `p' ∈ s` whose degree dominates the degree of every element of `p ∈ span R s`. -/ theorem exists_degree_le_of_mem_span_of_finite {s : Set R[X]} (s_fin : s.Finite) (hs : s.Nonempty) : ∃ p' ∈ s, ∀ (p : R[X]), p ∈ Submodule.span R s → degree p ≤ degree p' := by rcases Set.Finite.exists_maximal_wrt degree s s_fin hs with ⟨a, has, hmax⟩ refine ⟨a, has, fun p hp => ?_⟩ rcases exists_degree_le_of_mem_span hs hp with ⟨p', hp'⟩ by_cases h : degree a ≤ degree p' · rw [← hmax p' hp'.left h] at hp'; exact hp'.right · exact le_trans hp'.right (not_le.mp h).le /-- The span of every finite set of polynomials is contained in a `degreeLE n` for some `n`. -/ theorem span_le_degreeLE_of_finite {s : Set R[X]} (s_fin : s.Finite) : ∃ n : ℕ, Submodule.span R s ≤ degreeLE R n := by by_cases s_emp : s.Nonempty · rcases exists_degree_le_of_mem_span_of_finite s_fin s_emp with ⟨p', _, hp'max⟩ exact ⟨natDegree p', fun p hp => mem_degreeLE.mpr ((hp'max _ hp).trans degree_le_natDegree)⟩ · rw [Set.not_nonempty_iff_eq_empty] at s_emp rw [s_emp, Submodule.span_empty] exact ⟨0, bot_le⟩ /-- The span of every finite set of polynomials is contained in a `degreeLT n` for some `n`. -/ theorem span_of_finite_le_degreeLT {s : Set R[X]} (s_fin : s.Finite) : ∃ n : ℕ, Submodule.span R s ≤ degreeLT R n := by rcases span_le_degreeLE_of_finite s_fin with ⟨n, _⟩ exact ⟨n + 1, by rwa [degreeLT_succ_eq_degreeLE]⟩ /-- If `R` is a nontrivial ring, the polynomials `R[X]` are not finite as an `R`-module. When `R` is a field, this is equivalent to `R[X]` being an infinite-dimensional vector space over `R`. -/ theorem not_finite [Nontrivial R] : ¬ Module.Finite R R[X] := by rw [Module.finite_def, Submodule.fg_def] push_neg intro s hs contra rcases span_le_degreeLE_of_finite hs with ⟨n,hn⟩ have : ((X : R[X]) ^ (n + 1)) ∈ Polynomial.degreeLE R ↑n := by rw [contra] at hn exact hn Submodule.mem_top rw [mem_degreeLE, degree_X_pow, Nat.cast_le, add_le_iff_nonpos_right, nonpos_iff_eq_zero] at this exact one_ne_zero this theorem geom_sum_X_comp_X_add_one_eq_sum (n : ℕ) : (∑ i ∈ range n, (X : R[X]) ^ i).comp (X + 1) = (Finset.range n).sum fun i : ℕ => (n.choose (i + 1) : R[X]) * X ^ i := by ext i trans (n.choose (i + 1) : R); swap · simp only [finset_sum_coeff, ← C_eq_natCast, coeff_C_mul_X_pow] rw [Finset.sum_eq_single i, if_pos rfl] · simp +contextual only [@eq_comm _ i, if_false, eq_self_iff_true, imp_true_iff] · simp +contextual only [Nat.lt_add_one_iff, Nat.choose_eq_zero_of_lt, Nat.cast_zero, Finset.mem_range, not_lt, eq_self_iff_true, if_true, imp_true_iff] induction' n with n ih generalizing i · dsimp; simp only [zero_comp, coeff_zero, Nat.cast_zero] · simp only [geom_sum_succ', ih, add_comp, X_pow_comp, coeff_add, Nat.choose_succ_succ, Nat.cast_add, coeff_X_add_one_pow] theorem Monic.geom_sum {P : R[X]} (hP : P.Monic) (hdeg : 0 < P.natDegree) {n : ℕ} (hn : n ≠ 0) : (∑ i ∈ range n, P ^ i).Monic := by nontriviality R obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn rw [geom_sum_succ'] refine (hP.pow _).add_of_left ?_
refine lt_of_le_of_lt (degree_sum_le _ _) ?_ rw [Finset.sup_lt_iff] · simp only [Finset.mem_range, degree_eq_natDegree (hP.pow _).ne_zero] simp only [Nat.cast_lt, hP.natDegree_pow]
Mathlib/RingTheory/Polynomial/Basic.lean
279
282
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Star.SelfAdjoint import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.LinearAlgebra.FreeModule.Finite.Basic /-! # Quaternions In this file we define quaternions `ℍ[R]` over a commutative ring `R`, and define some algebraic structures on `ℍ[R]`. ## Main definitions * `QuaternionAlgebra R a b c`, `ℍ[R, a, b, c]` : [Bourbaki, *Algebra I*][bourbaki1989] with coefficients `a`, `b`, `c` (Many other references such as Wikipedia assume $\operatorname{char} R ≠ 2$ therefore one can complete the square and WLOG assume $b = 0$.) * `Quaternion R`, `ℍ[R]` : the space of quaternions, a.k.a. `QuaternionAlgebra R (-1) (0) (-1)`; * `Quaternion.normSq` : square of the norm of a quaternion; We also define the following algebraic structures on `ℍ[R]`: * `Ring ℍ[R, a, b, c]`, `StarRing ℍ[R, a, b, c]`, and `Algebra R ℍ[R, a, b, c]` : for any commutative ring `R`; * `Ring ℍ[R]`, `StarRing ℍ[R]`, and `Algebra R ℍ[R]` : for any commutative ring `R`; * `IsDomain ℍ[R]` : for a linear ordered commutative ring `R`; * `DivisionRing ℍ[R]` : for a linear ordered field `R`. ## Notation The following notation is available with `open Quaternion` or `open scoped Quaternion`. * `ℍ[R, c₁, c₂, c₃]` : `QuaternionAlgebra R c₁ c₂ c₃` * `ℍ[R, c₁, c₂]` : `QuaternionAlgebra R c₁ 0 c₂` * `ℍ[R]` : quaternions over `R`. ## Implementation notes We define quaternions over any ring `R`, not just `ℝ` to be able to deal with, e.g., integer or rational quaternions without using real numbers. In particular, all definitions in this file are computable. ## Tags quaternion -/ /-- Quaternion algebra over a type with fixed coefficients where $i^2 = a + bi$ and $j^2 = c$, denoted as `ℍ[R,a,b]`. Implemented as a structure with four fields: `re`, `imI`, `imJ`, and `imK`. -/ @[ext] structure QuaternionAlgebra (R : Type*) (a b c : R) where /-- Real part of a quaternion. -/ re : R /-- First imaginary part (i) of a quaternion. -/ imI : R /-- Second imaginary part (j) of a quaternion. -/ imJ : R /-- Third imaginary part (k) of a quaternion. -/ imK : R @[inherit_doc] scoped[Quaternion] notation "ℍ[" R "," a "," b "," c "]" => QuaternionAlgebra R a b c @[inherit_doc] scoped[Quaternion] notation "ℍ[" R "," a "," b "]" => QuaternionAlgebra R a 0 b namespace QuaternionAlgebra open Quaternion /-- The equivalence between a quaternion algebra over `R` and `R × R × R × R`. -/ @[simps] def equivProd {R : Type*} (c₁ c₂ c₃ : R) : ℍ[R,c₁,c₂,c₃] ≃ R × R × R × R where toFun a := ⟨a.1, a.2, a.3, a.4⟩ invFun a := ⟨a.1, a.2.1, a.2.2.1, a.2.2.2⟩ left_inv _ := rfl right_inv _ := rfl /-- The equivalence between a quaternion algebra over `R` and `Fin 4 → R`. -/ @[simps symm_apply] def equivTuple {R : Type*} (c₁ c₂ c₃ : R) : ℍ[R,c₁,c₂,c₃] ≃ (Fin 4 → R) where toFun a := ![a.1, a.2, a.3, a.4] invFun a := ⟨a 0, a 1, a 2, a 3⟩ left_inv _ := rfl right_inv f := by ext ⟨_, _ | _ | _ | _ | _ | ⟨⟩⟩ <;> rfl @[simp] theorem equivTuple_apply {R : Type*} (c₁ c₂ c₃ : R) (x : ℍ[R,c₁,c₂,c₃]) : equivTuple c₁ c₂ c₃ x = ![x.re, x.imI, x.imJ, x.imK] := rfl @[simp] theorem mk.eta {R : Type*} {c₁ c₂ c₃} (a : ℍ[R,c₁,c₂,c₃]) : mk a.1 a.2 a.3 a.4 = a := rfl variable {S T R : Type*} {c₁ c₂ c₃ : R} (r x y : R) (a b : ℍ[R,c₁,c₂,c₃]) instance [Subsingleton R] : Subsingleton ℍ[R, c₁, c₂, c₃] := (equivTuple c₁ c₂ c₃).subsingleton instance [Nontrivial R] : Nontrivial ℍ[R, c₁, c₂, c₃] := (equivTuple c₁ c₂ c₃).surjective.nontrivial section Zero variable [Zero R] /-- The imaginary part of a quaternion. Note that unless `c₂ = 0`, this definition is not particularly well-behaved; for instance, `QuaternionAlgebra.star_im` only says that the star of an imaginary quaternion is imaginary under this condition. -/ def im (x : ℍ[R,c₁,c₂,c₃]) : ℍ[R,c₁,c₂,c₃] := ⟨0, x.imI, x.imJ, x.imK⟩ @[simp] theorem im_re : a.im.re = 0 := rfl @[simp] theorem im_imI : a.im.imI = a.imI := rfl @[simp] theorem im_imJ : a.im.imJ = a.imJ := rfl @[simp] theorem im_imK : a.im.imK = a.imK := rfl @[simp] theorem im_idem : a.im.im = a.im := rfl /-- Coercion `R → ℍ[R,c₁,c₂,c₃]`. -/ @[coe] def coe (x : R) : ℍ[R,c₁,c₂,c₃] := ⟨x, 0, 0, 0⟩ instance : CoeTC R ℍ[R,c₁,c₂,c₃] := ⟨coe⟩ @[simp, norm_cast] theorem coe_re : (x : ℍ[R,c₁,c₂,c₃]).re = x := rfl @[simp, norm_cast] theorem coe_imI : (x : ℍ[R,c₁,c₂,c₃]).imI = 0 := rfl @[simp, norm_cast] theorem coe_imJ : (x : ℍ[R,c₁,c₂,c₃]).imJ = 0 := rfl @[simp, norm_cast] theorem coe_imK : (x : ℍ[R,c₁,c₂,c₃]).imK = 0 := rfl theorem coe_injective : Function.Injective (coe : R → ℍ[R,c₁,c₂,c₃]) := fun _ _ h => congr_arg re h @[simp] theorem coe_inj {x y : R} : (x : ℍ[R,c₁,c₂,c₃]) = y ↔ x = y := coe_injective.eq_iff -- Porting note: removed `simps`, added simp lemmas manually. -- Should adjust `simps` to name properly, i.e. as `zero_re` rather than `instZero_zero_re`. instance : Zero ℍ[R,c₁,c₂,c₃] := ⟨⟨0, 0, 0, 0⟩⟩ @[scoped simp] theorem zero_re : (0 : ℍ[R,c₁,c₂,c₃]).re = 0 := rfl @[scoped simp] theorem zero_imI : (0 : ℍ[R,c₁,c₂,c₃]).imI = 0 := rfl @[scoped simp] theorem zero_imJ : (0 : ℍ[R,c₁,c₂,c₃]).imJ = 0 := rfl @[scoped simp] theorem zero_imK : (0 : ℍ[R,c₁,c₂,c₃]).imK = 0 := rfl @[scoped simp] theorem zero_im : (0 : ℍ[R,c₁,c₂,c₃]).im = 0 := rfl @[simp, norm_cast] theorem coe_zero : ((0 : R) : ℍ[R,c₁,c₂,c₃]) = 0 := rfl instance : Inhabited ℍ[R,c₁,c₂,c₃] := ⟨0⟩ section One variable [One R] -- Porting note: removed `simps`, added simp lemmas manually. Should adjust `simps` to name properly instance : One ℍ[R,c₁,c₂,c₃] := ⟨⟨1, 0, 0, 0⟩⟩ @[scoped simp] theorem one_re : (1 : ℍ[R,c₁,c₂,c₃]).re = 1 := rfl @[scoped simp] theorem one_imI : (1 : ℍ[R,c₁,c₂,c₃]).imI = 0 := rfl @[scoped simp] theorem one_imJ : (1 : ℍ[R,c₁,c₂,c₃]).imJ = 0 := rfl @[scoped simp] theorem one_imK : (1 : ℍ[R,c₁,c₂,c₃]).imK = 0 := rfl @[scoped simp] theorem one_im : (1 : ℍ[R,c₁,c₂,c₃]).im = 0 := rfl @[simp, norm_cast] theorem coe_one : ((1 : R) : ℍ[R,c₁,c₂,c₃]) = 1 := rfl end One end Zero section Add variable [Add R] -- Porting note: removed `simps`, added simp lemmas manually. Should adjust `simps` to name properly instance : Add ℍ[R,c₁,c₂,c₃] := ⟨fun a b => ⟨a.1 + b.1, a.2 + b.2, a.3 + b.3, a.4 + b.4⟩⟩ @[simp] theorem add_re : (a + b).re = a.re + b.re := rfl @[simp] theorem add_imI : (a + b).imI = a.imI + b.imI := rfl @[simp] theorem add_imJ : (a + b).imJ = a.imJ + b.imJ := rfl @[simp] theorem add_imK : (a + b).imK = a.imK + b.imK := rfl @[simp] theorem mk_add_mk (a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ : R) : (mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂,c₃]) + mk b₁ b₂ b₃ b₄ = mk (a₁ + b₁) (a₂ + b₂) (a₃ + b₃) (a₄ + b₄) := rfl end Add section AddZeroClass variable [AddZeroClass R] @[simp] theorem add_im : (a + b).im = a.im + b.im := QuaternionAlgebra.ext (zero_add _).symm rfl rfl rfl @[simp, norm_cast] theorem coe_add : ((x + y : R) : ℍ[R,c₁,c₂,c₃]) = x + y := by ext <;> simp end AddZeroClass section Neg variable [Neg R] -- Porting note: removed `simps`, added simp lemmas manually. Should adjust `simps` to name properly instance : Neg ℍ[R,c₁,c₂,c₃] := ⟨fun a => ⟨-a.1, -a.2, -a.3, -a.4⟩⟩ @[simp] theorem neg_re : (-a).re = -a.re := rfl @[simp] theorem neg_imI : (-a).imI = -a.imI := rfl @[simp] theorem neg_imJ : (-a).imJ = -a.imJ := rfl @[simp] theorem neg_imK : (-a).imK = -a.imK := rfl @[simp] theorem neg_mk (a₁ a₂ a₃ a₄ : R) : -(mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂,c₃]) = ⟨-a₁, -a₂, -a₃, -a₄⟩ := rfl end Neg section AddGroup variable [AddGroup R] @[simp] theorem neg_im : (-a).im = -a.im := QuaternionAlgebra.ext neg_zero.symm rfl rfl rfl @[simp, norm_cast] theorem coe_neg : ((-x : R) : ℍ[R,c₁,c₂,c₃]) = -x := by ext <;> simp instance : Sub ℍ[R,c₁,c₂,c₃] := ⟨fun a b => ⟨a.1 - b.1, a.2 - b.2, a.3 - b.3, a.4 - b.4⟩⟩ @[simp] theorem sub_re : (a - b).re = a.re - b.re := rfl @[simp] theorem sub_imI : (a - b).imI = a.imI - b.imI := rfl @[simp] theorem sub_imJ : (a - b).imJ = a.imJ - b.imJ := rfl @[simp] theorem sub_imK : (a - b).imK = a.imK - b.imK := rfl @[simp] theorem sub_im : (a - b).im = a.im - b.im := QuaternionAlgebra.ext (sub_zero _).symm rfl rfl rfl @[simp] theorem mk_sub_mk (a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ : R) : (mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂,c₃]) - mk b₁ b₂ b₃ b₄ = mk (a₁ - b₁) (a₂ - b₂) (a₃ - b₃) (a₄ - b₄) := rfl @[simp, norm_cast] theorem coe_im : (x : ℍ[R,c₁,c₂,c₃]).im = 0 := rfl @[simp] theorem re_add_im : ↑a.re + a.im = a := QuaternionAlgebra.ext (add_zero _) (zero_add _) (zero_add _) (zero_add _) @[simp] theorem sub_self_im : a - a.im = a.re := QuaternionAlgebra.ext (sub_zero _) (sub_self _) (sub_self _) (sub_self _) @[simp] theorem sub_self_re : a - a.re = a.im := QuaternionAlgebra.ext (sub_self _) (sub_zero _) (sub_zero _) (sub_zero _) end AddGroup section Ring variable [Ring R] /-- Multiplication is given by * `1 * x = x * 1 = x`; * `i * i = c₁ + c₂ * i`; * `j * j = c₃`; * `i * j = k`, `j * i = c₂ * j - k`; * `k * k = - c₁ * c₃`; * `i * k = c₁ * j + c₂ * k`, `k * i = -c₁ * j`; * `j * k = c₂ * c₃ - c₃ * i`, `k * j = c₃ * i`. -/ instance : Mul ℍ[R,c₁,c₂,c₃] := ⟨fun a b => ⟨a.1 * b.1 + c₁ * a.2 * b.2 + c₃ * a.3 * b.3 + c₂ * c₃ * a.3 * b.4 - c₁ * c₃ * a.4 * b.4, a.1 * b.2 + a.2 * b.1 + c₂ * a.2 * b.2 - c₃ * a.3 * b.4 + c₃ * a.4 * b.3, a.1 * b.3 + c₁ * a.2 * b.4 + a.3 * b.1 + c₂ * a.3 * b.2 - c₁ * a.4 * b.2, a.1 * b.4 + a.2 * b.3 + c₂ * a.2 * b.4 - a.3 * b.2 + a.4 * b.1⟩⟩ @[simp] theorem mul_re : (a * b).re = a.1 * b.1 + c₁ * a.2 * b.2 + c₃ * a.3 * b.3 + c₂ * c₃ * a.3 * b.4 - c₁ * c₃ * a.4 * b.4 := rfl @[simp] theorem mul_imI : (a * b).imI = a.1 * b.2 + a.2 * b.1 + c₂ * a.2 * b.2 - c₃ * a.3 * b.4 + c₃ * a.4 * b.3 := rfl @[simp] theorem mul_imJ : (a * b).imJ = a.1 * b.3 + c₁ * a.2 * b.4 + a.3 * b.1 + c₂ * a.3 * b.2 - c₁ * a.4 * b.2 := rfl @[simp] theorem mul_imK : (a * b).imK = a.1 * b.4 + a.2 * b.3 + c₂ * a.2 * b.4 - a.3 * b.2 + a.4 * b.1 := rfl @[simp] theorem mk_mul_mk (a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ : R) : (mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂,c₃]) * mk b₁ b₂ b₃ b₄ = mk (a₁ * b₁ + c₁ * a₂ * b₂ + c₃ * a₃ * b₃ + c₂ * c₃ * a₃ * b₄ - c₁ * c₃ * a₄ * b₄) (a₁ * b₂ + a₂ * b₁ + c₂ * a₂ * b₂ - c₃ * a₃ * b₄ + c₃ * a₄ * b₃) (a₁ * b₃ + c₁ * a₂ * b₄ + a₃ * b₁ + c₂ * a₃ * b₂ - c₁ * a₄ * b₂) (a₁ * b₄ + a₂ * b₃ + c₂ * a₂ * b₄ - a₃ * b₂ + a₄ * b₁) := rfl end Ring section SMul variable [SMul S R] [SMul T R] (s : S) instance : SMul S ℍ[R,c₁,c₂,c₃] where smul s a := ⟨s • a.1, s • a.2, s • a.3, s • a.4⟩ instance [SMul S T] [IsScalarTower S T R] : IsScalarTower S T ℍ[R,c₁,c₂,c₃] where smul_assoc s t x := by ext <;> exact smul_assoc _ _ _ instance [SMulCommClass S T R] : SMulCommClass S T ℍ[R,c₁,c₂,c₃] where smul_comm s t x := by ext <;> exact smul_comm _ _ _ @[simp] theorem smul_re : (s • a).re = s • a.re := rfl @[simp] theorem smul_imI : (s • a).imI = s • a.imI := rfl @[simp] theorem smul_imJ : (s • a).imJ = s • a.imJ := rfl @[simp] theorem smul_imK : (s • a).imK = s • a.imK := rfl @[simp] theorem smul_im {S} [CommRing R] [SMulZeroClass S R] (s : S) : (s • a).im = s • a.im := QuaternionAlgebra.ext (smul_zero s).symm rfl rfl rfl @[simp] theorem smul_mk (re im_i im_j im_k : R) : s • (⟨re, im_i, im_j, im_k⟩ : ℍ[R,c₁,c₂,c₃]) = ⟨s • re, s • im_i, s • im_j, s • im_k⟩ := rfl end SMul @[simp, norm_cast] theorem coe_smul [Zero R] [SMulZeroClass S R] (s : S) (r : R) : (↑(s • r) : ℍ[R,c₁,c₂,c₃]) = s • (r : ℍ[R,c₁,c₂,c₃]) := QuaternionAlgebra.ext rfl (smul_zero _).symm (smul_zero _).symm (smul_zero _).symm instance [AddCommGroup R] : AddCommGroup ℍ[R,c₁,c₂,c₃] := (equivProd c₁ c₂ c₃).injective.addCommGroup _ rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) section AddCommGroupWithOne variable [AddCommGroupWithOne R] instance : AddCommGroupWithOne ℍ[R,c₁,c₂,c₃] where natCast n := ((n : R) : ℍ[R,c₁,c₂,c₃]) natCast_zero := by simp natCast_succ := by simp intCast n := ((n : R) : ℍ[R,c₁,c₂,c₃]) intCast_ofNat _ := congr_arg coe (Int.cast_natCast _) intCast_negSucc n := by change coe _ = -coe _ rw [Int.cast_negSucc, coe_neg] @[simp, norm_cast] theorem natCast_re (n : ℕ) : (n : ℍ[R,c₁,c₂,c₃]).re = n := rfl @[simp, norm_cast] theorem natCast_imI (n : ℕ) : (n : ℍ[R,c₁,c₂,c₃]).imI = 0 := rfl @[simp, norm_cast] theorem natCast_imJ (n : ℕ) : (n : ℍ[R,c₁,c₂,c₃]).imJ = 0 := rfl @[simp, norm_cast] theorem natCast_imK (n : ℕ) : (n : ℍ[R,c₁,c₂,c₃]).imK = 0 := rfl @[simp, norm_cast] theorem natCast_im (n : ℕ) : (n : ℍ[R,c₁,c₂,c₃]).im = 0 := rfl @[norm_cast] theorem coe_natCast (n : ℕ) : ↑(n : R) = (n : ℍ[R,c₁,c₂,c₃]) := rfl @[simp, norm_cast] theorem intCast_re (z : ℤ) : (z : ℍ[R,c₁,c₂,c₃]).re = z := rfl @[scoped simp] theorem ofNat_re (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℍ[R,c₁,c₂,c₃]).re = ofNat(n) := rfl @[scoped simp] theorem ofNat_imI (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℍ[R,c₁,c₂,c₃]).imI = 0 := rfl @[scoped simp] theorem ofNat_imJ (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℍ[R,c₁,c₂,c₃]).imJ = 0 := rfl @[scoped simp] theorem ofNat_imK (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℍ[R,c₁,c₂,c₃]).imK = 0 := rfl @[scoped simp] theorem ofNat_im (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℍ[R,c₁,c₂,c₃]).im = 0 := rfl @[simp, norm_cast] theorem intCast_imI (z : ℤ) : (z : ℍ[R,c₁,c₂,c₃]).imI = 0 := rfl @[simp, norm_cast] theorem intCast_imJ (z : ℤ) : (z : ℍ[R,c₁,c₂,c₃]).imJ = 0 := rfl @[simp, norm_cast] theorem intCast_imK (z : ℤ) : (z : ℍ[R,c₁,c₂,c₃]).imK = 0 := rfl @[simp, norm_cast] theorem intCast_im (z : ℤ) : (z : ℍ[R,c₁,c₂,c₃]).im = 0 := rfl @[norm_cast] theorem coe_intCast (z : ℤ) : ↑(z : R) = (z : ℍ[R,c₁,c₂,c₃]) := rfl end AddCommGroupWithOne -- For the remainder of the file we assume `CommRing R`. variable [CommRing R] instance instRing : Ring ℍ[R,c₁,c₂,c₃] where __ := inferInstanceAs (AddCommGroupWithOne ℍ[R,c₁,c₂,c₃]) left_distrib _ _ _ := by ext <;> simp <;> ring right_distrib _ _ _ := by ext <;> simp <;> ring zero_mul _ := by ext <;> simp mul_zero _ := by ext <;> simp mul_assoc _ _ _ := by ext <;> simp <;> ring one_mul _ := by ext <;> simp mul_one _ := by ext <;> simp @[norm_cast, simp] theorem coe_mul : ((x * y : R) : ℍ[R,c₁,c₂,c₃]) = x * y := by ext <;> simp @[norm_cast, simp] lemma coe_ofNat {n : ℕ} [n.AtLeastTwo]: ((ofNat(n) : R) : ℍ[R,c₁,c₂,c₃]) = (ofNat(n) : ℍ[R,c₁,c₂,c₃]) := by rfl -- TODO: add weaker `MulAction`, `DistribMulAction`, and `Module` instances (and repeat them -- for `ℍ[R]`) instance [CommSemiring S] [Algebra S R] : Algebra S ℍ[R,c₁,c₂,c₃] where smul := (· • ·) algebraMap := { toFun s := coe (algebraMap S R s) map_one' := by simp only [map_one, coe_one] map_zero' := by simp only [map_zero, coe_zero] map_mul' x y := by simp only [map_mul, coe_mul] map_add' x y := by simp only [map_add, coe_add] } smul_def' s x := by ext <;> simp [Algebra.smul_def] commutes' s x := by ext <;> simp [Algebra.commutes] theorem algebraMap_eq (r : R) : algebraMap R ℍ[R,c₁,c₂,c₃] r = ⟨r, 0, 0, 0⟩ := rfl theorem algebraMap_injective : (algebraMap R ℍ[R,c₁,c₂,c₃] : _ → _).Injective := fun _ _ ↦ by simp [algebraMap_eq] instance [NoZeroDivisors R] : NoZeroSMulDivisors R ℍ[R,c₁,c₂,c₃] := ⟨by rintro t ⟨a, b, c, d⟩ h rw [or_iff_not_imp_left] intro ht simpa [QuaternionAlgebra.ext_iff, ht] using h⟩ section variable (c₁ c₂ c₃) /-- `QuaternionAlgebra.re` as a `LinearMap` -/ @[simps] def reₗ : ℍ[R,c₁,c₂,c₃] →ₗ[R] R where toFun := re map_add' _ _ := rfl map_smul' _ _ := rfl /-- `QuaternionAlgebra.imI` as a `LinearMap` -/ @[simps] def imIₗ : ℍ[R,c₁,c₂,c₃] →ₗ[R] R where toFun := imI map_add' _ _ := rfl map_smul' _ _ := rfl /-- `QuaternionAlgebra.imJ` as a `LinearMap` -/ @[simps] def imJₗ : ℍ[R,c₁,c₂,c₃] →ₗ[R] R where toFun := imJ map_add' _ _ := rfl map_smul' _ _ := rfl /-- `QuaternionAlgebra.imK` as a `LinearMap` -/ @[simps] def imKₗ : ℍ[R,c₁,c₂,c₃] →ₗ[R] R where toFun := imK map_add' _ _ := rfl map_smul' _ _ := rfl /-- `QuaternionAlgebra.equivTuple` as a linear equivalence. -/ def linearEquivTuple : ℍ[R,c₁,c₂,c₃] ≃ₗ[R] Fin 4 → R := LinearEquiv.symm -- proofs are not `rfl` in the forward direction { (equivTuple c₁ c₂ c₃).symm with toFun := (equivTuple c₁ c₂ c₃).symm invFun := equivTuple c₁ c₂ c₃ map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } @[simp] theorem coe_linearEquivTuple : ⇑(linearEquivTuple c₁ c₂ c₃) = equivTuple c₁ c₂ c₃ := rfl @[simp] theorem coe_linearEquivTuple_symm : ⇑(linearEquivTuple c₁ c₂ c₃).symm = (equivTuple c₁ c₂ c₃).symm := rfl /-- `ℍ[R, c₁, c₂, c₃]` has a basis over `R` given by `1`, `i`, `j`, and `k`. -/ noncomputable def basisOneIJK : Basis (Fin 4) R ℍ[R,c₁,c₂,c₃] := .ofEquivFun <| linearEquivTuple c₁ c₂ c₃ @[simp] theorem coe_basisOneIJK_repr (q : ℍ[R,c₁,c₂,c₃]) : ((basisOneIJK c₁ c₂ c₃).repr q) = ![q.re, q.imI, q.imJ, q.imK] := rfl instance : Module.Finite R ℍ[R,c₁,c₂,c₃] := .of_basis (basisOneIJK c₁ c₂ c₃) instance : Module.Free R ℍ[R,c₁,c₂,c₃] := .of_basis (basisOneIJK c₁ c₂ c₃) theorem rank_eq_four [StrongRankCondition R] : Module.rank R ℍ[R,c₁,c₂,c₃] = 4 := by rw [rank_eq_card_basis (basisOneIJK c₁ c₂ c₃), Fintype.card_fin] norm_num theorem finrank_eq_four [StrongRankCondition R] : Module.finrank R ℍ[R,c₁,c₂,c₃] = 4 := by rw [Module.finrank, rank_eq_four, Cardinal.toNat_ofNat] /-- There is a natural equivalence when swapping the first and third coefficients of a quaternion algebra if `c₂` is 0. -/ @[simps] def swapEquiv : ℍ[R,c₁,0,c₃] ≃ₐ[R] ℍ[R,c₃,0,c₁] where toFun t := ⟨t.1, t.3, t.2, -t.4⟩ invFun t := ⟨t.1, t.3, t.2, -t.4⟩ left_inv _ := by simp right_inv _ := by simp map_mul' _ _ := by ext <;> simp <;> ring map_add' _ _ := by ext <;> simp [add_comm] commutes' _ := by simp [algebraMap_eq] end @[norm_cast, simp] theorem coe_sub : ((x - y : R) : ℍ[R,c₁,c₂,c₃]) = x - y := (algebraMap R ℍ[R,c₁,c₂,c₃]).map_sub x y @[norm_cast, simp] theorem coe_pow (n : ℕ) : (↑(x ^ n) : ℍ[R,c₁,c₂,c₃]) = (x : ℍ[R,c₁,c₂,c₃]) ^ n := (algebraMap R ℍ[R,c₁,c₂,c₃]).map_pow x n theorem coe_commutes : ↑r * a = a * r := Algebra.commutes r a theorem coe_commute : Commute (↑r) a := coe_commutes r a theorem coe_mul_eq_smul : ↑r * a = r • a := (Algebra.smul_def r a).symm theorem mul_coe_eq_smul : a * r = r • a := by rw [← coe_commutes, coe_mul_eq_smul] @[norm_cast, simp] theorem coe_algebraMap : ⇑(algebraMap R ℍ[R,c₁,c₂,c₃]) = coe := rfl theorem smul_coe : x • (y : ℍ[R,c₁,c₂,c₃]) = ↑(x * y) := by rw [coe_mul, coe_mul_eq_smul] /-- Quaternion conjugate. -/ instance instStarQuaternionAlgebra : Star ℍ[R,c₁,c₂,c₃] where star a := ⟨a.1 + c₂ * a.2, -a.2, -a.3, -a.4⟩ @[simp] theorem re_star : (star a).re = a.re + c₂ * a.imI := rfl @[simp] theorem imI_star : (star a).imI = -a.imI := rfl @[simp] theorem imJ_star : (star a).imJ = -a.imJ := rfl @[simp] theorem imK_star : (star a).imK = -a.imK := rfl @[simp] theorem im_star : (star a).im = -a.im := QuaternionAlgebra.ext neg_zero.symm rfl rfl rfl @[simp] theorem star_mk (a₁ a₂ a₃ a₄ : R) : star (mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂,c₃]) = ⟨a₁ + c₂ * a₂, -a₂, -a₃, -a₄⟩ := rfl instance instStarRing : StarRing ℍ[R,c₁,c₂,c₃] where star_involutive x := by simp [Star.star] star_add a b := by ext <;> simp [add_comm] ; ring star_mul a b := by ext <;> simp <;> ring theorem self_add_star' : a + star a = ↑(2 * a.re + c₂ * a.imI) := by ext <;> simp [two_mul]; ring theorem self_add_star : a + star a = 2 * a.re + c₂ * a.imI := by simp [self_add_star'] theorem star_add_self' : star a + a = ↑(2 * a.re + c₂ * a.imI) := by rw [add_comm, self_add_star'] theorem star_add_self : star a + a = 2 * a.re + c₂ * a.imI := by rw [add_comm, self_add_star] theorem star_eq_two_re_sub : star a = ↑(2 * a.re + c₂ * a.imI) - a := eq_sub_iff_add_eq.2 a.star_add_self' lemma comm (r : R) (x : ℍ[R, c₁, c₂, c₃]) : r * x = x * r := by ext <;> simp [mul_comm] instance : IsStarNormal a := ⟨by rw [commute_iff_eq, a.star_eq_two_re_sub]; ext <;> simp <;> ring⟩ @[simp, norm_cast] theorem star_coe : star (x : ℍ[R,c₁,c₂,c₃]) = x := by ext <;> simp @[simp] theorem star_im : star a.im = -a.im + c₂ * a.imI := by ext <;> simp @[simp] theorem star_smul [Monoid S] [DistribMulAction S R] [SMulCommClass S R R] (s : S) (a : ℍ[R,c₁,c₂,c₃]) : star (s • a) = s • star a := QuaternionAlgebra.ext (by simp [mul_smul_comm]) (smul_neg _ _).symm (smul_neg _ _).symm (smul_neg _ _).symm /-- A version of `star_smul` for the special case when `c₂ = 0`, without `SMulCommClass S R R`. -/ theorem star_smul' [Monoid S] [DistribMulAction S R] (s : S) (a : ℍ[R,c₁,0,c₃]) : star (s • a) = s • star a := QuaternionAlgebra.ext (by simp) (smul_neg _ _).symm (smul_neg _ _).symm (smul_neg _ _).symm theorem eq_re_of_eq_coe {a : ℍ[R,c₁,c₂,c₃]} {x : R} (h : a = x) : a = a.re := by rw [h, coe_re] theorem eq_re_iff_mem_range_coe {a : ℍ[R,c₁,c₂,c₃]} : a = a.re ↔ a ∈ Set.range (coe : R → ℍ[R,c₁,c₂,c₃]) := ⟨fun h => ⟨a.re, h.symm⟩, fun ⟨_, h⟩ => eq_re_of_eq_coe h.symm⟩ section CharZero variable [NoZeroDivisors R] [CharZero R] @[simp] theorem star_eq_self {c₁ c₂ : R} {a : ℍ[R,c₁,c₂,c₃]} : star a = a ↔ a = a.re := by simp_all [QuaternionAlgebra.ext_iff, neg_eq_iff_add_eq_zero, add_self_eq_zero] theorem star_eq_neg {c₁ : R} {a : ℍ[R,c₁,0,c₃]} : star a = -a ↔ a.re = 0 := by simp [QuaternionAlgebra.ext_iff, eq_neg_iff_add_eq_zero] end CharZero -- Can't use `rw ← star_eq_self` in the proof without additional assumptions theorem star_mul_eq_coe : star a * a = (star a * a).re := by ext <;> simp <;> ring theorem mul_star_eq_coe : a * star a = (a * star a).re := by rw [← star_comm_self'] exact a.star_mul_eq_coe open MulOpposite /-- Quaternion conjugate as an `AlgEquiv` to the opposite ring. -/ def starAe : ℍ[R,c₁,c₂,c₃] ≃ₐ[R] ℍ[R,c₁,c₂,c₃]ᵐᵒᵖ := { starAddEquiv.trans opAddEquiv with toFun := op ∘ star invFun := star ∘ unop map_mul' := fun x y => by simp commutes' := fun r => by simp } @[simp] theorem coe_starAe : ⇑(starAe : ℍ[R,c₁,c₂,c₃] ≃ₐ[R] _) = op ∘ star := rfl end QuaternionAlgebra /-- Space of quaternions over a type, denoted as `ℍ[R]`. Implemented as a structure with four fields: `re`, `im_i`, `im_j`, and `im_k`. -/ def Quaternion (R : Type*) [Zero R] [One R] [Neg R] := QuaternionAlgebra R (-1) (0) (-1) @[inherit_doc] scoped[Quaternion] notation "ℍ[" R "]" => Quaternion R open Quaternion /-- The equivalence between the quaternions over `R` and `R × R × R × R`. -/ @[simps!] def Quaternion.equivProd (R : Type*) [Zero R] [One R] [Neg R] : ℍ[R] ≃ R × R × R × R := QuaternionAlgebra.equivProd _ _ _ /-- The equivalence between the quaternions over `R` and `Fin 4 → R`. -/ @[simps! symm_apply] def Quaternion.equivTuple (R : Type*) [Zero R] [One R] [Neg R] : ℍ[R] ≃ (Fin 4 → R) := QuaternionAlgebra.equivTuple _ _ _ @[simp] theorem Quaternion.equivTuple_apply (R : Type*) [Zero R] [One R] [Neg R] (x : ℍ[R]) : Quaternion.equivTuple R x = ![x.re, x.imI, x.imJ, x.imK] := rfl instance {R : Type*} [Zero R] [One R] [Neg R] [Subsingleton R] : Subsingleton ℍ[R] := inferInstanceAs (Subsingleton <| ℍ[R, -1, 0, -1]) instance {R : Type*} [Zero R] [One R] [Neg R] [Nontrivial R] : Nontrivial ℍ[R] := inferInstanceAs (Nontrivial <| ℍ[R, -1, 0, -1]) namespace Quaternion variable {S T R : Type*} [CommRing R] (r x y : R) (a b : ℍ[R]) /-- Coercion `R → ℍ[R]`. -/ @[coe] def coe : R → ℍ[R] := QuaternionAlgebra.coe instance : CoeTC R ℍ[R] := ⟨coe⟩ instance instRing : Ring ℍ[R] := QuaternionAlgebra.instRing instance : Inhabited ℍ[R] := inferInstanceAs <| Inhabited ℍ[R,-1, 0, -1] instance [SMul S R] : SMul S ℍ[R] := inferInstanceAs <| SMul S ℍ[R,-1, 0, -1] instance [SMul S T] [SMul S R] [SMul T R] [IsScalarTower S T R] : IsScalarTower S T ℍ[R] := inferInstanceAs <| IsScalarTower S T ℍ[R,-1,0,-1] instance [SMul S R] [SMul T R] [SMulCommClass S T R] : SMulCommClass S T ℍ[R] := inferInstanceAs <| SMulCommClass S T ℍ[R,-1,0,-1] protected instance algebra [CommSemiring S] [Algebra S R] : Algebra S ℍ[R] := inferInstanceAs <| Algebra S ℍ[R,-1,0,-1] instance : Star ℍ[R] := QuaternionAlgebra.instStarQuaternionAlgebra instance : StarRing ℍ[R] := QuaternionAlgebra.instStarRing instance : IsStarNormal a := inferInstanceAs <| IsStarNormal (R := ℍ[R,-1,0,-1]) a @[ext] theorem ext : a.re = b.re → a.imI = b.imI → a.imJ = b.imJ → a.imK = b.imK → a = b := QuaternionAlgebra.ext /-- The imaginary part of a quaternion. -/ nonrec def im (x : ℍ[R]) : ℍ[R] := x.im @[simp] theorem im_re : a.im.re = 0 := rfl @[simp] theorem im_imI : a.im.imI = a.imI := rfl @[simp] theorem im_imJ : a.im.imJ = a.imJ := rfl @[simp] theorem im_imK : a.im.imK = a.imK := rfl @[simp] theorem im_idem : a.im.im = a.im := rfl @[simp] nonrec theorem re_add_im : ↑a.re + a.im = a := a.re_add_im @[simp] nonrec theorem sub_self_im : a - a.im = a.re := a.sub_self_im @[simp] nonrec theorem sub_self_re : a - ↑a.re = a.im := a.sub_self_re @[simp, norm_cast] theorem coe_re : (x : ℍ[R]).re = x := rfl @[simp, norm_cast] theorem coe_imI : (x : ℍ[R]).imI = 0 := rfl @[simp, norm_cast] theorem coe_imJ : (x : ℍ[R]).imJ = 0 := rfl @[simp, norm_cast] theorem coe_imK : (x : ℍ[R]).imK = 0 := rfl @[simp, norm_cast] theorem coe_im : (x : ℍ[R]).im = 0 := rfl @[scoped simp] theorem zero_re : (0 : ℍ[R]).re = 0 := rfl @[scoped simp] theorem zero_imI : (0 : ℍ[R]).imI = 0 := rfl @[scoped simp] theorem zero_imJ : (0 : ℍ[R]).imJ = 0 := rfl @[scoped simp] theorem zero_imK : (0 : ℍ[R]).imK = 0 := rfl @[scoped simp] theorem zero_im : (0 : ℍ[R]).im = 0 := rfl @[simp, norm_cast] theorem coe_zero : ((0 : R) : ℍ[R]) = 0 := rfl @[scoped simp] theorem one_re : (1 : ℍ[R]).re = 1 := rfl @[scoped simp] theorem one_imI : (1 : ℍ[R]).imI = 0 := rfl @[scoped simp] theorem one_imJ : (1 : ℍ[R]).imJ = 0 := rfl @[scoped simp] theorem one_imK : (1 : ℍ[R]).imK = 0 := rfl @[scoped simp] theorem one_im : (1 : ℍ[R]).im = 0 := rfl @[simp, norm_cast] theorem coe_one : ((1 : R) : ℍ[R]) = 1 := rfl @[simp] theorem add_re : (a + b).re = a.re + b.re := rfl @[simp] theorem add_imI : (a + b).imI = a.imI + b.imI := rfl @[simp] theorem add_imJ : (a + b).imJ = a.imJ + b.imJ := rfl @[simp] theorem add_imK : (a + b).imK = a.imK + b.imK := rfl @[simp] nonrec theorem add_im : (a + b).im = a.im + b.im := a.add_im b @[simp, norm_cast] theorem coe_add : ((x + y : R) : ℍ[R]) = x + y := QuaternionAlgebra.coe_add x y @[simp] theorem neg_re : (-a).re = -a.re := rfl @[simp] theorem neg_imI : (-a).imI = -a.imI := rfl @[simp] theorem neg_imJ : (-a).imJ = -a.imJ := rfl @[simp] theorem neg_imK : (-a).imK = -a.imK := rfl @[simp] nonrec theorem neg_im : (-a).im = -a.im := a.neg_im @[simp, norm_cast] theorem coe_neg : ((-x : R) : ℍ[R]) = -x := QuaternionAlgebra.coe_neg x @[simp] theorem sub_re : (a - b).re = a.re - b.re := rfl @[simp] theorem sub_imI : (a - b).imI = a.imI - b.imI := rfl @[simp] theorem sub_imJ : (a - b).imJ = a.imJ - b.imJ := rfl @[simp] theorem sub_imK : (a - b).imK = a.imK - b.imK := rfl @[simp] nonrec theorem sub_im : (a - b).im = a.im - b.im := a.sub_im b @[simp, norm_cast] theorem coe_sub : ((x - y : R) : ℍ[R]) = x - y := QuaternionAlgebra.coe_sub x y @[simp] theorem mul_re : (a * b).re = a.re * b.re - a.imI * b.imI - a.imJ * b.imJ - a.imK * b.imK := (QuaternionAlgebra.mul_re a b).trans <| by simp [one_mul, neg_mul, sub_eq_add_neg, neg_neg] @[simp] theorem mul_imI : (a * b).imI = a.re * b.imI + a.imI * b.re + a.imJ * b.imK - a.imK * b.imJ := (QuaternionAlgebra.mul_imI a b).trans <| by ring @[simp] theorem mul_imJ : (a * b).imJ = a.re * b.imJ - a.imI * b.imK + a.imJ * b.re + a.imK * b.imI := (QuaternionAlgebra.mul_imJ a b).trans <| by ring @[simp] theorem mul_imK : (a * b).imK = a.re * b.imK + a.imI * b.imJ - a.imJ * b.imI + a.imK * b.re := (QuaternionAlgebra.mul_imK a b).trans <| by ring @[simp, norm_cast] theorem coe_mul : ((x * y : R) : ℍ[R]) = x * y := QuaternionAlgebra.coe_mul x y @[norm_cast, simp] theorem coe_pow (n : ℕ) : (↑(x ^ n) : ℍ[R]) = (x : ℍ[R]) ^ n := QuaternionAlgebra.coe_pow x n @[simp, norm_cast] theorem natCast_re (n : ℕ) : (n : ℍ[R]).re = n := rfl @[simp, norm_cast] theorem natCast_imI (n : ℕ) : (n : ℍ[R]).imI = 0 := rfl @[simp, norm_cast] theorem natCast_imJ (n : ℕ) : (n : ℍ[R]).imJ = 0 := rfl @[simp, norm_cast] theorem natCast_imK (n : ℕ) : (n : ℍ[R]).imK = 0 := rfl @[simp, norm_cast] theorem natCast_im (n : ℕ) : (n : ℍ[R]).im = 0 := rfl @[norm_cast] theorem coe_natCast (n : ℕ) : ↑(n : R) = (n : ℍ[R]) := rfl @[simp, norm_cast] theorem intCast_re (z : ℤ) : (z : ℍ[R]).re = z := rfl @[simp, norm_cast] theorem intCast_imI (z : ℤ) : (z : ℍ[R]).imI = 0 := rfl @[simp, norm_cast] theorem intCast_imJ (z : ℤ) : (z : ℍ[R]).imJ = 0 := rfl @[simp, norm_cast] theorem intCast_imK (z : ℤ) : (z : ℍ[R]).imK = 0 := rfl @[simp, norm_cast] theorem intCast_im (z : ℤ) : (z : ℍ[R]).im = 0 := rfl @[norm_cast] theorem coe_intCast (z : ℤ) : ↑(z : R) = (z : ℍ[R]) := rfl theorem coe_injective : Function.Injective (coe : R → ℍ[R]) := QuaternionAlgebra.coe_injective @[simp] theorem coe_inj {x y : R} : (x : ℍ[R]) = y ↔ x = y := coe_injective.eq_iff @[simp] theorem smul_re [SMul S R] (s : S) : (s • a).re = s • a.re := rfl @[simp] theorem smul_imI [SMul S R] (s : S) : (s • a).imI = s • a.imI := rfl @[simp] theorem smul_imJ [SMul S R] (s : S) : (s • a).imJ = s • a.imJ := rfl @[simp] theorem smul_imK [SMul S R] (s : S) : (s • a).imK = s • a.imK := rfl @[simp] nonrec theorem smul_im [SMulZeroClass S R] (s : S) : (s • a).im = s • a.im := a.smul_im s @[simp, norm_cast] theorem coe_smul [SMulZeroClass S R] (s : S) (r : R) : (↑(s • r) : ℍ[R]) = s • (r : ℍ[R]) := QuaternionAlgebra.coe_smul _ _ theorem coe_commutes : ↑r * a = a * r := QuaternionAlgebra.coe_commutes r a theorem coe_commute : Commute (↑r) a := QuaternionAlgebra.coe_commute r a theorem coe_mul_eq_smul : ↑r * a = r • a := QuaternionAlgebra.coe_mul_eq_smul r a theorem mul_coe_eq_smul : a * r = r • a := QuaternionAlgebra.mul_coe_eq_smul r a @[simp] theorem algebraMap_def : ⇑(algebraMap R ℍ[R]) = coe := rfl theorem algebraMap_injective : (algebraMap R ℍ[R] : _ → _).Injective := QuaternionAlgebra.algebraMap_injective theorem smul_coe : x • (y : ℍ[R]) = ↑(x * y) := QuaternionAlgebra.smul_coe x y instance : Module.Finite R ℍ[R] := inferInstanceAs <| Module.Finite R ℍ[R,-1,0,-1] instance : Module.Free R ℍ[R] := inferInstanceAs <| Module.Free R ℍ[R,-1,0,-1] theorem rank_eq_four [StrongRankCondition R] : Module.rank R ℍ[R] = 4 := QuaternionAlgebra.rank_eq_four _ _ _ theorem finrank_eq_four [StrongRankCondition R] : Module.finrank R ℍ[R] = 4 := QuaternionAlgebra.finrank_eq_four _ _ _ @[simp] theorem star_re : (star a).re = a.re := by rw [QuaternionAlgebra.re_star, zero_mul, add_zero] @[simp] theorem star_imI : (star a).imI = -a.imI := rfl @[simp] theorem star_imJ : (star a).imJ = -a.imJ := rfl @[simp] theorem star_imK : (star a).imK = -a.imK := rfl @[simp] theorem star_im : (star a).im = -a.im := a.im_star nonrec theorem self_add_star' : a + star a = ↑(2 * a.re) := by simp [a.self_add_star', Quaternion.coe] nonrec theorem self_add_star : a + star a = 2 * a.re := by simp [a.self_add_star, Quaternion.coe] nonrec theorem star_add_self' : star a + a = ↑(2 * a.re) := by simp [a.star_add_self', Quaternion.coe] nonrec theorem star_add_self : star a + a = 2 * a.re := by simp [a.star_add_self, Quaternion.coe] nonrec theorem star_eq_two_re_sub : star a = ↑(2 * a.re) - a := by simp [a.star_eq_two_re_sub, Quaternion.coe] @[simp, norm_cast] theorem star_coe : star (x : ℍ[R]) = x := QuaternionAlgebra.star_coe x @[simp] theorem im_star : star a.im = -a.im := by ext <;> simp @[simp] theorem star_smul [Monoid S] [DistribMulAction S R] (s : S) (a : ℍ[R]) : star (s • a) = s • star a := QuaternionAlgebra.star_smul' s a theorem eq_re_of_eq_coe {a : ℍ[R]} {x : R} (h : a = x) : a = a.re := QuaternionAlgebra.eq_re_of_eq_coe h theorem eq_re_iff_mem_range_coe {a : ℍ[R]} : a = a.re ↔ a ∈ Set.range (coe : R → ℍ[R]) := QuaternionAlgebra.eq_re_iff_mem_range_coe section CharZero variable [NoZeroDivisors R] [CharZero R] @[simp] theorem star_eq_self {a : ℍ[R]} : star a = a ↔ a = a.re := QuaternionAlgebra.star_eq_self @[simp] theorem star_eq_neg {a : ℍ[R]} : star a = -a ↔ a.re = 0 := QuaternionAlgebra.star_eq_neg end CharZero nonrec theorem star_mul_eq_coe : star a * a = (star a * a).re := a.star_mul_eq_coe nonrec theorem mul_star_eq_coe : a * star a = (a * star a).re := a.mul_star_eq_coe open MulOpposite /-- Quaternion conjugate as an `AlgEquiv` to the opposite ring. -/ def starAe : ℍ[R] ≃ₐ[R] ℍ[R]ᵐᵒᵖ := QuaternionAlgebra.starAe @[simp] theorem coe_starAe : ⇑(starAe : ℍ[R] ≃ₐ[R] ℍ[R]ᵐᵒᵖ) = op ∘ star := rfl /-- Square of the norm. -/ def normSq : ℍ[R] →*₀ R where toFun a := (a * star a).re map_zero' := by simp only [star_zero, zero_mul, zero_re] map_one' := by simp only [star_one, one_mul, one_re] map_mul' x y := coe_injective <| by conv_lhs => rw [← mul_star_eq_coe, star_mul, mul_assoc, ← mul_assoc y, y.mul_star_eq_coe, coe_commutes, ← mul_assoc, x.mul_star_eq_coe, ← coe_mul] theorem normSq_def : normSq a = (a * star a).re := rfl theorem normSq_def' : normSq a = a.1 ^ 2 + a.2 ^ 2 + a.3 ^ 2 + a.4 ^ 2 := by simp only [normSq_def, sq, mul_neg, sub_neg_eq_add, mul_re, star_re, star_imI, star_imJ, star_imK] theorem normSq_coe : normSq (x : ℍ[R]) = x ^ 2 := by rw [normSq_def, star_coe, ← coe_mul, coe_re, sq] @[simp] theorem normSq_star : normSq (star a) = normSq a := by simp [normSq_def'] @[norm_cast] theorem normSq_natCast (n : ℕ) : normSq (n : ℍ[R]) = (n : R) ^ 2 := by rw [← coe_natCast, normSq_coe] @[norm_cast] theorem normSq_intCast (z : ℤ) : normSq (z : ℍ[R]) = (z : R) ^ 2 := by rw [← coe_intCast, normSq_coe] @[simp] theorem normSq_neg : normSq (-a) = normSq a := by simp only [normSq_def, star_neg, neg_mul_neg] theorem self_mul_star : a * star a = normSq a := by rw [mul_star_eq_coe, normSq_def] theorem star_mul_self : star a * a = normSq a := by rw [star_comm_self, self_mul_star] theorem im_sq : a.im ^ 2 = -normSq a.im := by simp_rw [sq, ← star_mul_self, im_star, neg_mul, neg_neg] theorem coe_normSq_add : normSq (a + b) = normSq a + a * star b + b * star a + normSq b := by simp only [star_add, ← self_mul_star, mul_add, add_mul, add_assoc, add_left_comm] theorem normSq_smul (r : R) (q : ℍ[R]) : normSq (r • q) = r ^ 2 * normSq q := by simp only [normSq_def', smul_re, smul_imI, smul_imJ, smul_imK, mul_pow, mul_add, smul_eq_mul] theorem normSq_add (a b : ℍ[R]) : normSq (a + b) = normSq a + normSq b + 2 * (a * star b).re := calc normSq (a + b) = normSq a + (a * star b).re + ((b * star a).re + normSq b) := by simp_rw [normSq_def, star_add, add_mul, mul_add, add_re] _ = normSq a + normSq b + ((a * star b).re + (b * star a).re) := by abel _ = normSq a + normSq b + 2 * (a * star b).re := by rw [← add_re, ← star_mul_star a b, self_add_star', coe_re] end Quaternion namespace Quaternion variable {R : Type*} section LinearOrderedCommRing variable [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] {a : ℍ[R]} @[simp] theorem normSq_eq_zero : normSq a = 0 ↔ a = 0 := by refine ⟨fun h => ?_, fun h => h.symm ▸ normSq.map_zero⟩ rw [normSq_def', add_eq_zero_iff_of_nonneg, add_eq_zero_iff_of_nonneg, add_eq_zero_iff_of_nonneg] at h · exact ext a 0 (pow_eq_zero h.1.1.1) (pow_eq_zero h.1.1.2) (pow_eq_zero h.1.2) (pow_eq_zero h.2) all_goals apply_rules [sq_nonneg, add_nonneg] theorem normSq_ne_zero : normSq a ≠ 0 ↔ a ≠ 0 := normSq_eq_zero.not @[simp] theorem normSq_nonneg : 0 ≤ normSq a := by rw [normSq_def'] apply_rules [sq_nonneg, add_nonneg] @[simp] theorem normSq_le_zero : normSq a ≤ 0 ↔ a = 0 := normSq_nonneg.le_iff_eq.trans normSq_eq_zero instance instNontrivial : Nontrivial ℍ[R] where exists_pair_ne := ⟨0, 1, mt (congr_arg QuaternionAlgebra.re) zero_ne_one⟩ instance : NoZeroDivisors ℍ[R] where eq_zero_or_eq_zero_of_mul_eq_zero {a b} hab := have : normSq a * normSq b = 0 := by rwa [← map_mul, normSq_eq_zero] (eq_zero_or_eq_zero_of_mul_eq_zero this).imp normSq_eq_zero.1 normSq_eq_zero.1 instance : IsDomain ℍ[R] := NoZeroDivisors.to_isDomain _ theorem sq_eq_normSq : a ^ 2 = normSq a ↔ a = a.re := by rw [← star_eq_self, ← star_mul_self, sq, mul_eq_mul_right_iff, eq_comm] exact or_iff_left_of_imp fun ha ↦ ha.symm ▸ star_zero _ theorem sq_eq_neg_normSq : a ^ 2 = -normSq a ↔ a.re = 0 := by simp_rw [← star_eq_neg] obtain rfl | hq0 := eq_or_ne a 0 · simp · rw [← star_mul_self, ← mul_neg, ← neg_sq, sq, mul_left_inj' (neg_ne_zero.mpr hq0), eq_comm] end LinearOrderedCommRing section Field variable [Field R] (a b : ℍ[R]) instance instNNRatCast : NNRatCast ℍ[R] where nnratCast q := (q : R) instance instRatCast : RatCast ℍ[R] where ratCast q := (q : R) @[simp, norm_cast] lemma re_nnratCast (q : ℚ≥0) : (q : ℍ[R]).re = q := rfl @[simp, norm_cast] lemma im_nnratCast (q : ℚ≥0) : (q : ℍ[R]).im = 0 := rfl @[simp, norm_cast] lemma imI_nnratCast (q : ℚ≥0) : (q : ℍ[R]).imI = 0 := rfl @[simp, norm_cast] lemma imJ_nnratCast (q : ℚ≥0) : (q : ℍ[R]).imJ = 0 := rfl @[simp, norm_cast] lemma imK_nnratCast (q : ℚ≥0) : (q : ℍ[R]).imK = 0 := rfl @[simp, norm_cast] lemma ratCast_re (q : ℚ) : (q : ℍ[R]).re = q := rfl @[simp, norm_cast] lemma ratCast_im (q : ℚ) : (q : ℍ[R]).im = 0 := rfl @[simp, norm_cast] lemma ratCast_imI (q : ℚ) : (q : ℍ[R]).imI = 0 := rfl @[simp, norm_cast] lemma ratCast_imJ (q : ℚ) : (q : ℍ[R]).imJ = 0 := rfl @[simp, norm_cast] lemma ratCast_imK (q : ℚ) : (q : ℍ[R]).imK = 0 := rfl @[norm_cast] lemma coe_nnratCast (q : ℚ≥0) : ↑(q : R) = (q : ℍ[R]) := rfl @[norm_cast] lemma coe_ratCast (q : ℚ) : ↑(q : R) = (q : ℍ[R]) := rfl variable [LinearOrder R] [IsStrictOrderedRing R] (a b : ℍ[R]) @[simps -isSimp] instance instInv : Inv ℍ[R] := ⟨fun a => (normSq a)⁻¹ • star a⟩ instance instGroupWithZero : GroupWithZero ℍ[R] := { Quaternion.instNontrivial with inv := Inv.inv inv_zero := by rw [instInv_inv, star_zero, smul_zero] mul_inv_cancel := fun a ha => by rw [instInv_inv, Algebra.mul_smul_comm (normSq a)⁻¹ a (star a), self_mul_star, smul_coe, inv_mul_cancel₀ (normSq_ne_zero.2 ha), coe_one] } @[norm_cast, simp] theorem coe_inv (x : R) : ((x⁻¹ : R) : ℍ[R]) = (↑x)⁻¹ := map_inv₀ (algebraMap R ℍ[R]) _ @[norm_cast, simp] theorem coe_div (x y : R) : ((x / y : R) : ℍ[R]) = x / y := map_div₀ (algebraMap R ℍ[R]) x y @[norm_cast, simp] theorem coe_zpow (x : R) (z : ℤ) : ((x ^ z : R) : ℍ[R]) = (x : ℍ[R]) ^ z := map_zpow₀ (algebraMap R ℍ[R]) x z instance instDivisionRing : DivisionRing ℍ[R] where __ := Quaternion.instRing __ := Quaternion.instGroupWithZero nnqsmul := (· • ·) qsmul := (· • ·) nnratCast_def _ := by rw [← coe_nnratCast, NNRat.cast_def, coe_div, coe_natCast, coe_natCast] ratCast_def _ := by rw [← coe_ratCast, Rat.cast_def, coe_div, coe_intCast, coe_natCast] nnqsmul_def _ _ := by rw [← coe_nnratCast, coe_mul_eq_smul]; ext <;> exact NNRat.smul_def .. qsmul_def _ _ := by rw [← coe_ratCast, coe_mul_eq_smul]; ext <;> exact Rat.smul_def .. theorem normSq_inv : normSq a⁻¹ = (normSq a)⁻¹ := map_inv₀ normSq _ theorem normSq_div : normSq (a / b) = normSq a / normSq b := map_div₀ normSq a b theorem normSq_zpow (z : ℤ) : normSq (a ^ z) = normSq a ^ z := map_zpow₀ normSq a z @[norm_cast] theorem normSq_ratCast (q : ℚ) : normSq (q : ℍ[R]) = (q : ℍ[R]) ^ 2 := by rw [← coe_ratCast, normSq_coe, coe_pow] end Field end Quaternion namespace Cardinal open Quaternion section QuaternionAlgebra variable {R : Type*} (c₁ c₂ c₃ : R) private theorem pow_four [Infinite R] : #R ^ 4 = #R := power_nat_eq (aleph0_le_mk R) <| by decide /-- The cardinality of a quaternion algebra, as a type. -/ theorem mk_quaternionAlgebra : #(ℍ[R,c₁,c₂,c₃]) = #R ^ 4 := by rw [mk_congr (QuaternionAlgebra.equivProd c₁ c₂ c₃)] simp only [mk_prod, lift_id] ring @[simp] theorem mk_quaternionAlgebra_of_infinite [Infinite R] : #(ℍ[R,c₁,c₂,c₃]) = #R := by rw [mk_quaternionAlgebra, pow_four] /-- The cardinality of a quaternion algebra, as a set. -/ theorem mk_univ_quaternionAlgebra : #(Set.univ : Set ℍ[R,c₁,c₂,c₃]) = #R ^ 4 := by rw [mk_univ, mk_quaternionAlgebra] theorem mk_univ_quaternionAlgebra_of_infinite [Infinite R] : #(Set.univ : Set ℍ[R,c₁,c₂,c₃]) = #R := by rw [mk_univ_quaternionAlgebra, pow_four] /-- Show the quaternion ⟨w, x, y, z⟩ as a string "{ re := w, imI := x, imJ := y, imK := z }". For the typical case of quaternions over ℝ, each component will show as a Cauchy sequence due to the way Real numbers are represented. -/ instance [Repr R] {a b c : R} : Repr ℍ[R, a, b, c] where reprPrec q _ := s!"\{ re := {repr q.re}, imI := {repr q.imI}, imJ := {repr q.imJ}, imK := {repr q.imK} }" end QuaternionAlgebra section Quaternion variable (R : Type*) [Zero R] [One R] [Neg R] /-- The cardinality of the quaternions, as a type. -/ @[simp] theorem mk_quaternion : #(ℍ[R]) = #R ^ 4 := mk_quaternionAlgebra _ _ _ theorem mk_quaternion_of_infinite [Infinite R] : #(ℍ[R]) = #R := mk_quaternionAlgebra_of_infinite _ _ _ /-- The cardinality of the quaternions, as a set. -/ theorem mk_univ_quaternion : #(Set.univ : Set ℍ[R]) = #R ^ 4 := mk_univ_quaternionAlgebra _ _ _ theorem mk_univ_quaternion_of_infinite [Infinite R] : #(Set.univ : Set ℍ[R]) = #R := mk_univ_quaternionAlgebra_of_infinite _ _ _ end Quaternion end Cardinal
Mathlib/Algebra/Quaternion.lean
1,343
1,344
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Yury Kudryashov -/ import Mathlib.Algebra.Algebra.Tower /-! # The `RestrictScalars` type alias See the documentation attached to the `RestrictScalars` definition for advice on how and when to use this type alias. As described there, it is often a better choice to use the `IsScalarTower` typeclass instead. ## Main definitions * `RestrictScalars R S M`: the `S`-module `M` viewed as an `R` module when `S` is an `R`-algebra. Note that by default we do *not* have a `Module S (RestrictScalars R S M)` instance for the original action. This is available as a def `RestrictScalars.moduleOrig` if really needed. * `RestrictScalars.addEquiv : RestrictScalars R S M ≃+ M`: the additive equivalence between the restricted and original space (in fact, they are definitionally equal, but sometimes it is helpful to avoid using this fact, to keep instances from leaking). * `RestrictScalars.ringEquiv : RestrictScalars R S A ≃+* A`: the ring equivalence between the restricted and original space when the module is an algebra. ## See also There are many similarly-named definitions elsewhere which do not refer to this type alias. These refer to restricting the scalar type in a bundled type, such as from `A →ₗ[R] B` to `A →ₗ[S] B`: * `LinearMap.restrictScalars` * `LinearEquiv.restrictScalars` * `AlgHom.restrictScalars` * `AlgEquiv.restrictScalars` * `Submodule.restrictScalars` * `Subalgebra.restrictScalars` -/ variable (R S M A : Type*) /-- If we put an `R`-algebra structure on a semiring `S`, we get a natural equivalence from the category of `S`-modules to the category of representations of the algebra `S` (over `R`). The type synonym `RestrictScalars` is essentially this equivalence. Warning: use this type synonym judiciously! Consider an example where we want to construct an `R`-linear map from `M` to `S`, given: ```lean variable (R S M : Type*) variable [CommSemiring R] [Semiring S] [Algebra R S] [AddCommMonoid M] [Module S M] ``` With the assumptions above we can't directly state our map as we have no `Module R M` structure, but `RestrictScalars` permits it to be written as: ```lean -- an `R`-module structure on `M` is provided by `RestrictScalars` which is compatible example : RestrictScalars R S M →ₗ[R] S := sorry ``` However, it is usually better just to add this extra structure as an argument: ```lean -- an `R`-module structure on `M` and proof of its compatibility is provided by the user example [Module R M] [IsScalarTower R S M] : M →ₗ[R] S := sorry ``` The advantage of the second approach is that it defers the duty of providing the missing typeclasses `[Module R M] [IsScalarTower R S M]`. If some concrete `M` naturally carries these (as is often the case) then we have avoided `RestrictScalars` entirely. If not, we can pass `RestrictScalars R S M` later on instead of `M`. Note that this means we almost always want to state definitions and lemmas in the language of `IsScalarTower` rather than `RestrictScalars`. An example of when one might want to use `RestrictScalars` would be if one has a vector space over a field of characteristic zero and wishes to make use of the `ℚ`-algebra structure. -/ @[nolint unusedArguments] def RestrictScalars (_R _S M : Type*) : Type _ := M instance [I : Inhabited M] : Inhabited (RestrictScalars R S M) := I instance [I : AddCommMonoid M] : AddCommMonoid (RestrictScalars R S M) := I instance [I : AddCommGroup M] : AddCommGroup (RestrictScalars R S M) := I section Module section variable [Semiring S] [AddCommMonoid M] /-- We temporarily install an action of the original ring on `RestrictScalars R S M`. -/ def RestrictScalars.moduleOrig [I : Module S M] : Module S (RestrictScalars R S M) := I variable [CommSemiring R] [Algebra R S] section attribute [local instance] RestrictScalars.moduleOrig /-- When `M` is a module over a ring `S`, and `S` is an algebra over `R`, then `M` inherits a module structure over `R`. The preferred way of setting this up is `[Module R M] [Module S M] [IsScalarTower R S M]`. -/ instance RestrictScalars.module [Module S M] : Module R (RestrictScalars R S M) := Module.compHom M (algebraMap R S) /-- This instance is only relevant when `RestrictScalars.moduleOrig` is available as an instance. -/ instance RestrictScalars.isScalarTower [Module S M] : IsScalarTower R S (RestrictScalars R S M) := ⟨fun r S M ↦ by rw [Algebra.smul_def, mul_smul] rfl⟩ end /-- When `M` is a right-module over a ring `S`, and `S` is an algebra over `R`, then `M` inherits a right-module structure over `R`. The preferred way of setting this up is `[Module Rᵐᵒᵖ M] [Module Sᵐᵒᵖ M] [IsScalarTower Rᵐᵒᵖ Sᵐᵒᵖ M]`. -/ instance RestrictScalars.opModule [Module Sᵐᵒᵖ M] : Module Rᵐᵒᵖ (RestrictScalars R S M) := letI : Module Sᵐᵒᵖ (RestrictScalars R S M) := ‹Module Sᵐᵒᵖ M› Module.compHom M (RingHom.op <| algebraMap R S) instance RestrictScalars.isCentralScalar [Module S M] [Module Sᵐᵒᵖ M] [IsCentralScalar S M] : IsCentralScalar R (RestrictScalars R S M) where op_smul_eq_smul r _x := (op_smul_eq_smul (algebraMap R S r) (_ : M) :) /-- The `R`-algebra homomorphism from the original coefficient algebra `S` to endomorphisms of `RestrictScalars R S M`. -/ def RestrictScalars.lsmul [Module S M] : S →ₐ[R] Module.End R (RestrictScalars R S M) := -- We use `RestrictScalars.moduleOrig` in the implementation, -- but not in the type. letI : Module S (RestrictScalars R S M) := RestrictScalars.moduleOrig R S M Algebra.lsmul R R (RestrictScalars R S M) end variable [AddCommMonoid M] /-- `RestrictScalars.addEquiv` is the additive equivalence with the original module. -/ def RestrictScalars.addEquiv : RestrictScalars R S M ≃+ M := AddEquiv.refl M variable [CommSemiring R] [Semiring S] [Algebra R S] [Module S M] theorem RestrictScalars.smul_def (c : R) (x : RestrictScalars R S M) : c • x = (RestrictScalars.addEquiv R S M).symm (algebraMap R S c • RestrictScalars.addEquiv R S M x) := rfl @[simp] theorem RestrictScalars.addEquiv_map_smul (c : R) (x : RestrictScalars R S M) : RestrictScalars.addEquiv R S M (c • x) = algebraMap R S c • RestrictScalars.addEquiv R S M x := rfl theorem RestrictScalars.addEquiv_symm_map_algebraMap_smul (r : R) (x : M) : (RestrictScalars.addEquiv R S M).symm (algebraMap R S r • x) = r • (RestrictScalars.addEquiv R S M).symm x := rfl theorem RestrictScalars.addEquiv_symm_map_smul_smul (r : R) (s : S) (x : M) : (RestrictScalars.addEquiv R S M).symm ((r • s) • x) = r • (RestrictScalars.addEquiv R S M).symm (s • x) := by rw [Algebra.smul_def, mul_smul] rfl theorem RestrictScalars.lsmul_apply_apply (s : S) (x : RestrictScalars R S M) : RestrictScalars.lsmul R S M s x = (RestrictScalars.addEquiv R S M).symm (s • RestrictScalars.addEquiv R S M x) := rfl end Module
section Algebra instance [I : Semiring A] : Semiring (RestrictScalars R S A) := I
Mathlib/Algebra/Algebra/RestrictScalars.lean
175
179
/- Copyright (c) 2023 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Algebra.Field.Subfield.Basic import Mathlib.Data.W.Cardinal import Mathlib.Tactic.FinCases /-! # Cardinality of the division ring generated by a set `Subfield.cardinalMk_closure_le_max`: the cardinality of the (sub-)division ring generated by a set is bounded by the cardinality of the set unless it is finite. The method used to prove this (via `WType`) can be easily generalized to other algebraic structures, but those cardinalities can usually be obtained by other means, using some explicit universal objects. -/ universe u variable {α : Type u} (s : Set α) namespace Subfield private abbrev Operands : Fin 6 ⊕ s → Type | .inl 0 => Bool -- add | .inl 1 => Bool -- mul | .inl 2 => Unit -- neg | .inl 3 => Unit -- inv | .inl 4 => Empty -- zero | .inl 5 => Empty -- one | .inr _ => Empty -- s variable [DivisionRing α] private def operate : (Σ n, Operands s n → closure s) → closure s | ⟨.inl 0, f⟩ => f false + f true | ⟨.inl 1, f⟩ => f false * f true | ⟨.inl 2, f⟩ => - f () | ⟨.inl 3, f⟩ => (f ())⁻¹ | ⟨.inl 4, _⟩ => 0 | ⟨.inl 5, _⟩ => 1 | ⟨.inr a, _⟩ => ⟨a, subset_closure a.prop⟩ private def rangeOfWType : Subfield (closure s) where carrier := Set.range (WType.elim _ <| operate s) add_mem' := by rintro _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact ⟨WType.mk (.inl 0) (Bool.rec x y), by rfl⟩ mul_mem' := by rintro _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact ⟨WType.mk (.inl 1) (Bool.rec x y), by rfl⟩ neg_mem' := by rintro _ ⟨x, rfl⟩; exact ⟨WType.mk (.inl 2) fun _ ↦ x, rfl⟩ inv_mem' := by rintro _ ⟨x, rfl⟩; exact ⟨WType.mk (.inl 3) fun _ ↦ x, rfl⟩ zero_mem' := ⟨WType.mk (.inl 4) Empty.rec, rfl⟩ one_mem' := ⟨WType.mk (.inl 5) Empty.rec, rfl⟩ private lemma rangeOfWType_eq_top : rangeOfWType s = ⊤ := top_le_iff.mp fun a _ ↦ by rw [← SetLike.mem_coe, ← Subtype.val_injective.mem_set_image] change ↑a ∈ map (closure s).subtype _ refine closure_le.mpr (fun a ha ↦ ?_) a.prop exact ⟨⟨a, subset_closure ha⟩, ⟨WType.mk (.inr ⟨a, ha⟩) Empty.rec, rfl⟩, rfl⟩ private lemma surjective_ofWType : Function.Surjective (WType.elim _ <| operate s) := by rw [← Set.range_eq_univ] exact SetLike.coe_set_eq.mpr (rangeOfWType_eq_top s) open Cardinal
lemma cardinalMk_closure_le_max : #(closure s) ≤ max #s ℵ₀ := (Cardinal.mk_le_of_surjective <| surjective_ofWType s).trans <| by convert WType.cardinalMk_le_max_aleph0_of_finite' using 1 · rw [lift_uzero, mk_sum, lift_uzero] have : lift.{u,0} #(Fin 6) < ℵ₀ := lift_lt_aleph0.mpr (lt_aleph0_of_finite _) obtain h|h := lt_or_le #s ℵ₀ · rw [max_eq_right h.le, max_eq_right] exact (add_lt_aleph0 this h).le · rw [max_eq_left h, add_eq_right h (this.le.trans h), max_eq_left h] rintro (n|_) · fin_cases n <;> (dsimp only [id_eq]; infer_instance) infer_instance
Mathlib/SetTheory/Cardinal/Subfield.lean
69
80
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Edward Ayers -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.Data.Set.BooleanAlgebra /-! # Theory of sieves - For an object `X` of a category `C`, a `Sieve X` is a set of morphisms to `X` which is closed under left-composition. - The complete lattice structure on sieves is given, as well as the Galois insertion given by downward-closing. - A `Sieve X` (functorially) induces a presheaf on `C` together with a monomorphism to the yoneda embedding of `X`. ## Tags sieve, pullback -/ universe v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory open Category Limits variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D) variable {X Y Z : C} (f : Y ⟶ X) /-- A set of arrows all with codomain `X`. -/ def Presieve (X : C) := ∀ ⦃Y⦄, Set (Y ⟶ X)-- deriving CompleteLattice instance : CompleteLattice (Presieve X) := by dsimp [Presieve] infer_instance namespace Presieve noncomputable instance : Inhabited (Presieve X) := ⟨⊤⟩ /-- The full subcategory of the over category `C/X` consisting of arrows which belong to a presieve on `X`. -/ abbrev category {X : C} (P : Presieve X) := ObjectProperty.FullSubcategory fun f : Over X => P f.hom /-- Construct an object of `P.category`. -/ abbrev categoryMk {X : C} (P : Presieve X) {Y : C} (f : Y ⟶ X) (hf : P f) : P.category := ⟨Over.mk f, hf⟩ /-- Given a sieve `S` on `X : C`, its associated diagram `S.diagram` is defined to be the natural functor from the full subcategory of the over category `C/X` consisting of arrows in `S` to `C`. -/ abbrev diagram (S : Presieve X) : S.category ⥤ C := ObjectProperty.ι _ ⋙ Over.forget X /-- Given a sieve `S` on `X : C`, its associated cocone `S.cocone` is defined to be the natural cocone over the diagram defined above with cocone point `X`. -/ abbrev cocone (S : Presieve X) : Cocone S.diagram := (Over.forgetCocone X).whisker (ObjectProperty.ι _) /-- Given a set of arrows `S` all with codomain `X`, and a set of arrows with codomain `Y` for each `f : Y ⟶ X` in `S`, produce a set of arrows with codomain `X`: `{ g ≫ f | (f : Y ⟶ X) ∈ S, (g : Z ⟶ Y) ∈ R f }`. -/ def bind (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y) : Presieve X := fun Z h => ∃ (Y : C) (g : Z ⟶ Y) (f : Y ⟶ X) (H : S f), R H g ∧ g ≫ f = h /-- Structure which contains the data and properties for a morphism `h` satisfying `Presieve.bind S R h`. -/ structure BindStruct (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y) {Z : C} (h : Z ⟶ X) where /-- the intermediate object -/ Y : C /-- a morphism in the family of presieves `R` -/ g : Z ⟶ Y /-- a morphism in the presieve `S` -/ f : Y ⟶ X hf : S f hg : R hf g fac : g ≫ f = h attribute [reassoc (attr := simp)] BindStruct.fac /-- If a morphism `h` satisfies `Presieve.bind S R h`, this is a choice of a structure in `BindStruct S R h`. -/ noncomputable def bind.bindStruct {S : Presieve X} {R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y} {Z : C} {h : Z ⟶ X} (H : bind S R h) : BindStruct S R h := Nonempty.some (by obtain ⟨Y, g, f, hf, hg, fac⟩ := H exact ⟨{ hf := hf, hg := hg, fac := fac, .. }⟩) lemma BindStruct.bind {S : Presieve X} {R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y} {Z : C} {h : Z ⟶ X} (b : BindStruct S R h) : bind S R h := ⟨b.Y, b.g, b.f, b.hf, b.hg, b.fac⟩ @[simp] theorem bind_comp {S : Presieve X} {R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y} {g : Z ⟶ Y} (h₁ : S f) (h₂ : R h₁ g) : bind S R (g ≫ f) := ⟨_, _, _, h₁, h₂, rfl⟩ -- Porting note: it seems the definition of `Presieve` must be unfolded in order to define -- this inductive type, it was thus renamed `singleton'` -- Note we can't make this into `HasSingleton` because of the out-param. /-- The singleton presieve. -/ inductive singleton' : ⦃Y : C⦄ → (Y ⟶ X) → Prop | mk : singleton' f /-- The singleton presieve. -/ def singleton : Presieve X := singleton' f lemma singleton.mk {f : Y ⟶ X} : singleton f f := singleton'.mk @[simp] theorem singleton_eq_iff_domain (f g : Y ⟶ X) : singleton f g ↔ f = g := by constructor · rintro ⟨a, rfl⟩ rfl · rintro rfl apply singleton.mk theorem singleton_self : singleton f f := singleton.mk /-- Pullback a set of arrows with given codomain along a fixed map, by taking the pullback in the category. This is not the same as the arrow set of `Sieve.pullback`, but there is a relation between them in `pullbackArrows_comm`. -/ inductive pullbackArrows [HasPullbacks C] (R : Presieve X) : Presieve Y | mk (Z : C) (h : Z ⟶ X) : R h → pullbackArrows _ (pullback.snd h f) theorem pullback_singleton [HasPullbacks C] (g : Z ⟶ X) : pullbackArrows f (singleton g) = singleton (pullback.snd g f) := by funext W ext h constructor · rintro ⟨W, _, _, _⟩ exact singleton.mk · rintro ⟨_⟩ exact pullbackArrows.mk Z g singleton.mk /-- Construct the presieve given by the family of arrows indexed by `ι`. -/ inductive ofArrows {ι : Type*} (Y : ι → C) (f : ∀ i, Y i ⟶ X) : Presieve X | mk (i : ι) : ofArrows _ _ (f i) theorem ofArrows_pUnit : (ofArrows _ fun _ : PUnit => f) = singleton f := by funext Y ext g constructor · rintro ⟨_⟩ apply singleton.mk · rintro ⟨_⟩ exact ofArrows.mk PUnit.unit theorem ofArrows_pullback [HasPullbacks C] {ι : Type*} (Z : ι → C) (g : ∀ i : ι, Z i ⟶ X) : (ofArrows (fun i => pullback (g i) f) fun _ => pullback.snd _ _) = pullbackArrows f (ofArrows Z g) := by funext T ext h constructor · rintro ⟨hk⟩ exact pullbackArrows.mk _ _ (ofArrows.mk hk) · rintro ⟨W, k, ⟨_⟩⟩ apply ofArrows.mk theorem ofArrows_bind {ι : Type*} (Z : ι → C) (g : ∀ i : ι, Z i ⟶ X) (j : ∀ ⦃Y⦄ (f : Y ⟶ X), ofArrows Z g f → Type*) (W : ∀ ⦃Y⦄ (f : Y ⟶ X) (H), j f H → C) (k : ∀ ⦃Y⦄ (f : Y ⟶ X) (H i), W f H i ⟶ Y) : ((ofArrows Z g).bind fun _ f H => ofArrows (W f H) (k f H)) = ofArrows (fun i : Σi, j _ (ofArrows.mk i) => W (g i.1) _ i.2) fun ij => k (g ij.1) _ ij.2 ≫ g ij.1 := by funext Y ext f constructor · rintro ⟨_, _, _, ⟨i⟩, ⟨i'⟩, rfl⟩ exact ofArrows.mk (Sigma.mk _ _) · rintro ⟨i⟩ exact bind_comp _ (ofArrows.mk _) (ofArrows.mk _) theorem ofArrows_surj {ι : Type*} {Y : ι → C} (f : ∀ i, Y i ⟶ X) {Z : C} (g : Z ⟶ X) (hg : ofArrows Y f g) : ∃ (i : ι) (h : Y i = Z), g = eqToHom h.symm ≫ f i := by obtain ⟨i⟩ := hg exact ⟨i, rfl, by simp only [eqToHom_refl, id_comp]⟩ /-- Given a presieve on `F(X)`, we can define a presieve on `X` by taking the preimage via `F`. -/ def functorPullback (R : Presieve (F.obj X)) : Presieve X := fun _ f => R (F.map f) @[simp] theorem functorPullback_mem (R : Presieve (F.obj X)) {Y} (f : Y ⟶ X) : R.functorPullback F f ↔ R (F.map f) := Iff.rfl @[simp] theorem functorPullback_id (R : Presieve X) : R.functorPullback (𝟭 _) = R := rfl /-- Given a presieve `R` on `X`, the predicate `R.hasPullbacks` means that for all arrows `f` and `g` in `R`, the pullback of `f` and `g` exists. -/ class hasPullbacks (R : Presieve X) : Prop where /-- For all arrows `f` and `g` in `R`, the pullback of `f` and `g` exists. -/ has_pullbacks : ∀ {Y Z} {f : Y ⟶ X} (_ : R f) {g : Z ⟶ X} (_ : R g), HasPullback f g instance (R : Presieve X) [HasPullbacks C] : R.hasPullbacks := ⟨fun _ _ ↦ inferInstance⟩ instance {α : Type v₂} {X : α → C} {B : C} (π : (a : α) → X a ⟶ B) [(Presieve.ofArrows X π).hasPullbacks] (a b : α) : HasPullback (π a) (π b) := Presieve.hasPullbacks.has_pullbacks (Presieve.ofArrows.mk _) (Presieve.ofArrows.mk _) section FunctorPushforward variable {E : Type u₃} [Category.{v₃} E] (G : D ⥤ E) /-- Given a presieve on `X`, we can define a presieve on `F(X)` (which is actually a sieve) by taking the sieve generated by the image via `F`. -/ def functorPushforward (S : Presieve X) : Presieve (F.obj X) := fun Y f => ∃ (Z : C) (g : Z ⟶ X) (h : Y ⟶ F.obj Z), S g ∧ f = h ≫ F.map g /-- An auxiliary definition in order to fix the choice of the preimages between various definitions. -/ structure FunctorPushforwardStructure (S : Presieve X) {Y} (f : Y ⟶ F.obj X) where /-- an object in the source category -/ preobj : C /-- a map in the source category which has to be in the presieve -/ premap : preobj ⟶ X /-- the morphism which appear in the factorisation -/ lift : Y ⟶ F.obj preobj /-- the condition that `premap` is in the presieve -/ cover : S premap /-- the factorisation of the morphism -/ fac : f = lift ≫ F.map premap /-- The fixed choice of a preimage. -/ noncomputable def getFunctorPushforwardStructure {F : C ⥤ D} {S : Presieve X} {Y : D} {f : Y ⟶ F.obj X} (h : S.functorPushforward F f) : FunctorPushforwardStructure F S f := by choose Z f' g h₁ h using h exact ⟨Z, f', g, h₁, h⟩ theorem functorPushforward_comp (R : Presieve X) : R.functorPushforward (F ⋙ G) = (R.functorPushforward F).functorPushforward G := by funext x ext f constructor · rintro ⟨X, f₁, g₁, h₁, rfl⟩ exact ⟨F.obj X, F.map f₁, g₁, ⟨X, f₁, 𝟙 _, h₁, by simp⟩, rfl⟩ · rintro ⟨X, f₁, g₁, ⟨X', f₂, g₂, h₁, rfl⟩, rfl⟩ exact ⟨X', f₂, g₁ ≫ G.map g₂, h₁, by simp⟩ theorem image_mem_functorPushforward (R : Presieve X) {f : Y ⟶ X} (h : R f) : R.functorPushforward F (F.map f) := ⟨Y, f, 𝟙 _, h, by simp⟩ end FunctorPushforward end Presieve /-- For an object `X` of a category `C`, a `Sieve X` is a set of morphisms to `X` which is closed under left-composition. -/ structure Sieve {C : Type u₁} [Category.{v₁} C] (X : C) where /-- the underlying presieve -/ arrows : Presieve X /-- stability by precomposition -/ downward_closed : ∀ {Y Z f} (_ : arrows f) (g : Z ⟶ Y), arrows (g ≫ f) namespace Sieve instance : CoeFun (Sieve X) fun _ => Presieve X := ⟨Sieve.arrows⟩ initialize_simps_projections Sieve (arrows → apply) variable {S R : Sieve X} attribute [simp] downward_closed theorem arrows_ext : ∀ {R S : Sieve X}, R.arrows = S.arrows → R = S := by rintro ⟨_, _⟩ ⟨_, _⟩ rfl rfl @[ext] protected theorem ext {R S : Sieve X} (h : ∀ ⦃Y⦄ (f : Y ⟶ X), R f ↔ S f) : R = S := arrows_ext <| funext fun _ => funext fun f => propext <| h f open Lattice /-- The supremum of a collection of sieves: the union of them all. -/ protected def sup (𝒮 : Set (Sieve X)) : Sieve X where arrows _ := { f | ∃ S ∈ 𝒮, Sieve.arrows S f } downward_closed {_ _ f} hf _ := by obtain ⟨S, hS, hf⟩ := hf exact ⟨S, hS, S.downward_closed hf _⟩ /-- The infimum of a collection of sieves: the intersection of them all. -/ protected def inf (𝒮 : Set (Sieve X)) : Sieve X where arrows _ := { f | ∀ S ∈ 𝒮, Sieve.arrows S f } downward_closed {_ _ _} hf g S H := S.downward_closed (hf S H) g /-- The union of two sieves is a sieve. -/ protected def union (S R : Sieve X) : Sieve X where arrows _ f := S f ∨ R f downward_closed := by rintro _ _ _ (h | h) g <;> simp [h] /-- The intersection of two sieves is a sieve. -/ protected def inter (S R : Sieve X) : Sieve X where arrows _ f := S f ∧ R f downward_closed := by rintro _ _ _ ⟨h₁, h₂⟩ g simp [h₁, h₂] /-- Sieves on an object `X` form a complete lattice. We generate this directly rather than using the galois insertion for nicer definitional properties. -/ instance : CompleteLattice (Sieve X) where le S R := ∀ ⦃Y⦄ (f : Y ⟶ X), S f → R f le_refl _ _ _ := id le_trans _ _ _ S₁₂ S₂₃ _ _ h := S₂₃ _ (S₁₂ _ h) le_antisymm _ _ p q := Sieve.ext fun _ _ => ⟨p _, q _⟩ top := { arrows := fun _ => Set.univ downward_closed := fun _ _ => ⟨⟩ } bot := { arrows := fun _ => ∅ downward_closed := False.elim } sup := Sieve.union inf := Sieve.inter sSup := Sieve.sup sInf := Sieve.inf le_sSup _ S hS _ _ hf := ⟨S, hS, hf⟩ sSup_le := fun _ _ ha _ _ ⟨b, hb, hf⟩ => (ha b hb) _ hf sInf_le _ _ hS _ _ h := h _ hS le_sInf _ _ hS _ _ hf _ hR := hS _ hR _ hf le_sup_left _ _ _ _ := Or.inl le_sup_right _ _ _ _ := Or.inr sup_le _ _ _ h₁ h₂ _ f := by--ℰ S hS Y f := by rintro (hf | hf) · exact h₁ _ hf · exact h₂ _ hf inf_le_left _ _ _ _ := And.left inf_le_right _ _ _ _ := And.right le_inf _ _ _ p q _ _ z := ⟨p _ z, q _ z⟩ le_top _ _ _ _ := trivial bot_le _ _ _ := False.elim /-- The maximal sieve always exists. -/ instance sieveInhabited : Inhabited (Sieve X) := ⟨⊤⟩ @[simp] theorem sInf_apply {Ss : Set (Sieve X)} {Y} (f : Y ⟶ X) : sInf Ss f ↔ ∀ (S : Sieve X) (_ : S ∈ Ss), S f := Iff.rfl @[simp] theorem sSup_apply {Ss : Set (Sieve X)} {Y} (f : Y ⟶ X) : sSup Ss f ↔ ∃ (S : Sieve X) (_ : S ∈ Ss), S f := by simp [sSup, Sieve.sup, setOf] @[simp] theorem inter_apply {R S : Sieve X} {Y} (f : Y ⟶ X) : (R ⊓ S) f ↔ R f ∧ S f := Iff.rfl @[simp] theorem union_apply {R S : Sieve X} {Y} (f : Y ⟶ X) : (R ⊔ S) f ↔ R f ∨ S f := Iff.rfl @[simp] theorem top_apply (f : Y ⟶ X) : (⊤ : Sieve X) f := trivial /-- Generate the smallest sieve containing the given set of arrows. -/ @[simps] def generate (R : Presieve X) : Sieve X where arrows Z f := ∃ (Y : _) (h : Z ⟶ Y) (g : Y ⟶ X), R g ∧ h ≫ g = f downward_closed := by rintro Y Z _ ⟨W, g, f, hf, rfl⟩ h exact ⟨_, h ≫ g, _, hf, by simp⟩ /-- Given a presieve on `X`, and a sieve on each domain of an arrow in the presieve, we can bind to produce a sieve on `X`. -/ @[simps] def bind (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) : Sieve X where arrows := S.bind fun _ _ h => R h downward_closed := by rintro Y Z f ⟨W, f, h, hh, hf, rfl⟩ g exact ⟨_, g ≫ f, _, hh, by simp [hf]⟩ /-- Structure which contains the data and properties for a morphism `h` satisfying `Sieve.bind S R h`. -/ abbrev BindStruct (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) {Z : C} (h : Z ⟶ X) := Presieve.BindStruct S (fun _ _ hf ↦ R hf) h open Order Lattice theorem generate_le_iff (R : Presieve X) (S : Sieve X) : generate R ≤ S ↔ R ≤ S := ⟨fun H _ _ hg => H _ ⟨_, 𝟙 _, _, hg, id_comp _⟩, fun ss Y f => by rintro ⟨Z, f, g, hg, rfl⟩ exact S.downward_closed (ss Z hg) f⟩ /-- Show that there is a galois insertion (generate, set_over). -/ def giGenerate : GaloisInsertion (generate : Presieve X → Sieve X) arrows where gc := generate_le_iff choice 𝒢 _ := generate 𝒢 choice_eq _ _ := rfl le_l_u _ _ _ hf := ⟨_, 𝟙 _, _, hf, id_comp _⟩ theorem le_generate (R : Presieve X) : R ≤ generate R := giGenerate.gc.le_u_l R @[simp] theorem generate_sieve (S : Sieve X) : generate S = S := giGenerate.l_u_eq S /-- If the identity arrow is in a sieve, the sieve is maximal. -/ theorem id_mem_iff_eq_top : S (𝟙 X) ↔ S = ⊤ := ⟨fun h => top_unique fun Y f _ => by simpa using downward_closed _ h f, fun h => h.symm ▸ trivial⟩ /-- If an arrow set contains a split epi, it generates the maximal sieve. -/ theorem generate_of_contains_isSplitEpi {R : Presieve X} (f : Y ⟶ X) [IsSplitEpi f] (hf : R f) : generate R = ⊤ := by rw [← id_mem_iff_eq_top] exact ⟨_, section_ f, f, hf, by simp⟩ @[simp] theorem generate_of_singleton_isSplitEpi (f : Y ⟶ X) [IsSplitEpi f] : generate (Presieve.singleton f) = ⊤ := generate_of_contains_isSplitEpi f (Presieve.singleton_self _) @[simp] theorem generate_top : generate (⊤ : Presieve X) = ⊤ := generate_of_contains_isSplitEpi (𝟙 _) ⟨⟩ @[simp] lemma comp_mem_iff (i : X ⟶ Y) (f : Y ⟶ Z) [IsIso i] (S : Sieve Z) : S (i ≫ f) ↔ S f := by refine ⟨fun H ↦ ?_, fun H ↦ S.downward_closed H _⟩ convert S.downward_closed H (inv i) simp section variable {I : Type*} {X : C} (Y : I → C) (f : ∀ i, Y i ⟶ X) /-- The sieve of `X` generated by family of morphisms `Y i ⟶ X`. -/ abbrev ofArrows : Sieve X := generate (Presieve.ofArrows Y f) lemma ofArrows_mk (i : I) : ofArrows Y f (f i) := ⟨_, 𝟙 _, _, ⟨i⟩, by simp⟩ lemma mem_ofArrows_iff {W : C} (g : W ⟶ X) : ofArrows Y f g ↔ ∃ (i : I) (a : W ⟶ Y i), g = a ≫ f i := by constructor · rintro ⟨T, a, b, ⟨i⟩, rfl⟩ exact ⟨i, a, rfl⟩ · rintro ⟨i, a, rfl⟩ apply downward_closed _ (ofArrows_mk Y f i) variable {Y f} {W : C} {g : W ⟶ X} (hg : ofArrows Y f g) include hg in lemma ofArrows.exists : ∃ (i : I) (h : W ⟶ Y i), g = h ≫ f i := by obtain ⟨_, h, _, ⟨i⟩, rfl⟩ := hg exact ⟨i, h, rfl⟩ /-- When `hg : Sieve.ofArrows Y f g`, this is a choice of `i` such that `g` factors through `f i`. -/ noncomputable def ofArrows.i : I := (ofArrows.exists hg).choose /-- When `hg : Sieve.ofArrows Y f g`, this is a morphism `h : W ⟶ Y (i hg)` such that `h ≫ f (i hg) = g`. -/ noncomputable def ofArrows.h : W ⟶ Y (i hg) := (ofArrows.exists hg).choose_spec.choose @[reassoc (attr := simp)] lemma ofArrows.fac : h hg ≫ f (i hg) = g := (ofArrows.exists hg).choose_spec.choose_spec.symm end /-- The sieve generated by two morphisms. -/ abbrev ofTwoArrows {U V X : C} (i : U ⟶ X) (j : V ⟶ X) : Sieve X := Sieve.ofArrows (Y := pairFunction U V) (fun k ↦ WalkingPair.casesOn k i j) /-- The sieve of `X : C` that is generated by a family of objects `Y : I → C`: it consists of morphisms to `X` which factor through at least one of the `Y i`. -/ def ofObjects {I : Type*} (Y : I → C) (X : C) : Sieve X where arrows Z _ := ∃ (i : I), Nonempty (Z ⟶ Y i) downward_closed := by rintro Z₁ Z₂ p ⟨i, ⟨f⟩⟩ g exact ⟨i, ⟨g ≫ f⟩⟩ lemma mem_ofObjects_iff {I : Type*} (Y : I → C) {Z X : C} (g : Z ⟶ X) : ofObjects Y X g ↔ ∃ (i : I), Nonempty (Z ⟶ Y i) := by rfl lemma ofArrows_le_ofObjects {I : Type*} (Y : I → C) {X : C} (f : ∀ i, Y i ⟶ X) : Sieve.ofArrows Y f ≤ Sieve.ofObjects Y X := by intro W g hg rw [mem_ofArrows_iff] at hg obtain ⟨i, a, rfl⟩ := hg exact ⟨i, ⟨a⟩⟩ lemma ofArrows_eq_ofObjects {X : C} (hX : IsTerminal X) {I : Type*} (Y : I → C) (f : ∀ i, Y i ⟶ X) : ofArrows Y f = ofObjects Y X := by refine le_antisymm (ofArrows_le_ofObjects Y f) (fun W g => ?_) rw [mem_ofArrows_iff, mem_ofObjects_iff] rintro ⟨i, ⟨h⟩⟩ exact ⟨i, h, hX.hom_ext _ _⟩ /-- Given a morphism `h : Y ⟶ X`, send a sieve S on X to a sieve on Y as the inverse image of S with `_ ≫ h`. That is, `Sieve.pullback S h := (≫ h) '⁻¹ S`. -/ @[simps] def pullback (h : Y ⟶ X) (S : Sieve X) : Sieve Y where arrows _ sl := S (sl ≫ h) downward_closed g := by simp [g] @[simp] theorem pullback_id : S.pullback (𝟙 _) = S := by simp [Sieve.ext_iff] @[simp] theorem pullback_top {f : Y ⟶ X} : (⊤ : Sieve X).pullback f = ⊤ := top_unique fun _ _ => id theorem pullback_comp {f : Y ⟶ X} {g : Z ⟶ Y} (S : Sieve X) : S.pullback (g ≫ f) = (S.pullback f).pullback g := by simp [Sieve.ext_iff] @[simp] theorem pullback_inter {f : Y ⟶ X} (S R : Sieve X) : (S ⊓ R).pullback f = S.pullback f ⊓ R.pullback f := by simp [Sieve.ext_iff] theorem mem_iff_pullback_eq_top (f : Y ⟶ X) : S f ↔ S.pullback f = ⊤ := by rw [← id_mem_iff_eq_top, pullback_apply, id_comp] @[deprecated (since := "2025-02-28")] alias pullback_eq_top_iff_mem := mem_iff_pullback_eq_top theorem pullback_eq_top_of_mem (S : Sieve X) {f : Y ⟶ X} : S f → S.pullback f = ⊤ := (mem_iff_pullback_eq_top f).1 lemma pullback_ofObjects_eq_top {I : Type*} (Y : I → C) {X : C} {i : I} (g : X ⟶ Y i) : ofObjects Y X = ⊤ := by ext Z h simp only [top_apply, iff_true] rw [mem_ofObjects_iff ] exact ⟨i, ⟨h ≫ g⟩⟩ /-- Push a sieve `R` on `Y` forward along an arrow `f : Y ⟶ X`: `gf : Z ⟶ X` is in the sieve if `gf` factors through some `g : Z ⟶ Y` which is in `R`. -/ @[simps] def pushforward (f : Y ⟶ X) (R : Sieve Y) : Sieve X where arrows _ gf := ∃ g, g ≫ f = gf ∧ R g downward_closed := fun ⟨j, k, z⟩ h => ⟨h ≫ j, by simp [k], by simp [z]⟩ theorem pushforward_apply_comp {R : Sieve Y} {Z : C} {g : Z ⟶ Y} (hg : R g) (f : Y ⟶ X) : R.pushforward f (g ≫ f) := ⟨g, rfl, hg⟩ theorem pushforward_comp {f : Y ⟶ X} {g : Z ⟶ Y} (R : Sieve Z) : R.pushforward (g ≫ f) = (R.pushforward g).pushforward f := Sieve.ext fun W h => ⟨fun ⟨f₁, hq, hf₁⟩ => ⟨f₁ ≫ g, by simpa, f₁, rfl, hf₁⟩, fun ⟨y, hy, z, hR, hz⟩ => ⟨z, by rw [← Category.assoc, hR]; tauto⟩⟩ theorem galoisConnection (f : Y ⟶ X) : GaloisConnection (Sieve.pushforward f) (Sieve.pullback f) := fun _ _ => ⟨fun hR _ g hg => hR _ ⟨g, rfl, hg⟩, fun hS _ _ ⟨h, hg, hh⟩ => hg ▸ hS h hh⟩ theorem pullback_monotone (f : Y ⟶ X) : Monotone (Sieve.pullback f) := (galoisConnection f).monotone_u theorem pushforward_monotone (f : Y ⟶ X) : Monotone (Sieve.pushforward f) := (galoisConnection f).monotone_l theorem le_pushforward_pullback (f : Y ⟶ X) (R : Sieve Y) : R ≤ (R.pushforward f).pullback f := (galoisConnection f).le_u_l _ theorem pullback_pushforward_le (f : Y ⟶ X) (R : Sieve X) : (R.pullback f).pushforward f ≤ R := (galoisConnection f).l_u_le _ theorem pushforward_union {f : Y ⟶ X} (S R : Sieve Y) : (S ⊔ R).pushforward f = S.pushforward f ⊔ R.pushforward f := (galoisConnection f).l_sup theorem pushforward_le_bind_of_mem (S : Presieve X) (R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) (f : Y ⟶ X) (h : S f) : (R h).pushforward f ≤ bind S R := by rintro Z _ ⟨g, rfl, hg⟩ exact ⟨_, g, f, h, hg, rfl⟩ theorem le_pullback_bind (S : Presieve X) (R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) (f : Y ⟶ X) (h : S f) : R h ≤ (bind S R).pullback f := by rw [← galoisConnection f] apply pushforward_le_bind_of_mem /-- If `f` is a monomorphism, the pushforward-pullback adjunction on sieves is coreflective. -/ def galoisCoinsertionOfMono (f : Y ⟶ X) [Mono f] : GaloisCoinsertion (Sieve.pushforward f) (Sieve.pullback f) := by apply (galoisConnection f).toGaloisCoinsertion rintro S Z g ⟨g₁, hf, hg₁⟩ rw [cancel_mono f] at hf rwa [← hf] /-- If `f` is a split epi, the pushforward-pullback adjunction on sieves is reflective. -/ def galoisInsertionOfIsSplitEpi (f : Y ⟶ X) [IsSplitEpi f] : GaloisInsertion (Sieve.pushforward f) (Sieve.pullback f) := by apply (galoisConnection f).toGaloisInsertion intro S Z g hg exact ⟨g ≫ section_ f, by simpa⟩ theorem pullbackArrows_comm [HasPullbacks C] {X Y : C} (f : Y ⟶ X) (R : Presieve X) : Sieve.generate (R.pullbackArrows f) = (Sieve.generate R).pullback f := by ext W g constructor · rintro ⟨_, h, k, ⟨W, g, hg⟩, rfl⟩ rw [Sieve.pullback_apply, assoc, ← pullback.condition, ← assoc] exact Sieve.downward_closed _ (by exact Sieve.le_generate R W hg) (h ≫ pullback.fst g f) · rintro ⟨W, h, k, hk, comm⟩ exact ⟨_, _, _, Presieve.pullbackArrows.mk _ _ hk, pullback.lift_snd _ _ comm⟩ section Functor variable {E : Type u₃} [Category.{v₃} E] (G : D ⥤ E) /-- If `R` is a sieve, then the `CategoryTheory.Presieve.functorPullback` of `R` is actually a sieve. -/ @[simps] def functorPullback (R : Sieve (F.obj X)) : Sieve X where arrows := Presieve.functorPullback F R downward_closed := by intro _ _ f hf g unfold Presieve.functorPullback rw [F.map_comp] exact R.downward_closed hf (F.map g) @[simp] theorem functorPullback_arrows (R : Sieve (F.obj X)) : (R.functorPullback F).arrows = R.arrows.functorPullback F := rfl @[simp] theorem functorPullback_id (R : Sieve X) : R.functorPullback (𝟭 _) = R := by ext rfl theorem functorPullback_comp (R : Sieve ((F ⋙ G).obj X)) : R.functorPullback (F ⋙ G) = (R.functorPullback G).functorPullback F := by ext rfl theorem functorPushforward_extend_eq {R : Presieve X} : (generate R).arrows.functorPushforward F = R.functorPushforward F := by funext Y ext f constructor · rintro ⟨X', g, f', ⟨X'', g', f'', h₁, rfl⟩, rfl⟩ exact ⟨X'', f'', f' ≫ F.map g', h₁, by simp⟩ · rintro ⟨X', g, f', h₁, h₂⟩ exact ⟨X', g, f', le_generate R _ h₁, h₂⟩ /-- The sieve generated by the image of `R` under `F`. -/ @[simps] def functorPushforward (R : Sieve X) : Sieve (F.obj X) where arrows := R.arrows.functorPushforward F downward_closed := by intro _ _ f h g obtain ⟨X, α, β, hα, rfl⟩ := h exact ⟨X, α, g ≫ β, hα, by simp⟩ @[simp] theorem functorPushforward_id (R : Sieve X) : R.functorPushforward (𝟭 _) = R := by ext X f constructor · intro hf obtain ⟨X, g, h, hg, rfl⟩ := hf exact R.downward_closed hg h · intro hf exact ⟨X, f, 𝟙 _, hf, by simp⟩ theorem functorPushforward_comp (R : Sieve X) : R.functorPushforward (F ⋙ G) = (R.functorPushforward F).functorPushforward G := by ext simp [R.arrows.functorPushforward_comp F G] theorem functor_galoisConnection (X : C) : GaloisConnection (Sieve.functorPushforward F : Sieve X → Sieve (F.obj X)) (Sieve.functorPullback F) := by intro R S constructor · intro hle X f hf apply hle refine ⟨X, f, 𝟙 _, hf, ?_⟩ rw [id_comp] · rintro hle Y f ⟨X, g, h, hg, rfl⟩ apply Sieve.downward_closed S exact hle g hg theorem functorPullback_monotone (X : C) : Monotone (Sieve.functorPullback F : Sieve (F.obj X) → Sieve X) := (functor_galoisConnection F X).monotone_u theorem functorPushforward_monotone (X : C) : Monotone (Sieve.functorPushforward F : Sieve X → Sieve (F.obj X)) := (functor_galoisConnection F X).monotone_l theorem le_functorPushforward_pullback (R : Sieve X) : R ≤ (R.functorPushforward F).functorPullback F := (functor_galoisConnection F X).le_u_l _ theorem functorPullback_pushforward_le (R : Sieve (F.obj X)) : (R.functorPullback F).functorPushforward F ≤ R := (functor_galoisConnection F X).l_u_le _ theorem functorPushforward_union (S R : Sieve X) : (S ⊔ R).functorPushforward F = S.functorPushforward F ⊔ R.functorPushforward F := (functor_galoisConnection F X).l_sup theorem functorPullback_union (S R : Sieve (F.obj X)) : (S ⊔ R).functorPullback F = S.functorPullback F ⊔ R.functorPullback F := rfl theorem functorPullback_inter (S R : Sieve (F.obj X)) : (S ⊓ R).functorPullback F = S.functorPullback F ⊓ R.functorPullback F := rfl @[simp] theorem functorPushforward_bot (F : C ⥤ D) (X : C) : (⊥ : Sieve X).functorPushforward F = ⊥ := (functor_galoisConnection F X).l_bot @[simp] theorem functorPushforward_top (F : C ⥤ D) (X : C) : (⊤ : Sieve X).functorPushforward F = ⊤ := by refine (generate_sieve _).symm.trans ?_ apply generate_of_contains_isSplitEpi (𝟙 (F.obj X)) exact ⟨X, 𝟙 _, 𝟙 _, trivial, by simp⟩ @[simp] theorem functorPullback_bot (F : C ⥤ D) (X : C) : (⊥ : Sieve (F.obj X)).functorPullback F = ⊥ := rfl @[simp] theorem functorPullback_top (F : C ⥤ D) (X : C) : (⊤ : Sieve (F.obj X)).functorPullback F = ⊤ := rfl theorem image_mem_functorPushforward (R : Sieve X) {V} {f : V ⟶ X} (h : R f) : R.functorPushforward F (F.map f) := ⟨V, f, 𝟙 _, h, by simp⟩ /-- When `F` is essentially surjective and full, the galois connection is a galois insertion. -/ def essSurjFullFunctorGaloisInsertion [F.EssSurj] [F.Full] (X : C) : GaloisInsertion (Sieve.functorPushforward F : Sieve X → Sieve (F.obj X)) (Sieve.functorPullback F) := by apply (functor_galoisConnection F X).toGaloisInsertion intro S Y f hf refine ⟨_, F.preimage ((F.objObjPreimageIso Y).hom ≫ f), (F.objObjPreimageIso Y).inv, ?_⟩ simpa using hf /-- When `F` is fully faithful, the galois connection is a galois coinsertion. -/ def fullyFaithfulFunctorGaloisCoinsertion [F.Full] [F.Faithful] (X : C) : GaloisCoinsertion (Sieve.functorPushforward F : Sieve X → Sieve (F.obj X)) (Sieve.functorPullback F) := by apply (functor_galoisConnection F X).toGaloisCoinsertion rintro S Y f ⟨Z, g, h, h₁, h₂⟩ rw [← F.map_preimage h, ← F.map_comp] at h₂ rw [F.map_injective h₂] exact S.downward_closed h₁ _ lemma functorPushforward_functor (S : Sieve X) (e : C ≌ D) : S.functorPushforward e.functor = (S.pullback (e.unitInv.app X)).functorPullback e.inverse := by ext Y iYX constructor · rintro ⟨Z, iZX, iYZ, hiZX, rfl⟩ simpa using S.downward_closed hiZX (e.inverse.map iYZ ≫ e.unitInv.app Z) · intro H exact ⟨_, e.inverse.map iYX ≫ e.unitInv.app X, e.counitInv.app Y, by simpa using H, by simp⟩
@[simp] lemma mem_functorPushforward_functor {Y : D} {S : Sieve X} {e : C ≌ D} {f : Y ⟶ e.functor.obj X} : S.functorPushforward e.functor f ↔ S (e.inverse.map f ≫ e.unitInv.app X) :=
Mathlib/CategoryTheory/Sites/Sieves.lean
787
789
/- 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.Group.Action.Pi import Mathlib.Algebra.Group.End import Mathlib.Algebra.Module.NatInt import Mathlib.Algebra.Order.Archimedean.Basic /-! # Maps (semi)conjugating a shift to a shift Denote by $S^1$ the unit circle `UnitAddCircle`. A common way to study a self-map $f\colon S^1\to S^1$ of degree `1` is to lift it to a map $\tilde f\colon \mathbb R\to \mathbb R$ such that $\tilde f(x + 1) = \tilde f(x)+1$ for all `x`. In this file we define a structure and a typeclass for bundled maps satisfying `f (x + a) = f x + b`. We use parameters `a` and `b` instead of `1` to accommodate for two use cases: - maps between circles of different lengths; - self-maps $f\colon S^1\to S^1$ of degree other than one, including orientation-reversing maps. -/ assert_not_exists Finset open Function Set /-- A bundled map `f : G → H` such that `f (x + a) = f x + b` for all `x`, denoted as `f: G →+c[a, b] H`. One can think about `f` as a lift to `G` of a map between two `AddCircle`s. -/ structure AddConstMap (G H : Type*) [Add G] [Add H] (a : G) (b : H) where /-- The underlying function of an `AddConstMap`. Use automatic coercion to function instead. -/ protected toFun : G → H /-- An `AddConstMap` satisfies `f (x + a) = f x + b`. Use `map_add_const` instead. -/ map_add_const' (x : G) : toFun (x + a) = toFun x + b @[inherit_doc] scoped [AddConstMap] notation:25 G " →+c[" a ", " b "] " H => AddConstMap G H a b /-- Typeclass for maps satisfying `f (x + a) = f x + b`. Note that `a` and `b` are `outParam`s, so one should not add instances like `[AddConstMapClass F G H a b] : AddConstMapClass F G H (-a) (-b)`. -/ class AddConstMapClass (F : Type*) (G H : outParam Type*) [Add G] [Add H] (a : outParam G) (b : outParam H) [FunLike F G H] : Prop where /-- A map of `AddConstMapClass` class semiconjugates shift by `a` to the shift by `b`: `∀ x, f (x + a) = f x + b`. -/ map_add_const (f : F) (x : G) : f (x + a) = f x + b namespace AddConstMapClass /-! ### Properties of `AddConstMapClass` maps In this section we prove properties like `f (x + n • a) = f x + n • b`. -/ scoped [AddConstMapClass] attribute [simp] map_add_const variable {F G H : Type*} [FunLike F G H] {a : G} {b : H} protected theorem semiconj [Add G] [Add H] [AddConstMapClass F G H a b] (f : F) : Semiconj f (· + a) (· + b) := map_add_const f @[scoped simp] theorem map_add_nsmul [AddMonoid G] [AddMonoid H] [AddConstMapClass F G H a b] (f : F) (x : G) (n : ℕ) : f (x + n • a) = f x + n • b := by simpa using (AddConstMapClass.semiconj f).iterate_right n x @[scoped simp] theorem map_add_nat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℕ) : f (x + n) = f x + n • b := by simp [← map_add_nsmul] theorem map_add_one [AddMonoidWithOne G] [Add H] [AddConstMapClass F G H 1 b] (f : F) (x : G) : f (x + 1) = f x + b := map_add_const f x @[scoped simp] theorem map_add_ofNat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℕ) [n.AtLeastTwo] : f (x + ofNat(n)) = f x + (ofNat(n) : ℕ) • b := map_add_nat' f x n theorem map_add_nat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (x : G) (n : ℕ) : f (x + n) = f x + n := by simp theorem map_add_ofNat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (x : G) (n : ℕ) [n.AtLeastTwo] : f (x + ofNat(n)) = f x + ofNat(n) := map_add_nat f x n @[scoped simp] theorem map_const [AddZeroClass G] [Add H] [AddConstMapClass F G H a b] (f : F) : f a = f 0 + b := by simpa using map_add_const f 0 theorem map_one [AddZeroClass G] [One G] [Add H] [AddConstMapClass F G H 1 b] (f : F) : f 1 = f 0 + b := map_const f @[scoped simp] theorem map_nsmul_const [AddMonoid G] [AddMonoid H] [AddConstMapClass F G H a b] (f : F) (n : ℕ) : f (n • a) = f 0 + n • b := by simpa using map_add_nsmul f 0 n @[scoped simp] theorem map_nat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (n : ℕ) : f n = f 0 + n • b := by simpa using map_add_nat' f 0 n theorem map_ofNat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (n : ℕ) [n.AtLeastTwo] : f (ofNat(n)) = f 0 + (ofNat(n) : ℕ) • b := map_nat' f n theorem map_nat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (n : ℕ) : f n = f 0 + n := by simp theorem map_ofNat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (n : ℕ) [n.AtLeastTwo] : f ofNat(n) = f 0 + ofNat(n) := map_nat f n @[scoped simp] theorem map_const_add [AddCommMagma G] [Add H] [AddConstMapClass F G H a b] (f : F) (x : G) : f (a + x) = f x + b := by rw [add_comm, map_add_const] theorem map_one_add [AddCommMonoidWithOne G] [Add H] [AddConstMapClass F G H 1 b] (f : F) (x : G) : f (1 + x) = f x + b := map_const_add f x
@[scoped simp] theorem map_nsmul_add [AddCommMonoid G] [AddMonoid H] [AddConstMapClass F G H a b] (f : F) (n : ℕ) (x : G) : f (n • a + x) = f x + n • b := by
Mathlib/Algebra/AddConstMap/Basic.lean
138
140
/- 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.CategoryTheory.Sites.Over /-! Internal hom of sheaves In this file, given two sheaves `F` and `G` on a site `(C, J)` with values in a category `A`, we define a sheaf of types `sheafHom F G` which sends `X : C` to the type of morphisms between the restrictions of `F` and `G` to the categories `Over X`. We first define `presheafHom F G` when `F` and `G` are presheaves `Cᵒᵖ ⥤ A` and show that it is a sheaf when `G` is a sheaf. TODO: - turn both `presheafHom` and `sheafHom` into bifunctors - for a sheaf of types `F`, the `sheafHom` functor from `F` is right-adjoint to the product functor with `F`, i.e. for all `X` and `Y`, there is a natural bijection `(X ⨯ F ⟶ Y) ≃ (X ⟶ sheafHom F Y)`. - use these results in order to show that the category of sheaves of types is Cartesian closed -/ universe v v' u u' namespace CategoryTheory open Category Opposite Limits variable {C : Type u} [Category.{v} C] {J : GrothendieckTopology C} {A : Type u'} [Category.{v'} A] variable (F G : Cᵒᵖ ⥤ A) /-- Given two presheaves `F` and `G` on a category `C` with values in a category `A`, this `presheafHom F G` is the presheaf of types which sends an object `X : C` to the type of morphisms between the "restrictions" of `F` and `G` to the category `Over X`. -/ @[simps! obj] def presheafHom : Cᵒᵖ ⥤ Type _ where obj X := (Over.forget X.unop).op ⋙ F ⟶ (Over.forget X.unop).op ⋙ G map f := whiskerLeft (Over.map f.unop).op map_id := by rintro ⟨X⟩ ext φ ⟨Y⟩ simpa [Over.mapId] using φ.naturality ((Over.mapId X).hom.app Y).op map_comp := by rintro ⟨X⟩ ⟨Y⟩ ⟨Z⟩ ⟨f : Y ⟶ X⟩ ⟨g : Z ⟶ Y⟩ ext φ ⟨W⟩ simpa [Over.mapComp] using φ.naturality ((Over.mapComp g f).hom.app W).op variable {F G} /-- Equational lemma for the presheaf structure on `presheafHom`. It is advisable to use this lemma rather than `dsimp [presheafHom]` which may result in the need to prove equalities of objects in an `Over` category. -/ lemma presheafHom_map_app {X Y Z : C} (f : Z ⟶ Y) (g : Y ⟶ X) (h : Z ⟶ X) (w : f ≫ g = h) (α : (presheafHom F G).obj (op X)) : ((presheafHom F G).map g.op α).app (op (Over.mk f)) = α.app (op (Over.mk h)) := by subst w rfl @[simp] lemma presheafHom_map_app_op_mk_id {X Y : C} (g : Y ⟶ X) (α : (presheafHom F G).obj (op X)) : ((presheafHom F G).map g.op α).app (op (Over.mk (𝟙 Y))) = α.app (op (Over.mk g)) := presheafHom_map_app (𝟙 Y) g g (by simp) α variable (F G) /-- The sections of the presheaf `presheafHom F G` identify to morphisms `F ⟶ G`. -/ def presheafHomSectionsEquiv : (presheafHom F G).sections ≃ (F ⟶ G) where toFun s := { app := fun X => (s.1 X).app ⟨Over.mk (𝟙 _)⟩ naturality := by rintro ⟨X₁⟩ ⟨X₂⟩ ⟨f : X₂ ⟶ X₁⟩ dsimp refine Eq.trans ?_ ((s.1 ⟨X₁⟩).naturality (Over.homMk f : Over.mk f ⟶ Over.mk (𝟙 X₁)).op) rw [← s.2 f.op, presheafHom_map_app_op_mk_id] rfl } invFun f := ⟨fun _ => whiskerLeft _ f, fun _ => rfl⟩ left_inv s := by dsimp ext ⟨X⟩ ⟨Y : Over X⟩ have H := s.2 Y.hom.op dsimp at H ⊢ rw [← H] apply presheafHom_map_app_op_mk_id right_inv _ := rfl variable {F G} lemma PresheafHom.isAmalgamation_iff {X : C} (S : Sieve X) (x : Presieve.FamilyOfElements (presheafHom F G) S.arrows) (hx : x.Compatible) (y : (presheafHom F G).obj (op X)) : x.IsAmalgamation y ↔ ∀ (Y : C) (g : Y ⟶ X) (hg : S g), y.app (op (Over.mk g)) = (x g hg).app (op (Over.mk (𝟙 Y))) := by constructor · intro h Y g hg rw [← h g hg, presheafHom_map_app_op_mk_id] · intro h Y g hg dsimp ext ⟨W : Over Y⟩ refine (h W.left (W.hom ≫ g) (S.downward_closed hg _)).trans ?_ have H := hx (𝟙 _) W.hom (S.downward_closed hg W.hom) hg (by simp) dsimp at H simp only [Functor.map_id, FunctorToTypes.map_id_apply] at H rw [H, presheafHom_map_app_op_mk_id] rfl section variable {X : C} {S : Sieve X} (hG : ∀ ⦃Y : C⦄ (f : Y ⟶ X), IsLimit (G.mapCone (S.pullback f).arrows.cocone.op)) namespace PresheafHom.IsSheafFor variable (x : Presieve.FamilyOfElements (presheafHom F G) S.arrows) {Y : C} include hG in lemma exists_app (hx : x.Compatible) (g : Y ⟶ X) : ∃ (φ : F.obj (op Y) ⟶ G.obj (op Y)), ∀ {Z : C} (p : Z ⟶ Y) (hp : S (p ≫ g)), φ ≫ G.map p.op = F.map p.op ≫ (x (p ≫ g) hp).app ⟨Over.mk (𝟙 Z)⟩ := by let c : Cone ((Presieve.diagram (Sieve.pullback g S).arrows).op ⋙ G) := { pt := F.obj (op Y) π := { app := fun ⟨Z, hZ⟩ => F.map Z.hom.op ≫ (x _ hZ).app (op (Over.mk (𝟙 _))) naturality := by rintro ⟨Z₁, hZ₁⟩ ⟨Z₂, hZ₂⟩ ⟨f : Z₂ ⟶ Z₁⟩ dsimp rw [id_comp, assoc] have H := hx f.left (𝟙 _) hZ₁ hZ₂ (by simp) simp only [presheafHom_obj, unop_op, Functor.id_obj, op_id, FunctorToTypes.map_id_apply] at H let φ : Over.mk f.left ⟶ Over.mk (𝟙 Z₁.left) := Over.homMk f.left have H' := (x (Z₁.hom ≫ g) hZ₁).naturality φ.op dsimp at H H' ⊢ erw [← H, ← H', presheafHom_map_app_op_mk_id, ← F.map_comp_assoc, ← op_comp, Over.w f] } } use (hG g).lift c intro Z p hp exact ((hG g).fac c ⟨Over.mk p, hp⟩) /-- Auxiliary definition for `presheafHom_isSheafFor`. -/ noncomputable def app (hx : x.Compatible) (g : Y ⟶ X) : F.obj (op Y) ⟶ G.obj (op Y) := (exists_app hG x hx g).choose lemma app_cond (hx : x.Compatible) (g : Y ⟶ X) {Z : C} (p : Z ⟶ Y) (hp : S (p ≫ g)) : app hG x hx g ≫ G.map p.op = F.map p.op ≫ (x (p ≫ g) hp).app ⟨Over.mk (𝟙 Z)⟩ := (exists_app hG x hx g).choose_spec p hp end PresheafHom.IsSheafFor variable (F G S) include hG in open PresheafHom.IsSheafFor in lemma presheafHom_isSheafFor : Presieve.IsSheafFor (presheafHom F G) S.arrows := by intro x hx apply existsUnique_of_exists_of_unique · refine ⟨ { app := fun Y => app hG x hx Y.unop.hom naturality := by rintro ⟨Y₁ : Over X⟩ ⟨Y₂ : Over X⟩ ⟨φ : Y₂ ⟶ Y₁⟩ apply (hG Y₂.hom).hom_ext rintro ⟨Z : Over Y₂.left, hZ⟩ dsimp rw [assoc, assoc, app_cond hG x hx Y₂.hom Z.hom hZ, ← G.map_comp, ← op_comp] rw [app_cond hG x hx Y₁.hom (Z.hom ≫ φ.left) (by simpa using hZ), ← F.map_comp_assoc, op_comp] congr 3 simp }, ?_⟩ rw [PresheafHom.isAmalgamation_iff _ _ hx] intro Y g hg dsimp have H := app_cond hG x hx g (𝟙 _) (by simpa using hg) rw [op_id, G.map_id, comp_id, F.map_id, id_comp] at H exact H.trans (by congr; simp) · intro y₁ y₂ hy₁ hy₂ rw [PresheafHom.isAmalgamation_iff _ _ hx] at hy₁ hy₂ apply NatTrans.ext ext ⟨Y : Over X⟩ apply (hG Y.hom).hom_ext rintro ⟨Z : Over Y.left, hZ⟩ dsimp let φ : Over.mk (Z.hom ≫ Y.hom) ⟶ Y := Over.homMk Z.hom refine (y₁.naturality φ.op).symm.trans (Eq.trans ?_ (y₂.naturality φ.op)) rw [(hy₁ _ _ hZ), ← ((hy₂ _ _ hZ))] end
variable (F G) lemma Presheaf.IsSheaf.hom (hG : Presheaf.IsSheaf J G) : Presheaf.IsSheaf J (presheafHom F G) := by rw [isSheaf_iff_isSheaf_of_type] intro X S hS
Mathlib/CategoryTheory/Sites/SheafHom.lean
200
205
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Patrick Massot -/ import Mathlib.Algebra.Group.Basic import Mathlib.Data.Set.Function import Mathlib.Order.Interval.Set.Basic import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE /-! # Images of intervals under `(+ d)` The lemmas in this file state that addition maps intervals bijectively. The typeclass `ExistsAddOfLE` is defined specifically to make them work when combined with `OrderedCancelAddCommMonoid`; the lemmas below therefore apply to all `OrderedAddCommGroup`, but also to `ℕ` and `ℝ≥0`, which are not groups. -/ namespace Set variable {M : Type*} [AddCommMonoid M] [PartialOrder M] [IsOrderedCancelAddMonoid M] [ExistsAddOfLE M] (a b c d : M) theorem Ici_add_bij : BijOn (· + d) (Ici a) (Ici (a + d)) := by refine ⟨fun x h => add_le_add_right (mem_Ici.mp h) _, (add_left_injective d).injOn, fun _ h => ?_⟩ obtain ⟨c, rfl⟩ := exists_add_of_le (mem_Ici.mp h) rw [mem_Ici, add_right_comm, add_le_add_iff_right] at h exact ⟨a + c, h, by rw [add_right_comm]⟩ theorem Ioi_add_bij : BijOn (· + d) (Ioi a) (Ioi (a + d)) := by refine ⟨fun x h => add_lt_add_right (mem_Ioi.mp h) _, fun _ _ _ _ h => add_right_cancel h, fun _ h => ?_⟩ obtain ⟨c, rfl⟩ := exists_add_of_le (mem_Ioi.mp h).le rw [mem_Ioi, add_right_comm, add_lt_add_iff_right] at h exact ⟨a + c, h, by rw [add_right_comm]⟩ theorem Icc_add_bij : BijOn (· + d) (Icc a b) (Icc (a + d) (b + d)) := by rw [← Ici_inter_Iic, ← Ici_inter_Iic] exact (Ici_add_bij a d).inter_mapsTo (fun x hx => add_le_add_right hx _) fun x hx => le_of_add_le_add_right hx.2 theorem Ioo_add_bij : BijOn (· + d) (Ioo a b) (Ioo (a + d) (b + d)) := by rw [← Ioi_inter_Iio, ← Ioi_inter_Iio] exact (Ioi_add_bij a d).inter_mapsTo (fun x hx => add_lt_add_right hx _) fun x hx => lt_of_add_lt_add_right hx.2 theorem Ioc_add_bij : BijOn (· + d) (Ioc a b) (Ioc (a + d) (b + d)) := by rw [← Ioi_inter_Iic, ← Ioi_inter_Iic] exact (Ioi_add_bij a d).inter_mapsTo (fun x hx => add_le_add_right hx _) fun x hx => le_of_add_le_add_right hx.2 theorem Ico_add_bij : BijOn (· + d) (Ico a b) (Ico (a + d) (b + d)) := by rw [← Ici_inter_Iio, ← Ici_inter_Iio] exact (Ici_add_bij a d).inter_mapsTo (fun x hx => add_lt_add_right hx _) fun x hx => lt_of_add_lt_add_right hx.2 /-! ### Images under `x ↦ x + a` -/ @[simp] theorem image_add_const_Ici : (fun x => x + a) '' Ici b = Ici (b + a) := (Ici_add_bij _ _).image_eq @[simp] theorem image_add_const_Ioi : (fun x => x + a) '' Ioi b = Ioi (b + a) := (Ioi_add_bij _ _).image_eq @[simp] theorem image_add_const_Icc : (fun x => x + a) '' Icc b c = Icc (b + a) (c + a) := (Icc_add_bij _ _ _).image_eq @[simp] theorem image_add_const_Ico : (fun x => x + a) '' Ico b c = Ico (b + a) (c + a) := (Ico_add_bij _ _ _).image_eq @[simp] theorem image_add_const_Ioc : (fun x => x + a) '' Ioc b c = Ioc (b + a) (c + a) := (Ioc_add_bij _ _ _).image_eq @[simp] theorem image_add_const_Ioo : (fun x => x + a) '' Ioo b c = Ioo (b + a) (c + a) := (Ioo_add_bij _ _ _).image_eq /-! ### Images under `x ↦ a + x` -/ @[simp] theorem image_const_add_Ici : (fun x => a + x) '' Ici b = Ici (a + b) := by simp only [add_comm a, image_add_const_Ici] @[simp] theorem image_const_add_Ioi : (fun x => a + x) '' Ioi b = Ioi (a + b) := by simp only [add_comm a, image_add_const_Ioi] @[simp] theorem image_const_add_Icc : (fun x => a + x) '' Icc b c = Icc (a + b) (a + c) := by simp only [add_comm a, image_add_const_Icc] @[simp] theorem image_const_add_Ico : (fun x => a + x) '' Ico b c = Ico (a + b) (a + c) := by simp only [add_comm a, image_add_const_Ico] @[simp] theorem image_const_add_Ioc : (fun x => a + x) '' Ioc b c = Ioc (a + b) (a + c) := by simp only [add_comm a, image_add_const_Ioc] @[simp] theorem image_const_add_Ioo : (fun x => a + x) '' Ioo b c = Ioo (a + b) (a + c) := by simp only [add_comm a, image_add_const_Ioo] end Set
Mathlib/Algebra/Order/Interval/Set/Monoid.lean
128
129
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.FieldTheory.RatFunc.Defs import Mathlib.RingTheory.EuclideanDomain import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Polynomial.Content /-! # The field structure of rational functions ## Main definitions Working with rational functions as polynomials: - `RatFunc.instField` provides a field structure You can use `IsFractionRing` API to treat `RatFunc` as the field of fractions of polynomials: * `algebraMap K[X] (RatFunc K)` maps polynomials to rational functions * `IsFractionRing.algEquiv` maps other fields of fractions of `K[X]` to `RatFunc K`, in particular: * `FractionRing.algEquiv K[X] (RatFunc K)` maps the generic field of fraction construction to `RatFunc K`. Combine this with `AlgEquiv.restrictScalars` to change the `FractionRing K[X] ≃ₐ[K[X]] RatFunc K` to `FractionRing K[X] ≃ₐ[K] RatFunc K`. Working with rational functions as fractions: - `RatFunc.num` and `RatFunc.denom` give the numerator and denominator. These values are chosen to be coprime and such that `RatFunc.denom` is monic. Lifting homomorphisms of polynomials to other types, by mapping and dividing, as long as the homomorphism retains the non-zero-divisor property: - `RatFunc.liftMonoidWithZeroHom` lifts a `K[X] →*₀ G₀` to a `RatFunc K →*₀ G₀`, where `[CommRing K] [CommGroupWithZero G₀]` - `RatFunc.liftRingHom` lifts a `K[X] →+* L` to a `RatFunc K →+* L`, where `[CommRing K] [Field L]` - `RatFunc.liftAlgHom` lifts a `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L`, where `[CommRing K] [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L]` This is satisfied by injective homs. We also have lifting homomorphisms of polynomials to other polynomials, with the same condition on retaining the non-zero-divisor property across the map: - `RatFunc.map` lifts `K[X] →* R[X]` when `[CommRing K] [CommRing R]` - `RatFunc.mapRingHom` lifts `K[X] →+* R[X]` when `[CommRing K] [CommRing R]` - `RatFunc.mapAlgHom` lifts `K[X] →ₐ[S] R[X]` when `[CommRing K] [IsDomain K] [CommRing R] [IsDomain R]` -/ universe u v noncomputable section open scoped nonZeroDivisors Polynomial variable {K : Type u} namespace RatFunc section Field variable [CommRing K] /-- The zero rational function. -/ protected irreducible_def zero : RatFunc K := ⟨0⟩ instance : Zero (RatFunc K) := ⟨RatFunc.zero⟩ theorem ofFractionRing_zero : (ofFractionRing 0 : RatFunc K) = 0 := zero_def.symm /-- Addition of rational functions. -/ protected irreducible_def add : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p + q⟩ instance : Add (RatFunc K) := ⟨RatFunc.add⟩ theorem ofFractionRing_add (p q : FractionRing K[X]) : ofFractionRing (p + q) = ofFractionRing p + ofFractionRing q := (add_def _ _).symm /-- Subtraction of rational functions. -/ protected irreducible_def sub : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p - q⟩ instance : Sub (RatFunc K) := ⟨RatFunc.sub⟩ theorem ofFractionRing_sub (p q : FractionRing K[X]) : ofFractionRing (p - q) = ofFractionRing p - ofFractionRing q := (sub_def _ _).symm /-- Additive inverse of a rational function. -/ protected irreducible_def neg : RatFunc K → RatFunc K | ⟨p⟩ => ⟨-p⟩ instance : Neg (RatFunc K) := ⟨RatFunc.neg⟩ theorem ofFractionRing_neg (p : FractionRing K[X]) : ofFractionRing (-p) = -ofFractionRing p := (neg_def _).symm /-- The multiplicative unit of rational functions. -/ protected irreducible_def one : RatFunc K := ⟨1⟩ instance : One (RatFunc K) := ⟨RatFunc.one⟩ theorem ofFractionRing_one : (ofFractionRing 1 : RatFunc K) = 1 := one_def.symm /-- Multiplication of rational functions. -/ protected irreducible_def mul : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p * q⟩ instance : Mul (RatFunc K) := ⟨RatFunc.mul⟩ theorem ofFractionRing_mul (p q : FractionRing K[X]) : ofFractionRing (p * q) = ofFractionRing p * ofFractionRing q := (mul_def _ _).symm section IsDomain variable [IsDomain K] /-- Division of rational functions. -/ protected irreducible_def div : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p / q⟩ instance : Div (RatFunc K) := ⟨RatFunc.div⟩ theorem ofFractionRing_div (p q : FractionRing K[X]) : ofFractionRing (p / q) = ofFractionRing p / ofFractionRing q := (div_def _ _).symm /-- Multiplicative inverse of a rational function. -/ protected irreducible_def inv : RatFunc K → RatFunc K | ⟨p⟩ => ⟨p⁻¹⟩ instance : Inv (RatFunc K) := ⟨RatFunc.inv⟩ theorem ofFractionRing_inv (p : FractionRing K[X]) : ofFractionRing p⁻¹ = (ofFractionRing p)⁻¹ := (inv_def _).symm -- Auxiliary lemma for the `Field` instance theorem mul_inv_cancel : ∀ {p : RatFunc K}, p ≠ 0 → p * p⁻¹ = 1 | ⟨p⟩, h => by have : p ≠ 0 := fun hp => h <| by rw [hp, ofFractionRing_zero] simpa only [← ofFractionRing_inv, ← ofFractionRing_mul, ← ofFractionRing_one, ofFractionRing.injEq] using mul_inv_cancel₀ this end IsDomain section SMul variable {R : Type*} /-- Scalar multiplication of rational functions. -/ protected irreducible_def smul [SMul R (FractionRing K[X])] : R → RatFunc K → RatFunc K | r, ⟨p⟩ => ⟨r • p⟩ instance [SMul R (FractionRing K[X])] : SMul R (RatFunc K) := ⟨RatFunc.smul⟩ theorem ofFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : FractionRing K[X]) : ofFractionRing (c • p) = c • ofFractionRing p := (smul_def _ _).symm theorem toFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : RatFunc K) : toFractionRing (c • p) = c • toFractionRing p := by cases p rw [← ofFractionRing_smul] theorem smul_eq_C_smul (x : RatFunc K) (r : K) : r • x = Polynomial.C r • x := by obtain ⟨x⟩ := x induction x using Localization.induction_on rw [← ofFractionRing_smul, ← ofFractionRing_smul, Localization.smul_mk, Localization.smul_mk, smul_eq_mul, Polynomial.smul_eq_C_mul] section IsDomain variable [IsDomain K] variable [Monoid R] [DistribMulAction R K[X]] variable [IsScalarTower R K[X] K[X]] theorem mk_smul (c : R) (p q : K[X]) : RatFunc.mk (c • p) q = c • RatFunc.mk p q := by letI : SMulZeroClass R (FractionRing K[X]) := inferInstance by_cases hq : q = 0 · rw [hq, mk_zero, mk_zero, ← ofFractionRing_smul, smul_zero] · rw [mk_eq_localization_mk _ hq, mk_eq_localization_mk _ hq, ← Localization.smul_mk, ← ofFractionRing_smul] instance : IsScalarTower R K[X] (RatFunc K) := ⟨fun c p q => q.induction_on' fun q r _ => by rw [← mk_smul, smul_assoc, mk_smul, mk_smul]⟩ end IsDomain end SMul variable (K) instance [Subsingleton K] : Subsingleton (RatFunc K) := toFractionRing_injective.subsingleton instance : Inhabited (RatFunc K) := ⟨0⟩ instance instNontrivial [Nontrivial K] : Nontrivial (RatFunc K) := ofFractionRing_injective.nontrivial /-- `RatFunc K` is isomorphic to the field of fractions of `K[X]`, as rings. This is an auxiliary definition; `simp`-normal form is `IsLocalization.algEquiv`. -/ @[simps apply] def toFractionRingRingEquiv : RatFunc K ≃+* FractionRing K[X] where toFun := toFractionRing invFun := ofFractionRing left_inv := fun ⟨_⟩ => rfl right_inv _ := rfl map_add' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_add] map_mul' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_mul] end Field section TacticInterlude /-- Solve equations for `RatFunc K` by working in `FractionRing K[X]`. -/ macro "frac_tac" : tactic => `(tactic| · repeat (rintro (⟨⟩ : RatFunc _)) try simp only [← ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_sub, ← ofFractionRing_neg, ← ofFractionRing_one, ← ofFractionRing_mul, ← ofFractionRing_div, ← ofFractionRing_inv, add_assoc, zero_add, add_zero, mul_assoc, mul_zero, mul_one, mul_add, inv_zero, add_comm, add_left_comm, mul_comm, mul_left_comm, sub_eq_add_neg, div_eq_mul_inv, add_mul, zero_mul, one_mul, neg_mul, mul_neg, add_neg_cancel]) /-- Solve equations for `RatFunc K` by applying `RatFunc.induction_on`. -/ macro "smul_tac" : tactic => `(tactic| repeat (first | rintro (⟨⟩ : RatFunc _) | intro) <;> simp_rw [← ofFractionRing_smul] <;> simp only [add_comm, mul_comm, zero_smul, succ_nsmul, zsmul_eq_mul, mul_add, mul_one, mul_zero, neg_add, mul_neg, Int.cast_zero, Int.cast_add, Int.cast_one, Int.cast_negSucc, Int.cast_natCast, Nat.cast_succ, Localization.mk_zero, Localization.add_mk_self, Localization.neg_mk, ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_neg]) end TacticInterlude section CommRing variable (K) [CommRing K] /-- `RatFunc K` is a commutative monoid. This is an intermediate step on the way to the full instance `RatFunc.instCommRing`. -/ def instCommMonoid : CommMonoid (RatFunc K) where mul := (· * ·) mul_assoc := by frac_tac mul_comm := by frac_tac one := 1 one_mul := by frac_tac mul_one := by frac_tac npow := npowRec /-- `RatFunc K` is an additive commutative group. This is an intermediate step on the way to the full instance `RatFunc.instCommRing`. -/ def instAddCommGroup : AddCommGroup (RatFunc K) where add := (· + ·) add_assoc := by frac_tac add_comm := by frac_tac zero := 0 zero_add := by frac_tac add_zero := by frac_tac neg := Neg.neg neg_add_cancel := by frac_tac sub := Sub.sub sub_eq_add_neg := by frac_tac nsmul := (· • ·) nsmul_zero := by smul_tac nsmul_succ _ := by smul_tac zsmul := (· • ·) zsmul_zero' := by smul_tac zsmul_succ' _ := by smul_tac zsmul_neg' _ := by smul_tac instance instCommRing : CommRing (RatFunc K) := { instCommMonoid K, instAddCommGroup K with zero := 0 sub := Sub.sub zero_mul := by frac_tac mul_zero := by frac_tac left_distrib := by frac_tac right_distrib := by frac_tac one := 1 nsmul := (· • ·) zsmul := (· • ·) npow := npowRec } variable {K} section LiftHom open RatFunc variable {G₀ L R S F : Type*} [CommGroupWithZero G₀] [Field L] [CommRing R] [CommRing S] variable [FunLike F R[X] S[X]] open scoped Classical in /-- Lift a monoid homomorphism that maps polynomials `φ : R[X] →* S[X]` to a `RatFunc R →* RatFunc S`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def map [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : RatFunc R →* RatFunc S where toFun f := RatFunc.liftOn f (fun n d => if h : φ d ∈ S[X]⁰ then ofFractionRing (Localization.mk (φ n) ⟨φ d, h⟩) else 0) fun {p q p' q'} hq hq' h => by simp only [Submonoid.mem_comap.mp (hφ hq), Submonoid.mem_comap.mp (hφ hq'), dif_pos, ofFractionRing.injEq, Localization.mk_eq_mk_iff] refine Localization.r_of_eq ?_ simpa only [map_mul] using congr_arg φ h map_one' := by simp_rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk, OneMemClass.coe_one, map_one, OneMemClass.one_mem, dite_true, ofFractionRing.injEq, Localization.mk_one, Localization.mk_eq_monoidOf_mk', Submonoid.LocalizationMap.mk'_self] map_mul' x y := by obtain ⟨x⟩ := x; obtain ⟨y⟩ := y induction' x using Localization.induction_on with pq induction' y using Localization.induction_on with p'q' obtain ⟨p, q⟩ := pq obtain ⟨p', q'⟩ := p'q' have hq : φ q ∈ S[X]⁰ := hφ q.prop have hq' : φ q' ∈ S[X]⁰ := hφ q'.prop have hqq' : φ ↑(q * q') ∈ S[X]⁰ := by simpa using Submonoid.mul_mem _ hq hq' simp_rw [← ofFractionRing_mul, Localization.mk_mul, liftOn_ofFractionRing_mk, dif_pos hq, dif_pos hq', dif_pos hqq', ← ofFractionRing_mul, Submonoid.coe_mul, map_mul, Localization.mk_mul, Submonoid.mk_mul_mk] theorem map_apply_ofFractionRing_mk [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) (n : R[X]) (d : R[X]⁰) : map φ hφ (ofFractionRing (Localization.mk n d)) = ofFractionRing (Localization.mk (φ n) ⟨φ d, hφ d.prop⟩) := by simp only [map, MonoidHom.coe_mk, OneHom.coe_mk, liftOn_ofFractionRing_mk, Submonoid.mem_comap.mp (hφ d.2), ↓reduceDIte] theorem map_injective [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) (hf : Function.Injective φ) : Function.Injective (map φ hφ) := by rintro ⟨x⟩ ⟨y⟩ h induction x using Localization.induction_on induction y using Localization.induction_on simpa only [map_apply_ofFractionRing_mk, ofFractionRing_injective.eq_iff, Localization.mk_eq_mk_iff, Localization.r_iff_exists, mul_cancel_left_coe_nonZeroDivisors, exists_const, ← map_mul, hf.eq_iff] using h /-- Lift a ring homomorphism that maps polynomials `φ : R[X] →+* S[X]` to a `RatFunc R →+* RatFunc S`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def mapRingHom [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : RatFunc R →+* RatFunc S := { map φ hφ with map_zero' := by simp_rw [MonoidHom.toFun_eq_coe, ← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰), ← Localization.mk_zero (1 : S[X]⁰), map_apply_ofFractionRing_mk, map_zero, Localization.mk_eq_mk', IsLocalization.mk'_zero] map_add' := by rintro ⟨x⟩ ⟨y⟩ induction x using Localization.induction_on induction y using Localization.induction_on · simp only [← ofFractionRing_add, Localization.add_mk, map_add, map_mul, MonoidHom.toFun_eq_coe, map_apply_ofFractionRing_mk, Submonoid.coe_mul, -- We have to specify `S[X]⁰` to `mk_mul_mk`, otherwise it will try to rewrite -- the wrong occurrence. Submonoid.mk_mul_mk S[X]⁰] } theorem coe_mapRingHom_eq_coe_map [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : (mapRingHom φ hφ : RatFunc R → RatFunc S) = map φ hφ := rfl -- TODO: Generalize to `FunLike` classes, /-- Lift a monoid with zero homomorphism `R[X] →*₀ G₀` to a `RatFunc R →*₀ G₀` on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def liftMonoidWithZeroHom (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ) : RatFunc R →*₀ G₀ where toFun f := RatFunc.liftOn f (fun p q => φ p / φ q) fun {p q p' q'} hq hq' h => by cases subsingleton_or_nontrivial R · rw [Subsingleton.elim p q, Subsingleton.elim p' q, Subsingleton.elim q' q] rw [div_eq_div_iff, ← map_mul, mul_comm p, h, map_mul, mul_comm] <;> exact nonZeroDivisors.ne_zero (hφ ‹_›) map_one' := by simp_rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk, OneMemClass.coe_one, map_one, div_one] map_mul' x y := by obtain ⟨x⟩ := x obtain ⟨y⟩ := y induction' x using Localization.induction_on with p q induction' y using Localization.induction_on with p' q' rw [← ofFractionRing_mul, Localization.mk_mul] simp only [liftOn_ofFractionRing_mk, div_mul_div_comm, map_mul, Submonoid.coe_mul] map_zero' := by simp_rw [← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰), liftOn_ofFractionRing_mk, map_zero, zero_div] theorem liftMonoidWithZeroHom_apply_ofFractionRing_mk (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ) (n : R[X]) (d : R[X]⁰) : liftMonoidWithZeroHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftOn_ofFractionRing_mk _ _ _ _ theorem liftMonoidWithZeroHom_injective [Nontrivial R] (φ : R[X] →*₀ G₀) (hφ : Function.Injective φ) (hφ' : R[X]⁰ ≤ G₀⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftMonoidWithZeroHom φ hφ') := by rintro ⟨x⟩ ⟨y⟩ induction' x using Localization.induction_on with a induction' y using Localization.induction_on with a' simp_rw [liftMonoidWithZeroHom_apply_ofFractionRing_mk] intro h congr 1 refine Localization.mk_eq_mk_iff.mpr (Localization.r_of_eq (M := R[X]) ?_) have := mul_eq_mul_of_div_eq_div _ _ ?_ ?_ h · rwa [← map_mul, ← map_mul, hφ.eq_iff, mul_comm, mul_comm a'.fst] at this all_goals exact map_ne_zero_of_mem_nonZeroDivisors _ hφ (SetLike.coe_mem _) /-- Lift an injective ring homomorphism `R[X] →+* L` to a `RatFunc R →+* L` by mapping both the numerator and denominator and quotienting them. -/ def liftRingHom (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) : RatFunc R →+* L := { liftMonoidWithZeroHom φ.toMonoidWithZeroHom hφ with map_add' := fun x y => by simp only [ZeroHom.toFun_eq_coe, MonoidWithZeroHom.toZeroHom_coe] cases subsingleton_or_nontrivial R · rw [Subsingleton.elim (x + y) y, Subsingleton.elim x 0, map_zero, zero_add] obtain ⟨x⟩ := x obtain ⟨y⟩ := y induction' x using Localization.induction_on with pq induction' y using Localization.induction_on with p'q' obtain ⟨p, q⟩ := pq obtain ⟨p', q'⟩ := p'q' rw [← ofFractionRing_add, Localization.add_mk] simp only [RingHom.toMonoidWithZeroHom_eq_coe, liftMonoidWithZeroHom_apply_ofFractionRing_mk] rw [div_add_div, div_eq_div_iff] · rw [mul_comm _ p, mul_comm _ p', mul_comm _ (φ p'), add_comm] simp only [map_add, map_mul, Submonoid.coe_mul] all_goals try simp only [← map_mul, ← Submonoid.coe_mul] exact nonZeroDivisors.ne_zero (hφ (SetLike.coe_mem _)) } theorem liftRingHom_apply_ofFractionRing_mk (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) (n : R[X]) (d : R[X]⁰) : liftRingHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _ theorem liftRingHom_injective [Nontrivial R] (φ : R[X] →+* L) (hφ : Function.Injective φ) (hφ' : R[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftRingHom φ hφ') := liftMonoidWithZeroHom_injective _ hφ end LiftHom variable (K) @[stacks 09FK] instance instField [IsDomain K] : Field (RatFunc K) where inv_zero := by frac_tac div := (· / ·) div_eq_mul_inv := by frac_tac mul_inv_cancel _ := mul_inv_cancel zpow := zpowRec nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl section IsFractionRing /-! ### `RatFunc` as field of fractions of `Polynomial` -/ section IsDomain variable [IsDomain K] instance (R : Type*) [CommSemiring R] [Algebra R K[X]] : Algebra R (RatFunc K) where algebraMap := { toFun x := RatFunc.mk (algebraMap _ _ x) 1 map_add' x y := by simp only [mk_one', RingHom.map_add, ofFractionRing_add] map_mul' x y := by simp only [mk_one', RingHom.map_mul, ofFractionRing_mul] map_one' := by simp only [mk_one', RingHom.map_one, ofFractionRing_one] map_zero' := by simp only [mk_one', RingHom.map_zero, ofFractionRing_zero] } smul := (· • ·) smul_def' c x := by induction' x using RatFunc.induction_on' with p q hq rw [RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, mk_one', ← mk_smul, mk_def_of_ne (c • p) hq, mk_def_of_ne p hq, ← ofFractionRing_mul, IsLocalization.mul_mk'_eq_mk'_of_mul, Algebra.smul_def] commutes' _ _ := mul_comm _ _ variable {K} /-- The coercion from polynomials to rational functions, implemented as the algebra map from a domain to its field of fractions -/ @[coe] def coePolynomial (P : Polynomial K) : RatFunc K := algebraMap _ _ P instance : Coe (Polynomial K) (RatFunc K) := ⟨coePolynomial⟩ theorem mk_one (x : K[X]) : RatFunc.mk x 1 = algebraMap _ _ x := rfl theorem ofFractionRing_algebraMap (x : K[X]) : ofFractionRing (algebraMap _ (FractionRing K[X]) x) = algebraMap _ _ x := by rw [← mk_one, mk_one'] @[simp] theorem mk_eq_div (p q : K[X]) : RatFunc.mk p q = algebraMap _ _ p / algebraMap _ _ q := by simp only [mk_eq_div', ofFractionRing_div, ofFractionRing_algebraMap] @[simp] theorem div_smul {R} [Monoid R] [DistribMulAction R K[X]] [IsScalarTower R K[X] K[X]] (c : R) (p q : K[X]) : algebraMap _ (RatFunc K) (c • p) / algebraMap _ _ q = c • (algebraMap _ _ p / algebraMap _ _ q) := by rw [← mk_eq_div, mk_smul, mk_eq_div] theorem algebraMap_apply {R : Type*} [CommSemiring R] [Algebra R K[X]] (x : R) : algebraMap R (RatFunc K) x = algebraMap _ _ (algebraMap R K[X] x) / algebraMap K[X] _ 1 := by rw [← mk_eq_div] rfl theorem map_apply_div_ne_zero {R F : Type*} [CommRing R] [IsDomain R] [FunLike F K[X] R[X]] [MonoidHomClass F K[X] R[X]] (φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) (hq : q ≠ 0) : map φ hφ (algebraMap _ _ p / algebraMap _ _ q) = algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by have hq' : φ q ≠ 0 := nonZeroDivisors.ne_zero (hφ (mem_nonZeroDivisors_iff_ne_zero.mpr hq)) simp only [← mk_eq_div, mk_eq_localization_mk _ hq, map_apply_ofFractionRing_mk, mk_eq_localization_mk _ hq'] @[simp] theorem map_apply_div {R F : Type*} [CommRing R] [IsDomain R] [FunLike F K[X] R[X]] [MonoidWithZeroHomClass F K[X] R[X]] (φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) : map φ hφ (algebraMap _ _ p / algebraMap _ _ q) = algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by rcases eq_or_ne q 0 with (rfl | hq) · have : (0 : RatFunc K) = algebraMap K[X] _ 0 / algebraMap K[X] _ 1 := by simp rw [map_zero, map_zero, map_zero, div_zero, div_zero, this, map_apply_div_ne_zero, map_one, map_one, div_one, map_zero, map_zero] exact one_ne_zero exact map_apply_div_ne_zero _ _ _ _ hq theorem liftMonoidWithZeroHom_apply_div {L : Type*} [CommGroupWithZero L] (φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftMonoidWithZeroHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := by rcases eq_or_ne q 0 with (rfl | hq) · simp only [div_zero, map_zero] simp only [← mk_eq_div, mk_eq_localization_mk _ hq, liftMonoidWithZeroHom_apply_ofFractionRing_mk] @[simp] theorem liftMonoidWithZeroHom_apply_div' {L : Type*} [CommGroupWithZero L] (φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftMonoidWithZeroHom φ hφ (algebraMap _ _ p) / liftMonoidWithZeroHom φ hφ (algebraMap _ _ q) = φ p / φ q := by rw [← map_div₀, liftMonoidWithZeroHom_apply_div] theorem liftRingHom_apply_div {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div _ hφ _ _ @[simp] theorem liftRingHom_apply_div' {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p) / liftRingHom φ hφ (algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div' _ hφ _ _ variable (K) theorem ofFractionRing_comp_algebraMap : ofFractionRing ∘ algebraMap K[X] (FractionRing K[X]) = algebraMap _ _ := funext ofFractionRing_algebraMap theorem algebraMap_injective : Function.Injective (algebraMap K[X] (RatFunc K)) := by rw [← ofFractionRing_comp_algebraMap] exact ofFractionRing_injective.comp (IsFractionRing.injective _ _) variable {K} section LiftAlgHom variable {L R S : Type*} [Field L] [CommRing R] [IsDomain R] [CommSemiring S] [Algebra S K[X]] [Algebra S L] [Algebra S R[X]] (φ : K[X] →ₐ[S] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) /-- Lift an algebra homomorphism that maps polynomials `φ : K[X] →ₐ[S] R[X]` to a `RatFunc K →ₐ[S] RatFunc R`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def mapAlgHom (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) : RatFunc K →ₐ[S] RatFunc R := { mapRingHom φ hφ with commutes' := fun r => by simp_rw [RingHom.toFun_eq_coe, coe_mapRingHom_eq_coe_map, algebraMap_apply r, map_apply_div, map_one, AlgHom.commutes] } theorem coe_mapAlgHom_eq_coe_map (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) : (mapAlgHom φ hφ : RatFunc K → RatFunc R) = map φ hφ := rfl /-- Lift an injective algebra homomorphism `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L` by mapping both the numerator and denominator and quotienting them. -/ def liftAlgHom : RatFunc K →ₐ[S] L := { liftRingHom φ.toRingHom hφ with commutes' := fun r => by simp_rw [RingHom.toFun_eq_coe, AlgHom.toRingHom_eq_coe, algebraMap_apply r, liftRingHom_apply_div, AlgHom.coe_toRingHom, map_one, div_one, AlgHom.commutes] } theorem liftAlgHom_apply_ofFractionRing_mk (n : K[X]) (d : K[X]⁰) : liftAlgHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _ theorem liftAlgHom_injective (φ : K[X] →ₐ[S] L) (hφ : Function.Injective φ) (hφ' : K[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftAlgHom φ hφ') := liftMonoidWithZeroHom_injective _ hφ @[simp] theorem liftAlgHom_apply_div' (p q : K[X]) : liftAlgHom φ hφ (algebraMap _ _ p) / liftAlgHom φ hφ (algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div' _ hφ _ _ theorem liftAlgHom_apply_div (p q : K[X]) : liftAlgHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div _ hφ _ _ end LiftAlgHom variable (K) /-- `RatFunc K` is the field of fractions of the polynomials over `K`. -/ instance : IsFractionRing K[X] (RatFunc K) where map_units' y := by rw [← ofFractionRing_algebraMap] exact (toFractionRingRingEquiv K).symm.toRingHom.isUnit_map (IsLocalization.map_units _ y) exists_of_eq {x y} := by rw [← ofFractionRing_algebraMap, ← ofFractionRing_algebraMap] exact fun h ↦ IsLocalization.exists_of_eq ((toFractionRingRingEquiv K).symm.injective h) surj' := by rintro ⟨z⟩ convert IsLocalization.surj K[X]⁰ z simp only [← ofFractionRing_algebraMap, Function.comp_apply, ← ofFractionRing_mul, ofFractionRing.injEq] variable {K} theorem algebraMap_ne_zero {x : K[X]} (hx : x ≠ 0) : algebraMap K[X] (RatFunc K) x ≠ 0 := by simpa @[simp] theorem liftOn_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1) (H' : ∀ {p q p' q'} (_hq : q ≠ 0) (_hq' : q' ≠ 0), q' * p = q * p' → f p q = f p' q') (H : ∀ {p q p' q'} (_hq : q ∈ K[X]⁰) (_hq' : q' ∈ K[X]⁰), q' * p = q * p' → f p q = f p' q' := fun {_ _ _ _} hq hq' h => H' (nonZeroDivisors.ne_zero hq) (nonZeroDivisors.ne_zero hq') h) : (RatFunc.liftOn (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by rw [← mk_eq_div, liftOn_mk _ _ f f0 @H'] @[simp] theorem liftOn'_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1) (H) : (RatFunc.liftOn' (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by rw [RatFunc.liftOn', liftOn_div _ _ _ f0] apply liftOn_condition_of_liftOn'_condition H /-- Induction principle for `RatFunc K`: if `f p q : P (p / q)` for all `p q : K[X]`, then `P` holds on all elements of `RatFunc K`. See also `induction_on'`, which is a recursion principle defined in terms of `RatFunc.mk`. -/ protected theorem induction_on {P : RatFunc K → Prop} (x : RatFunc K) (f : ∀ (p q : K[X]) (_ : q ≠ 0), P (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) : P x := x.induction_on' fun p q hq => by simpa using f p q hq theorem ofFractionRing_mk' (x : K[X]) (y : K[X]⁰) : ofFractionRing (IsLocalization.mk' _ x y) = IsLocalization.mk' (RatFunc K) x y := by rw [IsFractionRing.mk'_eq_div, IsFractionRing.mk'_eq_div, ← mk_eq_div', ← mk_eq_div] theorem mk_eq_mk' (f : Polynomial K) {g : Polynomial K} (hg : g ≠ 0) : RatFunc.mk f g = IsLocalization.mk' (RatFunc K) f ⟨g, mem_nonZeroDivisors_iff_ne_zero.2 hg⟩ := by simp only [mk_eq_div, IsFractionRing.mk'_eq_div] @[simp] theorem ofFractionRing_eq : (ofFractionRing : FractionRing K[X] → RatFunc K) = IsLocalization.algEquiv K[X]⁰ _ _ := funext fun x => Localization.induction_on x fun x => by simp only [Localization.mk_eq_mk'_apply, ofFractionRing_mk', IsLocalization.algEquiv_apply, IsLocalization.map_mk', RingHom.id_apply] @[simp] theorem toFractionRing_eq : (toFractionRing : RatFunc K → FractionRing K[X]) = IsLocalization.algEquiv K[X]⁰ _ _ := funext fun ⟨x⟩ => Localization.induction_on x fun x => by simp only [Localization.mk_eq_mk'_apply, ofFractionRing_mk', IsLocalization.algEquiv_apply, IsLocalization.map_mk', RingHom.id_apply] @[simp] theorem toFractionRingRingEquiv_symm_eq : (toFractionRingRingEquiv K).symm = (IsLocalization.algEquiv K[X]⁰ _ _).toRingEquiv := by ext x simp [toFractionRingRingEquiv, ofFractionRing_eq, AlgEquiv.coe_ringEquiv'] end IsDomain end IsFractionRing end CommRing section NumDenom /-! ### Numerator and denominator -/ open GCDMonoid Polynomial variable [Field K] open scoped Classical in /-- `RatFunc.numDenom` are numerator and denominator of a rational function over a field, normalized such that the denominator is monic. -/ def numDenom (x : RatFunc K) : K[X] × K[X] := x.liftOn' (fun p q => if q = 0 then ⟨0, 1⟩ else let r := gcd p q ⟨Polynomial.C (q / r).leadingCoeff⁻¹ * (p / r), Polynomial.C (q / r).leadingCoeff⁻¹ * (q / r)⟩) (by intros p q a hq ha dsimp rw [if_neg hq, if_neg (mul_ne_zero ha hq)] have ha' : a.leadingCoeff ≠ 0 := Polynomial.leadingCoeff_ne_zero.mpr ha have hainv : a.leadingCoeff⁻¹ ≠ 0 := inv_ne_zero ha' simp only [Prod.ext_iff, gcd_mul_left, normalize_apply a, Polynomial.coe_normUnit, mul_assoc, CommGroupWithZero.coe_normUnit _ ha'] have hdeg : (gcd p q).degree ≤ q.degree := degree_gcd_le_right _ hq have hdeg' : (Polynomial.C a.leadingCoeff⁻¹ * gcd p q).degree ≤ q.degree := by rw [Polynomial.degree_mul, Polynomial.degree_C hainv, zero_add] exact hdeg have hdivp : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ p := (C_mul_dvd hainv).mpr (gcd_dvd_left p q) have hdivq : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ q := (C_mul_dvd hainv).mpr (gcd_dvd_right p q) rw [EuclideanDomain.mul_div_mul_cancel ha hdivp, EuclideanDomain.mul_div_mul_cancel ha hdivq, leadingCoeff_div hdeg, leadingCoeff_div hdeg', Polynomial.leadingCoeff_mul, Polynomial.leadingCoeff_C, div_C_mul, div_C_mul, ← mul_assoc, ← Polynomial.C_mul, ← mul_assoc, ← Polynomial.C_mul] constructor <;> congr <;> rw [inv_div, mul_comm, mul_div_assoc, ← mul_assoc, inv_inv, mul_inv_cancel₀ ha', one_mul, inv_div]) open scoped Classical in @[simp] theorem numDenom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) : numDenom (algebraMap _ _ p / algebraMap _ _ q) = (Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q), Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q)) := by rw [numDenom, liftOn'_div, if_neg hq] intro p rw [if_pos rfl, if_neg (one_ne_zero' K[X])] simp /-- `RatFunc.num` is the numerator of a rational function, normalized such that the denominator is monic. -/ def num (x : RatFunc K) : K[X] := x.numDenom.1 open scoped Classical in private theorem num_div' (p : K[X]) {q : K[X]} (hq : q ≠ 0) : num (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by rw [num, numDenom_div _ hq] @[simp] theorem num_zero : num (0 : RatFunc K) = 0 := by convert num_div' (0 : K[X]) one_ne_zero <;> simp open scoped Classical in @[simp] theorem num_div (p q : K[X]) : num (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by by_cases hq : q = 0 · simp [hq] · exact num_div' p hq @[simp] theorem num_one : num (1 : RatFunc K) = 1 := by convert num_div (1 : K[X]) 1 <;> simp @[simp] theorem num_algebraMap (p : K[X]) : num (algebraMap _ _ p) = p := by convert num_div p 1 <;> simp theorem num_div_dvd (p : K[X]) {q : K[X]} (hq : q ≠ 0) : num (algebraMap _ _ p / algebraMap _ _ q) ∣ p := by classical rw [num_div _ q, C_mul_dvd] · exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_left p q) · simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq open scoped Classical in /-- A version of `num_div_dvd` with the LHS in simp normal form -/ @[simp] theorem num_div_dvd' (p : K[X]) {q : K[X]} (hq : q ≠ 0) : C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) ∣ p := by simpa using num_div_dvd p hq /-- `RatFunc.denom` is the denominator of a rational function, normalized such that it is monic. -/ def denom (x : RatFunc K) : K[X] := x.numDenom.2 open scoped Classical in @[simp] theorem denom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) : denom (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q) := by rw [denom, numDenom_div _ hq] theorem monic_denom (x : RatFunc K) : (denom x).Monic := by classical induction x using RatFunc.induction_on with | f p q hq => rw [denom_div p hq, mul_comm] exact Polynomial.monic_mul_leadingCoeff_inv (right_div_gcd_ne_zero hq) theorem denom_ne_zero (x : RatFunc K) : denom x ≠ 0 := (monic_denom x).ne_zero @[simp] theorem denom_zero : denom (0 : RatFunc K) = 1 := by convert denom_div (0 : K[X]) one_ne_zero <;> simp @[simp] theorem denom_one : denom (1 : RatFunc K) = 1 := by convert denom_div (1 : K[X]) one_ne_zero <;> simp @[simp] theorem denom_algebraMap (p : K[X]) : denom (algebraMap _ (RatFunc K) p) = 1 := by convert denom_div p one_ne_zero <;> simp @[simp] theorem denom_div_dvd (p q : K[X]) : denom (algebraMap _ _ p / algebraMap _ _ q) ∣ q := by classical by_cases hq : q = 0 · simp [hq] rw [denom_div _ hq, C_mul_dvd] · exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_right p q) · simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq @[simp] theorem num_div_denom (x : RatFunc K) : algebraMap _ _ (num x) / algebraMap _ _ (denom x) = x := by classical induction' x using RatFunc.induction_on with p q hq have q_div_ne_zero : q / gcd p q ≠ 0 := right_div_gcd_ne_zero hq rw [num_div p q, denom_div p hq, RingHom.map_mul, RingHom.map_mul, mul_div_mul_left, div_eq_div_iff, ← RingHom.map_mul, ← RingHom.map_mul, mul_comm _ q, ← EuclideanDomain.mul_div_assoc, ← EuclideanDomain.mul_div_assoc, mul_comm] · apply gcd_dvd_right · apply gcd_dvd_left · exact algebraMap_ne_zero q_div_ne_zero · exact algebraMap_ne_zero hq · refine algebraMap_ne_zero (mt Polynomial.C_eq_zero.mp ?_) exact inv_ne_zero (Polynomial.leadingCoeff_ne_zero.mpr q_div_ne_zero) theorem isCoprime_num_denom (x : RatFunc K) : IsCoprime x.num x.denom := by classical induction' x using RatFunc.induction_on with p q hq rw [num_div, denom_div _ hq] exact (isCoprime_mul_unit_left ((leadingCoeff_ne_zero.2 <| right_div_gcd_ne_zero hq).isUnit.inv.map C) _ _).2 (isCoprime_div_gcd_div_gcd hq) @[simp] theorem num_eq_zero_iff {x : RatFunc K} : num x = 0 ↔ x = 0 := ⟨fun h => by rw [← num_div_denom x, h, RingHom.map_zero, zero_div], fun h => h.symm ▸ num_zero⟩ theorem num_ne_zero {x : RatFunc K} (hx : x ≠ 0) : num x ≠ 0 := mt num_eq_zero_iff.mp hx theorem num_mul_eq_mul_denom_iff {x : RatFunc K} {p q : K[X]} (hq : q ≠ 0) : x.num * q = p * x.denom ↔ x = algebraMap _ _ p / algebraMap _ _ q := by rw [← (algebraMap_injective K).eq_iff, eq_div_iff (algebraMap_ne_zero hq)] conv_rhs => rw [← num_div_denom x] rw [RingHom.map_mul, RingHom.map_mul, div_eq_mul_inv, mul_assoc, mul_comm (Inv.inv _), ← mul_assoc, ← div_eq_mul_inv, div_eq_iff] exact algebraMap_ne_zero (denom_ne_zero x) theorem num_denom_add (x y : RatFunc K) : (x + y).num * (x.denom * y.denom) = (x.num * y.denom + x.denom * y.num) * (x + y).denom := (num_mul_eq_mul_denom_iff (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))).mpr <| by conv_lhs => rw [← num_div_denom x, ← num_div_denom y] rw [div_add_div, RingHom.map_mul, RingHom.map_add, RingHom.map_mul, RingHom.map_mul] · exact algebraMap_ne_zero (denom_ne_zero x) · exact algebraMap_ne_zero (denom_ne_zero y) theorem num_denom_neg (x : RatFunc K) : (-x).num * x.denom = -x.num * (-x).denom := by rw [num_mul_eq_mul_denom_iff (denom_ne_zero x), map_neg, neg_div, num_div_denom] theorem num_denom_mul (x y : RatFunc K) : (x * y).num * (x.denom * y.denom) = x.num * y.num * (x * y).denom := (num_mul_eq_mul_denom_iff (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))).mpr <| by conv_lhs => rw [← num_div_denom x, ← num_div_denom y, div_mul_div_comm, ← RingHom.map_mul, ← RingHom.map_mul] theorem num_dvd {x : RatFunc K} {p : K[X]} (hp : p ≠ 0) : num x ∣ p ↔ ∃ q : K[X], q ≠ 0 ∧ x = algebraMap _ _ p / algebraMap _ _ q := by constructor · rintro ⟨q, rfl⟩ obtain ⟨_hx, hq⟩ := mul_ne_zero_iff.mp hp use denom x * q rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, div_self, mul_one, num_div_denom] · exact ⟨mul_ne_zero (denom_ne_zero x) hq, rfl⟩ · exact algebraMap_ne_zero hq · rintro ⟨q, hq, rfl⟩ exact num_div_dvd p hq theorem denom_dvd {x : RatFunc K} {q : K[X]} (hq : q ≠ 0) : denom x ∣ q ↔ ∃ p : K[X], x = algebraMap _ _ p / algebraMap _ _ q := by constructor · rintro ⟨p, rfl⟩ obtain ⟨_hx, hp⟩ := mul_ne_zero_iff.mp hq use num x * p rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, div_self, mul_one, num_div_denom] exact algebraMap_ne_zero hp · rintro ⟨p, rfl⟩ exact denom_div_dvd p q theorem num_mul_dvd (x y : RatFunc K) : num (x * y) ∣ num x * num y := by by_cases hx : x = 0 · simp [hx] by_cases hy : y = 0 · simp [hy] rw [num_dvd (mul_ne_zero (num_ne_zero hx) (num_ne_zero hy))] refine ⟨x.denom * y.denom, mul_ne_zero (denom_ne_zero x) (denom_ne_zero y), ?_⟩ rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, num_div_denom, num_div_denom] theorem denom_mul_dvd (x y : RatFunc K) : denom (x * y) ∣ denom x * denom y := by rw [denom_dvd (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))] refine ⟨x.num * y.num, ?_⟩ rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, num_div_denom, num_div_denom] theorem denom_add_dvd (x y : RatFunc K) : denom (x + y) ∣ denom x * denom y := by rw [denom_dvd (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))] refine ⟨x.num * y.denom + x.denom * y.num, ?_⟩ rw [RingHom.map_mul, RingHom.map_add, RingHom.map_mul, RingHom.map_mul, ← div_add_div, num_div_denom, num_div_denom] · exact algebraMap_ne_zero (denom_ne_zero x) · exact algebraMap_ne_zero (denom_ne_zero y) theorem map_denom_ne_zero {L F : Type*} [Zero L] [FunLike F K[X] L] [ZeroHomClass F K[X] L] (φ : F) (hφ : Function.Injective φ) (f : RatFunc K) : φ f.denom ≠ 0 := fun H => (denom_ne_zero f) ((map_eq_zero_iff φ hφ).mp H) theorem map_apply {R F : Type*} [CommRing R] [IsDomain R] [FunLike F K[X] R[X]] [MonoidHomClass F K[X] R[X]] (φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (f : RatFunc K) : map φ hφ f = algebraMap _ _ (φ f.num) / algebraMap _ _ (φ f.denom) := by rw [← num_div_denom f, map_apply_div_ne_zero, num_div_denom f] exact denom_ne_zero _ theorem liftMonoidWithZeroHom_apply {L : Type*} [CommGroupWithZero L] (φ : K[X] →*₀ L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (f : RatFunc K) : liftMonoidWithZeroHom φ hφ f = φ f.num / φ f.denom := by rw [← num_div_denom f, liftMonoidWithZeroHom_apply_div, num_div_denom] theorem liftRingHom_apply {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (f : RatFunc K) : liftRingHom φ hφ f = φ f.num / φ f.denom := liftMonoidWithZeroHom_apply _ hφ _ theorem liftAlgHom_apply {L S : Type*} [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L] (φ : K[X] →ₐ[S] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (f : RatFunc K) : liftAlgHom φ hφ f = φ f.num / φ f.denom := liftMonoidWithZeroHom_apply _ hφ _ theorem num_mul_denom_add_denom_mul_num_ne_zero {x y : RatFunc K} (hxy : x + y ≠ 0) : x.num * y.denom + x.denom * y.num ≠ 0 := by intro h_zero have h := num_denom_add x y rw [h_zero, zero_mul] at h exact (mul_ne_zero (num_ne_zero hxy) (mul_ne_zero x.denom_ne_zero y.denom_ne_zero)) h end NumDenom end RatFunc
Mathlib/FieldTheory/RatFunc/Basic.lean
1,022
1,023
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Group.Unbundled.Int import Mathlib.Algebra.Ring.Nat import Mathlib.Data.Int.GCD /-! # Congruences modulo a natural number This file defines the equivalence relation `a ≡ b [MOD n]` on the natural numbers, and proves basic properties about it such as the Chinese Remainder Theorem `modEq_and_modEq_iff_modEq_mul`. ## Notations `a ≡ b [MOD n]` is notation for `nat.ModEq n a b`, which is defined to mean `a % n = b % n`. ## Tags ModEq, congruence, mod, MOD, modulo -/ assert_not_exists OrderedAddCommMonoid Function.support namespace Nat /-- Modular equality. `n.ModEq a b`, or `a ≡ b [MOD n]`, means that `a - b` is a multiple of `n`. -/ def ModEq (n a b : ℕ) := a % n = b % n @[inherit_doc] notation:50 a " ≡ " b " [MOD " n "]" => ModEq n a b variable {m n a b c d : ℕ} -- Since `ModEq` is semi-reducible, we need to provide the decidable instance manually instance : Decidable (ModEq n a b) := inferInstanceAs <| Decidable (a % n = b % n) namespace ModEq @[refl] protected theorem refl (a : ℕ) : a ≡ a [MOD n] := rfl protected theorem rfl : a ≡ a [MOD n] := ModEq.refl _ instance : IsRefl _ (ModEq n) := ⟨ModEq.refl⟩ @[symm] protected theorem symm : a ≡ b [MOD n] → b ≡ a [MOD n] := Eq.symm @[trans] protected theorem trans : a ≡ b [MOD n] → b ≡ c [MOD n] → a ≡ c [MOD n] := Eq.trans instance : Trans (ModEq n) (ModEq n) (ModEq n) where trans := Nat.ModEq.trans protected theorem comm : a ≡ b [MOD n] ↔ b ≡ a [MOD n] := ⟨ModEq.symm, ModEq.symm⟩ end ModEq theorem modEq_zero_iff_dvd : a ≡ 0 [MOD n] ↔ n ∣ a := by rw [ModEq, zero_mod, dvd_iff_mod_eq_zero] theorem _root_.Dvd.dvd.modEq_zero_nat (h : n ∣ a) : a ≡ 0 [MOD n] := modEq_zero_iff_dvd.2 h theorem _root_.Dvd.dvd.zero_modEq_nat (h : n ∣ a) : 0 ≡ a [MOD n] := h.modEq_zero_nat.symm theorem modEq_iff_dvd : a ≡ b [MOD n] ↔ (n : ℤ) ∣ b - a := by rw [ModEq, eq_comm, ← Int.natCast_inj, Int.natCast_mod, Int.natCast_mod, Int.emod_eq_emod_iff_emod_sub_eq_zero, Int.dvd_iff_emod_eq_zero] alias ⟨ModEq.dvd, modEq_of_dvd⟩ := modEq_iff_dvd /-- A variant of `modEq_iff_dvd` with `Nat` divisibility -/ theorem modEq_iff_dvd' (h : a ≤ b) : a ≡ b [MOD n] ↔ n ∣ b - a := by rw [modEq_iff_dvd, ← Int.natCast_dvd_natCast, Int.ofNat_sub h] theorem mod_modEq (a n) : a % n ≡ a [MOD n] := mod_mod _ _ namespace ModEq lemma of_dvd (d : m ∣ n) (h : a ≡ b [MOD n]) : a ≡ b [MOD m] := modEq_of_dvd <| Int.ofNat_dvd.mpr d |>.trans h.dvd protected theorem mul_left' (c : ℕ) (h : a ≡ b [MOD n]) : c * a ≡ c * b [MOD c * n] := by unfold ModEq at *; rw [mul_mod_mul_left, mul_mod_mul_left, h] @[gcongr] protected theorem mul_left (c : ℕ) (h : a ≡ b [MOD n]) : c * a ≡ c * b [MOD n] := (h.mul_left' _).of_dvd (dvd_mul_left _ _) protected theorem mul_right' (c : ℕ) (h : a ≡ b [MOD n]) : a * c ≡ b * c [MOD n * c] := by rw [mul_comm a, mul_comm b, mul_comm n]; exact h.mul_left' c @[gcongr] protected theorem mul_right (c : ℕ) (h : a ≡ b [MOD n]) : a * c ≡ b * c [MOD n] := by rw [mul_comm a, mul_comm b]; exact h.mul_left c @[gcongr] protected theorem mul (h₁ : a ≡ b [MOD n]) (h₂ : c ≡ d [MOD n]) : a * c ≡ b * d [MOD n] := (h₂.mul_left _).trans (h₁.mul_right _) @[gcongr] protected theorem pow (m : ℕ) (h : a ≡ b [MOD n]) : a ^ m ≡ b ^ m [MOD n] := by induction m with | zero => rfl | succ d hd => rw [Nat.pow_succ, Nat.pow_succ] exact hd.mul h @[gcongr] protected theorem add (h₁ : a ≡ b [MOD n]) (h₂ : c ≡ d [MOD n]) : a + c ≡ b + d [MOD n] := by rw [modEq_iff_dvd, Int.natCast_add, Int.natCast_add, add_sub_add_comm] exact Int.dvd_add h₁.dvd h₂.dvd @[gcongr] protected theorem add_left (c : ℕ) (h : a ≡ b [MOD n]) : c + a ≡ c + b [MOD n] := ModEq.rfl.add h @[gcongr] protected theorem add_right (c : ℕ) (h : a ≡ b [MOD n]) : a + c ≡ b + c [MOD n] := h.add ModEq.rfl protected theorem add_left_cancel (h₁ : a ≡ b [MOD n]) (h₂ : a + c ≡ b + d [MOD n]) : c ≡ d [MOD n] := by simp only [modEq_iff_dvd, Int.natCast_add] at * rw [add_sub_add_comm] at h₂ convert Int.dvd_sub h₂ h₁ using 1 rw [add_sub_cancel_left] protected theorem add_left_cancel' (c : ℕ) (h : c + a ≡ c + b [MOD n]) : a ≡ b [MOD n] := ModEq.rfl.add_left_cancel h protected theorem add_right_cancel (h₁ : c ≡ d [MOD n]) (h₂ : a + c ≡ b + d [MOD n]) : a ≡ b [MOD 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 [MOD n]) : a ≡ b [MOD n] := ModEq.rfl.add_right_cancel h /-- Cancel left multiplication on both sides of the `≡` and in the modulus. For cancelling left multiplication in the modulus, see `Nat.ModEq.of_mul_left`. -/ protected theorem mul_left_cancel' {a b c m : ℕ} (hc : c ≠ 0) : c * a ≡ c * b [MOD c * m] → a ≡ b [MOD m] := by simp only [modEq_iff_dvd, Int.natCast_mul, ← Int.mul_sub] exact fun h => (Int.dvd_of_mul_dvd_mul_left (Int.ofNat_ne_zero.mpr hc) h) protected theorem mul_left_cancel_iff' {a b c m : ℕ} (hc : c ≠ 0) : c * a ≡ c * b [MOD c * m] ↔ a ≡ b [MOD m] := ⟨ModEq.mul_left_cancel' hc, ModEq.mul_left' _⟩ /-- Cancel right multiplication on both sides of the `≡` and in the modulus. For cancelling right multiplication in the modulus, see `Nat.ModEq.of_mul_right`. -/ protected theorem mul_right_cancel' {a b c m : ℕ} (hc : c ≠ 0) : a * c ≡ b * c [MOD m * c] → a ≡ b [MOD m] := by simp only [modEq_iff_dvd, Int.natCast_mul, ← Int.sub_mul] exact fun h => (Int.dvd_of_mul_dvd_mul_right (Int.ofNat_ne_zero.mpr hc) h) protected theorem mul_right_cancel_iff' {a b c m : ℕ} (hc : c ≠ 0) : a * c ≡ b * c [MOD m * c] ↔ a ≡ b [MOD m] := ⟨ModEq.mul_right_cancel' hc, ModEq.mul_right' _⟩ /-- Cancel left multiplication in the modulus. For cancelling left multiplication on both sides of the `≡`, see `nat.modeq.mul_left_cancel'`. -/ lemma of_mul_left (m : ℕ) (h : a ≡ b [MOD m * n]) : a ≡ b [MOD n] := by rw [modEq_iff_dvd] at * exact (dvd_mul_left (n : ℤ) (m : ℤ)).trans h /-- Cancel right multiplication in the modulus. For cancelling right multiplication on both sides of the `≡`, see `nat.modeq.mul_right_cancel'`. -/ lemma of_mul_right (m : ℕ) : a ≡ b [MOD n * m] → a ≡ b [MOD n] := mul_comm m n ▸ of_mul_left _ theorem of_div (h : a / c ≡ b / c [MOD m / c]) (ha : c ∣ a) (ha : c ∣ b) (ha : c ∣ m) : a ≡ b [MOD m] := by convert h.mul_left' c <;> rwa [Nat.mul_div_cancel'] end ModEq lemma modEq_sub (h : b ≤ a) : a ≡ b [MOD a - b] := (modEq_of_dvd <| by rw [Int.ofNat_sub h]).symm lemma modEq_one : a ≡ b [MOD 1] := modEq_of_dvd <| one_dvd _ @[simp] lemma modEq_zero_iff : a ≡ b [MOD 0] ↔ a = b := by rw [ModEq, mod_zero, mod_zero] @[simp] lemma add_modEq_left : n + a ≡ a [MOD n] := by rw [ModEq, add_mod_left] @[simp] lemma add_modEq_right : a + n ≡ a [MOD n] := by rw [ModEq, add_mod_right] namespace ModEq theorem le_of_lt_add (h1 : a ≡ b [MOD m]) (h2 : a < b + m) : a ≤ b := (le_total a b).elim id fun h3 => Nat.le_of_sub_eq_zero (eq_zero_of_dvd_of_lt ((modEq_iff_dvd' h3).mp h1.symm) (by omega)) theorem add_le_of_lt (h1 : a ≡ b [MOD m]) (h2 : a < b) : a + m ≤ b := le_of_lt_add (add_modEq_right.trans h1) (by omega) theorem dvd_iff (h : a ≡ b [MOD m]) (hdm : d ∣ m) : d ∣ a ↔ d ∣ b := by simp only [← modEq_zero_iff_dvd] replace h := h.of_dvd hdm exact ⟨h.symm.trans, h.trans⟩ theorem gcd_eq (h : a ≡ b [MOD m]) : gcd a m = gcd b m := by have h1 := gcd_dvd_right a m have h2 := gcd_dvd_right b m exact dvd_antisymm (dvd_gcd ((h.dvd_iff h1).mp (gcd_dvd_left a m)) h1) (dvd_gcd ((h.dvd_iff h2).mpr (gcd_dvd_left b m)) h2) lemma eq_of_abs_lt (h : a ≡ b [MOD m]) (h2 : |(b : ℤ) - a| < m) : a = b := by apply Int.ofNat.inj rw [eq_comm, ← sub_eq_zero] exact Int.eq_zero_of_abs_lt_dvd h.dvd h2 lemma eq_of_lt_of_lt (h : a ≡ b [MOD m]) (ha : a < m) (hb : b < m) : a = b := h.eq_of_abs_lt <| Int.abs_sub_lt_of_lt_lt ha hb /-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c` -/ lemma cancel_left_div_gcd (hm : 0 < m) (h : c * a ≡ c * b [MOD m]) : a ≡ b [MOD m / gcd m c] := by let d := gcd m c have hmd := gcd_dvd_left m c have hcd := gcd_dvd_right m c rw [modEq_iff_dvd] refine @Int.dvd_of_dvd_mul_right_of_gcd_one (m / d) (c / d) (b - a) ?_ ?_ · show (m / d : ℤ) ∣ c / d * (b - a) rw [mul_comm, ← Int.mul_ediv_assoc (b - a) (Int.natCast_dvd_natCast.mpr hcd), mul_comm] apply Int.ediv_dvd_ediv (Int.natCast_dvd_natCast.mpr hmd) rw [Int.mul_sub] exact modEq_iff_dvd.mp h · show Int.gcd (m / d) (c / d) = 1 simp only [d, ← Int.natCast_div, Int.gcd_natCast_natCast (m / d) (c / d), gcd_div hmd hcd, Nat.div_self (gcd_pos_of_pos_left c hm)] /-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c` -/ lemma cancel_right_div_gcd (hm : 0 < m) (h : a * c ≡ b * c [MOD m]) : a ≡ b [MOD m / gcd m c] := by apply cancel_left_div_gcd hm simpa [mul_comm] using h lemma cancel_left_div_gcd' (hm : 0 < m) (hcd : c ≡ d [MOD m]) (h : c * a ≡ d * b [MOD m]) : a ≡ b [MOD m / gcd m c] := (h.trans <| hcd.symm.mul_right b).cancel_left_div_gcd hm lemma cancel_right_div_gcd' (hm : 0 < m) (hcd : c ≡ d [MOD m]) (h : a * c ≡ b * d [MOD m]) : a ≡ b [MOD m / gcd m c] := (h.trans <| hcd.symm.mul_left b).cancel_right_div_gcd hm /-- A common factor that's coprime with the modulus can be cancelled from a `ModEq` -/ lemma cancel_left_of_coprime (hmc : gcd m c = 1) (h : c * a ≡ c * b [MOD m]) : a ≡ b [MOD m] := by rcases m.eq_zero_or_pos with (rfl | hm) · simp only [gcd_zero_left] at hmc simp only [gcd_zero_left, hmc, one_mul, modEq_zero_iff] at h subst h rfl simpa [hmc] using h.cancel_left_div_gcd hm /-- A common factor that's coprime with the modulus can be cancelled from a `ModEq` -/ lemma cancel_right_of_coprime (hmc : gcd m c = 1) (h : a * c ≡ b * c [MOD m]) : a ≡ b [MOD m] := cancel_left_of_coprime hmc <| by simpa [mul_comm] using h end ModEq /-- The natural number less than `lcm n m` congruent to `a` mod `n` and `b` mod `m` -/ def chineseRemainder' (h : a ≡ b [MOD gcd n m]) : { k // k ≡ a [MOD n] ∧ k ≡ b [MOD m] } := if hn : n = 0 then ⟨a, by rw [hn, gcd_zero_left] at h; constructor · rfl · exact h⟩ else if hm : m = 0 then ⟨b, by rw [hm, gcd_zero_right] at h; constructor · exact h.symm · rfl⟩ else ⟨let (c, d) := xgcd n m; Int.toNat ((n * c * b + m * d * a) / gcd n m % lcm n m), by rw [xgcd_val] dsimp rw [modEq_iff_dvd, modEq_iff_dvd, Int.toNat_of_nonneg (Int.emod_nonneg _ (Int.natCast_ne_zero.2 (lcm_ne_zero hn hm)))] have hnonzero : (gcd n m : ℤ) ≠ 0 := by norm_cast rw [Nat.gcd_eq_zero_iff, not_and] exact fun _ => hm have hcoedvd : ∀ t, (gcd n m : ℤ) ∣ t * (b - a) := fun t => h.dvd.mul_left _ have := gcd_eq_gcd_ab n m constructor <;> rw [Int.emod_def, ← sub_add] <;> refine Int.dvd_add ?_ (dvd_mul_of_dvd_left ?_ _) <;> try norm_cast · rw [← sub_eq_iff_eq_add'] at this rw [← this, Int.sub_mul, ← add_sub_assoc, add_comm, add_sub_assoc, ← Int.mul_sub, Int.add_ediv_of_dvd_left, Int.mul_ediv_cancel_left _ hnonzero, Int.mul_ediv_assoc _ h.dvd, ← sub_sub, sub_self, zero_sub, Int.dvd_neg, mul_assoc] · exact dvd_mul_right _ _ norm_cast exact dvd_mul_right _ _ · exact dvd_lcm_left n m · rw [← sub_eq_iff_eq_add] at this rw [← this, Int.sub_mul, sub_add, ← Int.mul_sub, Int.sub_ediv_of_dvd, Int.mul_ediv_cancel_left _ hnonzero, Int.mul_ediv_assoc _ h.dvd, ← sub_add, sub_self, zero_add, mul_assoc] · exact dvd_mul_right _ _ · exact hcoedvd _ · exact dvd_lcm_right n m⟩ /-- The natural number less than `n*m` congruent to `a` mod `n` and `b` mod `m` -/ def chineseRemainder (co : n.Coprime m) (a b : ℕ) : { k // k ≡ a [MOD n] ∧ k ≡ b [MOD m] } := chineseRemainder' (by convert @modEq_one a b) theorem chineseRemainder'_lt_lcm (h : a ≡ b [MOD gcd n m]) (hn : n ≠ 0) (hm : m ≠ 0) : ↑(chineseRemainder' h) < lcm n m := by dsimp only [chineseRemainder'] rw [dif_neg hn, dif_neg hm, Subtype.coe_mk, xgcd_val, ← Int.toNat_natCast (lcm n m)] have lcm_pos := Int.natCast_pos.mpr (Nat.pos_of_ne_zero (lcm_ne_zero hn hm)) exact (Int.toNat_lt_toNat lcm_pos).mpr (Int.emod_lt_of_pos _ lcm_pos) theorem chineseRemainder_lt_mul (co : n.Coprime m) (a b : ℕ) (hn : n ≠ 0) (hm : m ≠ 0) : ↑(chineseRemainder co a b) < n * m := lt_of_lt_of_le (chineseRemainder'_lt_lcm _ hn hm) (le_of_eq co.lcm_eq_mul) theorem mod_lcm (hn : a ≡ b [MOD n]) (hm : a ≡ b [MOD m]) : a ≡ b [MOD lcm n m] := Nat.modEq_iff_dvd.mpr <| Int.coe_lcm_dvd (Nat.modEq_iff_dvd.mp hn) (Nat.modEq_iff_dvd.mp hm) theorem chineseRemainder_modEq_unique (co : n.Coprime m) {a b z} (hzan : z ≡ a [MOD n]) (hzbm : z ≡ b [MOD m]) : z ≡ chineseRemainder co a b [MOD n*m] := by simpa [Nat.Coprime.lcm_eq_mul co] using mod_lcm (hzan.trans ((chineseRemainder co a b).prop.1).symm) (hzbm.trans ((chineseRemainder co a b).prop.2).symm) theorem modEq_and_modEq_iff_modEq_mul {a b m n : ℕ} (hmn : m.Coprime n) : a ≡ b [MOD m] ∧ a ≡ b [MOD n] ↔ a ≡ b [MOD m * n] := ⟨fun h => by rw [Nat.modEq_iff_dvd, Nat.modEq_iff_dvd, ← Int.dvd_natAbs, Int.natCast_dvd_natCast, ← Int.dvd_natAbs, Int.natCast_dvd_natCast] at h rw [Nat.modEq_iff_dvd, ← Int.dvd_natAbs, Int.natCast_dvd_natCast] exact hmn.mul_dvd_of_dvd_of_dvd h.1 h.2, fun h => ⟨h.of_mul_right _, h.of_mul_left _⟩⟩ theorem coprime_of_mul_modEq_one (b : ℕ) {a n : ℕ} (h : a * b ≡ 1 [MOD n]) : a.Coprime n := by obtain ⟨g, hh⟩ := Nat.gcd_dvd_right a n rw [Nat.coprime_iff_gcd_eq_one, ← Nat.dvd_one, ← Nat.modEq_zero_iff_dvd] calc 1 ≡ a * b [MOD a.gcd n] := (hh ▸ h).symm.of_mul_right g _ ≡ 0 * b [MOD a.gcd n] := (Nat.modEq_zero_iff_dvd.mpr (Nat.gcd_dvd_left _ _)).mul_right b _ = 0 := by rw [zero_mul] theorem add_mod_add_ite (a b c : ℕ) : ((a + b) % c + if c ≤ a % c + b % c then c else 0) = a % c + b % c := have : (a + b) % c = (a % c + b % c) % c := ((mod_modEq _ _).add <| mod_modEq _ _).symm if hc0 : c = 0 then by simp [hc0, Nat.mod_zero] else by rw [this] split_ifs with h · have h2 : (a % c + b % c) / c < 2 := Nat.div_lt_of_lt_mul (by rw [mul_two] exact add_lt_add (Nat.mod_lt _ (Nat.pos_of_ne_zero hc0)) (Nat.mod_lt _ (Nat.pos_of_ne_zero hc0))) have h0 : 0 < (a % c + b % c) / c := Nat.div_pos h (Nat.pos_of_ne_zero hc0) rw [← @add_right_cancel_iff _ _ _ (c * ((a % c + b % c) / c)), add_comm _ c, add_assoc, mod_add_div, le_antisymm (le_of_lt_succ h2) h0, mul_one, add_comm] · rw [Nat.mod_eq_of_lt (lt_of_not_ge h), add_zero] theorem add_mod_of_add_mod_lt {a b c : ℕ} (hc : a % c + b % c < c) : (a + b) % c = a % c + b % c := by rw [← add_mod_add_ite, if_neg (not_le_of_lt hc), add_zero] theorem add_mod_add_of_le_add_mod {a b c : ℕ} (hc : c ≤ a % c + b % c) : (a + b) % c + c = a % c + b % c := by rw [← add_mod_add_ite, if_pos hc] theorem add_div_eq_of_add_mod_lt {a b c : ℕ} (hc : a % c + b % c < c) : (a + b) / c = a / c + b / c := if hc0 : c = 0 then by simp [hc0] else by rw [Nat.add_div (Nat.pos_of_ne_zero hc0), if_neg (not_le_of_lt hc), add_zero] protected theorem add_div_of_dvd_right {a b c : ℕ} (hca : c ∣ a) : (a + b) / c = a / c + b / c := if h : c = 0 then by simp [h] else add_div_eq_of_add_mod_lt (by rw [Nat.mod_eq_zero_of_dvd hca, zero_add]
exact Nat.mod_lt _ (zero_lt_of_ne_zero h)) protected theorem add_div_of_dvd_left {a b c : ℕ} (hca : c ∣ b) : (a + b) / c = a / c + b / c := by rwa [add_comm, Nat.add_div_of_dvd_right, add_comm]
Mathlib/Data/Nat/ModEq.lean
396
400
/- Copyright (c) 2024 Brendan Murphy. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Brendan Murphy -/ import Mathlib.RingTheory.Regular.IsSMulRegular import Mathlib.RingTheory.Artinian.Module import Mathlib.RingTheory.Nakayama import Mathlib.Algebra.Equiv.TransferInstance import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic import Mathlib.RingTheory.Noetherian.Basic /-! # Regular sequences and weakly regular sequences The notion of a regular sequence is fundamental in commutative algebra. Properties of regular sequences encode information about singularities of a ring and regularity of a sequence can be tested homologically. However the notion of a regular sequence is only really sensible for Noetherian local rings. TODO: Koszul regular sequences, H_1-regular sequences, quasi-regular sequences, depth. ## Tags module, regular element, regular sequence, commutative algebra -/ universe u v open scoped Pointwise variable {R S M M₂ M₃ M₄ : Type*} namespace Ideal variable [Semiring R] [Semiring S] /-- The ideal generated by a list of elements. -/ abbrev ofList (rs : List R) := span { r | r ∈ rs } @[simp] lemma ofList_nil : (ofList [] : Ideal R) = ⊥ := have : { r | r ∈ [] } = ∅ := Set.eq_empty_of_forall_not_mem (fun _ => List.not_mem_nil) Eq.trans (congrArg span this) span_empty @[simp] lemma ofList_append (rs₁ rs₂ : List R) : ofList (rs₁ ++ rs₂) = ofList rs₁ ⊔ ofList rs₂ := have : { r | r ∈ rs₁ ++ rs₂ } = _ := Set.ext (fun _ => List.mem_append) Eq.trans (congrArg span this) (span_union _ _) lemma ofList_singleton (r : R) : ofList [r] = span {r} := congrArg span (Set.ext fun _ => List.mem_singleton) @[simp] lemma ofList_cons (r : R) (rs : List R) : ofList (r::rs) = span {r} ⊔ ofList rs := Eq.trans (ofList_append [r] rs) (congrArg (· ⊔ _) (ofList_singleton r)) @[simp] lemma map_ofList (f : R →+* S) (rs : List R) : map f (ofList rs) = ofList (rs.map f) := Eq.trans (map_span f { r | r ∈ rs }) <| congrArg span <| Set.ext (fun _ => List.mem_map.symm) lemma ofList_cons_smul {R} [CommSemiring R] (r : R) (rs : List R) {M} [AddCommMonoid M] [Module R M] (N : Submodule R M) : ofList (r :: rs) • N = r • N ⊔ ofList rs • N := by rw [ofList_cons, Submodule.sup_smul, Submodule.ideal_span_singleton_smul] end Ideal namespace Submodule lemma smul_top_le_comap_smul_top [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] (I : Ideal R) (f : M →ₗ[R] M₂) : I • ⊤ ≤ comap f (I • ⊤) := map_le_iff_le_comap.mp <| le_of_eq_of_le (map_smul'' _ _ _) <| smul_mono_right _ le_top variable (M) [CommRing R] [AddCommGroup M] [AddCommGroup M₂] [Module R M] [Module R M₂] (r : R) (rs : List R) /-- The equivalence between M ⧸ (r₀, r₁, …, rₙ)M and (M ⧸ r₀M) ⧸ (r₁, …, rₙ) (M ⧸ r₀M). -/ def quotOfListConsSMulTopEquivQuotSMulTopInner : (M ⧸ (Ideal.ofList (r :: rs) • ⊤ : Submodule R M)) ≃ₗ[R] QuotSMulTop r M ⧸ (Ideal.ofList rs • ⊤ : Submodule R (QuotSMulTop r M)) := quotEquivOfEq _ _ (Ideal.ofList_cons_smul r rs ⊤) ≪≫ₗ (quotientQuotientEquivQuotientSup (r • ⊤) (Ideal.ofList rs • ⊤)).symm ≪≫ₗ quotEquivOfEq _ _ (by rw [map_smul'', map_top, range_mkQ]) /-- The equivalence between M ⧸ (r₀, r₁, …, rₙ)M and (M ⧸ (r₁, …, rₙ)) ⧸ r₀ (M ⧸ (r₁, …, rₙ)). -/ def quotOfListConsSMulTopEquivQuotSMulTopOuter : (M ⧸ (Ideal.ofList (r :: rs) • ⊤ : Submodule R M)) ≃ₗ[R] QuotSMulTop r (M ⧸ (Ideal.ofList rs • ⊤ : Submodule R M)) := quotEquivOfEq _ _ (Eq.trans (Ideal.ofList_cons_smul r rs ⊤) (sup_comm _ _)) ≪≫ₗ (quotientQuotientEquivQuotientSup (Ideal.ofList rs • ⊤) (r • ⊤)).symm ≪≫ₗ quotEquivOfEq _ _ (by rw [map_pointwise_smul, map_top, range_mkQ]) variable {M} lemma quotOfListConsSMulTopEquivQuotSMulTopInner_naturality (f : M →ₗ[R] M₂) : (quotOfListConsSMulTopEquivQuotSMulTopInner M₂ r rs).toLinearMap ∘ₗ mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList (r :: rs)) f) = mapQ _ _ _ (smul_top_le_comap_smul_top _ (QuotSMulTop.map r f)) ∘ₗ (quotOfListConsSMulTopEquivQuotSMulTopInner M r rs).toLinearMap := quot_hom_ext _ _ _ fun _ => rfl lemma top_eq_ofList_cons_smul_iff : (⊤ : Submodule R M) = Ideal.ofList (r :: rs) • ⊤ ↔ (⊤ : Submodule R (QuotSMulTop r M)) = Ideal.ofList rs • ⊤ := by conv => congr <;> rw [eq_comm, ← subsingleton_quotient_iff_eq_top] exact (quotOfListConsSMulTopEquivQuotSMulTopInner M r rs).toEquiv.subsingleton_congr end Submodule namespace RingTheory.Sequence open scoped TensorProduct List open Function Submodule QuotSMulTop variable (S M) section Definitions /- In theory, regularity of `rs : List α` on `M` makes sense as soon as `[Monoid α]`, `[AddCommGroup M]`, and `[DistribMulAction α M]`. Instead of `Ideal.ofList (rs.take i) • (⊤ : Submodule R M)` we use `⨆ (j : Fin i), rs[j] • (⊤ : AddSubgroup M)`. However it's not clear that this is a useful generalization. If we add the assumption `[SMulCommClass α α M]` this is essentially the same as focusing on the commutative ring case, by passing to the monoid ring `ℤ[abelianization of α]`. -/ variable [CommRing R] [AddCommGroup M] [Module R M] open Ideal /-- A sequence `[r₁, …, rₙ]` is weakly regular on `M` iff `rᵢ` is regular on `M⧸(r₁, …, rᵢ₋₁)M` for all `1 ≤ i ≤ n`. -/ @[mk_iff] structure IsWeaklyRegular (rs : List R) : Prop where regular_mod_prev : ∀ i (h : i < rs.length), IsSMulRegular (M ⧸ (ofList (rs.take i) • ⊤ : Submodule R M)) rs[i] lemma isWeaklyRegular_iff_Fin (rs : List R) : IsWeaklyRegular M rs ↔ ∀ (i : Fin rs.length), IsSMulRegular (M ⧸ (ofList (rs.take i) • ⊤ : Submodule R M)) rs[i] := Iff.trans (isWeaklyRegular_iff M rs) (Iff.symm Fin.forall_iff) /-- A weakly regular sequence `rs` on `M` is regular if also `M/rsM ≠ 0`. -/ @[mk_iff] structure IsRegular (rs : List R) : Prop extends IsWeaklyRegular M rs where top_ne_smul : (⊤ : Submodule R M) ≠ Ideal.ofList rs • ⊤ end Definitions section Congr variable {S M} [CommRing R] [CommRing S] [AddCommGroup M] [AddCommGroup M₂] [Module R M] [Module S M₂] {σ : R →+* S} {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ]
open DistribMulAction AddSubgroup in private lemma _root_.AddHom.map_smul_top_toAddSubgroup_of_surjective {f : M →+ M₂} {as : List R} {bs : List S} (hf : Function.Surjective f) (h : List.Forall₂ (fun r s => ∀ x, f (r • x) = s • f x) as bs) : (Ideal.ofList as • ⊤ : Submodule R M).toAddSubgroup.map f = (Ideal.ofList bs • ⊤ : Submodule S M₂).toAddSubgroup := by induction h with | nil => convert AddSubgroup.map_bot f using 1 <;> rw [Ideal.ofList_nil, bot_smul, bot_toAddSubgroup] | @cons r s _ _ h _ ih => conv => congr <;> rw [Ideal.ofList_cons, sup_smul, sup_toAddSubgroup, ideal_span_singleton_smul, pointwise_smul_toAddSubgroup, top_toAddSubgroup, pointwise_smul_def] apply DFunLike.ext (f.comp (toAddMonoidEnd R M r)) ((toAddMonoidEnd S M₂ s).comp f) at h
Mathlib/RingTheory/Regular/RegularSequence.lean
160
176
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.Algebra.Polynomial.Splits import Mathlib.FieldTheory.RatFunc.AsPolynomial import Mathlib.NumberTheory.ArithmeticFunction import Mathlib.RingTheory.RootsOfUnity.Complex /-! # Cyclotomic polynomials. For `n : ℕ` and an integral domain `R`, we define a modified version of the `n`-th cyclotomic polynomial with coefficients in `R`, denoted `cyclotomic' n R`, as `∏ (X - μ)`, where `μ` varies over the primitive `n`th roots of unity. If there is a primitive `n`th root of unity in `R` then this the standard definition. We then define the standard cyclotomic polynomial `cyclotomic n R` with coefficients in any ring `R`. ## Main definition * `cyclotomic n R` : the `n`-th cyclotomic polynomial with coefficients in `R`. ## Main results * `Polynomial.degree_cyclotomic` : The degree of `cyclotomic n` is `totient n`. * `Polynomial.prod_cyclotomic_eq_X_pow_sub_one` : `X ^ n - 1 = ∏ (cyclotomic i)`, where `i` divides `n`. * `Polynomial.cyclotomic_eq_prod_X_pow_sub_one_pow_moebius` : The Möbius inversion formula for `cyclotomic n R` over an abstract fraction field for `R[X]`. ## Implementation details Our definition of `cyclotomic' n R` makes sense in any integral domain `R`, but the interesting results hold if there is a primitive `n`-th root of unity in `R`. In particular, our definition is not the standard one unless there is a primitive `n`th root of unity in `R`. For example, `cyclotomic' 3 ℤ = 1`, since there are no primitive cube roots of unity in `ℤ`. The main example is `R = ℂ`, we decided to work in general since the difficulties are essentially the same. To get the standard cyclotomic polynomials, we use `unique_int_coeff_of_cycl`, with `R = ℂ`, to get a polynomial with integer coefficients and then we map it to `R[X]`, for any ring `R`. -/ open scoped Polynomial noncomputable section universe u namespace Polynomial section Cyclotomic' section IsDomain variable {R : Type*} [CommRing R] [IsDomain R] /-- The modified `n`-th cyclotomic polynomial with coefficients in `R`, it is the usual cyclotomic polynomial if there is a primitive `n`-th root of unity in `R`. -/ def cyclotomic' (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : R[X] := ∏ μ ∈ primitiveRoots n R, (X - C μ) /-- The zeroth modified cyclotomic polyomial is `1`. -/ @[simp] theorem cyclotomic'_zero (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 0 R = 1 := by simp only [cyclotomic', Finset.prod_empty, primitiveRoots_zero] /-- The first modified cyclotomic polyomial is `X - 1`. -/ @[simp] theorem cyclotomic'_one (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 1 R = X - 1 := by simp only [cyclotomic', Finset.prod_singleton, RingHom.map_one, IsPrimitiveRoot.primitiveRoots_one] /-- The second modified cyclotomic polyomial is `X + 1` if the characteristic of `R` is not `2`. -/ @[simp] theorem cyclotomic'_two (R : Type*) [CommRing R] [IsDomain R] (p : ℕ) [CharP R p] (hp : p ≠ 2) : cyclotomic' 2 R = X + 1 := by rw [cyclotomic'] have prim_root_two : primitiveRoots 2 R = {(-1 : R)} := by simp only [Finset.eq_singleton_iff_unique_mem, mem_primitiveRoots two_pos] exact ⟨IsPrimitiveRoot.neg_one p hp, fun x => IsPrimitiveRoot.eq_neg_one_of_two_right⟩ simp only [prim_root_two, Finset.prod_singleton, RingHom.map_neg, RingHom.map_one, sub_neg_eq_add] /-- `cyclotomic' n R` is monic. -/ theorem cyclotomic'.monic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : (cyclotomic' n R).Monic := monic_prod_of_monic _ _ fun _ _ => monic_X_sub_C _ /-- `cyclotomic' n R` is different from `0`. -/ theorem cyclotomic'_ne_zero (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' n R ≠ 0 := (cyclotomic'.monic n R).ne_zero /-- The natural degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/ theorem natDegree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) : (cyclotomic' n R).natDegree = Nat.totient n := by rw [cyclotomic'] rw [natDegree_prod (primitiveRoots n R) fun z : R => X - C z] · simp only [IsPrimitiveRoot.card_primitiveRoots h, mul_one, natDegree_X_sub_C, Nat.cast_id, Finset.sum_const, nsmul_eq_mul] intro z _ exact X_sub_C_ne_zero z /-- The degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/ theorem degree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) : (cyclotomic' n R).degree = Nat.totient n := by simp only [degree_eq_natDegree (cyclotomic'_ne_zero n R), natDegree_cyclotomic' h] /-- The roots of `cyclotomic' n R` are the primitive `n`-th roots of unity. -/ theorem roots_of_cyclotomic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : (cyclotomic' n R).roots = (primitiveRoots n R).val := by rw [cyclotomic']; exact roots_prod_X_sub_C (primitiveRoots n R) /-- If there is a primitive `n`th root of unity in `K`, then `X ^ n - 1 = ∏ (X - μ)`, where `μ` varies over the `n`-th roots of unity. -/ theorem X_pow_sub_one_eq_prod {ζ : R} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : X ^ n - 1 = ∏ ζ ∈ nthRootsFinset n (1 : R), (X - C ζ) := by classical rw [nthRootsFinset, ← Multiset.toFinset_eq (IsPrimitiveRoot.nthRoots_one_nodup h)] simp only [Finset.prod_mk, RingHom.map_one] rw [nthRoots] have hmonic : (X ^ n - C (1 : R)).Monic := monic_X_pow_sub_C (1 : R) (ne_of_lt hpos).symm symm apply prod_multiset_X_sub_C_of_monic_of_roots_card_eq hmonic rw [@natDegree_X_pow_sub_C R _ _ n 1, ← nthRoots] exact IsPrimitiveRoot.card_nthRoots_one h end IsDomain section Field variable {K : Type*} [Field K] /-- `cyclotomic' n K` splits. -/ theorem cyclotomic'_splits (n : ℕ) : Splits (RingHom.id K) (cyclotomic' n K) := by apply splits_prod (RingHom.id K) intro z _ simp only [splits_X_sub_C (RingHom.id K)] /-- If there is a primitive `n`-th root of unity in `K`, then `X ^ n - 1` splits. -/ theorem X_pow_sub_one_splits {ζ : K} {n : ℕ} (h : IsPrimitiveRoot ζ n) : Splits (RingHom.id K) (X ^ n - C (1 : K)) := by rw [splits_iff_card_roots, ← nthRoots, IsPrimitiveRoot.card_nthRoots_one h, natDegree_X_pow_sub_C] /-- If there is a primitive `n`-th root of unity in `K`, then `∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1`. -/ theorem prod_cyclotomic'_eq_X_pow_sub_one {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : ∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1 := by classical have hd : (n.divisors : Set ℕ).PairwiseDisjoint fun k => primitiveRoots k K := fun x _ y _ hne => IsPrimitiveRoot.disjoint hne simp only [X_pow_sub_one_eq_prod hpos h, cyclotomic', ← Finset.prod_biUnion hd, IsPrimitiveRoot.nthRoots_one_eq_biUnion_primitiveRoots] /-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K = (X ^ k - 1) /ₘ (∏ i ∈ Nat.properDivisors k, cyclotomic' i K)`. -/ theorem cyclotomic'_eq_X_pow_sub_one_div {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : cyclotomic' n K = (X ^ n - 1) /ₘ ∏ i ∈ Nat.properDivisors n, cyclotomic' i K := by rw [← prod_cyclotomic'_eq_X_pow_sub_one hpos h, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] have prod_monic : (∏ i ∈ Nat.properDivisors n, cyclotomic' i K).Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic'.monic i K rw [(div_modByMonic_unique (cyclotomic' n K) 0 prod_monic _).1] simp only [degree_zero, zero_add] refine ⟨by rw [mul_comm], ?_⟩ rw [bot_lt_iff_ne_bot] intro h exact Monic.ne_zero prod_monic (degree_eq_bot.1 h) /-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K` comes from a monic polynomial with integer coefficients. -/ theorem int_coeff_of_cyclotomic' {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (h : IsPrimitiveRoot ζ n) : ∃ P : ℤ[X], map (Int.castRingHom K) P = cyclotomic' n K ∧ P.degree = (cyclotomic' n K).degree ∧ P.Monic := by refine lifts_and_degree_eq_and_monic ?_ (cyclotomic'.monic n K) induction' n using Nat.strong_induction_on with k ihk generalizing ζ rcases k.eq_zero_or_pos with (rfl | hpos) · use 1 simp only [cyclotomic'_zero, coe_mapRingHom, Polynomial.map_one] let B : K[X] := ∏ i ∈ Nat.properDivisors k, cyclotomic' i K have Bmo : B.Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic'.monic i K have Bint : B ∈ lifts (Int.castRingHom K) := by refine Subsemiring.prod_mem (lifts (Int.castRingHom K)) ?_ intro x hx have xsmall := (Nat.mem_properDivisors.1 hx).2 obtain ⟨d, hd⟩ := (Nat.mem_properDivisors.1 hx).1 rw [mul_comm] at hd exact ihk x xsmall (h.pow hpos hd) replace Bint := lifts_and_degree_eq_and_monic Bint Bmo obtain ⟨B₁, hB₁, _, hB₁mo⟩ := Bint let Q₁ : ℤ[X] := (X ^ k - 1) /ₘ B₁ have huniq : 0 + B * cyclotomic' k K = X ^ k - 1 ∧ (0 : K[X]).degree < B.degree := by constructor · rw [zero_add, mul_comm, ← prod_cyclotomic'_eq_X_pow_sub_one hpos h, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] · simpa only [degree_zero, bot_lt_iff_ne_bot, Ne, degree_eq_bot] using Bmo.ne_zero replace huniq := div_modByMonic_unique (cyclotomic' k K) (0 : K[X]) Bmo huniq simp only [lifts, RingHom.mem_rangeS] use Q₁ rw [coe_mapRingHom, map_divByMonic (Int.castRingHom K) hB₁mo, hB₁, ← huniq.1] simp /-- If `K` is of characteristic `0` and there is a primitive `n`-th root of unity in `K`, then `cyclotomic n K` comes from a unique polynomial with integer coefficients. -/ theorem unique_int_coeff_of_cycl {K : Type*} [CommRing K] [IsDomain K] [CharZero K] {ζ : K} {n : ℕ+} (h : IsPrimitiveRoot ζ n) : ∃! P : ℤ[X], map (Int.castRingHom K) P = cyclotomic' n K := by obtain ⟨P, hP⟩ := int_coeff_of_cyclotomic' h refine ⟨P, hP.1, fun Q hQ => ?_⟩ apply map_injective (Int.castRingHom K) Int.cast_injective rw [hP.1, hQ] end Field end Cyclotomic' section Cyclotomic /-- The `n`-th cyclotomic polynomial with coefficients in `R`. -/ def cyclotomic (n : ℕ) (R : Type*) [Ring R] : R[X] := if h : n = 0 then 1 else map (Int.castRingHom R) (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n h)).choose theorem int_cyclotomic_rw {n : ℕ} (h : n ≠ 0) : cyclotomic n ℤ = (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n h)).choose := by simp only [cyclotomic, h, dif_neg, not_false_iff] ext i simp only [coeff_map, Int.cast_id, eq_intCast] /-- `cyclotomic n R` comes from `cyclotomic n ℤ`. -/ theorem map_cyclotomic_int (n : ℕ) (R : Type*) [Ring R] : map (Int.castRingHom R) (cyclotomic n ℤ) = cyclotomic n R := by by_cases hzero : n = 0 · simp only [hzero, cyclotomic, dif_pos, Polynomial.map_one] simp [cyclotomic, hzero] theorem int_cyclotomic_spec (n : ℕ) : map (Int.castRingHom ℂ) (cyclotomic n ℤ) = cyclotomic' n ℂ ∧ (cyclotomic n ℤ).degree = (cyclotomic' n ℂ).degree ∧ (cyclotomic n ℤ).Monic := by by_cases hzero : n = 0 · simp only [hzero, cyclotomic, degree_one, monic_one, cyclotomic'_zero, dif_pos, eq_self_iff_true, Polynomial.map_one, and_self_iff] rw [int_cyclotomic_rw hzero] exact (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n hzero)).choose_spec theorem int_cyclotomic_unique {n : ℕ} {P : ℤ[X]} (h : map (Int.castRingHom ℂ) P = cyclotomic' n ℂ) : P = cyclotomic n ℤ := by apply map_injective (Int.castRingHom ℂ) Int.cast_injective rw [h, (int_cyclotomic_spec n).1] /-- The definition of `cyclotomic n R` commutes with any ring homomorphism. -/ @[simp] theorem map_cyclotomic (n : ℕ) {R S : Type*} [Ring R] [Ring S] (f : R →+* S) : map f (cyclotomic n R) = cyclotomic n S := by rw [← map_cyclotomic_int n R, ← map_cyclotomic_int n S, map_map] have : Subsingleton (ℤ →+* S) := inferInstance congr! theorem cyclotomic.eval_apply {R S : Type*} (q : R) (n : ℕ) [Ring R] [Ring S] (f : R →+* S) : eval (f q) (cyclotomic n S) = f (eval q (cyclotomic n R)) := by rw [← map_cyclotomic n f, eval_map, eval₂_at_apply] @[simp] theorem cyclotomic.eval_apply_ofReal (q : ℝ) (n : ℕ) : eval (q : ℂ) (cyclotomic n ℂ) = (eval q (cyclotomic n ℝ)) := cyclotomic.eval_apply q n (algebraMap ℝ ℂ)
/-- The zeroth cyclotomic polyomial is `1`. -/ @[simp] theorem cyclotomic_zero (R : Type*) [Ring R] : cyclotomic 0 R = 1 := by simp only [cyclotomic, dif_pos] /-- The first cyclotomic polyomial is `X - 1`. -/ @[simp]
Mathlib/RingTheory/Polynomial/Cyclotomic/Basic.lean
273
280
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Peter Nelson -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.GeomSum import Mathlib.LinearAlgebra.Matrix.Block import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.Nondegenerate import Mathlib.RingTheory.Localization.FractionRing /-! # Vandermonde matrix This file defines the `vandermonde` matrix and gives its determinant. For each `CommRing R`, and function `v : Fin n → R` the matrix `vandermonde v` is defined to be `Fin n` by `Fin n` matrix `V` whose `i`th row is `[1, (v i), (v i)^2, ...]`. This matrix has determinant equal to the product of `v i - v j` over all unordered pairs `i,j`, and therefore is nonsingular if and only if `v` is injective. `vandermonde v` is a special case of two more general matrices we also define. For a type `α` and functions `v w : α → R`, we write `rectVandermonde v w n` for the `α × Fin n` matrix with `i`th row `[(w i) ^ (n-1), (v i) * (w i)^(n-2), ..., (v i)^(n-1)]`. `projVandermonde v w = rectVandermonde v w n` is the square matrix case, where `α = Fin n`. The determinant of `projVandermonde v w` is the product of `v j * w i - v i * w j`, taken over all pairs `i,j` with `i < j`, which gives a similar characterization of when it it nonsingular. Since `vandermonde v w = projVandermonde v 1`, we can derive most of the API for the former in terms of the latter. These extensions of Vandermonde matrices arise in the study of complete arcs in finite geometry, coding theory, and representations of uniform matroids over finite fields. ## Main definitions * `vandermonde v`: a square matrix with the `i, j`th entry equal to `v i ^ j`. * `rectVandermonde v w n`: an `α × Fin n` matrix whose `i, j`-th entry is `(v i) ^ j * (w i) ^ (n-1-j)`. * `projVandermonde v w`: a square matrix whose `i, j`-th entry is `(v i) ^ j * (w i) ^ (n-1-j)`. ## Main results * `det_vandermonde`: `det (vandermonde v)` is the product of `v j - v i`, where `(i, j)` ranges over the set of pairs with `i < j`. * `det_projVandermonde`: `det (projVandermonde v w)` is the product of `v j * w i - v i * w j`, taken over all pairs with `i < j`. ## Implementation notes We derive the `det_vandermonde` formula from `det_projVandermonde`, which is proved using an induction argument involving row operations and division. To circumvent issues with non-invertible elements while still maintaining the generality of rings, we first prove it for fields using the private lemma `det_projVandermonde_of_field`, and then use an algebraic workaround to generalize to the ring case, stating the strictly more general form as `det_projVandermonde`. ## TODO Characterize when `rectVandermonde v w n` has linearly independent rows. -/ variable {R K : Type*} [CommRing R] [Field K] {n : ℕ} open Equiv Finset open Matrix Fin
namespace Matrix
Mathlib/LinearAlgebra/Vandermonde.lean
67
69
/- Copyright (c) 2017 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Mario Carneiro -/ import Mathlib.Algebra.Ring.CharZero import Mathlib.Algebra.Star.Basic import Mathlib.Data.Real.Basic import Mathlib.Order.Interval.Set.UnorderedInterval import Mathlib.Tactic.Ring /-! # The complex numbers The complex numbers are modelled as ℝ^2 in the obvious way and it is shown that they form a field of characteristic zero. The result that the complex numbers are algebraically closed, see `FieldTheory.AlgebraicClosure`. -/ assert_not_exists Multiset Algebra open Set Function /-! ### Definition and basic arithmetic -/ /-- Complex numbers consist of two `Real`s: a real part `re` and an imaginary part `im`. -/ structure Complex : Type where /-- The real part of a complex number. -/ re : ℝ /-- The imaginary part of a complex number. -/ im : ℝ @[inherit_doc] notation "ℂ" => Complex namespace Complex open ComplexConjugate noncomputable instance : DecidableEq ℂ := Classical.decEq _ /-- The equivalence between the complex numbers and `ℝ × ℝ`. -/ @[simps apply] def equivRealProd : ℂ ≃ ℝ × ℝ where toFun z := ⟨z.re, z.im⟩ invFun p := ⟨p.1, p.2⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl @[simp] theorem eta : ∀ z : ℂ, Complex.mk z.re z.im = z | ⟨_, _⟩ => rfl -- We only mark this lemma with `ext` *locally* to avoid it applying whenever terms of `ℂ` appear. theorem ext : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w | ⟨_, _⟩, ⟨_, _⟩, rfl, rfl => rfl attribute [local ext] Complex.ext lemma «forall» {p : ℂ → Prop} : (∀ x, p x) ↔ ∀ a b, p ⟨a, b⟩ := by aesop lemma «exists» {p : ℂ → Prop} : (∃ x, p x) ↔ ∃ a b, p ⟨a, b⟩ := by aesop theorem re_surjective : Surjective re := fun x => ⟨⟨x, 0⟩, rfl⟩ theorem im_surjective : Surjective im := fun y => ⟨⟨0, y⟩, rfl⟩ @[simp] theorem range_re : range re = univ := re_surjective.range_eq @[simp] theorem range_im : range im = univ := im_surjective.range_eq /-- The natural inclusion of the real numbers into the complex numbers. -/ @[coe] def ofReal (r : ℝ) : ℂ := ⟨r, 0⟩ instance : Coe ℝ ℂ := ⟨ofReal⟩ @[simp, norm_cast] theorem ofReal_re (r : ℝ) : Complex.re (r : ℂ) = r := rfl @[simp, norm_cast] theorem ofReal_im (r : ℝ) : (r : ℂ).im = 0 := rfl theorem ofReal_def (r : ℝ) : (r : ℂ) = ⟨r, 0⟩ := rfl @[simp, norm_cast] theorem ofReal_inj {z w : ℝ} : (z : ℂ) = w ↔ z = w := ⟨congrArg re, by apply congrArg⟩ theorem ofReal_injective : Function.Injective ((↑) : ℝ → ℂ) := fun _ _ => congrArg re instance canLift : CanLift ℂ ℝ (↑) fun z => z.im = 0 where prf z hz := ⟨z.re, ext rfl hz.symm⟩ /-- The product of a set on the real axis and a set on the imaginary axis of the complex plane, denoted by `s ×ℂ t`. -/ def reProdIm (s t : Set ℝ) : Set ℂ := re ⁻¹' s ∩ im ⁻¹' t @[deprecated (since := "2024-12-03")] protected alias Set.reProdIm := reProdIm @[inherit_doc] infixl:72 " ×ℂ " => reProdIm theorem mem_reProdIm {z : ℂ} {s t : Set ℝ} : z ∈ s ×ℂ t ↔ z.re ∈ s ∧ z.im ∈ t := Iff.rfl instance : Zero ℂ := ⟨(0 : ℝ)⟩ instance : Inhabited ℂ := ⟨0⟩ @[simp] theorem zero_re : (0 : ℂ).re = 0 := rfl @[simp] theorem zero_im : (0 : ℂ).im = 0 := rfl @[simp, norm_cast] theorem ofReal_zero : ((0 : ℝ) : ℂ) = 0 := rfl @[simp] theorem ofReal_eq_zero {z : ℝ} : (z : ℂ) = 0 ↔ z = 0 := ofReal_inj theorem ofReal_ne_zero {z : ℝ} : (z : ℂ) ≠ 0 ↔ z ≠ 0 := not_congr ofReal_eq_zero instance : One ℂ := ⟨(1 : ℝ)⟩ @[simp] theorem one_re : (1 : ℂ).re = 1 := rfl @[simp] theorem one_im : (1 : ℂ).im = 0 := rfl @[simp, norm_cast] theorem ofReal_one : ((1 : ℝ) : ℂ) = 1 := rfl @[simp] theorem ofReal_eq_one {z : ℝ} : (z : ℂ) = 1 ↔ z = 1 := ofReal_inj theorem ofReal_ne_one {z : ℝ} : (z : ℂ) ≠ 1 ↔ z ≠ 1 := not_congr ofReal_eq_one instance : Add ℂ := ⟨fun z w => ⟨z.re + w.re, z.im + w.im⟩⟩ @[simp] theorem add_re (z w : ℂ) : (z + w).re = z.re + w.re := rfl @[simp] theorem add_im (z w : ℂ) : (z + w).im = z.im + w.im := rfl -- replaced by `re_ofNat` -- replaced by `im_ofNat` @[simp, norm_cast] theorem ofReal_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s := Complex.ext_iff.2 <| by simp [ofReal] -- replaced by `Complex.ofReal_ofNat` instance : Neg ℂ := ⟨fun z => ⟨-z.re, -z.im⟩⟩ @[simp] theorem neg_re (z : ℂ) : (-z).re = -z.re := rfl @[simp] theorem neg_im (z : ℂ) : (-z).im = -z.im := rfl @[simp, norm_cast] theorem ofReal_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r := Complex.ext_iff.2 <| by simp [ofReal] instance : Sub ℂ := ⟨fun z w => ⟨z.re - w.re, z.im - w.im⟩⟩ instance : Mul ℂ := ⟨fun z w => ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩ @[simp] theorem mul_re (z w : ℂ) : (z * w).re = z.re * w.re - z.im * w.im := rfl @[simp] theorem mul_im (z w : ℂ) : (z * w).im = z.re * w.im + z.im * w.re := rfl @[simp, norm_cast] theorem ofReal_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = r * s := Complex.ext_iff.2 <| by simp [ofReal] theorem re_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).re = r * z.re := by simp [ofReal] theorem im_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).im = r * z.im := by simp [ofReal] lemma re_mul_ofReal (z : ℂ) (r : ℝ) : (z * r).re = z.re * r := by simp [ofReal] lemma im_mul_ofReal (z : ℂ) (r : ℝ) : (z * r).im = z.im * r := by simp [ofReal] theorem ofReal_mul' (r : ℝ) (z : ℂ) : ↑r * z = ⟨r * z.re, r * z.im⟩ := ext (re_ofReal_mul _ _) (im_ofReal_mul _ _) /-! ### The imaginary unit, `I` -/ /-- The imaginary unit. -/ def I : ℂ := ⟨0, 1⟩ @[simp] theorem I_re : I.re = 0 := rfl @[simp] theorem I_im : I.im = 1 := rfl @[simp] theorem I_mul_I : I * I = -1 := Complex.ext_iff.2 <| by simp theorem I_mul (z : ℂ) : I * z = ⟨-z.im, z.re⟩ := Complex.ext_iff.2 <| by simp @[simp] lemma I_ne_zero : (I : ℂ) ≠ 0 := mt (congr_arg im) zero_ne_one.symm theorem mk_eq_add_mul_I (a b : ℝ) : Complex.mk a b = a + b * I := Complex.ext_iff.2 <| by simp [ofReal] @[simp] theorem re_add_im (z : ℂ) : (z.re : ℂ) + z.im * I = z := Complex.ext_iff.2 <| by simp [ofReal] theorem mul_I_re (z : ℂ) : (z * I).re = -z.im := by simp theorem mul_I_im (z : ℂ) : (z * I).im = z.re := by simp theorem I_mul_re (z : ℂ) : (I * z).re = -z.im := by simp theorem I_mul_im (z : ℂ) : (I * z).im = z.re := by simp @[simp] theorem equivRealProd_symm_apply (p : ℝ × ℝ) : equivRealProd.symm p = p.1 + p.2 * I := by ext <;> simp [Complex.equivRealProd, ofReal] /-- The natural `AddEquiv` from `ℂ` to `ℝ × ℝ`. -/ @[simps! +simpRhs apply symm_apply_re symm_apply_im] def equivRealProdAddHom : ℂ ≃+ ℝ × ℝ := { equivRealProd with map_add' := by simp } theorem equivRealProdAddHom_symm_apply (p : ℝ × ℝ) : equivRealProdAddHom.symm p = p.1 + p.2 * I := equivRealProd_symm_apply p /-! ### Commutative ring instance and lemmas -/ /- We use a nonstandard formula for the `ℕ` and `ℤ` actions to make sure there is no diamond from the other actions they inherit through the `ℝ`-action on `ℂ` and action transitivity defined in `Data.Complex.Module`. -/ instance : Nontrivial ℂ := domain_nontrivial re rfl rfl namespace SMul -- The useless `0` multiplication in `smul` is to make sure that -- `RestrictScalars.module ℝ ℂ ℂ = Complex.module` definitionally. -- instance made scoped to avoid situations like instance synthesis -- of `SMul ℂ ℂ` trying to proceed via `SMul ℂ ℝ`. /-- Scalar multiplication by `R` on `ℝ` extends to `ℂ`. This is used here and in `Matlib.Data.Complex.Module` to transfer instances from `ℝ` to `ℂ`, but is not needed outside, so we make it scoped. -/ scoped instance instSMulRealComplex {R : Type*} [SMul R ℝ] : SMul R ℂ where smul r x := ⟨r • x.re - 0 * x.im, r • x.im + 0 * x.re⟩ end SMul open scoped SMul section SMul variable {R : Type*} [SMul R ℝ] theorem smul_re (r : R) (z : ℂ) : (r • z).re = r • z.re := by simp [(· • ·), SMul.smul] theorem smul_im (r : R) (z : ℂ) : (r • z).im = r • z.im := by simp [(· • ·), SMul.smul] @[simp] theorem real_smul {x : ℝ} {z : ℂ} : x • z = x * z := rfl end SMul instance addCommGroup : AddCommGroup ℂ := { zero := (0 : ℂ) add := (· + ·) neg := Neg.neg sub := Sub.sub nsmul := fun n z => n • z zsmul := fun n z => n • z zsmul_zero' := by intros; ext <;> simp [smul_re, smul_im] nsmul_zero := by intros; ext <;> simp [smul_re, smul_im] nsmul_succ := by intros; ext <;> simp [smul_re, smul_im] <;> ring zsmul_succ' := by intros; ext <;> simp [smul_re, smul_im] <;> ring zsmul_neg' := by intros; ext <;> simp [smul_re, smul_im] <;> ring add_assoc := by intros; ext <;> simp <;> ring zero_add := by intros; ext <;> simp add_zero := by intros; ext <;> simp add_comm := by intros; ext <;> simp <;> ring neg_add_cancel := by intros; ext <;> simp } instance addGroupWithOne : AddGroupWithOne ℂ := { Complex.addCommGroup with natCast := fun n => ⟨n, 0⟩ natCast_zero := by ext <;> simp [Nat.cast, AddMonoidWithOne.natCast_zero] natCast_succ := fun _ => by ext <;> simp [Nat.cast, AddMonoidWithOne.natCast_succ] intCast := fun n => ⟨n, 0⟩ intCast_ofNat := fun _ => by ext <;> rfl intCast_negSucc := fun n => by ext · simp [AddGroupWithOne.intCast_negSucc] show -(1 : ℝ) + (-n) = -(↑(n + 1)) simp [Nat.cast_add, add_comm] · simp [AddGroupWithOne.intCast_negSucc] show im ⟨n, 0⟩ = 0 rfl one := 1 } instance commRing : CommRing ℂ := { addGroupWithOne with mul := (· * ·) npow := @npowRec _ ⟨(1 : ℂ)⟩ ⟨(· * ·)⟩ add_comm := by intros; ext <;> simp <;> ring left_distrib := by intros; ext <;> simp [mul_re, mul_im] <;> ring right_distrib := by intros; ext <;> simp [mul_re, mul_im] <;> ring zero_mul := by intros; ext <;> simp mul_zero := by intros; ext <;> simp mul_assoc := by intros; ext <;> simp <;> ring one_mul := by intros; ext <;> simp mul_one := by intros; ext <;> simp mul_comm := by intros; ext <;> simp <;> ring } /-- This shortcut instance ensures we do not find `Ring` via the noncomputable `Complex.field` instance. -/ instance : Ring ℂ := by infer_instance /-- This shortcut instance ensures we do not find `CommSemiring` via the noncomputable `Complex.field` instance. -/ instance : CommSemiring ℂ := inferInstance /-- This shortcut instance ensures we do not find `Semiring` via the noncomputable `Complex.field` instance. -/ instance : Semiring ℂ := inferInstance /-- The "real part" map, considered as an additive group homomorphism. -/ def reAddGroupHom : ℂ →+ ℝ where toFun := re map_zero' := zero_re map_add' := add_re @[simp] theorem coe_reAddGroupHom : (reAddGroupHom : ℂ → ℝ) = re := rfl /-- The "imaginary part" map, considered as an additive group homomorphism. -/ def imAddGroupHom : ℂ →+ ℝ where toFun := im map_zero' := zero_im map_add' := add_im @[simp] theorem coe_imAddGroupHom : (imAddGroupHom : ℂ → ℝ) = im := rfl /-! ### Cast lemmas -/ instance instNNRatCast : NNRatCast ℂ where nnratCast q := ofReal q instance instRatCast : RatCast ℂ where ratCast q := ofReal q @[simp, norm_cast] lemma ofReal_ofNat (n : ℕ) [n.AtLeastTwo] : ofReal ofNat(n) = ofNat(n) := rfl @[simp, norm_cast] lemma ofReal_natCast (n : ℕ) : ofReal n = n := rfl @[simp, norm_cast] lemma ofReal_intCast (n : ℤ) : ofReal n = n := rfl @[simp, norm_cast] lemma ofReal_nnratCast (q : ℚ≥0) : ofReal q = q := rfl @[simp, norm_cast] lemma ofReal_ratCast (q : ℚ) : ofReal q = q := rfl @[simp] lemma re_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℂ).re = ofNat(n) := rfl @[simp] lemma im_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℂ).im = 0 := rfl @[simp, norm_cast] lemma natCast_re (n : ℕ) : (n : ℂ).re = n := rfl @[simp, norm_cast] lemma natCast_im (n : ℕ) : (n : ℂ).im = 0 := rfl @[simp, norm_cast] lemma intCast_re (n : ℤ) : (n : ℂ).re = n := rfl @[simp, norm_cast] lemma intCast_im (n : ℤ) : (n : ℂ).im = 0 := rfl @[simp, norm_cast] lemma re_nnratCast (q : ℚ≥0) : (q : ℂ).re = q := rfl @[simp, norm_cast] lemma im_nnratCast (q : ℚ≥0) : (q : ℂ).im = 0 := rfl @[simp, norm_cast] lemma ratCast_re (q : ℚ) : (q : ℂ).re = q := rfl @[simp, norm_cast] lemma ratCast_im (q : ℚ) : (q : ℂ).im = 0 := rfl lemma re_nsmul (n : ℕ) (z : ℂ) : (n • z).re = n • z.re := smul_re .. lemma im_nsmul (n : ℕ) (z : ℂ) : (n • z).im = n • z.im := smul_im .. lemma re_zsmul (n : ℤ) (z : ℂ) : (n • z).re = n • z.re := smul_re .. lemma im_zsmul (n : ℤ) (z : ℂ) : (n • z).im = n • z.im := smul_im .. @[simp] lemma re_nnqsmul (q : ℚ≥0) (z : ℂ) : (q • z).re = q • z.re := smul_re .. @[simp] lemma im_nnqsmul (q : ℚ≥0) (z : ℂ) : (q • z).im = q • z.im := smul_im .. @[simp] lemma re_qsmul (q : ℚ) (z : ℂ) : (q • z).re = q • z.re := smul_re .. @[simp] lemma im_qsmul (q : ℚ) (z : ℂ) : (q • z).im = q • z.im := smul_im .. @[norm_cast] lemma ofReal_nsmul (n : ℕ) (r : ℝ) : ↑(n • r) = n • (r : ℂ) := by simp @[norm_cast] lemma ofReal_zsmul (n : ℤ) (r : ℝ) : ↑(n • r) = n • (r : ℂ) := by simp /-! ### Complex conjugation -/ /-- This defines the complex conjugate as the `star` operation of the `StarRing ℂ`. It is recommended to use the ring endomorphism version `starRingEnd`, available under the notation `conj` in the locale `ComplexConjugate`. -/ instance : StarRing ℂ where star z := ⟨z.re, -z.im⟩ star_involutive x := by simp only [eta, neg_neg] star_mul a b := by ext <;> simp [add_comm] <;> ring star_add a b := by ext <;> simp [add_comm] @[simp] theorem conj_re (z : ℂ) : (conj z).re = z.re := rfl @[simp] theorem conj_im (z : ℂ) : (conj z).im = -z.im := rfl @[simp] theorem conj_ofReal (r : ℝ) : conj (r : ℂ) = r := Complex.ext_iff.2 <| by simp [star] @[simp] theorem conj_I : conj I = -I := Complex.ext_iff.2 <| by simp theorem conj_natCast (n : ℕ) : conj (n : ℂ) = n := map_natCast _ _ theorem conj_ofNat (n : ℕ) [n.AtLeastTwo] : conj (ofNat(n) : ℂ) = ofNat(n) := map_ofNat _ _ theorem conj_neg_I : conj (-I) = I := by simp theorem conj_eq_iff_real {z : ℂ} : conj z = z ↔ ∃ r : ℝ, z = r := ⟨fun h => ⟨z.re, ext rfl <| eq_zero_of_neg_eq (congr_arg im h)⟩, fun ⟨h, e⟩ => by rw [e, conj_ofReal]⟩ theorem conj_eq_iff_re {z : ℂ} : conj z = z ↔ (z.re : ℂ) = z := conj_eq_iff_real.trans ⟨by rintro ⟨r, rfl⟩; simp [ofReal], fun h => ⟨_, h.symm⟩⟩ theorem conj_eq_iff_im {z : ℂ} : conj z = z ↔ z.im = 0 := ⟨fun h => add_self_eq_zero.mp (neg_eq_iff_add_eq_zero.mp (congr_arg im h)), fun h => ext rfl (neg_eq_iff_add_eq_zero.mpr (add_self_eq_zero.mpr h))⟩ @[simp] theorem star_def : (Star.star : ℂ → ℂ) = conj := rfl /-! ### Norm squared -/ /-- The norm squared function. -/ @[pp_nodot] def normSq : ℂ →*₀ ℝ where toFun z := z.re * z.re + z.im * z.im map_zero' := by simp map_one' := by simp map_mul' z w := by dsimp ring theorem normSq_apply (z : ℂ) : normSq z = z.re * z.re + z.im * z.im := rfl @[simp] theorem normSq_ofReal (r : ℝ) : normSq r = r * r := by simp [normSq, ofReal] @[simp] theorem normSq_natCast (n : ℕ) : normSq n = n * n := normSq_ofReal _ @[simp] theorem normSq_intCast (z : ℤ) : normSq z = z * z := normSq_ofReal _ @[simp] theorem normSq_ratCast (q : ℚ) : normSq q = q * q := normSq_ofReal _ @[simp] theorem normSq_ofNat (n : ℕ) [n.AtLeastTwo] : normSq (ofNat(n) : ℂ) = ofNat(n) * ofNat(n) := normSq_natCast _ @[simp] theorem normSq_mk (x y : ℝ) : normSq ⟨x, y⟩ = x * x + y * y := rfl theorem normSq_add_mul_I (x y : ℝ) : normSq (x + y * I) = x ^ 2 + y ^ 2 := by rw [← mk_eq_add_mul_I, normSq_mk, sq, sq] theorem normSq_eq_conj_mul_self {z : ℂ} : (normSq z : ℂ) = conj z * z := by ext <;> simp [normSq, mul_comm, ofReal] theorem normSq_zero : normSq 0 = 0 := by simp theorem normSq_one : normSq 1 = 1 := by simp @[simp] theorem normSq_I : normSq I = 1 := by simp [normSq] theorem normSq_nonneg (z : ℂ) : 0 ≤ normSq z := add_nonneg (mul_self_nonneg _) (mul_self_nonneg _) theorem normSq_eq_zero {z : ℂ} : normSq z = 0 ↔ z = 0 := ⟨fun h => ext (eq_zero_of_mul_self_add_mul_self_eq_zero h) (eq_zero_of_mul_self_add_mul_self_eq_zero <| (add_comm _ _).trans h), fun h => h.symm ▸ normSq_zero⟩ @[simp] theorem normSq_pos {z : ℂ} : 0 < normSq z ↔ z ≠ 0 := (normSq_nonneg z).lt_iff_ne.trans <| not_congr (eq_comm.trans normSq_eq_zero) @[simp] theorem normSq_neg (z : ℂ) : normSq (-z) = normSq z := by simp [normSq] @[simp] theorem normSq_conj (z : ℂ) : normSq (conj z) = normSq z := by simp [normSq] theorem normSq_mul (z w : ℂ) : normSq (z * w) = normSq z * normSq w := normSq.map_mul z w theorem normSq_add (z w : ℂ) : normSq (z + w) = normSq z + normSq w + 2 * (z * conj w).re := by dsimp [normSq]; ring theorem re_sq_le_normSq (z : ℂ) : z.re * z.re ≤ normSq z := le_add_of_nonneg_right (mul_self_nonneg _) theorem im_sq_le_normSq (z : ℂ) : z.im * z.im ≤ normSq z := le_add_of_nonneg_left (mul_self_nonneg _) theorem mul_conj (z : ℂ) : z * conj z = normSq z := Complex.ext_iff.2 <| by simp [normSq, mul_comm, sub_eq_neg_add, add_comm, ofReal] theorem add_conj (z : ℂ) : z + conj z = (2 * z.re : ℝ) := Complex.ext_iff.2 <| by simp [two_mul, ofReal] /-- The coercion `ℝ → ℂ` as a `RingHom`. -/ def ofRealHom : ℝ →+* ℂ where toFun x := (x : ℂ) map_one' := ofReal_one map_zero' := ofReal_zero map_mul' := ofReal_mul map_add' := ofReal_add @[simp] lemma ofRealHom_eq_coe (r : ℝ) : ofRealHom r = r := rfl variable {α : Type*} @[simp] lemma ofReal_comp_add (f g : α → ℝ) : ofReal ∘ (f + g) = ofReal ∘ f + ofReal ∘ g := map_comp_add ofRealHom .. @[simp] lemma ofReal_comp_sub (f g : α → ℝ) : ofReal ∘ (f - g) = ofReal ∘ f - ofReal ∘ g := map_comp_sub ofRealHom .. @[simp] lemma ofReal_comp_neg (f : α → ℝ) : ofReal ∘ (-f) = -(ofReal ∘ f) := map_comp_neg ofRealHom _ lemma ofReal_comp_nsmul (n : ℕ) (f : α → ℝ) : ofReal ∘ (n • f) = n • (ofReal ∘ f) := map_comp_nsmul ofRealHom .. lemma ofReal_comp_zsmul (n : ℤ) (f : α → ℝ) : ofReal ∘ (n • f) = n • (ofReal ∘ f) := map_comp_zsmul ofRealHom .. @[simp] lemma ofReal_comp_mul (f g : α → ℝ) : ofReal ∘ (f * g) = ofReal ∘ f * ofReal ∘ g := map_comp_mul ofRealHom .. @[simp] lemma ofReal_comp_pow (f : α → ℝ) (n : ℕ) : ofReal ∘ (f ^ n) = (ofReal ∘ f) ^ n := map_comp_pow ofRealHom .. @[simp] theorem I_sq : I ^ 2 = -1 := by rw [sq, I_mul_I] @[simp] lemma I_pow_three : I ^ 3 = -I := by rw [pow_succ, I_sq, neg_one_mul] @[simp] theorem I_pow_four : I ^ 4 = 1 := by rw [(by norm_num : 4 = 2 * 2), pow_mul, I_sq, neg_one_sq] lemma I_pow_eq_pow_mod (n : ℕ) : I ^ n = I ^ (n % 4) := by conv_lhs => rw [← Nat.div_add_mod n 4] simp [pow_add, pow_mul, I_pow_four] @[simp] theorem sub_re (z w : ℂ) : (z - w).re = z.re - w.re := rfl @[simp] theorem sub_im (z w : ℂ) : (z - w).im = z.im - w.im := rfl @[simp, norm_cast] theorem ofReal_sub (r s : ℝ) : ((r - s : ℝ) : ℂ) = r - s := Complex.ext_iff.2 <| by simp [ofReal] @[simp, norm_cast] theorem ofReal_pow (r : ℝ) (n : ℕ) : ((r ^ n : ℝ) : ℂ) = (r : ℂ) ^ n := by induction n <;> simp [*, ofReal_mul, pow_succ] theorem sub_conj (z : ℂ) : z - conj z = (2 * z.im : ℝ) * I := Complex.ext_iff.2 <| by simp [two_mul, sub_eq_add_neg, ofReal] theorem normSq_sub (z w : ℂ) : normSq (z - w) = normSq z + normSq w - 2 * (z * conj w).re := by rw [sub_eq_add_neg, normSq_add] simp only [RingHom.map_neg, mul_neg, neg_re, normSq_neg] ring /-! ### Inversion -/ noncomputable instance : Inv ℂ := ⟨fun z => conj z * ((normSq z)⁻¹ : ℝ)⟩ theorem inv_def (z : ℂ) : z⁻¹ = conj z * ((normSq z)⁻¹ : ℝ) := rfl @[simp] theorem inv_re (z : ℂ) : z⁻¹.re = z.re / normSq z := by simp [inv_def, division_def, ofReal] @[simp] theorem inv_im (z : ℂ) : z⁻¹.im = -z.im / normSq z := by simp [inv_def, division_def, ofReal] @[simp, norm_cast] theorem ofReal_inv (r : ℝ) : ((r⁻¹ : ℝ) : ℂ) = (r : ℂ)⁻¹ := Complex.ext_iff.2 <| by simp [ofReal] protected theorem inv_zero : (0⁻¹ : ℂ) = 0 := by rw [← ofReal_zero, ← ofReal_inv, inv_zero] protected theorem mul_inv_cancel {z : ℂ} (h : z ≠ 0) : z * z⁻¹ = 1 := by rw [inv_def, ← mul_assoc, mul_conj, ← ofReal_mul, mul_inv_cancel₀ (mt normSq_eq_zero.1 h), ofReal_one] noncomputable instance instDivInvMonoid : DivInvMonoid ℂ where lemma div_re (z w : ℂ) : (z / w).re = z.re * w.re / normSq w + z.im * w.im / normSq w := by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg] lemma div_im (z w : ℂ) : (z / w).im = z.im * w.re / normSq w - z.re * w.im / normSq w := by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm] /-! ### Field instance and lemmas -/ noncomputable instance instField : Field ℂ where mul_inv_cancel := @Complex.mul_inv_cancel inv_zero := Complex.inv_zero nnqsmul := (· • ·) qsmul := (· • ·) nnratCast_def q := by ext <;> simp [NNRat.cast_def, div_re, div_im, mul_div_mul_comm] ratCast_def q := by ext <;> simp [Rat.cast_def, div_re, div_im, mul_div_mul_comm] nnqsmul_def n z := Complex.ext_iff.2 <| by simp [NNRat.smul_def, smul_re, smul_im] qsmul_def n z := Complex.ext_iff.2 <| by simp [Rat.smul_def, smul_re, smul_im] @[simp, norm_cast] lemma ofReal_nnqsmul (q : ℚ≥0) (r : ℝ) : ofReal (q • r) = q • r := by simp [NNRat.smul_def] @[simp, norm_cast] lemma ofReal_qsmul (q : ℚ) (r : ℝ) : ofReal (q • r) = q • r := by simp [Rat.smul_def] theorem conj_inv (x : ℂ) : conj x⁻¹ = (conj x)⁻¹ := star_inv₀ _ @[simp, norm_cast] theorem ofReal_div (r s : ℝ) : ((r / s : ℝ) : ℂ) = r / s := map_div₀ ofRealHom r s @[simp, norm_cast] theorem ofReal_zpow (r : ℝ) (n : ℤ) : ((r ^ n : ℝ) : ℂ) = (r : ℂ) ^ n := map_zpow₀ ofRealHom r n @[simp] theorem div_I (z : ℂ) : z / I = -(z * I) := (div_eq_iff_mul_eq I_ne_zero).2 <| by simp [mul_assoc] @[simp] theorem inv_I : I⁻¹ = -I := by rw [inv_eq_one_div, div_I, one_mul] theorem normSq_inv (z : ℂ) : normSq z⁻¹ = (normSq z)⁻¹ := by simp theorem normSq_div (z w : ℂ) : normSq (z / w) = normSq z / normSq w := by simp lemma div_ofReal (z : ℂ) (x : ℝ) : z / x = ⟨z.re / x, z.im / x⟩ := by simp_rw [div_eq_inv_mul, ← ofReal_inv, ofReal_mul'] lemma div_natCast (z : ℂ) (n : ℕ) : z / n = ⟨z.re / n, z.im / n⟩ := mod_cast div_ofReal z n lemma div_intCast (z : ℂ) (n : ℤ) : z / n = ⟨z.re / n, z.im / n⟩ := mod_cast div_ofReal z n lemma div_ratCast (z : ℂ) (x : ℚ) : z / x = ⟨z.re / x, z.im / x⟩ := mod_cast div_ofReal z x lemma div_ofNat (z : ℂ) (n : ℕ) [n.AtLeastTwo] : z / ofNat(n) = ⟨z.re / ofNat(n), z.im / ofNat(n)⟩ := div_natCast z n @[simp] lemma div_ofReal_re (z : ℂ) (x : ℝ) : (z / x).re = z.re / x := by rw [div_ofReal] @[simp] lemma div_ofReal_im (z : ℂ) (x : ℝ) : (z / x).im = z.im / x := by rw [div_ofReal] @[simp] lemma div_natCast_re (z : ℂ) (n : ℕ) : (z / n).re = z.re / n := by rw [div_natCast] @[simp] lemma div_natCast_im (z : ℂ) (n : ℕ) : (z / n).im = z.im / n := by rw [div_natCast] @[simp] lemma div_intCast_re (z : ℂ) (n : ℤ) : (z / n).re = z.re / n := by rw [div_intCast] @[simp] lemma div_intCast_im (z : ℂ) (n : ℤ) : (z / n).im = z.im / n := by rw [div_intCast] @[simp] lemma div_ratCast_re (z : ℂ) (x : ℚ) : (z / x).re = z.re / x := by rw [div_ratCast] @[simp] lemma div_ratCast_im (z : ℂ) (x : ℚ) : (z / x).im = z.im / x := by rw [div_ratCast] @[simp] lemma div_ofNat_re (z : ℂ) (n : ℕ) [n.AtLeastTwo] : (z / ofNat(n)).re = z.re / ofNat(n) := div_natCast_re z n @[simp] lemma div_ofNat_im (z : ℂ) (n : ℕ) [n.AtLeastTwo] : (z / ofNat(n)).im = z.im / ofNat(n) := div_natCast_im z n /-! ### Characteristic zero -/ instance instCharZero : CharZero ℂ := charZero_of_inj_zero fun n h => by rwa [← ofReal_natCast, ofReal_eq_zero, Nat.cast_eq_zero] at h /-- A complex number `z` plus its conjugate `conj z` is `2` times its real part. -/ theorem re_eq_add_conj (z : ℂ) : (z.re : ℂ) = (z + conj z) / 2 := by simp only [add_conj, ofReal_mul, ofReal_ofNat, mul_div_cancel_left₀ (z.re : ℂ) two_ne_zero] /-- A complex number `z` minus its conjugate `conj z` is `2i` times its imaginary part. -/ theorem im_eq_sub_conj (z : ℂ) : (z.im : ℂ) = (z - conj z) / (2 * I) := by simp only [sub_conj, ofReal_mul, ofReal_ofNat, mul_right_comm, mul_div_cancel_left₀ _ (mul_ne_zero two_ne_zero I_ne_zero : 2 * I ≠ 0)] /-- Show the imaginary number ⟨x, y⟩ as an "x + y*I" string Note that the Real numbers used for x and y will show as cauchy sequences due to the way Real numbers are represented. -/ unsafe instance instRepr : Repr ℂ where reprPrec f p := (if p > 65 then (Std.Format.bracket "(" · ")") else (·)) <| reprPrec f.re 65 ++ " + " ++ reprPrec f.im 70 ++ "*I" section reProdIm /-- The preimage under `equivRealProd` of `s ×ˢ t` is `s ×ℂ t`. -/ lemma preimage_equivRealProd_prod (s t : Set ℝ) : equivRealProd ⁻¹' (s ×ˢ t) = s ×ℂ t := rfl /-- The inequality `s × t ⊆ s₁ × t₁` holds in `ℂ` iff it holds in `ℝ × ℝ`. -/ lemma reProdIm_subset_iff {s s₁ t t₁ : Set ℝ} : s ×ℂ t ⊆ s₁ ×ℂ t₁ ↔ s ×ˢ t ⊆ s₁ ×ˢ t₁ := by rw [← @preimage_equivRealProd_prod s t, ← @preimage_equivRealProd_prod s₁ t₁] exact Equiv.preimage_subset equivRealProd _ _ /-- If `s ⊆ s₁ ⊆ ℝ` and `t ⊆ t₁ ⊆ ℝ`, then `s × t ⊆ s₁ × t₁` in `ℂ`. -/ lemma reProdIm_subset_iff' {s s₁ t t₁ : Set ℝ} : s ×ℂ t ⊆ s₁ ×ℂ t₁ ↔ s ⊆ s₁ ∧ t ⊆ t₁ ∨ s = ∅ ∨ t = ∅ := by convert prod_subset_prod_iff exact reProdIm_subset_iff variable {s t : Set ℝ} @[simp] lemma reProdIm_nonempty : (s ×ℂ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := by simp [Set.Nonempty, reProdIm, Complex.exists] @[simp] lemma reProdIm_eq_empty : s ×ℂ t = ∅ ↔ s = ∅ ∨ t = ∅ := by simp [← not_nonempty_iff_eq_empty, reProdIm_nonempty, -not_and, not_and_or]
end reProdIm
Mathlib/Data/Complex/Basic.lean
798
799
/- 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.BigOperators.Ring.Finset import Mathlib.Combinatorics.SimpleGraph.Density import Mathlib.Data.Nat.Cast.Order.Field import Mathlib.Order.Partition.Equipartition import Mathlib.SetTheory.Cardinal.Order /-! # Graph uniformity and uniform partitions In this file we define uniformity of a pair of vertices in a graph and uniformity of a partition of vertices of a graph. Both are also known as ε-regularity. Finsets of vertices `s` and `t` are `ε`-uniform in a graph `G` if their edge density is at most `ε`-far from the density of any big enough `s'` and `t'` where `s' ⊆ s`, `t' ⊆ t`. The definition is pretty technical, but it amounts to the edges between `s` and `t` being "random" The literature contains several definitions which are equivalent up to scaling `ε` by some constant when the partition is equitable. A partition `P` of the vertices is `ε`-uniform if the proportion of non `ε`-uniform pairs of parts is less than `ε`. ## Main declarations * `SimpleGraph.IsUniform`: Graph uniformity of a pair of finsets of vertices. * `SimpleGraph.nonuniformWitness`: `G.nonuniformWitness ε s t` and `G.nonuniformWitness ε t s` together witness the non-uniformity of `s` and `t`. * `Finpartition.nonUniforms`: Non uniform pairs of parts of a partition. * `Finpartition.IsUniform`: Uniformity of a partition. * `Finpartition.nonuniformWitnesses`: For each non-uniform pair of parts of a partition, pick witnesses of non-uniformity and dump them all together. ## References [Yaël Dillies, Bhavik Mehta, *Formalising Szemerédi’s Regularity Lemma in Lean*][srl_itp] -/ open Finset variable {α 𝕜 : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] /-! ### Graph uniformity -/ namespace SimpleGraph variable (G : SimpleGraph α) [DecidableRel G.Adj] (ε : 𝕜) {s t : Finset α} {a b : α} /-- A pair of finsets of vertices is `ε`-uniform (aka `ε`-regular) iff their edge density is close to the density of any big enough pair of subsets. Intuitively, the edges between them are random-like. -/ def IsUniform (s t : Finset α) : Prop := ∀ ⦃s'⦄, s' ⊆ s → ∀ ⦃t'⦄, t' ⊆ t → (#s : 𝕜) * ε ≤ #s' → (#t : 𝕜) * ε ≤ #t' → |(G.edgeDensity s' t' : 𝕜) - (G.edgeDensity s t : 𝕜)| < ε variable {G ε} instance IsUniform.instDecidableRel : DecidableRel (G.IsUniform ε) := by unfold IsUniform; infer_instance theorem IsUniform.mono {ε' : 𝕜} (h : ε ≤ ε') (hε : IsUniform G ε s t) : IsUniform G ε' s t := fun s' hs' t' ht' hs ht => by refine (hε hs' ht' (le_trans ?_ hs) (le_trans ?_ ht)).trans_le h <;> gcongr omit [IsStrictOrderedRing 𝕜] in theorem IsUniform.symm : Symmetric (IsUniform G ε) := fun s t h t' ht' s' hs' ht hs => by rw [edgeDensity_comm _ t', edgeDensity_comm _ t] exact h hs' ht' hs ht variable (G) omit [IsStrictOrderedRing 𝕜] in theorem isUniform_comm : IsUniform G ε s t ↔ IsUniform G ε t s := ⟨fun h => h.symm, fun h => h.symm⟩ lemma isUniform_one : G.IsUniform (1 : 𝕜) s t := by intro s' hs' t' ht' hs ht rw [mul_one] at hs ht rw [eq_of_subset_of_card_le hs' (Nat.cast_le.1 hs), eq_of_subset_of_card_le ht' (Nat.cast_le.1 ht), sub_self, abs_zero] exact zero_lt_one variable {G} lemma IsUniform.pos (hG : G.IsUniform ε s t) : 0 < ε := not_le.1 fun hε ↦ (hε.trans <| abs_nonneg _).not_lt <| hG (empty_subset _) (empty_subset _) (by simpa using mul_nonpos_of_nonneg_of_nonpos (Nat.cast_nonneg _) hε) (by simpa using mul_nonpos_of_nonneg_of_nonpos (Nat.cast_nonneg _) hε) @[simp] lemma isUniform_singleton : G.IsUniform ε {a} {b} ↔ 0 < ε := by refine ⟨IsUniform.pos, fun hε s' hs' t' ht' hs ht ↦ ?_⟩ rw [card_singleton, Nat.cast_one, one_mul] at hs ht obtain rfl | rfl := Finset.subset_singleton_iff.1 hs' · replace hs : ε ≤ 0 := by simpa using hs exact (hε.not_le hs).elim obtain rfl | rfl := Finset.subset_singleton_iff.1 ht' · replace ht : ε ≤ 0 := by simpa using ht exact (hε.not_le ht).elim · rwa [sub_self, abs_zero] theorem not_isUniform_zero : ¬G.IsUniform (0 : 𝕜) s t := fun h => (abs_nonneg _).not_lt <| h (empty_subset _) (empty_subset _) (by simp) (by simp) theorem not_isUniform_iff : ¬G.IsUniform ε s t ↔ ∃ s', s' ⊆ s ∧ ∃ t', t' ⊆ t ∧ #s * ε ≤ #s' ∧ #t * ε ≤ #t' ∧ ε ≤ |G.edgeDensity s' t' - G.edgeDensity s t| := by unfold IsUniform simp only [not_forall, not_lt, exists_prop, exists_and_left, Rat.cast_abs, Rat.cast_sub] variable (G) /-- An arbitrary pair of subsets witnessing the non-uniformity of `(s, t)`. If `(s, t)` is uniform, returns `(s, t)`. Witnesses for `(s, t)` and `(t, s)` don't necessarily match. See `SimpleGraph.nonuniformWitness`. -/ noncomputable def nonuniformWitnesses (ε : 𝕜) (s t : Finset α) : Finset α × Finset α := if h : ¬G.IsUniform ε s t then ((not_isUniform_iff.1 h).choose, (not_isUniform_iff.1 h).choose_spec.2.choose) else (s, t) theorem left_nonuniformWitnesses_subset (h : ¬G.IsUniform ε s t) : (G.nonuniformWitnesses ε s t).1 ⊆ s := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.1 theorem left_nonuniformWitnesses_card (h : ¬G.IsUniform ε s t) : #s * ε ≤ #(G.nonuniformWitnesses ε s t).1 := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.2.choose_spec.2.1 theorem right_nonuniformWitnesses_subset (h : ¬G.IsUniform ε s t) : (G.nonuniformWitnesses ε s t).2 ⊆ t := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.2.choose_spec.1 theorem right_nonuniformWitnesses_card (h : ¬G.IsUniform ε s t) : #t * ε ≤ #(G.nonuniformWitnesses ε s t).2 := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.2.choose_spec.2.2.1 theorem nonuniformWitnesses_spec (h : ¬G.IsUniform ε s t) : ε ≤ |G.edgeDensity (G.nonuniformWitnesses ε s t).1 (G.nonuniformWitnesses ε s t).2 - G.edgeDensity s t| := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.2.choose_spec.2.2.2 open scoped Classical in /-- Arbitrary witness of non-uniformity. `G.nonuniformWitness ε s t` and `G.nonuniformWitness ε t s` form a pair of subsets witnessing the non-uniformity of `(s, t)`. If `(s, t)` is uniform, returns `s`. -/ noncomputable def nonuniformWitness (ε : 𝕜) (s t : Finset α) : Finset α := if WellOrderingRel s t then (G.nonuniformWitnesses ε s t).1 else (G.nonuniformWitnesses ε t s).2 theorem nonuniformWitness_subset (h : ¬G.IsUniform ε s t) : G.nonuniformWitness ε s t ⊆ s := by unfold nonuniformWitness split_ifs · exact G.left_nonuniformWitnesses_subset h · exact G.right_nonuniformWitnesses_subset fun i => h i.symm theorem le_card_nonuniformWitness (h : ¬G.IsUniform ε s t) : #s * ε ≤ #(G.nonuniformWitness ε s t) := by unfold nonuniformWitness split_ifs · exact G.left_nonuniformWitnesses_card h · exact G.right_nonuniformWitnesses_card fun i => h i.symm theorem nonuniformWitness_spec (h₁ : s ≠ t) (h₂ : ¬G.IsUniform ε s t) : ε ≤ |G.edgeDensity (G.nonuniformWitness ε s t) (G.nonuniformWitness ε t s) - G.edgeDensity s t| := by unfold nonuniformWitness rcases trichotomous_of WellOrderingRel s t with (lt | rfl | gt) · rw [if_pos lt, if_neg (asymm lt)] exact G.nonuniformWitnesses_spec h₂ · cases h₁ rfl · rw [if_neg (asymm gt), if_pos gt, edgeDensity_comm, edgeDensity_comm _ s] apply G.nonuniformWitnesses_spec fun i => h₂ i.symm end SimpleGraph /-! ### Uniform partitions -/ variable [DecidableEq α] {A : Finset α} (P : Finpartition A) (G : SimpleGraph α) [DecidableRel G.Adj] {ε δ : 𝕜} {u v : Finset α} namespace Finpartition /-- The pairs of parts of a partition `P` which are not `ε`-dense in a graph `G`. Note that we dismiss the diagonal. We do not care whether `s` is `ε`-dense with itself. -/ def sparsePairs (ε : 𝕜) : Finset (Finset α × Finset α) := P.parts.offDiag.filter fun (u, v) ↦ G.edgeDensity u v < ε omit [IsStrictOrderedRing 𝕜] in @[simp] lemma mk_mem_sparsePairs (u v : Finset α) (ε : 𝕜) : (u, v) ∈ P.sparsePairs G ε ↔ u ∈ P.parts ∧ v ∈ P.parts ∧ u ≠ v ∧ G.edgeDensity u v < ε := by rw [sparsePairs, mem_filter, mem_offDiag, and_assoc, and_assoc] omit [IsStrictOrderedRing 𝕜] in lemma sparsePairs_mono {ε ε' : 𝕜} (h : ε ≤ ε') : P.sparsePairs G ε ⊆ P.sparsePairs G ε' := monotone_filter_right _ fun _ ↦ h.trans_lt' /-- The pairs of parts of a partition `P` which are not `ε`-uniform in a graph `G`. Note that we dismiss the diagonal. We do not care whether `s` is `ε`-uniform with itself. -/ def nonUniforms (ε : 𝕜) : Finset (Finset α × Finset α) := P.parts.offDiag.filter fun (u, v) ↦ ¬G.IsUniform ε u v omit [IsStrictOrderedRing 𝕜] in @[simp] lemma mk_mem_nonUniforms : (u, v) ∈ P.nonUniforms G ε ↔ u ∈ P.parts ∧ v ∈ P.parts ∧ u ≠ v ∧ ¬G.IsUniform ε u v := by rw [nonUniforms, mem_filter, mem_offDiag, and_assoc, and_assoc] theorem nonUniforms_mono {ε ε' : 𝕜} (h : ε ≤ ε') : P.nonUniforms G ε' ⊆ P.nonUniforms G ε := monotone_filter_right _ fun _ => mt <| SimpleGraph.IsUniform.mono h theorem nonUniforms_bot (hε : 0 < ε) : (⊥ : Finpartition A).nonUniforms G ε = ∅ := by rw [eq_empty_iff_forall_not_mem] rintro ⟨u, v⟩ simp only [mk_mem_nonUniforms, parts_bot, mem_map, not_and, Classical.not_not, exists_imp]; dsimp rintro x ⟨_, rfl⟩ y ⟨_,rfl⟩ _ rwa [SimpleGraph.isUniform_singleton] /-- A finpartition of a graph's vertex set is `ε`-uniform (aka `ε`-regular) iff the proportion of its pairs of parts that are not `ε`-uniform is at most `ε`. -/ def IsUniform (ε : 𝕜) : Prop := (#(P.nonUniforms G ε) : 𝕜) ≤ (#P.parts * (#P.parts - 1) : ℕ) * ε lemma bot_isUniform (hε : 0 < ε) : (⊥ : Finpartition A).IsUniform G ε := by rw [Finpartition.IsUniform, Finpartition.card_bot, nonUniforms_bot _ hε, Finset.card_empty, Nat.cast_zero] exact mul_nonneg (Nat.cast_nonneg _) hε.le lemma isUniform_one : P.IsUniform G (1 : 𝕜) := by rw [IsUniform, mul_one, Nat.cast_le] refine (card_filter_le _ (fun uv => ¬SimpleGraph.IsUniform G 1 (Prod.fst uv) (Prod.snd uv))).trans ?_ rw [offDiag_card, Nat.mul_sub_left_distrib, mul_one] variable {P G} theorem IsUniform.mono {ε ε' : 𝕜} (hP : P.IsUniform G ε) (h : ε ≤ ε') : P.IsUniform G ε' := ((Nat.cast_le.2 <| card_le_card <| P.nonUniforms_mono G h).trans hP).trans <| by gcongr omit [IsStrictOrderedRing 𝕜] in theorem isUniformOfEmpty (hP : P.parts = ∅) : P.IsUniform G ε := by simp [IsUniform, hP, nonUniforms] omit [IsStrictOrderedRing 𝕜] in theorem nonempty_of_not_uniform (h : ¬P.IsUniform G ε) : P.parts.Nonempty := nonempty_of_ne_empty fun h₁ => h <| isUniformOfEmpty h₁ variable (P G ε) (s : Finset α) /-- A choice of witnesses of non-uniformity among the parts of a finpartition. -/ noncomputable def nonuniformWitnesses : Finset (Finset α) := {t ∈ P.parts | s ≠ t ∧ ¬G.IsUniform ε s t}.image (G.nonuniformWitness ε s) variable {P G ε s} {t : Finset α} theorem nonuniformWitness_mem_nonuniformWitnesses (h : ¬G.IsUniform ε s t) (ht : t ∈ P.parts) (hst : s ≠ t) : G.nonuniformWitness ε s t ∈ P.nonuniformWitnesses G ε s := mem_image_of_mem _ <| mem_filter.2 ⟨ht, hst, h⟩ /-! ### Equipartitions -/ open SimpleGraph in lemma IsEquipartition.card_interedges_sparsePairs_le' (hP : P.IsEquipartition) (hε : 0 ≤ ε) : #((P.sparsePairs G ε).biUnion fun (U, V) ↦ G.interedges U V) ≤ ε * (#A + #P.parts) ^ 2 := by calc _ ≤ ∑ UV ∈ P.sparsePairs G ε, (#(G.interedges UV.1 UV.2) : 𝕜) := mod_cast card_biUnion_le _ ≤ ∑ UV ∈ P.sparsePairs G ε, ε * (#UV.1 * #UV.2) := ?_ _ ≤ _ := sum_le_sum_of_subset_of_nonneg (filter_subset _ _) fun i _ _ ↦ by positivity _ = _ := (mul_sum _ _ _).symm _ ≤ _ := mul_le_mul_of_nonneg_left ?_ hε · gcongr with UV hUV obtain ⟨U, V⟩ := UV simp [mk_mem_sparsePairs, ← card_interedges_div_card] at hUV refine ((div_lt_iff₀ ?_).1 hUV.2.2.2).le exact mul_pos (Nat.cast_pos.2 (P.nonempty_of_mem_parts hUV.1).card_pos) (Nat.cast_pos.2 (P.nonempty_of_mem_parts hUV.2.1).card_pos) norm_cast calc (_ : ℕ) ≤ _ := sum_le_card_nsmul P.parts.offDiag (fun i ↦ #i.1 * #i.2) ((#A / #P.parts + 1)^2 : ℕ) ?_ _ ≤ (#P.parts * (#A / #P.parts) + #P.parts) ^ 2 := ?_ _ ≤ _ := Nat.pow_le_pow_left (add_le_add_right (Nat.mul_div_le _ _) _) _ · simp only [Prod.forall, Finpartition.mk_mem_nonUniforms, and_imp, mem_offDiag, sq] rintro U V hU hV - exact_mod_cast Nat.mul_le_mul (hP.card_part_le_average_add_one hU) (hP.card_part_le_average_add_one hV) · rw [smul_eq_mul, offDiag_card, Nat.mul_sub_right_distrib, ← sq, ← mul_pow, mul_add_one (α := ℕ)] exact Nat.sub_le _ _ lemma IsEquipartition.card_interedges_sparsePairs_le (hP : P.IsEquipartition) (hε : 0 ≤ ε) : #((P.sparsePairs G ε).biUnion fun (U, V) ↦ G.interedges U V) ≤ 4 * ε * #A ^ 2 := by calc _ ≤ _ := hP.card_interedges_sparsePairs_le' hε _ ≤ ε * (#A + #A)^2 := by gcongr; exact P.card_parts_le_card _ = _ := by ring private lemma aux {i j : ℕ} (hj : 0 < j) : j * (j - 1) * (i / j + 1) ^ 2 < (i + j) ^ 2 := by have : j * (j - 1) < j ^ 2 := by rw [sq]; exact Nat.mul_lt_mul_of_pos_left (Nat.sub_lt hj zero_lt_one) hj apply (Nat.mul_lt_mul_of_pos_right this <| pow_pos Nat.succ_pos' _).trans_le rw [← mul_pow] exact Nat.pow_le_pow_left (add_le_add_right (Nat.mul_div_le i j) _) _ lemma IsEquipartition.card_biUnion_offDiag_le' (hP : P.IsEquipartition) : (#(P.parts.biUnion offDiag) : 𝕜) ≤ #A * (#A + #P.parts) / #P.parts := by obtain h | h := P.parts.eq_empty_or_nonempty · simp [h] calc _ ≤ (#P.parts : 𝕜) * (↑(#A / #P.parts) * ↑(#A / #P.parts + 1)) := mod_cast card_biUnion_le_card_mul _ _ _ fun U hU ↦ ?_ _ = #P.parts * ↑(#A / #P.parts) * ↑(#A / #P.parts + 1) := by rw [mul_assoc] _ ≤ #A * (#A / #P.parts + 1) := mul_le_mul (mod_cast Nat.mul_div_le _ _) ?_ (by positivity) (by positivity) _ = _ := by rw [← div_add_same (mod_cast h.card_pos.ne'), mul_div_assoc] · simpa using Nat.cast_div_le suffices (#U - 1) * #U ≤ #A / #P.parts * (#A / #P.parts + 1) by rwa [Nat.mul_sub_right_distrib, one_mul, ← offDiag_card] at this have := hP.card_part_le_average_add_one hU refine Nat.mul_le_mul ((Nat.sub_le_sub_right this 1).trans ?_) this simp only [Nat.add_succ_sub_one, add_zero, card_univ, le_rfl] lemma IsEquipartition.card_biUnion_offDiag_le (hε : 0 < ε) (hP : P.IsEquipartition) (hP' : 4 / ε ≤ #P.parts) : #(P.parts.biUnion offDiag) ≤ ε / 2 * #A ^ 2 := by obtain rfl | hA : A = ⊥ ∨ _ := A.eq_empty_or_nonempty · simp [Subsingleton.elim P ⊥] apply hP.card_biUnion_offDiag_le'.trans rw [div_le_iff₀ (Nat.cast_pos.2 (P.parts_nonempty hA.ne_empty).card_pos)] have : (#A : 𝕜) + #P.parts ≤ 2 * #A := by rw [two_mul]; exact add_le_add_left (Nat.cast_le.2 P.card_parts_le_card) _ refine (mul_le_mul_of_nonneg_left this <| by positivity).trans ?_ suffices 1 ≤ ε/4 * #P.parts by rw [mul_left_comm, ← sq] convert mul_le_mul_of_nonneg_left this (mul_nonneg zero_le_two <| sq_nonneg (#A : 𝕜)) using 1 <;> ring rwa [← div_le_iff₀', one_div_div] positivity lemma IsEquipartition.sum_nonUniforms_lt' (hA : A.Nonempty) (hε : 0 < ε) (hP : P.IsEquipartition) (hG : P.IsUniform G ε) : ∑ i ∈ P.nonUniforms G ε, (#i.1 * #i.2 : 𝕜) < ε * (#A + #P.parts) ^ 2 := by calc _ ≤ #(P.nonUniforms G ε) • (↑(#A / #P.parts + 1) : 𝕜) ^ 2 := sum_le_card_nsmul _ _ _ ?_ _ = _ := nsmul_eq_mul _ _ _ ≤ _ := mul_le_mul_of_nonneg_right hG <| by positivity _ < _ := ?_ · simp only [Prod.forall, Finpartition.mk_mem_nonUniforms, and_imp] rintro U V hU hV - - rw [sq, ← Nat.cast_mul, ← Nat.cast_mul, Nat.cast_le] exact Nat.mul_le_mul (hP.card_part_le_average_add_one hU) (hP.card_part_le_average_add_one hV) · rw [mul_right_comm _ ε, mul_comm ε] apply mul_lt_mul_of_pos_right _ hε norm_cast exact aux (P.parts_nonempty hA.ne_empty).card_pos lemma IsEquipartition.sum_nonUniforms_lt (hA : A.Nonempty) (hε : 0 < ε) (hP : P.IsEquipartition) (hG : P.IsUniform G ε) : #((P.nonUniforms G ε).biUnion fun (U, V) ↦ U ×ˢ V) < 4 * ε * #A ^ 2 := by calc _ ≤ ∑ i ∈ P.nonUniforms G ε, (#i.1 * #i.2 : 𝕜) := by norm_cast; simp_rw [← card_product]; exact card_biUnion_le _ < _ := hP.sum_nonUniforms_lt' hA hε hG _ ≤ ε * (#A + #A) ^ 2 := by gcongr; exact P.card_parts_le_card _ = _ := by ring end Finpartition /-! ### Reduced graph -/ namespace SimpleGraph /-- The reduction of the graph `G` along partition `P` has edges between `ε`-uniform pairs of parts that have edge density at least `δ`. -/ @[simps] def regularityReduced (ε δ : 𝕜) : SimpleGraph α where Adj a b := G.Adj a b ∧ ∃ U ∈ P.parts, ∃ V ∈ P.parts, a ∈ U ∧ b ∈ V ∧ U ≠ V ∧ G.IsUniform ε U V ∧ δ ≤ G.edgeDensity U V symm a b := by rintro ⟨ab, U, UP, V, VP, xU, yV, UV, GUV, εUV⟩ refine ⟨G.symm ab, V, VP, U, UP, yV, xU, UV.symm, GUV.symm, ?_⟩ rwa [edgeDensity_comm] loopless a h := G.loopless a h.1 instance regularityReduced.instDecidableRel_adj : DecidableRel (G.regularityReduced P ε δ).Adj := by unfold regularityReduced; infer_instance variable {G P} omit [IsStrictOrderedRing 𝕜] in lemma regularityReduced_le : G.regularityReduced P ε δ ≤ G := fun _ _ ↦ And.left lemma regularityReduced_mono {ε₁ ε₂ : 𝕜} (hε : ε₁ ≤ ε₂) : G.regularityReduced P ε₁ δ ≤ G.regularityReduced P ε₂ δ := fun _a _b ⟨hab, U, hU, V, hV, ha, hb, hUV, hGε, hGδ⟩ ↦ ⟨hab, U, hU, V, hV, ha, hb, hUV, hGε.mono hε, hGδ⟩ omit [IsStrictOrderedRing 𝕜] in lemma regularityReduced_anti {δ₁ δ₂ : 𝕜} (hδ : δ₁ ≤ δ₂) : G.regularityReduced P ε δ₂ ≤ G.regularityReduced P ε δ₁ := fun _a _b ⟨hab, U, hU, V, hV, ha, hb, hUV, hUVε, hUVδ⟩ ↦ ⟨hab, U, hU, V, hV, ha, hb, hUV, hUVε, hδ.trans hUVδ⟩ omit [IsStrictOrderedRing 𝕜] in lemma unreduced_edges_subset : (A ×ˢ A).filter (fun (x, y) ↦ G.Adj x y ∧ ¬ (G.regularityReduced P (ε/8) (ε/4)).Adj x y) ⊆ (P.nonUniforms G (ε/8)).biUnion (fun (U, V) ↦ U ×ˢ V) ∪ P.parts.biUnion offDiag ∪ (P.sparsePairs G (ε/4)).biUnion fun (U, V) ↦ G.interedges U V := by rintro ⟨x, y⟩ simp only [mem_sdiff, mem_filter, mem_univ, true_and, regularityReduced_adj, not_and, not_exists, not_le, mem_biUnion, mem_union, exists_prop, mem_product, Prod.exists, mem_offDiag, and_imp, or_assoc, and_assoc, P.mk_mem_nonUniforms, Finpartition.mk_mem_sparsePairs, mem_interedges_iff] intros hx hy h h' replace h' := h' h obtain ⟨U, hU, hx⟩ := P.exists_mem hx obtain ⟨V, hV, hy⟩ := P.exists_mem hy obtain rfl | hUV := eq_or_ne U V · exact Or.inr (Or.inl ⟨U, hU, hx, hy, G.ne_of_adj h⟩) by_cases h₂ : G.IsUniform (ε/8) U V · exact Or.inr <| Or.inr ⟨U, V, hU, hV, hUV, h' _ hU _ hV hx hy hUV h₂, hx, hy, h⟩ · exact Or.inl ⟨U, V, hU, hV, hUV, h₂, hx, hy⟩ end SimpleGraph
Mathlib/Combinatorics/SimpleGraph/Regularity/Uniform.lean
438
454
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen, Kim Morrison, Chris Hughes, Anne Baanen -/ import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.LinearAlgebra.Basis.Prod import Mathlib.LinearAlgebra.Dimension.Free import Mathlib.LinearAlgebra.TensorProduct.Basis /-! # Rank of various constructions ## Main statements - `rank_quotient_add_rank_le` : `rank M/N + rank N ≤ rank M`. - `lift_rank_add_lift_rank_le_rank_prod`: `rank M × N ≤ rank M + rank N`. - `rank_span_le_of_finite`: `rank (span s) ≤ #s` for finite `s`. For free modules, we have - `rank_prod` : `rank M × N = rank M + rank N`. - `rank_finsupp` : `rank (ι →₀ M) = #ι * rank M` - `rank_directSum`: `rank (⨁ Mᵢ) = ∑ rank Mᵢ` - `rank_tensorProduct`: `rank (M ⊗ N) = rank M * rank N`. Lemmas for ranks of submodules and subalgebras are also provided. We have finrank variants for most lemmas as well. -/ noncomputable section universe u u' v v' u₁' w w' variable {R : Type u} {S : Type u'} {M : Type v} {M' : Type v'} {M₁ : Type v} variable {ι : Type w} {ι' : Type w'} {η : Type u₁'} {φ : η → Type*} open Basis Cardinal DirectSum Function Module Set Submodule section Quotient variable [Ring R] [CommRing S] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁] variable [Module R M] theorem LinearIndependent.sumElim_of_quotient {M' : Submodule R M} {ι₁ ι₂} {f : ι₁ → M'} (hf : LinearIndependent R f) (g : ι₂ → M) (hg : LinearIndependent R (Submodule.Quotient.mk (p := M') ∘ g)) : LinearIndependent R (Sum.elim (f · : ι₁ → M) g) := by refine .sum_type (hf.map' M'.subtype M'.ker_subtype) (.of_comp M'.mkQ hg) ?_ refine disjoint_def.mpr fun x h₁ h₂ ↦ ?_ have : x ∈ M' := span_le.mpr (Set.range_subset_iff.mpr fun i ↦ (f i).prop) h₁ obtain ⟨c, rfl⟩ := Finsupp.mem_span_range_iff_exists_finsupp.mp h₂ simp_rw [← Quotient.mk_eq_zero, ← mkQ_apply, map_finsuppSum, map_smul, mkQ_apply] at this rw [linearIndependent_iff.mp hg _ this, Finsupp.sum_zero_index] @[deprecated (since := "2025-02-21")] alias LinearIndependent.sum_elim_of_quotient := LinearIndependent.sumElim_of_quotient theorem LinearIndepOn.union_of_quotient {s t : Set ι} {f : ι → M} (hs : LinearIndepOn R f s) (ht : LinearIndepOn R (mkQ (span R (f '' s)) ∘ f) t) : LinearIndepOn R f (s ∪ t) := by apply hs.union ht.of_comp convert (Submodule.range_ker_disjoint ht).symm · simp aesop theorem LinearIndepOn.union_id_of_quotient {M' : Submodule R M} {s : Set M} (hs : s ⊆ M') (hs' : LinearIndepOn R id s) {t : Set M} (ht : LinearIndepOn R (mkQ M') t) : LinearIndepOn R id (s ∪ t) := hs'.union_of_quotient <| by rw [image_id] exact ht.of_comp ((span R s).mapQ M' (LinearMap.id) (span_le.2 hs)) @[deprecated (since := "2025-02-16")] alias LinearIndependent.union_of_quotient := LinearIndepOn.union_id_of_quotient theorem linearIndepOn_union_iff_quotient {s t : Set ι} {f : ι → M} (hst : Disjoint s t) : LinearIndepOn R f (s ∪ t) ↔ LinearIndepOn R f s ∧ LinearIndepOn R (mkQ (span R (f '' s)) ∘ f) t := by refine ⟨fun h ↦ ⟨?_, ?_⟩, fun h ↦ h.1.union_of_quotient h.2⟩ · exact h.mono subset_union_left apply (h.mono subset_union_right).map simpa [← image_eq_range] using ((linearIndepOn_union_iff hst).1 h).2.2.symm theorem LinearIndepOn.quotient_iff_union {s t : Set ι} {f : ι → M} (hs : LinearIndepOn R f s) (hst : Disjoint s t) : LinearIndepOn R (mkQ (span R (f '' s)) ∘ f) t ↔ LinearIndepOn R f (s ∪ t) := by rw [linearIndepOn_union_iff_quotient hst, and_iff_right hs] theorem rank_quotient_add_rank_le [Nontrivial R] (M' : Submodule R M) : Module.rank R (M ⧸ M') + Module.rank R M' ≤ Module.rank R M := by conv_lhs => simp only [Module.rank_def] have := nonempty_linearIndependent_set R (M ⧸ M') have := nonempty_linearIndependent_set R M' rw [Cardinal.ciSup_add_ciSup _ (bddAbove_range _) _ (bddAbove_range _)] refine ciSup_le fun ⟨s, hs⟩ ↦ ciSup_le fun ⟨t, ht⟩ ↦ ?_ choose f hf using Submodule.Quotient.mk_surjective M' simpa [add_comm] using (LinearIndependent.sumElim_of_quotient ht (fun (i : s) ↦ f i) (by simpa [Function.comp_def, hf] using hs)).cardinal_le_rank theorem rank_quotient_le (p : Submodule R M) : Module.rank R (M ⧸ p) ≤ Module.rank R M := (mkQ p).rank_le_of_surjective Quot.mk_surjective /-- The dimension of a quotient is bounded by the dimension of the ambient space. -/ theorem Submodule.finrank_quotient_le [StrongRankCondition R] [Module.Finite R M] (s : Submodule R M) : finrank R (M ⧸ s) ≤ finrank R M := toNat_le_toNat ((Submodule.mkQ s).rank_le_of_surjective Quot.mk_surjective) (rank_lt_aleph0 _ _) end Quotient variable [Semiring R] [CommSemiring S] [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M₁] variable [Module R M] section ULift @[simp] theorem rank_ulift : Module.rank R (ULift.{w} M) = Cardinal.lift.{w} (Module.rank R M) := Cardinal.lift_injective.{v} <| Eq.symm <| (lift_lift _).trans ULift.moduleEquiv.symm.lift_rank_eq @[simp] theorem finrank_ulift : finrank R (ULift M) = finrank R M := by simp_rw [finrank, rank_ulift, toNat_lift] end ULift section Prod variable (R M M') variable [Module R M₁] [Module R M'] theorem rank_add_rank_le_rank_prod [Nontrivial R] : Module.rank R M + Module.rank R M₁ ≤ Module.rank R (M × M₁) := by conv_lhs => simp only [Module.rank_def] have := nonempty_linearIndependent_set R M have := nonempty_linearIndependent_set R M₁ rw [Cardinal.ciSup_add_ciSup _ (bddAbove_range _) _ (bddAbove_range _)] exact ciSup_le fun ⟨s, hs⟩ ↦ ciSup_le fun ⟨t, ht⟩ ↦ (linearIndependent_inl_union_inr' hs ht).cardinal_le_rank theorem lift_rank_add_lift_rank_le_rank_prod [Nontrivial R] : lift.{v'} (Module.rank R M) + lift.{v} (Module.rank R M') ≤ Module.rank R (M × M') := by rw [← rank_ulift, ← rank_ulift] exact (rank_add_rank_le_rank_prod R _).trans_eq (ULift.moduleEquiv.prodCongr ULift.moduleEquiv).rank_eq variable {R M M'} variable [StrongRankCondition R] [Module.Free R M] [Module.Free R M'] [Module.Free R M₁] open Module.Free /-- If `M` and `M'` are free, then the rank of `M × M'` is `(Module.rank R M).lift + (Module.rank R M').lift`. -/ @[simp] theorem rank_prod : Module.rank R (M × M') = Cardinal.lift.{v'} (Module.rank R M) + Cardinal.lift.{v, v'} (Module.rank R M') := by simpa [rank_eq_card_chooseBasisIndex R M, rank_eq_card_chooseBasisIndex R M', lift_umax] using ((chooseBasis R M).prod (chooseBasis R M')).mk_eq_rank.symm /-- If `M` and `M'` are free (and lie in the same universe), the rank of `M × M'` is `(Module.rank R M) + (Module.rank R M')`. -/ theorem rank_prod' : Module.rank R (M × M₁) = Module.rank R M + Module.rank R M₁ := by simp /-- The finrank of `M × M'` is `(finrank R M) + (finrank R M')`. -/ @[simp] theorem Module.finrank_prod [Module.Finite R M] [Module.Finite R M'] : finrank R (M × M') = finrank R M + finrank R M' := by simp [finrank, rank_lt_aleph0 R M, rank_lt_aleph0 R M'] end Prod section Finsupp variable (R M M') variable [StrongRankCondition R] [Module.Free R M] [Module R M'] [Module.Free R M'] open Module.Free @[simp] theorem rank_finsupp (ι : Type w) : Module.rank R (ι →₀ M) = Cardinal.lift.{v} #ι * Cardinal.lift.{w} (Module.rank R M) := by obtain ⟨⟨_, bs⟩⟩ := Module.Free.exists_basis (R := R) (M := M) rw [← bs.mk_eq_rank'', ← (Finsupp.basis fun _ : ι => bs).mk_eq_rank'', Cardinal.mk_sigma, Cardinal.sum_const] theorem rank_finsupp' (ι : Type v) : Module.rank R (ι →₀ M) = #ι * Module.rank R M := by simp [rank_finsupp] /-- The rank of `(ι →₀ R)` is `(#ι).lift`. -/ theorem rank_finsupp_self (ι : Type w) : Module.rank R (ι →₀ R) = Cardinal.lift.{u} #ι := by simp /-- If `R` and `ι` lie in the same universe, the rank of `(ι →₀ R)` is `# ι`. -/ theorem rank_finsupp_self' {ι : Type u} : Module.rank R (ι →₀ R) = #ι := by simp /-- The rank of the direct sum is the sum of the ranks. -/ @[simp] theorem rank_directSum {ι : Type v} (M : ι → Type w) [∀ i : ι, AddCommMonoid (M i)] [∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] : Module.rank R (⨁ i, M i) = Cardinal.sum fun i => Module.rank R (M i) := by let B i := chooseBasis R (M i) let b : Basis _ R (⨁ i, M i) := DFinsupp.basis fun i => B i simp [← b.mk_eq_rank'', fun i => (B i).mk_eq_rank''] /-- If `m` and `n` are finite, the rank of `m × n` matrices over a module `M` is `(#m).lift * (#n).lift * rank R M`. -/ @[simp] theorem rank_matrix_module (m : Type w) (n : Type w') [Finite m] [Finite n] : Module.rank R (Matrix m n M) = lift.{max v w'} #m * lift.{max v w} #n * lift.{max w w'} (Module.rank R M) := by cases nonempty_fintype m cases nonempty_fintype n obtain ⟨I, b⟩ := Module.Free.exists_basis (R := R) (M := M) rw [← (b.matrix m n).mk_eq_rank''] simp only [mk_prod, lift_mul, lift_lift, ← mul_assoc, b.mk_eq_rank''] /-- If `m` and `n` are finite and lie in the same universe, the rank of `m × n` matrices over a module `M` is `(#m * #n).lift * rank R M`. -/ @[simp high] theorem rank_matrix_module' (m n : Type w) [Finite m] [Finite n] : Module.rank R (Matrix m n M) = lift.{max v} (#m * #n) * lift.{w} (Module.rank R M) := by rw [rank_matrix_module, lift_mul, lift_umax.{w, v}] /-- If `m` and `n` are finite, the rank of `m × n` matrices is `(#m).lift * (#n).lift`. -/ theorem rank_matrix (m : Type v) (n : Type w) [Finite m] [Finite n] : Module.rank R (Matrix m n R) =
Cardinal.lift.{max v w u, v} #m * Cardinal.lift.{max v w u, w} #n := by rw [rank_matrix_module, rank_self, lift_one, mul_one, ← lift_lift.{v, max u w}, lift_id,
Mathlib/LinearAlgebra/Dimension/Constructions.lean
230
231
/- Copyright (c) 2018 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Markus Himmel -/ import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Limits.HasLimits /-! # Equalizers and coequalizers This file defines (co)equalizers as special cases of (co)limits. An equalizer is the categorical generalization of the subobject {a ∈ A | f(a) = g(a)} known from abelian groups or modules. It is a limit cone over the diagram formed by `f` and `g`. A coequalizer is the dual concept. ## Main definitions * `WalkingParallelPair` is the indexing category used for (co)equalizer_diagrams * `parallelPair` is a functor from `WalkingParallelPair` to our category `C`. * a `fork` is a cone over a parallel pair. * there is really only one interesting morphism in a fork: the arrow from the vertex of the fork to the domain of f and g. It is called `fork.ι`. * an `equalizer` is now just a `limit (parallelPair f g)` Each of these has a dual. ## Main statements * `equalizer.ι_mono` states that every equalizer map is a monomorphism * `isIso_limit_cone_parallelPair_of_self` states that the identity on the domain of `f` is an equalizer of `f` and `f`. ## Implementation notes As with the other special shapes in the limits library, all the definitions here are given as `abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about general limits can be used. ## References * [F. Borceux, *Handbook of Categorical Algebra 1*][borceux-vol1] -/ section open CategoryTheory Opposite namespace CategoryTheory.Limits universe v v₂ u u₂ /-- The type of objects for the diagram indexing a (co)equalizer. -/ inductive WalkingParallelPair : Type | zero | one deriving DecidableEq, Inhabited open WalkingParallelPair -- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about. set_option genSizeOfSpec false in /-- The type family of morphisms for the diagram indexing a (co)equalizer. -/ inductive WalkingParallelPairHom : WalkingParallelPair → WalkingParallelPair → Type | left : WalkingParallelPairHom zero one | right : WalkingParallelPairHom zero one | id (X : WalkingParallelPair) : WalkingParallelPairHom X X deriving DecidableEq /-- Satisfying the inhabited linter -/ instance : Inhabited (WalkingParallelPairHom zero one) where default := WalkingParallelPairHom.left open WalkingParallelPairHom /-- Composition of morphisms in the indexing diagram for (co)equalizers. -/ def WalkingParallelPairHom.comp : -- Porting note: changed X Y Z to implicit to match comp fields in precategory ∀ {X Y Z : WalkingParallelPair} (_ : WalkingParallelPairHom X Y) (_ : WalkingParallelPairHom Y Z), WalkingParallelPairHom X Z | _, _, _, id _, h => h | _, _, _, left, id one => left | _, _, _, right, id one => right -- Porting note: adding these since they are simple and aesop couldn't directly prove them theorem WalkingParallelPairHom.id_comp {X Y : WalkingParallelPair} (g : WalkingParallelPairHom X Y) : comp (id X) g = g := rfl theorem WalkingParallelPairHom.comp_id {X Y : WalkingParallelPair} (f : WalkingParallelPairHom X Y) : comp f (id Y) = f := by cases f <;> rfl theorem WalkingParallelPairHom.assoc {X Y Z W : WalkingParallelPair} (f : WalkingParallelPairHom X Y) (g : WalkingParallelPairHom Y Z) (h : WalkingParallelPairHom Z W) : comp (comp f g) h = comp f (comp g h) := by cases f <;> cases g <;> cases h <;> rfl instance walkingParallelPairHomCategory : SmallCategory WalkingParallelPair where Hom := WalkingParallelPairHom id := id comp := comp comp_id := comp_id id_comp := id_comp assoc := assoc @[simp] theorem walkingParallelPairHom_id (X : WalkingParallelPair) : WalkingParallelPairHom.id X = 𝟙 X := rfl /-- The functor `WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ` sending left to left and right to right. -/ def walkingParallelPairOp : WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ where obj x := op <| by cases x; exacts [one, zero] map f := by cases f <;> apply Quiver.Hom.op exacts [left, right, WalkingParallelPairHom.id _] map_comp := by rintro _ _ _ (_|_|_) g <;> cases g <;> rfl @[simp] theorem walkingParallelPairOp_zero : walkingParallelPairOp.obj zero = op one := rfl @[simp] theorem walkingParallelPairOp_one : walkingParallelPairOp.obj one = op zero := rfl @[simp] theorem walkingParallelPairOp_left : walkingParallelPairOp.map left = @Quiver.Hom.op _ _ zero one left := rfl @[simp] theorem walkingParallelPairOp_right : walkingParallelPairOp.map right = @Quiver.Hom.op _ _ zero one right := rfl /-- The equivalence `WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ` sending left to left and right to right. -/ @[simps functor inverse] def walkingParallelPairOpEquiv : WalkingParallelPair ≌ WalkingParallelPairᵒᵖ where functor := walkingParallelPairOp inverse := walkingParallelPairOp.leftOp unitIso := NatIso.ofComponents (fun j => eqToIso (by cases j <;> rfl)) (by rintro _ _ (_ | _ | _) <;> simp) counitIso := NatIso.ofComponents (fun j => eqToIso (by induction' j with X cases X <;> rfl)) (fun {i} {j} f => by induction' i with i induction' j with j let g := f.unop have : f = g.op := rfl rw [this] cases i <;> cases j <;> cases g <;> rfl) functor_unitIso_comp := fun j => by cases j <;> rfl @[simp] theorem walkingParallelPairOpEquiv_unitIso_zero : walkingParallelPairOpEquiv.unitIso.app zero = Iso.refl zero := rfl @[simp] theorem walkingParallelPairOpEquiv_unitIso_one : walkingParallelPairOpEquiv.unitIso.app one = Iso.refl one := rfl @[simp] theorem walkingParallelPairOpEquiv_counitIso_zero : walkingParallelPairOpEquiv.counitIso.app (op zero) = Iso.refl (op zero) := rfl @[simp] theorem walkingParallelPairOpEquiv_counitIso_one : walkingParallelPairOpEquiv.counitIso.app (op one) = Iso.refl (op one) := rfl variable {C : Type u} [Category.{v} C] variable {X Y : C} /-- `parallelPair f g` is the diagram in `C` consisting of the two morphisms `f` and `g` with common domain and codomain. -/ def parallelPair (f g : X ⟶ Y) : WalkingParallelPair ⥤ C where obj x := match x with | zero => X | one => Y map h := match h with | WalkingParallelPairHom.id _ => 𝟙 _ | left => f | right => g -- `sorry` can cope with this, but it's too slow: map_comp := by rintro _ _ _ ⟨⟩ g <;> cases g <;> {dsimp; simp} @[simp] theorem parallelPair_obj_zero (f g : X ⟶ Y) : (parallelPair f g).obj zero = X := rfl @[simp] theorem parallelPair_obj_one (f g : X ⟶ Y) : (parallelPair f g).obj one = Y := rfl @[simp] theorem parallelPair_map_left (f g : X ⟶ Y) : (parallelPair f g).map left = f := rfl @[simp] theorem parallelPair_map_right (f g : X ⟶ Y) : (parallelPair f g).map right = g := rfl @[simp] theorem parallelPair_functor_obj {F : WalkingParallelPair ⥤ C} (j : WalkingParallelPair) : (parallelPair (F.map left) (F.map right)).obj j = F.obj j := by cases j <;> rfl /-- Every functor indexing a (co)equalizer is naturally isomorphic (actually, equal) to a `parallelPair` -/ @[simps!] def diagramIsoParallelPair (F : WalkingParallelPair ⥤ C) : F ≅ parallelPair (F.map left) (F.map right) := NatIso.ofComponents (fun j => eqToIso <| by cases j <;> rfl) (by rintro _ _ (_|_|_) <;> simp) /-- Construct a morphism between parallel pairs. -/ def parallelPairHom {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : parallelPair f g ⟶ parallelPair f' g' where app j := match j with | zero => p | one => q naturality := by rintro _ _ ⟨⟩ <;> {dsimp; simp [wf,wg]} @[simp] theorem parallelPairHom_app_zero {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : (parallelPairHom f g f' g' p q wf wg).app zero = p := rfl @[simp] theorem parallelPairHom_app_one {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : (parallelPairHom f g f' g' p q wf wg).app one = q := rfl /-- Construct a natural isomorphism between functors out of the walking parallel pair from its components. -/ @[simps!] def parallelPair.ext {F G : WalkingParallelPair ⥤ C} (zero : F.obj zero ≅ G.obj zero) (one : F.obj one ≅ G.obj one) (left : F.map left ≫ one.hom = zero.hom ≫ G.map left) (right : F.map right ≫ one.hom = zero.hom ≫ G.map right) : F ≅ G := NatIso.ofComponents (by rintro ⟨j⟩ exacts [zero, one]) (by rintro _ _ ⟨_⟩ <;> simp [left, right]) /-- Construct a natural isomorphism between `parallelPair f g` and `parallelPair f' g'` given equalities `f = f'` and `g = g'`. -/ @[simps!] def parallelPair.eqOfHomEq {f g f' g' : X ⟶ Y} (hf : f = f') (hg : g = g') : parallelPair f g ≅ parallelPair f' g' := parallelPair.ext (Iso.refl _) (Iso.refl _) (by simp [hf]) (by simp [hg]) /-- A fork on `f` and `g` is just a `Cone (parallelPair f g)`. -/ abbrev Fork (f g : X ⟶ Y) := Cone (parallelPair f g) /-- A cofork on `f` and `g` is just a `Cocone (parallelPair f g)`. -/ abbrev Cofork (f g : X ⟶ Y) := Cocone (parallelPair f g) variable {f g : X ⟶ Y} /-- A fork `t` on the parallel pair `f g : X ⟶ Y` consists of two morphisms `t.π.app zero : t.pt ⟶ X` and `t.π.app one : t.pt ⟶ Y`. Of these, only the first one is interesting, and we give it the shorter name `Fork.ι t`. -/ def Fork.ι (t : Fork f g) := t.π.app zero @[simp] theorem Fork.app_zero_eq_ι (t : Fork f g) : t.π.app zero = t.ι := rfl /-- A cofork `t` on the parallelPair `f g : X ⟶ Y` consists of two morphisms `t.ι.app zero : X ⟶ t.pt` and `t.ι.app one : Y ⟶ t.pt`. Of these, only the second one is interesting, and we give it the shorter name `Cofork.π t`. -/ def Cofork.π (t : Cofork f g) := t.ι.app one @[simp] theorem Cofork.app_one_eq_π (t : Cofork f g) : t.ι.app one = t.π := rfl @[simp] theorem Fork.app_one_eq_ι_comp_left (s : Fork f g) : s.π.app one = s.ι ≫ f := by rw [← s.app_zero_eq_ι, ← s.w left, parallelPair_map_left] @[reassoc] theorem Fork.app_one_eq_ι_comp_right (s : Fork f g) : s.π.app one = s.ι ≫ g := by rw [← s.app_zero_eq_ι, ← s.w right, parallelPair_map_right] @[simp] theorem Cofork.app_zero_eq_comp_π_left (s : Cofork f g) : s.ι.app zero = f ≫ s.π := by rw [← s.app_one_eq_π, ← s.w left, parallelPair_map_left] @[reassoc] theorem Cofork.app_zero_eq_comp_π_right (s : Cofork f g) : s.ι.app zero = g ≫ s.π := by rw [← s.app_one_eq_π, ← s.w right, parallelPair_map_right] /-- A fork on `f g : X ⟶ Y` is determined by the morphism `ι : P ⟶ X` satisfying `ι ≫ f = ι ≫ g`. -/ @[simps] def Fork.ofι {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) : Fork f g where pt := P π := { app := fun X => by cases X · exact ι · exact ι ≫ f naturality := fun {X} {Y} f => by cases X <;> cases Y <;> cases f <;> dsimp <;> simp; assumption } /-- A cofork on `f g : X ⟶ Y` is determined by the morphism `π : Y ⟶ P` satisfying `f ≫ π = g ≫ π`. -/ @[simps] def Cofork.ofπ {P : C} (π : Y ⟶ P) (w : f ≫ π = g ≫ π) : Cofork f g where pt := P ι := { app := fun X => WalkingParallelPair.casesOn X (f ≫ π) π naturality := fun i j f => by cases f <;> dsimp <;> simp [w] } -- See note [dsimp, simp] @[simp] theorem Fork.ι_ofι {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) : (Fork.ofι ι w).ι = ι := rfl @[simp] theorem Cofork.π_ofπ {P : C} (π : Y ⟶ P) (w : f ≫ π = g ≫ π) : (Cofork.ofπ π w).π = π := rfl @[reassoc (attr := simp)] theorem Fork.condition (t : Fork f g) : t.ι ≫ f = t.ι ≫ g := by rw [← t.app_one_eq_ι_comp_left, ← t.app_one_eq_ι_comp_right] @[reassoc (attr := simp)] theorem Cofork.condition (t : Cofork f g) : f ≫ t.π = g ≫ t.π := by rw [← t.app_zero_eq_comp_π_left, ← t.app_zero_eq_comp_π_right] /-- To check whether two maps are equalized by both maps of a fork, it suffices to check it for the first map -/ theorem Fork.equalizer_ext (s : Fork f g) {W : C} {k l : W ⟶ s.pt} (h : k ≫ s.ι = l ≫ s.ι) : ∀ j : WalkingParallelPair, k ≫ s.π.app j = l ≫ s.π.app j | zero => h | one => by have : k ≫ ι s ≫ f = l ≫ ι s ≫ f := by simp only [← Category.assoc]; exact congrArg (· ≫ f) h rw [s.app_one_eq_ι_comp_left, this] /-- To check whether two maps are coequalized by both maps of a cofork, it suffices to check it for the second map -/ theorem Cofork.coequalizer_ext (s : Cofork f g) {W : C} {k l : s.pt ⟶ W} (h : Cofork.π s ≫ k = Cofork.π s ≫ l) : ∀ j : WalkingParallelPair, s.ι.app j ≫ k = s.ι.app j ≫ l | zero => by simp only [s.app_zero_eq_comp_π_left, Category.assoc, h] | one => h theorem Fork.IsLimit.hom_ext {s : Fork f g} (hs : IsLimit s) {W : C} {k l : W ⟶ s.pt} (h : k ≫ Fork.ι s = l ≫ Fork.ι s) : k = l := hs.hom_ext <| Fork.equalizer_ext _ h theorem Cofork.IsColimit.hom_ext {s : Cofork f g} (hs : IsColimit s) {W : C} {k l : s.pt ⟶ W} (h : Cofork.π s ≫ k = Cofork.π s ≫ l) : k = l := hs.hom_ext <| Cofork.coequalizer_ext _ h @[reassoc (attr := simp)] theorem Fork.IsLimit.lift_ι {s t : Fork f g} (hs : IsLimit s) : hs.lift t ≫ s.ι = t.ι := hs.fac _ _ @[reassoc (attr := simp)] theorem Cofork.IsColimit.π_desc {s t : Cofork f g} (hs : IsColimit s) : s.π ≫ hs.desc t = t.π := hs.fac _ _ -- Porting note: `Fork.IsLimit.lift` was added in order to ease the port /-- If `s` is a limit fork over `f` and `g`, then a morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` induces a morphism `l : W ⟶ s.pt` such that `l ≫ fork.ι s = k`. -/ def Fork.IsLimit.lift {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : W ⟶ s.pt := hs.lift (Fork.ofι _ h) @[reassoc (attr := simp)] lemma Fork.IsLimit.lift_ι' {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : Fork.IsLimit.lift hs k h ≫ Fork.ι s = k := hs.fac _ _ /-- If `s` is a limit fork over `f` and `g`, then a morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` induces a morphism `l : W ⟶ s.pt` such that `l ≫ fork.ι s = k`. -/
def Fork.IsLimit.lift' {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : { l : W ⟶ s.pt // l ≫ Fork.ι s = k } :=
Mathlib/CategoryTheory/Limits/Shapes/Equalizers.lean
392
393
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.Cover.Open import Mathlib.AlgebraicGeometry.GammaSpecAdjunction import Mathlib.AlgebraicGeometry.Restrict import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.RingTheory.Localization.InvSubmonoid import Mathlib.RingTheory.RingHom.Surjective import Mathlib.Topology.Sheaves.CommRingCat /-! # Affine schemes We define the category of `AffineScheme`s as the essential image of `Spec`. We also define predicates about affine schemes and affine open sets. ## Main definitions * `AlgebraicGeometry.AffineScheme`: The category of affine schemes. * `AlgebraicGeometry.IsAffine`: A scheme is affine if the canonical map `X ⟶ Spec Γ(X)` is an isomorphism. * `AlgebraicGeometry.Scheme.isoSpec`: The canonical isomorphism `X ≅ Spec Γ(X)` for an affine scheme. * `AlgebraicGeometry.AffineScheme.equivCommRingCat`: The equivalence of categories `AffineScheme ≌ CommRingᵒᵖ` given by `AffineScheme.Spec : CommRingᵒᵖ ⥤ AffineScheme` and `AffineScheme.Γ : AffineSchemeᵒᵖ ⥤ CommRingCat`. * `AlgebraicGeometry.IsAffineOpen`: An open subset of a scheme is affine if the open subscheme is affine. * `AlgebraicGeometry.IsAffineOpen.fromSpec`: The immersion `Spec 𝒪ₓ(U) ⟶ X` for an affine `U`. -/ -- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737 noncomputable section open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace universe u namespace AlgebraicGeometry open Spec (structureSheaf) /-- The category of affine schemes -/ def AffineScheme := Scheme.Spec.EssImageSubcategory deriving Category /-- A Scheme is affine if the canonical map `X ⟶ Spec Γ(X)` is an isomorphism. -/ class IsAffine (X : Scheme) : Prop where affine : IsIso X.toSpecΓ attribute [instance] IsAffine.affine instance (X : Scheme.{u}) [IsAffine X] : IsIso (ΓSpec.adjunction.unit.app X) := @IsAffine.affine X _ /-- The canonical isomorphism `X ≅ Spec Γ(X)` for an affine scheme. -/ @[simps! -isSimp hom] def Scheme.isoSpec (X : Scheme) [IsAffine X] : X ≅ Spec Γ(X, ⊤) := asIso X.toSpecΓ @[reassoc] theorem Scheme.isoSpec_hom_naturality {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) : X.isoSpec.hom ≫ Spec.map (f.appTop) = f ≫ Y.isoSpec.hom := by simp only [isoSpec, asIso_hom, Scheme.toSpecΓ_naturality] @[reassoc] theorem Scheme.isoSpec_inv_naturality {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) : Spec.map (f.appTop) ≫ Y.isoSpec.inv = X.isoSpec.inv ≫ f := by rw [Iso.eq_inv_comp, isoSpec, asIso_hom, ← Scheme.toSpecΓ_naturality_assoc, isoSpec, asIso_inv, IsIso.hom_inv_id, Category.comp_id] @[reassoc (attr := simp)] lemma Scheme.toSpecΓ_isoSpec_inv (X : Scheme.{u}) [IsAffine X] : X.toSpecΓ ≫ X.isoSpec.inv = 𝟙 _ := X.isoSpec.hom_inv_id @[reassoc (attr := simp)] lemma Scheme.isoSpec_inv_toSpecΓ (X : Scheme.{u}) [IsAffine X] : X.isoSpec.inv ≫ X.toSpecΓ = 𝟙 _ := X.isoSpec.inv_hom_id /-- Construct an affine scheme from a scheme and the information that it is affine. Also see `AffineScheme.of` for a typeclass version. -/ @[simps] def AffineScheme.mk (X : Scheme) (_ : IsAffine X) : AffineScheme := ⟨X, ΓSpec.adjunction.mem_essImage_of_unit_isIso _⟩ /-- Construct an affine scheme from a scheme. Also see `AffineScheme.mk` for a non-typeclass version. -/ def AffineScheme.of (X : Scheme) [h : IsAffine X] : AffineScheme := AffineScheme.mk X h /-- Type check a morphism of schemes as a morphism in `AffineScheme`. -/ def AffineScheme.ofHom {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) : AffineScheme.of X ⟶ AffineScheme.of Y := f @[simp] theorem essImage_Spec {X : Scheme} : Scheme.Spec.essImage X ↔ IsAffine X := ⟨fun h => ⟨Functor.essImage.unit_isIso h⟩, fun _ => ΓSpec.adjunction.mem_essImage_of_unit_isIso _⟩ @[deprecated (since := "2025-04-08")] alias mem_Spec_essImage := essImage_Spec instance isAffine_affineScheme (X : AffineScheme.{u}) : IsAffine X.obj := ⟨Functor.essImage.unit_isIso X.property⟩ instance (R : CommRingCatᵒᵖ) : IsAffine (Scheme.Spec.obj R) := AlgebraicGeometry.isAffine_affineScheme ⟨_, Scheme.Spec.obj_mem_essImage R⟩ instance isAffine_Spec (R : CommRingCat) : IsAffine (Spec R) := AlgebraicGeometry.isAffine_affineScheme ⟨_, Scheme.Spec.obj_mem_essImage (op R)⟩ theorem IsAffine.of_isIso {X Y : Scheme} (f : X ⟶ Y) [IsIso f] [h : IsAffine Y] : IsAffine X := by rw [← essImage_Spec] at h ⊢; exact Functor.essImage.ofIso (asIso f).symm h @[deprecated (since := "2025-03-31")] alias isAffine_of_isIso := IsAffine.of_isIso /-- If `f : X ⟶ Y` is a morphism between affine schemes, the corresponding arrow is isomorphic to the arrow of the morphism on prime spectra induced by the map on global sections. -/ noncomputable def arrowIsoSpecΓOfIsAffine {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) : Arrow.mk f ≅ Arrow.mk (Spec.map f.appTop) := Arrow.isoMk X.isoSpec Y.isoSpec (ΓSpec.adjunction.unit_naturality _) /-- If `f : A ⟶ B` is a ring homomorphism, the corresponding arrow is isomorphic to the arrow of the morphism induced on global sections by the map on prime spectra. -/ def arrowIsoΓSpecOfIsAffine {A B : CommRingCat} (f : A ⟶ B) : Arrow.mk f ≅ Arrow.mk ((Spec.map f).appTop) := Arrow.isoMk (Scheme.ΓSpecIso _).symm (Scheme.ΓSpecIso _).symm (Scheme.ΓSpecIso_inv_naturality f).symm theorem Scheme.isoSpec_Spec (R : CommRingCat.{u}) : (Spec R).isoSpec = Scheme.Spec.mapIso (Scheme.ΓSpecIso R).op := Iso.ext (SpecMap_ΓSpecIso_hom R).symm @[simp] theorem Scheme.isoSpec_Spec_hom (R : CommRingCat.{u}) : (Spec R).isoSpec.hom = Spec.map (Scheme.ΓSpecIso R).hom := (SpecMap_ΓSpecIso_hom R).symm @[simp] theorem Scheme.isoSpec_Spec_inv (R : CommRingCat.{u}) : (Spec R).isoSpec.inv = Spec.map (Scheme.ΓSpecIso R).inv := congr($(isoSpec_Spec R).inv) lemma ext_of_isAffine {X Y : Scheme} [IsAffine Y] {f g : X ⟶ Y} (e : f.appTop = g.appTop) : f = g := by rw [← cancel_mono Y.toSpecΓ, Scheme.toSpecΓ_naturality, Scheme.toSpecΓ_naturality, e] namespace AffineScheme /-- The `Spec` functor into the category of affine schemes. -/ def Spec : CommRingCatᵒᵖ ⥤ AffineScheme := Scheme.Spec.toEssImage /-! We copy over instances from `Scheme.Spec.toEssImage`. -/ instance Spec_full : Spec.Full := Functor.Full.toEssImage _ instance Spec_faithful : Spec.Faithful := Functor.Faithful.toEssImage _ instance Spec_essSurj : Spec.EssSurj := Functor.EssSurj.toEssImage (F := _) /-- The forgetful functor `AffineScheme ⥤ Scheme`. -/ @[simps!] def forgetToScheme : AffineScheme ⥤ Scheme := Scheme.Spec.essImage.ι /-! We copy over instances from `Scheme.Spec.essImageInclusion`. -/ instance forgetToScheme_full : forgetToScheme.Full := inferInstanceAs Scheme.Spec.essImage.ι.Full instance forgetToScheme_faithful : forgetToScheme.Faithful := inferInstanceAs Scheme.Spec.essImage.ι.Faithful /-- The global section functor of an affine scheme. -/ def Γ : AffineSchemeᵒᵖ ⥤ CommRingCat := forgetToScheme.op ⋙ Scheme.Γ /-- The category of affine schemes is equivalent to the category of commutative rings. -/ def equivCommRingCat : AffineScheme ≌ CommRingCatᵒᵖ := equivEssImageOfReflective.symm instance : Γ.{u}.rightOp.IsEquivalence := equivCommRingCat.isEquivalence_functor instance : Γ.{u}.rightOp.op.IsEquivalence := equivCommRingCat.op.isEquivalence_functor instance ΓIsEquiv : Γ.{u}.IsEquivalence := inferInstanceAs (Γ.{u}.rightOp.op ⋙ (opOpEquivalence _).functor).IsEquivalence instance hasColimits : HasColimits AffineScheme.{u} := haveI := Adjunction.has_limits_of_equivalence.{u} Γ.{u} Adjunction.has_colimits_of_equivalence.{u} (opOpEquivalence AffineScheme.{u}).inverse instance hasLimits : HasLimits AffineScheme.{u} := by haveI := Adjunction.has_colimits_of_equivalence Γ.{u} haveI : HasLimits AffineScheme.{u}ᵒᵖᵒᵖ := Limits.hasLimits_op_of_hasColimits exact Adjunction.has_limits_of_equivalence (opOpEquivalence AffineScheme.{u}).inverse noncomputable instance Γ_preservesLimits : PreservesLimits Γ.{u}.rightOp := inferInstance noncomputable instance forgetToScheme_preservesLimits : PreservesLimits forgetToScheme := by apply (config := { allowSynthFailures := true }) @preservesLimits_of_natIso _ _ _ _ _ _ (isoWhiskerRight equivCommRingCat.unitIso forgetToScheme).symm change PreservesLimits (equivCommRingCat.functor ⋙ Scheme.Spec) infer_instance end AffineScheme /-- An open subset of a scheme is affine if the open subscheme is affine. -/ def IsAffineOpen {X : Scheme} (U : X.Opens) : Prop := IsAffine U /-- The set of affine opens as a subset of `opens X`. -/ def Scheme.affineOpens (X : Scheme) : Set X.Opens := {U : X.Opens | IsAffineOpen U} instance {Y : Scheme.{u}} (U : Y.affineOpens) : IsAffine U := U.property theorem isAffineOpen_opensRange {X Y : Scheme} [IsAffine X] (f : X ⟶ Y) [H : IsOpenImmersion f] : IsAffineOpen (Scheme.Hom.opensRange f) := by refine .of_isIso (IsOpenImmersion.isoOfRangeEq f (Y.ofRestrict _) ?_).inv exact Subtype.range_val.symm theorem isAffineOpen_top (X : Scheme) [IsAffine X] : IsAffineOpen (⊤ : X.Opens) := by convert isAffineOpen_opensRange (𝟙 X) ext1 exact Set.range_id.symm instance Scheme.isAffine_affineCover (X : Scheme) (i : X.affineCover.J) : IsAffine (X.affineCover.obj i) := isAffine_Spec _ instance Scheme.isAffine_affineBasisCover (X : Scheme) (i : X.affineBasisCover.J) : IsAffine (X.affineBasisCover.obj i) := isAffine_Spec _ instance Scheme.isAffine_affineOpenCover (X : Scheme) (𝒰 : X.AffineOpenCover) (i : 𝒰.J) : IsAffine (𝒰.openCover.obj i) := inferInstanceAs (IsAffine (Spec (𝒰.obj i))) instance {X} [IsAffine X] (i) : IsAffine ((Scheme.coverOfIsIso (P := @IsOpenImmersion) (𝟙 X)).obj i) := by dsimp; infer_instance theorem isBasis_affine_open (X : Scheme) : Opens.IsBasis X.affineOpens := by rw [Opens.isBasis_iff_nbhd] rintro U x (hU : x ∈ (U : Set X)) obtain ⟨S, hS, hxS, hSU⟩ := X.affineBasisCover_is_basis.exists_subset_of_mem_open hU U.isOpen refine ⟨⟨S, X.affineBasisCover_is_basis.isOpen hS⟩, ?_, hxS, hSU⟩ rcases hS with ⟨i, rfl⟩ exact isAffineOpen_opensRange _ theorem iSup_affineOpens_eq_top (X : Scheme) : ⨆ i : X.affineOpens, (i : X.Opens) = ⊤ := by apply Opens.ext rw [Opens.coe_iSup] apply IsTopologicalBasis.sUnion_eq rw [← Set.image_eq_range] exact isBasis_affine_open X theorem Scheme.map_PrimeSpectrum_basicOpen_of_affine (X : Scheme) [IsAffine X] (f : Γ(X, ⊤)) : X.isoSpec.hom ⁻¹ᵁ PrimeSpectrum.basicOpen f = X.basicOpen f := Scheme.toSpecΓ_preimage_basicOpen _ _ theorem isBasis_basicOpen (X : Scheme) [IsAffine X] : Opens.IsBasis (Set.range (X.basicOpen : Γ(X, ⊤) → X.Opens)) := by delta Opens.IsBasis convert PrimeSpectrum.isBasis_basic_opens.isInducing (TopCat.homeoOfIso (Scheme.forgetToTop.mapIso X.isoSpec)).isInducing using 1 ext simp only [Set.mem_image, exists_exists_eq_and] constructor · rintro ⟨_, ⟨x, rfl⟩, rfl⟩ refine ⟨_, ⟨_, ⟨x, rfl⟩, rfl⟩, ?_⟩ exact congr_arg Opens.carrier (Scheme.toSpecΓ_preimage_basicOpen _ _) · rintro ⟨_, ⟨_, ⟨x, rfl⟩, rfl⟩, rfl⟩ refine ⟨_, ⟨x, rfl⟩, ?_⟩ exact congr_arg Opens.carrier (Scheme.toSpecΓ_preimage_basicOpen _ _).symm /-- The canonical map `U ⟶ Spec Γ(X, U)` for an open `U ⊆ X`. -/ noncomputable def Scheme.Opens.toSpecΓ {X : Scheme.{u}} (U : X.Opens) : U.toScheme ⟶ Spec Γ(X, U) := U.toScheme.toSpecΓ ≫ Spec.map U.topIso.inv @[reassoc (attr := simp)] lemma Scheme.Opens.toSpecΓ_SpecMap_map {X : Scheme} (U V : X.Opens) (h : U ≤ V) : U.toSpecΓ ≫ Spec.map (X.presheaf.map (homOfLE h).op) = X.homOfLE h ≫ V.toSpecΓ := by delta Scheme.Opens.toSpecΓ simp [← Spec.map_comp, ← X.presheaf.map_comp, toSpecΓ_naturality_assoc] @[simp] lemma Scheme.Opens.toSpecΓ_top {X : Scheme} : (⊤ : X.Opens).toSpecΓ = (⊤ : X.Opens).ι ≫ X.toSpecΓ := by simp [Scheme.Opens.toSpecΓ, toSpecΓ_naturality]; rfl @[reassoc] lemma Scheme.Opens.toSpecΓ_appTop {X : Scheme.{u}} (U : X.Opens) : U.toSpecΓ.appTop = (Scheme.ΓSpecIso Γ(X, U)).hom ≫ U.topIso.inv := by simp [Scheme.Opens.toSpecΓ] namespace IsAffineOpen variable {X Y : Scheme.{u}} {U : X.Opens} (hU : IsAffineOpen U) (f : Γ(X, U)) attribute [-simp] eqToHom_op in /-- The isomorphism `U ≅ Spec Γ(X, U)` for an affine `U`. -/ @[simps! -isSimp inv] def isoSpec : ↑U ≅ Spec Γ(X, U) := haveI : IsAffine U := hU U.toScheme.isoSpec ≪≫ Scheme.Spec.mapIso U.topIso.symm.op lemma isoSpec_hom : hU.isoSpec.hom = U.toSpecΓ := rfl @[reassoc (attr := simp)] lemma toSpecΓ_isoSpec_inv : U.toSpecΓ ≫ hU.isoSpec.inv = 𝟙 _ := hU.isoSpec.hom_inv_id @[reassoc (attr := simp)] lemma isoSpec_inv_toSpecΓ : hU.isoSpec.inv ≫ U.toSpecΓ = 𝟙 _ := hU.isoSpec.inv_hom_id open IsLocalRing in lemma isoSpec_hom_base_apply (x : U) : hU.isoSpec.hom.base x = (Spec.map (X.presheaf.germ U x x.2)).base (closedPoint _) := by dsimp [IsAffineOpen.isoSpec_hom, Scheme.isoSpec_hom, Scheme.toSpecΓ_base, Scheme.Opens.toSpecΓ] rw [← Scheme.comp_base_apply, ← Spec.map_comp, (Iso.eq_comp_inv _).mpr (Scheme.Opens.germ_stalkIso_hom U (V := ⊤) x trivial), X.presheaf.germ_res_assoc, Spec.map_comp, Scheme.comp_base_apply] congr 1 exact IsLocalRing.comap_closedPoint (U.stalkIso x).inv.hom lemma isoSpec_inv_appTop : hU.isoSpec.inv.appTop = U.topIso.hom ≫ (Scheme.ΓSpecIso Γ(X, U)).inv := by simp_rw [Scheme.Opens.toScheme_presheaf_obj, isoSpec_inv, Scheme.isoSpec, asIso_inv, Scheme.comp_app, Scheme.Opens.topIso_hom, Scheme.ΓSpecIso_inv_naturality, Scheme.inv_appTop, -- `check_compositions` reports defeq problems starting after this step. IsIso.inv_comp_eq] rw [Scheme.toSpecΓ_appTop] -- We need `erw` here because the goal has -- `Scheme.ΓSpecIso Γ(↑U, ⊤)).hom ≫ Scheme.ΓSpecIso Γ(X, U.ι ''ᵁ ⊤)).inv` -- and `Γ(X, U.ι ''ᵁ ⊤)` is non-reducibly defeq to `Γ(↑U, ⊤)`. erw [Iso.hom_inv_id_assoc] simp only [Opens.map_top] lemma isoSpec_hom_appTop : hU.isoSpec.hom.appTop = (Scheme.ΓSpecIso Γ(X, U)).hom ≫ U.topIso.inv := by have := congr(inv $hU.isoSpec_inv_appTop) rw [IsIso.inv_comp, IsIso.Iso.inv_inv, IsIso.Iso.inv_hom] at this have := (Scheme.Γ.map_inv hU.isoSpec.inv.op).trans this rwa [← op_inv, IsIso.Iso.inv_inv] at this @[deprecated (since := "2024-11-16")] alias isoSpec_inv_app_top := isoSpec_inv_appTop @[deprecated (since := "2024-11-16")] alias isoSpec_hom_app_top := isoSpec_hom_appTop /-- The open immersion `Spec Γ(X, U) ⟶ X` for an affine `U`. -/ def fromSpec : Spec Γ(X, U) ⟶ X := haveI : IsAffine U := hU hU.isoSpec.inv ≫ U.ι instance isOpenImmersion_fromSpec : IsOpenImmersion hU.fromSpec := by delta fromSpec infer_instance @[reassoc (attr := simp)] lemma isoSpec_inv_ι : hU.isoSpec.inv ≫ U.ι = hU.fromSpec := rfl
@[reassoc (attr := simp)] lemma toSpecΓ_fromSpec : U.toSpecΓ ≫ hU.fromSpec = U.ι := toSpecΓ_isoSpec_inv_assoc _ _ @[simp]
Mathlib/AlgebraicGeometry/AffineScheme.lean
377
380
/- 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] theorem mapDomain_injective {f : α → β} (hf : Function.Injective f) : Function.Injective (mapDomain f : (α →₀ M) → β →₀ M) := by intro v₁ v₂ eq ext a have : mapDomain f v₁ (f a) = mapDomain f v₂ (f a) := by rw [eq] rwa [mapDomain_apply hf, mapDomain_apply hf] at this /-- When `f` is an embedding we have an embedding `(α →₀ ℕ) ↪ (β →₀ ℕ)` given by `mapDomain`. -/ @[simps] def mapDomainEmbedding {α β : Type*} (f : α ↪ β) : (α →₀ ℕ) ↪ β →₀ ℕ := ⟨Finsupp.mapDomain f, Finsupp.mapDomain_injective f.injective⟩ theorem mapDomain.addMonoidHom_comp_mapRange [AddCommMonoid N] (f : α → β) (g : M →+ N) : (mapDomain.addMonoidHom f).comp (mapRange.addMonoidHom g) = (mapRange.addMonoidHom g).comp (mapDomain.addMonoidHom f) := by ext simp only [AddMonoidHom.coe_comp, Finsupp.mapRange_single, Finsupp.mapDomain.addMonoidHom_apply, Finsupp.singleAddHom_apply, eq_self_iff_true, Function.comp_apply, Finsupp.mapDomain_single, Finsupp.mapRange.addMonoidHom_apply] /-- When `g` preserves addition, `mapRange` and `mapDomain` commute. -/ theorem mapDomain_mapRange [AddCommMonoid N] (f : α → β) (v : α →₀ M) (g : M → N) (h0 : g 0 = 0) (hadd : ∀ x y, g (x + y) = g x + g y) : mapDomain f (mapRange g h0 v) = mapRange g h0 (mapDomain f v) := let g' : M →+ N := { toFun := g map_zero' := h0 map_add' := hadd } DFunLike.congr_fun (mapDomain.addMonoidHom_comp_mapRange f g') v theorem sum_update_add [AddZeroClass α] [AddCommMonoid β] (f : ι →₀ α) (i : ι) (a : α) (g : ι → α → β) (hg : ∀ i, g i 0 = 0) (hgg : ∀ (j : ι) (a₁ a₂ : α), g j (a₁ + a₂) = g j a₁ + g j a₂) : (f.update i a).sum g + g i (f i) = f.sum g + g i a := by rw [update_eq_erase_add_single, sum_add_index' hg hgg] conv_rhs => rw [← Finsupp.update_self f i] rw [update_eq_erase_add_single, sum_add_index' hg hgg, add_assoc, add_assoc] congr 1 rw [add_comm, sum_single_index (hg _), sum_single_index (hg _)] theorem mapDomain_injOn (S : Set α) {f : α → β} (hf : Set.InjOn f S) : Set.InjOn (mapDomain f : (α →₀ M) → β →₀ M) { w | (w.support : Set α) ⊆ S } := by intro v₁ hv₁ v₂ hv₂ eq ext a classical by_cases h : a ∈ v₁.support ∪ v₂.support · rw [← mapDomain_apply' S _ hv₁ hf _, ← mapDomain_apply' S _ hv₂ hf _, eq] <;> · apply Set.union_subset hv₁ hv₂ exact mod_cast h · simp only [not_or, mem_union, not_not, mem_support_iff] at h simp [h] theorem equivMapDomain_eq_mapDomain {M} [AddCommMonoid M] (f : α ≃ β) (l : α →₀ M) : equivMapDomain f l = mapDomain f l := by ext x; simp [mapDomain_equiv_apply] end MapDomain /-! ### Declarations about `comapDomain` -/ section ComapDomain /-- Given `f : α → β`, `l : β →₀ M` and a proof `hf` that `f` is injective on the preimage of `l.support`, `comapDomain f l hf` is the finitely supported function from `α` to `M` given by composing `l` with `f`. -/ @[simps support] def comapDomain [Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) : α →₀ M where support := l.support.preimage f hf toFun a := l (f a) mem_support_toFun := by intro a simp only [Finset.mem_def.symm, Finset.mem_preimage] exact l.mem_support_toFun (f a) @[simp] theorem comapDomain_apply [Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) (a : α) : comapDomain f l hf a = l (f a) := rfl theorem sum_comapDomain [Zero M] [AddCommMonoid N] (f : α → β) (l : β →₀ M) (g : β → M → N) (hf : Set.BijOn f (f ⁻¹' ↑l.support) ↑l.support) : (comapDomain f l hf.injOn).sum (g ∘ f) = l.sum g := by simp only [sum, comapDomain_apply, (· ∘ ·), comapDomain] exact Finset.sum_preimage_of_bij f _ hf fun x => g x (l x) theorem eq_zero_of_comapDomain_eq_zero [Zero M] (f : α → β) (l : β →₀ M) (hf : Set.BijOn f (f ⁻¹' ↑l.support) ↑l.support) : comapDomain f l hf.injOn = 0 → l = 0 := by rw [← support_eq_empty, ← support_eq_empty, comapDomain] simp only [Finset.ext_iff, Finset.not_mem_empty, iff_false, mem_preimage] intro h a ha obtain ⟨b, hb⟩ := hf.2.2 ha exact h b (hb.2.symm ▸ ha) section FInjective section Zero variable [Zero M] lemma embDomain_comapDomain {f : α ↪ β} {g : β →₀ M} (hg : ↑g.support ⊆ Set.range f) : embDomain f (comapDomain f g f.injective.injOn) = g := by ext b by_cases hb : b ∈ Set.range f · obtain ⟨a, rfl⟩ := hb rw [embDomain_apply, comapDomain_apply] · replace hg : g b = 0 := not_mem_support_iff.mp <| mt (hg ·) hb rw [embDomain_notin_range _ _ _ hb, hg] /-- Note the `hif` argument is needed for this to work in `rw`. -/ @[simp] theorem comapDomain_zero (f : α → β) (hif : Set.InjOn f (f ⁻¹' ↑(0 : β →₀ M).support) := Finset.coe_empty ▸ (Set.injOn_empty f)) : comapDomain f (0 : β →₀ M) hif = (0 : α →₀ M) := by ext rfl @[simp] theorem comapDomain_single (f : α → β) (a : α) (m : M) (hif : Set.InjOn f (f ⁻¹' (single (f a) m).support)) : comapDomain f (Finsupp.single (f a) m) hif = Finsupp.single a m := by rcases eq_or_ne m 0 with (rfl | hm) · simp only [single_zero, comapDomain_zero] · rw [eq_single_iff, comapDomain_apply, comapDomain_support, ← Finset.coe_subset, coe_preimage, support_single_ne_zero _ hm, coe_singleton, coe_singleton, single_eq_same] rw [support_single_ne_zero _ hm, coe_singleton] at hif exact ⟨fun x hx => hif hx rfl hx, rfl⟩ end Zero section AddZeroClass variable [AddZeroClass M] {f : α → β} theorem comapDomain_add (v₁ v₂ : β →₀ M) (hv₁ : Set.InjOn f (f ⁻¹' ↑v₁.support)) (hv₂ : Set.InjOn f (f ⁻¹' ↑v₂.support)) (hv₁₂ : Set.InjOn f (f ⁻¹' ↑(v₁ + v₂).support)) : comapDomain f (v₁ + v₂) hv₁₂ = comapDomain f v₁ hv₁ + comapDomain f v₂ hv₂ := by ext simp only [comapDomain_apply, coe_add, Pi.add_apply] /-- A version of `Finsupp.comapDomain_add` that's easier to use. -/ theorem comapDomain_add_of_injective (hf : Function.Injective f) (v₁ v₂ : β →₀ M) : comapDomain f (v₁ + v₂) hf.injOn = comapDomain f v₁ hf.injOn + comapDomain f v₂ hf.injOn := comapDomain_add _ _ _ _ _ /-- `Finsupp.comapDomain` is an `AddMonoidHom`. -/ @[simps] def comapDomain.addMonoidHom (hf : Function.Injective f) : (β →₀ M) →+ α →₀ M where toFun x := comapDomain f x hf.injOn map_zero' := comapDomain_zero f map_add' := comapDomain_add_of_injective hf end AddZeroClass variable [AddCommMonoid M] (f : α → β) theorem mapDomain_comapDomain (hf : Function.Injective f) (l : β →₀ M) (hl : ↑l.support ⊆ Set.range f) : mapDomain f (comapDomain f l hf.injOn) = l := by conv_rhs => rw [← embDomain_comapDomain (f := ⟨f, hf⟩) hl (M := M), embDomain_eq_mapDomain] rfl end FInjective end ComapDomain /-! ### Declarations about finitely supported functions whose support is an `Option` type -/ section Option /-- Restrict a finitely supported function on `Option α` to a finitely supported function on `α`. -/ def some [Zero M] (f : Option α →₀ M) : α →₀ M := f.comapDomain Option.some fun _ => by simp @[simp] theorem some_apply [Zero M] (f : Option α →₀ M) (a : α) : f.some a = f (Option.some a) := rfl @[simp] theorem some_zero [Zero M] : (0 : Option α →₀ M).some = 0 := by ext simp @[simp] theorem some_add [AddZeroClass M] (f g : Option α →₀ M) : (f + g).some = f.some + g.some := by ext simp @[simp] theorem some_single_none [Zero M] (m : M) : (single none m : Option α →₀ M).some = 0 := by ext simp @[simp] theorem some_single_some [Zero M] (a : α) (m : M) : (single (Option.some a) m : Option α →₀ M).some = single a m := by classical ext b simp [single_apply] @[to_additive] theorem prod_option_index [AddZeroClass M] [CommMonoid N] (f : Option α →₀ M) (b : Option α → M → N) (h_zero : ∀ o, b o 0 = 1) (h_add : ∀ o m₁ m₂, b o (m₁ + m₂) = b o m₁ * b o m₂) : f.prod b = b none (f none) * f.some.prod fun a => b (Option.some a) := by classical induction f using induction_linear with | zero => simp [some_zero, h_zero] | add f₁ f₂ h₁ h₂ => rw [Finsupp.prod_add_index, h₁, h₂, some_add, Finsupp.prod_add_index] · simp only [h_add, Pi.add_apply, Finsupp.coe_add] rw [mul_mul_mul_comm] all_goals simp [h_zero, h_add] | single a m => cases a <;> simp [h_zero, h_add] theorem sum_option_index_smul [Semiring R] [AddCommMonoid M] [Module R M] (f : Option α →₀ R) (b : Option α → M) : (f.sum fun o r => r • b o) = f none • b none + f.some.sum fun a r => r • b (Option.some a) := f.sum_option_index _ (fun _ => zero_smul _ _) fun _ _ _ => add_smul _ _ _ theorem eq_option_embedding_update_none_iff [Zero M] {n : Option α →₀ M} {m : α →₀ M} {i : M} : (n = (embDomain Embedding.some m).update none i) ↔ n none = i ∧ n.some = m := by classical rw [Finsupp.ext_iff, Option.forall, Finsupp.ext_iff] apply and_congr · simp · apply forall_congr' intro simp only [coe_update, ne_eq, reduceCtorEq, not_false_eq_true, update_of_ne, some_apply] rw [← Embedding.some_apply, embDomain_apply, Embedding.some_apply] @[simp] lemma some_embDomain_some [Zero M] (f : α →₀ M) : (f.embDomain .some).some = f := by ext; rw [some_apply]; exact embDomain_apply _ _ _ @[simp] lemma embDomain_some_none [Zero M] (f : α →₀ M) : f.embDomain .some .none = 0 := embDomain_notin_range _ _ _ (by simp) end Option /-! ### Declarations about `Finsupp.filter` -/ section Filter section Zero variable [Zero M] (p : α → Prop) [DecidablePred p] (f : α →₀ M) /-- `Finsupp.filter p f` is the finitely supported function that is `f a` if `p a` is true and `0` otherwise. -/ def filter (p : α → Prop) [DecidablePred p] (f : α →₀ M) : α →₀ M where toFun a := if p a then f a else 0 support := f.support.filter p mem_support_toFun a := by split_ifs with h <;> · simp only [h, mem_filter, mem_support_iff] tauto theorem filter_apply (a : α) : f.filter p a = if p a then f a else 0 := rfl theorem filter_eq_indicator : ⇑(f.filter p) = Set.indicator { x | p x } f := by ext simp [filter_apply, Set.indicator_apply] theorem filter_eq_zero_iff : f.filter p = 0 ↔ ∀ x, p x → f x = 0 := by simp only [DFunLike.ext_iff, filter_eq_indicator, zero_apply, Set.indicator_apply_eq_zero, Set.mem_setOf_eq] theorem filter_eq_self_iff : f.filter p = f ↔ ∀ x, f x ≠ 0 → p x := by simp only [DFunLike.ext_iff, filter_eq_indicator, Set.indicator_apply_eq_self, Set.mem_setOf_eq, not_imp_comm] @[simp] theorem filter_apply_pos {a : α} (h : p a) : f.filter p a = f a := if_pos h @[simp] theorem filter_apply_neg {a : α} (h : ¬p a) : f.filter p a = 0 := if_neg h @[simp] theorem support_filter : (f.filter p).support = {x ∈ f.support | p x} := rfl theorem filter_zero : (0 : α →₀ M).filter p = 0 := by classical rw [← support_eq_empty, support_filter, support_zero, Finset.filter_empty] @[simp] theorem filter_single_of_pos {a : α} {b : M} (h : p a) : (single a b).filter p = single a b := (filter_eq_self_iff _ _).2 fun _ hx => (single_apply_ne_zero.1 hx).1.symm ▸ h @[simp] theorem filter_single_of_neg {a : α} {b : M} (h : ¬p a) : (single a b).filter p = 0 := (filter_eq_zero_iff _ _).2 fun _ hpx => single_apply_eq_zero.2 fun hxa => absurd hpx (hxa.symm ▸ h) @[to_additive] theorem prod_filter_index [CommMonoid N] (g : α → M → N) : (f.filter p).prod g = ∏ x ∈ (f.filter p).support, g x (f x) := by classical refine Finset.prod_congr rfl fun x hx => ?_ rw [support_filter, Finset.mem_filter] at hx rw [filter_apply_pos _ _ hx.2] @[to_additive (attr := simp)] theorem prod_filter_mul_prod_filter_not [CommMonoid N] (g : α → M → N) : (f.filter p).prod g * (f.filter fun a => ¬p a).prod g = f.prod g := by classical simp_rw [prod_filter_index, support_filter, Finset.prod_filter_mul_prod_filter_not, Finsupp.prod] @[to_additive (attr := simp)] theorem prod_div_prod_filter [CommGroup G] (g : α → M → G) : f.prod g / (f.filter p).prod g = (f.filter fun a => ¬p a).prod g := div_eq_of_eq_mul' (prod_filter_mul_prod_filter_not _ _ _).symm end Zero theorem filter_pos_add_filter_neg [AddZeroClass M] (f : α →₀ M) (p : α → Prop) [DecidablePred p] : (f.filter p + f.filter fun a => ¬p a) = f := DFunLike.coe_injective <| by simp only [coe_add, filter_eq_indicator] exact Set.indicator_self_add_compl { x | p x } f end Filter /-! ### Declarations about `frange` -/ section Frange variable [Zero M] /-- `frange f` is the image of `f` on the support of `f`. -/ def frange (f : α →₀ M) : Finset M := haveI := Classical.decEq M Finset.image f f.support theorem mem_frange {f : α →₀ M} {y : M} : y ∈ f.frange ↔ y ≠ 0 ∧ ∃ x, f x = y := by rw [frange, @Finset.mem_image _ _ (Classical.decEq _) _ f.support] exact ⟨fun ⟨x, hx1, hx2⟩ => ⟨hx2 ▸ mem_support_iff.1 hx1, x, hx2⟩, fun ⟨hy, x, hx⟩ => ⟨x, mem_support_iff.2 (hx.symm ▸ hy), hx⟩⟩ theorem zero_not_mem_frange {f : α →₀ M} : (0 : M) ∉ f.frange := fun H => (mem_frange.1 H).1 rfl theorem frange_single {x : α} {y : M} : frange (single x y) ⊆ {y} := fun r hr => let ⟨t, ht1, ht2⟩ := mem_frange.1 hr ht2 ▸ by classical rw [single_apply] at ht2 ⊢ split_ifs at ht2 ⊢ · exact Finset.mem_singleton_self _ · exact (t ht2.symm).elim end Frange /-! ### Declarations about `Finsupp.subtypeDomain` -/ section SubtypeDomain section Zero variable [Zero M] {p : α → Prop} /-- `subtypeDomain p f` is the restriction of the finitely supported function `f` to subtype `p`. -/ def subtypeDomain (p : α → Prop) (f : α →₀ M) : Subtype p →₀ M where support := haveI := Classical.decPred p f.support.subtype p toFun := f ∘ Subtype.val mem_support_toFun a := by simp only [@mem_subtype _ _ (Classical.decPred p), mem_support_iff]; rfl @[simp] theorem support_subtypeDomain [D : DecidablePred p] {f : α →₀ M} : (subtypeDomain p f).support = f.support.subtype p := by rw [Subsingleton.elim D] <;> rfl @[simp] theorem subtypeDomain_apply {a : Subtype p} {v : α →₀ M} : (subtypeDomain p v) a = v a.val := rfl @[simp] theorem subtypeDomain_zero : subtypeDomain p (0 : α →₀ M) = 0 := rfl theorem subtypeDomain_eq_iff_forall {f g : α →₀ M} : f.subtypeDomain p = g.subtypeDomain p ↔ ∀ x, p x → f x = g x := by simp_rw [DFunLike.ext_iff, subtypeDomain_apply, Subtype.forall] theorem subtypeDomain_eq_iff {f g : α →₀ M} (hf : ∀ x ∈ f.support, p x) (hg : ∀ x ∈ g.support, p x) : f.subtypeDomain p = g.subtypeDomain p ↔ f = g := subtypeDomain_eq_iff_forall.trans ⟨fun H ↦ Finsupp.ext fun _a ↦ (em _).elim (H _ <| hf _ ·) fun haf ↦ (em _).elim (H _ <| hg _ ·) fun hag ↦ (not_mem_support_iff.mp haf).trans (not_mem_support_iff.mp hag).symm, fun H _ _ ↦ congr($H _)⟩ theorem subtypeDomain_eq_zero_iff' {f : α →₀ M} : f.subtypeDomain p = 0 ↔ ∀ x, p x → f x = 0 := subtypeDomain_eq_iff_forall (g := 0) theorem subtypeDomain_eq_zero_iff {f : α →₀ M} (hf : ∀ x ∈ f.support, p x) : f.subtypeDomain p = 0 ↔ f = 0 := subtypeDomain_eq_iff (g := 0) hf (by simp) @[to_additive] theorem prod_subtypeDomain_index [CommMonoid N] {v : α →₀ M} {h : α → M → N} (hp : ∀ x ∈ v.support, p x) : (v.subtypeDomain p).prod (fun a b ↦ h a b) = v.prod h := by refine Finset.prod_bij (fun p _ ↦ p) ?_ ?_ ?_ ?_ <;> aesop end Zero section AddZeroClass variable [AddZeroClass M] {p : α → Prop} {v v' : α →₀ M} @[simp] theorem subtypeDomain_add {v v' : α →₀ M} : (v + v').subtypeDomain p = v.subtypeDomain p + v'.subtypeDomain p := ext fun _ => rfl /-- `subtypeDomain` but as an `AddMonoidHom`. -/ def subtypeDomainAddMonoidHom : (α →₀ M) →+ Subtype p →₀ M where toFun := subtypeDomain p map_zero' := subtypeDomain_zero map_add' _ _ := subtypeDomain_add /-- `Finsupp.filter` as an `AddMonoidHom`. -/ def filterAddHom (p : α → Prop) [DecidablePred p] : (α →₀ M) →+ α →₀ M where toFun := filter p map_zero' := filter_zero p map_add' f g := DFunLike.coe_injective <| by simp only [filter_eq_indicator, coe_add] exact Set.indicator_add { x | p x } f g @[simp] theorem filter_add [DecidablePred p] {v v' : α →₀ M} : (v + v').filter p = v.filter p + v'.filter p := (filterAddHom p).map_add v v' end AddZeroClass section CommMonoid variable [AddCommMonoid M] {p : α → Prop} theorem subtypeDomain_sum {s : Finset ι} {h : ι → α →₀ M} : (∑ c ∈ s, h c).subtypeDomain p = ∑ c ∈ s, (h c).subtypeDomain p := map_sum subtypeDomainAddMonoidHom _ s theorem subtypeDomain_finsupp_sum [Zero N] {s : β →₀ N} {h : β → N → α →₀ M} : (s.sum h).subtypeDomain p = s.sum fun c d => (h c d).subtypeDomain p := subtypeDomain_sum theorem filter_sum [DecidablePred p] (s : Finset ι) (f : ι → α →₀ M) : (∑ a ∈ s, f a).filter p = ∑ a ∈ s, filter p (f a) := map_sum (filterAddHom p) f s theorem filter_eq_sum (p : α → Prop) [DecidablePred p] (f : α →₀ M) : f.filter p = ∑ i ∈ f.support.filter p, single i (f i) := (f.filter p).sum_single.symm.trans <| Finset.sum_congr rfl fun x hx => by rw [filter_apply_pos _ _ (mem_filter.1 hx).2] end CommMonoid section Group variable [AddGroup G] {p : α → Prop} {v v' : α →₀ G} @[simp] theorem subtypeDomain_neg : (-v).subtypeDomain p = -v.subtypeDomain p := ext fun _ => rfl @[simp] theorem subtypeDomain_sub : (v - v').subtypeDomain p = v.subtypeDomain p - v'.subtypeDomain p := ext fun _ => rfl @[simp] theorem filter_neg (p : α → Prop) [DecidablePred p] (f : α →₀ G) : filter p (-f) = -filter p f := (filterAddHom p : (_ →₀ G) →+ _).map_neg f @[simp] theorem filter_sub (p : α → Prop) [DecidablePred p] (f₁ f₂ : α →₀ G) : filter p (f₁ - f₂) = filter p f₁ - filter p f₂ := (filterAddHom p : (_ →₀ G) →+ _).map_sub f₁ f₂ end Group end SubtypeDomain theorem mem_support_multiset_sum [AddCommMonoid M] {s : Multiset (α →₀ M)} (a : α) : a ∈ s.sum.support → ∃ f ∈ s, a ∈ (f : α →₀ M).support := Multiset.induction_on s (fun h => False.elim (by simp at h)) (by intro f s ih ha by_cases h : a ∈ f.support · exact ⟨f, Multiset.mem_cons_self _ _, h⟩ · simp only [Multiset.sum_cons, mem_support_iff, add_apply, not_mem_support_iff.1 h, zero_add] at ha rcases ih (mem_support_iff.2 ha) with ⟨f', h₀, h₁⟩ exact ⟨f', Multiset.mem_cons_of_mem h₀, h₁⟩) theorem mem_support_finset_sum [AddCommMonoid M] {s : Finset ι} {h : ι → α →₀ M} (a : α) (ha : a ∈ (∑ c ∈ s, h c).support) : ∃ c ∈ s, a ∈ (h c).support := let ⟨_, hf, hfa⟩ := mem_support_multiset_sum a ha let ⟨c, hc, Eq⟩ := Multiset.mem_map.1 hf ⟨c, hc, Eq.symm ▸ hfa⟩ /-! ### Declarations about `curry` and `uncurry` -/ section CurryUncurry variable [AddCommMonoid M] [AddCommMonoid N] /-- Given a finitely supported function `f` from a product type `α × β` to `γ`, `curry f` is the "curried" finitely supported function from `α` to the type of finitely supported functions from `β` to `γ`. -/ protected def curry (f : α × β →₀ M) : α →₀ β →₀ M := f.sum fun p c => single p.1 (single p.2 c) @[simp] theorem curry_apply (f : α × β →₀ M) (x : α) (y : β) : f.curry x y = f (x, y) := by classical have : ∀ b : α × β, single b.fst (single b.snd (f b)) x y = if b = (x, y) then f b else 0 := by rintro ⟨b₁, b₂⟩ simp only [ne_eq, single_apply, Prod.ext_iff, ite_and] split_ifs <;> simp [single_apply, *] rw [Finsupp.curry, sum_apply, sum_apply, sum_eq_single, this, if_pos rfl] · intro b _ b_ne rw [this b, if_neg b_ne] · intro _ rw [single_zero, single_zero, coe_zero, Pi.zero_apply, coe_zero, Pi.zero_apply] theorem sum_curry_index (f : α × β →₀ M) (g : α → β → M → N) (hg₀ : ∀ a b, g a b 0 = 0) (hg₁ : ∀ a b c₀ c₁, g a b (c₀ + c₁) = g a b c₀ + g a b c₁) : (f.curry.sum fun a f => f.sum (g a)) = f.sum fun p c => g p.1 p.2 c := by rw [Finsupp.curry] trans · exact sum_sum_index (fun a => sum_zero_index) fun a b₀ b₁ => sum_add_index' (fun a => hg₀ _ _) fun c d₀ d₁ => hg₁ _ _ _ _ congr; funext p c trans · exact sum_single_index sum_zero_index exact sum_single_index (hg₀ _ _) /-- Given a finitely supported function `f` from `α` to the type of finitely supported functions from `β` to `M`, `uncurry f` is the "uncurried" finitely supported function from `α × β` to `M`. -/ protected def uncurry (f : α →₀ β →₀ M) : α × β →₀ M := f.sum fun a g => g.sum fun b c => single (a, b) c @[simp] protected theorem uncurry_apply_pair (f : α →₀ β →₀ M) (x : α) (y : β) : f.uncurry (x, y) = f x y := by rw [← curry_apply (f.uncurry) x y] simp only [Finsupp.curry, Finsupp.uncurry, sum_sum_index, single_zero, single_add, forall_true_iff, sum_single_index, single_zero, ← single_sum, sum_single] @[simp] theorem curry_uncurry (f : α →₀ β →₀ M) : f.uncurry.curry = f := by ext a b rw [curry_apply, Finsupp.uncurry_apply_pair] @[simp] theorem uncurry_curry (f : α × β →₀ M) : f.curry.uncurry = f := by ext ⟨a, b⟩ rw [Finsupp.uncurry_apply_pair, curry_apply] /-- `finsuppProdEquiv` defines the `Equiv` between `((α × β) →₀ M)` and `(α →₀ (β →₀ M))` given by currying and uncurrying. -/ def finsuppProdEquiv : (α × β →₀ M) ≃ (α →₀ β →₀ M) where toFun := Finsupp.curry invFun := Finsupp.uncurry left_inv := uncurry_curry right_inv := curry_uncurry theorem filter_curry (f : α × β →₀ M) (p : α → Prop) [DecidablePred p] : (f.filter fun a : α × β => p a.1).curry = f.curry.filter p := by classical rw [Finsupp.curry, Finsupp.curry, Finsupp.sum, Finsupp.sum, filter_sum, support_filter, sum_filter] refine Finset.sum_congr rfl ?_ rintro ⟨a₁, a₂⟩ _ split_ifs with h · rw [filter_apply_pos, filter_single_of_pos] <;> exact h · rwa [filter_single_of_neg] theorem support_curry [DecidableEq α] (f : α × β →₀ M) : f.curry.support ⊆ f.support.image Prod.fst := by rw [← Finset.biUnion_singleton] refine Finset.Subset.trans support_sum ?_ exact Finset.biUnion_mono fun a _ => support_single_subset end CurryUncurry /-! ### Declarations about finitely supported functions whose support is a `Sum` type -/ section Sum /-- `Finsupp.sumElim f g` maps `inl x` to `f x` and `inr y` to `g y`. -/ @[simps support] def sumElim {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) : α ⊕ β →₀ γ where support := f.support.disjSum g.support toFun := Sum.elim f g mem_support_toFun := by simp @[simp, norm_cast] theorem coe_sumElim {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) : ⇑(sumElim f g) = Sum.elim f g := rfl theorem sumElim_apply {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) (x : α ⊕ β) : sumElim f g x = Sum.elim f g x := rfl theorem sumElim_inl {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) (x : α) : sumElim f g (Sum.inl x) = f x := rfl theorem sumElim_inr {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) (x : β) : sumElim f g (Sum.inr x) = g x := rfl @[to_additive] lemma prod_sumElim {ι₁ ι₂ α M : Type*} [Zero α] [CommMonoid M] (f₁ : ι₁ →₀ α) (f₂ : ι₂ →₀ α) (g : ι₁ ⊕ ι₂ → α → M) : (f₁.sumElim f₂).prod g = f₁.prod (g ∘ Sum.inl) * f₂.prod (g ∘ Sum.inr) := by simp [Finsupp.prod, Finset.prod_disj_sum] /-- The equivalence between `(α ⊕ β) →₀ γ` and `(α →₀ γ) × (β →₀ γ)`. This is the `Finsupp` version of `Equiv.sum_arrow_equiv_prod_arrow`. -/ @[simps apply symm_apply] def sumFinsuppEquivProdFinsupp {α β γ : Type*} [Zero γ] : (α ⊕ β →₀ γ) ≃ (α →₀ γ) × (β →₀ γ) where toFun f := ⟨f.comapDomain Sum.inl Sum.inl_injective.injOn, f.comapDomain Sum.inr Sum.inr_injective.injOn⟩ invFun fg := sumElim fg.1 fg.2 left_inv f := by ext ab rcases ab with a | b <;> simp right_inv fg := by ext <;> simp theorem fst_sumFinsuppEquivProdFinsupp {α β γ : Type*} [Zero γ] (f : α ⊕ β →₀ γ) (x : α) : (sumFinsuppEquivProdFinsupp f).1 x = f (Sum.inl x) := rfl theorem snd_sumFinsuppEquivProdFinsupp {α β γ : Type*} [Zero γ] (f : α ⊕ β →₀ γ) (y : β) : (sumFinsuppEquivProdFinsupp f).2 y = f (Sum.inr y) := rfl theorem sumFinsuppEquivProdFinsupp_symm_inl {α β γ : Type*} [Zero γ] (fg : (α →₀ γ) × (β →₀ γ)) (x : α) : (sumFinsuppEquivProdFinsupp.symm fg) (Sum.inl x) = fg.1 x := rfl theorem sumFinsuppEquivProdFinsupp_symm_inr {α β γ : Type*} [Zero γ] (fg : (α →₀ γ) × (β →₀ γ)) (y : β) : (sumFinsuppEquivProdFinsupp.symm fg) (Sum.inr y) = fg.2 y := rfl variable [AddMonoid M] /-- The additive equivalence between `(α ⊕ β) →₀ M` and `(α →₀ M) × (β →₀ M)`. This is the `Finsupp` version of `Equiv.sum_arrow_equiv_prod_arrow`. -/ @[simps! apply symm_apply] def sumFinsuppAddEquivProdFinsupp {α β : Type*} : (α ⊕ β →₀ M) ≃+ (α →₀ M) × (β →₀ M) := { sumFinsuppEquivProdFinsupp with map_add' := by intros ext <;> simp only [Equiv.toFun_as_coe, Prod.fst_add, Prod.snd_add, add_apply, snd_sumFinsuppEquivProdFinsupp, fst_sumFinsuppEquivProdFinsupp] } theorem fst_sumFinsuppAddEquivProdFinsupp {α β : Type*} (f : α ⊕ β →₀ M) (x : α) : (sumFinsuppAddEquivProdFinsupp f).1 x = f (Sum.inl x) := rfl theorem snd_sumFinsuppAddEquivProdFinsupp {α β : Type*} (f : α ⊕ β →₀ M) (y : β) : (sumFinsuppAddEquivProdFinsupp f).2 y = f (Sum.inr y) := rfl theorem sumFinsuppAddEquivProdFinsupp_symm_inl {α β : Type*} (fg : (α →₀ M) × (β →₀ M)) (x : α) : (sumFinsuppAddEquivProdFinsupp.symm fg) (Sum.inl x) = fg.1 x := rfl theorem sumFinsuppAddEquivProdFinsupp_symm_inr {α β : Type*} (fg : (α →₀ M) × (β →₀ M)) (y : β) : (sumFinsuppAddEquivProdFinsupp.symm fg) (Sum.inr y) = fg.2 y := rfl end Sum section variable [Zero R] /-- The `Finsupp` version of `Pi.unique`. -/ instance uniqueOfRight [Subsingleton R] : Unique (α →₀ R) := DFunLike.coe_injective.unique /-- The `Finsupp` version of `Pi.uniqueOfIsEmpty`. -/ instance uniqueOfLeft [IsEmpty α] : Unique (α →₀ R) := DFunLike.coe_injective.unique end section variable {M : Type*} [Zero M] {P : α → Prop} [DecidablePred P] /-- Combine finitely supported functions over `{a // P a}` and `{a // ¬P a}`, by case-splitting on `P a`. -/ @[simps] def piecewise (f : Subtype P →₀ M) (g : {a // ¬ P a} →₀ M) : α →₀ M where toFun a := if h : P a then f ⟨a, h⟩ else g ⟨a, h⟩ support := (f.support.map (.subtype _)).disjUnion (g.support.map (.subtype _)) <| by simp_rw [Finset.disjoint_left, mem_map, forall_exists_index, Embedding.coe_subtype, Subtype.forall, Subtype.exists] rintro _ a ha ⟨-, rfl⟩ ⟨b, hb, -, rfl⟩ exact hb ha mem_support_toFun a := by by_cases ha : P a <;> simp [ha] @[simp] theorem subtypeDomain_piecewise (f : Subtype P →₀ M) (g : {a // ¬ P a} →₀ M) : subtypeDomain P (f.piecewise g) = f := Finsupp.ext fun a => dif_pos a.prop @[simp] theorem subtypeDomain_not_piecewise (f : Subtype P →₀ M) (g : {a // ¬ P a} →₀ M) : subtypeDomain (¬P ·) (f.piecewise g) = g := Finsupp.ext fun a => dif_neg a.prop /-- Extend the domain of a `Finsupp` by using `0` where `P x` does not hold. -/ @[simps! support toFun] def extendDomain (f : Subtype P →₀ M) : α →₀ M := piecewise f 0 theorem extendDomain_eq_embDomain_subtype (f : Subtype P →₀ M) : extendDomain f = embDomain (.subtype _) f := by ext a by_cases h : P a · refine Eq.trans ?_ (embDomain_apply (.subtype P) f (Subtype.mk a h)).symm simp [h] · rw [embDomain_notin_range, extendDomain_toFun, dif_neg h] simp [h] theorem support_extendDomain_subset (f : Subtype P →₀ M) : ↑(f.extendDomain).support ⊆ {x | P x} := by intro x rw [extendDomain_support, mem_coe, mem_map, Embedding.coe_subtype] rintro ⟨x, -, rfl⟩ exact x.prop @[simp] theorem subtypeDomain_extendDomain (f : Subtype P →₀ M) : subtypeDomain P f.extendDomain = f := subtypeDomain_piecewise _ _ theorem extendDomain_subtypeDomain (f : α →₀ M) (hf : ∀ a ∈ f.support, P a) : (subtypeDomain P f).extendDomain = f := by ext a by_cases h : P a · exact dif_pos h · #adaptation_note /-- nightly-2024-06-18 this `rw` was done by `dsimp`. -/ rw [extendDomain_toFun] dsimp rw [if_neg h, eq_comm, ← not_mem_support_iff] refine mt ?_ h exact @hf _ @[simp] theorem extendDomain_single (a : Subtype P) (m : M) : (single a m).extendDomain = single a.val m := by ext a' #adaptation_note /-- nightly-2024-06-18 this `rw` was instead `dsimp only`. -/ rw [extendDomain_toFun] obtain rfl | ha := eq_or_ne a.val a' · simp_rw [single_eq_same, dif_pos a.prop] · simp_rw [single_eq_of_ne ha, dite_eq_right_iff] intro h rw [single_eq_of_ne] simp [Subtype.ext_iff, ha] end /-- Given an `AddCommMonoid M` and `s : Set α`, `restrictSupportEquiv s M` is the `Equiv` between the subtype of finitely supported functions with support contained in `s` and the type of finitely supported functions from `s`. -/ -- TODO: add [DecidablePred (· ∈ s)] as an assumption @[simps] def restrictSupportEquiv (s : Set α) (M : Type*) [AddCommMonoid M] : { f : α →₀ M // ↑f.support ⊆ s } ≃ (s →₀ M) where toFun f := subtypeDomain (· ∈ s) f.1 invFun f := letI := Classical.decPred (· ∈ s); ⟨f.extendDomain, support_extendDomain_subset _⟩ left_inv f := letI := Classical.decPred (· ∈ s); Subtype.ext <| extendDomain_subtypeDomain f.1 f.prop right_inv _ := letI := Classical.decPred (· ∈ s); subtypeDomain_extendDomain _ /-- Given `AddCommMonoid M` and `e : α ≃ β`, `domCongr e` is the corresponding `Equiv` between `α →₀ M` and `β →₀ M`. This is `Finsupp.equivCongrLeft` as an `AddEquiv`. -/ @[simps apply] protected def domCongr [AddCommMonoid M] (e : α ≃ β) : (α →₀ M) ≃+ (β →₀ M) where toFun := equivMapDomain e invFun := equivMapDomain e.symm left_inv v := by simp only [← equivMapDomain_trans, Equiv.self_trans_symm] exact equivMapDomain_refl _ right_inv := by intro v simp only [← equivMapDomain_trans, Equiv.symm_trans_self] exact equivMapDomain_refl _ map_add' a b := by simp only [equivMapDomain_eq_mapDomain]; exact mapDomain_add @[simp] theorem domCongr_refl [AddCommMonoid M] : Finsupp.domCongr (Equiv.refl α) = AddEquiv.refl (α →₀ M) := AddEquiv.ext fun _ => equivMapDomain_refl _ @[simp] theorem domCongr_symm [AddCommMonoid M] (e : α ≃ β) : (Finsupp.domCongr e).symm = (Finsupp.domCongr e.symm : (β →₀ M) ≃+ (α →₀ M)) := AddEquiv.ext fun _ => rfl @[simp] theorem domCongr_trans [AddCommMonoid M] (e : α ≃ β) (f : β ≃ γ) : (Finsupp.domCongr e).trans (Finsupp.domCongr f) = (Finsupp.domCongr (e.trans f) : (α →₀ M) ≃+ _) := AddEquiv.ext fun _ => (equivMapDomain_trans _ _ _).symm end Finsupp namespace Finsupp /-! ### Declarations about sigma types -/ section Sigma variable {αs : ι → Type*} [Zero M] (l : (Σ i, αs i) →₀ M) /-- Given `l`, a finitely supported function from the sigma type `Σ (i : ι), αs i` to `M` and an index element `i : ι`, `split l i` is the `i`th component of `l`, a finitely supported function from `as i` to `M`. This is the `Finsupp` version of `Sigma.curry`. -/ def split (i : ι) : αs i →₀ M := l.comapDomain (Sigma.mk i) fun _ _ _ _ hx => heq_iff_eq.1 (Sigma.mk.inj hx).2 theorem split_apply (i : ι) (x : αs i) : split l i x = l ⟨i, x⟩ := by dsimp only [split] rw [comapDomain_apply] /-- Given `l`, a finitely supported function from the sigma type `Σ (i : ι), αs i` to `β`, `split_support l` is the finset of indices in `ι` that appear in the support of `l`. -/ def splitSupport (l : (Σ i, αs i) →₀ M) : Finset ι := haveI := Classical.decEq ι l.support.image Sigma.fst theorem mem_splitSupport_iff_nonzero (i : ι) : i ∈ splitSupport l ↔ split l i ≠ 0 := by classical rw [splitSupport, mem_image, Ne, ← support_eq_empty, ← Ne, ← Finset.nonempty_iff_ne_empty, split, comapDomain, Finset.Nonempty] simp only [exists_prop, Finset.mem_preimage, exists_and_right, exists_eq_right, mem_support_iff, Sigma.exists, Ne] /-- Given `l`, a finitely supported function from the sigma type `Σ i, αs i` to `β` and an `ι`-indexed family `g` of functions from `(αs i →₀ β)` to `γ`, `split_comp` defines a finitely supported function from the index type `ι` to `γ` given by composing `g i` with `split l i`. -/ def splitComp [Zero N] (g : ∀ i, (αs i →₀ M) → N) (hg : ∀ i x, x = 0 ↔ g i x = 0) : ι →₀ N where support := splitSupport l toFun i := g i (split l i) mem_support_toFun := by intro i rw [mem_splitSupport_iff_nonzero, not_iff_not, hg] theorem sigma_support : l.support = l.splitSupport.sigma fun i => (l.split i).support := by simp only [Finset.ext_iff, splitSupport, split, comapDomain, mem_image, mem_preimage, Sigma.forall, mem_sigma] tauto theorem sigma_sum [AddCommMonoid N] (f : (Σ i : ι, αs i) → M → N) : l.sum f = ∑ i ∈ splitSupport l, (split l i).sum fun (a : αs i) b => f ⟨i, a⟩ b := by simp only [sum, sigma_support, sum_sigma, split_apply] variable {η : Type*} [Fintype η] {ιs : η → Type*} [Zero α] /-- On a `Fintype η`, `Finsupp.split` is an equivalence between `(Σ (j : η), ιs j) →₀ α` and `Π j, (ιs j →₀ α)`. This is the `Finsupp` version of `Equiv.Pi_curry`. -/ noncomputable def sigmaFinsuppEquivPiFinsupp : ((Σ j, ιs j) →₀ α) ≃ ∀ j, ιs j →₀ α where toFun := split invFun f := onFinset (Finset.univ.sigma fun j => (f j).support) (fun ji => f ji.1 ji.2) fun _ hg => Finset.mem_sigma.mpr ⟨Finset.mem_univ _, mem_support_iff.mpr hg⟩ left_inv f := by ext simp [split] right_inv f := by ext simp [split] @[simp] theorem sigmaFinsuppEquivPiFinsupp_apply (f : (Σ j, ιs j) →₀ α) (j i) : sigmaFinsuppEquivPiFinsupp f j i = f ⟨j, i⟩ := rfl /-- On a `Fintype η`, `Finsupp.split` is an additive equivalence between `(Σ (j : η), ιs j) →₀ α` and `Π j, (ιs j →₀ α)`. This is the `AddEquiv` version of `Finsupp.sigmaFinsuppEquivPiFinsupp`. -/ noncomputable def sigmaFinsuppAddEquivPiFinsupp {α : Type*} {ιs : η → Type*} [AddMonoid α] : ((Σ j, ιs j) →₀ α) ≃+ ∀ j, ιs j →₀ α := { sigmaFinsuppEquivPiFinsupp with map_add' := fun f g => by ext simp } @[simp] theorem sigmaFinsuppAddEquivPiFinsupp_apply {α : Type*} {ιs : η → Type*} [AddMonoid α] (f : (Σ j, ιs j) →₀ α) (j i) : sigmaFinsuppAddEquivPiFinsupp f j i = f ⟨j, i⟩ := rfl end Sigma end Finsupp
Mathlib/Data/Finsupp/Basic.lean
1,839
1,841
/- Copyright (c) 2022 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Data.Nat.Cast.Field import Mathlib.GroupTheory.Abelianization import Mathlib.GroupTheory.GroupAction.CardCommute import Mathlib.GroupTheory.SpecificGroups.Dihedral import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Qify /-! # Commuting Probability This file introduces the commuting probability of finite groups. ## Main definitions * `commProb`: The commuting probability of a finite type with a multiplication operation. ## TODO * Neumann's theorem. -/ assert_not_exists Ideal TwoSidedIdeal noncomputable section open Fintype variable (M : Type*) [Mul M] /-- The commuting probability of a finite type with a multiplication operation. -/ def commProb : ℚ := Nat.card { p : M × M // Commute p.1 p.2 } / (Nat.card M : ℚ) ^ 2 theorem commProb_def : commProb M = Nat.card { p : M × M // Commute p.1 p.2 } / (Nat.card M : ℚ) ^ 2 := rfl theorem commProb_prod (M' : Type*) [Mul M'] : commProb (M × M') = commProb M * commProb M' := by simp_rw [commProb_def, div_mul_div_comm, Nat.card_prod, Nat.cast_mul, mul_pow, ← Nat.cast_mul, ← Nat.card_prod, Commute, SemiconjBy, Prod.ext_iff] congr 2 exact Nat.card_congr ⟨fun x => ⟨⟨⟨x.1.1.1, x.1.2.1⟩, x.2.1⟩, ⟨⟨x.1.1.2, x.1.2.2⟩, x.2.2⟩⟩, fun x => ⟨⟨⟨x.1.1.1, x.2.1.1⟩, ⟨x.1.1.2, x.2.1.2⟩⟩, ⟨x.1.2, x.2.2⟩⟩, fun x => rfl, fun x => rfl⟩ theorem commProb_pi {α : Type*} (i : α → Type*) [Fintype α] [∀ a, Mul (i a)] : commProb (∀ a, i a) = ∏ a, commProb (i a) := by simp_rw [commProb_def, Finset.prod_div_distrib, Finset.prod_pow, ← Nat.cast_prod, ← Nat.card_pi, Commute, SemiconjBy, funext_iff] congr 2 exact Nat.card_congr ⟨fun x a => ⟨⟨x.1.1 a, x.1.2 a⟩, x.2 a⟩, fun x => ⟨⟨fun a => (x a).1.1, fun a => (x a).1.2⟩, fun a => (x a).2⟩, fun x => rfl, fun x => rfl⟩ theorem commProb_function {α β : Type*} [Fintype α] [Mul β] : commProb (α → β) = (commProb β) ^ Fintype.card α := by rw [commProb_pi, Finset.prod_const, Finset.card_univ] @[simp] theorem commProb_eq_zero_of_infinite [Infinite M] : commProb M = 0 := div_eq_zero_iff.2 (Or.inl (Nat.cast_eq_zero.2 Nat.card_eq_zero_of_infinite)) variable [Finite M] theorem commProb_pos [h : Nonempty M] : 0 < commProb M := h.elim fun x ↦ div_pos (Nat.cast_pos.mpr (Finite.card_pos_iff.mpr ⟨⟨(x, x), rfl⟩⟩)) (pow_pos (Nat.cast_pos.mpr Finite.card_pos) 2) theorem commProb_le_one : commProb M ≤ 1 := by refine div_le_one_of_le₀ ?_ (sq_nonneg (Nat.card M : ℚ)) rw [← Nat.cast_pow, Nat.cast_le, sq, ← Nat.card_prod] apply Finite.card_subtype_le variable {M}
theorem commProb_eq_one_iff [h : Nonempty M] : commProb M = 1 ↔ Std.Commutative ((· * ·) : M → M → M) := by classical
Mathlib/GroupTheory/CommutingProbability.lean
78
81
/- 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.Geometry.Manifold.Algebra.Structures import Mathlib.Geometry.Manifold.BumpFunction import Mathlib.Topology.MetricSpace.PartitionOfUnity import Mathlib.Topology.ShrinkingLemma /-! # Smooth partition of unity In this file we define two structures, `SmoothBumpCovering` and `SmoothPartitionOfUnity`. Both structures describe coverings of a set by a locally finite family of supports of smooth functions with some additional properties. The former structure is mostly useful as an intermediate step in the construction of a smooth partition of unity but some proofs that traditionally deal with a partition of unity can use a `SmoothBumpCovering` as well. Given a real manifold `M` and its subset `s`, a `SmoothBumpCovering ι I M s` is a collection of `SmoothBumpFunction`s `f i` indexed by `i : ι` such that * the center of each `f i` belongs to `s`; * the family of sets `support (f i)` is locally finite; * for each `x ∈ s`, there exists `i : ι` such that `f i =ᶠ[𝓝 x] 1`. In the same settings, a `SmoothPartitionOfUnity ι I M s` is a collection of smooth nonnegative functions `f i : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯`, `i : ι`, such that * the family of sets `support (f i)` is locally finite; * for each `x ∈ s`, the sum `∑ᶠ i, f i x` equals one; * for each `x`, the sum `∑ᶠ i, f i x` is less than or equal to one. We say that `f : SmoothBumpCovering ι I M s` is *subordinate* to a map `U : M → Set M` if for each index `i`, we have `tsupport (f i) ⊆ U (f i).c`. This notion is a bit more general than being subordinate to an open covering of `M`, because we make no assumption about the way `U x` depends on `x`. We prove that on a smooth finitely dimensional real manifold with `σ`-compact Hausdorff topology, for any `U : M → Set M` such that `∀ x ∈ s, U x ∈ 𝓝 x` there exists a `SmoothBumpCovering ι I M s` subordinate to `U`. Then we use this fact to prove a similar statement about smooth partitions of unity, see `SmoothPartitionOfUnity.exists_isSubordinate`. Finally, we use existence of a partition of unity to prove lemma `exists_smooth_forall_mem_convex_of_local` that allows us to construct a globally defined smooth function from local functions. ## TODO * Build a framework for to transfer local definitions to global using partition of unity and use it to define, e.g., the integral of a differential form over a manifold. Lemma `exists_smooth_forall_mem_convex_of_local` is a first step in this direction. ## Tags smooth bump function, partition of unity -/ universe uι uE uH uM uF open Function Filter Module Set open scoped Topology Manifold ContDiff noncomputable section variable {ι : Type uι} {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace ℝ F] {H : Type uH} [TopologicalSpace H] (I : ModelWithCorners ℝ E H) {M : Type uM} [TopologicalSpace M] [ChartedSpace H M] /-! ### Covering by supports of smooth bump functions In this section we define `SmoothBumpCovering ι I M s` to be a collection of `SmoothBumpFunction`s such that their supports is a locally finite family of sets and for each `x ∈ s` some function `f i` from the collection is equal to `1` in a neighborhood of `x`. A covering of this type is useful to construct a smooth partition of unity and can be used instead of a partition of unity in some proofs. We prove that on a smooth finite dimensional real manifold with `σ`-compact Hausdorff topology, for any `U : M → Set M` such that `∀ x ∈ s, U x ∈ 𝓝 x` there exists a `SmoothBumpCovering ι I M s` subordinate to `U`. -/ variable (ι M) /-- We say that a collection of `SmoothBumpFunction`s is a `SmoothBumpCovering` of a set `s` if * `(f i).c ∈ s` for all `i`; * the family `fun i ↦ support (f i)` is locally finite; * for each point `x ∈ s` there exists `i` such that `f i =ᶠ[𝓝 x] 1`; in other words, `x` belongs to the interior of `{y | f i y = 1}`; If `M` is a finite dimensional real manifold which is a `σ`-compact Hausdorff topological space, then for every covering `U : M → Set M`, `∀ x, U x ∈ 𝓝 x`, there exists a `SmoothBumpCovering` subordinate to `U`, see `SmoothBumpCovering.exists_isSubordinate`. This covering can be used, e.g., to construct a partition of unity and to prove the weak Whitney embedding theorem. -/ structure SmoothBumpCovering [FiniteDimensional ℝ E] (s : Set M := univ) where /-- The center point of each bump in the smooth covering. -/ c : ι → M /-- A smooth bump function around `c i`. -/ toFun : ∀ i, SmoothBumpFunction I (c i) /-- All the bump functions in the covering are centered at points in `s`. -/ c_mem' : ∀ i, c i ∈ s /-- Around each point, there are only finitely many nonzero bump functions in the family. -/ locallyFinite' : LocallyFinite fun i => support (toFun i) /-- Around each point in `s`, one of the bump functions is equal to `1`. -/ eventuallyEq_one' : ∀ x ∈ s, ∃ i, toFun i =ᶠ[𝓝 x] 1 /-- We say that a collection of functions form a smooth partition of unity on a set `s` if * all functions are infinitely smooth and nonnegative; * the family `fun i ↦ support (f i)` is locally finite; * for all `x ∈ s` the sum `∑ᶠ i, f i x` equals one; * for all `x`, the sum `∑ᶠ i, f i x` is less than or equal to one. -/ structure SmoothPartitionOfUnity (s : Set M := univ) where /-- The family of functions forming the partition of unity. -/ toFun : ι → C^∞⟮I, M; 𝓘(ℝ), ℝ⟯ /-- Around each point, there are only finitely many nonzero functions in the family. -/ locallyFinite' : LocallyFinite fun i => support (toFun i) /-- All the functions in the partition of unity are nonnegative. -/ nonneg' : ∀ i x, 0 ≤ toFun i x /-- The functions in the partition of unity add up to `1` at any point of `s`. -/ sum_eq_one' : ∀ x ∈ s, ∑ᶠ i, toFun i x = 1 /-- The functions in the partition of unity add up to at most `1` everywhere. -/ sum_le_one' : ∀ x, ∑ᶠ i, toFun i x ≤ 1 variable {ι I M} namespace SmoothPartitionOfUnity variable {s : Set M} (f : SmoothPartitionOfUnity ι I M s) {n : ℕ∞} instance {s : Set M} : FunLike (SmoothPartitionOfUnity ι I M s) ι C^∞⟮I, M; 𝓘(ℝ), ℝ⟯ where coe := toFun coe_injective' f g h := by cases f; cases g; congr protected theorem locallyFinite : LocallyFinite fun i => support (f i) := f.locallyFinite' theorem nonneg (i : ι) (x : M) : 0 ≤ f i x := f.nonneg' i x theorem sum_eq_one {x} (hx : x ∈ s) : ∑ᶠ i, f i x = 1 := f.sum_eq_one' x hx theorem exists_pos_of_mem {x} (hx : x ∈ s) : ∃ i, 0 < f i x := by by_contra! h have H : ∀ i, f i x = 0 := fun i ↦ le_antisymm (h i) (f.nonneg i x) have := f.sum_eq_one hx simp_rw [H] at this simpa theorem sum_le_one (x : M) : ∑ᶠ i, f i x ≤ 1 := f.sum_le_one' x /-- Reinterpret a smooth partition of unity as a continuous partition of unity. -/ @[simps] def toPartitionOfUnity : PartitionOfUnity ι M s := { f with toFun := fun i => f i } theorem contMDiff_sum : ContMDiff I 𝓘(ℝ) ∞ fun x => ∑ᶠ i, f i x := contMDiff_finsum (fun i => (f i).contMDiff) f.locallyFinite @[deprecated (since := "2024-11-21")] alias smooth_sum := contMDiff_sum theorem le_one (i : ι) (x : M) : f i x ≤ 1 := f.toPartitionOfUnity.le_one i x theorem sum_nonneg (x : M) : 0 ≤ ∑ᶠ i, f i x := f.toPartitionOfUnity.sum_nonneg x theorem finsum_smul_mem_convex {g : ι → M → F} {t : Set F} {x : M} (hx : x ∈ s) (hg : ∀ i, f i x ≠ 0 → g i x ∈ t) (ht : Convex ℝ t) : ∑ᶠ i, f i x • g i x ∈ t := ht.finsum_mem (fun _ => f.nonneg _ _) (f.sum_eq_one hx) hg theorem contMDiff_smul {g : M → F} {i} (hg : ∀ x ∈ tsupport (f i), ContMDiffAt I 𝓘(ℝ, F) n g x) : ContMDiff I 𝓘(ℝ, F) n fun x => f i x • g x := contMDiff_of_tsupport fun x hx => ((f i).contMDiff.contMDiffAt.of_le (mod_cast le_top)).smul <| hg x <| tsupport_smul_subset_left _ _ hx @[deprecated (since := "2024-11-21")] alias smooth_smul := contMDiff_smul /-- If `f` is a smooth partition of unity on a set `s : Set M` and `g : ι → M → F` is a family of functions such that `g i` is $C^n$ smooth at every point of the topological support of `f i`, then the sum `fun x ↦ ∑ᶠ i, f i x • g i x` is smooth on the whole manifold. -/ theorem contMDiff_finsum_smul {g : ι → M → F} (hg : ∀ (i), ∀ x ∈ tsupport (f i), ContMDiffAt I 𝓘(ℝ, F) n (g i) x) : ContMDiff I 𝓘(ℝ, F) n fun x => ∑ᶠ i, f i x • g i x := (contMDiff_finsum fun i => f.contMDiff_smul (hg i)) <| f.locallyFinite.subset fun _ => support_smul_subset_left _ _ @[deprecated (since := "2024-11-21")] alias smooth_finsum_smul := contMDiff_finsum_smul theorem contMDiffAt_finsum {x₀ : M} {g : ι → M → F} (hφ : ∀ i, x₀ ∈ tsupport (f i) → ContMDiffAt I 𝓘(ℝ, F) n (g i) x₀) : ContMDiffAt I 𝓘(ℝ, F) n (fun x ↦ ∑ᶠ i, f i x • g i x) x₀ := by refine _root_.contMDiffAt_finsum (f.locallyFinite.smul_left _) fun i ↦ ?_ by_cases hx : x₀ ∈ tsupport (f i) · exact ContMDiffAt.smul ((f i).contMDiff.of_le (mod_cast le_top)).contMDiffAt (hφ i hx) · exact contMDiffAt_of_not_mem (compl_subset_compl.mpr (tsupport_smul_subset_left (f i) (g i)) hx) n theorem contDiffAt_finsum {s : Set E} (f : SmoothPartitionOfUnity ι 𝓘(ℝ, E) E s) {x₀ : E} {g : ι → E → F} (hφ : ∀ i, x₀ ∈ tsupport (f i) → ContDiffAt ℝ n (g i) x₀) : ContDiffAt ℝ n (fun x ↦ ∑ᶠ i, f i x • g i x) x₀ := by simp only [← contMDiffAt_iff_contDiffAt] at * exact f.contMDiffAt_finsum hφ section finsupport variable {s : Set M} (ρ : SmoothPartitionOfUnity ι I M s) (x₀ : M) /-- The support of a smooth partition of unity at a point `x₀` as a `Finset`. This is the set of `i : ι` such that `x₀ ∈ support f i`, i.e. `f i ≠ x₀`. -/ def finsupport : Finset ι := ρ.toPartitionOfUnity.finsupport x₀ @[simp] theorem mem_finsupport {i : ι} : i ∈ ρ.finsupport x₀ ↔ i ∈ support fun i ↦ ρ i x₀ := ρ.toPartitionOfUnity.mem_finsupport x₀ @[simp] theorem coe_finsupport : (ρ.finsupport x₀ : Set ι) = support fun i ↦ ρ i x₀ := ρ.toPartitionOfUnity.coe_finsupport x₀ theorem sum_finsupport (hx₀ : x₀ ∈ s) : ∑ i ∈ ρ.finsupport x₀, ρ i x₀ = 1 := ρ.toPartitionOfUnity.sum_finsupport hx₀ theorem sum_finsupport' (hx₀ : x₀ ∈ s) {I : Finset ι} (hI : ρ.finsupport x₀ ⊆ I) : ∑ i ∈ I, ρ i x₀ = 1 := ρ.toPartitionOfUnity.sum_finsupport' hx₀ hI theorem sum_finsupport_smul_eq_finsum {A : Type*} [AddCommGroup A] [Module ℝ A] (φ : ι → M → A) : ∑ i ∈ ρ.finsupport x₀, ρ i x₀ • φ i x₀ = ∑ᶠ i, ρ i x₀ • φ i x₀ := ρ.toPartitionOfUnity.sum_finsupport_smul_eq_finsum φ end finsupport section fintsupport -- smooth partitions of unity have locally finite `tsupport` variable {s : Set M} (ρ : SmoothPartitionOfUnity ι I M s) (x₀ : M) /-- The `tsupport`s of a smooth partition of unity are locally finite. -/ theorem finite_tsupport : {i | x₀ ∈ tsupport (ρ i)}.Finite := ρ.toPartitionOfUnity.finite_tsupport _ /-- The tsupport of a partition of unity at a point `x₀` as a `Finset`. This is the set of `i : ι` such that `x₀ ∈ tsupport f i`. -/ def fintsupport (x : M) : Finset ι := (ρ.finite_tsupport x).toFinset theorem mem_fintsupport_iff (i : ι) : i ∈ ρ.fintsupport x₀ ↔ x₀ ∈ tsupport (ρ i) := Finite.mem_toFinset _ theorem eventually_fintsupport_subset : ∀ᶠ y in 𝓝 x₀, ρ.fintsupport y ⊆ ρ.fintsupport x₀ := ρ.toPartitionOfUnity.eventually_fintsupport_subset _ theorem finsupport_subset_fintsupport : ρ.finsupport x₀ ⊆ ρ.fintsupport x₀ := ρ.toPartitionOfUnity.finsupport_subset_fintsupport x₀ theorem eventually_finsupport_subset : ∀ᶠ y in 𝓝 x₀, ρ.finsupport y ⊆ ρ.fintsupport x₀ := ρ.toPartitionOfUnity.eventually_finsupport_subset x₀ end fintsupport section IsSubordinate /-- A smooth partition of unity `f i` is subordinate to a family of sets `U i` indexed by the same type if for each `i` the closure of the support of `f i` is a subset of `U i`. -/ def IsSubordinate (f : SmoothPartitionOfUnity ι I M s) (U : ι → Set M) := ∀ i, tsupport (f i) ⊆ U i variable {f} variable {U : ι → Set M} @[simp] theorem isSubordinate_toPartitionOfUnity : f.toPartitionOfUnity.IsSubordinate U ↔ f.IsSubordinate U := Iff.rfl alias ⟨_, IsSubordinate.toPartitionOfUnity⟩ := isSubordinate_toPartitionOfUnity /-- If `f` is a smooth partition of unity on a set `s : Set M` subordinate to a family of open sets `U : ι → Set M` and `g : ι → M → F` is a family of functions such that `g i` is $C^n$ smooth on `U i`, then the sum `fun x ↦ ∑ᶠ i, f i x • g i x` is $C^n$ smooth on the whole manifold. -/ theorem IsSubordinate.contMDiff_finsum_smul {g : ι → M → F} (hf : f.IsSubordinate U) (ho : ∀ i, IsOpen (U i)) (hg : ∀ i, ContMDiffOn I 𝓘(ℝ, F) n (g i) (U i)) : ContMDiff I 𝓘(ℝ, F) n fun x => ∑ᶠ i, f i x • g i x := f.contMDiff_finsum_smul fun i _ hx => (hg i).contMDiffAt <| (ho i).mem_nhds (hf i hx) @[deprecated (since := "2024-11-21")] alias IsSubordinate.smooth_finsum_smul := IsSubordinate.contMDiff_finsum_smul end IsSubordinate end SmoothPartitionOfUnity namespace BumpCovering -- Repeat variables to drop `[FiniteDimensional ℝ E]` and `[IsManifold I ∞ M]` theorem contMDiff_toPartitionOfUnity {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E] {H : Type uH} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type uM} [TopologicalSpace M] [ChartedSpace H M] {s : Set M} (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) (i : ι) : ContMDiff I 𝓘(ℝ) ∞ (f.toPartitionOfUnity i) := (hf i).mul <| (contMDiff_finprod_cond fun j _ => contMDiff_const.sub (hf j)) <| by simp only [Pi.sub_def, mulSupport_one_sub] exact f.locallyFinite @[deprecated (since := "2024-11-21")] alias smooth_toPartitionOfUnity := contMDiff_toPartitionOfUnity variable {s : Set M} /-- A `BumpCovering` such that all functions in this covering are smooth generates a smooth partition of unity. In our formalization, not every `f : BumpCovering ι M s` with smooth functions `f i` is a `SmoothBumpCovering`; instead, a `SmoothBumpCovering` is a covering by supports of `SmoothBumpFunction`s. So, we define `BumpCovering.toSmoothPartitionOfUnity`, then reuse it in `SmoothBumpCovering.toSmoothPartitionOfUnity`. -/ def toSmoothPartitionOfUnity (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) : SmoothPartitionOfUnity ι I M s := { f.toPartitionOfUnity with toFun := fun i => ⟨f.toPartitionOfUnity i, f.contMDiff_toPartitionOfUnity hf i⟩ } @[simp] theorem toSmoothPartitionOfUnity_toPartitionOfUnity (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) : (f.toSmoothPartitionOfUnity hf).toPartitionOfUnity = f.toPartitionOfUnity := rfl @[simp] theorem coe_toSmoothPartitionOfUnity (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) (i : ι) : ⇑(f.toSmoothPartitionOfUnity hf i) = f.toPartitionOfUnity i := rfl theorem IsSubordinate.toSmoothPartitionOfUnity {f : BumpCovering ι M s} {U : ι → Set M} (h : f.IsSubordinate U) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) : (f.toSmoothPartitionOfUnity hf).IsSubordinate U := h.toPartitionOfUnity end BumpCovering namespace SmoothBumpCovering variable [FiniteDimensional ℝ E] variable {s : Set M} {U : M → Set M} (fs : SmoothBumpCovering ι I M s) instance : CoeFun (SmoothBumpCovering ι I M s) fun x => ∀ i : ι, SmoothBumpFunction I (x.c i) := ⟨toFun⟩ /-- We say that `f : SmoothBumpCovering ι I M s` is *subordinate* to a map `U : M → Set M` if for each index `i`, we have `tsupport (f i) ⊆ U (f i).c`. This notion is a bit more general than being subordinate to an open covering of `M`, because we make no assumption about the way `U x` depends on `x`. -/ def IsSubordinate {s : Set M} (f : SmoothBumpCovering ι I M s) (U : M → Set M) := ∀ i, tsupport (f i) ⊆ U (f.c i) theorem IsSubordinate.support_subset {fs : SmoothBumpCovering ι I M s} {U : M → Set M} (h : fs.IsSubordinate U) (i : ι) : support (fs i) ⊆ U (fs.c i) := Subset.trans subset_closure (h i) variable (I) in /-- Let `M` be a smooth manifold modelled on a finite dimensional real vector space. Suppose also that `M` is a Hausdorff `σ`-compact topological space. Let `s` be a closed set in `M` and `U : M → Set M` be a collection of sets such that `U x ∈ 𝓝 x` for every `x ∈ s`. Then there exists a smooth bump covering of `s` that is subordinate to `U`. -/ theorem exists_isSubordinate [T2Space M] [SigmaCompactSpace M] (hs : IsClosed s) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ (ι : Type uM) (f : SmoothBumpCovering ι I M s), f.IsSubordinate U := by -- First we deduce some missing instances haveI : LocallyCompactSpace H := I.locallyCompactSpace haveI : LocallyCompactSpace M := ChartedSpace.locallyCompactSpace H M -- Next we choose a covering by supports of smooth bump functions have hB := fun x hx => SmoothBumpFunction.nhds_basis_support (I := I) (hU x hx) rcases refinement_of_locallyCompact_sigmaCompact_of_nhds_basis_set hs hB with ⟨ι, c, f, hf, hsub', hfin⟩ choose hcs hfU using hf -- Then we use the shrinking lemma to get a covering by smaller open rcases exists_subset_iUnion_closed_subset hs (fun i => (f i).isOpen_support) (fun x _ => hfin.point_finite x) hsub' with ⟨V, hsV, hVc, hVf⟩ choose r hrR hr using fun i => (f i).exists_r_pos_lt_subset_ball (hVc i) (hVf i) refine ⟨ι, ⟨c, fun i => (f i).updateRIn (r i) (hrR i), hcs, ?_, fun x hx => ?_⟩, fun i => ?_⟩ · simpa only [SmoothBumpFunction.support_updateRIn] · refine (mem_iUnion.1 <| hsV hx).imp fun i hi => ?_ exact ((f i).updateRIn _ _).eventuallyEq_one_of_dist_lt ((f i).support_subset_source <| hVf _ hi) (hr i hi).2 · simpa only [SmoothBumpFunction.support_updateRIn, tsupport] using hfU i protected theorem locallyFinite : LocallyFinite fun i => support (fs i) := fs.locallyFinite' protected theorem point_finite (x : M) : {i | fs i x ≠ 0}.Finite := fs.locallyFinite.point_finite x /-- Index of a bump function such that `fs i =ᶠ[𝓝 x] 1`. -/ def ind (x : M) (hx : x ∈ s) : ι := (fs.eventuallyEq_one' x hx).choose theorem eventuallyEq_one (x : M) (hx : x ∈ s) : fs (fs.ind x hx) =ᶠ[𝓝 x] 1 := (fs.eventuallyEq_one' x hx).choose_spec theorem apply_ind (x : M) (hx : x ∈ s) : fs (fs.ind x hx) x = 1 := (fs.eventuallyEq_one x hx).eq_of_nhds theorem mem_support_ind (x : M) (hx : x ∈ s) : x ∈ support (fs <| fs.ind x hx) := by simp [fs.apply_ind x hx] theorem mem_chartAt_source_of_eq_one {i : ι} {x : M} (h : fs i x = 1) : x ∈ (chartAt H (fs.c i)).source := (fs i).support_subset_source <| by simp [h] theorem mem_extChartAt_source_of_eq_one {i : ι} {x : M} (h : fs i x = 1) : x ∈ (extChartAt I (fs.c i)).source := by rw [extChartAt_source]; exact fs.mem_chartAt_source_of_eq_one h theorem mem_chartAt_ind_source (x : M) (hx : x ∈ s) : x ∈ (chartAt H (fs.c (fs.ind x hx))).source := fs.mem_chartAt_source_of_eq_one (fs.apply_ind x hx) theorem mem_extChartAt_ind_source (x : M) (hx : x ∈ s) : x ∈ (extChartAt I (fs.c (fs.ind x hx))).source := fs.mem_extChartAt_source_of_eq_one (fs.apply_ind x hx) /-- The index type of a `SmoothBumpCovering` of a compact manifold is finite. -/ protected def fintype [CompactSpace M] : Fintype ι := fs.locallyFinite.fintypeOfCompact fun i => (fs i).nonempty_support variable [T2Space M] variable [IsManifold I ∞ M] /-- Reinterpret a `SmoothBumpCovering` as a continuous `BumpCovering`. Note that not every `f : BumpCovering ι M s` with smooth functions `f i` is a `SmoothBumpCovering`. -/ def toBumpCovering : BumpCovering ι M s where toFun i := ⟨fs i, (fs i).continuous⟩ locallyFinite' := fs.locallyFinite nonneg' i _ := (fs i).nonneg le_one' i _ := (fs i).le_one eventuallyEq_one' := fs.eventuallyEq_one' @[simp] theorem isSubordinate_toBumpCovering {f : SmoothBumpCovering ι I M s} {U : M → Set M} : (f.toBumpCovering.IsSubordinate fun i => U (f.c i)) ↔ f.IsSubordinate U := Iff.rfl alias ⟨_, IsSubordinate.toBumpCovering⟩ := isSubordinate_toBumpCovering /-- Every `SmoothBumpCovering` defines a smooth partition of unity. -/ def toSmoothPartitionOfUnity : SmoothPartitionOfUnity ι I M s := fs.toBumpCovering.toSmoothPartitionOfUnity fun i => (fs i).contMDiff theorem toSmoothPartitionOfUnity_apply (i : ι) (x : M) : fs.toSmoothPartitionOfUnity i x = fs i x * ∏ᶠ (j) (_ : WellOrderingRel j i), (1 - fs j x) := rfl open Classical in theorem toSmoothPartitionOfUnity_eq_mul_prod (i : ι) (x : M) (t : Finset ι) (ht : ∀ j, WellOrderingRel j i → fs j x ≠ 0 → j ∈ t) : fs.toSmoothPartitionOfUnity i x = fs i x * ∏ j ∈ t with WellOrderingRel j i, (1 - fs j x) := fs.toBumpCovering.toPartitionOfUnity_eq_mul_prod i x t ht open Classical in theorem exists_finset_toSmoothPartitionOfUnity_eventuallyEq (i : ι) (x : M) : ∃ t : Finset ι, fs.toSmoothPartitionOfUnity i =ᶠ[𝓝 x] fs i * ∏ j ∈ t with WellOrderingRel j i, ((1 : M → ℝ) - fs j) := by -- Porting note: was defeq, now the continuous lemma uses bundled homs simpa using fs.toBumpCovering.exists_finset_toPartitionOfUnity_eventuallyEq i x theorem toSmoothPartitionOfUnity_zero_of_zero {i : ι} {x : M} (h : fs i x = 0) : fs.toSmoothPartitionOfUnity i x = 0 := fs.toBumpCovering.toPartitionOfUnity_zero_of_zero h theorem support_toSmoothPartitionOfUnity_subset (i : ι) : support (fs.toSmoothPartitionOfUnity i) ⊆ support (fs i) := fs.toBumpCovering.support_toPartitionOfUnity_subset i theorem IsSubordinate.toSmoothPartitionOfUnity {f : SmoothBumpCovering ι I M s} {U : M → Set M} (h : f.IsSubordinate U) : f.toSmoothPartitionOfUnity.IsSubordinate fun i => U (f.c i) := h.toBumpCovering.toPartitionOfUnity theorem sum_toSmoothPartitionOfUnity_eq (x : M) : ∑ᶠ i, fs.toSmoothPartitionOfUnity i x = 1 - ∏ᶠ i, (1 - fs i x) := fs.toBumpCovering.sum_toPartitionOfUnity_eq x end SmoothBumpCovering variable (I) variable [FiniteDimensional ℝ E] variable [IsManifold I ∞ M] /-- Given two disjoint closed sets `s, t` in a Hausdorff σ-compact finite dimensional manifold, there exists an infinitely smooth function that is equal to `0` on `s` and to `1` on `t`. See also `exists_msmooth_zero_iff_one_iff_of_isClosed`, which ensures additionally that `f` is equal to `0` exactly on `s` and to `1` exactly on `t`. -/ theorem exists_smooth_zero_one_of_isClosed [T2Space M] [SigmaCompactSpace M] {s t : Set M} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯, EqOn f 0 s ∧ EqOn f 1 t ∧ ∀ x, f x ∈ Icc 0 1 := by have : ∀ x ∈ t, sᶜ ∈ 𝓝 x := fun x hx => hs.isOpen_compl.mem_nhds (disjoint_right.1 hd hx) rcases SmoothBumpCovering.exists_isSubordinate I ht this with ⟨ι, f, hf⟩ set g := f.toSmoothPartitionOfUnity refine ⟨⟨_, g.contMDiff_sum⟩, fun x hx => ?_, fun x => g.sum_eq_one, fun x => ⟨g.sum_nonneg x, g.sum_le_one x⟩⟩ suffices ∀ i, g i x = 0 by simp only [this, ContMDiffMap.coeFn_mk, finsum_zero, Pi.zero_apply] refine fun i => f.toSmoothPartitionOfUnity_zero_of_zero ?_ exact nmem_support.1 (subset_compl_comm.1 (hf.support_subset i) hx) /-- Given two disjoint closed sets `s, t` in a Hausdorff normal σ-compact finite dimensional manifold `M`, there exists a smooth function `f : M → [0,1]` that vanishes in a neighbourhood of `s` and is equal to `1` in a neighbourhood of `t`. -/ theorem exists_smooth_zero_one_nhds_of_isClosed [T2Space M] [NormalSpace M] [SigmaCompactSpace M] {s t : Set M} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯, (∀ᶠ x in 𝓝ˢ s, f x = 0) ∧ (∀ᶠ x in 𝓝ˢ t, f x = 1) ∧ ∀ x, f x ∈ Icc 0 1 := by obtain ⟨u, u_op, hsu, hut⟩ := normal_exists_closure_subset hs ht.isOpen_compl (subset_compl_iff_disjoint_left.mpr hd.symm) obtain ⟨v, v_op, htv, hvu⟩ := normal_exists_closure_subset ht isClosed_closure.isOpen_compl (subset_compl_comm.mp hut) obtain ⟨f, hfu, hfv, hf⟩ := exists_smooth_zero_one_of_isClosed I isClosed_closure isClosed_closure (subset_compl_iff_disjoint_left.mp hvu) refine ⟨f, ?_, ?_, hf⟩ · exact eventually_of_mem (mem_of_superset (u_op.mem_nhdsSet.mpr hsu) subset_closure) hfu · exact eventually_of_mem (mem_of_superset (v_op.mem_nhdsSet.mpr htv) subset_closure) hfv /-- Given two sets `s, t` in a Hausdorff normal σ-compact finite-dimensional manifold `M` with `s` open and `s ⊆ interior t`, there is a smooth function `f : M → [0,1]` which is equal to `s` in a neighbourhood of `s` and has support contained in `t`. -/ theorem exists_smooth_one_nhds_of_subset_interior [T2Space M] [NormalSpace M] [SigmaCompactSpace M] {s t : Set M} (hs : IsClosed s) (hd : s ⊆ interior t) : ∃ f : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯, (∀ᶠ x in 𝓝ˢ s, f x = 1) ∧ (∀ x ∉ t, f x = 0) ∧ ∀ x, f x ∈ Icc 0 1 := by rcases exists_smooth_zero_one_nhds_of_isClosed I isOpen_interior.isClosed_compl hs (by rwa [← subset_compl_iff_disjoint_left, compl_compl]) with ⟨f, h0, h1, hf⟩ refine ⟨f, h1, fun x hx ↦ ?_, hf⟩ exact h0.self_of_nhdsSet _ fun hx' ↦ hx <| interior_subset hx' namespace SmoothPartitionOfUnity /-- A `SmoothPartitionOfUnity` that consists of a single function, uniformly equal to one, defined as an example for `Inhabited` instance. -/ def single (i : ι) (s : Set M) : SmoothPartitionOfUnity ι I M s := (BumpCovering.single i s).toSmoothPartitionOfUnity fun j => by classical rcases eq_or_ne j i with (rfl | h) · simp only [contMDiff_one, ContinuousMap.coe_one, BumpCovering.coe_single, Pi.single_eq_same] · simp only [contMDiff_zero, BumpCovering.coe_single, Pi.single_eq_of_ne h, ContinuousMap.coe_zero] instance [Inhabited ι] (s : Set M) : Inhabited (SmoothPartitionOfUnity ι I M s) := ⟨single I default s⟩ variable [T2Space M] [SigmaCompactSpace M] /-- If `X` is a paracompact normal topological space and `U` is an open covering of a closed set `s`, then there exists a `SmoothPartitionOfUnity ι M s` that is subordinate to `U`. -/ theorem exists_isSubordinate {s : Set M} (hs : IsClosed s) (U : ι → Set M) (ho : ∀ i, IsOpen (U i)) (hU : s ⊆ ⋃ i, U i) : ∃ f : SmoothPartitionOfUnity ι I M s, f.IsSubordinate U := by haveI : LocallyCompactSpace H := I.locallyCompactSpace haveI : LocallyCompactSpace M := ChartedSpace.locallyCompactSpace H M -- porting note(https://github.com/leanprover/std4/issues/116): -- split `rcases` into `have` + `rcases` have := BumpCovering.exists_isSubordinate_of_prop (ContMDiff I 𝓘(ℝ) ∞) ?_ hs U ho hU · rcases this with ⟨f, hf, hfU⟩ exact ⟨f.toSmoothPartitionOfUnity hf, hfU.toSmoothPartitionOfUnity hf⟩ · intro s t hs ht hd rcases exists_smooth_zero_one_of_isClosed I hs ht hd with ⟨f, hf⟩ exact ⟨f, f.contMDiff, hf⟩ theorem exists_isSubordinate_chartAt_source_of_isClosed {s : Set M} (hs : IsClosed s) : ∃ f : SmoothPartitionOfUnity s I M s, f.IsSubordinate (fun x ↦ (chartAt H (x : M)).source) := by apply exists_isSubordinate _ hs _ (fun i ↦ (chartAt H _).open_source) (fun x hx ↦ ?_) exact mem_iUnion_of_mem ⟨x, hx⟩ (mem_chart_source H x) variable (M) theorem exists_isSubordinate_chartAt_source : ∃ f : SmoothPartitionOfUnity M I M univ, f.IsSubordinate (fun x ↦ (chartAt H x).source) := by apply exists_isSubordinate _ isClosed_univ _ (fun i ↦ (chartAt H _).open_source) (fun x _ ↦ ?_) exact mem_iUnion_of_mem x (mem_chart_source H x) end SmoothPartitionOfUnity variable [SigmaCompactSpace M] [T2Space M] {t : M → Set F} {n : ℕ∞} /-- Let `M` be a σ-compact Hausdorff finite dimensional topological manifold. Let `t : M → Set F` be a family of convex sets. Suppose that for each point `x : M` there exists a neighborhood `U ∈ 𝓝 x` and a function `g : M → F` such that `g` is $C^n$ smooth on `U` and `g y ∈ t y` for all `y ∈ U`. Then there exists a $C^n$ smooth function `g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯` such that `g x ∈ t x` for all `x`. See also `exists_smooth_forall_mem_convex_of_local` and `exists_smooth_forall_mem_convex_of_local_const`. -/ theorem exists_contMDiffOn_forall_mem_convex_of_local (ht : ∀ x, Convex ℝ (t x)) (Hloc : ∀ x : M, ∃ U ∈ 𝓝 x, ∃ g : M → F, ContMDiffOn I 𝓘(ℝ, F) n g U ∧ ∀ y ∈ U, g y ∈ t y) : ∃ g : C^n⟮I, M; 𝓘(ℝ, F), F⟯, ∀ x, g x ∈ t x := by choose U hU g hgs hgt using Hloc obtain ⟨f, hf⟩ := SmoothPartitionOfUnity.exists_isSubordinate I isClosed_univ (fun x => interior (U x)) (fun x => isOpen_interior) fun x _ => mem_iUnion.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x)⟩ refine ⟨⟨fun x => ∑ᶠ i, f i x • g i x, hf.contMDiff_finsum_smul (fun i => isOpen_interior) fun i => (hgs i).mono interior_subset⟩, fun x => f.finsum_smul_mem_convex (mem_univ x) (fun i hi => hgt _ _ ?_) (ht _)⟩ exact interior_subset (hf _ <| subset_closure hi) /-- Let `M` be a σ-compact Hausdorff finite dimensional topological manifold. Let `t : M → Set F` be a family of convex sets. Suppose that for each point `x : M` there exists a neighborhood `U ∈ 𝓝 x` and a function `g : M → F` such that `g` is smooth on `U` and `g y ∈ t y` for all `y ∈ U`. Then there exists a smooth function `g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯` such that `g x ∈ t x` for all `x`. See also `exists_contMDiffOn_forall_mem_convex_of_local` and `exists_smooth_forall_mem_convex_of_local_const`. -/ theorem exists_smooth_forall_mem_convex_of_local (ht : ∀ x, Convex ℝ (t x)) (Hloc : ∀ x : M, ∃ U ∈ 𝓝 x, ∃ g : M → F, ContMDiffOn I 𝓘(ℝ, F) ∞ g U ∧ ∀ y ∈ U, g y ∈ t y) : ∃ g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯, ∀ x, g x ∈ t x := exists_contMDiffOn_forall_mem_convex_of_local I ht Hloc /-- Let `M` be a σ-compact Hausdorff finite dimensional topological manifold. Let `t : M → Set F` be a family of convex sets. Suppose that for each point `x : M` there exists a vector `c : F` such that for all `y` in a neighborhood of `x` we have `c ∈ t y`. Then there exists a smooth function `g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯` such that `g x ∈ t x` for all `x`. See also `exists_contMDiffOn_forall_mem_convex_of_local` and `exists_smooth_forall_mem_convex_of_local`. -/ theorem exists_smooth_forall_mem_convex_of_local_const (ht : ∀ x, Convex ℝ (t x)) (Hloc : ∀ x : M, ∃ c : F, ∀ᶠ y in 𝓝 x, c ∈ t y) : ∃ g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯, ∀ x, g x ∈ t x := exists_smooth_forall_mem_convex_of_local I ht fun x => let ⟨c, hc⟩ := Hloc x ⟨_, hc, fun _ => c, contMDiffOn_const, fun _ => id⟩ /-- Let `M` be a smooth σ-compact manifold with extended distance. Let `K : ι → Set M` be a locally finite family of closed sets, let `U : ι → Set M` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive smooth function `δ : M → ℝ≥0` such that for any `i` and `x ∈ K i`, we have `EMetric.closedBall x (δ x) ⊆ U i`. -/ theorem Emetric.exists_smooth_forall_closedBall_subset {M} [EMetricSpace M] [ChartedSpace H M] [IsManifold I ∞ M] [SigmaCompactSpace M] {K : ι → Set M} {U : ι → Set M} (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C^∞⟮I, M; 𝓘(ℝ, ℝ), ℝ⟯, (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, EMetric.closedBall x (ENNReal.ofReal (δ x)) ⊆ U i := by simpa only [mem_inter_iff, forall_and, mem_preimage, mem_iInter, @forall_swap ι M] using exists_smooth_forall_mem_convex_of_local_const I EMetric.exists_forall_closedBall_subset_aux₂ (EMetric.exists_forall_closedBall_subset_aux₁ hK hU hKU hfin) /-- Let `M` be a smooth σ-compact manifold with a metric. Let `K : ι → Set M` be a locally finite family of closed sets, let `U : ι → Set M` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive smooth function `δ : M → ℝ≥0` such that for any `i` and `x ∈ K i`, we have `Metric.closedBall x (δ x) ⊆ U i`. -/ theorem Metric.exists_smooth_forall_closedBall_subset {M} [MetricSpace M] [ChartedSpace H M] [IsManifold I ∞ M] [SigmaCompactSpace M] {K : ι → Set M} {U : ι → Set M} (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C^∞⟮I, M; 𝓘(ℝ, ℝ), ℝ⟯, (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, Metric.closedBall x (δ x) ⊆ U i := by rcases Emetric.exists_smooth_forall_closedBall_subset I hK hU hKU hfin with ⟨δ, hδ0, hδ⟩ refine ⟨δ, hδ0, fun i x hx => ?_⟩ rw [← Metric.emetric_closedBall (hδ0 _).le] exact hδ i x hx lemma IsOpen.exists_msmooth_support_eq_aux {s : Set H} (hs : IsOpen s) : ∃ f : H → ℝ, f.support = s ∧ ContMDiff I 𝓘(ℝ) ∞ f ∧ Set.range f ⊆ Set.Icc 0 1 := by have h's : IsOpen (I.symm ⁻¹' s) := I.continuous_symm.isOpen_preimage _ hs rcases h's.exists_smooth_support_eq with ⟨f, f_supp, f_diff, f_range⟩ refine ⟨f ∘ I, ?_, ?_, ?_⟩ · rw [support_comp_eq_preimage, f_supp, ← preimage_comp] simp only [ModelWithCorners.symm_comp_self, preimage_id_eq, id_eq] · exact f_diff.comp_contMDiff contMDiff_model · exact Subset.trans (range_comp_subset_range _ _) f_range /-- Given an open set in a finite-dimensional real manifold, there exists a nonnegative smooth function with support equal to `s`. -/ theorem IsOpen.exists_msmooth_support_eq {s : Set M} (hs : IsOpen s) : ∃ f : M → ℝ, f.support = s ∧ ContMDiff I 𝓘(ℝ) ∞ f ∧ ∀ x, 0 ≤ f x := by rcases SmoothPartitionOfUnity.exists_isSubordinate_chartAt_source I M with ⟨f, hf⟩ have A : ∀ (c : M), ∃ g : H → ℝ, g.support = (chartAt H c).target ∩ (chartAt H c).symm ⁻¹' s ∧ ContMDiff I 𝓘(ℝ) ∞ g ∧ Set.range g ⊆ Set.Icc 0 1 := by intro i apply IsOpen.exists_msmooth_support_eq_aux exact PartialHomeomorph.isOpen_inter_preimage_symm _ hs choose g g_supp g_diff hg using A have h'g : ∀ c x, 0 ≤ g c x := fun c x ↦ (hg c (mem_range_self (f := g c) x)).1 have h''g : ∀ c x, 0 ≤ f c x * g c (chartAt H c x) := fun c x ↦ mul_nonneg (f.nonneg c x) (h'g c _) refine ⟨fun x ↦ ∑ᶠ c, f c x * g c (chartAt H c x), ?_, ?_, ?_⟩ · refine support_eq_iff.2 ⟨fun x hx ↦ ?_, fun x hx ↦ ?_⟩ · apply ne_of_gt have B : ∃ c, 0 < f c x * g c (chartAt H c x) := by obtain ⟨c, hc⟩ : ∃ c, 0 < f c x := f.exists_pos_of_mem (mem_univ x) refine ⟨c, mul_pos hc ?_⟩ apply lt_of_le_of_ne (h'g _ _) (Ne.symm _) rw [← mem_support, g_supp, ← mem_preimage, preimage_inter] have Hx : x ∈ tsupport (f c) := subset_tsupport _ (ne_of_gt hc) simp [(chartAt H c).left_inv (hf c Hx), hx, (chartAt H c).map_source (hf c Hx)] apply finsum_pos' (fun c ↦ h''g c x) B apply (f.locallyFinite.point_finite x).subset apply compl_subset_compl.2 rintro c (hc : f c x = 0) simpa only [mul_eq_zero] using Or.inl hc · apply finsum_eq_zero_of_forall_eq_zero intro c by_cases Hx : x ∈ tsupport (f c) · suffices g c (chartAt H c x) = 0 by simp only [this, mul_zero] rw [← nmem_support, g_supp, ← mem_preimage, preimage_inter] contrapose! hx simp only [mem_inter_iff, mem_preimage, (chartAt H c).left_inv (hf c Hx)] at hx exact hx.2 · have : x ∉ support (f c) := by contrapose! Hx; exact subset_tsupport _ Hx rw [nmem_support] at this simp [this] · apply SmoothPartitionOfUnity.contMDiff_finsum_smul intro c x hx apply (g_diff c (chartAt H c x)).comp exact contMDiffAt_of_mem_maximalAtlas (IsManifold.chart_mem_maximalAtlas _) (hf c hx) · intro x apply finsum_nonneg (fun c ↦ h''g c x) /-- Given an open set `s` containing a closed set `t` in a finite-dimensional real manifold, there exists a smooth function with support equal to `s`, taking values in `[0,1]`, and equal to `1` exactly on `t`. -/ theorem exists_msmooth_support_eq_eq_one_iff {s t : Set M} (hs : IsOpen s) (ht : IsClosed t) (h : t ⊆ s) : ∃ f : M → ℝ, ContMDiff I 𝓘(ℝ) ∞ f ∧ range f ⊆ Icc 0 1 ∧ support f = s ∧ (∀ x, x ∈ t ↔ f x = 1) := by /- Take `f` with support equal to `s`, and `g` with support equal to `tᶜ`. Then `f / (f + g)` satisfies the conclusion of the theorem. -/ rcases hs.exists_msmooth_support_eq I with ⟨f, f_supp, f_diff, f_pos⟩ rcases ht.isOpen_compl.exists_msmooth_support_eq I with ⟨g, g_supp, g_diff, g_pos⟩ have A : ∀ x, 0 < f x + g x := by intro x by_cases xs : x ∈ support f · have : 0 < f x := lt_of_le_of_ne (f_pos x) (Ne.symm xs) linarith [g_pos x] · have : 0 < g x := by classical apply lt_of_le_of_ne (g_pos x) (Ne.symm ?_) rw [← mem_support, g_supp] contrapose! xs simp? at xs says simp only [mem_compl_iff, Decidable.not_not] at xs exact h.trans f_supp.symm.subset xs linarith [f_pos x] refine ⟨fun x ↦ f x / (f x + g x), ?_, ?_, ?_, ?_⟩ -- show that `f / (f + g)` is smooth · exact f_diff.div₀ (f_diff.add g_diff) (fun x ↦ ne_of_gt (A x)) -- show that the range is included in `[0, 1]` · refine range_subset_iff.2 (fun x ↦ ⟨div_nonneg (f_pos x) (A x).le, ?_⟩) apply div_le_one_of_le₀ _ (A x).le simpa only [le_add_iff_nonneg_right] using g_pos x -- show that the support is `s` · have B : support (fun x ↦ f x + g x) = univ := eq_univ_of_forall (fun x ↦ (A x).ne') simp only [support_div, f_supp, B, inter_univ] -- show that the function equals one exactly on `t` · intro x simp [div_eq_one_iff_eq (A x).ne', left_eq_add, ← nmem_support, g_supp] /-- Given two disjoint closed sets `s, t` in a Hausdorff σ-compact finite dimensional manifold, there exists an infinitely smooth function that is equal to `0` exactly on `s` and to `1` exactly on `t`. See also `exists_smooth_zero_one_of_isClosed` for a slightly weaker version. -/ theorem exists_msmooth_zero_iff_one_iff_of_isClosed {s t : Set M} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : M → ℝ, ContMDiff I 𝓘(ℝ) ∞ f ∧ range f ⊆ Icc 0 1 ∧ (∀ x, x ∈ s ↔ f x = 0) ∧ (∀ x, x ∈ t ↔ f x = 1) := by rcases exists_msmooth_support_eq_eq_one_iff I hs.isOpen_compl ht hd.subset_compl_left with ⟨f, f_diff, f_range, fs, ft⟩ refine ⟨f, f_diff, f_range, ?_, ft⟩ simp [← nmem_support, fs]
Mathlib/Geometry/Manifold/PartitionOfUnity.lean
787
819
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Geometry.Euclidean.Projection import Mathlib.Geometry.Euclidean.Sphere.Basic import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Tactic.DeriveFintype /-! # Circumcenter and circumradius This file proves some lemmas on points equidistant from a set of points, and defines the circumradius and circumcenter of a simplex. There are also some definitions for use in calculations where it is convenient to work with affine combinations of vertices together with the circumcenter. ## Main definitions * `circumcenter` and `circumradius` are the circumcenter and circumradius of a simplex. ## References * https://en.wikipedia.org/wiki/Circumscribed_circle -/ noncomputable section open RealInnerProductSpace namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] open AffineSubspace /-- The induction step for the existence and uniqueness of the circumcenter. Given a nonempty set of points in a nonempty affine subspace whose direction is complete, such that there is a unique (circumcenter, circumradius) pair for those points in that subspace, and a point `p` not in that subspace, there is a unique (circumcenter, circumradius) pair for the set with `p` added, in the span of the subspace with `p` added. -/ theorem existsUnique_dist_eq_of_insert {s : AffineSubspace ℝ P} [s.direction.HasOrthogonalProjection] {ps : Set P} (hnps : ps.Nonempty) {p : P} (hps : ps ⊆ s) (hp : p ∉ s) (hu : ∃! cs : Sphere P, cs.center ∈ s ∧ ps ⊆ (cs : Set P)) : ∃! cs₂ : Sphere P, cs₂.center ∈ affineSpan ℝ (insert p (s : Set P)) ∧ insert p ps ⊆ (cs₂ : Set P) := by haveI : Nonempty s := Set.Nonempty.to_subtype (hnps.mono hps) rcases hu with ⟨⟨cc, cr⟩, ⟨hcc, hcr⟩, hcccru⟩ simp only at hcc hcr hcccru let x := dist cc (orthogonalProjection s p) let y := dist p (orthogonalProjection s p) have hy0 : y ≠ 0 := dist_orthogonalProjection_ne_zero_of_not_mem hp let ycc₂ := (x * x + y * y - cr * cr) / (2 * y) let cc₂ := (ycc₂ / y) • (p -ᵥ orthogonalProjection s p : V) +ᵥ cc let cr₂ := √(cr * cr + ycc₂ * ycc₂) use ⟨cc₂, cr₂⟩ simp -zeta -proj only have hpo : p = (1 : ℝ) • (p -ᵥ orthogonalProjection s p : V) +ᵥ (orthogonalProjection s p : P) := by simp constructor · constructor · refine vadd_mem_of_mem_direction ?_ (mem_affineSpan ℝ (Set.mem_insert_of_mem _ hcc)) rw [direction_affineSpan] exact Submodule.smul_mem _ _ (vsub_mem_vectorSpan ℝ (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (orthogonalProjection_mem _))) · intro p₁ hp₁ rw [Sphere.mem_coe, mem_sphere, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] rcases hp₁ with hp₁ | hp₁ · rw [hp₁] rw [hpo, dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s p), ← dist_eq_norm_vsub V p, dist_comm _ cc] -- TODO(https://github.com/leanprover-community/mathlib4/issues/15486): used to be `field_simp`, but was really slow -- replaced by `simp only ...` to speed up. Reinstate `field_simp` once it is faster. simp (disch := field_simp_discharge) only [div_div, sub_div', one_mul, mul_div_assoc', div_mul_eq_mul_div, add_div', eq_div_iff, div_eq_iff, ycc₂] ring · rw [dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp₁), orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc, Subtype.coe_mk, dist_of_mem_subset_mk_sphere hp₁ hcr, dist_eq_norm_vsub V cc₂ cc, vadd_vsub, norm_smul, ← dist_eq_norm_vsub V, Real.norm_eq_abs, abs_div, abs_of_nonneg dist_nonneg, div_mul_cancel₀ _ hy0, abs_mul_abs_self] · rintro ⟨cc₃, cr₃⟩ ⟨hcc₃, hcr₃⟩ simp only at hcc₃ hcr₃ obtain ⟨t₃, cc₃', hcc₃', hcc₃''⟩ : ∃ r : ℝ, ∃ p0 ∈ s, cc₃ = r • (p -ᵥ ↑((orthogonalProjection s) p)) +ᵥ p0 := by rwa [mem_affineSpan_insert_iff (orthogonalProjection_mem p)] at hcc₃ have hcr₃' : ∃ r, ∀ p₁ ∈ ps, dist p₁ cc₃ = r := ⟨cr₃, fun p₁ hp₁ => dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp₁) hcr₃⟩ rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq hps cc₃, hcc₃'', orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃'] at hcr₃' obtain ⟨cr₃', hcr₃'⟩ := hcr₃' have hu := hcccru ⟨cc₃', cr₃'⟩ simp only at hu replace hu := hu ⟨hcc₃', hcr₃'⟩ -- Porting note: was -- cases' hu with hucc hucr -- substs hucc hucr cases hu have hcr₃val : cr₃ = √(cr * cr + t₃ * y * (t₃ * y)) := by obtain ⟨p0, hp0⟩ := hnps have h' : ↑(⟨cc, hcc₃'⟩ : s) = cc := rfl rw [← dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp0) hcr₃, hcc₃'', ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)), dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp0), orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃', h', dist_of_mem_subset_mk_sphere hp0 hcr, dist_eq_norm_vsub V _ cc, vadd_vsub, norm_smul, ← dist_eq_norm_vsub V p, Real.norm_eq_abs, ← mul_assoc, mul_comm _ |t₃|, ← mul_assoc, abs_mul_abs_self] ring replace hcr₃ := dist_of_mem_subset_mk_sphere (Set.mem_insert _ _) hcr₃ rw [hpo, hcc₃'', hcr₃val, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc₃' _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s p), dist_comm, ← dist_eq_norm_vsub V p, Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] at hcr₃ change x * x + _ * (y * y) = _ at hcr₃ rw [show x * x + (1 - t₃) * (1 - t₃) * (y * y) = x * x + y * y - 2 * y * (t₃ * y) + t₃ * y * (t₃ * y) by ring, add_left_inj] at hcr₃ have ht₃ : t₃ = ycc₂ / y := by field_simp [ycc₂, ← hcr₃, hy0] subst ht₃ change cc₃ = cc₂ at hcc₃'' congr rw [hcr₃val] congr 2 field_simp [hy0] /-- Given a finite nonempty affinely independent family of points, there is a unique (circumcenter, circumradius) pair for those points in the affine subspace they span. -/ theorem _root_.AffineIndependent.existsUnique_dist_eq {ι : Type*} [hne : Nonempty ι] [Finite ι] {p : ι → P} (ha : AffineIndependent ℝ p) : ∃! cs : Sphere P, cs.center ∈ affineSpan ℝ (Set.range p) ∧ Set.range p ⊆ (cs : Set P) := by cases nonempty_fintype ι induction' hn : Fintype.card ι with m hm generalizing ι · exfalso have h := Fintype.card_pos_iff.2 hne rw [hn] at h exact lt_irrefl 0 h · rcases m with - | m · rw [Fintype.card_eq_one_iff] at hn obtain ⟨i, hi⟩ := hn haveI : Unique ι := ⟨⟨i⟩, hi⟩ use ⟨p i, 0⟩ simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton] constructor · simp_rw [hi default, Set.singleton_subset_iff] exact ⟨⟨⟩, by simp only [Metric.sphere_zero, Set.mem_singleton_iff]⟩ · rintro ⟨cc, cr⟩ simp only rintro ⟨rfl, hdist⟩ simp? [Set.singleton_subset_iff] at hdist says simp only [Set.singleton_subset_iff, Metric.mem_sphere, dist_self] at hdist rw [hi default, hdist] · have i := hne.some let ι2 := { x // x ≠ i } classical have hc : Fintype.card ι2 = m + 1 := by rw [Fintype.card_of_subtype {x | x ≠ i}] · rw [Finset.filter_not] -- Porting note: removed `simp_rw [eq_comm]` and used `filter_eq'` instead of `filter_eq` rw [Finset.filter_eq' _ i, if_pos (Finset.mem_univ _), Finset.card_sdiff (Finset.subset_univ _), Finset.card_singleton, Finset.card_univ, hn] simp · simp haveI : Nonempty ι2 := Fintype.card_pos_iff.1 (hc.symm ▸ Nat.zero_lt_succ _) have ha2 : AffineIndependent ℝ fun i2 : ι2 => p i2 := ha.subtype _ replace hm := hm ha2 _ hc have hr : Set.range p = insert (p i) (Set.range fun i2 : ι2 => p i2) := by change _ = insert _ (Set.range fun i2 : { x | x ≠ i } => p i2) rw [← Set.image_eq_range, ← Set.image_univ, ← Set.image_insert_eq] congr with j simp [Classical.em] rw [hr, ← affineSpan_insert_affineSpan] refine existsUnique_dist_eq_of_insert (Set.range_nonempty _) (subset_affineSpan ℝ _) ?_ hm convert ha.not_mem_affineSpan_diff i Set.univ change (Set.range fun i2 : { x | x ≠ i } => p i2) = _ rw [← Set.image_eq_range] congr with j simp end EuclideanGeometry namespace Affine namespace Simplex open Finset AffineSubspace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The circumsphere of a simplex. -/ def circumsphere {n : ℕ} (s : Simplex ℝ P n) : Sphere P := s.independent.existsUnique_dist_eq.choose /-- The property satisfied by the circumsphere. -/ theorem circumsphere_unique_dist_eq {n : ℕ} (s : Simplex ℝ P n) : (s.circumsphere.center ∈ affineSpan ℝ (Set.range s.points) ∧ Set.range s.points ⊆ s.circumsphere) ∧ ∀ cs : Sphere P, cs.center ∈ affineSpan ℝ (Set.range s.points) ∧ Set.range s.points ⊆ cs → cs = s.circumsphere := s.independent.existsUnique_dist_eq.choose_spec /-- The circumcenter of a simplex. -/ def circumcenter {n : ℕ} (s : Simplex ℝ P n) : P := s.circumsphere.center /-- The circumradius of a simplex. -/ def circumradius {n : ℕ} (s : Simplex ℝ P n) : ℝ := s.circumsphere.radius /-- The center of the circumsphere is the circumcenter. -/ @[simp] theorem circumsphere_center {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.center = s.circumcenter := rfl /-- The radius of the circumsphere is the circumradius. -/ @[simp] theorem circumsphere_radius {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.radius = s.circumradius := rfl /-- The circumcenter lies in the affine span. -/ theorem circumcenter_mem_affineSpan {n : ℕ} (s : Simplex ℝ P n) : s.circumcenter ∈ affineSpan ℝ (Set.range s.points) := s.circumsphere_unique_dist_eq.1.1 /-- All points have distance from the circumcenter equal to the circumradius. -/ @[simp] theorem dist_circumcenter_eq_circumradius {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : dist (s.points i) s.circumcenter = s.circumradius := dist_of_mem_subset_sphere (Set.mem_range_self _) s.circumsphere_unique_dist_eq.1.2 /-- All points lie in the circumsphere. -/ theorem mem_circumsphere {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.points i ∈ s.circumsphere := s.dist_circumcenter_eq_circumradius i /-- All points have distance to the circumcenter equal to the circumradius. -/ @[simp] theorem dist_circumcenter_eq_circumradius' {n : ℕ} (s : Simplex ℝ P n) : ∀ i, dist s.circumcenter (s.points i) = s.circumradius := by intro i rw [dist_comm] exact dist_circumcenter_eq_circumradius _ _ /-- Given a point in the affine span from which all the points are equidistant, that point is the circumcenter. -/ theorem eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : p = s.circumcenter := by have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩ simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and] at h -- Porting note: added the next three lines (`simp` less powerful) rw [subset_sphere (s := ⟨p, r⟩)] at h simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and] at h exact h.1 /-- Given a point in the affine span from which all the points are equidistant, that distance is the circumradius. -/ theorem eq_circumradius_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : r = s.circumradius := by have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩ simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere] at h -- Porting note: added the next three lines (`simp` less powerful) rw [subset_sphere (s := ⟨p, r⟩)] at h simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and] at h exact h.2 /-- The circumradius is non-negative. -/ theorem circumradius_nonneg {n : ℕ} (s : Simplex ℝ P n) : 0 ≤ s.circumradius := s.dist_circumcenter_eq_circumradius 0 ▸ dist_nonneg /-- The circumradius of a simplex with at least two points is positive. -/ theorem circumradius_pos {n : ℕ} (s : Simplex ℝ P (n + 1)) : 0 < s.circumradius := by refine lt_of_le_of_ne s.circumradius_nonneg ?_ intro h have hr := s.dist_circumcenter_eq_circumradius simp_rw [← h, dist_eq_zero] at hr have h01 := s.independent.injective.ne (by simp : (0 : Fin (n + 2)) ≠ 1) simp [hr] at h01 /-- The circumcenter of a 0-simplex equals its unique point. -/ theorem circumcenter_eq_point (s : Simplex ℝ P 0) (i : Fin 1) : s.circumcenter = s.points i := by have h := s.circumcenter_mem_affineSpan have : Unique (Fin 1) := ⟨⟨0, by decide⟩, fun a => by simp only [Fin.eq_zero]⟩ simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton] at h rw [h] congr simp only [eq_iff_true_of_subsingleton] /-- The circumcenter of a 1-simplex equals its centroid. -/ theorem circumcenter_eq_centroid (s : Simplex ℝ P 1) : s.circumcenter = Finset.univ.centroid ℝ s.points := by have hr : Set.Pairwise Set.univ fun i j : Fin 2 => dist (s.points i) (Finset.univ.centroid ℝ s.points) = dist (s.points j) (Finset.univ.centroid ℝ s.points) := by intro i hi j hj hij rw [Finset.centroid_pair_fin, dist_eq_norm_vsub V (s.points i), dist_eq_norm_vsub V (s.points j), vsub_vadd_eq_vsub_sub, vsub_vadd_eq_vsub_sub, ← one_smul ℝ (s.points i -ᵥ s.points 0), ← one_smul ℝ (s.points j -ᵥ s.points 0)] fin_cases i <;> fin_cases j <;> simp [-one_smul, ← sub_smul] <;> norm_num rw [Set.pairwise_eq_iff_exists_eq] at hr obtain ⟨r, hr⟩ := hr exact (s.eq_circumcenter_of_dist_eq (centroid_mem_affineSpan_of_card_eq_add_one ℝ _ (Finset.card_fin 2)) fun i => hr i (Set.mem_univ _)).symm /-- Reindexing a simplex along an `Equiv` of index types does not change the circumsphere. -/ @[simp] theorem circumsphere_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumsphere = s.circumsphere := by refine s.circumsphere_unique_dist_eq.2 _ ⟨?_, ?_⟩ <;> rw [← s.reindex_range_points e] · exact (s.reindex e).circumsphere_unique_dist_eq.1.1 · exact (s.reindex e).circumsphere_unique_dist_eq.1.2 /-- Reindexing a simplex along an `Equiv` of index types does not change the circumcenter. -/ @[simp] theorem circumcenter_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumcenter = s.circumcenter := by simp_rw [circumcenter, circumsphere_reindex] /-- Reindexing a simplex along an `Equiv` of index types does not change the circumradius. -/ @[simp] theorem circumradius_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumradius = s.circumradius := by simp_rw [circumradius, circumsphere_reindex] attribute [local instance] AffineSubspace.toAddTorsor theorem dist_circumcenter_sq_eq_sq_sub_circumradius {n : ℕ} {r : ℝ} (s : Simplex ℝ P n) {p₁ : P} (h₁ : ∀ i : Fin (n + 1), dist (s.points i) p₁ = r) (h₁' : ↑(s.orthogonalProjectionSpan p₁) = s.circumcenter) (h : s.points 0 ∈ affineSpan ℝ (Set.range s.points)) : dist p₁ s.circumcenter * dist p₁ s.circumcenter = r * r - s.circumradius * s.circumradius := by rw [dist_comm, ← h₁ 0, s.dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p₁ h] simp only [h₁', dist_comm p₁, add_sub_cancel_left, Simplex.dist_circumcenter_eq_circumradius] /-- If there exists a distance that a point has from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ theorem orthogonalProjection_eq_circumcenter_of_exists_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hr : ∃ r, ∀ i, dist (s.points i) p = r) : ↑(s.orthogonalProjectionSpan p) = s.circumcenter := by change ∃ r : ℝ, ∀ i, (fun x => dist x p = r) (s.points i) at hr have hr : ∃ (r : ℝ), ∀ (a : P), a ∈ Set.range (fun (i : Fin (n + 1)) => s.points i) → dist a p = r := by obtain ⟨r, hr⟩ := hr use r refine Set.forall_mem_range.mpr ?_ exact hr rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq (subset_affineSpan ℝ _) p] at hr obtain ⟨r, hr⟩ := hr exact s.eq_circumcenter_of_dist_eq (orthogonalProjection_mem p) fun i => hr _ (Set.mem_range_self i) /-- If a point has the same distance from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ theorem orthogonalProjection_eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : ↑(s.orthogonalProjectionSpan p) = s.circumcenter := s.orthogonalProjection_eq_circumcenter_of_exists_dist_eq ⟨r, hr⟩ /-- The orthogonal projection of the circumcenter onto a face is the circumcenter of that face. -/ theorem orthogonalProjection_circumcenter {n : ℕ} (s : Simplex ℝ P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : #fs = m + 1) : ↑((s.face h).orthogonalProjectionSpan s.circumcenter) = (s.face h).circumcenter := haveI hr : ∃ r, ∀ i, dist ((s.face h).points i) s.circumcenter = r := by use s.circumradius simp [face_points] orthogonalProjection_eq_circumcenter_of_exists_dist_eq _ hr /-- Two simplices with the same points have the same circumcenter. -/ theorem circumcenter_eq_of_range_eq {n : ℕ} {s₁ s₂ : Simplex ℝ P n} (h : Set.range s₁.points = Set.range s₂.points) : s₁.circumcenter = s₂.circumcenter := by have hs : s₁.circumcenter ∈ affineSpan ℝ (Set.range s₂.points) := h ▸ s₁.circumcenter_mem_affineSpan have hr : ∀ i, dist (s₂.points i) s₁.circumcenter = s₁.circumradius := by intro i have hi : s₂.points i ∈ Set.range s₂.points := Set.mem_range_self _ rw [← h, Set.mem_range] at hi rcases hi with ⟨j, hj⟩ rw [← hj, s₁.dist_circumcenter_eq_circumradius j] exact s₂.eq_circumcenter_of_dist_eq hs hr /-- An index type for the vertices of a simplex plus its circumcenter. This is for use in calculations where it is convenient to work with affine combinations of vertices together with the circumcenter. (An equivalent form sometimes used in the literature is placing the circumcenter at the origin and working with vectors for the vertices.) -/ inductive PointsWithCircumcenterIndex (n : ℕ) | pointIndex : Fin (n + 1) → PointsWithCircumcenterIndex n | circumcenterIndex : PointsWithCircumcenterIndex n deriving Fintype open PointsWithCircumcenterIndex instance pointsWithCircumcenterIndexInhabited (n : ℕ) : Inhabited (PointsWithCircumcenterIndex n) := ⟨circumcenterIndex⟩ /-- `pointIndex` as an embedding. -/ def pointIndexEmbedding (n : ℕ) : Fin (n + 1) ↪ PointsWithCircumcenterIndex n := ⟨fun i => pointIndex i, fun _ _ h => by injection h⟩ /-- The sum of a function over `PointsWithCircumcenterIndex`. -/ theorem sum_pointsWithCircumcenter {α : Type*} [AddCommMonoid α] {n : ℕ} (f : PointsWithCircumcenterIndex n → α) : ∑ i, f i = (∑ i : Fin (n + 1), f (pointIndex i)) + f circumcenterIndex := by classical have h : univ = insert circumcenterIndex (univ.map (pointIndexEmbedding n)) := by ext x refine ⟨fun h => ?_, fun _ => mem_univ _⟩ obtain i | - := x · exact mem_insert_of_mem (mem_map_of_mem _ (mem_univ i)) · exact mem_insert_self _ _ change _ = (∑ i, f (pointIndexEmbedding n i)) + _ rw [add_comm, h, ← sum_map, sum_insert] simp_rw [Finset.mem_map, not_exists] rintro x ⟨_, h⟩ injection h /-- The vertices of a simplex plus its circumcenter. -/ def pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) : PointsWithCircumcenterIndex n → P | pointIndex i => s.points i | circumcenterIndex => s.circumcenter /-- `pointsWithCircumcenter`, applied to a `pointIndex` value, equals `points` applied to that value. -/ @[simp] theorem pointsWithCircumcenter_point {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.pointsWithCircumcenter (pointIndex i) = s.points i := rfl /-- `pointsWithCircumcenter`, applied to `circumcenterIndex`, equals the circumcenter. -/ @[simp] theorem pointsWithCircumcenter_eq_circumcenter {n : ℕ} (s : Simplex ℝ P n) : s.pointsWithCircumcenter circumcenterIndex = s.circumcenter := rfl /-- The weights for a single vertex of a simplex, in terms of `pointsWithCircumcenter`. -/ def pointWeightsWithCircumcenter {n : ℕ} (i : Fin (n + 1)) : PointsWithCircumcenterIndex n → ℝ | pointIndex j => if j = i then 1 else 0 | circumcenterIndex => 0 /-- `point_weights_with_circumcenter` sums to 1. -/ @[simp] theorem sum_pointWeightsWithCircumcenter {n : ℕ} (i : Fin (n + 1)) : ∑ j, pointWeightsWithCircumcenter i j = 1 := by classical convert sum_ite_eq' univ (pointIndex i) (Function.const _ (1 : ℝ)) with j · cases j <;> simp [pointWeightsWithCircumcenter] · simp /-- A single vertex, in terms of `pointsWithCircumcenter`. -/ theorem point_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.points i = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (pointWeightsWithCircumcenter i) := by rw [← pointsWithCircumcenter_point] symm refine affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_univ _) (by simp [pointWeightsWithCircumcenter]) ?_ intro i hi hn cases i · have h : _ ≠ i := fun h => hn (h ▸ rfl) simp [pointWeightsWithCircumcenter, h] · rfl
/-- The weights for the centroid of some vertices of a simplex, in terms of `pointsWithCircumcenter`. -/ def centroidWeightsWithCircumcenter {n : ℕ} (fs : Finset (Fin (n + 1))) : PointsWithCircumcenterIndex n → ℝ | pointIndex i => if i ∈ fs then (#fs : ℝ)⁻¹ else 0 | circumcenterIndex => 0 /-- `centroidWeightsWithCircumcenter` sums to 1, if the `Finset` is nonempty. -/ @[simp] theorem sum_centroidWeightsWithCircumcenter {n : ℕ} {fs : Finset (Fin (n + 1))} (h : fs.Nonempty) :
Mathlib/Geometry/Euclidean/Circumcenter.lean
497
507
/- 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 theorem abs_cos_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |cos θ| = |cos ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [cos_add_pi, abs_neg] theorem abs_cos_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |cos θ| = |cos ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_cos_eq_of_two_nsmul_eq h @[simp] theorem coe_toIcoMod (θ ψ : ℝ) : ↑(toIcoMod two_pi_pos ψ θ) = (θ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIcoDiv two_pi_pos ψ θ, ?_⟩ rw [toIcoMod_sub_self, zsmul_eq_mul, mul_comm] @[simp] theorem coe_toIocMod (θ ψ : ℝ) : ↑(toIocMod two_pi_pos ψ θ) = (θ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIocDiv two_pi_pos ψ θ, ?_⟩ rw [toIocMod_sub_self, zsmul_eq_mul, mul_comm] /-- Convert a `Real.Angle` to a real number in the interval `Ioc (-π) π`. -/ def toReal (θ : Angle) : ℝ := (toIocMod_periodic two_pi_pos (-π)).lift θ theorem toReal_coe (θ : ℝ) : (θ : Angle).toReal = toIocMod two_pi_pos (-π) θ := rfl theorem toReal_coe_eq_self_iff {θ : ℝ} : (θ : Angle).toReal = θ ↔ -π < θ ∧ θ ≤ π := by rw [toReal_coe, toIocMod_eq_self two_pi_pos] ring_nf rfl theorem toReal_coe_eq_self_iff_mem_Ioc {θ : ℝ} : (θ : Angle).toReal = θ ↔ θ ∈ Set.Ioc (-π) π := by rw [toReal_coe_eq_self_iff, ← Set.mem_Ioc] theorem toReal_injective : Function.Injective toReal := by intro θ ψ h induction θ using Real.Angle.induction_on induction ψ using Real.Angle.induction_on simpa [toReal_coe, toIocMod_eq_toIocMod, zsmul_eq_mul, mul_comm _ (2 * π), ← angle_eq_iff_two_pi_dvd_sub, eq_comm] using h @[simp] theorem toReal_inj {θ ψ : Angle} : θ.toReal = ψ.toReal ↔ θ = ψ := toReal_injective.eq_iff @[simp] theorem coe_toReal (θ : Angle) : (θ.toReal : Angle) = θ := by induction θ using Real.Angle.induction_on exact coe_toIocMod _ _ theorem neg_pi_lt_toReal (θ : Angle) : -π < θ.toReal := by induction θ using Real.Angle.induction_on exact left_lt_toIocMod _ _ _ theorem toReal_le_pi (θ : Angle) : θ.toReal ≤ π := by induction θ using Real.Angle.induction_on convert toIocMod_le_right two_pi_pos _ _ ring theorem abs_toReal_le_pi (θ : Angle) : |θ.toReal| ≤ π := abs_le.2 ⟨(neg_pi_lt_toReal _).le, toReal_le_pi _⟩ theorem toReal_mem_Ioc (θ : Angle) : θ.toReal ∈ Set.Ioc (-π) π := ⟨neg_pi_lt_toReal _, toReal_le_pi _⟩ @[simp] theorem toIocMod_toReal (θ : Angle) : toIocMod two_pi_pos (-π) θ.toReal = θ.toReal := by induction θ using Real.Angle.induction_on rw [toReal_coe] exact toIocMod_toIocMod _ _ _ _ @[simp] theorem toReal_zero : (0 : Angle).toReal = 0 := by rw [← coe_zero, toReal_coe_eq_self_iff] exact ⟨Left.neg_neg_iff.2 Real.pi_pos, Real.pi_pos.le⟩ @[simp] theorem toReal_eq_zero_iff {θ : Angle} : θ.toReal = 0 ↔ θ = 0 := by nth_rw 1 [← toReal_zero] exact toReal_inj @[simp] theorem toReal_pi : (π : Angle).toReal = π := by rw [toReal_coe_eq_self_iff]
exact ⟨Left.neg_lt_self Real.pi_pos, le_refl _⟩ @[simp] theorem toReal_eq_pi_iff {θ : Angle} : θ.toReal = π ↔ θ = π := by rw [← toReal_inj, toReal_pi] theorem pi_ne_zero : (π : Angle) ≠ 0 := by
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
493
498
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Geometry.Manifold.MFDeriv.SpecificFunctions /-! # Differentiability of models with corners and (extended) charts In this file, we analyse the differentiability of charts, models with corners and extended charts. We show that * models with corners are differentiable * charts are differentiable on their source * `mdifferentiableOn_extChartAt`: `extChartAt` is differentiable on its source Suppose a partial homeomorphism `e` is differentiable. This file shows * `PartialHomeomorph.MDifferentiable.mfderiv`: its derivative is a continuous linear equivalence * `PartialHomeomorph.MDifferentiable.mfderiv_bijective`: its derivative is bijective; there are also spelling with trivial kernel and full range In particular, (extended) charts have bijective differential. ## Tags charts, differentiable, bijective -/ noncomputable section open scoped Manifold ContDiff open Bundle Set Topology variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] section ModelWithCorners namespace ModelWithCorners /- In general, the model with corner `I` is implicit in most theorems in differential geometry, but this section is about `I` as a map, not as a parameter. Therefore, we make it explicit. -/ variable (I) /-! #### Model with corners -/ protected theorem hasMFDerivAt {x} : HasMFDerivAt I 𝓘(𝕜, E) I x (ContinuousLinearMap.id _ _) := ⟨I.continuousAt, (hasFDerivWithinAt_id _ _).congr' I.rightInvOn (mem_range_self _)⟩ protected theorem hasMFDerivWithinAt {s x} : HasMFDerivWithinAt I 𝓘(𝕜, E) I s x (ContinuousLinearMap.id _ _) := I.hasMFDerivAt.hasMFDerivWithinAt protected theorem mdifferentiableWithinAt {s x} : MDifferentiableWithinAt I 𝓘(𝕜, E) I s x := I.hasMFDerivWithinAt.mdifferentiableWithinAt protected theorem mdifferentiableAt {x} : MDifferentiableAt I 𝓘(𝕜, E) I x := I.hasMFDerivAt.mdifferentiableAt protected theorem mdifferentiableOn {s} : MDifferentiableOn I 𝓘(𝕜, E) I s := fun _ _ => I.mdifferentiableWithinAt protected theorem mdifferentiable : MDifferentiable I 𝓘(𝕜, E) I := fun _ => I.mdifferentiableAt theorem hasMFDerivWithinAt_symm {x} (hx : x ∈ range I) : HasMFDerivWithinAt 𝓘(𝕜, E) I I.symm (range I) x (ContinuousLinearMap.id _ _) := ⟨I.continuousWithinAt_symm, (hasFDerivWithinAt_id _ _).congr' (fun _y hy => I.rightInvOn hy.1) ⟨hx, mem_range_self _⟩⟩ theorem mdifferentiableOn_symm : MDifferentiableOn 𝓘(𝕜, E) I I.symm (range I) := fun _x hx => (I.hasMFDerivWithinAt_symm hx).mdifferentiableWithinAt theorem mdifferentiableWithinAt_symm {z : E} (hz : z ∈ range I) : MDifferentiableWithinAt 𝓘(𝕜, E) I I.symm (range I) z := I.mdifferentiableOn_symm z hz end ModelWithCorners end ModelWithCorners section Charts variable [IsManifold I 1 M] [IsManifold I' 1 M'] [IsManifold I'' 1 M''] {e : PartialHomeomorph M H} theorem mdifferentiableAt_atlas (h : e ∈ atlas H M) {x : M} (hx : x ∈ e.source) : MDifferentiableAt I I e x := by rw [mdifferentiableAt_iff] refine ⟨(e.continuousOn x hx).continuousAt (e.open_source.mem_nhds hx), ?_⟩ have mem : I ((chartAt H x : M → H) x) ∈ I.symm ⁻¹' ((chartAt H x).symm ≫ₕ e).source ∩ range I := by simp only [hx, mfld_simps] have : (chartAt H x).symm.trans e ∈ contDiffGroupoid 1 I := HasGroupoid.compatible (chart_mem_atlas H x) h have A : ContDiffOn 𝕜 1 (I ∘ (chartAt H x).symm.trans e ∘ I.symm) (I.symm ⁻¹' ((chartAt H x).symm.trans e).source ∩ range I) := this.1 have B := A.differentiableOn le_rfl (I ((chartAt H x : M → H) x)) mem simp only [mfld_simps] at B rw [inter_comm, differentiableWithinAt_inter] at B · simpa only [mfld_simps] · apply IsOpen.mem_nhds ((PartialHomeomorph.open_source _).preimage I.continuous_symm) mem.1 theorem mdifferentiableOn_atlas (h : e ∈ atlas H M) : MDifferentiableOn I I e e.source := fun _x hx => (mdifferentiableAt_atlas h hx).mdifferentiableWithinAt theorem mdifferentiableAt_atlas_symm (h : e ∈ atlas H M) {x : H} (hx : x ∈ e.target) : MDifferentiableAt I I e.symm x := by rw [mdifferentiableAt_iff] refine ⟨(e.continuousOn_symm x hx).continuousAt (e.open_target.mem_nhds hx), ?_⟩ have mem : I x ∈ I.symm ⁻¹' (e.symm ≫ₕ chartAt H (e.symm x)).source ∩ range I := by simp only [hx, mfld_simps] have : e.symm.trans (chartAt H (e.symm x)) ∈ contDiffGroupoid 1 I := HasGroupoid.compatible h (chart_mem_atlas H _) have A : ContDiffOn 𝕜 1 (I ∘ e.symm.trans (chartAt H (e.symm x)) ∘ I.symm) (I.symm ⁻¹' (e.symm.trans (chartAt H (e.symm x))).source ∩ range I) := this.1 have B := A.differentiableOn le_rfl (I x) mem simp only [mfld_simps] at B rw [inter_comm, differentiableWithinAt_inter] at B · simpa only [mfld_simps] · apply IsOpen.mem_nhds ((PartialHomeomorph.open_source _).preimage I.continuous_symm) mem.1 theorem mdifferentiableOn_atlas_symm (h : e ∈ atlas H M) : MDifferentiableOn I I e.symm e.target := fun _x hx => (mdifferentiableAt_atlas_symm h hx).mdifferentiableWithinAt theorem mdifferentiable_of_mem_atlas (h : e ∈ atlas H M) : e.MDifferentiable I I := ⟨mdifferentiableOn_atlas h, mdifferentiableOn_atlas_symm h⟩ theorem mdifferentiable_chart (x : M) : (chartAt H x).MDifferentiable I I := mdifferentiable_of_mem_atlas (chart_mem_atlas _ _) end Charts /-! ### Differentiable partial homeomorphisms -/ namespace PartialHomeomorph.MDifferentiable variable {e : PartialHomeomorph M M'} (he : e.MDifferentiable I I') {e' : PartialHomeomorph M' M''} include he
nonrec theorem symm : e.symm.MDifferentiable I' I := he.symm protected theorem mdifferentiableAt {x : M} (hx : x ∈ e.source) : MDifferentiableAt I I' e x := (he.1 x hx).mdifferentiableAt (e.open_source.mem_nhds hx) theorem mdifferentiableAt_symm {x : M'} (hx : x ∈ e.target) : MDifferentiableAt I' I e.symm x := (he.2 x hx).mdifferentiableAt (e.open_target.mem_nhds hx)
Mathlib/Geometry/Manifold/MFDeriv/Atlas.lean
146
153
/- 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.Ordering.Basic import Mathlib.Order.Synonym /-! # Comparison This file provides basic results about orderings and comparison in linear orders. ## Definitions * `CmpLE`: An `Ordering` from `≤`. * `Ordering.Compares`: Turns an `Ordering` into `<` and `=` propositions. * `linearOrderOfCompares`: Constructs a `LinearOrder` instance from the fact that any two elements that are not one strictly less than the other either way are equal. -/ variable {α β : Type*} /-- Like `cmp`, but uses a `≤` on the type instead of `<`. Given two elements `x` and `y`, returns a three-way comparison result `Ordering`. -/ def cmpLE {α} [LE α] [DecidableLE α] (x y : α) : Ordering := if x ≤ y then if y ≤ x then Ordering.eq else Ordering.lt else Ordering.gt theorem cmpLE_swap {α} [LE α] [IsTotal α (· ≤ ·)] [DecidableLE α] (x y : α) : (cmpLE x y).swap = cmpLE y x := by by_cases xy : x ≤ y <;> by_cases yx : y ≤ x <;> simp [cmpLE, *, Ordering.swap] cases not_or_intro xy yx (total_of _ _ _) theorem cmpLE_eq_cmp {α} [Preorder α] [IsTotal α (· ≤ ·)] [DecidableLE α] [DecidableLT α] (x y : α) : cmpLE x y = cmp x y := by by_cases xy : x ≤ y <;> by_cases yx : y ≤ x <;> simp [cmpLE, lt_iff_le_not_le, *, cmp, cmpUsing] cases not_or_intro xy yx (total_of _ _ _) namespace Ordering theorem compares_swap [LT α] {a b : α} {o : Ordering} : o.swap.Compares a b ↔ o.Compares b a := by cases o · exact Iff.rfl · exact eq_comm · exact Iff.rfl alias ⟨Compares.of_swap, Compares.swap⟩ := compares_swap theorem swap_eq_iff_eq_swap {o o' : Ordering} : o.swap = o' ↔ o = o'.swap := by rw [← swap_inj, swap_swap] theorem Compares.eq_lt [Preorder α] : ∀ {o} {a b : α}, Compares o a b → (o = lt ↔ a < b) | lt, _, _, h => ⟨fun _ => h, fun _ => rfl⟩ | eq, a, b, h => ⟨fun h => by injection h, fun h' => (ne_of_lt h' h).elim⟩ | gt, a, b, h => ⟨fun h => by injection h, fun h' => (lt_asymm h h').elim⟩ theorem Compares.ne_lt [Preorder α] : ∀ {o} {a b : α}, Compares o a b → (o ≠ lt ↔ b ≤ a) | lt, _, _, h => ⟨absurd rfl, fun h' => (not_le_of_lt h h').elim⟩ | eq, _, _, h => ⟨fun _ => ge_of_eq h, fun _ h => by injection h⟩ | gt, _, _, h => ⟨fun _ => le_of_lt h, fun _ h => by injection h⟩ theorem Compares.eq_eq [Preorder α] : ∀ {o} {a b : α}, Compares o a b → (o = eq ↔ a = b) | lt, a, b, h => ⟨fun h => by injection h, fun h' => (ne_of_lt h h').elim⟩ | eq, _, _, h => ⟨fun _ => h, fun _ => rfl⟩ | gt, a, b, h => ⟨fun h => by injection h, fun h' => (ne_of_gt h h').elim⟩ theorem Compares.eq_gt [Preorder α] {o} {a b : α} (h : Compares o a b) : o = gt ↔ b < a := swap_eq_iff_eq_swap.symm.trans h.swap.eq_lt theorem Compares.ne_gt [Preorder α] {o} {a b : α} (h : Compares o a b) : o ≠ gt ↔ a ≤ b := (not_congr swap_eq_iff_eq_swap.symm).trans h.swap.ne_lt theorem Compares.le_total [Preorder α] {a b : α} : ∀ {o}, Compares o a b → a ≤ b ∨ b ≤ a | lt, h => Or.inl (le_of_lt h) | eq, h => Or.inl (le_of_eq h) | gt, h => Or.inr (le_of_lt h) theorem Compares.le_antisymm [Preorder α] {a b : α} : ∀ {o}, Compares o a b → a ≤ b → b ≤ a → a = b | lt, h, _, hba => (not_le_of_lt h hba).elim | eq, h, _, _ => h | gt, h, hab, _ => (not_le_of_lt h hab).elim theorem Compares.inj [Preorder α] {o₁} : ∀ {o₂} {a b : α}, Compares o₁ a b → Compares o₂ a b → o₁ = o₂ | lt, _, _, h₁, h₂ => h₁.eq_lt.2 h₂ | eq, _, _, h₁, h₂ => h₁.eq_eq.2 h₂ | gt, _, _, h₁, h₂ => h₁.eq_gt.2 h₂ theorem compares_iff_of_compares_impl [LinearOrder α] [Preorder β] {a b : α} {a' b' : β} (h : ∀ {o}, Compares o a b → Compares o a' b') (o) : Compares o a b ↔ Compares o a' b' := by refine ⟨h, fun ho => ?_⟩ rcases lt_trichotomy a b with hab | hab | hab · have hab : Compares Ordering.lt a b := hab rwa [ho.inj (h hab)] · have hab : Compares Ordering.eq a b := hab rwa [ho.inj (h hab)] · have hab : Compares Ordering.gt a b := hab rwa [ho.inj (h hab)] end Ordering open Ordering OrderDual @[simp] theorem toDual_compares_toDual [LT α] {a b : α} {o : Ordering} : Compares o (toDual a) (toDual b) ↔ Compares o b a := by cases o exacts [Iff.rfl, eq_comm, Iff.rfl] @[simp] theorem ofDual_compares_ofDual [LT α] {a b : αᵒᵈ} {o : Ordering} : Compares o (ofDual a) (ofDual b) ↔ Compares o b a := by cases o exacts [Iff.rfl, eq_comm, Iff.rfl] theorem cmp_compares [LinearOrder α] (a b : α) : (cmp a b).Compares a b := by obtain h | h | h := lt_trichotomy a b <;> simp [cmp, cmpUsing, h, h.not_lt] theorem Ordering.Compares.cmp_eq [LinearOrder α] {a b : α} {o : Ordering} (h : o.Compares a b) : cmp a b = o := (cmp_compares a b).inj h @[simp] theorem cmp_swap [Preorder α] [DecidableLT α] (a b : α) : (cmp a b).swap = cmp b a := by unfold cmp cmpUsing by_cases h : a < b <;> by_cases h₂ : b < a <;> simp [h, h₂, Ordering.swap] exact lt_asymm h h₂ @[simp] theorem cmpLE_toDual [LE α] [DecidableLE α] (x y : α) : cmpLE (toDual x) (toDual y) = cmpLE y x := rfl @[simp] theorem cmpLE_ofDual [LE α] [DecidableLE α] (x y : αᵒᵈ) : cmpLE (ofDual x) (ofDual y) = cmpLE y x := rfl @[simp] theorem cmp_toDual [LT α] [DecidableLT α] (x y : α) : cmp (toDual x) (toDual y) = cmp y x := rfl @[simp] theorem cmp_ofDual [LT α] [DecidableLT α] (x y : αᵒᵈ) : cmp (ofDual x) (ofDual y) = cmp y x := rfl /-- Generate a linear order structure from a preorder and `cmp` function. -/ def linearOrderOfCompares [Preorder α] (cmp : α → α → Ordering) (h : ∀ a b, (cmp a b).Compares a b) : LinearOrder α := let H : DecidableLE α := fun a b => decidable_of_iff _ (h a b).ne_gt { inferInstanceAs (Preorder α) with le_antisymm := fun a b => (h a b).le_antisymm, le_total := fun a b => (h a b).le_total, toMin := minOfLe, toMax := maxOfLe, toDecidableLE := H, toDecidableLT := fun a b => decidable_of_iff _ (h a b).eq_lt, toDecidableEq := fun a b => decidable_of_iff _ (h a b).eq_eq } variable [LinearOrder α] (x y : α) @[simp] theorem cmp_eq_lt_iff : cmp x y = Ordering.lt ↔ x < y := Ordering.Compares.eq_lt (cmp_compares x y) @[simp] theorem cmp_eq_eq_iff : cmp x y = Ordering.eq ↔ x = y := Ordering.Compares.eq_eq (cmp_compares x y) @[simp] theorem cmp_eq_gt_iff : cmp x y = Ordering.gt ↔ y < x := Ordering.Compares.eq_gt (cmp_compares x y) @[simp] theorem cmp_self_eq_eq : cmp x x = Ordering.eq := by rw [cmp_eq_eq_iff]
variable {x y} {β : Type*} [LinearOrder β] {x' y' : β} theorem cmp_eq_cmp_symm : cmp x y = cmp x' y' ↔ cmp y x = cmp y' x' := ⟨fun h => by rwa [← cmp_swap x', ← cmp_swap, swap_inj],
Mathlib/Order/Compare.lean
177
180
/- 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.IsolatedZeros import Mathlib.Analysis.SpecialFunctions.Complex.CircleMap import Mathlib.Analysis.SpecialFunctions.NonIntegrable /-! # Integral over a circle in `ℂ` In this file we define `∮ z in C(c, R), f z` to be the integral $\oint_{|z-c|=|R|} f(z)\,dz$ and prove some properties of this integral. We give definition and prove most lemmas for a function `f : ℂ → E`, where `E` is a complex Banach space. For this reason, some lemmas use, e.g., `(z - c)⁻¹ • f z` instead of `f z / (z - c)`. ## Main definitions * `CircleIntegrable f c R`: a function `f : ℂ → E` is integrable on the circle with center `c` and radius `R` if `f ∘ circleMap c R` is integrable on `[0, 2π]`; * `circleIntegral f c R`: the integral $\oint_{|z-c|=|R|} f(z)\,dz$, defined as $\int_{0}^{2π}(c + Re^{θ i})' f(c+Re^{θ i})\,dθ$; * `cauchyPowerSeries f c R`: the power series that is equal to $\sum_{n=0}^{\infty} \oint_{|z-c|=R} \left(\frac{w-c}{z - c}\right)^n \frac{1}{z-c}f(z)\,dz$ at `w - c`. The coefficients of this power series depend only on `f ∘ circleMap c R`, and the power series converges to `f w` if `f` is differentiable on the closed ball `Metric.closedBall c R` and `w` belongs to the corresponding open ball. ## Main statements * `hasFPowerSeriesOn_cauchy_integral`: for any circle integrable function `f`, the power series `cauchyPowerSeries f c R`, `R > 0`, converges to the Cauchy integral `(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z` on the open disc `Metric.ball c R`; * `circleIntegral.integral_sub_zpow_of_undef`, `circleIntegral.integral_sub_zpow_of_ne`, and `circleIntegral.integral_sub_inv_of_mem_ball`: formulas for `∮ z in C(c, R), (z - w) ^ n`, `n : ℤ`. These lemmas cover the following cases: - `circleIntegral.integral_sub_zpow_of_undef`, `n < 0` and `|w - c| = |R|`: in this case the function is not integrable, so the integral is equal to its default value (zero); - `circleIntegral.integral_sub_zpow_of_ne`, `n ≠ -1`: in the cases not covered by the previous lemma, we have `(z - w) ^ n = ((z - w) ^ (n + 1) / (n + 1))'`, thus the integral equals zero; - `circleIntegral.integral_sub_inv_of_mem_ball`, `n = -1`, `|w - c| < R`: in this case the integral is equal to `2πi`. The case `n = -1`, `|w -c| > R` is not covered by these lemmas. While it is possible to construct an explicit primitive, it is easier to apply Cauchy theorem, so we postpone the proof till we have this theorem (see https://github.com/leanprover-community/mathlib4/pull/10000). ## Notation - `∮ z in C(c, R), f z`: notation for the integral $\oint_{|z-c|=|R|} f(z)\,dz$, defined as $\int_{0}^{2π}(c + Re^{θ i})' f(c+Re^{θ i})\,dθ$. ## Tags integral, circle, Cauchy integral -/ variable {E : Type*} [NormedAddCommGroup E] noncomputable section open scoped Real NNReal Interval Pointwise Topology open Complex MeasureTheory TopologicalSpace Metric Function Set Filter Asymptotics /-! ### Facts about `circleMap` -/ /-- The range of `circleMap c R` is the circle with center `c` and radius `|R|`. -/ @[simp] theorem range_circleMap (c : ℂ) (R : ℝ) : range (circleMap c R) = sphere c |R| := calc range (circleMap c R) = c +ᵥ R • range fun θ : ℝ => exp (θ * I) := by simp +unfoldPartialApp only [← image_vadd, ← image_smul, ← range_comp, vadd_eq_add, circleMap, comp_def, real_smul] _ = sphere c |R| := by rw [range_exp_mul_I, smul_sphere R 0 zero_le_one] simp /-- The image of `(0, 2π]` under `circleMap c R` is the circle with center `c` and radius `|R|`. -/ @[simp] theorem image_circleMap_Ioc (c : ℂ) (R : ℝ) : circleMap c R '' Ioc 0 (2 * π) = sphere c |R| := by rw [← range_circleMap, ← (periodic_circleMap c R).image_Ioc Real.two_pi_pos 0, zero_add] theorem hasDerivAt_circleMap (c : ℂ) (R : ℝ) (θ : ℝ) : HasDerivAt (circleMap c R) (circleMap 0 R θ * I) θ := by simpa only [mul_assoc, one_mul, ofRealCLM_apply, circleMap, ofReal_one, zero_add] using (((ofRealCLM.hasDerivAt (x := θ)).mul_const I).cexp.const_mul (R : ℂ)).const_add c theorem differentiable_circleMap (c : ℂ) (R : ℝ) : Differentiable ℝ (circleMap c R) := fun θ => (hasDerivAt_circleMap c R θ).differentiableAt /-- The circleMap is real analytic. -/ theorem analyticOnNhd_circleMap (c : ℂ) (R : ℝ) : AnalyticOnNhd ℝ (circleMap c R) Set.univ := by intro z hz apply analyticAt_const.add apply analyticAt_const.mul rw [← Function.comp_def] apply analyticAt_cexp.restrictScalars.comp ((ofRealCLM.analyticAt z).mul (by fun_prop)) /-- The circleMap is continuously differentiable. -/ theorem contDiff_circleMap (c : ℂ) (R : ℝ) {n : WithTop ℕ∞} : ContDiff ℝ n (circleMap c R) := (analyticOnNhd_circleMap c R).contDiff @[continuity, fun_prop] theorem continuous_circleMap (c : ℂ) (R : ℝ) : Continuous (circleMap c R) := (differentiable_circleMap c R).continuous @[fun_prop, measurability]
theorem measurable_circleMap (c : ℂ) (R : ℝ) : Measurable (circleMap c R) := (continuous_circleMap c R).measurable
Mathlib/MeasureTheory/Integral/CircleIntegral.lean
120
122
/- 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 theorem smul_eq_C_mul (p : MvPolynomial σ R) (a : R) : a • p = C a * p := C_mul'.symm theorem C_eq_smul_one : (C a : MvPolynomial σ R) = a • (1 : MvPolynomial σ R) := by rw [← C_mul', mul_one] theorem smul_monomial {S₁ : Type*} [SMulZeroClass S₁ R] (r : S₁) : r • monomial s a = monomial s (r • a) := Finsupp.smul_single _ _ _ theorem X_injective [Nontrivial R] : Function.Injective (X : σ → MvPolynomial σ R) := (monomial_left_injective one_ne_zero).comp (Finsupp.single_left_injective one_ne_zero) @[simp] theorem X_inj [Nontrivial R] (m n : σ) : X m = (X n : MvPolynomial σ R) ↔ m = n := X_injective.eq_iff theorem monomial_pow : monomial s a ^ e = monomial (e • s) (a ^ e) := AddMonoidAlgebra.single_pow e @[simp] theorem monomial_mul {s s' : σ →₀ ℕ} {a b : R} : monomial s a * monomial s' b = monomial (s + s') (a * b) := AddMonoidAlgebra.single_mul_single variable (σ R) /-- `fun s ↦ monomial s 1` as a homomorphism. -/ def monomialOneHom : Multiplicative (σ →₀ ℕ) →* MvPolynomial σ R := AddMonoidAlgebra.of _ _ variable {σ R} @[simp] theorem monomialOneHom_apply : monomialOneHom R σ s = (monomial s 1 : MvPolynomial σ R) := rfl theorem X_pow_eq_monomial : X n ^ e = monomial (Finsupp.single n e) (1 : R) := by simp [X, monomial_pow] theorem monomial_add_single : monomial (s + Finsupp.single n e) a = monomial s a * X n ^ e := by rw [X_pow_eq_monomial, monomial_mul, mul_one] theorem monomial_single_add : monomial (Finsupp.single n e + s) a = X n ^ e * monomial s a := by rw [X_pow_eq_monomial, monomial_mul, one_mul] theorem C_mul_X_pow_eq_monomial {s : σ} {a : R} {n : ℕ} : C a * X s ^ n = monomial (Finsupp.single s n) a := by rw [← zero_add (Finsupp.single s n), monomial_add_single, C_apply] theorem C_mul_X_eq_monomial {s : σ} {a : R} : C a * X s = monomial (Finsupp.single s 1) a := by rw [← C_mul_X_pow_eq_monomial, pow_one] @[simp] theorem monomial_zero {s : σ →₀ ℕ} : monomial s (0 : R) = 0 := Finsupp.single_zero _ @[simp] theorem monomial_zero' : (monomial (0 : σ →₀ ℕ) : R → MvPolynomial σ R) = C := rfl @[simp] theorem monomial_eq_zero {s : σ →₀ ℕ} {b : R} : monomial s b = 0 ↔ b = 0 := Finsupp.single_eq_zero @[simp] theorem sum_monomial_eq {A : Type*} [AddCommMonoid A] {u : σ →₀ ℕ} {r : R} {b : (σ →₀ ℕ) → R → A} (w : b u 0 = 0) : sum (monomial u r) b = b u r := Finsupp.sum_single_index w @[simp] theorem sum_C {A : Type*} [AddCommMonoid A] {b : (σ →₀ ℕ) → R → A} (w : b 0 0 = 0) : sum (C a) b = b 0 a := sum_monomial_eq w theorem monomial_sum_one {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) : (monomial (∑ i ∈ s, f i) 1 : MvPolynomial σ R) = ∏ i ∈ s, monomial (f i) 1 := map_prod (monomialOneHom R σ) (fun i => Multiplicative.ofAdd (f i)) s theorem monomial_sum_index {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) (a : R) : monomial (∑ i ∈ s, f i) a = C a * ∏ i ∈ s, monomial (f i) 1 := by rw [← monomial_sum_one, C_mul', ← (monomial _).map_smul, smul_eq_mul, mul_one] theorem monomial_finsupp_sum_index {α β : Type*} [Zero β] (f : α →₀ β) (g : α → β → σ →₀ ℕ) (a : R) : monomial (f.sum g) a = C a * f.prod fun a b => monomial (g a b) 1 := monomial_sum_index _ _ _ theorem monomial_eq_monomial_iff {α : Type*} (a₁ a₂ : α →₀ ℕ) (b₁ b₂ : R) : monomial a₁ b₁ = monomial a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ ∨ b₁ = 0 ∧ b₂ = 0 := Finsupp.single_eq_single_iff _ _ _ _ theorem monomial_eq : monomial s a = C a * (s.prod fun n e => X n ^ e : MvPolynomial σ R) := by simp only [X_pow_eq_monomial, ← monomial_finsupp_sum_index, Finsupp.sum_single] @[simp] lemma prod_X_pow_eq_monomial : ∏ x ∈ s.support, X x ^ s x = monomial s (1 : R) := by simp only [monomial_eq, map_one, one_mul, Finsupp.prod] @[elab_as_elim] theorem induction_on_monomial {motive : MvPolynomial σ R → Prop} (C : ∀ a, motive (C a)) (mul_X : ∀ p n, motive p → motive (p * X n)) : ∀ s a, motive (monomial s a) := by intro s a apply @Finsupp.induction σ ℕ _ _ s · show motive (monomial 0 a) exact C a · intro n e p _hpn _he ih have : ∀ e : ℕ, motive (monomial p a * X n ^ e) := by intro e induction e with | zero => simp [ih] | succ e e_ih => simp [ih, pow_succ, (mul_assoc _ _ _).symm, mul_X, e_ih] simp [add_comm, monomial_add_single, this] /-- Analog of `Polynomial.induction_on'`. To prove something about mv_polynomials, it suffices to show the condition is closed under taking sums, and it holds for monomials. -/ @[elab_as_elim] theorem induction_on' {P : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (monomial : ∀ (u : σ →₀ ℕ) (a : R), P (monomial u a)) (add : ∀ p q : MvPolynomial σ R, P p → P q → P (p + q)) : P p := Finsupp.induction p (suffices P (MvPolynomial.monomial 0 0) by rwa [monomial_zero] at this show P (MvPolynomial.monomial 0 0) from monomial 0 0) fun _ _ _ _ha _hb hPf => add _ _ (monomial _ _) hPf /-- Similar to `MvPolynomial.induction_on` but only a weak form of `h_add` is required. In particular, this version only requires us to show that `motive` is closed under addition of nontrivial monomials not present in the support. -/ @[elab_as_elim] theorem monomial_add_induction_on {motive : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (C : ∀ a, motive (C a)) (monomial_add : ∀ (a : σ →₀ ℕ) (b : R) (f : MvPolynomial σ R), a ∉ f.support → b ≠ 0 → motive f → motive ((monomial a b) + f)) : motive p := Finsupp.induction p (C_0.rec <| C 0) monomial_add @[deprecated (since := "2025-03-11")] alias induction_on''' := monomial_add_induction_on /-- Similar to `MvPolynomial.induction_on` but only a yet weaker form of `h_add` is required. In particular, this version only requires us to show that `motive` is closed under addition of monomials not present in the support for which `motive` is already known to hold. -/ theorem induction_on'' {motive : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (C : ∀ a, motive (C a)) (monomial_add : ∀ (a : σ →₀ ℕ) (b : R) (f : MvPolynomial σ R), a ∉ f.support → b ≠ 0 → motive f → motive (monomial a b) → motive ((monomial a b) + f)) (mul_X : ∀ (p : MvPolynomial σ R) (n : σ), motive p → motive (p * MvPolynomial.X n)) : motive p := monomial_add_induction_on p C fun a b f ha hb hf => monomial_add a b f ha hb hf <| induction_on_monomial C mul_X a b /-- Analog of `Polynomial.induction_on`. If a property holds for any constant polynomial and is preserved under addition and multiplication by variables then it holds for all multivariate polynomials. -/ @[recursor 5] theorem induction_on {motive : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (C : ∀ a, motive (C a)) (add : ∀ p q, motive p → motive q → motive (p + q)) (mul_X : ∀ p n, motive p → motive (p * X n)) : motive p := induction_on'' p C (fun a b f _ha _hb hf hm => add (monomial a b) f hm hf) mul_X theorem ringHom_ext {A : Type*} [Semiring A] {f g : MvPolynomial σ R →+* A} (hC : ∀ r, f (C r) = g (C r)) (hX : ∀ i, f (X i) = g (X i)) : f = g := by refine AddMonoidAlgebra.ringHom_ext' ?_ ?_ -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): this has high priority, but Lean still chooses `RingHom.ext`, why? -- probably because of the type synonym · ext x exact hC _ · apply Finsupp.mulHom_ext'; intros x -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `Finsupp.mulHom_ext'` needs to have increased priority apply MonoidHom.ext_mnat exact hX _ /-- See note [partially-applied ext lemmas]. -/ @[ext 1100] theorem ringHom_ext' {A : Type*} [Semiring A] {f g : MvPolynomial σ R →+* A} (hC : f.comp C = g.comp C) (hX : ∀ i, f (X i) = g (X i)) : f = g := ringHom_ext (RingHom.ext_iff.1 hC) hX theorem hom_eq_hom [Semiring S₂] (f g : MvPolynomial σ R →+* S₂) (hC : f.comp C = g.comp C) (hX : ∀ n : σ, f (X n) = g (X n)) (p : MvPolynomial σ R) : f p = g p := RingHom.congr_fun (ringHom_ext' hC hX) p theorem is_id (f : MvPolynomial σ R →+* MvPolynomial σ R) (hC : f.comp C = C) (hX : ∀ n : σ, f (X n) = X n) (p : MvPolynomial σ R) : f p = p := hom_eq_hom f (RingHom.id _) hC hX p @[ext 1100] theorem algHom_ext' {A B : Type*} [CommSemiring A] [CommSemiring B] [Algebra R A] [Algebra R B] {f g : MvPolynomial σ A →ₐ[R] B} (h₁ : f.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A)) = g.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A))) (h₂ : ∀ i, f (X i) = g (X i)) : f = g := AlgHom.coe_ringHom_injective (MvPolynomial.ringHom_ext' (congr_arg AlgHom.toRingHom h₁) h₂) @[ext 1200] theorem algHom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : MvPolynomial σ R →ₐ[R] A} (hf : ∀ i : σ, f (X i) = g (X i)) : f = g := AddMonoidAlgebra.algHom_ext' (mulHom_ext' fun X : σ => MonoidHom.ext_mnat (hf X)) @[simp] theorem algHom_C {A : Type*} [Semiring A] [Algebra R A] (f : MvPolynomial σ R →ₐ[R] A) (r : R) : f (C r) = algebraMap R A r := f.commutes r @[simp] theorem adjoin_range_X : Algebra.adjoin R (range (X : σ → MvPolynomial σ R)) = ⊤ := by set S := Algebra.adjoin R (range (X : σ → MvPolynomial σ R)) refine top_unique fun p hp => ?_; clear hp induction p using MvPolynomial.induction_on with | C => exact S.algebraMap_mem _ | add p q hp hq => exact S.add_mem hp hq | mul_X p i hp => exact S.mul_mem hp (Algebra.subset_adjoin <| mem_range_self _) @[ext] theorem linearMap_ext {M : Type*} [AddCommMonoid M] [Module R M] {f g : MvPolynomial σ R →ₗ[R] M} (h : ∀ s, f ∘ₗ monomial s = g ∘ₗ monomial s) : f = g := Finsupp.lhom_ext' h section Support /-- The finite set of all `m : σ →₀ ℕ` such that `X^m` has a non-zero coefficient. -/ def support (p : MvPolynomial σ R) : Finset (σ →₀ ℕ) := Finsupp.support p theorem finsupp_support_eq_support (p : MvPolynomial σ R) : Finsupp.support p = p.support := rfl theorem support_monomial [h : Decidable (a = 0)] : (monomial s a).support = if a = 0 then ∅ else {s} := by rw [← Subsingleton.elim (Classical.decEq R a 0) h] rfl theorem support_monomial_subset : (monomial s a).support ⊆ {s} := support_single_subset theorem support_add [DecidableEq σ] : (p + q).support ⊆ p.support ∪ q.support := Finsupp.support_add theorem support_X [Nontrivial R] : (X n : MvPolynomial σ R).support = {Finsupp.single n 1} := by classical rw [X, support_monomial, if_neg]; exact one_ne_zero theorem support_X_pow [Nontrivial R] (s : σ) (n : ℕ) : (X s ^ n : MvPolynomial σ R).support = {Finsupp.single s n} := by classical rw [X_pow_eq_monomial, support_monomial, if_neg (one_ne_zero' R)] @[simp] theorem support_zero : (0 : MvPolynomial σ R).support = ∅ := rfl theorem support_smul {S₁ : Type*} [SMulZeroClass S₁ R] {a : S₁} {f : MvPolynomial σ R} : (a • f).support ⊆ f.support := Finsupp.support_smul theorem support_sum {α : Type*} [DecidableEq σ] {s : Finset α} {f : α → MvPolynomial σ R} : (∑ x ∈ s, f x).support ⊆ s.biUnion fun x => (f x).support := Finsupp.support_finset_sum end Support section Coeff /-- The coefficient of the monomial `m` in the multi-variable polynomial `p`. -/ def coeff (m : σ →₀ ℕ) (p : MvPolynomial σ R) : R := @DFunLike.coe ((σ →₀ ℕ) →₀ R) _ _ _ p m @[simp] theorem mem_support_iff {p : MvPolynomial σ R} {m : σ →₀ ℕ} : m ∈ p.support ↔ p.coeff m ≠ 0 := by simp [support, coeff] theorem not_mem_support_iff {p : MvPolynomial σ R} {m : σ →₀ ℕ} : m ∉ p.support ↔ p.coeff m = 0 := by simp theorem sum_def {A} [AddCommMonoid A] {p : MvPolynomial σ R} {b : (σ →₀ ℕ) → R → A} : p.sum b = ∑ m ∈ p.support, b m (p.coeff m) := by simp [support, Finsupp.sum, coeff] theorem support_mul [DecidableEq σ] (p q : MvPolynomial σ R) : (p * q).support ⊆ p.support + q.support := AddMonoidAlgebra.support_mul p q @[ext] theorem ext (p q : MvPolynomial σ R) : (∀ m, coeff m p = coeff m q) → p = q := Finsupp.ext @[simp] theorem coeff_add (m : σ →₀ ℕ) (p q : MvPolynomial σ R) : coeff m (p + q) = coeff m p + coeff m q := add_apply p q m @[simp] theorem coeff_smul {S₁ : Type*} [SMulZeroClass S₁ R] (m : σ →₀ ℕ) (C : S₁) (p : MvPolynomial σ R) : coeff m (C • p) = C • coeff m p := smul_apply C p m @[simp] theorem coeff_zero (m : σ →₀ ℕ) : coeff m (0 : MvPolynomial σ R) = 0 := rfl @[simp] theorem coeff_zero_X (i : σ) : coeff 0 (X i : MvPolynomial σ R) = 0 := single_eq_of_ne fun h => by cases Finsupp.single_eq_zero.1 h /-- `MvPolynomial.coeff m` but promoted to an `AddMonoidHom`. -/ @[simps] def coeffAddMonoidHom (m : σ →₀ ℕ) : MvPolynomial σ R →+ R where toFun := coeff m map_zero' := coeff_zero m map_add' := coeff_add m variable (R) in /-- `MvPolynomial.coeff m` but promoted to a `LinearMap`. -/ @[simps] def lcoeff (m : σ →₀ ℕ) : MvPolynomial σ R →ₗ[R] R where toFun := coeff m map_add' := coeff_add m map_smul' := coeff_smul m theorem coeff_sum {X : Type*} (s : Finset X) (f : X → MvPolynomial σ R) (m : σ →₀ ℕ) : coeff m (∑ x ∈ s, f x) = ∑ x ∈ s, coeff m (f x) := map_sum (@coeffAddMonoidHom R σ _ _) _ s theorem monic_monomial_eq (m) : monomial m (1 : R) = (m.prod fun n e => X n ^ e : MvPolynomial σ R) := by simp [monomial_eq] @[simp] theorem coeff_monomial [DecidableEq σ] (m n) (a) : coeff m (monomial n a : MvPolynomial σ R) = if n = m then a else 0 := Finsupp.single_apply @[simp] theorem coeff_C [DecidableEq σ] (m) (a) : coeff m (C a : MvPolynomial σ R) = if 0 = m then a else 0 := Finsupp.single_apply lemma eq_C_of_isEmpty [IsEmpty σ] (p : MvPolynomial σ R) : p = C (p.coeff 0) := by obtain ⟨x, rfl⟩ := C_surjective σ p simp theorem coeff_one [DecidableEq σ] (m) : coeff m (1 : MvPolynomial σ R) = if 0 = m then 1 else 0 := coeff_C m 1 @[simp] theorem coeff_zero_C (a) : coeff 0 (C a : MvPolynomial σ R) = a := single_eq_same @[simp] theorem coeff_zero_one : coeff 0 (1 : MvPolynomial σ R) = 1 := coeff_zero_C 1 theorem coeff_X_pow [DecidableEq σ] (i : σ) (m) (k : ℕ) : coeff m (X i ^ k : MvPolynomial σ R) = if Finsupp.single i k = m then 1 else 0 := by have := coeff_monomial m (Finsupp.single i k) (1 : R) rwa [@monomial_eq _ _ (1 : R) (Finsupp.single i k) _, C_1, one_mul, Finsupp.prod_single_index] at this exact pow_zero _ theorem coeff_X' [DecidableEq σ] (i : σ) (m) : coeff m (X i : MvPolynomial σ R) = if Finsupp.single i 1 = m then 1 else 0 := by rw [← coeff_X_pow, pow_one] @[simp] theorem coeff_X (i : σ) : coeff (Finsupp.single i 1) (X i : MvPolynomial σ R) = 1 := by classical rw [coeff_X', if_pos rfl] @[simp] theorem coeff_C_mul (m) (a : R) (p : MvPolynomial σ R) : coeff m (C a * p) = a * coeff m p := by classical rw [mul_def, sum_C] · simp +contextual [sum_def, coeff_sum] simp theorem coeff_mul [DecidableEq σ] (p q : MvPolynomial σ R) (n : σ →₀ ℕ) : coeff n (p * q) = ∑ x ∈ Finset.antidiagonal n, coeff x.1 p * coeff x.2 q := AddMonoidAlgebra.mul_apply_antidiagonal p q _ _ Finset.mem_antidiagonal @[simp] theorem coeff_mul_monomial (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) : coeff (m + s) (p * monomial s r) = coeff m p * r := AddMonoidAlgebra.mul_single_apply_aux p _ _ _ _ fun _a _ => add_left_inj _ @[simp] theorem coeff_monomial_mul (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) : coeff (s + m) (monomial s r * p) = r * coeff m p := AddMonoidAlgebra.single_mul_apply_aux p _ _ _ _ fun _a _ => add_right_inj _ @[simp] theorem coeff_mul_X (m) (s : σ) (p : MvPolynomial σ R) : coeff (m + Finsupp.single s 1) (p * X s) = coeff m p := (coeff_mul_monomial _ _ _ _).trans (mul_one _) @[simp] theorem coeff_X_mul (m) (s : σ) (p : MvPolynomial σ R) : coeff (Finsupp.single s 1 + m) (X s * p) = coeff m p := (coeff_monomial_mul _ _ _ _).trans (one_mul _) lemma coeff_single_X_pow [DecidableEq σ] (s s' : σ) (n n' : ℕ) : (X (R := R) s ^ n).coeff (Finsupp.single s' n') = if s = s' ∧ n = n' ∨ n = 0 ∧ n' = 0 then 1 else 0 := by simp only [coeff_X_pow, single_eq_single_iff] @[simp] lemma coeff_single_X [DecidableEq σ] (s s' : σ) (n : ℕ) : (X s).coeff (R := R) (Finsupp.single s' n) = if n = 1 ∧ s = s' then 1 else 0 := by simpa [eq_comm, and_comm] using coeff_single_X_pow s s' 1 n @[simp] theorem support_mul_X (s : σ) (p : MvPolynomial σ R) : (p * X s).support = p.support.map (addRightEmbedding (Finsupp.single s 1)) := AddMonoidAlgebra.support_mul_single p _ (by simp) _ @[simp] theorem support_X_mul (s : σ) (p : MvPolynomial σ R) : (X s * p).support = p.support.map (addLeftEmbedding (Finsupp.single s 1)) := AddMonoidAlgebra.support_single_mul p _ (by simp) _ @[simp] theorem support_smul_eq {S₁ : Type*} [Semiring S₁] [Module S₁ R] [NoZeroSMulDivisors S₁ R] {a : S₁} (h : a ≠ 0) (p : MvPolynomial σ R) : (a • p).support = p.support := Finsupp.support_smul_eq h theorem support_sdiff_support_subset_support_add [DecidableEq σ] (p q : MvPolynomial σ R) : p.support \ q.support ⊆ (p + q).support := by intro m hm simp only [Classical.not_not, mem_support_iff, Finset.mem_sdiff, Ne] at hm simp [hm.2, hm.1] open scoped symmDiff in theorem support_symmDiff_support_subset_support_add [DecidableEq σ] (p q : MvPolynomial σ R) : p.support ∆ q.support ⊆ (p + q).support := by rw [symmDiff_def, Finset.sup_eq_union] apply Finset.union_subset · exact support_sdiff_support_subset_support_add p q · rw [add_comm] exact support_sdiff_support_subset_support_add q p theorem coeff_mul_monomial' (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) : coeff m (p * monomial s r) = if s ≤ m then coeff (m - s) p * r else 0 := by classical split_ifs with h · conv_rhs => rw [← coeff_mul_monomial _ s] congr with t rw [tsub_add_cancel_of_le h] · contrapose! h rw [← mem_support_iff] at h obtain ⟨j, -, rfl⟩ : ∃ j ∈ support p, j + s = m := by simpa [Finset.mem_add] using Finset.add_subset_add_left support_monomial_subset <| support_mul _ _ h exact le_add_left le_rfl theorem coeff_monomial_mul' (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) : coeff m (monomial s r * p) = if s ≤ m then r * coeff (m - s) p else 0 := by -- note that if we allow `R` to be non-commutative we will have to duplicate the proof above. rw [mul_comm, mul_comm r] exact coeff_mul_monomial' _ _ _ _ theorem coeff_mul_X' [DecidableEq σ] (m) (s : σ) (p : MvPolynomial σ R) : coeff m (p * X s) = if s ∈ m.support then coeff (m - Finsupp.single s 1) p else 0 := by refine (coeff_mul_monomial' _ _ _ _).trans ?_ simp_rw [Finsupp.single_le_iff, Finsupp.mem_support_iff, Nat.succ_le_iff, pos_iff_ne_zero, mul_one] theorem coeff_X_mul' [DecidableEq σ] (m) (s : σ) (p : MvPolynomial σ R) : coeff m (X s * p) = if s ∈ m.support then coeff (m - Finsupp.single s 1) p else 0 := by refine (coeff_monomial_mul' _ _ _ _).trans ?_ simp_rw [Finsupp.single_le_iff, Finsupp.mem_support_iff, Nat.succ_le_iff, pos_iff_ne_zero, one_mul] theorem eq_zero_iff {p : MvPolynomial σ R} : p = 0 ↔ ∀ d, coeff d p = 0 := by rw [MvPolynomial.ext_iff] simp only [coeff_zero] theorem ne_zero_iff {p : MvPolynomial σ R} : p ≠ 0 ↔ ∃ d, coeff d p ≠ 0 := by rw [Ne, eq_zero_iff] push_neg rfl @[simp] theorem X_ne_zero [Nontrivial R] (s : σ) : X (R := R) s ≠ 0 := by rw [ne_zero_iff] use Finsupp.single s 1 simp only [coeff_X, ne_eq, one_ne_zero, not_false_eq_true] @[simp] theorem support_eq_empty {p : MvPolynomial σ R} : p.support = ∅ ↔ p = 0 := Finsupp.support_eq_empty @[simp] lemma support_nonempty {p : MvPolynomial σ R} : p.support.Nonempty ↔ p ≠ 0 := by rw [Finset.nonempty_iff_ne_empty, ne_eq, support_eq_empty] theorem exists_coeff_ne_zero {p : MvPolynomial σ R} (h : p ≠ 0) : ∃ d, coeff d p ≠ 0 := ne_zero_iff.mp h theorem C_dvd_iff_dvd_coeff (r : R) (φ : MvPolynomial σ R) : C r ∣ φ ↔ ∀ i, r ∣ φ.coeff i := by constructor · rintro ⟨φ, rfl⟩ c rw [coeff_C_mul] apply dvd_mul_right · intro h choose C hc using h classical let c' : (σ →₀ ℕ) → R := fun i => if i ∈ φ.support then C i else 0 let ψ : MvPolynomial σ R := ∑ i ∈ φ.support, monomial i (c' i) use ψ apply MvPolynomial.ext intro i simp only [ψ, c', coeff_C_mul, coeff_sum, coeff_monomial, Finset.sum_ite_eq'] split_ifs with hi · rw [hc] · rw [not_mem_support_iff] at hi rwa [mul_zero] @[simp] lemma isRegular_X : IsRegular (X n : MvPolynomial σ R) := by suffices IsLeftRegular (X n : MvPolynomial σ R) from ⟨this, this.right_of_commute <| Commute.all _⟩ intro P Q (hPQ : (X n) * P = (X n) * Q) ext i rw [← coeff_X_mul i n P, hPQ, coeff_X_mul i n Q] @[simp] lemma isRegular_X_pow (k : ℕ) : IsRegular (X n ^ k : MvPolynomial σ R) := isRegular_X.pow k @[simp] lemma isRegular_prod_X (s : Finset σ) : IsRegular (∏ n ∈ s, X n : MvPolynomial σ R) := IsRegular.prod fun _ _ ↦ isRegular_X /-- The finset of nonzero coefficients of a multivariate polynomial. -/ def coeffs (p : MvPolynomial σ R) : Finset R := letI := Classical.decEq R Finset.image p.coeff p.support @[simp] lemma coeffs_zero : coeffs (0 : MvPolynomial σ R) = ∅ := rfl lemma coeffs_one : coeffs (1 : MvPolynomial σ R) ⊆ {1} := by classical rw [coeffs, Finset.image_subset_iff] simp_all [coeff_one] @[nontriviality] lemma coeffs_eq_empty_of_subsingleton [Subsingleton R] (p : MvPolynomial σ R) : p.coeffs = ∅ := by simpa [coeffs] using Subsingleton.eq_zero p @[simp] lemma coeffs_one_of_nontrivial [Nontrivial R] : coeffs (1 : MvPolynomial σ R) = {1} := by apply Finset.Subset.antisymm coeffs_one simp only [coeffs, Finset.singleton_subset_iff, Finset.mem_image] exact ⟨0, by simp⟩ lemma mem_coeffs_iff {p : MvPolynomial σ R} {c : R} : c ∈ p.coeffs ↔ ∃ n ∈ p.support, c = p.coeff n := by
simp [coeffs, eq_comm, (Finset.mem_image)] lemma coeff_mem_coeffs {p : MvPolynomial σ R} (m : σ →₀ ℕ) (h : p.coeff m ≠ 0) : p.coeff m ∈ p.coeffs := letI := Classical.decEq R
Mathlib/Algebra/MvPolynomial/Basic.lean
817
821
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.CharP.Frobenius import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.RingTheory.Polynomial.Basic /-! # Expand a polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`. ## Main definitions * `Polynomial.expand R p f`: expand the polynomial `f` with coefficients in a commutative semiring `R` by a factor of p, so `expand R p (∑ aₙ xⁿ)` is `∑ aₙ xⁿᵖ`. * `Polynomial.contract p f`: the opposite of `expand`, so it sends `∑ aₙ xⁿᵖ` to `∑ aₙ xⁿ`. -/ universe u v w open Polynomial open Finset namespace Polynomial section CommSemiring variable (R : Type u) [CommSemiring R] {S : Type v} [CommSemiring S] (p q : ℕ) /-- Expand the polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`. -/ noncomputable def expand : R[X] →ₐ[R] R[X] := { (eval₂RingHom C (X ^ p) : R[X] →+* R[X]) with commutes' := fun _ => eval₂_C _ _ } theorem coe_expand : (expand R p : R[X] → R[X]) = eval₂ C (X ^ p) := rfl variable {R} theorem expand_eq_comp_X_pow {f : R[X]} : expand R p f = f.comp (X ^ p) := rfl theorem expand_eq_sum {f : R[X]} : expand R p f = f.sum fun e a => C a * (X ^ p) ^ e := by simp [expand, eval₂] @[simp] theorem expand_C (r : R) : expand R p (C r) = C r := eval₂_C _ _ @[simp] theorem expand_X : expand R p X = X ^ p := eval₂_X _ _ @[simp] theorem expand_monomial (r : R) : expand R p (monomial q r) = monomial (q * p) r := by simp_rw [← smul_X_eq_monomial, map_smul, map_pow, expand_X, mul_comm, pow_mul] theorem expand_expand (f : R[X]) : expand R p (expand R q f) = expand R (p * q) f := Polynomial.induction_on f (fun r => by simp_rw [expand_C]) (fun f g ihf ihg => by simp_rw [map_add, ihf, ihg]) fun n r _ => by simp_rw [map_mul, expand_C, map_pow, expand_X, map_pow, expand_X, pow_mul] theorem expand_mul (f : R[X]) : expand R (p * q) f = expand R p (expand R q f) := (expand_expand p q f).symm @[simp] theorem expand_zero (f : R[X]) : expand R 0 f = C (eval 1 f) := by simp [expand] @[simp] theorem expand_one (f : R[X]) : expand R 1 f = f := Polynomial.induction_on f (fun r => by rw [expand_C]) (fun f g ihf ihg => by rw [map_add, ihf, ihg]) fun n r _ => by rw [map_mul, expand_C, map_pow, expand_X, pow_one] theorem expand_pow (f : R[X]) : expand R (p ^ q) f = (expand R p)^[q] f := Nat.recOn q (by rw [pow_zero, expand_one, Function.iterate_zero, id]) fun n ih => by rw [Function.iterate_succ_apply', pow_succ', expand_mul, ih] theorem derivative_expand (f : R[X]) : Polynomial.derivative (expand R p f) = expand R p (Polynomial.derivative f) * (p * (X ^ (p - 1) : R[X])) := by rw [coe_expand, derivative_eval₂_C, derivative_pow, C_eq_natCast, derivative_X, mul_one] theorem coeff_expand {p : ℕ} (hp : 0 < p) (f : R[X]) (n : ℕ) : (expand R p f).coeff n = if p ∣ n then f.coeff (n / p) else 0 := by simp only [expand_eq_sum] simp_rw [coeff_sum, ← pow_mul, C_mul_X_pow_eq_monomial, coeff_monomial, sum] split_ifs with h · rw [Finset.sum_eq_single (n / p), Nat.mul_div_cancel' h, if_pos rfl] · intro b _ hb2 rw [if_neg] intro hb3 apply hb2 rw [← hb3, Nat.mul_div_cancel_left b hp] · intro hn rw [not_mem_support_iff.1 hn] split_ifs <;> rfl · rw [Finset.sum_eq_zero] intro k _ rw [if_neg] exact fun hkn => h ⟨k, hkn.symm⟩ @[simp] theorem coeff_expand_mul {p : ℕ} (hp : 0 < p) (f : R[X]) (n : ℕ) : (expand R p f).coeff (n * p) = f.coeff n := by rw [coeff_expand hp, if_pos (dvd_mul_left _ _), Nat.mul_div_cancel _ hp] @[simp] theorem coeff_expand_mul' {p : ℕ} (hp : 0 < p) (f : R[X]) (n : ℕ) : (expand R p f).coeff (p * n) = f.coeff n := by rw [mul_comm, coeff_expand_mul hp] /-- Expansion is injective. -/ theorem expand_injective {n : ℕ} (hn : 0 < n) : Function.Injective (expand R n) := fun g g' H => ext fun k => by rw [← coeff_expand_mul hn, H, coeff_expand_mul hn] theorem expand_inj {p : ℕ} (hp : 0 < p) {f g : R[X]} : expand R p f = expand R p g ↔ f = g := (expand_injective hp).eq_iff theorem expand_eq_zero {p : ℕ} (hp : 0 < p) {f : R[X]} : expand R p f = 0 ↔ f = 0 := (expand_injective hp).eq_iff' (map_zero _) theorem expand_ne_zero {p : ℕ} (hp : 0 < p) {f : R[X]} : expand R p f ≠ 0 ↔ f ≠ 0 := (expand_eq_zero hp).not theorem expand_eq_C {p : ℕ} (hp : 0 < p) {f : R[X]} {r : R} : expand R p f = C r ↔ f = C r := by rw [← expand_C, expand_inj hp, expand_C] theorem natDegree_expand (p : ℕ) (f : R[X]) : (expand R p f).natDegree = f.natDegree * p := by rcases p.eq_zero_or_pos with hp | hp · rw [hp, coe_expand, pow_zero, mul_zero, ← C_1, eval₂_hom, natDegree_C] by_cases hf : f = 0 · rw [hf, map_zero, natDegree_zero, zero_mul] have hf1 : expand R p f ≠ 0 := mt (expand_eq_zero hp).1 hf rw [← Nat.cast_inj (R := WithBot ℕ), ← degree_eq_natDegree hf1] refine le_antisymm ((degree_le_iff_coeff_zero _ _).2 fun n hn => ?_) ?_ · rw [coeff_expand hp] split_ifs with hpn · rw [coeff_eq_zero_of_natDegree_lt] contrapose! hn norm_cast rw [← Nat.div_mul_cancel hpn] exact Nat.mul_le_mul_right p hn · rfl · refine le_degree_of_ne_zero ?_ rw [coeff_expand_mul hp, ← leadingCoeff] exact mt leadingCoeff_eq_zero.1 hf theorem leadingCoeff_expand {p : ℕ} {f : R[X]} (hp : 0 < p) : (expand R p f).leadingCoeff = f.leadingCoeff := by simp_rw [leadingCoeff, natDegree_expand, coeff_expand_mul hp] theorem monic_expand_iff {p : ℕ} {f : R[X]} (hp : 0 < p) : (expand R p f).Monic ↔ f.Monic := by simp only [Monic, leadingCoeff_expand hp] alias ⟨_, Monic.expand⟩ := monic_expand_iff theorem map_expand {p : ℕ} {f : R →+* S} {q : R[X]} : map f (expand R p q) = expand S p (map f q) := by by_cases hp : p = 0 · simp [hp] ext rw [coeff_map, coeff_expand (Nat.pos_of_ne_zero hp), coeff_expand (Nat.pos_of_ne_zero hp)] split_ifs <;> simp_all @[simp] theorem expand_eval (p : ℕ) (P : R[X]) (r : R) : eval r (expand R p P) = eval (r ^ p) P := by refine Polynomial.induction_on P (fun a => by simp) (fun f g hf hg => ?_) fun n a _ => by simp rw [map_add, eval_add, eval_add, hf, hg] @[simp] theorem expand_aeval {A : Type*} [Semiring A] [Algebra R A] (p : ℕ) (P : R[X]) (r : A) : aeval r (expand R p P) = aeval (r ^ p) P := by refine Polynomial.induction_on P (fun a => by simp) (fun f g hf hg => ?_) fun n a _ => by simp rw [map_add, aeval_add, aeval_add, hf, hg] /-- The opposite of `expand`: sends `∑ aₙ xⁿᵖ` to `∑ aₙ xⁿ`. -/ noncomputable def contract (p : ℕ) (f : R[X]) : R[X] := ∑ n ∈ range (f.natDegree + 1), monomial n (f.coeff (n * p)) theorem coeff_contract {p : ℕ} (hp : p ≠ 0) (f : R[X]) (n : ℕ) : (contract p f).coeff n = f.coeff (n * p) := by simp only [contract, coeff_monomial, sum_ite_eq', finset_sum_coeff, mem_range, not_lt, ite_eq_left_iff] intro hn apply (coeff_eq_zero_of_natDegree_lt _).symm calc f.natDegree < f.natDegree + 1 := Nat.lt_succ_self _ _ ≤ n * 1 := by simpa only [mul_one] using hn _ ≤ n * p := mul_le_mul_of_nonneg_left (show 1 ≤ p from hp.bot_lt) (zero_le n) theorem map_contract {p : ℕ} (hp : p ≠ 0) {f : R →+* S} {q : R[X]} : (q.contract p).map f = (q.map f).contract p := ext fun n ↦ by simp only [coeff_map, coeff_contract hp] theorem contract_expand {f : R[X]} (hp : p ≠ 0) : contract p (expand R p f) = f := by ext simp [coeff_contract hp, coeff_expand hp.bot_lt, Nat.mul_div_cancel _ hp.bot_lt] theorem contract_one {f : R[X]} : contract 1 f = f := ext fun n ↦ by rw [coeff_contract one_ne_zero, mul_one] @[simp] theorem contract_C (r : R) : contract p (C r) = C r := by simp [contract] theorem contract_add {p : ℕ} (hp : p ≠ 0) (f g : R[X]) : contract p (f + g) = contract p f + contract p g := by ext; simp_rw [coeff_add, coeff_contract hp, coeff_add] theorem contract_mul_expand {p : ℕ} (hp : p ≠ 0) (f g : R[X]) : contract p (f * expand R p g) = contract p f * g := by ext n rw [coeff_contract hp, coeff_mul, coeff_mul, ← sum_subset (s₁ := (antidiagonal n).image fun x ↦ (x.1 * p, x.2 * p)), sum_image] · simp_rw [coeff_expand_mul hp.bot_lt, coeff_contract hp] · intro x hx y hy eq; simpa only [Prod.ext_iff, Nat.mul_right_cancel_iff hp.bot_lt] using eq · simp_rw [subset_iff, mem_image, mem_antidiagonal]; rintro _ ⟨x, rfl, rfl⟩; simp_rw [add_mul] simp_rw [mem_image, mem_antidiagonal] intro ⟨x, y⟩ eq nex by_cases h : p ∣ y · obtain ⟨x, rfl⟩ : p ∣ x := (Nat.dvd_add_iff_left h).mpr (eq ▸ dvd_mul_left p n) obtain ⟨y, rfl⟩ := h refine (nex ⟨⟨x, y⟩, (Nat.mul_right_cancel_iff hp.bot_lt).mp ?_, by simp_rw [mul_comm]⟩).elim rw [← eq, mul_comm, mul_add] · rw [coeff_expand hp.bot_lt, if_neg h, mul_zero] @[simp] theorem isCoprime_expand {f g : R[X]} {p : ℕ} (hp : p ≠ 0) : IsCoprime (expand R p f) (expand R p g) ↔ IsCoprime f g := ⟨fun ⟨a, b, eq⟩ ↦ ⟨contract p a, contract p b, by simp_rw [← contract_mul_expand hp, ← contract_add hp, eq, ← C_1, contract_C]⟩, (·.map _)⟩ section ExpChar theorem expand_contract [CharP R p] [NoZeroDivisors R] {f : R[X]} (hf : Polynomial.derivative f = 0) (hp : p ≠ 0) : expand R p (contract p f) = f := by ext n rw [coeff_expand hp.bot_lt, coeff_contract hp] split_ifs with h · rw [Nat.div_mul_cancel h] · rcases n with - | n · exact absurd (dvd_zero p) h have := coeff_derivative f n rw [hf, coeff_zero, zero_eq_mul] at this rcases this with h' | _ · rw [h'] rename_i _ _ _ h' rw [← Nat.cast_succ, CharP.cast_eq_zero_iff R p] at h' exact absurd h' h variable [ExpChar R p] theorem expand_contract' [NoZeroDivisors R] {f : R[X]} (hf : Polynomial.derivative f = 0) : expand R p (contract p f) = f := by obtain _ | @⟨_, hprime, hchar⟩ := ‹ExpChar R p› · rw [expand_one, contract_one] · haveI := Fact.mk hchar; exact expand_contract p hf hprime.ne_zero theorem expand_char (f : R[X]) : map (frobenius R p) (expand R p f) = f ^ p := by refine f.induction_on' (fun a b ha hb => ?_) fun n a => ?_ · rw [map_add, Polynomial.map_add, ha, hb, add_pow_expChar] · rw [expand_monomial, map_monomial, ← C_mul_X_pow_eq_monomial, ← C_mul_X_pow_eq_monomial, mul_pow, ← C.map_pow, frobenius_def] ring theorem map_expand_pow_char (f : R[X]) (n : ℕ) : map (frobenius R p ^ n) (expand R (p ^ n) f) = f ^ p ^ n := by induction n with | zero => simp [RingHom.one_def] | succ _ n_ih => symm
rw [pow_succ, pow_mul, ← n_ih, ← expand_char, pow_succ', RingHom.mul_def, ← map_map, mul_comm, expand_mul, ← map_expand] end ExpChar end CommSemiring
Mathlib/Algebra/Polynomial/Expand.lean
271
277
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Analysis.Convex.Side import Mathlib.Geometry.Euclidean.Angle.Oriented.Rotation import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine /-! # Oriented angles. This file defines oriented angles in Euclidean affine spaces. ## Main definitions * `EuclideanGeometry.oangle`, with notation `∡`, is the oriented angle determined by three points. -/ noncomputable section open Module Complex open scoped Affine EuclideanGeometry Real RealInnerProductSpace ComplexConjugate namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)] /-- A fixed choice of positive orientation of Euclidean space `ℝ²` -/ abbrev o := @Module.Oriented.positiveOrientation /-- The oriented angle at `p₂` between the line segments to `p₁` and `p₃`, modulo `2 * π`. If either of those points equals `p₂`, this is 0. See `EuclideanGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (p₁ p₂ p₃ : P) : Real.Angle := o.oangle (p₁ -ᵥ p₂) (p₃ -ᵥ p₂) @[inherit_doc] scoped notation "∡" => EuclideanGeometry.oangle /-- Oriented angles are continuous when neither end point equals the middle point. -/ theorem continuousAt_oangle {x : P × P × P} (hx12 : x.1 ≠ x.2.1) (hx32 : x.2.2 ≠ x.2.1) : ContinuousAt (fun y : P × P × P => ∡ y.1 y.2.1 y.2.2) x := by unfold oangle fun_prop (disch := simp [*]) /-- The angle ∡AAB at a point. -/ @[simp] theorem oangle_self_left (p₁ p₂ : P) : ∡ p₁ p₁ p₂ = 0 := by simp [oangle] /-- The angle ∡ABB at a point. -/ @[simp] theorem oangle_self_right (p₁ p₂ : P) : ∡ p₁ p₂ p₂ = 0 := by simp [oangle] /-- The angle ∡ABA at a point. -/ @[simp] theorem oangle_self_left_right (p₁ p₂ : P) : ∡ p₁ p₂ p₁ = 0 := o.oangle_self _ /-- If the angle between three points is nonzero, the first two points are not equal. -/ theorem left_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₂ := by rw [← @vsub_ne_zero V]; exact o.left_ne_zero_of_oangle_ne_zero h /-- If the angle between three points is nonzero, the last two points are not equal. -/ theorem right_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₃ ≠ p₂ := by rw [← @vsub_ne_zero V]; exact o.right_ne_zero_of_oangle_ne_zero h /-- If the angle between three points is nonzero, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₃ := by rw [← (vsub_left_injective p₂).ne_iff]; exact o.ne_of_oangle_ne_zero h /-- If the angle between three points is `π`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π / 2`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π / 2`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π / 2`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `-π / 2`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `-π / 2`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `-π / 2`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the sign of the angle between three points is nonzero, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between three points is nonzero, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between three points is nonzero, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between three points is positive, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₁ ≠ p₂ := left_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is positive, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₃ ≠ p₂ := right_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is positive, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₁ ≠ p₃ := left_ne_right_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is negative, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₁ ≠ p₂ := left_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is negative, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₃ ≠ p₂ := right_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is negative, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₁ ≠ p₃ := left_ne_right_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- Reversing the order of the points passed to `oangle` negates the angle. -/ theorem oangle_rev (p₁ p₂ p₃ : P) : ∡ p₃ p₂ p₁ = -∡ p₁ p₂ p₃ := o.oangle_rev _ _ /-- Adding an angle to that with the order of the points reversed results in 0. -/ @[simp] theorem oangle_add_oangle_rev (p₁ p₂ p₃ : P) : ∡ p₁ p₂ p₃ + ∡ p₃ p₂ p₁ = 0 := o.oangle_add_oangle_rev _ _ /-- An oriented angle is zero if and only if the angle with the order of the points reversed is zero. -/ theorem oangle_eq_zero_iff_oangle_rev_eq_zero {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ↔ ∡ p₃ p₂ p₁ = 0 := o.oangle_eq_zero_iff_oangle_rev_eq_zero /-- An oriented angle is `π` if and only if the angle with the order of the points reversed is `π`. -/ theorem oangle_eq_pi_iff_oangle_rev_eq_pi {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ ∡ p₃ p₂ p₁ = π := o.oangle_eq_pi_iff_oangle_rev_eq_pi /-- An oriented angle is not zero or `π` if and only if the three points are affinely independent. -/ theorem oangle_ne_zero_and_ne_pi_iff_affineIndependent {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ ≠ 0 ∧ ∡ p₁ p₂ p₃ ≠ π ↔ AffineIndependent ℝ ![p₁, p₂, p₃] := by rw [oangle, o.oangle_ne_zero_and_ne_pi_iff_linearIndependent, affineIndependent_iff_linearIndependent_vsub ℝ _ (1 : Fin 3), ← linearIndependent_equiv (finSuccAboveEquiv (1 : Fin 3))] convert Iff.rfl ext i fin_cases i <;> rfl /-- An oriented angle is zero or `π` if and only if the three points are collinear. -/ theorem oangle_eq_zero_or_eq_pi_iff_collinear {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ∨ ∡ p₁ p₂ p₃ = π ↔ Collinear ℝ ({p₁, p₂, p₃} : Set P) := by rw [← not_iff_not, not_or, oangle_ne_zero_and_ne_pi_iff_affineIndependent, affineIndependent_iff_not_collinear_set] /-- An oriented angle has a sign zero if and only if the three points are collinear. -/ theorem oangle_sign_eq_zero_iff_collinear {p₁ p₂ p₃ : P} : (∡ p₁ p₂ p₃).sign = 0 ↔ Collinear ℝ ({p₁, p₂, p₃} : Set P) := by rw [Real.Angle.sign_eq_zero_iff, oangle_eq_zero_or_eq_pi_iff_collinear] /-- If twice the oriented angles between two triples of points are equal, one triple is affinely independent if and only if the other is. -/ theorem affineIndependent_iff_of_two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆) : AffineIndependent ℝ ![p₁, p₂, p₃] ↔ AffineIndependent ℝ ![p₄, p₅, p₆] := by simp_rw [← oangle_ne_zero_and_ne_pi_iff_affineIndependent, ← Real.Angle.two_zsmul_ne_zero_iff, h] /-- If twice the oriented angles between two triples of points are equal, one triple is collinear if and only if the other is. -/ theorem collinear_iff_of_two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆) : Collinear ℝ ({p₁, p₂, p₃} : Set P) ↔ Collinear ℝ ({p₄, p₅, p₆} : Set P) := by simp_rw [← oangle_eq_zero_or_eq_pi_iff_collinear, ← Real.Angle.two_zsmul_eq_zero_iff, h] /-- If corresponding pairs of points in two angles have the same vector span, twice those angles are equal. -/ theorem two_zsmul_oangle_of_vectorSpan_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h₁₂₄₅ : vectorSpan ℝ ({p₁, p₂} : Set P) = vectorSpan ℝ ({p₄, p₅} : Set P)) (h₃₂₆₅ : vectorSpan ℝ ({p₃, p₂} : Set P) = vectorSpan ℝ ({p₆, p₅} : Set P)) : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆ := by simp_rw [vectorSpan_pair] at h₁₂₄₅ h₃₂₆₅ exact o.two_zsmul_oangle_of_span_eq_of_span_eq h₁₂₄₅ h₃₂₆₅ /-- If the lines determined by corresponding pairs of points in two angles are parallel, twice those angles are equal. -/ theorem two_zsmul_oangle_of_parallel {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h₁₂₄₅ : line[ℝ, p₁, p₂] ∥ line[ℝ, p₄, p₅]) (h₃₂₆₅ : line[ℝ, p₃, p₂] ∥ line[ℝ, p₆, p₅]) : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆ := by rw [AffineSubspace.affineSpan_pair_parallel_iff_vectorSpan_eq] at h₁₂₄₅ h₃₂₆₅ exact two_zsmul_oangle_of_vectorSpan_eq h₁₂₄₅ h₃₂₆₅ /-- Given three points not equal to `p`, the angle between the first and the second at `p` plus the angle between the second and the third equals the angle between the first and the third. -/ @[simp] theorem oangle_add {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₂ + ∡ p₂ p p₃ = ∡ p₁ p p₃ := o.oangle_add (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Given three points not equal to `p`, the angle between the second and the third at `p` plus the angle between the first and the second equals the angle between the first and the third. -/ @[simp] theorem oangle_add_swap {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₂ p p₃ + ∡ p₁ p p₂ = ∡ p₁ p p₃ := o.oangle_add_swap (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Given three points not equal to `p`, the angle between the first and the third at `p` minus the angle between the first and the second equals the angle between the second and the third. -/ @[simp] theorem oangle_sub_left {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₃ - ∡ p₁ p p₂ = ∡ p₂ p p₃ := o.oangle_sub_left (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Given three points not equal to `p`, the angle between the first and the third at `p` minus the angle between the second and the third equals the angle between the first and the second. -/ @[simp] theorem oangle_sub_right {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₃ - ∡ p₂ p p₃ = ∡ p₁ p p₂ := o.oangle_sub_right (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Given three points not equal to `p`, adding the angles between them at `p` in cyclic order results in 0. -/ @[simp] theorem oangle_add_cyc3 {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₂ + ∡ p₂ p p₃ + ∡ p₃ p p₁ = 0 := o.oangle_add_cyc3 (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Pons asinorum, oriented angle-at-point form. -/ theorem oangle_eq_oangle_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) : ∡ p₁ p₂ p₃ = ∡ p₂ p₃ p₁ := by simp_rw [dist_eq_norm_vsub V] at h rw [oangle, oangle, ← vsub_sub_vsub_cancel_left p₃ p₂ p₁, ← vsub_sub_vsub_cancel_left p₂ p₃ p₁, o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h] /-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented angle-at-point form. -/ theorem oangle_eq_pi_sub_two_zsmul_oangle_of_dist_eq {p₁ p₂ p₃ : P} (hn : p₂ ≠ p₃) (h : dist p₁ p₂ = dist p₁ p₃) : ∡ p₃ p₁ p₂ = π - (2 : ℤ) • ∡ p₁ p₂ p₃ := by simp_rw [dist_eq_norm_vsub V] at h rw [oangle, oangle] convert o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq _ h using 1 · rw [← neg_vsub_eq_vsub_rev p₁ p₃, ← neg_vsub_eq_vsub_rev p₁ p₂, o.oangle_neg_neg] · rw [← o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h]; simp · simpa using hn /-- A base angle of an isosceles triangle is acute, oriented angle-at-point form. -/ theorem abs_oangle_right_toReal_lt_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) : |(∡ p₁ p₂ p₃).toReal| < π / 2 := by simp_rw [dist_eq_norm_vsub V] at h rw [oangle, ← vsub_sub_vsub_cancel_left p₃ p₂ p₁] exact o.abs_oangle_sub_right_toReal_lt_pi_div_two h /-- A base angle of an isosceles triangle is acute, oriented angle-at-point form. -/ theorem abs_oangle_left_toReal_lt_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) : |(∡ p₂ p₃ p₁).toReal| < π / 2 := oangle_eq_oangle_of_dist_eq h ▸ abs_oangle_right_toReal_lt_pi_div_two_of_dist_eq h /-- The cosine of the oriented angle at `p` between two points not equal to `p` equals that of the unoriented angle. -/ theorem cos_oangle_eq_cos_angle {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) : Real.Angle.cos (∡ p₁ p p₂) = Real.cos (∠ p₁ p p₂) := o.cos_oangle_eq_cos_angle (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) /-- The oriented angle at `p` between two points not equal to `p` is plus or minus the unoriented angle. -/ theorem oangle_eq_angle_or_eq_neg_angle {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) : ∡ p₁ p p₂ = ∠ p₁ p p₂ ∨ ∡ p₁ p p₂ = -∠ p₁ p p₂ := o.oangle_eq_angle_or_eq_neg_angle (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) /-- The unoriented angle at `p` between two points not equal to `p` is the absolute value of the oriented angle. -/ theorem angle_eq_abs_oangle_toReal {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) : ∠ p₁ p p₂ = |(∡ p₁ p p₂).toReal| := o.angle_eq_abs_oangle_toReal (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) /-- If the sign of the oriented angle at `p` between two points is zero, either one of the points equals `p` or the unoriented angle is 0 or π. -/ theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {p p₁ p₂ : P} (h : (∡ p₁ p p₂).sign = 0) : p₁ = p ∨ p₂ = p ∨ ∠ p₁ p p₂ = 0 ∨ ∠ p₁ p p₂ = π := by convert o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero h <;> simp /-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are equal, then the oriented angles are equal (even in degenerate cases). -/ theorem oangle_eq_of_angle_eq_of_sign_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : ∠ p₁ p₂ p₃ = ∠ p₄ p₅ p₆) (hs : (∡ p₁ p₂ p₃).sign = (∡ p₄ p₅ p₆).sign) : ∡ p₁ p₂ p₃ = ∡ p₄ p₅ p₆ := o.oangle_eq_of_angle_eq_of_sign_eq h hs /-- If the signs of two nondegenerate oriented angles between points are equal, the oriented angles are equal if and only if the unoriented angles are equal. -/ theorem angle_eq_iff_oangle_eq_of_sign_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (hp₁ : p₁ ≠ p₂) (hp₃ : p₃ ≠ p₂) (hp₄ : p₄ ≠ p₅) (hp₆ : p₆ ≠ p₅) (hs : (∡ p₁ p₂ p₃).sign = (∡ p₄ p₅ p₆).sign) : ∠ p₁ p₂ p₃ = ∠ p₄ p₅ p₆ ↔ ∡ p₁ p₂ p₃ = ∡ p₄ p₅ p₆ := o.angle_eq_iff_oangle_eq_of_sign_eq (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₃) (vsub_ne_zero.2 hp₄) (vsub_ne_zero.2 hp₆) hs /-- The oriented angle between three points equals the unoriented angle if the sign is positive. -/ theorem oangle_eq_angle_of_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : ∡ p₁ p₂ p₃ = ∠ p₁ p₂ p₃ := o.oangle_eq_angle_of_sign_eq_one h /-- The oriented angle between three points equals minus the unoriented angle if the sign is negative. -/ theorem oangle_eq_neg_angle_of_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : ∡ p₁ p₂ p₃ = -∠ p₁ p₂ p₃ := o.oangle_eq_neg_angle_of_sign_eq_neg_one h /-- The unoriented angle at `p` between two points not equal to `p` is zero if and only if the unoriented angle is zero. -/ theorem oangle_eq_zero_iff_angle_eq_zero {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) : ∡ p₁ p p₂ = 0 ↔ ∠ p₁ p p₂ = 0 := o.oangle_eq_zero_iff_angle_eq_zero (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) /-- The oriented angle between three points is `π` if and only if the unoriented angle is `π`. -/ theorem oangle_eq_pi_iff_angle_eq_pi {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ ∠ p₁ p₂ p₃ = π := o.oangle_eq_pi_iff_angle_eq_pi /-- If the oriented angle between three points is `π / 2`, so is the unoriented angle. -/ theorem angle_eq_pi_div_two_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∠ p₁ p₂ p₃ = π / 2 := by rw [angle, ← InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two] exact o.inner_eq_zero_of_oangle_eq_pi_div_two h /-- If the oriented angle between three points is `π / 2`, so is the unoriented angle (reversed). -/ theorem angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∠ p₃ p₂ p₁ = π / 2 := by rw [angle_comm] exact angle_eq_pi_div_two_of_oangle_eq_pi_div_two h /-- If the oriented angle between three points is `-π / 2`, the unoriented angle is `π / 2`. -/ theorem angle_eq_pi_div_two_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(-π / 2)) : ∠ p₁ p₂ p₃ = π / 2 := by rw [angle, ← InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two] exact o.inner_eq_zero_of_oangle_eq_neg_pi_div_two h /-- If the oriented angle between three points is `-π / 2`, the unoriented angle (reversed) is `π / 2`. -/ theorem angle_rev_eq_pi_div_two_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(-π / 2)) : ∠ p₃ p₂ p₁ = π / 2 := by rw [angle_comm] exact angle_eq_pi_div_two_of_oangle_eq_neg_pi_div_two h /-- Swapping the first and second points in an oriented angle negates the sign of that angle. -/ theorem oangle_swap₁₂_sign (p₁ p₂ p₃ : P) : -(∡ p₁ p₂ p₃).sign = (∡ p₂ p₁ p₃).sign := by rw [eq_comm, oangle, oangle, ← o.oangle_neg_neg, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, ← vsub_sub_vsub_cancel_left p₁ p₃ p₂, ← neg_vsub_eq_vsub_rev p₃ p₂, sub_eq_add_neg, neg_vsub_eq_vsub_rev p₂ p₁, add_comm, ← @neg_one_smul ℝ] nth_rw 2 [← one_smul ℝ (p₁ -ᵥ p₂)] rw [o.oangle_sign_smul_add_smul_right] simp /-- Swapping the first and third points in an oriented angle negates the sign of that angle. -/ theorem oangle_swap₁₃_sign (p₁ p₂ p₃ : P) : -(∡ p₁ p₂ p₃).sign = (∡ p₃ p₂ p₁).sign := by rw [oangle_rev, Real.Angle.sign_neg, neg_neg] /-- Swapping the second and third points in an oriented angle negates the sign of that angle. -/ theorem oangle_swap₂₃_sign (p₁ p₂ p₃ : P) : -(∡ p₁ p₂ p₃).sign = (∡ p₁ p₃ p₂).sign := by rw [oangle_swap₁₃_sign, ← oangle_swap₁₂_sign, oangle_swap₁₃_sign] /-- Rotating the points in an oriented angle does not change the sign of that angle. -/ theorem oangle_rotate_sign (p₁ p₂ p₃ : P) : (∡ p₂ p₃ p₁).sign = (∡ p₁ p₂ p₃).sign := by rw [← oangle_swap₁₂_sign, oangle_swap₁₃_sign] /-- The oriented angle between three points is π if and only if the second point is strictly between the other two. -/ theorem oangle_eq_pi_iff_sbtw {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ Sbtw ℝ p₁ p₂ p₃ := by rw [oangle_eq_pi_iff_angle_eq_pi, angle_eq_pi_iff_sbtw] /-- If the second of three points is strictly between the other two, the oriented angle at that point is π. -/ theorem _root_.Sbtw.oangle₁₂₃_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₁ p₂ p₃ = π := oangle_eq_pi_iff_sbtw.2 h /-- If the second of three points is strictly between the other two, the oriented angle at that point (reversed) is π. -/ theorem _root_.Sbtw.oangle₃₂₁_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₃ p₂ p₁ = π := by rw [oangle_eq_pi_iff_oangle_rev_eq_pi, ← h.oangle₁₂₃_eq_pi] /-- If the second of three points is weakly between the other two, the oriented angle at the first point is zero. -/ theorem _root_.Wbtw.oangle₂₁₃_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₁ p₃ = 0 := by by_cases hp₂p₁ : p₂ = p₁; · simp [hp₂p₁] by_cases hp₃p₁ : p₃ = p₁; · simp [hp₃p₁] rw [oangle_eq_zero_iff_angle_eq_zero hp₂p₁ hp₃p₁] exact h.angle₂₁₃_eq_zero_of_ne hp₂p₁ /-- If the second of three points is strictly between the other two, the oriented angle at the first point is zero. -/ theorem _root_.Sbtw.oangle₂₁₃_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₁ p₃ = 0 := h.wbtw.oangle₂₁₃_eq_zero /-- If the second of three points is weakly between the other two, the oriented angle at the first point (reversed) is zero. -/ theorem _root_.Wbtw.oangle₃₁₂_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₃ p₁ p₂ = 0 := by rw [oangle_eq_zero_iff_oangle_rev_eq_zero, h.oangle₂₁₃_eq_zero] /-- If the second of three points is strictly between the other two, the oriented angle at the first point (reversed) is zero. -/ theorem _root_.Sbtw.oangle₃₁₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₃ p₁ p₂ = 0 := h.wbtw.oangle₃₁₂_eq_zero /-- If the second of three points is weakly between the other two, the oriented angle at the third point is zero. -/ theorem _root_.Wbtw.oangle₂₃₁_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₃ p₁ = 0 := h.symm.oangle₂₁₃_eq_zero /-- If the second of three points is strictly between the other two, the oriented angle at the third point is zero. -/ theorem _root_.Sbtw.oangle₂₃₁_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₃ p₁ = 0 := h.wbtw.oangle₂₃₁_eq_zero /-- If the second of three points is weakly between the other two, the oriented angle at the third point (reversed) is zero. -/ theorem _root_.Wbtw.oangle₁₃₂_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₁ p₃ p₂ = 0 := h.symm.oangle₃₁₂_eq_zero /-- If the second of three points is strictly between the other two, the oriented angle at the third point (reversed) is zero. -/ theorem _root_.Sbtw.oangle₁₃₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₁ p₃ p₂ = 0 := h.wbtw.oangle₁₃₂_eq_zero /-- The oriented angle between three points is zero if and only if one of the first and third points is weakly between the other two. -/ theorem oangle_eq_zero_iff_wbtw {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ↔ Wbtw ℝ p₂ p₁ p₃ ∨ Wbtw ℝ p₂ p₃ p₁ := by by_cases hp₁p₂ : p₁ = p₂; · simp [hp₁p₂] by_cases hp₃p₂ : p₃ = p₂; · simp [hp₃p₂]
rw [oangle_eq_zero_iff_angle_eq_zero hp₁p₂ hp₃p₂, angle_eq_zero_iff_ne_and_wbtw] simp [hp₁p₂, hp₃p₂]
Mathlib/Geometry/Euclidean/Angle/Oriented/Affine.lean
470
471
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn -/ import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.Algebra.Order.Group.Pointwise.Bounds import Mathlib.Data.Real.Basic import Mathlib.Order.ConditionallyCompleteLattice.Indexed import Mathlib.Order.Interval.Set.Disjoint /-! # The real numbers are an Archimedean floor ring, and a conditionally complete linear order. -/ assert_not_exists Finset open Pointwise CauSeq namespace Real variable {ι : Sort*} {f : ι → ℝ} {s : Set ℝ} {a : ℝ} instance instArchimedean : Archimedean ℝ := archimedean_iff_rat_le.2 fun x => Real.ind_mk x fun f => let ⟨M, _, H⟩ := f.bounded' 0 ⟨M, mk_le_of_forall_le ⟨0, fun i _ => Rat.cast_le.2 <| le_of_lt (abs_lt.1 (H i)).2⟩⟩ noncomputable instance : FloorRing ℝ := Archimedean.floorRing _ theorem isCauSeq_iff_lift {f : ℕ → ℚ} : IsCauSeq abs f ↔ IsCauSeq abs fun i => (f i : ℝ) where mp H ε ε0 := let ⟨δ, δ0, δε⟩ := exists_pos_rat_lt ε0 (H _ δ0).imp fun i hi j ij => by dsimp; exact lt_trans (mod_cast hi _ ij) δε mpr H ε ε0 := (H _ (Rat.cast_pos.2 ε0)).imp fun i hi j ij => by dsimp at hi; exact mod_cast hi _ ij theorem of_near (f : ℕ → ℚ) (x : ℝ) (h : ∀ ε > 0, ∃ i, ∀ j ≥ i, |(f j : ℝ) - x| < ε) : ∃ h', Real.mk ⟨f, h'⟩ = x := ⟨isCauSeq_iff_lift.2 (CauSeq.of_near _ (const abs x) h), sub_eq_zero.1 <| abs_eq_zero.1 <| (eq_of_le_of_forall_lt_imp_le_of_dense (abs_nonneg _)) fun _ε ε0 => mk_near_of_forall_near <| (h _ ε0).imp fun _i h j ij => le_of_lt (h j ij)⟩ theorem exists_floor (x : ℝ) : ∃ ub : ℤ, (ub : ℝ) ≤ x ∧ ∀ z : ℤ, (z : ℝ) ≤ x → z ≤ ub := Int.exists_greatest_of_bdd (let ⟨n, hn⟩ := exists_int_gt x ⟨n, fun _ h' => Int.cast_le.1 <| le_trans h' <| le_of_lt hn⟩) (let ⟨n, hn⟩ := exists_int_lt x ⟨n, le_of_lt hn⟩) theorem exists_isLUB (hne : s.Nonempty) (hbdd : BddAbove s) : ∃ x, IsLUB s x := by rcases hne, hbdd with ⟨⟨L, hL⟩, ⟨U, hU⟩⟩ have : ∀ d : ℕ, BddAbove { m : ℤ | ∃ y ∈ s, (m : ℝ) ≤ y * d } := by obtain ⟨k, hk⟩ := exists_int_gt U refine fun d => ⟨k * d, fun z h => ?_⟩ rcases h with ⟨y, yS, hy⟩ refine Int.cast_le.1 (hy.trans ?_) push_cast exact mul_le_mul_of_nonneg_right ((hU yS).trans hk.le) d.cast_nonneg choose f hf using fun d : ℕ => Int.exists_greatest_of_bdd (this d) ⟨⌊L * d⌋, L, hL, Int.floor_le _⟩ have hf₁ : ∀ n > 0, ∃ y ∈ s, ((f n / n : ℚ) : ℝ) ≤ y := fun n n0 => let ⟨y, yS, hy⟩ := (hf n).1 ⟨y, yS, by simpa using (div_le_iff₀ (Nat.cast_pos.2 n0 : (_ : ℝ) < _)).2 hy⟩ have hf₂ : ∀ n > 0, ∀ y ∈ s, (y - ((n : ℕ) : ℝ)⁻¹) < (f n / n : ℚ) := by intro n n0 y yS have := (Int.sub_one_lt_floor _).trans_le (Int.cast_le.2 <| (hf n).2 _ ⟨y, yS, Int.floor_le _⟩) simp only [Rat.cast_div, Rat.cast_intCast, Rat.cast_natCast, gt_iff_lt] rwa [lt_div_iff₀ (Nat.cast_pos.2 n0 : (_ : ℝ) < _), sub_mul, inv_mul_cancel₀] exact ne_of_gt (Nat.cast_pos.2 n0) have hg : IsCauSeq abs (fun n => f n / n : ℕ → ℚ) := by intro ε ε0 suffices ∀ j ≥ ⌈ε⁻¹⌉₊, ∀ k ≥ ⌈ε⁻¹⌉₊, (f j / j - f k / k : ℚ) < ε by refine ⟨_, fun j ij => abs_lt.2 ⟨?_, this _ ij _ le_rfl⟩⟩ rw [neg_lt, neg_sub] exact this _ le_rfl _ ij intro j ij k ik replace ij := le_trans (Nat.le_ceil _) (Nat.cast_le.2 ij) replace ik := le_trans (Nat.le_ceil _) (Nat.cast_le.2 ik) have j0 := Nat.cast_pos.1 ((inv_pos.2 ε0).trans_le ij) have k0 := Nat.cast_pos.1 ((inv_pos.2 ε0).trans_le ik) rcases hf₁ _ j0 with ⟨y, yS, hy⟩ refine lt_of_lt_of_le ((Rat.cast_lt (K := ℝ)).1 ?_) ((inv_le_comm₀ ε0 (Nat.cast_pos.2 k0)).1 ik) simpa using sub_lt_iff_lt_add'.2 (lt_of_le_of_lt hy <| sub_lt_iff_lt_add.1 <| hf₂ _ k0 _ yS) let g : CauSeq ℚ abs := ⟨fun n => f n / n, hg⟩ refine ⟨mk g, ⟨fun x xS => ?_, fun y h => ?_⟩⟩ · refine le_of_forall_lt_imp_le_of_dense fun z xz => ?_ obtain ⟨K, hK⟩ := exists_nat_gt (x - z)⁻¹ refine le_mk_of_forall_le ⟨K, fun n nK => ?_⟩ replace xz := sub_pos.2 xz replace hK := hK.le.trans (Nat.cast_le.2 nK) have n0 : 0 < n := Nat.cast_pos.1 ((inv_pos.2 xz).trans_le hK) refine le_trans ?_ (hf₂ _ n0 _ xS).le rwa [le_sub_comm, inv_le_comm₀ (Nat.cast_pos.2 n0 : (_ : ℝ) < _) xz] · exact mk_le_of_forall_le ⟨1, fun n n1 => let ⟨x, xS, hx⟩ := hf₁ _ n1 le_trans hx (h xS)⟩ /-- A nonempty, bounded below set of real numbers has a greatest lower bound. -/ theorem exists_isGLB (hne : s.Nonempty) (hbdd : BddBelow s) : ∃ x, IsGLB s x := by have hne' : (-s).Nonempty := Set.nonempty_neg.mpr hne have hbdd' : BddAbove (-s) := bddAbove_neg.mpr hbdd use -Classical.choose (Real.exists_isLUB hne' hbdd') rw [← isLUB_neg] exact Classical.choose_spec (Real.exists_isLUB hne' hbdd') open scoped Classical in noncomputable instance : SupSet ℝ := ⟨fun s => if h : s.Nonempty ∧ BddAbove s then Classical.choose (exists_isLUB h.1 h.2) else 0⟩ open scoped Classical in theorem sSup_def (s : Set ℝ) : sSup s = if h : s.Nonempty ∧ BddAbove s then Classical.choose (exists_isLUB h.1 h.2) else 0 := rfl protected theorem isLUB_sSup (h₁ : s.Nonempty) (h₂ : BddAbove s) : IsLUB s (sSup s) := by simp only [sSup_def, dif_pos (And.intro h₁ h₂)] apply Classical.choose_spec noncomputable instance : InfSet ℝ := ⟨fun s => -sSup (-s)⟩ theorem sInf_def (s : Set ℝ) : sInf s = -sSup (-s) := rfl protected theorem isGLB_sInf (h₁ : s.Nonempty) (h₂ : BddBelow s) : IsGLB s (sInf s) := by rw [sInf_def, ← isLUB_neg', neg_neg] exact Real.isLUB_sSup h₁.neg h₂.neg noncomputable instance : ConditionallyCompleteLinearOrder ℝ where __ := Real.linearOrder __ := Real.lattice le_csSup s a hs ha := (Real.isLUB_sSup ⟨a, ha⟩ hs).1 ha csSup_le s a hs ha := (Real.isLUB_sSup hs ⟨a, ha⟩).2 ha csInf_le s a hs ha := (Real.isGLB_sInf ⟨a, ha⟩ hs).1 ha le_csInf s a hs ha := (Real.isGLB_sInf hs ⟨a, ha⟩).2 ha csSup_of_not_bddAbove s hs := by simp [hs, sSup_def] csInf_of_not_bddBelow s hs := by simp [hs, sInf_def, sSup_def] theorem lt_sInf_add_pos (h : s.Nonempty) {ε : ℝ} (hε : 0 < ε) : ∃ a ∈ s, a < sInf s + ε := exists_lt_of_csInf_lt h <| lt_add_of_pos_right _ hε theorem add_neg_lt_sSup (h : s.Nonempty) {ε : ℝ} (hε : ε < 0) : ∃ a ∈ s, sSup s + ε < a := exists_lt_of_lt_csSup h <| add_lt_iff_neg_left.2 hε theorem sInf_le_iff (h : BddBelow s) (h' : s.Nonempty) : sInf s ≤ a ↔ ∀ ε, 0 < ε → ∃ x ∈ s, x < a + ε := by rw [le_iff_forall_pos_lt_add] constructor <;> intro H ε ε_pos · exact exists_lt_of_csInf_lt h' (H ε ε_pos) · rcases H ε ε_pos with ⟨x, x_in, hx⟩ exact csInf_lt_of_lt h x_in hx theorem le_sSup_iff (h : BddAbove s) (h' : s.Nonempty) : a ≤ sSup s ↔ ∀ ε, ε < 0 → ∃ x ∈ s, a + ε < x := by rw [le_iff_forall_pos_lt_add] refine ⟨fun H ε ε_neg => ?_, fun H ε ε_pos => ?_⟩ · exact exists_lt_of_lt_csSup h' (lt_sub_iff_add_lt.mp (H _ (neg_pos.mpr ε_neg))) · rcases H _ (neg_lt_zero.mpr ε_pos) with ⟨x, x_in, hx⟩
exact sub_lt_iff_lt_add.mp (lt_csSup_of_lt h x_in hx) @[simp] theorem sSup_empty : sSup (∅ : Set ℝ) = 0 := dif_neg <| by simp @[simp] lemma iSup_of_isEmpty [IsEmpty ι] (f : ι → ℝ) : ⨆ i, f i = 0 := by
Mathlib/Data/Real/Archimedean.lean
165
171
/- 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
Mathlib/Data/QPF/Multivariate/Constructions/Cofix.lean
362
363
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Sébastien Gouëzel, Heather Macbeth, Patrick Massot, Floris van Doorn -/ import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps import Mathlib.Topology.FiberBundle.Basic /-! # Vector bundles In this file we define (topological) vector bundles. Let `B` be the base space, let `F` be a normed space over a normed field `R`, and let `E : B → Type*` be a `FiberBundle` with fiber `F`, in which, for each `x`, the fiber `E x` is a topological vector space over `R`. To have a vector bundle structure on `Bundle.TotalSpace F E`, one should additionally have the following properties: * The bundle trivializations in the trivialization atlas should be continuous linear equivs in the fibers; * For any two trivializations `e`, `e'` in the atlas the transition function considered as a map from `B` into `F →L[R] F` is continuous on `e.baseSet ∩ e'.baseSet` with respect to the operator norm topology on `F →L[R] F`. If these conditions are satisfied, we register the typeclass `VectorBundle R F E`. We define constructions on vector bundles like pullbacks and direct sums in other files. ## Main Definitions * `Trivialization.IsLinear`: a class stating that a trivialization is fiberwise linear on its base set. * `Trivialization.linearEquivAt` and `Trivialization.continuousLinearMapAt` are the (continuous) linear fiberwise equivalences a trivialization induces. * They have forward maps `Trivialization.linearMapAt` / `Trivialization.continuousLinearMapAt` and inverses `Trivialization.symmₗ` / `Trivialization.symmL`. Note that these are all defined everywhere, since they are extended using the zero function. * `Trivialization.coordChangeL` is the coordinate change induced by two trivializations. It only makes sense on the intersection of their base sets, but is extended outside it using the identity. * Given a continuous (semi)linear map between `E x` and `E' y` where `E` and `E'` are bundles over possibly different base sets, `ContinuousLinearMap.inCoordinates` turns this into a continuous (semi)linear map between the chosen fibers of those bundles. ## Implementation notes The implementation choices in the vector bundle definition are discussed in the "Implementation notes" section of `Mathlib.Topology.FiberBundle.Basic`. ## Tags Vector bundle -/ noncomputable section open Bundle Set Topology variable (R : Type*) {B : Type*} (F : Type*) (E : B → Type*) section TopologicalVectorSpace variable {F E} variable [Semiring R] [TopologicalSpace F] [TopologicalSpace B] /-- A mixin class for `Pretrivialization`, stating that a pretrivialization is fiberwise linear with respect to given module structures on its fibers and the model fiber. -/ protected class Pretrivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] (e : Pretrivialization F (π F E)) : Prop where linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 namespace Pretrivialization variable (e : Pretrivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b} theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 := Pretrivialization.IsLinear.linear b hb variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] /-- A fiberwise linear inverse to `e`. -/ @[simps!] protected def symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b := by refine IsLinearMap.mk' (e.symm b) ?_ by_cases hb : b ∈ e.baseSet · exact (((e.linear R hb).mk' _).inverse (e.symm b) (e.symm_apply_apply_mk hb) fun v ↦ congr_arg Prod.snd <| e.apply_mk_symm hb v).isLinear · rw [e.coe_symm_of_not_mem hb] exact (0 : F →ₗ[R] E b).isLinear /-- A pretrivialization for a vector bundle defines linear equivalences between the fibers and the model space. -/ @[simps -fullyApplied] def linearEquivAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) : E b ≃ₗ[R] F where toFun y := (e ⟨b, y⟩).2 invFun := e.symm b left_inv := e.symm_apply_apply_mk hb right_inv v := by simp_rw [e.apply_mk_symm hb v] map_add' v w := (e.linear R hb).map_add v w map_smul' c v := (e.linear R hb).map_smul c v open Classical in /-- A fiberwise linear map equal to `e` on `e.baseSet`. -/ protected def linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F := if hb : b ∈ e.baseSet then e.linearEquivAt R b hb else 0 variable {R} open Classical in theorem coe_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : ⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by rw [Pretrivialization.linearMapAt] split_ifs <;> rfl theorem coe_linearMapAt_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by simp_rw [coe_linearMapAt, if_pos hb] open Classical in theorem linearMapAt_apply (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) : e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by rw [coe_linearMapAt]
theorem linearMapAt_def_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb :=
Mathlib/Topology/VectorBundle/Basic.lean
126
128
/- Copyright (c) 2017 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Keeley Hoek -/ import Mathlib.Algebra.NeZero import Mathlib.Data.Int.DivMod import Mathlib.Logic.Embedding.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Tactic.Common import Mathlib.Tactic.Attr.Register /-! # The finite type with `n` elements `Fin n` is the type whose elements are natural numbers smaller than `n`. This file expands on the development in the core library. ## Main definitions ### Induction principles * `finZeroElim` : Elimination principle for the empty set `Fin 0`, generalizes `Fin.elim0`. Further definitions and eliminators can be found in `Init.Data.Fin.Lemmas` ### Embeddings and isomorphisms * `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`; * `Fin.succEmb` : `Fin.succ` as an `Embedding`; * `Fin.castLEEmb h` : `Fin.castLE` as an `Embedding`, embed `Fin n` into `Fin m`, `h : n ≤ m`; * `finCongr` : `Fin.cast` as an `Equiv`, equivalence between `Fin n` and `Fin m` when `n = m`; * `Fin.castAddEmb m` : `Fin.castAdd` as an `Embedding`, embed `Fin n` into `Fin (n+m)`; * `Fin.castSuccEmb` : `Fin.castSucc` as an `Embedding`, embed `Fin n` into `Fin (n+1)`; * `Fin.addNatEmb m i` : `Fin.addNat` as an `Embedding`, add `m` on `i` on the right, generalizes `Fin.succ`; * `Fin.natAddEmb n i` : `Fin.natAdd` as an `Embedding`, adds `n` on `i` on the left; ### Other casts * `Fin.divNat i` : divides `i : Fin (m * n)` by `n`; * `Fin.modNat i` : takes the mod of `i : Fin (m * n)` by `n`; -/ assert_not_exists Monoid Finset open Fin Nat Function attribute [simp] Fin.succ_ne_zero Fin.castSucc_lt_last /-- Elimination principle for the empty set `Fin 0`, dependent version. -/ def finZeroElim {α : Fin 0 → Sort*} (x : Fin 0) : α x := x.elim0 namespace Fin @[simp] theorem mk_eq_one {n a : Nat} {ha : a < n + 2} : (⟨a, ha⟩ : Fin (n + 2)) = 1 ↔ a = 1 := mk.inj_iff @[simp] theorem one_eq_mk {n a : Nat} {ha : a < n + 2} : 1 = (⟨a, ha⟩ : Fin (n + 2)) ↔ a = 1 := by simp [eq_comm] instance {n : ℕ} : CanLift ℕ (Fin n) Fin.val (· < n) where prf k hk := ⟨⟨k, hk⟩, rfl⟩ /-- A dependent variant of `Fin.elim0`. -/ def rec0 {α : Fin 0 → Sort*} (i : Fin 0) : α i := absurd i.2 (Nat.not_lt_zero _) variable {n m : ℕ} --variable {a b : Fin n} -- this *really* breaks stuff theorem val_injective : Function.Injective (@Fin.val n) := @Fin.eq_of_val_eq n /-- If you actually have an element of `Fin n`, then the `n` is always positive -/ lemma size_positive : Fin n → 0 < n := Fin.pos lemma size_positive' [Nonempty (Fin n)] : 0 < n := ‹Nonempty (Fin n)›.elim Fin.pos protected theorem prop (a : Fin n) : a.val < n := a.2 lemma lt_last_iff_ne_last {a : Fin (n + 1)} : a < last n ↔ a ≠ last n := by simp [Fin.lt_iff_le_and_ne, le_last] lemma ne_zero_of_lt {a b : Fin (n + 1)} (hab : a < b) : b ≠ 0 := Fin.ne_of_gt <| Fin.lt_of_le_of_lt a.zero_le hab lemma ne_last_of_lt {a b : Fin (n + 1)} (hab : a < b) : a ≠ last n := Fin.ne_of_lt <| Fin.lt_of_lt_of_le hab b.le_last /-- Equivalence between `Fin n` and `{ i // i < n }`. -/ @[simps apply symm_apply] def equivSubtype : Fin n ≃ { i // i < n } where toFun a := ⟨a.1, a.2⟩ invFun a := ⟨a.1, a.2⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl section coe /-! ### coercions and constructions -/ theorem val_eq_val (a b : Fin n) : (a : ℕ) = b ↔ a = b := Fin.ext_iff.symm theorem ne_iff_vne (a b : Fin n) : a ≠ b ↔ a.1 ≠ b.1 := Fin.ext_iff.not theorem mk_eq_mk {a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a' := Fin.ext_iff -- syntactic tautologies now /-- Assume `k = l`. If two functions defined on `Fin k` and `Fin l` are equal on each element, then they coincide (in the heq sense). -/ protected theorem heq_fun_iff {α : Sort*} {k l : ℕ} (h : k = l) {f : Fin k → α} {g : Fin l → α} : HEq f g ↔ ∀ i : Fin k, f i = g ⟨(i : ℕ), h ▸ i.2⟩ := by subst h simp [funext_iff] /-- Assume `k = l` and `k' = l'`. If two functions `Fin k → Fin k' → α` and `Fin l → Fin l' → α` are equal on each pair, then they coincide (in the heq sense). -/ protected theorem heq_fun₂_iff {α : Sort*} {k l k' l' : ℕ} (h : k = l) (h' : k' = l') {f : Fin k → Fin k' → α} {g : Fin l → Fin l' → α} : HEq f g ↔ ∀ (i : Fin k) (j : Fin k'), f i j = g ⟨(i : ℕ), h ▸ i.2⟩ ⟨(j : ℕ), h' ▸ j.2⟩ := by subst h subst h' simp [funext_iff] /-- Two elements of `Fin k` and `Fin l` are heq iff their values in `ℕ` coincide. This requires `k = l`. For the left implication without this assumption, see `val_eq_val_of_heq`. -/ protected theorem heq_ext_iff {k l : ℕ} (h : k = l) {i : Fin k} {j : Fin l} : HEq i j ↔ (i : ℕ) = (j : ℕ) := by subst h simp [val_eq_val] end coe section Order /-! ### order -/ theorem le_iff_val_le_val {a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b := Iff.rfl /-- `a < b` as natural numbers if and only if `a < b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_lt {n : ℕ} {a b : Fin n} : (a : ℕ) < (b : ℕ) ↔ a < b := Iff.rfl /-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_le {n : ℕ} {a b : Fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b := Iff.rfl theorem min_val {a : Fin n} : min (a : ℕ) n = a := by simp theorem max_val {a : Fin n} : max (a : ℕ) n = n := by simp /-- The inclusion map `Fin n → ℕ` is an embedding. -/ @[simps -fullyApplied apply] def valEmbedding : Fin n ↪ ℕ := ⟨val, val_injective⟩ @[simp] theorem equivSubtype_symm_trans_valEmbedding : equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) := rfl /-- Use the ordering on `Fin n` for checking recursive definitions. For example, the following definition is not accepted by the termination checker, unless we declare the `WellFoundedRelation` instance: ```lean def factorial {n : ℕ} : Fin n → ℕ | ⟨0, _⟩ := 1 | ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩ ``` -/ instance {n : ℕ} : WellFoundedRelation (Fin n) := measure (val : Fin n → ℕ) @[deprecated (since := "2025-02-24")] alias val_zero' := val_zero /-- `Fin.mk_zero` in `Lean` only applies in `Fin (n + 1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem mk_zero' (n : ℕ) [NeZero n] : (⟨0, pos_of_neZero n⟩ : Fin n) = 0 := rfl /-- The `Fin.zero_le` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] protected theorem zero_le' [NeZero n] (a : Fin n) : 0 ≤ a := Nat.zero_le a.val @[simp, norm_cast] theorem val_eq_zero_iff [NeZero n] {a : Fin n} : a.val = 0 ↔ a = 0 := by rw [Fin.ext_iff, val_zero] theorem val_ne_zero_iff [NeZero n] {a : Fin n} : a.val ≠ 0 ↔ a ≠ 0 := val_eq_zero_iff.not @[simp, norm_cast] theorem val_pos_iff [NeZero n] {a : Fin n} : 0 < a.val ↔ 0 < a := by rw [← val_fin_lt, val_zero] /-- The `Fin.pos_iff_ne_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ theorem pos_iff_ne_zero' [NeZero n] (a : Fin n) : 0 < a ↔ a ≠ 0 := by rw [← val_pos_iff, Nat.pos_iff_ne_zero, val_ne_zero_iff] @[simp] lemma cast_eq_self (a : Fin n) : a.cast rfl = a := rfl @[simp] theorem cast_eq_zero {k l : ℕ} [NeZero k] [NeZero l] (h : k = l) (x : Fin k) : Fin.cast h x = 0 ↔ x = 0 := by simp [← val_eq_zero_iff] lemma cast_injective {k l : ℕ} (h : k = l) : Injective (Fin.cast h) := fun a b hab ↦ by simpa [← val_eq_val] using hab theorem last_pos' [NeZero n] : 0 < last n := n.pos_of_neZero theorem one_lt_last [NeZero n] : 1 < last (n + 1) := by rw [lt_iff_val_lt_val, val_one, val_last, Nat.lt_add_left_iff_pos, Nat.pos_iff_ne_zero] exact NeZero.ne n end Order /-! ### Coercions to `ℤ` and the `fin_omega` tactic. -/ open Int theorem coe_int_sub_eq_ite {n : Nat} (u v : Fin n) : ((u - v : Fin n) : Int) = if v ≤ u then (u - v : Int) else (u - v : Int) + n := by rw [Fin.sub_def] split · rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega · rw [natCast_emod, Int.emod_eq_of_lt] <;> omega theorem coe_int_sub_eq_mod {n : Nat} (u v : Fin n) : ((u - v : Fin n) : Int) = ((u : Int) - (v : Int)) % n := by rw [coe_int_sub_eq_ite] split · rw [Int.emod_eq_of_lt] <;> omega · rw [Int.emod_eq_add_self_emod, Int.emod_eq_of_lt] <;> omega theorem coe_int_add_eq_ite {n : Nat} (u v : Fin n) : ((u + v : Fin n) : Int) = if (u + v : ℕ) < n then (u + v : Int) else (u + v : Int) - n := by rw [Fin.add_def] split · rw [natCast_emod, Int.emod_eq_of_lt] <;> omega · rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega theorem coe_int_add_eq_mod {n : Nat} (u v : Fin n) : ((u + v : Fin n) : Int) = ((u : Int) + (v : Int)) % n := by rw [coe_int_add_eq_ite] split · rw [Int.emod_eq_of_lt] <;> omega · rw [Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega -- Write `a + b` as `if (a + b : ℕ) < n then (a + b : ℤ) else (a + b : ℤ) - n` and -- similarly `a - b` as `if (b : ℕ) ≤ a then (a - b : ℤ) else (a - b : ℤ) + n`. attribute [fin_omega] coe_int_sub_eq_ite coe_int_add_eq_ite -- Rewrite inequalities in `Fin` to inequalities in `ℕ` attribute [fin_omega] Fin.lt_iff_val_lt_val Fin.le_iff_val_le_val -- Rewrite `1 : Fin (n + 2)` to `1 : ℤ` attribute [fin_omega] val_one /-- Preprocessor for `omega` to handle inequalities in `Fin`. Note that this involves a lot of case splitting, so may be slow. -/ -- Further adjustment to the simp set can probably make this more powerful. -- Please experiment and PR updates! macro "fin_omega" : tactic => `(tactic| { try simp only [fin_omega, ← Int.ofNat_lt, ← Int.ofNat_le] at * omega }) section Add /-! ### addition, numerals, and coercion from Nat -/ @[simp] theorem val_one' (n : ℕ) [NeZero n] : ((1 : Fin n) : ℕ) = 1 % n := rfl @[deprecated val_one' (since := "2025-03-10")] theorem val_one'' {n : ℕ} : ((1 : Fin (n + 1)) : ℕ) = 1 % (n + 1) := rfl instance nontrivial {n : ℕ} : Nontrivial (Fin (n + 2)) where exists_pair_ne := ⟨0, 1, (ne_iff_vne 0 1).mpr (by simp [val_one, val_zero])⟩ theorem nontrivial_iff_two_le : Nontrivial (Fin n) ↔ 2 ≤ n := by rcases n with (_ | _ | n) <;> simp [Fin.nontrivial, not_nontrivial, Nat.succ_le_iff] section Monoid instance inhabitedFinOneAdd (n : ℕ) : Inhabited (Fin (1 + n)) := haveI : NeZero (1 + n) := by rw [Nat.add_comm]; infer_instance inferInstance @[simp] theorem default_eq_zero (n : ℕ) [NeZero n] : (default : Fin n) = 0 := rfl instance instNatCast [NeZero n] : NatCast (Fin n) where natCast i := Fin.ofNat' n i lemma natCast_def [NeZero n] (a : ℕ) : (a : Fin n) = ⟨a % n, mod_lt _ n.pos_of_neZero⟩ := rfl end Monoid theorem val_add_eq_ite {n : ℕ} (a b : Fin n) : (↑(a + b) : ℕ) = if n ≤ a + b then a + b - n else a + b := by rw [Fin.val_add, Nat.add_mod_eq_ite, Nat.mod_eq_of_lt (show ↑a < n from a.2), Nat.mod_eq_of_lt (show ↑b < n from b.2)] theorem val_add_eq_of_add_lt {n : ℕ} {a b : Fin n} (huv : a.val + b.val < n) : (a + b).val = a.val + b.val := by rw [val_add] simp [Nat.mod_eq_of_lt huv] lemma intCast_val_sub_eq_sub_add_ite {n : ℕ} (a b : Fin n) : ((a - b).val : ℤ) = a.val - b.val + if b ≤ a then 0 else n := by split <;> fin_omega lemma one_le_of_ne_zero {n : ℕ} [NeZero n] {k : Fin n} (hk : k ≠ 0) : 1 ≤ k := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n) cases n with | zero => simp only [Nat.reduceAdd, Fin.isValue, Fin.zero_le] | succ n => rwa [Fin.le_iff_val_le_val, Fin.val_one, Nat.one_le_iff_ne_zero, val_ne_zero_iff] lemma val_sub_one_of_ne_zero [NeZero n] {i : Fin n} (hi : i ≠ 0) : (i - 1).val = i - 1 := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n) rw [Fin.sub_val_of_le (one_le_of_ne_zero hi), Fin.val_one', Nat.mod_eq_of_lt (Nat.succ_le_iff.mpr (nontrivial_iff_two_le.mp <| nontrivial_of_ne i 0 hi))] section OfNatCoe @[simp] theorem ofNat'_eq_cast (n : ℕ) [NeZero n] (a : ℕ) : Fin.ofNat' n a = a := rfl @[simp] lemma val_natCast (a n : ℕ) [NeZero n] : (a : Fin n).val = a % n := rfl /-- Converting an in-range number to `Fin (n + 1)` produces a result whose value is the original number. -/ theorem val_cast_of_lt {n : ℕ} [NeZero n] {a : ℕ} (h : a < n) : (a : Fin n).val = a := Nat.mod_eq_of_lt h /-- If `n` is non-zero, converting the value of a `Fin n` to `Fin n` results in the same value. -/ @[simp, norm_cast] theorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a := Fin.ext <| val_cast_of_lt a.isLt -- This is a special case of `CharP.cast_eq_zero` that doesn't require typeclass search @[simp high] lemma natCast_self (n : ℕ) [NeZero n] : (n : Fin n) = 0 := by ext; simp @[simp] lemma natCast_eq_zero {a n : ℕ} [NeZero n] : (a : Fin n) = 0 ↔ n ∣ a := by simp [Fin.ext_iff, Nat.dvd_iff_mod_eq_zero] @[simp] theorem natCast_eq_last (n) : (n : Fin (n + 1)) = Fin.last n := by ext; simp theorem le_val_last (i : Fin (n + 1)) : i ≤ n := by rw [Fin.natCast_eq_last] exact Fin.le_last i variable {a b : ℕ} lemma natCast_le_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) ≤ b ↔ a ≤ b := by rw [← Nat.lt_succ_iff] at han hbn simp [le_iff_val_le_val, -val_fin_le, Nat.mod_eq_of_lt, han, hbn] lemma natCast_lt_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) < b ↔ a < b := by rw [← Nat.lt_succ_iff] at han hbn; simp [lt_iff_val_lt_val, Nat.mod_eq_of_lt, han, hbn] lemma natCast_mono (hbn : b ≤ n) (hab : a ≤ b) : (a : Fin (n + 1)) ≤ b := (natCast_le_natCast (hab.trans hbn) hbn).2 hab lemma natCast_strictMono (hbn : b ≤ n) (hab : a < b) : (a : Fin (n + 1)) < b := (natCast_lt_natCast (hab.le.trans hbn) hbn).2 hab end OfNatCoe end Add section Succ /-! ### succ and casts into larger Fin types -/ lemma succ_injective (n : ℕ) : Injective (@Fin.succ n) := fun a b ↦ by simp [Fin.ext_iff] /-- `Fin.succ` as an `Embedding` -/ def succEmb (n : ℕ) : Fin n ↪ Fin (n + 1) where toFun := succ inj' := succ_injective _ @[simp] theorem coe_succEmb : ⇑(succEmb n) = Fin.succ := rfl @[deprecated (since := "2025-04-12")] alias val_succEmb := coe_succEmb @[simp] theorem exists_succ_eq {x : Fin (n + 1)} : (∃ y, Fin.succ y = x) ↔ x ≠ 0 := ⟨fun ⟨_, hy⟩ => hy ▸ succ_ne_zero _, x.cases (fun h => h.irrefl.elim) (fun _ _ => ⟨_, rfl⟩)⟩ theorem exists_succ_eq_of_ne_zero {x : Fin (n + 1)} (h : x ≠ 0) : ∃ y, Fin.succ y = x := exists_succ_eq.mpr h @[simp] theorem succ_zero_eq_one' [NeZero n] : Fin.succ (0 : Fin n) = 1 := by cases n · exact (NeZero.ne 0 rfl).elim · rfl theorem one_pos' [NeZero n] : (0 : Fin (n + 1)) < 1 := succ_zero_eq_one' (n := n) ▸ succ_pos _ theorem zero_ne_one' [NeZero n] : (0 : Fin (n + 1)) ≠ 1 := Fin.ne_of_lt one_pos' /-- The `Fin.succ_one_eq_two` in `Lean` only applies in `Fin (n+2)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem succ_one_eq_two' [NeZero n] : Fin.succ (1 : Fin (n + 1)) = 2 := by cases n · exact (NeZero.ne 0 rfl).elim · rfl -- Version of `succ_one_eq_two` to be used by `dsimp`. -- Note the `'` swapped around due to a move to std4. /-- The `Fin.le_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem le_zero_iff' {n : ℕ} [NeZero n] {k : Fin n} : k ≤ 0 ↔ k = 0 := ⟨fun h => Fin.ext <| by rw [Nat.eq_zero_of_le_zero h]; rfl, by rintro rfl; exact Nat.le_refl _⟩ -- TODO: Move to Batteries @[simp] lemma castLE_inj {hmn : m ≤ n} {a b : Fin m} : castLE hmn a = castLE hmn b ↔ a = b := by simp [Fin.ext_iff] @[simp] lemma castAdd_inj {a b : Fin m} : castAdd n a = castAdd n b ↔ a = b := by simp [Fin.ext_iff] attribute [simp] castSucc_inj lemma castLE_injective (hmn : m ≤ n) : Injective (castLE hmn) := fun _ _ hab ↦ Fin.ext (congr_arg val hab :) lemma castAdd_injective (m n : ℕ) : Injective (@Fin.castAdd m n) := castLE_injective _ lemma castSucc_injective (n : ℕ) : Injective (@Fin.castSucc n) := castAdd_injective _ _ /-- `Fin.castLE` as an `Embedding`, `castLEEmb h i` embeds `i` into a larger `Fin` type. -/ @[simps apply] def castLEEmb (h : n ≤ m) : Fin n ↪ Fin m where toFun := castLE h inj' := castLE_injective _ @[simp, norm_cast] lemma coe_castLEEmb {m n} (hmn : m ≤ n) : castLEEmb hmn = castLE hmn := rfl /- The next proof can be golfed a lot using `Fintype.card`. It is written this way to define `ENat.card` and `Nat.card` without a `Fintype` dependency (not done yet). -/ lemma nonempty_embedding_iff : Nonempty (Fin n ↪ Fin m) ↔ n ≤ m := by refine ⟨fun h ↦ ?_, fun h ↦ ⟨castLEEmb h⟩⟩ induction n generalizing m with | zero => exact m.zero_le | succ n ihn => obtain ⟨e⟩ := h rcases exists_eq_succ_of_ne_zero (pos_iff_nonempty.2 (Nonempty.map e inferInstance)).ne' with ⟨m, rfl⟩ refine Nat.succ_le_succ <| ihn ⟨?_⟩ refine ⟨fun i ↦ (e.setValue 0 0 i.succ).pred (mt e.setValue_eq_iff.1 i.succ_ne_zero), fun i j h ↦ ?_⟩ simpa only [pred_inj, EmbeddingLike.apply_eq_iff_eq, succ_inj] using h lemma equiv_iff_eq : Nonempty (Fin m ≃ Fin n) ↔ m = n := ⟨fun ⟨e⟩ ↦ le_antisymm (nonempty_embedding_iff.1 ⟨e⟩) (nonempty_embedding_iff.1 ⟨e.symm⟩), fun h ↦ h ▸ ⟨.refl _⟩⟩ @[simp] lemma castLE_castSucc {n m} (i : Fin n) (h : n + 1 ≤ m) : i.castSucc.castLE h = i.castLE (Nat.le_of_succ_le h) := rfl @[simp] lemma castLE_comp_castSucc {n m} (h : n + 1 ≤ m) : Fin.castLE h ∘ Fin.castSucc = Fin.castLE (Nat.le_of_succ_le h) := rfl @[simp] lemma castLE_rfl (n : ℕ) : Fin.castLE (le_refl n) = id := rfl @[simp] theorem range_castLE {n k : ℕ} (h : n ≤ k) : Set.range (castLE h) = { i : Fin k | (i : ℕ) < n } := Set.ext fun x => ⟨fun ⟨y, hy⟩ => hy ▸ y.2, fun hx => ⟨⟨x, hx⟩, rfl⟩⟩ @[simp] theorem coe_of_injective_castLE_symm {n k : ℕ} (h : n ≤ k) (i : Fin k) (hi) : ((Equiv.ofInjective _ (castLE_injective h)).symm ⟨i, hi⟩ : ℕ) = i := by rw [← coe_castLE h] exact congr_arg Fin.val (Equiv.apply_ofInjective_symm _ _) theorem leftInverse_cast (eq : n = m) : LeftInverse (Fin.cast eq.symm) (Fin.cast eq) := fun _ => rfl theorem rightInverse_cast (eq : n = m) : RightInverse (Fin.cast eq.symm) (Fin.cast eq) := fun _ => rfl @[simp] theorem cast_inj (eq : n = m) {a b : Fin n} : a.cast eq = b.cast eq ↔ a = b := by simp [← val_inj] @[simp] theorem cast_lt_cast (eq : n = m) {a b : Fin n} : a.cast eq < b.cast eq ↔ a < b := Iff.rfl @[simp] theorem cast_le_cast (eq : n = m) {a b : Fin n} : a.cast eq ≤ b.cast eq ↔ a ≤ b := Iff.rfl /-- The 'identity' equivalence between `Fin m` and `Fin n` when `m = n`. -/ @[simps] def _root_.finCongr (eq : n = m) : Fin n ≃ Fin m where toFun := Fin.cast eq invFun := Fin.cast eq.symm left_inv := leftInverse_cast eq right_inv := rightInverse_cast eq @[simp] lemma _root_.finCongr_apply_mk (h : m = n) (k : ℕ) (hk : k < m) : finCongr h ⟨k, hk⟩ = ⟨k, h ▸ hk⟩ := rfl @[simp] lemma _root_.finCongr_refl (h : n = n := rfl) : finCongr h = Equiv.refl (Fin n) := by ext; simp @[simp] lemma _root_.finCongr_symm (h : m = n) : (finCongr h).symm = finCongr h.symm := rfl @[simp] lemma _root_.finCongr_apply_coe (h : m = n) (k : Fin m) : (finCongr h k : ℕ) = k := rfl lemma _root_.finCongr_symm_apply_coe (h : m = n) (k : Fin n) : ((finCongr h).symm k : ℕ) = k := rfl /-- While in many cases `finCongr` is better than `Equiv.cast`/`cast`, sometimes we want to apply a generic theorem about `cast`. -/ lemma _root_.finCongr_eq_equivCast (h : n = m) : finCongr h = .cast (h ▸ rfl) := by subst h; simp /-- While in many cases `Fin.cast` is better than `Equiv.cast`/`cast`, sometimes we want to apply a generic theorem about `cast`. -/ theorem cast_eq_cast (h : n = m) : (Fin.cast h : Fin n → Fin m) = _root_.cast (h ▸ rfl) := by subst h ext rfl /-- `Fin.castAdd` as an `Embedding`, `castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`. See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/ def castAddEmb (m) : Fin n ↪ Fin (n + m) := castLEEmb (le_add_right n m) @[simp] lemma coe_castAddEmb (m) : (castAddEmb m : Fin n → Fin (n + m)) = castAdd m := rfl lemma castAddEmb_apply (m) (i : Fin n) : castAddEmb m i = castAdd m i := rfl /-- `Fin.castSucc` as an `Embedding`, `castSuccEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/ def castSuccEmb : Fin n ↪ Fin (n + 1) := castAddEmb _ @[simp, norm_cast] lemma coe_castSuccEmb : (castSuccEmb : Fin n → Fin (n + 1)) = Fin.castSucc := rfl lemma castSuccEmb_apply (i : Fin n) : castSuccEmb i = i.castSucc := rfl theorem castSucc_le_succ {n} (i : Fin n) : i.castSucc ≤ i.succ := Nat.le_succ i @[simp] theorem castSucc_le_castSucc_iff {a b : Fin n} : castSucc a ≤ castSucc b ↔ a ≤ b := .rfl @[simp] theorem succ_le_castSucc_iff {a b : Fin n} : succ a ≤ castSucc b ↔ a < b := by rw [le_castSucc_iff, succ_lt_succ_iff] @[simp] theorem castSucc_lt_succ_iff {a b : Fin n} : castSucc a < succ b ↔ a ≤ b := by rw [castSucc_lt_iff_succ_le, succ_le_succ_iff] theorem le_of_castSucc_lt_of_succ_lt {a b : Fin (n + 1)} {i : Fin n} (hl : castSucc i < a) (hu : b < succ i) : b < a := by simp [Fin.lt_def, -val_fin_lt] at *; omega theorem castSucc_lt_or_lt_succ (p : Fin (n + 1)) (i : Fin n) : castSucc i < p ∨ p < i.succ := by simp [Fin.lt_def, -val_fin_lt]; omega theorem succ_le_or_le_castSucc (p : Fin (n + 1)) (i : Fin n) : succ i ≤ p ∨ p ≤ i.castSucc := by rw [le_castSucc_iff, ← castSucc_lt_iff_succ_le] exact p.castSucc_lt_or_lt_succ i theorem eq_castSucc_of_ne_last {x : Fin (n + 1)} (h : x ≠ (last _)) : ∃ y, Fin.castSucc y = x := exists_castSucc_eq.mpr h @[deprecated (since := "2025-02-06")] alias exists_castSucc_eq_of_ne_last := eq_castSucc_of_ne_last theorem forall_fin_succ' {P : Fin (n + 1) → Prop} : (∀ i, P i) ↔ (∀ i : Fin n, P i.castSucc) ∧ P (.last _) := ⟨fun H => ⟨fun _ => H _, H _⟩, fun ⟨H0, H1⟩ i => Fin.lastCases H1 H0 i⟩ -- to match `Fin.eq_zero_or_eq_succ` theorem eq_castSucc_or_eq_last {n : Nat} (i : Fin (n + 1)) : (∃ j : Fin n, i = j.castSucc) ∨ i = last n := i.lastCases (Or.inr rfl) (Or.inl ⟨·, rfl⟩) @[simp] theorem castSucc_ne_last {n : ℕ} (i : Fin n) : i.castSucc ≠ .last n := Fin.ne_of_lt i.castSucc_lt_last theorem exists_fin_succ' {P : Fin (n + 1) → Prop} : (∃ i, P i) ↔ (∃ i : Fin n, P i.castSucc) ∨ P (.last _) := ⟨fun ⟨i, h⟩ => Fin.lastCases Or.inr (fun i hi => Or.inl ⟨i, hi⟩) i h, fun h => h.elim (fun ⟨i, hi⟩ => ⟨i.castSucc, hi⟩) (fun h => ⟨.last _, h⟩)⟩ /-- The `Fin.castSucc_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem castSucc_zero' [NeZero n] : castSucc (0 : Fin n) = 0 := rfl @[simp] theorem castSucc_pos_iff [NeZero n] {i : Fin n} : 0 < castSucc i ↔ 0 < i := by simp [← val_pos_iff] /-- `castSucc i` is positive when `i` is positive. The `Fin.castSucc_pos` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ alias ⟨_, castSucc_pos'⟩ := castSucc_pos_iff /-- The `Fin.castSucc_eq_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem castSucc_eq_zero_iff' [NeZero n] (a : Fin n) : castSucc a = 0 ↔ a = 0 := Fin.ext_iff.trans <| (Fin.ext_iff.trans <| by simp).symm /-- The `Fin.castSucc_ne_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ theorem castSucc_ne_zero_iff' [NeZero n] (a : Fin n) : castSucc a ≠ 0 ↔ a ≠ 0 := not_iff_not.mpr <| castSucc_eq_zero_iff' a theorem castSucc_ne_zero_of_lt {p i : Fin n} (h : p < i) : castSucc i ≠ 0 := by cases n · exact i.elim0 · rw [castSucc_ne_zero_iff', Ne, Fin.ext_iff] exact ((zero_le _).trans_lt h).ne' theorem succ_ne_last_iff (a : Fin (n + 1)) : succ a ≠ last (n + 1) ↔ a ≠ last n := not_iff_not.mpr <| succ_eq_last_succ theorem succ_ne_last_of_lt {p i : Fin n} (h : i < p) : succ i ≠ last n := by cases n · exact i.elim0 · rw [succ_ne_last_iff, Ne, Fin.ext_iff] exact ((le_last _).trans_lt' h).ne @[norm_cast, simp] theorem coe_eq_castSucc {a : Fin n} : (a : Fin (n + 1)) = castSucc a := by ext exact val_cast_of_lt (Nat.lt.step a.is_lt) theorem coe_succ_lt_iff_lt {n : ℕ} {j k : Fin n} : (j : Fin <| n + 1) < k ↔ j < k := by simp only [coe_eq_castSucc, castSucc_lt_castSucc_iff] @[simp] theorem range_castSucc {n : ℕ} : Set.range (castSucc : Fin n → Fin n.succ) = ({ i | (i : ℕ) < n } : Set (Fin n.succ)) := range_castLE (by omega) @[simp] theorem coe_of_injective_castSucc_symm {n : ℕ} (i : Fin n.succ) (hi) : ((Equiv.ofInjective castSucc (castSucc_injective _)).symm ⟨i, hi⟩ : ℕ) = i := by rw [← coe_castSucc] exact congr_arg val (Equiv.apply_ofInjective_symm _ _) /-- `Fin.addNat` as an `Embedding`, `addNatEmb m i` adds `m` to `i`, generalizes `Fin.succ`. -/ @[simps! apply] def addNatEmb (m) : Fin n ↪ Fin (n + m) where toFun := (addNat · m) inj' a b := by simp [Fin.ext_iff] /-- `Fin.natAdd` as an `Embedding`, `natAddEmb n i` adds `n` to `i` "on the left". -/ @[simps! apply] def natAddEmb (n) {m} : Fin m ↪ Fin (n + m) where toFun := natAdd n inj' a b := by simp [Fin.ext_iff] theorem castSucc_castAdd (i : Fin n) : castSucc (castAdd m i) = castAdd (m + 1) i := rfl theorem castSucc_natAdd (i : Fin m) : castSucc (natAdd n i) = natAdd n (castSucc i) := rfl theorem succ_castAdd (i : Fin n) : succ (castAdd m i) = if h : i.succ = last _ then natAdd n (0 : Fin (m + 1)) else castAdd (m + 1) ⟨i.1 + 1, lt_of_le_of_ne i.2 (Fin.val_ne_iff.mpr h)⟩ := by split_ifs with h exacts [Fin.ext (congr_arg Fin.val h :), rfl] theorem succ_natAdd (i : Fin m) : succ (natAdd n i) = natAdd n (succ i) := rfl end Succ section Pred /-! ### pred -/ theorem pred_one' [NeZero n] (h := (zero_ne_one' (n := n)).symm) : Fin.pred (1 : Fin (n + 1)) h = 0 := by simp_rw [Fin.ext_iff, coe_pred, val_one', val_zero, Nat.sub_eq_zero_iff_le, Nat.mod_le] theorem pred_last (h := Fin.ext_iff.not.2 last_pos'.ne') : pred (last (n + 1)) h = last n := by simp_rw [← succ_last, pred_succ] theorem pred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi < j ↔ i < succ j := by rw [← succ_lt_succ_iff, succ_pred] theorem lt_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j < pred i hi ↔ succ j < i := by rw [← succ_lt_succ_iff, succ_pred] theorem pred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi ≤ j ↔ i ≤ succ j := by rw [← succ_le_succ_iff, succ_pred] theorem le_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j ≤ pred i hi ↔ succ j ≤ i := by rw [← succ_le_succ_iff, succ_pred] theorem castSucc_pred_eq_pred_castSucc {a : Fin (n + 1)} (ha : a ≠ 0) (ha' := castSucc_ne_zero_iff.mpr ha) : (a.pred ha).castSucc = (castSucc a).pred ha' := rfl theorem castSucc_pred_add_one_eq {a : Fin (n + 1)} (ha : a ≠ 0) : (a.pred ha).castSucc + 1 = a := by cases a using cases · exact (ha rfl).elim · rw [pred_succ, coeSucc_eq_succ] theorem le_pred_castSucc_iff {a b : Fin (n + 1)} (ha : castSucc a ≠ 0) : b ≤ (castSucc a).pred ha ↔ b < a := by rw [le_pred_iff, succ_le_castSucc_iff] theorem pred_castSucc_lt_iff {a b : Fin (n + 1)} (ha : castSucc a ≠ 0) : (castSucc a).pred ha < b ↔ a ≤ b := by rw [pred_lt_iff, castSucc_lt_succ_iff] theorem pred_castSucc_lt {a : Fin (n + 1)} (ha : castSucc a ≠ 0) : (castSucc a).pred ha < a := by rw [pred_castSucc_lt_iff, le_def] theorem le_castSucc_pred_iff {a b : Fin (n + 1)} (ha : a ≠ 0) : b ≤ castSucc (a.pred ha) ↔ b < a := by rw [castSucc_pred_eq_pred_castSucc, le_pred_castSucc_iff] theorem castSucc_pred_lt_iff {a b : Fin (n + 1)} (ha : a ≠ 0) : castSucc (a.pred ha) < b ↔ a ≤ b := by rw [castSucc_pred_eq_pred_castSucc, pred_castSucc_lt_iff] theorem castSucc_pred_lt {a : Fin (n + 1)} (ha : a ≠ 0) : castSucc (a.pred ha) < a := by rw [castSucc_pred_lt_iff, le_def] end Pred section CastPred /-- `castPred i` sends `i : Fin (n + 1)` to `Fin n` as long as i ≠ last n. -/ @[inline] def castPred (i : Fin (n + 1)) (h : i ≠ last n) : Fin n := castLT i (val_lt_last h) @[simp] lemma castLT_eq_castPred (i : Fin (n + 1)) (h : i < last _) (h' := Fin.ext_iff.not.2 h.ne) : castLT i h = castPred i h' := rfl @[simp] lemma coe_castPred (i : Fin (n + 1)) (h : i ≠ last _) : (castPred i h : ℕ) = i := rfl @[simp] theorem castPred_castSucc {i : Fin n} (h' := Fin.ext_iff.not.2 (castSucc_lt_last i).ne) : castPred (castSucc i) h' = i := rfl @[simp] theorem castSucc_castPred (i : Fin (n + 1)) (h : i ≠ last n) : castSucc (i.castPred h) = i := by rcases exists_castSucc_eq.mpr h with ⟨y, rfl⟩ rw [castPred_castSucc] theorem castPred_eq_iff_eq_castSucc (i : Fin (n + 1)) (hi : i ≠ last _) (j : Fin n) : castPred i hi = j ↔ i = castSucc j := ⟨fun h => by rw [← h, castSucc_castPred], fun h => by simp_rw [h, castPred_castSucc]⟩ @[simp] theorem castPred_mk (i : ℕ) (h₁ : i < n) (h₂ := h₁.trans (Nat.lt_succ_self _)) (h₃ : ⟨i, h₂⟩ ≠ last _ := (ne_iff_vne _ _).mpr (val_last _ ▸ h₁.ne)) : castPred ⟨i, h₂⟩ h₃ = ⟨i, h₁⟩ := rfl @[simp] theorem castPred_le_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi ≤ castPred j hj ↔ i ≤ j := Iff.rfl /-- A version of the right-to-left implication of `castPred_le_castPred_iff` that deduces `i ≠ last n` from `i ≤ j` and `j ≠ last n`. -/ @[gcongr] theorem castPred_le_castPred {i j : Fin (n + 1)} (h : i ≤ j) (hj : j ≠ last n) : castPred i (by rw [← lt_last_iff_ne_last] at hj ⊢; exact Fin.lt_of_le_of_lt h hj) ≤ castPred j hj := h @[simp] theorem castPred_lt_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi < castPred j hj ↔ i < j := Iff.rfl /-- A version of the right-to-left implication of `castPred_lt_castPred_iff` that deduces `i ≠ last n` from `i < j`. -/ @[gcongr] theorem castPred_lt_castPred {i j : Fin (n + 1)} (h : i < j) (hj : j ≠ last n) : castPred i (ne_last_of_lt h) < castPred j hj := h theorem castPred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : castPred i hi < j ↔ i < castSucc j := by rw [← castSucc_lt_castSucc_iff, castSucc_castPred] theorem lt_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : j < castPred i hi ↔ castSucc j < i := by rw [← castSucc_lt_castSucc_iff, castSucc_castPred] theorem castPred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : castPred i hi ≤ j ↔ i ≤ castSucc j := by rw [← castSucc_le_castSucc_iff, castSucc_castPred] theorem le_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : j ≤ castPred i hi ↔ castSucc j ≤ i := by rw [← castSucc_le_castSucc_iff, castSucc_castPred] @[simp] theorem castPred_inj {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi = castPred j hj ↔ i = j := by simp_rw [Fin.ext_iff, le_antisymm_iff, ← le_def, castPred_le_castPred_iff] theorem castPred_zero' [NeZero n] (h := Fin.ext_iff.not.2 last_pos'.ne) : castPred (0 : Fin (n + 1)) h = 0 := rfl theorem castPred_zero (h := Fin.ext_iff.not.2 last_pos.ne) : castPred (0 : Fin (n + 2)) h = 0 := rfl @[simp] theorem castPred_eq_zero [NeZero n] {i : Fin (n + 1)} (h : i ≠ last n) : Fin.castPred i h = 0 ↔ i = 0 := by rw [← castPred_zero', castPred_inj] @[simp] theorem castPred_one [NeZero n] (h := Fin.ext_iff.not.2 one_lt_last.ne) : castPred (1 : Fin (n + 2)) h = 1 := by cases n · exact subsingleton_one.elim _ 1 · rfl theorem succ_castPred_eq_castPred_succ {a : Fin (n + 1)} (ha : a ≠ last n) (ha' := a.succ_ne_last_iff.mpr ha) : (a.castPred ha).succ = (succ a).castPred ha' := rfl theorem succ_castPred_eq_add_one {a : Fin (n + 1)} (ha : a ≠ last n) : (a.castPred ha).succ = a + 1 := by cases a using lastCases · exact (ha rfl).elim · rw [castPred_castSucc, coeSucc_eq_succ] theorem castpred_succ_le_iff {a b : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) : (succ a).castPred ha ≤ b ↔ a < b := by rw [castPred_le_iff, succ_le_castSucc_iff] theorem lt_castPred_succ_iff {a b : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) : b < (succ a).castPred ha ↔ b ≤ a := by rw [lt_castPred_iff, castSucc_lt_succ_iff] theorem lt_castPred_succ {a : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) : a < (succ a).castPred ha := by rw [lt_castPred_succ_iff, le_def] theorem succ_castPred_le_iff {a b : Fin (n + 1)} (ha : a ≠ last n) : succ (a.castPred ha) ≤ b ↔ a < b := by rw [succ_castPred_eq_castPred_succ ha, castpred_succ_le_iff] theorem lt_succ_castPred_iff {a b : Fin (n + 1)} (ha : a ≠ last n) : b < succ (a.castPred ha) ↔ b ≤ a := by rw [succ_castPred_eq_castPred_succ ha, lt_castPred_succ_iff] theorem lt_succ_castPred {a : Fin (n + 1)} (ha : a ≠ last n) : a < succ (a.castPred ha) := by rw [lt_succ_castPred_iff, le_def] theorem castPred_le_pred_iff {a b : Fin (n + 1)} (ha : a ≠ last n) (hb : b ≠ 0) : castPred a ha ≤ pred b hb ↔ a < b := by rw [le_pred_iff, succ_castPred_le_iff] theorem pred_lt_castPred_iff {a b : Fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ last n) : pred a ha < castPred b hb ↔ a ≤ b := by rw [lt_castPred_iff, castSucc_pred_lt_iff ha] theorem pred_lt_castPred {a : Fin (n + 1)} (h₁ : a ≠ 0) (h₂ : a ≠ last n) : pred a h₁ < castPred a h₂ := by rw [pred_lt_castPred_iff, le_def] end CastPred section SuccAbove variable {p : Fin (n + 1)} {i j : Fin n} /-- `succAbove p i` embeds `Fin n` into `Fin (n + 1)` with a hole around `p`. -/ def succAbove (p : Fin (n + 1)) (i : Fin n) : Fin (n + 1) := if castSucc i < p then i.castSucc else i.succ /-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)` embeds `i` by `castSucc` when the resulting `i.castSucc < p`. -/ lemma succAbove_of_castSucc_lt (p : Fin (n + 1)) (i : Fin n) (h : castSucc i < p) : p.succAbove i = castSucc i := if_pos h lemma succAbove_of_succ_le (p : Fin (n + 1)) (i : Fin n) (h : succ i ≤ p) : p.succAbove i = castSucc i := succAbove_of_castSucc_lt _ _ (castSucc_lt_iff_succ_le.mpr h) /-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)` embeds `i` by `succ` when the resulting `p < i.succ`. -/ lemma succAbove_of_le_castSucc (p : Fin (n + 1)) (i : Fin n) (h : p ≤ castSucc i) : p.succAbove i = i.succ := if_neg (Fin.not_lt.2 h) lemma succAbove_of_lt_succ (p : Fin (n + 1)) (i : Fin n) (h : p < succ i) : p.succAbove i = succ i := succAbove_of_le_castSucc _ _ (le_castSucc_iff.mpr h) lemma succAbove_succ_of_lt (p i : Fin n) (h : p < i) : succAbove p.succ i = i.succ := succAbove_of_lt_succ _ _ (succ_lt_succ_iff.mpr h) lemma succAbove_succ_of_le (p i : Fin n) (h : i ≤ p) : succAbove p.succ i = i.castSucc := succAbove_of_succ_le _ _ (succ_le_succ_iff.mpr h) @[simp] lemma succAbove_succ_self (j : Fin n) : j.succ.succAbove j = j.castSucc := succAbove_succ_of_le _ _ Fin.le_rfl lemma succAbove_castSucc_of_lt (p i : Fin n) (h : i < p) : succAbove p.castSucc i = i.castSucc := succAbove_of_castSucc_lt _ _ (castSucc_lt_castSucc_iff.2 h) lemma succAbove_castSucc_of_le (p i : Fin n) (h : p ≤ i) : succAbove p.castSucc i = i.succ := succAbove_of_le_castSucc _ _ (castSucc_le_castSucc_iff.2 h) @[simp] lemma succAbove_castSucc_self (j : Fin n) : succAbove j.castSucc j = j.succ := succAbove_castSucc_of_le _ _ Fin.le_rfl lemma succAbove_pred_of_lt (p i : Fin (n + 1)) (h : p < i) (hi := Fin.ne_of_gt <| Fin.lt_of_le_of_lt p.zero_le h) : succAbove p (i.pred hi) = i := by rw [succAbove_of_lt_succ _ _ (succ_pred _ _ ▸ h), succ_pred] lemma succAbove_pred_of_le (p i : Fin (n + 1)) (h : i ≤ p) (hi : i ≠ 0) : succAbove p (i.pred hi) = (i.pred hi).castSucc := succAbove_of_succ_le _ _ (succ_pred _ _ ▸ h) @[simp] lemma succAbove_pred_self (p : Fin (n + 1)) (h : p ≠ 0) : succAbove p (p.pred h) = (p.pred h).castSucc := succAbove_pred_of_le _ _ Fin.le_rfl h lemma succAbove_castPred_of_lt (p i : Fin (n + 1)) (h : i < p) (hi := Fin.ne_of_lt <| Nat.lt_of_lt_of_le h p.le_last) : succAbove p (i.castPred hi) = i := by rw [succAbove_of_castSucc_lt _ _ (castSucc_castPred _ _ ▸ h), castSucc_castPred] lemma succAbove_castPred_of_le (p i : Fin (n + 1)) (h : p ≤ i) (hi : i ≠ last n) : succAbove p (i.castPred hi) = (i.castPred hi).succ := succAbove_of_le_castSucc _ _ (castSucc_castPred _ _ ▸ h) lemma succAbove_castPred_self (p : Fin (n + 1)) (h : p ≠ last n) : succAbove p (p.castPred h) = (p.castPred h).succ := succAbove_castPred_of_le _ _ Fin.le_rfl h /-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)` never results in `p` itself -/ @[simp] lemma succAbove_ne (p : Fin (n + 1)) (i : Fin n) : p.succAbove i ≠ p := by rcases p.castSucc_lt_or_lt_succ i with (h | h) · rw [succAbove_of_castSucc_lt _ _ h] exact Fin.ne_of_lt h · rw [succAbove_of_lt_succ _ _ h] exact Fin.ne_of_gt h @[simp] lemma ne_succAbove (p : Fin (n + 1)) (i : Fin n) : p ≠ p.succAbove i := (succAbove_ne _ _).symm /-- Given a fixed pivot `p : Fin (n + 1)`, `p.succAbove` is injective. -/ lemma succAbove_right_injective : Injective p.succAbove := by rintro i j hij unfold succAbove at hij split_ifs at hij with hi hj hj · exact castSucc_injective _ hij · rw [hij] at hi cases hj <| Nat.lt_trans j.castSucc_lt_succ hi · rw [← hij] at hj cases hi <| Nat.lt_trans i.castSucc_lt_succ hj · exact succ_injective _ hij /-- Given a fixed pivot `p : Fin (n + 1)`, `p.succAbove` is injective. -/ lemma succAbove_right_inj : p.succAbove i = p.succAbove j ↔ i = j := succAbove_right_injective.eq_iff /-- `Fin.succAbove p` as an `Embedding`. -/ @[simps!] def succAboveEmb (p : Fin (n + 1)) : Fin n ↪ Fin (n + 1) := ⟨p.succAbove, succAbove_right_injective⟩ @[simp, norm_cast] lemma coe_succAboveEmb (p : Fin (n + 1)) : p.succAboveEmb = p.succAbove := rfl @[simp] lemma succAbove_ne_zero_zero [NeZero n] {a : Fin (n + 1)} (ha : a ≠ 0) : a.succAbove 0 = 0 := by rw [Fin.succAbove_of_castSucc_lt] · exact castSucc_zero' · exact Fin.pos_iff_ne_zero.2 ha lemma succAbove_eq_zero_iff [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) : a.succAbove b = 0 ↔ b = 0 := by rw [← succAbove_ne_zero_zero ha, succAbove_right_inj] lemma succAbove_ne_zero [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) (hb : b ≠ 0) : a.succAbove b ≠ 0 := mt (succAbove_eq_zero_iff ha).mp hb /-- Embedding `Fin n` into `Fin (n + 1)` with a hole around zero embeds by `succ`. -/ @[simp] lemma succAbove_zero : succAbove (0 : Fin (n + 1)) = Fin.succ := rfl lemma succAbove_zero_apply (i : Fin n) : succAbove 0 i = succ i := by rw [succAbove_zero] @[simp] lemma succAbove_ne_last_last {a : Fin (n + 2)} (h : a ≠ last (n + 1)) : a.succAbove (last n) = last (n + 1) := by rw [succAbove_of_lt_succ _ _ (succ_last _ ▸ lt_last_iff_ne_last.2 h), succ_last] lemma succAbove_eq_last_iff {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) : a.succAbove b = last _ ↔ b = last _ := by rw [← succAbove_ne_last_last ha, succAbove_right_inj] lemma succAbove_ne_last {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) (hb : b ≠ last _) : a.succAbove b ≠ last _ := mt (succAbove_eq_last_iff ha).mp hb /-- Embedding `Fin n` into `Fin (n + 1)` with a hole around `last n` embeds by `castSucc`. -/ @[simp] lemma succAbove_last : succAbove (last n) = castSucc := by ext; simp only [succAbove_of_castSucc_lt, castSucc_lt_last] lemma succAbove_last_apply (i : Fin n) : succAbove (last n) i = castSucc i := by rw [succAbove_last] /-- Embedding `i : Fin n` into `Fin (n + 1)` using a pivot `p` that is greater results in a value that is less than `p`. -/ lemma succAbove_lt_iff_castSucc_lt (p : Fin (n + 1)) (i : Fin n) : p.succAbove i < p ↔ castSucc i < p := by rcases castSucc_lt_or_lt_succ p i with H | H · rwa [iff_true_right H, succAbove_of_castSucc_lt _ _ H] · rw [castSucc_lt_iff_succ_le, iff_false_right (Fin.not_le.2 H), succAbove_of_lt_succ _ _ H] exact Fin.not_lt.2 <| Fin.le_of_lt H lemma succAbove_lt_iff_succ_le (p : Fin (n + 1)) (i : Fin n) : p.succAbove i < p ↔ succ i ≤ p := by rw [succAbove_lt_iff_castSucc_lt, castSucc_lt_iff_succ_le] /-- Embedding `i : Fin n` into `Fin (n + 1)` using a pivot `p` that is lesser results in a value that is greater than `p`. -/ lemma lt_succAbove_iff_le_castSucc (p : Fin (n + 1)) (i : Fin n) : p < p.succAbove i ↔ p ≤ castSucc i := by rcases castSucc_lt_or_lt_succ p i with H | H · rw [iff_false_right (Fin.not_le.2 H), succAbove_of_castSucc_lt _ _ H] exact Fin.not_lt.2 <| Fin.le_of_lt H · rwa [succAbove_of_lt_succ _ _ H, iff_true_left H, le_castSucc_iff] lemma lt_succAbove_iff_lt_castSucc (p : Fin (n + 1)) (i : Fin n) : p < p.succAbove i ↔ p < succ i := by rw [lt_succAbove_iff_le_castSucc, le_castSucc_iff] /-- Embedding a positive `Fin n` results in a positive `Fin (n + 1)` -/ lemma succAbove_pos [NeZero n] (p : Fin (n + 1)) (i : Fin n) (h : 0 < i) : 0 < p.succAbove i := by by_cases H : castSucc i < p · simpa [succAbove_of_castSucc_lt _ _ H] using castSucc_pos' h · simp [succAbove_of_le_castSucc _ _ (Fin.not_lt.1 H)] lemma castPred_succAbove (x : Fin n) (y : Fin (n + 1)) (h : castSucc x < y) (h' := Fin.ne_last_of_lt <| (succAbove_lt_iff_castSucc_lt ..).2 h) : (y.succAbove x).castPred h' = x := by rw [castPred_eq_iff_eq_castSucc, succAbove_of_castSucc_lt _ _ h] lemma pred_succAbove (x : Fin n) (y : Fin (n + 1)) (h : y ≤ castSucc x) (h' := Fin.ne_zero_of_lt <| (lt_succAbove_iff_le_castSucc ..).2 h) : (y.succAbove x).pred h' = x := by simp only [succAbove_of_le_castSucc _ _ h, pred_succ] lemma exists_succAbove_eq {x y : Fin (n + 1)} (h : x ≠ y) : ∃ z, y.succAbove z = x := by obtain hxy | hyx := Fin.lt_or_lt_of_ne h exacts [⟨_, succAbove_castPred_of_lt _ _ hxy⟩, ⟨_, succAbove_pred_of_lt _ _ hyx⟩] @[simp] lemma exists_succAbove_eq_iff {x y : Fin (n + 1)} : (∃ z, x.succAbove z = y) ↔ y ≠ x := ⟨by rintro ⟨y, rfl⟩; exact succAbove_ne _ _, exists_succAbove_eq⟩ /-- The range of `p.succAbove` is everything except `p`. -/ @[simp] lemma range_succAbove (p : Fin (n + 1)) : Set.range p.succAbove = {p}ᶜ := Set.ext fun _ => exists_succAbove_eq_iff @[simp] lemma range_succ (n : ℕ) : Set.range (Fin.succ : Fin n → Fin (n + 1)) = {0}ᶜ := by rw [← succAbove_zero]; exact range_succAbove (0 : Fin (n + 1)) /-- `succAbove` is injective at the pivot -/ lemma succAbove_left_injective : Injective (@succAbove n) := fun _ _ h => by simpa [range_succAbove] using congr_arg (fun f : Fin n → Fin (n + 1) => (Set.range f)ᶜ) h /-- `succAbove` is injective at the pivot -/ @[simp] lemma succAbove_left_inj {x y : Fin (n + 1)} : x.succAbove = y.succAbove ↔ x = y := succAbove_left_injective.eq_iff @[simp] lemma zero_succAbove {n : ℕ} (i : Fin n) : (0 : Fin (n + 1)).succAbove i = i.succ := rfl lemma succ_succAbove_zero {n : ℕ} [NeZero n] (i : Fin n) : succAbove i.succ 0 = 0 := by simp /-- `succ` commutes with `succAbove`. -/ @[simp] lemma succ_succAbove_succ {n : ℕ} (i : Fin (n + 1)) (j : Fin n) : i.succ.succAbove j.succ = (i.succAbove j).succ := by obtain h | h := i.lt_or_le (succ j) · rw [succAbove_of_lt_succ _ _ h, succAbove_succ_of_lt _ _ h] · rwa [succAbove_of_castSucc_lt _ _ h, succAbove_succ_of_le, succ_castSucc] /-- `castSucc` commutes with `succAbove`. -/ @[simp] lemma castSucc_succAbove_castSucc {n : ℕ} {i : Fin (n + 1)} {j : Fin n} : i.castSucc.succAbove j.castSucc = (i.succAbove j).castSucc := by rcases i.le_or_lt (castSucc j) with (h | h) · rw [succAbove_of_le_castSucc _ _ h, succAbove_castSucc_of_le _ _ h, succ_castSucc] · rw [succAbove_of_castSucc_lt _ _ h, succAbove_castSucc_of_lt _ _ h] /-- `pred` commutes with `succAbove`. -/ lemma pred_succAbove_pred {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ 0) (hk := succAbove_ne_zero ha hb) : (a.pred ha).succAbove (b.pred hb) = (a.succAbove b).pred hk := by simp_rw [← succ_inj (b := pred (succAbove a b) hk), ← succ_succAbove_succ, succ_pred] /-- `castPred` commutes with `succAbove`. -/ lemma castPred_succAbove_castPred {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last (n + 1)) (hb : b ≠ last n) (hk := succAbove_ne_last ha hb) : (a.castPred ha).succAbove (b.castPred hb) = (a.succAbove b).castPred hk := by simp_rw [← castSucc_inj (b := (a.succAbove b).castPred hk), ← castSucc_succAbove_castSucc, castSucc_castPred] lemma one_succAbove_zero {n : ℕ} : (1 : Fin (n + 2)).succAbove 0 = 0 := by
rfl /-- By moving `succ` to the outside of this expression, we create opportunities for further
Mathlib/Data/Fin/Basic.lean
1,153
1,155
/- 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.Analysis.InnerProductSpace.Convex import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Combinatorics.Additive.AP.Three.Defs import Mathlib.Combinatorics.Pigeonhole import Mathlib.Data.Complex.ExponentialBounds /-! # Behrend's bound on Roth numbers This file proves Behrend's lower bound on Roth numbers. This says that we can find a subset of `{1, ..., n}` of size `n / exp (O (sqrt (log n)))` which does not contain arithmetic progressions of length `3`. The idea is that the sphere (in the `n` dimensional Euclidean space) doesn't contain arithmetic progressions (literally) because the corresponding ball is strictly convex. Thus we can take integer points on that sphere and map them onto `ℕ` in a way that preserves arithmetic progressions (`Behrend.map`). ## Main declarations * `Behrend.sphere`: The intersection of the Euclidean sphere with the positive integer quadrant. This is the set that we will map on `ℕ`. * `Behrend.map`: Given a natural number `d`, `Behrend.map d : ℕⁿ → ℕ` reads off the coordinates as digits in base `d`. * `Behrend.card_sphere_le_rothNumberNat`: Implicit lower bound on Roth numbers in terms of `Behrend.sphere`. * `Behrend.roth_lower_bound`: Behrend's explicit lower bound on Roth numbers. ## References * [Bryan Gillespie, *Behrend’s Construction*] (http://www.epsilonsmall.com/resources/behrends-construction/behrend.pdf) * Behrend, F. A., "On sets of integers which contain no three terms in arithmetical progression" * [Wikipedia, *Salem-Spencer set*](https://en.wikipedia.org/wiki/Salem–Spencer_set) ## Tags 3AP-free, Salem-Spencer, Behrend construction, arithmetic progression, sphere, strictly convex -/ assert_not_exists IsConformalMap Conformal open Nat hiding log open Finset Metric Real open scoped Pointwise /-- The frontier of a closed strictly convex set only contains trivial arithmetic progressions. The idea is that an arithmetic progression is contained on a line and the frontier of a strictly convex set does not contain lines. -/ lemma threeAPFree_frontier {𝕜 E : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [TopologicalSpace E] [AddCommMonoid E] [Module 𝕜 E] {s : Set E} (hs₀ : IsClosed s) (hs₁ : StrictConvex 𝕜 s) : ThreeAPFree (frontier s) := by intro a ha b hb c hc habc obtain rfl : (1 / 2 : 𝕜) • a + (1 / 2 : 𝕜) • c = b := by rwa [← smul_add, one_div, inv_smul_eq_iff₀ (show (2 : 𝕜) ≠ 0 by norm_num), two_smul] have := hs₁.eq (hs₀.frontier_subset ha) (hs₀.frontier_subset hc) one_half_pos one_half_pos (add_halves _) hb.2 simp [this, ← add_smul] ring_nf simp lemma threeAPFree_sphere {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [StrictConvexSpace ℝ E] (x : E) (r : ℝ) : ThreeAPFree (sphere x r) := by obtain rfl | hr := eq_or_ne r 0 · rw [sphere_zero] exact threeAPFree_singleton _ · convert threeAPFree_frontier isClosed_closedBall (strictConvex_closedBall ℝ x r) exact (frontier_closedBall _ hr).symm namespace Behrend variable {n d k N : ℕ} {x : Fin n → ℕ} /-! ### Turning the sphere into 3AP-free set We define `Behrend.sphere`, the intersection of the $L^2$ sphere with the positive quadrant of integer points. Because the $L^2$ closed ball is strictly convex, the $L^2$ sphere and `Behrend.sphere` are 3AP-free (`threeAPFree_sphere`). Then we can turn this set in `Fin n → ℕ` into a set in `ℕ` using `Behrend.map`, which preserves `ThreeAPFree` because it is an additive monoid homomorphism. -/ /-- The box `{0, ..., d - 1}^n` as a `Finset`. -/ def box (n d : ℕ) : Finset (Fin n → ℕ) := Fintype.piFinset fun _ => range d theorem mem_box : x ∈ box n d ↔ ∀ i, x i < d := by simp only [box, Fintype.mem_piFinset, mem_range] @[simp] theorem card_box : #(box n d) = d ^ n := by simp [box] @[simp] theorem box_zero : box (n + 1) 0 = ∅ := by simp [box] /-- The intersection of the sphere of radius `√k` with the integer points in the positive quadrant. -/ def sphere (n d k : ℕ) : Finset (Fin n → ℕ) := {x ∈ box n d | ∑ i, x i ^ 2 = k} theorem sphere_zero_subset : sphere n d 0 ⊆ 0 := fun x => by simp [sphere, funext_iff] @[simp] theorem sphere_zero_right (n k : ℕ) : sphere (n + 1) 0 k = ∅ := by simp [sphere] theorem sphere_subset_box : sphere n d k ⊆ box n d := filter_subset _ _ theorem norm_of_mem_sphere {x : Fin n → ℕ} (hx : x ∈ sphere n d k) : ‖(WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)‖ = √↑k := by rw [EuclideanSpace.norm_eq] dsimp simp_rw [abs_cast, ← cast_pow, ← cast_sum, (mem_filter.1 hx).2] theorem sphere_subset_preimage_metric_sphere : (sphere n d k : Set (Fin n → ℕ)) ⊆ (fun x : Fin n → ℕ => (WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)) ⁻¹' Metric.sphere (0 : PiLp 2 fun _ : Fin n => ℝ) (√↑k) := fun x hx => by rw [Set.mem_preimage, mem_sphere_zero_iff_norm, norm_of_mem_sphere hx] /-- The map that appears in Behrend's bound on Roth numbers. -/ @[simps] def map (d : ℕ) : (Fin n → ℕ) →+ ℕ where toFun a := ∑ i, a i * d ^ (i : ℕ) map_zero' := by simp_rw [Pi.zero_apply, zero_mul, sum_const_zero] map_add' a b := by simp_rw [Pi.add_apply, add_mul, sum_add_distrib] theorem map_zero (d : ℕ) (a : Fin 0 → ℕ) : map d a = 0 := by simp [map] theorem map_succ (a : Fin (n + 1) → ℕ) : map d a = a 0 + (∑ x : Fin n, a x.succ * d ^ (x : ℕ)) * d := by simp [map, Fin.sum_univ_succ, _root_.pow_succ, ← mul_assoc, ← sum_mul] theorem map_succ' (a : Fin (n + 1) → ℕ) : map d a = a 0 + map d (a ∘ Fin.succ) * d := map_succ _ theorem map_monotone (d : ℕ) : Monotone (map d : (Fin n → ℕ) → ℕ) := fun x y h => by dsimp; exact sum_le_sum fun i _ => Nat.mul_le_mul_right _ <| h i theorem map_mod (a : Fin n.succ → ℕ) : map d a % d = a 0 % d := by rw [map_succ, Nat.add_mul_mod_self_right] theorem map_eq_iff {x₁ x₂ : Fin n.succ → ℕ} (hx₁ : ∀ i, x₁ i < d) (hx₂ : ∀ i, x₂ i < d) : map d x₁ = map d x₂ ↔ x₁ 0 = x₂ 0 ∧ map d (x₁ ∘ Fin.succ) = map d (x₂ ∘ Fin.succ) := by refine ⟨fun h => ?_, fun h => by rw [map_succ', map_succ', h.1, h.2]⟩ have : x₁ 0 = x₂ 0 := by rw [← mod_eq_of_lt (hx₁ _), ← map_mod, ← mod_eq_of_lt (hx₂ _), ← map_mod, h] rw [map_succ, map_succ, this, add_right_inj, mul_eq_mul_right_iff] at h exact ⟨this, h.resolve_right (pos_of_gt (hx₁ 0)).ne'⟩ theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by intro x₁ hx₁ x₂ hx₂ h induction n with | zero => simp [eq_iff_true_of_subsingleton] | succ n ih => ext i have x := (map_eq_iff hx₁ hx₂).1 h exact Fin.cases x.1 (congr_fun <| ih (fun _ => hx₁ _) (fun _ => hx₂ _) x.2) i theorem map_le_of_mem_box (hx : x ∈ box n d) : map (2 * d - 1) x ≤ ∑ i : Fin n, (d - 1) * (2 * d - 1) ^ (i : ℕ) := map_monotone (2 * d - 1) fun _ => Nat.le_sub_one_of_lt <| mem_box.1 hx _ nonrec theorem threeAPFree_sphere : ThreeAPFree (sphere n d k : Set (Fin n → ℕ)) := by set f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) := { toFun := fun f => ((↑) : ℕ → ℝ) ∘ f map_zero' := funext fun _ => cast_zero map_add' := fun _ _ => funext fun _ => cast_add _ _ } refine ThreeAPFree.of_image (AddMonoidHomClass.isAddFreimanHom f (Set.mapsTo_image _ _)) cast_injective.comp_left.injOn (Set.subset_univ _) ?_ refine (threeAPFree_sphere 0 (√↑k)).mono (Set.image_subset_iff.2 fun x => ?_) rw [Set.mem_preimage, mem_sphere_zero_iff_norm] exact norm_of_mem_sphere theorem threeAPFree_image_sphere : ThreeAPFree ((sphere n d k).image (map (2 * d - 1)) : Set ℕ) := by rw [coe_image] apply ThreeAPFree.image' (α := Fin n → ℕ) (β := ℕ) (s := sphere n d k) (map (2 * d - 1)) (map_injOn.mono _) threeAPFree_sphere rw [Set.add_subset_iff] rintro a ha b hb i have hai := mem_box.1 (sphere_subset_box ha) i have hbi := mem_box.1 (sphere_subset_box hb) i rw [lt_tsub_iff_right, ← succ_le_iff, two_mul] exact (add_add_add_comm _ _ 1 1).trans_le (_root_.add_le_add hai hbi) theorem sum_sq_le_of_mem_box (hx : x ∈ box n d) : ∑ i : Fin n, x i ^ 2 ≤ n * (d - 1) ^ 2 := by rw [mem_box] at hx have : ∀ i, x i ^ 2 ≤ (d - 1) ^ 2 := fun i => Nat.pow_le_pow_left (Nat.le_sub_one_of_lt (hx i)) _ exact (sum_le_card_nsmul univ _ _ fun i _ => this i).trans (by rw [card_fin, smul_eq_mul]) theorem sum_eq : (∑ i : Fin n, d * (2 * d + 1) ^ (i : ℕ)) = ((2 * d + 1) ^ n - 1) / 2 := by refine (Nat.div_eq_of_eq_mul_left zero_lt_two ?_).symm rw [← sum_range fun i => d * (2 * d + 1) ^ (i : ℕ), ← mul_sum, mul_right_comm, mul_comm d, ← geom_sum_mul_add, add_tsub_cancel_right, mul_comm] theorem sum_lt : (∑ i : Fin n, d * (2 * d + 1) ^ (i : ℕ)) < (2 * d + 1) ^ n := sum_eq.trans_lt <| (Nat.div_le_self _ 2).trans_lt <| pred_lt (pow_pos (succ_pos _) _).ne' theorem card_sphere_le_rothNumberNat (n d k : ℕ) : #(sphere n d k) ≤ rothNumberNat ((2 * d - 1) ^ n) := by cases n · dsimp; refine (card_le_univ _).trans_eq ?_; rfl cases d · simp apply threeAPFree_image_sphere.le_rothNumberNat _ _ (card_image_of_injOn _) · simp only [subset_iff, mem_image, and_imp, forall_exists_index, mem_range, forall_apply_eq_imp_iff₂, sphere, mem_filter] rintro _ x hx _ rfl exact (map_le_of_mem_box hx).trans_lt sum_lt apply map_injOn.mono fun x => ?_
simp only [mem_coe, sphere, mem_filter, mem_box, and_imp, two_mul] exact fun h _ i => (h i).trans_le le_self_add /-! ### Optimization
Mathlib/Combinatorics/Additive/AP/Three/Behrend.lean
219
223
/- 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,511
2,512
/- Copyright (c) 2020 Johan Commelin, Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.Algebra.Field.ZMod import Mathlib.NumberTheory.Padics.PadicIntegers import Mathlib.RingTheory.LocalRing.ResidueField.Defs import Mathlib.RingTheory.ZMod /-! # Relating `ℤ_[p]` to `ZMod (p ^ n)`, aka `ℤ/p^nℤ`. In this file we establish connections between the `p`-adic integers `ℤ_[p]` and the integers modulo powers of `p`, `ℤ/p^nℤ`, implemented as `ZMod (p^n)`. ## Main declarations We show that `ℤ_[p]` has a ring homomorphism to `ℤ/p^nℤ` for each `n`. The case for `n = 1` is handled separately, since it is used in the general construction and we may want to use it without the `^1` getting in the way. * `PadicInt.toZMod`: ring homomorphism to `ℤ/pℤ`, implemented as `ZMod p`. * `PadicInt.toZModPow`: ring homomorphism to `ℤ/p^nℤ`, implemented as `ZMod (p^n)`. * `PadicInt.ker_toZMod` / `PadicInt.ker_toZModPow`: the kernels of these maps are the ideals generated by `p^n` * `PadicInt.residueField` shows that the residue field of `ℤ_[p]` is isomorhic to ``ℤ/pℤ`. We also establish the universal property of `ℤ_[p]` as a projective limit. Given a family of compatible ring homomorphisms `f_k : R → ℤ/p^nℤ`, there is a unique limit `R → ℤ_[p]` * `PadicInt.lift`: the limit function * `PadicInt.lift_spec` / `PadicInt.lift_unique`: the universal property ## Implementation notes The constructions of the ring homomorphisms go through an auxiliary constructor `PadicInt.toZModHom`, which removes some boilerplate code. -/ noncomputable section open Nat IsLocalRing Padic namespace PadicInt variable {p : ℕ} [hp_prime : Fact p.Prime] section RingHoms /-! ### Ring homomorphisms to `ZMod p` and `ZMod (p ^ n)` -/ variable (p) (r : ℚ) /-- `modPart p r` is an integer that satisfies `‖(r - modPart p r : ℚ_[p])‖ < 1` when `‖(r : ℚ_[p])‖ ≤ 1`, see `PadicInt.norm_sub_modPart`. It is the unique non-negative integer that is `< p` with this property. (Note that this definition assumes `r : ℚ`. See `PadicInt.zmodRepr` for a version that takes values in `ℕ` and works for arbitrary `x : ℤ_[p]`.) -/ def modPart : ℤ := r.num * gcdA r.den p % p variable {p} theorem modPart_lt_p : modPart p r < p := by convert Int.emod_lt_abs _ _ · simp · exact mod_cast hp_prime.1.ne_zero theorem modPart_nonneg : 0 ≤ modPart p r := Int.emod_nonneg _ <| mod_cast hp_prime.1.ne_zero theorem isUnit_den (r : ℚ) (h : ‖(r : ℚ_[p])‖ ≤ 1) : IsUnit (r.den : ℤ_[p]) := by rw [isUnit_iff] apply le_antisymm (r.den : ℤ_[p]).2 rw [← not_lt, coe_natCast] intro norm_denom_lt have hr : ‖(r * r.den : ℚ_[p])‖ = ‖(r.num : ℚ_[p])‖ := by congr rw_mod_cast [@Rat.mul_den_eq_num r] rw [padicNormE.mul] at hr have key : ‖(r.num : ℚ_[p])‖ < 1 := by calc _ = _ := hr.symm _ < 1 * 1 := mul_lt_mul' h norm_denom_lt (norm_nonneg _) zero_lt_one _ = 1 := mul_one 1 have : ↑p ∣ r.num ∧ (p : ℤ) ∣ r.den := by simp only [← norm_int_lt_one_iff_dvd, ← padic_norm_e_of_padicInt] exact ⟨key, norm_denom_lt⟩ apply hp_prime.1.not_dvd_one rwa [← r.reduced.gcd_eq_one, Nat.dvd_gcd_iff, ← Int.natCast_dvd, ← Int.natCast_dvd_natCast] theorem norm_sub_modPart_aux (r : ℚ) (h : ‖(r : ℚ_[p])‖ ≤ 1) : ↑p ∣ r.num - r.num * r.den.gcdA p % p * ↑r.den := by rw [← ZMod.intCast_zmod_eq_zero_iff_dvd] simp only [Int.cast_natCast, ZMod.natCast_mod, Int.cast_mul, Int.cast_sub] have := congr_arg (fun x => x % p : ℤ → ZMod p) (gcd_eq_gcd_ab r.den p) simp only [Int.cast_natCast, CharP.cast_eq_zero, EuclideanDomain.mod_zero, Int.cast_add, Int.cast_mul, zero_mul, add_zero] at this push_cast rw [mul_right_comm, mul_assoc, ← this] suffices rdcp : r.den.Coprime p by rw [rdcp.gcd_eq_one] simp only [mul_one, cast_one, sub_self] apply Coprime.symm apply (coprime_or_dvd_of_prime hp_prime.1 _).resolve_right rw [← Int.natCast_dvd_natCast, ← norm_int_lt_one_iff_dvd, not_lt] apply ge_of_eq rw [← isUnit_iff] exact isUnit_den r h theorem norm_sub_modPart (h : ‖(r : ℚ_[p])‖ ≤ 1) : ‖(⟨r, h⟩ - modPart p r : ℤ_[p])‖ < 1 := by let n := modPart p r rw [norm_lt_one_iff_dvd, ← (isUnit_den r h).dvd_mul_right] suffices ↑p ∣ r.num - n * r.den by convert (Int.castRingHom ℤ_[p]).map_dvd this simp only [n, sub_mul, Int.cast_natCast, eq_intCast, Int.cast_mul, sub_left_inj, Int.cast_sub] apply Subtype.coe_injective simp only [coe_mul, Subtype.coe_mk, coe_natCast] rw_mod_cast [@Rat.mul_den_eq_num r] rfl exact norm_sub_modPart_aux r h theorem exists_mem_range_of_norm_rat_le_one (h : ‖(r : ℚ_[p])‖ ≤ 1) : ∃ n : ℤ, 0 ≤ n ∧ n < p ∧ ‖(⟨r, h⟩ - n : ℤ_[p])‖ < 1 := ⟨modPart p r, modPart_nonneg _, modPart_lt_p _, norm_sub_modPart _ h⟩ theorem zmod_congr_of_sub_mem_span_aux (n : ℕ) (x : ℤ_[p]) (a b : ℤ) (ha : x - a ∈ (Ideal.span {(p : ℤ_[p]) ^ n})) (hb : x - b ∈ (Ideal.span {(p : ℤ_[p]) ^ n})) : (a : ZMod (p ^ n)) = b := by rw [Ideal.mem_span_singleton] at ha hb rw [← sub_eq_zero, ← Int.cast_sub, ZMod.intCast_zmod_eq_zero_iff_dvd, Int.natCast_pow] rw [← dvd_neg, neg_sub] at ha have := dvd_add ha hb rwa [sub_eq_add_neg, sub_eq_add_neg, add_assoc, neg_add_cancel_left, ← sub_eq_add_neg, ← Int.cast_sub, pow_p_dvd_int_iff] at this theorem zmod_congr_of_sub_mem_span (n : ℕ) (x : ℤ_[p]) (a b : ℕ) (ha : x - a ∈ (Ideal.span {(p : ℤ_[p]) ^ n})) (hb : x - b ∈ (Ideal.span {(p : ℤ_[p]) ^ n})) : (a : ZMod (p ^ n)) = b := by simpa using zmod_congr_of_sub_mem_span_aux n x a b ha hb theorem zmod_congr_of_sub_mem_max_ideal (x : ℤ_[p]) (m n : ℕ) (hm : x - m ∈ maximalIdeal ℤ_[p]) (hn : x - n ∈ maximalIdeal ℤ_[p]) : (m : ZMod p) = n := by rw [maximalIdeal_eq_span_p] at hm hn have := zmod_congr_of_sub_mem_span_aux 1 x m n simp only [pow_one] at this specialize this hm hn apply_fun ZMod.castHom (show p ∣ p ^ 1 by rw [pow_one]) (ZMod p) at this simp only [map_intCast] at this simpa only [Int.cast_natCast] using this variable (x : ℤ_[p]) theorem exists_mem_range : ∃ n : ℕ, n < p ∧ x - n ∈ maximalIdeal ℤ_[p] := by simp only [maximalIdeal_eq_span_p, Ideal.mem_span_singleton, ← norm_lt_one_iff_dvd] obtain ⟨r, hr⟩ := rat_dense p (x : ℚ_[p]) zero_lt_one have H : ‖(r : ℚ_[p])‖ ≤ 1 := by rw [norm_sub_rev] at hr calc _ = ‖(r : ℚ_[p]) - x + x‖ := by ring_nf _ ≤ _ := padicNormE.nonarchimedean _ _ _ ≤ _ := max_le (le_of_lt hr) x.2 obtain ⟨n, hzn, hnp, hn⟩ := exists_mem_range_of_norm_rat_le_one r H lift n to ℕ using hzn use n constructor · exact mod_cast hnp simp only [norm_def, coe_sub, Subtype.coe_mk, coe_natCast] at hn ⊢ rw [show (x - n : ℚ_[p]) = x - r + (r - n) by ring] apply lt_of_le_of_lt (padicNormE.nonarchimedean _ _) apply max_lt hr simpa using hn theorem existsUnique_mem_range : ∃! n : ℕ, n < p ∧ x - n ∈ maximalIdeal ℤ_[p] := by obtain ⟨n, hn₁, hn₂⟩ := exists_mem_range x use n, ⟨hn₁, hn₂⟩, fun m ⟨hm₁, hm₂⟩ ↦ ?_ have := (zmod_congr_of_sub_mem_max_ideal x n m hn₂ hm₂).symm rwa [ZMod.natCast_eq_natCast_iff, ModEq, mod_eq_of_lt hn₁, mod_eq_of_lt hm₁] at this @[deprecated (since := "2024-12-17")] alias exists_unique_mem_range := existsUnique_mem_range /-- `zmodRepr x` is the unique natural number smaller than `p` satisfying `‖(x - zmodRepr x : ℤ_[p])‖ < 1`. -/ def zmodRepr : ℕ := Classical.choose (existsUnique_mem_range x).exists theorem zmodRepr_spec : zmodRepr x < p ∧ x - zmodRepr x ∈ maximalIdeal ℤ_[p] := Classical.choose_spec (existsUnique_mem_range x).exists theorem zmodRepr_unique (y : ℕ) (hy₁ : y < p) (hy₂ : x - y ∈ maximalIdeal ℤ_[p]) : y = zmodRepr x := have h := (Classical.choose_spec (existsUnique_mem_range x)).right (h y ⟨hy₁, hy₂⟩).trans (h (zmodRepr x) (zmodRepr_spec x)).symm theorem zmodRepr_lt_p : zmodRepr x < p := (zmodRepr_spec _).1 theorem sub_zmodRepr_mem : x - zmodRepr x ∈ maximalIdeal ℤ_[p] := (zmodRepr_spec _).2 /-- `toZModHom` is an auxiliary constructor for creating ring homs from `ℤ_[p]` to `ZMod v`. -/ def toZModHom (v : ℕ) (f : ℤ_[p] → ℕ) (f_spec : ∀ x, x - f x ∈ (Ideal.span {↑v} : Ideal ℤ_[p])) (f_congr : ∀ (x : ℤ_[p]) (a b : ℕ), x - a ∈ (Ideal.span {↑v} : Ideal ℤ_[p]) → x - b ∈ (Ideal.span {↑v} : Ideal ℤ_[p]) → (a : ZMod v) = b) : ℤ_[p] →+* ZMod v where toFun x := f x map_zero' := by rw [f_congr (0 : ℤ_[p]) _ 0, cast_zero] · exact f_spec _ · simp only [sub_zero, cast_zero, Submodule.zero_mem] map_one' := by rw [f_congr (1 : ℤ_[p]) _ 1, cast_one] · exact f_spec _ · simp only [sub_self, cast_one, Submodule.zero_mem] map_add' := by intro x y rw [f_congr (x + y) _ (f x + f y), cast_add] · exact f_spec _ · convert Ideal.add_mem _ (f_spec x) (f_spec y) using 1 rw [cast_add] ring map_mul' := by intro x y rw [f_congr (x * y) _ (f x * f y), cast_mul] · exact f_spec _ · let I : Ideal ℤ_[p] := Ideal.span {↑v} convert I.add_mem (I.mul_mem_left x (f_spec y)) (I.mul_mem_right ↑(f y) (f_spec x)) using 1 rw [cast_mul] ring /-- `toZMod` is a ring hom from `ℤ_[p]` to `ZMod p`, with the equality `toZMod x = (zmodRepr x : ZMod p)`. -/ def toZMod : ℤ_[p] →+* ZMod p := toZModHom p zmodRepr (by rw [← maximalIdeal_eq_span_p] exact sub_zmodRepr_mem) (by rw [← maximalIdeal_eq_span_p] exact zmod_congr_of_sub_mem_max_ideal) /-- `z - (toZMod z : ℤ_[p])` is contained in the maximal ideal of `ℤ_[p]`, for every `z : ℤ_[p]`. The coercion from `ZMod p` to `ℤ_[p]` is `ZMod.cast`, which coerces `ZMod p` into arbitrary rings. This is unfortunate, but a consequence of the fact that we allow `ZMod p` to coerce to rings of arbitrary characteristic, instead of only rings of characteristic `p`. This coercion is only a ring homomorphism if it coerces into a ring whose characteristic divides `p`. While this is not the case here we can still make use of the coercion. -/ theorem toZMod_spec : x - (ZMod.cast (toZMod x) : ℤ_[p]) ∈ maximalIdeal ℤ_[p] := by convert sub_zmodRepr_mem x using 2 dsimp [toZMod, toZModHom] rcases Nat.exists_eq_add_of_lt hp_prime.1.pos with ⟨p', rfl⟩ change ↑((_ : ZMod (0 + p' + 1)).val) = (_ : ℤ_[0 + p' + 1]) rw [Nat.cast_inj] apply mod_eq_of_lt simpa only [zero_add] using zmodRepr_lt_p x theorem ker_toZMod : RingHom.ker (toZMod : ℤ_[p] →+* ZMod p) = maximalIdeal ℤ_[p] := by ext x rw [RingHom.mem_ker] constructor · intro h simpa only [h, ZMod.cast_zero, sub_zero] using toZMod_spec x · intro h rw [← sub_zero x] at h dsimp [toZMod, toZModHom] convert zmod_congr_of_sub_mem_max_ideal x _ 0 _ h · norm_cast · apply sub_zmodRepr_mem /-- The equivalence between the residue field of the `p`-adic integers and `ℤ/pℤ` -/ def residueField : IsLocalRing.ResidueField ℤ_[p] ≃+* ZMod p := (Ideal.quotEquivOfEq PadicInt.ker_toZMod.symm).trans <| RingHom.quotientKerEquivOfSurjective (ZMod.ringHom_surjective PadicInt.toZMod) open scoped Classical in /-- `appr n x` gives a value `v : ℕ` such that `x` and `↑v : ℤ_p` are congruent mod `p^n`. See `appr_spec`. -/ noncomputable def appr : ℤ_[p] → ℕ → ℕ | _x, 0 => 0 | x, n + 1 => let y := x - appr x n if hy : y = 0 then appr x n else let u := (unitCoeff hy : ℤ_[p]) appr x n + p ^ n * (toZMod ((u * (p : ℤ_[p]) ^ (y.valuation - n : ℤ).natAbs) : ℤ_[p])).val theorem appr_lt (x : ℤ_[p]) (n : ℕ) : x.appr n < p ^ n := by induction n generalizing x with | zero => simp only [appr, zero_eq, _root_.pow_zero, zero_lt_one] | succ n ih => simp only [appr, map_natCast, ZMod.natCast_self, RingHom.map_pow, Int.natAbs, RingHom.map_mul] have hp : p ^ n < p ^ (n + 1) := by apply Nat.pow_lt_pow_right hp_prime.1.one_lt n.lt_add_one split_ifs with h · apply lt_trans (ih _) hp · calc _ < p ^ n + p ^ n * (p - 1) := ?_ _ = p ^ (n + 1) := ?_ · apply add_lt_add_of_lt_of_le (ih _) apply Nat.mul_le_mul_left apply le_pred_of_lt apply ZMod.val_lt · rw [mul_tsub, mul_one, ← _root_.pow_succ] apply add_tsub_cancel_of_le (le_of_lt hp) theorem appr_mono (x : ℤ_[p]) : Monotone x.appr := by apply monotone_nat_of_le_succ intro n dsimp [appr] split_ifs; · rfl apply Nat.le_add_right theorem dvd_appr_sub_appr (x : ℤ_[p]) (m n : ℕ) (h : m ≤ n) : p ^ m ∣ x.appr n - x.appr m := by obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le h; clear h induction k with | zero => simp only [zero_eq, add_zero, le_refl, tsub_eq_zero_of_le, ne_eq, Nat.isUnit_iff, dvd_zero] | succ k ih => rw [← add_assoc] dsimp [appr] split_ifs with h · exact ih rw [add_comm, add_tsub_assoc_of_le (appr_mono _ (Nat.le_add_right m k))] apply dvd_add _ ih apply dvd_mul_of_dvd_left apply pow_dvd_pow _ (Nat.le_add_right m k) theorem appr_spec (n : ℕ) : ∀ x : ℤ_[p], x - appr x n ∈ Ideal.span {(p : ℤ_[p]) ^ n} := by simp only [Ideal.mem_span_singleton] induction n with | zero => simp only [zero_eq, _root_.pow_zero, isUnit_one, IsUnit.dvd, forall_const] | succ n ih => intro x dsimp only [appr] split_ifs with h · rw [h] apply dvd_zero push_cast rw [sub_add_eq_sub_sub] obtain ⟨c, hc⟩ := ih x simp only [map_natCast, ZMod.natCast_self, RingHom.map_pow, RingHom.map_mul, ZMod.natCast_val] have hc' : c ≠ 0 := by rintro rfl simp only [mul_zero] at hc contradiction conv_rhs => congr simp only [hc] rw [show (x - (appr x n : ℤ_[p])).valuation = ((p : ℤ_[p]) ^ n * c).valuation by rw [hc]] rw [valuation_p_pow_mul _ _ hc', Nat.cast_add, add_sub_cancel_left, _root_.pow_succ, ← mul_sub] apply mul_dvd_mul_left obtain hc0 | hc0 := eq_or_ne c.valuation 0 · simp only [hc0, mul_one, _root_.pow_zero, Nat.cast_zero, Int.natAbs_zero] rw [mul_comm, unitCoeff_spec h] at hc suffices c = unitCoeff h by rw [← this, ← Ideal.mem_span_singleton, ← maximalIdeal_eq_span_p] apply toZMod_spec lift c to ℤ_[p]ˣ using by simp [isUnit_iff, norm_eq_zpow_neg_valuation hc', hc0] rw [IsDiscreteValuationRing.unit_mul_pow_congr_unit _ _ _ _ _ hc] exact irreducible_p · simp only [Int.natAbs_natCast, zero_pow hc0, sub_zero, ZMod.cast_zero, mul_zero] rw [unitCoeff_spec hc'] exact (dvd_pow_self (p : ℤ_[p]) hc0).mul_left _ /-- A ring hom from `ℤ_[p]` to `ZMod (p^n)`, with underlying function `PadicInt.appr n`. -/ def toZModPow (n : ℕ) : ℤ_[p] →+* ZMod (p ^ n) := toZModHom (p ^ n) (fun x => appr x n) (by intros rw [Nat.cast_pow] exact appr_spec n _) (by intro x a b ha hb apply zmod_congr_of_sub_mem_span n x a b · simpa using ha · simpa using hb) theorem ker_toZModPow (n : ℕ) : RingHom.ker (toZModPow n : ℤ_[p] →+* ZMod (p ^ n)) = Ideal.span {(p : ℤ_[p]) ^ n} := by ext x rw [RingHom.mem_ker] constructor · intro h suffices x.appr n = 0 by convert appr_spec n x simp only [this, sub_zero, cast_zero] dsimp [toZModPow, toZModHom] at h rw [ZMod.natCast_zmod_eq_zero_iff_dvd] at h apply eq_zero_of_dvd_of_lt h (appr_lt _ _) · intro h rw [← sub_zero x] at h dsimp [toZModPow, toZModHom] rw [zmod_congr_of_sub_mem_span n x _ 0 _ h, cast_zero] apply appr_spec -- This is not a simp lemma; simp can't match the LHS. theorem zmod_cast_comp_toZModPow (m n : ℕ) (h : m ≤ n) : (ZMod.castHom (pow_dvd_pow p h) (ZMod (p ^ m))).comp (@toZModPow p _ n) = @toZModPow p _ m := by apply ZMod.ringHom_eq_of_ker_eq ext x rw [RingHom.mem_ker, RingHom.mem_ker] simp only [Function.comp_apply, ZMod.castHom_apply, RingHom.coe_comp] simp only [toZModPow, toZModHom, RingHom.coe_mk] dsimp rw [ZMod.cast_natCast (pow_dvd_pow p h), zmod_congr_of_sub_mem_span m (x.appr n) (x.appr n) (x.appr m)] · rw [sub_self] apply Ideal.zero_mem _ · rw [Ideal.mem_span_singleton] rcases dvd_appr_sub_appr x m n h with ⟨c, hc⟩ use c rw [← Nat.cast_sub (appr_mono _ h), hc, Nat.cast_mul, Nat.cast_pow] @[simp] theorem cast_toZModPow (m n : ℕ) (h : m ≤ n) (x : ℤ_[p]) : ZMod.cast (toZModPow n x) = toZModPow m x := by rw [← zmod_cast_comp_toZModPow _ _ h] rfl theorem denseRange_natCast : DenseRange (Nat.cast : ℕ → ℤ_[p]) := by intro x rw [Metric.mem_closure_range_iff] intro ε hε obtain ⟨n, hn⟩ := exists_pow_neg_lt p hε use x.appr n rw [dist_eq_norm] apply lt_of_le_of_lt _ hn rw [norm_le_pow_iff_mem_span_pow] apply appr_spec theorem denseRange_intCast : DenseRange (Int.cast : ℤ → ℤ_[p]) := by intro x refine DenseRange.induction_on denseRange_natCast x ?_ ?_ · exact isClosed_closure · intro a apply subset_closure exact Set.mem_range_self _ end RingHoms section lift /-! ### Universal property as projective limit -/ open CauSeq PadicSeq variable {R : Type*} [NonAssocSemiring R] {p : Nat} (f : ∀ k : ℕ, R →+* ZMod (p ^ k)) /-- Given a family of ring homs `f : Π n : ℕ, R →+* ZMod (p ^ n)`, `nthHom f r` is an integer-valued sequence whose `n`th value is the unique integer `k` such that `0 ≤ k < p ^ n` and `f n r = (k : ZMod (p ^ n))`. -/ def nthHom (r : R) : ℕ → ℤ := fun n => (f n r : ZMod (p ^ n)).val @[simp] theorem nthHom_zero : nthHom f 0 = 0 := by simp +unfoldPartialApp [nthHom] rfl variable {f} variable [hp_prime : Fact p.Prime] section variable (f_compat : ∀ (k1 k2) (hk : k1 ≤ k2), (ZMod.castHom (pow_dvd_pow p hk) _).comp (f k2) = f k1) include f_compat theorem pow_dvd_nthHom_sub (r : R) (i j : ℕ) (h : i ≤ j) : (p : ℤ) ^ i ∣ nthHom f r j - nthHom f r i := by specialize f_compat i j h rw [← Int.natCast_pow, ← ZMod.intCast_zmod_eq_zero_iff_dvd, Int.cast_sub] dsimp [nthHom] rw [← f_compat, RingHom.comp_apply] simp only [ZMod.cast_id, ZMod.castHom_apply, sub_self, ZMod.natCast_val, ZMod.intCast_cast] theorem isCauSeq_nthHom (r : R) : IsCauSeq (padicNorm p) fun n => nthHom f r n := by intro ε hε obtain ⟨k, hk⟩ : ∃ k : ℕ, (p : ℚ) ^ (-((k : ℕ) : ℤ)) < ε := exists_pow_neg_lt_rat p hε use k intro j hj refine lt_of_le_of_lt ?_ hk -- Need to do beta reduction first, as `norm_cast` doesn't. -- Added to adapt to https://github.com/leanprover/lean4/pull/2734. beta_reduce norm_cast rw [← padicNorm.dvd_iff_norm_le] exact mod_cast pow_dvd_nthHom_sub f_compat r k j hj /-- `nthHomSeq f_compat r` bundles `PadicInt.nthHom f r` as a Cauchy sequence of rationals with respect to the `p`-adic norm. The `n`th value of the sequence is `((f n r).val : ℚ)`. -/ def nthHomSeq (r : R) : PadicSeq p := ⟨fun n => nthHom f r n, isCauSeq_nthHom f_compat r⟩ -- this lemma ran into issues after changing to `NeZero` and I'm not sure why. theorem nthHomSeq_one : nthHomSeq f_compat 1 ≈ 1 := by intro ε hε change _ < _ at hε use 1 intro j hj haveI : Fact (1 < p ^ j) := ⟨Nat.one_lt_pow (by omega) hp_prime.1.one_lt⟩ suffices (ZMod.cast (1 : ZMod (p ^ j)) : ℚ) = 1 by simp [nthHomSeq, nthHom, this, hε] rw [ZMod.cast_eq_val, ZMod.val_one, Nat.cast_one] theorem nthHomSeq_add (r s : R) : nthHomSeq f_compat (r + s) ≈ nthHomSeq f_compat r + nthHomSeq f_compat s := by intro ε hε obtain ⟨n, hn⟩ := exists_pow_neg_lt_rat p hε use n intro j hj dsimp [nthHomSeq] apply lt_of_le_of_lt _ hn rw [← Int.cast_add, ← Int.cast_sub, ← padicNorm.dvd_iff_norm_le, ← ZMod.intCast_zmod_eq_zero_iff_dvd] dsimp [nthHom] simp only [ZMod.natCast_val, RingHom.map_add, Int.cast_sub, ZMod.intCast_cast, Int.cast_add] rw [ZMod.cast_add (show p ^ n ∣ p ^ j from pow_dvd_pow _ hj)] simp only [cast_add, ZMod.natCast_val, Int.cast_add, ZMod.intCast_cast, sub_self] theorem nthHomSeq_mul (r s : R) : nthHomSeq f_compat (r * s) ≈ nthHomSeq f_compat r * nthHomSeq f_compat s := by intro ε hε obtain ⟨n, hn⟩ := exists_pow_neg_lt_rat p hε use n intro j hj
dsimp [nthHomSeq] apply lt_of_le_of_lt _ hn rw [← Int.cast_mul, ← Int.cast_sub, ← padicNorm.dvd_iff_norm_le, ← ZMod.intCast_zmod_eq_zero_iff_dvd] dsimp [nthHom] simp only [ZMod.natCast_val, RingHom.map_mul, Int.cast_sub, ZMod.intCast_cast, Int.cast_mul] rw [ZMod.cast_mul (show p ^ n ∣ p ^ j from pow_dvd_pow _ hj), sub_self] /-- `limNthHom f_compat r` is the limit of a sequence `f` of compatible ring homs `R →+* ZMod (p^k)`. This is itself a ring hom: see `PadicInt.lift`. -/ def limNthHom (r : R) : ℤ_[p] := ofIntSeq (nthHom f r) (isCauSeq_nthHom f_compat r)
Mathlib/NumberTheory/Padics/RingHoms.lean
547
560
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios -/ import Mathlib.SetTheory.Cardinal.Arithmetic import Mathlib.SetTheory.Ordinal.FixedPoint /-! # Cofinality This file contains the definition of cofinality of an order and an ordinal number. ## Main Definitions * `Order.cof r` is the cofinality of a reflexive order. This is the smallest cardinality of a subset `s` that is *cofinal*, i.e. `∀ x, ∃ y ∈ s, r x y`. * `Ordinal.cof o` is the cofinality of the ordinal `o` when viewed as a linear order. ## Main Statements * `Cardinal.lt_power_cof`: A consequence of König's theorem stating that `c < c ^ c.ord.cof` for `c ≥ ℵ₀`. ## Implementation Notes * The cofinality is defined for ordinals. If `c` is a cardinal number, its cofinality is `c.ord.cof`. -/ noncomputable section open Function Cardinal Set Order open scoped Ordinal universe u v w variable {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop} /-! ### Cofinality of orders -/ attribute [local instance] IsRefl.swap namespace Order /-- Cofinality of a reflexive order `≼`. This is the smallest cardinality of a subset `S : Set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/ def cof (r : α → α → Prop) : Cardinal := sInf { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c } /-- The set in the definition of `Order.cof` is nonempty. -/ private theorem cof_nonempty (r : α → α → Prop) [IsRefl α r] : { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }.Nonempty := ⟨_, Set.univ, fun a => ⟨a, ⟨⟩, refl _⟩, rfl⟩ theorem cof_le (r : α → α → Prop) {S : Set α} (h : ∀ a, ∃ b ∈ S, r a b) : cof r ≤ #S := csInf_le' ⟨S, h, rfl⟩ theorem le_cof [IsRefl α r] (c : Cardinal) : c ≤ cof r ↔ ∀ {S : Set α}, (∀ a, ∃ b ∈ S, r a b) → c ≤ #S := by rw [cof, le_csInf_iff'' (cof_nonempty r)] use fun H S h => H _ ⟨S, h, rfl⟩ rintro H d ⟨S, h, rfl⟩ exact H h end Order namespace RelIso private theorem cof_le_lift [IsRefl β s] (f : r ≃r s) : Cardinal.lift.{v} (Order.cof r) ≤ Cardinal.lift.{u} (Order.cof s) := by rw [Order.cof, Order.cof, lift_sInf, lift_sInf, le_csInf_iff'' ((Order.cof_nonempty s).image _)] rintro - ⟨-, ⟨u, H, rfl⟩, rfl⟩ apply csInf_le' refine ⟨_, ⟨f.symm '' u, fun a => ?_, rfl⟩, lift_mk_eq'.2 ⟨(f.symm.toEquiv.image u).symm⟩⟩ rcases H (f a) with ⟨b, hb, hb'⟩ refine ⟨f.symm b, mem_image_of_mem _ hb, f.map_rel_iff.1 ?_⟩ rwa [RelIso.apply_symm_apply] theorem cof_eq_lift [IsRefl β s] (f : r ≃r s) : Cardinal.lift.{v} (Order.cof r) = Cardinal.lift.{u} (Order.cof s) := have := f.toRelEmbedding.isRefl (f.cof_le_lift).antisymm (f.symm.cof_le_lift) theorem cof_eq {α β : Type u} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) : Order.cof r = Order.cof s := lift_inj.1 (f.cof_eq_lift) end RelIso /-! ### Cofinality of ordinals -/ namespace Ordinal /-- Cofinality of an ordinal. This is the smallest cardinal of a subset `S` of the ordinal which is unbounded, in the sense `∀ a, ∃ b ∈ S, a ≤ b`. In particular, `cof 0 = 0` and `cof (succ o) = 1`. -/ def cof (o : Ordinal.{u}) : Cardinal.{u} := o.liftOn (fun a ↦ Order.cof (swap a.rᶜ)) fun _ _ ⟨f⟩ ↦ f.compl.swap.cof_eq theorem cof_type (r : α → α → Prop) [IsWellOrder α r] : (type r).cof = Order.cof (swap rᶜ) := rfl theorem cof_type_lt [LinearOrder α] [IsWellOrder α (· < ·)] : (@type α (· < ·) _).cof = @Order.cof α (· ≤ ·) := by rw [cof_type, compl_lt, swap_ge] theorem cof_eq_cof_toType (o : Ordinal) : o.cof = @Order.cof o.toType (· ≤ ·) := by conv_lhs => rw [← type_toType o, cof_type_lt] theorem le_cof_type [IsWellOrder α r] {c} : c ≤ cof (type r) ↔ ∀ S, Unbounded r S → c ≤ #S := (le_csInf_iff'' (Order.cof_nonempty _)).trans ⟨fun H S h => H _ ⟨S, h, rfl⟩, by rintro H d ⟨S, h, rfl⟩ exact H _ h⟩ theorem cof_type_le [IsWellOrder α r] {S : Set α} (h : Unbounded r S) : cof (type r) ≤ #S := le_cof_type.1 le_rfl S h theorem lt_cof_type [IsWellOrder α r] {S : Set α} : #S < cof (type r) → Bounded r S := by simpa using not_imp_not.2 cof_type_le theorem cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ #S = cof (type r) := csInf_mem (Order.cof_nonempty (swap rᶜ)) theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ type (Subrel r (· ∈ S)) = (cof (type r)).ord := by let ⟨S, hS, e⟩ := cof_eq r let ⟨s, _, e'⟩ := Cardinal.ord_eq S let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a } suffices Unbounded r T by refine ⟨T, this, le_antisymm ?_ (Cardinal.ord_le.2 <| cof_type_le this)⟩ rw [← e, e'] refine (RelEmbedding.ofMonotone (fun a : T => (⟨a, let ⟨aS, _⟩ := a.2 aS⟩ : S)) fun a b h => ?_).ordinal_type_le rcases a with ⟨a, aS, ha⟩ rcases b with ⟨b, bS, hb⟩ change s ⟨a, _⟩ ⟨b, _⟩ refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_ · exact asymm h (ha _ hn) · intro e injection e with e subst b exact irrefl _ h intro a have : { b : S | ¬r b a }.Nonempty := let ⟨b, bS, ba⟩ := hS a ⟨⟨b, bS⟩, ba⟩ let b := (IsWellFounded.wf : WellFounded s).min _ this have ba : ¬r b a := IsWellFounded.wf.min_mem _ this refine ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => ?_⟩, ba⟩ rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl] exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba) /-! ### Cofinality of suprema and least strict upper bounds -/ private theorem card_mem_cof {o} : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = o.card := ⟨_, _, lsub_typein o, mk_toType o⟩ /-- The set in the `lsub` characterization of `cof` is nonempty. -/ theorem cof_lsub_def_nonempty (o) : { a : Cardinal | ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a }.Nonempty := ⟨_, card_mem_cof⟩ theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o = sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by refine le_antisymm (le_csInf (cof_lsub_def_nonempty o) ?_) (csInf_le' ?_) · rintro a ⟨ι, f, hf, rfl⟩ rw [← type_toType o] refine (cof_type_le fun a => ?_).trans (@mk_le_of_injective _ _ (fun s : typein ((· < ·) : o.toType → o.toType → Prop) ⁻¹' Set.range f => Classical.choose s.prop) fun s t hst => by let H := congr_arg f hst rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj, Subtype.coe_inj] at H) have := typein_lt_self a simp_rw [← hf, lt_lsub_iff] at this obtain ⟨i, hi⟩ := this refine ⟨enum (α := o.toType) (· < ·) ⟨f i, ?_⟩, ?_, ?_⟩ · rw [type_toType, ← hf] apply lt_lsub · rw [mem_preimage, typein_enum] exact mem_range_self i · rwa [← typein_le_typein, typein_enum] · rcases cof_eq (α := o.toType) (· < ·) with ⟨S, hS, hS'⟩ let f : S → Ordinal := fun s => typein LT.lt s.val refine ⟨S, f, le_antisymm (lsub_le fun i => typein_lt_self (o := o) i) (le_of_forall_lt fun a ha => ?_), by rwa [type_toType o] at hS'⟩ rw [← type_toType o] at ha rcases hS (enum (· < ·) ⟨a, ha⟩) with ⟨b, hb, hb'⟩ rw [← typein_le_typein, typein_enum] at hb' exact hb'.trans_lt (lt_lsub.{u, u} f ⟨b, hb⟩) @[simp] theorem lift_cof (o) : Cardinal.lift.{u, v} (cof o) = cof (Ordinal.lift.{u, v} o) := by refine inductionOn o fun α r _ ↦ ?_ rw [← type_uLift, cof_type, cof_type, ← Cardinal.lift_id'.{v, u} (Order.cof _), ← Cardinal.lift_umax] apply RelIso.cof_eq_lift ⟨Equiv.ulift.symm, _⟩ simp [swap] theorem cof_le_card (o) : cof o ≤ card o := by rw [cof_eq_sInf_lsub] exact csInf_le' card_mem_cof theorem cof_ord_le (c : Cardinal) : c.ord.cof ≤ c := by simpa using cof_le_card c.ord theorem ord_cof_le (o : Ordinal.{u}) : o.cof.ord ≤ o := (ord_le_ord.2 (cof_le_card o)).trans (ord_card_le o) theorem exists_lsub_cof (o : Ordinal) : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = cof o := by rw [cof_eq_sInf_lsub] exact csInf_mem (cof_lsub_def_nonempty o) theorem cof_lsub_le {ι} (f : ι → Ordinal) : cof (lsub.{u, u} f) ≤ #ι := by rw [cof_eq_sInf_lsub] exact csInf_le' ⟨ι, f, rfl, rfl⟩ theorem cof_lsub_le_lift {ι} (f : ι → Ordinal) : cof (lsub.{u, v} f) ≤ Cardinal.lift.{v, u} #ι := by rw [← mk_uLift.{u, v}] convert cof_lsub_le.{max u v} fun i : ULift.{v, u} ι => f i.down exact lsub_eq_of_range_eq.{u, max u v, max u v} (Set.ext fun x => ⟨fun ⟨i, hi⟩ => ⟨ULift.up.{v, u} i, hi⟩, fun ⟨i, hi⟩ => ⟨_, hi⟩⟩) theorem le_cof_iff_lsub {o : Ordinal} {a : Cardinal} : a ≤ cof o ↔ ∀ {ι} (f : ι → Ordinal), lsub.{u, u} f = o → a ≤ #ι := by rw [cof_eq_sInf_lsub] exact (le_csInf_iff'' (cof_lsub_def_nonempty o)).trans ⟨fun H ι f hf => H _ ⟨ι, f, hf, rfl⟩, fun H b ⟨ι, f, hf, hb⟩ => by rw [← hb] exact H _ hf⟩ theorem lsub_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof) (hf : ∀ i, f i < c) : lsub.{u, v} f < c := lt_of_le_of_ne (lsub_le hf) fun h => by subst h exact (cof_lsub_le_lift.{u, v} f).not_lt hι theorem lsub_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) : (∀ i, f i < c) → lsub.{u, u} f < c := lsub_lt_ord_lift (by rwa [(#ι).lift_id]) theorem cof_iSup_le_lift {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) : cof (iSup f) ≤ Cardinal.lift.{v, u} #ι := by rw [← Ordinal.sup] at * rw [← sup_eq_lsub_iff_lt_sup.{u, v}] at H rw [H] exact cof_lsub_le_lift f theorem cof_iSup_le {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) : cof (iSup f) ≤ #ι := by rw [← (#ι).lift_id] exact cof_iSup_le_lift H theorem iSup_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof) (hf : ∀ i, f i < c) : iSup f < c := (sup_le_lsub.{u, v} f).trans_lt (lsub_lt_ord_lift hι hf) theorem iSup_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) : (∀ i, f i < c) → iSup f < c := iSup_lt_ord_lift (by rwa [(#ι).lift_id]) theorem iSup_lt_lift {ι} {f : ι → Cardinal} {c : Cardinal} (hι : Cardinal.lift.{v, u} #ι < c.ord.cof) (hf : ∀ i, f i < c) : iSup f < c := by rw [← ord_lt_ord, iSup_ord (Cardinal.bddAbove_range _)] refine iSup_lt_ord_lift hι fun i => ?_ rw [ord_lt_ord] apply hf theorem iSup_lt {ι} {f : ι → Cardinal} {c : Cardinal} (hι : #ι < c.ord.cof) : (∀ i, f i < c) → iSup f < c := iSup_lt_lift (by rwa [(#ι).lift_id]) theorem nfpFamily_lt_ord_lift {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : Cardinal.lift.{v, u} #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} (ha : a < c) : nfpFamily f a < c := by refine iSup_lt_ord_lift ((Cardinal.lift_le.2 (mk_list_le_max ι)).trans_lt ?_) fun l => ?_ · rw [lift_max] apply max_lt _ hc' rwa [Cardinal.lift_aleph0] · induction' l with i l H · exact ha · exact hf _ _ H theorem nfpFamily_lt_ord {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} : a < c → nfpFamily.{u, u} f a < c := nfpFamily_lt_ord_lift hc (by rwa [(#ι).lift_id]) hf theorem nfp_lt_ord {f : Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hf : ∀ i < c, f i < c) {a} : a < c → nfp f a < c := nfpFamily_lt_ord_lift hc (by simpa using Cardinal.one_lt_aleph0.trans hc) fun _ => hf theorem exists_blsub_cof (o : Ordinal) : ∃ f : ∀ a < (cof o).ord, Ordinal, blsub.{u, u} _ f = o := by rcases exists_lsub_cof o with ⟨ι, f, hf, hι⟩ rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩ rw [← @blsub_eq_lsub' ι r hr] at hf rw [← hι, hι'] exact ⟨_, hf⟩ theorem le_cof_iff_blsub {b : Ordinal} {a : Cardinal} : a ≤ cof b ↔ ∀ {o} (f : ∀ a < o, Ordinal), blsub.{u, u} o f = b → a ≤ o.card := le_cof_iff_lsub.trans ⟨fun H o f hf => by simpa using H _ hf, fun H ι f hf => by rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩ rw [← @blsub_eq_lsub' ι r hr] at hf simpa using H _ hf⟩ theorem cof_blsub_le_lift {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by rw [← mk_toType o] exact cof_lsub_le_lift _ theorem cof_blsub_le {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, u} o f) ≤ o.card := by rw [← o.card.lift_id] exact cof_blsub_le_lift f theorem blsub_lt_ord_lift {o : Ordinal.{u}} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, v} o f < c := lt_of_le_of_ne (blsub_le hf) fun h => ho.not_le (by simpa [← iSup_ord, hf, h] using cof_blsub_le_lift.{u, v} f) theorem blsub_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, u} o f < c := blsub_lt_ord_lift (by rwa [o.card.lift_id]) hf theorem cof_bsup_le_lift {o : Ordinal} {f : ∀ a < o, Ordinal} (H : ∀ i h, f i h < bsup.{u, v} o f) : cof (bsup.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by rw [← bsup_eq_blsub_iff_lt_bsup.{u, v}] at H rw [H] exact cof_blsub_le_lift.{u, v} f theorem cof_bsup_le {o : Ordinal} {f : ∀ a < o, Ordinal} : (∀ i h, f i h < bsup.{u, u} o f) → cof (bsup.{u, u} o f) ≤ o.card := by rw [← o.card.lift_id] exact cof_bsup_le_lift theorem bsup_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : bsup.{u, v} o f < c := (bsup_le_blsub f).trans_lt (blsub_lt_ord_lift ho hf) theorem bsup_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) : (∀ i hi, f i hi < c) → bsup.{u, u} o f < c := bsup_lt_ord_lift (by rwa [o.card.lift_id]) /-! ### Basic results -/ @[simp] theorem cof_zero : cof 0 = 0 := by refine LE.le.antisymm ?_ (Cardinal.zero_le _) rw [← card_zero] exact cof_le_card 0 @[simp] theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 := ⟨inductionOn o fun _ r _ z => let ⟨_, hl, e⟩ := cof_eq r type_eq_zero_iff_isEmpty.2 <| ⟨fun a => let ⟨_, h, _⟩ := hl a (mk_eq_zero_iff.1 (e.trans z)).elim' ⟨_, h⟩⟩, fun e => by simp [e]⟩ theorem cof_ne_zero {o} : cof o ≠ 0 ↔ o ≠ 0 := cof_eq_zero.not @[simp] theorem cof_succ (o) : cof (succ o) = 1 := by apply le_antisymm · refine inductionOn o fun α r _ => ?_ change cof (type _) ≤ _ rw [← (_ : #_ = 1)] · apply cof_type_le refine fun a => ⟨Sum.inr PUnit.unit, Set.mem_singleton _, ?_⟩ rcases a with (a | ⟨⟨⟨⟩⟩⟩) <;> simp [EmptyRelation] · rw [Cardinal.mk_fintype, Set.card_singleton] simp · rw [← Cardinal.succ_zero, succ_le_iff] simpa [lt_iff_le_and_ne, Cardinal.zero_le] using fun h => succ_ne_zero o (cof_eq_zero.1 (Eq.symm h)) @[simp] theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ ∃ a, o = succ a := ⟨inductionOn o fun α r _ z => by rcases cof_eq r with ⟨S, hl, e⟩; rw [z] at e obtain ⟨a⟩ := mk_ne_zero_iff.1 (by rw [e]; exact one_ne_zero) refine ⟨typein r a, Eq.symm <| Quotient.sound ⟨RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ fun x y => ?_) fun x => ?_⟩⟩ · apply Sum.rec <;> [exact Subtype.val; exact fun _ => a] · rcases x with (x | ⟨⟨⟨⟩⟩⟩) <;> rcases y with (y | ⟨⟨⟨⟩⟩⟩) <;> simp [Subrel, Order.Preimage, EmptyRelation] exact x.2 · suffices r x a ∨ ∃ _ : PUnit.{u}, ↑a = x by convert this dsimp [RelEmbedding.ofMonotone]; simp rcases trichotomous_of r x a with (h | h | h) · exact Or.inl h · exact Or.inr ⟨PUnit.unit, h.symm⟩ · rcases hl x with ⟨a', aS, hn⟩ refine absurd h ?_ convert hn change (a : α) = ↑(⟨a', aS⟩ : S) have := le_one_iff_subsingleton.1 (le_of_eq e) congr!, fun ⟨a, e⟩ => by simp [e]⟩ /-! ### Fundamental sequences -/ -- TODO: move stuff about fundamental sequences to their own file. /-- A fundamental sequence for `a` is an increasing sequence of length `o = cof a` that converges at `a`. We provide `o` explicitly in order to avoid type rewrites. -/ def IsFundamentalSequence (a o : Ordinal.{u}) (f : ∀ b < o, Ordinal.{u}) : Prop := o ≤ a.cof.ord ∧ (∀ {i j} (hi hj), i < j → f i hi < f j hj) ∧ blsub.{u, u} o f = a namespace IsFundamentalSequence variable {a o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}} protected theorem cof_eq (hf : IsFundamentalSequence a o f) : a.cof.ord = o := hf.1.antisymm' <| by rw [← hf.2.2] exact (ord_le_ord.2 (cof_blsub_le f)).trans (ord_card_le o) protected theorem strict_mono (hf : IsFundamentalSequence a o f) {i j} : ∀ hi hj, i < j → f i hi < f j hj := hf.2.1 theorem blsub_eq (hf : IsFundamentalSequence a o f) : blsub.{u, u} o f = a := hf.2.2 theorem ord_cof (hf : IsFundamentalSequence a o f) : IsFundamentalSequence a a.cof.ord fun i hi => f i (hi.trans_le (by rw [hf.cof_eq])) := by have H := hf.cof_eq subst H exact hf theorem id_of_le_cof (h : o ≤ o.cof.ord) : IsFundamentalSequence o o fun a _ => a := ⟨h, @fun _ _ _ _ => id, blsub_id o⟩ protected theorem zero {f : ∀ b < (0 : Ordinal), Ordinal} : IsFundamentalSequence 0 0 f := ⟨by rw [cof_zero, ord_zero], @fun i _ hi => (Ordinal.not_lt_zero i hi).elim, blsub_zero f⟩ protected theorem succ : IsFundamentalSequence (succ o) 1 fun _ _ => o := by refine ⟨?_, @fun i j hi hj h => ?_, blsub_const Ordinal.one_ne_zero o⟩ · rw [cof_succ, ord_one] · rw [lt_one_iff_zero] at hi hj rw [hi, hj] at h exact h.false.elim
protected theorem monotone (hf : IsFundamentalSequence a o f) {i j : Ordinal} (hi : i < o) (hj : j < o) (hij : i ≤ j) : f i hi ≤ f j hj := by
Mathlib/SetTheory/Cardinal/Cofinality.lean
469
471
/- Copyright (c) 2021 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Data.W.Basic import Mathlib.SetTheory.Cardinal.Arithmetic /-! # Cardinality of W-types This file proves some theorems about the cardinality of W-types. The main result is `cardinalMk_le_max_aleph0_of_finite` which says that if for any `a : α`, `β a` is finite, then the cardinality of `WType β` is at most the maximum of the cardinality of `α` and `ℵ₀`. This can be used to prove theorems about the cardinality of algebraic constructions such as polynomials. There is a surjection from a `WType` to `MvPolynomial` for example, and this surjection can be used to put an upper bound on the cardinality of `MvPolynomial`. ## Tags W, W type, cardinal, first order -/ universe u v variable {α : Type u} {β : α → Type v} noncomputable section namespace WType open Cardinal theorem cardinalMk_eq_sum_lift : #(WType β) = sum fun a ↦ #(WType β) ^ lift.{u} #(β a) := (mk_congr <| equivSigma β).trans <| by simp_rw [mk_sigma, mk_arrow]; rw [lift_id'.{v, u}, lift_umax.{v, u}] @[deprecated (since := "2024-11-10")] alias cardinal_mk_eq_sum' := cardinalMk_eq_sum_lift /-- `#(WType β)` is the least cardinal `κ` such that `sum (fun a : α ↦ κ ^ #(β a)) ≤ κ` -/ theorem cardinalMk_le_of_le' {κ : Cardinal.{max u v}} (hκ : (sum fun a : α => κ ^ lift.{u} #(β a)) ≤ κ) : #(WType β) ≤ κ := by induction' κ using Cardinal.inductionOn with γ simp_rw [← lift_umax.{v, u}] at hκ nth_rewrite 1 [← lift_id'.{v, u} #γ] at hκ simp_rw [← mk_arrow, ← mk_sigma, le_def] at hκ obtain ⟨hκ⟩ := hκ exact Cardinal.mk_le_of_injective (elim_injective _ hκ.1 hκ.2) @[deprecated (since := "2024-11-10")] alias cardinal_mk_le_of_le' := cardinalMk_le_of_le' /-- If, for any `a : α`, `β a` is finite, then the cardinality of `WType β`
is at most the maximum of the cardinality of `α` and `ℵ₀` -/ theorem cardinalMk_le_max_aleph0_of_finite' [∀ a, Finite (β a)] : #(WType β) ≤ max (lift.{v} #α) ℵ₀ := (isEmpty_or_nonempty α).elim (by intro h rw [Cardinal.mk_eq_zero (WType β)] exact zero_le _) fun hn => let m := max (lift.{v} #α) ℵ₀ cardinalMk_le_of_le' <| calc (Cardinal.sum fun a => m ^ lift.{u} #(β a)) ≤ lift.{v} #α * ⨆ a, m ^ lift.{u} #(β a) := Cardinal.sum_le_iSup_lift _ _ ≤ m * ⨆ a, m ^ lift.{u} #(β a) := mul_le_mul' (le_max_left _ _) le_rfl _ = m := mul_eq_left (le_max_right _ _) (ciSup_le' fun _ => pow_le (le_max_right _ _) (lt_aleph0_of_finite _)) <| pos_iff_ne_zero.1 <| Order.succ_le_iff.1 (by rw [succ_zero] obtain ⟨a⟩ : Nonempty α := hn refine le_trans ?_ (le_ciSup (bddAbove_range _) a) rw [← power_zero] exact power_le_power_left
Mathlib/Data/W/Cardinal.lean
57
83
/- 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.FieldTheory.Finiteness import Mathlib.LinearAlgebra.AffineSpace.Basis import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas /-! # Finite-dimensional subspaces of affine spaces. This file provides a few results relating to finite-dimensional subspaces of affine spaces. ## Main definitions * `Collinear` defines collinear sets of points as those that span a subspace of dimension at most 1. -/ noncomputable section open Affine open scoped Finset section AffineSpace' variable (k : Type*) {V : Type*} {P : Type*} variable {ι : Type*} open AffineSubspace Module variable [DivisionRing k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- The `vectorSpan` of a finite set is finite-dimensional. -/ theorem finiteDimensional_vectorSpan_of_finite {s : Set P} (h : Set.Finite s) : FiniteDimensional k (vectorSpan k s) := .span_of_finite k <| h.vsub h /-- The vector span of a singleton is finite-dimensional. -/ instance finiteDimensional_vectorSpan_singleton (p : P) : FiniteDimensional k (vectorSpan k {p}) := finiteDimensional_vectorSpan_of_finite _ (Set.finite_singleton p) /-- The `vectorSpan` of a family indexed by a `Fintype` is finite-dimensional. -/ instance finiteDimensional_vectorSpan_range [Finite ι] (p : ι → P) : FiniteDimensional k (vectorSpan k (Set.range p)) := finiteDimensional_vectorSpan_of_finite k (Set.finite_range _) /-- The `vectorSpan` of a subset of a family indexed by a `Fintype` is finite-dimensional. -/ instance finiteDimensional_vectorSpan_image_of_finite [Finite ι] (p : ι → P) (s : Set ι) : FiniteDimensional k (vectorSpan k (p '' s)) := finiteDimensional_vectorSpan_of_finite k (Set.toFinite _) /-- The direction of the affine span of a finite set is finite-dimensional. -/ theorem finiteDimensional_direction_affineSpan_of_finite {s : Set P} (h : Set.Finite s) : FiniteDimensional k (affineSpan k s).direction := (direction_affineSpan k s).symm ▸ finiteDimensional_vectorSpan_of_finite k h /-- The direction of the affine span of a singleton is finite-dimensional. -/ instance finiteDimensional_direction_affineSpan_singleton (p : P) : FiniteDimensional k (affineSpan k {p}).direction := by rw [direction_affineSpan] infer_instance /-- The direction of the affine span of a family indexed by a `Fintype` is finite-dimensional. -/ instance finiteDimensional_direction_affineSpan_range [Finite ι] (p : ι → P) : FiniteDimensional k (affineSpan k (Set.range p)).direction := finiteDimensional_direction_affineSpan_of_finite k (Set.finite_range _) /-- The direction of the affine span of a subset of a family indexed by a `Fintype` is finite-dimensional. -/ instance finiteDimensional_direction_affineSpan_image_of_finite [Finite ι] (p : ι → P) (s : Set ι) : FiniteDimensional k (affineSpan k (p '' s)).direction := finiteDimensional_direction_affineSpan_of_finite k (Set.toFinite _) /-- An affine-independent family of points in a finite-dimensional affine space is finite. -/ theorem finite_of_fin_dim_affineIndependent [FiniteDimensional k V] {p : ι → P} (hi : AffineIndependent k p) : Finite ι := by nontriviality ι; inhabit ι rw [affineIndependent_iff_linearIndependent_vsub k p default] at hi letI : IsNoetherian k V := IsNoetherian.iff_fg.2 inferInstance exact (Set.finite_singleton default).finite_of_compl (Set.finite_coe_iff.1 hi.finite_of_isNoetherian) /-- An affine-independent subset of a finite-dimensional affine space is finite. -/ theorem finite_set_of_fin_dim_affineIndependent [FiniteDimensional k V] {s : Set ι} {f : s → P} (hi : AffineIndependent k f) : s.Finite := @Set.toFinite _ s (finite_of_fin_dim_affineIndependent k hi) variable {k} /-- The `vectorSpan` of a finite subset of an affinely independent family has dimension one less than its cardinality. -/ theorem AffineIndependent.finrank_vectorSpan_image_finset [DecidableEq P] {p : ι → P} (hi : AffineIndependent k p) {s : Finset ι} {n : ℕ} (hc : #s = n + 1) : finrank k (vectorSpan k (s.image p : Set P)) = n := by classical have hi' := hi.range.mono (Set.image_subset_range p ↑s) have hc' : #(s.image p) = n + 1 := by rwa [s.card_image_of_injective hi.injective] have hn : (s.image p).Nonempty := by simp [hc', ← Finset.card_pos] rcases hn with ⟨p₁, hp₁⟩ have hp₁' : p₁ ∈ p '' s := by simpa using hp₁ rw [affineIndependent_set_iff_linearIndependent_vsub k hp₁', ← Finset.coe_singleton, ← Finset.coe_image, ← Finset.coe_sdiff, Finset.sdiff_singleton_eq_erase, ← Finset.coe_image] at hi' have hc : #(((s.image p).erase p₁).image (· -ᵥ p₁)) = n := by rw [Finset.card_image_of_injective _ (vsub_left_injective _), Finset.card_erase_of_mem hp₁] exact Nat.pred_eq_of_eq_succ hc' rwa [vectorSpan_eq_span_vsub_finset_right_ne k hp₁, finrank_span_finset_eq_card, hc] /-- The `vectorSpan` of a finite affinely independent family has dimension one less than its cardinality. -/ theorem AffineIndependent.finrank_vectorSpan [Fintype ι] {p : ι → P} (hi : AffineIndependent k p) {n : ℕ} (hc : Fintype.card ι = n + 1) : finrank k (vectorSpan k (Set.range p)) = n := by classical rw [← Finset.card_univ] at hc rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image] exact hi.finrank_vectorSpan_image_finset hc /-- The `vectorSpan` of a finite affinely independent family has dimension one less than its cardinality. -/ lemma AffineIndependent.finrank_vectorSpan_add_one [Fintype ι] [Nonempty ι] {p : ι → P} (hi : AffineIndependent k p) : finrank k (vectorSpan k (Set.range p)) + 1 = Fintype.card ι := by rw [hi.finrank_vectorSpan (tsub_add_cancel_of_le _).symm, tsub_add_cancel_of_le] <;> exact Fintype.card_pos /-- The `vectorSpan` of a finite affinely independent family whose cardinality is one more than that of the finite-dimensional space is `⊤`. -/ theorem AffineIndependent.vectorSpan_eq_top_of_card_eq_finrank_add_one [FiniteDimensional k V] [Fintype ι] {p : ι → P} (hi : AffineIndependent k p) (hc : Fintype.card ι = finrank k V + 1) : vectorSpan k (Set.range p) = ⊤ := Submodule.eq_top_of_finrank_eq <| hi.finrank_vectorSpan hc variable (k) /-- The `vectorSpan` of `n + 1` points in an indexed family has dimension at most `n`. -/ theorem finrank_vectorSpan_image_finset_le [DecidableEq P] (p : ι → P) (s : Finset ι) {n : ℕ} (hc : #s = n + 1) : finrank k (vectorSpan k (s.image p : Set P)) ≤ n := by classical have hn : (s.image p).Nonempty := by rw [Finset.image_nonempty, ← Finset.card_pos, hc] apply Nat.succ_pos rcases hn with ⟨p₁, hp₁⟩ rw [vectorSpan_eq_span_vsub_finset_right_ne k hp₁] refine le_trans (finrank_span_finset_le_card (((s.image p).erase p₁).image fun p => p -ᵥ p₁)) ?_ rw [Finset.card_image_of_injective _ (vsub_left_injective p₁), Finset.card_erase_of_mem hp₁, tsub_le_iff_right, ← hc] apply Finset.card_image_le /-- The `vectorSpan` of an indexed family of `n + 1` points has dimension at most `n`. -/ theorem finrank_vectorSpan_range_le [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 1) : finrank k (vectorSpan k (Set.range p)) ≤ n := by classical rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image] rw [← Finset.card_univ] at hc exact finrank_vectorSpan_image_finset_le _ _ _ hc /-- The `vectorSpan` of an indexed family of `n + 1` points has dimension at most `n`. -/ lemma finrank_vectorSpan_range_add_one_le [Fintype ι] [Nonempty ι] (p : ι → P) : finrank k (vectorSpan k (Set.range p)) + 1 ≤ Fintype.card ι := (le_tsub_iff_right <| Nat.succ_le_iff.2 Fintype.card_pos).1 <| finrank_vectorSpan_range_le _ _ (tsub_add_cancel_of_le <| Nat.succ_le_iff.2 Fintype.card_pos).symm /-- `n + 1` points are affinely independent if and only if their `vectorSpan` has dimension `n`. -/ theorem affineIndependent_iff_finrank_vectorSpan_eq [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 1) : AffineIndependent k p ↔ finrank k (vectorSpan k (Set.range p)) = n := by classical have hn : Nonempty ι := by simp [← Fintype.card_pos_iff, hc] obtain ⟨i₁⟩ := hn rw [affineIndependent_iff_linearIndependent_vsub _ _ i₁, linearIndependent_iff_card_eq_finrank_span, eq_comm, vectorSpan_range_eq_span_range_vsub_right_ne k p i₁, Set.finrank] rw [← Finset.card_univ] at hc rw [Fintype.subtype_card] simp [Finset.filter_ne', Finset.card_erase_of_mem, hc] /-- `n + 1` points are affinely independent if and only if their `vectorSpan` has dimension at least `n`. -/ theorem affineIndependent_iff_le_finrank_vectorSpan [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 1) : AffineIndependent k p ↔ n ≤ finrank k (vectorSpan k (Set.range p)) := by rw [affineIndependent_iff_finrank_vectorSpan_eq k p hc] constructor · rintro rfl rfl · exact fun hle => le_antisymm (finrank_vectorSpan_range_le k p hc) hle /-- `n + 2` points are affinely independent if and only if their `vectorSpan` does not have dimension at most `n`. -/ theorem affineIndependent_iff_not_finrank_vectorSpan_le [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 2) : AffineIndependent k p ↔ ¬finrank k (vectorSpan k (Set.range p)) ≤ n := by rw [affineIndependent_iff_le_finrank_vectorSpan k p hc, ← Nat.lt_iff_add_one_le, lt_iff_not_ge] /-- `n + 2` points have a `vectorSpan` with dimension at most `n` if and only if they are not affinely independent. -/ theorem finrank_vectorSpan_le_iff_not_affineIndependent [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 2) : finrank k (vectorSpan k (Set.range p)) ≤ n ↔ ¬AffineIndependent k p := (not_iff_comm.1 (affineIndependent_iff_not_finrank_vectorSpan_le k p hc).symm).symm variable {k} lemma AffineIndependent.card_le_finrank_succ [Fintype ι] {p : ι → P} (hp : AffineIndependent k p) : Fintype.card ι ≤ Module.finrank k (vectorSpan k (Set.range p)) + 1 := by cases isEmpty_or_nonempty ι · simp [Fintype.card_eq_zero] rw [← tsub_le_iff_right] exact (affineIndependent_iff_le_finrank_vectorSpan _ _ (tsub_add_cancel_of_le <| Nat.one_le_iff_ne_zero.2 Fintype.card_ne_zero).symm).1 hp open Finset in /-- If an affine independent finset is contained in the affine span of another finset, then its cardinality is at most the cardinality of that finset. -/ lemma AffineIndependent.card_le_card_of_subset_affineSpan {s t : Finset V} (hs : AffineIndependent k ((↑) : s → V)) (hst : (s : Set V) ⊆ affineSpan k (t : Set V)) : #s ≤ #t := by obtain rfl | hs' := s.eq_empty_or_nonempty · simp obtain rfl | ht' := t.eq_empty_or_nonempty · simpa [Set.subset_empty_iff] using hst have := hs'.to_subtype have := ht'.to_set.to_subtype have direction_le := AffineSubspace.direction_le (affineSpan_mono k hst) rw [AffineSubspace.affineSpan_coe, direction_affineSpan, direction_affineSpan, ← @Subtype.range_coe _ (s : Set V), ← @Subtype.range_coe _ (t : Set V)] at direction_le have finrank_le := add_le_add_right (Submodule.finrank_mono direction_le) 1 -- We use `erw` to elide the difference between `↥s` and `↥(s : Set V)}` erw [hs.finrank_vectorSpan_add_one] at finrank_le simpa using finrank_le.trans <| finrank_vectorSpan_range_add_one_le _ _ open Finset in /-- If the affine span of an affine independent finset is strictly contained in the affine span of another finset, then its cardinality is strictly less than the cardinality of that finset. -/ lemma AffineIndependent.card_lt_card_of_affineSpan_lt_affineSpan {s t : Finset V} (hs : AffineIndependent k ((↑) : s → V)) (hst : affineSpan k (s : Set V) < affineSpan k (t : Set V)) : #s < #t := by obtain rfl | hs' := s.eq_empty_or_nonempty · simpa [card_pos] using hst obtain rfl | ht' := t.eq_empty_or_nonempty · simp [Set.subset_empty_iff] at hst have := hs'.to_subtype have := ht'.to_set.to_subtype have dir_lt := AffineSubspace.direction_lt_of_nonempty (k := k) hst <| hs'.to_set.affineSpan k rw [direction_affineSpan, direction_affineSpan, ← @Subtype.range_coe _ (s : Set V), ← @Subtype.range_coe _ (t : Set V)] at dir_lt have finrank_lt := add_lt_add_right (Submodule.finrank_lt_finrank_of_lt dir_lt) 1 -- We use `erw` to elide the difference between `↥s` and `↥(s : Set V)}` erw [hs.finrank_vectorSpan_add_one] at finrank_lt simpa using finrank_lt.trans_le <| finrank_vectorSpan_range_add_one_le _ _ /-- If the `vectorSpan` of a finite subset of an affinely independent family lies in a submodule with dimension one less than its cardinality, it equals that submodule. -/ theorem AffineIndependent.vectorSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one [DecidableEq P] {p : ι → P} (hi : AffineIndependent k p) {s : Finset ι} {sm : Submodule k V} [FiniteDimensional k sm] (hle : vectorSpan k (s.image p : Set P) ≤ sm) (hc : #s = finrank k sm + 1) : vectorSpan k (s.image p : Set P) = sm := Submodule.eq_of_le_of_finrank_eq hle <| hi.finrank_vectorSpan_image_finset hc /-- If the `vectorSpan` of a finite affinely independent family lies in a submodule with dimension one less than its cardinality, it equals that submodule. -/ theorem AffineIndependent.vectorSpan_eq_of_le_of_card_eq_finrank_add_one [Fintype ι] {p : ι → P} (hi : AffineIndependent k p) {sm : Submodule k V} [FiniteDimensional k sm] (hle : vectorSpan k (Set.range p) ≤ sm) (hc : Fintype.card ι = finrank k sm + 1) : vectorSpan k (Set.range p) = sm := Submodule.eq_of_le_of_finrank_eq hle <| hi.finrank_vectorSpan hc /-- If the `affineSpan` of a finite subset of an affinely independent family lies in an affine subspace whose direction has dimension one less than its cardinality, it equals that subspace. -/ theorem AffineIndependent.affineSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one [DecidableEq P] {p : ι → P} (hi : AffineIndependent k p) {s : Finset ι} {sp : AffineSubspace k P} [FiniteDimensional k sp.direction] (hle : affineSpan k (s.image p : Set P) ≤ sp) (hc : #s = finrank k sp.direction + 1) : affineSpan k (s.image p : Set P) = sp := by have hn : s.Nonempty := by rw [← Finset.card_pos, hc] apply Nat.succ_pos refine eq_of_direction_eq_of_nonempty_of_le ?_ ((hn.image p).to_set.affineSpan k) hle have hd := direction_le hle rw [direction_affineSpan] at hd ⊢ exact hi.vectorSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one hd hc /-- If the `affineSpan` of a finite affinely independent family lies in an affine subspace whose direction has dimension one less than its cardinality, it equals that subspace. -/ theorem AffineIndependent.affineSpan_eq_of_le_of_card_eq_finrank_add_one [Fintype ι] {p : ι → P} (hi : AffineIndependent k p) {sp : AffineSubspace k P} [FiniteDimensional k sp.direction] (hle : affineSpan k (Set.range p) ≤ sp) (hc : Fintype.card ι = finrank k sp.direction + 1) : affineSpan k (Set.range p) = sp := by classical rw [← Finset.card_univ] at hc rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image] at hle ⊢ exact hi.affineSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one hle hc /-- The `affineSpan` of a finite affinely independent family is `⊤` iff the family's cardinality is one more than that of the finite-dimensional space. -/ theorem AffineIndependent.affineSpan_eq_top_iff_card_eq_finrank_add_one [FiniteDimensional k V] [Fintype ι] {p : ι → P} (hi : AffineIndependent k p) : affineSpan k (Set.range p) = ⊤ ↔ Fintype.card ι = finrank k V + 1 := by constructor · intro h_tot let n := Fintype.card ι - 1 have hn : Fintype.card ι = n + 1 := (Nat.succ_pred_eq_of_pos (card_pos_of_affineSpan_eq_top k V P h_tot)).symm rw [hn, ← finrank_top, ← (vectorSpan_eq_top_of_affineSpan_eq_top k V P) h_tot, ← hi.finrank_vectorSpan hn] · intro hc rw [← finrank_top, ← direction_top k V P] at hc exact hi.affineSpan_eq_of_le_of_card_eq_finrank_add_one le_top hc theorem Affine.Simplex.span_eq_top [FiniteDimensional k V] {n : ℕ} (T : Affine.Simplex k V n) (hrank : finrank k V = n) : affineSpan k (Set.range T.points) = ⊤ := by rw [AffineIndependent.affineSpan_eq_top_iff_card_eq_finrank_add_one T.independent, Fintype.card_fin, hrank] /-- The `vectorSpan` of adding a point to a finite-dimensional subspace is finite-dimensional. -/ instance finiteDimensional_vectorSpan_insert (s : AffineSubspace k P) [FiniteDimensional k s.direction] (p : P) : FiniteDimensional k (vectorSpan k (insert p (s : Set P))) := by rw [← direction_affineSpan, ← affineSpan_insert_affineSpan] rcases (s : Set P).eq_empty_or_nonempty with (hs | ⟨p₀, hp₀⟩) · rw [coe_eq_bot_iff] at hs rw [hs, bot_coe, span_empty, bot_coe, direction_affineSpan] convert finiteDimensional_bot k V <;> simp · rw [affineSpan_coe, direction_affineSpan_insert hp₀] infer_instance /-- The direction of the affine span of adding a point to a finite-dimensional subspace is finite-dimensional. -/ instance finiteDimensional_direction_affineSpan_insert (s : AffineSubspace k P) [FiniteDimensional k s.direction] (p : P) : FiniteDimensional k (affineSpan k (insert p (s : Set P))).direction := (direction_affineSpan k (insert p (s : Set P))).symm ▸ finiteDimensional_vectorSpan_insert s p variable (k) /-- The `vectorSpan` of adding a point to a set with a finite-dimensional `vectorSpan` is finite-dimensional. -/ instance finiteDimensional_vectorSpan_insert_set (s : Set P) [FiniteDimensional k (vectorSpan k s)] (p : P) : FiniteDimensional k (vectorSpan k (insert p s)) := by haveI : FiniteDimensional k (affineSpan k s).direction := (direction_affineSpan k s).symm ▸ inferInstance rw [← direction_affineSpan, ← affineSpan_insert_affineSpan, direction_affineSpan] exact finiteDimensional_vectorSpan_insert (affineSpan k s) p /-- A set of points is collinear if their `vectorSpan` has dimension at most `1`. -/ def Collinear (s : Set P) : Prop := Module.rank k (vectorSpan k s) ≤ 1 /-- The definition of `Collinear`. -/ theorem collinear_iff_rank_le_one (s : Set P) : Collinear k s ↔ Module.rank k (vectorSpan k s) ≤ 1 := Iff.rfl variable {k} /-- A set of points, whose `vectorSpan` is finite-dimensional, is collinear if and only if their `vectorSpan` has dimension at most `1`. -/ theorem collinear_iff_finrank_le_one {s : Set P} [FiniteDimensional k (vectorSpan k s)] : Collinear k s ↔ finrank k (vectorSpan k s) ≤ 1 := by have h := collinear_iff_rank_le_one k s rw [← finrank_eq_rank] at h exact mod_cast h alias ⟨Collinear.finrank_le_one, _⟩ := collinear_iff_finrank_le_one /-- A subset of a collinear set is collinear. -/ theorem Collinear.subset {s₁ s₂ : Set P} (hs : s₁ ⊆ s₂) (h : Collinear k s₂) : Collinear k s₁ := (Submodule.rank_mono (vectorSpan_mono k hs)).trans h /-- The `vectorSpan` of collinear points is finite-dimensional. -/ theorem Collinear.finiteDimensional_vectorSpan {s : Set P} (h : Collinear k s) : FiniteDimensional k (vectorSpan k s) := IsNoetherian.iff_fg.1 (IsNoetherian.iff_rank_lt_aleph0.2 (lt_of_le_of_lt h Cardinal.one_lt_aleph0))
/-- The direction of the affine span of collinear points is finite-dimensional. -/ theorem Collinear.finiteDimensional_direction_affineSpan {s : Set P} (h : Collinear k s) : FiniteDimensional k (affineSpan k s).direction := (direction_affineSpan k s).symm ▸ h.finiteDimensional_vectorSpan
Mathlib/LinearAlgebra/AffineSpace/FiniteDimensional.lean
395
399
/- 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₁]
Mathlib/Data/List/Intervals.lean
62
69
/- Copyright (c) 2023 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Divisibility.Basic import Mathlib.Algebra.Group.Prod import Mathlib.Tactic.Common /-! # Lemmas about the divisibility relation in product (semi)groups -/ variable {ι G₁ G₂ : Type*} {G : ι → Type*} [Semigroup G₁] [Semigroup G₂] [∀ i, Semigroup (G i)]
theorem prod_dvd_iff {x y : G₁ × G₂} : x ∣ y ↔ x.1 ∣ y.1 ∧ x.2 ∣ y.2 := by cases x; cases y simp only [dvd_def, Prod.exists, Prod.mk_mul_mk, Prod.mk.injEq, exists_and_left, exists_and_right, and_self, true_and]
Mathlib/Algebra/Divisibility/Prod.lean
16
20
/- 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
Mathlib/Data/Int/ModEq.lean
112
114
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kim Morrison, Ainsley Pahljina -/ import Mathlib.RingTheory.Fintype import Mathlib.Tactic.NormNum import Mathlib.Tactic.Ring import Mathlib.Tactic.Zify /-! # The Lucas-Lehmer test for Mersenne primes. We define `lucasLehmerResidue : Π p : ℕ, ZMod (2^p - 1)`, and prove `lucasLehmerResidue p = 0 → Prime (mersenne p)`. We construct a `norm_num` extension to calculate this residue to certify primality of Mersenne primes using `lucas_lehmer_sufficiency`. ## TODO - Show reverse implication. - Speed up the calculations using `n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1]`. - Find some bigger primes! ## History This development began as a student project by Ainsley Pahljina, and was then cleaned up for mathlib by Kim Morrison. The tactic for certified computation of Lucas-Lehmer residues was provided by Mario Carneiro. This tactic was ported by Thomas Murrills to Lean 4, and then it was converted to a `norm_num` extension and made to use kernel reductions by Kyle Miller. -/ assert_not_exists TwoSidedIdeal /-- The Mersenne numbers, 2^p - 1. -/ def mersenne (p : ℕ) : ℕ := 2 ^ p - 1 theorem strictMono_mersenne : StrictMono mersenne := fun m n h ↦ (Nat.sub_lt_sub_iff_right <| Nat.one_le_pow _ _ two_pos).2 <| by gcongr; norm_num1 @[simp] theorem mersenne_lt_mersenne {p q : ℕ} : mersenne p < mersenne q ↔ p < q := strictMono_mersenne.lt_iff_lt @[gcongr] protected alias ⟨_, GCongr.mersenne_lt_mersenne⟩ := mersenne_lt_mersenne @[simp] theorem mersenne_le_mersenne {p q : ℕ} : mersenne p ≤ mersenne q ↔ p ≤ q := strictMono_mersenne.le_iff_le @[gcongr] protected alias ⟨_, GCongr.mersenne_le_mersenne⟩ := mersenne_le_mersenne @[simp] theorem mersenne_zero : mersenne 0 = 0 := rfl @[simp] lemma mersenne_odd : ∀ {p : ℕ}, Odd (mersenne p) ↔ p ≠ 0 | 0 => by simp | p + 1 => by simpa using Nat.Even.sub_odd (one_le_pow₀ one_le_two) (even_two.pow_of_ne_zero p.succ_ne_zero) odd_one @[simp] theorem mersenne_pos {p : ℕ} : 0 < mersenne p ↔ 0 < p := mersenne_lt_mersenne (p := 0) namespace Mathlib.Meta.Positivity open Lean Meta Qq Function alias ⟨_, mersenne_pos_of_pos⟩ := mersenne_pos /-- Extension for the `positivity` tactic: `mersenne`. -/ @[positivity mersenne _] def evalMersenne : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℕ), ~q(mersenne $a) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure (.positive q(mersenne_pos_of_pos $pa)) | _ => pure (.nonnegative q(Nat.zero_le (mersenne $a))) | _, _, _ => throwError "not mersenne" end Mathlib.Meta.Positivity @[simp] theorem one_lt_mersenne {p : ℕ} : 1 < mersenne p ↔ 1 < p := mersenne_lt_mersenne (p := 1) @[simp] theorem succ_mersenne (k : ℕ) : mersenne k + 1 = 2 ^ k := by rw [mersenne, tsub_add_cancel_of_le] exact one_le_pow₀ (by norm_num) namespace LucasLehmer open Nat /-! We now define three(!) different versions of the recurrence `s (i+1) = (s i)^2 - 2`. These versions take values either in `ℤ`, in `ZMod (2^p - 1)`, or in `ℤ` but applying `% (2^p - 1)` at each step. They are each useful at different points in the proof, so we take a moment setting up the lemmas relating them. -/ /-- The recurrence `s (i+1) = (s i)^2 - 2` in `ℤ`. -/ def s : ℕ → ℤ | 0 => 4 | i + 1 => s i ^ 2 - 2 /-- The recurrence `s (i+1) = (s i)^2 - 2` in `ZMod (2^p - 1)`. -/ def sZMod (p : ℕ) : ℕ → ZMod (2 ^ p - 1) | 0 => 4 | i + 1 => sZMod p i ^ 2 - 2 /-- The recurrence `s (i+1) = ((s i)^2 - 2) % (2^p - 1)` in `ℤ`. -/ def sMod (p : ℕ) : ℕ → ℤ | 0 => 4 % (2 ^ p - 1) | i + 1 => (sMod p i ^ 2 - 2) % (2 ^ p - 1) theorem mersenne_int_pos {p : ℕ} (hp : p ≠ 0) : (0 : ℤ) < 2 ^ p - 1 := sub_pos.2 <| mod_cast Nat.one_lt_two_pow hp theorem mersenne_int_ne_zero (p : ℕ) (hp : p ≠ 0) : (2 ^ p - 1 : ℤ) ≠ 0 := (mersenne_int_pos hp).ne' theorem sMod_nonneg (p : ℕ) (hp : p ≠ 0) (i : ℕ) : 0 ≤ sMod p i := by cases i <;> dsimp [sMod] · exact sup_eq_right.mp rfl · apply Int.emod_nonneg exact mersenne_int_ne_zero p hp theorem sMod_mod (p i : ℕ) : sMod p i % (2 ^ p - 1) = sMod p i := by cases i <;> simp [sMod] theorem sMod_lt (p : ℕ) (hp : p ≠ 0) (i : ℕ) : sMod p i < 2 ^ p - 1 := by rw [← sMod_mod] refine (Int.emod_lt_abs _ (mersenne_int_ne_zero p hp)).trans_eq ?_ exact abs_of_nonneg (mersenne_int_pos hp).le theorem sZMod_eq_s (p' : ℕ) (i : ℕ) : sZMod (p' + 2) i = (s i : ZMod (2 ^ (p' + 2) - 1)) := by induction i with | zero => dsimp [s, sZMod]; norm_num
| succ i ih => push_cast [s, sZMod, ih]; rfl -- These next two don't make good `norm_cast` lemmas. theorem Int.natCast_pow_pred (b p : ℕ) (w : 0 < b) : ((b ^ p - 1 : ℕ) : ℤ) = (b : ℤ) ^ p - 1 := by
Mathlib/NumberTheory/LucasLehmer.lean
148
151
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Patrick Massot -/ import Mathlib.Data.Set.Image import Mathlib.Data.SProd /-! # Sets in product and pi types This file proves basic properties of product of sets in `α × β` and in `Π i, α i`, and of the diagonal of a type. ## Main declarations This file contains basic results on the following notions, which are defined in `Set.Operations`. * `Set.prod`: Binary product of sets. For `s : Set α`, `t : Set β`, we have `s.prod t : Set (α × β)`. Denoted by `s ×ˢ t`. * `Set.diagonal`: Diagonal of a type. `Set.diagonal α = {(x, x) | x : α}`. * `Set.offDiag`: Off-diagonal. `s ×ˢ s` without the diagonal. * `Set.pi`: Arbitrary product of sets. -/ open Function namespace Set /-! ### Cartesian binary product of sets -/ section Prod variable {α β γ δ : Type*} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {a : α} {b : β} theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) : (s ×ˢ t).Subsingleton := fun _x hx _y hy ↦ Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2) noncomputable instance decidableMemProd [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] : DecidablePred (· ∈ s ×ˢ t) := fun x => inferInstanceAs (Decidable (x.1 ∈ s ∧ x.2 ∈ t)) @[gcongr] theorem prod_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ×ˢ t₁ ⊆ s₂ ×ˢ t₂ := fun _ ⟨h₁, h₂⟩ => ⟨hs h₁, ht h₂⟩ @[gcongr] theorem prod_mono_left (hs : s₁ ⊆ s₂) : s₁ ×ˢ t ⊆ s₂ ×ˢ t := prod_mono hs Subset.rfl @[gcongr] theorem prod_mono_right (ht : t₁ ⊆ t₂) : s ×ˢ t₁ ⊆ s ×ˢ t₂ := prod_mono Subset.rfl ht @[simp] theorem prod_self_subset_prod_self : s₁ ×ˢ s₁ ⊆ s₂ ×ˢ s₂ ↔ s₁ ⊆ s₂ := ⟨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => ⟨h hx.1, h hx.2⟩⟩ @[simp] theorem prod_self_ssubset_prod_self : s₁ ×ˢ s₁ ⊂ s₂ ×ˢ s₂ ↔ s₁ ⊂ s₂ := and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self theorem prod_subset_iff {P : Set (α × β)} : s ×ˢ t ⊆ P ↔ ∀ x ∈ s, ∀ y ∈ t, (x, y) ∈ P := ⟨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h ⟨_, _⟩ hp => h _ hp.1 _ hp.2⟩ theorem forall_prod_set {p : α × β → Prop} : (∀ x ∈ s ×ˢ t, p x) ↔ ∀ x ∈ s, ∀ y ∈ t, p (x, y) := prod_subset_iff theorem exists_prod_set {p : α × β → Prop} : (∃ x ∈ s ×ˢ t, p x) ↔ ∃ x ∈ s, ∃ y ∈ t, p (x, y) := by simp [and_assoc] @[simp] theorem prod_empty : s ×ˢ (∅ : Set β) = ∅ := by ext exact iff_of_eq (and_false _) @[simp] theorem empty_prod : (∅ : Set α) ×ˢ t = ∅ := by ext exact iff_of_eq (false_and _) @[simp, mfld_simps] theorem univ_prod_univ : @univ α ×ˢ @univ β = univ := by ext exact iff_of_eq (true_and _) theorem univ_prod {t : Set β} : (univ : Set α) ×ˢ t = Prod.snd ⁻¹' t := by simp [prod_eq] theorem prod_univ {s : Set α} : s ×ˢ (univ : Set β) = Prod.fst ⁻¹' s := by simp [prod_eq] @[simp] lemma prod_eq_univ [Nonempty α] [Nonempty β] : s ×ˢ t = univ ↔ s = univ ∧ t = univ := by simp [eq_univ_iff_forall, forall_and] theorem singleton_prod : ({a} : Set α) ×ˢ t = Prod.mk a '' t := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] theorem prod_singleton : s ×ˢ ({b} : Set β) = (fun a => (a, b)) '' s := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] @[simp] theorem singleton_prod_singleton : ({a} : Set α) ×ˢ ({b} : Set β) = {(a, b)} := by ext ⟨c, d⟩; simp @[simp] theorem union_prod : (s₁ ∪ s₂) ×ˢ t = s₁ ×ˢ t ∪ s₂ ×ˢ t := by ext ⟨x, y⟩ simp [or_and_right] @[simp] theorem prod_union : s ×ˢ (t₁ ∪ t₂) = s ×ˢ t₁ ∪ s ×ˢ t₂ := by ext ⟨x, y⟩ simp [and_or_left] theorem inter_prod : (s₁ ∩ s₂) ×ˢ t = s₁ ×ˢ t ∩ s₂ ×ˢ t := by ext ⟨x, y⟩ simp only [← and_and_right, mem_inter_iff, mem_prod] theorem prod_inter : s ×ˢ (t₁ ∩ t₂) = s ×ˢ t₁ ∩ s ×ˢ t₂ := by ext ⟨x, y⟩ simp only [← and_and_left, mem_inter_iff, mem_prod] @[mfld_simps] theorem prod_inter_prod : s₁ ×ˢ t₁ ∩ s₂ ×ˢ t₂ = (s₁ ∩ s₂) ×ˢ (t₁ ∩ t₂) := by ext ⟨x, y⟩ simp [and_assoc, and_left_comm] lemma compl_prod_eq_union {α β : Type*} (s : Set α) (t : Set β) : (s ×ˢ t)ᶜ = (sᶜ ×ˢ univ) ∪ (univ ×ˢ tᶜ) := by
ext p simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and] constructor <;> intro h
Mathlib/Data/Set/Prod.lean
132
134
/- Copyright (c) 2021 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.Order.Module.Algebra import Mathlib.Algebra.Ring.Subring.Units import Mathlib.LinearAlgebra.LinearIndependent.Defs import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Module import Mathlib.Tactic.Positivity.Basic /-! # Rays in modules This file defines rays in modules. ## Main definitions * `SameRay`: two vectors belong to the same ray if they are proportional with a nonnegative coefficient. * `Module.Ray` is a type for the equivalence class of nonzero vectors in a module with some common positive multiple. -/ noncomputable section section StrictOrderedCommSemiring -- TODO: remove `[IsStrictOrderedRing R]` and `@[nolint unusedArguments]`. /-- Two vectors are in the same ray if either one of them is zero or some positive multiples of them are equal (in the typical case over a field, this means one of them is a nonnegative multiple of the other). -/ @[nolint unusedArguments] def SameRay (R : Type*) [CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R] {M : Type*} [AddCommMonoid M] [Module R M] (v₁ v₂ : M) : Prop := v₁ = 0 ∨ v₂ = 0 ∨ ∃ r₁ r₂ : R, 0 < r₁ ∧ 0 < r₂ ∧ r₁ • v₁ = r₂ • v₂ variable {R : Type*} [CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R] variable {M : Type*} [AddCommMonoid M] [Module R M] variable {N : Type*} [AddCommMonoid N] [Module R N] variable (ι : Type*) [DecidableEq ι] namespace SameRay variable {x y z : M} @[simp] theorem zero_left (y : M) : SameRay R 0 y := Or.inl rfl @[simp] theorem zero_right (x : M) : SameRay R x 0 := Or.inr <| Or.inl rfl @[nontriviality] theorem of_subsingleton [Subsingleton M] (x y : M) : SameRay R x y := by rw [Subsingleton.elim x 0] exact zero_left _ @[nontriviality] theorem of_subsingleton' [Subsingleton R] (x y : M) : SameRay R x y := haveI := Module.subsingleton R M of_subsingleton x y /-- `SameRay` is reflexive. -/ @[refl] theorem refl (x : M) : SameRay R x x := by nontriviality R exact Or.inr (Or.inr <| ⟨1, 1, zero_lt_one, zero_lt_one, rfl⟩) protected theorem rfl : SameRay R x x := refl _ /-- `SameRay` is symmetric. -/ @[symm] theorem symm (h : SameRay R x y) : SameRay R y x := (or_left_comm.1 h).imp_right <| Or.imp_right fun ⟨r₁, r₂, h₁, h₂, h⟩ => ⟨r₂, r₁, h₂, h₁, h.symm⟩ /-- If `x` and `y` are nonzero vectors on the same ray, then there exist positive numbers `r₁ r₂` such that `r₁ • x = r₂ • y`. -/ theorem exists_pos (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) : ∃ r₁ r₂ : R, 0 < r₁ ∧ 0 < r₂ ∧ r₁ • x = r₂ • y := (h.resolve_left hx).resolve_left hy theorem sameRay_comm : SameRay R x y ↔ SameRay R y x := ⟨SameRay.symm, SameRay.symm⟩ /-- `SameRay` is transitive unless the vector in the middle is zero and both other vectors are nonzero. -/ theorem trans (hxy : SameRay R x y) (hyz : SameRay R y z) (hy : y = 0 → x = 0 ∨ z = 0) : SameRay R x z := by rcases eq_or_ne x 0 with (rfl | hx); · exact zero_left z rcases eq_or_ne z 0 with (rfl | hz); · exact zero_right x rcases eq_or_ne y 0 with (rfl | hy) · exact (hy rfl).elim (fun h => (hx h).elim) fun h => (hz h).elim rcases hxy.exists_pos hx hy with ⟨r₁, r₂, hr₁, hr₂, h₁⟩ rcases hyz.exists_pos hy hz with ⟨r₃, r₄, hr₃, hr₄, h₂⟩ refine Or.inr (Or.inr <| ⟨r₃ * r₁, r₂ * r₄, mul_pos hr₃ hr₁, mul_pos hr₂ hr₄, ?_⟩) rw [mul_smul, mul_smul, h₁, ← h₂, smul_comm] variable {S : Type*} [CommSemiring S] [PartialOrder S] [Algebra S R] [Module S M] [SMulPosMono S R] [IsScalarTower S R M] {a : S} /-- A vector is in the same ray as a nonnegative multiple of itself. -/ lemma sameRay_nonneg_smul_right (v : M) (h : 0 ≤ a) : SameRay R v (a • v) := by obtain h | h := (algebraMap_nonneg R h).eq_or_gt · rw [← algebraMap_smul R a v, h, zero_smul] exact zero_right _ · refine Or.inr <| Or.inr ⟨algebraMap S R a, 1, h, by nontriviality R; exact zero_lt_one, ?_⟩ module /-- A nonnegative multiple of a vector is in the same ray as that vector. -/ lemma sameRay_nonneg_smul_left (v : M) (ha : 0 ≤ a) : SameRay R (a • v) v := (sameRay_nonneg_smul_right v ha).symm /-- A vector is in the same ray as a positive multiple of itself. -/ lemma sameRay_pos_smul_right (v : M) (ha : 0 < a) : SameRay R v (a • v) := sameRay_nonneg_smul_right v ha.le /-- A positive multiple of a vector is in the same ray as that vector. -/ lemma sameRay_pos_smul_left (v : M) (ha : 0 < a) : SameRay R (a • v) v := sameRay_nonneg_smul_left v ha.le /-- A vector is in the same ray as a nonnegative multiple of one it is in the same ray as. -/ lemma nonneg_smul_right (h : SameRay R x y) (ha : 0 ≤ a) : SameRay R x (a • y) := h.trans (sameRay_nonneg_smul_right y ha) fun hy => Or.inr <| by rw [hy, smul_zero] /-- A nonnegative multiple of a vector is in the same ray as one it is in the same ray as. -/ lemma nonneg_smul_left (h : SameRay R x y) (ha : 0 ≤ a) : SameRay R (a • x) y := (h.symm.nonneg_smul_right ha).symm /-- A vector is in the same ray as a positive multiple of one it is in the same ray as. -/ theorem pos_smul_right (h : SameRay R x y) (ha : 0 < a) : SameRay R x (a • y) := h.nonneg_smul_right ha.le /-- A positive multiple of a vector is in the same ray as one it is in the same ray as. -/ theorem pos_smul_left (h : SameRay R x y) (hr : 0 < a) : SameRay R (a • x) y := h.nonneg_smul_left hr.le /-- If two vectors are on the same ray then they remain so after applying a linear map. -/ theorem map (f : M →ₗ[R] N) (h : SameRay R x y) : SameRay R (f x) (f y) := (h.imp fun hx => by rw [hx, map_zero]) <| Or.imp (fun hy => by rw [hy, map_zero]) fun ⟨r₁, r₂, hr₁, hr₂, h⟩ => ⟨r₁, r₂, hr₁, hr₂, by rw [← f.map_smul, ← f.map_smul, h]⟩ /-- The images of two vectors under an injective linear map are on the same ray if and only if the original vectors are on the same ray. -/ theorem _root_.Function.Injective.sameRay_map_iff {F : Type*} [FunLike F M N] [LinearMapClass F R M N] {f : F} (hf : Function.Injective f) : SameRay R (f x) (f y) ↔ SameRay R x y := by simp only [SameRay, map_zero, ← hf.eq_iff, map_smul] /-- The images of two vectors under a linear equivalence are on the same ray if and only if the original vectors are on the same ray. -/ @[simp] theorem sameRay_map_iff (e : M ≃ₗ[R] N) : SameRay R (e x) (e y) ↔ SameRay R x y := Function.Injective.sameRay_map_iff (EquivLike.injective e) /-- If two vectors are on the same ray then both scaled by the same action are also on the same ray. -/ theorem smul {S : Type*} [Monoid S] [DistribMulAction S M] [SMulCommClass R S M] (h : SameRay R x y) (s : S) : SameRay R (s • x) (s • y) := h.map (s • (LinearMap.id : M →ₗ[R] M)) /-- If `x` and `y` are on the same ray as `z`, then so is `x + y`. -/ theorem add_left (hx : SameRay R x z) (hy : SameRay R y z) : SameRay R (x + y) z := by rcases eq_or_ne x 0 with (rfl | hx₀); · rwa [zero_add] rcases eq_or_ne y 0 with (rfl | hy₀); · rwa [add_zero] rcases eq_or_ne z 0 with (rfl | hz₀); · apply zero_right rcases hx.exists_pos hx₀ hz₀ with ⟨rx, rz₁, hrx, hrz₁, Hx⟩ rcases hy.exists_pos hy₀ hz₀ with ⟨ry, rz₂, hry, hrz₂, Hy⟩ refine Or.inr (Or.inr ⟨rx * ry, ry * rz₁ + rx * rz₂, mul_pos hrx hry, ?_, ?_⟩) · positivity · convert congr(ry • $Hx + rx • $Hy) using 1 <;> module /-- If `y` and `z` are on the same ray as `x`, then so is `y + z`. -/ theorem add_right (hy : SameRay R x y) (hz : SameRay R x z) : SameRay R x (y + z) := (hy.symm.add_left hz.symm).symm end SameRay set_option linter.unusedVariables false in /-- Nonzero vectors, as used to define rays. This type depends on an unused argument `R` so that `RayVector.Setoid` can be an instance. -/ @[nolint unusedArguments] def RayVector (R M : Type*) [Zero M] := { v : M // v ≠ 0 } instance RayVector.coe [Zero M] : CoeOut (RayVector R M) M where coe := Subtype.val instance {R M : Type*} [Zero M] [Nontrivial M] : Nonempty (RayVector R M) := let ⟨x, hx⟩ := exists_ne (0 : M) ⟨⟨x, hx⟩⟩ variable (R M) /-- The setoid of the `SameRay` relation for the subtype of nonzero vectors. -/ instance RayVector.Setoid : Setoid (RayVector R M) where r x y := SameRay R (x : M) y iseqv := ⟨fun _ => SameRay.refl _, fun h => h.symm, by intros x y z hxy hyz exact hxy.trans hyz fun hy => (y.2 hy).elim⟩ /-- A ray (equivalence class of nonzero vectors with common positive multiples) in a module. -/ def Module.Ray := Quotient (RayVector.Setoid R M) variable {R M} /-- Equivalence of nonzero vectors, in terms of `SameRay`. -/ theorem equiv_iff_sameRay {v₁ v₂ : RayVector R M} : v₁ ≈ v₂ ↔ SameRay R (v₁ : M) v₂ := Iff.rfl variable (R) /-- The ray given by a nonzero vector. -/ def rayOfNeZero (v : M) (h : v ≠ 0) : Module.Ray R M := ⟦⟨v, h⟩⟧ /-- An induction principle for `Module.Ray`, used as `induction x using Module.Ray.ind`. -/ theorem Module.Ray.ind {C : Module.Ray R M → Prop} (h : ∀ (v) (hv : v ≠ 0), C (rayOfNeZero R v hv)) (x : Module.Ray R M) : C x := Quotient.ind (Subtype.rec <| h) x variable {R} instance [Nontrivial M] : Nonempty (Module.Ray R M) := Nonempty.map Quotient.mk' inferInstance /-- The rays given by two nonzero vectors are equal if and only if those vectors satisfy `SameRay`. -/ theorem ray_eq_iff {v₁ v₂ : M} (hv₁ : v₁ ≠ 0) (hv₂ : v₂ ≠ 0) : rayOfNeZero R _ hv₁ = rayOfNeZero R _ hv₂ ↔ SameRay R v₁ v₂ := Quotient.eq' /-- The ray given by a positive multiple of a nonzero vector. -/ @[simp] theorem ray_pos_smul {v : M} (h : v ≠ 0) {r : R} (hr : 0 < r) (hrv : r • v ≠ 0) : rayOfNeZero R (r • v) hrv = rayOfNeZero R v h := (ray_eq_iff _ _).2 <| SameRay.sameRay_pos_smul_left v hr /-- An equivalence between modules implies an equivalence between ray vectors. -/ def RayVector.mapLinearEquiv (e : M ≃ₗ[R] N) : RayVector R M ≃ RayVector R N := Equiv.subtypeEquiv e.toEquiv fun _ => e.map_ne_zero_iff.symm /-- An equivalence between modules implies an equivalence between rays. -/ def Module.Ray.map (e : M ≃ₗ[R] N) : Module.Ray R M ≃ Module.Ray R N := Quotient.congr (RayVector.mapLinearEquiv e) fun _ _=> (SameRay.sameRay_map_iff _).symm @[simp] theorem Module.Ray.map_apply (e : M ≃ₗ[R] N) (v : M) (hv : v ≠ 0) : Module.Ray.map e (rayOfNeZero _ v hv) = rayOfNeZero _ (e v) (e.map_ne_zero_iff.2 hv) := rfl @[simp] theorem Module.Ray.map_refl : (Module.Ray.map <| LinearEquiv.refl R M) = Equiv.refl _ := Equiv.ext <| Module.Ray.ind R fun _ _ => rfl @[simp] theorem Module.Ray.map_symm (e : M ≃ₗ[R] N) : (Module.Ray.map e).symm = Module.Ray.map e.symm := rfl section Action variable {G : Type*} [Group G] [DistribMulAction G M] /-- Any invertible action preserves the non-zeroness of ray vectors. This is primarily of interest when `G = Rˣ` -/ instance {R : Type*} : MulAction G (RayVector R M) where smul r := Subtype.map (r • ·) fun _ => (smul_ne_zero_iff_ne _).2 mul_smul a b _ := Subtype.ext <| mul_smul a b _ one_smul _ := Subtype.ext <| one_smul _ _ variable [SMulCommClass R G M] /-- Any invertible action preserves the non-zeroness of rays. This is primarily of interest when `G = Rˣ` -/ instance : MulAction G (Module.Ray R M) where smul r := Quotient.map (r • ·) fun _ _ h => h.smul _ mul_smul a b := Quotient.ind fun _ => congr_arg Quotient.mk' <| mul_smul a b _ one_smul := Quotient.ind fun _ => congr_arg Quotient.mk' <| one_smul _ _ /-- The action via `LinearEquiv.apply_distribMulAction` corresponds to `Module.Ray.map`. -/ @[simp] theorem Module.Ray.linearEquiv_smul_eq_map (e : M ≃ₗ[R] M) (v : Module.Ray R M) : e • v = Module.Ray.map e v := rfl @[simp] theorem smul_rayOfNeZero (g : G) (v : M) (hv) : g • rayOfNeZero R v hv = rayOfNeZero R (g • v) ((smul_ne_zero_iff_ne _).2 hv) := rfl end Action namespace Module.Ray /-- Scaling by a positive unit is a no-op. -/ theorem units_smul_of_pos (u : Rˣ) (hu : 0 < (u : R)) (v : Module.Ray R M) : u • v = v := by induction v using Module.Ray.ind rw [smul_rayOfNeZero, ray_eq_iff] exact SameRay.sameRay_pos_smul_left _ hu /-- An arbitrary `RayVector` giving a ray. -/ def someRayVector (x : Module.Ray R M) : RayVector R M := Quotient.out x /-- The ray of `someRayVector`. -/ @[simp] theorem someRayVector_ray (x : Module.Ray R M) : (⟦x.someRayVector⟧ : Module.Ray R M) = x := Quotient.out_eq _ /-- An arbitrary nonzero vector giving a ray. -/ def someVector (x : Module.Ray R M) : M := x.someRayVector /-- `someVector` is nonzero. -/ @[simp] theorem someVector_ne_zero (x : Module.Ray R M) : x.someVector ≠ 0 := x.someRayVector.property /-- The ray of `someVector`. -/ @[simp] theorem someVector_ray (x : Module.Ray R M) : rayOfNeZero R _ x.someVector_ne_zero = x := (congr_arg _ (Subtype.coe_eta _ _) :).trans x.out_eq end Module.Ray end StrictOrderedCommSemiring section StrictOrderedCommRing variable {R : Type*} [CommRing R] [PartialOrder R] [IsStrictOrderedRing R] variable {M N : Type*} [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] {x y : M} /-- `SameRay.neg` as an `iff`. -/ @[simp] theorem sameRay_neg_iff : SameRay R (-x) (-y) ↔ SameRay R x y := by simp only [SameRay, neg_eq_zero, smul_neg, neg_inj]
alias ⟨SameRay.of_neg, SameRay.neg⟩ := sameRay_neg_iff theorem sameRay_neg_swap : SameRay R (-x) y ↔ SameRay R x (-y) := by rw [← sameRay_neg_iff, neg_neg]
Mathlib/LinearAlgebra/Ray.lean
348
351
/- 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.Order.Filter.SmallSets import Mathlib.Topology.UniformSpace.Defs import Mathlib.Topology.ContinuousOn /-! # Basic results on uniform spaces Uniform spaces are a generalization of metric spaces and topological groups. ## Main definitions In this file we define a complete lattice structure on the type `UniformSpace X` of uniform structures on `X`, as well as the pullback (`UniformSpace.comap`) of uniform structures coming from the pullback of filters. Like distance functions, uniform structures cannot be pushed forward in general. ## Notations Localized in `Uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`, and `○` for composition of relations, seen as terms with type `Set (X × X)`. ## References The formalization uses the books: * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] But it makes a more systematic use of the filter library. -/ open Set Filter Topology universe u v ua ub uc ud /-! ### Relations, seen as `Set (α × α)` -/ variable {α : Type ua} {β : Type ub} {γ : Type uc} {δ : Type ud} {ι : Sort*} open Uniformity section UniformSpace variable [UniformSpace α] /-- If `s ∈ 𝓤 α`, then for any natural `n`, for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ○ ... ○ t ⊆ s` (`n` compositions). -/ theorem eventually_uniformity_iterate_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) (n : ℕ) : ∀ᶠ t in (𝓤 α).smallSets, (t ○ ·)^[n] t ⊆ s := by suffices ∀ᶠ t in (𝓤 α).smallSets, t ⊆ s ∧ (t ○ ·)^[n] t ⊆ s from (eventually_and.1 this).2 induction n generalizing s with | zero => simpa | succ _ ihn => rcases comp_mem_uniformity_sets hs with ⟨t, htU, hts⟩ refine (ihn htU).mono fun U hU => ?_ rw [Function.iterate_succ_apply'] exact ⟨hU.1.trans <| (subset_comp_self <| refl_le_uniformity htU).trans hts, (compRel_mono hU.1 hU.2).trans hts⟩ /-- If `s ∈ 𝓤 α`, then for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ⊆ s`. -/ theorem eventually_uniformity_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∀ᶠ t in (𝓤 α).smallSets, t ○ t ⊆ s := eventually_uniformity_iterate_comp_subset hs 1 /-! ### Balls in uniform spaces -/ namespace UniformSpace open UniformSpace (ball) lemma isOpen_ball (x : α) {V : Set (α × α)} (hV : IsOpen V) : IsOpen (ball x V) := hV.preimage <| .prodMk_right _ lemma isClosed_ball (x : α) {V : Set (α × α)} (hV : IsClosed V) : IsClosed (ball x V) := hV.preimage <| .prodMk_right _ /-! ### Neighborhoods in uniform spaces -/ theorem hasBasis_nhds_prod (x y : α) : HasBasis (𝓝 (x, y)) (fun s => s ∈ 𝓤 α ∧ IsSymmetricRel s) fun s => ball x s ×ˢ ball y s := by rw [nhds_prod_eq] apply (hasBasis_nhds x).prod_same_index (hasBasis_nhds y) rintro U V ⟨U_in, U_symm⟩ ⟨V_in, V_symm⟩ exact ⟨U ∩ V, ⟨(𝓤 α).inter_sets U_in V_in, U_symm.inter V_symm⟩, ball_inter_left x U V, ball_inter_right y U V⟩ end UniformSpace open UniformSpace theorem nhds_eq_uniformity_prod {a b : α} : 𝓝 (a, b) = (𝓤 α).lift' fun s : Set (α × α) => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ s } := by rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'] · exact fun s => monotone_const.set_prod monotone_preimage · refine fun t => Monotone.set_prod ?_ monotone_const exact monotone_preimage (f := fun y => (y, a)) theorem nhdset_of_mem_uniformity {d : Set (α × α)} (s : Set (α × α)) (hd : d ∈ 𝓤 α) : ∃ t : Set (α × α), IsOpen t ∧ s ⊆ t ∧ t ⊆ { p | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } := by let cl_d := { p : α × α | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } have : ∀ p ∈ s, ∃ t, t ⊆ cl_d ∧ IsOpen t ∧ p ∈ t := fun ⟨x, y⟩ hp => mem_nhds_iff.mp <| show cl_d ∈ 𝓝 (x, y) by rw [nhds_eq_uniformity_prod, mem_lift'_sets] · exact ⟨d, hd, fun ⟨a, b⟩ ⟨ha, hb⟩ => ⟨x, y, ha, hp, hb⟩⟩ · exact fun _ _ h _ h' => ⟨h h'.1, h h'.2⟩ choose t ht using this exact ⟨(⋃ p : α × α, ⋃ h : p ∈ s, t p h : Set (α × α)), isOpen_iUnion fun p : α × α => isOpen_iUnion fun hp => (ht p hp).right.left, fun ⟨a, b⟩ hp => by simp only [mem_iUnion, Prod.exists]; exact ⟨a, b, hp, (ht (a, b) hp).right.right⟩, iUnion_subset fun p => iUnion_subset fun hp => (ht p hp).left⟩ /-- Entourages are neighborhoods of the diagonal. -/ theorem nhds_le_uniformity (x : α) : 𝓝 (x, x) ≤ 𝓤 α := by intro V V_in rcases comp_symm_mem_uniformity_sets V_in with ⟨w, w_in, w_symm, w_sub⟩ have : ball x w ×ˢ ball x w ∈ 𝓝 (x, x) := by rw [nhds_prod_eq] exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in) apply mem_of_superset this rintro ⟨u, v⟩ ⟨u_in, v_in⟩ exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in) /-- Entourages are neighborhoods of the diagonal. -/ theorem iSup_nhds_le_uniformity : ⨆ x : α, 𝓝 (x, x) ≤ 𝓤 α := iSup_le nhds_le_uniformity /-- Entourages are neighborhoods of the diagonal. -/ theorem nhdsSet_diagonal_le_uniformity : 𝓝ˢ (diagonal α) ≤ 𝓤 α := (nhdsSet_diagonal α).trans_le iSup_nhds_le_uniformity section variable (α) theorem UniformSpace.has_seq_basis [IsCountablyGenerated <| 𝓤 α] : ∃ V : ℕ → Set (α × α), HasAntitoneBasis (𝓤 α) V ∧ ∀ n, IsSymmetricRel (V n) := let ⟨U, hsym, hbasis⟩ := (@UniformSpace.hasBasis_symmetric α _).exists_antitone_subbasis ⟨U, hbasis, fun n => (hsym n).2⟩ end /-! ### Closure and interior in uniform spaces -/ theorem closure_eq_uniformity (s : Set <| α × α) : closure s = ⋂ V ∈ { V | V ∈ 𝓤 α ∧ IsSymmetricRel V }, V ○ s ○ V := by ext ⟨x, y⟩ simp +contextual only [mem_closure_iff_nhds_basis (UniformSpace.hasBasis_nhds_prod x y), mem_iInter, mem_setOf_eq, and_imp, mem_comp_comp, exists_prop, ← mem_inter_iff, inter_comm, Set.Nonempty] theorem uniformity_hasBasis_closed : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsClosed V) id := by refine Filter.hasBasis_self.2 fun t h => ?_ rcases comp_comp_symm_mem_uniformity_sets h with ⟨w, w_in, w_symm, r⟩ refine ⟨closure w, mem_of_superset w_in subset_closure, isClosed_closure, ?_⟩ refine Subset.trans ?_ r rw [closure_eq_uniformity] apply iInter_subset_of_subset apply iInter_subset exact ⟨w_in, w_symm⟩ theorem uniformity_eq_uniformity_closure : 𝓤 α = (𝓤 α).lift' closure := Eq.symm <| uniformity_hasBasis_closed.lift'_closure_eq_self fun _ => And.right theorem Filter.HasBasis.uniformity_closure {p : ι → Prop} {U : ι → Set (α × α)} (h : (𝓤 α).HasBasis p U) : (𝓤 α).HasBasis p fun i => closure (U i) := (@uniformity_eq_uniformity_closure α _).symm ▸ h.lift'_closure /-- Closed entourages form a basis of the uniformity filter. -/ theorem uniformity_hasBasis_closure : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α) closure := (𝓤 α).basis_sets.uniformity_closure theorem closure_eq_inter_uniformity {t : Set (α × α)} : closure t = ⋂ d ∈ 𝓤 α, d ○ (t ○ d) := calc closure t = ⋂ (V) (_ : V ∈ 𝓤 α ∧ IsSymmetricRel V), V ○ t ○ V := closure_eq_uniformity t _ = ⋂ V ∈ 𝓤 α, V ○ t ○ V := Eq.symm <| UniformSpace.hasBasis_symmetric.biInter_mem fun _ _ hV => compRel_mono (compRel_mono hV Subset.rfl) hV _ = ⋂ V ∈ 𝓤 α, V ○ (t ○ V) := by simp only [compRel_assoc] theorem uniformity_eq_uniformity_interior : 𝓤 α = (𝓤 α).lift' interior := le_antisymm (le_iInf₂ fun d hd => by let ⟨s, hs, hs_comp⟩ := comp3_mem_uniformity hd let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs have : s ⊆ interior d := calc s ⊆ t := hst _ ⊆ interior d := ht.subset_interior_iff.mpr fun x (hx : x ∈ t) => let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp hx hs_comp ⟨x, h₁, y, h₂, h₃⟩ have : interior d ∈ 𝓤 α := by filter_upwards [hs] using this simp [this]) fun _ hs => ((𝓤 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset theorem interior_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : interior s ∈ 𝓤 α := by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs theorem mem_uniformity_isClosed {s : Set (α × α)} (h : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsClosed t ∧ t ⊆ s := let ⟨t, ⟨ht_mem, htc⟩, hts⟩ := uniformity_hasBasis_closed.mem_iff.1 h ⟨t, ht_mem, htc, hts⟩ theorem isOpen_iff_isOpen_ball_subset {s : Set α} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, IsOpen V ∧ ball x V ⊆ s := by rw [isOpen_iff_ball_subset] constructor <;> intro h x hx · obtain ⟨V, hV, hV'⟩ := h x hx exact ⟨interior V, interior_mem_uniformity hV, isOpen_interior, (ball_mono interior_subset x).trans hV'⟩ · obtain ⟨V, hV, -, hV'⟩ := h x hx exact ⟨V, hV, hV'⟩ @[deprecated (since := "2024-11-18")] alias isOpen_iff_open_ball_subset := isOpen_iff_isOpen_ball_subset /-- The uniform neighborhoods of all points of a dense set cover the whole space. -/ theorem Dense.biUnion_uniformity_ball {s : Set α} {U : Set (α × α)} (hs : Dense s) (hU : U ∈ 𝓤 α) : ⋃ x ∈ s, ball x U = univ := by refine iUnion₂_eq_univ_iff.2 fun y => ?_ rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with ⟨x, hxs, hxy : (x, y) ∈ U⟩ exact ⟨x, hxs, hxy⟩ /-- The uniform neighborhoods of all points of a dense indexed collection cover the whole space. -/ lemma DenseRange.iUnion_uniformity_ball {ι : Type*} {xs : ι → α} (xs_dense : DenseRange xs) {U : Set (α × α)} (hU : U ∈ uniformity α) : ⋃ i, UniformSpace.ball (xs i) U = univ := by rw [← biUnion_range (f := xs) (g := fun x ↦ UniformSpace.ball x U)] exact Dense.biUnion_uniformity_ball xs_dense hU /-! ### Uniformity bases -/ /-- Open elements of `𝓤 α` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V) id := hasBasis_self.2 fun s hs => ⟨interior s, interior_mem_uniformity hs, isOpen_interior, interior_subset⟩ theorem Filter.HasBasis.mem_uniformity_iff {p : β → Prop} {s : β → Set (α × α)} (h : (𝓤 α).HasBasis p s) {t : Set (α × α)} : t ∈ 𝓤 α ↔ ∃ i, p i ∧ ∀ a b, (a, b) ∈ s i → (a, b) ∈ t := h.mem_iff.trans <| by simp only [Prod.forall, subset_def] /-- Open elements `s : Set (α × α)` of `𝓤 α` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open_symmetric : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V ∧ IsSymmetricRel V) id := by simp only [← and_assoc] refine uniformity_hasBasis_open.restrict fun s hs => ⟨symmetrizeRel s, ?_⟩ exact ⟨⟨symmetrize_mem_uniformity hs.1, IsOpen.inter hs.2 (hs.2.preimage continuous_swap)⟩, symmetric_symmetrizeRel s, symmetrizeRel_subset_self s⟩ theorem comp_open_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsOpen t ∧ IsSymmetricRel t ∧ t ○ t ⊆ s := by obtain ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs obtain ⟨u, ⟨hu₁, hu₂, hu₃⟩, hu₄ : u ⊆ t⟩ := uniformity_hasBasis_open_symmetric.mem_iff.mp ht₁ exact ⟨u, hu₁, hu₂, hu₃, (compRel_mono hu₄ hu₄).trans ht₂⟩ end UniformSpace open uniformity section Constructions instance : PartialOrder (UniformSpace α) := PartialOrder.lift (fun u => 𝓤[u]) fun _ _ => UniformSpace.ext protected theorem UniformSpace.le_def {u₁ u₂ : UniformSpace α} : u₁ ≤ u₂ ↔ 𝓤[u₁] ≤ 𝓤[u₂] := Iff.rfl instance : InfSet (UniformSpace α) := ⟨fun s => UniformSpace.ofCore { uniformity := ⨅ u ∈ s, 𝓤[u] refl := le_iInf fun u => le_iInf fun _ => u.toCore.refl symm := le_iInf₂ fun u hu => le_trans (map_mono <| iInf_le_of_le _ <| iInf_le _ hu) u.symm comp := le_iInf₂ fun u hu => le_trans (lift'_mono (iInf_le_of_le _ <| iInf_le _ hu) <| le_rfl) u.comp }⟩ protected theorem UniformSpace.sInf_le {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : t ∈ tt) : sInf tt ≤ t := show ⨅ u ∈ tt, 𝓤[u] ≤ 𝓤[t] from iInf₂_le t h protected theorem UniformSpace.le_sInf {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : ∀ t' ∈ tt, t ≤ t') : t ≤ sInf tt := show 𝓤[t] ≤ ⨅ u ∈ tt, 𝓤[u] from le_iInf₂ h instance : Top (UniformSpace α) := ⟨@UniformSpace.mk α ⊤ ⊤ le_top le_top fun x ↦ by simp only [nhds_top, comap_top]⟩ instance : Bot (UniformSpace α) := ⟨{ toTopologicalSpace := ⊥ uniformity := 𝓟 idRel symm := by simp [Tendsto] comp := lift'_le (mem_principal_self _) <| principal_mono.2 id_compRel.subset nhds_eq_comap_uniformity := fun s => by let _ : TopologicalSpace α := ⊥; have := discreteTopology_bot α simp [idRel] }⟩ instance : Min (UniformSpace α) := ⟨fun u₁ u₂ => { uniformity := 𝓤[u₁] ⊓ 𝓤[u₂] symm := u₁.symm.inf u₂.symm comp := (lift'_inf_le _ _ _).trans <| inf_le_inf u₁.comp u₂.comp toTopologicalSpace := u₁.toTopologicalSpace ⊓ u₂.toTopologicalSpace nhds_eq_comap_uniformity := fun _ ↦ by rw [@nhds_inf _ u₁.toTopologicalSpace _, @nhds_eq_comap_uniformity _ u₁, @nhds_eq_comap_uniformity _ u₂, comap_inf] }⟩ instance : CompleteLattice (UniformSpace α) := { inferInstanceAs (PartialOrder (UniformSpace α)) with sup := fun a b => sInf { x | a ≤ x ∧ b ≤ x } le_sup_left := fun _ _ => UniformSpace.le_sInf fun _ ⟨h, _⟩ => h le_sup_right := fun _ _ => UniformSpace.le_sInf fun _ ⟨_, h⟩ => h sup_le := fun _ _ _ h₁ h₂ => UniformSpace.sInf_le ⟨h₁, h₂⟩ inf := (· ⊓ ·) le_inf := fun a _ _ h₁ h₂ => show a.uniformity ≤ _ from le_inf h₁ h₂ inf_le_left := fun a _ => show _ ≤ a.uniformity from inf_le_left inf_le_right := fun _ b => show _ ≤ b.uniformity from inf_le_right top := ⊤ le_top := fun a => show a.uniformity ≤ ⊤ from le_top bot := ⊥ bot_le := fun u => u.toCore.refl sSup := fun tt => sInf { t | ∀ t' ∈ tt, t' ≤ t } le_sSup := fun _ _ h => UniformSpace.le_sInf fun _ h' => h' _ h sSup_le := fun _ _ h => UniformSpace.sInf_le h sInf := sInf le_sInf := fun _ _ hs => UniformSpace.le_sInf hs sInf_le := fun _ _ ha => UniformSpace.sInf_le ha } theorem iInf_uniformity {ι : Sort*} {u : ι → UniformSpace α} : 𝓤[iInf u] = ⨅ i, 𝓤[u i] := iInf_range theorem inf_uniformity {u v : UniformSpace α} : 𝓤[u ⊓ v] = 𝓤[u] ⊓ 𝓤[v] := rfl lemma bot_uniformity : 𝓤[(⊥ : UniformSpace α)] = 𝓟 idRel := rfl lemma top_uniformity : 𝓤[(⊤ : UniformSpace α)] = ⊤ := rfl instance inhabitedUniformSpace : Inhabited (UniformSpace α) := ⟨⊥⟩ instance inhabitedUniformSpaceCore : Inhabited (UniformSpace.Core α) := ⟨@UniformSpace.toCore _ default⟩ instance [Subsingleton α] : Unique (UniformSpace α) where uniq u := bot_unique <| le_principal_iff.2 <| by rw [idRel, ← diagonal, diagonal_eq_univ]; exact univ_mem /-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f` is the inverse image in the filter sense of the induced function `α × α → β × β`. See note [reducible non-instances]. -/ abbrev UniformSpace.comap (f : α → β) (u : UniformSpace β) : UniformSpace α where uniformity := 𝓤[u].comap fun p : α × α => (f p.1, f p.2) symm := by simp only [tendsto_comap_iff, Prod.swap, (· ∘ ·)] exact tendsto_swap_uniformity.comp tendsto_comap comp := le_trans (by rw [comap_lift'_eq, comap_lift'_eq2] · exact lift'_mono' fun s _ ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩ => ⟨f x, h₁, h₂⟩ · exact monotone_id.compRel monotone_id) (comap_mono u.comp) toTopologicalSpace := u.toTopologicalSpace.induced f nhds_eq_comap_uniformity x := by simp only [nhds_induced, nhds_eq_comap_uniformity, comap_comap, Function.comp_def] theorem uniformity_comap {_ : UniformSpace β} (f : α → β) : 𝓤[UniformSpace.comap f ‹_›] = comap (Prod.map f f) (𝓤 β) := rfl lemma ball_preimage {f : α → β} {U : Set (β × β)} {x : α} : UniformSpace.ball x (Prod.map f f ⁻¹' U) = f ⁻¹' UniformSpace.ball (f x) U := by ext : 1 simp only [UniformSpace.ball, mem_preimage, Prod.map_apply] @[simp] theorem uniformSpace_comap_id {α : Type*} : UniformSpace.comap (id : α → α) = id := by ext : 2 rw [uniformity_comap, Prod.map_id, comap_id] theorem UniformSpace.comap_comap {α β γ} {uγ : UniformSpace γ} {f : α → β} {g : β → γ} : UniformSpace.comap (g ∘ f) uγ = UniformSpace.comap f (UniformSpace.comap g uγ) := by ext1 simp only [uniformity_comap, Filter.comap_comap, Prod.map_comp_map] theorem UniformSpace.comap_inf {α γ} {u₁ u₂ : UniformSpace γ} {f : α → γ} : (u₁ ⊓ u₂).comap f = u₁.comap f ⊓ u₂.comap f := UniformSpace.ext Filter.comap_inf theorem UniformSpace.comap_iInf {ι α γ} {u : ι → UniformSpace γ} {f : α → γ} : (⨅ i, u i).comap f = ⨅ i, (u i).comap f := by ext : 1 simp [uniformity_comap, iInf_uniformity] theorem UniformSpace.comap_mono {α γ} {f : α → γ} : Monotone fun u : UniformSpace γ => u.comap f := fun _ _ hu => Filter.comap_mono hu theorem uniformContinuous_iff {α β} {uα : UniformSpace α} {uβ : UniformSpace β} {f : α → β} : UniformContinuous f ↔ uα ≤ uβ.comap f := Filter.map_le_iff_le_comap theorem le_iff_uniformContinuous_id {u v : UniformSpace α} : u ≤ v ↔ @UniformContinuous _ _ u v id := by rw [uniformContinuous_iff, uniformSpace_comap_id, id] theorem uniformContinuous_comap {f : α → β} [u : UniformSpace β] : @UniformContinuous α β (UniformSpace.comap f u) u f := tendsto_comap theorem uniformContinuous_comap' {f : γ → β} {g : α → γ} [v : UniformSpace β] [u : UniformSpace α] (h : UniformContinuous (f ∘ g)) : @UniformContinuous α γ u (UniformSpace.comap f v) g := tendsto_comap_iff.2 h namespace UniformSpace theorem to_nhds_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) (a : α) : @nhds _ (@UniformSpace.toTopologicalSpace _ u₁) a ≤ @nhds _ (@UniformSpace.toTopologicalSpace _ u₂) a := by rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact lift'_mono h le_rfl theorem toTopologicalSpace_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) : @UniformSpace.toTopologicalSpace _ u₁ ≤ @UniformSpace.toTopologicalSpace _ u₂ := le_of_nhds_le_nhds <| to_nhds_mono h theorem toTopologicalSpace_comap {f : α → β} {u : UniformSpace β} : @UniformSpace.toTopologicalSpace _ (UniformSpace.comap f u) = TopologicalSpace.induced f (@UniformSpace.toTopologicalSpace β u) := rfl lemma uniformSpace_eq_bot {u : UniformSpace α} : u = ⊥ ↔ idRel ∈ 𝓤[u] := le_bot_iff.symm.trans le_principal_iff protected lemma _root_.Filter.HasBasis.uniformSpace_eq_bot {ι p} {s : ι → Set (α × α)} {u : UniformSpace α} (h : 𝓤[u].HasBasis p s) : u = ⊥ ↔ ∃ i, p i ∧ Pairwise fun x y : α ↦ (x, y) ∉ s i := by simp [uniformSpace_eq_bot, h.mem_iff, subset_def, Pairwise, not_imp_not] theorem toTopologicalSpace_bot : @UniformSpace.toTopologicalSpace α ⊥ = ⊥ := rfl theorem toTopologicalSpace_top : @UniformSpace.toTopologicalSpace α ⊤ = ⊤ := rfl theorem toTopologicalSpace_iInf {ι : Sort*} {u : ι → UniformSpace α} : (iInf u).toTopologicalSpace = ⨅ i, (u i).toTopologicalSpace := TopologicalSpace.ext_nhds fun a ↦ by simp only [@nhds_eq_comap_uniformity _ (iInf u), nhds_iInf, iInf_uniformity, @nhds_eq_comap_uniformity _ (u _), Filter.comap_iInf] theorem toTopologicalSpace_sInf {s : Set (UniformSpace α)} : (sInf s).toTopologicalSpace = ⨅ i ∈ s, @UniformSpace.toTopologicalSpace α i := by rw [sInf_eq_iInf] simp only [← toTopologicalSpace_iInf] theorem toTopologicalSpace_inf {u v : UniformSpace α} : (u ⊓ v).toTopologicalSpace = u.toTopologicalSpace ⊓ v.toTopologicalSpace := rfl end UniformSpace theorem UniformContinuous.continuous [UniformSpace α] [UniformSpace β] {f : α → β} (hf : UniformContinuous f) : Continuous f := continuous_iff_le_induced.mpr <| UniformSpace.toTopologicalSpace_mono <| uniformContinuous_iff.1 hf /-- Uniform space structure on `ULift α`. -/ instance ULift.uniformSpace [UniformSpace α] : UniformSpace (ULift α) := UniformSpace.comap ULift.down ‹_› /-- Uniform space structure on `αᵒᵈ`. -/ instance OrderDual.instUniformSpace [UniformSpace α] : UniformSpace (αᵒᵈ) := ‹UniformSpace α› section UniformContinuousInfi -- TODO: add an `iff` lemma? theorem UniformContinuous.inf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ u₃ : UniformSpace β} (h₁ : UniformContinuous[u₁, u₂] f) (h₂ : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁, u₂ ⊓ u₃] f := tendsto_inf.mpr ⟨h₁, h₂⟩ theorem UniformContinuous.inf_dom_left {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_left hf theorem UniformContinuous.inf_dom_right {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₂, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_right hf theorem uniformContinuous_sInf_dom {f : α → β} {u₁ : Set (UniformSpace α)} {u₂ : UniformSpace β} {u : UniformSpace α} (h₁ : u ∈ u₁) (hf : UniformContinuous[u, u₂] f) : UniformContinuous[sInf u₁, u₂] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity] exact tendsto_iInf' ⟨u, h₁⟩ hf theorem uniformContinuous_sInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : Set (UniformSpace β)} : UniformContinuous[u₁, sInf u₂] f ↔ ∀ u ∈ u₂, UniformContinuous[u₁, u] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity, tendsto_iInf, SetCoe.forall] theorem uniformContinuous_iInf_dom {f : α → β} {u₁ : ι → UniformSpace α} {u₂ : UniformSpace β} {i : ι} (hf : UniformContinuous[u₁ i, u₂] f) : UniformContinuous[iInf u₁, u₂] f := by delta UniformContinuous rw [iInf_uniformity] exact tendsto_iInf' i hf theorem uniformContinuous_iInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : ι → UniformSpace β} : UniformContinuous[u₁, iInf u₂] f ↔ ∀ i, UniformContinuous[u₁, u₂ i] f := by delta UniformContinuous rw [iInf_uniformity, tendsto_iInf] end UniformContinuousInfi /-- A uniform space with the discrete uniformity has the discrete topology. -/ theorem discreteTopology_of_discrete_uniformity [hα : UniformSpace α] (h : uniformity α = 𝓟 idRel) : DiscreteTopology α := ⟨(UniformSpace.ext h.symm : ⊥ = hα) ▸ rfl⟩ instance : UniformSpace Empty := ⊥ instance : UniformSpace PUnit := ⊥ instance : UniformSpace Bool := ⊥ instance : UniformSpace ℕ := ⊥ instance : UniformSpace ℤ := ⊥ section variable [UniformSpace α] open Additive Multiplicative instance : UniformSpace (Additive α) := ‹UniformSpace α› instance : UniformSpace (Multiplicative α) := ‹UniformSpace α› theorem uniformContinuous_ofMul : UniformContinuous (ofMul : α → Additive α) := uniformContinuous_id theorem uniformContinuous_toMul : UniformContinuous (toMul : Additive α → α) := uniformContinuous_id theorem uniformContinuous_ofAdd : UniformContinuous (ofAdd : α → Multiplicative α) := uniformContinuous_id theorem uniformContinuous_toAdd : UniformContinuous (toAdd : Multiplicative α → α) := uniformContinuous_id theorem uniformity_additive : 𝓤 (Additive α) = (𝓤 α).map (Prod.map ofMul ofMul) := rfl theorem uniformity_multiplicative : 𝓤 (Multiplicative α) = (𝓤 α).map (Prod.map ofAdd ofAdd) := rfl end instance instUniformSpaceSubtype {p : α → Prop} [t : UniformSpace α] : UniformSpace (Subtype p) := UniformSpace.comap Subtype.val t theorem uniformity_subtype {p : α → Prop} [UniformSpace α] : 𝓤 (Subtype p) = comap (fun q : Subtype p × Subtype p => (q.1.1, q.2.1)) (𝓤 α) := rfl theorem uniformity_setCoe {s : Set α} [UniformSpace α] : 𝓤 s = comap (Prod.map ((↑) : s → α) ((↑) : s → α)) (𝓤 α) := rfl theorem map_uniformity_set_coe {s : Set α} [UniformSpace α] : map (Prod.map (↑) (↑)) (𝓤 s) = 𝓤 α ⊓ 𝓟 (s ×ˢ s) := by rw [uniformity_setCoe, map_comap, range_prodMap, Subtype.range_val] theorem uniformContinuous_subtype_val {p : α → Prop} [UniformSpace α] : UniformContinuous (Subtype.val : { a : α // p a } → α) := uniformContinuous_comap theorem UniformContinuous.subtype_mk {p : α → Prop} [UniformSpace α] [UniformSpace β] {f : β → α} (hf : UniformContinuous f) (h : ∀ x, p (f x)) : UniformContinuous (fun x => ⟨f x, h x⟩ : β → Subtype p) := uniformContinuous_comap' hf theorem uniformContinuousOn_iff_restrict [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ UniformContinuous (s.restrict f) := by delta UniformContinuousOn UniformContinuous rw [← map_uniformity_set_coe, tendsto_map'_iff]; rfl theorem tendsto_of_uniformContinuous_subtype [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} {a : α} (hf : UniformContinuous fun x : s => f x.val) (ha : s ∈ 𝓝 a) : Tendsto f (𝓝 a) (𝓝 (f a)) := by rw [(@map_nhds_subtype_coe_eq_nhds α _ s a (mem_of_mem_nhds ha) ha).symm] exact tendsto_map' hf.continuous.continuousAt theorem UniformContinuousOn.continuousOn [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} (h : UniformContinuousOn f s) : ContinuousOn f s := by rw [uniformContinuousOn_iff_restrict] at h rw [continuousOn_iff_continuous_restrict] exact h.continuous @[to_additive] instance [UniformSpace α] : UniformSpace αᵐᵒᵖ := UniformSpace.comap MulOpposite.unop ‹_› @[to_additive] theorem uniformity_mulOpposite [UniformSpace α] : 𝓤 αᵐᵒᵖ = comap (fun q : αᵐᵒᵖ × αᵐᵒᵖ => (q.1.unop, q.2.unop)) (𝓤 α) := rfl @[to_additive (attr := simp)] theorem comap_uniformity_mulOpposite [UniformSpace α] : comap (fun p : α × α => (MulOpposite.op p.1, MulOpposite.op p.2)) (𝓤 αᵐᵒᵖ) = 𝓤 α := by simpa [uniformity_mulOpposite, comap_comap, (· ∘ ·)] using comap_id namespace MulOpposite @[to_additive] theorem uniformContinuous_unop [UniformSpace α] : UniformContinuous (unop : αᵐᵒᵖ → α) := uniformContinuous_comap @[to_additive] theorem uniformContinuous_op [UniformSpace α] : UniformContinuous (op : α → αᵐᵒᵖ) := uniformContinuous_comap' uniformContinuous_id end MulOpposite section Prod open UniformSpace /- a similar product space is possible on the function space (uniformity of pointwise convergence), but we want to have the uniformity of uniform convergence on function spaces -/ instance instUniformSpaceProd [u₁ : UniformSpace α] [u₂ : UniformSpace β] : UniformSpace (α × β) := u₁.comap Prod.fst ⊓ u₂.comap Prod.snd -- check the above produces no diamond for `simp` and typeclass search example [UniformSpace α] [UniformSpace β] : (instTopologicalSpaceProd : TopologicalSpace (α × β)) = UniformSpace.toTopologicalSpace := by with_reducible_and_instances rfl theorem uniformity_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = ((𝓤 α).comap fun p : (α × β) × α × β => (p.1.1, p.2.1)) ⊓ (𝓤 β).comap fun p : (α × β) × α × β => (p.1.2, p.2.2) := rfl instance [UniformSpace α] [IsCountablyGenerated (𝓤 α)] [UniformSpace β] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (α × β)) := by rw [uniformity_prod] infer_instance theorem uniformity_prod_eq_comap_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = comap (fun p : (α × β) × α × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by simp_rw [uniformity_prod, prod_eq_inf, Filter.comap_inf, Filter.comap_comap, Function.comp_def] theorem uniformity_prod_eq_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = map (fun p : (α × α) × β × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by rw [map_swap4_eq_comap, uniformity_prod_eq_comap_prod] theorem mem_uniformity_of_uniformContinuous_invariant [UniformSpace α] [UniformSpace β] {s : Set (β × β)} {f : α → α → β} (hf : UniformContinuous fun p : α × α => f p.1 p.2) (hs : s ∈ 𝓤 β) : ∃ u ∈ 𝓤 α, ∀ a b c, (a, b) ∈ u → (f a c, f b c) ∈ s := by rw [UniformContinuous, uniformity_prod_eq_prod, tendsto_map'_iff] at hf rcases mem_prod_iff.1 (mem_map.1 <| hf hs) with ⟨u, hu, v, hv, huvt⟩ exact ⟨u, hu, fun a b c hab => @huvt ((_, _), (_, _)) ⟨hab, refl_mem_uniformity hv⟩⟩ /-- An entourage of the diagonal in `α` and an entourage in `β` yield an entourage in `α × β` once we permute coordinates. -/ def entourageProd (u : Set (α × α)) (v : Set (β × β)) : Set ((α × β) × α × β) := {((a₁, b₁),(a₂, b₂)) | (a₁, a₂) ∈ u ∧ (b₁, b₂) ∈ v} theorem mem_entourageProd {u : Set (α × α)} {v : Set (β × β)} {p : (α × β) × α × β} : p ∈ entourageProd u v ↔ (p.1.1, p.2.1) ∈ u ∧ (p.1.2, p.2.2) ∈ v := Iff.rfl theorem entourageProd_mem_uniformity [t₁ : UniformSpace α] [t₂ : UniformSpace β] {u : Set (α × α)} {v : Set (β × β)} (hu : u ∈ 𝓤 α) (hv : v ∈ 𝓤 β) : entourageProd u v ∈ 𝓤 (α × β) := by rw [uniformity_prod]; exact inter_mem_inf (preimage_mem_comap hu) (preimage_mem_comap hv) theorem ball_entourageProd (u : Set (α × α)) (v : Set (β × β)) (x : α × β) : ball x (entourageProd u v) = ball x.1 u ×ˢ ball x.2 v := by ext p; simp only [ball, entourageProd, Set.mem_setOf_eq, Set.mem_prod, Set.mem_preimage] lemma IsSymmetricRel.entourageProd {u : Set (α × α)} {v : Set (β × β)} (hu : IsSymmetricRel u) (hv : IsSymmetricRel v) : IsSymmetricRel (entourageProd u v) := Set.ext fun _ ↦ and_congr hu.mk_mem_comm hv.mk_mem_comm theorem Filter.HasBasis.uniformity_prod {ιa ιb : Type*} [UniformSpace α] [UniformSpace β] {pa : ιa → Prop} {pb : ιb → Prop} {sa : ιa → Set (α × α)} {sb : ιb → Set (β × β)} (ha : (𝓤 α).HasBasis pa sa) (hb : (𝓤 β).HasBasis pb sb) : (𝓤 (α × β)).HasBasis (fun i : ιa × ιb ↦ pa i.1 ∧ pb i.2) (fun i ↦ entourageProd (sa i.1) (sb i.2)) := (ha.comap _).inf (hb.comap _) theorem entourageProd_subset [UniformSpace α] [UniformSpace β] {s : Set ((α × β) × α × β)} (h : s ∈ 𝓤 (α × β)) : ∃ u ∈ 𝓤 α, ∃ v ∈ 𝓤 β, entourageProd u v ⊆ s := by rcases (((𝓤 α).basis_sets.uniformity_prod (𝓤 β).basis_sets).mem_iff' s).1 h with ⟨w, hw⟩ use w.1, hw.1.1, w.2, hw.1.2, hw.2 theorem tendsto_prod_uniformity_fst [UniformSpace α] [UniformSpace β] : Tendsto (fun p : (α × β) × α × β => (p.1.1, p.2.1)) (𝓤 (α × β)) (𝓤 α) := le_trans (map_mono inf_le_left) map_comap_le
theorem tendsto_prod_uniformity_snd [UniformSpace α] [UniformSpace β] : Tendsto (fun p : (α × β) × α × β => (p.1.2, p.2.2)) (𝓤 (α × β)) (𝓤 β) :=
Mathlib/Topology/UniformSpace/Basic.lean
721
723
/- 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 -/ import Mathlib.Data.Multiset.Bind /-! # Sections of a multiset -/ assert_not_exists Ring namespace Multiset variable {α : Type*} section Sections /-- The sections of a multiset of multisets `s` consists of all those multisets which can be put in bijection with `s`, so each element is a member of the corresponding multiset. -/ def Sections (s : Multiset (Multiset α)) : Multiset (Multiset α) := Multiset.recOn s {0} (fun s _ c => s.bind fun a => c.map (Multiset.cons a)) fun a₀ a₁ _ pi => by simp [map_bind, bind_bind a₀ a₁, cons_swap] @[simp] theorem sections_zero : Sections (0 : Multiset (Multiset α)) = {0} := rfl @[simp] theorem sections_cons (s : Multiset (Multiset α)) (m : Multiset α) : Sections (m ::ₘ s) = m.bind fun a => (Sections s).map (Multiset.cons a) := recOn_cons m s theorem coe_sections : ∀ l : List (List α), Sections (l.map fun l : List α => (l : Multiset α) : Multiset (Multiset α)) = (l.sections.map fun l : List α => (l : Multiset α) : Multiset (Multiset α)) | [] => rfl | a :: l => by simp only [List.map_cons, List.sections] rw [← cons_coe, sections_cons, bind_map_comm, coe_sections l] simp [List.sections, Function.comp_def, List.flatMap] @[simp] theorem sections_add (s t : Multiset (Multiset α)) : Sections (s + t) = (Sections s).bind fun m => (Sections t).map (m + ·) := Multiset.induction_on s (by simp) fun a s ih => by simp [ih, bind_assoc, map_bind, bind_map] theorem mem_sections {s : Multiset (Multiset α)} :
∀ {a}, a ∈ Sections s ↔ s.Rel (fun s a => a ∈ s) a := by induction s using Multiset.induction_on with | empty => simp | cons _ _ ih => simp [ih, rel_cons_left, eq_comm]
Mathlib/Data/Multiset/Sections.lean
54
57
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.MvPolynomial.Expand import Mathlib.FieldTheory.Finite.Basic import Mathlib.LinearAlgebra.Dual.Lemmas import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.RingTheory.MvPolynomial.Basic /-! ## Polynomials over finite fields -/ namespace MvPolynomial variable {σ : Type*} /-- A polynomial over the integers is divisible by `n : ℕ` if and only if it is zero over `ZMod n`. -/ theorem C_dvd_iff_zmod (n : ℕ) (φ : MvPolynomial σ ℤ) : C (n : ℤ) ∣ φ ↔ map (Int.castRingHom (ZMod n)) φ = 0 := C_dvd_iff_map_hom_eq_zero _ _ (CharP.intCast_eq_zero_iff (ZMod n) n) _ section frobenius variable {p : ℕ} [Fact p.Prime] theorem frobenius_zmod (f : MvPolynomial σ (ZMod p)) : frobenius _ p f = expand p f := by apply induction_on f · intro a; rw [expand_C, frobenius_def, ← C_pow, ZMod.pow_card] · simp only [map_add]; intro _ _ hf hg; rw [hf, hg] · simp only [expand_X, map_mul] intro _ _ hf; rw [hf, frobenius_def] theorem expand_zmod (f : MvPolynomial σ (ZMod p)) : expand p f = f ^ p := (frobenius_zmod _).symm end frobenius end MvPolynomial namespace MvPolynomial noncomputable section open Set LinearMap Submodule variable {K : Type*} {σ : Type*} section Indicator variable [Fintype K] [Fintype σ] /-- Over a field, this is the indicator function as an `MvPolynomial`. -/ def indicator [CommRing K] (a : σ → K) : MvPolynomial σ K := ∏ n, (1 - (X n - C (a n)) ^ (Fintype.card K - 1)) section CommRing variable [CommRing K] theorem eval_indicator_apply_eq_one (a : σ → K) : eval a (indicator a) = 1 := by nontriviality have : 0 < Fintype.card K - 1 := tsub_pos_of_lt Fintype.one_lt_card simp only [indicator, map_prod, map_sub, map_one, map_pow, eval_X, eval_C, sub_self, zero_pow this.ne', sub_zero, Finset.prod_const_one] theorem degrees_indicator (c : σ → K) : degrees (indicator c) ≤ ∑ s : σ, (Fintype.card K - 1) • {s} := by rw [indicator] classical refine degrees_prod_le.trans <| Finset.sum_le_sum fun s _ ↦ degrees_sub_le.trans ?_ rw [degrees_one, Multiset.zero_union] refine le_trans degrees_pow_le (nsmul_le_nsmul_right ?_ _) refine degrees_sub_le.trans ?_ rw [degrees_C, Multiset.union_zero] exact degrees_X' _ theorem indicator_mem_restrictDegree (c : σ → K) : indicator c ∈ restrictDegree σ K (Fintype.card K - 1) := by classical rw [mem_restrictDegree_iff_sup, indicator] intro n refine le_trans (Multiset.count_le_of_le _ <| degrees_indicator _) (le_of_eq ?_) simp_rw [← Multiset.coe_countAddMonoidHom, map_sum, AddMonoidHom.map_nsmul, Multiset.coe_countAddMonoidHom, nsmul_eq_mul, Nat.cast_id] trans
· refine Finset.sum_eq_single n ?_ ?_ · intro b _ ne simp [Multiset.count_singleton, ne, if_neg (Ne.symm _)] · intro h; exact (h <| Finset.mem_univ _).elim · rw [Multiset.count_singleton_self, mul_one] end CommRing variable [Field K] theorem eval_indicator_apply_eq_zero (a b : σ → K) (h : a ≠ b) : eval a (indicator b) = 0 := by obtain ⟨i, hi⟩ : ∃ i, a i ≠ b i := by rwa [Ne, funext_iff, not_forall] at h simp only [indicator, map_prod, map_sub, map_one, map_pow, eval_X, eval_C, sub_self,
Mathlib/FieldTheory/Finite/Polynomial.lean
91
103
/- Copyright (c) 2023 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Yaël Dillies, Jineon Baek -/ import Mathlib.Algebra.EuclideanDomain.Int import Mathlib.Algebra.GCDMonoid.Finset import Mathlib.Algebra.GCDMonoid.Nat import Mathlib.Algebra.Order.Ring.Abs import Mathlib.RingTheory.PrincipalIdealDomain /-! # Statement of Fermat's Last Theorem This file states Fermat's Last Theorem. We provide a statement over a general semiring with specific exponent, along with the usual statement over the naturals. ## Main definitions * `FermatLastTheoremWith R n`: The statement that only solutions to the Fermat equation `a^n + b^n = c^n` in the semiring `R` have `a = 0`, `b = 0` or `c = 0`. Note that this statement can certainly be false for certain values of `R` and `n`. For example `FermatLastTheoremWith ℝ 3` is false as `1^3 + 1^3 = (2^{1/3})^3`, and `FermatLastTheoremWith ℕ 2` is false, as 3^2 + 4^2 = 5^2. * `FermatLastTheoremFor n` : The statement that the only solutions to `a^n + b^n = c^n` in `ℕ` have `a = 0`, `b = 0` or `c = 0`. Again, this statement is not always true, for example `FermatLastTheoremFor 1` is false because `2^1 + 2^1 = 4^1`. * `FermatLastTheorem` : The statement of Fermat's Last Theorem, namely that the only solutions to `a^n + b^n = c^n` in `ℕ` when `n ≥ 3` have `a = 0`, `b = 0` or `c = 0`. ## History Fermat's Last Theorem was an open problem in number theory for hundreds of years, until it was finally solved by Andrew Wiles, assisted by Richard Taylor, in 1994 (see [A. Wiles, *Modular elliptic curves and Fermat's last theorem*][Wiles-FLT] and [R. Taylor and A. Wiles, *Ring-theoretic properties of certain Hecke algebras*][Taylor-Wiles-FLT]). An ongoing Lean formalisation of the proof, using mathlib as a dependency, is taking place at https://github.com/ImperialCollegeLondon/FLT . -/ open List
/-- Statement of Fermat's Last Theorem over a given semiring with a specific exponent. -/ def FermatLastTheoremWith (R : Type*) [Semiring R] (n : ℕ) : Prop := ∀ a b c : R, a ≠ 0 → b ≠ 0 → c ≠ 0 → a ^ n + b ^ n ≠ c ^ n /-- Statement of Fermat's Last Theorem over the naturals for a given exponent. -/ def FermatLastTheoremFor (n : ℕ) : Prop := FermatLastTheoremWith ℕ n
Mathlib/NumberTheory/FLT/Basic.lean
47
52
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl -/ import Mathlib.Algebra.Order.Monoid.Unbundled.Basic /-! # Lemmas about `min` and `max` in an ordered monoid. -/ open Function variable {α β : Type*} /-! Some lemmas about types that have an ordering and a binary operation, with no rules relating them. -/ section CommSemigroup variable [LinearOrder α] [CommSemigroup β] @[to_additive] lemma fn_min_mul_fn_max (f : α → β) (a b : α) : f (min a b) * f (max a b) = f a * f b := by obtain h | h := le_total a b <;> simp [h, mul_comm] @[to_additive] lemma fn_max_mul_fn_min (f : α → β) (a b : α) : f (max a b) * f (min a b) = f a * f b := by obtain h | h := le_total a b <;> simp [h, mul_comm] variable [CommSemigroup α] @[to_additive (attr := simp)] lemma min_mul_max (a b : α) : min a b * max a b = a * b := fn_min_mul_fn_max id _ _ @[to_additive (attr := simp)] lemma max_mul_min (a b : α) : max a b * min a b = a * b := fn_max_mul_fn_min id _ _ end CommSemigroup section CovariantClassMulLe variable [LinearOrder α] section Mul variable [Mul α] section Left variable [MulLeftMono α] @[to_additive] theorem min_mul_mul_left (a b c : α) : min (a * b) (a * c) = a * min b c := (monotone_id.const_mul' a).map_min.symm @[to_additive] theorem max_mul_mul_left (a b c : α) : max (a * b) (a * c) = a * max b c := (monotone_id.const_mul' a).map_max.symm end Left section Right variable [MulRightMono α] @[to_additive] theorem min_mul_mul_right (a b c : α) : min (a * c) (b * c) = min a b * c := (monotone_id.mul_const' c).map_min.symm @[to_additive] theorem max_mul_mul_right (a b c : α) : max (a * c) (b * c) = max a b * c := (monotone_id.mul_const' c).map_max.symm end Right @[to_additive] theorem lt_or_lt_of_mul_lt_mul [MulLeftMono α] [MulRightMono α] {a₁ a₂ b₁ b₂ : α} : a₁ * b₁ < a₂ * b₂ → a₁ < a₂ ∨ b₁ < b₂ := by contrapose! exact fun h => mul_le_mul' h.1 h.2 @[to_additive] theorem le_or_lt_of_mul_le_mul [MulLeftMono α] [MulRightStrictMono α] {a₁ a₂ b₁ b₂ : α} : a₁ * b₁ ≤ a₂ * b₂ → a₁ ≤ a₂ ∨ b₁ < b₂ := by contrapose! exact fun h => mul_lt_mul_of_lt_of_le h.1 h.2 @[to_additive] theorem lt_or_le_of_mul_le_mul [MulLeftStrictMono α] [MulRightMono α] {a₁ a₂ b₁ b₂ : α} : a₁ * b₁ ≤ a₂ * b₂ → a₁ < a₂ ∨ b₁ ≤ b₂ := by contrapose! exact fun h => mul_lt_mul_of_le_of_lt h.1 h.2 @[to_additive] theorem le_or_le_of_mul_le_mul [MulLeftStrictMono α] [MulRightStrictMono α] {a₁ a₂ b₁ b₂ : α} : a₁ * b₁ ≤ a₂ * b₂ → a₁ ≤ a₂ ∨ b₁ ≤ b₂ := by contrapose! exact fun h => mul_lt_mul_of_lt_of_lt h.1 h.2 @[to_additive] theorem mul_lt_mul_iff_of_le_of_le [MulLeftMono α] [MulRightMono α] [MulLeftStrictMono α] [MulRightStrictMono α] {a₁ a₂ b₁ b₂ : α} (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) : a₁ * b₁ < a₂ * b₂ ↔ a₁ < a₂ ∨ b₁ < b₂ := by refine ⟨lt_or_lt_of_mul_lt_mul, fun h => ?_⟩ rcases h with ha' | hb' · exact mul_lt_mul_of_lt_of_le ha' hb · exact mul_lt_mul_of_le_of_lt ha hb' end Mul variable [MulOneClass α] @[to_additive] theorem min_le_mul_of_one_le_right [MulLeftMono α] {a b : α} (hb : 1 ≤ b) :
min a b ≤ a * b := min_le_iff.2 <| Or.inl <| le_mul_of_one_le_right' hb @[to_additive] theorem min_le_mul_of_one_le_left [MulRightMono α] {a b : α} (ha : 1 ≤ a) :
Mathlib/Algebra/Order/Monoid/Unbundled/MinMax.lean
117
121
/- Copyright (c) 2020 Kenji Nakagawa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenji Nakagawa, Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.Algebra.Algebra.Subalgebra.Pointwise import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.RingTheory.Spectrum.Maximal.Localization import Mathlib.RingTheory.ChainOfDivisors import Mathlib.RingTheory.DedekindDomain.Basic import Mathlib.RingTheory.FractionalIdeal.Operations import Mathlib.Algebra.Squarefree.Basic /-! # Dedekind domains and ideals In this file, we show a ring is a Dedekind domain iff all fractional ideals are invertible. Then we prove some results on the unique factorization monoid structure of the ideals. ## Main definitions - `IsDedekindDomainInv` alternatively defines a Dedekind domain as an integral domain where every nonzero fractional ideal is invertible. - `isDedekindDomainInv_iff` shows that this does note depend on the choice of field of fractions. - `IsDedekindDomain.HeightOneSpectrum` defines the type of nonzero prime ideals of `R`. ## Main results: - `isDedekindDomain_iff_isDedekindDomainInv` - `Ideal.uniqueFactorizationMonoid` ## Implementation notes The definitions that involve a field of fractions choose a canonical field of fractions, but are independent of that choice. The `..._iff` lemmas express this independence. Often, definitions assume that Dedekind domains are not fields. We found it more practical to add a `(h : ¬ IsField A)` assumption whenever this is explicitly needed. ## References * [D. Marcus, *Number Fields*][marcus1977number] * [J.W.S. Cassels, A. Fröhlich, *Algebraic Number Theory*][cassels1967algebraic] * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags dedekind domain, dedekind ring -/ variable (R A K : Type*) [CommRing R] [CommRing A] [Field K] open scoped nonZeroDivisors Polynomial section Inverse namespace FractionalIdeal variable {R₁ : Type*} [CommRing R₁] [IsDomain R₁] [Algebra R₁ K] [IsFractionRing R₁ K] variable {I J : FractionalIdeal R₁⁰ K} noncomputable instance : Inv (FractionalIdeal R₁⁰ K) := ⟨fun I => 1 / I⟩ theorem inv_eq : I⁻¹ = 1 / I := rfl theorem inv_zero' : (0 : FractionalIdeal R₁⁰ K)⁻¹ = 0 := div_zero theorem inv_nonzero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : J⁻¹ = ⟨(1 : FractionalIdeal R₁⁰ K) / J, fractional_div_of_nonzero h⟩ := div_nonzero h theorem coe_inv_of_nonzero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : (↑J⁻¹ : Submodule R₁ K) = IsLocalization.coeSubmodule K ⊤ / (J : Submodule R₁ K) := by simp_rw [inv_nonzero _ h, coe_one, coe_mk, IsLocalization.coeSubmodule_top] variable {K} theorem mem_inv_iff (hI : I ≠ 0) {x : K} : x ∈ I⁻¹ ↔ ∀ y ∈ I, x * y ∈ (1 : FractionalIdeal R₁⁰ K) := mem_div_iff_of_nonzero hI theorem inv_anti_mono (hI : I ≠ 0) (hJ : J ≠ 0) (hIJ : I ≤ J) : J⁻¹ ≤ I⁻¹ := by -- Porting note: in Lean3, introducing `x` would just give `x ∈ J⁻¹ → x ∈ I⁻¹`, but -- in Lean4, it goes all the way down to the subtypes intro x simp only [val_eq_coe, mem_coe, mem_inv_iff hJ, mem_inv_iff hI] exact fun h y hy => h y (hIJ hy) theorem le_self_mul_inv {I : FractionalIdeal R₁⁰ K} (hI : I ≤ (1 : FractionalIdeal R₁⁰ K)) : I ≤ I * I⁻¹ := le_self_mul_one_div hI variable (K) theorem coe_ideal_le_self_mul_inv (I : Ideal R₁) : (I : FractionalIdeal R₁⁰ K) ≤ I * (I : FractionalIdeal R₁⁰ K)⁻¹ := le_self_mul_inv coeIdeal_le_one /-- `I⁻¹` is the inverse of `I` if `I` has an inverse. -/ theorem right_inverse_eq (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : J = I⁻¹ := by have hI : I ≠ 0 := ne_zero_of_mul_eq_one I J h suffices h' : I * (1 / I) = 1 from congr_arg Units.inv <| @Units.ext _ _ (Units.mkOfMulEqOne _ _ h) (Units.mkOfMulEqOne _ _ h') rfl apply le_antisymm · apply mul_le.mpr _ intro x hx y hy rw [mul_comm] exact (mem_div_iff_of_nonzero hI).mp hy x hx rw [← h] apply mul_left_mono I apply (le_div_iff_of_nonzero hI).mpr _ intro y hy x hx rw [mul_comm] exact mul_mem_mul hy hx theorem mul_inv_cancel_iff {I : FractionalIdeal R₁⁰ K} : I * I⁻¹ = 1 ↔ ∃ J, I * J = 1 := ⟨fun h => ⟨I⁻¹, h⟩, fun ⟨J, hJ⟩ => by rwa [← right_inverse_eq K I J hJ]⟩ theorem mul_inv_cancel_iff_isUnit {I : FractionalIdeal R₁⁰ K} : I * I⁻¹ = 1 ↔ IsUnit I := (mul_inv_cancel_iff K).trans isUnit_iff_exists_inv.symm variable {K' : Type*} [Field K'] [Algebra R₁ K'] [IsFractionRing R₁ K'] @[simp] protected theorem map_inv (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : I⁻¹.map (h : K →ₐ[R₁] K') = (I.map h)⁻¹ := by rw [inv_eq, FractionalIdeal.map_div, FractionalIdeal.map_one, inv_eq] open Submodule Submodule.IsPrincipal @[simp] theorem spanSingleton_inv (x : K) : (spanSingleton R₁⁰ x)⁻¹ = spanSingleton _ x⁻¹ := one_div_spanSingleton x theorem spanSingleton_div_spanSingleton (x y : K) : spanSingleton R₁⁰ x / spanSingleton R₁⁰ y = spanSingleton R₁⁰ (x / y) := by rw [div_spanSingleton, mul_comm, spanSingleton_mul_spanSingleton, div_eq_mul_inv] theorem spanSingleton_div_self {x : K} (hx : x ≠ 0) : spanSingleton R₁⁰ x / spanSingleton R₁⁰ x = 1 := by rw [spanSingleton_div_spanSingleton, div_self hx, spanSingleton_one] theorem coe_ideal_span_singleton_div_self {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K) / Ideal.span ({x} : Set R₁) = 1 := by rw [coeIdeal_span_singleton, spanSingleton_div_self K <| (map_ne_zero_iff _ <| FaithfulSMul.algebraMap_injective R₁ K).mpr hx] theorem spanSingleton_mul_inv {x : K} (hx : x ≠ 0) : spanSingleton R₁⁰ x * (spanSingleton R₁⁰ x)⁻¹ = 1 := by rw [spanSingleton_inv, spanSingleton_mul_spanSingleton, mul_inv_cancel₀ hx, spanSingleton_one] theorem coe_ideal_span_singleton_mul_inv {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K) * (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K)⁻¹ = 1 := by rw [coeIdeal_span_singleton, spanSingleton_mul_inv K <| (map_ne_zero_iff _ <| FaithfulSMul.algebraMap_injective R₁ K).mpr hx] theorem spanSingleton_inv_mul {x : K} (hx : x ≠ 0) : (spanSingleton R₁⁰ x)⁻¹ * spanSingleton R₁⁰ x = 1 := by rw [mul_comm, spanSingleton_mul_inv K hx] theorem coe_ideal_span_singleton_inv_mul {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K)⁻¹ * Ideal.span ({x} : Set R₁) = 1 := by rw [mul_comm, coe_ideal_span_singleton_mul_inv K hx] theorem mul_generator_self_inv {R₁ : Type*} [CommRing R₁] [Algebra R₁ K] [IsLocalization R₁⁰ K] (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : I * spanSingleton _ (generator (I : Submodule R₁ K))⁻¹ = 1 := by -- Rewrite only the `I` that appears alone. conv_lhs => congr; rw [eq_spanSingleton_of_principal I] rw [spanSingleton_mul_spanSingleton, mul_inv_cancel₀, spanSingleton_one] intro generator_I_eq_zero apply h rw [eq_spanSingleton_of_principal I, generator_I_eq_zero, spanSingleton_zero] theorem invertible_of_principal (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : I * I⁻¹ = 1 := mul_div_self_cancel_iff.mpr ⟨spanSingleton _ (generator (I : Submodule R₁ K))⁻¹, mul_generator_self_inv _ I h⟩ theorem invertible_iff_generator_nonzero (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] : I * I⁻¹ = 1 ↔ generator (I : Submodule R₁ K) ≠ 0 := by constructor · intro hI hg apply ne_zero_of_mul_eq_one _ _ hI rw [eq_spanSingleton_of_principal I, hg, spanSingleton_zero] · intro hg apply invertible_of_principal rw [eq_spanSingleton_of_principal I] intro hI have := mem_spanSingleton_self R₁⁰ (generator (I : Submodule R₁ K)) rw [hI, mem_zero_iff] at this contradiction theorem isPrincipal_inv (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : Submodule.IsPrincipal I⁻¹.1 := by rw [val_eq_coe, isPrincipal_iff] use (generator (I : Submodule R₁ K))⁻¹ have hI : I * spanSingleton _ (generator (I : Submodule R₁ K))⁻¹ = 1 := mul_generator_self_inv _ I h exact (right_inverse_eq _ I (spanSingleton _ (generator (I : Submodule R₁ K))⁻¹) hI).symm variable {K} lemma den_mem_inv {I : FractionalIdeal R₁⁰ K} (hI : I ≠ ⊥) : (algebraMap R₁ K) (I.den : R₁) ∈ I⁻¹ := by rw [mem_inv_iff hI] intro i hi rw [← Algebra.smul_def (I.den : R₁) i, ← mem_coe, coe_one] suffices Submodule.map (Algebra.linearMap R₁ K) I.num ≤ 1 from this <| (den_mul_self_eq_num I).symm ▸ smul_mem_pointwise_smul i I.den I.coeToSubmodule hi apply le_trans <| map_mono (show I.num ≤ 1 by simp only [Ideal.one_eq_top, le_top, bot_eq_zero]) rw [Ideal.one_eq_top, Submodule.map_top, one_eq_range] lemma num_le_mul_inv (I : FractionalIdeal R₁⁰ K) : I.num ≤ I * I⁻¹ := by by_cases hI : I = 0 · rw [hI, num_zero_eq <| FaithfulSMul.algebraMap_injective R₁ K, zero_mul, zero_eq_bot, coeIdeal_bot]
· rw [mul_comm, ← den_mul_self_eq_num'] exact mul_right_mono I <| spanSingleton_le_iff_mem.2 (den_mem_inv hI) lemma bot_lt_mul_inv {I : FractionalIdeal R₁⁰ K} (hI : I ≠ ⊥) : ⊥ < I * I⁻¹ := lt_of_lt_of_le (coeIdeal_ne_zero.2 (hI ∘ num_eq_zero_iff.1)).bot_lt I.num_le_mul_inv noncomputable instance : InvOneClass (FractionalIdeal R₁⁰ K) := { inv_one := div_one }
Mathlib/RingTheory/DedekindDomain/Ideal.lean
221
227
/- 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.Ordering.Basic import Mathlib.Order.Synonym /-! # Comparison This file provides basic results about orderings and comparison in linear orders. ## Definitions * `CmpLE`: An `Ordering` from `≤`. * `Ordering.Compares`: Turns an `Ordering` into `<` and `=` propositions. * `linearOrderOfCompares`: Constructs a `LinearOrder` instance from the fact that any two elements that are not one strictly less than the other either way are equal. -/ variable {α β : Type*} /-- Like `cmp`, but uses a `≤` on the type instead of `<`. Given two elements `x` and `y`, returns a three-way comparison result `Ordering`. -/ def cmpLE {α} [LE α] [DecidableLE α] (x y : α) : Ordering := if x ≤ y then if y ≤ x then Ordering.eq else Ordering.lt else Ordering.gt theorem cmpLE_swap {α} [LE α] [IsTotal α (· ≤ ·)] [DecidableLE α] (x y : α) : (cmpLE x y).swap = cmpLE y x := by by_cases xy : x ≤ y <;> by_cases yx : y ≤ x <;> simp [cmpLE, *, Ordering.swap] cases not_or_intro xy yx (total_of _ _ _) theorem cmpLE_eq_cmp {α} [Preorder α] [IsTotal α (· ≤ ·)] [DecidableLE α] [DecidableLT α] (x y : α) : cmpLE x y = cmp x y := by by_cases xy : x ≤ y <;> by_cases yx : y ≤ x <;> simp [cmpLE, lt_iff_le_not_le, *, cmp, cmpUsing] cases not_or_intro xy yx (total_of _ _ _) namespace Ordering theorem compares_swap [LT α] {a b : α} {o : Ordering} : o.swap.Compares a b ↔ o.Compares b a := by cases o · exact Iff.rfl · exact eq_comm · exact Iff.rfl alias ⟨Compares.of_swap, Compares.swap⟩ := compares_swap theorem swap_eq_iff_eq_swap {o o' : Ordering} : o.swap = o' ↔ o = o'.swap := by rw [← swap_inj, swap_swap] theorem Compares.eq_lt [Preorder α] : ∀ {o} {a b : α}, Compares o a b → (o = lt ↔ a < b) | lt, _, _, h => ⟨fun _ => h, fun _ => rfl⟩ | eq, a, b, h => ⟨fun h => by injection h, fun h' => (ne_of_lt h' h).elim⟩ | gt, a, b, h => ⟨fun h => by injection h, fun h' => (lt_asymm h h').elim⟩ theorem Compares.ne_lt [Preorder α] : ∀ {o} {a b : α}, Compares o a b → (o ≠ lt ↔ b ≤ a) | lt, _, _, h => ⟨absurd rfl, fun h' => (not_le_of_lt h h').elim⟩ | eq, _, _, h => ⟨fun _ => ge_of_eq h, fun _ h => by injection h⟩ | gt, _, _, h => ⟨fun _ => le_of_lt h, fun _ h => by injection h⟩ theorem Compares.eq_eq [Preorder α] : ∀ {o} {a b : α}, Compares o a b → (o = eq ↔ a = b) | lt, a, b, h => ⟨fun h => by injection h, fun h' => (ne_of_lt h h').elim⟩ | eq, _, _, h => ⟨fun _ => h, fun _ => rfl⟩ | gt, a, b, h => ⟨fun h => by injection h, fun h' => (ne_of_gt h h').elim⟩ theorem Compares.eq_gt [Preorder α] {o} {a b : α} (h : Compares o a b) : o = gt ↔ b < a := swap_eq_iff_eq_swap.symm.trans h.swap.eq_lt theorem Compares.ne_gt [Preorder α] {o} {a b : α} (h : Compares o a b) : o ≠ gt ↔ a ≤ b := (not_congr swap_eq_iff_eq_swap.symm).trans h.swap.ne_lt theorem Compares.le_total [Preorder α] {a b : α} : ∀ {o}, Compares o a b → a ≤ b ∨ b ≤ a | lt, h => Or.inl (le_of_lt h) | eq, h => Or.inl (le_of_eq h) | gt, h => Or.inr (le_of_lt h) theorem Compares.le_antisymm [Preorder α] {a b : α} : ∀ {o}, Compares o a b → a ≤ b → b ≤ a → a = b | lt, h, _, hba => (not_le_of_lt h hba).elim | eq, h, _, _ => h | gt, h, hab, _ => (not_le_of_lt h hab).elim theorem Compares.inj [Preorder α] {o₁} : ∀ {o₂} {a b : α}, Compares o₁ a b → Compares o₂ a b → o₁ = o₂ | lt, _, _, h₁, h₂ => h₁.eq_lt.2 h₂ | eq, _, _, h₁, h₂ => h₁.eq_eq.2 h₂ | gt, _, _, h₁, h₂ => h₁.eq_gt.2 h₂ theorem compares_iff_of_compares_impl [LinearOrder α] [Preorder β] {a b : α} {a' b' : β} (h : ∀ {o}, Compares o a b → Compares o a' b') (o) : Compares o a b ↔ Compares o a' b' := by refine ⟨h, fun ho => ?_⟩ rcases lt_trichotomy a b with hab | hab | hab · have hab : Compares Ordering.lt a b := hab rwa [ho.inj (h hab)] · have hab : Compares Ordering.eq a b := hab rwa [ho.inj (h hab)] · have hab : Compares Ordering.gt a b := hab rwa [ho.inj (h hab)] end Ordering open Ordering OrderDual @[simp] theorem toDual_compares_toDual [LT α] {a b : α} {o : Ordering} : Compares o (toDual a) (toDual b) ↔ Compares o b a := by cases o exacts [Iff.rfl, eq_comm, Iff.rfl] @[simp] theorem ofDual_compares_ofDual [LT α] {a b : αᵒᵈ} {o : Ordering} : Compares o (ofDual a) (ofDual b) ↔ Compares o b a := by cases o exacts [Iff.rfl, eq_comm, Iff.rfl] theorem cmp_compares [LinearOrder α] (a b : α) : (cmp a b).Compares a b := by obtain h | h | h := lt_trichotomy a b <;> simp [cmp, cmpUsing, h, h.not_lt] theorem Ordering.Compares.cmp_eq [LinearOrder α] {a b : α} {o : Ordering} (h : o.Compares a b) : cmp a b = o := (cmp_compares a b).inj h @[simp] theorem cmp_swap [Preorder α] [DecidableLT α] (a b : α) : (cmp a b).swap = cmp b a := by unfold cmp cmpUsing by_cases h : a < b <;> by_cases h₂ : b < a <;> simp [h, h₂, Ordering.swap] exact lt_asymm h h₂ @[simp] theorem cmpLE_toDual [LE α] [DecidableLE α] (x y : α) : cmpLE (toDual x) (toDual y) = cmpLE y x := rfl @[simp] theorem cmpLE_ofDual [LE α] [DecidableLE α] (x y : αᵒᵈ) : cmpLE (ofDual x) (ofDual y) = cmpLE y x := rfl @[simp] theorem cmp_toDual [LT α] [DecidableLT α] (x y : α) : cmp (toDual x) (toDual y) = cmp y x :=
rfl
Mathlib/Order/Compare.lean
141
142
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Geometry.Euclidean.Altitude import Mathlib.Geometry.Euclidean.Circumcenter /-! # Monge point and orthocenter This file defines the orthocenter of a triangle, via its n-dimensional generalization, the Monge point of a simplex. ## Main definitions * `mongePoint` is the Monge point of a simplex, defined in terms of its position on the Euler line and then shown to be the point of concurrence of the Monge planes. * `mongePlane` is a Monge plane of an (n+2)-simplex, which is the (n+1)-dimensional affine subspace of the subspace spanned by the simplex that passes through the centroid of an n-dimensional face and is orthogonal to the opposite edge (in 2 dimensions, this is the same as an altitude). * `orthocenter` is defined, for the case of a triangle, to be the same as its Monge point, then shown to be the point of concurrence of the altitudes. * `OrthocentricSystem` is a predicate on sets of points that says whether they are four points, one of which is the orthocenter of the other three (in which case various other properties hold, including that each is the orthocenter of the other three). ## References * <https://en.wikipedia.org/wiki/Monge_point> * <https://en.wikipedia.org/wiki/Orthocentric_system> * Małgorzata Buba-Brzozowa, [The Monge Point and the 3(n+1) Point Sphere of an n-Simplex](https://pdfs.semanticscholar.org/6f8b/0f623459c76dac2e49255737f8f0f4725d16.pdf) -/ noncomputable section open scoped RealInnerProductSpace namespace Affine namespace Simplex open Finset AffineSubspace EuclideanGeometry PointsWithCircumcenterIndex variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The Monge point of a simplex (in 2 or more dimensions) is a generalization of the orthocenter of a triangle. It is defined to be the intersection of the Monge planes, where a Monge plane is the (n-1)-dimensional affine subspace of the subspace spanned by the simplex that passes through the centroid of an (n-2)-dimensional face and is orthogonal to the opposite edge (in 2 dimensions, this is the same as an altitude). The circumcenter O, centroid G and Monge point M are collinear in that order on the Euler line, with OG : GM = (n-1): 2. Here, we use that ratio to define the Monge point (so resulting in a point that equals the centroid in 0 or 1 dimensions), and then show in subsequent lemmas that the point so defined lies in the Monge planes and is their unique point of intersection. -/ def mongePoint {n : ℕ} (s : Simplex ℝ P n) : P := (((n + 1 : ℕ) : ℝ) / ((n - 1 : ℕ) : ℝ)) • ((univ : Finset (Fin (n + 1))).centroid ℝ s.points -ᵥ s.circumcenter) +ᵥ s.circumcenter /-- The position of the Monge point in relation to the circumcenter and centroid. -/ theorem mongePoint_eq_smul_vsub_vadd_circumcenter {n : ℕ} (s : Simplex ℝ P n) : s.mongePoint = (((n + 1 : ℕ) : ℝ) / ((n - 1 : ℕ) : ℝ)) • ((univ : Finset (Fin (n + 1))).centroid ℝ s.points -ᵥ s.circumcenter) +ᵥ s.circumcenter := rfl /-- The Monge point lies in the affine span. -/ theorem mongePoint_mem_affineSpan {n : ℕ} (s : Simplex ℝ P n) : s.mongePoint ∈ affineSpan ℝ (Set.range s.points) := smul_vsub_vadd_mem _ _ (centroid_mem_affineSpan_of_card_eq_add_one ℝ _ (card_fin (n + 1))) s.circumcenter_mem_affineSpan s.circumcenter_mem_affineSpan /-- Two simplices with the same points have the same Monge point. -/ theorem mongePoint_eq_of_range_eq {n : ℕ} {s₁ s₂ : Simplex ℝ P n} (h : Set.range s₁.points = Set.range s₂.points) : s₁.mongePoint = s₂.mongePoint := by simp_rw [mongePoint_eq_smul_vsub_vadd_circumcenter, centroid_eq_of_range_eq h, circumcenter_eq_of_range_eq h] /-- The weights for the Monge point of an (n+2)-simplex, in terms of `pointsWithCircumcenter`. -/ def mongePointWeightsWithCircumcenter (n : ℕ) : PointsWithCircumcenterIndex (n + 2) → ℝ | pointIndex _ => ((n + 1 : ℕ) : ℝ)⁻¹ | circumcenterIndex => -2 / ((n + 1 : ℕ) : ℝ) /-- `mongePointWeightsWithCircumcenter` sums to 1. -/ @[simp] theorem sum_mongePointWeightsWithCircumcenter (n : ℕ) : ∑ i, mongePointWeightsWithCircumcenter n i = 1 := by simp_rw [sum_pointsWithCircumcenter, mongePointWeightsWithCircumcenter, sum_const, card_fin, nsmul_eq_mul] field_simp ring /-- The Monge point of an (n+2)-simplex, in terms of `pointsWithCircumcenter`. -/ theorem mongePoint_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P (n + 2)) : s.mongePoint = (univ : Finset (PointsWithCircumcenterIndex (n + 2))).affineCombination ℝ s.pointsWithCircumcenter (mongePointWeightsWithCircumcenter n) := by rw [mongePoint_eq_smul_vsub_vadd_circumcenter, centroid_eq_affineCombination_of_pointsWithCircumcenter, circumcenter_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub, ← LinearMap.map_smul, weightedVSub_vadd_affineCombination] congr with i rw [Pi.add_apply, Pi.smul_apply, smul_eq_mul, Pi.sub_apply] -- Porting note: replaced -- have hn1 : (n + 1 : ℝ) ≠ 0 := mod_cast Nat.succ_ne_zero _ have hn1 : (n + 1 : ℝ) ≠ 0 := n.cast_add_one_ne_zero cases i <;> simp_rw [centroidWeightsWithCircumcenter, circumcenterWeightsWithCircumcenter, mongePointWeightsWithCircumcenter] <;> rw [add_tsub_assoc_of_le (by decide : 1 ≤ 2), (by decide : 2 - 1 = 1)] · rw [if_pos (mem_univ _), sub_zero, add_zero, card_fin] -- Porting note: replaced -- have hn3 : (n + 2 + 1 : ℝ) ≠ 0 := mod_cast Nat.succ_ne_zero _ have hn3 : (n + 2 + 1 : ℝ) ≠ 0 := by norm_cast field_simp [hn1, hn3, mul_comm] · field_simp [hn1] ring /-- The weights for the Monge point of an (n+2)-simplex, minus the centroid of an n-dimensional face, in terms of `pointsWithCircumcenter`. This definition is only valid when `i₁ ≠ i₂`. -/ def mongePointVSubFaceCentroidWeightsWithCircumcenter {n : ℕ} (i₁ i₂ : Fin (n + 3)) : PointsWithCircumcenterIndex (n + 2) → ℝ | pointIndex i => if i = i₁ ∨ i = i₂ then ((n + 1 : ℕ) : ℝ)⁻¹ else 0 | circumcenterIndex => -2 / ((n + 1 : ℕ) : ℝ) /-- `mongePointVSubFaceCentroidWeightsWithCircumcenter` is the result of subtracting `centroidWeightsWithCircumcenter` from `mongePointWeightsWithCircumcenter`. -/ theorem mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub {n : ℕ} {i₁ i₂ : Fin (n + 3)} (h : i₁ ≠ i₂) : mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂ = mongePointWeightsWithCircumcenter n - centroidWeightsWithCircumcenter {i₁, i₂}ᶜ := by ext i obtain i | i := i · rw [Pi.sub_apply, mongePointWeightsWithCircumcenter, centroidWeightsWithCircumcenter, mongePointVSubFaceCentroidWeightsWithCircumcenter] have hu : #{i₁, i₂}ᶜ = n + 1 := by simp [card_compl, Fintype.card_fin, h] rw [hu] by_cases hi : i = i₁ ∨ i = i₂ <;> simp [compl_eq_univ_sdiff, hi] · simp [mongePointWeightsWithCircumcenter, centroidWeightsWithCircumcenter, mongePointVSubFaceCentroidWeightsWithCircumcenter] /-- `mongePointVSubFaceCentroidWeightsWithCircumcenter` sums to 0. -/ @[simp] theorem sum_mongePointVSubFaceCentroidWeightsWithCircumcenter {n : ℕ} {i₁ i₂ : Fin (n + 3)} (h : i₁ ≠ i₂) : ∑ i, mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂ i = 0 := by rw [mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub h] simp_rw [Pi.sub_apply, sum_sub_distrib, sum_mongePointWeightsWithCircumcenter] rw [sum_centroidWeightsWithCircumcenter, sub_self] simp [← card_pos, card_compl, h] /-- The Monge point of an (n+2)-simplex, minus the centroid of an n-dimensional face, in terms of `pointsWithCircumcenter`. -/ theorem mongePoint_vsub_face_centroid_eq_weightedVSub_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} (h : i₁ ≠ i₂) : s.mongePoint -ᵥ ({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points = (univ : Finset (PointsWithCircumcenterIndex (n + 2))).weightedVSub s.pointsWithCircumcenter (mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂) := by simp_rw [mongePoint_eq_affineCombination_of_pointsWithCircumcenter, centroid_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub, mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub h] /-- The Monge point of an (n+2)-simplex, minus the centroid of an n-dimensional face, is orthogonal to the difference of the two vertices not in that face. -/ theorem inner_mongePoint_vsub_face_centroid_vsub {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} : ⟪s.mongePoint -ᵥ ({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points, s.points i₁ -ᵥ s.points i₂⟫ = 0 := by by_cases h : i₁ = i₂ · simp [h] simp_rw [mongePoint_vsub_face_centroid_eq_weightedVSub_of_pointsWithCircumcenter s h, point_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub] have hs : ∑ i, (pointWeightsWithCircumcenter i₁ - pointWeightsWithCircumcenter i₂) i = 0 := by simp rw [inner_weightedVSub _ (sum_mongePointVSubFaceCentroidWeightsWithCircumcenter h) _ hs, sum_pointsWithCircumcenter, pointsWithCircumcenter_eq_circumcenter] simp only [mongePointVSubFaceCentroidWeightsWithCircumcenter, pointsWithCircumcenter_point] let fs : Finset (Fin (n + 3)) := {i₁, i₂} have hfs : ∀ i : Fin (n + 3), i ∉ fs → i ≠ i₁ ∧ i ≠ i₂ := by intro i hi constructor <;> · intro hj; simp [fs, ← hj] at hi rw [← sum_subset fs.subset_univ _] · simp_rw [sum_pointsWithCircumcenter, pointsWithCircumcenter_eq_circumcenter, pointsWithCircumcenter_point, Pi.sub_apply, pointWeightsWithCircumcenter] rw [← sum_subset fs.subset_univ _] · simp_rw [fs, sum_insert (not_mem_singleton.2 h), sum_singleton] repeat rw [← sum_subset fs.subset_univ _] · simp_rw [fs, sum_insert (not_mem_singleton.2 h), sum_singleton] simp [h, Ne.symm h, dist_comm (s.points i₁)] all_goals intro i _ hi; simp [hfs i hi] · intro i _ hi simp [hfs i hi, pointsWithCircumcenter] · intro i _ hi simp [hfs i hi] /-- A Monge plane of an (n+2)-simplex is the (n+1)-dimensional affine subspace of the subspace spanned by the simplex that passes through the centroid of an n-dimensional face and is orthogonal to the opposite edge (in 2 dimensions, this is the same as an altitude). This definition is only intended to be used when `i₁ ≠ i₂`. -/ def mongePlane {n : ℕ} (s : Simplex ℝ P (n + 2)) (i₁ i₂ : Fin (n + 3)) : AffineSubspace ℝ P := mk' (({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points) (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ affineSpan ℝ (Set.range s.points) /-- The definition of a Monge plane. -/ theorem mongePlane_def {n : ℕ} (s : Simplex ℝ P (n + 2)) (i₁ i₂ : Fin (n + 3)) : s.mongePlane i₁ i₂ = mk' (({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points) (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ affineSpan ℝ (Set.range s.points) := rfl /-- The Monge plane associated with vertices `i₁` and `i₂` equals that associated with `i₂` and `i₁`. -/ theorem mongePlane_comm {n : ℕ} (s : Simplex ℝ P (n + 2)) (i₁ i₂ : Fin (n + 3)) : s.mongePlane i₁ i₂ = s.mongePlane i₂ i₁ := by simp_rw [mongePlane_def] congr 3 · congr 1 exact pair_comm _ _ · ext simp_rw [Submodule.mem_span_singleton] constructor all_goals rintro ⟨r, rfl⟩; use -r; rw [neg_smul, ← smul_neg, neg_vsub_eq_vsub_rev] /-- The Monge point lies in the Monge planes. -/ theorem mongePoint_mem_mongePlane {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} : s.mongePoint ∈ s.mongePlane i₁ i₂ := by rw [mongePlane_def, mem_inf_iff, ← vsub_right_mem_direction_iff_mem (self_mem_mk' _ _), direction_mk', Submodule.mem_orthogonal'] refine ⟨?_, s.mongePoint_mem_affineSpan⟩ intro v hv rcases Submodule.mem_span_singleton.mp hv with ⟨r, rfl⟩ rw [inner_smul_right, s.inner_mongePoint_vsub_face_centroid_vsub, mul_zero] /-- The direction of a Monge plane. -/ theorem direction_mongePlane {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} : (s.mongePlane i₁ i₂).direction = (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ vectorSpan ℝ (Set.range s.points) := by rw [mongePlane_def, direction_inf_of_mem_inf s.mongePoint_mem_mongePlane, direction_mk', direction_affineSpan] /-- The Monge point is the only point in all the Monge planes from any one vertex. -/ theorem eq_mongePoint_of_forall_mem_mongePlane {n : ℕ} {s : Simplex ℝ P (n + 2)} {i₁ : Fin (n + 3)} {p : P} (h : ∀ i₂, i₁ ≠ i₂ → p ∈ s.mongePlane i₁ i₂) : p = s.mongePoint := by rw [← @vsub_eq_zero_iff_eq V] have h' : ∀ i₂, i₁ ≠ i₂ → p -ᵥ s.mongePoint ∈ (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ vectorSpan ℝ (Set.range s.points) := by intro i₂ hne rw [← s.direction_mongePlane, vsub_right_mem_direction_iff_mem s.mongePoint_mem_mongePlane] exact h i₂ hne have hi : p -ᵥ s.mongePoint ∈ ⨅ i₂ : { i // i₁ ≠ i }, (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ := by rw [Submodule.mem_iInf] exact fun i => (Submodule.mem_inf.1 (h' i i.property)).1 rw [Submodule.iInf_orthogonal, ← Submodule.span_iUnion] at hi have hu : ⋃ i : { i // i₁ ≠ i }, ({s.points i₁ -ᵥ s.points i} : Set V) = (s.points i₁ -ᵥ ·) '' (s.points '' (Set.univ \ {i₁})) := by rw [Set.image_image] ext x simp_rw [Set.mem_iUnion, Set.mem_image, Set.mem_singleton_iff, Set.mem_diff_singleton] constructor · rintro ⟨i, rfl⟩ use i, ⟨Set.mem_univ _, i.property.symm⟩ · rintro ⟨i, ⟨-, hi⟩, rfl⟩ use ⟨i, hi.symm⟩ rw [hu, ← vectorSpan_image_eq_span_vsub_set_left_ne ℝ _ (Set.mem_univ _), Set.image_univ] at hi have hv : p -ᵥ s.mongePoint ∈ vectorSpan ℝ (Set.range s.points) := by let s₁ : Finset (Fin (n + 3)) := univ.erase i₁ obtain ⟨i₂, h₂⟩ := card_pos.1 (show 0 < #s₁ by simp [s₁, card_erase_of_mem]) have h₁₂ : i₁ ≠ i₂ := (ne_of_mem_erase h₂).symm exact (Submodule.mem_inf.1 (h' i₂ h₁₂)).2 exact Submodule.disjoint_def.1 (vectorSpan ℝ (Set.range s.points)).orthogonal_disjoint _ hv hi end Simplex namespace Triangle open EuclideanGeometry Finset Simplex AffineSubspace Module variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The orthocenter of a triangle is the intersection of its altitudes. It is defined here as the 2-dimensional case of the Monge point. -/ def orthocenter (t : Triangle ℝ P) : P := t.mongePoint /-- The orthocenter equals the Monge point. -/ theorem orthocenter_eq_mongePoint (t : Triangle ℝ P) : t.orthocenter = t.mongePoint := rfl /-- The position of the orthocenter in relation to the circumcenter and centroid. -/ theorem orthocenter_eq_smul_vsub_vadd_circumcenter (t : Triangle ℝ P) : t.orthocenter = (3 : ℝ) • ((univ : Finset (Fin 3)).centroid ℝ t.points -ᵥ t.circumcenter : V) +ᵥ t.circumcenter := by rw [orthocenter_eq_mongePoint, mongePoint_eq_smul_vsub_vadd_circumcenter] norm_num /-- The orthocenter lies in the affine span. -/ theorem orthocenter_mem_affineSpan (t : Triangle ℝ P) : t.orthocenter ∈ affineSpan ℝ (Set.range t.points) := t.mongePoint_mem_affineSpan /-- Two triangles with the same points have the same orthocenter. -/ theorem orthocenter_eq_of_range_eq {t₁ t₂ : Triangle ℝ P} (h : Set.range t₁.points = Set.range t₂.points) : t₁.orthocenter = t₂.orthocenter := mongePoint_eq_of_range_eq h /-- In the case of a triangle, altitudes are the same thing as Monge planes. -/ theorem altitude_eq_mongePlane (t : Triangle ℝ P) {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : t.altitude i₁ = t.mongePlane i₂ i₃ := by have hs : ({i₂, i₃}ᶜ : Finset (Fin 3)) = {i₁} := by decide +revert have he : univ.erase i₁ = {i₂, i₃} := by decide +revert rw [mongePlane_def, altitude_def, direction_affineSpan, hs, he, centroid_singleton, coe_insert, coe_singleton, vectorSpan_image_eq_span_vsub_set_left_ne ℝ _ (Set.mem_insert i₂ _)] simp [h₂₃, Submodule.span_insert_eq_span] /-- The orthocenter lies in the altitudes. -/ theorem orthocenter_mem_altitude (t : Triangle ℝ P) {i₁ : Fin 3} : t.orthocenter ∈ t.altitude i₁ := by obtain ⟨i₂, i₃, h₁₂, h₂₃, h₁₃⟩ : ∃ i₂ i₃, i₁ ≠ i₂ ∧ i₂ ≠ i₃ ∧ i₁ ≠ i₃ := by decide +revert rw [orthocenter_eq_mongePoint, t.altitude_eq_mongePlane h₁₂ h₁₃ h₂₃] exact t.mongePoint_mem_mongePlane /-- The orthocenter is the only point lying in any two of the altitudes. -/ theorem eq_orthocenter_of_forall_mem_altitude {t : Triangle ℝ P} {i₁ i₂ : Fin 3} {p : P} (h₁₂ : i₁ ≠ i₂) (h₁ : p ∈ t.altitude i₁) (h₂ : p ∈ t.altitude i₂) : p = t.orthocenter := by obtain ⟨i₃, h₂₃, h₁₃⟩ : ∃ i₃, i₂ ≠ i₃ ∧ i₁ ≠ i₃ := by clear h₁ h₂ decide +revert rw [t.altitude_eq_mongePlane h₁₃ h₁₂ h₂₃.symm] at h₁ rw [t.altitude_eq_mongePlane h₂₃ h₁₂.symm h₁₃.symm] at h₂ rw [orthocenter_eq_mongePoint] have ha : ∀ i, i₃ ≠ i → p ∈ t.mongePlane i₃ i := by intro i hi obtain rfl | rfl : i₁ = i ∨ i₂ = i := by omega all_goals assumption exact eq_mongePoint_of_forall_mem_mongePlane ha /-- The distance from the orthocenter to the reflection of the circumcenter in a side equals the circumradius. -/ theorem dist_orthocenter_reflection_circumcenter (t : Triangle ℝ P) {i₁ i₂ : Fin 3} (h : i₁ ≠ i₂) : dist t.orthocenter (reflection (affineSpan ℝ (t.points '' {i₁, i₂})) t.circumcenter) = t.circumradius := by rw [← mul_self_inj_of_nonneg dist_nonneg t.circumradius_nonneg, t.reflection_circumcenter_eq_affineCombination_of_pointsWithCircumcenter h, t.orthocenter_eq_mongePoint, mongePoint_eq_affineCombination_of_pointsWithCircumcenter, dist_affineCombination t.pointsWithCircumcenter (sum_mongePointWeightsWithCircumcenter _) (sum_reflectionCircumcenterWeightsWithCircumcenter h)] simp_rw [sum_pointsWithCircumcenter, Pi.sub_apply, mongePointWeightsWithCircumcenter, reflectionCircumcenterWeightsWithCircumcenter] have hu : ({i₁, i₂} : Finset (Fin 3)) ⊆ univ := subset_univ _ obtain ⟨i₃, hi₃, hi₃₁, hi₃₂⟩ : ∃ i₃, univ \ ({i₁, i₂} : Finset (Fin 3)) = {i₃} ∧ i₃ ≠ i₁ ∧ i₃ ≠ i₂ := by decide +revert simp_rw [← sum_sdiff hu, hi₃] norm_num [hi₃₁, hi₃₂] /-- The distance from the orthocenter to the reflection of the circumcenter in a side equals the circumradius, variant using a `Finset`. -/ theorem dist_orthocenter_reflection_circumcenter_finset (t : Triangle ℝ P) {i₁ i₂ : Fin 3} (h : i₁ ≠ i₂) : dist t.orthocenter (reflection (affineSpan ℝ (t.points '' ↑({i₁, i₂} : Finset (Fin 3)))) t.circumcenter) = t.circumradius := by simp only [mem_singleton, coe_insert, coe_singleton, Set.mem_singleton_iff] exact dist_orthocenter_reflection_circumcenter _ h /-- The affine span of the orthocenter and a vertex is contained in the altitude. -/ theorem affineSpan_orthocenter_point_le_altitude (t : Triangle ℝ P) (i : Fin 3) : line[ℝ, t.orthocenter, t.points i] ≤ t.altitude i := by refine affineSpan_le_of_subset_coe ?_ rw [Set.insert_subset_iff, Set.singleton_subset_iff] exact ⟨t.orthocenter_mem_altitude, t.mem_altitude i⟩ /-- Suppose we are given a triangle `t₁`, and replace one of its vertices by its orthocenter, yielding triangle `t₂` (with vertices not necessarily listed in the same order). Then an altitude of `t₂` from a vertex that was not replaced is the corresponding side of `t₁`. -/ theorem altitude_replace_orthocenter_eq_affineSpan {t₁ t₂ : Triangle ℝ P} {i₁ i₂ i₃ j₁ j₂ j₃ : Fin 3} (hi₁₂ : i₁ ≠ i₂) (hi₁₃ : i₁ ≠ i₃) (hi₂₃ : i₂ ≠ i₃) (hj₁₂ : j₁ ≠ j₂) (hj₁₃ : j₁ ≠ j₃) (hj₂₃ : j₂ ≠ j₃) (h₁ : t₂.points j₁ = t₁.orthocenter) (h₂ : t₂.points j₂ = t₁.points i₂) (h₃ : t₂.points j₃ = t₁.points i₃) : t₂.altitude j₂ = line[ℝ, t₁.points i₁, t₁.points i₂] := by symm rw [← h₂, t₂.affineSpan_pair_eq_altitude_iff] rw [h₂] use t₁.independent.injective.ne hi₁₂ have he : affineSpan ℝ (Set.range t₂.points) = affineSpan ℝ (Set.range t₁.points) := by refine ext_of_direction_eq ?_ ⟨t₁.points i₃, mem_affineSpan ℝ ⟨j₃, h₃⟩, mem_affineSpan ℝ (Set.mem_range_self _)⟩ refine Submodule.eq_of_le_of_finrank_eq (direction_le (affineSpan_le_of_subset_coe ?_)) ?_ · have hu : (Finset.univ : Finset (Fin 3)) = {j₁, j₂, j₃} := by clear h₁ h₂ h₃ decide +revert rw [← Set.image_univ, ← Finset.coe_univ, hu, Finset.coe_insert, Finset.coe_insert, Finset.coe_singleton, Set.image_insert_eq, Set.image_insert_eq, Set.image_singleton, h₁, h₂, h₃, Set.insert_subset_iff, Set.insert_subset_iff, Set.singleton_subset_iff] exact ⟨t₁.orthocenter_mem_affineSpan, mem_affineSpan ℝ (Set.mem_range_self _), mem_affineSpan ℝ (Set.mem_range_self _)⟩ · rw [direction_affineSpan, direction_affineSpan, t₁.independent.finrank_vectorSpan (Fintype.card_fin _), t₂.independent.finrank_vectorSpan (Fintype.card_fin _)] rw [he] use mem_affineSpan ℝ (Set.mem_range_self _) have hu : Finset.univ.erase j₂ = {j₁, j₃} := by clear h₁ h₂ h₃ decide +revert rw [hu, Finset.coe_insert, Finset.coe_singleton, Set.image_insert_eq, Set.image_singleton, h₁, h₃] have hle : (t₁.altitude i₃).directionᗮ ≤ line[ℝ, t₁.orthocenter, t₁.points i₃].directionᗮ := Submodule.orthogonal_le (direction_le (affineSpan_orthocenter_point_le_altitude _ _)) refine hle ((t₁.vectorSpan_isOrtho_altitude_direction i₃) ?_) have hui : Finset.univ.erase i₃ = {i₁, i₂} := by clear hle h₂ h₃ decide +revert rw [hui, Finset.coe_insert, Finset.coe_singleton, Set.image_insert_eq, Set.image_singleton] exact vsub_mem_vectorSpan ℝ (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_singleton _)) /-- Suppose we are given a triangle `t₁`, and replace one of its vertices by its orthocenter, yielding triangle `t₂` (with vertices not necessarily listed in the same order). Then the orthocenter of `t₂` is the vertex of `t₁` that was replaced. -/ theorem orthocenter_replace_orthocenter_eq_point {t₁ t₂ : Triangle ℝ P} {i₁ i₂ i₃ j₁ j₂ j₃ : Fin 3} (hi₁₂ : i₁ ≠ i₂) (hi₁₃ : i₁ ≠ i₃) (hi₂₃ : i₂ ≠ i₃) (hj₁₂ : j₁ ≠ j₂) (hj₁₃ : j₁ ≠ j₃) (hj₂₃ : j₂ ≠ j₃) (h₁ : t₂.points j₁ = t₁.orthocenter) (h₂ : t₂.points j₂ = t₁.points i₂) (h₃ : t₂.points j₃ = t₁.points i₃) : t₂.orthocenter = t₁.points i₁ := by refine (Triangle.eq_orthocenter_of_forall_mem_altitude hj₂₃ ?_ ?_).symm · rw [altitude_replace_orthocenter_eq_affineSpan hi₁₂ hi₁₃ hi₂₃ hj₁₂ hj₁₃ hj₂₃ h₁ h₂ h₃] exact mem_affineSpan ℝ (Set.mem_insert _ _) · rw [altitude_replace_orthocenter_eq_affineSpan hi₁₃ hi₁₂ hi₂₃.symm hj₁₃ hj₁₂ hj₂₃.symm h₁ h₃ h₂] exact mem_affineSpan ℝ (Set.mem_insert _ _) end Triangle end Affine namespace EuclideanGeometry open Affine AffineSubspace Module variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- Four points form an orthocentric system if they consist of the vertices of a triangle and its orthocenter. -/ def OrthocentricSystem (s : Set P) : Prop := ∃ t : Triangle ℝ P, t.orthocenter ∉ Set.range t.points ∧ s = insert t.orthocenter (Set.range t.points) /-- This is an auxiliary lemma giving information about the relation of two triangles in an orthocentric system; it abstracts some reasoning, with no geometric content, that is common to some other lemmas. Suppose the orthocentric system is generated by triangle `t`, and we are given three points `p` in the orthocentric system. Then either we can find indices `i₁`, `i₂` and `i₃` for `p` such that `p i₁` is the orthocenter of `t` and `p i₂` and `p i₃` are points `j₂` and `j₃` of `t`, or `p` has the same points as `t`. -/ theorem exists_of_range_subset_orthocentricSystem {t : Triangle ℝ P} (ho : t.orthocenter ∉ Set.range t.points) {p : Fin 3 → P} (hps : Set.range p ⊆ insert t.orthocenter (Set.range t.points)) (hpi : Function.Injective p) : (∃ i₁ i₂ i₃ j₂ j₃ : Fin 3, i₁ ≠ i₂ ∧ i₁ ≠ i₃ ∧ i₂ ≠ i₃ ∧ (∀ i : Fin 3, i = i₁ ∨ i = i₂ ∨ i = i₃) ∧ p i₁ = t.orthocenter ∧ j₂ ≠ j₃ ∧ t.points j₂ = p i₂ ∧ t.points j₃ = p i₃) ∨ Set.range p = Set.range t.points := by by_cases h : t.orthocenter ∈ Set.range p · left rcases h with ⟨i₁, h₁⟩ obtain ⟨i₂, i₃, h₁₂, h₁₃, h₂₃, h₁₂₃⟩ : ∃ i₂ i₃ : Fin 3, i₁ ≠ i₂ ∧ i₁ ≠ i₃ ∧ i₂ ≠ i₃ ∧ ∀ i : Fin 3, i = i₁ ∨ i = i₂ ∨ i = i₃ := by clear h₁ decide +revert have h : ∀ i, i₁ ≠ i → ∃ j : Fin 3, t.points j = p i := by intro i hi replace hps := Set.mem_of_mem_insert_of_ne (Set.mem_of_mem_of_subset (Set.mem_range_self i) hps) (h₁ ▸ hpi.ne hi.symm) exact hps rcases h i₂ h₁₂ with ⟨j₂, h₂⟩ rcases h i₃ h₁₃ with ⟨j₃, h₃⟩ have hj₂₃ : j₂ ≠ j₃ := by intro he rw [he, h₃] at h₂ exact h₂₃.symm (hpi h₂) exact ⟨i₁, i₂, i₃, j₂, j₃, h₁₂, h₁₃, h₂₃, h₁₂₃, h₁, hj₂₃, h₂, h₃⟩
· right have hs := Set.subset_diff_singleton hps h rw [Set.insert_diff_self_of_not_mem ho] at hs classical refine Set.eq_of_subset_of_card_le hs ?_ rw [Set.card_range_of_injective hpi, Set.card_range_of_injective t.independent.injective] /-- For any three points in an orthocentric system generated by triangle `t`, there is a point in the subspace spanned by the triangle from which the distance of all those three points equals the circumradius. -/ theorem exists_dist_eq_circumradius_of_subset_insert_orthocenter {t : Triangle ℝ P} (ho : t.orthocenter ∉ Set.range t.points) {p : Fin 3 → P} (hps : Set.range p ⊆ insert t.orthocenter (Set.range t.points)) (hpi : Function.Injective p) : ∃ c ∈ affineSpan ℝ (Set.range t.points), ∀ p₁ ∈ Set.range p, dist p₁ c = t.circumradius := by rcases exists_of_range_subset_orthocentricSystem ho hps hpi with (⟨i₁, i₂, i₃, j₂, j₃, _, _, _, h₁₂₃, h₁, hj₂₃, h₂, h₃⟩ | hs) · use reflection (affineSpan ℝ (t.points '' {j₂, j₃})) t.circumcenter, reflection_mem_of_le_of_mem (affineSpan_mono ℝ (Set.image_subset_range _ _)) t.circumcenter_mem_affineSpan intro p₁ hp₁ rcases hp₁ with ⟨i, rfl⟩ have h₁₂₃ := h₁₂₃ i repeat' rcases h₁₂₃ with h₁₂₃ | h₁₂₃ · convert Triangle.dist_orthocenter_reflection_circumcenter t hj₂₃ · rw [← h₂, dist_reflection_eq_of_mem _
Mathlib/Geometry/Euclidean/MongePoint.lean
521
545
/- Copyright (c) 2024 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.AlgebraicGeometry.EllipticCurve.Group import Mathlib.NumberTheory.EllipticDivisibilitySequence /-! # Division polynomials of Weierstrass curves This file defines certain polynomials associated to division polynomials of Weierstrass curves. These are defined in terms of the auxiliary sequences for normalised elliptic divisibility sequences (EDS) as defined in `Mathlib.NumberTheory.EllipticDivisibilitySequence`. ## Mathematical background Let `W` be a Weierstrass curve over a commutative ring `R`. The sequence of `n`-division polynomials `ψₙ ∈ R[X, Y]` of `W` is the normalised EDS with initial values * `ψ₀ := 0`, * `ψ₁ := 1`, * `ψ₂ := 2Y + a₁X + a₃`, * `ψ₃ := 3X⁴ + b₂X³ + 3b₄X² + 3b₆X + b₈`, and * `ψ₄ := ψ₂ ⬝ (2X⁶ + b₂X⁵ + 5b₄X⁴ + 10b₆X³ + 10b₈X² + (b₂b₈ - b₄b₆)X + (b₄b₈ - b₆²))`. Furthermore, define the associated sequences `φₙ, ωₙ ∈ R[X, Y]` by * `φₙ := Xψₙ² - ψₙ₊₁ ⬝ ψₙ₋₁`, and * `ωₙ := (ψ₂ₙ / ψₙ - ψₙ ⬝ (a₁φₙ + a₃ψₙ²)) / 2`. Note that `ωₙ` is always well-defined as a polynomial in `R[X, Y]`. As a start, it can be shown by induction that `ψₙ` always divides `ψ₂ₙ` in `R[X, Y]`, so that `ψ₂ₙ / ψₙ` is always well-defined as a polynomial, while division by `2` is well-defined when `R` has characteristic different from `2`. In general, it can be shown that `2` always divides the polynomial `ψ₂ₙ / ψₙ - ψₙ ⬝ (a₁φₙ + a₃ψₙ²)` in the characteristic `0` universal ring `𝓡[X, Y] := ℤ[A₁, A₂, A₃, A₄, A₆][X, Y]` of `W`, where the `Aᵢ` are indeterminates. Then `ωₙ` can be equivalently defined as the image of this division under the associated universal morphism `𝓡[X, Y] → R[X, Y]` mapping `Aᵢ` to `aᵢ`. Now, in the coordinate ring `R[W]`, note that `ψ₂²` is congruent to the polynomial `Ψ₂Sq := 4X³ + b₂X² + 2b₄X + b₆ ∈ R[X]`. As such, the recurrences of a normalised EDS show that `ψₙ / ψ₂` are congruent to certain polynomials in `R[W]`. In particular, define `preΨₙ ∈ R[X]` as the auxiliary sequence for a normalised EDS with extra parameter `Ψ₂Sq²` and initial values * `preΨ₀ := 0`, * `preΨ₁ := 1`, * `preΨ₂ := 1`, * `preΨ₃ := ψ₃`, and * `preΨ₄ := ψ₄ / ψ₂`. The corresponding normalised EDS `Ψₙ ∈ R[X, Y]` is then given by * `Ψₙ := preΨₙ ⬝ ψ₂` if `n` is even, and * `Ψₙ := preΨₙ` if `n` is odd. Furthermore, define the associated sequences `ΨSqₙ, Φₙ ∈ R[X]` by * `ΨSqₙ := preΨₙ² ⬝ Ψ₂Sq` if `n` is even, * `ΨSqₙ := preΨₙ²` if `n` is odd, * `Φₙ := XΨSqₙ - preΨₙ₊₁ ⬝ preΨₙ₋₁` if `n` is even, and * `Φₙ := XΨSqₙ - preΨₙ₊₁ ⬝ preΨₙ₋₁ ⬝ Ψ₂Sq` if `n` is odd. With these definitions, `ψₙ ∈ R[X, Y]` and `φₙ ∈ R[X, Y]` are congruent in `R[W]` to `Ψₙ ∈ R[X, Y]` and `Φₙ ∈ R[X]` respectively, which are defined in terms of `Ψ₂Sq ∈ R[X]` and `preΨₙ ∈ R[X]`. ## Main definitions * `WeierstrassCurve.preΨ`: the univariate polynomials `preΨₙ`. * `WeierstrassCurve.ΨSq`: the univariate polynomials `ΨSqₙ`. * `WeierstrassCurve.Ψ`: the bivariate polynomials `Ψₙ`. * `WeierstrassCurve.Φ`: the univariate polynomials `Φₙ`. * `WeierstrassCurve.ψ`: the bivariate `n`-division polynomials `ψₙ`. * `WeierstrassCurve.φ`: the bivariate polynomials `φₙ`. * TODO: the bivariate polynomials `ωₙ`. ## Implementation notes Analogously to `Mathlib.NumberTheory.EllipticDivisibilitySequence`, the bivariate polynomials `Ψₙ` are defined in terms of the univariate polynomials `preΨₙ`. This is done partially to avoid ring division, but more crucially to allow the definition of `ΨSqₙ` and `Φₙ` as univariate polynomials without needing to work under the coordinate ring, and to allow the computation of their leading terms without ambiguity. Furthermore, evaluating these polynomials at a rational point on `W` recovers their original definition up to linear combinations of the Weierstrass equation of `W`, hence also avoiding the need to work in the coordinate ring. TODO: implementation notes for the definition of `ωₙ`. ## References [J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009] ## Tags elliptic curve, division polynomial, torsion point -/ 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 "map_simp" : tactic => `(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow, map_div₀, Polynomial.map_ofNat, Polynomial.map_one, map_C, map_X, Polynomial.map_neg, Polynomial.map_add, Polynomial.map_sub, Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_div, coe_mapRingHom, apply_ite <| mapRingHom _, WeierstrassCurve.map]) universe r s u v namespace WeierstrassCurve variable {R : Type r} {S : Type s} [CommRing R] [CommRing S] (W : WeierstrassCurve R) section Ψ₂Sq /-! ### The univariate polynomial `Ψ₂Sq` -/ /-- The `2`-division polynomial `ψ₂ = Ψ₂`. -/ noncomputable def ψ₂ : R[X][Y] := W.toAffine.polynomialY /-- The univariate polynomial `Ψ₂Sq` congruent to `ψ₂²`. -/ noncomputable def Ψ₂Sq : R[X] := C 4 * X ^ 3 + C W.b₂ * X ^ 2 + C (2 * W.b₄) * X + C W.b₆ lemma C_Ψ₂Sq : C W.Ψ₂Sq = W.ψ₂ ^ 2 - 4 * W.toAffine.polynomial := by rw [Ψ₂Sq, ψ₂, b₂, b₄, b₆, Affine.polynomialY, Affine.polynomial] C_simp ring1 lemma ψ₂_sq : W.ψ₂ ^ 2 = C W.Ψ₂Sq + 4 * W.toAffine.polynomial := by rw [C_Ψ₂Sq, sub_add_cancel] lemma Affine.CoordinateRing.mk_ψ₂_sq : mk W W.ψ₂ ^ 2 = mk W (C W.Ψ₂Sq) := by rw [C_Ψ₂Sq, map_sub, map_mul, AdjoinRoot.mk_self, mul_zero, sub_zero, map_pow] -- TODO: remove `twoTorsionPolynomial` in favour of `Ψ₂Sq` lemma Ψ₂Sq_eq : W.Ψ₂Sq = W.twoTorsionPolynomial.toPoly := rfl end Ψ₂Sq section preΨ' /-! ### The univariate polynomials `preΨₙ` for `n ∈ ℕ` -/ /-- The `3`-division polynomial `ψ₃ = Ψ₃`. -/ noncomputable def Ψ₃ : R[X] := 3 * X ^ 4 + C W.b₂ * X ^ 3 + 3 * C W.b₄ * X ^ 2 + 3 * C W.b₆ * X + C W.b₈ /-- The univariate polynomial `preΨ₄`, which is auxiliary to the 4-division polynomial `ψ₄ = Ψ₄ = preΨ₄ψ₂`. -/ noncomputable def preΨ₄ : R[X] := 2 * X ^ 6 + C W.b₂ * X ^ 5 + 5 * C W.b₄ * X ^ 4 + 10 * C W.b₆ * X ^ 3 + 10 * C W.b₈ * X ^ 2 + C (W.b₂ * W.b₈ - W.b₄ * W.b₆) * X + C (W.b₄ * W.b₈ - W.b₆ ^ 2) /-- The univariate polynomials `preΨₙ` for `n ∈ ℕ`, which are auxiliary to the bivariate polynomials `Ψₙ` congruent to the bivariate `n`-division polynomials `ψₙ`. -/ noncomputable def preΨ' (n : ℕ) : R[X] := preNormEDS' (W.Ψ₂Sq ^ 2) W.Ψ₃ W.preΨ₄ n @[simp] lemma preΨ'_zero : W.preΨ' 0 = 0 := preNormEDS'_zero .. @[simp] lemma preΨ'_one : W.preΨ' 1 = 1 := preNormEDS'_one .. @[simp] lemma preΨ'_two : W.preΨ' 2 = 1 := preNormEDS'_two .. @[simp] lemma preΨ'_three : W.preΨ' 3 = W.Ψ₃ := preNormEDS'_three .. @[simp] lemma preΨ'_four : W.preΨ' 4 = W.preΨ₄ := preNormEDS'_four .. lemma preΨ'_even (m : ℕ) : W.preΨ' (2 * (m + 3)) = W.preΨ' (m + 2) ^ 2 * W.preΨ' (m + 3) * W.preΨ' (m + 5) - W.preΨ' (m + 1) * W.preΨ' (m + 3) * W.preΨ' (m + 4) ^ 2 := preNormEDS'_even .. lemma preΨ'_odd (m : ℕ) : W.preΨ' (2 * (m + 2) + 1) = W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) := preNormEDS'_odd .. end preΨ' section preΨ /-! ### The univariate polynomials `preΨₙ` for `n ∈ ℤ` -/ /-- The univariate polynomials `preΨₙ` for `n ∈ ℤ`, which are auxiliary to the bivariate polynomials `Ψₙ` congruent to the bivariate `n`-division polynomials `ψₙ`. -/ noncomputable def preΨ (n : ℤ) : R[X] := preNormEDS (W.Ψ₂Sq ^ 2) W.Ψ₃ W.preΨ₄ n @[simp] lemma preΨ_ofNat (n : ℕ) : W.preΨ n = W.preΨ' n := preNormEDS_ofNat .. @[simp] lemma preΨ_zero : W.preΨ 0 = 0 := preNormEDS_zero .. @[simp] lemma preΨ_one : W.preΨ 1 = 1 := preNormEDS_one .. @[simp] lemma preΨ_two : W.preΨ 2 = 1 := preNormEDS_two .. @[simp] lemma preΨ_three : W.preΨ 3 = W.Ψ₃ := preNormEDS_three .. @[simp] lemma preΨ_four : W.preΨ 4 = W.preΨ₄ := preNormEDS_four .. lemma preΨ_even_ofNat (m : ℕ) : W.preΨ (2 * (m + 3)) = W.preΨ (m + 2) ^ 2 * W.preΨ (m + 3) * W.preΨ (m + 5) - W.preΨ (m + 1) * W.preΨ (m + 3) * W.preΨ (m + 4) ^ 2 := preNormEDS_even_ofNat .. lemma preΨ_odd_ofNat (m : ℕ) : W.preΨ (2 * (m + 2) + 1) = W.preΨ (m + 4) * W.preΨ (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ (m + 1) * W.preΨ (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) := preNormEDS_odd_ofNat .. @[simp] lemma preΨ_neg (n : ℤ) : W.preΨ (-n) = -W.preΨ n := preNormEDS_neg .. lemma preΨ_even (m : ℤ) : W.preΨ (2 * m) = W.preΨ (m - 1) ^ 2 * W.preΨ m * W.preΨ (m + 2) - W.preΨ (m - 2) * W.preΨ m * W.preΨ (m + 1) ^ 2 := preNormEDS_even .. lemma preΨ_odd (m : ℤ) : W.preΨ (2 * m + 1) = W.preΨ (m + 2) * W.preΨ m ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) := preNormEDS_odd .. end preΨ section ΨSq /-! ### The univariate polynomials `ΨSqₙ` -/ /-- The univariate polynomials `ΨSqₙ` congruent to `ψₙ²`. -/ noncomputable def ΨSq (n : ℤ) : R[X] := W.preΨ n ^ 2 * if Even n then W.Ψ₂Sq else 1 @[simp] lemma ΨSq_ofNat (n : ℕ) : W.ΨSq n = W.preΨ' n ^ 2 * if Even n then W.Ψ₂Sq else 1 := by simp only [ΨSq, preΨ_ofNat, Int.even_coe_nat] @[simp] lemma ΨSq_zero : W.ΨSq 0 = 0 := by rw [← Nat.cast_zero, ΨSq_ofNat, preΨ'_zero, zero_pow two_ne_zero, zero_mul] @[simp] lemma ΨSq_one : W.ΨSq 1 = 1 := by rw [← Nat.cast_one, ΨSq_ofNat, preΨ'_one, one_pow, one_mul, if_neg Nat.not_even_one] @[simp] lemma ΨSq_two : W.ΨSq 2 = W.Ψ₂Sq := by rw [← Nat.cast_two, ΨSq_ofNat, preΨ'_two, one_pow, one_mul, if_pos even_two] @[simp] lemma ΨSq_three : W.ΨSq 3 = W.Ψ₃ ^ 2 := by rw [← Nat.cast_three, ΨSq_ofNat, preΨ'_three, if_neg <| by decide, mul_one] @[simp] lemma ΨSq_four : W.ΨSq 4 = W.preΨ₄ ^ 2 * W.Ψ₂Sq := by rw [← Nat.cast_four, ΨSq_ofNat, preΨ'_four, if_pos <| by decide] lemma ΨSq_even_ofNat (m : ℕ) : W.ΨSq (2 * (m + 3)) = (W.preΨ' (m + 2) ^ 2 * W.preΨ' (m + 3) * W.preΨ' (m + 5) - W.preΨ' (m + 1) * W.preΨ' (m + 3) * W.preΨ' (m + 4) ^ 2) ^ 2 * W.Ψ₂Sq := by rw_mod_cast [ΨSq_ofNat, preΨ'_even, if_pos <| even_two_mul _] lemma ΨSq_odd_ofNat (m : ℕ) : W.ΨSq (2 * (m + 2) + 1) = (W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2)) ^ 2 := by rw_mod_cast [ΨSq_ofNat, preΨ'_odd, if_neg (m + 2).not_even_two_mul_add_one, mul_one] @[simp] lemma ΨSq_neg (n : ℤ) : W.ΨSq (-n) = W.ΨSq n := by simp only [ΨSq, preΨ_neg, neg_sq, even_neg] lemma ΨSq_even (m : ℤ) : W.ΨSq (2 * m) = (W.preΨ (m - 1) ^ 2 * W.preΨ m * W.preΨ (m + 2) - W.preΨ (m - 2) * W.preΨ m * W.preΨ (m + 1) ^ 2) ^ 2 * W.Ψ₂Sq := by rw [ΨSq, preΨ_even, if_pos <| even_two_mul _] lemma ΨSq_odd (m : ℤ) : W.ΨSq (2 * m + 1) = (W.preΨ (m + 2) * W.preΨ m ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2)) ^ 2 := by rw [ΨSq, preΨ_odd, if_neg m.not_even_two_mul_add_one, mul_one] end ΨSq section Ψ /-! ### The bivariate polynomials `Ψₙ` -/ /-- The bivariate polynomials `Ψₙ` congruent to the `n`-division polynomials `ψₙ`. -/ protected noncomputable def Ψ (n : ℤ) : R[X][Y] := C (W.preΨ n) * if Even n then W.ψ₂ else 1 open WeierstrassCurve (Ψ) @[simp] lemma Ψ_ofNat (n : ℕ) : W.Ψ n = C (W.preΨ' n) * if Even n then W.ψ₂ else 1 := by simp only [Ψ, preΨ_ofNat, Int.even_coe_nat] @[simp] lemma Ψ_zero : W.Ψ 0 = 0 := by rw [← Nat.cast_zero, Ψ_ofNat, preΨ'_zero, C_0, zero_mul] @[simp] lemma Ψ_one : W.Ψ 1 = 1 := by rw [← Nat.cast_one, Ψ_ofNat, preΨ'_one, C_1, if_neg Nat.not_even_one, mul_one] @[simp] lemma Ψ_two : W.Ψ 2 = W.ψ₂ := by rw [← Nat.cast_two, Ψ_ofNat, preΨ'_two, C_1, one_mul, if_pos even_two] @[simp] lemma Ψ_three : W.Ψ 3 = C W.Ψ₃ := by rw [← Nat.cast_three, Ψ_ofNat, preΨ'_three, if_neg <| by decide, mul_one] @[simp] lemma Ψ_four : W.Ψ 4 = C W.preΨ₄ * W.ψ₂ := by rw [← Nat.cast_four, Ψ_ofNat, preΨ'_four, if_pos <| by decide] lemma Ψ_even_ofNat (m : ℕ) : W.Ψ (2 * (m + 3)) * W.ψ₂ = W.Ψ (m + 2) ^ 2 * W.Ψ (m + 3) * W.Ψ (m + 5) - W.Ψ (m + 1) * W.Ψ (m + 3) * W.Ψ (m + 4) ^ 2 := by repeat rw_mod_cast [Ψ_ofNat] simp_rw [preΨ'_even, if_pos <| even_two_mul _, Nat.even_add_one, ite_not] split_ifs <;> C_simp <;> ring1 lemma Ψ_odd_ofNat (m : ℕ) : W.Ψ (2 * (m + 2) + 1) = W.Ψ (m + 4) * W.Ψ (m + 2) ^ 3 - W.Ψ (m + 1) * W.Ψ (m + 3) ^ 3 + W.toAffine.polynomial * (16 * W.toAffine.polynomial - 8 * W.ψ₂ ^ 2) * C (if Even m then W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 else -W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3) := by repeat rw_mod_cast [Ψ_ofNat] simp_rw [preΨ'_odd, if_neg (m + 2).not_even_two_mul_add_one, Nat.even_add_one, ite_not] split_ifs <;> C_simp <;> rw [C_Ψ₂Sq] <;> ring1 @[simp] lemma Ψ_neg (n : ℤ) : W.Ψ (-n) = -W.Ψ n := by simp only [Ψ, preΨ_neg, C_neg, neg_mul (α := R[X][Y]), even_neg] lemma Ψ_even (m : ℤ) : W.Ψ (2 * m) * W.ψ₂ = W.Ψ (m - 1) ^ 2 * W.Ψ m * W.Ψ (m + 2) - W.Ψ (m - 2) * W.Ψ m * W.Ψ (m + 1) ^ 2 := by repeat rw [Ψ] simp_rw [preΨ_even, if_pos <| even_two_mul _, Int.even_add_one, show m + 2 = m + 1 + 1 by ring1, Int.even_add_one, show m - 2 = m - 1 - 1 by ring1, Int.even_sub_one, ite_not] split_ifs <;> C_simp <;> ring1 lemma Ψ_odd (m : ℤ) : W.Ψ (2 * m + 1) = W.Ψ (m + 2) * W.Ψ m ^ 3 - W.Ψ (m - 1) * W.Ψ (m + 1) ^ 3 + W.toAffine.polynomial * (16 * W.toAffine.polynomial - 8 * W.ψ₂ ^ 2) * C (if Even m then W.preΨ (m + 2) * W.preΨ m ^ 3 else -W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3) := by repeat rw [Ψ] simp_rw [preΨ_odd, if_neg m.not_even_two_mul_add_one, show m + 2 = m + 1 + 1 by ring1, Int.even_add_one, Int.even_sub_one, ite_not] split_ifs <;> C_simp <;> rw [C_Ψ₂Sq] <;> ring1 lemma Affine.CoordinateRing.mk_Ψ_sq (n : ℤ) : mk W (W.Ψ n) ^ 2 = mk W (C <| W.ΨSq n) := by simp only [Ψ, ΨSq, map_one, map_mul, map_pow, one_pow, mul_pow, ite_pow, apply_ite C, apply_ite <| mk W, mk_ψ₂_sq] end Ψ section Φ /-! ### The univariate polynomials `Φₙ` -/ /-- The univariate polynomials `Φₙ` congruent to `φₙ`. -/ protected noncomputable def Φ (n : ℤ) : R[X] := X * W.ΨSq n - W.preΨ (n + 1) * W.preΨ (n - 1) * if Even n then 1 else W.Ψ₂Sq open WeierstrassCurve (Φ)
@[simp] lemma Φ_ofNat (n : ℕ) : W.Φ (n + 1) = X * W.preΨ' (n + 1) ^ 2 * (if Even n then 1 else W.Ψ₂Sq) -
Mathlib/AlgebraicGeometry/EllipticCurve/DivisionPolynomial/Basic.lean
392
395
/- Copyright (c) 2024 Ira Fesefeldt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ira Fesefeldt -/ import Mathlib.SetTheory.Ordinal.Arithmetic /-! # Ordinal Approximants for the Fixed points on complete lattices This file sets up the ordinal-indexed approximation theory of fixed points of a monotone function in a complete lattice [Cousot1979]. The proof follows loosely the one from [Echenique2005]. However, the proof given here is not constructive as we use the non-constructive axiomatization of ordinals from mathlib. It still allows an approximation scheme indexed over the ordinals. ## Main definitions * `OrdinalApprox.lfpApprox`: The ordinal-indexed approximation of the least fixed point greater or equal than an initial value of a bundled monotone function. * `OrdinalApprox.gfpApprox`: The ordinal-indexed approximation of the greatest fixed point less or equal than an initial value of a bundled monotone function. ## Main theorems * `OrdinalApprox.lfp_mem_range_lfpApprox`: The ordinal-indexed approximation of the least fixed point eventually reaches the least fixed point * `OrdinalApprox.gfp_mem_range_gfpApprox`: The ordinal-indexed approximation of the greatest fixed point eventually reaches the greatest fixed point ## References * [F. Echenique, *A short and constructive proof of Tarski’s fixed-point theorem*][Echenique2005] * [P. Cousot & R. Cousot, *Constructive Versions of Tarski's Fixed Point Theorems*][Cousot1979] ## Tags fixed point, complete lattice, monotone function, ordinals, approximation -/ namespace Cardinal universe u variable {α : Type u} variable (g : Ordinal → α) open Cardinal Ordinal SuccOrder Function Set theorem not_injective_limitation_set : ¬ InjOn g (Iio (ord <| succ #α)) := by intro h_inj have h := lift_mk_le_lift_mk_of_injective <| injOn_iff_injective.1 h_inj have mk_initialSeg_subtype : #(Iio (ord <| succ #α)) = lift.{u + 1} (succ #α) := by simpa only [coe_setOf, card_typein, card_ord] using mk_Iio_ordinal (ord <| succ #α) rw [mk_initialSeg_subtype, lift_lift, lift_le] at h exact not_le_of_lt (Order.lt_succ #α) h end Cardinal namespace OrdinalApprox universe u variable {α : Type u} variable [CompleteLattice α] (f : α →o α) (x : α) open Function fixedPoints Cardinal Order OrderHom set_option linter.unusedVariables false in /-- The ordinal-indexed sequence approximating the least fixed point greater than an initial value `x`. It is defined in such a way that we have `lfpApprox 0 x = x` and `lfpApprox a x = ⨆ b < a, f (lfpApprox b x)`. -/ def lfpApprox (a : Ordinal.{u}) : α := sSup ({ f (lfpApprox b) | (b : Ordinal) (h : b < a) } ∪ {x}) termination_by a decreasing_by exact h theorem lfpApprox_monotone : Monotone (lfpApprox f x) := by intros a b h rw [lfpApprox, lfpApprox] refine sSup_le_sSup ?h apply sup_le_sup_right simp only [exists_prop, Set.le_eq_subset, Set.setOf_subset_setOf, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] intros a' h' use a' exact ⟨lt_of_lt_of_le h' h, rfl⟩ theorem le_lfpApprox {a : Ordinal} : x ≤ lfpApprox f x a := by rw [lfpApprox] apply le_sSup simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, true_or] theorem lfpApprox_add_one (h : x ≤ f x) (a : Ordinal) : lfpApprox f x (a+1) = f (lfpApprox f x a) := by apply le_antisymm · conv => left; rw [lfpApprox] apply sSup_le simp only [Ordinal.add_one_eq_succ, lt_succ_iff, exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, forall_eq_or_imp, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] apply And.intro · apply le_trans h apply Monotone.imp f.monotone exact le_lfpApprox f x · intros a' h apply f.2; apply lfpApprox_monotone; exact h · conv => right; rw [lfpApprox] apply le_sSup simp only [Ordinal.add_one_eq_succ, lt_succ_iff, exists_prop] rw [Set.mem_union] apply Or.inl simp only [Set.mem_setOf_eq] use a theorem lfpApprox_mono_left : Monotone (lfpApprox : (α →o α) → _) := by intro f g h x a induction a using Ordinal.induction with | h i ih => rw [lfpApprox, lfpApprox] apply sSup_le simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, sSup_insert, forall_eq_or_imp, le_sup_left, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, true_and] intro i' h_lt apply le_sup_of_le_right apply le_sSup_of_le · use i' · apply le_trans (h _) simp only [OrderHom.toFun_eq_coe] exact g.monotone (ih i' h_lt) theorem lfpApprox_mono_mid : Monotone (lfpApprox f) := by intro x₁ x₂ h a induction a using Ordinal.induction with | h i ih => rw [lfpApprox, lfpApprox] apply sSup_le simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, sSup_insert, forall_eq_or_imp, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] constructor · exact le_sup_of_le_left h · intro i' h_i' apply le_sup_of_le_right apply le_sSup_of_le · use i' · exact f.monotone (ih i' h_i') /-- The approximations of the least fixed point stabilize at a fixed point of `f` -/ theorem lfpApprox_eq_of_mem_fixedPoints {a b : Ordinal} (h_init : x ≤ f x) (h_ab : a ≤ b) (h : lfpApprox f x a ∈ fixedPoints f) : lfpApprox f x b = lfpApprox f x a := by rw [mem_fixedPoints_iff] at h induction b using Ordinal.induction with | h b IH => apply le_antisymm · conv => left; rw [lfpApprox] apply sSup_le simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, forall_eq_or_imp, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] apply And.intro (le_lfpApprox f x) intro a' ha'b by_cases haa : a' < a · rw [← lfpApprox_add_one f x h_init] apply lfpApprox_monotone simp only [Ordinal.add_one_eq_succ, succ_le_iff] exact haa · rw [IH a' ha'b (le_of_not_lt haa), h] · exact lfpApprox_monotone f x h_ab /-- There are distinct indices smaller than the successor of the domain's cardinality yielding the same value -/ theorem exists_lfpApprox_eq_lfpApprox : ∃ a < ord <| succ #α, ∃ b < ord <| succ #α, a ≠ b ∧ lfpApprox f x a = lfpApprox f x b := by have h_ninj := not_injective_limitation_set <| lfpApprox f x rw [Set.injOn_iff_injective, Function.not_injective_iff] at h_ninj let ⟨a, b, h_fab, h_nab⟩ := h_ninj use a.val; apply And.intro a.prop use b.val; apply And.intro b.prop apply And.intro · intro h_eq; rw [Subtype.coe_inj] at h_eq; exact h_nab h_eq · exact h_fab /-- If the sequence of ordinal-indexed approximations takes a value twice, then it actually stabilised at that value. -/ lemma lfpApprox_mem_fixedPoints_of_eq {a b c : Ordinal} (h_init : x ≤ f x) (h_ab : a < b) (h_ac : a ≤ c) (h_fab : lfpApprox f x a = lfpApprox f x b) : lfpApprox f x c ∈ fixedPoints f := by have lfpApprox_mem_fixedPoint : lfpApprox f x a ∈ fixedPoints f := by rw [mem_fixedPoints_iff, ← lfpApprox_add_one f x h_init] exact Monotone.eq_of_le_of_le (lfpApprox_monotone f x) h_fab (SuccOrder.le_succ a) (SuccOrder.succ_le_of_lt h_ab) rw [lfpApprox_eq_of_mem_fixedPoints f x h_init] · exact lfpApprox_mem_fixedPoint · exact h_ac · exact lfpApprox_mem_fixedPoint /-- The approximation at the index of the successor of the domain's cardinality is a fixed point -/ theorem lfpApprox_ord_mem_fixedPoint (h_init : x ≤ f x) : lfpApprox f x (ord <| succ #α) ∈ fixedPoints f := by let ⟨a, h_a, b, h_b, h_nab, h_fab⟩ := exists_lfpApprox_eq_lfpApprox f x cases le_total a b with | inl h_ab => exact lfpApprox_mem_fixedPoints_of_eq f x h_init (h_nab.lt_of_le h_ab) (le_of_lt h_a) h_fab | inr h_ba => exact lfpApprox_mem_fixedPoints_of_eq f x h_init (h_nab.symm.lt_of_le h_ba) (le_of_lt h_b) (h_fab.symm) /-- Every value of the approximation is less or equal than every fixed point of `f` greater or equal than the initial value -/
theorem lfpApprox_le_of_mem_fixedPoints {a : α} (h_a : a ∈ fixedPoints f) (h_le_init : x ≤ a) (i : Ordinal) : lfpApprox f x i ≤ a := by induction i using Ordinal.induction with
Mathlib/SetTheory/Ordinal/FixedPointApproximants.lean
209
211
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.Algebra.Hom import Mathlib.RingTheory.Congruence.Basic import Mathlib.RingTheory.Ideal.Quotient.Defs import Mathlib.RingTheory.Ideal.Span /-! # Quotients of semirings In this file, we directly define the quotient of a semiring by any relation, by building a bigger relation that represents the ideal generated by that relation. We prove the universal properties of the quotient, and recommend avoiding relying on the actual definition, which is made irreducible for this purpose. Since everything runs in parallel for quotients of `R`-algebras, we do that case at the same time. -/ assert_not_exists Star.star universe uR uS uT uA u₄ variable {R : Type uR} [Semiring R] variable {S : Type uS} [CommSemiring S] variable {T : Type uT} variable {A : Type uA} [Semiring A] [Algebra S A] namespace RingCon instance (c : RingCon A) : Algebra S c.Quotient where smul := (· • ·) algebraMap := c.mk'.comp (algebraMap S A) commutes' _ := Quotient.ind' fun _ ↦ congr_arg Quotient.mk'' <| Algebra.commutes _ _ smul_def' _ := Quotient.ind' fun _ ↦ congr_arg Quotient.mk'' <| Algebra.smul_def _ _ @[simp, norm_cast] theorem coe_algebraMap (c : RingCon A) (s : S) : (algebraMap S A s : c.Quotient) = algebraMap S _ s := rfl end RingCon namespace RingQuot /-- Given an arbitrary relation `r` on a ring, we strengthen it to a relation `Rel r`, such that the equivalence relation generated by `Rel r` has `x ~ y` if and only if `x - y` is in the ideal generated by elements `a - b` such that `r a b`. -/ inductive Rel (r : R → R → Prop) : R → R → Prop | of ⦃x y : R⦄ (h : r x y) : Rel r x y | add_left ⦃a b c⦄ : Rel r a b → Rel r (a + c) (b + c) | mul_left ⦃a b c⦄ : Rel r a b → Rel r (a * c) (b * c) | mul_right ⦃a b c⦄ : Rel r b c → Rel r (a * b) (a * c) theorem Rel.add_right {r : R → R → Prop} ⦃a b c : R⦄ (h : Rel r b c) : Rel r (a + b) (a + c) := by rw [add_comm a b, add_comm a c] exact Rel.add_left h theorem Rel.neg {R : Type uR} [Ring R] {r : R → R → Prop} ⦃a b : R⦄ (h : Rel r a b) : Rel r (-a) (-b) := by simp only [neg_eq_neg_one_mul a, neg_eq_neg_one_mul b, Rel.mul_right h] theorem Rel.sub_left {R : Type uR} [Ring R] {r : R → R → Prop} ⦃a b c : R⦄ (h : Rel r a b) : Rel r (a - c) (b - c) := by simp only [sub_eq_add_neg, h.add_left] theorem Rel.sub_right {R : Type uR} [Ring R] {r : R → R → Prop} ⦃a b c : R⦄ (h : Rel r b c) : Rel r (a - b) (a - c) := by simp only [sub_eq_add_neg, h.neg.add_right] theorem Rel.smul {r : A → A → Prop} (k : S) ⦃a b : A⦄ (h : Rel r a b) : Rel r (k • a) (k • b) := by simp only [Algebra.smul_def, Rel.mul_right h] /-- `EqvGen (RingQuot.Rel r)` is a ring congruence. -/ def ringCon (r : R → R → Prop) : RingCon R where r := Relation.EqvGen (Rel r) iseqv := Relation.EqvGen.is_equivalence _ add' {a b c d} hab hcd := by induction hab generalizing c d with | rel _ _ hab => refine (Relation.EqvGen.rel _ _ hab.add_left).trans _ _ _ ?_ induction hcd with | rel _ _ hcd => exact Relation.EqvGen.rel _ _ hcd.add_right | refl => exact Relation.EqvGen.refl _ | symm _ _ _ h => exact h.symm _ _ | trans _ _ _ _ _ h h' => exact h.trans _ _ _ h' | refl => induction hcd with | rel _ _ hcd => exact Relation.EqvGen.rel _ _ hcd.add_right | refl => exact Relation.EqvGen.refl _ | symm _ _ _ h => exact h.symm _ _ | trans _ _ _ _ _ h h' => exact h.trans _ _ _ h' | symm x y _ hxy => exact (hxy hcd.symm).symm | trans x y z _ _ h h' => exact (h hcd).trans _ _ _ (h' <| Relation.EqvGen.refl _) mul' {a b c d} hab hcd := by induction hab generalizing c d with | rel _ _ hab => refine (Relation.EqvGen.rel _ _ hab.mul_left).trans _ _ _ ?_ induction hcd with | rel _ _ hcd => exact Relation.EqvGen.rel _ _ hcd.mul_right | refl => exact Relation.EqvGen.refl _ | symm _ _ _ h => exact h.symm _ _ | trans _ _ _ _ _ h h' => exact h.trans _ _ _ h' | refl => induction hcd with | rel _ _ hcd => exact Relation.EqvGen.rel _ _ hcd.mul_right | refl => exact Relation.EqvGen.refl _ | symm _ _ _ h => exact h.symm _ _ | trans _ _ _ _ _ h h' => exact h.trans _ _ _ h' | symm x y _ hxy => exact (hxy hcd.symm).symm | trans x y z _ _ h h' => exact (h hcd).trans _ _ _ (h' <| Relation.EqvGen.refl _) theorem eqvGen_rel_eq (r : R → R → Prop) : Relation.EqvGen (Rel r) = RingConGen.Rel r := by ext x₁ x₂ constructor · intro h induction h with | rel _ _ h => induction h with | of => exact RingConGen.Rel.of _ _ ‹_› | add_left _ h => exact h.add (RingConGen.Rel.refl _) | mul_left _ h => exact h.mul (RingConGen.Rel.refl _) | mul_right _ h => exact (RingConGen.Rel.refl _).mul h | refl => exact RingConGen.Rel.refl _ | symm => exact RingConGen.Rel.symm ‹_› | trans => exact RingConGen.Rel.trans ‹_› ‹_› · intro h induction h with | of => exact Relation.EqvGen.rel _ _ (Rel.of ‹_›) | refl => exact (RingQuot.ringCon r).refl _ | symm => exact (RingQuot.ringCon r).symm ‹_› | trans => exact (RingQuot.ringCon r).trans ‹_› ‹_› | add => exact (RingQuot.ringCon r).add ‹_› ‹_› | mul => exact (RingQuot.ringCon r).mul ‹_› ‹_› end RingQuot /-- The quotient of a ring by an arbitrary relation. -/ structure RingQuot (r : R → R → Prop) where toQuot : Quot (RingQuot.Rel r) namespace RingQuot variable (r : R → R → Prop) -- can't be irreducible, causes diamonds in ℕ-algebras private def natCast (n : ℕ) : RingQuot r := ⟨Quot.mk _ n⟩ private irreducible_def zero : RingQuot r := ⟨Quot.mk _ 0⟩ private irreducible_def one : RingQuot r := ⟨Quot.mk _ 1⟩ private irreducible_def add : RingQuot r → RingQuot r → RingQuot r | ⟨a⟩, ⟨b⟩ => ⟨Quot.map₂ (· + ·) Rel.add_right Rel.add_left a b⟩ private irreducible_def mul : RingQuot r → RingQuot r → RingQuot r | ⟨a⟩, ⟨b⟩ => ⟨Quot.map₂ (· * ·) Rel.mul_right Rel.mul_left a b⟩ private irreducible_def neg {R : Type uR} [Ring R] (r : R → R → Prop) : RingQuot r → RingQuot r | ⟨a⟩ => ⟨Quot.map (fun a ↦ -a) Rel.neg a⟩ private irreducible_def sub {R : Type uR} [Ring R] (r : R → R → Prop) : RingQuot r → RingQuot r → RingQuot r | ⟨a⟩, ⟨b⟩ => ⟨Quot.map₂ Sub.sub Rel.sub_right Rel.sub_left a b⟩ private irreducible_def npow (n : ℕ) : RingQuot r → RingQuot r | ⟨a⟩ => ⟨Quot.lift (fun a ↦ Quot.mk (RingQuot.Rel r) (a ^ n)) (fun a b (h : Rel r a b) ↦ by -- note we can't define a `Rel.pow` as `Rel` isn't reflexive so `Rel r 1 1` isn't true dsimp only induction n with | zero => rw [pow_zero, pow_zero] | succ n ih => simpa only [pow_succ, mul_def, Quot.map₂_mk, mk.injEq] using congr_arg₂ (fun x y ↦ mul r ⟨x⟩ ⟨y⟩) ih (Quot.sound h)) a⟩ -- note: this cannot be irreducible, as otherwise diamonds don't commute. private def smul [Algebra S R] (n : S) : RingQuot r → RingQuot r | ⟨a⟩ => ⟨Quot.map (fun a ↦ n • a) (Rel.smul n) a⟩ instance : NatCast (RingQuot r) := ⟨natCast r⟩ instance : Zero (RingQuot r) := ⟨zero r⟩ instance : One (RingQuot r) := ⟨one r⟩ instance : Add (RingQuot r) := ⟨add r⟩ instance : Mul (RingQuot r) := ⟨mul r⟩ instance : NatPow (RingQuot r) := ⟨fun x n ↦ npow r n x⟩ instance {R : Type uR} [Ring R] (r : R → R → Prop) : Neg (RingQuot r) := ⟨neg r⟩ instance {R : Type uR} [Ring R] (r : R → R → Prop) : Sub (RingQuot r) := ⟨sub r⟩ instance [Algebra S R] : SMul S (RingQuot r) := ⟨smul r⟩ theorem zero_quot : (⟨Quot.mk _ 0⟩ : RingQuot r) = 0 := show _ = zero r by rw [zero_def] theorem one_quot : (⟨Quot.mk _ 1⟩ : RingQuot r) = 1 := show _ = one r by rw [one_def] theorem add_quot {a b} : (⟨Quot.mk _ a⟩ + ⟨Quot.mk _ b⟩ : RingQuot r) = ⟨Quot.mk _ (a + b)⟩ := by show add r _ _ = _ rw [add_def] rfl theorem mul_quot {a b} : (⟨Quot.mk _ a⟩ * ⟨Quot.mk _ b⟩ : RingQuot r) = ⟨Quot.mk _ (a * b)⟩ := by show mul r _ _ = _ rw [mul_def] rfl theorem pow_quot {a} {n : ℕ} : (⟨Quot.mk _ a⟩ ^ n : RingQuot r) = ⟨Quot.mk _ (a ^ n)⟩ := by show npow r _ _ = _ rw [npow_def] theorem neg_quot {R : Type uR} [Ring R] (r : R → R → Prop) {a} : (-⟨Quot.mk _ a⟩ : RingQuot r) = ⟨Quot.mk _ (-a)⟩ := by show neg r _ = _ rw [neg_def] rfl theorem sub_quot {R : Type uR} [Ring R] (r : R → R → Prop) {a b} : (⟨Quot.mk _ a⟩ - ⟨Quot.mk _ b⟩ : RingQuot r) = ⟨Quot.mk _ (a - b)⟩ := by show sub r _ _ = _ rw [sub_def] rfl theorem smul_quot [Algebra S R] {n : S} {a : R} : (n • ⟨Quot.mk _ a⟩ : RingQuot r) = ⟨Quot.mk _ (n • a)⟩ := by show smul r _ _ = _ rw [smul] rfl instance instIsScalarTower [CommSemiring T] [SMul S T] [Algebra S R] [Algebra T R] [IsScalarTower S T R] : IsScalarTower S T (RingQuot r) := ⟨fun s t ⟨a⟩ => Quot.inductionOn a fun a' => by simp only [RingQuot.smul_quot, smul_assoc]⟩ instance instSMulCommClass [CommSemiring T] [Algebra S R] [Algebra T R] [SMulCommClass S T R] : SMulCommClass S T (RingQuot r) := ⟨fun s t ⟨a⟩ => Quot.inductionOn a fun a' => by simp only [RingQuot.smul_quot, smul_comm]⟩ instance instAddCommMonoid (r : R → R → Prop) : AddCommMonoid (RingQuot r) where add := (· + ·) zero := 0 add_assoc := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp only [add_quot, add_assoc] zero_add := by rintro ⟨⟨⟩⟩ simp [add_quot, ← zero_quot, zero_add] add_zero := by rintro ⟨⟨⟩⟩ simp only [add_quot, ← zero_quot, add_zero] add_comm := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp only [add_quot, add_comm] nsmul := (· • ·) nsmul_zero := by rintro ⟨⟨⟩⟩ simp only [smul_quot, zero_smul, zero_quot] nsmul_succ := by rintro n ⟨⟨⟩⟩ simp only [smul_quot, nsmul_eq_mul, Nat.cast_add, Nat.cast_one, add_mul, one_mul, add_comm, add_quot] instance instMonoidWithZero (r : R → R → Prop) : MonoidWithZero (RingQuot r) where mul_assoc := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp only [mul_quot, mul_assoc] one_mul := by rintro ⟨⟨⟩⟩ simp only [mul_quot, ← one_quot, one_mul] mul_one := by rintro ⟨⟨⟩⟩ simp only [mul_quot, ← one_quot, mul_one] zero_mul := by rintro ⟨⟨⟩⟩ simp only [mul_quot, ← zero_quot, zero_mul] mul_zero := by rintro ⟨⟨⟩⟩ simp only [mul_quot, ← zero_quot, mul_zero] npow n x := x ^ n npow_zero := by rintro ⟨⟨⟩⟩ simp only [pow_quot, ← one_quot, pow_zero] npow_succ := by rintro n ⟨⟨⟩⟩ simp only [pow_quot, mul_quot, pow_succ] instance instSemiring (r : R → R → Prop) : Semiring (RingQuot r) where natCast := natCast r natCast_zero := by simp [Nat.cast, natCast, ← zero_quot] natCast_succ := by simp [Nat.cast, natCast, ← one_quot, add_quot] left_distrib := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp only [mul_quot, add_quot, left_distrib] right_distrib := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp only [mul_quot, add_quot, right_distrib] nsmul := (· • ·) nsmul_zero := by rintro ⟨⟨⟩⟩ simp only [smul_quot, zero_smul, zero_quot] nsmul_succ := by rintro n ⟨⟨⟩⟩ simp only [smul_quot, nsmul_eq_mul, Nat.cast_add, Nat.cast_one, add_mul, one_mul, add_comm, add_quot] __ := instAddCommMonoid r __ := instMonoidWithZero r -- can't be irreducible, causes diamonds in ℤ-algebras private def intCast {R : Type uR} [Ring R] (r : R → R → Prop) (z : ℤ) : RingQuot r := ⟨Quot.mk _ z⟩ instance instRing {R : Type uR} [Ring R] (r : R → R → Prop) : Ring (RingQuot r) := { RingQuot.instSemiring r with neg := Neg.neg neg_add_cancel := by rintro ⟨⟨⟩⟩ simp [neg_quot, add_quot, ← zero_quot] sub := Sub.sub sub_eq_add_neg := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp [neg_quot, sub_quot, add_quot, sub_eq_add_neg] zsmul := (· • ·) zsmul_zero' := by rintro ⟨⟨⟩⟩ simp [smul_quot, ← zero_quot] zsmul_succ' := by rintro n ⟨⟨⟩⟩ simp [smul_quot, add_quot, add_mul, add_comm] zsmul_neg' := by rintro n ⟨⟨⟩⟩ simp [smul_quot, neg_quot, add_mul] intCast := intCast r intCast_ofNat := fun n => congrArg RingQuot.mk <| by exact congrArg (Quot.mk _) (Int.cast_natCast _) intCast_negSucc := fun n => congrArg RingQuot.mk <| by simp_rw [neg_def] exact congrArg (Quot.mk _) (Int.cast_negSucc n) } instance instCommSemiring {R : Type uR} [CommSemiring R] (r : R → R → Prop) : CommSemiring (RingQuot r) := { RingQuot.instSemiring r with mul_comm := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp [mul_quot, mul_comm] } instance {R : Type uR} [CommRing R] (r : R → R → Prop) : CommRing (RingQuot r) := { RingQuot.instCommSemiring r, RingQuot.instRing r with } instance instInhabited (r : R → R → Prop) : Inhabited (RingQuot r) := ⟨0⟩ instance instAlgebra [Algebra S R] (r : R → R → Prop) : Algebra S (RingQuot r) where smul := (· • ·) algebraMap := { toFun r := ⟨Quot.mk _ (algebraMap S R r)⟩ map_one' := by simp [← one_quot] map_mul' := by simp [mul_quot] map_zero' := by simp [← zero_quot] map_add' := by simp [add_quot] } commutes' r := by rintro ⟨⟨a⟩⟩ simp [Algebra.commutes, mul_quot] smul_def' r := by rintro ⟨⟨a⟩⟩ simp [smul_quot, Algebra.smul_def, mul_quot] /-- The quotient map from a ring to its quotient, as a homomorphism of rings. -/ irreducible_def mkRingHom (r : R → R → Prop) : R →+* RingQuot r := { toFun := fun x ↦ ⟨Quot.mk _ x⟩ map_one' := by simp [← one_quot] map_mul' := by simp [mul_quot] map_zero' := by simp [← zero_quot] map_add' := by simp [add_quot] } theorem mkRingHom_rel {r : R → R → Prop} {x y : R} (w : r x y) : mkRingHom r x = mkRingHom r y := by simp [mkRingHom_def, Quot.sound (Rel.of w)] theorem mkRingHom_surjective (r : R → R → Prop) : Function.Surjective (mkRingHom r) := by simp only [mkRingHom_def, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk] rintro ⟨⟨⟩⟩ simp @[ext 1100] theorem ringQuot_ext [NonAssocSemiring T] {r : R → R → Prop} (f g : RingQuot r →+* T) (w : f.comp (mkRingHom r) = g.comp (mkRingHom r)) : f = g := by ext x rcases mkRingHom_surjective r x with ⟨x, rfl⟩ exact (RingHom.congr_fun w x :) variable [Semiring T] irreducible_def preLift {r : R → R → Prop} {f : R →+* T} (h : ∀ ⦃x y⦄, r x y → f x = f y) : RingQuot r →+* T := { toFun := fun x ↦ Quot.lift f (by rintro _ _ r induction r with | of r => exact h r | add_left _ r' => rw [map_add, map_add, r'] | mul_left _ r' => rw [map_mul, map_mul, r'] | mul_right _ r' => rw [map_mul, map_mul, r']) x.toQuot map_zero' := by simp only [← zero_quot, f.map_zero] map_add' := by rintro ⟨⟨x⟩⟩ ⟨⟨y⟩⟩ simp only [add_quot, f.map_add x y] map_one' := by simp only [← one_quot, f.map_one] map_mul' := by rintro ⟨⟨x⟩⟩ ⟨⟨y⟩⟩ simp only [mul_quot, f.map_mul x y] } /-- Any ring homomorphism `f : R →+* T` which respects a relation `r : R → R → Prop` factors uniquely through a morphism `RingQuot r →+* T`. -/ irreducible_def lift {r : R → R → Prop} : { f : R →+* T // ∀ ⦃x y⦄, r x y → f x = f y } ≃ (RingQuot r →+* T) := { toFun := fun f ↦ preLift f.prop invFun := fun F ↦ ⟨F.comp (mkRingHom r), fun _ _ h ↦ congr_arg F (mkRingHom_rel h)⟩ left_inv := fun f ↦ by ext simp only [preLift_def, mkRingHom_def, RingHom.coe_comp, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, Function.comp_apply] right_inv := fun F ↦ by simp only [preLift_def] ext simp only [mkRingHom_def, RingHom.coe_comp, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, Function.comp_apply, forall_const] } @[simp] theorem lift_mkRingHom_apply (f : R →+* T) {r : R → R → Prop} (w : ∀ ⦃x y⦄, r x y → f x = f y) (x) : lift ⟨f, w⟩ (mkRingHom r x) = f x := by simp_rw [lift_def, preLift_def, mkRingHom_def] rfl -- note this is essentially `lift.symm_apply_eq.mp h` theorem lift_unique (f : R →+* T) {r : R → R → Prop} (w : ∀ ⦃x y⦄, r x y → f x = f y) (g : RingQuot r →+* T) (h : g.comp (mkRingHom r) = f) : g = lift ⟨f, w⟩ := by ext simp [h] theorem eq_lift_comp_mkRingHom {r : R → R → Prop} (f : RingQuot r →+* T) : f = lift ⟨f.comp (mkRingHom r), fun _ _ h ↦ congr_arg f (mkRingHom_rel h)⟩ := by conv_lhs => rw [← lift.apply_symm_apply f] rw [lift_def] rfl section CommRing /-! We now verify that in the case of a commutative ring, the `RingQuot` construction agrees with the quotient by the appropriate ideal. -/ variable {B : Type uR} [CommRing B] /-- The universal ring homomorphism from `RingQuot r` to `B ⧸ Ideal.ofRel r`. -/ def ringQuotToIdealQuotient (r : B → B → Prop) : RingQuot r →+* B ⧸ Ideal.ofRel r := lift ⟨Ideal.Quotient.mk (Ideal.ofRel r), fun x y h ↦ Ideal.Quotient.eq.2 <| Submodule.mem_sInf.mpr fun _ w ↦ w ⟨x, y, h, sub_add_cancel x y⟩⟩ @[simp] theorem ringQuotToIdealQuotient_apply (r : B → B → Prop) (x : B) : ringQuotToIdealQuotient r (mkRingHom r x) = Ideal.Quotient.mk (Ideal.ofRel r) x := by simp_rw [ringQuotToIdealQuotient, lift_def, preLift_def, mkRingHom_def] rfl /-- The universal ring homomorphism from `B ⧸ Ideal.ofRel r` to `RingQuot r`. -/ def idealQuotientToRingQuot (r : B → B → Prop) : B ⧸ Ideal.ofRel r →+* RingQuot r := Ideal.Quotient.lift (Ideal.ofRel r) (mkRingHom r) (by refine fun x h ↦ Submodule.span_induction ?_ ?_ ?_ ?_ h · rintro y ⟨a, b, h, su⟩ symm at su rw [← sub_eq_iff_eq_add] at su rw [← su, RingHom.map_sub, mkRingHom_rel h, sub_self] · simp · intro a b _ _ ha hb simp [ha, hb] · intro a x _ hx simp [hx]) @[simp] theorem idealQuotientToRingQuot_apply (r : B → B → Prop) (x : B) : idealQuotientToRingQuot r (Ideal.Quotient.mk _ x) = mkRingHom r x := rfl /-- The ring equivalence between `RingQuot r` and `(Ideal.ofRel r).quotient` -/ def ringQuotEquivIdealQuotient (r : B → B → Prop) : RingQuot r ≃+* B ⧸ Ideal.ofRel r := RingEquiv.ofHomInv (ringQuotToIdealQuotient r) (idealQuotientToRingQuot r) (by ext x simp_rw [ringQuotToIdealQuotient, lift_def, preLift_def, mkRingHom_def] change mkRingHom r x = _ rw [mkRingHom_def] rfl) (by ext x simp_rw [ringQuotToIdealQuotient, lift_def, preLift_def, mkRingHom_def] change Quot.lift _ _ ((mkRingHom r) x).toQuot = _ rw [mkRingHom_def] rfl) end CommRing section Algebra variable (S) /-- The quotient map from an `S`-algebra to its quotient, as a homomorphism of `S`-algebras. -/ irreducible_def mkAlgHom (s : A → A → Prop) : A →ₐ[S] RingQuot s := { mkRingHom s with commutes' := fun _ ↦ by simp [mkRingHom_def]; rfl } @[simp] theorem mkAlgHom_coe (s : A → A → Prop) : (mkAlgHom S s : A →+* RingQuot s) = mkRingHom s := by simp_rw [mkAlgHom_def, mkRingHom_def] rfl theorem mkAlgHom_rel {s : A → A → Prop} {x y : A} (w : s x y) : mkAlgHom S s x = mkAlgHom S s y := by simp [mkAlgHom_def, mkRingHom_def, Quot.sound (Rel.of w)] theorem mkAlgHom_surjective (s : A → A → Prop) : Function.Surjective (mkAlgHom S s) := by suffices Function.Surjective fun x ↦ (⟨.mk (Rel s) x⟩ : RingQuot s) by simpa [mkAlgHom_def, mkRingHom_def] rintro ⟨⟨a⟩⟩ use a variable {B : Type u₄} [Semiring B] [Algebra S B] @[ext 1100] theorem ringQuot_ext' {s : A → A → Prop} (f g : RingQuot s →ₐ[S] B) (w : f.comp (mkAlgHom S s) = g.comp (mkAlgHom S s)) : f = g := by ext x rcases mkAlgHom_surjective S s x with ⟨x, rfl⟩ exact AlgHom.congr_fun w x irreducible_def preLiftAlgHom {s : A → A → Prop} {f : A →ₐ[S] B} (h : ∀ ⦃x y⦄, s x y → f x = f y) : RingQuot s →ₐ[S] B := { toFun := fun x ↦ Quot.lift f (by rintro _ _ r induction r with | of r => exact h r | add_left _ r' => simp only [map_add, r'] | mul_left _ r' => simp only [map_mul, r'] | mul_right _ r' => simp only [map_mul, r']) x.toQuot map_zero' := by simp only [← zero_quot, map_zero] map_add' := by rintro ⟨⟨x⟩⟩ ⟨⟨y⟩⟩ simp only [add_quot, map_add _ x y] map_one' := by simp only [← one_quot, map_one] map_mul' := by rintro ⟨⟨x⟩⟩ ⟨⟨y⟩⟩ simp only [mul_quot, map_mul _ x y] commutes' := by rintro x simp [← one_quot, smul_quot, Algebra.algebraMap_eq_smul_one] } /-- Any `S`-algebra homomorphism `f : A →ₐ[S] B` which respects a relation `s : A → A → Prop` factors uniquely through a morphism `RingQuot s →ₐ[S] B`. -/ irreducible_def liftAlgHom {s : A → A → Prop} : { f : A →ₐ[S] B // ∀ ⦃x y⦄, s x y → f x = f y } ≃ (RingQuot s →ₐ[S] B) := { toFun := fun f' ↦ preLiftAlgHom _ f'.prop invFun := fun F ↦ ⟨F.comp (mkAlgHom S s), fun _ _ h ↦ congr_arg F (mkAlgHom_rel S h)⟩ left_inv := fun f ↦ by ext simp only [preLiftAlgHom_def, mkAlgHom_def, mkRingHom_def, RingHom.toMonoidHom_eq_coe, RingHom.coe_monoidHom_mk, AlgHom.coe_comp, AlgHom.coe_mk, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, Function.comp_apply] right_inv := fun F ↦ by ext
simp only [preLiftAlgHom_def, mkAlgHom_def, mkRingHom_def, RingHom.toMonoidHom_eq_coe, RingHom.coe_monoidHom_mk, AlgHom.coe_comp, AlgHom.coe_mk, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, Function.comp_apply] } @[simp]
Mathlib/Algebra/RingQuot.lean
599
603
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.AlgebraicTopology.DoldKan.Faces import Mathlib.CategoryTheory.Idempotents.Basic /-! # Construction of projections for the Dold-Kan correspondence In this file, we construct endomorphisms `P q : K[X] ⟶ K[X]` for all `q : ℕ`. We study how they behave with respect to face maps with the lemmas `HigherFacesVanish.of_P`, `HigherFacesVanish.comp_P_eq_self` and `comp_P_eq_self_iff`. Then, we show that they are projections (see `P_f_idem` and `P_idem`). They are natural transformations (see `natTransP` and `P_f_naturality`) and are compatible with the application of additive functors (see `map_P`). By passing to the limit, these endomorphisms `P q` shall be used in `PInfty.lean` in order to define `PInfty : K[X] ⟶ K[X]`. (See `Equivalence.lean` for the general strategy of proof of the Dold-Kan equivalence.) -/ open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Preadditive CategoryTheory.SimplicialObject Opposite CategoryTheory.Idempotents open Simplicial DoldKan noncomputable section namespace AlgebraicTopology namespace DoldKan variable {C : Type*} [Category C] [Preadditive C] {X : SimplicialObject C} /-- This is the inductive definition of the projections `P q : K[X] ⟶ K[X]`, with `P 0 := 𝟙 _` and `P (q+1) := P q ≫ (𝟙 _ + Hσ q)`. -/ noncomputable def P : ℕ → (K[X] ⟶ K[X]) | 0 => 𝟙 _ | q + 1 => P q ≫ (𝟙 _ + Hσ q) lemma P_zero : (P 0 : K[X] ⟶ K[X]) = 𝟙 _ := rfl lemma P_succ (q : ℕ) : (P (q+1) : K[X] ⟶ K[X]) = P q ≫ (𝟙 _ + Hσ q) := rfl /-- All the `P q` coincide with `𝟙 _` in degree 0. -/ @[simp] theorem P_f_0_eq (q : ℕ) : ((P q).f 0 : X _⦋0⦌ ⟶ X _⦋0⦌) = 𝟙 _ := by induction' q with q hq · rfl · simp only [P_succ, HomologicalComplex.add_f_apply, HomologicalComplex.comp_f, HomologicalComplex.id_f, id_comp, hq, Hσ_eq_zero, add_zero] /-- `Q q` is the complement projection associated to `P q` -/ def Q (q : ℕ) : K[X] ⟶ K[X] := 𝟙 _ - P q theorem P_add_Q (q : ℕ) : P q + Q q = 𝟙 K[X] := by rw [Q] abel theorem P_add_Q_f (q n : ℕ) : (P q).f n + (Q q).f n = 𝟙 (X _⦋n⦌) := HomologicalComplex.congr_hom (P_add_Q q) n @[simp] theorem Q_zero : (Q 0 : K[X] ⟶ _) = 0 := sub_self _ theorem Q_succ (q : ℕ) : (Q (q + 1) : K[X] ⟶ _) = Q q - P q ≫ Hσ q := by simp only [Q, P_succ, comp_add, comp_id] abel /-- All the `Q q` coincide with `0` in degree 0. -/ @[simp] theorem Q_f_0_eq (q : ℕ) : ((Q q).f 0 : X _⦋0⦌ ⟶ X _⦋0⦌) = 0 := by simp only [HomologicalComplex.sub_f_apply, HomologicalComplex.id_f, Q, P_f_0_eq, sub_self] namespace HigherFacesVanish /-- This lemma expresses the vanishing of `(P q).f (n+1) ≫ X.δ k : X _⦋n+1⦌ ⟶ X _⦋n⦌` when `k≠0` and `k≥n-q+2` -/ theorem of_P : ∀ q n : ℕ, HigherFacesVanish q ((P q).f (n + 1) : X _⦋n + 1⦌ ⟶ X _⦋n + 1⦌) | 0 => fun n j hj₁ => by omega | q + 1 => fun n => by simp only [P_succ] exact (of_P q n).induction @[reassoc] theorem comp_P_eq_self {Y : C} {n q : ℕ} {φ : Y ⟶ X _⦋n + 1⦌} (v : HigherFacesVanish q φ) : φ ≫ (P q).f (n + 1) = φ := by induction' q with q hq · simp only [P_zero] apply comp_id · simp only [P_succ, comp_add, HomologicalComplex.comp_f, HomologicalComplex.add_f_apply, comp_id, ← assoc, hq v.of_succ, add_eq_left] by_cases hqn : n < q · exact v.of_succ.comp_Hσ_eq_zero hqn · obtain ⟨a, ha⟩ := Nat.le.dest (not_lt.mp hqn) have hnaq : n = a + q := by omega simp only [v.of_succ.comp_Hσ_eq hnaq, neg_eq_zero, ← assoc] have eq := v ⟨a, by omega⟩ (by simp only [hnaq, Nat.succ_eq_add_one, add_assoc] rfl) simp only [Fin.succ_mk] at eq simp only [eq, zero_comp] end HigherFacesVanish theorem comp_P_eq_self_iff {Y : C} {n q : ℕ} {φ : Y ⟶ X _⦋n + 1⦌} : φ ≫ (P q).f (n + 1) = φ ↔ HigherFacesVanish q φ := by constructor · intro hφ rw [← hφ] apply HigherFacesVanish.of_comp apply HigherFacesVanish.of_P · exact HigherFacesVanish.comp_P_eq_self @[reassoc (attr := simp)] theorem P_f_idem (q n : ℕ) : ((P q).f n : X _⦋n⦌ ⟶ _) ≫ (P q).f n = (P q).f n := by rcases n with (_|n) · rw [P_f_0_eq q, comp_id] · exact (HigherFacesVanish.of_P q n).comp_P_eq_self @[reassoc (attr := simp)] theorem Q_f_idem (q n : ℕ) : ((Q q).f n : X _⦋n⦌ ⟶ _) ≫ (Q q).f n = (Q q).f n := idem_of_id_sub_idem _ (P_f_idem q n) @[reassoc (attr := simp)] theorem P_idem (q : ℕ) : (P q : K[X] ⟶ K[X]) ≫ P q = P q := by ext n exact P_f_idem q n
@[reassoc (attr := simp)] theorem Q_idem (q : ℕ) : (Q q : K[X] ⟶ K[X]) ≫ Q q = Q q := by ext n exact Q_f_idem q n /-- For each `q`, `P q` is a natural transformation. -/ @[simps] def natTransP (q : ℕ) : alternatingFaceMapComplex C ⟶ alternatingFaceMapComplex C where
Mathlib/AlgebraicTopology/DoldKan/Projections.lean
140
147
/- 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'
Mathlib/Analysis/BoxIntegral/Partition/Basic.lean
495
496
/- 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,368
2,372
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang, Joël Riou -/ import Mathlib.CategoryTheory.Adjunction.Restrict import Mathlib.CategoryTheory.Functor.KanExtension.Adjunction import Mathlib.CategoryTheory.Sites.Continuous import Mathlib.CategoryTheory.Sites.Sheafification /-! # Cocontinuous functors between sites. We define cocontinuous functors between sites as functors that pull covering sieves back to covering sieves. This concept is also known as *cover-lifting* or *cover-reflecting functors*. We use the original terminology and definition of SGA 4 III 2.1. However, the notion of cocontinuous functor should not be confused with the general definition of cocontinuous functors between categories as functors preserving small colimits. ## Main definitions * `CategoryTheory.Functor.IsCocontinuous`: a functor between sites is cocontinuous if it pulls back covering sieves to covering sieves * `CategoryTheory.Functor.sheafPushforwardCocontinuous`: A cocontinuous functor `G : (C, J) ⥤ (D, K)` induces a functor `Sheaf J A ⥤ Sheaf K A`. ## Main results * `CategoryTheory.ran_isSheaf_of_isCocontinuous`: If `G : C ⥤ D` is cocontinuous, then `G.op.ran` (`ₚu`) as a functor `(Cᵒᵖ ⥤ A) ⥤ (Dᵒᵖ ⥤ A)` of presheaves maps sheaves to sheaves. * `CategoryTheory.Functor.sheafAdjunctionCocontinuous`: If `G : (C, J) ⥤ (D, K)` is cocontinuous and continuous, then `G.sheafPushforwardContinuous A J K` and `G.sheafPushforwardCocontinuous A J K` are adjoint. ## References * [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.3. * [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92] * https://stacks.math.columbia.edu/tag/00XI -/ universe w' w v v₁ v₂ v₃ u u₁ u₂ u₃ noncomputable section open CategoryTheory open Opposite open CategoryTheory.Presieve.FamilyOfElements open CategoryTheory.Presieve open CategoryTheory.Limits namespace CategoryTheory section IsCocontinuous variable {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] (G : C ⥤ D) (G' : D ⥤ E) variable (J : GrothendieckTopology C) (K : GrothendieckTopology D) variable {L : GrothendieckTopology E} /-- A functor `G : (C, J) ⥤ (D, K)` between sites is called cocontinuous (SGA 4 III 2.1) if for all covering sieves `R` in `D`, `R.pullback G` is a covering sieve in `C`. -/ class Functor.IsCocontinuous : Prop where cover_lift : ∀ {U : C} {S : Sieve (G.obj U)} (_ : S ∈ K (G.obj U)), S.functorPullback G ∈ J U lemma Functor.cover_lift [G.IsCocontinuous J K] {U : C} {S : Sieve (G.obj U)} (hS : S ∈ K (G.obj U)) : S.functorPullback G ∈ J U := IsCocontinuous.cover_lift hS /-- The identity functor on a site is cocontinuous. -/ instance isCocontinuous_id : Functor.IsCocontinuous (𝟭 C) J J := ⟨fun h => by simpa using h⟩ /-- The composition of two cocontinuous functors is cocontinuous. -/ theorem isCocontinuous_comp [G.IsCocontinuous J K] [G'.IsCocontinuous K L] : (G ⋙ G').IsCocontinuous J L where cover_lift h := G.cover_lift J K (G'.cover_lift K L h) end IsCocontinuous /-! We will now prove that `G.op.ran : (Cᵒᵖ ⥤ A) ⥤ (Dᵒᵖ ⥤ A)` maps sheaves to sheaves when `G : C ⥤ D` is a cocontinuous functor. We do not follow the proofs in SGA 4 III 2.2 or <https://stacks.math.columbia.edu/tag/00XK>. Instead, we verify as directly as possible that if `F : Cᵒᵖ ⥤ A` is a sheaf, then `G.op.ran.obj F` is a sheaf. in order to do this, we use the "multifork" characterization of sheaves which involves limits in the category `A`. As `G.op.ran.obj F` is the chosen right Kan extension of `F` along `G.op : Cᵒᵖ ⥤ Dᵒᵖ`, we actually verify that any pointwise right Kan extension of `F` along `G.op` is a sheaf. -/ variable {C D : Type*} [Category C] [Category D] (G : C ⥤ D) variable {A : Type w} [Category.{w'} A] variable {J : GrothendieckTopology C} {K : GrothendieckTopology D} [G.IsCocontinuous J K] namespace RanIsSheafOfIsCocontinuous variable {G} variable {F : Cᵒᵖ ⥤ A} (hF : Presheaf.IsSheaf J F) variable {R : Dᵒᵖ ⥤ A} (α : G.op ⋙ R ⟶ F) variable (hR : (Functor.RightExtension.mk _ α).IsPointwiseRightKanExtension) variable {X : D} {S : K.Cover X} (s : Multifork (S.index R)) /-- Auxiliary definition for `lift`. -/ def liftAux {Y : C} (f : G.obj Y ⟶ X) : s.pt ⟶ F.obj (op Y) := Multifork.IsLimit.lift (hF.isLimitMultifork ⟨_, G.cover_lift J K (K.pullback_stable f S.2)⟩) (fun k ↦ s.ι (⟨_, G.map k.f ≫ f, k.hf⟩) ≫ α.app (op k.Y)) (by intro { fst := ⟨Y₁, p₁, hp₁⟩, snd := ⟨Y₂, p₂, hp₂⟩, r := ⟨W, g₁, g₂, w⟩ } dsimp at g₁ g₂ w ⊢ simp only [Category.assoc, ← α.naturality, Functor.comp_map, Functor.op_map, Quiver.Hom.unop_op] apply s.condition_assoc { fst.hf := hp₁ snd.hf := hp₂ r.g₁ := G.map g₁ r.g₂ := G.map g₂ r.w := by simpa using G.congr_map w =≫ f .. }) lemma liftAux_map {Y : C} (f : G.obj Y ⟶ X) {W : C} (g : W ⟶ Y) (i : S.Arrow) (h : G.obj W ⟶ i.Y) (w : h ≫ i.f = G.map g ≫ f) : liftAux hF α s f ≫ F.map g.op = s.ι i ≫ R.map h.op ≫ α.app _ := (Multifork.IsLimit.fac (hF.isLimitMultifork ⟨_, G.cover_lift J K (K.pullback_stable f S.2)⟩) _ _ ⟨W, g, by simpa only [Sieve.functorPullback_apply, functorPullback_mem, Sieve.pullback_apply, ← w] using S.1.downward_closed i.hf h⟩).trans (by dsimp simp only [← Category.assoc] congr 1 let r : S.Relation := { fst.f := G.map g ≫ f fst.hf := by simpa only [← w] using S.1.downward_closed i.hf h snd := i r.g₁ := 𝟙 _ r.g₂ := h r.w := by simpa using w.symm .. } simpa [r] using s.condition r ) lemma liftAux_map' {Y Y' : C} (f : G.obj Y ⟶ X) (f' : G.obj Y' ⟶ X) {W : C} (a : W ⟶ Y) (b : W ⟶ Y') (w : G.map a ≫ f = G.map b ≫ f') : liftAux hF α s f ≫ F.map a.op = liftAux hF α s f' ≫ F.map b.op := by apply hF.hom_ext ⟨_, G.cover_lift J K (K.pullback_stable (G.map a ≫ f) S.2)⟩ rintro ⟨T, g, hg⟩ dsimp have eq₁ := liftAux_map hF α s f (g ≫ a) ⟨_, _, hg⟩ (𝟙 _) (by simp) have eq₂ := liftAux_map hF α s f' (g ≫ b) ⟨_, _, hg⟩ (𝟙 _) (by simp [w]) dsimp at eq₁ eq₂ simp only [Functor.map_comp, Functor.map_id, Category.id_comp] at eq₁ eq₂ simp only [Category.assoc, eq₁, eq₂] variable {α} /-- Auxiliary definition for `isLimitMultifork` -/ def lift : s.pt ⟶ R.obj (op X) := (hR (op X)).lift (Cone.mk _ { app := fun j ↦ liftAux hF α s j.hom.unop naturality := fun j j' φ ↦ by simpa using liftAux_map' hF α s j'.hom.unop j.hom.unop (𝟙 _) φ.right.unop (Quiver.Hom.op_inj (by simpa using (StructuredArrow.w φ).symm)) }) lemma fac' (j : StructuredArrow (op X) G.op) : lift hF hR s ≫ R.map j.hom ≫ α.app j.right = liftAux hF α s j.hom.unop := by apply IsLimit.fac @[reassoc (attr := simp)] lemma fac (i : S.Arrow) : lift hF hR s ≫ R.map i.f.op = s.ι i := by apply (hR (op i.Y)).hom_ext intro j have eq := fac' hF hR s (StructuredArrow.mk (i.f.op ≫ j.hom)) dsimp at eq ⊢ simp only [Functor.map_comp, Category.assoc] at eq rw [Category.assoc, eq] simpa using liftAux_map hF α s (j.hom.unop ≫ i.f) (𝟙 _) i j.hom.unop (by simp) include hR hF in variable (K) in lemma hom_ext {W : A} {f g : W ⟶ R.obj (op X)} (h : ∀ (i : S.Arrow), f ≫ R.map i.f.op = g ≫ R.map i.f.op) : f = g := by apply (hR (op X)).hom_ext intro j apply hF.hom_ext ⟨_, G.cover_lift J K (K.pullback_stable j.hom.unop S.2)⟩ intro ⟨W, i, hi⟩ have eq := h (GrothendieckTopology.Cover.Arrow.mk _ (G.map i ≫ j.hom.unop) hi) dsimp at eq ⊢ simp only [Category.assoc, ← NatTrans.naturality, Functor.comp_map, ← Functor.map_comp_assoc, Functor.op_map, Quiver.Hom.unop_op] rw [reassoc_of% eq] variable (S) /-- Auxiliary definition for `ran_isSheaf_of_isCocontinuous` -/ def isLimitMultifork : IsLimit (S.multifork R) := Multifork.IsLimit.mk _ (lift hF hR) (fac hF hR) (fun s _ hm ↦ hom_ext K hF hR (fun i ↦ (hm i).trans (fac hF hR s i).symm)) end RanIsSheafOfIsCocontinuous variable (K) variable [∀ (F : Cᵒᵖ ⥤ A), G.op.HasPointwiseRightKanExtension F] /-- If `G` is cocontinuous, then `G.op.ran` pushes sheaves to sheaves. This is SGA 4 III 2.2. -/ @[stacks 00XK "Alternative reference. There, results are obtained under the additional assumption that `C` and `D` have pullbacks."] theorem ran_isSheaf_of_isCocontinuous (ℱ : Sheaf J A) :
Presheaf.IsSheaf K (G.op.ran.obj ℱ.val) := by rw [Presheaf.isSheaf_iff_multifork] intros X S exact ⟨RanIsSheafOfIsCocontinuous.isLimitMultifork ℱ.2 (G.op.isPointwiseRightKanExtensionRanCounit ℱ.val) S⟩ variable (A J) /-- A cocontinuous functor induces a pushforward functor on categories of sheaves. -/ def Functor.sheafPushforwardCocontinuous : Sheaf J A ⥤ Sheaf K A where obj ℱ := ⟨G.op.ran.obj ℱ.val, ran_isSheaf_of_isCocontinuous _ K ℱ⟩ map f := ⟨G.op.ran.map f.val⟩ map_id ℱ := Sheaf.Hom.ext <| (ran G.op).map_id ℱ.val map_comp f g := Sheaf.Hom.ext <| (ran G.op).map_comp f.val g.val /-- `G.sheafPushforwardCocontinuous A J K : Sheaf J A ⥤ Sheaf K A` is induced by the right Kan extension functor `G.op.ran` on presheaves. -/ @[simps! hom inv] def Functor.sheafPushforwardCocontinuousCompSheafToPresheafIso : G.sheafPushforwardCocontinuous A J K ⋙ sheafToPresheaf K A ≅ sheafToPresheaf J A ⋙ G.op.ran := Iso.refl _ /-
Mathlib/CategoryTheory/Sites/CoverLifting.lean
218
241
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.Topology.Category.Profinite.Nobeling.Basic import Mathlib.Topology.Category.Profinite.Nobeling.Induction import Mathlib.Topology.Category.Profinite.Nobeling.Span import Mathlib.Topology.Category.Profinite.Nobeling.Successor import Mathlib.Topology.Category.Profinite.Nobeling.ZeroLimit deprecated_module (since := "2025-04-13")
Mathlib/Topology/Category/Profinite/Nobeling.lean
1,174
1,177
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo, Yury Kudryashov, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Algebra.Module.Opposite import Mathlib.Topology.Algebra.Group.Quotient import Mathlib.Topology.Algebra.Ring.Basic import Mathlib.Topology.UniformSpace.UniformEmbedding import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Quotient.Defs /-! # Theory of topological modules We use the class `ContinuousSMul` for topological (semi) modules and topological vector spaces. -/ assert_not_exists Star.star open LinearMap (ker range) open Topology Filter Pointwise universe u v w u' section variable {R : Type*} {M : Type*} [Ring R] [TopologicalSpace R] [TopologicalSpace M] [AddCommGroup M] [Module R M] theorem ContinuousSMul.of_nhds_zero [IsTopologicalRing R] [IsTopologicalAddGroup M] (hmul : Tendsto (fun p : R × M => p.1 • p.2) (𝓝 0 ×ˢ 𝓝 0) (𝓝 0)) (hmulleft : ∀ m : M, Tendsto (fun a : R => a • m) (𝓝 0) (𝓝 0)) (hmulright : ∀ a : R, Tendsto (fun m : M => a • m) (𝓝 0) (𝓝 0)) : ContinuousSMul R M where continuous_smul := by rw [← nhds_prod_eq] at hmul refine continuous_of_continuousAt_zero₂ (AddMonoidHom.smul : R →+ M →+ M) ?_ ?_ ?_ <;> simpa [ContinuousAt] variable (R M) in omit [TopologicalSpace R] in /-- A topological module over a ring has continuous negation. This cannot be an instance, because it would cause search for `[Module ?R M]` with unknown `R`. -/ theorem ContinuousNeg.of_continuousConstSMul [ContinuousConstSMul R M] : ContinuousNeg M where continuous_neg := by simpa using continuous_const_smul (T := M) (-1 : R) end section variable {R : Type*} {M : Type*} [Ring R] [TopologicalSpace R] [TopologicalSpace M] [AddCommGroup M] [ContinuousAdd M] [Module R M] [ContinuousSMul R M] /-- If `M` is a topological module over `R` and `0` is a limit of invertible elements of `R`, then `⊤` is the only submodule of `M` with a nonempty interior. This is the case, e.g., if `R` is a nontrivially normed field. -/ theorem Submodule.eq_top_of_nonempty_interior' [NeBot (𝓝[{ x : R | IsUnit x }] 0)] (s : Submodule R M) (hs : (interior (s : Set M)).Nonempty) : s = ⊤ := by rcases hs with ⟨y, hy⟩ refine Submodule.eq_top_iff'.2 fun x => ?_ rw [mem_interior_iff_mem_nhds] at hy have : Tendsto (fun c : R => y + c • x) (𝓝[{ x : R | IsUnit x }] 0) (𝓝 (y + (0 : R) • x)) := tendsto_const_nhds.add ((tendsto_nhdsWithin_of_tendsto_nhds tendsto_id).smul tendsto_const_nhds) rw [zero_smul, add_zero] at this obtain ⟨_, hu : y + _ • _ ∈ s, u, rfl⟩ := nonempty_of_mem (inter_mem (Filter.mem_map.1 (this hy)) self_mem_nhdsWithin) have hy' : y ∈ ↑s := mem_of_mem_nhds hy rwa [s.add_mem_iff_right hy', ← Units.smul_def, s.smul_mem_iff' u] at hu variable (R M) /-- Let `R` be a topological ring such that zero is not an isolated point (e.g., a nontrivially normed field, see `NormedField.punctured_nhds_neBot`). Let `M` be a nontrivial module over `R` such that `c • x = 0` implies `c = 0 ∨ x = 0`. Then `M` has no isolated points. We formulate this using `NeBot (𝓝[≠] x)`. This lemma is not an instance because Lean would need to find `[ContinuousSMul ?m_1 M]` with unknown `?m_1`. We register this as an instance for `R = ℝ` in `Real.punctured_nhds_module_neBot`. One can also use `haveI := Module.punctured_nhds_neBot R M` in a proof. -/ theorem Module.punctured_nhds_neBot [Nontrivial M] [NeBot (𝓝[≠] (0 : R))] [NoZeroSMulDivisors R M] (x : M) : NeBot (𝓝[≠] x) := by rcases exists_ne (0 : M) with ⟨y, hy⟩ suffices Tendsto (fun c : R => x + c • y) (𝓝[≠] 0) (𝓝[≠] x) from this.neBot refine Tendsto.inf ?_ (tendsto_principal_principal.2 <| ?_) · convert tendsto_const_nhds.add ((@tendsto_id R _).smul_const y) rw [zero_smul, add_zero] · intro c hc simpa [hy] using hc end section LatticeOps variable {R M₁ M₂ : Type*} [SMul R M₁] [SMul R M₂] [u : TopologicalSpace R] {t : TopologicalSpace M₂} [ContinuousSMul R M₂] {F : Type*} [FunLike F M₁ M₂] [MulActionHomClass F R M₁ M₂] (f : F) theorem continuousSMul_induced : @ContinuousSMul R M₁ _ u (t.induced f) := let _ : TopologicalSpace M₁ := t.induced f IsInducing.continuousSMul ⟨rfl⟩ continuous_id (map_smul f _ _) end LatticeOps /-- The span of a separable subset with respect to a separable scalar ring is again separable. -/ lemma TopologicalSpace.IsSeparable.span {R M : Type*} [AddCommMonoid M] [Semiring R] [Module R M] [TopologicalSpace M] [TopologicalSpace R] [SeparableSpace R] [ContinuousAdd M] [ContinuousSMul R M] {s : Set M} (hs : IsSeparable s) : IsSeparable (Submodule.span R s : Set M) := by rw [Submodule.span_eq_iUnion_nat] refine .iUnion fun n ↦ .image ?_ ?_ · have : IsSeparable {f : Fin n → R × M | ∀ (i : Fin n), f i ∈ Set.univ ×ˢ s} := by apply isSeparable_pi (fun i ↦ .prod (.of_separableSpace Set.univ) hs) rwa [Set.univ_prod] at this · apply continuous_finset_sum _ (fun i _ ↦ ?_) exact (continuous_fst.comp (continuous_apply i)).smul (continuous_snd.comp (continuous_apply i)) namespace Submodule instance topologicalAddGroup {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [TopologicalSpace M] [IsTopologicalAddGroup M] (S : Submodule R M) : IsTopologicalAddGroup S := inferInstanceAs (IsTopologicalAddGroup S.toAddSubgroup) end Submodule section closure variable {R : Type u} {M : Type v} [Semiring R] [TopologicalSpace M] [AddCommMonoid M] [Module R M] [ContinuousConstSMul R M] theorem Submodule.mapsTo_smul_closure (s : Submodule R M) (c : R) : Set.MapsTo (c • ·) (closure s : Set M) (closure s) := have : Set.MapsTo (c • ·) (s : Set M) s := fun _ h ↦ s.smul_mem c h this.closure (continuous_const_smul c) theorem Submodule.smul_closure_subset (s : Submodule R M) (c : R) : c • closure (s : Set M) ⊆ closure (s : Set M) := (s.mapsTo_smul_closure c).image_subset variable [ContinuousAdd M] /-- The (topological-space) closure of a submodule of a topological `R`-module `M` is itself a submodule. -/ def Submodule.topologicalClosure (s : Submodule R M) : Submodule R M := { s.toAddSubmonoid.topologicalClosure with smul_mem' := s.mapsTo_smul_closure } @[simp, norm_cast] theorem Submodule.topologicalClosure_coe (s : Submodule R M) : (s.topologicalClosure : Set M) = closure (s : Set M) := rfl theorem Submodule.le_topologicalClosure (s : Submodule R M) : s ≤ s.topologicalClosure := subset_closure theorem Submodule.closure_subset_topologicalClosure_span (s : Set M) : closure s ⊆ (span R s).topologicalClosure := by rw [Submodule.topologicalClosure_coe] exact closure_mono subset_span theorem Submodule.isClosed_topologicalClosure (s : Submodule R M) : IsClosed (s.topologicalClosure : Set M) := isClosed_closure theorem Submodule.topologicalClosure_minimal (s : Submodule R M) {t : Submodule R M} (h : s ≤ t) (ht : IsClosed (t : Set M)) : s.topologicalClosure ≤ t := closure_minimal h ht theorem Submodule.topologicalClosure_mono {s : Submodule R M} {t : Submodule R M} (h : s ≤ t) : s.topologicalClosure ≤ t.topologicalClosure := closure_mono h /-- The topological closure of a closed submodule `s` is equal to `s`. -/ theorem IsClosed.submodule_topologicalClosure_eq {s : Submodule R M} (hs : IsClosed (s : Set M)) : s.topologicalClosure = s := SetLike.ext' hs.closure_eq /-- A subspace is dense iff its topological closure is the entire space. -/ theorem Submodule.dense_iff_topologicalClosure_eq_top {s : Submodule R M} : Dense (s : Set M) ↔ s.topologicalClosure = ⊤ := by rw [← SetLike.coe_set_eq, dense_iff_closure_eq] simp instance Submodule.topologicalClosure.completeSpace {M' : Type*} [AddCommMonoid M'] [Module R M'] [UniformSpace M'] [ContinuousAdd M'] [ContinuousConstSMul R M'] [CompleteSpace M'] (U : Submodule R M') : CompleteSpace U.topologicalClosure := isClosed_closure.completeSpace_coe /-- A maximal proper subspace of a topological module (i.e a `Submodule` satisfying `IsCoatom`) is either closed or dense. -/ theorem Submodule.isClosed_or_dense_of_isCoatom (s : Submodule R M) (hs : IsCoatom s) : IsClosed (s : Set M) ∨ Dense (s : Set M) := by refine (hs.le_iff.mp s.le_topologicalClosure).symm.imp ?_ dense_iff_topologicalClosure_eq_top.mpr exact fun h ↦ h ▸ isClosed_closure end closure namespace Submodule variable {ι R : Type*} {M : ι → Type*} [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] [∀ i, TopologicalSpace (M i)] [DecidableEq ι] /-- If `s i` is a family of submodules, each is in its module, then the closure of their span in the indexed product of the modules is the product of their closures. In case of a finite index type, this statement immediately follows from `Submodule.iSup_map_single`. However, the statement is true for an infinite index type as well. -/ theorem closure_coe_iSup_map_single (s : ∀ i, Submodule R (M i)) : closure (↑(⨆ i, (s i).map (LinearMap.single R M i)) : Set (∀ i, M i)) = Set.univ.pi fun i ↦ closure (s i) := by rw [← closure_pi_set] refine (closure_mono ?_).antisymm <| closure_minimal ?_ isClosed_closure · exact SetLike.coe_mono <| iSup_map_single_le · simp only [Set.subset_def, mem_closure_iff] intro x hx U hU hxU rcases isOpen_pi_iff.mp hU x hxU with ⟨t, V, hV, hVU⟩ refine ⟨∑ i ∈ t, Pi.single i (x i), hVU ?_, ?_⟩ · simp_all [Finset.sum_pi_single] · exact sum_mem fun i hi ↦ mem_iSup_of_mem i <| mem_map_of_mem <| hx _ <| Set.mem_univ _ /-- If `s i` is a family of submodules, each is in its module, then the closure of their span in the indexed product of the modules is the product of their closures. In case of a finite index type, this statement immediately follows from `Submodule.iSup_map_single`. However, the statement is true for an infinite index type as well. This version is stated in terms of `Submodule.topologicalClosure`, thus assumes that `M i`s are topological modules over `R`. However, the statement is true without assuming continuity of the operations, see `Submodule.closure_coe_iSup_map_single` above. -/ theorem topologicalClosure_iSup_map_single [∀ i, ContinuousAdd (M i)] [∀ i, ContinuousConstSMul R (M i)] (s : ∀ i, Submodule R (M i)) : topologicalClosure (⨆ i, (s i).map (LinearMap.single R M i)) = pi Set.univ fun i ↦ (s i).topologicalClosure := SetLike.coe_injective <| closure_coe_iSup_map_single _ end Submodule section Pi theorem LinearMap.continuous_on_pi {ι : Type*} {R : Type*} {M : Type*} [Finite ι] [Semiring R] [TopologicalSpace R] [AddCommMonoid M] [Module R M] [TopologicalSpace M] [ContinuousAdd M] [ContinuousSMul R M] (f : (ι → R) →ₗ[R] M) : Continuous f := by cases nonempty_fintype ι classical -- for the proof, write `f` in the standard basis, and use that each coordinate is a continuous -- function. have : (f : (ι → R) → M) = fun x => ∑ i : ι, x i • f fun j => if i = j then 1 else 0 := by ext x exact f.pi_apply_eq_sum_univ x rw [this] refine continuous_finset_sum _ fun i _ => ?_ exact (continuous_apply i).smul continuous_const end Pi section PointwiseLimits variable {M₁ M₂ α R S : Type*} [TopologicalSpace M₂] [T2Space M₂] [Semiring R] [Semiring S] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module S M₂] [ContinuousConstSMul S M₂] variable [ContinuousAdd M₂] {σ : R →+* S} {l : Filter α} /-- Constructs a bundled linear map from a function and a proof that this function belongs to the closure of the set of linear maps. -/ @[simps -fullyApplied] def linearMapOfMemClosureRangeCoe (f : M₁ → M₂) (hf : f ∈ closure (Set.range ((↑) : (M₁ →ₛₗ[σ] M₂) → M₁ → M₂))) : M₁ →ₛₗ[σ] M₂ := { addMonoidHomOfMemClosureRangeCoe f hf with map_smul' := (isClosed_setOf_map_smul M₁ M₂ σ).closure_subset_iff.2 (Set.range_subset_iff.2 LinearMap.map_smulₛₗ) hf } /-- Construct a bundled linear map from a pointwise limit of linear maps -/ @[simps! -fullyApplied] def linearMapOfTendsto (f : M₁ → M₂) (g : α → M₁ →ₛₗ[σ] M₂) [l.NeBot] (h : Tendsto (fun a x => g a x) l (𝓝 f)) : M₁ →ₛₗ[σ] M₂ := linearMapOfMemClosureRangeCoe f <| mem_closure_of_tendsto h <| Eventually.of_forall fun _ => Set.mem_range_self _ variable (M₁ M₂ σ) theorem LinearMap.isClosed_range_coe : IsClosed (Set.range ((↑) : (M₁ →ₛₗ[σ] M₂) → M₁ → M₂)) := isClosed_of_closure_subset fun f hf => ⟨linearMapOfMemClosureRangeCoe f hf, rfl⟩ end PointwiseLimits section Quotient namespace Submodule variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [TopologicalSpace M] (S : Submodule R M) instance _root_.QuotientModule.Quotient.topologicalSpace : TopologicalSpace (M ⧸ S) := inferInstanceAs (TopologicalSpace (Quotient S.quotientRel)) theorem isOpenMap_mkQ [ContinuousAdd M] : IsOpenMap S.mkQ := QuotientAddGroup.isOpenMap_coe theorem isOpenQuotientMap_mkQ [ContinuousAdd M] : IsOpenQuotientMap S.mkQ := QuotientAddGroup.isOpenQuotientMap_mk instance topologicalAddGroup_quotient [IsTopologicalAddGroup M] : IsTopologicalAddGroup (M ⧸ S) := inferInstanceAs <| IsTopologicalAddGroup (M ⧸ S.toAddSubgroup) instance continuousSMul_quotient [TopologicalSpace R] [IsTopologicalAddGroup M] [ContinuousSMul R M] : ContinuousSMul R (M ⧸ S) where continuous_smul := by rw [← (IsOpenQuotientMap.id.prodMap S.isOpenQuotientMap_mkQ).continuous_comp_iff] exact continuous_quot_mk.comp continuous_smul instance t3_quotient_of_isClosed [IsTopologicalAddGroup M] [IsClosed (S : Set M)] : T3Space (M ⧸ S) := letI : IsClosed (S.toAddSubgroup : Set M) := ‹_› QuotientAddGroup.instT3Space S.toAddSubgroup end Submodule end Quotient
Mathlib/Topology/Algebra/Module/Basic.lean
2,705
2,717
/- Copyright (c) 2020 Thomas Browning and Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning, Patrick Lutz -/ import Mathlib.GroupTheory.Solvable import Mathlib.FieldTheory.PolynomialGaloisGroup import Mathlib.RingTheory.RootsOfUnity.Basic /-! # The Abel-Ruffini Theorem This file proves one direction of the Abel-Ruffini theorem, namely that if an element is solvable by radicals, then its minimal polynomial has solvable Galois group. ## Main definitions * `solvableByRad F E` : the intermediate field of solvable-by-radicals elements ## Main results * the Abel-Ruffini Theorem `solvableByRad.isSolvable'` : An irreducible polynomial with a root that is solvable by radicals has a solvable Galois group. -/ noncomputable section open Polynomial IntermediateField section AbelRuffini variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E] theorem gal_zero_isSolvable : IsSolvable (0 : F[X]).Gal := by infer_instance theorem gal_one_isSolvable : IsSolvable (1 : F[X]).Gal := by infer_instance theorem gal_C_isSolvable (x : F) : IsSolvable (C x).Gal := by infer_instance theorem gal_X_isSolvable : IsSolvable (X : F[X]).Gal := by infer_instance theorem gal_X_sub_C_isSolvable (x : F) : IsSolvable (X - C x).Gal := by infer_instance theorem gal_X_pow_isSolvable (n : ℕ) : IsSolvable (X ^ n : F[X]).Gal := by infer_instance
Mathlib/FieldTheory/AbelRuffini.lean
45
45
/- Copyright (c) 2022 Praneeth Kolichala. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Praneeth Kolichala -/ import Mathlib.Topology.Homotopy.Equiv import Mathlib.CategoryTheory.Equivalence import Mathlib.AlgebraicTopology.FundamentalGroupoid.Product /-! # Homotopic maps induce naturally isomorphic functors ## Main definitions - `FundamentalGroupoidFunctor.homotopicMapsNatIso H` The natural isomorphism between the induced functors `f : π(X) ⥤ π(Y)` and `g : π(X) ⥤ π(Y)`, given a homotopy `H : f ∼ g` - `FundamentalGroupoidFunctor.equivOfHomotopyEquiv hequiv` The equivalence of the categories `π(X)` and `π(Y)` given a homotopy equivalence `hequiv : X ≃ₕ Y` between them. ## Implementation notes - In order to be more universe polymorphic, we define `ContinuousMap.Homotopy.uliftMap` which lifts a homotopy from `I × X → Y` to `(TopCat.of ((ULift I) × X)) → Y`. This is because this construction uses `FundamentalGroupoidFunctor.prodToProdTop` to convert between pairs of paths in I and X and the corresponding path after passing through a homotopy `H`. But `FundamentalGroupoidFunctor.prodToProdTop` requires two spaces in the same universe. -/ noncomputable section universe u open FundamentalGroupoid open CategoryTheory open FundamentalGroupoidFunctor open scoped FundamentalGroupoid open scoped unitInterval namespace unitInterval /-- The path 0 ⟶ 1 in `I` -/ def path01 : Path (0 : I) 1 where toFun := id source' := rfl target' := rfl /-- The path 0 ⟶ 1 in `ULift I` -/ def upath01 : Path (ULift.up 0 : ULift.{u} I) (ULift.up 1) where toFun := ULift.up source' := rfl target' := rfl attribute [local instance] Path.Homotopic.setoid /-- The homotopy path class of 0 → 1 in `ULift I` -/ def uhpath01 : @fromTop (TopCat.of <| ULift.{u} I) (ULift.up (0 : I)) ⟶ fromTop (ULift.up 1) := ⟦upath01⟧ end unitInterval namespace ContinuousMap.Homotopy open unitInterval (uhpath01) attribute [local instance] Path.Homotopic.setoid section Casts /-- Abbreviation for `eqToHom` that accepts points in a topological space -/ abbrev hcast {X : TopCat} {x₀ x₁ : X} (hx : x₀ = x₁) : fromTop x₀ ⟶ fromTop x₁ := eqToHom <| FundamentalGroupoid.ext hx @[simp] theorem hcast_def {X : TopCat} {x₀ x₁ : X} (hx₀ : x₀ = x₁) : hcast hx₀ = eqToHom (FundamentalGroupoid.ext hx₀) := rfl variable {X₁ X₂ Y : TopCat.{u}} {f : C(X₁, Y)} {g : C(X₂, Y)} {x₀ x₁ : X₁} {x₂ x₃ : X₂} {p : Path x₀ x₁} {q : Path x₂ x₃} (hfg : ∀ t, f (p t) = g (q t)) include hfg /-- If `f(p(t) = g(q(t))` for two paths `p` and `q`, then the induced path homotopy classes `f(p)` and `g(p)` are the same as well, despite having a priori different types -/ theorem heq_path_of_eq_image : HEq ((πₘ (TopCat.ofHom f)).map ⟦p⟧) ((πₘ (TopCat.ofHom g)).map ⟦q⟧) := by simp only [map_eq, ← Path.Homotopic.map_lift]; apply Path.Homotopic.hpath_hext; exact hfg private theorem start_path : f x₀ = g x₂ := by convert hfg 0 <;> simp only [Path.source]
private theorem end_path : f x₁ = g x₃ := by convert hfg 1 <;> simp only [Path.target]
Mathlib/AlgebraicTopology/FundamentalGroupoid/InducedMaps.lean
96
97
/- Copyright (c) 2020 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz -/ import Mathlib.Algebra.FreeAlgebra import Mathlib.Algebra.RingQuot import Mathlib.Algebra.TrivSqZeroExt import Mathlib.Algebra.Algebra.Operations import Mathlib.LinearAlgebra.Multilinear.Basic /-! # Tensor Algebras Given a commutative semiring `R`, and an `R`-module `M`, we construct the tensor algebra of `M`. This is the free `R`-algebra generated (`R`-linearly) by the module `M`. ## Notation 1. `TensorAlgebra R M` is the tensor algebra itself. It is endowed with an R-algebra structure. 2. `TensorAlgebra.ι R` is the canonical R-linear map `M → TensorAlgebra R M`. 3. Given a linear map `f : M → A` to an R-algebra `A`, `lift R f` is the lift of `f` to an `R`-algebra morphism `TensorAlgebra R M → A`. ## Theorems 1. `ι_comp_lift` states that the composition `(lift R f) ∘ (ι R)` is identical to `f`. 2. `lift_unique` states that whenever an R-algebra morphism `g : TensorAlgebra R M → A` is given whose composition with `ι R` is `f`, then one has `g = lift R f`. 3. `hom_ext` is a variant of `lift_unique` in the form of an extensionality theorem. 4. `lift_comp_ι` is a combination of `ι_comp_lift` and `lift_unique`. It states that the lift of the composition of an algebra morphism with `ι` is the algebra morphism itself. ## Implementation details As noted above, the tensor algebra of `M` is constructed as the free `R`-algebra generated by `M`, modulo the additional relations making the inclusion of `M` into an `R`-linear map. -/ variable (R : Type*) [CommSemiring R] variable (M : Type*) [AddCommMonoid M] [Module R M] namespace TensorAlgebra /-- An inductively defined relation on `Pre R M` used to force the initial algebra structure on the associated quotient. -/ inductive Rel : FreeAlgebra R M → FreeAlgebra R M → Prop -- force `ι` to be linear | add {a b : M} : Rel (FreeAlgebra.ι R (a + b)) (FreeAlgebra.ι R a + FreeAlgebra.ι R b) | smul {r : R} {a : M} : Rel (FreeAlgebra.ι R (r • a)) (algebraMap R (FreeAlgebra R M) r * FreeAlgebra.ι R a) end TensorAlgebra /-- The tensor algebra of the module `M` over the commutative semiring `R`. -/ def TensorAlgebra := RingQuot (TensorAlgebra.Rel R M) -- The `Inhabited, Semiring, Algebra` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance : Inhabited (TensorAlgebra R M) := RingQuot.instInhabited _ instance : Semiring (TensorAlgebra R M) := RingQuot.instSemiring _ -- `IsScalarTower` is not needed, but the instance isn't really canonical without it. @[nolint unusedArguments] instance instAlgebra {R A M} [CommSemiring R] [AddCommMonoid M] [CommSemiring A] [Algebra R A] [Module R M] [Module A M] [IsScalarTower R A M] : Algebra R (TensorAlgebra A M) := RingQuot.instAlgebra _ -- verify there is no diamond -- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906 example : (Semiring.toNatAlgebra : Algebra ℕ (TensorAlgebra R M)) = instAlgebra := rfl instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommMonoid M] [CommSemiring A] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] [IsScalarTower R A M] [IsScalarTower S A M] : SMulCommClass R S (TensorAlgebra A M) := RingQuot.instSMulCommClass _ instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommMonoid M] [CommSemiring A] [SMul R S] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] [IsScalarTower R A M] [IsScalarTower S A M] [IsScalarTower R S A] : IsScalarTower R S (TensorAlgebra A M) := RingQuot.instIsScalarTower _ namespace TensorAlgebra instance {S : Type*} [CommRing S] [Module S M] : Ring (TensorAlgebra S M) := RingQuot.instRing (Rel S M) -- verify there is no diamond -- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906 variable (S M : Type) [CommRing S] [AddCommGroup M] [Module S M] in example : (Ring.toIntAlgebra _ : Algebra ℤ (TensorAlgebra S M)) = instAlgebra := rfl variable {M} /-- The canonical linear map `M →ₗ[R] TensorAlgebra R M`. -/ irreducible_def ι : M →ₗ[R] TensorAlgebra R M := { toFun := fun m => RingQuot.mkAlgHom R _ (FreeAlgebra.ι R m) map_add' := fun x y => by rw [← map_add (RingQuot.mkAlgHom R (Rel R M))] exact RingQuot.mkAlgHom_rel R Rel.add map_smul' := fun r x => by rw [← map_smul (RingQuot.mkAlgHom R (Rel R M))] exact RingQuot.mkAlgHom_rel R Rel.smul } theorem ringQuot_mkAlgHom_freeAlgebra_ι_eq_ι (m : M) : RingQuot.mkAlgHom R (Rel R M) (FreeAlgebra.ι R m) = ι R m := by rw [ι] rfl /-- Given a linear map `f : M → A` where `A` is an `R`-algebra, `lift R f` is the unique lift of `f` to a morphism of `R`-algebras `TensorAlgebra R M → A`. -/ @[simps symm_apply] def lift {A : Type*} [Semiring A] [Algebra R A] : (M →ₗ[R] A) ≃ (TensorAlgebra R M →ₐ[R] A) := { toFun := RingQuot.liftAlgHom R ∘ fun f => ⟨FreeAlgebra.lift R (⇑f), fun x y (h : Rel R M x y) => by induction h <;> simp only [Algebra.smul_def, FreeAlgebra.lift_ι_apply, LinearMap.map_smulₛₗ, RingHom.id_apply, map_mul, AlgHom.commutes, map_add]⟩ invFun := fun F => F.toLinearMap.comp (ι R) left_inv := fun f => by rw [ι] ext1 x exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (FreeAlgebra.lift_ι_apply f x) right_inv := fun F => RingQuot.ringQuot_ext' _ _ _ <| FreeAlgebra.hom_ext <| funext fun x => by rw [ι] exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (FreeAlgebra.lift_ι_apply _ _) } variable {R} @[simp] theorem ι_comp_lift {A : Type*} [Semiring A] [Algebra R A] (f : M →ₗ[R] A) : (lift R f).toLinearMap.comp (ι R) = f := by convert (lift R).symm_apply_apply f @[simp] theorem lift_ι_apply {A : Type*} [Semiring A] [Algebra R A] (f : M →ₗ[R] A) (x) : lift R f (ι R x) = f x := by conv_rhs => rw [← ι_comp_lift f] rfl @[simp] theorem lift_unique {A : Type*} [Semiring A] [Algebra R A] (f : M →ₗ[R] A) (g : TensorAlgebra R M →ₐ[R] A) : g.toLinearMap.comp (ι R) = f ↔ g = lift R f := by rw [← (lift R).symm_apply_eq] simp only [lift, Equiv.coe_fn_symm_mk] -- Marking `TensorAlgebra` irreducible makes `Ring` instances inaccessible on quotients. -- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241 -- For now, we avoid this by not marking it irreducible. @[simp] theorem lift_comp_ι {A : Type*} [Semiring A] [Algebra R A] (g : TensorAlgebra R M →ₐ[R] A) : lift R (g.toLinearMap.comp (ι R)) = g := by rw [← lift_symm_apply] exact (lift R).apply_symm_apply g /-- See note [partially-applied ext lemmas]. -/ @[ext] theorem hom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : TensorAlgebra R M →ₐ[R] A} (w : f.toLinearMap.comp (ι R) = g.toLinearMap.comp (ι R)) : f = g := by rw [← lift_symm_apply, ← lift_symm_apply] at w exact (lift R).symm.injective w -- This proof closely follows `FreeAlgebra.induction` /-- If `C` holds for the `algebraMap` of `r : R` into `TensorAlgebra R M`, the `ι` of `x : M`, and is preserved under addition and multiplication, then it holds for all of `TensorAlgebra R M`. -/ @[elab_as_elim] theorem induction {C : TensorAlgebra R M → Prop} (algebraMap : ∀ r, C (algebraMap R (TensorAlgebra R M) r)) (ι : ∀ x, C (ι R x)) (mul : ∀ a b, C a → C b → C (a * b)) (add : ∀ a b, C a → C b → C (a + b)) (a : TensorAlgebra R M) : C a := by -- the arguments are enough to construct a subalgebra, and a mapping into it from M let s : Subalgebra R (TensorAlgebra R M) := { carrier := C mul_mem' := @mul add_mem' := @add algebraMap_mem' := algebraMap } let of : M →ₗ[R] s := (TensorAlgebra.ι R).codRestrict (Subalgebra.toSubmodule s) ι -- the mapping through the subalgebra is the identity have of_id : AlgHom.id R (TensorAlgebra R M) = s.val.comp (lift R of) := by ext simp only [AlgHom.toLinearMap_id, LinearMap.id_comp, AlgHom.comp_toLinearMap, LinearMap.coe_comp, Function.comp_apply, AlgHom.toLinearMap_apply, lift_ι_apply, Subalgebra.coe_val] erw [LinearMap.codRestrict_apply] -- finding a proof is finding an element of the subalgebra rw [← AlgHom.id_apply (R := R) a, of_id] exact Subtype.prop (lift R of a) /-- The left-inverse of `algebraMap`. -/ def algebraMapInv : TensorAlgebra R M →ₐ[R] R := lift R (0 : M →ₗ[R] R) variable (M) theorem algebraMap_leftInverse : Function.LeftInverse algebraMapInv (algebraMap R <| TensorAlgebra R M) := fun x => by simp [algebraMapInv] @[simp] theorem algebraMap_inj (x y : R) : algebraMap R (TensorAlgebra R M) x = algebraMap R (TensorAlgebra R M) y ↔ x = y := (algebraMap_leftInverse M).injective.eq_iff @[simp] theorem algebraMap_eq_zero_iff (x : R) : algebraMap R (TensorAlgebra R M) x = 0 ↔ x = 0 := map_eq_zero_iff (algebraMap _ _) (algebraMap_leftInverse _).injective @[simp] theorem algebraMap_eq_one_iff (x : R) : algebraMap R (TensorAlgebra R M) x = 1 ↔ x = 1 := map_eq_one_iff (algebraMap _ _) (algebraMap_leftInverse _).injective /-- A `TensorAlgebra` over a nontrivial semiring is nontrivial. -/ instance [Nontrivial R] : Nontrivial (TensorAlgebra R M) := (algebraMap_leftInverse M).injective.nontrivial variable {M} /-- The canonical map from `TensorAlgebra R M` into `TrivSqZeroExt R M` that sends `TensorAlgebra.ι` to `TrivSqZeroExt.inr`. -/ def toTrivSqZeroExt [Module Rᵐᵒᵖ M] [IsCentralScalar R M] : TensorAlgebra R M →ₐ[R] TrivSqZeroExt R M := lift R (TrivSqZeroExt.inrHom R M) @[simp] theorem toTrivSqZeroExt_ι (x : M) [Module Rᵐᵒᵖ M] [IsCentralScalar R M] : toTrivSqZeroExt (ι R x) = TrivSqZeroExt.inr x := lift_ι_apply _ _ /-- The left-inverse of `ι`. As an implementation detail, we implement this using `TrivSqZeroExt` which has a suitable algebra structure. -/ def ιInv : TensorAlgebra R M →ₗ[R] M := by letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm) haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩ exact (TrivSqZeroExt.sndHom R M).comp toTrivSqZeroExt.toLinearMap theorem ι_leftInverse : Function.LeftInverse ιInv (ι R : M → TensorAlgebra R M) := fun x ↦ by simp [ιInv] variable (R) @[simp] theorem ι_inj (x y : M) : ι R x = ι R y ↔ x = y := ι_leftInverse.injective.eq_iff @[simp] theorem ι_eq_zero_iff (x : M) : ι R x = 0 ↔ x = 0 := by rw [← ι_inj R x 0, LinearMap.map_zero] variable {R} @[simp] theorem ι_eq_algebraMap_iff (x : M) (r : R) : ι R x = algebraMap R _ r ↔ x = 0 ∧ r = 0 := by refine ⟨fun h => ?_, ?_⟩ · letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm) haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩ have hf0 : toTrivSqZeroExt (ι R x) = (0, x) := lift_ι_apply _ _ rw [h, AlgHom.commutes] at hf0 have : r = 0 ∧ 0 = x := Prod.ext_iff.1 hf0 exact this.symm.imp_left Eq.symm
· rintro ⟨rfl, rfl⟩ rw [LinearMap.map_zero, RingHom.map_zero]
Mathlib/LinearAlgebra/TensorAlgebra/Basic.lean
277
278
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Algebra.Module.Submodule.Ker import Mathlib.Algebra.Module.Submodule.RestrictScalars import Mathlib.Data.Set.Finite.Range /-! # Range of linear maps The range `LinearMap.range` of a (semi)linear map `f : M → M₂` is a submodule of `M₂`. More specifically, `LinearMap.range` applies to any `SemilinearMapClass` over a `RingHomSurjective` ring homomorphism. Note that this also means that dot notation (i.e. `f.range` for a linear map `f`) does not work. ## Notations * We continue to use the notations `M →ₛₗ[σ] M₂` and `M →ₗ[R] M₂` for the type of semilinear (resp. linear) maps from `M` to `M₂` over the ring homomorphism `σ` (resp. over the ring `R`). ## Tags linear algebra, vector space, module, range -/ open Function variable {R : Type*} {R₂ : Type*} {R₃ : Type*} variable {K : Type*} variable {M : Type*} {M₂ : Type*} {M₃ : Type*} variable {V : Type*} {V₂ : Type*} namespace LinearMap section AddCommMonoid variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] open Submodule variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] section variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] /-- The range of a linear map `f : M → M₂` is a submodule of `M₂`. See Note [range copy pattern]. -/ def range [RingHomSurjective τ₁₂] (f : F) : Submodule R₂ M₂ := (map f ⊤).copy (Set.range f) Set.image_univ.symm theorem range_coe [RingHomSurjective τ₁₂] (f : F) : (range f : Set M₂) = Set.range f := rfl theorem range_toAddSubmonoid [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : (range f).toAddSubmonoid = AddMonoidHom.mrange f := rfl @[simp] theorem mem_range [RingHomSurjective τ₁₂] {f : F} {x} : x ∈ range f ↔ ∃ y, f y = x := Iff.rfl theorem range_eq_map [RingHomSurjective τ₁₂] (f : F) : range f = map f ⊤ := by ext simp theorem mem_range_self [RingHomSurjective τ₁₂] (f : F) (x : M) : f x ∈ range f := ⟨x, rfl⟩ @[simp] theorem range_id : range (LinearMap.id : M →ₗ[R] M) = ⊤ := SetLike.coe_injective Set.range_id theorem range_comp [RingHomSurjective τ₁₂] [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) = map g (range f) := SetLike.coe_injective (Set.range_comp g f) theorem range_comp_le_range [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) ≤ range g := SetLike.coe_mono (Set.range_comp_subset_range f g) theorem range_eq_top [RingHomSurjective τ₁₂] {f : F} : range f = ⊤ ↔ Surjective f := by rw [SetLike.ext'_iff, range_coe, top_coe, Set.range_eq_univ] theorem range_eq_top_of_surjective [RingHomSurjective τ₁₂] (f : F) (hf : Surjective f) : range f = ⊤ := range_eq_top.2 hf theorem range_le_iff_comap [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂} : range f ≤ p ↔ comap f p = ⊤ := by rw [range_eq_map, map_le_iff_le_comap, eq_top_iff] theorem map_le_range [RingHomSurjective τ₁₂] {f : F} {p : Submodule R M} : map f p ≤ range f := SetLike.coe_mono (Set.image_subset_range f p) @[simp] theorem range_neg {R : Type*} {R₂ : Type*} {M : Type*} {M₂ : Type*} [Semiring R] [Ring R₂] [AddCommMonoid M] [AddCommGroup M₂] [Module R M] [Module R₂ M₂] {τ₁₂ : R →+* R₂} [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : LinearMap.range (-f) = LinearMap.range f := by change range ((-LinearMap.id : M₂ →ₗ[R₂] M₂).comp f) = _ rw [range_comp, Submodule.map_neg, Submodule.map_id] @[simp] lemma range_domRestrict [Module R M₂] (K : Submodule R M) (f : M →ₗ[R] M₂) : range (domRestrict f K) = K.map f := by ext; simp lemma range_domRestrict_le_range [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) (S : Submodule R M) : LinearMap.range (f.domRestrict S) ≤ LinearMap.range f := by rintro x ⟨⟨y, hy⟩, rfl⟩ exact LinearMap.mem_range_self f y @[simp] theorem _root_.AddMonoidHom.coe_toIntLinearMap_range {M M₂ : Type*} [AddCommGroup M] [AddCommGroup M₂] (f : M →+ M₂) : LinearMap.range f.toIntLinearMap = AddSubgroup.toIntSubmodule f.range := rfl lemma _root_.Submodule.map_comap_eq_of_le [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂} (h : p ≤ LinearMap.range f) : (p.comap f).map f = p := SetLike.coe_injective <| Set.image_preimage_eq_of_subset h lemma range_restrictScalars [SMul R R₂] [Module R₂ M] [Module R M₂] [CompatibleSMul M M₂ R R₂] [IsScalarTower R R₂ M₂] (f : M →ₗ[R₂] M₂) : LinearMap.range (f.restrictScalars R) = (LinearMap.range f).restrictScalars R := rfl end /-- The decreasing sequence of submodules consisting of the ranges of the iterates of a linear map. -/ @[simps] def iterateRange (f : M →ₗ[R] M) : ℕ →o (Submodule R M)ᵒᵈ where toFun n := LinearMap.range (f ^ n) monotone' n m w x h := by obtain ⟨c, rfl⟩ := Nat.exists_eq_add_of_le w rw [LinearMap.mem_range] at h obtain ⟨m, rfl⟩ := h rw [LinearMap.mem_range] use (f ^ c) m rw [pow_add, Module.End.mul_apply] /-- Restrict the codomain of a linear map `f` to `f.range`. This is the bundled version of `Set.rangeFactorization`. -/ abbrev rangeRestrict [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : M →ₛₗ[τ₁₂] LinearMap.range f := f.codRestrict (LinearMap.range f) (LinearMap.mem_range_self f) /-- The range of a linear map is finite if the domain is finite. Note: this instance can form a diamond with `Subtype.fintype` in the presence of `Fintype M₂`. -/ instance fintypeRange [Fintype M] [DecidableEq M₂] [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : Fintype (range f) := Set.fintypeRange f variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] theorem range_codRestrict {τ₂₁ : R₂ →+* R} [RingHomSurjective τ₂₁] (p : Submodule R M) (f : M₂ →ₛₗ[τ₂₁] M) (hf) : range (codRestrict p f hf) = comap p.subtype (LinearMap.range f) := by simpa only [range_eq_map] using map_codRestrict _ _ _ _ theorem _root_.Submodule.map_comap_eq [RingHomSurjective τ₁₂] (f : F) (q : Submodule R₂ M₂) : map f (comap f q) = range f ⊓ q := le_antisymm (le_inf map_le_range (map_comap_le _ _)) <| by rintro _ ⟨⟨x, _, rfl⟩, hx⟩; exact ⟨x, hx, rfl⟩ theorem _root_.Submodule.map_comap_eq_self [RingHomSurjective τ₁₂] {f : F} {q : Submodule R₂ M₂} (h : q ≤ range f) : map f (comap f q) = q := by rwa [Submodule.map_comap_eq, inf_eq_right] @[simp] theorem range_zero [RingHomSurjective τ₁₂] : range (0 : M →ₛₗ[τ₁₂] M₂) = ⊥ := by simpa only [range_eq_map] using Submodule.map_zero _ section variable [RingHomSurjective τ₁₂] theorem range_le_bot_iff (f : M →ₛₗ[τ₁₂] M₂) : range f ≤ ⊥ ↔ f = 0 := by rw [range_le_iff_comap]; exact ker_eq_top theorem range_eq_bot {f : M →ₛₗ[τ₁₂] M₂} : range f = ⊥ ↔ f = 0 := by rw [← range_le_bot_iff, le_bot_iff] theorem range_le_ker_iff {f : M →ₛₗ[τ₁₂] M₂} {g : M₂ →ₛₗ[τ₂₃] M₃} : range f ≤ ker g ↔ (g.comp f : M →ₛₗ[τ₁₃] M₃) = 0 := ⟨fun h => ker_eq_top.1 <| eq_top_iff'.2 fun _ => h <| ⟨_, rfl⟩, fun h x hx => mem_ker.2 <| Exists.elim hx fun y hy => by rw [← hy, ← comp_apply, h, zero_apply]⟩ theorem comap_le_comap_iff {f : F} (hf : range f = ⊤) {p p'} : comap f p ≤ comap f p' ↔ p ≤ p' := ⟨fun H ↦ by rwa [SetLike.le_def, (range_eq_top.1 hf).forall], comap_mono⟩ theorem comap_injective {f : F} (hf : range f = ⊤) : Injective (comap f) := fun _ _ h => le_antisymm ((comap_le_comap_iff hf).1 (le_of_eq h)) ((comap_le_comap_iff hf).1 (ge_of_eq h)) -- TODO (?): generalize to semilinear maps with `f ∘ₗ g` bijective. theorem ker_eq_range_of_comp_eq_id {M P} [AddCommGroup M] [Module R M] [AddCommGroup P] [Module R P] {f : M →ₗ[R] P} {g : P →ₗ[R] M} (h : f ∘ₗ g = .id) : ker f = range (LinearMap.id - g ∘ₗ f) := le_antisymm (fun x hx ↦ ⟨x, show x - g (f x) = x by rw [hx, map_zero, sub_zero]⟩) <| range_le_ker_iff.mpr <| by rw [comp_sub, comp_id, ← comp_assoc, h, id_comp, sub_self] end end AddCommMonoid section Ring variable [Ring R] [Ring R₂] variable [AddCommGroup M] [AddCommGroup M₂] variable [Module R M] [Module R₂ M₂] variable {τ₁₂ : R →+* R₂} variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] variable {f : F} open Submodule theorem range_toAddSubgroup [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : (range f).toAddSubgroup = f.toAddMonoidHom.range := rfl theorem ker_le_iff [RingHomSurjective τ₁₂] {p : Submodule R M} : ker f ≤ p ↔ ∃ y ∈ range f, f ⁻¹' {y} ⊆ p := by constructor · intro h use 0 rw [← SetLike.mem_coe, range_coe] exact ⟨⟨0, map_zero f⟩, h⟩ · rintro ⟨y, h₁, h₂⟩ rw [SetLike.le_def] intro z hz simp only [mem_ker, SetLike.mem_coe] at hz rw [← SetLike.mem_coe, range_coe, Set.mem_range] at h₁ obtain ⟨x, hx⟩ := h₁ have hx' : x ∈ p := h₂ hx have hxz : z + x ∈ p := by apply h₂ simp [hx, hz] suffices z + x - x ∈ p by simpa only [this, add_sub_cancel_right] exact p.sub_mem hxz hx' end Ring section Semifield variable [Semifield K] variable [AddCommMonoid V] [Module K V] variable [AddCommMonoid V₂] [Module K V₂] theorem range_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : range (a • f) = range f := by simpa only [range_eq_map] using Submodule.map_smul f _ a h theorem range_smul' (f : V →ₗ[K] V₂) (a : K) : range (a • f) = ⨆ _ : a ≠ 0, range f := by simpa only [range_eq_map] using Submodule.map_smul' f _ a end Semifield end LinearMap namespace Submodule section AddCommMonoid variable [Semiring R] [Semiring R₂] [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R₂ M₂] variable (p : Submodule R M) variable {τ₁₂ : R →+* R₂} variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] open LinearMap @[simp] theorem map_top [RingHomSurjective τ₁₂] (f : F) : map f ⊤ = range f := (range_eq_map f).symm @[simp] theorem range_subtype : range p.subtype = p := by simpa using map_comap_subtype p ⊤ theorem map_subtype_le (p' : Submodule R p) : map p.subtype p' ≤ p := by simpa using (map_le_range : map p.subtype p' ≤ range p.subtype) /-- Under the canonical linear map from a submodule `p` to the ambient space `M`, the image of the maximal submodule of `p` is just `p`. -/ theorem map_subtype_top : map p.subtype (⊤ : Submodule R p) = p := by simp @[simp] theorem comap_subtype_eq_top {p p' : Submodule R M} : comap p.subtype p' = ⊤ ↔ p ≤ p' := eq_top_iff.trans <| map_le_iff_le_comap.symm.trans <| by rw [map_subtype_top] @[simp] theorem comap_subtype_self : comap p.subtype p = ⊤ := comap_subtype_eq_top.2 le_rfl @[simp] lemma comap_subtype_le_iff {p q r : Submodule R M} : q.comap p.subtype ≤ r.comap p.subtype ↔ p ⊓ q ≤ p ⊓ r := ⟨fun h ↦ by simpa using map_mono (f := p.subtype) h, fun h ↦ by simpa using comap_mono (f := p.subtype) h⟩ theorem range_inclusion (p q : Submodule R M) (h : p ≤ q) : range (inclusion h) = comap q.subtype p := by rw [← map_top, inclusion, LinearMap.map_codRestrict, map_top, range_subtype] @[simp] theorem map_subtype_range_inclusion {p p' : Submodule R M} (h : p ≤ p') : map p'.subtype (range <| inclusion h) = p := by simp [range_inclusion, map_comap_eq, h] lemma restrictScalars_map [SMul R R₂] [Module R₂ M] [Module R M₂] [IsScalarTower R R₂ M] [IsScalarTower R R₂ M₂] (f : M →ₗ[R₂] M₂) (M' : Submodule R₂ M) : (M'.map f).restrictScalars R = (M'.restrictScalars R).map (f.restrictScalars R) := rfl /-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N`. See also `Submodule.mapIic`. -/ def MapSubtype.relIso : Submodule R p ≃o { p' : Submodule R M // p' ≤ p } where toFun p' := ⟨map p.subtype p', map_subtype_le p _⟩ invFun q := comap p.subtype q left_inv p' := comap_map_eq_of_injective (by exact Subtype.val_injective) p' right_inv := fun ⟨q, hq⟩ => Subtype.ext_val <| by simp [map_comap_subtype p, inf_of_le_right hq] map_rel_iff' {p₁ p₂} := Subtype.coe_le_coe.symm.trans <| by dsimp rw [map_le_iff_le_comap, comap_map_eq_of_injective (show Injective p.subtype from Subtype.coe_injective) p₂] /-- If `p ⊆ M` is a submodule, the ordering of submodules of `p` is embedded in the ordering of submodules of `M`. -/ def MapSubtype.orderEmbedding : Submodule R p ↪o Submodule R M := (RelIso.toRelEmbedding <| MapSubtype.relIso p).trans <| Subtype.relEmbedding (X := Submodule R M) (fun p p' ↦ p ≤ p') _ @[simp] theorem map_subtype_embedding_eq (p' : Submodule R p) : MapSubtype.orderEmbedding p p' = map p.subtype p' := rfl /-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N`. -/ def mapIic (p : Submodule R M) : Submodule R p ≃o Set.Iic p := Submodule.MapSubtype.relIso p @[simp] lemma coe_mapIic_apply (p : Submodule R M) (q : Submodule R p) : (p.mapIic q : Submodule R M) = q.map p.subtype := rfl end AddCommMonoid end Submodule namespace LinearMap section Semiring variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] /-- A monomorphism is injective. -/ theorem ker_eq_bot_of_cancel {f : M →ₛₗ[τ₁₂] M₂} (h : ∀ u v : ker f →ₗ[R] M, f.comp u = f.comp v → u = v) : ker f = ⊥ := by have h₁ : f.comp (0 : ker f →ₗ[R] M) = 0 := comp_zero _ rw [← Submodule.range_subtype (ker f), ← h 0 (ker f).subtype (Eq.trans h₁ (comp_ker_subtype f).symm)] exact range_zero theorem range_comp_of_range_eq_top [RingHomSurjective τ₁₂] [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] {f : M →ₛₗ[τ₁₂] M₂} (g : M₂ →ₛₗ[τ₂₃] M₃) (hf : range f = ⊤) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) = range g := by rw [range_comp, hf, Submodule.map_top] section Image /-- If `O` is a submodule of `M`, and `Φ : O →ₗ M'` is a linear map, then `(ϕ : O →ₗ M').submoduleImage N` is `ϕ(N)` as a submodule of `M'` -/ def submoduleImage {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M}
(ϕ : O →ₗ[R] M') (N : Submodule R M) : Submodule R M' := (N.comap O.subtype).map ϕ @[simp] theorem mem_submoduleImage {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M} {ϕ : O →ₗ[R] M'} {N : Submodule R M} {x : M'} :
Mathlib/Algebra/Module/Submodule/Range.lean
379
384
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Nat.Find import Mathlib.Data.Stream.Init import Mathlib.Tactic.Common /-! # Coinductive formalization of unbounded computations. This file provides a `Computation` type where `Computation α` is the type of unbounded computations returning `α`. -/ open Function universe u v w /- coinductive Computation (α : Type u) : Type u | pure : α → Computation α | think : Computation α → Computation α -/ /-- `Computation α` is the type of unbounded computations returning `α`. An element of `Computation α` is an infinite sequence of `Option α` such that if `f n = some a` for some `n` then it is constantly `some a` after that. -/ def Computation (α : Type u) : Type u := { f : Stream' (Option α) // ∀ ⦃n a⦄, f n = some a → f (n + 1) = some a } namespace Computation variable {α : Type u} {β : Type v} {γ : Type w} -- constructors /-- `pure a` is the computation that immediately terminates with result `a`. -/ def pure (a : α) : Computation α := ⟨Stream'.const (some a), fun _ _ => id⟩ instance : CoeTC α (Computation α) := ⟨pure⟩ -- note [use has_coe_t] /-- `think c` is the computation that delays for one "tick" and then performs computation `c`. -/ def think (c : Computation α) : Computation α := ⟨Stream'.cons none c.1, fun n a h => by rcases n with - | n · contradiction · exact c.2 h⟩ /-- `thinkN c n` is the computation that delays for `n` ticks and then performs computation `c`. -/ def thinkN (c : Computation α) : ℕ → Computation α | 0 => c | n + 1 => think (thinkN c n) -- check for immediate result /-- `head c` is the first step of computation, either `some a` if `c = pure a` or `none` if `c = think c'`. -/ def head (c : Computation α) : Option α := c.1.head -- one step of computation /-- `tail c` is the remainder of computation, either `c` if `c = pure a` or `c'` if `c = think c'`. -/ def tail (c : Computation α) : Computation α := ⟨c.1.tail, fun _ _ h => c.2 h⟩ /-- `empty α` is the computation that never returns, an infinite sequence of `think`s. -/ def empty (α) : Computation α := ⟨Stream'.const none, fun _ _ => id⟩ instance : Inhabited (Computation α) := ⟨empty _⟩ /-- `runFor c n` evaluates `c` for `n` steps and returns the result, or `none` if it did not terminate after `n` steps. -/ def runFor : Computation α → ℕ → Option α := Subtype.val /-- `destruct c` is the destructor for `Computation α` as a coinductive type. It returns `inl a` if `c = pure a` and `inr c'` if `c = think c'`. -/ def destruct (c : Computation α) : α ⊕ (Computation α) := match c.1 0 with | none => Sum.inr (tail c) | some a => Sum.inl a /-- `run c` is an unsound meta function that runs `c` to completion, possibly resulting in an infinite loop in the VM. -/ unsafe def run : Computation α → α | c => match destruct c with | Sum.inl a => a | Sum.inr ca => run ca theorem destruct_eq_pure {s : Computation α} {a : α} : destruct s = Sum.inl a → s = pure a := by dsimp [destruct] induction' f0 : s.1 0 with _ <;> intro h · contradiction · apply Subtype.eq funext n induction' n with n IH · injection h with h' rwa [h'] at f0 · exact s.2 IH theorem destruct_eq_think {s : Computation α} {s'} : destruct s = Sum.inr s' → s = think s' := by dsimp [destruct] induction' f0 : s.1 0 with a' <;> intro h · injection h with h' rw [← h'] obtain ⟨f, al⟩ := s apply Subtype.eq dsimp [think, tail] rw [← f0] exact (Stream'.eta f).symm · contradiction @[simp] theorem destruct_pure (a : α) : destruct (pure a) = Sum.inl a := rfl @[simp] theorem destruct_think : ∀ s : Computation α, destruct (think s) = Sum.inr s | ⟨_, _⟩ => rfl @[simp] theorem destruct_empty : destruct (empty α) = Sum.inr (empty α) := rfl @[simp] theorem head_pure (a : α) : head (pure a) = some a := rfl @[simp] theorem head_think (s : Computation α) : head (think s) = none := rfl @[simp] theorem head_empty : head (empty α) = none := rfl @[simp] theorem tail_pure (a : α) : tail (pure a) = pure a := rfl @[simp] theorem tail_think (s : Computation α) : tail (think s) = s := by obtain ⟨f, al⟩ := s; apply Subtype.eq; dsimp [tail, think] @[simp] theorem tail_empty : tail (empty α) = empty α := rfl theorem think_empty : empty α = think (empty α) := destruct_eq_think destruct_empty /-- Recursion principle for computations, compare with `List.recOn`. -/ def recOn {C : Computation α → Sort v} (s : Computation α) (h1 : ∀ a, C (pure a)) (h2 : ∀ s, C (think s)) : C s := match H : destruct s with | Sum.inl v => by rw [destruct_eq_pure H] apply h1 | Sum.inr v => match v with | ⟨a, s'⟩ => by rw [destruct_eq_think H] apply h2 /-- Corecursor constructor for `corec` -/ def Corec.f (f : β → α ⊕ β) : α ⊕ β → Option α × (α ⊕ β) | Sum.inl a => (some a, Sum.inl a) | Sum.inr b => (match f b with | Sum.inl a => some a | Sum.inr _ => none, f b) /-- `corec f b` is the corecursor for `Computation α` as a coinductive type. If `f b = inl a` then `corec f b = pure a`, and if `f b = inl b'` then `corec f b = think (corec f b')`. -/ def corec (f : β → α ⊕ β) (b : β) : Computation α := by refine ⟨Stream'.corec' (Corec.f f) (Sum.inr b), fun n a' h => ?_⟩ rw [Stream'.corec'_eq] change Stream'.corec' (Corec.f f) (Corec.f f (Sum.inr b)).2 n = some a' revert h; generalize Sum.inr b = o; revert o induction' n with n IH <;> intro o · change (Corec.f f o).1 = some a' → (Corec.f f (Corec.f f o).2).1 = some a' rcases o with _ | b <;> intro h · exact h unfold Corec.f at *; split <;> simp_all · rw [Stream'.corec'_eq (Corec.f f) (Corec.f f o).2, Stream'.corec'_eq (Corec.f f) o] exact IH (Corec.f f o).2 /-- left map of `⊕` -/ def lmap (f : α → β) : α ⊕ γ → β ⊕ γ | Sum.inl a => Sum.inl (f a) | Sum.inr b => Sum.inr b /-- right map of `⊕` -/ def rmap (f : β → γ) : α ⊕ β → α ⊕ γ | Sum.inl a => Sum.inl a | Sum.inr b => Sum.inr (f b) attribute [simp] lmap rmap @[simp] theorem corec_eq (f : β → α ⊕ β) (b : β) : destruct (corec f b) = rmap (corec f) (f b) := by dsimp [corec, destruct] rw [show Stream'.corec' (Corec.f f) (Sum.inr b) 0 = Sum.rec Option.some (fun _ ↦ none) (f b) by dsimp [Corec.f, Stream'.corec', Stream'.corec, Stream'.map, Stream'.get, Stream'.iterate] match (f b) with | Sum.inl x => rfl | Sum.inr x => rfl ] induction' h : f b with a b'; · rfl dsimp [Corec.f, destruct] apply congr_arg; apply Subtype.eq dsimp [corec, tail] rw [Stream'.corec'_eq, Stream'.tail_cons] dsimp [Corec.f]; rw [h] section Bisim variable (R : Computation α → Computation α → Prop) /-- bisimilarity relation -/ local infixl:50 " ~ " => R /-- Bisimilarity over a sum of `Computation`s -/ def BisimO : α ⊕ (Computation α) → α ⊕ (Computation α) → Prop | Sum.inl a, Sum.inl a' => a = a' | Sum.inr s, Sum.inr s' => R s s' | _, _ => False attribute [simp] BisimO attribute [nolint simpNF] BisimO.eq_3 /-- Attribute expressing bisimilarity over two `Computation`s -/ def IsBisimulation := ∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → BisimO R (destruct s₁) (destruct s₂) -- If two computations are bisimilar, then they are equal theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ := by apply Subtype.eq apply Stream'.eq_of_bisim fun x y => ∃ s s' : Computation α, s.1 = x ∧ s'.1 = y ∧ R s s' · dsimp [Stream'.IsBisimulation] intro t₁ t₂ e match t₁, t₂, e with | _, _, ⟨s, s', rfl, rfl, r⟩ => suffices head s = head s' ∧ R (tail s) (tail s') from And.imp id (fun r => ⟨tail s, tail s', by cases s; rfl, by cases s'; rfl, r⟩) this have h := bisim r; revert r h apply recOn s _ _ <;> intro r' <;> apply recOn s' _ _ <;> intro a' r h · constructor <;> dsimp at h · rw [h] · rw [h] at r rw [tail_pure, tail_pure,h] assumption · rw [destruct_pure, destruct_think] at h exact False.elim h · rw [destruct_pure, destruct_think] at h exact False.elim h · simp_all · exact ⟨s₁, s₂, rfl, rfl, r⟩ end Bisim -- It's more of a stretch to use ∈ for this relation, but it -- asserts that the computation limits to the given value. /-- Assertion that a `Computation` limits to a given value -/ protected def Mem (s : Computation α) (a : α) := some a ∈ s.1 instance : Membership α (Computation α) := ⟨Computation.Mem⟩ theorem le_stable (s : Computation α) {a m n} (h : m ≤ n) : s.1 m = some a → s.1 n = some a := by obtain ⟨f, al⟩ := s induction' h with n _ IH exacts [id, fun h2 => al (IH h2)] theorem mem_unique {s : Computation α} {a b : α} : a ∈ s → b ∈ s → a = b
| ⟨m, ha⟩, ⟨n, hb⟩ => by injection (le_stable s (le_max_left m n) ha.symm).symm.trans (le_stable s (le_max_right m n) hb.symm) theorem Mem.left_unique : Relator.LeftUnique ((· ∈ ·) : α → Computation α → Prop) := fun _ _ _ => mem_unique /-- `Terminates s` asserts that the computation `s` eventually terminates with some value. -/ class Terminates (s : Computation α) : Prop where /-- assertion that there is some term `a` such that the `Computation` terminates -/ term : ∃ a, a ∈ s theorem terminates_iff (s : Computation α) : Terminates s ↔ ∃ a, a ∈ s := ⟨fun h => h.1, Terminates.mk⟩ theorem terminates_of_mem {s : Computation α} {a : α} (h : a ∈ s) : Terminates s := ⟨⟨a, h⟩⟩ theorem terminates_def (s : Computation α) : Terminates s ↔ ∃ n, (s.1 n).isSome := ⟨fun ⟨⟨a, n, h⟩⟩ => ⟨n, by dsimp [Stream'.get] at h
Mathlib/Data/Seq/Computation.lean
288
309