filename
stringlengths
5
30
content
stringlengths
22
296k
Solvable.lean
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Abelian import Mathlib.Algebra.Lie.BaseChange import Mathlib.Algebra.Lie.IdealOperations import Mathlib.Order.Hom.Basic import Mathlib.RingTheory.Flat.FaithfullyFlat.Basic /-! # Solvable Lie algebras Like groups, Lie algebras admit a natural concept of solvability. We define this here via the derived series and prove some related results. We also define the radical of a Lie algebra and prove that it is solvable when the Lie algebra is Noetherian. ## Main definitions * `LieAlgebra.derivedSeriesOfIdeal` * `LieAlgebra.derivedSeries` * `LieAlgebra.IsSolvable` * `LieAlgebra.isSolvableAdd` * `LieAlgebra.radical` * `LieAlgebra.radicalIsSolvable` * `LieAlgebra.derivedLengthOfIdeal` * `LieAlgebra.derivedLength` * `LieAlgebra.derivedAbelianOfIdeal` ## Tags lie algebra, derived series, derived length, solvable, radical -/ universe u v w w₁ w₂ variable (R : Type u) (L : Type v) (M : Type w) {L' : Type w₁} variable [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] variable (I J : LieIdeal R L) {f : L' →ₗ⁅R⁆ L} namespace LieAlgebra /-- A generalisation of the derived series of a Lie algebra, whose zeroth term is a specified ideal. It can be more convenient to work with this generalisation when considering the derived series of an ideal since it provides a type-theoretic expression of the fact that the terms of the ideal's derived series are also ideals of the enclosing algebra. See also `LieIdeal.derivedSeries_eq_derivedSeriesOfIdeal_comap` and `LieIdeal.derivedSeries_eq_derivedSeriesOfIdeal_map` below. -/ def derivedSeriesOfIdeal (k : ℕ) : LieIdeal R L → LieIdeal R L := (fun I => ⁅I, I⁆)^[k] @[simp] theorem derivedSeriesOfIdeal_zero : derivedSeriesOfIdeal R L 0 I = I := rfl @[simp] theorem derivedSeriesOfIdeal_succ (k : ℕ) : derivedSeriesOfIdeal R L (k + 1) I = ⁅derivedSeriesOfIdeal R L k I, derivedSeriesOfIdeal R L k I⁆ := Function.iterate_succ_apply' (fun I => ⁅I, I⁆) k I /-- The derived series of Lie ideals of a Lie algebra. -/ abbrev derivedSeries (k : ℕ) : LieIdeal R L := derivedSeriesOfIdeal R L k ⊤ theorem derivedSeries_def (k : ℕ) : derivedSeries R L k = derivedSeriesOfIdeal R L k ⊤ := rfl variable {R L} local notation "D" => derivedSeriesOfIdeal R L theorem derivedSeriesOfIdeal_add (k l : ℕ) : D (k + l) I = D k (D l I) := by induction k with | zero => rw [Nat.zero_add, derivedSeriesOfIdeal_zero] | succ k ih => rw [Nat.succ_add k l, derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_succ, ih] @[gcongr, mono] theorem derivedSeriesOfIdeal_le {I J : LieIdeal R L} {k l : ℕ} (h₁ : I ≤ J) (h₂ : l ≤ k) : D k I ≤ D l J := by revert l; induction' k with k ih <;> intro l h₂ · rw [le_zero_iff] at h₂; rw [h₂, derivedSeriesOfIdeal_zero]; exact h₁ · have h : l = k.succ ∨ l ≤ k := by rwa [le_iff_eq_or_lt, Nat.lt_succ_iff] at h₂ rcases h with h | h · rw [h, derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_succ] exact LieSubmodule.mono_lie (ih (le_refl k)) (ih (le_refl k)) · rw [derivedSeriesOfIdeal_succ]; exact le_trans (LieSubmodule.lie_le_left _ _) (ih h) theorem derivedSeriesOfIdeal_succ_le (k : ℕ) : D (k + 1) I ≤ D k I := derivedSeriesOfIdeal_le (le_refl I) k.le_succ theorem derivedSeriesOfIdeal_le_self (k : ℕ) : D k I ≤ I := derivedSeriesOfIdeal_le (le_refl I) (zero_le k) theorem derivedSeriesOfIdeal_mono {I J : LieIdeal R L} (h : I ≤ J) (k : ℕ) : D k I ≤ D k J := derivedSeriesOfIdeal_le h (le_refl k) theorem derivedSeriesOfIdeal_antitone {k l : ℕ} (h : l ≤ k) : D k I ≤ D l I := derivedSeriesOfIdeal_le (le_refl I) h theorem derivedSeriesOfIdeal_add_le_add (J : LieIdeal R L) (k l : ℕ) : D (k + l) (I + J) ≤ D k I + D l J := by let D₁ : LieIdeal R L →o LieIdeal R L := { toFun := fun I => ⁅I, I⁆ monotone' := fun I J h => LieSubmodule.mono_lie h h } have h₁ : ∀ I J : LieIdeal R L, D₁ (I ⊔ J) ≤ D₁ I ⊔ J := by simp [D₁, LieSubmodule.lie_le_right, LieSubmodule.lie_le_left, le_sup_of_le_right] rw [← D₁.iterate_sup_le_sup_iff] at h₁ exact h₁ k l I J theorem derivedSeries_of_bot_eq_bot (k : ℕ) : derivedSeriesOfIdeal R L k ⊥ = ⊥ := by rw [eq_bot_iff]; exact derivedSeriesOfIdeal_le_self ⊥ k theorem abelian_iff_derived_one_eq_bot : IsLieAbelian I ↔ derivedSeriesOfIdeal R L 1 I = ⊥ := by rw [derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_zero, LieSubmodule.lie_abelian_iff_lie_self_eq_bot] theorem abelian_iff_derived_succ_eq_bot (I : LieIdeal R L) (k : ℕ) : IsLieAbelian (derivedSeriesOfIdeal R L k I) ↔ derivedSeriesOfIdeal R L (k + 1) I = ⊥ := by rw [add_comm, derivedSeriesOfIdeal_add I 1 k, abelian_iff_derived_one_eq_bot] open TensorProduct in @[simp] theorem derivedSeriesOfIdeal_baseChange {A : Type*} [CommRing A] [Algebra R A] (k : ℕ) : derivedSeriesOfIdeal A (A ⊗[R] L) k (I.baseChange A) = (derivedSeriesOfIdeal R L k I).baseChange A := by induction k with | zero => simp | succ k ih => simp only [derivedSeriesOfIdeal_succ, ih, LieSubmodule.lie_baseChange] open TensorProduct in @[simp] theorem derivedSeries_baseChange {A : Type*} [CommRing A] [Algebra R A] (k : ℕ) : derivedSeries A (A ⊗[R] L) k = (derivedSeries R L k).baseChange A := by rw [derivedSeries_def, derivedSeries_def, ← derivedSeriesOfIdeal_baseChange, LieSubmodule.baseChange_top] end LieAlgebra namespace LieIdeal open LieAlgebra variable {R L} theorem derivedSeries_eq_derivedSeriesOfIdeal_comap (k : ℕ) : derivedSeries R I k = (derivedSeriesOfIdeal R L k I).comap I.incl := by induction k with | zero => simp only [derivedSeries_def, comap_incl_self, derivedSeriesOfIdeal_zero] | succ k ih => simp only [derivedSeries_def, derivedSeriesOfIdeal_succ] at ih ⊢; rw [ih] exact comap_bracket_incl_of_le I (derivedSeriesOfIdeal_le_self I k) (derivedSeriesOfIdeal_le_self I k) theorem derivedSeries_eq_derivedSeriesOfIdeal_map (k : ℕ) : (derivedSeries R I k).map I.incl = derivedSeriesOfIdeal R L k I := by rw [derivedSeries_eq_derivedSeriesOfIdeal_comap, map_comap_incl, inf_eq_right] apply derivedSeriesOfIdeal_le_self theorem derivedSeries_eq_bot_iff (k : ℕ) : derivedSeries R I k = ⊥ ↔ derivedSeriesOfIdeal R L k I = ⊥ := by rw [← derivedSeries_eq_derivedSeriesOfIdeal_map, map_eq_bot_iff, ker_incl, eq_bot_iff] theorem derivedSeries_add_eq_bot {k l : ℕ} {I J : LieIdeal R L} (hI : derivedSeries R I k = ⊥) (hJ : derivedSeries R J l = ⊥) : derivedSeries R (I + J) (k + l) = ⊥ := by rw [LieIdeal.derivedSeries_eq_bot_iff] at hI hJ ⊢ rw [← le_bot_iff] let D := derivedSeriesOfIdeal R L; change D k I = ⊥ at hI; change D l J = ⊥ at hJ calc D (k + l) (I + J) ≤ D k I + D l J := derivedSeriesOfIdeal_add_le_add I J k l _ ≤ ⊥ := by rw [hI, hJ]; simp theorem derivedSeries_map_le (k : ℕ) : (derivedSeries R L' k).map f ≤ derivedSeries R L k := by induction k with | zero => simp only [derivedSeries_def, derivedSeriesOfIdeal_zero, le_top] | succ k ih => simp only [derivedSeries_def, derivedSeriesOfIdeal_succ] at ih ⊢ exact le_trans (map_bracket_le f) (LieSubmodule.mono_lie ih ih) theorem derivedSeries_map_eq (k : ℕ) (h : Function.Surjective f) : (derivedSeries R L' k).map f = derivedSeries R L k := by induction k with | zero => change (⊤ : LieIdeal R L').map f = ⊤ rw [← f.idealRange_eq_map] exact f.idealRange_eq_top_of_surjective h | succ k ih => simp only [derivedSeries_def, map_bracket_eq f h, ih, derivedSeriesOfIdeal_succ] theorem derivedSeries_succ_eq_top_iff (n : ℕ) : derivedSeries R L (n + 1) = ⊤ ↔ derivedSeries R L 1 = ⊤ := by simp only [derivedSeries_def] induction n with | zero => simp | succ n ih => rw [derivedSeriesOfIdeal_succ] refine ⟨fun h ↦ ?_, fun h ↦ by rwa [ih.mpr h]⟩ rw [← ih, eq_top_iff] conv_lhs => rw [← h] exact LieSubmodule.lie_le_right _ _ theorem derivedSeries_eq_top (n : ℕ) (h : derivedSeries R L 1 = ⊤) : derivedSeries R L n = ⊤ := by cases n · rfl · rwa [derivedSeries_succ_eq_top_iff] private theorem coe_derivedSeries_eq_int_aux (R₁ R₂ L : Type*) [CommRing R₁] [CommRing R₂] [LieRing L] [LieAlgebra R₁ L] [LieAlgebra R₂ L] (k : ℕ) (ih : ∀ (x : L), x ∈ derivedSeriesOfIdeal R₁ L k ⊤ ↔ x ∈ derivedSeriesOfIdeal R₂ L k ⊤) : let I := derivedSeriesOfIdeal R₂ L k ⊤; let S : Set L := {⁅a, b⁆ | (a ∈ I) (b ∈ I)} (Submodule.span R₁ S : Set L) ≤ (Submodule.span R₂ S : Set L) := by intro I S x hx simp only [SetLike.mem_coe] at hx ⊢ induction hx using Submodule.closure_induction with | zero => exact Submodule.zero_mem _ | add y z hy₁ hz₁ hy₂ hz₂ => exact Submodule.add_mem _ hy₂ hz₂ | smul_mem c y hy => obtain ⟨a, ha, b, hb, rfl⟩ := hy rw [← smul_lie] refine Submodule.subset_span ⟨c • a, ?_, b, hb, rfl⟩ rw [← ih] at ha ⊢ exact Submodule.smul_mem _ _ ha theorem coe_derivedSeries_eq_int (k : ℕ) : (derivedSeries R L k : Set L) = (derivedSeries ℤ L k : Set L) := by rw [← LieSubmodule.coe_toSubmodule, ← LieSubmodule.coe_toSubmodule, derivedSeries_def, derivedSeries_def] induction k with | zero => rfl | succ k ih => rw [derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_succ] rw [LieSubmodule.lieIdeal_oper_eq_linear_span', LieSubmodule.lieIdeal_oper_eq_linear_span'] rw [Set.ext_iff] at ih simp only [SetLike.mem_coe, LieSubmodule.mem_toSubmodule] at ih simp only [ih] apply le_antisymm · exact coe_derivedSeries_eq_int_aux _ _ L k ih · simp only [← ih] apply coe_derivedSeries_eq_int_aux _ _ L k simp [ih] end LieIdeal namespace LieAlgebra /-- A Lie algebra is solvable if its derived series reaches 0 (in a finite number of steps). -/ @[mk_iff isSolvable_iff_int] class IsSolvable : Prop where mk_int :: solvable_int : ∃ k, derivedSeries ℤ L k = ⊥ instance isSolvableBot : IsSolvable (⊥ : LieIdeal R L) := ⟨⟨0, Subsingleton.elim _ ⊥⟩⟩ lemma isSolvable_iff : IsSolvable L ↔ ∃ k, derivedSeries R L k = ⊥ := by simp [isSolvable_iff_int, SetLike.ext'_iff, LieIdeal.coe_derivedSeries_eq_int] lemma IsSolvable.solvable [IsSolvable L] : ∃ k, derivedSeries R L k = ⊥ := (isSolvable_iff R L).mp ‹_› variable {R L} in lemma IsSolvable.mk {k : ℕ} (h : derivedSeries R L k = ⊥) : IsSolvable L := (isSolvable_iff R L).mpr ⟨k, h⟩ instance isSolvableAdd {I J : LieIdeal R L} [IsSolvable I] [IsSolvable J] : IsSolvable (I + J) := by obtain ⟨k, hk⟩ := IsSolvable.solvable R I obtain ⟨l, hl⟩ := IsSolvable.solvable R J exact IsSolvable.mk (LieIdeal.derivedSeries_add_eq_bot hk hl) theorem derivedSeries_lt_top_of_solvable [IsSolvable L] [Nontrivial L] : derivedSeries R L 1 < ⊤ := by obtain ⟨n, hn⟩ := IsSolvable.solvable (R := R) (L := L) rw [lt_top_iff_ne_top] intro contra rw [LieIdeal.derivedSeries_eq_top n contra] at hn exact top_ne_bot hn open TensorProduct in instance {A : Type*} [CommRing A] [Algebra R A] [IsSolvable L] : IsSolvable (A ⊗[R] L) := by obtain ⟨k, hk⟩ := IsSolvable.solvable R L rw [isSolvable_iff A] use k rw [derivedSeries_baseChange, hk, LieSubmodule.baseChange_bot] open TensorProduct in variable {A : Type*} [CommRing A] [Algebra R A] [Module.FaithfullyFlat R A] in theorem isSolvable_tensorProduct_iff : IsSolvable (A ⊗[R] L) ↔ IsSolvable L := by refine ⟨?_, fun _ ↦ inferInstance⟩ rw [isSolvable_iff A, isSolvable_iff R] rintro ⟨k, h⟩ use k rw [eq_bot_iff] at h ⊢ intro x hx rw [derivedSeries_baseChange] at h specialize h <| Submodule.tmul_mem_baseChange_of_mem 1 hx rw [LieSubmodule.mem_bot] at h ⊢ rwa [Module.FaithfullyFlat.one_tmul_eq_zero_iff] at h end LieAlgebra variable {R L} namespace Function open LieAlgebra theorem Injective.lieAlgebra_isSolvable [hL : IsSolvable L] (h : Injective f) : IsSolvable L' := by rw [isSolvable_iff R] at hL ⊢ apply hL.imp intro k hk apply LieIdeal.bot_of_map_eq_bot h; rw [eq_bot_iff, ← hk] apply LieIdeal.derivedSeries_map_le instance (A : LieIdeal R L) [IsSolvable L] : IsSolvable A := A.incl_injective.lieAlgebra_isSolvable theorem Surjective.lieAlgebra_isSolvable [hL' : IsSolvable L'] (h : Surjective f) : IsSolvable L := by rw [isSolvable_iff R] at hL' ⊢ apply hL'.imp intro k hk rw [← LieIdeal.derivedSeries_map_eq k h, hk] simp only [LieIdeal.map_eq_bot_iff, bot_le] end Function instance LieHom.isSolvable_range (f : L' →ₗ⁅R⁆ L) [LieAlgebra.IsSolvable L'] : LieAlgebra.IsSolvable f.range := f.surjective_rangeRestrict.lieAlgebra_isSolvable namespace LieAlgebra theorem solvable_iff_equiv_solvable (e : L' ≃ₗ⁅R⁆ L) : IsSolvable L' ↔ IsSolvable L := by constructor <;> intro h · exact e.symm.injective.lieAlgebra_isSolvable · exact e.injective.lieAlgebra_isSolvable theorem le_solvable_ideal_solvable {I J : LieIdeal R L} (h₁ : I ≤ J) (_ : IsSolvable J) : IsSolvable I := (LieIdeal.inclusion_injective h₁).lieAlgebra_isSolvable variable (R L) instance (priority := 100) ofAbelianIsSolvable [IsLieAbelian L] : IsSolvable L := by use 1 rw [← abelian_iff_derived_one_eq_bot, lie_abelian_iff_equiv_lie_abelian LieIdeal.topEquiv] infer_instance /-- The (solvable) radical of Lie algebra is the `sSup` of all solvable ideals. -/ def radical := sSup { I : LieIdeal R L | IsSolvable I } /-- The radical of a Noetherian Lie algebra is solvable. -/ instance radicalIsSolvable [IsNoetherian R L] : IsSolvable (radical R L) := by have hwf := LieSubmodule.wellFoundedGT_of_noetherian R L L rw [← CompleteLattice.isSupClosedCompact_iff_wellFoundedGT] at hwf refine hwf { I : LieIdeal R L | IsSolvable I } ⟨⊥, ?_⟩ fun I hI J hJ => ?_ · exact LieAlgebra.isSolvableBot R L · rw [Set.mem_setOf_eq] at hI hJ ⊢ apply LieAlgebra.isSolvableAdd R L /-- The `→` direction of this lemma is actually true without the `IsNoetherian` assumption. -/ theorem LieIdeal.solvable_iff_le_radical [IsNoetherian R L] (I : LieIdeal R L) : IsSolvable I ↔ I ≤ radical R L := ⟨fun h => le_sSup h, fun h => le_solvable_ideal_solvable h inferInstance⟩ theorem center_le_radical : center R L ≤ radical R L := have h : IsSolvable (center R L) := inferInstance le_sSup h instance [IsSolvable L] : IsSolvable (⊤ : LieSubalgebra R L) := by rwa [solvable_iff_equiv_solvable LieSubalgebra.topEquiv] @[simp] lemma radical_eq_top_of_isSolvable [IsSolvable L] : radical R L = ⊤ := by rw [eq_top_iff] have h : IsSolvable (⊤ : LieSubalgebra R L) := inferInstance exact le_sSup h /-- Given a solvable Lie ideal `I` with derived series `I = D₀ ≥ D₁ ≥ ⋯ ≥ Dₖ = ⊥`, this is the natural number `k` (the number of inclusions). For a non-solvable ideal, the value is 0. -/ noncomputable def derivedLengthOfIdeal (I : LieIdeal R L) : ℕ := sInf { k | derivedSeriesOfIdeal R L k I = ⊥ } /-- The derived length of a Lie algebra is the derived length of its 'top' Lie ideal. See also `LieAlgebra.derivedLength_eq_derivedLengthOfIdeal`. -/ noncomputable abbrev derivedLength : ℕ := derivedLengthOfIdeal R L ⊤ theorem derivedSeries_of_derivedLength_succ (I : LieIdeal R L) (k : ℕ) : derivedLengthOfIdeal R L I = k + 1 ↔ IsLieAbelian (derivedSeriesOfIdeal R L k I) ∧ derivedSeriesOfIdeal R L k I ≠ ⊥ := by rw [abelian_iff_derived_succ_eq_bot] let s := { k | derivedSeriesOfIdeal R L k I = ⊥ } change sInf s = k + 1 ↔ k + 1 ∈ s ∧ k ∉ s have hs : ∀ k₁ k₂ : ℕ, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s := by intro k₁ k₂ h₁₂ h₁ suffices derivedSeriesOfIdeal R L k₂ I ≤ ⊥ by exact eq_bot_iff.mpr this change derivedSeriesOfIdeal R L k₁ I = ⊥ at h₁; rw [← h₁] exact derivedSeriesOfIdeal_antitone I h₁₂ exact Nat.sInf_upward_closed_eq_succ_iff hs k theorem derivedLength_eq_derivedLengthOfIdeal (I : LieIdeal R L) : derivedLength R I = derivedLengthOfIdeal R L I := by let s₁ := { k | derivedSeries R I k = ⊥ } let s₂ := { k | derivedSeriesOfIdeal R L k I = ⊥ } change sInf s₁ = sInf s₂ congr; ext k; exact I.derivedSeries_eq_bot_iff k variable {R L} /-- Given a solvable Lie ideal `I` with derived series `I = D₀ ≥ D₁ ≥ ⋯ ≥ Dₖ = ⊥`, this is the `k-1`th term in the derived series (and is therefore an Abelian ideal contained in `I`). For a non-solvable ideal, this is the zero ideal, `⊥`. -/ noncomputable def derivedAbelianOfIdeal (I : LieIdeal R L) : LieIdeal R L := match derivedLengthOfIdeal R L I with | 0 => ⊥ | k + 1 => derivedSeriesOfIdeal R L k I instance : Unique {x // x ∈ (⊥ : LieIdeal R L)} := inferInstanceAs <| Unique {x // x ∈ (⊥ : Submodule R L)} theorem abelian_derivedAbelianOfIdeal (I : LieIdeal R L) : IsLieAbelian (derivedAbelianOfIdeal I) := by dsimp only [derivedAbelianOfIdeal] rcases h : derivedLengthOfIdeal R L I with - | k · dsimp; infer_instance · rw [derivedSeries_of_derivedLength_succ] at h; exact h.1 theorem derivedLength_zero (I : LieIdeal R L) [IsSolvable I] : derivedLengthOfIdeal R L I = 0 ↔ I = ⊥ := by let s := { k | derivedSeriesOfIdeal R L k I = ⊥ } change sInf s = 0 ↔ _ have hne : s ≠ ∅ := by obtain ⟨k, hk⟩ := IsSolvable.solvable R I refine Set.Nonempty.ne_empty ⟨k, ?_⟩ rw [derivedSeries_def, LieIdeal.derivedSeries_eq_bot_iff] at hk; exact hk simp [s, hne] theorem abelian_of_solvable_ideal_eq_bot_iff (I : LieIdeal R L) [h : IsSolvable I] : derivedAbelianOfIdeal I = ⊥ ↔ I = ⊥ := by dsimp only [derivedAbelianOfIdeal] split · simp_all only [derivedLength_zero] · rename_i k h obtain ⟨_, h₂⟩ := (derivedSeries_of_derivedLength_succ R L I k).mp h have h₃ : I ≠ ⊥ := by rintro rfl; apply h₂; apply derivedSeries_of_bot_eq_bot simp only [h₂, h₃] end LieAlgebra
Map.lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jeremy Avigad -/ import Mathlib.Control.Basic import Mathlib.Data.Set.Lattice.Image import Mathlib.Order.Filter.Basic /-! # Theorems about map and comap on filters. -/ assert_not_exists OrderedSemiring Fintype open Function Set Order open scoped symmDiff universe u v w x y namespace Filter variable {α β γ δ : Type*} {ι : Sort*} {F : Filter α} {G : Filter β} /-! ### Push-forwards, pull-backs, and the monad structure -/ section Map @[simp] theorem map_principal {s : Set α} {f : α → β} : map f (𝓟 s) = 𝓟 (Set.image f s) := Filter.ext fun _ => image_subset_iff.symm variable {f : Filter α} {m : α → β} {m' : β → γ} {s : Set α} {t : Set β} @[simp] theorem eventually_map {P : β → Prop} : (∀ᶠ b in map m f, P b) ↔ ∀ᶠ a in f, P (m a) := Iff.rfl @[simp] theorem frequently_map {P : β → Prop} : (∃ᶠ b in map m f, P b) ↔ ∃ᶠ a in f, P (m a) := Iff.rfl @[simp] theorem eventuallyEq_map {f₁ f₂ : β → γ} : f₁ =ᶠ[map m f] f₂ ↔ f₁ ∘ m =ᶠ[f] f₂ ∘ m := .rfl @[simp] theorem eventuallyLE_map [LE γ] {f₁ f₂ : β → γ} : f₁ ≤ᶠ[map m f] f₂ ↔ f₁ ∘ m ≤ᶠ[f] f₂ ∘ m := .rfl @[simp] theorem mem_map : t ∈ map m f ↔ m ⁻¹' t ∈ f := Iff.rfl theorem mem_map' : t ∈ map m f ↔ { x | m x ∈ t } ∈ f := Iff.rfl theorem image_mem_map (hs : s ∈ f) : m '' s ∈ map m f := f.sets_of_superset hs <| subset_preimage_image m s -- The simpNF linter says that the LHS can be simplified via `Filter.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 @[simp 1100, nolint simpNF] theorem image_mem_map_iff (hf : Injective m) : m '' s ∈ map m f ↔ s ∈ f := ⟨fun h => by rwa [← preimage_image_eq s hf], image_mem_map⟩ theorem range_mem_map : range m ∈ map m f := by rw [← image_univ] exact image_mem_map univ_mem theorem mem_map_iff_exists_image : t ∈ map m f ↔ ∃ s ∈ f, m '' s ⊆ t := ⟨fun ht => ⟨m ⁻¹' t, ht, image_preimage_subset _ _⟩, fun ⟨_, hs, ht⟩ => mem_of_superset (image_mem_map hs) ht⟩ @[simp] theorem map_id : Filter.map id f = f := filter_eq <| rfl @[simp] theorem map_id' : Filter.map (fun x => x) f = f := map_id @[simp] theorem map_compose : Filter.map m' ∘ Filter.map m = Filter.map (m' ∘ m) := funext fun _ => filter_eq <| rfl @[simp] theorem map_map : Filter.map m' (Filter.map m f) = Filter.map (m' ∘ m) f := congr_fun Filter.map_compose f /-- If functions `m₁` and `m₂` are eventually equal at a filter `f`, then they map this filter to the same filter. -/ theorem map_congr {m₁ m₂ : α → β} {f : Filter α} (h : m₁ =ᶠ[f] m₂) : map m₁ f = map m₂ f := Filter.ext' fun _ => eventually_congr (h.mono fun _ hx => hx ▸ Iff.rfl) end Map section Comap variable {f : α → β} {l : Filter β} {p : α → Prop} {s : Set α} theorem mem_comap' : s ∈ comap f l ↔ { y | ∀ ⦃x⦄, f x = y → x ∈ s } ∈ l := ⟨fun ⟨t, ht, hts⟩ => mem_of_superset ht fun y hy x hx => hts <| mem_preimage.2 <| by rwa [hx], fun h => ⟨_, h, fun _ hx => hx rfl⟩⟩ -- TODO: it would be nice to use `kernImage` much more to take advantage of common name and API, -- and then this would become `mem_comap'` theorem mem_comap'' : s ∈ comap f l ↔ kernImage f s ∈ l := mem_comap' /-- RHS form is used, e.g., in the definition of `UniformSpace`. -/ lemma mem_comap_prodMk {x : α} {s : Set β} {F : Filter (α × β)} : s ∈ comap (Prod.mk x) F ↔ {p : α × β | p.fst = x → p.snd ∈ s} ∈ F := by simp_rw [mem_comap', Prod.ext_iff, and_imp, @forall_swap β (_ = _), forall_eq, eq_comm] @[deprecated (since := "2025-03-10")] alias mem_comap_prod_mk := mem_comap_prodMk @[simp] theorem eventually_comap : (∀ᶠ a in comap f l, p a) ↔ ∀ᶠ b in l, ∀ a, f a = b → p a := mem_comap' @[simp] theorem frequently_comap : (∃ᶠ a in comap f l, p a) ↔ ∃ᶠ b in l, ∃ a, f a = b ∧ p a := by simp only [Filter.Frequently, eventually_comap, not_exists, _root_.not_and] theorem mem_comap_iff_compl : s ∈ comap f l ↔ (f '' sᶜ)ᶜ ∈ l := by simp only [mem_comap'', kernImage_eq_compl] theorem compl_mem_comap : sᶜ ∈ comap f l ↔ (f '' s)ᶜ ∈ l := by rw [mem_comap_iff_compl, compl_compl] end Comap instance : LawfulFunctor (Filter : Type u → Type u) where id_map _ := map_id comp_map _ _ _ := map_map.symm map_const := rfl theorem pure_sets (a : α) : (pure a : Filter α).sets = { s | a ∈ s } := rfl @[simp] theorem eventually_pure {a : α} {p : α → Prop} : (∀ᶠ x in pure a, p x) ↔ p a := Iff.rfl @[simp] theorem principal_singleton (a : α) : 𝓟 {a} = pure a := Filter.ext fun s => by simp only [mem_pure, mem_principal, singleton_subset_iff] @[simp] theorem map_pure (f : α → β) (a : α) : map f (pure a) = pure (f a) := rfl theorem pure_le_principal {s : Set α} (a : α) : pure a ≤ 𝓟 s ↔ a ∈ s := by simp @[simp] theorem join_pure (f : Filter α) : join (pure f) = f := rfl @[simp] theorem pure_bind (a : α) (m : α → Filter β) : bind (pure a) m = m a := by simp only [bind, map_pure, join_pure] theorem map_bind {α β} (m : β → γ) (f : Filter α) (g : α → Filter β) : map m (bind f g) = bind f (map m ∘ g) := rfl theorem bind_map {α β} (m : α → β) (f : Filter α) (g : β → Filter γ) : (bind (map m f) g) = bind f (g ∘ m) := rfl /-! ### `Filter` as a `Monad` In this section we define `Filter.monad`, a `Monad` structure on `Filter`s. This definition is not an instance because its `Seq` projection is not equal to the `Filter.seq` function we use in the `Applicative` instance on `Filter`. -/ section /-- The monad structure on filters. -/ protected def monad : Monad Filter where map := @Filter.map attribute [local instance] Filter.monad protected theorem lawfulMonad : LawfulMonad Filter where map_const := rfl id_map _ := rfl seqLeft_eq _ _ := rfl seqRight_eq _ _ := rfl pure_seq _ _ := rfl bind_pure_comp _ _ := rfl bind_map _ _ := rfl pure_bind _ _ := rfl bind_assoc _ _ _ := rfl end instance : Alternative Filter where seq := fun x y => x.seq (y ()) failure := ⊥ orElse x y := x ⊔ y () @[simp] theorem map_def {α β} (m : α → β) (f : Filter α) : m <$> f = map m f := rfl @[simp] theorem bind_def {α β} (f : Filter α) (m : α → Filter β) : f >>= m = bind f m := rfl /-! #### `map` and `comap` equations -/ section Map variable {f f₁ f₂ : Filter α} {g g₁ g₂ : Filter β} {m : α → β} {m' : β → γ} {s : Set α} {t : Set β} @[simp] theorem mem_comap : s ∈ comap m g ↔ ∃ t ∈ g, m ⁻¹' t ⊆ s := Iff.rfl theorem preimage_mem_comap (ht : t ∈ g) : m ⁻¹' t ∈ comap m g := ⟨t, ht, Subset.rfl⟩ theorem Eventually.comap {p : β → Prop} (hf : ∀ᶠ b in g, p b) (f : α → β) : ∀ᶠ a in comap f g, p (f a) := preimage_mem_comap hf theorem comap_id : comap id f = f := le_antisymm (fun _ => preimage_mem_comap) fun _ ⟨_, ht, hst⟩ => mem_of_superset ht hst theorem comap_id' : comap (fun x => x) f = f := comap_id theorem comap_const_of_notMem {x : β} (ht : t ∈ g) (hx : x ∉ t) : comap (fun _ : α => x) g = ⊥ := empty_mem_iff_bot.1 <| mem_comap'.2 <| mem_of_superset ht fun _ hx' _ h => hx <| h.symm ▸ hx' @[deprecated (since := "2025-05-23")] alias comap_const_of_not_mem := comap_const_of_notMem theorem comap_const_of_mem {x : β} (h : ∀ t ∈ g, x ∈ t) : comap (fun _ : α => x) g = ⊤ := top_unique fun _ hs => univ_mem' fun _ => h _ (mem_comap'.1 hs) rfl theorem map_const [NeBot f] {c : β} : (f.map fun _ => c) = pure c := by ext s by_cases h : c ∈ s <;> simp [h] theorem comap_comap {m : γ → β} {n : β → α} : comap m (comap n f) = comap (n ∘ m) f := Filter.coext fun s => by simp only [compl_mem_comap, image_image, (· ∘ ·)] section comm /-! The variables in the following lemmas are used as in this diagram: ``` φ α → β θ ↓ ↓ ψ γ → δ ρ ``` -/ variable {φ : α → β} {θ : α → γ} {ψ : β → δ} {ρ : γ → δ} theorem map_comm (H : ψ ∘ φ = ρ ∘ θ) (F : Filter α) : map ψ (map φ F) = map ρ (map θ F) := by rw [Filter.map_map, H, ← Filter.map_map] theorem comap_comm (H : ψ ∘ φ = ρ ∘ θ) (G : Filter δ) : comap φ (comap ψ G) = comap θ (comap ρ G) := by rw [Filter.comap_comap, H, ← Filter.comap_comap] end comm theorem _root_.Function.Semiconj.filter_map {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (map f) (map ga) (map gb) := map_comm h.comp_eq theorem _root_.Function.Commute.filter_map {f g : α → α} (h : Function.Commute f g) : Function.Commute (map f) (map g) := h.semiconj.filter_map theorem _root_.Function.Semiconj.filter_comap {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (comap f) (comap gb) (comap ga) := comap_comm h.comp_eq.symm theorem _root_.Function.Commute.filter_comap {f g : α → α} (h : Function.Commute f g) : Function.Commute (comap f) (comap g) := h.semiconj.filter_comap section open Filter theorem _root_.Function.LeftInverse.filter_map {f : α → β} {g : β → α} (hfg : LeftInverse g f) : LeftInverse (map g) (map f) := fun F ↦ by rw [map_map, hfg.comp_eq_id, map_id] theorem _root_.Function.LeftInverse.filter_comap {f : α → β} {g : β → α} (hfg : LeftInverse g f) : RightInverse (comap g) (comap f) := fun F ↦ by rw [comap_comap, hfg.comp_eq_id, comap_id] nonrec theorem _root_.Function.RightInverse.filter_map {f : α → β} {g : β → α} (hfg : RightInverse g f) : RightInverse (map g) (map f) := hfg.filter_map nonrec theorem _root_.Function.RightInverse.filter_comap {f : α → β} {g : β → α} (hfg : RightInverse g f) : LeftInverse (comap g) (comap f) := hfg.filter_comap theorem _root_.Set.LeftInvOn.filter_map_Iic {f : α → β} {g : β → α} (hfg : LeftInvOn g f s) : LeftInvOn (map g) (map f) (Iic <| 𝓟 s) := fun F (hF : F ≤ 𝓟 s) ↦ by have : (g ∘ f) =ᶠ[𝓟 s] id := by simpa only [eventuallyEq_principal] using hfg rw [map_map, map_congr (this.filter_mono hF), map_id] nonrec theorem _root_.Set.RightInvOn.filter_map_Iic {f : α → β} {g : β → α} (hfg : RightInvOn g f t) : RightInvOn (map g) (map f) (Iic <| 𝓟 t) := hfg.filter_map_Iic end section KernMap /-- The analog of `Set.kernImage` for filters. A set `s` belongs to `Filter.kernMap m f` if either of the following equivalent conditions hold. 1. There exists a set `t ∈ f` such that `s = Set.kernImage m t`. This is used as a definition. 2. There exists a set `t` such that `tᶜ ∈ f` and `sᶜ = m '' t`, see `Filter.mem_kernMap_iff_compl` and `Filter.compl_mem_kernMap`. This definition is useful because it gives a right adjoint to `Filter.comap`, and because it has a nice interpretation when working with `co-` filters (`Filter.cocompact`, `Filter.cofinite`, ...). For example, `kernMap m (cocompact α)` is the filter generated by the complements of the sets `m '' K` where `K` is a compact subset of `α`. -/ def kernMap (m : α → β) (f : Filter α) : Filter β where sets := (kernImage m) '' f.sets univ_sets := ⟨univ, f.univ_sets, by simp [kernImage_eq_compl]⟩ sets_of_superset := by rintro _ t ⟨s, hs, rfl⟩ hst refine ⟨s ∪ m ⁻¹' t, mem_of_superset hs subset_union_left, ?_⟩ rw [kernImage_union_preimage, union_eq_right.mpr hst] inter_sets := by rintro _ _ ⟨s₁, h₁, rfl⟩ ⟨s₂, h₂, rfl⟩ exact ⟨s₁ ∩ s₂, f.inter_sets h₁ h₂, Set.preimage_kernImage.u_inf⟩ variable {m : α → β} {f : Filter α} theorem mem_kernMap {s : Set β} : s ∈ kernMap m f ↔ ∃ t ∈ f, kernImage m t = s := Iff.rfl theorem mem_kernMap_iff_compl {s : Set β} : s ∈ kernMap m f ↔ ∃ t, tᶜ ∈ f ∧ m '' t = sᶜ := by rw [mem_kernMap, compl_surjective.exists] refine exists_congr (fun x ↦ and_congr_right fun _ ↦ ?_) rw [kernImage_compl, compl_eq_comm, eq_comm] theorem compl_mem_kernMap {s : Set β} : sᶜ ∈ kernMap m f ↔ ∃ t, tᶜ ∈ f ∧ m '' t = s := by simp_rw [mem_kernMap_iff_compl, compl_compl] theorem comap_le_iff_le_kernMap : comap m g ≤ f ↔ g ≤ kernMap m f := by simp [Filter.le_def, mem_comap'', mem_kernMap, -mem_comap] theorem gc_comap_kernMap (m : α → β) : GaloisConnection (comap m) (kernMap m) := fun _ _ ↦ comap_le_iff_le_kernMap theorem kernMap_principal {s : Set α} : kernMap m (𝓟 s) = 𝓟 (kernImage m s) := by refine eq_of_forall_le_iff (fun g ↦ ?_) rw [← comap_le_iff_le_kernMap, le_principal_iff, le_principal_iff, mem_comap''] end KernMap @[simp] theorem comap_principal {t : Set β} : comap m (𝓟 t) = 𝓟 (m ⁻¹' t) := Filter.ext fun _ => ⟨fun ⟨_u, hu, b⟩ => (preimage_mono hu).trans b, fun h => ⟨t, Subset.rfl, h⟩⟩ theorem principal_subtype {α : Type*} (s : Set α) (t : Set s) : 𝓟 t = comap (↑) (𝓟 (((↑) : s → α) '' t)) := by rw [comap_principal, preimage_image_eq _ Subtype.coe_injective] @[simp] theorem comap_pure {b : β} : comap m (pure b) = 𝓟 (m ⁻¹' {b}) := by rw [← principal_singleton, comap_principal] theorem map_le_iff_le_comap : map m f ≤ g ↔ f ≤ comap m g := ⟨fun h _ ⟨_, ht, hts⟩ => mem_of_superset (h ht) hts, fun h _ ht => h ⟨_, ht, Subset.rfl⟩⟩ theorem gc_map_comap (m : α → β) : GaloisConnection (map m) (comap m) := fun _ _ => map_le_iff_le_comap @[mono] theorem map_mono : Monotone (map m) := (gc_map_comap m).monotone_l @[mono] theorem comap_mono : Monotone (comap m) := (gc_map_comap m).monotone_u /-- Temporary lemma that we can tag with `gcongr` -/ @[gcongr] theorem _root_.GCongr.Filter.map_le_map {F G : Filter α} (h : F ≤ G) : map m F ≤ map m G := map_mono h /-- Temporary lemma that we can tag with `gcongr` -/ @[gcongr] theorem _root_.GCongr.Filter.comap_le_comap {F G : Filter β} (h : F ≤ G) : comap m F ≤ comap m G := comap_mono h @[simp] theorem map_bot : map m ⊥ = ⊥ := (gc_map_comap m).l_bot @[simp] theorem map_sup : map m (f₁ ⊔ f₂) = map m f₁ ⊔ map m f₂ := (gc_map_comap m).l_sup @[simp] theorem map_iSup {f : ι → Filter α} : map m (⨆ i, f i) = ⨆ i, map m (f i) := (gc_map_comap m).l_iSup @[simp] theorem map_top (f : α → β) : map f ⊤ = 𝓟 (range f) := by rw [← principal_univ, map_principal, image_univ] @[simp] theorem comap_top : comap m ⊤ = ⊤ := (gc_map_comap m).u_top @[simp] theorem comap_inf : comap m (g₁ ⊓ g₂) = comap m g₁ ⊓ comap m g₂ := (gc_map_comap m).u_inf @[simp] theorem comap_iInf {f : ι → Filter β} : comap m (⨅ i, f i) = ⨅ i, comap m (f i) := (gc_map_comap m).u_iInf theorem le_comap_top (f : α → β) (l : Filter α) : l ≤ comap f ⊤ := by rw [comap_top] exact le_top theorem map_comap_le : map m (comap m g) ≤ g := (gc_map_comap m).l_u_le _ theorem le_comap_map : f ≤ comap m (map m f) := (gc_map_comap m).le_u_l _ @[simp] theorem comap_bot : comap m ⊥ = ⊥ := bot_unique fun s _ => ⟨∅, mem_bot, by simp only [empty_subset, preimage_empty]⟩ theorem neBot_of_comap (h : (comap m g).NeBot) : g.NeBot := by rw [neBot_iff] at * contrapose! h rw [h] exact comap_bot theorem comap_inf_principal_range : comap m (g ⊓ 𝓟 (range m)) = comap m g := by simp theorem disjoint_comap (h : Disjoint g₁ g₂) : Disjoint (comap m g₁) (comap m g₂) := by simp only [disjoint_iff, ← comap_inf, h.eq_bot, comap_bot] theorem comap_iSup {ι} {f : ι → Filter β} {m : α → β} : comap m (iSup f) = ⨆ i, comap m (f i) := (gc_comap_kernMap m).l_iSup theorem comap_sSup {s : Set (Filter β)} {m : α → β} : comap m (sSup s) = ⨆ f ∈ s, comap m f := by simp only [sSup_eq_iSup, comap_iSup] theorem comap_sup : comap m (g₁ ⊔ g₂) = comap m g₁ ⊔ comap m g₂ := by rw [sup_eq_iSup, comap_iSup, iSup_bool_eq, Bool.cond_true, Bool.cond_false] theorem map_comap (f : Filter β) (m : α → β) : (f.comap m).map m = f ⊓ 𝓟 (range m) := by refine le_antisymm (le_inf map_comap_le <| le_principal_iff.2 range_mem_map) ?_ rintro t' ⟨t, ht, sub⟩ refine mem_inf_principal.2 (mem_of_superset ht ?_) rintro _ hxt ⟨x, rfl⟩ exact sub hxt theorem map_comap_setCoe_val (f : Filter β) (s : Set β) : (f.comap ((↑) : s → β)).map (↑) = f ⊓ 𝓟 s := by rw [map_comap, Subtype.range_val] theorem map_comap_of_mem {f : Filter β} {m : α → β} (hf : range m ∈ f) : (f.comap m).map m = f := by rw [map_comap, inf_eq_left.2 (le_principal_iff.2 hf)] instance canLift (c) (p) [CanLift α β c p] : CanLift (Filter α) (Filter β) (map c) fun f => ∀ᶠ x : α in f, p x where prf f hf := ⟨comap c f, map_comap_of_mem <| hf.mono CanLift.prf⟩ theorem comap_le_comap_iff {f g : Filter β} {m : α → β} (hf : range m ∈ f) : comap m f ≤ comap m g ↔ f ≤ g := ⟨fun h => map_comap_of_mem hf ▸ (map_mono h).trans map_comap_le, fun h => comap_mono h⟩ theorem map_comap_of_surjective {f : α → β} (hf : Surjective f) (l : Filter β) : map f (comap f l) = l := map_comap_of_mem <| by simp only [hf.range_eq, univ_mem] theorem comap_injective {f : α → β} (hf : Surjective f) : Injective (comap f) := LeftInverse.injective <| map_comap_of_surjective hf theorem _root_.Function.Surjective.filter_map_top {f : α → β} (hf : Surjective f) : map f ⊤ = ⊤ := (congr_arg _ comap_top).symm.trans <| map_comap_of_surjective hf ⊤ theorem subtype_coe_map_comap (s : Set α) (f : Filter α) : map ((↑) : s → α) (comap ((↑) : s → α) f) = f ⊓ 𝓟 s := by rw [map_comap, Subtype.range_coe] theorem image_mem_of_mem_comap {f : Filter α} {c : β → α} (h : range c ∈ f) {W : Set β} (W_in : W ∈ comap c f) : c '' W ∈ f := by rw [← map_comap_of_mem h] exact image_mem_map W_in theorem image_coe_mem_of_mem_comap {f : Filter α} {U : Set α} (h : U ∈ f) {W : Set U} (W_in : W ∈ comap ((↑) : U → α) f) : (↑) '' W ∈ f := image_mem_of_mem_comap (by simp [h]) W_in theorem comap_map {f : Filter α} {m : α → β} (h : Injective m) : comap m (map m f) = f := le_antisymm (fun s hs => mem_of_superset (preimage_mem_comap <| image_mem_map hs) <| by simp only [preimage_image_eq s h, Subset.rfl]) le_comap_map theorem mem_comap_iff {f : Filter β} {m : α → β} (inj : Injective m) (large : Set.range m ∈ f) {S : Set α} : S ∈ comap m f ↔ m '' S ∈ f := by rw [← image_mem_map_iff inj, map_comap_of_mem large] theorem map_le_map_iff_of_injOn {l₁ l₂ : Filter α} {f : α → β} {s : Set α} (h₁ : s ∈ l₁) (h₂ : s ∈ l₂) (hinj : InjOn f s) : map f l₁ ≤ map f l₂ ↔ l₁ ≤ l₂ := ⟨fun h _t ht => mp_mem h₁ <| mem_of_superset (h <| image_mem_map (inter_mem h₂ ht)) fun _y ⟨_x, ⟨hxs, hxt⟩, hxy⟩ hys => hinj hxs hys hxy ▸ hxt, fun h => map_mono h⟩ theorem map_le_map_iff {f g : Filter α} {m : α → β} (hm : Injective m) : map m f ≤ map m g ↔ f ≤ g := by rw [map_le_iff_le_comap, comap_map hm] theorem map_eq_map_iff_of_injOn {f g : Filter α} {m : α → β} {s : Set α} (hsf : s ∈ f) (hsg : s ∈ g) (hm : InjOn m s) : map m f = map m g ↔ f = g := by simp only [le_antisymm_iff, map_le_map_iff_of_injOn hsf hsg hm, map_le_map_iff_of_injOn hsg hsf hm] theorem map_inj {f g : Filter α} {m : α → β} (hm : Injective m) : map m f = map m g ↔ f = g := map_eq_map_iff_of_injOn univ_mem univ_mem hm.injOn theorem map_injective {m : α → β} (hm : Injective m) : Injective (map m) := fun _ _ => (map_inj hm).1 theorem comap_neBot_iff {f : Filter β} {m : α → β} : NeBot (comap m f) ↔ ∀ t ∈ f, ∃ a, m a ∈ t := by simp only [← forall_mem_nonempty_iff_neBot, mem_comap, forall_exists_index, and_imp] exact ⟨fun h t t_in => h (m ⁻¹' t) t t_in Subset.rfl, fun h s t ht hst => (h t ht).imp hst⟩ theorem comap_neBot {f : Filter β} {m : α → β} (hm : ∀ t ∈ f, ∃ a, m a ∈ t) : NeBot (comap m f) := comap_neBot_iff.mpr hm theorem comap_neBot_iff_frequently {f : Filter β} {m : α → β} : NeBot (comap m f) ↔ ∃ᶠ y in f, y ∈ range m := by simp only [comap_neBot_iff, frequently_iff, mem_range, @and_comm (_ ∈ _), exists_exists_eq_and] theorem comap_neBot_iff_compl_range {f : Filter β} {m : α → β} : NeBot (comap m f) ↔ (range m)ᶜ ∉ f := comap_neBot_iff_frequently theorem comap_eq_bot_iff_compl_range {f : Filter β} {m : α → β} : comap m f = ⊥ ↔ (range m)ᶜ ∈ f := not_iff_not.mp <| neBot_iff.symm.trans comap_neBot_iff_compl_range theorem comap_surjective_eq_bot {f : Filter β} {m : α → β} (hm : Surjective m) : comap m f = ⊥ ↔ f = ⊥ := by rw [comap_eq_bot_iff_compl_range, hm.range_eq, compl_univ, empty_mem_iff_bot] theorem disjoint_comap_iff (h : Surjective m) : Disjoint (comap m g₁) (comap m g₂) ↔ Disjoint g₁ g₂ := by rw [disjoint_iff, disjoint_iff, ← comap_inf, comap_surjective_eq_bot h] theorem NeBot.comap_of_range_mem {f : Filter β} {m : α → β} (_ : NeBot f) (hm : range m ∈ f) : NeBot (comap m f) := comap_neBot_iff_frequently.2 <| Eventually.frequently hm section Sum open Sum @[simp] theorem comap_inl_map_inr : comap inl (map (@inr α β) g) = ⊥ := by ext rw [mem_comap_iff_compl] simp @[simp] theorem comap_inr_map_inl : comap inr (map (@inl α β) f) = ⊥ := by ext rw [mem_comap_iff_compl] simp @[simp] theorem map_inl_inf_map_inr : map inl f ⊓ map inr g = ⊥ := by apply le_bot_iff.mp trans map inl ⊤ ⊓ map inr ⊤ · apply inf_le_inf <;> simp · simp @[simp] theorem map_inr_inf_map_inl : map inr f ⊓ map inl g = ⊥ := by rw [inf_comm, map_inl_inf_map_inr] theorem comap_sumElim_eq (l : Filter γ) (m₁ : α → γ) (m₂ : β → γ) : comap (Sum.elim m₁ m₂) l = map inl (comap m₁ l) ⊔ map inr (comap m₂ l) := by ext s simp_rw [mem_sup, mem_map, mem_comap_iff_compl] simp [image_sumElim] theorem map_comap_inl_sup_map_comap_inr (l : Filter (α ⊕ β)) : map inl (comap inl l) ⊔ map inr (comap inr l) = l := by rw [← comap_sumElim_eq, Sum.elim_inl_inr, comap_id] theorem map_sumElim_eq (l : Filter (α ⊕ β)) (m₁ : α → γ) (m₂ : β → γ) : map (Sum.elim m₁ m₂) l = map m₁ (comap inl l) ⊔ map m₂ (comap inr l) := by rw [← map_comap_inl_sup_map_comap_inr l] simp [map_sup, map_map, comap_sup, (gc_map_comap _).u_l_u_eq_u] end Sum @[simp] theorem comap_fst_neBot_iff {f : Filter α} : (f.comap (Prod.fst : α × β → α)).NeBot ↔ f.NeBot ∧ Nonempty β := by cases isEmpty_or_nonempty β · rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not]; simp [*] · simp [comap_neBot_iff_frequently, *] @[instance] theorem comap_fst_neBot [Nonempty β] {f : Filter α} [NeBot f] : (f.comap (Prod.fst : α × β → α)).NeBot := comap_fst_neBot_iff.2 ⟨‹_›, ‹_›⟩ @[simp] theorem comap_snd_neBot_iff {f : Filter β} : (f.comap (Prod.snd : α × β → β)).NeBot ↔ Nonempty α ∧ f.NeBot := by rcases isEmpty_or_nonempty α with hα | hα · rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not]; simp · simp [comap_neBot_iff_frequently, hα] @[instance] theorem comap_snd_neBot [Nonempty α] {f : Filter β} [NeBot f] : (f.comap (Prod.snd : α × β → β)).NeBot := comap_snd_neBot_iff.2 ⟨‹_›, ‹_›⟩ theorem comap_eval_neBot_iff' {ι : Type*} {α : ι → Type*} {i : ι} {f : Filter (α i)} : (comap (eval i) f).NeBot ↔ (∀ j, Nonempty (α j)) ∧ NeBot f := by rcases isEmpty_or_nonempty (∀ j, α j) with H | H · rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not] simp [← Classical.nonempty_pi] · have : ∀ j, Nonempty (α j) := Classical.nonempty_pi.1 H simp [comap_neBot_iff_frequently, *] @[simp] theorem comap_eval_neBot_iff {ι : Type*} {α : ι → Type*} [∀ j, Nonempty (α j)] {i : ι} {f : Filter (α i)} : (comap (eval i) f).NeBot ↔ NeBot f := by simp [comap_eval_neBot_iff', *] @[instance] theorem comap_eval_neBot {ι : Type*} {α : ι → Type*} [∀ j, Nonempty (α j)] (i : ι) (f : Filter (α i)) [NeBot f] : (comap (eval i) f).NeBot := comap_eval_neBot_iff.2 ‹_› theorem comap_coe_neBot_of_le_principal {s : Set γ} {l : Filter γ} [h : NeBot l] (h' : l ≤ 𝓟 s) : NeBot (comap ((↑) : s → γ) l) := h.comap_of_range_mem <| (@Subtype.range_coe γ s).symm ▸ h' (mem_principal_self s) theorem NeBot.comap_of_surj {f : Filter β} {m : α → β} (hf : NeBot f) (hm : Surjective m) : NeBot (comap m f) := hf.comap_of_range_mem <| univ_mem' hm theorem NeBot.comap_of_image_mem {f : Filter β} {m : α → β} (hf : NeBot f) {s : Set α} (hs : m '' s ∈ f) : NeBot (comap m f) := hf.comap_of_range_mem <| mem_of_superset hs (image_subset_range _ _) @[simp] theorem map_eq_bot_iff : map m f = ⊥ ↔ f = ⊥ := ⟨by rw [← empty_mem_iff_bot, ← empty_mem_iff_bot] exact id, fun h => by simp only [h, map_bot]⟩ theorem map_neBot_iff (f : α → β) {F : Filter α} : NeBot (map f F) ↔ NeBot F := by simp only [neBot_iff, Ne, map_eq_bot_iff] theorem NeBot.map (hf : NeBot f) (m : α → β) : NeBot (map m f) := (map_neBot_iff m).2 hf theorem NeBot.of_map : NeBot (f.map m) → NeBot f := (map_neBot_iff m).1 instance map_neBot [hf : NeBot f] : NeBot (f.map m) := hf.map m theorem sInter_comap_sets (f : α → β) (F : Filter β) : ⋂₀ (comap f F).sets = ⋂ U ∈ F, f ⁻¹' U := by ext x suffices (∀ (A : Set α) (B : Set β), B ∈ F → f ⁻¹' B ⊆ A → x ∈ A) ↔ ∀ B : Set β, B ∈ F → f x ∈ B by simp only [mem_sInter, mem_iInter, Filter.mem_sets, mem_comap, this, and_imp, mem_preimage, exists_imp] constructor · intro h U U_in simpa only [Subset.rfl, forall_prop_of_true, mem_preimage] using h (f ⁻¹' U) U U_in · intro h V U U_in f_U_V exact f_U_V (h U U_in) end Map -- this is a generic rule for monotone functions: theorem map_iInf_le {f : ι → Filter α} {m : α → β} : map m (iInf f) ≤ ⨅ i, map m (f i) := le_iInf fun _ => map_mono <| iInf_le _ _ theorem map_iInf_eq {f : ι → Filter α} {m : α → β} (hf : Directed (· ≥ ·) f) [Nonempty ι] : map m (iInf f) = ⨅ i, map m (f i) := map_iInf_le.antisymm fun s (hs : m ⁻¹' s ∈ iInf f) => let ⟨i, hi⟩ := (mem_iInf_of_directed hf _).1 hs have : ⨅ i, map m (f i) ≤ 𝓟 s := iInf_le_of_le i <| by simpa only [le_principal_iff, mem_map] Filter.le_principal_iff.1 this theorem map_biInf_eq {ι : Type w} {f : ι → Filter α} {m : α → β} {p : ι → Prop} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) { x | p x }) (ne : ∃ i, p i) : map m (⨅ (i) (_ : p i), f i) = ⨅ (i) (_ : p i), map m (f i) := by haveI := nonempty_subtype.2 ne simp only [iInf_subtype'] exact map_iInf_eq h.directed_val theorem map_inf_le {f g : Filter α} {m : α → β} : map m (f ⊓ g) ≤ map m f ⊓ map m g := (@map_mono _ _ m).map_inf_le f g theorem map_inf {f g : Filter α} {m : α → β} (h : Injective m) : map m (f ⊓ g) = map m f ⊓ map m g := by refine map_inf_le.antisymm ?_ rintro t ⟨s₁, hs₁, s₂, hs₂, ht : m ⁻¹' t = s₁ ∩ s₂⟩ refine mem_inf_of_inter (image_mem_map hs₁) (image_mem_map hs₂) ?_ rw [← image_inter h, image_subset_iff, ht] theorem map_inf' {f g : Filter α} {m : α → β} {t : Set α} (htf : t ∈ f) (htg : t ∈ g) (h : InjOn m t) : map m (f ⊓ g) = map m f ⊓ map m g := by lift f to Filter t using htf; lift g to Filter t using htg replace h : Injective (m ∘ ((↑) : t → α)) := h.injective simp only [map_map, ← map_inf Subtype.coe_injective, map_inf h] lemma disjoint_of_map {α β : Type*} {F G : Filter α} {f : α → β} (h : Disjoint (map f F) (map f G)) : Disjoint F G := disjoint_iff.mpr <| map_eq_bot_iff.mp <| le_bot_iff.mp <| trans map_inf_le (disjoint_iff.mp h) theorem disjoint_map {m : α → β} (hm : Injective m) {f₁ f₂ : Filter α} : Disjoint (map m f₁) (map m f₂) ↔ Disjoint f₁ f₂ := by simp only [disjoint_iff, ← map_inf hm, map_eq_bot_iff] theorem map_equiv_symm (e : α ≃ β) (f : Filter β) : map e.symm f = comap e f := map_injective e.injective <| by rw [map_map, e.self_comp_symm, map_id, map_comap_of_surjective e.surjective] theorem map_eq_comap_of_inverse {f : Filter α} {m : α → β} {n : β → α} (h₁ : m ∘ n = id) (h₂ : n ∘ m = id) : map m f = comap n f := map_equiv_symm ⟨n, m, congr_fun h₁, congr_fun h₂⟩ f theorem comap_equiv_symm (e : α ≃ β) (f : Filter α) : comap e.symm f = map e f := (map_eq_comap_of_inverse e.self_comp_symm e.symm_comp_self).symm theorem map_swap_eq_comap_swap {f : Filter (α × β)} : map Prod.swap f = comap Prod.swap f := map_eq_comap_of_inverse Prod.swap_swap_eq Prod.swap_swap_eq /-- A useful lemma when dealing with uniformities. -/ theorem map_swap4_eq_comap {f : Filter ((α × β) × γ × δ)} : map (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) f = comap (fun p : (α × γ) × β × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) f := map_eq_comap_of_inverse (funext fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl) (funext fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl) theorem le_map {f : Filter α} {m : α → β} {g : Filter β} (h : ∀ s ∈ f, m '' s ∈ g) : g ≤ f.map m := fun _ hs => mem_of_superset (h _ hs) <| image_preimage_subset _ _ theorem le_map_iff {f : Filter α} {m : α → β} {g : Filter β} : g ≤ f.map m ↔ ∀ s ∈ f, m '' s ∈ g := ⟨fun h _ hs => h (image_mem_map hs), le_map⟩ protected theorem push_pull (f : α → β) (F : Filter α) (G : Filter β) : map f (F ⊓ comap f G) = map f F ⊓ G := by apply le_antisymm · calc map f (F ⊓ comap f G) ≤ map f F ⊓ (map f <| comap f G) := map_inf_le _ ≤ map f F ⊓ G := inf_le_inf_left (map f F) map_comap_le · rintro U ⟨V, V_in, W, ⟨Z, Z_in, hZ⟩, h⟩ apply mem_inf_of_inter (image_mem_map V_in) Z_in calc f '' V ∩ Z = f '' (V ∩ f ⁻¹' Z) := by rw [image_inter_preimage] _ ⊆ f '' (V ∩ W) := by gcongr _ = f '' (f ⁻¹' U) := by rw [h] _ ⊆ U := image_preimage_subset f U protected theorem push_pull' (f : α → β) (F : Filter α) (G : Filter β) : map f (comap f G ⊓ F) = G ⊓ map f F := by simp only [Filter.push_pull, inf_comm] theorem disjoint_comap_iff_map {f : α → β} {F : Filter α} {G : Filter β} : Disjoint F (comap f G) ↔ Disjoint (map f F) G := by simp only [disjoint_iff, ← Filter.push_pull, map_eq_bot_iff] theorem disjoint_comap_iff_map' {f : α → β} {F : Filter α} {G : Filter β} : Disjoint (comap f G) F ↔ Disjoint G (map f F) := by simp only [disjoint_iff, ← Filter.push_pull', map_eq_bot_iff] theorem neBot_inf_comap_iff_map {f : α → β} {F : Filter α} {G : Filter β} : NeBot (F ⊓ comap f G) ↔ NeBot (map f F ⊓ G) := by rw [← map_neBot_iff, Filter.push_pull] theorem neBot_inf_comap_iff_map' {f : α → β} {F : Filter α} {G : Filter β} : NeBot (comap f G ⊓ F) ↔ NeBot (G ⊓ map f F) := by rw [← map_neBot_iff, Filter.push_pull'] theorem comap_inf_principal_neBot_of_image_mem {f : Filter β} {m : α → β} (hf : NeBot f) {s : Set α} (hs : m '' s ∈ f) : NeBot (comap m f ⊓ 𝓟 s) := by rw [neBot_inf_comap_iff_map', map_principal, ← frequently_mem_iff_neBot] exact Eventually.frequently hs theorem principal_eq_map_coe_top (s : Set α) : 𝓟 s = map ((↑) : s → α) ⊤ := by simp theorem inf_principal_eq_bot_iff_comap {F : Filter α} {s : Set α} : F ⊓ 𝓟 s = ⊥ ↔ comap ((↑) : s → α) F = ⊥ := by rw [principal_eq_map_coe_top s, ← Filter.push_pull', inf_top_eq, map_eq_bot_iff] lemma map_generate_le_generate_preimage_preimage (U : Set (Set β)) (f : β → α) : map f (generate U) ≤ generate ((f ⁻¹' ·) ⁻¹' U) := by rw [le_generate_iff] exact fun u hu ↦ mem_generate_of_mem hu lemma generate_image_preimage_le_comap (U : Set (Set α)) (f : β → α) : generate ((f ⁻¹' ·) '' U) ≤ comap f (generate U) := by rw [← map_le_iff_le_comap, le_generate_iff] exact fun u hu ↦ mem_generate_of_mem ⟨u, hu, rfl⟩ section Applicative theorem singleton_mem_pure {a : α} : {a} ∈ (pure a : Filter α) := mem_singleton a theorem pure_injective : Injective (pure : α → Filter α) := fun a _ hab => (Filter.ext_iff.1 hab { x | a = x }).1 rfl instance pure_neBot {α : Type u} {a : α} : NeBot (pure a) := ⟨mt empty_mem_iff_bot.2 <| notMem_empty a⟩ @[simp] theorem le_pure_iff {f : Filter α} {a : α} : f ≤ pure a ↔ {a} ∈ f := by rw [← principal_singleton, le_principal_iff] theorem mem_seq_def {f : Filter (α → β)} {g : Filter α} {s : Set β} : s ∈ f.seq g ↔ ∃ u ∈ f, ∃ t ∈ g, ∀ x ∈ u, ∀ y ∈ t, (x : α → β) y ∈ s := Iff.rfl theorem mem_seq_iff {f : Filter (α → β)} {g : Filter α} {s : Set β} : s ∈ f.seq g ↔ ∃ u ∈ f, ∃ t ∈ g, Set.seq u t ⊆ s := by simp only [mem_seq_def, seq_subset] theorem mem_map_seq_iff {f : Filter α} {g : Filter β} {m : α → β → γ} {s : Set γ} : s ∈ (f.map m).seq g ↔ ∃ t u, t ∈ g ∧ u ∈ f ∧ ∀ x ∈ u, ∀ y ∈ t, m x y ∈ s := Iff.intro (fun ⟨t, ht, s, hs, hts⟩ => ⟨s, m ⁻¹' t, hs, ht, fun _ => hts _⟩) fun ⟨t, s, ht, hs, hts⟩ => ⟨m '' s, image_mem_map hs, t, ht, fun _ ⟨_, has, Eq⟩ => Eq ▸ hts _ has⟩ theorem seq_mem_seq {f : Filter (α → β)} {g : Filter α} {s : Set (α → β)} {t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s.seq t ∈ f.seq g := ⟨s, hs, t, ht, fun f hf a ha => ⟨f, hf, a, ha, rfl⟩⟩ theorem le_seq {f : Filter (α → β)} {g : Filter α} {h : Filter β} (hh : ∀ t ∈ f, ∀ u ∈ g, Set.seq t u ∈ h) : h ≤ seq f g := fun _ ⟨_, ht, _, hu, hs⟩ => mem_of_superset (hh _ ht _ hu) fun _ ⟨_, hm, _, ha, eq⟩ => eq ▸ hs _ hm _ ha @[mono] theorem seq_mono {f₁ f₂ : Filter (α → β)} {g₁ g₂ : Filter α} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.seq g₁ ≤ f₂.seq g₂ := le_seq fun _ hs _ ht => seq_mem_seq (hf hs) (hg ht) @[simp] theorem pure_seq_eq_map (g : α → β) (f : Filter α) : seq (pure g) f = f.map g := by refine le_antisymm (le_map fun s hs => ?_) (le_seq fun s hs t ht => ?_) · rw [← singleton_seq] apply seq_mem_seq _ hs exact singleton_mem_pure · refine sets_of_superset (map g f) (image_mem_map ht) ?_ rintro b ⟨a, ha, rfl⟩ exact ⟨g, hs, a, ha, rfl⟩ @[simp] theorem seq_pure (f : Filter (α → β)) (a : α) : seq f (pure a) = map (fun g : α → β => g a) f := by refine le_antisymm (le_map fun s hs => ?_) (le_seq fun s hs t ht => ?_) · rw [← seq_singleton] exact seq_mem_seq hs singleton_mem_pure · refine sets_of_superset (map (fun g : α → β => g a) f) (image_mem_map hs) ?_ rintro b ⟨g, hg, rfl⟩ exact ⟨g, hg, a, ht, rfl⟩ @[simp] theorem seq_assoc (x : Filter α) (g : Filter (α → β)) (h : Filter (β → γ)) : seq h (seq g x) = seq (seq (map (· ∘ ·) h) g) x := by refine le_antisymm (le_seq fun s hs t ht => ?_) (le_seq fun s hs t ht => ?_) · rcases mem_seq_iff.1 hs with ⟨u, hu, v, hv, hs⟩ rcases mem_map_iff_exists_image.1 hu with ⟨w, hw, hu⟩ refine mem_of_superset ?_ (Set.seq_mono ((Set.seq_mono hu Subset.rfl).trans hs) Subset.rfl) rw [← Set.seq_seq] exact seq_mem_seq hw (seq_mem_seq hv ht) · rcases mem_seq_iff.1 ht with ⟨u, hu, v, hv, ht⟩ refine mem_of_superset ?_ (Set.seq_mono Subset.rfl ht) rw [Set.seq_seq] exact seq_mem_seq (seq_mem_seq (image_mem_map hs) hu) hv theorem prod_map_seq_comm (f : Filter α) (g : Filter β) : (map Prod.mk f).seq g = seq (map (fun b a => (a, b)) g) f := by refine le_antisymm (le_seq fun s hs t ht => ?_) (le_seq fun s hs t ht => ?_) · rcases mem_map_iff_exists_image.1 hs with ⟨u, hu, hs⟩ refine mem_of_superset ?_ (Set.seq_mono hs Subset.rfl) rw [← Set.prod_image_seq_comm] exact seq_mem_seq (image_mem_map ht) hu · rcases mem_map_iff_exists_image.1 hs with ⟨u, hu, hs⟩ refine mem_of_superset ?_ (Set.seq_mono hs Subset.rfl) rw [Set.prod_image_seq_comm] exact seq_mem_seq (image_mem_map ht) hu theorem seq_eq_filter_seq {α β : Type u} (f : Filter (α → β)) (g : Filter α) : f <*> g = seq f g := rfl instance : LawfulApplicative (Filter : Type u → Type u) where map_pure := map_pure seqLeft_eq _ _ := rfl seqRight_eq _ _ := rfl seq_pure := seq_pure pure_seq := pure_seq_eq_map seq_assoc := seq_assoc instance : CommApplicative (Filter : Type u → Type u) := ⟨fun f g => prod_map_seq_comm f g⟩ end Applicative /-! #### `bind` equations -/ section Bind @[simp] theorem eventually_bind {f : Filter α} {m : α → Filter β} {p : β → Prop} : (∀ᶠ y in bind f m, p y) ↔ ∀ᶠ x in f, ∀ᶠ y in m x, p y := Iff.rfl @[simp] theorem frequently_bind {f : Filter α} {m : α → Filter β} {p : β → Prop} : (∃ᶠ y in bind f m, p y) ↔ ∃ᶠ x in f, ∃ᶠ y in m x, p y := by rw [← not_iff_not] simp only [not_frequently, eventually_bind] @[simp] theorem eventuallyEq_bind {f : Filter α} {m : α → Filter β} {g₁ g₂ : β → γ} : g₁ =ᶠ[bind f m] g₂ ↔ ∀ᶠ x in f, g₁ =ᶠ[m x] g₂ := Iff.rfl @[simp] theorem eventuallyLE_bind [LE γ] {f : Filter α} {m : α → Filter β} {g₁ g₂ : β → γ} : g₁ ≤ᶠ[bind f m] g₂ ↔ ∀ᶠ x in f, g₁ ≤ᶠ[m x] g₂ := Iff.rfl theorem mem_bind' {s : Set β} {f : Filter α} {m : α → Filter β} : s ∈ bind f m ↔ { a | s ∈ m a } ∈ f := Iff.rfl @[simp] theorem mem_bind {s : Set β} {f : Filter α} {m : α → Filter β} : s ∈ bind f m ↔ ∃ t ∈ f, ∀ x ∈ t, s ∈ m x := calc s ∈ bind f m ↔ { a | s ∈ m a } ∈ f := Iff.rfl _ ↔ ∃ t ∈ f, t ⊆ { a | s ∈ m a } := exists_mem_subset_iff.symm _ ↔ ∃ t ∈ f, ∀ x ∈ t, s ∈ m x := Iff.rfl theorem bind_le {f : Filter α} {g : α → Filter β} {l : Filter β} (h : ∀ᶠ x in f, g x ≤ l) : f.bind g ≤ l := join_le <| eventually_map.2 h @[mono] theorem bind_mono {f₁ f₂ : Filter α} {g₁ g₂ : α → Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ᶠ[f₁] g₂) : bind f₁ g₁ ≤ bind f₂ g₂ := by refine le_trans (fun s hs => ?_) (join_mono <| map_mono hf) simp only [mem_join, mem_bind', mem_map] at hs ⊢ filter_upwards [hg, hs] with _ hx hs using hx hs theorem bind_inf_principal {f : Filter α} {g : α → Filter β} {s : Set β} : (f.bind fun x => g x ⊓ 𝓟 s) = f.bind g ⊓ 𝓟 s := Filter.ext fun s => by simp only [mem_bind, mem_inf_principal] theorem sup_bind {f g : Filter α} {h : α → Filter β} : bind (f ⊔ g) h = bind f h ⊔ bind g h := rfl theorem principal_bind {s : Set α} {f : α → Filter β} : bind (𝓟 s) f = ⨆ x ∈ s, f x := show join (map f (𝓟 s)) = ⨆ x ∈ s, f x by simp only [sSup_image, join_principal_eq_sSup, map_principal] end Bind end Filter open Filter variable {α β : Type*} {F : Filter α} {G : Filter β} -- TODO(Anatole): unify with the global case theorem Filter.map_surjOn_Iic_iff_le_map {m : α → β} : SurjOn (map m) (Iic F) (Iic G) ↔ G ≤ map m F := by refine ⟨fun hm ↦ ?_, fun hm ↦ ?_⟩ · rcases hm right_mem_Iic with ⟨H, (hHF : H ≤ F), rfl⟩ exact map_mono hHF · have : RightInvOn (F ⊓ comap m ·) (map m) (Iic G) := fun H (hHG : H ≤ G) ↦ by simpa [Filter.push_pull] using hHG.trans hm exact this.surjOn fun H _ ↦ mem_Iic.mpr inf_le_left theorem Filter.map_surjOn_Iic_iff_surjOn {s : Set α} {t : Set β} {m : α → β} : SurjOn (map m) (Iic <| 𝓟 s) (Iic <| 𝓟 t) ↔ SurjOn m s t := by rw [map_surjOn_Iic_iff_le_map, map_principal, principal_mono, SurjOn] alias ⟨_, Set.SurjOn.filter_map_Iic⟩ := Filter.map_surjOn_Iic_iff_surjOn theorem Filter.filter_injOn_Iic_iff_injOn {s : Set α} {m : α → β} : InjOn (map m) (Iic <| 𝓟 s) ↔ InjOn m s := by refine ⟨fun hm x hx y hy hxy ↦ ?_, fun hm F hF G hG ↦ ?_⟩ · rwa [← pure_injective.eq_iff, ← map_pure, ← map_pure, hm.eq_iff, pure_injective.eq_iff] at hxy <;> rwa [mem_Iic, pure_le_principal] · simp [map_eq_map_iff_of_injOn (le_principal_iff.mp hF) (le_principal_iff.mp hG) hm] alias ⟨_, Set.InjOn.filter_map_Iic⟩ := Filter.filter_injOn_Iic_iff_injOn
Stirling.lean
/- Copyright (c) 2022 Moritz Firsching. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Firsching, Fabian Kruse, Nikolas Kuhn -/ import Mathlib.Analysis.PSeries import Mathlib.Data.Real.Pi.Wallis import Mathlib.Tactic.AdaptationNote /-! # Stirling's formula This file proves Stirling's formula for the factorial. It states that $n!$ grows asymptotically like $\sqrt{2\pi n}(\frac{n}{e})^n$. ## Proof outline The proof follows: <https://proofwiki.org/wiki/Stirling%27s_Formula>. We proceed in two parts. **Part 1**: We consider the sequence $a_n$ of fractions $\frac{n!}{\sqrt{2n}(\frac{n}{e})^n}$ and prove that this sequence converges to a real, positive number $a$. For this the two main ingredients are - taking the logarithm of the sequence and - using the series expansion of $\log(1 + x)$. **Part 2**: We use the fact that the series defined in part 1 converges against a real number $a$ and prove that $a = \sqrt{\pi}$. Here the main ingredient is the convergence of Wallis' product formula for `π`. -/ open scoped Topology Real Nat Asymptotics open Finset Filter Nat Real namespace Stirling /-! ### Part 1 https://proofwiki.org/wiki/Stirling%27s_Formula#Part_1 -/ /-- Define `stirlingSeq n` as $\frac{n!}{\sqrt{2n}(\frac{n}{e})^n}$. Stirling's formula states that this sequence has limit $\sqrt(π)$. -/ noncomputable def stirlingSeq (n : ℕ) : ℝ := n ! / (√(2 * n : ℝ) * (n / exp 1) ^ n) @[simp] theorem stirlingSeq_zero : stirlingSeq 0 = 0 := by rw [stirlingSeq, cast_zero, mul_zero, Real.sqrt_zero, zero_mul, div_zero] @[simp] theorem stirlingSeq_one : stirlingSeq 1 = exp 1 / √2 := by rw [stirlingSeq, pow_one, factorial_one, cast_one, mul_one, mul_one_div, one_div_div] theorem log_stirlingSeq_formula (n : ℕ) : log (stirlingSeq n) = Real.log n ! - 1 / 2 * Real.log (2 * n) - n * log (n / exp 1) := by cases n · simp · rw [stirlingSeq, log_div, log_mul, sqrt_eq_rpow, log_rpow, Real.log_pow, tsub_tsub] <;> positivity /-- The sequence `log (stirlingSeq (m + 1)) - log (stirlingSeq (m + 2))` has the series expansion `∑ 1 / (2 * (k + 1) + 1) * (1 / 2 * (m + 1) + 1)^(2 * (k + 1))`. -/ theorem log_stirlingSeq_diff_hasSum (m : ℕ) : HasSum (fun k : ℕ => (1 : ℝ) / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ ↑(k + 1)) (log (stirlingSeq (m + 1)) - log (stirlingSeq (m + 2))) := by let f (k : ℕ) := (1 : ℝ) / (2 * k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k change HasSum (fun k => f (k + 1)) _ rw [hasSum_nat_add_iff] convert (hasSum_log_one_add_inv m.cast_add_one_pos).mul_left ((↑(m + 1) : ℝ) + 1 / 2) using 1 · ext k dsimp only [f] rw [← pow_mul, pow_add] push_cast field_simp ring · have h : ∀ x ≠ (0 : ℝ), 1 + x⁻¹ = (x + 1) / x := fun x hx ↦ by field_simp [hx] simp (disch := positivity) only [log_stirlingSeq_formula, log_div, log_mul, log_exp, factorial_succ, cast_mul, cast_succ, range_one, sum_singleton, h] ring /-- The sequence `log ∘ stirlingSeq ∘ succ` is monotone decreasing -/ theorem log_stirlingSeq'_antitone : Antitone (Real.log ∘ stirlingSeq ∘ succ) := antitone_nat_of_succ_le fun n => sub_nonneg.mp <| (log_stirlingSeq_diff_hasSum n).nonneg fun m => by positivity /-- We have a bound for successive elements in the sequence `log (stirlingSeq k)`. -/ theorem log_stirlingSeq_diff_le_geo_sum (n : ℕ) : log (stirlingSeq (n + 1)) - log (stirlingSeq (n + 2)) ≤ ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2 / (1 - ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) := by have h_nonneg : (0 : ℝ) ≤ ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2 := sq_nonneg _ have g : HasSum (fun k : ℕ => (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) ^ ↑(k + 1)) (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2 / (1 - ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2)) := by have := (hasSum_geometric_of_lt_one h_nonneg ?_).mul_left (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) · simp_rw [← _root_.pow_succ'] at this exact this rw [one_div, inv_pow] exact inv_lt_one_of_one_lt₀ (one_lt_pow₀ (lt_add_of_pos_left _ <| by positivity) two_ne_zero) have hab (k : ℕ) : (1 : ℝ) / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(n + 1) + 1)) ^ 2) ^ ↑(k + 1) ≤ (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) ^ ↑(k + 1) := by refine mul_le_of_le_one_left (pow_nonneg h_nonneg ↑(k + 1)) ?_ rw [one_div] exact inv_le_one_of_one_le₀ (le_add_of_nonneg_left <| by positivity) exact hasSum_le hab (log_stirlingSeq_diff_hasSum n) g /-- We have the bound `log (stirlingSeq n) - log (stirlingSeq (n+1))` ≤ 1/(4 n^2) -/ theorem log_stirlingSeq_sub_log_stirlingSeq_succ (n : ℕ) : log (stirlingSeq (n + 1)) - log (stirlingSeq (n + 2)) ≤ 1 / (4 * (↑(n + 1) : ℝ) ^ 2) := by have h₁ : (0 : ℝ) < 4 * ((n : ℝ) + 1) ^ 2 := by positivity have h₃ : (0 : ℝ) < (2 * ((n : ℝ) + 1) + 1) ^ 2 := by positivity have h₂ : (0 : ℝ) < 1 - (1 / (2 * ((n : ℝ) + 1) + 1)) ^ 2 := by rw [← mul_lt_mul_right h₃] have H : 0 < (2 * ((n : ℝ) + 1) + 1) ^ 2 - 1 := by nlinarith [cast_nonneg (α := ℝ) n] convert H using 1 <;> field_simp [h₃.ne'] refine (log_stirlingSeq_diff_le_geo_sum n).trans ?_ push_cast rw [div_le_div_iff₀ h₂ h₁] field_simp [h₃.ne'] rw [div_le_div_iff_of_pos_right h₃] ring_nf norm_cast omega /-- For any `n`, we have `log_stirlingSeq 1 - log_stirlingSeq n ≤ 1/4 * ∑' 1/k^2` -/ theorem log_stirlingSeq_bounded_aux : ∃ c : ℝ, ∀ n : ℕ, log (stirlingSeq 1) - log (stirlingSeq (n + 1)) ≤ c := by let d : ℝ := ∑' k : ℕ, (1 : ℝ) / (↑(k + 1) : ℝ) ^ 2 use 1 / 4 * d let log_stirlingSeq' : ℕ → ℝ := fun k => log (stirlingSeq (k + 1)) intro n have h₁ k : log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ 1 / 4 * (1 / (↑(k + 1) : ℝ) ^ 2) := by convert log_stirlingSeq_sub_log_stirlingSeq_succ k using 1; field_simp have h₂ : (∑ k ∈ range n, 1 / (↑(k + 1) : ℝ) ^ 2) ≤ d := by have := (summable_nat_add_iff 1).mpr <| Real.summable_one_div_nat_pow.mpr one_lt_two exact this.sum_le_tsum (range n) (fun k _ => by positivity) calc log (stirlingSeq 1) - log (stirlingSeq (n + 1)) = log_stirlingSeq' 0 - log_stirlingSeq' n := rfl _ = ∑ k ∈ range n, (log_stirlingSeq' k - log_stirlingSeq' (k + 1)) := by rw [← sum_range_sub' log_stirlingSeq' n] _ ≤ ∑ k ∈ range n, 1 / 4 * (1 / ↑((k + 1)) ^ 2) := sum_le_sum fun k _ => h₁ k _ = 1 / 4 * ∑ k ∈ range n, 1 / ↑((k + 1)) ^ 2 := by rw [mul_sum] _ ≤ 1 / 4 * d := by gcongr /-- The sequence `log_stirlingSeq` is bounded below for `n ≥ 1`. -/ theorem log_stirlingSeq_bounded_by_constant : ∃ c, ∀ n : ℕ, c ≤ log (stirlingSeq (n + 1)) := by obtain ⟨d, h⟩ := log_stirlingSeq_bounded_aux exact ⟨log (stirlingSeq 1) - d, fun n => sub_le_comm.mp (h n)⟩ /-- The sequence `stirlingSeq` is positive for `n > 0` -/ theorem stirlingSeq'_pos (n : ℕ) : 0 < stirlingSeq (n + 1) := by unfold stirlingSeq; positivity /-- The sequence `stirlingSeq` has a positive lower bound. -/ theorem stirlingSeq'_bounded_by_pos_constant : ∃ a, 0 < a ∧ ∀ n : ℕ, a ≤ stirlingSeq (n + 1) := by obtain ⟨c, h⟩ := log_stirlingSeq_bounded_by_constant refine ⟨exp c, exp_pos _, fun n => ?_⟩ rw [← le_log_iff_exp_le (stirlingSeq'_pos n)] exact h n /-- The sequence `stirlingSeq ∘ succ` is monotone decreasing -/ theorem stirlingSeq'_antitone : Antitone (stirlingSeq ∘ succ) := fun n m h => (log_le_log_iff (stirlingSeq'_pos m) (stirlingSeq'_pos n)).mp (log_stirlingSeq'_antitone h) /-- The limit `a` of the sequence `stirlingSeq` satisfies `0 < a` -/ theorem stirlingSeq_has_pos_limit_a : ∃ a : ℝ, 0 < a ∧ Tendsto stirlingSeq atTop (𝓝 a) := by obtain ⟨x, x_pos, hx⟩ := stirlingSeq'_bounded_by_pos_constant have hx' : x ∈ lowerBounds (Set.range (stirlingSeq ∘ succ)) := by simpa [lowerBounds] using hx refine ⟨_, lt_of_lt_of_le x_pos (le_csInf (Set.range_nonempty _) hx'), ?_⟩ rw [← Filter.tendsto_add_atTop_iff_nat 1] exact tendsto_atTop_ciInf stirlingSeq'_antitone ⟨x, hx'⟩ /-! ### Part 2 https://proofwiki.org/wiki/Stirling%27s_Formula#Part_2 -/ /-- The sequence `n / (2 * n + 1)` tends to `1/2` -/ theorem tendsto_self_div_two_mul_self_add_one : Tendsto (fun n : ℕ => (n : ℝ) / (2 * n + 1)) atTop (𝓝 (1 / 2)) := by conv => congr · skip · skip rw [one_div, ← add_zero (2 : ℝ)] refine (((tendsto_const_div_atTop_nhds_zero_nat 1).const_add (2 : ℝ)).inv₀ ((add_zero (2 : ℝ)).symm ▸ two_ne_zero)).congr' (eventually_atTop.mpr ⟨1, fun n hn => ?_⟩) rw [add_div' (1 : ℝ) 2 n (cast_ne_zero.mpr (one_le_iff_ne_zero.mp hn)), inv_div] /-- For any `n ≠ 0`, we have the identity `(stirlingSeq n)^4 / (stirlingSeq (2*n))^2 * (n / (2 * n + 1)) = W n`, where `W n` is the `n`-th partial product of Wallis' formula for `π / 2`. -/ theorem stirlingSeq_pow_four_div_stirlingSeq_pow_two_eq (n : ℕ) (hn : n ≠ 0) : stirlingSeq n ^ 4 / stirlingSeq (2 * n) ^ 2 * (n / (2 * n + 1)) = Wallis.W n := by have : 4 = 2 * 2 := by rfl rw [stirlingSeq, this, pow_mul, stirlingSeq, Wallis.W_eq_factorial_ratio] simp_rw [div_pow, mul_pow] rw [sq_sqrt, sq_sqrt] any_goals positivity field_simp [← exp_nsmul] ring_nf /-- Suppose the sequence `stirlingSeq` (defined above) has the limit `a ≠ 0`. Then the Wallis sequence `W n` has limit `a^2 / 2`. -/ theorem second_wallis_limit (a : ℝ) (hane : a ≠ 0) (ha : Tendsto stirlingSeq atTop (𝓝 a)) : Tendsto Wallis.W atTop (𝓝 (a ^ 2 / 2)) := by refine Tendsto.congr' (eventually_atTop.mpr ⟨1, fun n hn => stirlingSeq_pow_four_div_stirlingSeq_pow_two_eq n (one_le_iff_ne_zero.mp hn)⟩) ?_ have h : a ^ 2 / 2 = a ^ 4 / a ^ 2 * (1 / 2) := by rw [mul_one_div, ← mul_one_div (a ^ 4) (a ^ 2), one_div, ← pow_sub_of_lt a] norm_num rw [h] exact ((ha.pow 4).div ((ha.comp (tendsto_id.const_mul_atTop' two_pos)).pow 2) (pow_ne_zero 2 hane)).mul tendsto_self_div_two_mul_self_add_one /-- **Stirling's Formula** -/ theorem tendsto_stirlingSeq_sqrt_pi : Tendsto stirlingSeq atTop (𝓝 (√π)) := by obtain ⟨a, hapos, halimit⟩ := stirlingSeq_has_pos_limit_a have hπ : π / 2 = a ^ 2 / 2 := tendsto_nhds_unique Wallis.tendsto_W_nhds_pi_div_two (second_wallis_limit a hapos.ne' halimit) rwa [(div_left_inj' (two_ne_zero' ℝ)).mp hπ, sqrt_sq hapos.le] /-- **Stirling's Formula**, formulated in terms of `Asymptotics.IsEquivalent`. -/ lemma factorial_isEquivalent_stirling : (fun n ↦ n ! : ℕ → ℝ) ~[atTop] fun n ↦ Real.sqrt (2 * n * π) * (n / exp 1) ^ n := by refine Asymptotics.isEquivalent_of_tendsto_one ?_ ?_ · filter_upwards [eventually_ne_atTop 0] with n hn h exact absurd h (by positivity) · have : sqrt π ≠ 0 := by positivity nth_rewrite 2 [← div_self this] convert tendsto_stirlingSeq_sqrt_pi.div tendsto_const_nhds this using 1 ext n field_simp [stirlingSeq, mul_right_comm] end Stirling
FixedPoints.lean
/- Copyright (c) 2024 Emilie Burgun. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Emilie Burgun -/ import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Dynamics.PeriodicPts.Defs import Mathlib.GroupTheory.GroupAction.Defs /-! # Properties of `fixedPoints` and `fixedBy` This module contains some useful properties of `MulAction.fixedPoints` and `MulAction.fixedBy` that don't directly belong to `Mathlib/GroupTheory/GroupAction/Basic.lean`. ## Main theorems * `MulAction.fixedBy_mul`: `fixedBy α (g * h) ⊆ fixedBy α g ∪ fixedBy α h` * `MulAction.fixedBy_conj` and `MulAction.smul_fixedBy`: the pointwise group action of `h` on `fixedBy α g` is equal to the `fixedBy` set of the conjugation of `h` with `g` (`fixedBy α (h * g * h⁻¹)`). * `MulAction.set_mem_fixedBy_of_movedBy_subset` shows that if a set `s` is a superset of `(fixedBy α g)ᶜ`, then the group action of `g` cannot send elements of `s` outside of `s`. This is expressed as `s ∈ fixedBy (Set α) g`, and `MulAction.set_mem_fixedBy_iff` allows one to convert the relationship back to `g • x ∈ s ↔ x ∈ s`. * `MulAction.not_commute_of_disjoint_smul_movedBy` allows one to prove that `g` and `h` do not commute from the disjointness of the `(fixedBy α g)ᶜ` set and `h • (fixedBy α g)ᶜ`, which is a property used in the proof of Rubin's theorem. The theorems above are also available for `AddAction`. ## Pointwise group action and `fixedBy (Set α) g` Since `fixedBy α g = { x | g • x = x }` by definition, properties about the pointwise action of a set `s : Set α` can be expressed using `fixedBy (Set α) g`. To properly use theorems using `fixedBy (Set α) g`, you should `open Pointwise` in your file. `s ∈ fixedBy (Set α) g` means that `g • s = s`, which is equivalent to say that `∀ x, g • x ∈ s ↔ x ∈ s` (the translation can be done using `MulAction.set_mem_fixedBy_iff`). `s ∈ fixedBy (Set α) g` is a weaker statement than `s ⊆ fixedBy α g`: the latter requires that all points in `s` are fixed by `g`, whereas the former only requires that `g • x ∈ s`. -/ namespace MulAction open Pointwise variable {α : Type*} variable {G : Type*} [Group G] [MulAction G α] variable {M : Type*} [Monoid M] [MulAction M α] section FixedPoints variable (α) in /-- In a multiplicative group action, the points fixed by `g` are also fixed by `g⁻¹` -/ @[to_additive (attr := simp) /-- In an additive group action, the points fixed by `g` are also fixed by `g⁻¹` -/] theorem fixedBy_inv (g : G) : fixedBy α g⁻¹ = fixedBy α g := by ext rw [mem_fixedBy, mem_fixedBy, inv_smul_eq_iff, eq_comm] @[to_additive] theorem smul_mem_fixedBy_iff_mem_fixedBy {a : α} {g : G} : g • a ∈ fixedBy α g ↔ a ∈ fixedBy α g := by rw [mem_fixedBy, smul_left_cancel_iff] rfl @[to_additive] theorem smul_inv_mem_fixedBy_iff_mem_fixedBy {a : α} {g : G} : g⁻¹ • a ∈ fixedBy α g ↔ a ∈ fixedBy α g := by rw [← fixedBy_inv, smul_mem_fixedBy_iff_mem_fixedBy, fixedBy_inv] @[to_additive minimalPeriod_eq_one_iff_fixedBy] theorem minimalPeriod_eq_one_iff_fixedBy {a : α} {g : G} : Function.minimalPeriod (fun x => g • x) a = 1 ↔ a ∈ fixedBy α g := Function.minimalPeriod_eq_one_iff_isFixedPt variable (α) in @[to_additive] theorem fixedBy_subset_fixedBy_zpow (g : G) (j : ℤ) : fixedBy α g ⊆ fixedBy α (g ^ j) := by intro a a_in_fixedBy rw [mem_fixedBy, zpow_smul_eq_iff_minimalPeriod_dvd, minimalPeriod_eq_one_iff_fixedBy.mpr a_in_fixedBy, Int.natCast_one] exact one_dvd j variable (M α) in @[to_additive (attr := simp)] theorem fixedBy_one_eq_univ : fixedBy α (1 : M) = Set.univ := Set.eq_univ_iff_forall.mpr <| one_smul M variable (α) in @[to_additive] theorem fixedBy_mul (m₁ m₂ : M) : fixedBy α m₁ ∩ fixedBy α m₂ ⊆ fixedBy α (m₁ * m₂) := by intro a ⟨h₁, h₂⟩ rw [mem_fixedBy, mul_smul, h₂, h₁] variable (α) in @[to_additive] theorem smul_fixedBy (g h : G) : h • fixedBy α g = fixedBy α (h * g * h⁻¹) := by ext a simp_rw [Set.mem_smul_set_iff_inv_smul_mem, mem_fixedBy, mul_smul, smul_eq_iff_eq_inv_smul h] end FixedPoints section Pointwise /-! ### `fixedBy` sets of the pointwise group action The theorems below need the `Pointwise` scoped to be opened (using `open Pointwise`) to be used effectively. -/ /-- If a set `s : Set α` is in `fixedBy (Set α) g`, then all points of `s` will stay in `s` after being moved by `g`. -/ @[to_additive /-- If a set `s : Set α` is in `fixedBy (Set α) g`, then all points of `s` will stay in `s` after being moved by `g`. -/] theorem set_mem_fixedBy_iff (s : Set α) (g : G) : s ∈ fixedBy (Set α) g ↔ ∀ x, g • x ∈ s ↔ x ∈ s := by simp_rw [mem_fixedBy, ← eq_inv_smul_iff, Set.ext_iff, Set.mem_inv_smul_set_iff, Iff.comm] @[to_additive] theorem smul_mem_of_set_mem_fixedBy {s : Set α} {g : G} (s_in_fixedBy : s ∈ fixedBy (Set α) g) {x : α} : g • x ∈ s ↔ x ∈ s := (set_mem_fixedBy_iff s g).mp s_in_fixedBy x /-- If `s ⊆ fixedBy α g`, then `g • s = s`, which means that `s ∈ fixedBy (Set α) g`. Note that the reverse implication is in general not true, as `s ∈ fixedBy (Set α) g` is a weaker statement (it allows for points `x ∈ s` for which `g • x ≠ x` and `g • x ∈ s`). -/ @[to_additive /-- If `s ⊆ fixedBy α g`, then `g +ᵥ s = s`, which means that `s ∈ fixedBy (Set α) g`. Note that the reverse implication is in general not true, as `s ∈ fixedBy (Set α) g` is a weaker statement (it allows for points `x ∈ s` for which `g +ᵥ x ≠ x` and `g +ᵥ x ∈ s`). -/] theorem set_mem_fixedBy_of_subset_fixedBy {s : Set α} {g : G} (s_ss_fixedBy : s ⊆ fixedBy α g) : s ∈ fixedBy (Set α) g := by rw [← fixedBy_inv] ext x rw [Set.mem_inv_smul_set_iff] refine ⟨fun gxs => ?xs, fun xs => (s_ss_fixedBy xs).symm ▸ xs⟩ rw [← fixedBy_inv] at s_ss_fixedBy rwa [← s_ss_fixedBy gxs, inv_smul_smul] at gxs theorem smul_subset_of_set_mem_fixedBy {s t : Set α} {g : G} (t_ss_s : t ⊆ s) (s_in_fixedBy : s ∈ fixedBy (Set α) g) : g • t ⊆ s := (Set.smul_set_subset_smul_set_iff.mpr t_ss_s).trans s_in_fixedBy.subset /-! If a set `s : Set α` is a superset of `(MulAction.fixedBy α g)ᶜ` (resp. `(AddAction.fixedBy α g)ᶜ`), then no point or subset of `s` can be moved outside of `s` by the group action of `g`. -/ /-- If `(fixedBy α g)ᶜ ⊆ s`, then `g` cannot move a point of `s` outside of `s`. -/ @[to_additive /-- If `(fixedBy α g)ᶜ ⊆ s`, then `g` cannot move a point of `s` outside of `s`. -/] theorem set_mem_fixedBy_of_movedBy_subset {s : Set α} {g : G} (s_subset : (fixedBy α g)ᶜ ⊆ s) : s ∈ fixedBy (Set α) g := by rw [← fixedBy_inv] ext a rw [Set.mem_inv_smul_set_iff] by_cases a ∈ fixedBy α g case pos a_fixed => rw [a_fixed] case neg a_moved => constructor <;> (intro; apply s_subset) · exact a_moved · rwa [Set.mem_compl_iff, smul_mem_fixedBy_iff_mem_fixedBy] end Pointwise section Commute /-! ## Pointwise image of the `fixedBy` set by a commuting group element If two group elements `g` and `h` commute, then `g` fixes `h • x` (resp. `h +ᵥ x`) if and only if `g` fixes `x`. This is equivalent to say that if `Commute g h`, then `fixedBy α g ∈ fixedBy (Set α) h` and `(fixedBy α g)ᶜ ∈ fixedBy (Set α) h`. -/ /-- If `g` and `h` commute, then `g` fixes `h • x` iff `g` fixes `x`. This is equivalent to say that the set `fixedBy α g` is fixed by `h`. -/ @[to_additive /-- If `g` and `h` commute, then `g` fixes `h +ᵥ x` iff `g` fixes `x`. This is equivalent to say that the set `fixedBy α g` is fixed by `h`. -/] theorem fixedBy_mem_fixedBy_of_commute {g h : G} (comm : Commute g h) : (fixedBy α g) ∈ fixedBy (Set α) h := by ext x rw [Set.mem_smul_set_iff_inv_smul_mem, mem_fixedBy, ← mul_smul, comm.inv_right, mul_smul, smul_left_cancel_iff, mem_fixedBy] /-- If `g` and `h` commute, then `g` fixes `(h ^ j) • x` iff `g` fixes `x`. -/ @[to_additive /-- If `g` and `h` commute, then `g` fixes `(j • h) +ᵥ x` iff `g` fixes `x`. -/] theorem smul_zpow_fixedBy_eq_of_commute {g h : G} (comm : Commute g h) (j : ℤ) : h ^ j • fixedBy α g = fixedBy α g := fixedBy_subset_fixedBy_zpow (Set α) h j (fixedBy_mem_fixedBy_of_commute comm) /-- If `g` and `h` commute, then `g` moves `h • x` iff `g` moves `x`. This is equivalent to say that the set `(fixedBy α g)ᶜ` is fixed by `h`. -/ @[to_additive /-- If `g` and `h` commute, then `g` moves `h +ᵥ x` iff `g` moves `x`. This is equivalent to say that the set `(fixedBy α g)ᶜ` is fixed by `h`. -/] theorem movedBy_mem_fixedBy_of_commute {g h : G} (comm : Commute g h) : (fixedBy α g)ᶜ ∈ fixedBy (Set α) h := by rw [mem_fixedBy, Set.smul_set_compl, fixedBy_mem_fixedBy_of_commute comm] /-- If `g` and `h` commute, then `g` moves `h ^ j • x` iff `g` moves `x`. -/ @[to_additive /-- If `g` and `h` commute, then `g` moves `(j • h) +ᵥ x` iff `g` moves `x`. -/] theorem smul_zpow_movedBy_eq_of_commute {g h : G} (comm : Commute g h) (j : ℤ) : h ^ j • (fixedBy α g)ᶜ = (fixedBy α g)ᶜ := fixedBy_subset_fixedBy_zpow (Set α) h j (movedBy_mem_fixedBy_of_commute comm) end Commute section Faithful variable [FaithfulSMul G α] variable [FaithfulSMul M α] /-- If the multiplicative action of `M` on `α` is faithful, then `fixedBy α m = Set.univ` implies that `m = 1`. -/ @[to_additive /-- If the additive action of `M` on `α` is faithful, then `fixedBy α m = Set.univ` implies that `m = 1`. -/] theorem fixedBy_eq_univ_iff_eq_one {m : M} : fixedBy α m = Set.univ ↔ m = 1 := by rw [← (smul_left_injective' (M := M) (α := α)).eq_iff, Set.eq_univ_iff_forall] simp_rw [funext_iff, one_smul, mem_fixedBy] /-- If the image of the `(fixedBy α g)ᶜ` set by the pointwise action of `h: G` is disjoint from `(fixedBy α g)ᶜ`, then `g` and `h` cannot commute. -/ @[to_additive /-- If the image of the `(fixedBy α g)ᶜ` set by the pointwise action of `h: G` is disjoint from `(fixedBy α g)ᶜ`, then `g` and `h` cannot commute. -/] theorem not_commute_of_disjoint_movedBy_preimage {g h : G} (ne_one : g ≠ 1) (disjoint : Disjoint (fixedBy α g)ᶜ (h • (fixedBy α g)ᶜ)) : ¬Commute g h := by contrapose! ne_one with comm rwa [movedBy_mem_fixedBy_of_commute comm, disjoint_self, Set.bot_eq_empty, ← Set.compl_univ, compl_inj_iff, fixedBy_eq_univ_iff_eq_one] at disjoint end Faithful end MulAction
test_guard.v
From mathcomp Require Import all_boot. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Inductive tree := Node { children : seq tree }. Inductive ptree (T : Type) := singleton of T | branch of list (ptree T). (* has *) Fixpoint tree_has (T : Type) (p : pred T) (t : ptree T) : bool := match t with | singleton x => p x | branch ts => has (tree_has p) ts end. (* all *) Fixpoint tree_all (T : Type) (p : pred T) (t : ptree T) : bool := match t with | singleton x => p x | branch ts => all (tree_all p) ts end. (* map *) Fixpoint traverse_id (t : tree) : tree := Node (map traverse_id (children t)). (* foldr *) Fixpoint tree_foldr (T R : Type) (f : T -> R -> R) (z : R) (t : ptree T) : R := match t with | singleton x => f x z | branch ts => foldr (fun t z' => tree_foldr f z' t) z ts end. (* foldl *) Fixpoint tree_foldl (T R : Type) (f : R -> T -> R) (z : R) (t : ptree T) : R := match t with | singleton x => f z x | branch ts => foldl (tree_foldl f) z ts end. (* all2 *) Fixpoint eq_tree (x y : tree) {struct x} : bool := all2 eq_tree (children x) (children y).
Disjoint.lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Aesop import Mathlib.Order.BoundedOrder.Lattice /-! # Disjointness and complements This file defines `Disjoint`, `Codisjoint`, and the `IsCompl` predicate. ## Main declarations * `Disjoint x y`: two elements of a lattice are disjoint if their `inf` is the bottom element. * `Codisjoint x y`: two elements of a lattice are codisjoint if their `join` is the top element. * `IsCompl x y`: In a bounded lattice, predicate for "`x` is a complement of `y`". Note that in a non distributive lattice, an element can have several complements. * `ComplementedLattice α`: Typeclass stating that any element of a lattice has a complement. -/ open Function variable {α : Type*} section Disjoint section PartialOrderBot variable [PartialOrder α] [OrderBot α] {a b c d : α} /-- Two elements of a lattice are disjoint if their inf is the bottom element. (This generalizes disjoint sets, viewed as members of the subset lattice.) Note that we define this without reference to `⊓`, as this allows us to talk about orders where the infimum is not unique, or where implementing `Inf` would require additional `Decidable` arguments. -/ def Disjoint (a b : α) : Prop := ∀ ⦃x⦄, x ≤ a → x ≤ b → x ≤ ⊥ @[simp] theorem disjoint_of_subsingleton [Subsingleton α] : Disjoint a b := fun x _ _ ↦ le_of_eq (Subsingleton.elim x ⊥) theorem disjoint_comm : Disjoint a b ↔ Disjoint b a := forall_congr' fun _ ↦ forall_swap @[symm] theorem Disjoint.symm ⦃a b : α⦄ : Disjoint a b → Disjoint b a := disjoint_comm.1 theorem symmetric_disjoint : Symmetric (Disjoint : α → α → Prop) := Disjoint.symm @[simp] theorem disjoint_bot_left : Disjoint ⊥ a := fun _ hbot _ ↦ hbot @[simp] theorem disjoint_bot_right : Disjoint a ⊥ := fun _ _ hbot ↦ hbot @[gcongr] theorem Disjoint.mono (h₁ : a ≤ b) (h₂ : c ≤ d) : Disjoint b d → Disjoint a c := fun h _ ha hc ↦ h (ha.trans h₁) (hc.trans h₂) theorem Disjoint.mono_left (h : a ≤ b) : Disjoint b c → Disjoint a c := Disjoint.mono h le_rfl theorem Disjoint.mono_right : b ≤ c → Disjoint a c → Disjoint a b := Disjoint.mono le_rfl @[simp] theorem disjoint_self : Disjoint a a ↔ a = ⊥ := ⟨fun hd ↦ bot_unique <| hd le_rfl le_rfl, fun h _ ha _ ↦ ha.trans_eq h⟩ /- TODO: Rename `Disjoint.eq_bot` to `Disjoint.inf_eq` and `Disjoint.eq_bot_of_self` to `Disjoint.eq_bot` -/ alias ⟨Disjoint.eq_bot_of_self, _⟩ := disjoint_self theorem Disjoint.ne (ha : a ≠ ⊥) (hab : Disjoint a b) : a ≠ b := fun h ↦ ha <| disjoint_self.1 <| by rwa [← h] at hab theorem Disjoint.eq_bot_of_le (hab : Disjoint a b) (h : a ≤ b) : a = ⊥ := eq_bot_iff.2 <| hab le_rfl h theorem Disjoint.eq_bot_of_ge (hab : Disjoint a b) : b ≤ a → b = ⊥ := hab.symm.eq_bot_of_le lemma Disjoint.eq_iff (hab : Disjoint a b) : a = b ↔ a = ⊥ ∧ b = ⊥ := by aesop lemma Disjoint.ne_iff (hab : Disjoint a b) : a ≠ b ↔ a ≠ ⊥ ∨ b ≠ ⊥ := hab.eq_iff.not.trans not_and_or theorem disjoint_of_le_iff_left_eq_bot (h : a ≤ b) : Disjoint a b ↔ a = ⊥ := ⟨fun hd ↦ hd.eq_bot_of_le h, fun h ↦ h ▸ disjoint_bot_left⟩ end PartialOrderBot section PartialBoundedOrder variable [PartialOrder α] [BoundedOrder α] {a : α} @[simp] theorem disjoint_top : Disjoint a ⊤ ↔ a = ⊥ := ⟨fun h ↦ bot_unique <| h le_rfl le_top, fun h _ ha _ ↦ ha.trans_eq h⟩ @[simp] theorem top_disjoint : Disjoint ⊤ a ↔ a = ⊥ := ⟨fun h ↦ bot_unique <| h le_top le_rfl, fun h _ _ ha ↦ ha.trans_eq h⟩ end PartialBoundedOrder section SemilatticeInfBot variable [SemilatticeInf α] [OrderBot α] {a b c : α} theorem disjoint_iff_inf_le : Disjoint a b ↔ a ⊓ b ≤ ⊥ := ⟨fun hd ↦ hd inf_le_left inf_le_right, fun h _ ha hb ↦ (le_inf ha hb).trans h⟩ theorem disjoint_iff : Disjoint a b ↔ a ⊓ b = ⊥ := disjoint_iff_inf_le.trans le_bot_iff theorem Disjoint.le_bot : Disjoint a b → a ⊓ b ≤ ⊥ := disjoint_iff_inf_le.mp theorem Disjoint.eq_bot : Disjoint a b → a ⊓ b = ⊥ := bot_unique ∘ Disjoint.le_bot theorem disjoint_assoc : Disjoint (a ⊓ b) c ↔ Disjoint a (b ⊓ c) := by rw [disjoint_iff_inf_le, disjoint_iff_inf_le, inf_assoc] theorem disjoint_left_comm : Disjoint a (b ⊓ c) ↔ Disjoint b (a ⊓ c) := by simp_rw [disjoint_iff_inf_le, inf_left_comm] theorem disjoint_right_comm : Disjoint (a ⊓ b) c ↔ Disjoint (a ⊓ c) b := by simp_rw [disjoint_iff_inf_le, inf_right_comm] variable (c) theorem Disjoint.inf_left (h : Disjoint a b) : Disjoint (a ⊓ c) b := h.mono_left inf_le_left theorem Disjoint.inf_left' (h : Disjoint a b) : Disjoint (c ⊓ a) b := h.mono_left inf_le_right theorem Disjoint.inf_right (h : Disjoint a b) : Disjoint a (b ⊓ c) := h.mono_right inf_le_left theorem Disjoint.inf_right' (h : Disjoint a b) : Disjoint a (c ⊓ b) := h.mono_right inf_le_right variable {c} theorem Disjoint.of_disjoint_inf_of_le (h : Disjoint (a ⊓ b) c) (hle : a ≤ c) : Disjoint a b := disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_left_le hle theorem Disjoint.of_disjoint_inf_of_le' (h : Disjoint (a ⊓ b) c) (hle : b ≤ c) : Disjoint a b := disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_right_le hle end SemilatticeInfBot theorem Disjoint.right_lt_sup_of_left_ne_bot [SemilatticeSup α] [OrderBot α] {a b : α} (h : Disjoint a b) (ha : a ≠ ⊥) : b < a ⊔ b := le_sup_right.lt_of_ne fun eq ↦ ha (le_bot_iff.mp <| h le_rfl <| sup_eq_right.mp eq.symm) section DistribLatticeBot variable [DistribLattice α] [OrderBot α] {a b c : α} @[simp] theorem disjoint_sup_left : Disjoint (a ⊔ b) c ↔ Disjoint a c ∧ Disjoint b c := by simp only [disjoint_iff, inf_sup_right, sup_eq_bot_iff] @[simp] theorem disjoint_sup_right : Disjoint a (b ⊔ c) ↔ Disjoint a b ∧ Disjoint a c := by simp only [disjoint_iff, inf_sup_left, sup_eq_bot_iff] theorem Disjoint.sup_left (ha : Disjoint a c) (hb : Disjoint b c) : Disjoint (a ⊔ b) c := disjoint_sup_left.2 ⟨ha, hb⟩ theorem Disjoint.sup_right (hb : Disjoint a b) (hc : Disjoint a c) : Disjoint a (b ⊔ c) := disjoint_sup_right.2 ⟨hb, hc⟩ theorem Disjoint.left_le_of_le_sup_right (h : a ≤ b ⊔ c) (hd : Disjoint a c) : a ≤ b := le_of_inf_le_sup_le (le_trans hd.le_bot bot_le) <| sup_le h le_sup_right theorem Disjoint.left_le_of_le_sup_left (h : a ≤ c ⊔ b) (hd : Disjoint a c) : a ≤ b := hd.left_le_of_le_sup_right <| by rwa [sup_comm] end DistribLatticeBot end Disjoint section Codisjoint section PartialOrderTop variable [PartialOrder α] [OrderTop α] {a b c d : α} /-- Two elements of a lattice are codisjoint if their sup is the top element. Note that we define this without reference to `⊔`, as this allows us to talk about orders where the supremum is not unique, or where implement `Sup` would require additional `Decidable` arguments. -/ def Codisjoint (a b : α) : Prop := ∀ ⦃x⦄, a ≤ x → b ≤ x → ⊤ ≤ x theorem codisjoint_comm : Codisjoint a b ↔ Codisjoint b a := forall_congr' fun _ ↦ forall_swap @[symm] theorem Codisjoint.symm ⦃a b : α⦄ : Codisjoint a b → Codisjoint b a := codisjoint_comm.1 theorem symmetric_codisjoint : Symmetric (Codisjoint : α → α → Prop) := Codisjoint.symm @[simp] theorem codisjoint_top_left : Codisjoint ⊤ a := fun _ htop _ ↦ htop @[simp] theorem codisjoint_top_right : Codisjoint a ⊤ := fun _ _ htop ↦ htop @[gcongr] theorem Codisjoint.mono (h₁ : a ≤ b) (h₂ : c ≤ d) : Codisjoint a c → Codisjoint b d := fun h _ ha hc ↦ h (h₁.trans ha) (h₂.trans hc) theorem Codisjoint.mono_left (h : a ≤ b) : Codisjoint a c → Codisjoint b c := Codisjoint.mono h le_rfl theorem Codisjoint.mono_right : b ≤ c → Codisjoint a b → Codisjoint a c := Codisjoint.mono le_rfl @[simp] theorem codisjoint_self : Codisjoint a a ↔ a = ⊤ := ⟨fun hd ↦ top_unique <| hd le_rfl le_rfl, fun h _ ha _ ↦ h.symm.trans_le ha⟩ /- TODO: Rename `Codisjoint.eq_top` to `Codisjoint.sup_eq` and `Codisjoint.eq_top_of_self` to `Codisjoint.eq_top` -/ alias ⟨Codisjoint.eq_top_of_self, _⟩ := codisjoint_self theorem Codisjoint.ne (ha : a ≠ ⊤) (hab : Codisjoint a b) : a ≠ b := fun h ↦ ha <| codisjoint_self.1 <| by rwa [← h] at hab theorem Codisjoint.eq_top_of_le (hab : Codisjoint a b) (h : b ≤ a) : a = ⊤ := eq_top_iff.2 <| hab le_rfl h theorem Codisjoint.eq_top_of_ge (hab : Codisjoint a b) : a ≤ b → b = ⊤ := hab.symm.eq_top_of_le lemma Codisjoint.eq_iff (hab : Codisjoint a b) : a = b ↔ a = ⊤ ∧ b = ⊤ := by aesop lemma Codisjoint.ne_iff (hab : Codisjoint a b) : a ≠ b ↔ a ≠ ⊤ ∨ b ≠ ⊤ := hab.eq_iff.not.trans not_and_or end PartialOrderTop section PartialBoundedOrder variable [PartialOrder α] [BoundedOrder α] {a b : α} @[simp] theorem codisjoint_bot : Codisjoint a ⊥ ↔ a = ⊤ := ⟨fun h ↦ top_unique <| h le_rfl bot_le, fun h _ ha _ ↦ h.symm.trans_le ha⟩ @[simp] theorem bot_codisjoint : Codisjoint ⊥ a ↔ a = ⊤ := ⟨fun h ↦ top_unique <| h bot_le le_rfl, fun h _ _ ha ↦ h.symm.trans_le ha⟩ lemma Codisjoint.ne_bot_of_ne_top (h : Codisjoint a b) (ha : a ≠ ⊤) : b ≠ ⊥ := by rintro rfl; exact ha <| by simpa using h lemma Codisjoint.ne_bot_of_ne_top' (h : Codisjoint a b) (hb : b ≠ ⊤) : a ≠ ⊥ := by rintro rfl; exact hb <| by simpa using h end PartialBoundedOrder section SemilatticeSupTop variable [SemilatticeSup α] [OrderTop α] {a b c : α} theorem codisjoint_iff_le_sup : Codisjoint a b ↔ ⊤ ≤ a ⊔ b := @disjoint_iff_inf_le αᵒᵈ _ _ _ _ theorem codisjoint_iff : Codisjoint a b ↔ a ⊔ b = ⊤ := @disjoint_iff αᵒᵈ _ _ _ _ theorem Codisjoint.top_le : Codisjoint a b → ⊤ ≤ a ⊔ b := @Disjoint.le_bot αᵒᵈ _ _ _ _ theorem Codisjoint.eq_top : Codisjoint a b → a ⊔ b = ⊤ := @Disjoint.eq_bot αᵒᵈ _ _ _ _ theorem codisjoint_assoc : Codisjoint (a ⊔ b) c ↔ Codisjoint a (b ⊔ c) := @disjoint_assoc αᵒᵈ _ _ _ _ _ theorem codisjoint_left_comm : Codisjoint a (b ⊔ c) ↔ Codisjoint b (a ⊔ c) := @disjoint_left_comm αᵒᵈ _ _ _ _ _ theorem codisjoint_right_comm : Codisjoint (a ⊔ b) c ↔ Codisjoint (a ⊔ c) b := @disjoint_right_comm αᵒᵈ _ _ _ _ _ variable (c) theorem Codisjoint.sup_left (h : Codisjoint a b) : Codisjoint (a ⊔ c) b := h.mono_left le_sup_left theorem Codisjoint.sup_left' (h : Codisjoint a b) : Codisjoint (c ⊔ a) b := h.mono_left le_sup_right theorem Codisjoint.sup_right (h : Codisjoint a b) : Codisjoint a (b ⊔ c) := h.mono_right le_sup_left theorem Codisjoint.sup_right' (h : Codisjoint a b) : Codisjoint a (c ⊔ b) := h.mono_right le_sup_right variable {c} theorem Codisjoint.of_codisjoint_sup_of_le (h : Codisjoint (a ⊔ b) c) (hle : c ≤ a) : Codisjoint a b := @Disjoint.of_disjoint_inf_of_le αᵒᵈ _ _ _ _ _ h hle theorem Codisjoint.of_codisjoint_sup_of_le' (h : Codisjoint (a ⊔ b) c) (hle : c ≤ b) : Codisjoint a b := @Disjoint.of_disjoint_inf_of_le' αᵒᵈ _ _ _ _ _ h hle end SemilatticeSupTop section DistribLatticeTop variable [DistribLattice α] [OrderTop α] {a b c : α} @[simp] theorem codisjoint_inf_left : Codisjoint (a ⊓ b) c ↔ Codisjoint a c ∧ Codisjoint b c := by simp only [codisjoint_iff, sup_inf_right, inf_eq_top_iff] @[simp] theorem codisjoint_inf_right : Codisjoint a (b ⊓ c) ↔ Codisjoint a b ∧ Codisjoint a c := by simp only [codisjoint_iff, sup_inf_left, inf_eq_top_iff] theorem Codisjoint.inf_left (ha : Codisjoint a c) (hb : Codisjoint b c) : Codisjoint (a ⊓ b) c := codisjoint_inf_left.2 ⟨ha, hb⟩ theorem Codisjoint.inf_right (hb : Codisjoint a b) (hc : Codisjoint a c) : Codisjoint a (b ⊓ c) := codisjoint_inf_right.2 ⟨hb, hc⟩ theorem Codisjoint.left_le_of_le_inf_right (h : a ⊓ b ≤ c) (hd : Codisjoint b c) : a ≤ c := @Disjoint.left_le_of_le_sup_right αᵒᵈ _ _ _ _ _ h hd.symm theorem Codisjoint.left_le_of_le_inf_left (h : b ⊓ a ≤ c) (hd : Codisjoint b c) : a ≤ c := hd.left_le_of_le_inf_right <| by rwa [inf_comm] end DistribLatticeTop end Codisjoint open OrderDual theorem Disjoint.dual [PartialOrder α] [OrderBot α] {a b : α} : Disjoint a b → Codisjoint (toDual a) (toDual b) := id theorem Codisjoint.dual [PartialOrder α] [OrderTop α] {a b : α} : Codisjoint a b → Disjoint (toDual a) (toDual b) := id @[simp] theorem disjoint_toDual_iff [PartialOrder α] [OrderTop α] {a b : α} : Disjoint (toDual a) (toDual b) ↔ Codisjoint a b := Iff.rfl @[simp] theorem disjoint_ofDual_iff [PartialOrder α] [OrderBot α] {a b : αᵒᵈ} : Disjoint (ofDual a) (ofDual b) ↔ Codisjoint a b := Iff.rfl @[simp] theorem codisjoint_toDual_iff [PartialOrder α] [OrderBot α] {a b : α} : Codisjoint (toDual a) (toDual b) ↔ Disjoint a b := Iff.rfl @[simp] theorem codisjoint_ofDual_iff [PartialOrder α] [OrderTop α] {a b : αᵒᵈ} : Codisjoint (ofDual a) (ofDual b) ↔ Disjoint a b := Iff.rfl section DistribLattice variable [DistribLattice α] [BoundedOrder α] {a b c : α} theorem Disjoint.le_of_codisjoint (hab : Disjoint a b) (hbc : Codisjoint b c) : a ≤ c := by rw [← @inf_top_eq _ _ _ a, ← @bot_sup_eq _ _ _ c, ← hab.eq_bot, ← hbc.eq_top, sup_inf_right] exact inf_le_inf_right _ le_sup_left end DistribLattice section IsCompl /-- Two elements `x` and `y` are complements of each other if `x ⊔ y = ⊤` and `x ⊓ y = ⊥`. -/ structure IsCompl [PartialOrder α] [BoundedOrder α] (x y : α) : Prop where /-- If `x` and `y` are to be complementary in an order, they should be disjoint. -/ protected disjoint : Disjoint x y /-- If `x` and `y` are to be complementary in an order, they should be codisjoint. -/ protected codisjoint : Codisjoint x y theorem isCompl_iff [PartialOrder α] [BoundedOrder α] {a b : α} : IsCompl a b ↔ Disjoint a b ∧ Codisjoint a b := ⟨fun h ↦ ⟨h.1, h.2⟩, fun h ↦ ⟨h.1, h.2⟩⟩ namespace IsCompl section BoundedPartialOrder variable [PartialOrder α] [BoundedOrder α] {x y : α} @[symm] protected theorem symm (h : IsCompl x y) : IsCompl y x := ⟨h.1.symm, h.2.symm⟩ lemma _root_.isCompl_comm : IsCompl x y ↔ IsCompl y x := ⟨IsCompl.symm, IsCompl.symm⟩ theorem dual (h : IsCompl x y) : IsCompl (toDual x) (toDual y) := ⟨h.2, h.1⟩ theorem ofDual {a b : αᵒᵈ} (h : IsCompl a b) : IsCompl (ofDual a) (ofDual b) := ⟨h.2, h.1⟩ end BoundedPartialOrder section BoundedLattice variable [Lattice α] [BoundedOrder α] {x y : α} theorem of_le (h₁ : x ⊓ y ≤ ⊥) (h₂ : ⊤ ≤ x ⊔ y) : IsCompl x y := ⟨disjoint_iff_inf_le.mpr h₁, codisjoint_iff_le_sup.mpr h₂⟩ theorem of_eq (h₁ : x ⊓ y = ⊥) (h₂ : x ⊔ y = ⊤) : IsCompl x y := ⟨disjoint_iff.mpr h₁, codisjoint_iff.mpr h₂⟩ theorem inf_eq_bot (h : IsCompl x y) : x ⊓ y = ⊥ := h.disjoint.eq_bot theorem sup_eq_top (h : IsCompl x y) : x ⊔ y = ⊤ := h.codisjoint.eq_top end BoundedLattice variable [DistribLattice α] [BoundedOrder α] {a b x y z : α} theorem inf_left_le_of_le_sup_right (h : IsCompl x y) (hle : a ≤ b ⊔ y) : a ⊓ x ≤ b := calc a ⊓ x ≤ (b ⊔ y) ⊓ x := inf_le_inf hle le_rfl _ = b ⊓ x ⊔ y ⊓ x := inf_sup_right _ _ _ _ = b ⊓ x := by rw [h.symm.inf_eq_bot, sup_bot_eq] _ ≤ b := inf_le_left theorem le_sup_right_iff_inf_left_le {a b} (h : IsCompl x y) : a ≤ b ⊔ y ↔ a ⊓ x ≤ b := ⟨h.inf_left_le_of_le_sup_right, h.symm.dual.inf_left_le_of_le_sup_right⟩ theorem inf_left_eq_bot_iff (h : IsCompl y z) : x ⊓ y = ⊥ ↔ x ≤ z := by rw [← le_bot_iff, ← h.le_sup_right_iff_inf_left_le, bot_sup_eq] theorem inf_right_eq_bot_iff (h : IsCompl y z) : x ⊓ z = ⊥ ↔ x ≤ y := h.symm.inf_left_eq_bot_iff theorem disjoint_left_iff (h : IsCompl y z) : Disjoint x y ↔ x ≤ z := by rw [disjoint_iff] exact h.inf_left_eq_bot_iff theorem disjoint_right_iff (h : IsCompl y z) : Disjoint x z ↔ x ≤ y := h.symm.disjoint_left_iff theorem le_left_iff (h : IsCompl x y) : z ≤ x ↔ Disjoint z y := h.disjoint_right_iff.symm theorem le_right_iff (h : IsCompl x y) : z ≤ y ↔ Disjoint z x := h.symm.le_left_iff theorem left_le_iff (h : IsCompl x y) : x ≤ z ↔ Codisjoint z y := h.dual.le_left_iff theorem right_le_iff (h : IsCompl x y) : y ≤ z ↔ Codisjoint z x := h.symm.left_le_iff protected theorem Antitone {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') (hx : x ≤ x') : y' ≤ y := h'.right_le_iff.2 <| h.symm.codisjoint.mono_right hx theorem right_unique (hxy : IsCompl x y) (hxz : IsCompl x z) : y = z := le_antisymm (hxz.Antitone hxy <| le_refl x) (hxy.Antitone hxz <| le_refl x) theorem left_unique (hxz : IsCompl x z) (hyz : IsCompl y z) : x = y := hxz.symm.right_unique hyz.symm theorem sup_inf {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') : IsCompl (x ⊔ x') (y ⊓ y') := of_eq (by rw [inf_sup_right, ← inf_assoc, h.inf_eq_bot, bot_inf_eq, bot_sup_eq, inf_left_comm, h'.inf_eq_bot, inf_bot_eq]) (by rw [sup_inf_left, sup_comm x, sup_assoc, h.sup_eq_top, sup_top_eq, top_inf_eq, sup_assoc, sup_left_comm, h'.sup_eq_top, sup_top_eq]) theorem inf_sup {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') : IsCompl (x ⊓ x') (y ⊔ y') := (h.symm.sup_inf h'.symm).symm end IsCompl namespace Prod variable {β : Type*} [PartialOrder α] [PartialOrder β] protected theorem disjoint_iff [OrderBot α] [OrderBot β] {x y : α × β} : Disjoint x y ↔ Disjoint x.1 y.1 ∧ Disjoint x.2 y.2 := by constructor · intro h refine ⟨fun a hx hy ↦ (@h (a, ⊥) ⟨hx, ?_⟩ ⟨hy, ?_⟩).1, fun b hx hy ↦ (@h (⊥, b) ⟨?_, hx⟩ ⟨?_, hy⟩).2⟩ all_goals exact bot_le · rintro ⟨ha, hb⟩ z hza hzb exact ⟨ha hza.1 hzb.1, hb hza.2 hzb.2⟩ protected theorem codisjoint_iff [OrderTop α] [OrderTop β] {x y : α × β} : Codisjoint x y ↔ Codisjoint x.1 y.1 ∧ Codisjoint x.2 y.2 := @Prod.disjoint_iff αᵒᵈ βᵒᵈ _ _ _ _ _ _ protected theorem isCompl_iff [BoundedOrder α] [BoundedOrder β] {x y : α × β} : IsCompl x y ↔ IsCompl x.1 y.1 ∧ IsCompl x.2 y.2 := by simp_rw [isCompl_iff, Prod.disjoint_iff, Prod.codisjoint_iff, and_and_and_comm] end Prod section variable [Lattice α] [BoundedOrder α] {a b x : α} @[simp] theorem isCompl_toDual_iff : IsCompl (toDual a) (toDual b) ↔ IsCompl a b := ⟨IsCompl.ofDual, IsCompl.dual⟩ @[simp] theorem isCompl_ofDual_iff {a b : αᵒᵈ} : IsCompl (ofDual a) (ofDual b) ↔ IsCompl a b := ⟨IsCompl.dual, IsCompl.ofDual⟩ theorem isCompl_bot_top : IsCompl (⊥ : α) ⊤ := IsCompl.of_eq (bot_inf_eq _) (sup_top_eq _) theorem isCompl_top_bot : IsCompl (⊤ : α) ⊥ := IsCompl.of_eq (inf_bot_eq _) (top_sup_eq _) theorem eq_top_of_isCompl_bot (h : IsCompl x ⊥) : x = ⊤ := by rw [← sup_bot_eq x, h.sup_eq_top] theorem eq_top_of_bot_isCompl (h : IsCompl ⊥ x) : x = ⊤ := eq_top_of_isCompl_bot h.symm theorem eq_bot_of_isCompl_top (h : IsCompl x ⊤) : x = ⊥ := eq_top_of_isCompl_bot h.dual theorem eq_bot_of_top_isCompl (h : IsCompl ⊤ x) : x = ⊥ := eq_top_of_bot_isCompl h.dual end section IsComplemented section Lattice variable [Lattice α] [BoundedOrder α] /-- An element is *complemented* if it has a complement. -/ def IsComplemented (a : α) : Prop := ∃ b, IsCompl a b theorem isComplemented_bot : IsComplemented (⊥ : α) := ⟨⊤, isCompl_bot_top⟩ theorem isComplemented_top : IsComplemented (⊤ : α) := ⟨⊥, isCompl_top_bot⟩ end Lattice variable [DistribLattice α] [BoundedOrder α] {a b : α} theorem IsComplemented.sup : IsComplemented a → IsComplemented b → IsComplemented (a ⊔ b) := fun ⟨a', ha⟩ ⟨b', hb⟩ => ⟨a' ⊓ b', ha.sup_inf hb⟩ theorem IsComplemented.inf : IsComplemented a → IsComplemented b → IsComplemented (a ⊓ b) := fun ⟨a', ha⟩ ⟨b', hb⟩ => ⟨a' ⊔ b', ha.inf_sup hb⟩ end IsComplemented /-- A complemented bounded lattice is one where every element has a (not necessarily unique) complement. -/ class ComplementedLattice (α) [Lattice α] [BoundedOrder α] : Prop where /-- In a `ComplementedLattice`, every element admits a complement. -/ exists_isCompl : ∀ a : α, ∃ b : α, IsCompl a b lemma complementedLattice_iff (α) [Lattice α] [BoundedOrder α] : ComplementedLattice α ↔ ∀ a : α, ∃ b : α, IsCompl a b := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ export ComplementedLattice (exists_isCompl) -- This was previously a global instance, -- but it doesn't appear to be used and has been implicated in slow typeclass resolutions. lemma Subsingleton.instComplementedLattice [Lattice α] [BoundedOrder α] [Subsingleton α] : ComplementedLattice α := by refine ⟨fun a ↦ ⟨⊥, disjoint_bot_right, ?_⟩⟩ rw [Subsingleton.elim ⊥ ⊤] exact codisjoint_top_right namespace ComplementedLattice variable [Lattice α] [BoundedOrder α] [ComplementedLattice α] instance : ComplementedLattice αᵒᵈ := ⟨fun a ↦ let ⟨b, hb⟩ := exists_isCompl (show α from a) ⟨b, hb.dual⟩⟩ end ComplementedLattice -- TODO: Define as a sublattice? /-- The sublattice of complemented elements. -/ abbrev Complementeds (α : Type*) [Lattice α] [BoundedOrder α] : Type _ := {a : α // IsComplemented a} namespace Complementeds section Lattice variable [Lattice α] [BoundedOrder α] {a b : Complementeds α} instance hasCoeT : CoeTC (Complementeds α) α := ⟨Subtype.val⟩ theorem coe_injective : Injective ((↑) : Complementeds α → α) := Subtype.coe_injective @[simp, norm_cast] theorem coe_inj : (a : α) = b ↔ a = b := Subtype.coe_inj @[norm_cast] theorem coe_le_coe : (a : α) ≤ b ↔ a ≤ b := by simp @[norm_cast] theorem coe_lt_coe : (a : α) < b ↔ a < b := by simp instance : BoundedOrder (Complementeds α) := Subtype.boundedOrder isComplemented_bot isComplemented_top @[simp, norm_cast] theorem coe_bot : ((⊥ : Complementeds α) : α) = ⊥ := rfl @[simp, norm_cast] theorem coe_top : ((⊤ : Complementeds α) : α) = ⊤ := rfl theorem mk_bot : (⟨⊥, isComplemented_bot⟩ : Complementeds α) = ⊥ := by simp theorem mk_top : (⟨⊤, isComplemented_top⟩ : Complementeds α) = ⊤ := by simp instance : Inhabited (Complementeds α) := ⟨⊥⟩ end Lattice variable [DistribLattice α] [BoundedOrder α] {a b : Complementeds α} instance : Max (Complementeds α) := ⟨fun a b => ⟨a ⊔ b, a.2.sup b.2⟩⟩ instance : Min (Complementeds α) := ⟨fun a b => ⟨a ⊓ b, a.2.inf b.2⟩⟩ @[simp, norm_cast] theorem coe_sup (a b : Complementeds α) : ↑(a ⊔ b) = (a : α) ⊔ b := rfl @[simp, norm_cast] theorem coe_inf (a b : Complementeds α) : ↑(a ⊓ b) = (a : α) ⊓ b := rfl @[simp] theorem mk_sup_mk {a b : α} (ha : IsComplemented a) (hb : IsComplemented b) : (⟨a, ha⟩ ⊔ ⟨b, hb⟩ : Complementeds α) = ⟨a ⊔ b, ha.sup hb⟩ := rfl @[simp] theorem mk_inf_mk {a b : α} (ha : IsComplemented a) (hb : IsComplemented b) : (⟨a, ha⟩ ⊓ ⟨b, hb⟩ : Complementeds α) = ⟨a ⊓ b, ha.inf hb⟩ := rfl instance : DistribLattice (Complementeds α) := Complementeds.coe_injective.distribLattice _ coe_sup coe_inf @[simp, norm_cast] theorem disjoint_coe : Disjoint (a : α) b ↔ Disjoint a b := by rw [disjoint_iff, disjoint_iff, ← coe_inf, ← coe_bot, coe_inj] @[simp, norm_cast] theorem codisjoint_coe : Codisjoint (a : α) b ↔ Codisjoint a b := by rw [codisjoint_iff, codisjoint_iff, ← coe_sup, ← coe_top, coe_inj] @[simp, norm_cast] theorem isCompl_coe : IsCompl (a : α) b ↔ IsCompl a b := by simp_rw [isCompl_iff, disjoint_coe, codisjoint_coe] instance : ComplementedLattice (Complementeds α) := ⟨fun ⟨a, b, h⟩ => ⟨⟨b, a, h.symm⟩, isCompl_coe.1 h⟩⟩ end Complementeds end IsCompl
Abelian.lean
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.Algebra.Category.ModuleCat.Kernels import Mathlib.Algebra.Category.ModuleCat.Limits import Mathlib.CategoryTheory.Abelian.Basic /-! # The category of left R-modules is abelian. Additionally, two linear maps are exact in the categorical sense iff `range f = ker g`. -/ open CategoryTheory open CategoryTheory.Limits noncomputable section universe w v u namespace ModuleCat variable {R : Type u} [Ring R] {M N : ModuleCat.{v} R} (f : M ⟶ N) /-- In the category of modules, every monomorphism is normal. -/ def normalMono (hf : Mono f) : NormalMono f where Z := of R (N ⧸ LinearMap.range f.hom) g := ofHom (LinearMap.range f.hom).mkQ w := hom_ext <| LinearMap.range_mkQ_comp _ isLimit := /- The following [invalid Lean code](https://github.com/leanprover-community/lean/issues/341) might help you understand what's going on here: ``` calc M ≃ₗ[R] f.ker.quotient : (Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm ... ≃ₗ[R] f.range : LinearMap.quotKerEquivRange f ... ≃ₗ[R] r.range.mkQ.ker : LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm ``` -/ IsKernel.isoKernel _ _ (kernelIsLimit _) (LinearEquiv.toModuleIso ((Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm ≪≫ₗ (LinearMap.quotKerEquivRange f.hom ≪≫ₗ LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm))) <| by ext; rfl /-- In the category of modules, every epimorphism is normal. -/ def normalEpi (hf : Epi f) : NormalEpi f where W := of R (LinearMap.ker f.hom) g := ofHom (LinearMap.ker f.hom).subtype w := hom_ext <| LinearMap.comp_ker_subtype _ isColimit := /- The following invalid Lean code might help you understand what's going on here: ``` calc f.ker.subtype.range.quotient ≃ₗ[R] f.ker.quotient : Submodule.quotEquivOfEq _ _ (Submodule.range_subtype _) ... ≃ₗ[R] f.range : LinearMap.quotKerEquivRange f ... ≃ₗ[R] N : LinearEquiv.ofTop _ (range_eq_top_of_epi _) ``` -/ IsCokernel.cokernelIso _ _ (cokernelIsColimit _) (LinearEquiv.toModuleIso (Submodule.quotEquivOfEq _ _ (Submodule.range_subtype _) ≪≫ₗ LinearMap.quotKerEquivRange f.hom ≪≫ₗ LinearEquiv.ofTop _ (range_eq_top_of_epi _))) <| by ext; rfl /-- The category of R-modules is abelian. -/ instance abelian : Abelian (ModuleCat.{v} R) where has_cokernels := hasCokernels_moduleCat normalMonoOfMono f hf := ⟨normalMono f hf⟩ normalEpiOfEpi f hf := ⟨normalEpi f hf⟩ section ReflectsLimits /-- Add this instance to help Lean with universe levels. -/ instance : HasLimitsOfSize.{v,v} (ModuleCat.{max v w} R) := ModuleCat.hasLimitsOfSize.{v, v, max v w} /- We need to put this in this weird spot because we need to know that the category of modules is balanced. -/ instance forget_reflectsLimitsOfSize : ReflectsLimitsOfSize.{v, v} (forget (ModuleCat.{max v w} R)) := reflectsLimits_of_reflectsIsomorphisms instance forget₂_reflectsLimitsOfSize : ReflectsLimitsOfSize.{v, v} (forget₂ (ModuleCat.{max v w} R) AddCommGrp.{max v w}) := reflectsLimits_of_reflectsIsomorphisms instance forget_reflectsLimits : ReflectsLimits (forget (ModuleCat.{v} R)) := ModuleCat.forget_reflectsLimitsOfSize.{v, v} instance forget₂_reflectsLimits : ReflectsLimits (forget₂ (ModuleCat.{v} R) AddCommGrp.{v}) := ModuleCat.forget₂_reflectsLimitsOfSize.{v, v} end ReflectsLimits end ModuleCat
FilterBasis.lean
/- Copyright (c) 2021 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Topology.Algebra.Module.Basic /-! # Group and ring filter bases A `GroupFilterBasis` is a `FilterBasis` on a group with some properties relating the basis to the group structure. The main theorem is that a `GroupFilterBasis` on a group gives a topology on the group which makes it into a topological group with neighborhoods of the neutral element generated by the given basis. ## Main definitions and results Given a group `G` and a ring `R`: * `GroupFilterBasis G`: the type of filter bases that will become neighborhood of `1` for a topology on `G` compatible with the group structure * `GroupFilterBasis.topology`: the associated topology * `GroupFilterBasis.isTopologicalGroup`: the compatibility between the above topology and the group structure * `RingFilterBasis R`: the type of filter bases that will become neighborhood of `0` for a topology on `R` compatible with the ring structure * `RingFilterBasis.topology`: the associated topology * `RingFilterBasis.isTopologicalRing`: the compatibility between the above topology and the ring structure ## References * [N. Bourbaki, *General Topology*][bourbaki1966] -/ open Filter Set TopologicalSpace Function open Topology Filter Pointwise universe u /-- A `GroupFilterBasis` on a group is a `FilterBasis` satisfying some additional axioms. Example : if `G` is a topological group then the neighbourhoods of the identity are a `GroupFilterBasis`. Conversely given a `GroupFilterBasis` one can define a topology compatible with the group structure on `G`. -/ class GroupFilterBasis (G : Type u) [Group G] extends FilterBasis G where one' : ∀ {U}, U ∈ sets → (1 : G) ∈ U mul' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V * V ⊆ U inv' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U conj' : ∀ x₀, ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ * x * x₀⁻¹) ⁻¹' U /-- An `AddGroupFilterBasis` on an additive group is a `FilterBasis` satisfying some additional axioms. Example : if `G` is a topological group then the neighbourhoods of the identity are an `AddGroupFilterBasis`. Conversely given an `AddGroupFilterBasis` one can define a topology compatible with the group structure on `G`. -/ class AddGroupFilterBasis (A : Type u) [AddGroup A] extends FilterBasis A where zero' : ∀ {U}, U ∈ sets → (0 : A) ∈ U add' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V + V ⊆ U neg' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ -x) ⁻¹' U conj' : ∀ x₀, ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ + x + -x₀) ⁻¹' U attribute [to_additive existing] GroupFilterBasis GroupFilterBasis.conj' GroupFilterBasis.toFilterBasis /-- `GroupFilterBasis` constructor in the commutative group case. -/ @[to_additive /-- `AddGroupFilterBasis` constructor in the additive commutative group case. -/] def groupFilterBasisOfComm {G : Type*} [CommGroup G] (sets : Set (Set G)) (nonempty : sets.Nonempty) (inter_sets : ∀ x y, x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y) (one : ∀ U ∈ sets, (1 : G) ∈ U) (mul : ∀ U ∈ sets, ∃ V ∈ sets, V * V ⊆ U) (inv : ∀ U ∈ sets, ∃ V ∈ sets, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U) : GroupFilterBasis G := { sets := sets nonempty := nonempty inter_sets := inter_sets _ _ one' := one _ mul' := mul _ inv' := inv _ conj' := fun x U U_in ↦ ⟨U, U_in, by simp only [mul_inv_cancel_comm, preimage_id']; rfl⟩ } namespace GroupFilterBasis variable {G : Type u} [Group G] {B : GroupFilterBasis G} @[to_additive] instance : Membership (Set G) (GroupFilterBasis G) := ⟨fun f s ↦ s ∈ f.sets⟩ @[to_additive] theorem one {U : Set G} : U ∈ B → (1 : G) ∈ U := GroupFilterBasis.one' @[to_additive] theorem mul {U : Set G} : U ∈ B → ∃ V ∈ B, V * V ⊆ U := GroupFilterBasis.mul' @[to_additive] theorem inv {U : Set G} : U ∈ B → ∃ V ∈ B, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U := GroupFilterBasis.inv' @[to_additive] theorem conj : ∀ x₀, ∀ {U}, U ∈ B → ∃ V ∈ B, V ⊆ (fun x ↦ x₀ * x * x₀⁻¹) ⁻¹' U := GroupFilterBasis.conj' /-- The trivial group filter basis consists of `{1}` only. The associated topology is discrete. -/ @[to_additive /-- The trivial additive group filter basis consists of `{0}` only. The associated topology is discrete. -/] instance : Inhabited (GroupFilterBasis G) where default := { sets := {{1}} nonempty := singleton_nonempty _ inter_sets := by simp one' := by simp mul' := by simp inv' := by simp conj' := by simp } @[to_additive] theorem subset_mul_self (B : GroupFilterBasis G) {U : Set G} (h : U ∈ B) : U ⊆ U * U := fun x x_in ↦ ⟨1, one h, x, x_in, one_mul x⟩ /-- The neighborhood function of a `GroupFilterBasis`. -/ @[to_additive /-- The neighborhood function of an `AddGroupFilterBasis`. -/] def N (B : GroupFilterBasis G) : G → Filter G := fun x ↦ map (fun y ↦ x * y) B.toFilterBasis.filter @[to_additive (attr := simp)] theorem N_one (B : GroupFilterBasis G) : B.N 1 = B.toFilterBasis.filter := by simp only [N, one_mul, map_id'] @[to_additive] protected theorem hasBasis (B : GroupFilterBasis G) (x : G) : HasBasis (B.N x) (fun V : Set G ↦ V ∈ B) fun V ↦ (fun y ↦ x * y) '' V := HasBasis.map (fun y ↦ x * y) toFilterBasis.hasBasis /-- The topological space structure coming from a group filter basis. -/ @[to_additive /-- The topological space structure coming from an additive group filter basis. -/] def topology (B : GroupFilterBasis G) : TopologicalSpace G := TopologicalSpace.mkOfNhds B.N @[to_additive] theorem nhds_eq (B : GroupFilterBasis G) {x₀ : G} : @nhds G B.topology x₀ = B.N x₀ := by apply TopologicalSpace.nhds_mkOfNhds_of_hasBasis (fun x ↦ (FilterBasis.hasBasis _).map _) · intro a U U_in exact ⟨1, B.one U_in, mul_one a⟩ · intro a U U_in rcases GroupFilterBasis.mul U_in with ⟨V, V_in, hVU⟩ filter_upwards [image_mem_map (B.mem_filter_of_mem V_in)] rintro _ ⟨x, hx, rfl⟩ calc (a * x) • V ∈ (a * x) • B.filter := smul_set_mem_smul_filter <| B.mem_filter_of_mem V_in _ = a • x • V := smul_smul .. |>.symm _ ⊆ a • (V * V) := smul_set_mono <| smul_set_subset_smul hx _ ⊆ a • U := smul_set_mono hVU @[to_additive] theorem nhds_one_eq (B : GroupFilterBasis G) : @nhds G B.topology (1 : G) = B.toFilterBasis.filter := by rw [B.nhds_eq] simp only [N, one_mul] exact map_id @[to_additive] theorem nhds_hasBasis (B : GroupFilterBasis G) (x₀ : G) : HasBasis (@nhds G B.topology x₀) (fun V : Set G ↦ V ∈ B) fun V ↦ (fun y ↦ x₀ * y) '' V := by rw [B.nhds_eq] apply B.hasBasis @[to_additive] theorem nhds_one_hasBasis (B : GroupFilterBasis G) : HasBasis (@nhds G B.topology 1) (fun V : Set G ↦ V ∈ B) id := by rw [B.nhds_one_eq] exact B.toFilterBasis.hasBasis @[to_additive] theorem mem_nhds_one (B : GroupFilterBasis G) {U : Set G} (hU : U ∈ B) : U ∈ @nhds G B.topology 1 := by rw [B.nhds_one_hasBasis.mem_iff] exact ⟨U, hU, rfl.subset⟩ -- See note [lower instance priority] /-- If a group is endowed with a topological structure coming from a group filter basis then, it's a topological group. -/ @[to_additive /-- If an additive group is endowed with a topological structure coming from an additive group filter basis, then it's an additive topological group. -/] instance (priority := 100) isTopologicalGroup (B : GroupFilterBasis G) : @IsTopologicalGroup G B.topology _ := by letI := B.topology have basis := B.nhds_one_hasBasis have basis' := basis.prod basis refine IsTopologicalGroup.of_nhds_one ?_ ?_ ?_ ?_ · rw [basis'.tendsto_iff basis] suffices ∀ U ∈ B, ∃ V W, (V ∈ B ∧ W ∈ B) ∧ ∀ a b, a ∈ V → b ∈ W → a * b ∈ U by simpa intro U U_in rcases mul U_in with ⟨V, V_in, hV⟩ refine ⟨V, V, ⟨V_in, V_in⟩, ?_⟩ intro a b a_in b_in exact hV <| mul_mem_mul a_in b_in · rw [basis.tendsto_iff basis] intro U U_in simpa using inv U_in · intro x₀ rw [nhds_eq, nhds_one_eq] rfl · intro x₀ rw [basis.tendsto_iff basis] intro U U_in exact conj x₀ U_in end GroupFilterBasis /-- A `RingFilterBasis` on a ring is a `FilterBasis` satisfying some additional axioms. Example : if `R` is a topological ring then the neighbourhoods of the identity are a `RingFilterBasis`. Conversely given a `RingFilterBasis` on a ring `R`, one can define a topology on `R` which is compatible with the ring structure. -/ class RingFilterBasis (R : Type u) [Ring R] extends AddGroupFilterBasis R where mul' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V * V ⊆ U mul_left' : ∀ (x₀ : R) {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ * x) ⁻¹' U mul_right' : ∀ (x₀ : R) {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x * x₀) ⁻¹' U namespace RingFilterBasis variable {R : Type u} [Ring R] (B : RingFilterBasis R) instance : Membership (Set R) (RingFilterBasis R) := ⟨fun B s ↦ s ∈ B.sets⟩ theorem mul {U : Set R} (hU : U ∈ B) : ∃ V ∈ B, V * V ⊆ U := mul' hU theorem mul_left (x₀ : R) {U : Set R} (hU : U ∈ B) : ∃ V ∈ B, V ⊆ (fun x ↦ x₀ * x) ⁻¹' U := mul_left' x₀ hU theorem mul_right (x₀ : R) {U : Set R} (hU : U ∈ B) : ∃ V ∈ B, V ⊆ (fun x ↦ x * x₀) ⁻¹' U := mul_right' x₀ hU /-- The topology associated to a ring filter basis. It has the given basis as a basis of neighborhoods of zero. -/ def topology : TopologicalSpace R := B.toAddGroupFilterBasis.topology /-- If a ring is endowed with a topological structure coming from a ring filter basis then it's a topological ring. -/ instance (priority := 100) isTopologicalRing {R : Type u} [Ring R] (B : RingFilterBasis R) : @IsTopologicalRing R B.topology _ := by let B' := B.toAddGroupFilterBasis letI := B'.topology have basis := B'.nhds_zero_hasBasis have basis' := basis.prod basis haveI := B'.isTopologicalAddGroup apply IsTopologicalRing.of_addGroup_of_nhds_zero · rw [basis'.tendsto_iff basis] suffices ∀ U ∈ B', ∃ V W, (V ∈ B' ∧ W ∈ B') ∧ ∀ a b, a ∈ V → b ∈ W → a * b ∈ U by simpa intro U U_in rcases B.mul U_in with ⟨V, V_in, hV⟩ refine ⟨V, V, ⟨V_in, V_in⟩, ?_⟩ intro a b a_in b_in exact hV <| mul_mem_mul a_in b_in · intro x₀ rw [basis.tendsto_iff basis] intro U simpa using B.mul_left x₀ · intro x₀ rw [basis.tendsto_iff basis] intro U simpa using B.mul_right x₀ end RingFilterBasis /-- A `ModuleFilterBasis` on a module is a `FilterBasis` satisfying some additional axioms. Example : if `M` is a topological module then the neighbourhoods of zero are a `ModuleFilterBasis`. Conversely given a `ModuleFilterBasis` one can define a topology compatible with the module structure on `M`. -/ structure ModuleFilterBasis (R M : Type*) [CommRing R] [TopologicalSpace R] [AddCommGroup M] [Module R M] extends AddGroupFilterBasis M where smul' : ∀ {U}, U ∈ sets → ∃ V ∈ 𝓝 (0 : R), ∃ W ∈ sets, V • W ⊆ U smul_left' : ∀ (x₀ : R) {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ • x) ⁻¹' U smul_right' : ∀ (m₀ : M) {U}, U ∈ sets → ∀ᶠ x in 𝓝 (0 : R), x • m₀ ∈ U namespace ModuleFilterBasis variable {R M : Type*} [CommRing R] [TopologicalSpace R] [AddCommGroup M] [Module R M] (B : ModuleFilterBasis R M) instance GroupFilterBasis.hasMem : Membership (Set M) (ModuleFilterBasis R M) := ⟨fun B s ↦ s ∈ B.sets⟩ theorem smul {U : Set M} (hU : U ∈ B) : ∃ V ∈ 𝓝 (0 : R), ∃ W ∈ B, V • W ⊆ U := B.smul' hU theorem smul_left (x₀ : R) {U : Set M} (hU : U ∈ B) : ∃ V ∈ B, V ⊆ (fun x ↦ x₀ • x) ⁻¹' U := B.smul_left' x₀ hU theorem smul_right (m₀ : M) {U : Set M} (hU : U ∈ B) : ∀ᶠ x in 𝓝 (0 : R), x • m₀ ∈ U := B.smul_right' m₀ hU /-- If `R` is discrete then the trivial additive group filter basis on any `R`-module is a module filter basis. -/ instance [DiscreteTopology R] : Inhabited (ModuleFilterBasis R M) := ⟨{ show AddGroupFilterBasis M from default with smul' := by rintro U (rfl : U ∈ {{(0 : M)}}) use univ, univ_mem, {0}, rfl rintro a ⟨x, -, m, rfl, rfl⟩ simp only [smul_zero, mem_singleton_iff] smul_left' := by rintro x₀ U (h : U ∈ {{(0 : M)}}) rw [mem_singleton_iff] at h use {0}, rfl simp [h] smul_right' := by rintro m₀ U (h : U ∈ (0 : Set (Set M))) rw [Set.mem_zero] at h simp [h, nhds_discrete] }⟩ /-- The topology associated to a module filter basis on a module over a topological ring. It has the given basis as a basis of neighborhoods of zero. -/ def topology : TopologicalSpace M := B.toAddGroupFilterBasis.topology /-- The topology associated to a module filter basis on a module over a topological ring. It has the given basis as a basis of neighborhoods of zero. This version gets the ring topology by unification instead of type class inference. -/ def topology' {R M : Type*} [CommRing R] {_ : TopologicalSpace R} [AddCommGroup M] [Module R M] (B : ModuleFilterBasis R M) : TopologicalSpace M := B.toAddGroupFilterBasis.topology /-- A topological add group with a basis of `𝓝 0` satisfying the axioms of `ModuleFilterBasis` is a topological module. This lemma is mathematically useless because one could obtain such a result by applying `ModuleFilterBasis.continuousSMul` and use the fact that group topologies are characterized by their neighborhoods of 0 to obtain the `ContinuousSMul` on the pre-existing topology. But it turns out it's just easier to get it as a byproduct of the proof, so this is just a free quality-of-life improvement. -/ theorem _root_.ContinuousSMul.of_basis_zero {ι : Type*} [IsTopologicalRing R] [TopologicalSpace M] [IsTopologicalAddGroup M] {p : ι → Prop} {b : ι → Set M} (h : HasBasis (𝓝 0) p b) (hsmul : ∀ {i}, p i → ∃ V ∈ 𝓝 (0 : R), ∃ j, p j ∧ V • b j ⊆ b i) (hsmul_left : ∀ (x₀ : R) {i}, p i → ∃ j, p j ∧ MapsTo (x₀ • ·) (b j) (b i)) (hsmul_right : ∀ (m₀ : M) {i}, p i → ∀ᶠ x in 𝓝 (0 : R), x • m₀ ∈ b i) : ContinuousSMul R M := by apply ContinuousSMul.of_nhds_zero · rw [h.tendsto_right_iff] intro i hi rcases hsmul hi with ⟨V, V_in, j, hj, hVj⟩ apply mem_of_superset (prod_mem_prod V_in <| h.mem_of_mem hj) rintro ⟨v, w⟩ ⟨v_in : v ∈ V, w_in : w ∈ b j⟩ exact hVj (Set.smul_mem_smul v_in w_in) · intro m₀ rw [h.tendsto_right_iff] intro i hi exact hsmul_right m₀ hi · intro x₀ rw [h.tendsto_right_iff] intro i hi rcases hsmul_left x₀ hi with ⟨j, hj, hji⟩ exact mem_of_superset (h.mem_of_mem hj) hji /-- If a module is endowed with a topological structure coming from a module filter basis then it's a topological module. -/ instance (priority := 100) continuousSMul [IsTopologicalRing R] : @ContinuousSMul R M _ _ B.topology := by let B' := B.toAddGroupFilterBasis let _ := B'.topology have _ := B'.isTopologicalAddGroup exact ContinuousSMul.of_basis_zero B'.nhds_zero_hasBasis (fun {_} => by simpa using B.smul) (by simpa using B.smul_left) B.smul_right /-- Build a module filter basis from compatible ring and additive group filter bases. -/ def ofBases {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] (BR : RingFilterBasis R) (BM : AddGroupFilterBasis M) (smul : ∀ {U}, U ∈ BM → ∃ V ∈ BR, ∃ W ∈ BM, V • W ⊆ U) (smul_left : ∀ (x₀ : R) {U}, U ∈ BM → ∃ V ∈ BM, V ⊆ (fun x ↦ x₀ • x) ⁻¹' U) (smul_right : ∀ (m₀ : M) {U}, U ∈ BM → ∃ V ∈ BR, V ⊆ (fun x ↦ x • m₀) ⁻¹' U) : @ModuleFilterBasis R M _ BR.topology _ _ := let _ := BR.topology { BM with smul' := by intro U U_in rcases smul U_in with ⟨V, V_in, W, W_in, H⟩ exact ⟨V, BR.toAddGroupFilterBasis.mem_nhds_zero V_in, W, W_in, H⟩ smul_left' := smul_left smul_right' := by intro m₀ U U_in rcases smul_right m₀ U_in with ⟨V, V_in, H⟩ exact mem_of_superset (BR.toAddGroupFilterBasis.mem_nhds_zero V_in) H } end ModuleFilterBasis
ssrint.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat choice seq. From mathcomp Require Import fintype finfun bigop order ssralg countalg ssrnum. From mathcomp Require Import poly. (******************************************************************************) (* This file develops a basic theory of signed integers, defining: *) (* int == the type of signed integers, with two constructors Posz for *) (* non-negative integers and Negz for negative integers. It *) (* supports the realDomainType interface (and its parents). *) (* n%:Z == explicit cast from nat to int (:= Posz n); displayed as n. *) (* However (Posz m = Posz n) is displayed as (m = n :> int) *) (* (and so are ==, != and <>) *) (* Lemma NegzE : turns (Negz n) into - n.+1%:Z. *) (* <number> == <number> as an int, with <number> an optional minus sign *) (* followed by a sequence of digits. This notation is in *) (* int_scope (delimited with %Z). *) (* x *~ m == m times x, with m : int; *) (* convertible to x *+ n if m is Posz n *) (* convertible to x *- n.+1 if m is Negz n. *) (* m%:~R == the image of m : int in a generic ring (:= 1 *~ m). *) (* x ^ m == x to the m, with m : int; *) (* convertible to x ^+ n if m is Posz n *) (* convertible to x ^- n.+1 if m is Negz n. *) (* sgz x == sign of x : R, *) (* equals (0 : int) if and only x == 0, *) (* equals (1 : int) if x is positive *) (* and (-1 : int) otherwise. *) (* `|m|%N == the n : nat such that `|m|%R = n%:Z, for m : int. *) (* `|m - n|%N == the distance between m and n; the '-' is specialized to *) (* the int type, so m and n can be either of type nat or int *) (* thanks to the Posz coercion; m and n are however parsed in *) (* the %N scope. The IntDist submodule provides this notation *) (* and the corresponding theory independently of the rest of *) (* of the int and ssralg libraries (and notations). *) (* Warning: due to the declaration of Posz as a coercion, two terms might be *) (* displayed the same while not being convertible, for instance: *) (* (Posz (x - y)) and (Posz x) - (Posz y) for x, y : nat. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope int_scope. Declare Scope distn_scope. Declare Scope rat_scope. Reserved Notation "*~%R" (format " *~%R"). Reserved Notation "x *~ n" (at level 40, left associativity, format "x *~ n"). Reserved Notation "n %:~R" (left associativity, format "n %:~R"). Reserved Notation "n %:Z" (left associativity, format "n %:Z"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "n = m :> 'int'" (format "n = m :> 'int'"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "n == m :> 'int'" (format "n == m :> 'int'"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "n != m :> 'int'" (format "n != m :> 'int'"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "n <> m :> 'int'" (format "n <> m :> 'int'"). Import Order.TTheory GRing.Theory Num.Theory. Delimit Scope int_scope with Z. Local Open Scope int_scope. (* Defining int *) Variant int : Set := Posz of nat | Negz of nat. (* This must be deferred to module DistInt to work around the design flaws of *) (* the Coq module system. *) (* Coercion Posz : nat >-> int. *) Notation "n %:Z" := (Posz n) (only parsing) : int_scope. Notation "n %:Z" := (Posz n) (only parsing) : ring_scope. Notation "n = m :> 'int'" := (@eq int n%Z m%Z) (only parsing) : ring_scope. Notation "n = m :> 'int'" := (Posz n = Posz m) (only printing) : ring_scope. Notation "n == m :> 'int'" := ((n%Z : int) == (m%Z : int)) (only parsing) : ring_scope. Notation "n == m :> 'int'" := (Posz n == Posz m) (only printing) : ring_scope. Notation "n != m :> 'int'" := ((n%Z : int) != (m%Z : int)) (only parsing) : ring_scope. Notation "n != m :> 'int'" := (Posz n != Posz m) (only printing) : ring_scope. Notation "n <> m :> 'int'" := (not (@eq int n%Z m%Z)) (only parsing) : ring_scope. Notation "n <> m :> 'int'" := (Posz n <> Posz m) (only printing) : ring_scope. Definition parse_int (x : Number.int) : int := match x with | Number.IntDecimal (Decimal.Pos u) => Posz (Nat.of_uint u) | Number.IntDecimal (Decimal.Neg u) => Negz (Nat.of_uint u).-1 | Number.IntHexadecimal (Hexadecimal.Pos u) => Posz (Nat.of_hex_uint u) | Number.IntHexadecimal (Hexadecimal.Neg u) => Negz (Nat.of_hex_uint u).-1 end. Definition print_int (x : int) : Number.int := match x with | Posz n => Number.IntDecimal (Decimal.Pos (Nat.to_uint n)) | Negz n => Number.IntDecimal (Decimal.Neg (Nat.to_uint n.+1)) end. Number Notation int parse_int print_int : int_scope. Definition natsum_of_int (m : int) : nat + nat := match m with Posz p => inl _ p | Negz n => inr _ n end. Definition int_of_natsum (m : nat + nat) := match m with inl p => Posz p | inr n => Negz n end. Lemma natsum_of_intK : cancel natsum_of_int int_of_natsum. Proof. by case. Qed. HB.instance Definition _ := Countable.copy int (can_type natsum_of_intK). Lemma eqz_nat (m n : nat) : (m%:Z == n%:Z) = (m == n). Proof. by []. Qed. Module intZmod. Section intZmod. Definition addz (m n : int) := match m, n with | Posz m', Posz n' => Posz (m' + n') | Negz m', Negz n' => Negz (m' + n').+1 | Posz m', Negz n' => if n' < m' then Posz (m' - n'.+1) else Negz (n' - m') | Negz n', Posz m' => if n' < m' then Posz (m' - n'.+1) else Negz (n' - m') end. Definition oppz m := match m with | Posz n => if n is (n'.+1)%N then Negz n' else Posz 0 | Negz n => Posz (n.+1)%N end. Arguments oppz : simpl never. Local Notation "-%Z" := (@oppz) : int_scope. Local Notation "- x" := (oppz x) : int_scope. Local Notation "+%Z" := (@addz) : int_scope. Local Notation "x + y" := (addz x y) : int_scope. Local Notation "x - y" := (x + - y) : int_scope. Lemma PoszD : {morph Posz : m n / (m + n)%N >-> m + n}. Proof. by []. Qed. Local Coercion Posz : nat >-> int. Lemma NegzE (n : nat) : Negz n = - n.+1. Proof. by []. Qed. Lemma int_rect (P : int -> Type) : P 0 -> (forall n : nat, P n -> P (n.+1)) -> (forall n : nat, P (- n) -> P (- (n.+1))) -> forall n : int, P n. Proof. by move=> P0 hPp hPn []; elim=> [|n ihn]//; do ?[apply: hPn | apply: hPp]. Qed. Definition int_rec := int_rect. Definition int_ind := int_rect. Variant int_spec (x : int) : int -> Type := | ZintNull of x = 0 : int_spec x 0 | ZintPos n of x = n.+1 : int_spec x n.+1 | ZintNeg n of x = - (n.+1)%:Z : int_spec x (- n.+1). Lemma intP x : int_spec x x. Proof. by move: x=> [] []; constructor. Qed. Lemma addzC : commutative addz. Proof. by move=> [] m [] n //=; rewrite addnC. Qed. Lemma add0z : left_id 0 addz. Proof. by do 2?case. Qed. Lemma oppzK : involutive oppz. Proof. by do 2?case. Qed. Lemma oppzD : {morph oppz : m n / m + n}. Proof. by move=> [[|n]|n] [[|m]|m] /=; rewrite ?addn0 ?subn0 ?addnS //; rewrite !NegzE !ltnS !subSS; case: ltngtP => [?|?|->]; rewrite ?subnn // ?oppzK ?subnS ?prednK // subn_gt0. Qed. Lemma add1Pz (n : int) : 1 + (n - 1) = n. Proof. by case: (intP n)=> // n' /= _; rewrite ?(subn1, addn0). Qed. Lemma subSz1 (n : int) : 1 + n - 1 = n. Proof. by apply: (inv_inj oppzK); rewrite addzC !oppzD oppzK [_ - n]addzC add1Pz. Qed. Lemma addSnz (m : nat) (n : int) : m.+1%N + n = 1 + (m + n). Proof. move: m n=> [|m] [] [|n] //=; rewrite ?add1n ?subn1 // !(ltnS, subSS). case: ltngtP=> hnm /=; rewrite ?hnm ?subnn //. by rewrite subnS add1n prednK ?subn_gt0. by rewrite ltnS leqn0 subn_eq0 leqNgt hnm /= subnS subn1. Qed. Lemma addSz (m n : int) : (1 + m) + n = 1 + (m + n). Proof. case: m => [] m; first by rewrite -PoszD add1n addSnz. rewrite !NegzE; apply: (inv_inj oppzK). rewrite !oppzD !oppzK addSnz [-1%:Z + _]addzC addSnz add1Pz. by rewrite [-1%:Z + _]addzC subSz1. Qed. Lemma addPz (m n : int) : (m - 1) + n = (m + n) - 1. Proof. by apply: (inv_inj oppzK); rewrite !oppzD oppzK [_ + 1]addzC addSz addzC. Qed. Lemma addzA : associative addz. Proof. elim=> [|m ihm|m ihm] n p; first by rewrite !add0z. by rewrite -add1n PoszD !addSz ihm. by rewrite -add1n addnC PoszD oppzD !addPz ihm. Qed. Lemma addNz : left_inverse (0:int) oppz addz. Proof. by do 3?elim. Qed. Lemma predn_int (n : nat) : 0 < n -> n.-1%:Z = n - 1. Proof. by case: n => //= n _; rewrite subn1. Qed. Definition Mixin := GRing.isZmodule.Build int addzA addzC add0z addNz. End intZmod. Arguments oppz : simpl never. End intZmod. HB.instance Definition _ := intZmod.Mixin. HB.instance Definition _ := GRing.isNmodMorphism.Build nat int Posz (erefl, intZmod.PoszD). Local Open Scope ring_scope. Section intZmoduleTheory. Local Coercion Posz : nat >-> int. Lemma PoszD : {morph Posz : n m / (n + m)%N >-> n + m}. Proof. by []. Qed. Lemma NegzE (n : nat) : Negz n = -(n.+1)%:Z. Proof. by []. Qed. Lemma int_rect (P : int -> Type) : P 0 -> (forall n : nat, P n -> P (n.+1)%N) -> (forall n : nat, P (- (n%:Z)) -> P (- (n.+1%N%:Z))) -> forall n : int, P n. Proof. by move=> P0 hPp hPn []; elim=> [|n ihn]//; do ?[apply: hPn | apply: hPp]. Qed. Definition int_rec := int_rect. Definition int_ind := int_rect. Variant int_spec (x : int) : int -> Type := | ZintNull : int_spec x 0 | ZintPos n : int_spec x n.+1 | ZintNeg n : int_spec x (- (n.+1)%:Z). Lemma intP x : int_spec x x. Proof. by move: x=> [] [] *; rewrite ?NegzE; constructor. Qed. Definition oppzD := @opprD int. Lemma subzn (m n : nat) : (n <= m)%N -> m%:Z - n%:Z = (m - n)%N. Proof. elim: n=> //= [|n ihn] hmn; first by rewrite subr0 subn0. rewrite subnS -addn1 !PoszD opprD addrA ihn 1?ltnW //. by rewrite intZmod.predn_int // subn_gt0. Qed. Lemma subzSS (m n : nat) : m.+1%:Z - n.+1%:Z = m%:Z - n%:Z. Proof. by elim: n m=> [|n ihn] m //; rewrite !subzn. Qed. End intZmoduleTheory. Module intRing. Section intRing. Local Coercion Posz : nat >-> int. Definition mulz (m n : int) := match m, n with | Posz m', Posz n' => (m' * n')%N%:Z | Negz m', Negz n' => (m'.+1%N * n'.+1%N)%N%:Z | Posz m', Negz n' => - (m' * (n'.+1%N))%N%:Z | Negz n', Posz m' => - (m' * (n'.+1%N))%N%:Z end. Local Notation "*%Z" := (@mulz) : int_scope. Local Notation "x * y" := (mulz x y) : int_scope. Lemma mul0z : left_zero 0 *%Z. Proof. by case=> [n|[|n]] //=; rewrite muln0. Qed. Lemma mulzC : commutative mulz. Proof. by move=> [] m [] n //=; rewrite mulnC. Qed. Lemma mulz0 : right_zero 0 *%Z. Proof. by move=> x; rewrite mulzC mul0z. Qed. Lemma mulzN (m n : int) : (m * (- n))%Z = - (m * n)%Z. Proof. by case: (intP m)=> {m} [|m|m]; rewrite ?mul0z //; case: (intP n)=> {n} [|n|n]; rewrite ?mulz0 //= mulnC. Qed. Lemma mulNz (m n : int) : ((- m) * n)%Z = - (m * n)%Z. Proof. by rewrite mulzC mulzN mulzC. Qed. Lemma mulzA : associative mulz. Proof. by move=> [] m [] n [] p; rewrite ?NegzE ?(mulnA,mulNz,mulzN,opprK) //= ?mulnA. Qed. Lemma mul1z : left_id 1%Z mulz. Proof. by case=> [[|n]|n] //=; rewrite ?mul1n// plusE addn0. Qed. Lemma mulzS (x : int) (n : nat) : (x * n.+1%:Z)%Z = x + (x * n)%Z. Proof. by case: (intP x)=> [|m'|m'] //=; [rewrite mulnS|rewrite mulSn -opprD]. Qed. Lemma mulz_addl : left_distributive mulz (+%R). Proof. move=> x y z; elim: z=> [|n|n]; first by rewrite !(mul0z,mulzC). by rewrite !mulzS=> ->; rewrite !addrA [X in X + _]addrAC. rewrite !mulzN !mulzS -!opprD=> /oppr_inj->. by rewrite !addrA [X in X + _]addrAC. Qed. Lemma nonzero1z : 1%Z != 0. Proof. by []. Qed. Definition comMixin := GRing.Zmodule_isComNzRing.Build int mulzA mulzC mul1z mulz_addl nonzero1z. End intRing. End intRing. HB.instance Definition _ := intRing.comMixin. Section intRingTheory. Implicit Types m n : int. Local Coercion Posz : nat >-> int. Lemma PoszM : {morph Posz : n m / (n * m)%N >-> n * m}. Proof. by []. Qed. Lemma intS (n : nat) : n.+1%:Z = 1 + n%:Z. Proof. by rewrite -PoszD. Qed. Lemma predn_int (n : nat) : (0 < n)%N -> n.-1%:Z = n%:Z - 1. Proof. exact: intZmod.predn_int. Qed. End intRingTheory. HB.instance Definition _ := GRing.isMonoidMorphism.Build nat int Posz (erefl, PoszM). Module intUnitRing. Section intUnitRing. Implicit Types m n : int. Local Coercion Posz : nat >-> int. Definition unitz := [qualify a n : int | (n == 1) || (n == -1)]. Definition invz n : int := n. Lemma mulVz : {in unitz, left_inverse 1%R invz *%R}. Proof. by move=> n /pred2P[] ->. Qed. Lemma mulzn_eq1 m (n : nat) : (m * n == 1) = (m == 1) && (n == 1). Proof. by case: m => m /=; [rewrite -PoszM [_==_]muln_eq1 | case: n]. Qed. Lemma unitzPl m n : n * m = 1 -> m \is a unitz. Proof. rewrite qualifE => /eqP. by case: m => m; rewrite ?NegzE ?mulrN -?mulNr mulzn_eq1 => /andP[_ /eqP->]. Qed. Lemma invz_out : {in [predC unitz], invz =1 id}. Proof. exact. Qed. Lemma idomain_axiomz m n : m * n = 0 -> (m == 0) || (n == 0). Proof. by case: m n => [[|m]|m] [[|n]|n]. Qed. Definition comMixin := GRing.ComNzRing_hasMulInverse.Build int mulVz unitzPl invz_out. End intUnitRing. End intUnitRing. HB.instance Definition _ := intUnitRing.comMixin. HB.instance Definition _ := GRing.ComUnitRing_isIntegral.Build int intUnitRing.idomain_axiomz. Definition absz m := match m with Posz p => p | Negz n => n.+1 end. Notation "m - n" := (@GRing.add int m%N (@GRing.opp int n%N)) : distn_scope. Arguments absz m%_distn_scope. Local Notation "`| m |" := (absz m) : nat_scope. Module intOrdered. Section intOrdered. Implicit Types m n p : int. Local Coercion Posz : nat >-> int. Local Notation normz m := (absz m)%:Z. Definition lez m n := match m, n with | Posz m', Posz n' => (m' <= n')%N | Posz m', Negz n' => false | Negz m', Posz n' => true | Negz m', Negz n' => (n' <= m')%N end. Definition ltz m n := match m, n with | Posz m', Posz n' => (m' < n')%N | Posz m', Negz n' => false | Negz m', Posz n' => true | Negz m', Negz n' => (n' < m')%N end. Fact lez_add m n : lez 0 m -> lez 0 n -> lez 0 (m + n). Proof. by case: m n => [] m [] n. Qed. Fact lez_mul m n : lez 0 m -> lez 0 n -> lez 0 (m * n). Proof. by case: m n => [] m [] n. Qed. Fact lez_anti m : lez 0 m -> lez m 0 -> m = 0. Proof. by case: m; first case. Qed. Lemma subz_ge0 m n : lez 0 (n - m) = lez m n. Proof. case: (intP m); case: (intP n)=> // {}m {}n /=; rewrite ?ltnS -?opprD ?opprB ?subzSS; case: leqP=> // hmn; by [ rewrite subzn // | rewrite -opprB subzn ?(ltnW hmn) //; move: hmn; rewrite -subn_gt0; case: (_ - _)%N]. Qed. Fact lez_total m n : lez m n || lez n m. Proof. by move: m n => [] m [] n //=; apply: leq_total. Qed. Fact normzN m : normz (- m) = normz m. Proof. by case: m => // -[]. Qed. Fact gez0_norm m : lez 0 m -> normz m = m. Proof. by case: m. Qed. Fact ltz_def m n : (ltz m n) = (n != m) && (lez m n). Proof. by move: m n => [] m [] n //=; rewrite (ltn_neqAle, leq_eqVlt) // eq_sym. Qed. Definition Mixin := Num.IntegralDomain_isLeReal.Build int lez_add lez_mul lez_anti subz_ge0 (lez_total 0) normzN gez0_norm ltz_def. End intOrdered. End intOrdered. HB.instance Definition _ := intOrdered.Mixin. Section intOrderedTheory. Local Coercion Posz : nat >-> int. Implicit Types m n p : nat. Implicit Types x y z : int. Lemma lez_nat m n : (m <= n :> int) = (m <= n)%N. Proof. by []. Qed. Lemma ltz_nat m n : (m < n :> int) = (m < n)%N. Proof. by rewrite ltnNge ltNge lez_nat. Qed. Definition ltez_nat := (lez_nat, ltz_nat). Lemma leNz_nat m n : (- m%:Z <= n). Proof. by case: m. Qed. Lemma ltNz_nat m n : (- m%:Z < n) = (m != 0) || (n != 0). Proof. by move: m n=> [|?] []. Qed. Definition lteNz_nat := (leNz_nat, ltNz_nat). Lemma lezN_nat m n : (m%:Z <= - n%:Z) = (m == 0) && (n == 0). Proof. by move: m n=> [|?] []. Qed. Lemma ltzN_nat m n : (m%:Z < - n%:Z) = false. Proof. by move: m n=> [|?] []. Qed. Lemma le0z_nat n : 0 <= n :> int. Proof. by []. Qed. Lemma lez0_nat n : n <= 0 :> int = (n == 0 :> nat). Proof. by elim: n. Qed. Definition ltezN_nat := (lezN_nat, ltzN_nat). Definition ltez_natE := (ltez_nat, lteNz_nat, ltezN_nat, le0z_nat, lez0_nat). Lemma gtz0_ge1 x : (0 < x) = (1 <= x). Proof. by case: (intP x). Qed. Lemma lez1D x y : (1 + x <= y) = (x < y). Proof. by rewrite -subr_gt0 gtz0_ge1 lterBDr. Qed. Lemma lezD1 x y : (x + 1 <= y) = (x < y). Proof. by rewrite addrC lez1D. Qed. Lemma ltz1D x y : (x < 1 + y) = (x <= y). Proof. by rewrite -lez1D lerD2l. Qed. Lemma ltzD1 x y : (x < y + 1) = (x <= y). Proof. by rewrite -lezD1 lerD2r. Qed. End intOrderedTheory. Bind Scope ring_scope with int. (* definition of intmul *) Definition intmul (R : zmodType) (x : R) (n : int) := match n with | Posz n => (x *+ n)%R | Negz n => (x *- (n.+1))%R end. Arguments intmul : simpl never. Notation "*~%R" := (@intmul _) : function_scope. Notation "x *~ n" := (intmul x n) : ring_scope. Notation intr := ( *~%R 1). Notation "n %:~R" := (1 *~ n)%R : ring_scope. Lemma pmulrn (R : zmodType) (x : R) (n : nat) : x *+ n = x *~ n%:Z. Proof. by []. Qed. Lemma nmulrn (R : zmodType) (x : R) (n : nat) : x *- n = x *~ - n%:Z. Proof. by case: n; rewrite // oppr0. Qed. Section ZintLmod. Definition zmodule (M : Type) : Type := M. Local Notation "M ^z" := (zmodule M) (format "M ^z") : type_scope. Local Coercion Posz : nat >-> int. Variable M : zmodType. Implicit Types m n : int. Implicit Types x y z : M. Fact mulrzA_C m n x : (x *~ n) *~ m = x *~ (m * n). Proof. elim: m=> [|m _|m _]; elim: n=> [|n _|n _]; rewrite /intmul //=; rewrite ?(muln0, mulr0n, mul0rn, oppr0, mulNrn, opprK) //; do ?by rewrite mulnC mulrnA. * by rewrite -mulrnA mulnC. * by rewrite -mulrnA. Qed. Fact mulrzAC m n x : (x *~ n) *~ m = (x *~ m) *~ n. Proof. by rewrite !mulrzA_C mulrC. Qed. Fact mulr1z (x : M) : x *~ 1 = x. Proof. by []. Qed. Fact mulrzDl m : {morph ( *~%R^~ m : M -> M) : x y / x + y}. Proof. by case: m => m x y; rewrite /intmul mulrnDl // opprD. Qed. Lemma mulrzBl_nat (m n : nat) x : x *~ (m%:Z - n%:Z) = x *~ m - x *~ n. Proof. wlog/subnK <-: m n / (n <= m)%N; last by rewrite -!pmulrn PoszD mulrnDr !addrK. have [hmn|/ltnW hmn] := leqP n m; first exact. by rewrite -[in LHS]opprB -[RHS]opprB subzn // -nmulrn pmulrn -subzn // => ->. Qed. Fact mulrzDr x : {morph *~%R x : m n / m + n}. Proof. by case=> []m []n; rewrite ?NegzE /intmul /= -/(intmul _ _) -?opprD; rewrite -?[- _ + _]addrC ?mulrzBl_nat // -mulrnDr // addnS. Qed. HB.instance Definition _ := GRing.Zmodule.on M^z. (* FIXME, the error message below "nomsg" when we forget this line is not very helpful *) HB.instance Definition _ := @GRing.Zmodule_isLmodule.Build _ M^z (fun n x => x *~ n) mulrzA_C mulr1z mulrzDl mulrzDr. Lemma scalezrE n x : n *: (x : M^z) = x *~ n. Proof. by []. Qed. Lemma mulrzA x m n : x *~ (m * n) = x *~ m *~ n. Proof. by rewrite -!scalezrE scalerA mulrC. Qed. Lemma mulr0z x : x *~ 0 = 0. Proof. by []. Qed. Lemma mul0rz n : 0 *~ n = 0 :> M. Proof. by rewrite -scalezrE scaler0. Qed. Lemma mulrNz x n : x *~ (- n) = - (x *~ n). Proof. by rewrite -scalezrE scaleNr. Qed. Lemma mulrN1z x : x *~ (- 1) = - x. Proof. by rewrite -scalezrE scaleN1r. Qed. Lemma mulNrz x n : (- x) *~ n = - (x *~ n). Proof. by rewrite -scalezrE scalerN. Qed. Lemma mulrzBr x m n : x *~ (m - n) = x *~ m - x *~ n. Proof. by rewrite -scalezrE scalerBl. Qed. Lemma mulrzBl x y n : (x - y) *~ n = x *~ n - y *~ n. Proof. by rewrite -scalezrE scalerBr. Qed. Lemma mulrz_nat (n : nat) x : x *~ n%:R = x *+ n. Proof. by rewrite -scalezrE scaler_nat. Qed. Lemma mulrz_sumr : forall x I r (P : pred I) F, x *~ (\sum_(i <- r | P i) F i) = \sum_(i <- r | P i) x *~ F i. Proof. by rewrite -/M^z; apply: scaler_suml. Qed. Lemma mulrz_suml : forall n I r (P : pred I) (F : I -> M), (\sum_(i <- r | P i) F i) *~ n= \sum_(i <- r | P i) F i *~ n. Proof. by rewrite -/M^z; apply: scaler_sumr. Qed. HB.instance Definition _ (x : M) := GRing.isZmodMorphism.Build int M ( *~%R x) (@mulrzBr x). End ZintLmod. #[deprecated(since="mathcomp 2.3.0", note="Use mulrzDl instead.")] Notation mulrzDl_tmp := mulrzDl. #[deprecated(since="mathcomp 2.3.0", note="Use mulrzDr instead.")] Notation mulrzDr_tmp := mulrzDr. Lemma ffunMzE (I : finType) (M : zmodType) (f : {ffun I -> M}) z x : (f *~ z) x = f x *~ z. Proof. by case: z => n; rewrite ?ffunE ffunMnE. Qed. Lemma intz (n : int) : n%:~R = n. Proof. by case: n => n; rewrite ?NegzE /intmul/= -(rmorphMn Posz)/= natn. Qed. Lemma natz (n : nat) : n%:R = n%:Z :> int. Proof. by rewrite pmulrn intz. Qed. Section RintMod. Local Coercion Posz : nat >-> int. Variable R : pzRingType. Implicit Types m n : int. Implicit Types x y z : R. Lemma mulrzAl n x y : (x *~ n) * y = (x * y) *~ n. Proof. by case: n => n; rewrite ?mulNr mulrnAl. Qed. Lemma mulrzAr n x y : x * (y *~ n) = (x * y) *~ n. Proof. by case: n => n; rewrite ?mulrN mulrnAr. Qed. Lemma mulrzl x n : n%:~R * x = x *~ n. Proof. by rewrite mulrzAl mul1r. Qed. Lemma mulrzr x n : x * n%:~R = x *~ n. Proof. by rewrite mulrzAr mulr1. Qed. Lemma mulNrNz n x : (- x) *~ (- n) = x *~ n. Proof. by rewrite mulNrz mulrNz opprK. Qed. Lemma mulrbz x (b : bool) : x *~ b = (if b then x else 0). Proof. by case: b. Qed. Lemma intrN n : (- n)%:~R = - n%:~R :> R. Proof. exact: mulrNz. Qed. Lemma intrD m n : (m + n)%:~R = m%:~R + n%:~R :> R. Proof. exact: mulrzDr. Qed. Lemma intrB m n : (m - n)%:~R = m%:~R - n%:~R :> R. Proof. exact: mulrzBr. Qed. Lemma intrM m n : (m * n)%:~R = m%:~R * n%:~R :> R. Proof. by rewrite mulrzA -mulrzr. Qed. Lemma intmul1_is_monoid_morphism : monoid_morphism ( *~%R (1 : R)). Proof. by split; move=> // x y /=; rewrite ?intrD ?mulrNz ?intrM. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `intmul1_is_monoid_morphism` instead")] Definition intmul1_is_multiplicative := (fun g => (g.2,g.1)) intmul1_is_monoid_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build int R ( *~%R 1) intmul1_is_monoid_morphism. Lemma mulr2z n : n *~ 2 = n + n. Proof. exact: mulr2n. Qed. End RintMod. Lemma mulrzz m n : m *~ n = m * n. Proof. by rewrite -mulrzr intz. Qed. Lemma mulz2 n : n * 2%:Z = n + n. Proof. by rewrite -mulrzz. Qed. Lemma mul2z n : 2%:Z * n = n + n. Proof. by rewrite mulrC -mulrzz. Qed. Section LMod. Variable R : pzRingType. Variable V : (lmodType R). Local Coercion Posz : nat >-> int. Implicit Types m n : int. Implicit Types x y z : R. Implicit Types u v w : V. Lemma scaler_int n v : n%:~R *: v = v *~ n. Proof. by case: n => n; rewrite /intmul ?scaleNr scaler_nat. Qed. Lemma scalerMzl a v n : (a *: v) *~ n = (a *~ n) *: v. Proof. by rewrite -mulrzl -scaler_int scalerA. Qed. Lemma scalerMzr a v n : (a *: v) *~ n = a *: (v *~ n). Proof. by rewrite -!scaler_int !scalerA mulrzr mulrzl. Qed. End LMod. Lemma mulrz_int (M : zmodType) (n : int) (x : M) : x *~ n%:~R = x *~ n. Proof. by rewrite -scalezrE scaler_int. Qed. Section MorphTheory. Local Coercion Posz : nat >-> int. Section Additive. Variables (U V : zmodType) (f : {additive U -> V}). Lemma raddfMz n : {morph f : x / x *~ n}. Proof. by case: n=> n x; rewrite 1?raddfN raddfMn. Qed. End Additive. Section Multiplicative. Variables (R S : pzRingType) (f : {rmorphism R -> S}). Lemma rmorphMz : forall n, {morph f : x / x *~ n}. Proof. exact: raddfMz. Qed. Lemma rmorph_int : forall n, f n%:~R = n%:~R. Proof. by move=> n; rewrite rmorphMz rmorph1. Qed. End Multiplicative. Section Linear. Variable R : pzRingType. Variables (U V : lmodType R) (f : {linear U -> V}). Lemma linearMn : forall n, {morph f : x / x *~ n}. Proof. exact: raddfMz. Qed. End Linear. Lemma raddf_int_scalable (aV rV : lmodType int) (f : {additive aV -> rV}) : scalable f. Proof. by move=> z u; rewrite -[z]intz !scaler_int raddfMz. Qed. Section Zintmul1rMorph. Variable R : pzRingType. Lemma commrMz (x y : R) n : GRing.comm x y -> GRing.comm x (y *~ n). Proof. by rewrite /GRing.comm=> com_xy; rewrite mulrzAr mulrzAl com_xy. Qed. Lemma commr_int (x : R) n : GRing.comm x n%:~R. Proof. exact/commrMz/commr1. Qed. End Zintmul1rMorph. Section ZintBigMorphism. Variable R : pzRingType. Lemma sumMz : forall I r (P : pred I) F, (\sum_(i <- r | P i) F i)%N%:~R = \sum_(i <- r | P i) ((F i)%:~R) :> R. Proof. exact: rmorph_sum. Qed. Lemma prodMz : forall I r (P : pred I) F, (\prod_(i <- r | P i) F i)%N%:~R = \prod_(i <- r | P i) ((F i)%:~R) :> R. Proof. exact: rmorph_prod. Qed. End ZintBigMorphism. Section Frobenius. Variable R : nzRingType. Implicit Types x y : R. Variable p : nat. Hypothesis pcharFp : p \in [pchar R]. Local Notation "x ^f" := (pFrobenius_aut pcharFp x). Lemma pFrobenius_autMz x n : (x *~ n)^f = x^f *~ n. Proof. case: n=> n /=; first exact: pFrobenius_autMn. by rewrite !NegzE !mulrNz pFrobenius_autN pFrobenius_autMn. Qed. Lemma pFrobenius_aut_int n : (n%:~R)^f = n%:~R. Proof. by rewrite pFrobenius_autMz pFrobenius_aut1. Qed. End Frobenius. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autMz instead.")] Notation Frobenius_autMz := (pFrobenius_autMz) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut_int instead.")] Notation Frobenius_aut_int := (pFrobenius_aut_int) (only parsing). Section NumMorphism. Section PO. Variables (R : numDomainType). Implicit Types n m : int. Implicit Types x y : R. Lemma rmorphzP (f : {rmorphism int -> R}) : f =1 ( *~%R 1). Proof. by move=> n; rewrite -[n in LHS]intz rmorph_int. Qed. (* intmul and ler/ltr *) Lemma ler_pMz2r n (hn : 0 < n) : {mono *~%R^~ n :x y / x <= y :> R}. Proof. by move=> x y; case: n hn=> [[]|] // n _; rewrite ler_pMn2r. Qed. Lemma ltr_pMz2r n (hn : 0 < n) : {mono *~%R^~ n : x y / x < y :> R}. Proof. exact: leW_mono (ler_pMz2r _). Qed. Lemma ler_nMz2r n (hn : n < 0) : {mono *~%R^~ n : x y /~ x <= y :> R}. Proof. by move=> x y /=; rewrite -![_ *~ n]mulNrNz ler_pMz2r (oppr_cp0, lerN2). Qed. Lemma ltr_nMz2r n (hn : n < 0) : {mono *~%R^~ n : x y /~ x < y :> R}. Proof. exact: leW_nmono (ler_nMz2r _). Qed. Lemma ler_wpMz2r n (hn : 0 <= n) : {homo *~%R^~ n : x y / x <= y :> R}. Proof. by move=> x y xy; case: n hn=> [] // n _; rewrite ler_wMn2r. Qed. Lemma ler_wnMz2r n (hn : n <= 0) : {homo *~%R^~ n : x y /~ x <= y :> R}. Proof. by move=> x y xy /=; rewrite -lerN2 -!mulrNz ler_wpMz2r // oppr_ge0. Qed. Lemma mulrz_ge0 x n (x0 : 0 <= x) (n0 : 0 <= n) : 0 <= x *~ n. Proof. by rewrite -(mul0rz _ n) ler_wpMz2r. Qed. Lemma mulrz_le0 x n (x0 : x <= 0) (n0 : n <= 0) : 0 <= x *~ n. Proof. by rewrite -(mul0rz _ n) ler_wnMz2r. Qed. Lemma mulrz_ge0_le0 x n (x0 : 0 <= x) (n0 : n <= 0) : x *~ n <= 0. Proof. by rewrite -(mul0rz _ n) ler_wnMz2r. Qed. Lemma mulrz_le0_ge0 x n (x0 : x <= 0) (n0 : 0 <= n) : x *~ n <= 0. Proof. by rewrite -(mul0rz _ n) ler_wpMz2r. Qed. Lemma pmulrz_lgt0 x n (n0 : 0 < n) : 0 < x *~ n = (0 < x). Proof. by rewrite -(mul0rz _ n) ltr_pMz2r // mul0rz. Qed. Lemma nmulrz_lgt0 x n (n0 : n < 0) : 0 < x *~ n = (x < 0). Proof. by rewrite -(mul0rz _ n) ltr_nMz2r // mul0rz. Qed. Lemma pmulrz_llt0 x n (n0 : 0 < n) : x *~ n < 0 = (x < 0). Proof. by rewrite -(mul0rz _ n) ltr_pMz2r // mul0rz. Qed. Lemma nmulrz_llt0 x n (n0 : n < 0) : x *~ n < 0 = (0 < x). Proof. by rewrite -(mul0rz _ n) ltr_nMz2r // mul0rz. Qed. Lemma pmulrz_lge0 x n (n0 : 0 < n) : 0 <= x *~ n = (0 <= x). Proof. by rewrite -(mul0rz _ n) ler_pMz2r // mul0rz. Qed. Lemma nmulrz_lge0 x n (n0 : n < 0) : 0 <= x *~ n = (x <= 0). Proof. by rewrite -(mul0rz _ n) ler_nMz2r // mul0rz. Qed. Lemma pmulrz_lle0 x n (n0 : 0 < n) : x *~ n <= 0 = (x <= 0). Proof. by rewrite -(mul0rz _ n) ler_pMz2r // mul0rz. Qed. Lemma nmulrz_lle0 x n (n0 : n < 0) : x *~ n <= 0 = (0 <= x). Proof. by rewrite -(mul0rz _ n) ler_nMz2r // mul0rz. Qed. Lemma ler_wpMz2l x (hx : 0 <= x) : {homo *~%R x : x y / x <= y}. Proof. by move=> m n /= hmn; rewrite -subr_ge0 -mulrzBr mulrz_ge0 // subr_ge0. Qed. Lemma ler_wnMz2l x (hx : x <= 0) : {homo *~%R x : x y /~ x <= y}. Proof. by move=> m n /= hmn; rewrite -subr_ge0 -mulrzBr mulrz_le0 // subr_le0. Qed. Lemma ler_pMz2l x (hx : 0 < x) : {mono *~%R x : x y / x <= y}. Proof. move=> m n /=; rewrite real_mono ?num_real // => {m n}. by move=> m n /= hmn; rewrite -subr_gt0 -mulrzBr pmulrz_lgt0 // subr_gt0. Qed. Lemma ler_nMz2l x (hx : x < 0) : {mono *~%R x : x y /~ x <= y}. Proof. move=> m n /=; rewrite real_nmono ?num_real // => {m n}. by move=> m n /= hmn; rewrite -subr_gt0 -mulrzBr nmulrz_lgt0 // subr_lt0. Qed. Lemma ltr_pMz2l x (hx : 0 < x) : {mono *~%R x : x y / x < y}. Proof. exact: leW_mono (ler_pMz2l _). Qed. Lemma ltr_nMz2l x (hx : x < 0) : {mono *~%R x : x y /~ x < y}. Proof. exact: leW_nmono (ler_nMz2l _). Qed. Lemma pmulrz_rgt0 x n (x0 : 0 < x) : 0 < x *~ n = (0 < n). Proof. by rewrite -(mulr0z x) ltr_pMz2l. Qed. Lemma nmulrz_rgt0 x n (x0 : x < 0) : 0 < x *~ n = (n < 0). Proof. by rewrite -(mulr0z x) ltr_nMz2l. Qed. Lemma pmulrz_rlt0 x n (x0 : 0 < x) : x *~ n < 0 = (n < 0). Proof. by rewrite -(mulr0z x) ltr_pMz2l. Qed. Lemma nmulrz_rlt0 x n (x0 : x < 0) : x *~ n < 0 = (0 < n). Proof. by rewrite -(mulr0z x) ltr_nMz2l. Qed. Lemma pmulrz_rge0 x n (x0 : 0 < x) : 0 <= x *~ n = (0 <= n). Proof. by rewrite -(mulr0z x) ler_pMz2l. Qed. Lemma nmulrz_rge0 x n (x0 : x < 0) : 0 <= x *~ n = (n <= 0). Proof. by rewrite -(mulr0z x) ler_nMz2l. Qed. Lemma pmulrz_rle0 x n (x0 : 0 < x) : x *~ n <= 0 = (n <= 0). Proof. by rewrite -(mulr0z x) ler_pMz2l. Qed. Lemma nmulrz_rle0 x n (x0 : x < 0) : x *~ n <= 0 = (0 <= n). Proof. by rewrite -(mulr0z x) ler_nMz2l. Qed. Lemma mulrIz x (hx : x != 0) : injective ( *~%R x). Proof. move=> y z; rewrite -![x *~ _]mulrzr => /(mulfI hx). by apply: inc_inj y z; exact: ler_pMz2l. Qed. Lemma ler_int m n : (m%:~R <= n%:~R :> R) = (m <= n). Proof. by rewrite ler_pMz2l. Qed. Lemma ltr_int m n : (m%:~R < n%:~R :> R) = (m < n). Proof. by rewrite ltr_pMz2l. Qed. Lemma eqr_int m n : (m%:~R == n%:~R :> R) = (m == n). Proof. by rewrite (inj_eq (mulrIz _)) ?oner_eq0. Qed. Lemma ler0z n : (0 <= n%:~R :> R) = (0 <= n). Proof. by rewrite pmulrz_rge0. Qed. Lemma ltr0z n : (0 < n%:~R :> R) = (0 < n). Proof. by rewrite pmulrz_rgt0. Qed. Lemma lerz0 n : (n%:~R <= 0 :> R) = (n <= 0). Proof. by rewrite pmulrz_rle0. Qed. Lemma ltrz0 n : (n%:~R < 0 :> R) = (n < 0). Proof. by rewrite pmulrz_rlt0. Qed. Lemma ler1z (n : int) : (1 <= n%:~R :> R) = (1 <= n). Proof. by rewrite -[1]/(1%:~R) ler_int. Qed. Lemma ltr1z (n : int) : (1 < n%:~R :> R) = (1 < n). Proof. by rewrite -[1]/(1%:~R) ltr_int. Qed. Lemma lerz1 n : (n%:~R <= 1 :> R) = (n <= 1). Proof. by rewrite -[1]/(1%:~R) ler_int. Qed. Lemma ltrz1 n : (n%:~R < 1 :> R) = (n < 1). Proof. by rewrite -[1]/(1%:~R) ltr_int. Qed. Lemma intr_eq0 n : (n%:~R == 0 :> R) = (n == 0). Proof. by rewrite -(mulr0z 1) (inj_eq (mulrIz _)) // oner_eq0. Qed. Lemma mulrz_eq0 x n : (x *~ n == 0) = ((n == 0) || (x == 0)). Proof. by rewrite -mulrzl mulf_eq0 intr_eq0. Qed. Lemma mulrz_neq0 x n : x *~ n != 0 = ((n != 0) && (x != 0)). Proof. by rewrite mulrz_eq0 negb_or. Qed. Lemma realz n : (n%:~R : R) \in Num.real. Proof. by rewrite -topredE /Num.real /= ler0z lerz0 le_total. Qed. Hint Resolve realz : core. Definition intr_inj := @mulrIz 1 (oner_neq0 R). End PO. End NumMorphism. End MorphTheory. Arguments intr_inj {R} [x1 x2]. Definition exprz (R : unitRingType) (x : R) (n : int) := match n with | Posz n => x ^+ n | Negz n => x ^- (n.+1) end. Arguments exprz : simpl never. Notation "x ^ n" := (exprz x n) : ring_scope. Section ExprzUnitRing. Variable R : unitRingType. Implicit Types x y : R. Implicit Types m n : int. Local Coercion Posz : nat >-> int. Lemma exprnP x (n : nat) : x ^+ n = x ^ n. Proof. by []. Qed. Lemma exprnN x (n : nat) : x ^- n = x ^ (-n%:Z). Proof. by case: n=> //; rewrite oppr0 expr0 invr1. Qed. Lemma expr0z x : x ^ 0 = 1. Proof. by []. Qed. Lemma expr1z x : x ^ 1 = x. Proof. by []. Qed. Lemma exprN1 x : x ^ (-1) = x^-1. Proof. by []. Qed. Lemma invr_expz x n : (x ^ n)^-1 = x ^ (- n). Proof. by case: (intP n)=> // [|m]; rewrite ?opprK ?expr0z ?invr1 // invrK. Qed. Lemma exprz_inv x n : (x^-1) ^ n = x ^ (- n). Proof. by case: (intP n)=> // m; rewrite -[_ ^ (- _)]exprVn ?opprK ?invrK. Qed. Lemma exp1rz n : 1 ^ n = 1 :> R. Proof. by case: (intP n)=> // m; rewrite -?exprz_inv ?invr1; apply: expr1n. Qed. Lemma exprSz x (n : nat) : x ^ n.+1 = x * x ^ n. Proof. exact: exprS. Qed. Lemma exprSzr x (n : nat) : x ^ n.+1 = x ^ n * x. Proof. exact: exprSr. Qed. Fact exprzD_nat x (m n : nat) : x ^ (m%:Z + n) = x ^ m * x ^ n. Proof. exact: exprD. Qed. Fact exprzD_Nnat x (m n : nat) : x ^ (-m%:Z + -n%:Z) = x ^ (-m%:Z) * x ^ (-n%:Z). Proof. by rewrite -opprD -!exprz_inv exprzD_nat. Qed. Lemma exprzD_ss x m n : (0 <= m) && (0 <= n) || (m <= 0) && (n <= 0) -> x ^ (m + n) = x ^ m * x ^ n. Proof. case: (intP m)=> {m} [|m|m]; case: (intP n)=> {n} [|n|n] //= _; by rewrite ?expr0z ?mul1r ?exprzD_nat ?exprzD_Nnat ?sub0r ?addr0 ?mulr1. Qed. Lemma exp0rz n : 0 ^ n = (n == 0)%:~R :> R. Proof. by case: (intP n)=> // m; rewrite -?exprz_inv ?invr0 exprSz mul0r. Qed. Lemma commrXz x y n : GRing.comm x y -> GRing.comm x (y ^ n). Proof. rewrite /GRing.comm; elim: n x y=> [|n ihn|n ihn] x y com_xy //=. * by rewrite expr0z mul1r mulr1. * by rewrite -exprnP commrX //. rewrite -exprz_inv -exprnP commrX //. case: (boolP (y \is a GRing.unit))=> uy; last by rewrite invr_out. by apply/eqP; rewrite (can2_eq (mulrVK _) (mulrK _)) // -mulrA com_xy mulKr. Qed. Lemma exprMz_comm x y n : x \is a GRing.unit -> y \is a GRing.unit -> GRing.comm x y -> (x * y) ^ n = x ^ n * y ^ n. Proof. move=> ux uy com_xy; elim: n => [|n _|n _]; first by rewrite expr0z mulr1. by rewrite -!exprnP exprMn_comm. rewrite -!exprnN -!exprVn com_xy -exprMn_comm ?invrM//. exact/commrV/commr_sym/commrV. Qed. Lemma commrXz_wmulls x y n : 0 <= n -> GRing.comm x y -> (x * y) ^ n = x ^ n * y ^ n. Proof. move=> n0 com_xy; elim: n n0 => [|n _|n _] //; first by rewrite expr0z mulr1. by rewrite -!exprnP exprMn_comm. Qed. Lemma unitrXz x n (ux : x \is a GRing.unit) : x ^ n \is a GRing.unit. Proof. case: (intP n)=> {n} [|n|n]; rewrite ?expr0z ?unitr1 ?unitrX //. by rewrite -invr_expz unitrV unitrX. Qed. Lemma exprzDr x (ux : x \is a GRing.unit) m n : x ^ (m + n) = x ^ m * x ^ n. Proof. move: n m; apply: wlog_le=> n m hnm. by rewrite addrC hnm commrXz //; exact/commr_sym/commrXz. case: (intP m) hnm=> {m} [|m|m]; rewrite ?mul1r ?add0r //; case: (intP n)=> {n} [|n|n _]; rewrite ?mulr1 ?addr0 //; do ?by rewrite exprzD_ss. rewrite -invr_expz subzSS !exprSzr invrM ?unitrX // -mulrA mulVKr //. case: (leqP n m)=> [|/ltnW] hmn; rewrite -{2}(subnK hmn) exprzD_nat -subzn //. by rewrite mulrK ?unitrX. by rewrite invrM ?unitrXz // mulVKr ?unitrXz // -opprB -invr_expz. Qed. Lemma exprz_exp x m n : (x ^ m) ^ n = (x ^ (m * n)). Proof. wlog: n / 0 <= n. by case: n=> [n -> //|n]; rewrite ?NegzE mulrN -?invr_expz=> -> /=. elim: n x m=> [|n ihn|n ihn] x m // _; first by rewrite mulr0 !expr0z. rewrite exprSz ihn // intS mulrDr mulr1 exprzD_ss //. by case: (intP m)=> // m'; rewrite ?oppr_le0 //. Qed. Lemma exprzAC x m n : (x ^ m) ^ n = (x ^ n) ^ m. Proof. by rewrite !exprz_exp mulrC. Qed. Lemma exprz_out x n (nux : x \isn't a GRing.unit) (hn : 0 <= n) : x ^ (- n) = x ^ n. Proof. by case: (intP n) hn=> //= m; rewrite -exprnN -exprVn invr_out. Qed. End ExprzUnitRing. Section Exprz_Zint_UnitRing. Variable R : unitRingType. Implicit Types x y : R. Implicit Types m n : int. Local Coercion Posz : nat >-> int. Lemma exprz_pMzl x m n : 0 <= n -> (x *~ m) ^ n = x ^ n *~ (m ^ n). Proof. by elim: n=> [|n ihn|n _] // _; rewrite !exprSz ihn // mulrzAr mulrzAl -mulrzA. Qed. Lemma exprz_pintl m n (hn : 0 <= n) : m%:~R ^ n = (m ^ n)%:~R :> R. Proof. by rewrite exprz_pMzl // exp1rz. Qed. Lemma exprzMzl x m n (ux : x \is a GRing.unit) (um : m%:~R \is a @GRing.unit R): (x *~ m) ^ n = (m%:~R ^ n) * x ^ n :> R. Proof. rewrite -[x *~ _]mulrzl exprMz_comm //; exact/commr_sym/commr_int. Qed. Lemma expNrz x n : (- x) ^ n = (-1) ^ n * x ^ n :> R. Proof. case: n=> [] n; rewrite ?NegzE; first exact: exprNn. by rewrite -!exprz_inv !invrN invr1; apply: exprNn. Qed. Lemma unitr_n0expz x n : n != 0 -> (x ^ n \is a GRing.unit) = (x \is a GRing.unit). Proof. by case: n => *; rewrite ?NegzE -?exprz_inv ?unitrX_pos ?unitrV ?lt0n. Qed. Lemma intrV (n : int) : n \in [:: 0; 1; -1] -> n%:~R ^-1 = n%:~R :> R. Proof. by case: (intP n)=> // [|[]|[]] //; rewrite ?rmorphN ?invrN (invr0, invr1). Qed. Lemma rmorphXz (R' : unitRingType) (f : {rmorphism R -> R'}) n : {in GRing.unit, {morph f : x / x ^ n}}. Proof. by case: n => n x Ux; rewrite ?rmorphV ?rpredX ?rmorphXn. Qed. End Exprz_Zint_UnitRing. Section ExprzIdomain. Variable R : idomainType. Implicit Types x y : R. Implicit Types m n : int. Local Coercion Posz : nat >-> int. Lemma expfz_eq0 x n : (x ^ n == 0) = (n != 0) && (x == 0). Proof. by case: n=> n; rewrite ?NegzE -?exprz_inv ?expf_eq0 ?lt0n ?invr_eq0. Qed. Lemma expfz_neq0 x n : x != 0 -> x ^ n != 0. Proof. by move=> x_nz; rewrite expfz_eq0; apply/nandP; right. Qed. Lemma exprzMl x y n (ux : x \is a GRing.unit) (uy : y \is a GRing.unit) : (x * y) ^ n = x ^ n * y ^ n. Proof. by rewrite exprMz_comm //; apply: mulrC. Qed. Lemma expfV (x : R) (i : int) : (x ^ i) ^-1 = (x ^-1) ^ i. Proof. by rewrite invr_expz exprz_inv. Qed. End ExprzIdomain. Section ExprzField. Variable F : fieldType. Implicit Types x y : F. Implicit Types m n : int. Local Coercion Posz : nat >-> int. Lemma expfzDr x m n : x != 0 -> x ^ (m + n) = x ^ m * x ^ n. Proof. by move=> hx; rewrite exprzDr ?unitfE. Qed. Lemma expfz_n0addr x m n : m + n != 0 -> x ^ (m + n) = x ^ m * x ^ n. Proof. have [-> hmn|nx0 _] := eqVneq x 0; last exact: expfzDr. rewrite !exp0rz (negPf hmn). case: (eqVneq m 0) hmn => [->|]; rewrite (mul0r, mul1r) //. by rewrite add0r=> /negPf->. Qed. Lemma expfzMl x y n : (x * y) ^ n = x ^ n * y ^ n. Proof. have [->|/negPf n0] := eqVneq n 0; first by rewrite !expr0z mulr1. case: (boolP ((x * y) == 0)); rewrite ?mulf_eq0. by case/pred2P=> ->; rewrite ?(mul0r, mulr0, exp0rz, n0). by case/norP=> x0 y0; rewrite exprzMl ?unitfE. Qed. Lemma fmorphXz (R : unitRingType) (f : {rmorphism F -> R}) n : {morph f : x / x ^ n}. Proof. by case: n => n x; rewrite ?fmorphV rmorphXn. Qed. End ExprzField. Section ExprzNumDomain. Variable R : numDomainType. Implicit Types x y : R. Implicit Types m n : int. Local Coercion Posz : nat >-> int. (* ler and exprz *) Lemma exprz_ge0 n x (hx : 0 <= x) : (0 <= x ^ n). Proof. by case: n => n; rewrite ?invr_ge0 ?exprn_ge0. Qed. Lemma exprz_gt0 n x (hx : 0 < x) : (0 < x ^ n). Proof. by case: n => n; rewrite ?invr_gt0 ?exprn_gt0. Qed. Definition exprz_gte0 := (exprz_ge0, exprz_gt0). Lemma ler_wpiXz2l x (x0 : 0 <= x) (x1 : x <= 1) : {in >= 0 &, {homo exprz x : x y /~ x <= y}}. Proof. move=> [] m [] n; rewrite -!topredE /= ?oppr_cp0 ?ltz_nat // => _ _. by rewrite lez_nat -?exprnP => /ler_wiXn2l; apply. Qed. Fact ler_wpeXz2l x (x1 : 1 <= x) : {in >= 0 &, {homo exprz x : x y / x <= y}}. Proof. move=> [] m [] n; rewrite -!topredE /= ?oppr_cp0 ?ltz_nat // => _ _. by rewrite lez_nat -?exprnP=> /ler_weXn2l; apply. Qed. Lemma pexprz_eq1 x n (x0 : 0 <= x) : (x ^ n == 1) = ((n == 0) || (x == 1)). Proof. case: n=> n; rewrite ?NegzE -?exprz_inv ?oppr_eq0 pexprn_eq1 // ?invr_eq1 //. by rewrite invr_ge0. Qed. Lemma ler_wpXz2r n (hn : 0 <= n) : {in >= 0 & , {homo (@exprz R)^~ n : x y / x <= y}}. Proof. by case: n hn=> // n _; exact: lerXn2r. Qed. End ExprzNumDomain. Section ExprzOrder. Variable R : realFieldType. Implicit Types x y : R. Implicit Types m n : int. Local Coercion Posz : nat >-> int. (* ler and exprz *) Lemma ler_wniXz2l x (x0 : 0 <= x) (x1 : x <= 1) : {in < 0 &, {homo exprz x : x y /~ x <= y}}. Proof. move=> [] m [] n; rewrite ?NegzE -!topredE /= ?oppr_cp0 ?ltz_nat // => _ _. rewrite lerN2 lez_nat -?invr_expz=> hmn; have := x0. rewrite le0r=> /predU1P [->|lx0]; first by rewrite !exp0rz invr0. by rewrite lef_pV2 -?topredE /= ?exprz_gt0 // ler_wiXn2l. Qed. Fact ler_wneXz2l x (x1 : 1 <= x) : {in <= 0 &, {homo exprz x : x y / x <= y}}. Proof. move=> m n hm hn /= hmn. rewrite -lef_pV2 -?topredE /= ?exprz_gt0 ?(lt_le_trans ltr01) //. by rewrite !invr_expz ler_wpeXz2l ?lerN2 -?topredE //= oppr_cp0. Qed. Lemma ler_weXz2l x (x1 : 1 <= x) : {homo exprz x : x y / x <= y}. Proof. move=> m n /= hmn; case: (lerP 0 m)=> [|/ltW] hm. by rewrite ler_wpeXz2l // [_ \in _](le_trans hm). case: (lerP n 0)=> [|/ltW] hn. by rewrite ler_wneXz2l // [_ \in _](le_trans hmn). apply: (@le_trans _ _ (x ^ 0)); first by rewrite ler_wneXz2l. by rewrite ler_wpeXz2l. Qed. Lemma ieexprIz x (x0 : 0 < x) (nx1 : x != 1) : injective (exprz x). Proof. apply: wlog_lt=> // m n hmn; first by move=> hmn'; rewrite hmn. move=> /(f_equal ( *%R^~ (x ^ (- n)))). rewrite -!expfzDr ?gt_eqF // subrr expr0z=> /eqP. by rewrite pexprz_eq1 ?(ltW x0) // (negPf nx1) subr_eq0 orbF=> /eqP. Qed. Lemma ler_piXz2l x (x0 : 0 < x) (x1 : x < 1) : {in >= 0 &, {mono exprz x : x y /~ x <= y}}. Proof. apply: (le_nmono_in (inj_nhomo_lt_in _ _)). by move=> n m hn hm /=; apply: ieexprIz; rewrite // lt_eqF. by apply: ler_wpiXz2l; rewrite ?ltW. Qed. Lemma ltr_piXz2l x (x0 : 0 < x) (x1 : x < 1) : {in >= 0 &, {mono exprz x : x y /~ x < y}}. Proof. exact: (leW_nmono_in (ler_piXz2l _ _)). Qed. Lemma ler_niXz2l x (x0 : 0 < x) (x1 : x < 1) : {in < 0 &, {mono exprz x : x y /~ x <= y}}. Proof. apply: (le_nmono_in (inj_nhomo_lt_in _ _)). by move=> n m hn hm /=; apply: ieexprIz; rewrite // lt_eqF. by apply: ler_wniXz2l; rewrite ?ltW. Qed. Lemma ltr_niXz2l x (x0 : 0 < x) (x1 : x < 1) : {in < 0 &, {mono (exprz x) : x y /~ x < y}}. Proof. exact: (leW_nmono_in (ler_niXz2l _ _)). Qed. Lemma ler_eXz2l x (x1 : 1 < x) : {mono exprz x : x y / x <= y}. Proof. apply: (le_mono (inj_homo_lt _ _)). by apply: ieexprIz; rewrite ?(lt_trans ltr01) // gt_eqF. by apply: ler_weXz2l; rewrite ?ltW. Qed. Lemma ltr_eXz2l x (x1 : 1 < x) : {mono exprz x : x y / x < y}. Proof. exact: (leW_mono (ler_eXz2l _)). Qed. Lemma ler_wnXz2r n (hn : n <= 0) : {in > 0 & , {homo (@exprz R)^~ n : x y /~ x <= y}}. Proof. move=> x y /= hx hy hxy; rewrite -lef_pV2 ?[_ \in _]exprz_gt0 //. by rewrite !invr_expz ler_wpXz2r ?[_ \in _]ltW // oppr_cp0. Qed. Lemma pexpIrz n (n0 : n != 0) : {in >= 0 &, injective ((@exprz R)^~ n)}. Proof. move=> x y; rewrite ![_ \in _]le0r=> /predU1P [-> _ /eqP|hx]. by rewrite exp0rz ?(negPf n0) eq_sym expfz_eq0=> /andP [_ /eqP->]. case/predU1P=> [-> /eqP|hy]. by rewrite exp0rz ?(negPf n0) expfz_eq0=> /andP [_ /eqP]. move=> /(f_equal ( *%R^~ (y ^ (- n)))) /eqP. rewrite -expfzDr ?(gt_eqF hy) // subrr expr0z -exprz_inv -expfzMl. rewrite pexprz_eq1 ?(negPf n0) /= ?mulr_ge0 ?invr_ge0 ?ltW //. by rewrite (can2_eq (mulrVK _) (mulrK _)) ?unitfE ?(gt_eqF hy) // mul1r=> /eqP. Qed. Lemma nexpIrz n (n0 : n != 0) : {in <= 0 &, injective ((@exprz R)^~ n)}. Proof. move=> x y; rewrite ![_ \in _]le_eqVlt => /predU1P [-> _ /eqP|hx]. by rewrite exp0rz ?(negPf n0) eq_sym expfz_eq0=> /andP [_ /eqP->]. case/predU1P=> [-> /eqP|hy]. by rewrite exp0rz ?(negPf n0) expfz_eq0=> /andP [_ /eqP]. move=> /(f_equal ( *%R^~ (y ^ (- n)))) /eqP. rewrite -expfzDr ?(lt_eqF hy) // subrr expr0z -exprz_inv -expfzMl. rewrite pexprz_eq1 ?(negPf n0) /= ?mulr_le0 ?invr_le0 ?ltW //. by rewrite (can2_eq (mulrVK _) (mulrK _)) ?unitfE ?(lt_eqF hy) // mul1r=> /eqP. Qed. Lemma ler_pXz2r n (hn : 0 < n) : {in >= 0 & , {mono ((@exprz R)^~ n) : x y / x <= y}}. Proof. apply: le_mono_in (inj_homo_lt_in _ _). by move=> x y hx hy /=; apply: pexpIrz; rewrite // gt_eqF. by apply: ler_wpXz2r; rewrite ltW. Qed. Lemma ltr_pXz2r n (hn : 0 < n) : {in >= 0 & , {mono ((@exprz R)^~ n) : x y / x < y}}. Proof. exact: leW_mono_in (ler_pXz2r _). Qed. Lemma ler_nXz2r n (hn : n < 0) : {in > 0 & , {mono ((@exprz R)^~ n) : x y /~ x <= y}}. Proof. apply: le_nmono_in (inj_nhomo_lt_in _ _); last first. by apply: ler_wnXz2r; rewrite ltW. by move=> x y hx hy /=; apply: pexpIrz; rewrite ?[_ \in _]ltW ?lt_eqF. Qed. Lemma ltr_nXz2r n (hn : n < 0) : {in > 0 & , {mono ((@exprz R)^~ n) : x y /~ x < y}}. Proof. exact: leW_nmono_in (ler_nXz2r _). Qed. Lemma eqrXz2 n x y : n != 0 -> 0 <= x -> 0 <= y -> (x ^ n == y ^ n) = (x == y). Proof. by move=> *; rewrite (inj_in_eq (pexpIrz _)). Qed. End ExprzOrder. Local Notation sgr := Num.sg. Section Sgz. Variable R : numDomainType. Implicit Types x y z : R. Implicit Types m n p : int. Local Coercion Posz : nat >-> int. Definition sgz x : int := if x == 0 then 0 else if x < 0 then -1 else 1. Lemma sgz_def x : sgz x = (-1) ^+ (x < 0)%R *+ (x != 0). Proof. by rewrite /sgz; case: (_ == _); case: (_ < _). Qed. Lemma sgrEz x : sgr x = (sgz x)%:~R. Proof. by rewrite !(fun_if intr). Qed. Lemma gtr0_sgz x : 0 < x -> sgz x = 1. Proof. by move=> x_gt0; rewrite /sgz lt_neqAle andbC eq_le lt_geF. Qed. Lemma ltr0_sgz x : x < 0 -> sgz x = -1. Proof. by move=> x_lt0; rewrite /sgz eq_sym eq_le x_lt0 lt_geF. Qed. Lemma sgz0 : sgz (0 : R) = 0. Proof. by rewrite /sgz eqxx. Qed. Lemma sgz1 : sgz (1 : R) = 1. Proof. by rewrite gtr0_sgz // ltr01. Qed. Lemma sgzN1 : sgz (-1 : R) = -1. Proof. by rewrite ltr0_sgz // ltrN10. Qed. Definition sgzE := (sgz0, sgz1, sgzN1). Lemma sgz_sgr x : sgz (sgr x) = sgz x. Proof. by rewrite !(fun_if sgz) !sgzE. Qed. Lemma normr_sgz x : `|sgz x| = (x != 0). Proof. by rewrite sgz_def -mulr_natr normrMsign normr_nat natz. Qed. Lemma normr_sg x : `|sgr x| = (x != 0)%:~R. Proof. by rewrite sgr_def -mulr_natr normrMsign normr_nat. Qed. End Sgz. Section MoreSgz. Variable R : numDomainType. Lemma sgz_int m : sgz (m%:~R : R) = sgz m. Proof. by rewrite /sgz intr_eq0 ltrz0. Qed. Lemma sgrz (n : int) : sgr n = sgz n. Proof. by rewrite sgrEz intz. Qed. Lemma intr_sg m : (sgr m)%:~R = sgr (m%:~R) :> R. Proof. by rewrite sgrz -sgz_int -sgrEz. Qed. Lemma sgz_id (x : R) : sgz (sgz x) = sgz x. Proof. by rewrite !(fun_if (@sgz _)). Qed. End MoreSgz. Section SgzReal. Variable R : realDomainType. Implicit Types x y z : R. Implicit Types m n p : int. Local Coercion Posz : nat >-> int. Lemma sgz_cp0 x : ((sgz x == 1) = (0 < x)) * ((sgz x == -1) = (x < 0)) * ((sgz x == 0) = (x == 0)). Proof. by rewrite /sgz; case: ltrgtP. Qed. Variant sgz_val x : bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> R -> R -> int -> Set := | SgzNull of x = 0 : sgz_val x true true true true false false true false false true false false true false false true false false 0 0 0 | SgzPos of x > 0 : sgz_val x false false true false false true false false true false false true false false true false false true x 1 1 | SgzNeg of x < 0 : sgz_val x false true false false true false false true false false true false false true false false true false (-x) (-1) (-1). Lemma sgzP x : sgz_val x (0 == x) (x <= 0) (0 <= x) (x == 0) (x < 0) (0 < x) (0 == sgr x) (-1 == sgr x) (1 == sgr x) (sgr x == 0) (sgr x == -1) (sgr x == 1) (0 == sgz x) (-1 == sgz x) (1 == sgz x) (sgz x == 0) (sgz x == -1) (sgz x == 1) `|x| (sgr x) (sgz x). Proof. rewrite ![_ == sgz _]eq_sym ![_ == sgr _]eq_sym !sgr_cp0 !sgz_cp0. by rewrite /sgz; case: sgrP; constructor. Qed. Lemma sgzN x : sgz (- x) = - sgz x. Proof. by rewrite /sgz oppr_eq0 oppr_lt0; case: ltrgtP. Qed. Lemma mulz_sg x : sgz x * sgz x = (x != 0)%:~R. Proof. by case: sgzP; rewrite ?(mulr0, mulr1, mulrNN). Qed. Lemma mulz_sg_eq1 x y : (sgz x * sgz y == 1) = (x != 0) && (sgz x == sgz y). Proof. do 2?case: sgzP=> _; rewrite ?(mulr0, mulr1, mulrN1, opprK, oppr0, eqxx); by rewrite ?[0 == 1]eq_sym ?oner_eq0 //= eqr_oppLR oppr0 oner_eq0. Qed. Lemma mulz_sg_eqN1 x y : (sgz x * sgz y == -1) = (x != 0) && (sgz x == - sgz y). Proof. by rewrite -eqr_oppLR -mulrN -sgzN mulz_sg_eq1. Qed. (* Lemma muls_eqA x y z : sgr x != 0 -> *) (* (sgr y * sgr z == sgr x) = ((sgr y * sgr x == sgr z) && (sgr z != 0)). *) (* Proof. by do 3!case: sgrP=> _. Qed. *) Lemma sgzM x y : sgz (x * y) = sgz x * sgz y. Proof. rewrite -sgz_sgr -(sgz_sgr x) -(sgz_sgr y) sgrM. by case: sgrP; case: sgrP; rewrite /sgz ?(mulNr, mul0r, mul1r); rewrite ?(oppr_eq0, oppr_cp0, eqxx, ltxx, ltr01, ltr10, oner_eq0). Qed. Lemma sgzX (n : nat) x : sgz (x ^+ n) = (sgz x) ^+ n. Proof. by elim: n => [|n IHn]; rewrite ?sgz1 // !exprS sgzM IHn. Qed. Lemma sgz_eq0 x : (sgz x == 0) = (x == 0). Proof. by rewrite sgz_cp0. Qed. Lemma sgz_odd (n : nat) x : x != 0 -> (sgz x) ^+ n = (sgz x) ^+ (odd n). Proof. by case: sgzP => //=; rewrite ?expr1n // signr_odd. Qed. Lemma sgz_gt0 x : (sgz x > 0) = (x > 0). Proof. by case: sgzP. Qed. Lemma sgz_lt0 x : (sgz x < 0) = (x < 0). Proof. by case: sgzP. Qed. Lemma sgz_ge0 x : (sgz x >= 0) = (x >= 0). Proof. by case: sgzP. Qed. Lemma sgz_le0 x : (sgz x <= 0) = (x <= 0). Proof. by case: sgzP. Qed. Lemma sgz_smul x y : sgz (y *~ (sgz x)) = (sgz x) * (sgz y). Proof. by rewrite -mulrzl sgzM -sgrEz sgz_sgr. Qed. Lemma sgrMz m x : sgr (x *~ m) = sgr x *~ sgr m. Proof. by rewrite -mulrzr sgrM -intr_sg mulrzr. Qed. End SgzReal. Lemma sgz_eq (R R' : realDomainType) (x : R) (y : R') : (sgz x == sgz y) = ((x == 0) == (y == 0)) && ((0 < x) == (0 < y)). Proof. by do 2!case: sgzP. Qed. Lemma intr_sign (R : pzRingType) s : ((-1) ^+ s)%:~R = (-1) ^+ s :> R. Proof. exact: rmorph_sign. Qed. Section Absz. Implicit Types m n p : int. Open Scope nat_scope. Local Coercion Posz : nat >-> int. Lemma absz_nat (n : nat) : `|n| = n. Proof. by []. Qed. Lemma abszE (m : int) : `|m| = `|m|%R :> int. Proof. by []. Qed. Lemma absz0 : `|0%R| = 0. Proof. by []. Qed. Lemma abszN m : `|- m| = `|m|. Proof. by case: (normrN m). Qed. Lemma absz_eq0 m : (`|m| == 0) = (m == 0%R). Proof. by case: (intP m). Qed. Lemma absz_gt0 m : (`|m| > 0) = (m != 0%R). Proof. by case: (intP m). Qed. Lemma absz1 : `|1%R| = 1. Proof. by []. Qed. Lemma abszN1 : `|-1%R| = 1. Proof. by []. Qed. Lemma absz_id m : `|(`|m|)| = `|m|. Proof. by []. Qed. Lemma abszM m1 m2 : `|(m1 * m2)%R| = `|m1| * `|m2|. Proof. by case: m1 m2 => [[|m1]|m1] [[|m2]|m2] //=; rewrite ?mulnS mulnC. Qed. Lemma abszX (n : nat) m : `|m ^+ n| = `|m| ^ n. Proof. by elim: n => // n ihn; rewrite exprS expnS abszM ihn. Qed. Lemma absz_sg m : `|sgr m| = (m != 0%R). Proof. by case: (intP m). Qed. Lemma gez0_abs m : (0 <= m)%R -> `|m| = m :> int. Proof. by case: (intP m). Qed. Lemma gtz0_abs m : (0 < m)%R -> `|m| = m :> int. Proof. by case: (intP m). Qed. Lemma lez0_abs m : (m <= 0)%R -> `|m| = - m :> int. Proof. by case: (intP m). Qed. Lemma ltz0_abs m : (m < 0)%R -> `|m| = - m :> int. Proof. by case: (intP m). Qed. Lemma lez_abs m : m <= `|m|%N :> int. Proof. by case: (intP m). Qed. Lemma absz_sign s : `|(-1) ^+ s| = 1. Proof. by rewrite abszX exp1n. Qed. Lemma abszMsign s m : `|((-1) ^+ s * m)%R| = `|m|. Proof. by rewrite abszM absz_sign mul1n. Qed. Lemma mulz_sign_abs m : ((-1) ^+ (m < 0)%R * `|m|%:Z)%R = m. Proof. by rewrite abszE mulr_sign_norm. Qed. Lemma mulz_Nsign_abs m : ((-1) ^+ (0 < m)%R * `|m|%:Z)%R = - m. Proof. by rewrite abszE mulr_Nsign_norm. Qed. Lemma intEsign m : m = ((-1) ^+ (m < 0)%R * `|m|%:Z)%R. Proof. exact: numEsign. Qed. Lemma abszEsign m : `|m|%:Z = ((-1) ^+ (m < 0)%R * m)%R. Proof. exact: normrEsign. Qed. Lemma intEsg m : m = (sgz m * `|m|%:Z)%R. Proof. by rewrite -sgrz -numEsg. Qed. Lemma abszEsg m : (`|m|%:Z = sgz m * m)%R. Proof. by rewrite -sgrz -normrEsg. Qed. End Absz. Section MoreAbsz. Variable R : numDomainType. Implicit Type i : int. Lemma mulr_absz (x : R) i : x *+ `|i| = x *~ `|i|. Proof. by rewrite -abszE. Qed. Lemma natr_absz i : `|i|%:R = `|i|%:~R :> R. Proof. by rewrite -abszE. Qed. End MoreAbsz. Module Export IntDist. (* This notation is supposed to work even if the ssrint library is not Imported. Since we can't rely on the CS database to contain the zmodule instance on int we put the instance by hand in the notation. *) Local Definition int_nmodType : nmodType := int. Local Definition int_zmodType : zmodType := int. Notation "m - n" := (@GRing.add int_nmodType (m%N : int) (@GRing.opp int_zmodType (n%N : int))) : distn_scope. Arguments absz m%_distn_scope. Notation "`| m |" := (absz m) : nat_scope. Coercion Posz : nat >-> int. Section Distn. Open Scope nat_scope. Implicit Type m : int. Implicit Types n d : nat. Lemma distnC m1 m2 : `|m1 - m2| = `|m2 - m1|. Proof. by rewrite -opprB abszN. Qed. Lemma distnDl d n1 n2 : `|d + n1 - (d + n2)| = `|n1 - n2|. Proof. by rewrite !PoszD opprD addrCA -addrA addKr. Qed. Lemma distnDr d n1 n2 : `|n1 + d - (n2 + d)| = `|n1 - n2|. Proof. by rewrite -!(addnC d) distnDl. Qed. Lemma distnEr n1 n2 : n1 <= n2 -> `|n1 - n2| = n2 - n1. Proof. by move/subnK=> {1}<-; rewrite distnC PoszD addrK absz_nat. Qed. Lemma distnEl n1 n2 : n2 <= n1 -> `|n1 - n2| = n1 - n2. Proof. by move/distnEr <-; rewrite distnC. Qed. Lemma distn0 n : `|n - 0| = n. Proof. by rewrite subr0 absz_nat. Qed. Lemma dist0n n : `|0 - n| = n. Proof. by rewrite distnC distn0. Qed. Lemma distnn m : `|m - m| = 0. Proof. by rewrite subrr. Qed. Lemma distn_eq0 n1 n2 : (`|n1 - n2| == 0) = (n1 == n2). Proof. by rewrite absz_eq0 subr_eq0. Qed. Lemma distnS n : `|n - n.+1| = 1. Proof. exact: distnDr n 0 1. Qed. Lemma distSn n : `|n.+1 - n| = 1. Proof. exact: distnDr n 1 0. Qed. Lemma distn_eq1 n1 n2 : (`|n1 - n2| == 1) = (if n1 < n2 then n1.+1 == n2 else n1 == n2.+1). Proof. case: ltnP => [lt_n12 | le_n21]. by rewrite eq_sym -(eqn_add2r n1) distnEr ?subnK // ltnW. by rewrite -(eqn_add2r n2) distnEl ?subnK. Qed. Lemma leqD_dist m1 m2 m3 : `|m1 - m3| <= `|m1 - m2| + `|m2 - m3|. Proof. by rewrite -lez_nat PoszD !abszE ler_distD. Qed. (* Most of this proof generalizes to all real-ordered rings. *) Lemma leqifD_distz m1 m2 m3 : `|m1 - m3| <= `|m1 - m2| + `|m2 - m3| ?= iff (m1 <= m2 <= m3)%R || (m3 <= m2 <= m1)%R. Proof. apply/leqifP; rewrite -ltz_nat -eqz_nat PoszD !abszE; apply/leifP. wlog le_m31 : m1 m3 / (m3 <= m1)%R. move=> IH; case/orP: (le_total m1 m3) => /IH //. by rewrite (addrC `|_|)%R orbC !(distrC m1) !(distrC m3). rewrite ger0_norm ?subr_ge0 // orb_idl => [|/andP[le_m12 le_m23]]; last first. by have /eqP->: m2 == m3; rewrite ?lexx // eq_le le_m23 (le_trans le_m31). rewrite -{1}(subrK m2 m1) -(addrA _ m2) -subr_ge0 andbC -[X in X && _]subr_ge0. by apply: leifD; apply/real_leif_norm/num_real. Qed. Lemma leqifD_dist n1 n2 n3 : `|n1 - n3| <= `|n1 - n2| + `|n2 - n3| ?= iff (n1 <= n2 <= n3) || (n3 <= n2 <= n1). Proof. exact: leqifD_distz. Qed. Lemma sqrn_dist n1 n2 : `|n1 - n2| ^ 2 + 2 * (n1 * n2) = n1 ^ 2 + n2 ^ 2. Proof. wlog le_n21: n1 n2 / n2 <= n1. move=> IH; case/orP: (leq_total n2 n1) => /IH //. by rewrite (addnC (n2 ^ 2)) (mulnC n2) distnC. by rewrite distnEl ?sqrnB ?subnK ?nat_Cauchy. Qed. End Distn. End IntDist. Section NormInt. Variable R : numDomainType. Lemma intr_norm m : `|m|%:~R = `|m%:~R : R|. Proof. by rewrite {2}[m]intEsign rmorphMsign normrMsign abszE normr_nat. Qed. Lemma normrMz m (x : R) : `|x *~ m| = `|x| *~ `|m|. Proof. by rewrite -mulrzl normrM -intr_norm mulrzl. Qed. Lemma expN1r (i : int) : (-1 : R) ^ i = (-1) ^+ `|i|. Proof. case: i => n; first by rewrite exprnP absz_nat. by rewrite NegzE abszN absz_nat -invr_expz expfV invrN1. Qed. End NormInt. Section PolyZintRing. Variable R : nzRingType. Implicit Types x y z: R. Implicit Types m n : int. Implicit Types i j k : nat. Implicit Types p q r : {poly R}. Lemma coefMrz p n i : (p *~ n)`_i = (p`_i *~ n). Proof. by case: n => n; rewrite ?NegzE (coefMNn, coefMn). Qed. Lemma polyCMz n : {morph (@polyC R) : c / c *~ n}. Proof. by case: (intP n) => // n' c; rewrite ?mulrNz ?polyCN polyCMn. Qed. Lemma hornerMz n p x : (p *~ n).[x] = p.[x] *~ n. Proof. by case: n => n; rewrite ?NegzE ?mulNzr ?(hornerN, hornerMn). Qed. Lemma horner_int n x : (n%:~R : {poly R}).[x] = n%:~R. Proof. by rewrite hornerMz hornerC. Qed. Lemma derivMz n p : (p *~ n)^`() = p^`() *~ n. Proof. by case: n => n; rewrite ?NegzE -?pmulrn (derivMn, derivMNn). Qed. Lemma mulpz p n : p *~ n = n%:~R *: p. Proof. by rewrite -mul_polyC polyCMz polyC1 mulrzl. Qed. End PolyZintRing. Section rpred. Lemma rpredMz (M : zmodType) (S : zmodClosed M) m : {in S, forall u, u *~ m \in S}. Proof. by case: m => n u Su; rewrite ?rpredN ?rpredMn. Qed. Lemma rpred_int (R : pzRingType) (S : subringClosed R) m : m%:~R \in S. Proof. by rewrite rpredMz ?rpred1. Qed. Lemma rpredZint (R : pzRingType) (M : lmodType R) (S : zmodClosed M) m : {in S, forall u, m%:~R *: u \in S}. Proof. by move=> u Su; rewrite /= scaler_int rpredMz. Qed. Lemma rpredXz (R : unitRingType) (S : divClosed R) m : {in S, forall x, x ^ m \in S}. Proof. by case: m => n x Sx; rewrite ?rpredV rpredX. Qed. Lemma rpredXsign (R : unitRingType) (S : divClosed R) n x : (x ^ ((-1) ^+ n) \in S) = (x \in S). Proof. by rewrite -signr_odd; case: (odd n); rewrite ?rpredV. Qed. End rpred.
ApproximatesLinearOn.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Sébastien Gouëzel -/ import Mathlib.Analysis.Normed.Operator.Banach import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace import Mathlib.Topology.PartialHomeomorph /-! # Non-linear maps close to affine maps In this file we study a map `f` such that `‖f x - f y - f' (x - y)‖ ≤ c * ‖x - y‖` on an open set `s`, where `f' : E →L[𝕜] F` is a continuous linear map and `c` is suitably small. Maps of this type behave like `f a + f' (x - a)` near each `a ∈ s`. When `f'` is onto, we show that `f` is locally onto. When `f'` is a continuous linear equiv, we show that `f` is a homeomorphism between `s` and `f '' s`. More precisely, we define `ApproximatesLinearOn.toPartialHomeomorph` to be a `PartialHomeomorph` with `toFun = f`, `source = s`, and `target = f '' s`. between `s` and `f '' s`. More precisely, we define `ApproximatesLinearOn.toPartialHomeomorph` to be a `PartialHomeomorph` with `toFun = f`, `source = s`, and `target = f '' s`. Maps of this type naturally appear in the proof of the inverse function theorem (see next section), and `ApproximatesLinearOn.toPartialHomeomorph` will imply that the locally inverse function and `ApproximatesLinearOn.toPartialHomeomorph` will imply that the locally inverse function exists. We define this auxiliary notion to split the proof of the inverse function theorem into small lemmas. This approach makes it possible - to prove a lower estimate on the size of the domain of the inverse function; - to reuse parts of the proofs in the case if a function is not strictly differentiable. E.g., for a function `f : E × F → G` with estimates on `f x y₁ - f x y₂` but not on `f x₁ y - f x₂ y`. ## Notations We introduce some `local notation` to make formulas shorter: * by `N` we denote `‖f'⁻¹‖`; * by `g` we denote the auxiliary contracting map `x ↦ x + f'.symm (y - f x)` used to prove that `{x | f x = y}` is nonempty. -/ open Function Set Filter Metric open scoped Topology NNReal noncomputable section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {ε : ℝ} open Filter Metric Set open ContinuousLinearMap (id) /-- We say that `f` approximates a continuous linear map `f'` on `s` with constant `c`, if `‖f x - f y - f' (x - y)‖ ≤ c * ‖x - y‖` whenever `x, y ∈ s`. This predicate is defined to facilitate the splitting of the inverse function theorem into small lemmas. Some of these lemmas can be useful, e.g., to prove that the inverse function is defined on a specific set. -/ def ApproximatesLinearOn (f : E → F) (f' : E →L[𝕜] F) (s : Set E) (c : ℝ≥0) : Prop := ∀ x ∈ s, ∀ y ∈ s, ‖f x - f y - f' (x - y)‖ ≤ c * ‖x - y‖ @[simp] theorem approximatesLinearOn_empty (f : E → F) (f' : E →L[𝕜] F) (c : ℝ≥0) : ApproximatesLinearOn f f' ∅ c := by simp [ApproximatesLinearOn] namespace ApproximatesLinearOn variable {f : E → F} /-! First we prove some properties of a function that `ApproximatesLinearOn` a (not necessarily invertible) continuous linear map. -/ section variable {f' : E →L[𝕜] F} {s t : Set E} {c c' : ℝ≥0} theorem mono_num (hc : c ≤ c') (hf : ApproximatesLinearOn f f' s c) : ApproximatesLinearOn f f' s c' := fun x hx y hy => le_trans (hf x hx y hy) (mul_le_mul_of_nonneg_right hc <| norm_nonneg _) theorem mono_set (hst : s ⊆ t) (hf : ApproximatesLinearOn f f' t c) : ApproximatesLinearOn f f' s c := fun x hx y hy => hf x (hst hx) y (hst hy) theorem approximatesLinearOn_iff_lipschitzOnWith {f : E → F} {f' : E →L[𝕜] F} {s : Set E} {c : ℝ≥0} : ApproximatesLinearOn f f' s c ↔ LipschitzOnWith c (f - ⇑f') s := by have : ∀ x y, f x - f y - f' (x - y) = (f - f') x - (f - f') y := fun x y ↦ by simp only [map_sub, Pi.sub_apply]; abel simp only [this, lipschitzOnWith_iff_norm_sub_le, ApproximatesLinearOn] alias ⟨lipschitzOnWith, _root_.LipschitzOnWith.approximatesLinearOn⟩ := approximatesLinearOn_iff_lipschitzOnWith theorem lipschitz_sub (hf : ApproximatesLinearOn f f' s c) : LipschitzWith c fun x : s => f x - f' x := hf.lipschitzOnWith.to_restrict protected theorem lipschitz (hf : ApproximatesLinearOn f f' s c) : LipschitzWith (‖f'‖₊ + c) (s.restrict f) := by simpa only [restrict_apply, add_sub_cancel] using (f'.lipschitz.restrict s).add hf.lipschitz_sub protected theorem continuous (hf : ApproximatesLinearOn f f' s c) : Continuous (s.restrict f) := hf.lipschitz.continuous protected theorem continuousOn (hf : ApproximatesLinearOn f f' s c) : ContinuousOn f s := continuousOn_iff_continuous_restrict.2 hf.continuous end section LocallyOnto /-! We prove that a function which is linearly approximated by a continuous linear map with a nonlinear right inverse is locally onto. This will apply to the case where the approximating map is a linear equivalence, for the local inverse theorem, but also whenever the approximating map is onto, by Banach's open mapping theorem. -/ variable [CompleteSpace E] {s : Set E} {c : ℝ≥0} {f' : E →L[𝕜] F} /-- If a function is linearly approximated by a continuous linear map with a (possibly nonlinear) right inverse, then it is locally onto: a ball of an explicit radius is included in the image of the map. -/ theorem surjOn_closedBall_of_nonlinearRightInverse (hf : ApproximatesLinearOn f f' s c) (f'symm : f'.NonlinearRightInverse) {ε : ℝ} {b : E} (ε0 : 0 ≤ ε) (hε : closedBall b ε ⊆ s) : SurjOn f (closedBall b ε) (closedBall (f b) (((f'symm.nnnorm : ℝ)⁻¹ - c) * ε)) := by intro y hy rcases le_or_gt (f'symm.nnnorm : ℝ)⁻¹ c with hc | hc · refine ⟨b, by simp [ε0], ?_⟩ have : dist y (f b) ≤ 0 := (mem_closedBall.1 hy).trans (mul_nonpos_of_nonpos_of_nonneg (by linarith) ε0) simp only [dist_le_zero] at this rw [this] have If' : (0 : ℝ) < f'symm.nnnorm := by rw [← inv_pos]; exact (NNReal.coe_nonneg _).trans_lt hc have Icf' : (c : ℝ) * f'symm.nnnorm < 1 := by rwa [inv_eq_one_div, lt_div_iff₀ If'] at hc have Jf' : (f'symm.nnnorm : ℝ) ≠ 0 := ne_of_gt If' have Jcf' : (1 : ℝ) - c * f'symm.nnnorm ≠ 0 := by apply ne_of_gt; linarith /- We have to show that `y` can be written as `f x` for some `x ∈ closedBall b ε`. The idea of the proof is to apply the Banach contraction principle to the map `g : x ↦ x + f'symm (y - f x)`, as a fixed point of this map satisfies `f x = y`. When `f'symm` is a genuine linear inverse, `g` is a contracting map. In our case, since `f'symm` is nonlinear, this map is not contracting (it is not even continuous), but still the proof of the contraction theorem holds: `uₙ = gⁿ b` is a Cauchy sequence, converging exponentially fast to the desired point `x`. Instead of appealing to general results, we check this by hand. The main point is that `f (u n)` becomes exponentially close to `y`, and therefore `dist (u (n+1)) (u n)` becomes exponentally small, making it possible to get an inductive bound on `dist (u n) b`, from which one checks that `u n` stays in the ball on which one has a control. Therefore, the bound can be checked at the next step, and so on inductively. -/ set g := fun x => x + f'symm (y - f x) with hg set u := fun n : ℕ => g^[n] b with hu have usucc : ∀ n, u (n + 1) = g (u n) := by simp [hu, ← iterate_succ_apply' g _ b] -- First bound: if `f z` is close to `y`, then `g z` is close to `z` (i.e., almost a fixed point). have A : ∀ z, dist (g z) z ≤ f'symm.nnnorm * dist (f z) y := by intro z rw [dist_eq_norm, hg, add_sub_cancel_left, dist_eq_norm'] exact f'symm.bound _ -- Second bound: if `z` and `g z` are in the set with good control, then `f (g z)` becomes closer -- to `y` than `f z` was (this uses the linear approximation property, and is the reason for the -- choice of the formula for `g`). have B : ∀ z ∈ closedBall b ε, g z ∈ closedBall b ε → dist (f (g z)) y ≤ c * f'symm.nnnorm * dist (f z) y := by intro z hz hgz set v := f'symm (y - f z) calc dist (f (g z)) y = ‖f (z + v) - y‖ := by rw [dist_eq_norm] _ = ‖f (z + v) - f z - f' v + f' v - (y - f z)‖ := by congr 1; abel _ = ‖f (z + v) - f z - f' (z + v - z)‖ := by simp only [v, ContinuousLinearMap.NonlinearRightInverse.right_inv, add_sub_cancel_left, sub_add_cancel] _ ≤ c * ‖z + v - z‖ := hf _ (hε hgz) _ (hε hz) _ ≤ c * (f'symm.nnnorm * dist (f z) y) := by gcongr simpa [dist_eq_norm'] using f'symm.bound (y - f z) _ = c * f'symm.nnnorm * dist (f z) y := by ring -- Third bound: a complicated bound on `dist w b` (that will show up in the induction) is enough -- to check that `w` is in the ball on which one has controls. Will be used to check that `u n` -- belongs to this ball for all `n`. have C : ∀ (n : ℕ) (w : E), dist w b ≤ f'symm.nnnorm * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n) / (1 - c * f'symm.nnnorm) * dist (f b) y → w ∈ closedBall b ε := fun n w hw ↦ by apply hw.trans rw [div_mul_eq_mul_div, div_le_iff₀]; swap; · linarith calc (f'symm.nnnorm : ℝ) * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n) * dist (f b) y = f'symm.nnnorm * dist (f b) y * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n) := by ring _ ≤ f'symm.nnnorm * dist (f b) y * 1 := by gcongr rw [sub_le_self_iff] positivity _ ≤ f'symm.nnnorm * (((f'symm.nnnorm : ℝ)⁻¹ - c) * ε) := by rw [mul_one] gcongr exact mem_closedBall'.1 hy _ = ε * (1 - c * f'symm.nnnorm) := by field_simp; ring /- Main inductive control: `f (u n)` becomes exponentially close to `y`, and therefore `dist (u (n+1)) (u n)` becomes exponentally small, making it possible to get an inductive bound on `dist (u n) b`, from which one checks that `u n` remains in the ball on which we have estimates. -/ have D : ∀ n : ℕ, dist (f (u n)) y ≤ ((c : ℝ) * f'symm.nnnorm) ^ n * dist (f b) y ∧ dist (u n) b ≤ f'symm.nnnorm * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n) / (1 - (c : ℝ) * f'symm.nnnorm) * dist (f b) y := fun n ↦ by induction' n with n IH; · simp [hu, le_refl] rw [usucc] have Ign : dist (g (u n)) b ≤ f'symm.nnnorm * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n.succ) / (1 - c * f'symm.nnnorm) * dist (f b) y := calc dist (g (u n)) b ≤ dist (g (u n)) (u n) + dist (u n) b := dist_triangle _ _ _ _ ≤ f'symm.nnnorm * dist (f (u n)) y + dist (u n) b := add_le_add (A _) le_rfl _ ≤ f'symm.nnnorm * (((c : ℝ) * f'symm.nnnorm) ^ n * dist (f b) y) + f'symm.nnnorm * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n) / (1 - c * f'symm.nnnorm) * dist (f b) y := by gcongr · exact IH.1 · exact IH.2 _ = f'symm.nnnorm * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n.succ) / (1 - (c : ℝ) * f'symm.nnnorm) * dist (f b) y := by field_simp [Jcf', pow_succ]; ring refine ⟨?_, Ign⟩ calc dist (f (g (u n))) y ≤ c * f'symm.nnnorm * dist (f (u n)) y := B _ (C n _ IH.2) (C n.succ _ Ign) _ ≤ (c : ℝ) * f'symm.nnnorm * (((c : ℝ) * f'symm.nnnorm) ^ n * dist (f b) y) := by gcongr apply IH.1 _ = ((c : ℝ) * f'symm.nnnorm) ^ n.succ * dist (f b) y := by simp only [pow_succ']; ring -- Deduce from the inductive bound that `uₙ` is a Cauchy sequence, therefore converging. have : CauchySeq u := by refine cauchySeq_of_le_geometric _ (↑f'symm.nnnorm * dist (f b) y) Icf' fun n ↦ ?_ calc dist (u n) (u (n + 1)) = dist (g (u n)) (u n) := by rw [usucc, dist_comm] _ ≤ f'symm.nnnorm * dist (f (u n)) y := A _ _ ≤ f'symm.nnnorm * (((c : ℝ) * f'symm.nnnorm) ^ n * dist (f b) y) := by gcongr exact (D n).1 _ = f'symm.nnnorm * dist (f b) y * ((c : ℝ) * f'symm.nnnorm) ^ n := by ring obtain ⟨x, hx⟩ : ∃ x, Tendsto u atTop (𝓝 x) := cauchySeq_tendsto_of_complete this -- As all the `uₙ` belong to the ball `closedBall b ε`, so does their limit `x`. have xmem : x ∈ closedBall b ε := isClosed_closedBall.mem_of_tendsto hx (Eventually.of_forall fun n => C n _ (D n).2) refine ⟨x, xmem, ?_⟩ -- It remains to check that `f x = y`. This follows from continuity of `f` on `closedBall b ε` -- and from the fact that `f uₙ` is converging to `y` by construction. have hx' : Tendsto u atTop (𝓝[closedBall b ε] x) := by simp only [nhdsWithin, tendsto_inf, hx, true_and, tendsto_principal] exact Eventually.of_forall fun n => C n _ (D n).2 have T1 : Tendsto (f ∘ u) atTop (𝓝 (f x)) := (hf.continuousOn.mono hε x xmem).tendsto.comp hx' have T2 : Tendsto (f ∘ u) atTop (𝓝 y) := by rw [tendsto_iff_dist_tendsto_zero] refine squeeze_zero (fun _ => dist_nonneg) (fun n => (D n).1) ?_ simpa using (tendsto_pow_atTop_nhds_zero_of_lt_one (by positivity) Icf').mul tendsto_const_nhds exact tendsto_nhds_unique T1 T2 theorem open_image (hf : ApproximatesLinearOn f f' s c) (f'symm : f'.NonlinearRightInverse) (hs : IsOpen s) (hc : Subsingleton F ∨ c < f'symm.nnnorm⁻¹) : IsOpen (f '' s) := by rcases hc with hE | hc · exact isOpen_discrete _ simp only [isOpen_iff_mem_nhds, nhds_basis_closedBall.mem_iff, forall_mem_image] at hs ⊢ intro x hx rcases hs x hx with ⟨ε, ε0, hε⟩ refine ⟨(f'symm.nnnorm⁻¹ - c) * ε, mul_pos (sub_pos.2 hc) ε0, ?_⟩ exact (hf.surjOn_closedBall_of_nonlinearRightInverse f'symm (le_of_lt ε0) hε).mono hε Subset.rfl theorem image_mem_nhds (hf : ApproximatesLinearOn f f' s c) (f'symm : f'.NonlinearRightInverse) {x : E} (hs : s ∈ 𝓝 x) (hc : Subsingleton F ∨ c < f'symm.nnnorm⁻¹) : f '' s ∈ 𝓝 (f x) := by obtain ⟨t, hts, ht, xt⟩ : ∃ t, t ⊆ s ∧ IsOpen t ∧ x ∈ t := _root_.mem_nhds_iff.1 hs have := IsOpen.mem_nhds ((hf.mono_set hts).open_image f'symm ht hc) (mem_image_of_mem _ xt) exact mem_of_superset this (image_mono hts) theorem map_nhds_eq (hf : ApproximatesLinearOn f f' s c) (f'symm : f'.NonlinearRightInverse) {x : E} (hs : s ∈ 𝓝 x) (hc : Subsingleton F ∨ c < f'symm.nnnorm⁻¹) : map f (𝓝 x) = 𝓝 (f x) := by refine le_antisymm ((hf.continuousOn x (mem_of_mem_nhds hs)).continuousAt hs) (le_map fun t ht => ?_) have : f '' (s ∩ t) ∈ 𝓝 (f x) := (hf.mono_set inter_subset_left).image_mem_nhds f'symm (inter_mem hs ht) hc exact mem_of_superset this (image_mono inter_subset_right) end LocallyOnto /-! From now on we assume that `f` approximates an invertible continuous linear map `f : E ≃L[𝕜] F`. We also assume that either `E = {0}`, or `c < ‖f'⁻¹‖⁻¹`. We use `N` as an abbreviation for `‖f'⁻¹‖`. -/ variable {f' : E ≃L[𝕜] F} {s : Set E} {c : ℝ≥0} local notation "N" => ‖(f'.symm : F →L[𝕜] E)‖₊ protected theorem antilipschitz (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E ∨ c < N⁻¹) : AntilipschitzWith (N⁻¹ - c)⁻¹ (s.restrict f) := by rcases hc with hE | hc · exact AntilipschitzWith.of_subsingleton convert (f'.antilipschitz.restrict s).add_lipschitzWith hf.lipschitz_sub hc simp [restrict] protected theorem injective (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E ∨ c < N⁻¹) : Injective (s.restrict f) := (hf.antilipschitz hc).injective protected theorem injOn (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E ∨ c < N⁻¹) : InjOn f s := injOn_iff_injective.2 <| hf.injective hc protected theorem surjective [CompleteSpace E] (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) univ c) (hc : Subsingleton E ∨ c < N⁻¹) : Surjective f := by rcases hc with hE | hc · haveI : Subsingleton F := (Equiv.subsingleton_congr f'.toEquiv).1 hE exact surjective_to_subsingleton _ · apply forall_of_forall_mem_closedBall (fun y : F => ∃ a, f a = y) (f 0) _ have hc' : (0 : ℝ) < N⁻¹ - c := by rw [sub_pos]; exact hc let p : ℝ → Prop := fun R => closedBall (f 0) R ⊆ Set.range f have hp : ∀ᶠ r : ℝ in atTop, p ((N⁻¹ - c) * r) := by have hr : ∀ᶠ r : ℝ in atTop, 0 ≤ r := eventually_ge_atTop 0 refine hr.mono fun r hr => Subset.trans ?_ (image_subset_range f (closedBall 0 r)) refine hf.surjOn_closedBall_of_nonlinearRightInverse f'.toNonlinearRightInverse hr ?_ exact subset_univ _ refine ((tendsto_id.const_mul_atTop hc').frequently hp.frequently).mono ?_ exact fun R h y hy => h hy /-- A map approximating a linear equivalence on a set defines a partial equivalence on this set. Should not be used outside of this file, because it is superseded by `toPartialHomeomorph` below. This is a first step towards the inverse function. -/ def toPartialEquiv (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E ∨ c < N⁻¹) : PartialEquiv E F := (hf.injOn hc).toPartialEquiv _ _ /-- The inverse function is continuous on `f '' s`. Use properties of `PartialHomeomorph` instead. -/ theorem inverse_continuousOn (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E ∨ c < N⁻¹) : ContinuousOn (hf.toPartialEquiv hc).symm (f '' s) := by apply continuousOn_iff_continuous_restrict.2 refine ((hf.antilipschitz hc).to_rightInvOn' ?_ (hf.toPartialEquiv hc).right_inv').continuous exact fun x hx => (hf.toPartialEquiv hc).map_target hx /-- The inverse function is approximated linearly on `f '' s` by `f'.symm`. -/ theorem to_inv (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E ∨ c < N⁻¹) : ApproximatesLinearOn (hf.toPartialEquiv hc).symm (f'.symm : F →L[𝕜] E) (f '' s) (N * (N⁻¹ - c)⁻¹ * c) := fun x hx y hy ↦ by set A := hf.toPartialEquiv hc have Af : ∀ z, A z = f z := fun z => rfl rcases (mem_image _ _ _).1 hx with ⟨x', x's, rfl⟩ rcases (mem_image _ _ _).1 hy with ⟨y', y's, rfl⟩ rw [← Af x', ← Af y', A.left_inv x's, A.left_inv y's] calc ‖x' - y' - f'.symm (A x' - A y')‖ ≤ N * ‖f' (x' - y' - f'.symm (A x' - A y'))‖ := (f' : E →L[𝕜] F).bound_of_antilipschitz f'.antilipschitz _ _ = N * ‖A y' - A x' - f' (y' - x')‖ := by congr 2 simp only [ContinuousLinearEquiv.apply_symm_apply, ContinuousLinearEquiv.map_sub] abel _ ≤ N * (c * ‖y' - x'‖) := mul_le_mul_of_nonneg_left (hf _ y's _ x's) (NNReal.coe_nonneg _) _ ≤ N * (c * (((N⁻¹ - c)⁻¹ : ℝ≥0) * ‖A y' - A x'‖)) := by gcongr rw [← dist_eq_norm, ← dist_eq_norm] exact (hf.antilipschitz hc).le_mul_dist ⟨y', y's⟩ ⟨x', x's⟩ _ = (N * (N⁻¹ - c)⁻¹ * c : ℝ≥0) * ‖A x' - A y'‖ := by simp only [norm_sub_rev, NNReal.coe_mul]; ring variable [CompleteSpace E] section variable (f s) /-- Given a function `f` that approximates a linear equivalence on an open set `s`, returns a partial homeomorphism with `toFun = f` and `source = s`. -/ def toPartialHomeomorph (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E ∨ c < N⁻¹) (hs : IsOpen s) : PartialHomeomorph E F where toPartialEquiv := hf.toPartialEquiv hc open_source := hs open_target := hf.open_image f'.toNonlinearRightInverse hs <| by rwa [f'.toEquiv.subsingleton_congr] at hc continuousOn_toFun := hf.continuousOn continuousOn_invFun := hf.inverse_continuousOn hc @[simp] theorem toPartialHomeomorph_coe (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E ∨ c < N⁻¹) (hs : IsOpen s) : (hf.toPartialHomeomorph f s hc hs : E → F) = f := rfl @[simp] theorem toPartialHomeomorph_source (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E ∨ c < N⁻¹) (hs : IsOpen s) : (hf.toPartialHomeomorph f s hc hs).source = s := rfl @[simp] theorem toPartialHomeomorph_target (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E ∨ c < N⁻¹) (hs : IsOpen s) : (hf.toPartialHomeomorph f s hc hs).target = f '' s := rfl /-- A function `f` that approximates a linear equivalence on the whole space is a homeomorphism. -/ def toHomeomorph (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) univ c) (hc : Subsingleton E ∨ c < N⁻¹) : E ≃ₜ F := by refine (hf.toPartialHomeomorph _ _ hc isOpen_univ).toHomeomorphOfSourceEqUnivTargetEqUniv rfl ?_ rw [toPartialHomeomorph_target, image_univ, range_eq_univ] exact hf.surjective hc end theorem closedBall_subset_target (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E ∨ c < N⁻¹) (hs : IsOpen s) {b : E} (ε0 : 0 ≤ ε) (hε : closedBall b ε ⊆ s) : closedBall (f b) ((N⁻¹ - c) * ε) ⊆ (hf.toPartialHomeomorph f s hc hs).target := (hf.surjOn_closedBall_of_nonlinearRightInverse f'.toNonlinearRightInverse ε0 hε).mono hε Subset.rfl end ApproximatesLinearOn
Finite.lean
/- Copyright (c) 2025 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.FinCategory.AsType /-! # Creation of finite limits This file defines the classes `CreatesFiniteLimits`, `CreatesFiniteColimits`, `CreatesFiniteProducts` and `CreatesFiniteCoproducts`. -/ namespace CategoryTheory.Limits universe w w' v₁ v₂ v₃ u₁ u₂ u₃ variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable {E : Type u₃} [Category.{v₃} E] /-- We say that a functor creates finite limits if it creates all limits of shape `J` where `J : Type` is a finite category. -/ class CreatesFiniteLimits (F : C ⥤ D) where /-- `F` creates all finite limits. -/ createsFiniteLimits : ∀ (J : Type) [SmallCategory J] [FinCategory J], CreatesLimitsOfShape J F := by infer_instance attribute [instance] CreatesFiniteLimits.createsFiniteLimits noncomputable section instance (priority := 100) createsLimitsOfShapeOfCreatesFiniteLimits (F : C ⥤ D) [CreatesFiniteLimits F] (J : Type w) [SmallCategory J] [FinCategory J] : CreatesLimitsOfShape J F := createsLimitsOfShapeOfEquiv (FinCategory.equivAsType J) _ -- Cannot be an instance because of unbound universe variables. /-- If `F` creates limits of any size, it creates finite limits. -/ def CreatesLimitsOfSize.createsFiniteLimits (F : C ⥤ D) [CreatesLimitsOfSize.{w, w'} F] : CreatesFiniteLimits F where createsFiniteLimits J _ _ := createsLimitsOfShapeOfEquiv ((ShrinkHoms.equivalence.{w} J).trans (Shrink.equivalence.{w'} _)).symm _ instance (priority := 120) CreatesLimitsOfSize0.createsFiniteLimits (F : C ⥤ D) [CreatesLimitsOfSize.{0, 0} F] : CreatesFiniteLimits F := CreatesLimitsOfSize.createsFiniteLimits F instance (priority := 100) CreatesLimits.createsFiniteLimits (F : C ⥤ D) [CreatesLimits F] : CreatesFiniteLimits F := CreatesLimitsOfSize.createsFiniteLimits F attribute [local instance] uliftCategory in /-- If `F` creates finite limits in any universe, then it creates finite limits. -/ def createsFiniteLimitsOfCreatesFiniteLimitsOfSize (F : C ⥤ D) (h : ∀ (J : Type w) {_ : SmallCategory J} (_ : FinCategory J), CreatesLimitsOfShape J F) : CreatesFiniteLimits F where createsFiniteLimits J _ _ := haveI := h (ULiftHom (ULift J)) CategoryTheory.finCategoryUlift createsLimitsOfShapeOfEquiv (ULiftHomULiftCategory.equiv J).symm _ instance compCreatesFiniteLimits (F : C ⥤ D) (G : D ⥤ E) [CreatesFiniteLimits F] [CreatesFiniteLimits G] : CreatesFiniteLimits (F ⋙ G) where createsFiniteLimits _ _ _ := compCreatesLimitsOfShape F G /-- Transfer creation of finite limits along a natural isomorphism in the functor. -/ def createsFiniteLimitsOfNatIso {F G : C ⥤ D} {h : F ≅ G} [CreatesFiniteLimits F] : CreatesFiniteLimits G where createsFiniteLimits _ _ _ := createsLimitsOfShapeOfNatIso h theorem hasFiniteLimits_of_hasLimitsLimits_of_createsFiniteLimits (F : C ⥤ D) [HasFiniteLimits D] [CreatesFiniteLimits F] : HasFiniteLimits C where out _ _ _ := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape F instance (priority := 100) preservesFiniteLimits_of_createsFiniteLimits_and_hasFiniteLimits (F : C ⥤ D) [CreatesFiniteLimits F] [HasFiniteLimits D] : PreservesFiniteLimits F where preservesFiniteLimits _ _ _ := inferInstance end /-- We say that a functor creates finite products if it creates all limits of shape `Discrete J` where `J : Type` is finite. -/ class CreatesFiniteProducts (F : C ⥤ D) where /-- `F` creates all finite limits. -/ creates : ∀ (J : Type) [Fintype J], CreatesLimitsOfShape (Discrete J) F := by infer_instance attribute [instance] CreatesFiniteProducts.creates noncomputable section instance (priority := 100) createsLimitsOfShapeOfCreatesFiniteProducts (F : C ⥤ D) [CreatesFiniteProducts F] (J : Type w) [Finite J] : CreatesLimitsOfShape (Discrete J) F := createsLimitsOfShapeOfEquiv (Discrete.equivalence (Finite.exists_equiv_fin J).choose_spec.some.symm) F instance compCreatesFiniteProducts (F : C ⥤ D) (G : D ⥤ E) [CreatesFiniteProducts F] [CreatesFiniteProducts G] : CreatesFiniteProducts (F ⋙ G) where creates _ _ := compCreatesLimitsOfShape _ _ /-- Transfer creation of finite products along a natural isomorphism in the functor. -/ def createsFiniteProductsOfNatIso {F G : C ⥤ D} {h : F ≅ G} [CreatesFiniteProducts F] : CreatesFiniteProducts G where creates _ _ := createsLimitsOfShapeOfNatIso h instance (F : C ⥤ D) [CreatesFiniteLimits F] : CreatesFiniteProducts F where creates _ _ := inferInstance end /-- We say that a functor creates finite colimits if it creates all colimits of shape `J` where `J : Type` is a finite category. -/ class CreatesFiniteColimits (F : C ⥤ D) where /-- `F` creates all finite colimits. -/ createsFiniteColimits : ∀ (J : Type) [SmallCategory J] [FinCategory J], CreatesColimitsOfShape J F := by infer_instance attribute [instance] CreatesFiniteColimits.createsFiniteColimits noncomputable section instance (priority := 100) createsColimitsOfShapeOfCreatesFiniteColimits (F : C ⥤ D) [CreatesFiniteColimits F] (J : Type w) [SmallCategory J] [FinCategory J] : CreatesColimitsOfShape J F := createsColimitsOfShapeOfEquiv (FinCategory.equivAsType J) _ -- Cannot be an instance because of unbound universe variables. /-- If `F` creates colimits of any size, it creates finite colimits. -/ def CreatesColimitsOfSize.createsFiniteColimits (F : C ⥤ D) [CreatesColimitsOfSize.{w, w'} F] : CreatesFiniteColimits F where createsFiniteColimits J _ _ := createsColimitsOfShapeOfEquiv ((ShrinkHoms.equivalence.{w} J).trans (Shrink.equivalence.{w'} _)).symm _ instance (priority := 120) CreatesColimitsOfSize0.createsFiniteColimits (F : C ⥤ D) [CreatesColimitsOfSize.{0, 0} F] : CreatesFiniteColimits F := CreatesColimitsOfSize.createsFiniteColimits F instance (priority := 100) CreatesColimits.createsFiniteColimits (F : C ⥤ D) [CreatesColimits F] : CreatesFiniteColimits F := CreatesColimitsOfSize.createsFiniteColimits F attribute [local instance] uliftCategory in /-- If `F` creates finite colimits in any universe, then it creates finite colimits. -/ def createsFiniteColimitsOfCreatesFiniteColimitsOfSize (F : C ⥤ D) (h : ∀ (J : Type w) {_ : SmallCategory J} (_ : FinCategory J), CreatesColimitsOfShape J F) : CreatesFiniteColimits F where createsFiniteColimits J _ _ := haveI := h (ULiftHom (ULift J)) CategoryTheory.finCategoryUlift createsColimitsOfShapeOfEquiv (ULiftHomULiftCategory.equiv J).symm _ instance compCreatesFiniteColimits (F : C ⥤ D) (G : D ⥤ E) [CreatesFiniteColimits F] [CreatesFiniteColimits G] : CreatesFiniteColimits (F ⋙ G) where createsFiniteColimits _ _ _ := compCreatesColimitsOfShape F G /-- Transfer creation of finite colimits along a natural isomorphism in the functor. -/ def createsFiniteColimitsOfNatIso {F G : C ⥤ D} {h : F ≅ G} [CreatesFiniteColimits F] : CreatesFiniteColimits G where createsFiniteColimits _ _ _ := createsColimitsOfShapeOfNatIso h theorem hasFiniteColimits_of_hasColimits_of_createsFiniteColimits (F : C ⥤ D) [HasFiniteColimits D] [CreatesFiniteColimits F] : HasFiniteColimits C where out _ _ _ := hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape F instance (priority := 100) preservesFiniteColimits_of_createsFiniteColimits_and_hasFiniteColimits (F : C ⥤ D) [CreatesFiniteColimits F] [HasFiniteColimits D] : PreservesFiniteColimits F where preservesFiniteColimits _ _ _ := inferInstance end /-- We say that a functor creates finite limits if it creates all limits of shape `J` where `J : Type` is a finite category. -/ class CreatesFiniteCoproducts (F : C ⥤ D) where /-- `F` creates all finite limits. -/ creates : ∀ (J : Type) [Fintype J], CreatesColimitsOfShape (Discrete J) F := by infer_instance attribute [instance] CreatesFiniteCoproducts.creates noncomputable section instance (priority := 100) createsColimitsOfShapeOfCreatesFiniteProducts (F : C ⥤ D) [CreatesFiniteCoproducts F] (J : Type w) [Finite J] : CreatesColimitsOfShape (Discrete J) F := createsColimitsOfShapeOfEquiv (Discrete.equivalence (Finite.exists_equiv_fin J).choose_spec.some.symm) F instance compCreatesFiniteCoproducts (F : C ⥤ D) (G : D ⥤ E) [CreatesFiniteCoproducts F] [CreatesFiniteCoproducts G] : CreatesFiniteCoproducts (F ⋙ G) where creates _ _ := compCreatesColimitsOfShape _ _ /-- Transfer creation of finite limits along a natural isomorphism in the functor. -/ def createsFiniteCoproductsOfNatIso {F G : C ⥤ D} {h : F ≅ G} [CreatesFiniteCoproducts F] : CreatesFiniteCoproducts G where creates _ _ := createsColimitsOfShapeOfNatIso h instance (F : C ⥤ D) [CreatesFiniteColimits F] : CreatesFiniteCoproducts F where creates _ _ := inferInstance end end CategoryTheory.Limits
FiniteMeasureProd.lean
/- Copyright (c) 2023 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.MeasureTheory.Measure.LevyProkhorovMetric import Mathlib.MeasureTheory.Measure.Prod /-! # Products of finite measures and probability measures This file introduces binary products of finite measures and probability measures. The constructions are obtained from special cases of products of general measures. Taking products nevertheless has specific properties in the cases of finite measures and probability measures, notably the fact that the product measures depend continuously on their factors in the topology of weak convergence when the underlying space is metrizable and separable. ## Main definitions * `MeasureTheory.FiniteMeasure.prod`: The product of two finite measures. * `MeasureTheory.ProbabilityMeasure.prod`: The product of two probability measures. ## Main results `MeasureTheory.ProbabilityMeasure.continuous_prod`: the product probability measure depends continuously on the factors. -/ open MeasureTheory Topology Metric Filter Set ENNReal NNReal open scoped Topology ENNReal NNReal BoundedContinuousFunction namespace MeasureTheory section FiniteMeasure_product namespace FiniteMeasure variable {α : Type*} [MeasurableSpace α] {β : Type*} [MeasurableSpace β] /-- The binary product of finite measures. -/ noncomputable def prod (μ : FiniteMeasure α) (ν : FiniteMeasure β) : FiniteMeasure (α × β) := ⟨μ.toMeasure.prod ν.toMeasure, inferInstance⟩ variable (μ : FiniteMeasure α) (ν : FiniteMeasure β) @[simp] lemma toMeasure_prod : (μ.prod ν).toMeasure = μ.toMeasure.prod ν.toMeasure := rfl lemma prod_apply (s : Set (α × β)) (s_mble : MeasurableSet s) : μ.prod ν s = ENNReal.toNNReal (∫⁻ x, ν.toMeasure (Prod.mk x ⁻¹' s) ∂μ) := by simp [coeFn_def, Measure.prod_apply s_mble] lemma prod_apply_symm (s : Set (α × β)) (s_mble : MeasurableSet s) : μ.prod ν s = ENNReal.toNNReal (∫⁻ y, μ.toMeasure ((fun x ↦ ⟨x, y⟩) ⁻¹' s) ∂ν) := by simp [coeFn_def, Measure.prod_apply_symm s_mble] @[simp] lemma prod_prod (s : Set α) (t : Set β) : μ.prod ν (s ×ˢ t) = μ s * ν t := by simp [coeFn_def] @[simp] lemma mass_prod : (μ.prod ν).mass = μ.mass * ν.mass := by simp only [coeFn_def, mass, univ_prod_univ.symm, toMeasure_prod] rw [← ENNReal.toNNReal_mul] exact congr_arg ENNReal.toNNReal (Measure.prod_prod univ univ) @[simp] lemma zero_prod : (0 : FiniteMeasure α).prod ν = 0 := by rw [← mass_zero_iff, mass_prod, zero_mass, zero_mul] @[simp] lemma prod_zero : μ.prod (0 : FiniteMeasure β) = 0 := by rw [← mass_zero_iff, mass_prod, zero_mass, mul_zero] @[simp] lemma map_fst_prod : (μ.prod ν).map Prod.fst = ν univ • μ := by ext; simp @[simp] lemma map_snd_prod : (μ.prod ν).map Prod.snd = μ univ • ν := by ext; simp lemma map_prod_map {α' : Type*} [MeasurableSpace α'] {β' : Type*} [MeasurableSpace β'] {f : α → α'} {g : β → β'} (f_mble : Measurable f) (g_mble : Measurable g) : (μ.map f).prod (ν.map g) = (μ.prod ν).map (Prod.map f g) := by apply Subtype.ext simp only [val_eq_toMeasure, toMeasure_prod, toMeasure_map] rw [Measure.map_prod_map _ _ f_mble g_mble] lemma prod_swap : (μ.prod ν).map Prod.swap = ν.prod μ := by apply Subtype.ext simp [Measure.prod_swap] end FiniteMeasure -- namespace end FiniteMeasure_product -- section section ProbabilityMeasure_product namespace ProbabilityMeasure variable {α : Type*} [MeasurableSpace α] {β : Type*} [MeasurableSpace β] /-- The binary product of probability measures. -/ noncomputable def prod (μ : ProbabilityMeasure α) (ν : ProbabilityMeasure β) : ProbabilityMeasure (α × β) := ⟨μ.toMeasure.prod ν.toMeasure, by infer_instance⟩ variable (μ : ProbabilityMeasure α) (ν : ProbabilityMeasure β) @[simp] lemma toMeasure_prod : (μ.prod ν).toMeasure = μ.toMeasure.prod ν.toMeasure := rfl lemma prod_apply (s : Set (α × β)) (s_mble : MeasurableSet s) : μ.prod ν s = ENNReal.toNNReal (∫⁻ x, ν.toMeasure (Prod.mk x ⁻¹' s) ∂μ) := by simp [coeFn_def, Measure.prod_apply s_mble] lemma prod_apply_symm (s : Set (α × β)) (s_mble : MeasurableSet s) : μ.prod ν s = ENNReal.toNNReal (∫⁻ y, μ.toMeasure ((fun x ↦ ⟨x, y⟩) ⁻¹' s) ∂ν) := by simp [coeFn_def, Measure.prod_apply_symm s_mble] @[simp] lemma prod_prod (s : Set α) (t : Set β) : μ.prod ν (s ×ˢ t) = μ s * ν t := by simp [coeFn_def] /-- The first marginal of a product probability measure is the first probability measure. -/ @[simp] lemma map_fst_prod : (μ.prod ν).map measurable_fst.aemeasurable = μ := by apply Subtype.ext simp only [val_eq_to_measure, toMeasure_map, toMeasure_prod, Measure.map_fst_prod, measure_univ, one_smul] /-- The second marginal of a product probability measure is the second probability measure. -/ @[simp] lemma map_snd_prod : (μ.prod ν).map measurable_snd.aemeasurable = ν := by apply Subtype.ext simp only [val_eq_to_measure, toMeasure_map, toMeasure_prod, Measure.map_snd_prod, measure_univ, one_smul] lemma map_prod_map {α' : Type*} [MeasurableSpace α'] {β' : Type*} [MeasurableSpace β'] {f : α → α'} {g : β → β'} (f_mble : Measurable f) (g_mble : Measurable g) : (μ.map f_mble.aemeasurable).prod (ν.map g_mble.aemeasurable) = (μ.prod ν).map (f_mble.prodMap g_mble).aemeasurable := by apply Subtype.ext simp only [val_eq_to_measure, toMeasure_prod, toMeasure_map] rw [Measure.map_prod_map _ _ f_mble g_mble] lemma prod_swap : (μ.prod ν).map measurable_swap.aemeasurable = ν.prod μ := by apply Subtype.ext simp [Measure.prod_swap] open TopologicalSpace /-- The map associating to two probability measures their product is a continuous map. -/ @[fun_prop] theorem continuous_prod [TopologicalSpace α] [TopologicalSpace β] [SecondCountableTopology α] [SecondCountableTopology β] [PseudoMetrizableSpace α] [PseudoMetrizableSpace β] [OpensMeasurableSpace α] [OpensMeasurableSpace β] : Continuous (fun (μ : ProbabilityMeasure α × ProbabilityMeasure β) ↦ μ.1.prod μ.2) := by refine continuous_iff_continuousAt.2 (fun μ ↦ ?_) /- It suffices to check the convergence along elements of a π-system containing arbitrarily small neighborhoods of any point, by `tendsto_probabilityMeasure_of_tendsto_of_mem`. We take as a π-system the sets of the form `a ×ˢ b` where `a` and `b` have null frontier. -/ let S : Set (Set (α × β)) := {t | ∃ (a : Set α) (b : Set β), MeasurableSet a ∧ μ.1 (frontier a) = 0 ∧ MeasurableSet b ∧ μ.2 (frontier b) = 0 ∧ t = a ×ˢ b} have : IsPiSystem S := by rintro - ⟨a, b, ameas, ha, bmeas, hb, rfl⟩ - ⟨a', b', a'meas, ha', b'meas, hb', rfl⟩ - refine ⟨a ∩ a', b ∩ b', ameas.inter a'meas, ?_, bmeas.inter b'meas, ?_, prod_inter_prod⟩ · rw [null_iff_toMeasure_null] at ha ha' ⊢ exact null_frontier_inter ha ha' · rw [null_iff_toMeasure_null] at hb hb' ⊢ exact null_frontier_inter hb hb' apply this.tendsto_probabilityMeasure_of_tendsto_of_mem · rintro s ⟨a, b, ameas, -, bmeas, -, rfl⟩ exact ameas.prod bmeas · letI : PseudoMetricSpace α := TopologicalSpace.pseudoMetrizableSpacePseudoMetric α letI : PseudoMetricSpace β := TopologicalSpace.pseudoMetrizableSpacePseudoMetric β intro u u_open x xu obtain ⟨ε, εpos, hε⟩ : ∃ ε > 0, ball x ε ⊆ u := Metric.isOpen_iff.1 u_open x xu rcases exists_null_frontier_thickening (μ.1 : Measure α) {x.1} εpos with ⟨r, hr, μr⟩ rcases exists_null_frontier_thickening (μ.2 : Measure β) {x.2} εpos with ⟨r', hr', μr'⟩ simp only [thickening_singleton] at μr μr' refine ⟨ball x.1 r ×ˢ ball x.2 r', ⟨ball x.1 r, ball x.2 r', measurableSet_ball, by simp [coeFn_def, μr], measurableSet_ball, by simp [coeFn_def, μr'], rfl⟩, ?_, ?_⟩ · exact (isOpen_ball.prod isOpen_ball).mem_nhds (by simp [hr.1, hr'.1]) · calc ball x.1 r ×ˢ ball x.2 r' _ ⊆ ball x.1 ε ×ˢ ball x.2 ε := by gcongr; exacts [hr.2.le, hr'.2.le] _ ⊆ _ := by rwa [ball_prod_same] · rintro s ⟨a, b, ameas, ha, bmeas, hb, rfl⟩ simp only [prod_prod] apply Filter.Tendsto.mul · exact tendsto_measure_of_null_frontier_of_tendsto tendsto_id.fst_nhds ha · exact tendsto_measure_of_null_frontier_of_tendsto tendsto_id.snd_nhds hb end ProbabilityMeasure -- namespace end ProbabilityMeasure_product -- section end MeasureTheory -- namespace
MultiequalizerPullback.lean
/- Copyright (c) 2025 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.Limits.Shapes.Multiequalizer import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq /-! # Multicoequalizers that are pushouts In this file, we show that a multicoequalizer for `I : MultispanIndex (.ofLinearOrder ι) C` is also a pushout when `ι` has exactly two elements. -/ namespace CategoryTheory.Limits.Multicofork.IsColimit variable {C : Type*} [Category C] {J : MultispanShape} [Unique J.L] {I : MultispanIndex J C} (c : Multicofork I) (h : {J.fst default, J.snd default} = Set.univ) (h' : J.fst default ≠ J.snd default) namespace isPushout variable (s : PushoutCocone (I.fst default) (I.snd default)) open Classical in /-- Given a multispan shape `J` which is essentially `.ofLinearOrder ι` (where `ι` has exactly two elements), this is the multicofork deduced from a pushout cocone. -/ noncomputable def multicofork : Multicofork I := Multicofork.ofπ _ s.pt (fun k ↦ if hk : k = J.fst default then eqToHom (by simp [hk]) ≫ s.inl else eqToHom (by obtain rfl : k = J.snd default := by have := h.symm.le (Set.mem_univ k) simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at this tauto rfl) ≫ s.inr) (by rw [Unique.forall_iff] simpa [h'.symm] using s.condition) @[simp] lemma multicofork_π_eq_inl : (multicofork h h' s).π (J.fst default) = s.inl := by dsimp only [multicofork, ofπ, π] rw [dif_pos rfl, eqToHom_refl, Category.id_comp] @[simp] lemma multicofork_π_eq_inr : (multicofork h h' s).π (J.snd default) = s.inr := by dsimp only [multicofork, ofπ, π] rw [dif_neg h'.symm, eqToHom_refl, Category.id_comp] end isPushout include h h' in /-- A multicoequalizer for `I : MultispanIndex J C` is also a pushout when `J` is essentially `.ofLinearOrder ι` where `ι` contains exactly two elements. -/ lemma isPushout (hc : IsColimit c) : IsPushout (I.fst default) (I.snd default) (c.π (J.fst default)) (c.π (J.snd default)) where w := c.condition _ isColimit' := ⟨PushoutCocone.IsColimit.mk _ (fun s ↦ hc.desc (isPushout.multicofork h h' s)) (fun s ↦ by simpa using hc.fac (isPushout.multicofork h h' s) (.right (J.fst default))) (fun s ↦ by simpa using hc.fac (isPushout.multicofork h h' s) (.right (J.snd default))) (fun s m h₁ h₂ ↦ by apply Multicofork.IsColimit.hom_ext hc intro k have := h.symm.le (Set.mem_univ k) simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at this obtain rfl | rfl := this · simpa [h₁] using (hc.fac (isPushout.multicofork h h' s) (.right (J.fst default))).symm · simpa [h₂] using (hc.fac (isPushout.multicofork h h' s) (.right (J.snd default))).symm)⟩ end CategoryTheory.Limits.Multicofork.IsColimit
FiniteDimensional.lean
/- Copyright (c) 2025 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Topology.Algebra.SeparationQuotient.Basic import Mathlib.RingTheory.Finiteness.Basic /-! # Separation quotient is a finite module In this file we show that the separation quotient of a finite module is a finite module. -/ /-- The separation quotient of a finite module is a finite module. -/ instance SeparationQuotient.instModuleFinite {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] [Module.Finite R M] [TopologicalSpace M] [ContinuousAdd M] [ContinuousConstSMul R M] : Module.Finite R (SeparationQuotient M) := Module.Finite.of_surjective (mkCLM R M).toLinearMap Quotient.mk_surjective
PrimeCounting.lean
/- Copyright (c) 2021 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Ralf Stephan -/ import Mathlib.Data.Nat.Prime.Nth import Mathlib.Data.Nat.Totient import Mathlib.NumberTheory.SmoothNumbers import Mathlib.Order.Filter.AtTopBot.Basic /-! # The Prime Counting Function In this file we define the prime counting function: the function on natural numbers that returns the number of primes less than or equal to its input. ## Main Results The main definitions for this file are - `Nat.primeCounting`: The prime counting function π - `Nat.primeCounting'`: π(n - 1) We then prove that these are monotone in `Nat.monotone_primeCounting` and `Nat.monotone_primeCounting'`. The last main theorem `Nat.primeCounting'_add_le` is an upper bound on `π'` which arises by observing that all numbers greater than `k` and not coprime to `k` are not prime, and so only at most `φ(k)/k` fraction of the numbers from `k` to `n` are prime. ## Notation With `open scoped Nat.Prime`, we use the standard notation `π` to represent the prime counting function (and `π'` to represent the reindexed version). -/ namespace Nat open Finset /-- A variant of the traditional prime counting function which gives the number of primes *strictly* less than the input. More convenient for avoiding off-by-one errors. With `open scoped Nat.Prime`, this has notation `π'`. -/ def primeCounting' : ℕ → ℕ := Nat.count Prime /-- The prime counting function: Returns the number of primes less than or equal to the input. With `open scoped Nat.Prime`, this has notation `π`. -/ def primeCounting (n : ℕ) : ℕ := primeCounting' (n + 1) @[inherit_doc] scoped[Nat.Prime] notation "π" => Nat.primeCounting @[inherit_doc] scoped[Nat.Prime] notation "π'" => Nat.primeCounting' open scoped Nat.Prime @[simp] theorem primeCounting_sub_one (n : ℕ) : π (n - 1) = π' n := by cases n <;> rfl theorem monotone_primeCounting' : Monotone primeCounting' := count_monotone Prime theorem monotone_primeCounting : Monotone primeCounting := monotone_primeCounting'.comp (monotone_id.add_const _) @[simp] theorem primeCounting'_nth_eq (n : ℕ) : π' (nth Prime n) = n := count_nth_of_infinite infinite_setOf_prime _ /-- The `n`th prime is greater or equal to `n + 2`. -/ theorem add_two_le_nth_prime (n : ℕ) : n + 2 ≤ nth Prime n := nth_prime_zero_eq_two ▸ (nth_strictMono infinite_setOf_prime).add_le_nat n 0 theorem surjective_primeCounting' : Function.Surjective π' := Nat.surjective_count_of_infinite_setOf infinite_setOf_prime theorem surjective_primeCounting : Function.Surjective π := by suffices Function.Surjective (π ∘ fun n => n - 1) from this.of_comp convert surjective_primeCounting' ext exact primeCounting_sub_one _ open Filter theorem tendsto_primeCounting' : Tendsto π' atTop atTop := by apply tendsto_atTop_atTop_of_monotone' monotone_primeCounting' simp [Set.range_eq_univ.mpr surjective_primeCounting'] theorem tendsto_primeCounting : Tendsto π atTop atTop := (tendsto_add_atTop_iff_nat 1).mpr tendsto_primeCounting' @[deprecated (since := "2025-07-08")] alias tensto_primeCounting := tendsto_primeCounting @[simp] theorem prime_nth_prime (n : ℕ) : Prime (nth Prime n) := nth_mem_of_infinite infinite_setOf_prime _ @[simp] lemma primeCounting'_eq_zero_iff {n : ℕ} : n.primeCounting' = 0 ↔ n ≤ 2 := by rw [primeCounting', Nat.count_eq_zero ⟨_, Nat.prime_two⟩, Nat.nth_prime_zero_eq_two] @[simp] lemma primeCounting_eq_zero_iff {n : ℕ} : n.primeCounting = 0 ↔ n ≤ 1 := by simp [primeCounting] @[simp] lemma primeCounting_zero : primeCounting 0 = 0 := primeCounting_eq_zero_iff.mpr zero_le_one @[simp] lemma primeCounting_one : primeCounting 1 = 0 := primeCounting_eq_zero_iff.mpr le_rfl /-- The cardinality of the finset `primesBelow n` equals the counting function `primeCounting'` at `n`. -/ theorem primesBelow_card_eq_primeCounting' (n : ℕ) : #n.primesBelow = primeCounting' n := by simp only [primesBelow, primeCounting'] exact (count_eq_card_filter_range Prime n).symm /-- A linear upper bound on the size of the `primeCounting'` function -/ theorem primeCounting'_add_le {a k : ℕ} (h0 : 0 < a) (h1 : a < k) (n : ℕ) : π' (k + n) ≤ π' k + Nat.totient a * (n / a + 1) := calc π' (k + n) ≤ #{p ∈ range k | p.Prime} + #{p ∈ Ico k (k + n) | p.Prime} := by rw [primeCounting', count_eq_card_filter_range, range_eq_Ico, ← Ico_union_Ico_eq_Ico (zero_le k) le_self_add, filter_union] apply card_union_le _ ≤ π' k + #{p ∈ Ico k (k + n) | p.Prime} := by rw [primeCounting', count_eq_card_filter_range] _ ≤ π' k + #{b ∈ Ico k (k + n) | a.Coprime b} := by refine add_le_add_left (card_le_card ?_) k.primeCounting' simp only [subset_iff, and_imp, mem_filter, mem_Ico] intro p succ_k_le_p p_lt_n p_prime constructor · exact ⟨succ_k_le_p, p_lt_n⟩ · rw [coprime_comm] exact coprime_of_lt_prime h0 (lt_of_lt_of_le h1 succ_k_le_p) p_prime _ ≤ π' k + totient a * (n / a + 1) := by rw [add_le_add_iff_left] exact Ico_filter_coprime_le k n h0 end Nat
ReduceModChar.lean
/- Copyright (c) 2023 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Data.ZMod.Basic import Mathlib.RingTheory.Polynomial.Basic import Mathlib.Tactic.NormNum.DivMod import Mathlib.Tactic.NormNum.PowMod import Mathlib.Tactic.ReduceModChar.Ext /-! # `reduce_mod_char` tactic Define the `reduce_mod_char` tactic, which traverses expressions looking for numerals `n`, such that the type of `n` is a ring of (positive) characteristic `p`, and reduces these numerals modulo `p`, to lie between `0` and `p`. ## Implementation The main entry point is `ReduceModChar.derive`, which uses `simp` to traverse expressions and calls `matchAndNorm` on each subexpression. The type of each subexpression is matched syntactically to determine if it is a ring with positive characteristic in `typeToCharP`. Using syntactic matching should be faster than trying to infer a `CharP` instance on each subexpression. The actual reduction happens in `normIntNumeral`. This is written to be compatible with `norm_num` so it can serve as a drop-in replacement for some `norm_num`-based routines (specifically, the intended use is as an option for the `ring` tactic). In addition to the main functionality, we call `normNeg` and `normNegCoeffMul` to replace negation with multiplication by `p - 1`, and simp lemmas tagged `@[reduce_mod_char]` to clean up the resulting expression: e.g. `1 * X + 0` becomes `X`. -/ open Lean Meta Simp open Lean.Elab open Tactic open Qq namespace Tactic namespace ReduceModChar open Mathlib.Meta.NormNum variable {u : Level} lemma CharP.isInt_of_mod {e' r : ℤ} {α : Type*} [Ring α] {n n' : ℕ} (inst : CharP α n) {e : α} (he : IsInt e e') (hn : IsNat n n') (h₂ : IsInt (e' % n') r) : IsInt e r := ⟨by rw [he.out, CharP.intCast_eq_intCast_mod α n, show n = n' from hn.out, h₂.out, Int.cast_id]⟩ lemma CharP.isNat_pow {α} [Semiring α] : ∀ {f : α → ℕ → α} {a : α} {a' b b' c n n' : ℕ}, CharP α n → f = HPow.hPow → IsNat a a' → IsNat b b' → IsNat n n' → Nat.mod (Nat.pow a' b') n' = c → IsNat (f a b) c | _, _, a, _, b, _, _, n, _, rfl, ⟨h⟩, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨by rw [h, Nat.cast_id, Nat.pow_eq, ← Nat.cast_pow, CharP.natCast_eq_natCast_mod α n] rfl⟩ attribute [local instance] Mathlib.Meta.monadLiftOptionMetaM in /-- Evaluates `e` to an integer using `norm_num` and reduces the result modulo `n`. -/ def normBareNumeral {α : Q(Type u)} (n n' : Q(ℕ)) (pn : Q(IsNat «$n» «$n'»)) (e : Q($α)) (_ : Q(Ring $α)) (instCharP : Q(CharP $α $n)) : MetaM (Result e) := do let ⟨ze, ne, pe⟩ ← Result.toInt _ (← Mathlib.Meta.NormNum.derive e) let rr ← evalIntMod.go _ _ ze q(IsInt.raw_refl $ne) _ <| .isNat q(instAddMonoidWithOne) _ q(isNat_natCast _ _ (IsNat.raw_refl $n')) let ⟨zr, nr, pr⟩ ← rr.toInt _ return .isInt _ nr zr q(CharP.isInt_of_mod $instCharP $pe $pn $pr) mutual /-- Given an expression of the form `a ^ b` in a ring of characteristic `n`, reduces `a` modulo `n` recursively and then calculates `a ^ b` using fast modular exponentiation. -/ partial def normPow {α : Q(Type u)} (n n' : Q(ℕ)) (pn : Q(IsNat «$n» «$n'»)) (e : Q($α)) (_ : Q(Ring $α)) (instCharP : Q(CharP $α $n)) : MetaM (Result e) := do let .app (.app (f : Q($α → ℕ → $α)) (a : Q($α))) (b : Q(ℕ)) ← whnfR e | failure let .isNat sα na pa ← normIntNumeral' n n' pn a _ instCharP | failure let ⟨nb, pb⟩ ← Mathlib.Meta.NormNum.deriveNat b q(instAddMonoidWithOneNat) guard <|← withNewMCtxDepth <| isDefEq f q(HPow.hPow (α := $α)) haveI' : $e =Q $a ^ $b := ⟨⟩ haveI' : $f =Q HPow.hPow := ⟨⟩ have ⟨c, r⟩ := evalNatPowMod na nb n' assumeInstancesCommute return .isNat sα c q(CharP.isNat_pow (f := $f) $instCharP (.refl $f) $pa $pb $pn $r) /-- If `e` is of the form `a ^ b`, reduce it using fast modular exponentiation, otherwise reduce it using `norm_num`. -/ partial def normIntNumeral' {α : Q(Type u)} (n n' : Q(ℕ)) (pn : Q(IsNat «$n» «$n'»)) (e : Q($α)) (_ : Q(Ring $α)) (instCharP : Q(CharP $α $n)) : MetaM (Result e) := normPow n n' pn e _ instCharP <|> normBareNumeral n n' pn e _ instCharP end lemma CharP.intCast_eq_mod (R : Type _) [Ring R] (p : ℕ) [CharP R p] (k : ℤ) : (k : R) = (k % p : ℤ) := CharP.intCast_eq_intCast_mod R p /-- Given an integral expression `e : t` such that `t` is a ring of characteristic `n`, reduce `e` modulo `n`. -/ partial def normIntNumeral {α : Q(Type u)} (n : Q(ℕ)) (e : Q($α)) (_ : Q(Ring $α)) (instCharP : Q(CharP $α $n)) : MetaM (Result e) := do let ⟨n', pn⟩ ← deriveNat n q(instAddMonoidWithOneNat) normIntNumeral' n n' pn e _ instCharP lemma CharP.neg_eq_sub_one_mul {α : Type _} [Ring α] (n : ℕ) (inst : CharP α n) (b : α) (a : ℕ) (a' : α) (p : IsNat (n - 1 : α) a) (pa : a = a') : -b = a' * b := by rw [← pa, ← p.out, ← neg_one_mul] simp /-- Given an expression `(-e) : t` such that `t` is a ring of characteristic `n`, simplify this to `(n - 1) * e`. This should be called only when `normIntNumeral` fails, because `normIntNumeral` would otherwise be more useful by evaluating `-e` mod `n` to an actual numeral. -/ @[nolint unusedHavesSuffices] -- the `=Q` is necessary for type checking partial def normNeg {α : Q(Type u)} (n : Q(ℕ)) (e : Q($α)) (_instRing : Q(Ring $α)) (instCharP : Q(CharP $α $n)) : MetaM Simp.Result := do let .app f (b : Q($α)) ← whnfR e | failure guard <|← withNewMCtxDepth <| isDefEq f q(Neg.neg (α := $α)) let r ← (derive (α := α) q($n - 1)) match r with | .isNat sα a p => do have : instAddMonoidWithOne =Q $sα := ⟨⟩ let ⟨a', pa'⟩ ← mkOfNat α sα a let pf : Q(-$b = $a' * $b) := q(CharP.neg_eq_sub_one_mul $n $instCharP $b $a $a' $p $pa') return { expr := q($a' * $b), proof? := pf } | .isNegNat _ _ _ => throwError "normNeg: nothing useful to do in negative characteristic" | _ => throwError "normNeg: evaluating `{n} - 1` should give an integer result" lemma CharP.neg_mul_eq_sub_one_mul {α : Type _} [Ring α] (n : ℕ) (inst : CharP α n) (a b : α) (na : ℕ) (na' : α) (p : IsNat ((n - 1) * a : α) na) (pa : na = na') : -(a * b) = na' * b := by rw [← pa, ← p.out, ← neg_one_mul] simp /-- Given an expression `-(a * b) : t` such that `t` is a ring of characteristic `n`, and `a` is a numeral, simplify this to `((n - 1) * a) * b`. -/ @[nolint unusedHavesSuffices] -- the `=Q` is necessary for type checking partial def normNegCoeffMul {α : Q(Type u)} (n : Q(ℕ)) (e : Q($α)) (_instRing : Q(Ring $α)) (instCharP : Q(CharP $α $n)) : MetaM Simp.Result := do let .app neg (.app (.app mul (a : Q($α))) (b : Q($α))) ← whnfR e | failure guard <|← withNewMCtxDepth <| isDefEq neg q(Neg.neg (α := $α)) guard <|← withNewMCtxDepth <| isDefEq mul q(HMul.hMul (α := $α)) let r ← (derive (α := α) q(($n - 1) * $a)) match r with | .isNat sα na np => do have : AddGroupWithOne.toAddMonoidWithOne =Q $sα := ⟨⟩ let ⟨na', npa'⟩ ← mkOfNat α sα na let pf : Q(-($a * $b) = $na' * $b) := q(CharP.neg_mul_eq_sub_one_mul $n $instCharP $a $b $na $na' $np $npa') return { expr := q($na' * $b), proof? := pf } | .isNegNat _ _ _ => throwError "normNegCoeffMul: nothing useful to do in negative characteristic" | _ => throwError "normNegCoeffMul: evaluating `{n} - 1` should give an integer result" /-- A `TypeToCharPResult α` indicates if `α` can be determined to be a ring of characteristic `p`. -/ inductive TypeToCharPResult (α : Q(Type u)) | intLike (n : Q(ℕ)) (instRing : Q(Ring $α)) (instCharP : Q(CharP $α $n)) | failure instance {α : Q(Type u)} : Inhabited (TypeToCharPResult α) := ⟨.failure⟩ /-- Determine the characteristic of a ring from the type. This should be fast, so this pattern-matches on the type, rather than searching for a `CharP` instance. Use `typeToCharP (expensive := true)` to do more work in finding the characteristic, in particular it will search for a `CharP` instance in the context. -/ partial def typeToCharP (expensive := false) (t : Q(Type u)) : MetaM (TypeToCharPResult t) := match Expr.getAppFnArgs t with | (``ZMod, #[(n : Q(ℕ))]) => return .intLike n (q((ZMod.commRing _).toRing) : Q(Ring (ZMod $n))) (q(ZMod.charP _) : Q(CharP (ZMod $n) $n)) | (``Polynomial, #[(R : Q(Type u)), _]) => do match ← typeToCharP (expensive := expensive) R with | (.intLike n _ _) => return .intLike n (q(Polynomial.ring) : Q(Ring (Polynomial $R))) (q(Polynomial.instCharP _) : Q(CharP (Polynomial $R) $n)) | .failure => return .failure | _ => if ! expensive then return .failure else do -- Fallback: run an expensive procedures to determine a characteristic, -- by looking for a `CharP` instance. withNewMCtxDepth do /- If we want to support semirings, here we could implement the `natLike` fallback. -/ let .some instRing ← trySynthInstanceQ q(Ring $t) | return .failure let n ← mkFreshExprMVarQ q(ℕ) let .some instCharP ← findLocalDeclWithTypeQ? q(CharP $t $n) | return .failure return .intLike (← instantiateMVarsQ n) instRing instCharP /-- Given an expression `e`, determine whether it is a numeric expression in characteristic `n`, and if so, reduce `e` modulo `n`. This is not a `norm_num` plugin because it does not match on the syntax of `e`, rather it matches on the type of `e`. Use `matchAndNorm (expensive := true)` to do more work in finding the characteristic of the type of `e`. -/ partial def matchAndNorm (expensive := false) (e : Expr) : MetaM Simp.Result := do let α ← inferType e let u_succ : Level ← getLevel α let (.succ u) := u_succ | throwError "expected {α} to be a `Type _`, not `Sort {u_succ}`" have α : Q(Type u) := α match ← typeToCharP (expensive := expensive) α with | (.intLike n instRing instCharP) => -- Handle the numeric expressions first, e.g. `-5` (which shouldn't become `-1 * 5`) normIntNumeral n e instRing instCharP >>= Result.toSimpResult <|> normNegCoeffMul n e instRing instCharP <|> -- `-(3 * X) → ((n - 1) * 3) * X` normNeg n e instRing instCharP -- `-X → (n - 1) * X` /- Here we could add a `natLike` result using only a `Semiring` instance. This would activate only the less-powerful procedures that cannot handle subtraction. -/ | .failure => throwError "inferred type `{α}` does not have a known characteristic" -- We use a few `simp` lemmas to preprocess the expression and clean up subterms like `0 * X`. attribute [reduce_mod_char] sub_eq_add_neg attribute [reduce_mod_char] zero_add add_zero zero_mul mul_zero one_mul mul_one attribute [reduce_mod_char] eq_self_iff_true -- For closing non-numeric goals, e.g. `X = X` /-- Reduce all numeric subexpressions of `e` modulo their characteristic. Use `derive (expensive := true)` to do more work in finding the characteristic of the type of `e`. -/ partial def derive (expensive := false) (e : Expr) : MetaM Simp.Result := do withTraceNode `Tactic.reduce_mod_char (fun _ => return m!"{e}") do let e ← instantiateMVars e let config : Simp.Config := { zeta := false beta := false eta := false proj := false iota := false } let congrTheorems ← Meta.getSimpCongrTheorems let ext? ← getSimpExtension? `reduce_mod_char let ext ← match ext? with | some ext => pure ext | none => throwError "internal error: reduce_mod_char not registered as simp extension" let ctx ← Simp.mkContext config (congrTheorems := congrTheorems) (simpTheorems := #[← ext.getTheorems]) let discharge := Mathlib.Meta.NormNum.discharge ctx let r : Simp.Result := {expr := e} let pre := Simp.preDefault #[] >> fun e => try return (Simp.Step.done (← matchAndNorm (expensive := expensive) e)) catch _ => pure .continue let post := Simp.postDefault #[] let r ← r.mkEqTrans (← Simp.main r.expr ctx (methods := { pre, post, discharge? := discharge })).1 return r /-- Reduce all numeric subexpressions of the goal modulo their characteristic. -/ partial def reduceModCharTarget (expensive := false) : TacticM Unit := do liftMetaTactic1 fun goal ↦ do let tgt ← instantiateMVars (← goal.getType) let prf ← derive (expensive := expensive) tgt if prf.expr.consumeMData.isConstOf ``True then match prf.proof? with | some proof => goal.assign (← mkOfEqTrue proof) | none => goal.assign (mkConst ``True.intro) return none else applySimpResultToTarget goal tgt prf /-- Reduce all numeric subexpressions of the given hypothesis modulo their characteristic. -/ partial def reduceModCharHyp (expensive := false) (fvarId : FVarId) : TacticM Unit := liftMetaTactic1 fun goal ↦ do let hyp ← instantiateMVars (← fvarId.getDecl).type let prf ← derive (expensive := expensive) hyp return (← applySimpResultToLocalDecl goal fvarId prf false).map (·.snd) open Parser.Tactic /-- The tactic `reduce_mod_char` looks for numeric expressions in characteristic `p` and reduces these to lie between `0` and `p`. For example: ``` example : (5 : ZMod 4) = 1 := by reduce_mod_char example : (X ^ 2 - 3 * X + 4 : (ZMod 4)[X]) = X ^ 2 + X := by reduce_mod_char ``` It also handles negation, turning it into multiplication by `p - 1`, and similarly subtraction. This tactic uses the type of the subexpression to figure out if it is indeed of positive characteristic, for improved performance compared to trying to synthesise a `CharP` instance. The variant `reduce_mod_char!` also tries to use `CharP R n` hypotheses in the context. (Limitations of the typeclass system mean the tactic can't search for a `CharP R n` instance if `n` is not yet known; use `have : CharP R n := inferInstance; reduce_mod_char!` as a workaround.) -/ syntax (name := reduce_mod_char) "reduce_mod_char" (location)? : tactic @[inherit_doc reduce_mod_char] syntax (name := reduce_mod_char!) "reduce_mod_char!" (location)? : tactic elab_rules : tactic | `(tactic| reduce_mod_char $[$loc]?) => unsafe do match expandOptLocation (Lean.mkOptionalNode loc) with | Location.targets hyps target => do (← getFVarIds hyps).forM reduceModCharHyp if target then reduceModCharTarget | Location.wildcard => do (← (← getMainGoal).getNondepPropHyps).forM reduceModCharHyp reduceModCharTarget | `(tactic| reduce_mod_char! $[$loc]?) => unsafe do match expandOptLocation (Lean.mkOptionalNode loc) with | Location.targets hyps target => do (← getFVarIds hyps).forM (reduceModCharHyp (expensive := true)) if target then reduceModCharTarget (expensive := true) | Location.wildcard => do (← (← getMainGoal).getNondepPropHyps).forM (reduceModCharHyp (expensive := true)) reduceModCharTarget (expensive := true) end ReduceModChar end Tactic
Basic.lean
/- 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.CharP.Reduced import Mathlib.RingTheory.IntegralDomain -- TODO: remove Mathlib.Algebra.CharP.Reduced and move the last two lemmas to Lemmas /-! # Roots of unity We define roots of unity in the context of an arbitrary commutative monoid, as a subgroup of the group of units. ## Main definitions * `rootsOfUnity n M`, for `n : ℕ` is the subgroup of the units of a commutative monoid `M` consisting of elements `x` that satisfy `x ^ n = 1`. ## Main results * `rootsOfUnity.isCyclic`: the roots of unity in an integral domain form a cyclic group. ## Implementation details It is desirable that `rootsOfUnity` is a subgroup, and it will mainly be applied to rings (e.g. the ring of integers in a number field) and fields. We therefore implement it as a subgroup of the units of a commutative monoid. We have chosen to define `rootsOfUnity n` for `n : ℕ` and add a `[NeZero n]` typeclass assumption when we need `n` to be non-zero (which is the case for most interesting statements). Note that `rootsOfUnity 0 M` is the top subgroup of `Mˣ` (as the condition `ζ^0 = 1` is satisfied for all units). -/ noncomputable section open Polynomial open Finset variable {M N G R S F : Type*} variable [CommMonoid M] [CommMonoid N] [DivisionCommMonoid G] section rootsOfUnity variable {k l : ℕ} /-- `rootsOfUnity k M` is the subgroup of elements `m : Mˣ` that satisfy `m ^ k = 1`. -/ def rootsOfUnity (k : ℕ) (M : Type*) [CommMonoid M] : Subgroup Mˣ where carrier := {ζ | ζ ^ k = 1} one_mem' := one_pow _ mul_mem' _ _ := by simp_all only [Set.mem_setOf_eq, mul_pow, one_mul] inv_mem' _ := by simp_all only [Set.mem_setOf_eq, inv_pow, inv_one] @[simp] theorem mem_rootsOfUnity (k : ℕ) (ζ : Mˣ) : ζ ∈ rootsOfUnity k M ↔ ζ ^ k = 1 := Iff.rfl /-- A variant of `mem_rootsOfUnity` using `ζ : Mˣ`. -/ theorem mem_rootsOfUnity' (k : ℕ) (ζ : Mˣ) : ζ ∈ rootsOfUnity k M ↔ (ζ : M) ^ k = 1 := by rw [mem_rootsOfUnity]; norm_cast @[simp] theorem rootsOfUnity_one (M : Type*) [CommMonoid M] : rootsOfUnity 1 M = ⊥ := by ext1 simp only [mem_rootsOfUnity, pow_one, Subgroup.mem_bot] @[simp] lemma rootsOfUnity_zero (M : Type*) [CommMonoid M] : rootsOfUnity 0 M = ⊤ := by ext1 simp only [mem_rootsOfUnity, pow_zero, Subgroup.mem_top] theorem rootsOfUnity.coe_injective {n : ℕ} : Function.Injective (fun x : rootsOfUnity n M ↦ x.val.val) := Units.val_injective.comp Subtype.val_injective /-- Make an element of `rootsOfUnity` from a member of the base ring, and a proof that it has a positive power equal to one. -/ @[simps! coe_val] def rootsOfUnity.mkOfPowEq (ζ : M) {n : ℕ} [NeZero n] (h : ζ ^ n = 1) : rootsOfUnity n M := ⟨Units.ofPowEqOne ζ n h <| NeZero.ne n, Units.pow_ofPowEqOne _ _⟩ @[simp] theorem rootsOfUnity.coe_mkOfPowEq {ζ : M} {n : ℕ} [NeZero n] (h : ζ ^ n = 1) : ((rootsOfUnity.mkOfPowEq _ h : Mˣ) : M) = ζ := rfl theorem rootsOfUnity_le_of_dvd (h : k ∣ l) : rootsOfUnity k M ≤ rootsOfUnity l M := by obtain ⟨d, rfl⟩ := h intro ζ h simp_all only [mem_rootsOfUnity, pow_mul, one_pow] theorem map_rootsOfUnity (f : Mˣ →* Nˣ) (k : ℕ) : (rootsOfUnity k M).map f ≤ rootsOfUnity k N := by rintro _ ⟨ζ, h, rfl⟩ simp_all only [← map_pow, mem_rootsOfUnity, SetLike.mem_coe, MonoidHom.map_one] @[norm_cast] theorem rootsOfUnity.coe_pow [CommMonoid R] (ζ : rootsOfUnity k R) (m : ℕ) : (((ζ ^ m :) : Rˣ) : R) = ((ζ : Rˣ) : R) ^ m := by rw [Subgroup.coe_pow, Units.val_pow_eq_pow_val] /-- The canonical isomorphism from the `n`th roots of unity in `Mˣ` to the `n`th roots of unity in `M`. -/ def rootsOfUnityUnitsMulEquiv (M : Type*) [CommMonoid M] (n : ℕ) : rootsOfUnity n Mˣ ≃* rootsOfUnity n M where toFun ζ := ⟨ζ.val, (mem_rootsOfUnity ..).mpr <| (mem_rootsOfUnity' ..).mp ζ.prop⟩ invFun ζ := ⟨toUnits ζ.val, by simp only [mem_rootsOfUnity, ← map_pow, EmbeddingLike.map_eq_one_iff] exact (mem_rootsOfUnity ..).mp ζ.prop⟩ left_inv ζ := by simp only [toUnits_val_apply, Subtype.coe_eta] right_inv ζ := by simp only [val_toUnits_apply, Subtype.coe_eta] map_mul' ζ ζ' := by simp only [Subgroup.coe_mul, Units.val_mul, MulMemClass.mk_mul_mk] section CommMonoid variable [CommMonoid R] [CommMonoid S] [FunLike F R S] /-- Restrict a ring homomorphism to the nth roots of unity. -/ def restrictRootsOfUnity [MonoidHomClass F R S] (σ : F) (n : ℕ) : rootsOfUnity n R →* rootsOfUnity n S := { toFun := fun ξ ↦ ⟨Units.map σ (ξ : Rˣ), by rw [mem_rootsOfUnity, ← map_pow, Units.ext_iff, Units.coe_map, ξ.prop] exact map_one σ⟩ map_one' := by ext1; simp only [OneMemClass.coe_one, map_one] map_mul' := fun ξ₁ ξ₂ ↦ by ext1; simp only [Subgroup.coe_mul, map_mul, MulMemClass.mk_mul_mk] } @[simp] theorem restrictRootsOfUnity_coe_apply [MonoidHomClass F R S] (σ : F) (ζ : rootsOfUnity k R) : (restrictRootsOfUnity σ k ζ : Sˣ) = σ (ζ : Rˣ) := rfl /-- Restrict a monoid isomorphism to the nth roots of unity. -/ nonrec def MulEquiv.restrictRootsOfUnity (σ : R ≃* S) (n : ℕ) : rootsOfUnity n R ≃* rootsOfUnity n S where toFun := restrictRootsOfUnity σ n invFun := restrictRootsOfUnity σ.symm n left_inv ξ := by ext; exact σ.symm_apply_apply _ right_inv ξ := by ext; exact σ.apply_symm_apply _ map_mul' := (restrictRootsOfUnity _ n).map_mul @[simp] theorem MulEquiv.restrictRootsOfUnity_coe_apply (σ : R ≃* S) (ζ : rootsOfUnity k R) : (σ.restrictRootsOfUnity k ζ : Sˣ) = σ (ζ : Rˣ) := rfl @[simp] theorem MulEquiv.restrictRootsOfUnity_symm (σ : R ≃* S) : (σ.restrictRootsOfUnity k).symm = σ.symm.restrictRootsOfUnity k := rfl theorem coe_rootsOfUnity_to_set [NeZero k] : ((↑) : Rˣ → _) '' (rootsOfUnity k R) = {z : R | z^k = 1} := by ext x exact ⟨fun ⟨y,hy1,hy2⟩ => by rw [← hy2]; exact (mem_rootsOfUnity' k y).mp hy1, fun h ↦ ⟨(rootsOfUnity.mkOfPowEq x h), ⟨Subtype.coe_prop (rootsOfUnity.mkOfPowEq x h), rfl⟩⟩⟩ theorem rootsOfUnity_one_set : ((↑) : Rˣ → R) '' (rootsOfUnity 1 R) = {1} := by ext x simp end CommMonoid open Set in theorem rootsOfUnity_two_set [CommRing R] [NoZeroDivisors R] : ((↑) : Rˣ → R) '' (rootsOfUnity 2 R) = {1, -1} := by ext x rw [mem_insert_iff, mem_singleton_iff, ← sq_eq_one_iff, coe_rootsOfUnity_to_set, mem_setOf_eq] section IsDomain -- The following results need `k` to be nonzero. variable [NeZero k] [CommRing R] [IsDomain R] theorem mem_rootsOfUnity_iff_mem_nthRoots {ζ : Rˣ} : ζ ∈ rootsOfUnity k R ↔ (ζ : R) ∈ nthRoots k (1 : R) := by simp only [mem_rootsOfUnity, mem_nthRoots (NeZero.pos k), Units.ext_iff, Units.val_one, Units.val_pow_eq_pow_val] variable (k R) /-- Equivalence between the `k`-th roots of unity in `R` and the `k`-th roots of `1`. This is implemented as equivalence of subtypes, because `rootsOfUnity` is a subgroup of the group of units, whereas `nthRoots` is a multiset. -/ def rootsOfUnityEquivNthRoots : rootsOfUnity k R ≃ { x // x ∈ nthRoots k (1 : R) } where toFun x := ⟨(x : Rˣ), mem_rootsOfUnity_iff_mem_nthRoots.mp x.2⟩ invFun x := by refine ⟨⟨x, ↑x ^ (k - 1 : ℕ), ?_, ?_⟩, ?_⟩ all_goals rcases x with ⟨x, hx⟩; rw [mem_nthRoots <| NeZero.pos k] at hx simp only [← pow_succ, ← pow_succ', hx, tsub_add_cancel_of_le NeZero.one_le] simp only [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, hx, Units.val_one] variable {k R} @[simp] theorem rootsOfUnityEquivNthRoots_apply (x : rootsOfUnity k R) : (rootsOfUnityEquivNthRoots R k x : R) = ((x : Rˣ) : R) := rfl @[simp] theorem rootsOfUnityEquivNthRoots_symm_apply (x : { x // x ∈ nthRoots k (1 : R) }) : (((rootsOfUnityEquivNthRoots R k).symm x : Rˣ) : R) = (x : R) := rfl variable (k R) instance rootsOfUnity.fintype : Fintype (rootsOfUnity k R) := by classical exact Fintype.ofEquiv { x // x ∈ nthRoots k (1 : R) } (rootsOfUnityEquivNthRoots R k).symm instance rootsOfUnity.isCyclic : IsCyclic (rootsOfUnity k R) := isCyclic_of_subgroup_isDomain ((Units.coeHom R).comp (rootsOfUnity k R).subtype) coe_injective theorem card_rootsOfUnity : Fintype.card (rootsOfUnity k R) ≤ k := by classical calc Fintype.card (rootsOfUnity k R) = Fintype.card { x // x ∈ nthRoots k (1 : R) } := Fintype.card_congr (rootsOfUnityEquivNthRoots R k) _ ≤ Multiset.card (nthRoots k (1 : R)).attach := Multiset.card_le_card (Multiset.dedup_le _) _ = Multiset.card (nthRoots k (1 : R)) := Multiset.card_attach _ ≤ k := card_nthRoots k 1 variable {k R} theorem map_rootsOfUnity_eq_pow_self [FunLike F R R] [MonoidHomClass F R R] (σ : F) (ζ : rootsOfUnity k R) : ∃ m : ℕ, σ (ζ : Rˣ) = ((ζ : Rˣ) : R) ^ m := by obtain ⟨m, hm⟩ := MonoidHom.map_cyclic (restrictRootsOfUnity σ k) rw [← restrictRootsOfUnity_coe_apply, hm, ← zpow_mod_orderOf, ← Int.toNat_of_nonneg (m.emod_nonneg (Int.natCast_ne_zero.mpr (pos_iff_ne_zero.mp (orderOf_pos ζ)))), zpow_natCast, rootsOfUnity.coe_pow] exact ⟨(m % orderOf ζ).toNat, rfl⟩ lemma coe_rootsOfUnity_to_nthRootsFinset : ((↑) : Rˣ → R) '' (rootsOfUnity k R) = nthRootsFinset k (1 : R) := by ext x rw [mem_coe, Polynomial.mem_nthRootsFinset (Nat.pos_of_neZero k), coe_rootsOfUnity_to_set, Set.mem_setOf_eq] end IsDomain section Reduced variable (R) [CommRing R] [IsReduced R] -- @[simp] -- Porting note: simp normal form is `mem_rootsOfUnity_prime_pow_mul_iff'` theorem mem_rootsOfUnity_prime_pow_mul_iff (p k : ℕ) (m : ℕ) [ExpChar R p] {ζ : Rˣ} : ζ ∈ rootsOfUnity (p ^ k * m) R ↔ ζ ∈ rootsOfUnity m R := by simp only [mem_rootsOfUnity', ExpChar.pow_prime_pow_mul_eq_one_iff] /-- A variant of `mem_rootsOfUnity_prime_pow_mul_iff` in terms of `ζ ^ _` -/ @[simp] theorem mem_rootsOfUnity_prime_pow_mul_iff' (p k : ℕ) (m : ℕ) [ExpChar R p] {ζ : Rˣ} : ζ ^ (p ^ k * m) = 1 ↔ ζ ∈ rootsOfUnity m R := by rw [← mem_rootsOfUnity, mem_rootsOfUnity_prime_pow_mul_iff] end Reduced end rootsOfUnity section cyclic namespace IsCyclic /-- The isomorphism from the group of group homomorphisms from a finite cyclic group `G` of order `n` into another group `G'` to the group of `n`th roots of unity in `G'` determined by a generator `g` of `G`. It sends `φ : G →* G'` to `φ g`. -/ noncomputable def monoidHomMulEquivRootsOfUnityOfGenerator {G : Type*} [CommGroup G] {g : G} (hg : ∀ (x : G), x ∈ Subgroup.zpowers g) (G' : Type*) [CommGroup G'] : (G →* G') ≃* rootsOfUnity (Nat.card G) G' where toFun φ := ⟨(IsUnit.map φ <| Group.isUnit g).unit, by simp only [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, IsUnit.unit_spec, ← map_pow, pow_card_eq_one', map_one, Units.val_one]⟩ invFun ζ := monoidHomOfForallMemZpowers hg (g' := (ζ.val : G')) <| by simpa only [orderOf_eq_card_of_forall_mem_zpowers hg, orderOf_dvd_iff_pow_eq_one, ← Units.val_pow_eq_pow_val, Units.val_eq_one] using ζ.prop left_inv φ := (MonoidHom.eq_iff_eq_on_generator hg _ φ).mpr <| by simp only [IsUnit.unit_spec, monoidHomOfForallMemZpowers_apply_gen] right_inv φ := Subtype.ext <| by simp only [monoidHomOfForallMemZpowers_apply_gen, IsUnit.unit_of_val_units] map_mul' x y := by simp only [MonoidHom.mul_apply, MulMemClass.mk_mul_mk, Subtype.mk.injEq, Units.ext_iff, IsUnit.unit_spec, Units.val_mul] /-- The group of group homomorphisms from a finite cyclic group `G` of order `n` into another group `G'` is (noncanonically) isomorphic to the group of `n`th roots of unity in `G'`. -/ lemma monoidHom_mulEquiv_rootsOfUnity (G : Type*) [CommGroup G] [IsCyclic G] (G' : Type*) [CommGroup G'] : Nonempty <| (G →* G') ≃* rootsOfUnity (Nat.card G) G' := by obtain ⟨g, hg⟩ := IsCyclic.exists_generator (α := G) exact ⟨monoidHomMulEquivRootsOfUnityOfGenerator hg G'⟩ end IsCyclic end cyclic
Zeckendorf.lean
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Nat.Fib.Basic /-! # Zeckendorf's Theorem This file proves Zeckendorf's theorem: Every natural number can be written uniquely as a sum of distinct non-consecutive Fibonacci numbers. ## Main declarations * `List.IsZeckendorfRep`: Predicate for a list to be an increasing sequence of non-consecutive natural numbers greater than or equal to `2`, namely a Zeckendorf representation. * `Nat.greatestFib`: Greatest index of a Fibonacci number less than or equal to some natural. * `Nat.zeckendorf`: Send a natural number to its Zeckendorf representation. * `Nat.zeckendorfEquiv`: Zeckendorf's theorem, in the form of an equivalence between natural numbers and Zeckendorf representations. ## TODO We could prove that the order induced by `zeckendorfEquiv` on Zeckendorf representations is exactly the lexicographic order. ## Tags fibonacci, zeckendorf, digit -/ open List Nat -- TODO: The `local` attribute makes this not considered as an instance by linters @[nolint defLemma docBlame] local instance : IsTrans ℕ fun a b ↦ b + 2 ≤ a where trans _a _b _c hba hcb := hcb.trans <| le_self_add.trans hba namespace List /-- A list of natural numbers is a Zeckendorf representation (of a natural number) if it is an increasing sequence of non-consecutive numbers greater than or equal to `2`. This is relevant for Zeckendorf's theorem, since if we write a natural `n` as a sum of Fibonacci numbers `(l.map fib).sum`, `IsZeckendorfRep l` exactly means that we can't simplify any expression of the form `fib n + fib (n + 1) = fib (n + 2)`, `fib 1 = fib 2` or `fib 0 = 0` in the sum. -/ def IsZeckendorfRep (l : List ℕ) : Prop := (l ++ [0]).Chain' (fun a b ↦ b + 2 ≤ a) @[simp] lemma IsZeckendorfRep_nil : IsZeckendorfRep [] := by simp [IsZeckendorfRep] lemma IsZeckendorfRep.sum_fib_lt : ∀ {n l}, IsZeckendorfRep l → (∀ a ∈ (l ++ [0]).head?, a < n) → (l.map fib).sum < fib n | _, [], _, hn => fib_pos.2 <| hn _ rfl | n, a :: l, hl, hn => by simp only [IsZeckendorfRep, cons_append, chain'_iff_pairwise, pairwise_cons] at hl have : ∀ b, b ∈ head? (l ++ [0]) → b < a - 1 := fun b hb ↦ lt_tsub_iff_right.2 <| hl.1 _ <| mem_of_mem_head? hb simp only [mem_append, mem_singleton, ← chain'_iff_pairwise, or_imp, forall_and, forall_eq, zero_add] at hl simp only [map, List.sum_cons] refine (add_lt_add_left (sum_fib_lt hl.2 this) _).trans_le ?_ rw [add_comm, ← fib_add_one (hl.1.2.trans_lt' zero_lt_two).ne'] exact fib_mono (hn _ rfl) end List namespace Nat variable {m n : ℕ} /-- The greatest index of a Fibonacci number less than or equal to `n`. -/ def greatestFib (n : ℕ) : ℕ := (n + 1).findGreatest (fun k ↦ fib k ≤ n) lemma fib_greatestFib_le (n : ℕ) : fib (greatestFib n) ≤ n := findGreatest_spec (P := (fun k ↦ fib k ≤ n)) (zero_le _) <| zero_le _ lemma greatestFib_mono : Monotone greatestFib := fun _a _b hab ↦ findGreatest_mono (fun _k ↦ hab.trans') <| add_le_add_right hab _ @[simp] lemma le_greatestFib : m ≤ greatestFib n ↔ fib m ≤ n := ⟨fun h ↦ (fib_mono h).trans <| fib_greatestFib_le _, fun h ↦ le_findGreatest (m.le_fib_add_one.trans <| add_le_add_right h _) h⟩ @[simp] lemma greatestFib_lt : greatestFib m < n ↔ m < fib n := lt_iff_lt_of_le_iff_le le_greatestFib lemma lt_fib_greatestFib_add_one (n : ℕ) : n < fib (greatestFib n + 1) := greatestFib_lt.1 <| lt_succ_self _ @[simp] lemma greatestFib_fib : ∀ {n}, n ≠ 1 → greatestFib (fib n) = n | 0, _ => rfl | _n + 2, _ => findGreatest_eq_iff.2 ⟨le_fib_add_one _, fun _ ↦ le_rfl, fun _m hnm _ ↦ ((fib_lt_fib le_add_self).2 hnm).not_ge⟩ @[simp] lemma greatestFib_eq_zero : greatestFib n = 0 ↔ n = 0 := ⟨fun h ↦ by simpa using findGreatest_eq_zero_iff.1 h zero_lt_one le_add_self, by rintro rfl; rfl⟩ lemma greatestFib_ne_zero : greatestFib n ≠ 0 ↔ n ≠ 0 := greatestFib_eq_zero.not @[simp] lemma greatestFib_pos : 0 < greatestFib n ↔ 0 < n := by simp [pos_iff_ne_zero] lemma greatestFib_sub_fib_greatestFib_le_greatestFib (hn : n ≠ 0) : greatestFib (n - fib (greatestFib n)) ≤ greatestFib n - 2 := by rw [← Nat.lt_succ_iff, greatestFib_lt, tsub_lt_iff_right n.fib_greatestFib_le, Nat.sub_succ, succ_pred, ← fib_add_one] · exact n.lt_fib_greatestFib_add_one · simpa · simpa [← succ_le_iff, tsub_eq_zero_iff_le] using hn.bot_lt private lemma zeckendorf_aux (hm : 0 < m) : m - fib (greatestFib m) < m := tsub_lt_self hm <| fib_pos.2 <| findGreatest_pos.2 ⟨1, zero_lt_one, le_add_self, hm⟩ /-- The Zeckendorf representation of a natural number. Note: For unfolding, you should use the equational lemmas `Nat.zeckendorf_zero` and `Nat.zeckendorf_of_pos` instead of the autogenerated one. -/ def zeckendorf : ℕ → List ℕ | 0 => [] | m@(_ + 1) => letI a := greatestFib m a :: zeckendorf (m - fib a) decreasing_by simp_wf; subst_vars; apply zeckendorf_aux (zero_lt_succ _) @[simp] lemma zeckendorf_zero : zeckendorf 0 = [] := zeckendorf.eq_1 .. @[simp] lemma zeckendorf_succ (n : ℕ) : zeckendorf (n + 1) = greatestFib (n + 1) :: zeckendorf (n + 1 - fib (greatestFib (n + 1))) := zeckendorf.eq_2 .. @[simp] lemma zeckendorf_of_pos : ∀ {n}, 0 < n → zeckendorf n = greatestFib n :: zeckendorf (n - fib (greatestFib n)) | _n + 1, _ => zeckendorf_succ _ lemma isZeckendorfRep_zeckendorf : ∀ n, (zeckendorf n).IsZeckendorfRep | 0 => by simp only [zeckendorf_zero, IsZeckendorfRep_nil] | n + 1 => by rw [zeckendorf_succ, IsZeckendorfRep, List.cons_append] refine (isZeckendorfRep_zeckendorf _).cons' (fun a ha ↦ ?_) obtain h | h := eq_zero_or_pos (n + 1 - fib (greatestFib (n + 1))) · simp only [h, zeckendorf_zero, nil_append, head?_cons, Option.mem_some_iff] at ha subst ha exact le_greatestFib.2 le_add_self rw [zeckendorf_of_pos h, cons_append, head?_cons, Option.mem_some_iff] at ha subst a exact add_le_of_le_tsub_right_of_le (le_greatestFib.2 le_add_self) (greatestFib_sub_fib_greatestFib_le_greatestFib n.succ_ne_zero) lemma zeckendorf_sum_fib : ∀ {l}, IsZeckendorfRep l → zeckendorf (l.map fib).sum = l | [], _ => by simp only [map_nil, List.sum_nil, zeckendorf_zero] | a :: l, hl => by have hl' := hl simp only [IsZeckendorfRep, cons_append, chain'_iff_pairwise, pairwise_cons, mem_append, mem_singleton, or_imp, forall_and, forall_eq, zero_add] at hl rw [← chain'_iff_pairwise] at hl have ha : 0 < a := hl.1.2.trans_lt' zero_lt_two suffices h : greatestFib (fib a + sum (map fib l)) = a by simp only [map, List.sum_cons, add_pos_iff, fib_pos.2 ha, true_or, zeckendorf_of_pos, h, add_tsub_cancel_left, zeckendorf_sum_fib hl.2] simp only [add_comm, add_assoc, greatestFib, findGreatest_eq_iff, ne_eq, ha.ne', not_false_eq_true, le_add_iff_nonneg_left, _root_.zero_le, forall_true_left, not_le, true_and] refine ⟨le_add_of_le_right <| le_fib_add_one _, fun n hn _ ↦ ?_⟩ rw [add_comm, ← List.sum_cons, ← map_cons] exact hl'.sum_fib_lt (by simpa) @[simp] lemma sum_zeckendorf_fib (n : ℕ) : (n.zeckendorf.map fib).sum = n := by induction n using zeckendorf.induct <;> simp_all [fib_greatestFib_le] /-- **Zeckendorf's Theorem** as an equivalence between natural numbers and Zeckendorf representations. Every natural number can be written uniquely as a sum of non-consecutive Fibonacci numbers (if we forget about the first two terms `F₀ = 0`, `F₁ = 1`). -/ def zeckendorfEquiv : ℕ ≃ {l // IsZeckendorfRep l} where toFun n := ⟨zeckendorf n, isZeckendorfRep_zeckendorf _⟩ invFun l := (map fib l).sum left_inv := sum_zeckendorf_fib right_inv l := Subtype.ext <| zeckendorf_sum_fib l.2 end Nat
SurjOn.lean
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Data.Set.Function import Mathlib.Order.Interval.Set.LinearOrder /-! # Monotone surjective functions are surjective on intervals A monotone surjective function sends any interval in the domain onto the interval with corresponding endpoints in the range. This is expressed in this file using `Set.surjOn`, and provided for all permutations of interval endpoints. -/ variable {α : Type*} {β : Type*} [LinearOrder α] [PartialOrder β] {f : α → β} open Set Function open OrderDual (toDual) theorem surjOn_Ioo_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a b : α) : SurjOn f (Ioo a b) (Ioo (f a) (f b)) := by intro p hp rcases h_surj p with ⟨x, rfl⟩ refine ⟨x, mem_Ioo.2 ?_, rfl⟩ contrapose! hp exact fun h => h.2.not_ge (h_mono <| hp <| h_mono.reflect_lt h.1) theorem surjOn_Ico_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a b : α) : SurjOn f (Ico a b) (Ico (f a) (f b)) := by obtain hab | hab := lt_or_ge a b · intro p hp rcases eq_left_or_mem_Ioo_of_mem_Ico hp with (rfl | hp') · exact mem_image_of_mem f (left_mem_Ico.mpr hab) · exact image_mono Ioo_subset_Ico_self <| surjOn_Ioo_of_monotone_surjective h_mono h_surj a b hp' · rw [Ico_eq_empty (h_mono hab).not_gt] exact surjOn_empty f _ theorem surjOn_Ioc_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a b : α) : SurjOn f (Ioc a b) (Ioc (f a) (f b)) := by simpa using surjOn_Ico_of_monotone_surjective h_mono.dual h_surj (toDual b) (toDual a) -- to see that the hypothesis `a ≤ b` is necessary, consider a constant function theorem surjOn_Icc_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) {a b : α} (hab : a ≤ b) : SurjOn f (Icc a b) (Icc (f a) (f b)) := by intro p hp rcases eq_endpoints_or_mem_Ioo_of_mem_Icc hp with (rfl | rfl | hp') · exact ⟨a, left_mem_Icc.mpr hab, rfl⟩ · exact ⟨b, right_mem_Icc.mpr hab, rfl⟩ · exact image_mono Ioo_subset_Icc_self <| surjOn_Ioo_of_monotone_surjective h_mono h_surj a b hp' theorem surjOn_Ioi_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a : α) : SurjOn f (Ioi a) (Ioi (f a)) := by rw [← compl_Iic, ← compl_compl (Ioi (f a))] refine MapsTo.surjOn_compl ?_ h_surj exact fun x hx => (h_mono hx).not_gt theorem surjOn_Iio_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a : α) : SurjOn f (Iio a) (Iio (f a)) := @surjOn_Ioi_of_monotone_surjective _ _ _ _ _ h_mono.dual h_surj a theorem surjOn_Ici_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a : α) : SurjOn f (Ici a) (Ici (f a)) := by rw [← Ioi_union_left, ← Ioi_union_left] exact (surjOn_Ioi_of_monotone_surjective h_mono h_surj a).union_union (@image_singleton _ _ f a ▸ surjOn_image _ _) theorem surjOn_Iic_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a : α) : SurjOn f (Iic a) (Iic (f a)) := @surjOn_Ici_of_monotone_surjective _ _ _ _ _ h_mono.dual h_surj a
Lemmas.lean
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.FieldTheory.KummerExtension /-! # More results on primitive roots of unity (We put these in a separate file because of the `KummerExtension` import.) Assume that `μ` is a primitive `n`th root of unity in an integral domain `R`. Then $$ \prod_{k=1}^{n-1} (1 - \mu^k) = n \,; $$ see `IsPrimitiveRoot.prod_one_sub_pow_eq_order` and its variant `IsPrimitiveRoot.prod_pow_sub_one_eq_order` in terms of `∏ (μ^k - 1)`. We use this to deduce that `n` is divisible by `(μ - 1)^k` in `ℤ[μ] ⊆ R` when `k < n`. -/ variable {R : Type*} [CommRing R] [IsDomain R] namespace IsPrimitiveRoot open Finset Polynomial /-- If `μ` is a primitive `n`th root of unity in `R`, then `∏(1≤k<n) (1-μ^k) = n`. (Stated with `n+1` in place of `n` to avoid the condition `n ≠ 0`.) -/ lemma prod_one_sub_pow_eq_order {n : ℕ} {μ : R} (hμ : IsPrimitiveRoot μ (n + 1)) : ∏ k ∈ range n, (1 - μ ^ (k + 1)) = n + 1 := by have := X_pow_sub_C_eq_prod hμ n.zero_lt_succ (one_pow (n + 1)) rw [C_1, ← mul_geom_sum, prod_range_succ', pow_zero, mul_one, mul_comm, eq_comm] at this replace this := mul_right_cancel₀ (Polynomial.X_sub_C_ne_zero 1) this apply_fun Polynomial.eval 1 at this simpa only [mul_one, map_pow, eval_prod, eval_sub, eval_X, eval_pow, eval_C, eval_geom_sum, one_pow, sum_const, card_range, nsmul_eq_mul, Nat.cast_add, Nat.cast_one] using this /-- If `μ` is a primitive `n`th root of unity in `R`, then `(-1)^(n-1) * ∏(1≤k<n) (μ^k-1) = n`. (Stated with `n+1` in place of `n` to avoid the condition `n ≠ 0`.) -/ lemma prod_pow_sub_one_eq_order {n : ℕ} {μ : R} (hμ : IsPrimitiveRoot μ (n + 1)) : (-1) ^ n * ∏ k ∈ range n, (μ ^ (k + 1) - 1) = n + 1 := by have : (-1 : R) ^ n = ∏ k ∈ range n, -1 := by rw [prod_const, card_range] simp only [this, ← prod_mul_distrib, neg_one_mul, neg_sub, ← prod_one_sub_pow_eq_order hμ] open Algebra in /-- If `μ` is a primitive `n`th root of unity in `R` and `k < n`, then `n` is divisible by `(μ-1)^k` in `ℤ[μ] ⊆ R`. -/ lemma self_sub_one_pow_dvd_order {k n : ℕ} (hn : k < n) {μ : R} (hμ : IsPrimitiveRoot μ n) : ∃ z ∈ adjoin ℤ {μ}, n = z * (μ - 1) ^ k := by let n' + 1 := n obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le' (Nat.le_of_lt_succ hn) have hdvd k : ∃ z ∈ adjoin ℤ {μ}, μ ^ k - 1 = z * (μ - 1) := by refine ⟨(Finset.range k).sum (μ ^ ·), ?_, (geom_sum_mul μ k).symm⟩ exact Subalgebra.sum_mem _ fun m _ ↦ Subalgebra.pow_mem _ (self_mem_adjoin_singleton _ μ) _ let Z k := Classical.choose <| hdvd k have Zdef k : Z k ∈ adjoin ℤ {μ} ∧ μ ^ k - 1 = Z k * (μ - 1) := Classical.choose_spec <| hdvd k refine ⟨(-1) ^ (m + k) * (∏ j ∈ range k, Z (j + 1)) * ∏ j ∈ Ico k (m + k), (μ ^ (j + 1) - 1), ?_, ?_⟩ · apply Subalgebra.mul_mem · apply Subalgebra.mul_mem · exact Subalgebra.pow_mem _ (Subalgebra.neg_mem _ <| Subalgebra.one_mem _) _ · exact Subalgebra.prod_mem _ fun _ _ ↦ (Zdef _).1 · refine Subalgebra.prod_mem _ fun _ _ ↦ ?_ apply Subalgebra.sub_mem · exact Subalgebra.pow_mem _ (self_mem_adjoin_singleton ℤ μ) _ · exact Subalgebra.one_mem _ · push_cast have := Nat.cast_add (R := R) m k ▸ hμ.prod_pow_sub_one_eq_order rw [← this, mul_assoc, mul_assoc] congr 1 conv => enter [2, 2, 2]; rw [← card_range k] rw [← prod_range_mul_prod_Ico _ (Nat.le_add_left k m), mul_comm _ (_ ^ #_), ← mul_assoc, prod_mul_pow_card] conv => enter [2, 1, 2, j]; rw [← (Zdef _).2] end IsPrimitiveRoot
WhitneyEmbedding.lean
/- 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.FieldTheory.Finiteness import Mathlib.Geometry.Manifold.Diffeomorph import Mathlib.Geometry.Manifold.Instances.Real import Mathlib.Geometry.Manifold.PartitionOfUnity /-! # Whitney embedding theorem In this file we prove a version of the Whitney embedding theorem: for any compact real manifold `M`, for sufficiently large `n` there exists a smooth embedding `M → ℝ^n`. ## TODO * Prove the weak Whitney embedding theorem: any `σ`-compact smooth `m`-dimensional manifold can be embedded into `ℝ^(2m+1)`. This requires a version of Sard's theorem: for a locally Lipschitz continuous map `f : ℝ^m → ℝ^n`, `m < n`, the range has Hausdorff dimension at most `m`, hence it has measure zero. ## Tags partition of unity, smooth bump function, whitney theorem -/ universe uι uE uH uM open Function Filter Module Set Topology open scoped Manifold ContDiff variable {ι : Type uι} {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {H : Type uH} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type uM} [TopologicalSpace M] [ChartedSpace H M] [IsManifold I ∞ M] noncomputable section namespace SmoothBumpCovering /-! ### Whitney embedding theorem In this section we prove a version of the Whitney embedding theorem: for any compact real manifold `M`, for sufficiently large `n` there exists a smooth embedding `M → ℝ^n`. -/ variable [T2Space M] [Fintype ι] {s : Set M} (f : SmoothBumpCovering ι I M s) /-- Smooth embedding of `M` into `(E × ℝ) ^ ι`. -/ def embeddingPiTangent : C^∞⟮I, M; 𝓘(ℝ, ι → E × ℝ), ι → E × ℝ⟯ where val x i := (f i x • extChartAt I (f.c i) x, f i x) property := contMDiff_pi_space.2 fun i => ((f i).contMDiff_smul contMDiffOn_extChartAt).prodMk_space (f i).contMDiff @[local simp] theorem embeddingPiTangent_coe : ⇑f.embeddingPiTangent = fun x i => (f i x • extChartAt I (f.c i) x, f i x) := rfl theorem embeddingPiTangent_injOn : InjOn f.embeddingPiTangent s := by intro x hx y _ h simp only [embeddingPiTangent_coe, funext_iff] at h obtain ⟨h₁, h₂⟩ := Prod.mk_inj.1 (h (f.ind x hx)) rw [f.apply_ind x hx] at h₂ rw [← h₂, f.apply_ind x hx, one_smul, one_smul] at h₁ have := f.mem_extChartAt_source_of_eq_one h₂.symm exact (extChartAt I (f.c _)).injOn (f.mem_extChartAt_ind_source x hx) this h₁ theorem embeddingPiTangent_injective (f : SmoothBumpCovering ι I M) : Injective f.embeddingPiTangent := injective_iff_injOn_univ.2 f.embeddingPiTangent_injOn theorem comp_embeddingPiTangent_mfderiv (x : M) (hx : x ∈ s) : ((ContinuousLinearMap.fst ℝ E ℝ).comp (@ContinuousLinearMap.proj ℝ _ ι (fun _ => E × ℝ) _ _ (fun _ => inferInstance) (f.ind x hx))).comp (mfderiv I 𝓘(ℝ, ι → E × ℝ) f.embeddingPiTangent x) = mfderiv I I (chartAt H (f.c (f.ind x hx))) x := by set L := (ContinuousLinearMap.fst ℝ E ℝ).comp (@ContinuousLinearMap.proj ℝ _ ι (fun _ => E × ℝ) _ _ (fun _ => inferInstance) (f.ind x hx)) have := L.hasMFDerivAt.comp x (f.embeddingPiTangent.contMDiff.mdifferentiableAt (mod_cast le_top)).hasMFDerivAt convert hasMFDerivAt_unique this _ refine (hasMFDerivAt_extChartAt (f.mem_chartAt_ind_source x hx)).congr_of_eventuallyEq ?_ refine (f.eventuallyEq_one x hx).mono fun y hy => ?_ simp only [L, embeddingPiTangent_coe, ContinuousLinearMap.coe_comp', (· ∘ ·), ContinuousLinearMap.coe_fst', ContinuousLinearMap.proj_apply] rw [hy, Pi.one_apply, one_smul] theorem embeddingPiTangent_ker_mfderiv (x : M) (hx : x ∈ s) : LinearMap.ker (mfderiv I 𝓘(ℝ, ι → E × ℝ) f.embeddingPiTangent x) = ⊥ := by apply bot_unique rw [← (mdifferentiable_chart (f.c (f.ind x hx))).ker_mfderiv_eq_bot (f.mem_chartAt_ind_source x hx), ← comp_embeddingPiTangent_mfderiv] exact LinearMap.ker_le_ker_comp _ _ theorem embeddingPiTangent_injective_mfderiv (x : M) (hx : x ∈ s) : Injective (mfderiv I 𝓘(ℝ, ι → E × ℝ) f.embeddingPiTangent x) := LinearMap.ker_eq_bot.1 (f.embeddingPiTangent_ker_mfderiv x hx) /-- Baby version of the **Whitney weak embedding theorem**: if `M` admits a finite covering by supports of bump functions, then for some `n` it can be immersed into the `n`-dimensional Euclidean space. -/ theorem exists_immersion_euclidean {ι : Type*} [Finite ι] (f : SmoothBumpCovering ι I M) : ∃ (n : ℕ) (e : M → EuclideanSpace ℝ (Fin n)), ContMDiff I (𝓡 n) ∞ e ∧ Injective e ∧ ∀ x : M, Injective (mfderiv I (𝓡 n) e x) := by cases nonempty_fintype ι set F := EuclideanSpace ℝ (Fin <| finrank ℝ (ι → E × ℝ)) letI : IsNoetherian ℝ (E × ℝ) := IsNoetherian.iff_fg.2 inferInstance letI : FiniteDimensional ℝ (ι → E × ℝ) := IsNoetherian.iff_fg.1 inferInstance set eEF : (ι → E × ℝ) ≃L[ℝ] F := ContinuousLinearEquiv.ofFinrankEq finrank_euclideanSpace_fin.symm refine ⟨_, eEF ∘ f.embeddingPiTangent, eEF.toDiffeomorph.contMDiff.comp f.embeddingPiTangent.contMDiff, eEF.injective.comp f.embeddingPiTangent_injective, fun x => ?_⟩ rw [mfderiv_comp _ eEF.differentiableAt.mdifferentiableAt (f.embeddingPiTangent.contMDiff.mdifferentiableAt (mod_cast le_top)), eEF.mfderiv_eq] exact eEF.injective.comp (f.embeddingPiTangent_injective_mfderiv _ trivial) end SmoothBumpCovering /-- Baby version of the Whitney weak embedding theorem: if `M` admits a finite covering by supports of bump functions, then for some `n` it can be embedded into the `n`-dimensional Euclidean space. -/ theorem exists_embedding_euclidean_of_compact [T2Space M] [CompactSpace M] : ∃ (n : ℕ) (e : M → EuclideanSpace ℝ (Fin n)), ContMDiff I (𝓡 n) ∞ e ∧ IsClosedEmbedding e ∧ ∀ x : M, Injective (mfderiv I (𝓡 n) e x) := by rcases SmoothBumpCovering.exists_isSubordinate I isClosed_univ fun (x : M) _ => univ_mem with ⟨ι, f, -⟩ haveI := f.fintype rcases f.exists_immersion_euclidean with ⟨n, e, hsmooth, hinj, hinj_mfderiv⟩ exact ⟨n, e, hsmooth, hsmooth.continuous.isClosedEmbedding hinj, hinj_mfderiv⟩
action.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrbool ssrfun ssrnotations eqtype. From mathcomp Require Import ssrnat div seq prime fintype bigop finset. From mathcomp Require Import fingroup morphism perm automorphism quotient. (******************************************************************************) (* Group action: orbits, stabilisers, transitivity. *) (* is_action D to == the function to : T -> aT -> T defines an action *) (* of D : {set aT} on T. *) (* action D T == structure for a function defining an action of D. *) (* act_dom to == the domain D of to : action D rT. *) (* {action: aT &-> T} == structure for a total action. *) (* := action [set: aT] T *) (* TotalAction to1 toM == the constructor for total actions; to1 and toM *) (* are the proofs of the action identities for 1 and *) (* a * b, respectively. *) (* is_groupAction R to == to is a group action on range R: for all a in D, *) (* the permutation induced by to a is in Aut R. Thus *) (* the action of D must be trivial outside R. *) (* groupAction D R == the structure for group actions of D on R. This *) (* is a telescope on action D rT. *) (* gact_range to == the range R of to : groupAction D R. *) (* GroupAction toAut == constructs a groupAction for action to from *) (* toAut : actm to @* D \subset Aut R (actm to is *) (* the morphism to {perm rT} associated to 'to'). *) (* orbit to A x == the orbit of x under the action of A via to. *) (* orbit_transversal to A S == a transversal of the partition orbit to A @: S *) (* of S, provided A acts on S via to. *) (* amove to A x y == the set of a in A whose action sends x to y. *) (* 'C_A[x | to] == the stabiliser of x : rT in A :&: D. *) (* 'C_A(S | to) == the pointwise stabiliser of S : {set rT} in D :&: A. *) (* 'N_A(S | to) == the global stabiliser of S : {set rT} in D :&: A. *) (* 'Fix_(S | to)[a] == the set of fixpoints of a in S. *) (* 'Fix_(S | to)(A) == the set of fixpoints of A in S. *) (* In the first three _A can be omitted and defaults to the domain D of to; *) (* in the last two S can be omitted and defaults to [set: T], so 'Fix_to[a] *) (* is the set of all fixpoints of a. *) (* The domain restriction ensures that stabilisers have a canonical group *) (* structure, but note that 'Fix sets are generally not groups. Indeed, we *) (* provide alternative definitions when to is a group action on R: *) (* 'C_(G | to)(A) == the centraliser in R :&: G of the group action of *) (* D :&: A via to *) (* 'C_(G | to)[a] == the centraliser in R :&: G of a \in D, via to. *) (* These sets are groups when G is; G can be omitted: 'C(|to)(A) is the *) (* centraliser in R of the action of D :&: A via to. *) (* [acts A, on S | to] == A \subset D acts on the set S via to. *) (* {acts A, on S | to} == A acts on the set S (Prop statement). *) (* {acts A, on group G | to} == [acts A, on S | to] /\ G \subset R, i.e., *) (* A \subset D acts on G \subset R, via *) (* to : groupAction D R. *) (* [transitive A, on S | to] == A acts transitively on S. *) (* [faithful A, on S | to] == A acts faithfully on S. *) (* acts_irreducibly to A G == A acts irreducibly via the groupAction to *) (* on the nontrivial group G, i.e., A does *) (* not act on any nontrivial subgroup of G. *) (* Important caveat: the definitions of orbit, amove, 'Fix_(S | to)(A), *) (* transitive and faithful assume that A is a subset of the domain D. As most *) (* of the permutation actions we consider are total this is usually harmless. *) (* (Note that the theory of partial actions is only partially developed.) *) (* In all of the above, to is expected to be the actual action structure, *) (* not merely the function. There is a special scope %act for actions, and *) (* constructions and notations for many classical actions: *) (* 'P == natural action of a permutation group via aperm. *) (* 'J == internal group action (conjugation) via conjg (_ ^ _). *) (* 'R == regular group action (right translation) via mulg (_ * _). *) (* (However, to limit ambiguity, _ * _ is NOT a canonical action.) *) (* to^* == the action induced by to on {set rT} via to^* (== setact to). *) (* 'Js == the internal action on subsets via _ :^ _, equivalent to 'J^*. *) (* 'Rs == the regular action on subsets via rcoset, equivalent to 'R^*. *) (* 'JG == the conjugation action on {group rT} via (_ :^ _)%G. *) (* to / H == the action induced by to on coset_of H via qact to H, and *) (* restricted to (qact_dom to H) == 'N(rcosets H 'N(H) | to^* ). *) (* 'Q == the action induced to cosets by conjugation; the domain is *) (* qact_dom 'J H, which is provably equal to 'N(H). *) (* to %% A == the action of coset_of A via modact to A, with domain D / A *) (* and support restricted to 'C(D :&: A | to). *) (* to \ sAD == the action of A via ract to sAD == to, if sAD : A \subset D. *) (* [Aut G] == the permutation action restricted to Aut G, via autact G. *) (* <[nRA]> == the action of A on R via actby nRA == to in A and on R, and *) (* the trivial action elsewhere; here nRA : [acts A, on R | to] *) (* or nRA : {acts A, on group R | to}. *) (* to^? == the action induced by to on sT : @subType rT P, via subact to *) (* with domain subact_dom P to == 'N([set x | P x] | to). *) (* <<phi>> == the action of phi : D >-> {perm rT}, via mact phi. *) (* to \o f == the composite action (with domain f @*^-1 D) of the action to *) (* with f : {morphism G >-> aT}, via comp_act to f. Here f must *) (* be the actual morphism object (e.g., coset_morphism H), not *) (* the underlying function (e.g., coset H). *) (* The explicit application of an action to is usually written (to%act x a), *) (* but %act can be omitted if to is an abstract action or a set action to^*. *) (* Note that this form will simplify and expose the acting function. *) (* There is a %gact scope for group actions; the notations above are *) (* recognised in %gact when they denote canonical group actions. *) (* Actions can be used to define morphisms: *) (* actperm to == the morphism D >-> {perm rT} induced by to. *) (* actm to a == if a \in D the function on D induced by the action to, else *) (* the identity function. If to is a group action with range R *) (* then actm to a is canonically a morphism on R. *) (* We also define here the restriction operation on permutations (the domain *) (* of this operations is a stabiliser), and local automorphism groups: *) (* restr_perm S p == if p acts on S, the permutation with support in S that *) (* coincides with p on S; else the identity. Note that *) (* restr_perm is a permutation group morphism that maps *) (* Aut G to Aut S when S is a subgroup of G. *) (* Aut_in A G == the local permutation group 'N_A(G | 'P) / 'C_A(G | 'P) *) (* Usually A is an automorphism group, and then Aut_in A G *) (* is isomorphic to a subgroup of Aut G, specifically *) (* restr_perm @* A. *) (* Finally, gproduct.v will provide a semi-direct group construction that *) (* maps an external group action to an internal one; the theory of morphisms *) (* between such products makes use of the following definition: *) (* morph_act to to' f fA <=> the action of to' on the images of f and fA is *) (* the image of the action of to, i.e., for all x and a we *) (* have f (to x a) = to' (f x) (fA a). Note that there is *) (* no mention of the domains of to and to'; if needed, this *) (* predicate should be restricted via the {in ...} notation *) (* and domain conditions should be added. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope action_scope. Declare Scope groupAction_scope. Import GroupScope. Section ActionDef. Variables (aT : finGroupType) (D : {set aT}) (rT : Type). Implicit Types a b : aT. Implicit Type x : rT. Definition act_morph to x := forall a b, to x (a * b) = to (to x a) b. Definition is_action to := left_injective to /\ forall x, {in D &, act_morph to x}. Record action := Action {act :> rT -> aT -> rT; _ : is_action act}. Definition clone_action to := let: Action _ toP := to return {type of Action for to} -> action in fun k => k toP. End ActionDef. (* Need to close the Section here to avoid re-declaring all Argument Scopes *) Delimit Scope action_scope with act. Bind Scope action_scope with action. Arguments act_morph {aT rT%_type} to x%_g. Arguments is_action {aT} D%_g {rT} to. Arguments act {aT D%_g rT%_type} to%_act x%_g a%_g : rename. Arguments clone_action [aT D%_g rT%_type to%_act] _. Notation "{ 'action' aT &-> T }" := (action [set: aT] T) (format "{ 'action' aT &-> T }") : type_scope. Notation "[ 'action' 'of' to ]" := (clone_action (@Action _ _ _ to)) (format "[ 'action' 'of' to ]") : form_scope. Definition act_dom aT D rT of @action aT D rT := D. Section TotalAction. Variables (aT : finGroupType) (rT : Type) (to : rT -> aT -> rT). Hypotheses (to1 : to^~ 1 =1 id) (toM : forall x, act_morph to x). Lemma is_total_action : is_action setT to. Proof. split=> [a | x a b _ _] /=; last by rewrite toM. by apply: can_inj (to^~ a^-1) _ => x; rewrite -toM ?mulgV. Qed. Definition TotalAction := Action is_total_action. End TotalAction. Section ActionDefs. Variables (aT aT' : finGroupType) (D : {set aT}) (D' : {set aT'}). Definition morph_act rT rT' (to : action D rT) (to' : action D' rT') f fA := forall x a, f (to x a) = to' (f x) (fA a). Variable rT : finType. (* Most definitions require a finType structure on rT *) Implicit Type to : action D rT. Implicit Type A : {set aT}. Implicit Type S : {set rT}. Definition actm to a := if a \in D then to^~ a else id. Definition setact to S a := [set to x a | x in S]. Definition orbit to A x := to x @: A. Definition amove to A x y := [set a in A | to x a == y]. Definition afix to A := [set x | A \subset [set a | to x a == x]]. Definition astab S to := D :&: [set a | S \subset [set x | to x a == x]]. Definition astabs S to := D :&: [set a | S \subset to^~ a @^-1: S]. Definition acts_on A S to := {in A, forall a x, (to x a \in S) = (x \in S)}. Definition atrans A S to := S \in orbit to A @: S. Definition faithful A S to := A :&: astab S to \subset [1]. End ActionDefs. Arguments setact {aT D%_g rT} to%_act S%_g a%_g. Arguments orbit {aT D%_g rT} to%_act A%_g x%_g. Arguments amove {aT D%_g rT} to%_act A%_g x%_g y%_g. Arguments afix {aT D%_g rT} to%_act A%_g. Arguments astab {aT D%_g rT} S%_g to%_act. Arguments astabs {aT D%_g rT} S%_g to%_act. Arguments acts_on {aT D%_g rT} A%_g S%_g to%_act. Arguments atrans {aT D%_g rT} A%_g S%_g to%_act. Arguments faithful {aT D%_g rT} A%_g S%_g to%_act. Notation "to ^*" := (setact to) : function_scope. Prenex Implicits orbit amove. Notation "''Fix_' to ( A )" := (afix to A) (to at level 2, format "''Fix_' to ( A )") : group_scope. (* camlp4 grammar factoring *) Notation "''Fix_' ( to ) ( A )" := 'Fix_to(A) (only parsing) : group_scope. Notation "''Fix_' ( S | to ) ( A )" := (S :&: 'Fix_to(A)) (format "''Fix_' ( S | to ) ( A )") : group_scope. Notation "''Fix_' to [ a ]" := ('Fix_to([set a])) (to at level 2, format "''Fix_' to [ a ]") : group_scope. Notation "''Fix_' ( S | to ) [ a ]" := (S :&: 'Fix_to[a]) (format "''Fix_' ( S | to ) [ a ]") : group_scope. Notation "''C' ( S | to )" := (astab S to) : group_scope. Notation "''C_' A ( S | to )" := (A :&: 'C(S | to)) : group_scope. Notation "''C_' ( A ) ( S | to )" := 'C_A(S | to) (only parsing) : group_scope. Notation "''C' [ x | to ]" := ('C([set x] | to)) : group_scope. Notation "''C_' A [ x | to ]" := (A :&: 'C[x | to]) : group_scope. Notation "''C_' ( A ) [ x | to ]" := 'C_A[x | to] (only parsing) : group_scope. Notation "''N' ( S | to )" := (astabs S to) (format "''N' ( S | to )") : group_scope. Notation "''N_' A ( S | to )" := (A :&: 'N(S | to)) (A at level 2, format "''N_' A ( S | to )") : group_scope. Notation "[ 'acts' A , 'on' S | to ]" := (A \subset pred_of_set 'N(S | to)) (format "[ 'acts' A , 'on' S | to ]") : form_scope. Notation "{ 'acts' A , 'on' S | to }" := (acts_on A S to) (format "{ 'acts' A , 'on' S | to }") : type_scope. Notation "[ 'transitive' A , 'on' S | to ]" := (atrans A S to) (format "[ 'transitive' A , 'on' S | to ]") : form_scope. Notation "[ 'faithful' A , 'on' S | to ]" := (faithful A S to) (format "[ 'faithful' A , 'on' S | to ]") : form_scope. Section RawAction. (* Lemmas that do not require the group structure on the action domain. *) (* Some lemmas like actMin would be actually be valid for arbitrary rT, *) (* e.g., for actions on a function type, but would be difficult to use *) (* as a view due to the confusion between parameters and assumptions. *) Variables (aT : finGroupType) (D : {set aT}) (rT : finType) (to : action D rT). Implicit Types (a : aT) (x y : rT) (A B : {set aT}) (S T : {set rT}). Lemma act_inj : left_injective to. Proof. by case: to => ? []. Qed. Arguments act_inj : clear implicits. Lemma actMin x : {in D &, act_morph to x}. Proof. by case: to => ? []. Qed. Lemma actmEfun a : a \in D -> actm to a = to^~ a. Proof. by rewrite /actm => ->. Qed. Lemma actmE a : a \in D -> actm to a =1 to^~ a. Proof. by move=> Da; rewrite actmEfun. Qed. Lemma setactE S a : to^* S a = [set to x a | x in S]. Proof. by []. Qed. Lemma mem_setact S a x : x \in S -> to x a \in to^* S a. Proof. exact: imset_f. Qed. Lemma card_setact S a : #|to^* S a| = #|S|. Proof. by apply: card_imset; apply: act_inj. Qed. Lemma setact_is_action : is_action D to^*. Proof. split=> [a R S eqRS | a b Da Db S]; last first. by rewrite /setact /= -imset_comp; apply: eq_imset => x; apply: actMin. apply/setP=> x; apply/idP/idP=> /(mem_setact a). by rewrite eqRS => /imsetP[y Sy /act_inj->]. by rewrite -eqRS => /imsetP[y Sy /act_inj->]. Qed. Canonical set_action := Action setact_is_action. Lemma orbitE A x : orbit to A x = to x @: A. Proof. by []. Qed. Lemma orbitP A x y : reflect (exists2 a, a \in A & to x a = y) (y \in orbit to A x). Proof. by apply: (iffP imsetP) => [] [a]; exists a. Qed. Lemma mem_orbit A x a : a \in A -> to x a \in orbit to A x. Proof. exact: imset_f. Qed. Lemma afixP A x : reflect (forall a, a \in A -> to x a = x) (x \in 'Fix_to(A)). Proof. rewrite inE; apply: (iffP subsetP) => [xfix a /xfix | xfix a Aa]. by rewrite inE => /eqP. by rewrite inE xfix. Qed. Lemma afixS A B : A \subset B -> 'Fix_to(B) \subset 'Fix_to(A). Proof. by move=> sAB; apply/subsetP=> u /[!inE]; apply: subset_trans. Qed. Lemma afixU A B : 'Fix_to(A :|: B) = 'Fix_to(A) :&: 'Fix_to(B). Proof. by apply/setP=> x; rewrite !inE subUset. Qed. Lemma afix1P a x : reflect (to x a = x) (x \in 'Fix_to[a]). Proof. by rewrite inE sub1set inE; apply: eqP. Qed. Lemma astabIdom S : 'C_D(S | to) = 'C(S | to). Proof. by rewrite setIA setIid. Qed. Lemma astab_dom S : {subset 'C(S | to) <= D}. Proof. by move=> a /setIP[]. Qed. Lemma astab_act S a x : a \in 'C(S | to) -> x \in S -> to x a = x. Proof. rewrite 2!inE => /andP[_ cSa] Sx; apply/eqP. by have /[1!inE] := subsetP cSa x Sx. Qed. Lemma astabS S1 S2 : S1 \subset S2 -> 'C(S2 | to) \subset 'C(S1 | to). Proof. by move=> sS12; apply/subsetP=> x /[!inE] /andP[->]; apply: subset_trans. Qed. Lemma astabsIdom S : 'N_D(S | to) = 'N(S | to). Proof. by rewrite setIA setIid. Qed. Lemma astabs_dom S : {subset 'N(S | to) <= D}. Proof. by move=> a /setIdP[]. Qed. Lemma astabs_act S a x : a \in 'N(S | to) -> (to x a \in S) = (x \in S). Proof. rewrite 2!inE subEproper properEcard => /andP[_]. rewrite (card_preimset _ (act_inj _)) ltnn andbF orbF => /eqP{2}->. by rewrite inE. Qed. Lemma astab_sub S : 'C(S | to) \subset 'N(S | to). Proof. apply/subsetP=> a cSa; rewrite !inE (astab_dom cSa). by apply/subsetP=> x Sx; rewrite inE (astab_act cSa). Qed. Lemma astabsC S : 'N(~: S | to) = 'N(S | to). Proof. apply/setP=> a; apply/idP/idP=> nSa; rewrite !inE (astabs_dom nSa). by rewrite -setCS -preimsetC; apply/subsetP=> x; rewrite inE astabs_act. by rewrite preimsetC setCS; apply/subsetP=> x; rewrite inE astabs_act. Qed. Lemma astabsI S T : 'N(S | to) :&: 'N(T | to) \subset 'N(S :&: T | to). Proof. apply/subsetP=> a; rewrite !inE -!andbA preimsetI => /and4P[-> nSa _ nTa] /=. by rewrite setISS. Qed. Lemma astabs_setact S a : a \in 'N(S | to) -> to^* S a = S. Proof. move=> nSa; apply/eqP; rewrite eqEcard card_setact leqnn andbT. by apply/subsetP=> _ /imsetP[x Sx ->]; rewrite astabs_act. Qed. Lemma astab1_set S : 'C[S | set_action] = 'N(S | to). Proof. apply/setP=> a; apply/idP/idP=> nSa. case/setIdP: nSa => Da; rewrite !inE Da sub1set inE => /eqP defS. by apply/subsetP=> x Sx; rewrite inE -defS mem_setact. by rewrite !inE (astabs_dom nSa) sub1set inE /= astabs_setact. Qed. Lemma astabs_set1 x : 'N([set x] | to) = 'C[x | to]. Proof. apply/eqP; rewrite eqEsubset astab_sub andbC setIS //. by apply/subsetP=> a; rewrite ?(inE,sub1set). Qed. Lemma acts_dom A S : [acts A, on S | to] -> A \subset D. Proof. by move=> nSA; rewrite (subset_trans nSA) ?subsetIl. Qed. Lemma acts_act A S : [acts A, on S | to] -> {acts A, on S | to}. Proof. by move=> nAS a Aa x; rewrite astabs_act ?(subsetP nAS). Qed. Lemma astabCin A S : A \subset D -> (A \subset 'C(S | to)) = (S \subset 'Fix_to(A)). Proof. move=> sAD; apply/subsetP/subsetP=> [sAC x xS | sSF a aA]. by apply/afixP=> a aA; apply: astab_act (sAC _ aA) xS. rewrite !inE (subsetP sAD _ aA); apply/subsetP=> x xS. by move/afixP/(_ _ aA): (sSF _ xS) => /[1!inE] ->. Qed. Section ActsSetop. Variables (A : {set aT}) (S T : {set rT}). Hypotheses (AactS : [acts A, on S | to]) (AactT : [acts A, on T | to]). Lemma astabU : 'C(S :|: T | to) = 'C(S | to) :&: 'C(T | to). Proof. by apply/setP=> a; rewrite !inE subUset; case: (a \in D). Qed. Lemma astabsU : 'N(S | to) :&: 'N(T | to) \subset 'N(S :|: T | to). Proof. by rewrite -(astabsC S) -(astabsC T) -(astabsC (S :|: T)) setCU astabsI. Qed. Lemma astabsD : 'N(S | to) :&: 'N(T | to) \subset 'N(S :\: T| to). Proof. by rewrite setDE -(astabsC T) astabsI. Qed. Lemma actsI : [acts A, on S :&: T | to]. Proof. by apply: subset_trans (astabsI S T); rewrite subsetI AactS. Qed. Lemma actsU : [acts A, on S :|: T | to]. Proof. by apply: subset_trans astabsU; rewrite subsetI AactS. Qed. Lemma actsD : [acts A, on S :\: T | to]. Proof. by apply: subset_trans astabsD; rewrite subsetI AactS. Qed. End ActsSetop. Lemma acts_in_orbit A S x y : [acts A, on S | to] -> y \in orbit to A x -> x \in S -> y \in S. Proof. by move=> nSA/imsetP[a Aa ->{y}] Sx; rewrite (astabs_act _ (subsetP nSA a Aa)). Qed. Lemma subset_faithful A B S : B \subset A -> [faithful A, on S | to] -> [faithful B, on S | to]. Proof. by move=> sAB; apply: subset_trans; apply: setSI. Qed. Section Reindex. Variables (vT : Type) (idx : vT) (op : Monoid.com_law idx) (S : {set rT}). Lemma reindex_astabs a F : a \in 'N(S | to) -> \big[op/idx]_(i in S) F i = \big[op/idx]_(i in S) F (to i a). Proof. move=> nSa; rewrite (reindex_inj (act_inj a)); apply: eq_bigl => x. exact: astabs_act. Qed. Lemma reindex_acts A a F : [acts A, on S | to] -> a \in A -> \big[op/idx]_(i in S) F i = \big[op/idx]_(i in S) F (to i a). Proof. by move=> nSA /(subsetP nSA); apply: reindex_astabs. Qed. End Reindex. End RawAction. Arguments act_inj {aT D rT} to a [x1 x2] : rename. Notation "to ^*" := (set_action to) : action_scope. Arguments orbitP {aT D rT to A x y}. Arguments afixP {aT D rT to A x}. Arguments afix1P {aT D rT to a x}. Arguments reindex_astabs [aT D rT] to [vT idx op S] a [F]. Arguments reindex_acts [aT D rT] to [vT idx op S A a F]. Section PartialAction. (* Lemmas that require a (partial) group domain. *) Variables (aT : finGroupType) (D : {group aT}) (rT : finType). Variable to : action D rT. Implicit Types a : aT. Implicit Types x y : rT. Implicit Types A B : {set aT}. Implicit Types G H : {group aT}. Implicit Types S : {set rT}. Lemma act1 x : to x 1 = x. Proof. by apply: (act_inj to 1); rewrite -actMin ?mulg1. Qed. Lemma actKin : {in D, right_loop invg to}. Proof. by move=> a Da /= x; rewrite -actMin ?groupV // mulgV act1. Qed. Lemma actKVin : {in D, rev_right_loop invg to}. Proof. by move=> a Da /= x; rewrite -{2}(invgK a) actKin ?groupV. Qed. Lemma setactVin S a : a \in D -> to^* S a^-1 = to^~ a @^-1: S. Proof. by move=> Da; apply: can2_imset_pre; [apply: actKVin | apply: actKin]. Qed. Lemma actXin x a i : a \in D -> to x (a ^+ i) = iter i (to^~ a) x. Proof. move=> Da; elim: i => /= [|i <-]; first by rewrite act1. by rewrite expgSr actMin ?groupX. Qed. Lemma afix1 : 'Fix_to(1) = setT. Proof. by apply/setP=> x; rewrite !inE sub1set inE act1 eqxx. Qed. Lemma afixD1 G : 'Fix_to(G^#) = 'Fix_to(G). Proof. by rewrite -{2}(setD1K (group1 G)) afixU afix1 setTI. Qed. Lemma orbit_refl G x : x \in orbit to G x. Proof. by rewrite -{1}[x]act1 mem_orbit. Qed. Local Notation orbit_rel A := (fun x y => x \in orbit to A y). Lemma contra_orbit G x y : x \notin orbit to G y -> x != y. Proof. by apply: contraNneq => ->; apply: orbit_refl. Qed. Lemma orbit_in_sym G : G \subset D -> symmetric (orbit_rel G). Proof. move=> sGD; apply: symmetric_from_pre => x y /imsetP[a Ga]. by move/(canLR (actKin (subsetP sGD a Ga))) <-; rewrite mem_orbit ?groupV. Qed. Lemma orbit_in_trans G : G \subset D -> transitive (orbit_rel G). Proof. move=> sGD _ _ z /imsetP[a Ga ->] /imsetP[b Gb ->]. by rewrite -actMin ?mem_orbit ?groupM // (subsetP sGD). Qed. Lemma orbit_in_eqP G x y : G \subset D -> reflect (orbit to G x = orbit to G y) (x \in orbit to G y). Proof. move=> sGD; apply: (iffP idP) => [yGx|<-]; last exact: orbit_refl. by apply/setP=> z; apply/idP/idP=> /orbit_in_trans-> //; rewrite orbit_in_sym. Qed. Lemma orbit_in_transl G x y z : G \subset D -> y \in orbit to G x -> (y \in orbit to G z) = (x \in orbit to G z). Proof. by move=> sGD Gxy; rewrite !(orbit_in_sym sGD _ z) (orbit_in_eqP y x sGD Gxy). Qed. Lemma orbit_act_in x a G : G \subset D -> a \in G -> orbit to G (to x a) = orbit to G x. Proof. by move=> sGD /mem_orbit/orbit_in_eqP->. Qed. Lemma orbit_actr_in x a G y : G \subset D -> a \in G -> (to y a \in orbit to G x) = (y \in orbit to G x). Proof. by move=> sGD /mem_orbit/orbit_in_transl->. Qed. Lemma orbit_inv_in A x y : A \subset D -> (y \in orbit to A^-1 x) = (x \in orbit to A y). Proof. move/subsetP=> sAD; apply/imsetP/imsetP=> [] [a Aa ->]. by exists a^-1; rewrite -?mem_invg ?actKin // -groupV sAD -?mem_invg. by exists a^-1; rewrite ?memV_invg ?actKin // sAD. Qed. Lemma orbit_lcoset_in A a x : A \subset D -> a \in D -> orbit to (a *: A) x = orbit to A (to x a). Proof. move/subsetP=> sAD Da; apply/setP=> y; apply/imsetP/imsetP=> [] [b Ab ->{y}]. by exists (a^-1 * b); rewrite -?actMin ?mulKVg // ?sAD -?mem_lcoset. by exists (a * b); rewrite ?mem_mulg ?set11 ?actMin // sAD. Qed. Lemma orbit_rcoset_in A a x y : A \subset D -> a \in D -> (to y a \in orbit to (A :* a) x) = (y \in orbit to A x). Proof. move=> sAD Da; rewrite -orbit_inv_in ?mul_subG ?sub1set // invMg. by rewrite invg_set1 orbit_lcoset_in ?inv_subG ?groupV ?actKin ?orbit_inv_in. Qed. Lemma orbit_conjsg_in A a x y : A \subset D -> a \in D -> (to y a \in orbit to (A :^ a) (to x a)) = (y \in orbit to A x). Proof. move=> sAD Da; rewrite conjsgE. by rewrite orbit_lcoset_in ?groupV ?mul_subG ?sub1set ?actKin ?orbit_rcoset_in. Qed. Lemma orbit1P G x : reflect (orbit to G x = [set x]) (x \in 'Fix_to(G)). Proof. apply: (iffP afixP) => [xfix | xfix a Ga]. apply/eqP; rewrite eq_sym eqEsubset sub1set -{1}[x]act1 imset_f //=. by apply/subsetP=> y; case/imsetP=> a Ga ->; rewrite inE xfix. by apply/set1P; rewrite -xfix imset_f. Qed. Lemma card_orbit1 G x : #|orbit to G x| = 1%N -> orbit to G x = [set x]. Proof. move=> orb1; apply/eqP; rewrite eq_sym eqEcard {}orb1 cards1. by rewrite sub1set orbit_refl. Qed. Lemma orbit_partition G S : [acts G, on S | to] -> partition (orbit to G @: S) S. Proof. move=> actsGS; have sGD := acts_dom actsGS. have eqiG: {in S & &, equivalence_rel [rel x y | y \in orbit to G x]}. by move=> x y z * /=; rewrite orbit_refl; split=> // /orbit_in_eqP->. congr (partition _ _): (equivalence_partitionP eqiG). apply: eq_in_imset => x Sx; apply/setP=> y. by rewrite inE /= andb_idl // => /acts_in_orbit->. Qed. Definition orbit_transversal A S := transversal (orbit to A @: S) S. Lemma orbit_transversalP G S (P := orbit to G @: S) (X := orbit_transversal G S) : [acts G, on S | to] -> [/\ is_transversal X P S, X \subset S, {in X &, forall x y, (y \in orbit to G x) = (x == y)} & forall x, x \in S -> exists2 a, a \in G & to x a \in X]. Proof. move/orbit_partition; rewrite -/P => partP. have [/eqP defS tiP _] := and3P partP. have trXP: is_transversal X P S := transversalP partP. have sXS: X \subset S := transversal_sub trXP. split=> // [x y Xx Xy /= | x Sx]. have Sx := subsetP sXS x Xx. rewrite -(inj_in_eq (pblock_inj trXP)) // eq_pblock ?defS //. by rewrite (def_pblock tiP (imset_f _ Sx)) ?orbit_refl. have /imsetP[y Xy defxG]: orbit to G x \in pblock P @: X. by rewrite (pblock_transversal trXP) ?imset_f. suffices /orbitP[a Ga def_y]: y \in orbit to G x by exists a; rewrite ?def_y. by rewrite defxG mem_pblock defS (subsetP sXS). Qed. Lemma group_set_astab S : group_set 'C(S | to). Proof. apply/group_setP; split=> [|a b cSa cSb]. by rewrite !inE group1; apply/subsetP=> x _; rewrite inE act1. rewrite !inE groupM ?(@astab_dom _ _ _ to S) //; apply/subsetP=> x Sx. by rewrite inE actMin ?(@astab_dom _ _ _ to S) ?(astab_act _ Sx). Qed. Canonical astab_group S := group (group_set_astab S). Lemma afix_gen_in A : A \subset D -> 'Fix_to(<<A>>) = 'Fix_to(A). Proof. move=> sAD; apply/eqP; rewrite eqEsubset afixS ?sub_gen //=. by rewrite -astabCin gen_subG ?astabCin. Qed. Lemma afix_cycle_in a : a \in D -> 'Fix_to(<[a]>) = 'Fix_to[a]. Proof. by move=> Da; rewrite afix_gen_in ?sub1set. Qed. Lemma afixYin A B : A \subset D -> B \subset D -> 'Fix_to(A <*> B) = 'Fix_to(A) :&: 'Fix_to(B). Proof. by move=> sAD sBD; rewrite afix_gen_in ?afixU // subUset sAD. Qed. Lemma afixMin G H : G \subset D -> H \subset D -> 'Fix_to(G * H) = 'Fix_to(G) :&: 'Fix_to(H). Proof. by move=> sGD sHD; rewrite -afix_gen_in ?mul_subG // genM_join afixYin. Qed. Lemma sub_astab1_in A x : A \subset D -> (A \subset 'C[x | to]) = (x \in 'Fix_to(A)). Proof. by move=> sAD; rewrite astabCin ?sub1set. Qed. Lemma group_set_astabs S : group_set 'N(S | to). Proof. apply/group_setP; split=> [|a b cSa cSb]. by rewrite !inE group1; apply/subsetP=> x Sx; rewrite inE act1. rewrite !inE groupM ?(@astabs_dom _ _ _ to S) //; apply/subsetP=> x Sx. by rewrite inE actMin ?(@astabs_dom _ _ _ to S) ?astabs_act. Qed. Canonical astabs_group S := group (group_set_astabs S). Lemma astab_norm S : 'N(S | to) \subset 'N('C(S | to)). Proof. apply/subsetP=> a nSa; rewrite inE sub_conjg; apply/subsetP=> b cSb. have [Da Db] := (astabs_dom nSa, astab_dom cSb). rewrite mem_conjgV !inE groupJ //; apply/subsetP=> x Sx. rewrite inE !actMin ?groupM ?groupV //. by rewrite (astab_act cSb) ?actKVin ?astabs_act ?groupV. Qed. Lemma astab_normal S : 'C(S | to) <| 'N(S | to). Proof. by rewrite /normal astab_sub astab_norm. Qed. Lemma acts_sub_orbit G S x : [acts G, on S | to] -> (orbit to G x \subset S) = (x \in S). Proof. move/acts_act=> GactS. apply/subsetP/idP=> [| Sx y]; first by apply; apply: orbit_refl. by case/orbitP=> a Ga <-{y}; rewrite GactS. Qed. Lemma acts_orbit G x : G \subset D -> [acts G, on orbit to G x | to]. Proof. move/subsetP=> sGD; apply/subsetP=> a Ga; rewrite !inE sGD //. apply/subsetP=> _ /imsetP[b Gb ->]. by rewrite inE -actMin ?sGD // imset_f ?groupM. Qed. Lemma acts_subnorm_fix A : [acts 'N_D(A), on 'Fix_to(D :&: A) | to]. Proof. apply/subsetP=> a nAa; have [Da _] := setIP nAa; rewrite !inE Da. apply/subsetP=> x Cx /[1!inE]; apply/afixP=> b DAb. have [Db _]:= setIP DAb; rewrite -actMin // conjgCV actMin ?groupJ ?groupV //. by rewrite /= (afixP Cx) // memJ_norm // groupV (subsetP (normsGI _ _) _ nAa). Qed. Lemma atrans_orbit G x : [transitive G, on orbit to G x | to]. Proof. by apply: imset_f; apply: orbit_refl. Qed. Section OrbitStabilizer. Variables (G : {group aT}) (x : rT). Hypothesis sGD : G \subset D. Let ssGD := subsetP sGD. Lemma amove_act a : a \in G -> amove to G x (to x a) = 'C_G[x | to] :* a. Proof. move=> Ga; apply/setP=> b; have Da := ssGD Ga. rewrite mem_rcoset !(inE, sub1set) !groupMr ?groupV //. by case Gb: (b \in G); rewrite //= actMin ?groupV ?ssGD ?(canF_eq (actKVin Da)). Qed. Lemma amove_orbit : amove to G x @: orbit to G x = rcosets 'C_G[x | to] G. Proof. apply/setP => Ha; apply/imsetP/rcosetsP=> [[y] | [a Ga ->]]. by case/imsetP=> b Gb -> ->{Ha y}; exists b => //; rewrite amove_act. by rewrite -amove_act //; exists (to x a); first apply: mem_orbit. Qed. Lemma amoveK : {in orbit to G x, cancel (amove to G x) (fun Ca => to x (repr Ca))}. Proof. move=> _ /orbitP[a Ga <-]; rewrite amove_act //= -[G :&: _]/(gval _). case: repr_rcosetP => b; rewrite !(inE, sub1set)=> /and3P[Gb _ xbx]. by rewrite actMin ?ssGD ?(eqP xbx). Qed. Lemma orbit_stabilizer : orbit to G x = [set to x (repr Ca) | Ca in rcosets 'C_G[x | to] G]. Proof. rewrite -amove_orbit -imset_comp /=; apply/setP=> z. by apply/idP/imsetP=> [xGz | [y xGy ->]]; first exists z; rewrite /= ?amoveK. Qed. Lemma act_reprK : {in rcosets 'C_G[x | to] G, cancel (to x \o repr) (amove to G x)}. Proof. move=> _ /rcosetsP[a Ga ->] /=; rewrite amove_act ?rcoset_repr //. rewrite -[G :&: _]/(gval _); case: repr_rcosetP => b /setIP[Gb _]. exact: groupM. Qed. End OrbitStabilizer. Lemma card_orbit_in G x : G \subset D -> #|orbit to G x| = #|G : 'C_G[x | to]|. Proof. move=> sGD; rewrite orbit_stabilizer 1?card_in_imset //. exact: can_in_inj (act_reprK _). Qed. Lemma card_orbit_in_stab G x : G \subset D -> (#|orbit to G x| * #|'C_G[x | to]|)%N = #|G|. Proof. by move=> sGD; rewrite mulnC card_orbit_in ?Lagrange ?subsetIl. Qed. Lemma acts_sum_card_orbit G S : [acts G, on S | to] -> \sum_(T in orbit to G @: S) #|T| = #|S|. Proof. by move/orbit_partition/card_partition. Qed. Lemma astab_setact_in S a : a \in D -> 'C(to^* S a | to) = 'C(S | to) :^ a. Proof. move=> Da; apply/setP=> b; rewrite mem_conjg !inE -mem_conjg conjGid //. apply: andb_id2l => Db; rewrite sub_imset_pre; apply: eq_subset_r => x. by rewrite !inE !actMin ?groupM ?groupV // invgK (canF_eq (actKVin Da)). Qed. Lemma astab1_act_in x a : a \in D -> 'C[to x a | to] = 'C[x | to] :^ a. Proof. by move=> Da; rewrite -astab_setact_in // /setact imset_set1. Qed. Theorem Frobenius_Cauchy G S : [acts G, on S | to] -> \sum_(a in G) #|'Fix_(S | to)[a]| = (#|orbit to G @: S| * #|G|)%N. Proof. move=> GactS; have sGD := acts_dom GactS. transitivity (\sum_(a in G) \sum_(x in 'Fix_(S | to)[a]) 1%N). by apply: eq_bigr => a _; rewrite -sum1_card. rewrite (exchange_big_dep [in S]) /= => [|a x _]; last by case/setIP. rewrite (set_partition_big _ (orbit_partition GactS)) -sum_nat_const /=. apply: eq_bigr => _ /imsetP[x Sx ->]. rewrite -(card_orbit_in_stab x sGD) -sum_nat_const. apply: eq_bigr => y; rewrite orbit_in_sym // => /imsetP[a Ga defx]. rewrite defx astab1_act_in ?(subsetP sGD) //. rewrite -{2}(conjGid Ga) -conjIg cardJg -sum1_card setIA (setIidPl sGD). by apply: eq_bigl => b; rewrite !(sub1set, inE) -(acts_act GactS Ga) -defx Sx. Qed. Lemma atrans_dvd_index_in G S : G \subset D -> [transitive G, on S | to] -> #|S| %| #|G : 'C_G(S | to)|. Proof. move=> sGD /imsetP[x Sx {1}->]; rewrite card_orbit_in //. by rewrite indexgS // setIS // astabS // sub1set. Qed. Lemma atrans_dvd_in G S : G \subset D -> [transitive G, on S | to] -> #|S| %| #|G|. Proof. move=> sGD transG; apply: dvdn_trans (atrans_dvd_index_in sGD transG) _. exact: dvdn_indexg. Qed. Lemma atransPin G S : G \subset D -> [transitive G, on S | to] -> forall x, x \in S -> orbit to G x = S. Proof. by move=> sGD /imsetP[y _ ->] x; apply/orbit_in_eqP. Qed. Lemma atransP2in G S : G \subset D -> [transitive G, on S | to] -> {in S &, forall x y, exists2 a, a \in G & y = to x a}. Proof. by move=> sGD transG x y /(atransPin sGD transG) <- /imsetP. Qed. Lemma atrans_acts_in G S : G \subset D -> [transitive G, on S | to] -> [acts G, on S | to]. Proof. move=> sGD transG; apply/subsetP=> a Ga; rewrite !inE (subsetP sGD) //. by apply/subsetP=> x /(atransPin sGD transG) <-; rewrite inE imset_f. Qed. Lemma subgroup_transitivePin G H S x : x \in S -> H \subset G -> G \subset D -> [transitive G, on S | to] -> reflect ('C_G[x | to] * H = G) [transitive H, on S | to]. Proof. move=> Sx sHG sGD trG; have sHD := subset_trans sHG sGD. apply: (iffP idP) => [trH | defG]. rewrite group_modr //; apply/setIidPl/subsetP=> a Ga. have Sxa: to x a \in S by rewrite (acts_act (atrans_acts_in sGD trG)). have [b Hb xab]:= atransP2in sHD trH Sxa Sx. have Da := subsetP sGD a Ga; have Db := subsetP sHD b Hb. rewrite -(mulgK b a) mem_mulg ?groupV // !inE groupM //= sub1set inE. by rewrite actMin -?xab. apply/imsetP; exists x => //; apply/setP=> y; rewrite -(atransPin sGD trG Sx). apply/imsetP/imsetP=> [] [a]; last by exists a; first apply: (subsetP sHG). rewrite -defG => /imset2P[c b /setIP[_ cxc] Hb ->] ->. exists b; rewrite ?actMin ?(astab_dom cxc) ?(subsetP sHD) //. by rewrite (astab_act cxc) ?inE. Qed. End PartialAction. Arguments orbit_transversal {aT D%_g rT} to%_act A%_g S%_g. Arguments orbit_in_eqP {aT D rT to G x y}. Arguments orbit1P {aT D rT to G x}. Arguments contra_orbit [aT D rT] to G [x y]. Notation "''C' ( S | to )" := (astab_group to S) : Group_scope. Notation "''C_' A ( S | to )" := (setI_group A 'C(S | to)) : Group_scope. Notation "''C_' ( A ) ( S | to )" := (setI_group A 'C(S | to)) (only parsing) : Group_scope. Notation "''C' [ x | to ]" := (astab_group to [set x%g]) : Group_scope. Notation "''C_' A [ x | to ]" := (setI_group A 'C[x | to]) : Group_scope. Notation "''C_' ( A ) [ x | to ]" := (setI_group A 'C[x | to]) (only parsing) : Group_scope. Notation "''N' ( S | to )" := (astabs_group to S) : Group_scope. Notation "''N_' A ( S | to )" := (setI_group A 'N(S | to)) : Group_scope. Section TotalActions. (* These lemmas are only established for total actions (domain = [set: rT]) *) Variable (aT : finGroupType) (rT : finType). Variable to : {action aT &-> rT}. Implicit Types (a b : aT) (x y z : rT) (A B : {set aT}) (G H : {group aT}). Implicit Type S : {set rT}. Lemma actM x a b : to x (a * b) = to (to x a) b. Proof. by rewrite actMin ?inE. Qed. Lemma actK : right_loop invg to. Proof. by move=> a; apply: actKin; rewrite inE. Qed. Lemma actKV : rev_right_loop invg to. Proof. by move=> a; apply: actKVin; rewrite inE. Qed. Lemma actX x a n : to x (a ^+ n) = iter n (to^~ a) x. Proof. by elim: n => [|n /= <-]; rewrite ?act1 // -actM expgSr. Qed. Lemma actCJ a b x : to (to x a) b = to (to x b) (a ^ b). Proof. by rewrite !actM actK. Qed. Lemma actCJV a b x : to (to x a) b = to (to x (b ^ a^-1)) a. Proof. by rewrite (actCJ _ a) conjgKV. Qed. Lemma orbit_sym G x y : (x \in orbit to G y) = (y \in orbit to G x). Proof. exact/orbit_in_sym/subsetT. Qed. Lemma orbit_trans G x y z : x \in orbit to G y -> y \in orbit to G z -> x \in orbit to G z. Proof. exact/orbit_in_trans/subsetT. Qed. Lemma orbit_eqP G x y : reflect (orbit to G x = orbit to G y) (x \in orbit to G y). Proof. exact/orbit_in_eqP/subsetT. Qed. Lemma orbit_transl G x y z : y \in orbit to G x -> (y \in orbit to G z) = (x \in orbit to G z). Proof. exact/orbit_in_transl/subsetT. Qed. Lemma orbit_act G a x: a \in G -> orbit to G (to x a) = orbit to G x. Proof. exact/orbit_act_in/subsetT. Qed. Lemma orbit_actr G a x y : a \in G -> (to y a \in orbit to G x) = (y \in orbit to G x). Proof. by move/mem_orbit/orbit_transl; apply. Qed. Lemma orbit_eq_mem G x y : (orbit to G x == orbit to G y) = (x \in orbit to G y). Proof. exact: sameP eqP (orbit_eqP G x y). Qed. Lemma orbit_inv A x y : (y \in orbit to A^-1 x) = (x \in orbit to A y). Proof. by rewrite orbit_inv_in ?subsetT. Qed. Lemma orbit_lcoset A a x : orbit to (a *: A) x = orbit to A (to x a). Proof. by rewrite orbit_lcoset_in ?subsetT ?inE. Qed. Lemma orbit_rcoset A a x y : (to y a \in orbit to (A :* a) x) = (y \in orbit to A x). Proof. by rewrite orbit_rcoset_in ?subsetT ?inE. Qed. Lemma orbit_conjsg A a x y : (to y a \in orbit to (A :^ a) (to x a)) = (y \in orbit to A x). Proof. by rewrite orbit_conjsg_in ?subsetT ?inE. Qed. Lemma astabP S a : reflect (forall x, x \in S -> to x a = x) (a \in 'C(S | to)). Proof. apply: (iffP idP) => [cSa x|cSa]; first exact: astab_act. by rewrite !inE; apply/subsetP=> x Sx; rewrite inE cSa. Qed. Lemma astab1P x a : reflect (to x a = x) (a \in 'C[x | to]). Proof. by rewrite !inE sub1set inE; apply: eqP. Qed. Lemma sub_astab1 A x : (A \subset 'C[x | to]) = (x \in 'Fix_to(A)). Proof. by rewrite sub_astab1_in ?subsetT. Qed. Lemma astabC A S : (A \subset 'C(S | to)) = (S \subset 'Fix_to(A)). Proof. by rewrite astabCin ?subsetT. Qed. Lemma afix_cycle a : 'Fix_to(<[a]>) = 'Fix_to[a]. Proof. by rewrite afix_cycle_in ?inE. Qed. Lemma afix_gen A : 'Fix_to(<<A>>) = 'Fix_to(A). Proof. by rewrite afix_gen_in ?subsetT. Qed. Lemma afixM G H : 'Fix_to(G * H) = 'Fix_to(G) :&: 'Fix_to(H). Proof. by rewrite afixMin ?subsetT. Qed. Lemma astabsP S a : reflect (forall x, (to x a \in S) = (x \in S)) (a \in 'N(S | to)). Proof. apply: (iffP idP) => [nSa x|nSa]; first exact: astabs_act. by rewrite !inE; apply/subsetP=> x; rewrite inE nSa. Qed. Lemma card_orbit G x : #|orbit to G x| = #|G : 'C_G[x | to]|. Proof. by rewrite card_orbit_in ?subsetT. Qed. Lemma dvdn_orbit G x : #|orbit to G x| %| #|G|. Proof. by rewrite card_orbit dvdn_indexg. Qed. Lemma card_orbit_stab G x : (#|orbit to G x| * #|'C_G[x | to]|)%N = #|G|. Proof. by rewrite mulnC card_orbit Lagrange ?subsetIl. Qed. Lemma actsP A S : reflect {acts A, on S | to} [acts A, on S | to]. Proof. apply: (iffP idP) => [nSA x|nSA]; first exact: acts_act. by apply/subsetP=> a Aa /[!inE]; apply/subsetP=> x; rewrite inE nSA. Qed. Arguments actsP {A S}. Lemma setact_orbit A x b : to^* (orbit to A x) b = orbit to (A :^ b) (to x b). Proof. apply/setP=> y; apply/idP/idP=> /imsetP[_ /imsetP[a Aa ->] ->{y}]. by rewrite actCJ mem_orbit ?memJ_conjg. by rewrite -actCJ mem_setact ?mem_orbit. Qed. Lemma astab_setact S a : 'C(to^* S a | to) = 'C(S | to) :^ a. Proof. apply/setP=> b; rewrite mem_conjg. apply/astabP/astabP=> stab x => [Sx|]. by rewrite conjgE invgK !actM stab ?actK //; apply/imsetP; exists x. by case/imsetP=> y Sy ->{x}; rewrite -actM conjgCV actM stab. Qed. Lemma astab1_act x a : 'C[to x a | to] = 'C[x | to] :^ a. Proof. by rewrite -astab_setact /setact imset_set1. Qed. Lemma atransP G S : [transitive G, on S | to] -> forall x, x \in S -> orbit to G x = S. Proof. by case/imsetP=> x _ -> y; apply/orbit_eqP. Qed. Lemma atransP2 G S : [transitive G, on S | to] -> {in S &, forall x y, exists2 a, a \in G & y = to x a}. Proof. by move=> GtrS x y /(atransP GtrS) <- /imsetP. Qed. Lemma atrans_acts G S : [transitive G, on S | to] -> [acts G, on S | to]. Proof. move=> GtrS; apply/subsetP=> a Ga; rewrite !inE. by apply/subsetP=> x /(atransP GtrS) <-; rewrite inE imset_f. Qed. Lemma atrans_supgroup G H S : G \subset H -> [transitive G, on S | to] -> [transitive H, on S | to] = [acts H, on S | to]. Proof. move=> sGH trG; apply/idP/idP=> [|actH]; first exact: atrans_acts. case/imsetP: trG => x Sx defS; apply/imsetP; exists x => //. by apply/eqP; rewrite eqEsubset acts_sub_orbit ?Sx // defS imsetS. Qed. Lemma atrans_acts_card G S : [transitive G, on S | to] = [acts G, on S | to] && (#|orbit to G @: S| == 1%N). Proof. apply/idP/andP=> [GtrS | [nSG]]. split; first exact: atrans_acts. rewrite ((_ @: S =P [set S]) _) ?cards1 // eqEsubset sub1set. apply/andP; split=> //; apply/subsetP=> _ /imsetP[x Sx ->]. by rewrite inE (atransP GtrS). rewrite eqn_leq andbC lt0n => /andP[/existsP[X /imsetP[x Sx X_Gx]]]. rewrite (cardD1 X) {X}X_Gx imset_f // ltnS leqn0 => /eqP GtrS. apply/imsetP; exists x => //; apply/eqP. rewrite eqEsubset acts_sub_orbit // Sx andbT. apply/subsetP=> y Sy; have:= card0_eq GtrS (orbit to G y). by rewrite !inE /= imset_f // andbT => /eqP <-; apply: orbit_refl. Qed. Lemma atrans_dvd G S : [transitive G, on S | to] -> #|S| %| #|G|. Proof. by case/imsetP=> x _ ->; apply: dvdn_orbit. Qed. (* This is Aschbacher (5.2) *) Lemma acts_fix_norm A B : A \subset 'N(B) -> [acts A, on 'Fix_to(B) | to]. Proof. move=> nAB; have:= acts_subnorm_fix to B; rewrite !setTI. exact: subset_trans. Qed. Lemma faithfulP A S : reflect (forall a, a \in A -> {in S, to^~ a =1 id} -> a = 1) [faithful A, on S | to]. Proof. apply: (iffP subsetP) => [Cto1 a Aa Ca | Cto1 a]. by apply/set1P; rewrite Cto1 // inE Aa; apply/astabP. by case/setIP=> Aa /astabP Ca; apply/set1P; apply: Cto1. Qed. (* This is the first part of Aschbacher (5.7) *) Lemma astab_trans_gcore G S u : [transitive G, on S | to] -> u \in S -> 'C(S | to) = gcore 'C[u | to] G. Proof. move=> transG Su; apply/eqP; rewrite eqEsubset. rewrite gcore_max ?astabS ?sub1set //=; last first. exact: subset_trans (atrans_acts transG) (astab_norm _ _). apply/subsetP=> x cSx; apply/astabP=> uy. case/(atransP2 transG Su) => y Gy ->{uy}. by apply/astab1P; rewrite astab1_act (bigcapP cSx). Qed. (* This is Aschbacher (5.20) *) Theorem subgroup_transitiveP G H S x : x \in S -> H \subset G -> [transitive G, on S | to] -> reflect ('C_G[x | to] * H = G) [transitive H, on S | to]. Proof. by move=> Sx sHG; apply: subgroup_transitivePin (subsetT G). Qed. (* This is Aschbacher (5.21) *) Lemma trans_subnorm_fixP x G H S : let C := 'C_G[x | to] in let T := 'Fix_(S | to)(H) in [transitive G, on S | to] -> x \in S -> H \subset C -> reflect ((H :^: G) ::&: C = H :^: C) [transitive 'N_G(H), on T | to]. Proof. move=> C T trGS Sx sHC; have actGS := acts_act (atrans_acts trGS). have:= sHC; rewrite subsetI sub_astab1 => /andP[sHG cHx]. have Tx: x \in T by rewrite inE Sx. apply: (iffP idP) => [trN | trC]. apply/setP=> Ha; apply/setIdP/imsetP=> [[]|[a Ca ->{Ha}]]; last first. by rewrite conj_subG //; case/setIP: Ca => Ga _; rewrite imset_f. case/imsetP=> a Ga ->{Ha}; rewrite subsetI !sub_conjg => /andP[_ sHCa]. have Txa: to x a^-1 \in T. by rewrite inE -sub_astab1 astab1_act actGS ?Sx ?groupV. have [b] := atransP2 trN Tx Txa; case/setIP=> Gb nHb cxba. exists (b * a); last by rewrite conjsgM (normP nHb). by rewrite inE groupM //; apply/astab1P; rewrite actM -cxba actKV. apply/imsetP; exists x => //; apply/setP=> y; apply/idP/idP=> [Ty|]. have [Sy cHy]:= setIP Ty; have [a Ga defy] := atransP2 trGS Sx Sy. have: H :^ a^-1 \in H :^: C. rewrite -trC inE subsetI imset_f 1?conj_subG ?groupV // sub_conjgV. by rewrite -astab1_act -defy sub_astab1. case/imsetP=> b /setIP[Gb /astab1P cxb] defHb. rewrite defy -{1}cxb -actM mem_orbit // inE groupM //. by apply/normP; rewrite conjsgM -defHb conjsgKV. case/imsetP=> a /setIP[Ga nHa] ->{y}. by rewrite inE actGS // Sx (acts_act (acts_fix_norm _) nHa). Qed. End TotalActions. Arguments astabP {aT rT to S a}. Arguments orbit_eqP {aT rT to G x y}. Arguments astab1P {aT rT to x a}. Arguments astabsP {aT rT to S a}. Arguments atransP {aT rT to G S}. Arguments actsP {aT rT to A S}. Arguments faithfulP {aT rT to A S}. Section Restrict. Variables (aT : finGroupType) (D : {set aT}) (rT : Type). Variables (to : action D rT) (A : {set aT}). Definition ract of A \subset D := act to. Variable sAD : A \subset D. Lemma ract_is_action : is_action A (ract sAD). Proof. rewrite /ract; case: to => f [injf fM]. by split=> // x; apply: (sub_in2 (subsetP sAD)). Qed. Canonical raction := Action ract_is_action. Lemma ractE : raction =1 to. Proof. by []. Qed. (* Other properties of raction need rT : finType; we defer them *) (* until after the definition of actperm. *) End Restrict. Notation "to \ sAD" := (raction to sAD) (at level 50) : action_scope. Section ActBy. Variables (aT : finGroupType) (D : {set aT}) (rT : finType). Definition actby_cond (A : {set aT}) R (to : action D rT) : Prop := [acts A, on R | to]. Definition actby A R to of actby_cond A R to := fun x a => if (x \in R) && (a \in A) then to x a else x. Variables (A : {group aT}) (R : {set rT}) (to : action D rT). Hypothesis nRA : actby_cond A R to. Lemma actby_is_action : is_action A (actby nRA). Proof. rewrite /actby; split=> [a x y | x a b Aa Ab /=]; last first. rewrite Aa Ab groupM // !andbT actMin ?(subsetP (acts_dom nRA)) //. by case Rx: (x \in R); rewrite ?(acts_act nRA) ?Rx. case Aa: (a \in A); rewrite ?andbF ?andbT //. case Rx: (x \in R); case Ry: (y \in R) => // eqxy; first exact: act_inj eqxy. by rewrite -eqxy (acts_act nRA Aa) Rx in Ry. by rewrite eqxy (acts_act nRA Aa) Ry in Rx. Qed. Canonical action_by := Action actby_is_action. Local Notation "<[nRA]>" := action_by : action_scope. Lemma actbyE x a : x \in R -> a \in A -> <[nRA]>%act x a = to x a. Proof. by rewrite /= /actby => -> ->. Qed. Lemma afix_actby B : 'Fix_<[nRA]>(B) = ~: R :|: 'Fix_to(A :&: B). Proof. apply/setP=> x; rewrite !inE /= /actby. case: (x \in R); last by apply/subsetP=> a _ /[!inE]. apply/subsetP/subsetP=> [cBx a | cABx a Ba] /[!inE]. by case/andP=> Aa /cBx; rewrite inE Aa. by case: ifP => //= Aa; have:= cABx a; rewrite !inE Aa => ->. Qed. Lemma astab_actby S : 'C(S | <[nRA]>) = 'C_A(R :&: S | to). Proof. apply/setP=> a; rewrite setIA (setIidPl (acts_dom nRA)) !inE. case Aa: (a \in A) => //=; apply/subsetP/subsetP=> cRSa x => [|Sx]. by case/setIP=> Rx /cRSa; rewrite !inE actbyE. by have:= cRSa x; rewrite !inE /= /actby Aa Sx; case: (x \in R) => //; apply. Qed. Lemma astabs_actby S : 'N(S | <[nRA]>) = 'N_A(R :&: S | to). Proof. apply/setP=> a; rewrite setIA (setIidPl (acts_dom nRA)) !inE. case Aa: (a \in A) => //=; apply/subsetP/subsetP=> nRSa x => [|Sx]. by case/setIP=> Rx /nRSa; rewrite !inE actbyE ?(acts_act nRA) ?Rx. have:= nRSa x; rewrite !inE /= /actby Aa Sx ?(acts_act nRA) //. by case: (x \in R) => //; apply. Qed. Lemma acts_actby (B : {set aT}) S : [acts B, on S | <[nRA]>] = (B \subset A) && [acts B, on R :&: S | to]. Proof. by rewrite astabs_actby subsetI. Qed. End ActBy. Notation "<[ nRA ] >" := (action_by nRA) : action_scope. Section SubAction. Variables (aT : finGroupType) (D : {group aT}). Variables (rT : finType) (sP : pred rT) (sT : subFinType sP) (to : action D rT). Implicit Type A : {set aT}. Implicit Type u : sT. Implicit Type S : {set sT}. Definition subact_dom := 'N([set x | sP x] | to). Canonical subact_dom_group := [group of subact_dom]. Implicit Type Na : {a | a \in subact_dom}. Lemma sub_act_proof u Na : sP (to (val u) (val Na)). Proof. by case: Na => a /= /(astabs_act (val u)); rewrite !inE valP. Qed. Definition subact u a := if insub a is Some Na then Sub _ (sub_act_proof u Na) else u. Lemma val_subact u a : val (subact u a) = if a \in subact_dom then to (val u) a else val u. Proof. by rewrite /subact -if_neg; case: insubP => [Na|] -> //=; rewrite SubK => ->. Qed. Lemma subact_is_action : is_action subact_dom subact. Proof. split=> [a u v eq_uv | u a b Na Nb]; apply: val_inj. move/(congr1 val): eq_uv; rewrite !val_subact. by case: (a \in _); first move/act_inj. have Da := astabs_dom Na; have Db := astabs_dom Nb. by rewrite !val_subact Na Nb groupM ?actMin. Qed. Canonical subaction := Action subact_is_action. Lemma astab_subact S : 'C(S | subaction) = subact_dom :&: 'C(val @: S | to). Proof. apply/setP=> a; rewrite inE in_setI; apply: andb_id2l => sDa. have [Da _] := setIP sDa; rewrite !inE Da. apply/subsetP/subsetP=> [cSa _ /imsetP[x Sx ->] | cSa x Sx] /[!inE]. by have:= cSa x Sx; rewrite inE -val_eqE val_subact sDa. by have:= cSa _ (imset_f val Sx); rewrite inE -val_eqE val_subact sDa. Qed. Lemma astabs_subact S : 'N(S | subaction) = subact_dom :&: 'N(val @: S | to). Proof. apply/setP=> a; rewrite inE in_setI; apply: andb_id2l => sDa. have [Da _] := setIP sDa; rewrite !inE Da. apply/subsetP/subsetP=> [nSa _ /imsetP[x Sx ->] | nSa x Sx] /[!inE]. by have /[1!inE]/(imset_f val) := nSa x Sx; rewrite val_subact sDa. have /[1!inE]/imsetP[y Sy def_y] := nSa _ (imset_f val Sx). by rewrite ((_ a =P y) _) // -val_eqE val_subact sDa def_y. Qed. Lemma afix_subact A : A \subset subact_dom -> 'Fix_subaction(A) = val @^-1: 'Fix_to(A). Proof. move/subsetP=> sAD; apply/setP=> u. rewrite !inE !(sameP setIidPl eqP); congr (_ == A). apply/setP=> a /[!inE]; apply: andb_id2l => Aa. by rewrite -val_eqE val_subact sAD. Qed. End SubAction. Notation "to ^?" := (subaction _ to) (format "to ^?") : action_scope. Section QuotientAction. Variables (aT : finGroupType) (D : {group aT}) (rT : finGroupType). Variables (to : action D rT) (H : {group rT}). Definition qact_dom := 'N(rcosets H 'N(H) | to^*). Canonical qact_dom_group := [group of qact_dom]. Local Notation subdom := (subact_dom (coset_range H) to^*). Fact qact_subdomE : subdom = qact_dom. Proof. by congr 'N(_|_); apply/setP=> Hx; rewrite !inE genGid. Qed. Lemma qact_proof : qact_dom \subset subdom. Proof. by rewrite qact_subdomE. Qed. Definition qact : coset_of H -> aT -> coset_of H := act (to^*^? \ qact_proof). Canonical quotient_action := [action of qact]. Lemma acts_qact_dom : [acts qact_dom, on 'N(H) | to]. Proof. apply/subsetP=> a nNa; rewrite !inE (astabs_dom nNa); apply/subsetP=> x Nx. have: H :* x \in rcosets H 'N(H) by rewrite -rcosetE imset_f. rewrite inE -(astabs_act _ nNa) => /rcosetsP[y Ny defHy]. have: to x a \in H :* y by rewrite -defHy (imset_f (to^~a)) ?rcoset_refl. by apply: subsetP; rewrite mul_subG ?sub1set ?normG. Qed. Lemma qactEcond x a : x \in 'N(H) -> quotient_action (coset H x) a = coset H (if a \in qact_dom then to x a else x). Proof. move=> Nx; apply: val_inj; rewrite val_subact //= qact_subdomE. have: H :* x \in rcosets H 'N(H) by rewrite -rcosetE imset_f. case nNa: (a \in _); rewrite // -(astabs_act _ nNa). rewrite !val_coset ?(acts_act acts_qact_dom nNa) //=. case/rcosetsP=> y Ny defHy; rewrite defHy; apply: rcoset_eqP. by rewrite rcoset_sym -defHy (imset_f (_^~_)) ?rcoset_refl. Qed. Lemma qactE x a : x \in 'N(H) -> a \in qact_dom -> quotient_action (coset H x) a = coset H (to x a). Proof. by move=> Nx nNa; rewrite qactEcond ?nNa. Qed. Lemma acts_quotient (A : {set aT}) (B : {set rT}) : A \subset 'N_qact_dom(B | to) -> [acts A, on B / H | quotient_action]. Proof. move=> nBA; apply: subset_trans {A}nBA _; apply/subsetP=> a /setIP[dHa nBa]. rewrite inE dHa inE; apply/subsetP=> _ /morphimP[x nHx Bx ->]. rewrite inE /= qactE //. by rewrite mem_morphim ?(acts_act acts_qact_dom) ?(astabs_act _ nBa). Qed. Lemma astabs_quotient (G : {group rT}) : H <| G -> 'N(G / H | quotient_action) = 'N_qact_dom(G | to). Proof. move=> nsHG; have [_ nHG] := andP nsHG. apply/eqP; rewrite eqEsubset acts_quotient // andbT. apply/subsetP=> a nGa; have dHa := astabs_dom nGa; have [Da _]:= setIdP dHa. rewrite inE dHa 2!inE Da; apply/subsetP=> x Gx; have nHx := subsetP nHG x Gx. rewrite -(quotientGK nsHG) 2!inE (acts_act acts_qact_dom) ?nHx //= inE. by rewrite -qactE // (astabs_act _ nGa) mem_morphim. Qed. End QuotientAction. Notation "to / H" := (quotient_action to H) : action_scope. Section ModAction. Variables (aT : finGroupType) (D : {group aT}) (rT : finType). Variable to : action D rT. Implicit Types (G : {group aT}) (S : {set rT}). Section GenericMod. Variable H : {group aT}. Local Notation dom := 'N_D(H). Local Notation range := 'Fix_to(D :&: H). Let acts_dom : {acts dom, on range | to} := acts_act (acts_subnorm_fix to H). Definition modact x (Ha : coset_of H) := if x \in range then to x (repr (D :&: Ha)) else x. Lemma modactEcond x a : a \in dom -> modact x (coset H a) = (if x \in range then to x a else x). Proof. case/setIP=> Da Na; case: ifP => Cx; rewrite /modact Cx //. rewrite val_coset // -group_modr ?sub1set //. case: (repr _) / (repr_rcosetP (D :&: H) a) => a' Ha'. by rewrite actMin ?(afixP Cx _ Ha') //; case/setIP: Ha'. Qed. Lemma modactE x a : a \in D -> a \in 'N(H) -> x \in range -> modact x (coset H a) = to x a. Proof. by move=> Da Na Rx; rewrite modactEcond ?Rx // inE Da. Qed. Lemma modact_is_action : is_action (D / H) modact. Proof. split=> [Ha x y | x Ha Hb]; last first. case/morphimP=> a Na Da ->{Ha}; case/morphimP=> b Nb Db ->{Hb}. rewrite -morphM //= !modactEcond // ?groupM ?(introT setIP _) //. by case: ifP => Cx; rewrite ?(acts_dom, Cx, actMin, introT setIP _). case: (set_0Vmem (D :&: Ha)) => [Da0 | [a /setIP[Da NHa]]]. by rewrite /modact Da0 repr_set0 !act1 !if_same. have Na := subsetP (coset_norm _) _ NHa. have NDa: a \in 'N_D(H) by rewrite inE Da. rewrite -(coset_mem NHa) !modactEcond //. do 2![case: ifP]=> Cy Cx // eqxy; first exact: act_inj eqxy. by rewrite -eqxy acts_dom ?Cx in Cy. by rewrite eqxy acts_dom ?Cy in Cx. Qed. Canonical mod_action := Action modact_is_action. Section Stabilizers. Variable S : {set rT}. Hypothesis cSH : H \subset 'C(S | to). Let fixSH : S \subset 'Fix_to(D :&: H). Proof. by rewrite -astabCin ?subsetIl // subIset ?cSH ?orbT. Qed. Lemma astabs_mod : 'N(S | mod_action) = 'N(S | to) / H. Proof. apply/setP=> Ha; apply/idP/morphimP=> [nSa | [a nHa nSa ->]]. case/morphimP: (astabs_dom nSa) => a nHa Da defHa. exists a => //; rewrite !inE Da; apply/subsetP=> x Sx; rewrite !inE. by have:= Sx; rewrite -(astabs_act x nSa) defHa /= modactE ?(subsetP fixSH). have Da := astabs_dom nSa; rewrite !inE mem_quotient //; apply/subsetP=> x Sx. by rewrite !inE /= modactE ?(astabs_act x nSa) ?(subsetP fixSH). Qed. Lemma astab_mod : 'C(S | mod_action) = 'C(S | to) / H. Proof. apply/setP=> Ha; apply/idP/morphimP=> [cSa | [a nHa cSa ->]]. case/morphimP: (astab_dom cSa) => a nHa Da defHa. exists a => //; rewrite !inE Da; apply/subsetP=> x Sx; rewrite !inE. by rewrite -{2}[x](astab_act cSa) // defHa /= modactE ?(subsetP fixSH). have Da := astab_dom cSa; rewrite !inE mem_quotient //; apply/subsetP=> x Sx. by rewrite !inE /= modactE ?(astab_act cSa) ?(subsetP fixSH). Qed. End Stabilizers. Lemma afix_mod G S : H \subset 'C(S | to) -> G \subset 'N_D(H) -> 'Fix_(S | mod_action)(G / H) = 'Fix_(S | to)(G). Proof. move=> cSH /subsetIP[sGD nHG]. apply/eqP; rewrite eqEsubset !subsetI !subsetIl /= -!astabCin ?quotientS //. have cfixH F: H \subset 'C(S :&: F | to). by rewrite (subset_trans cSH) // astabS ?subsetIl. rewrite andbC astab_mod ?quotientS //=; last by rewrite astabCin ?subsetIr. by rewrite -(quotientSGK nHG) //= -astab_mod // astabCin ?quotientS ?subsetIr. Qed. End GenericMod. Lemma modact_faithful G S : [faithful G / 'C_G(S | to), on S | mod_action 'C_G(S | to)]. Proof. rewrite /faithful astab_mod ?subsetIr //=. by rewrite -quotientIG ?subsetIr ?trivg_quotient. Qed. End ModAction. Notation "to %% H" := (mod_action to H) : action_scope. Section ActPerm. (* Morphism to permutations induced by an action. *) Variables (aT : finGroupType) (D : {set aT}) (rT : finType). Variable to : action D rT. Definition actperm a := perm (act_inj to a). Lemma actpermM : {in D &, {morph actperm : a b / a * b}}. Proof. by move=> a b Da Db; apply/permP=> x; rewrite permM !permE actMin. Qed. Canonical actperm_morphism := Morphism actpermM. Lemma actpermE a x : actperm a x = to x a. Proof. by rewrite permE. Qed. Lemma actpermK x a : aperm x (actperm a) = to x a. Proof. exact: actpermE. Qed. Lemma ker_actperm : 'ker actperm = 'C(setT | to). Proof. congr (_ :&: _); apply/setP=> a /[!inE]/=. apply/eqP/subsetP=> [a1 x _ | a1]; first by rewrite inE -actpermE a1 perm1. by apply/permP=> x; apply/eqP; have:= a1 x; rewrite !inE actpermE perm1 => ->. Qed. End ActPerm. Section RestrictActionTheory. Variables (aT : finGroupType) (D : {set aT}) (rT : finType). Variables (to : action D rT). Lemma faithful_isom (A : {group aT}) S (nSA : actby_cond A S to) : [faithful A, on S | to] -> isom A (actperm <[nSA]> @* A) (actperm <[nSA]>). Proof. by move=> ffulAS; apply/isomP; rewrite ker_actperm astab_actby setIT. Qed. Variables (A : {set aT}) (sAD : A \subset D). Lemma ractpermE : actperm (to \ sAD) =1 actperm to. Proof. by move=> a; apply/permP=> x; rewrite !permE. Qed. Lemma afix_ract B : 'Fix_(to \ sAD)(B) = 'Fix_to(B). Proof. by []. Qed. Lemma astab_ract S : 'C(S | to \ sAD) = 'C_A(S | to). Proof. by rewrite setIA (setIidPl sAD). Qed. Lemma astabs_ract S : 'N(S | to \ sAD) = 'N_A(S | to). Proof. by rewrite setIA (setIidPl sAD). Qed. Lemma acts_ract (B : {set aT}) S : [acts B, on S | to \ sAD] = (B \subset A) && [acts B, on S | to]. Proof. by rewrite astabs_ract subsetI. Qed. End RestrictActionTheory. Section MorphAct. (* Action induced by a morphism to permutations. *) Variables (aT : finGroupType) (D : {group aT}) (rT : finType). Variable phi : {morphism D >-> {perm rT}}. Definition mact x a := phi a x. Lemma mact_is_action : is_action D mact. Proof. split=> [a x y | x a b Da Db]; first exact: perm_inj. by rewrite /mact morphM //= permM. Qed. Canonical morph_action := Action mact_is_action. Lemma mactE x a : morph_action x a = phi a x. Proof. by []. Qed. Lemma injm_faithful : 'injm phi -> [faithful D, on setT | morph_action]. Proof. move/injmP=> phi_inj; apply/subsetP=> a /setIP[Da /astab_act a1]. apply/set1P/phi_inj => //; apply/permP=> x. by rewrite morph1 perm1 -mactE a1 ?inE. Qed. Lemma perm_mact a : actperm morph_action a = phi a. Proof. by apply/permP=> x; rewrite permE. Qed. End MorphAct. Notation "<< phi >>" := (morph_action phi) : action_scope. Section CompAct. Variables (gT aT : finGroupType) (rT : finType). Variables (D : {set aT}) (to : action D rT). Variables (B : {set gT}) (f : {morphism B >-> aT}). Definition comp_act x e := to x (f e). Lemma comp_is_action : is_action (f @*^-1 D) comp_act. Proof. split=> [e | x e1 e2]; first exact: act_inj. move=> /morphpreP[Be1 Dfe1] /morphpreP[Be2 Dfe2]. by rewrite /comp_act morphM ?actMin. Qed. Canonical comp_action := Action comp_is_action. Lemma comp_actE x e : comp_action x e = to x (f e). Proof. by []. Qed. Lemma afix_comp (A : {set gT}) : A \subset B -> 'Fix_comp_action(A) = 'Fix_to(f @* A). Proof. move=> sAB; apply/setP=> x; rewrite !inE /morphim (setIidPr sAB). apply/subsetP/subsetP; first by move=> + _ /imsetP[a + ->] => /[apply]/[!inE]. by move=> + a Aa => /(_ (f a)); rewrite !inE imset_f// => ->. Qed. Lemma astab_comp S : 'C(S | comp_action) = f @*^-1 'C(S | to). Proof. by apply/setP=> x; rewrite !inE -andbA. Qed. Lemma astabs_comp S : 'N(S | comp_action) = f @*^-1 'N(S | to). Proof. by apply/setP=> x; rewrite !inE -andbA. Qed. End CompAct. Notation "to \o f" := (comp_action to f) : action_scope. Section PermAction. (* Natural action of permutation groups. *) Variable rT : finType. Local Notation gT := {perm rT}. Implicit Types a b c : gT. Lemma aperm_is_action : is_action setT (@aperm rT). Proof. by apply: is_total_action => [x|x a b]; rewrite apermE (perm1, permM). Qed. Canonical perm_action := Action aperm_is_action. Lemma porbitE a : porbit a = orbit perm_action <[a]>%g. Proof. by rewrite unlock. Qed. Lemma perm_act1P a : reflect (forall x, aperm x a = x) (a == 1). Proof. apply: (iffP eqP) => [-> x | a1]; first exact: act1. by apply/permP=> x; rewrite -apermE a1 perm1. Qed. Lemma perm_faithful A : [faithful A, on setT | perm_action]. Proof. apply/subsetP=> a /setIP[Da crTa]. by apply/set1P; apply/permP=> x; rewrite -apermE perm1 (astabP crTa) ?inE. Qed. Lemma actperm_id p : actperm perm_action p = p. Proof. by apply/permP=> x; rewrite permE. Qed. End PermAction. Arguments perm_act1P {rT a}. Notation "'P" := (perm_action _) : action_scope. Section ActpermOrbits. Variables (aT : finGroupType) (D : {group aT}) (rT : finType). Variable to : action D rT. Lemma orbit_morphim_actperm (A : {set aT}) : A \subset D -> orbit 'P (actperm to @* A) =1 orbit to A. Proof. move=> sAD x; rewrite morphimEsub // /orbit -imset_comp. by apply: eq_imset => a //=; rewrite actpermK. Qed. Lemma porbit_actperm (a : aT) : a \in D -> porbit (actperm to a) =1 orbit to <[a]>. Proof. move=> Da x. by rewrite porbitE -orbit_morphim_actperm ?cycle_subG ?morphim_cycle. Qed. End ActpermOrbits. Section RestrictPerm. Variables (T : finType) (S : {set T}). Definition restr_perm := actperm (<[subxx 'N(S | 'P)]>). Canonical restr_perm_morphism := [morphism of restr_perm]. Lemma restr_perm_on p : perm_on S (restr_perm p). Proof. apply/subsetP=> x; apply: contraR => notSx. by rewrite permE /= /actby (negPf notSx). Qed. Lemma triv_restr_perm p : p \notin 'N(S | 'P) -> restr_perm p = 1. Proof. move=> not_nSp; apply/permP=> x. by rewrite !permE /= /actby (negPf not_nSp) andbF. Qed. Lemma restr_permE : {in 'N(S | 'P) & S, forall p, restr_perm p =1 p}. Proof. by move=> y x nSp Sx; rewrite /= actpermE actbyE. Qed. Lemma ker_restr_perm : 'ker restr_perm = 'C(S | 'P). Proof. by rewrite ker_actperm astab_actby setIT (setIidPr (astab_sub _ _)). Qed. Lemma im_restr_perm p : restr_perm p @: S = S. Proof. exact: im_perm_on (restr_perm_on p). Qed. Lemma restr_perm_commute s : commute (restr_perm s) s. Proof. have [sC|/triv_restr_perm->] := boolP (s \in 'N(S | 'P)); last first. exact: (commute_sym (commute1 _)). apply/permP => x; have /= xsS := astabsP sC x; rewrite !permM. have [xS|xNS] := boolP (x \in S); first by rewrite ?(restr_permE) ?xsS. by rewrite !(out_perm (restr_perm_on _)) ?xsS. Qed. End RestrictPerm. Section Symmetry. Variables (T : finType) (S : {set T}). Lemma SymE : Sym S = 'C(~: S | 'P). Proof. apply/setP => s; rewrite inE; apply/idP/astabP => [sS x|/= S_id]. by rewrite inE /= apermE => /out_perm->. by apply/subsetP => x; move=> /(contra_neqN (S_id _)); rewrite inE negbK. Qed. End Symmetry. Section AutIn. Variable gT : finGroupType. Definition Aut_in A (B : {set gT}) := 'N_A(B | 'P) / 'C_A(B | 'P). Variables G H : {group gT}. Hypothesis sHG: H \subset G. Lemma Aut_restr_perm a : a \in Aut G -> restr_perm H a \in Aut H. Proof. move=> AutGa. case nHa: (a \in 'N(H | 'P)); last by rewrite triv_restr_perm ?nHa ?group1. rewrite inE restr_perm_on; apply/morphicP=> x y Hx Hy /=. by rewrite !restr_permE ?groupM // -(autmE AutGa) morphM ?(subsetP sHG). Qed. Lemma restr_perm_Aut : restr_perm H @* Aut G \subset Aut H. Proof. by apply/subsetP=> a'; case/morphimP=> a _ AutGa ->{a'}; apply: Aut_restr_perm. Qed. Lemma Aut_in_isog : Aut_in (Aut G) H \isog restr_perm H @* Aut G. Proof. rewrite /Aut_in -ker_restr_perm kerE -morphpreIdom -morphimIdom -kerE /=. by rewrite setIA (setIC _ (Aut G)) first_isog_loc ?subsetIr. Qed. Lemma Aut_sub_fullP : reflect (forall h : {morphism H >-> gT}, 'injm h -> h @* H = H -> exists g : {morphism G >-> gT}, [/\ 'injm g, g @* G = G & {in H, g =1 h}]) (Aut_in (Aut G) H \isog Aut H). Proof. rewrite (isog_transl _ Aut_in_isog) /=; set rG := _ @* _. apply: (iffP idP) => [iso_rG h injh hH| AutHinG]. have: aut injh hH \in rG; last case/morphimP=> g nHg AutGg def_g. suffices ->: rG = Aut H by apply: Aut_aut. by apply/eqP; rewrite eqEcard restr_perm_Aut /= (card_isog iso_rG). exists (autm_morphism AutGg); rewrite injm_autm im_autm; split=> // x Hx. by rewrite -(autE injh hH Hx) def_g actpermE actbyE. suffices ->: rG = Aut H by apply: isog_refl. apply/eqP; rewrite eqEsubset restr_perm_Aut /=. apply/subsetP=> h AutHh; have hH := im_autm AutHh. have [g [injg gG eq_gh]] := AutHinG _ (injm_autm AutHh) hH. have [Ng AutGg]: aut injg gG \in 'N(H | 'P) /\ aut injg gG \in Aut G. rewrite Aut_aut !inE; split=> //; apply/subsetP=> x Hx. by rewrite inE /= /aperm autE ?(subsetP sHG) // -hH eq_gh ?mem_morphim. apply/morphimP; exists (aut injg gG) => //; apply: (eq_Aut AutHh) => [|x Hx]. by rewrite (subsetP restr_perm_Aut) // mem_morphim. by rewrite restr_permE //= /aperm autE ?eq_gh ?(subsetP sHG). Qed. End AutIn. Arguments Aut_in {gT} A%_g B%_g. Section InjmAutIn. Variables (gT rT : finGroupType) (D G H : {group gT}) (f : {morphism D >-> rT}). Hypotheses (injf : 'injm f) (sGD : G \subset D) (sHG : H \subset G). Let sHD := subset_trans sHG sGD. Local Notation fGisom := (Aut_isom injf sGD). Local Notation fHisom := (Aut_isom injf sHD). Local Notation inH := (restr_perm H). Local Notation infH := (restr_perm (f @* H)). Lemma astabs_Aut_isom a : a \in Aut G -> (fGisom a \in 'N(f @* H | 'P)) = (a \in 'N(H | 'P)). Proof. move=> AutGa; rewrite !inE sub_morphim_pre // subsetI sHD /= /aperm. rewrite !(sameP setIidPl eqP) !eqEsubset !subsetIl; apply: eq_subset_r => x. rewrite !inE; apply: andb_id2l => Hx; have Gx: x \in G := subsetP sHG x Hx. have Dax: a x \in D by rewrite (subsetP sGD) // Aut_closed. by rewrite Aut_isomE // -!sub1set -morphim_set1 // injmSK ?sub1set. Qed. Lemma isom_restr_perm a : a \in Aut G -> fHisom (inH a) = infH (fGisom a). Proof. move=> AutGa; case nHa: (a \in 'N(H | 'P)); last first. by rewrite !triv_restr_perm ?astabs_Aut_isom ?nHa ?morph1. apply: (eq_Aut (Aut_Aut_isom injf sHD _)) => [|fx Hfx /=]. by rewrite (Aut_restr_perm (morphimS f sHG)) ?Aut_Aut_isom. have [x Dx Hx def_fx] := morphimP Hfx; have Gx := subsetP sHG x Hx. rewrite {1}def_fx Aut_isomE ?(Aut_restr_perm sHG) //. by rewrite !restr_permE ?astabs_Aut_isom // def_fx Aut_isomE. Qed. Lemma restr_perm_isom : isom (inH @* Aut G) (infH @* Aut (f @* G)) fHisom. Proof. apply: sub_isom; rewrite ?restr_perm_Aut ?injm_Aut_isom //=. rewrite -(im_Aut_isom injf sGD) -!morphim_comp. apply: eq_in_morphim; last exact: isom_restr_perm. (* TODO: investigate why rewrite does not match in the same order *) apply/setP=> a; rewrite in_setI [in RHS]in_setI; apply: andb_id2r => AutGa. (* the middle rewrite was rewrite 2!in_setI *) rewrite /= inE andbC inE (Aut_restr_perm sHG) //=. by symmetry; rewrite inE AutGa inE astabs_Aut_isom. Qed. Lemma injm_Aut_sub : Aut_in (Aut (f @* G)) (f @* H) \isog Aut_in (Aut G) H. Proof. do 2!rewrite isog_sym (isog_transl _ (Aut_in_isog _ _)). by rewrite isog_sym (isom_isog _ _ restr_perm_isom) // restr_perm_Aut. Qed. Lemma injm_Aut_full : (Aut_in (Aut (f @* G)) (f @* H) \isog Aut (f @* H)) = (Aut_in (Aut G) H \isog Aut H). Proof. by rewrite (isog_transl _ injm_Aut_sub) (isog_transr _ (injm_Aut injf sHD)). Qed. End InjmAutIn. Section GroupAction. Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}). Local Notation actT := (action D rT). Definition is_groupAction (to : actT) := {in D, forall a, actperm to a \in Aut R}. Structure groupAction := GroupAction {gact :> actT; _ : is_groupAction gact}. Definition clone_groupAction to := let: GroupAction _ toA := to return {type of GroupAction for to} -> _ in fun k => k toA : groupAction. End GroupAction. Delimit Scope groupAction_scope with gact. Bind Scope groupAction_scope with groupAction. Arguments is_groupAction {aT rT D%_g} R%_g to%_act. Arguments groupAction {aT rT} D%_g R%_g. Arguments gact {aT rT D%_g R%_g} to%_gact : rename. Notation "[ 'groupAction' 'of' to ]" := (clone_groupAction (@GroupAction _ _ _ _ to)) (format "[ 'groupAction' 'of' to ]") : form_scope. Section GroupActionDefs. Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}). Implicit Type A : {set aT}. Implicit Type S : {set rT}. Implicit Type to : groupAction D R. Definition gact_range of groupAction D R := R. Definition gacent to A := 'Fix_(R | to)(D :&: A). Definition acts_on_group A S to := [acts A, on S | to] /\ S \subset R. Coercion actby_cond_group A S to : acts_on_group A S to -> actby_cond A S to := @proj1 _ _. Definition acts_irreducibly A S to := [min S of G | G :!=: 1 & [acts A, on G | to]]. End GroupActionDefs. Arguments gacent {aT rT D%_g R%_g} to%_gact A%_g. Arguments acts_on_group {aT rT D%_g R%_g} A%_g S%_g to%_gact. Arguments acts_irreducibly {aT rT D%_g R%_g} A%_g S%_g to%_gact. Notation "''C_' ( | to ) ( A )" := (gacent to A) : group_scope. Notation "''C_' ( G | to ) ( A )" := (G :&: 'C_(|to)(A)) : group_scope. Notation "''C_' ( | to ) [ a ]" := 'C_(|to)([set a]) : group_scope. Notation "''C_' ( G | to ) [ a ]" := 'C_(G | to)([set a]) : group_scope. Notation "{ 'acts' A , 'on' 'group' G | to }" := (acts_on_group A G to) (format "{ 'acts' A , 'on' 'group' G | to }") : type_scope. Section RawGroupAction. Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}). Variable to : groupAction D R. Lemma actperm_Aut : is_groupAction R to. Proof. by case: to. Qed. Lemma im_actperm_Aut : actperm to @* D \subset Aut R. Proof. by apply/subsetP=> _ /morphimP[a _ Da ->]; apply: actperm_Aut. Qed. Lemma gact_out x a : a \in D -> x \notin R -> to x a = x. Proof. by move=> Da Rx; rewrite -actpermE (out_Aut _ Rx) ?actperm_Aut. Qed. Lemma gactM : {in D, forall a, {in R &, {morph to^~ a : x y / x * y}}}. Proof. move=> a Da /= x y; rewrite -!(actpermE to); apply: morphicP x y. by rewrite Aut_morphic ?actperm_Aut. Qed. Lemma actmM a : {in R &, {morph actm to a : x y / x * y}}. Proof. by rewrite /actm; case: ifP => //; apply: gactM. Qed. Canonical act_morphism a := Morphism (actmM a). Lemma morphim_actm : {in D, forall a (S : {set rT}), S \subset R -> actm to a @* S = to^* S a}. Proof. by move=> a Da /= S sSR; rewrite /morphim /= actmEfun ?(setIidPr _). Qed. Variables (a : aT) (A B : {set aT}) (S : {set rT}). Lemma gacentIdom : 'C_(|to)(D :&: A) = 'C_(|to)(A). Proof. by rewrite /gacent setIA setIid. Qed. Lemma gacentIim : 'C_(R | to)(A) = 'C_(|to)(A). Proof. by rewrite setIA setIid. Qed. Lemma gacentS : A \subset B -> 'C_(|to)(B) \subset 'C_(|to)(A). Proof. by move=> sAB; rewrite !(setIS, afixS). Qed. Lemma gacentU : 'C_(|to)(A :|: B) = 'C_(|to)(A) :&: 'C_(|to)(B). Proof. by rewrite -setIIr -afixU -setIUr. Qed. Hypotheses (Da : a \in D) (sAD : A \subset D) (sSR : S \subset R). Lemma gacentE : 'C_(|to)(A) = 'Fix_(R | to)(A). Proof. by rewrite -{2}(setIidPr sAD). Qed. Lemma gacent1E : 'C_(|to)[a] = 'Fix_(R | to)[a]. Proof. by rewrite /gacent [D :&: _](setIidPr _) ?sub1set. Qed. Lemma subgacentE : 'C_(S | to)(A) = 'Fix_(S | to)(A). Proof. by rewrite gacentE setIA (setIidPl sSR). Qed. Lemma subgacent1E : 'C_(S | to)[a] = 'Fix_(S | to)[a]. Proof. by rewrite gacent1E setIA (setIidPl sSR). Qed. End RawGroupAction. Section GroupActionTheory. Variables aT rT : finGroupType. Variables (D : {group aT}) (R : {group rT}) (to : groupAction D R). Implicit Type A B : {set aT}. Implicit Types G H : {group aT}. Implicit Type S : {set rT}. Implicit Types M N : {group rT}. Lemma gact1 : {in D, forall a, to 1 a = 1}. Proof. by move=> a Da; rewrite /= -actmE ?morph1. Qed. Lemma gactV : {in D, forall a, {in R, {morph to^~ a : x / x^-1}}}. Proof. by move=> a Da /= x Rx; move; rewrite -!actmE ?morphV. Qed. Lemma gactX : {in D, forall a n, {in R, {morph to^~ a : x / x ^+ n}}}. Proof. by move=> a Da /= n x Rx; rewrite -!actmE // morphX. Qed. Lemma gactJ : {in D, forall a, {in R &, {morph to^~ a : x y / x ^ y}}}. Proof. by move=> a Da /= x Rx y Ry; rewrite -!actmE // morphJ. Qed. Lemma gactR : {in D, forall a, {in R &, {morph to^~ a : x y / [~ x, y]}}}. Proof. by move=> a Da /= x Rx y Ry; rewrite -!actmE // morphR. Qed. Lemma gact_stable : {acts D, on R | to}. Proof. apply: acts_act; apply/subsetP=> a Da; rewrite !inE Da. apply/subsetP=> x; rewrite inE; apply: contraLR => R'xa. by rewrite -(actKin to Da x) gact_out ?groupV. Qed. Lemma group_set_gacent A : group_set 'C_(|to)(A). Proof. apply/group_setP; split=> [|x y]. by rewrite !inE group1; apply/subsetP=> a /setIP[Da _]; rewrite inE gact1. case/setIP=> Rx /afixP cAx /setIP[Ry /afixP cAy]. rewrite inE groupM //; apply/afixP=> a Aa. by rewrite gactM ?cAx ?cAy //; case/setIP: Aa. Qed. Canonical gacent_group A := Group (group_set_gacent A). Lemma gacent1 : 'C_(|to)(1) = R. Proof. by rewrite /gacent (setIidPr (sub1G _)) afix1 setIT. Qed. Lemma gacent_gen A : A \subset D -> 'C_(|to)(<<A>>) = 'C_(|to)(A). Proof. by move=> sAD; rewrite /gacent ![D :&: _](setIidPr _) ?gen_subG ?afix_gen_in. Qed. Lemma gacentD1 A : 'C_(|to)(A^#) = 'C_(|to)(A). Proof. rewrite -gacentIdom -gacent_gen ?subsetIl // setIDA genD1 ?group1 //. by rewrite gacent_gen ?subsetIl // gacentIdom. Qed. Lemma gacent_cycle a : a \in D -> 'C_(|to)(<[a]>) = 'C_(|to)[a]. Proof. by move=> Da; rewrite gacent_gen ?sub1set. Qed. Lemma gacentY A B : A \subset D -> B \subset D -> 'C_(|to)(A <*> B) = 'C_(|to)(A) :&: 'C_(|to)(B). Proof. by move=> sAD sBD; rewrite gacent_gen ?gacentU // subUset sAD. Qed. Lemma gacentM G H : G \subset D -> H \subset D -> 'C_(|to)(G * H) = 'C_(|to)(G) :&: 'C_(|to)(H). Proof. by move=> sGD sHB; rewrite -gacent_gen ?mul_subG // genM_join gacentY. Qed. Lemma astab1 : 'C(1 | to) = D. Proof. by apply/setP=> x; rewrite ?(inE, sub1set) andb_idr //; move/gact1=> ->. Qed. Lemma astab_range : 'C(R | to) = 'C(setT | to). Proof. apply/eqP; rewrite eqEsubset andbC astabS ?subsetT //=. apply/subsetP=> a cRa; have Da := astab_dom cRa; rewrite !inE Da. apply/subsetP=> x; rewrite -(setUCr R) !inE. by case/orP=> ?; [rewrite (astab_act cRa) | rewrite gact_out]. Qed. Lemma gacentC A S : A \subset D -> S \subset R -> (S \subset 'C_(|to)(A)) = (A \subset 'C(S | to)). Proof. by move=> sAD sSR; rewrite subsetI sSR astabCin // (setIidPr sAD). Qed. Lemma astab_gen S : S \subset R -> 'C(<<S>> | to) = 'C(S | to). Proof. move=> sSR; apply/setP=> a; case Da: (a \in D); last by rewrite !inE Da. by rewrite -!sub1set -!gacentC ?sub1set ?gen_subG. Qed. Lemma astabM M N : M \subset R -> N \subset R -> 'C(M * N | to) = 'C(M | to) :&: 'C(N | to). Proof. move=> sMR sNR; rewrite -astabU -astab_gen ?mul_subG // genM_join. by rewrite astab_gen // subUset sMR. Qed. Lemma astabs1 : 'N(1 | to) = D. Proof. by rewrite astabs_set1 astab1. Qed. Lemma astabs_range : 'N(R | to) = D. Proof. apply/setIidPl; apply/subsetP=> a Da; rewrite inE. by apply/subsetP=> x Rx; rewrite inE gact_stable. Qed. Lemma astabsD1 S : 'N(S^# | to) = 'N(S | to). Proof. case S1: (1 \in S); last first. by rewrite (setDidPl _) // disjoint_sym disjoints_subset sub1set inE S1. apply/eqP; rewrite eqEsubset andbC -{1}astabsIdom -{1}astabs1 setIC astabsD /=. by rewrite -{2}(setD1K S1) -astabsIdom -{1}astabs1 astabsU. Qed. Lemma gacts_range A : A \subset D -> {acts A, on group R | to}. Proof. by move=> sAD; split; rewrite ?astabs_range. Qed. Lemma acts_subnorm_gacent A : A \subset D -> [acts 'N_D(A), on 'C_(| to)(A) | to]. Proof. move=> sAD; rewrite gacentE // actsI ?astabs_range ?subsetIl //. by rewrite -{2}(setIidPr sAD) acts_subnorm_fix. Qed. Lemma acts_subnorm_subgacent A B S : A \subset D -> [acts B, on S | to] -> [acts 'N_B(A), on 'C_(S | to)(A) | to]. Proof. move=> sAD actsB; rewrite actsI //; first by rewrite subIset ?actsB. by rewrite (subset_trans _ (acts_subnorm_gacent sAD)) ?setSI ?(acts_dom actsB). Qed. Lemma acts_gen A S : S \subset R -> [acts A, on S | to] -> [acts A, on <<S>> | to]. Proof. move=> sSR actsA; apply: {A}subset_trans actsA _. apply/subsetP=> a nSa; have Da := astabs_dom nSa; rewrite !inE Da. apply: subset_trans (_ : <<S>> \subset actm to a @*^-1 <<S>>) _. rewrite gen_subG subsetI sSR; apply/subsetP=> x Sx. by rewrite inE /= actmE ?mem_gen // astabs_act. by apply/subsetP=> x /[!inE]; case/andP=> Rx; rewrite /= actmE. Qed. Lemma acts_joing A M N : M \subset R -> N \subset R -> [acts A, on M | to] -> [acts A, on N | to] -> [acts A, on M <*> N | to]. Proof. by move=> sMR sNR nMA nNA; rewrite acts_gen ?actsU // subUset sMR. Qed. Lemma injm_actm a : 'injm (actm to a). Proof. apply/injmP=> x y Rx Ry; rewrite /= /actm; case: ifP => Da //. exact: act_inj. Qed. Lemma im_actm a : actm to a @* R = R. Proof. apply/eqP; rewrite eqEcard (card_injm (injm_actm a)) // leqnn andbT. apply/subsetP=> _ /morphimP[x Rx _ ->] /=. by rewrite /actm; case: ifP => // Da; rewrite gact_stable. Qed. Lemma acts_char G M : G \subset D -> M \char R -> [acts G, on M | to]. Proof. move=> sGD /charP[sMR charM]. apply/subsetP=> a Ga; have Da := subsetP sGD a Ga; rewrite !inE Da. apply/subsetP=> x Mx; have Rx := subsetP sMR x Mx. by rewrite inE -(charM _ (injm_actm a) (im_actm a)) -actmE // mem_morphim. Qed. Lemma gacts_char G M : G \subset D -> M \char R -> {acts G, on group M | to}. (* TODO: investigate why rewrite does not match in the same order *) Proof. by move=> sGD charM; split; rewrite ?acts_char// char_sub. Qed. (* was ending with rewrite (acts_char, char_sub)// *) Section Restrict. Variables (A : {group aT}) (sAD : A \subset D). Lemma ract_is_groupAction : is_groupAction R (to \ sAD). Proof. by move=> a Aa /=; rewrite ractpermE actperm_Aut ?(subsetP sAD). Qed. Canonical ract_groupAction := GroupAction ract_is_groupAction. Lemma gacent_ract B : 'C_(|ract_groupAction)(B) = 'C_(|to)(A :&: B). Proof. by rewrite /gacent afix_ract setIA (setIidPr sAD). Qed. End Restrict. Section ActBy. Variables (A : {group aT}) (G : {group rT}) (nGAg : {acts A, on group G | to}). Lemma actby_is_groupAction : is_groupAction G <[nGAg]>. Proof. move=> a Aa; rewrite /= inE; apply/andP; split. apply/subsetP=> x; apply: contraR => Gx. by rewrite actpermE /= /actby (negbTE Gx). apply/morphicP=> x y Gx Gy; rewrite !actpermE /= /actby Aa groupM ?Gx ?Gy //=. by case nGAg; move/acts_dom; do 2!move/subsetP=> ?; rewrite gactM; auto. Qed. Canonical actby_groupAction := GroupAction actby_is_groupAction. Lemma gacent_actby B : 'C_(|actby_groupAction)(B) = 'C_(G | to)(A :&: B). Proof. rewrite /gacent afix_actby !setIA setIid setIUr setICr set0U. by have [nAG sGR] := nGAg; rewrite (setIidPr (acts_dom nAG)) (setIidPl sGR). Qed. End ActBy. Section Quotient. Variable H : {group rT}. Lemma acts_qact_dom_norm : {acts qact_dom to H, on 'N(H) | to}. Proof. move=> a HDa /= x; rewrite {2}(('N(H) =P to^~ a @^-1: 'N(H)) _) ?inE {x}//. rewrite eqEcard (card_preimset _ (act_inj _ _)) leqnn andbT. apply/subsetP=> x Nx; rewrite inE; move/(astabs_act (H :* x)): HDa. rewrite mem_rcosets mulSGid ?normG // Nx => /rcosetsP[y Ny defHy]. suffices: to x a \in H :* y by apply: subsetP; rewrite mul_subG ?sub1set ?normG. by rewrite -defHy; apply: imset_f; apply: rcoset_refl. Qed. Lemma qact_is_groupAction : is_groupAction (R / H) (to / H). Proof. move=> a HDa /=; have Da := astabs_dom HDa. rewrite inE; apply/andP; split. apply/subsetP=> Hx /=; case: (cosetP Hx) => x Nx ->{Hx}. apply: contraR => R'Hx; rewrite actpermE qactE // gact_out //. by apply: contra R'Hx; apply: mem_morphim. apply/morphicP=> Hx Hy; rewrite !actpermE. case/morphimP=> x Nx Gx ->{Hx}; case/morphimP=> y Ny Gy ->{Hy}. by rewrite -morphM ?qactE ?groupM ?gactM // morphM ?acts_qact_dom_norm. Qed. Canonical quotient_groupAction := GroupAction qact_is_groupAction. Lemma qact_domE : H \subset R -> qact_dom to H = 'N(H | to). Proof. move=> sHR; apply/setP=> a; apply/idP/idP=> nHa; have Da := astabs_dom nHa. rewrite !inE Da; apply/subsetP=> x Hx; rewrite inE -(rcoset1 H). have /rcosetsP[y Ny defHy]: to^~ a @: H \in rcosets H 'N(H). by rewrite (astabs_act _ nHa); apply/rcosetsP; exists 1; rewrite ?mulg1. by rewrite (rcoset_eqP (_ : 1 \in H :* y)) -defHy -1?(gact1 Da) mem_setact. rewrite !inE Da; apply/subsetP=> Hx /[1!inE] /rcosetsP[x Nx ->{Hx}]. apply/imsetP; exists (to x a). case Rx: (x \in R); last by rewrite gact_out ?Rx. rewrite inE; apply/subsetP=> _ /imsetP[y Hy ->]. rewrite -(actKVin to Da y) -gactJ // ?(subsetP sHR, astabs_act, groupV) //. by rewrite memJ_norm // astabs_act ?groupV. apply/eqP; rewrite rcosetE eqEcard. rewrite (card_imset _ (act_inj _ _)) !card_rcoset leqnn andbT. apply/subsetP=> _ /imsetP[y Hxy ->]; rewrite !mem_rcoset in Hxy *. have Rxy := subsetP sHR _ Hxy; rewrite -(mulgKV x y). case Rx: (x \in R); last by rewrite !gact_out ?mulgK // 1?groupMl ?Rx. by rewrite -gactV // -gactM 1?groupMr ?groupV // mulgK astabs_act. Qed. End Quotient. Section Mod. Variable H : {group aT}. Lemma modact_is_groupAction : is_groupAction 'C_(|to)(H) (to %% H). Proof. move=> Ha /morphimP[a Na Da ->]; have NDa: a \in 'N_D(H) by apply/setIP. rewrite inE; apply/andP; split. apply/subsetP=> x; rewrite 2!inE andbC actpermE /= modactEcond //. by apply: contraR; case: ifP => // E Rx; rewrite gact_out. apply/morphicP=> x y /setIP[Rx cHx] /setIP[Ry cHy]. rewrite /= !actpermE /= !modactE ?gactM //. suffices: x * y \in 'C_(|to)(H) by case/setIP. by rewrite groupM //; apply/setIP. Qed. Canonical mod_groupAction := GroupAction modact_is_groupAction. Lemma modgactE x a : H \subset 'C(R | to) -> a \in 'N_D(H) -> (to %% H)%act x (coset H a) = to x a. Proof. move=> cRH NDa /=; have [Da Na] := setIP NDa. have [Rx | notRx] := boolP (x \in R). by rewrite modactE //; apply/afixP=> b /setIP[_ /(subsetP cRH)/astab_act->]. rewrite gact_out //= /modact; case: ifP => // _; rewrite gact_out //. suffices: a \in D :&: coset H a by case/mem_repr/setIP. by rewrite inE Da val_coset // rcoset_refl. Qed. Lemma gacent_mod G M : H \subset 'C(M | to) -> G \subset 'N(H) -> 'C_(M | mod_groupAction)(G / H) = 'C_(M | to)(G). Proof. move=> cMH nHG; rewrite -gacentIdom gacentE ?subsetIl // setICA. have sHD: H \subset D by rewrite (subset_trans cMH) ?subsetIl. rewrite -quotientGI // afix_mod ?setIS // setICA -gacentIim (setIC R) -setIA. rewrite -gacentE ?subsetIl // gacentIdom setICA (setIidPr _) //. by rewrite gacentC // ?(subset_trans cMH) ?astabS ?subsetIl // setICA subsetIl. Qed. Lemma acts_irr_mod G M : H \subset 'C(M | to) -> G \subset 'N(H) -> acts_irreducibly G M to -> acts_irreducibly (G / H) M mod_groupAction. Proof. move=> cMH nHG /mingroupP[/andP[ntM nMG] minM]. apply/mingroupP; rewrite ntM astabs_mod ?quotientS //; split=> // L modL ntL. have cLH: H \subset 'C(L | to) by rewrite (subset_trans cMH) ?astabS //. apply: minM => //; case/andP: modL => ->; rewrite astabs_mod ?quotientSGK //. by rewrite (subset_trans cLH) ?astab_sub. Qed. End Mod. Lemma modact_coset_astab x a : a \in D -> (to %% 'C(R | to))%act x (coset _ a) = to x a. Proof. move=> Da; apply: modgactE => {x}//. rewrite !inE Da; apply/subsetP=> _ /imsetP[c Cc ->]. have Dc := astab_dom Cc; rewrite !inE groupJ //. apply/subsetP=> x Rx; rewrite inE conjgE !actMin ?groupM ?groupV //. by rewrite (astab_act Cc) ?actKVin // gact_stable ?groupV. Qed. Lemma acts_irr_mod_astab G M : acts_irreducibly G M to -> acts_irreducibly (G / 'C_G(M | to)) M (mod_groupAction _). Proof. move=> irrG; have /andP[_ nMG] := mingroupp irrG. apply: acts_irr_mod irrG; first exact: subsetIr. by rewrite normsI ?normG // (subset_trans nMG) // astab_norm. Qed. Section CompAct. Variables (gT : finGroupType) (G : {group gT}) (f : {morphism G >-> aT}). Lemma comp_is_groupAction : is_groupAction R (comp_action to f). Proof. move=> a /morphpreP[Ba Dfa]; apply: etrans (actperm_Aut to Dfa). by congr (_ \in Aut R); apply/permP=> x; rewrite !actpermE. Qed. Canonical comp_groupAction := GroupAction comp_is_groupAction. Lemma gacent_comp U : 'C_(|comp_groupAction)(U) = 'C_(|to)(f @* U). Proof. rewrite /gacent afix_comp ?subIset ?subxx //. by rewrite -(setIC U) (setIC D) morphim_setIpre. Qed. End CompAct. End GroupActionTheory. Notation "''C_' ( | to ) ( A )" := (gacent_group to A) : Group_scope. Notation "''C_' ( G | to ) ( A )" := (setI_group G 'C_(|to)(A)) : Group_scope. Notation "''C_' ( | to ) [ a ]" := (gacent_group to [set a%g]) : Group_scope. Notation "''C_' ( G | to ) [ a ]" := (setI_group G 'C_(|to)[a]) : Group_scope. Notation "to \ sAD" := (ract_groupAction to sAD) : groupAction_scope. Notation "<[ nGA ] >" := (actby_groupAction nGA) : groupAction_scope. Notation "to / H" := (quotient_groupAction to H) : groupAction_scope. Notation "to %% H" := (mod_groupAction to H) : groupAction_scope. Notation "to \o f" := (comp_groupAction to f) : groupAction_scope. (* Operator group isomorphism. *) Section MorphAction. Variables (aT1 aT2 : finGroupType) (rT1 rT2 : finType). Variables (D1 : {group aT1}) (D2 : {group aT2}). Variables (to1 : action D1 rT1) (to2 : action D2 rT2). Variables (A : {set aT1}) (R S : {set rT1}). Variables (h : rT1 -> rT2) (f : {morphism D1 >-> aT2}). Hypotheses (actsDR : {acts D1, on R | to1}) (injh : {in R &, injective h}). Hypothesis defD2 : f @* D1 = D2. Hypotheses (sSR : S \subset R) (sAD1 : A \subset D1). Hypothesis hfJ : {in S & D1, morph_act to1 to2 h f}. Lemma morph_astabs : f @* 'N(S | to1) = 'N(h @: S | to2). Proof. apply/setP=> fx; apply/morphimP/idP=> [[x D1x nSx ->] | nSx]. rewrite 2!inE -{1}defD2 mem_morphim //=; apply/subsetP=> _ /imsetP[u Su ->]. by rewrite inE -hfJ ?imset_f // (astabs_act _ nSx). have [|x D1x _ def_fx] := morphimP (_ : fx \in f @* D1). by rewrite defD2 (astabs_dom nSx). exists x => //; rewrite !inE D1x; apply/subsetP=> u Su. have /imsetP[u' Su' /injh def_u']: h (to1 u x) \in h @: S. by rewrite hfJ // -def_fx (astabs_act _ nSx) imset_f. by rewrite inE def_u' ?actsDR ?(subsetP sSR). Qed. Lemma morph_astab : f @* 'C(S | to1) = 'C(h @: S | to2). Proof. apply/setP=> fx; apply/morphimP/idP=> [[x D1x cSx ->] | cSx]. rewrite 2!inE -{1}defD2 mem_morphim //=; apply/subsetP=> _ /imsetP[u Su ->]. by rewrite inE -hfJ // (astab_act cSx). have [|x D1x _ def_fx] := morphimP (_ : fx \in f @* D1). by rewrite defD2 (astab_dom cSx). exists x => //; rewrite !inE D1x; apply/subsetP=> u Su. rewrite inE -(inj_in_eq injh) ?actsDR ?(subsetP sSR) ?hfJ //. by rewrite -def_fx (astab_act cSx) ?imset_f. Qed. Lemma morph_afix : h @: 'Fix_(S | to1)(A) = 'Fix_(h @: S | to2)(f @* A). Proof. apply/setP=> hu; apply/imsetP/setIP=> [[u /setIP[Su cAu] ->]|]. split; first by rewrite imset_f. by apply/afixP=> _ /morphimP[x D1x Ax ->]; rewrite -hfJ ?(afixP cAu). case=> /imsetP[u Su ->] /afixP c_hu_fA; exists u; rewrite // inE Su. apply/afixP=> x Ax; have Dx := subsetP sAD1 x Ax. by apply: injh; rewrite ?actsDR ?(subsetP sSR) ?hfJ // c_hu_fA ?mem_morphim. Qed. End MorphAction. Section MorphGroupAction. Variables (aT1 aT2 rT1 rT2 : finGroupType). Variables (D1 : {group aT1}) (D2 : {group aT2}). Variables (R1 : {group rT1}) (R2 : {group rT2}). Variables (to1 : groupAction D1 R1) (to2 : groupAction D2 R2). Variables (h : {morphism R1 >-> rT2}) (f : {morphism D1 >-> aT2}). Hypotheses (iso_h : isom R1 R2 h) (iso_f : isom D1 D2 f). Hypothesis hfJ : {in R1 & D1, morph_act to1 to2 h f}. Implicit Types (A : {set aT1}) (S : {set rT1}) (M : {group rT1}). Lemma morph_gastabs S : S \subset R1 -> f @* 'N(S | to1) = 'N(h @* S | to2). Proof. have [[_ defD2] [injh _]] := (isomP iso_f, isomP iso_h). move=> sSR1; rewrite (morphimEsub _ sSR1). apply: (morph_astabs (gact_stable to1) (injmP injh)) => // u x. by move/(subsetP sSR1); apply: hfJ. Qed. Lemma morph_gastab S : S \subset R1 -> f @* 'C(S | to1) = 'C(h @* S | to2). Proof. have [[_ defD2] [injh _]] := (isomP iso_f, isomP iso_h). move=> sSR1; rewrite (morphimEsub _ sSR1). apply: (morph_astab (gact_stable to1) (injmP injh)) => // u x. by move/(subsetP sSR1); apply: hfJ. Qed. Lemma morph_gacent A : A \subset D1 -> h @* 'C_(|to1)(A) = 'C_(|to2)(f @* A). Proof. have [[_ defD2] [injh defR2]] := (isomP iso_f, isomP iso_h). move=> sAD1; rewrite !gacentE //; last by rewrite -defD2 morphimS. rewrite morphimEsub ?subsetIl // -{1}defR2 morphimEdom. exact: (morph_afix (gact_stable to1) (injmP injh)). Qed. Lemma morph_gact_irr A M : A \subset D1 -> M \subset R1 -> acts_irreducibly (f @* A) (h @* M) to2 = acts_irreducibly A M to1. Proof. move=> sAD1 sMR1. have [[injf defD2] [injh defR2]] := (isomP iso_f, isomP iso_h). have h_eq1 := morphim_injm_eq1 injh. apply/mingroupP/mingroupP=> [] [/andP[ntM actAM] minM]. split=> [|U]; first by rewrite -h_eq1 // ntM -(injmSK injf) ?morph_gastabs. case/andP=> ntU acts_fAU sUM; have sUR1 := subset_trans sUM sMR1. apply: (injm_morphim_inj injh) => //; apply: minM; last exact: morphimS. by rewrite h_eq1 // ntU -morph_gastabs ?morphimS. split=> [|U]; first by rewrite h_eq1 // ntM -morph_gastabs ?morphimS. case/andP=> ntU acts_fAU sUhM. have sUhR1 := subset_trans sUhM (morphimS h sMR1). have sU'M: h @*^-1 U \subset M by rewrite sub_morphpre_injm. rewrite /= -(minM _ _ sU'M) ?morphpreK // -h_eq1 ?subsetIl // -(injmSK injf) //. by rewrite morph_gastabs ?(subset_trans sU'M) // morphpreK ?ntU. Qed. End MorphGroupAction. (* Conjugation and right translation actions. *) Section InternalActionDefs. Variable gT : finGroupType. Implicit Type A : {set gT}. Implicit Type G : {group gT}. (* This is not a Canonical action because it is seldom used, and it would *) (* cause too many spurious matches (any group product would be viewed as an *) (* action!). *) Definition mulgr_action := TotalAction (@mulg1 gT) (@mulgA gT). Canonical conjg_action := TotalAction (@conjg1 gT) (@conjgM gT). Lemma conjg_is_groupAction : is_groupAction setT conjg_action. Proof. move=> a _; rewrite inE; apply/andP; split; first by apply/subsetP=> x /[1!inE]. by apply/morphicP=> x y _ _; rewrite !actpermE /= conjMg. Qed. Canonical conjg_groupAction := GroupAction conjg_is_groupAction. Lemma rcoset_is_action : is_action setT (@rcoset gT). Proof. by apply: is_total_action => [A|A x y]; rewrite !rcosetE (mulg1, rcosetM). Qed. Canonical rcoset_action := Action rcoset_is_action. Canonical conjsg_action := TotalAction (@conjsg1 gT) (@conjsgM gT). Lemma conjG_is_action : is_action setT (@conjG_group gT). Proof. apply: is_total_action => [G | G x y]; apply: val_inj; rewrite /= ?act1 //. exact: actM. Qed. Definition conjG_action := Action conjG_is_action. End InternalActionDefs. Notation "'R" := (@mulgr_action _) : action_scope. Notation "'Rs" := (@rcoset_action _) : action_scope. Notation "'J" := (@conjg_action _) : action_scope. Notation "'J" := (@conjg_groupAction _) : groupAction_scope. Notation "'Js" := (@conjsg_action _) : action_scope. Notation "'JG" := (@conjG_action _) : action_scope. Notation "'Q" := ('J / _)%act : action_scope. Notation "'Q" := ('J / _)%gact : groupAction_scope. Section InternalGroupAction. Variable gT : finGroupType. Implicit Types A B : {set gT}. Implicit Types G H : {group gT}. Implicit Type x : gT. (* Various identities for actions on groups. *) Lemma orbitR G x : orbit 'R G x = x *: G. Proof. by rewrite -lcosetE. Qed. Lemma astab1R x : 'C[x | 'R] = 1. Proof. apply/trivgP/subsetP=> y cxy. by rewrite -(mulKg x y) [x * y](astab1P cxy) mulVg set11. Qed. Lemma astabR G : 'C(G | 'R) = 1. Proof. apply/trivgP/subsetP=> x cGx. by rewrite -(mul1g x) [1 * x](astabP cGx) group1. Qed. Lemma astabsR G : 'N(G | 'R) = G. Proof. apply/setP=> x; rewrite !inE -setactVin ?inE //=. by rewrite -groupV -{1 3}(mulg1 G) rcoset_sym -sub1set -mulGS -!rcosetE. Qed. Lemma atransR G : [transitive G, on G | 'R]. Proof. by rewrite /atrans -{1}(mul1g G) -orbitR imset_f. Qed. Lemma faithfulR G : [faithful G, on G | 'R]. Proof. by rewrite /faithful astabR subsetIr. Qed. Definition Cayley_repr G := actperm <[atrans_acts (atransR G)]>. Theorem Cayley_isom G : isom G (Cayley_repr G @* G) (Cayley_repr G). Proof. exact: faithful_isom (faithfulR G). Qed. Theorem Cayley_isog G : G \isog Cayley_repr G @* G. Proof. exact: isom_isog (Cayley_isom G). Qed. Lemma orbitJ G x : orbit 'J G x = x ^: G. Proof. by []. Qed. Lemma afixJ A : 'Fix_('J)(A) = 'C(A). Proof. apply/setP=> x; apply/afixP/centP=> cAx y Ay /=. by rewrite /commute conjgC cAx. by rewrite conjgE cAx ?mulKg. Qed. Lemma astabJ A : 'C(A |'J) = 'C(A). Proof. apply/setP=> x; apply/astabP/centP=> cAx y Ay /=. by apply: esym; rewrite conjgC cAx. by rewrite conjgE -cAx ?mulKg. Qed. Lemma astab1J x : 'C[x |'J] = 'C[x]. Proof. by rewrite astabJ cent_set1. Qed. Lemma astabsJ A : 'N(A | 'J) = 'N(A). Proof. by apply/setP=> x; rewrite -2!groupV !inE -conjg_preim -sub_conjg. Qed. Lemma setactJ A x : 'J^*%act A x = A :^ x. Proof. by []. Qed. Lemma gacentJ A : 'C_(|'J)(A) = 'C(A). Proof. by rewrite gacentE ?setTI ?subsetT ?afixJ. Qed. Lemma orbitRs G A : orbit 'Rs G A = rcosets A G. Proof. by []. Qed. Lemma sub_afixRs_norms G x A : (G :* x \in 'Fix_('Rs)(A)) = (A \subset G :^ x). Proof. rewrite inE /=; apply: eq_subset_r => a. rewrite inE rcosetE -(can2_eq (rcosetKV x) (rcosetK x)) -!rcosetM. rewrite eqEcard card_rcoset leqnn andbT mulgA (conjgCV x) mulgK. by rewrite -{2 3}(mulGid G) mulGS sub1set -mem_conjg. Qed. Lemma sub_afixRs_norm G x : (G :* x \in 'Fix_('Rs)(G)) = (x \in 'N(G)). Proof. by rewrite sub_afixRs_norms -groupV inE sub_conjgV. Qed. Lemma afixRs_rcosets A G : 'Fix_(rcosets G A | 'Rs)(G) = rcosets G 'N_A(G). Proof. apply/setP=> Gx; apply/setIP/rcosetsP=> [[/rcosetsP[x Ax ->]]|[x]]. by rewrite sub_afixRs_norm => Nx; exists x; rewrite // inE Ax. by case/setIP=> Ax Nx ->; rewrite -{1}rcosetE imset_f // sub_afixRs_norm. Qed. Lemma astab1Rs G : 'C[G : {set gT} | 'Rs] = G. Proof. apply/setP=> x. by apply/astab1P/idP=> /= [<- | Gx]; rewrite rcosetE ?rcoset_refl ?rcoset_id. Qed. Lemma actsRs_rcosets H G : [acts G, on rcosets H G | 'Rs]. Proof. by rewrite -orbitRs acts_orbit ?subsetT. Qed. Lemma transRs_rcosets H G : [transitive G, on rcosets H G | 'Rs]. Proof. by rewrite -orbitRs atrans_orbit. Qed. (* This is the second part of Aschbacher (5.7) *) Lemma astabRs_rcosets H G : 'C(rcosets H G | 'Rs) = gcore H G. Proof. have transGH := transRs_rcosets H G. by rewrite (astab_trans_gcore transGH (orbit_refl _ G _)) astab1Rs. Qed. Lemma orbitJs G A : orbit 'Js G A = A :^: G. Proof. by []. Qed. Lemma astab1Js A : 'C[A | 'Js] = 'N(A). Proof. by apply/setP=> x; apply/astab1P/normP. Qed. Lemma card_conjugates A G : #|A :^: G| = #|G : 'N_G(A)|. Proof. by rewrite card_orbit astab1Js. Qed. Lemma afixJG G A : (G \in 'Fix_('JG)(A)) = (A \subset 'N(G)). Proof. by apply/afixP/normsP=> nG x Ax; apply/eqP; move/eqP: (nG x Ax). Qed. Lemma astab1JG G : 'C[G | 'JG] = 'N(G). Proof. by apply/setP=> x; apply/astab1P/normP=> [/congr_group | /group_inj]. Qed. Lemma dom_qactJ H : qact_dom 'J H = 'N(H). Proof. by rewrite qact_domE ?subsetT ?astabsJ. Qed. Lemma qactJ H (Hy : coset_of H) x : 'Q%act Hy x = if x \in 'N(H) then Hy ^ coset H x else Hy. Proof. case: (cosetP Hy) => y Ny ->{Hy}. by rewrite qactEcond // dom_qactJ; case Nx: (x \in 'N(H)); rewrite ?morphJ. Qed. Lemma actsQ A B H : A \subset 'N(H) -> A \subset 'N(B) -> [acts A, on B / H | 'Q]. Proof. by move=> nHA nBA; rewrite acts_quotient // subsetI dom_qactJ nHA astabsJ. Qed. Lemma astabsQ G H : H <| G -> 'N(G / H | 'Q) = 'N(H) :&: 'N(G). Proof. by move=> nsHG; rewrite astabs_quotient // dom_qactJ astabsJ. Qed. Lemma astabQ H Abar : 'C(Abar |'Q) = coset H @*^-1 'C(Abar). Proof. apply/setP=> x; rewrite inE /= dom_qactJ morphpreE in_setI /=. apply: andb_id2l => Nx; rewrite !inE -sub1set centsC cent_set1. apply: eq_subset_r => {Abar} Hy; rewrite inE qactJ Nx (sameP eqP conjg_fixP). by rewrite (sameP cent1P eqP) (sameP commgP eqP). Qed. Lemma sub_astabQ A H Bbar : (A \subset 'C(Bbar | 'Q)) = (A \subset 'N(H)) && (A / H \subset 'C(Bbar)). Proof. rewrite astabQ -morphpreIdom subsetI; apply: andb_id2l => nHA. by rewrite -sub_quotient_pre. Qed. Lemma sub_astabQR A B H : A \subset 'N(H) -> B \subset 'N(H) -> (A \subset 'C(B / H | 'Q)) = ([~: A, B] \subset H). Proof. move=> nHA nHB; rewrite sub_astabQ nHA /= (sameP commG1P eqP). by rewrite eqEsubset sub1G andbT -quotientR // quotient_sub1 // comm_subG. Qed. Lemma astabQR A H : A \subset 'N(H) -> 'C(A / H | 'Q) = [set x in 'N(H) | [~: [set x], A] \subset H]. Proof. move=> nHA; apply/setP=> x; rewrite astabQ -morphpreIdom 2!inE -astabQ. by case nHx: (x \in _); rewrite //= -sub1set sub_astabQR ?sub1set. Qed. Lemma quotient_astabQ H Abar : 'C(Abar | 'Q) / H = 'C(Abar). Proof. by rewrite astabQ cosetpreK. Qed. Lemma conj_astabQ A H x : x \in 'N(H) -> 'C(A / H | 'Q) :^ x = 'C(A :^ x / H | 'Q). Proof. move=> nHx; apply/setP=> y; rewrite !astabQ mem_conjg !in_setI -mem_conjg. rewrite -normJ (normP nHx) quotientJ //; apply/andb_id2l => nHy. by rewrite !inE centJ morphJ ?groupV ?morphV // -mem_conjg. Qed. Section CardClass. Variable G : {group gT}. Lemma index_cent1 x : #|G : 'C_G[x]| = #|x ^: G|. Proof. by rewrite -astab1J -card_orbit. Qed. Lemma classes_partition : partition (classes G) G. Proof. by apply: orbit_partition; apply/actsP=> x Gx y; apply: groupJr. Qed. Lemma sum_card_class : \sum_(C in classes G) #|C| = #|G|. Proof. by apply: acts_sum_card_orbit; apply/actsP=> x Gx y; apply: groupJr. Qed. Lemma class_formula : \sum_(C in classes G) #|G : 'C_G[repr C]| = #|G|. Proof. rewrite -sum_card_class; apply: eq_bigr => _ /imsetP[x Gx ->]. have: x \in x ^: G by rewrite -{1}(conjg1 x) imset_f. by case/mem_repr/imsetP=> y Gy ->; rewrite index_cent1 classGidl. Qed. Lemma abelian_classP : reflect {in G, forall x, x ^: G = [set x]} (abelian G). Proof. rewrite /abelian -astabJ astabC. by apply: (iffP subsetP) => cGG x Gx; apply/orbit1P; apply: cGG. Qed. Lemma card_classes_abelian : abelian G = (#|classes G| == #|G|). Proof. have cGgt0 C: C \in classes G -> 1 <= #|C| ?= iff (#|C| == 1)%N. by case/imsetP=> x _ ->; rewrite eq_sym -index_cent1. rewrite -sum_card_class -sum1_card (leqif_sum cGgt0). apply/abelian_classP/forall_inP=> [cGG _ /imsetP[x Gx ->]| cGG x Gx]. by rewrite cGG ?cards1. apply/esym/eqP; rewrite eqEcard sub1set cards1 class_refl leq_eqVlt cGG //. exact: imset_f. Qed. End CardClass. End InternalGroupAction. Lemma gacentQ (gT : finGroupType) (H : {group gT}) (A : {set gT}) : 'C_(|'Q)(A) = 'C(A / H). Proof. apply/setP=> Hx; case: (cosetP Hx) => x Nx ->{Hx}. rewrite -sub_cent1 -astab1J astabC sub1set -(quotientInorm H A). have defD: qact_dom 'J H = 'N(H) by rewrite qact_domE ?subsetT ?astabsJ. rewrite !(inE, mem_quotient) //= defD setIC. apply/subsetP/subsetP=> [cAx _ /morphimP[a Na Aa ->] | cAx a Aa]. by move/cAx: Aa; rewrite !inE qactE ?defD ?morphJ. have [_ Na] := setIP Aa; move/implyP: (cAx (coset H a)); rewrite mem_morphim //. by rewrite !inE qactE ?defD ?morphJ. Qed. Section AutAct. Variable (gT : finGroupType) (G : {set gT}). Definition autact := act ('P \ subsetT (Aut G)). Canonical aut_action := [action of autact]. Lemma autactK a : actperm aut_action a = a. Proof. by apply/permP=> x; rewrite permE. Qed. Lemma autact_is_groupAction : is_groupAction G aut_action. Proof. by move=> a Aa /=; rewrite autactK. Qed. Canonical aut_groupAction := GroupAction autact_is_groupAction. Section perm_prime_orbit. Variable (T : finType) (c : {perm T}). Hypothesis Tp : prime #|T|. Hypothesis cc : #[c]%g = #|T|. Let cp : prime #[c]%g. Proof. by rewrite cc. Qed. Lemma perm_prime_atrans : [transitive <[c]>, on setT | 'P]. Proof. apply/imsetP; suff /existsP[x] : [exists x, ~~ (#|orbit 'P <[c]> x| < #[c])]. move=> oxT; suff /eqP orbit_x : orbit 'P <[c]> x == setT by exists x. by rewrite eqEcard subsetT cardsT -cc leqNgt. apply/forallP => olT; have o1 x : #|orbit 'P <[c]> x| == 1%N. by case/primeP: cp => _ /(_ _ (dvdn_orbit 'P _ x))/orP[]//; rewrite ltn_eqF. suff c1 : c = 1%g by rewrite c1 ?order1 in (cp). apply/permP => x; rewrite perm1; apply/set1P. by rewrite -(card_orbit1 (eqP (o1 _))) (mem_orbit 'P) ?cycle_id. Qed. Lemma perm_prime_orbit x : orbit 'P <[c]> x = [set: T]. Proof. by apply: atransP => //; apply: perm_prime_atrans. Qed. Lemma perm_prime_astab x : 'C_<[c]>[x | 'P]%g = 1%g. Proof. by apply/card1_trivg/eqP; rewrite -(@eqn_pmul2l #|orbit 'P <[c]> x|) ?card_orbit_stab ?perm_prime_orbit ?cardsT ?muln1 ?prime_gt0// -cc. Qed. End perm_prime_orbit. End AutAct. Arguments autact {gT} G%_g. Arguments aut_action {gT} G%_g. Arguments aut_groupAction {gT} G%_g. Notation "[ 'Aut' G ]" := (aut_action G) : action_scope. Notation "[ 'Aut' G ]" := (aut_groupAction G) : groupAction_scope.
Option.lean
/- Copyright (c) 2024 Tom Kranz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tom Kranz -/ import Mathlib.Data.FinEnum import Mathlib.Logic.Equiv.Fin.Basic /-! # FinEnum instance for Option Provides a recursor for FinEnum types like `Fintype.truncRecEmptyOption`, but capable of producing non-truncated data. ## TODO * recreate rest of `Mathlib/Data/Fintype/Option.lean` -/ namespace FinEnum universe u v /-- Inserting an `Option.none` anywhere in an enumeration yields another enumeration. -/ def insertNone (α : Type u) [FinEnum α] (i : Fin (card α + 1)) : FinEnum (Option α) where card := card α + 1 equiv := equiv.optionCongr.trans <| finSuccEquiv' i |>.symm /-- This is an arbitrary choice of insertion rank for a default instance. It keeps the mapping of the existing `α`-inhabitants intact, modulo `Fin.castSucc`. -/ instance instFinEnumOptionLast (α : Type u) [FinEnum α] : FinEnum (Option α) := insertNone α (Fin.last _) open Fin.NatCast in -- TODO: refactor the proof to avoid needing this. /-- A recursor principle for finite-and-enumerable types, analogous to `Nat.rec`. It effectively says that every `FinEnum` is either `Empty` or `Option α`, up to an `Equiv` mediated by `Fin`s of equal cardinality. In contrast to the `Fintype` case, data can be transported along such an `Equiv`. Also, since order matters, the choice of element that gets replaced by `Option.none` has to be provided for every step. Since every `FinEnum` instance implies a `Fintype` instance and `Prop` is squashed already, `Fintype.induction_empty_option` can be used if a `Prop` needs to be constructed. Cf. `Data.Fintype.Option` -/ def recEmptyOption {P : Type u → Sort v} (finChoice : (n : ℕ) → Fin (n + 1)) (congr : {α β : Type u} → (_ : FinEnum α) → (_ : FinEnum β) → card β = card α → P α → P β) (empty : P PEmpty.{u + 1}) (option : {α : Type u} → FinEnum α → P α → P (Option α)) (α : Type u) [FinEnum α] : P α := match cardeq : card α with | 0 => congr _ _ cardeq empty | n + 1 => let fN := ULift.instFinEnum (α := Fin n) have : card (ULift.{u} <| Fin n) = n := card_ulift.trans card_fin congr (insertNone _ <| finChoice n) _ (cardeq.trans <| congrArg Nat.succ this.symm) <| option fN (recEmptyOption finChoice congr empty option _) termination_by card α /-- For an empty type, the recursion principle evaluates to whatever `congr` makes of the base case. -/ theorem recEmptyOption_of_card_eq_zero {P : Type u → Sort v} (finChoice : (n : ℕ) → Fin (n + 1)) (congr : {α β : Type u} → (_ : FinEnum α) → (_ : FinEnum β) → card β = card α → P α → P β) (empty : P PEmpty.{u + 1}) (option : {α : Type u} → FinEnum α → P α → P (Option α)) (α : Type u) [FinEnum α] (h : card α = 0) (_ : FinEnum PEmpty.{u + 1}) : recEmptyOption finChoice congr empty option α = congr _ _ (h.trans card_eq_zero.symm) empty := by unfold recEmptyOption split · congr 1; exact Subsingleton.allEq _ _ · exact Nat.noConfusion <| h.symm.trans ‹_› open Fin.NatCast in -- TODO: refactor the proof to avoid needing this. /-- For a type with positive `card`, the recursion principle evaluates to whatever `congr` makes of the step result, where `Option.none` has been inserted into the `(finChoice (card α - 1))`th rank of the enumeration. -/ theorem recEmptyOption_of_card_pos {P : Type u → Sort v} (finChoice : (n : ℕ) → Fin (n + 1)) (congr : {α β : Type u} → (_ : FinEnum α) → (_ : FinEnum β) → card β = card α → P α → P β) (empty : P PEmpty.{u + 1}) (option : {α : Type u} → FinEnum α → P α → P (Option α)) (α : Type u) [FinEnum α] (h : 0 < card α) : recEmptyOption finChoice congr empty option α = congr (insertNone _ <| finChoice (card α - 1)) ‹_› (congrArg (· + 1) card_fin |>.trans <| (card α).succ_pred_eq_of_pos h).symm (option ULift.instFinEnum <| recEmptyOption finChoice congr empty option (ULift.{u} <| Fin (card α - 1))) := by conv => lhs; unfold recEmptyOption split · exact absurd (‹_› ▸ h) (card α).lt_irrefl · rcases Nat.succ.inj <| (card α).succ_pred_eq_of_pos h |>.trans ‹_› with rfl; rfl /-- A recursor principle for finite-and-enumerable types, analogous to `Nat.recOn`. It effectively says that every `FinEnum` is either `Empty` or `Option α`, up to an `Equiv` mediated by `Fin`s of equal cardinality. In contrast to the `Fintype` case, data can be transported along such an `Equiv`. Also, since order matters, the choice of element that gets replaced by `Option.none` has to be provided for every step. -/ abbrev recOnEmptyOption {P : Type u → Sort v} {α : Type u} (aenum : FinEnum α) (finChoice : (n : ℕ) → Fin (n + 1)) (congr : {α β : Type u} → (_ : FinEnum α) → (_ : FinEnum β) → card β = card α → P α → P β) (empty : P PEmpty.{u + 1}) (option : {α : Type u} → FinEnum α → P α → P (Option α)) : P α := @recEmptyOption P finChoice congr empty option α aenum end FinEnum
fraction.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat div seq. From mathcomp Require Import ssrAC choice tuple bigop ssralg poly polydiv. From mathcomp Require Import generic_quotient. (******************************************************************************) (* Field of fraction of an integral domain *) (* *) (* This file builds the field of fraction of any integral domain. The main *) (* result of this file is the existence of the field and of the tofrac *) (* function which is a injective ring morphism from R to its fraction field *) (* {fraction R}. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory. Local Open Scope ring_scope. Local Open Scope quotient_scope. Reserved Notation "{ 'ratio' T }" (format "{ 'ratio' T }"). Reserved Notation "{ 'fraction' T }" (format "{ 'fraction' T }"). Reserved Notation "x %:F" (format "x %:F"). Section FracDomain. Variable R : nzRingType. (* ratios are pairs of R, such that the second member is nonzero *) Inductive ratio := mkRatio { frac :> R * R; _ : frac.2 != 0 }. HB.instance Definition _ := [isSub for frac]. HB.instance Definition _ := [Choice of ratio by <:]. Lemma denom_ratioP : forall f : ratio, f.2 != 0. Proof. by case. Qed. Definition ratio0 := (@mkRatio (0, 1) (oner_neq0 _)). Definition Ratio x y : ratio := insubd ratio0 (x, y). Lemma numer_Ratio x y : y != 0 -> (Ratio x y).1 = x. Proof. by move=> ny0; rewrite /Ratio /insubd insubT. Qed. Lemma denom_Ratio x y : y != 0 -> (Ratio x y).2 = y. Proof. by move=> ny0; rewrite /Ratio /insubd insubT. Qed. Definition numden_Ratio := (numer_Ratio, denom_Ratio). Variant Ratio_spec (n d : R) : ratio -> R -> R -> Type := | RatioNull of d = 0 : Ratio_spec n d ratio0 n 0 | RatioNonNull (d_neq0 : d != 0) : Ratio_spec n d (@mkRatio (n, d) d_neq0) n d. Lemma RatioP n d : Ratio_spec n d (Ratio n d) n d. Proof. rewrite /Ratio /insubd; case: insubP=> /= [x /= d_neq0 hx|]. have ->: x = @mkRatio (n, d) d_neq0 by apply: val_inj. by constructor. by rewrite negbK=> /eqP hx; rewrite {2}hx; constructor. Qed. Lemma Ratio0 x : Ratio x 0 = ratio0. Proof. by rewrite /Ratio /insubd; case: insubP; rewrite //= eqxx. Qed. End FracDomain. Arguments ratio R%_type. Notation "{ 'ratio' T }" := (ratio T) : type_scope. Notation "'\n_' x" := (frac x).1 (at level 8, x at level 2, format "'\n_' x"). Notation "'\d_' x" := (frac x).2 (at level 8, x at level 2, format "'\d_' x"). Module FracField. Section FracField. Variable R : idomainType. Local Notation frac := (R * R). Local Notation dom := (ratio R). Local Notation domP := denom_ratioP. Implicit Types x y z : dom. (* We define a relation in ratios *) Local Notation equivf_notation x y := (\n_x * \d_y == \d_x * \n_y). Definition equivf x y := equivf_notation x y. Lemma equivfE x y : equivf x y = equivf_notation x y. Proof. by []. Qed. Lemma equivf_refl : reflexive equivf. Proof. by move=> x; rewrite /equivf mulrC. Qed. Lemma equivf_sym : symmetric equivf. Proof. by move=> x y; rewrite /equivf eq_sym; congr (_==_); rewrite mulrC. Qed. Lemma equivf_trans : transitive equivf. Proof. move=> [x Px] [y Py] [z Pz]; rewrite /equivf /= mulrC => /eqP xy /eqP yz. by rewrite -(inj_eq (mulfI Px)) mulrA xy -mulrA yz mulrCA. Qed. (* we show that equivf is an equivalence *) Canonical equivf_equiv := EquivRel equivf equivf_refl equivf_sym equivf_trans. Definition type := {eq_quot equivf}. (* we recover some structure for the quotient *) HB.instance Definition _ : EqQuotient _ equivf type := EqQuotient.on type. HB.instance Definition _ := Choice.on type. (* we explain what was the equivalence on the quotient *) Lemma equivf_def (x y : ratio R) : x == y %[mod type] = (\n_x * \d_y == \d_x * \n_y). Proof. by rewrite eqmodE. Qed. Lemma equivf_r x : \n_x * \d_(repr (\pi_type x)) = \d_x * \n_(repr (\pi_type x)). Proof. by apply/eqP; rewrite -equivf_def reprK. Qed. Lemma equivf_l x : \n_(repr (\pi_type x)) * \d_x = \d_(repr (\pi_type x)) * \n_x. Proof. by apply/eqP; rewrite -equivf_def reprK. Qed. Lemma numer0 x : (\n_x == 0) = (x == (ratio0 R) %[mod_eq equivf]). Proof. by rewrite eqmodE /= !equivfE // mulr1 mulr0. Qed. Lemma Ratio_numden : forall x, Ratio \n_x \d_x = x. Proof. case=> [[n d] /= nd]; rewrite /Ratio /insubd; apply: val_inj=> /=. by case: insubP=> //=; rewrite nd. Qed. Definition tofrac := lift_embed type (fun x : R => Ratio x 1). Canonical tofrac_pi_morph := PiEmbed tofrac. Notation "x %:F" := (@tofrac x). Implicit Types a b c : type. Definition addf x y : dom := Ratio (\n_x * \d_y + \n_y * \d_x) (\d_x * \d_y). Definition add := lift_op2 type addf. Lemma pi_add : {morph \pi : x y / addf x y >-> add x y}. Proof. move=> x y; unlock add; apply/eqmodP; rewrite /= equivfE /addf /=. rewrite !numden_Ratio ?mulf_neq0 ?domP // mulrDr mulrDl; apply/eqP. symmetry; rewrite (AC (2*2) (3*1*2*4)) (AC (2*2) (3*2*1*4))/=. by rewrite !equivf_l (ACl ((2*3)*(1*4))) (ACl ((2*3)*(4*1)))/=. Qed. Canonical pi_add_morph := PiMorph2 pi_add. Definition oppf x : dom := Ratio (- \n_x) \d_x. Definition opp := lift_op1 type oppf. Lemma pi_opp : {morph \pi : x / oppf x >-> opp x}. Proof. move=> x; unlock opp; apply/eqmodP; rewrite /= /equivf /oppf /=. by rewrite !numden_Ratio ?(domP,mulf_neq0) // mulNr mulrN -equivf_r. Qed. Canonical pi_opp_morph := PiMorph1 pi_opp. Definition mulf x y : dom := Ratio (\n_x * \n_y) (\d_x * \d_y). Definition mul := lift_op2 type mulf. Lemma pi_mul : {morph \pi : x y / mulf x y >-> mul x y}. Proof. move=> x y; unlock mul; apply/eqmodP=> /=. rewrite equivfE /= /addf /= !numden_Ratio ?mulf_neq0 ?domP //. by rewrite mulrACA !equivf_r mulrACA. Qed. Canonical pi_mul_morph := PiMorph2 pi_mul. Definition invf x : dom := Ratio \d_x \n_x. Definition inv := lift_op1 type invf. Lemma pi_inv : {morph \pi : x / invf x >-> inv x}. Proof. move=> x; unlock inv; apply/eqmodP=> /=; rewrite equivfE /invf eq_sym. do 2?case: RatioP=> /= [/eqP|]; rewrite ?mul0r ?mul1r -?equivf_def ?numer0 ?reprK //. by move=> hx /eqP hx'; rewrite hx' eqxx in hx. by move=> /eqP ->; rewrite eqxx. Qed. Canonical pi_inv_morph := PiMorph1 pi_inv. Lemma addA : associative add. Proof. elim/quotW=> x; elim/quotW=> y; elim/quotW=> z; rewrite !piE. rewrite /addf /= !numden_Ratio ?mulf_neq0 ?domP // !mulrDl. by rewrite !mulrA !addrA ![_ * _ * \d_x]mulrAC. Qed. Lemma addC : commutative add. Proof. by elim/quotW=> x; elim/quotW=> y; rewrite !piE /addf addrC [\d__ * _]mulrC. Qed. Lemma add0_l : left_id 0%:F add. Proof. elim/quotW=> x; rewrite !piE /addf !numden_Ratio ?oner_eq0 //. by rewrite mul0r mul1r mulr1 add0r Ratio_numden. Qed. Lemma addN_l : left_inverse 0%:F opp add. Proof. elim/quotW=> x; apply/eqP; rewrite piE /equivf. rewrite /addf /oppf !numden_Ratio ?(oner_eq0, mulf_neq0, domP) //. by rewrite mulr1 mulr0 mulNr addNr. Qed. (* fracions form an abelian group *) HB.instance Definition _ := GRing.isZmodule.Build type addA addC add0_l addN_l. Lemma mulA : associative mul. Proof. elim/quotW=> x; elim/quotW=> y; elim/quotW=> z; rewrite !piE. by rewrite /mulf !numden_Ratio ?mulf_neq0 ?domP // !mulrA. Qed. Lemma mulC : commutative mul. Proof. elim/quotW=> x; elim/quotW=> y; rewrite !piE /mulf. by rewrite [_ * (\d_x)]mulrC [_ * (\n_x)]mulrC. Qed. Lemma mul1_l : left_id 1%:F mul. Proof. elim/quotW=> x; rewrite !piE /mulf. by rewrite !numden_Ratio ?oner_eq0 // !mul1r Ratio_numden. Qed. Lemma mul_addl : left_distributive mul add. Proof. elim/quotW=> x; elim/quotW=> y; elim/quotW=> z; apply/eqP. rewrite !piE /equivf /mulf /addf !numden_Ratio ?mulf_neq0 ?domP //; apply/eqP. rewrite !(mulrDr, mulrDl) (AC (3*(2*2)) (4*2*7*((1*3)*(6*5))))/=. by rewrite [X in _ + X](AC (3*(2*2)) (4*6*7*((1*3)*(2*5))))/=. Qed. Lemma nonzero1 : 1%:F != 0%:F :> type. Proof. by rewrite piE equivfE !numden_Ratio ?mul1r ?oner_eq0. Qed. (* fractions form a commutative ring *) HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build type mulA mulC mul1_l mul_addl nonzero1. Lemma mulV_l : forall a, a != 0%:F -> mul (inv a) a = 1%:F. Proof. elim/quotW=> x /=; rewrite !piE. rewrite /equivf !numden_Ratio ?oner_eq0 // mulr1 mulr0=> nx0. apply/eqmodP; rewrite /= equivfE. by rewrite !numden_Ratio ?(oner_eq0, mulf_neq0, domP) // !mulr1 mulrC. Qed. Lemma inv0 : inv 0%:F = 0%:F. Proof. rewrite !piE /invf !numden_Ratio ?oner_eq0 // /Ratio /insubd. do 2?case: insubP; rewrite //= ?eqxx ?oner_eq0 // => u _ hu _. by congr \pi; apply: val_inj; rewrite /= hu. Qed. (* fractions form a ring with explicit unit *) (* fractions form a field *) HB.instance Definition _ := GRing.ComNzRing_isField.Build type mulV_l inv0. End FracField. End FracField. HB.export FracField. Arguments FracField.type R%_type. Notation "{ 'fraction' T }" := (FracField.type T). Notation equivf := (@FracField.equivf _). #[global] Hint Resolve denom_ratioP : core. Section FracFieldTheory. Import FracField. Variable R : idomainType. Lemma Ratio_numden (x : {ratio R}) : Ratio \n_x \d_x = x. Proof. exact: FracField.Ratio_numden. Qed. (* exporting the embedding from R to {fraction R} *) Local Notation tofrac := (@FracField.tofrac R). Local Notation "x %:F" := (tofrac x). Lemma tofrac_is_zmod_morphism: zmod_morphism tofrac. Proof. move=> p q /=; unlock tofrac. rewrite -[X in _ = _ + X]pi_opp -[RHS]pi_add. by rewrite /addf /oppf /= !numden_Ratio ?(oner_neq0, mul1r, mulr1). Qed. #[deprecated(since="mathcomp 2.5.0", note="use `tofrac_is_zmod_morphism` instead")] Definition tofrac_is_additive := tofrac_is_zmod_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build R {fraction R} tofrac tofrac_is_zmod_morphism. Lemma tofrac_is_monoid_morphism: monoid_morphism tofrac. Proof. split=> [//|p q]; unlock tofrac; rewrite -[RHS]pi_mul. by rewrite /mulf /= !numden_Ratio ?(oner_neq0, mul1r, mulr1). Qed. #[deprecated(since="mathcomp 2.5.0", note="use `tofrac_is_monoid_morphism` instead")] Definition tofrac_is_multiplicative := tofrac_is_monoid_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build R {fraction R} tofrac tofrac_is_monoid_morphism. (* tests *) Lemma tofrac0 : 0%:F = 0. Proof. exact: rmorph0. Qed. Lemma tofracN : {morph tofrac: x / - x}. Proof. exact: rmorphN. Qed. Lemma tofracD : {morph tofrac: x y / x + y}. Proof. exact: rmorphD. Qed. Lemma tofracB : {morph tofrac: x y / x - y}. Proof. exact: rmorphB. Qed. Lemma tofracMn n : {morph tofrac: x / x *+ n}. Proof. exact: rmorphMn. Qed. Lemma tofracMNn n : {morph tofrac: x / x *- n}. Proof. exact: rmorphMNn. Qed. Lemma tofrac1 : 1%:F = 1. Proof. exact: rmorph1. Qed. Lemma tofracM : {morph tofrac: x y / x * y}. Proof. exact: rmorphM. Qed. Lemma tofracXn n : {morph tofrac: x / x ^+ n}. Proof. exact: rmorphXn. Qed. Lemma tofrac_eq (p q : R): (p%:F == q%:F) = (p == q). Proof. apply/eqP/eqP=> [|->//]; unlock tofrac=> /eqmodP /eqP /=. by rewrite !numden_Ratio ?(oner_eq0, mul1r, mulr1). Qed. Lemma tofrac_eq0 (p : R): (p%:F == 0) = (p == 0). Proof. by rewrite tofrac_eq. Qed. End FracFieldTheory.
Regular.lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.GroupWithZero.Regular import Mathlib.Algebra.Ring.Defs /-! # Lemmas about regular elements in rings. -/ variable {α : Type*} /-- Left `Mul` by a `k : α` over `[Ring α]` is injective, if `k` is not a zero divisor. The typeclass that restricts all terms of `α` to have this property is `NoZeroDivisors`. -/ theorem isLeftRegular_of_non_zero_divisor [NonUnitalNonAssocRing α] (k : α) (h : ∀ x : α, k * x = 0 → x = 0) : IsLeftRegular k := by refine fun x y (h' : k * x = k * y) => sub_eq_zero.mp (h _ ?_) rw [mul_sub, sub_eq_zero, h'] /-- Right `Mul` by a `k : α` over `[Ring α]` is injective, if `k` is not a zero divisor. The typeclass that restricts all terms of `α` to have this property is `NoZeroDivisors`. -/ theorem isRightRegular_of_non_zero_divisor [NonUnitalNonAssocRing α] (k : α) (h : ∀ x : α, x * k = 0 → x = 0) : IsRightRegular k := by refine fun x y (h' : x * k = y * k) => sub_eq_zero.mp (h _ ?_) rw [sub_mul, sub_eq_zero, h'] theorem isRegular_of_ne_zero' [NonUnitalNonAssocRing α] [NoZeroDivisors α] {k : α} (hk : k ≠ 0) : IsRegular k := ⟨isLeftRegular_of_non_zero_divisor k fun _ h => (NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_left hk, isRightRegular_of_non_zero_divisor k fun _ h => (NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_right hk⟩ theorem isRegular_iff_ne_zero' [Nontrivial α] [NonUnitalNonAssocRing α] [NoZeroDivisors α] {k : α} : IsRegular k ↔ k ≠ 0 := ⟨fun h => by rintro rfl exact not_not.mpr h.left not_isLeftRegular_zero, isRegular_of_ne_zero'⟩ /-- A ring with no zero divisors is a `CancelMonoidWithZero`. Note this is not an instance as it forms a typeclass loop. -/ abbrev NoZeroDivisors.toCancelMonoidWithZero [Ring α] [NoZeroDivisors α] : CancelMonoidWithZero α where mul_left_cancel_of_ne_zero ha := (isRegular_of_ne_zero' ha).1 mul_right_cancel_of_ne_zero hb := (isRegular_of_ne_zero' hb).2 /-- A commutative ring with no zero divisors is a `CancelCommMonoidWithZero`. Note this is not an instance as it forms a typeclass loop. -/ abbrev NoZeroDivisors.toCancelCommMonoidWithZero [CommRing α] [NoZeroDivisors α] : CancelCommMonoidWithZero α := { NoZeroDivisors.toCancelMonoidWithZero, ‹CommRing α› with } section IsDomain -- see Note [lower instance priority] instance (priority := 100) IsDomain.toCancelMonoidWithZero [Semiring α] [IsDomain α] : CancelMonoidWithZero α where variable [CommSemiring α] [IsDomain α] -- see Note [lower instance priority] instance (priority := 100) IsDomain.toCancelCommMonoidWithZero : CancelCommMonoidWithZero α := { mul_left_cancel_of_ne_zero := IsLeftCancelMulZero.mul_left_cancel_of_ne_zero } end IsDomain
SeparatedMap.lean
/- 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.Topology.Connected.Basic import Mathlib.Topology.Separation.Hausdorff import Mathlib.Topology.Connected.Clopen /-! # Separated maps and locally injective maps out of a topological space. This module introduces a pair of dual notions `IsSeparatedMap` and `IsLocallyInjective`. A function from a topological space `X` to a type `Y` is a separated map if any two distinct points in `X` with the same image in `Y` can be separated by open neighborhoods. A constant function is a separated map if and only if `X` is a `T2Space`. A function from a topological space `X` is locally injective if every point of `X` has a neighborhood on which `f` is injective. A constant function is locally injective if and only if `X` is discrete. Given `f : X → Y` we can form the pullback $X \times_Y X$; the diagonal map $\Delta: X \to X \times_Y X$ is always an embedding. It is a closed embedding iff `f` is a separated map, iff the equal locus of any two continuous maps coequalized by `f` is closed. It is an open embedding iff `f` is locally injective, iff any such equal locus is open. Therefore, if `f` is a locally injective separated map, the equal locus of two continuous maps coequalized by `f` is clopen, so if the two maps agree on a point, then they agree on the whole connected component. The analogue of separated maps and locally injective maps in algebraic geometry are separated morphisms and unramified morphisms, respectively. ## Reference https://stacks.math.columbia.edu/tag/0CY0 -/ open Topology variable {X Y A} [TopologicalSpace X] [TopologicalSpace A] protected lemma Topology.IsEmbedding.toPullbackDiag (f : X → Y) : IsEmbedding (toPullbackDiag f) := .mk' _ (injective_toPullbackDiag f) fun x ↦ by simp [nhds_induced, Filter.comap_comap, nhds_prod_eq, Filter.comap_prod, Function.comp_def, Filter.comap_id'] lemma Continuous.mapPullback {X₁ X₂ Y₁ Y₂ Z₁ Z₂} [TopologicalSpace X₁] [TopologicalSpace X₂] [TopologicalSpace Z₁] [TopologicalSpace Z₂] {f₁ : X₁ → Y₁} {g₁ : Z₁ → Y₁} {f₂ : X₂ → Y₂} {g₂ : Z₂ → Y₂} {mapX : X₁ → X₂} (contX : Continuous mapX) {mapY : Y₁ → Y₂} {mapZ : Z₁ → Z₂} (contZ : Continuous mapZ) {commX : f₂ ∘ mapX = mapY ∘ f₁} {commZ : g₂ ∘ mapZ = mapY ∘ g₁} : Continuous (Function.mapPullback mapX mapY mapZ commX commZ) := by refine continuous_induced_rng.mpr (.prodMk ?_ ?_) <;> apply_rules [continuous_fst, continuous_snd, continuous_subtype_val, Continuous.comp] /-- A function from a topological space `X` to a type `Y` is a separated map if any two distinct points in `X` with the same image in `Y` can be separated by open neighborhoods. -/ def IsSeparatedMap (f : X → Y) : Prop := ∀ x₁ x₂, f x₁ = f x₂ → x₁ ≠ x₂ → ∃ s₁ s₂, IsOpen s₁ ∧ IsOpen s₂ ∧ x₁ ∈ s₁ ∧ x₂ ∈ s₂ ∧ Disjoint s₁ s₂ lemma t2space_iff_isSeparatedMap (y : Y) : T2Space X ↔ IsSeparatedMap fun _ : X ↦ y := ⟨fun ⟨t2⟩ _ _ _ hne ↦ t2 hne, fun sep ↦ ⟨fun x₁ x₂ hne ↦ sep x₁ x₂ rfl hne⟩⟩ lemma T2Space.isSeparatedMap [T2Space X] (f : X → Y) : IsSeparatedMap f := fun _ _ _ ↦ t2_separation lemma Function.Injective.isSeparatedMap {f : X → Y} (inj : f.Injective) : IsSeparatedMap f := fun _ _ he hne ↦ (hne (inj he)).elim lemma isSeparatedMap_iff_disjoint_nhds {f : X → Y} : IsSeparatedMap f ↔ ∀ x₁ x₂, f x₁ = f x₂ → x₁ ≠ x₂ → Disjoint (𝓝 x₁) (𝓝 x₂) := forall₃_congr fun x x' _ ↦ by simp only [(nhds_basis_opens x).disjoint_iff (nhds_basis_opens x'), ← exists_and_left, and_assoc, and_comm, and_left_comm] lemma isSeparatedMap_iff_nhds {f : X → Y} : IsSeparatedMap f ↔ ∀ x₁ x₂, f x₁ = f x₂ → x₁ ≠ x₂ → ∃ s₁ ∈ 𝓝 x₁, ∃ s₂ ∈ 𝓝 x₂, Disjoint s₁ s₂ := by simp_rw [isSeparatedMap_iff_disjoint_nhds, Filter.disjoint_iff] open Set Filter in theorem isSeparatedMap_iff_isClosed_diagonal {f : X → Y} : IsSeparatedMap f ↔ IsClosed f.pullbackDiagonal := by simp_rw [isSeparatedMap_iff_nhds, ← isOpen_compl_iff, isOpen_iff_mem_nhds, Subtype.forall, Prod.forall, nhds_induced, nhds_prod_eq] refine forall₄_congr fun x₁ x₂ _ _ ↦ ⟨fun h ↦ ?_, fun ⟨t, ht, t_sub⟩ ↦ ?_⟩ · simp_rw [← Filter.disjoint_iff, ← compl_diagonal_mem_prod] at h exact ⟨_, h, subset_rfl⟩ · obtain ⟨s₁, h₁, s₂, h₂, s_sub⟩ := mem_prod_iff.mp ht exact ⟨s₁, h₁, s₂, h₂, disjoint_left.2 fun x h₁ h₂ ↦ @t_sub ⟨(x, x), rfl⟩ (s_sub ⟨h₁, h₂⟩) rfl⟩ theorem isSeparatedMap_iff_isClosedEmbedding {f : X → Y} : IsSeparatedMap f ↔ IsClosedEmbedding (toPullbackDiag f) := by rw [isSeparatedMap_iff_isClosed_diagonal, ← range_toPullbackDiag] exact ⟨fun h ↦ ⟨.toPullbackDiag f, h⟩, fun h ↦ h.isClosed_range⟩ theorem isSeparatedMap_iff_isClosedMap {f : X → Y} : IsSeparatedMap f ↔ IsClosedMap (toPullbackDiag f) := isSeparatedMap_iff_isClosedEmbedding.trans ⟨IsClosedEmbedding.isClosedMap, .of_continuous_injective_isClosedMap (IsEmbedding.toPullbackDiag f).continuous (injective_toPullbackDiag f)⟩ open Function.Pullback in theorem IsSeparatedMap.pullback {f : X → Y} (sep : IsSeparatedMap f) (g : A → Y) : IsSeparatedMap (@snd X Y A f g) := by rw [isSeparatedMap_iff_isClosed_diagonal] at sep ⊢ rw [← preimage_map_fst_pullbackDiagonal] refine sep.preimage (Continuous.mapPullback ?_ ?_) <;> apply_rules [continuous_fst, continuous_subtype_val, Continuous.comp] theorem IsSeparatedMap.comp_left {A} {f : X → Y} (sep : IsSeparatedMap f) {g : Y → A} (inj : g.Injective) : IsSeparatedMap (g ∘ f) := fun x₁ x₂ he ↦ sep x₁ x₂ (inj he) theorem IsSeparatedMap.comp_right {f : X → Y} (sep : IsSeparatedMap f) {g : A → X} (cont : Continuous g) (inj : g.Injective) : IsSeparatedMap (f ∘ g) := by rw [isSeparatedMap_iff_isClosed_diagonal] at sep ⊢ rw [← inj.preimage_pullbackDiagonal] exact sep.preimage (cont.mapPullback cont) /-- A function from a topological space `X` is locally injective if every point of `X` has a neighborhood on which `f` is injective. -/ def IsLocallyInjective (f : X → Y) : Prop := ∀ x : X, ∃ U, IsOpen U ∧ x ∈ U ∧ U.InjOn f lemma Function.Injective.IsLocallyInjective {f : X → Y} (inj : f.Injective) : IsLocallyInjective f := fun _ ↦ ⟨_, isOpen_univ, trivial, fun _ _ _ _ ↦ @inj _ _⟩ lemma isLocallyInjective_iff_nhds {f : X → Y} : IsLocallyInjective f ↔ ∀ x : X, ∃ U ∈ 𝓝 x, U.InjOn f := by constructor <;> intro h x · obtain ⟨U, ho, hm, hi⟩ := h x; exact ⟨U, ho.mem_nhds hm, hi⟩ · obtain ⟨U, hn, hi⟩ := h x exact ⟨interior U, isOpen_interior, mem_interior_iff_mem_nhds.mpr hn, hi.mono interior_subset⟩ theorem isLocallyInjective_iff_isOpen_diagonal {f : X → Y} : IsLocallyInjective f ↔ IsOpen f.pullbackDiagonal := by simp_rw [isLocallyInjective_iff_nhds, isOpen_iff_mem_nhds, Subtype.forall, Prod.forall, nhds_induced, nhds_prod_eq, Filter.mem_comap] refine ⟨?_, fun h x ↦ ?_⟩ · rintro h x x' hx (rfl : x = x') obtain ⟨U, hn, hi⟩ := h x exact ⟨_, Filter.prod_mem_prod hn hn, fun {p} hp ↦ hi hp.1 hp.2 p.2⟩ · obtain ⟨t, ht, t_sub⟩ := h x x rfl rfl obtain ⟨t₁, h₁, t₂, h₂, prod_sub⟩ := Filter.mem_prod_iff.mp ht exact ⟨t₁ ∩ t₂, Filter.inter_mem h₁ h₂, fun x₁ h₁ x₂ h₂ he ↦ @t_sub ⟨(x₁, x₂), he⟩ (prod_sub ⟨h₁.1, h₂.2⟩)⟩ theorem IsLocallyInjective_iff_isOpenEmbedding {f : X → Y} : IsLocallyInjective f ↔ IsOpenEmbedding (toPullbackDiag f) := by rw [isLocallyInjective_iff_isOpen_diagonal, ← range_toPullbackDiag] exact ⟨fun h ↦ ⟨.toPullbackDiag f, h⟩, fun h ↦ h.isOpen_range⟩ theorem isLocallyInjective_iff_isOpenMap {f : X → Y} : IsLocallyInjective f ↔ IsOpenMap (toPullbackDiag f) := IsLocallyInjective_iff_isOpenEmbedding.trans ⟨IsOpenEmbedding.isOpenMap, .of_continuous_injective_isOpenMap (IsEmbedding.toPullbackDiag f).continuous (injective_toPullbackDiag f)⟩ theorem discreteTopology_iff_locallyInjective (y : Y) : DiscreteTopology X ↔ IsLocallyInjective fun _ : X ↦ y := by rw [discreteTopology_iff_singleton_mem_nhds, isLocallyInjective_iff_nhds] refine forall_congr' fun x ↦ ⟨fun h ↦ ⟨{x}, h, Set.injOn_singleton _ _⟩, fun ⟨U, hU, inj⟩ ↦ ?_⟩ convert hU; ext x'; refine ⟨?_, fun h ↦ inj h (mem_of_mem_nhds hU) rfl⟩ rintro rfl; exact mem_of_mem_nhds hU theorem IsLocallyInjective.comp_left {A} {f : X → Y} (hf : IsLocallyInjective f) {g : Y → A} (hg : g.Injective) : IsLocallyInjective (g ∘ f) := fun x ↦ let ⟨U, hU, hx, inj⟩ := hf x; ⟨U, hU, hx, hg.comp_injOn inj⟩ theorem IsLocallyInjective.comp_right {f : X → Y} (hf : IsLocallyInjective f) {g : A → X} (cont : Continuous g) (hg : g.Injective) : IsLocallyInjective (f ∘ g) := by rw [isLocallyInjective_iff_isOpen_diagonal] at hf ⊢ rw [← hg.preimage_pullbackDiagonal] apply hf.preimage (cont.mapPullback cont) section eqLocus variable {f : X → Y} {g₁ g₂ : A → X} (h₁ : Continuous g₁) (h₂ : Continuous g₂) include h₁ h₂ theorem IsSeparatedMap.isClosed_eqLocus (sep : IsSeparatedMap f) (he : f ∘ g₁ = f ∘ g₂) : IsClosed {a | g₁ a = g₂ a} := let g : A → f.Pullback f := fun a ↦ ⟨⟨g₁ a, g₂ a⟩, congr_fun he a⟩ (isSeparatedMap_iff_isClosed_diagonal.mp sep).preimage (by fun_prop : Continuous g) theorem IsLocallyInjective.isOpen_eqLocus (inj : IsLocallyInjective f) (he : f ∘ g₁ = f ∘ g₂) : IsOpen {a | g₁ a = g₂ a} := let g : A → f.Pullback f := fun a ↦ ⟨⟨g₁ a, g₂ a⟩, congr_fun he a⟩ (isLocallyInjective_iff_isOpen_diagonal.mp inj).preimage (by fun_prop : Continuous g) end eqLocus variable {X E A : Type*} [TopologicalSpace E] [TopologicalSpace A] {p : E → X} namespace IsSeparatedMap variable {s : Set A} {g g₁ g₂ : A → E} (sep : IsSeparatedMap p) (inj : IsLocallyInjective p) include sep inj /-- If `p` is a locally injective separated map, and `A` is a connected space, then two lifts `g₁, g₂ : A → E` of a map `f : A → X` are equal if they agree at one point. -/ theorem eq_of_comp_eq [PreconnectedSpace A] (h₁ : Continuous g₁) (h₂ : Continuous g₂) (he : p ∘ g₁ = p ∘ g₂) (a : A) (ha : g₁ a = g₂ a) : g₁ = g₂ := funext fun a' ↦ by apply (IsClopen.eq_univ ⟨sep.isClosed_eqLocus h₁ h₂ he, inj.isOpen_eqLocus h₁ h₂ he⟩ ⟨a, ha⟩).symm ▸ Set.mem_univ a' theorem eqOn_of_comp_eqOn (hs : IsPreconnected s) (h₁ : ContinuousOn g₁ s) (h₂ : ContinuousOn g₂ s) (he : s.EqOn (p ∘ g₁) (p ∘ g₂)) {a : A} (has : a ∈ s) (ha : g₁ a = g₂ a) : s.EqOn g₁ g₂ := by rw [← Set.restrict_eq_restrict_iff] at he ⊢ rw [continuousOn_iff_continuous_restrict] at h₁ h₂ rw [isPreconnected_iff_preconnectedSpace] at hs exact sep.eq_of_comp_eq inj h₁ h₂ he ⟨a, has⟩ ha theorem const_of_comp [PreconnectedSpace A] (cont : Continuous g) (he : ∀ a a', p (g a) = p (g a')) (a a') : g a = g a' := congr_fun (sep.eq_of_comp_eq inj cont continuous_const (funext fun a ↦ he a a') a' rfl) a theorem constOn_of_comp (hs : IsPreconnected s) (cont : ContinuousOn g s) (he : ∀ a ∈ s, ∀ a' ∈ s, p (g a) = p (g a')) {a a'} (ha : a ∈ s) (ha' : a' ∈ s) : g a = g a' := sep.eqOn_of_comp_eqOn inj hs cont continuous_const.continuousOn (fun a ha ↦ he a ha a' ha') ha' rfl ha end IsSeparatedMap
Urysohn.lean
/- 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.SpecificLimits.Basic import Mathlib.Topology.UrysohnsLemma import Mathlib.Topology.Metrizable.Basic import Mathlib.Topology.ContinuousMap.Bounded.Basic /-! # Urysohn's Metrization Theorem In this file we prove Urysohn's Metrization Theorem: a T₃ topological space with second countable topology `X` is metrizable. First we prove that `X` can be embedded into `l^∞`, then use this embedding to pull back the metric space structure. ## Implementation notes We use `ℕ →ᵇ ℝ`, not `lpSpace` for `l^∞` to avoid heavy imports. -/ open Filter Metric Set Topology open scoped BoundedContinuousFunction namespace TopologicalSpace section RegularSpace variable (X : Type*) [TopologicalSpace X] [RegularSpace X] [SecondCountableTopology X] /-- For a regular topological space with second countable topology, there exists an inducing map to `l^∞ = ℕ →ᵇ ℝ`. -/ theorem exists_isInducing_l_infty : ∃ f : X → ℕ →ᵇ ℝ, IsInducing f := by -- Choose a countable basis, and consider the set `s` of pairs of set `(U, V)` such that `U ∈ B`, -- `V ∈ B`, and `closure U ⊆ V`. rcases exists_countable_basis X with ⟨B, hBc, -, hB⟩ let s : Set (Set X × Set X) := { UV ∈ B ×ˢ B | closure UV.1 ⊆ UV.2 } -- `s` is a countable set. haveI : Encodable s := ((hBc.prod hBc).mono inter_subset_left).toEncodable -- We don't have the space of bounded (possibly discontinuous) functions, so we equip `s` -- with the discrete topology and deal with `s →ᵇ ℝ` instead. letI : TopologicalSpace s := ⊥ haveI : DiscreteTopology s := ⟨rfl⟩ rsuffices ⟨f, hf⟩ : ∃ f : X → s →ᵇ ℝ, IsInducing f · exact ⟨fun x => (f x).extend (Encodable.encode' s) 0, (BoundedContinuousFunction.isometry_extend (Encodable.encode' s) (0 : ℕ →ᵇ ℝ)).isEmbedding.isInducing.comp hf⟩ have hd : ∀ UV : s, Disjoint (closure UV.1.1) UV.1.2ᶜ := fun UV => disjoint_compl_right.mono_right (compl_subset_compl.2 UV.2.2) -- Choose a sequence of `εₙ > 0`, `n : s`, that is bounded above by `1` and tends to zero -- along the `cofinite` filter. obtain ⟨ε, ε01, hε⟩ : ∃ ε : s → ℝ, (∀ UV, ε UV ∈ Ioc (0 : ℝ) 1) ∧ Tendsto ε cofinite (𝓝 0) := by rcases posSumOfEncodable zero_lt_one s with ⟨ε, ε0, c, hεc, hc1⟩ refine ⟨ε, fun UV => ⟨ε0 UV, ?_⟩, hεc.summable.tendsto_cofinite_zero⟩ exact (le_hasSum hεc UV fun _ _ => (ε0 _).le).trans hc1 /- For each `UV = (U, V) ∈ s` we use Urysohn's lemma to choose a function `f UV` that is equal to zero on `U` and is equal to `ε UV` on the complement to `V`. -/ have : ∀ UV : s, ∃ f : C(X, ℝ), EqOn f 0 UV.1.1 ∧ EqOn f (fun _ => ε UV) UV.1.2ᶜ ∧ ∀ x, f x ∈ Icc 0 (ε UV) := by intro UV rcases exists_continuous_zero_one_of_isClosed isClosed_closure (hB.isOpen UV.2.1.2).isClosed_compl (hd UV) with ⟨f, hf₀, hf₁, hf01⟩ exact ⟨ε UV • f, fun x hx => by simp [hf₀ (subset_closure hx)], fun x hx => by simp [hf₁ hx], fun x => ⟨mul_nonneg (ε01 _).1.le (hf01 _).1, mul_le_of_le_one_right (ε01 _).1.le (hf01 _).2⟩⟩ choose f hf0 hfε hf0ε using this have hf01 : ∀ UV x, f UV x ∈ Icc (0 : ℝ) 1 := fun UV x => Icc_subset_Icc_right (ε01 _).2 (hf0ε _ _) -- The embedding is given by `F x UV = f UV x`. set F : X → s →ᵇ ℝ := fun x => ⟨⟨fun UV => f UV x, continuous_of_discreteTopology⟩, 1, fun UV₁ UV₂ => Real.dist_le_of_mem_Icc_01 (hf01 _ _) (hf01 _ _)⟩ have hF : ∀ x UV, F x UV = f UV x := fun _ _ => rfl refine ⟨F, isInducing_iff_nhds.2 fun x => le_antisymm ?_ ?_⟩ · /- First we prove that `F` is continuous. Given `δ > 0`, consider the set `T` of `(U, V) ∈ s` such that `ε (U, V) ≥ δ`. Since `ε` tends to zero, `T` is finite. Since each `f` is continuous, we can choose a neighborhood such that `dist (F y (U, V)) (F x (U, V)) ≤ δ` for any `(U, V) ∈ T`. For `(U, V) ∉ T`, the same inequality is true because both `F y (U, V)` and `F x (U, V)` belong to the interval `[0, ε (U, V)]`. -/ refine (nhds_basis_closedBall.comap _).ge_iff.2 fun δ δ0 => ?_ have h_fin : { UV : s | δ ≤ ε UV }.Finite := by simpa only [← not_lt] using hε (gt_mem_nhds δ0) have : ∀ᶠ y in 𝓝 x, ∀ UV, δ ≤ ε UV → dist (F y UV) (F x UV) ≤ δ := by refine (eventually_all_finite h_fin).2 fun UV _ => ?_ exact (f UV).continuous.tendsto x (closedBall_mem_nhds _ δ0) refine this.mono fun y hy => (BoundedContinuousFunction.dist_le δ0.le).2 fun UV => ?_ rcases le_total δ (ε UV) with hle | hle exacts [hy _ hle, (Real.dist_le_of_mem_Icc (hf0ε _ _) (hf0ε _ _)).trans (by rwa [sub_zero])] · /- Finally, we prove that each neighborhood `V` of `x : X` includes a preimage of a neighborhood of `F x` under `F`. Without loss of generality, `V` belongs to `B`. Choose `U ∈ B` such that `x ∈ V` and `closure V ⊆ U`. Then the preimage of the `(ε (U, V))`-neighborhood of `F x` is included by `V`. -/ refine ((nhds_basis_ball.comap _).le_basis_iff hB.nhds_hasBasis).2 ?_ rintro V ⟨hVB, hxV⟩ rcases hB.exists_closure_subset (hB.mem_nhds hVB hxV) with ⟨U, hUB, hxU, hUV⟩ set UV : ↥s := ⟨(U, V), ⟨hUB, hVB⟩, hUV⟩ refine ⟨ε UV, (ε01 UV).1, fun y (hy : dist (F y) (F x) < ε UV) => ?_⟩ replace hy : dist (F y UV) (F x UV) < ε UV := (BoundedContinuousFunction.dist_coe_le_dist _).trans_lt hy contrapose! hy rw [hF, hF, hfε UV hy, hf0 UV hxU, Pi.zero_apply, dist_zero_right] exact le_abs_self _ /-- *Urysohn's metrization theorem* (Tychonoff's version): a regular topological space with second countable topology `X` is metrizable, i.e., there exists a pseudometric space structure that generates the same topology. -/ instance (priority := 90) PseudoMetrizableSpace.of_regularSpace_secondCountableTopology : PseudoMetrizableSpace X := let ⟨_, hf⟩ := exists_isInducing_l_infty X hf.pseudoMetrizableSpace end RegularSpace variable (X : Type*) [TopologicalSpace X] [T3Space X] [SecondCountableTopology X] /-- A T₃ topological space with second countable topology can be embedded into `l^∞ = ℕ →ᵇ ℝ`. -/ theorem exists_embedding_l_infty : ∃ f : X → ℕ →ᵇ ℝ, IsEmbedding f := let ⟨f, hf⟩ := exists_isInducing_l_infty X; ⟨f, hf.isEmbedding⟩ /-- *Urysohn's metrization theorem* (Tychonoff's version): a T₃ topological space with second countable topology `X` is metrizable, i.e., there exists a metric space structure that generates the same topology. -/ instance (priority := 90) metrizableSpace_of_t3_secondCountable : MetrizableSpace X := let ⟨_, hf⟩ := exists_embedding_l_infty X hf.metrizableSpace end TopologicalSpace
IndepAxioms.lean
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.Order.Interval.Finset.Nat import Mathlib.Data.Set.Finite.Lattice import Mathlib.Data.Matroid.Basic /-! # Matroid Independence and Basis axioms Matroids in mathlib are defined axiomatically in terms of bases, but can be described just as naturally via their collections of independent sets, and in fact such a description, being more 'verbose', can often be useful. As well as this, the definition of a `Matroid` uses an unwieldy 'maximality' axiom that can be dropped in cases where there is some finiteness assumption. This file provides several ways to do define a matroid in terms of its independence or base predicates, using axiom sets that are appropriate in different settings, and often much simpler than the general definition. It also contains `simp` lemmas and typeclasses as appropriate. All the independence axiom sets need nontriviality (the empty set is independent), monotonicity (subsets of independent sets are independent), and some form of 'augmentation' axiom, which allows one to enlarge a non-maximal independent set. This augmentation axiom is still required when there are finiteness assumptions, but is simpler. It just states that if `I` is a finite independent set and `J` is a larger finite independent set, then there exists `e ∈ J \ I` for which `insert e I` is independent. This is the axiom that appears in most of the definitions. ## Implementation Details To facilitate building a matroid from its independent sets, we define a structure `IndepMatroid` which has a ground set `E`, an independence predicate `Indep`, and some axioms as its fields. This structure is another encoding of the data in a `Matroid`; the function `IndepMatroid.matroid` constructs a `Matroid` from an `IndepMatroid`. This is convenient because if one wants to define `M : Matroid α` from a known independence predicate `Ind`, it is easier to define an `M' : IndepMatroid α` so that `M'.Indep = Ind` and then set `M = M'.matroid` than it is to directly define `M` with the base axioms. The simp lemma `IndepMatroid.matroid_indep_iff` is important here; it shows that `M.Indep = Ind`, so the `Matroid` constructed is the right one, and the intermediate `IndepMatroid` can be made essentially invisible by the simplifier when working with `M`. Because of this setup, we don't define any API for `IndepMatroid`, as it would be a redundant copy of the existing API for `Matroid.Indep`. (In particular, one could define a natural equivalence `e : IndepMatroid α ≃ Matroid α` with `e.toFun = IndepMatroid.matroid`, but this would be pointless, as there is no need for the inverse of `e`). ## Main definitions * `IndepMatroid α` is a matroid structure on `α` described in terms of its independent sets in full generality, using infinite versions of the axioms. * `IndepMatroid.matroid` turns `M' : IndepMatroid α` into `M : Matroid α` with `M'.Indep = M.Indep`. * `IndepMatroid.ofFinitary` constructs an `IndepMatroid` whose associated `Matroid` is `Finitary` in the special case where independence of a set is determined only by that of its finite subsets. This construction uses Zorn's lemma. * `IndepMatroid.ofFinitaryCardAugment` is a variant of `IndepMatroid.ofFinitary` where the augmentation axiom resembles the finite augmentation axiom. * `IndepMatroid.ofBdd` constructs an `IndepMatroid` in the case where there is some known absolute upper bound on the size of an independent set. This uses the infinite version of the augmentation axiom; the corresponding `Matroid` is `RankFinite`. * `IndepMatroid.ofBddAugment` is the same as the above, but with a finite augmentation axiom. * `IndepMatroid.ofFinite` constructs an `IndepMatroid` from a finite ground set in terms of its independent sets. * `IndepMatroid.ofFinset` constructs an `IndepMatroid α` whose corresponding matroid is `Finitary` from an independence predicate on `Finset α`. * `Matroid.ofExistsMatroid` constructs a 'copy' of a matroid that is known only existentially, but whose independence predicate is known explicitly. * `Matroid.ofExistsFiniteIsBase` constructs a matroid from its bases, if it is known that one of them is finite. This gives a `RankFinite` matroid. * `Matroid.ofIsBaseOfFinite` constructs a `Finite` matroid from its bases. -/ assert_not_exists Field open Set Matroid variable {α : Type*} section IndepMatroid /-- A matroid as defined by a ground set and an independence predicate. This definition is an implementation detail whose purpose is to organize the multiple different versions of the independence axioms; usually, terms of type `IndepMatroid` should either be directly piped into `IndepMatroid.matroid`, or should be constructed as a private definition which is then converted into a matroid via `IndepMatroid.matroid`. To define a `Matroid α` from a known independence predicate `MyIndep : Set α → Prop` and ground set `E : Set α`, one can either write ``` def myMatroid (…) : Matroid α := IndepMatroid.matroid <| IndepMatroid.ofFoo E MyIndep _ _ … _ ``` or, slightly more indirectly, ``` private def myIndepMatroid (…) : IndepMatroid α := IndepMatroid.ofFoo E MyIndep _ _ … _ def myMatroid (…) : Matroid α := (myIndepMatroid …).matroid ``` In both cases, `IndepMatroid.ofFoo` is either `IndepMatroid.mk`, or one of the several other available constructors for `IndepMatroid`, and the `_` represent the proofs that this constructor requires. After such a definition is made, the facts that `myMatroid.Indep = myIndep` and `myMatroid.E = E` are true by either `rfl` or `simp [myMatroid]`, and can be made directly into @[simp] lemmas. -/ structure IndepMatroid (α : Type*) where /-- The ground set -/ (E : Set α) /-- The independence predicate -/ (Indep : Set α → Prop) (indep_empty : Indep ∅) (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I) (indep_aug : ∀ ⦃I B⦄, Indep I → ¬ Maximal Indep I → Maximal Indep B → ∃ x ∈ B \ I, Indep (insert x I)) (indep_maximal : ∀ X, X ⊆ E → ExistsMaximalSubsetProperty Indep X) (subset_ground : ∀ I, Indep I → I ⊆ E) namespace IndepMatroid /-- An `M : IndepMatroid α` gives a `Matroid α` whose bases are the maximal `M`-independent sets. -/ @[simps] protected def matroid (M : IndepMatroid α) : Matroid α where E := M.E IsBase := Maximal M.Indep Indep := M.Indep indep_iff' := by refine fun I ↦ ⟨fun h ↦ ?_, fun ⟨B, ⟨h, _⟩, hIB'⟩ ↦ M.indep_subset h hIB'⟩ obtain ⟨J, hIJ, hmax⟩ := M.indep_maximal M.E rfl.subset I h (M.subset_ground I h) rw [maximal_and_iff_right_of_imp M.subset_ground] at hmax exact ⟨J, hmax.1, hIJ⟩ exists_isBase := by obtain ⟨B, -, hB⟩ := M.indep_maximal M.E rfl.subset ∅ M.indep_empty <| empty_subset _ rw [maximal_and_iff_right_of_imp M.subset_ground] at hB exact ⟨B, hB.1⟩ isBase_exchange B B' hB hB' e he := by have hnotmax : ¬ Maximal M.Indep (B \ {e}) := fun h ↦ h.not_prop_of_ssuperset (diff_singleton_ssubset.2 he.1) hB.prop obtain ⟨f, hf, hfB⟩ := M.indep_aug (M.indep_subset hB.prop diff_subset) hnotmax hB' replace hf := show f ∈ B' \ B by simpa [show f ≠ e by rintro rfl; exact he.2 hf.1] using hf refine ⟨f, hf, by_contra fun hnot ↦ ?_⟩ obtain ⟨x, hxB, hind⟩ := M.indep_aug hfB hnot hB obtain ⟨-, rfl⟩ : _ ∧ x = e := by simpa [hxB.1] using hxB refine hB.not_prop_of_ssuperset ?_ hind rw [insert_comm, insert_diff_singleton, insert_eq_of_mem he.1] exact ssubset_insert hf.2 maximality := M.indep_maximal subset_ground B hB := M.subset_ground B hB.1 @[simp] theorem matroid_indep_iff {M : IndepMatroid α} {I : Set α} : M.matroid.Indep I ↔ M.Indep I := Iff.rfl /-- If `Indep` has the 'compactness' property that each set `I` satisfies `Indep I` if and only if `Indep J` for every finite subset `J` of `I`, then an `IndepMatroid` can be constructed without proving the maximality axiom. This needs choice, since it can be used to prove that every vector space has a basis. -/ @[simps E] protected def ofFinitary (E : Set α) (Indep : Set α → Prop) (indep_empty : Indep ∅) (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I) (indep_aug : ∀ ⦃I B⦄, Indep I → ¬ Maximal Indep I → Maximal Indep B → ∃ x ∈ B \ I, Indep (insert x I)) (indep_compact : ∀ I, (∀ J, J ⊆ I → J.Finite → Indep J) → Indep I) (subset_ground : ∀ I, Indep I → I ⊆ E) : IndepMatroid α where E := E Indep := Indep indep_empty := indep_empty indep_subset := indep_subset indep_aug := indep_aug indep_maximal := by refine fun X _ I hI hIX ↦ zorn_subset_nonempty {Y | Indep Y ∧ Y ⊆ X} ?_ I ⟨hI, hIX⟩ refine fun Is hIs hchain _ ↦ ⟨⋃₀ Is, ⟨?_, sUnion_subset fun Y hY ↦ (hIs hY).2⟩, fun _ ↦ subset_sUnion_of_mem⟩ refine indep_compact _ fun J hJ hJfin ↦ ?_ have hchoose : ∀ e, e ∈ J → ∃ I, I ∈ Is ∧ (e : α) ∈ I := fun _ he ↦ mem_sUnion.1 <| hJ he choose! f hf using hchoose refine J.eq_empty_or_nonempty.elim (fun hJ ↦ hJ ▸ indep_empty) (fun hne ↦ ?_) obtain ⟨x, hxJ, hxmax⟩ := Finite.exists_maximalFor f _ hJfin hne refine indep_subset (hIs (hf x hxJ).1).1 fun y hyJ ↦ ?_ obtain (hle | hle) := hchain.total (hf _ hxJ).1 (hf _ hyJ).1 · exact hxmax hyJ hle <| (hf _ hyJ).2 · exact hle (hf _ hyJ).2 subset_ground := subset_ground @[simp] theorem ofFinitary_indep (E : Set α) (Indep : Set α → Prop) indep_empty indep_subset indep_aug indep_compact subset_ground : (IndepMatroid.ofFinitary E Indep indep_empty indep_subset indep_aug indep_compact subset_ground).Indep = Indep := rfl instance ofFinitary_finitary (E : Set α) (Indep : Set α → Prop) indep_empty indep_subset indep_aug indep_compact subset_ground : Finitary (IndepMatroid.ofFinitary E Indep indep_empty indep_subset indep_aug indep_compact subset_ground).matroid := ⟨by simpa⟩ /-- An independence predicate satisfying the finite matroid axioms determines a matroid, provided independence is determined by its behaviour on finite sets. -/ @[simps! E] protected def ofFinitaryCardAugment (E : Set α) (Indep : Set α → Prop) (indep_empty : Indep ∅) (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I) (indep_aug : ∀ ⦃I J⦄, Indep I → I.Finite → Indep J → J.Finite → I.ncard < J.ncard → ∃ e ∈ J, e ∉ I ∧ Indep (insert e I)) (indep_compact : ∀ I, (∀ J, J ⊆ I → J.Finite → Indep J) → Indep I) (subset_ground : ∀ I, Indep I → I ⊆ E) : IndepMatroid α := IndepMatroid.ofFinitary (E := E) (Indep := Indep) (indep_empty := indep_empty) (indep_subset := indep_subset) (indep_compact := indep_compact) (indep_aug := by have htofin : ∀ I e, Indep I → ¬ Indep (insert e I) → ∃ I₀, I₀ ⊆ I ∧ I₀.Finite ∧ ¬ Indep (insert e I₀) := by by_contra h; push_neg at h obtain ⟨I, e, -, hIe, h⟩ := h refine hIe <| indep_compact _ fun J hJss hJfin ↦ ?_ exact indep_subset (h (J \ {e}) (by rwa [diff_subset_iff]) hJfin.diff) (by simp) intro I B hI hImax hBmax obtain ⟨e, heI, hins⟩ := exists_insert_of_not_maximal indep_subset hI hImax by_cases heB : e ∈ B · exact ⟨e, ⟨heB, heI⟩, hins⟩ by_contra hcon; push_neg at hcon have heBdep := hBmax.not_prop_of_ssuperset (ssubset_insert heB) -- There is a finite subset `B₀` of `B` so that `B₀ + e` is dependent obtain ⟨B₀, hB₀B, hB₀fin, hB₀e⟩ := htofin B e hBmax.1 heBdep have hB₀ := indep_subset hBmax.1 hB₀B -- `I` has a finite subset `I₀` that doesn't extend into `B₀` have hexI₀ : ∃ I₀, I₀ ⊆ I ∧ I₀.Finite ∧ ∀ x, x ∈ B₀ \ I₀ → ¬Indep (insert x I₀) := by have hch : ∀ (b : ↑(B₀ \ I)), ∃ Ib, Ib ⊆ I ∧ Ib.Finite ∧ ¬Indep (insert (b : α) Ib) := by rintro ⟨b, hb⟩; exact htofin I b hI (hcon b ⟨hB₀B hb.1, hb.2⟩) choose! f hf using hch have : Finite ↑(B₀ \ I) := hB₀fin.diff.to_subtype refine ⟨iUnion f ∪ (B₀ ∩ I), union_subset (iUnion_subset (fun i ↦ (hf i).1)) inter_subset_right, (finite_iUnion fun i ↦ (hf i).2.1).union (hB₀fin.subset inter_subset_left), fun x ⟨hxB₀, hxn⟩ hi ↦ ?_⟩ have hxI : x ∉ I := fun hxI ↦ hxn <| Or.inr ⟨hxB₀, hxI⟩ refine (hf ⟨x, ⟨hxB₀, hxI⟩⟩).2.2 (indep_subset hi <| insert_subset_insert ?_) apply subset_union_of_subset_left apply subset_iUnion obtain ⟨I₀, hI₀I, hI₀fin, hI₀⟩ := hexI₀ set E₀ := insert e (I₀ ∪ B₀) have hE₀fin : E₀.Finite := (hI₀fin.union hB₀fin).insert e -- Extend `B₀` to a maximal independent subset of `I₀ ∪ B₀ + e` obtain ⟨J, ⟨hB₀J, hJ, hJss⟩, hJmax⟩ := Finite.exists_maximalFor (f := id) (s := {J | B₀ ⊆ J ∧ Indep J ∧ J ⊆ E₀}) (hE₀fin.finite_subsets.subset (by simp)) ⟨B₀, Subset.rfl, hB₀, subset_union_right.trans (subset_insert _ _)⟩ have heI₀ : e ∉ I₀ := notMem_subset hI₀I heI have heI₀i : Indep (insert e I₀) := indep_subset hins (insert_subset_insert hI₀I) have heJ : e ∉ J := fun heJ ↦ hB₀e (indep_subset hJ <| insert_subset heJ hB₀J) have hJfin := hE₀fin.subset hJss -- We have `|I₀ + e| ≤ |J|`, since otherwise we could extend the maximal set `J` have hcard : (insert e I₀).ncard ≤ J.ncard := by refine not_lt.1 fun hlt ↦ ?_ obtain ⟨f, hfI, hfJ, hfi⟩ := indep_aug hJ hJfin heI₀i (hI₀fin.insert e) hlt have hfE₀ : f ∈ E₀ := mem_of_mem_of_subset hfI (insert_subset_insert subset_union_left) exact hfJ <| insert_eq_self.1 <| le_imp_eq_iff_le_imp_ge'.2 (hJmax ⟨hB₀J.trans <| subset_insert _ _, hfi, insert_subset hfE₀ hJss⟩) (subset_insert _ _) -- But this means `|I₀| < |J|`, and extending `I₀` into `J` gives a contradiction rw [ncard_insert_of_notMem heI₀ hI₀fin, ← Nat.lt_iff_add_one_le] at hcard obtain ⟨f, hfJ, hfI₀, hfi⟩ := indep_aug (indep_subset hI hI₀I) hI₀fin hJ hJfin hcard exact hI₀ f ⟨Or.elim (hJss hfJ) (fun hfe ↦ (heJ <| hfe ▸ hfJ).elim) (by aesop), hfI₀⟩ hfi ) (subset_ground := subset_ground) @[simp] theorem ofFinitaryCardAugment_indep (E : Set α) (Indep : Set α → Prop) indep_empty indep_subset indep_aug indep_compact subset_ground : (IndepMatroid.ofFinitaryCardAugment E Indep indep_empty indep_subset indep_aug indep_compact subset_ground).Indep = Indep := rfl instance ofFinitaryCardAugment_finitary (E : Set α) (Indep : Set α → Prop) indep_empty indep_subset indep_aug indep_compact subset_ground : Finitary (IndepMatroid.ofFinitaryCardAugment E Indep indep_empty indep_subset indep_aug indep_compact subset_ground).matroid := ⟨by simpa⟩ /-- If there is an absolute upper bound on the size of a set satisfying `P`, then the maximal subset property always holds. -/ theorem _root_.Matroid.existsMaximalSubsetProperty_of_bdd {P : Set α → Prop} (hP : ∃ (n : ℕ), ∀ Y, P Y → Y.encard ≤ n) (X : Set α) : ExistsMaximalSubsetProperty P X := by obtain ⟨n, hP⟩ := hP rintro I hI hIX have hfin : Set.Finite (ncard '' {Y | P Y ∧ I ⊆ Y ∧ Y ⊆ X}) := by rw [finite_iff_bddAbove, bddAbove_def] simp_rw [ENat.le_coe_iff] at hP use n rintro x ⟨Y, ⟨hY,-,-⟩, rfl⟩ obtain ⟨n₀, heq, hle⟩ := hP Y hY rwa [ncard_def, heq, ENat.toNat_coe] obtain ⟨Y, ⟨hY, hIY, hYX⟩, hY'⟩ := Finite.exists_maximalFor' ncard _ hfin ⟨I, hI, rfl.subset, hIX⟩ refine ⟨Y, hIY, ⟨hY, hYX⟩, fun K ⟨hPK, hKX⟩ hYK ↦ ?_⟩ have hKfin : K.Finite := finite_of_encard_le_coe (hP K hPK) refine (eq_of_subset_of_ncard_le hYK ?_ hKfin).symm.subset exact hY' ⟨hPK, hIY.trans hYK, hKX⟩ (ncard_le_ncard hYK hKfin) /-- If there is an absolute upper bound on the size of an independent set, then the maximality axiom isn't needed to define a matroid by independent sets. -/ @[simps E] protected def ofBdd (E : Set α) (Indep : Set α → Prop) (indep_empty : Indep ∅) (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I) (indep_aug : ∀ ⦃I B⦄, Indep I → ¬ Maximal Indep I → Maximal Indep B → ∃ x ∈ B \ I, Indep (insert x I)) (subset_ground : ∀ I, Indep I → I ⊆ E) (indep_bdd : ∃ (n : ℕ), ∀ I, Indep I → I.encard ≤ n) : IndepMatroid α where E := E Indep := Indep indep_empty := indep_empty indep_subset := indep_subset indep_aug := indep_aug indep_maximal X _ := Matroid.existsMaximalSubsetProperty_of_bdd indep_bdd X subset_ground := subset_ground @[simp] theorem ofBdd_indep (E : Set α) Indep indep_empty indep_subset indep_aug subset_ground h_bdd : (IndepMatroid.ofBdd E Indep indep_empty indep_subset indep_aug subset_ground h_bdd).Indep = Indep := rfl /-- `IndepMatroid.ofBdd` constructs a `RankFinite` matroid. -/ instance (E : Set α) (Indep : Set α → Prop) indep_empty indep_subset indep_aug subset_ground h_bdd : RankFinite (IndepMatroid.ofBdd E Indep indep_empty indep_subset indep_aug subset_ground h_bdd).matroid := by obtain ⟨B, hB⟩ := (IndepMatroid.ofBdd E Indep _ _ _ _ _).matroid.exists_isBase refine hB.rankFinite_of_finite ?_ obtain ⟨n, hn⟩ := h_bdd exact finite_of_encard_le_coe <| hn B (by simpa using hB.indep) /-- If there is an absolute upper bound on the size of an independent set, then matroids can be defined using an 'augmentation' axiom similar to the standard definition of finite matroids for independent sets. -/ protected def ofBddAugment (E : Set α) (Indep : Set α → Prop) (indep_empty : Indep ∅) (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I) (indep_aug : ∀ ⦃I J⦄, Indep I → Indep J → I.encard < J.encard → ∃ e ∈ J, e ∉ I ∧ Indep (insert e I)) (indep_bdd : ∃ (n : ℕ), ∀ I, Indep I → I.encard ≤ n) (subset_ground : ∀ I, Indep I → I ⊆ E) : IndepMatroid α := IndepMatroid.ofBdd (E := E) (Indep := Indep) (indep_empty := indep_empty) (indep_subset := indep_subset) (indep_aug := by rintro I B hI hImax hBmax suffices hcard : I.encard < B.encard by obtain ⟨e, heB, heI, hi⟩ := indep_aug hI hBmax.prop hcard exact ⟨e, ⟨heB, heI⟩, hi⟩ refine lt_of_not_ge fun hle ↦ ?_ obtain ⟨x, hxnot, hxI⟩ := exists_insert_of_not_maximal indep_subset hI hImax have hlt : B.encard < (insert x I).encard := by rwa [encard_insert_of_notMem hxnot, ← not_le, ENat.add_one_le_iff, not_lt] rw [encard_ne_top_iff] obtain ⟨n, hn⟩ := indep_bdd exact finite_of_encard_le_coe (hn _ hI) obtain ⟨y, -, hyB, hi⟩ := indep_aug hBmax.prop hxI hlt exact hBmax.not_prop_of_ssuperset (ssubset_insert hyB) hi) (indep_bdd := indep_bdd) (subset_ground := subset_ground) @[simp] theorem ofBddAugment_E (E : Set α) Indep indep_empty indep_subset indep_aug indep_bdd subset_ground : (IndepMatroid.ofBddAugment E Indep indep_empty indep_subset indep_aug indep_bdd subset_ground).E = E := rfl @[simp] theorem ofBddAugment_indep (E : Set α) Indep indep_empty indep_subset indep_aug indep_bdd subset_ground : (IndepMatroid.ofBddAugment E Indep indep_empty indep_subset indep_aug indep_bdd subset_ground).Indep = Indep := rfl instance ofBddAugment_rankFinite (E : Set α) Indep indep_empty indep_subset indep_aug indep_bdd subset_ground : RankFinite (IndepMatroid.ofBddAugment E Indep indep_empty indep_subset indep_aug indep_bdd subset_ground).matroid := by rw [IndepMatroid.ofBddAugment] infer_instance /-- If `E` is finite, then any collection of subsets of `E` satisfying the usual independence axioms determines a matroid -/ protected def ofFinite {E : Set α} (hE : E.Finite) (Indep : Set α → Prop) (indep_empty : Indep ∅) (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I) (indep_aug : ∀ ⦃I J⦄, Indep I → Indep J → I.ncard < J.ncard → ∃ e ∈ J, e ∉ I ∧ Indep (insert e I)) (subset_ground : ∀ ⦃I⦄, Indep I → I ⊆ E) : IndepMatroid α := IndepMatroid.ofBddAugment (E := E) (Indep := Indep) (indep_empty := indep_empty) (indep_subset := indep_subset) (indep_aug := by refine fun {I J} hI hJ hIJ ↦ indep_aug hI hJ ?_ rwa [← Nat.cast_lt (α := ℕ∞), (hE.subset (subset_ground hJ)).cast_ncard_eq, (hE.subset (subset_ground hI)).cast_ncard_eq] ) (indep_bdd := ⟨E.ncard, fun I hI ↦ by rw [hE.cast_ncard_eq] exact encard_le_encard <| subset_ground hI ⟩) (subset_ground := subset_ground) @[simp] theorem ofFinite_E {E : Set α} hE Indep indep_empty indep_subset indep_aug subset_ground : (IndepMatroid.ofFinite (hE : E.Finite) Indep indep_empty indep_subset indep_aug subset_ground).E = E := rfl @[simp] theorem ofFinite_indep {E : Set α} hE Indep indep_empty indep_subset indep_aug subset_ground : (IndepMatroid.ofFinite (hE : E.Finite) Indep indep_empty indep_subset indep_aug subset_ground).Indep = Indep := rfl instance ofFinite_finite {E : Set α} hE Indep indep_empty indep_subset indep_aug subset_ground : (IndepMatroid.ofFinite (hE : E.Finite) Indep indep_empty indep_subset indep_aug subset_ground).matroid.Finite := ⟨hE⟩ /-- An independence predicate on `Finset α` that obeys the finite matroid axioms determines a finitary matroid on `α`. -/ protected def ofFinset [DecidableEq α] (E : Set α) (Indep : Finset α → Prop) (indep_empty : Indep ∅) (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I) (indep_aug : ∀ ⦃I J⦄, Indep I → Indep J → I.card < J.card → ∃ e ∈ J, e ∉ I ∧ Indep (insert e I)) (subset_ground : ∀ ⦃I⦄, Indep I → (I : Set α) ⊆ E) : IndepMatroid α := IndepMatroid.ofFinitaryCardAugment (E := E) (Indep := (fun I ↦ (∀ (J : Finset α), (J : Set α) ⊆ I → Indep J))) (indep_empty := by simpa [subset_empty_iff]) (indep_subset := ( fun _ _ hJ hIJ _ hKI ↦ hJ _ (hKI.trans hIJ) )) (indep_aug := by intro I J hI hIfin hJ hJfin hIJ rw [ncard_eq_toFinset_card _ hIfin, ncard_eq_toFinset_card _ hJfin] at hIJ have aug := indep_aug (hI _ (by simp)) (hJ _ (by simp)) hIJ simp only [Finite.mem_toFinset] at aug obtain ⟨e, heJ, heI, hi⟩ := aug exact ⟨e, heJ, heI, fun K hK ↦ indep_subset hi <| Finset.coe_subset.1 (by simpa)⟩ ) (indep_compact := fun _ h J hJ ↦ h _ hJ J.finite_toSet _ Subset.rfl ) (subset_ground := fun I hI x hxI ↦ by simpa using subset_ground <| hI {x} (by simpa) ) @[simp] theorem ofFinset_E [DecidableEq α] (E : Set α) Indep indep_empty indep_subset indep_aug subset_ground : (IndepMatroid.ofFinset E Indep indep_empty indep_subset indep_aug subset_ground).E = E := rfl @[simp] theorem ofFinset_indep [DecidableEq α] (E : Set α) Indep indep_empty indep_subset indep_aug subset_ground {I : Finset α} : (IndepMatroid.ofFinset E Indep indep_empty indep_subset indep_aug subset_ground).Indep I ↔ Indep I := by simp only [IndepMatroid.ofFinset, ofFinitaryCardAugment_indep, Finset.coe_subset] exact ⟨fun h ↦ h _ Subset.rfl, fun h J hJI ↦ indep_subset h hJI⟩ /-- This can't be `@[simp]`, because it would cause the more useful `Matroid.ofIndepFinset_apply` not to be in simp normal form. -/ theorem ofFinset_indep' [DecidableEq α] (E : Set α) Indep indep_empty indep_subset indep_aug subset_ground {I : Set α} : (IndepMatroid.ofFinset E Indep indep_empty indep_subset indep_aug subset_ground).Indep I ↔ ∀ (J : Finset α), (J : Set α) ⊆ I → Indep J := by simp only [IndepMatroid.ofFinset, ofFinitaryCardAugment_indep] end IndepMatroid section IsBase namespace Matroid /-- Construct an `Matroid` from an independence predicate that agrees with that of some matroid `M`. This is computable even if `M` is only known existentially, or when `M` exists for different reasons in different cases. This can also be used to change the independence predicate to a more useful definitional form. -/ @[simps! E] protected def ofExistsMatroid (E : Set α) (Indep : Set α → Prop) (hM : ∃ (M : Matroid α), E = M.E ∧ ∀ I, M.Indep I ↔ Indep I) : Matroid α := IndepMatroid.matroid <| have hex : ∃ (M : Matroid α), E = M.E ∧ M.Indep = Indep := by obtain ⟨M, rfl, h⟩ := hM; refine ⟨_, rfl, funext (by simp [h])⟩ IndepMatroid.mk (E := E) (Indep := Indep) (indep_empty := by obtain ⟨M, -, rfl⟩ := hex; exact M.empty_indep) (indep_subset := by obtain ⟨M, -, rfl⟩ := hex; exact fun I J hJ hIJ ↦ hJ.subset hIJ) (indep_aug := by obtain ⟨M, -, rfl⟩ := hex; exact Indep.exists_insert_of_not_maximal M) (indep_maximal := by obtain ⟨M, rfl, rfl⟩ := hex; exact M.existsMaximalSubsetProperty_indep) (subset_ground := by obtain ⟨M, rfl, rfl⟩ := hex; exact fun I ↦ Indep.subset_ground) /-- A matroid defined purely in terms of its bases. -/ @[simps E] protected def ofBase (E : Set α) (IsBase : Set α → Prop) (exists_isBase : ∃ B, IsBase B) (isBase_exchange : ExchangeProperty IsBase) (maximality : ∀ X, X ⊆ E → Matroid.ExistsMaximalSubsetProperty (∃ B, IsBase B ∧ · ⊆ B) X) (subset_ground : ∀ B, IsBase B → B ⊆ E) : Matroid α where E := E IsBase := IsBase Indep I := (∃ B, IsBase B ∧ I ⊆ B) indep_iff' _ := Iff.rfl exists_isBase := exists_isBase isBase_exchange := isBase_exchange maximality := maximality subset_ground := subset_ground /-- A collection of bases with the exchange property and at least one finite member is a matroid -/ @[simps! E] protected def ofExistsFiniteIsBase (E : Set α) (IsBase : Set α → Prop) (exists_finite_base : ∃ B, IsBase B ∧ B.Finite) (isBase_exchange : ExchangeProperty IsBase) (subset_ground : ∀ B, IsBase B → B ⊆ E) : Matroid α := Matroid.ofBase (E := E) (IsBase := IsBase) (exists_isBase := by obtain ⟨B,h⟩ := exists_finite_base; exact ⟨B, h.1⟩) (isBase_exchange := isBase_exchange) (maximality := by obtain ⟨B, hB, hfin⟩ := exists_finite_base refine fun X _ ↦ Matroid.existsMaximalSubsetProperty_of_bdd ⟨B.ncard, fun Y ⟨B', hB', hYB'⟩ ↦ ?_⟩ X rw [hfin.cast_ncard_eq, isBase_exchange.encard_isBase_eq hB hB'] exact encard_mono hYB') (subset_ground := subset_ground) @[simp] theorem ofExistsFiniteIsBase_isBase (E : Set α) IsBase exists_finite_base isBase_exchange subset_ground : (Matroid.ofExistsFiniteIsBase E IsBase exists_finite_base isBase_exchange subset_ground).IsBase = IsBase := rfl instance ofExistsFiniteIsBase_rankFinite (E : Set α) IsBase exists_finite_base isBase_exchange subset_ground : RankFinite (Matroid.ofExistsFiniteIsBase E IsBase exists_finite_base isBase_exchange subset_ground) := by obtain ⟨B, hB, hfin⟩ := exists_finite_base exact Matroid.IsBase.rankFinite_of_finite (by simpa) hfin /-- If `E` is finite, then any nonempty collection of its subsets with the exchange property is the collection of bases of a matroid on `E`. -/ protected def ofIsBaseOfFinite {E : Set α} (hE : E.Finite) (IsBase : Set α → Prop) (exists_isBase : ∃ B, IsBase B) (isBase_exchange : ExchangeProperty IsBase) (subset_ground : ∀ B, IsBase B → B ⊆ E) : Matroid α := Matroid.ofExistsFiniteIsBase (E := E) (IsBase := IsBase) (exists_finite_base := let ⟨B, hB⟩ := exists_isBase ⟨B, hB, hE.subset (subset_ground B hB)⟩) (isBase_exchange := isBase_exchange) (subset_ground := subset_ground) @[simp] theorem ofIsBaseOfFinite_E {E : Set α} (hE : E.Finite) IsBase exists_isBase isBase_exchange subset_ground : (Matroid.ofIsBaseOfFinite hE IsBase exists_isBase isBase_exchange subset_ground).E = E := rfl @[simp] theorem ofIsBaseOfFinite_isBase {E : Set α} (hE : E.Finite) IsBase exists_isBase isBase_exchange subset_ground : (Matroid.ofIsBaseOfFinite hE IsBase exists_isBase isBase_exchange subset_ground).IsBase = IsBase := rfl instance ofBaseOfFinite_finite {E : Set α} (hE : E.Finite) IsBase exists_isBase isBase_exchange subset_ground : (Matroid.ofIsBaseOfFinite hE IsBase exists_isBase isBase_exchange subset_ground).Finite := ⟨hE⟩ end Matroid end IsBase end IndepMatroid
countalg.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice. From mathcomp Require Import fintype bigop ssralg. (*****************************************************************************) (* The algebraic part of the algebraic hierarchy for countable types *) (* *) (* This file clones part of ssralg hierarchy for countable types; it does *) (* not cover the left module / algebra interfaces, providing only *) (* countNmodType == countable nmodType interface *) (* countZmodType == countable zmodType interface *) (* countPzSemiRingType == countable pzSemiRingType interface *) (* countNzSemiRingType == countable nzSemiRingType interface *) (* countPzRingType == countable pzRingType interface *) (* countNzRingType == countable nzRingType interface *) (* countComPzSemiRingType == countable comPzSemiRingType interface *) (* countComNzSemiRingType == countable comNzSemiRingType interface *) (* countComPzRingType == countable comPzRingType interface *) (* countComNzRingType == countable comNzRingType interface *) (* countUnitRingType == countable unitRingType interface *) (* countComUnitRingType == countable comUnitRingType interface *) (* countIdomainType == countable idomainType interface *) (* countFieldType == countable fieldType interface *) (* countDecFieldType == countable decFieldType interface *) (* countClosedFieldType == countable closedFieldType interface *) (* *) (* This file provides constructions for both simple extension and algebraic *) (* closure of countable fields. *) (*****************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Import GRing.Theory CodeSeq. Module CountRing. Import GRing.Theory. #[short(type="countNmodType")] HB.structure Definition Nmodule := {M of GRing.Nmodule M & Countable M}. #[short(type="countZmodType")] HB.structure Definition Zmodule := {M of GRing.Zmodule M & Countable M}. #[short(type="countPzSemiRingType")] HB.structure Definition PzSemiRing := {R of GRing.PzSemiRing R & Countable R}. #[short(type="countNzSemiRingType")] HB.structure Definition NzSemiRing := {R of GRing.NzSemiRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing instead.")] Notation SemiRing R := (NzSemiRing R) (only parsing). Module SemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing.sort instead.")] Notation sort := (NzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing.on instead.")] Notation on R := (NzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing.copy instead.")] Notation copy T U := (NzSemiRing.copy T U) (only parsing). End SemiRing. #[short(type="countPzRingType")] HB.structure Definition PzRing := {R of GRing.PzRing R & Countable R}. #[short(type="countNzRingType")] HB.structure Definition NzRing := {R of GRing.NzRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing instead.")] Notation Ring R := (NzRing R) (only parsing). Module Ring. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing.sort instead.")] Notation sort := (NzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing.on instead.")] Notation on R := (NzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing.copy instead.")] Notation copy T U := (NzRing.copy T U) (only parsing). End Ring. #[short(type="countComPzSemiRingType")] HB.structure Definition ComPzSemiRing := {R of GRing.ComPzSemiRing R & Countable R}. #[short(type="countComNzSemiRingType")] HB.structure Definition ComNzSemiRing := {R of GRing.ComNzSemiRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing instead.")] Notation ComSemiRing R := (ComNzSemiRing R) (only parsing). Module ComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing.sort instead.")] Notation sort := (ComNzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing.on instead.")] Notation on R := (ComNzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing.copy instead.")] Notation copy T U := (ComNzSemiRing.copy T U) (only parsing). End ComSemiRing. #[short(type="countComPzRingType")] HB.structure Definition ComPzRing := {R of GRing.ComPzRing R & Countable R}. #[short(type="countComNzRingType")] HB.structure Definition ComNzRing := {R of GRing.ComNzRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing instead.")] Notation ComRing R := (ComNzRing R) (only parsing). Module ComRing. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing.sort instead.")] Notation sort := (ComNzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing.on instead.")] Notation on R := (ComNzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing.copy instead.")] Notation copy T U := (ComNzRing.copy T U) (only parsing). End ComRing. #[short(type="countUnitRingType")] HB.structure Definition UnitRing := {R of GRing.UnitRing R & Countable R}. #[short(type="countComUnitRingType")] HB.structure Definition ComUnitRing := {R of GRing.ComUnitRing R & Countable R}. #[short(type="countIdomainType")] HB.structure Definition IntegralDomain := {R of GRing.IntegralDomain R & Countable R}. #[short(type="countFieldType")] HB.structure Definition Field := {R of GRing.Field R & Countable R}. #[short(type="countDecFieldType")] HB.structure Definition DecidableField := {R of GRing.DecidableField R & Countable R}. #[short(type="countClosedFieldType")] HB.structure Definition ClosedField := {R of GRing.ClosedField R & Countable R}. Module ReguralExports. HB.instance Definition _ (R : countType) := Countable.on R^o. HB.instance Definition _ (R : countNmodType) := Nmodule.on R^o. HB.instance Definition _ (R : countZmodType) := Zmodule.on R^o. HB.instance Definition _ (R : countPzSemiRingType) := PzSemiRing.on R^o. HB.instance Definition _ (R : countNzSemiRingType) := NzSemiRing.on R^o. HB.instance Definition _ (R : countPzRingType) := PzRing.on R^o. HB.instance Definition _ (R : countNzRingType) := NzRing.on R^o. HB.instance Definition _ (R : countComPzSemiRingType) := ComPzSemiRing.on R^o. HB.instance Definition _ (R : countComNzSemiRingType) := ComNzSemiRing.on R^o. HB.instance Definition _ (R : countComPzRingType) := ComPzRing.on R^o. HB.instance Definition _ (R : countComNzRingType) := ComNzRing.on R^o. HB.instance Definition _ (R : countUnitRingType) := UnitRing.on R^o. HB.instance Definition _ (R : countComUnitRingType) := ComUnitRing.on R^o. HB.instance Definition _ (R : countIdomainType) := IntegralDomain.on R^o. HB.instance Definition _ (R : countFieldType) := Field.on R^o. HB.instance Definition _ (R : countDecFieldType) := DecidableField.on R^o. HB.instance Definition _ (R : countClosedFieldType) := ClosedField.on R^o. End ReguralExports. HB.export ReguralExports. End CountRing. Import CountRing. HB.reexport. #[deprecated(since="mathcomp 2.4.0", note="Use countNzSemiRingType instead.")] Notation countSemiRingType := (countNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use countNzRingType instead.")] Notation countRingType := (countNzRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use countComNzSemiRingType instead.")] Notation countComSemiRingType := (countComNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use countComNzRingType instead.")] Notation countComRingType := (countComNzRingType) (only parsing).
ssrfun.v
From mathcomp Require Import ssreflect. From Corelib Require Export ssrfun. From mathcomp Require Export ssrnotations. #[export] Set Warnings "-overwriting-delimiting-key". (* remove above line when requiring Rocq >= 9.0 *) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. (******************) (* v9.1 additions *) (******************) #[export] Set Warnings "-hiding-delimiting-key". Delimit Scope function_scope with FUN. Declare Scope fun_scope. Close Scope fun_scope. Definition injective2 (rT aT1 aT2 : Type) (f : aT1 -> aT2 -> rT) := forall (x1 x2 : aT1) (y1 y2 : aT2), f x1 y1 = f x2 y2 -> (x1 = x2) * (y1 = y2). Arguments injective2 [rT aT1 aT2] f. Lemma inj_omap {aT rT : Type} (f : aT -> rT) : injective f -> injective (omap f). Proof. by move=> injf [?|] [?|] //= [/injf->]. Qed. Lemma omap_id {T : Type} (x : option T) : omap id x = x. Proof. by case: x. Qed. Lemma eq_omap {aT rT : Type} (f g : aT -> rT) : f =1 g -> omap f =1 omap g. Proof. by move=> Ef [?|] //=; rewrite Ef. Qed. Lemma omapK {aT rT : Type} (f : aT -> rT) (g : rT -> aT) : cancel f g -> cancel (omap f) (omap g). Proof. by move=> fK [?|] //=; rewrite fK. Qed. Definition idempotent_op (S : Type) (op : S -> S -> S) := forall x, op x x = x. #[deprecated(since="mathcomp 2.3.0", note="use `idempotent_op` instead")] Notation idempotent:= idempotent_op (only parsing). Definition idempotent_fun (U : Type) (f : U -> U) := f \o f =1 f. Lemma inr_inj {A B} : injective (@inr A B). Proof. by move=> ? ? []. Qed. Lemma inl_inj {A B} : injective (@inl A B). Proof. by move=> ? ? []. Qed. (**********************) (* not yet backported *) (**********************) Lemma taggedK {I : Type} (T_ : I -> Type) (s : {i : I & T_ i}) : Tagged T_ (tagged s) = s. Proof. by case: s. Qed. Definition swap_pair {T1 T2 : Type} (x : T1 * T2) := (x.2, x.1). (* Note that this lemma coudn't be an instance of the [involutive] predicate. *) Lemma swap_pairK {T1 T2 : Type} : @cancel _ (T1 * T2) swap_pair swap_pair. Proof. by case. Qed.
PosDef.lean
/- Copyright (c) 2022 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Mohanad Ahmed -/ import Mathlib.LinearAlgebra.Matrix.Spectrum import Mathlib.LinearAlgebra.QuadraticForm.Basic /-! # Positive Definite Matrices This file defines positive (semi)definite matrices and connects the notion to positive definiteness of quadratic forms. Most results require `𝕜 = ℝ` or `ℂ`. ## Main definitions * `Matrix.PosDef` : a matrix `M : Matrix n n 𝕜` is positive definite if it is hermitian and `xᴴMx` is greater than zero for all nonzero `x`. * `Matrix.PosSemidef` : a matrix `M : Matrix n n 𝕜` is positive semidefinite if it is hermitian and `xᴴMx` is nonnegative for all `x`. ## Main results * `Matrix.posSemidef_iff_eq_conjTranspose_mul_self` : a matrix `M : Matrix n n 𝕜` is positive semidefinite iff it has the form `Bᴴ * B` for some `B`. * `Matrix.posDef_iff_eq_conjTranspose_mul_self` : a matrix `M : Matrix n n 𝕜` is positive definite iff it has the form `Bᴴ * B` for some _invertible_ `B`. * `Matrix.PosSemidef.sqrt` : the unique positive semidefinite square root of a positive semidefinite matrix. (See `Matrix.PosSemidef.eq_sqrt_of_sq_eq` for the proof of uniqueness.) -/ open scoped ComplexOrder namespace Matrix variable {m n R 𝕜 : Type*} variable [Fintype m] [Fintype n] variable [CommRing R] [PartialOrder R] [StarRing R] variable [RCLike 𝕜] open scoped Matrix /-! ## Positive semidefinite matrices -/ /-- A matrix `M : Matrix n n R` is positive semidefinite if it is Hermitian and `xᴴ * M * x` is nonnegative for all `x`. -/ def PosSemidef (M : Matrix n n R) := M.IsHermitian ∧ ∀ x : n → R, 0 ≤ star x ⬝ᵥ (M *ᵥ x) protected theorem PosSemidef.diagonal [StarOrderedRing R] [DecidableEq n] {d : n → R} (h : 0 ≤ d) : PosSemidef (diagonal d) := ⟨isHermitian_diagonal_of_self_adjoint _ <| funext fun i => IsSelfAdjoint.of_nonneg (h i), fun x => by refine Fintype.sum_nonneg fun i => ?_ simpa only [mulVec_diagonal, ← mul_assoc] using conjugate_nonneg (h i) _⟩ /-- A diagonal matrix is positive semidefinite iff its diagonal entries are nonnegative. -/ lemma posSemidef_diagonal_iff [StarOrderedRing R] [DecidableEq n] {d : n → R} : PosSemidef (diagonal d) ↔ (∀ i : n, 0 ≤ d i) := ⟨fun ⟨_, hP⟩ i ↦ by simpa using hP (Pi.single i 1), .diagonal⟩ namespace PosSemidef theorem isHermitian {M : Matrix n n R} (hM : M.PosSemidef) : M.IsHermitian := hM.1 theorem re_dotProduct_nonneg {M : Matrix n n 𝕜} (hM : M.PosSemidef) (x : n → 𝕜) : 0 ≤ RCLike.re (star x ⬝ᵥ (M *ᵥ x)) := RCLike.nonneg_iff.mp (hM.2 _) |>.1 lemma conjTranspose_mul_mul_same {A : Matrix n n R} (hA : PosSemidef A) {m : Type*} [Fintype m] (B : Matrix n m R) : PosSemidef (Bᴴ * A * B) := by constructor · exact isHermitian_conjTranspose_mul_mul B hA.1 · intro x simpa only [star_mulVec, dotProduct_mulVec, vecMul_vecMul] using hA.2 (B *ᵥ x) lemma mul_mul_conjTranspose_same {A : Matrix n n R} (hA : PosSemidef A) {m : Type*} [Fintype m] (B : Matrix m n R) : PosSemidef (B * A * Bᴴ) := by simpa only [conjTranspose_conjTranspose] using hA.conjTranspose_mul_mul_same Bᴴ theorem submatrix {M : Matrix n n R} (hM : M.PosSemidef) (e : m → n) : (M.submatrix e e).PosSemidef := by classical rw [(by simp : M = 1 * M * 1), submatrix_mul (he₂ := Function.bijective_id), submatrix_mul (he₂ := Function.bijective_id), submatrix_id_id] simpa only [conjTranspose_submatrix, conjTranspose_one] using conjTranspose_mul_mul_same hM (Matrix.submatrix 1 id e) theorem transpose {M : Matrix n n R} (hM : M.PosSemidef) : Mᵀ.PosSemidef := by refine ⟨IsHermitian.transpose hM.1, fun x => ?_⟩ convert hM.2 (star x) using 1 rw [mulVec_transpose, dotProduct_mulVec, star_star, dotProduct_comm] @[simp] theorem _root_.Matrix.posSemidef_transpose_iff {M : Matrix n n R} : Mᵀ.PosSemidef ↔ M.PosSemidef := ⟨(by simpa using ·.transpose), .transpose⟩ theorem conjTranspose {M : Matrix n n R} (hM : M.PosSemidef) : Mᴴ.PosSemidef := hM.1.symm ▸ hM @[simp] theorem _root_.Matrix.posSemidef_conjTranspose_iff {M : Matrix n n R} : Mᴴ.PosSemidef ↔ M.PosSemidef := ⟨(by simpa using ·.conjTranspose), .conjTranspose⟩ protected lemma zero : PosSemidef (0 : Matrix n n R) := ⟨isHermitian_zero, by simp⟩ protected lemma one [StarOrderedRing R] [DecidableEq n] : PosSemidef (1 : Matrix n n R) := ⟨isHermitian_one, fun x => by rw [one_mulVec]; exact Fintype.sum_nonneg fun i => star_mul_self_nonneg _⟩ protected theorem natCast [StarOrderedRing R] [DecidableEq n] (d : ℕ) : PosSemidef (d : Matrix n n R) := ⟨isHermitian_natCast _, fun x => by simp only [natCast_mulVec, dotProduct_smul] rw [Nat.cast_smul_eq_nsmul] exact nsmul_nonneg (dotProduct_star_self_nonneg _) _⟩ protected theorem ofNat [StarOrderedRing R] [DecidableEq n] (d : ℕ) [d.AtLeastTwo] : PosSemidef (ofNat(d) : Matrix n n R) := .natCast d protected theorem intCast [StarOrderedRing R] [DecidableEq n] (d : ℤ) (hd : 0 ≤ d) : PosSemidef (d : Matrix n n R) := ⟨isHermitian_intCast _, fun x => by simp only [intCast_mulVec, dotProduct_smul] rw [Int.cast_smul_eq_zsmul] exact zsmul_nonneg (dotProduct_star_self_nonneg _) hd⟩ @[simp] protected theorem _root_.Matrix.posSemidef_intCast_iff [StarOrderedRing R] [DecidableEq n] [Nonempty n] [Nontrivial R] (d : ℤ) : PosSemidef (d : Matrix n n R) ↔ 0 ≤ d := posSemidef_diagonal_iff.trans <| by simp protected lemma pow [StarOrderedRing R] [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) (k : ℕ) : PosSemidef (M ^ k) := match k with | 0 => .one | 1 => by simpa using hM | (k + 2) => by rw [pow_succ, pow_succ'] simpa only [hM.isHermitian.eq] using (hM.pow k).mul_mul_conjTranspose_same M protected lemma inv [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) : M⁻¹.PosSemidef := by by_cases h : IsUnit M.det · have := (conjTranspose_mul_mul_same hM M⁻¹).conjTranspose rwa [mul_nonsing_inv_cancel_right _ _ h, conjTranspose_conjTranspose] at this · rw [nonsing_inv_apply_not_isUnit _ h] exact .zero protected lemma zpow [StarOrderedRing R] [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) (z : ℤ) : (M ^ z).PosSemidef := by obtain ⟨n, rfl | rfl⟩ := z.eq_nat_or_neg · simpa using hM.pow n · simpa using (hM.pow n).inv protected lemma add [AddLeftMono R] {A : Matrix m m R} {B : Matrix m m R} (hA : A.PosSemidef) (hB : B.PosSemidef) : (A + B).PosSemidef := ⟨hA.isHermitian.add hB.isHermitian, fun x => by rw [add_mulVec, dotProduct_add] exact add_nonneg (hA.2 x) (hB.2 x)⟩ /-- The eigenvalues of a positive semi-definite matrix are non-negative -/ lemma eigenvalues_nonneg [DecidableEq n] {A : Matrix n n 𝕜} (hA : Matrix.PosSemidef A) (i : n) : 0 ≤ hA.1.eigenvalues i := (hA.re_dotProduct_nonneg _).trans_eq (hA.1.eigenvalues_eq _).symm theorem det_nonneg [DecidableEq n] {M : Matrix n n 𝕜} (hM : M.PosSemidef) : 0 ≤ M.det := by rw [hM.isHermitian.det_eq_prod_eigenvalues] exact Finset.prod_nonneg fun i _ ↦ by simpa using hM.eigenvalues_nonneg i section sqrt variable [DecidableEq n] {A : Matrix n n 𝕜} (hA : PosSemidef A) /-- The positive semidefinite square root of a positive semidefinite matrix -/ noncomputable def sqrt : Matrix n n 𝕜 := hA.1.eigenvectorUnitary.1 * diagonal ((↑) ∘ (√·) ∘ hA.1.eigenvalues) * (star hA.1.eigenvectorUnitary : Matrix n n 𝕜) open Lean PrettyPrinter.Delaborator SubExpr in /-- Custom elaborator to produce output like `(_ : PosSemidef A).sqrt` in the goal view. -/ @[app_delab Matrix.PosSemidef.sqrt] def delabSqrt : Delab := whenPPOption getPPNotation <| whenNotPPOption getPPAnalysisSkip <| withOverApp 7 <| withOptionAtCurrPos `pp.analysis.skip true do let e ← getExpr guard <| e.isAppOfArity ``Matrix.PosSemidef.sqrt 7 let optionsPerPos ← withNaryArg 6 do return (← read).optionsPerPos.setBool (← getPos) `pp.proofs.withType true withTheReader Context ({· with optionsPerPos}) delab lemma posSemidef_sqrt : PosSemidef hA.sqrt := by apply PosSemidef.mul_mul_conjTranspose_same refine posSemidef_diagonal_iff.mpr fun i ↦ ?_ rw [Function.comp_apply, RCLike.nonneg_iff] constructor · simp only [RCLike.ofReal_re] exact Real.sqrt_nonneg _ · simp only [RCLike.ofReal_im] @[simp] lemma sq_sqrt : hA.sqrt ^ 2 = A := by let C : Matrix n n 𝕜 := hA.1.eigenvectorUnitary let E := diagonal ((↑) ∘ (√·) ∘ hA.1.eigenvalues : n → 𝕜) suffices C * (E * (star C * C) * E) * star C = A by rw [Matrix.PosSemidef.sqrt, pow_two] simpa only [← mul_assoc] using this have : E * E = diagonal ((↑) ∘ hA.1.eigenvalues) := by rw [diagonal_mul_diagonal] congr! with v simp [← pow_two, ← RCLike.ofReal_pow, Real.sq_sqrt (hA.eigenvalues_nonneg v)] simpa [C, this] using hA.1.spectral_theorem.symm @[simp] lemma sqrt_mul_self : hA.sqrt * hA.sqrt = A := by rw [← pow_two, sq_sqrt] include hA in lemma eq_of_sq_eq_sq {B : Matrix n n 𝕜} (hB : PosSemidef B) (hAB : A ^ 2 = B ^ 2) : A = B := by /- This is deceptively hard, much more difficult than the positive *definite* case. We follow a clever proof due to Koeber and Schäfer. The idea is that if `A ≠ B`, then `A - B` has a nonzero real eigenvalue, with eigenvector `v`. Then a manipulation using the identity `A ^ 2 - B ^ 2 = A * (A - B) + (A - B) * B` leads to the conclusion that `⟨v, A v⟩ + ⟨v, B v⟩ = 0`. Since `A, B` are positive semidefinite, both terms must be zero. Thus `⟨v, (A - B) v⟩ = 0`, but this is a nonzero scalar multiple of `⟨v, v⟩`, contradiction. -/ by_contra h_ne let ⟨v, t, ht, hv, hv'⟩ := (hA.1.sub hB.1).exists_eigenvector_of_ne_zero (sub_ne_zero.mpr h_ne) have h_sum : 0 = t * (star v ⬝ᵥ A *ᵥ v + star v ⬝ᵥ B *ᵥ v) := calc 0 = star v ⬝ᵥ (A ^ 2 - B ^ 2) *ᵥ v := by rw [hAB, sub_self, zero_mulVec, dotProduct_zero] _ = star v ⬝ᵥ A *ᵥ (A - B) *ᵥ v + star v ⬝ᵥ (A - B) *ᵥ B *ᵥ v := by rw [mulVec_mulVec, mulVec_mulVec, ← dotProduct_add, ← add_mulVec, mul_sub, sub_mul, add_sub, sub_add_cancel, pow_two, pow_two] _ = t * (star v ⬝ᵥ A *ᵥ v) + (star v) ᵥ* (A - B)ᴴ ⬝ᵥ B *ᵥ v := by rw [hv', mulVec_smul, dotProduct_smul, RCLike.real_smul_eq_coe_mul, dotProduct_mulVec _ (A - B), hA.1.sub hB.1] _ = t * (star v ⬝ᵥ A *ᵥ v + star v ⬝ᵥ B *ᵥ v) := by simp_rw [← star_mulVec, hv', mul_add, ← RCLike.real_smul_eq_coe_mul, ← smul_dotProduct] congr 2 with i simp only [Pi.star_apply, Pi.smul_apply, RCLike.real_smul_eq_coe_mul, star_mul', RCLike.star_def, RCLike.conj_ofReal] replace h_sum : star v ⬝ᵥ A *ᵥ v + star v ⬝ᵥ B *ᵥ v = 0 := by rw [eq_comm, ← mul_zero (t : 𝕜)] at h_sum exact mul_left_cancel₀ (RCLike.ofReal_ne_zero.mpr ht) h_sum have h_van : star v ⬝ᵥ A *ᵥ v = 0 ∧ star v ⬝ᵥ B *ᵥ v = 0 := by refine ⟨le_antisymm ?_ (hA.2 v), le_antisymm ?_ (hB.2 v)⟩ · rw [add_comm, add_eq_zero_iff_eq_neg] at h_sum simpa only [h_sum, neg_nonneg] using hB.2 v · simpa only [add_eq_zero_iff_eq_neg.mp h_sum, neg_nonneg] using hA.2 v have aux : star v ⬝ᵥ (A - B) *ᵥ v = 0 := by rw [sub_mulVec, dotProduct_sub, h_van.1, h_van.2, sub_zero] rw [hv', dotProduct_smul, RCLike.real_smul_eq_coe_mul, ← mul_zero ↑t] at aux exact hv <| dotProduct_star_self_eq_zero.mp <| mul_left_cancel₀ (RCLike.ofReal_ne_zero.mpr ht) aux include hA in lemma sq_eq_sq_iff {B : Matrix n n 𝕜} (hB : PosSemidef B) : A ^ 2 = B ^ 2 ↔ A = B := ⟨eq_of_sq_eq_sq hA hB, fun h => h ▸ rfl⟩ lemma sqrt_sq : (hA.pow 2 : PosSemidef (A ^ 2)).sqrt = A := (hA.pow 2).posSemidef_sqrt.eq_of_sq_eq_sq hA (hA.pow 2).sq_sqrt include hA in lemma eq_sqrt_iff_sq_eq {B : Matrix n n 𝕜} (hB : PosSemidef B) : A = hB.sqrt ↔ A ^ 2 = B := ⟨fun h => h ▸ hB.sq_sqrt, fun h => by subst h; rw [hA.sqrt_sq]⟩ include hA in lemma sqrt_eq_iff_eq_sq {B : Matrix n n 𝕜} (hB : PosSemidef B) : hA.sqrt = B ↔ A = B ^ 2 := by simpa [eq_comm] using eq_sqrt_iff_sq_eq hB hA include hA in @[deprecated eq_sqrt_iff_sq_eq (since := "2025-05-07")] lemma eq_sqrt_of_sq_eq {B : Matrix n n 𝕜} (hB : PosSemidef B) (hAB : A ^ 2 = B) : A = hB.sqrt := eq_sqrt_iff_sq_eq hA hB |>.2 hAB @[simp] lemma sqrt_eq_zero_iff : hA.sqrt = 0 ↔ A = 0 := by rw [sqrt_eq_iff_eq_sq _ .zero, zero_pow two_ne_zero] @[simp] lemma sqrt_eq_one_iff : hA.sqrt = 1 ↔ A = 1 := by rw [sqrt_eq_iff_eq_sq _ .one, one_pow] @[simp] lemma isUnit_sqrt_iff : IsUnit hA.sqrt ↔ IsUnit A := by conv_rhs => rw [← hA.sqrt_mul_self] rw [isUnit_mul_self_iff] lemma inv_sqrt : hA.sqrt⁻¹ = hA.inv.sqrt := by rw [eq_sqrt_iff_sq_eq hA.posSemidef_sqrt.inv, sq, ← Matrix.mul_inv_rev, ← sq, sq_sqrt] end sqrt end PosSemidef @[simp] theorem posSemidef_submatrix_equiv {M : Matrix n n R} (e : m ≃ n) : (M.submatrix e e).PosSemidef ↔ M.PosSemidef := ⟨fun h => by simpa using h.submatrix e.symm, fun h => h.submatrix _⟩ /-- The conjugate transpose of a matrix multiplied by the matrix is positive semidefinite -/ theorem posSemidef_conjTranspose_mul_self [StarOrderedRing R] (A : Matrix m n R) : PosSemidef (Aᴴ * A) := by refine ⟨isHermitian_transpose_mul_self _, fun x => ?_⟩ rw [← mulVec_mulVec, dotProduct_mulVec, vecMul_conjTranspose, star_star] exact Finset.sum_nonneg fun i _ => star_mul_self_nonneg _ /-- A matrix multiplied by its conjugate transpose is positive semidefinite -/ theorem posSemidef_self_mul_conjTranspose [StarOrderedRing R] (A : Matrix m n R) : PosSemidef (A * Aᴴ) := by simpa only [conjTranspose_conjTranspose] using posSemidef_conjTranspose_mul_self Aᴴ lemma eigenvalues_conjTranspose_mul_self_nonneg (A : Matrix m n 𝕜) [DecidableEq n] (i : n) : 0 ≤ (isHermitian_transpose_mul_self A).eigenvalues i := (posSemidef_conjTranspose_mul_self _).eigenvalues_nonneg _ lemma eigenvalues_self_mul_conjTranspose_nonneg (A : Matrix m n 𝕜) [DecidableEq m] (i : m) : 0 ≤ (isHermitian_mul_conjTranspose_self A).eigenvalues i := (posSemidef_self_mul_conjTranspose _).eigenvalues_nonneg _ /-- A matrix is positive semidefinite if and only if it has the form `Bᴴ * B` for some `B`. -/ lemma posSemidef_iff_eq_conjTranspose_mul_self {A : Matrix n n 𝕜} : PosSemidef A ↔ ∃ (B : Matrix n n 𝕜), A = Bᴴ * B := by classical refine ⟨fun hA ↦ ⟨hA.sqrt, ?_⟩, fun ⟨B, hB⟩ ↦ (hB ▸ posSemidef_conjTranspose_mul_self B)⟩ simp_rw [← PosSemidef.sq_sqrt hA, pow_two] rw [hA.posSemidef_sqrt.1] @[deprecated (since := "2025-05-07")] alias posSemidef_iff_eq_transpose_mul_self := posSemidef_iff_eq_conjTranspose_mul_self lemma IsHermitian.posSemidef_of_eigenvalues_nonneg [DecidableEq n] {A : Matrix n n 𝕜} (hA : IsHermitian A) (h : ∀ i : n, 0 ≤ hA.eigenvalues i) : PosSemidef A := by rw [hA.spectral_theorem] refine (posSemidef_diagonal_iff.mpr ?_).mul_mul_conjTranspose_same _ simpa using h /-- For `A` positive semidefinite, we have `x⋆ A x = 0` iff `A x = 0`. -/ theorem PosSemidef.dotProduct_mulVec_zero_iff {A : Matrix n n 𝕜} (hA : PosSemidef A) (x : n → 𝕜) : star x ⬝ᵥ A *ᵥ x = 0 ↔ A *ᵥ x = 0 := by constructor · obtain ⟨B, rfl⟩ := posSemidef_iff_eq_conjTranspose_mul_self.mp hA rw [← Matrix.mulVec_mulVec, dotProduct_mulVec, vecMul_conjTranspose, star_star, dotProduct_star_self_eq_zero] intro h0 rw [h0, mulVec_zero] · intro h0 rw [h0, dotProduct_zero] /-- For `A` positive semidefinite, we have `x⋆ A x = 0` iff `A x = 0` (linear maps version). -/ theorem PosSemidef.toLinearMap₂'_zero_iff [DecidableEq n] {A : Matrix n n 𝕜} (hA : PosSemidef A) (x : n → 𝕜) : Matrix.toLinearMap₂' 𝕜 A (star x) x = 0 ↔ A *ᵥ x = 0 := by simpa only [toLinearMap₂'_apply'] using hA.dotProduct_mulVec_zero_iff x /-! ## Positive definite matrices -/ /-- A matrix `M : Matrix n n R` is positive definite if it is hermitian and `xᴴMx` is greater than zero for all nonzero `x`. -/ def PosDef (M : Matrix n n R) := M.IsHermitian ∧ ∀ x : n → R, x ≠ 0 → 0 < star x ⬝ᵥ (M *ᵥ x) namespace PosDef theorem isHermitian {M : Matrix n n R} (hM : M.PosDef) : M.IsHermitian := hM.1 theorem re_dotProduct_pos {M : Matrix n n 𝕜} (hM : M.PosDef) {x : n → 𝕜} (hx : x ≠ 0) : 0 < RCLike.re (star x ⬝ᵥ (M *ᵥ x)) := RCLike.pos_iff.mp (hM.2 _ hx) |>.1 theorem posSemidef {M : Matrix n n R} (hM : M.PosDef) : M.PosSemidef := by refine ⟨hM.1, ?_⟩ intro x by_cases hx : x = 0 · simp only [hx, zero_dotProduct, star_zero] exact le_rfl · exact le_of_lt (hM.2 x hx) theorem transpose {M : Matrix n n R} (hM : M.PosDef) : Mᵀ.PosDef := by refine ⟨IsHermitian.transpose hM.1, fun x hx => ?_⟩ convert hM.2 (star x) (star_ne_zero.2 hx) using 1 rw [mulVec_transpose, dotProduct_mulVec, star_star, dotProduct_comm] @[simp] theorem transpose_iff {M : Matrix n n R} : Mᵀ.PosDef ↔ M.PosDef := ⟨(by simpa using ·.transpose), .transpose⟩ protected theorem diagonal [StarOrderedRing R] [DecidableEq n] [NoZeroDivisors R] {d : n → R} (h : ∀ i, 0 < d i) : PosDef (diagonal d) := ⟨isHermitian_diagonal_of_self_adjoint _ <| funext fun i => IsSelfAdjoint.of_nonneg (h i).le, fun x hx => by refine Fintype.sum_pos ?_ simp_rw [mulVec_diagonal, ← mul_assoc, Pi.lt_def] obtain ⟨i, hi⟩ := Function.ne_iff.mp hx exact ⟨fun i => conjugate_nonneg (h i).le _, i, conjugate_pos (h _) (isRegular_of_ne_zero hi)⟩⟩ @[simp] theorem _root_.Matrix.posDef_diagonal_iff [StarOrderedRing R] [DecidableEq n] [NoZeroDivisors R] [Nontrivial R] {d : n → R} : PosDef (diagonal d) ↔ ∀ i, 0 < d i := by refine ⟨fun h i => ?_, .diagonal⟩ have := h.2 (Pi.single i 1) simp_rw [mulVec_single_one, ← Pi.single_star, star_one, single_dotProduct, one_mul, col_apply, diagonal_apply_eq, Function.ne_iff] at this exact this ⟨i, by simp⟩ protected theorem one [StarOrderedRing R] [DecidableEq n] [NoZeroDivisors R] : PosDef (1 : Matrix n n R) := ⟨isHermitian_one, fun x hx => by simpa only [one_mulVec, dotProduct_star_self_pos_iff]⟩ protected theorem natCast [StarOrderedRing R] [DecidableEq n] [NoZeroDivisors R] (d : ℕ) (hd : d ≠ 0) : PosDef (d : Matrix n n R) := ⟨isHermitian_natCast _, fun x hx => by simp only [natCast_mulVec, dotProduct_smul] rw [Nat.cast_smul_eq_nsmul] exact nsmul_pos (dotProduct_star_self_pos_iff.mpr hx) hd⟩ @[simp] theorem _root_.Matrix.posDef_natCast_iff [StarOrderedRing R] [DecidableEq n] [NoZeroDivisors R] [Nonempty n] [Nontrivial R] {d : ℕ} : PosDef (d : Matrix n n R) ↔ 0 < d := posDef_diagonal_iff.trans <| by simp protected theorem ofNat [StarOrderedRing R] [DecidableEq n] [NoZeroDivisors R] (d : ℕ) [d.AtLeastTwo] : PosDef (ofNat(d) : Matrix n n R) := .natCast d (NeZero.ne _) protected theorem intCast [StarOrderedRing R] [DecidableEq n] [NoZeroDivisors R] (d : ℤ) (hd : 0 < d) : PosDef (d : Matrix n n R) := ⟨isHermitian_intCast _, fun x hx => by simp only [intCast_mulVec, dotProduct_smul] rw [Int.cast_smul_eq_zsmul] exact zsmul_pos (dotProduct_star_self_pos_iff.mpr hx) hd⟩ @[simp] theorem _root_.Matrix.posDef_intCast_iff [StarOrderedRing R] [DecidableEq n] [NoZeroDivisors R] [Nonempty n] [Nontrivial R] {d : ℤ} : PosDef (d : Matrix n n R) ↔ 0 < d := posDef_diagonal_iff.trans <| by simp protected lemma add_posSemidef [AddLeftMono R] {A : Matrix m m R} {B : Matrix m m R} (hA : A.PosDef) (hB : B.PosSemidef) : (A + B).PosDef := ⟨hA.isHermitian.add hB.isHermitian, fun x hx => by rw [add_mulVec, dotProduct_add] exact add_pos_of_pos_of_nonneg (hA.2 x hx) (hB.2 x)⟩ protected lemma posSemidef_add [AddLeftMono R] {A : Matrix m m R} {B : Matrix m m R} (hA : A.PosSemidef) (hB : B.PosDef) : (A + B).PosDef := ⟨hA.isHermitian.add hB.isHermitian, fun x hx => by rw [add_mulVec, dotProduct_add] exact add_pos_of_nonneg_of_pos (hA.2 x) (hB.2 x hx)⟩ protected lemma add [AddLeftMono R] {A : Matrix m m R} {B : Matrix m m R} (hA : A.PosDef) (hB : B.PosDef) : (A + B).PosDef := hA.add_posSemidef hB.posSemidef lemma conjTranspose_mul_mul_same {A : Matrix n n R} {B : Matrix n m R} (hA : A.PosDef) (hB : Function.Injective B.mulVec) : (Bᴴ * A * B).PosDef := by refine ⟨Matrix.isHermitian_conjTranspose_mul_mul _ hA.1, fun x hx => ?_⟩ have : B *ᵥ x ≠ 0 := fun h => hx <| hB.eq_iff' (mulVec_zero _) |>.1 h simpa only [star_mulVec, dotProduct_mulVec, vecMul_vecMul] using hA.2 _ this lemma mul_mul_conjTranspose_same {A : Matrix n n R} {B : Matrix m n R} (hA : A.PosDef) (hB : Function.Injective B.vecMul) : (B * A * Bᴴ).PosDef := by replace hB := star_injective.comp <| hB.comp star_injective simp_rw [Function.comp_def, star_vecMul, star_star] at hB simpa using hA.conjTranspose_mul_mul_same (B := Bᴴ) hB theorem conjTranspose_mul_self [StarOrderedRing R] [NoZeroDivisors R] (A : Matrix m n R) (hA : Function.Injective A.mulVec) : PosDef (Aᴴ * A) := by classical simpa using conjTranspose_mul_mul_same .one hA theorem conjTranspose {M : Matrix n n R} (hM : M.PosDef) : Mᴴ.PosDef := hM.1.symm ▸ hM @[simp] theorem _root_.Matrix.posDef_conjTranspose_iff {M : Matrix n n R} : Mᴴ.PosDef ↔ M.PosDef := ⟨(by simpa using ·.conjTranspose), .conjTranspose⟩ theorem of_toQuadraticForm' [DecidableEq n] {M : Matrix n n ℝ} (hM : M.IsSymm) (hMq : M.toQuadraticMap'.PosDef) : M.PosDef := by refine ⟨hM, fun x hx => ?_⟩ simp only [toQuadraticMap', QuadraticMap.PosDef, LinearMap.BilinMap.toQuadraticMap_apply, toLinearMap₂'_apply'] at hMq apply hMq x hx theorem toQuadraticForm' [DecidableEq n] {M : Matrix n n ℝ} (hM : M.PosDef) : M.toQuadraticMap'.PosDef := by intro x hx simp only [Matrix.toQuadraticMap', LinearMap.BilinMap.toQuadraticMap_apply, toLinearMap₂'_apply'] apply hM.2 x hx /-- The eigenvalues of a positive definite matrix are positive -/ lemma eigenvalues_pos [DecidableEq n] {A : Matrix n n 𝕜} (hA : Matrix.PosDef A) (i : n) : 0 < hA.1.eigenvalues i := by simp only [hA.1.eigenvalues_eq] exact hA.re_dotProduct_pos <| hA.1.eigenvectorBasis.orthonormal.ne_zero i theorem det_pos [DecidableEq n] {M : Matrix n n 𝕜} (hM : M.PosDef) : 0 < det M := by rw [hM.isHermitian.det_eq_prod_eigenvalues] apply Finset.prod_pos intro i _ simpa using hM.eigenvalues_pos i theorem isUnit [DecidableEq n] {M : Matrix n n 𝕜} (hM : M.PosDef) : IsUnit M := isUnit_iff_isUnit_det _ |>.2 <| hM.det_pos.ne'.isUnit protected theorem inv [DecidableEq n] {M : Matrix n n 𝕜} (hM : M.PosDef) : M⁻¹.PosDef := by have := hM.mul_mul_conjTranspose_same (B := M⁻¹) ?_ · let _ := hM.isUnit.invertible simpa using this.conjTranspose · simp only [Matrix.vecMul_injective_iff_isUnit, isUnit_nonsing_inv_iff, hM.isUnit] @[simp] theorem _root_.Matrix.posDef_inv_iff [DecidableEq n] {M : Matrix n n 𝕜} : M⁻¹.PosDef ↔ M.PosDef := ⟨fun h => letI := (Matrix.isUnit_nonsing_inv_iff.1 <| h.isUnit).invertible Matrix.inv_inv_of_invertible M ▸ h.inv, (·.inv)⟩ lemma posDef_sqrt [DecidableEq n] {M : Matrix n n 𝕜} (hM : M.PosDef) : PosDef hM.posSemidef.sqrt := by apply PosDef.mul_mul_conjTranspose_same · rw [posDef_diagonal_iff] simpa using hM.eigenvalues_pos · apply Matrix.vecMul_injective_of_isUnit convert (Group.isUnit _).map (unitaryGroup n 𝕜).subtype /-- A matrix is positive definite if and only if it has the form `Bᴴ * B` for some invertible `B`. -/ lemma _root_.Matrix.posDef_iff_eq_conjTranspose_mul_self [DecidableEq n] {A : Matrix n n 𝕜} : PosDef A ↔ ∃ B : Matrix n n 𝕜, IsUnit B ∧ A = Bᴴ * B := by refine ⟨fun hA ↦ ⟨_, hA.posDef_sqrt.isUnit, ?_⟩, fun ⟨B, hB, hA⟩ ↦ (hA ▸ ?_)⟩ · simp [hA.posDef_sqrt.isHermitian.eq] · exact conjTranspose_mul_self _ (mulVec_injective_of_isUnit hB) @[deprecated (since := "07-08-2025")] alias posDef_iff_eq_conjTranspose_mul_self := Matrix.posDef_iff_eq_conjTranspose_mul_self /-- A positive semi-definite matrix is positive definite if and only if it is invertible. -/ @[grind =] theorem _root_.Matrix.PosSemidef.posDef_iff_isUnit [DecidableEq n] {x : Matrix n n 𝕜} (hx : x.PosSemidef) : x.PosDef ↔ IsUnit x := by refine ⟨fun h => h.isUnit, fun h => ⟨hx.1, fun v hv => ?_⟩⟩ obtain ⟨y, rfl⟩ := posSemidef_iff_eq_conjTranspose_mul_self.mp hx simp_rw [dotProduct_mulVec, ← vecMul_vecMul, ← star_mulVec, ← dotProduct_mulVec, dotProduct_star_self_pos_iff] contrapose! hv rw [← map_eq_zero_iff (f := (yᴴ * y).mulVecLin) (mulVec_injective_iff_isUnit.mpr h), mulVecLin_apply, ← mulVec_mulVec, hv, mulVec_zero] end PosDef end Matrix namespace QuadraticForm open QuadraticMap variable {n : Type*} [Fintype n] theorem posDef_of_toMatrix' [DecidableEq n] {Q : QuadraticForm ℝ (n → ℝ)} (hQ : Q.toMatrix'.PosDef) : Q.PosDef := by rw [← toQuadraticMap_associated ℝ Q, ← (LinearMap.toMatrix₂' ℝ).left_inv ((associatedHom (R := ℝ) ℝ) Q)] exact hQ.toQuadraticForm' theorem posDef_toMatrix' [DecidableEq n] {Q : QuadraticForm ℝ (n → ℝ)} (hQ : Q.PosDef) : Q.toMatrix'.PosDef := by rw [← toQuadraticMap_associated ℝ Q, ← (LinearMap.toMatrix₂' ℝ).left_inv ((associatedHom (R := ℝ) ℝ) Q)] at hQ exact .of_toQuadraticForm' (isSymm_toMatrix' Q) hQ end QuadraticForm namespace Matrix variable {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n] /-- A positive definite matrix `M` induces a norm `‖x‖ = sqrt (re xᴴMx)`. -/ noncomputable abbrev NormedAddCommGroup.ofMatrix {M : Matrix n n 𝕜} (hM : M.PosDef) : NormedAddCommGroup (n → 𝕜) := @InnerProductSpace.Core.toNormedAddCommGroup _ _ _ _ _ { inner := fun x y => (M *ᵥ y) ⬝ᵥ star x conj_inner_symm := fun x y => by rw [dotProduct_comm, star_dotProduct, starRingEnd_apply, star_star, star_mulVec, dotProduct_comm (M *ᵥ y), dotProduct_mulVec, hM.isHermitian.eq] re_inner_nonneg := fun x => by by_cases h : x = 0 · simp [h] · exact (dotProduct_comm _ (M *ᵥ x) ▸ hM.re_dotProduct_pos h).le definite := fun x (hx : _ ⬝ᵥ _ = 0) => by by_contra! h simpa [hx, lt_irrefl, dotProduct_comm] using hM.re_dotProduct_pos h add_left := by simp only [star_add, dotProduct_add, forall_const] smul_left := fun x y r => by rw [← smul_eq_mul, ← dotProduct_smul, starRingEnd_apply, ← star_smul] } /-- A positive definite matrix `M` induces an inner product `⟪x, y⟫ = xᴴMy`. -/ def InnerProductSpace.ofMatrix {M : Matrix n n 𝕜} (hM : M.PosDef) : @InnerProductSpace 𝕜 (n → 𝕜) _ (NormedAddCommGroup.ofMatrix hM).toSeminormedAddCommGroup := InnerProductSpace.ofCore _ end Matrix