filename
stringlengths
5
42
content
stringlengths
15
319k
Unitary.lean
/- Copyright (c) 2024 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Tactic.Peel import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Unital import Mathlib.Analysis.Complex.Basic /-! # Conditions on unitary elements imposed by the continuous functional calculus ## Main theorems * `unitary_iff_isStarNormal_and_spectrum_subset_unitary`: An element is unitary if and only if it is star-normal and its spectrum lies on the unit circle. -/ section Generic variable {R A : Type*} {p : A → Prop} [CommRing R] [StarRing R] [MetricSpace R] variable [IsTopologicalRing R] [ContinuousStar R] [TopologicalSpace A] [Ring A] [StarRing A] variable [Algebra R A] [ContinuousFunctionalCalculus R A p] lemma cfc_unitary_iff (f : R → R) (a : A) (ha : p a := by cfc_tac) (hf : ContinuousOn f (spectrum R a) := by cfc_cont_tac) : cfc f a ∈ unitary A ↔ ∀ x ∈ spectrum R a, star (f x) * f x = 1 := by simp only [unitary, Submonoid.mem_mk, Subsemigroup.mem_mk, Set.mem_setOf_eq] rw [← IsStarNormal.cfc_map (p := p) f a |>.star_comm_self |>.eq, and_self, ← cfc_one R a, ← cfc_star, ← cfc_mul .., cfc_eq_cfc_iff_eqOn] exact Iff.rfl end Generic section Complex variable {A : Type*} [TopologicalSpace A] [Ring A] [StarRing A] [Algebra ℂ A] [ContinuousFunctionalCalculus ℂ A IsStarNormal] lemma unitary_iff_isStarNormal_and_spectrum_subset_unitary {u : A} : u ∈ unitary A ↔ IsStarNormal u ∧ spectrum ℂ u ⊆ unitary ℂ := by rw [← and_iff_right_of_imp isStarNormal_of_mem_unitary] refine and_congr_right fun hu ↦ ?_ nth_rw 1 [← cfc_id ℂ u] rw [cfc_unitary_iff id u, Set.subset_def] simp only [id_eq, RCLike.star_def, SetLike.mem_coe, unitary.mem_iff_star_mul_self] lemma mem_unitary_of_spectrum_subset_unitary {u : A} [IsStarNormal u] (hu : spectrum ℂ u ⊆ unitary ℂ) : u ∈ unitary A := unitary_iff_isStarNormal_and_spectrum_subset_unitary.mpr ⟨‹_›, hu⟩ lemma spectrum_subset_unitary_of_mem_unitary {u : A} (hu : u ∈ unitary A) : spectrum ℂ u ⊆ unitary ℂ := unitary_iff_isStarNormal_and_spectrum_subset_unitary.mp hu |>.right end Complex
Dual.lean
/- Copyright (c) 2025 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.Module.Submodule.Pointwise import Mathlib.Geometry.Convex.Cone.Pointed /-! # The algebraic dual of a cone Given a bilinear pairing `p` between two `R`-modules `M` and `N` and a set `s` in `M`, we define `PointedCone.dual p C` to be the pointed cone in `N` consisting of all points `y` such that `0 ≤ p x y` for all `x ∈ s`. When the pairing is perfect, this gives us the algebraic dual of a cone. This is developed here. When the pairing is continuous and perfect (as a continuous pairing), this gives us the topological dual instead. See `Mathlib/Analysis/Convex/Cone/Dual.lean` for that case. ## Implementation notes We do not provide a `ConvexCone`-valued version of `PointedCone.dual` since the dual cone of any set always contains `0`, ie is a pointed cone. Furthermore, the strict version `{y | ∀ x ∈ s, 0 < p x y}` is a candidate to the name `ConvexCone.dual`. ## TODO Deduce from `dual_flip_dual_dual_flip` that polyhedral cones are invariant under taking double duals -/ assert_not_exists TopologicalSpace Real Cardinal open Function LinearMap Pointwise Set namespace PointedCone variable {R M N : Type*} [CommRing R] [PartialOrder R] [IsOrderedRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] {p : M →ₗ[R] N →ₗ[R] R} {s t : Set M} {y : N} local notation3 "R≥0" => {c : R // 0 ≤ c} variable (p s) in /-- The dual cone of a set `s` with respect to a bilinear pairing `p` is the cone consisting of all points `y` such that for all points `x ∈ s` we have `0 ≤ p x y`. -/ def dual (s : Set M) : PointedCone R N where carrier := {y | ∀ ⦃x⦄, x ∈ s → 0 ≤ p x y} zero_mem' := by simp add_mem' {u v} hu hv x hx := by rw [map_add]; exact add_nonneg (hu hx) (hv hx) smul_mem' c y hy x hx := by rw [← Nonneg.coe_smul, map_smul]; exact mul_nonneg c.2 (hy hx) @[simp] lemma mem_dual : y ∈ dual p s ↔ ∀ ⦃x⦄, x ∈ s → 0 ≤ p x y := .rfl @[simp] lemma dual_empty : dual p ∅ = ⊤ := by ext; simp @[simp] lemma dual_zero : dual p 0 = ⊤ := by ext; simp lemma dual_univ (hp : Injective p.flip) : dual p univ = 0 := by refine le_antisymm (fun y hy ↦ (_root_.map_eq_zero_iff p.flip hp).1 ?_) (by simp) ext x exact (hy <| mem_univ x).antisymm' <| by simpa using hy <| mem_univ (-x) @[gcongr] lemma dual_le_dual (h : t ⊆ s) : dual p s ≤ dual p t := fun _y hy _x hx ↦ hy (h hx) /-- The inner dual cone of a singleton is given by the preimage of the positive cone under the linear map `p x`. -/ lemma dual_singleton (x : M) : dual p {x} = (positive R R).comap (p x) := by ext; simp lemma dual_union (s t : Set M) : dual p (s ∪ t) = dual p s ⊓ dual p t := by aesop lemma dual_insert (x : M) (s : Set M) : dual p (insert x s) = dual p {x} ⊓ dual p s := by rw [insert_eq, dual_union] lemma dual_iUnion {ι : Sort*} (f : ι → Set M) : dual p (⋃ i, f i) = ⨅ i, dual p (f i) := by ext; simp [forall_swap (α := M)] lemma dual_sUnion (S : Set (Set M)) : dual p (⋃₀ S) = sInf (dual p '' S) := by ext; simp [forall_swap (α := M)] /-- The dual cone of `s` equals the intersection of dual cones of the points in `s`. -/ lemma dual_eq_iInter_dual_singleton (s : Set M) : dual p s = ⋂ i : s, (dual p {i.val} : Set N) := by ext; simp /-- Any set is a subset of its double dual cone. -/ lemma subset_dual_dual : s ⊆ dual p.flip (dual p s) := fun _x hx _y hy ↦ hy hx variable (s) in @[simp] lemma dual_dual_flip_dual : dual p (dual p.flip (dual p s)) = dual p s := le_antisymm (dual_le_dual subset_dual_dual) subset_dual_dual @[simp] lemma dual_flip_dual_dual_flip (s : Set N) : dual p.flip (dual p (dual p.flip s)) = dual p.flip s := dual_dual_flip_dual _ @[simp] lemma dual_span (s : Set M) : dual p (Submodule.span R≥0 s) = dual p s := by refine le_antisymm (dual_le_dual Submodule.subset_span) (fun x hx y hy => ?_) induction hy using Submodule.span_induction with | mem _y h => exact hx h | zero => simp | add y z _hy _hz hy hz => rw [map_add, add_apply]; exact add_nonneg hy hz | smul t y _hy hy => rw [map_smul_of_tower, Nonneg.mk_smul, smul_apply]; exact mul_nonneg t.2 hy end PointedCone
Ray.lean
/- Copyright (c) 2021 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.Order.Module.Algebra import Mathlib.Algebra.Ring.Subring.Units import Mathlib.LinearAlgebra.LinearIndependent.Defs import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Module import Mathlib.Tactic.Positivity.Basic /-! # Rays in modules This file defines rays in modules. ## Main definitions * `SameRay`: two vectors belong to the same ray if they are proportional with a nonnegative coefficient. * `Module.Ray` is a type for the equivalence class of nonzero vectors in a module with some common positive multiple. -/ noncomputable section section StrictOrderedCommSemiring -- TODO: remove `[IsStrictOrderedRing R]` and `@[nolint unusedArguments]`. /-- Two vectors are in the same ray if either one of them is zero or some positive multiples of them are equal (in the typical case over a field, this means one of them is a nonnegative multiple of the other). -/ @[nolint unusedArguments] def SameRay (R : Type*) [CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R] {M : Type*} [AddCommMonoid M] [Module R M] (v₁ v₂ : M) : Prop := v₁ = 0 ∨ v₂ = 0 ∨ ∃ r₁ r₂ : R, 0 < r₁ ∧ 0 < r₂ ∧ r₁ • v₁ = r₂ • v₂ variable {R : Type*} [CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R] variable {M : Type*} [AddCommMonoid M] [Module R M] variable {N : Type*} [AddCommMonoid N] [Module R N] variable (ι : Type*) [DecidableEq ι] namespace SameRay variable {x y z : M} @[simp] theorem zero_left (y : M) : SameRay R 0 y := Or.inl rfl @[simp] theorem zero_right (x : M) : SameRay R x 0 := Or.inr <| Or.inl rfl @[nontriviality] theorem of_subsingleton [Subsingleton M] (x y : M) : SameRay R x y := by rw [Subsingleton.elim x 0] exact zero_left _ @[nontriviality] theorem of_subsingleton' [Subsingleton R] (x y : M) : SameRay R x y := haveI := Module.subsingleton R M of_subsingleton x y /-- `SameRay` is reflexive. -/ @[refl] theorem refl (x : M) : SameRay R x x := by nontriviality R exact Or.inr (Or.inr <| ⟨1, 1, zero_lt_one, zero_lt_one, rfl⟩) protected theorem rfl : SameRay R x x := refl _ /-- `SameRay` is symmetric. -/ @[symm] theorem symm (h : SameRay R x y) : SameRay R y x := (or_left_comm.1 h).imp_right <| Or.imp_right fun ⟨r₁, r₂, h₁, h₂, h⟩ => ⟨r₂, r₁, h₂, h₁, h.symm⟩ /-- If `x` and `y` are nonzero vectors on the same ray, then there exist positive numbers `r₁ r₂` such that `r₁ • x = r₂ • y`. -/ theorem exists_pos (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) : ∃ r₁ r₂ : R, 0 < r₁ ∧ 0 < r₂ ∧ r₁ • x = r₂ • y := (h.resolve_left hx).resolve_left hy theorem sameRay_comm : SameRay R x y ↔ SameRay R y x := ⟨SameRay.symm, SameRay.symm⟩ /-- `SameRay` is transitive unless the vector in the middle is zero and both other vectors are nonzero. -/ theorem trans (hxy : SameRay R x y) (hyz : SameRay R y z) (hy : y = 0 → x = 0 ∨ z = 0) : SameRay R x z := by rcases eq_or_ne x 0 with (rfl | hx); · exact zero_left z rcases eq_or_ne z 0 with (rfl | hz); · exact zero_right x rcases eq_or_ne y 0 with (rfl | hy) · exact (hy rfl).elim (fun h => (hx h).elim) fun h => (hz h).elim rcases hxy.exists_pos hx hy with ⟨r₁, r₂, hr₁, hr₂, h₁⟩ rcases hyz.exists_pos hy hz with ⟨r₃, r₄, hr₃, hr₄, h₂⟩ refine Or.inr (Or.inr <| ⟨r₃ * r₁, r₂ * r₄, mul_pos hr₃ hr₁, mul_pos hr₂ hr₄, ?_⟩) rw [mul_smul, mul_smul, h₁, ← h₂, smul_comm] variable {S : Type*} [CommSemiring S] [PartialOrder S] [Algebra S R] [Module S M] [SMulPosMono S R] [IsScalarTower S R M] {a : S} /-- A vector is in the same ray as a nonnegative multiple of itself. -/ lemma sameRay_nonneg_smul_right (v : M) (h : 0 ≤ a) : SameRay R v (a • v) := by obtain h | h := (algebraMap_nonneg R h).eq_or_lt' · rw [← algebraMap_smul R a v, h, zero_smul] exact zero_right _ · refine Or.inr <| Or.inr ⟨algebraMap S R a, 1, h, by nontriviality R; exact zero_lt_one, ?_⟩ module /-- A nonnegative multiple of a vector is in the same ray as that vector. -/ lemma sameRay_nonneg_smul_left (v : M) (ha : 0 ≤ a) : SameRay R (a • v) v := (sameRay_nonneg_smul_right v ha).symm /-- A vector is in the same ray as a positive multiple of itself. -/ lemma sameRay_pos_smul_right (v : M) (ha : 0 < a) : SameRay R v (a • v) := sameRay_nonneg_smul_right v ha.le /-- A positive multiple of a vector is in the same ray as that vector. -/ lemma sameRay_pos_smul_left (v : M) (ha : 0 < a) : SameRay R (a • v) v := sameRay_nonneg_smul_left v ha.le /-- A vector is in the same ray as a nonnegative multiple of one it is in the same ray as. -/ lemma nonneg_smul_right (h : SameRay R x y) (ha : 0 ≤ a) : SameRay R x (a • y) := h.trans (sameRay_nonneg_smul_right y ha) fun hy => Or.inr <| by rw [hy, smul_zero] /-- A nonnegative multiple of a vector is in the same ray as one it is in the same ray as. -/ lemma nonneg_smul_left (h : SameRay R x y) (ha : 0 ≤ a) : SameRay R (a • x) y := (h.symm.nonneg_smul_right ha).symm /-- A vector is in the same ray as a positive multiple of one it is in the same ray as. -/ theorem pos_smul_right (h : SameRay R x y) (ha : 0 < a) : SameRay R x (a • y) := h.nonneg_smul_right ha.le /-- A positive multiple of a vector is in the same ray as one it is in the same ray as. -/ theorem pos_smul_left (h : SameRay R x y) (hr : 0 < a) : SameRay R (a • x) y := h.nonneg_smul_left hr.le /-- If two vectors are on the same ray then they remain so after applying a linear map. -/ theorem map (f : M →ₗ[R] N) (h : SameRay R x y) : SameRay R (f x) (f y) := (h.imp fun hx => by rw [hx, map_zero]) <| Or.imp (fun hy => by rw [hy, map_zero]) fun ⟨r₁, r₂, hr₁, hr₂, h⟩ => ⟨r₁, r₂, hr₁, hr₂, by rw [← f.map_smul, ← f.map_smul, h]⟩ /-- The images of two vectors under an injective linear map are on the same ray if and only if the original vectors are on the same ray. -/ theorem _root_.Function.Injective.sameRay_map_iff {F : Type*} [FunLike F M N] [LinearMapClass F R M N] {f : F} (hf : Function.Injective f) : SameRay R (f x) (f y) ↔ SameRay R x y := by simp only [SameRay, map_zero, ← hf.eq_iff, map_smul] /-- The images of two vectors under a linear equivalence are on the same ray if and only if the original vectors are on the same ray. -/ @[simp] theorem sameRay_map_iff (e : M ≃ₗ[R] N) : SameRay R (e x) (e y) ↔ SameRay R x y := Function.Injective.sameRay_map_iff (EquivLike.injective e) /-- If two vectors are on the same ray then both scaled by the same action are also on the same ray. -/ theorem smul {S : Type*} [Monoid S] [DistribMulAction S M] [SMulCommClass R S M] (h : SameRay R x y) (s : S) : SameRay R (s • x) (s • y) := h.map (s • (LinearMap.id : M →ₗ[R] M)) /-- If `x` and `y` are on the same ray as `z`, then so is `x + y`. -/ theorem add_left (hx : SameRay R x z) (hy : SameRay R y z) : SameRay R (x + y) z := by rcases eq_or_ne x 0 with (rfl | hx₀); · rwa [zero_add] rcases eq_or_ne y 0 with (rfl | hy₀); · rwa [add_zero] rcases eq_or_ne z 0 with (rfl | hz₀); · apply zero_right rcases hx.exists_pos hx₀ hz₀ with ⟨rx, rz₁, hrx, hrz₁, Hx⟩ rcases hy.exists_pos hy₀ hz₀ with ⟨ry, rz₂, hry, hrz₂, Hy⟩ refine Or.inr (Or.inr ⟨rx * ry, ry * rz₁ + rx * rz₂, mul_pos hrx hry, ?_, ?_⟩) · positivity · convert congr(ry • $Hx + rx • $Hy) using 1 <;> module /-- If `y` and `z` are on the same ray as `x`, then so is `y + z`. -/ theorem add_right (hy : SameRay R x y) (hz : SameRay R x z) : SameRay R x (y + z) := (hy.symm.add_left hz.symm).symm end SameRay set_option linter.unusedVariables false in /-- Nonzero vectors, as used to define rays. This type depends on an unused argument `R` so that `RayVector.Setoid` can be an instance. -/ @[nolint unusedArguments] def RayVector (R M : Type*) [Zero M] := { v : M // v ≠ 0 } instance RayVector.coe [Zero M] : CoeOut (RayVector R M) M where coe := Subtype.val instance {R M : Type*} [Zero M] [Nontrivial M] : Nonempty (RayVector R M) := let ⟨x, hx⟩ := exists_ne (0 : M) ⟨⟨x, hx⟩⟩ variable (R M) /-- The setoid of the `SameRay` relation for the subtype of nonzero vectors. -/ instance RayVector.Setoid : Setoid (RayVector R M) where r x y := SameRay R (x : M) y iseqv := ⟨fun _ => SameRay.refl _, fun h => h.symm, by intros x y z hxy hyz exact hxy.trans hyz fun hy => (y.2 hy).elim⟩ /-- A ray (equivalence class of nonzero vectors with common positive multiples) in a module. -/ def Module.Ray := Quotient (RayVector.Setoid R M) variable {R M} /-- Equivalence of nonzero vectors, in terms of `SameRay`. -/ theorem equiv_iff_sameRay {v₁ v₂ : RayVector R M} : v₁ ≈ v₂ ↔ SameRay R (v₁ : M) v₂ := Iff.rfl variable (R) /-- The ray given by a nonzero vector. -/ def rayOfNeZero (v : M) (h : v ≠ 0) : Module.Ray R M := ⟦⟨v, h⟩⟧ /-- An induction principle for `Module.Ray`, used as `induction x using Module.Ray.ind`. -/ theorem Module.Ray.ind {C : Module.Ray R M → Prop} (h : ∀ (v) (hv : v ≠ 0), C (rayOfNeZero R v hv)) (x : Module.Ray R M) : C x := Quotient.ind (Subtype.rec <| h) x variable {R} instance [Nontrivial M] : Nonempty (Module.Ray R M) := Nonempty.map Quotient.mk' inferInstance /-- The rays given by two nonzero vectors are equal if and only if those vectors satisfy `SameRay`. -/ theorem ray_eq_iff {v₁ v₂ : M} (hv₁ : v₁ ≠ 0) (hv₂ : v₂ ≠ 0) : rayOfNeZero R _ hv₁ = rayOfNeZero R _ hv₂ ↔ SameRay R v₁ v₂ := Quotient.eq' /-- The ray given by a positive multiple of a nonzero vector. -/ @[simp] theorem ray_pos_smul {v : M} (h : v ≠ 0) {r : R} (hr : 0 < r) (hrv : r • v ≠ 0) : rayOfNeZero R (r • v) hrv = rayOfNeZero R v h := (ray_eq_iff _ _).2 <| SameRay.sameRay_pos_smul_left v hr /-- An equivalence between modules implies an equivalence between ray vectors. -/ def RayVector.mapLinearEquiv (e : M ≃ₗ[R] N) : RayVector R M ≃ RayVector R N := Equiv.subtypeEquiv e.toEquiv fun _ => e.map_ne_zero_iff.symm /-- An equivalence between modules implies an equivalence between rays. -/ def Module.Ray.map (e : M ≃ₗ[R] N) : Module.Ray R M ≃ Module.Ray R N := Quotient.congr (RayVector.mapLinearEquiv e) fun _ _=> (SameRay.sameRay_map_iff _).symm @[simp] theorem Module.Ray.map_apply (e : M ≃ₗ[R] N) (v : M) (hv : v ≠ 0) : Module.Ray.map e (rayOfNeZero _ v hv) = rayOfNeZero _ (e v) (e.map_ne_zero_iff.2 hv) := rfl @[simp] theorem Module.Ray.map_refl : (Module.Ray.map <| LinearEquiv.refl R M) = Equiv.refl _ := Equiv.ext <| Module.Ray.ind R fun _ _ => rfl @[simp] theorem Module.Ray.map_symm (e : M ≃ₗ[R] N) : (Module.Ray.map e).symm = Module.Ray.map e.symm := rfl section Action variable {G : Type*} [Group G] [DistribMulAction G M] /-- Any invertible action preserves the non-zeroness of ray vectors. This is primarily of interest when `G = Rˣ` -/ instance {R : Type*} : MulAction G (RayVector R M) where smul r := Subtype.map (r • ·) fun _ => (smul_ne_zero_iff_ne _).2 mul_smul a b _ := Subtype.ext <| mul_smul a b _ one_smul _ := Subtype.ext <| one_smul _ _ variable [SMulCommClass R G M] /-- Any invertible action preserves the non-zeroness of rays. This is primarily of interest when `G = Rˣ` -/ instance : MulAction G (Module.Ray R M) where smul r := Quotient.map (r • ·) fun _ _ h => h.smul _ mul_smul a b := Quotient.ind fun _ => congr_arg Quotient.mk' <| mul_smul a b _ one_smul := Quotient.ind fun _ => congr_arg Quotient.mk' <| one_smul _ _ /-- The action via `LinearEquiv.apply_distribMulAction` corresponds to `Module.Ray.map`. -/ @[simp] theorem Module.Ray.linearEquiv_smul_eq_map (e : M ≃ₗ[R] M) (v : Module.Ray R M) : e • v = Module.Ray.map e v := rfl @[simp] theorem smul_rayOfNeZero (g : G) (v : M) (hv) : g • rayOfNeZero R v hv = rayOfNeZero R (g • v) ((smul_ne_zero_iff_ne _).2 hv) := rfl end Action namespace Module.Ray /-- Scaling by a positive unit is a no-op. -/ theorem units_smul_of_pos (u : Rˣ) (hu : 0 < (u : R)) (v : Module.Ray R M) : u • v = v := by induction v using Module.Ray.ind rw [smul_rayOfNeZero, ray_eq_iff] exact SameRay.sameRay_pos_smul_left _ hu /-- An arbitrary `RayVector` giving a ray. -/ def someRayVector (x : Module.Ray R M) : RayVector R M := Quotient.out x /-- The ray of `someRayVector`. -/ @[simp] theorem someRayVector_ray (x : Module.Ray R M) : (⟦x.someRayVector⟧ : Module.Ray R M) = x := Quotient.out_eq _ /-- An arbitrary nonzero vector giving a ray. -/ def someVector (x : Module.Ray R M) : M := x.someRayVector /-- `someVector` is nonzero. -/ @[simp] theorem someVector_ne_zero (x : Module.Ray R M) : x.someVector ≠ 0 := x.someRayVector.property /-- The ray of `someVector`. -/ @[simp] theorem someVector_ray (x : Module.Ray R M) : rayOfNeZero R _ x.someVector_ne_zero = x := (congr_arg _ (Subtype.coe_eta _ _) :).trans x.out_eq end Module.Ray end StrictOrderedCommSemiring section StrictOrderedCommRing variable {R : Type*} [CommRing R] [PartialOrder R] [IsStrictOrderedRing R] variable {M N : Type*} [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] {x y : M} /-- `SameRay.neg` as an `iff`. -/ @[simp] theorem sameRay_neg_iff : SameRay R (-x) (-y) ↔ SameRay R x y := by simp only [SameRay, neg_eq_zero, smul_neg, neg_inj] alias ⟨SameRay.of_neg, SameRay.neg⟩ := sameRay_neg_iff theorem sameRay_neg_swap : SameRay R (-x) y ↔ SameRay R x (-y) := by rw [← sameRay_neg_iff, neg_neg] theorem eq_zero_of_sameRay_neg_smul_right [NoZeroSMulDivisors R M] {r : R} (hr : r < 0) (h : SameRay R x (r • x)) : x = 0 := by rcases h with (rfl | h₀ | ⟨r₁, r₂, hr₁, hr₂, h⟩) · rfl · simpa [hr.ne] using h₀ · rw [← sub_eq_zero, smul_smul, ← sub_smul, smul_eq_zero] at h refine h.resolve_left (ne_of_gt <| sub_pos.2 ?_) exact (mul_neg_of_pos_of_neg hr₂ hr).trans hr₁ /-- If a vector is in the same ray as its negation, that vector is zero. -/ theorem eq_zero_of_sameRay_self_neg [NoZeroSMulDivisors R M] (h : SameRay R x (-x)) : x = 0 := by nontriviality M; haveI : Nontrivial R := Module.nontrivial R M refine eq_zero_of_sameRay_neg_smul_right (neg_lt_zero.2 (zero_lt_one' R)) ?_ rwa [neg_one_smul] namespace RayVector /-- Negating a nonzero vector. -/ instance {R : Type*} : Neg (RayVector R M) := ⟨fun v => ⟨-v, neg_ne_zero.2 v.prop⟩⟩ /-- Negating a nonzero vector commutes with coercion to the underlying module. -/ @[simp, norm_cast] theorem coe_neg {R : Type*} (v : RayVector R M) : ↑(-v) = -(v : M) := rfl /-- Negating a nonzero vector twice produces the original vector. -/ instance {R : Type*} : InvolutiveNeg (RayVector R M) where neg := Neg.neg neg_neg v := by rw [Subtype.ext_iff, coe_neg, coe_neg, neg_neg] /-- If two nonzero vectors are equivalent, so are their negations. -/ @[simp] theorem equiv_neg_iff {v₁ v₂ : RayVector R M} : -v₁ ≈ -v₂ ↔ v₁ ≈ v₂ := sameRay_neg_iff end RayVector variable (R) /-- Negating a ray. -/ instance : Neg (Module.Ray R M) := ⟨Quotient.map (fun v => -v) fun _ _ => RayVector.equiv_neg_iff.2⟩ /-- The ray given by the negation of a nonzero vector. -/ @[simp] theorem neg_rayOfNeZero (v : M) (h : v ≠ 0) : -rayOfNeZero R _ h = rayOfNeZero R (-v) (neg_ne_zero.2 h) := rfl namespace Module.Ray variable {R} /-- Negating a ray twice produces the original ray. -/ instance : InvolutiveNeg (Module.Ray R M) where neg := Neg.neg neg_neg x := by apply ind R (by simp) x -- Quotient.ind (fun a => congr_arg Quotient.mk' <| neg_neg _) x /-- A ray does not equal its own negation. -/ theorem ne_neg_self [NoZeroSMulDivisors R M] (x : Module.Ray R M) : x ≠ -x := by induction x using Module.Ray.ind with | h x hx => rw [neg_rayOfNeZero, Ne, ray_eq_iff] exact mt eq_zero_of_sameRay_self_neg hx theorem neg_units_smul (u : Rˣ) (v : Module.Ray R M) : -u • v = -(u • v) := by induction v using Module.Ray.ind simp only [smul_rayOfNeZero, Units.smul_def, Units.val_neg, neg_smul, neg_rayOfNeZero] /-- Scaling by a negative unit is negation. -/ theorem units_smul_of_neg (u : Rˣ) (hu : (u : R) < 0) (v : Module.Ray R M) : u • v = -v := by rw [← neg_inj, neg_neg, ← neg_units_smul, units_smul_of_pos] rwa [Units.val_neg, Right.neg_pos_iff] @[simp] protected theorem map_neg (f : M ≃ₗ[R] N) (v : Module.Ray R M) : map f (-v) = -map f v := by induction v using Module.Ray.ind with | h g hg => simp end Module.Ray end StrictOrderedCommRing section LinearOrderedCommRing variable {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] variable {M : Type*} [AddCommGroup M] [Module R M] /-- `SameRay` follows from membership of `MulAction.orbit` for the `Units.posSubgroup`. -/ theorem sameRay_of_mem_orbit {v₁ v₂ : M} (h : v₁ ∈ MulAction.orbit (Units.posSubgroup R) v₂) : SameRay R v₁ v₂ := by rcases h with ⟨⟨r, hr : 0 < r.1⟩, rfl : r • v₂ = v₁⟩ exact SameRay.sameRay_pos_smul_left _ hr /-- Scaling by an inverse unit is the same as scaling by itself. -/ @[simp] theorem units_inv_smul (u : Rˣ) (v : Module.Ray R M) : u⁻¹ • v = u • v := have := mul_self_pos.2 u.ne_zero calc u⁻¹ • v = (u * u) • u⁻¹ • v := Eq.symm <| (u⁻¹ • v).units_smul_of_pos _ (by exact this) _ = u • v := by rw [mul_smul, smul_inv_smul] section variable [NoZeroSMulDivisors R M] @[simp] theorem sameRay_smul_right_iff {v : M} {r : R} : SameRay R v (r • v) ↔ 0 ≤ r ∨ v = 0 := ⟨fun hrv => or_iff_not_imp_left.2 fun hr => eq_zero_of_sameRay_neg_smul_right (not_le.1 hr) hrv, or_imp.2 ⟨SameRay.sameRay_nonneg_smul_right v, fun h => h.symm ▸ SameRay.zero_left _⟩⟩ /-- A nonzero vector is in the same ray as a multiple of itself if and only if that multiple is positive. -/ theorem sameRay_smul_right_iff_of_ne {v : M} (hv : v ≠ 0) {r : R} (hr : r ≠ 0) : SameRay R v (r • v) ↔ 0 < r := by simp only [sameRay_smul_right_iff, hv, or_false, hr.symm.le_iff_lt] @[simp] theorem sameRay_smul_left_iff {v : M} {r : R} : SameRay R (r • v) v ↔ 0 ≤ r ∨ v = 0 := SameRay.sameRay_comm.trans sameRay_smul_right_iff /-- A multiple of a nonzero vector is in the same ray as that vector if and only if that multiple is positive. -/ theorem sameRay_smul_left_iff_of_ne {v : M} (hv : v ≠ 0) {r : R} (hr : r ≠ 0) : SameRay R (r • v) v ↔ 0 < r := SameRay.sameRay_comm.trans (sameRay_smul_right_iff_of_ne hv hr) @[simp] theorem sameRay_neg_smul_right_iff {v : M} {r : R} : SameRay R (-v) (r • v) ↔ r ≤ 0 ∨ v = 0 := by rw [← sameRay_neg_iff, neg_neg, ← neg_smul, sameRay_smul_right_iff, neg_nonneg] theorem sameRay_neg_smul_right_iff_of_ne {v : M} {r : R} (hv : v ≠ 0) (hr : r ≠ 0) : SameRay R (-v) (r • v) ↔ r < 0 := by simp only [sameRay_neg_smul_right_iff, hv, or_false, hr.le_iff_lt] @[simp] theorem sameRay_neg_smul_left_iff {v : M} {r : R} : SameRay R (r • v) (-v) ↔ r ≤ 0 ∨ v = 0 := SameRay.sameRay_comm.trans sameRay_neg_smul_right_iff theorem sameRay_neg_smul_left_iff_of_ne {v : M} {r : R} (hv : v ≠ 0) (hr : r ≠ 0) : SameRay R (r • v) (-v) ↔ r < 0 := SameRay.sameRay_comm.trans <| sameRay_neg_smul_right_iff_of_ne hv hr @[simp] theorem units_smul_eq_self_iff {u : Rˣ} {v : Module.Ray R M} : u • v = v ↔ 0 < (u : R) := by induction v using Module.Ray.ind with | h v hv => simp only [smul_rayOfNeZero, ray_eq_iff, Units.smul_def, sameRay_smul_left_iff_of_ne hv u.ne_zero] @[simp] theorem units_smul_eq_neg_iff {u : Rˣ} {v : Module.Ray R M} : u • v = -v ↔ u.1 < 0 := by rw [← neg_inj, neg_neg, ← Module.Ray.neg_units_smul, units_smul_eq_self_iff, Units.val_neg, neg_pos] /-- Two vectors are in the same ray, or the first is in the same ray as the negation of the second, if and only if they are not linearly independent. -/ theorem sameRay_or_sameRay_neg_iff_not_linearIndependent {x y : M} : SameRay R x y ∨ SameRay R x (-y) ↔ ¬LinearIndependent R ![x, y] := by by_cases hx : x = 0; · simpa [hx] using fun h : LinearIndependent R ![0, y] => h.ne_zero 0 rfl by_cases hy : y = 0; · simpa [hy] using fun h : LinearIndependent R ![x, 0] => h.ne_zero 1 rfl simp_rw [Fintype.not_linearIndependent_iff] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with ((hx0 | hy0 | ⟨r₁, r₂, hr₁, _, h⟩) | (hx0 | hy0 | ⟨r₁, r₂, hr₁, _, h⟩)) · exact False.elim (hx hx0) · exact False.elim (hy hy0) · refine ⟨![r₁, -r₂], ?_⟩ rw [Fin.sum_univ_two, Fin.exists_fin_two] simp [h, hr₁.ne.symm] · exact False.elim (hx hx0) · exact False.elim (hy (neg_eq_zero.1 hy0)) · refine ⟨![r₁, r₂], ?_⟩ rw [Fin.sum_univ_two, Fin.exists_fin_two] simp [h, hr₁.ne.symm] · rcases h with ⟨m, hm, hmne⟩ rw [Fin.sum_univ_two, add_eq_zero_iff_eq_neg] at hm dsimp only [Matrix.cons_val] at hm rcases lt_trichotomy (m 0) 0 with (hm0 | hm0 | hm0) <;> rcases lt_trichotomy (m 1) 0 with (hm1 | hm1 | hm1) · refine Or.inr (Or.inr (Or.inr ⟨-m 0, -m 1, Left.neg_pos_iff.2 hm0, Left.neg_pos_iff.2 hm1, ?_⟩)) linear_combination (norm := module) -hm · exfalso simp [hm1, hx, hm0.ne] at hm · refine Or.inl (Or.inr (Or.inr ⟨-m 0, m 1, Left.neg_pos_iff.2 hm0, hm1, ?_⟩)) linear_combination (norm := module) -hm · exfalso simp [hm0, hy, hm1.ne] at hm · rw [Fin.exists_fin_two] at hmne exact False.elim (not_and_or.2 hmne ⟨hm0, hm1⟩) · exfalso simp [hm0, hy, hm1.ne.symm] at hm · refine Or.inl (Or.inr (Or.inr ⟨m 0, -m 1, hm0, Left.neg_pos_iff.2 hm1, ?_⟩)) rwa [neg_smul] · exfalso simp [hm1, hx, hm0.ne.symm] at hm · refine Or.inr (Or.inr (Or.inr ⟨m 0, m 1, hm0, hm1, ?_⟩)) rwa [smul_neg] /-- Two vectors are in the same ray, or they are nonzero and the first is in the same ray as the negation of the second, if and only if they are not linearly independent. -/ theorem sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent {x y : M} : SameRay R x y ∨ x ≠ 0 ∧ y ≠ 0 ∧ SameRay R x (-y) ↔ ¬LinearIndependent R ![x, y] := by rw [← sameRay_or_sameRay_neg_iff_not_linearIndependent] by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0 <;> simp [hx, hy] end end LinearOrderedCommRing namespace SameRay variable {R : Type*} [Field R] [LinearOrder R] [IsStrictOrderedRing R] variable {M : Type*} [AddCommGroup M] [Module R M] {x y v₁ v₂ : M} theorem exists_pos_left (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) : ∃ r : R, 0 < r ∧ r • x = y := let ⟨r₁, r₂, hr₁, hr₂, h⟩ := h.exists_pos hx hy ⟨r₂⁻¹ * r₁, mul_pos (inv_pos.2 hr₂) hr₁, by rw [mul_smul, h, inv_smul_smul₀ hr₂.ne']⟩ theorem exists_pos_right (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) : ∃ r : R, 0 < r ∧ x = r • y := (h.symm.exists_pos_left hy hx).imp fun _ => And.imp_right Eq.symm /-- If a vector `v₂` is on the same ray as a nonzero vector `v₁`, then it is equal to `c • v₁` for some nonnegative `c`. -/ theorem exists_nonneg_left (h : SameRay R x y) (hx : x ≠ 0) : ∃ r : R, 0 ≤ r ∧ r • x = y := by obtain rfl | hy := eq_or_ne y 0 · exact ⟨0, le_rfl, zero_smul _ _⟩ · exact (h.exists_pos_left hx hy).imp fun _ => And.imp_left le_of_lt /-- If a vector `v₁` is on the same ray as a nonzero vector `v₂`, then it is equal to `c • v₂` for some nonnegative `c`. -/ theorem exists_nonneg_right (h : SameRay R x y) (hy : y ≠ 0) : ∃ r : R, 0 ≤ r ∧ x = r • y := (h.symm.exists_nonneg_left hy).imp fun _ => And.imp_right Eq.symm /-- If vectors `v₁` and `v₂` are on the same ray, then for some nonnegative `a b`, `a + b = 1`, we have `v₁ = a • (v₁ + v₂)` and `v₂ = b • (v₁ + v₂)`. -/ theorem exists_eq_smul_add (h : SameRay R v₁ v₂) : ∃ a b : R, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ v₁ = a • (v₁ + v₂) ∧ v₂ = b • (v₁ + v₂) := by rcases h with (rfl | rfl | ⟨r₁, r₂, h₁, h₂, H⟩) · use 0, 1 simp · use 1, 0 simp · have h₁₂ : 0 < r₁ + r₂ := add_pos h₁ h₂ refine ⟨r₂ / (r₁ + r₂), r₁ / (r₁ + r₂), div_nonneg h₂.le h₁₂.le, div_nonneg h₁.le h₁₂.le, ?_, ?_, ?_⟩ · rw [← add_div, add_comm, div_self h₁₂.ne'] · rw [div_eq_inv_mul, mul_smul, smul_add, ← H, ← add_smul, add_comm r₂, inv_smul_smul₀ h₁₂.ne'] · rw [div_eq_inv_mul, mul_smul, smul_add, H, ← add_smul, add_comm r₂, inv_smul_smul₀ h₁₂.ne'] /-- If vectors `v₁` and `v₂` are on the same ray, then they are nonnegative multiples of the same vector. Actually, this vector can be assumed to be `v₁ + v₂`, see `SameRay.exists_eq_smul_add`. -/ theorem exists_eq_smul (h : SameRay R v₁ v₂) : ∃ (u : M) (a b : R), 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ v₁ = a • u ∧ v₂ = b • u := ⟨v₁ + v₂, h.exists_eq_smul_add⟩ end SameRay section LinearOrderedField variable {R : Type*} [Field R] [LinearOrder R] [IsStrictOrderedRing R] variable {M : Type*} [AddCommGroup M] [Module R M] {x y : M} theorem exists_pos_left_iff_sameRay (hx : x ≠ 0) (hy : y ≠ 0) : (∃ r : R, 0 < r ∧ r • x = y) ↔ SameRay R x y := by refine ⟨fun h => ?_, fun h => h.exists_pos_left hx hy⟩ rcases h with ⟨r, hr, rfl⟩ exact SameRay.sameRay_pos_smul_right x hr theorem exists_pos_left_iff_sameRay_and_ne_zero (hx : x ≠ 0) : (∃ r : R, 0 < r ∧ r • x = y) ↔ SameRay R x y ∧ y ≠ 0 := by constructor · rintro ⟨r, hr, rfl⟩ simp [hx, hr.le, hr.ne'] · rintro ⟨hxy, hy⟩ exact (exists_pos_left_iff_sameRay hx hy).2 hxy theorem exists_nonneg_left_iff_sameRay (hx : x ≠ 0) : (∃ r : R, 0 ≤ r ∧ r • x = y) ↔ SameRay R x y := by refine ⟨fun h => ?_, fun h => h.exists_nonneg_left hx⟩ rcases h with ⟨r, hr, rfl⟩ exact SameRay.sameRay_nonneg_smul_right x hr theorem exists_pos_right_iff_sameRay (hx : x ≠ 0) (hy : y ≠ 0) : (∃ r : R, 0 < r ∧ x = r • y) ↔ SameRay R x y := by rw [SameRay.sameRay_comm] simp_rw [eq_comm (a := x)] exact exists_pos_left_iff_sameRay hy hx theorem exists_pos_right_iff_sameRay_and_ne_zero (hy : y ≠ 0) : (∃ r : R, 0 < r ∧ x = r • y) ↔ SameRay R x y ∧ x ≠ 0 := by rw [SameRay.sameRay_comm] simp_rw [eq_comm (a := x)] exact exists_pos_left_iff_sameRay_and_ne_zero hy theorem exists_nonneg_right_iff_sameRay (hy : y ≠ 0) : (∃ r : R, 0 ≤ r ∧ x = r • y) ↔ SameRay R x y := by rw [SameRay.sameRay_comm] simp_rw [eq_comm (a := x)] exact exists_nonneg_left_iff_sameRay (R := R) hy end LinearOrderedField
List.lean
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Topology.Constructions import Mathlib.Order.Filter.ListTraverse import Mathlib.Tactic.AdaptationNote import Mathlib.Topology.Algebra.Monoid.Defs /-! # Topology on lists and vectors -/ open TopologicalSpace Set Filter open Topology variable {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] instance : TopologicalSpace (List α) := TopologicalSpace.mkOfNhds (traverse nhds) theorem nhds_list (as : List α) : 𝓝 as = traverse 𝓝 as := by refine nhds_mkOfNhds _ _ ?_ ?_ · intro l induction l with | nil => exact le_rfl | cons a l ih => suffices List.cons <$> pure a <*> pure l ≤ List.cons <$> 𝓝 a <*> traverse 𝓝 l by simpa only [functor_norm] using this exact Filter.seq_mono (Filter.map_mono <| pure_le_nhds a) ih · intro l s hs rcases (mem_traverse_iff _ _).1 hs with ⟨u, hu, hus⟩ clear as hs have : ∃ v : List (Set α), l.Forall₂ (fun a s => IsOpen s ∧ a ∈ s) v ∧ sequence v ⊆ s := by induction hu generalizing s with | nil => exists [] simp only [List.forall₂_nil_left_iff] exact ⟨trivial, hus⟩ | cons ht _ ih => rcases mem_nhds_iff.1 ht with ⟨u, hut, hu⟩ rcases ih _ Subset.rfl with ⟨v, hv, hvss⟩ exact ⟨u::v, List.Forall₂.cons hu hv, Subset.trans (Set.seq_mono (Set.image_mono hut) hvss) hus⟩ rcases this with ⟨v, hv, hvs⟩ have : sequence v ∈ traverse 𝓝 l := mem_traverse _ _ <| hv.imp fun a s ⟨hs, ha⟩ => IsOpen.mem_nhds hs ha refine mem_of_superset this fun u hu ↦ ?_ have hu := (List.mem_traverse _ _).1 hu have : List.Forall₂ (fun a s => IsOpen s ∧ a ∈ s) u v := by refine List.Forall₂.flip ?_ replace hv := hv.flip simp only [List.forall₂_and_left, Function.flip_def] at hv ⊢ exact ⟨hv.1, hu.flip⟩ refine mem_of_superset ?_ hvs exact mem_traverse _ _ (this.imp fun a s ⟨hs, ha⟩ => IsOpen.mem_nhds hs ha) @[simp] theorem nhds_nil : 𝓝 ([] : List α) = pure [] := by rw [nhds_list, List.traverse_nil _] theorem nhds_cons (a : α) (l : List α) : 𝓝 (a::l) = List.cons <$> 𝓝 a <*> 𝓝 l := by rw [nhds_list, List.traverse_cons _, ← nhds_list] theorem List.tendsto_cons {a : α} {l : List α} : Tendsto (fun p : α × List α => List.cons p.1 p.2) (𝓝 a ×ˢ 𝓝 l) (𝓝 (a::l)) := by rw [nhds_cons, Tendsto, Filter.map_prod]; exact le_rfl theorem Filter.Tendsto.cons {α : Type*} {f : α → β} {g : α → List β} {a : Filter α} {b : β} {l : List β} (hf : Tendsto f a (𝓝 b)) (hg : Tendsto g a (𝓝 l)) : Tendsto (fun a => List.cons (f a) (g a)) a (𝓝 (b::l)) := List.tendsto_cons.comp (Tendsto.prodMk hf hg) namespace List theorem tendsto_cons_iff {β : Type*} {f : List α → β} {b : Filter β} {a : α} {l : List α} : Tendsto f (𝓝 (a::l)) b ↔ Tendsto (fun p : α × List α => f (p.1::p.2)) (𝓝 a ×ˢ 𝓝 l) b := by have : 𝓝 (a::l) = (𝓝 a ×ˢ 𝓝 l).map fun p : α × List α => p.1::p.2 := by simp only [nhds_cons, Filter.prod_eq, (Filter.map_def _ _).symm, (Filter.seq_eq_filter_seq _ _).symm] simp [-Filter.map_def, Function.comp_def, functor_norm] rw [this, Filter.tendsto_map'_iff]; rfl theorem continuous_cons : Continuous fun x : α × List α => (x.1::x.2 : List α) := continuous_iff_continuousAt.mpr fun ⟨_x, _y⟩ => continuousAt_fst.cons continuousAt_snd theorem tendsto_nhds {β : Type*} {f : List α → β} {r : List α → Filter β} (h_nil : Tendsto f (pure []) (r [])) (h_cons : ∀ l a, Tendsto f (𝓝 l) (r l) → Tendsto (fun p : α × List α => f (p.1::p.2)) (𝓝 a ×ˢ 𝓝 l) (r (a::l))) : ∀ l, Tendsto f (𝓝 l) (r l) | [] => by rwa [nhds_nil] | a::l => by rw [tendsto_cons_iff]; exact h_cons l a (@tendsto_nhds _ _ _ h_nil h_cons l) instance [DiscreteTopology α] : DiscreteTopology (List α) := by rw [discreteTopology_iff_nhds]; intro l; induction l <;> simp [*, nhds_cons] theorem continuousAt_length : ∀ l : List α, ContinuousAt List.length l := by simp only [ContinuousAt, nhds_discrete] refine tendsto_nhds ?_ ?_ · exact tendsto_pure_pure _ _ · intro l a ih dsimp only [List.length] refine Tendsto.comp (tendsto_pure_pure (fun x => x + 1) _) ?_ exact Tendsto.comp ih tendsto_snd /-- Continuity of `insertIdx` in terms of `Tendsto`. -/ theorem tendsto_insertIdx' {a : α} : ∀ {n : ℕ} {l : List α}, Tendsto (fun p : α × List α => p.2.insertIdx n p.1) (𝓝 a ×ˢ 𝓝 l) (𝓝 (l.insertIdx n a)) | 0, _ => tendsto_cons | n + 1, [] => by simp | n + 1, a'::l => by have : 𝓝 a ×ˢ 𝓝 (a'::l) = (𝓝 a ×ˢ (𝓝 a' ×ˢ 𝓝 l)).map fun p : α × α × List α => (p.1, p.2.1::p.2.2) := by simp only [nhds_cons, Filter.prod_eq, ← Filter.map_def, ← Filter.seq_eq_filter_seq] simp [-Filter.map_def, Function.comp_def, functor_norm] rw [this, tendsto_map'_iff] exact (tendsto_fst.comp tendsto_snd).cons ((@tendsto_insertIdx' _ n l).comp <| tendsto_fst.prodMk <| tendsto_snd.comp tendsto_snd) theorem tendsto_insertIdx {β} {n : ℕ} {a : α} {l : List α} {f : β → α} {g : β → List α} {b : Filter β} (hf : Tendsto f b (𝓝 a)) (hg : Tendsto g b (𝓝 l)) : Tendsto (fun b : β => (g b).insertIdx n (f b)) b (𝓝 (l.insertIdx n a)) := tendsto_insertIdx'.comp (hf.prodMk hg) theorem continuous_insertIdx {n : ℕ} : Continuous fun p : α × List α => p.2.insertIdx n p.1 := continuous_iff_continuousAt.mpr fun ⟨a, l⟩ => by rw [ContinuousAt, nhds_prod_eq]; exact tendsto_insertIdx' theorem tendsto_eraseIdx : ∀ {n : ℕ} {l : List α}, Tendsto (eraseIdx · n) (𝓝 l) (𝓝 (eraseIdx l n)) | _, [] => by rw [nhds_nil]; exact tendsto_pure_nhds _ _ | 0, a::l => by rw [tendsto_cons_iff]; exact tendsto_snd | n + 1, a::l => by rw [tendsto_cons_iff] dsimp [eraseIdx] exact tendsto_fst.cons ((@tendsto_eraseIdx n l).comp tendsto_snd) theorem continuous_eraseIdx {n : ℕ} : Continuous fun l : List α => eraseIdx l n := continuous_iff_continuousAt.mpr fun _a => tendsto_eraseIdx @[to_additive] theorem tendsto_prod [MulOneClass α] [ContinuousMul α] {l : List α} : Tendsto List.prod (𝓝 l) (𝓝 l.prod) := by induction l with | nil => simp +contextual [nhds_nil, mem_of_mem_nhds, tendsto_pure_left] | cons x l ih => simp_rw [tendsto_cons_iff, prod_cons] have := continuous_iff_continuousAt.mp continuous_mul (x, l.prod) rw [ContinuousAt, nhds_prod_eq] at this exact this.comp (tendsto_id.prodMap ih) @[to_additive] theorem continuous_prod [MulOneClass α] [ContinuousMul α] : Continuous (prod : List α → α) := continuous_iff_continuousAt.mpr fun _l => tendsto_prod end List namespace List.Vector instance (n : ℕ) : TopologicalSpace (Vector α n) := by unfold Vector; infer_instance theorem tendsto_cons {n : ℕ} {a : α} {l : Vector α n} : Tendsto (fun p : α × Vector α n => p.1 ::ᵥ p.2) (𝓝 a ×ˢ 𝓝 l) (𝓝 (a ::ᵥ l)) := by rw [tendsto_subtype_rng, Vector.cons_val] exact tendsto_fst.cons (Tendsto.comp continuousAt_subtype_val tendsto_snd) theorem tendsto_insertIdx {n : ℕ} {i : Fin (n + 1)} {a : α} : ∀ {l : Vector α n}, Tendsto (fun p : α × Vector α n => insertIdx p.1 i p.2) (𝓝 a ×ˢ 𝓝 l) (𝓝 (insertIdx a i l)) | ⟨l, hl⟩ => by rw [insertIdx, tendsto_subtype_rng] simp only [insertIdx_val] exact List.tendsto_insertIdx tendsto_fst (Tendsto.comp continuousAt_subtype_val tendsto_snd : _) /-- Continuity of `Vector.insertIdx`. -/ theorem continuous_insertIdx' {n : ℕ} {i : Fin (n + 1)} : Continuous fun p : α × Vector α n => Vector.insertIdx p.1 i p.2 := continuous_iff_continuousAt.mpr fun ⟨a, l⟩ => by rw [ContinuousAt, nhds_prod_eq]; exact tendsto_insertIdx theorem continuous_insertIdx {n : ℕ} {i : Fin (n + 1)} {f : β → α} {g : β → Vector α n} (hf : Continuous f) (hg : Continuous g) : Continuous fun b => Vector.insertIdx (f b) i (g b) := continuous_insertIdx'.comp (hf.prodMk hg) theorem continuousAt_eraseIdx {n : ℕ} {i : Fin (n + 1)} : ∀ {l : Vector α (n + 1)}, ContinuousAt (Vector.eraseIdx i) l | ⟨l, hl⟩ => by rw [ContinuousAt, Vector.eraseIdx, tendsto_subtype_rng] simp only [Vector.eraseIdx_val] exact Tendsto.comp List.tendsto_eraseIdx continuousAt_subtype_val theorem continuous_eraseIdx {n : ℕ} {i : Fin (n + 1)} : Continuous (Vector.eraseIdx i : Vector α (n + 1) → Vector α n) := continuous_iff_continuousAt.mpr fun ⟨_a, _l⟩ => continuousAt_eraseIdx end List.Vector
End.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yury Kudryashov -/ import Mathlib.Algebra.Group.Action.Basic import Mathlib.Algebra.Group.Action.Hom import Mathlib.Algebra.Group.End /-! # Interaction between actions and endomorphisms/automorphisms This file provides two things: * The tautological actions by endomorphisms/automorphisms on their base type. * An action by a monoid/group on a type is the same as a hom from the monoid/group to endomorphisms/automorphisms of the type. ## Tags monoid action, group action -/ assert_not_exists MonoidWithZero open Function (Injective Surjective) variable {G M N A α : Type*} /-! ### Tautological actions -/ /-! #### Tautological action by `Function.End` -/ namespace Function.End /-- The tautological action by `Function.End α` on `α`. This is generalized to bundled endomorphisms by: * `Equiv.Perm.applyMulAction` * `AddMonoid.End.applyDistribMulAction` * `AddMonoid.End.applyModule` * `AddAut.applyDistribMulAction` * `MulAut.applyMulDistribMulAction` * `LinearEquiv.applyDistribMulAction` * `LinearMap.applyModule` * `RingHom.applyMulSemiringAction` * `RingAut.applyMulSemiringAction` * `AlgEquiv.applyMulSemiringAction` * `RelHom.applyMulAction` * `RelEmbedding.applyMulAction` * `RelIso.applyMulAction` -/ instance applyMulAction : MulAction (Function.End α) α where smul := (· <| ·) one_smul _ := rfl mul_smul _ _ _ := rfl /-- The tautological additive action by `Additive (Function.End α)` on `α`. -/ instance applyAddAction : AddAction (Additive (Function.End α)) α := inferInstance @[simp] lemma smul_def (f : Function.End α) (a : α) : f • a = f a := rfl --TODO - This statement should be somethting like `toFun (f * g) = toFun f ∘ toFun g` lemma mul_def (f g : Function.End α) : (f * g) = f ∘ g := rfl --TODO - This statement should be somethting like `toFun 1 = id` lemma one_def : (1 : Function.End α) = id := rfl /-- `Function.End.applyMulAction` is faithful. -/ instance apply_FaithfulSMul : FaithfulSMul (Function.End α) α where eq_of_smul_eq_smul := funext end Function.End /-! #### Tautological action by `Equiv.Perm` -/ namespace Equiv.Perm /-- The tautological action by `Equiv.Perm α` on `α`. This generalizes `Function.End.applyMulAction`. -/ instance applyMulAction (α : Type*) : MulAction (Perm α) α where smul f a := f a one_smul _ := rfl mul_smul _ _ _ := rfl @[simp] protected lemma smul_def {α : Type*} (f : Perm α) (a : α) : f • a = f a := rfl /-- `Equiv.Perm.applyMulAction` is faithful. -/ instance applyFaithfulSMul (α : Type*) : FaithfulSMul (Perm α) α := ⟨Equiv.ext⟩ /-- The permutation group of `α` acts transitively on `α`. -/ instance : MulAction.IsPretransitive (Perm α) α := by rw [MulAction.isPretransitive_iff] classical intro x y use Equiv.swap x y simp end Equiv.Perm /-! #### Tautological action by `MulAut` -/ namespace MulAut variable [Monoid M] /-- The tautological action by `MulAut M` on `M`. -/ instance applyMulAction : MulAction (MulAut M) M where smul := (· <| ·) one_smul _ := rfl mul_smul _ _ _ := rfl /-- The tautological action by `MulAut M` on `M`. This generalizes `Function.End.applyMulAction`. -/ instance applyMulDistribMulAction : MulDistribMulAction (MulAut M) M where smul := (· <| ·) one_smul _ := rfl mul_smul _ _ _ := rfl smul_one := map_one smul_mul := map_mul @[simp] protected lemma smul_def (f : MulAut M) (a : M) : f • a = f a := rfl /-- `MulAut.applyDistribMulAction` is faithful. -/ instance apply_faithfulSMul : FaithfulSMul (MulAut M) M where eq_of_smul_eq_smul := MulEquiv.ext end MulAut /-! #### Tautological action by `AddAut` -/ namespace AddAut variable [AddMonoid M] /-- The tautological action by `AddAut M` on `M`. -/ instance applyMulAction : MulAction (AddAut M) M where smul := (· <| ·) one_smul _ := rfl mul_smul _ _ _ := rfl @[simp] protected lemma smul_def (f : AddAut M) (a : M) : f • a = f a := rfl /-- `AddAut.applyDistribMulAction` is faithful. -/ instance apply_faithfulSMul : FaithfulSMul (AddAut M) M where eq_of_smul_eq_smul := AddEquiv.ext end AddAut /-! ### Converting actions to and from homs to the monoid/group of endomorphisms/automorphisms -/ section Monoid variable [Monoid M] /-- The monoid hom representing a monoid action. When `M` is a group, see `MulAction.toPermHom`. -/ def MulAction.toEndHom [MulAction M α] : M →* Function.End α where toFun := (· • ·) map_one' := funext (one_smul M) map_mul' x y := funext (mul_smul x y) /-- The monoid action induced by a monoid hom to `Function.End α` See note [reducible non-instances]. -/ abbrev MulAction.ofEndHom (f : M →* Function.End α) : MulAction M α := .compHom α f end Monoid section AddMonoid variable [AddMonoid M] /-- The additive monoid hom representing an additive monoid action. When `M` is a group, see `AddAction.toPermHom`. -/ def AddAction.toEndHom [AddAction M α] : M →+ Additive (Function.End α) := MonoidHom.toAdditive'' MulAction.toEndHom /-- The additive action induced by a hom to `Additive (Function.End α)` See note [reducible non-instances]. -/ abbrev AddAction.ofEndHom (f : M →+ Additive (Function.End α)) : AddAction M α := .compHom α f end AddMonoid section Group variable (G α) [Group G] [MulAction G α] /-- Given an action of a group `G` on a set `α`, each `g : G` defines a permutation of `α`. -/ @[simps] def MulAction.toPermHom : G →* Equiv.Perm α where toFun := MulAction.toPerm map_one' := Equiv.ext <| one_smul G map_mul' u₁ u₂ := Equiv.ext <| mul_smul (u₁ : G) u₂ end Group section AddGroup variable (G α) [AddGroup G] [AddAction G α] /-- Given an action of an additive group `G` on a set `α`, each `g : G` defines a permutation of `α`. -/ @[simps!] def AddAction.toPermHom : G →+ Additive (Equiv.Perm α) := MonoidHom.toAdditive'' <| MulAction.toPermHom .. end AddGroup section MulDistribMulAction variable (M) [Group G] [Monoid M] [MulDistribMulAction G M] /-- Each element of the group defines a multiplicative monoid isomorphism. This is a stronger version of `MulAction.toPerm`. -/ @[simps +simpRhs] def MulDistribMulAction.toMulEquiv (x : G) : M ≃* M := { MulDistribMulAction.toMonoidHom M x, MulAction.toPermHom G M x with } variable (G) in /-- Each element of the group defines a multiplicative monoid isomorphism. This is a stronger version of `MulAction.toPermHom`. -/ @[simps] def MulDistribMulAction.toMulAut : G →* MulAut M where toFun := MulDistribMulAction.toMulEquiv M map_one' := MulEquiv.ext (one_smul _) map_mul' _ _ := MulEquiv.ext (mul_smul _ _) end MulDistribMulAction section Arrow variable [Group G] [MulAction G A] [Monoid M] attribute [local instance] arrowMulDistribMulAction /-- Given groups `G H` with `G` acting on `A`, `G` acts by multiplicative automorphisms on `A → H`. -/ @[simps!] def mulAutArrow : G →* MulAut (A → M) := MulDistribMulAction.toMulAut _ _ end Arrow
Shapes.lean
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.CategoryTheory.Limits.Types.Colimits import Mathlib.CategoryTheory.Limits.Types.Limits import Mathlib.Logic.Function.Coequalizer import Mathlib.Tactic.CategoryTheory.Elementwise /-! # Special shapes for limits in `Type`. The general shape (co)limits defined in `CategoryTheory.Limits.Types` are intended for use through the limits API, and the actual implementation should mostly be considered "sealed". In this file, we provide definitions of the "standard" special shapes of limits in `Type`, giving the expected definitional implementation: * the terminal object is `PUnit` * the binary product of `X` and `Y` is `X × Y` * the product of a family `f : J → Type` is `Π j, f j` * the coproduct of a family `f : J → Type` is `Σ j, f j` * the binary coproduct of `X` and `Y` is the sum type `X ⊕ Y` * the equalizer of a pair of maps `(g, h)` is the subtype `{x : Y // g x = h x}` * the coequalizer of a pair of maps `(f, g)` is the quotient of `Y` by `∀ x : Y, f x ~ g x` * the pullback of `f : X ⟶ Z` and `g : Y ⟶ Z` is the subtype `{ p : X × Y // f p.1 = g p.2 }` of the product * multiequalizers We first construct terms of `IsLimit` and `LimitCone`, and then provide isomorphisms with the types generated by the `HasLimit` API. As an example, when setting up the monoidal category structure on `Type` we use the `Types.terminalLimitCone` and `Types.binaryProductLimitCone` definitions. -/ universe v u open CategoryTheory Limits namespace CategoryTheory.Limits.Types example : HasProducts.{v} (Type v) := inferInstance example [UnivLE.{v, u}] : HasProducts.{v} (Type u) := inferInstance -- This shortcut instance is required in `Mathlib/CategoryTheory/Closed/Types.lean`, -- although I don't understand why, and wish it wasn't. instance : HasProducts.{v} (Type v) := inferInstance /-- A restatement of `Types.Limit.lift_π_apply` that uses `Pi.π` and `Pi.lift`. -/ -- The increased `@[simp]` priority here results in a minor speed up in -- `Mathlib/CategoryTheory/Sites/EqualizerSheafCondition.lean`. @[simp 1001] theorem pi_lift_π_apply {β : Type v} [Small.{u} β] (f : β → Type u) {P : Type u} (s : ∀ b, P ⟶ f b) (b : β) (x : P) : (Pi.π f b : (piObj f) → f b) (@Pi.lift β _ _ f _ P s x) = s b x := congr_fun (limit.lift_π (Fan.mk P s) ⟨b⟩) x /-- A restatement of `Types.Limit.lift_π_apply` that uses `Pi.π` and `Pi.lift`, with specialized universes. -/ theorem pi_lift_π_apply' {β : Type v} (f : β → Type v) {P : Type v} (s : ∀ b, P ⟶ f b) (b : β) (x : P) : (Pi.π f b : (piObj f) → f b) (@Pi.lift β _ _ f _ P s x) = s b x := by simp /-- A restatement of `Types.Limit.map_π_apply` that uses `Pi.π` and `Pi.map`. -/ @[simp] theorem pi_map_π_apply {β : Type v} [Small.{u} β] {f g : β → Type u} (α : ∀ j, f j ⟶ g j) (b : β) (x) : (Pi.π g b : ∏ᶜ g → g b) (Pi.map α x) = α b ((Pi.π f b : ∏ᶜ f → f b) x) := Limit.map_π_apply.{v, u} _ _ _ /-- A restatement of `Types.Limit.map_π_apply` that uses `Pi.π` and `Pi.map`, with specialized universes. -/ theorem pi_map_π_apply' {β : Type v} {f g : β → Type v} (α : ∀ j, f j ⟶ g j) (b : β) (x) : (Pi.π g b : ∏ᶜ g → g b) (Pi.map α x) = α b ((Pi.π f b : ∏ᶜ f → f b) x) := by simp /-- The category of types has `PUnit` as a terminal object. -/ def terminalLimitCone : Limits.LimitCone (Functor.empty (Type u)) where -- Porting note: tidy was able to fill the structure automatically cone := { pt := PUnit π := (Functor.uniqueFromEmpty _).hom } isLimit := { lift := fun _ _ => PUnit.unit fac := fun _ => by rintro ⟨⟨⟩⟩ } /-- The terminal object in `Type u` is `PUnit`. -/ noncomputable def terminalIso : ⊤_ Type u ≅ PUnit := limit.isoLimitCone terminalLimitCone.{u, 0} /-- The terminal object in `Type u` is `PUnit`. -/ noncomputable def isTerminalPunit : IsTerminal (PUnit : Type u) := terminalIsTerminal.ofIso terminalIso noncomputable instance : Inhabited (⊤_ (Type u)) := ⟨@terminal.from (Type u) _ _ (ULift (Fin 1)) (ULift.up 0)⟩ instance : Subsingleton (⊤_ (Type u)) := ⟨fun a b => congr_fun (@Subsingleton.elim (_ ⟶ ⊤_ (Type u)) _ (fun _ => a) (fun _ => b)) (ULift.up (0 : Fin 1))⟩ noncomputable instance : Unique (⊤_ (Type u)) := Unique.mk' _ /-- A type is terminal if and only if it contains exactly one element. -/ noncomputable def isTerminalEquivUnique (X : Type u) : IsTerminal X ≃ Unique X := equivOfSubsingletonOfSubsingleton (fun h => ((Iso.toEquiv (terminalIsoIsTerminal h).symm).unique)) (fun _ => IsTerminal.ofIso terminalIsTerminal (Equiv.toIso (Equiv.ofUnique _ _))) /-- A type is terminal if and only if it is isomorphic to `PUnit`. -/ noncomputable def isTerminalEquivIsoPUnit (X : Type u) : IsTerminal X ≃ (X ≅ PUnit) := by calc IsTerminal X ≃ Unique X := isTerminalEquivUnique _ _ ≃ (X ≃ PUnit.{u + 1}) := uniqueEquivEquivUnique _ _ _ ≃ (X ≅ PUnit) := equivEquivIso /-- The category of types has `PEmpty` as an initial object. -/ def initialColimitCocone : Limits.ColimitCocone (Functor.empty (Type u)) where -- Porting note: tidy was able to fill the structure automatically cocone := { pt := PEmpty ι := (Functor.uniqueFromEmpty _).inv } isColimit := { desc := fun _ => by rintro ⟨⟩ fac := fun _ => by rintro ⟨⟨⟩⟩ uniq := fun _ _ _ => by funext x; cases x } /-- The initial object in `Type u` is `PEmpty`. -/ noncomputable def initialIso : ⊥_ Type u ≅ PEmpty := colimit.isoColimitCocone initialColimitCocone.{u, 0} /-- The initial object in `Type u` is `PEmpty`. -/ noncomputable def isInitialPunit : IsInitial (PEmpty : Type u) := initialIsInitial.ofIso initialIso /-- An object in `Type u` is initial if and only if it is empty. -/ lemma initial_iff_empty (X : Type u) : Nonempty (IsInitial X) ↔ IsEmpty X := by constructor · intro ⟨h⟩ exact Function.isEmpty (IsInitial.to h PEmpty) · intro h exact ⟨IsInitial.ofIso Types.isInitialPunit <| Equiv.toIso <| Equiv.equivOfIsEmpty PEmpty X⟩ open CategoryTheory.Limits.WalkingPair -- We manually generate the other projection lemmas since the simp-normal form for the legs is -- otherwise not created correctly. /-- The product type `X × Y` forms a cone for the binary product of `X` and `Y`. -/ @[simps! pt] def binaryProductCone (X Y : Type u) : BinaryFan X Y := BinaryFan.mk _root_.Prod.fst _root_.Prod.snd @[simp] theorem binaryProductCone_fst (X Y : Type u) : (binaryProductCone X Y).fst = _root_.Prod.fst := rfl @[simp] theorem binaryProductCone_snd (X Y : Type u) : (binaryProductCone X Y).snd = _root_.Prod.snd := rfl /-- The product type `X × Y` is a binary product for `X` and `Y`. -/ @[simps] def binaryProductLimit (X Y : Type u) : IsLimit (binaryProductCone X Y) where lift (s : BinaryFan X Y) x := (s.fst x, s.snd x) fac _ j := Discrete.recOn j fun j => WalkingPair.casesOn j rfl rfl uniq _ _ w := funext fun x => Prod.ext (congr_fun (w ⟨left⟩) x) (congr_fun (w ⟨right⟩) x) /-- The category of types has `X × Y`, the usual cartesian product, as the binary product of `X` and `Y`. -/ @[simps] def binaryProductLimitCone (X Y : Type u) : Limits.LimitCone (pair X Y) := ⟨_, binaryProductLimit X Y⟩ /-- The categorical binary product in `Type u` is cartesian product. -/ noncomputable def binaryProductIso (X Y : Type u) : Limits.prod X Y ≅ X × Y := limit.isoLimitCone (binaryProductLimitCone X Y) @[elementwise (attr := simp)] theorem binaryProductIso_hom_comp_fst (X Y : Type u) : (binaryProductIso X Y).hom ≫ _root_.Prod.fst = Limits.prod.fst := limit.isoLimitCone_hom_π (binaryProductLimitCone X Y) ⟨WalkingPair.left⟩ @[elementwise (attr := simp)] theorem binaryProductIso_hom_comp_snd (X Y : Type u) : (binaryProductIso X Y).hom ≫ _root_.Prod.snd = Limits.prod.snd := limit.isoLimitCone_hom_π (binaryProductLimitCone X Y) ⟨WalkingPair.right⟩ @[elementwise (attr := simp)] theorem binaryProductIso_inv_comp_fst (X Y : Type u) : (binaryProductIso X Y).inv ≫ Limits.prod.fst = _root_.Prod.fst := limit.isoLimitCone_inv_π (binaryProductLimitCone X Y) ⟨WalkingPair.left⟩ @[elementwise (attr := simp)] theorem binaryProductIso_inv_comp_snd (X Y : Type u) : (binaryProductIso X Y).inv ≫ Limits.prod.snd = _root_.Prod.snd := limit.isoLimitCone_inv_π (binaryProductLimitCone X Y) ⟨WalkingPair.right⟩ /-- The functor which sends `X, Y` to the product type `X × Y`. -/ @[simps] def binaryProductFunctor : Type u ⥤ Type u ⥤ Type u where obj X := { obj := fun Y => X × Y map := fun { _ Y₂} f => (binaryProductLimit X Y₂).lift (BinaryFan.mk _root_.Prod.fst (_root_.Prod.snd ≫ f)) } map {X₁ X₂} f := { app := fun Y => (binaryProductLimit X₂ Y).lift (BinaryFan.mk (_root_.Prod.fst ≫ f) _root_.Prod.snd) } /-- The product functor given by the instance `HasBinaryProducts (Type u)` is isomorphic to the explicit binary product functor given by the product type. -/ noncomputable def binaryProductIsoProd : binaryProductFunctor ≅ (prod.functor : Type u ⥤ _) := by refine NatIso.ofComponents (fun X => ?_) (fun _ => ?_) · refine NatIso.ofComponents (fun Y => ?_) (fun _ => ?_) · exact ((limit.isLimit _).conePointUniqueUpToIso (binaryProductLimit X Y)).symm · apply Limits.prod.hom_ext <;> simp <;> rfl · ext : 2 apply Limits.prod.hom_ext <;> simp <;> rfl /-- The sum type `X ⊕ Y` forms a cocone for the binary coproduct of `X` and `Y`. -/ @[simps!] def binaryCoproductCocone (X Y : Type u) : Cocone (pair X Y) := BinaryCofan.mk Sum.inl Sum.inr /-- The sum type `X ⊕ Y` is a binary coproduct for `X` and `Y`. -/ @[simps] def binaryCoproductColimit (X Y : Type u) : IsColimit (binaryCoproductCocone X Y) where desc := fun s : BinaryCofan X Y => Sum.elim s.inl s.inr fac _ j := Discrete.recOn j fun j => WalkingPair.casesOn j rfl rfl uniq _ _ w := funext fun x => Sum.casesOn x (congr_fun (w ⟨left⟩)) (congr_fun (w ⟨right⟩)) /-- The category of types has `X ⊕ Y`, as the binary coproduct of `X` and `Y`. -/ def binaryCoproductColimitCocone (X Y : Type u) : Limits.ColimitCocone (pair X Y) := ⟨_, binaryCoproductColimit X Y⟩ /-- The categorical binary coproduct in `Type u` is the sum `X ⊕ Y`. -/ noncomputable def binaryCoproductIso (X Y : Type u) : Limits.coprod X Y ≅ X ⊕ Y := colimit.isoColimitCocone (binaryCoproductColimitCocone X Y) --open CategoryTheory.Type @[elementwise (attr := simp)] theorem binaryCoproductIso_inl_comp_hom (X Y : Type u) : Limits.coprod.inl ≫ (binaryCoproductIso X Y).hom = Sum.inl := colimit.isoColimitCocone_ι_hom (binaryCoproductColimitCocone X Y) ⟨WalkingPair.left⟩ @[elementwise (attr := simp)] theorem binaryCoproductIso_inr_comp_hom (X Y : Type u) : Limits.coprod.inr ≫ (binaryCoproductIso X Y).hom = Sum.inr := colimit.isoColimitCocone_ι_hom (binaryCoproductColimitCocone X Y) ⟨WalkingPair.right⟩ @[elementwise (attr := simp)] theorem binaryCoproductIso_inl_comp_inv (X Y : Type u) : ↾(Sum.inl : X ⟶ X ⊕ Y) ≫ (binaryCoproductIso X Y).inv = Limits.coprod.inl := colimit.isoColimitCocone_ι_inv (binaryCoproductColimitCocone X Y) ⟨WalkingPair.left⟩ @[elementwise (attr := simp)] theorem binaryCoproductIso_inr_comp_inv (X Y : Type u) : ↾(Sum.inr : Y ⟶ X ⊕ Y) ≫ (binaryCoproductIso X Y).inv = Limits.coprod.inr := colimit.isoColimitCocone_ι_inv (binaryCoproductColimitCocone X Y) ⟨WalkingPair.right⟩ open Function (Injective) theorem binaryCofan_isColimit_iff {X Y : Type u} (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ Injective c.inl ∧ Injective c.inr ∧ IsCompl (Set.range c.inl) (Set.range c.inr) := by classical constructor · rintro ⟨h⟩ rw [← show _ = c.inl from h.comp_coconePointUniqueUpToIso_inv (binaryCoproductColimit X Y) ⟨WalkingPair.left⟩, ← show _ = c.inr from h.comp_coconePointUniqueUpToIso_inv (binaryCoproductColimit X Y) ⟨WalkingPair.right⟩] dsimp [binaryCoproductCocone] refine ⟨(h.coconePointUniqueUpToIso (binaryCoproductColimit X Y)).symm.toEquiv.injective.comp Sum.inl_injective, (h.coconePointUniqueUpToIso (binaryCoproductColimit X Y)).symm.toEquiv.injective.comp Sum.inr_injective, ?_⟩ rw [types_comp, Set.range_comp, ← eq_compl_iff_isCompl, types_comp, Set.range_comp _ Sum.inr] erw [← Set.image_compl_eq (h.coconePointUniqueUpToIso (binaryCoproductColimit X Y)).symm.toEquiv.bijective] simp · rintro ⟨h₁, h₂, h₃⟩ have : ∀ x, x ∈ Set.range c.inl ∨ x ∈ Set.range c.inr := by rw [eq_compl_iff_isCompl.mpr h₃.symm] exact fun _ => or_not refine ⟨BinaryCofan.IsColimit.mk _ ?_ ?_ ?_ ?_⟩ · intro T f g x exact if h : x ∈ Set.range c.inl then f ((Equiv.ofInjective _ h₁).symm ⟨x, h⟩) else g ((Equiv.ofInjective _ h₂).symm ⟨x, (this x).resolve_left h⟩) · intro T f g funext x simp [h₁.eq_iff] · intro T f g funext x dsimp simp only [Set.mem_range, Equiv.ofInjective_symm_apply, dite_eq_right_iff, forall_exists_index] intro y e have : c.inr x ∈ Set.range c.inl ⊓ Set.range c.inr := ⟨⟨_, e⟩, ⟨_, rfl⟩⟩ rw [disjoint_iff.mp h₃.1] at this exact this.elim · rintro T _ _ m rfl rfl funext x dsimp split_ifs <;> exact congr_arg _ (Equiv.apply_ofInjective_symm _ ⟨_, _⟩).symm /-- Any monomorphism in `Type` is a coproduct injection. -/ noncomputable def isCoprodOfMono {X Y : Type u} (f : X ⟶ Y) [Mono f] : IsColimit (BinaryCofan.mk f (Subtype.val : ↑(Set.range f)ᶜ → Y)) := by apply Nonempty.some rw [binaryCofan_isColimit_iff] refine ⟨(mono_iff_injective f).mp inferInstance, Subtype.val_injective, ?_⟩ symm rw [← eq_compl_iff_isCompl] exact Subtype.range_val /-- The category of types has `Π j, f j` as the product of a type family `f : J → Type max v u`. -/ def productLimitCone {J : Type v} (F : J → Type max v u) : Limits.LimitCone (Discrete.functor F) where cone := { pt := ∀ j, F j π := Discrete.natTrans (fun ⟨j⟩ f => f j) } isLimit := { lift := fun s x j => s.π.app ⟨j⟩ x uniq := fun _ _ w => funext fun x => funext fun j => (congr_fun (w ⟨j⟩) x :) } /-- The categorical product in `Type max v u` is the type theoretic product `Π j, F j`. -/ noncomputable def productIso {J : Type v} (F : J → Type max v u) : ∏ᶜ F ≅ ∀ j, F j := limit.isoLimitCone (productLimitCone.{v, u} F) @[simp, elementwise (attr := simp)] theorem productIso_hom_comp_eval {J : Type v} (F : J → Type max v u) (j : J) : ((productIso.{v, u} F).hom ≫ fun f => f j) = Pi.π F j := rfl @[elementwise (attr := simp)] theorem productIso_inv_comp_π {J : Type v} (F : J → Type max v u) (j : J) : (productIso.{v, u} F).inv ≫ Pi.π F j = fun f => f j := limit.isoLimitCone_inv_π (productLimitCone.{v, u} F) ⟨j⟩ namespace Small variable {J : Type v} (F : J → Type u) [Small.{u} J] /-- A variant of `productLimitCone` using a `Small` hypothesis rather than a function to `Type`. -/ noncomputable def productLimitCone : Limits.LimitCone (Discrete.functor F) where cone := { pt := Shrink (∀ j, F j) π := Discrete.natTrans (fun ⟨j⟩ f => (equivShrink (∀ j, F j)).symm f j) } isLimit := have : Small.{u} (∀ j, F j) := inferInstance { lift := fun s x => (equivShrink _) (fun j => s.π.app ⟨j⟩ x) uniq := fun s m w => funext fun x => Shrink.ext <| funext fun j => by simpa using (congr_fun (w ⟨j⟩) x :) } /-- The categorical product in `Type u` indexed in `Type v` is the type theoretic product `Π j, F j`, after shrinking back to `Type u`. -/ noncomputable def productIso : (∏ᶜ F : Type u) ≅ Shrink.{u} (∀ j, F j) := limit.isoLimitCone (productLimitCone.{v, u} F) @[elementwise (attr := simp)] theorem productIso_hom_comp_eval (j : J) : ((productIso.{v, u} F).hom ≫ fun f => (equivShrink (∀ j, F j)).symm f j) = Pi.π F j := limit.isoLimitCone_hom_π (productLimitCone.{v, u} F) ⟨j⟩ @[elementwise (attr := simp)] theorem productIso_inv_comp_π (j : J) : (productIso.{v, u} F).inv ≫ Pi.π F j = fun f => ((equivShrink (∀ j, F j)).symm f) j := limit.isoLimitCone_inv_π (productLimitCone.{v, u} F) ⟨j⟩ end Small /-- The category of types has `Σ j, f j` as the coproduct of a type family `f : J → Type`. -/ def coproductColimitCocone {J : Type v} (F : J → Type max v u) : Limits.ColimitCocone (Discrete.functor F) where cocone := { pt := Σ j, F j ι := Discrete.natTrans (fun ⟨j⟩ x => ⟨j, x⟩)} isColimit := { desc := fun s x => s.ι.app ⟨x.1⟩ x.2 uniq := fun s m w => by funext ⟨j, x⟩ exact congr_fun (w ⟨j⟩) x } /-- The categorical coproduct in `Type u` is the type theoretic coproduct `Σ j, F j`. -/ noncomputable def coproductIso {J : Type v} (F : J → Type max v u) : ∐ F ≅ Σ j, F j := colimit.isoColimitCocone (coproductColimitCocone F) @[elementwise (attr := simp)] theorem coproductIso_ι_comp_hom {J : Type v} (F : J → Type max v u) (j : J) : Sigma.ι F j ≫ (coproductIso F).hom = fun x : F j => (⟨j, x⟩ : Σ j, F j) := colimit.isoColimitCocone_ι_hom (coproductColimitCocone F) ⟨j⟩ @[elementwise (attr := simp)] theorem coproductIso_mk_comp_inv {J : Type v} (F : J → Type max v u) (j : J) : (↾fun x : F j => (⟨j, x⟩ : Σ j, F j)) ≫ (coproductIso F).inv = Sigma.ι F j := rfl section Fork variable {X Y Z : Type u} (f : X ⟶ Y) {g h : Y ⟶ Z} (w : f ≫ g = f ≫ h) /-- Show the given fork in `Type u` is an equalizer given that any element in the "difference kernel" comes from `X`. The converse of `unique_of_type_equalizer`. -/ noncomputable def typeEqualizerOfUnique (t : ∀ y : Y, g y = h y → ∃! x : X, f x = y) : IsLimit (Fork.ofι _ w) := Fork.IsLimit.mk' _ fun s => by refine ⟨fun i => ?_, ?_, ?_⟩ · apply Classical.choose (t (s.ι i) _) apply congr_fun s.condition i · funext i exact (Classical.choose_spec (t (s.ι i) (congr_fun s.condition i))).1 · intro m hm funext i exact (Classical.choose_spec (t (s.ι i) (congr_fun s.condition i))).2 _ (congr_fun hm i) /-- The converse of `type_equalizer_of_unique`. -/ theorem unique_of_type_equalizer (t : IsLimit (Fork.ofι _ w)) (y : Y) (hy : g y = h y) : ∃! x : X, f x = y := by let y' : PUnit ⟶ Y := fun _ => y have hy' : y' ≫ g = y' ≫ h := funext fun _ => hy refine ⟨(Fork.IsLimit.lift' t _ hy').1 ⟨⟩, congr_fun (Fork.IsLimit.lift' t y' _).2 ⟨⟩, ?_⟩ intro x' hx' suffices (fun _ : PUnit => x') = (Fork.IsLimit.lift' t y' hy').1 by rw [← this] apply Fork.IsLimit.hom_ext t funext ⟨⟩ apply hx'.trans (congr_fun (Fork.IsLimit.lift' t _ hy').2 ⟨⟩).symm theorem type_equalizer_iff_unique : Nonempty (IsLimit (Fork.ofι _ w)) ↔ ∀ y : Y, g y = h y → ∃! x : X, f x = y := ⟨fun i => unique_of_type_equalizer _ _ (Classical.choice i), fun k => ⟨typeEqualizerOfUnique f w k⟩⟩ /-- Show that the subtype `{x : Y // g x = h x}` is an equalizer for the pair `(g,h)`. -/ def equalizerLimit : Limits.LimitCone (parallelPair g h) where cone := Fork.ofι (Subtype.val : { x : Y // g x = h x } → Y) (funext Subtype.prop) isLimit := Fork.IsLimit.mk' _ fun s => ⟨fun i => ⟨s.ι i, by apply congr_fun s.condition i⟩, rfl, fun hm => funext fun x => Subtype.ext (congr_fun hm x)⟩ variable (g h) /-- The categorical equalizer in `Type u` is `{x : Y // g x = h x}`. -/ noncomputable def equalizerIso : equalizer g h ≅ { x : Y // g x = h x } := limit.isoLimitCone equalizerLimit @[elementwise (attr := simp)] theorem equalizerIso_hom_comp_subtype : (equalizerIso g h).hom ≫ Subtype.val = equalizer.ι g h := by rfl @[elementwise (attr := simp)] theorem equalizerIso_inv_comp_ι : (equalizerIso g h).inv ≫ equalizer.ι g h = Subtype.val := limit.isoLimitCone_inv_π equalizerLimit WalkingParallelPair.zero end Fork section Cofork variable {X Y Z : Type u} (f g : X ⟶ Y) /-- Show that the quotient by the relation generated by `f(x) ~ g(x)` is a coequalizer for the pair `(f, g)`. -/ def coequalizerColimit : Limits.ColimitCocone (parallelPair f g) where cocone := Cofork.ofπ (Function.Coequalizer.mk f g) (funext fun x => Function.Coequalizer.condition f g x) isColimit := Cofork.IsColimit.mk _ (fun s ↦ Function.Coequalizer.desc f g s.π s.condition) (fun _ ↦ rfl) (fun _ _ hm ↦ funext (fun x ↦ Quot.inductionOn x (congr_fun hm))) /-- If `π : Y ⟶ Z` is an coequalizer for `(f, g)`, and `U ⊆ Y` such that `f ⁻¹' U = g ⁻¹' U`, then `π ⁻¹' (π '' U) = U`. -/ theorem coequalizer_preimage_image_eq_of_preimage_eq (π : Y ⟶ Z) (e : f ≫ π = g ≫ π) (h : IsColimit (Cofork.ofπ π e)) (U : Set Y) (H : f ⁻¹' U = g ⁻¹' U) : π ⁻¹' (π '' U) = U := by have lem : ∀ x y, Function.Coequalizer.Rel f g x y → (x ∈ U ↔ y ∈ U) := by rintro _ _ ⟨x⟩ change x ∈ f ⁻¹' U ↔ x ∈ g ⁻¹' U rw [H] have eqv : _root_.Equivalence fun x y => x ∈ U ↔ y ∈ U := by aesop (add safe constructors _root_.Equivalence) ext constructor · rw [← show _ = π from h.comp_coconePointUniqueUpToIso_inv (coequalizerColimit f g).2 WalkingParallelPair.one] rintro ⟨y, hy, e'⟩ dsimp at e' replace e' := (mono_iff_injective (h.coconePointUniqueUpToIso (coequalizerColimit f g).isColimit).inv).mp inferInstance e' exact (eqv.eqvGen_iff.mp (Relation.EqvGen.mono lem (Quot.eqvGen_exact e'))).mp hy · exact fun hx => ⟨_, hx, rfl⟩ /-- The categorical coequalizer in `Type u` is the quotient by `f g ~ g x`. -/ noncomputable def coequalizerIso : coequalizer f g ≅ Function.Coequalizer f g := colimit.isoColimitCocone (coequalizerColimit f g) @[elementwise (attr := simp)] theorem coequalizerIso_π_comp_hom : coequalizer.π f g ≫ (coequalizerIso f g).hom = Function.Coequalizer.mk f g := colimit.isoColimitCocone_ι_hom (coequalizerColimit f g) WalkingParallelPair.one @[elementwise (attr := simp)] theorem coequalizerIso_quot_comp_inv : ↾Function.Coequalizer.mk f g ≫ (coequalizerIso f g).inv = coequalizer.π f g := rfl end Cofork section Pullback -- #synth HasPullbacks.{u} (Type u) instance : HasPullbacks.{u} (Type u) := -- FIXME does not work via `inferInstance` despite `#synth HasPullbacks.{u} (Type u)` succeeding. -- https://github.com/leanprover-community/mathlib4/issues/5752 -- inferInstance hasPullbacks_of_hasWidePullbacks.{u} (Type u) instance : HasPushouts.{u} (Type u) := hasPushouts_of_hasWidePushouts.{u} (Type u) variable {X Y Z : Type u} {X' Y' Z' : Type v} variable (f : X ⟶ Z) (g : Y ⟶ Z) (f' : X' ⟶ Z') (g' : Y' ⟶ Z') /-- The usual explicit pullback in the category of types, as a subtype of the product. The full `LimitCone` data is bundled as `pullbackLimitCone f g`. -/ abbrev PullbackObj : Type u := { p : X × Y // f p.1 = g p.2 } -- `PullbackObj f g` comes with a coercion to the product type `X × Y`. example (p : PullbackObj f g) : X × Y := p /-- The explicit pullback cone on `PullbackObj f g`. This is bundled with the `IsLimit` data as `pullbackLimitCone f g`. -/ abbrev pullbackCone : Limits.PullbackCone f g := PullbackCone.mk (fun p : PullbackObj f g => p.1.1) (fun p => p.1.2) (funext fun p => p.2) /-- The explicit pullback in the category of types, bundled up as a `LimitCone` for given `f` and `g`. -/ @[simps] def pullbackLimitCone (f : X ⟶ Z) (g : Y ⟶ Z) : Limits.LimitCone (cospan f g) where cone := pullbackCone f g isLimit := PullbackCone.isLimitAux _ (fun s x => ⟨⟨s.fst x, s.snd x⟩, congr_fun s.condition x⟩) (by aesop) (by aesop) fun _ _ w => funext fun x => Subtype.ext <| Prod.ext (congr_fun (w WalkingCospan.left) x) (congr_fun (w WalkingCospan.right) x) end Pullback end Types section Pullback variable {X Y S : Type v} {f : X ⟶ S} {g : Y ⟶ S} {c : PullbackCone f g} namespace PullbackCone namespace IsLimit variable (hc : IsLimit c) /-- A limit pullback cone in the category of types identifies to the explicit pullback. -/ noncomputable def equivPullbackObj : c.pt ≃ Types.PullbackObj f g := (IsLimit.conePointUniqueUpToIso hc (Types.pullbackLimitCone f g).isLimit).toEquiv @[simp] lemma equivPullbackObj_apply_fst (x : c.pt) : (equivPullbackObj hc x).1.1 = c.fst x := congr_fun (IsLimit.conePointUniqueUpToIso_hom_comp hc (Types.pullbackLimitCone f g).isLimit .left) x @[simp] lemma equivPullbackObj_apply_snd (x : c.pt) : (equivPullbackObj hc x).1.2 = c.snd x := congr_fun (IsLimit.conePointUniqueUpToIso_hom_comp hc (Types.pullbackLimitCone f g).isLimit .right) x @[simp] lemma equivPullbackObj_symm_apply_fst (x : Types.PullbackObj f g) : c.fst ((equivPullbackObj hc).symm x) = x.1.1 := by obtain ⟨x, rfl⟩ := (equivPullbackObj hc).surjective x simp @[simp] lemma equivPullbackObj_symm_apply_snd (x : Types.PullbackObj f g) : c.snd ((equivPullbackObj hc).symm x) = x.1.2 := by obtain ⟨x, rfl⟩ := (equivPullbackObj hc).surjective x simp include hc in lemma type_ext {x y : c.pt} (h₁ : c.fst x = c.fst y) (h₂ : c.snd x = c.snd y) : x = y := (equivPullbackObj hc).injective (by ext <;> assumption) end IsLimit variable (c) /-- Given `c : PullbackCone f g` in the category of types, this is the canonical map `c.pt → Types.PullbackObj f g`. -/ @[simps coe_fst coe_snd] def toPullbackObj (x : c.pt) : Types.PullbackObj f g := ⟨⟨c.fst x, c.snd x⟩, congr_fun c.condition x⟩ /-- A pullback cone `c` in the category of types is limit iff the map `c.toPullbackObj : c.pt → Types.PullbackObj f g` is a bijection. -/ noncomputable def isLimitEquivBijective : IsLimit c ≃ Function.Bijective c.toPullbackObj where toFun h := (IsLimit.equivPullbackObj h).bijective invFun h := IsLimit.ofIsoLimit (Types.pullbackLimitCone f g).isLimit (Iso.symm (PullbackCone.ext (Equiv.ofBijective _ h).toIso)) left_inv _ := Subsingleton.elim _ _ end PullbackCone end Pullback namespace Types section Pullback open CategoryTheory.Limits.WalkingCospan variable {W X Y Z : Type u} variable (f : X ⟶ Z) (g : Y ⟶ Z) /-- The pullback given by the instance `HasPullbacks (Type u)` is isomorphic to the explicit pullback object given by `PullbackObj`. -/ noncomputable def pullbackIsoPullback : pullback f g ≅ PullbackObj f g := (PullbackCone.IsLimit.equivPullbackObj (pullbackIsPullback f g)).toIso @[simp] theorem pullbackIsoPullback_hom_fst (p : pullback f g) : ((pullbackIsoPullback f g).hom p : X × Y).fst = (pullback.fst f g) p := PullbackCone.IsLimit.equivPullbackObj_apply_fst (pullbackIsPullback f g) p @[simp] theorem pullbackIsoPullback_hom_snd (p : pullback f g) : ((pullbackIsoPullback f g).hom p : X × Y).snd = (pullback.snd f g) p := PullbackCone.IsLimit.equivPullbackObj_apply_snd (pullbackIsPullback f g) p @[simp] theorem pullbackIsoPullback_inv_fst_apply (x : (Types.pullbackCone f g).pt) : (pullback.fst f g) ((pullbackIsoPullback f g).inv x) = (fun p => (p.1 : X × Y).fst) x := PullbackCone.IsLimit.equivPullbackObj_symm_apply_fst (pullbackIsPullback f g) x @[simp] theorem pullbackIsoPullback_inv_snd_apply (x : (Types.pullbackCone f g).pt) : (pullback.snd f g) ((pullbackIsoPullback f g).inv x) = (fun p => (p.1 : X × Y).snd) x := PullbackCone.IsLimit.equivPullbackObj_symm_apply_snd (pullbackIsPullback f g) x @[simp] theorem pullbackIsoPullback_inv_fst : (pullbackIsoPullback f g).inv ≫ pullback.fst _ _ = fun p => (p.1 : X × Y).fst := by aesop @[simp] theorem pullbackIsoPullback_inv_snd : (pullbackIsoPullback f g).inv ≫ pullback.snd _ _ = fun p => (p.1 : X × Y).snd := by aesop end Pullback section Pushout variable {S X₁ X₂ : Type u} (f : S ⟶ X₁) (g : S ⟶ X₂) /-- The pushout of two maps `f : S ⟶ X₁` and `g : S ⟶ X₂` is the quotient by the equivalence relation on `X₁ ⊕ X₂` generated by this relation. -/ inductive Pushout.Rel (f : S ⟶ X₁) (g : S ⟶ X₂) : X₁ ⊕ X₂ → X₁ ⊕ X₂ → Prop | inl_inr (s : S) : Pushout.Rel f g (Sum.inl (f s)) (Sum.inr (g s)) /-- Construction of the pushout in the category of types, as a quotient of `X₁ ⊕ X₂`. -/ def Pushout : Type u := _root_.Quot (Pushout.Rel f g) /-- In case `f : S ⟶ X₁` is a monomorphism, this relation is the equivalence relation generated by `Pushout.Rel f g`. -/ inductive Pushout.Rel' : X₁ ⊕ X₂ → X₁ ⊕ X₂ → Prop | refl (x : X₁ ⊕ X₂) : Rel' x x | inl_inl (x₀ y₀ : S) (h : g x₀ = g y₀) : Rel' (Sum.inl (f x₀)) (Sum.inl (f y₀)) | inl_inr (s : S) : Rel' (Sum.inl (f s)) (Sum.inr (g s)) | inr_inl (s : S) : Rel' (Sum.inr (g s)) (Sum.inl (f s)) /-- The quotient of `X₁ ⊕ X₂` by the relation `PushoutRel' f g`. -/ def Pushout' : Type u := _root_.Quot (Pushout.Rel' f g) namespace Pushout /-- The left inclusion in the constructed pushout `Pushout f g`. -/ @[simp] def inl : X₁ ⟶ Pushout f g := fun x => Quot.mk _ (Sum.inl x) /-- The right inclusion in the constructed pushout `Pushout f g`. -/ @[simp] def inr : X₂ ⟶ Pushout f g := fun x => Quot.mk _ (Sum.inr x) lemma condition : f ≫ inl f g = g ≫ inr f g := by ext x exact Quot.sound (Rel.inl_inr x) /-- The constructed pushout cocone in the category of types. -/ @[simps!] def cocone : PushoutCocone f g := PushoutCocone.mk _ _ (condition f g) /-- The cocone `cocone f g` is colimit. -/ def isColimitCocone : IsColimit (cocone f g) := PushoutCocone.IsColimit.mk _ (fun s => Quot.lift (fun x => match x with | Sum.inl x₁ => s.inl x₁ | Sum.inr x₂ => s.inr x₂) (by rintro _ _ ⟨t⟩ exact congr_fun s.condition t)) (fun _ => rfl) (fun _ => rfl) (fun s m h₁ h₂ => by ext ⟨x₁|x₂⟩ · exact congr_fun h₁ x₁ · exact congr_fun h₂ x₂) @[simp] lemma inl_rel'_inl_iff (x₁ y₁ : X₁) : Rel' f g (Sum.inl x₁) (Sum.inl y₁) ↔ x₁ = y₁ ∨ ∃ (x₀ y₀ : S) (_ : g x₀ = g y₀), x₁ = f x₀ ∧ y₁ = f y₀ := by constructor · rintro (_ | ⟨_, _, h⟩) · exact Or.inl rfl · exact Or.inr ⟨_, _, h, rfl, rfl⟩ · rintro (rfl | ⟨_,_ , h, rfl, rfl⟩) · apply Rel'.refl · exact Rel'.inl_inl _ _ h @[simp] lemma inl_rel'_inr_iff (x₁ : X₁) (x₂ : X₂) : Rel' f g (Sum.inl x₁) (Sum.inr x₂) ↔ ∃ (s : S), x₁ = f s ∧ x₂ = g s := by constructor · rintro ⟨_⟩ exact ⟨_, rfl, rfl⟩ · rintro ⟨s, rfl, rfl⟩ exact Rel'.inl_inr _ @[simp] lemma inr_rel'_inr_iff (x₂ y₂ : X₂) : Rel' f g (Sum.inr x₂) (Sum.inr y₂) ↔ x₂ = y₂ := by constructor · rintro ⟨_⟩ rfl · rintro rfl apply Rel'.refl variable {f g} lemma Rel'.symm {x y : X₁ ⊕ X₂} (h : Rel' f g x y) : Rel' f g y x := by obtain _ | ⟨_, _, h⟩ | _ | _ := h · apply Rel'.refl · exact Rel'.inl_inl _ _ h.symm · exact Rel'.inr_inl _ · exact Rel'.inl_inr _ variable (f g) lemma equivalence_rel' [Mono f] : _root_.Equivalence (Rel' f g) where refl := Rel'.refl symm h := h.symm trans := by rintro x y z (_ | ⟨_, _, h⟩ | s | _) hyz · exact hyz · obtain z₁ | z₂ := z · rw [inl_rel'_inl_iff] at hyz obtain rfl | ⟨_, _, h', h'', rfl⟩ := hyz · exact Rel'.inl_inl _ _ h · obtain rfl := (mono_iff_injective f).1 inferInstance h'' exact Rel'.inl_inl _ _ (h.trans h') · rw [inl_rel'_inr_iff] at hyz obtain ⟨s, hs, rfl⟩ := hyz obtain rfl := (mono_iff_injective f).1 inferInstance hs rw [← h] apply Rel'.inl_inr · obtain z₁ | z₂ := z · replace hyz := hyz.symm rw [inl_rel'_inr_iff] at hyz obtain ⟨s', rfl, hs'⟩ := hyz exact Rel'.inl_inl _ _ hs' · rw [inr_rel'_inr_iff] at hyz subst hyz apply Rel'.inl_inr · obtain z₁ | z₂ := z · rw [inl_rel'_inl_iff] at hyz obtain rfl | ⟨_, _, h, h', rfl⟩ := hyz · apply Rel'.inr_inl · obtain rfl := (mono_iff_injective f).1 inferInstance h' rw [h] apply Rel'.inr_inl · rw [inl_rel'_inr_iff] at hyz obtain ⟨s, hs, rfl⟩ := hyz obtain rfl := (mono_iff_injective f).1 inferInstance hs apply Rel'.refl /-- The obvious equivalence `Pushout f g ≃ Pushout' f g`. -/ def equivPushout' : Pushout f g ≃ Pushout' f g where toFun := Quot.lift (Quot.mk _) (by rintro _ _ ⟨⟩ apply Quot.sound apply Rel'.inl_inr) invFun := Quot.lift (Quot.mk _) (by rintro a b (_ | ⟨x₀, y₀, h⟩ | _ | _) · rfl · have h₀ : Rel f g _ _ := Rel.inl_inr x₀ rw [Quot.sound h₀, h] symm apply Quot.sound apply Rel.inl_inr · apply Quot.sound apply Rel.inl_inr · symm apply Quot.sound apply Rel.inl_inr) left_inv := by rintro ⟨x⟩; rfl right_inv := by rintro ⟨x⟩; rfl lemma quot_mk_eq_iff [Mono f] (a b : X₁ ⊕ X₂) : (Quot.mk _ a : Pushout f g) = Quot.mk _ b ↔ Rel' f g a b := by rw [← (equivalence_rel' f g).quot_mk_eq_iff] exact ⟨fun h => (equivPushout' f g).symm.injective h, fun h => (equivPushout' f g).injective h⟩ lemma inl_eq_inr_iff [Mono f] (x₁ : X₁) (x₂ : X₂) : (inl f g x₁ = inr f g x₂) ↔ ∃ (s : S), f s = x₁ ∧ g s = x₂ := by refine (Pushout.quot_mk_eq_iff f g (Sum.inl x₁) (Sum.inr x₂)).trans ?_ constructor · rintro ⟨⟩ exact ⟨_, rfl, rfl⟩ · rintro ⟨s, rfl, rfl⟩ apply Rel'.inl_inr end Pushout variable {f g} lemma pushoutCocone_inl_eq_inr_imp_of_iso {c c' : PushoutCocone f g} (e : c ≅ c') (x₁ : X₁) (x₂ : X₂) (h : c.inl x₁ = c.inr x₂) : c'.inl x₁ = c'.inr x₂ := by convert congr_arg e.hom.hom h · exact congr_fun (e.hom.w WalkingSpan.left).symm x₁ · exact congr_fun (e.hom.w WalkingSpan.right).symm x₂ lemma pushoutCocone_inl_eq_inr_iff_of_iso {c c' : PushoutCocone f g} (e : c ≅ c') (x₁ : X₁) (x₂ : X₂) : c.inl x₁ = c.inr x₂ ↔ c'.inl x₁ = c'.inr x₂ := by constructor · apply pushoutCocone_inl_eq_inr_imp_of_iso e · apply pushoutCocone_inl_eq_inr_imp_of_iso e.symm lemma pushoutCocone_inl_eq_inr_iff_of_isColimit {c : PushoutCocone f g} (hc : IsColimit c) (h₁ : Function.Injective f) (x₁ : X₁) (x₂ : X₂) : c.inl x₁ = c.inr x₂ ↔ ∃ (s : S), f s = x₁ ∧ g s = x₂ := by rw [pushoutCocone_inl_eq_inr_iff_of_iso (Cocones.ext (IsColimit.coconePointUniqueUpToIso hc (Pushout.isColimitCocone f g)) (by simp))] have := (mono_iff_injective f).2 h₁ apply Pushout.inl_eq_inr_iff end Pushout end Types section Multiequalizer variable {J : MulticospanShape} (I : MulticospanIndex J (Type u)) /-- Given `I : MulticospanIndex J (Type u)`, this is a type which identifies to the sections of the functor `I.multicospan`. -/ @[ext] structure MulticospanIndex.sections where /-- The data of an element in `I.left i` for each `i : J.L`. -/ val (i : J.L) : I.left i property (r : J.R) : I.fst r (val _) = I.snd r (val _) /-- The bijection `I.sections ≃ I.multicospan.sections` when `I : MulticospanIndex (Type u)` is a multiequalizer diagram in the category of types. -/ @[simps] def MulticospanIndex.sectionsEquiv : I.sections ≃ I.multicospan.sections where toFun s := { val := fun i ↦ match i with | .left i => s.val i | .right j => I.fst j (s.val _) property := by rintro _ _ (_ | _ | r) · rfl · rfl · exact (s.property r).symm } invFun s := { val := fun i ↦ s.val (.left i) property := fun r ↦ (s.property (.fst r)).trans (s.property (.snd r)).symm } right_inv s := by ext (_ | r) · rfl · exact s.property (.fst r) namespace Multifork variable {I} variable (c : Multifork I) /-- Given a multiequalizer diagram `I : MulticospanIndex (Type u)` in the category of types and `c` a multifork for `I`, this is the canonical map `c.pt → I.sections`. -/ @[simps] def toSections (x : c.pt) : I.sections where val i := c.ι i x property r := congr_fun (c.condition r) x lemma toSections_fac : I.sectionsEquiv.symm ∘ Types.sectionOfCone c = c.toSections := rfl /-- A multifork `c : Multifork I` in the category of types is limit iff the map `c.toSections : c.pt → I.sections` is a bijection. -/ lemma isLimit_types_iff : Nonempty (IsLimit c) ↔ Function.Bijective c.toSections := by rw [Types.isLimit_iff_bijective_sectionOfCone, ← toSections_fac, EquivLike.comp_bijective] namespace IsLimit variable {c} (hc : IsLimit c) /-- The bijection `I.sections ≃ c.pt` when `c : Multifork I` is a limit multifork in the category of types. -/ noncomputable def sectionsEquiv : I.sections ≃ c.pt := (Equiv.ofBijective _ (c.isLimit_types_iff.1 ⟨hc⟩)).symm @[simp] lemma sectionsEquiv_symm_apply_val (x : c.pt) (i : J.L) : ((sectionsEquiv hc).symm x).val i = c.ι i x := rfl @[simp] lemma sectionsEquiv_apply_val (s : I.sections) (i : J.L) : c.ι i (sectionsEquiv hc s) = s.val i := by obtain ⟨x, rfl⟩ := (sectionsEquiv hc).symm.surjective s simp end IsLimit end Multifork end Multiequalizer end CategoryTheory.Limits
MinimalAxioms.lean
/- Copyright (c) 2015 Nathaniel Thomas. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro, Martin C. Martin -/ import Mathlib.Algebra.Module.Defs /-! # Minimal Axioms for a Module This file defines a constructor to define a `Module` structure on a Type with an `AddCommGroup`, while proving a minimum number of equalities. ## Main Definitions * `Module.ofMinimalAxioms`: Define a `Module` structure on a Type with an AddCommGroup by proving a minimized set of axioms -/ universe u v /-- Define a `Module` structure on a Type by proving a minimized set of axioms. -/ abbrev Module.ofMinimalAxioms {R : Type u} {M : Type v} [Semiring R] [AddCommGroup M] [SMul R M] -- Scalar multiplication distributes over addition from the left. (smul_add : ∀ (r : R) (x y : M), r • (x + y) = r • x + r • y) -- Scalar multiplication distributes over addition from the right. (add_smul : ∀ (r s : R) (x : M), (r + s) • x = r • x + s • x) -- Scalar multiplication distributes over multiplication from the right. (mul_smul : ∀ (r s : R) (x : M), (r * s) • x = r • s • x) -- Scalar multiplication by one is the identity. (one_smul : ∀ x : M, (1 : R) • x = x) : Module R M := { smul_add := smul_add, add_smul := add_smul, mul_smul := mul_smul, one_smul := one_smul, zero_smul := fun x => (AddMonoidHom.mk' (· • x) fun r s => add_smul r s x).map_zero smul_zero := fun r => (AddMonoidHom.mk' (r • ·) (smul_add r)).map_zero }
Quasicoherent.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Category.ModuleCat.Sheaf.Generators /-! # Quasicoherent sheaves A sheaf of modules is quasi-coherent if it admits locally a presentation as the cokernel of a morphism between coproducts of copies of the sheaf of rings. When these coproducts are finite, we say that the sheaf is of finite presentation. ## References * https://stacks.math.columbia.edu/tag/01BD -/ universe u v' u' open CategoryTheory Limits variable {C : Type u'} [Category.{v'} C] {J : GrothendieckTopology C} variable {R : Sheaf J RingCat.{u}} namespace SheafOfModules variable (M : SheafOfModules.{u} R) section variable [HasWeakSheafify J AddCommGrp.{u}] [J.WEqualsLocallyBijective AddCommGrp.{u}] [J.HasSheafCompose (forget₂ RingCat.{u} AddCommGrp.{u})] /-- A global presentation of a sheaf of modules `M` consists of a family `generators.s` of sections `s` which generate `M`, and a family of sections which generate the kernel of the morphism `generators.π : free (generators.I) ⟶ M`. -/ structure Presentation where /-- generators -/ generators : M.GeneratingSections /-- relations -/ relations : (kernel generators.π).GeneratingSections end variable [∀ X, (J.over X).HasSheafCompose (forget₂ RingCat.{u} AddCommGrp.{u})] [∀ X, HasWeakSheafify (J.over X) AddCommGrp.{u}] [∀ X, (J.over X).WEqualsLocallyBijective AddCommGrp.{u}] /-- This structure contains the data of a family of objects `X i` which cover the terminal object, and of a presentation of `M.over (X i)` for all `i`. -/ structure QuasicoherentData where /-- the index type of the covering -/ I : Type u' /-- a family of objects which cover the terminal object -/ X : I → C coversTop : J.CoversTop X /-- a presentation of the sheaf of modules `M.over (X i)` for any `i : I` -/ presentation (i : I) : (M.over (X i)).Presentation namespace QuasicoherentData variable {M} /-- If `M` is quasicoherent, it is locally generated by sections. -/ @[simps] def localGeneratorsData (q : M.QuasicoherentData) : M.LocalGeneratorsData where I := q.I X := q.X coversTop := q.coversTop generators i := (q.presentation i).generators end QuasicoherentData /-- A sheaf of modules is quasi-coherent if it is locally the cokernel of a morphism between coproducts of copies of the sheaf of rings. -/ class IsQuasicoherent : Prop where nonempty_quasicoherentData : Nonempty M.QuasicoherentData /-- A sheaf of modules is finitely presented if it is locally the cokernel of a morphism between coproducts of finitely many copies of the sheaf of rings. -/ class IsFinitePresentation : Prop where exists_quasicoherentData : ∃ (σ : M.QuasicoherentData), ∀ (i : σ.I), (Finite (σ.presentation i).generators.I ∧ Finite (σ.presentation i).relations.I) section variable [h : M.IsFinitePresentation] /-- A choice of local presentations when `M` is a sheaf of modules of finite presentation. -/ noncomputable def quasicoherentDataOfIsFinitePresentation : M.QuasicoherentData := h.exists_quasicoherentData.choose instance (i : M.quasicoherentDataOfIsFinitePresentation.I) : Finite (M.quasicoherentDataOfIsFinitePresentation.presentation i).generators.I := have : _ ∧ Finite (M.quasicoherentDataOfIsFinitePresentation.presentation i).relations.I := h.exists_quasicoherentData.choose_spec i this.1 instance (i : M.quasicoherentDataOfIsFinitePresentation.I) : Finite (M.quasicoherentDataOfIsFinitePresentation.presentation i).relations.I := have : _ ∧ Finite (M.quasicoherentDataOfIsFinitePresentation.presentation i).relations.I := h.exists_quasicoherentData.choose_spec i this.2 end instance [M.IsFinitePresentation] : M.IsFiniteType where exists_localGeneratorsData := ⟨M.quasicoherentDataOfIsFinitePresentation.localGeneratorsData, by intro; dsimp; infer_instance⟩ end SheafOfModules
polyXY.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 choice ssrnat seq. From mathcomp Require Import fintype tuple finfun bigop fingroup perm div. From mathcomp Require Import ssralg zmodp matrix mxalgebra. From mathcomp Require Import poly polydiv mxpoly binomial. (******************************************************************************) (* This file provides additional primitives and theory for bivariate *) (* polynomials (polynomials of two variables), represented as polynomials *) (* with (univariate) polynomial coefficients : *) (* 'Y == the (generic) second variable (:= 'X%:P). *) (* p^:P == the bivariate polynomial p['X], for p univariate. *) (* := map_poly polyC p (this notation is defined in poly.v). *) (* u.[x, y] == the bivariate polynomial u evaluated at 'X = x, 'Y = y. *) (* := u.[x%:P].[y]. *) (* sizeY u == the size of u in 'Y (1 + the 'Y-degree of u, if u != 0). *) (* := \max_(i < size u) size u`_i. *) (* swapXY u == the bivariate polynomial u['Y, 'X], for u bivariate. *) (* poly_XaY p == the bivariate polynomial p['X + 'Y], for p univariate. *) (* := p^:P \Po ('X + 'Y). *) (* poly_XmY p == the bivariate polynomial p['X * 'Y], for p univariate. *) (* := P^:P \Po ('X * 'Y). *) (* sub_annihilant p q == for univariate p, q != 0, a nonzero polynomial whose *) (* roots include all the differences of roots of p and q, in *) (* all field extensions (:= resultant (poly_XaY p) q^:P). *) (* div_annihilant p q == for polynomials p != 0, q with q.[0] != 0, a nonzero *) (* polynomial whose roots include all the quotients of roots *) (* of p by roots of q, in all field extensions *) (* (:= resultant (poly_XmY p) q^:P). *) (* The latter two "annhilants" provide uniform witnesses for an alternative *) (* proof of the closure of the algebraicOver predicate (see mxpoly.v). The *) (* fact that the annhilant does not depend on the particular choice of roots *) (* of p and q is crucial for the proof of the Primitive Element Theorem (file *) (* separable.v). *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Import GRing.Theory. Local Notation "p ^ f" := (map_poly f p) : ring_scope. Local Notation eval := horner_eval. Notation "'Y" := 'X%:P : ring_scope. Notation "p ^:P" := (p ^ polyC) (format "p ^:P") : ring_scope. Notation "p .[ x , y ]" := (p.[x%:P].[y]) (left associativity, format "p .[ x , y ]") : ring_scope. Section PolyXY_NzRing. Variable R : nzRingType. Implicit Types (u : {poly {poly R}}) (p q : {poly R}) (x : R). Fact swapXY_key : unit. Proof. by []. Qed. Definition swapXY_def u : {poly {poly R}} := (u ^ map_poly polyC).['Y]. Definition swapXY := locked_with swapXY_key swapXY_def. Canonical swapXY_unlockable := [unlockable fun swapXY]. Definition sizeY u : nat := \max_(i < size u) (size u`_i). Definition poly_XaY p : {poly {poly R}} := p^:P \Po ('X + 'Y). Definition poly_XmY p : {poly {poly R}} := p^:P \Po ('X * 'Y). Definition sub_annihilant p q := resultant (poly_XaY p) q^:P. Definition div_annihilant p q := resultant (poly_XmY p) q^:P. Lemma swapXY_polyC p : swapXY p%:P = p^:P. Proof. by rewrite unlock map_polyC hornerC. Qed. Lemma swapXY_X : swapXY 'X = 'Y. Proof. by rewrite unlock map_polyX hornerX. Qed. Lemma swapXY_Y : swapXY 'Y = 'X. Proof. by rewrite swapXY_polyC map_polyX. Qed. Lemma swapXY_is_zmod_morphism : zmod_morphism swapXY. Proof. by move=> u v; rewrite unlock rmorphB !hornerE. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `swapXY_is_zmod_morphism` instead")] Definition swapXY_is_additive := swapXY_is_zmod_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build {poly {poly R}} {poly {poly R}} swapXY swapXY_is_zmod_morphism. Lemma coef_swapXY u i j : (swapXY u)`_i`_j = u`_j`_i. Proof. elim/poly_ind: u => [|u p IHu] in i j *; first by rewrite raddf0 !coef0. rewrite raddfD !coefD /= swapXY_polyC coef_map /= !coefC coefMX. rewrite !(fun_if (fun q : {poly R} => q`_i)) coef0 -IHu; congr (_ + _). by rewrite unlock rmorphM /= map_polyX hornerMX coefMC coefMX. Qed. Lemma swapXYK : involutive swapXY. Proof. by move=> u; apply/polyP=> i; apply/polyP=> j; rewrite !coef_swapXY. Qed. Lemma swapXY_map_polyC p : swapXY p^:P = p%:P. Proof. by rewrite -swapXY_polyC swapXYK. Qed. Lemma swapXY_eq0 u : (swapXY u == 0) = (u == 0). Proof. by rewrite (inv_eq swapXYK) raddf0. Qed. Lemma swapXY_is_monoid_morphism : monoid_morphism swapXY. Proof. split=> [|u v]; first by rewrite swapXY_polyC map_polyC. apply/polyP=> i; apply/polyP=> j; rewrite coef_swapXY !coefM !coef_sum. rewrite (eq_bigr _ (fun _ _ => coefM _ _ _)) exchange_big /=. apply: eq_bigr => j1 _; rewrite coefM; apply: eq_bigr=> i1 _. by rewrite !coef_swapXY. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `swapXY_is_monoid_morphism` instead")] Definition swapXY_is_multiplicative := (fun g => (g.2,g.1)) swapXY_is_monoid_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build {poly {poly R}} {poly {poly R}} swapXY swapXY_is_monoid_morphism. Lemma swapXY_is_scalable : scalable_for (map_poly polyC \; *%R) swapXY. Proof. by move=> p u /=; rewrite -mul_polyC rmorphM /= swapXY_polyC. Qed. HB.instance Definition _ := GRing.isScalable.Build {poly R} {poly {poly R}} {poly {poly R}} (map_poly polyC \; *%R) swapXY swapXY_is_scalable. Lemma swapXY_comp_poly p u : swapXY (p^:P \Po u) = p^:P \Po swapXY u. Proof. rewrite -horner_map; congr _.[_]; rewrite -!map_poly_comp /=. by apply: eq_map_poly => x; rewrite /= swapXY_polyC map_polyC. Qed. Lemma max_size_coefXY u i : size u`_i <= sizeY u. Proof. have [ltiu | /(nth_default 0)->] := ltnP i (size u); last by rewrite size_poly0. exact: (bigmax_sup (Ordinal ltiu)). Qed. Lemma max_size_lead_coefXY u : size (lead_coef u) <= sizeY u. Proof. by rewrite lead_coefE max_size_coefXY. Qed. Lemma max_size_evalX u : size u.['X] <= sizeY u + (size u).-1. Proof. rewrite horner_coef (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP=> i _. rewrite (leq_trans (size_polyMleq _ _)) // size_polyXn addnS. by rewrite leq_add ?max_size_coefXY //= -ltnS (leq_trans _ (leqSpred _)). Qed. Lemma max_size_evalC u x : size u.[x%:P] <= sizeY u. Proof. rewrite horner_coef (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP=> i _. rewrite (leq_trans (size_polyMleq _ _)) // -polyC_exp size_polyC addnC -subn1. by rewrite (leq_trans _ (max_size_coefXY _ i)) // leq_subLR leq_add2r leq_b1. Qed. Lemma sizeYE u : sizeY u = size (swapXY u). Proof. apply/eqP; rewrite eqn_leq; apply/andP; split. apply/bigmax_leqP=> /= i _; apply/leq_sizeP => j /(nth_default 0) u_j_0. by rewrite -coef_swapXY u_j_0 coef0. apply/leq_sizeP=> j le_uY_j; apply/polyP=> i; rewrite coef_swapXY coef0. by rewrite nth_default // (leq_trans _ le_uY_j) ?max_size_coefXY. Qed. Lemma sizeY_eq0 u : (sizeY u == 0) = (u == 0). Proof. by rewrite sizeYE size_poly_eq0 swapXY_eq0. Qed. Lemma sizeY_mulX u : sizeY (u * 'X) = sizeY u. Proof. rewrite !sizeYE rmorphM /= swapXY_X rreg_size //. by have /monic_comreg[_ /rreg_lead] := monicX R. Qed. Lemma swapXY_poly_XaY p : swapXY (poly_XaY p) = poly_XaY p. Proof. by rewrite swapXY_comp_poly rmorphD /= swapXY_X swapXY_Y addrC. Qed. Lemma swapXY_poly_XmY p : swapXY (poly_XmY p) = poly_XmY p. Proof. by rewrite swapXY_comp_poly rmorphM /= swapXY_X swapXY_Y commr_polyX. Qed. Lemma poly_XaY0 : poly_XaY 0 = 0. Proof. by rewrite /poly_XaY rmorph0 comp_poly0. Qed. Lemma poly_XmY0 : poly_XmY 0 = 0. Proof. by rewrite /poly_XmY rmorph0 comp_poly0. Qed. End PolyXY_NzRing. Prenex Implicits swapXY sizeY poly_XaY poly_XmY sub_annihilant div_annihilant. Prenex Implicits swapXYK. Lemma swapXY_map (R S : nzRingType) (f : {additive R -> S}) u : swapXY (u ^ map_poly f) = swapXY u ^ map_poly f. Proof. by apply/polyP=> i; apply/polyP=> j; rewrite !(coef_map, coef_swapXY). Qed. Section PolyXY_ComNzRing. Variable R : comNzRingType. Implicit Types (u : {poly {poly R}}) (p : {poly R}) (x y : R). Lemma horner_swapXY u x : (swapXY u).[x%:P] = u ^ eval x. Proof. apply/polyP=> i /=; rewrite coef_map /= /eval horner_coef coef_sum -sizeYE. rewrite (horner_coef_wide _ (max_size_coefXY u i)); apply: eq_bigr=> j _. by rewrite -polyC_exp coefMC coef_swapXY. Qed. Lemma horner_polyC u x : u.[x%:P] = swapXY u ^ eval x. Proof. by rewrite -horner_swapXY swapXYK. Qed. Lemma horner2_swapXY u x y : (swapXY u).[x, y] = u.[y, x]. Proof. by rewrite horner_swapXY -{1}(hornerC y x) horner_map. Qed. Lemma horner_poly_XaY p v : (poly_XaY p).[v] = p \Po (v + 'X). Proof. by rewrite horner_comp !hornerE. Qed. Lemma horner_poly_XmY p v : (poly_XmY p).[v] = p \Po (v * 'X). Proof. by rewrite horner_comp !hornerE. Qed. End PolyXY_ComNzRing. Section PolyXY_Idomain. Variable R : idomainType. Implicit Types (p q : {poly R}) (x y : R). Lemma size_poly_XaY p : size (poly_XaY p) = size p. Proof. by rewrite size_comp_poly2 ?size_XaddC // size_map_polyC. Qed. Lemma poly_XaY_eq0 p : (poly_XaY p == 0) = (p == 0). Proof. by rewrite -!size_poly_eq0 size_poly_XaY. Qed. Lemma size_poly_XmY p : size (poly_XmY p) = size p. Proof. by rewrite size_comp_poly2 ?size_XmulC ?polyX_eq0 ?size_map_polyC. Qed. Lemma poly_XmY_eq0 p : (poly_XmY p == 0) = (p == 0). Proof. by rewrite -!size_poly_eq0 size_poly_XmY. Qed. Lemma lead_coef_poly_XaY p : lead_coef (poly_XaY p) = (lead_coef p)%:P. Proof. rewrite lead_coef_comp ?size_XaddC // -['Y]opprK -polyCN lead_coefXsubC. by rewrite expr1n mulr1 lead_coef_map_inj //; apply: polyC_inj. Qed. Lemma sub_annihilant_in_ideal p q : 1 < size p -> 1 < size q -> {uv : {poly {poly R}} * {poly {poly R}} | size uv.1 < size q /\ size uv.2 < size p & forall x y, (sub_annihilant p q).[y] = uv.1.[x, y] * p.[x + y] + uv.2.[x, y] * q.[x]}. Proof. rewrite -size_poly_XaY -(size_map_polyC q) => p1_gt1 q1_gt1. have [uv /= [ub_u ub_v Dr]] := resultant_in_ideal p1_gt1 q1_gt1. exists uv => // x y; rewrite -[r in r.[y]](hornerC _ x%:P) Dr. by rewrite !(hornerE, horner_comp). Qed. Lemma sub_annihilantP p q x y : p != 0 -> q != 0 -> p.[x] = 0 -> q.[y] = 0 -> (sub_annihilant p q).[x - y] = 0. Proof. move=> nz_p nz_q px0 qy0. have p_gt1: size p > 1 by have /rootP/root_size_gt1-> := px0. have q_gt1: size q > 1 by have /rootP/root_size_gt1-> := qy0. have [uv /= _ /(_ y)->] := sub_annihilant_in_ideal p_gt1 q_gt1. by rewrite (addrC y) subrK px0 qy0 !mulr0 addr0. Qed. Lemma sub_annihilant_neq0 p q : p != 0 -> q != 0 -> sub_annihilant p q != 0. Proof. rewrite resultant_eq0; set p1 := poly_XaY p => nz_p nz_q. have [nz_p1 nz_q1]: p1 != 0 /\ q^:P != 0 by rewrite poly_XaY_eq0 map_polyC_eq0. rewrite -leqNgt eq_leq //; apply/eqP/Bezout_coprimepPn=> // [[[u v]]] /=. rewrite !size_poly_gt0 -andbA => /and4P[nz_u ltuq nz_v _] Duv. have /eqP/= := congr1 (size \o (lead_coef \o swapXY)) Duv. rewrite ltn_eqF // !rmorphM !lead_coefM (leq_trans (leq_ltn_trans _ ltuq)) //=. rewrite -{2}[u]swapXYK -sizeYE swapXY_poly_XaY lead_coef_poly_XaY. by rewrite mulrC mul_polyC size_scale ?max_size_lead_coefXY ?lead_coef_eq0. rewrite swapXY_map_polyC lead_coefC size_map_polyC. set v1 := lead_coef _; have nz_v1: v1 != 0 by rewrite lead_coef_eq0 swapXY_eq0. rewrite [leqRHS]polySpred ?mulf_neq0 // size_mul //. by rewrite (polySpred nz_v1) addnC addnS polySpred // ltnS leq_addr. Qed. Lemma div_annihilant_in_ideal p q : 1 < size p -> 1 < size q -> {uv : {poly {poly R}} * {poly {poly R}} | size uv.1 < size q /\ size uv.2 < size p & forall x y, (div_annihilant p q).[y] = uv.1.[x, y] * p.[x * y] + uv.2.[x, y] * q.[x]}. Proof. rewrite -size_poly_XmY -(size_map_polyC q) => p1_gt1 q1_gt1. have [uv /= [ub_u ub_v Dr]] := resultant_in_ideal p1_gt1 q1_gt1. exists uv => // x y; rewrite -[r in r.[y]](hornerC _ x%:P) Dr. by rewrite !(hornerE, horner_comp). Qed. Lemma div_annihilant_neq0 p q : p != 0 -> q.[0] != 0 -> div_annihilant p q != 0. Proof. have factorX u: u != 0 -> root u 0 -> exists2 v, v != 0 & u = v * 'X. move=> nz_u /factor_theorem[v]; rewrite subr0 => Du; exists v => //. by apply: contraNneq nz_u => v0; rewrite Du v0 mul0r. have nzX: 'X != 0 := monic_neq0 (monicX _); have rootC0 := root_polyC _ 0. rewrite resultant_eq0 -leqNgt -rootE // => nz_p nz_q0; apply/eq_leq/eqP. have nz_q: q != 0 by apply: contraNneq nz_q0 => ->; rewrite root0. apply/Bezout_coprimepPn; rewrite ?map_polyC_eq0 ?poly_XmY_eq0 // => [[uv]]. rewrite !size_poly_gt0 -andbA ltnNge => /and4P[nz_u /negP ltuq nz_v _] Duv. pose u := swapXY uv.1; pose v := swapXY uv.2. suffices{ltuq}: size q <= sizeY u by rewrite sizeYE swapXYK -size_map_polyC. have{nz_u nz_v} [nz_u nz_v Dvu]: [/\ u != 0, v != 0 & q *: v = u * poly_XmY p]. rewrite !swapXY_eq0; split=> //; apply: (can_inj swapXYK). by rewrite linearZ rmorphM /= !swapXYK swapXY_poly_XmY Duv mulrC. have{Duv} [n ltvn]: {n | size v < n} by exists (size v).+1. elim: n {uv} => // n IHn in p (v) (u) nz_u nz_v Dvu nz_p ltvn *. have Dp0: root (poly_XmY p) 0 = root p 0 by rewrite root_comp !hornerE rootC0. have Dv0: root u 0 || root p 0 = root v 0 by rewrite -Dp0 -rootM -Dvu rootZ. have [v0_0 | nz_v0] := boolP (root v 0); last first. have nz_p0: ~~ root p 0 by apply: contra nz_v0; rewrite -Dv0 orbC => ->. apply: (@leq_trans (size (q * v.[0]))). by rewrite size_mul // (polySpred nz_v0) addnS leq_addr. rewrite -hornerZ Dvu !(horner_comp, hornerE) horner_map mulrC size_Cmul //. by rewrite horner_coef0 max_size_coefXY. have [v1 nz_v1 Dv] := factorX _ _ nz_v v0_0; rewrite Dv size_mulX // in ltvn. have /orP[/factorX[//|u1 nz_u1 Du] | p0_0]: root u 0 || root p 0 by rewrite Dv0. rewrite Du sizeY_mulX; apply: IHn nz_u1 nz_v1 _ nz_p ltvn. by apply: (mulIf (nzX _)); rewrite mulrAC -scalerAl -Du -Dv. have /factorX[|v2 nz_v2 Dv1]: root (swapXY v1) 0; rewrite ?swapXY_eq0 //. suffices: root (swapXY v1 * 'Y) 0 by rewrite mulrC mul_polyC rootZ ?polyX_eq0. have: root (swapXY (q *: v)) 0. by rewrite Dvu rmorphM rootM /= swapXY_poly_XmY Dp0 p0_0 orbT. by rewrite linearZ /= rootM rootC0 (negPf nz_q0) /= Dv rmorphM /= swapXY_X. rewrite ltnS (canRL swapXYK Dv1) -sizeYE sizeY_mulX sizeYE in ltvn. have [p1 nz_p1 Dp] := factorX _ _ nz_p p0_0. apply: IHn nz_u _ _ nz_p1 ltvn; first by rewrite swapXY_eq0. have: 'X * 'Y != 0 :> {poly {poly R}} by rewrite mulf_neq0 ?polyC_eq0 ?nzX. move/mulIf; apply. rewrite -scalerAl mulrA mulrAC -{1}swapXY_X -rmorphM /= -Dv1 swapXYK -Dv Dvu. by rewrite /poly_XmY Dp rmorphM /= map_polyX comp_polyM comp_polyX mulrA. Qed. End PolyXY_Idomain. Section PolyXY_Field. Variables (F E : fieldType) (FtoE : {rmorphism F -> E}). Local Notation pFtoE := (map_poly (GRing.RMorphism.sort FtoE)). Lemma div_annihilantP (p q : {poly E}) (x y : E) : p != 0 -> q != 0 -> y != 0 -> p.[x] = 0 -> q.[y] = 0 -> (div_annihilant p q).[x / y] = 0. Proof. move=> nz_p nz_q nz_y px0 qy0. have p_gt1: size p > 1 by have /rootP/root_size_gt1-> := px0. have q_gt1: size q > 1 by have /rootP/root_size_gt1-> := qy0. have [uv /= _ /(_ y)->] := div_annihilant_in_ideal p_gt1 q_gt1. by rewrite (mulrC y) divfK // px0 qy0 !mulr0 addr0. Qed. Lemma map_sub_annihilantP (p q : {poly F}) (x y : E) : p != 0 -> q != 0 ->(p ^ FtoE).[x] = 0 -> (q ^ FtoE).[y] = 0 -> (sub_annihilant p q ^ FtoE).[x - y] = 0. Proof. move=> nz_p nz_q px0 qy0; have pFto0 := map_poly_eq0 FtoE. rewrite map_resultant ?pFto0 ?lead_coef_eq0 ?map_poly_eq0 ?poly_XaY_eq0 //. rewrite map_comp_poly rmorphD /= map_polyC /= !map_polyX -!map_poly_comp /=. by rewrite !(eq_map_poly (map_polyC _)) !map_poly_comp sub_annihilantP ?pFto0. Qed. Lemma map_div_annihilantP (p q : {poly F}) (x y : E) : p != 0 -> q != 0 -> y != 0 -> (p ^ FtoE).[x] = 0 -> (q ^ FtoE).[y] = 0 -> (div_annihilant p q ^ FtoE).[x / y] = 0. Proof. move=> nz_p nz_q nz_y px0 qy0; have pFto0 := map_poly_eq0 FtoE. rewrite map_resultant ?pFto0 ?lead_coef_eq0 ?map_poly_eq0 ?poly_XmY_eq0 //. rewrite map_comp_poly rmorphM /= map_polyC /= !map_polyX -!map_poly_comp /=. by rewrite !(eq_map_poly (map_polyC _)) !map_poly_comp div_annihilantP ?pFto0. Qed. Lemma root_annihilant x p (pEx := (p ^ pFtoE).[x%:P]) : pEx != 0 -> algebraicOver FtoE x -> exists2 r : {poly F}, r != 0 & forall y, root pEx y -> root (r ^ FtoE) y. Proof. move=> nz_px [q nz_q qx0]. have [/size1_polyC Dp | p_gt1] := leqP (size p) 1. by rewrite {}/pEx Dp map_polyC hornerC map_poly_eq0 in nz_px *; exists p`_0. have nz_p: p != 0 by rewrite -size_poly_gt0 ltnW. have [m le_qm] := ubnP (size q); elim: m => // m IHm in q le_qm nz_q qx0 *. have nz_q1: q^:P != 0 by rewrite map_poly_eq0. have sz_q1: size q^:P = size q by rewrite size_map_polyC. have q1_gt1: size q^:P > 1. by rewrite sz_q1 -(size_map_poly FtoE) (root_size_gt1 _ qx0) ?map_poly_eq0. have [uv _ Dr] := resultant_in_ideal p_gt1 q1_gt1; set r := resultant p _ in Dr. have /eqP q1x0: (q^:P ^ pFtoE).[x%:P] == 0. by rewrite -swapXY_polyC -swapXY_map horner_swapXY !map_polyC polyC_eq0. have [|r_nz] := boolP (r == 0); last first. exists r => // y pxy0; rewrite -[r ^ _](hornerC _ x%:P) -map_polyC Dr. by rewrite rmorphD !rmorphM !hornerE q1x0 mulr0 addr0 rootM pxy0 orbT. rewrite resultant_eq0 => /gtn_eqF/Bezout_coprimepPn[]// [q2 p1] /=. rewrite size_poly_gt0 sz_q1 => /andP[/andP[nz_q2 ltq2] _] Dq. pose n := (size (lead_coef q2)).-1; pose q3 := map_poly (coefp n) q2. have nz_q3: q3 != 0 by rewrite map_poly_eq0_id0 ?lead_coef_eq0. apply: (IHm q3); rewrite ?(leq_ltn_trans (size_poly _ _)) ?(leq_trans ltq2) //. have /polyP/(_ n)/eqP: (q2 ^ pFtoE).[x%:P] = 0. apply: (mulIf nz_px); rewrite -hornerM -rmorphM Dq rmorphM hornerM /= q1x0. by rewrite mul0r mulr0. rewrite coef0; congr (_ == 0); rewrite !horner_coef coef_sum. rewrite size_map_poly !size_map_poly_id0 ?map_poly_eq0 ?lead_coef_eq0 //. by apply: eq_bigr => i _; rewrite -rmorphXn coefMC !coef_map. Qed. Lemma algebraic_root_polyXY x y : (let pEx p := (p ^ map_poly FtoE).[x%:P] in exists2 p, pEx p != 0 & root (pEx p) y) -> algebraicOver FtoE x -> algebraicOver FtoE y. Proof. by case=> p nz_px pxy0 /(root_annihilant nz_px)[r]; exists r; auto. Qed. End PolyXY_Field.
Basic.lean
/- Copyright (c) 2021 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kyle Miller -/ import Lean import Mathlib.Tactic.PPWithUniv import Mathlib.Tactic.ExtendDoc import Mathlib.Tactic.Lemma import Mathlib.Tactic.TypeStar import Mathlib.Tactic.Linter.OldObtain import Mathlib.Tactic.Simproc.ExistsAndEq /-! # Basic tactics and utilities for tactic writing This file defines some basic utilities for tactic writing, and also - a dummy `variables` macro (which warns that the Lean 4 name is `variable`) - the `introv` tactic, which allows the user to automatically introduce the variables of a theorem and explicitly name the non-dependent hypotheses, - an `assumption` macro, calling the `assumption` tactic on all goals - the tactics `match_target` and `clear_aux_decl` (clearing all auxiliary declarations from the context). -/ namespace Mathlib.Tactic open Lean Parser.Tactic Elab Command Elab.Tactic Meta /-- Syntax for the `variables` command: this command is just a stub, and merely warns that it has been renamed to `variable` in Lean 4. -/ syntax (name := «variables») "variables" (ppSpace bracketedBinder)* : command /-- The `variables` command: this is just a stub, and merely warns that it has been renamed to `variable` in Lean 4. -/ @[command_elab «variables»] def elabVariables : CommandElab | `(variables%$pos $binders*) => do logWarningAt pos "'variables' has been replaced by 'variable' in lean 4" elabVariable (← `(variable%$pos $binders*)) | _ => throwUnsupportedSyntax /-- Given two arrays of `FVarId`s, one from an old local context and the other from a new local context, pushes `FVarAliasInfo`s into the info tree for corresponding pairs of `FVarId`s. Recall that variables linked this way should be considered to be semantically identical. The effect of this is, for example, the unused variable linter will see that variables from the first array are used if corresponding variables in the second array are used. -/ def pushFVarAliasInfo {m : Type → Type} [Monad m] [MonadInfoTree m] (oldFVars newFVars : Array FVarId) (newLCtx : LocalContext) : m Unit := do for old in oldFVars, new in newFVars do if old != new then let decl := newLCtx.get! new pushInfoLeaf (.ofFVarAliasInfo { id := new, baseId := old, userName := decl.userName }) /-- The tactic `introv` allows the user to automatically introduce the variables of a theorem and explicitly name the non-dependent hypotheses. Any dependent hypotheses are assigned their default names. Examples: ``` example : ∀ a b : Nat, a = b → b = a := by introv h, exact h.symm ``` The state after `introv h` is ``` a b : ℕ, h : a = b ⊢ b = a ``` ``` example : ∀ a b : Nat, a = b → ∀ c, b = c → a = c := by introv h₁ h₂, exact h₁.trans h₂ ``` The state after `introv h₁ h₂` is ``` a b : ℕ, h₁ : a = b, c : ℕ, h₂ : b = c ⊢ a = c ``` -/ syntax (name := introv) "introv " (ppSpace colGt binderIdent)* : tactic @[tactic introv] partial def evalIntrov : Tactic := fun stx ↦ do match stx with | `(tactic| introv) => introsDep | `(tactic| introv $h:ident $hs:binderIdent*) => evalTactic (← `(tactic| introv; intro $h:ident; introv $hs:binderIdent*)) | `(tactic| introv _%$tk $hs:binderIdent*) => evalTactic (← `(tactic| introv; intro _%$tk; introv $hs:binderIdent*)) | _ => throwUnsupportedSyntax where introsDep : TacticM Unit := do let t ← getMainTarget match t with | Expr.forallE _ _ e _ => if e.hasLooseBVars then intro1PStep introsDep | _ => pure () intro1PStep : TacticM Unit := liftMetaTactic fun goal ↦ do let (_, goal) ← goal.intro1P pure [goal] /-- Try calling `assumption` on all goals; succeeds if it closes at least one goal. -/ macro "assumption'" : tactic => `(tactic| any_goals assumption) elab "match_target " t:term : tactic => do withMainContext do let (val) ← elabTerm t (← inferType (← getMainTarget)) if not (← isDefEq val (← getMainTarget)) then throwError "failed" /-- This tactic clears all auxiliary declarations from the context. -/ elab (name := clearAuxDecl) "clear_aux_decl" : tactic => withMainContext do let mut g ← getMainGoal for ldec in ← getLCtx do if ldec.isAuxDecl then g ← g.tryClear ldec.fvarId replaceMainGoal [g] attribute [pp_with_univ] ULift PUnit PEmpty end Mathlib.Tactic
Homology.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.RightHomology /-! # Homology of short complexes In this file, we shall define the homology of short complexes `S`, i.e. diagrams `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` such that `f ≫ g = 0`. We shall say that `[S.HasHomology]` when there exists `h : S.HomologyData`. A homology data for `S` consists of compatible left/right homology data `left` and `right`. The left homology data `left` involves an object `left.H` that is a cokernel of the canonical map `S.X₁ ⟶ K` where `K` is a kernel of `g`. On the other hand, the dual notion `right.H` is a kernel of the canonical morphism `Q ⟶ S.X₃` when `Q` is a cokernel of `f`. The compatibility that is required involves an isomorphism `left.H ≅ right.H` which makes a certain pentagon commute. When such a homology data exists, `S.homology` shall be defined as `h.left.H` for a chosen `h : S.HomologyData`. This definition requires very little assumption on the category (only the existence of zero morphisms). We shall prove that in abelian categories, all short complexes have homology data. Note: This definition arose by the end of the Liquid Tensor Experiment which contained a structure `has_homology` which is quite similar to `S.HomologyData`. After the category `ShortComplex C` was introduced by J. Riou, A. Topaz suggested such a structure could be used as a basis for the *definition* of homology. -/ universe v u namespace CategoryTheory open Category Limits variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] (S : ShortComplex C) {S₁ S₂ S₃ S₄ : ShortComplex C} namespace ShortComplex /-- A homology data for a short complex consists of two compatible left and right homology data -/ structure HomologyData where /-- a left homology data -/ left : S.LeftHomologyData /-- a right homology data -/ right : S.RightHomologyData /-- the compatibility isomorphism relating the two dual notions of `LeftHomologyData` and `RightHomologyData` -/ iso : left.H ≅ right.H /-- the pentagon relation expressing the compatibility of the left and right homology data -/ comm : left.π ≫ iso.hom ≫ right.ι = left.i ≫ right.p := by cat_disch attribute [reassoc (attr := simp)] HomologyData.comm variable (φ : S₁ ⟶ S₂) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) /-- A homology map data for a morphism `φ : S₁ ⟶ S₂` where both `S₁` and `S₂` are equipped with homology data consists of left and right homology map data. -/ structure HomologyMapData where /-- a left homology map data -/ left : LeftHomologyMapData φ h₁.left h₂.left /-- a right homology map data -/ right : RightHomologyMapData φ h₁.right h₂.right namespace HomologyMapData variable {φ h₁ h₂} @[reassoc] lemma comm (h : HomologyMapData φ h₁ h₂) : h.left.φH ≫ h₂.iso.hom = h₁.iso.hom ≫ h.right.φH := by simp only [← cancel_epi h₁.left.π, ← cancel_mono h₂.right.ι, assoc, LeftHomologyMapData.commπ_assoc, HomologyData.comm, LeftHomologyMapData.commi_assoc, RightHomologyMapData.commι, HomologyData.comm_assoc, RightHomologyMapData.commp] instance : Subsingleton (HomologyMapData φ h₁ h₂) := ⟨by rintro ⟨left₁, right₁⟩ ⟨left₂, right₂⟩ simp only [mk.injEq, eq_iff_true_of_subsingleton, and_self]⟩ instance : Inhabited (HomologyMapData φ h₁ h₂) := ⟨⟨default, default⟩⟩ instance : Unique (HomologyMapData φ h₁ h₂) := Unique.mk' _ variable (φ h₁ h₂) /-- A choice of the (unique) homology map data associated with a morphism `φ : S₁ ⟶ S₂` where both short complexes `S₁` and `S₂` are equipped with homology data. -/ def homologyMapData : HomologyMapData φ h₁ h₂ := default variable {φ h₁ h₂} lemma congr_left_φH {γ₁ γ₂ : HomologyMapData φ h₁ h₂} (eq : γ₁ = γ₂) : γ₁.left.φH = γ₂.left.φH := by rw [eq] end HomologyMapData namespace HomologyData /-- When the first map `S.f` is zero, this is the homology data on `S` given by any limit kernel fork of `S.g` -/ @[simps] def ofIsLimitKernelFork (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) : S.HomologyData where left := LeftHomologyData.ofIsLimitKernelFork S hf c hc right := RightHomologyData.ofIsLimitKernelFork S hf c hc iso := Iso.refl _ /-- When the first map `S.f` is zero, this is the homology data on `S` given by the chosen `kernel S.g` -/ @[simps] noncomputable def ofHasKernel (hf : S.f = 0) [HasKernel S.g] : S.HomologyData where left := LeftHomologyData.ofHasKernel S hf right := RightHomologyData.ofHasKernel S hf iso := Iso.refl _ /-- When the second map `S.g` is zero, this is the homology data on `S` given by any colimit cokernel cofork of `S.f` -/ @[simps] def ofIsColimitCokernelCofork (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : S.HomologyData where left := LeftHomologyData.ofIsColimitCokernelCofork S hg c hc right := RightHomologyData.ofIsColimitCokernelCofork S hg c hc iso := Iso.refl _ /-- When the second map `S.g` is zero, this is the homology data on `S` given by the chosen `cokernel S.f` -/ @[simps] noncomputable def ofHasCokernel (hg : S.g = 0) [HasCokernel S.f] : S.HomologyData where left := LeftHomologyData.ofHasCokernel S hg right := RightHomologyData.ofHasCokernel S hg iso := Iso.refl _ /-- When both `S.f` and `S.g` are zero, the middle object `S.X₂` gives a homology data on S -/ @[simps] noncomputable def ofZeros (hf : S.f = 0) (hg : S.g = 0) : S.HomologyData where left := LeftHomologyData.ofZeros S hf hg right := RightHomologyData.ofZeros S hf hg iso := Iso.refl _ /-- If `φ : S₁ ⟶ S₂` is a morphism of short complexes such that `φ.τ₁` is epi, `φ.τ₂` is an iso and `φ.τ₃` is mono, then a homology data for `S₁` induces a homology data for `S₂`. The inverse construction is `ofEpiOfIsIsoOfMono'`. -/ @[simps] noncomputable def ofEpiOfIsIsoOfMono (φ : S₁ ⟶ S₂) (h : HomologyData S₁) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HomologyData S₂ where left := LeftHomologyData.ofEpiOfIsIsoOfMono φ h.left right := RightHomologyData.ofEpiOfIsIsoOfMono φ h.right iso := h.iso /-- If `φ : S₁ ⟶ S₂` is a morphism of short complexes such that `φ.τ₁` is epi, `φ.τ₂` is an iso and `φ.τ₃` is mono, then a homology data for `S₂` induces a homology data for `S₁`. The inverse construction is `ofEpiOfIsIsoOfMono`. -/ @[simps] noncomputable def ofEpiOfIsIsoOfMono' (φ : S₁ ⟶ S₂) (h : HomologyData S₂) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HomologyData S₁ where left := LeftHomologyData.ofEpiOfIsIsoOfMono' φ h.left right := RightHomologyData.ofEpiOfIsIsoOfMono' φ h.right iso := h.iso /-- If `e : S₁ ≅ S₂` is an isomorphism of short complexes and `h₁ : HomologyData S₁`, this is the homology data for `S₂` deduced from the isomorphism. -/ @[simps!] noncomputable def ofIso (e : S₁ ≅ S₂) (h : HomologyData S₁) := h.ofEpiOfIsIsoOfMono e.hom variable {S} /-- A homology data for a short complex `S` induces a homology data for `S.op`. -/ @[simps] def op (h : S.HomologyData) : S.op.HomologyData where left := h.right.op right := h.left.op iso := h.iso.op comm := Quiver.Hom.unop_inj (by simp) /-- A homology data for a short complex `S` in the opposite category induces a homology data for `S.unop`. -/ @[simps] def unop {S : ShortComplex Cᵒᵖ} (h : S.HomologyData) : S.unop.HomologyData where left := h.right.unop right := h.left.unop iso := h.iso.unop comm := Quiver.Hom.op_inj (by simp) end HomologyData /-- A short complex `S` has homology when there exists a `S.HomologyData` -/ class HasHomology : Prop where /-- the condition that there exists a homology data -/ condition : Nonempty S.HomologyData /-- A chosen `S.HomologyData` for a short complex `S` that has homology -/ noncomputable def homologyData [HasHomology S] : S.HomologyData := HasHomology.condition.some variable {S} lemma HasHomology.mk' (h : S.HomologyData) : HasHomology S := ⟨Nonempty.intro h⟩ instance [HasHomology S] : HasHomology S.op := HasHomology.mk' S.homologyData.op instance (S : ShortComplex Cᵒᵖ) [HasHomology S] : HasHomology S.unop := HasHomology.mk' S.homologyData.unop instance hasLeftHomology_of_hasHomology [S.HasHomology] : S.HasLeftHomology := HasLeftHomology.mk' S.homologyData.left instance hasRightHomology_of_hasHomology [S.HasHomology] : S.HasRightHomology := HasRightHomology.mk' S.homologyData.right instance hasHomology_of_hasCokernel {X Y : C} (f : X ⟶ Y) (Z : C) [HasCokernel f] : (ShortComplex.mk f (0 : Y ⟶ Z) comp_zero).HasHomology := HasHomology.mk' (HomologyData.ofHasCokernel _ rfl) instance hasHomology_of_hasKernel {Y Z : C} (g : Y ⟶ Z) (X : C) [HasKernel g] : (ShortComplex.mk (0 : X ⟶ Y) g zero_comp).HasHomology := HasHomology.mk' (HomologyData.ofHasKernel _ rfl) instance hasHomology_of_zeros (X Y Z : C) : (ShortComplex.mk (0 : X ⟶ Y) (0 : Y ⟶ Z) zero_comp).HasHomology := HasHomology.mk' (HomologyData.ofZeros _ rfl rfl) lemma hasHomology_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) [HasHomology S₁] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HasHomology S₂ := HasHomology.mk' (HomologyData.ofEpiOfIsIsoOfMono φ S₁.homologyData) lemma hasHomology_of_epi_of_isIso_of_mono' (φ : S₁ ⟶ S₂) [HasHomology S₂] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HasHomology S₁ := HasHomology.mk' (HomologyData.ofEpiOfIsIsoOfMono' φ S₂.homologyData) lemma hasHomology_of_iso (e : S₁ ≅ S₂) [HasHomology S₁] : HasHomology S₂ := HasHomology.mk' (HomologyData.ofIso e S₁.homologyData) namespace HomologyMapData /-- The homology map data associated to the identity morphism of a short complex. -/ @[simps] def id (h : S.HomologyData) : HomologyMapData (𝟙 S) h h where left := LeftHomologyMapData.id h.left right := RightHomologyMapData.id h.right /-- The homology map data associated to the zero morphism between two short complexes. -/ @[simps] def zero (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) : HomologyMapData 0 h₁ h₂ where left := LeftHomologyMapData.zero h₁.left h₂.left right := RightHomologyMapData.zero h₁.right h₂.right /-- The composition of homology map data. -/ @[simps] def comp {φ : S₁ ⟶ S₂} {φ' : S₂ ⟶ S₃} {h₁ : S₁.HomologyData} {h₂ : S₂.HomologyData} {h₃ : S₃.HomologyData} (ψ : HomologyMapData φ h₁ h₂) (ψ' : HomologyMapData φ' h₂ h₃) : HomologyMapData (φ ≫ φ') h₁ h₃ where left := ψ.left.comp ψ'.left right := ψ.right.comp ψ'.right /-- A homology map data for a morphism of short complexes induces a homology map data in the opposite category. -/ @[simps] def op {φ : S₁ ⟶ S₂} {h₁ : S₁.HomologyData} {h₂ : S₂.HomologyData} (ψ : HomologyMapData φ h₁ h₂) : HomologyMapData (opMap φ) h₂.op h₁.op where left := ψ.right.op right := ψ.left.op /-- A homology map data for a morphism of short complexes in the opposite category induces a homology map data in the original category. -/ @[simps] def unop {S₁ S₂ : ShortComplex Cᵒᵖ} {φ : S₁ ⟶ S₂} {h₁ : S₁.HomologyData} {h₂ : S₂.HomologyData} (ψ : HomologyMapData φ h₁ h₂) : HomologyMapData (unopMap φ) h₂.unop h₁.unop where left := ψ.right.unop right := ψ.left.unop /-- When `S₁.f`, `S₁.g`, `S₂.f` and `S₂.g` are all zero, the action on homology of a morphism `φ : S₁ ⟶ S₂` is given by the action `φ.τ₂` on the middle objects. -/ @[simps] noncomputable def ofZeros (φ : S₁ ⟶ S₂) (hf₁ : S₁.f = 0) (hg₁ : S₁.g = 0) (hf₂ : S₂.f = 0) (hg₂ : S₂.g = 0) : HomologyMapData φ (HomologyData.ofZeros S₁ hf₁ hg₁) (HomologyData.ofZeros S₂ hf₂ hg₂) where left := LeftHomologyMapData.ofZeros φ hf₁ hg₁ hf₂ hg₂ right := RightHomologyMapData.ofZeros φ hf₁ hg₁ hf₂ hg₂ /-- When `S₁.g` and `S₂.g` are zero and we have chosen colimit cokernel coforks `c₁` and `c₂` for `S₁.f` and `S₂.f` respectively, the action on homology of a morphism `φ : S₁ ⟶ S₂` of short complexes is given by the unique morphism `f : c₁.pt ⟶ c₂.pt` such that `φ.τ₂ ≫ c₂.π = c₁.π ≫ f`. -/ @[simps] def ofIsColimitCokernelCofork (φ : S₁ ⟶ S₂) (hg₁ : S₁.g = 0) (c₁ : CokernelCofork S₁.f) (hc₁ : IsColimit c₁) (hg₂ : S₂.g = 0) (c₂ : CokernelCofork S₂.f) (hc₂ : IsColimit c₂) (f : c₁.pt ⟶ c₂.pt) (comm : φ.τ₂ ≫ c₂.π = c₁.π ≫ f) : HomologyMapData φ (HomologyData.ofIsColimitCokernelCofork S₁ hg₁ c₁ hc₁) (HomologyData.ofIsColimitCokernelCofork S₂ hg₂ c₂ hc₂) where left := LeftHomologyMapData.ofIsColimitCokernelCofork φ hg₁ c₁ hc₁ hg₂ c₂ hc₂ f comm right := RightHomologyMapData.ofIsColimitCokernelCofork φ hg₁ c₁ hc₁ hg₂ c₂ hc₂ f comm /-- When `S₁.f` and `S₂.f` are zero and we have chosen limit kernel forks `c₁` and `c₂` for `S₁.g` and `S₂.g` respectively, the action on homology of a morphism `φ : S₁ ⟶ S₂` of short complexes is given by the unique morphism `f : c₁.pt ⟶ c₂.pt` such that `c₁.ι ≫ φ.τ₂ = f ≫ c₂.ι`. -/ @[simps] def ofIsLimitKernelFork (φ : S₁ ⟶ S₂) (hf₁ : S₁.f = 0) (c₁ : KernelFork S₁.g) (hc₁ : IsLimit c₁) (hf₂ : S₂.f = 0) (c₂ : KernelFork S₂.g) (hc₂ : IsLimit c₂) (f : c₁.pt ⟶ c₂.pt) (comm : c₁.ι ≫ φ.τ₂ = f ≫ c₂.ι) : HomologyMapData φ (HomologyData.ofIsLimitKernelFork S₁ hf₁ c₁ hc₁) (HomologyData.ofIsLimitKernelFork S₂ hf₂ c₂ hc₂) where left := LeftHomologyMapData.ofIsLimitKernelFork φ hf₁ c₁ hc₁ hf₂ c₂ hc₂ f comm right := RightHomologyMapData.ofIsLimitKernelFork φ hf₁ c₁ hc₁ hf₂ c₂ hc₂ f comm /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the homology map data (for the identity of `S`) which relates the homology data `ofZeros` and `ofIsColimitCokernelCofork`. -/ noncomputable def compatibilityOfZerosOfIsColimitCokernelCofork (hf : S.f = 0) (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : HomologyMapData (𝟙 S) (HomologyData.ofZeros S hf hg) (HomologyData.ofIsColimitCokernelCofork S hg c hc) where left := LeftHomologyMapData.compatibilityOfZerosOfIsColimitCokernelCofork S hf hg c hc right := RightHomologyMapData.compatibilityOfZerosOfIsColimitCokernelCofork S hf hg c hc /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the homology map data (for the identity of `S`) which relates the homology data `HomologyData.ofIsLimitKernelFork` and `ofZeros` . -/ @[simps] noncomputable def compatibilityOfZerosOfIsLimitKernelFork (hf : S.f = 0) (hg : S.g = 0) (c : KernelFork S.g) (hc : IsLimit c) : HomologyMapData (𝟙 S) (HomologyData.ofIsLimitKernelFork S hf c hc) (HomologyData.ofZeros S hf hg) where left := LeftHomologyMapData.compatibilityOfZerosOfIsLimitKernelFork S hf hg c hc right := RightHomologyMapData.compatibilityOfZerosOfIsLimitKernelFork S hf hg c hc /-- This homology map data expresses compatibilities of the homology data constructed by `HomologyData.ofEpiOfIsIsoOfMono` -/ noncomputable def ofEpiOfIsIsoOfMono (φ : S₁ ⟶ S₂) (h : HomologyData S₁) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HomologyMapData φ h (HomologyData.ofEpiOfIsIsoOfMono φ h) where left := LeftHomologyMapData.ofEpiOfIsIsoOfMono φ h.left right := RightHomologyMapData.ofEpiOfIsIsoOfMono φ h.right /-- This homology map data expresses compatibilities of the homology data constructed by `HomologyData.ofEpiOfIsIsoOfMono'` -/ noncomputable def ofEpiOfIsIsoOfMono' (φ : S₁ ⟶ S₂) (h : HomologyData S₂) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HomologyMapData φ (HomologyData.ofEpiOfIsIsoOfMono' φ h) h where left := LeftHomologyMapData.ofEpiOfIsIsoOfMono' φ h.left right := RightHomologyMapData.ofEpiOfIsIsoOfMono' φ h.right end HomologyMapData variable (S) /-- The homology of a short complex is the `left.H` field of a chosen homology data. -/ noncomputable def homology [HasHomology S] : C := S.homologyData.left.H /-- When a short complex has homology, this is the canonical isomorphism `S.leftHomology ≅ S.homology`. -/ noncomputable def leftHomologyIso [S.HasHomology] : S.leftHomology ≅ S.homology := leftHomologyMapIso' (Iso.refl _) _ _ /-- When a short complex has homology, this is the canonical isomorphism `S.rightHomology ≅ S.homology`. -/ noncomputable def rightHomologyIso [S.HasHomology] : S.rightHomology ≅ S.homology := rightHomologyMapIso' (Iso.refl _) _ _ ≪≫ S.homologyData.iso.symm variable {S} /-- When a short complex has homology, its homology can be computed using any left homology data. -/ noncomputable def LeftHomologyData.homologyIso (h : S.LeftHomologyData) [S.HasHomology] : S.homology ≅ h.H := S.leftHomologyIso.symm ≪≫ h.leftHomologyIso /-- When a short complex has homology, its homology can be computed using any right homology data. -/ noncomputable def RightHomologyData.homologyIso (h : S.RightHomologyData) [S.HasHomology] : S.homology ≅ h.H := S.rightHomologyIso.symm ≪≫ h.rightHomologyIso variable (S) @[simp] lemma LeftHomologyData.homologyIso_leftHomologyData [S.HasHomology] : S.leftHomologyData.homologyIso = S.leftHomologyIso.symm := by ext dsimp [homologyIso, leftHomologyIso, ShortComplex.leftHomologyIso] rw [← leftHomologyMap'_comp, comp_id] @[simp] lemma RightHomologyData.homologyIso_rightHomologyData [S.HasHomology] : S.rightHomologyData.homologyIso = S.rightHomologyIso.symm := by ext simp [homologyIso, rightHomologyIso] variable {S} /-- Given a morphism `φ : S₁ ⟶ S₂` of short complexes and homology data `h₁` and `h₂` for `S₁` and `S₂` respectively, this is the induced homology map `h₁.left.H ⟶ h₁.left.H`. -/ def homologyMap' (φ : S₁ ⟶ S₂) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) : h₁.left.H ⟶ h₂.left.H := leftHomologyMap' φ _ _ /-- The homology map `S₁.homology ⟶ S₂.homology` induced by a morphism `S₁ ⟶ S₂` of short complexes. -/ noncomputable def homologyMap (φ : S₁ ⟶ S₂) [HasHomology S₁] [HasHomology S₂] : S₁.homology ⟶ S₂.homology := homologyMap' φ _ _ namespace HomologyMapData variable {φ : S₁ ⟶ S₂} {h₁ : S₁.HomologyData} {h₂ : S₂.HomologyData} (γ : HomologyMapData φ h₁ h₂) lemma homologyMap'_eq : homologyMap' φ h₁ h₂ = γ.left.φH := LeftHomologyMapData.congr_φH (Subsingleton.elim _ _) lemma cyclesMap'_eq : cyclesMap' φ h₁.left h₂.left = γ.left.φK := LeftHomologyMapData.congr_φK (Subsingleton.elim _ _) lemma opcyclesMap'_eq : opcyclesMap' φ h₁.right h₂.right = γ.right.φQ := RightHomologyMapData.congr_φQ (Subsingleton.elim _ _) end HomologyMapData namespace LeftHomologyMapData variable {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} (γ : LeftHomologyMapData φ h₁ h₂) [S₁.HasHomology] [S₂.HasHomology] lemma homologyMap_eq : homologyMap φ = h₁.homologyIso.hom ≫ γ.φH ≫ h₂.homologyIso.inv := by dsimp [homologyMap, LeftHomologyData.homologyIso, leftHomologyIso, LeftHomologyData.leftHomologyIso, homologyMap'] simp only [← γ.leftHomologyMap'_eq, ← leftHomologyMap'_comp, id_comp, comp_id] lemma homologyMap_comm : homologyMap φ ≫ h₂.homologyIso.hom = h₁.homologyIso.hom ≫ γ.φH := by simp only [γ.homologyMap_eq, assoc, Iso.inv_hom_id, comp_id] end LeftHomologyMapData namespace RightHomologyMapData variable {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} (γ : RightHomologyMapData φ h₁ h₂) [S₁.HasHomology] [S₂.HasHomology] lemma homologyMap_eq : homologyMap φ = h₁.homologyIso.hom ≫ γ.φH ≫ h₂.homologyIso.inv := by dsimp [homologyMap, homologyMap', RightHomologyData.homologyIso, rightHomologyIso, RightHomologyData.rightHomologyIso] have γ' : HomologyMapData φ S₁.homologyData S₂.homologyData := default simp only [← γ.rightHomologyMap'_eq, assoc, ← rightHomologyMap'_comp_assoc, id_comp, comp_id, γ'.left.leftHomologyMap'_eq, γ'.right.rightHomologyMap'_eq, ← γ'.comm_assoc, Iso.hom_inv_id] lemma homologyMap_comm : homologyMap φ ≫ h₂.homologyIso.hom = h₁.homologyIso.hom ≫ γ.φH := by simp only [γ.homologyMap_eq, assoc, Iso.inv_hom_id, comp_id] end RightHomologyMapData @[simp] lemma homologyMap'_id (h : S.HomologyData) : homologyMap' (𝟙 S) h h = 𝟙 _ := (HomologyMapData.id h).homologyMap'_eq variable (S) @[simp] lemma homologyMap_id [HasHomology S] : homologyMap (𝟙 S) = 𝟙 _ := homologyMap'_id _ @[simp] lemma homologyMap'_zero (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) : homologyMap' 0 h₁ h₂ = 0 := (HomologyMapData.zero h₁ h₂).homologyMap'_eq variable (S₁ S₂) @[simp] lemma homologyMap_zero [S₁.HasHomology] [S₂.HasHomology] : homologyMap (0 : S₁ ⟶ S₂) = 0 := homologyMap'_zero _ _ variable {S₁ S₂} lemma homologyMap'_comp (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) (h₃ : S₃.HomologyData) : homologyMap' (φ₁ ≫ φ₂) h₁ h₃ = homologyMap' φ₁ h₁ h₂ ≫ homologyMap' φ₂ h₂ h₃ := leftHomologyMap'_comp _ _ _ _ _ @[simp] lemma homologyMap_comp [HasHomology S₁] [HasHomology S₂] [HasHomology S₃] (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) : homologyMap (φ₁ ≫ φ₂) = homologyMap φ₁ ≫ homologyMap φ₂ := homologyMap'_comp _ _ _ _ _ /-- Given an isomorphism `S₁ ≅ S₂` of short complexes and homology data `h₁` and `h₂` for `S₁` and `S₂` respectively, this is the induced homology isomorphism `h₁.left.H ≅ h₁.left.H`. -/ @[simps] def homologyMapIso' (e : S₁ ≅ S₂) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) : h₁.left.H ≅ h₂.left.H where hom := homologyMap' e.hom h₁ h₂ inv := homologyMap' e.inv h₂ h₁ hom_inv_id := by rw [← homologyMap'_comp, e.hom_inv_id, homologyMap'_id] inv_hom_id := by rw [← homologyMap'_comp, e.inv_hom_id, homologyMap'_id] instance isIso_homologyMap'_of_isIso (φ : S₁ ⟶ S₂) [IsIso φ] (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) : IsIso (homologyMap' φ h₁ h₂) := (inferInstance : IsIso (homologyMapIso' (asIso φ) h₁ h₂).hom) /-- The homology isomorphism `S₁.homology ⟶ S₂.homology` induced by an isomorphism `S₁ ≅ S₂` of short complexes. -/ @[simps] noncomputable def homologyMapIso (e : S₁ ≅ S₂) [S₁.HasHomology] [S₂.HasHomology] : S₁.homology ≅ S₂.homology where hom := homologyMap e.hom inv := homologyMap e.inv hom_inv_id := by rw [← homologyMap_comp, e.hom_inv_id, homologyMap_id] inv_hom_id := by rw [← homologyMap_comp, e.inv_hom_id, homologyMap_id] instance isIso_homologyMap_of_iso (φ : S₁ ⟶ S₂) [IsIso φ] [S₁.HasHomology] [S₂.HasHomology] : IsIso (homologyMap φ) := (inferInstance : IsIso (homologyMapIso (asIso φ)).hom) variable {S} section variable (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) /-- If a short complex `S` has both a left homology data `h₁` and a right homology data `h₂`, this is the canonical morphism `h₁.H ⟶ h₂.H`. -/ def leftRightHomologyComparison' : h₁.H ⟶ h₂.H := h₂.liftH (h₁.descH (h₁.i ≫ h₂.p) (by simp)) (by rw [← cancel_epi h₁.π, LeftHomologyData.π_descH_assoc, assoc, RightHomologyData.p_g', LeftHomologyData.wi, comp_zero]) lemma leftRightHomologyComparison'_eq_liftH : leftRightHomologyComparison' h₁ h₂ = h₂.liftH (h₁.descH (h₁.i ≫ h₂.p) (by simp)) (by rw [← cancel_epi h₁.π, LeftHomologyData.π_descH_assoc, assoc, RightHomologyData.p_g', LeftHomologyData.wi, comp_zero]) := rfl @[reassoc (attr := simp)] lemma π_leftRightHomologyComparison'_ι : h₁.π ≫ leftRightHomologyComparison' h₁ h₂ ≫ h₂.ι = h₁.i ≫ h₂.p := by simp only [leftRightHomologyComparison'_eq_liftH, RightHomologyData.liftH_ι, LeftHomologyData.π_descH] lemma leftRightHomologyComparison'_eq_descH : leftRightHomologyComparison' h₁ h₂ = h₁.descH (h₂.liftH (h₁.i ≫ h₂.p) (by simp)) (by rw [← cancel_mono h₂.ι, assoc, RightHomologyData.liftH_ι, LeftHomologyData.f'_i_assoc, RightHomologyData.wp, zero_comp]) := by simp only [← cancel_mono h₂.ι, ← cancel_epi h₁.π, π_leftRightHomologyComparison'_ι, LeftHomologyData.π_descH_assoc, RightHomologyData.liftH_ι] end variable (S) /-- If a short complex `S` has both a left and right homology, this is the canonical morphism `S.leftHomology ⟶ S.rightHomology`. -/ noncomputable def leftRightHomologyComparison [S.HasLeftHomology] [S.HasRightHomology] : S.leftHomology ⟶ S.rightHomology := leftRightHomologyComparison' _ _ @[reassoc (attr := simp)] lemma π_leftRightHomologyComparison_ι [S.HasLeftHomology] [S.HasRightHomology] : S.leftHomologyπ ≫ S.leftRightHomologyComparison ≫ S.rightHomologyι = S.iCycles ≫ S.pOpcycles := π_leftRightHomologyComparison'_ι _ _ @[reassoc] lemma leftRightHomologyComparison'_naturality (φ : S₁ ⟶ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₁.RightHomologyData) (h₁' : S₂.LeftHomologyData) (h₂' : S₂.RightHomologyData) : leftHomologyMap' φ h₁ h₁' ≫ leftRightHomologyComparison' h₁' h₂' = leftRightHomologyComparison' h₁ h₂ ≫ rightHomologyMap' φ h₂ h₂' := by simp only [← cancel_epi h₁.π, ← cancel_mono h₂'.ι, assoc, leftHomologyπ_naturality'_assoc, rightHomologyι_naturality', π_leftRightHomologyComparison'_ι, π_leftRightHomologyComparison'_ι_assoc, cyclesMap'_i_assoc, p_opcyclesMap'] variable {S} lemma leftRightHomologyComparison'_compatibility (h₁ h₁' : S.LeftHomologyData) (h₂ h₂' : S.RightHomologyData) : leftRightHomologyComparison' h₁ h₂ = leftHomologyMap' (𝟙 S) h₁ h₁' ≫ leftRightHomologyComparison' h₁' h₂' ≫ rightHomologyMap' (𝟙 S) _ _ := by rw [leftRightHomologyComparison'_naturality_assoc (𝟙 S) h₁ h₂ h₁' h₂', ← rightHomologyMap'_comp, comp_id, rightHomologyMap'_id, comp_id] lemma leftRightHomologyComparison_eq [S.HasLeftHomology] [S.HasRightHomology] (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) : S.leftRightHomologyComparison = h₁.leftHomologyIso.hom ≫ leftRightHomologyComparison' h₁ h₂ ≫ h₂.rightHomologyIso.inv := leftRightHomologyComparison'_compatibility _ _ _ _ @[simp] lemma HomologyData.leftRightHomologyComparison'_eq (h : S.HomologyData) : leftRightHomologyComparison' h.left h.right = h.iso.hom := by simp only [← cancel_epi h.left.π, ← cancel_mono h.right.ι, assoc, π_leftRightHomologyComparison'_ι, comm] instance isIso_leftRightHomologyComparison'_of_homologyData (h : S.HomologyData) : IsIso (leftRightHomologyComparison' h.left h.right) := by rw [h.leftRightHomologyComparison'_eq] infer_instance instance isIso_leftRightHomologyComparison' [S.HasHomology] (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) : IsIso (leftRightHomologyComparison' h₁ h₂) := by rw [leftRightHomologyComparison'_compatibility h₁ S.homologyData.left h₂ S.homologyData.right] infer_instance instance isIso_leftRightHomologyComparison [S.HasHomology] : IsIso S.leftRightHomologyComparison := by dsimp only [leftRightHomologyComparison] infer_instance namespace HomologyData /-- This is the homology data for a short complex `S` that is obtained from a left homology data `h₁` and a right homology data `h₂` when the comparison morphism `leftRightHomologyComparison' h₁ h₂ : h₁.H ⟶ h₂.H` is an isomorphism. -/ @[simps] noncomputable def ofIsIsoLeftRightHomologyComparison' (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) [IsIso (leftRightHomologyComparison' h₁ h₂)] : S.HomologyData where left := h₁ right := h₂ iso := asIso (leftRightHomologyComparison' h₁ h₂) end HomologyData lemma leftRightHomologyComparison'_eq_leftHomologpMap'_comp_iso_hom_comp_rightHomologyMap' (h : S.HomologyData) (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) : leftRightHomologyComparison' h₁ h₂ = leftHomologyMap' (𝟙 S) h₁ h.left ≫ h.iso.hom ≫ rightHomologyMap' (𝟙 S) h.right h₂ := by simpa only [h.leftRightHomologyComparison'_eq] using leftRightHomologyComparison'_compatibility h₁ h.left h₂ h.right @[reassoc] lemma leftRightHomologyComparison'_fac (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) [S.HasHomology] : leftRightHomologyComparison' h₁ h₂ = h₁.homologyIso.inv ≫ h₂.homologyIso.hom := by rw [leftRightHomologyComparison'_eq_leftHomologpMap'_comp_iso_hom_comp_rightHomologyMap' S.homologyData h₁ h₂] dsimp only [LeftHomologyData.homologyIso, LeftHomologyData.leftHomologyIso, Iso.symm, Iso.trans, Iso.refl, leftHomologyMapIso', leftHomologyIso, RightHomologyData.homologyIso, RightHomologyData.rightHomologyIso, rightHomologyMapIso', rightHomologyIso] simp only [assoc, ← leftHomologyMap'_comp_assoc, id_comp, ← rightHomologyMap'_comp] variable (S) @[reassoc] lemma leftRightHomologyComparison_fac [S.HasHomology] : S.leftRightHomologyComparison = S.leftHomologyIso.hom ≫ S.rightHomologyIso.inv := by simpa only [LeftHomologyData.homologyIso_leftHomologyData, Iso.symm_inv, RightHomologyData.homologyIso_rightHomologyData, Iso.symm_hom] using leftRightHomologyComparison'_fac S.leftHomologyData S.rightHomologyData variable {S} lemma HomologyData.right_homologyIso_eq_left_homologyIso_trans_iso (h : S.HomologyData) [S.HasHomology] : h.right.homologyIso = h.left.homologyIso ≪≫ h.iso := by suffices h.iso = h.left.homologyIso.symm ≪≫ h.right.homologyIso by rw [this, Iso.self_symm_id_assoc] ext dsimp rw [← leftRightHomologyComparison'_fac, leftRightHomologyComparison'_eq] lemma hasHomology_of_isIso_leftRightHomologyComparison' (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) [IsIso (leftRightHomologyComparison' h₁ h₂)] : S.HasHomology := HasHomology.mk' (HomologyData.ofIsIsoLeftRightHomologyComparison' h₁ h₂) lemma hasHomology_of_isIsoLeftRightHomologyComparison [S.HasLeftHomology] [S.HasRightHomology] [h : IsIso S.leftRightHomologyComparison] : S.HasHomology := by haveI : IsIso (leftRightHomologyComparison' S.leftHomologyData S.rightHomologyData) := h exact hasHomology_of_isIso_leftRightHomologyComparison' S.leftHomologyData S.rightHomologyData section variable [S₁.HasHomology] [S₂.HasHomology] (φ : S₁ ⟶ S₂) @[reassoc] lemma LeftHomologyData.leftHomologyIso_hom_naturality (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : h₁.homologyIso.hom ≫ leftHomologyMap' φ h₁ h₂ = homologyMap φ ≫ h₂.homologyIso.hom := by dsimp [homologyIso, ShortComplex.leftHomologyIso, homologyMap, homologyMap', leftHomologyIso] simp only [← leftHomologyMap'_comp, id_comp, comp_id] @[reassoc] lemma LeftHomologyData.leftHomologyIso_inv_naturality (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : h₁.homologyIso.inv ≫ homologyMap φ = leftHomologyMap' φ h₁ h₂ ≫ h₂.homologyIso.inv := by dsimp [homologyIso, ShortComplex.leftHomologyIso, homologyMap, homologyMap', leftHomologyIso] simp only [← leftHomologyMap'_comp, id_comp, comp_id] @[reassoc] lemma leftHomologyIso_hom_naturality : S₁.leftHomologyIso.hom ≫ homologyMap φ = leftHomologyMap φ ≫ S₂.leftHomologyIso.hom := by simpa only [LeftHomologyData.homologyIso_leftHomologyData, Iso.symm_inv] using LeftHomologyData.leftHomologyIso_inv_naturality φ S₁.leftHomologyData S₂.leftHomologyData @[reassoc] lemma leftHomologyIso_inv_naturality : S₁.leftHomologyIso.inv ≫ leftHomologyMap φ = homologyMap φ ≫ S₂.leftHomologyIso.inv := by simpa only [LeftHomologyData.homologyIso_leftHomologyData, Iso.symm_inv] using LeftHomologyData.leftHomologyIso_hom_naturality φ S₁.leftHomologyData S₂.leftHomologyData @[reassoc] lemma RightHomologyData.rightHomologyIso_hom_naturality (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : h₁.homologyIso.hom ≫ rightHomologyMap' φ h₁ h₂ = homologyMap φ ≫ h₂.homologyIso.hom := by rw [← cancel_epi h₁.homologyIso.inv, Iso.inv_hom_id_assoc, ← cancel_epi (leftRightHomologyComparison' S₁.leftHomologyData h₁), ← leftRightHomologyComparison'_naturality φ S₁.leftHomologyData h₁ S₂.leftHomologyData h₂, ← cancel_epi (S₁.leftHomologyData.homologyIso.hom), LeftHomologyData.leftHomologyIso_hom_naturality_assoc, leftRightHomologyComparison'_fac, leftRightHomologyComparison'_fac, assoc, Iso.hom_inv_id_assoc, Iso.hom_inv_id_assoc, Iso.hom_inv_id_assoc] @[reassoc] lemma RightHomologyData.rightHomologyIso_inv_naturality (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : h₁.homologyIso.inv ≫ homologyMap φ = rightHomologyMap' φ h₁ h₂ ≫ h₂.homologyIso.inv := by simp only [← cancel_mono h₂.homologyIso.hom, assoc, Iso.inv_hom_id_assoc, comp_id, ← RightHomologyData.rightHomologyIso_hom_naturality φ h₁ h₂, Iso.inv_hom_id] @[reassoc] lemma rightHomologyIso_hom_naturality : S₁.rightHomologyIso.hom ≫ homologyMap φ = rightHomologyMap φ ≫ S₂.rightHomologyIso.hom := by simpa only [RightHomologyData.homologyIso_rightHomologyData, Iso.symm_inv] using RightHomologyData.rightHomologyIso_inv_naturality φ S₁.rightHomologyData S₂.rightHomologyData @[reassoc] lemma rightHomologyIso_inv_naturality : S₁.rightHomologyIso.inv ≫ rightHomologyMap φ = homologyMap φ ≫ S₂.rightHomologyIso.inv := by simpa only [RightHomologyData.homologyIso_rightHomologyData, Iso.symm_inv] using RightHomologyData.rightHomologyIso_hom_naturality φ S₁.rightHomologyData S₂.rightHomologyData end variable (C) /-- We shall say that a category `C` is a category with homology when all short complexes have homology. -/ class _root_.CategoryTheory.CategoryWithHomology : Prop where hasHomology : ∀ (S : ShortComplex C), S.HasHomology attribute [instance] CategoryWithHomology.hasHomology instance [CategoryWithHomology C] : CategoryWithHomology Cᵒᵖ := ⟨fun S => HasHomology.mk' S.unop.homologyData.op⟩ /-- The homology functor `ShortComplex C ⥤ C` for a category `C` with homology. -/ @[simps] noncomputable def homologyFunctor [CategoryWithHomology C] : ShortComplex C ⥤ C where obj S := S.homology map f := homologyMap f variable {C} instance isIso_homologyMap'_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : IsIso (homologyMap' φ h₁ h₂) := by dsimp only [homologyMap'] infer_instance lemma isIso_homologyMap_of_epi_of_isIso_of_mono' (φ : S₁ ⟶ S₂) [S₁.HasHomology] [S₂.HasHomology] (h₁ : Epi φ.τ₁) (h₂ : IsIso φ.τ₂) (h₃ : Mono φ.τ₃) : IsIso (homologyMap φ) := by dsimp only [homologyMap] infer_instance instance isIso_homologyMap_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) [S₁.HasHomology] [S₂.HasHomology] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : IsIso (homologyMap φ) := isIso_homologyMap_of_epi_of_isIso_of_mono' φ inferInstance inferInstance inferInstance instance isIso_homologyFunctor_map_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) [CategoryWithHomology C] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : IsIso ((homologyFunctor C).map φ) := (inferInstance : IsIso (homologyMap φ)) instance isIso_homologyMap_of_isIso (φ : S₁ ⟶ S₂) [S₁.HasHomology] [S₂.HasHomology] [IsIso φ] : IsIso (homologyMap φ) := by dsimp only [homologyMap, homologyMap'] infer_instance section variable (S) {A : C} variable [HasHomology S] /-- The canonical morphism `S.cycles ⟶ S.homology` for a short complex `S` that has homology. -/ noncomputable def homologyπ : S.cycles ⟶ S.homology := S.leftHomologyπ ≫ S.leftHomologyIso.hom /-- The canonical morphism `S.homology ⟶ S.opcycles` for a short complex `S` that has homology. -/ noncomputable def homologyι : S.homology ⟶ S.opcycles := S.rightHomologyIso.inv ≫ S.rightHomologyι @[reassoc (attr := simp)] lemma homologyπ_comp_leftHomologyIso_inv : S.homologyπ ≫ S.leftHomologyIso.inv = S.leftHomologyπ := by dsimp only [homologyπ] simp only [assoc, Iso.hom_inv_id, comp_id] @[reassoc (attr := simp)] lemma rightHomologyIso_hom_comp_homologyι : S.rightHomologyIso.hom ≫ S.homologyι = S.rightHomologyι := by dsimp only [homologyι] simp only [Iso.hom_inv_id_assoc] @[reassoc (attr := simp)] lemma toCycles_comp_homologyπ : S.toCycles ≫ S.homologyπ = 0 := by dsimp only [homologyπ] simp only [toCycles_comp_leftHomologyπ_assoc, zero_comp] @[reassoc (attr := simp)] lemma homologyι_comp_fromOpcycles : S.homologyι ≫ S.fromOpcycles = 0 := by dsimp only [homologyι] simp only [assoc, rightHomologyι_comp_fromOpcycles, comp_zero] /-- The homology `S.homology` of a short complex is the cokernel of the morphism `S.toCycles : S.X₁ ⟶ S.cycles`. -/ noncomputable def homologyIsCokernel : IsColimit (CokernelCofork.ofπ S.homologyπ S.toCycles_comp_homologyπ) := IsColimit.ofIsoColimit S.leftHomologyIsCokernel (Cofork.ext S.leftHomologyIso rfl) /-- The homology `S.homology` of a short complex is the kernel of the morphism `S.fromOpcycles : S.opcycles ⟶ S.X₃`. -/ noncomputable def homologyIsKernel : IsLimit (KernelFork.ofι S.homologyι S.homologyι_comp_fromOpcycles) := IsLimit.ofIsoLimit S.rightHomologyIsKernel (Fork.ext S.rightHomologyIso (by simp)) instance : Epi S.homologyπ := Limits.epi_of_isColimit_cofork (S.homologyIsCokernel) instance : Mono S.homologyι := Limits.mono_of_isLimit_fork (S.homologyIsKernel) /-- Given a morphism `k : S.cycles ⟶ A` such that `S.toCycles ≫ k = 0`, this is the induced morphism `S.homology ⟶ A`. -/ noncomputable def descHomology (k : S.cycles ⟶ A) (hk : S.toCycles ≫ k = 0) : S.homology ⟶ A := S.homologyIsCokernel.desc (CokernelCofork.ofπ k hk) /-- Given a morphism `k : A ⟶ S.opcycles` such that `k ≫ S.fromOpcycles = 0`, this is the induced morphism `A ⟶ S.homology`. -/ noncomputable def liftHomology (k : A ⟶ S.opcycles) (hk : k ≫ S.fromOpcycles = 0) : A ⟶ S.homology := S.homologyIsKernel.lift (KernelFork.ofι k hk) @[reassoc (attr := simp)] lemma π_descHomology (k : S.cycles ⟶ A) (hk : S.toCycles ≫ k = 0) : S.homologyπ ≫ S.descHomology k hk = k := Cofork.IsColimit.π_desc S.homologyIsCokernel @[reassoc (attr := simp)] lemma liftHomology_ι (k : A ⟶ S.opcycles) (hk : k ≫ S.fromOpcycles = 0) : S.liftHomology k hk ≫ S.homologyι = k := Fork.IsLimit.lift_ι S.homologyIsKernel @[reassoc (attr := simp)] lemma homologyπ_naturality (φ : S₁ ⟶ S₂) [S₁.HasHomology] [S₂.HasHomology] : S₁.homologyπ ≫ homologyMap φ = cyclesMap φ ≫ S₂.homologyπ := by simp only [← cancel_mono S₂.leftHomologyIso.inv, assoc, ← leftHomologyIso_inv_naturality φ, homologyπ_comp_leftHomologyIso_inv] simp only [homologyπ, assoc, Iso.hom_inv_id_assoc, leftHomologyπ_naturality] @[reassoc (attr := simp)] lemma homologyι_naturality (φ : S₁ ⟶ S₂) [S₁.HasHomology] [S₂.HasHomology] : homologyMap φ ≫ S₂.homologyι = S₁.homologyι ≫ S₁.opcyclesMap φ := by simp only [← cancel_epi S₁.rightHomologyIso.hom, rightHomologyIso_hom_naturality_assoc φ, rightHomologyIso_hom_comp_homologyι, rightHomologyι_naturality] simp only [homologyι, assoc, Iso.hom_inv_id_assoc] @[reassoc (attr := simp)] lemma homology_π_ι : S.homologyπ ≫ S.homologyι = S.iCycles ≫ S.pOpcycles := by dsimp only [homologyπ, homologyι] simpa only [assoc, S.leftRightHomologyComparison_fac] using S.π_leftRightHomologyComparison_ι /-- The homology of a short complex `S` identifies to the kernel of the induced morphism `cokernel S.f ⟶ S.X₃`. -/ noncomputable def homologyIsoKernelDesc [HasCokernel S.f] [HasKernel (cokernel.desc S.f S.g S.zero)] : S.homology ≅ kernel (cokernel.desc S.f S.g S.zero) := S.rightHomologyIso.symm ≪≫ S.rightHomologyIsoKernelDesc /-- The homology of a short complex `S` identifies to the cokernel of the induced morphism `S.X₁ ⟶ kernel S.g`. -/ noncomputable def homologyIsoCokernelLift [HasKernel S.g] [HasCokernel (kernel.lift S.g S.f S.zero)] : S.homology ≅ cokernel (kernel.lift S.g S.f S.zero) := S.leftHomologyIso.symm ≪≫ S.leftHomologyIsoCokernelLift @[reassoc (attr := simp)] lemma LeftHomologyData.homologyπ_comp_homologyIso_hom (h : S.LeftHomologyData) : S.homologyπ ≫ h.homologyIso.hom = h.cyclesIso.hom ≫ h.π := by dsimp only [homologyπ, homologyIso] simp only [Iso.trans_hom, Iso.symm_hom, assoc, Iso.hom_inv_id_assoc, leftHomologyπ_comp_leftHomologyIso_hom] @[reassoc (attr := simp)] lemma LeftHomologyData.π_comp_homologyIso_inv (h : S.LeftHomologyData) : h.π ≫ h.homologyIso.inv = h.cyclesIso.inv ≫ S.homologyπ := by dsimp only [homologyπ, homologyIso] simp only [Iso.trans_inv, Iso.symm_inv, π_comp_leftHomologyIso_inv_assoc] @[reassoc (attr := simp)] lemma RightHomologyData.homologyIso_inv_comp_homologyι (h : S.RightHomologyData) : h.homologyIso.inv ≫ S.homologyι = h.ι ≫ h.opcyclesIso.inv := by dsimp only [homologyι, homologyIso] simp only [Iso.trans_inv, Iso.symm_inv, assoc, Iso.hom_inv_id_assoc, rightHomologyIso_inv_comp_rightHomologyι] @[reassoc (attr := simp)] lemma RightHomologyData.homologyIso_hom_comp_ι (h : S.RightHomologyData) : h.homologyIso.hom ≫ h.ι = S.homologyι ≫ h.opcyclesIso.hom := by dsimp only [homologyι, homologyIso] simp only [Iso.trans_hom, Iso.symm_hom, assoc, rightHomologyIso_hom_comp_ι] @[reassoc (attr := simp)] lemma LeftHomologyData.homologyIso_hom_comp_leftHomologyIso_inv (h : S.LeftHomologyData) : h.homologyIso.hom ≫ h.leftHomologyIso.inv = S.leftHomologyIso.inv := by dsimp only [homologyIso] simp only [Iso.trans_hom, Iso.symm_hom, assoc, Iso.hom_inv_id, comp_id] @[reassoc (attr := simp)] lemma LeftHomologyData.leftHomologyIso_hom_comp_homologyIso_inv (h : S.LeftHomologyData) : h.leftHomologyIso.hom ≫ h.homologyIso.inv = S.leftHomologyIso.hom := by dsimp only [homologyIso] simp only [Iso.trans_inv, Iso.symm_inv, Iso.hom_inv_id_assoc] @[reassoc (attr := simp)] lemma RightHomologyData.homologyIso_hom_comp_rightHomologyIso_inv (h : S.RightHomologyData) : h.homologyIso.hom ≫ h.rightHomologyIso.inv = S.rightHomologyIso.inv := by dsimp only [homologyIso] simp only [Iso.trans_hom, Iso.symm_hom, assoc, Iso.hom_inv_id, comp_id] @[reassoc (attr := simp)] lemma RightHomologyData.rightHomologyIso_hom_comp_homologyIso_inv (h : S.RightHomologyData) : h.rightHomologyIso.hom ≫ h.homologyIso.inv = S.rightHomologyIso.hom := by dsimp only [homologyIso] simp only [Iso.trans_inv, Iso.symm_inv, Iso.hom_inv_id_assoc] @[reassoc] lemma comp_homologyMap_comp [S₁.HasHomology] [S₂.HasHomology] (φ : S₁ ⟶ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.RightHomologyData) : h₁.π ≫ h₁.homologyIso.inv ≫ homologyMap φ ≫ h₂.homologyIso.hom ≫ h₂.ι = h₁.i ≫ φ.τ₂ ≫ h₂.p := by dsimp only [LeftHomologyData.homologyIso, RightHomologyData.homologyIso, Iso.symm, Iso.trans, Iso.refl, leftHomologyIso, rightHomologyIso, leftHomologyMapIso', rightHomologyMapIso', LeftHomologyData.cyclesIso, RightHomologyData.opcyclesIso, LeftHomologyData.leftHomologyIso, RightHomologyData.rightHomologyIso, homologyMap, homologyMap'] simp only [assoc, rightHomologyι_naturality', rightHomologyι_naturality'_assoc, leftHomologyπ_naturality'_assoc, HomologyData.comm_assoc, p_opcyclesMap'_assoc, id_τ₂, p_opcyclesMap', id_comp, cyclesMap'_i_assoc] @[reassoc] lemma π_homologyMap_ι [S₁.HasHomology] [S₂.HasHomology] (φ : S₁ ⟶ S₂) : S₁.homologyπ ≫ homologyMap φ ≫ S₂.homologyι = S₁.iCycles ≫ φ.τ₂ ≫ S₂.pOpcycles := by simp only [homologyι_naturality, homology_π_ι_assoc, p_opcyclesMap] end variable (S) /-- The canonical isomorphism `S.op.homology ≅ Opposite.op S.homology` when a short complex `S` has homology. -/ noncomputable def homologyOpIso [S.HasHomology] : S.op.homology ≅ Opposite.op S.homology := S.op.leftHomologyIso.symm ≪≫ S.leftHomologyOpIso ≪≫ S.rightHomologyIso.symm.op lemma homologyMap'_op : (homologyMap' φ h₁ h₂).op = h₂.iso.inv.op ≫ homologyMap' (opMap φ) h₂.op h₁.op ≫ h₁.iso.hom.op := Quiver.Hom.unop_inj (by dsimp have γ : HomologyMapData φ h₁ h₂ := default simp only [γ.homologyMap'_eq, γ.op.homologyMap'_eq, HomologyData.op_left, HomologyMapData.op_left, RightHomologyMapData.op_φH, Quiver.Hom.unop_op, assoc, ← γ.comm_assoc, Iso.hom_inv_id, comp_id]) lemma homologyMap_op [HasHomology S₁] [HasHomology S₂] : (homologyMap φ).op = (S₂.homologyOpIso).inv ≫ homologyMap (opMap φ) ≫ (S₁.homologyOpIso).hom := by dsimp only [homologyMap, homologyOpIso] rw [homologyMap'_op] dsimp only [Iso.symm, Iso.trans, Iso.op, Iso.refl, rightHomologyIso, leftHomologyIso, leftHomologyOpIso, leftHomologyMapIso', rightHomologyMapIso', LeftHomologyData.leftHomologyIso, homologyMap'] simp only [assoc, rightHomologyMap'_op, op_comp, ← leftHomologyMap'_comp_assoc, id_comp, opMap_id, comp_id, HomologyData.op_left] @[reassoc] lemma homologyOpIso_hom_naturality [S₁.HasHomology] [S₂.HasHomology] : homologyMap (opMap φ) ≫ (S₁.homologyOpIso).hom = S₂.homologyOpIso.hom ≫ (homologyMap φ).op := by simp [homologyMap_op] @[reassoc] lemma homologyOpIso_inv_naturality [S₁.HasHomology] [S₂.HasHomology] : (homologyMap φ).op ≫ (S₁.homologyOpIso).inv = S₂.homologyOpIso.inv ≫ homologyMap (opMap φ) := by simp [homologyMap_op] variable (C) /-- The natural isomorphism `(homologyFunctor C).op ≅ opFunctor C ⋙ homologyFunctor Cᵒᵖ` which relates the homology in `C` and in `Cᵒᵖ`. -/ noncomputable def homologyFunctorOpNatIso [CategoryWithHomology C] : (homologyFunctor C).op ≅ opFunctor C ⋙ homologyFunctor Cᵒᵖ := NatIso.ofComponents (fun S => S.unop.homologyOpIso.symm) (fun _ ↦ homologyOpIso_inv_naturality _) variable {C} {A : C} lemma liftCycles_homologyπ_eq_zero_of_boundary [S.HasHomology] (k : A ⟶ S.X₂) (x : A ⟶ S.X₁) (hx : k = x ≫ S.f) : S.liftCycles k (by rw [hx, assoc, S.zero, comp_zero]) ≫ S.homologyπ = 0 := by dsimp only [homologyπ] rw [S.liftCycles_leftHomologyπ_eq_zero_of_boundary_assoc k x hx, zero_comp] @[reassoc] lemma homologyι_descOpcycles_eq_zero_of_boundary [S.HasHomology] (k : S.X₂ ⟶ A) (x : S.X₃ ⟶ A) (hx : k = S.g ≫ x) : S.homologyι ≫ S.descOpcycles k (by rw [hx, S.zero_assoc, zero_comp]) = 0 := by dsimp only [homologyι] rw [assoc, S.rightHomologyι_descOpcycles_π_eq_zero_of_boundary k x hx, comp_zero] lemma isIso_homologyMap_of_isIso_cyclesMap_of_epi {φ : S₁ ⟶ S₂} [S₁.HasHomology] [S₂.HasHomology] (h₁ : IsIso (cyclesMap φ)) (h₂ : Epi φ.τ₁) : IsIso (homologyMap φ) := by have h : S₂.toCycles ≫ inv (cyclesMap φ) ≫ S₁.homologyπ = 0 := by simp only [← cancel_epi φ.τ₁, ← toCycles_naturality_assoc, IsIso.hom_inv_id_assoc, toCycles_comp_homologyπ, comp_zero] have ⟨z, hz⟩ := CokernelCofork.IsColimit.desc' S₂.homologyIsCokernel _ h dsimp at hz refine ⟨⟨z, ?_, ?_⟩⟩ · rw [← cancel_epi S₁.homologyπ, homologyπ_naturality_assoc, hz, IsIso.hom_inv_id_assoc, comp_id] · rw [← cancel_epi S₂.homologyπ, reassoc_of% hz, homologyπ_naturality, IsIso.inv_hom_id_assoc, comp_id] lemma isIso_homologyMap_of_isIso_opcyclesMap_of_mono {φ : S₁ ⟶ S₂} [S₁.HasHomology] [S₂.HasHomology] (h₁ : IsIso (opcyclesMap φ)) (h₂ : Mono φ.τ₃) : IsIso (homologyMap φ) := by have h : (S₂.homologyι ≫ inv (opcyclesMap φ)) ≫ S₁.fromOpcycles = 0 := by simp only [← cancel_mono φ.τ₃, zero_comp, assoc, ← fromOpcycles_naturality, IsIso.inv_hom_id_assoc, homologyι_comp_fromOpcycles] have ⟨z, hz⟩ := KernelFork.IsLimit.lift' S₁.homologyIsKernel _ h dsimp at hz refine ⟨⟨z, ?_, ?_⟩⟩ · rw [← cancel_mono S₁.homologyι, id_comp, assoc, hz, homologyι_naturality_assoc, IsIso.hom_inv_id, comp_id] · rw [← cancel_mono S₂.homologyι, assoc, homologyι_naturality, reassoc_of% hz, IsIso.inv_hom_id, comp_id, id_comp] lemma isZero_homology_of_isZero_X₂ (hS : IsZero S.X₂) [S.HasHomology] : IsZero S.homology := IsZero.of_iso hS (HomologyData.ofZeros S (hS.eq_of_tgt _ _) (hS.eq_of_src _ _)).left.homologyIso lemma isIso_homologyπ (hf : S.f = 0) [S.HasHomology] : IsIso S.homologyπ := by have := S.isIso_leftHomologyπ hf dsimp only [homologyπ] infer_instance lemma isIso_homologyι (hg : S.g = 0) [S.HasHomology] : IsIso S.homologyι := by have := S.isIso_rightHomologyι hg dsimp only [homologyι] infer_instance /-- The canonical isomorphism `S.cycles ≅ S.homology` when `S.f = 0`. -/ @[simps! hom] noncomputable def asIsoHomologyπ (hf : S.f = 0) [S.HasHomology] : S.cycles ≅ S.homology := by have := S.isIso_homologyπ hf exact asIso S.homologyπ @[reassoc (attr := simp)] lemma asIsoHomologyπ_inv_comp_homologyπ (hf : S.f = 0) [S.HasHomology] : (S.asIsoHomologyπ hf).inv ≫ S.homologyπ = 𝟙 _ := Iso.inv_hom_id _ @[reassoc (attr := simp)] lemma homologyπ_comp_asIsoHomologyπ_inv (hf : S.f = 0) [S.HasHomology] : S.homologyπ ≫ (S.asIsoHomologyπ hf).inv = 𝟙 _ := (S.asIsoHomologyπ hf).hom_inv_id /-- The canonical isomorphism `S.homology ≅ S.opcycles` when `S.g = 0`. -/ @[simps! hom] noncomputable def asIsoHomologyι (hg : S.g = 0) [S.HasHomology] : S.homology ≅ S.opcycles := by have := S.isIso_homologyι hg exact asIso S.homologyι @[reassoc (attr := simp)] lemma asIsoHomologyι_inv_comp_homologyι (hg : S.g = 0) [S.HasHomology] : (S.asIsoHomologyι hg).inv ≫ S.homologyι = 𝟙 _ := Iso.inv_hom_id _ @[reassoc (attr := simp)] lemma homologyι_comp_asIsoHomologyι_inv (hg : S.g = 0) [S.HasHomology] : S.homologyι ≫ (S.asIsoHomologyι hg).inv = 𝟙 _ := (S.asIsoHomologyι hg).hom_inv_id lemma mono_homologyMap_of_mono_opcyclesMap' [S₁.HasHomology] [S₂.HasHomology] (h : Mono (opcyclesMap φ)) : Mono (homologyMap φ) := by have : Mono (homologyMap φ ≫ S₂.homologyι) := by rw [homologyι_naturality φ] apply mono_comp exact mono_of_mono (homologyMap φ) S₂.homologyι instance mono_homologyMap_of_mono_opcyclesMap [S₁.HasHomology] [S₂.HasHomology] [Mono (opcyclesMap φ)] : Mono (homologyMap φ) := mono_homologyMap_of_mono_opcyclesMap' φ inferInstance lemma epi_homologyMap_of_epi_cyclesMap' [S₁.HasHomology] [S₂.HasHomology] (h : Epi (cyclesMap φ)) : Epi (homologyMap φ) := by have : Epi (S₁.homologyπ ≫ homologyMap φ) := by rw [homologyπ_naturality φ] apply epi_comp exact epi_of_epi S₁.homologyπ (homologyMap φ) instance epi_homologyMap_of_epi_cyclesMap [S₁.HasHomology] [S₂.HasHomology] [Epi (cyclesMap φ)] : Epi (homologyMap φ) := epi_homologyMap_of_epi_cyclesMap' φ inferInstance /-- Given a short complex `S` such that `S.HasHomology`, this is the canonical left homology data for `S` whose `K` and `H` fields are respectively `S.cycles` and `S.homology`. -/ @[simps!] noncomputable def LeftHomologyData.canonical [S.HasHomology] : S.LeftHomologyData where K := S.cycles H := S.homology i := S.iCycles π := S.homologyπ wi := by simp hi := S.cyclesIsKernel wπ := S.toCycles_comp_homologyπ hπ := S.homologyIsCokernel /-- Computation of the `f'` field of `LeftHomologyData.canonical`. -/ @[simp] lemma LeftHomologyData.canonical_f' [S.HasHomology] : (LeftHomologyData.canonical S).f' = S.toCycles := rfl /-- Given a short complex `S` such that `S.HasHomology`, this is the canonical right homology data for `S` whose `Q` and `H` fields are respectively `S.opcycles` and `S.homology`. -/ @[simps!] noncomputable def RightHomologyData.canonical [S.HasHomology] : S.RightHomologyData where Q := S.opcycles H := S.homology p := S.pOpcycles ι := S.homologyι wp := by simp hp := S.opcyclesIsCokernel wι := S.homologyι_comp_fromOpcycles hι := S.homologyIsKernel /-- Computation of the `g'` field of `RightHomologyData.canonical`. -/ @[simp] lemma RightHomologyData.canonical_g' [S.HasHomology] : (RightHomologyData.canonical S).g' = S.fromOpcycles := rfl /-- Given a short complex `S` such that `S.HasHomology`, this is the canonical homology data for `S` whose `left.K`, `left/right.H` and `right.Q` fields are respectively `S.cycles`, `S.homology` and `S.opcycles`. -/ @[simps!] noncomputable def HomologyData.canonical [S.HasHomology] : S.HomologyData where left := LeftHomologyData.canonical S right := RightHomologyData.canonical S iso := Iso.refl _ end ShortComplex end CategoryTheory
Nilpotent.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.RingTheory.Finiteness.Basic import Mathlib.RingTheory.Nilpotent.Lemmas /-! # Nilpotent maps on finite modules -/ variable {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] theorem Module.End.isNilpotent_iff_of_finite [Module.Finite R M] {f : End R M} : IsNilpotent f ↔ ∀ m : M, ∃ n : ℕ, (f ^ n) m = 0 := by refine ⟨fun ⟨n, hn⟩ m ↦ ⟨n, by simp [hn]⟩, fun h ↦ ?_⟩ rcases Module.Finite.fg_top (R := R) (M := M) with ⟨S, hS⟩ choose g hg using h use Finset.sup S g ext m have hm : m ∈ Submodule.span R S := by simp [hS] induction hm using Submodule.span_induction with | mem x hx => exact pow_map_zero_of_le (Finset.le_sup hx) (hg x) | zero => simp | add => simp_all | smul => simp_all namespace Matrix open scoped Matrix variable {ι : Type*} [DecidableEq ι] [Fintype ι] {A : Matrix ι ι R} @[simp] theorem isNilpotent_transpose_iff : IsNilpotent Aᵀ ↔ IsNilpotent A := by simp_rw [IsNilpotent, ← transpose_pow, transpose_eq_zero] theorem isNilpotent_iff : IsNilpotent A ↔ ∀ v, ∃ n : ℕ, A ^ n *ᵥ v = 0 := by simp_rw [← isNilpotent_toLin'_iff, Module.End.isNilpotent_iff_of_finite, ← toLin'_pow, toLin'_apply] theorem isNilpotent_iff_forall_row : IsNilpotent A ↔ ∀ i, ∃ n : ℕ, (A ^ n).row i = 0 := by rw [← isNilpotent_transpose_iff, isNilpotent_iff] refine ⟨fun h i ↦ ?_, fun h v ↦ ?_⟩ · obtain ⟨n, hn⟩ := h (Pi.single i 1) exact ⟨n, by simpa [← transpose_pow] using hn⟩ · choose n hn using h suffices ∀ i, (A ^ ⨆ j, n j) i = 0 from ⟨⨆ j, n j, by simp [mulVec_eq_sum, this]⟩ exact fun i ↦ pow_row_eq_zero_of_le (hn i) (Finite.le_ciSup n i) theorem isNilpotent_iff_forall_col : IsNilpotent A ↔ ∀ i, ∃ n : ℕ, (A ^ n).col i = 0 := by rw [← isNilpotent_transpose_iff, isNilpotent_iff_forall_row] simp_rw [← transpose_pow, row_transpose] end Matrix
Basic.lean
/- Copyright (c) 2025 Nailin Guan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nailin Guan -/ import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Order.Ring.Int import Mathlib.Algebra.GradedMonoid import Mathlib.Algebra.Group.Submonoid.Defs import Mathlib.Algebra.GradedMulAction /-! # The filtration on abelian groups and rings In this file, we define the concept of filtration for abelian groups, rings, and modules. # Main definitions * `IsFiltration` : For a family of subsets `σ` of `A`, an increasing series of `F` in `σ` is a filtration if there is another series `F_lt` in `σ` equal to the supremum of `F` with smaller index. * `IsRingFiltration` : For a family of subsets `σ` of semiring `R`, an increasing series `F` in `σ` is a ring filtration if `IsFiltration F F_lt` and the pointwise multiplication of `F i` and `F j` is in `F (i + j)`. * `IsModuleFiltration` : For `F` satisfying `IsRingFiltration F F_lt` in a semiring `R` and `σM` a family of subsets of a `R` module `M`, an increasing series `FM` in `σM` is a module filtration if `IsFiltration F F_lt` and the pointwise scalar multiplication of `F i` and `FM j` is in `F (i +ᵥ j)`. -/ section GeneralFiltration variable {ι A σ : Type*} [Preorder ι] [SetLike σ A] /-- For a family of subsets `σ` of `A`, an increasing series of `F` in `σ` is a filtration if there is another series `F_lt` in `σ` equal to the supremum of `F` with smaller index. In the intended applications, `σ` is a complete lattice, and `F_lt` is uniquely-determined as `F_lt j = ⨆ i < j, F i`. Thus `F_lt` is an implementation detail which allows us defer depending on a complete lattice structure on `σ`. It also provides the ancillary benefit of giving us better definition control. This is convenient e.g., when the index is `ℤ`. -/ class IsFiltration (F : ι → σ) (F_lt : outParam <| ι → σ) : Prop where mono : Monotone F is_le {i j} : i < j → F i ≤ F_lt j is_sup (B : σ) (j : ι) : (∀ i < j, F i ≤ B) → F_lt j ≤ B lemma IsFiltration.F_lt_le_F (F : ι → σ) (F_lt : outParam <| ι → σ) (i : ι) [IsFiltration F F_lt] : F_lt i ≤ F i := is_sup (F i) i (fun _ hi ↦ IsFiltration.mono (le_of_lt hi)) /-- A convenience constructor for `IsFiltration` when the index is the integers. -/ lemma IsFiltration.mk_int (F : ℤ → σ) (mono : Monotone F) : IsFiltration F (fun n ↦ F (n - 1)) where mono := mono is_le lt := mono (Int.le_sub_one_of_lt lt) is_sup _ j hi := hi (j - 1) (sub_one_lt j) end GeneralFiltration section FilteredRing variable {ι R σ : Type*} [AddMonoid ι] [PartialOrder ι] [Semiring R] [SetLike σ R] /-- For a family of subsets `σ` of semiring `R`, an increasing series `F` in `σ` is a ring filtration if `IsFiltration F F_lt` and the pointwise multiplication of `F i` and `F j` is in `F (i + j)`. -/ class IsRingFiltration (F : ι → σ) (F_lt : outParam <| ι → σ) : Prop extends IsFiltration F F_lt, SetLike.GradedMonoid F /-- A convenience constructor for `IsRingFiltration` when the index is the integers. -/ lemma IsRingFiltration.mk_int (F : ℤ → σ) (mono : Monotone F) [SetLike.GradedMonoid F] : IsRingFiltration F (fun n ↦ F (n - 1)) where __ := IsFiltration.mk_int F mono end FilteredRing section FilteredModule variable {ι ιM R M σ σM : Type*} [AddMonoid ι] [PartialOrder ι] [PartialOrder ιM] [VAdd ι ιM] variable [Semiring R] [SetLike σ R] [AddCommMonoid M] [Module R M] [SetLike σM M] /-- For `F` satisfying `IsRingFiltration F F_lt` in a semiring `R` and `σM` a family of subsets of a `R` module `M`, an increasing series `FM` in `σM` is a module filtration if `IsFiltration F F_lt` and the pointwise scalar multiplication of `F i` and `FM j` is in `F (i +ᵥ j)`. The index set `ιM` for the module can be more general, however usually we take `ιM = ι`. -/ class IsModuleFiltration (F : ι → σ) (F_lt : outParam <| ι → σ) [IsRingFiltration F F_lt] (F' : ιM → σM) (F'_lt : outParam <| ιM → σM) : Prop extends IsFiltration F' F'_lt, SetLike.GradedSMul F F' /-- A convenience constructor for `IsModuleFiltration` when the index is the integers. -/ lemma IsModuleFiltration.mk_int (F : ℤ → σ) (mono : Monotone F) [SetLike.GradedMonoid F] (F' : ℤ → σM) (mono' : Monotone F') [SetLike.GradedSMul F F'] : letI := IsRingFiltration.mk_int F mono IsModuleFiltration F (fun n ↦ F (n - 1)) F' (fun n ↦ F' (n - 1)) := letI := IsRingFiltration.mk_int F mono { IsFiltration.mk_int F' mono' with } end FilteredModule
ShiftedLegendre.lean
/- Copyright (c) 2025 Junqi Liu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junqi Liu, Jinzhao Pan -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Derivative /-! # shifted Legendre Polynomials In this file, we define the shifted Legendre polynomials `shiftedLegendre n` for `n : ℕ` as a polynomial in `ℤ[X]`. We prove some basic properties of the Legendre polynomials. * `factorial_mul_shiftedLegendre_eq`: The analogue of Rodrigues' formula for the shifted Legendre polynomials; * `shiftedLegendre_eval_symm`: The values of the shifted Legendre polynomial at `x` and `1 - x` differ by a factor `(-1)ⁿ`. ## Reference * <https://en.wikipedia.org/wiki/Legendre_polynomials> ## Tags shifted Legendre polynomials, derivative -/ open Nat BigOperators Finset namespace Polynomial /-- `shiftedLegendre n` is an integer polynomial for each `n : ℕ`, defined by: `Pₙ(x) = ∑ k ∈ Finset.range (n + 1), (-1)ᵏ * choose n k * choose (n + k) n * xᵏ` These polynomials appear in combinatorics and the theory of orthogonal polynomials. -/ noncomputable def shiftedLegendre (n : ℕ) : ℤ[X] := ∑ k ∈ Finset.range (n + 1), C ((-1 : ℤ) ^ k * n.choose k * (n + k).choose n) * X ^ k /-- The shifted Legendre polynomial multiplied by a factorial equals the higher-order derivative of the combinatorial function `X ^ n * (1 - X) ^ n`. This is the analogue of Rodrigues' formula for the shifted Legendre polynomials. -/ theorem factorial_mul_shiftedLegendre_eq (n : ℕ) : (n ! : ℤ[X]) * (shiftedLegendre n) = derivative^[n] (X ^ n * (1 - (X : ℤ[X])) ^ n) := by symm calc _ = derivative^[n] (((X : ℤ[X]) - X ^ 2) ^ n) := by rw [← mul_pow, mul_one_sub, ← pow_two] _ = derivative^[n] (∑ m ∈ range (n + 1), n.choose m • (-1) ^ m * X ^ (n + m)) := by congr rw [sub_eq_add_neg, add_comm, add_pow] congr! 1 with m hm rw [neg_pow, pow_two, mul_pow, ← mul_assoc, mul_comm, mul_assoc, pow_mul_pow_sub, mul_assoc, ← pow_add, ← mul_assoc, nsmul_eq_mul, add_comm] rw [Finset.mem_range] at hm linarith _ = ∑ x ∈ range (n + 1), ↑((n + x)! / x !) * C (↑(n.choose x) * (-1) ^ x) * X ^ x := by rw [iterate_derivative_sum] congr! 1 with x _ rw [show (n.choose x • (-1) ^ x : ℤ[X]) = C (n.choose x • (-1) ^ x) by simp, iterate_derivative_C_mul, iterate_derivative_X_pow_eq_smul, descFactorial_eq_div (by omega), show n + x - n = x by omega] simp only [Int.reduceNeg, nsmul_eq_mul, eq_intCast, Int.cast_mul, Int.cast_natCast, Int.cast_pow, Int.cast_neg, Int.cast_one, zsmul_eq_mul] ring _ = ∑ i ∈ range (n + 1), ↑n ! * C ((-1) ^ i * ↑(n.choose i) * ↑((n + i).choose n)) * X ^ i := by congr! 2 with x _ rw [C_mul (b := ((n + x).choose n : ℤ)), mul_comm, mul_comm (n ! : ℤ[X]), mul_comm _ ((-1) ^ x), mul_assoc] congr 1 rw [add_comm, add_choose] simp only [Int.natCast_ediv, cast_mul, eq_intCast] norm_cast rw [mul_comm, ← Nat.mul_div_assoc] · rw [mul_comm, Nat.mul_div_mul_right _ _ (by positivity)] · simp only [factorial_mul_factorial_dvd_factorial_add] _ = (n ! : ℤ[X]) * (shiftedLegendre n) := by simp [← mul_assoc, shiftedLegendre, mul_sum] /-- The coefficient of the shifted Legendre polynomial at `k` is `(-1) ^ k * (n.choose k) * (n + k).choose n`. -/ theorem coeff_shiftedLegendre (n k : ℕ) : (shiftedLegendre n).coeff k = (-1) ^ k * n.choose k * (n + k).choose n := by rw [shiftedLegendre, finset_sum_coeff] simp_rw [coeff_C_mul_X_pow] simp +contextual [choose_eq_zero_of_lt, add_one_le_iff] /-- The degree of `shiftedLegendre n` is `n`. -/ @[simp] theorem degree_shiftedLegendre (n : ℕ) : (shiftedLegendre n).degree = n := by refine le_antisymm ?_ (le_degree_of_ne_zero ?_) · rw [degree_le_iff_coeff_zero] intro k h norm_cast at h simp [coeff_shiftedLegendre, choose_eq_zero_of_lt h] · simp [coeff_shiftedLegendre, (choose_pos (show n ≤ n + n by simp)).ne'] @[simp] theorem natDegree_shiftedLegendre (n : ℕ) : (shiftedLegendre n).natDegree = n := natDegree_eq_of_degree_eq_some (degree_shiftedLegendre n) theorem neg_one_pow_mul_shiftedLegendre_comp_one_sub_X_eq (n : ℕ) : (-1) ^ n * (shiftedLegendre n).comp (1 - X) = shiftedLegendre n := by refine nat_mul_inj' ?_ (factorial_ne_zero n) rw [← mul_assoc, mul_comm (n ! : ℤ[X]), mul_assoc, ← natCast_mul_comp, factorial_mul_shiftedLegendre_eq, ← iterate_derivative_comp_one_sub_X] simp [mul_comm] /-- The values ​​of the Legendre polynomial at `x` and `1 - x` differ by a factor `(-1)ⁿ`. -/ lemma shiftedLegendre_eval_symm (n : ℕ) {R : Type*} [Ring R] (x : R) : aeval x (shiftedLegendre n) = (-1) ^ n * aeval (1 - x) (shiftedLegendre n) := by have := congr(aeval x $(neg_one_pow_mul_shiftedLegendre_comp_one_sub_X_eq n)) simpa [aeval_comp] using this.symm end Polynomial
NormedSpace.lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Geometry.Manifold.ContMDiff.Constructions import Mathlib.Analysis.NormedSpace.OperatorNorm.Prod /-! ## Equivalence of smoothness with the basic definition for functions between vector spaces * `contMDiff_iff_contDiff`: for functions between vector spaces, manifold-smoothness is equivalent to usual smoothness. * `ContinuousLinearMap.contMDiff`: continuous linear maps between normed spaces are smooth * `smooth_smul`: multiplication by scalars is a smooth operation -/ open Set ChartedSpace open scoped Topology Manifold variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] -- declare a charted space `M` over the pair `(E, H)`. {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] -- declare normed spaces `E'`, `F`, `F'`, `F₁`, `F₂`, `F₃`, `F₄`. {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {F₁ : Type*} [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] {F₂ : Type*} [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] {F₃ : Type*} [NormedAddCommGroup F₃] [NormedSpace 𝕜 F₃] {F₄ : Type*} [NormedAddCommGroup F₄] [NormedSpace 𝕜 F₄] -- declare functions, sets, points and smoothness indices {s : Set M} {x : M} {n : WithTop ℕ∞} section Module theorem contMDiffWithinAt_iff_contDiffWithinAt {f : E → E'} {s : Set E} {x : E} : ContMDiffWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') n f s x ↔ ContDiffWithinAt 𝕜 n f s x := by simp +contextual only [ContMDiffWithinAt, liftPropWithinAt_iff', ContDiffWithinAtProp, iff_def, mfld_simps] exact ContDiffWithinAt.continuousWithinAt alias ⟨ContMDiffWithinAt.contDiffWithinAt, ContDiffWithinAt.contMDiffWithinAt⟩ := contMDiffWithinAt_iff_contDiffWithinAt theorem contMDiffAt_iff_contDiffAt {f : E → E'} {x : E} : ContMDiffAt 𝓘(𝕜, E) 𝓘(𝕜, E') n f x ↔ ContDiffAt 𝕜 n f x := by rw [← contMDiffWithinAt_univ, contMDiffWithinAt_iff_contDiffWithinAt, contDiffWithinAt_univ] alias ⟨ContMDiffAt.contDiffAt, ContDiffAt.contMDiffAt⟩ := contMDiffAt_iff_contDiffAt theorem contMDiffOn_iff_contDiffOn {f : E → E'} {s : Set E} : ContMDiffOn 𝓘(𝕜, E) 𝓘(𝕜, E') n f s ↔ ContDiffOn 𝕜 n f s := forall_congr' <| by simp [contMDiffWithinAt_iff_contDiffWithinAt] alias ⟨ContMDiffOn.contDiffOn, ContDiffOn.contMDiffOn⟩ := contMDiffOn_iff_contDiffOn theorem contMDiff_iff_contDiff {f : E → E'} : ContMDiff 𝓘(𝕜, E) 𝓘(𝕜, E') n f ↔ ContDiff 𝕜 n f := by rw [← contDiffOn_univ, ← contMDiffOn_univ, contMDiffOn_iff_contDiffOn] alias ⟨ContMDiff.contDiff, ContDiff.contMDiff⟩ := contMDiff_iff_contDiff theorem ContDiffWithinAt.comp_contMDiffWithinAt {g : F → F'} {f : M → F} {s : Set M} {t : Set F} {x : M} (hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContMDiffWithinAt I 𝓘(𝕜, F) n f s x) (h : s ⊆ f ⁻¹' t) : ContMDiffWithinAt I 𝓘(𝕜, F') n (g ∘ f) s x := hg.contMDiffWithinAt.comp x hf h theorem ContDiffAt.comp_contMDiffWithinAt {g : F → F'} {f : M → F} {s : Set M} {x : M} (hg : ContDiffAt 𝕜 n g (f x)) (hf : ContMDiffWithinAt I 𝓘(𝕜, F) n f s x) : ContMDiffWithinAt I 𝓘(𝕜, F') n (g ∘ f) s x := hg.contMDiffAt.comp_contMDiffWithinAt x hf theorem ContDiffAt.comp_contMDiffAt {g : F → F'} {f : M → F} {x : M} (hg : ContDiffAt 𝕜 n g (f x)) (hf : ContMDiffAt I 𝓘(𝕜, F) n f x) : ContMDiffAt I 𝓘(𝕜, F') n (g ∘ f) x := hg.comp_contMDiffWithinAt hf theorem ContDiff.comp_contMDiffWithinAt {g : F → F'} {f : M → F} {s : Set M} {x : M} (hg : ContDiff 𝕜 n g) (hf : ContMDiffWithinAt I 𝓘(𝕜, F) n f s x) : ContMDiffWithinAt I 𝓘(𝕜, F') n (g ∘ f) s x := hg.contDiffAt.comp_contMDiffWithinAt hf theorem ContDiff.comp_contMDiffAt {g : F → F'} {f : M → F} {x : M} (hg : ContDiff 𝕜 n g) (hf : ContMDiffAt I 𝓘(𝕜, F) n f x) : ContMDiffAt I 𝓘(𝕜, F') n (g ∘ f) x := hg.comp_contMDiffWithinAt hf theorem ContDiff.comp_contMDiff {g : F → F'} {f : M → F} (hg : ContDiff 𝕜 n g) (hf : ContMDiff I 𝓘(𝕜, F) n f) : ContMDiff I 𝓘(𝕜, F') n (g ∘ f) := fun x => hg.contDiffAt.comp_contMDiffAt (hf x) end Module /-! ### Linear maps between normed spaces are smooth -/ theorem ContinuousLinearMap.contMDiff (L : E →L[𝕜] F) : ContMDiff 𝓘(𝕜, E) 𝓘(𝕜, F) n L := L.contDiff.contMDiff theorem ContinuousLinearMap.contMDiffAt (L : E →L[𝕜] F) {x} : ContMDiffAt 𝓘(𝕜, E) 𝓘(𝕜, F) n L x := L.contMDiff _ theorem ContinuousLinearMap.contMDiffWithinAt (L : E →L[𝕜] F) {s x} : ContMDiffWithinAt 𝓘(𝕜, E) 𝓘(𝕜, F) n L s x := L.contMDiffAt.contMDiffWithinAt theorem ContinuousLinearMap.contMDiffOn (L : E →L[𝕜] F) {s} : ContMDiffOn 𝓘(𝕜, E) 𝓘(𝕜, F) n L s := L.contMDiff.contMDiffOn theorem ContMDiffWithinAt.clm_precomp {f : M → F₁ →L[𝕜] F₂} {s : Set M} {x : M} (hf : ContMDiffWithinAt I 𝓘(𝕜, F₁ →L[𝕜] F₂) n f s x) : ContMDiffWithinAt I 𝓘(𝕜, (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) n (fun y ↦ (f y).precomp F₃ : M → (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) s x := ContDiff.comp_contMDiffWithinAt (g := (ContinuousLinearMap.compL 𝕜 F₁ F₂ F₃).flip) (ContinuousLinearMap.contDiff _) hf nonrec theorem ContMDiffAt.clm_precomp {f : M → F₁ →L[𝕜] F₂} {x : M} (hf : ContMDiffAt I 𝓘(𝕜, F₁ →L[𝕜] F₂) n f x) : ContMDiffAt I 𝓘(𝕜, (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) n (fun y ↦ (f y).precomp F₃ : M → (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) x := hf.clm_precomp theorem ContMDiffOn.clm_precomp {f : M → F₁ →L[𝕜] F₂} {s : Set M} (hf : ContMDiffOn I 𝓘(𝕜, F₁ →L[𝕜] F₂) n f s) : ContMDiffOn I 𝓘(𝕜, (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) n (fun y ↦ (f y).precomp F₃ : M → (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) s := fun x hx ↦ (hf x hx).clm_precomp theorem ContMDiff.clm_precomp {f : M → F₁ →L[𝕜] F₂} (hf : ContMDiff I 𝓘(𝕜, F₁ →L[𝕜] F₂) n f) : ContMDiff I 𝓘(𝕜, (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) n (fun y ↦ (f y).precomp F₃ : M → (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) := fun x ↦ (hf x).clm_precomp theorem ContMDiffWithinAt.clm_postcomp {f : M → F₂ →L[𝕜] F₃} {s : Set M} {x : M} (hf : ContMDiffWithinAt I 𝓘(𝕜, F₂ →L[𝕜] F₃) n f s x) : ContMDiffWithinAt I 𝓘(𝕜, (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) n (fun y ↦ (f y).postcomp F₁ : M → (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) s x := ContDiff.comp_contMDiffWithinAt (F' := (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) (g := ContinuousLinearMap.compL 𝕜 F₁ F₂ F₃) (ContinuousLinearMap.contDiff _) hf nonrec theorem ContMDiffAt.clm_postcomp {f : M → F₂ →L[𝕜] F₃} {x : M} (hf : ContMDiffAt I 𝓘(𝕜, F₂ →L[𝕜] F₃) n f x) : ContMDiffAt I 𝓘(𝕜, (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) n (fun y ↦ (f y).postcomp F₁ : M → (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) x := hf.clm_postcomp nonrec theorem ContMDiffOn.clm_postcomp {f : M → F₂ →L[𝕜] F₃} {s : Set M} (hf : ContMDiffOn I 𝓘(𝕜, F₂ →L[𝕜] F₃) n f s) : ContMDiffOn I 𝓘(𝕜, (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) n (fun y ↦ (f y).postcomp F₁ : M → (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) s := fun x hx ↦ (hf x hx).clm_postcomp theorem ContMDiff.clm_postcomp {f : M → F₂ →L[𝕜] F₃} (hf : ContMDiff I 𝓘(𝕜, F₂ →L[𝕜] F₃) n f) : ContMDiff I 𝓘(𝕜, (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) n (fun y ↦ (f y).postcomp F₁ : M → (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) := fun x ↦ (hf x).clm_postcomp theorem ContMDiffWithinAt.clm_comp {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₁} {s : Set M} {x : M} (hg : ContMDiffWithinAt I 𝓘(𝕜, F₁ →L[𝕜] F₃) n g s x) (hf : ContMDiffWithinAt I 𝓘(𝕜, F₂ →L[𝕜] F₁) n f s x) : ContMDiffWithinAt I 𝓘(𝕜, F₂ →L[𝕜] F₃) n (fun x => (g x).comp (f x)) s x := ContDiff.comp_contMDiffWithinAt (g := fun x : (F₁ →L[𝕜] F₃) × (F₂ →L[𝕜] F₁) => x.1.comp x.2) (f := fun x => (g x, f x)) (contDiff_fst.clm_comp contDiff_snd) (hg.prodMk_space hf) theorem ContMDiffAt.clm_comp {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₁} {x : M} (hg : ContMDiffAt I 𝓘(𝕜, F₁ →L[𝕜] F₃) n g x) (hf : ContMDiffAt I 𝓘(𝕜, F₂ →L[𝕜] F₁) n f x) : ContMDiffAt I 𝓘(𝕜, F₂ →L[𝕜] F₃) n (fun x => (g x).comp (f x)) x := (hg.contMDiffWithinAt.clm_comp hf.contMDiffWithinAt).contMDiffAt Filter.univ_mem theorem ContMDiffOn.clm_comp {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₁} {s : Set M} (hg : ContMDiffOn I 𝓘(𝕜, F₁ →L[𝕜] F₃) n g s) (hf : ContMDiffOn I 𝓘(𝕜, F₂ →L[𝕜] F₁) n f s) : ContMDiffOn I 𝓘(𝕜, F₂ →L[𝕜] F₃) n (fun x => (g x).comp (f x)) s := fun x hx => (hg x hx).clm_comp (hf x hx) theorem ContMDiff.clm_comp {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₁} (hg : ContMDiff I 𝓘(𝕜, F₁ →L[𝕜] F₃) n g) (hf : ContMDiff I 𝓘(𝕜, F₂ →L[𝕜] F₁) n f) : ContMDiff I 𝓘(𝕜, F₂ →L[𝕜] F₃) n fun x => (g x).comp (f x) := fun x => (hg x).clm_comp (hf x) /-- Applying a linear map to a vector is smooth within a set. Version in vector spaces. For versions in nontrivial vector bundles, see `ContMDiffWithinAt.clm_apply_of_inCoordinates` and `ContMDiffWithinAt.clm_bundle_apply`. -/ theorem ContMDiffWithinAt.clm_apply {g : M → F₁ →L[𝕜] F₂} {f : M → F₁} {s : Set M} {x : M} (hg : ContMDiffWithinAt I 𝓘(𝕜, F₁ →L[𝕜] F₂) n g s x) (hf : ContMDiffWithinAt I 𝓘(𝕜, F₁) n f s x) : ContMDiffWithinAt I 𝓘(𝕜, F₂) n (fun x => g x (f x)) s x := ContDiffWithinAt.comp_contMDiffWithinAt (t := univ) (g := fun x : (F₁ →L[𝕜] F₂) × F₁ => x.1 x.2) (by apply ContDiff.contDiffAt; exact contDiff_fst.clm_apply contDiff_snd) (hg.prodMk_space hf) (by simp_rw [preimage_univ, subset_univ]) /-- Applying a linear map to a vector is smooth. Version in vector spaces. For versions in nontrivial vector bundles, see `ContMDiffAt.clm_apply_of_inCoordinates` and `ContMDiffAt.clm_bundle_apply`. -/ nonrec theorem ContMDiffAt.clm_apply {g : M → F₁ →L[𝕜] F₂} {f : M → F₁} {x : M} (hg : ContMDiffAt I 𝓘(𝕜, F₁ →L[𝕜] F₂) n g x) (hf : ContMDiffAt I 𝓘(𝕜, F₁) n f x) : ContMDiffAt I 𝓘(𝕜, F₂) n (fun x => g x (f x)) x := hg.clm_apply hf theorem ContMDiffOn.clm_apply {g : M → F₁ →L[𝕜] F₂} {f : M → F₁} {s : Set M} (hg : ContMDiffOn I 𝓘(𝕜, F₁ →L[𝕜] F₂) n g s) (hf : ContMDiffOn I 𝓘(𝕜, F₁) n f s) : ContMDiffOn I 𝓘(𝕜, F₂) n (fun x => g x (f x)) s := fun x hx => (hg x hx).clm_apply (hf x hx) theorem ContMDiff.clm_apply {g : M → F₁ →L[𝕜] F₂} {f : M → F₁} (hg : ContMDiff I 𝓘(𝕜, F₁ →L[𝕜] F₂) n g) (hf : ContMDiff I 𝓘(𝕜, F₁) n f) : ContMDiff I 𝓘(𝕜, F₂) n fun x => g x (f x) := fun x => (hg x).clm_apply (hf x) theorem ContMDiffWithinAt.cle_arrowCongr {f : M → F₁ ≃L[𝕜] F₂} {g : M → F₃ ≃L[𝕜] F₄} {s : Set M} {x : M} (hf : ContMDiffWithinAt I 𝓘(𝕜, F₂ →L[𝕜] F₁) n (fun x ↦ ((f x).symm : F₂ →L[𝕜] F₁)) s x) (hg : ContMDiffWithinAt I 𝓘(𝕜, F₃ →L[𝕜] F₄) n (fun x ↦ (g x : F₃ →L[𝕜] F₄)) s x) : ContMDiffWithinAt I 𝓘(𝕜, (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) n (fun y ↦ (f y).arrowCongr (g y) : M → (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) s x := show ContMDiffWithinAt I 𝓘(𝕜, (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) n (fun y ↦ (((f y).symm : F₂ →L[𝕜] F₁).precomp F₄).comp ((g y : F₃ →L[𝕜] F₄).postcomp F₁)) s x from hf.clm_precomp (F₃ := F₄) |>.clm_comp <| hg.clm_postcomp (F₁ := F₁) nonrec theorem ContMDiffAt.cle_arrowCongr {f : M → F₁ ≃L[𝕜] F₂} {g : M → F₃ ≃L[𝕜] F₄} {x : M} (hf : ContMDiffAt I 𝓘(𝕜, F₂ →L[𝕜] F₁) n (fun x ↦ ((f x).symm : F₂ →L[𝕜] F₁)) x) (hg : ContMDiffAt I 𝓘(𝕜, F₃ →L[𝕜] F₄) n (fun x ↦ (g x : F₃ →L[𝕜] F₄)) x) : ContMDiffAt I 𝓘(𝕜, (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) n (fun y ↦ (f y).arrowCongr (g y) : M → (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) x := hf.cle_arrowCongr hg theorem ContMDiffOn.cle_arrowCongr {f : M → F₁ ≃L[𝕜] F₂} {g : M → F₃ ≃L[𝕜] F₄} {s : Set M} (hf : ContMDiffOn I 𝓘(𝕜, F₂ →L[𝕜] F₁) n (fun x ↦ ((f x).symm : F₂ →L[𝕜] F₁)) s) (hg : ContMDiffOn I 𝓘(𝕜, F₃ →L[𝕜] F₄) n (fun x ↦ (g x : F₃ →L[𝕜] F₄)) s) : ContMDiffOn I 𝓘(𝕜, (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) n (fun y ↦ (f y).arrowCongr (g y) : M → (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) s := fun x hx ↦ (hf x hx).cle_arrowCongr (hg x hx) theorem ContMDiff.cle_arrowCongr {f : M → F₁ ≃L[𝕜] F₂} {g : M → F₃ ≃L[𝕜] F₄} (hf : ContMDiff I 𝓘(𝕜, F₂ →L[𝕜] F₁) n (fun x ↦ ((f x).symm : F₂ →L[𝕜] F₁))) (hg : ContMDiff I 𝓘(𝕜, F₃ →L[𝕜] F₄) n (fun x ↦ (g x : F₃ →L[𝕜] F₄))) : ContMDiff I 𝓘(𝕜, (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) n (fun y ↦ (f y).arrowCongr (g y) : M → (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) := fun x ↦ (hf x).cle_arrowCongr (hg x) theorem ContMDiffWithinAt.clm_prodMap {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₄} {s : Set M} {x : M} (hg : ContMDiffWithinAt I 𝓘(𝕜, F₁ →L[𝕜] F₃) n g s x) (hf : ContMDiffWithinAt I 𝓘(𝕜, F₂ →L[𝕜] F₄) n f s x) : ContMDiffWithinAt I 𝓘(𝕜, F₁ × F₂ →L[𝕜] F₃ × F₄) n (fun x => (g x).prodMap (f x)) s x := ContDiff.comp_contMDiffWithinAt (g := fun x : (F₁ →L[𝕜] F₃) × (F₂ →L[𝕜] F₄) => x.1.prodMap x.2) (f := fun x => (g x, f x)) (ContinuousLinearMap.prodMapL 𝕜 F₁ F₃ F₂ F₄).contDiff (hg.prodMk_space hf) nonrec theorem ContMDiffAt.clm_prodMap {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₄} {x : M} (hg : ContMDiffAt I 𝓘(𝕜, F₁ →L[𝕜] F₃) n g x) (hf : ContMDiffAt I 𝓘(𝕜, F₂ →L[𝕜] F₄) n f x) : ContMDiffAt I 𝓘(𝕜, F₁ × F₂ →L[𝕜] F₃ × F₄) n (fun x => (g x).prodMap (f x)) x := hg.clm_prodMap hf theorem ContMDiffOn.clm_prodMap {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₄} {s : Set M} (hg : ContMDiffOn I 𝓘(𝕜, F₁ →L[𝕜] F₃) n g s) (hf : ContMDiffOn I 𝓘(𝕜, F₂ →L[𝕜] F₄) n f s) : ContMDiffOn I 𝓘(𝕜, F₁ × F₂ →L[𝕜] F₃ × F₄) n (fun x => (g x).prodMap (f x)) s := fun x hx => (hg x hx).clm_prodMap (hf x hx) theorem ContMDiff.clm_prodMap {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₄} (hg : ContMDiff I 𝓘(𝕜, F₁ →L[𝕜] F₃) n g) (hf : ContMDiff I 𝓘(𝕜, F₂ →L[𝕜] F₄) n f) : ContMDiff I 𝓘(𝕜, F₁ × F₂ →L[𝕜] F₃ × F₄) n fun x => (g x).prodMap (f x) := fun x => (hg x).clm_prodMap (hf x) /-! ### Smoothness of scalar multiplication -/ variable {V : Type*} [NormedAddCommGroup V] [NormedSpace 𝕜 V] /-- On any vector space, multiplication by a scalar is a smooth operation. -/ theorem contMDiff_smul : ContMDiff (𝓘(𝕜).prod 𝓘(𝕜, V)) 𝓘(𝕜, V) ⊤ fun p : 𝕜 × V => p.1 • p.2 := contMDiff_iff.2 ⟨continuous_smul, fun _ _ => contDiff_smul.contDiffOn⟩ theorem ContMDiffWithinAt.smul {f : M → 𝕜} {g : M → V} (hf : ContMDiffWithinAt I 𝓘(𝕜) n f s x) (hg : ContMDiffWithinAt I 𝓘(𝕜, V) n g s x) : ContMDiffWithinAt I 𝓘(𝕜, V) n (fun p => f p • g p) s x := (contMDiff_smul.of_le le_top).contMDiffAt.comp_contMDiffWithinAt x (hf.prodMk hg) nonrec theorem ContMDiffAt.smul {f : M → 𝕜} {g : M → V} (hf : ContMDiffAt I 𝓘(𝕜) n f x) (hg : ContMDiffAt I 𝓘(𝕜, V) n g x) : ContMDiffAt I 𝓘(𝕜, V) n (fun p => f p • g p) x := hf.smul hg theorem ContMDiffOn.smul {f : M → 𝕜} {g : M → V} (hf : ContMDiffOn I 𝓘(𝕜) n f s) (hg : ContMDiffOn I 𝓘(𝕜, V) n g s) : ContMDiffOn I 𝓘(𝕜, V) n (fun p => f p • g p) s := fun x hx => (hf x hx).smul (hg x hx) theorem ContMDiff.smul {f : M → 𝕜} {g : M → V} (hf : ContMDiff I 𝓘(𝕜) n f) (hg : ContMDiff I 𝓘(𝕜, V) n g) : ContMDiff I 𝓘(𝕜, V) n fun p => f p • g p := fun x => (hf x).smul (hg x)
Extend.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Embedding.IsSupported import Mathlib.Algebra.Homology.Additive import Mathlib.Algebra.Homology.Opposite /-! # The extension of a homological complex by an embedding of complex shapes Given an embedding `e : Embedding c c'` of complex shapes, and `K : HomologicalComplex C c`, we define `K.extend e : HomologicalComplex C c'`, and this leads to a functor `e.extendFunctor C : HomologicalComplex C c ⥤ HomologicalComplex C c'`. This construction first appeared in the Liquid Tensor Experiment. -/ open CategoryTheory Category Limits ZeroObject variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'} namespace HomologicalComplex variable {C : Type*} [Category C] [HasZeroObject C] section variable [HasZeroMorphisms C] (K L M : HomologicalComplex C c) (φ : K ⟶ L) (φ' : L ⟶ M) (e : c.Embedding c') namespace extend /-- Auxiliary definition for the `X` field of `HomologicalComplex.extend`. -/ noncomputable def X : Option ι → C | some x => K.X x | none => 0 /-- The isomorphism `X K i ≅ K.X j` when `i = some j`. -/ noncomputable def XIso {i : Option ι} {j : ι} (hj : i = some j) : X K i ≅ K.X j := eqToIso (by subst hj; rfl) lemma isZero_X {i : Option ι} (hi : i = none) : IsZero (X K i) := by subst hi exact Limits.isZero_zero _ /-- The canonical isomorphism `X K.op i ≅ Opposite.op (X K i)`. -/ noncomputable def XOpIso (i : Option ι) : X K.op i ≅ Opposite.op (X K i) := match i with | some _ => Iso.refl _ | none => IsZero.iso (isZero_X _ rfl) (isZero_X K rfl).op /-- Auxiliary definition for the `d` field of `HomologicalComplex.extend`. -/ noncomputable def d : ∀ (i j : Option ι), extend.X K i ⟶ extend.X K j | none, _ => 0 | some i, some j => K.d i j | some _, none => 0 lemma d_none_eq_zero (i j : Option ι) (hi : i = none) : d K i j = 0 := by subst hi; rfl lemma d_none_eq_zero' (i j : Option ι) (hj : j = none) : d K i j = 0 := by subst hj; cases i <;> rfl lemma d_eq {i j : Option ι} {a b : ι} (hi : i = some a) (hj : j = some b) : d K i j = (XIso K hi).hom ≫ K.d a b ≫ (XIso K hj).inv := by subst hi hj simp [XIso, X, d] @[reassoc] lemma XOpIso_hom_d_op (i j : Option ι) : (XOpIso K i).hom ≫ (d K j i).op = d K.op i j ≫ (XOpIso K j).hom := match i, j with | none, _ => by simp only [d_none_eq_zero, d_none_eq_zero', comp_zero, zero_comp, op_zero] | some i, some j => by dsimp [XOpIso] simp only [d_eq _ rfl rfl, op_comp, assoc, id_comp, comp_id] rfl | some _, none => by simp only [d_none_eq_zero, d_none_eq_zero', comp_zero, zero_comp, op_zero] variable {K L} /-- Auxiliary definition for `HomologicalComplex.extendMap`. -/ noncomputable def mapX : ∀ (i : Option ι), X K i ⟶ X L i | some i => φ.f i | none => 0 lemma mapX_some {i : Option ι} {a : ι} (hi : i = some a) : mapX φ i = (XIso K hi).hom ≫ φ.f a ≫ (XIso L hi).inv := by subst hi dsimp [XIso, X] rw [id_comp, comp_id] rfl lemma mapX_none {i : Option ι} (hi : i = none) : mapX φ i = 0 := by subst hi; rfl end extend /-- Given `K : HomologicalComplex C c` and `e : c.Embedding c'`, this is the extension of `K` in `HomologicalComplex C c'`: it is zero in the degrees that are not in the image of `e.f`. -/ noncomputable def extend : HomologicalComplex C c' where X i' := extend.X K (e.r i') d i' j' := extend.d K (e.r i') (e.r j') shape i' j' h := by obtain hi'|⟨i, hi⟩ := (e.r i').eq_none_or_eq_some · rw [extend.d_none_eq_zero K _ _ hi'] · obtain hj'|⟨j, hj⟩ := (e.r j').eq_none_or_eq_some · rw [extend.d_none_eq_zero' K _ _ hj'] · rw [extend.d_eq K hi hj,K.shape, zero_comp, comp_zero] obtain rfl := e.f_eq_of_r_eq_some hi obtain rfl := e.f_eq_of_r_eq_some hj intro hij exact h (e.rel hij) d_comp_d' i' j' k' _ _ := by obtain hi'|⟨i, hi⟩ := (e.r i').eq_none_or_eq_some · rw [extend.d_none_eq_zero K _ _ hi', zero_comp] · obtain hj'|⟨j, hj⟩ := (e.r j').eq_none_or_eq_some · rw [extend.d_none_eq_zero K _ _ hj', comp_zero] · obtain hk'|⟨k, hk⟩ := (e.r k').eq_none_or_eq_some · rw [extend.d_none_eq_zero' K _ _ hk', comp_zero] · rw [extend.d_eq K hi hj, extend.d_eq K hj hk, assoc, assoc, Iso.inv_hom_id_assoc, K.d_comp_d_assoc, zero_comp, comp_zero] /-- The isomorphism `(K.extend e).X i' ≅ K.X i` when `e.f i = i'`. -/ noncomputable def extendXIso {i' : ι'} {i : ι} (h : e.f i = i') : (K.extend e).X i' ≅ K.X i := extend.XIso K (e.r_eq_some h) lemma isZero_extend_X' (i' : ι') (hi' : e.r i' = none) : IsZero ((K.extend e).X i') := extend.isZero_X K hi' lemma isZero_extend_X (i' : ι') (hi' : ∀ i, e.f i ≠ i') : IsZero ((K.extend e).X i') := K.isZero_extend_X' e i' (by obtain hi'|⟨i, hi⟩ := (e.r i').eq_none_or_eq_some · exact hi' · exfalso exact hi' _ (e.f_eq_of_r_eq_some hi)) instance : (K.extend e).IsStrictlySupported e where isZero i' hi' := K.isZero_extend_X e i' hi' lemma extend_d_eq {i' j' : ι'} {i j : ι} (hi : e.f i = i') (hj : e.f j = j') : (K.extend e).d i' j' = (K.extendXIso e hi).hom ≫ K.d i j ≫ (K.extendXIso e hj).inv := by apply extend.d_eq lemma extend_d_from_eq_zero (i' j' : ι') (i : ι) (hi : e.f i = i') (hi' : ¬ c.Rel i (c.next i)) : (K.extend e).d i' j' = 0 := by obtain hj'|⟨j, hj⟩ := (e.r j').eq_none_or_eq_some · exact extend.d_none_eq_zero' _ _ _ hj' · rw [extend_d_eq K e hi (e.f_eq_of_r_eq_some hj), K.shape, zero_comp, comp_zero] intro hij obtain rfl := c.next_eq' hij exact hi' hij lemma extend_d_to_eq_zero (i' j' : ι') (j : ι) (hj : e.f j = j') (hj' : ¬ c.Rel (c.prev j) j) : (K.extend e).d i' j' = 0 := by obtain hi'|⟨i, hi⟩ := (e.r i').eq_none_or_eq_some · exact extend.d_none_eq_zero _ _ _ hi' · rw [extend_d_eq K e (e.f_eq_of_r_eq_some hi) hj, K.shape, zero_comp, comp_zero] intro hij obtain rfl := c.prev_eq' hij exact hj' hij variable {K L M} /-- Given an embedding `e : c.Embedding c'` of complexes shapes, this is the morphism `K.extend e ⟶ L.extend e` induced by a morphism `K ⟶ L` in `HomologicalComplex C c`. -/ noncomputable def extendMap : K.extend e ⟶ L.extend e where f _ := extend.mapX φ _ comm' i' j' _ := by by_cases hi : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi by_cases hj : ∃ j, e.f j = j' · obtain ⟨j, hj⟩ := hj rw [K.extend_d_eq e hi hj, L.extend_d_eq e hi hj, extend.mapX_some φ (e.r_eq_some hi), extend.mapX_some φ (e.r_eq_some hj)] simp only [extendXIso, assoc, Iso.inv_hom_id_assoc, Hom.comm_assoc] · have hj' := e.r_eq_none j' (fun j'' hj'' => hj ⟨j'', hj''⟩) dsimp [extend] rw [extend.d_none_eq_zero' _ _ _ hj', extend.d_none_eq_zero' _ _ _ hj', comp_zero, zero_comp] · have hi' := e.r_eq_none i' (fun i'' hi'' => hi ⟨i'', hi''⟩) dsimp [extend] rw [extend.d_none_eq_zero _ _ _ hi', extend.d_none_eq_zero _ _ _ hi', comp_zero, zero_comp] lemma extendMap_f {i : ι} {i' : ι'} (h : e.f i = i') : (extendMap φ e).f i' = (extendXIso K e h).hom ≫ φ.f i ≫ (extendXIso L e h).inv := by dsimp [extendMap] rw [extend.mapX_some φ (e.r_eq_some h)] rfl lemma extendMap_f_eq_zero (i' : ι') (hi' : ∀ i, e.f i ≠ i') : (extendMap φ e).f i' = 0 := by dsimp [extendMap] rw [extend.mapX_none φ (e.r_eq_none i' hi')] @[reassoc, simp] lemma extendMap_comp : extendMap (φ ≫ φ') e = extendMap φ e ≫ extendMap φ' e := by ext i' by_cases hi' : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi' simp [extendMap_f _ e hi] · simp [extendMap_f_eq_zero _ e i' (fun i hi => hi' ⟨i, hi⟩)] variable (K L M) lemma extendMap_id_f (i' : ι') : (extendMap (𝟙 K) e).f i' = 𝟙 _ := by by_cases hi' : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi' simp [extendMap_f _ e hi] · apply (K.isZero_extend_X e i' (fun i hi => hi' ⟨i, hi⟩)).eq_of_src @[simp] lemma extendMap_id : extendMap (𝟙 K) e = 𝟙 _ := by ext i' by_cases hi' : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi' simp [extendMap_f _ e hi] · apply (K.isZero_extend_X e i' (fun i hi => hi' ⟨i, hi⟩)).eq_of_src @[simp] lemma extendMap_zero : extendMap (0 : K ⟶ L) e = 0 := by ext i' by_cases hi' : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi' simp [extendMap_f _ e hi] · apply (K.isZero_extend_X e i' (fun i hi => hi' ⟨i, hi⟩)).eq_of_src /-- The canonical isomorphism `K.op.extend e.op ≅ (K.extend e).op`. -/ noncomputable def extendOpIso : K.op.extend e.op ≅ (K.extend e).op := Hom.isoOfComponents (fun _ ↦ extend.XOpIso _ _) (fun _ _ _ ↦ extend.XOpIso_hom_d_op _ _ _) @[reassoc] lemma extend_op_d (i' j' : ι') : (K.op.extend e.op).d i' j' = (K.extendOpIso e).hom.f i' ≫ ((K.extend e).d j' i').op ≫ (K.extendOpIso e).inv.f j' := by have := (K.extendOpIso e).inv.comm i' j' dsimp at this rw [← this, ← comp_f_assoc, Iso.hom_inv_id, id_f, id_comp] end @[simp] lemma extendMap_add [Preadditive C] {K L : HomologicalComplex C c} (φ φ' : K ⟶ L) (e : c.Embedding c') : extendMap (φ + φ' : K ⟶ L) e = extendMap φ e + extendMap φ' e := by ext i' by_cases hi' : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi' simp [extendMap_f _ e hi] · apply (K.isZero_extend_X e i' (fun i hi => hi' ⟨i, hi⟩)).eq_of_src end HomologicalComplex namespace ComplexShape.Embedding variable (e : Embedding c c') (C : Type*) [Category C] [HasZeroObject C] /-- Given an embedding `e : c.Embedding c'` of complex shapes, this is the functor `HomologicalComplex C c ⥤ HomologicalComplex C c'` which extend complexes along `e`: the extended complexes are zero in the degrees that are not in the image of `e.f`. -/ @[simps] noncomputable def extendFunctor [HasZeroMorphisms C] : HomologicalComplex C c ⥤ HomologicalComplex C c' where obj K := K.extend e map φ := HomologicalComplex.extendMap φ e instance [HasZeroMorphisms C] : (e.extendFunctor C).PreservesZeroMorphisms where instance [Preadditive C] : (e.extendFunctor C).Additive where end ComplexShape.Embedding
extremal.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 ssrbool ssrfun eqtype ssrnat seq div. From mathcomp Require Import choice fintype bigop finset prime binomial. From mathcomp Require Import fingroup morphism perm automorphism presentation. From mathcomp Require Import quotient action commutator gproduct gfunctor. From mathcomp Require Import ssralg countalg finalg zmodp cyclic pgroup center gseries. From mathcomp Require Import nilpotent sylow abelian finmodule matrix maximal. (******************************************************************************) (* This file contains the definition and properties of extremal p-groups; *) (* it covers and is mostly based on the beginning of Aschbacher, section 23, *) (* as well as several exercises of this section. *) (* We define canonical representatives for the group classes that cover the *) (* extremal p-groups (non-abelian p-groups with a cyclic maximal subgroup): *) (* 'Mod_m == the modular group of order m, for m = p ^ n, p prime and n >= 3. *) (* 'D_m == the dihedral group of order m, for m = 2n >= 4. *) (* 'Q_m == the generalized quaternion group of order m, for m = 2 ^ n >= 8. *) (* 'SD_m == the semi-dihedral group of order m, for m = 2 ^ n >= 16. *) (* In each case the notation is defined in the %type, %g and %G scopes, where *) (* it denotes a finGroupType, a full gset and the full group for that type. *) (* However each notation is only meaningful under the given conditions, in *) (* 'D_m is only an extremal group for m = 2 ^ n >= 8, and 'D_8 = 'Mod_8 (they *) (* are, in fact, beta-convertible). *) (* We also define *) (* extremal_generators G p n (x, y) <-> G has order p ^ n, x in G has order *) (* p ^ n.-1, and y is in G \ <[x]>: thus <[x]> has index p in G, *) (* so if p is prime, <[x]> is maximal in G, G is generated by x *) (* and y, and G is extremal or abelian. *) (* extremal_class G == the class of extremal groups G belongs to: one of *) (* ModularGroup, Dihedral, Quaternion, SemiDihedral or NotExtremal. *) (* extremal2 G <=> extremal_class G is one of Dihedral, Quaternion, or *) (* SemiDihedral; this allows 'D_4 and 'D_8, but excludes 'Mod_(2^n) *) (* for n > 3. *) (* modular_group_generators p n (x, y) <-> y has order p and acts on x via *) (* x ^ y = x ^+ (p ^ n.-2).+1. This is the complement to *) (* extremal_generators G p n (x, y) for modular groups. *) (* We provide cardinality, presentation, generator and structure theorems for *) (* each class of extremal group. The extremal_generators predicate is used to *) (* supply structure theorems with all the required data about G; this is *) (* completed by an isomorphism assumption (e.g., G \isog 'D_(2 ^ n)), and *) (* sometimes other properties (e.g., #[y] == 2 in the semidihedral case). The *) (* generators assumption can be deduced generically from the isomorphism *) (* assumption, or it can be proved manually for a specific choice of x and y. *) (* The extremal_class function is used to formulate synthetic theorems that *) (* cover several classes of extremal groups (e.g., Aschbacher ex. 8.3). *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Notation "n %:R" := (n %:R%R). Import GroupScope GRing.Theory. Reserved Notation "''Mod_' m" (at level 0, m at level 2, format "''Mod_' m"). Reserved Notation "''D_' m" (at level 0, m at level 2, format "''D_' m"). Reserved Notation "''SD_' m" (at level 0, m at level 2, format "''SD_' m"). Reserved Notation "''Q_' m" (at level 0, m at level 2, format "''Q_' m"). Module Extremal. Section Construction. Variables q p e : nat. (* Construct the semi-direct product of 'Z_q by 'Z_p with 1%R ^ 1%R = e%R, *) (* if possible, i.e., if p, q > 1 and there is s \in Aut 'Z_p such that *) (* #[s] %| p and s 1%R = 1%R ^+ e. *) Let a : 'Z_p := Zp1. Let b : 'Z_q := Zp1. Local Notation B := <[b]>. Definition aut_of := odflt 1 [pick s in Aut B | p > 1 & (#[s] %| p) && (s b == b ^+ e)]. Lemma aut_dvdn : #[aut_of] %| #[a]. Proof. rewrite order_Zp1 /aut_of; case: pickP => [s | _]; last by rewrite order1. by case/and4P=> _ p_gt1 p_s _; rewrite Zp_cast. Qed. Definition act_morphism := eltm_morphism aut_dvdn. Definition base_act := ([Aut B] \o act_morphism)%gact. Lemma act_dom : <[a]> \subset act_dom base_act. Proof. rewrite cycle_subG 2!inE cycle_id /= eltm_id /aut_of. by case: pickP => [op /andP[] | _] //=; rewrite group1. Qed. Definition gact := (base_act \ act_dom)%gact. End Construction. HB.lock Definition gtype q p e : finGroupType := sdprod_by (gact q p e). Canonical gtype_unlockable := Unlockable gtype.unlock. Section ConstructionCont. Variables q p e : nat. Let a : 'Z_p := Zp1. Let b : 'Z_q := Zp1. Local Notation B := <[b]>. Local Notation gtype := (gtype q p e) (only parsing). Local Notation gact := (gact q p e) (only parsing). Local Notation aut_of := (aut_of q p e) (only parsing). Hypotheses (p_gt1 : p > 1) (q_gt1 : q > 1). Lemma card : #|[set: gtype]| = (p * q)%N. Proof. rewrite [gtype.body]unlock -(sdprod_card (sdprod_sdpair _)). rewrite !card_injm ?injm_sdpair1 ?injm_sdpair2 //. by rewrite mulnC -!orderE !order_Zp1 !Zp_cast. Qed. Lemma Grp : (exists s, [/\ s \in Aut B, #[s] %| p & s b = b ^+ e]) -> [set: gtype] \isog Grp (x : y : x ^+ q, y ^+ p, x ^ y = x ^+ e). Proof. rewrite [gtype.body]unlock => [[s [AutBs dvd_s_p sb]]]. have memB: _ \in B by move=> c; rewrite -Zp_cycle inE. have Aa: a \in <[a]> by rewrite !cycle_id. have [oa ob]: #[a] = p /\ #[b] = q by rewrite !order_Zp1 !Zp_cast. have def_s: aut_of = s. rewrite /aut_of; case: pickP => /= [t | ]; last first. by move/(_ s); case/and4P; rewrite sb. case/and4P=> AutBt _ _ tb; apply: (eq_Aut AutBt) => // b_i. case/cycleP=> i ->; rewrite -(autmE AutBt) -(autmE AutBs) !morphX //=. by rewrite !autmE // sb (eqP tb). apply: intro_isoGrp => [|gT G]. apply/existsP; exists (sdpair1 _ b, sdpair2 _ a); rewrite /= !xpair_eqE. apply/andP; split. by rewrite -!morphim_cycle ?norm_joinEr ?im_sdpair ?im_sdpair_norm ?eqxx //=. rewrite -!order_dvdn !order_injm ?injm_sdpair1 ?injm_sdpair2 // oa ob !dvdnn. by rewrite -sdpair_act // [act _ _ _]apermE /= eltm_id -morphX // -sb -def_s. case/existsP=> -[x y] /= /eqP[defG xq1 yp1 xy]. have fxP: #[x] %| #[b] by rewrite order_dvdn ob xq1. have fyP: #[y] %| #[a] by rewrite order_dvdn oa yp1. have fP: {in <[b]> & <[a]>, morph_act gact 'J (eltm fxP) (eltm fyP)}. move=> bj ai; case/cycleP=> j ->{bj}; case/cycleP=> i ->{ai}. rewrite /= !eltmE def_s gactX ?groupX // conjXg morphX //=; congr (_ ^+ j). rewrite /autact /= apermE; elim: i {j} => /= [|i IHi]. by rewrite perm1 eltm_id conjg1. rewrite !expgS permM sb -(autmE (groupX i AutBs)) !morphX //= {}IHi. by rewrite -conjXg -xy -conjgM. apply/homgP; exists (xsdprod_morphism fP). rewrite im_xsdprodm !morphim_cycle //= !eltm_id -norm_joinEr //. by rewrite norms_cycle xy mem_cycle. Qed. End ConstructionCont. End Extremal. Section SpecializeExtremals. Import Extremal. Variable m : nat. Let p := pdiv m. Let q := m %/ p. Definition modular_gtype := gtype q p (q %/ p).+1. Definition dihedral_gtype := gtype q 2 q.-1. Definition semidihedral_gtype := gtype q 2 (q %/ p).-1. Definition quaternion_kernel := <<[set u | u ^+ 2 == 1] :\: [set u ^+ 2 | u in [set: gtype q 4 q.-1]]>>. End SpecializeExtremals. HB.lock Definition quaternion_gtype n : finGroupType := coset_of (quaternion_kernel n). Canonical quaternion_unlock := Unlockable quaternion_gtype.unlock. Notation "''Mod_' m" := (modular_gtype m) : type_scope. Notation "''Mod_' m" := [set: gsort 'Mod_m] : group_scope. Notation "''Mod_' m" := [set: gsort 'Mod_m]%G : Group_scope. Notation "''D_' m" := (dihedral_gtype m) : type_scope. Notation "''D_' m" := [set: gsort 'D_m] : group_scope. Notation "''D_' m" := [set: gsort 'D_m]%G : Group_scope. Notation "''SD_' m" := (semidihedral_gtype m) : type_scope. Notation "''SD_' m" := [set: gsort 'SD_m] : group_scope. Notation "''SD_' m" := [set: gsort 'SD_m]%G : Group_scope. Notation "''Q_' m" := (quaternion_gtype m) : type_scope. Notation "''Q_' m" := [set: gsort 'Q_m] : group_scope. Notation "''Q_' m" := [set: gsort 'Q_m]%G : Group_scope. Section ExtremalTheory. Implicit Types (gT : finGroupType) (p q m n : nat). (* This is Aschbacher (23.3), with the isomorphism made explicit, and a *) (* slightly reworked case analysis on the prime and exponent; in particular *) (* the inverting involution is available for all non-trivial p-cycles. *) Lemma cyclic_pgroup_Aut_structure gT p (G : {group gT}) : p.-group G -> cyclic G -> G :!=: 1 -> let q := #|G| in let n := (logn p q).-1 in let A := Aut G in let P := 'O_p(A) in let F := 'O_p^'(A) in exists m : {perm gT} -> 'Z_q, [/\ [/\ {in A & G, forall a x, x ^+ m a = a x}, m 1 = 1%R /\ {in A &, {morph m : a b / a * b >-> (a * b)%R}}, {in A &, injective m} /\ image m A =i GRing.unit, forall k, {in A, {morph m : a / a ^+ k >-> (a ^+ k)%R}} & {in A, {morph m : a / a^-1 >-> (a^-1)%R}}], [/\ abelian A, cyclic F, #|F| = p.-1 & [faithful F, on 'Ohm_1(G) | [Aut G]]] & if n == 0 then A = F else exists t, [/\ t \in A, #[t] = 2, m t = (- 1)%R & if odd p then [/\ cyclic A /\ cyclic P, exists s, [/\ s \in A, #[s] = (p ^ n)%N, m s = p.+1%:R & P = <[s]>] & exists s0, [/\ s0 \in A, #[s0] = p, m s0 = (p ^ n).+1%:R & 'Ohm_1(P) = <[s0]>]] else if n == 1%N then A = <[t]> else exists s, [/\ s \in A, #[s] = (2 ^ n.-1)%N, m s = 5%:R, <[s]> \x <[t]> = A & exists s0, [/\ s0 \in A, #[s0] = 2, m s0 = (2 ^ n).+1%:R, m (s0 * t) = (2 ^ n).-1%:R & 'Ohm_1(<[s]>) = <[s0]>]]]]. Proof. move=> pG cycG ntG q n0 A P F; have [p_pr p_dvd_G [n oG]] := pgroup_pdiv pG ntG. have [x0 defG] := cyclicP cycG; have Gx0: x0 \in G by rewrite defG cycle_id. rewrite {1}/q oG pfactorK //= in n0 *; rewrite {}/n0. have [p_gt1 min_p] := primeP p_pr; have p_gt0 := ltnW p_gt1. have q_gt1: q > 1 by rewrite cardG_gt1. have cAA: abelian A := Aut_cyclic_abelian cycG; have nilA := abelian_nil cAA. have oA: #|A| = (p.-1 * p ^ n)%N. by rewrite card_Aut_cyclic // oG totient_pfactor. have [sylP hallF]: p.-Sylow(A) P /\ p^'.-Hall(A) F. by rewrite !nilpotent_pcore_Hall. have [defPF tiPF]: P * F = A /\ P :&: F = 1. by case/dprodP: (nilpotent_pcoreC p nilA). have oP: #|P| = (p ^ n)%N. by rewrite (card_Hall sylP) oA p_part logn_Gauss ?coprimenP ?pfactorK. have oF: #|F| = p.-1. apply/eqP; rewrite -(@eqn_pmul2l #|P|) ?cardG_gt0 // -TI_cardMg // defPF. by rewrite oA oP mulnC. have [m' [inj_m' defA def_m']]: exists m' : {morphism units_Zp q >-> {perm gT}}, [/\ 'injm m', m' @* setT = A & {in G, forall x u, m' u x = x ^+ val u}]. - rewrite /A /q defG; exists (Zp_unit_morphism x0). by have [->]:= isomP (Zp_unit_isom x0); split=> // y Gy u; rewrite permE Gy. pose m (a : {perm gT}) : 'Z_q := val (invm inj_m' a). have{def_m'} def_m: {in A & G, forall a x, x ^+ m a = a x}. by move=> a x Aa Gx /=; rewrite -{2}[a](invmK inj_m') ?defA ?def_m'. have m1: m 1 = 1%R by rewrite /m morph1. have mM: {in A &, {morph m : a b / a * b >-> (a * b)%R}}. by move=> a b Aa Ab; rewrite /m morphM ?defA. have mX k: {in A, {morph m : a / a ^+ k >-> (a ^+ k)%R}}. by elim: k => // k IHk a Aa; rewrite expgS exprS mM ?groupX ?IHk. have inj_m: {in A &, injective m}. apply: can_in_inj (fun u => m' (insubd (1 : {unit 'Z_q}) u)) _ => a Aa. by rewrite valKd invmK ?defA. have{defA} im_m: image m A =i GRing.unit. move=> u; apply/imageP/idP=> [[a Aa ->]| Uu]; first exact: valP. exists (m' (Sub u Uu)) => /=; first by rewrite -defA mem_morphim ?inE. by rewrite /m invmE ?inE. have mV: {in A, {morph m : a / a^-1 >-> (a^-1)%R}}. move=> a Aa /=; rewrite -div1r; apply: canRL (mulrK (valP _)) _. by rewrite -mM ?groupV ?mulVg. have inv_m (u : 'Z_q) : coprime q u -> {a | a \in A & m a = u}. rewrite -?unitZpE // natr_Zp -im_m => m_u. by exists (iinv m_u); [apply: mem_iinv | rewrite f_iinv]. have [cycF ffulF]: cyclic F /\ [faithful F, on 'Ohm_1(G) | [Aut G]]. have Um0 a: ((m a)%:R : 'F_p) \in GRing.unit. have: m a \in GRing.unit by apply: valP. by rewrite -{1}[m a]natr_Zp unitFpE ?unitZpE // {1}/q oG coprime_pexpl. pose fm0 a := FinRing.unit 'F_p (Um0 a). have natZqp u: (u%:R : 'Z_q)%:R = u %:R :> 'F_p. by rewrite val_Zp_nat // -Fp_nat_mod // modn_dvdm ?Fp_nat_mod. have m0M: {in A &, {morph fm0 : a b / a * b}}. by move=> a b Aa Ab; apply: val_inj; rewrite /= -natrM mM //= -val_Zp_nat. pose m0 : {morphism A >-> {unit 'F_p}} := Morphism m0M. have im_m0: m0 @* A = [set: {unit 'F_p}]. apply/setP=> [[/= u Uu]]; rewrite in_setT morphimEdom; apply/imsetP. have [|a Aa m_a] := inv_m u%:R. by rewrite {1}[q]oG coprime_pexpl // -unitFpE // natZqp natr_Zp. by exists a => //; apply: val_inj; rewrite /= m_a natZqp natr_Zp. have [x1 defG1]: exists x1, 'Ohm_1(G) = <[x1]>. by apply/cyclicP; apply: cyclicS (Ohm_sub _ _) cycG. have ox1: #[x1] = p by rewrite orderE -defG1 (Ohm1_cyclic_pgroup_prime _ pG). have Gx1: x1 \in G by rewrite -cycle_subG -defG1 Ohm_sub. have ker_m0: 'ker m0 = 'C('Ohm_1(G) | [Aut G]). apply/setP=> a; rewrite inE in_setI; apply: andb_id2l => Aa. rewrite 3!inE /= -2!val_eqE /= val_Fp_nat // [1 %% _]modn_small // defG1. apply/idP/subsetP=> [ma1 x1i | ma1]. case/cycleP=> i ->{x1i}; rewrite inE gactX // -[_ a]def_m //. by rewrite -(expg_mod_order x1) ox1 (eqP ma1). have:= ma1 x1 (cycle_id x1); rewrite inE -[_ a]def_m //. by rewrite (eq_expg_mod_order x1 _ 1) ox1 (modn_small p_gt1). have card_units_Fp: #|[set: {unit 'F_p}]| = p.-1. by rewrite card_units_Zp // pdiv_id // (@totient_pfactor p 1) ?muln1. have ker_m0_P: 'ker m0 = P. apply: nilpotent_Hall_pcore nilA _. rewrite pHallE -(card_Hall sylP) oP subsetIl /=. rewrite -(@eqn_pmul2r #|m0 @* A|) ?cardG_gt0 //; apply/eqP. rewrite -{1}(card_isog (first_isog _)) card_quotient ?ker_norm //. by rewrite Lagrange ?subsetIl // oA im_m0 mulnC card_units_Fp. have inj_m0: 'ker_F m0 \subset [1] by rewrite setIC ker_m0_P tiPF. split; last by rewrite /faithful -ker_m0. have isogF: F \isog [set: {unit 'F_p}]. have sFA: F \subset A by apply: pcore_sub. apply/isogP; exists (restrm_morphism sFA m0); first by rewrite ker_restrm. apply/eqP; rewrite eqEcard subsetT card_injm ?ker_restrm //= oF. by rewrite card_units_Fp. rewrite (isog_cyclic isogF) pdiv_id // -ox1 (isog_cyclic (Zp_unit_isog x1)). by rewrite Aut_prime_cyclic // -orderE ox1. exists m; split=> {im_m mV}//; have [n0 | n_gt0] := posnP n. by apply/eqP; rewrite eq_sym eqEcard pcore_sub oF oA n0 muln1 /=. have [t At mt]: {t | t \in A & m t = -1}%R. apply: inv_m; rewrite /= Zp_cast // coprime_modr modn_small // subn1. by rewrite coprimenP // ltnW. have ot: #[t] = 2. apply/eqP; rewrite eqn_leq order_gt1 dvdn_leq ?order_dvdn //=. apply/eqP; move/(congr1 m); apply/eqP; rewrite mt m1 eq_sym -subr_eq0. rewrite opprK -val_eqE /= Zp_cast ?modn_small // /q oG ltnW //. by rewrite (leq_trans (_ : 2 ^ 2 <= p ^ 2)) ?leq_sqr ?leq_exp2l. by apply/eqP; apply: inj_m; rewrite ?groupX ?group1 ?mX // mt -signr_odd. exists t; split=> //. case G4: (~~ odd p && (n == 1%N)). case: (even_prime p_pr) G4 => [p2 | -> //]; rewrite p2 /=; move/eqP=> n1. rewrite n1 /=; apply/eqP; rewrite eq_sym eqEcard cycle_subG At /=. by rewrite -orderE oA ot p2 n1. pose e0 : nat := ~~ odd p. have{inv_m} [s As ms]: {s | s \in A & m s = (p ^ e0.+1).+1%:R}. apply: inv_m; rewrite val_Zp_nat // coprime_modr /q oG coprime_pexpl //. by rewrite -(@coprime_pexpl e0.+1) // coprimenS. have lt_e0_n: e0 < n. by rewrite /e0; case: (~~ _) G4 => //=; rewrite ltn_neqAle eq_sym => ->. pose s0 := s ^+ (p ^ (n - e0.+1)). have [ms0 os0]: m s0 = (p ^ n).+1%:R /\ #[s0] = p. have m_se e: exists2 k, k = 1 %[mod p] & m (s ^+ (p ^ e)) = (k * p ^ (e + e0.+1)).+1%:R. - elim: e => [|e [k k1 IHe]]; first by exists 1%N; rewrite ?mul1n. rewrite expnSr expgM mX ?groupX // {}IHe -natrX -(add1n (k * _)). rewrite expnDn -(prednK p_gt0) 2!big_ord_recl /= prednK // !exp1n bin1. rewrite bin0 muln1 mul1n mulnCA -expnS (addSn e). set f := (e + _)%N; set sum := (\sum_i _)%N. exists (sum %/ p ^ f.+2 * p + k)%N; first by rewrite modnMDl. rewrite -(addnC k) mulnDl -mulnA -expnS divnK // {}/sum. apply big_ind => [||[i _] /= _]; [exact: dvdn0 | exact: dvdn_add |]. rewrite exp1n mul1n /bump !add1n expnMn mulnCA dvdn_mull // -expnM. case: (ltnP f.+1 (f * i.+2)) => [le_f_fi|]. by rewrite dvdn_mull ?dvdn_exp2l. rewrite {1}mulnS -(addn1 f) leq_add2l {}/f addnS /e0. case: i e => [] // [] //; case odd_p: (odd p) => //= _. by rewrite bin2odd // mulnAC dvdn_mulr. have [[|d]] := m_se (n - e0.+1)%N; first by rewrite mod0n modn_small. move/eqP; rewrite -/s0 eqn_mod_dvd ?subn1 //=; case/dvdnP=> f -> {d}. rewrite subnK // mulSn -mulnA -expnS -addSn natrD natrM -oG pchar_Zp //. rewrite mulr0 addr0 => m_s0; split => //. have [d _] := m_se (n - e0)%N; rewrite -subnSK // expnSr expgM -/s0. rewrite addSn subnK // -oG mulrS natrM pchar_Zp // {d}mulr0 addr0. move/eqP; rewrite -m1 (inj_in_eq inj_m) ?group1 ?groupX // -order_dvdn. move/min_p; rewrite order_eq1; case/predU1P=> [s0_1 | ]; last by move/eqP. move/eqP: m_s0; rewrite eq_sym s0_1 m1 -subr_eq0 mulrSr addrK -val_eqE /=. have pf_gt0: p ^ _ > 0 by move=> e; rewrite expn_gt0 p_gt0. by rewrite val_Zp_nat // /q oG [_ == _]pfactor_dvdn // pfactorK ?ltnn. have os: #[s] = (p ^ (n - e0))%N. have: #[s] %| p ^ (n - e0). by rewrite order_dvdn -subnSK // expnSr expgM -order_dvdn os0. case/dvdn_pfactor=> // d; rewrite leq_eqVlt. case/predU1P=> [-> // | lt_d os]; case/idPn: (p_gt1); rewrite -os0. by rewrite order_gt1 negbK -order_dvdn os dvdn_exp2l // -ltnS -subSn. have p_s: p.-elt s by rewrite /p_elt os pnatX ?pnat_id. have defS1: 'Ohm_1(<[s]>) = <[s0]>. apply/eqP; rewrite eq_sym eqEcard cycle_subG -orderE os0. rewrite (Ohm1_cyclic_pgroup_prime _ p_s) ?cycle_cyclic ?leqnn ?cycle_eq1 //=. rewrite (OhmE _ p_s) mem_gen ?groupX //= !inE mem_cycle //. by rewrite -order_dvdn os0 ?dvdnn. by apply/eqP=> s1; rewrite -os0 /s0 s1 expg1n order1 in p_gt1. case: (even_prime p_pr) => [p2 | oddp]; last first. rewrite {+}/e0 oddp subn0 in s0 os0 ms0 os ms defS1 *. have [f defF] := cyclicP cycF; have defP: P = <[s]>. apply/eqP; rewrite eq_sym eqEcard -orderE oP os leqnn andbT. by rewrite cycle_subG (mem_normal_Hall sylP) ?pcore_normal. rewrite defP; split; last 1 [by exists s | by exists s0; rewrite ?groupX]. rewrite -defPF defP defF -cycleM ?cycle_cyclic // /order. by red; rewrite (centsP cAA) // -cycle_subG -defF pcore_sub. by rewrite -defF -defP (pnat_coprime (pcore_pgroup _ _) (pcore_pgroup _ _)). rewrite {+}/e0 p2 subn1 /= in s0 os0 ms0 os ms G4 defS1 lt_e0_n *. rewrite G4; exists s; split=> //; last first. exists s0; split; rewrite ?groupX //; apply/eqP; rewrite mM ?groupX //. rewrite ms0 mt eq_sym mulrN1 -subr_eq0 opprK -natrD -addSnnS. by rewrite prednK ?expn_gt0 // addnn -mul2n -expnS -p2 -oG pchar_Zp. suffices TIst: <[s]> :&: <[t]> = 1. rewrite dprodE //; last by rewrite (sub_abelian_cent2 cAA) ?cycle_subG. apply/eqP; rewrite eqEcard mulG_subG !cycle_subG As At oA. by rewrite TI_cardMg // -!orderE os ot p2 mul1n /= -expnSr prednK. rewrite setIC; apply: prime_TIg; first by rewrite -orderE ot. rewrite cycle_subG; apply/negP=> St. have: t \in <[s0]>. by rewrite -defS1 (OhmE _ p_s) mem_gen // !inE St -order_dvdn ot p2. have ->: <[s0]> = [set 1; s0]. apply/eqP; rewrite eq_sym eqEcard subUset !sub1set group1 cycle_id /=. by rewrite -orderE cards2 eq_sym -order_gt1 os0. rewrite !inE -order_eq1 ot /=; move/eqP; move/(congr1 m); move/eqP. rewrite mt ms0 eq_sym -subr_eq0 opprK -mulrSr. rewrite -val_eqE [val _]val_Zp_nat //= /q oG p2 modn_small //. by rewrite -addn3 expnS mul2n -addnn leq_add2l (ltn_exp2l 1). Qed. Definition extremal_generators gT (A : {set gT}) p n xy := let: (x, y) := xy in [/\ #|A| = (p ^ n)%N, x \in A, #[x] = (p ^ n.-1)%N & y \in A :\: <[x]>]. Lemma extremal_generators_facts gT (G : {group gT}) p n x y : prime p -> extremal_generators G p n (x, y) -> [/\ p.-group G, maximal <[x]> G, <[x]> <| G, <[x]> * <[y]> = G & <[y]> \subset 'N(<[x]>)]. Proof. move=> p_pr [oG Gx ox] /setDP[Gy notXy]. have pG: p.-group G by rewrite /pgroup oG pnatX pnat_id. have maxX: maximal <[x]> G. rewrite p_index_maximal -?divgS ?cycle_subG // -orderE oG ox. case: (n) oG => [|n' _]; last by rewrite -expnB ?subSnn ?leqnSn ?prime_gt0. move/eqP; rewrite -trivg_card1; case/trivgPn. by exists y; rewrite // (group1_contra notXy). have nsXG := p_maximal_normal pG maxX; split=> //. by apply: mulg_normal_maximal; rewrite ?cycle_subG. by rewrite cycle_subG (subsetP (normal_norm nsXG)). Qed. Section ModularGroup. Variables p n : nat. Let m := (p ^ n)%N. Let q := (p ^ n.-1)%N. Let r := (p ^ n.-2)%N. Hypotheses (p_pr : prime p) (n_gt2 : n > 2). Let p_gt1 := prime_gt1 p_pr. Let p_gt0 := ltnW p_gt1. Let def_n := esym (subnKC n_gt2). Let def_p : pdiv m = p. Proof. by rewrite /m def_n pdiv_pfactor. Qed. Let def_q : m %/ p = q. Proof. by rewrite /m /q def_n expnS mulKn. Qed. Let def_r : q %/ p = r. Proof. by rewrite /r /q def_n expnS mulKn. Qed. Let ltqm : q < m. Proof. by rewrite ltn_exp2l // def_n. Qed. Let ltrq : r < q. Proof. by rewrite ltn_exp2l // def_n. Qed. Let r_gt0 : 0 < r. Proof. by rewrite expn_gt0 ?p_gt0. Qed. Let q_gt1 : q > 1. Proof. exact: leq_ltn_trans r_gt0 ltrq. Qed. Lemma card_modular_group : #|'Mod_(p ^ n)| = (p ^ n)%N. Proof. by rewrite Extremal.card def_p ?def_q // -expnS def_n. Qed. Lemma Grp_modular_group : 'Mod_(p ^ n) \isog Grp (x : y : x ^+ q, y ^+ p, x ^ y = x ^+ r.+1). Proof. rewrite /modular_gtype def_p def_q def_r; apply: Extremal.Grp => //. set B := <[_]>; have Bb: Zp1 \in B by apply: cycle_id. have oB: #|B| = q by rewrite -orderE order_Zp1 Zp_cast. have cycB: cyclic B by rewrite cycle_cyclic. have pB: p.-group B by rewrite /pgroup oB pnatX ?pnat_id. have ntB: B != 1 by rewrite -cardG_gt1 oB. have [] := cyclic_pgroup_Aut_structure pB cycB ntB. rewrite oB pfactorK //= -/B -(expg_znat r.+1 Bb) oB => mB [[def_mB _ _ _ _] _]. rewrite {1}def_n /= => [[t [At ot mBt]]]. have [p2 | ->] := even_prime p_pr; last first. by case=> _ _ [s [As os mBs _]]; exists s; rewrite os -mBs def_mB. rewrite {1}p2 /= -2!eqSS -addn2 -2!{1}subn1 -subnDA subnK 1?ltnW //. case: eqP => [n3 _ | _ [_ [_ _ _ _ [s [As os mBs _ _]{t At ot mBt}]]]]. by exists t; rewrite At ot -def_mB // mBt /q /r p2 n3. by exists s; rewrite As os -def_mB // mBs /r p2. Qed. Definition modular_group_generators gT (xy : gT * gT) := let: (x, y) := xy in #[y] = p /\ x ^ y = x ^+ r.+1. Lemma generators_modular_group gT (G : {group gT}) : G \isog 'Mod_m -> exists2 xy, extremal_generators G p n xy & modular_group_generators xy. Proof. case/(isoGrpP _ Grp_modular_group); rewrite card_modular_group // -/m => oG. case/existsP=> -[x y] /= /eqP[defG xq yp xy]. rewrite norm_joinEr ?norms_cycle ?xy ?mem_cycle // in defG. have [Gx Gy]: x \in G /\ y \in G. by apply/andP; rewrite -!cycle_subG -mulG_subG defG. have notXy: y \notin <[x]>. apply: contraL ltqm; rewrite -cycle_subG -oG -defG; move/mulGidPl->. by rewrite -leqNgt dvdn_leq ?(ltnW q_gt1) // order_dvdn xq. have oy: #[y] = p by apply: nt_prime_order (group1_contra notXy). exists (x, y) => //=; split; rewrite ?inE ?notXy //. apply/eqP; rewrite -(eqn_pmul2r p_gt0) -expnSr -{1}oy (ltn_predK n_gt2) -/m. by rewrite -TI_cardMg ?defG ?oG // setIC prime_TIg ?cycle_subG // -orderE oy. Qed. (* This is an adaptation of Aschbacher, exercise 8.2: *) (* - We allow an alternative to the #[x] = p ^ n.-1 condition that meshes *) (* better with the modular_Grp lemma above. *) (* - We state explicitly some "obvious" properties of G, namely that G is *) (* the non-abelian semi-direct product <[x]> ><| <[y]> and that y ^+ j *) (* acts on <[x]> via z |-> z ^+ (j * p ^ n.-2).+1 *) (* - We also give the values of the 'Mho^k(G). *) (* - We corrected a pair of typos. *) Lemma modular_group_structure gT (G : {group gT}) x y : extremal_generators G p n (x, y) -> G \isog 'Mod_m -> modular_group_generators (x, y) -> let X := <[x]> in [/\ [/\ X ><| <[y]> = G, ~~ abelian G & {in X, forall z j, z ^ (y ^+ j) = z ^+ (j * r).+1}], [/\ 'Z(G) = <[x ^+ p]>, 'Phi(G) = 'Z(G) & #|'Z(G)| = r], [/\ G^`(1) = <[x ^+ r]>, #|G^`(1)| = p & nil_class G = 2], forall k, k > 0 -> 'Mho^k(G) = <[x ^+ (p ^ k)]> & if (p, n) == (2, 3) then 'Ohm_1(G) = G else forall k, 0 < k < n.-1 -> <[x ^+ (p ^ (n - k.+1))]> \x <[y]> = 'Ohm_k(G) /\ #|'Ohm_k(G)| = (p ^ k.+1)%N]. Proof. move=> genG isoG [oy xy] X. have [oG Gx ox /setDP[Gy notXy]] := genG; rewrite -/m -/q in ox oG. have [pG _ nsXG defXY nXY] := extremal_generators_facts p_pr genG. have [sXG nXG] := andP nsXG; have sYG: <[y]> \subset G by rewrite cycle_subG. have n1_gt1: n.-1 > 1 by [rewrite def_n]; have n1_gt0 := ltnW n1_gt1. have def_n1 := prednK n1_gt0. have def_m: (q * p)%N = m by rewrite -expnSr /m def_n. have notcxy: y \notin 'C[x]. apply: contraL (introT eqP xy); move/cent1P=> cxy. rewrite /conjg -cxy // eq_mulVg1 expgS !mulKg -order_dvdn ox. by rewrite pfactor_dvdn ?expn_gt0 ?p_gt0 // pfactorK // -ltnNge prednK. have tiXY: <[x]> :&: <[y]> = 1. rewrite setIC prime_TIg -?orderE ?oy //; apply: contra notcxy. by rewrite cycle_subG; apply: subsetP; rewrite cycle_subG cent1id. have notcGG: ~~ abelian G. by rewrite -defXY abelianM !cycle_abelian cent_cycle cycle_subG. have cXpY: <[y]> \subset 'C(<[x ^+ p]>). rewrite cent_cycle cycle_subG cent1C (sameP cent1P commgP) /commg conjXg xy. by rewrite -expgM mulSn expgD mulKg -expnSr def_n1 -/q -ox expg_order. have oxp: #[x ^+ p] = r by rewrite orderXdiv ox ?dvdn_exp //. have [sZG nZG] := andP (center_normal G). have defZ: 'Z(G) = <[x ^+ p]>. apply/eqP; rewrite eq_sym eqEcard subsetI -{2}defXY centM subsetI cent_cycle. rewrite 2!cycle_subG !groupX ?cent1id //= centsC cXpY /= -orderE oxp leqNgt. apply: contra notcGG => gtZr; apply: cyclic_center_factor_abelian. rewrite (dvdn_prime_cyclic p_pr) // card_quotient //. rewrite -(dvdn_pmul2l (cardG_gt0 'Z(G))) Lagrange // oG -def_m dvdn_pmul2r //. case/p_natP: (pgroupS sZG pG) gtZr => k ->. by rewrite ltn_exp2l // def_n1; apply: dvdn_exp2l. have Zxr: x ^+ r \in 'Z(G) by rewrite /r def_n expnS expgM defZ mem_cycle. have rxy: [~ x, y] = x ^+ r by rewrite /commg xy expgS mulKg. have defG': G^`(1) = <[x ^+ r]>. case/setIP: Zxr => _; rewrite -rxy -defXY -(norm_joinEr nXY). exact: der1_joing_cycles. have oG': #|G^`(1)| = p. by rewrite defG' -orderE orderXdiv ox /q -def_n1 ?dvdn_exp2l // expnS mulnK. have sG'Z: G^`(1) \subset 'Z(G) by rewrite defG' cycle_subG. have nil2_G: nil_class G = 2. by apply/eqP; rewrite eqn_leq andbC ltnNge nil_class1 notcGG nil_class2. have XYp: {in X & <[y]>, forall z t, (z * t) ^+ p \in z ^+ p *: <[x ^+ r ^+ 'C(p, 2)]>}. - move=> z t Xz Yt; have Gz := subsetP sXG z Xz; have Gt := subsetP sYG t Yt. have Rtz: [~ t, z] \in G^`(1) by apply: mem_commg. have cGtz: [~ t, z] \in 'C(G) by case/setIP: (subsetP sG'Z _ Rtz). rewrite expMg_Rmul /commute ?(centP cGtz) //. have ->: t ^+ p = 1 by apply/eqP; rewrite -order_dvdn -oy order_dvdG. rewrite defG' in Rtz; case/cycleP: Rtz => i ->. by rewrite mem_lcoset mulg1 mulKg expgAC mem_cycle. have defMho: 'Mho^1(G) = <[x ^+ p]>. apply/eqP; rewrite eqEsubset cycle_subG (Mho_p_elt 1) ?(mem_p_elt pG) //. rewrite andbT (MhoE 1 pG) gen_subG -defXY; apply/subsetP=> ztp. case/imsetP=> zt; case/imset2P=> z t Xz Yt -> -> {zt ztp}. apply: subsetP (XYp z t Xz Yt); case/cycleP: Xz => i ->. by rewrite expgAC mul_subG ?sub1set ?mem_cycle //= -defZ cycle_subG groupX. split=> //; try exact: extend_cyclic_Mho. - rewrite sdprodE //; split=> // z; case/cycleP=> i ->{z} j. rewrite conjXg -expgM mulnC expgM actX; congr (_ ^+ i). elim: j {i} => //= j ->; rewrite conjXg xy -!expgM mulnS mulSn addSn. rewrite addnA -mulSn -addSn expgD mulnCA (mulnC j). rewrite {3}/r def_n expnS mulnA -expnSr def_n1 -/q -ox -mulnA expgM. by rewrite expg_order expg1n mulg1. - by rewrite (Phi_joing pG) defMho -defZ (joing_idPr _) ?defZ. have G1y: y \in 'Ohm_1(G). by rewrite (OhmE _ pG) mem_gen // !inE Gy -order_dvdn oy /=. case: eqP => [[p2 n3] | notG8 k]; last case/andP=> k_gt0 lt_k_n1. apply/eqP; rewrite eqEsubset Ohm_sub -{1}defXY mulG_subG !cycle_subG. rewrite G1y -(groupMr _ G1y) /= (OhmE _ pG) mem_gen // !inE groupM //. rewrite /q /r p2 n3 in oy ox xy *. by rewrite expgS -mulgA -{1}(invg2id oy) -conjgE xy -expgS -order_dvdn ox. have le_k_n2: k <= n.-2 by rewrite -def_n1 in lt_k_n1. suffices{lt_k_n1} defGk: <[x ^+ (p ^ (n - k.+1))]> \x <[y]> = 'Ohm_k(G). split=> //; case/dprodP: defGk => _ <- _ tiXkY; rewrite expnSr TI_cardMg //. rewrite -!orderE oy (subnDA 1) subn1 orderXdiv ox ?dvdn_exp2l ?leq_subr //. by rewrite /q -{1}(subnK (ltnW lt_k_n1)) expnD mulKn // expn_gt0 p_gt0. suffices{k k_gt0 le_k_n2} defGn2: <[x ^+ p]> \x <[y]> = 'Ohm_(n.-2)(G). have:= Ohm_dprod k defGn2; have p_xp := mem_p_elt pG (groupX p Gx). rewrite (Ohm_p_cycle _ p_xp) (Ohm_p_cycle _ (mem_p_elt pG Gy)) oxp oy. rewrite pfactorK ?(pfactorK 1) // (eqnP k_gt0) expg1 -expgM -expnS. rewrite -subSn // -subSS def_n1 def_n => -> /=; rewrite ?add1n subnSK // subn2. by apply/eqP; rewrite eqEsubset OhmS ?Ohm_sub //= -{1}Ohm_id OhmS ?Ohm_leq. rewrite dprodEY //=; last by apply/trivgP; rewrite -tiXY setSI ?cycleX. apply/eqP; rewrite eqEsubset join_subG !cycle_subG /= [in y \in _]def_n. rewrite (subsetP (Ohm_leq G (ltn0Sn _)) y) //= (OhmE _ pG) -/r. rewrite mem_gen /=; last by rewrite !inE -order_dvdn oxp groupX /=. rewrite gen_subG /= cent_joinEr // -defXY; apply/subsetP=> uv; case/setIP. case/imset2P=> u v Xu Yv ->{uv}; rewrite /r inE def_n expnS expgM. case/lcosetP: (XYp u v Xu Yv) => _ /cycleP[j ->] ->. case/cycleP: Xu => i ->{u}; rewrite -!(expgM, expgD) -order_dvdn ox. rewrite (mulnC r) /r {1}def_n expnSr mulnA -mulnDl -mulnA -expnS. rewrite subnSK // subn2 /q -def_n1 expnS dvdn_pmul2r // dvdn_addl. by case/dvdnP=> k ->; rewrite mulnC expgM mem_mulg ?mem_cycle. case: (ltngtP n 3) => [|n_gt3|n3]; first by rewrite ltnNge n_gt2. by rewrite -subnSK // expnSr mulnA dvdn_mull. case: (even_prime p_pr) notG8 => [-> | oddp _]; first by rewrite n3. by rewrite bin2odd // -!mulnA dvdn_mulr. Qed. End ModularGroup. (* Basic properties of dihedral groups; these will be refined for dihedral *) (* 2-groups in the section on extremal 2-groups. *) Section DihedralGroup. Variable q : nat. Hypothesis q_gt1 : q > 1. Let m := q.*2. Let def2 : pdiv m = 2. Proof. apply/eqP; rewrite /m -mul2n eqn_leq pdiv_min_dvd ?dvdn_mulr //. by rewrite prime_gt1 // pdiv_prime // (@leq_pmul2l 2 1) ltnW. Qed. Let def_q : m %/ pdiv m = q. Proof. by rewrite def2 divn2 half_double. Qed. Section Dihedral_extension. Variable p : nat. Hypotheses (p_gt1 : p > 1) (even_p : 2 %| p). Local Notation ED := [set: gsort (Extremal.gtype q p q.-1)]. Lemma card_ext_dihedral : #|ED| = (p./2 * m)%N. Proof. by rewrite Extremal.card // /m -mul2n -divn2 mulnA divnK. Qed. Lemma Grp_ext_dihedral : ED \isog Grp (x : y : x ^+ q, y ^+ p, x ^ y = x^-1). Proof. suffices isoED: ED \isog Grp (x : y : x ^+ q, y ^+ p, x ^ y = x ^+ q.-1). move=> gT G; rewrite isoED. apply: eq_existsb => [[x y]] /=; rewrite !xpair_eqE. congr (_ && _); apply: andb_id2l; move/eqP=> xq1; congr (_ && (_ == _)). by apply/eqP; rewrite eq_sym eq_invg_mul -expgS (ltn_predK q_gt1) xq1. have unitrN1 : (- 1)%R \in GRing.unit by move=> R; rewrite unitrN unitr1. pose uN1 := FinRing.unit ('Z_#[Zp1 : 'Z_q]) (unitrN1 _). apply: Extremal.Grp => //; exists (Zp_unitm uN1). rewrite Aut_aut order_injm ?injm_Zp_unitm ?in_setT //; split=> //. by rewrite (dvdn_trans _ even_p) // order_dvdn -val_eqE /= mulrNN. apply/eqP; rewrite autE ?cycle_id // eq_expg_mod_order /=. by rewrite order_Zp1 !Zp_cast // !modn_mod (modn_small q_gt1) subn1. Qed. End Dihedral_extension. Lemma card_dihedral : #|'D_m| = m. Proof. by rewrite /('D_m)%type def_q card_ext_dihedral ?mul1n. Qed. Lemma Grp_dihedral : 'D_m \isog Grp (x : y : x ^+ q, y ^+ 2, x ^ y = x^-1). Proof. by rewrite /('D_m)%type def_q; apply: Grp_ext_dihedral. Qed. Lemma Grp'_dihedral : 'D_m \isog Grp (x : y : x ^+ 2, y ^+ 2, (x * y) ^+ q). Proof. move=> gT G; rewrite Grp_dihedral; apply/existsP/existsP=> [] [[x y]] /=. case/eqP=> <- xq1 y2 xy; exists (x * y, y); rewrite !xpair_eqE /= eqEsubset. rewrite !join_subG !joing_subr !cycle_subG -{3}(mulgK y x) /=. rewrite 2?groupM ?groupV ?mem_gen ?inE ?cycle_id ?orbT //= -mulgA expgS. by rewrite {1}(conjgC x) xy -mulgA mulKg -(expgS y 1) y2 mulg1 xq1 !eqxx. case/eqP=> <- x2 y2 xyq; exists (x * y, y); rewrite !xpair_eqE /= eqEsubset. rewrite !join_subG !joing_subr !cycle_subG -{3}(mulgK y x) /=. rewrite 2?groupM ?groupV ?mem_gen ?inE ?cycle_id ?orbT //= xyq y2 !eqxx /=. by rewrite eq_sym eq_invg_mul !mulgA mulgK -mulgA -!(expgS _ 1) x2 y2 mulg1. Qed. End DihedralGroup. Lemma involutions_gen_dihedral gT (x y : gT) : let G := <<[set x; y]>> in #[x] = 2 -> #[y] = 2 -> x != y -> G \isog 'D_#|G|. Proof. move=> G ox oy ne_x_y; pose q := #[x * y]. have q_gt1: q > 1 by rewrite order_gt1 -eq_invg_mul invg_expg ox. have homG: G \homg 'D_q.*2. rewrite Grp'_dihedral //; apply/existsP; exists (x, y); rewrite /= !xpair_eqE. by rewrite joing_idl joing_idr -{1}ox -oy !expg_order !eqxx. suff oG: #|G| = q.*2 by rewrite oG isogEcard oG card_dihedral ?leqnn ?andbT. have: #|G| %| q.*2 by rewrite -card_dihedral ?card_homg. have Gxy: <[x * y]> \subset G. by rewrite cycle_subG groupM ?mem_gen ?set21 ?set22. have[k oG]: exists k, #|G| = (k * q)%N by apply/dvdnP; rewrite cardSg. rewrite oG -mul2n dvdn_pmul2r ?order_gt0 ?dvdn_divisors // !inE /=. case/pred2P=> [k1 | -> //]; case/negP: ne_x_y. have cycG: cyclic G. apply/cyclicP; exists (x * y); apply/eqP. by rewrite eq_sym eqEcard Gxy oG k1 mul1n leqnn. have: <[x]> == <[y]>. by rewrite (eq_subG_cyclic cycG) ?genS ?subsetUl ?subsetUr -?orderE ?ox ?oy. by rewrite eqEcard cycle_subG /= cycle2g // !inE -order_eq1 ox; case/andP. Qed. Lemma Grp_2dihedral n : n > 1 -> 'D_(2 ^ n) \isog Grp (x : y : x ^+ (2 ^ n.-1), y ^+ 2, x ^ y = x^-1). Proof. move=> n_gt1; rewrite -(ltn_predK n_gt1) expnS mul2n /=. by apply: Grp_dihedral; rewrite (ltn_exp2l 0) // -(subnKC n_gt1). Qed. Lemma card_2dihedral n : n > 1 -> #|'D_(2 ^ n)| = (2 ^ n)%N. Proof. move=> n_gt1; rewrite -(ltn_predK n_gt1) expnS mul2n /= card_dihedral //. by rewrite (ltn_exp2l 0) // -(subnKC n_gt1). Qed. Lemma card_semidihedral n : n > 3 -> #|'SD_(2 ^ n)| = (2 ^ n)%N. Proof. move=> n_gt3. rewrite /('SD__)%type -(subnKC (ltnW (ltnW n_gt3))) pdiv_pfactor //. by rewrite // !expnS !mulKn -?expnS ?Extremal.card //= (ltn_exp2l 0). Qed. Lemma Grp_semidihedral n : n > 3 -> 'SD_(2 ^ n) \isog Grp (x : y : x ^+ (2 ^ n.-1), y ^+ 2, x ^ y = x ^+ (2 ^ n.-2).-1). Proof. move=> n_gt3. rewrite /('SD__)%type -(subnKC (ltnW (ltnW n_gt3))) pdiv_pfactor //. rewrite !expnS !mulKn // -!expnS /=; set q := (2 ^ _)%N. have q_gt1: q > 1 by rewrite (ltn_exp2l 0). apply: Extremal.Grp => //; set B := <[_]>. have oB: #|B| = q by rewrite -orderE order_Zp1 Zp_cast. have pB: 2.-group B by rewrite /pgroup oB pnatX. have ntB: B != 1 by rewrite -cardG_gt1 oB. have [] := cyclic_pgroup_Aut_structure pB (cycle_cyclic _) ntB. rewrite oB /= pfactorK //= -/B => m [[def_m _ _ _ _] _]. rewrite -{1 2}(subnKC n_gt3) => [[t [At ot _ [s [_ _ _ defA]]]]]. case/dprodP: defA => _ defA cst _. have{cst defA} cAt: t \in 'C(Aut B). rewrite -defA centM inE -sub_cent1 -cent_cycle centsC cst /=. by rewrite cent_cycle cent1id. case=> s0 [As0 os0 _ def_s0t _]; exists (s0 * t). rewrite -def_m ?groupM ?cycle_id // def_s0t !Zp_expg !mul1n valZpK Zp_nat. rewrite order_dvdn expgMn /commute 1?(centP cAt) // -{1}os0 -{1}ot. by rewrite !expg_order mul1g. Qed. Section Quaternion. Variable n : nat. Hypothesis n_gt2 : n > 2. Let m := (2 ^ n)%N. Let q := (2 ^ n.-1)%N. Let r := (2 ^ n.-2)%N. Let GrpQ := 'Q_m \isog Grp (x : y : x ^+ q, y ^+ 2 = x ^+ r, x ^ y = x^-1). Let defQ : #|'Q_m| = m /\ GrpQ. Proof. have q_gt1 : q > 1 by rewrite (ltn_exp2l 0) // -(subnKC n_gt2). have def_m : (2 * q)%N = m by rewrite -expnS (ltn_predK n_gt2). have def_q : m %/ pdiv m = q by rewrite /m -(ltn_predK n_gt2) pdiv_pfactor // expnS mulKn. have r_gt1 : r > 1 by rewrite (ltn_exp2l 0) // -(subnKC n_gt2). have def2r : (2 * r)%N = q by rewrite -expnS /q -(subnKC n_gt2). rewrite /GrpQ [quaternion_gtype]unlock /quaternion_kernel {}def_q. set B := [set: _]; have: B \homg Grp (u : v : u ^+ q, v ^+ 4, u ^ v = u^-1). by rewrite -Grp_ext_dihedral ?homg_refl. have: #|B| = (q * 4)%N by rewrite card_ext_dihedral // mulnC -muln2 -mulnA. rewrite {}/B; move: (Extremal.gtype q 4 _) => gT. set B := [set: gT] => oB; set K := _ :\: _. case/existsP=> -[u v] /= /eqP[defB uq v4 uv]. have nUV: <[v]> \subset 'N(<[u]>) by rewrite norms_cycle uv groupV cycle_id. rewrite norm_joinEr // in defB. have le_ou: #[u] <= q by rewrite dvdn_leq ?expn_gt0 // order_dvdn uq. have le_ov: #[v] <= 4 by rewrite dvdn_leq // order_dvdn v4. have tiUV: <[u]> :&: <[v]> = 1 by rewrite cardMg_TI // defB oB leq_mul. have{le_ou le_ov} [ou ov]: #[u] = q /\ #[v] = 4. have:= esym (leqif_mul (leqif_eq le_ou) (leqif_eq le_ov)).2. by rewrite -TI_cardMg // defB -oB eqxx eqn0Ngt cardG_gt0; do 2!case: eqP=> //. have sdB: <[u]> ><| <[v]> = B by rewrite sdprodE. have uvj j: u ^ (v ^+ j) = (if odd j then u^-1 else u). elim: j => [|j IHj]; first by rewrite conjg1. by rewrite expgS conjgM uv conjVg IHj (fun_if invg) invgK if_neg. have sqrB i j: (u ^+ i * v ^+ j) ^+ 2 = (if odd j then v ^+ 2 else u ^+ i.*2). rewrite expgS; case: ifP => odd_j. rewrite {1}(conjgC (u ^+ i)) conjXg uvj odd_j expgVn -mulgA mulKg. rewrite -expgD addnn -(odd_double_half j) odd_j doubleD addnC /=. by rewrite -(expg_mod _ v4) -!muln2 -mulnA modnMDl. rewrite {2}(conjgC (u ^+ i)) conjXg uvj odd_j mulgA -(mulgA (u ^+ i)). rewrite -expgD addnn -(odd_double_half j) odd_j -2!mul2n mulnA. by rewrite expgM v4 expg1n mulg1 -expgD addnn. pose w := u ^+ r * v ^+ 2. have Kw: w \in K. rewrite !inE sqrB /= -mul2n def2r uq eqxx andbT -defB. apply/imsetP=> [[_]] /imset2P[_ _ /cycleP[i ->] /cycleP[j ->] ->]. apply/eqP; rewrite sqrB; case: ifP => _. rewrite eq_mulgV1 mulgK -order_dvdn ou pfactor_dvdn ?expn_gt0 ?pfactorK //. by rewrite -ltnNge -(subnKC n_gt2). rewrite (canF_eq (mulKg _)); apply/eqP=> def_v2. suffices: v ^+ 2 \in <[u]> :&: <[v]> by rewrite tiUV inE -order_dvdn ov. by rewrite inE {1}def_v2 groupM ?groupV !mem_cycle. have ow: #[w] = 2. case/setDP: Kw; rewrite inE -order_dvdn dvdn_divisors // !inE /= order_eq1. by case/orP=> /eqP-> // /imsetP[]; exists 1; rewrite ?inE ?expg1n. have defK: K = [set w]. apply/eqP; rewrite eqEsubset sub1set Kw andbT subDset setUC. apply/subsetP=> uivj; have: uivj \in B by rewrite inE. rewrite -{1}defB => /imset2P[_ _ /cycleP[i ->] /cycleP[j ->] ->] {uivj}. rewrite !inE sqrB; set b := odd j; rewrite -[j]odd_double_half -/b. case: b; rewrite -order_dvdn ?ov // ou -def2r -mul2n dvdn_pmul2l //. case/dvdnP=> k ->{i}; apply/orP. rewrite add0n -[j./2]odd_double_half addnC doubleD -!muln2 -mulnA. rewrite -(expg_mod_order v) ov modnMDl; case: (odd _); last first. right; rewrite mulg1 /r -(subnKC n_gt2) expnSr mulnA expgM. by apply: imset_f => /[1!inE]. rewrite (inj_eq (mulIg _)) -expg_mod_order ou -[k]odd_double_half. rewrite addnC -muln2 mulnDl -mulnA def2r modnMDl -ou expg_mod_order. case: (odd k); [left | right]; rewrite ?mul1n ?mul1g //. by apply/imsetP; exists v; rewrite ?inE. have nKB: 'N(<<K>>) = B. apply/setP=> b; rewrite !inE -genJ genS // {1}defK conjg_set1 sub1set. have:= Kw; rewrite !inE -!order_dvdn orderJ ow !andbT; apply: contra. case/imsetP=> z _ def_wb; apply/imsetP; exists (z ^ b^-1); rewrite ?inE //. by rewrite -conjXg -def_wb conjgK. rewrite -im_quotient card_quotient // nKB -divgS ?subsetT //. split; first by rewrite oB defK -orderE ow (mulnA q 2 2) mulnK // mulnC. apply: intro_isoGrp => [|rT H]. apply/existsP; exists (coset _ u, coset _ v); rewrite /= !xpair_eqE. rewrite -!morphX -?morphJ -?morphV /= ?nKB ?in_setT // uq uv morph1 !eqxx. rewrite -/B -defB -norm_joinEr // quotientY ?nKB ?subsetT //= andbT. rewrite !quotient_cycle /= ?nKB ?in_setT ?eqxx //=. by rewrite -(coset_kerl _ (mem_gen Kw)) -mulgA -expgD v4 mulg1. case/existsP=> -[x y] /= /eqP[defH xq y2 xy]. have ox: #[x] %| #[u] by rewrite ou order_dvdn xq. have oy: #[y] %| #[v]. by rewrite ov order_dvdn (expgM y 2 2) y2 -expgM mulnC def2r xq. have actB: {in <[u]> & <[v]>, morph_act 'J 'J (eltm ox) (eltm oy)}. move=> _ _ /cycleP[i ->] /cycleP[j ->] /=. rewrite conjXg uvj fun_if if_arg fun_if expgVn morphV ?mem_cycle //= !eltmE. rewrite -expgVn -if_arg -fun_if conjXg; congr (_ ^+ i). rewrite -{2}[j]odd_double_half addnC expgD -mul2n expgM y2. rewrite -expgM conjgM (conjgE x) commuteX // mulKg. by case: (odd j); rewrite ?conjg1. pose f := sdprodm sdB actB. have Kf: 'ker (coset <<K>>) \subset 'ker f. rewrite ker_coset defK cycle_subG /= ker_sdprodm. apply/imset2P; exists (u ^+ r) (v ^+ 2); first exact: mem_cycle. by rewrite inE mem_cycle /= !eltmE y2. by apply: canRL (mulgK _) _; rewrite -mulgA -expgD v4 mulg1. have Df: 'dom f \subset 'dom (coset <<K>>) by rewrite /dom nKB subsetT. apply/homgP; exists (factm_morphism Kf Df); rewrite morphim_factm /= -/B. rewrite -{2}defB morphim_sdprodm // !morphim_cycle ?cycle_id //= !eltm_id. by rewrite -norm_joinEr // norms_cycle xy groupV cycle_id. Qed. Lemma card_quaternion : #|'Q_m| = m. Proof. by case defQ. Qed. Lemma Grp_quaternion : GrpQ. Proof. by case defQ. Qed. End Quaternion. Lemma eq_Mod8_D8 : 'Mod_8 = 'D_8. Proof. by []. Qed. Section ExtremalStructure. Variables (gT : finGroupType) (G : {group gT}) (n : nat). Implicit Type H : {group gT}. Let m := (2 ^ n)%N. Let q := (2 ^ n.-1)%N. Let q_gt0: q > 0. Proof. by rewrite expn_gt0. Qed. Let r := (2 ^ n.-2)%N. Let r_gt0: r > 0. Proof. by rewrite expn_gt0. Qed. Let def2qr : n > 1 -> [/\ 2 * q = m, 2 * r = q, q < m & r < q]%N. Proof. by rewrite /q /m /r; move/subnKC=> <-; rewrite !ltn_exp2l ?expnS. Qed. Lemma generators_2dihedral : n > 1 -> G \isog 'D_m -> exists2 xy, extremal_generators G 2 n xy & let: (x, y) := xy in #[y] = 2 /\ x ^ y = x^-1. Proof. move=> n_gt1; have [def2q _ ltqm _] := def2qr n_gt1. case/(isoGrpP _ (Grp_2dihedral n_gt1)); rewrite card_2dihedral // -/ m => oG. case/existsP=> -[x y] /=; rewrite -/q => /eqP[defG xq y2 xy]. have{} defG: <[x]> * <[y]> = G. by rewrite -norm_joinEr // norms_cycle xy groupV cycle_id. have notXy: y \notin <[x]>. apply: contraL ltqm => Xy; rewrite -leqNgt -oG -defG mulGSid ?cycle_subG //. by rewrite dvdn_leq // order_dvdn xq. have oy: #[y] = 2 by apply: nt_prime_order (group1_contra notXy). have ox: #[x] = q. apply: double_inj; rewrite -muln2 -oy -mul2n def2q -oG -defG TI_cardMg //. by rewrite setIC prime_TIg ?cycle_subG // -orderE oy. exists (x, y) => //=. by rewrite oG ox !inE notXy -!cycle_subG /= -defG mulG_subl mulG_subr. Qed. Lemma generators_semidihedral : n > 3 -> G \isog 'SD_m -> exists2 xy, extremal_generators G 2 n xy & let: (x, y) := xy in #[y] = 2 /\ x ^ y = x ^+ r.-1. Proof. move=> n_gt3; have [def2q _ ltqm _] := def2qr (ltnW (ltnW n_gt3)). case/(isoGrpP _ (Grp_semidihedral n_gt3)). rewrite card_semidihedral // -/m => oG. case/existsP=> -[x y] /=; rewrite -/q -/r => /eqP[defG xq y2 xy]. have{} defG: <[x]> * <[y]> = G. by rewrite -norm_joinEr // norms_cycle xy mem_cycle. have notXy: y \notin <[x]>. apply: contraL ltqm => Xy; rewrite -leqNgt -oG -defG mulGSid ?cycle_subG //. by rewrite dvdn_leq // order_dvdn xq. have oy: #[y] = 2 by apply: nt_prime_order (group1_contra notXy). have ox: #[x] = q. apply: double_inj; rewrite -muln2 -oy -mul2n def2q -oG -defG TI_cardMg //. by rewrite setIC prime_TIg ?cycle_subG // -orderE oy. exists (x, y) => //=. by rewrite oG ox !inE notXy -!cycle_subG /= -defG mulG_subl mulG_subr. Qed. Lemma generators_quaternion : n > 2 -> G \isog 'Q_m -> exists2 xy, extremal_generators G 2 n xy & let: (x, y) := xy in [/\ #[y] = 4, y ^+ 2 = x ^+ r & x ^ y = x^-1]. Proof. move=> n_gt2; have [def2q def2r ltqm _] := def2qr (ltnW n_gt2). case/(isoGrpP _ (Grp_quaternion n_gt2)); rewrite card_quaternion // -/m => oG. case/existsP=> -[x y] /=; rewrite -/q -/r => /eqP[defG xq y2 xy]. have{} defG: <[x]> * <[y]> = G. by rewrite -norm_joinEr // norms_cycle xy groupV cycle_id. have notXy: y \notin <[x]>. apply: contraL ltqm => Xy; rewrite -leqNgt -oG -defG mulGSid ?cycle_subG //. by rewrite dvdn_leq // order_dvdn xq. have ox: #[x] = q. apply/eqP; rewrite eqn_leq dvdn_leq ?order_dvdn ?xq //=. rewrite -(leq_pmul2r (order_gt0 y)) mul_cardG defG oG -def2q mulnAC mulnC. rewrite leq_pmul2r // dvdn_leq ?muln_gt0 ?cardG_gt0 // order_dvdn expgM. by rewrite -order_dvdn order_dvdG //= inE {1}y2 !mem_cycle. have oy2: #[y ^+ 2] = 2 by rewrite y2 orderXdiv ox -def2r ?dvdn_mull ?mulnK. exists (x, y) => /=; last by rewrite (orderXprime oy2). by rewrite oG !inE notXy -!cycle_subG /= -defG mulG_subl mulG_subr. Qed. Variables x y : gT. Implicit Type M : {group gT}. Let X := <[x]>. Let Y := <[y]>. Let yG := y ^: G. Let xyG := (x * y) ^: G. Let My := <<yG>>. Let Mxy := <<xyG>>. Theorem dihedral2_structure : n > 1 -> extremal_generators G 2 n (x, y) -> G \isog 'D_m -> [/\ [/\ X ><| Y = G, {in G :\: X, forall t, #[t] = 2} & {in X & G :\: X, forall z t, z ^ t = z^-1}], [/\ G ^`(1) = <[x ^+ 2]>, 'Phi(G) = G ^`(1), #|G^`(1)| = r & nil_class G = n.-1], 'Ohm_1(G) = G /\ (forall k, k > 0 -> 'Mho^k(G) = <[x ^+ (2 ^ k)]>), [/\ yG :|: xyG = G :\: X, [disjoint yG & xyG] & forall M, maximal M G = pred3 X My Mxy M] & if n == 2 then (2.-abelem G : Prop) else [/\ 'Z(G) = <[x ^+ r]>, #|'Z(G)| = 2, My \isog 'D_q, Mxy \isog 'D_q & forall U, cyclic U -> U \subset G -> #|G : U| = 2 -> U = X]]. Proof. move=> n_gt1 genG isoG; have [def2q def2r ltqm ltrq] := def2qr n_gt1. have [oG Gx ox X'y] := genG; rewrite -/m -/q -/X in oG ox X'y. case/extremal_generators_facts: genG; rewrite -/X // => pG maxX nsXG defXY nXY. have [sXG nXG]:= andP nsXG; have [Gy notXy]:= setDP X'y. have ox2: #[x ^+ 2] = r by rewrite orderXdiv ox -def2r ?dvdn_mulr ?mulKn. have oxr: #[x ^+ r] = 2 by rewrite orderXdiv ox -def2r ?dvdn_mull ?mulnK. have [[u v] [_ Gu ou U'v] [ov uv]] := generators_2dihedral n_gt1 isoG. have defUv: <[u]> :* v = G :\: <[u]>. apply: rcoset_index2; rewrite -?divgS ?cycle_subG //. by rewrite oG -orderE ou -def2q mulnK. have invUV: {in <[u]> & <[u]> :* v, forall z t, z ^ t = z^-1}. move=> z t; case/cycleP=> i ->; case/rcosetP=> z'; case/cycleP=> j -> ->{z t}. by rewrite conjgM {2}/conjg commuteX2 // mulKg conjXg uv expgVn. have oU': {in <[u]> :* v, forall t, #[t] = 2}. move=> t Uvt; apply: nt_prime_order => //; last first. by case: eqP Uvt => // ->; rewrite defUv !inE group1. case/rcosetP: Uvt => z Uz ->{t}; rewrite expgS {1}(conjgC z) -mulgA. by rewrite invUV ?rcoset_refl // mulKg -(expgS v 1) -ov expg_order. have defU: n > 2 -> {in G, forall z, #[z] = q -> <[z]> = <[u]>}. move=> n_gt2 z Gz oz; apply/eqP; rewrite eqEcard -!orderE oz cycle_subG. apply: contraLR n_gt2; rewrite ou leqnn andbT -(ltn_predK n_gt1) => notUz. by rewrite ltnS -(@ltn_exp2l 2) // -/q -oz oU' // defUv inE notUz. have n2_abelG: (n > 2) || 2.-abelem G. rewrite ltn_neqAle eq_sym n_gt1; case: eqP => //= n2. apply/abelemP=> //; split=> [|z Gz]. by apply: (p2group_abelian pG); rewrite oG pfactorK ?n2. case Uz: (z \in <[u]>); last by rewrite -expg_mod_order oU' // defUv inE Uz. apply/eqP; rewrite -order_dvdn (dvdn_trans (order_dvdG Uz)) // -orderE. by rewrite ou /q n2. have{oU'} oX': {in G :\: X, forall t, #[t] = 2}. have [n_gt2 | abelG] := orP n2_abelG; first by rewrite [X]defU // -defUv. move=> t /setDP[Gt notXt]; apply: nt_prime_order (group1_contra notXt) => //. by case/abelemP: abelG => // _ ->. have{invUV} invXX': {in X & G :\: X, forall z t, z ^ t = z^-1}. have [n_gt2 | abelG] := orP n2_abelG; first by rewrite [X]defU // -defUv. have [//|cGG oG2] := abelemP _ abelG. move=> t z Xt /setDP[Gz _]; apply/eqP; rewrite eq_sym eq_invg_mul. by rewrite /conjg -(centsP cGG z) // ?mulKg ?[t * t]oG2 ?(subsetP sXG). have nXiG k: G \subset 'N(<[x ^+ k]>). apply: char_norm_trans nXG. by rewrite cycle_subgroup_char // cycle_subG mem_cycle. have memL i: x ^+ (2 ^ i) \in 'L_i.+1(G). elim: i => // i IHi; rewrite -groupV expnSr expgM invMg. by rewrite -{2}(invXX' _ y) ?mem_cycle ?cycle_id ?mem_commg. have defG': G^`(1) = <[x ^+ 2]>. apply/eqP; rewrite eqEsubset cycle_subG (memL 1%N) ?der1_min //=. rewrite (p2group_abelian (quotient_pgroup _ pG)) ?card_quotient //=. rewrite -divgS ?cycle_subG ?groupX // oG -orderE ox2. by rewrite -def2q -def2r mulnA mulnK. have defG1: 'Mho^1(G) = <[x ^+ 2]>. apply/eqP; rewrite (MhoE _ pG) eqEsubset !gen_subG sub1set andbC. rewrite mem_gen; last exact: imset_f. apply/subsetP=> z2; case/imsetP=> z Gz ->{z2}. case Xz: (z \in X); last by rewrite -{1}(oX' z) ?expg_order ?group1 // inE Xz. by case/cycleP: Xz => i ->; rewrite expgAC mem_cycle. have defPhi: 'Phi(G) = <[x ^+ 2]>. by rewrite (Phi_joing pG) defG' defG1 (joing_idPl _). have def_tG: {in G :\: X, forall t, t ^: G = <[x ^+ 2]> :* t}. move=> t X't; have [Gt notXt] := setDP X't. have defJt: {in X, forall z, t ^ z = z ^- 2 * t}. move=> z Xz; rewrite /= invMg -mulgA (conjgC _ t). by rewrite (invXX' _ t) ?groupV ?invgK. have defGt: X * <[t]> = G by rewrite (mulg_normal_maximal nsXG) ?cycle_subG. apply/setP=> tz; apply/imsetP/rcosetP=> [[t'z] | [z]]. rewrite -defGt -normC ?cycle_subG ?(subsetP nXG) //. case/imset2P=> _ z /cycleP[j ->] Xz -> -> {tz t'z}. exists (z ^- 2); last by rewrite conjgM {2}/conjg commuteX // mulKg defJt. case/cycleP: Xz => i ->{z}. by rewrite groupV -expgM mulnC expgM mem_cycle. case/cycleP=> i -> -> {z tz}; exists (x ^- i); first by rewrite groupV groupX. by rewrite defJt ?groupV ?mem_cycle // expgVn invgK expgAC. have defMt: {in G :\: X, forall t, <[x ^+ 2]> ><| <[t]> = <<t ^: G>>}. move=> t X't; have [Gt notXt] := setDP X't. rewrite sdprodEY ?cycle_subG ?(subsetP (nXiG 2)) //; first 1 last. rewrite setIC prime_TIg -?orderE ?oX' // cycle_subG. by apply: contra notXt; apply: subsetP; rewrite cycleX. apply/eqP; have: t \in <<t ^: G>> by rewrite mem_gen ?class_refl. rewrite def_tG // eqEsubset join_subG !cycle_subG !gen_subG => tGt. rewrite tGt -(groupMr _ tGt) mem_gen ?mem_mulg ?cycle_id ?set11 //=. by rewrite mul_subG ?joing_subl // -gen_subG joing_subr. have oMt: {in G :\: X, forall t, #|<<t ^: G>>| = q}. move=> t X't /=; rewrite -(sdprod_card (defMt t X't)) -!orderE ox2 oX' //. by rewrite mulnC. have sMtG: {in G :\: X, forall t, <<t ^: G>> \subset G}. by move=> t; case/setDP=> Gt _; rewrite gen_subG class_subG. have maxMt: {in G :\: X, forall t, maximal <<t ^: G>> G}. move=> t X't /=; rewrite p_index_maximal -?divgS ?sMtG ?oMt //. by rewrite oG -def2q mulnK. have X'xy: x * y \in G :\: X by rewrite !inE !groupMl ?cycle_id ?notXy. have ti_yG_xyG: [disjoint yG & xyG]. apply/pred0P=> t; rewrite /= /yG /xyG !def_tG //; apply/andP=> [[yGt]]. rewrite rcoset_sym (rcoset_eqP yGt) mem_rcoset mulgK; move/order_dvdG. by rewrite -orderE ox2 ox gtnNdvd. have s_tG_X': {in G :\: X, forall t, t ^: G \subset G :\: X}. by move=> t X't /=; rewrite class_sub_norm // normsD ?normG. have defX': yG :|: xyG = G :\: X. apply/eqP; rewrite eqEcard subUset !s_tG_X' //= -(leq_add2l q) -{1}ox orderE. rewrite -/X -{1}(setIidPr sXG) cardsID oG -def2q mul2n -addnn leq_add2l. rewrite -(leq_add2r #|yG :&: xyG|) cardsUI disjoint_setI0 // cards0 addn0. by rewrite /yG /xyG !def_tG // !card_rcoset addnn -mul2n -orderE ox2 def2r. split. - by rewrite ?sdprodE // setIC // prime_TIg ?cycle_subG // -orderE ?oX'. - rewrite defG'; split=> //. apply/eqP; rewrite eqn_leq (leq_trans (nil_class_pgroup pG)); last first. by rewrite oG pfactorK // geq_max leqnn -(subnKC n_gt1). rewrite -(subnKC n_gt1) subn2 ltnNge. rewrite (sameP (lcn_nil_classP _ (pgroup_nil pG)) eqP). by apply/trivgPn; exists (x ^+ r); rewrite ?memL // -order_gt1 oxr. - split; last exact: extend_cyclic_Mho. have sX'G1: {subset G :\: X <= 'Ohm_1(G)}. move=> t X't; have [Gt _] := setDP X't. by rewrite (OhmE 1 pG) mem_gen // !inE Gt -(oX' t) //= expg_order. apply/eqP; rewrite eqEsubset Ohm_sub -{1}defXY mulG_subG !cycle_subG. by rewrite -(groupMr _ (sX'G1 y X'y)) !sX'G1. - split=> //= H; apply/idP/idP=> [maxH |]; last first. by case/or3P=> /eqP->; rewrite ?maxMt. have [sHG nHG]:= andP (p_maximal_normal pG maxH). have oH: #|H| = q. apply: double_inj; rewrite -muln2 -(p_maximal_index pG maxH) Lagrange //. by rewrite oG -mul2n. rewrite !(eq_sym (gval H)) -eq_sym !eqEcard oH -orderE ox !oMt // !leqnn. case sHX: (H \subset X) => //=; case/subsetPn: sHX => t Ht notXt. have: t \in yG :|: xyG by rewrite defX' inE notXt (subsetP sHG). rewrite !andbT !gen_subG /yG /xyG. by case/setUP; move/class_eqP <-; rewrite !class_sub_norm ?Ht ?orbT. rewrite eqn_leq n_gt1; case: leqP n2_abelG => //= n_gt2 _. have ->: 'Z(G) = <[x ^+ r]>. apply/eqP; rewrite eqEcard andbC -orderE oxr -{1}(setIidPr (center_sub G)). rewrite cardG_gt1 /= meet_center_nil ?(pgroup_nil pG) //; last first. by rewrite -cardG_gt1 oG (leq_trans _ ltqm). apply/subsetP=> t; case/setIP=> Gt cGt. case X't: (t \in G :\: X). move/eqP: (invXX' _ _ (cycle_id x) X't). rewrite /conjg -(centP cGt) // mulKg eq_sym eq_invg_mul -order_eq1 ox2. by rewrite (eqn_exp2l _ 0) // -(subnKC n_gt2). move/idPn: X't; rewrite inE Gt andbT negbK => Xt. have:= Ohm_p_cycle 1 (mem_p_elt pG Gx); rewrite ox pfactorK // subn1 => <-. rewrite (OhmE _ (pgroupS sXG pG)) mem_gen // !inE Xt /=. by rewrite -eq_invg_mul -(invXX' _ y) // /conjg (centP cGt) // mulKg. have isoMt: {in G :\: X, forall t, <<t ^: G>> \isog 'D_q}. have n1_gt1: n.-1 > 1 by rewrite -(subnKC n_gt2). move=> t X't /=; rewrite isogEcard card_2dihedral ?oMt // leqnn andbT. rewrite Grp_2dihedral //; apply/existsP; exists (x ^+ 2, t) => /=. have [_ <- nX2T _] := sdprodP (defMt t X't); rewrite norm_joinEr //. rewrite -/q -/r !xpair_eqE eqxx -expgM def2r -ox -{1}(oX' t X't). by rewrite !expg_order !eqxx /= invXX' ?mem_cycle. rewrite !isoMt //; split=> // C; case/cyclicP=> z ->{C} sCG iCG. rewrite [X]defU // defU -?cycle_subG //. by apply: double_inj; rewrite -muln2 -iCG Lagrange // oG -mul2n. Qed. (* HERE BOOM *) Theorem quaternion_structure : n > 2 -> extremal_generators G 2 n (x, y) -> G \isog 'Q_m -> [/\ [/\ pprod X Y = G, {in G :\: X, forall t, #[t] = 4} & {in X & G :\: X, forall z t, z ^ t = z^-1}], [/\ G ^`(1) = <[x ^+ 2]>, 'Phi(G) = G ^`(1), #|G^`(1)| = r & nil_class G = n.-1], [/\ 'Z(G) = <[x ^+ r]>, #|'Z(G)| = 2, forall u, u \in G -> #[u] = 2 -> u = x ^+ r, 'Ohm_1(G) = <[x ^+ r]> /\ 'Ohm_2(G) = G & forall k, k > 0 -> 'Mho^k(G) = <[x ^+ (2 ^ k)]>], [/\ yG :|: xyG = G :\: X /\ [disjoint yG & xyG] & forall M, maximal M G = pred3 X My Mxy M] & n > 3 -> [/\ My \isog 'Q_q, Mxy \isog 'Q_q & forall U, cyclic U -> U \subset G -> #|G : U| = 2 -> U = X]]. Proof. move=> n_gt2 genG isoG; have [def2q def2r ltqm ltrq] := def2qr (ltnW n_gt2). have [oG Gx ox X'y] := genG; rewrite -/m -/q -/X in oG ox X'y. case/extremal_generators_facts: genG; rewrite -/X // => pG maxX nsXG defXY nXY. have [sXG nXG]:= andP nsXG; have [Gy notXy]:= setDP X'y. have oxr: #[x ^+ r] = 2 by rewrite orderXdiv ox -def2r ?dvdn_mull ?mulnK. have ox2: #[x ^+ 2] = r by rewrite orderXdiv ox -def2r ?dvdn_mulr ?mulKn. have [[u v] [_ Gu ou U'v] [ov v2 uv]] := generators_quaternion n_gt2 isoG. have defUv: <[u]> :* v = G :\: <[u]>. apply: rcoset_index2; rewrite -?divgS ?cycle_subG //. by rewrite oG -orderE ou -def2q mulnK. have invUV: {in <[u]> & <[u]> :* v, forall z t, z ^ t = z^-1}. move=> z t; case/cycleP=> i ->; case/rcosetP=> ?; case/cycleP=> j -> ->{z t}. by rewrite conjgM {2}/conjg commuteX2 // mulKg conjXg uv expgVn. have U'2: {in <[u]> :* v, forall t, t ^+ 2 = u ^+ r}. move=> t; case/rcosetP=> z Uz ->; rewrite expgS {1}(conjgC z) -mulgA. by rewrite invUV ?rcoset_refl // mulKg -(expgS v 1) v2. have our: #[u ^+ r] = 2 by rewrite orderXdiv ou -/q -def2r ?dvdn_mull ?mulnK. have def_ur: {in G, forall t, #[t] = 2 -> t = u ^+ r}. move=> t Gt /= ot; case Ut: (t \in <[u]>); last first. move/eqP: ot; rewrite eqn_dvd order_dvdn -order_eq1 U'2 ?our //. by rewrite defUv inE Ut. have p2u: 2.-elt u by rewrite /p_elt ou pnatX. have: t \in 'Ohm_1(<[u]>). by rewrite (OhmE _ p2u) mem_gen // !inE Ut -order_dvdn ot. rewrite (Ohm_p_cycle _ p2u) ou pfactorK // subn1 -/r cycle_traject our !inE. by rewrite -order_eq1 ot /= mulg1; move/eqP. have defU: n > 3 -> {in G, forall z, #[z] = q -> <[z]> = <[u]>}. move=> n_gt3 z Gz oz; apply/eqP; rewrite eqEcard -!orderE oz cycle_subG. rewrite ou leqnn andbT; apply: contraLR n_gt3 => notUz. rewrite -(ltn_predK n_gt2) ltnS -(@ltn_exp2l 2) // -/q -oz. by rewrite (@orderXprime _ 2 2) // U'2 // defUv inE notUz. have def_xr: x ^+ r = u ^+ r by apply: def_ur; rewrite ?groupX. have X'2: {in G :\: X, forall t, t ^+ 2 = u ^+ r}. case: (ltngtP n 3) => [|n_gt3|n3 t]; first by rewrite ltnNge n_gt2. by rewrite /X defU // -defUv. case/setDP=> Gt notXt. case Ut: (t \in <[u]>); last by rewrite U'2 // defUv inE Ut. rewrite [t ^+ 2]def_ur ?groupX //. have:= order_dvdG Ut; rewrite -orderE ou /q n3 dvdn_divisors ?inE //=. rewrite order_eq1 (negbTE (group1_contra notXt)) /=. case/pred2P=> oz; last by rewrite orderXdiv oz. by rewrite [t]def_ur // -def_xr mem_cycle in notXt. have oX': {in G :\: X, forall z, #[z] = 4}. by move=> t X't /=; rewrite (@orderXprime _ 2 2) // X'2. have defZ: 'Z(G) = <[x ^+ r]>. apply/eqP; rewrite eqEcard andbC -orderE oxr -{1}(setIidPr (center_sub G)). rewrite cardG_gt1 /= meet_center_nil ?(pgroup_nil pG) //; last first. by rewrite -cardG_gt1 oG (leq_trans _ ltqm). apply/subsetP=> z; case/setIP=> Gz cGz; have [Gv _]:= setDP U'v. case Uvz: (z \in <[u]> :* v). move/eqP: (invUV _ _ (cycle_id u) Uvz). rewrite /conjg -(centP cGz) // mulKg eq_sym eq_invg_mul -(order_dvdn _ 2). by rewrite ou pfactor_dvdn // -(subnKC n_gt2). move/idPn: Uvz; rewrite defUv inE Gz andbT negbK def_xr => Uz. have p_u: 2.-elt u := mem_p_elt pG Gu. suff: z \in 'Ohm_1(<[u]>) by rewrite (Ohm_p_cycle 1 p_u) ou pfactorK // subn1. rewrite (OhmE _ p_u) mem_gen // !inE Uz /= -eq_invg_mul. by rewrite -(invUV _ v) ?rcoset_refl // /conjg (centP cGz) ?mulKg. have{invUV} invXX': {in X & G :\: X, forall z t, z ^ t = z^-1}. case: (ltngtP n 3) => [|n_gt3|n3 t z Xt]; first by rewrite ltnNge n_gt2. by rewrite /X defU // -defUv. case/setDP=> Gz notXz; rewrite /q /r n3 /= in oxr ox. suff xz: x ^ z = x^-1 by case/cycleP: Xt => i ->; rewrite conjXg xz expgVn. have: x ^ z \in X by rewrite memJ_norm ?cycle_id ?(subsetP nXG). rewrite invg_expg /X cycle_traject ox !inE /= !mulg1 -order_eq1 orderJ ox /=. case/or3P; move/eqP=> //; last by move/(congr1 order); rewrite orderJ ox oxr. move/conjg_fixP; rewrite (sameP commgP cent1P) cent1C -cent_cycle -/X => cXz. have defXz: X * <[z]> = G by rewrite (mulg_normal_maximal nsXG) ?cycle_subG. have: z \in 'Z(G) by rewrite inE Gz -defXz centM inE cXz cent_cycle cent1id. by rewrite defZ => Xr_z; rewrite (subsetP (cycleX x r)) in notXz. have nXiG k: G \subset 'N(<[x ^+ k]>). apply: char_norm_trans nXG. by rewrite cycle_subgroup_char // cycle_subG mem_cycle. have memL i: x ^+ (2 ^ i) \in 'L_i.+1(G). elim: i => // i IHi; rewrite -groupV expnSr expgM invMg. by rewrite -{2}(invXX' _ y) ?mem_cycle ?cycle_id ?mem_commg. have defG': G^`(1) = <[x ^+ 2]>. apply/eqP; rewrite eqEsubset cycle_subG (memL 1%N) ?der1_min //=. rewrite (p2group_abelian (quotient_pgroup _ pG)) ?card_quotient //=. rewrite -divgS ?cycle_subG ?groupX // oG -orderE ox2. by rewrite -def2q -def2r mulnA mulnK. have defG1: 'Mho^1(G) = <[x ^+ 2]>. apply/eqP; rewrite (MhoE _ pG) eqEsubset !gen_subG sub1set andbC. rewrite mem_gen; last exact: imset_f. apply/subsetP=> z2; case/imsetP=> z Gz ->{z2}. case Xz: (z \in X). by case/cycleP: Xz => i ->; rewrite -expgM mulnC expgM mem_cycle. rewrite (X'2 z) ?inE ?Xz // -def_xr. by rewrite /r -(subnKC n_gt2) expnS expgM mem_cycle. have defPhi: 'Phi(G) = <[x ^+ 2]>. by rewrite (Phi_joing pG) defG' defG1 (joing_idPl _). have def_tG: {in G :\: X, forall t, t ^: G = <[x ^+ 2]> :* t}. move=> t X't; have [Gt notXt] := setDP X't. have defJt: {in X, forall z, t ^ z = z ^- 2 * t}. move=> z Xz; rewrite /= invMg -mulgA (conjgC _ t). by rewrite (invXX' _ t) ?groupV ?invgK. have defGt: X * <[t]> = G by rewrite (mulg_normal_maximal nsXG) ?cycle_subG. apply/setP=> tz; apply/imsetP/rcosetP=> [[t'z] | [z]]. rewrite -defGt -normC ?cycle_subG ?(subsetP nXG) //. case/imset2P=> t' z; case/cycleP=> j -> Xz -> -> {tz t'z t'}. exists (z ^- 2); last by rewrite conjgM {2}/conjg commuteX // mulKg defJt. case/cycleP: Xz => i ->{z}. by rewrite groupV -expgM mulnC expgM mem_cycle. case/cycleP=> i -> -> {z tz}; exists (x ^- i); first by rewrite groupV groupX. by rewrite defJt ?groupV ?mem_cycle // expgVn invgK -!expgM mulnC. have defMt: {in G :\: X, forall t, <[x ^+ 2]> <*> <[t]> = <<t ^: G>>}. move=> t X't; have [Gt notXt] := setDP X't. apply/eqP; have: t \in <<t ^: G>> by rewrite mem_gen ?class_refl. rewrite def_tG // eqEsubset join_subG !cycle_subG !gen_subG => tGt. rewrite tGt -(groupMr _ tGt) mem_gen ?mem_mulg ?cycle_id ?set11 //=. by rewrite mul_subG ?joing_subl // -gen_subG joing_subr. have sMtG: {in G :\: X, forall t, <<t ^: G>> \subset G}. by move=> t; case/setDP=> Gt _; rewrite gen_subG class_subG. have oMt: {in G :\: X, forall t, #|<<t ^: G>>| = q}. move=> t X't; have [Gt notXt] := setDP X't. rewrite -defMt // -(Lagrange (joing_subl _ _)) -orderE ox2 -def2r mulnC. congr (_ * r)%N; rewrite -card_quotient /=; last first. by rewrite defMt // (subset_trans _ (nXiG 2)) ?sMtG. rewrite joingC quotientYidr ?(subset_trans _ (nXiG 2)) ?cycle_subG //. rewrite quotient_cycle ?(subsetP (nXiG 2)) //= -defPhi. rewrite -orderE (abelem_order_p (Phi_quotient_abelem pG)) ?mem_quotient //. apply: contraNneq notXt; move/coset_idr; move/implyP=> /=. by rewrite defPhi ?(subsetP (nXiG 2)) //; apply: subsetP; apply: cycleX. have maxMt: {in G :\: X, forall t, maximal <<t ^: G>> G}. move=> t X't; rewrite /= p_index_maximal -?divgS ?sMtG ?oMt //. by rewrite oG -def2q mulnK. have X'xy: x * y \in G :\: X by rewrite !inE !groupMl ?cycle_id ?notXy. have ti_yG_xyG: [disjoint yG & xyG]. apply/pred0P=> t; rewrite /= /yG /xyG !def_tG //; apply/andP=> [[yGt]]. rewrite rcoset_sym (rcoset_eqP yGt) mem_rcoset mulgK; move/order_dvdG. by rewrite -orderE ox2 ox gtnNdvd. have s_tG_X': {in G :\: X, forall t, t ^: G \subset G :\: X}. by move=> t X't /=; rewrite class_sub_norm // normsD ?normG. have defX': yG :|: xyG = G :\: X. apply/eqP; rewrite eqEcard subUset !s_tG_X' //= -(leq_add2l q) -{1}ox orderE. rewrite -/X -{1}(setIidPr sXG) cardsID oG -def2q mul2n -addnn leq_add2l. rewrite -(leq_add2r #|yG :&: xyG|) cardsUI disjoint_setI0 // cards0 addn0. by rewrite /yG /xyG !def_tG // !card_rcoset addnn -mul2n -orderE ox2 def2r. rewrite pprodE //; split=> // [|||n_gt3]. - rewrite defG'; split=> //; apply/eqP; rewrite eqn_leq. rewrite (leq_trans (nil_class_pgroup pG)); last first. by rewrite oG pfactorK // -(subnKC n_gt2). rewrite -(subnKC (ltnW n_gt2)) subn2 ltnNge. rewrite (sameP (lcn_nil_classP _ (pgroup_nil pG)) eqP). by apply/trivgPn; exists (x ^+ r); rewrite ?memL // -order_gt1 oxr. - rewrite {2}def_xr defZ; split=> //; last exact: extend_cyclic_Mho. split; apply/eqP; last first. have sX'G2: {subset G :\: X <= 'Ohm_2(G)}. move=> z X'z; have [Gz _] := setDP X'z. by rewrite (OhmE 2 pG) mem_gen // !inE Gz -order_dvdn oX'. rewrite eqEsubset Ohm_sub -{1}defXY mulG_subG !cycle_subG. by rewrite -(groupMr _ (sX'G2 y X'y)) !sX'G2. rewrite eqEsubset (OhmE 1 pG) cycle_subG gen_subG andbC. rewrite mem_gen ?inE ?groupX -?order_dvdn ?oxr //=. apply/subsetP=> t; case/setIP=> Gt; rewrite inE -order_dvdn /=. rewrite dvdn_divisors ?inE //= order_eq1. case/pred2P=> [->|]; first exact: group1. by move/def_ur=> -> //; rewrite def_xr cycle_id. - split=> //= H; apply/idP/idP=> [maxH |]; last first. by case/or3P=> /eqP->; rewrite ?maxMt. have [sHG nHG]:= andP (p_maximal_normal pG maxH). have oH: #|H| = q. apply: double_inj; rewrite -muln2 -(p_maximal_index pG maxH) Lagrange //. by rewrite oG -mul2n. rewrite !(eq_sym (gval H)) -eq_sym !eqEcard oH -orderE ox !oMt // !leqnn. case sHX: (H \subset X) => //=; case/subsetPn: sHX => z Hz notXz. have: z \in yG :|: xyG by rewrite defX' inE notXz (subsetP sHG). rewrite !andbT !gen_subG /yG /xyG. by case/setUP=> /class_eqP <-; rewrite !class_sub_norm ?Hz ?orbT. have isoMt: {in G :\: X, forall z, <<z ^: G>> \isog 'Q_q}. have n1_gt2: n.-1 > 2 by rewrite -(subnKC n_gt3). move=> z X'z /=; rewrite isogEcard card_quaternion ?oMt // leqnn andbT. rewrite Grp_quaternion //; apply/existsP; exists (x ^+ 2, z) => /=. rewrite defMt // -/q -/r !xpair_eqE -!expgM def2r -order_dvdn ox dvdnn. rewrite -expnS prednK; last by rewrite -subn2 subn_gt0. by rewrite X'2 // def_xr !eqxx /= invXX' ?mem_cycle. rewrite !isoMt //; split=> // C; case/cyclicP=> z ->{C} sCG iCG. rewrite [X]defU // defU -?cycle_subG //. by apply: double_inj; rewrite -muln2 -iCG Lagrange // oG -mul2n. Qed. Theorem semidihedral_structure : n > 3 -> extremal_generators G 2 n (x, y) -> G \isog 'SD_m -> #[y] = 2 -> [/\ [/\ X ><| Y = G, #[x * y] = 4 & {in X & G :\: X, forall z t, z ^ t = z ^+ r.-1}], [/\ G ^`(1) = <[x ^+ 2]>, 'Phi(G) = G ^`(1), #|G^`(1)| = r & nil_class G = n.-1], [/\ 'Z(G) = <[x ^+ r]>, #|'Z(G)| = 2, 'Ohm_1(G) = My /\ 'Ohm_2(G) = G & forall k, k > 0 -> 'Mho^k(G) = <[x ^+ (2 ^ k)]>], [/\ yG :|: xyG = G :\: X /\ [disjoint yG & xyG] & forall H, maximal H G = pred3 X My Mxy H] & [/\ My \isog 'D_q, Mxy \isog 'Q_q & forall U, cyclic U -> U \subset G -> #|G : U| = 2 -> U = X]]. Proof. move=> n_gt3 genG isoG oy. have [def2q def2r ltqm ltrq] := def2qr (ltnW (ltnW n_gt3)). have [oG Gx ox X'y] := genG; rewrite -/m -/q -/X in oG ox X'y. case/extremal_generators_facts: genG; rewrite -/X // => pG maxX nsXG defXY nXY. have [sXG nXG]:= andP nsXG; have [Gy notXy]:= setDP X'y. have ox2: #[x ^+ 2] = r by rewrite orderXdiv ox -def2r ?dvdn_mulr ?mulKn. have oxr: #[x ^+ r] = 2 by rewrite orderXdiv ox -def2r ?dvdn_mull ?mulnK. have [[u v] [_ Gu ou U'v] [ov uv]] := generators_semidihedral n_gt3 isoG. have defUv: <[u]> :* v = G :\: <[u]>. apply: rcoset_index2; rewrite -?divgS ?cycle_subG //. by rewrite oG -orderE ou -def2q mulnK. have invUV: {in <[u]> & <[u]> :* v, forall z t, z ^ t = z ^+ r.-1}. move=> z t; case/cycleP=> i ->; case/rcosetP=> ?; case/cycleP=> j -> ->{z t}. by rewrite conjgM {2}/conjg commuteX2 // mulKg conjXg uv -!expgM mulnC. have [vV yV]: v^-1 = v /\ y^-1 = y by rewrite !invg_expg ov oy. have defU: {in G, forall z, #[z] = q -> <[z]> = <[u]>}. move=> z Gz /= oz; apply/eqP; rewrite eqEcard -!orderE oz ou leqnn andbT. apply: contraLR (n_gt3) => notUz; rewrite -leqNgt -(ltn_predK n_gt3) ltnS. rewrite -(@dvdn_Pexp2l 2) // -/q -{}oz order_dvdn expgM (expgS z). have{Gz notUz} [z' Uz' ->{z}]: exists2 z', z' \in <[u]> & z = z' * v. by apply/rcosetP; rewrite defUv inE -cycle_subG notUz Gz. rewrite {2}(conjgC z') invUV ?rcoset_refl // mulgA -{2}vV mulgK -expgS. by rewrite prednK // -expgM mulnC def2r -order_dvdn /q -ou order_dvdG. have{invUV} invXX': {in X & G :\: X, forall z t, z ^ t = z ^+ r.-1}. by rewrite /X defU -?defUv. have xy2: (x * y) ^+ 2 = x ^+ r. rewrite expgS {2}(conjgC x) invXX' ?cycle_id // mulgA -{2}yV mulgK -expgS. by rewrite prednK. have oxy: #[x * y] = 4 by rewrite (@orderXprime _ 2 2) ?xy2. have r_gt2: r > 2 by rewrite (ltn_exp2l 1) // -(subnKC n_gt3). have coXr1: coprime #[x] (2 ^ (n - 3)).-1. rewrite ox coprimeXl // -(@coprime_pexpl (n - 3)) ?coprimenP ?subn_gt0 //. by rewrite expn_gt0. have def2r1: (2 * (2 ^ (n - 3)).-1).+1 = r.-1. rewrite -!subn1 mulnBr -expnS [_.+1]subnSK ?(ltn_exp2l 0) //. by rewrite /r -(subnKC n_gt3). have defZ: 'Z(G) = <[x ^+ r]>. apply/eqP; rewrite eqEcard andbC -orderE oxr -{1}(setIidPr (center_sub G)). rewrite cardG_gt1 /= meet_center_nil ?(pgroup_nil pG) //; last first. by rewrite -cardG_gt1 oG (leq_trans _ ltqm). apply/subsetP=> z /setIP[Gz cGz]. case X'z: (z \in G :\: X). move/eqP: (invXX' _ _ (cycle_id x) X'z). rewrite /conjg -(centP cGz) // mulKg -def2r1 eq_mulVg1 expgS mulKg mulnC. rewrite -order_dvdn Gauss_dvdr // order_dvdn -order_eq1. by rewrite ox2 -(subnKC r_gt2). move/idPn: X'z; rewrite inE Gz andbT negbK => Xz. have:= Ohm_p_cycle 1 (mem_p_elt pG Gx); rewrite ox pfactorK // subn1 => <-. rewrite (OhmE _ (mem_p_elt pG Gx)) mem_gen // !inE Xz /=. rewrite -(expgK coXr1 Xz) -!expgM mulnCA -order_dvdn dvdn_mull //. rewrite mulnC order_dvdn -(inj_eq (mulgI z)) -expgS mulg1 def2r1. by rewrite -(invXX' z y) // /conjg (centP cGz) ?mulKg. have nXiG k: G \subset 'N(<[x ^+ k]>). apply: char_norm_trans nXG. by rewrite cycle_subgroup_char // cycle_subG mem_cycle. have memL i: x ^+ (2 ^ i) \in 'L_i.+1(G). elim: i => // i IHi; rewrite -(expgK coXr1 (mem_cycle _ _)) groupX //. rewrite -expgM expnSr -mulnA expgM -(mulKg (x ^+ (2 ^ i)) (_ ^+ _)). by rewrite -expgS def2r1 -(invXX' _ y) ?mem_cycle ?mem_commg. have defG': G^`(1) = <[x ^+ 2]>. apply/eqP; rewrite eqEsubset cycle_subG (memL 1%N) ?der1_min //=. rewrite (p2group_abelian (quotient_pgroup _ pG)) ?card_quotient //=. rewrite -divgS ?cycle_subG ?groupX // oG -orderE ox2. by rewrite -def2q -def2r mulnA mulnK. have defG1: 'Mho^1(G) = <[x ^+ 2]>. apply/eqP; rewrite (MhoE _ pG) eqEsubset !gen_subG sub1set andbC. rewrite mem_gen; last exact: imset_f. apply/subsetP=> z2; case/imsetP=> z Gz ->{z2}. case Xz: (z \in X). by case/cycleP: Xz => i ->; rewrite -expgM mulnC expgM mem_cycle. have{Xz Gz} [xi Xxi ->{z}]: exists2 xi, xi \in X & z = xi * y. have Uvy: y \in <[u]> :* v by rewrite defUv -(defU x). apply/rcosetP; rewrite /X defU // (rcoset_eqP Uvy) defUv. by rewrite inE -(defU x) ?Xz. rewrite expn1 expgS {2}(conjgC xi) -{2}[y]/(y ^+ 2.-1) -{1}oy -invg_expg. rewrite mulgA mulgK invXX' // -expgS prednK // /r -(subnKC n_gt3) expnS. by case/cycleP: Xxi => i ->; rewrite -expgM mulnCA expgM mem_cycle. have defPhi: 'Phi(G) = <[x ^+ 2]>. by rewrite (Phi_joing pG) defG' defG1 (joing_idPl _). have def_tG: {in G :\: X, forall t, t ^: G = <[x ^+ 2]> :* t}. move=> t X't; have [Gt notXt] := setDP X't. have defJt: {in X, forall z, t ^ z = z ^+ r.-2 * t}. move=> z Xz /=; rewrite -(mulKg z (z ^+ _)) -expgS -subn2. have X'tV: t^-1 \in G :\: X by rewrite inE !groupV notXt. by rewrite subnSK 1?ltnW // subn1 -(invXX' _ t^-1) // -mulgA -conjgCV. have defGt: X * <[t]> = G by rewrite (mulg_normal_maximal nsXG) ?cycle_subG. apply/setP=> tz; apply/imsetP/rcosetP=> [[t'z] | [z]]. rewrite -defGt -normC ?cycle_subG ?(subsetP nXG) //. case/imset2P=> t' z; case/cycleP=> j -> Xz -> -> {t' t'z tz}. exists (z ^+ r.-2); last first. by rewrite conjgM {2}/conjg commuteX // mulKg defJt. case/cycleP: Xz => i ->{z}. by rewrite -def2r1 -expgM mulnCA expgM mem_cycle. case/cycleP=> i -> -> {z tz}. exists (x ^+ (i * expg_invn X (2 ^ (n - 3)).-1)); first by rewrite groupX. rewrite defJt ?mem_cycle // -def2r1 -!expgM. by rewrite mulnAC mulnA mulnC muln2 !expgM expgK ?mem_cycle. have defMt: {in G :\: X, forall t, <[x ^+ 2]> <*> <[t]> = <<t ^: G>>}. move=> t X't; have [Gt notXt] := setDP X't. apply/eqP; have: t \in <<t ^: G>> by rewrite mem_gen ?class_refl. rewrite def_tG // eqEsubset join_subG !cycle_subG !gen_subG => tGt. rewrite tGt -(groupMr _ tGt) mem_gen ?mem_mulg ?cycle_id ?set11 //=. by rewrite mul_subG ?joing_subl // -gen_subG joing_subr. have sMtG: {in G :\: X, forall t, <<t ^: G>> \subset G}. by move=> t; case/setDP=> Gt _; rewrite gen_subG class_subG. have oMt: {in G :\: X, forall t, #|<<t ^: G>>| = q}. move=> t X't; have [Gt notXt] := setDP X't. rewrite -defMt // -(Lagrange (joing_subl _ _)) -orderE ox2 -def2r mulnC. congr (_ * r)%N; rewrite -card_quotient /=; last first. by rewrite defMt // (subset_trans _ (nXiG 2)) ?sMtG. rewrite joingC quotientYidr ?(subset_trans _ (nXiG 2)) ?cycle_subG //. rewrite quotient_cycle ?(subsetP (nXiG 2)) //= -defPhi -orderE. rewrite (abelem_order_p (Phi_quotient_abelem pG)) ?mem_quotient //. apply: contraNneq notXt; move/coset_idr; move/implyP=> /=. by rewrite /= defPhi (subsetP (nXiG 2)) //; apply: subsetP; apply: cycleX. have maxMt: {in G :\: X, forall t, maximal <<t ^: G>> G}. move=> t X't /=; rewrite p_index_maximal -?divgS ?sMtG ?oMt //. by rewrite oG -def2q mulnK. have X'xy: x * y \in G :\: X by rewrite !inE !groupMl ?cycle_id ?notXy. have ti_yG_xyG: [disjoint yG & xyG]. apply/pred0P=> t; rewrite /= /yG /xyG !def_tG //; apply/andP=> [[yGt]]. rewrite rcoset_sym (rcoset_eqP yGt) mem_rcoset mulgK; move/order_dvdG. by rewrite -orderE ox2 ox gtnNdvd. have s_tG_X': {in G :\: X, forall t, t ^: G \subset G :\: X}. by move=> t X't /=; rewrite class_sub_norm // normsD ?normG. have defX': yG :|: xyG = G :\: X. apply/eqP; rewrite eqEcard subUset !s_tG_X' //= -(leq_add2l q) -{1}ox orderE. rewrite -/X -{1}(setIidPr sXG) cardsID oG -def2q mul2n -addnn leq_add2l. rewrite -(leq_add2r #|yG :&: xyG|) cardsUI disjoint_setI0 // cards0 addn0. by rewrite /yG /xyG !def_tG // !card_rcoset addnn -mul2n -orderE ox2 def2r. split. - by rewrite sdprodE // setIC prime_TIg ?cycle_subG // -orderE oy. - rewrite defG'; split=> //. apply/eqP; rewrite eqn_leq (leq_trans (nil_class_pgroup pG)); last first. by rewrite oG pfactorK // -(subnKC n_gt3). rewrite -(subnKC (ltnW (ltnW n_gt3))) subn2 ltnNge. rewrite (sameP (lcn_nil_classP _ (pgroup_nil pG)) eqP). by apply/trivgPn; exists (x ^+ r); rewrite ?memL // -order_gt1 oxr. - rewrite defZ; split=> //; last exact: extend_cyclic_Mho. split; apply/eqP; last first. have sX'G2: {subset G :\: X <= 'Ohm_2(G)}. move=> t X't; have [Gt _] := setDP X't; rewrite -defX' in X't. rewrite (OhmE 2 pG) mem_gen // !inE Gt -order_dvdn. by case/setUP: X't; case/imsetP=> z _ ->; rewrite orderJ ?oy ?oxy. rewrite eqEsubset Ohm_sub -{1}defXY mulG_subG !cycle_subG. by rewrite -(groupMr _ (sX'G2 y X'y)) !sX'G2. rewrite eqEsubset andbC gen_subG class_sub_norm ?gFnorm //. rewrite (OhmE 1 pG) mem_gen ?inE ?Gy -?order_dvdn ?oy // gen_subG /= -/My. apply/subsetP=> t /[!inE]; case/andP=> Gt t2. have pX := pgroupS sXG pG. case Xt: (t \in X). have: t \in 'Ohm_1(X) by rewrite (OhmE 1 pX) mem_gen // !inE Xt. apply: subsetP; rewrite (Ohm_p_cycle 1 pX) ox pfactorK //. rewrite -(subnKC n_gt3) expgM (subset_trans (cycleX _ _)) //. by rewrite /My -defMt ?joing_subl. have{Xt}: t \in yG :|: xyG by rewrite defX' inE Xt. case/setUP; first exact: mem_gen. by case/imsetP=> z _ def_t; rewrite -order_dvdn def_t orderJ oxy in t2. - split=> //= H; apply/idP/idP=> [maxH |]; last first. by case/or3P=> /eqP->; rewrite ?maxMt. have [sHG nHG]:= andP (p_maximal_normal pG maxH). have oH: #|H| = q. apply: double_inj; rewrite -muln2 -(p_maximal_index pG maxH) Lagrange //. by rewrite oG -mul2n. rewrite !(eq_sym (gval H)) -eq_sym !eqEcard oH -orderE ox !oMt // !leqnn. case sHX: (H \subset X) => //=; case/subsetPn: sHX => t Ht notXt. have: t \in yG :|: xyG by rewrite defX' inE notXt (subsetP sHG). rewrite !andbT !gen_subG /yG /xyG. by case/setUP=> /class_eqP <-; rewrite !class_sub_norm ?Ht ?orbT. have n1_gt2: n.-1 > 2 by [rewrite -(subnKC n_gt3)]; have n1_gt1 := ltnW n1_gt2. rewrite !isogEcard card_2dihedral ?card_quaternion ?oMt // leqnn !andbT. have invX2X': {in G :\: X, forall t, x ^+ 2 ^ t == x ^- 2}. move=> t X't; rewrite /= invXX' ?mem_cycle // eq_sym eq_invg_mul -expgS. by rewrite prednK // -order_dvdn ox2. rewrite Grp_2dihedral ?Grp_quaternion //; split=> [||C]. - apply/existsP; exists (x ^+ 2, y); rewrite /= defMt // !xpair_eqE. by rewrite -!expgM def2r -!order_dvdn ox oy dvdnn eqxx /= invX2X'. - apply/existsP; exists (x ^+ 2, x * y); rewrite /= defMt // !xpair_eqE. rewrite -!expgM def2r -order_dvdn ox xy2 dvdnn eqxx invX2X' //=. by rewrite andbT /r -(subnKC n_gt3). case/cyclicP=> z ->{C} sCG iCG; rewrite [X]defU // defU -?cycle_subG //. by apply: double_inj; rewrite -muln2 -iCG Lagrange // oG -mul2n. Qed. End ExtremalStructure. Section ExtremalClass. Variables (gT : finGroupType) (G : {group gT}). Inductive extremal_group_type := ModularGroup | Dihedral | SemiDihedral | Quaternion | NotExtremal. Definition index_extremal_group_type c : nat := match c with | ModularGroup => 0 | Dihedral => 1 | SemiDihedral => 2 | Quaternion => 3 | NotExtremal => 4 end. Definition enum_extremal_groups := [:: ModularGroup; Dihedral; SemiDihedral; Quaternion]. Lemma cancel_index_extremal_groups : cancel index_extremal_group_type (nth NotExtremal enum_extremal_groups). Proof. by case. Qed. Local Notation extgK := cancel_index_extremal_groups. #[export] HB.instance Definition _ := Countable.copy extremal_group_type (can_type extgK). Lemma bound_extremal_groups (c : extremal_group_type) : pickle c < 6. Proof. by case: c. Qed. Definition extremal_class (A : {set gT}) := let m := #|A| in let p := pdiv m in let n := logn p m in if (n > 1) && (A \isog 'D_(2 ^ n)) then Dihedral else if (n > 2) && (A \isog 'Q_(2 ^ n)) then Quaternion else if (n > 3) && (A \isog 'SD_(2 ^ n)) then SemiDihedral else if (n > 2) && (A \isog 'Mod_(p ^ n)) then ModularGroup else NotExtremal. Definition extremal2 A := extremal_class A \in behead enum_extremal_groups. Lemma dihedral_classP : extremal_class G = Dihedral <-> (exists2 n, n > 1 & G \isog 'D_(2 ^ n)). Proof. rewrite /extremal_class; split=> [ | [n n_gt1 isoG]]. by move: (logn _ _) => n; do 4?case: ifP => //; case/andP; exists n. rewrite (card_isog isoG) card_2dihedral // -(ltn_predK n_gt1) pdiv_pfactor //. by rewrite pfactorK // (ltn_predK n_gt1) n_gt1 isoG. Qed. Lemma quaternion_classP : extremal_class G = Quaternion <-> (exists2 n, n > 2 & G \isog 'Q_(2 ^ n)). Proof. rewrite /extremal_class; split=> [ | [n n_gt2 isoG]]. by move: (logn _ _) => n; do 4?case: ifP => //; case/andP; exists n. rewrite (card_isog isoG) card_quaternion // -(ltn_predK n_gt2) pdiv_pfactor //. rewrite pfactorK // (ltn_predK n_gt2) n_gt2 isoG. case: andP => // [[n_gt1 isoGD]]. have [[x y] genG [oy _ _]]:= generators_quaternion n_gt2 isoG. have [_ _ _ X'y] := genG. by case/dihedral2_structure: genG oy => // [[_ ->]]. Qed. Lemma semidihedral_classP : extremal_class G = SemiDihedral <-> (exists2 n, n > 3 & G \isog 'SD_(2 ^ n)). Proof. rewrite /extremal_class; split=> [ | [n n_gt3 isoG]]. by move: (logn _ _) => n; do 4?case: ifP => //; case/andP; exists n. rewrite (card_isog isoG) card_semidihedral //. rewrite -(ltn_predK n_gt3) pdiv_pfactor // pfactorK // (ltn_predK n_gt3) n_gt3. have [[x y] genG [oy _]]:= generators_semidihedral n_gt3 isoG. have [_ Gx _ X'y]:= genG. case: andP => [[n_gt1 isoGD]|_]. have [[_ oxy _ _] _ _ _]:= semidihedral_structure n_gt3 genG isoG oy. case: (dihedral2_structure n_gt1 genG isoGD) oxy => [[_ ->]] //. by rewrite !inE !groupMl ?cycle_id in X'y *. case: andP => // [[n_gt2 isoGQ]|]; last by rewrite isoG. by case: (quaternion_structure n_gt2 genG isoGQ) oy => [[_ ->]]. Qed. Lemma odd_not_extremal2 : odd #|G| -> ~~ extremal2 G. Proof. rewrite /extremal2 /extremal_class; case: logn => // n'. case: andP => [[n_gt1 isoG] | _]. by rewrite (card_isog isoG) card_2dihedral ?oddX. case: andP => [[n_gt2 isoG] | _]. by rewrite (card_isog isoG) card_quaternion ?oddX. case: andP => [[n_gt3 isoG] | _]. by rewrite (card_isog isoG) card_semidihedral ?oddX. by case: ifP. Qed. Lemma modular_group_classP : extremal_class G = ModularGroup <-> (exists2 p, prime p & exists2 n, n >= (p == 2) + 3 & G \isog 'Mod_(p ^ n)). Proof. rewrite /extremal_class; split=> [ | [p p_pr [n n_gt23 isoG]]]. move: (pdiv _) => p; set n := logn p _; do 4?case: ifP => //. case/andP=> n_gt2 isoG _ _; rewrite ltnW //= => not_isoG _. exists p; first by move: n_gt2; rewrite /n lognE; case (prime p). exists n => //; case: eqP => // p2; rewrite ltn_neqAle; case: eqP => // n3. by case/idP: not_isoG; rewrite p2 -n3 in isoG *. have n_gt2 := leq_trans (leq_addl _ _) n_gt23; have n_gt1 := ltnW n_gt2. have n_gt0 := ltnW n_gt1; have def_n := prednK n_gt0. have [[x y] genG mod_xy] := generators_modular_group p_pr n_gt2 isoG. case/modular_group_structure: (genG) => // _ _ [_ _ nil2G] _ _. have [oG _ _ _] := genG; have [oy _] := mod_xy. rewrite oG -def_n pdiv_pfactor // def_n pfactorK // n_gt1 n_gt2 {}isoG /=. case: (ltngtP p 2) => [|p_gt2|p2]; first by rewrite ltnNge prime_gt1. rewrite !(isog_sym G) !isogEcard card_2dihedral ?card_quaternion //= oG. rewrite leq_exp2r // leqNgt p_gt2 !andbF; case: and3P=> // [[n_gt3 _]]. by rewrite card_semidihedral // leq_exp2r // leqNgt p_gt2. rewrite p2 in genG oy n_gt23; rewrite n_gt23. have: nil_class G <> n.-1. by apply/eqP; rewrite neq_ltn -ltnS nil2G def_n n_gt23. case: ifP => [isoG | _]; first by case/dihedral2_structure: genG => // _ []. case: ifP => [isoG | _]; first by case/quaternion_structure: genG => // _ []. by case: ifP => // isoG; case/semidihedral_structure: genG => // _ []. Qed. End ExtremalClass. Theorem extremal2_structure (gT : finGroupType) (G : {group gT}) n x y : let cG := extremal_class G in let m := (2 ^ n)%N in let q := (2 ^ n.-1)%N in let r := (2 ^ n.-2)%N in let X := <[x]> in let yG := y ^: G in let xyG := (x * y) ^: G in let My := <<yG>> in let Mxy := <<xyG>> in extremal_generators G 2 n (x, y) -> extremal2 G -> (cG == SemiDihedral) ==> (#[y] == 2) -> [/\ [/\ (if cG == Quaternion then pprod X <[y]> else X ><| <[y]>) = G, if cG == SemiDihedral then #[x * y] = 4 else {in G :\: X, forall z, #[z] = (if cG == Dihedral then 2 else 4)}, if cG != Quaternion then True else {in G, forall z, #[z] = 2 -> z = x ^+ r} & {in X & G :\: X, forall t z, t ^ z = (if cG == SemiDihedral then t ^+ r.-1 else t^-1)}], [/\ G ^`(1) = <[x ^+ 2]>, 'Phi(G) = G ^`(1), #|G^`(1)| = r & nil_class G = n.-1], [/\ if n > 2 then 'Z(G) = <[x ^+ r]> /\ #|'Z(G)| = 2 else 2.-abelem G, 'Ohm_1(G) = (if cG == Quaternion then <[x ^+ r]> else if cG == SemiDihedral then My else G), 'Ohm_2(G) = G & forall k, k > 0 -> 'Mho^k(G) = <[x ^+ (2 ^ k)]>], [/\ yG :|: xyG = G :\: X, [disjoint yG & xyG] & forall H : {group gT}, maximal H G = (gval H \in pred3 X My Mxy)] & if n <= (cG == Quaternion) + 2 then True else [/\ forall U, cyclic U -> U \subset G -> #|G : U| = 2 -> U = X, if cG == Quaternion then My \isog 'Q_q else My \isog 'D_q, extremal_class My = (if cG == Quaternion then cG else Dihedral), if cG == Dihedral then Mxy \isog 'D_q else Mxy \isog 'Q_q & extremal_class Mxy = (if cG == Dihedral then cG else Quaternion)]]. Proof. move=> cG m q r X yG xyG My Mxy genG; have [oG _ _ _] := genG. have logG: logn (pdiv #|G|) #|G| = n by rewrite oG pfactorKpdiv. rewrite /extremal2 -/cG; do [rewrite {1}/extremal_class /= {}logG] in cG *. case: ifP => [isoG | _] in cG * => [_ _ /=|]. case/andP: isoG => n_gt1 isoG. have:= dihedral2_structure n_gt1 genG isoG; rewrite -/X -/q -/r -/yG -/xyG. case=> [[defG oX' invXX'] nilG [defOhm defMho] maxG defZ]. rewrite eqn_leq n_gt1 andbT add0n in defZ *; split=> //. split=> //; first by case: leqP defZ => // _ []. by apply/eqP; rewrite eqEsubset Ohm_sub -{1}defOhm Ohm_leq. case: leqP defZ => // n_gt2 [_ _ isoMy isoMxy defX]. have n1_gt1: n.-1 > 1 by rewrite -(subnKC n_gt2). by split=> //; apply/dihedral_classP; exists n.-1. case: ifP => [isoG | _] in cG * => [_ _ /=|]. case/andP: isoG => n_gt2 isoG; rewrite n_gt2 add1n. have:= quaternion_structure n_gt2 genG isoG; rewrite -/X -/q -/r -/yG -/xyG. case=> [[defG oX' invXX'] nilG [defZ oZ def2 [-> ->] defMho]]. case=> [[-> ->] maxG] isoM; split=> //. case: leqP isoM => // n_gt3 [//|isoMy isoMxy defX]. have n1_gt2: n.-1 > 2 by rewrite -(subnKC n_gt3). by split=> //; apply/quaternion_classP; exists n.-1. do [case: ifP => [isoG | _]; last by case: ifP] in cG * => /= _; move/eqnP=> oy. case/andP: isoG => n_gt3 isoG; rewrite (leqNgt n) (ltnW n_gt3) /=. have n1_gt2: n.-1 > 2 by rewrite -(subnKC n_gt3). have:= semidihedral_structure n_gt3 genG isoG oy. rewrite -/X -/q -/r -/yG -/xyG -/My -/Mxy. case=> [[defG oxy invXX'] nilG [defZ oZ [-> ->] defMho] [[defX' tiX'] maxG]]. case=> isoMy isoMxy defX; do 2!split=> //. by apply/dihedral_classP; exists n.-1; first apply: ltnW. by apply/quaternion_classP; exists n.-1. Qed. (* This is Aschbacher (23.4). *) Lemma maximal_cycle_extremal gT p (G X : {group gT}) : p.-group G -> ~~ abelian G -> cyclic X -> X \subset G -> #|G : X| = p -> (extremal_class G == ModularGroup) || (p == 2) && extremal2 G. Proof. move=> pG not_cGG cycX sXG iXG; rewrite /extremal2; set cG := extremal_class G. have [|p_pr _ _] := pgroup_pdiv pG. by case: eqP not_cGG => // ->; rewrite abelian1. have p_gt1 := prime_gt1 p_pr; have p_gt0 := ltnW p_gt1. have [n oG] := p_natP pG; have n_gt2: n > 2. apply: contraR not_cGG; rewrite -leqNgt => n_le2. by rewrite (p2group_abelian pG) // oG pfactorK. have def_n := subnKC n_gt2; have n_gt1 := ltnW n_gt2; have n_gt0 := ltnW n_gt1. pose q := (p ^ n.-1)%N; pose r := (p ^ n.-2)%N. have q_gt1: q > 1 by rewrite (ltn_exp2l 0) // -(subnKC n_gt2). have r_gt0: r > 0 by rewrite expn_gt0 p_gt0. have def_pr: (p * r)%N = q by rewrite /q /r -def_n. have oX: #|X| = q by rewrite -(divg_indexS sXG) oG iXG /q -def_n mulKn. have ntX: X :!=: 1 by rewrite -cardG_gt1 oX. have maxX: maximal X G by rewrite p_index_maximal ?iXG. have nsXG: X <| G := p_maximal_normal pG maxX; have [_ nXG] := andP nsXG. have cXX: abelian X := cyclic_abelian cycX. have scXG: 'C_G(X) = X. apply/eqP; rewrite eqEsubset subsetI sXG -abelianE cXX !andbT. apply: contraR not_cGG; case/subsetPn=> y; case/setIP=> Gy cXy notXy. rewrite -!cycle_subG in Gy notXy; rewrite -(mulg_normal_maximal nsXG _ Gy) //. by rewrite abelianM cycle_abelian cyclic_abelian ?cycle_subG. have [x defX] := cyclicP cycX; have pX := pgroupS sXG pG. have Xx: x \in X by [rewrite defX cycle_id]; have Gx := subsetP sXG x Xx. have [ox p_x]: #[x] = q /\ p.-elt x by rewrite defX in pX oX. pose Z := <[x ^+ r]>. have defZ: Z = 'Ohm_1(X) by rewrite defX (Ohm_p_cycle _ p_x) ox subn1 pfactorK. have oZ: #|Z| = p by rewrite -orderE orderXdiv ox -def_pr ?dvdn_mull ?mulnK. have cGZ: Z \subset 'C(G). have nsZG: Z <| G by rewrite defZ gFnormal_trans. move/implyP: (meet_center_nil (pgroup_nil pG) nsZG). rewrite -cardG_gt1 oZ p_gt1 setIA (setIidPl (normal_sub nsZG)). by apply: contraR; move/prime_TIg=> -> //; rewrite oZ. have X_Gp y: y \in G -> y ^+ p \in X. move=> Gy; have nXy: y \in 'N(X) := subsetP nXG y Gy. rewrite coset_idr ?groupX // morphX //; apply/eqP. by rewrite -order_dvdn -iXG -card_quotient // order_dvdG ?mem_quotient. have [y X'y]: exists2 y, y \in G :\: X & (p == 2) + 3 <= n /\ x ^ y = x ^+ r.+1 \/ p = 2 /\ x * x ^ y \in Z. - have [y Gy notXy]: exists2 y, y \in G & y \notin X. by apply/subsetPn; rewrite proper_subn ?(maxgroupp maxX). have nXy: y \in 'N(X) := subsetP nXG y Gy; pose ay := conj_aut X y. have oay: #[ay] = p. apply: nt_prime_order => //. by rewrite -morphX // mker // ker_conj_aut (subsetP cXX) ?X_Gp. rewrite (sameP eqP (kerP _ nXy)) ker_conj_aut. by apply: contra notXy => cXy; rewrite -scXG inE Gy. have [m []]:= cyclic_pgroup_Aut_structure pX cycX ntX. set Ap := 'O_p(_); case=> def_m [m1 _] [m_inj _] _ _ _. have sylAp: p.-Sylow(Aut X) Ap. by rewrite nilpotent_pcore_Hall // abelian_nil // Aut_cyclic_abelian. have Ap1ay: ay \in 'Ohm_1(Ap). rewrite (OhmE _ (pcore_pgroup _ _)) mem_gen // !inE -order_dvdn oay dvdnn. rewrite (mem_normal_Hall sylAp) ?pcore_normal ?Aut_aut //. by rewrite /p_elt oay pnat_id. rewrite {1}oX pfactorK // -{1}def_n /=. have [p2 | odd_p] := even_prime p_pr; last first. rewrite (sameP eqP (prime_oddPn p_pr)) odd_p n_gt2. case=> _ [_ _ _] [_ _ [s [As os m_s defAp1]]]. have [j def_s]: exists j, s = ay ^+ j. apply/cycleP; rewrite -cycle_subG subEproper eq_sym eqEcard -!orderE. by rewrite -defAp1 cycle_subG Ap1ay oay os leqnn . exists (y ^+ j); last first. left; rewrite -(norm_conj_autE _ Xx) ?groupX // morphX // -def_s. by rewrite -def_m // m_s expg_znat // oX pfactorK ?eqxx. rewrite -scXG !inE groupX //= andbT -ker_conj_aut !inE morphX // -def_s. rewrite andbC -(inj_in_eq m_inj) ?group1 // m_s m1 oX pfactorK // -/r. rewrite mulrSr -subr_eq0 addrK -val_eqE /= val_Zp_nat //. by rewrite [_ == 0]dvdn_Pexp2l // -def_n ltnn. rewrite {1}p2 /= => [[t [At ot m_t]]]; rewrite {1}oX pfactorK // -{1}def_n. rewrite eqSS subn_eq0 => defA; exists y; rewrite ?inE ?notXy //. rewrite p2 -(norm_conj_autE _ Xx) //= -/ay -def_m ?Aut_aut //. case Tay: (ay \in <[t]>). rewrite cycle2g // !inE -order_eq1 oay p2 /= in Tay. by right; rewrite (eqP Tay) m_t expg_zneg // mulgV group1. case: leqP defA => [_ defA|le3n [a [Aa _ _ defA [s [As os m_s m_st defA1]]]]]. by rewrite -defA Aut_aut in Tay. have: ay \in [set s; s * t]. have: ay \in 'Ohm_1(Aut X) := subsetP (OhmS 1 (pcore_sub _ _)) ay Ap1ay. case/dprodP: (Ohm_dprod 1 defA) => _ <- _ _. rewrite defA1 (@Ohm_p_cycle _ _ 2) /p_elt ot //= expg1 cycle2g //. by rewrite mulUg mul1g inE Tay cycle2g // mulgU mulg1 mulg_set1. case/set2P=> ->; [left | right]. by rewrite ?le3n m_s expg_znat // oX pfactorK // -p2. by rewrite m_st expg_znat // oX pfactorK // -p2 -/r -expgS prednK ?cycle_id. have [Gy notXy] := setDP X'y; have nXy := subsetP nXG y Gy. have defG j: <[x]> <*> <[x ^+ j * y]> = G. rewrite -defX -genM_join. by rewrite (mulg_normal_maximal nsXG) ?cycle_subG ?groupMl ?groupX ?genGid. have[i def_yp]: exists i, y ^- p = x ^+ i. by apply/cycleP; rewrite -defX groupV X_Gp. have p_i: p %| i. apply: contraR notXy; rewrite -prime_coprime // => co_p_j. have genX: generator X (y ^- p). by rewrite def_yp defX generator_coprime ox coprimeXl. rewrite -scXG (setIidPl _) // centsC ((X :=P: _) genX) cycle_subG groupV. rewrite /= -(defG 0) mul1g centY inE -defX (subsetP cXX) ?X_Gp //. by rewrite (subsetP (cycle_abelian y)) ?mem_cycle. case=> [[n_gt23 xy] | [p2 Z_xxy]]. suffices ->: cG = ModularGroup by []; apply/modular_group_classP. exists p => //; exists n => //; rewrite isogEcard card_modular_group //. rewrite oG leqnn andbT Grp_modular_group // -/q -/r. have{i def_yp p_i} [i def_yp]: exists i, y ^- p = x ^+ i ^+ p. by case/dvdnP: p_i => j def_i; exists j; rewrite -expgM -def_i. have Zyx: [~ y, x] \in Z. by rewrite -groupV invg_comm commgEl xy expgS mulKg cycle_id. have def_yxj j: [~ y, x ^+ j] = [~ y, x] ^+ j. by rewrite commgX /commute ?(centsP cGZ _ Zyx). have Zyxj j: [~ y, x ^+ j] \in Z by rewrite def_yxj groupX. have x_xjy j: x ^ (x ^+ j * y) = x ^+ r.+1. by rewrite conjgM {2}/conjg commuteX //= mulKg. have [cyxi | not_cyxi] := eqVneq ([~ y, x ^+ i] ^+ 'C(p, 2)) 1. apply/existsP; exists (x, x ^+ i * y); rewrite /= !xpair_eqE. rewrite defG x_xjy -order_dvdn ox dvdnn !eqxx andbT /=. rewrite expMg_Rmul /commute ?(centsP cGZ _ (Zyxj _)) ?groupX // cyxi. by rewrite -def_yp -mulgA mulKg. have [p2 | odd_p] := even_prime p_pr; last first. by rewrite -order_dvdn bin2odd ?dvdn_mulr // -oZ order_dvdG in not_cyxi. have def_yxi: [~ y, x ^+ i] = x ^+ r. have:= Zyxj i; rewrite /Z cycle_traject orderE oZ p2 !inE mulg1. by case/pred2P=> // cyxi; rewrite cyxi p2 eqxx in not_cyxi. apply/existsP; exists (x, x ^+ (i + r %/ 2) * y); rewrite /= !xpair_eqE. rewrite defG x_xjy -order_dvdn ox dvdnn !eqxx andbT /=. rewrite expMg_Rmul /commute ?(centsP cGZ _ (Zyxj _)) ?groupX // def_yxj. rewrite -expgM mulnDl addnC !expgD (expgM x i) -def_yp mulgKV. rewrite -def_yxj def_yxi p2 mulgA -expgD in n_gt23 *. rewrite -expg_mod_order ox /q /r p2 -(subnKC n_gt23) mulnC !expnS mulKn //. rewrite addnn -mul2n modnn mul1g -order_dvdn dvdn_mulr //. by rewrite -p2 -oZ order_dvdG. have{i def_yp p_i} Zy2: y ^+ 2 \in Z. rewrite defZ (OhmE _ pX) -groupV -p2 def_yp mem_gen // !inE groupX //= p2. rewrite expgS -{2}def_yp -(mulKg y y) -conjgE -conjXg -conjVg def_yp conjXg. rewrite -expgMn //; last by apply: (centsP cXX); rewrite ?memJ_norm. by rewrite -order_dvdn (dvdn_trans (order_dvdG Z_xxy)) ?oZ. rewrite !cycle_traject !orderE oZ p2 !inE !mulg1 /= in Z_xxy Zy2 *. rewrite -eq_invg_mul eq_sym -[r]prednK // expgS (inj_eq (mulgI _)) in Z_xxy. case/pred2P: Z_xxy => xy; last first. suffices ->: cG = SemiDihedral by []; apply/semidihedral_classP. have n_gt3: n > 3. case: ltngtP notXy => // [|n3]; first by rewrite ltnNge n_gt2. rewrite -scXG inE Gy defX cent_cycle; case/cent1P; red. by rewrite (conjgC x) xy /r p2 -n3. exists n => //; rewrite isogEcard card_semidihedral // oG p2 leqnn andbT. rewrite Grp_semidihedral //; apply/existsP=> /=. case/pred2P: Zy2 => y2; [exists (x, y) | exists (x, x * y)]. by rewrite /= -{1}[y]mul1g (defG 0) y2 xy -p2 -/q -ox expg_order. rewrite /= (defG 1%N) conjgM {2}/conjg mulKg -p2 -/q -ox expg_order -xy. rewrite !xpair_eqE !eqxx /= andbT p2 expgS {2}(conjgC x) xy mulgA -(mulgA x). rewrite [y * y]y2 -expgS -expgD addSnnS prednK // addnn -mul2n -p2 def_pr. by rewrite -ox expg_order. case/pred2P: Zy2 => y2. suffices ->: cG = Dihedral by []; apply/dihedral_classP. exists n => //; rewrite isogEcard card_2dihedral // oG p2 leqnn andbT. rewrite Grp_2dihedral //; apply/existsP; exists (x, y) => /=. by rewrite /= -{1}[y]mul1g (defG 0) y2 xy -p2 -/q -ox expg_order. suffices ->: cG = Quaternion by []; apply/quaternion_classP. exists n => //; rewrite isogEcard card_quaternion // oG p2 leqnn andbT. rewrite Grp_quaternion //; apply/existsP; exists (x, y) => /=. by rewrite /= -{1}[y]mul1g (defG 0) y2 xy -p2 -/q -ox expg_order. Qed. (* This is Aschbacher (23.5) *) Lemma cyclic_SCN gT p (G U : {group gT}) : p.-group G -> U \in 'SCN(G) -> ~~ abelian G -> cyclic U -> [/\ p = 2, #|G : U| = 2 & extremal2 G] \/ exists M : {group gT}, [/\ M :=: 'C_G('Mho^1(U)), #|M : U| = p, extremal_class M = ModularGroup, 'Ohm_1(M)%G \in 'E_p^2(G) & 'Ohm_1(M) \char G]. Proof. move=> pG /SCN_P[nsUG scUG] not_cGG cycU; have [sUG nUG] := andP nsUG. have [cUU pU] := (cyclic_abelian cycU, pgroupS sUG pG). have ltUG: ~~ (G \subset U). by apply: contra not_cGG => sGU; apply: abelianS cUU. have ntU: U :!=: 1. by apply: contraNneq ltUG => U1; rewrite -scUG subsetIidl U1 cents1. have [p_pr _ [n oU]] := pgroup_pdiv pU ntU. have p_gt1 := prime_gt1 p_pr; have p_gt0 := ltnW p_gt1. have [u defU] := cyclicP cycU; have Uu: u \in U by rewrite defU cycle_id. have Gu := subsetP sUG u Uu; have p_u := mem_p_elt pG Gu. have defU1: 'Mho^1(U) = <[u ^+ p]> by rewrite defU (Mho_p_cycle _ p_u). have modM1 (M : {group gT}): [/\ U \subset M, #|M : U| = p & extremal_class M = ModularGroup] -> M :=: 'C_M('Mho^1(U)) /\ 'Ohm_1(M)%G \in 'E_p^2(M). - case=> sUM iUM /modular_group_classP[q q_pr {n oU}[n n_gt23 isoM]]. have n_gt2: n > 2 by apply: leq_trans (leq_addl _ _) n_gt23. have def_n: n = (n - 3).+3 by rewrite -{1}(subnKC n_gt2). have oM: #|M| = (q ^ n)%N by rewrite (card_isog isoM) card_modular_group. have pM: q.-group M by rewrite /pgroup oM pnatX pnat_id. have def_q: q = p; last rewrite {q q_pr}def_q in oM pM isoM n_gt23. by apply/eqP; rewrite eq_sym [p == q](pgroupP pM) // -iUM dvdn_indexg. have [[x y] genM modM] := generators_modular_group p_pr n_gt2 isoM. case/modular_group_structure: genM => // _ [defZ _ oZ] _ defMho. have ->: 'Mho^1(U) = 'Z(M). apply/eqP; rewrite eqEcard oZ defZ -(defMho 1%N) ?MhoS //= defU1 -orderE. suff ou: #[u] = (p * p ^ n.-2)%N by rewrite orderXdiv ou ?dvdn_mulr ?mulKn. by rewrite orderE -defU -(divg_indexS sUM) iUM oM def_n mulKn. case: eqP => [[p2 n3] | _ defOhm]; first by rewrite p2 n3 in n_gt23. have{defOhm} [|defM1 oM1] := defOhm 1%N; first by rewrite def_n. split; rewrite ?(setIidPl _) //; first by rewrite centsC subsetIr. rewrite inE oM1 pfactorK // andbT inE Ohm_sub abelem_Ohm1 //. exact: (card_p2group_abelian p_pr oM1). have ou: #[u] = (p ^ n.+1)%N by rewrite defU in oU. pose Gs := G / U; have pGs: p.-group Gs by rewrite quotient_pgroup. have ntGs: Gs != 1 by rewrite -subG1 quotient_sub1. have [_ _ [[|k] oGs]] := pgroup_pdiv pGs ntGs. have iUG: #|G : U| = p by rewrite -card_quotient ?oGs. case: (predU1P (maximal_cycle_extremal _ _ _ _ iUG)) => // [modG | ext2G]. by right; exists G; case: (modM1 G) => // <- ->; rewrite Ohm_char. by left; case: eqP ext2G => // <-. pose M := 'C_G('Mho^1(U)); right; exists [group of M]. have sMG: M \subset G by apply: subsetIl. have [pM nUM] := (pgroupS sMG pG, subset_trans sMG nUG). have sUM: U \subset M by rewrite subsetI sUG sub_abelian_cent ?Mho_sub. pose A := Aut U; have cAA: abelian A by rewrite Aut_cyclic_abelian. have sylAp: p.-Sylow(A) 'O_p(A) by rewrite nilpotent_pcore_Hall ?abelian_nil. have [f [injf sfGsA fG]]: exists f : {morphism Gs >-> {perm gT}}, [/\ 'injm f, f @* Gs \subset A & {in G, forall y, f (coset U y) u = u ^ y}]. - have [] := first_isom_loc [morphism of conj_aut U] nUG. rewrite ker_conj_aut scUG /= -/Gs => f injf im_f. exists f; rewrite im_f ?Aut_conj_aut //. split=> // y Gy; have nUy := subsetP nUG y Gy. suffices ->: f (coset U y) = conj_aut U y by rewrite norm_conj_autE. by apply: set1_inj; rewrite -!morphim_set1 ?mem_quotient // im_f ?sub1set. have cGsGs: abelian Gs by rewrite -(injm_abelian injf) // (abelianS sfGsA). have p_fGs: p.-group (f @* Gs) by rewrite morphim_pgroup. have sfGsAp: f @* Gs \subset 'O_p(A) by rewrite (sub_Hall_pcore sylAp). have [a [fGa oa au n_gt01 cycGs]]: exists a, [/\ a \in f @* Gs, #[a] = p, a u = u ^+ (p ^ n).+1, (p == 2) + 1 <= n & cyclic Gs \/ p = 2 /\ (exists2 c, c \in f @* Gs & c u = u^-1)]. - have [m [[def_m _ _ _ _] _]] := cyclic_pgroup_Aut_structure pU cycU ntU. have ->: logn p #|U| = n.+1 by rewrite oU pfactorK. rewrite /= -/A; case: posnP => [_ defA | n_gt0 [c [Ac oc m_c defA]]]. have:= cardSg sfGsAp; rewrite (card_Hall sylAp) /= -/A defA card_injm //. by rewrite oGs (part_p'nat (pcore_pgroup _ _)) pfactor_dvdn // logn1. have [p2 | odd_p] := even_prime p_pr; last first. case: eqP => [-> // | _] in odd_p *; rewrite odd_p in defA. have [[cycA _] _ [a [Aa oa m_a defA1]]] := defA. exists a; rewrite -def_m // oa m_a expg_znat //. split=> //; last by left; rewrite -(injm_cyclic injf) ?(cyclicS sfGsA). have: f @* Gs != 1 by rewrite morphim_injm_eq1. rewrite -cycle_subG; apply: contraR => not_sfGs_a. by rewrite -(setIidPl sfGsAp) TI_Ohm1 // defA1 setIC prime_TIg -?orderE ?oa. do [rewrite {1}p2 /= eqn_leq n_gt0; case: leqP => /= [_ | n_gt1]] in defA. have:= cardSg sfGsAp; rewrite (card_Hall sylAp) /= -/A defA -orderE oc p2. by rewrite card_injm // oGs p2 pfactor_dvdn // p_part. have{defA} [s [As os _ defA [a [Aa oa m_a _ defA1]]]] := defA; exists a. have fGs_a: a \in f @* Gs. suffices: f @* Gs :&: <[s]> != 1. apply: contraR => not_fGs_a; rewrite TI_Ohm1 // defA1 setIC. by rewrite prime_TIg -?orderE ?oa // cycle_subG. have: (f @* Gs) * <[s]> \subset A by rewrite mulG_subG cycle_subG sfGsA. move/subset_leq_card; apply: contraL; move/eqP; move/TI_cardMg->. rewrite -(dprod_card defA) -ltnNge mulnC -!orderE ltn_pmul2r // oc. by rewrite card_injm // oGs p2 (ltn_exp2l 1). rewrite -def_m // oa m_a expg_znat // p2; split=> //. rewrite abelian_rank1_cyclic // (rank_pgroup pGs) //. rewrite -(injm_p_rank injf) // p_rank_abelian 1?morphim_abelian //= p2 -/Gs. case: leqP => [|fGs1_gt1]; [by left | right]. split=> //; exists c; last by rewrite -def_m // m_c expg_zneg. have{} defA1: <[a]> \x <[c]> = 'Ohm_1(Aut U). by rewrite -(Ohm_dprod 1 defA) defA1 (@Ohm_p_cycle 1 _ 2) /p_elt oc. have def_fGs1: 'Ohm_1(f @* Gs) = 'Ohm_1(A). apply/eqP; rewrite eqEcard OhmS // -(dprod_card defA1) -!orderE oa oc. by rewrite dvdn_leq ?(@pfactor_dvdn 2 2) ?cardG_gt0. rewrite (subsetP (Ohm_sub 1 _)) // def_fGs1 -cycle_subG. by case/dprodP: defA1 => _ <- _ _; rewrite mulG_subr. have n_gt0: n > 0 := leq_trans (leq_addl _ _) n_gt01. have [ys Gys _ def_a] := morphimP fGa. have oys: #[ys] = p by rewrite -(order_injm injf) // -def_a oa. have defMs: M / U = <[ys]>. apply/eqP; rewrite eq_sym eqEcard -orderE oys cycle_subG; apply/andP; split. have [y nUy Gy /= def_ys] := morphimP Gys. rewrite def_ys mem_quotient //= inE Gy defU1 cent_cycle cent1C. rewrite (sameP cent1P commgP) commgEl conjXg -fG //= -def_ys -def_a au. by rewrite -expgM mulSn expgD mulKg -expnSr -ou expg_order. rewrite card_quotient // -(setIidPr sUM) -scUG setIA (setIidPl sMG). rewrite defU cent_cycle index_cent1 -(card_imset _ (mulgI u^-1)) -imset_comp. have <-: #|'Ohm_1(U)| = p. rewrite defU (Ohm_p_cycle 1 p_u) -orderE (orderXexp _ ou) ou pfactorK //. by rewrite subKn. rewrite (OhmE 1 pU) subset_leq_card ?sub_gen //. apply/subsetP=> _ /imsetP[z /setIP[/(subsetP nUG) nUz cU1z] ->]. have Uv' := groupVr Uu; have Uuz: u ^ z \in U by rewrite memJ_norm. rewrite !inE groupM // expgMn /commute 1?(centsP cUU u^-1) //= expgVn -conjXg. by rewrite (sameP commgP cent1P) cent1C -cent_cycle -defU1. have iUM: #|M : U| = p by rewrite -card_quotient ?defMs. have not_cMM: ~~ abelian M. apply: contraL p_pr => cMM; rewrite -iUM -indexgI /= -/M. by rewrite (setIidPl _) ?indexgg // -scUG subsetI sMG sub_abelian_cent. have modM: extremal_class M = ModularGroup. have sU1Z: 'Mho^1(U) \subset 'Z(M). by rewrite subsetI gFsub_trans // centsC subsetIr. have /maximal_cycle_extremal/predU1P[] //= := iUM; rewrite -/M. case/andP=> /eqP-p2 ext2M; rewrite p2 add1n in n_gt01. suffices{sU1Z}: #|'Z(M)| = 2. move/eqP; rewrite eqn_leq leqNgt (leq_trans _ (subset_leq_card sU1Z)) //. by rewrite defU1 -orderE (orderXexp 1 ou) subn1 p2 (ltn_exp2l 1). move: ext2M; rewrite /extremal2 !inE orbC -orbA; case/or3P; move/eqP. - case/semidihedral_classP=> m m_gt3 isoM. have [[x z] genM [oz _]] := generators_semidihedral m_gt3 isoM. by case/semidihedral_structure: genM => // _ _ []. - case/quaternion_classP=> m m_gt2 isoM. have [[x z] genM _] := generators_quaternion m_gt2 isoM. by case/quaternion_structure: genM => // _ _ []. case/dihedral_classP=> m m_gt1 isoM. have [[x z] genM _] := generators_2dihedral m_gt1 isoM. case/dihedral2_structure: genM not_cMM => // _ _ _ _. by case: (m == 2) => [|[]//]; move/abelem_abelian->. split=> //. have [//|_] := modM1 [group of M]; rewrite !inE -andbA /=. by case/andP=> /subset_trans->. have{cycGs} [cycGs | [p2 [c fGs_c u_c]]] := cycGs. suffices ->: 'Ohm_1(M) = 'Ohm_1(G) by apply: Ohm_char. suffices sG1M: 'Ohm_1(G) \subset M. by apply/eqP; rewrite eqEsubset -{2}(Ohm_id 1 G) !OhmS. rewrite -(quotientSGK _ sUM) ?(subset_trans (Ohm_sub _ G)) //= defMs. suffices ->: <[ys]> = 'Ohm_1(Gs) by rewrite morphim_Ohm. apply/eqP; rewrite eqEcard -orderE cycle_subG /= {1}(OhmE 1 pGs) /=. rewrite mem_gen ?inE ?Gys -?order_dvdn oys //=. rewrite -(part_pnat_id (pgroupS (Ohm_sub _ _) pGs)) p_part (leq_exp2l _ 1) //. by rewrite -p_rank_abelian -?rank_pgroup -?abelian_rank1_cyclic. suffices charU1: 'Mho^1(U) \char G^`(1). by rewrite gFchar_trans // subcent_char ?(char_trans charU1) ?gFchar. suffices sUiG': 'Mho^1(U) \subset G^`(1). have /cyclicP[zs cycG']: cyclic G^`(1) by rewrite (cyclicS _ cycU) ?der1_min. by rewrite cycG' in sUiG' *; apply: cycle_subgroup_char. rewrite defU1 cycle_subG p2 -groupV invMg -{2}u_c. by have [_ _ /morphimP[z _ Gz ->] ->] := morphimP fGs_c; rewrite fG ?mem_commg. Qed. (* This is Aschbacher, exercise (8.4) *) Lemma normal_rank1_structure gT p (G : {group gT}) : p.-group G -> (forall X : {group gT}, X <| G -> abelian X -> cyclic X) -> cyclic G \/ [&& p == 2, extremal2 G & (#|G| >= 16) || (G \isog 'Q_8)]. Proof. move=> pG dn_G_1. have [cGG | not_cGG] := boolP (abelian G); first by left; rewrite dn_G_1. have [X maxX]: {X | [max X | X <| G & abelian X]}. by apply: ex_maxgroup; exists 1%G; rewrite normal1 abelian1. have cycX: cyclic X by rewrite dn_G_1; case/andP: (maxgroupp maxX). have scX: X \in 'SCN(G) := max_SCN pG maxX. have [[p2 _ cG] | [M [_ _ _]]] := cyclic_SCN pG scX not_cGG cycX; last first. rewrite 2!inE -andbA => /and3P[sEG abelE dimE_2] charE. have:= dn_G_1 _ (char_normal charE) (abelem_abelian abelE). by rewrite (abelem_cyclic abelE) (eqP dimE_2). have [n oG] := p_natP pG; right; rewrite p2 cG /= in oG *. rewrite oG (@leq_exp2l 2 4) //. rewrite /extremal2 /extremal_class oG pfactorKpdiv // in cG. case: andP cG => [[n_gt1 isoG] _ | _]; last first. by case: (ltngtP 3 n) => //= <-; do 2?case: ifP. have [[x y] genG _] := generators_2dihedral n_gt1 isoG. have [_ _ _ [_ _ maxG]] := dihedral2_structure n_gt1 genG isoG. rewrite 2!ltn_neqAle n_gt1 !(eq_sym _ n). case: eqP => [_ abelG| _]; first by rewrite (abelem_abelian abelG) in not_cGG. case: eqP => // -> [_ _ isoY _ _]; set Y := <<_>> in isoY. have nxYG: Y <| G by rewrite (p_maximal_normal pG) // maxG !inE eqxx orbT. have [// | [u v] genY _] := generators_2dihedral _ isoY. case/dihedral2_structure: (genY) => //= _ _ _ _ abelY. have:= dn_G_1 _ nxYG (abelem_abelian abelY). by rewrite (abelem_cyclic abelY); case: genY => ->. Qed. (* Replacement for Section 4 proof. *) Lemma odd_pgroup_rank1_cyclic gT p (G : {group gT}) : p.-group G -> odd #|G| -> cyclic G = ('r_p(G) <= 1). Proof. move=> pG oddG; rewrite -rank_pgroup //; apply/idP/idP=> [cycG | dimG1]. by rewrite -abelian_rank1_cyclic ?cyclic_abelian. have [X nsXG cXX|//|] := normal_rank1_structure pG; last first. by rewrite (negPf (odd_not_extremal2 oddG)) andbF. by rewrite abelian_rank1_cyclic // (leq_trans (rankS (normal_sub nsXG))). Qed. (* This is the second part of Aschbacher, exercise (8.4). *) Lemma prime_Ohm1P gT p (G : {group gT}) : p.-group G -> G :!=: 1 -> reflect (#|'Ohm_1(G)| = p) (cyclic G || (p == 2) && (extremal_class G == Quaternion)). Proof. move=> pG ntG; have [p_pr p_dvd_G _] := pgroup_pdiv pG ntG. apply: (iffP idP) => [|oG1p]. case/orP=> [cycG|]; first exact: Ohm1_cyclic_pgroup_prime. case/andP=> /eqP p2 /eqP/quaternion_classP[n n_gt2 isoG]. rewrite p2; have [[x y]] := generators_quaternion n_gt2 isoG. by case/quaternion_structure=> // _ _ [<- oZ _ [->]]. have [X nsXG cXX|-> //|]:= normal_rank1_structure pG. have [sXG _] := andP nsXG; have pX := pgroupS sXG pG. rewrite abelian_rank1_cyclic // (rank_pgroup pX) p_rank_abelian //. rewrite -{2}(pfactorK 1 p_pr) -{3}oG1p dvdn_leq_log ?cardG_gt0 //. by rewrite cardSg ?OhmS. case/and3P=> /eqP p2; rewrite p2 (orbC (cyclic G)) /extremal2. case cG: (extremal_class G) => //; case: notF. case/dihedral_classP: cG => n n_gt1 isoG. have [[x y] genG _] := generators_2dihedral n_gt1 isoG. have [oG _ _ _] := genG; case/dihedral2_structure: genG => // _ _ [defG1 _] _. by case/idPn: n_gt1; rewrite -(@ltn_exp2l 2) // -oG -defG1 oG1p p2. case/semidihedral_classP: cG => n n_gt3 isoG. have [[x y] genG [oy _]] := generators_semidihedral n_gt3 isoG. case/semidihedral_structure: genG => // _ _ [_ _ [defG1 _] _] _ [isoG1 _ _]. case/idPn: (n_gt3); rewrite -(ltn_predK n_gt3) ltnS -leqNgt -(@leq_exp2l 2) //. rewrite -card_2dihedral //; last by rewrite -(subnKC n_gt3). by rewrite -(card_isog isoG1) /= -defG1 oG1p p2. Qed. (* This is Aschbacher (23.9) *) Theorem symplectic_type_group_structure gT p (G : {group gT}) : p.-group G -> (forall X : {group gT}, X \char G -> abelian X -> cyclic X) -> exists2 E : {group gT}, E :=: 1 \/ extraspecial E & exists R : {group gT}, [/\ cyclic R \/ [/\ p = 2, extremal2 R & #|R| >= 16], E \* R = G & E :&: R = 'Z(E)]. Proof. move=> pG sympG; have [H [charH]] := Thompson_critical pG. have sHG := char_sub charH; have pH := pgroupS sHG pG. set U := 'Z(H) => sPhiH_U sHG_U defU; set Z := 'Ohm_1(U). have sZU: Z \subset U by rewrite Ohm_sub. have charU: U \char G := gFchar_trans _ charH. have cUU: abelian U := center_abelian H. have cycU: cyclic U by apply: sympG. have pU: p.-group U := pgroupS (char_sub charU) pG. have cHU: U \subset 'C(H) by rewrite subsetIr. have cHsHs: abelian (H / Z). rewrite sub_der1_abelian //= (OhmE _ pU) genS //= -/U. apply/subsetP=> _ /imset2P[h k Hh Hk ->]. have Uhk: [~ h, k] \in U by rewrite (subsetP sHG_U) ?mem_commg ?(subsetP sHG). rewrite inE Uhk inE -commXg; last by red; rewrite -(centsP cHU). apply/commgP; red; rewrite (centsP cHU) // (subsetP sPhiH_U) //. by rewrite (Phi_joing pH) mem_gen // inE orbC (Mho_p_elt 1) ?(mem_p_elt pH). have nsZH: Z <| H by rewrite sub_center_normal. have [K /=] := inv_quotientS nsZH (Ohm_sub 1 (H / Z)); fold Z => defKs sZK sKH. have nsZK: Z <| K := normalS sZK sKH nsZH; have [_ nZK] := andP nsZK. have abelKs: p.-abelem (K / Z) by rewrite -defKs Ohm1_abelem ?quotient_pgroup. have charK: K \char G. have charZ: Z \char H := gFchar_trans _ (center_char H). rewrite (char_trans _ charH) // (char_from_quotient nsZK) //. by rewrite -defKs Ohm_char. have cycZK: cyclic 'Z(K) by rewrite sympG ?center_abelian ?gFchar_trans. have [cKK | not_cKK] := orP (orbN (abelian K)). have defH: U = H. apply: center_idP; apply: cyclic_factor_abelian (Ohm_sub 1 _) _. rewrite /= -/Z abelian_rank1_cyclic //. have cKsKs: abelian (K / Z) by rewrite -defKs (abelianS (Ohm_sub 1 _)). have cycK: cyclic K by rewrite -(center_idP cKK). by rewrite -rank_Ohm1 defKs -abelian_rank1_cyclic ?quotient_cyclic. have scH: H \in 'SCN(G) by apply/SCN_P; rewrite defU char_normal. have [cGG | not_cGG] := orP (orbN (abelian G)). exists 1%G; [by left | exists G; rewrite cprod1g (setIidPl _) ?sub1G //]. by split; first left; rewrite ?center1 // sympG ?char_refl. have cycH: cyclic H by rewrite -{}defH. have [[p2 _ cG2]|[M [_ _ _]]] := cyclic_SCN pG scH not_cGG cycH; last first. do 2![case/setIdP] => _ abelE dimE_2 charE. have:= sympG _ charE (abelem_abelian abelE). by rewrite (abelem_cyclic abelE) (eqP dimE_2). have [n oG] := p_natP pG; rewrite p2 in oG. have [n_gt3 | n_le3] := ltnP 3 n. exists 1%G; [by left | exists G; rewrite cprod1g (setIidPl _) ?sub1G //]. by split; first right; rewrite ?center1 // oG (@leq_exp2l 2 4). have esG: extraspecial G. by apply: (p3group_extraspecial pG); rewrite // p2 oG pfactorK. exists G; [by right | exists ('Z(G))%G; rewrite cprod_center_id setIA setIid]. by split=> //; left; rewrite prime_cyclic; case: esG. have ntK: K :!=: 1 by apply: contra not_cKK => /eqP->; apply: abelian1. have [p_pr _ _] := pgroup_pdiv (pgroupS sKH pH) ntK. have p_gt1 := prime_gt1 p_pr; have p_gt0 := ltnW p_gt1. have oZ: #|Z| = p. apply: Ohm1_cyclic_pgroup_prime => //=; apply: contra ntK; move/eqP. by move/(trivg_center_pgroup pH)=> GH; rewrite -subG1 -GH. have sZ_ZK: Z \subset 'Z(K). by rewrite subsetI sZK gFsub_trans // subIset ?centS ?orbT. have sZsKs: 'Z(K) / Z \subset K / Z by rewrite quotientS ?center_sub. have [Es /= splitKs] := abelem_split_dprod abelKs sZsKs. have [_ /= defEsZs cEsZs tiEsZs] := dprodP splitKs. have sEsKs: Es \subset K / Z by rewrite -defEsZs mulG_subr. have [E defEs sZE sEK] := inv_quotientS nsZK sEsKs; rewrite /= -/Z in defEs sZE. have [nZE nZ_ZK] := (subset_trans sEK nZK, subset_trans (center_sub K) nZK). have defK: 'Z(K) * E = K. rewrite -(mulSGid sZ_ZK) -mulgA -quotientK ?mul_subG ?quotientMl //. by rewrite -defEs defEsZs quotientGK. have defZE: 'Z(E) = Z. have cEZK: 'Z(K) \subset 'C(E) by rewrite subIset // orbC centS. have cE_Z: E \subset 'C(Z) by rewrite centsC (subset_trans sZ_ZK). apply/eqP; rewrite eqEsubset andbC subsetI sZE centsC cE_Z /=. rewrite -quotient_sub1 ?subIset ?nZE //= -/Z -tiEsZs subsetI defEs. rewrite !quotientS ?center_sub //= subsetI subIset ?sEK //=. by rewrite -defK centM setSI // centsC. have sEH := subset_trans sEK sKH; have pE := pgroupS sEH pH. have esE: extraspecial E. split; last by rewrite defZE oZ. have sPhiZ: 'Phi(E) \subset Z. rewrite -quotient_sub1 ?gFsub_trans ?(quotient_Phi pE) //. rewrite subG1 (trivg_Phi (quotient_pgroup _ pE)) /= -defEs. by rewrite (abelemS sEsKs) //= -defKs Ohm1_abelem ?quotient_pgroup. have sE'Phi: E^`(1) \subset 'Phi(E) by rewrite (Phi_joing pE) joing_subl. have ntE': E^`(1) != 1. rewrite (sameP eqP commG1P) -abelianE; apply: contra not_cKK => cEE. by rewrite -defK mulGSid ?center_abelian // -(center_idP cEE) defZE. have defE': E^`(1) = Z. apply/eqP; rewrite eqEcard (subset_trans sE'Phi) //= oZ. have [_ _ [n ->]] := pgroup_pdiv (pgroupS (der_sub _ _) pE) ntE'. by rewrite (leq_exp2l 1) ?prime_gt1. by split; rewrite defZE //; apply/eqP; rewrite eqEsubset sPhiZ -defE'. have [spE _] := esE; have [defPhiE defE'] := spE. have{defE'} sEG_E': [~: E, G] \subset E^`(1). rewrite defE' defZE /Z (OhmE _ pU) commGC genS //. apply/subsetP=> _ /imset2P[g e Gg Ee ->]. have He: e \in H by rewrite (subsetP sKH) ?(subsetP sEK). have Uge: [~ g, e] \in U by rewrite (subsetP sHG_U) ?mem_commg. rewrite inE Uge inE -commgX; last by red; rewrite -(centsP cHU). have sZ_ZG: Z \subset 'Z(G). have charZ: Z \char G := gFchar_trans _ charU. have/implyP:= meet_center_nil (pgroup_nil pG) (char_normal charZ). rewrite -cardG_gt1 oZ prime_gt1 //=; apply: contraR => not_sZ_ZG. by rewrite prime_TIg ?oZ. have: e ^+ p \in 'Z(G). rewrite (subsetP sZ_ZG) // -defZE -defPhiE (Phi_joing pE) mem_gen //. by rewrite inE orbC (Mho_p_elt 1) ?(mem_p_elt pE). by case/setIP=> _ /centP cGep; apply/commgP; red; rewrite cGep. have sEG: E \subset G := subset_trans sEK (char_sub charK). set R := 'C_G(E). have{sEG_E'} defG: E \* R = G by apply: (critical_extraspecial pG). have [_ defER cRE] := cprodP defG. have defH: E \* 'C_H(E) = H by rewrite -(setIidPr sHG) setIAC (cprod_modl defG). have{defH} [_ defH cRH_E] := cprodP defH. have cRH_RH: abelian 'C_H(E). have sZ_ZRH: Z \subset 'Z('C_H(E)). rewrite subsetI -{1}defZE setSI //= (subset_trans sZU) // centsC. by rewrite subIset // centsC cHU. rewrite (cyclic_factor_abelian sZ_ZRH) //= -/Z. have defHs: Es \x ('C_H(E) / Z) = H / Z. rewrite defEs dprodE ?quotient_cents // -?quotientMl ?defH -?quotientGI //=. by rewrite setIA (setIidPl sEH) ['C_E(E)]defZE trivg_quotient. have:= Ohm_dprod 1 defHs; rewrite /= defKs (Ohm1_id (abelemS sEsKs abelKs)). rewrite dprodC; case/dprodP=> _ defEsRHs1 cRHs1Es tiRHs1Es. have sRHsHs: 'C_H(E) / Z \subset H / Z by rewrite quotientS ?subsetIl. have cRHsRHs: abelian ('C_H(E) / Z) by apply: abelianS cHsHs. have pHs: p.-group (H / Z) by rewrite quotient_pgroup. rewrite abelian_rank1_cyclic // (rank_pgroup (pgroupS sRHsHs pHs)). rewrite p_rank_abelian // -(leq_add2r (logn p #|Es|)) -lognM ?cardG_gt0 //. rewrite -TI_cardMg // defEsRHs1 /= -defEsZs TI_cardMg ?lognM ?cardG_gt0 //. by rewrite leq_add2r -abelem_cyclic ?(abelemS sZsKs) // quotient_cyclic. have{cRH_RH} defRH: 'C_H(E) = U. apply/eqP; rewrite eqEsubset andbC setIS ?centS // subsetI subsetIl /=. by rewrite -{2}defH centM subsetI subsetIr. have scUR: 'C_R(U) = U by rewrite -setIA -{1}defRH -centM defH. have sUR: U \subset R by rewrite -defRH setSI. have tiER: E :&: R = 'Z(E) by rewrite setIA (setIidPl (subset_trans sEH sHG)). have [cRR | not_cRR] := boolP (abelian R). exists E; [by right | exists [group of R]; split=> //; left]. by rewrite /= -(setIidPl (sub_abelian_cent cRR sUR)) scUR. have{} scUR: [group of U] \in 'SCN(R). by apply/SCN_P; rewrite (normalS sUR (subsetIl _ _)) // char_normal. have pR: p.-group R := pgroupS (subsetIl _ _) pG. have [R_le_3 | R_gt_3] := leqP (logn p #|R|) 3. have esR: extraspecial R := p3group_extraspecial pR not_cRR R_le_3. have esG: extraspecial G := cprod_extraspecial pG defG tiER esE esR. exists G; [by right | exists ('Z(G))%G; rewrite cprod_center_id setIA setIid]. by split=> //; left; rewrite prime_cyclic; case: esG. have [[p2 _ ext2R] | [M []]] := cyclic_SCN pR scUR not_cRR cycU. exists E; [by right | exists [group of R]; split=> //; right]. by rewrite dvdn_leq ?(@pfactor_dvdn 2 4) ?cardG_gt0 // -{2}p2. rewrite /= -/R => defM iUM modM _ _; pose N := 'C_G('Mho^1(U)). have charZN2: 'Z('Ohm_2(N)) \char G by rewrite !(gFchar_trans, subcent_char). have:= sympG _ charZN2 (center_abelian _). rewrite abelian_rank1_cyclic ?center_abelian // leqNgt; case/negP. have defN: E \* M = N. rewrite defM (cprod_modl defG) // centsC gFsub_trans //= -/U. by rewrite -defRH subsetIr. case/modular_group_classP: modM => q q_pr [n n_gt23 isoM]. have{n_gt23} n_gt2 := leq_trans (leq_addl _ _) n_gt23. have n_gt1 := ltnW n_gt2; have n_gt0 := ltnW n_gt1. have [[x y] genM modM] := generators_modular_group q_pr n_gt2 isoM. have{q_pr} defq: q = p; last rewrite {q}defq in genM modM isoM. have: p %| #|M| by rewrite -iUM dvdn_indexg. by have [-> _ _ _] := genM; rewrite Euclid_dvdX // dvdn_prime2 //; case: eqP. have [oM Mx ox X'y] := genM; have [My _] := setDP X'y; have [oy _] := modM. have [sUM sMR]: U \subset M /\ M \subset R. by rewrite defM subsetI sUR subsetIl centsC gFsub_trans. have oU1: #|'Mho^1(U)| = (p ^ n.-2)%N. have oU: #|U| = (p ^ n.-1)%N. by rewrite -(divg_indexS sUM) iUM oM -subn1 expnB. case/cyclicP: cycU pU oU => u -> p_u ou. by rewrite (Mho_p_cycle 1 p_u) -orderE (orderXexp 1 ou) subn1. have sZU1: Z \subset 'Mho^1(U). rewrite -(cardSg_cyclic cycU) ?gFsub // oZ oU1. by rewrite -(subnKC n_gt2) expnS dvdn_mulr. case/modular_group_structure: genM => // _ [defZM _ oZM] _ _. have:= n_gt2; rewrite leq_eqVlt eq_sym !xpair_eqE andbC. case: eqP => [n3 _ _ | _ /= n_gt3 defOhmM]. have eqZU1: Z = 'Mho^1(U) by apply/eqP; rewrite eqEcard sZU1 oZ oU1 n3 /=. rewrite (setIidPl _) in defM; first by rewrite -defM oM n3 pfactorK in R_gt_3. by rewrite -eqZU1 subIset ?centS ?orbT. have{defOhmM} [|defM2 _] := defOhmM 2; first by rewrite -subn1 ltn_subRL. do [set xpn3 := x ^+ _; set X2 := <[_]>] in defM2. have oX2: #|X2| = (p ^ 2)%N. by rewrite -orderE (orderXexp _ ox) -{1}(subnKC n_gt2) addSn addnK. have sZX2: Z \subset X2. have cycXp: cyclic <[x ^+ p]> := cycle_cyclic _. rewrite -(cardSg_cyclic cycXp) /=; first by rewrite oZ oX2 dvdn_mull. rewrite -defZM subsetI (subset_trans (Ohm_sub _ _)) //=. by rewrite (subset_trans sZU1) // centsC defM subsetIr. by rewrite /xpn3 -subnSK //expnS expgM cycleX. have{defM2} [_ /= defM2 cYX2 tiX2Y] := dprodP defM2. have{defN} [_ defN cME] := cprodP defN. have cEM2: E \subset 'C('Ohm_2(M)). by rewrite centsC (subset_trans _ cME) ?centS ?Ohm_sub. have [cEX2 cYE]: X2 \subset 'C(E) /\ E \subset 'C(<[y]>). by apply/andP; rewrite centsC -subsetI -centM defM2. have pN: p.-group N := pgroupS (subsetIl _ _) pG. have defN2: (E <*> X2) \x <[y]> = 'Ohm_2(N). rewrite dprodE ?centY ?subsetI 1?centsC ?cYE //=; last first. rewrite -cycle_subG in My; rewrite joingC cent_joinEl //= -/X2. rewrite -(setIidPr My) setIA -group_modl ?cycle_subG ?groupX //. by rewrite mulGSid // (subset_trans _ sZX2) // -defZE -tiER setIS. apply/eqP; rewrite cent_joinEr // -mulgA defM2 eqEsubset mulG_subG. rewrite OhmS ?andbT; last by rewrite -defN mulG_subr. have expE: exponent E %| p ^ 2 by rewrite exponent_special ?(pgroupS sEG). rewrite /= (OhmE 2 pN) sub_gen /=; last 1 first. by rewrite subsetI -defN mulG_subl sub_LdivT expE. rewrite -cent_joinEl // -genM_join genS // -defN. apply/subsetP=> _ /setIP[/imset2P[e z Ee Mz ->]]. rewrite inE expgMn; last by red; rewrite -(centsP cME). rewrite (exponentP expE) // mul1g => zp2; rewrite mem_mulg //=. by rewrite (OhmE 2 (pgroupS sMR pR)) mem_gen // !inE Mz. have{defN2} defZN2: X2 \x <[y]> = 'Z('Ohm_2(N)). rewrite -[X2](mulSGid sZX2) /= -/Z -defZE -(center_dprod defN2). do 2!rewrite -{1}(center_idP (cycle_abelian _)) -/X2; congr (_ \x _). by case/cprodP: (center_cprod (cprodEY cEX2)). have{defZN2} strZN2: \big[dprod/1]_(z <- [:: xpn3; y]) <[z]> = 'Z('Ohm_2(N)). by rewrite unlock /= dprodg1. rewrite -size_abelian_type ?center_abelian //. have pZN2: p.-group 'Z('Ohm_2(N)) by rewrite (pgroupS _ pN) // subIset ?Ohm_sub. rewrite (perm_size (abelian_type_pgroup pZN2 strZN2 _)) //= !inE. rewrite !(eq_sym 1) -!order_eq1 oy orderE oX2. by rewrite (eqn_exp2l 2 0) // (eqn_exp2l 1 0). Qed. End ExtremalTheory.
HasLimits.lean
/- Copyright (c) 2018 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Kim Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Limits.IsLimit import Mathlib.CategoryTheory.Category.ULift import Mathlib.CategoryTheory.EssentiallySmall import Mathlib.CategoryTheory.Functor.EpiMono import Mathlib.Logic.Equiv.Basic /-! # Existence of limits and colimits In `CategoryTheory.Limits.IsLimit` we defined `IsLimit c`, the data showing that a cone `c` is a limit cone. The two main structures defined in this file are: * `LimitCone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and * `HasLimit F`, asserting the mere existence of some limit cone for `F`. `HasLimit` is a propositional typeclass (it's important that it is a proposition merely asserting the existence of a limit, as otherwise we would have non-defeq problems from incompatible instances). While `HasLimit` only asserts the existence of a limit cone, we happily use the axiom of choice in mathlib, so there are convenience functions all depending on `HasLimit F`: * `limit F : C`, producing some limit object (of course all such are isomorphic) * `limit.π F j : limit F ⟶ F.obj j`, the morphisms out of the limit, * `limit.lift F c : c.pt ⟶ limit F`, the universal morphism from any other `c : Cone F`, etc. Key to using the `HasLimit` interface is that there is an `@[ext]` lemma stating that to check `f = g`, for `f g : Z ⟶ limit F`, it suffices to check `f ≫ limit.π F j = g ≫ limit.π F j` for every `j`. This, combined with `@[simp]` lemmas, makes it possible to prove many easy facts about limits using automation (e.g. `tidy`). There are abbreviations `HasLimitsOfShape J C` and `HasLimits C` asserting the existence of classes of limits. Later more are introduced, for finite limits, special shapes of limits, etc. Ideally, many results about limits should be stated first in terms of `IsLimit`, and then a result in terms of `HasLimit` derived from this. At this point, however, this is far from uniformly achieved in mathlib --- often statements are only written in terms of `HasLimit`. ## Implementation At present we simply say everything twice, in order to handle both limits and colimits. It would be highly desirable to have some automation support, e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`. ## References * [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Functor Opposite namespace CategoryTheory.Limits -- morphism levels before object levels. See note [CategoryTheory universes]. universe v₁ u₁ v₂ u₂ v₃ u₃ v v' v'' u u' u'' variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable {C : Type u} [Category.{v} C] variable {F : J ⥤ C} section Limit /-- `LimitCone F` contains a cone over `F` together with the information that it is a limit. -/ structure LimitCone (F : J ⥤ C) where /-- The cone itself -/ cone : Cone F /-- The proof that is the limit cone -/ isLimit : IsLimit cone /-- `HasLimit F` represents the mere existence of a limit for `F`. -/ class HasLimit (F : J ⥤ C) : Prop where mk' :: /-- There is some limit cone for `F` -/ exists_limit : Nonempty (LimitCone F) theorem HasLimit.mk {F : J ⥤ C} (d : LimitCone F) : HasLimit F := ⟨Nonempty.intro d⟩ /-- Use the axiom of choice to extract explicit `LimitCone F` from `HasLimit F`. -/ def getLimitCone (F : J ⥤ C) [HasLimit F] : LimitCone F := Classical.choice <| HasLimit.exists_limit variable (J C) /-- `C` has limits of shape `J` if there exists a limit for every functor `F : J ⥤ C`. -/ class HasLimitsOfShape : Prop where /-- All functors `F : J ⥤ C` from `J` have limits -/ has_limit : ∀ F : J ⥤ C, HasLimit F := by infer_instance /-- `C` has all limits of size `v₁ u₁` (`HasLimitsOfSize.{v₁ u₁} C`) if it has limits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasLimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All functors `F : J ⥤ C` from all small `J` have limits -/ has_limits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasLimitsOfShape J C := by infer_instance /-- `C` has all (small) limits if it has limits of every shape that is as big as its hom-sets. -/ abbrev HasLimits (C : Type u) [Category.{v} C] : Prop := HasLimitsOfSize.{v, v} C theorem HasLimits.has_limits_of_shape {C : Type u} [Category.{v} C] [HasLimits C] (J : Type v) [Category.{v} J] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasLimitOfHasLimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasLimitsOfShape J C] (F : J ⥤ C) : HasLimit F := HasLimitsOfShape.has_limit F -- see Note [lower instance priority] instance (priority := 100) hasLimitsOfShapeOfHasLimits {J : Type u₁} [Category.{v₁} J] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J -- Interface to the `HasLimit` class. /-- An arbitrary choice of limit cone for a functor. -/ def limit.cone (F : J ⥤ C) [HasLimit F] : Cone F := (getLimitCone F).cone /-- An arbitrary choice of limit object of a functor. -/ def limit (F : J ⥤ C) [HasLimit F] := (limit.cone F).pt /-- The projection from the limit object to a value of the functor. -/ def limit.π (F : J ⥤ C) [HasLimit F] (j : J) : limit F ⟶ F.obj j := (limit.cone F).π.app j @[reassoc] theorem limit.π_comp_eqToHom (F : J ⥤ C) [HasLimit F] {j j' : J} (hj : j = j') : limit.π F j ≫ eqToHom (by subst hj; rfl) = limit.π F j' := by subst hj simp @[simp] theorem limit.cone_x {F : J ⥤ C} [HasLimit F] : (limit.cone F).pt = limit F := rfl @[simp] theorem limit.cone_π {F : J ⥤ C} [HasLimit F] : (limit.cone F).π.app = limit.π _ := rfl @[reassoc (attr := simp)] theorem limit.w (F : J ⥤ C) [HasLimit F] {j j' : J} (f : j ⟶ j') : limit.π F j ≫ F.map f = limit.π F j' := (limit.cone F).w f /-- Evidence that the arbitrary choice of cone provided by `limit.cone F` is a limit cone. -/ def limit.isLimit (F : J ⥤ C) [HasLimit F] : IsLimit (limit.cone F) := (getLimitCone F).isLimit /-- The morphism from the cone point of any other cone to the limit object. -/ def limit.lift (F : J ⥤ C) [HasLimit F] (c : Cone F) : c.pt ⟶ limit F := (limit.isLimit F).lift c @[simp] theorem limit.isLimit_lift {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.isLimit F).lift c = limit.lift F c := rfl @[reassoc (attr := simp)] theorem limit.lift_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : limit.lift F c ≫ limit.π F j = c.π.app j := IsLimit.fac _ c j /-- Functoriality of limits. Usually this morphism should be accessed through `lim.map`, but may be needed separately when you have specified limits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def limMap {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) : limit F ⟶ limit G := IsLimit.map _ (limit.isLimit G) α @[reassoc (attr := simp)] theorem limMap_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) (j : J) : limMap α ≫ limit.π G j = limit.π F j ≫ α.app j := limit.lift_π _ j /-- The cone morphism from any cone to the arbitrary choice of limit cone. -/ def limit.coneMorphism {F : J ⥤ C} [HasLimit F] (c : Cone F) : c ⟶ limit.cone F := (limit.isLimit F).liftConeMorphism c @[simp] theorem limit.coneMorphism_hom {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.coneMorphism c).hom = limit.lift F c := rfl theorem limit.coneMorphism_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : (limit.coneMorphism c).hom ≫ limit.π F j = c.π.app j := by simp @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_hom_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso hc (limit.isLimit _)).hom ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_hom_comp _ _ _ @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_inv_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso (limit.isLimit _) hc).inv ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_inv_comp _ _ _ theorem limit.existsUnique {F : J ⥤ C} [HasLimit F] (t : Cone F) : ∃! l : t.pt ⟶ limit F, ∀ j, l ≫ limit.π F j = t.π.app j := (limit.isLimit F).existsUnique _ /-- Given any other limit cone for `F`, the chosen `limit F` is isomorphic to the cone point. -/ def limit.isoLimitCone {F : J ⥤ C} [HasLimit F] (t : LimitCone F) : limit F ≅ t.cone.pt := IsLimit.conePointUniqueUpToIso (limit.isLimit F) t.isLimit @[reassoc (attr := simp)] theorem limit.isoLimitCone_hom_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).hom ≫ t.cone.π.app j = limit.π F j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] simp @[reassoc (attr := simp)] theorem limit.isoLimitCone_inv_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).inv ≫ limit.π F j = t.cone.π.app j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] simp @[ext] theorem limit.hom_ext {F : J ⥤ C} [HasLimit F] {X : C} {f f' : X ⟶ limit F} (w : ∀ j, f ≫ limit.π F j = f' ≫ limit.π F j) : f = f' := (limit.isLimit F).hom_ext w @[reassoc (attr := simp)] theorem limit.lift_map {F G : J ⥤ C} [HasLimit F] [HasLimit G] (c : Cone F) (α : F ⟶ G) : limit.lift F c ≫ limMap α = limit.lift G ((Cones.postcompose α).obj c) := by ext rw [assoc, limMap_π, limit.lift_π_assoc, limit.lift_π] rfl @[simp] theorem limit.lift_cone {F : J ⥤ C} [HasLimit F] : limit.lift F (limit.cone F) = 𝟙 (limit F) := (limit.isLimit _).lift_self /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and cones with cone point `W`. -/ def limit.homIso (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ F.cones.obj (op W) := (limit.isLimit F).homIso W @[simp] theorem limit.homIso_hom (F : J ⥤ C) [HasLimit F] {W : C} (f : ULift (W ⟶ limit F)) : (limit.homIso F W).hom f = (const J).map f.down ≫ (limit.cone F).π := (limit.isLimit F).homIso_hom f /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and an explicit componentwise description of cones with cone point `W`. -/ def limit.homIso' (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ { p : ∀ j, W ⟶ F.obj j // ∀ {j j' : J} (f : j ⟶ j'), p j ≫ F.map f = p j' } := (limit.isLimit F).homIso' W theorem limit.lift_extend {F : J ⥤ C} [HasLimit F] (c : Cone F) {X : C} (f : X ⟶ c.pt) : limit.lift F (c.extend f) = f ≫ limit.lift F c := by cat_disch /-- If a functor `F` has a limit, so does any naturally isomorphic functor. -/ theorem hasLimit_of_iso {F G : J ⥤ C} [HasLimit F] (α : F ≅ G) : HasLimit G := HasLimit.mk { cone := (Cones.postcompose α.hom).obj (limit.cone F) isLimit := (IsLimit.postcomposeHomEquiv _ _).symm (limit.isLimit F) } @[deprecated (since := "2025-03-03")] alias hasLimitOfIso := hasLimit_of_iso theorem hasLimit_iff_of_iso {F G : J ⥤ C} (α : F ≅ G) : HasLimit F ↔ HasLimit G := ⟨fun _ ↦ hasLimit_of_iso α, fun _ ↦ hasLimit_of_iso α.symm⟩ -- See the construction of limits from products and equalizers -- for an example usage. /-- If a functor `G` has the same collection of cones as a functor `F` which has a limit, then `G` also has a limit. -/ theorem HasLimit.ofConesIso {J K : Type u₁} [Category.{v₁} J] [Category.{v₂} K] (F : J ⥤ C) (G : K ⥤ C) (h : F.cones ≅ G.cones) [HasLimit F] : HasLimit G := HasLimit.mk ⟨_, IsLimit.ofRepresentableBy ((limit.isLimit F).representableBy.ofIso h)⟩ /-- The limits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic, if the functors are naturally isomorphic. -/ def HasLimit.isoOfNatIso {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) : limit F ≅ limit G := IsLimit.conePointsIsoOfNatIso (limit.isLimit F) (limit.isLimit G) w @[reassoc (attr := simp)] theorem HasLimit.isoOfNatIso_hom_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) : (HasLimit.isoOfNatIso w).hom ≫ limit.π G j = limit.π F j ≫ w.hom.app j := IsLimit.conePointsIsoOfNatIso_hom_comp _ _ _ _ @[reassoc (attr := simp)] theorem HasLimit.isoOfNatIso_inv_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) : (HasLimit.isoOfNatIso w).inv ≫ limit.π F j = limit.π G j ≫ w.inv.app j := IsLimit.conePointsIsoOfNatIso_inv_comp _ _ _ _ @[reassoc (attr := simp)] theorem HasLimit.lift_isoOfNatIso_hom {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone F) (w : F ≅ G) : limit.lift F t ≫ (HasLimit.isoOfNatIso w).hom = limit.lift G ((Cones.postcompose w.hom).obj _) := IsLimit.lift_comp_conePointsIsoOfNatIso_hom _ _ _ @[reassoc (attr := simp)] theorem HasLimit.lift_isoOfNatIso_inv {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone G) (w : F ≅ G) : limit.lift G t ≫ (HasLimit.isoOfNatIso w).inv = limit.lift F ((Cones.postcompose w.inv).obj _) := IsLimit.lift_comp_conePointsIsoOfNatIso_inv _ _ _ /-- The limits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic, if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism. -/ def HasLimit.isoOfEquivalence {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : limit F ≅ limit G := IsLimit.conePointsIsoOfEquivalence (limit.isLimit F) (limit.isLimit G) e w @[simp] theorem HasLimit.isoOfEquivalence_hom_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) : (HasLimit.isoOfEquivalence e w).hom ≫ limit.π G k = limit.π F (e.inverse.obj k) ≫ w.inv.app (e.inverse.obj k) ≫ G.map (e.counit.app k) := by simp only [HasLimit.isoOfEquivalence, IsLimit.conePointsIsoOfEquivalence_hom] simp @[simp] theorem HasLimit.isoOfEquivalence_inv_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) : (HasLimit.isoOfEquivalence e w).inv ≫ limit.π F j = limit.π G (e.functor.obj j) ≫ w.hom.app j := by simp only [HasLimit.isoOfEquivalence] simp section Pre variable (F) variable [HasLimit F] (E : K ⥤ J) [HasLimit (E ⋙ F)] /-- The canonical morphism from the limit of `F` to the limit of `E ⋙ F`. -/ def limit.pre : limit F ⟶ limit (E ⋙ F) := limit.lift (E ⋙ F) ((limit.cone F).whisker E) @[reassoc (attr := simp)] theorem limit.pre_π (k : K) : limit.pre F E ≫ limit.π (E ⋙ F) k = limit.π F (E.obj k) := by erw [IsLimit.fac] rfl @[simp] theorem limit.lift_pre (c : Cone F) : limit.lift F c ≫ limit.pre F E = limit.lift (E ⋙ F) (c.whisker E) := by ext; simp variable {L : Type u₃} [Category.{v₃} L] variable (D : L ⥤ K) @[simp] theorem limit.pre_pre [h : HasLimit (D ⋙ E ⋙ F)] : haveI : HasLimit ((D ⋙ E) ⋙ F) := h limit.pre F E ≫ limit.pre (E ⋙ F) D = limit.pre F (D ⋙ E) := by haveI : HasLimit ((D ⋙ E) ⋙ F) := h ext j; erw [assoc, limit.pre_π, limit.pre_π, limit.pre_π]; rfl variable {E F} /-- - If we have particular limit cones available for `E ⋙ F` and for `F`, we obtain a formula for `limit.pre F E`. -/ theorem limit.pre_eq (s : LimitCone (E ⋙ F)) (t : LimitCone F) : limit.pre F E = (limit.isoLimitCone t).hom ≫ s.isLimit.lift (t.cone.whisker E) ≫ (limit.isoLimitCone s).inv := by cat_disch end Pre section Post variable {D : Type u'} [Category.{v'} D] variable (F : J ⥤ C) [HasLimit F] (G : C ⥤ D) [HasLimit (F ⋙ G)] /-- The canonical morphism from `G` applied to the limit of `F` to the limit of `F ⋙ G`. -/ def limit.post : G.obj (limit F) ⟶ limit (F ⋙ G) := limit.lift (F ⋙ G) (G.mapCone (limit.cone F)) @[reassoc (attr := simp)] theorem limit.post_π (j : J) : limit.post F G ≫ limit.π (F ⋙ G) j = G.map (limit.π F j) := by erw [IsLimit.fac] rfl @[simp] theorem limit.lift_post (c : Cone F) : G.map (limit.lift F c) ≫ limit.post F G = limit.lift (F ⋙ G) (G.mapCone c) := by ext rw [assoc, limit.post_π, ← G.map_comp, limit.lift_π, limit.lift_π] rfl @[simp] theorem limit.post_post {E : Type u''} [Category.{v''} E] (H : D ⥤ E) [h : HasLimit ((F ⋙ G) ⋙ H)] : -- H G (limit F) ⟶ H (limit (F ⋙ G)) ⟶ limit ((F ⋙ G) ⋙ H) equals -- H G (limit F) ⟶ limit (F ⋙ (G ⋙ H)) haveI : HasLimit (F ⋙ G ⋙ H) := h H.map (limit.post F G) ≫ limit.post (F ⋙ G) H = limit.post F (G ⋙ H) := by haveI : HasLimit (F ⋙ G ⋙ H) := h ext; erw [assoc, limit.post_π, ← H.map_comp, limit.post_π, limit.post_π]; rfl end Post theorem limit.pre_post {D : Type u'} [Category.{v'} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D) [HasLimit F] [HasLimit (E ⋙ F)] [HasLimit (F ⋙ G)] [h : HasLimit ((E ⋙ F) ⋙ G)] :-- G (limit F) ⟶ G (limit (E ⋙ F)) ⟶ limit ((E ⋙ F) ⋙ G) vs -- G (limit F) ⟶ limit F ⋙ G ⟶ limit (E ⋙ (F ⋙ G)) or haveI : HasLimit (E ⋙ F ⋙ G) := h G.map (limit.pre F E) ≫ limit.post (E ⋙ F) G = limit.post F G ≫ limit.pre (F ⋙ G) E := by haveI : HasLimit (E ⋙ F ⋙ G) := h ext; erw [assoc, limit.post_π, ← G.map_comp, limit.pre_π, assoc, limit.pre_π, limit.post_π] open CategoryTheory.Equivalence instance hasLimit_equivalence_comp (e : K ≌ J) [HasLimit F] : HasLimit (e.functor ⋙ F) := HasLimit.mk { cone := Cone.whisker e.functor (limit.cone F) isLimit := IsLimit.whiskerEquivalence (limit.isLimit F) e } -- not entirely sure why this is needed /-- If a `E ⋙ F` has a limit, and `E` is an equivalence, we can construct a limit of `F`. -/ theorem hasLimit_of_equivalence_comp (e : K ≌ J) [HasLimit (e.functor ⋙ F)] : HasLimit F := by haveI : HasLimit (e.inverse ⋙ e.functor ⋙ F) := Limits.hasLimit_equivalence_comp e.symm apply hasLimit_of_iso (e.invFunIdAssoc F) @[deprecated (since := "2025-03-02")] alias hasLimitEquivalenceComp := hasLimit_equivalence_comp @[deprecated (since := "2025-03-02")] alias hasLimitOfEquivalenceComp := hasLimit_of_equivalence_comp -- `hasLimitCompEquivalence` and `hasLimitOfCompEquivalence` -- are proved in `CategoryTheory/Adjunction/Limits.lean`. section LimFunctor variable [HasLimitsOfShape J C] section /-- `limit F` is functorial in `F`, when `C` has all limits of shape `J`. -/ @[simps] def lim : (J ⥤ C) ⥤ C where obj F := limit F map α := limMap α map_id F := by apply Limits.limit.hom_ext; intro j simp map_comp α β := by apply Limits.limit.hom_ext; intro j simp [assoc] end variable {G : J ⥤ C} (α : F ⟶ G) theorem limMap_eq : limMap α = lim.map α := rfl theorem limit.map_pre [HasLimitsOfShape K C] (E : K ⥤ J) : lim.map α ≫ limit.pre G E = limit.pre F E ≫ lim.map (whiskerLeft E α) := by ext simp theorem limit.map_pre' [HasLimitsOfShape K C] (F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟶ E₂) : limit.pre F E₂ = limit.pre F E₁ ≫ lim.map (whiskerRight α F) := by ext1; simp theorem limit.id_pre (F : J ⥤ C) : limit.pre F (𝟭 _) = lim.map (Functor.leftUnitor F).inv := by cat_disch theorem limit.map_post {D : Type u'} [Category.{v'} D] [HasLimitsOfShape J D] (H : C ⥤ D) : /- H (limit F) ⟶ H (limit G) ⟶ limit (G ⋙ H) vs H (limit F) ⟶ limit (F ⋙ H) ⟶ limit (G ⋙ H) -/ H.map (limMap α) ≫ limit.post G H = limit.post F H ≫ limMap (whiskerRight α H) := by ext simp only [whiskerRight_app, limMap_π, assoc, limit.post_π_assoc, limit.post_π, ← H.map_comp] /-- The isomorphism between morphisms from `W` to the cone point of the limit cone for `F` and cones over `F` with cone point `W` is natural in `F`. -/ def limYoneda : lim ⋙ yoneda ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} ≅ CategoryTheory.cones J C := NatIso.ofComponents fun F => NatIso.ofComponents fun W => limit.homIso F (unop W) /-- The constant functor and limit functor are adjoint to each other -/ def constLimAdj : (const J : C ⥤ J ⥤ C) ⊣ lim := Adjunction.mk' { homEquiv := fun c g ↦ { toFun := fun f => limit.lift _ ⟨c, f⟩ invFun := fun f => { app := fun _ => f ≫ limit.π _ _ } left_inv := by cat_disch right_inv := by cat_disch } unit := { app := fun _ => limit.lift _ ⟨_, 𝟙 _⟩ } counit := { app := fun g => { app := limit.π _ } } } instance : IsRightAdjoint (lim : (J ⥤ C) ⥤ C) := ⟨_, ⟨constLimAdj⟩⟩ end LimFunctor instance limMap_mono' {F G : J ⥤ C} [HasLimitsOfShape J C] (α : F ⟶ G) [Mono α] : Mono (limMap α) := (lim : (J ⥤ C) ⥤ C).map_mono α instance limMap_mono {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) [∀ j, Mono (α.app j)] : Mono (limMap α) := ⟨fun {Z} u v h => limit.hom_ext fun j => (cancel_mono (α.app j)).1 <| by simpa using h =≫ limit.π _ j⟩ section Adjunction variable {L : (J ⥤ C) ⥤ C} (adj : Functor.const _ ⊣ L) /- The fact that the existence of limits of shape `J` is equivalent to the existence of a right adjoint to the constant functor `C ⥤ (J ⥤ C)` is obtained in the file `Mathlib/CategoryTheory/Limits/ConeCategory.lean`: see the lemma `hasLimitsOfShape_iff_isLeftAdjoint_const`. In the definitions below, given an adjunction `adj : Functor.const _ ⊣ (L : (J ⥤ C) ⥤ C)`, we directly construct a limit cone for any `F : J ⥤ C`. -/ /-- The limit cone obtained from a right adjoint of the constant functor. -/ @[simps] noncomputable def coneOfAdj (F : J ⥤ C) : Cone F where pt := L.obj F π := adj.counit.app F /-- The cones defined by `coneOfAdj` are limit cones. -/ @[simps] def isLimitConeOfAdj (F : J ⥤ C) : IsLimit (coneOfAdj adj F) where lift s := adj.homEquiv _ _ s.π fac s j := by have eq := NatTrans.congr_app (adj.counit.naturality s.π) j have eq' := NatTrans.congr_app (adj.left_triangle_components s.pt) j dsimp at eq eq' ⊢ rw [adj.homEquiv_unit, assoc, eq, reassoc_of% eq'] uniq s m hm := (adj.homEquiv _ _).symm.injective (by ext j; simpa using hm j) end Adjunction /-- We can transport limits of shape `J` along an equivalence `J ≌ J'`. -/ theorem hasLimitsOfShape_of_equivalence {J' : Type u₂} [Category.{v₂} J'] (e : J ≌ J') [HasLimitsOfShape J C] : HasLimitsOfShape J' C := by constructor intro F apply hasLimit_of_equivalence_comp e variable (C) /-- A category that has larger limits also has smaller limits. -/ theorem hasLimitsOfSizeOfUnivLE [UnivLE.{v₂, v₁}] [UnivLE.{u₂, u₁}] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfSize.{v₂, u₂} C where has_limits_of_shape J {_} := hasLimitsOfShape_of_equivalence ((ShrinkHoms.equivalence J).trans <| Shrink.equivalence _).symm /-- `hasLimitsOfSizeShrink.{v u} C` tries to obtain `HasLimitsOfSize.{v u} C` from some other `HasLimitsOfSize C`. -/ theorem hasLimitsOfSizeShrink [HasLimitsOfSize.{max v₁ v₂, max u₁ u₂} C] : HasLimitsOfSize.{v₁, u₁} C := hasLimitsOfSizeOfUnivLE.{max v₁ v₂, max u₁ u₂} C instance (priority := 100) hasSmallestLimitsOfHasLimits [HasLimits C] : HasLimitsOfSize.{0, 0} C := hasLimitsOfSizeShrink.{0, 0} C end Limit section Colimit /-- `ColimitCocone F` contains a cocone over `F` together with the information that it is a colimit. -/ structure ColimitCocone (F : J ⥤ C) where /-- The cocone itself -/ cocone : Cocone F /-- The proof that it is the colimit cocone -/ isColimit : IsColimit cocone /-- `HasColimit F` represents the mere existence of a colimit for `F`. -/ class HasColimit (F : J ⥤ C) : Prop where mk' :: /-- There exists a colimit for `F` -/ exists_colimit : Nonempty (ColimitCocone F) theorem HasColimit.mk {F : J ⥤ C} (d : ColimitCocone F) : HasColimit F := ⟨Nonempty.intro d⟩ /-- Use the axiom of choice to extract explicit `ColimitCocone F` from `HasColimit F`. -/ def getColimitCocone (F : J ⥤ C) [HasColimit F] : ColimitCocone F := Classical.choice <| HasColimit.exists_colimit variable (J C) /-- `C` has colimits of shape `J` if there exists a colimit for every functor `F : J ⥤ C`. -/ class HasColimitsOfShape : Prop where /-- All `F : J ⥤ C` have colimits for a fixed `J` -/ has_colimit : ∀ F : J ⥤ C, HasColimit F := by infer_instance /-- `C` has all colimits of size `v₁ u₁` (`HasColimitsOfSize.{v₁ u₁} C`) if it has colimits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasColimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All `F : J ⥤ C` have colimits for all small `J` -/ has_colimits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasColimitsOfShape J C := by infer_instance /-- `C` has all (small) colimits if it has colimits of every shape that is as big as its hom-sets. -/ abbrev HasColimits (C : Type u) [Category.{v} C] : Prop := HasColimitsOfSize.{v, v} C theorem HasColimits.hasColimitsOfShape {C : Type u} [Category.{v} C] [HasColimits C] (J : Type v) [Category.{v} J] : HasColimitsOfShape J C := HasColimitsOfSize.has_colimits_of_shape J variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasColimitOfHasColimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasColimitsOfShape J C] (F : J ⥤ C) : HasColimit F := HasColimitsOfShape.has_colimit F -- see Note [lower instance priority] instance (priority := 100) hasColimitsOfShapeOfHasColimitsOfSize {J : Type u₁} [Category.{v₁} J] [HasColimitsOfSize.{v₁, u₁} C] : HasColimitsOfShape J C := HasColimitsOfSize.has_colimits_of_shape J -- Interface to the `HasColimit` class. /-- An arbitrary choice of colimit cocone of a functor. -/ def colimit.cocone (F : J ⥤ C) [HasColimit F] : Cocone F := (getColimitCocone F).cocone /-- An arbitrary choice of colimit object of a functor. -/ def colimit (F : J ⥤ C) [HasColimit F] := (colimit.cocone F).pt /-- The coprojection from a value of the functor to the colimit object. -/ def colimit.ι (F : J ⥤ C) [HasColimit F] (j : J) : F.obj j ⟶ colimit F := (colimit.cocone F).ι.app j @[reassoc] theorem colimit.eqToHom_comp_ι (F : J ⥤ C) [HasColimit F] {j j' : J} (hj : j = j') : eqToHom (by subst hj; rfl) ≫ colimit.ι F j = colimit.ι F j' := by subst hj simp @[simp] theorem colimit.cocone_ι {F : J ⥤ C} [HasColimit F] (j : J) : (colimit.cocone F).ι.app j = colimit.ι _ j := rfl @[simp] theorem colimit.cocone_x {F : J ⥤ C} [HasColimit F] : (colimit.cocone F).pt = colimit F := rfl @[reassoc (attr := simp)] theorem colimit.w (F : J ⥤ C) [HasColimit F] {j j' : J} (f : j ⟶ j') : F.map f ≫ colimit.ι F j' = colimit.ι F j := (colimit.cocone F).w f /-- Evidence that the arbitrary choice of cocone is a colimit cocone. -/ def colimit.isColimit (F : J ⥤ C) [HasColimit F] : IsColimit (colimit.cocone F) := (getColimitCocone F).isColimit /-- The morphism from the colimit object to the cone point of any other cocone. -/ def colimit.desc (F : J ⥤ C) [HasColimit F] (c : Cocone F) : colimit F ⟶ c.pt := (colimit.isColimit F).desc c @[simp] theorem colimit.isColimit_desc {F : J ⥤ C} [HasColimit F] (c : Cocone F) : (colimit.isColimit F).desc c = colimit.desc F c := rfl /-- We have lots of lemmas describing how to simplify `colimit.ι F j ≫ _`, and combined with `colimit.ext` we rely on these lemmas for many calculations. However, since `Category.assoc` is a `@[simp]` lemma, often expressions are right associated, and it's hard to apply these lemmas about `colimit.ι`. We thus use `reassoc` to define additional `@[simp]` lemmas, with an arbitrary extra morphism. (see `Tactic/reassoc_axiom.lean`) -/ @[reassoc (attr := simp)] theorem colimit.ι_desc {F : J ⥤ C} [HasColimit F] (c : Cocone F) (j : J) : colimit.ι F j ≫ colimit.desc F c = c.ι.app j := IsColimit.fac _ c j /-- Functoriality of colimits. Usually this morphism should be accessed through `colim.map`, but may be needed separately when you have specified colimits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def colimMap {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) : colimit F ⟶ colimit G := IsColimit.map (colimit.isColimit F) _ α @[reassoc (attr := simp)] theorem ι_colimMap {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) (j : J) : colimit.ι F j ≫ colimMap α = α.app j ≫ colimit.ι G j := colimit.ι_desc _ j /-- The cocone morphism from the arbitrary choice of colimit cocone to any cocone. -/ def colimit.coconeMorphism {F : J ⥤ C} [HasColimit F] (c : Cocone F) : colimit.cocone F ⟶ c := (colimit.isColimit F).descCoconeMorphism c @[simp] theorem colimit.coconeMorphism_hom {F : J ⥤ C} [HasColimit F] (c : Cocone F) : (colimit.coconeMorphism c).hom = colimit.desc F c := rfl theorem colimit.ι_coconeMorphism {F : J ⥤ C} [HasColimit F] (c : Cocone F) (j : J) : colimit.ι F j ≫ (colimit.coconeMorphism c).hom = c.ι.app j := by simp @[reassoc (attr := simp)] theorem colimit.comp_coconePointUniqueUpToIso_hom {F : J ⥤ C} [HasColimit F] {c : Cocone F} (hc : IsColimit c) (j : J) : colimit.ι F j ≫ (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) hc).hom = c.ι.app j := IsColimit.comp_coconePointUniqueUpToIso_hom _ _ _ @[reassoc (attr := simp)] theorem colimit.comp_coconePointUniqueUpToIso_inv {F : J ⥤ C} [HasColimit F] {c : Cocone F} (hc : IsColimit c) (j : J) : colimit.ι F j ≫ (IsColimit.coconePointUniqueUpToIso hc (colimit.isColimit _)).inv = c.ι.app j := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ _ theorem colimit.existsUnique {F : J ⥤ C} [HasColimit F] (t : Cocone F) : ∃! d : colimit F ⟶ t.pt, ∀ j, colimit.ι F j ≫ d = t.ι.app j := (colimit.isColimit F).existsUnique _ /-- Given any other colimit cocone for `F`, the chosen `colimit F` is isomorphic to the cocone point. -/ def colimit.isoColimitCocone {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) : colimit F ≅ t.cocone.pt := IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) t.isColimit @[reassoc (attr := simp)] theorem colimit.isoColimitCocone_ι_hom {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) (j : J) : colimit.ι F j ≫ (colimit.isoColimitCocone t).hom = t.cocone.ι.app j := by dsimp [colimit.isoColimitCocone, IsColimit.coconePointUniqueUpToIso] simp @[reassoc (attr := simp)] theorem colimit.isoColimitCocone_ι_inv {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) (j : J) : t.cocone.ι.app j ≫ (colimit.isoColimitCocone t).inv = colimit.ι F j := by dsimp [colimit.isoColimitCocone, IsColimit.coconePointUniqueUpToIso] simp @[ext] theorem colimit.hom_ext {F : J ⥤ C} [HasColimit F] {X : C} {f f' : colimit F ⟶ X} (w : ∀ j, colimit.ι F j ≫ f = colimit.ι F j ≫ f') : f = f' := (colimit.isColimit F).hom_ext w @[simp] theorem colimit.desc_cocone {F : J ⥤ C} [HasColimit F] : colimit.desc F (colimit.cocone F) = 𝟙 (colimit F) := (colimit.isColimit _).desc_self /-- The isomorphism (in `Type`) between morphisms from the colimit object to a specified object `W`, and cocones with cone point `W`. -/ def colimit.homIso (F : J ⥤ C) [HasColimit F] (W : C) : ULift.{u₁} (colimit F ⟶ W : Type v) ≅ F.cocones.obj W := (colimit.isColimit F).homIso W @[simp] theorem colimit.homIso_hom (F : J ⥤ C) [HasColimit F] {W : C} (f : ULift (colimit F ⟶ W)) : (colimit.homIso F W).hom f = (colimit.cocone F).ι ≫ (const J).map f.down := (colimit.isColimit F).homIso_hom f /-- The isomorphism (in `Type`) between morphisms from the colimit object to a specified object `W`, and an explicit componentwise description of cocones with cone point `W`. -/ def colimit.homIso' (F : J ⥤ C) [HasColimit F] (W : C) : ULift.{u₁} (colimit F ⟶ W : Type v) ≅ { p : ∀ j, F.obj j ⟶ W // ∀ {j j'} (f : j ⟶ j'), F.map f ≫ p j' = p j } := (colimit.isColimit F).homIso' W theorem colimit.desc_extend (F : J ⥤ C) [HasColimit F] (c : Cocone F) {X : C} (f : c.pt ⟶ X) : colimit.desc F (c.extend f) = colimit.desc F c ≫ f := by ext1; rw [← Category.assoc]; simp -- This has the isomorphism pointing in the opposite direction than in `has_limit_of_iso`. -- This is intentional; it seems to help with elaboration. /-- If `F` has a colimit, so does any naturally isomorphic functor. -/ theorem hasColimit_of_iso {F G : J ⥤ C} [HasColimit F] (α : G ≅ F) : HasColimit G := HasColimit.mk { cocone := (Cocones.precompose α.hom).obj (colimit.cocone F) isColimit := (IsColimit.precomposeHomEquiv _ _).symm (colimit.isColimit F) } @[deprecated (since := "2025-03-03")] alias hasColimitOfIso := hasColimit_of_iso theorem hasColimit_iff_of_iso {F G : J ⥤ C} (α : F ≅ G) : HasColimit F ↔ HasColimit G := ⟨fun _ ↦ hasColimit_of_iso α.symm, fun _ ↦ hasColimit_of_iso α⟩ /-- If a functor `G` has the same collection of cocones as a functor `F` which has a colimit, then `G` also has a colimit. -/ theorem HasColimit.ofCoconesIso {K : Type u₁} [Category.{v₂} K] (F : J ⥤ C) (G : K ⥤ C) (h : F.cocones ≅ G.cocones) [HasColimit F] : HasColimit G := HasColimit.mk ⟨_, IsColimit.ofCorepresentableBy ((colimit.isColimit F).corepresentableBy.ofIso h)⟩ /-- The colimits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic, if the functors are naturally isomorphic. -/ def HasColimit.isoOfNatIso {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) : colimit F ≅ colimit G := IsColimit.coconePointsIsoOfNatIso (colimit.isColimit F) (colimit.isColimit G) w @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_ι_hom {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) (j : J) : colimit.ι F j ≫ (HasColimit.isoOfNatIso w).hom = w.hom.app j ≫ colimit.ι G j := IsColimit.comp_coconePointsIsoOfNatIso_hom _ _ _ _ @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_ι_inv {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) (j : J) : colimit.ι G j ≫ (HasColimit.isoOfNatIso w).inv = w.inv.app j ≫ colimit.ι F j := IsColimit.comp_coconePointsIsoOfNatIso_inv _ _ _ _ @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_hom_desc {F G : J ⥤ C} [HasColimit F] [HasColimit G] (t : Cocone G) (w : F ≅ G) : (HasColimit.isoOfNatIso w).hom ≫ colimit.desc G t = colimit.desc F ((Cocones.precompose w.hom).obj _) := IsColimit.coconePointsIsoOfNatIso_hom_desc _ _ _ @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_inv_desc {F G : J ⥤ C} [HasColimit F] [HasColimit G] (t : Cocone F) (w : F ≅ G) : (HasColimit.isoOfNatIso w).inv ≫ colimit.desc F t = colimit.desc G ((Cocones.precompose w.inv).obj _) := IsColimit.coconePointsIsoOfNatIso_inv_desc _ _ _ /-- The colimits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic, if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism. -/ def HasColimit.isoOfEquivalence {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : colimit F ≅ colimit G := IsColimit.coconePointsIsoOfEquivalence (colimit.isColimit F) (colimit.isColimit G) e w @[simp] theorem HasColimit.isoOfEquivalence_hom_π {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) : colimit.ι F j ≫ (HasColimit.isoOfEquivalence e w).hom = F.map (e.unit.app j) ≫ w.inv.app _ ≫ colimit.ι G _ := by simp [HasColimit.isoOfEquivalence] @[simp] theorem HasColimit.isoOfEquivalence_inv_π {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) : colimit.ι G k ≫ (HasColimit.isoOfEquivalence e w).inv = G.map (e.counitInv.app k) ≫ w.hom.app (e.inverse.obj k) ≫ colimit.ι F (e.inverse.obj k) := by simp [HasColimit.isoOfEquivalence, IsColimit.coconePointsIsoOfEquivalence_inv] section Pre variable (F) variable [HasColimit F] (E : K ⥤ J) [HasColimit (E ⋙ F)] /-- The canonical morphism from the colimit of `E ⋙ F` to the colimit of `F`. -/ def colimit.pre : colimit (E ⋙ F) ⟶ colimit F := colimit.desc (E ⋙ F) ((colimit.cocone F).whisker E) @[reassoc (attr := simp)] theorem colimit.ι_pre (k : K) : colimit.ι (E ⋙ F) k ≫ colimit.pre F E = colimit.ι F (E.obj k) := by erw [IsColimit.fac] rfl @[reassoc (attr := simp)] theorem colimit.ι_inv_pre [IsIso (pre F E)] (k : K) : colimit.ι F (E.obj k) ≫ inv (colimit.pre F E) = colimit.ι (E ⋙ F) k := by simp [IsIso.comp_inv_eq] @[reassoc (attr := simp)] theorem colimit.pre_desc (c : Cocone F) : colimit.pre F E ≫ colimit.desc F c = colimit.desc (E ⋙ F) (c.whisker E) := by ext; rw [← assoc, colimit.ι_pre]; simp variable {L : Type u₃} [Category.{v₃} L] variable (D : L ⥤ K) @[simp] theorem colimit.pre_pre [h : HasColimit (D ⋙ E ⋙ F)] : haveI : HasColimit ((D ⋙ E) ⋙ F) := h colimit.pre (E ⋙ F) D ≫ colimit.pre F E = colimit.pre F (D ⋙ E) := by ext j rw [← assoc, colimit.ι_pre, colimit.ι_pre] haveI : HasColimit ((D ⋙ E) ⋙ F) := h exact (colimit.ι_pre F (D ⋙ E) j).symm variable {E F} /-- - If we have particular colimit cocones available for `E ⋙ F` and for `F`, we obtain a formula for `colimit.pre F E`. -/ theorem colimit.pre_eq (s : ColimitCocone (E ⋙ F)) (t : ColimitCocone F) : colimit.pre F E = (colimit.isoColimitCocone s).hom ≫ s.isColimit.desc (t.cocone.whisker E) ≫ (colimit.isoColimitCocone t).inv := by cat_disch end Pre section Post variable {D : Type u'} [Category.{v'} D] variable (F) variable [HasColimit F] (G : C ⥤ D) [HasColimit (F ⋙ G)] /-- The canonical morphism from `G` applied to the colimit of `F ⋙ G` to `G` applied to the colimit of `F`. -/ def colimit.post : colimit (F ⋙ G) ⟶ G.obj (colimit F) := colimit.desc (F ⋙ G) (G.mapCocone (colimit.cocone F)) @[reassoc (attr := simp)] theorem colimit.ι_post (j : J) : colimit.ι (F ⋙ G) j ≫ colimit.post F G = G.map (colimit.ι F j) := by erw [IsColimit.fac] rfl @[simp] theorem colimit.post_desc (c : Cocone F) : colimit.post F G ≫ G.map (colimit.desc F c) = colimit.desc (F ⋙ G) (G.mapCocone c) := by ext rw [← assoc, colimit.ι_post, ← G.map_comp, colimit.ι_desc, colimit.ι_desc] rfl @[simp] theorem colimit.post_post {E : Type u''} [Category.{v''} E] (H : D ⥤ E) -- H G (colimit F) ⟶ H (colimit (F ⋙ G)) ⟶ colimit ((F ⋙ G) ⋙ H) equals -- H G (colimit F) ⟶ colimit (F ⋙ (G ⋙ H)) [h : HasColimit ((F ⋙ G) ⋙ H)] : haveI : HasColimit (F ⋙ G ⋙ H) := h colimit.post (F ⋙ G) H ≫ H.map (colimit.post F G) = colimit.post F (G ⋙ H) := by ext j rw [← assoc, colimit.ι_post, ← H.map_comp, colimit.ι_post] haveI : HasColimit (F ⋙ G ⋙ H) := h exact (colimit.ι_post F (G ⋙ H) j).symm end Post theorem colimit.pre_post {D : Type u'} [Category.{v'} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D) [HasColimit F] [HasColimit (E ⋙ F)] [HasColimit (F ⋙ G)] [h : HasColimit ((E ⋙ F) ⋙ G)] : -- G (colimit F) ⟶ G (colimit (E ⋙ F)) ⟶ colimit ((E ⋙ F) ⋙ G) vs -- G (colimit F) ⟶ colimit F ⋙ G ⟶ colimit (E ⋙ (F ⋙ G)) or haveI : HasColimit (E ⋙ F ⋙ G) := h colimit.post (E ⋙ F) G ≫ G.map (colimit.pre F E) = colimit.pre (F ⋙ G) E ≫ colimit.post F G := by ext j rw [← assoc, colimit.ι_post, ← G.map_comp, colimit.ι_pre, ← assoc] haveI : HasColimit (E ⋙ F ⋙ G) := h erw [colimit.ι_pre (F ⋙ G) E j, colimit.ι_post] open CategoryTheory.Equivalence instance hasColimit_equivalence_comp (e : K ≌ J) [HasColimit F] : HasColimit (e.functor ⋙ F) := HasColimit.mk { cocone := Cocone.whisker e.functor (colimit.cocone F) isColimit := IsColimit.whiskerEquivalence (colimit.isColimit F) e } /-- If a `E ⋙ F` has a colimit, and `E` is an equivalence, we can construct a colimit of `F`. -/ theorem hasColimit_of_equivalence_comp (e : K ≌ J) [HasColimit (e.functor ⋙ F)] : HasColimit F := by haveI : HasColimit (e.inverse ⋙ e.functor ⋙ F) := Limits.hasColimit_equivalence_comp e.symm apply hasColimit_of_iso (e.invFunIdAssoc F).symm section ColimFunctor variable [HasColimitsOfShape J C] section /-- `colimit F` is functorial in `F`, when `C` has all colimits of shape `J`. -/ @[simps] def colim : (J ⥤ C) ⥤ C where obj F := colimit F map α := colimMap α end variable {G : J ⥤ C} (α : F ⟶ G) theorem colimMap_eq : colimMap α = colim.map α := rfl @[reassoc] theorem colimit.ι_map (j : J) : colimit.ι F j ≫ colim.map α = α.app j ≫ colimit.ι G j := by simp @[reassoc (attr := simp)] theorem colimit.map_desc (c : Cocone G) : colimMap α ≫ colimit.desc G c = colimit.desc F ((Cocones.precompose α).obj c) := by ext j simp [colimit.ι_desc, colimit.ι_desc] theorem colimit.pre_map [HasColimitsOfShape K C] (E : K ⥤ J) : colimit.pre F E ≫ colim.map α = colim.map (whiskerLeft E α) ≫ colimit.pre G E := by ext rw [← assoc, colimit.ι_pre, colimit.ι_map, ← assoc, colimit.ι_map, assoc, colimit.ι_pre] rfl theorem colimit.pre_map' [HasColimitsOfShape K C] (F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟶ E₂) : colimit.pre F E₁ = colim.map (whiskerRight α F) ≫ colimit.pre F E₂ := by ext1 simp theorem colimit.pre_id (F : J ⥤ C) : colimit.pre F (𝟭 _) = colim.map (Functor.leftUnitor F).hom := by cat_disch theorem colimit.map_post {D : Type u'} [Category.{v'} D] [HasColimitsOfShape J D] (H : C ⥤ D) : /- H (colimit F) ⟶ H (colimit G) ⟶ colimit (G ⋙ H) vs H (colimit F) ⟶ colimit (F ⋙ H) ⟶ colimit (G ⋙ H) -/ colimit.post F H ≫ H.map (colim.map α) = colim.map (whiskerRight α H) ≫ colimit.post G H := by ext rw [← assoc, colimit.ι_post, ← H.map_comp, colimit.ι_map, H.map_comp] rw [← assoc, colimit.ι_map, assoc, colimit.ι_post] rfl /-- The isomorphism between morphisms from the cone point of the colimit cocone for `F` to `W` and cocones over `F` with cone point `W` is natural in `F`. -/ def colimCoyoneda : colim.op ⋙ coyoneda ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} ≅ CategoryTheory.cocones J C := NatIso.ofComponents fun F => NatIso.ofComponents fun W => colimit.homIso (unop F) W /-- The colimit functor and constant functor are adjoint to each other -/ def colimConstAdj : (colim : (J ⥤ C) ⥤ C) ⊣ const J := Adjunction.mk' { homEquiv := fun f c ↦ { toFun := fun g => { app := fun _ => colimit.ι _ _ ≫ g } invFun := fun g => colimit.desc _ ⟨_, g⟩ left_inv := by cat_disch right_inv := by cat_disch } unit := { app := fun g => { app := colimit.ι _ } } counit := { app := fun _ => colimit.desc _ ⟨_, 𝟙 _⟩ } } instance : IsLeftAdjoint (colim : (J ⥤ C) ⥤ C) := ⟨_, ⟨colimConstAdj⟩⟩ end ColimFunctor instance colimMap_epi' {F G : J ⥤ C} [HasColimitsOfShape J C] (α : F ⟶ G) [Epi α] : Epi (colimMap α) := (colim : (J ⥤ C) ⥤ C).map_epi α instance colimMap_epi {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) [∀ j, Epi (α.app j)] : Epi (colimMap α) := ⟨fun {Z} u v h => colimit.hom_ext fun j => (cancel_epi (α.app j)).1 <| by simpa using colimit.ι _ j ≫= h⟩ /-- We can transport colimits of shape `J` along an equivalence `J ≌ J'`. -/ theorem hasColimitsOfShape_of_equivalence {J' : Type u₂} [Category.{v₂} J'] (e : J ≌ J') [HasColimitsOfShape J C] : HasColimitsOfShape J' C := by constructor intro F apply hasColimit_of_equivalence_comp e variable (C) /-- A category that has larger colimits also has smaller colimits. -/ theorem hasColimitsOfSizeOfUnivLE [UnivLE.{v₂, v₁}] [UnivLE.{u₂, u₁}] [HasColimitsOfSize.{v₁, u₁} C] : HasColimitsOfSize.{v₂, u₂} C where has_colimits_of_shape J {_} := hasColimitsOfShape_of_equivalence ((ShrinkHoms.equivalence J).trans <| Shrink.equivalence _).symm /-- `hasColimitsOfSizeShrink.{v u} C` tries to obtain `HasColimitsOfSize.{v u} C` from some other `HasColimitsOfSize C`. -/ theorem hasColimitsOfSizeShrink [HasColimitsOfSize.{max v₁ v₂, max u₁ u₂} C] : HasColimitsOfSize.{v₁, u₁} C := hasColimitsOfSizeOfUnivLE.{max v₁ v₂, max u₁ u₂} C instance (priority := 100) hasSmallestColimitsOfHasColimits [HasColimits C] : HasColimitsOfSize.{0, 0} C := hasColimitsOfSizeShrink.{0, 0} C end Colimit section Opposite /-- If `t : Cone F` is a limit cone, then `t.op : Cocone F.op` is a colimit cocone. -/ def IsLimit.op {t : Cone F} (P : IsLimit t) : IsColimit t.op where desc s := (P.lift s.unop).op fac s j := congrArg Quiver.Hom.op (P.fac s.unop (unop j)) uniq s m w := by dsimp rw [← P.uniq s.unop m.unop] · rfl · dsimp intro j rw [← w] rfl /-- If `t : Cocone F` is a colimit cocone, then `t.op : Cone F.op` is a limit cone. -/ def IsColimit.op {t : Cocone F} (P : IsColimit t) : IsLimit t.op where lift s := (P.desc s.unop).op fac s j := congrArg Quiver.Hom.op (P.fac s.unop (unop j)) uniq s m w := by dsimp rw [← P.uniq s.unop m.unop] · rfl · dsimp intro j rw [← w] rfl /-- If `t : Cone F.op` is a limit cone, then `t.unop : Cocone F` is a colimit cocone. -/ def IsLimit.unop {t : Cone F.op} (P : IsLimit t) : IsColimit t.unop where desc s := (P.lift s.op).unop fac s j := congrArg Quiver.Hom.unop (P.fac s.op (.op j)) uniq s m w := by dsimp rw [← P.uniq s.op m.op] · rfl · dsimp intro j rw [← w] rfl /-- If `t : Cocone F.op` is a colimit cocone, then `t.unop : Cone F` is a limit cone. -/ def IsColimit.unop {t : Cocone F.op} (P : IsColimit t) : IsLimit t.unop where lift s := (P.desc s.op).unop fac s j := congrArg Quiver.Hom.unop (P.fac s.op (.op j)) uniq s m w := by dsimp rw [← P.uniq s.op m.op] · rfl · dsimp intro j rw [← w] rfl /-- If `t.op : Cocone F.op` is a colimit cocone, then `t : Cone F` is a limit cone. -/ def isLimitOfOp {t : Cone F} (P : IsColimit t.op) : IsLimit t := P.unop /-- If `t.op : Cone F.op` is a limit cone, then `t : Cocone F` is a colimit cocone. -/ def isColimitOfOp {t : Cocone F} (P : IsLimit t.op) : IsColimit t := P.unop /-- If `t.unop : Cocone F` is a colimit cocone, then `t : Cone F.op` is a limit cone. -/ def isLimitOfUnop {t : Cone F.op} (P : IsColimit t.unop) : IsLimit t := P.op /-- If `t.unop : Cone F` is a limit cone, then `t : Cocone F.op` is a colimit cocone. -/ def isColimitOfUnop {t : Cocone F.op} (P : IsLimit t.unop) : IsColimit t := P.op /-- `t : Cone F` is a limit cone if and only if `t.op : Cocone F.op` is a colimit cocone. -/ def isLimitEquivIsColimitOp {t : Cone F} : IsLimit t ≃ IsColimit t.op := equivOfSubsingletonOfSubsingleton IsLimit.op isLimitOfOp /-- `t : Cocone F` is a colimit cocone if and only if `t.op : Cone F.op` is a limit cone. -/ def isColimitEquivIsLimitOp {t : Cocone F} : IsColimit t ≃ IsLimit t.op := equivOfSubsingletonOfSubsingleton IsColimit.op isColimitOfOp end Opposite end Limits end CategoryTheory
Counterexamples.lean
import Counterexamples.AharoniKorman import Counterexamples.CanonicallyOrderedCommSemiringTwoMul import Counterexamples.CharPZeroNeCharZero import Counterexamples.CliffordAlgebraNotInjective import Counterexamples.Cyclotomic105 import Counterexamples.DirectSumIsInternal import Counterexamples.DiscreteTopologyNonDiscreteUniformity import Counterexamples.GameMultiplication import Counterexamples.Girard import Counterexamples.HomogeneousPrimeNotPrime import Counterexamples.IrrationalPowerOfIrrational import Counterexamples.LinearOrderWithPosMulPosEqZero import Counterexamples.MapFloor import Counterexamples.MonicNonRegular import Counterexamples.Motzkin import Counterexamples.OrderedCancelAddCommMonoidWithBounds import Counterexamples.Phillips import Counterexamples.Pseudoelement import Counterexamples.QuadraticForm import Counterexamples.SeminormLatticeNotDistrib import Counterexamples.SorgenfreyLine import Counterexamples.TopologistsSineCurve import Counterexamples.ZeroDivisorsInAddMonoidAlgebras
Basic.lean
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang, Kevin Buzzard -/ import Mathlib.CategoryTheory.Preadditive.Projective.Basic /-! # Injective objects and categories with enough injectives An object `J` is injective iff every morphism into `J` can be obtained by extending a monomorphism. -/ noncomputable section open CategoryTheory Limits Opposite universe v v₁ v₂ u₁ u₂ namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] /-- An object `J` is injective iff every morphism into `J` can be obtained by extending a monomorphism. -/ class Injective (J : C) : Prop where factors : ∀ {X Y : C} (g : X ⟶ J) (f : X ⟶ Y) [Mono f], ∃ h : Y ⟶ J, f ≫ h = g attribute [inherit_doc Injective] Injective.factors lemma Limits.IsZero.injective {X : C} (h : IsZero X) : Injective X where factors _ _ _ := ⟨h.from_ _, h.eq_of_tgt _ _⟩ section /-- An injective presentation of an object `X` consists of a monomorphism `f : X ⟶ J` to some injective object `J`. -/ structure InjectivePresentation (X : C) where J : C injective : Injective J := by infer_instance f : X ⟶ J mono : Mono f := by infer_instance open InjectivePresentation in attribute [inherit_doc InjectivePresentation] J injective f mono attribute [instance] InjectivePresentation.injective InjectivePresentation.mono variable (C) /-- A category "has enough injectives" if every object has an injective presentation, i.e. if for every object `X` there is an injective object `J` and a monomorphism `X ↪ J`. -/ class EnoughInjectives : Prop where presentation : ∀ X : C, Nonempty (InjectivePresentation X) attribute [inherit_doc EnoughInjectives] EnoughInjectives.presentation end namespace Injective /-- Let `J` be injective and `g` a morphism into `J`, then `g` can be factored through any monomorphism. -/ def factorThru {J X Y : C} [Injective J] (g : X ⟶ J) (f : X ⟶ Y) [Mono f] : Y ⟶ J := (Injective.factors g f).choose @[reassoc (attr := simp)] theorem comp_factorThru {J X Y : C} [Injective J] (g : X ⟶ J) (f : X ⟶ Y) [Mono f] : f ≫ factorThru g f = g := (Injective.factors g f).choose_spec section open ZeroObject instance zero_injective [HasZeroObject C] : Injective (0 : C) := (isZero_zero C).injective end theorem of_iso {P Q : C} (i : P ≅ Q) (hP : Injective P) : Injective Q := { factors := fun g f mono => by obtain ⟨h, h_eq⟩ := @Injective.factors C _ P _ _ _ (g ≫ i.inv) f mono refine ⟨h ≫ i.hom, ?_⟩ rw [← Category.assoc, h_eq, Category.assoc, Iso.inv_hom_id, Category.comp_id] } theorem iso_iff {P Q : C} (i : P ≅ Q) : Injective P ↔ Injective Q := ⟨of_iso i, of_iso i.symm⟩ /-- The axiom of choice says that every nonempty type is an injective object in `Type`. -/ instance (X : Type u₁) [Nonempty X] : Injective X where factors g f mono := ⟨fun z => by classical exact if h : z ∈ Set.range f then g (Classical.choose h) else Nonempty.some inferInstance, by ext y classical change dite (f y ∈ Set.range f) (fun h => g (Classical.choose h)) _ = _ split_ifs <;> rename_i h · rw [mono_iff_injective] at mono rw [mono (Classical.choose_spec h)] · exact False.elim (h ⟨y, rfl⟩)⟩ instance Type.enoughInjectives : EnoughInjectives (Type u₁) where presentation X := Nonempty.intro { J := WithBot X injective := inferInstance f := Option.some mono := by rw [mono_iff_injective] exact Option.some_injective X } instance {P Q : C} [HasBinaryProduct P Q] [Injective P] [Injective Q] : Injective (P ⨯ Q) where factors g f mono := by use Limits.prod.lift (factorThru (g ≫ Limits.prod.fst) f) (factorThru (g ≫ Limits.prod.snd) f) simp only [prod.comp_lift, comp_factorThru] ext · simp only [prod.lift_fst] · simp only [prod.lift_snd] instance {β : Type v} (c : β → C) [HasProduct c] [∀ b, Injective (c b)] : Injective (∏ᶜ c) where factors g f mono := by refine ⟨Pi.lift fun b => factorThru (g ≫ Pi.π c _) f, ?_⟩ ext b simp only [Category.assoc, limit.lift_π, Fan.mk_π_app, comp_factorThru] instance {P Q : C} [HasZeroMorphisms C] [HasBinaryBiproduct P Q] [Injective P] [Injective Q] : Injective (P ⊞ Q) where factors g f mono := by refine ⟨biprod.lift (factorThru (g ≫ biprod.fst) f) (factorThru (g ≫ biprod.snd) f), ?_⟩ ext · simp only [Category.assoc, biprod.lift_fst, comp_factorThru] · simp only [Category.assoc, biprod.lift_snd, comp_factorThru] instance {β : Type v} (c : β → C) [HasZeroMorphisms C] [HasBiproduct c] [∀ b, Injective (c b)] : Injective (⨁ c) where factors g f mono := by refine ⟨biproduct.lift fun b => factorThru (g ≫ biproduct.π _ _) f, ?_⟩ ext simp only [Category.assoc, biproduct.lift_π, comp_factorThru] instance {P : Cᵒᵖ} [Projective P] : Injective no_index (unop P) where factors g f mono := ⟨(@Projective.factorThru Cᵒᵖ _ P _ _ _ g.op f.op _).unop, Quiver.Hom.op_inj (by simp)⟩ instance {J : Cᵒᵖ} [Injective J] : Projective no_index (unop J) where factors f e he := ⟨(@factorThru Cᵒᵖ _ J _ _ _ f.op e.op _).unop, Quiver.Hom.op_inj (by simp)⟩ instance {J : C} [Injective J] : Projective (op J) where factors f e epi := ⟨(@factorThru C _ J _ _ _ f.unop e.unop _).op, Quiver.Hom.unop_inj (by simp)⟩ instance {P : C} [Projective P] : Injective (op P) where factors g f mono := ⟨(@Projective.factorThru C _ P _ _ _ g.unop f.unop _).op, Quiver.Hom.unop_inj (by simp)⟩ theorem injective_iff_projective_op {J : C} : Injective J ↔ Projective (op J) := ⟨fun _ => inferInstance, fun _ => show Injective (unop (op J)) from inferInstance⟩ theorem projective_iff_injective_op {P : C} : Projective P ↔ Injective (op P) := ⟨fun _ => inferInstance, fun _ => show Projective (unop (op P)) from inferInstance⟩ theorem injective_iff_preservesEpimorphisms_yoneda_obj (J : C) : Injective J ↔ (yoneda.obj J).PreservesEpimorphisms := by rw [injective_iff_projective_op, Projective.projective_iff_preservesEpimorphisms_coyoneda_obj] exact Functor.preservesEpimorphisms.iso_iff (Coyoneda.objOpOp _) section Adjunction open CategoryTheory.Functor variable {D : Type u₂} [Category.{v₂} D] variable {L : C ⥤ D} {R : D ⥤ C} [PreservesMonomorphisms L] theorem injective_of_adjoint (adj : L ⊣ R) (J : D) [Injective J] : Injective <| R.obj J := ⟨fun {A} {_} g f im => ⟨adj.homEquiv _ _ (factorThru ((adj.homEquiv A J).symm g) (L.map f)), (adj.homEquiv _ _).symm.injective (by simp [Adjunction.homEquiv_unit, Adjunction.homEquiv_counit])⟩⟩ end Adjunction section EnoughInjectives variable [EnoughInjectives C] /-- `Injective.under X` provides an arbitrarily chosen injective object equipped with a monomorphism `Injective.ι : X ⟶ Injective.under X`. -/ def under (X : C) : C := (EnoughInjectives.presentation X).some.J instance injective_under (X : C) : Injective (under X) := (EnoughInjectives.presentation X).some.injective /-- The monomorphism `Injective.ι : X ⟶ Injective.under X` from the arbitrarily chosen injective object under `X`. -/ def ι (X : C) : X ⟶ under X := (EnoughInjectives.presentation X).some.f instance ι_mono (X : C) : Mono (ι X) := (EnoughInjectives.presentation X).some.mono section variable [HasZeroMorphisms C] {X Y : C} (f : X ⟶ Y) [HasCokernel f] /-- When `C` has enough injectives, the object `Injective.syzygies f` is an arbitrarily chosen injective object under `cokernel f`. -/ def syzygies : C := under (cokernel f) deriving Injective /-- When `C` has enough injective, `Injective.d f : Y ⟶ syzygies f` is the composition `cokernel.π f ≫ ι (cokernel f)`. (When `C` is abelian, we have `exact f (injective.d f)`.) -/ abbrev d : Y ⟶ syzygies f := cokernel.π f ≫ ι (cokernel f) end end EnoughInjectives instance [EnoughInjectives C] : EnoughProjectives Cᵒᵖ := ⟨fun X => ⟨{ p := _, f := (Injective.ι (unop X)).op}⟩⟩ instance [EnoughProjectives C] : EnoughInjectives Cᵒᵖ := ⟨fun X => ⟨⟨_, inferInstance, (Projective.π (unop X)).op, inferInstance⟩⟩⟩ theorem enoughProjectives_of_enoughInjectives_op [EnoughInjectives Cᵒᵖ] : EnoughProjectives C := ⟨fun X => ⟨{ p := _, f := (Injective.ι (op X)).unop} ⟩⟩ theorem enoughInjectives_of_enoughProjectives_op [EnoughProjectives Cᵒᵖ] : EnoughInjectives C := ⟨fun X => ⟨⟨_, inferInstance, (Projective.π (op X)).unop, inferInstance⟩⟩⟩ end Injective namespace Adjunction variable {D : Type*} [Category D] {F : C ⥤ D} {G : D ⥤ C} theorem map_injective (adj : F ⊣ G) [F.PreservesMonomorphisms] (I : D) (hI : Injective I) : Injective (G.obj I) := ⟨fun {X} {Y} f g => by intro rcases hI.factors (F.map f ≫ adj.counit.app _) (F.map g) with ⟨w,h⟩ use adj.unit.app Y ≫ G.map w rw [← unit_naturality_assoc, ← G.map_comp, h] simp⟩ theorem injective_of_map_injective (adj : F ⊣ G) [G.Full] [G.Faithful] (I : D) (hI : Injective (G.obj I)) : Injective I := ⟨fun {X} {Y} f g => by intro haveI : PreservesLimitsOfSize.{0, 0} G := adj.rightAdjoint_preservesLimits rcases hI.factors (G.map f) (G.map g) with ⟨w,h⟩ use inv (adj.counit.app _) ≫ F.map w ≫ adj.counit.app _ exact G.map_injective (by simpa)⟩ /-- Given an adjunction `F ⊣ G` such that `F` preserves monos, `G` maps an injective presentation of `X` to an injective presentation of `G(X)`. -/ def mapInjectivePresentation (adj : F ⊣ G) [F.PreservesMonomorphisms] (X : D) (I : InjectivePresentation X) : InjectivePresentation (G.obj X) where J := G.obj I.J injective := adj.map_injective _ I.injective f := G.map I.f mono := by haveI : PreservesLimitsOfSize.{0, 0} G := adj.rightAdjoint_preservesLimits; infer_instance /-- Given an adjunction `F ⊣ G` such that `F` preserves monomorphisms and is faithful, then any injective presentation of `F(X)` can be pulled back to an injective presentation of `X`. This is similar to `mapInjectivePresentation`. -/ def injectivePresentationOfMap (adj : F ⊣ G) [F.PreservesMonomorphisms] [F.ReflectsMonomorphisms] (X : C) (I : InjectivePresentation <| F.obj X) : InjectivePresentation X where J := G.obj I.J injective := Injective.injective_of_adjoint adj _ f := adj.homEquiv _ _ I.f end Adjunction namespace Functor variable {D : Type*} [Category D] (F : C ⥤ D) theorem injective_of_map_injective [F.Full] [F.Faithful] [F.PreservesMonomorphisms] {I : C} (hI : Injective (F.obj I)) : Injective I where factors g f _ := by obtain ⟨h, fac⟩ := hI.factors (F.map g) (F.map f) exact ⟨F.preimage h, F.map_injective (by simp [fac])⟩ end Functor /-- [Lemma 3.8](https://ncatlab.org/nlab/show/injective+object#preservation_of_injective_objects) -/ lemma EnoughInjectives.of_adjunction {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] {L : C ⥤ D} {R : D ⥤ C} (adj : L ⊣ R) [L.PreservesMonomorphisms] [L.ReflectsMonomorphisms] [EnoughInjectives D] : EnoughInjectives C where presentation _ := ⟨adj.injectivePresentationOfMap _ (EnoughInjectives.presentation _).some⟩ /-- An equivalence of categories transfers enough injectives. -/ lemma EnoughInjectives.of_equivalence {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] (e : C ⥤ D) [e.IsEquivalence] [EnoughInjectives D] : EnoughInjectives C := EnoughInjectives.of_adjunction (adj := e.asEquivalence.toAdjunction) namespace Equivalence variable {D : Type*} [Category D] (F : C ≌ D) theorem map_injective_iff (P : C) : Injective (F.functor.obj P) ↔ Injective P := ⟨F.symm.toAdjunction.injective_of_map_injective P, F.symm.toAdjunction.map_injective P⟩ /-- Given an equivalence of categories `F`, an injective presentation of `F(X)` induces an injective presentation of `X.` -/ def injectivePresentationOfMapInjectivePresentation (X : C) (I : InjectivePresentation (F.functor.obj X)) : InjectivePresentation X := F.toAdjunction.injectivePresentationOfMap _ I theorem enoughInjectives_iff (F : C ≌ D) : EnoughInjectives C ↔ EnoughInjectives D := ⟨fun h => h.of_adjunction F.symm.toAdjunction, fun h => h.of_adjunction F.toAdjunction⟩ end Equivalence end CategoryTheory
CompleteSublattice.lean
/- Copyright (c) 2024 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Data.Set.Functor import Mathlib.Order.Sublattice import Mathlib.Order.Hom.CompleteLattice /-! # Complete Sublattices This file defines complete sublattices. These are subsets of complete lattices which are closed under arbitrary suprema and infima. As a standard example one could take the complete sublattice of invariant submodules of some module with respect to a linear map. ## Main definitions: * `CompleteSublattice`: the definition of a complete sublattice * `CompleteSublattice.mk'`: an alternate constructor for a complete sublattice, demanding fewer hypotheses * `CompleteSublattice.instCompleteLattice`: a complete sublattice is a complete lattice * `CompleteSublattice.map`: complete sublattices push forward under complete lattice morphisms. * `CompleteSublattice.comap`: complete sublattices pull back under complete lattice morphisms. -/ open Function Set variable (α β : Type*) [CompleteLattice α] [CompleteLattice β] (f : CompleteLatticeHom α β) /-- A complete sublattice is a subset of a complete lattice that is closed under arbitrary suprema and infima. -/ structure CompleteSublattice extends Sublattice α where sSupClosed' : ∀ ⦃s : Set α⦄, s ⊆ carrier → sSup s ∈ carrier sInfClosed' : ∀ ⦃s : Set α⦄, s ⊆ carrier → sInf s ∈ carrier variable {α β} namespace CompleteSublattice /-- To check that a subset is a complete sublattice, one does not need to check that it is closed under binary `Sup` since this follows from the stronger `sSup` condition. Likewise for infima. -/ @[simps] def mk' (carrier : Set α) (sSupClosed' : ∀ ⦃s : Set α⦄, s ⊆ carrier → sSup s ∈ carrier) (sInfClosed' : ∀ ⦃s : Set α⦄, s ⊆ carrier → sInf s ∈ carrier) : CompleteSublattice α where carrier := carrier sSupClosed' := sSupClosed' sInfClosed' := sInfClosed' supClosed' := fun x hx y hy ↦ by suffices x ⊔ y = sSup {x, y} by exact this ▸ sSupClosed' (fun z hz ↦ by aesop) simp [sSup_singleton] infClosed' := fun x hx y hy ↦ by suffices x ⊓ y = sInf {x, y} by exact this ▸ sInfClosed' (fun z hz ↦ by aesop) simp [sInf_singleton] variable {L : CompleteSublattice α} instance instSetLike : SetLike (CompleteSublattice α) α where coe L := L.carrier coe_injective' L M h := by cases L; cases M; congr; exact SetLike.coe_injective' h theorem top_mem : ⊤ ∈ L := by simpa using L.sInfClosed' <| empty_subset _ theorem bot_mem : ⊥ ∈ L := by simpa using L.sSupClosed' <| empty_subset _ instance instBot : Bot L where bot := ⟨⊥, bot_mem⟩ instance instTop : Top L where top := ⟨⊤, top_mem⟩ instance instSupSet : SupSet L where sSup s := ⟨sSup <| (↑) '' s, L.sSupClosed' image_val_subset⟩ instance instInfSet : InfSet L where sInf s := ⟨sInf <| (↑) '' s, L.sInfClosed' image_val_subset⟩ theorem sSupClosed {s : Set α} (h : s ⊆ L) : sSup s ∈ L := L.sSupClosed' h theorem sInfClosed {s : Set α} (h : s ⊆ L) : sInf s ∈ L := L.sInfClosed' h @[simp] theorem coe_bot : (↑(⊥ : L) : α) = ⊥ := rfl @[simp] theorem coe_top : (↑(⊤ : L) : α) = ⊤ := rfl @[simp] theorem coe_sSup (S : Set L) : (↑(sSup S) : α) = sSup {(s : α) | s ∈ S} := rfl theorem coe_sSup' (S : Set L) : (↑(sSup S) : α) = ⨆ N ∈ S, (N : α) := by rw [coe_sSup, ← Set.image, sSup_image] @[simp] theorem coe_sInf (S : Set L) : (↑(sInf S) : α) = sInf {(s : α) | s ∈ S} := rfl theorem coe_sInf' (S : Set L) : (↑(sInf S) : α) = ⨅ N ∈ S, (N : α) := by rw [coe_sInf, ← Set.image, sInf_image] @[simp] theorem coe_iSup {ι} (f : ι → L) : (↑(iSup f) : α) = ⨆ i, (f i : α) := by rw [iSup, coe_sSup', iSup_range] @[simp] theorem coe_iInf {ι} (f : ι → L) : (↑(iInf f) : α) = ⨅ i, (f i : α) := by rw [iInf, coe_sInf', iInf_range] -- Redeclaring to get proper keys for these instances instance : Max {x // x ∈ L} := Sublattice.instSupCoe instance : Min {x // x ∈ L} := Sublattice.instInfCoe instance instCompleteLattice : CompleteLattice L := Subtype.coe_injective.completeLattice _ Sublattice.coe_sup Sublattice.coe_inf coe_sSup' coe_sInf' coe_top coe_bot /-- The natural complete lattice hom from a complete sublattice to the original lattice. -/ def subtype (L : CompleteSublattice α) : CompleteLatticeHom L α where toFun := Subtype.val map_sInf' _ := rfl map_sSup' _ := rfl @[simp, norm_cast] lemma coe_subtype (L : CompleteSublattice α) : L.subtype = ((↑) : L → α) := rfl lemma subtype_apply (L : Sublattice α) (a : L) : L.subtype a = a := rfl lemma subtype_injective (L : CompleteSublattice α) : Injective <| subtype L := Subtype.coe_injective /-- The push forward of a complete sublattice under a complete lattice hom is a complete sublattice. -/ @[simps] def map (L : CompleteSublattice α) : CompleteSublattice β where carrier := f '' L supClosed' := L.supClosed.image f infClosed' := L.infClosed.image f sSupClosed' := fun s hs ↦ by obtain ⟨t, ht, rfl⟩ := subset_image_iff.mp hs rw [← map_sSup] exact mem_image_of_mem f (sSupClosed ht) sInfClosed' := fun s hs ↦ by obtain ⟨t, ht, rfl⟩ := subset_image_iff.mp hs rw [← map_sInf] exact mem_image_of_mem f (sInfClosed ht) @[simp] theorem mem_map {b : β} : b ∈ L.map f ↔ ∃ a ∈ L, f a = b := Iff.rfl /-- The pull back of a complete sublattice under a complete lattice hom is a complete sublattice. -/ @[simps] def comap (L : CompleteSublattice β) : CompleteSublattice α where carrier := f ⁻¹' L supClosed' := L.supClosed.preimage f infClosed' := L.infClosed.preimage f sSupClosed' s hs := by simpa only [mem_preimage, map_sSup, SetLike.mem_coe] using sSupClosed <| mapsTo'.mp hs sInfClosed' s hs := by simpa only [mem_preimage, map_sInf, SetLike.mem_coe] using sInfClosed <| mapsTo'.mp hs @[simp] theorem mem_comap {L : CompleteSublattice β} {a : α} : a ∈ L.comap f ↔ f a ∈ L := Iff.rfl protected lemma disjoint_iff {a b : L} : Disjoint a b ↔ Disjoint (a : α) (b : α) := by rw [disjoint_iff, disjoint_iff, ← Sublattice.coe_inf, ← coe_bot (L := L), Subtype.coe_injective.eq_iff] protected lemma codisjoint_iff {a b : L} : Codisjoint a b ↔ Codisjoint (a : α) (b : α) := by rw [codisjoint_iff, codisjoint_iff, ← Sublattice.coe_sup, ← coe_top (L := L), Subtype.coe_injective.eq_iff] protected lemma isCompl_iff {a b : L} : IsCompl a b ↔ IsCompl (a : α) (b : α) := by rw [isCompl_iff, isCompl_iff, CompleteSublattice.disjoint_iff, CompleteSublattice.codisjoint_iff] lemma isComplemented_iff : ComplementedLattice L ↔ ∀ a ∈ L, ∃ b ∈ L, IsCompl a b := by refine ⟨fun ⟨h⟩ a ha ↦ ?_, fun h ↦ ⟨fun ⟨a, ha⟩ ↦ ?_⟩⟩ · obtain ⟨b, hb⟩ := h ⟨a, ha⟩ exact ⟨b, b.property, CompleteSublattice.isCompl_iff.mp hb⟩ · obtain ⟨b, hb, hb'⟩ := h a ha exact ⟨⟨b, hb⟩, CompleteSublattice.isCompl_iff.mpr hb'⟩ instance : Top (CompleteSublattice α) := ⟨mk' univ (fun _ _ ↦ mem_univ _) (fun _ _ ↦ mem_univ _)⟩ variable (L) /-- Copy of a complete sublattice with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (s : Set α) (hs : s = L) : CompleteSublattice α := mk' s (hs ▸ L.sSupClosed') (hs ▸ L.sInfClosed') @[simp, norm_cast] lemma coe_copy (s : Set α) (hs) : L.copy s hs = s := rfl lemma copy_eq (s : Set α) (hs) : L.copy s hs = L := SetLike.coe_injective hs end CompleteSublattice namespace CompleteLatticeHom /-- The range of a `CompleteLatticeHom` is a `CompleteSublattice`. See Note [range copy pattern]. -/ protected def range : CompleteSublattice β := (CompleteSublattice.map f ⊤).copy (range f) image_univ.symm theorem range_coe : (f.range : Set β) = range f := rfl /-- We can regard a complete lattice homomorphism as an order equivalence to its range. -/ @[simps! apply] noncomputable def toOrderIsoRangeOfInjective (hf : Injective f) : α ≃o f.range := (orderEmbeddingOfInjective f hf).orderIso end CompleteLatticeHom
MeanErgodic.lean
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.InnerProductSpace.Projection.Submodule import Mathlib.Dynamics.BirkhoffSum.NormedSpace /-! # Von Neumann Mean Ergodic Theorem in a Hilbert Space In this file we prove the von Neumann Mean Ergodic Theorem for an operator in a Hilbert space. It says that for a contracting linear self-map `f : E →ₗ[𝕜] E` of a Hilbert space, the Birkhoff averages ``` birkhoffAverage 𝕜 f id N x = (N : 𝕜)⁻¹ • ∑ n ∈ Finset.range N, f^[n] x ``` converge to the orthogonal projection of `x` to the subspace of fixed points of `f`, see `ContinuousLinearMap.tendsto_birkhoffAverage_orthogonalProjection`. -/ open Filter Finset Function Bornology open scoped Topology variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] /-- **Von Neumann Mean Ergodic Theorem**, a version for a normed space. Let `f : E → E` be a contracting linear self-map of a normed space. Let `S` be the subspace of fixed points of `f`. Let `g : E → S` be a continuous linear projection, `g|_S=id`. If the range of `f - id` is dense in the kernel of `g`, then for each `x`, the Birkhoff averages ``` birkhoffAverage 𝕜 f id N x = (N : 𝕜)⁻¹ • ∑ n ∈ Finset.range N, f^[n] x ``` converge to `g x` as `N → ∞`. Usually, this fact is not formulated as a separate lemma. I chose to do it in order to isolate parts of the proof that do not rely on the inner product space structure. -/ theorem LinearMap.tendsto_birkhoffAverage_of_ker_subset_closure [NormedSpace 𝕜 E] (f : E →ₗ[𝕜] E) (hf : LipschitzWith 1 f) (g : E →L[𝕜] LinearMap.eqLocus f 1) (hg_proj : ∀ x : LinearMap.eqLocus f 1, g x = x) (hg_ker : (LinearMap.ker g : Set E) ⊆ closure (LinearMap.range (f - 1))) (x : E) : Tendsto (birkhoffAverage 𝕜 f _root_.id · x) atTop (𝓝 (g x)) := by /- Any point can be represented as a sum of `y ∈ LinearMap.ker g` and a fixed point `z`. -/ obtain ⟨y, hy, z, hz, rfl⟩ : ∃ y, g y = 0 ∧ ∃ z, IsFixedPt f z ∧ x = y + z := ⟨x - g x, by simp [hg_proj], g x, (g x).2, by simp⟩ /- For a fixed point, the theorem is trivial, so it suffices to prove it for `y ∈ LinearMap.ker g`. -/ suffices Tendsto (birkhoffAverage 𝕜 f _root_.id · y) atTop (𝓝 0) by have hgz : g z = z := congr_arg Subtype.val (hg_proj ⟨z, hz⟩) simpa [hy, hgz, birkhoffAverage, birkhoffSum, Finset.sum_add_distrib, smul_add] using this.add (hz.tendsto_birkhoffAverage 𝕜 _root_.id) /- By continuity, it suffices to prove the theorem on a dense subset of `LinearMap.ker g`. By assumption, `LinearMap.range (f - 1)` is dense in the kernel of `g`, so it suffices to prove the theorem for `y = f x - x`. -/ have : IsClosed {x | Tendsto (birkhoffAverage 𝕜 f _root_.id · x) atTop (𝓝 0)} := isClosed_setOf_tendsto_birkhoffAverage 𝕜 hf uniformContinuous_id continuous_const refine closure_minimal (Set.forall_mem_range.2 fun x ↦ ?_) this (hg_ker hy) /- Finally, for `y = f x - x` the average is equal to the difference between averages along the orbits of `f x` and `x`, and most of the terms cancel. -/ have : IsBounded (Set.range (_root_.id <| f^[·] x)) := isBounded_iff_forall_norm_le.2 ⟨‖x‖, Set.forall_mem_range.2 fun n ↦ by have H : f^[n] 0 = 0 := iterate_map_zero (f : E →+ E) n simpa [H] using (hf.iterate n).dist_le_mul x 0⟩ have H : ∀ n x y, f^[n] (x - y) = f^[n] x - f^[n] y := iterate_map_sub (f : E →+ E) simpa [birkhoffAverage, birkhoffSum, Finset.sum_sub_distrib, smul_sub, H] using tendsto_birkhoffAverage_apply_sub_birkhoffAverage 𝕜 this variable [InnerProductSpace 𝕜 E] [CompleteSpace E] local notation "⟪" x ", " y "⟫" => inner 𝕜 x y /-- **Von Neumann Mean Ergodic Theorem** for an operator in a Hilbert space. For a contracting continuous linear self-map `f : E →L[𝕜] E` of a Hilbert space, `‖f‖ ≤ 1`, the Birkhoff averages ``` birkhoffAverage 𝕜 f id N x = (N : 𝕜)⁻¹ • ∑ n ∈ Finset.range N, f^[n] x ``` converge to the orthogonal projection of `x` to the subspace of fixed points of `f`. -/ theorem ContinuousLinearMap.tendsto_birkhoffAverage_orthogonalProjection (f : E →L[𝕜] E) (hf : ‖f‖ ≤ 1) (x : E) : Tendsto (birkhoffAverage 𝕜 f _root_.id · x) atTop (𝓝 <| (LinearMap.eqLocus f 1).orthogonalProjection x) := by /- Due to the previous theorem, it suffices to verify that the range of `f - 1` is dense in the orthogonal complement to the submodule of fixed points of `f`. -/ apply (f : E →ₗ[𝕜] E).tendsto_birkhoffAverage_of_ker_subset_closure (f.lipschitz.weaken hf) · exact (LinearMap.eqLocus f 1).orthogonalProjection_mem_subspace_eq_self · clear x /- In other words, we need to verify that any vector that is orthogonal to the range of `f - 1` is a fixed point of `f`. -/ rw [Submodule.ker_orthogonalProjection, ← Submodule.topologicalClosure_coe, SetLike.coe_subset_coe, ← Submodule.orthogonal_orthogonal_eq_closure] /- To verify this, we verify `‖f x‖ ≤ ‖x‖` (because `‖f‖ ≤ 1`) and `⟪f x, x⟫ = ‖x‖²`. -/ refine Submodule.orthogonal_le fun x hx ↦ eq_of_norm_le_re_inner_eq_norm_sq (𝕜 := 𝕜) ?_ ?_ · simpa using f.le_of_opNorm_le hf x · have : ∀ y, ⟪f y, x⟫ = ⟪y, x⟫ := by simpa [Submodule.mem_orthogonal, inner_sub_left, sub_eq_zero] using hx simp [this, ← norm_sq_eq_re_inner]
pgroup.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div. From mathcomp Require Import fintype bigop finset prime fingroup morphism. From mathcomp Require Import gfunctor automorphism quotient action gproduct. From mathcomp Require Import cyclic. (******************************************************************************) (* Standard group notions and constructions based on the prime decomposition *) (* of the order of the group or its elements: *) (* pi.-group G <=> G is a pi-group, i.e., pi.-nat #|G|. *) (* -> Recall that here and in the sequel pi can be a single prime p. *) (* pi.-subgroup(H) G <=> H is a pi-subgroup of G. *) (* := (H \subset G) && pi.-group H. *) (* -> This is provided mostly as a shorhand, with few associated lemmas. *) (* However, we do establish some results on maximal pi-subgroups. *) (* pi.-elt x <=> x is a pi-element. *) (* := pi.-nat #[x] or pi.-group <[x]>. *) (* x.`_pi == the pi-constituent of x: the (unique) pi-element *) (* y \in <[x]> such that x * y^-1 is a pi'-element. *) (* pi.-Hall(G) H <=> H is a Hall pi-subgroup of G. *) (* := [&& H \subset G, pi.-group H & pi^'.-nat #|G : H|]. *) (* -> This is also equivalent to H \subset G /\ #|H| = #|G|`_pi. *) (* p.-Sylow(G) P <=> P is a Sylow p-subgroup of G. *) (* -> This is the display and preferred input notation for p.-Hall(G) P. *) (* 'Syl_p(G) == the set of the p-Sylow subgroups of G. *) (* := [set P : {group _} | p.-Sylow(G) P]. *) (* p_group P <=> P is a p-group for some prime p. *) (* Hall G H <=> H is a Hall pi-subgroup of G for some pi. *) (* := coprime #|H| #|G : H| && (H \subset G). *) (* Sylow G P <=> P is a Sylow p-subgroup of G for some p. *) (* := p_group P && Hall G P. *) (* 'O_pi(G) == the pi-core (largest normal pi-subgroup) of G. *) (* pcore_mod pi G H == the pi-core of G mod H. *) (* := G :&: (coset H @*^-1 'O_pi(G / H)). *) (* 'O_{pi2, pi1}(G) == the pi1,pi2-core of G. *) (* := the pi1-core of G mod 'O_pi2(G). *) (* -> We have 'O_{pi2, pi1}(G) / 'O_pi2(G) = 'O_pi1(G / 'O_pi2(G)) *) (* with 'O_pi2(G) <| 'O_{pi2, pi1}(G) <| G. *) (* 'O_{pn, ..., p1}(G) == the p1, ..., pn-core of G. *) (* := the p1-core of G mod 'O_{pn, ..., p2}(G). *) (* Note that notions are always defined on sets even though their name *) (* indicates "group" properties; the actual definition of the notion never *) (* tests for the group property, since this property will always be provided *) (* by a (canonical) group structure. Similarly, p-group properties assume *) (* without test that p is a prime. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Section PgroupDefs. (* We defer the definition of the functors ('0_p(G), etc) because they need *) (* to quantify over the finGroupType explicitly. *) Variable gT : finGroupType. Implicit Type (x : gT) (A B : {set gT}) (pi : nat_pred) (p n : nat). Definition pgroup pi A := pi.-nat #|A|. Definition psubgroup pi A B := (B \subset A) && pgroup pi B. Definition p_group A := pgroup (pdiv #|A|) A. Definition p_elt pi x := pi.-nat #[x]. Definition constt x pi := x ^+ (chinese #[x]`_pi #[x]`_pi^' 1 0). Definition Hall A B := (B \subset A) && coprime #|B| #|A : B|. Definition pHall pi A B := [&& B \subset A, pgroup pi B & pi^'.-nat #|A : B|]. Definition Syl p A := [set P : {group gT} | pHall p A P]. Definition Sylow A B := p_group B && Hall A B. End PgroupDefs. Arguments pgroup {gT} pi%_N A%_g. Arguments psubgroup {gT} pi%_N A%_g B%_g. Arguments p_group {gT} A%_g. Arguments p_elt {gT} pi%_N x. Arguments constt {gT} x%_g pi%_N. Arguments Hall {gT} A%_g B%_g. Arguments pHall {gT} pi%_N A%_g B%_g. Arguments Syl {gT} p%_N A%_g. Arguments Sylow {gT} A%_g B%_g. Notation "pi .-group" := (pgroup pi) (format "pi .-group") : group_scope. Notation "pi .-subgroup ( A )" := (psubgroup pi A) (format "pi .-subgroup ( A )") : group_scope. Notation "pi .-elt" := (p_elt pi) (format "pi .-elt") : group_scope. Notation "x .`_ pi" := (constt x pi) (at level 3, left associativity, format "x .`_ pi") : group_scope. Notation "pi .-Hall ( G )" := (pHall pi G) (format "pi .-Hall ( G )") : group_scope. Notation "p .-Sylow ( G )" := (nat_pred_of_nat p).-Hall(G) (format "p .-Sylow ( G )") : group_scope. Notation "''Syl_' p ( G )" := (Syl p G) (p at level 2, format "''Syl_' p ( G )") : group_scope. Section PgroupProps. Variable gT : finGroupType. Implicit Types (pi rho : nat_pred) (p : nat). Implicit Types (x y z : gT) (A B C D : {set gT}) (G H K P Q R : {group gT}). Lemma trivgVpdiv G : G :=: 1 \/ (exists2 p, prime p & p %| #|G|). Proof. have [leG1|lt1G] := leqP #|G| 1; first by left; apply: card_le1_trivg. by right; exists (pdiv #|G|); rewrite ?pdiv_dvd ?pdiv_prime. Qed. Lemma prime_subgroupVti G H : prime #|G| -> G \subset H \/ H :&: G = 1. Proof. move=> prG; have [|[p p_pr pG]] := trivgVpdiv (H :&: G); first by right. left; rewrite (sameP setIidPr eqP) eqEcard subsetIr. suffices <-: p = #|G| by rewrite dvdn_leq ?cardG_gt0. by apply/eqP; rewrite -dvdn_prime2 // -(LagrangeI G H) setIC dvdn_mulr. Qed. Lemma pgroupE pi A : pi.-group A = pi.-nat #|A|. Proof. by []. Qed. Lemma sub_pgroup pi rho A : {subset pi <= rho} -> pi.-group A -> rho.-group A. Proof. by move=> pi_sub_rho; apply: sub_in_pnat (in1W pi_sub_rho). Qed. Lemma eq_pgroup pi rho A : pi =i rho -> pi.-group A = rho.-group A. Proof. exact: eq_pnat. Qed. Lemma eq_p'group pi rho A : pi =i rho -> pi^'.-group A = rho^'.-group A. Proof. by move/eq_negn; apply: eq_pnat. Qed. Lemma pgroupNK pi A : pi^'^'.-group A = pi.-group A. Proof. exact: pnatNK. Qed. Lemma pi_pgroup p pi A : p.-group A -> p \in pi -> pi.-group A. Proof. exact: pi_pnat. Qed. Lemma pi_p'group p pi A : pi.-group A -> p \in pi^' -> p^'.-group A. Proof. exact: pi_p'nat. Qed. Lemma pi'_p'group p pi A : pi^'.-group A -> p \in pi -> p^'.-group A. Proof. exact: pi'_p'nat. Qed. Lemma p'groupEpi p G : p^'.-group G = (p \notin \pi(G)). Proof. exact: p'natEpi (cardG_gt0 G). Qed. Lemma pgroup_pi G : \pi(G).-group G. Proof. by rewrite /=; apply: pnat_pi. Qed. Lemma partG_eq1 pi G : (#|G|`_pi == 1%N) = pi^'.-group G. Proof. exact: partn_eq1 (cardG_gt0 G). Qed. Lemma pgroupP pi G : reflect (forall p, prime p -> p %| #|G| -> p \in pi) (pi.-group G). Proof. exact: pnatP. Qed. Arguments pgroupP {pi G}. Lemma pgroup1 pi : pi.-group [1 gT]. Proof. by rewrite /pgroup cards1. Qed. Lemma pgroupS pi G H : H \subset G -> pi.-group G -> pi.-group H. Proof. by move=> sHG; apply: pnat_dvd (cardSg sHG). Qed. Lemma oddSg G H : H \subset G -> odd #|G| -> odd #|H|. Proof. by rewrite !odd_2'nat; apply: pgroupS. Qed. Lemma odd_pgroup_odd p G : odd p -> p.-group G -> odd #|G|. Proof. move=> p_odd pG; rewrite odd_2'nat (pi_pnat pG) // !inE. by case: eqP p_odd => // ->. Qed. Lemma card_pgroup p G : p.-group G -> #|G| = (p ^ logn p #|G|)%N. Proof. by move=> pG; rewrite -p_part part_pnat_id. Qed. Lemma properG_ltn_log p G H : p.-group G -> H \proper G -> logn p #|H| < logn p #|G|. Proof. move=> pG; rewrite properEneq eqEcard andbC ltnNge => /andP[sHG]. rewrite sHG /= {1}(card_pgroup pG) {1}(card_pgroup (pgroupS sHG pG)). by apply: contra; case: p {pG} => [|p] leHG; rewrite ?logn0 // leq_pexp2l. Qed. Lemma pgroupM pi G H : pi.-group (G * H) = pi.-group G && pi.-group H. Proof. have GH_gt0: 0 < #|G :&: H| := cardG_gt0 _. rewrite /pgroup -(mulnK #|_| GH_gt0) -mul_cardG -(LagrangeI G H) -mulnA. by rewrite mulKn // -(LagrangeI H G) setIC !pnatM andbCA; case: (pnat _). Qed. Lemma pgroupJ pi G x : pi.-group (G :^ x) = pi.-group G. Proof. by rewrite /pgroup cardJg. Qed. Lemma pgroup_p p P : p.-group P -> p_group P. Proof. case: (leqP #|P| 1); first by move=> /card_le1_trivg-> _; apply: pgroup1. move/pdiv_prime=> pr_q pgP; have:= pgroupP pgP _ pr_q (pdiv_dvd _). by rewrite /p_group => /eqnP->. Qed. Lemma p_groupP P : p_group P -> exists2 p, prime p & p.-group P. Proof. case: (ltnP 1 #|P|); first by move/pdiv_prime; exists (pdiv #|P|). by move/card_le1_trivg=> -> _; exists 2 => //; apply: pgroup1. Qed. Lemma pgroup_pdiv p G : p.-group G -> G :!=: 1 -> [/\ prime p, p %| #|G| & exists m, #|G| = p ^ m.+1]%N. Proof. move=> pG; rewrite trivg_card1; case/p_groupP: (pgroup_p pG) => q q_pr qG. move/implyP: (pgroupP pG q q_pr); case/p_natP: qG => // [[|m] ->] //. by rewrite dvdn_exp // => /eqnP <- _; split; rewrite ?dvdn_exp //; exists m. Qed. Lemma coprime_p'group p K R : coprime #|K| #|R| -> p.-group R -> R :!=: 1 -> p^'.-group K. Proof. move=> coKR pR ntR; have [p_pr _ [e oK]] := pgroup_pdiv pR ntR. by rewrite oK coprime_sym coprime_pexpl // prime_coprime // -p'natE in coKR. Qed. Lemma card_Hall pi G H : pi.-Hall(G) H -> #|H| = #|G|`_pi. Proof. case/and3P=> sHG piH pi'H; rewrite -(Lagrange sHG). by rewrite partnM ?Lagrange // part_pnat_id ?part_p'nat ?muln1. Qed. Lemma pHall_sub pi A B : pi.-Hall(A) B -> B \subset A. Proof. by case/andP. Qed. Lemma pHall_pgroup pi A B : pi.-Hall(A) B -> pi.-group B. Proof. by case/and3P. Qed. Lemma pHallP pi G H : reflect (H \subset G /\ #|H| = #|G|`_pi) (pi.-Hall(G) H). Proof. apply: (iffP idP) => [piH | [sHG oH]]. by split; [apply: pHall_sub piH | apply: card_Hall]. rewrite /pHall sHG -divgS // /pgroup oH. by rewrite -{2}(@partnC pi #|G|) ?mulKn ?part_pnat. Qed. Lemma pHallE pi G H : pi.-Hall(G) H = (H \subset G) && (#|H| == #|G|`_pi). Proof. by apply/pHallP/andP=> [] [->] /eqP. Qed. Lemma coprime_mulpG_Hall pi G K R : K * R = G -> pi.-group K -> pi^'.-group R -> pi.-Hall(G) K /\ pi^'.-Hall(G) R. Proof. move=> defG piK pi'R; apply/andP. rewrite /pHall piK -!divgS /= -defG ?mulG_subl ?mulg_subr //= pnatNK. by rewrite coprime_cardMg ?(pnat_coprime piK) // mulKn ?mulnK //; apply/and3P. Qed. Lemma coprime_mulGp_Hall pi G K R : K * R = G -> pi^'.-group K -> pi.-group R -> pi^'.-Hall(G) K /\ pi.-Hall(G) R. Proof. move=> defG pi'K piR; apply/andP; rewrite andbC; apply/andP. by apply: coprime_mulpG_Hall => //; rewrite -(comm_group_setP _) defG ?groupP. Qed. Lemma eq_in_pHall pi rho G H : {in \pi(G), pi =i rho} -> pi.-Hall(G) H = rho.-Hall(G) H. Proof. move=> eq_pi_rho; apply: andb_id2l => sHG. congr (_ && _); apply: eq_in_pnat => p piHp. by apply: eq_pi_rho; apply: (piSg sHG). by congr (~~ _); apply: eq_pi_rho; apply: (pi_of_dvd (dvdn_indexg G H)). Qed. Lemma eq_pHall pi rho G H : pi =i rho -> pi.-Hall(G) H = rho.-Hall(G) H. Proof. by move=> eq_pi_rho; apply: eq_in_pHall (in1W eq_pi_rho). Qed. Lemma eq_p'Hall pi rho G H : pi =i rho -> pi^'.-Hall(G) H = rho^'.-Hall(G) H. Proof. by move=> eq_pi_rho; apply: eq_pHall (eq_negn _). Qed. Lemma pHallNK pi G H : pi^'^'.-Hall(G) H = pi.-Hall(G) H. Proof. exact: eq_pHall (negnK _). Qed. Lemma subHall_Hall pi rho G H K : rho.-Hall(G) H -> {subset pi <= rho} -> pi.-Hall(H) K -> pi.-Hall(G) K. Proof. move=> hallH pi_sub_rho hallK. rewrite pHallE (subset_trans (pHall_sub hallK) (pHall_sub hallH)) /=. by rewrite (card_Hall hallK) (card_Hall hallH) partn_part. Qed. Lemma subHall_Sylow pi p G H P : pi.-Hall(G) H -> p \in pi -> p.-Sylow(H) P -> p.-Sylow(G) P. Proof. move=> hallH pi_p sylP; have [sHG piH _] := and3P hallH. rewrite pHallE (subset_trans (pHall_sub sylP) sHG) /=. by rewrite (card_Hall sylP) (card_Hall hallH) partn_part // => q; move/eqnP->. Qed. Lemma pHall_Hall pi A B : pi.-Hall(A) B -> Hall A B. Proof. by case/and3P=> sBA piB pi'B; rewrite /Hall sBA (pnat_coprime piB). Qed. Lemma Hall_pi G H : Hall G H -> \pi(H).-Hall(G) H. Proof. by case/andP=> sHG coHG /=; rewrite /pHall sHG /pgroup pnat_pi -?coprime_pi'. Qed. Lemma HallP G H : Hall G H -> exists pi, pi.-Hall(G) H. Proof. by exists \pi(H); apply: Hall_pi. Qed. Lemma sdprod_Hall G K H : K ><| H = G -> Hall G K = Hall G H. Proof. case/sdprod_context=> /andP[sKG _] sHG defG _ tiKH. by rewrite /Hall sKG sHG -!divgS // -defG TI_cardMg // coprime_sym mulKn ?mulnK. Qed. Lemma coprime_sdprod_Hall_l G K H : K ><| H = G -> coprime #|K| #|H| = Hall G K. Proof. case/sdprod_context=> /andP[sKG _] _ defG _ tiKH. by rewrite /Hall sKG -divgS // -defG TI_cardMg ?mulKn. Qed. Lemma coprime_sdprod_Hall_r G K H : K ><| H = G -> coprime #|K| #|H| = Hall G H. Proof. by move=> defG; rewrite (coprime_sdprod_Hall_l defG) (sdprod_Hall defG). Qed. Lemma compl_pHall pi K H G : pi.-Hall(G) K -> (H \in [complements to K in G]) = pi^'.-Hall(G) H. Proof. move=> hallK; apply/complP/idP=> [[tiKH mulKH] | hallH]. have [_] := andP hallK; rewrite /pHall pnatNK -{3}(invGid G) -mulKH mulG_subr. rewrite invMG !indexMg -indexgI andbC. by rewrite -[#|K : H|]indexgI setIC tiKH !indexg1. have [[sKG piK _] [sHG pi'H _]] := (and3P hallK, and3P hallH). have tiKH: K :&: H = 1 := coprime_TIg (pnat_coprime piK pi'H). split=> //; apply/eqP; rewrite eqEcard mul_subG //= TI_cardMg //. by rewrite (card_Hall hallK) (card_Hall hallH) partnC. Qed. Lemma compl_p'Hall pi K H G : pi^'.-Hall(G) K -> (H \in [complements to K in G]) = pi.-Hall(G) H. Proof. by move/compl_pHall->; apply: eq_pHall (negnK pi). Qed. Lemma sdprod_normal_p'HallP pi K H G : K <| G -> pi^'.-Hall(G) H -> reflect (K ><| H = G) (pi.-Hall(G) K). Proof. move=> nsKG hallH; rewrite -(compl_p'Hall K hallH). exact: sdprod_normal_complP. Qed. Lemma sdprod_normal_pHallP pi K H G : K <| G -> pi.-Hall(G) H -> reflect (K ><| H = G) (pi^'.-Hall(G) K). Proof. by move=> nsKG hallH; apply: sdprod_normal_p'HallP; rewrite ?pHallNK. Qed. Lemma pHallJ2 pi G H x : pi.-Hall(G :^ x) (H :^ x) = pi.-Hall(G) H. Proof. by rewrite !pHallE conjSg !cardJg. Qed. Lemma pHallJnorm pi G H x : x \in 'N(G) -> pi.-Hall(G) (H :^ x) = pi.-Hall(G) H. Proof. by move=> Nx; rewrite -{1}(normP Nx) pHallJ2. Qed. Lemma pHallJ pi G H x : x \in G -> pi.-Hall(G) (H :^ x) = pi.-Hall(G) H. Proof. by move=> Gx; rewrite -{1}(conjGid Gx) pHallJ2. Qed. Lemma HallJ G H x : x \in G -> Hall G (H :^ x) = Hall G H. Proof. by move=> Gx; rewrite /Hall -!divgI -{1 3}(conjGid Gx) conjSg -conjIg !cardJg. Qed. Lemma psubgroupJ pi G H x : x \in G -> pi.-subgroup(G) (H :^ x) = pi.-subgroup(G) H. Proof. by move=> Gx; rewrite /psubgroup pgroupJ -{1}(conjGid Gx) conjSg. Qed. Lemma p_groupJ P x : p_group (P :^ x) = p_group P. Proof. by rewrite /p_group cardJg pgroupJ. Qed. Lemma SylowJ G P x : x \in G -> Sylow G (P :^ x) = Sylow G P. Proof. by move=> Gx; rewrite /Sylow p_groupJ HallJ. Qed. Lemma p_Sylow p G P : p.-Sylow(G) P -> Sylow G P. Proof. by move=> pP; rewrite /Sylow (pgroup_p (pHall_pgroup pP)) (pHall_Hall pP). Qed. Lemma pHall_subl pi G K H : H \subset K -> K \subset G -> pi.-Hall(G) H -> pi.-Hall(K) H. Proof. by move=> sHK sKG; rewrite /pHall sHK => /and3P[_ ->]; apply/pnat_dvd/indexSg. Qed. Lemma Hall1 G : Hall G 1. Proof. by rewrite /Hall sub1G cards1 coprime1n. Qed. Lemma p_group1 : @p_group gT 1. Proof. by rewrite (@pgroup_p 2) ?pgroup1. Qed. Lemma Sylow1 G : Sylow G 1. Proof. by rewrite /Sylow p_group1 Hall1. Qed. Lemma SylowP G P : reflect (exists2 p, prime p & p.-Sylow(G) P) (Sylow G P). Proof. apply: (iffP idP) => [| [p _]]; last exact: p_Sylow. case/andP=> /p_groupP[p p_pr] /p_natP[[P1 _ | n oP /Hall_pi]]; last first. by rewrite /= oP pi_of_exp // (eq_pHall _ _ (pi_of_prime _)) //; exists p. have{p p_pr P1} ->: P :=: 1 by apply: card1_trivg; rewrite P1. pose p := pdiv #|G|.+1; have p_pr: prime p by rewrite pdiv_prime ?ltnS. exists p; rewrite // pHallE sub1G cards1 part_p'nat //. apply/pgroupP=> q pr_q qG; apply/eqnP=> def_q. have: p %| #|G| + 1 by rewrite addn1 pdiv_dvd. by rewrite dvdn_addr -def_q // Euclid_dvd1. Qed. Lemma p_elt_exp pi x m : pi.-elt (x ^+ m) = (#[x]`_pi^' %| m). Proof. apply/idP/idP=> [pi_xm | /dvdnP[q ->{m}]]; last first. rewrite mulnC; apply: pnat_dvd (part_pnat pi #[x]). by rewrite order_dvdn -expgM mulnC mulnA partnC // -order_dvdn dvdn_mulr. rewrite -(@Gauss_dvdr _ #[x ^+ m]); last first. by rewrite coprime_sym (pnat_coprime pi_xm) ?part_pnat. apply: (@dvdn_trans #[x]); first by rewrite -{2}[#[x]](partnC pi) ?dvdn_mull. by rewrite order_dvdn mulnC expgM expg_order. Qed. Lemma mem_p_elt pi x G : pi.-group G -> x \in G -> pi.-elt x. Proof. by move=> piG Gx; apply: pgroupS piG; rewrite cycle_subG. Qed. Lemma p_eltM_norm pi x y : x \in 'N(<[y]>) -> pi.-elt x -> pi.-elt y -> pi.-elt (x * y). Proof. move=> nyx pi_x pi_y; apply: (@mem_p_elt pi _ (<[x]> <*> <[y]>)%G). by rewrite /= norm_joinEl ?cycle_subG // pgroupM; apply/andP. by rewrite groupM // mem_gen // inE cycle_id ?orbT. Qed. Lemma p_eltM pi x y : commute x y -> pi.-elt x -> pi.-elt y -> pi.-elt (x * y). Proof. move=> cxy; apply: p_eltM_norm; apply: (subsetP (cent_sub _)). by rewrite cent_gen cent_set1; apply/cent1P. Qed. Lemma p_elt1 pi : pi.-elt (1 : gT). Proof. by rewrite /p_elt order1. Qed. Lemma p_eltV pi x : pi.-elt x^-1 = pi.-elt x. Proof. by rewrite /p_elt orderV. Qed. Lemma p_eltX pi x n : pi.-elt x -> pi.-elt (x ^+ n). Proof. by rewrite -{1}[x]expg1 !p_elt_exp dvdn1 => /eqnP->. Qed. Lemma p_eltJ pi x y : pi.-elt (x ^ y) = pi.-elt x. Proof. by congr pnat; rewrite orderJ. Qed. Lemma sub_p_elt pi1 pi2 x : {subset pi1 <= pi2} -> pi1.-elt x -> pi2.-elt x. Proof. by move=> pi12; apply: sub_in_pnat => q _; apply: pi12. Qed. Lemma eq_p_elt pi1 pi2 x : pi1 =i pi2 -> pi1.-elt x = pi2.-elt x. Proof. by move=> pi12; apply: eq_pnat. Qed. Lemma p_eltNK pi x : pi^'^'.-elt x = pi.-elt x. Proof. exact: pnatNK. Qed. Lemma eq_constt pi1 pi2 x : pi1 =i pi2 -> x.`_pi1 = x.`_pi2. Proof. move=> pi12; congr (x ^+ (chinese _ _ 1 0)); apply: eq_partn => // a. by congr (~~ _); apply: pi12. Qed. Lemma consttNK pi x : x.`_pi^'^' = x.`_pi. Proof. by rewrite /constt !partnNK. Qed. Lemma cycle_constt pi x : x.`_pi \in <[x]>. Proof. exact: mem_cycle. Qed. Lemma consttV pi x : (x^-1).`_pi = (x.`_pi)^-1. Proof. by rewrite /constt expgVn orderV. Qed. Lemma constt1 pi : 1.`_pi = 1 :> gT. Proof. exact: expg1n. Qed. Lemma consttJ pi x y : (x ^ y).`_pi = x.`_pi ^ y. Proof. by rewrite /constt orderJ conjXg. Qed. Lemma p_elt_constt pi x : pi.-elt x.`_pi. Proof. by rewrite p_elt_exp /chinese addn0 mul1n dvdn_mulr. Qed. Lemma consttC pi x : x.`_pi * x.`_pi^' = x. Proof. apply/eqP; rewrite -{3}[x]expg1 -expgD eq_expg_mod_order. rewrite partnNK -{5 6}(@partnC pi #[x]) // /chinese !addn0. by rewrite chinese_remainder ?chinese_modl ?chinese_modr ?coprime_partC ?eqxx. Qed. Lemma p'_elt_constt pi x : pi^'.-elt (x * (x.`_pi)^-1). Proof. by rewrite -{1}(consttC pi^' x) consttNK mulgK p_elt_constt. Qed. Lemma order_constt pi (x : gT) : #[x.`_pi] = #[x]`_pi. Proof. rewrite -{2}(consttC pi x) orderM; [|exact: commuteX2|]; last first. by apply: (@pnat_coprime pi); apply: p_elt_constt. by rewrite partnM // part_pnat_id ?part_p'nat ?muln1 //; apply: p_elt_constt. Qed. Lemma consttM pi x y : commute x y -> (x * y).`_pi = x.`_pi * y.`_pi. Proof. move=> cxy; pose m := #|<<[set x; y]>>|; have m_gt0: 0 < m := cardG_gt0 _. pose k := chinese m`_pi m`_pi^' 1 0. suffices kXpi z: z \in <<[set x; y]>> -> z.`_pi = z ^+ k. by rewrite !kXpi ?expgMn // ?groupM ?mem_gen // !inE eqxx ?orbT. move=> xyz; have{xyz} zm: #[z] %| m by rewrite cardSg ?cycle_subG. apply/eqP; rewrite eq_expg_mod_order -{3 4}[#[z]](partnC pi) //. rewrite chinese_remainder ?chinese_modl ?chinese_modr ?coprime_partC //. rewrite -!(modn_dvdm k (partn_dvd _ m_gt0 zm)). rewrite chinese_modl ?chinese_modr ?coprime_partC //. by rewrite !modn_dvdm ?partn_dvd ?eqxx. Qed. Lemma consttX pi x n : (x ^+ n).`_pi = x.`_pi ^+ n. Proof. elim: n => [|n IHn]; first exact: constt1. by rewrite !expgS consttM ?IHn //; apply: commuteX. Qed. Lemma constt1P pi x : reflect (x.`_pi = 1) (pi^'.-elt x). Proof. rewrite -{2}[x]expg1 p_elt_exp -order_constt consttNK order_dvdn expg1. exact: eqP. Qed. Lemma constt_p_elt pi x : pi.-elt x -> x.`_pi = x. Proof. by rewrite -p_eltNK -{3}(consttC pi x) => /constt1P->; rewrite mulg1. Qed. Lemma sub_in_constt pi1 pi2 x : {in \pi(#[x]), {subset pi1 <= pi2}} -> x.`_pi2.`_pi1 = x.`_pi1. Proof. move=> pi12; rewrite -{2}(consttC pi2 x) consttM; last exact: commuteX2. rewrite (constt1P _ x.`_pi2^' _) ?mulg1 //. apply: sub_in_pnat (p_elt_constt _ x) => p; rewrite order_constt => pi_p. by apply/contra/pi12; rewrite -[#[x]](partnC pi2^') // primesM // pi_p. Qed. Lemma prod_constt x : \prod_(0 <= p < #[x].+1) x.`_p = x. Proof. pose lp n := [pred p | p < n]. have: (lp #[x].+1).-elt x by apply/pnatP=> // p _; apply: dvdn_leq. move/constt_p_elt=> def_x; symmetry; rewrite -{1}def_x {def_x}. elim: _.+1 => [|p IHp]. by rewrite big_nil; apply/constt1P; apply/pgroupP. rewrite big_nat_recr //= -{}IHp -(consttC (lp p) x.`__); congr (_ * _). by rewrite sub_in_constt // => q _; apply: leqW. set y := _.`__; rewrite -(consttC p y) (constt1P p^' _ _) ?mulg1. by rewrite 2?sub_in_constt // => q _; move/eqnP->; rewrite !inE ?ltnn. rewrite /p_elt pnatNK !order_constt -partnI. apply: sub_in_pnat (part_pnat _ _) => q _. by rewrite !inE ltnS -leqNgt -eqn_leq. Qed. Lemma max_pgroupJ pi M G x : x \in G -> [max M | pi.-subgroup(G) M] -> [max M :^ x of M | pi.-subgroup(G) M]. Proof. move=> Gx /maxgroupP[piM maxM]; apply/maxgroupP. split=> [|H piH]; first by rewrite psubgroupJ. by rewrite -(conjsgKV x H) conjSg => /maxM/=-> //; rewrite psubgroupJ ?groupV. Qed. Lemma comm_sub_max_pgroup pi H M G : [max M | pi.-subgroup(G) M] -> pi.-group H -> H \subset G -> commute H M -> H \subset M. Proof. case/maxgroupP=> /andP[sMG piM] maxM piH sHG cHM. rewrite -(maxM (H <*> M)%G) /= comm_joingE ?(mulG_subl, mulG_subr) //. by rewrite /psubgroup pgroupM piM piH mul_subG. Qed. Lemma normal_sub_max_pgroup pi H M G : [max M | pi.-subgroup(G) M] -> pi.-group H -> H <| G -> H \subset M. Proof. move=> maxM piH /andP[sHG nHG]. apply: comm_sub_max_pgroup piH sHG _ => //; apply: commute_sym; apply: normC. by apply: subset_trans nHG; case/andP: (maxgroupp maxM). Qed. Lemma norm_sub_max_pgroup pi H M G : [max M | pi.-subgroup(G) M] -> pi.-group H -> H \subset G -> H \subset 'N(M) -> H \subset M. Proof. by move=> maxM piH sHG /normC; apply: comm_sub_max_pgroup piH sHG. Qed. Lemma sub_pHall pi H G K : pi.-Hall(G) H -> pi.-group K -> H \subset K -> K \subset G -> K :=: H. Proof. move=> hallH piK sHK sKG; apply/eqP; rewrite eq_sym eqEcard sHK. by rewrite (card_Hall hallH) -(part_pnat_id piK) dvdn_leq ?partn_dvd ?cardSg. Qed. Lemma Hall_max pi H G : pi.-Hall(G) H -> [max H | pi.-subgroup(G) H]. Proof. move=> hallH; apply/maxgroupP; split=> [|K /andP[sKG piK] sHK]. by rewrite /psubgroup; case/and3P: hallH => ->. exact: (sub_pHall hallH). Qed. Lemma pHall_id pi H G : pi.-Hall(G) H -> pi.-group G -> H :=: G. Proof. by move=> hallH piG; rewrite (sub_pHall hallH piG) ?(pHall_sub hallH). Qed. Lemma psubgroup1 pi G : pi.-subgroup(G) 1. Proof. by rewrite /psubgroup sub1G pgroup1. Qed. Lemma Cauchy p G : prime p -> p %| #|G| -> {x | x \in G & #[x] = p}. Proof. move=> p_pr; have [n] := ubnP #|G|; elim: n G => // n IHn G /ltnSE-leGn pG. pose xpG := [pred x in G | #[x] == p]. have [x /andP[Gx /eqP] | no_x] := pickP xpG; first by exists x. have{pG n leGn IHn} pZ: p %| #|'C_G(G)|. suffices /dvdn_addl <-: p %| #|G :\: 'C(G)| by rewrite cardsID. have /acts_sum_card_orbit <-: [acts G, on G :\: 'C(G) | 'J]. by apply/actsP=> x Gx y; rewrite !inE -!mem_conjgV -centJ conjGid ?groupV. elim/big_rec: _ => // _ _ /imsetP[x /setDP[Gx nCx] ->] /dvdn_addl->. have ltCx: 'C_G[x] \proper G by rewrite properE subsetIl subsetIidl sub_cent1. have /negP: ~ p %| #|'C_G[x]|. case/(IHn _ (leq_trans (proper_card ltCx) leGn))=> y /setIP[Gy _] /eqP-oy. by have /andP[] := no_x y. by apply/implyP; rewrite -index_cent1 indexgI implyNb -Euclid_dvdM ?LagrangeI. have [Q maxQ _]: {Q | [max Q | p^'.-subgroup('C_G(G)) Q] & 1%G \subset Q}. by apply: maxgroup_exists; apply: psubgroup1. case/andP: (maxgroupp maxQ) => sQC; rewrite /pgroup p'natE // => /negP[]. apply: dvdn_trans pZ (cardSg _); apply/subsetP=> x /setIP[Gx Cx]. rewrite -sub1set -gen_subG (normal_sub_max_pgroup maxQ) //; last first. rewrite /normal subsetI !cycle_subG ?Gx ?cents_norm ?subIset ?andbT //=. by rewrite centsC cycle_subG Cx. rewrite /pgroup p'natE //= -[#|_|]/#[x]; apply/dvdnP=> [[m oxm]]. have m_gt0: 0 < m by apply: dvdn_gt0 (order_gt0 x) _; rewrite oxm dvdn_mulr. case/idP: (no_x (x ^+ m)); rewrite /= groupX //= orderXgcd //= oxm. by rewrite gcdnC gcdnMr mulKn. Qed. (* These lemmas actually hold for maximal pi-groups, but below we'll *) (* derive from the Cauchy lemma that a normal max pi-group is Hall. *) Lemma sub_normal_Hall pi G H K : pi.-Hall(G) H -> H <| G -> K \subset G -> (K \subset H) = pi.-group K. Proof. move=> hallH nsHG sKG; apply/idP/idP=> [sKH | piK]. by rewrite (pgroupS sKH) ?(pHall_pgroup hallH). apply: norm_sub_max_pgroup (Hall_max hallH) piK _ _ => //. exact: subset_trans sKG (normal_norm nsHG). Qed. Lemma mem_normal_Hall pi H G x : pi.-Hall(G) H -> H <| G -> x \in G -> (x \in H) = pi.-elt x. Proof. by rewrite -!cycle_subG; apply: sub_normal_Hall. Qed. Lemma uniq_normal_Hall pi H G K : pi.-Hall(G) H -> H <| G -> [max K | pi.-subgroup(G) K] -> K :=: H. Proof. move=> hallH nHG /maxgroupP[/andP[sKG piK] /(_ H) -> //]. exact: (maxgroupp (Hall_max hallH)). by rewrite (sub_normal_Hall hallH). Qed. End PgroupProps. Arguments pgroupP {gT pi G}. Arguments constt1P {gT pi x}. Section NormalHall. Variables (gT : finGroupType) (pi : nat_pred). Implicit Types G H K : {group gT}. Lemma normal_max_pgroup_Hall G H : [max H | pi.-subgroup(G) H] -> H <| G -> pi.-Hall(G) H. Proof. case/maxgroupP=> /andP[sHG piH] maxH nsHG; have [_ nHG] := andP nsHG. rewrite /pHall sHG piH; apply/pnatP=> // p p_pr. rewrite inE /= -pnatE // -card_quotient //. case/Cauchy=> //= Hx; rewrite -sub1set -gen_subG -/<[Hx]> /order. case/inv_quotientS=> //= K -> sHK sKG {Hx}. rewrite card_quotient ?(subset_trans sKG) // => iKH; apply/negP=> pi_p. rewrite -iKH -divgS // (maxH K) ?divnn ?cardG_gt0 // in p_pr. by rewrite /psubgroup sKG /pgroup -(Lagrange sHK) mulnC pnatM iKH pi_p. Qed. Lemma setI_normal_Hall G H K : H <| G -> pi.-Hall(G) H -> K \subset G -> pi.-Hall(K) (H :&: K). Proof. move=> nsHG hallH sKG; apply: normal_max_pgroup_Hall; last first. by rewrite /= setIC (normalGI sKG nsHG). apply/maxgroupP; split=> [|M /andP[sMK piM] sHK_M]. by rewrite /psubgroup subsetIr (pgroupS (subsetIl _ _) (pHall_pgroup hallH)). apply/eqP; rewrite eqEsubset sHK_M subsetI sMK !andbT. by rewrite (sub_normal_Hall hallH) // (subset_trans sMK). Qed. End NormalHall. Section Morphim. Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}). Implicit Types (pi : nat_pred) (G H P : {group aT}). Lemma morphim_pgroup pi G : pi.-group G -> pi.-group (f @* G). Proof. by apply: pnat_dvd; apply: dvdn_morphim. Qed. Lemma morphim_odd G : odd #|G| -> odd #|f @* G|. Proof. by rewrite !odd_2'nat; apply: morphim_pgroup. Qed. Lemma pmorphim_pgroup pi G : pi.-group ('ker f) -> G \subset D -> pi.-group (f @* G) = pi.-group G. Proof. move=> piker sGD; apply/idP/idP=> [pifG|]; last exact: morphim_pgroup. apply: (@pgroupS _ _ (f @*^-1 (f @* G))); first by rewrite -sub_morphim_pre. by rewrite /pgroup card_morphpre ?morphimS // pnatM; apply/andP. Qed. Lemma morphim_p_index pi G H : H \subset D -> pi.-nat #|G : H| -> pi.-nat #|f @* G : f @* H|. Proof. by move=> sHD; apply: pnat_dvd; rewrite index_morphim ?subIset // sHD orbT. Qed. Lemma morphim_pHall pi G H : H \subset D -> pi.-Hall(G) H -> pi.-Hall(f @* G) (f @* H). Proof. move=> sHD /and3P[sHG piH pi'GH]. by rewrite /pHall morphimS // morphim_pgroup // morphim_p_index. Qed. Lemma pmorphim_pHall pi G H : G \subset D -> H \subset D -> pi.-subgroup(H :&: G) ('ker f) -> pi.-Hall(f @* G) (f @* H) = pi.-Hall(G) H. Proof. move=> sGD sHD /andP[/subsetIP[sKH sKG] piK]; rewrite !pHallE morphimSGK //. apply: andb_id2l => sHG; rewrite -(Lagrange sKH) -(Lagrange sKG) partnM //. by rewrite (part_pnat_id piK) !card_morphim !(setIidPr _) // eqn_pmul2l. Qed. Lemma morphim_Hall G H : H \subset D -> Hall G H -> Hall (f @* G) (f @* H). Proof. by move=> sHD /HallP[pi piH]; apply: (@pHall_Hall _ pi); apply: morphim_pHall. Qed. Lemma morphim_pSylow p G P : P \subset D -> p.-Sylow(G) P -> p.-Sylow(f @* G) (f @* P). Proof. exact: morphim_pHall. Qed. Lemma morphim_p_group P : p_group P -> p_group (f @* P). Proof. by move/morphim_pgroup; apply: pgroup_p. Qed. Lemma morphim_Sylow G P : P \subset D -> Sylow G P -> Sylow (f @* G) (f @* P). Proof. by move=> sPD /andP[pP hallP]; rewrite /Sylow morphim_p_group // morphim_Hall. Qed. Lemma morph_p_elt pi x : x \in D -> pi.-elt x -> pi.-elt (f x). Proof. by move=> Dx; apply: pnat_dvd; apply: morph_order. Qed. Lemma morph_constt pi x : x \in D -> f x.`_pi = (f x).`_pi. Proof. move=> Dx; rewrite -{2}(consttC pi x) morphM ?groupX //. rewrite consttM; last by rewrite !morphX //; apply: commuteX2. have: pi.-elt (f x.`_pi) by rewrite morph_p_elt ?groupX ?p_elt_constt //. have: pi^'.-elt (f x.`_pi^') by rewrite morph_p_elt ?groupX ?p_elt_constt //. by move/constt1P->; move/constt_p_elt->; rewrite mulg1. Qed. End Morphim. Section Pquotient. Variables (pi : nat_pred) (gT : finGroupType) (p : nat) (G H K : {group gT}). Hypothesis piK : pi.-group K. Lemma quotient_pgroup : pi.-group (K / H). Proof. exact: morphim_pgroup. Qed. Lemma quotient_pHall : K \subset 'N(H) -> pi.-Hall(G) K -> pi.-Hall(G / H) (K / H). Proof. exact: morphim_pHall. Qed. Lemma quotient_odd : odd #|K| -> odd #|K / H|. Proof. exact: morphim_odd. Qed. Lemma pquotient_pgroup : G \subset 'N(K) -> pi.-group (G / K) = pi.-group G. Proof. by move=> nKG; rewrite pmorphim_pgroup ?ker_coset. Qed. Lemma pquotient_pHall : K <| G -> K <| H -> pi.-Hall(G / K) (H / K) = pi.-Hall(G) H. Proof. case/andP=> sKG nKG; case/andP=> sKH nKH. by rewrite pmorphim_pHall // ker_coset /psubgroup subsetI sKH sKG. Qed. Lemma ltn_log_quotient : p.-group G -> H :!=: 1 -> H \subset G -> logn p #|G / H| < logn p #|G|. Proof. move=> pG ntH sHG; apply: contraLR (ltn_quotient ntH sHG); rewrite -!leqNgt. rewrite {2}(card_pgroup pG) {2}(card_pgroup (morphim_pgroup _ pG)). by case: (posnP p) => [-> //|]; apply: leq_pexp2l. Qed. End Pquotient. (* Application of card_Aut_cyclic to internal faithful action on cyclic *) (* p-subgroups. *) Section InnerAutCyclicPgroup. Variables (gT : finGroupType) (p : nat) (G C : {group gT}). Hypothesis nCG : G \subset 'N(C). Lemma logn_quotient_cent_cyclic_pgroup : p.-group C -> cyclic C -> logn p #|G / 'C_G(C)| <= (logn p #|C|).-1. Proof. move=> pC cycC; have [-> | ntC] := eqsVneq C 1. by rewrite cent1T setIT trivg_quotient cards1 logn1. have [p_pr _ [e oC]] := pgroup_pdiv pC ntC. rewrite -ker_conj_aut (card_isog (first_isog_loc _ _)) //. apply: leq_trans (dvdn_leq_log _ _ (cardSg (Aut_conj_aut _ _))) _ => //. rewrite card_Aut_cyclic // oC totient_pfactor //= logn_Gauss ?pfactorK //. by rewrite prime_coprime // gtnNdvd // -(subnKC (prime_gt1 p_pr)). Qed. Lemma p'group_quotient_cent_prime : prime p -> #|C| %| p -> p^'.-group (G / 'C_G(C)). Proof. move=> p_pr pC; have pgC: p.-group C := pnat_dvd pC (pnat_id p_pr). have [_ dv_p] := primeP p_pr; case/pred2P: {dv_p pC}(dv_p _ pC) => [|pC]. by move/card1_trivg->; rewrite cent1T setIT trivg_quotient pgroup1. have le_oGC := logn_quotient_cent_cyclic_pgroup pgC. rewrite /pgroup -partn_eq1 ?cardG_gt0 // -dvdn1 p_part pfactor_dvdn // logn1. by rewrite (leq_trans (le_oGC _)) ?prime_cyclic // pC ?(pfactorK 1). Qed. End InnerAutCyclicPgroup. Section PcoreDef. (* A functor needs to quantify over the finGroupType just beore the set. *) Variables (pi : nat_pred) (gT : finGroupType) (A : {set gT}). Definition pcore := \bigcap_(G | [max G | pi.-subgroup(A) G]) G. Canonical pcore_group : {group gT} := Eval hnf in [group of pcore]. End PcoreDef. Arguments pcore pi%_N {gT} A%_g. Arguments pcore_group pi%_N {gT} A%_G. Notation "''O_' pi ( G )" := (pcore pi G) (pi at level 2, format "''O_' pi ( G )") : group_scope. Notation "''O_' pi ( G )" := (pcore_group pi G) : Group_scope. Section PseriesDefs. Variables (pis : seq nat_pred) (gT : finGroupType) (A : {set gT}). Definition pcore_mod pi B := coset B @*^-1 'O_pi(A / B). Canonical pcore_mod_group pi B : {group gT} := Eval hnf in [group of pcore_mod pi B]. Definition pseries := foldr pcore_mod 1 (rev pis). Lemma pseries_group_set : group_set pseries. Proof. by rewrite /pseries; case: rev => [|pi1 pi1']; apply: groupP. Qed. Canonical pseries_group : {group gT} := group pseries_group_set. End PseriesDefs. Arguments pseries pis%_SEQ {gT} _%_g. Local Notation ConsPred p := (@Cons nat_pred p%N) (only parsing). Notation "''O_{' p1 , .. , pn } ( A )" := (pseries (ConsPred p1 .. (ConsPred pn [::]) ..) A) (format "''O_{' p1 , .. , pn } ( A )") : group_scope. Notation "''O_{' p1 , .. , pn } ( A )" := (pseries_group (ConsPred p1 .. (ConsPred pn [::]) ..) A) : Group_scope. Section PCoreProps. Variables (pi : nat_pred) (gT : finGroupType). Implicit Types (A : {set gT}) (G H M K : {group gT}). Lemma pcore_psubgroup G : pi.-subgroup(G) 'O_pi(G). Proof. have [M maxM _]: {M | [max M | pi.-subgroup(G) M] & 1%G \subset M}. by apply: maxgroup_exists; rewrite /psubgroup sub1G pgroup1. have sOM: 'O_pi(G) \subset M by apply: bigcap_inf. have /andP[piM sMG] := maxgroupp maxM. by rewrite /psubgroup (pgroupS sOM) // (subset_trans sOM). Qed. Lemma pcore_pgroup G : pi.-group 'O_pi(G). Proof. by case/andP: (pcore_psubgroup G). Qed. Lemma pcore_sub G : 'O_pi(G) \subset G. Proof. by case/andP: (pcore_psubgroup G). Qed. Lemma pcore_sub_Hall G H : pi.-Hall(G) H -> 'O_pi(G) \subset H. Proof. by move/Hall_max=> maxH; apply: bigcap_inf. Qed. Lemma pcore_max G H : pi.-group H -> H <| G -> H \subset 'O_pi(G). Proof. move=> piH nHG; apply/bigcapsP=> M maxM. exact: normal_sub_max_pgroup piH nHG. Qed. Lemma pcore_pgroup_id G : pi.-group G -> 'O_pi(G) = G. Proof. by move=> piG; apply/eqP; rewrite eqEsubset pcore_sub pcore_max. Qed. Lemma pcore_normal G : 'O_pi(G) <| G. Proof. rewrite /(_ <| G) pcore_sub; apply/subsetP=> x Gx. rewrite inE; apply/bigcapsP=> M maxM; rewrite sub_conjg. by apply: bigcap_inf; apply: max_pgroupJ; rewrite ?groupV. Qed. Lemma normal_Hall_pcore H G : pi.-Hall(G) H -> H <| G -> 'O_pi(G) = H. Proof. move=> hallH nHG; apply/eqP. rewrite eqEsubset (sub_normal_Hall hallH) ?pcore_sub ?pcore_pgroup //=. by rewrite pcore_max //= (pHall_pgroup hallH). Qed. Lemma eq_Hall_pcore G H : pi.-Hall(G) 'O_pi(G) -> pi.-Hall(G) H -> H :=: 'O_pi(G). Proof. move=> hallGpi hallH. exact: uniq_normal_Hall (pcore_normal G) (Hall_max hallH). Qed. Lemma sub_Hall_pcore G K : pi.-Hall(G) 'O_pi(G) -> K \subset G -> (K \subset 'O_pi(G)) = pi.-group K. Proof. by move=> hallGpi; apply: sub_normal_Hall (pcore_normal G). Qed. Lemma mem_Hall_pcore G x : pi.-Hall(G) 'O_pi(G) -> x \in G -> (x \in 'O_pi(G)) = pi.-elt x. Proof. by move=> hallGpi; apply: mem_normal_Hall (pcore_normal G). Qed. Lemma sdprod_Hall_pcoreP H G : pi.-Hall(G) 'O_pi(G) -> reflect ('O_pi(G) ><| H = G) (pi^'.-Hall(G) H). Proof. move=> hallGpi; rewrite -(compl_pHall H hallGpi) complgC. exact: sdprod_normal_complP (pcore_normal G). Qed. Lemma sdprod_pcore_HallP H G : pi^'.-Hall(G) H -> reflect ('O_pi(G) ><| H = G) (pi.-Hall(G) 'O_pi(G)). Proof. exact: sdprod_normal_p'HallP (pcore_normal G). Qed. Lemma pcoreJ G x : 'O_pi(G :^ x) = 'O_pi(G) :^ x. Proof. apply/eqP; rewrite eqEsubset -sub_conjgV. rewrite !pcore_max ?pgroupJ ?pcore_pgroup ?normalJ ?pcore_normal //. by rewrite -(normalJ _ _ x) conjsgKV pcore_normal. Qed. End PCoreProps. Section MorphPcore. Implicit Types (pi : nat_pred) (gT rT : finGroupType). Lemma morphim_pcore pi : GFunctor.pcontinuous (@pcore pi). Proof. move=> gT rT D G f; apply/bigcapsP=> M /normal_sub_max_pgroup; apply. by rewrite morphim_pgroup ?pcore_pgroup. by apply: morphim_normal; apply: pcore_normal. Qed. Lemma pcoreS pi gT (G H : {group gT}) : H \subset G -> H :&: 'O_pi(G) \subset 'O_pi(H). Proof. move=> sHG; rewrite -{2}(setIidPl sHG). by do 2!rewrite -(morphim_idm (subsetIl H _)) morphimIdom; apply: morphim_pcore. Qed. Canonical pcore_igFun pi := [igFun by pcore_sub pi & morphim_pcore pi]. Canonical pcore_gFun pi := [gFun by morphim_pcore pi]. Canonical pcore_pgFun pi := [pgFun by morphim_pcore pi]. Lemma pcore_char pi gT (G : {group gT}) : 'O_pi(G) \char G. Proof. exact: gFchar. Qed. Section PcoreMod. Variable F : GFunctor.pmap. Lemma pcore_mod_sub pi gT (G : {group gT}) : pcore_mod G pi (F _ G) \subset G. Proof. by rewrite sub_morphpre_im ?gFsub_trans ?morphimS ?gFnorm //= ker_coset gFsub. Qed. Lemma quotient_pcore_mod pi gT (G : {group gT}) (B : {set gT}) : pcore_mod G pi B / B = 'O_pi(G / B). Proof. exact/morphpreK/gFsub_trans/morphim_sub. Qed. Lemma morphim_pcore_mod pi gT rT (D G : {group gT}) (f : {morphism D >-> rT}) : f @* pcore_mod G pi (F _ G) \subset pcore_mod (f @* G) pi (F _ (f @* G)). Proof. have sDF: D :&: G \subset 'dom (coset (F _ G)). by rewrite setIC subIset ?gFnorm. have sDFf: D :&: G \subset 'dom (coset (F _ (f @* G)) \o f). by rewrite -sub_morphim_pre ?subsetIl // morphimIdom gFnorm. pose K := 'ker (restrm sDFf (coset (F _ (f @* G)) \o f)). have sFK: 'ker (restrm sDF (coset (F _ G))) \subset K. rewrite /K !ker_restrm ker_comp /= subsetI subsetIl /= -setIA. rewrite -sub_morphim_pre ?subsetIl //. by rewrite morphimIdom !ker_coset (setIidPr _) ?pmorphimF ?gFsub. have sOF := pcore_sub pi (G / F _ G); have sDD: D :&: G \subset D :&: G by []. rewrite -sub_morphim_pre -?quotientE; last first. by apply: subset_trans (gFnorm F _); rewrite morphimS ?pcore_mod_sub. suffices im_fact (H : {group gT}) : F _ G \subset H -> H \subset G -> factm sFK sDD @* (H / F _ G) = f @* H / F _ (f @* G). - rewrite -2?im_fact ?pcore_mod_sub ?gFsub //; try by rewrite -{1}[F _ G]ker_coset morphpreS ?sub1G. by rewrite quotient_pcore_mod morphim_pcore. move=> sFH sHG; rewrite -(morphimIdom _ (H / _)) /= {2}morphim_restrm setIid. rewrite -morphimIG ?ker_coset //. rewrite -(morphim_restrm sDF) morphim_factm morphim_restrm. by rewrite morphim_comp -quotientE -setIA morphimIdom (setIidPr _). Qed. Lemma pcore_mod_res pi gT rT (D : {group gT}) (f : {morphism D >-> rT}) : f @* pcore_mod D pi (F _ D) \subset pcore_mod (f @* D) pi (F _ (f @* D)). Proof. exact: morphim_pcore_mod. Qed. Lemma pcore_mod1 pi gT (G : {group gT}) : pcore_mod G pi 1 = 'O_pi(G). Proof. rewrite /pcore_mod; have inj1 := coset1_injm gT; rewrite -injmF ?norms1 //. by rewrite -(morphim_invmE inj1) morphim_invm ?norms1. Qed. End PcoreMod. Lemma pseries_rcons pi pis gT (A : {set gT}) : pseries (rcons pis pi) A = pcore_mod A pi (pseries pis A). Proof. by rewrite /pseries rev_rcons. Qed. Lemma pseries_subfun pis : GFunctor.closed (@pseries pis) /\ GFunctor.pcontinuous (@pseries pis). Proof. elim/last_ind: pis => [|pis pi [sFpi fFpi]]. by split=> [gT G | gT rT D G f]; rewrite (sub1G, morphim1). pose fF := [gFun by fFpi : GFunctor.continuous [igFun by sFpi & fFpi]]. pose F := [pgFun by fFpi : GFunctor.hereditary fF]. split=> [gT G | gT rT D G f]; rewrite !pseries_rcons ?(pcore_mod_sub F) //. exact: (morphim_pcore_mod F). Qed. Lemma pseries_sub pis : GFunctor.closed (@pseries pis). Proof. by case: (pseries_subfun pis). Qed. Lemma morphim_pseries pis : GFunctor.pcontinuous (@pseries pis). Proof. by case: (pseries_subfun pis). Qed. Lemma pseriesS pis : GFunctor.hereditary (@pseries pis). Proof. exact: (morphim_pseries pis). Qed. Canonical pseries_igFun pis := [igFun by pseries_sub pis & morphim_pseries pis]. Canonical pseries_gFun pis := [gFun by morphim_pseries pis]. Canonical pseries_pgFun pis := [pgFun by morphim_pseries pis]. Lemma pseries_char pis gT (G : {group gT}) : pseries pis G \char G. Proof. exact: gFchar. Qed. Lemma pseries_normal pis gT (G : {group gT}) : pseries pis G <| G. Proof. exact: gFnormal. Qed. Lemma pseriesJ pis gT (G : {group gT}) x : pseries pis (G :^ x) = pseries pis G :^ x. Proof. rewrite -{1}(setIid G) -morphim_conj -(injmF _ (injm_conj G x)) //=. by rewrite morphim_conj (setIidPr (pseries_sub _ _)). Qed. Lemma pseries1 pi gT (G : {group gT}) : 'O_{pi}(G) = 'O_pi(G). Proof. exact: pcore_mod1. Qed. Lemma pseries_pop pi pis gT (G : {group gT}) : 'O_pi(G) = 1 -> pseries (pi :: pis) G = pseries pis G. Proof. by move=> OG1; rewrite /pseries rev_cons -cats1 foldr_cat /= pcore_mod1 OG1. Qed. Lemma pseries_pop2 pi1 pi2 gT (G : {group gT}) : 'O_pi1(G) = 1 -> 'O_{pi1, pi2}(G) = 'O_pi2(G). Proof. by move/pseries_pop->; apply: pseries1. Qed. Lemma pseries_sub_catl pi1s pi2s gT (G : {group gT}) : pseries pi1s G \subset pseries (pi1s ++ pi2s) G. Proof. elim/last_ind: pi2s => [|pi pis IHpi]; rewrite ?cats0 // -rcons_cat. by rewrite pseries_rcons; apply: subset_trans IHpi _; rewrite sub_cosetpre. Qed. Lemma quotient_pseries pis pi gT (G : {group gT}) : pseries (rcons pis pi) G / pseries pis G = 'O_pi(G / pseries pis G). Proof. by rewrite pseries_rcons quotient_pcore_mod. Qed. Lemma pseries_norm2 pi1s pi2s gT (G : {group gT}) : pseries pi2s G \subset 'N(pseries pi1s G). Proof. by rewrite gFsub_trans ?gFnorm. Qed. Lemma pseries_sub_catr pi1s pi2s gT (G : {group gT}) : pseries pi2s G \subset pseries (pi1s ++ pi2s) G. Proof. elim: pi1s => //= pi1 pi1s /subset_trans; apply. elim/last_ind: {pi1s pi2s}(_ ++ _) => [|pis pi IHpi]; first exact: sub1G. rewrite -rcons_cons (pseries_rcons _ (pi1 :: pis)). rewrite -sub_morphim_pre ?pseries_norm2 //. apply: pcore_max; last by rewrite morphim_normal ?pseries_normal. have: pi.-group (pseries (rcons pis pi) G / pseries pis G). by rewrite quotient_pseries pcore_pgroup. by apply: pnat_dvd; rewrite !card_quotient ?pseries_norm2 // indexgS. Qed. Lemma quotient_pseries2 pi1 pi2 gT (G : {group gT}) : 'O_{pi1, pi2}(G) / 'O_pi1(G) = 'O_pi2(G / 'O_pi1(G)). Proof. by rewrite -pseries1 -quotient_pseries. Qed. Lemma quotient_pseries_cat pi1s pi2s gT (G : {group gT}) : pseries (pi1s ++ pi2s) G / pseries pi1s G = pseries pi2s (G / pseries pi1s G). Proof. elim/last_ind: pi2s => [|pi2s pi IHpi]; first by rewrite cats0 trivg_quotient. have psN := pseries_normal _ G; set K := pseries _ G. case: (third_isom (pseries_sub_catl pi1s pi2s G) (psN _)) => //= f inj_f im_f. have nH2H: pseries pi2s (G / K) <| pseries (pi1s ++ rcons pi2s pi) G / K. rewrite -IHpi morphim_normal // -cats1 catA. by apply/andP; rewrite pseries_sub_catl pseries_norm2. apply: (quotient_inj nH2H). by apply/andP; rewrite /= -cats1 pseries_sub_catl pseries_norm2. rewrite /= quotient_pseries /= -IHpi -rcons_cat. rewrite -[G / _ / _](morphim_invm inj_f) //= {2}im_f //. rewrite -(@injmF [igFun of @pcore pi]) /= ?injm_invm ?im_f // -quotient_pseries. by rewrite -im_f ?morphim_invm ?morphimS ?normal_sub. Qed. Lemma pseries_catl_id pi1s pi2s gT (G : {group gT}) : pseries pi1s (pseries (pi1s ++ pi2s) G) = pseries pi1s G. Proof. elim/last_ind: pi1s => [//|pi1s pi IHpi] in pi2s *. apply: (@quotient_inj _ (pseries_group pi1s G)). - rewrite /= -(IHpi (pi :: pi2s)) cat_rcons /(_ <| _) pseries_norm2. by rewrite -cats1 pseries_sub_catl. - by rewrite /= /(_ <| _) pseries_norm2 -cats1 pseries_sub_catl. rewrite /= cat_rcons -(IHpi (pi :: pi2s)) {1}quotient_pseries IHpi. apply/eqP; rewrite quotient_pseries eqEsubset !pcore_max ?pcore_pgroup //=. rewrite -quotient_pseries morphim_normal // /(_ <| _) pseries_norm2. by rewrite -cat_rcons pseries_sub_catl. by rewrite gFnormal_trans ?quotient_normal ?gFnormal. Qed. Lemma pseries_char_catl pi1s pi2s gT (G : {group gT}) : pseries pi1s G \char pseries (pi1s ++ pi2s) G. Proof. by rewrite -(pseries_catl_id pi1s pi2s G) pseries_char. Qed. Lemma pseries_catr_id pi1s pi2s gT (G : {group gT}) : pseries pi2s (pseries (pi1s ++ pi2s) G) = pseries pi2s G. Proof. elim/last_ind: pi2s => [//|pi2s pi IHpi] in G *. have Epis: pseries pi2s (pseries (pi1s ++ rcons pi2s pi) G) = pseries pi2s G. by rewrite -cats1 catA -[RHS]IHpi -[LHS]IHpi /= [pseries (_ ++ _) _]pseries_catl_id. apply: (@quotient_inj _ (pseries_group pi2s G)). - by rewrite /= -Epis /(_ <| _) pseries_norm2 -cats1 pseries_sub_catl. - by rewrite /= /(_ <| _) pseries_norm2 -cats1 pseries_sub_catl. rewrite /= -Epis {1}quotient_pseries Epis quotient_pseries. apply/eqP; rewrite eqEsubset !pcore_max ?pcore_pgroup //=. rewrite -quotient_pseries morphim_normal // /(_ <| _) pseries_norm2. by rewrite pseries_sub_catr. by rewrite gFnormal_trans ?morphim_normal ?gFnormal. Qed. Lemma pseries_char_catr pi1s pi2s gT (G : {group gT}) : pseries pi2s G \char pseries (pi1s ++ pi2s) G. Proof. by rewrite -(pseries_catr_id pi1s pi2s G) pseries_char. Qed. Lemma pcore_modp pi gT (G H : {group gT}) : H <| G -> pi.-group H -> pcore_mod G pi H = 'O_pi(G). Proof. move=> nsHG piH; have nHG := normal_norm nsHG; apply/eqP. rewrite eqEsubset andbC -sub_morphim_pre ?(gFsub_trans, morphim_pcore) //=. rewrite -[G in 'O_pi(G)](quotientGK nsHG) pcore_max //. by rewrite -(pquotient_pgroup piH) ?subsetIl // cosetpreK pcore_pgroup. by rewrite morphpre_normal ?gFnormal ?gFsub_trans ?morphim_sub. Qed. Lemma pquotient_pcore pi gT (G H : {group gT}) : H <| G -> pi.-group H -> 'O_pi(G / H) = 'O_pi(G) / H. Proof. by move=> nsHG piH; rewrite -quotient_pcore_mod pcore_modp. Qed. Lemma trivg_pcore_quotient pi gT (G : {group gT}) : 'O_pi(G / 'O_pi(G)) = 1. Proof. by rewrite pquotient_pcore ?gFnormal ?pcore_pgroup ?trivg_quotient. Qed. Lemma pseries_rcons_id pis pi gT (G : {group gT}) : pseries (rcons (rcons pis pi) pi) G = pseries (rcons pis pi) G. Proof. apply/eqP; rewrite -!cats1 eqEsubset pseries_sub_catl andbT -catA. rewrite -(quotientSGK _ (pseries_sub_catl _ _ _)) ?pseries_norm2 //. rewrite !quotient_pseries_cat -quotient_sub1 ?pseries_norm2 //. by rewrite quotient_pseries_cat /= !pseries1 trivg_pcore_quotient. Qed. End MorphPcore. Section EqPcore. Variables gT : finGroupType. Implicit Types (pi rho : nat_pred) (G H : {group gT}). Lemma sub_in_pcore pi rho G : {in \pi(G), {subset pi <= rho}} -> 'O_pi(G) \subset 'O_rho(G). Proof. move=> pi_sub_rho; rewrite pcore_max ?pcore_normal //. apply: sub_in_pnat (pcore_pgroup _ _) => p. by move/(piSg (pcore_sub _ _)); apply: pi_sub_rho. Qed. Lemma sub_pcore pi rho G : {subset pi <= rho} -> 'O_pi(G) \subset 'O_rho(G). Proof. by move=> pi_sub_rho; apply: sub_in_pcore (in1W pi_sub_rho). Qed. Lemma eq_in_pcore pi rho G : {in \pi(G), pi =i rho} -> 'O_pi(G) = 'O_rho(G). Proof. move=> eq_pi_rho; apply/eqP; rewrite eqEsubset. by rewrite !sub_in_pcore // => p /eq_pi_rho->. Qed. Lemma eq_pcore pi rho G : pi =i rho -> 'O_pi(G) = 'O_rho(G). Proof. by move=> eq_pi_rho; apply: eq_in_pcore (in1W eq_pi_rho). Qed. Lemma pcoreNK pi G : 'O_pi^'^'(G) = 'O_pi(G). Proof. by apply: eq_pcore; apply: negnK. Qed. Lemma eq_p'core pi rho G : pi =i rho -> 'O_pi^'(G) = 'O_rho^'(G). Proof. by move/eq_negn; apply: eq_pcore. Qed. Lemma sdprod_Hall_p'coreP pi H G : pi^'.-Hall(G) 'O_pi^'(G) -> reflect ('O_pi^'(G) ><| H = G) (pi.-Hall(G) H). Proof. by rewrite -(pHallNK pi G H); apply: sdprod_Hall_pcoreP. Qed. Lemma sdprod_p'core_HallP pi H G : pi.-Hall(G) H -> reflect ('O_pi^'(G) ><| H = G) (pi^'.-Hall(G) 'O_pi^'(G)). Proof. by rewrite -(pHallNK pi G H); apply: sdprod_pcore_HallP. Qed. Lemma pcoreI pi rho G : 'O_[predI pi & rho](G) = 'O_pi('O_rho(G)). Proof. apply/eqP; rewrite eqEsubset !pcore_max //. - rewrite /pgroup pnatI -!pgroupE. by rewrite pcore_pgroup (pgroupS (pcore_sub pi _))// pcore_pgroup. - by rewrite !gFnormal_trans. - by apply: sub_pgroup (pcore_pgroup _ _) => p /andP[]. apply/andP; split; first by apply: sub_pcore => p /andP[]. by rewrite gFnorm_trans ?normsG ?gFsub. Qed. Lemma bigcap_p'core pi G : G :&: \bigcap_(p < #|G|.+1 | (p : nat) \in pi) 'O_p^'(G) = 'O_pi^'(G). Proof. apply/eqP; rewrite eqEsubset subsetI pcore_sub pcore_max /=. - by apply/bigcapsP=> p pi_p; apply: sub_pcore => r; apply: contraNneq => ->. - apply/pgroupP=> q q_pr qGpi'; apply: contraL (eqxx q) => /= pi_q. apply: (pgroupP (pcore_pgroup q^' G)) => //. have qG: q %| #|G| by rewrite (dvdn_trans qGpi') // cardSg ?subsetIl. have ltqG: q < #|G|.+1 by rewrite ltnS dvdn_leq. rewrite (dvdn_trans qGpi') ?cardSg ?subIset //= orbC. by rewrite (bigcap_inf (Ordinal ltqG)). rewrite /normal subsetIl normsI ?normG // norms_bigcap //. by apply/bigcapsP => p _; apply: gFnorm. Qed. Lemma coprime_pcoreC (rT : finGroupType) pi G (R : {group rT}) : coprime #|'O_pi(G)| #|'O_pi^'(R)|. Proof. exact: pnat_coprime (pcore_pgroup _ _) (pcore_pgroup _ _). Qed. Lemma TI_pcoreC pi G H : 'O_pi(G) :&: 'O_pi^'(H) = 1. Proof. by rewrite coprime_TIg ?coprime_pcoreC. Qed. Lemma pcore_setI_normal pi G H : H <| G -> 'O_pi(G) :&: H = 'O_pi(H). Proof. move=> nsHG; apply/eqP; rewrite eqEsubset subsetI pcore_sub setIC. rewrite !pcore_max ?(pgroupS (subsetIr H _)) ?pcore_pgroup ?gFnormal_trans //=. by rewrite norm_normalI ?gFnorm_trans ?normsG ?normal_sub. Qed. End EqPcore. Arguments sdprod_Hall_pcoreP {pi gT H G}. Arguments sdprod_Hall_p'coreP {gT pi H G}. Section Injm. Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}). Hypothesis injf : 'injm f. Implicit Types (A : {set aT}) (G H : {group aT}). Lemma injm_pgroup pi A : A \subset D -> pi.-group (f @* A) = pi.-group A. Proof. by move=> sAD; rewrite /pgroup card_injm. Qed. Lemma injm_pelt pi x : x \in D -> pi.-elt (f x) = pi.-elt x. Proof. by move=> Dx; rewrite /p_elt order_injm. Qed. Lemma injm_pHall pi G H : G \subset D -> H \subset D -> pi.-Hall(f @* G) (f @* H) = pi.-Hall(G) H. Proof. by move=> sGD sGH; rewrite !pHallE injmSK ?card_injm. Qed. Lemma injm_pcore pi G : G \subset D -> f @* 'O_pi(G) = 'O_pi(f @* G). Proof. exact: injmF. Qed. Lemma injm_pseries pis G : G \subset D -> f @* pseries pis G = pseries pis (f @* G). Proof. exact: injmF. Qed. End Injm. Section Isog. Variables (aT rT : finGroupType) (G : {group aT}) (H : {group rT}). Lemma isog_pgroup pi : G \isog H -> pi.-group G = pi.-group H. Proof. by move=> isoGH; rewrite /pgroup (card_isog isoGH). Qed. Lemma isog_pcore pi : G \isog H -> 'O_pi(G) \isog 'O_pi(H). Proof. exact: gFisog. Qed. Lemma isog_pseries pis : G \isog H -> pseries pis G \isog pseries pis H. Proof. exact: gFisog. Qed. End Isog.
ContextInfo.lean
/- Copyright (c) 2025 Lean FRO, LLC. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ -- Import this linter explicitly to ensure that -- this file has a valid copyright header and module docstring. import Mathlib.Tactic.Linter.Header /-! # Executing actions using the infotree This file contains helper functions for running `CoreM`, `MetaM` and tactic actions in the context of an infotree node. -/ open Lean Elab Term Command Linter namespace Lean.Elab.ContextInfo variable {α} /-- Embeds a `CoreM` action in `CommandElabM` by supplying the information stored in `info`. Copy of `ContextInfo.runCoreM` that makes use of the `CommandElabM` context for: * logging messages produced by the `CoreM` action, * metavariable generation, * auxiliary declaration generation. -/ def runCoreMWithMessages (info : ContextInfo) (x : CoreM α) : CommandElabM α := do -- We assume that this function is used only outside elaboration, mostly in the language server, -- and so we can and should provide access to information regardless whether it is exported. let env := info.env.setExporting false let ctx ← read /- We must execute `x` using the `ngen` stored in `info`. Otherwise, we may create `MVarId`s and `FVarId`s that have been used in `lctx` and `info.mctx`. Similarly, we need to pass in a `namePrefix` because otherwise we can't create auxiliary definitions. -/ let (x, newState) ← (withOptions (fun _ => info.options) x).toIO { currNamespace := info.currNamespace, openDecls := info.openDecls fileName := ctx.fileName, fileMap := ctx.fileMap } { env, ngen := info.ngen, auxDeclNGen := { namePrefix := info.parentDecl?.getD .anonymous } } -- Migrate logs back to the main context. modify fun state => { state with messages := state.messages ++ newState.messages, traceState.traces := state.traceState.traces ++ newState.traceState.traces } return x /-- Embeds a `MetaM` action in `CommandElabM` by supplying the information stored in `info`. Copy of `ContextInfo.runMetaM` that makes use of the `CommandElabM` context for: * message logging (messages produced by the `CoreM` action are migrated back), * metavariable generation, * auxiliary declaration generation, * local instances. -/ def runMetaMWithMessages (info : ContextInfo) (lctx : LocalContext) (x : MetaM α) : CommandElabM α := do (·.1) <$> info.runCoreMWithMessages (Lean.Meta.MetaM.run (ctx := { lctx := lctx }) (s := { mctx := info.mctx }) <| -- Update the local instances, otherwise typeclass search would fail to see anything in the -- local context. Meta.withLocalInstances (lctx.decls.toList.filterMap id) <| x) /-- Run a tactic computation in the context of an infotree node. -/ def runTactic (ctx : ContextInfo) (i : TacticInfo) (goal : MVarId) (x : MVarId → MetaM α) : CommandElabM α := do if !i.goalsBefore.contains goal then panic!"ContextInfo.runTactic: `goal` must be an element of `i.goalsBefore`" let mctx := i.mctxBefore let lctx := (mctx.decls.find! goal).2 ctx.runMetaMWithMessages lctx <| do -- Make a fresh metavariable because the original goal is already assigned. let type ← goal.getType let goal ← Meta.mkFreshExprSyntheticOpaqueMVar type x goal.mvarId! end Lean.Elab.ContextInfo
PNatPowAssoc.lean
/- Copyright (c) 2023 Scott Carnahan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Carnahan -/ import Mathlib.Data.PNat.Basic import Mathlib.Algebra.Notation.Prod /-! # Typeclasses for power-associative structures In this file we define power-associativity for algebraic structures with a multiplication operation. The class is a Prop-valued mixin named `PNatPowAssoc`, where `PNat` means only strictly positive powers are considered. ## Results - `ppow_add` a defining property: `x ^ (k + n) = x ^ k * x ^ n` - `ppow_one` a defining property: `x ^ 1 = x` - `ppow_assoc` strictly positive powers of an element have associative multiplication. - `ppow_comm` `x ^ m * x ^ n = x ^ n * x ^ m` for strictly positive `m` and `n`. - `ppow_mul` `x ^ (m * n) = (x ^ m) ^ n` for strictly positive `m` and `n`. - `ppow_eq_pow` monoid exponentiation coincides with semigroup exponentiation. ## Instances - PNatPowAssoc for products and Pi types ## TODO * `NatPowAssoc` for `MulOneClass` - more or less the same flow * It seems unlikely that anyone will want `NatSMulAssoc` and `PNatSMulAssoc` as additive versions of power-associativity, but we have found that it is not hard to write. -/ -- TODO: -- assert_not_exists MonoidWithZero variable {M : Type*} /-- A `Prop`-valued mixin for power-associative multiplication in the non-unital setting. -/ class PNatPowAssoc (M : Type*) [Mul M] [Pow M ℕ+] : Prop where /-- Multiplication is power-associative. -/ protected ppow_add : ∀ (k n : ℕ+) (x : M), x ^ (k + n) = x ^ k * x ^ n /-- Exponent one is identity. -/ protected ppow_one : ∀ (x : M), x ^ (1 : ℕ+) = x section Mul variable [Mul M] [Pow M ℕ+] [PNatPowAssoc M] theorem ppow_add (k n : ℕ+) (x : M) : x ^ (k + n) = x ^ k * x ^ n := PNatPowAssoc.ppow_add k n x @[simp] theorem ppow_one (x : M) : x ^ (1 : ℕ+) = x := PNatPowAssoc.ppow_one x theorem ppow_mul_assoc (k m n : ℕ+) (x : M) : (x ^ k * x ^ m) * x ^ n = x ^ k * (x ^ m * x ^ n) := by simp only [← ppow_add, add_assoc] theorem ppow_mul_comm (m n : ℕ+) (x : M) : x ^ m * x ^ n = x ^ n * x ^ m := by simp only [← ppow_add, add_comm] theorem ppow_mul (x : M) (m n : ℕ+) : x ^ (m * n) = (x ^ m) ^ n := by induction n with | one => rw [ppow_one, mul_one] | succ k hk => rw [ppow_add, ppow_one, mul_add, ppow_add, mul_one, hk] theorem ppow_mul' (x : M) (m n : ℕ+) : x ^ (m * n) = (x ^ n) ^ m := by rw [mul_comm] exact ppow_mul x n m end Mul instance Pi.instPNatPowAssoc {ι : Type*} {α : ι → Type*} [∀ i, Mul <| α i] [∀ i, Pow (α i) ℕ+] [∀ i, PNatPowAssoc <| α i] : PNatPowAssoc (∀ i, α i) where ppow_add _ _ _ := by ext; simp [ppow_add] ppow_one _ := by ext; simp instance Prod.instPNatPowAssoc {N : Type*} [Mul M] [Pow M ℕ+] [PNatPowAssoc M] [Mul N] [Pow N ℕ+] [PNatPowAssoc N] : PNatPowAssoc (M × N) where ppow_add _ _ _ := by ext <;> simp [ppow_add] ppow_one _ := by ext <;> simp theorem ppow_eq_pow [Monoid M] [Pow M ℕ+] [PNatPowAssoc M] (x : M) (n : ℕ+) : x ^ n = x ^ (n : ℕ) := by induction n with | one => rw [ppow_one, PNat.one_coe, pow_one] | succ k hk => rw [ppow_add, ppow_one, PNat.add_coe, pow_add, PNat.one_coe, pow_one, ← hk]
ErwQuestion.lean
import Mathlib.Tactic.ErwQuestion section Single def f (x : Nat) := x + 1 def a := 37 theorem f_a : f a = 38 := rfl def b := a -- make sure that `erw'` is noisy, so that it gets picked up by CI /-- info: Debugging `erw?` -/ #guard_msgs in example : f 37 = 38 := by erw? [f] /-- error: Tactic `rewrite` failed: Did not find an occurrence of the pattern f a in the target expression f b = 38 ⊢ f b = 38 -/ #guard_msgs in example : f b = 38 := by rw [f_a] example : f b = 38 := by erw [f_a] /-- info: Debugging `erw?` --- info: ❌️ at reducible transparency, b and a are not defeq, but they are at default transparency. -/ #guard_msgs in example : f b = 38 := by erw? [f_a] set_option tactic.erw?.verbose true in /-- info: Debugging `erw?` --- info: ❌️ at reducible transparency, b and a are not defeq, but they are at default transparency. --- info: Expression appearing in target: f b = 38 Expression from `erw`: f a = 38 ❌️ at reducible transparency, f b = 38 and f a = 38 are not defeq. ✅️ at reducible transparency, 38 and 38 are defeq. ❌️ at reducible transparency, Eq (f b) and Eq (f a) are not defeq. ❌️ at reducible transparency, f b and f a are not defeq. ❌️ at reducible transparency, b and a are not defeq. -/ #guard_msgs in example : f b = 38 := by erw? [f_a] end Single section Sequence def c := 38 theorem f_c : f c = 39 := rfl /-- info: Debugging `erw?` --- info: ❌️ at reducible transparency, b and a are not defeq, but they are at default transparency. --- info: ❌️ at reducible transparency, f 38 and f c are not defeq, but they are at default transparency. -/ #guard_msgs in example : f (f b) = 39 := by erw? [f_a, f_c] end Sequence section Location /-- info: Debugging `erw?` --- info: ❌️ at reducible transparency, b and a are not defeq, but they are at default transparency. -/ #guard_msgs in example (h : f b = c) : c = 38 := by erw? [f_a] at h exact h.symm set_option tactic.erw?.verbose true in /-- info: Debugging `erw?` --- info: ❌️ at reducible transparency, b and a are not defeq, but they are at default transparency. --- info: Expression appearing in h: f b = c Expression from `erw`: f a = c ❌️ at reducible transparency, f b = c and f a = c are not defeq. ✅️ at reducible transparency, c and c are defeq. ❌️ at reducible transparency, Eq (f b) and Eq (f a) are not defeq. ❌️ at reducible transparency, f b and f a are not defeq. ❌️ at reducible transparency, b and a are not defeq. -/ #guard_msgs in example (h : f b = c) : c = 38 := by erw? [f_a] at h exact h.symm end Location
PathELength.lean
/- Copyright (c) 2025 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.AddTorsor.AffineMap import Mathlib.Analysis.SpecialFunctions.SmoothTransition import Mathlib.Geometry.Manifold.ContMDiff.NormedSpace import Mathlib.Geometry.Manifold.Instances.Icc import Mathlib.MeasureTheory.Constructions.UnitInterval import Mathlib.MeasureTheory.Function.JacobianOneDim /-! # Lengths of paths in manifolds Consider a manifold in which the tangent spaces have an enormed structure. Then one defines `pathELength γ a b` as the length of the path `γ : ℝ → M` between `a` and `b`, i.e., the integral of the norm of its derivative on `Icc a b`. We give several ways to write this quantity (as an integral over `Icc`, or `Ioo`, or the subtype `Icc`, using either `mfderiv` or `mfderivWithin`). We show that this notion is invariant under reparameterization by a monotone map, in `pathELength_comp_of_monotoneOn`. We define `riemannianEDist x y` as the infimum of the length of `C^1` paths between `x` and `y`. We prove, in `exists_lt_locally_constant_of_riemannianEDist_lt`, that it is also the infimum on such path that are moreover locally constant near their endpoints. Such paths can be glued while retaining the `C^1` property. We deduce that `riemannianEDist` satisfies the triangle inequality, in `riemannianEDist_triangle`. Note that `riemannianEDist x y` could also be named `finslerEDist x y` as we do not require that the metric comes from an inner product space. However, as all the current applications in mathlib are to Riemannian spaces we stick with the simpler name. This could be changed when Finsler manifolds are studied in mathlib. -/ open Set MeasureTheory open scoped Manifold ENNReal ContDiff Topology noncomputable section variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {n : WithTop ℕ∞} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] namespace Manifold variable [∀ (x : M), ENorm (TangentSpace I x)] {a b c a' b' : ℝ} {γ γ' : ℝ → M} variable (I) in /-- The length on `Icc a b` of a path into a manifold, where the path is defined on the whole real line. We use the whole real line to avoid subtype hell in API, but this is equivalent to considering functions on the manifold with boundary `Icc a b`, see `lintegral_norm_mfderiv_Icc_eq_pathELength_projIcc`. We use `mfderiv` instead of `mfderivWithin` in the definition as these coincide (apart from the two endpoints which have zero measure) and `mfderiv` is easier to manipulate. However, we give a lemma `pathELength_eq_integral_mfderivWithin_Icc` to rewrite with the `mfderivWithin` form. -/ irreducible_def pathELength (γ : ℝ → M) (a b : ℝ) : ℝ≥0∞ := ∫⁻ t in Icc a b, ‖mfderiv 𝓘(ℝ) I γ t 1‖ₑ lemma pathELength_eq_lintegral_mfderiv_Icc : pathELength I γ a b = ∫⁻ t in Icc a b, ‖mfderiv 𝓘(ℝ) I γ t 1‖ₑ := by simp [pathELength] lemma pathELength_eq_lintegral_mfderiv_Ioo : pathELength I γ a b = ∫⁻ t in Ioo a b, ‖mfderiv 𝓘(ℝ) I γ t 1‖ₑ := by rw [pathELength_eq_lintegral_mfderiv_Icc, restrict_Ioo_eq_restrict_Icc] lemma pathELength_eq_lintegral_mfderivWithin_Icc : pathELength I γ a b = ∫⁻ t in Icc a b, ‖mfderivWithin 𝓘(ℝ) I γ (Icc a b) t 1‖ₑ := by -- we use that the endpoints have measure 0 to rewrite on `Ioo a b`, where `mfderiv` and -- `mfderivWithin` coincide. rw [pathELength_eq_lintegral_mfderiv_Icc, ← restrict_Ioo_eq_restrict_Icc] apply setLIntegral_congr_fun measurableSet_Ioo (fun t ht ↦ ?_) rw [mfderivWithin_of_mem_nhds] exact Icc_mem_nhds ht.1 ht.2 @[simp] lemma pathELength_self : pathELength I γ a a = 0 := by simp [pathELength] lemma pathELength_congr_Ioo (h : EqOn γ γ' (Ioo a b)) : pathELength I γ a b = pathELength I γ' a b := by simp only [pathELength_eq_lintegral_mfderiv_Ioo] apply setLIntegral_congr_fun measurableSet_Ioo (fun t ht ↦ ?_) have A : γ t = γ' t := h ht congr! 2 apply Filter.EventuallyEq.mfderiv_eq filter_upwards [Ioo_mem_nhds ht.1 ht.2] with a ha using h ha lemma pathELength_congr (h : EqOn γ γ' (Icc a b)) : pathELength I γ a b = pathELength I γ' a b := pathELength_congr_Ioo (fun _ hx ↦ h ⟨hx.1.le, hx.2.le⟩) @[gcongr] lemma pathELength_mono (h : a' ≤ a) (h' : b ≤ b') : pathELength I γ a b ≤ pathELength I γ a' b' := by simpa [pathELength_eq_lintegral_mfderiv_Icc] using lintegral_mono_set (Icc_subset_Icc h h') lemma pathELength_add (h : a ≤ b) (h' : b ≤ c) : pathELength I γ a b + pathELength I γ b c = pathELength I γ a c := by symm have : Icc a c = Icc a b ∪ Ioc b c := (Icc_union_Ioc_eq_Icc h h').symm rw [pathELength, this, lintegral_union measurableSet_Ioc]; swap · exact disjoint_iff_forall_ne.mpr (fun a ha b hb ↦ (ha.2.trans_lt hb.1).ne) simp [restrict_Ioc_eq_restrict_Icc, pathELength] attribute [local instance] Measure.Subtype.measureSpace /-- Given a path `γ` defined on the manifold with boundary `[a, b]`, its length (as the integral of the norm of its manifold derivative) coincides with `pathELength` of the lift of `γ` to the real line, between `a` and `b`. -/ lemma lintegral_norm_mfderiv_Icc_eq_pathELength_projIcc {a b : ℝ} [h : Fact (a < b)] {γ : Icc a b → M} : ∫⁻ t, ‖mfderiv (𝓡∂ 1) I γ t 1‖ₑ = pathELength I (γ ∘ (projIcc a b h.out.le)) a b := by rw [pathELength_eq_lintegral_mfderivWithin_Icc] simp_rw [← mfderivWithin_comp_projIcc_one] have : MeasurePreserving (Subtype.val : Icc a b → ℝ) volume (volume.restrict (Icc a b)) := measurePreserving_subtype_coe measurableSet_Icc rw [← MeasurePreserving.lintegral_comp_emb this (MeasurableEmbedding.subtype_coe measurableSet_Icc)] congr ext t have : t = projIcc a b h.out.le (t : ℝ) := by simp congr open MeasureTheory variable [∀ (x : M), ENormSMulClass ℝ (TangentSpace I x)] /-- The length of a path in a manifold is invariant under a monotone reparametrization. -/ lemma pathELength_comp_of_monotoneOn {f : ℝ → ℝ} (h : a ≤ b) (hf : MonotoneOn f (Icc a b)) (h'f : DifferentiableOn ℝ f (Icc a b)) (hγ : MDifferentiableOn 𝓘(ℝ) I γ (Icc (f a) (f b))) : pathELength I (γ ∘ f) a b = pathELength I γ (f a) (f b) := by rcases h.eq_or_lt with rfl | h · simp have f_im : f '' (Icc a b) = Icc (f a) (f b) := h'f.continuousOn.image_Icc_of_monotoneOn h.le hf simp only [pathELength_eq_lintegral_mfderivWithin_Icc, ← f_im] have B (t) (ht : t ∈ Icc a b) : HasDerivWithinAt f (derivWithin f (Icc a b) t) (Icc a b) t := (h'f t ht).hasDerivWithinAt rw [lintegral_image_eq_lintegral_deriv_mul_of_monotoneOn measurableSet_Icc B hf] apply setLIntegral_congr_fun measurableSet_Icc (fun t ht ↦ ?_) have : (mfderivWithin 𝓘(ℝ, ℝ) I (γ ∘ f) (Icc a b) t) = (mfderivWithin 𝓘(ℝ, ℝ) I γ (Icc (f a) (f b)) (f t)) ∘L mfderivWithin 𝓘(ℝ) 𝓘(ℝ) f (Icc a b) t := by rw [← f_im] at hγ ⊢ apply mfderivWithin_comp · apply hγ _ (mem_image_of_mem _ ht) · rw [mdifferentiableWithinAt_iff_differentiableWithinAt] exact h'f _ ht · exact subset_preimage_image _ _ · rw [uniqueMDiffWithinAt_iff_uniqueDiffWithinAt] exact uniqueDiffOn_Icc h _ ht rw [this] simp only [Function.comp_apply, ContinuousLinearMap.coe_comp'] have : mfderivWithin 𝓘(ℝ) 𝓘(ℝ) f (Icc a b) t 1 = derivWithin f (Icc a b) t • (1 : TangentSpace 𝓘(ℝ) (f t)) := by simp only [mfderivWithin_eq_fderivWithin, ← fderivWithin_derivWithin, smul_eq_mul, mul_one] rfl rw [this] have : 0 ≤ derivWithin f (Icc a b) t := hf.derivWithin_nonneg simp only [map_smul, enorm_smul, ← Real.enorm_of_nonneg this, f_im] /-- The length of a path in a manifold is invariant under an antitone reparametrization. -/ lemma pathELength_comp_of_antitoneOn {f : ℝ → ℝ} (h : a ≤ b) (hf : AntitoneOn f (Icc a b)) (h'f : DifferentiableOn ℝ f (Icc a b)) (hγ : MDifferentiableOn 𝓘(ℝ) I γ (Icc (f b) (f a))) : pathELength I (γ ∘ f) a b = pathELength I γ (f b) (f a) := by rcases h.eq_or_lt with rfl | h · simp have f_im : f '' (Icc a b) = Icc (f b) (f a) := h'f.continuousOn.image_Icc_of_antitoneOn h.le hf simp only [pathELength_eq_lintegral_mfderivWithin_Icc, ← f_im] have B (t) (ht : t ∈ Icc a b) : HasDerivWithinAt f (derivWithin f (Icc a b) t) (Icc a b) t := (h'f t ht).hasDerivWithinAt rw [lintegral_image_eq_lintegral_deriv_mul_of_antitoneOn measurableSet_Icc B hf] apply setLIntegral_congr_fun measurableSet_Icc (fun t ht ↦ ?_) have : (mfderivWithin 𝓘(ℝ, ℝ) I (γ ∘ f) (Icc a b) t) = (mfderivWithin 𝓘(ℝ, ℝ) I γ (Icc (f b) (f a)) (f t)) ∘L mfderivWithin 𝓘(ℝ) 𝓘(ℝ) f (Icc a b) t := by rw [← f_im] at hγ ⊢ apply mfderivWithin_comp · apply hγ _ (mem_image_of_mem _ ht) · rw [mdifferentiableWithinAt_iff_differentiableWithinAt] exact h'f _ ht · exact subset_preimage_image _ _ · rw [uniqueMDiffWithinAt_iff_uniqueDiffWithinAt] exact uniqueDiffOn_Icc h _ ht rw [this] simp only [Function.comp_apply, ContinuousLinearMap.coe_comp'] have : mfderivWithin 𝓘(ℝ) 𝓘(ℝ) f (Icc a b) t 1 = derivWithin f (Icc a b) t • (1 : TangentSpace 𝓘(ℝ) (f t)) := by simp only [mfderivWithin_eq_fderivWithin, ← fderivWithin_derivWithin, smul_eq_mul, mul_one] rfl rw [this] have : 0 ≤ -derivWithin f (Icc a b) t := by simp [hf.derivWithin_nonpos] simp only [map_smul, enorm_smul, f_im, ← Real.enorm_of_nonneg this, enorm_neg] section variable {x y z : M} {r : ℝ≥0∞} {a b : ℝ} variable (I) in /-- The Riemannian extended distance between two points, in a manifold where the tangent spaces have an extended norm, defined as the infimum of the lengths of `C^1` paths between the points. -/ noncomputable irreducible_def riemannianEDist (x y : M) : ℝ≥0∞ := ⨅ (γ : Path x y) (_ : ContMDiff (𝓡∂ 1) I 1 γ), ∫⁻ x, ‖mfderiv (𝓡∂ 1) I γ x 1‖ₑ /-- The Riemannian edistance is bounded above by the length of any `C^1` path from `x` to `y`. Here, we express this using a path defined on the whole real line, considered on some interval `[a, b]`. -/ lemma riemannianEDist_le_pathELength {γ : ℝ → M} (hγ : ContMDiffOn 𝓘(ℝ) I 1 γ (Icc a b)) (ha : γ a = x) (hb : γ b = y) (hab : a ≤ b) : riemannianEDist I x y ≤ pathELength I γ a b := by let η : ℝ →ᴬ[ℝ] ℝ := ContinuousAffineMap.lineMap a b have hη : ContMDiffOn 𝓘(ℝ) I 1 (γ ∘ η) (Icc 0 1) := by apply hγ.comp · rw [contMDiffOn_iff_contDiffOn] exact η.contDiff.contDiffOn · rw [← image_subset_iff, ContinuousAffineMap.coe_lineMap_eq, ← segment_eq_image_lineMap] simp [hab] let f : unitInterval → M := fun t ↦ (γ ∘ η) t have hf : ContMDiff (𝓡∂ 1) I 1 f := by rw [← contMDiffOn_comp_projIcc_iff] apply hη.congr (fun t ht ↦ ?_) simp only [Function.comp_apply, f, projIcc_of_mem, ht] let g : Path x y := by refine ⟨⟨f, hf.continuous⟩, ?_, ?_⟩ <;> simp [f, η, ContinuousAffineMap.coe_lineMap_eq, ha, hb] have A : riemannianEDist I x y ≤ ∫⁻ x, ‖mfderiv (𝓡∂ 1) I g x 1‖ₑ := by rw [riemannianEDist]; exact biInf_le _ hf apply A.trans_eq rw [lintegral_norm_mfderiv_Icc_eq_pathELength_projIcc] have E : pathELength I (g ∘ projIcc 0 1 zero_le_one) 0 1 = pathELength I (γ ∘ η) 0 1 := by apply pathELength_congr (fun t ht ↦ ?_) simp only [Function.comp_apply, ht, projIcc_of_mem] rfl rw [E, pathELength_comp_of_monotoneOn zero_le_one _ η.differentiableOn] · simp [η, ContinuousAffineMap.coe_lineMap_eq] · simpa [η, ContinuousAffineMap.coe_lineMap_eq] using hγ.mdifferentiableOn le_rfl · apply (AffineMap.lineMap_mono hab).monotoneOn omit [∀ (x : M), ENormSMulClass ℝ (TangentSpace I x)] in /-- If some `r` is strictly larger than the Riemannian edistance between two points, there exists a path between these two points of length `< r`. Here, we get such a path on `[0, 1]`. For a more precise version giving locally constant paths around the endpoints, see `exists_lt_locally_constant_of_riemannianEDist_lt` -/ lemma exists_lt_of_riemannianEDist_lt (hr : riemannianEDist I x y < r) : ∃ γ : ℝ → M, γ 0 = x ∧ γ 1 = y ∧ ContMDiffOn 𝓘(ℝ) I 1 γ (Icc 0 1) ∧ pathELength I γ 0 1 < r := by simp only [riemannianEDist, iInf_lt_iff, exists_prop] at hr rcases hr with ⟨γ, γ_smooth, hγ⟩ refine ⟨γ ∘ (projIcc 0 1 zero_le_one), by simp, by simp, contMDiffOn_comp_projIcc_iff.2 γ_smooth, ?_⟩ rwa [← lintegral_norm_mfderiv_Icc_eq_pathELength_projIcc] /-- If some `r` is strictly larger than the Riemannian edistance between two points, there exists a path between these two points of length `< r`. Here, we get such a path on an arbitrary interval `[a, b]` with `a < b`, and moreover we ensure that the path is locally constant around `a` and `b`, which is convenient for gluing purposes. -/ lemma exists_lt_locally_constant_of_riemannianEDist_lt (hr : riemannianEDist I x y < r) (hab : a < b) : ∃ γ : ℝ → M, γ a = x ∧ γ b = y ∧ ContMDiff 𝓘(ℝ) I 1 γ ∧ pathELength I γ a b < r ∧ γ =ᶠ[𝓝 a] (fun _ ↦ x) ∧ γ =ᶠ[𝓝 b] (fun _ ↦ y) := by /- We start from a path from `x` to `y` defined on `[0, 1]` with length `< r`. Then, we reparameterize it using a smooth monotone map `η` from `[a, b]` to `[0, 1]` which is moreover locally constant around `a` and `b`. Such a map is easy to build with `Real.smoothTransition`. Note that this is a very standard construction in differential topology. TODO: refactor once we have more differential topology in Mathlib and this gets duplicated. -/ rcases exists_lt_of_riemannianEDist_lt hr with ⟨γ, hγx, hγy, γ_smooth, hγ⟩ rcases exists_between hab with ⟨a', haa', ha'b⟩ rcases exists_between ha'b with ⟨b', ha'b', hb'b⟩ let η (t : ℝ) : ℝ := Real.smoothTransition ((b' - a') ⁻¹ * (t - a')) have A (t) (ht : t < a') : η t = 0 := by simp only [η, Real.smoothTransition.zero_iff_nonpos] apply mul_nonpos_of_nonneg_of_nonpos · simpa using ha'b'.le · linarith have A' (t) (ht : t < a') : (γ ∘ η) t = x := by simp [A t ht, hγx] have B (t) (ht : b' < t) : η t = 1 := by simp only [η, Real.smoothTransition.eq_one_iff_one_le, inv_mul_eq_div] rw [one_le_div₀] <;> linarith have B' (t) (ht : b' < t) : (γ ∘ η) t = y := by simp [B t ht, hγy] refine ⟨γ ∘ η, A' _ haa', B' _ hb'b, ?_, ?_, ?_, ?_⟩ · rw [← contMDiffOn_univ] apply γ_smooth.comp · rw [contMDiffOn_univ, contMDiff_iff_contDiff] fun_prop · intro t ht exact ⟨Real.smoothTransition.nonneg _, Real.smoothTransition.le_one _⟩ · convert hγ using 1 rw [← A a haa', ← B b hb'b] apply pathELength_comp_of_monotoneOn hab.le · apply Monotone.monotoneOn apply Real.smoothTransition.monotone.comp intro t u htu dsimp only gcongr simpa only [inv_nonneg, sub_nonneg] using ha'b'.le · simp only [η] apply (ContDiff.contDiffOn _).differentiableOn le_rfl fun_prop · rw [A a haa', B b hb'b] apply γ_smooth.mdifferentiableOn le_rfl · filter_upwards [Iio_mem_nhds haa'] with t ht using A' t ht · filter_upwards [Ioi_mem_nhds hb'b] with t ht using B' t ht lemma riemannianEDist_self : riemannianEDist I x x = 0 := by apply le_antisymm _ bot_le exact (riemannianEDist_le_pathELength (γ := fun (t : ℝ) ↦ x) (a := 0) (b := 0) contMDiffOn_const rfl rfl le_rfl).trans_eq (by simp) lemma riemannianEDist_comm : riemannianEDist I x y = riemannianEDist I y x := by suffices H : ∀ x y, riemannianEDist I y x ≤ riemannianEDist I x y from le_antisymm (H y x) (H x y) intro x y apply le_of_forall_gt (fun r hr ↦ ?_) rcases exists_lt_locally_constant_of_riemannianEDist_lt hr zero_lt_one with ⟨γ, γ0, γ1, γ_smooth, hγ, -⟩ let η : ℝ → ℝ := fun t ↦ - t have h_smooth : ContMDiff 𝓘(ℝ) I 1 (γ ∘ η) := by apply γ_smooth.comp ?_ simp only [contMDiff_iff_contDiff] fun_prop have : riemannianEDist I y x ≤ pathELength I (γ ∘ η) (η 1) (η 0) := by apply riemannianEDist_le_pathELength h_smooth.contMDiffOn <;> simp [η, γ0, γ1] rw [← pathELength_comp_of_antitoneOn zero_le_one] at this; rotate_left · exact monotone_id.neg.antitoneOn _ · exact differentiableOn_neg _ · exact h_smooth.contMDiffOn.mdifferentiableOn le_rfl apply this.trans_lt convert hγ ext t simp [η] lemma riemannianEDist_triangle : riemannianEDist I x z ≤ riemannianEDist I x y + riemannianEDist I y z := by apply le_of_forall_gt (fun r hr ↦ ?_) rcases ENNReal.exists_add_lt_of_add_lt hr with ⟨u, hu, v, hv, huv⟩ rcases exists_lt_locally_constant_of_riemannianEDist_lt hu zero_lt_one with ⟨γ₁, hγ₁0, hγ₁1, hγ₁_smooth, hγ₁, -, hγ₁_const⟩ rcases exists_lt_locally_constant_of_riemannianEDist_lt hv one_lt_two with ⟨γ₂, hγ₂1, hγ₂2, hγ₂_smooth, hγ₂, hγ₂_const, -⟩ let γ := piecewise (Iic 1) γ₁ γ₂ have : riemannianEDist I x z ≤ pathELength I γ 0 2 := by apply riemannianEDist_le_pathELength · apply ContMDiff.contMDiffOn exact ContMDiff.piecewise_Iic hγ₁_smooth hγ₂_smooth (hγ₁_const.trans hγ₂_const.symm) · simp [γ, hγ₁0] · simp [γ, hγ₂2] · exact zero_le_two apply this.trans_lt (lt_trans ?_ huv) rw [← pathELength_add zero_le_one one_le_two] gcongr · convert hγ₁ using 1 apply pathELength_congr intro t ht simp [γ, ht.2] · convert hγ₂ using 1 apply pathELength_congr_Ioo intro t ht simp [γ, ht.1] end end Manifold
Basic.lean
/- Copyright (c) 2025 Richard Hill. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Richard Hill, Andrew Yang -/ import Mathlib.Algebra.Category.ModuleCat.Topology.Homology import Mathlib.Algebra.Homology.Embedding.Restriction import Mathlib.Algebra.Homology.Functor import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex import Mathlib.CategoryTheory.Action.Limits import Mathlib.Topology.ContinuousMap.Algebra /-! # Continuous cohomology We define continuous cohomology as the homology of homogeneous cochains. ## Implementation details We define homogeneous cochains as `g`-invariant continuous function in `C(G, C(G,...,C(G, M)))` instead of the usual `C(Gⁿ, M)` to allow more general topological groups other than locally compact ones. For this to work, we also work in `Action (TopModuleCat R) G`, where the `G` action on `M` is only continuous on `M`, and not necessarily continuous in both variables, because the `G` action on `C(G, M)` might not be continuous on both variables even if it is on `M`. For the differential map, instead of a finite sum we use the inductive definition `d₋₁ : M → C(G, M) := const : m ↦ g ↦ m` and `dₙ₊₁ : C(G, _) → C(G, C(G, _)) := const - C(G, dₙ) : f ↦ g ↦ f - dₙ (f (g))` See `ContinuousCohomology.MultiInd.d`. ## Main definition - `ContinuousCohomology.homogeneousCochains`: The functor taking an `R`-linear `G`-representation to the complex of homogeneous cochains. - `continuousCohomology`: The functor taking an `R`-linear `G`-representation to its `n`-th continuous cohomology. ## TODO - Show that it coincides with `groupCohomology` for discrete groups. - Give the usual description of cochains in terms of `n`-ary functions for locally compact groups. - Show that short exact sequences induce long exact sequences in certain scenarios. -/ open CategoryTheory Functor ContinuousMap variable (R G : Type*) [CommRing R] [Group G] [TopologicalSpace R] namespace ContinuousCohomology variable [TopologicalSpace G] [IsTopologicalGroup G] variable {R G} in /-- The `G` representation `C(G, rep)` given a representation `rep`. The `G` action is defined by `g • f := x ↦ g • f (g⁻¹ * x)`. -/ abbrev Iobj (rep : Action (TopModuleCat R) G) : Action (TopModuleCat R) G where V := .of R C(G, rep.V) ρ := { toFun g := TopModuleCat.ofHom { toFun f := .comp (rep.ρ g).hom (f.comp (Homeomorph.mulLeft g⁻¹)) map_add' _ _ := by ext; simp map_smul' _ _ := by ext; simp cont := (continuous_postcomp _).comp (continuous_precomp _) } map_one' := ConcreteCategory.ext (by ext; simp) map_mul' _ _ := ConcreteCategory.ext (by ext; simp [mul_assoc]) } lemma Iobj_ρ_apply (rep : Action (TopModuleCat R) G) (g f x) : ((Iobj rep).ρ g).hom f x = (rep.ρ g).hom (f (g⁻¹ * x)) := rfl /-- The functor taking a representation `rep` to the representation `C(G, rep)`. -/ @[simps] def I : Action (TopModuleCat R) G ⥤ Action (TopModuleCat R) G where obj := Iobj map {M N} φ := { hom := TopModuleCat.ofHom (ContinuousLinearMap.compLeftContinuous _ _ φ.hom.hom) comm g := by ext f g' change (M.ρ g ≫ φ.hom).hom (f (g⁻¹ * g')) = (φ.hom ≫ N.ρ g).hom (f (g⁻¹ * g')) rw [φ.comm] } map_id _ := rfl map_comp _ _ := rfl instance : (I R G).Additive where instance : (I R G).Linear R where /-- The constant function `rep ⟶ C(G, rep)` as a natural transformation. -/ @[simps] def const : 𝟭 _ ⟶ I R G where app _ := { hom := TopModuleCat.ofHom (.const _ _), comm _ := rfl } naturality _ _ _ := rfl namespace MultiInd /-- The n-th functor taking `M` to `C(G, C(G,...,C(G, M)))` (with n `G`s). These functors form a complex, see `MultiInd.complex`. -/ def functor : ℕ → Action (TopModuleCat R) G ⥤ Action (TopModuleCat R) G | 0 => 𝟭 _ | n + 1 => functor n ⋙ I R G /-- The differential map in `MultiInd.complex`. -/ def d : ∀ n : ℕ, functor R G n ⟶ functor R G (n + 1) | 0 => const R G | n + 1 => whiskerLeft (functor R G (n + 1)) (const R G) - (by exact whiskerRight (d n) (I R G)) lemma d_zero : d R G 0 = const R G := rfl lemma d_succ (n : ℕ) : d R G (n + 1) = whiskerLeft (functor R G (n + 1)) (const R G) - (by exact whiskerRight (d R G n) (I R G)) := rfl @[reassoc (attr := simp)] lemma d_comp_d (n : ℕ) : d R G n ≫ d R G (n + 1) = 0 := by induction n with | zero => rw [d_succ, Preadditive.comp_sub, sub_eq_zero] rfl | succ n ih => rw [d_succ R G (n + 1), Preadditive.comp_sub] nth_rw 2 [d_succ] rw [Preadditive.sub_comp, ← whiskerRight_comp, ih, Functor.whiskerRight_zero, sub_zero, sub_eq_zero] rfl /-- The complex of functors whose behaviour pointwise takes an `R`-linear `G`-representation `M` to the complex `M → C(G, M) → ⋯ → C(G, C(G,...,C(G, M))) → ⋯` The `G`-invariant submodules of it is the homogeneous cochains (shifted by one). -/ def complex : CochainComplex (Action (TopModuleCat R) G ⥤ Action (TopModuleCat R) G) ℕ := CochainComplex.of (functor R G) (d R G) (d_comp_d R G) end MultiInd /-- The functor taking an `R`-linear `G`-representation to its `G`-invariant submodule. -/ def invariants : Action (TopModuleCat R) G ⥤ TopModuleCat R where obj M := .of R { carrier := { x | ∀ g : G, (M.ρ g).hom x = x } add_mem' hx hy g := by simp [hx g, hy g] zero_mem' := by simp smul_mem' r x hx g := by simp [hx g] : Submodule R M.V } map f := TopModuleCat.ofHom { toLinearMap := f.hom.hom.restrict fun x hx g ↦ congr($(f.comm g) x).symm.trans congr(f.hom.hom $(hx g)) cont := continuous_induced_rng.mpr (f.hom.hom.2.comp continuous_subtype_val) } instance : (invariants R G).Linear R where instance : (invariants R G).Additive where /-- `homogeneousCochains R G` is the functor taking an `R`-linear `G`-representation to the complex of homogeneous cochains. -/ def homogeneousCochains : Action (TopModuleCat R) G ⥤ CochainComplex (TopModuleCat R) ℕ := (MultiInd.complex R G).asFunctor ⋙ (invariants R G).mapHomologicalComplex _ ⋙ (ComplexShape.embeddingUp'Add 1 1).restrictionFunctor _ /-- `continuousCohomology R G n` is the functor taking an `R`-linear `G`-representation to its `n`-th continuous cohomology. -/ noncomputable def _root_.continuousCohomology (n : ℕ) : Action (TopModuleCat R) G ⥤ TopModuleCat R := homogeneousCochains R G ⋙ HomologicalComplex.homologyFunctor _ _ n /-- The `0`-homogeneous cochains are isomorphic to `Xᴳ`. -/ def kerHomogeneousCochainsZeroEquiv (X : Action (TopModuleCat R) G) (n : ℕ) (hn : n = 1) : LinearMap.ker (((homogeneousCochains R G).obj X).d 0 n).hom ≃L[R] (invariants R G).obj X where toFun x := { val := DFunLike.coe (F := C(G, _)) x.1.1 1 property g := by subst hn obtain ⟨⟨x : C(G, _), hx⟩, hx'⟩ := x have : (X.ρ g).hom (x (g⁻¹ * 1)) = x 1 := congr(DFunLike.coe (F := C(G, _)) $(hx g) 1) have hx' : x (g⁻¹ * 1) - x 1 = 0 := congr(DFunLike.coe (F := C(G, _)) (DFunLike.coe (F := C(G, _)) ($hx').1 1) (g⁻¹ * 1)) rw [sub_eq_zero] at hx' exact congr((X.ρ g).hom $hx').symm.trans this } map_add' _ _ := rfl map_smul' _ _ := rfl invFun x := by refine ⟨⟨ContinuousLinearMap.const R _ x.1, fun g ↦ ContinuousMap.ext fun a ↦ by subst hn; exact x.2 g⟩, ?_⟩ subst hn exact Subtype.ext (ContinuousMap.ext fun a ↦ ContinuousMap.ext fun b ↦ show x.1 - x.1 = (0 : X.V) by simp) left_inv x := by subst hn obtain ⟨⟨x : C(G, _), hx⟩, hx'⟩ := x refine Subtype.ext (Subtype.ext <| ContinuousMap.ext fun a ↦ ?_) have hx' : x 1 - x a = 0 := congr(DFunLike.coe (F := C(G, _)) (DFunLike.coe (F := C(G, _)) ($hx').1 a) 1) rwa [sub_eq_zero] at hx' right_inv _ := rfl continuous_toFun := continuous_induced_rng.mpr ((continuous_eval_const (F := C(G, _)) 1).comp (continuous_subtype_val.comp continuous_subtype_val)) continuous_invFun := continuous_induced_rng.mpr (continuous_induced_rng.mpr ((ContinuousLinearMap.const R G).cont.comp continuous_subtype_val)) open ShortComplex HomologyData in /-- `H⁰_cont(G, X) ≅ Xᴳ`. -/ noncomputable def continuousCohomologyZeroIso : (continuousCohomology R G 0) ≅ invariants R G := NatIso.ofComponents (fun X ↦ (ofIsLimitKernelFork _ (by simp) _ (TopModuleCat.isLimitKer _)).left.homologyIso ≪≫ TopModuleCat.ofIso (kerHomogeneousCochainsZeroEquiv R G X _ (by simp))) fun {X Y} f ↦ by dsimp [continuousCohomology, HomologicalComplex.homologyMap] rw [Category.assoc, ← Iso.inv_comp_eq] rw [LeftHomologyData.leftHomologyIso_inv_naturality_assoc, Iso.inv_hom_id_assoc, ← cancel_epi (LeftHomologyData.π _), leftHomologyπ_naturality'_assoc] rfl end ContinuousCohomology
Algebra.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.DirectSum.Module import Mathlib.Algebra.DirectSum.Ring /-! # Additively-graded algebra structures on `⨁ i, A i` This file provides `R`-algebra structures on external direct sums of `R`-modules. Recall that if `A i` are a family of `AddCommMonoid`s indexed by an `AddMonoid`, then an instance of `DirectSum.GMonoid A` is a multiplication `A i → A j → A (i + j)` giving `⨁ i, A i` the structure of a semiring. In this file, we introduce the `DirectSum.GAlgebra R A` class for the case where all `A i` are `R`-modules. This is the extra structure needed to promote `⨁ i, A i` to an `R`-algebra. ## Main definitions * `DirectSum.GAlgebra R A`, the typeclass. * `DirectSum.toAlgebra` extends `DirectSum.toSemiring` to produce an `AlgHom`. -/ universe uι uR uA uB variable {ι : Type uι} namespace DirectSum open DirectSum variable (R : Type uR) (A : ι → Type uA) {B : Type uB} variable [CommSemiring R] [∀ i, AddCommMonoid (A i)] [∀ i, Module R (A i)] variable [AddMonoid ι] [GSemiring A] section /-- A graded version of `Algebra`. An instance of `DirectSum.GAlgebra R A` endows `(⨁ i, A i)` with an `R`-algebra structure. -/ class GAlgebra where toFun : R →+ A 0 map_one : toFun 1 = GradedMonoid.GOne.one map_mul : ∀ r s, GradedMonoid.mk _ (toFun (r * s)) = .mk _ (GradedMonoid.GMul.mul (toFun r) (toFun s)) commutes : ∀ (r) (x : GradedMonoid A), .mk _ (toFun r) * x = x * .mk _ (toFun r) smul_def : ∀ (r) (x : GradedMonoid A), r • x = .mk _ (toFun r) * x end variable [Semiring B] [GAlgebra R A] [Algebra R B] instance _root_.GradedMonoid.smulCommClass_right : SMulCommClass R (GradedMonoid A) (GradedMonoid A) where smul_comm s x y := by dsimp rw [GAlgebra.smul_def, GAlgebra.smul_def, ← mul_assoc, GAlgebra.commutes, mul_assoc] instance _root_.GradedMonoid.isScalarTower_right : IsScalarTower R (GradedMonoid A) (GradedMonoid A) where smul_assoc s x y := by dsimp rw [GAlgebra.smul_def, GAlgebra.smul_def, ← mul_assoc] variable [DecidableEq ι] instance : Algebra R (⨁ i, A i) where algebraMap := { toFun := (DirectSum.of A 0).comp GAlgebra.toFun map_zero' := AddMonoidHom.map_zero _ map_add' := AddMonoidHom.map_add _ map_one' := DFunLike.congr_arg (DirectSum.of A 0) GAlgebra.map_one map_mul' a b := by simp only [AddMonoidHom.comp_apply] rw [of_mul_of] apply DFinsupp.single_eq_of_sigma_eq (GAlgebra.map_mul a b) } commutes' r x := by change AddMonoidHom.mul (DirectSum.of _ _ _) x = AddMonoidHom.mul.flip (DirectSum.of _ _ _) x apply DFunLike.congr_fun _ x ext i xi : 2 dsimp only [AddMonoidHom.comp_apply, AddMonoidHom.mul_apply, AddMonoidHom.flip_apply] rw [of_mul_of, of_mul_of] apply DFinsupp.single_eq_of_sigma_eq (GAlgebra.commutes r ⟨i, xi⟩) smul_def' r x := by change DistribMulAction.toAddMonoidHom _ r x = AddMonoidHom.mul (DirectSum.of _ _ _) x apply DFunLike.congr_fun _ x ext i xi : 2 dsimp only [AddMonoidHom.comp_apply, DistribMulAction.toAddMonoidHom_apply, AddMonoidHom.mul_apply] rw [DirectSum.of_mul_of, ← of_smul] apply DFinsupp.single_eq_of_sigma_eq (GAlgebra.smul_def r ⟨i, xi⟩) theorem algebraMap_apply (r : R) : algebraMap R (⨁ i, A i) r = DirectSum.of A 0 (GAlgebra.toFun r) := rfl theorem algebraMap_toAddMonoid_hom : ↑(algebraMap R (⨁ i, A i)) = (DirectSum.of A 0).comp (GAlgebra.toFun : R →+ A 0) := rfl /-- A family of `LinearMap`s preserving `DirectSum.GOne.one` and `DirectSum.GMul.mul` describes an `AlgHom` on `⨁ i, A i`. This is a stronger version of `DirectSum.toSemiring`. Of particular interest is the case when `A i` are bundled subobjects, `f` is the family of coercions such as `Submodule.subtype (A i)`, and the `[GMonoid A]` structure originates from `DirectSum.GMonoid.ofAddSubmodules`, in which case the proofs about `GOne` and `GMul` can be discharged by `rfl`. -/ @[simps] def toAlgebra (f : ∀ i, A i →ₗ[R] B) (hone : f _ GradedMonoid.GOne.one = 1) (hmul : ∀ {i j} (ai : A i) (aj : A j), f _ (GradedMonoid.GMul.mul ai aj) = f _ ai * f _ aj) : (⨁ i, A i) →ₐ[R] B := { toSemiring (fun i => (f i).toAddMonoidHom) hone @hmul with toFun := toSemiring (fun i => (f i).toAddMonoidHom) hone @hmul commutes' := fun r => by change toModule R _ _ f (algebraMap R _ r) = _ rw [Algebra.algebraMap_eq_smul_one, Algebra.algebraMap_eq_smul_one, map_smul, one_def, ← lof_eq_of R, toModule_lof, hone] } /-- Two `AlgHom`s out of a direct sum are equal if they agree on the generators. See note [partially-applied ext lemmas]. -/ @[ext] theorem algHom_ext' ⦃f g : (⨁ i, A i) →ₐ[R] B⦄ (h : ∀ i, f.toLinearMap.comp (lof _ _ A i) = g.toLinearMap.comp (lof _ _ A i)) : f = g := AlgHom.toLinearMap_injective <| DirectSum.linearMap_ext _ h theorem algHom_ext ⦃f g : (⨁ i, A i) →ₐ[R] B⦄ (h : ∀ i x, f (of A i x) = g (of A i x)) : f = g := algHom_ext' R A fun i => LinearMap.ext <| h i /-- The piecewise multiplication from the `Mul` instance, as a bundled linear map. This is the graded version of `LinearMap.mul`, and the linear version of `DirectSum.gMulHom` -/ @[simps] def gMulLHom {i j} : A i →ₗ[R] A j →ₗ[R] A (i + j) where toFun a := { toFun := fun b => GradedMonoid.GMul.mul a b map_smul' := fun r x => by injection (smul_comm r (GradedMonoid.mk _ a) (GradedMonoid.mk _ x)).symm map_add' := GNonUnitalNonAssocSemiring.mul_add _ } map_smul' r x := LinearMap.ext fun y => by injection smul_assoc r (GradedMonoid.mk _ x) (GradedMonoid.mk _ y) map_add' _ _ := LinearMap.ext fun _ => GNonUnitalNonAssocSemiring.add_mul _ _ _ end DirectSum /-! ### Concrete instances -/ /-- A direct sum of copies of an `Algebra` inherits the algebra structure. -/ @[simps] instance Algebra.directSumGAlgebra {R A : Type*} [AddMonoid ι] [CommSemiring R] [Semiring A] [Algebra R A] : DirectSum.GAlgebra R fun _ : ι => A where toFun := (algebraMap R A).toAddMonoidHom map_one := (algebraMap R A).map_one map_mul a b := Sigma.ext (zero_add _).symm (heq_of_eq <| (algebraMap R A).map_mul a b) commutes := fun _ ⟨_, _⟩ => Sigma.ext ((zero_add _).trans (add_zero _).symm) (heq_of_eq <| Algebra.commutes _ _) smul_def := fun _ ⟨_, _⟩ => Sigma.ext (zero_add _).symm (heq_of_eq <| Algebra.smul_def _ _)
Caratheodory.lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.OuterMeasure.OfFunction import Mathlib.MeasureTheory.PiSystem /-! # The Caratheodory σ-algebra of an outer measure Given an outer measure `m`, the Carathéodory-measurable sets are the sets `s` such that for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. This forms a measurable space. ## Main definitions and statements * `MeasureTheory.OuterMeasure.caratheodory` is the Carathéodory-measurable space of an outer measure. ## References * <https://en.wikipedia.org/wiki/Outer_measure> * <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion> ## Tags Carathéodory-measurable, Carathéodory's criterion -/ noncomputable section open Set Function Filter open scoped NNReal Topology ENNReal namespace MeasureTheory namespace OuterMeasure section CaratheodoryMeasurable universe u variable {α : Type u} (m : OuterMeasure α) attribute [local simp] Set.inter_comm Set.inter_left_comm Set.inter_assoc variable {s s₁ s₂ : Set α} /-- A set `s` is Carathéodory-measurable for an outer measure `m` if for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. -/ def IsCaratheodory (s : Set α) : Prop := ∀ t, m t = m (t ∩ s) + m (t \ s) theorem isCaratheodory_iff_le' {s : Set α} : IsCaratheodory m s ↔ ∀ t, m (t ∩ s) + m (t \ s) ≤ m t := forall_congr' fun _ => le_antisymm_iff.trans <| and_iff_right <| measure_le_inter_add_diff _ _ _ @[simp] theorem isCaratheodory_empty : IsCaratheodory m ∅ := by simp [IsCaratheodory, diff_empty] theorem isCaratheodory_compl : IsCaratheodory m s₁ → IsCaratheodory m s₁ᶜ := by simp [IsCaratheodory, diff_eq, add_comm] @[simp] theorem isCaratheodory_compl_iff : IsCaratheodory m sᶜ ↔ IsCaratheodory m s := ⟨fun h => by simpa using isCaratheodory_compl m h, isCaratheodory_compl m⟩ theorem isCaratheodory_union (h₁ : IsCaratheodory m s₁) (h₂ : IsCaratheodory m s₂) : IsCaratheodory m (s₁ ∪ s₂) := fun t => by rw [h₁ t, h₂ (t ∩ s₁), h₂ (t \ s₁), h₁ (t ∩ (s₁ ∪ s₂)), inter_diff_assoc _ _ s₁, Set.inter_assoc _ _ s₁, inter_eq_self_of_subset_right Set.subset_union_left, union_diff_left, h₂ (t ∩ s₁)] simp [diff_eq, add_assoc] variable {m} in lemma IsCaratheodory.biUnion_of_finite {ι : Type*} {s : ι → Set α} {t : Set ι} (ht : t.Finite) (h : ∀ i ∈ t, m.IsCaratheodory (s i)) : m.IsCaratheodory (⋃ i ∈ t, s i) := by classical lift t to Finset ι using ht induction t using Finset.induction_on with | empty => simp | insert i t hi IH => simp only [Finset.mem_coe, Finset.mem_insert, iUnion_iUnion_eq_or_left] at h ⊢ exact m.isCaratheodory_union (h _ <| Or.inl rfl) (IH fun _ hj ↦ h _ <| Or.inr hj) theorem measure_inter_union (h : s₁ ∩ s₂ ⊆ ∅) (h₁ : IsCaratheodory m s₁) {t : Set α} : m (t ∩ (s₁ ∪ s₂)) = m (t ∩ s₁) + m (t ∩ s₂) := by rw [h₁, Set.inter_assoc, Set.union_inter_cancel_left, inter_diff_assoc, union_diff_cancel_left h] theorem isCaratheodory_iUnion_lt {s : ℕ → Set α} : ∀ {n : ℕ}, (∀ i < n, IsCaratheodory m (s i)) → IsCaratheodory m (⋃ i < n, s i) | 0, _ => by simp | n + 1, h => by rw [biUnion_lt_succ] exact isCaratheodory_union m (isCaratheodory_iUnion_lt fun i hi => h i <| lt_of_lt_of_le hi <| Nat.le_succ _) (h n (le_refl (n + 1))) theorem isCaratheodory_inter (h₁ : IsCaratheodory m s₁) (h₂ : IsCaratheodory m s₂) : IsCaratheodory m (s₁ ∩ s₂) := by rw [← isCaratheodory_compl_iff, Set.compl_inter] exact isCaratheodory_union _ (isCaratheodory_compl _ h₁) (isCaratheodory_compl _ h₂) lemma isCaratheodory_diff (h₁ : IsCaratheodory m s₁) (h₂ : IsCaratheodory m s₂) : IsCaratheodory m (s₁ \ s₂) := m.isCaratheodory_inter h₁ (m.isCaratheodory_compl h₂) lemma isCaratheodory_partialSups {ι : Type*} [Preorder ι] [LocallyFiniteOrderBot ι] {s : ι → Set α} (h : ∀ i, m.IsCaratheodory (s i)) (i : ι) : m.IsCaratheodory (partialSups s i) := by simpa only [partialSups_apply, Finset.sup'_eq_sup, Finset.sup_set_eq_biUnion, ← Finset.mem_coe, Finset.coe_Iic] using .biUnion_of_finite (finite_Iic _) (fun j _ ↦ h j) lemma isCaratheodory_disjointed {ι : Type*} [Preorder ι] [LocallyFiniteOrderBot ι] {s : ι → Set α} (h : ∀ i, m.IsCaratheodory (s i)) (i : ι) : m.IsCaratheodory (disjointed s i) := disjointedRec (fun _ j ht ↦ m.isCaratheodory_diff ht <| h j) (h i) theorem isCaratheodory_sum {s : ℕ → Set α} (h : ∀ i, IsCaratheodory m (s i)) (hd : Pairwise (Disjoint on s)) {t : Set α} : ∀ {n}, (∑ i ∈ Finset.range n, m (t ∩ s i)) = m (t ∩ ⋃ i < n, s i) | 0 => by simp | Nat.succ n => by rw [biUnion_lt_succ, Finset.sum_range_succ, Set.union_comm, isCaratheodory_sum h hd, m.measure_inter_union _ (h n), add_comm] intro a simpa using fun (h₁ : a ∈ s n) i (hi : i < n) h₂ => (hd (ne_of_gt hi)).le_bot ⟨h₁, h₂⟩ /-- Use `isCaratheodory_iUnion` instead, which does not require the disjoint assumption. -/ theorem isCaratheodory_iUnion_of_disjoint {s : ℕ → Set α} (h : ∀ i, IsCaratheodory m (s i)) (hd : Pairwise (Disjoint on s)) : IsCaratheodory m (⋃ i, s i) := by apply (isCaratheodory_iff_le' m).mpr intro t have hp : m (t ∩ ⋃ i, s i) ≤ ⨆ n, m (t ∩ ⋃ i < n, s i) := by convert measure_iUnion_le (μ := m) fun i => t ∩ s i using 1 · simp [inter_iUnion] · simp [ENNReal.tsum_eq_iSup_nat, isCaratheodory_sum m h hd] refine le_trans (add_le_add_right hp _) ?_ rw [ENNReal.iSup_add] refine iSup_le fun n => le_trans (add_le_add_left ?_ _) (ge_of_eq (isCaratheodory_iUnion_lt m (fun i _ => h i) _)) refine m.mono (diff_subset_diff_right ?_) exact iUnion₂_subset fun i _ => subset_iUnion _ i lemma isCaratheodory_iUnion {s : ℕ → Set α} (h : ∀ i, m.IsCaratheodory (s i)) : m.IsCaratheodory (⋃ i, s i) := by rw [← iUnion_disjointed] exact m.isCaratheodory_iUnion_of_disjoint (m.isCaratheodory_disjointed h) (disjoint_disjointed _) theorem f_iUnion {s : ℕ → Set α} (h : ∀ i, IsCaratheodory m (s i)) (hd : Pairwise (Disjoint on s)) : m (⋃ i, s i) = ∑' i, m (s i) := by refine le_antisymm (measure_iUnion_le s) ?_ rw [ENNReal.tsum_eq_iSup_nat] refine iSup_le fun n => ?_ have := @isCaratheodory_sum _ m _ h hd univ n simp only [inter_comm, inter_univ, univ_inter] at this; simp only [this] exact m.mono (iUnion₂_subset fun i _ => subset_iUnion _ i) /-- The Carathéodory-measurable sets for an outer measure `m` form a Dynkin system. -/ def caratheodoryDynkin : MeasurableSpace.DynkinSystem α where Has := IsCaratheodory m has_empty := isCaratheodory_empty m has_compl s := isCaratheodory_compl m s has_iUnion_nat _ hf hn := by apply isCaratheodory_iUnion m hf /-- Given an outer measure `μ`, the Carathéodory-measurable space is defined such that `s` is measurable if `∀ t, μ t = μ (t ∩ s) + μ (t \ s)`. -/ protected def caratheodory : MeasurableSpace α := by apply MeasurableSpace.DynkinSystem.toMeasurableSpace (caratheodoryDynkin m) intro s₁ s₂ apply isCaratheodory_inter theorem isCaratheodory_iff {s : Set α} : MeasurableSet[OuterMeasure.caratheodory m] s ↔ ∀ t, m t = m (t ∩ s) + m (t \ s) := Iff.rfl theorem isCaratheodory_iff_le {s : Set α} : MeasurableSet[OuterMeasure.caratheodory m] s ↔ ∀ t, m (t ∩ s) + m (t \ s) ≤ m t := isCaratheodory_iff_le' m protected theorem iUnion_eq_of_caratheodory {s : ℕ → Set α} (h : ∀ i, MeasurableSet[OuterMeasure.caratheodory m] (s i)) (hd : Pairwise (Disjoint on s)) : m (⋃ i, s i) = ∑' i, m (s i) := f_iUnion m h hd end CaratheodoryMeasurable variable {α : Type*} theorem ofFunction_caratheodory {m : Set α → ℝ≥0∞} {s : Set α} {h₀ : m ∅ = 0} (hs : ∀ t, m (t ∩ s) + m (t \ s) ≤ m t) : MeasurableSet[(OuterMeasure.ofFunction m h₀).caratheodory] s := by apply (isCaratheodory_iff_le _).mpr refine fun t => le_iInf fun f => le_iInf fun hf => ?_ refine le_trans (add_le_add ((iInf_le_of_le fun i => f i ∩ s) <| iInf_le _ ?_) ((iInf_le_of_le fun i => f i \ s) <| iInf_le _ ?_)) ?_ · rw [← iUnion_inter] exact inter_subset_inter_left _ hf · rw [← iUnion_diff] exact diff_subset_diff_left hf · rw [← ENNReal.tsum_add] exact ENNReal.tsum_le_tsum fun i => hs _ theorem boundedBy_caratheodory {m : Set α → ℝ≥0∞} {s : Set α} (hs : ∀ t, m (t ∩ s) + m (t \ s) ≤ m t) : MeasurableSet[(boundedBy m).caratheodory] s := by apply ofFunction_caratheodory; intro t rcases t.eq_empty_or_nonempty with h | h · simp [h, Set.not_nonempty_empty] · convert le_trans _ (hs t) · simp [h] exact add_le_add iSup_const_le iSup_const_le @[simp] theorem zero_caratheodory : (0 : OuterMeasure α).caratheodory = ⊤ := top_unique fun _ _ _ => (add_zero _).symm theorem top_caratheodory : (⊤ : OuterMeasure α).caratheodory = ⊤ := top_unique fun s _ => (isCaratheodory_iff_le _).2 fun t => t.eq_empty_or_nonempty.elim (fun ht => by simp [ht]) fun ht => by simp only [ht, top_apply, le_top] theorem le_add_caratheodory (m₁ m₂ : OuterMeasure α) : m₁.caratheodory ⊓ m₂.caratheodory ≤ (m₁ + m₂ : OuterMeasure α).caratheodory := fun s ⟨hs₁, hs₂⟩ t => by simp [hs₁ t, hs₂ t, add_left_comm, add_assoc] theorem le_sum_caratheodory {ι} (m : ι → OuterMeasure α) : ⨅ i, (m i).caratheodory ≤ (sum m).caratheodory := fun s h t => by simp [fun i => MeasurableSpace.measurableSet_iInf.1 h i t, ENNReal.tsum_add] theorem le_smul_caratheodory (a : ℝ≥0∞) (m : OuterMeasure α) : m.caratheodory ≤ (a • m).caratheodory := fun s h t => by simp only [smul_apply, smul_eq_mul] rw [(isCaratheodory_iff m).mp h t] simp [mul_add] @[simp] theorem dirac_caratheodory (a : α) : (dirac a).caratheodory = ⊤ := top_unique fun s _ t => by by_cases ht : a ∈ t; swap; · simp [ht] by_cases hs : a ∈ s <;> simp [*] end OuterMeasure end MeasureTheory
Relative.lean
/- Copyright (c) 2025 Jeremy Tan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Tan -/ import Mathlib.Data.Set.Image import Mathlib.Data.SetLike.Basic import Mathlib.Order.Interval.Set.Defs import Mathlib.Order.SetNotation /-! # Properties of relative upper/lower sets This file proves results on `IsRelUpperSet` and `IsRelLowerSet`. -/ open Set variable {α : Type*} {ι : Sort*} {κ : ι → Sort*} {s t : Set α} {a : α} {P : α → Prop} section LE variable [LE α] lemma IsRelUpperSet.prop_of_mem (hs : IsRelUpperSet s P) (h : a ∈ s) : P a := (hs h).1 lemma IsRelLowerSet.prop_of_mem (hs : IsRelLowerSet s P) (h : a ∈ s) : P a := (hs h).1 @[simp] lemma isRelUpperSet_empty : IsRelUpperSet (∅ : Set α) P := fun _ ↦ False.elim @[simp] lemma isRelLowerSet_empty : IsRelLowerSet (∅ : Set α) P := fun _ ↦ False.elim @[simp] lemma isRelUpperSet_self : IsRelUpperSet s (· ∈ s) := fun _ b ↦ ⟨b, fun _ _ ↦ id⟩ @[simp] lemma isRelLowerSet_self : IsRelLowerSet s (· ∈ s) := fun _ b ↦ ⟨b, fun _ _ ↦ id⟩ lemma IsRelUpperSet.union (hs : IsRelUpperSet s P) (ht : IsRelUpperSet t P) : IsRelUpperSet (s ∪ t) P := fun b mb ↦ by cases mb with | inl h => exact ⟨(hs h).1, fun _ x y ↦ .inl ((hs h).2 x y)⟩ | inr h => exact ⟨(ht h).1, fun _ x y ↦ .inr ((ht h).2 x y)⟩ lemma IsRelLowerSet.union (hs : IsRelLowerSet s P) (ht : IsRelLowerSet t P) : IsRelLowerSet (s ∪ t) P := fun b mb ↦ by cases mb with | inl h => exact ⟨(hs h).1, fun _ x y ↦ .inl ((hs h).2 x y)⟩ | inr h => exact ⟨(ht h).1, fun _ x y ↦ .inr ((ht h).2 x y)⟩ lemma IsRelUpperSet.inter (hs : IsRelUpperSet s P) (ht : IsRelUpperSet t P) : IsRelUpperSet (s ∩ t) P := fun b ⟨bs, bt⟩ ↦ by simp_all only [IsRelUpperSet, true_and] exact fun _ x y ↦ ⟨(hs bs).2 x y, (ht bt).2 x y⟩ lemma IsRelLowerSet.inter (hs : IsRelLowerSet s P) (ht : IsRelLowerSet t P) : IsRelLowerSet (s ∩ t) P := fun b ⟨bs, bt⟩ ↦ by simp_all only [IsRelLowerSet, true_and] exact fun _ x y ↦ ⟨(hs bs).2 x y, (ht bt).2 x y⟩ protected lemma IsRelUpperSet.sUnion {S : Set (Set α)} (hS : ∀ s ∈ S, IsRelUpperSet s P) : IsRelUpperSet (⋃₀ S) P := fun _ ⟨s, ms, mb⟩ ↦ ⟨(hS s ms mb).1, fun _ x y ↦ ⟨s, ms, (hS s ms mb).2 x y⟩⟩ protected lemma IsRelLowerSet.sUnion {S : Set (Set α)} (hS : ∀ s ∈ S, IsRelLowerSet s P) : IsRelLowerSet (⋃₀ S) P := fun _ ⟨s, ms, mb⟩ ↦ ⟨(hS s ms mb).1, fun _ x y ↦ ⟨s, ms, (hS s ms mb).2 x y⟩⟩ protected lemma IsRelUpperSet.iUnion {f : ι → Set α} (hf : ∀ i, IsRelUpperSet (f i) P) : IsRelUpperSet (⋃ i, f i) P := .sUnion (forall_mem_range.2 hf) protected lemma IsRelLowerSet.iUnion {f : ι → Set α} (hf : ∀ i, IsRelLowerSet (f i) P) : IsRelLowerSet (⋃ i, f i) P := .sUnion (forall_mem_range.2 hf) protected lemma IsRelUpperSet.iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsRelUpperSet (f i j) P) : IsRelUpperSet (⋃ (i) (j), f i j) P := .iUnion fun i ↦ .iUnion (hf i) protected lemma IsRelLowerSet.iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsRelLowerSet (f i j) P) : IsRelLowerSet (⋃ (i) (j), f i j) P := .iUnion fun i ↦ .iUnion (hf i) protected lemma IsRelUpperSet.sInter {S : Set (Set α)} (hS : S.Nonempty) (hf : ∀ s ∈ S, IsRelUpperSet s P) : IsRelUpperSet (⋂₀ S) P := fun b mb ↦ by obtain ⟨s₀, ms₀⟩ := hS refine ⟨(hf s₀ ms₀ (mb s₀ ms₀)).1, fun _ x y s ms ↦ (hf s ms (mb s ms)).2 x y⟩ protected lemma IsRelLowerSet.sInter {S : Set (Set α)} (hS : S.Nonempty) (hf : ∀ s ∈ S, IsRelLowerSet s P) : IsRelLowerSet (⋂₀ S) P := fun b mb ↦ by obtain ⟨s₀, ms₀⟩ := hS refine ⟨(hf s₀ ms₀ (mb s₀ ms₀)).1, fun _ x y s ms ↦ (hf s ms (mb s ms)).2 x y⟩ protected lemma IsRelUpperSet.iInter [Nonempty ι] {f : ι → Set α} (hf : ∀ i, IsRelUpperSet (f i) P) : IsRelUpperSet (⋂ i, f i) P := .sInter (range_nonempty f) (forall_mem_range.2 hf) protected lemma IsRelLowerSet.iInter [Nonempty ι] {f : ι → Set α} (hf : ∀ i, IsRelLowerSet (f i) P) : IsRelLowerSet (⋂ i, f i) P := .sInter (range_nonempty f) (forall_mem_range.2 hf) protected lemma IsRelUpperSet.iInter₂ [Nonempty ι] [∀ i, Nonempty (κ i)] {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsRelUpperSet (f i j) P) : IsRelUpperSet (⋂ (i) (j), f i j) P := .iInter fun i ↦ .iInter (hf i) protected lemma IsRelLowerSet.iInter₂ [Nonempty ι] [∀ i, Nonempty (κ i)] {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsRelLowerSet (f i j) P) : IsRelLowerSet (⋂ (i) (j), f i j) P := .iInter fun i ↦ .iInter (hf i) lemma isUpperSet_subtype_iff_isRelUpperSet {s : Set { x // P x }} : IsUpperSet s ↔ IsRelUpperSet (Subtype.val '' s) P := by refine ⟨fun h a x ↦ ?_, fun h a b x y ↦ ?_⟩ · obtain ⟨a, ma, rfl⟩ := x exact ⟨a.2, fun b x y ↦ by simpa [h (show a ≤ ⟨b, y⟩ by exact x) ma]⟩ · have ma : a.1 ∈ Subtype.val '' s := by simp [a.2, y] simpa only [mem_image, SetCoe.ext_iff, exists_eq_right] using (h ma).2 x b.2 lemma isLowerSet_subtype_iff_isRelLowerSet {s : Set { x // P x }} : IsLowerSet s ↔ IsRelLowerSet (Subtype.val '' s) P := by refine ⟨fun h a x ↦ ?_, fun h a b x y ↦ ?_⟩ · obtain ⟨a, ma, rfl⟩ := x exact ⟨a.2, fun b x y ↦ by simpa [h (show ⟨b, y⟩ ≤ a by exact x) ma]⟩ · have ma : a.1 ∈ Subtype.val '' s := by simp [a.2, y] simpa only [mem_image, SetCoe.ext_iff, exists_eq_right] using (h ma).2 x b.2 instance : SetLike (RelUpperSet P) α where coe := RelUpperSet.carrier coe_injective' s t h := by cases s; cases t; congr instance : SetLike (RelLowerSet P) α where coe := RelLowerSet.carrier coe_injective' s t h := by cases s; cases t; congr lemma RelUpperSet.isRelUpperSet (u : RelUpperSet P) : IsRelUpperSet u P := u.isRelUpperSet' lemma RelLowerSet.isRelLowerSet (l : RelLowerSet P) : IsRelLowerSet l P := l.isRelLowerSet' end LE section Preorder variable [Preorder α] {c : α} lemma isRelUpperSet_Icc_le : IsRelUpperSet (Icc a c) (· ≤ c) := fun _ b ↦ by simp_all only [mem_Icc, and_true, true_and] exact fun _ x _ ↦ b.1.trans x lemma isRelLowerSet_Icc_ge : IsRelLowerSet (Icc c a) (c ≤ ·) := fun _ b ↦ by simp_all only [mem_Icc, true_and] exact fun _ x _ ↦ x.trans b.2 end Preorder
Basic.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn, Heather Macbeth -/ import Mathlib.Topology.FiberBundle.Trivialization import Mathlib.Topology.Order.LeftRightNhds /-! # Fiber bundles Mathematically, a (topological) fiber bundle with fiber `F` over a base `B` is a space projecting on `B` for which the fibers are all homeomorphic to `F`, such that the local situation around each point is a direct product. In our formalism, a fiber bundle is by definition the type `Bundle.TotalSpace F E` where `E : B → Type*` is a function associating to `x : B` the fiber over `x`. This type `Bundle.TotalSpace F E` is a type of pairs `⟨proj : B, snd : E proj⟩`. To have a fiber bundle structure on `Bundle.TotalSpace F E`, one should additionally have the following data: * `F` should be a topological space; * There should be a topology on `Bundle.TotalSpace F E`, for which the projection to `B` is a fiber bundle with fiber `F` (in particular, each fiber `E x` is homeomorphic to `F`); * For each `x`, the fiber `E x` should be a topological space, and the injection from `E x` to `Bundle.TotalSpace F E` should be an embedding; * There should be a distinguished set of bundle trivializations, the "trivialization atlas" * There should be a choice of bundle trivialization at each point, which belongs to this atlas. If all these conditions are satisfied, we register the typeclass `FiberBundle F E`. It is in general nontrivial to construct a fiber bundle. A way is to start from the knowledge of how changes of local trivializations act on the fiber. From this, one can construct the total space of the bundle and its topology by a suitable gluing construction. The main content of this file is an implementation of this construction: starting from an object of type `FiberBundleCore` registering the trivialization changes, one gets the corresponding fiber bundle and projection. Similarly we implement the object `FiberPrebundle` which allows to define a topological fiber bundle from trivializations given as partial equivalences with minimum additional properties. ## Main definitions ### Basic definitions * `FiberBundle F E` : Structure saying that `E : B → Type*` is a fiber bundle with fiber `F`. ### Construction of a bundle from trivializations * `Bundle.TotalSpace F E` is the type of pairs `(proj : B, snd : E proj)`. We can use the extra argument `F` to construct topology on the total space. * `FiberBundleCore ι B F` : structure registering how changes of coordinates act on the fiber `F` above open subsets of `B`, where local trivializations are indexed by `ι`. Let `Z : FiberBundleCore ι B F`. Then we define * `Z.Fiber x` : the fiber above `x`, homeomorphic to `F` (and defeq to `F` as a type). * `Z.TotalSpace` : the total space of `Z`, defined as `Bundle.TotalSpace F Z.Fiber` with a custom topology. * `Z.proj` : projection from `Z.TotalSpace` to `B`. It is continuous. * `Z.localTriv i` : for `i : ι`, bundle trivialization above the set `Z.baseSet i`, which is an open set in `B`. * `FiberPrebundle F E` : structure registering a cover of prebundle trivializations and requiring that the relative transition maps are partial homeomorphisms. * `FiberPrebundle.totalSpaceTopology a` : natural topology of the total space, making the prebundle into a bundle. ## Implementation notes ### Data vs mixins For both fiber and vector bundles, one faces a choice: should the definition state the *existence* of local trivializations (a propositional typeclass), or specify a fixed atlas of trivializations (a typeclass containing data)? In their initial mathlib implementations, both fiber and vector bundles were defined propositionally. For vector bundles, this turns out to be mathematically wrong: in infinite dimension, the transition function between two trivializations is not automatically continuous as a map from the base `B` to the endomorphisms `F →L[R] F` of the fiber (considered with the operator-norm topology), and so the definition needs to be modified by restricting consideration to a family of trivializations (constituting the data) which are all mutually-compatible in this sense. The PRs https://github.com/leanprover-community/mathlib4/pull/13052 and https://github.com/leanprover-community/mathlib4/pull/13175 implemented this change. There is still the choice about whether to hold this data at the level of fiber bundles or of vector bundles. As of PR https://github.com/leanprover-community/mathlib4/pull/17505, the data is all held in `FiberBundle`, with `VectorBundle` a (propositional) mixin stating fiberwise-linearity. This allows bundles to carry instances of typeclasses in which the scalar field, `R`, does not appear as a parameter. Notably, we would like a vector bundle over `R` with fiber `F` over base `B` to be a `ChartedSpace (B × F)`, with the trivializations providing the charts. This would be a dangerous instance for typeclass inference, because `R` does not appear as a parameter in `ChartedSpace (B × F)`. But if the data of the trivializations is held in `FiberBundle`, then a fiber bundle with fiber `F` over base `B` can be a `ChartedSpace (B × F)`, and this is safe for typeclass inference. We expect that this choice of definition will also streamline constructions of fiber bundles with similar underlying structure (e.g., the same bundle being both a real and complex vector bundle). ### Core construction A fiber bundle with fiber `F` over a base `B` is a family of spaces isomorphic to `F`, indexed by `B`, which is locally trivial in the following sense: there is a covering of `B` by open sets such that, on each such open set `s`, the bundle is isomorphic to `s × F`. To construct a fiber bundle formally, the main data is what happens when one changes trivializations from `s × F` to `s' × F` on `s ∩ s'`: one should get a family of homeomorphisms of `F`, depending continuously on the base point, satisfying basic compatibility conditions (cocycle property). Useful classes of bundles can then be specified by requiring that these homeomorphisms of `F` belong to some subgroup, preserving some structure (the "structure group of the bundle"): then these structures are inherited by the fibers of the bundle. Given such trivialization change data (encoded below in a structure called `FiberBundleCore`), one can construct the fiber bundle. The intrinsic canonical mathematical construction is the following. The fiber above `x` is the disjoint union of `F` over all trivializations, modulo the gluing identifications: one gets a fiber which is isomorphic to `F`, but non-canonically (each choice of one of the trivializations around `x` gives such an isomorphism). Given a trivialization over a set `s`, one gets an isomorphism between `s × F` and `proj^{-1} s`, by using the identification corresponding to this trivialization. One chooses the topology on the bundle that makes all of these into homeomorphisms. For the practical implementation, it turns out to be more convenient to avoid completely the gluing and quotienting construction above, and to declare above each `x` that the fiber is `F`, but thinking that it corresponds to the `F` coming from the choice of one trivialization around `x`. This has several practical advantages: * without any work, one gets a topological space structure on the fiber. And if `F` has more structure it is inherited for free by the fiber. * In the case of the tangent bundle of manifolds, this implies that on vector spaces the derivative (from `F` to `F`) and the manifold derivative (from `TangentSpace I x` to `TangentSpace I' (f x)`) are equal. A drawback is that some silly constructions will typecheck: in the case of the tangent bundle, one can add two vectors in different tangent spaces (as they both are elements of `F` from the point of view of Lean). To solve this, one could mark the tangent space as irreducible, but then one would lose the identification of the tangent space to `F` with `F`. There is however a big advantage of this situation: even if Lean can not check that two basepoints are defeq, it will accept the fact that the tangent spaces are the same. For instance, if two maps `f` and `g` are locally inverse to each other, one can express that the composition of their derivatives is the identity of `TangentSpace I x`. One could fear issues as this composition goes from `TangentSpace I x` to `TangentSpace I (g (f x))` (which should be the same, but should not be obvious to Lean as it does not know that `g (f x) = x`). As these types are the same to Lean (equal to `F`), there are in fact no dependent type difficulties here! For this construction of a fiber bundle from a `FiberBundleCore`, we should thus choose for each `x` one specific trivialization around it. We include this choice in the definition of the `FiberBundleCore`, as it makes some constructions more functorial and it is a nice way to say that the trivializations cover the whole space `B`. With this definition, the type of the fiber bundle space constructed from the core data is `Bundle.TotalSpace F (fun b : B ↦ F)`, but the topology is not the product one, in general. We also take the indexing type (indexing all the trivializations) as a parameter to the fiber bundle core: it could always be taken as a subtype of all the maps from open subsets of `B` to continuous maps of `F`, but in practice it will sometimes be something else. For instance, on a manifold, one will use the set of charts as a good parameterization for the trivializations of the tangent bundle. Or for the pullback of a `FiberBundleCore`, the indexing type will be the same as for the initial bundle. ## Tags Fiber bundle, topological bundle, structure group -/ variable {ι B F X : Type*} [TopologicalSpace X] open TopologicalSpace Filter Set Bundle Topology /-! ### General definition of fiber bundles -/ section FiberBundle variable (F) variable [TopologicalSpace B] [TopologicalSpace F] (E : B → Type*) [TopologicalSpace (TotalSpace F E)] [∀ b, TopologicalSpace (E b)] /-- A (topological) fiber bundle with fiber `F` over a base `B` is a space projecting on `B` for which the fibers are all homeomorphic to `F`, such that the local situation around each point is a direct product. -/ class FiberBundle where totalSpaceMk_isInducing' : ∀ b : B, IsInducing (@TotalSpace.mk B F E b) trivializationAtlas' : Set (Trivialization F (π F E)) trivializationAt' : B → Trivialization F (π F E) mem_baseSet_trivializationAt' : ∀ b : B, b ∈ (trivializationAt' b).baseSet trivialization_mem_atlas' : ∀ b : B, trivializationAt' b ∈ trivializationAtlas' namespace FiberBundle variable [FiberBundle F E] (b : B) theorem totalSpaceMk_isInducing : IsInducing (@TotalSpace.mk B F E b) := totalSpaceMk_isInducing' b /-- Atlas of a fiber bundle. -/ abbrev trivializationAtlas : Set (Trivialization F (π F E)) := trivializationAtlas' /-- Trivialization of a fiber bundle at a point. -/ abbrev trivializationAt : Trivialization F (π F E) := trivializationAt' b theorem mem_baseSet_trivializationAt : b ∈ (trivializationAt F E b).baseSet := mem_baseSet_trivializationAt' b theorem trivialization_mem_atlas : trivializationAt F E b ∈ trivializationAtlas F E := trivialization_mem_atlas' b end FiberBundle export FiberBundle (totalSpaceMk_isInducing trivializationAtlas trivializationAt mem_baseSet_trivializationAt trivialization_mem_atlas) variable {F} variable {E} /-- Given a type `E` equipped with a fiber bundle structure, this is a `Prop` typeclass for trivializations of `E`, expressing that a trivialization is in the designated atlas for the bundle. This is needed because lemmas about the linearity of trivializations or the continuity (as functions to `F →L[R] F`, where `F` is the model fiber) of the transition functions are only expected to hold for trivializations in the designated atlas. -/ @[mk_iff] class MemTrivializationAtlas [FiberBundle F E] (e : Trivialization F (π F E)) : Prop where out : e ∈ trivializationAtlas F E instance [FiberBundle F E] (b : B) : MemTrivializationAtlas (trivializationAt F E b) where out := trivialization_mem_atlas F E b namespace FiberBundle variable (F) variable [FiberBundle F E] theorem map_proj_nhds (x : TotalSpace F E) : map (π F E) (𝓝 x) = 𝓝 x.proj := (trivializationAt F E x.proj).map_proj_nhds <| (trivializationAt F E x.proj).mem_source.2 <| mem_baseSet_trivializationAt F E x.proj variable (E) /-- The projection from a fiber bundle to its base is continuous. -/ @[continuity] theorem continuous_proj : Continuous (π F E) := continuous_iff_continuousAt.2 fun x => (map_proj_nhds F x).le /-- The projection from a fiber bundle to its base is an open map. -/ theorem isOpenMap_proj : IsOpenMap (π F E) := IsOpenMap.of_nhds_le fun x => (map_proj_nhds F x).ge /-- The projection from a fiber bundle with a nonempty fiber to its base is a surjective map. -/ theorem surjective_proj [Nonempty F] : Function.Surjective (π F E) := fun b => let ⟨p, _, hpb⟩ := (trivializationAt F E b).proj_surjOn_baseSet (mem_baseSet_trivializationAt F E b) ⟨p, hpb⟩ /-- The projection from a fiber bundle with a nonempty fiber to its base is a quotient map. -/ theorem isQuotientMap_proj [Nonempty F] : IsQuotientMap (π F E) := (isOpenMap_proj F E).isQuotientMap (continuous_proj F E) (surjective_proj F E) theorem continuous_totalSpaceMk (x : B) : Continuous (@TotalSpace.mk B F E x) := (totalSpaceMk_isInducing F E x).continuous theorem totalSpaceMk_isEmbedding (x : B) : IsEmbedding (@TotalSpace.mk B F E x) := ⟨totalSpaceMk_isInducing F E x, TotalSpace.mk_injective x⟩ theorem totalSpaceMk_isClosedEmbedding [T1Space B] (x : B) : IsClosedEmbedding (@TotalSpace.mk B F E x) := ⟨totalSpaceMk_isEmbedding F E x, by rw [TotalSpace.range_mk] exact isClosed_singleton.preimage <| continuous_proj F E⟩ variable {E F} @[simp, mfld_simps] theorem mem_trivializationAt_proj_source {x : TotalSpace F E} : x ∈ (trivializationAt F E x.proj).source := (Trivialization.mem_source _).mpr <| mem_baseSet_trivializationAt F E x.proj theorem trivializationAt_proj_fst {x : TotalSpace F E} : ((trivializationAt F E x.proj) x).1 = x.proj := Trivialization.coe_fst' _ <| mem_baseSet_trivializationAt F E x.proj variable (F) open Trivialization /-- Characterization of continuous functions (at a point, within a set) into a fiber bundle. -/ theorem continuousWithinAt_totalSpace (f : X → TotalSpace F E) {s : Set X} {x₀ : X} : ContinuousWithinAt f s x₀ ↔ ContinuousWithinAt (fun x => (f x).proj) s x₀ ∧ ContinuousWithinAt (fun x => ((trivializationAt F E (f x₀).proj) (f x)).2) s x₀ := (trivializationAt F E (f x₀).proj).tendsto_nhds_iff mem_trivializationAt_proj_source /-- Characterization of continuous functions (at a point) into a fiber bundle. -/ theorem continuousAt_totalSpace (f : X → TotalSpace F E) {x₀ : X} : ContinuousAt f x₀ ↔ ContinuousAt (fun x => (f x).proj) x₀ ∧ ContinuousAt (fun x => ((trivializationAt F E (f x₀).proj) (f x)).2) x₀ := (trivializationAt F E (f x₀).proj).tendsto_nhds_iff mem_trivializationAt_proj_source end FiberBundle variable (F) variable (E) /-- If `E` is a fiber bundle over a conditionally complete linear order, then it is trivial over any closed interval. -/ theorem FiberBundle.exists_trivialization_Icc_subset [ConditionallyCompleteLinearOrder B] [OrderTopology B] [FiberBundle F E] (a b : B) : ∃ e : Trivialization F (π F E), Icc a b ⊆ e.baseSet := by obtain ⟨ea, hea⟩ : ∃ ea : Trivialization F (π F E), a ∈ ea.baseSet := ⟨trivializationAt F E a, mem_baseSet_trivializationAt F E a⟩ -- If `a < b`, then `[a, b] = ∅`, and the statement is trivial rcases lt_or_ge b a with _ | hab · exact ⟨ea, by simp [*]⟩ /- Let `s` be the set of points `x ∈ [a, b]` such that `E` is trivializable over `[a, x]`. We need to show that `b ∈ s`. Let `c = Sup s`. We will show that `c ∈ s` and `c = b`. -/ set s : Set B := { x ∈ Icc a b | ∃ e : Trivialization F (π F E), Icc a x ⊆ e.baseSet } have ha : a ∈ s := ⟨left_mem_Icc.2 hab, ea, by simp [hea]⟩ have sne : s.Nonempty := ⟨a, ha⟩ have hsb : b ∈ upperBounds s := fun x hx => hx.1.2 have sbd : BddAbove s := ⟨b, hsb⟩ set c := sSup s have hsc : IsLUB s c := isLUB_csSup sne sbd have hc : c ∈ Icc a b := ⟨hsc.1 ha, hsc.2 hsb⟩ obtain ⟨-, ec : Trivialization F (π F E), hec : Icc a c ⊆ ec.baseSet⟩ : c ∈ s := by rcases hc.1.eq_or_lt with heq | hlt · rwa [← heq] refine ⟨hc, ?_⟩ /- In order to show that `c ∈ s`, consider a trivialization `ec` of `proj` over a neighborhood of `c`. Its base set includes `(c', c]` for some `c' ∈ [a, c)`. -/ obtain ⟨ec, hc⟩ : ∃ ec : Trivialization F (π F E), c ∈ ec.baseSet := ⟨trivializationAt F E c, mem_baseSet_trivializationAt F E c⟩ obtain ⟨c', hc', hc'e⟩ : ∃ c' ∈ Ico a c, Ioc c' c ⊆ ec.baseSet := (mem_nhdsLE_iff_exists_mem_Ico_Ioc_subset hlt).1 (mem_nhdsWithin_of_mem_nhds <| IsOpen.mem_nhds ec.open_baseSet hc) /- Since `c' < c = Sup s`, there exists `d ∈ s ∩ (c', c]`. Let `ead` be a trivialization of `proj` over `[a, d]`. Then we can glue `ead` and `ec` into a trivialization over `[a, c]`. -/ obtain ⟨d, ⟨hdab, ead, had⟩, hd⟩ : ∃ d ∈ s, d ∈ Ioc c' c := hsc.exists_between hc'.2 refine ⟨ead.piecewiseLe ec d (had ⟨hdab.1, le_rfl⟩) (hc'e hd), subset_ite.2 ?_⟩ exact ⟨fun x hx => had ⟨hx.1.1, hx.2⟩, fun x hx => hc'e ⟨hd.1.trans (not_le.1 hx.2), hx.1.2⟩⟩ /- So, `c ∈ s`. Let `ec` be a trivialization of `proj` over `[a, c]`. If `c = b`, then we are done. Otherwise we show that `proj` can be trivialized over a larger interval `[a, d]`, `d ∈ (c, b]`, hence `c` is not an upper bound of `s`. -/ rcases hc.2.eq_or_lt with heq | hlt · exact ⟨ec, heq ▸ hec⟩ rsuffices ⟨d, hdcb, hd⟩ : ∃ d ∈ Ioc c b, ∃ e : Trivialization F (π F E), Icc a d ⊆ e.baseSet · exact ((hsc.1 ⟨⟨hc.1.trans hdcb.1.le, hdcb.2⟩, hd⟩).not_gt hdcb.1).elim /- Since the base set of `ec` is open, it includes `[c, d)` (hence, `[a, d)`) for some `d ∈ (c, b]`. -/ obtain ⟨d, hdcb, hd⟩ : ∃ d ∈ Ioc c b, Ico c d ⊆ ec.baseSet := (mem_nhdsGE_iff_exists_mem_Ioc_Ico_subset hlt).1 (mem_nhdsWithin_of_mem_nhds <| IsOpen.mem_nhds ec.open_baseSet (hec ⟨hc.1, le_rfl⟩)) have had : Ico a d ⊆ ec.baseSet := Ico_subset_Icc_union_Ico.trans (union_subset hec hd) by_cases he : Disjoint (Iio d) (Ioi c) · /- If `(c, d) = ∅`, then let `ed` be a trivialization of `proj` over a neighborhood of `d`. Then the disjoint union of `ec` restricted to `(-∞, d)` and `ed` restricted to `(c, ∞)` is a trivialization over `[a, d]`. -/ obtain ⟨ed, hed⟩ : ∃ ed : Trivialization F (π F E), d ∈ ed.baseSet := ⟨trivializationAt F E d, mem_baseSet_trivializationAt F E d⟩ refine ⟨d, hdcb, (ec.restrOpen (Iio d) isOpen_Iio).disjointUnion (ed.restrOpen (Ioi c) isOpen_Ioi) (he.mono inter_subset_right inter_subset_right), fun x hx => ?_⟩ rcases hx.2.eq_or_lt with (rfl | hxd) exacts [Or.inr ⟨hed, hdcb.1⟩, Or.inl ⟨had ⟨hx.1, hxd⟩, hxd⟩] · /- If `(c, d)` is nonempty, then take `d' ∈ (c, d)`. Since the base set of `ec` includes `[a, d)`, it includes `[a, d'] ⊆ [a, d)` as well. -/ rw [disjoint_left] at he push_neg at he rcases he with ⟨d', hdd' : d' < d, hd'c⟩ exact ⟨d', ⟨hd'c, hdd'.le.trans hdcb.2⟩, ec, (Icc_subset_Ico_right hdd').trans had⟩ end FiberBundle /-! ### Core construction for constructing fiber bundles -/ /-- Core data defining a locally trivial bundle with fiber `F` over a topological space `B`. Note that "bundle" is used in its mathematical sense. This is the (computer science) bundled version, i.e., all the relevant data is contained in the following structure. A family of local trivializations is indexed by a type `ι`, on open subsets `baseSet i` for each `i : ι`. Trivialization changes from `i` to `j` are given by continuous maps `coordChange i j` from `baseSet i ∩ baseSet j` to the set of homeomorphisms of `F`, but we express them as maps `B → F → F` and require continuity on `(baseSet i ∩ baseSet j) × F` to avoid the topology on the space of continuous maps on `F`. -/ structure FiberBundleCore (ι : Type*) (B : Type*) [TopologicalSpace B] (F : Type*) [TopologicalSpace F] where baseSet : ι → Set B isOpen_baseSet : ∀ i, IsOpen (baseSet i) indexAt : B → ι mem_baseSet_at : ∀ x, x ∈ baseSet (indexAt x) coordChange : ι → ι → B → F → F coordChange_self : ∀ i, ∀ x ∈ baseSet i, ∀ v, coordChange i i x v = v continuousOn_coordChange : ∀ i j, ContinuousOn (fun p : B × F => coordChange i j p.1 p.2) ((baseSet i ∩ baseSet j) ×ˢ univ) coordChange_comp : ∀ i j k, ∀ x ∈ baseSet i ∩ baseSet j ∩ baseSet k, ∀ v, (coordChange j k x) (coordChange i j x v) = coordChange i k x v namespace FiberBundleCore variable [TopologicalSpace B] [TopologicalSpace F] (Z : FiberBundleCore ι B F) /-- The index set of a fiber bundle core, as a convenience function for dot notation -/ @[nolint unusedArguments] def Index (_Z : FiberBundleCore ι B F) := ι /-- The base space of a fiber bundle core, as a convenience function for dot notation -/ @[nolint unusedArguments, reducible] def Base (_Z : FiberBundleCore ι B F) := B /-- The fiber of a fiber bundle core, as a convenience function for dot notation and typeclass inference -/ @[nolint unusedArguments] def Fiber (_ : FiberBundleCore ι B F) (_x : B) := F instance topologicalSpaceFiber (x : B) : TopologicalSpace (Z.Fiber x) := ‹_› /-- The total space of the fiber bundle, as a convenience function for dot notation. It is by definition equal to `Bundle.TotalSpace F Z.Fiber`. -/ abbrev TotalSpace := Bundle.TotalSpace F Z.Fiber /-- The projection from the total space of a fiber bundle core, on its base. -/ @[reducible, simp, mfld_simps] def proj : Z.TotalSpace → B := Bundle.TotalSpace.proj /-- Local homeomorphism version of the trivialization change. -/ def trivChange (i j : ι) : PartialHomeomorph (B × F) (B × F) where source := (Z.baseSet i ∩ Z.baseSet j) ×ˢ univ target := (Z.baseSet i ∩ Z.baseSet j) ×ˢ univ toFun p := ⟨p.1, Z.coordChange i j p.1 p.2⟩ invFun p := ⟨p.1, Z.coordChange j i p.1 p.2⟩ map_source' p hp := by simpa using hp map_target' p hp := by simpa using hp left_inv' := by rintro ⟨x, v⟩ hx simp only [prodMk_mem_set_prod_eq, mem_inter_iff, and_true, mem_univ] at hx dsimp only rw [coordChange_comp, Z.coordChange_self] exacts [hx.1, ⟨⟨hx.1, hx.2⟩, hx.1⟩] right_inv' := by rintro ⟨x, v⟩ hx simp only [prodMk_mem_set_prod_eq, mem_inter_iff, and_true, mem_univ] at hx dsimp only rw [Z.coordChange_comp, Z.coordChange_self] · exact hx.2 · simp [hx] open_source := ((Z.isOpen_baseSet i).inter (Z.isOpen_baseSet j)).prod isOpen_univ open_target := ((Z.isOpen_baseSet i).inter (Z.isOpen_baseSet j)).prod isOpen_univ continuousOn_toFun := continuous_fst.continuousOn.prodMk (Z.continuousOn_coordChange i j) continuousOn_invFun := by simpa [inter_comm] using continuous_fst.continuousOn.prodMk (Z.continuousOn_coordChange j i) @[simp, mfld_simps] theorem mem_trivChange_source (i j : ι) (p : B × F) : p ∈ (Z.trivChange i j).source ↔ p.1 ∈ Z.baseSet i ∩ Z.baseSet j := by rw [trivChange, mem_prod] simp /-- Associate to a trivialization index `i : ι` the corresponding trivialization, i.e., a bijection between `proj ⁻¹ (baseSet i)` and `baseSet i × F`. As the fiber above `x` is `F` but read in the chart with index `index_at x`, the trivialization in the fiber above x is by definition the coordinate change from i to `index_at x`, so it depends on `x`. The local trivialization will ultimately be a partial homeomorphism. For now, we only introduce the partial equivalence version, denoted with a prime. In further developments, avoid this auxiliary version, and use `Z.local_triv` instead. -/ def localTrivAsPartialEquiv (i : ι) : PartialEquiv Z.TotalSpace (B × F) where source := Z.proj ⁻¹' Z.baseSet i target := Z.baseSet i ×ˢ univ invFun p := ⟨p.1, Z.coordChange i (Z.indexAt p.1) p.1 p.2⟩ toFun p := ⟨p.1, Z.coordChange (Z.indexAt p.1) i p.1 p.2⟩ map_source' p hp := by simpa only [Set.mem_preimage, and_true, Set.mem_univ, Set.prodMk_mem_set_prod_eq] using hp map_target' p hp := by simpa only [Set.mem_preimage, and_true, Set.mem_univ, Set.mem_prod] using hp left_inv' := by rintro ⟨x, v⟩ hx replace hx : x ∈ Z.baseSet i := hx dsimp only rw [Z.coordChange_comp, Z.coordChange_self] <;> apply_rules [mem_baseSet_at, mem_inter] right_inv' := by rintro ⟨x, v⟩ hx simp only [prodMk_mem_set_prod_eq, and_true, mem_univ] at hx dsimp only rw [Z.coordChange_comp, Z.coordChange_self] exacts [hx, ⟨⟨hx, Z.mem_baseSet_at _⟩, hx⟩] variable (i : ι) theorem mem_localTrivAsPartialEquiv_source (p : Z.TotalSpace) : p ∈ (Z.localTrivAsPartialEquiv i).source ↔ p.1 ∈ Z.baseSet i := Iff.rfl theorem mem_localTrivAsPartialEquiv_target (p : B × F) : p ∈ (Z.localTrivAsPartialEquiv i).target ↔ p.1 ∈ Z.baseSet i := by rw [localTrivAsPartialEquiv, mem_prod] simp only [and_true, mem_univ] theorem localTrivAsPartialEquiv_apply (p : Z.TotalSpace) : (Z.localTrivAsPartialEquiv i) p = ⟨p.1, Z.coordChange (Z.indexAt p.1) i p.1 p.2⟩ := rfl /-- The composition of two local trivializations is the trivialization change Z.triv_change i j. -/ theorem localTrivAsPartialEquiv_trans (i j : ι) : (Z.localTrivAsPartialEquiv i).symm.trans (Z.localTrivAsPartialEquiv j) ≈ (Z.trivChange i j).toPartialEquiv := by constructor · ext x simp only [mem_localTrivAsPartialEquiv_target, mfld_simps] rfl · rintro ⟨x, v⟩ hx simp only [trivChange, localTrivAsPartialEquiv, PartialEquiv.symm, Prod.mk_inj, prodMk_mem_set_prod_eq, PartialEquiv.trans_source, mem_inter_iff, mem_preimage, proj, mem_univ, (· ∘ ·), PartialEquiv.coe_trans] at hx ⊢ simp only [Z.coordChange_comp, hx, mem_inter_iff, and_self_iff, mem_baseSet_at] /-- Topological structure on the total space of a fiber bundle created from core, designed so that all the local trivialization are continuous. -/ instance toTopologicalSpace : TopologicalSpace (Bundle.TotalSpace F Z.Fiber) := TopologicalSpace.generateFrom <| ⋃ (i : ι) (s : Set (B × F)) (_ : IsOpen s), {(Z.localTrivAsPartialEquiv i).source ∩ Z.localTrivAsPartialEquiv i ⁻¹' s} variable (b : B) (a : F) theorem open_source' (i : ι) : IsOpen (Z.localTrivAsPartialEquiv i).source := by apply TopologicalSpace.GenerateOpen.basic simp only [exists_prop, mem_iUnion, mem_singleton_iff] refine ⟨i, Z.baseSet i ×ˢ univ, (Z.isOpen_baseSet i).prod isOpen_univ, ?_⟩ ext p simp only [localTrivAsPartialEquiv_apply, prodMk_mem_set_prod_eq, mem_inter_iff, and_self_iff, mem_localTrivAsPartialEquiv_source, and_true, mem_univ, mem_preimage] /-- Extended version of the local trivialization of a fiber bundle constructed from core, registering additionally in its type that it is a local bundle trivialization. -/ def localTriv (i : ι) : Trivialization F Z.proj where baseSet := Z.baseSet i open_baseSet := Z.isOpen_baseSet i source_eq := rfl target_eq := rfl proj_toFun p _ := by simp only [mfld_simps] rfl open_source := Z.open_source' i open_target := (Z.isOpen_baseSet i).prod isOpen_univ continuousOn_toFun := by rw [continuousOn_open_iff (Z.open_source' i)] intro s s_open apply TopologicalSpace.GenerateOpen.basic simp only [exists_prop, mem_iUnion, mem_singleton_iff] exact ⟨i, s, s_open, rfl⟩ continuousOn_invFun := by refine continuousOn_isOpen_of_generateFrom fun t ht ↦ ?_ simp only [exists_prop, mem_iUnion, mem_singleton_iff] at ht obtain ⟨j, s, s_open, ts⟩ : ∃ j s, IsOpen s ∧ t = (localTrivAsPartialEquiv Z j).source ∩ localTrivAsPartialEquiv Z j ⁻¹' s := ht rw [ts] simp only [preimage_inter] let e := Z.localTrivAsPartialEquiv i let e' := Z.localTrivAsPartialEquiv j let f := e.symm.trans e' have : IsOpen (f.source ∩ f ⁻¹' s) := by rw [PartialEquiv.EqOnSource.source_inter_preimage_eq (Z.localTrivAsPartialEquiv_trans i j)] exact (continuousOn_open_iff (Z.trivChange i j).open_source).1 (Z.trivChange i j).continuousOn _ s_open convert this using 1 dsimp [f, PartialEquiv.trans_source] rw [← preimage_comp, inter_assoc] toPartialEquiv := Z.localTrivAsPartialEquiv i /-- Preferred local trivialization of a fiber bundle constructed from core, at a given point, as a bundle trivialization -/ def localTrivAt (b : B) : Trivialization F (π F Z.Fiber) := Z.localTriv (Z.indexAt b) @[simp, mfld_simps] theorem localTrivAt_def (b : B) : Z.localTriv (Z.indexAt b) = Z.localTrivAt b := rfl theorem localTrivAt_snd (b : B) (p) : (Z.localTrivAt b p).2 = Z.coordChange (Z.indexAt p.1) (Z.indexAt b) p.1 p.2 := rfl /-- If an element of `F` is invariant under all coordinate changes, then one can define a corresponding section of the fiber bundle, which is continuous. This applies in particular to the zero section of a vector bundle. Another example (not yet defined) would be the identity section of the endomorphism bundle of a vector bundle. -/ theorem continuous_const_section (v : F) (h : ∀ i j, ∀ x ∈ Z.baseSet i ∩ Z.baseSet j, Z.coordChange i j x v = v) : Continuous (show B → Z.TotalSpace from fun x => ⟨x, v⟩) := by refine continuous_iff_continuousAt.2 fun x => ?_ have A : Z.baseSet (Z.indexAt x) ∈ 𝓝 x := IsOpen.mem_nhds (Z.isOpen_baseSet (Z.indexAt x)) (Z.mem_baseSet_at x) refine ((Z.localTrivAt x).toPartialHomeomorph.continuousAt_iff_continuousAt_comp_left ?_).2 ?_ · exact A · apply continuousAt_id.prodMk simp only [mfld_simps] have : ContinuousOn (fun _ : B => v) (Z.baseSet (Z.indexAt x)) := continuousOn_const refine (this.congr fun y hy ↦ ?_).continuousAt A exact h _ _ _ ⟨mem_baseSet_at _ _, hy⟩ @[simp, mfld_simps] theorem localTrivAsPartialEquiv_coe : ⇑(Z.localTrivAsPartialEquiv i) = Z.localTriv i := rfl @[simp, mfld_simps] theorem localTrivAsPartialEquiv_source : (Z.localTrivAsPartialEquiv i).source = (Z.localTriv i).source := rfl @[simp, mfld_simps] theorem localTrivAsPartialEquiv_target : (Z.localTrivAsPartialEquiv i).target = (Z.localTriv i).target := rfl @[simp, mfld_simps] theorem localTrivAsPartialEquiv_symm : (Z.localTrivAsPartialEquiv i).symm = (Z.localTriv i).toPartialEquiv.symm := rfl @[simp, mfld_simps] theorem baseSet_at : Z.baseSet i = (Z.localTriv i).baseSet := rfl @[simp, mfld_simps] theorem localTriv_apply (p : Z.TotalSpace) : (Z.localTriv i) p = ⟨p.1, Z.coordChange (Z.indexAt p.1) i p.1 p.2⟩ := rfl @[simp, mfld_simps] theorem localTrivAt_apply (p : Z.TotalSpace) : (Z.localTrivAt p.1) p = ⟨p.1, p.2⟩ := by rw [localTrivAt, localTriv_apply, coordChange_self] exact Z.mem_baseSet_at p.1 @[simp, mfld_simps] theorem localTrivAt_apply_mk (b : B) (a : F) : (Z.localTrivAt b) ⟨b, a⟩ = ⟨b, a⟩ := Z.localTrivAt_apply _ @[simp, mfld_simps] theorem mem_localTriv_source (p : Z.TotalSpace) : p ∈ (Z.localTriv i).source ↔ p.1 ∈ (Z.localTriv i).baseSet := Iff.rfl @[simp, mfld_simps] theorem mem_localTrivAt_source (p : Z.TotalSpace) (b : B) : p ∈ (Z.localTrivAt b).source ↔ p.1 ∈ (Z.localTrivAt b).baseSet := Iff.rfl @[simp, mfld_simps] theorem mem_localTriv_target (p : B × F) : p ∈ (Z.localTriv i).target ↔ p.1 ∈ (Z.localTriv i).baseSet := Trivialization.mem_target _ @[simp, mfld_simps] theorem mem_localTrivAt_target (p : B × F) (b : B) : p ∈ (Z.localTrivAt b).target ↔ p.1 ∈ (Z.localTrivAt b).baseSet := Trivialization.mem_target _ @[simp, mfld_simps] theorem localTriv_symm_apply (p : B × F) : (Z.localTriv i).toPartialHomeomorph.symm p = ⟨p.1, Z.coordChange i (Z.indexAt p.1) p.1 p.2⟩ := rfl @[simp, mfld_simps] theorem mem_localTrivAt_baseSet (b : B) : b ∈ (Z.localTrivAt b).baseSet := by rw [localTrivAt, ← baseSet_at] exact Z.mem_baseSet_at b theorem mk_mem_localTrivAt_source : (⟨b, a⟩ : Z.TotalSpace) ∈ (Z.localTrivAt b).source := by simp only [mfld_simps] /-- A fiber bundle constructed from core is indeed a fiber bundle. -/ instance fiberBundle : FiberBundle F Z.Fiber where totalSpaceMk_isInducing' b := isInducing_iff_nhds.2 fun x ↦ by rw [(Z.localTrivAt b).nhds_eq_comap_inf_principal (mk_mem_localTrivAt_source _ _ _), comap_inf, comap_principal, comap_comap] simp only [Function.comp_def, localTrivAt_apply_mk, Trivialization.coe_coe, ← (isEmbedding_prodMkRight b).nhds_eq_comap] convert_to 𝓝 x = 𝓝 x ⊓ 𝓟 univ · congr exact eq_univ_of_forall (mk_mem_localTrivAt_source Z _) · rw [principal_univ, inf_top_eq] trivializationAtlas' := Set.range Z.localTriv trivializationAt' := Z.localTrivAt mem_baseSet_trivializationAt' := Z.mem_baseSet_at trivialization_mem_atlas' b := ⟨Z.indexAt b, rfl⟩ /-- The inclusion of a fiber into the total space is a continuous map. -/ @[continuity] theorem continuous_totalSpaceMk (b : B) : Continuous (TotalSpace.mk b : Z.Fiber b → Bundle.TotalSpace F Z.Fiber) := FiberBundle.continuous_totalSpaceMk F Z.Fiber b /-- The projection on the base of a fiber bundle created from core is continuous -/ nonrec theorem continuous_proj : Continuous Z.proj := FiberBundle.continuous_proj F Z.Fiber /-- The projection on the base of a fiber bundle created from core is an open map -/ nonrec theorem isOpenMap_proj : IsOpenMap Z.proj := FiberBundle.isOpenMap_proj F Z.Fiber end FiberBundleCore /-! ### Prebundle construction for constructing fiber bundles -/ variable (F) variable (E : B → Type*) [TopologicalSpace B] [TopologicalSpace F] [∀ x, TopologicalSpace (E x)] /-- This structure permits to define a fiber bundle when trivializations are given as local equivalences but there is not yet a topology on the total space. The total space is hence given a topology in such a way that there is a fiber bundle structure for which the partial equivalences are also partial homeomorphisms and hence local trivializations. -/ structure FiberPrebundle where pretrivializationAtlas : Set (Pretrivialization F (π F E)) pretrivializationAt : B → Pretrivialization F (π F E) mem_base_pretrivializationAt : ∀ x : B, x ∈ (pretrivializationAt x).baseSet pretrivialization_mem_atlas : ∀ x : B, pretrivializationAt x ∈ pretrivializationAtlas continuous_trivChange : ∀ e, e ∈ pretrivializationAtlas → ∀ e', e' ∈ pretrivializationAtlas → ContinuousOn (e ∘ e'.toPartialEquiv.symm) (e'.target ∩ e'.toPartialEquiv.symm ⁻¹' e.source) totalSpaceMk_isInducing : ∀ b : B, IsInducing (pretrivializationAt b ∘ TotalSpace.mk b) namespace FiberPrebundle variable {F E} variable (a : FiberPrebundle F E) {e : Pretrivialization F (π F E)} /-- Topology on the total space that will make the prebundle into a bundle. -/ def totalSpaceTopology (a : FiberPrebundle F E) : TopologicalSpace (TotalSpace F E) := ⨆ (e : Pretrivialization F (π F E)) (_ : e ∈ a.pretrivializationAtlas), coinduced e.setSymm instTopologicalSpaceSubtype theorem continuous_symm_of_mem_pretrivializationAtlas (he : e ∈ a.pretrivializationAtlas) : @ContinuousOn _ _ _ a.totalSpaceTopology e.toPartialEquiv.symm e.target := by refine fun z H U h => preimage_nhdsWithin_coinduced' H (le_def.1 (nhds_mono ?_) U h) exact le_iSup₂ (α := TopologicalSpace (TotalSpace F E)) e he theorem isOpen_source (e : Pretrivialization F (π F E)) : IsOpen[a.totalSpaceTopology] e.source := by refine isOpen_iSup_iff.mpr fun e' => isOpen_iSup_iff.mpr fun _ => ?_ refine isOpen_coinduced.mpr (isOpen_induced_iff.mpr ⟨e.target, e.open_target, ?_⟩) ext ⟨x, hx⟩ simp only [mem_preimage, Pretrivialization.setSymm, restrict, e.mem_target, e.mem_source, e'.proj_symm_apply hx] theorem isOpen_target_of_mem_pretrivializationAtlas_inter (e e' : Pretrivialization F (π F E)) (he' : e' ∈ a.pretrivializationAtlas) : IsOpen (e'.toPartialEquiv.target ∩ e'.toPartialEquiv.symm ⁻¹' e.source) := by letI := a.totalSpaceTopology obtain ⟨u, hu1, hu2⟩ := continuousOn_iff'.mp (a.continuous_symm_of_mem_pretrivializationAtlas he') e.source (a.isOpen_source e) rw [inter_comm, hu2] exact hu1.inter e'.open_target /-- Promotion from a `Pretrivialization` to a `Trivialization`. -/ def trivializationOfMemPretrivializationAtlas (he : e ∈ a.pretrivializationAtlas) : @Trivialization B F _ _ _ a.totalSpaceTopology (π F E) := let _ := a.totalSpaceTopology { e with open_source := a.isOpen_source e, continuousOn_toFun := by refine continuousOn_iff'.mpr fun s hs => ⟨e ⁻¹' s ∩ e.source, isOpen_iSup_iff.mpr fun e' => ?_, by rw [inter_assoc, inter_self]; rfl⟩ refine isOpen_iSup_iff.mpr fun he' => ?_ rw [isOpen_coinduced, isOpen_induced_iff] obtain ⟨u, hu1, hu2⟩ := continuousOn_iff'.mp (a.continuous_trivChange _ he _ he') s hs have hu3 := congr_arg (fun s => (fun x : e'.target => (x : B × F)) ⁻¹' s) hu2 simp only [Subtype.coe_preimage_self, preimage_inter, univ_inter] at hu3 refine ⟨u ∩ e'.toPartialEquiv.target ∩ e'.toPartialEquiv.symm ⁻¹' e.source, ?_, by simp only [preimage_inter, inter_univ, Subtype.coe_preimage_self, hu3.symm]; rfl⟩ rw [inter_assoc] exact hu1.inter (a.isOpen_target_of_mem_pretrivializationAtlas_inter e e' he') continuousOn_invFun := a.continuous_symm_of_mem_pretrivializationAtlas he } theorem mem_pretrivializationAt_source (b : B) (x : E b) : ⟨b, x⟩ ∈ (a.pretrivializationAt b).source := by simp only [(a.pretrivializationAt b).source_eq, mem_preimage] exact a.mem_base_pretrivializationAt b @[simp] theorem totalSpaceMk_preimage_source (b : B) : TotalSpace.mk b ⁻¹' (a.pretrivializationAt b).source = univ := eq_univ_of_forall (a.mem_pretrivializationAt_source b) @[continuity] theorem continuous_totalSpaceMk (b : B) : Continuous[_, a.totalSpaceTopology] (TotalSpace.mk b) := by letI := a.totalSpaceTopology let e := a.trivializationOfMemPretrivializationAtlas (a.pretrivialization_mem_atlas b) rw [e.toPartialHomeomorph.continuous_iff_continuous_comp_left (a.totalSpaceMk_preimage_source b)] exact continuous_iff_le_induced.2 (a.totalSpaceMk_isInducing b).eq_induced.le theorem inducing_totalSpaceMk_of_inducing_comp (b : B) (h : IsInducing (a.pretrivializationAt b ∘ TotalSpace.mk b)) : @IsInducing _ _ _ a.totalSpaceTopology (TotalSpace.mk b) := by letI := a.totalSpaceTopology rw [← restrict_comp_codRestrict (a.mem_pretrivializationAt_source b)] at h apply IsInducing.of_codRestrict (a.mem_pretrivializationAt_source b) refine h.of_comp ?_ (continuousOn_iff_continuous_restrict.mp (a.trivializationOfMemPretrivializationAtlas (a.pretrivialization_mem_atlas b)).continuousOn) exact (a.continuous_totalSpaceMk b).codRestrict (a.mem_pretrivializationAt_source b) /-- Make a `FiberBundle` from a `FiberPrebundle`. Concretely this means that, given a `FiberPrebundle` structure for a sigma-type `E` -- which consists of a number of "pretrivializations" identifying parts of `E` with product spaces `U × F` -- one establishes that for the topology constructed on the sigma-type using `FiberPrebundle.totalSpaceTopology`, these "pretrivializations" are actually "trivializations" (i.e., homeomorphisms with respect to the constructed topology). -/ def toFiberBundle : @FiberBundle B F _ _ E a.totalSpaceTopology _ := let _ := a.totalSpaceTopology { totalSpaceMk_isInducing' := fun b ↦ a.inducing_totalSpaceMk_of_inducing_comp b (a.totalSpaceMk_isInducing b) trivializationAtlas' := { e | ∃ (e₀ : _) (he₀ : e₀ ∈ a.pretrivializationAtlas), e = a.trivializationOfMemPretrivializationAtlas he₀ }, trivializationAt' := fun x ↦ a.trivializationOfMemPretrivializationAtlas (a.pretrivialization_mem_atlas x), mem_baseSet_trivializationAt' := a.mem_base_pretrivializationAt trivialization_mem_atlas' := fun x ↦ ⟨_, a.pretrivialization_mem_atlas x, rfl⟩ } theorem continuous_proj : @Continuous _ _ a.totalSpaceTopology _ (π F E) := by letI := a.totalSpaceTopology letI := a.toFiberBundle exact FiberBundle.continuous_proj F E instance {e₀} (he₀ : e₀ ∈ a.pretrivializationAtlas) : (letI := a.totalSpaceTopology; letI := a.toFiberBundle MemTrivializationAtlas (a.trivializationOfMemPretrivializationAtlas he₀)) := letI := a.totalSpaceTopology; letI := a.toFiberBundle; ⟨e₀, he₀, rfl⟩ /-- For a fiber bundle `E` over `B` constructed using the `FiberPrebundle` mechanism, continuity of a function `TotalSpace F E → X` on an open set `s` can be checked by precomposing at each point with the pretrivialization used for the construction at that point. -/ theorem continuousOn_of_comp_right {X : Type*} [TopologicalSpace X] {f : TotalSpace F E → X} {s : Set B} (hs : IsOpen s) (hf : ∀ b ∈ s, ContinuousOn (f ∘ (a.pretrivializationAt b).toPartialEquiv.symm) ((s ∩ (a.pretrivializationAt b).baseSet) ×ˢ (Set.univ : Set F))) : @ContinuousOn _ _ a.totalSpaceTopology _ f (π F E ⁻¹' s) := by letI := a.totalSpaceTopology intro z hz let e : Trivialization F (π F E) := a.trivializationOfMemPretrivializationAtlas (a.pretrivialization_mem_atlas z.proj) refine (e.continuousAt_of_comp_right ?_ ((hf z.proj hz).continuousAt (IsOpen.mem_nhds ?_ ?_))).continuousWithinAt · exact a.mem_base_pretrivializationAt z.proj · exact (hs.inter (a.pretrivializationAt z.proj).open_baseSet).prod isOpen_univ refine ⟨?_, mem_univ _⟩ rw [e.coe_fst] · exact ⟨hz, a.mem_base_pretrivializationAt z.proj⟩ · rw [e.mem_source] exact a.mem_base_pretrivializationAt z.proj end FiberPrebundle
JacobsonSpace.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Topology.LocalAtTarget import Mathlib.Topology.Separation.Regular import Mathlib.Tactic.StacksAttribute /-! # Jacobson spaces ## Main results - `JacobsonSpace`: The class of jacobson spaces, i.e. spaces such that the set of closed points are dense in every closed subspace. - `jacobsonSpace_iff_locallyClosed`: `X` is a jacobson space iff every locally closed subset contains a closed point of `X`. - `JacobsonSpace.discreteTopology`: If `X` only has finitely many closed points, then the topology on `X` is discrete. ## References - https://stacks.math.columbia.edu/tag/005T -/ open Topology TopologicalSpace variable (X) {Y} [TopologicalSpace X] [TopologicalSpace Y] {f : X → Y} section closedPoints /-- The set of closed points. -/ def closedPoints : Set X := setOf (IsClosed {·}) variable {X} @[simp] lemma mem_closedPoints_iff {x} : x ∈ closedPoints X ↔ IsClosed {x} := Iff.rfl lemma preimage_closedPoints_subset (hf : Function.Injective f) (hf' : Continuous f) : f ⁻¹' closedPoints Y ⊆ closedPoints X := by intros x hx rw [mem_closedPoints_iff] convert continuous_iff_isClosed.mp hf' _ hx rw [← Set.image_singleton, Set.preimage_image_eq _ hf] lemma Topology.IsClosedEmbedding.preimage_closedPoints (hf : IsClosedEmbedding f) : f ⁻¹' closedPoints Y = closedPoints X := by ext x simp [mem_closedPoints_iff, ← Set.image_singleton, hf.isClosed_iff_image_isClosed] lemma closedPoints_eq_univ [T1Space X] : closedPoints X = Set.univ := Set.eq_univ_iff_forall.mpr fun _ ↦ isClosed_singleton end closedPoints /-- The class of jacobson spaces, i.e. spaces such that the set of closed points are dense in every closed subspace. -/ @[mk_iff, stacks 005U] class JacobsonSpace : Prop where closure_inter_closedPoints : ∀ {Z}, IsClosed Z → closure (Z ∩ closedPoints X) = Z export JacobsonSpace (closure_inter_closedPoints) variable {X} lemma closure_closedPoints [JacobsonSpace X] : closure (closedPoints X) = Set.univ := by simpa using closure_inter_closedPoints isClosed_univ lemma jacobsonSpace_iff_locallyClosed : JacobsonSpace X ↔ ∀ Z, Z.Nonempty → IsLocallyClosed Z → (Z ∩ closedPoints X).Nonempty := by rw [jacobsonSpace_iff] constructor · simp_rw [isLocallyClosed_iff_isOpen_coborder, coborder, isOpen_compl_iff, Set.nonempty_iff_ne_empty] intros H Z hZ hZ' e have : Z ⊆ closure Z \ Z := by refine subset_closure.trans ?_ nth_rw 1 [← H isClosed_closure] rw [hZ'.closure_subset_iff, Set.subset_diff, Set.disjoint_iff, Set.inter_assoc, Set.inter_comm _ Z, e] exact ⟨Set.inter_subset_left, Set.inter_subset_right⟩ rw [Set.subset_diff, disjoint_self, Set.bot_eq_empty] at this exact hZ this.2 · intro H Z hZ refine subset_antisymm (hZ.closure_subset_iff.mpr Set.inter_subset_left) ?_ rw [← Set.disjoint_compl_left_iff_subset, Set.disjoint_iff_inter_eq_empty, ← Set.not_nonempty_iff_eq_empty] intro H' have := H _ H' (isClosed_closure.isOpen_compl.isLocallyClosed.inter hZ.isLocallyClosed) rw [Set.nonempty_iff_ne_empty, Set.inter_assoc, ne_eq, ← Set.disjoint_iff_inter_eq_empty, Set.disjoint_compl_left_iff_subset] at this exact this subset_closure lemma nonempty_inter_closedPoints [JacobsonSpace X] {Z : Set X} (hZ : Z.Nonempty) (hZ' : IsLocallyClosed Z) : (Z ∩ closedPoints X).Nonempty := jacobsonSpace_iff_locallyClosed.mp inferInstance Z hZ hZ' lemma isClosed_singleton_of_isLocallyClosed_singleton [JacobsonSpace X] {x : X} (hx : IsLocallyClosed {x}) : IsClosed {x} := by obtain ⟨_, ⟨y, rfl : y = x, rfl⟩, hy'⟩ := nonempty_inter_closedPoints (Set.singleton_nonempty x) hx exact hy' lemma Topology.IsOpenEmbedding.preimage_closedPoints (hf : IsOpenEmbedding f) [JacobsonSpace Y] : f ⁻¹' closedPoints Y = closedPoints X := by apply subset_antisymm (preimage_closedPoints_subset hf.injective hf.continuous) intros x hx apply isClosed_singleton_of_isLocallyClosed_singleton rw [← Set.image_singleton] exact (hx.isLocallyClosed.image hf.isInducing hf.isOpen_range.isLocallyClosed) lemma JacobsonSpace.of_isOpenEmbedding [JacobsonSpace Y] (hf : IsOpenEmbedding f) : JacobsonSpace X := by rw [jacobsonSpace_iff_locallyClosed, ← hf.preimage_closedPoints] intros Z hZ hZ' obtain ⟨_, ⟨x, hx, rfl⟩, hx'⟩ := nonempty_inter_closedPoints (hZ.image f) (hZ'.image hf.isInducing hf.isOpen_range.isLocallyClosed) exact ⟨_, hx, hx'⟩ lemma JacobsonSpace.of_isClosedEmbedding [JacobsonSpace Y] (hf : IsClosedEmbedding f) : JacobsonSpace X := by rw [jacobsonSpace_iff_locallyClosed, ← hf.preimage_closedPoints] intros Z hZ hZ' obtain ⟨_, ⟨x, hx, rfl⟩, hx'⟩ := nonempty_inter_closedPoints (hZ.image f) (hZ'.image hf.isInducing hf.isClosed_range.isLocallyClosed) exact ⟨_, hx, hx'⟩ lemma JacobsonSpace.discreteTopology [JacobsonSpace X] (h : (closedPoints X).Finite) : DiscreteTopology X := by have : closedPoints X = Set.univ := by rw [← Set.univ_subset_iff, ← closure_closedPoints, closure_subset_iff_isClosed, ← (closedPoints X).biUnion_of_singleton] exact h.isClosed_biUnion fun _ ↦ id have inst : Finite X := Set.finite_univ_iff.mp (this ▸ h) rw [← forall_open_iff_discrete] intro s rw [← isClosed_compl_iff, ← sᶜ.biUnion_of_singleton] refine sᶜ.toFinite.isClosed_biUnion fun x _ ↦ ?_ rw [← mem_closedPoints_iff, this] trivial instance (priority := 100) [Finite X] [JacobsonSpace X] : DiscreteTopology X := JacobsonSpace.discreteTopology (Set.toFinite _) instance (priority := 100) [T1Space X] : JacobsonSpace X := ⟨by simp [closedPoints_eq_univ, closure_eq_iff_isClosed]⟩ lemma TopologicalSpace.IsOpenCover.jacobsonSpace_iff {ι : Type*} {U : ι → Opens X} (hU : IsOpenCover U) : JacobsonSpace X ↔ ∀ i, JacobsonSpace (U i) := by refine ⟨fun H i ↦ .of_isOpenEmbedding (U i).2.isOpenEmbedding_subtypeVal, fun H ↦ ?_⟩ rw [jacobsonSpace_iff_locallyClosed] intros Z hZ hZ' rw [← hU.iUnion_inter Z, Set.nonempty_iUnion] at hZ obtain ⟨i, x, hx, hx'⟩ := hZ obtain ⟨y, hy, hy'⟩ := (jacobsonSpace_iff_locallyClosed.mp (H i)) _ ⟨⟨x, hx'⟩, hx⟩ (hZ'.preimage continuous_subtype_val) refine ⟨y, hy, hU.isClosed_iff_coe_preimage.mpr fun j ↦ ?_⟩ by_cases h : (y : X) ∈ U j · convert_to IsClosed {(⟨y, h⟩ : U j)} · ext; simp [← Subtype.coe_inj] apply isClosed_singleton_of_isLocallyClosed_singleton convert (hy'.isLocallyClosed.image IsEmbedding.subtypeVal.isInducing (U i).2.isOpenEmbedding_subtypeVal.isOpen_range.isLocallyClosed).preimage continuous_subtype_val ext simp [← Subtype.coe_inj] · convert isClosed_empty rw [Set.eq_empty_iff_forall_notMem] intro z (hz : z.1 = y.1) exact h (hz ▸ z.2) @[deprecated IsOpenCover.jacobsonSpace_iff (since := "2025-02-10")] lemma jacobsonSpace_iff_of_iSup_eq_top {ι : Type*} {U : ι → Opens X} (hU : iSup U = ⊤) : JacobsonSpace X ↔ ∀ i, JacobsonSpace (U i) := (IsOpenCover.mk hU).jacobsonSpace_iff
Zify.lean
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll, Robert Y. Lewis -/ import Mathlib.Tactic.Zify import Mathlib.Algebra.Ring.Int.Parity import Mathlib.Algebra.Ring.Int.Units set_option linter.unusedVariables false private axiom test_sorry : ∀ {α}, α example (a b c x y z : ℕ) (h : ¬ x*y*z < 0) : c < a + 3*b := by zify guard_target =~ (c : ℤ) < (a : ℤ) + 3 * (b : ℤ) zify at h guard_hyp h :~ ¬(x : ℤ) * (y : ℤ) * (z : ℤ) < (0 : ℤ) exact test_sorry -- TODO: These are verbatim copies of the tests from mathlib3. It would be nice to add more. -- set_option pp.coercions false example (a b c x y z : ℕ) (h : ¬ x*y*z < 0) (h2 : (c : ℤ) < a + 3 * b) : a + 3*b > c := by zify at h ⊢ guard_hyp h :~ ¬↑x * ↑y * ↑z < (0 : ℤ) -- TODO: canonize instances? guard_target =~ ↑c < (↑a : ℤ) + 3 * ↑b exact h2 example (a b : ℕ) (h : (a : ℤ) ≤ b) : a ≤ b := by zify guard_target = (a : ℤ) ≤ b exact h /- example (a b : ℕ) (h : a = b ∧ b < a) : False := by zify at h rcases h with ⟨ha, hb⟩ -- Preorder for `ℤ` is missing exact ne_of_lt hb ha -/ example (a b c : ℕ) (h : a - b < c) (hab : b ≤ a) : True := by zify [hab] at h guard_hyp h : (a : ℤ) - b < c trivial example (a b c : ℕ) (h : a + b ≠ c) : True := by zify at h guard_hyp h : (a + b : ℤ) ≠ c trivial example (a b c : ℕ) (h : a - b ∣ c) (h2 : b ≤ a) : True := by zify [h2] at h guard_hyp h : (a : ℤ) - b ∣ c trivial
Horn.lean
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kim Morrison, Adam Topaz, Joël Riou -/ import Mathlib.AlgebraicTopology.SimplicialSet.StdSimplex import Mathlib.CategoryTheory.Subpresheaf.Equalizer /-! # Horns This file introduce horns `Λ[n, i]`. -/ universe u open CategoryTheory Simplicial Opposite namespace SSet /-- `horn n i` (or `Λ[n, i]`) is the `i`-th horn of the `n`-th standard simplex, where `i : n`. It consists of all `m`-simplices `α` of `Δ[n]` for which the union of `{i}` and the range of `α` is not all of `n` (when viewing `α` as monotone function `m → n`). -/ @[simps -isSimp obj] def horn (n : ℕ) (i : Fin (n + 1)) : (Δ[n] : SSet.{u}).Subcomplex where obj _ := setOf (fun s ↦ Set.range (stdSimplex.asOrderHom s) ∪ {i} ≠ Set.univ) map φ s hs h := hs (by rw [Set.eq_univ_iff_forall] at h ⊢; intro j apply Or.imp _ id (h j) intro hj exact Set.range_comp_subset_range _ _ hj) /-- The `i`-th horn `Λ[n, i]` of the standard `n`-simplex -/ scoped[Simplicial] notation3 "Λ[" n ", " i "]" => SSet.horn (n : ℕ) i lemma horn_eq_iSup (n : ℕ) (i : Fin (n + 1)) : horn.{u} n i = ⨆ (j : ({i}ᶜ : Set (Fin (n + 1)))), stdSimplex.face {j.1}ᶜ := by ext m j simp [stdSimplex.face_obj, horn, Set.eq_univ_iff_forall] rfl lemma face_le_horn {n : ℕ} (i j : Fin (n + 1)) (h : i ≠ j) : stdSimplex.face.{u} {i}ᶜ ≤ horn n j := by rw [horn_eq_iSup] exact le_iSup (fun (k : ({j}ᶜ : Set (Fin (n + 1)))) ↦ stdSimplex.face.{u} {k.1}ᶜ) ⟨i, h⟩ @[simp] lemma horn_obj_zero (n : ℕ) (i : Fin (n + 3)) : (horn.{u} (n + 2) i).obj (op (.mk 0)) = ⊤ := by ext j -- this was produced using `simp? [horn_eq_iSup]` simp only [horn_eq_iSup, Subpresheaf.iSup_obj, Set.iUnion_coe_set, Set.mem_compl_iff, Set.mem_singleton_iff, Set.mem_iUnion, stdSimplex.mem_face_iff, Nat.reduceAdd, Finset.mem_compl, Finset.mem_singleton, exists_prop, Set.top_eq_univ, Set.mem_univ, iff_true] let S : Finset (Fin (n + 3)) := {i, j 0} have hS : ¬ (S = Finset.univ) := fun hS ↦ by have := Finset.card_le_card hS.symm.le simp only [Finset.card_univ, Fintype.card_fin, S] at this have := this.trans Finset.card_le_two omega rw [Finset.eq_univ_iff_forall, not_forall] at hS obtain ⟨k, hk⟩ := hS simp only [Finset.mem_insert, Finset.mem_singleton, not_or, S] at hk refine ⟨k, hk.1, fun a ↦ ?_⟩ fin_cases a exact Ne.symm hk.2 namespace horn open SimplexCategory Finset Opposite section variable (n : ℕ) (i k : Fin (n + 3)) /-- The (degenerate) subsimplex of `Λ[n+2, i]` concentrated in vertex `k`. -/ def const (m : SimplexCategoryᵒᵖ) : Λ[n+2, i].obj m := SSet.yonedaEquiv (X := Λ[n+2, i]) (SSet.const ⟨stdSimplex.obj₀Equiv.symm k, by simp⟩) @[simp] lemma const_val_apply {m : ℕ} (a : Fin (m + 1)) : (const n i k (op (.mk m))).val a = k := rfl end /-- The edge of `Λ[n, i]` with endpoints `a` and `b`. This edge only exists if `{i, a, b}` has cardinality less than `n`. -/ @[simps] def edge (n : ℕ) (i a b : Fin (n + 1)) (hab : a ≤ b) (H : #{i, a, b} ≤ n) : (Λ[n, i] : SSet.{u}) _⦋1⦌ := ⟨stdSimplex.edge n a b hab, by have hS : ¬ ({i, a, b} = Finset.univ) := fun hS ↦ by have := Finset.card_le_card hS.symm.le simp only [card_univ, Fintype.card_fin] at this omega rw [Finset.eq_univ_iff_forall, not_forall] at hS obtain ⟨k, hk⟩ := hS simp only [mem_insert, mem_singleton, not_or] at hk -- this was produced by `simp? [horn_eq_iSup]` simp only [horn_eq_iSup, Subpresheaf.iSup_obj, Set.iUnion_coe_set, Set.mem_compl_iff, Set.mem_singleton_iff, Set.mem_iUnion, stdSimplex.mem_face_iff, Nat.reduceAdd, mem_compl, mem_singleton, exists_prop] refine ⟨k, hk.1, fun a ↦ ?_⟩ fin_cases a · exact Ne.symm hk.2.1 · exact Ne.symm hk.2.2⟩ /-- Alternative constructor for the edge of `Λ[n, i]` with endpoints `a` and `b`, assuming `3 ≤ n`. -/ @[simps!] def edge₃ (n : ℕ) (i a b : Fin (n + 1)) (hab : a ≤ b) (H : 3 ≤ n) : (Λ[n, i] : SSet.{u}) _⦋1⦌ := edge n i a b hab <| Finset.card_le_three.trans H /-- The edge of `Λ[n, i]` with endpoints `j` and `j+1`. This constructor assumes `0 < i < n`, which is the type of horn that occurs in the horn-filling condition of quasicategories. -/ @[simps!] def primitiveEdge {n : ℕ} {i : Fin (n + 1)} (h₀ : 0 < i) (hₙ : i < Fin.last n) (j : Fin n) : (Λ[n, i] : SSet.{u}) _⦋1⦌ := by refine edge n i j.castSucc j.succ ?_ ?_ · simp only [← Fin.val_fin_le, Fin.coe_castSucc, Fin.val_succ, le_add_iff_nonneg_right, zero_le] simp only [← Fin.val_fin_lt, Fin.val_zero, Fin.val_last] at h₀ hₙ obtain rfl | hn : n = 2 ∨ 2 < n := by rw [eq_comm, or_comm, ← le_iff_lt_or_eq]; omega · revert i j; decide · exact Finset.card_le_three.trans hn /-- The triangle in the standard simplex with vertices `k`, `k+1`, and `k+2`. This constructor assumes `0 < i < n`, which is the type of horn that occurs in the horn-filling condition of quasicategories. -/ @[simps] def primitiveTriangle {n : ℕ} (i : Fin (n + 4)) (h₀ : 0 < i) (hₙ : i < Fin.last (n + 3)) (k : ℕ) (h : k < n + 2) : (Λ[n+3, i] : SSet.{u}) _⦋2⦌ := by refine ⟨stdSimplex.triangle (n := n+3) ⟨k, by omega⟩ ⟨k+1, by omega⟩ ⟨k+2, by omega⟩ ?_ ?_, ?_⟩ · simp only [Fin.mk_le_mk, le_add_iff_nonneg_right, zero_le] · simp only [Fin.mk_le_mk, add_le_add_iff_left, one_le_two] -- this was produced using `simp? [horn_eq_iSup]` simp only [horn_eq_iSup, Subpresheaf.iSup_obj, Set.iUnion_coe_set, Set.mem_compl_iff, Set.mem_singleton_iff, Set.mem_iUnion, stdSimplex.mem_face_iff, Nat.reduceAdd, mem_compl, mem_singleton, exists_prop] have hS : ¬ ({i, (⟨k, by omega⟩ : Fin (n + 4)), (⟨k + 1, by omega⟩ : Fin (n + 4)), (⟨k + 2, by omega⟩ : Fin (n + 4))} = Finset.univ) := fun hS ↦ by obtain ⟨i, hi⟩ := i by_cases hk : k = 0 · subst hk have := Finset.mem_univ (Fin.last _ : Fin (n + 4)) rw [← hS] at this -- this was produced using `simp? [Fin.ext_iff] at this` simp only [Fin.zero_eta, zero_add, Fin.mk_one, mem_insert, Fin.ext_iff, Fin.val_last, Fin.val_zero, AddLeftCancelMonoid.add_eq_zero, OfNat.ofNat_ne_zero, and_false, Fin.val_one, Nat.reduceEqDiff, mem_singleton, or_self, or_false] at this simp only [Fin.lt_iff_val_lt_val, Fin.val_last] at hₙ omega · have := Finset.mem_univ (0 : Fin (n + 4)) rw [← hS] at this -- this was produced using `simp? [Fin.ext_iff] at this` simp only [mem_insert, Fin.ext_iff, Fin.val_zero, right_eq_add, AddLeftCancelMonoid.add_eq_zero, one_ne_zero, and_false, mem_singleton, OfNat.ofNat_ne_zero, or_self, or_false] at this obtain rfl | rfl := this <;> tauto rw [Finset.eq_univ_iff_forall, not_forall] at hS obtain ⟨l, hl⟩ := hS simp only [mem_insert, mem_singleton, not_or] at hl refine ⟨l, hl.1, fun a ↦ ?_⟩ fin_cases a · exact Ne.symm hl.2.1 · exact Ne.symm hl.2.2.1 · exact Ne.symm hl.2.2.2 /-- The `j`th face of codimension `1` of the `i`-th horn. -/ def face {n : ℕ} (i j : Fin (n + 2)) (h : j ≠ i) : (Λ[n + 1, i] : SSet.{u}) _⦋n⦌ := yonedaEquiv (Subpresheaf.lift (stdSimplex.δ j) (by simpa using face_le_horn _ _ h)) /-- Two morphisms from a horn are equal if they are equal on all suitable faces. -/ protected lemma hom_ext {n : ℕ} {i : Fin (n + 2)} {S : SSet} (σ₁ σ₂ : (Λ[n + 1, i] : SSet.{u}) ⟶ S) (h : ∀ (j) (h : j ≠ i), σ₁.app _ (face i j h) = σ₂.app _ (face i j h)) : σ₁ = σ₂ := by rw [← Subpresheaf.equalizer_eq_iff] apply le_antisymm (Subpresheaf.equalizer_le σ₁ σ₂) simp only [horn_eq_iSup, iSup_le_iff, Subtype.forall, Set.mem_compl_iff, Set.mem_singleton_iff, ← stdSimplex.ofSimplex_yonedaEquiv_δ, Subcomplex.ofSimplex_le_iff] intro j hj exact (Subpresheaf.mem_equalizer_iff σ₁ σ₂ (face i j hj)).2 (by apply h) end horn end SSet
ArzelaAscoli.lean
/- Copyright (c) 2018 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Mario Carneiro, Yury Kudryashov, Heather Macbeth -/ import Mathlib.Topology.ContinuousMap.Bounded.Basic import Mathlib.Topology.MetricSpace.Equicontinuity /-! # The Arzelà–Ascoli theorem for bounded continuous functions Arzelà–Ascoli asserts that, on a compact space, a set of functions sharing a common modulus of continuity and taking values in a compact set forms a compact subset for the topology of uniform convergence. This file proves the theorem and several useful variations around it. -/ open Set Metric universe u v namespace BoundedContinuousFunction variable {α : Type u} {β : Type v} [TopologicalSpace α] [CompactSpace α] [PseudoMetricSpace β] /-- First version, with pointwise equicontinuity and range in a compact space. -/ theorem arzela_ascoli₁ [CompactSpace β] (A : Set (α →ᵇ β)) (closed : IsClosed A) (H : Equicontinuous ((↑) : A → α → β)) : IsCompact A := by simp_rw [Equicontinuous, Metric.equicontinuousAt_iff_pair] at H refine isCompact_of_totallyBounded_isClosed ?_ closed refine totallyBounded_of_finite_discretization fun ε ε0 => ?_ rcases exists_between ε0 with ⟨ε₁, ε₁0, εε₁⟩ let ε₂ := ε₁ / 2 / 2 /- We have to find a finite discretization of `u`, i.e., finite information that is sufficient to reconstruct `u` up to `ε`. This information will be provided by the values of `u` on a sufficiently dense set `tα`, slightly translated to fit in a finite `ε₂`-dense set `tβ` in the image. Such sets exist by compactness of the source and range. Then, to check that these data determine the function up to `ε`, one uses the control on the modulus of continuity to extend the closeness on tα to closeness everywhere. -/ have ε₂0 : ε₂ > 0 := half_pos (half_pos ε₁0) have : ∀ x : α, ∃ U, x ∈ U ∧ IsOpen U ∧ ∀ y ∈ U, ∀ z ∈ U, ∀ {f : α →ᵇ β}, f ∈ A → dist (f y) (f z) < ε₂ := fun x => let ⟨U, nhdsU, hU⟩ := H x _ ε₂0 let ⟨V, VU, openV, xV⟩ := _root_.mem_nhds_iff.1 nhdsU ⟨V, xV, openV, fun y hy z hz f hf => hU y (VU hy) z (VU hz) ⟨f, hf⟩⟩ choose U hU using this /- For all `x`, the set `hU x` is an open set containing `x` on which the elements of `A` fluctuate by at most `ε₂`. We extract finitely many of these sets that cover the whole space, by compactness. -/ obtain ⟨tα : Set α, _, hfin, htα : univ ⊆ ⋃ x ∈ tα, U x⟩ := isCompact_univ.elim_finite_subcover_image (fun x _ => (hU x).2.1) fun x _ => mem_biUnion (mem_univ _) (hU x).1 rcases hfin.nonempty_fintype with ⟨_⟩ obtain ⟨tβ : Set β, _, hfin, htβ : univ ⊆ ⋃y ∈ tβ, ball y ε₂⟩ := @finite_cover_balls_of_compact β _ _ isCompact_univ _ ε₂0 rcases hfin.nonempty_fintype with ⟨_⟩ -- Associate to every point `y` in the space a nearby point `F y` in `tβ` choose F hF using fun y => show ∃ z ∈ tβ, dist y z < ε₂ by simpa using htβ (mem_univ y) -- `F : β → β`, `hF : ∀ (y : β), F y ∈ tβ ∧ dist y (F y) < ε₂` /- Associate to every function a discrete approximation, mapping each point in `tα` to a point in `tβ` close to its true image by the function. -/ classical refine ⟨tα → tβ, by infer_instance, fun f a => ⟨F (f.1 a), (hF (f.1 a)).1⟩, ?_⟩ rintro ⟨f, hf⟩ ⟨g, hg⟩ f_eq_g -- If two functions have the same approximation, then they are within distance `ε` refine lt_of_le_of_lt ((dist_le <| le_of_lt ε₁0).2 fun x => ?_) εε₁ obtain ⟨x', x'tα, hx'⟩ := mem_iUnion₂.1 (htα (mem_univ x)) calc dist (f x) (g x) ≤ dist (f x) (f x') + dist (g x) (g x') + dist (f x') (g x') := dist_triangle4_right _ _ _ _ _ ≤ ε₂ + ε₂ + ε₁ / 2 := by refine le_of_lt (add_lt_add (add_lt_add ?_ ?_) ?_) · exact (hU x').2.2 _ hx' _ (hU x').1 hf · exact (hU x').2.2 _ hx' _ (hU x').1 hg · have F_f_g : F (f x') = F (g x') := (congr_arg (fun f : tα → tβ => (f ⟨x', x'tα⟩ : β)) f_eq_g :) calc dist (f x') (g x') ≤ dist (f x') (F (f x')) + dist (g x') (F (f x')) := dist_triangle_right _ _ _ _ = dist (f x') (F (f x')) + dist (g x') (F (g x')) := by rw [F_f_g] _ < ε₂ + ε₂ := (add_lt_add (hF (f x')).2 (hF (g x')).2) _ = ε₁ / 2 := add_halves _ _ = ε₁ := by rw [add_halves, add_halves] /-- Second version, with pointwise equicontinuity and range in a compact subset. -/ theorem arzela_ascoli₂ (s : Set β) (hs : IsCompact s) (A : Set (α →ᵇ β)) (closed : IsClosed A) (in_s : ∀ (f : α →ᵇ β) (x : α), f ∈ A → f x ∈ s) (H : Equicontinuous ((↑) : A → α → β)) : IsCompact A := by /- This version is deduced from the previous one by restricting to the compact type in the target, using compactness there and then lifting everything to the original space. -/ have M : LipschitzWith 1 Subtype.val := LipschitzWith.subtype_val s let F : (α →ᵇ s) → α →ᵇ β := comp (↑) M refine IsCompact.of_isClosed_subset ((?_ : IsCompact (F ⁻¹' A)).image (continuous_comp M)) closed fun f hf => ?_ · haveI : CompactSpace s := isCompact_iff_compactSpace.1 hs refine arzela_ascoli₁ _ (continuous_iff_isClosed.1 (continuous_comp M) _ closed) ?_ rw [isUniformEmbedding_subtype_val.isUniformInducing.equicontinuous_iff] exact H.comp (A.restrictPreimage F) · let g := codRestrict s f fun x => in_s f x hf rw [show f = F g by ext; rfl] at hf ⊢ exact ⟨g, hf, rfl⟩ /-- Third (main) version, with pointwise equicontinuity and range in a compact subset, but without closedness. The closure is then compact. -/ theorem arzela_ascoli [T2Space β] (s : Set β) (hs : IsCompact s) (A : Set (α →ᵇ β)) (in_s : ∀ (f : α →ᵇ β) (x : α), f ∈ A → f x ∈ s) (H : Equicontinuous ((↑) : A → α → β)) : IsCompact (closure A) := /- This version is deduced from the previous one by checking that the closure of `A`, in addition to being closed, still satisfies the properties of compact range and equicontinuity. -/ arzela_ascoli₂ s hs (closure A) isClosed_closure (fun _ x hf => (mem_of_closed' hs.isClosed).2 fun ε ε0 => let ⟨g, gA, dist_fg⟩ := Metric.mem_closure_iff.1 hf ε ε0 ⟨g x, in_s g x gA, lt_of_le_of_lt (dist_coe_le_dist _) dist_fg⟩) (H.closure' continuous_coe) end BoundedContinuousFunction
Atlas.lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Geometry.Manifold.ContMDiff.Basic /-! ## Smoothness of charts and local structomorphisms We show that the model with corners, charts, extended charts and their inverses are `C^n`, and that local structomorphisms are `C^n` with `C^n` inverses. -/ open Set ChartedSpace IsManifold open scoped Manifold ContDiff variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] -- declare a `C^n` manifold `M` over the pair `(E, H)`. {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {n : WithTop ℕ∞} [IsManifold I n M] -- declare a topological space `M'`. {M' : Type*} [TopologicalSpace M'] -- declare functions, sets, points and smoothness indices {e : PartialHomeomorph M H} {x : M} /-! ### Atlas members are `C^n` -/ section Atlas theorem contMDiff_model : ContMDiff I 𝓘(𝕜, E) n I := by intro x refine contMDiffAt_iff.mpr ⟨I.continuousAt, ?_⟩ simp only [mfld_simps] refine contDiffWithinAt_id.congr_of_eventuallyEq ?_ ?_ · exact Filter.eventuallyEq_of_mem self_mem_nhdsWithin fun x₂ => I.right_inv simp_rw [Function.comp_apply, I.left_inv, Function.id_def] theorem contMDiffOn_model_symm : ContMDiffOn 𝓘(𝕜, E) I n I.symm (range I) := by rw [contMDiffOn_iff] refine ⟨I.continuousOn_symm, fun x y => ?_⟩ simp only [mfld_simps] exact contDiffOn_id.congr fun x' => I.right_inv /-- An atlas member is `C^n` for any `n`. -/ theorem contMDiffOn_of_mem_maximalAtlas (h : e ∈ maximalAtlas I n M) : ContMDiffOn I I n e e.source := (contDiffWithinAt_localInvariantProp n).liftPropOn_of_mem_maximalAtlas contDiffWithinAtProp_id h /-- The inverse of an atlas member is `C^n` for any `n`. -/ theorem contMDiffOn_symm_of_mem_maximalAtlas (h : e ∈ maximalAtlas I n M) : ContMDiffOn I I n e.symm e.target := (contDiffWithinAt_localInvariantProp n).liftPropOn_symm_of_mem_maximalAtlas contDiffWithinAtProp_id h theorem contMDiffAt_of_mem_maximalAtlas (h : e ∈ maximalAtlas I n M) (hx : x ∈ e.source) : ContMDiffAt I I n e x := (contMDiffOn_of_mem_maximalAtlas h).contMDiffAt <| e.open_source.mem_nhds hx theorem contMDiffAt_symm_of_mem_maximalAtlas {x : H} (h : e ∈ maximalAtlas I n M) (hx : x ∈ e.target) : ContMDiffAt I I n e.symm x := (contMDiffOn_symm_of_mem_maximalAtlas h).contMDiffAt <| e.open_target.mem_nhds hx theorem contMDiffOn_chart : ContMDiffOn I I n (chartAt H x) (chartAt H x).source := contMDiffOn_of_mem_maximalAtlas <| chart_mem_maximalAtlas x theorem contMDiffOn_chart_symm : ContMDiffOn I I n (chartAt H x).symm (chartAt H x).target := contMDiffOn_symm_of_mem_maximalAtlas <| chart_mem_maximalAtlas x theorem contMDiffAt_extend {x : M} (he : e ∈ maximalAtlas I n M) (hx : x ∈ e.source) : ContMDiffAt I 𝓘(𝕜, E) n (e.extend I) x := (contMDiff_model _).comp x <| contMDiffAt_of_mem_maximalAtlas he hx theorem contMDiffAt_extChartAt' {x' : M} (h : x' ∈ (chartAt H x).source) : ContMDiffAt I 𝓘(𝕜, E) n (extChartAt I x) x' := contMDiffAt_extend (chart_mem_maximalAtlas x) h omit [IsManifold I n M] in theorem contMDiffAt_extChartAt : ContMDiffAt I 𝓘(𝕜, E) n (extChartAt I x) x := by rw [contMDiffAt_iff_source] apply contMDiffWithinAt_id.congr_of_eventuallyEq_of_mem _ (by simp) filter_upwards [extChartAt_target_mem_nhdsWithin x] with y hy exact PartialEquiv.right_inv (extChartAt I x) hy theorem contMDiffOn_extChartAt : ContMDiffOn I 𝓘(𝕜, E) n (extChartAt I x) (chartAt H x).source := fun _x' hx' => (contMDiffAt_extChartAt' hx').contMDiffWithinAt theorem contMDiffOn_extend_symm (he : e ∈ maximalAtlas I n M) : ContMDiffOn 𝓘(𝕜, E) I n (e.extend I).symm (I '' e.target) := by refine (contMDiffOn_symm_of_mem_maximalAtlas he).comp (contMDiffOn_model_symm.mono <| image_subset_range _ _) ?_ simp_rw [image_subset_iff, PartialEquiv.restr_coe_symm, I.toPartialEquiv_coe_symm, preimage_preimage, I.left_inv, preimage_id']; rfl theorem contMDiffOn_extChartAt_symm (x : M) : ContMDiffOn 𝓘(𝕜, E) I n (extChartAt I x).symm (extChartAt I x).target := by convert contMDiffOn_extend_symm (chart_mem_maximalAtlas (I := I) x) · rw [extChartAt_target, I.image_eq] · infer_instance · infer_instance theorem contMDiffWithinAt_extChartAt_symm_target (x : M) {y : E} (hy : y ∈ (extChartAt I x).target) : ContMDiffWithinAt 𝓘(𝕜, E) I n (extChartAt I x).symm (extChartAt I x).target y := contMDiffOn_extChartAt_symm x y hy theorem contMDiffWithinAt_extChartAt_symm_range (x : M) {y : E} (hy : y ∈ (extChartAt I x).target) : ContMDiffWithinAt 𝓘(𝕜, E) I n (extChartAt I x).symm (range I) y := (contMDiffWithinAt_extChartAt_symm_target x hy).mono_of_mem_nhdsWithin (extChartAt_target_mem_nhdsWithin_of_mem hy) omit [IsManifold I n M] in theorem contMDiffWithinAt_extChartAt_symm_target_self (x : M) : ContMDiffWithinAt 𝓘(𝕜, E) I n (extChartAt I x).symm (extChartAt I x).target (extChartAt I x x) := by rw [contMDiffWithinAt_iff_target] constructor · apply ContinuousAt.continuousWithinAt apply ContinuousAt.comp _ I.continuousAt_symm exact (chartAt H x).symm.continuousAt (by simp) · apply contMDiffWithinAt_id.congr_of_mem (fun y hy ↦ ?_) (by simp) convert PartialEquiv.right_inv (extChartAt I x) hy simp omit [IsManifold I n M] in theorem contMDiffWithinAt_extChartAt_symm_range_self (x : M) : ContMDiffWithinAt 𝓘(𝕜, E) I n (extChartAt I x).symm (range I) (extChartAt I x x) := (contMDiffWithinAt_extChartAt_symm_target_self x).mono_of_mem_nhdsWithin (extChartAt_target_mem_nhdsWithin x) /-- An element of `contDiffGroupoid n I` is `C^n`. -/ theorem contMDiffOn_of_mem_contDiffGroupoid {e' : PartialHomeomorph H H} (h : e' ∈ contDiffGroupoid n I) : ContMDiffOn I I n e' e'.source := (contDiffWithinAt_localInvariantProp n).liftPropOn_of_mem_groupoid contDiffWithinAtProp_id h end Atlas /-! ### (local) structomorphisms are `C^n` -/ section IsLocalStructomorph variable [ChartedSpace H M'] [IsM' : IsManifold I n M'] theorem isLocalStructomorphOn_contDiffGroupoid_iff_aux {f : PartialHomeomorph M M'} (hf : LiftPropOn (contDiffGroupoid n I).IsLocalStructomorphWithinAt f f.source) : ContMDiffOn I I n f f.source := by -- It suffices to show regularity near each `x` apply contMDiffOn_of_locally_contMDiffOn intro x hx let c := chartAt H x let c' := chartAt H (f x) obtain ⟨-, hxf⟩ := hf x hx -- Since `f` is a local structomorph, it is locally equal to some transferred element `e` of -- the `contDiffGroupoid`. obtain ⟨e, he, he' : EqOn (c' ∘ f ∘ c.symm) e (c.symm ⁻¹' f.source ∩ e.source), hex : c x ∈ e.source⟩ := hxf (by simp only [hx, mfld_simps]) -- We choose a convenient set `s` in `M`. let s : Set M := (f.trans c').source ∩ ((c.trans e).trans c'.symm).source refine ⟨s, (f.trans c').open_source.inter ((c.trans e).trans c'.symm).open_source, ?_, ?_⟩ · simp only [s, mfld_simps] rw [← he'] <;> simp only [c, c', hx, hex, mfld_simps] -- We need to show `f` is `ContMDiffOn` the domain `s ∩ f.source`. We show this in two -- steps: `f` is equal to `c'.symm ∘ e ∘ c` on that domain and that function is -- `ContMDiffOn` it. have H₁ : ContMDiffOn I I n (c'.symm ∘ e ∘ c) s := by have hc' : ContMDiffOn I I n c'.symm _ := contMDiffOn_chart_symm have he'' : ContMDiffOn I I n e _ := contMDiffOn_of_mem_contDiffGroupoid he have hc : ContMDiffOn I I n c _ := contMDiffOn_chart refine (hc'.comp' (he''.comp' hc)).mono ?_ dsimp [s, c, c'] mfld_set_tac have H₂ : EqOn f (c'.symm ∘ e ∘ c) s := by intro y hy simp only [s, mfld_simps] at hy have hy₁ : f y ∈ c'.source := by simp only [hy, mfld_simps] have hy₂ : y ∈ c.source := by simp only [hy, mfld_simps] have hy₃ : c y ∈ c.symm ⁻¹' f.source ∩ e.source := by simp only [hy, mfld_simps] calc f y = c'.symm (c' (f y)) := by rw [c'.left_inv hy₁] _ = c'.symm (c' (f (c.symm (c y)))) := by rw [c.left_inv hy₂] _ = c'.symm (e (c y)) := by rw [← he' hy₃]; rfl refine (H₁.congr H₂).mono ?_ mfld_set_tac /-- Let `M` and `M'` be manifolds with the same model-with-corners, `I`. Then `f : M → M'` is a local structomorphism for `I`, if and only if it is manifold-`C^n` on the domain of definition in both directions. -/ theorem isLocalStructomorphOn_contDiffGroupoid_iff (f : PartialHomeomorph M M') : LiftPropOn (contDiffGroupoid n I).IsLocalStructomorphWithinAt f f.source ↔ ContMDiffOn I I n f f.source ∧ ContMDiffOn I I n f.symm f.target := by constructor · intro h refine ⟨isLocalStructomorphOn_contDiffGroupoid_iff_aux h, isLocalStructomorphOn_contDiffGroupoid_iff_aux ?_⟩ -- todo: we can generalize this part of the proof to a lemma intro X hX let x := f.symm X have hx : x ∈ f.source := f.symm.mapsTo hX let c := chartAt H x let c' := chartAt H X obtain ⟨-, hxf⟩ := h x hx refine ⟨(f.symm.continuousAt hX).continuousWithinAt, fun h2x => ?_⟩ obtain ⟨e, he, h2e, hef, hex⟩ : ∃ e : PartialHomeomorph H H, e ∈ contDiffGroupoid n I ∧ e.source ⊆ (c.symm ≫ₕ f ≫ₕ c').source ∧ EqOn (c' ∘ f ∘ c.symm) e e.source ∧ c x ∈ e.source := by have h1 : c' = chartAt H (f x) := by simp only [x, c', f.right_inv hX] have h2 : c' ∘ f ∘ c.symm = ⇑(c.symm ≫ₕ f ≫ₕ c') := rfl have hcx : c x ∈ c.symm ⁻¹' f.source := by simp only [c, hx, mfld_simps] rw [h2] rw [← h1, h2, PartialHomeomorph.isLocalStructomorphWithinAt_iff'] at hxf · exact hxf hcx · dsimp [x, c]; mfld_set_tac · apply Or.inl simp only [c, hx, h1, mfld_simps] have h2X : c' X = e (c (f.symm X)) := by rw [← hef hex] dsimp only [Function.comp_def] have hfX : f.symm X ∈ c.source := by simp only [c, x, mfld_simps] rw [c.left_inv hfX, f.right_inv hX] have h3e : EqOn (c ∘ f.symm ∘ c'.symm) e.symm (c'.symm ⁻¹' f.target ∩ e.target) := by have h1 : EqOn (c.symm ≫ₕ f ≫ₕ c').symm e.symm (e.target ∩ e.target) := by apply EqOn.symm refine e.isImage_source_target.symm_eqOn_of_inter_eq_of_eqOn ?_ ?_ · rw [inter_self, inter_eq_right.mpr h2e] · rw [inter_self]; exact hef.symm have h2 : e.target ⊆ (c.symm ≫ₕ f ≫ₕ c').target := by intro x hx; rw [← e.right_inv hx, ← hef (e.symm.mapsTo hx)] exact PartialHomeomorph.mapsTo _ (h2e <| e.symm.mapsTo hx) rw [inter_self] at h1 rwa [inter_eq_right.mpr] refine h2.trans ?_ mfld_set_tac refine ⟨e.symm, StructureGroupoid.symm _ he, h3e, ?_⟩ rw [h2X]; exact e.mapsTo hex · -- We now show the converse: a partial homeomorphism `f : M → M'` which is `C^n` in both -- directions is a local structomorphism. We do this by proposing -- `((chart_at H x).symm.trans f).trans (chart_at H (f x))` as a candidate for a structomorphism -- of `H`. rintro ⟨h₁, h₂⟩ x hx refine ⟨(h₁ x hx).continuousWithinAt, ?_⟩ let c := chartAt H x let c' := chartAt H (f x) rintro (hx' : c x ∈ c.symm ⁻¹' f.source) -- propose `(c.symm.trans f).trans c'` as a candidate for a local structomorphism of `H` refine ⟨(c.symm.trans f).trans c', ⟨?_, ?_⟩, (?_ : EqOn (c' ∘ f ∘ c.symm) _ _), ?_⟩ · -- regularity of the candidate local structomorphism in the forward direction intro y hy simp only [mfld_simps] at hy have H : ContMDiffWithinAt I I n f (f ≫ₕ c').source ((extChartAt I x).symm y) := by refine (h₁ ((extChartAt I x).symm y) ?_).mono ?_ · simp only [c, hy, mfld_simps] · mfld_set_tac have hy' : (extChartAt I x).symm y ∈ c.source := by simp only [c, hy, mfld_simps] have hy'' : f ((extChartAt I x).symm y) ∈ c'.source := by simp only [c, hy, mfld_simps] rw [contMDiffWithinAt_iff_of_mem_source hy' hy''] at H convert H.2.mono _ · simp only [c, hy, mfld_simps] · dsimp [c, c']; mfld_set_tac · -- regularity of the candidate local structomorphism in the reverse direction intro y hy simp only [mfld_simps] at hy have H : ContMDiffWithinAt I I n f.symm (f.symm ≫ₕ c).source ((extChartAt I (f x)).symm y) := by refine (h₂ ((extChartAt I (f x)).symm y) ?_).mono ?_ · simp only [c', hy, mfld_simps] · mfld_set_tac have hy' : (extChartAt I (f x)).symm y ∈ c'.source := by simp only [c', hy, mfld_simps] have hy'' : f.symm ((extChartAt I (f x)).symm y) ∈ c.source := by simp only [c', hy, mfld_simps] rw [contMDiffWithinAt_iff_of_mem_source hy' hy''] at H convert H.2.mono _ · simp only [c', hy, mfld_simps] · dsimp [c, c']; mfld_set_tac -- now check the candidate local structomorphism agrees with `f` where it is supposed to · simp only [mfld_simps]; apply eqOn_refl · simp only [c, c', hx', mfld_simps] end IsLocalStructomorph
NonZeroDivisors.lean
/- Copyright (c) 2022 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.Regular.Basic import Mathlib.Algebra.Ring.Basic /-! # Non-zero divisors in a ring -/ assert_not_exists Field open scoped nonZeroDivisors section Monoid variable {R : Type*} [Monoid R] [Finite R] {r : R} theorem IsLeftRegular.isUnit_of_finite (h : IsLeftRegular r) : IsUnit r := by rwa [IsUnit.isUnit_iff_mulLeft_bijective, ← Finite.injective_iff_bijective] theorem IsRightRegular.isUnit_of_finite (h : IsRightRegular r) : IsUnit r := by rwa [IsUnit.isUnit_iff_mulRight_bijective, ← Finite.injective_iff_bijective] theorem isRegular_iff_isUnit_of_finite {r : R} : IsRegular r ↔ IsUnit r where mp h := h.1.isUnit_of_finite mpr h := h.isRegular end Monoid section Ring variable {R : Type*} [Ring R] {a x y r : R} lemma isLeftRegular_iff_mem_nonZeroDivisorsLeft : IsLeftRegular r ↔ r ∈ nonZeroDivisorsLeft R := isLeftRegular_iff_right_eq_zero_of_mul lemma isRightRegular_iff_mem_nonZeroDivisorsRight : IsRightRegular r ↔ r ∈ nonZeroDivisorsRight R := isRightRegular_iff_left_eq_zero_of_mul lemma isRegular_iff_mem_nonZeroDivisors : IsRegular r ↔ r ∈ R⁰ := isRegular_iff_eq_zero_of_mul lemma le_nonZeroDivisorsLeft_iff_isLeftRegular {S : Submonoid R} : S ≤ nonZeroDivisorsLeft R ↔ ∀ s : S, IsLeftRegular (s : R) := by simp_rw [SetLike.le_def, isLeftRegular_iff_mem_nonZeroDivisorsLeft, Subtype.forall] lemma le_nonZeroDivisorsRight_iff_isRightRegular {S : Submonoid R} : S ≤ nonZeroDivisorsRight R ↔ ∀ s : S, IsRightRegular (s : R) := by simp_rw [SetLike.le_def, isRightRegular_iff_mem_nonZeroDivisorsRight, Subtype.forall] lemma le_nonZeroDivisors_iff_isRegular {S : Submonoid R} : S ≤ R⁰ ↔ ∀ s : S, IsRegular (s : R) := by simp_rw [nonZeroDivisors, le_inf_iff, le_nonZeroDivisorsLeft_iff_isLeftRegular, le_nonZeroDivisorsRight_iff_isRightRegular, isRegular_iff, forall_and] @[deprecated (since := "2025-07-16")] alias isLeftRegular_iff_mem_nonZeroDivisorsRight := isLeftRegular_iff_mem_nonZeroDivisorsLeft @[deprecated (since := "2025-07-16")] alias isRightRegular_iff_mem_nonZeroDivisorsLeft := isRightRegular_iff_mem_nonZeroDivisorsRight @[deprecated (since := "2025-07-16")] alias le_nonZeroDivisors_iff_isRightRegular := le_nonZeroDivisorsRight_iff_isRightRegular lemma mul_cancel_left_mem_nonZeroDivisorsLeft (hr : r ∈ nonZeroDivisorsLeft R) : r * x = r * y ↔ x = y := ⟨(isLeftRegular_iff_mem_nonZeroDivisorsLeft.mpr hr ·), congr_arg (r * ·)⟩ lemma mul_cancel_right_mem_nonZeroDivisorsRight (hr : r ∈ nonZeroDivisorsRight R) : x * r = y * r ↔ x = y := ⟨(isRightRegular_iff_mem_nonZeroDivisorsRight.mpr hr ·), congr_arg (· * r)⟩ @[simp] lemma mul_cancel_left_mem_nonZeroDivisors (hr : r ∈ R⁰) : r * x = r * y ↔ x = y := mul_cancel_left_mem_nonZeroDivisorsLeft hr.1 lemma mul_cancel_left_coe_nonZeroDivisors {c : R⁰} : (c : R) * x = c * y ↔ x = y := mul_cancel_left_mem_nonZeroDivisors c.prop lemma mul_cancel_right_mem_nonZeroDivisors (hr : r ∈ R⁰) : x * r = y * r ↔ x = y := mul_cancel_right_mem_nonZeroDivisorsRight hr.2 lemma mul_cancel_right_coe_nonZeroDivisors {c : R⁰} : x * c = y * c ↔ x = y := mul_cancel_right_mem_nonZeroDivisors c.prop /-- In a finite ring, an element is a unit iff it is a non-zero-divisor. -/ lemma isUnit_iff_mem_nonZeroDivisors_of_finite [Finite R] : IsUnit a ↔ a ∈ nonZeroDivisors R := by rw [← isRegular_iff_mem_nonZeroDivisors, isRegular_iff_isUnit_of_finite] lemma dvd_cancel_left_mem_nonZeroDivisors (hr : r ∈ R⁰) : r * x ∣ r * y ↔ x ∣ y := (isLeftRegular_iff_mem_nonZeroDivisorsLeft.mpr hr.1).dvd_cancel_left lemma dvd_cancel_left_coe_nonZeroDivisors {c : R⁰} : c * x ∣ c * y ↔ x ∣ y := dvd_cancel_left_mem_nonZeroDivisors c.prop end Ring section CommRing variable {R : Type*} [CommRing R] {r x y : R} lemma dvd_cancel_right_mem_nonZeroDivisors (hr : r ∈ R⁰) : x * r ∣ y * r ↔ x ∣ y := by simp_rw [← mul_comm r, dvd_cancel_left_mem_nonZeroDivisors hr] lemma dvd_cancel_right_coe_nonZeroDivisors {c : R⁰} : x * c ∣ y * c ↔ x ∣ y := dvd_cancel_right_mem_nonZeroDivisors c.prop end CommRing
test_regular_conv.v
From mathcomp Require Import all_boot all_order all_algebra all_field. Section regular. Import GRing. Goal forall R : ringType, [the lalgType R of R^o] = R :> ringType. Proof. by move=> [? []]. Qed. Goal forall R : comRingType, [the algType R of R^o] = R :> ringType. Proof. by move=> [? []]. Qed. Goal forall R : comRingType, [the comAlgType R of R^o] = R :> ringType. Proof. by move=> [? []]. Qed. Goal forall R : comUnitRingType, [the unitAlgType R of R^o] = R :> unitRingType. Proof. by move=> [? []]. Qed. Goal forall R : comUnitRingType, [the comUnitAlgType R of R^o] = R :> comUnitRingType. Proof. by move=> [? []]. Qed. Goal forall R : comUnitRingType, [the falgType R of R^o] = R :> unitRingType. Proof. by move=> [? []]. Qed. Goal forall K : fieldType, [the fieldExtType K of K^o] = K :> fieldType. Proof. by move=> [? []]. Qed. End regular.
PadicNorm.lean
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis -/ import Mathlib.Algebra.Order.AbsoluteValue.Basic import Mathlib.NumberTheory.Padics.PadicVal.Basic /-! # p-adic norm This file defines the `p`-adic norm on `ℚ`. The `p`-adic valuation on `ℚ` is the difference of the multiplicities of `p` in the numerator and denominator of `q`. This function obeys the standard properties of a valuation, with the appropriate assumptions on `p`. The valuation induces a norm on `ℚ`. This norm is a nonarchimedean absolute value. It takes values in {0} ∪ {1/p^k | k ∈ ℤ}. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking `[Fact p.Prime]` as a type class argument. ## References * [F. Q. Gouvêa, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, norm, valuation -/ /-- If `q ≠ 0`, the `p`-adic norm of a rational `q` is `p ^ (-padicValRat p q)`. If `q = 0`, the `p`-adic norm of `q` is `0`. -/ def padicNorm (p : ℕ) (q : ℚ) : ℚ := if q = 0 then 0 else (p : ℚ) ^ (-padicValRat p q) namespace padicNorm open padicValRat variable {p : ℕ} /-- Unfolds the definition of the `p`-adic norm of `q` when `q ≠ 0`. -/ @[simp] protected theorem eq_zpow_of_nonzero {q : ℚ} (hq : q ≠ 0) : padicNorm p q = (p : ℚ) ^ (-padicValRat p q) := by simp [hq, padicNorm] /-- The `p`-adic norm is nonnegative. -/ protected theorem nonneg (q : ℚ) : 0 ≤ padicNorm p q := if hq : q = 0 then by simp [hq, padicNorm] else by unfold padicNorm split_ifs apply zpow_nonneg exact mod_cast Nat.zero_le _ /-- The `p`-adic norm of `0` is `0`. -/ @[simp] protected theorem zero : padicNorm p 0 = 0 := by simp [padicNorm] /-- The `p`-adic norm of `1` is `1`. -/ protected theorem one : padicNorm p 1 = 1 := by simp [padicNorm] /-- The `p`-adic norm of `p` is `p⁻¹` if `p > 1`. See also `padicNorm.padicNorm_p_of_prime` for a version assuming `p` is prime. -/ theorem padicNorm_p (hp : 1 < p) : padicNorm p p = (p : ℚ)⁻¹ := by simp [padicNorm, (pos_of_gt hp).ne', padicValNat.self hp] /-- The `p`-adic norm of `p` is `p⁻¹` if `p` is prime. See also `padicNorm.padicNorm_p` for a version assuming `1 < p`. -/ @[simp] theorem padicNorm_p_of_prime [Fact p.Prime] : padicNorm p p = (p : ℚ)⁻¹ := padicNorm_p <| Nat.Prime.one_lt Fact.out /-- The `p`-adic norm of `q` is `1` if `q` is prime and not equal to `p`. -/ theorem padicNorm_of_prime_of_ne {q : ℕ} [p_prime : Fact p.Prime] [q_prime : Fact q.Prime] (neq : p ≠ q) : padicNorm p q = 1 := by have p : padicValRat p q = 0 := mod_cast padicValNat_primes neq rw [padicNorm, p] simp [q_prime.1.ne_zero] /-- The `p`-adic norm of `p` is less than `1` if `1 < p`. See also `padicNorm.padicNorm_p_lt_one_of_prime` for a version assuming `p` is prime. -/ theorem padicNorm_p_lt_one (hp : 1 < p) : padicNorm p p < 1 := by rw [padicNorm_p hp, inv_lt_one_iff₀] exact mod_cast Or.inr hp /-- The `p`-adic norm of `p` is less than `1` if `p` is prime. See also `padicNorm.padicNorm_p_lt_one` for a version assuming `1 < p`. -/ theorem padicNorm_p_lt_one_of_prime [Fact p.Prime] : padicNorm p p < 1 := padicNorm_p_lt_one <| Nat.Prime.one_lt Fact.out /-- `padicNorm p q` takes discrete values `p ^ -z` for `z : ℤ`. -/ protected theorem values_discrete {q : ℚ} (hq : q ≠ 0) : ∃ z : ℤ, padicNorm p q = (p : ℚ) ^ (-z) := ⟨padicValRat p q, by simp [padicNorm, hq]⟩ /-- `padicNorm p` is symmetric. -/ @[simp] protected theorem neg (q : ℚ) : padicNorm p (-q) = padicNorm p q := if hq : q = 0 then by simp [hq] else by simp [padicNorm, hq] variable [hp : Fact p.Prime] /-- If `q ≠ 0`, then `padicNorm p q ≠ 0`. -/ protected theorem nonzero {q : ℚ} (hq : q ≠ 0) : padicNorm p q ≠ 0 := by rw [padicNorm.eq_zpow_of_nonzero hq] apply zpow_ne_zero exact mod_cast ne_of_gt hp.1.pos /-- If the `p`-adic norm of `q` is 0, then `q` is `0`. -/ theorem zero_of_padicNorm_eq_zero {q : ℚ} (h : padicNorm p q = 0) : q = 0 := by apply by_contradiction; intro hq unfold padicNorm at h; rw [if_neg hq] at h apply absurd h apply zpow_ne_zero exact mod_cast hp.1.ne_zero /-- The `p`-adic norm is multiplicative. -/ @[simp] protected theorem mul (q r : ℚ) : padicNorm p (q * r) = padicNorm p q * padicNorm p r := if hq : q = 0 then by simp [hq] else if hr : r = 0 then by simp [hr] else by have : (p : ℚ) ≠ 0 := by simp [hp.1.ne_zero] simp [padicNorm, *, padicValRat.mul, zpow_add₀ this, mul_comm] /-- The `p`-adic norm respects division. -/ @[simp] protected theorem div (q r : ℚ) : padicNorm p (q / r) = padicNorm p q / padicNorm p r := if hr : r = 0 then by simp [hr] else eq_div_of_mul_eq (padicNorm.nonzero hr) (by rw [← padicNorm.mul, div_mul_cancel₀ _ hr]) /-- The `p`-adic norm of an integer is at most `1`. -/ protected theorem of_int (z : ℤ) : padicNorm p z ≤ 1 := by obtain rfl | hz := eq_or_ne z 0 · simp · rw [padicNorm, if_neg (mod_cast hz)] exact zpow_le_one_of_nonpos₀ (mod_cast hp.1.one_le) (by simp) private theorem nonarchimedean_aux {q r : ℚ} (h : padicValRat p q ≤ padicValRat p r) : padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) := have hnqp : padicNorm p q ≥ 0 := padicNorm.nonneg _ have hnrp : padicNorm p r ≥ 0 := padicNorm.nonneg _ if hq : q = 0 then by simp [hq, max_eq_right hnrp] else if hr : r = 0 then by simp [hr, max_eq_left hnqp] else if hqr : q + r = 0 then le_trans (by simpa [hqr] using hnqp) (le_max_left _ _) else by unfold padicNorm; split_ifs apply le_max_iff.2 left apply zpow_le_zpow_right₀ · exact mod_cast le_of_lt hp.1.one_lt · apply neg_le_neg have : padicValRat p q = min (padicValRat p q) (padicValRat p r) := (min_eq_left h).symm rw [this] exact min_le_padicValRat_add hqr /-- The `p`-adic norm is nonarchimedean: the norm of `p + q` is at most the max of the norm of `p` and the norm of `q`. -/ protected theorem nonarchimedean {q r : ℚ} : padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) := by wlog hle : padicValRat p q ≤ padicValRat p r generalizing q r · rw [add_comm, max_comm] exact this (le_of_not_ge hle) exact nonarchimedean_aux hle /-- The `p`-adic norm respects the triangle inequality: the norm of `p + q` is at most the norm of `p` plus the norm of `q`. -/ theorem triangle_ineq (q r : ℚ) : padicNorm p (q + r) ≤ padicNorm p q + padicNorm p r := calc padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) := padicNorm.nonarchimedean _ ≤ padicNorm p q + padicNorm p r := max_le_add_of_nonneg (padicNorm.nonneg _) (padicNorm.nonneg _) /-- The `p`-adic norm of a difference is at most the max of each component. Restates the archimedean property of the `p`-adic norm. -/ protected theorem sub {q r : ℚ} : padicNorm p (q - r) ≤ max (padicNorm p q) (padicNorm p r) := by rw [sub_eq_add_neg, ← padicNorm.neg r] exact padicNorm.nonarchimedean /-- If the `p`-adic norms of `q` and `r` are different, then the norm of `q + r` is equal to the max of the norms of `q` and `r`. -/ theorem add_eq_max_of_ne {q r : ℚ} (hne : padicNorm p q ≠ padicNorm p r) : padicNorm p (q + r) = max (padicNorm p q) (padicNorm p r) := by wlog hlt : padicNorm p r < padicNorm p q · rw [add_comm, max_comm] exact this hne.symm (hne.lt_or_gt.resolve_right hlt) have : padicNorm p q ≤ max (padicNorm p (q + r)) (padicNorm p r) := calc padicNorm p q = padicNorm p (q + r + (-r)) := by ring_nf _ ≤ max (padicNorm p (q + r)) (padicNorm p (-r)) := padicNorm.nonarchimedean _ = max (padicNorm p (q + r)) (padicNorm p r) := by simp have hnge : padicNorm p r ≤ padicNorm p (q + r) := by apply le_of_not_gt intro hgt rw [max_eq_right_of_lt hgt] at this exact not_lt_of_ge this hlt have : padicNorm p q ≤ padicNorm p (q + r) := by rwa [max_eq_left hnge] at this apply _root_.le_antisymm · apply padicNorm.nonarchimedean · rwa [max_eq_left_of_lt hlt] /-- The `p`-adic norm is an absolute value: positive-definite and multiplicative, satisfying the triangle inequality. -/ instance : IsAbsoluteValue (padicNorm p) where abv_nonneg' := padicNorm.nonneg abv_eq_zero' := ⟨zero_of_padicNorm_eq_zero, fun hx ↦ by simp [hx]⟩ abv_add' := padicNorm.triangle_ineq abv_mul' := padicNorm.mul theorem dvd_iff_norm_le {n : ℕ} {z : ℤ} : ↑(p ^ n) ∣ z ↔ padicNorm p z ≤ (p : ℚ) ^ (-n : ℤ) := by unfold padicNorm; split_ifs with hz · norm_cast at hz simp [hz] · rw [zpow_le_zpow_iff_right₀, neg_le_neg_iff, padicValRat.of_int, padicValInt.of_ne_one_ne_zero hp.1.ne_one _] · norm_cast rw [← FiniteMultiplicity.pow_dvd_iff_le_multiplicity] · norm_cast · apply Int.finiteMultiplicity_iff.2 ⟨by simp [hp.out.ne_one], mod_cast hz⟩ · exact_mod_cast hz · exact_mod_cast hp.out.one_lt /-- The `p`-adic norm of an integer `m` is one iff `p` doesn't divide `m`. -/ theorem int_eq_one_iff (m : ℤ) : padicNorm p m = 1 ↔ ¬(p : ℤ) ∣ m := by nth_rw 2 [← pow_one p] simp only [dvd_iff_norm_le, Nat.cast_one, zpow_neg, zpow_one, not_le] constructor · intro h rw [h, inv_lt_one₀] <;> norm_cast · exact Nat.Prime.one_lt Fact.out · exact Nat.Prime.pos Fact.out · simp only [padicNorm] split_ifs · rw [inv_lt_zero, ← Nat.cast_zero, Nat.cast_lt] intro h exact (Nat.not_lt_zero p h).elim · have : 1 < (p : ℚ) := by norm_cast; exact Nat.Prime.one_lt (Fact.out : Nat.Prime p) rw [← zpow_neg_one, zpow_lt_zpow_iff_right₀ this] have : 0 ≤ padicValRat p m := by simp only [of_int, Nat.cast_nonneg] intro h rw [← zpow_zero (p : ℚ), zpow_right_inj₀] <;> linarith theorem int_lt_one_iff (m : ℤ) : padicNorm p m < 1 ↔ (p : ℤ) ∣ m := by rw [← not_iff_not, ← int_eq_one_iff, eq_iff_le_not_lt] simp only [padicNorm.of_int, true_and] theorem of_nat (m : ℕ) : padicNorm p m ≤ 1 := padicNorm.of_int (m : ℤ) /-- The `p`-adic norm of a natural `m` is one iff `p` doesn't divide `m`. -/ theorem nat_eq_one_iff (m : ℕ) : padicNorm p m = 1 ↔ ¬p ∣ m := by rw [← Int.natCast_dvd_natCast, ← int_eq_one_iff, Int.cast_natCast] theorem nat_lt_one_iff (m : ℕ) : padicNorm p m < 1 ↔ p ∣ m := by rw [← Int.natCast_dvd_natCast, ← int_lt_one_iff, Int.cast_natCast] /-- If a rational is not a p-adic integer, it is not an integer. -/ theorem not_int_of_not_padic_int (p : ℕ) {a : ℚ} [hp : Fact (Nat.Prime p)] (H : 1 < padicNorm p a) : ¬ a.isInt := by contrapose! H rw [Rat.eq_num_of_isInt H] apply padicNorm.of_int theorem sum_lt {α : Type*} {F : α → ℚ} {t : ℚ} {s : Finset α} : s.Nonempty → (∀ i ∈ s, padicNorm p (F i) < t) → padicNorm p (∑ i ∈ s, F i) < t := by classical refine s.induction_on (by rintro ⟨-, ⟨⟩⟩) ?_ rintro a S haS IH - ht by_cases hs : S.Nonempty · rw [Finset.sum_insert haS] exact lt_of_le_of_lt padicNorm.nonarchimedean (max_lt (ht a (Finset.mem_insert_self a S)) (IH hs fun b hb ↦ ht b (Finset.mem_insert_of_mem hb))) · simp_all theorem sum_le {α : Type*} {F : α → ℚ} {t : ℚ} {s : Finset α} : s.Nonempty → (∀ i ∈ s, padicNorm p (F i) ≤ t) → padicNorm p (∑ i ∈ s, F i) ≤ t := by classical refine s.induction_on (by rintro ⟨-, ⟨⟩⟩) ?_ rintro a S haS IH - ht by_cases hs : S.Nonempty · rw [Finset.sum_insert haS] exact padicNorm.nonarchimedean.trans (max_le (ht a (Finset.mem_insert_self a S)) (IH hs fun b hb ↦ ht b (Finset.mem_insert_of_mem hb))) · simp_all theorem sum_lt' {α : Type*} {F : α → ℚ} {t : ℚ} {s : Finset α} (hF : ∀ i ∈ s, padicNorm p (F i) < t) (ht : 0 < t) : padicNorm p (∑ i ∈ s, F i) < t := by obtain rfl | hs := Finset.eq_empty_or_nonempty s · simp [ht] · exact sum_lt hs hF theorem sum_le' {α : Type*} {F : α → ℚ} {t : ℚ} {s : Finset α} (hF : ∀ i ∈ s, padicNorm p (F i) ≤ t) (ht : 0 ≤ t) : padicNorm p (∑ i ∈ s, F i) ≤ t := by obtain rfl | hs := Finset.eq_empty_or_nonempty s · simp [ht] · exact sum_le hs hF end padicNorm
Different.lean
/- Copyright (c) 2025 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.NumberTheory.NumberField.Discriminant.Defs import Mathlib.RingTheory.DedekindDomain.Factorization import Mathlib.RingTheory.DedekindDomain.Different import Mathlib.RingTheory.Ideal.Norm.AbsNorm import Mathlib.Tactic.Qify /-! # (Absolute) Discriminant and Different Ideal ## Main results - `NumberField.absNorm_differentIdeal`: The norm of `differentIdeal ℤ 𝒪` is the absolute discriminant. -/ variable {K 𝒪 : Type*} [Field K] [NumberField K] [CommRing 𝒪] [Algebra 𝒪 K] variable [IsFractionRing 𝒪 K] [IsIntegralClosure 𝒪 ℤ K] [IsDedekindDomain 𝒪] [CharZero 𝒪] variable [Module.Finite ℤ 𝒪] open nonZeroDivisors lemma NumberField.absNorm_differentIdeal : (differentIdeal ℤ 𝒪).absNorm = (discr K).natAbs := by refine (differentIdeal ℤ 𝒪).toAddSubgroup.relindex_top_right.symm.trans ?_ rw [← Submodule.comap_map_eq_of_injective (f := Algebra.linearMap 𝒪 K) (FaithfulSMul.algebraMap_injective 𝒪 K) (differentIdeal ℤ 𝒪)] refine (AddSubgroup.relindex_comap (IsLocalization.coeSubmodule K (differentIdeal ℤ 𝒪)).toAddSubgroup (algebraMap 𝒪 K).toAddMonoidHom ⊤).trans ?_ have := FractionalIdeal.quotientEquiv (R := 𝒪) (K := K) 1 (differentIdeal ℤ 𝒪) (differentIdeal ℤ 𝒪)⁻¹ 1 (by simp [differentIdeal_ne_bot]) FractionalIdeal.coeIdeal_le_one (le_inv_of_le_inv₀ (by simp [pos_iff_ne_zero, differentIdeal_ne_bot]) (by simpa using FractionalIdeal.coeIdeal_le_one)) one_ne_zero one_ne_zero have := Nat.card_congr this.toEquiv refine this.trans ?_ rw [FractionalIdeal.coe_one, coeIdeal_differentIdeal (K := ℚ), inv_inv] let b := integralBasis K let b' := (Algebra.traceForm ℚ K).dualBasis (traceForm_nondegenerate ℚ K) b have hb : Submodule.span ℤ (Set.range b) = (1 : Submodule 𝒪 K).restrictScalars ℤ := by ext let e := IsIntegralClosure.equiv ℤ (RingOfIntegers K) K 𝒪 simpa [e.symm.exists_congr_left, e] using mem_span_integralBasis K qify refine (AddSubgroup.relindex_eq_abs_det (1 : Submodule 𝒪 K).toAddSubgroup (FractionalIdeal.dual ℤ ℚ 1 : FractionalIdeal 𝒪⁰ K).coeToSubmodule.toAddSubgroup ?_ b b' ?_ ?_).trans ?_ · rw [Submodule.toAddSubgroup_le, ← FractionalIdeal.coe_one] exact FractionalIdeal.one_le_dual_one ℤ ℚ (L := K) (B := 𝒪) · apply AddSubgroup.toIntSubmodule.injective rw [AddSubgroup.toIntSubmodule_closure, hb, Submodule.toIntSubmodule_toAddSubgroup] · apply AddSubgroup.toIntSubmodule.injective rw [AddSubgroup.toIntSubmodule_closure, ← LinearMap.BilinForm.dualSubmodule_span_of_basis, hb] simp · simp only [Module.Basis.det_apply, discr, Algebra.discr] rw [← eq_intCast (algebraMap ℤ ℚ), RingHom.map_det] congr! 2 ext i j simp [b', Module.Basis.toMatrix_apply, mul_comm (RingOfIntegers.basis K i), b, integralBasis_apply, ← map_mul, Algebra.trace_localization ℤ ℤ⁰] lemma NumberField.discr_mem_differentIdeal : ↑(discr K) ∈ differentIdeal ℤ 𝒪 := by have := (differentIdeal ℤ 𝒪).absNorm_mem cases (discr K).natAbs_eq with | inl h => rwa [absNorm_differentIdeal (K := K), ← Int.cast_natCast, ← h] at this | inr h => rwa [absNorm_differentIdeal (K := K), ← Int.cast_natCast, Int.eq_neg_comm.mp h, Int.cast_neg, neg_mem_iff] at this
qpoly.v
From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice. From mathcomp Require Import fintype tuple bigop binomial finset finfun ssralg. From mathcomp Require Import countalg finalg poly polydiv perm fingroup matrix. From mathcomp Require Import mxalgebra mxpoly vector countalg. (******************************************************************************) (* This file defines the algebras R[X]/<p> and their theory. *) (* It mimics the zmod file for polynomials *) (* First, it defines polynomials of bounded size (equivalent of 'I_n), *) (* gives it a structure of choice, finite and countable ring, ..., and *) (* lmodule, when possible. *) (* Internally, the construction uses poly_rV and rVpoly, but they should not *) (* be exposed. *) (* We provide two bases: the 'X^i and the lagrange polynomials. *) (* {poly_n R} == the type of polynomial of size at most n *) (* irreducibleb p == boolean decision procedure for irreducibility *) (* of a bounded size polynomial over a finite idomain *) (* Considering {poly_n F} over a field F, it is a vectType and *) (* 'nX^i == 'X^i as an element of {poly_n R} *) (* polynX == [tuple 'X^0, ..., 'X^(n - 1)], basis of {poly_n R} *) (* x.-lagrange == lagrange basis of {poly_n R} wrt x : nat -> F *) (* x.-lagrange_ i == the ith lagrange polynomial wrt the sampling points x *) (* Second, it defines polynomials quotiented by a poly (equivalent of 'Z_p), *) (* as bounded polynomial. As we are aiming to build a ring structure we need *) (* the polynomial to be monic and of size greater than one. If it is not the *) (* case we quotient by 'X *) (* mk_monic p == the actual polynomial on which we quotient *) (* if p is monic and of size > 1 it is p otherwise 'X *) (* {poly %/ p} == defined as {poly_(size (mk_poly p)).-1 R} on which *) (* there is a ring structure *) (* in_qpoly q == turn the polynomial q into an element of {poly %/ p} by *) (* taking a modulo *) (* 'qX == in_qpoly 'X *) (* The last part that defines the field structure when the quotient is an *) (* irreducible polynomial is defined in field/qfpoly *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory. Import Pdiv.CommonRing. Import Pdiv.RingMonic. Import Pdiv.Field. Import FinRing.Theory. Local Open Scope ring_scope. Reserved Notation "'{poly_' n R }" (n at level 2, format "'{poly_' n R }"). Reserved Notation "''nX^' i" (at level 1, format "''nX^' i"). Reserved Notation "x .-lagrange" (format "x .-lagrange"). Reserved Notation "x .-lagrange_" (format "x .-lagrange_"). Reserved Notation "'qX". Reserved Notation "{ 'poly' '%/' p }" (p at level 2, format "{ 'poly' '%/' p }"). Section poly_of_size_zmod. Context {R : nzRingType}. Implicit Types (n : nat). Section poly_of_size. Variable (n : nat). Definition poly_of_size_pred := fun p : {poly R} => size p <= n. Arguments poly_of_size_pred _ /. Definition poly_of_size := [qualify a p | poly_of_size_pred p]. Lemma npoly_submod_closed : submod_closed poly_of_size. Proof. split=> [|x p q sp sq]; rewrite qualifE/= ?size_polyC ?eqxx//. rewrite (leq_trans (size_polyD _ _)) // geq_max. by rewrite (leq_trans (size_scale_leq _ _)). Qed. HB.instance Definition _ := GRing.isSubmodClosed.Build R {poly R} poly_of_size_pred npoly_submod_closed. End poly_of_size. Arguments poly_of_size_pred _ _ /. Section npoly. Variable (n : nat). Record npoly : predArgType := NPoly { polyn :> {poly R}; _ : polyn \is a poly_of_size n }. HB.instance Definition _ := [isSub for @polyn]. Lemma npoly_is_a_poly_of_size (p : npoly) : val p \is a poly_of_size n. Proof. by case: p. Qed. Hint Resolve npoly_is_a_poly_of_size : core. Lemma size_npoly (p : npoly) : size p <= n. Proof. exact: npoly_is_a_poly_of_size. Qed. Hint Resolve size_npoly : core. HB.instance Definition _ := [Choice of npoly by <:]. HB.instance Definition _ := [SubChoice_isSubLmodule of npoly by <:]. Definition npoly_rV : npoly -> 'rV[R]_n := poly_rV \o val. Definition rVnpoly : 'rV[R]_n -> npoly := insubd (0 : npoly) \o rVpoly. Arguments rVnpoly /. Arguments npoly_rV /. Lemma npoly_rV_K : cancel npoly_rV rVnpoly. Proof. move=> p /=; apply/val_inj. by rewrite val_insubd [_ \is a _]size_poly ?poly_rV_K. Qed. Lemma rVnpolyK : cancel rVnpoly npoly_rV. Proof. by move=> p /=; rewrite val_insubd [_ \is a _]size_poly rVpolyK. Qed. Hint Resolve npoly_rV_K rVnpolyK : core. Lemma npoly_vect_axiom : Vector.axiom n npoly. Proof. by exists npoly_rV; [exact:linearPZ | exists rVnpoly]. Qed. HB.instance Definition _ := Lmodule_hasFinDim.Build R npoly npoly_vect_axiom. End npoly. End poly_of_size_zmod. Arguments npoly {R}%_type n%_N. Notation "'{poly_' n R }" := (@npoly R n) : type_scope. #[global] Hint Resolve size_npoly npoly_is_a_poly_of_size : core. Arguments poly_of_size_pred _ _ _ /. Arguments npoly : clear implicits. HB.instance Definition _ (R : countNzRingType) n := [Countable of {poly_n R} by <:]. HB.instance Definition _ (R : finNzRingType) n : isFinite {poly_n R} := CanIsFinite (@npoly_rV_K R n). Section npoly_theory. Context (R : nzRingType) {n : nat}. Lemma polyn_is_linear : linear (@polyn _ _ : {poly_n R} -> _). Proof. by []. Qed. HB.instance Definition _ := GRing.isSemilinear.Build R {poly_n R} {poly R} _ (polyn (n:=n)) (GRing.semilinear_linear polyn_is_linear). Canonical mk_npoly (E : nat -> R) : {poly_n R} := @NPoly R _ (\poly_(i < n) E i) (size_poly _ _). Fact size_npoly0 : size (0 : {poly R}) <= n. Proof. by rewrite size_poly0. Qed. Definition npoly0 := NPoly (size_npoly0). Fact npolyp_key : unit. Proof. exact: tt. Qed. Definition npolyp : {poly R} -> {poly_n R} := locked_with npolyp_key (mk_npoly \o (nth 0)). Definition npoly_of_seq := npolyp \o Poly. Lemma npolyP (p q : {poly_n R}) : nth 0 p =1 nth 0 q <-> p = q. Proof. by split => [/polyP/val_inj|->]. Qed. Lemma coef_npolyp (p : {poly R}) i : (npolyp p)`_i = if i < n then p`_i else 0. Proof. by rewrite /npolyp unlock /= coef_poly. Qed. Lemma big_coef_npoly (p : {poly_n R}) i : n <= i -> p`_i = 0. Proof. by move=> i_big; rewrite nth_default // (leq_trans _ i_big) ?size_npoly. Qed. Lemma npolypK (p : {poly R}) : size p <= n -> npolyp p = p :> {poly R}. Proof. move=> spn; apply/polyP=> i; rewrite coef_npolyp. by have [i_big|i_small] // := ltnP; rewrite nth_default ?(leq_trans spn). Qed. Lemma coefn_sum (I : Type) (r : seq I) (P : pred I) (F : I -> {poly_n R}) (k : nat) : (\sum_(i <- r | P i) F i)`_k = \sum_(i <- r | P i) (F i)`_k. Proof. by rewrite !raddf_sum //= coef_sum. Qed. End npoly_theory. Arguments mk_npoly {R} n E. Arguments npolyp {R} n p. Section fin_npoly. Variable R : finNzRingType. Variable n : nat. Implicit Types p q : {poly_n R}. Definition npoly_enum : seq {poly_n R} := if n isn't n.+1 then [:: npoly0 _] else pmap insub [seq \poly_(i < n.+1) c (inord i) | c : (R ^ n.+1)%type]. Lemma npoly_enum_uniq : uniq npoly_enum. Proof. rewrite /npoly_enum; case: n=> [|k] //. rewrite pmap_sub_uniq // map_inj_uniq => [|f g eqfg]; rewrite ?enum_uniq //. apply/ffunP => /= i; have /(congr1 (fun p : {poly _} => p`_i)) := eqfg. by rewrite !coef_poly ltn_ord inord_val. Qed. Lemma mem_npoly_enum p : p \in npoly_enum. Proof. rewrite /npoly_enum; case: n => [|k] // in p *. case: p => [p sp] /=. by rewrite in_cons -val_eqE /= -size_poly_leq0 [size _ <= _]sp. rewrite mem_pmap_sub; apply/mapP. eexists [ffun i : 'I__ => p`_i]; first by rewrite mem_enum. apply/polyP => i; rewrite coef_poly. have [i_small|i_big] := ltnP; first by rewrite ffunE /= inordK. by rewrite nth_default // 1?(leq_trans _ i_big) // size_npoly. Qed. Lemma card_npoly : #|{poly_n R}| = (#|R| ^ n)%N. Proof. rewrite -(card_imset _ (can_inj (@npoly_rV_K _ _))) eq_cardT. by rewrite -cardT /= card_mx mul1n. by move=> v; apply/imsetP; exists (rVnpoly v); rewrite ?rVnpolyK //. Qed. End fin_npoly. Section Irreducible. Variable R : finIdomainType. Variable p : {poly R}. Definition irreducibleb := ((1 < size p) && [forall q : {poly_((size p).-1) R}, (Pdiv.Ring.rdvdp q p)%R ==> (size q <= 1)])%N. Lemma irreducibleP : reflect (irreducible_poly p) irreducibleb. Proof. rewrite /irreducibleb /irreducible_poly. apply: (iffP idP) => [/andP[sp /'forall_implyP /= Fp]|[sp Fpoly]]. have sp_gt0 : size p > 0 by case: size sp. have p_neq0 : p != 0 by rewrite -size_poly_eq0; case: size sp. split => // q sq_neq1 dvd_qp; rewrite -dvdp_size_eqp // eqn_leq dvdp_leq //=. apply: contraNT sq_neq1; rewrite -ltnNge => sq_lt_sp. have q_small: (size q <= (size p).-1)%N by rewrite -ltnS prednK. rewrite Pdiv.Idomain.dvdpE in dvd_qp. have /= := Fp (NPoly q_small) dvd_qp. rewrite leq_eqVlt ltnS => /orP[//|]; rewrite size_poly_leq0 => /eqP q_eq0. by rewrite -Pdiv.Idomain.dvdpE q_eq0 dvd0p (negPf p_neq0) in dvd_qp. have sp_gt0 : size p > 0 by case: size sp. rewrite sp /=; apply/'forall_implyP => /= q. rewrite -Pdiv.Idomain.dvdpE=> dvd_qp. have [/eqP->//|/Fpoly/(_ dvd_qp)/eqp_size sq_eq_sp] := boolP (size q == 1%N). by have := size_npoly q; rewrite sq_eq_sp -ltnS prednK ?ltnn. Qed. End Irreducible. Section Vspace. Variable (K : fieldType) (n : nat). Lemma dim_polyn : \dim (fullv : {vspace {poly_n K}}) = n. Proof. by rewrite [LHS]mxrank_gen mxrank1. Qed. Definition npolyX : n.-tuple {poly_n K} := [tuple npolyp n 'X^i | i < n]. Notation "''nX^' i" := (tnth npolyX i). Lemma npolyXE (i : 'I_n) : 'nX^i = 'X^i :> {poly _}. Proof. by rewrite tnth_map tnth_ord_tuple npolypK // size_polyXn. Qed. Lemma nth_npolyX (i : 'I_n) : npolyX`_i = 'nX^i. Proof. by rewrite -tnth_nth. Qed. Lemma npolyX_free : free npolyX. Proof. apply/freeP=> u /= sum_uX_eq0 i; have /npolyP /(_ i) := sum_uX_eq0. rewrite (@big_morph _ _ _ 0%R +%R) // coef_sum coef0. rewrite (bigD1 i) ?big1 /= ?addr0 ?coefZ ?(nth_map 0%N) ?size_iota //. by rewrite nth_npolyX npolyXE coefXn eqxx mulr1. move=> j; rewrite -val_eqE /= => neq_ji. by rewrite nth_npolyX npolyXE coefZ coefXn eq_sym (negPf neq_ji) mulr0. Qed. Lemma npolyX_full : basis_of fullv npolyX. Proof. by rewrite basisEfree npolyX_free subvf size_map size_enum_ord dim_polyn /=. Qed. Lemma npolyX_coords (p : {poly_n K}) i : coord npolyX i p = p`_i. Proof. rewrite [p in RHS](coord_basis npolyX_full) ?memvf // coefn_sum. rewrite (bigD1 i) //= coefZ nth_npolyX npolyXE coefXn eqxx mulr1 big1 ?addr0//. move=> j; rewrite -val_eqE => /= neq_ji. by rewrite coefZ nth_npolyX npolyXE coefXn eq_sym (negPf neq_ji) mulr0. Qed. Lemma npolyX_gen (p : {poly K}) : (size p <= n)%N -> p = \sum_(i < n) p`_i *: 'nX^i. Proof. move=> sp; rewrite -[p](@npolypK _ n) //. rewrite [npolyp _ _ in LHS](coord_basis npolyX_full) ?memvf //. rewrite (@big_morph _ _ _ 0%R +%R) // !raddf_sum. by apply: eq_bigr=> i _; rewrite npolyX_coords //= nth_npolyX npolyXE. Qed. Section lagrange. Variables (x : nat -> K). Notation lagrange_def := (fun i :'I_n => let k := i in let p := \prod_(j < n | j != k) ('X - (x j)%:P) in (p.[x k]^-1)%:P * p). Fact lagrange_key : unit. Proof. exact: tt. Qed. Definition lagrange := locked_with lagrange_key [tuple npolyp n (lagrange_def i) | i < n]. Notation lagrange_ := (tnth lagrange). Hypothesis n_gt0 : (0 < n)%N. Hypothesis x_inj : injective x. Let lagrange_def_sample (i j : 'I_n) : (lagrange_def i).[x j] = (i == j)%:R. Proof. clear n_gt0; rewrite hornerM hornerC; set p := (\prod_(_ < _ | _) _). have [<-|neq_ij] /= := altP eqP. rewrite mulVf // horner_prod; apply/prodf_neq0 => k neq_ki. by rewrite hornerXsubC subr_eq0 inj_eq // eq_sym. rewrite [X in _ * X]horner_prod (bigD1 j) 1?eq_sym //=. by rewrite hornerXsubC subrr mul0r mulr0. Qed. Let size_lagrange_def i : size (lagrange_def i) = n. Proof. rewrite size_Cmul; last first. suff : (lagrange_def i).[x i] != 0. by rewrite hornerE mulf_eq0 => /norP []. by rewrite lagrange_def_sample ?eqxx ?oner_eq0. rewrite size_prod /=; last first. by move=> j neq_ji; rewrite polyXsubC_eq0. rewrite (eq_bigr (fun=> (2 * 1)%N)); last first. by move=> j neq_ji; rewrite size_XsubC. rewrite -big_distrr /= sum1_card cardC1 card_ord /=. by case: (n) {i} n_gt0 => ?; rewrite mul2n -addnn -addSn addnK. Qed. Lemma lagrangeE i : lagrange_ i = lagrange_def i :> {poly _}. Proof. rewrite [lagrange]unlock tnth_map. by rewrite [val _]npolypK tnth_ord_tuple // size_lagrange_def. Qed. Lemma nth_lagrange (i : 'I_n) : lagrange`_i = lagrange_ i. Proof. by rewrite -tnth_nth. Qed. Lemma size_lagrange_ i : size (lagrange_ i) = n. Proof. by rewrite lagrangeE size_lagrange_def. Qed. Lemma size_lagrange : size lagrange = n. Proof. by rewrite size_tuple. Qed. Lemma lagrange_sample (i j : 'I_n) : (lagrange_ i).[x j] = (i == j)%:R. Proof. by rewrite lagrangeE lagrange_def_sample. Qed. Lemma lagrange_free : free lagrange. Proof. apply/freeP=> lambda eq_l i. have /(congr1 (fun p : {poly__ _} => p.[x i])) := eq_l. rewrite (@big_morph _ _ _ 0%R +%R) // horner_sum horner0. rewrite (bigD1 i) // big1 => [|j /= /negPf ji] /=; by rewrite ?hornerE nth_lagrange lagrange_sample ?eqxx ?ji ?mulr1 ?mulr0. Qed. Lemma lagrange_full : basis_of fullv lagrange. Proof. by rewrite basisEfree lagrange_free subvf size_lagrange dim_polyn /=. Qed. Lemma lagrange_coords (p : {poly_n K}) i : coord lagrange i p = p.[x i]. Proof. rewrite [p in RHS](coord_basis lagrange_full) ?memvf //. rewrite (@big_morph _ _ _ 0%R +%R) // horner_sum. rewrite (bigD1 i) // big1 => [|j /= /negPf ji] /=; by rewrite ?hornerE nth_lagrange lagrange_sample ?eqxx ?ji ?mulr1 ?mulr0. Qed. Lemma lagrange_gen (p : {poly K}) : (size p <= n)%N -> p = \sum_(i < n) p.[x i]%:P * lagrange_ i. Proof. move=> sp; rewrite -[p](@npolypK _ n) //. rewrite [npolyp _ _ in LHS](coord_basis lagrange_full) ?memvf //. rewrite (@big_morph _ _ _ 0%R +%R) //; apply: eq_bigr=> i _. by rewrite lagrange_coords mul_polyC nth_lagrange. Qed. End lagrange. End Vspace. Notation "''nX^' i" := (tnth (npolyX _) i) : ring_scope. Notation "x .-lagrange" := (lagrange x) : ring_scope. Notation "x .-lagrange_" := (tnth x.-lagrange) : ring_scope. Section Qpoly. Variable R : nzRingType. Variable h : {poly R}. Definition mk_monic := if (1 < size h)%N && (h \is monic) then h else 'X. Definition qpoly := {poly_(size mk_monic).-1 R}. End Qpoly. Notation "{ 'poly' '%/' p }" := (qpoly p) : type_scope. Section QpolyProp. Variable R : nzRingType. Variable h : {poly R}. Lemma monic_mk_monic : (mk_monic h) \is monic. Proof. rewrite /mk_monic; case: leqP=> [_|/=]; first by apply: monicX. by case E : (h \is monic) => [->//|] => _; apply: monicX. Qed. Lemma size_mk_monic_gt1 : (1 < size (mk_monic h))%N. Proof. by rewrite !fun_if size_polyX; case: leqP => //=; rewrite if_same. Qed. Lemma size_mk_monic_gt0 : (0 < size (mk_monic h))%N. Proof. by rewrite (leq_trans _ size_mk_monic_gt1). Qed. Lemma mk_monic_neq0 : mk_monic h != 0. Proof. by rewrite -size_poly_gt0 size_mk_monic_gt0. Qed. Lemma size_mk_monic (p : {poly %/ h}) : size p < size (mk_monic h). Proof. have: (p : {poly R}) \is a poly_of_size (size (mk_monic h)).-1 by case: p. by rewrite qualifE/= -ltnS prednK // size_mk_monic_gt0. Qed. (* standard inject *) Lemma poly_of_size_mod p : rmodp p (mk_monic h) \is a poly_of_size (size (mk_monic h)).-1. Proof. rewrite qualifE/= -ltnS prednK ?size_mk_monic_gt0 //. by apply: ltn_rmodpN0; rewrite mk_monic_neq0. Qed. Definition in_qpoly p : {poly %/ h} := NPoly (poly_of_size_mod p). Lemma in_qpoly_small (p : {poly R}) : size p < size (mk_monic h) -> in_qpoly p = p :> {poly R}. Proof. exact: rmodp_small. Qed. Lemma in_qpoly0 : in_qpoly 0 = 0. Proof. by apply/val_eqP; rewrite /= rmod0p. Qed. Lemma in_qpolyD p q : in_qpoly (p + q) = in_qpoly p + in_qpoly q. Proof. by apply/val_eqP=> /=; rewrite rmodpD ?monic_mk_monic. Qed. Lemma in_qpolyZ a p : in_qpoly (a *: p) = a *: in_qpoly p. Proof. apply/val_eqP=> /=; rewrite rmodpZ ?monic_mk_monic //. Qed. Fact in_qpoly_is_linear : linear in_qpoly. Proof. by move=> k p q; rewrite in_qpolyD in_qpolyZ. Qed. HB.instance Definition _ := GRing.isSemilinear.Build R {poly R} {poly_(size (mk_monic h)).-1 R} _ in_qpoly (GRing.semilinear_linear in_qpoly_is_linear). Lemma qpolyC_proof k : (k%:P : {poly R}) \is a poly_of_size (size (mk_monic h)).-1. Proof. rewrite qualifE/= -ltnS size_polyC prednK ?size_mk_monic_gt0 //. by rewrite (leq_ltn_trans _ size_mk_monic_gt1) //; case: eqP. Qed. Definition qpolyC k : {poly %/ h} := NPoly (qpolyC_proof k). Lemma qpolyCE k : qpolyC k = k%:P :> {poly R}. Proof. by []. Qed. Lemma qpolyC0 : qpolyC 0 = 0. Proof. by apply/val_eqP/eqP. Qed. Definition qpoly1 := qpolyC 1. Definition qpoly_mul (q1 q2 : {poly %/ h}) : {poly %/ h} := in_qpoly ((q1 : {poly R}) * q2). Lemma qpoly_mul1z : left_id qpoly1 qpoly_mul. Proof. by move=> x; apply: val_inj; rewrite /= mul1r rmodp_small // size_mk_monic. Qed. Lemma qpoly_mulz1 : right_id qpoly1 qpoly_mul. Proof. by move=> x; apply: val_inj; rewrite /= mulr1 rmodp_small // size_mk_monic. Qed. Lemma qpoly_nontrivial : qpoly1 != 0. Proof. by apply/eqP/val_eqP; rewrite /= oner_eq0. Qed. Definition qpolyX := in_qpoly 'X. Notation "'qX" := qpolyX. Lemma qpolyXE : 2 < size h -> h \is monic -> 'qX = 'X :> {poly R}. Proof. move=> sh_gt2 h_mo. by rewrite in_qpoly_small // size_polyX /mk_monic ifT // (ltn_trans _ sh_gt2). Qed. End QpolyProp. Notation "'qX" := (qpolyX _) : ring_scope. Lemma mk_monic_X (R : nzRingType) : mk_monic 'X = 'X :> {poly R}. Proof. by rewrite /mk_monic size_polyX monicX. Qed. Lemma mk_monic_Xn (R : nzRingType) n : mk_monic 'X^n = 'X^(n.-1.+1) :> {poly R}. Proof. by case: n => [|n]; rewrite /mk_monic size_polyXn monicXn /= ?expr1. Qed. Lemma card_qpoly (R : finNzRingType) (h : {poly R}): #|{poly %/ h}| = #|R| ^ (size (mk_monic h)).-1. Proof. by rewrite card_npoly. Qed. Lemma card_monic_qpoly (R : finNzRingType) (h : {poly R}): 1 < size h -> h \is monic -> #|{poly %/ h}| = #|R| ^ (size h).-1. Proof. by move=> sh_gt1 hM; rewrite card_qpoly /mk_monic sh_gt1 hM. Qed. Section QRing. Variable A : comNzRingType. Variable h : {poly A}. (* Ring operations *) Lemma qpoly_mulC : commutative (@qpoly_mul A h). Proof. by move=> p q; apply: val_inj; rewrite /= mulrC. Qed. Lemma qpoly_mulA : associative (@qpoly_mul A h). Proof. have rPM := monic_mk_monic h; move=> p q r; apply: val_inj. by rewrite /= rmodp_mulml // rmodp_mulmr // mulrA. Qed. Lemma qpoly_mul_addr : right_distributive (@qpoly_mul A h) +%R. Proof. have rPM := monic_mk_monic h; move=> p q r; apply: val_inj. by rewrite /= !(mulrDr, rmodp_mulmr, rmodpD). Qed. Lemma qpoly_mul_addl : left_distributive (@qpoly_mul A h) +%R. Proof. by move=> p q r; rewrite -!(qpoly_mulC r) qpoly_mul_addr. Qed. HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build {poly__ A} qpoly_mulA qpoly_mulC (@qpoly_mul1z _ h) qpoly_mul_addl (@qpoly_nontrivial _ h). HB.instance Definition _ := GRing.ComNzRing.on {poly %/ h}. Lemma in_qpoly1 : in_qpoly h 1 = 1. Proof. apply/val_eqP/eqP/in_qpoly_small. by rewrite size_polyC oner_eq0 /= size_mk_monic_gt1. Qed. Lemma in_qpolyM q1 q2 : in_qpoly h (q1 * q2) = in_qpoly h q1 * in_qpoly h q2. Proof. apply/val_eqP => /=. by rewrite rmodp_mulml ?rmodp_mulmr // monic_mk_monic. Qed. Fact in_qpoly_monoid_morphism : monoid_morphism (in_qpoly h). Proof. by split; [ apply: in_qpoly1 | apply: in_qpolyM]. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `in_qpoly_is_monoid_morphism` instead")] Definition in_qpoly_is_multiplicative := (fun g => (g.2,g.1)) in_qpoly_monoid_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build {poly A} {poly %/ h} (in_qpoly h) in_qpoly_monoid_morphism. Lemma poly_of_qpoly_sum I (r : seq I) (P1 : pred I) (F : I -> {poly %/ h}) : ((\sum_(i <- r | P1 i) F i) = \sum_(p <- r | P1 p) ((F p) : {poly A}) :> {poly A})%R. Proof. by elim/big_rec2: _ => // i p q IH <-. Qed. Lemma poly_of_qpolyD (p q : {poly %/ h}) : p + q= (p : {poly A}) + q :> {poly A}. Proof. by []. Qed. Lemma qpolyC_natr p : (p%:R : {poly %/ h}) = p%:R :> {poly A}. Proof. by elim: p => //= p IH; rewrite !mulrS poly_of_qpolyD IH. Qed. Lemma pchar_qpoly : [pchar {poly %/ h}] =i [pchar A]. Proof. move=> p; rewrite !inE; congr (_ && _). apply/eqP/eqP=> [/(congr1 val) /=|pE]; last first. by apply: val_inj => //=; rewrite qpolyC_natr /= -polyC_natr pE. rewrite !qpolyC_natr -!polyC_natr => /(congr1 val) /=. by rewrite polyseqC polyseq0; case: eqP. Qed. Lemma poly_of_qpolyM (p q : {poly %/ h}) : p * q = rmodp ((p : {poly A}) * q) (mk_monic h) :> {poly A}. Proof. by []. Qed. Lemma poly_of_qpolyX (p : {poly %/ h}) n : p ^+ n = rmodp ((p : {poly A}) ^+ n) (mk_monic h) :> {poly A}. Proof. have HhQ := monic_mk_monic h. elim: n => //= [|n IH]. rewrite rmodp_small // size_polyC ?(leq_ltn_trans _ (size_mk_monic_gt1 _)) //. by case: eqP. by rewrite exprS /= IH // rmodp_mulmr // -exprS. Qed. Lemma qpolyCN (a : A) : qpolyC h (- a) = -(qpolyC h a). Proof. apply: val_inj; rewrite /= raddfN //= raddfN. Qed. Lemma qpolyCD : {morph (qpolyC h) : a b / a + b >-> a + b}%R. Proof. by move=> a b; apply/val_eqP/eqP=> /=; rewrite -!raddfD. Qed. Lemma qpolyCM : {morph (qpolyC h) : a b / a * b >-> a * b}%R. Proof. move=> a b; apply/val_eqP/eqP=> /=; rewrite -polyCM rmodp_small //=. have := qpolyC_proof h (a * b). by rewrite qualifE/= -ltnS prednK // size_mk_monic_gt0. Qed. Lemma qpolyC_is_zmod_morphism : zmod_morphism (qpolyC h). Proof. by move=> x y; rewrite qpolyCD qpolyCN. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `qpolyC_is_zmod_morphism` instead")] Definition qpolyC_is_additive := qpolyC_is_zmod_morphism. Lemma qpolyC_is_monoid_morphism : monoid_morphism (qpolyC h). Proof. by split=> // x y; rewrite qpolyCM. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `qpolyC_is_monoid_morphism` instead")] Definition qpolyC_is_multiplicative := (fun g => (g.2,g.1)) qpolyC_is_monoid_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build A {poly %/ h} (qpolyC h) qpolyC_is_zmod_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build A {poly %/ h} (qpolyC h) qpolyC_is_monoid_morphism. Definition qpoly_scale k (p : {poly %/ h}) : {poly %/ h} := (k *: p)%R. Fact qpoly_scaleA a b p : qpoly_scale a (qpoly_scale b p) = qpoly_scale (a * b) p. Proof. by apply/val_eqP; rewrite /= scalerA. Qed. Fact qpoly_scale1l : left_id 1%R qpoly_scale. Proof. by move=> p; apply/val_eqP; rewrite /= scale1r. Qed. Fact qpoly_scaleDr a : {morph qpoly_scale a : p q / (p + q)%R}. Proof. by move=> p q; apply/val_eqP; rewrite /= scalerDr. Qed. Fact qpoly_scaleDl p : {morph qpoly_scale^~ p : a b / a + b}%R. Proof. by move=> a b; apply/val_eqP; rewrite /= scalerDl. Qed. Fact qpoly_scaleAl a p q : qpoly_scale a (p * q) = (qpoly_scale a p * q). Proof. by apply/val_eqP; rewrite /= -scalerAl rmodpZ // monic_mk_monic. Qed. Fact qpoly_scaleAr a p q : qpoly_scale a (p * q) = p * (qpoly_scale a q). Proof. by apply/val_eqP; rewrite /= -scalerAr rmodpZ // monic_mk_monic. Qed. HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build A {poly__ A} qpoly_scaleAl. HB.instance Definition _ := GRing.Lalgebra.on {poly %/ h}. HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build A {poly__ A} qpoly_scaleAr. HB.instance Definition _ := GRing.Algebra.on {poly %/ h}. Lemma poly_of_qpolyZ (p : {poly %/ h}) a : a *: p = a *: (p : {poly A}) :> {poly A}. Proof. by []. Qed. End QRing. #[deprecated(since="mathcomp 2.4.0", note="Use pchar_qpoly instead.")] Notation char_qpoly := (pchar_qpoly) (only parsing). Section Field. Variable R : fieldType. Variable h : {poly R}. Local Notation hQ := (mk_monic h). Definition qpoly_inv (p : {poly %/ h}) := if coprimep hQ p then let v : {poly %/ h} := in_qpoly h (egcdp hQ p).2 in ((lead_coef (v * p)) ^-1 *: v) else p. (* Ugly *) Lemma qpoly_mulVz (p : {poly %/ h}) : coprimep hQ p -> (qpoly_inv p * p = 1)%R. Proof. have hQM := monic_mk_monic h. move=> hCp; apply: val_inj; rewrite /qpoly_inv /in_qpoly hCp /=. have p_neq0 : p != 0%R. apply/eqP=> pZ; move: hCp; rewrite pZ. rewrite coprimep0 -size_poly_eq1. by case: size (size_mk_monic_gt1 h) => [|[]]. have F : (egcdp hQ p).1 * hQ + (egcdp hQ p).2 * p %= 1. apply: eqp_trans _ (_ : gcdp hQ p %= _). rewrite eqp_sym. by case: (egcdpP (mk_monic_neq0 h) p_neq0). by rewrite -size_poly_eq1. rewrite rmodp_mulml // -scalerAl rmodpZ // rmodp_mulml //. rewrite -[rmodp]/Pdiv.Ring.rmodp -!Pdiv.IdomainMonic.modpE //. have := eqp_modpl hQ F. rewrite modpD // modp_mull add0r // . rewrite [(1 %% _)%R]modp_small => // [egcdE|]; last first. by rewrite size_polyC oner_eq0 size_mk_monic_gt1. rewrite {2}(eqpfP egcdE) lead_coefC divr1 alg_polyC scale_polyC mulVf //. rewrite lead_coef_eq0. apply/eqP => egcdZ. by move: egcdE; rewrite -size_poly_eq1 egcdZ size_polyC eq_sym eqxx. Qed. Lemma qpoly_mulzV (p : {poly %/ h}) : coprimep hQ p -> (p * (qpoly_inv p) = 1)%R. Proof. by move=> hCp; rewrite /= mulrC qpoly_mulVz. Qed. Lemma qpoly_intro_unit (p q : {poly %/ h}) : (q * p = 1)%R -> coprimep hQ p. Proof. have hQM := monic_mk_monic h. case; rewrite -[rmodp]/Pdiv.Ring.rmodp -!Pdiv.IdomainMonic.modpE // => qp1. have:= coprimep1 hQ. rewrite -coprimep_modr -[1%R]qp1 !coprimep_modr coprimepMr; by case/andP. Qed. Lemma qpoly_inv_out (p : {poly %/ h}) : ~~ coprimep hQ p -> qpoly_inv p = p. Proof. by rewrite /qpoly_inv => /negPf->. Qed. HB.instance Definition _ := GRing.ComNzRing_hasMulInverse.Build {poly__ _} qpoly_mulVz qpoly_intro_unit qpoly_inv_out. HB.instance Definition _ := GRing.ComUnitAlgebra.on {poly %/ h}. Lemma irreducible_poly_coprime (A : idomainType) (p q : {poly A}) : irreducible_poly p -> coprimep p q = ~~(p %| q)%R. Proof. case => H1 H2; apply/coprimepP/negP. move=> sPq H. by have := sPq p (dvdpp _) H; rewrite -size_poly_eq1; case: size H1 => [|[]]. move=> pNDq d dDp dPq. rewrite -size_poly_eq1; case: eqP => // /eqP /(H2 _) => /(_ dDp) dEp. by case: pNDq; rewrite -(eqp_dvdl _ dEp). Qed. End Field.
TotallyBounded.lean
/- Copyright (c) 2024 Christopher Hoskin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christopher Hoskin -/ import Mathlib.Topology.UniformSpace.Cauchy import Mathlib.Analysis.Convex.Hull import Mathlib.Topology.Algebra.IsUniformGroup.Basic import Mathlib.Topology.Algebra.Module.LocallyConvex /-! # Totally Bounded sets and Convex Hulls ## Main statements - `totallyBounded_convexHull` The convex hull of a totally bounded set is totally bounded. ## References * [Bourbaki, *Topological Vector Spaces*][bourbaki1987] ## Tags convex, totally bounded -/ open Set Pointwise variable (E : Type*) {s : Set E} variable [AddCommGroup E] [Module ℝ E] variable [UniformSpace E] [IsUniformAddGroup E] [lcs : LocallyConvexSpace ℝ E] [ContinuousSMul ℝ E] theorem totallyBounded_convexHull (hs : TotallyBounded s) : TotallyBounded (convexHull ℝ s) := by rw [totallyBounded_iff_subset_finite_iUnion_nhds_zero] intro U hU obtain ⟨W, hW₁, hW₂⟩ := exists_nhds_zero_half hU obtain ⟨V, ⟨hV₁, hV₂, hV₃⟩⟩ := (locallyConvexSpace_iff_exists_convex_subset_zero ℝ E).mp lcs W hW₁ obtain ⟨t, ⟨htf, hts⟩⟩ := (totallyBounded_iff_subset_finite_iUnion_nhds_zero.mp hs) _ hV₁ obtain ⟨t', ⟨htf', hts'⟩⟩ := (totallyBounded_iff_subset_finite_iUnion_nhds_zero.mp (IsCompact.totallyBounded (Finite.isCompact_convexHull htf)) _ hV₁) use t', htf' simp only [iUnion_vadd_set, vadd_eq_add] at hts hts' ⊢ calc convexHull ℝ s _ ⊆ convexHull ℝ (t + V) := convexHull_mono hts _ ⊆ convexHull ℝ t + convexHull ℝ V := convexHull_add_subset _ = convexHull ℝ t + V := by rw [hV₂.convexHull_eq] _ ⊆ t' + V + V := add_subset_add_right hts' _ = t' + (V + V) := by rw [add_assoc] _ ⊆ t' + (W + W) := add_subset_add_left (add_subset_add hV₃ hV₃) _ ⊆ t' + U := add_subset_add_left (add_subset_iff.mpr hW₂)
OfAdjunction.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.Adjunction.Opposites import Mathlib.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Localization.CalculusOfFractions /-! # The calculus of fractions deduced from an adjunction If `G ⊣ F` is an adjunction, `F` is fully faithful, and `W` is a class of morphisms that is inverted by `G` and such that the morphism `adj.unit.app X` belongs to `W` for any object `X`, then `G` is a localization functor with respect to `W`. Moreover, if `W` is multiplicative, then `W` has a calculus of left fractions. This holds in particular if `W` is the inverse image of the class of isomorphisms by `G`. (The dual statement is also obtained.) -/ namespace CategoryTheory open MorphismProperty namespace Adjunction variable {C₁ C₂ : Type*} [Category C₁] [Category C₂] {G : C₁ ⥤ C₂} {F : C₂ ⥤ C₁} lemma hasLeftCalculusOfFractions (adj : G ⊣ F) (W : MorphismProperty C₁) [W.IsMultiplicative] (hW : W.IsInvertedBy G) (hW' : (W.functorCategory C₁) adj.unit) : W.HasLeftCalculusOfFractions where exists_leftFraction X Y φ := by obtain ⟨T, s, _, f, rfl⟩ := φ.cases dsimp have := hW s (by assumption) exact ⟨{ f := adj.unit.app X ≫ F.map (inv (G.map s)) ≫ F.map (G.map f) s := adj.unit.app Y hs := hW' Y}, by have := adj.unit.naturality s dsimp at this ⊢ rw [reassoc_of% this, Functor.map_inv, IsIso.hom_inv_id_assoc, adj.unit_naturality]⟩ ext X' X Y f₁ f₂ s _ h := by have := hW s (by assumption) refine ⟨_, adj.unit.app Y, hW' _, ?_⟩ rw [← adj.unit_naturality f₁, ← adj.unit_naturality f₂] congr 2 rw [← cancel_epi (G.map s), ← G.map_comp, ← G.map_comp, h] lemma hasRightCalculusOfFractions (adj : F ⊣ G) (W : MorphismProperty C₁) [W.IsMultiplicative] (hW : W.IsInvertedBy G) (hW' : (W.functorCategory _) adj.counit) : W.HasRightCalculusOfFractions := have := hasLeftCalculusOfFractions adj.op W.op hW.op (fun _ ↦ hW' _) inferInstanceAs W.op.unop.HasRightCalculusOfFractions section variable [F.Full] [F.Faithful] lemma isLocalization_leftAdjoint (adj : G ⊣ F) (W : MorphismProperty C₁) (hW : W.IsInvertedBy G) (hW' : (W.functorCategory C₁) adj.unit) : G.IsLocalization W := by let Φ : W.Localization ⥤ C₂ := Localization.lift _ hW W.Q let e : W.Q ⋙ Φ ≅ G := by apply Localization.fac have : IsIso (Functor.whiskerRight adj.unit W.Q) := by rw [NatTrans.isIso_iff_isIso_app] intro X exact Localization.inverts W.Q W _ (hW' X) have : Localization.Lifting W.Q W (G ⋙ F ⋙ W.Q) (Φ ⋙ F ⋙ W.Q) := ⟨(Functor.associator _ _ _).symm ≪≫ Functor.isoWhiskerRight e _⟩ exact Functor.IsLocalization.of_equivalence_target W.Q W _ (Equivalence.mk Φ (F ⋙ W.Q) (Localization.liftNatIso W.Q W W.Q (G ⋙ F ⋙ W.Q) _ _ (W.Q.leftUnitor.symm ≪≫ asIso (Functor.whiskerRight adj.unit W.Q) ≪≫ Functor.associator _ _ _)) (Functor.associator _ _ _ ≪≫ Functor.isoWhiskerLeft _ e ≪≫ asIso adj.counit)) e lemma isLocalization_rightAdjoint (adj : F ⊣ G) (W : MorphismProperty C₁) (hW : W.IsInvertedBy G) (hW' : (W.functorCategory C₁) adj.counit) : G.IsLocalization W := by simpa using isLocalization_leftAdjoint adj.op W.op hW.op (fun X ↦ hW' X.unop) lemma functorCategory_inverseImage_isomorphisms_unit (adj : G ⊣ F) : ((isomorphisms C₂).inverseImage G).functorCategory C₁ adj.unit := by intro simp only [Functor.id_obj, Functor.comp_obj, inverseImage_iff, isomorphisms.iff] infer_instance lemma functorCategory_inverseImage_isomorphisms_counit (adj : F ⊣ G) : ((isomorphisms C₂).inverseImage G).functorCategory C₁ adj.counit := by intro simp only [Functor.id_obj, Functor.comp_obj, inverseImage_iff, isomorphisms.iff] infer_instance lemma isLocalization_leftAdjoint' (adj : G ⊣ F) : G.IsLocalization ((isomorphisms C₂).inverseImage G) := adj.isLocalization_leftAdjoint _ (fun _ _ _ h ↦ h) adj.functorCategory_inverseImage_isomorphisms_unit lemma isLocalization_rightAdjoint' (adj : F ⊣ G) : G.IsLocalization ((isomorphisms C₂).inverseImage G) := adj.isLocalization_rightAdjoint _ (fun _ _ _ h ↦ h) adj.functorCategory_inverseImage_isomorphisms_counit lemma hasLeftCalculusOfFractions' (adj : G ⊣ F) : ((isomorphisms C₂).inverseImage G).HasLeftCalculusOfFractions := hasLeftCalculusOfFractions adj _ (fun _ _ _ h ↦ h) adj.functorCategory_inverseImage_isomorphisms_unit lemma hasRightCalculusOfFractions' (adj : F ⊣ G) : ((isomorphisms C₂).inverseImage G).HasRightCalculusOfFractions := hasRightCalculusOfFractions adj _ (fun _ _ _ h ↦ h) adj.functorCategory_inverseImage_isomorphisms_counit end end Adjunction end CategoryTheory
all.v
From mathcomp Require Export all_boot. From mathcomp Require Export all_order. From mathcomp Require Export all_fingroup. From mathcomp Require Export all_algebra. From mathcomp Require Export all_solvable. From mathcomp Require Export all_field. From mathcomp Require Export all_character.
Images.lean
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Mono import Mathlib.CategoryTheory.Limits.Shapes.StrongEpi import Mathlib.CategoryTheory.MorphismProperty.Factorization /-! # Categorical images We define the categorical image of `f` as a factorisation `f = e ≫ m` through a monomorphism `m`, so that `m` factors through the `m'` in any other such factorisation. ## Main definitions * A `MonoFactorisation` is a factorisation `f = e ≫ m`, where `m` is a monomorphism * `IsImage F` means that a given mono factorisation `F` has the universal property of the image. * `HasImage f` means that there is some image factorization for the morphism `f : X ⟶ Y`. * In this case, `image f` is some image object (selected with choice), `image.ι f : image f ⟶ Y` is the monomorphism `m` of the factorisation and `factorThruImage f : X ⟶ image f` is the morphism `e`. * `HasImages C` means that every morphism in `C` has an image. * Let `f : X ⟶ Y` and `g : P ⟶ Q` be morphisms in `C`, which we will represent as objects of the arrow category `Arrow C`. Then `sq : f ⟶ g` is a commutative square in `C`. If `f` and `g` have images, then `HasImageMap sq` represents the fact that there is a morphism `i : image f ⟶ image g` making the diagram X ----→ image f ----→ Y | | | | | | ↓ ↓ ↓ P ----→ image g ----→ Q commute, where the top row is the image factorisation of `f`, the bottom row is the image factorisation of `g`, and the outer rectangle is the commutative square `sq`. * If a category `HasImages`, then `HasImageMaps` means that every commutative square admits an image map. * If a category `HasImages`, then `HasStrongEpiImages` means that the morphism to the image is always a strong epimorphism. ## Main statements * When `C` has equalizers, the morphism `e` appearing in an image factorisation is an epimorphism. * When `C` has strong epi images, then these images admit image maps. ## Future work * TODO: coimages, and abelian categories. * TODO: connect this with existing working in the group theory and ring theory libraries. -/ noncomputable section universe v u open CategoryTheory open CategoryTheory.Limits.WalkingParallelPair namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable {X Y : C} (f : X ⟶ Y) /-- A factorisation of a morphism `f = e ≫ m`, with `m` monic. -/ structure MonoFactorisation (f : X ⟶ Y) where I : C -- Porting note: violates naming conventions but can't think a better replacement m : I ⟶ Y [m_mono : Mono m] e : X ⟶ I fac : e ≫ m = f := by cat_disch attribute [inherit_doc MonoFactorisation] MonoFactorisation.I MonoFactorisation.m MonoFactorisation.m_mono MonoFactorisation.e MonoFactorisation.fac attribute [reassoc (attr := simp)] MonoFactorisation.fac attribute [instance] MonoFactorisation.m_mono namespace MonoFactorisation /-- The obvious factorisation of a monomorphism through itself. -/ def self [Mono f] : MonoFactorisation f where I := X m := f e := 𝟙 X -- I'm not sure we really need this, but the linter says that an inhabited instance -- ought to exist... instance [Mono f] : Inhabited (MonoFactorisation f) := ⟨self f⟩ variable {f} /-- The morphism `m` in a factorisation `f = e ≫ m` through a monomorphism is uniquely determined. -/ @[ext (iff := false)] theorem ext {F F' : MonoFactorisation f} (hI : F.I = F'.I) (hm : F.m = eqToHom hI ≫ F'.m) : F = F' := by obtain ⟨_, Fm, _, Ffac⟩ := F; obtain ⟨_, Fm', _, Ffac'⟩ := F' cases hI simp? at hm says simp only [eqToHom_refl, Category.id_comp] at hm congr apply (cancel_mono Fm).1 rw [Ffac, hm, Ffac'] /-- Any mono factorisation of `f` gives a mono factorisation of `f ≫ g` when `g` is a mono. -/ @[simps] def compMono (F : MonoFactorisation f) {Y' : C} (g : Y ⟶ Y') [Mono g] : MonoFactorisation (f ≫ g) where I := F.I m := F.m ≫ g m_mono := mono_comp _ _ e := F.e /-- A mono factorisation of `f ≫ g`, where `g` is an isomorphism, gives a mono factorisation of `f`. -/ @[simps] def ofCompIso {Y' : C} {g : Y ⟶ Y'} [IsIso g] (F : MonoFactorisation (f ≫ g)) : MonoFactorisation f where I := F.I m := F.m ≫ inv g m_mono := mono_comp _ _ e := F.e /-- Any mono factorisation of `f` gives a mono factorisation of `g ≫ f`. -/ @[simps] def isoComp (F : MonoFactorisation f) {X' : C} (g : X' ⟶ X) : MonoFactorisation (g ≫ f) where I := F.I m := F.m e := g ≫ F.e /-- A mono factorisation of `g ≫ f`, where `g` is an isomorphism, gives a mono factorisation of `f`. -/ @[simps] def ofIsoComp {X' : C} (g : X' ⟶ X) [IsIso g] (F : MonoFactorisation (g ≫ f)) : MonoFactorisation f where I := F.I m := F.m e := inv g ≫ F.e /-- If `f` and `g` are isomorphic arrows, then a mono factorisation of `f` gives a mono factorisation of `g` -/ @[simps] def ofArrowIso {f g : Arrow C} (F : MonoFactorisation f.hom) (sq : f ⟶ g) [IsIso sq] : MonoFactorisation g.hom where I := F.I m := F.m ≫ sq.right e := inv sq.left ≫ F.e m_mono := mono_comp _ _ fac := by simp only [fac_assoc, Arrow.w, IsIso.inv_comp_eq, Category.assoc] end MonoFactorisation variable {f} /-- Data exhibiting that a given factorisation through a mono is initial. -/ structure IsImage (F : MonoFactorisation f) where lift : ∀ F' : MonoFactorisation f, F.I ⟶ F'.I lift_fac : ∀ F' : MonoFactorisation f, lift F' ≫ F'.m = F.m := by cat_disch attribute [inherit_doc IsImage] IsImage.lift IsImage.lift_fac attribute [reassoc (attr := simp)] IsImage.lift_fac namespace IsImage @[reassoc (attr := simp)] theorem fac_lift {F : MonoFactorisation f} (hF : IsImage F) (F' : MonoFactorisation f) : F.e ≫ hF.lift F' = F'.e := (cancel_mono F'.m).1 <| by simp variable (f) /-- The trivial factorisation of a monomorphism satisfies the universal property. -/ @[simps] def self [Mono f] : IsImage (MonoFactorisation.self f) where lift F' := F'.e instance [Mono f] : Inhabited (IsImage (MonoFactorisation.self f)) := ⟨self f⟩ variable {f} -- TODO this is another good candidate for a future `UniqueUpToCanonicalIso`. /-- Two factorisations through monomorphisms satisfying the universal property must factor through isomorphic objects. -/ @[simps] def isoExt {F F' : MonoFactorisation f} (hF : IsImage F) (hF' : IsImage F') : F.I ≅ F'.I where hom := hF.lift F' inv := hF'.lift F hom_inv_id := (cancel_mono F.m).1 (by simp) inv_hom_id := (cancel_mono F'.m).1 (by simp) variable {F F' : MonoFactorisation f} (hF : IsImage F) (hF' : IsImage F') theorem isoExt_hom_m : (isoExt hF hF').hom ≫ F'.m = F.m := by simp theorem isoExt_inv_m : (isoExt hF hF').inv ≫ F.m = F'.m := by simp theorem e_isoExt_hom : F.e ≫ (isoExt hF hF').hom = F'.e := by simp theorem e_isoExt_inv : F'.e ≫ (isoExt hF hF').inv = F.e := by simp /-- If `f` and `g` are isomorphic arrows, then a mono factorisation of `f` that is an image gives a mono factorisation of `g` that is an image -/ @[simps] def ofArrowIso {f g : Arrow C} {F : MonoFactorisation f.hom} (hF : IsImage F) (sq : f ⟶ g) [IsIso sq] : IsImage (F.ofArrowIso sq) where lift F' := hF.lift (F'.ofArrowIso (inv sq)) lift_fac F' := by simpa only [MonoFactorisation.ofArrowIso_m, Arrow.inv_right, ← Category.assoc, IsIso.comp_inv_eq] using hF.lift_fac (F'.ofArrowIso (inv sq)) end IsImage variable (f) /-- Data exhibiting that a morphism `f` has an image. -/ structure ImageFactorisation (f : X ⟶ Y) where F : MonoFactorisation f -- Porting note: another violation of the naming convention isImage : IsImage F attribute [inherit_doc ImageFactorisation] ImageFactorisation.F ImageFactorisation.isImage namespace ImageFactorisation instance [Mono f] : Inhabited (ImageFactorisation f) := ⟨⟨_, IsImage.self f⟩⟩ /-- If `f` and `g` are isomorphic arrows, then an image factorisation of `f` gives an image factorisation of `g` -/ @[simps] def ofArrowIso {f g : Arrow C} (F : ImageFactorisation f.hom) (sq : f ⟶ g) [IsIso sq] : ImageFactorisation g.hom where F := F.F.ofArrowIso sq isImage := F.isImage.ofArrowIso sq end ImageFactorisation /-- `HasImage f` means that there exists an image factorisation of `f`. -/ class HasImage (f : X ⟶ Y) : Prop where mk' :: exists_image : Nonempty (ImageFactorisation f) attribute [inherit_doc HasImage] HasImage.exists_image theorem HasImage.mk {f : X ⟶ Y} (F : ImageFactorisation f) : HasImage f := ⟨Nonempty.intro F⟩ theorem HasImage.of_arrow_iso {f g : Arrow C} [h : HasImage f.hom] (sq : f ⟶ g) [IsIso sq] : HasImage g.hom := ⟨⟨h.exists_image.some.ofArrowIso sq⟩⟩ instance (priority := 100) mono_hasImage (f : X ⟶ Y) [Mono f] : HasImage f := HasImage.mk ⟨_, IsImage.self f⟩ section variable [HasImage f] /-- Some factorisation of `f` through a monomorphism (selected with choice). -/ def Image.monoFactorisation : MonoFactorisation f := (Classical.choice HasImage.exists_image).F /-- The witness of the universal property for the chosen factorisation of `f` through a monomorphism. -/ def Image.isImage : IsImage (Image.monoFactorisation f) := (Classical.choice HasImage.exists_image).isImage /-- The categorical image of a morphism. -/ def image : C := (Image.monoFactorisation f).I /-- The inclusion of the image of a morphism into the target. -/ def image.ι : image f ⟶ Y := (Image.monoFactorisation f).m @[simp] theorem image.as_ι : (Image.monoFactorisation f).m = image.ι f := rfl instance : Mono (image.ι f) := (Image.monoFactorisation f).m_mono /-- The map from the source to the image of a morphism. -/ def factorThruImage : X ⟶ image f := (Image.monoFactorisation f).e /-- Rewrite in terms of the `factorThruImage` interface. -/ @[simp] theorem as_factorThruImage : (Image.monoFactorisation f).e = factorThruImage f := rfl @[reassoc (attr := simp)] theorem image.fac : factorThruImage f ≫ image.ι f = f := (Image.monoFactorisation f).fac variable {f} /-- Any other factorisation of the morphism `f` through a monomorphism receives a map from the image. -/ def image.lift (F' : MonoFactorisation f) : image f ⟶ F'.I := (Image.isImage f).lift F' @[reassoc (attr := simp)] theorem image.lift_fac (F' : MonoFactorisation f) : image.lift F' ≫ F'.m = image.ι f := (Image.isImage f).lift_fac F' @[reassoc (attr := simp)] theorem image.fac_lift (F' : MonoFactorisation f) : factorThruImage f ≫ image.lift F' = F'.e := (Image.isImage f).fac_lift F' @[simp] theorem image.isImage_lift (F : MonoFactorisation f) : (Image.isImage f).lift F = image.lift F := rfl @[reassoc (attr := simp)] theorem IsImage.lift_ι {F : MonoFactorisation f} (hF : IsImage F) : hF.lift (Image.monoFactorisation f) ≫ image.ι f = F.m := hF.lift_fac _ -- TODO we could put a category structure on `MonoFactorisation f`, -- with the morphisms being `g : I ⟶ I'` commuting with the `m`s -- (they then automatically commute with the `e`s) -- and show that an `imageOf f` gives an initial object there -- (uniqueness of the lift comes for free). instance image.lift_mono (F' : MonoFactorisation f) : Mono (image.lift F') := by refine @mono_of_mono _ _ _ _ _ _ F'.m ?_ simpa using MonoFactorisation.m_mono _ theorem HasImage.uniq (F' : MonoFactorisation f) (l : image f ⟶ F'.I) (w : l ≫ F'.m = image.ι f) : l = image.lift F' := (cancel_mono F'.m).1 (by simp [w]) /-- If `has_image g`, then `has_image (f ≫ g)` when `f` is an isomorphism. -/ instance {X Y Z : C} (f : X ⟶ Y) [IsIso f] (g : Y ⟶ Z) [HasImage g] : HasImage (f ≫ g) where exists_image := ⟨{ F := { I := image g m := image.ι g e := f ≫ factorThruImage g } isImage := { lift := fun F' => image.lift { I := F'.I m := F'.m e := inv f ≫ F'.e } } }⟩ end section variable (C) /-- `HasImages` asserts that every morphism has an image. -/ class HasImages : Prop where has_image : ∀ {X Y : C} (f : X ⟶ Y), HasImage f attribute [inherit_doc HasImages] HasImages.has_image attribute [instance 100] HasImages.has_image end section /-- The image of a monomorphism is isomorphic to the source. -/ def imageMonoIsoSource [Mono f] : image f ≅ X := IsImage.isoExt (Image.isImage f) (IsImage.self f) @[reassoc (attr := simp)] theorem imageMonoIsoSource_inv_ι [Mono f] : (imageMonoIsoSource f).inv ≫ image.ι f = f := by simp [imageMonoIsoSource] @[reassoc (attr := simp)] theorem imageMonoIsoSource_hom_self [Mono f] : (imageMonoIsoSource f).hom ≫ f = image.ι f := by simp only [← imageMonoIsoSource_inv_ι f] rw [← Category.assoc, Iso.hom_inv_id, Category.id_comp] -- This is the proof that `factorThruImage f` is an epimorphism -- from https://en.wikipedia.org/wiki/Image_%28category_theory%29, which is in turn taken from: -- Mitchell, Barry (1965), Theory of categories, MR 0202787, p.12, Proposition 10.1 @[ext (iff := false)] theorem image.ext [HasImage f] {W : C} {g h : image f ⟶ W} [HasLimit (parallelPair g h)] (w : factorThruImage f ≫ g = factorThruImage f ≫ h) : g = h := by let q := equalizer.ι g h let e' := equalizer.lift _ w let F' : MonoFactorisation f := { I := equalizer g h m := q ≫ image.ι f m_mono := mono_comp _ _ e := e' } let v := image.lift F' have t₀ : v ≫ q ≫ image.ι f = image.ι f := image.lift_fac F' have t : v ≫ q = 𝟙 (image f) := (cancel_mono_id (image.ι f)).1 (by convert t₀ using 1 rw [Category.assoc]) -- The proof from wikipedia next proves `q ≫ v = 𝟙 _`, -- and concludes that `equalizer g h ≅ image f`, -- but this isn't necessary. calc g = 𝟙 (image f) ≫ g := by rw [Category.id_comp] _ = v ≫ q ≫ g := by rw [← t, Category.assoc] _ = v ≫ q ≫ h := by rw [equalizer.condition g h] _ = 𝟙 (image f) ≫ h := by rw [← Category.assoc, t] _ = h := by rw [Category.id_comp] instance [HasImage f] [∀ {Z : C} (g h : image f ⟶ Z), HasLimit (parallelPair g h)] : Epi (factorThruImage f) := ⟨fun _ _ w => image.ext f w⟩ theorem epi_image_of_epi {X Y : C} (f : X ⟶ Y) [HasImage f] [E : Epi f] : Epi (image.ι f) := by rw [← image.fac f] at E exact epi_of_epi (factorThruImage f) (image.ι f) theorem epi_of_epi_image {X Y : C} (f : X ⟶ Y) [HasImage f] [Epi (image.ι f)] [Epi (factorThruImage f)] : Epi f := by rw [← image.fac f] apply epi_comp end section variable {f} variable {f' : X ⟶ Y} [HasImage f] [HasImage f'] /-- An equation between morphisms gives a comparison map between the images (which momentarily we prove is an iso). -/ def image.eqToHom (h : f = f') : image f ⟶ image f' := image.lift { I := image f' m := image.ι f' e := factorThruImage f' fac := by rw [h]; simp only [image.fac]} instance (h : f = f') : IsIso (image.eqToHom h) := ⟨⟨image.eqToHom h.symm, ⟨(cancel_mono (image.ι f)).1 (by -- Porting note: added let's for used to be a simp [image.eqToHom] let F : MonoFactorisation f' := ⟨image f, image.ι f, factorThruImage f, (by cat_disch)⟩ dsimp [image.eqToHom] rw [Category.id_comp,Category.assoc,image.lift_fac F] let F' : MonoFactorisation f := ⟨image f', image.ι f', factorThruImage f', (by cat_disch)⟩ rw [image.lift_fac F'] ), (cancel_mono (image.ι f')).1 (by -- Porting note: added let's for used to be a simp [image.eqToHom] let F' : MonoFactorisation f := ⟨image f', image.ι f', factorThruImage f', (by cat_disch)⟩ dsimp [image.eqToHom] rw [Category.id_comp,Category.assoc,image.lift_fac F'] let F : MonoFactorisation f' := ⟨image f, image.ι f, factorThruImage f, (by cat_disch)⟩ rw [image.lift_fac F])⟩⟩⟩ /-- An equation between morphisms gives an isomorphism between the images. -/ def image.eqToIso (h : f = f') : image f ≅ image f' := asIso (image.eqToHom h) /-- As long as the category has equalizers, the image inclusion maps commute with `image.eqToIso`. -/ theorem image.eq_fac [HasEqualizers C] (h : f = f') : image.ι f = (image.eqToIso h).hom ≫ image.ι f' := by apply image.ext dsimp [asIso,image.eqToIso, image.eqToHom] rw [image.lift_fac] -- Porting note: simp did not fire with this it seems end section variable {Z : C} (g : Y ⟶ Z) /-- The comparison map `image (f ≫ g) ⟶ image g`. -/ def image.preComp [HasImage g] [HasImage (f ≫ g)] : image (f ≫ g) ⟶ image g := image.lift { I := image g m := image.ι g e := f ≫ factorThruImage g } @[reassoc (attr := simp)] theorem image.preComp_ι [HasImage g] [HasImage (f ≫ g)] : image.preComp f g ≫ image.ι g = image.ι (f ≫ g) := by dsimp [image.preComp] rw [image.lift_fac] -- Porting note: also here, see image.eq_fac @[reassoc (attr := simp)] theorem image.factorThruImage_preComp [HasImage g] [HasImage (f ≫ g)] : factorThruImage (f ≫ g) ≫ image.preComp f g = f ≫ factorThruImage g := by simp [image.preComp] /-- `image.preComp f g` is a monomorphism. -/ instance image.preComp_mono [HasImage g] [HasImage (f ≫ g)] : Mono (image.preComp f g) := by refine @mono_of_mono _ _ _ _ _ _ (image.ι g) ?_ simp only [image.preComp_ι] infer_instance /-- The two step comparison map `image (f ≫ (g ≫ h)) ⟶ image (g ≫ h) ⟶ image h` agrees with the one step comparison map `image (f ≫ (g ≫ h)) ≅ image ((f ≫ g) ≫ h) ⟶ image h`. -/ theorem image.preComp_comp {W : C} (h : Z ⟶ W) [HasImage (g ≫ h)] [HasImage (f ≫ g ≫ h)] [HasImage h] [HasImage ((f ≫ g) ≫ h)] : image.preComp f (g ≫ h) ≫ image.preComp g h = image.eqToHom (Category.assoc f g h).symm ≫ image.preComp (f ≫ g) h := by apply (cancel_mono (image.ι h)).1 dsimp [image.preComp, image.eqToHom] repeat (rw [Category.assoc,image.lift_fac]) rw [image.lift_fac,image.lift_fac] variable [HasEqualizers C] /-- `image.preComp f g` is an epimorphism when `f` is an epimorphism (we need `C` to have equalizers to prove this). -/ instance image.preComp_epi_of_epi [HasImage g] [HasImage (f ≫ g)] [Epi f] : Epi (image.preComp f g) := by apply @epi_of_epi_fac _ _ _ _ _ _ _ _ ?_ (image.factorThruImage_preComp _ _) exact epi_comp _ _ instance hasImage_iso_comp [IsIso f] [HasImage g] : HasImage (f ≫ g) := HasImage.mk { F := (Image.monoFactorisation g).isoComp f isImage := { lift := fun F' => image.lift (F'.ofIsoComp f) lift_fac := fun F' => by dsimp have : (MonoFactorisation.ofIsoComp f F').m = F'.m := rfl rw [← this,image.lift_fac (MonoFactorisation.ofIsoComp f F')] } } /-- `image.preComp f g` is an isomorphism when `f` is an isomorphism (we need `C` to have equalizers to prove this). -/ instance image.isIso_precomp_iso (f : X ⟶ Y) [IsIso f] [HasImage g] : IsIso (image.preComp f g) := ⟨⟨image.lift { I := image (f ≫ g) m := image.ι (f ≫ g) e := inv f ≫ factorThruImage (f ≫ g) }, ⟨by ext simp [image.preComp], by ext simp [image.preComp]⟩⟩⟩ -- Note that in general we don't have the other comparison map you might expect -- `image f ⟶ image (f ≫ g)`. instance hasImage_comp_iso [HasImage f] [IsIso g] : HasImage (f ≫ g) := HasImage.mk { F := (Image.monoFactorisation f).compMono g isImage := { lift := fun F' => image.lift F'.ofCompIso lift_fac := fun F' => by rw [← Category.comp_id (image.lift (MonoFactorisation.ofCompIso F') ≫ F'.m), ← IsIso.inv_hom_id g,← Category.assoc] refine congrArg (· ≫ g) ?_ have : (image.lift (MonoFactorisation.ofCompIso F') ≫ F'.m) ≫ inv g = image.lift (MonoFactorisation.ofCompIso F') ≫ ((MonoFactorisation.ofCompIso F').m) := by simp only [MonoFactorisation.ofCompIso_I, Category.assoc, MonoFactorisation.ofCompIso_m] rw [this, image.lift_fac (MonoFactorisation.ofCompIso F'),image.as_ι] }} /-- Postcomposing by an isomorphism induces an isomorphism on the image. -/ def image.compIso [HasImage f] [IsIso g] : image f ≅ image (f ≫ g) where hom := image.lift (Image.monoFactorisation (f ≫ g)).ofCompIso inv := image.lift ((Image.monoFactorisation f).compMono g) @[reassoc (attr := simp)] theorem image.compIso_hom_comp_image_ι [HasImage f] [IsIso g] : (image.compIso f g).hom ≫ image.ι (f ≫ g) = image.ι f ≫ g := by ext simp [image.compIso] @[reassoc (attr := simp)] theorem image.compIso_inv_comp_image_ι [HasImage f] [IsIso g] : (image.compIso f g).inv ≫ image.ι f = image.ι (f ≫ g) ≫ inv g := by ext simp [image.compIso] end end CategoryTheory.Limits namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] section instance {X Y : C} (f : X ⟶ Y) [HasImage f] : HasImage (Arrow.mk f).hom := show HasImage f by infer_instance end section HasImageMap -- Don't generate unnecessary injectivity lemmas which the `simpNF` linter will complain about. set_option genInjectivity false in /-- An image map is a morphism `image f → image g` fitting into a commutative square and satisfying the obvious commutativity conditions. -/ structure ImageMap {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) where map : image f.hom ⟶ image g.hom map_ι : map ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by aesop attribute [inherit_doc ImageMap] ImageMap.map ImageMap.map_ι instance inhabitedImageMap {f : Arrow C} [HasImage f.hom] : Inhabited (ImageMap (𝟙 f)) := ⟨⟨𝟙 _, by simp⟩⟩ attribute [reassoc (attr := simp)] ImageMap.map_ι @[reassoc (attr := simp)] theorem ImageMap.factor_map {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) (m : ImageMap sq) : factorThruImage f.hom ≫ m.map = sq.left ≫ factorThruImage g.hom := (cancel_mono (image.ι g.hom)).1 <| by simp /-- To give an image map for a commutative square with `f` at the top and `g` at the bottom, it suffices to give a map between any mono factorisation of `f` and any image factorisation of `g`. -/ def ImageMap.transport {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) (F : MonoFactorisation f.hom) {F' : MonoFactorisation g.hom} (hF' : IsImage F') {map : F.I ⟶ F'.I} (map_ι : map ≫ F'.m = F.m ≫ sq.right) : ImageMap sq where map := image.lift F ≫ map ≫ hF'.lift (Image.monoFactorisation g.hom) map_ι := by simp [map_ι] /-- `HasImageMap sq` means that there is an `ImageMap` for the square `sq`. -/ class HasImageMap {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) : Prop where mk' :: has_image_map : Nonempty (ImageMap sq) attribute [inherit_doc HasImageMap] HasImageMap.has_image_map theorem HasImageMap.mk {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g} (m : ImageMap sq) : HasImageMap sq := ⟨Nonempty.intro m⟩ theorem HasImageMap.transport {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) (F : MonoFactorisation f.hom) {F' : MonoFactorisation g.hom} (hF' : IsImage F') (map : F.I ⟶ F'.I) (map_ι : map ≫ F'.m = F.m ≫ sq.right) : HasImageMap sq := HasImageMap.mk <| ImageMap.transport sq F hF' map_ι /-- Obtain an `ImageMap` from a `HasImageMap` instance. -/ def HasImageMap.imageMap {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) [HasImageMap sq] : ImageMap sq := Classical.choice <| @HasImageMap.has_image_map _ _ _ _ _ _ sq _ -- see Note [lower instance priority] instance (priority := 100) hasImageMapOfIsIso {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) [IsIso sq] : HasImageMap sq := HasImageMap.mk { map := image.lift ((Image.monoFactorisation g.hom).ofArrowIso (inv sq)) map_ι := by erw [← cancel_mono (inv sq).right, Category.assoc, ← MonoFactorisation.ofArrowIso_m, image.lift_fac, Category.assoc, ← Comma.comp_right, IsIso.hom_inv_id, Comma.id_right, Category.comp_id] } instance HasImageMap.comp {f g h : Arrow C} [HasImage f.hom] [HasImage g.hom] [HasImage h.hom] (sq1 : f ⟶ g) (sq2 : g ⟶ h) [HasImageMap sq1] [HasImageMap sq2] : HasImageMap (sq1 ≫ sq2) := HasImageMap.mk { map := (HasImageMap.imageMap sq1).map ≫ (HasImageMap.imageMap sq2).map map_ι := by rw [Category.assoc,ImageMap.map_ι, ImageMap.map_ι_assoc, Comma.comp_right] } variable {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) section attribute [local ext] ImageMap /- Porting note: ImageMap.mk.injEq has LHS simplify to True due to the next instance We make a replacement -/ theorem ImageMap.map_uniq_aux {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g} (map : image f.hom ⟶ image g.hom) (map_ι : map ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by cat_disch) (map' : image f.hom ⟶ image g.hom) (map_ι' : map' ≫ image.ι g.hom = image.ι f.hom ≫ sq.right) : (map = map') := by have : map ≫ image.ι g.hom = map' ≫ image.ι g.hom := by rw [map_ι,map_ι'] apply (cancel_mono (image.ι g.hom)).1 this -- Porting note: added to get variant on ImageMap.mk.injEq below theorem ImageMap.map_uniq {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g} (F G : ImageMap sq) : F.map = G.map := by apply ImageMap.map_uniq_aux _ F.map_ι _ G.map_ι @[simp] theorem ImageMap.mk.injEq' {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g} (map : image f.hom ⟶ image g.hom) (map_ι : map ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by cat_disch) (map' : image f.hom ⟶ image g.hom) (map_ι' : map' ≫ image.ι g.hom = image.ι f.hom ≫ sq.right) : (map = map') = True := by simp only [Functor.id_obj, eq_iff_iff, iff_true] apply ImageMap.map_uniq_aux _ map_ι _ map_ι' instance : Subsingleton (ImageMap sq) := Subsingleton.intro fun a b => ImageMap.ext <| ImageMap.map_uniq a b end variable [HasImageMap sq] /-- The map on images induced by a commutative square. -/ abbrev image.map : image f.hom ⟶ image g.hom := (HasImageMap.imageMap sq).map theorem image.factor_map : factorThruImage f.hom ≫ image.map sq = sq.left ≫ factorThruImage g.hom := by simp theorem image.map_ι : image.map sq ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by simp theorem image.map_homMk'_ι {X Y P Q : C} {k : X ⟶ Y} [HasImage k] {l : P ⟶ Q} [HasImage l] {m : X ⟶ P} {n : Y ⟶ Q} (w : m ≫ l = k ≫ n) [HasImageMap (Arrow.homMk' _ _ w)] : image.map (Arrow.homMk' _ _ w) ≫ image.ι l = image.ι k ≫ n := image.map_ι _ section variable {h : Arrow C} [HasImage h.hom] (sq' : g ⟶ h) variable [HasImageMap sq'] /-- Image maps for composable commutative squares induce an image map in the composite square. -/ def imageMapComp : ImageMap (sq ≫ sq') where map := image.map sq ≫ image.map sq' @[simp] theorem image.map_comp [HasImageMap (sq ≫ sq')] : image.map (sq ≫ sq') = image.map sq ≫ image.map sq' := show (HasImageMap.imageMap (sq ≫ sq')).map = (imageMapComp sq sq').map by congr; simp only [eq_iff_true_of_subsingleton] end section variable (f) /-- The identity `image f ⟶ image f` fits into the commutative square represented by the identity morphism `𝟙 f` in the arrow category. -/ def imageMapId : ImageMap (𝟙 f) where map := 𝟙 (image f.hom) @[simp] theorem image.map_id [HasImageMap (𝟙 f)] : image.map (𝟙 f) = 𝟙 (image f.hom) := show (HasImageMap.imageMap (𝟙 f)).map = (imageMapId f).map by congr; simp only [eq_iff_true_of_subsingleton] end end HasImageMap section variable (C) [HasImages C] /-- If a category `has_image_maps`, then all commutative squares induce morphisms on images. -/ class HasImageMaps : Prop where has_image_map : ∀ {f g : Arrow C} (st : f ⟶ g), HasImageMap st attribute [instance 100] HasImageMaps.has_image_map end section HasImageMaps variable [HasImages C] [HasImageMaps C] /-- The functor from the arrow category of `C` to `C` itself that maps a morphism to its image and a commutative square to the induced morphism on images. -/ @[simps] def im : Arrow C ⥤ C where obj f := image f.hom map st := image.map st end HasImageMaps section StrongEpiMonoFactorisation /-- A strong epi-mono factorisation is a decomposition `f = e ≫ m` with `e` a strong epimorphism and `m` a monomorphism. -/ structure StrongEpiMonoFactorisation {X Y : C} (f : X ⟶ Y) extends MonoFactorisation f where [e_strong_epi : StrongEpi e] attribute [inherit_doc StrongEpiMonoFactorisation] StrongEpiMonoFactorisation.e_strong_epi attribute [instance] StrongEpiMonoFactorisation.e_strong_epi /-- Satisfying the inhabited linter -/ instance strongEpiMonoFactorisationInhabited {X Y : C} (f : X ⟶ Y) [StrongEpi f] : Inhabited (StrongEpiMonoFactorisation f) := ⟨⟨⟨Y, 𝟙 Y, f, by simp⟩⟩⟩ /-- A mono factorisation coming from a strong epi-mono factorisation always has the universal property of the image. -/ def StrongEpiMonoFactorisation.toMonoIsImage {X Y : C} {f : X ⟶ Y} (F : StrongEpiMonoFactorisation f) : IsImage F.toMonoFactorisation where lift G := (CommSq.mk (show G.e ≫ G.m = F.e ≫ F.m by rw [F.toMonoFactorisation.fac, G.fac])).lift variable (C) /-- A category has strong epi-mono factorisations if every morphism admits a strong epi-mono factorisation. -/ class HasStrongEpiMonoFactorisations : Prop where mk' :: has_fac : ∀ {X Y : C} (f : X ⟶ Y), Nonempty (StrongEpiMonoFactorisation f) attribute [inherit_doc HasStrongEpiMonoFactorisations] HasStrongEpiMonoFactorisations.has_fac variable {C} theorem HasStrongEpiMonoFactorisations.mk (d : ∀ {X Y : C} (f : X ⟶ Y), StrongEpiMonoFactorisation f) : HasStrongEpiMonoFactorisations C := ⟨fun f => Nonempty.intro <| d f⟩ instance (priority := 100) hasImages_of_hasStrongEpiMonoFactorisations [HasStrongEpiMonoFactorisations C] : HasImages C where has_image f := let F' := Classical.choice (HasStrongEpiMonoFactorisations.has_fac f) HasImage.mk { F := F'.toMonoFactorisation isImage := F'.toMonoIsImage } end StrongEpiMonoFactorisation section HasStrongEpiImages variable (C) [HasImages C] /-- A category has strong epi images if it has all images and `factorThruImage f` is a strong epimorphism for all `f`. -/ class HasStrongEpiImages : Prop where strong_factorThruImage : ∀ {X Y : C} (f : X ⟶ Y), StrongEpi (factorThruImage f) attribute [instance] HasStrongEpiImages.strong_factorThruImage end HasStrongEpiImages section HasStrongEpiImages /-- If there is a single strong epi-mono factorisation of `f`, then every image factorisation is a strong epi-mono factorisation. -/ theorem strongEpi_of_strongEpiMonoFactorisation {X Y : C} {f : X ⟶ Y} (F : StrongEpiMonoFactorisation f) {F' : MonoFactorisation f} (hF' : IsImage F') : StrongEpi F'.e := by rw [← IsImage.e_isoExt_hom F.toMonoIsImage hF'] apply strongEpi_comp theorem strongEpi_factorThruImage_of_strongEpiMonoFactorisation {X Y : C} {f : X ⟶ Y} [HasImage f] (F : StrongEpiMonoFactorisation f) : StrongEpi (factorThruImage f) := strongEpi_of_strongEpiMonoFactorisation F <| Image.isImage f /-- If we constructed our images from strong epi-mono factorisations, then these images are strong epi images. -/ instance (priority := 100) hasStrongEpiImages_of_hasStrongEpiMonoFactorisations [HasStrongEpiMonoFactorisations C] : HasStrongEpiImages C where strong_factorThruImage f := strongEpi_factorThruImage_of_strongEpiMonoFactorisation <| Classical.choice <| HasStrongEpiMonoFactorisations.has_fac f end HasStrongEpiImages section HasStrongEpiImages variable [HasImages C] /-- A category with strong epi images has image maps. -/ instance (priority := 100) hasImageMapsOfHasStrongEpiImages [HasStrongEpiImages C] : HasImageMaps C where has_image_map {f} {g} st := HasImageMap.mk { map := (CommSq.mk (show (st.left ≫ factorThruImage g.hom) ≫ image.ι g.hom = factorThruImage f.hom ≫ image.ι f.hom ≫ st.right by simp)).lift } /-- If a category has images, equalizers and pullbacks, then images are automatically strong epi images. -/ instance (priority := 100) hasStrongEpiImages_of_hasPullbacks_of_hasEqualizers [HasPullbacks C] [HasEqualizers C] : HasStrongEpiImages C where strong_factorThruImage f := StrongEpi.mk' fun {A} {B} h h_mono x y sq => CommSq.HasLift.mk' { l := image.lift { I := pullback h y m := pullback.snd h y ≫ image.ι f m_mono := mono_comp _ _ e := pullback.lift _ _ sq.w } ≫ pullback.fst h y fac_left := by simp only [image.fac_lift_assoc, pullback.lift_fst] fac_right := by apply image.ext simp only [sq.w, Category.assoc, image.fac_lift_assoc, pullback.lift_fst_assoc] } end HasStrongEpiImages variable [HasStrongEpiMonoFactorisations C] variable {X Y : C} {f : X ⟶ Y} /-- If `C` has strong epi mono factorisations, then the image is unique up to isomorphism, in that if `f` factors as a strong epi followed by a mono, this factorisation is essentially the image factorisation. -/ def image.isoStrongEpiMono {I' : C} (e : X ⟶ I') (m : I' ⟶ Y) (comm : e ≫ m = f) [StrongEpi e] [Mono m] : I' ≅ image f := let F : StrongEpiMonoFactorisation f := { I := I', m := m, e := e} IsImage.isoExt F.toMonoIsImage <| Image.isImage f @[simp] theorem image.isoStrongEpiMono_hom_comp_ι {I' : C} (e : X ⟶ I') (m : I' ⟶ Y) (comm : e ≫ m = f) [StrongEpi e] [Mono m] : (image.isoStrongEpiMono e m comm).hom ≫ image.ι f = m := by dsimp [isoStrongEpiMono] apply IsImage.lift_fac @[simp] theorem image.isoStrongEpiMono_inv_comp_mono {I' : C} (e : X ⟶ I') (m : I' ⟶ Y) (comm : e ≫ m = f) [StrongEpi e] [Mono m] : (image.isoStrongEpiMono e m comm).inv ≫ m = image.ι f := image.lift_fac _ open MorphismProperty variable (C) /-- A category with strong epi mono factorisations admits functorial epi/mono factorizations. -/ noncomputable def functorialEpiMonoFactorizationData : FunctorialFactorizationData (epimorphisms C) (monomorphisms C) where Z := im i := { app := fun f => factorThruImage f.hom } p := { app := fun f => image.ι f.hom } hi _ := epimorphisms.infer_property _ hp _ := monomorphisms.infer_property _ end CategoryTheory.Limits namespace CategoryTheory.Functor open CategoryTheory.Limits variable {C D : Type*} [Category C] [Category D] theorem hasStrongEpiMonoFactorisations_imp_of_isEquivalence (F : C ⥤ D) [IsEquivalence F] [h : HasStrongEpiMonoFactorisations C] : HasStrongEpiMonoFactorisations D := ⟨fun {X} {Y} f => by let em : StrongEpiMonoFactorisation (F.inv.map f) := (HasStrongEpiMonoFactorisations.has_fac (F.inv.map f)).some haveI : Mono (F.map em.m ≫ F.asEquivalence.counitIso.hom.app Y) := mono_comp _ _ haveI : StrongEpi (F.asEquivalence.counitIso.inv.app X ≫ F.map em.e) := strongEpi_comp _ _ exact Nonempty.intro { I := F.obj em.I e := F.asEquivalence.counitIso.inv.app X ≫ F.map em.e m := F.map em.m ≫ F.asEquivalence.counitIso.hom.app Y fac := by simp only [asEquivalence_functor, Category.assoc, ← F.map_comp_assoc, MonoFactorisation.fac, fun_inv_map, id_obj, Iso.inv_hom_id_app, Category.comp_id, Iso.inv_hom_id_app_assoc] }⟩ end CategoryTheory.Functor
DynamicalEntourage.lean
/- Copyright (c) 2024 Damien Thomine. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damien Thomine, Pietro Monticone -/ import Mathlib.Order.Interval.Finset.Nat import Mathlib.Topology.Constructions.SumProd import Mathlib.Topology.UniformSpace.Basic /-! # Dynamical entourages Bowen-Dinaburg's definition of topological entropy of a transformation `T` in a metric space `(X, d)` relies on the so-called dynamical balls. These balls are sets `B (x, ε, n) = { y | ∀ k < n, d(T^[k] x, T^[k] y) < ε }`. We implement Bowen-Dinaburg's definitions in the more general context of uniform spaces. Dynamical balls are replaced by what we call dynamical entourages. This file collects all general lemmas about these objects. ## Main definitions - `dynEntourage`: dynamical entourage associated with a given transformation `T`, entourage `U` and time `n`. ## Tags entropy ## TODO Add product of entourages. In the context of (pseudo-e)metric spaces, relate the usual definition of dynamical balls with these dynamical entourages. -/ namespace Dynamics open Prod Set UniformSpace open scoped Topology Uniformity variable {X : Type*} /-- The dynamical entourage associated to a transformation `T`, entourage `U` and time `n` is the set of points `(x, y)` such that `(T^[k] x, T^[k] y) ∈ U` for all `k < n`, i.e. which are `U`-close up to time `n`. -/ def dynEntourage (T : X → X) (U : Set (X × X)) (n : ℕ) : Set (X × X) := ⋂ k < n, (map T T)^[k] ⁻¹' U lemma dynEntourage_eq_inter_Ico (T : X → X) (U : Set (X × X)) (n : ℕ) : dynEntourage T U n = ⋂ k : Ico 0 n, (map T T)^[k] ⁻¹' U := by simp [dynEntourage] lemma mem_dynEntourage {T : X → X} {U : Set (X × X)} {n : ℕ} {x y : X} : (x, y) ∈ dynEntourage T U n ↔ ∀ k < n, (T^[k] x, T^[k] y) ∈ U := by simp [dynEntourage] lemma mem_ball_dynEntourage {T : X → X} {U : Set (X × X)} {n : ℕ} {x y : X} : y ∈ ball x (dynEntourage T U n) ↔ ∀ k < n, T^[k] y ∈ ball (T^[k] x) U := by simp only [ball, mem_preimage, mem_dynEntourage] lemma dynEntourage_mem_uniformity [UniformSpace X] {T : X → X} (h : UniformContinuous T) {U : Set (X × X)} (U_uni : U ∈ 𝓤 X) (n : ℕ) : dynEntourage T U n ∈ 𝓤 X := by rw [dynEntourage_eq_inter_Ico T U n] refine Filter.iInter_mem.2 fun k ↦ ?_ rw [map_iterate T T k] exact uniformContinuous_def.1 (UniformContinuous.iterate T k h) U U_uni lemma ball_dynEntourage_mem_nhds [UniformSpace X] {T : X → X} (h : Continuous T) {U : Set (X × X)} (U_uni : U ∈ 𝓤 X) (n : ℕ) (x : X) : ball x (dynEntourage T U n) ∈ 𝓝 x := by rw [dynEntourage_eq_inter_Ico T U n, ball_iInter, Filter.iInter_mem, Subtype.forall] intro k _ simp only [map_iterate, _root_.ball_preimage] exact (h.iterate k).continuousAt.preimage_mem_nhds (ball_mem_nhds (T^[k] x) U_uni) lemma idRel_subset_dynEntourage (T : X → X) {U : Set (X × X)} (h : idRel ⊆ U) (n : ℕ) : idRel ⊆ (dynEntourage T U n) := by simp only [dynEntourage, map_iterate, subset_iInter_iff, idRel_subset, mem_preimage, map_apply] exact fun _ _ _ ↦ h rfl lemma _root_.IsSymmetricRel.dynEntourage (T : X → X) {U : Set (X × X)} (h : IsSymmetricRel U) (n : ℕ) : IsSymmetricRel (dynEntourage T U n) := by ext xy simp only [Dynamics.dynEntourage, map_iterate, mem_preimage, mem_iInter] refine forall₂_congr fun k _ ↦ ?_ exact map_apply' _ _ _ ▸ IsSymmetricRel.mk_mem_comm h @[deprecated (since := "2025-03-05")] alias _root_.SymmetricRel.dynEntourage := _root_.IsSymmetricRel.dynEntourage lemma dynEntourage_comp_subset (T : X → X) (U V : Set (X × X)) (n : ℕ) : (dynEntourage T U n) ○ (dynEntourage T V n) ⊆ dynEntourage T (U ○ V) n := by simp only [dynEntourage, map_iterate, subset_iInter_iff] intro k k_n xy xy_comp simp only [compRel, mem_iInter, mem_preimage, map_apply, mem_setOf_eq] at xy_comp ⊢ rcases xy_comp with ⟨z, hz1, hz2⟩ exact mem_ball_comp (hz1 k k_n) (hz2 k k_n) lemma _root_.isOpen.dynEntourage [TopologicalSpace X] {T : X → X} (T_cont : Continuous T) {U : Set (X × X)} (U_open : IsOpen U) (n : ℕ) : IsOpen (dynEntourage T U n) := by rw [dynEntourage_eq_inter_Ico T U n] refine isOpen_iInter_of_finite fun k ↦ ?_ exact U_open.preimage ((T_cont.prodMap T_cont).iterate k) lemma dynEntourage_monotone (T : X → X) (n : ℕ) : Monotone (fun U : Set (X × X) ↦ dynEntourage T U n) := fun _ _ h ↦ iInter₂_mono fun _ _ ↦ preimage_mono h lemma dynEntourage_antitone (T : X → X) (U : Set (X × X)) : Antitone (fun n : ℕ ↦ dynEntourage T U n) := fun m n m_n ↦ iInter₂_mono' fun k k_m ↦ by use k, lt_of_lt_of_le k_m m_n @[simp] lemma dynEntourage_zero {T : X → X} {U : Set (X × X)} : dynEntourage T U 0 = univ := by simp [dynEntourage] @[simp] lemma dynEntourage_one {T : X → X} {U : Set (X × X)} : dynEntourage T U 1 = U := by simp [dynEntourage] @[simp] lemma dynEntourage_univ {T : X → X} {n : ℕ} : dynEntourage T univ n = univ := by simp [dynEntourage] lemma mem_ball_dynEntourage_comp (T : X → X) (n : ℕ) {U : Set (X × X)} (U_symm : IsSymmetricRel U) (x y : X) (h : (ball x (dynEntourage T U n) ∩ ball y (dynEntourage T U n)).Nonempty) : x ∈ ball y (dynEntourage T (U ○ U) n) := by rcases h with ⟨z, z_Bx, z_By⟩ rw [mem_ball_symmetry (IsSymmetricRel.dynEntourage T U_symm n)] at z_Bx exact dynEntourage_comp_subset T U U n (mem_ball_comp z_By z_Bx) lemma _root_.Function.Semiconj.preimage_dynEntourage {Y : Type*} {S : X → X} {T : Y → Y} {φ : X → Y} (h : Function.Semiconj φ S T) (U : Set (Y × Y)) (n : ℕ) : (map φ φ)⁻¹' (dynEntourage T U n) = dynEntourage S ((map φ φ)⁻¹' U) n := by rw [dynEntourage, preimage_iInter₂] refine iInter₂_congr fun k _ ↦ ?_ rw [← preimage_comp, ← preimage_comp, map_iterate S S k, map_iterate T T k, map_comp_map, map_comp_map, (Function.Semiconj.iterate_right h k).comp_eq] end Dynamics
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.
Basic.lean
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Johan Commelin, Kim Morrison -/ import Mathlib.CategoryTheory.Limits.Constructions.Pullbacks import Mathlib.CategoryTheory.Preadditive.Biproducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers import Mathlib.CategoryTheory.Abelian.NonPreadditive /-! # Abelian categories This file contains the definition and basic properties of abelian categories. There are many definitions of abelian category. Our definition is as follows: A category is called abelian if it is preadditive, has a finite products, kernels and cokernels, and if every monomorphism and epimorphism is normal. It should be noted that if we also assume coproducts, then preadditivity is actually a consequence of the other properties, as we show in `NonPreadditiveAbelian.lean`. However, this fact is of little practical relevance, since essentially all interesting abelian categories come with a preadditive structure. In this way, by requiring preadditivity, we allow the user to pass in the "native" preadditive structure for the specific category they are working with. ## Main definitions * `Abelian` is the type class indicating that a category is abelian. It extends `Preadditive`. * `Abelian.image f` is `kernel (cokernel.π f)`, and * `Abelian.coimage f` is `cokernel (kernel.ι f)`. ## Main results * In an abelian category, mono + epi = iso. * If `f : X ⟶ Y`, then the map `factorThruImage f : X ⟶ image f` is an epimorphism, and the map `factorThruCoimage f : coimage f ⟶ Y` is a monomorphism. * Factoring through the image and coimage is a strong epi-mono factorisation. This means that * every abelian category has images. We provide the isomorphism `imageIsoImage : abelian.image f ≅ limits.image f`. * the canonical morphism `coimageImageComparison : coimage f ⟶ image f` is an isomorphism. * We provide the alternate characterisation of an abelian category as a category with (co)kernels and finite products, and in which the canonical coimage-image comparison morphism is always an isomorphism. * Every epimorphism is a cokernel of its kernel. Every monomorphism is a kernel of its cokernel. * The pullback of an epimorphism is an epimorphism. The pushout of a monomorphism is a monomorphism. (This is not to be confused with the fact that the pullback of a monomorphism is a monomorphism, which is true in any category). ## Implementation notes The typeclass `Abelian` does not extend `NonPreadditiveAbelian`, to avoid having to deal with comparing the two `HasZeroMorphisms` instances (one from `Preadditive` in `Abelian`, and the other a field of `NonPreadditiveAbelian`). As a consequence, at the beginning of this file we trivially build a `NonPreadditiveAbelian` instance from an `Abelian` instance, and use this to restate a number of theorems, in each case just reusing the proof from `NonPreadditiveAbelian.lean`. We don't show this yet, but abelian categories are finitely complete and finitely cocomplete. However, the limits we can construct at this level of generality will most likely be less nice than the ones that can be created in specific applications. For this reason, we adopt the following convention: * If the statement of a theorem involves limits, the existence of these limits should be made an explicit typeclass parameter. * If a limit only appears in a proof, but not in the statement of a theorem, the limit should not be a typeclass parameter, but instead be created using `Abelian.hasPullbacks` or a similar definition. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] * [P. Aluffi, *Algebra: Chapter 0*][aluffi2016] -/ noncomputable section open CategoryTheory open CategoryTheory.Preadditive open CategoryTheory.Limits universe v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] variable (C) /-- A (preadditive) category `C` is called abelian if it has all finite products, all kernels and cokernels, and if every monomorphism is the kernel of some morphism and every epimorphism is the cokernel of some morphism. (This definition implies the existence of zero objects: finite products give a terminal object, and in a preadditive category any terminal object is a zero object.) -/ class Abelian extends Preadditive C, IsNormalMonoCategory C, IsNormalEpiCategory C where [has_finite_products : HasFiniteProducts C] [has_kernels : HasKernels C] [has_cokernels : HasCokernels C] attribute [instance 100] Abelian.has_finite_products attribute [instance 90] Abelian.has_kernels Abelian.has_cokernels end CategoryTheory open CategoryTheory /-! We begin by providing an alternative constructor: a preadditive category with kernels, cokernels, and finite products, in which the coimage-image comparison morphism is always an isomorphism, is an abelian category. -/ namespace CategoryTheory.Abelian variable {C : Type u} [Category.{v} C] [Preadditive C] variable [Limits.HasKernels C] [Limits.HasCokernels C] namespace OfCoimageImageComparisonIsIso /-- The factorisation of a morphism through its abelian image. -/ @[simps] def imageMonoFactorisation {X Y : C} (f : X ⟶ Y) : MonoFactorisation f where I := Abelian.image f m := kernel.ι _ m_mono := inferInstance e := kernel.lift _ f (cokernel.condition _) fac := kernel.lift_ι _ _ _ theorem imageMonoFactorisation_e' {X Y : C} (f : X ⟶ Y) : (imageMonoFactorisation f).e = cokernel.π _ ≫ Abelian.coimageImageComparison f := by dsimp ext simp only [Abelian.coimageImageComparison, Category.assoc, cokernel.π_desc_assoc] /-- If the coimage-image comparison morphism for a morphism `f` is an isomorphism, we obtain an image factorisation of `f`. -/ def imageFactorisation {X Y : C} (f : X ⟶ Y) [IsIso (Abelian.coimageImageComparison f)] : ImageFactorisation f where F := imageMonoFactorisation f isImage := { lift := fun F => inv (Abelian.coimageImageComparison f) ≫ cokernel.desc _ F.e F.kernel_ι_comp lift_fac := fun F => by rw [imageMonoFactorisation_m] simp only [Category.assoc] rw [IsIso.inv_comp_eq] ext simp } instance [HasZeroObject C] {X Y : C} (f : X ⟶ Y) [Mono f] [IsIso (Abelian.coimageImageComparison f)] : IsIso (imageMonoFactorisation f).e := by rw [imageMonoFactorisation_e'] exact IsIso.comp_isIso instance [HasZeroObject C] {X Y : C} (f : X ⟶ Y) [Epi f] : IsIso (imageMonoFactorisation f).m := by dsimp infer_instance variable [∀ {X Y : C} (f : X ⟶ Y), IsIso (Abelian.coimageImageComparison f)] /-- A category in which coimage-image comparisons are all isomorphisms has images. -/ theorem hasImages : HasImages C := { has_image := fun {_} {_} f => { exists_image := ⟨imageFactorisation f⟩ } } variable [Limits.HasFiniteProducts C] attribute [local instance] Limits.HasFiniteBiproducts.of_hasFiniteProducts /-- A category with finite products in which coimage-image comparisons are all isomorphisms is a normal mono category. -/ lemma isNormalMonoCategory : IsNormalMonoCategory C where normalMonoOfMono f m := ⟨{ Z := _ g := cokernel.π f w := by simp isLimit := by haveI : Limits.HasImages C := hasImages haveI : HasEqualizers C := Preadditive.hasEqualizers_of_hasKernels haveI : HasZeroObject C := Limits.hasZeroObject_of_hasFiniteBiproducts _ have aux : ∀ (s : KernelFork (cokernel.π f)), (limit.lift (parallelPair (cokernel.π f) 0) s ≫ inv (imageMonoFactorisation f).e) ≫ Fork.ι (KernelFork.ofι f (by simp)) = Fork.ι s := ?_ · refine isLimitAux _ (fun A => limit.lift _ _ ≫ inv (imageMonoFactorisation f).e) aux ?_ intro A g hg rw [KernelFork.ι_ofι] at hg rw [← cancel_mono f, hg, ← aux, KernelFork.ι_ofι] · intro A simp only [KernelFork.ι_ofι, Category.assoc] convert limit.lift_π A WalkingParallelPair.zero using 2 rw [IsIso.inv_comp_eq, eq_comm] exact (imageMonoFactorisation f).fac }⟩ /-- A category with finite products in which coimage-image comparisons are all isomorphisms is a normal epi category. -/ lemma isNormalEpiCategory : IsNormalEpiCategory C where normalEpiOfEpi f m := ⟨{ W := kernel f g := kernel.ι _ w := kernel.condition _ isColimit := by haveI : Limits.HasImages C := hasImages haveI : HasEqualizers C := Preadditive.hasEqualizers_of_hasKernels haveI : HasZeroObject C := Limits.hasZeroObject_of_hasFiniteBiproducts _ have aux : ∀ (s : CokernelCofork (kernel.ι f)), Cofork.π (CokernelCofork.ofπ f (by simp)) ≫ inv (imageMonoFactorisation f).m ≫ inv (Abelian.coimageImageComparison f) ≫ colimit.desc (parallelPair (kernel.ι f) 0) s = Cofork.π s := ?_ · refine isColimitAux _ (fun A => inv (imageMonoFactorisation f).m ≫ inv (Abelian.coimageImageComparison f) ≫ colimit.desc _ _) aux ?_ intro A g hg rw [CokernelCofork.π_ofπ] at hg rw [← cancel_epi f, hg, ← aux, CokernelCofork.π_ofπ] · intro A simp only [CokernelCofork.π_ofπ, ← Category.assoc] convert colimit.ι_desc A WalkingParallelPair.one using 2 rw [IsIso.comp_inv_eq, IsIso.comp_inv_eq, eq_comm, ← imageMonoFactorisation_e'] exact (imageMonoFactorisation f).fac }⟩ end OfCoimageImageComparisonIsIso variable [∀ {X Y : C} (f : X ⟶ Y), IsIso (Abelian.coimageImageComparison f)] [Limits.HasFiniteProducts C] attribute [local instance] OfCoimageImageComparisonIsIso.isNormalMonoCategory attribute [local instance] OfCoimageImageComparisonIsIso.isNormalEpiCategory /-- A preadditive category with kernels, cokernels, and finite products, in which the coimage-image comparison morphism is always an isomorphism, is an abelian category. -/ @[stacks 0109 "The Stacks project uses this characterisation at the definition of an abelian category."] def ofCoimageImageComparisonIsIso : Abelian C where end CategoryTheory.Abelian namespace CategoryTheory.Abelian variable {C : Type u} [Category.{v} C] [Abelian C] -- Porting note: the below porting note is from mathlib3! -- Porting note: this should be an instance, -- but triggers https://github.com/leanprover/lean4/issues/2055 -- We set it as a local instance instead. -- instance (priority := 100) -- Turning it into a global instance breaks `Mathlib/Algebra/Category/ModuleCat/Sheaf/Free.lean`. /-- An abelian category has finite biproducts. -/ theorem hasFiniteBiproducts : HasFiniteBiproducts C := Limits.HasFiniteBiproducts.of_hasFiniteProducts attribute [local instance] hasFiniteBiproducts instance (priority := 100) hasBinaryBiproducts : HasBinaryBiproducts C := Limits.hasBinaryBiproducts_of_finite_biproducts _ instance (priority := 100) hasZeroObject : HasZeroObject C := hasZeroObject_of_hasInitial_object section ToNonPreadditiveAbelian /-- Every abelian category is, in particular, `NonPreadditiveAbelian`. -/ def nonPreadditiveAbelian : NonPreadditiveAbelian C := { ‹Abelian C› with } end ToNonPreadditiveAbelian section /-! We now promote some instances that were constructed using `non_preadditive_abelian`. -/ attribute [local instance] nonPreadditiveAbelian variable {P Q : C} (f : P ⟶ Q) /-- The map `p : P ⟶ image f` is an epimorphism -/ instance : Epi (Abelian.factorThruImage f) := by infer_instance instance isIso_factorThruImage [Mono f] : IsIso (Abelian.factorThruImage f) := by infer_instance /-- The canonical morphism `i : coimage f ⟶ Q` is a monomorphism -/ instance : Mono (Abelian.factorThruCoimage f) := by infer_instance instance isIso_factorThruCoimage [Epi f] : IsIso (Abelian.factorThruCoimage f) := by infer_instance end section Factor attribute [local instance] nonPreadditiveAbelian variable {P Q : C} (f : P ⟶ Q) section theorem mono_of_kernel_ι_eq_zero (h : kernel.ι f = 0) : Mono f := mono_of_kernel_zero h theorem epi_of_cokernel_π_eq_zero (h : cokernel.π f = 0) : Epi f := by apply NormalMonoCategory.epi_of_zero_cokernel _ (cokernel f) simp_rw [← h] exact IsColimit.ofIsoColimit (colimit.isColimit (parallelPair f 0)) (isoOfπ _) end section variable {f} theorem image_ι_comp_eq_zero {R : C} {g : Q ⟶ R} (h : f ≫ g = 0) : Abelian.image.ι f ≫ g = 0 := zero_of_epi_comp (Abelian.factorThruImage f) <| by simp [h] theorem comp_coimage_π_eq_zero {R : C} {g : Q ⟶ R} (h : f ≫ g = 0) : f ≫ Abelian.coimage.π g = 0 := zero_of_comp_mono (Abelian.factorThruCoimage g) <| by simp [h] end /-- Factoring through the image is a strong epi-mono factorisation. -/ @[simps] def imageStrongEpiMonoFactorisation : StrongEpiMonoFactorisation f where I := Abelian.image f m := image.ι f m_mono := by infer_instance e := Abelian.factorThruImage f e_strong_epi := strongEpi_of_epi _ /-- Factoring through the coimage is a strong epi-mono factorisation. -/ @[simps] def coimageStrongEpiMonoFactorisation : StrongEpiMonoFactorisation f where I := Abelian.coimage f m := Abelian.factorThruCoimage f m_mono := by infer_instance e := coimage.π f e_strong_epi := strongEpi_of_epi _ end Factor section HasStrongEpiMonoFactorisations /-- An abelian category has strong epi-mono factorisations. -/ instance (priority := 100) : HasStrongEpiMonoFactorisations C := HasStrongEpiMonoFactorisations.mk fun f => imageStrongEpiMonoFactorisation f -- In particular, this means that it has well-behaved images. example : HasImages C := by infer_instance example : HasImageMaps C := by infer_instance end HasStrongEpiMonoFactorisations section Images variable {X Y : C} (f : X ⟶ Y) /-- The coimage-image comparison morphism is always an isomorphism in an abelian category. See `CategoryTheory.Abelian.ofCoimageImageComparisonIsIso` for the converse. -/ instance : IsIso (coimageImageComparison f) := by convert Iso.isIso_hom (IsImage.isoExt (coimageStrongEpiMonoFactorisation f).toMonoIsImage (imageStrongEpiMonoFactorisation f).toMonoIsImage) ext change _ = _ ≫ (imageStrongEpiMonoFactorisation f).m simp [-imageStrongEpiMonoFactorisation_m] /-- There is a canonical isomorphism between the abelian coimage and the abelian image of a morphism. -/ abbrev coimageIsoImage : Abelian.coimage f ≅ Abelian.image f := asIso (coimageImageComparison f) /-- There is a canonical isomorphism between the abelian coimage and the categorical image of a morphism. -/ abbrev coimageIsoImage' : Abelian.coimage f ≅ image f := IsImage.isoExt (coimageStrongEpiMonoFactorisation f).toMonoIsImage (Image.isImage f) theorem coimageIsoImage'_hom : (coimageIsoImage' f).hom = cokernel.desc _ (factorThruImage f) (by simp [← cancel_mono (Limits.image.ι f)]) := by ext simp only [← cancel_mono (Limits.image.ι f), IsImage.isoExt_hom, cokernel.π_desc, Category.assoc, IsImage.lift_ι, coimageStrongEpiMonoFactorisation_m, Limits.image.fac] theorem factorThruImage_comp_coimageIsoImage'_inv : factorThruImage f ≫ (coimageIsoImage' f).inv = cokernel.π _ := by simp only [IsImage.isoExt_inv, image.isImage_lift, image.fac_lift, coimageStrongEpiMonoFactorisation_e] /-- There is a canonical isomorphism between the abelian image and the categorical image of a morphism. -/ abbrev imageIsoImage : Abelian.image f ≅ image f := IsImage.isoExt (imageStrongEpiMonoFactorisation f).toMonoIsImage (Image.isImage f) theorem imageIsoImage_hom_comp_image_ι : (imageIsoImage f).hom ≫ Limits.image.ι _ = kernel.ι _ := by simp only [IsImage.isoExt_hom, IsImage.lift_ι, imageStrongEpiMonoFactorisation_m] theorem imageIsoImage_inv : (imageIsoImage f).inv = kernel.lift _ (Limits.image.ι f) (by simp [← cancel_epi (factorThruImage f)]) := by ext rw [IsImage.isoExt_inv, image.isImage_lift, Limits.image.fac_lift, imageStrongEpiMonoFactorisation_e, Category.assoc, kernel.lift_ι, equalizer_as_kernel, kernel.lift_ι, Limits.image.fac] end Images section CokernelOfKernel variable {X Y : C} {f : X ⟶ Y} attribute [local instance] nonPreadditiveAbelian /-- In an abelian category, an epi is the cokernel of its kernel. More precisely: If `f` is an epimorphism and `s` is some limit kernel cone on `f`, then `f` is a cokernel of `fork.ι s`. -/ def epiIsCokernelOfKernel [Epi f] (s : Fork f 0) (h : IsLimit s) : IsColimit (CokernelCofork.ofπ f (KernelFork.condition s)) := NonPreadditiveAbelian.epiIsCokernelOfKernel s h /-- In an abelian category, a mono is the kernel of its cokernel. More precisely: If `f` is a monomorphism and `s` is some colimit cokernel cocone on `f`, then `f` is a kernel of `cofork.π s`. -/ def monoIsKernelOfCokernel [Mono f] (s : Cofork f 0) (h : IsColimit s) : IsLimit (KernelFork.ofι f (CokernelCofork.condition s)) := NonPreadditiveAbelian.monoIsKernelOfCokernel s h variable (f) /-- In an abelian category, any morphism that turns to zero when precomposed with the kernel of an epimorphism factors through that epimorphism. -/ def epiDesc [Epi f] {T : C} (g : X ⟶ T) (hg : kernel.ι f ≫ g = 0) : Y ⟶ T := (epiIsCokernelOfKernel _ (limit.isLimit _)).desc (CokernelCofork.ofπ _ hg) @[reassoc (attr := simp)] theorem comp_epiDesc [Epi f] {T : C} (g : X ⟶ T) (hg : kernel.ι f ≫ g = 0) : f ≫ epiDesc f g hg = g := (epiIsCokernelOfKernel _ (limit.isLimit _)).fac (CokernelCofork.ofπ _ hg) WalkingParallelPair.one /-- In an abelian category, any morphism that turns to zero when postcomposed with the cokernel of a monomorphism factors through that monomorphism. -/ def monoLift [Mono f] {T : C} (g : T ⟶ Y) (hg : g ≫ cokernel.π f = 0) : T ⟶ X := (monoIsKernelOfCokernel _ (colimit.isColimit _)).lift (KernelFork.ofι _ hg) @[reassoc (attr := simp)] theorem monoLift_comp [Mono f] {T : C} (g : T ⟶ Y) (hg : g ≫ cokernel.π f = 0) : monoLift f g hg ≫ f = g := (monoIsKernelOfCokernel _ (colimit.isColimit _)).fac (KernelFork.ofι _ hg) WalkingParallelPair.zero section variable {D : Type*} [Category D] [HasZeroMorphisms D] /-- If `F : D ⥤ C` is a functor to an abelian category, `i : X ⟶ Y` is a morphism admitting a cokernel such that `F` preserves this cokernel and `F.map i` is a mono, then `F.map X` identifies to the kernel of `F.map (cokernel.π i)`. -/ noncomputable def isLimitMapConeOfKernelForkOfι {X Y : D} (i : X ⟶ Y) [HasCokernel i] (F : D ⥤ C) [F.PreservesZeroMorphisms] [Mono (F.map i)] [PreservesColimit (parallelPair i 0) F] : IsLimit (F.mapCone (KernelFork.ofι i (cokernel.condition i))) := by let e : parallelPair (cokernel.π (F.map i)) 0 ≅ parallelPair (cokernel.π i) 0 ⋙ F := parallelPair.ext (Iso.refl _) (asIso (cokernelComparison i F)) (by simp) (by simp) refine IsLimit.postcomposeInvEquiv e _ ?_ let hi := Abelian.monoIsKernelOfCokernel _ (cokernelIsCokernel (F.map i)) refine IsLimit.ofIsoLimit hi (Fork.ext (Iso.refl _) ?_) change 𝟙 _ ≫ F.map i ≫ 𝟙 _ = F.map i rw [Category.comp_id, Category.id_comp] /-- If `F : D ⥤ C` is a functor to an abelian category, `p : X ⟶ Y` is a morphisms admitting a kernel such that `F` preserves this kernel and `F.map p` is an epi, then `F.map Y` identifies to the cokernel of `F.map (kernel.ι p)`. -/ noncomputable def isColimitMapCoconeOfCokernelCoforkOfπ {X Y : D} (p : X ⟶ Y) [HasKernel p] (F : D ⥤ C) [F.PreservesZeroMorphisms] [Epi (F.map p)] [PreservesLimit (parallelPair p 0) F] : IsColimit (F.mapCocone (CokernelCofork.ofπ p (kernel.condition p))) := by let e : parallelPair (kernel.ι p) 0 ⋙ F ≅ parallelPair (kernel.ι (F.map p)) 0 := parallelPair.ext (asIso (kernelComparison p F)) (Iso.refl _) (by simp) (by simp) refine IsColimit.precomposeInvEquiv e _ ?_ let hp := Abelian.epiIsCokernelOfKernel _ (kernelIsKernel (F.map p)) refine IsColimit.ofIsoColimit hp (Cofork.ext (Iso.refl _) ?_) change F.map p ≫ 𝟙 _ = 𝟙 _ ≫ F.map p rw [Category.comp_id, Category.id_comp] end end CokernelOfKernel section instance (priority := 100) hasEqualizers : HasEqualizers C := Preadditive.hasEqualizers_of_hasKernels /-- Any abelian category has pullbacks -/ instance (priority := 100) hasPullbacks : HasPullbacks C := hasPullbacks_of_hasBinaryProducts_of_hasEqualizers C end section instance (priority := 100) hasCoequalizers : HasCoequalizers C := Preadditive.hasCoequalizers_of_hasCokernels /-- Any abelian category has pushouts -/ instance (priority := 100) hasPushouts : HasPushouts C := hasPushouts_of_hasBinaryCoproducts_of_hasCoequalizers C instance (priority := 100) hasFiniteLimits : HasFiniteLimits C := Limits.hasFiniteLimits_of_hasEqualizers_and_finite_products instance (priority := 100) hasFiniteColimits : HasFiniteColimits C := Limits.hasFiniteColimits_of_hasCoequalizers_and_finite_coproducts end namespace PullbackToBiproductIsKernel variable [Limits.HasPullbacks C] {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) /-! This section contains a slightly technical result about pullbacks and biproducts. We will need it in the proof that the pullback of an epimorphism is an epimorphism. -/ /-- The canonical map `pullback f g ⟶ X ⊞ Y` -/ abbrev pullbackToBiproduct : pullback f g ⟶ X ⊞ Y := biprod.lift (pullback.fst f g) (pullback.snd f g) /-- The canonical map `pullback f g ⟶ X ⊞ Y` induces a kernel cone on the map `biproduct X Y ⟶ Z` induced by `f` and `g`. A slightly more intuitive way to think of this may be that it induces an equalizer fork on the maps induced by `(f, 0)` and `(0, g)`. -/ abbrev pullbackToBiproductFork : KernelFork (biprod.desc f (-g)) := KernelFork.ofι (pullbackToBiproduct f g) <| by rw [biprod.lift_desc, comp_neg, pullback.condition, add_neg_cancel] /-- The canonical map `pullback f g ⟶ X ⊞ Y` is a kernel of the map induced by `(f, -g)`. -/ def isLimitPullbackToBiproduct : IsLimit (pullbackToBiproductFork f g) := Fork.IsLimit.mk _ (fun s => pullback.lift (Fork.ι s ≫ biprod.fst) (Fork.ι s ≫ biprod.snd) <| sub_eq_zero.1 <| by rw [Category.assoc, Category.assoc, ← comp_sub, sub_eq_add_neg, ← comp_neg, ← biprod.desc_eq, KernelFork.condition s]) (fun s => by apply biprod.hom_ext <;> rw [Fork.ι_ofι, Category.assoc] · rw [biprod.lift_fst, pullback.lift_fst] · rw [biprod.lift_snd, pullback.lift_snd]) fun s m h => by apply pullback.hom_ext <;> simp [← h] end PullbackToBiproductIsKernel namespace BiproductToPushoutIsCokernel variable [Limits.HasPushouts C] {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) /-- The canonical map `Y ⊞ Z ⟶ pushout f g` -/ abbrev biproductToPushout : Y ⊞ Z ⟶ pushout f g := biprod.desc (pushout.inl _ _) (pushout.inr _ _) /-- The canonical map `Y ⊞ Z ⟶ pushout f g` induces a cokernel cofork on the map `X ⟶ Y ⊞ Z` induced by `f` and `-g`. -/ abbrev biproductToPushoutCofork : CokernelCofork (biprod.lift f (-g)) := CokernelCofork.ofπ (biproductToPushout f g) <| by rw [biprod.lift_desc, neg_comp, pushout.condition, add_neg_cancel] /-- The cofork induced by the canonical map `Y ⊞ Z ⟶ pushout f g` is in fact a colimit cokernel cofork. -/ def isColimitBiproductToPushout : IsColimit (biproductToPushoutCofork f g) := Cofork.IsColimit.mk _ (fun s => pushout.desc (biprod.inl ≫ Cofork.π s) (biprod.inr ≫ Cofork.π s) <| sub_eq_zero.1 <| by rw [← Category.assoc, ← Category.assoc, ← sub_comp, sub_eq_add_neg, ← neg_comp, ← biprod.lift_eq, Cofork.condition s, zero_comp]) (fun s => by apply biprod.hom_ext' <;> simp) fun s m h => by apply pushout.hom_ext <;> simp [← h] end BiproductToPushoutIsCokernel section EpiPullback variable [Limits.HasPullbacks C] {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) /-- In an abelian category, the pullback of an epimorphism is an epimorphism. Proof from [aluffi2016, IX.2.3], cf. [borceux-vol2, 1.7.6] -/ instance epi_pullback_of_epi_f [Epi f] : Epi (pullback.snd f g) := -- It will suffice to consider some morphism e : Y ⟶ R such that -- pullback.snd f g ≫ e = 0 and show that e = 0. epi_of_cancel_zero _ fun {R} e h => by -- Consider the morphism u := (0, e) : X ⊞ Y⟶ R. let u := biprod.desc (0 : X ⟶ R) e -- The composite pullback f g ⟶ X ⊞ Y ⟶ R is zero by assumption. have hu : PullbackToBiproductIsKernel.pullbackToBiproduct f g ≫ u = 0 := by simpa [u] -- pullbackToBiproduct f g is a kernel of (f, -g), so (f, -g) is a -- cokernel of pullbackToBiproduct f g have := epiIsCokernelOfKernel _ (PullbackToBiproductIsKernel.isLimitPullbackToBiproduct f g) -- We use this fact to obtain a factorization of u through (f, -g) via some d : Z ⟶ R. obtain ⟨d, hd⟩ := CokernelCofork.IsColimit.desc' this u hu dsimp at d; dsimp [u] at hd -- But then f ≫ d = 0: have : f ≫ d = 0 := calc f ≫ d = (biprod.inl ≫ biprod.desc f (-g)) ≫ d := by rw [biprod.inl_desc] _ = biprod.inl ≫ u := by rw [Category.assoc, hd] _ = 0 := biprod.inl_desc _ _ -- But f is an epimorphism, so d = 0... have : d = 0 := (cancel_epi f).1 (by simpa) -- ...or, in other words, e = 0. calc e = biprod.inr ≫ biprod.desc (0 : X ⟶ R) e := by rw [biprod.inr_desc] _ = biprod.inr ≫ biprod.desc f (-g) ≫ d := by rw [← hd] _ = biprod.inr ≫ biprod.desc f (-g) ≫ 0 := by rw [this] _ = (biprod.inr ≫ biprod.desc f (-g)) ≫ 0 := by rw [← Category.assoc] _ = 0 := HasZeroMorphisms.comp_zero _ _ /-- In an abelian category, the pullback of an epimorphism is an epimorphism. -/ instance epi_pullback_of_epi_g [Epi g] : Epi (pullback.fst f g) := -- It will suffice to consider some morphism e : X ⟶ R such that -- pullback.fst f g ≫ e = 0 and show that e = 0. epi_of_cancel_zero _ fun {R} e h => by -- Consider the morphism u := (e, 0) : X ⊞ Y ⟶ R. let u := biprod.desc e (0 : Y ⟶ R) -- The composite pullback f g ⟶ X ⊞ Y ⟶ R is zero by assumption. have hu : PullbackToBiproductIsKernel.pullbackToBiproduct f g ≫ u = 0 := by simpa [u] -- pullbackToBiproduct f g is a kernel of (f, -g), so (f, -g) is a -- cokernel of pullbackToBiproduct f g have := epiIsCokernelOfKernel _ (PullbackToBiproductIsKernel.isLimitPullbackToBiproduct f g) -- We use this fact to obtain a factorization of u through (f, -g) via some d : Z ⟶ R. obtain ⟨d, hd⟩ := CokernelCofork.IsColimit.desc' this u hu dsimp at d; dsimp [u] at hd -- But then (-g) ≫ d = 0: have : (-g) ≫ d = 0 := calc (-g) ≫ d = (biprod.inr ≫ biprod.desc f (-g)) ≫ d := by rw [biprod.inr_desc] _ = biprod.inr ≫ u := by rw [Category.assoc, hd] _ = 0 := biprod.inr_desc _ _ -- But g is an epimorphism, thus so is -g, so d = 0... have : d = 0 := (cancel_epi (-g)).1 (by simpa) -- ...or, in other words, e = 0. calc e = biprod.inl ≫ biprod.desc e (0 : Y ⟶ R) := by rw [biprod.inl_desc] _ = biprod.inl ≫ biprod.desc f (-g) ≫ d := by rw [← hd] _ = biprod.inl ≫ biprod.desc f (-g) ≫ 0 := by rw [this] _ = (biprod.inl ≫ biprod.desc f (-g)) ≫ 0 := by rw [← Category.assoc] _ = 0 := HasZeroMorphisms.comp_zero _ _ theorem epi_snd_of_isLimit [Epi f] {s : PullbackCone f g} (hs : IsLimit s) : Epi s.snd := by haveI : Epi (NatTrans.app (limit.cone (cospan f g)).π WalkingCospan.right) := Abelian.epi_pullback_of_epi_f f g apply epi_of_epi_fac (IsLimit.conePointUniqueUpToIso_hom_comp (limit.isLimit _) hs _) theorem epi_fst_of_isLimit [Epi g] {s : PullbackCone f g} (hs : IsLimit s) : Epi s.fst := by haveI : Epi (NatTrans.app (limit.cone (cospan f g)).π WalkingCospan.left) := Abelian.epi_pullback_of_epi_g f g apply epi_of_epi_fac (IsLimit.conePointUniqueUpToIso_hom_comp (limit.isLimit _) hs _) /-- Suppose `f` and `g` are two morphisms with a common codomain and suppose we have written `g` as an epimorphism followed by a monomorphism. If `f` factors through the mono part of this factorization, then any pullback of `g` along `f` is an epimorphism. -/ theorem epi_fst_of_factor_thru_epi_mono_factorization (g₁ : Y ⟶ W) [Epi g₁] (g₂ : W ⟶ Z) [Mono g₂] (hg : g₁ ≫ g₂ = g) (f' : X ⟶ W) (hf : f' ≫ g₂ = f) (t : PullbackCone f g) (ht : IsLimit t) : Epi t.fst := by apply epi_fst_of_isLimit _ _ (PullbackCone.isLimitOfFactors f g g₂ f' g₁ hf hg t ht) end EpiPullback section MonoPushout variable [Limits.HasPushouts C] {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) instance mono_pushout_of_mono_f [Mono f] : Mono (pushout.inr _ _ : Z ⟶ pushout f g) := mono_of_cancel_zero _ fun {R} e h => by let u := biprod.lift (0 : R ⟶ Y) e have hu : u ≫ BiproductToPushoutIsCokernel.biproductToPushout f g = 0 := by simpa [u] have := monoIsKernelOfCokernel _ (BiproductToPushoutIsCokernel.isColimitBiproductToPushout f g) obtain ⟨d, hd⟩ := KernelFork.IsLimit.lift' this u hu dsimp at d dsimp [u] at hd have : d ≫ f = 0 := calc d ≫ f = d ≫ biprod.lift f (-g) ≫ biprod.fst := by rw [biprod.lift_fst] _ = u ≫ biprod.fst := by rw [← Category.assoc, hd] _ = 0 := biprod.lift_fst _ _ have : d = 0 := (cancel_mono f).1 (by simpa) calc e = biprod.lift (0 : R ⟶ Y) e ≫ biprod.snd := by rw [biprod.lift_snd] _ = (d ≫ biprod.lift f (-g)) ≫ biprod.snd := by rw [← hd] _ = (0 ≫ biprod.lift f (-g)) ≫ biprod.snd := by rw [this] _ = 0 ≫ biprod.lift f (-g) ≫ biprod.snd := by rw [Category.assoc] _ = 0 := zero_comp instance mono_pushout_of_mono_g [Mono g] : Mono (pushout.inl f g) := mono_of_cancel_zero _ fun {R} e h => by let u := biprod.lift e (0 : R ⟶ Z) have hu : u ≫ BiproductToPushoutIsCokernel.biproductToPushout f g = 0 := by simpa [u] have := monoIsKernelOfCokernel _ (BiproductToPushoutIsCokernel.isColimitBiproductToPushout f g) obtain ⟨d, hd⟩ := KernelFork.IsLimit.lift' this u hu dsimp at d dsimp [u] at hd have : d ≫ (-g) = 0 := calc d ≫ (-g) = d ≫ biprod.lift f (-g) ≫ biprod.snd := by rw [biprod.lift_snd] _ = biprod.lift e (0 : R ⟶ Z) ≫ biprod.snd := by rw [← Category.assoc, hd] _ = 0 := biprod.lift_snd _ _ have : d = 0 := (cancel_mono (-g)).1 (by simpa) calc e = biprod.lift e (0 : R ⟶ Z) ≫ biprod.fst := by rw [biprod.lift_fst] _ = (d ≫ biprod.lift f (-g)) ≫ biprod.fst := by rw [← hd] _ = (0 ≫ biprod.lift f (-g)) ≫ biprod.fst := by rw [this] _ = 0 ≫ biprod.lift f (-g) ≫ biprod.fst := by rw [Category.assoc] _ = 0 := zero_comp theorem mono_inr_of_isColimit [Mono f] {s : PushoutCocone f g} (hs : IsColimit s) : Mono s.inr := by haveI : Mono (NatTrans.app (colimit.cocone (span f g)).ι WalkingCospan.right) := Abelian.mono_pushout_of_mono_f f g apply mono_of_mono_fac (IsColimit.comp_coconePointUniqueUpToIso_hom hs (colimit.isColimit _) _) theorem mono_inl_of_isColimit [Mono g] {s : PushoutCocone f g} (hs : IsColimit s) : Mono s.inl := by haveI : Mono (NatTrans.app (colimit.cocone (span f g)).ι WalkingCospan.left) := Abelian.mono_pushout_of_mono_g f g apply mono_of_mono_fac (IsColimit.comp_coconePointUniqueUpToIso_hom hs (colimit.isColimit _) _) /-- Suppose `f` and `g` are two morphisms with a common domain and suppose we have written `g` as an epimorphism followed by a monomorphism. If `f` factors through the epi part of this factorization, then any pushout of `g` along `f` is a monomorphism. -/ theorem mono_inl_of_factor_thru_epi_mono_factorization (f : X ⟶ Y) (g : X ⟶ Z) (g₁ : X ⟶ W) [Epi g₁] (g₂ : W ⟶ Z) [Mono g₂] (hg : g₁ ≫ g₂ = g) (f' : W ⟶ Y) (hf : g₁ ≫ f' = f) (t : PushoutCocone f g) (ht : IsColimit t) : Mono t.inl := by apply mono_inl_of_isColimit _ _ (PushoutCocone.isColimitOfFactors _ _ _ _ _ hf hg t ht) end MonoPushout end CategoryTheory.Abelian namespace CategoryTheory.NonPreadditiveAbelian variable (C : Type u) [Category.{v} C] [NonPreadditiveAbelian C] /-- Every NonPreadditiveAbelian category can be promoted to an abelian category. -/ def abelian : Abelian C where toPreadditive := NonPreadditiveAbelian.preadditive normalMonoOfMono := fun f _ ↦ ⟨normalMonoOfMono f⟩ normalEpiOfEpi := fun f _ ↦ ⟨normalEpiOfEpi f⟩ end CategoryTheory.NonPreadditiveAbelian
Generators.lean
import Mathlib.RingTheory.Extension.Generators deprecated_module (since := "2025-05-11")
Class.lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.SetTheory.ZFC.Ordinal /-! # ZFC classes Classes in set theory are usually defined as collections of elements satisfying some property. Here, however, we define `Class` as `Set ZFSet` to derive many instances automatically, most of them being the lifting of set operations to classes. The usual definition is then definitionally equal to ours. ## Main definitions * `Class`: Defined as `Set ZFSet`. * `Class.iota`: Definite description operator. * `ZFSet.isOrdinal_notMem_univ`: The Burali-Forti paradox. Ordinals form a proper class. -/ universe u /-- The collection of all classes. We define `Class` as `Set ZFSet`, as this allows us to get many instances automatically. However, in practice, we treat it as (the definitionally equal) `ZFSet → Prop`. This means, the preferred way to state that `x : ZFSet` belongs to `A : Class` is to write `A x`. -/ @[pp_with_univ] def Class := Set ZFSet deriving HasSubset, EmptyCollection, Nonempty, Union, Inter, HasCompl, SDiff instance : Insert ZFSet Class := ⟨Set.insert⟩ namespace Class -- Porting note: this used to be a `deriving HasSep Set` instance, -- it should probably be turned into notation. /-- `{x ∈ A | p x}` is the class of elements in `A` satisfying `p` -/ protected def sep (p : ZFSet → Prop) (A : Class) : Class := {y | A y ∧ p y} @[ext] theorem ext {x y : Class.{u}} : (∀ z : ZFSet.{u}, x z ↔ y z) → x = y := Set.ext /-- Coerce a ZFC set into a class -/ @[coe] def ofSet (x : ZFSet.{u}) : Class.{u} := { y | y ∈ x } instance : Coe ZFSet Class := ⟨ofSet⟩ /-- The universal class -/ def univ : Class := Set.univ /-- Assert that `A` is a ZFC set satisfying `B` -/ def ToSet (B : Class.{u}) (A : Class.{u}) : Prop := ∃ x : ZFSet, ↑x = A ∧ B x /-- `A ∈ B` if `A` is a ZFC set which satisfies `B` -/ protected def Mem (B A : Class.{u}) : Prop := ToSet.{u} B A instance : Membership Class Class := ⟨Class.Mem⟩ theorem mem_def (A B : Class.{u}) : A ∈ B ↔ ∃ x : ZFSet, ↑x = A ∧ B x := Iff.rfl @[simp] theorem notMem_empty (x : Class.{u}) : x ∉ (∅ : Class.{u}) := fun ⟨_, _, h⟩ => h @[deprecated (since := "2025-05-23")] alias not_mem_empty := notMem_empty @[simp] theorem not_empty_hom (x : ZFSet.{u}) : ¬(∅ : Class.{u}) x := id @[simp] theorem mem_univ {A : Class.{u}} : A ∈ univ.{u} ↔ ∃ x : ZFSet.{u}, ↑x = A := exists_congr fun _ => iff_of_eq (and_true _) @[simp] theorem mem_univ_hom (x : ZFSet.{u}) : univ.{u} x := trivial theorem eq_univ_iff_forall {A : Class.{u}} : A = univ ↔ ∀ x : ZFSet, A x := Set.eq_univ_iff_forall theorem eq_univ_of_forall {A : Class.{u}} : (∀ x : ZFSet, A x) → A = univ := Set.eq_univ_of_forall theorem mem_wf : @WellFounded Class.{u} (· ∈ ·) := ⟨by have H : ∀ x : ZFSet.{u}, @Acc Class.{u} (· ∈ ·) ↑x := by refine fun a => ZFSet.inductionOn a fun x IH => ⟨_, ?_⟩ rintro A ⟨z, rfl, hz⟩ exact IH z hz refine fun A => ⟨A, ?_⟩ rintro B ⟨x, rfl, _⟩ exact H x⟩ instance : IsWellFounded Class (· ∈ ·) := ⟨mem_wf⟩ instance : WellFoundedRelation Class := ⟨_, mem_wf⟩ theorem mem_asymm {x y : Class} : x ∈ y → y ∉ x := asymm_of (· ∈ ·) theorem mem_irrefl (x : Class) : x ∉ x := irrefl_of (· ∈ ·) x /-- **There is no universal set.** This is stated as `univ ∉ univ`, meaning that `univ` (the class of all sets) is proper (does not belong to the class of all sets). -/ theorem univ_notMem_univ : univ ∉ univ := mem_irrefl _ @[deprecated (since := "2025-05-23")] alias univ_not_mem_univ := univ_notMem_univ /-- Convert a conglomerate (a collection of classes) into a class -/ def congToClass (x : Set Class.{u}) : Class.{u} := { y | ↑y ∈ x } @[simp] theorem congToClass_empty : congToClass ∅ = ∅ := by ext z simp only [congToClass, not_empty_hom, iff_false] exact Set.notMem_empty z /-- Convert a class into a conglomerate (a collection of classes) -/ def classToCong (x : Class.{u}) : Set Class.{u} := { y | y ∈ x } @[simp] theorem classToCong_empty : classToCong ∅ = ∅ := by ext simp [classToCong] /-- The power class of a class is the class of all subclasses that are ZFC sets -/ def powerset (x : Class) : Class := congToClass (Set.powerset x) /-- The union of a class is the class of all members of ZFC sets in the class. Uses `⋃₀` notation, scoped under the `Class` namespace. -/ def sUnion (x : Class) : Class := ⋃₀ classToCong x @[inherit_doc] scoped prefix:110 "⋃₀ " => Class.sUnion /-- The intersection of a class is the class of all members of ZFC sets in the class . Uses `⋂₀` notation, scoped under the `Class` namespace. -/ def sInter (x : Class) : Class := ⋂₀ classToCong x @[inherit_doc] scoped prefix:110 "⋂₀ " => Class.sInter theorem ofSet.inj {x y : ZFSet.{u}} (h : (x : Class.{u}) = y) : x = y := ZFSet.ext fun z => by change (x : Class.{u}) z ↔ (y : Class.{u}) z rw [h] @[simp] theorem toSet_of_ZFSet (A : Class.{u}) (x : ZFSet.{u}) : ToSet A x ↔ A x := ⟨fun ⟨y, yx, py⟩ => by rwa [ofSet.inj yx] at py, fun px => ⟨x, rfl, px⟩⟩ @[simp, norm_cast] theorem coe_mem {x : ZFSet.{u}} {A : Class.{u}} : ↑x ∈ A ↔ A x := toSet_of_ZFSet _ _ @[simp] theorem coe_apply {x y : ZFSet.{u}} : (y : Class.{u}) x ↔ x ∈ y := Iff.rfl @[simp, norm_cast] theorem coe_subset (x y : ZFSet.{u}) : (x : Class.{u}) ⊆ y ↔ x ⊆ y := Iff.rfl @[simp, norm_cast] theorem coe_sep (p : Class.{u}) (x : ZFSet.{u}) : (ZFSet.sep p x : Class) = { y ∈ x | p y } := ext fun _ => ZFSet.mem_sep @[simp, norm_cast] theorem coe_empty : ↑(∅ : ZFSet.{u}) = (∅ : Class.{u}) := ext fun y => iff_false _ ▸ ZFSet.notMem_empty y @[simp, norm_cast] theorem coe_insert (x y : ZFSet.{u}) : ↑(insert x y) = @insert ZFSet.{u} Class.{u} _ x y := ext fun _ => ZFSet.mem_insert_iff @[simp, norm_cast] theorem coe_union (x y : ZFSet.{u}) : ↑(x ∪ y) = (x : Class.{u}) ∪ y := ext fun _ => ZFSet.mem_union @[simp, norm_cast] theorem coe_inter (x y : ZFSet.{u}) : ↑(x ∩ y) = (x : Class.{u}) ∩ y := ext fun _ => ZFSet.mem_inter @[simp, norm_cast] theorem coe_diff (x y : ZFSet.{u}) : ↑(x \ y) = (x : Class.{u}) \ y := ext fun _ => ZFSet.mem_diff @[simp, norm_cast] theorem coe_powerset (x : ZFSet.{u}) : ↑x.powerset = powerset.{u} x := ext fun _ => ZFSet.mem_powerset @[simp] theorem powerset_apply {A : Class.{u}} {x : ZFSet.{u}} : powerset A x ↔ ↑x ⊆ A := Iff.rfl @[simp] theorem sUnion_apply {x : Class} {y : ZFSet} : (⋃₀ x) y ↔ ∃ z : ZFSet, x z ∧ y ∈ z := by constructor · rintro ⟨-, ⟨z, rfl, hxz⟩, hyz⟩ exact ⟨z, hxz, hyz⟩ · exact fun ⟨z, hxz, hyz⟩ => ⟨_, coe_mem.2 hxz, hyz⟩ open scoped ZFSet in @[simp, norm_cast] theorem coe_sUnion (x : ZFSet.{u}) : ↑(⋃₀ x : ZFSet) = ⋃₀ (x : Class.{u}) := ext fun y => ZFSet.mem_sUnion.trans (sUnion_apply.trans <| by rfl).symm @[simp] theorem mem_sUnion {x y : Class.{u}} : y ∈ ⋃₀ x ↔ ∃ z, z ∈ x ∧ y ∈ z := by constructor · rintro ⟨w, rfl, z, hzx, hwz⟩ exact ⟨z, hzx, coe_mem.2 hwz⟩ · rintro ⟨w, hwx, z, rfl, hwz⟩ exact ⟨z, rfl, w, hwx, hwz⟩ theorem sInter_apply {x : Class.{u}} {y : ZFSet.{u}} : (⋂₀ x) y ↔ ∀ z : ZFSet.{u}, x z → y ∈ z := by refine ⟨fun hxy z hxz => hxy _ ⟨z, rfl, hxz⟩, ?_⟩ rintro H - ⟨z, rfl, hxz⟩ exact H _ hxz open scoped ZFSet in @[simp, norm_cast] theorem coe_sInter {x : ZFSet.{u}} (h : x.Nonempty) : ↑(⋂₀ x : ZFSet) = ⋂₀ (x : Class.{u}) := Set.ext fun _ => (ZFSet.mem_sInter h).trans sInter_apply.symm theorem mem_of_mem_sInter {x y z : Class} (hy : y ∈ ⋂₀ x) (hz : z ∈ x) : y ∈ z := by obtain ⟨w, rfl, hw⟩ := hy exact coe_mem.2 (hw z hz) theorem mem_sInter {x y : Class.{u}} (h : x.Nonempty) : y ∈ ⋂₀ x ↔ ∀ z, z ∈ x → y ∈ z := by refine ⟨fun hy z => mem_of_mem_sInter hy, fun H => ?_⟩ simp_rw [mem_def, sInter_apply] obtain ⟨z, hz⟩ := h obtain ⟨y, rfl, _⟩ := H z (coe_mem.2 hz) refine ⟨y, rfl, fun w hxw => ?_⟩ simpa only [coe_mem, coe_apply] using H w (coe_mem.2 hxw) @[simp] theorem sUnion_empty : ⋃₀ (∅ : Class.{u}) = (∅ : Class.{u}) := by ext simp @[simp] theorem sInter_empty : ⋂₀ (∅ : Class.{u}) = univ := by rw [sInter, classToCong_empty, Set.sInter_empty, univ] /-- An induction principle for sets. If every subset of a class is a member, then the class is universal. -/ theorem eq_univ_of_powerset_subset {A : Class} (hA : powerset A ⊆ A) : A = univ := eq_univ_of_forall (by by_contra! hnA exact WellFounded.min_mem ZFSet.mem_wf _ hnA (hA fun x hx => Classical.not_not.1 fun hB => WellFounded.not_lt_min ZFSet.mem_wf _ hnA hB <| coe_apply.1 hx)) /-- The definite description operator, which is `{x}` if `{y | A y} = {x}` and `∅` otherwise. -/ def iota (A : Class) : Class := ⋃₀ ({ x | ∀ y, A y ↔ y = x } : Class) theorem iota_val (A : Class) (x : ZFSet) (H : ∀ y, A y ↔ y = x) : iota A = ↑x := ext fun y => ⟨fun ⟨_, ⟨x', rfl, h⟩, yx'⟩ => by rwa [← (H x').1 <| (h x').2 rfl], fun yx => ⟨_, ⟨x, rfl, H⟩, yx⟩⟩ /-- Unlike the other set constructors, the `iota` definite descriptor is a set for any set input, but not constructively so, so there is no associated `Class → Set` function. -/ theorem iota_ex (A) : iota.{u} A ∈ univ.{u} := mem_univ.2 <| Or.elim (Classical.em <| ∃ x, ∀ y, A y ↔ y = x) (fun ⟨x, h⟩ => ⟨x, Eq.symm <| iota_val A x h⟩) fun hn => ⟨∅, ext fun _ => coe_empty.symm ▸ ⟨False.rec, fun ⟨_, ⟨x, rfl, H⟩, _⟩ => hn ⟨x, H⟩⟩⟩ /-- Function value -/ def fval (F A : Class.{u}) : Class.{u} := iota fun y => ToSet (fun x => F (ZFSet.pair x y)) A @[inherit_doc] infixl:100 " ′ " => fval theorem fval_ex (F A : Class.{u}) : F ′ A ∈ univ.{u} := iota_ex _ end Class namespace ZFSet @[simp] theorem map_fval {f : ZFSet.{u} → ZFSet.{u}} [Definable₁ f] {x y : ZFSet.{u}} (h : y ∈ x) : (ZFSet.map f x ′ y : Class.{u}) = f y := Class.iota_val _ _ fun z => by rw [Class.toSet_of_ZFSet, Class.coe_apply, mem_map] exact ⟨fun ⟨w, _, pr⟩ => by let ⟨wy, fw⟩ := ZFSet.pair_injective pr rw [← fw, wy], fun e => by subst e exact ⟨_, h, rfl⟩⟩ variable (x : ZFSet.{u}) /-- A choice function on the class of nonempty ZFC sets. -/ noncomputable def choice : ZFSet := @map (fun y => Classical.epsilon fun z => z ∈ y) (Classical.allZFSetDefinable _) x theorem choice_mem_aux (h : ∅ ∉ x) (y : ZFSet.{u}) (yx : y ∈ x) : (Classical.epsilon fun z : ZFSet.{u} => z ∈ y) ∈ y := (@Classical.epsilon_spec _ fun z : ZFSet.{u} => z ∈ y) <| by_contradiction fun n => h <| by rwa [← (eq_empty y).2 fun z zx => n ⟨z, zx⟩] theorem choice_isFunc (h : ∅ ∉ x) : IsFunc x (⋃₀ x) (choice x) := (@map_isFunc _ (Classical.allZFSetDefinable _) _ _).2 fun y yx => mem_sUnion.2 ⟨y, yx, choice_mem_aux x h y yx⟩ theorem choice_mem (h : ∅ ∉ x) (y : ZFSet.{u}) (yx : y ∈ x) : (choice x ′ y : Class.{u}) ∈ (y : Class.{u}) := by delta choice rw [@map_fval _ (Classical.allZFSetDefinable _) x y yx, Class.coe_mem, Class.coe_apply] exact choice_mem_aux x h y yx private lemma toSet_equiv_aux {s : Set ZFSet.{u}} (hs : Small.{u} s) : (mk <| PSet.mk (Shrink s) fun x ↦ ((equivShrink s).symm x).1.out).toSet = s := by ext x rw [mem_toSet, ← mk_out x, mk_mem_iff, mk_out] refine ⟨?_, fun xs ↦ ⟨equivShrink s (Subtype.mk x xs), ?_⟩⟩ · rintro ⟨b, h2⟩ rw [← ZFSet.eq, ZFSet.mk_out] at h2 simp [h2] · simp [PSet.Equiv.refl] /-- `ZFSet.toSet` as an equivalence. -/ @[simps apply_coe] noncomputable def toSet_equiv : ZFSet.{u} ≃ {s : Set ZFSet.{u} // Small.{u, u+1} s} where toFun x := ⟨x.toSet, x.small_toSet⟩ invFun := fun ⟨s, _⟩ ↦ mk <| PSet.mk (Shrink s) fun x ↦ ((equivShrink.{u, u + 1} s).symm x).1.out left_inv := Function.rightInverse_of_injective_of_leftInverse (by intros x y; simp) fun s ↦ Subtype.coe_injective <| toSet_equiv_aux s.2 right_inv s := Subtype.coe_injective <| toSet_equiv_aux s.2 /-- The **Burali-Forti paradox**: ordinals form a proper class. -/ theorem isOrdinal_notMem_univ : IsOrdinal ∉ Class.univ.{u} := by rintro ⟨x, hx, -⟩ suffices IsOrdinal x by apply Class.mem_irrefl x rwa [Class.coe_mem, hx] refine ⟨fun y hy z hz ↦ ?_, fun hyz hzw hwx ↦ ?_⟩ <;> rw [← Class.coe_apply, hx] at * exacts [hy.mem hz, hwx.mem_trans hyz hzw] @[deprecated (since := "2025-05-23")] alias isOrdinal_not_mem_univ := isOrdinal_notMem_univ end ZFSet
WellKnown.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Algebra.Rat import Mathlib.Data.Nat.Cast.Field import Mathlib.RingTheory.PowerSeries.Basic /-! # Definition of well-known power series In this file we define the following power series: * `PowerSeries.invUnitsSub`: given `u : Rˣ`, this is the series for `1 / (u - x)`. It is given by `∑ n, x ^ n /ₚ u ^ (n + 1)`. * `PowerSeries.invOneSubPow`: given a commutative ring `S` and a number `d : ℕ`, `PowerSeries.invOneSubPow S d` is the multiplicative inverse of `(1 - X) ^ d` in `S⟦X⟧ˣ`. When `d` is `0`, `PowerSeries.invOneSubPow S d` will just be `1`. When `d` is positive, `PowerSeries.invOneSubPow S d` will be `∑ n, Nat.choose (d - 1 + n) (d - 1)`. * `PowerSeries.sin`, `PowerSeries.cos`, `PowerSeries.exp` : power series for sin, cosine, and exponential functions. -/ namespace PowerSeries section Ring variable {R S : Type*} [Ring R] [Ring S] /-- The power series for `1 / (u - x)`. -/ def invUnitsSub (u : Rˣ) : PowerSeries R := mk fun n => 1 /ₚ u ^ (n + 1) @[simp] theorem coeff_invUnitsSub (u : Rˣ) (n : ℕ) : coeff R n (invUnitsSub u) = 1 /ₚ u ^ (n + 1) := coeff_mk _ _ @[simp] theorem constantCoeff_invUnitsSub (u : Rˣ) : constantCoeff R (invUnitsSub u) = 1 /ₚ u := by rw [← coeff_zero_eq_constantCoeff_apply, coeff_invUnitsSub, zero_add, pow_one] @[simp] theorem invUnitsSub_mul_X (u : Rˣ) : invUnitsSub u * X = invUnitsSub u * C R u - 1 := by ext (_ | n) · simp · simp [pow_succ'] @[simp] theorem invUnitsSub_mul_sub (u : Rˣ) : invUnitsSub u * (C R u - X) = 1 := by simp [mul_sub, sub_sub_cancel] theorem map_invUnitsSub (f : R →+* S) (u : Rˣ) : map f (invUnitsSub u) = invUnitsSub (Units.map (f : R →* S) u) := by ext simp only [← map_pow, coeff_map, coeff_invUnitsSub, one_divp] rfl end Ring section invOneSubPow variable (S : Type*) [CommRing S] (d : ℕ) /-- (1 + X + X^2 + ...) * (1 - X) = 1. Note that the power series `1 + X + X^2 + ...` is written as `mk 1` where `1` is the constant function so that `mk 1` is the power series with all coefficients equal to one. -/ theorem mk_one_mul_one_sub_eq_one : (mk 1 : S⟦X⟧) * (1 - X) = 1 := by rw [mul_comm, PowerSeries.ext_iff] intro n cases n with | zero => simp | succ n => simp [sub_mul] /-- Note that `mk 1` is the constant function `1` so the power series `1 + X + X^2 + ...`. This theorem states that for any `d : ℕ`, `(1 + X + X^2 + ... : S⟦X⟧) ^ (d + 1)` is equal to the power series `mk fun n => Nat.choose (d + n) d : S⟦X⟧`. -/ theorem mk_one_pow_eq_mk_choose_add : (mk 1 : S⟦X⟧) ^ (d + 1) = (mk fun n => Nat.choose (d + n) d : S⟦X⟧) := by induction d with | zero => ext; simp | succ d hd => ext n rw [pow_add, hd, pow_one, mul_comm, coeff_mul] simp_rw [coeff_mk, Pi.one_apply, one_mul] norm_cast rw [Finset.sum_antidiagonal_choose_add, add_right_comm] /-- Given a natural number `d : ℕ` and a commutative ring `S`, `PowerSeries.invOneSubPow S d` is the multiplicative inverse of `(1 - X) ^ d` in `S⟦X⟧ˣ`. When `d` is `0`, `PowerSeries.invOneSubPow S d` will just be `1`. When `d` is positive, `PowerSeries.invOneSubPow S d` will be the power series `mk fun n => Nat.choose (d - 1 + n) (d - 1)`. -/ noncomputable def invOneSubPow : ℕ → S⟦X⟧ˣ | 0 => 1 | d + 1 => { val := mk fun n => Nat.choose (d + n) d inv := (1 - X) ^ (d + 1) val_inv := by rw [← mk_one_pow_eq_mk_choose_add, ← mul_pow, mk_one_mul_one_sub_eq_one, one_pow] inv_val := by rw [← mk_one_pow_eq_mk_choose_add, ← mul_pow, mul_comm, mk_one_mul_one_sub_eq_one, one_pow] } theorem invOneSubPow_zero : invOneSubPow S 0 = 1 := by delta invOneSubPow simp only theorem invOneSubPow_val_eq_mk_sub_one_add_choose_of_pos (h : 0 < d) : (invOneSubPow S d).val = (mk fun n => Nat.choose (d - 1 + n) (d - 1) : S⟦X⟧) := by rw [← Nat.sub_one_add_one_eq_of_pos h, invOneSubPow, add_tsub_cancel_right] theorem invOneSubPow_val_succ_eq_mk_add_choose : (invOneSubPow S (d + 1)).val = (mk fun n => Nat.choose (d + n) d : S⟦X⟧) := rfl theorem invOneSubPow_val_one_eq_invUnitSub_one : (invOneSubPow S 1).val = invUnitsSub (1 : Sˣ) := by simp [invOneSubPow, invUnitsSub] /-- The theorem `PowerSeries.mk_one_mul_one_sub_eq_one` implies that `1 - X` is a unit in `S⟦X⟧` whose inverse is the power series `1 + X + X^2 + ...`. This theorem states that for any `d : ℕ`, `PowerSeries.invOneSubPow S d` is equal to `(1 - X)⁻¹ ^ d`. -/ theorem invOneSubPow_eq_inv_one_sub_pow : invOneSubPow S d = (Units.mkOfMulEqOne (1 - X) (mk 1 : S⟦X⟧) <| Eq.trans (mul_comm _ _) (mk_one_mul_one_sub_eq_one S))⁻¹ ^ d := by induction d with | zero => exact Eq.symm <| pow_zero _ | succ d _ => rw [inv_pow] exact (DivisionMonoid.inv_eq_of_mul _ (invOneSubPow S (d + 1)) <| by rw [← Units.val_eq_one, Units.val_mul, Units.val_pow_eq_pow_val] exact (invOneSubPow S (d + 1)).inv_val).symm theorem invOneSubPow_inv_eq_one_sub_pow : (invOneSubPow S d).inv = (1 - X : S⟦X⟧) ^ d := by induction d with | zero => exact Eq.symm <| pow_zero _ | succ d => rfl theorem invOneSubPow_inv_zero_eq_one : (invOneSubPow S 0).inv = 1 := by delta invOneSubPow simp only [Units.inv_eq_val_inv, inv_one, Units.val_one] theorem mk_add_choose_mul_one_sub_pow_eq_one : (mk fun n ↦ Nat.choose (d + n) d : S⟦X⟧) * ((1 - X) ^ (d + 1)) = 1 := (invOneSubPow S (d + 1)).val_inv theorem invOneSubPow_add (e : ℕ) : invOneSubPow S (d + e) = invOneSubPow S d * invOneSubPow S e := by simp_rw [invOneSubPow_eq_inv_one_sub_pow, pow_add] theorem one_sub_pow_mul_invOneSubPow_val_add_eq_invOneSubPow_val (e : ℕ) : (1 - X) ^ e * (invOneSubPow S (d + e)).val = (invOneSubPow S d).val := by simp [invOneSubPow_add, Units.val_mul, mul_comm, mul_assoc, ← invOneSubPow_inv_eq_one_sub_pow] theorem one_sub_pow_add_mul_invOneSubPow_val_eq_one_sub_pow (e : ℕ) : (1 - X) ^ (d + e) * (invOneSubPow S e).val = (1 - X) ^ d := by simp [pow_add, mul_assoc, ← invOneSubPow_inv_eq_one_sub_pow S e] end invOneSubPow section Field variable (A A' : Type*) [Ring A] [Ring A'] [Algebra ℚ A] [Algebra ℚ A'] open Nat /-- Power series for the exponential function at zero. -/ def exp : PowerSeries A := mk fun n => algebraMap ℚ A (1 / n !) /-- Power series for the sine function at zero. -/ def sin : PowerSeries A := mk fun n => if Even n then 0 else algebraMap ℚ A ((-1) ^ (n / 2) / n !) /-- Power series for the cosine function at zero. -/ def cos : PowerSeries A := mk fun n => if Even n then algebraMap ℚ A ((-1) ^ (n / 2) / n !) else 0 variable {A A'} (n : ℕ) @[simp] theorem coeff_exp : coeff A n (exp A) = algebraMap ℚ A (1 / n !) := coeff_mk _ _ @[simp] theorem constantCoeff_exp : constantCoeff A (exp A) = 1 := by rw [← coeff_zero_eq_constantCoeff_apply, coeff_exp] simp variable (f : A →+* A') @[simp] theorem map_exp : map (f : A →+* A') (exp A) = exp A' := by ext simp @[simp] theorem map_sin : map f (sin A) = sin A' := by ext simp [sin, apply_ite f] @[simp] theorem map_cos : map f (cos A) = cos A' := by ext simp [cos, apply_ite f] end Field open RingHom open Finset Nat variable {A : Type*} [CommRing A] /-- Shows that $e^{aX} * e^{bX} = e^{(a + b)X}$ -/ theorem exp_mul_exp_eq_exp_add [Algebra ℚ A] (a b : A) : rescale a (exp A) * rescale b (exp A) = rescale (a + b) (exp A) := by ext n simp only [coeff_mul, exp, rescale, coeff_mk, MonoidHom.coe_mk, OneHom.coe_mk, coe_mk, Nat.sum_antidiagonal_eq_sum_range_succ_mk, add_pow, sum_mul] apply sum_congr rfl rintro x hx suffices a ^ x * b ^ (n - x) * (algebraMap ℚ A (1 / ↑x.factorial) * algebraMap ℚ A (1 / ↑(n - x).factorial)) = a ^ x * b ^ (n - x) * (↑(n.choose x) * (algebraMap ℚ A) (1 / ↑n.factorial)) by convert this using 1 <;> ring congr 1 rw [← map_natCast (algebraMap ℚ A) (n.choose x), ← map_mul, ← map_mul] refine RingHom.congr_arg _ ?_ rw [mul_one_div (↑(n.choose x) : ℚ), one_div_mul_one_div] symm rw [div_eq_iff, div_mul_eq_mul_div, one_mul, choose_eq_factorial_div_factorial] · norm_cast rw [cast_div_charZero] apply factorial_mul_factorial_dvd_factorial (mem_range_succ_iff.1 hx) · apply mem_range_succ_iff.1 hx · rintro h apply factorial_ne_zero n rw [cast_eq_zero.1 h] /-- Shows that $e^{x} * e^{-x} = 1$ -/ theorem exp_mul_exp_neg_eq_one [Algebra ℚ A] : exp A * evalNegHom (exp A) = 1 := by convert exp_mul_exp_eq_exp_add (1 : A) (-1) <;> simp /-- Shows that $(e^{X})^k = e^{kX}$. -/ theorem exp_pow_eq_rescale_exp [Algebra ℚ A] (k : ℕ) : exp A ^ k = rescale (k : A) (exp A) := by induction' k with k h · simp only [rescale_zero, constantCoeff_exp, Function.comp_apply, map_one, cast_zero, pow_zero (exp A), coe_comp] · simpa only [succ_eq_add_one, cast_add, ← exp_mul_exp_eq_exp_add (k : A), ← h, cast_one, id_apply, rescale_one] using pow_succ (exp A) k /-- Shows that $\sum_{k = 0}^{n - 1} (e^{X})^k = \sum_{p = 0}^{\infty} \sum_{k = 0}^{n - 1} \frac{k^p}{p!}X^p$. -/ theorem exp_pow_sum [Algebra ℚ A] (n : ℕ) : ((Finset.range n).sum fun k => exp A ^ k) = PowerSeries.mk fun p => (Finset.range n).sum fun k => (k ^ p : A) * algebraMap ℚ A p.factorial⁻¹ := by simp only [exp_pow_eq_rescale_exp, rescale] ext simp only [one_div, coeff_mk, coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, coeff_exp, map_sum] end PowerSeries
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.
Prod.lean
/- Copyright (c) 2023 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Divisibility.Basic import Mathlib.Algebra.Group.Pi.Basic import Mathlib.Algebra.Group.Prod import Mathlib.Tactic.Common /-! # Lemmas about the divisibility relation in product (semi)groups -/ variable {ι G₁ G₂ : Type*} {G : ι → Type*} [Semigroup G₁] [Semigroup G₂] [∀ i, Semigroup (G i)] theorem prod_dvd_iff {x y : G₁ × G₂} : x ∣ y ↔ x.1 ∣ y.1 ∧ x.2 ∣ y.2 := by cases x; cases y simp only [dvd_def, Prod.exists, Prod.mk_mul_mk, Prod.mk.injEq, exists_and_left, exists_and_right] @[simp] theorem Prod.mk_dvd_mk {x₁ y₁ : G₁} {x₂ y₂ : G₂} : (x₁, x₂) ∣ (y₁, y₂) ↔ x₁ ∣ y₁ ∧ x₂ ∣ y₂ := prod_dvd_iff instance [DecompositionMonoid G₁] [DecompositionMonoid G₂] : DecompositionMonoid (G₁ × G₂) where primal a b c h := by simp_rw [prod_dvd_iff] at h ⊢ obtain ⟨a₁, a₁', h₁, h₁', eq₁⟩ := DecompositionMonoid.primal a.1 h.1 obtain ⟨a₂, a₂', h₂, h₂', eq₂⟩ := DecompositionMonoid.primal a.2 h.2 -- aesop works here exact ⟨(a₁, a₂), (a₁', a₂'), ⟨h₁, h₂⟩, ⟨h₁', h₂'⟩, Prod.ext eq₁ eq₂⟩ theorem pi_dvd_iff {x y : ∀ i, G i} : x ∣ y ↔ ∀ i, x i ∣ y i := by simp_rw [dvd_def, funext_iff, Classical.skolem]; rfl instance [∀ i, DecompositionMonoid (G i)] : DecompositionMonoid (∀ i, G i) where primal a b c h := by simp_rw [pi_dvd_iff] at h ⊢ choose a₁ a₂ h₁ h₂ eq using fun i ↦ DecompositionMonoid.primal _ (h i) exact ⟨a₁, a₂, h₁, h₂, funext eq⟩
QuotientRing.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.RingTheory.Int.Basic import Mathlib.RingTheory.ZMod /-! # `ZMod n` and quotient groups / rings This file relates `ZMod n` to the quotient ring `ℤ ⧸ Ideal.span {(n : ℤ)}`. ## Main definitions - `ZMod.quotient_span_nat_equiv_zmod` and `ZMod.quotientSpanEquivZMod `: `ZMod n` is the ring quotient of `ℤ` by `n ℤ : Ideal.span {n}` (where `n : ℕ` and `n : ℤ` respectively) ## Tags zmod, quotient ring, ideal quotient -/ open QuotientAddGroup Set ZMod variable (n : ℕ) {A R : Type*} [AddGroup A] [Ring R] namespace Int /-- `ℤ` modulo the ideal generated by `n : ℕ` is `ZMod n`. -/ def quotientSpanNatEquivZMod : ℤ ⧸ Ideal.span {(n : ℤ)} ≃+* ZMod n := (Ideal.quotEquivOfEq (ZMod.ker_intCastRingHom _)).symm.trans <| RingHom.quotientKerEquivOfRightInverse <| show Function.RightInverse ZMod.cast (Int.castRingHom (ZMod n)) from intCast_zmod_cast /-- `ℤ` modulo the ideal generated by `a : ℤ` is `ZMod a.natAbs`. -/ def quotientSpanEquivZMod (a : ℤ) : ℤ ⧸ Ideal.span ({a} : Set ℤ) ≃+* ZMod a.natAbs := (Ideal.quotEquivOfEq (span_natAbs a)).symm.trans (quotientSpanNatEquivZMod a.natAbs) @[simp] theorem quotientSpanNatEquivZMod_comp_Quotient_mk (n : ℕ) : (Int.quotientSpanNatEquivZMod n : _ →+* _).comp (Ideal.Quotient.mk (Ideal.span {(n : ℤ)})) = Int.castRingHom (ZMod n) := rfl @[simp] theorem quotientSpanNatEquivZMod_comp_castRingHom (n : ℕ) : ((Int.quotientSpanNatEquivZMod n).symm : _ →+* _).comp (Int.castRingHom (ZMod n)) = Ideal.Quotient.mk (Ideal.span {(n : ℤ)}) := by ext; simp @[simp] theorem quotientSpanEquivZMod_comp_Quotient_mk (n : ℤ) : (Int.quotientSpanEquivZMod n : _ →+* _).comp (Ideal.Quotient.mk (Ideal.span {(n : ℤ)})) = Int.castRingHom (ZMod n.natAbs) := rfl @[simp] theorem quotientSpanEquivZMod_comp_castRingHom (n : ℤ) : ((Int.quotientSpanEquivZMod n).symm : _ →+* _).comp (Int.castRingHom (ZMod n.natAbs)) = Ideal.Quotient.mk (Ideal.span {(n : ℤ)}) := by ext; simp end Int noncomputable section ChineseRemainder open Ideal open scoped Function in -- required for scoped `on` notation /-- The **Chinese remainder theorem**, elementary version for `ZMod`. See also `Mathlib/Data/ZMod/Basic.lean` for versions involving only two numbers. -/ def ZMod.prodEquivPi {ι : Type*} [Fintype ι] (a : ι → ℕ) (coprime : Pairwise (Nat.Coprime on a)) : ZMod (∏ i, a i) ≃+* Π i, ZMod (a i) := have : Pairwise fun i j => IsCoprime (span {(a i : ℤ)}) (span {(a j : ℤ)}) := fun _i _j h ↦ (isCoprime_span_singleton_iff _ _).mpr ((coprime h).cast (R := ℤ)) Int.quotientSpanNatEquivZMod _ |>.symm.trans <| quotEquivOfEq (iInf_span_singleton_natCast (R := ℤ) coprime) |>.symm.trans <| quotientInfRingEquivPiQuotient _ this |>.trans <| RingEquiv.piCongrRight fun i ↦ Int.quotientSpanNatEquivZMod (a i) end ChineseRemainder
Algebra.lean
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Nicolò Cavalleri -/ import Mathlib.Algebra.Algebra.Pi import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.Tactic.FieldSimp import Mathlib.Topology.Algebra.InfiniteSum.Basic import Mathlib.Topology.Algebra.Module.LinearMap import Mathlib.Topology.Algebra.Ring.Basic import Mathlib.Topology.UniformSpace.CompactConvergence /-! # Algebraic structures over continuous functions In this file we define instances of algebraic structures over the type `ContinuousMap α β` (denoted `C(α, β)`) of **bundled** continuous maps from `α` to `β`. For example, `C(α, β)` is a group when `β` is a group, a ring when `β` is a ring, etc. For each type of algebraic structure, we also define an appropriate subobject of `α → β` with carrier `{ f : α → β | Continuous f }`. For example, when `β` is a group, a subgroup `continuousSubgroup α β` of `α → β` is constructed with carrier `{ f : α → β | Continuous f }`. Note that, rather than using the derived algebraic structures on these subobjects (for example, when `β` is a group, the derived group structure on `continuousSubgroup α β`), one should use `C(α, β)` with the appropriate instance of the structure. -/ assert_not_exists StoneCech --attribute [elab_without_expected_type] Continuous.comp namespace ContinuousFunctions variable {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] variable {f g : { f : α → β | Continuous f }} instance : CoeFun { f : α → β | Continuous f } fun _ => α → β := ⟨Subtype.val⟩ end ContinuousFunctions namespace ContinuousMap variable {α : Type*} {β : Type*} {γ : Type*} variable [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] /-! ### `mul` and `add` -/ @[to_additive] instance instMul [Mul β] [ContinuousMul β] : Mul C(α, β) := ⟨fun f g => ⟨f * g, continuous_mul.comp (f.continuous.prodMk g.continuous :)⟩⟩ @[to_additive (attr := norm_cast, simp)] theorem coe_mul [Mul β] [ContinuousMul β] (f g : C(α, β)) : ⇑(f * g) = f * g := rfl @[to_additive (attr := simp)] theorem mul_apply [Mul β] [ContinuousMul β] (f g : C(α, β)) (x : α) : (f * g) x = f x * g x := rfl @[to_additive (attr := simp)] theorem mul_comp [Mul γ] [ContinuousMul γ] (f₁ f₂ : C(β, γ)) (g : C(α, β)) : (f₁ * f₂).comp g = f₁.comp g * f₂.comp g := rfl /-! ### `one` -/ @[to_additive] instance [One β] : One C(α, β) := ⟨const α 1⟩ @[to_additive (attr := norm_cast, simp)] theorem coe_one [One β] : ⇑(1 : C(α, β)) = 1 := rfl @[to_additive (attr := simp)] theorem one_apply [One β] (x : α) : (1 : C(α, β)) x = 1 := rfl @[to_additive (attr := simp)] theorem one_comp [One γ] (g : C(α, β)) : (1 : C(β, γ)).comp g = 1 := rfl @[to_additive (attr := simp)] theorem comp_one [One β] (g : C(β, γ)) : g.comp (1 : C(α, β)) = const α (g 1) := rfl @[to_additive (attr := simp)] theorem const_one [One β] : const α (1 : β) = 1 := rfl /-! ### `Nat.cast` -/ instance [NatCast β] : NatCast C(α, β) := ⟨fun n => ContinuousMap.const _ n⟩ @[simp, norm_cast] theorem coe_natCast [NatCast β] (n : ℕ) : ((n : C(α, β)) : α → β) = n := rfl @[simp] theorem natCast_apply [NatCast β] (n : ℕ) (x : α) : (n : C(α, β)) x = n := rfl /-! ### `Int.cast` -/ instance [IntCast β] : IntCast C(α, β) := ⟨fun n => ContinuousMap.const _ n⟩ @[simp, norm_cast] theorem coe_intCast [IntCast β] (n : ℤ) : ((n : C(α, β)) : α → β) = n := rfl @[simp] theorem intCast_apply [IntCast β] (n : ℤ) (x : α) : (n : C(α, β)) x = n := rfl /-! ### `nsmul` and `pow` -/ instance instNSMul [AddMonoid β] [ContinuousAdd β] : SMul ℕ C(α, β) := ⟨fun n f => ⟨n • ⇑f, f.continuous.nsmul n⟩⟩ @[to_additive existing] instance instPow [Monoid β] [ContinuousMul β] : Pow C(α, β) ℕ := ⟨fun f n => ⟨(⇑f) ^ n, f.continuous.pow n⟩⟩ @[to_additive (attr := norm_cast) (reorder := 7 8)] theorem coe_pow [Monoid β] [ContinuousMul β] (f : C(α, β)) (n : ℕ) : ⇑(f ^ n) = (⇑f) ^ n := rfl @[to_additive (attr := norm_cast)] theorem pow_apply [Monoid β] [ContinuousMul β] (f : C(α, β)) (n : ℕ) (x : α) : (f ^ n) x = f x ^ n := rfl -- don't make auto-generated `coe_nsmul` and `nsmul_apply` simp, as the linter complains they're -- redundant WRT `coe_smul` attribute [simp] coe_pow pow_apply @[to_additive] theorem pow_comp [Monoid γ] [ContinuousMul γ] (f : C(β, γ)) (n : ℕ) (g : C(α, β)) : (f ^ n).comp g = f.comp g ^ n := rfl -- don't make `nsmul_comp` simp as the linter complains it's redundant WRT `smul_comp` attribute [simp] pow_comp /-! ### `inv` and `neg` -/ @[to_additive] instance [Inv β] [ContinuousInv β] : Inv C(α, β) where inv f := ⟨f⁻¹, f.continuous.inv⟩ @[to_additive (attr := simp)] theorem coe_inv [Inv β] [ContinuousInv β] (f : C(α, β)) : ⇑f⁻¹ = (⇑f)⁻¹ := rfl @[to_additive (attr := simp)] theorem inv_apply [Inv β] [ContinuousInv β] (f : C(α, β)) (x : α) : f⁻¹ x = (f x)⁻¹ := rfl @[to_additive (attr := simp)] theorem inv_comp [Inv γ] [ContinuousInv γ] (f : C(β, γ)) (g : C(α, β)) : f⁻¹.comp g = (f.comp g)⁻¹ := rfl /-! ### `div` and `sub` -/ @[to_additive] instance [Div β] [ContinuousDiv β] : Div C(α, β) where div f g := ⟨f / g, f.continuous.div' g.continuous⟩ @[to_additive (attr := norm_cast, simp)] theorem coe_div [Div β] [ContinuousDiv β] (f g : C(α, β)) : ⇑(f / g) = f / g := rfl @[to_additive (attr := simp)] theorem div_apply [Div β] [ContinuousDiv β] (f g : C(α, β)) (x : α) : (f / g) x = f x / g x := rfl @[to_additive (attr := simp)] theorem div_comp [Div γ] [ContinuousDiv γ] (f g : C(β, γ)) (h : C(α, β)) : (f / g).comp h = f.comp h / g.comp h := rfl /-! ### `zpow` and `zsmul` -/ instance instZSMul [AddGroup β] [IsTopologicalAddGroup β] : SMul ℤ C(α, β) where smul z f := ⟨z • ⇑f, f.continuous.zsmul z⟩ @[to_additive existing] instance instZPow [Group β] [IsTopologicalGroup β] : Pow C(α, β) ℤ where pow f z := ⟨(⇑f) ^ z, f.continuous.zpow z⟩ @[to_additive (attr := norm_cast) (reorder := 7 8)] theorem coe_zpow [Group β] [IsTopologicalGroup β] (f : C(α, β)) (z : ℤ) : ⇑(f ^ z) = (⇑f) ^ z := rfl @[to_additive] theorem zpow_apply [Group β] [IsTopologicalGroup β] (f : C(α, β)) (z : ℤ) (x : α) : (f ^ z) x = f x ^ z := rfl -- don't make auto-generated `coe_zsmul` and `zsmul_apply` simp as the linter complains they're -- redundant WRT `coe_smul` attribute [simp] coe_zpow zpow_apply @[to_additive] theorem zpow_comp [Group γ] [IsTopologicalGroup γ] (f : C(β, γ)) (z : ℤ) (g : C(α, β)) : (f ^ z).comp g = f.comp g ^ z := rfl -- don't make `zsmul_comp` simp as the linter complains it's redundant WRT `smul_comp` attribute [simp] zpow_comp end ContinuousMap section GroupStructure /-! ### Group structure In this section we show that continuous functions valued in a topological group inherit the structure of a group. -/ section Subtype /-- The `Submonoid` of continuous maps `α → β`. -/ @[to_additive /-- The `AddSubmonoid` of continuous maps `α → β`. -/] def continuousSubmonoid (α : Type*) (β : Type*) [TopologicalSpace α] [TopologicalSpace β] [MulOneClass β] [ContinuousMul β] : Submonoid (α → β) where carrier := { f : α → β | Continuous f } one_mem' := @continuous_const _ _ _ _ 1 mul_mem' fc gc := fc.mul gc /-- The subgroup of continuous maps `α → β`. -/ @[to_additive /-- The `AddSubgroup` of continuous maps `α → β`. -/] def continuousSubgroup (α : Type*) (β : Type*) [TopologicalSpace α] [TopologicalSpace β] [Group β] [IsTopologicalGroup β] : Subgroup (α → β) := { continuousSubmonoid α β with inv_mem' := fun fc => Continuous.inv fc } end Subtype namespace ContinuousMap variable {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] @[to_additive] instance [Semigroup β] [ContinuousMul β] : Semigroup C(α, β) := coe_injective.semigroup _ coe_mul @[to_additive] instance [CommSemigroup β] [ContinuousMul β] : CommSemigroup C(α, β) := coe_injective.commSemigroup _ coe_mul @[to_additive] instance [MulOneClass β] [ContinuousMul β] : MulOneClass C(α, β) := coe_injective.mulOneClass _ coe_one coe_mul instance [MulZeroClass β] [ContinuousMul β] : MulZeroClass C(α, β) := coe_injective.mulZeroClass _ coe_zero coe_mul instance [SemigroupWithZero β] [ContinuousMul β] : SemigroupWithZero C(α, β) := coe_injective.semigroupWithZero _ coe_zero coe_mul @[to_additive] instance [Monoid β] [ContinuousMul β] : Monoid C(α, β) := coe_injective.monoid _ coe_one coe_mul coe_pow instance [MonoidWithZero β] [ContinuousMul β] : MonoidWithZero C(α, β) := coe_injective.monoidWithZero _ coe_zero coe_one coe_mul coe_pow @[to_additive] instance [CommMonoid β] [ContinuousMul β] : CommMonoid C(α, β) := coe_injective.commMonoid _ coe_one coe_mul coe_pow instance [CommMonoidWithZero β] [ContinuousMul β] : CommMonoidWithZero C(α, β) := coe_injective.commMonoidWithZero _ coe_zero coe_one coe_mul coe_pow @[to_additive] instance [LocallyCompactSpace α] [Mul β] [ContinuousMul β] : ContinuousMul C(α, β) := ⟨by refine continuous_of_continuous_uncurry _ ?_ have h1 : Continuous fun x : (C(α, β) × C(α, β)) × α => x.fst.fst x.snd := continuous_eval.comp (continuous_fst.prodMap continuous_id) have h2 : Continuous fun x : (C(α, β) × C(α, β)) × α => x.fst.snd x.snd := continuous_eval.comp (continuous_snd.prodMap continuous_id) exact h1.mul h2⟩ /-- Coercion to a function as a `MonoidHom`. Similar to `MonoidHom.coeFn`. -/ @[to_additive (attr := simps) /-- Coercion to a function as an `AddMonoidHom`. Similar to `AddMonoidHom.coeFn`. -/] def coeFnMonoidHom [Monoid β] [ContinuousMul β] : C(α, β) →* α → β where toFun f := f map_one' := coe_one map_mul' := coe_mul variable (α) in /-- Composition on the left by a (continuous) homomorphism of topological monoids, as a `MonoidHom`. Similar to `MonoidHom.compLeft`. -/ @[to_additive (attr := simps) /-- Composition on the left by a (continuous) homomorphism of topological `AddMonoid`s, as an `AddMonoidHom`. Similar to `AddMonoidHom.comp_left`. -/] protected def _root_.MonoidHom.compLeftContinuous {γ : Type*} [Monoid β] [ContinuousMul β] [TopologicalSpace γ] [Monoid γ] [ContinuousMul γ] (g : β →* γ) (hg : Continuous g) : C(α, β) →* C(α, γ) where toFun f := (⟨g, hg⟩ : C(β, γ)).comp f map_one' := ext fun _ => g.map_one map_mul' _ _ := ext fun _ => g.map_mul _ _ /-- Composition on the right as a `MonoidHom`. Similar to `MonoidHom.compHom'`. -/ @[to_additive (attr := simps) /-- Composition on the right as an `AddMonoidHom`. Similar to `AddMonoidHom.compHom'`. -/] def compMonoidHom' {γ : Type*} [TopologicalSpace γ] [MulOneClass γ] [ContinuousMul γ] (g : C(α, β)) : C(β, γ) →* C(α, γ) where toFun f := f.comp g map_one' := one_comp g map_mul' f₁ f₂ := mul_comp f₁ f₂ g @[to_additive (attr := simp)] theorem coe_prod [CommMonoid β] [ContinuousMul β] {ι : Type*} (s : Finset ι) (f : ι → C(α, β)) : ⇑(∏ i ∈ s, f i) = ∏ i ∈ s, (f i : α → β) := map_prod coeFnMonoidHom f s @[to_additive] theorem prod_apply [CommMonoid β] [ContinuousMul β] {ι : Type*} (s : Finset ι) (f : ι → C(α, β)) (a : α) : (∏ i ∈ s, f i) a = ∏ i ∈ s, f i a := by simp @[to_additive] instance [Group β] [IsTopologicalGroup β] : Group C(α, β) := coe_injective.group _ coe_one coe_mul coe_inv coe_div coe_pow coe_zpow @[to_additive] instance instCommGroupContinuousMap [CommGroup β] [IsTopologicalGroup β] : CommGroup C(α, β) := coe_injective.commGroup _ coe_one coe_mul coe_inv coe_div coe_pow coe_zpow @[to_additive] instance [CommGroup β] [IsTopologicalGroup β] : IsTopologicalGroup C(α, β) where continuous_mul := by letI : UniformSpace β := IsTopologicalGroup.toUniformSpace β have : IsUniformGroup β := isUniformGroup_of_commGroup rw [continuous_iff_continuousAt] rintro ⟨f, g⟩ rw [ContinuousAt, tendsto_iff_forall_isCompact_tendstoUniformlyOn, nhds_prod_eq] exact fun K hK => uniformContinuous_mul.comp_tendstoUniformlyOn ((tendsto_iff_forall_isCompact_tendstoUniformlyOn.mp Filter.tendsto_id K hK).prodMk (tendsto_iff_forall_isCompact_tendstoUniformlyOn.mp Filter.tendsto_id K hK)) continuous_inv := by letI : UniformSpace β := IsTopologicalGroup.toUniformSpace β have : IsUniformGroup β := isUniformGroup_of_commGroup rw [continuous_iff_continuousAt] intro f rw [ContinuousAt, tendsto_iff_forall_isCompact_tendstoUniformlyOn] exact fun K hK => uniformContinuous_inv.comp_tendstoUniformlyOn (tendsto_iff_forall_isCompact_tendstoUniformlyOn.mp Filter.tendsto_id K hK) /-- If an infinite product of functions in `C(α, β)` converges to `g` (for the compact-open topology), then the pointwise product converges to `g x` for all `x ∈ α`. -/ @[to_additive /-- If an infinite sum of functions in `C(α, β)` converges to `g` (for the compact-open topology), then the pointwise sum converges to `g x` for all `x ∈ α`. -/] theorem hasProd_apply {γ : Type*} [CommMonoid β] [ContinuousMul β] {f : γ → C(α, β)} {g : C(α, β)} (hf : HasProd f g) (x : α) : HasProd (fun i : γ => f i x) (g x) := by let ev : C(α, β) →* β := (Pi.evalMonoidHom _ x).comp coeFnMonoidHom exact hf.map ev (continuous_eval_const x) @[to_additive] theorem multipliable_apply [CommMonoid β] [ContinuousMul β] {γ : Type*} {f : γ → C(α, β)} (hf : Multipliable f) (x : α) : Multipliable fun i : γ => f i x := (hasProd_apply hf.hasProd x).multipliable @[to_additive] theorem tprod_apply [T2Space β] [CommMonoid β] [ContinuousMul β] {γ : Type*} {f : γ → C(α, β)} (hf : Multipliable f) (x : α) : ∏' i : γ, f i x = (∏' i : γ, f i) x := (hasProd_apply hf.hasProd x).tprod_eq end ContinuousMap end GroupStructure section RingStructure /-! ### Ring structure In this section we show that continuous functions valued in a topological semiring `R` inherit the structure of a ring. -/ section Subtype /-- The subsemiring of continuous maps `α → β`. -/ def continuousSubsemiring (α : Type*) (R : Type*) [TopologicalSpace α] [TopologicalSpace R] [NonAssocSemiring R] [IsTopologicalSemiring R] : Subsemiring (α → R) := { continuousAddSubmonoid α R, continuousSubmonoid α R with } /-- The subring of continuous maps `α → β`. -/ def continuousSubring (α : Type*) (R : Type*) [TopologicalSpace α] [TopologicalSpace R] [Ring R] [IsTopologicalRing R] : Subring (α → R) := { continuousAddSubgroup α R, continuousSubsemiring α R with } end Subtype namespace ContinuousMap instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [NonUnitalNonAssocSemiring β] [IsTopologicalSemiring β] : NonUnitalNonAssocSemiring C(α, β) := coe_injective.nonUnitalNonAssocSemiring _ coe_zero coe_add coe_mul coe_nsmul instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [NonUnitalSemiring β] [IsTopologicalSemiring β] : NonUnitalSemiring C(α, β) := coe_injective.nonUnitalSemiring _ coe_zero coe_add coe_mul coe_nsmul instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [AddMonoidWithOne β] [ContinuousAdd β] : AddMonoidWithOne C(α, β) := coe_injective.addMonoidWithOne _ coe_zero coe_one coe_add coe_nsmul coe_natCast instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [NonAssocSemiring β] [IsTopologicalSemiring β] : NonAssocSemiring C(α, β) := coe_injective.nonAssocSemiring _ coe_zero coe_one coe_add coe_mul coe_nsmul coe_natCast instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [Semiring β] [IsTopologicalSemiring β] : Semiring C(α, β) := coe_injective.semiring _ coe_zero coe_one coe_add coe_mul coe_nsmul coe_pow coe_natCast instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [NonUnitalNonAssocRing β] [IsTopologicalRing β] : NonUnitalNonAssocRing C(α, β) := coe_injective.nonUnitalNonAssocRing _ coe_zero coe_add coe_mul coe_neg coe_sub coe_nsmul coe_zsmul instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [NonUnitalRing β] [IsTopologicalRing β] : NonUnitalRing C(α, β) := coe_injective.nonUnitalRing _ coe_zero coe_add coe_mul coe_neg coe_sub coe_nsmul coe_zsmul instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [NonAssocRing β] [IsTopologicalRing β] : NonAssocRing C(α, β) := coe_injective.nonAssocRing _ coe_zero coe_one coe_add coe_mul coe_neg coe_sub coe_nsmul coe_zsmul coe_natCast coe_intCast instance instRing {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [Ring β] [IsTopologicalRing β] : Ring C(α, β) := coe_injective.ring _ coe_zero coe_one coe_add coe_mul coe_neg coe_sub coe_nsmul coe_zsmul coe_pow coe_natCast coe_intCast instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [NonUnitalCommSemiring β] [IsTopologicalSemiring β] : NonUnitalCommSemiring C(α, β) := coe_injective.nonUnitalCommSemiring _ coe_zero coe_add coe_mul coe_nsmul instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [CommSemiring β] [IsTopologicalSemiring β] : CommSemiring C(α, β) := coe_injective.commSemiring _ coe_zero coe_one coe_add coe_mul coe_nsmul coe_pow coe_natCast instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [NonUnitalCommRing β] [IsTopologicalRing β] : NonUnitalCommRing C(α, β) := coe_injective.nonUnitalCommRing _ coe_zero coe_add coe_mul coe_neg coe_sub coe_nsmul coe_zsmul instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [CommRing β] [IsTopologicalRing β] : CommRing C(α, β) := coe_injective.commRing _ coe_zero coe_one coe_add coe_mul coe_neg coe_sub coe_nsmul coe_zsmul coe_pow coe_natCast coe_intCast instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [LocallyCompactSpace α] [NonUnitalSemiring β] [IsTopologicalSemiring β] : IsTopologicalSemiring C(α, β) where instance {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [LocallyCompactSpace α] [NonUnitalRing β] [IsTopologicalRing β] : IsTopologicalRing C(α, β) where /-- Composition on the left by a (continuous) homomorphism of topological semirings, as a `RingHom`. Similar to `RingHom.compLeft`. -/ @[simps!] protected def _root_.RingHom.compLeftContinuous (α : Type*) {β : Type*} {γ : Type*} [TopologicalSpace α] [TopologicalSpace β] [Semiring β] [IsTopologicalSemiring β] [TopologicalSpace γ] [Semiring γ] [IsTopologicalSemiring γ] (g : β →+* γ) (hg : Continuous g) : C(α, β) →+* C(α, γ) := { g.toMonoidHom.compLeftContinuous α hg, g.toAddMonoidHom.compLeftContinuous α hg with } /-- Coercion to a function as a `RingHom`. -/ @[simps!] def coeFnRingHom {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [Semiring β] [IsTopologicalSemiring β] : C(α, β) →+* α → β := { (coeFnMonoidHom : C(α, β) →* _), (coeFnAddMonoidHom : C(α, β) →+ _) with } end ContinuousMap end RingStructure attribute [local ext] Subtype.eq section ModuleStructure /-! ### Module structure In this section we show that continuous functions valued in a topological module `M` over a topological semiring `R` inherit the structure of a module. -/ section Subtype variable (α : Type*) [TopologicalSpace α] variable (R : Type*) [Semiring R] variable (M : Type*) [TopologicalSpace M] [AddCommGroup M] variable [Module R M] [ContinuousConstSMul R M] [IsTopologicalAddGroup M] /-- The `R`-submodule of continuous maps `α → M`. -/ def continuousSubmodule : Submodule R (α → M) := { continuousAddSubgroup α M with carrier := { f : α → M | Continuous f } smul_mem' := fun c _ hf => hf.const_smul c } end Subtype namespace ContinuousMap variable {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] {R R₁ : Type*} {M : Type*} [TopologicalSpace M] {M₂ : Type*} [TopologicalSpace M₂] @[to_additive] instance instSMul [SMul R M] [ContinuousConstSMul R M] : SMul R C(α, M) := ⟨fun r f => ⟨r • ⇑f, f.continuous.const_smul r⟩⟩ @[to_additive] instance [SMul R M] [ContinuousConstSMul R M] : ContinuousConstSMul R C(α, M) where continuous_const_smul r := continuous_postcomp ⟨_, continuous_const_smul r⟩ @[to_additive] instance [TopologicalSpace R] [SMul R M] [ContinuousSMul R M] : ContinuousSMul R C(α, M) := ⟨(continuous_postcomp ⟨_, continuous_smul⟩).comp continuous_prodMk_const⟩ @[to_additive (attr := simp, norm_cast)] theorem coe_smul [SMul R M] [ContinuousConstSMul R M] (c : R) (f : C(α, M)) : ⇑(c • f) = c • ⇑f := rfl @[to_additive] theorem smul_apply [SMul R M] [ContinuousConstSMul R M] (c : R) (f : C(α, M)) (a : α) : (c • f) a = c • f a := rfl @[to_additive (attr := simp)] theorem smul_comp [SMul R M] [ContinuousConstSMul R M] (r : R) (f : C(β, M)) (g : C(α, β)) : (r • f).comp g = r • f.comp g := rfl @[to_additive] instance [SMul R M] [ContinuousConstSMul R M] [SMul R₁ M] [ContinuousConstSMul R₁ M] [SMulCommClass R R₁ M] : SMulCommClass R R₁ C(α, M) where smul_comm _ _ _ := ext fun _ => smul_comm _ _ _ instance [SMul R M] [ContinuousConstSMul R M] [SMul R₁ M] [ContinuousConstSMul R₁ M] [SMul R R₁] [IsScalarTower R R₁ M] : IsScalarTower R R₁ C(α, M) where smul_assoc _ _ _ := ext fun _ => smul_assoc _ _ _ instance [SMul R M] [SMul Rᵐᵒᵖ M] [ContinuousConstSMul R M] [IsCentralScalar R M] : IsCentralScalar R C(α, M) where op_smul_eq_smul _ _ := ext fun _ => op_smul_eq_smul _ _ instance [SMul R M] [ContinuousConstSMul R M] [Mul M] [ContinuousMul M] [IsScalarTower R M M] : IsScalarTower R C(α, M) C(α, M) where smul_assoc _ _ _ := ext fun _ => smul_mul_assoc .. instance [SMul R M] [ContinuousConstSMul R M] [Mul M] [ContinuousMul M] [SMulCommClass R M M] : SMulCommClass R C(α, M) C(α, M) where smul_comm _ _ _ := ext fun _ => (mul_smul_comm ..).symm instance [SMul R M] [ContinuousConstSMul R M] [Mul M] [ContinuousMul M] [SMulCommClass M R M] : SMulCommClass C(α, M) R C(α, M) where smul_comm _ _ _ := ext fun _ => smul_comm (_ : M) .. instance [Monoid R] [MulAction R M] [ContinuousConstSMul R M] : MulAction R C(α, M) := Function.Injective.mulAction _ coe_injective coe_smul instance [Monoid R] [AddMonoid M] [DistribMulAction R M] [ContinuousAdd M] [ContinuousConstSMul R M] : DistribMulAction R C(α, M) := Function.Injective.distribMulAction coeFnAddMonoidHom coe_injective coe_smul variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] variable [ContinuousAdd M] [Module R M] [ContinuousConstSMul R M] variable [ContinuousAdd M₂] [Module R M₂] [ContinuousConstSMul R M₂] instance module : Module R C(α, M) := Function.Injective.module R coeFnAddMonoidHom coe_injective coe_smul variable (R) /-- Composition on the left by a continuous linear map, as a `ContinuousLinearMap`. Similar to `LinearMap.compLeft`. -/ @[simps] protected def _root_.ContinuousLinearMap.compLeftContinuous (α : Type*) [TopologicalSpace α] (g : M →L[R] M₂) : C(α, M) →L[R] C(α, M₂) where __ := g.toLinearMap.toAddMonoidHom.compLeftContinuous α g.continuous map_smul' := fun c _ => ext fun _ => g.map_smul' c _ cont := ContinuousMap.continuous_postcomp _ /-- The constant map `x ↦ y ↦ x` as a `ContinuousLinearMap`. -/ @[simps!] def _root_.ContinuousLinearMap.const (α : Type*) [TopologicalSpace α] : M →L[R] C(α, M) where toFun m := .const α m map_add' _ _ := rfl map_smul' _ _ := rfl cont := ContinuousMap.continuous_const' /-- Coercion to a function as a `LinearMap`. -/ @[simps] def coeFnLinearMap : C(α, M) →ₗ[R] α → M := { (coeFnAddMonoidHom : C(α, M) →+ _) with map_smul' := coe_smul } /-- Evaluation at a point, as a continuous linear map. -/ @[simps apply] def evalCLM (x : α) : C(α, M) →L[R] M where toFun f := f x map_add' _ _ := add_apply _ _ x map_smul' _ _ := smul_apply _ _ x end ContinuousMap end ModuleStructure section AlgebraStructure /-! ### Algebra structure In this section we show that continuous functions valued in a topological algebra `A` over a ring `R` inherit the structure of an algebra. Note that the hypothesis that `A` is a topological algebra is obtained by requiring that `A` be both a `ContinuousSMul` and a `IsTopologicalSemiring`. -/ section Subtype variable {α : Type*} [TopologicalSpace α] {R : Type*} [CommSemiring R] {A : Type*} [TopologicalSpace A] [Semiring A] [Algebra R A] [IsTopologicalSemiring A] /-- The `R`-subalgebra of continuous maps `α → A`. -/ def continuousSubalgebra : Subalgebra R (α → A) := { continuousSubsemiring α A with carrier := { f : α → A | Continuous f } algebraMap_mem' := fun r => (continuous_const : Continuous fun _ : α => algebraMap R A r) } end Subtype section ContinuousMap variable {α : Type*} [TopologicalSpace α] {R : Type*} [CommSemiring R] {A : Type*} [TopologicalSpace A] [Semiring A] [Algebra R A] [IsTopologicalSemiring A] {A₂ : Type*} [TopologicalSpace A₂] [Semiring A₂] [Algebra R A₂] [IsTopologicalSemiring A₂] /-- Continuous constant functions as a `RingHom`. -/ def ContinuousMap.C : R →+* C(α, A) where toFun := fun c : R => ⟨fun _ : α => (algebraMap R A) c, continuous_const⟩ map_one' := by ext _; exact (algebraMap R A).map_one map_mul' c₁ c₂ := by ext _; exact (algebraMap R A).map_mul _ _ map_zero' := by ext _; exact (algebraMap R A).map_zero map_add' c₁ c₂ := by ext _; exact (algebraMap R A).map_add _ _ @[simp] theorem ContinuousMap.C_apply (r : R) (a : α) : ContinuousMap.C r a = algebraMap R A r := rfl instance ContinuousMap.algebra : Algebra R C(α, A) where algebraMap := ContinuousMap.C commutes' c f := by ext x; exact Algebra.commutes' _ _ smul_def' c f := by ext x; exact Algebra.smul_def' _ _ variable (R) /-- Composition on the left by a (continuous) homomorphism of topological `R`-algebras, as an `AlgHom`. Similar to `AlgHom.compLeft`. -/ @[simps!] protected def AlgHom.compLeftContinuous {α : Type*} [TopologicalSpace α] (g : A →ₐ[R] A₂) (hg : Continuous g) : C(α, A) →ₐ[R] C(α, A₂) := { g.toRingHom.compLeftContinuous α hg with commutes' := fun _ => ContinuousMap.ext fun _ => g.commutes' _ } variable (A) /-- Precomposition of functions into a topological semiring by a continuous map is an algebra homomorphism. -/ @[simps] def ContinuousMap.compRightAlgHom {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] (f : C(α, β)) : C(β, A) →ₐ[R] C(α, A) where toFun g := g.comp f map_zero' := ext fun _ ↦ rfl map_add' _ _ := ext fun _ ↦ rfl map_one' := ext fun _ ↦ rfl map_mul' _ _ := ext fun _ ↦ rfl commutes' _ := ext fun _ ↦ rfl theorem ContinuousMap.compRightAlgHom_continuous {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] (f : C(α, β)) : Continuous (compRightAlgHom R A f) := continuous_precomp f variable {A} /-- Coercion to a function as an `AlgHom`. -/ @[simps!] def ContinuousMap.coeFnAlgHom : C(α, A) →ₐ[R] α → A := { (ContinuousMap.coeFnRingHom : C(α, A) →+* _) with commutes' := fun _ => rfl } variable {R} /-- A version of `Set.SeparatesPoints` for subalgebras of the continuous functions, used for stating the Stone-Weierstrass theorem. -/ abbrev Subalgebra.SeparatesPoints (s : Subalgebra R C(α, A)) : Prop := Set.SeparatesPoints ((fun f : C(α, A) => (f : α → A)) '' (s : Set C(α, A))) theorem Subalgebra.separatesPoints_monotone : Monotone fun s : Subalgebra R C(α, A) => s.SeparatesPoints := fun s s' r h x y n => by obtain ⟨f, m, w⟩ := h n rcases m with ⟨f, ⟨m, rfl⟩⟩ exact ⟨_, ⟨f, ⟨r m, rfl⟩⟩, w⟩ @[simp] theorem algebraMap_apply (k : R) (a : α) : algebraMap R C(α, A) k a = k • (1 : A) := by rw [Algebra.algebraMap_eq_smul_one] rfl variable {𝕜 : Type*} [TopologicalSpace 𝕜] variable (s : Set C(α, 𝕜)) (f : s) (x : α) /-- A set of continuous maps "separates points strongly" if for each pair of distinct points there is a function with specified values on them. We give a slightly unusual formulation, where the specified values are given by some function `v`, and we ask `f x = v x ∧ f y = v y`. This avoids needing a hypothesis `x ≠ y`. In fact, this definition would work perfectly well for a set of non-continuous functions, but as the only current use case is in the Stone-Weierstrass theorem, writing it this way avoids having to deal with casts inside the set. (This may need to change if we do Stone-Weierstrass on non-compact spaces, where the functions would be continuous functions vanishing at infinity.) -/ def Set.SeparatesPointsStrongly (s : Set C(α, 𝕜)) : Prop := ∀ (v : α → 𝕜) (x y : α), ∃ f ∈ s, (f x : 𝕜) = v x ∧ f y = v y variable [Field 𝕜] [IsTopologicalRing 𝕜] /-- Working in continuous functions into a topological field, a subalgebra of functions that separates points also separates points strongly. By the hypothesis, we can find a function `f` so `f x ≠ f y`. By an affine transformation in the field we can arrange so that `f x = a` and `f x = b`. -/ theorem Subalgebra.SeparatesPoints.strongly {s : Subalgebra 𝕜 C(α, 𝕜)} (h : s.SeparatesPoints) : (s : Set C(α, 𝕜)).SeparatesPointsStrongly := fun v x y => by by_cases n : x = y · subst n exact ⟨_, (v x • (1 : s) : s).prop, mul_one _, mul_one _⟩ obtain ⟨_, ⟨f, hf, rfl⟩, hxy⟩ := h n replace hxy : f x - f y ≠ 0 := sub_ne_zero_of_ne hxy let a := v x let b := v y let f' : s := ((b - a) * (f x - f y)⁻¹) • (algebraMap _ s (f x) - (⟨f, hf⟩ : s)) + algebraMap _ s a refine ⟨f', f'.prop, ?_, ?_⟩ · simp [a, b, f'] · simp [a, b, f', inv_mul_cancel_right₀ hxy] end ContinuousMap instance ContinuousMap.subsingleton_subalgebra (α : Type*) [TopologicalSpace α] (R : Type*) [CommSemiring R] [TopologicalSpace R] [IsTopologicalSemiring R] [Subsingleton α] : Subsingleton (Subalgebra R C(α, R)) := ⟨fun s₁ s₂ => by cases isEmpty_or_nonempty α · have : Subsingleton C(α, R) := DFunLike.coe_injective.subsingleton subsingleton · inhabit α ext f have h : f = algebraMap R C(α, R) (f default) := by ext x' simp only [mul_one, Algebra.id.smul_eq_mul, algebraMap_apply] congr simp [eq_iff_true_of_subsingleton] rw [h] simp only [Subalgebra.algebraMap_mem]⟩ end AlgebraStructure section ModuleOverContinuousFunctions /-! ### Structure as module over scalar functions If `M` is a module over `R`, then we show that the space of continuous functions from `α` to `M` is naturally a module over the ring of continuous functions from `α` to `R`. -/ namespace ContinuousMap variable {α : Type*} [TopologicalSpace α] {R : Type*} [Semiring R] [TopologicalSpace R] {M : Type*} [TopologicalSpace M] [AddCommMonoid M] [Module R M] [ContinuousSMul R M] instance instSMul' : SMul C(α, R) C(α, M) := ⟨fun f g => ⟨fun x => f x • g x, Continuous.smul f.2 g.2⟩⟩ /-- Coercion to a function for a scalar-valued continuous map multiplying a vector-valued one (as opposed to `ContinuousMap.coe_smul` which is multiplication by a constant scalar). -/ @[simp] lemma coe_smul' (f : C(α, R)) (g : C(α, M)) : ⇑(f • g) = ⇑f • ⇑g := rfl /-- Evaluation of a scalar-valued continuous map multiplying a vector-valued one (as opposed to `ContinuousMap.smul_apply` which is multiplication by a constant scalar). -/ -- (this doesn't need to be @[simp] since it can be derived from `coe_smul'` and `Pi.smul_apply'`) lemma smul_apply' (f : C(α, R)) (g : C(α, M)) (x : α) : (f • g) x = f x • g x := rfl instance module' [IsTopologicalSemiring R] [ContinuousAdd M] : Module C(α, R) C(α, M) where smul := (· • ·) smul_add c f g := by ext x; exact smul_add (c x) (f x) (g x) add_smul c₁ c₂ f := by ext x; exact add_smul (c₁ x) (c₂ x) (f x) mul_smul c₁ c₂ f := by ext x; exact mul_smul (c₁ x) (c₂ x) (f x) one_smul f := by ext x; exact one_smul R (f x) zero_smul f := by ext x; exact zero_smul _ _ smul_zero r := by ext x; exact smul_zero _ end ContinuousMap end ModuleOverContinuousFunctions /-! ### Evaluation as a bundled map -/ variable {X : Type*} (S R : Type*) [TopologicalSpace X] [CommSemiring S] [CommSemiring R] variable [Algebra S R] [TopologicalSpace R] [IsTopologicalSemiring R] /-- Evaluation of continuous maps at a point, bundled as an algebra homomorphism. -/ @[simps] def ContinuousMap.evalAlgHom (x : X) : C(X, R) →ₐ[S] R where toFun f := f x map_zero' := rfl map_one' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl commutes' _ := rfl
Basic.lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Data.Int.Init import Mathlib.Data.Nat.Basic import Mathlib.Logic.Nontrivial.Defs import Mathlib.Tactic.Convert import Mathlib.Tactic.Lift import Mathlib.Tactic.OfNat /-! # Basic operations on the integers This file builds on `Data.Int.Init` by adding basic lemmas on integers. depending on Mathlib definitions. -/ open Nat namespace Int variable {a b c d m n : ℤ} -- TODO: Tag in Lean attribute [simp] natAbs_pos instance instNontrivial : Nontrivial ℤ := ⟨⟨0, 1, Int.zero_ne_one⟩⟩ @[simp] lemma ofNat_injective : Function.Injective ofNat := @Int.ofNat.inj section inductionOn' variable {C : ℤ → Sort*} (z b : ℤ) (H0 : C b) (Hs : ∀ k, b ≤ k → C k → C (k + 1)) (Hp : ∀ k ≤ b, C k → C (k - 1)) variable {z b H0 Hs Hp} lemma inductionOn'_add_one (hz : b ≤ z) : (z + 1).inductionOn' b H0 Hs Hp = Hs z hz (z.inductionOn' b H0 Hs Hp) := by apply cast_eq_iff_heq.mpr lift z - b to ℕ using Int.sub_nonneg.mpr hz with zb hzb rw [show z + 1 - b = zb + 1 by omega] have : b + zb = z := by omega subst this convert cast_heq _ _ rw [Int.inductionOn', cast_eq_iff_heq, ← hzb] end inductionOn' section strongRec variable {P : ℤ → Sort*} {lt : ∀ n < m, P n} {ge : ∀ n ≥ m, (∀ k < n, P k) → P n} lemma strongRec_of_ge : ∀ hn : m ≤ n, m.strongRec lt ge n = ge n hn fun k _ ↦ m.strongRec lt ge k := by refine m.strongRec (fun n hnm hmn ↦ (Int.not_lt.mpr hmn hnm).elim) (fun n _ ih hn ↦ ?_) n rw [Int.strongRec, dif_neg (Int.not_lt.mpr hn)] congr; revert ih refine n.inductionOn' m (fun _ ↦ ?_) (fun k hmk ih' ih ↦ ?_) (fun k hkm ih' _ ↦ ?_) <;> ext l hl · rw [inductionOn'_self, strongRec_of_lt hl] · rw [inductionOn'_add_one hmk]; split_ifs with hlm · rw [strongRec_of_lt hlm] · rw [ih' fun l hl ↦ ih l (Int.lt_trans hl k.lt_succ), ih _ hl] · rw [inductionOn'_sub_one hkm, ih'] exact fun l hlk hml ↦ (Int.not_lt.mpr hkm <| Int.lt_of_le_of_lt hml hlk).elim end strongRec /-! ### nat abs -/ lemma natAbs_surjective : natAbs.Surjective := fun n => ⟨n, natAbs_natCast n⟩ lemma pow_right_injective (h : 1 < a.natAbs) : ((a ^ ·) : ℕ → ℤ).Injective := by refine (?_ : (natAbs ∘ (a ^ · : ℕ → ℤ)).Injective).of_comp convert Nat.pow_right_injective h using 2 rw [Function.comp_apply, natAbs_pow] /-! ### dvd -/ @[norm_cast] theorem ofNat_dvd_natCast {x y : ℕ} : (ofNat(x) : ℤ) ∣ (y : ℤ) ↔ OfNat.ofNat x ∣ y := natCast_dvd_natCast @[norm_cast] theorem natCast_dvd_ofNat {x y : ℕ} : (x : ℤ) ∣ (ofNat(y) : ℤ) ↔ x ∣ OfNat.ofNat y := natCast_dvd_natCast lemma natCast_dvd {m : ℕ} : (m : ℤ) ∣ n ↔ m ∣ n.natAbs := by obtain hn | hn := natAbs_eq n <;> rw [hn] <;> simp [← natCast_dvd_natCast, Int.dvd_neg] lemma dvd_natCast {n : ℕ} : m ∣ (n : ℤ) ↔ m.natAbs ∣ n := by obtain hn | hn := natAbs_eq m <;> rw [hn] <;> simp [← natCast_dvd_natCast, Int.neg_dvd] lemma eq_zero_of_dvd_of_nonneg_of_lt (hm : 0 ≤ m) (hmn : m < n) (hnm : n ∣ m) : m = 0 := eq_zero_of_dvd_of_natAbs_lt_natAbs hnm (natAbs_lt_natAbs_of_nonneg_of_lt hm hmn) /-- If two integers are congruent to a sufficiently large modulus, they are equal. -/ lemma eq_of_mod_eq_of_natAbs_sub_lt_natAbs {a b c : ℤ} (h1 : a % b = c) (h2 : natAbs (a - c) < natAbs b) : a = c := Int.eq_of_sub_eq_zero (eq_zero_of_dvd_of_natAbs_lt_natAbs (dvd_self_sub_of_emod_eq h1) h2) lemma natAbs_le_of_dvd_ne_zero (hmn : m ∣ n) (hn : n ≠ 0) : natAbs m ≤ natAbs n := not_lt.mp (mt (eq_zero_of_dvd_of_natAbs_lt_natAbs hmn) hn) theorem gcd_emod (m n : ℤ) : (m % n).gcd n = m.gcd n := by conv_rhs => rw [← m.emod_add_ediv n, gcd_add_mul_left_left] end Int
Destutter.lean
/- Copyright (c) 2022 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez, Eric Wieser -/ import Mathlib.Data.List.Chain /-! # Destuttering of Lists This file proves theorems about `List.destutter` (in `Data.List.Defs`), which greedily removes all non-related items that are adjacent in a list, e.g. `[2, 2, 3, 3, 2].destutter (≠) = [2, 3, 2]`. Note that we make no guarantees of being the longest sublist with this property; e.g., `[123, 1, 2, 5, 543, 1000].destutter (<) = [123, 543, 1000]`, but a longer ascending chain could be `[1, 2, 5, 543, 1000]`. ## Main statements * `List.destutter_sublist`: `l.destutter` is a sublist of `l`. * `List.destutter_is_chain'`: `l.destutter` satisfies `Chain' R`. * Analogies of these theorems for `List.destutter'`, which is the `destutter` equivalent of `Chain`. ## Tags adjacent, chain, duplicates, remove, list, stutter, destutter -/ open Function variable {α β : Type*} (l l₁ l₂ : List α) (R : α → α → Prop) [DecidableRel R] {a b : α} variable {R₂ : β → β → Prop} [DecidableRel R₂] namespace List @[simp] theorem destutter'_nil : destutter' R a [] = [a] := rfl theorem destutter'_cons : (b :: l).destutter' R a = if R a b then a :: destutter' R b l else destutter' R a l := rfl variable {R} @[simp] theorem destutter'_cons_pos (h : R b a) : (a :: l).destutter' R b = b :: l.destutter' R a := by rw [destutter', if_pos h] @[simp] theorem destutter'_cons_neg (h : ¬R b a) : (a :: l).destutter' R b = l.destutter' R b := by rw [destutter', if_neg h] variable (R) @[simp] theorem destutter'_singleton : [b].destutter' R a = if R a b then [a, b] else [a] := by split_ifs with h <;> simp! [h] theorem destutter'_sublist (a) : l.destutter' R a <+ a :: l := by induction' l with b l hl generalizing a · simp rw [destutter'] split_ifs · exact Sublist.cons₂ a (hl b) · exact (hl a).trans ((l.sublist_cons_self b).cons_cons a) theorem mem_destutter' (a) : a ∈ l.destutter' R a := by induction' l with b l hl · simp rw [destutter'] split_ifs · simp · assumption theorem destutter'_is_chain : ∀ l : List α, ∀ {a b}, R a b → (l.destutter' R b).Chain R a | [], _, _, h => chain_singleton.mpr h | c :: l, a, b, h => by rw [destutter'] split_ifs with hbc · rw [chain_cons] exact ⟨h, destutter'_is_chain l hbc⟩ · exact destutter'_is_chain l h theorem destutter'_is_chain' (a) : (l.destutter' R a).Chain' R := by induction' l with b l hl generalizing a · simp rw [destutter'] split_ifs with h · exact destutter'_is_chain R l h · exact hl a theorem destutter'_of_chain (h : l.Chain R a) : l.destutter' R a = a :: l := by induction' l with b l hb generalizing a · simp obtain ⟨h, hc⟩ := chain_cons.mp h rw [l.destutter'_cons_pos h, hb hc] @[simp] theorem destutter'_eq_self_iff (a) : l.destutter' R a = a :: l ↔ l.Chain R a := ⟨fun h => by suffices Chain' R (a::l) by assumption rw [← h] exact l.destutter'_is_chain' R a, destutter'_of_chain _ _⟩ theorem destutter'_ne_nil : l.destutter' R a ≠ [] := ne_nil_of_mem <| l.mem_destutter' R a @[simp] theorem destutter_nil : ([] : List α).destutter R = [] := rfl theorem destutter_cons' : (a :: l).destutter R = destutter' R a l := rfl theorem destutter_cons_cons : (a :: b :: l).destutter R = if R a b then a :: destutter' R b l else destutter' R a l := rfl @[simp] theorem destutter_singleton : destutter R [a] = [a] := rfl @[simp] theorem destutter_pair : destutter R [a, b] = if R a b then [a, b] else [a] := destutter_cons_cons _ R theorem destutter_sublist : ∀ l : List α, l.destutter R <+ l | [] => Sublist.slnil | h :: l => l.destutter'_sublist R h theorem destutter_is_chain' : ∀ l : List α, (l.destutter R).Chain' R | [] => List.chain'_nil | h :: l => l.destutter'_is_chain' R h theorem destutter_of_chain' : ∀ l : List α, l.Chain' R → l.destutter R = l | [], _ => rfl | _ :: l, h => l.destutter'_of_chain _ h @[simp] theorem destutter_eq_self_iff : ∀ l : List α, l.destutter R = l ↔ l.Chain' R | [] => by simp | a :: l => l.destutter'_eq_self_iff R a theorem destutter_idem : (l.destutter R).destutter R = l.destutter R := destutter_of_chain' R _ <| l.destutter_is_chain' R @[simp] theorem destutter_eq_nil : ∀ {l : List α}, destutter R l = [] ↔ l = [] | [] => Iff.rfl | _ :: l => ⟨fun h => absurd h <| l.destutter'_ne_nil R, fun h => nomatch h⟩ variable {R} /-- For a relation-preserving map, `destutter` commutes with `map`. -/ theorem map_destutter {f : α → β} : ∀ {l : List α}, (∀ a ∈ l, ∀ b ∈ l, R a b ↔ R₂ (f a) (f b)) → (l.destutter R).map f = (l.map f).destutter R₂ | [], hl => by simp | [a], hl => by simp | a :: b :: l, hl => by have := hl a (by simp) b (by simp) simp_rw [map_cons, destutter_cons_cons, ← this] by_cases hr : R a b <;> simp [hr, ← destutter_cons', map_destutter fun c hc d hd ↦ hl _ (cons_subset_cons _ (subset_cons_self _ _) hc) _ (cons_subset_cons _ (subset_cons_self _ _) hd), map_destutter fun c hc d hd ↦ hl _ (subset_cons_self _ _ hc) _ (subset_cons_self _ _ hd)] /-- For a injective function `f`, `destutter' (·≠·)` commutes with `map f`. -/ theorem map_destutter_ne {f : α → β} (h : Injective f) [DecidableEq α] [DecidableEq β] : (l.destutter (·≠·)).map f = (l.map f).destutter (·≠·) := map_destutter fun _ _ _ _ ↦ h.ne_iff.symm /-- `destutter'` on a relation like ≠ or <, whose negation is transitive, has length monotone under a `¬R` changing of the first element. -/ theorem length_destutter'_cotrans_ge [i : IsTrans α Rᶜ] : ∀ {a} {l : List α}, ¬R b a → (l.destutter' R b).length ≤ (l.destutter' R a).length | a, [], hba => by simp | a, c :: l, hba => by by_cases hbc : R b c case pos => have hac : ¬Rᶜ a c := (mt (_root_.trans hba)) (not_not.2 hbc) simp_rw [destutter', if_pos (not_not.1 hac), if_pos hbc, length_cons, le_refl] case neg => simp only [destutter', if_neg hbc] by_cases hac : R a c case pos => simp only [if_pos hac, length_cons] exact Nat.le_succ_of_le (length_destutter'_cotrans_ge hbc) case neg => simp only [if_neg hac] exact length_destutter'_cotrans_ge hba /-- `List.destutter'` on a relation like `≠`, whose negation is an equivalence, gives the same length if the first elements are not related. -/ theorem length_destutter'_congr [IsEquiv α Rᶜ] (hab : ¬R a b) : (l.destutter' R a).length = (l.destutter' R b).length := (length_destutter'_cotrans_ge hab).antisymm <| length_destutter'_cotrans_ge (symm hab : Rᶜ b a) /-- `List.destutter'` on a relation like ≠, whose negation is an equivalence, has length monotonic under List.cons -/ /- TODO: Replace this lemma by the more general version: theorem Sublist.length_destutter'_mono [IsEquiv α Rᶜ] (h : a :: l₁ <+ b :: l₂) : (List.destutter' R a l₁).length ≤ (List.destutter' R b l₂).length -/ theorem le_length_destutter'_cons [IsEquiv α Rᶜ] : ∀ {l : List α}, (l.destutter' R b).length ≤ ((b :: l).destutter' R a).length | [] => by by_cases hab : (R a b) <;> simp_all [Nat.le_succ] | c :: cs => by by_cases hab : R a b case pos => simp [destutter', if_pos hab, Nat.le_succ] obtain hac | hac : R a c ∨ Rᶜ a c := em _ · have hbc : ¬Rᶜ b c := mt (_root_.trans hab) (not_not.2 hac) simp [destutter', if_pos hac, if_pos (not_not.1 hbc), if_neg hab] · have hbc : ¬R b c := trans (symm hab) hac simp only [destutter', if_neg hbc, if_neg hac, if_neg hab] exact (length_destutter'_congr cs hab).ge /-- `List.destutter` on a relation like ≠, whose negation is an equivalence, has length monotone under List.cons -/ theorem length_destutter_le_length_destutter_cons [IsEquiv α Rᶜ] : ∀ {l : List α}, (l.destutter R).length ≤ ((a :: l).destutter R).length | [] => by simp [destutter] | b :: l => le_length_destutter'_cons variable {l l₁ l₂} /-- `destutter ≠` has length monotone under `List.cons`. -/ theorem length_destutter_ne_le_length_destutter_cons [DecidableEq α] : (l.destutter (· ≠ ·)).length ≤ ((a :: l).destutter (· ≠ ·)).length := length_destutter_le_length_destutter_cons /-- `destutter` of relations like `≠`, whose negation is an equivalence relation, gives a list of maximal length over any chain. In other words, `l.destutter R` is an `R`-chain sublist of `l`, and is at least as long as any other `R`-chain sublist. -/ lemma Chain'.length_le_length_destutter [IsEquiv α Rᶜ] : ∀ {l₁ l₂ : List α}, l₁ <+ l₂ → l₁.Chain' R → l₁.length ≤ (l₂.destutter R).length -- `l₁ := []`, `l₂ := []` | [], [], _, _ => by simp -- `l₁ := l₁`, `l₂ := a :: l₂` | l₁, _, .cons (l₂ := l₂) a hl, hl₁ => (hl₁.length_le_length_destutter hl).trans length_destutter_le_length_destutter_cons -- `l₁ := [a]`, `l₂ := a :: l₂` | _, _, .cons₂ (l₁ := []) (l₂ := l₁) a hl, hl₁ => by simp [Nat.one_le_iff_ne_zero] -- `l₁ := a :: l₁`, `l₂ := a :: b :: l₂` | _, _, .cons₂ a <| .cons (l₁ := l₁) (l₂ := l₂) b hl, hl₁ => by by_cases hab : R a b · simpa [destutter_cons_cons, hab] using hl₁.tail.length_le_length_destutter (hl.cons _) · simpa [destutter_cons_cons, hab] using hl₁.length_le_length_destutter (hl.cons₂ _) -- `l₁ := a :: b :: l₁`, `l₂ := a :: b :: l₂` | _, _, .cons₂ a <| .cons₂ (l₁ := l₁) (l₂ := l₂) b hl, hl₁ => by simpa [destutter_cons_cons, rel_of_chain_cons hl₁] using hl₁.tail.length_le_length_destutter (hl.cons₂ _) /-- `destutter` of `≠` gives a list of maximal length over any chain. In other words, `l.destutter (· ≠ ·)` is a `≠`-chain sublist of `l`, and is at least as long as any other `≠`-chain sublist. -/ lemma Chain'.length_le_length_destutter_ne [DecidableEq α] (hl : l₁ <+ l₂) (hl₁ : l₁.Chain' (· ≠ ·)) : l₁.length ≤ (l₂.destutter (· ≠ ·)).length := hl₁.length_le_length_destutter hl end List
VonNeumann.lean
/- Copyright (c) 2024 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.ZFC.Class import Mathlib.SetTheory.ZFC.Ordinal import Mathlib.SetTheory.ZFC.Rank /-! # Von Neumann hierarchy This file defines the von Neumann hierarchy of sets `V_ o` for ordinal `o`, which is recursively defined so that `V_ a = ⋃ b < a, powerset (V_ b)`. This stratifies the universal class, in the sense that `⋃ o, V_ o = univ`. ## Notation - `V_ o` is notation for `vonNeumann o`. It is scoped in the `ZFSet` namespace. -/ universe u open Order namespace ZFSet /-- The von Neumann hierarchy is defined so that `V_ o` is the union of the powersets of all `V_ a` for `a < o`. It satisfies the following properties: - `vonNeumann_zero`: `V_ 0 = ∅` - `vonNeumann_succ`: `V_ (succ a) = powerset (V_ a)` - `vonNeumann_of_isSuccPrelimit`: `IsSuccPrelimit a → V_ a = ⋃ b < a, V_ b` -/ noncomputable def vonNeumann (o : Ordinal.{u}) : ZFSet.{u} := ⋃₀ range fun a : Set.Iio o ↦ powerset (vonNeumann a) termination_by o decreasing_by exact a.2 @[inherit_doc] scoped notation "V_ " => vonNeumann variable {a b o : Ordinal.{u}} {x : ZFSet.{u}} lemma mem_vonNeumann' : x ∈ V_ o ↔ ∃ a < o, x ⊆ V_ a := by rw [vonNeumann]; simp theorem isTransitive_vonNeumann (o : Ordinal) : IsTransitive (V_ o) := by rw [vonNeumann] refine IsTransitive.sUnion' fun x hx ↦ ?_ obtain ⟨⟨a, _⟩, rfl⟩ := mem_range.1 hx exact (isTransitive_vonNeumann a).powerset termination_by o @[gcongr] theorem vonNeumann_mem_of_lt (h : a < b) : V_ a ∈ V_ b := by rw [vonNeumann]; aesop @[gcongr] theorem vonNeumann_subset_of_le (h : a ≤ b) : V_ a ⊆ V_ b := h.eq_or_lt.rec (by simp_all) fun h ↦ isTransitive_vonNeumann _ _ <| vonNeumann_mem_of_lt h theorem subset_vonNeumann {o : Ordinal} {x : ZFSet} : x ⊆ V_ o ↔ rank x ≤ o := by rw [rank_le_iff] constructor <;> intro hx y hy · apply (rank_lt_of_mem (hx hy)).trans_le simp_rw [rank_le_iff, mem_vonNeumann'] rintro z ⟨a, ha, hz⟩ exact (subset_vonNeumann.1 hz).trans_lt ha · rw [mem_vonNeumann'] have := hx hy exact ⟨_, this, subset_vonNeumann.2 le_rfl⟩ termination_by o theorem subset_vonNeumann_self (x : ZFSet) : x ⊆ V_ (rank x) := by simp [subset_vonNeumann] theorem mem_vonNeumann : x ∈ V_ o ↔ rank x < o := by simp_rw [mem_vonNeumann', subset_vonNeumann] exact ⟨fun ⟨a, h₁, h₂⟩ ↦ h₂.trans_lt h₁, by aesop⟩ theorem mem_vonNeumann_succ (x : ZFSet) : x ∈ V_ (succ (rank x)) := by simp [mem_vonNeumann] /-- Every set is in some element of the von Neumann hierarchy. -/ theorem exists_mem_vonNeumann (x : ZFSet) : ∃ o, x ∈ V_ o := ⟨_, mem_vonNeumann_succ x⟩ @[simp] theorem rank_vonNeumann (o : Ordinal) : rank (V_ o) = o := le_antisymm (by rw [← subset_vonNeumann]) <| le_of_forall_lt fun a ha ↦ rank_vonNeumann a ▸ rank_lt_of_mem (vonNeumann_mem_of_lt ha) termination_by o @[simp] theorem vonNeumann_mem_vonNeumann_iff : V_ a ∈ V_ b ↔ a < b := by simp [mem_vonNeumann] @[simp] theorem vonNeumann_subset_vonNeumann_iff : V_ a ⊆ V_ b ↔ a ≤ b := by simp [subset_vonNeumann] theorem mem_vonNeumann_of_subset {y : ZFSet} (h : x ⊆ y) (hy : y ∈ V_ o) : x ∈ V_ o := by rw [mem_vonNeumann] at * exact (rank_mono h).trans_lt hy theorem vonNeumann_strictMono : StrictMono vonNeumann := strictMono_of_le_iff_le (by simp) theorem vonNeumann_injective : Function.Injective vonNeumann := vonNeumann_strictMono.injective @[simp] theorem vonNeumann_inj : V_ a = V_ b ↔ a = b := vonNeumann_injective.eq_iff @[gcongr] alias ⟨_, _root_.GCongr.ZFSet.vonNeumann_inj⟩ := vonNeumann_inj @[simp] theorem vonNeumann_zero : V_ 0 = ∅ := (eq_empty _).2 (by simp [mem_vonNeumann]) @[simp] theorem vonNeumann_succ (o : Ordinal) : V_ (succ o) = powerset (V_ o) := ext fun z ↦ by rw [mem_vonNeumann, mem_powerset, subset_vonNeumann, lt_succ_iff] theorem vonNeumann_of_isSuccPrelimit (h : IsSuccPrelimit o) : V_ o = (⋃₀ range fun a : Set.Iio o ↦ vonNeumann a : ZFSet) := ext fun z ↦ by simpa [mem_vonNeumann] using h.lt_iff_exists_lt theorem iUnion_vonNeumann : ⋃ o, (V_ o : Class) = Class.univ := Class.eq_univ_of_forall fun x ↦ Set.mem_iUnion.2 <| exists_mem_vonNeumann x end ZFSet
Variable.lean
/- Copyright (c) 2023 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Init import Lean.Meta.Tactic.TryThis /-! # The `variable?` command This defines a command like `variable` that automatically adds all missing typeclass arguments. For example, `variable? [Module R M]` is the same as `variable [Semiring R] [AddCommMonoid M] [Module R M]`, though if any of these three instance arguments can be inferred from previous variables then they will be omitted. An inherent limitation with this command is that variables are recorded in the scope as *syntax*. This means that `variable?` needs to pretty print the expressions we get from typeclass synthesis errors, and these might fail to round trip. -/ namespace Mathlib.Command.Variable open Lean Elab Command Parser.Term Meta initialize registerTraceClass `variable? register_option variable?.maxSteps : Nat := { defValue := 15 group := "variable?" descr := "The maximum number of instance arguments `variable?` will try to insert before giving up" } register_option variable?.checkRedundant : Bool := { defValue := true group := "variable?" descr := "Warn if instance arguments can be inferred from preceding ones" } /-- Get the type out of a bracketed binder. -/ def bracketedBinderType : Syntax → Option Term | `(bracketedBinderF|($_* $[: $ty?]? $(_annot?)?)) => ty? | `(bracketedBinderF|{$_* $[: $ty?]?}) => ty? | `(bracketedBinderF|⦃$_* $[: $ty?]?⦄) => ty? | `(bracketedBinderF|[$[$_ :]? $ty]) => some ty | _ => none /-- The `variable?` command has the same syntax as `variable`, but it will auto-insert missing instance arguments wherever they are needed. It does not add variables that can already be deduced from others in the current context. By default the command checks that variables aren't implied by earlier ones, but it does *not* check that earlier variables aren't implied by later ones. Unlike `variable`, the `variable?` command does not support changing variable binder types. The `variable?` command will give a suggestion to replace itself with a command of the form `variable? ...binders... => ...binders...`. The binders after the `=>` are the completed list of binders. When this `=>` clause is present, the command verifies that the expanded binders match the post-`=>` binders. The purpose of this is to help keep code that uses `variable?` resilient against changes to the typeclass hierarchy, at least in the sense that this additional information can be used to debug issues that might arise. One can also replace `variable? ...binders... =>` with `variable`. The core algorithm is to try elaborating binders one at a time, and whenever there is a typeclass instance inference failure, it synthesizes binder syntax for it and adds it to the list of binders and tries again, recursively. There are no guarantees that this process gives the "correct" list of binders. Structures tagged with the `variable_alias` attribute can serve as aliases for a collection of typeclasses. For example, given ```lean @[variable_alias] structure VectorSpace (k V : Type*) [Field k] [AddCommGroup V] [Module k V] ``` then `variable? [VectorSpace k V]` is equivalent to `variable {k V : Type*} [Field k] [AddCommGroup V] [Module k V]`, assuming that there are no pre-existing instances on `k` and `V`. Note that this is not a simple replacement: it only adds instances not inferable from others in the current scope. A word of warning: the core algorithm depends on pretty printing, so if terms that appear in binders do not round trip, this algorithm can fail. That said, it has some support for quantified binders such as `[∀ i, F i]`. -/ syntax (name := «variable?») "variable?" (ppSpace bracketedBinder)* (" =>" (ppSpace bracketedBinder)*)? : command /-- Attribute to record aliases for the `variable?` command. Aliases are structures that have no fields, and additional typeclasses are recorded as *arguments* to the structure. Example: ``` @[variable_alias] structure VectorSpace (k V : Type*) [Field k] [AddCommGroup V] [Module k V] ``` Then `variable? [VectorSpace k V]` ensures that these three typeclasses are present in the current scope. Notice that it's looking at the arguments to the `VectorSpace` type constructor. You should not have any fields in `variable_alias` structures. Notice that `VectorSpace` is not a class; the `variable?` command allows non-classes with the `variable_alias` attribute to use instance binders. -/ initialize variableAliasAttr : TagAttribute ← registerTagAttribute `variable_alias "Attribute to record aliases for the `variable?` command." /-- Find a synthetic typeclass metavariable with no expr metavariables in its type. -/ def pendingActionableSynthMVar (binder : TSyntax ``bracketedBinder) : TermElabM (Option MVarId) := do let pendingMVars := (← get).pendingMVars if pendingMVars.isEmpty then return none for mvarId in pendingMVars.reverse do let some decl ← Term.getSyntheticMVarDecl? mvarId | continue match decl.kind with | .typeClass _ => let ty ← instantiateMVars (← mvarId.getType) if !ty.hasExprMVar then return mvarId | _ => pure () throwErrorAt binder "Can not satisfy requirements for {binder} due to metavariables." /-- Try elaborating `ty`. Returns `none` if it doesn't need any additional typeclasses, or it returns a new binder that needs to come first. Does not add info unless it throws an exception. -/ partial def getSubproblem (binder : TSyntax ``bracketedBinder) (ty : Term) : TermElabM (Option (MessageData × TSyntax ``bracketedBinder)) := do let res : Term.TermElabResult (Option (MessageData × TSyntax ``bracketedBinder)) ← Term.observing do withTheReader Term.Context (fun ctx => {ctx with ignoreTCFailures := true}) do Term.withAutoBoundImplicit do _ ← Term.elabType ty Term.synthesizeSyntheticMVars (postpone := .yes) (ignoreStuckTC := true) let fvarIds := (← getLCtx).getFVarIds if let some mvarId ← pendingActionableSynthMVar binder then trace[«variable?»] "Actionable mvar:{mvarId}" -- TODO alter goal based on configuration, for example Semiring -> CommRing. -- 1. Find the new fvars that this instance problem depends on: let fvarIds' := (← mvarId.getDecl).lctx.getFVarIds.filter (fun fvar => !(fvarIds.contains fvar)) -- 2. Abstract the instance problem with respect to these fvars let goal ← mvarId.withContext do instantiateMVars <| (← mkForallFVars (usedOnly := true) (fvarIds'.map .fvar) (← mvarId.getType)) -- Note: pretty printing is not guaranteed to round-trip, but it's what we can do. let ty' ← PrettyPrinter.delab goal let binder' ← withRef binder `(bracketedBinderF| [$ty']) return some (← addMessageContext m!"{mvarId}", binder') else return none match res with | .ok v _ => return v | .error .. => Term.applyResult res /-- Tries elaborating binders, inserting new binders whenever typeclass inference fails. `i` is the index of the next binder that needs to be checked. The `toOmit` array keeps track of which binders should be removed at the end, in particular the `variable_alias` binders and any redundant binders. -/ partial def completeBinders' (maxSteps : Nat) (gas : Nat) (checkRedundant : Bool) (binders : TSyntaxArray ``bracketedBinder) (toOmit : Array Bool) (i : Nat) : TermElabM (TSyntaxArray ``bracketedBinder × Array Bool) := do if h : 0 < gas ∧ i < binders.size then let binder := binders[i] trace[«variable?»] "\ Have {(← getLCtx).getFVarIds.size} fvars and {(← getLocalInstances).size} local instances. \ Looking at{indentD binder}" let sub? ← getSubproblem binder (bracketedBinderType binder).get! if let some (goalMsg, binder') := sub? then trace[«variable?»] m!"new subproblem:{indentD binder'}" if binders.any (stop := i) (· == binder') then let binders' := binders.extract 0 i throwErrorAt binder "\ Binder{indentD binder}\nwas not able to satisfy one of its dependencies using \ the pre-existing binder{indentD binder'}\n\n\ This might be due to differences in implicit arguments, which are not represented \ in binders since they are generated by pretty printing unsatisfied dependencies.\n\n\ Current variable command:{indentD (← `(command| variable $binders'*))}\n\n\ Local context for the unsatisfied dependency:{goalMsg}" let binders := binders.insertIdx i binder' completeBinders' maxSteps (gas - 1) checkRedundant binders toOmit i else let lctx ← getLCtx let linst ← getLocalInstances withOptions (fun opts => Term.checkBinderAnnotations.set opts false) <| -- for variable_alias Term.withAutoBoundImplicit <| Term.elabBinders #[binder] fun bindersElab => do let types : Array Expr ← bindersElab.mapM (inferType ·) trace[«variable?»] m!"elaborated binder types array = {types}" Term.synthesizeSyntheticMVarsNoPostponing -- checkpoint for withAutoBoundImplicit Term.withoutAutoBoundImplicit do let (binders, toOmit) := ← do match binder with | `(bracketedBinderF|[$[$ident? :]? $ty]) => -- Check if it's an alias let type ← instantiateMVars (← inferType bindersElab.back!) if ← isVariableAlias type then if ident?.isSome then throwErrorAt binder "`variable_alias` binders can't have an explicit name" -- Switch to implicit so that `elabBinders` succeeds. -- We keep it around so that it gets infotrees let binder' ← withRef binder `(bracketedBinderF|{_ : $ty}) return (binders.set! i binder', toOmit.push true) -- Check that this wasn't already an instance let res ← try withLCtx lctx linst <| trySynthInstance type catch _ => pure .none if let .some _ := res then if checkRedundant then let mvar ← mkFreshExprMVarAt lctx linst type logWarningAt binder m!"Instance argument can be inferred from earlier arguments.\n{mvar.mvarId!}" return (binders, toOmit.push true) else return (binders, toOmit.push false) | _ => return (binders, toOmit.push false) completeBinders' maxSteps gas checkRedundant binders toOmit (i + 1) else if h : gas = 0 ∧ i < binders.size then let binders' := binders.extract 0 i logErrorAt binders[i] m!"Maximum recursion depth for variables! reached. This might be a \ bug, or you can try adjusting `set_option variable?.maxSteps {maxSteps}`\n\n\ Current variable command:{indentD (← `(command| variable $binders'*))}" return (binders, toOmit) where isVariableAlias (type : Expr) : MetaM Bool := do forallTelescope type fun _ type => do if let .const name _ := type.getAppFn then if variableAliasAttr.hasTag (← getEnv) name then return true return false def completeBinders (maxSteps : Nat) (checkRedundant : Bool) (binders : TSyntaxArray ``bracketedBinder) : TermElabM (TSyntaxArray ``bracketedBinder × Array Bool) := completeBinders' maxSteps maxSteps checkRedundant binders #[] 0 /-- Strip off whitespace and comments. -/ def cleanBinders (binders : TSyntaxArray ``bracketedBinder) : TSyntaxArray ``bracketedBinder := Id.run do let mut binders' := #[] for binder in binders do binders' := binders'.push <| ⟨binder.raw.unsetTrailing⟩ return binders' @[command_elab «variable?», inherit_doc «variable?»] def elabVariables : CommandElab := fun stx => match stx with | `(variable? $binders* $[=> $expectedBinders?*]?) => do let checkRedundant := variable?.checkRedundant.get (← getOptions) process stx checkRedundant binders expectedBinders? | _ => throwUnsupportedSyntax where extendScope (binders : TSyntaxArray ``bracketedBinder) : CommandElabM Unit := do for binder in binders do let varUIds ← (← getBracketedBinderIds binder) |>.mapM (withFreshMacroScope ∘ MonadQuotation.addMacroScope) modifyScope fun scope => { scope with varDecls := scope.varDecls.push binder, varUIds := scope.varUIds ++ varUIds } process (stx : Syntax) (checkRedundant : Bool) (binders : TSyntaxArray ``bracketedBinder) (expectedBinders? : Option <| TSyntaxArray ``bracketedBinder) : CommandElabM Unit := do let binders := cleanBinders binders let maxSteps := variable?.maxSteps.get (← getOptions) trace[«variable?»] "variable?.maxSteps = {maxSteps}" for binder in binders do if (bracketedBinderType binder).isNone then throwErrorAt binder "variable? cannot update pre-existing variables" let (binders', suggest) ← runTermElabM fun _ => do let (binders, toOmit) ← completeBinders maxSteps checkRedundant binders /- Elaborate the binders again, which also adds the infotrees. This also makes sure the list works with auto-bound implicits at the front. -/ Term.withAutoBoundImplicit <| Term.elabBinders binders fun _ => pure () -- Filter out omitted binders let binders' : TSyntaxArray ``bracketedBinder := (binders.zip toOmit).filterMap fun (b, toOmit) => if toOmit then none else some b if let some expectedBinders := expectedBinders? then trace[«variable?»] "checking expected binders" /- We re-elaborate the binders to create an expression that represents the entire resulting local context (auto-bound implicits mean we can't just the `binders` array). -/ let elabAndPackageBinders (binders : TSyntaxArray ``bracketedBinder) : TermElabM AbstractMVarsResult := withoutModifyingStateWithInfoAndMessages <| Term.withAutoBoundImplicit <| Term.elabBinders binders fun _ => do let e ← mkForallFVars (← getLCtx).getFVars (.sort .zero) let res ← abstractMVars e -- Throw in the level names from the current state since `Type*` produces new -- level names. return {res with paramNames := (← get).levelNames.toArray ++ res.paramNames} let ctx1 ← elabAndPackageBinders binders' let ctx2 ← elabAndPackageBinders expectedBinders trace[«variable?»] "new context: paramNames = {ctx1.paramNames}, { ""}numMVars = {ctx1.numMVars}\n{indentD ctx1.expr}" trace[«variable?»] "expected context: paramNames = {ctx2.paramNames}, { ""}numMVars = {ctx2.numMVars}\n{indentD ctx2.expr}" if ctx1.paramNames == ctx2.paramNames && ctx1.numMVars == ctx2.numMVars then if ← isDefEq ctx1.expr ctx2.expr then return (binders', false) logWarning "Calculated binders do not match the expected binders given after `=>`." return (binders', true) else return (binders', true) extendScope binders' let varComm ← `(command| variable? $binders* => $binders'*) trace[«variable?»] "derived{indentD varComm}" if suggest then liftTermElabM <| Lean.Meta.Tactic.TryThis.addSuggestion stx (origSpan? := stx) varComm /-- Hint for the unused variables linter. Copies the one for `variable`. -/ @[unused_variables_ignore_fn] def ignorevariable? : Lean.Linter.IgnoreFunction := fun _ stack _ => stack.matches [`null, none, `null, ``Mathlib.Command.Variable.variable?] || stack.matches [`null, none, `null, `null, ``Mathlib.Command.Variable.variable?] end Variable end Command end Mathlib
algnum.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 ssrbool ssrfun eqtype ssrnat seq path. From mathcomp Require Import div choice fintype tuple finfun bigop prime. From mathcomp Require Import ssralg poly polydiv ssrnum ssrint archimedean rat. From mathcomp Require Import finalg zmodp matrix mxalgebra mxpoly vector intdiv. From mathcomp Require Import falgebra fieldext separable galois algC cyclotomic. (******************************************************************************) (* This file provides a few basic results and constructions in algebraic *) (* number theory, that are used in the character theory library. Most of *) (* these could be generalized to a more abstract setting. Note that the type *) (* of abstract number fields is simply extFieldType rat. We define here: *) (* x \in Crat_span X <=> x is a Q-linear combination of elements of *) (* X : seq algC. *) (* x \in Cint_span X <=> x is a Z-linear combination of elements of *) (* X : seq algC. *) (* x \in Aint <=> x : algC is an algebraic integer, i.e., the (monic) *) (* polynomial of x over Q has integer coefficients. *) (* (e %| a)%A <=> e divides a with respect to algebraic integers, *) (* (e %| a)%Ax i.e., a is in the algebraic integer ideal generated *) (* by e. This is is notation for a \in dvdA e, where *) (* dvdv is the (collective) predicate for the Aint *) (* ideal generated by e. As in the (e %| a)%C notation *) (* e and a can be coerced to algC from nat or int. *) (* The (e %| a)%Ax display form is a workaround for *) (* design limitations of the Coq Notation facilities. *) (* (a == b %[mod e])%A, (a != b %[mod e])%A <=> *) (* a is equal (resp. not equal) to b mod e, i.e., a and *) (* b belong to the same e * Aint class. We do not *) (* force a, b and e to be algebraic integers. *) (* #[x]%C == the multiplicative order of x, i.e., the n such that *) (* x is an nth primitive root of unity, or 0 if x is not *) (* a root of unity. *) (* In addition several lemmas prove the (constructive) existence of number *) (* fields and of automorphisms of algC. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope algC_scope. Declare Scope algC_expanded_scope. Import GRing.Theory Num.Theory. Local Open Scope ring_scope. Local Notation ZtoQ := (intr : int -> rat). Local Notation ZtoC := (intr : int -> algC). Local Notation QtoC := (ratr : rat -> algC). Local Notation intrp := (map_poly intr). Local Notation pZtoQ := (map_poly ZtoQ). Local Notation pZtoC := (map_poly ZtoC). Local Notation pQtoC := (map_poly ratr). Local Definition intr_inj_ZtoC := (intr_inj : injective ZtoC). #[local] Hint Resolve intr_inj_ZtoC : core. Section MoreAlgCaut. Implicit Type rR : unitRingType. Lemma alg_num_field (Qz : fieldExtType rat) a : a%:A = ratr a :> Qz. Proof. by rewrite -in_algE fmorph_eq_rat. Qed. Lemma rmorphZ_num (Qz : fieldExtType rat) rR (f : {rmorphism Qz -> rR}) a x : f (a *: x) = ratr a * f x. Proof. by rewrite -mulr_algl rmorphM alg_num_field fmorph_rat. Qed. Lemma fmorph_numZ (Qz1 Qz2 : fieldExtType rat) (f : {rmorphism Qz1 -> Qz2}) : scalable f. Proof. by move=> a x; rewrite rmorphZ_num -alg_num_field mulr_algl. Qed. End MoreAlgCaut. (* Number fields and rational spans. *) Lemma algC_PET (s : seq algC) : {z | exists a : nat ^ size s, z = \sum_(i < size s) s`_i *+ a i & exists ps, s = [seq (pQtoC p).[z] | p <- ps]}. Proof. elim: s => [|x s [z /sig_eqW[a Dz] /sig_eqW[ps Ds]]]. by exists 0; [exists [ffun _ => 2%N]; rewrite big_ord0 | exists nil]. have r_exists (y : algC): {r | r != 0 & root (pQtoC r) y}. have [r [_ mon_r] dv_r] := minCpolyP y. by exists r; rewrite ?monic_neq0 ?dv_r. suffices /sig_eqW[[n [|px [|pz []]]]// [Dpx Dpz]]: exists np, let zn := x *+ np.1 + z in [:: x; z] = [seq (pQtoC p).[zn] | p <- np.2]. - exists (x *+ n + z). exists [ffun i => oapp a n (unlift ord0 i)]. rewrite /= big_ord_recl ffunE unlift_none Dz; congr (_ + _). by apply: eq_bigr => i _; rewrite ffunE liftK. exists (px :: [seq p \Po pz | p <- ps]); rewrite /= -Dpx; congr (_ :: _). rewrite -map_comp Ds; apply: eq_map => p /=. by rewrite map_comp_poly horner_comp -Dpz. have [rx nz_rx rx0] := r_exists x. have [rz nz_rz rz0] := r_exists (- z). have pchar0_Q: [pchar rat] =i pred0 by apply: pchar_num. have [n [[pz Dpz] [px Dpx]]] := pchar0_PET nz_rz rz0 nz_rx rx0 pchar0_Q. by exists (n, [:: px; - pz]); rewrite /= !raddfN hornerN -[z]opprK Dpz Dpx. Qed. Lemma num_field_exists (s : seq algC) : {Qs : fieldExtType rat & {QsC : {rmorphism Qs -> algC} & {s1 : seq Qs | map QsC s1 = s & <<1 & s1>>%VS = fullv}}}. Proof. have [z /sig_eqW[a Dz] /sig_eqW[ps Ds]] := algC_PET s. suffices [Qs [QsC [z1 z1C z1gen]]]: {Qs : fieldExtType rat & {QsC : {rmorphism Qs -> algC} & {z1 : Qs | QsC z1 = z & forall xx, exists p, fieldExt_horner z1 p = xx}}}. - set inQs := fieldExt_horner z1 in z1gen *; pose s1 := map inQs ps. have inQsK p: QsC (inQs p) = (pQtoC p).[z]. rewrite /= -horner_map z1C -map_poly_comp; congr _.[z]. by apply: eq_map_poly => b /=; rewrite alg_num_field fmorph_rat. exists Qs, QsC, s1; first by rewrite -map_comp Ds (eq_map inQsK). have sz_ps: size ps = size s by rewrite Ds size_map. apply/vspaceP=> x; rewrite memvf; have [p {x}<-] := z1gen x. elim/poly_ind: p => [|p b ApQs]; first by rewrite /inQs rmorph0 mem0v. rewrite /inQs rmorphD rmorphM /= fieldExt_hornerX fieldExt_hornerC -/inQs /=. suffices ->: z1 = \sum_(i < size s) s1`_i *+ a i. rewrite memvD ?memvZ ?mem1v ?memvM ?memv_suml // => i _. by rewrite rpredMn ?seqv_sub_adjoin ?mem_nth // size_map sz_ps. apply: (fmorph_inj QsC); rewrite z1C Dz rmorph_sum; apply: eq_bigr => i _. by rewrite rmorphMn {1}Ds !(nth_map 0) ?sz_ps //= inQsK. have [r [Dr /monic_neq0 nz_r] dv_r] := minCpolyP z. have rz0: root (pQtoC r) z by rewrite dv_r. have irr_r: irreducible_poly r. by apply/(subfx_irreducibleP rz0 nz_r)=> q qz0 nzq; rewrite dvdp_leq // -dv_r. exists (SubFieldExtType rz0 irr_r), (@subfx_inj _ _ QtoC z r). exists (subfx_root _ z r) => [|x]; first exact: subfx_inj_root. by have{x} [p ->] := subfxEroot rz0 nz_r x; exists p. Qed. Definition in_Crat_span s x := exists a : rat ^ size s, x = \sum_i QtoC (a i) * s`_i. Fact Crat_span_subproof s x : decidable (in_Crat_span s x). Proof. have [Qxs [QxsC [[|x1 s1] // [<- <-] {x s} _]]] := num_field_exists (x :: s). apply: decP (x1 \in <<in_tuple s1>>%VS) _; rewrite /in_Crat_span size_map. apply: (iffP idP) => [/coord_span-> | [a Dx]]. move: (coord _) => a; exists [ffun i => a i x1]; rewrite rmorph_sum /=. by apply: eq_bigr => i _; rewrite ffunE rmorphZ_num (nth_map 0). have{Dx} ->: x1 = \sum_i a i *: s1`_i. apply: (fmorph_inj QxsC); rewrite Dx rmorph_sum /=. by apply: eq_bigr => i _; rewrite rmorphZ_num (nth_map 0). by apply: memv_suml => i _; rewrite memvZ ?memv_span ?mem_nth. Qed. Definition Crat_span s : pred algC := Crat_span_subproof s. Lemma Crat_spanP s x : reflect (in_Crat_span s x) (x \in Crat_span s). Proof. exact: sumboolP. Qed. Lemma mem_Crat_span s : {subset s <= Crat_span s}. Proof. move=> _ /(nthP 0)[ix ltxs <-]; pose i0 := Ordinal ltxs. apply/Crat_spanP; exists [ffun i => (i == i0)%:R]. rewrite (bigD1_ord i0) //= ffunE eqxx // rmorph1 mul1r. by rewrite big1 ?addr0 // => i; rewrite ffunE rmorph_nat mulr_natl lift_eqF. Qed. Fact Crat_span_zmod_closed s : zmod_closed (Crat_span s). Proof. split=> [|_ _ /Crat_spanP[x ->] /Crat_spanP[y ->]]. apply/Crat_spanP; exists 0. by apply/esym/big1=> i _; rewrite ffunE rmorph0 mul0r. apply/Crat_spanP; exists (x - y); rewrite -sumrB; apply: eq_bigr => i _. by rewrite -mulrBl -rmorphB !ffunE. Qed. HB.instance Definition _ s := GRing.isZmodClosed.Build _ (Crat_span s) (Crat_span_zmod_closed s). Section NumFieldProj. Variables (Qn : fieldExtType rat) (QnC : {rmorphism Qn -> algC}). Lemma Crat_spanZ b a : {in Crat_span b, forall x, ratr a * x \in Crat_span b}. Proof. move=> _ /Crat_spanP[a1 ->]; apply/Crat_spanP; exists [ffun i => a * a1 i]. by rewrite mulr_sumr; apply: eq_bigr => i _; rewrite ffunE mulrA -rmorphM. Qed. Lemma Crat_spanM b : {in Crat & Crat_span b, forall a x, a * x \in Crat_span b}. Proof. by move=> _ x /CratP[a ->]; apply: Crat_spanZ. Qed. (* In principle CtoQn could be taken to be additive and Q-linear, but this *) (* would require a limit construction. *) Lemma num_field_proj : {CtoQn | CtoQn 0 = 0 & cancel QnC CtoQn}. Proof. pose b := vbasis {:Qn}. have Qn_bC (u : {x | x \in Crat_span (map QnC b)}): {y | QnC y = sval u}. case: u => _ /= /Crat_spanP/sig_eqW[a ->]. exists (\sum_i a i *: b`_i); rewrite rmorph_sum /=; apply: eq_bigr => i _. by rewrite rmorphZ_num (nth_map 0) // -(size_map QnC). pose CtoQn x := oapp (fun u => sval (Qn_bC u)) 0 (insub x). suffices QnCK: cancel QnC CtoQn by exists CtoQn; rewrite // -(rmorph0 QnC) /=. move=> x; rewrite /CtoQn insubT => /= [|Qn_x]; last first. by case: (Qn_bC _) => x1 /= /fmorph_inj. rewrite (coord_vbasis (memvf x)) rmorph_sum rpred_sum //= => i _. rewrite rmorphZ_num Crat_spanZ ?mem_Crat_span // -/b. by rewrite -tnth_nth -tnth_map mem_tnth. Qed. Lemma restrict_aut_to_num_field (nu : {rmorphism algC -> algC}) : (forall x, exists y, nu (QnC x) = QnC y) -> {nu0 : {lrmorphism Qn -> Qn} | {morph QnC : x / nu0 x >-> nu x}}. Proof. move=> Qn_nu; pose nu0 x := sval (sig_eqW (Qn_nu x)). have QnC_nu0: {morph QnC : x / nu0 x >-> nu x}. by rewrite /nu0 => x; case: (sig_eqW _). have nu0a : zmod_morphism nu0. by move=> x y; apply: (fmorph_inj QnC); rewrite !(QnC_nu0, rmorphB). have nu0m : monoid_morphism nu0. split=> [|x y]; apply: (fmorph_inj QnC); rewrite ?QnC_nu0 ?rmorph1 //. by rewrite !rmorphM /= !QnC_nu0. pose nu0aM := GRing.isZmodMorphism.Build Qn Qn nu0 nu0a. pose nu0mM := GRing.isMonoidMorphism.Build Qn Qn nu0 nu0m. pose nu0RM : {rmorphism _ -> _} := HB.pack nu0 nu0aM nu0mM. pose nu0lM := GRing.isScalable.Build rat Qn Qn *:%R nu0 (fmorph_numZ nu0RM). pose nu0LRM : {lrmorphism _ -> _} := HB.pack nu0 nu0aM nu0mM nu0lM. by exists nu0LRM. Qed. Lemma map_Qnum_poly (nu : {rmorphism algC -> algC}) p : p \in polyOver 1%VS -> map_poly (nu \o QnC) p = (map_poly QnC p). Proof. move=> Qp; apply/polyP=> i; rewrite /= !coef_map /=. have /vlineP[a ->]: p`_i \in 1%VS by apply: polyOverP. by rewrite alg_num_field !fmorph_rat. Qed. End NumFieldProj. Lemma restrict_aut_to_normal_num_field (Qn : splittingFieldType rat) (QnC : {rmorphism Qn -> algC})(nu : {rmorphism algC -> algC}) : {nu0 : {lrmorphism Qn -> Qn} | {morph QnC : x / nu0 x >-> nu x}}. Proof. apply: restrict_aut_to_num_field => x. case: (splitting_field_normal 1%AS x) => rs /eqP Hrs. have: root (map_poly (nu \o QnC) (minPoly 1%AS x)) (nu (QnC x)). by rewrite fmorph_root root_minPoly. rewrite map_Qnum_poly ?minPolyOver // Hrs. rewrite [map_poly _ _](_:_ = \prod_(y <- map QnC rs) ('X - y%:P)). by rewrite root_prod_XsubC; case/mapP => y _ ?; exists y. by rewrite big_map rmorph_prod /=; apply: eq_bigr => i _; rewrite map_polyXsubC. Qed. (* Integral spans. *) Lemma dec_Cint_span (V : vectType algC) m (s : m.-tuple V) v : decidable (inIntSpan s v). Proof. have s_s (i : 'I_m): s`_i \in <<s>>%VS by rewrite memv_span ?memt_nth. have s_Zs a: \sum_(i < m) s`_i *~ a i \in <<s>>%VS. by rewrite memv_suml // => i _; rewrite -scaler_int memvZ. case s_v: (v \in <<s>>%VS); last by right=> [[a Dv]]; rewrite Dv s_Zs in s_v. pose IzT := {: 'I_m * 'I_(\dim <<s>>)}; pose Iz := 'I_#|IzT|. pose b := vbasis <<s>>. pose z_s := [seq coord b ij.2 (tnth s ij.1) | ij : IzT]. pose rank2 j i: Iz := enum_rank (i, j); pose val21 (p : Iz) := (enum_val p).1. pose inQzs w := [forall j, Crat_span z_s (coord b j w)]. have enum_pairK j: {in predT, cancel (rank2 j) val21}. by move=> i; rewrite /val21 enum_rankK. have Qz_Zs a: inQzs (\sum_(i < m) s`_i *~ a i). apply/forallP=> j; apply/Crat_spanP; rewrite /in_Crat_span size_map -cardE. exists [ffun ij => (a (val21 ij))%:Q *+ ((enum_val ij).2 == j)]. rewrite linear_sum {1}(reindex_onto _ _ (enum_pairK j)) big_mkcond /=. apply: eq_bigr => ij _ /=; rewrite nth_image (tnth_nth 0) ffunE /val21. rewrite raddfMz rmorphMn rmorph_int mulrnAl mulrzl /=. rewrite (can2_eq (@enum_rankK _) (@enum_valK _)). by case: (enum_val ij) => i j1; rewrite xpair_eqE eqxx; have [->|] := eqVneq. case Qz_v: (inQzs v); last by right=> [[a Dv]]; rewrite Dv Qz_Zs in Qz_v. have [Qz [QzC [z1s Dz_s _]]] := num_field_exists z_s. have sz_z1s: size z1s = #|IzT| by rewrite -(size_map QzC) Dz_s size_map cardE. have xv j: {x | coord b j v = QzC x}. apply: sig_eqW; have /Crat_spanP[x ->] := forallP Qz_v j. exists (\sum_ij x ij *: z1s`_ij); rewrite rmorph_sum; apply: eq_bigr => ij _. by rewrite rmorphZ_num -[in RHS](nth_map _ 0) ?Dz_s // -(size_map QzC) Dz_s. pose sz := [tuple [ffun j => z1s`_(rank2 j i)] | i < m]. have [Zsv | Zs'v] := dec_Qint_span sz [ffun j => sval (xv j)]. left; have{Zsv} [a Dv] := Zsv; exists a. transitivity (\sum_j \sum_(i < m) QzC ((sz`_i *~ a i) j) *: b`_j). rewrite {1}(coord_vbasis s_v) -/b; apply: eq_bigr => j _. rewrite -scaler_suml; congr (_ *: _). have{Dv} /ffunP/(_ j) := Dv; rewrite sum_ffunE !ffunE -rmorph_sum => <-. by case: (xv j). rewrite exchange_big; apply: eq_bigr => i _. rewrite (coord_vbasis (s_s i)) -/b mulrz_suml; apply: eq_bigr => j _. rewrite scalerMzl ffunMzE rmorphMz; congr ((_ *~ _) *: _). rewrite nth_mktuple ffunE -(nth_map _ 0) ?sz_z1s // Dz_s. by rewrite nth_image enum_rankK /= (tnth_nth 0). right=> [[a Dv]]; case: Zs'v; exists a. apply/ffunP=> j; rewrite sum_ffunE !ffunE; apply: (fmorph_inj QzC). case: (xv j) => /= _ <-; rewrite Dv linear_sum rmorph_sum /=. apply: eq_bigr => i _; rewrite nth_mktuple raddfMz !ffunMzE rmorphMz ffunE. by rewrite -(nth_map _ 0 QzC) ?sz_z1s // Dz_s nth_image enum_rankK -tnth_nth. Qed. Definition Cint_span (s : seq algC) : pred algC := fun x => dec_Cint_span (in_tuple [seq \row_(i < 1) y | y <- s]) (\row_i x). Lemma Cint_spanP n (s : n.-tuple algC) x : reflect (inIntSpan s x) (x \in Cint_span s). Proof. rewrite unfold_in; case: (dec_Cint_span _ _) => [Zs_x | Zs'x] /=. left; have{Zs_x} [] := Zs_x; rewrite /= size_map size_tuple => a /rowP/(_ 0). rewrite !mxE => ->; exists a; rewrite summxE; apply: eq_bigr => i _. by rewrite -scaler_int (nth_map 0) ?size_tuple // !mxE mulrzl. right=> [[a Dx]]; have{Zs'x} [] := Zs'x. rewrite /inIntSpan /= size_map size_tuple; exists a. apply/rowP=> i0; rewrite !mxE summxE Dx; apply: eq_bigr => i _. by rewrite -scaler_int mxE mulrzl (nth_map 0) ?size_tuple // !mxE. Qed. Lemma mem_Cint_span s : {subset s <= Cint_span s}. Proof. move=> _ /(nthP 0)[ix ltxs <-]; apply/(Cint_spanP (in_tuple s)). exists [ffun i => i == Ordinal ltxs : int]. rewrite (bigD1 (Ordinal ltxs)) //= ffunE eqxx. by rewrite big1 ?addr0 // => i; rewrite ffunE => /negbTE->. Qed. Lemma Cint_span_zmod_closed s : zmod_closed (Cint_span s). Proof. have sP := Cint_spanP (in_tuple s); split=> [|_ _ /sP[x ->] /sP[y ->]]. by apply/sP; exists 0; rewrite big1 // => i; rewrite ffunE. apply/sP; exists (x - y); rewrite -sumrB; apply: eq_bigr => i _. by rewrite !ffunE raddfB. Qed. HB.instance Definition _ s := GRing.isZmodClosed.Build _ (Cint_span s) (Cint_span_zmod_closed s). (* Automorphism extensions. *) Lemma extend_algC_subfield_aut (Qs : fieldExtType rat) (QsC : {rmorphism Qs -> algC}) (phi : {rmorphism Qs -> Qs}) : {nu : {rmorphism algC -> algC} | {morph QsC : x / phi x >-> nu x}}. Proof. pose numF_inj (Qr : fieldExtType rat) := {rmorphism Qr -> algC}. pose subAut := {Qr : _ & numF_inj Qr * {lrmorphism Qr -> Qr}}%type. pose SubAut := existT _ _ (_, _) : subAut. pose Sdom (mu : subAut) := projT1 mu. pose Sinj (mu : subAut) : {rmorphism Sdom mu -> algC} := (projT2 mu).1. pose Saut (mu : subAut) : {rmorphism Sdom mu -> Sdom mu} := (projT2 mu).2. have Sinj_poly Qr (QrC : numF_inj Qr) p: map_poly QrC (map_poly (in_alg Qr) p) = pQtoC p. - rewrite -map_poly_comp; apply: eq_map_poly => a. by rewrite /= rmorphZ_num rmorph1 mulr1. have ext1 mu0 x : {mu1 | exists y, x = Sinj mu1 y & exists2 in01 : {lrmorphism _ -> _}, Sinj mu0 =1 Sinj mu1 \o in01 & {morph in01: y / Saut mu0 y >-> Saut mu1 y}}. - pose b0 := vbasis {:Sdom mu0}. have [z _ /sig_eqW[[|px ps] // [Dx Ds]]] := algC_PET (x :: map (Sinj mu0) b0). have [p [_ mon_p] /(_ p) pz0] := minCpolyP z; rewrite dvdpp in pz0. have [r Dr] := closed_field_poly_normal (pQtoC p : {poly algC}). rewrite lead_coef_map {mon_p}(monicP mon_p) rmorph1 scale1r in Dr. have{pz0} rz: z \in r by rewrite -root_prod_XsubC -Dr. have [Qr [QrC [rr Drr genQr]]] := num_field_exists r. have{rz} [zz Dz]: {zz | QrC zz = z}. by move: rz; rewrite -Drr => /mapP/sig2_eqW[zz]; exists zz. have{ps Ds} [in01 Din01]: {in01 : {lrmorphism _ -> _} | Sinj mu0 =1 QrC \o in01}. have in01P y: {yy | Sinj mu0 y = QrC yy}. exists (\sum_i coord b0 i y *: (map_poly (in_alg Qr) ps`_i).[zz]). rewrite {1}(coord_vbasis (memvf y)) !rmorph_sum /=; apply: eq_bigr => i _. rewrite 2!rmorphZ_num -(nth_map _ 0) ?size_tuple // Ds. rewrite -horner_map Dz Sinj_poly (nth_map 0) //. by have:= congr1 size Ds; rewrite !size_map size_tuple => <-. pose in01 y := sval (in01P y). have Din01 y: Sinj mu0 y = QrC (in01 y) by rewrite /in01; case: (in01P y). pose rwM := (=^~ Din01, rmorphZ_num, rmorph1, rmorphB, rmorphM). have in01a : zmod_morphism in01. by move=> ? ?; apply: (fmorph_inj QrC); rewrite !rwM. have in01m : monoid_morphism in01. by split; try move=> ? ?; apply: (fmorph_inj QrC); rewrite !rwM /= ?rwM. have in01l : scalable in01. by try move=> ? ?; apply: (fmorph_inj QrC); rewrite !rwM. pose in01aM := GRing.isZmodMorphism.Build _ _ in01 in01a. pose in01mM := GRing.isMonoidMorphism.Build _ _ in01 in01m. pose in01lM := GRing.isScalable.Build _ _ _ _ in01 in01l. pose in01LRM : {lrmorphism _ -> _} := HB.pack in01 in01aM in01mM in01lM. by exists in01LRM. have {z zz Dz px} Dx: exists xx, x = QrC xx. exists (map_poly (in_alg Qr) px).[zz]. by rewrite -horner_map Dz Sinj_poly Dx. pose lin01 := linfun in01; pose K := (lin01 @: fullv)%VS. have memK y: reflect (exists yy, y = in01 yy) (y \in K). apply: (iffP memv_imgP) => [[yy _ ->] | [yy ->]]; by exists yy; rewrite ?lfunE ?memvf. have algK: is_aspace K. rewrite /is_aspace has_algid1; last first. by apply/memK; exists 1; rewrite rmorph1. apply/prodvP=> _ _ /memK[y1 ->] /memK[y2 ->]. by apply/memK; exists (y1 * y2); rewrite rmorphM. have ker_in01: lker lin01 == 0%VS. by apply/lker0P=> y1 y2; rewrite !lfunE; apply: fmorph_inj. pose f := (lin01 \o linfun (Saut mu0) \o lin01^-1)%VF. have Df y: f (in01 y) = in01 (Saut mu0 y). transitivity (f (lin01 y)); first by rewrite !lfunE. by do 4!rewrite lfunE /=; rewrite lker0_lfunK. have hom_f: kHom 1 (ASpace algK) f. apply/kHomP_tmp; split=> [_ /vlineP[a ->] | _ _ /memK[y1 ->] /memK[y2 ->]]. by rewrite -(rmorph_alg in01) Df /= !rmorph_alg. by rewrite -rmorphM !Df !rmorphM. pose pr := map_poly (in_alg Qr) p. have Qpr: pr \is a polyOver 1%VS. by apply/polyOverP=> i; rewrite coef_map memvZ ?memv_line. have splitQr: splittingFieldFor K pr fullv. apply: splittingFieldForS (sub1v (Sub K algK)) (subvf _) _; exists rr => //. congr (_ %= _): (eqpxx pr); apply/(map_poly_inj QrC). rewrite Sinj_poly Dr -Drr big_map rmorph_prod /=; apply: eq_bigr => zz _. by rewrite map_polyXsubC. have [f1 aut_f1 Df1]:= kHom_extends (sub1v (ASpace algK)) hom_f Qpr splitQr. pose f1mM := GRing.isMonoidMorphism.Build _ _ f1 (kHom_monoid_morphism aut_f1). pose nu : {lrmorphism _ -> _} := HB.pack (fun_of_lfun f1) f1mM. exists (SubAut Qr QrC nu) => //; exists in01 => //= y. by rewrite -Df -Df1 //; apply/memK; exists y. have phiZ: scalable phi. by move=> a y; rewrite rmorphZ_num -alg_num_field mulr_algl. pose philM := GRing.isScalable.Build _ _ _ _ phi phiZ. pose phiLRM : {lrmorphism _ -> _} := HB.pack (GRing.RMorphism.sort phi) philM. pose fix ext n := if n is i.+1 then oapp (fun x => s2val (ext1 (ext i) x)) (ext i) (unpickle i) else SubAut Qs QsC phiLRM. have mem_ext x n: (pickle x < n)%N -> {xx | Sinj (ext n) xx = x}. move=> ltxn; apply: sig_eqW; elim: n ltxn => // n IHn. rewrite ltnS leq_eqVlt => /predU1P[<- | /IHn[xx <-]] /=. by rewrite pickleK /=; case: (ext1 _ x) => mu [xx]; exists xx. case: (unpickle n) => /= [y|]; last by exists xx. case: (ext1 _ y) => mu /= _ [in_mu inj_in_mu _]. by exists (in_mu xx); rewrite inj_in_mu. pose nu x := Sinj _ (Saut _ (sval (mem_ext x _ (ltnSn _)))). have nu_inj n y: nu (Sinj (ext n) y) = Sinj (ext n) (Saut (ext n) y). rewrite /nu; case: (mem_ext _ _ _); move: _.+1 => n1 y1 Dy /=. without loss /subnK Dn1: n n1 y y1 Dy / (n <= n1)%N. by move=> IH; case/orP: (leq_total n n1) => /IH => [/(_ y) | /(_ y1)]->. move: (n1 - n)%N => k in Dn1; elim: k => [|k IHk] in n Dn1 y Dy *. by move: y1 Dy; rewrite -Dn1 => y1 /fmorph_inj ->. rewrite addSnnS in Dn1; move/IHk: Dn1 => /=. case: (unpickle _) => [z|] /=; last exact. case: (ext1 _ _) => mu /= _ [in_mu Dinj Daut]. by rewrite Dy => /(_ _ (Dinj _))->; rewrite -Daut Dinj. pose le_nu (x : algC) n := (pickle x < n)%N. have max3 x1 x2 x3: exists n, [/\ le_nu x1 n, le_nu x2 n & le_nu x3 n]. exists (maxn (pickle x1) (maxn (pickle x2) (pickle x3))).+1. by apply/and3P; rewrite /le_nu !ltnS -!geq_max. have nua : zmod_morphism nu. move=> x1 x2; have [n] := max3 (x1 - x2) x1 x2. case=> /mem_ext[y Dx] /mem_ext[y1 Dx1] /mem_ext[y2 Dx2]. rewrite -Dx nu_inj; rewrite -Dx1 -Dx2 -rmorphB in Dx. by rewrite (fmorph_inj _ Dx) !rmorphB -!nu_inj Dx1 Dx2. have num : monoid_morphism nu. split=> [|x1 x2]; first by rewrite -(rmorph1 QsC) (nu_inj 0) !rmorph1. have [n] := max3 (x1 * x2) x1 x2. case=> /mem_ext[y Dx] /mem_ext[y1 Dx1] /mem_ext[y2 Dx2]. rewrite -Dx nu_inj; rewrite -Dx1 -Dx2 -rmorphM in Dx. by rewrite (fmorph_inj _ Dx) !rmorphM /= -!nu_inj Dx1 Dx2. pose nuaM := GRing.isZmodMorphism.Build _ _ nu nua. pose numM := GRing.isMonoidMorphism.Build _ _ nu num. pose nuRM : {rmorphism _ -> _} := HB.pack nu nuaM numM. by exists nuRM => x; rewrite /= (nu_inj 0). Qed. (* Extended automorphisms of Q_n. *) Lemma Qn_aut_exists k n : coprime k n -> {u : {rmorphism algC -> algC} | forall z, z ^+ n = 1 -> u z = z ^+ k}. Proof. have [-> /eqnP | n_gt0 co_k_n] := posnP n. by rewrite gcdn0 => ->; exists idfun. have [z prim_z] := C_prim_root_exists n_gt0. have [Qn [QnC [[|zn []] // [Dz]]] genQn] := num_field_exists [:: z]. pose phi := kHomExtend 1 \1 zn (zn ^+ k). have homQn1: kHom 1 1 (\1%VF : 'End(Qn)) by rewrite kHom1. have pzn_zk0: root (map_poly \1%VF (minPoly 1 zn)) (zn ^+ k). rewrite -(fmorph_root QnC) rmorphXn /= Dz -map_poly_comp. rewrite (@eq_map_poly _ _ _ QnC) => [|a]; last by rewrite /= id_lfunE. set p1 := map_poly _ _. have [q1 Dp1]: exists q1, p1 = pQtoC q1. have aP i: (minPoly 1 zn)`_i \in 1%VS. by apply/polyOverP; apply: minPolyOver. have{aP} a_ i := sig_eqW (vlineP _ _ (aP i)). exists (\poly_(i < size (minPoly 1 zn)) sval (a_ i)). apply/polyP=> i; rewrite coef_poly coef_map coef_poly /=. case: ifP => _; rewrite ?rmorph0 //; case: (a_ i) => a /= ->. by rewrite alg_num_field fmorph_rat. have: root p1 z by rewrite -Dz fmorph_root root_minPoly. rewrite Dp1; have [q2 [Dq2 _] ->] := minCpolyP z. case/dvdpP=> r1 ->; rewrite rmorphM rootM /= -Dq2; apply/orP; right. rewrite (minCpoly_cyclotomic prim_z) /cyclotomic. rewrite (bigD1 (Ordinal (ltn_pmod k n_gt0))) ?coprime_modl //=. by rewrite rootM root_XsubC prim_expr_mod ?eqxx. have phim : monoid_morphism phi. by apply/kHom_monoid_morphism; rewrite -genQn span_seq1 /= kHomExtendP. pose phimM := GRing.isMonoidMorphism.Build _ _ phi phim. pose phiRM : {rmorphism _ -> _} := HB.pack (fun_of_lfun phi) phimM. have [nu Dnu] := extend_algC_subfield_aut QnC phiRM. exists nu => _ /(prim_rootP prim_z)[i ->]. rewrite rmorphXn /= exprAC -Dz -Dnu /= -{1}[zn]hornerX /phi. rewrite (kHomExtend_poly homQn1) ?polyOverX //. rewrite map_polyE map_id_in => [|?]; last by rewrite id_lfunE. by rewrite polyseqK hornerX rmorphXn. Qed. (* Algebraic integers. *) Definition Aint : {pred algC} := fun x => minCpoly x \is a polyOver Num.int. Lemma root_monic_Aint p x : root p x -> p \is monic -> p \is a polyOver Num.int -> x \in Aint. Proof. have pZtoQtoC pz: pQtoC (pZtoQ pz) = pZtoC pz. by rewrite -map_poly_comp; apply: eq_map_poly => b; rewrite /= rmorph_int. move=> px0 mon_p /floorpP[pz Dp]; rewrite unfold_in. move: px0; rewrite Dp -pZtoQtoC; have [q [-> mon_q] ->] := minCpolyP x. case/dvdpP_rat_int=> qz [a nz_a Dq] [r]. move/(congr1 (fun q1 => lead_coef (a *: pZtoQ q1))). rewrite rmorphM scalerAl -Dq lead_coefZ lead_coefM /=. have /monicP->: pZtoQ pz \is monic by rewrite -(map_monic QtoC) pZtoQtoC -Dp. rewrite (monicP mon_q) mul1r mulr1 lead_coef_map_inj //; last exact: intr_inj. rewrite Dq => ->; apply/polyOverP=> i; rewrite !(coefZ, coef_map). by rewrite -rmorphM /= rmorph_int. Qed. Lemma Cint_rat_Aint z : z \in Crat -> z \in Aint -> z \in Num.int. Proof. case/CratP=> a ->{z} /polyOverP/(_ 0). have [p [Dp mon_p] dv_p] := minCpolyP (ratr a); rewrite Dp coef_map. suffices /eqP->: p == 'X - a%:P by rewrite polyseqXsubC /= rmorphN rpredN. rewrite -eqp_monic ?monicXsubC // irredp_XsubC //. by rewrite -(size_map_poly QtoC) -Dp neq_ltn size_minCpoly orbT. by rewrite -dv_p fmorph_root root_XsubC. Qed. Lemma Aint_Cint : {subset Num.int <= Aint}. Proof. move=> x; rewrite -polyOverXsubC. by apply: root_monic_Aint; rewrite ?monicXsubC ?root_XsubC. Qed. Lemma Aint_int x : x%:~R \in Aint. Proof. by rewrite Aint_Cint. Qed. Lemma Aint0 : 0 \in Aint. Proof. exact: Aint_int 0. Qed. Lemma Aint1 : 1 \in Aint. Proof. exact: Aint_int 1. Qed. #[global] Hint Resolve Aint0 Aint1 : core. Lemma Aint_unity_root n x : (n > 0)%N -> n.-unity_root x -> x \in Aint. Proof. move=> n_gt0 xn1; apply: root_monic_Aint xn1 (monicXnsubC _ n_gt0) _. by apply/polyOverP=> i; rewrite coefB coefC -mulrb coefXn /= rpredB ?rpred_nat. Qed. Lemma Aint_prim_root n z : n.-primitive_root z -> z \in Aint. Proof. move=> pr_z; apply/(Aint_unity_root (prim_order_gt0 pr_z))/unity_rootP. exact: prim_expr_order. Qed. Lemma Aint_Cnat : {subset Num.nat <= Aint}. Proof. by move=> z /intr_nat/Aint_Cint. Qed. (* This is Isaacs, Lemma (3.3) *) Lemma Aint_subring_exists (X : seq algC) : {subset X <= Aint} -> {S : pred algC & (*a*) subring_closed S /\ (*b*) {subset X <= S} & (*c*) {Y : {n : nat & n.-tuple algC} & {subset tagged Y <= S} & forall x, reflect (inIntSpan (tagged Y) x) (x \in S)}}. Proof. move=> AZ_X; pose m := (size X).+1. pose n (i : 'I_m) := (size (minCpoly X`_i)).-2; pose N := (\max_i n i).+1. pose IY := family (fun i => [pred e : 'I_N | e <= n i]%N). have IY_0: 0 \in IY by apply/familyP=> // i; rewrite ffunE. pose inIY := enum_rank_in IY_0. pose Y := [seq \prod_(i < m) X`_i ^+ (f : 'I_N ^ m) i | f in IY]. have S_P := Cint_spanP [tuple of Y]; set S := Cint_span _ in S_P. have sYS: {subset Y <= S} by apply: mem_Cint_span. have S_1: 1 \in S. by apply/sYS/imageP; exists 0 => //; rewrite big1 // => i; rewrite ffunE. have SmulX (i : 'I_m): {in S, forall x, x * X`_i \in S}. move=> _ /S_P[x ->]; rewrite mulr_suml rpred_sum // => j _. rewrite mulrzAl rpredMz {x}// nth_image mulrC (bigD1 i) //= mulrA -exprS. move: {j}(enum_val j) (familyP (enum_valP j)) => f fP. have:= fP i; rewrite inE /= leq_eqVlt => /predU1P[-> | fi_ltn]; last first. apply/sYS/imageP; have fiK: (inord (f i).+1 : 'I_N) = (f i).+1 :> nat. by rewrite inordK // ltnS (bigmax_sup i). exists (finfun [eta f with i |-> inord (f i).+1]). apply/familyP=> i1; rewrite inE ffunE /= fun_if fiK. by case: eqP => [-> // | _]; apply: fP. rewrite (bigD1 i isT) ffunE /= eqxx fiK; congr (_ * _). by apply: eq_bigr => i1 /[!ffunE]/= /negPf->. have [/monicP ] := (minCpoly_monic X`_i, root_minCpoly X`_i). rewrite /root horner_coef lead_coefE -(subnKC (size_minCpoly _)) subn2. rewrite big_ord_recr /= addrC addr_eq0 => ->; rewrite mul1r => /eqP->. have /floorpP[p Dp]: X`_i \in Aint. by have [/(nth_default 0)-> | /(mem_nth 0)/AZ_X] := leqP (size X) i. rewrite -/(n i) Dp mulNr rpredN // mulr_suml rpred_sum // => [[e le_e]] /= _. rewrite coef_map -mulrA mulrzl rpredMz ?sYS //; apply/imageP. have eK: (inord e : 'I_N) = e :> nat by rewrite inordK // ltnS (bigmax_sup i). exists (finfun [eta f with i |-> inord e]). apply/familyP=> i1; rewrite inE ffunE /= fun_if eK. by case: eqP => [-> // | _]; apply: fP. rewrite (bigD1 i isT) ffunE /= eqxx eK; congr (_ * _). by apply: eq_bigr => i1 /[!ffunE] /= /negPf->. exists S; last by exists (Tagged (fun n => n.-tuple _) [tuple of Y]). split=> [|x Xx]; last first. by rewrite -[x]mul1r -(nth_index 0 Xx) (SmulX (Ordinal _)) // ltnS index_size. split=> // x y Sx Sy; first by rewrite rpredB. case/S_P: Sy => {y}[y ->]; rewrite mulr_sumr rpred_sum //= => j. rewrite mulrzAr rpredMz {y}// nth_image; move: {j}(enum_val j) => f. elim/big_rec: _ => [|i y _ IHy] in x Sx *; first by rewrite mulr1. rewrite mulrA {y}IHy //. elim: {f}(f i : nat) => [|e IHe] in x Sx *; first by rewrite mulr1. by rewrite exprS mulrA IHe // SmulX. Qed. Section AlgIntSubring. (* This is Isaacs, Theorem (3.4). *) Theorem fin_Csubring_Aint S n (Y : n.-tuple algC) : mulr_closed S -> (forall x, reflect (inIntSpan Y x) (x \in S)) -> {subset S <= Aint}. Proof. move=> mulS. pose Sm := GRing.isMulClosed.Build _ _ mulS. pose SC : mulrClosed _ := HB.pack S Sm. have ZP_C c: (ZtoC c)%:P \is a polyOver Num.int_num_subdef. by rewrite raddfMz rpred_int. move=> S_P x Sx; pose v := \row_(i < n) Y`_i. have [v0 | nz_v] := eqVneq v 0. case/S_P: Sx => {}x ->; rewrite big1 ?isAlgInt0 // => i _. by have /rowP/(_ i)/[!mxE] -> := v0; rewrite mul0rz. have sYS (i : 'I_n): x * Y`_i \in SC. by rewrite rpredM //; apply/S_P/Cint_spanP/mem_Cint_span/memt_nth. pose A := \matrix_(i, j < n) sval (sig_eqW (S_P _ (sYS j))) i. pose p := char_poly (map_mx ZtoC A). have: p \is a polyOver Num.int_num_subdef. rewrite rpred_sum // => s _; rewrite rpredMsign rpred_prod // => j _. by rewrite !mxE /= rpredB ?rpredMn ?polyOverX. apply: root_monic_Aint (char_poly_monic _). rewrite -eigenvalue_root_char; apply/eigenvalueP; exists v => //. apply/rowP=> j; case dAj: (sig_eqW (S_P _ (sYS j))) => [a DxY]. by rewrite !mxE DxY; apply: eq_bigr => i _; rewrite !mxE dAj /= mulrzr. Qed. (* This is Isaacs, Corollary (3.5). *) Corollary Aint_subring : subring_closed Aint. Proof. suff rAZ: {in Aint &, forall x y, (x - y \in Aint) * (x * y \in Aint)}. by split=> // x y AZx AZy; rewrite rAZ. move=> x y AZx AZy. have [|S [ringS] ] := @Aint_subring_exists [:: x; y]; first exact/allP/and3P. move=> /allP/and3P[Sx Sy _] [Y _ genYS]. have AZ_S := fin_Csubring_Aint ringS genYS. by have [_ S_B S_M] := ringS; rewrite !AZ_S ?S_B ?S_M. Qed. HB.instance Definition _ := GRing.isSubringClosed.Build _ Aint Aint_subring. End AlgIntSubring. Lemma Aint_aut (nu : {rmorphism algC -> algC}) x : (nu x \in Aint) = (x \in Aint). Proof. by rewrite !unfold_in minCpoly_aut. Qed. Definition dvdA (e : Algebraics.divisor) : {pred algC} := fun z => if e == 0 then z == 0 else z / e \in Aint. Delimit Scope algC_scope with A. Delimit Scope algC_expanded_scope with Ax. Notation "e %| x" := (x \in dvdA e) : algC_expanded_scope. Notation "e %| x" := (@in_mem Algebraics.divisor x (mem (dvdA e))) : algC_scope. Fact dvdA_zmod_closed e : zmod_closed (dvdA e). Proof. split=> [|x y]; first by rewrite unfold_in mul0r eqxx rpred0 ?if_same. rewrite ![(e %| _)%A]unfold_in. case: ifP => [_ x0 /eqP-> | _]; first by rewrite subr0. by rewrite mulrBl; apply: rpredB. Qed. HB.instance Definition _ e := GRing.isZmodClosed.Build _ (dvdA e) (dvdA_zmod_closed e). Definition eqAmod (e x y : Algebraics.divisor) := (e %| x - y)%A. Notation "x == y %[mod e ]" := (eqAmod e x y) : algC_scope. Notation "x != y %[mod e ]" := (~~ (eqAmod e x y)) : algC_scope. Lemma eqAmod_refl e x : (x == x %[mod e])%A. Proof. by rewrite /eqAmod subrr rpred0. Qed. #[global] Hint Resolve eqAmod_refl : core. Lemma eqAmod_sym e x y : ((x == y %[mod e]) = (y == x %[mod e]))%A. Proof. by rewrite /eqAmod -opprB rpredN. Qed. Lemma eqAmod_trans e y x z : (x == y %[mod e] -> y == z %[mod e] -> x == z %[mod e])%A. Proof. by move=> Exy Eyz; rewrite /eqAmod -[x](subrK y) -[_ - z]addrA rpredD. Qed. Lemma eqAmod_transl e x y z : (x == y %[mod e])%A -> (x == z %[mod e])%A = (y == z %[mod e])%A. Proof. by move/(sym_left_transitive (eqAmod_sym e) (@eqAmod_trans e)). Qed. Lemma eqAmod_transr e x y z : (x == y %[mod e])%A -> (z == x %[mod e])%A = (z == y %[mod e])%A. Proof. by move/(sym_right_transitive (eqAmod_sym e) (@eqAmod_trans e)). Qed. Lemma eqAmod0 e x : (x == 0 %[mod e])%A = (e %| x)%A. Proof. by rewrite /eqAmod subr0. Qed. Lemma eqAmodN e x y : (- x == y %[mod e])%A = (x == - y %[mod e])%A. Proof. by rewrite eqAmod_sym /eqAmod !opprK addrC. Qed. Lemma eqAmodDr e x y z : (y + x == z + x %[mod e])%A = (y == z %[mod e])%A. Proof. by rewrite /eqAmod addrAC opprD !addrA subrK. Qed. Lemma eqAmodDl e x y z : (x + y == x + z %[mod e])%A = (y == z %[mod e])%A. Proof. by rewrite !(addrC x) eqAmodDr. Qed. Lemma eqAmodD e x1 x2 y1 y2 : (x1 == x2 %[mod e] -> y1 == y2 %[mod e] -> x1 + y1 == x2 + y2 %[mod e])%A. Proof. by rewrite -(eqAmodDl e x2 y1) -(eqAmodDr e y1); apply: eqAmod_trans. Qed. Lemma eqAmodm0 e : (e == 0 %[mod e])%A. Proof. by rewrite /eqAmod subr0 unfold_in; case: ifPn => // /divff->. Qed. #[global] Hint Resolve eqAmodm0 : core. Lemma eqAmodMr e : {in Aint, forall z x y, x == y %[mod e] -> x * z == y * z %[mod e]}%A. Proof. move=> z Zz x y. rewrite /eqAmod -mulrBl ![(e %| _)%A]unfold_in mulf_eq0 mulrAC. by case: ifP => [_ -> // | _ Exy]; apply: rpredM. Qed. Lemma eqAmodMl e : {in Aint, forall z x y, x == y %[mod e] -> z * x == z * y %[mod e]}%A. Proof. by move=> z Zz x y Exy; rewrite !(mulrC z) eqAmodMr. Qed. Lemma eqAmodMl0 e : {in Aint, forall x, x * e == 0 %[mod e]}%A. Proof. by move=> x Zx; rewrite -(mulr0 x) eqAmodMl. Qed. Lemma eqAmodMr0 e : {in Aint, forall x, e * x == 0 %[mod e]}%A. Proof. by move=> x Zx; rewrite /= mulrC eqAmodMl0. Qed. Lemma eqAmod_addl_mul e : {in Aint, forall x y, x * e + y == y %[mod e]}%A. Proof. by move=> x Zx y; rewrite -{2}[y]add0r eqAmodDr eqAmodMl0. Qed. Lemma eqAmodM e : {in Aint &, forall x1 y2 x2 y1, x1 == x2 %[mod e] -> y1 == y2 %[mod e] -> x1 * y1 == x2 * y2 %[mod e]}%A. Proof. move=> x1 y2 Zx1 Zy2 x2 y1 eq_x /(eqAmodMl Zx1)/eqAmod_trans-> //. exact: eqAmodMr. Qed. Lemma eqAmod_rat : {in Crat & &, forall e m n, (m == n %[mod e])%A = (m == n %[mod e])%C}. Proof. move=> e m n Qe Qm Qn; rewrite /eqCmod unfold_in /eqAmod unfold_in. case: ifPn => // nz_e; apply/idP/idP=> [/Cint_rat_Aint | /Aint_Cint] -> //. by rewrite rpred_div ?rpredB. Qed. Lemma eqAmod0_rat : {in Crat &, forall e n, (n == 0 %[mod e])%A = (e %| n)%C}. Proof. by move=> e n Qe Qn; rewrite /= eqAmod_rat /eqCmod ?subr0 ?Crat0. Qed. Lemma eqAmod_nat (e m n : nat) : (m == n %[mod e])%A = (m == n %[mod e])%N. Proof. by rewrite eqAmod_rat ?rpred_nat // eqCmod_nat. Qed. Lemma eqAmod0_nat (e m : nat) : (m == 0 %[mod e])%A = (e %| m)%N. Proof. by rewrite eqAmod0_rat ?rpred_nat // dvdC_nat. Qed. (* Multiplicative order. *) Definition orderC x := let p := minCpoly x in oapp val 0 [pick n : 'I_(2 * size p ^ 2) | p == intrp 'Phi_n]. Notation "#[ x ]" := (orderC x) : C_scope. Lemma exp_orderC x : x ^+ #[x]%C = 1. Proof. rewrite /orderC; case: pickP => //= [] [n _] /= /eqP Dp. have n_gt0: (0 < n)%N. rewrite lt0n; apply: contraTneq (size_minCpoly x) => n0. by rewrite Dp n0 Cyclotomic0 rmorph1 size_poly1. have [z prim_z] := C_prim_root_exists n_gt0. rewrite prim_expr_order // -(root_cyclotomic prim_z). by rewrite -Cintr_Cyclotomic // -Dp root_minCpoly. Qed. Lemma dvdn_orderC x n : (#[x]%C %| n)%N = (x ^+ n == 1). Proof. apply/idP/eqP=> [|x_n_1]; first by apply: expr_dvd; apply: exp_orderC. have [-> | n_gt0] := posnP n; first by rewrite dvdn0. have [m prim_x m_dv_n] := prim_order_exists n_gt0 x_n_1. have{n_gt0} m_gt0 := dvdn_gt0 n_gt0 m_dv_n; congr (_ %| n)%N: m_dv_n. pose p := minCpoly x; have Dp: p = cyclotomic x m := minCpoly_cyclotomic prim_x. rewrite /orderC; case: pickP => /= [k /eqP Dp_k | no_k]; last first. suffices lt_m_2p: (m < 2 * size p ^ 2)%N. have /eqP[] := no_k (Ordinal lt_m_2p). by rewrite /= -/p Dp -Cintr_Cyclotomic. rewrite Dp size_cyclotomic (sqrnD 1) addnAC mulnDr -add1n leq_add //. suffices: (m <= \prod_(q <- primes m | q == 2) q * totient m ^ 2)%N. have [m_even | m_odd] := boolP (2%N \in primes m). by rewrite -big_filter filter_pred1_uniq ?primes_uniq // big_seq1. by rewrite big_hasC ?has_pred1 // => /leq_trans-> //; apply: leq_addl. rewrite big_mkcond totientE // -mulnn -!big_split /=. rewrite {1}[m]prod_prime_decomp // prime_decompE big_map /= !big_seq. elim/big_ind2: _ => // [n1 m1 n2 m2 | q]; first exact: leq_mul. rewrite mem_primes => /and3P[q_pr _ q_dv_m]. rewrite lognE q_pr m_gt0 q_dv_m /=; move: (logn q _) => k. rewrite !mulnA expnS leq_mul //. case: (ltngtP q 2) (prime_gt1 q_pr) => // [q_gt2|->] _. rewrite mul1n mulnAC mulnn -{1}[q]muln1 leq_mul ?expn_gt0 ?prime_gt0 //. by rewrite -(subnKC q_gt2) (ltn_exp2l 1). by rewrite !muln1 -expnS (ltn_exp2l 0). have k_prim_x: k.-primitive_root x. have k_gt0: (0 < k)%N. rewrite lt0n; apply: contraTneq (size_minCpoly x) => k0. by rewrite Dp_k k0 Cyclotomic0 rmorph1 size_poly1. have [z prim_z] := C_prim_root_exists k_gt0. rewrite -(root_cyclotomic prim_z) -Cintr_Cyclotomic //. by rewrite -Dp_k root_minCpoly. apply/eqP; rewrite eqn_dvd !(@prim_order_dvd _ _ x) //. by rewrite !prim_expr_order ?eqxx. Qed.
Basic.lean
/- Copyright (c) 2022 Jesse Reimann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jesse Reimann, Kalle Kytölä -/ import Mathlib.MeasureTheory.Measure.Content import Mathlib.Topology.ContinuousMap.CompactlySupported import Mathlib.Topology.PartitionOfUnity /-! # Riesz–Markov–Kakutani representation theorem This file prepares technical definitions and results for the Riesz-Markov-Kakutani representation theorem on a locally compact T2 space `X`. As a special case, the statements about linear functionals on bounded continuous functions follows. Actual theorems, depending on the linearity (`ℝ`, `ℝ≥0` or `ℂ`), are proven in separate files (`Mathlib/MeasureTheory/Integral/RieszMarkovKakutani/Real.lean`, `Mathlib/MeasureTheory/Integral/RieszMarkovKakutani/NNReal.lean`...) To make use of the existing API, the measure is constructed from a content `λ` on the compact subsets of a locally compact space X, rather than the usual construction of open sets in the literature. ## References * [Walter Rudin, Real and Complex Analysis.][Rud87] -/ noncomputable section open scoped BoundedContinuousFunction NNReal ENNReal open Set Function TopologicalSpace CompactlySupported CompactlySupportedContinuousMap MeasureTheory variable {X : Type*} [TopologicalSpace X] variable (Λ : C_c(X, ℝ≥0) →ₗ[ℝ≥0] ℝ≥0) /-! ### Construction of the content: -/ section Monotone lemma CompactlySupportedContinuousMap.monotone_of_nnreal : Monotone Λ := by intro f₁ f₂ h obtain ⟨g, hg⟩ := CompactlySupportedContinuousMap.exists_add_of_le h rw [← hg] simp /-- The positivity of a linear functional `Λ` implies that `Λ` is monotone. -/ lemma CompactlySupportedContinuousMap.monotone_of_nonneg {Λ : C_c(X, ℝ) →ₗ[ℝ] ℝ} (hΛ : ∀ f, 0 ≤ f → 0 ≤ Λ f) : Monotone Λ := by intro f₁ f₂ h have : 0 ≤ Λ (f₂ - f₁) := by apply hΛ intro x simp only [coe_zero, Pi.zero_apply, coe_sub, Pi.sub_apply, sub_nonneg] exact h x calc Λ f₁ ≤ Λ f₁ + Λ (f₂ - f₁) := by exact (le_add_iff_nonneg_right (Λ f₁)).mpr this _ = Λ (f₁ + (f₂ - f₁)) := by exact Eq.symm (LinearMap.map_add Λ f₁ (f₂ - f₁)) _ = Λ f₂ := by congr; exact add_sub_cancel f₁ f₂ end Monotone /-- Given a positive linear functional `Λ` on continuous compactly supported functions on `X` with values in `ℝ≥0`, for `K ⊆ X` compact define `λ(K) = inf {Λf | 1≤f on K}`. When `X` is a locally compact T2 space, this will be shown to be a content, and will be shown to agree with the Riesz measure on the compact subsets `K ⊆ X`. -/ def rieszContentAux : Compacts X → ℝ≥0 := fun K => sInf (Λ '' { f : C_c(X, ℝ≥0) | ∀ x ∈ K, (1 : ℝ≥0) ≤ f x }) section RieszMonotone variable [T2Space X] [LocallyCompactSpace X] /-- For any compact subset `K ⊆ X`, there exist some compactly supported continuous nonnegative functions `f` on `X` such that `f ≥ 1` on `K`. -/ theorem rieszContentAux_image_nonempty (K : Compacts X) : (Λ '' { f : C_c(X, ℝ≥0) | ∀ x ∈ K, (1 : ℝ≥0) ≤ f x }).Nonempty := by rw [image_nonempty] obtain ⟨V, hVcp, hKsubintV⟩ := exists_compact_superset K.2 have hIsCompact_closure_interior : IsCompact (closure (interior V)) := by apply IsCompact.of_isClosed_subset hVcp isClosed_closure nth_rw 2 [← closure_eq_iff_isClosed.mpr (IsCompact.isClosed hVcp)] exact closure_mono interior_subset obtain ⟨f, hsuppfsubV, hfeq1onK, hfinicc⟩ := exists_tsupport_one_of_isOpen_isClosed isOpen_interior hIsCompact_closure_interior (IsCompact.isClosed K.2) hKsubintV have hfHasCompactSupport : HasCompactSupport f := IsCompact.of_isClosed_subset hVcp (isClosed_tsupport f) (Set.Subset.trans hsuppfsubV interior_subset) use nnrealPart ⟨f, hfHasCompactSupport⟩ intro x hx apply le_of_eq simp only [nnrealPart_apply, CompactlySupportedContinuousMap.coe_mk] rw [← Real.toNNReal_one, Real.toNNReal_eq_toNNReal_iff (zero_le_one' ℝ) (hfinicc x).1] exact hfeq1onK.symm hx /-- Riesz content `λ` (associated with a positive linear functional `Λ`) is monotone: if `K₁ ⊆ K₂` are compact subsets in `X`, then `λ(K₁) ≤ λ(K₂)`. -/ theorem rieszContentAux_mono {K₁ K₂ : Compacts X} (h : K₁ ≤ K₂) : rieszContentAux Λ K₁ ≤ rieszContentAux Λ K₂ := by unfold rieszContentAux gcongr apply rieszContentAux_image_nonempty end RieszMonotone section RieszSubadditive /-- Any compactly supported continuous nonnegative `f` such that `f ≥ 1` on `K` gives an upper bound on the content of `K`; namely `λ(K) ≤ Λ f`. -/ theorem rieszContentAux_le {K : Compacts X} {f : C_c(X, ℝ≥0)} (h : ∀ x ∈ K, (1 : ℝ≥0) ≤ f x) : rieszContentAux Λ K ≤ Λ f := csInf_le (OrderBot.bddBelow _) ⟨f, ⟨h, rfl⟩⟩ variable [T2Space X] [LocallyCompactSpace X] /-- The Riesz content can be approximated arbitrarily well by evaluating the positive linear functional on test functions: for any `ε > 0`, there exists a compactly supported continuous nonnegative function `f` on `X` such that `f ≥ 1` on `K` and such that `λ(K) ≤ Λ f < λ(K) + ε`. -/ theorem exists_lt_rieszContentAux_add_pos (K : Compacts X) {ε : ℝ≥0} (εpos : 0 < ε) : ∃ f : C_c(X, ℝ≥0), (∀ x ∈ K, (1 : ℝ≥0) ≤ f x) ∧ Λ f < rieszContentAux Λ K + ε := by --choose a test function `f` s.t. `Λf = α < λ(K) + ε` obtain ⟨α, ⟨⟨f, f_hyp⟩, α_hyp⟩⟩ := exists_lt_of_csInf_lt (rieszContentAux_image_nonempty Λ K) (lt_add_of_pos_right (rieszContentAux Λ K) εpos) refine ⟨f, f_hyp.left, ?_⟩ rw [f_hyp.right] exact α_hyp /-- The Riesz content `λ` associated to a given positive linear functional `Λ` is finitely subadditive: `λ(K₁ ∪ K₂) ≤ λ(K₁) + λ(K₂)` for any compact subsets `K₁, K₂ ⊆ X`. -/ theorem rieszContentAux_sup_le (K1 K2 : Compacts X) : rieszContentAux Λ (K1 ⊔ K2) ≤ rieszContentAux Λ K1 + rieszContentAux Λ K2 := by apply _root_.le_of_forall_pos_le_add intro ε εpos --get test functions s.t. `λ(Ki) ≤ Λfi ≤ λ(Ki) + ε/2, i=1,2` obtain ⟨f1, f_test_function_K1⟩ := exists_lt_rieszContentAux_add_pos Λ K1 (half_pos εpos) obtain ⟨f2, f_test_function_K2⟩ := exists_lt_rieszContentAux_add_pos Λ K2 (half_pos εpos) --let `f := f1 + f2` test function for the content of `K` have f_test_function_union : ∀ x ∈ K1 ⊔ K2, (1 : ℝ≥0) ≤ (f1 + f2) x := by rintro x (x_in_K1 | x_in_K2) · exact le_add_right (f_test_function_K1.left x x_in_K1) · exact le_add_left (f_test_function_K2.left x x_in_K2) --use that `Λf` is an upper bound for `λ(K1⊔K2)` apply (rieszContentAux_le Λ f_test_function_union).trans (le_of_lt _) rw [map_add] --use that `Λfi` are lower bounds for `λ(Ki) + ε/2` apply lt_of_lt_of_le (_root_.add_lt_add f_test_function_K1.right f_test_function_K2.right) (le_of_eq _) rw [add_assoc, add_comm (ε / 2), add_assoc, add_halves ε, add_assoc] end RieszSubadditive section PartitionOfUnity variable [T2Space X] [LocallyCompactSpace X] lemma exists_continuous_add_one_of_isCompact_nnreal {s₀ s₁ : Set X} {t : Set X} (s₀_compact : IsCompact s₀) (s₁_compact : IsCompact s₁) (t_compact : IsCompact t) (disj : Disjoint s₀ s₁) (hst : s₀ ∪ s₁ ⊆ t) : ∃ (f₀ f₁ : C_c(X, ℝ≥0)), EqOn f₀ 1 s₀ ∧ EqOn f₁ 1 s₁ ∧ EqOn (f₀ + f₁) 1 t := by set so : Fin 2 → Set X := fun j => if j = 0 then s₀ᶜ else s₁ᶜ with hso have soopen (j : Fin 2) : IsOpen (so j) := by fin_cases j · simp only [hso, Fin.zero_eta, Fin.isValue, ↓reduceIte, isOpen_compl_iff] exact IsCompact.isClosed <| s₀_compact · simp only [hso, Fin.isValue, Fin.mk_one, one_ne_zero, ↓reduceIte, isOpen_compl_iff] exact IsCompact.isClosed <| s₁_compact have hsot : t ⊆ ⋃ j, so j := by rw [hso] simp only [Fin.isValue] intro x hx rw [mem_iUnion] rw [← subset_compl_iff_disjoint_right, ← compl_compl s₀, compl_subset_iff_union] at disj have h : x ∈ s₀ᶜ ∨ x ∈ s₁ᶜ := by rw [← mem_union, disj] exact mem_univ _ apply Or.elim h · intro h0 use 0 simp only [Fin.isValue, ↓reduceIte] exact h0 · intro h1 use 1 simp only [Fin.isValue, one_ne_zero, ↓reduceIte] exact h1 obtain ⟨f, f_supp_in_so, sum_f_one_on_t, f_in_icc, f_hcs⟩ := exists_continuous_sum_one_of_isOpen_isCompact soopen t_compact hsot use (nnrealPart (⟨f 1, f_hcs 1⟩ : C_c(X, ℝ))), (nnrealPart (⟨f 0, f_hcs 0⟩ : C_c(X, ℝ))) simp only [Fin.isValue, CompactlySupportedContinuousMap.coe_add] have sum_one_x (x : X) (hx : x ∈ t) : (f 0) x + (f 1) x = 1 := by simpa only [Finset.sum_apply, Fin.sum_univ_two, Fin.isValue, Pi.one_apply] using sum_f_one_on_t hx refine ⟨?_, ?_, ?_⟩ · intro x hx simp only [Fin.isValue, nnrealPart_apply, CompactlySupportedContinuousMap.coe_mk, Pi.one_apply, Real.toNNReal_eq_one] have : (f 0) x = 0 := by rw [← notMem_support] have : s₀ ⊆ (tsupport (f 0))ᶜ := by apply subset_trans _ (compl_subset_compl.mpr (f_supp_in_so 0)) rw [hso] simp only [Fin.isValue, ↓reduceIte, compl_compl, subset_refl] apply notMem_of_mem_compl exact mem_of_subset_of_mem (subset_trans this (compl_subset_compl_of_subset subset_closure)) hx rw [union_subset_iff] at hst rw [← sum_one_x x (mem_of_subset_of_mem hst.1 hx), this] exact Eq.symm (AddZeroClass.zero_add ((f 1) x)) · intro x hx simp only [Fin.isValue, nnrealPart_apply, CompactlySupportedContinuousMap.coe_mk, Pi.one_apply, Real.toNNReal_eq_one] have : (f 1) x = 0 := by rw [← notMem_support] have : s₁ ⊆ (tsupport (f 1))ᶜ := by apply subset_trans _ (compl_subset_compl.mpr (f_supp_in_so 1)) rw [hso] simp only [Fin.isValue, one_ne_zero, ↓reduceIte, compl_compl, subset_refl] apply notMem_of_mem_compl exact mem_of_subset_of_mem (subset_trans this (compl_subset_compl_of_subset subset_closure)) hx rw [union_subset_iff] at hst rw [← sum_one_x x (mem_of_subset_of_mem hst.2 hx), this] exact Eq.symm (AddMonoid.add_zero ((f 0) x)) · intro x hx simp only [Fin.isValue, Pi.add_apply, nnrealPart_apply, CompactlySupportedContinuousMap.coe_mk, Pi.one_apply] rw [Real.toNNReal_add_toNNReal (f_in_icc 1 x).1 (f_in_icc 0 x).1, add_comm] simp only [Fin.isValue, Real.toNNReal_eq_one] exact sum_one_x x hx end PartitionOfUnity section RieszContentAdditive variable [T2Space X] [LocallyCompactSpace X] lemma rieszContentAux_union {K₁ K₂ : TopologicalSpace.Compacts X} (disj : Disjoint (K₁ : Set X) K₂) : rieszContentAux Λ (K₁ ⊔ K₂) = rieszContentAux Λ K₁ + rieszContentAux Λ K₂ := by refine le_antisymm (rieszContentAux_sup_le Λ K₁ K₂) ?_ refine le_csInf (rieszContentAux_image_nonempty Λ (K₁ ⊔ K₂)) ?_ intro b ⟨f, ⟨hf, Λf_eq_b⟩⟩ have hsuppf : ∀ x ∈ K₁ ⊔ K₂, x ∈ support f := by intro x hx rw [mem_support] exact ne_of_gt <| lt_of_lt_of_le (zero_lt_one' ℝ≥0) (hf x hx) have hsubsuppf : (K₁ : Set X) ∪ (K₂ : Set X) ⊆ tsupport f := subset_trans hsuppf subset_closure obtain ⟨g₁, g₂, hg₁, hg₂, sum_g⟩ := exists_continuous_add_one_of_isCompact_nnreal K₁.isCompact' K₂.isCompact' f.hasCompactSupport'.isCompact disj hsubsuppf have f_eq_sum : f = g₁ * f + g₂ * f := by ext x simp only [CompactlySupportedContinuousMap.coe_add, CompactlySupportedContinuousMap.coe_mul, Pi.mul_apply, NNReal.coe_mul, Eq.symm (RightDistribClass.right_distrib _ _ _)] by_cases h : f x = 0 · rw [h] simp only [NNReal.coe_zero, mul_zero] · push_neg at h simp only [CompactlySupportedContinuousMap.coe_add, ContinuousMap.toFun_eq_coe, CompactlySupportedContinuousMap.coe_toContinuousMap] at sum_g rw [sum_g (mem_of_subset_of_mem subset_closure (mem_support.mpr h))] simp only [Pi.one_apply, NNReal.coe_one, one_mul] rw [← Λf_eq_b, f_eq_sum, map_add] have aux₁ : ∀ x ∈ K₁, 1 ≤ (g₁ * f) x := by intro x x_in_K₁ simp [hg₁ x_in_K₁, hf x (mem_union_left _ x_in_K₁)] have aux₂ : ∀ x ∈ K₂, 1 ≤ (g₂ * f) x := by intro x x_in_K₂ simp [hg₂ x_in_K₂, hf x (mem_union_right _ x_in_K₂)] exact add_le_add (rieszContentAux_le Λ aux₁) (rieszContentAux_le Λ aux₂) end RieszContentAdditive section RieszContentRegular variable [T2Space X] [LocallyCompactSpace X] /-- The content induced by the linear functional `Λ`. -/ noncomputable def rieszContent (Λ : C_c(X, ℝ≥0) →ₗ[ℝ≥0] ℝ≥0) : Content X where toFun := rieszContentAux Λ mono' := fun _ _ ↦ rieszContentAux_mono Λ sup_disjoint' := fun _ _ disj _ _ ↦ rieszContentAux_union Λ disj sup_le' := rieszContentAux_sup_le Λ lemma rieszContent_ne_top {K : Compacts X} : rieszContent Λ K ≠ ⊤ := by simp [rieszContent, ne_eq, ENNReal.coe_ne_top, not_false_eq_true] lemma contentRegular_rieszContent : (rieszContent Λ).ContentRegular := by intro K simp only [rieszContent, le_antisymm_iff, le_iInf_iff, ENNReal.coe_le_coe, Content.mk_apply] refine ⟨fun K' hK' ↦ rieszContentAux_mono Λ (hK'.trans interior_subset), ?_⟩ rw [iInf_le_iff] intro b hb rw [rieszContentAux, ENNReal.le_coe_iff] have : b < ⊤ := by obtain ⟨F, hF⟩ := exists_compact_superset K.2 exact (le_iInf_iff.mp (hb ⟨F, hF.1⟩) hF.2).trans_lt ENNReal.coe_lt_top refine ⟨b.toNNReal, (ENNReal.coe_toNNReal this.ne).symm, NNReal.coe_le_coe.mp ?_⟩ apply le_iff_forall_pos_le_add.mpr intro ε hε lift ε to ℝ≥0 using hε.le obtain ⟨f, hfleoneonK, hfle⟩ := exists_lt_rieszContentAux_add_pos Λ K (Real.toNNReal_pos.mpr hε) rw [rieszContentAux, Real.toNNReal_of_nonneg hε.le, ← NNReal.coe_lt_coe] at hfle refine ((le_iff_forall_one_lt_le_mul₀ (zero_le (Λ f))).mpr fun α hα ↦ ?_).trans hfle.le rw [mul_comm, ← smul_eq_mul, ← map_smul] set K' := f ⁻¹' Ici α⁻¹ have hKK' : ↑K ⊆ interior K' := subset_interior_iff.2 ⟨f ⁻¹' Ioi α⁻¹, isOpen_Ioi.preimage f.1.2, fun x hx ↦ (inv_lt_one_of_one_lt₀ hα).trans_le (hfleoneonK x hx), preimage_mono Ioi_subset_Ici_self⟩ have hK'cp : IsCompact K' := .of_isClosed_subset f.2 (isClosed_Ici.preimage f.1.2) fun x hx ↦ subset_closure ((inv_pos_of_pos <| zero_lt_one.trans hα).trans_le hx).ne' set hb' := hb ⟨K', hK'cp⟩ simp only [Compacts.coe_mk, le_iInf_iff] at hb' exact (ENNReal.toNNReal_mono (by simp) <| hb' hKK').trans <| csInf_le' ⟨α • f, fun x ↦ (inv_le_iff_one_le_mul₀' (zero_lt_one.trans hα)).mp, by simp⟩ end RieszContentRegular namespace NNRealRMK variable [T2Space X] [LocallyCompactSpace X] [MeasurableSpace X] [BorelSpace X] /-- `rieszContent` gives a `Content` from `Λ : C_c(X, ℝ≥0) →ₗ[ℝ≥0] ℝ≥0`. Here `rieszContent Λ` is promoted to a measure. It will be later shown that `∫ (x : X), f x ∂(rieszMeasure Λ hΛ) = Λ f` for all `f : C_c(X, ℝ≥0)`. -/ def rieszMeasure := (rieszContent Λ).measure lemma le_rieszMeasure_of_isCompact_tsupport_subset {f : C_c(X, ℝ≥0)} (hf : ∀ x, f x ≤ 1) {K : Set X} (hK : IsCompact K) (h : tsupport f ⊆ K) : .ofNNReal (Λ f) ≤ rieszMeasure Λ K := by rw [← TopologicalSpace.Compacts.coe_mk K hK] simp only [rieszMeasure, Content.measure_eq_content_of_regular (rieszContent Λ) (contentRegular_rieszContent Λ)] simp only [rieszContent, ENNReal.coe_le_coe, Content.mk_apply] apply le_iff_forall_pos_le_add.mpr intro ε hε obtain ⟨g, hg⟩ := exists_lt_rieszContentAux_add_pos Λ ⟨K, hK⟩ hε apply le_trans _ hg.2.le apply monotone_of_nnreal Λ intro x simp only by_cases hx : x ∈ tsupport f · exact le_trans (hf x) (hg.1 x (Set.mem_of_subset_of_mem h hx)) · rw [image_eq_zero_of_notMem_tsupport hx] exact zero_le (g x) lemma le_rieszMeasure_of_tsupport_subset {f : C_c(X, ℝ≥0)} (hf : ∀ x, f x ≤ 1) {V : Set X} (h : tsupport f ⊆ V) : .ofNNReal (Λ f) ≤ rieszMeasure Λ V := by apply le_trans _ (measure_mono h) apply le_rieszMeasure_of_isCompact_tsupport_subset Λ hf f.hasCompactSupport exact subset_rfl end NNRealRMK
Imo1998Q2.lean
/- Copyright (c) 2020 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Field.Rat import Mathlib.Data.Finite.Prod import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.Tactic.NoncommRing import Mathlib.Tactic.Ring /-! # IMO 1998 Q2 In a competition, there are `a` contestants and `b` judges, where `b ≥ 3` is an odd integer. Each judge rates each contestant as either "pass" or "fail". Suppose `k` is a number such that, for any two judges, their ratings coincide for at most `k` contestants. Prove that `k / a ≥ (b - 1) / (2b)`. ## Solution The problem asks us to think about triples consisting of a contestant and two judges whose ratings agree for that contestant. We thus consider the subset `A ⊆ C × JJ` of all such incidences of agreement, where `C` and `J` are the sets of contestants and judges, and `JJ = J × J - {(j, j)}`. We have natural maps: `left : A → C` and `right: A → JJ`. We count the elements of `A` in two ways: as the sum of the cardinalities of the fibres of `left` and as the sum of the cardinalities of the fibres of `right`. We obtain an upper bound on the cardinality of `A` from the count for `right`, and a lower bound from the count for `left`. These two bounds combine to the required result. First consider the map `right : A → JJ`. Since the size of any fibre over a point in JJ is bounded by `k` and since `|JJ| = b^2 - b`, we obtain the upper bound: `|A| ≤ k(b^2-b)`. Now consider the map `left : A → C`. The fibre over a given contestant `c ∈ C` is the set of ordered pairs of (distinct) judges who agree about `c`. We seek to bound the cardinality of this fibre from below. Minimum agreement for a contestant occurs when the judges' ratings are split as evenly as possible. Since `b` is odd, this occurs when they are divided into groups of size `(b-1)/2` and `(b+1)/2`. This corresponds to a fibre of cardinality `(b-1)^2/2` and so we obtain the lower bound: `a(b-1)^2/2 ≤ |A|`. Rearranging gives the result. -/ variable {C J : Type*} (r : C → J → Prop) namespace Imo1998Q2 noncomputable section /-- An ordered pair of judges. -/ abbrev JudgePair (J : Type*) := J × J /-- A triple consisting of contestant together with an ordered pair of judges. -/ abbrev AgreedTriple (C J : Type*) := C × JudgePair J /-- The first judge from an ordered pair of judges. -/ abbrev JudgePair.judge₁ : JudgePair J → J := Prod.fst /-- The second judge from an ordered pair of judges. -/ abbrev JudgePair.judge₂ : JudgePair J → J := Prod.snd /-- The proposition that the judges in an ordered pair are distinct. -/ abbrev JudgePair.Distinct (p : JudgePair J) := p.judge₁ ≠ p.judge₂ /-- The proposition that the judges in an ordered pair agree about a contestant's rating. -/ abbrev JudgePair.Agree (p : JudgePair J) (c : C) := r c p.judge₁ ↔ r c p.judge₂ /-- The contestant from the triple consisting of a contestant and an ordered pair of judges. -/ abbrev AgreedTriple.contestant : AgreedTriple C J → C := Prod.fst /-- The ordered pair of judges from the triple consisting of a contestant and an ordered pair of judges. -/ abbrev AgreedTriple.judgePair : AgreedTriple C J → JudgePair J := Prod.snd @[simp] theorem JudgePair.agree_iff_same_rating (p : JudgePair J) (c : C) : p.Agree r c ↔ (r c p.judge₁ ↔ r c p.judge₂) := Iff.rfl open scoped Classical in /-- The set of contestants on which two judges agree. -/ def agreedContestants [Fintype C] (p : JudgePair J) : Finset C := Finset.univ.filter fun c => p.Agree r c section variable [Fintype J] [Fintype C] open scoped Classical in /-- All incidences of agreement. -/ def A : Finset (AgreedTriple C J) := Finset.univ.filter @fun (a : AgreedTriple C J) => (a.judgePair.Agree r a.contestant ∧ a.judgePair.Distinct) open scoped Classical in theorem A_maps_to_offDiag_judgePair (a : AgreedTriple C J) : a ∈ A r → a.judgePair ∈ Finset.offDiag (@Finset.univ J _) := by simp [A, Finset.mem_offDiag] open scoped Classical in theorem A_fibre_over_contestant (c : C) : (Finset.univ.filter fun p : JudgePair J => p.Agree r c ∧ p.Distinct) = ((A r).filter fun a : AgreedTriple C J => a.contestant = c).image Prod.snd := by ext p simp [A] open scoped Classical in theorem A_fibre_over_contestant_card (c : C) : (Finset.univ.filter fun p : JudgePair J => p.Agree r c ∧ p.Distinct).card = ((A r).filter fun a : AgreedTriple C J => a.contestant = c).card := by rw [A_fibre_over_contestant r] apply Finset.card_image_of_injOn unfold Set.InjOn rintro ⟨a, p⟩ h ⟨a', p'⟩ h' rfl aesop (add simp AgreedTriple.contestant) open scoped Classical in theorem A_fibre_over_judgePair {p : JudgePair J} (h : p.Distinct) : agreedContestants r p = ((A r).filter fun a : AgreedTriple C J => a.judgePair = p).image AgreedTriple.contestant := by dsimp only [A, agreedContestants]; ext c; constructor <;> intro h · rw [Finset.mem_image]; refine ⟨⟨c, p⟩, ?_⟩; aesop · aesop open scoped Classical in theorem A_fibre_over_judgePair_card {p : JudgePair J} (h : p.Distinct) : (agreedContestants r p).card = ((A r).filter fun a : AgreedTriple C J => a.judgePair = p).card := by rw [A_fibre_over_judgePair r h] apply Finset.card_image_of_injOn -- `aesop` sees through the abbrev `AgreedTriple C J = C × (J × J)`, but `simp` does not. -- Tell `simp` to unfold the abbreviations more aggressively, and it works. -- See also: https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/.60simp.60.20can't.20see.20through.20structure.20abbrevs.3F/with/534442087 aesop (add simp [Set.InjOn, AgreedTriple.contestant, AgreedTriple.judgePair]) theorem A_card_upper_bound {k : ℕ} (hk : ∀ p : JudgePair J, p.Distinct → (agreedContestants r p).card ≤ k) : (A r).card ≤ k * (Fintype.card J * Fintype.card J - Fintype.card J) := by change _ ≤ k * (Finset.card _ * Finset.card _ - Finset.card _) classical rw [← Finset.offDiag_card] apply Finset.card_le_mul_card_image_of_maps_to (A_maps_to_offDiag_judgePair r) intro p hp have hp' : p.Distinct := by grind rw [← A_fibre_over_judgePair_card r hp']; apply hk; exact hp' end theorem add_sq_add_sq_sub {α : Type*} [Ring α] (x y : α) : (x + y) * (x + y) + (x - y) * (x - y) = 2 * x * x + 2 * y * y := by noncomm_ring theorem norm_bound_of_odd_sum {x y z : ℤ} (h : x + y = 2 * z + 1) : 2 * z * z + 2 * z + 1 ≤ x * x + y * y := by suffices 4 * z * z + 4 * z + 1 + 1 ≤ 2 * x * x + 2 * y * y by rw [← mul_le_mul_left (zero_lt_two' ℤ)]; ring_nf at this ⊢; exact this have h' : (x + y) * (x + y) = 4 * z * z + 4 * z + 1 := by rw [h]; ring rw [← add_sq_add_sq_sub, h', add_le_add_iff_left] suffices 0 < (x - y) * (x - y) by apply Int.add_one_le_of_lt this rw [mul_self_pos, sub_ne_zero]; apply Int.ne_of_odd_add ⟨z, h⟩ section variable [Fintype J] open scoped Classical in theorem judge_pairs_card_lower_bound {z : ℕ} (hJ : Fintype.card J = 2 * z + 1) (c : C) : 2 * z * z + 2 * z + 1 ≤ (Finset.univ.filter fun p : JudgePair J => p.Agree r c).card := by let x := (Finset.univ.filter fun j => r c j).card let y := (Finset.univ.filter fun j => ¬r c j).card have h : (Finset.univ.filter fun p : JudgePair J => p.Agree r c).card = x * x + y * y := by simp [x, y, ← Finset.filter_product_card] rw [h]; apply Int.le_of_ofNat_le_ofNat; simp only [Int.natCast_add, Int.natCast_mul] apply norm_bound_of_odd_sum suffices x + y = 2 * z + 1 by simp [← Int.natCast_add, this] rw [Finset.filter_card_add_filter_neg_card_eq_card, ← hJ, Finset.card_univ] open scoped Classical in theorem distinct_judge_pairs_card_lower_bound {z : ℕ} (hJ : Fintype.card J = 2 * z + 1) (c : C) : 2 * z * z ≤ (Finset.univ.filter fun p : JudgePair J => p.Agree r c ∧ p.Distinct).card := by let s := Finset.univ.filter fun p : JudgePair J => p.Agree r c let t := Finset.univ.filter fun p : JudgePair J => p.Distinct have hs : 2 * z * z + 2 * z + 1 ≤ s.card := judge_pairs_card_lower_bound r hJ c have hst : s \ t = Finset.univ.diag := by ext p; constructor <;> intros hp · unfold s t at hp aesop · unfold s t suffices p.judge₁ = p.judge₂ by simp [this] aesop have hst' : (s \ t).card = 2 * z + 1 := by rw [hst, Finset.diag_card, ← hJ, Finset.card_univ] rw [Finset.filter_and, ← Finset.sdiff_sdiff_self_left s t, Finset.card_sdiff] · rw [hst']; rw [add_assoc] at hs; apply le_tsub_of_add_le_right hs · apply Finset.sdiff_subset theorem A_card_lower_bound [Fintype C] {z : ℕ} (hJ : Fintype.card J = 2 * z + 1) : 2 * z * z * Fintype.card C ≤ (A r).card := by classical have h : ∀ a, a ∈ A r → Prod.fst a ∈ @Finset.univ C _ := by intros; apply Finset.mem_univ apply Finset.mul_card_image_le_card_of_maps_to h intro c _ rw [← A_fibre_over_contestant_card] apply distinct_judge_pairs_card_lower_bound r hJ end theorem clear_denominators {a b k : ℕ} (ha : 0 < a) (hb : 0 < b) : (b - 1 : ℚ) / (2 * b) ≤ k / a ↔ ((b : ℕ) - 1) * a ≤ k * (2 * b) := by rw [div_le_div_iff₀] on_goal 1 => convert Nat.cast_le (α := ℚ) all_goals simp [ha, hb] end end Imo1998Q2 open Imo1998Q2 theorem imo1998_q2 [Fintype J] [Fintype C] (a b k : ℕ) (hC : Fintype.card C = a) (hJ : Fintype.card J = b) (ha : 0 < a) (hb : Odd b) (hk : ∀ p : JudgePair J, p.Distinct → (agreedContestants r p).card ≤ k) : (b - 1 : ℚ) / (2 * b) ≤ k / a := by rw [clear_denominators ha hb.pos] obtain ⟨z, hz⟩ := hb; rw [hz] at hJ; rw [hz] have h := le_trans (A_card_lower_bound r hJ) (A_card_upper_bound r hk) rw [hC, hJ] at h -- We are now essentially done; we just need to bash `h` into exactly the right shape. have hl : k * ((2 * z + 1) * (2 * z + 1) - (2 * z + 1)) = k * (2 * (2 * z + 1)) * z := by have : 0 < 2 * z + 1 := by aesop simp only [mul_comm, add_mul, one_mul, add_tsub_cancel_right]; ring have hr : 2 * z * z * a = 2 * z * a * z := by ring rw [hl, hr] at h rcases z with - | z · simp · exact le_of_mul_le_mul_right h z.succ_pos
ITauto.lean
/- Copyright (c) 2021 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Tactic.Exact import Batteries.Tactic.Init import Mathlib.Logic.Basic import Mathlib.Util.AtomM import Qq /-! # Intuitionistic tautology (`itauto`) decision procedure The `itauto` tactic will prove any intuitionistic tautology. It implements the well known `G4ip` algorithm: [Dyckhoff, *Contraction-free sequent calculi for intuitionistic logic*][dyckhoff_1992]. All built in propositional connectives are supported: `True`, `False`, `And`, `Or`, `→`, `Not`, `Iff`, `Xor'`, as well as `Eq` and `Ne` on propositions. Anything else, including definitions and predicate logical connectives (`∀` and `∃`), are not supported, and will have to be simplified or instantiated before calling this tactic. The resulting proofs will never use any axioms except possibly `propext`, and `propext` is only used if the input formula contains an equality of propositions `p = q`. Using `itauto!`, one can enable the selective use of LEM for case splitting on specified propositions. ## Implementation notes The core logic of the prover is in three functions: * `prove : Context → IProp → StateM Nat (Bool × Proof)`: The main entry point. Gets a context and a goal, and returns a `proof` object or fails, using `StateM Nat` for the name generator. * `search : Context → IProp → StateM Nat (Bool × Proof)`: Same meaning as `proof`, called during the search phase (see below). * `Context.add : IProp → Proof → Context → Except (IProp → Proof) Context`: Adds a proposition with its proof into the context, but it also does some simplifications on the spot while doing so. It will either return the new context, or if it happens to notice a proof of false, it will return a function to compute a proof of any proposition in the original context. The intuitionistic logic rules are separated into three groups: * level 1: No splitting, validity preserving: apply whenever you can. Left rules in `Context.add`, right rules in `prove`. * `Context.add`: * simplify `Γ, ⊤ ⊢ B` to `Γ ⊢ B` * `Γ, ⊥ ⊢ B` is true * simplify `Γ, A ∧ B ⊢ C` to `Γ, A, B ⊢ C` * simplify `Γ, ⊥ → A ⊢ B` to `Γ ⊢ B` * simplify `Γ, ⊤ → A ⊢ B` to `Γ, A ⊢ B` * simplify `Γ, A ∧ B → C ⊢ D` to `Γ, A → B → C ⊢ D` * simplify `Γ, A ∨ B → C ⊢ D` to `Γ, A → C, B → C ⊢ D` * `prove`: * `Γ ⊢ ⊤` is true * simplify `Γ ⊢ A → B` to `Γ, A ⊢ B` * `search`: * `Γ, P ⊢ P` is true * simplify `Γ, P, P → A ⊢ B` to `Γ, P, A ⊢ B` * level 2: Splitting rules, validity preserving: apply after level 1 rules. Done in `prove` * simplify `Γ ⊢ A ∧ B` to `Γ ⊢ A` and `Γ ⊢ B` * simplify `Γ, A ∨ B ⊢ C` to `Γ, A ⊢ C` and `Γ, B ⊢ C` * level 3: Splitting rules, not validity preserving: apply only if nothing else applies. Done in `search` * `Γ ⊢ A ∨ B` follows from `Γ ⊢ A` * `Γ ⊢ A ∨ B` follows from `Γ ⊢ B` * `Γ, (A₁ → A₂) → C ⊢ B` follows from `Γ, A₂ → C, A₁ ⊢ A₂` and `Γ, C ⊢ B` This covers the core algorithm, which only handles `True`, `False`, `And`, `Or`, and `→`. For `Iff` and `Eq`, we treat them essentially the same as `(p → q) ∧ (q → p)`, although we use a different `IProp` representation because we have to remember to apply different theorems during replay. For definitions like `Not` and `Xor'`, we just eagerly unfold them. (This could potentially cause a blowup issue for `Xor'`, but it isn't used very often anyway. We could add it to the `IProp` grammar if it matters.) ## Tags propositional logic, intuitionistic logic, decision procedure -/ open Std (TreeMap TreeSet) namespace Mathlib.Tactic.ITauto /-- Different propositional constructors that are variants of "and" for the purposes of the theorem prover. -/ inductive AndKind | and | iff | eq deriving Lean.ToExpr, DecidableEq instance : Inhabited AndKind := ⟨AndKind.and⟩ /-- A reified inductive type for propositional logic. -/ inductive IProp : Type | var : Nat → IProp -- propositional atoms P_i | true : IProp -- ⊤ | false : IProp -- ⊥ | and' : AndKind → IProp → IProp → IProp -- p ∧ q, p ↔ q, p = q | or : IProp → IProp → IProp -- p ∨ q | imp : IProp → IProp → IProp -- p → q deriving Lean.ToExpr, DecidableEq /-- Constructor for `p ∧ q`. -/ @[match_pattern] def IProp.and : IProp → IProp → IProp := .and' .and /-- Constructor for `p ↔ q`. -/ @[match_pattern] def IProp.iff : IProp → IProp → IProp := .and' .iff /-- Constructor for `p = q`. -/ @[match_pattern] def IProp.eq : IProp → IProp → IProp := .and' .eq /-- Constructor for `¬ p`. -/ @[match_pattern] def IProp.not (a : IProp) : IProp := a.imp .false /-- Constructor for `xor p q`. -/ @[match_pattern] def IProp.xor (a b : IProp) : IProp := (a.and b.not).or (b.and a.not) instance : Inhabited IProp := ⟨IProp.true⟩ /-- Given the contents of an `And` variant, return the two conjuncts. -/ def AndKind.sides : AndKind → IProp → IProp → IProp × IProp | .and, A, B => (A, B) | _, A, B => (A.imp B, B.imp A) /-- Debugging printer for propositions. -/ def IProp.format : IProp → Std.Format | .var i => f!"v{i}" | .true => f!"⊤" | .false => f!"⊥" | .and p q => f!"({p.format} ∧ {q.format})" | .iff p q => f!"({p.format} ↔ {q.format})" | .eq p q => f!"({p.format} = {q.format})" | .or p q => f!"({p.format} ∨ {q.format})" | .imp p q => f!"({p.format} → {q.format})" instance : Std.ToFormat IProp := ⟨IProp.format⟩ /-- A comparator for `AndKind`. (There should really be a derive handler for this.) -/ def AndKind.cmp (p q : AndKind) : Ordering := by cases p <;> cases q exacts [.eq, .lt, .lt, .gt, .eq, .lt, .gt, .gt, .eq] /-- A comparator for propositions. (There should really be a derive handler for this.) -/ def IProp.cmp (p q : IProp) : Ordering := by cases p <;> cases q case var.var p q => exact compare p q case true.true => exact .eq case false.false => exact .eq case and'.and' ap p₁ p₂ aq q₁ q₂ => exact (ap.cmp aq).then <| (p₁.cmp q₁).then (p₂.cmp q₂) case or.or p₁ p₂ q₁ q₂ => exact (p₁.cmp q₁).then (p₂.cmp q₂) case imp.imp p₁ p₂ q₁ q₂ => exact (p₁.cmp q₁).then (p₂.cmp q₂) exacts [.lt, .lt, .lt, .lt, .lt, .gt, .lt, .lt, .lt, .lt, .gt, .gt, .lt, .lt, .lt, .gt, .gt, .gt, .lt, .lt, .gt, .gt, .gt, .gt, .lt, .gt, .gt, .gt, .gt, .gt] instance : LT IProp := ⟨fun p q => p.cmp q = .lt⟩ instance : DecidableLT IProp := fun _ _ => inferInstanceAs (Decidable (_ = _)) open Lean (Name) /-- A reified inductive proof type for intuitionistic propositional logic. -/ inductive Proof /-- `⊢ A`, causes failure during reconstruction -/ | sorry : Proof /-- `(n: A) ⊢ A` -/ | hyp (n : Name) : Proof /-- `⊢ ⊤` -/ | triv : Proof /-- `(p: ⊥) ⊢ A` -/ | exfalso' (p : Proof) : Proof /-- `(p: (x: A) ⊢ B) ⊢ A → B` -/ | intro (x : Name) (p : Proof) : Proof /-- * `ak = .and`: `(p: A ∧ B) ⊢ A` * `ak = .iff`: `(p: A ↔ B) ⊢ A → B` * `ak = .eq`: `(p: A = B) ⊢ A → B` -/ | andLeft (ak : AndKind) (p : Proof) : Proof /-- * `ak = .and`: `(p: A ∧ B) ⊢ B` * `ak = .iff`: `(p: A ↔ B) ⊢ B → A` * `ak = .eq`: `(p: A = B) ⊢ B → A` -/ | andRight (ak : AndKind) (p : Proof) : Proof /-- * `ak = .and`: `(p₁: A) (p₂: B) ⊢ A ∧ B` * `ak = .iff`: `(p₁: A → B) (p₁: B → A) ⊢ A ↔ B` * `ak = .eq`: `(p₁: A → B) (p₁: B → A) ⊢ A = B` -/ | andIntro (ak : AndKind) (p₁ p₂ : Proof) : Proof /-- * `ak = .and`: `(p: A ∧ B → C) ⊢ A → B → C` * `ak = .iff`: `(p: (A ↔ B) → C) ⊢ (A → B) → (B → A) → C` * `ak = .eq`: `(p: (A = B) → C) ⊢ (A → B) → (B → A) → C` -/ | curry (ak : AndKind) (p : Proof) : Proof /-- This is a partial application of curry. * `ak = .and`: `(p: A ∧ B → C) (q : A) ⊢ B → C` * `ak = .iff`: `(p: (A ↔ B) → C) (q: A → B) ⊢ (B → A) → C` * `ak = .eq`: `(p: (A ↔ B) → C) (q: A → B) ⊢ (B → A) → C` -/ | curry₂ (ak : AndKind) (p q : Proof) : Proof /-- `(p: A → B) (q: A) ⊢ B` -/ | app' : Proof → Proof → Proof /-- `(p: A ∨ B → C) ⊢ A → C` -/ | orImpL (p : Proof) : Proof /-- `(p: A ∨ B → C) ⊢ B → C` -/ | orImpR (p : Proof) : Proof /-- `(p: A) ⊢ A ∨ B` -/ | orInL (p : Proof) : Proof /-- `(p: B) ⊢ A ∨ B` -/ | orInR (p : Proof) : Proof /-- `(p₁: A ∨ B) (p₂: (x: A) ⊢ C) (p₃: (x: B) ⊢ C) ⊢ C` -/ | orElim' (p₁ : Proof) (x : Name) (p₂ p₃ : Proof) : Proof /-- `(p₁: Decidable A) (p₂: (x: A) ⊢ C) (p₃: (x: ¬ A) ⊢ C) ⊢ C` -/ | decidableElim (classical : Bool) (p₁ x : Name) (p₂ p₃ : Proof) : Proof /-- * `classical = false`: `(p: Decidable A) ⊢ A ∨ ¬A` * `classical = true`: `(p: Prop) ⊢ p ∨ ¬p` -/ | em (classical : Bool) (p : Name) : Proof /-- The variable `x` here names the variable that will be used in the elaborated proof. * `(p: ((x:A) → B) → C) ⊢ B → C` -/ | impImpSimp (x : Name) (p : Proof) : Proof deriving Lean.ToExpr instance : Inhabited Proof := ⟨Proof.triv⟩ /-- Debugging printer for proof objects. -/ def Proof.format : Proof → Std.Format | .sorry => "sorry" | .hyp i => Std.format i | .triv => "triv" | .exfalso' p => f!"(exfalso {p.format})" | .intro x p => f!"(fun {x} ↦ {p.format})" | .andLeft _ p => f!"{p.format} .1" | .andRight _ p => f!"{p.format} .2" | .andIntro _ p q => f!"⟨{p.format}, {q.format}⟩" | .curry _ p => f!"(curry {p.format})" | .curry₂ _ p q => f!"(curry {p.format} {q.format})" | .app' p q => f!"({p.format} {q.format})" | .orImpL p => f!"(orImpL {p.format})" | .orImpR p => f!"(orImpR {p.format})" | .orInL p => f!"(Or.inl {p.format})" | .orInR p => f!"(Or.inr {p.format})" | .orElim' p x q r => f!"({p.format}.elim (fun {x} ↦ {q.format}) (fun {x} ↦ {r.format})" | .em false p => f!"(Decidable.em {p})" | .em true p => f!"(Classical.em {p})" | .decidableElim _ p x q r => f!"({p}.elim (fun {x} ↦ {q.format}) (fun {x} ↦ {r.format})" | .impImpSimp _ p => f!"(impImpSimp {p.format})" instance : Std.ToFormat Proof := ⟨Proof.format⟩ /-- A variant on `Proof.exfalso'` that performs opportunistic simplification. -/ def Proof.exfalso : IProp → Proof → Proof | .false, p => p | _, p => .exfalso' p /-- A variant on `Proof.orElim'` that performs opportunistic simplification. -/ def Proof.orElim : Proof → Name → Proof → Proof → Proof | .em cl p, x, q, r => .decidableElim cl p x q r | p, x, q, r => .orElim' p x q r /-- A variant on `Proof.app'` that performs opportunistic simplification. (This doesn't do full normalization because we don't want the proof size to blow up.) -/ def Proof.app : Proof → Proof → Proof | .curry ak p, q => .curry₂ ak p q | .curry₂ ak p q, r => p.app (q.andIntro ak r) | .orImpL p, q => p.app q.orInL | .orImpR p, q => p.app q.orInR | .impImpSimp x p, q => p.app (.intro x q) | p, q => p.app' q -- Note(Mario): the typechecker is disabled because it requires proofs to carry around additional -- props. These can be retrieved from the git history (rev 6c96d2ff7) if you want to re-enable this. /- /-- A typechecker for the `Proof` type. This is not used by the tactic but can be used for debugging. -/ def Proof.check : Lean.NameMap IProp → Proof → Option IProp | _, .sorry A => some A | Γ, .hyp i => Γ.find? i | _, triv => some .true | Γ, .exfalso' A p => guard (p.check Γ = some .false) *> pure A | Γ, .intro x A p => do let B ← p.check (Γ.insert x A); pure (.imp A B) | Γ, .andLeft ak p => do let .and' ak' A B ← p.check Γ | none guard (ak = ak') *> pure (ak.sides A B).1 | Γ, .andRight ak p => do let .and' ak' A B ← p.check Γ | none guard (ak = ak') *> pure (ak.sides A B).2 | Γ, .andIntro .and p q => do let A ← p.check Γ; let B ← q.check Γ pure (A.and B) | Γ, .andIntro ak p q => do let .imp A B ← p.check Γ | none let C ← q.check Γ; guard (C = .imp B A) *> pure (A.and' ak B) | Γ, .curry ak p => do let .imp (.and' ak' A B) C ← p.check Γ | none let (A', B') := ak.sides A B guard (ak = ak') *> pure (A'.imp $ B'.imp C) | Γ, .curry₂ ak p q => do let .imp (.and' ak' A B) C ← p.check Γ | none let A₂ ← q.check Γ let (A', B') := ak.sides A B guard (ak = ak' ∧ A₂ = A') *> pure (B'.imp C) | Γ, .app' p q => do let .imp A B ← p.check Γ | none let A' ← q.check Γ guard (A = A') *> pure B | Γ, .orImpL B p => do let .imp (.or A B') C ← p.check Γ | none guard (B = B') *> pure (A.imp C) | Γ, .orImpR A p => do let .imp (.or A' B) C ← p.check Γ | none guard (A = A') *> pure (B.imp C) | Γ, .orInL B p => do let A ← p.check Γ; pure (A.or B) | Γ, .orInR A p => do let B ← p.check Γ; pure (A.or B) | Γ, .orElim' p x q r => do let .or A B ← p.check Γ | none let C ← q.check (Γ.insert x A) let C' ← r.check (Γ.insert x B) guard (C = C') *> pure C | _, .em _ _ A => pure (A.or A.not) | Γ, .decidableElim _ A _ x p₂ p₃ => do let C ← p₂.check (Γ.insert x A) let C' ← p₃.check (Γ.insert x A.not) guard (C = C') *> pure C | Γ, .impImpSimp _ A p => do let .imp (.imp A' B) C ← p.check Γ | none guard (A = A') *> pure (B.imp C) -/ /-- Get a new name in the pattern `h0, h1, h2, ...` -/ @[inline] def freshName : StateM Nat Name := fun n => (Name.mkSimple s!"h{n}", n + 1) /-- The context during proof search is a map from propositions to proof values. -/ abbrev Context := TreeMap IProp Proof IProp.cmp /-- Debug printer for the context. -/ def Context.format (Γ : Context) : Std.Format := Γ.foldl (init := "") fun f P p => P.format ++ " := " ++ p.format ++ ",\n" ++ f instance : Std.ToFormat Context := ⟨Context.format⟩ /-- Insert a proposition and its proof into the context, as in `have : A := p`. This will eagerly apply all level 1 rules on the spot, which are rules that don't split the goal and are validity preserving: specifically, we drop `⊤` and `A → ⊤` hypotheses, close the goal if we find a `⊥` hypothesis, split all conjunctions, and also simplify `⊥ → A` (drop), `⊤ → A` (simplify to `A`), `A ∧ B → C` (curry to `A → B → C`) and `A ∨ B → C` (rewrite to `(A → C) ∧ (B → C)` and split). -/ partial def Context.add : IProp → Proof → Context → Except (IProp → Proof) Context | .true, _, Γ => pure Γ | .false, p, _ => throw fun A => .exfalso A p | .and' ak A B, p, Γ => do let (A, B) := ak.sides A B let Γ ← Γ.add A (p.andLeft ak) Γ.add B (p.andRight ak) | .imp .false _, _, Γ => pure Γ | .imp .true A, p, Γ => Γ.add A (p.app .triv) | .imp (.and' ak A B) C, p, Γ => let (A, B) := ak.sides A B Γ.add (A.imp (B.imp C)) (p.curry ak) | .imp (.or A B) C, p, Γ => do let Γ ← Γ.add (A.imp C) p.orImpL Γ.add (B.imp C) p.orImpR | .imp _ .true, _, Γ => pure Γ | A, p, Γ => pure (Γ.insert A p) /-- Add `A` to the context `Γ` with proof `p`. This version of `Context.add` takes a continuation and a target proposition `B`, so that in the case that `⊥` is found we can skip the continuation and just prove `B` outright. -/ @[inline] def Context.withAdd (Γ : Context) (A : IProp) (p : Proof) (B : IProp) (f : Context → IProp → StateM Nat (Bool × Proof)) : StateM Nat (Bool × Proof) := match Γ.add A p with | .ok Γ_A => f Γ_A B | .error p => pure (true, p B) /-- Map a function over the proof (regardless of whether the proof is successful or not). -/ def mapProof (f : Proof → Proof) : Bool × Proof → Bool × Proof | (b, p) => (b, f p) /-- Convert a value-with-success to an optional value. -/ def isOk : (Bool × Proof) × Nat → Option (Proof × Nat) | ((false, _), _) => none | ((true, p), n) => some (p, n) /-- Skip the continuation and return a failed proof if the boolean is false. -/ def whenOk : Bool → IProp → StateM Nat (Bool × Proof) → StateM Nat (Bool × Proof) | false, _, _ => pure (false, .sorry) | true, _, f => f mutual /-- The search phase, which deals with the level 3 rules, which are rules that are not validity preserving and so require proof search. One obvious one is the or-introduction rule: we prove `A ∨ B` by proving `A` or `B`, and we might have to try one and backtrack. There are two rules dealing with implication in this category: `p, p → C ⊢ B` where `p` is an atom (which is safe if we can find it but often requires the right search to expose the `p` assumption), and `(A₁ → A₂) → C ⊢ B`. We decompose the double implication into two subgoals: one to prove `A₁ → A₂`, which can be written `A₂ → C, A₁ ⊢ A₂` (where we used `A₁` to simplify `(A₁ → A₂) → C`), and one to use the consequent, `C ⊢ B`. The search here is that there are potentially many implications to split like this, and we have to try all of them if we want to be complete. -/ partial def search (Γ : Context) (B : IProp) : StateM Nat (Bool × Proof) := do if let some p := Γ[B]? then return (true, p) fun n => let search₁ := Γ.foldl (init := none) fun r A p => do if let some r := r then return r let .imp A' C := A | none if let some q := Γ[A']? then isOk <| Context.withAdd (Γ.erase A) C (p.app q) B prove n else let .imp A₁ A₂ := A' | none let Γ : Context := Γ.erase A let (a, n) := freshName n let (p₁, n) ← isOk <| Γ.withAdd A₁ (.hyp a) A₂ (fun Γ_A₁ A₂ => Γ_A₁.withAdd (IProp.imp A₂ C) (.impImpSimp a p) A₂ prove) n isOk <| Γ.withAdd C (p.app (.intro a p₁)) B prove n if let some (r, n) := search₁ then ((true, r), n) else if let .or B₁ B₂ := B then match (mapProof .orInL <$> prove Γ B₁) n with | ((false, _), _) => (mapProof .orInR <$> prove Γ B₂) n | r => r else ((false, .sorry), n) /-- The main prover. This receives a context of proven or assumed lemmas and a target proposition, and returns a proof or `none` (with state for the fresh variable generator). The intuitionistic logic rules are separated into three groups: * level 1: No splitting, validity preserving: apply whenever you can. Left rules in `Context.add`, right rules in `prove` * level 2: Splitting rules, validity preserving: apply after level 1 rules. Done in `prove` * level 3: Splitting rules, not validity preserving: apply only if nothing else applies. Done in `search` The level 1 rules on the right of the turnstile are `Γ ⊢ ⊤` and `Γ ⊢ A → B`, these are easy to handle. The rule `Γ ⊢ A ∧ B` is a level 2 rule, also handled here. If none of these apply, we try the level 2 rule `A ∨ B ⊢ C` by searching the context and splitting all ors we find. Finally, if we don't make any more progress, we go to the search phase. -/ partial def prove (Γ : Context) (B : IProp) : StateM Nat (Bool × Proof) := match B with | .true => pure (true, .triv) | .imp A B => do let a ← freshName mapProof (.intro a) <$> Γ.withAdd A (.hyp a) B prove | .and' ak A B => do let (A, B) := ak.sides A B let (ok, p) ← prove Γ A mapProof (p.andIntro ak) <$> whenOk ok B (prove Γ B) | B => Γ.foldl (init := fun found Γ => bif found then prove Γ B else search Γ B) (f := fun IH A p found Γ => do if let .or A₁ A₂ := A then let Γ : Context := Γ.erase A let a ← freshName let (ok, p₁) ← Γ.withAdd A₁ (.hyp a) B fun Γ _ => IH true Γ mapProof (.orElim p a p₁) <$> whenOk ok B (Γ.withAdd A₂ (.hyp a) B fun Γ _ => IH true Γ) else IH found Γ) (found := false) (Γ := Γ) end open Lean Qq Meta /-- Reify an `Expr` into a `IProp`, allocating anything non-propositional as an atom in the `AtomM` state. -/ partial def reify (e : Q(Prop)) : AtomM IProp := match e with | ~q(True) => return .true | ~q(False) => return .false | ~q(¬ $a) => return .not (← reify a) | ~q($a ∧ $b) => return .and (← reify a) (← reify b) | ~q($a ∨ $b) => return .or (← reify a) (← reify b) | ~q($a ↔ $b) => return .iff (← reify a) (← reify b) | ~q(Xor' $a $b) => return .xor (← reify a) (← reify b) | ~q(@Eq Prop $a $b) => return .eq (← reify a) (← reify b) | ~q(@Ne Prop $a $b) => return .not (.eq (← reify a) (← reify b)) | e => if e.isArrow then return .imp (← reify e.bindingDomain!) (← reify e.bindingBody!) else return .var (← AtomM.addAtom e).1 /-- Once we have a proof object, we have to apply it to the goal. -/ partial def applyProof (g : MVarId) (Γ : NameMap Expr) (p : Proof) : MetaM Unit := match p with | .sorry => throwError "itauto failed\n{g}" | .hyp n => do g.assignIfDefEq (← liftOption (Γ.find? n)) | .triv => g.assignIfDefEq q(trivial) | .exfalso' p => do let A ← mkFreshExprMVarQ q(Prop) let t ← mkFreshExprMVarQ q(False) g.assignIfDefEq q(@False.elim $A $t) applyProof t.mvarId! Γ p | .intro x p => do let (e, g) ← g.intro x; g.withContext do applyProof g (Γ.insert x (.fvar e)) p | .andLeft .and p => do let A ← mkFreshExprMVarQ q(Prop) let B ← mkFreshExprMVarQ q(Prop) let t ← mkFreshExprMVarQ q($A ∧ $B) g.assignIfDefEq q(And.left $t) applyProof t.mvarId! Γ p | .andLeft .iff p => do let A ← mkFreshExprMVarQ q(Prop) let B ← mkFreshExprMVarQ q(Prop) let t ← mkFreshExprMVarQ q($A ↔ $B) g.assignIfDefEq q(Iff.mp $t) applyProof t.mvarId! Γ p | .andLeft .eq p => do let A ← mkFreshExprMVarQ q(Prop) let B ← mkFreshExprMVarQ q(Prop) let t ← mkFreshExprMVarQ q($A = $B) g.assignIfDefEq q(cast $t) applyProof t.mvarId! Γ p | .andRight .and p => do let A ← mkFreshExprMVarQ q(Prop) let B ← mkFreshExprMVarQ q(Prop) let t ← mkFreshExprMVarQ q($A ∧ $B) g.assignIfDefEq q(And.right $t) applyProof t.mvarId! Γ p | .andRight .iff p => do let A ← mkFreshExprMVarQ q(Prop) let B ← mkFreshExprMVarQ q(Prop) let t ← mkFreshExprMVarQ q($A ↔ $B) g.assignIfDefEq q(Iff.mpr $t) applyProof t.mvarId! Γ p | .andRight .eq p => do let A ← mkFreshExprMVarQ q(Prop) let B ← mkFreshExprMVarQ q(Prop) let t ← mkFreshExprMVarQ q($A = $B) g.assignIfDefEq q(cast (Eq.symm $t)) applyProof t.mvarId! Γ p | .andIntro .and p q => do let A ← mkFreshExprMVarQ q(Prop) let B ← mkFreshExprMVarQ q(Prop) let t₁ ← mkFreshExprMVarQ q($A) let t₂ ← mkFreshExprMVarQ q($B) g.assignIfDefEq q(And.intro $t₁ $t₂) applyProof t₁.mvarId! Γ p applyProof t₂.mvarId! Γ q | .andIntro .iff p q => do let A ← mkFreshExprMVarQ q(Prop) let B ← mkFreshExprMVarQ q(Prop) let t₁ ← mkFreshExprMVarQ q($A → $B) let t₂ ← mkFreshExprMVarQ q($B → $A) g.assignIfDefEq q(Iff.intro $t₁ $t₂) applyProof t₁.mvarId! Γ p applyProof t₂.mvarId! Γ q | .andIntro .eq p q => do let A ← mkFreshExprMVarQ q(Prop) let B ← mkFreshExprMVarQ q(Prop) let t₁ ← mkFreshExprMVarQ q($A → $B) let t₂ ← mkFreshExprMVarQ q($B → $A) g.assignIfDefEq q(propext (Iff.intro $t₁ $t₂)) applyProof t₁.mvarId! Γ p applyProof t₂.mvarId! Γ q | .app' p q => do let A ← mkFreshExprMVarQ q(Prop) let B ← mkFreshExprMVarQ q(Prop) let t₁ ← mkFreshExprMVarQ q($A → $B) let t₂ ← mkFreshExprMVarQ q($A) g.assignIfDefEq q($t₁ $t₂) applyProof t₁.mvarId! Γ p applyProof t₂.mvarId! Γ q | .orInL p => do let A ← mkFreshExprMVarQ q(Prop) let B ← mkFreshExprMVarQ q(Prop) let t ← mkFreshExprMVarQ q($A) g.assignIfDefEq q(@Or.inl $A $B $t) applyProof t.mvarId! Γ p | .orInR p => do let A ← mkFreshExprMVarQ q(Prop) let B ← mkFreshExprMVarQ q(Prop) let t ← mkFreshExprMVarQ q($B) g.assignIfDefEq q(@Or.inr $A $B $t) applyProof t.mvarId! Γ p | .orElim' p x p₁ p₂ => do let A ← mkFreshExprMVarQ q(Prop) let B ← mkFreshExprMVarQ q(Prop) let C ← mkFreshExprMVarQ q(Prop) let t₁ ← mkFreshExprMVarQ q($A ∨ $B) let t₂ ← mkFreshExprMVarQ q($A → $C) let t₃ ← mkFreshExprMVarQ q($B → $C) g.assignIfDefEq q(Or.elim $t₁ $t₂ $t₃) applyProof t₁.mvarId! Γ p let (e, t₂) ← t₂.mvarId!.intro x; t₂.withContext do applyProof t₂ (Γ.insert x (.fvar e)) p₁ let (e, t₃) ← t₃.mvarId!.intro x; t₃.withContext do applyProof t₃ (Γ.insert x (.fvar e)) p₂ | .em false n => do let A ← mkFreshExprMVarQ q(Prop) let e : Q(Decidable $A) ← liftOption (Γ.find? n) let .true ← Meta.isDefEq (← Meta.inferType e) q(Decidable $A) | failure g.assignIfDefEq q(@Decidable.em $A $e) | .em true n => do let A : Q(Prop) ← liftOption (Γ.find? n) g.assignIfDefEq q(@Classical.em $A) | .decidableElim false n x p₁ p₂ => do let A ← mkFreshExprMVarQ q(Prop) let e : Q(Decidable $A) ← liftOption (Γ.find? n) let .true ← Meta.isDefEq (← Meta.inferType e) q(Decidable $A) | failure let B ← mkFreshExprMVarQ q(Prop) let t₁ ← mkFreshExprMVarQ q($A → $B) let t₂ ← mkFreshExprMVarQ q(¬$A → $B) g.assignIfDefEq q(@dite $B $A $e $t₁ $t₂) let (e, t₁) ← t₁.mvarId!.intro x; t₁.withContext do applyProof t₁ (Γ.insert x (.fvar e)) p₁ let (e, t₂) ← t₂.mvarId!.intro x; t₂.withContext do applyProof t₂ (Γ.insert x (.fvar e)) p₂ | .decidableElim true n x p₁ p₂ => do let A : Q(Prop) ← liftOption (Γ.find? n) let B ← mkFreshExprMVarQ q(Prop) let t₁ ← mkFreshExprMVarQ q($A → $B) let t₂ ← mkFreshExprMVarQ q(¬$A → $B) g.assignIfDefEq q(@Classical.byCases $A $B $t₁ $t₂) let (e, t₁) ← t₁.mvarId!.intro x; t₁.withContext do applyProof t₁ (Γ.insert x (.fvar e)) p₁ let (e, t₂) ← t₂.mvarId!.intro x; t₂.withContext do applyProof t₂ (Γ.insert x (.fvar e)) p₂ | .curry .. | .curry₂ .. | .orImpL .. | .orImpR .. | .impImpSimp .. => do let (e, g) ← g.intro1; g.withContext do applyProof g (Γ.insert e.name (.fvar e)) (p.app (.hyp e.name)) /-- A decision procedure for intuitionistic propositional logic. * `useDec` will add `a ∨ ¬ a` to the context for every decidable atomic proposition `a`. * `useClassical` will allow `a ∨ ¬ a` to be added even if the proposition is not decidable, using classical logic. * `extraDec` will add `a ∨ ¬ a` to the context for specified (not necessarily atomic) propositions `a`. -/ def itautoCore (g : MVarId) (useDec useClassical : Bool) (extraDec : Array Expr) : MetaM Unit := do AtomM.run (← getTransparency) do let mut hs := mkNameMap Expr let t ← g.getType let (g, t) ← if ← isProp t then pure (g, ← reify t) else pure (← g.exfalso, .false) let mut Γ : Except (IProp → Proof) ITauto.Context := .ok TreeMap.empty let mut decs := TreeMap.empty for ldecl in ← getLCtx do if !ldecl.isImplementationDetail then let e := ldecl.type if ← isProp e then let A ← reify e let n := ldecl.fvarId.name hs := hs.insert n (Expr.fvar ldecl.fvarId) Γ := do (← Γ).add A (.hyp n) else if let .const ``Decidable _ := e.getAppFn then let p : Q(Prop) := e.appArg! if useDec then let A ← reify p decs := decs.insert A (false, Expr.fvar ldecl.fvarId) let addDec (force : Bool) (decs : TreeMap IProp (Bool × Expr) IProp.cmp) (e : Q(Prop)) := do let A ← reify e let dec_e := q(Decidable $e) let res ← trySynthInstance q(Decidable $e) if !(res matches .some _) && !useClassical then if force then _ ← synthInstance dec_e pure decs else pure (decs.insert A (match res with | .some e => (false, e) | _ => (true, e))) decs ← extraDec.foldlM (addDec true) decs if useDec then let mut decided := TreeSet.empty (cmp := compare) if let .ok Γ' := Γ then decided := Γ'.foldl (init := decided) fun m p _ => match p with | .var i => m.insert i | .not (.var i) => m.insert i | _ => m let ats := (← get).atoms for e in ats, i in [0:ats.size] do if !decided.contains i then decs ← addDec false decs e for (A, cl, pf) in decs do let n ← mkFreshId hs := hs.insert n pf Γ := return (← Γ).insert (A.or A.not) (.em cl n) let p : Proof := match Γ with | .ok Γ => (prove Γ t 0).1.2 | .error p => p t applyProof g hs p open Elab Tactic /-- A decision procedure for intuitionistic propositional logic. Unlike `finish` and `tauto!` this tactic never uses the law of excluded middle (without the `!` option), and the proof search is tailored for this use case. (`itauto!` will work as a classical SAT solver, but the algorithm is not very good in this situation.) ```lean example (p : Prop) : ¬ (p ↔ ¬ p) := by itauto ``` `itauto [a, b]` will additionally attempt case analysis on `a` and `b` assuming that it can derive `Decidable a` and `Decidable b`. `itauto *` will case on all decidable propositions that it can find among the atomic propositions, and `itauto! *` will case on all propositional atoms. *Warning:* This can blow up the proof search, so it should be used sparingly. -/ syntax (name := itauto) "itauto" "!"? (" *" <|> (" [" term,* "]"))? : tactic elab_rules : tactic | `(tactic| itauto $[!%$cl]?) => liftMetaTactic (itautoCore · false cl.isSome #[] *> pure []) | `(tactic| itauto $[!%$cl]? *) => liftMetaTactic (itautoCore · true cl.isSome #[] *> pure []) | `(tactic| itauto $[!%$cl]? [$hs,*]) => withMainContext do let hs ← hs.getElems.mapM (Term.elabTermAndSynthesize · none) liftMetaTactic (itautoCore · true cl.isSome hs *> pure []) @[inherit_doc itauto] syntax (name := itauto!) "itauto!" (" *" <|> (" [" term,* "]"))? : tactic macro_rules | `(tactic| itauto!) => `(tactic| itauto !) | `(tactic| itauto! *) => `(tactic| itauto ! *) | `(tactic| itauto! [$hs,*]) => `(tactic| itauto ! [$hs,*]) -- add_hint_tactic itauto -- add_tactic_doc -- { Name := "itauto" -- category := DocCategory.tactic -- declNames := [`tactic.interactive.itauto] -- tags := ["logic", "propositional logic", "intuitionistic logic", "decision procedure"] } end Mathlib.Tactic.ITauto
LocallyFinite.lean
/- Copyright (c) 2024 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.BigOperators.Group.Finset.Sigma import Mathlib.Algebra.Order.Interval.Finset.SuccPred import Mathlib.Data.Nat.SuccPred import Mathlib.Order.Interval.Finset.Nat /-! # Big operators indexed by intervals This file proves lemmas about `∏ x ∈ Ixx a b, f x` and `∑ x ∈ Ixx a b, f x`. -/ open Order variable {α M : Type*} [CommMonoid M] {f : α → M} {a b : α} namespace Finset section PartialOrder variable [PartialOrder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[to_additive] lemma mul_prod_Ico_eq_prod_Icc (h : a ≤ b) : f b * ∏ x ∈ Ico a b, f x = ∏ x ∈ Icc a b, f x := by rw [Icc_eq_cons_Ico h, prod_cons] @[deprecated (since := "2025-05-03")] alias right_mul_prod_Ico := mul_prod_Ico_eq_prod_Icc @[deprecated (since := "2025-05-03")] alias right_add_sum_Ico := add_sum_Ico_eq_sum_Icc @[to_additive] lemma prod_Ico_mul_eq_prod_Icc (h : a ≤ b) : (∏ x ∈ Ico a b, f x) * f b = ∏ x ∈ Icc a b, f x := by rw [mul_comm, mul_prod_Ico_eq_prod_Icc h] @[deprecated (since := "2025-05-03")] alias prod_Ico_mul_right := prod_Ico_mul_eq_prod_Icc @[deprecated (since := "2025-05-03")] alias sum_Ico_add_right := sum_Ico_add_eq_sum_Icc @[to_additive] lemma mul_prod_Ioc_eq_prod_Icc (h : a ≤ b) : f a * ∏ x ∈ Ioc a b, f x = ∏ x ∈ Icc a b, f x := by rw [Icc_eq_cons_Ioc h, prod_cons] @[deprecated (since := "2025-05-03")] alias left_mul_prod_Ioc := mul_prod_Ioc_eq_prod_Icc @[deprecated (since := "2025-05-03")] alias left_add_sum_Ioc := add_sum_Ioc_eq_sum_Icc @[to_additive] lemma prod_Ioc_mul_eq_prod_Icc (h : a ≤ b) : (∏ x ∈ Ioc a b, f x) * f a = ∏ x ∈ Icc a b, f x := by rw [mul_comm, mul_prod_Ioc_eq_prod_Icc h] @[deprecated (since := "2025-05-03")] alias prod_Ioc_mul_left := prod_Ioc_mul_eq_prod_Icc @[deprecated (since := "2025-05-03")] alias sum_Ioc_add_left := sum_Ioc_add_eq_sum_Icc @[to_additive] lemma mul_prod_Ioo_eq_prod_Ico (h : a < b) : f a * ∏ x ∈ Ioo a b, f x = ∏ x ∈ Ico a b, f x := by rw [Ico_eq_cons_Ioo h, prod_cons] @[deprecated (since := "2025-05-03")] alias left_mul_prod_Ioo := mul_prod_Ioo_eq_prod_Ico @[deprecated (since := "2025-05-03")] alias left_add_sum_Ioo := add_sum_Ioo_eq_sum_Ico @[to_additive] lemma prod_Ioo_mul_eq_prod_Ico (h : a < b) : (∏ x ∈ Ioo a b, f x) * f a = ∏ x ∈ Ico a b, f x := by rw [mul_comm, mul_prod_Ioo_eq_prod_Ico h] @[deprecated (since := "2025-05-03")] alias prod_Ioo_mul_left := prod_Ioo_mul_eq_prod_Ico @[deprecated (since := "2025-05-03")] alias sum_Ioo_add_left := sum_Ioo_add_eq_sum_Ico @[to_additive] lemma mul_prod_Ioo_eq_prod_Ioc (h : a < b) : f b * ∏ x ∈ Ioo a b, f x = ∏ x ∈ Ioc a b, f x := by rw [Ioc_eq_cons_Ioo h, prod_cons] @[deprecated (since := "2025-05-03")] alias right_mul_prod_Ioo := mul_prod_Ioo_eq_prod_Ioc @[deprecated (since := "2025-05-03")] alias right_add_sum_Ioo := add_sum_Ioo_eq_sum_Ioc @[to_additive] lemma prod_Ioo_mul_eq_prod_Ioc (h : a < b) : (∏ x ∈ Ioo a b, f x) * f b = ∏ x ∈ Ioc a b, f x := by rw [mul_comm, mul_prod_Ioo_eq_prod_Ioc h] @[deprecated (since := "2025-05-03")] alias prod_Ioo_mul_right := prod_Ioo_mul_eq_prod_Ioc @[deprecated (since := "2025-05-03")] alias sum_Ioo_add_right := sum_Ioo_add_eq_sum_Ioc variable [AddMonoidWithOne α] [SuccAddOrder α] @[to_additive] theorem prod_eq_prod_Ico_succ_bot {a b : ℕ} (hab : a < b) (f : ℕ → M) : ∏ k ∈ Ico a b, f k = f a * ∏ k ∈ Ico (a + 1) b, f k := by have ha : a ∉ Ico (a + 1) b := by simp rw [← prod_insert ha, Finset.insert_Ico_add_one_left_eq_Ico hab] end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] @[to_additive] lemma mul_prod_Ioi_eq_prod_Ici (a : α) : f a * ∏ x ∈ Ioi a, f x = ∏ x ∈ Ici a, f x := by rw [Ici_eq_cons_Ioi, prod_cons] @[deprecated (since := "2025-05-03")] alias left_mul_prod_Ioi := mul_prod_Ioi_eq_prod_Ici @[deprecated (since := "2025-05-03")] alias left_add_sum_Ioi := add_sum_Ioi_eq_sum_Ici @[to_additive] lemma prod_Ioi_mul_eq_prod_Ici (a : α) : (∏ x ∈ Ioi a, f x) * f a = ∏ x ∈ Ici a, f x := by rw [mul_comm, mul_prod_Ioi_eq_prod_Ici] @[deprecated (since := "2025-05-03")] alias prod_Ioi_mul_left := prod_Ioi_mul_eq_prod_Ici @[deprecated (since := "2025-05-03")] alias sum_Ioi_add_left := sum_Ioi_add_eq_sum_Ici end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] @[to_additive] lemma mul_prod_Iio_eq_prod_Iic (a : α) : f a * ∏ x ∈ Iio a, f x = ∏ x ∈ Iic a, f x := by rw [Iic_eq_cons_Iio, prod_cons] @[deprecated (since := "2025-05-03")] alias right_mul_prod_Iio := mul_prod_Iio_eq_prod_Iic @[deprecated (since := "2025-05-03")] alias right_add_sum_Iio := add_sum_Iio_eq_sum_Iic @[to_additive] lemma prod_Iio_mul_eq_prod_Iic (a : α) : (∏ x ∈ Iio a, f x) * f a = ∏ x ∈ Iic a, f x := by rw [mul_comm, mul_prod_Iio_eq_prod_Iic] @[deprecated (since := "2025-05-03")] alias prod_Iio_mul_right := prod_Iio_mul_eq_prod_Iic @[deprecated (since := "2025-05-03")] alias sum_Iio_add_right := sum_Iio_add_eq_sum_Iic end LocallyFiniteOrderBot end PartialOrder section LinearOrder variable [LinearOrder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] [AddMonoidWithOne α] [SuccAddOrder α] [NoMaxOrder α] -- we can't use `to_additive`, because it tries to translate `1` into `0` lemma sum_Ico_add_eq_sum_Ico_add_one {M : Type*} [AddCommMonoid M] (hab : a ≤ b) (f : α → M) : ∑ x ∈ Ico a b, f x + f b = ∑ x ∈ Ico a (b + 1), f x := by rw [← Finset.insert_Ico_right_eq_Ico_add_one hab, sum_insert right_notMem_Ico, add_comm] lemma prod_Ico_mul_eq_prod_Ico_add_one (hab : a ≤ b) (f : α → M) : (∏ x ∈ Ico a b, f x) * f b = ∏ x ∈ Ico a (b + 1), f x := by rw [← Finset.insert_Ico_right_eq_Ico_add_one hab, prod_insert right_notMem_Ico, mul_comm] end LocallyFiniteOrder variable [Fintype α] [LocallyFiniteOrderTop α] [LocallyFiniteOrderBot α] @[to_additive] lemma prod_prod_Ioi_mul_eq_prod_prod_off_diag (f : α → α → M) : ∏ i, ∏ j ∈ Ioi i, f j i * f i j = ∏ i, ∏ j ∈ {i}ᶜ, f j i := by simp_rw [← Ioi_disjUnion_Iio, prod_disjUnion, prod_mul_distrib] congr 1 rw [prod_sigma', prod_sigma'] refine prod_nbij' (fun i ↦ ⟨i.2, i.1⟩) (fun i ↦ ⟨i.2, i.1⟩) ?_ ?_ ?_ ?_ ?_ <;> simp end LinearOrder end Finset
all_boot.v
Require Export ssreflect. Require Export ssrbool. Require Export ssrfun. Require Export eqtype. Require Export ssrnat. Require Export seq. Require Export choice. Require Export monoid. Require Export nmodule. Require Export path. Require Export div. Require Export fintype. Require Export fingraph. Require Export tuple. Require Export finfun. Require Export bigop. Require Export prime. Require Export finset. Require Export binomial. Require Export generic_quotient. Require Export ssrAC.
FirstMainTheorem.lean
/- Copyright (c) 2025 Stefan Kebekus. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Stefan Kebekus -/ import Mathlib.Analysis.Complex.ValueDistribution.CharacteristicFunction /-! # The First Main Theorem of Value Distribution Theory The First Main Theorem of Value Distribution Theory is a two-part statement, establishing invariance of the characteristic function `characteristic f ⊤` under modifications of `f`. - If `f` is meromorphic on the complex plane, then the characteristic functions for the value `⊤` of the function `f` and `f⁻¹` agree up to a constant, see Proposition 2.1 on p. 168 of [Lang, *Introduction to Complex Hyperbolic Spaces*][MR886677]. - If `f` is meromorphic on the complex plane, then the characteristic functions for the value `⊤` of the function `f` and `f - const` agree up to a constant, see Proposition 2.2 on p. 168 of [Lang, *Introduction to Complex Hyperbolic Spaces*][MR886677] See Section~VI.2 of [Lang, *Introduction to Complex Hyperbolic Spaces*][MR886677] or Section~1.1 of [Noguchi-Winkelmann, *Nevanlinna Theory in Several Complex Variables and Diophantine Approximation*][MR3156076] for a detailed discussion. ### TODO - Formalize the first part of the First Main Theorem, which is the more substantial part of the statement. -/ namespace ValueDistribution variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f : ℂ → E} {a₀ : E} open Asymptotics Filter Real /-! ## Second Part of the First Main Theorem -/ /-- Second part of the First Main Theorem of Value Distribution Theory, quantitative version: If `f` is meromorphic on the complex plane, then the characteristic functions (for value `⊤`) of `f` and `f - a₀` differ at most by `log⁺ ‖a₀‖ + log 2`. -/ theorem abs_characteristic_sub_characteristic_shift_le {r : ℝ} (h : MeromorphicOn f ⊤) : |characteristic f ⊤ r - characteristic (f · - a₀) ⊤ r| ≤ log⁺ ‖a₀‖ + log 2 := by have h₁f : CircleIntegrable (fun x ↦ log⁺ ‖f x‖) 0 r := circleIntegrable_posLog_norm_meromorphicOn (fun x a ↦ h x trivial) have h₂f : CircleIntegrable (fun x ↦ log⁺ ‖f x - a₀‖) 0 r := by apply circleIntegrable_posLog_norm_meromorphicOn apply MeromorphicOn.sub (fun x a => h x trivial) (MeromorphicOn.const a₀) rw [← Pi.sub_apply, characteristic_sub_characteristic_eq_proximity_sub_proximity h] simp only [proximity, reduceDIte, Pi.sub_apply, ← circleAverage_sub h₁f h₂f] apply le_trans abs_circleAverage_le_circleAverage_abs apply circleAverage_mono_on_of_le_circle · apply (h₁f.sub h₂f).abs · intro θ hθ simp only [Pi.abs_apply, Pi.sub_apply] by_cases h : 0 ≤ log⁺ ‖f θ‖ - log⁺ ‖f θ - a₀‖ · simpa [abs_of_nonneg h, sub_le_iff_le_add, add_comm (log⁺ ‖a₀‖ + log 2), ← add_assoc] using (posLog_norm_add_le (f θ - a₀) a₀) · simp [abs_of_nonpos (le_of_not_ge h), neg_sub, add_comm (log⁺ ‖a₀‖ + log 2), ← add_assoc] convert posLog_norm_add_le (-f θ) (a₀) using 2 · rw [← norm_neg] abel_nf · simp /-- Second part of the First Main Theorem of Value Distribution Theory, qualitative version: If `f` is meromorphic on the complex plane, then the characteristic functions for the value `⊤` of the function `f` and `f - a₀` agree asymptotically up to a bounded function. -/ theorem abs_characteristic_sub_characteristic_shift_eqO (h : MeromorphicOn f ⊤) : |characteristic f ⊤ - characteristic (f · - a₀) ⊤| =O[atTop] (1 : ℝ → ℝ) := by simp_rw [isBigO_iff', eventually_atTop] use log⁺ ‖a₀‖ + log 2, add_pos_of_nonneg_of_pos posLog_nonneg (log_pos one_lt_two), 0 simp [abs_characteristic_sub_characteristic_shift_le h] end ValueDistribution
Limits.lean
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.Condensed.Module /-! # Limits in categories of condensed objects This file adds some instances for limits in condensed sets and condensed modules. -/ universe u open CategoryTheory Limits instance : HasLimits CondensedSet.{u} := by change HasLimits (Sheaf _ _) infer_instance instance : HasLimitsOfSize.{u, u + 1} CondensedSet.{u} := hasLimitsOfSizeShrink.{u, u + 1, u + 1, u} _ variable (R : Type (u + 1)) [Ring R] instance : HasLimits (CondensedMod.{u} R) := inferInstanceAs (HasLimits (Sheaf _ _)) instance : HasColimits (CondensedMod.{u} R) := inferInstanceAs (HasColimits (Sheaf _ _)) instance : HasLimitsOfSize.{u, u + 1} (CondensedMod.{u} R) := hasLimitsOfSizeShrink.{u, u + 1, u + 1, u} _ instance {A J : Type*} [Category A] [Category J] [HasColimitsOfShape J A] [HasWeakSheafify (coherentTopology CompHaus.{u}) A] : HasColimitsOfShape J (Condensed.{u} A) := inferInstanceAs (HasColimitsOfShape J (Sheaf _ _)) instance {A J : Type*} [Category A] [Category J] [HasLimitsOfShape J A] : HasLimitsOfShape J (Condensed.{u} A) := inferInstanceAs (HasLimitsOfShape J (Sheaf _ _)) instance {A : Type*} [Category A] [HasFiniteLimits A] : HasFiniteLimits (Condensed.{u} A) := inferInstanceAs (HasFiniteLimits (Sheaf _ _)) instance {A : Type*} [Category A] [HasFiniteColimits A] [HasWeakSheafify (coherentTopology CompHaus.{u}) A] : HasFiniteColimits (Condensed.{u} A) := inferInstanceAs (HasFiniteColimits (Sheaf _ _))
ssrAC.v
From HB Require Import structures. From Corelib Require Import PosDef. (* use #[warning="-hiding-delimiting-key"] attribute once we require Coq 8.18 *) (* (the warning was completely removed in 9.0) *) Set Warnings "-hiding-delimiting-key". From mathcomp Require Import ssreflect ssrbool ssrfun ssrnat eqtype seq bigop. Set Warnings "hiding-delimiting-key". Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. (************************************************************************) (* Small Scale Rewriting using Associativity and Commutativity *) (* *) (* Rewriting with AC (not modulo AC), using a small scale command. *) (* Replaces opA, opC, opAC, opCA, ... and any combinations of them *) (* *) (* Usage : *) (* rewrite [pattern](AC patternshape reordering) *) (* rewrite [pattern](ACl reordering) *) (* rewrite [pattern](ACof reordering reordering) *) (* rewrite [pattern]op.[AC patternshape reordering] *) (* rewrite [pattern]op.[ACl reordering] *) (* rewrite [pattern]op.[ACof reordering reordering] *) (* *) (* - if op is specified, the rule is specialized to op *) (* otherwise, the head symbol is a generic comm_law *) (* and the rewrite might be less efficient *) (* NOTE because of a bug in Coq's notations coq/coq#8190 *) (* op must not contain any hole. *) (* *%R.[AC p s] currently does not work because of that *) (* (@GRing.mul R).[AC p s] must be used instead *) (* *) (* - pattern is optional, as usual, but must be used to select the *) (* appropriate operator in case of ambiguity such an operator must *) (* have a canonical Monoid.com_law structure *) (* (additions, multiplications, conjunction and disjunction do) *) (* *) (* - patternshape is expressed using the syntax *) (* p := n | p * p' *) (* where "*" is purely formal *) (* and n > 0 is the number of left associated symbols *) (* examples of pattern shapes: *) (* + 4 represents (n * m * p * q) *) (* + (1*2) represents (n * (m * p)) *) (* *) (* - reordering is expressed using the syntax *) (* s := n | s * s' *) (* where "*" is purely formal and n > 0 is the position in the LHS *) (* positions start at 1 ! *) (* *) (* If the ACl variant is used, the patternshape defaults to the *) (* pattern fully associated to the left i.e. n i.e (x * y * ...) *) (* *) (* Examples of reorderings: *) (* - ACl ((1*2)*3) is the identity (and will fail with error message) *) (* - opAC == op.[ACl (1*3)*2] == op.[AC 3 ((1*3)*2)] *) (* - opCA == op.[AC (2*1) (1*2*3)] *) (* - opACA == op.[AC (2*2) ((1*3)*(2*4))] *) (* - rewrite opAC -opA == rewrite op.[ACl 1*(3*2)] *) (* ... *) (************************************************************************) Declare Scope AC_scope. Delimit Scope AC_scope with AC. Reserved Notation "op .[ 'ACof' p s ]" (p at level 1, left associativity). Reserved Notation "op .[ 'AC' p s ]" (p at level 1, left associativity). Reserved Notation "op .[ 'ACl' s ]" (left associativity). Definition change_type ty ty' (x : ty) (strategy : ty = ty') : ty' := ecast ty ty strategy x. Notation simplrefl := (ltac: (simpl; reflexivity)) (only parsing). Notation cbvrefl := (ltac: (cbv; reflexivity)) (only parsing). Notation vmrefl := (ltac: (vm_compute; reflexivity)) (only parsing). (* From stdlib *) Module Pos. Import Pos. (** ** Conversion with a decimal representation for printing/parsing *) Local Notation ten := (xO (xI (xO xH))). Fixpoint of_uint_acc (d:Decimal.uint) (acc:positive) := match d with | Decimal.Nil => acc | Decimal.D0 l => of_uint_acc l (mul ten acc) | Decimal.D1 l => of_uint_acc l (add 1 (mul ten acc)) | Decimal.D2 l => of_uint_acc l (add 1~0 (mul ten acc)) | Decimal.D3 l => of_uint_acc l (add 1~1 (mul ten acc)) | Decimal.D4 l => of_uint_acc l (add 1~0~0 (mul ten acc)) | Decimal.D5 l => of_uint_acc l (add 1~0~1 (mul ten acc)) | Decimal.D6 l => of_uint_acc l (add 1~1~0 (mul ten acc)) | Decimal.D7 l => of_uint_acc l (add 1~1~1 (mul ten acc)) | Decimal.D8 l => of_uint_acc l (add 1~0~0~0 (mul ten acc)) | Decimal.D9 l => of_uint_acc l (add 1~0~0~1 (mul ten acc)) end. Fixpoint of_uint (d:Decimal.uint) : N := match d with | Decimal.Nil => N0 | Decimal.D0 l => of_uint l | Decimal.D1 l => Npos (of_uint_acc l 1) | Decimal.D2 l => Npos (of_uint_acc l 1~0) | Decimal.D3 l => Npos (of_uint_acc l 1~1) | Decimal.D4 l => Npos (of_uint_acc l 1~0~0) | Decimal.D5 l => Npos (of_uint_acc l 1~0~1) | Decimal.D6 l => Npos (of_uint_acc l 1~1~0) | Decimal.D7 l => Npos (of_uint_acc l 1~1~1) | Decimal.D8 l => Npos (of_uint_acc l 1~0~0~0) | Decimal.D9 l => Npos (of_uint_acc l 1~0~0~1) end. Local Notation sixteen := (xO (xO (xO (xO xH)))). Fixpoint of_hex_uint_acc (d:Hexadecimal.uint) (acc:positive) := match d with | Hexadecimal.Nil => acc | Hexadecimal.D0 l => of_hex_uint_acc l (mul sixteen acc) | Hexadecimal.D1 l => of_hex_uint_acc l (add 1 (mul sixteen acc)) | Hexadecimal.D2 l => of_hex_uint_acc l (add 1~0 (mul sixteen acc)) | Hexadecimal.D3 l => of_hex_uint_acc l (add 1~1 (mul sixteen acc)) | Hexadecimal.D4 l => of_hex_uint_acc l (add 1~0~0 (mul sixteen acc)) | Hexadecimal.D5 l => of_hex_uint_acc l (add 1~0~1 (mul sixteen acc)) | Hexadecimal.D6 l => of_hex_uint_acc l (add 1~1~0 (mul sixteen acc)) | Hexadecimal.D7 l => of_hex_uint_acc l (add 1~1~1 (mul sixteen acc)) | Hexadecimal.D8 l => of_hex_uint_acc l (add 1~0~0~0 (mul sixteen acc)) | Hexadecimal.D9 l => of_hex_uint_acc l (add 1~0~0~1 (mul sixteen acc)) | Hexadecimal.Da l => of_hex_uint_acc l (add 1~0~1~0 (mul sixteen acc)) | Hexadecimal.Db l => of_hex_uint_acc l (add 1~0~1~1 (mul sixteen acc)) | Hexadecimal.Dc l => of_hex_uint_acc l (add 1~1~0~0 (mul sixteen acc)) | Hexadecimal.Dd l => of_hex_uint_acc l (add 1~1~0~1 (mul sixteen acc)) | Hexadecimal.De l => of_hex_uint_acc l (add 1~1~1~0 (mul sixteen acc)) | Hexadecimal.Df l => of_hex_uint_acc l (add 1~1~1~1 (mul sixteen acc)) end. Fixpoint of_hex_uint (d:Hexadecimal.uint) : N := match d with | Hexadecimal.Nil => N0 | Hexadecimal.D0 l => of_hex_uint l | Hexadecimal.D1 l => Npos (of_hex_uint_acc l 1) | Hexadecimal.D2 l => Npos (of_hex_uint_acc l 1~0) | Hexadecimal.D3 l => Npos (of_hex_uint_acc l 1~1) | Hexadecimal.D4 l => Npos (of_hex_uint_acc l 1~0~0) | Hexadecimal.D5 l => Npos (of_hex_uint_acc l 1~0~1) | Hexadecimal.D6 l => Npos (of_hex_uint_acc l 1~1~0) | Hexadecimal.D7 l => Npos (of_hex_uint_acc l 1~1~1) | Hexadecimal.D8 l => Npos (of_hex_uint_acc l 1~0~0~0) | Hexadecimal.D9 l => Npos (of_hex_uint_acc l 1~0~0~1) | Hexadecimal.Da l => Npos (of_hex_uint_acc l 1~0~1~0) | Hexadecimal.Db l => Npos (of_hex_uint_acc l 1~0~1~1) | Hexadecimal.Dc l => Npos (of_hex_uint_acc l 1~1~0~0) | Hexadecimal.Dd l => Npos (of_hex_uint_acc l 1~1~0~1) | Hexadecimal.De l => Npos (of_hex_uint_acc l 1~1~1~0) | Hexadecimal.Df l => Npos (of_hex_uint_acc l 1~1~1~1) end. Definition of_int (d:Decimal.int) : option positive := match d with | Decimal.Pos d => match of_uint d with | N0 => None | Npos p => Some p end | Decimal.Neg _ => None end. Definition of_hex_int (d:Hexadecimal.int) : option positive := match d with | Hexadecimal.Pos d => match of_hex_uint d with | N0 => None | Npos p => Some p end | Hexadecimal.Neg _ => None end. Definition of_num_int (d:Number.int) : option positive := match d with | Number.IntDecimal d => of_int d | Number.IntHexadecimal d => of_hex_int d end. Fixpoint to_little_uint p := match p with | xH => Decimal.D1 Decimal.Nil | xI p => Decimal.Little.succ_double (to_little_uint p) | xO p => Decimal.Little.double (to_little_uint p) end. Definition to_uint p := Decimal.rev (to_little_uint p). Definition to_num_uint p := Number.UIntDecimal (to_uint p). (** ** Successor *) Definition Nsucc n := match n with | N0 => Npos xH | Npos p => Npos (Pos.succ p) end. Lemma nat_of_succ_bin b : nat_of_bin (Nsucc b) = 1 + nat_of_bin b :> nat. Proof. by case: b => [//|p /=]; rewrite nat_of_succ_pos. Qed. Theorem eqb_eq p q : Pos.eqb p q = true <-> p=q. Proof. by elim: p q => [p IHp|p IHp|] [q|q|] //=; split=> [/IHp->//|]; case=> /IHp. Qed. End Pos. Module AC. HB.instance Definition _ := hasDecEq.Build positive (fun _ _ => equivP idP (Pos.eqb_eq _ _)). Inductive syntax := Leaf of positive | Op of syntax & syntax. Coercion serial := (fix loop (acc : seq positive) (s : syntax) := match s with | Leaf n => n :: acc | Op s s' => (loop^~ s (loop^~ s' acc)) end) [::]. Lemma serial_Op s1 s2 : Op s1 s2 = s1 ++ s2 :> seq _. Proof. rewrite /serial; set loop := (X in X [::]); rewrite -/loop. elim: s1 (loop [::] s2) => [n|s11 IHs1 s12 IHs2] //= l. by rewrite IHs1 [in RHS]IHs1 IHs2 catA. Qed. Definition Leaf_of_nat n := Leaf (Pos.sub (pos_of_nat n n) xH). Module Import Syntax. Bind Scope AC_scope with syntax. Number Notation positive Pos.of_num_int Pos.to_num_uint : AC_scope. Coercion Leaf : positive >-> syntax. Coercion Leaf_of_nat : nat >-> syntax. Notation "x * y" := (Op x%AC y%AC) : AC_scope. End Syntax. Definition pattern (s : syntax) := ((fix loop n s := match s with | Leaf 1%positive => (Leaf n, Pos.succ n) | Leaf m => Pos.iter (fun oi => (Op oi.1 (Leaf oi.2), Pos.succ oi.2)) (Leaf n, Pos.succ n) (Pos.sub m xH) | Op s s' => let: (p, n') := loop n s in let: (p', n'') := loop n' s' in (Op p p', n'') end) 1%positive s).1. Section eval. Variables (T : Type) (idx : T) (op : T -> T -> T). Inductive env := Empty | ENode of T & env & env. Definition pos := fix loop (e : env) p {struct e} := match e, p with | ENode t _ _, 1%positive => t | ENode t e _, (p~0)%positive => loop e p | ENode t _ e, (p~1)%positive => loop e p | _, _ => idx end. Definition set_pos (f : T -> T) := fix loop e p {struct p} := match e, p with | ENode t e e', 1%positive => ENode (f t) e e' | ENode t e e', (p~0)%positive => ENode t (loop e p) e' | ENode t e e', (p~1)%positive => ENode t e (loop e' p) | Empty, 1%positive => ENode (f idx) Empty Empty | Empty, (p~0)%positive => ENode idx (loop Empty p) Empty | Empty, (p~1)%positive => ENode idx Empty (loop Empty p) end. Lemma pos_set_pos (f : T -> T) e (p p' : positive) : pos (set_pos f e p) p' = if p == p' then f (pos e p) else pos e p'. Proof. by elim: p e p' => [p IHp|p IHp|] [|???] [?|?|]//=; rewrite IHp. Qed. Fixpoint unzip z (e : env) : env := match z with | [::] => e | (x, inl e') :: z' => unzip z' (ENode x e' e) | (x, inr e') :: z' => unzip z' (ENode x e e') end. Definition set_pos_trec (f : T -> T) := fix loop z e p {struct p} := match e, p with | ENode t e e', 1%positive => unzip z (ENode (f t) e e') | ENode t e e', (p~0)%positive => loop ((t, inr e') :: z) e p | ENode t e e', (p~1)%positive => loop ((t, inl e) :: z) e' p | Empty, 1%positive => unzip z (ENode (f idx) Empty Empty) | Empty, (p~0)%positive => loop ((idx, (inr Empty)) :: z) Empty p | Empty, (p~1)%positive => loop ((idx, (inl Empty)) :: z) Empty p end. Lemma set_pos_trecE f z e p : set_pos_trec f z e p = unzip z (set_pos f e p). Proof. by elim: p e z => [p IHp|p IHp|] [|???] [|[??]?] //=; rewrite ?IHp. Qed. Definition eval (e : env) := fix loop (s : syntax) := match s with | Leaf n => pos e n | Op s s' => op (loop s) (loop s') end. End eval. Arguments Empty {T}. Definition content := (fix loop (acc : env N) s := match s with | Leaf n => set_pos_trec N0 Pos.Nsucc [::] acc n | Op s s' => loop (loop acc s') s end) Empty. Lemma count_memE x (t : syntax) : count_mem x t = nat_of_bin (pos N0 (content t) x). Proof. rewrite /content; set loop := (X in X Empty); rewrite -/loop. rewrite -[LHS]addn0. have <- : nat_of_bin (pos N0 Empty x) = 0 :> nat by elim: x. elim: t Empty => [n|s IHs s' IHs'] e //=; last first. by rewrite serial_Op count_cat -addnA IHs' IHs. rewrite ?addn0 set_pos_trecE pos_set_pos; case: (altP eqP) => [->|] //=. by rewrite Pos.nat_of_succ_bin. Qed. Definition cforall N T : env N -> (env T -> Type) -> Type := env_rect (@^~ Empty) (fun _ e IHe e' IHe' R => forall x, IHe (fun xe => IHe' (R \o ENode x xe))). Lemma cforallP N T R : (forall e : env T, R e) -> forall (e : env N), cforall e R. Proof. move=> Re e; elim: e R Re => [|? e /= IHe e' IHe' ?? x] //=. by apply: IHe => ?; apply: IHe' => /=. Qed. Section eq_eval. Variables (T : Type) (idx : T) (op : Monoid.com_law idx). Lemma proof (p s : syntax) : content p = content s -> forall env, eval idx op env p = eval idx op env s. Proof. suff evalE env t : eval idx op env t = \big[op/idx]_(i <- t) (pos idx env i). move=> cps e; rewrite !evalE; apply: perm_big. by apply/allP => x _ /=; rewrite !count_memE cps. elim: t => //= [n|t -> t' ->]; last by rewrite serial_Op big_cat. by rewrite big_cons big_nil Monoid.mulm1. Qed. Definition direct p s ps := cforallP (@proof p s ps) (content p). End eq_eval. Module Exports. Export AC.Syntax. End Exports. End AC. Export AC.Exports. Notation AC_check_pattern := (ltac: (match goal with |- AC.content ?pat = AC.content ?ord => let pat' := fresh "pat" in let pat' := eval compute in pat in tryif unify pat' ord then fail 1 "AC: equality between" pat "and" ord "is trivial, cannot progress" else tryif vm_compute; reflexivity then idtac else fail 2 "AC: mismatch between shape" pat "=" pat' "and reordering" ord | |- ?G => fail 3 "AC: no pattern to check" G end)) (only parsing). Notation opACof law p s := ((fun T idx op assoc lid rid comm => (change_type (@AC.direct T idx (Monoid.ComLaw.Pack (* FIXME: find a way to make this robust to hierarchy evolutions *) (Monoid.ComLaw.Class (SemiGroup.isLaw.Axioms_ op assoc) (Monoid.isMonoidLaw.Axioms_ idx op lid rid) (SemiGroup.isCommutativeLaw.Axioms_ op comm))) p%AC s%AC AC_check_pattern) cbvrefl)) _ _ law (Monoid.mulmA _) (Monoid.mul1m _) (Monoid.mulm1 _) (Monoid.mulmC _)) (only parsing). Notation opAC op p s := (opACof op (AC.pattern p%AC) s%AC) (only parsing). Notation opACl op s := (opAC op (AC.Leaf_of_nat (size (AC.serial s%AC))) s%AC) (only parsing). Notation "op .[ 'ACof' p s ]" := (opACof op p%AC s%AC) (only parsing). Notation "op .[ 'AC' p s ]" := (opAC op p%AC s%AC) (only parsing). Notation "op .[ 'ACl' s ]" := (opACl op s%AC) (only parsing). Notation AC_strategy := (ltac: (cbv -[Monoid.ComLaw.sort Monoid.Law.sort]; reflexivity)) (only parsing). Notation ACof p s := (change_type (@AC.direct _ _ _ p%AC s%AC AC_check_pattern) AC_strategy) (only parsing). Notation AC p s := (ACof (AC.pattern p%AC) s%AC) (only parsing). Notation ACl s := (AC (AC.Leaf_of_nat (size (AC.serial s%AC))) s%AC) (only parsing).
CommDiag.lean
import Mathlib.Tactic.Widget.CommDiag import ProofWidgets.Component.Panel.SelectionPanel import ProofWidgets.Component.Panel.GoalTypePanel /-! ## Example use of commutative diagram widgets -/ universe u namespace CategoryTheory open ProofWidgets /-- Local instance to make examples work. -/ local instance : Category (Type u) where Hom α β := α → β id _ := id comp f g := g ∘ f id_comp _ := rfl comp_id _ := rfl assoc _ _ _ := rfl example {f g : Nat ⟶ Bool}: f = g → (f ≫ 𝟙 Bool) = (g ≫ 𝟙 Bool) := by with_panel_widgets [GoalTypePanel] intro h exact h example {fButActuallyTheNameIsReallyLong g : Nat ⟶ Bool}: fButActuallyTheNameIsReallyLong = g → fButActuallyTheNameIsReallyLong = (g ≫ 𝟙 Bool) := by with_panel_widgets [GoalTypePanel] intro h conv => rhs enter [1] rw [← h] rfl -- from Sina Hazratpour example {X Y Z : Type} {f g : X ⟶ Y} {k : Y ⟶ Y} {f' : Y ⟶ Z} {i : X ⟶ Z} (h' : g ≫ f' = i) : (f ≫ k) = g → ((f ≫ k) ≫ f') = (g ≫ 𝟙 Y ≫ f') := by with_panel_widgets [GoalTypePanel] intro h rw [ h, ← Category.assoc g (𝟙 Y) f', h', Category.comp_id g, h' ] example {X Y Z : Type} {f i : X ⟶ Y} {g j : Y ⟶ Z} {h : X ⟶ Z} : h = f ≫ g → i ≫ j = h → f ≫ g = i ≫ j := by with_panel_widgets [SelectionPanel] intro h₁ h₂ rw [← h₁, h₂] end CategoryTheory
all_ssreflect.v
Attributes deprecated(since="mathcomp 2.5.0", note="Use 'all_boot' and/or 'all_order' instead."). From mathcomp Require Export all_boot. From mathcomp Require Export preorder. From mathcomp Require Export order.
TransImports.lean
/- Copyright (c) 2024 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Init /-! # The `#trans_imports` command `#trans_imports` reports how many transitive imports the current module has. The command takes an optional string input: `#trans_imports str` also shows the transitively imported modules whose name begins with `str`. -/ /-- `#trans_imports` reports how many transitive imports the current module has. The command takes an optional string input: `#trans_imports str` also shows the transitively imported modules whose name begins with `str`. Mostly for the sake of tests, the command also takes an optional `at_most x` input: if the number of imports does not exceed `x`, then the message involves `x`, rather than the actual, possibly varying, number of imports. -/ syntax (name := transImportsStx) "#trans_imports" (ppSpace str)? (&" at_most " num)? : command open Lean in @[inherit_doc transImportsStx] elab_rules : command | `(command| #trans_imports $(stx)? $[at_most $le:num]?) => do let imports := (← getEnv).allImportedModuleNames let currMod := if let mod@(.str _ _) := ← getMainModule then m!"'{mod}' has " else "" let rest := match stx with | none => m!"" | some str => let imps := imports.filterMap fun (i : Name) => if i.toString.startsWith str.getString then some i else none m!"\n\n{imps.size} starting with {str}:\n{imps.qsort (·.toString < ·.toString)}" match le with | none => logInfo m!"{currMod}{imports.size} transitive imports{rest}" | some bd => if imports.size ≤ bd.getNat then logInfo m!"{currMod}at most {bd} transitive imports{rest}" else logWarningAt bd m!"{currMod}{imports.size} transitive imports, exceeding the expected bound of {bd}{rest}"
Topology.lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Analysis.Filter import Mathlib.Topology.Bases import Mathlib.Topology.LocallyFinite /-! # Computational realization of topological spaces (experimental) This file provides infrastructure to compute with topological spaces. ## Main declarations * `Ctop`: Realization of a topology basis. * `Ctop.Realizer`: Realization of a topological space. `Ctop` that generates the given topology. * `LocallyFinite.Realizer`: Realization of the local finiteness of an indexed family of sets. * `Compact.Realizer`: Realization of the compactness of a set. -/ open Set open Filter hiding Realizer open Topology /-- A `Ctop α σ` is a realization of a topology (basis) on `α`, represented by a type `σ` together with operations for the top element and the intersection operation. -/ structure Ctop (α σ : Type*) where f : σ → Set α top : α → σ top_mem : ∀ x : α, x ∈ f (top x) inter : ∀ (a b) (x : α), x ∈ f a ∩ f b → σ inter_mem : ∀ a b x h, x ∈ f (inter a b x h) inter_sub : ∀ a b x h, f (inter a b x h) ⊆ f a ∩ f b variable {α : Type*} {β : Type*} {σ : Type*} {τ : Type*} instance : Inhabited (Ctop α (Set α)) := ⟨{ f := id top := singleton top_mem := mem_singleton inter := fun s t _ _ ↦ s ∩ t inter_mem := fun _s _t _a ↦ id inter_sub := fun _s _t _a _ha ↦ Subset.rfl }⟩ namespace Ctop section variable (F : Ctop α σ) instance : CoeFun (Ctop α σ) fun _ ↦ σ → Set α := ⟨Ctop.f⟩ theorem coe_mk (f T h₁ I h₂ h₃ a) : (@Ctop.mk α σ f T h₁ I h₂ h₃) a = f a := rfl /-- Map a Ctop to an equivalent representation type. -/ def ofEquiv (E : σ ≃ τ) : Ctop α σ → Ctop α τ | ⟨f, T, h₁, I, h₂, h₃⟩ => { f := fun a ↦ f (E.symm a) top := fun x ↦ E (T x) top_mem := fun x ↦ by simpa using h₁ x inter := fun a b x h ↦ E (I (E.symm a) (E.symm b) x h) inter_mem := fun a b x h ↦ by simpa using h₂ (E.symm a) (E.symm b) x h inter_sub := fun a b x h ↦ by simpa using h₃ (E.symm a) (E.symm b) x h } @[simp] theorem ofEquiv_val (E : σ ≃ τ) (F : Ctop α σ) (a : τ) : F.ofEquiv E a = F (E.symm a) := by cases F; rfl end /-- Every `Ctop` is a topological space. -/ def toTopsp (F : Ctop α σ) : TopologicalSpace α := TopologicalSpace.generateFrom (Set.range F.f) theorem toTopsp_isTopologicalBasis (F : Ctop α σ) : @TopologicalSpace.IsTopologicalBasis _ F.toTopsp (Set.range F.f) := letI := F.toTopsp ⟨fun _u ⟨a, e₁⟩ _v ⟨b, e₂⟩ ↦ e₁ ▸ e₂ ▸ fun x h ↦ ⟨_, ⟨_, rfl⟩, F.inter_mem a b x h, F.inter_sub a b x h⟩, eq_univ_iff_forall.2 fun x ↦ ⟨_, ⟨_, rfl⟩, F.top_mem x⟩, rfl⟩ @[simp] theorem mem_nhds_toTopsp (F : Ctop α σ) {s : Set α} {a : α} : s ∈ @nhds _ F.toTopsp a ↔ ∃ b, a ∈ F b ∧ F b ⊆ s := (@TopologicalSpace.IsTopologicalBasis.mem_nhds_iff _ F.toTopsp _ _ _ F.toTopsp_isTopologicalBasis).trans <| ⟨fun ⟨_, ⟨x, rfl⟩, h⟩ ↦ ⟨x, h⟩, fun ⟨x, h⟩ ↦ ⟨_, ⟨x, rfl⟩, h⟩⟩ end Ctop /-- A `Ctop` realizer for the topological space `T` is a `Ctop` which generates `T`. -/ structure Ctop.Realizer (α) [T : TopologicalSpace α] where σ : Type* F : Ctop α σ eq : F.toTopsp = T open Ctop /-- A `Ctop` realizes the topological space it generates. -/ protected def Ctop.toRealizer (F : Ctop α σ) : @Ctop.Realizer _ F.toTopsp := @Ctop.Realizer.mk _ F.toTopsp σ F rfl instance (F : Ctop α σ) : Inhabited (@Ctop.Realizer _ F.toTopsp) := ⟨F.toRealizer⟩ namespace Ctop.Realizer protected theorem is_basis [T : TopologicalSpace α] (F : Realizer α) : TopologicalSpace.IsTopologicalBasis (Set.range F.F.f) := by have := toTopsp_isTopologicalBasis F.F; rwa [F.eq] at this protected theorem mem_nhds [T : TopologicalSpace α] (F : Realizer α) {s : Set α} {a : α} : s ∈ 𝓝 a ↔ ∃ b, a ∈ F.F b ∧ F.F b ⊆ s := by have := @mem_nhds_toTopsp _ _ F.F s a; rwa [F.eq] at this theorem isOpen_iff [TopologicalSpace α] (F : Realizer α) {s : Set α} : IsOpen s ↔ ∀ a ∈ s, ∃ b, a ∈ F.F b ∧ F.F b ⊆ s := isOpen_iff_mem_nhds.trans <| forall₂_congr fun _a _h ↦ F.mem_nhds theorem isClosed_iff [TopologicalSpace α] (F : Realizer α) {s : Set α} : IsClosed s ↔ ∀ a, (∀ b, a ∈ F.F b → ∃ z, z ∈ F.F b ∩ s) → a ∈ s := isOpen_compl_iff.symm.trans <| F.isOpen_iff.trans <| forall_congr' fun a ↦ show (a ∉ s → ∃ b : F.σ, a ∈ F.F b ∧ ∀ z ∈ F.F b, z ∉ s) ↔ _ by haveI := Classical.propDecidable; rw [not_imp_comm] simp [not_exists, not_and, not_forall, and_comm] theorem mem_interior_iff [TopologicalSpace α] (F : Realizer α) {s : Set α} {a : α} : a ∈ interior s ↔ ∃ b, a ∈ F.F b ∧ F.F b ⊆ s := mem_interior_iff_mem_nhds.trans F.mem_nhds protected theorem isOpen [TopologicalSpace α] (F : Realizer α) (s : F.σ) : IsOpen (F.F s) := isOpen_iff_nhds.2 fun a m ↦ by simpa using F.mem_nhds.2 ⟨s, m, Subset.refl _⟩ theorem ext' [T : TopologicalSpace α] {σ : Type*} {F : Ctop α σ} (H : ∀ a s, s ∈ 𝓝 a ↔ ∃ b, a ∈ F b ∧ F b ⊆ s) : F.toTopsp = T := by refine TopologicalSpace.ext_nhds fun x ↦ ?_ ext s rw [mem_nhds_toTopsp, H] theorem ext [T : TopologicalSpace α] {σ : Type*} {F : Ctop α σ} (H₁ : ∀ a, IsOpen (F a)) (H₂ : ∀ a s, s ∈ 𝓝 a → ∃ b, a ∈ F b ∧ F b ⊆ s) : F.toTopsp = T := ext' fun a s ↦ ⟨H₂ a s, fun ⟨_b, h₁, h₂⟩ ↦ mem_nhds_iff.2 ⟨_, h₂, H₁ _, h₁⟩⟩ variable [TopologicalSpace α] /-- The topological space realizer made of the open sets. -/ protected def id : Realizer α := ⟨{ x : Set α // IsOpen x }, { f := Subtype.val top := fun _ ↦ ⟨univ, isOpen_univ⟩ top_mem := mem_univ inter := fun ⟨_x, h₁⟩ ⟨_y, h₂⟩ _a _h₃ ↦ ⟨_, h₁.inter h₂⟩ inter_mem := fun ⟨_x, _h₁⟩ ⟨_y, _h₂⟩ _a ↦ id inter_sub := fun ⟨_x, _h₁⟩ ⟨_y, _h₂⟩ _a _h₃ ↦ Subset.refl _ }, ext Subtype.property fun _x _s h ↦ let ⟨t, h, o, m⟩ := mem_nhds_iff.1 h ⟨⟨t, o⟩, m, h⟩⟩ /-- Replace the representation type of a `Ctop` realizer. -/ def ofEquiv (F : Realizer α) (E : F.σ ≃ τ) : Realizer α := ⟨τ, F.F.ofEquiv E, ext' fun a s ↦ F.mem_nhds.trans <| ⟨fun ⟨s, h⟩ ↦ ⟨E s, by simpa using h⟩, fun ⟨t, h⟩ ↦ ⟨E.symm t, by simpa using h⟩⟩⟩ @[simp] theorem ofEquiv_σ (F : Realizer α) (E : F.σ ≃ τ) : (F.ofEquiv E).σ = τ := rfl @[simp] theorem ofEquiv_F (F : Realizer α) (E : F.σ ≃ τ) (s : τ) : (F.ofEquiv E).F s = F.F (E.symm s) := by delta ofEquiv; simp /-- A realizer of the neighborhood of a point. -/ protected def nhds (F : Realizer α) (a : α) : (𝓝 a).Realizer := ⟨{ s : F.σ // a ∈ F.F s }, { f := fun s ↦ F.F s.1 pt := ⟨_, F.F.top_mem a⟩ inf := fun ⟨x, h₁⟩ ⟨y, h₂⟩ ↦ ⟨_, F.F.inter_mem x y a ⟨h₁, h₂⟩⟩ inf_le_left := fun ⟨x, h₁⟩ ⟨y, h₂⟩ _z h ↦ (F.F.inter_sub x y a ⟨h₁, h₂⟩ h).1 inf_le_right := fun ⟨x, h₁⟩ ⟨y, h₂⟩ _z h ↦ (F.F.inter_sub x y a ⟨h₁, h₂⟩ h).2 }, filter_eq <| Set.ext fun _x ↦ ⟨fun ⟨⟨_s, as⟩, h⟩ ↦ mem_nhds_iff.2 ⟨_, h, F.isOpen _, as⟩, fun h ↦ let ⟨s, h, as⟩ := F.mem_nhds.1 h ⟨⟨s, h⟩, as⟩⟩⟩ @[simp] theorem nhds_σ (F : Realizer α) (a : α) : (F.nhds a).σ = { s : F.σ // a ∈ F.F s } := rfl @[simp] theorem nhds_F (F : Realizer α) (a : α) (s) : (F.nhds a).F s = F.F s.1 := rfl theorem tendsto_nhds_iff {m : β → α} {f : Filter β} (F : f.Realizer) (R : Realizer α) {a : α} : Tendsto m f (𝓝 a) ↔ ∀ t, a ∈ R.F t → ∃ s, ∀ x ∈ F.F s, m x ∈ R.F t := (F.tendsto_iff _ (R.nhds a)).trans Subtype.forall end Ctop.Realizer /-- A `LocallyFinite.Realizer F f` is a realization that `f` is locally finite, namely it is a choice of open sets from the basis of `F` such that they intersect only finitely many of the values of `f`. -/ structure LocallyFinite.Realizer [TopologicalSpace α] (F : Ctop.Realizer α) (f : β → Set α) where bas : ∀ a, { s // a ∈ F.F s } sets : ∀ x : α, Fintype { i | (f i ∩ F.F (bas x)).Nonempty } theorem LocallyFinite.Realizer.to_locallyFinite [TopologicalSpace α] {F : Ctop.Realizer α} {f : β → Set α} (R : LocallyFinite.Realizer F f) : LocallyFinite f := fun a ↦ ⟨_, F.mem_nhds.2 ⟨(R.bas a).1, (R.bas a).2, Subset.rfl⟩, have := R.sets a; Set.toFinite _⟩ theorem locallyFinite_iff_exists_realizer [TopologicalSpace α] (F : Ctop.Realizer α) {f : β → Set α} : LocallyFinite f ↔ Nonempty (LocallyFinite.Realizer F f) := ⟨fun h ↦ let ⟨g, h₁⟩ := Classical.axiom_of_choice h let ⟨g₂, h₂⟩ := Classical.axiom_of_choice fun x ↦ show ∃ b : F.σ, x ∈ F.F b ∧ F.F b ⊆ g x from let ⟨h, _h'⟩ := h₁ x F.mem_nhds.1 h ⟨⟨fun x ↦ ⟨g₂ x, (h₂ x).1⟩, fun x ↦ Finite.fintype <| let ⟨_h, h'⟩ := h₁ x h'.subset fun _i hi ↦ hi.mono (inter_subset_inter_right _ (h₂ x).2)⟩⟩, fun ⟨R⟩ ↦ R.to_locallyFinite⟩ instance [TopologicalSpace α] [Finite β] (F : Ctop.Realizer α) (f : β → Set α) : Nonempty (LocallyFinite.Realizer F f) := (locallyFinite_iff_exists_realizer _).1 <| locallyFinite_of_finite _ /-- A `Compact.Realizer s` is a realization that `s` is compact, namely it is a choice of finite open covers for each set family covering `s`. -/ def Compact.Realizer [TopologicalSpace α] (s : Set α) := ∀ {f : Filter α} (F : f.Realizer) (x : F.σ), f ≠ ⊥ → F.F x ⊆ s → { a // a ∈ s ∧ 𝓝 a ⊓ f ≠ ⊥ } instance [TopologicalSpace α] : Inhabited (Compact.Realizer (∅ : Set α)) := ⟨fun {f} F x h hF ↦ by suffices f = ⊥ from absurd this h rw [← F.eq, eq_bot_iff] exact fun s _ ↦ ⟨x, hF.trans s.empty_subset⟩⟩
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.
SpinGroup.lean
/- Copyright (c) 2022 Jiale Miao. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jiale Miao, Utensil Song, Eric Wieser -/ import Mathlib.Algebra.Ring.Action.ConjAct import Mathlib.GroupTheory.GroupAction.ConjAct import Mathlib.Algebra.Star.Unitary import Mathlib.LinearAlgebra.CliffordAlgebra.Star import Mathlib.LinearAlgebra.CliffordAlgebra.Even import Mathlib.LinearAlgebra.CliffordAlgebra.Inversion /-! # The Pin group and the Spin group In this file we define `lipschitzGroup`, `pinGroup` and `spinGroup` and show they form a group. ## Main definitions * `lipschitzGroup`: the Lipschitz group with a quadratic form. * `pinGroup`: the Pin group defined as the infimum of `lipschitzGroup` and `unitary`. * `spinGroup`: the Spin group defined as the infimum of `pinGroup` and `CliffordAlgebra.even`. ## Implementation Notes The definition of the Lipschitz group $\{ x \in \mathop{\mathcal{C}\ell} | x \text{ is invertible and } x v x^{-1} ∈ V \}$ is given by: * [fulton2004][], Chapter 20 * https://en.wikipedia.org/wiki/Clifford_algebra#Lipschitz_group But they presumably form a group only in finite dimensions. So we define `lipschitzGroup` with closure of all the invertible elements in the form of `ι Q m`, and we show this definition is at least as large as the other definition (See `lipschitzGroup.conjAct_smul_range_ι` and `lipschitzGroup.involute_act_ι_mem_range_ι`). The reverse statement presumably is true only in finite dimensions. Here are some discussions about the latent ambiguity of definition : https://mathoverflow.net/q/427881/172242 and https://mathoverflow.net/q/251288/172242 ## TODO Try to show the reverse statement is true in finite dimensions. -/ variable {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable {Q : QuadraticForm R M} section Pin open CliffordAlgebra MulAction open scoped Pointwise /-- `lipschitzGroup` is the subgroup closure of all the invertible elements in the form of `ι Q m` where `ι` is the canonical linear map `M →ₗ[R] CliffordAlgebra Q`. -/ def lipschitzGroup (Q : QuadraticForm R M) : Subgroup (CliffordAlgebra Q)ˣ := Subgroup.closure ((↑) ⁻¹' Set.range (ι Q) : Set (CliffordAlgebra Q)ˣ) namespace lipschitzGroup /-- The conjugation action by elements of the Lipschitz group keeps vectors as vectors. -/ theorem conjAct_smul_ι_mem_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : x ∈ lipschitzGroup Q) [Invertible (2 : R)] (m : M) : ConjAct.toConjAct x • ι Q m ∈ LinearMap.range (ι Q) := by unfold lipschitzGroup at hx rw [ConjAct.units_smul_def, ConjAct.ofConjAct_toConjAct] induction hx using Subgroup.closure_induction'' generalizing m with | mem x hx => obtain ⟨a, ha⟩ := hx letI := x.invertible letI : Invertible (ι Q a) := by rwa [ha] letI : Invertible (Q a) := invertibleOfInvertibleι Q a simp_rw [← invOf_units x, ← ha, ι_mul_ι_mul_invOf_ι, LinearMap.mem_range_self] | inv_mem x hx => obtain ⟨a, ha⟩ := hx letI := x.invertible letI : Invertible (ι Q a) := by rwa [ha] letI : Invertible (Q a) := invertibleOfInvertibleι Q a letI := invertibleNeg (ι Q a) letI := Invertible.map involute (ι Q a) simp_rw [← invOf_units x, inv_inv, ← ha, invOf_ι_mul_ι_mul_ι, LinearMap.mem_range_self] | one => simp_rw [inv_one, Units.val_one, one_mul, mul_one, LinearMap.mem_range_self] | mul y z _ _ hy hz => simp_rw [mul_inv_rev, Units.val_mul] suffices ↑y * (↑z * ι Q m * ↑z⁻¹) * ↑y⁻¹ ∈ _ by simpa only [mul_assoc] using this obtain ⟨z', hz'⟩ := hz m obtain ⟨y', hy'⟩ := hy z' simp_rw [← hz', ← hy', LinearMap.mem_range_self] /-- This is another version of `lipschitzGroup.conjAct_smul_ι_mem_range_ι` which uses `involute`. -/ theorem involute_act_ι_mem_range_ι [Invertible (2 : R)] {x : (CliffordAlgebra Q)ˣ} (hx : x ∈ lipschitzGroup Q) (b : M) : involute (Q := Q) ↑x * ι Q b * ↑x⁻¹ ∈ LinearMap.range (ι Q) := by unfold lipschitzGroup at hx induction hx using Subgroup.closure_induction'' generalizing b with | mem x hx => obtain ⟨a, ha⟩ := hx letI := x.invertible letI : Invertible (ι Q a) := by rwa [ha] letI : Invertible (Q a) := invertibleOfInvertibleι Q a simp_rw [← invOf_units x, ← ha, involute_ι, neg_mul, ι_mul_ι_mul_invOf_ι Q a b, ← map_neg, LinearMap.mem_range_self] | inv_mem x hx => obtain ⟨a, ha⟩ := hx letI := x.invertible letI : Invertible (ι Q a) := by rwa [ha] letI : Invertible (Q a) := invertibleOfInvertibleι Q a letI := invertibleNeg (ι Q a) letI := Invertible.map involute (ι Q a) simp_rw [← invOf_units x, inv_inv, ← ha, map_invOf, involute_ι, invOf_neg, neg_mul, invOf_ι_mul_ι_mul_ι, ← map_neg, LinearMap.mem_range_self] | one => simp_rw [inv_one, Units.val_one, map_one, one_mul, mul_one, LinearMap.mem_range_self] | mul y z _ _ hy hz => simp_rw [mul_inv_rev, Units.val_mul, map_mul] suffices involute (Q := Q) ↑y * (involute (Q := Q) ↑z * ι Q b * ↑z⁻¹) * ↑y⁻¹ ∈ _ by simpa only [mul_assoc] using this obtain ⟨z', hz'⟩ := hz b obtain ⟨y', hy'⟩ := hy z' simp_rw [← hz', ← hy', LinearMap.mem_range_self] /-- If x is in `lipschitzGroup Q`, then `(ι Q).range` is closed under twisted conjugation. The reverse statement presumably is true only in finite dimensions. -/ theorem conjAct_smul_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : x ∈ lipschitzGroup Q) [Invertible (2 : R)] : ConjAct.toConjAct x • LinearMap.range (ι Q) = LinearMap.range (ι Q) := by suffices ∀ x ∈ lipschitzGroup Q, ConjAct.toConjAct x • LinearMap.range (ι Q) ≤ LinearMap.range (ι Q) by apply le_antisymm · exact this _ hx · have := smul_mono_right (ConjAct.toConjAct x) <| this _ (inv_mem hx) refine Eq.trans_le ?_ this simp only [map_inv, smul_inv_smul] intro x hx erw [Submodule.map_le_iff_le_comap] rintro _ ⟨m, rfl⟩ exact conjAct_smul_ι_mem_range_ι hx _ theorem coe_mem_iff_mem {x : (CliffordAlgebra Q)ˣ} : ↑x ∈ (lipschitzGroup Q).toSubmonoid.map (Units.coeHom <| CliffordAlgebra Q) ↔ x ∈ lipschitzGroup Q := by simp only [Submonoid.mem_map, Subgroup.mem_toSubmonoid, Units.coeHom_apply] norm_cast exact exists_eq_right end lipschitzGroup /-- `pinGroup Q` is defined as the infimum of `lipschitzGroup Q` and `unitary (CliffordAlgebra Q)`. See `mem_iff`. -/ def pinGroup (Q : QuadraticForm R M) : Submonoid (CliffordAlgebra Q) := (lipschitzGroup Q).toSubmonoid.map (Units.coeHom <| CliffordAlgebra Q) ⊓ unitary _ namespace pinGroup /-- An element is in `pinGroup Q` if and only if it is in `lipschitzGroup Q` and `unitary`. -/ theorem mem_iff {x : CliffordAlgebra Q} : x ∈ pinGroup Q ↔ x ∈ (lipschitzGroup Q).toSubmonoid.map (Units.coeHom <| CliffordAlgebra Q) ∧ x ∈ unitary (CliffordAlgebra Q) := Iff.rfl theorem mem_lipschitzGroup {x : CliffordAlgebra Q} (hx : x ∈ pinGroup Q) : x ∈ (lipschitzGroup Q).toSubmonoid.map (Units.coeHom <| CliffordAlgebra Q) := hx.1 theorem mem_unitary {x : CliffordAlgebra Q} (hx : x ∈ pinGroup Q) : x ∈ unitary (CliffordAlgebra Q) := hx.2 theorem units_mem_iff {x : (CliffordAlgebra Q)ˣ} : ↑x ∈ pinGroup Q ↔ x ∈ lipschitzGroup Q ∧ ↑x ∈ unitary (CliffordAlgebra Q) := by rw [mem_iff, lipschitzGroup.coe_mem_iff_mem] theorem units_mem_lipschitzGroup {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ pinGroup Q) : x ∈ lipschitzGroup Q := (units_mem_iff.1 hx).1 /-- The conjugation action by elements of the spin group keeps vectors as vectors. -/ theorem conjAct_smul_ι_mem_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ pinGroup Q) [Invertible (2 : R)] (y : M) : ConjAct.toConjAct x • ι Q y ∈ LinearMap.range (ι Q) := lipschitzGroup.conjAct_smul_ι_mem_range_ι (units_mem_lipschitzGroup hx) y /-- This is another version of `conjAct_smul_ι_mem_range_ι` which uses `involute`. -/ theorem involute_act_ι_mem_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ pinGroup Q) [Invertible (2 : R)] (y : M) : involute (Q := Q) ↑x * ι Q y * ↑x⁻¹ ∈ LinearMap.range (ι Q) := lipschitzGroup.involute_act_ι_mem_range_ι (units_mem_lipschitzGroup hx) y /-- If x is in `pinGroup Q`, then `(ι Q).range` is closed under twisted conjugation. The reverse statement presumably being true only in finite dimensions. -/ theorem conjAct_smul_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ pinGroup Q) [Invertible (2 : R)] : ConjAct.toConjAct x • LinearMap.range (ι Q) = LinearMap.range (ι Q) := lipschitzGroup.conjAct_smul_range_ι (units_mem_lipschitzGroup hx) @[simp] theorem star_mul_self_of_mem {x : CliffordAlgebra Q} (hx : x ∈ pinGroup Q) : star x * x = 1 := hx.2.1 @[simp] theorem mul_star_self_of_mem {x : CliffordAlgebra Q} (hx : x ∈ pinGroup Q) : x * star x = 1 := hx.2.2 /-- See `star_mem_iff` for both directions. -/ theorem star_mem {x : CliffordAlgebra Q} (hx : x ∈ pinGroup Q) : star x ∈ pinGroup Q := by rw [mem_iff] at hx ⊢ refine ⟨?_, unitary.star_mem hx.2⟩ rcases hx with ⟨⟨y, hy₁, hy₂⟩, _hx₂, hx₃⟩ simp only [Subgroup.coe_toSubmonoid, SetLike.mem_coe] at hy₁ simp only [Units.coeHom_apply] at hy₂ simp only [Submonoid.mem_map, Subgroup.mem_toSubmonoid, Units.coeHom_apply] refine ⟨star y, ?_, by simp only [hy₂, Units.coe_star]⟩ rw [← hy₂] at hx₃ have hy₃ : y * star y = 1 := by rw [← Units.val_inj] simp only [hx₃, Units.val_mul, Units.coe_star, Units.val_one] apply_fun fun x => y⁻¹ * x at hy₃ simp only [inv_mul_cancel_left, mul_one] at hy₃ simp only [hy₃, hy₁, inv_mem_iff] /-- An element is in `pinGroup Q` if and only if `star x` is in `pinGroup Q`. See `star_mem` for only one direction. -/ @[simp] theorem star_mem_iff {x : CliffordAlgebra Q} : star x ∈ pinGroup Q ↔ x ∈ pinGroup Q := by refine ⟨?_, star_mem⟩ intro hx convert star_mem hx exact (star_star x).symm instance : Star (pinGroup Q) where star x := ⟨star x, star_mem x.prop⟩ @[simp, norm_cast] theorem coe_star {x : pinGroup Q} : ↑(star x) = (star x : CliffordAlgebra Q) := rfl theorem coe_star_mul_self (x : pinGroup Q) : (star x : CliffordAlgebra Q) * x = 1 := star_mul_self_of_mem x.prop theorem coe_mul_star_self (x : pinGroup Q) : (x : CliffordAlgebra Q) * star x = 1 := mul_star_self_of_mem x.prop @[simp] theorem star_mul_self (x : pinGroup Q) : star x * x = 1 := Subtype.ext <| coe_star_mul_self x @[simp] theorem mul_star_self (x : pinGroup Q) : x * star x = 1 := Subtype.ext <| coe_mul_star_self x /-- `pinGroup Q` forms a group where the inverse is `star`. -/ instance : Group (pinGroup Q) where inv := star inv_mul_cancel := star_mul_self instance : StarMul (pinGroup Q) where star_involutive _ := Subtype.ext <| star_involutive _ star_mul _ _ := Subtype.ext <| star_mul _ _ instance : Inhabited (pinGroup Q) := ⟨1⟩ theorem star_eq_inv (x : pinGroup Q) : star x = x⁻¹ := rfl theorem star_eq_inv' : (star : pinGroup Q → pinGroup Q) = Inv.inv := rfl /-- The elements in `pinGroup Q` embed into (CliffordAlgebra Q)ˣ. -/ @[simps] def toUnits : pinGroup Q →* (CliffordAlgebra Q)ˣ where toFun x := ⟨x, ↑x⁻¹, coe_mul_star_self x, coe_star_mul_self x⟩ map_one' := Units.ext rfl map_mul' _x _y := Units.ext rfl theorem toUnits_injective : Function.Injective (toUnits : pinGroup Q → (CliffordAlgebra Q)ˣ) := fun _x _y h => Subtype.ext <| Units.ext_iff.mp h end pinGroup end Pin section Spin open CliffordAlgebra MulAction open scoped Pointwise /-- `spinGroup Q` is defined as the infimum of `pinGroup Q` and `CliffordAlgebra.even Q`. See `mem_iff`. -/ def spinGroup (Q : QuadraticForm R M) : Submonoid (CliffordAlgebra Q) := pinGroup Q ⊓ (CliffordAlgebra.even Q).toSubring.toSubmonoid namespace spinGroup /-- An element is in `spinGroup Q` if and only if it is in `pinGroup Q` and `even Q`. -/ theorem mem_iff {x : CliffordAlgebra Q} : x ∈ spinGroup Q ↔ x ∈ pinGroup Q ∧ x ∈ even Q := Iff.rfl theorem mem_pin {x : CliffordAlgebra Q} (hx : x ∈ spinGroup Q) : x ∈ pinGroup Q := hx.1 theorem mem_even {x : CliffordAlgebra Q} (hx : x ∈ spinGroup Q) : x ∈ even Q := hx.2 theorem units_mem_lipschitzGroup {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ spinGroup Q) : x ∈ lipschitzGroup Q := pinGroup.units_mem_lipschitzGroup (mem_pin hx) /-- If x is in `spinGroup Q`, then `involute x` is equal to x. -/ theorem involute_eq {x : CliffordAlgebra Q} (hx : x ∈ spinGroup Q) : involute x = x := involute_eq_of_mem_even (mem_even hx) theorem units_involute_act_eq_conjAct {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ spinGroup Q) (y : M) : involute (Q := Q) ↑x * ι Q y * ↑x⁻¹ = ConjAct.toConjAct x • (ι Q y) := by rw [involute_eq hx, @ConjAct.units_smul_def, @ConjAct.ofConjAct_toConjAct] /-- The conjugation action by elements of the spin group keeps vectors as vectors. -/ theorem conjAct_smul_ι_mem_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ spinGroup Q) [Invertible (2 : R)] (y : M) : ConjAct.toConjAct x • ι Q y ∈ LinearMap.range (ι Q) := lipschitzGroup.conjAct_smul_ι_mem_range_ι (units_mem_lipschitzGroup hx) y /- This is another version of `conjAct_smul_ι_mem_range_ι` which uses `involute`. -/ theorem involute_act_ι_mem_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ spinGroup Q) [Invertible (2 : R)] (y : M) : involute (Q := Q) ↑x * ι Q y * ↑x⁻¹ ∈ LinearMap.range (ι Q) := lipschitzGroup.involute_act_ι_mem_range_ι (units_mem_lipschitzGroup hx) y /- If x is in `spinGroup Q`, then `(ι Q).range` is closed under twisted conjugation. The reverse statement presumably being true only in finite dimensions. -/ theorem conjAct_smul_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ spinGroup Q) [Invertible (2 : R)] : ConjAct.toConjAct x • LinearMap.range (ι Q) = LinearMap.range (ι Q) := lipschitzGroup.conjAct_smul_range_ι (units_mem_lipschitzGroup hx) @[simp] theorem star_mul_self_of_mem {x : CliffordAlgebra Q} (hx : x ∈ spinGroup Q) : star x * x = 1 := hx.1.2.1 @[simp] theorem mul_star_self_of_mem {x : CliffordAlgebra Q} (hx : x ∈ spinGroup Q) : x * star x = 1 := hx.1.2.2 /-- See `star_mem_iff` for both directions. -/ theorem star_mem {x : CliffordAlgebra Q} (hx : x ∈ spinGroup Q) : star x ∈ spinGroup Q := by rw [mem_iff] at hx ⊢ obtain ⟨hx₁, hx₂⟩ := hx refine ⟨pinGroup.star_mem hx₁, ?_⟩ dsimp only [CliffordAlgebra.even] at hx₂ ⊢ simp only [Submodule.mem_toSubalgebra] at hx₂ ⊢ simp only [star_def, reverse_mem_evenOdd_iff, involute_mem_evenOdd_iff, hx₂] /-- An element is in `spinGroup Q` if and only if `star x` is in `spinGroup Q`. See `star_mem` for only one direction. -/ @[simp] theorem star_mem_iff {x : CliffordAlgebra Q} : star x ∈ spinGroup Q ↔ x ∈ spinGroup Q := by refine ⟨?_, star_mem⟩ intro hx convert star_mem hx exact (star_star x).symm instance : Star (spinGroup Q) where star x := ⟨star x, star_mem x.prop⟩ @[simp, norm_cast] theorem coe_star {x : spinGroup Q} : ↑(star x) = (star x : CliffordAlgebra Q) := rfl theorem coe_star_mul_self (x : spinGroup Q) : (star x : CliffordAlgebra Q) * x = 1 := star_mul_self_of_mem x.prop theorem coe_mul_star_self (x : spinGroup Q) : (x : CliffordAlgebra Q) * star x = 1 := mul_star_self_of_mem x.prop @[simp] theorem star_mul_self (x : spinGroup Q) : star x * x = 1 := Subtype.ext <| coe_star_mul_self x @[simp] theorem mul_star_self (x : spinGroup Q) : x * star x = 1 := Subtype.ext <| coe_mul_star_self x /-- `spinGroup Q` forms a group where the inverse is `star`. -/ instance : Group (spinGroup Q) where inv := star inv_mul_cancel := star_mul_self instance : StarMul (spinGroup Q) where star_involutive _ := Subtype.ext <| star_involutive _ star_mul _ _ := Subtype.ext <| star_mul _ _ instance : Inhabited (spinGroup Q) := ⟨1⟩ theorem star_eq_inv (x : spinGroup Q) : star x = x⁻¹ := rfl theorem star_eq_inv' : (star : spinGroup Q → spinGroup Q) = Inv.inv := rfl /-- The elements in `spinGroup Q` embed into (CliffordAlgebra Q)ˣ. -/ @[simps] def toUnits : spinGroup Q →* (CliffordAlgebra Q)ˣ where toFun x := ⟨x, ↑x⁻¹, coe_mul_star_self x, coe_star_mul_self x⟩ map_one' := Units.ext rfl map_mul' _x _y := Units.ext rfl theorem toUnits_injective : Function.Injective (toUnits : spinGroup Q → (CliffordAlgebra Q)ˣ) := fun _x _y h => Subtype.ext <| Units.ext_iff.mp h end spinGroup end Spin
IsIntegral.lean
/- Copyright (c) 2022 Yuyang Zhao. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yuyang Zhao -/ import Mathlib.Analysis.Complex.Basic import Mathlib.RingTheory.IntegralClosure.IsIntegral.Basic /-! # Integral elements of ℂ This file proves that `Complex.I` is integral over ℤ and ℚ. -/ open Polynomial namespace Complex theorem isIntegral_int_I : IsIntegral ℤ I := by refine ⟨X ^ 2 + C 1, monic_X_pow_add_C _ two_ne_zero, ?_⟩ rw [eval₂_add, eval₂_X_pow, eval₂_C, I_sq, eq_intCast, Int.cast_one, neg_add_cancel] theorem isIntegral_rat_I : IsIntegral ℚ I := isIntegral_int_I.tower_top end Complex
sesquilinear.v
From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq div. From mathcomp Require Import choice fintype tuple bigop ssralg finset fingroup. From mathcomp Require Import zmodp poly order ssrnum matrix mxalgebra vector. (******************************************************************************) (* Sesquilinear forms *) (* *) (* e_ j := the row matrix with a 1 in column j *) (* M ^ phi := map_mx phi M *) (* Notation in scope sesquilinear_scope. *) (* M ^t phi := (M ^T) ^ phi *) (* Notation in scope sesquilinear_scope. *) (* involutive_rmorphism R == the type of involutive functions *) (* R has type nzRingType. *) (* The HB class is InvolutiveRMorphism. *) (* *) (* {bilinear U -> U' -> V | s & s'} == the type of bilinear forms which are *) (* essentially functions of type U -> U' -> V *) (* U and U' are lmodType's, V is a zmodType, s and *) (* s' are scaling operations of type R -> V -> V. *) (* The HB class is Bilinear. *) (* The factory bilinear_isBilinear provides a way *) (* to instantiate a bilinear form from two *) (* GRing.linear_for proofs. *) (* {bilinear U -> V -> W | s } := {bilinear U -> V -> W | s.1 & s.2} *) (* {bilinear U -> V -> W} := {bilinear U -> V -> W | *:%R & *:%R } *) (* {biscalar U} := {bilinear U -> U -> _ | *%R & *%R } *) (* *) (* applyr f x := f ^~ x with f : U -> U' -> V *) (* form theta M u v == form defined from a matrix M *) (* := (u *m M *m (v ^t theta)) 0 0 *) (* u and v are row vectors, M is a square matrix, *) (* coefficients have type R : fieldType, *) (* theta is a morphism *) (* *) (* {hermitian U for eps & theta} == hermitian/skew-hermitian form *) (* eps is a boolean flag, *) (* (false -> hermitian, true -> skew-hermitian), *) (* theta is a function R -> R (R : nzRingType). *) (* The HB class is Hermitian. *) (* *%R is used as a the first scaling operator. *) (* theta \; *R is used as the second scaling *) (* operation of the bilinear form. *) (* The archetypal case is theta being the complex *) (* conjugate. *) (* *) (* M \is (eps, theta).-sesqui == M is a sesquilinear form *) (* *) (* orthomx theta M B == M-orthogonal complement of B *) (* := kermx (M *m B ^t theta) *) (* M is a square matrix representing a sesquilinear *) (* form, B is a rectangle matrix representing a *) (* subspace *) (* (local notation: B ^_|_) *) (* ortho theta M B == orthomx theta M B with theta a morphism *) (* A '_|_ B := (A%MS <= B^_|_)%MS *) (* This is a local notation. *) (* rad theta M := ortho theta M 1%:M *) (* (local notation: 1%:M^_|_) *) (* *) (* {symmetric U} == symmetric form *) (* := {hermitian U for false & idfun} *) (* {skew_symmetric U} == skew-symmetric form *) (* := {hermitian U for true & idfun} *) (* {hermitian_sym U for theta} := hermitian form using theta (eps = false) *) (* {dot U for theta} == type of positive definite forms *) (* The HB class is Dot. *) (* *) (* is_skew eps theta form := eps = true /\ theta = idfun *) (* is_sym eps theta form := eps = false /\ theta = idfun *) (* is_hermsym eps theta form := eps = false *) (* *) (* ortho_rec s1 s2 := elements of s1 and s2 are pairwise orthogonal *) (* pairwise_orthogonal s == elements of s are pairwise orthogonal and *) (* s does not contain 0 *) (* orthogonal s1 s2 == the inner product of an element of S1 and *) (* an element of S2 is 0 *) (* := ortho_rec s1 s2 *) (* orthonormal s == s is an orthonormal set of unit vectors *) (* *) (* isometry form1 form2 tau == tau is an isometry from form1 to form2 *) (* form1 and form2 are hermitian forms. *) (* {in D, isometry tau, to R} == local notation for now *) (* *) (* orthov (V : {vspace vT}) == the space orthogonal to V *) (* *) (* In the following definitions, we have f : {hermitian vT for eps & theta} *) (* with vT : vectType F (F : fieldType): *) (* nondegenerate f == f is non-degenerated *) (* is_symplectic f == f is a symplectic bilinear form *) (* is_orthogonal f == f is an orthogonal form *) (* is_unitary f == f is a unitary form *) (* *) (* form_of_matrix theta M U V := \tr (U *m M *m (V ^t theta)) *) (* matrix_of_form f := \matrix_(i, j) form 'e_i 'e_j *) (* M \is hermitianmx eps theta == same as M \is (eps, theta).-sesqui *) (* without the constraint that theta is a morphism *) (* *) (* symmetricmx := hermitianmx _ false idfun *) (* skewmx := hermitianmx _ true idfun *) (* hermsymmx := hermitianmx _ false conjC *) (* *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Reserved Notation "M ^t phi" (at level 39, left associativity, format "M ^t phi"). Reserved Notation "A ^!" (format "A ^!"). Reserved Notation "A ^_|_" (format "A ^_|_"). Reserved Notation "A ''_|_' B" (at level 69, format "A ''_|_' B"). Reserved Notation "eps_theta .-sesqui" (format "eps_theta .-sesqui"). Local Open Scope ring_scope. Import GRing.Theory Order.Theory Num.Theory. Notation "''e_' j" := (delta_mx 0 j) (format "''e_' j", at level 8, j at level 2) : ring_scope. Declare Scope sesquilinear_scope. Delimit Scope sesquilinear_scope with sesqui. Local Open Scope sesquilinear_scope. Notation "M ^ phi" := (map_mx phi M) : sesquilinear_scope. Notation "M ^t phi" := ((M ^T) ^ phi) : sesquilinear_scope. (* TODO: move? *) Lemma eq_map_mx_id (R : nzRingType) m n (M : 'M[R]_(m, n)) (f : R -> R) : f =1 id -> M ^ f = M. Proof. by move=> /eq_map_mx->; rewrite map_mx_id. Qed. HB.mixin Record isInvolutive (R : nzRingType) (f : R -> R) := { involutive_subproof : involutive f }. (* TODO: move? *) #[short(type="involutive_rmorphism")] HB.structure Definition InvolutiveRMorphism (R : nzRingType) := { f of @GRing.RMorphism R R f & @isInvolutive R f }. Section InvolutiveTheory. Variable R : nzRingType. Let idfunK : involutive (@idfun R). Proof. by []. Qed. HB.instance Definition _ := isInvolutive.Build _ _ idfunK. Lemma rmorphK (f : involutive_rmorphism R) : involutive f. Proof. by move: f => [? [? ? []]]. Qed. End InvolutiveTheory. Definition conjC {C : numClosedFieldType} (c : C) : C := c^*. HB.instance Definition _ (C : numClosedFieldType) := GRing.RMorphism.on (@conjC C). Section conjC_involutive. Variable C : numClosedFieldType. Let conjCfun_involutive : involutive (@conjC C). Proof. exact: conjCK. Qed. HB.instance Definition _ := isInvolutive.Build _ (@conjC C) conjCfun_involutive. End conjC_involutive. Lemma map_mxCK {C : numClosedFieldType} m n (A : 'M[C]_(m, n)) : (A ^ conjC) ^ conjC = A. Proof. by apply/matrixP=> i j; rewrite !mxE conjCK. Qed. (*Structure revop X Y Z (f : Y -> X -> Z) := RevOp { fun_of_revop :> X -> Y -> Z; _ : forall x, f x =1 fun_of_revop^~ x }. Notation "[ 'revop' revop 'of' op ]" := (@RevOp _ _ _ revop op (fun _ _ => erefl)) (format "[ 'revop' revop 'of' op ]") : form_scope.*) HB.mixin Record isBilinear (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s : R -> V -> V) (s' : R -> V -> V) (f : U -> U' -> V) := { zmod_morphisml_subproof : forall u', zmod_morphism (f ^~ u') ; zmod_morphismr_subproof : forall u, zmod_morphism (f u) ; linearl_subproof : forall u', scalable_for s (f ^~ u') ; linearr_subproof : forall u, scalable_for s' (f u) }. #[short(type="bilinear")] HB.structure Definition Bilinear (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s : R -> V -> V) (s' : R -> V -> V) := {f of isBilinear R U U' V s s' f}. Definition bilinear_for (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s : GRing.Scale.law R V) (s' : GRing.Scale.law R V) (f : U -> U' -> V) := ((forall u', GRing.linear_for (s : R -> V -> V) (f ^~ u')) * (forall u, GRing.linear_for s' (f u)))%type. HB.factory Record bilinear_isBilinear (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s : GRing.Scale.law R V) (s' : GRing.Scale.law R V) (f : U -> U' -> V) := { bilinear_subproof : bilinear_for s s' f }. HB.builders Context R U U' V s s' f of bilinear_isBilinear R U U' V s s' f. HB.instance Definition _ := isBilinear.Build R U U' V s s' f (fun u' => zmod_morphism_linear (bilinear_subproof.1 u')) (fun u => zmod_morphism_linear (bilinear_subproof.2 u)) (fun u' => scalable_linear (bilinear_subproof.1 u')) (fun u => scalable_linear (bilinear_subproof.2 u)). HB.end. Module BilinearExports. Module Bilinear. Section bilinear. Variables (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s s' : R -> V -> V). Local Notation bilinear f := (bilinear_for *:%R *:%R f). Local Notation biscalar f := (bilinear_for *%R *%R f). (* Support for right-to-left rewriting with the generic linearZ rule. *) Notation mapUUV := (@Bilinear.type R U U' V s s'). Definition map_class := mapUUV. Definition map_at_left (a : R) := mapUUV. Definition map_at_right (b : R) := mapUUV. Definition map_at_both (a b : R) := mapUUV. Structure map_for_left a s_a := MapForLeft {map_for_left_map : mapUUV; _ : s a = s_a }. Structure map_for_right b s'_b := MapForRight {map_for_right_map : mapUUV; _ : s' b = s'_b }. Structure map_for_both a b s_a s'_b := MapForBoth {map_for_both_map : mapUUV; _ : s a = s_a ; _ : s' b = s'_b }. Definition unify_map_at_left a (f : map_at_left a) := MapForLeft f (erefl (s a)). Definition unify_map_at_right b (f : map_at_right b) := MapForRight f (erefl (s' b)). Definition unify_map_at_both a b (f : map_at_both a b) := MapForBoth f (erefl (s a)) (erefl (s' b)). Structure wrapped := Wrap {unwrap : mapUUV}. Definition wrap (f : map_class) := Wrap f. End bilinear. End Bilinear. Notation "{ 'bilinear' U -> V -> W | s & t }" := (@Bilinear.type _ U%type V%type W%type s t) (U at level 98, V at level 98, W at level 99, format "{ 'bilinear' U -> V -> W | s & t }") : ring_scope. Notation "{ 'bilinear' U -> V -> W | s }" := ({bilinear U -> V -> W | s.1 & s.2}) (U at level 98, V at level 98, W at level 99, format "{ 'bilinear' U -> V -> W | s }") : ring_scope. Notation "{ 'bilinear' U -> V -> W }" := {bilinear U -> V -> W | *:%R & *:%R} (U at level 98, V at level 98, W at level 99, format "{ 'bilinear' U -> V -> W }") : ring_scope. Notation "{ 'biscalar' U }" := {bilinear U%type -> U%type -> _ | *%R & *%R} (format "{ 'biscalar' U }") : ring_scope. End BilinearExports. Export BilinearExports. #[non_forgetful_inheritance] HB.instance Definition _ (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s : R -> V -> V) (s' : R -> V -> V) (f : {bilinear U -> U' -> V | s & s'}) (u : U) := @GRing.isZmodMorphism.Build U' V (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u). #[non_forgetful_inheritance] HB.instance Definition _ (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s : R -> V -> V) (s' : R -> V -> V) (f : @bilinear R U U' V s s') (u : U) := @GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u). Section applyr. Variables (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s s' : R -> V -> V). Definition applyr_head t (f : U -> U' -> V) u v := let: tt := t in f v u. End applyr. Notation applyr := (applyr_head tt). Coercion Bilinear.map_for_left_map : Bilinear.map_for_left >-> Bilinear.type. Coercion Bilinear.map_for_right_map : Bilinear.map_for_right >-> Bilinear.type. Coercion Bilinear.map_for_both_map : Bilinear.map_for_both >-> Bilinear.type. Coercion Bilinear.unify_map_at_left : Bilinear.map_at_left >-> Bilinear.map_for_left. Coercion Bilinear.unify_map_at_right : Bilinear.map_at_right >-> Bilinear.map_for_right. Coercion Bilinear.unify_map_at_both : Bilinear.map_at_both >-> Bilinear.map_for_both. Canonical Bilinear.unify_map_at_left. Canonical Bilinear.unify_map_at_right. Canonical Bilinear.unify_map_at_both. Coercion Bilinear.unwrap : Bilinear.wrapped >-> Bilinear.type. Coercion Bilinear.wrap : Bilinear.map_class >-> Bilinear.wrapped. Canonical Bilinear.wrap. Section BilinearTheory. Variable R : nzRingType. Section GenericProperties. Variables (U U' : lmodType R) (V : zmodType) (s : R -> V -> V) (s' : R -> V -> V). Variable f : {bilinear U -> U' -> V | s & s'}. Section GenericPropertiesr. Variable z : U. Lemma linear0r : f z 0 = 0. Proof. by rewrite raddf0. Qed. Lemma linearNr : {morph f z : x / - x}. Proof. exact: raddfN. Qed. Lemma linearDr : {morph f z : x y / x + y}. Proof. exact: raddfD. Qed. Lemma linearBr : {morph f z : x y / x - y}. Proof. exact: raddfB. Qed. Lemma linearMnr n : {morph f z : x / x *+ n}. Proof. exact: raddfMn. Qed. Lemma linearMNnr n : {morph f z : x / x *- n}. Proof. exact: raddfMNn. Qed. Lemma linear_sumr I r (P : pred I) E : f z (\sum_(i <- r | P i) E i) = \sum_(i <- r | P i) f z (E i). Proof. exact: raddf_sum. Qed. Lemma linearZr_LR : scalable_for s' (f z). Proof. exact: linearZ_LR. Qed. Lemma linearPr a : {morph f z : u v / a *: u + v >-> s' a u + v}. Proof. exact: linearP. Qed. End GenericPropertiesr. Lemma applyrE x : applyr f x =1 f^~ x. Proof. by []. Qed. Section GenericPropertiesl. Variable z : U'. HB.instance Definition _ := GRing.isZmodMorphism.Build _ _ (applyr f z) (@zmod_morphisml_subproof _ _ _ _ _ _ f z). HB.instance Definition _ := GRing.isScalable.Build _ _ _ _ (applyr f z) (@linearl_subproof _ _ _ _ _ _ f z). Lemma linear0l : f 0 z = 0. Proof. by rewrite -applyrE raddf0. Qed. Lemma linearNl : {morph f^~ z : x / - x}. Proof. by move=> ?; rewrite -applyrE raddfN. Qed. Lemma linearDl : {morph f^~ z : x y / x + y}. Proof. by move=> ? ?; rewrite -applyrE raddfD. Qed. Lemma linearBl : {morph f^~ z : x y / x - y}. Proof. by move=> ? ?; rewrite -applyrE raddfB. Qed. Lemma linearMnl n : {morph f^~ z : x / x *+ n}. Proof. by move=> ?; rewrite -applyrE raddfMn. Qed. Lemma linearMNnl n : {morph f^~ z : x / x *- n}. Proof. by move=> ?; rewrite -applyrE raddfMNn. Qed. Lemma linear_sumlz I r (P : pred I) E : f (\sum_(i <- r | P i) E i) z = \sum_(i <- r | P i) f (E i) z. Proof. by rewrite -applyrE raddf_sum. Qed. Lemma linearZl_LR : scalable_for s (f ^~ z). Proof. by move=> ? ?; rewrite -applyrE linearZ_LR. Qed. Lemma linearPl a : {morph f^~ z : u v / a *: u + v >-> s a u + v}. Proof. by move=> ? ?; rewrite -applyrE linearP. Qed. End GenericPropertiesl. End GenericProperties. Section BidirectionalLinearZ. Variables (U U' : lmodType R) (V : zmodType) (s s' : R -> V -> V). Variables (S : nzRingType) (h : GRing.Scale.law S V) (h' : GRing.Scale.law S V). Lemma linearZl z (c : S) (a : R) (h_c := h c) (f : Bilinear.map_for_left U U' s s' a h_c) u : f (a *: u) z = h_c (Bilinear.wrap f u z). Proof. by rewrite linearZl_LR; case: f => f /= ->. Qed. Lemma linearZr z c' b (h'_c' := h' c') (f : Bilinear.map_for_right U U' s s' b h'_c') u : f z (b *: u) = h'_c' (Bilinear.wrap f z u). Proof. by rewrite linearZr_LR; case: f => f /= ->. Qed. Lemma linearZlr c c' a b (h_c := h c) (h'_c' := h' c') (f : Bilinear.map_for_both U U' s s' a b h_c h'_c') u v : f (a *: u) (b *: v) = h_c (h'_c' (Bilinear.wrap f u v)). Proof. by rewrite linearZl_LR linearZ_LR; case: f => f /= -> ->. Qed. Lemma linearZrl c c' a b (h_c := h c) (h'_c' := h' c') (f : Bilinear.map_for_both U U' s s' a b h_c h'_c') u v : f (a *: u) (b *: v) = h'_c' (h_c (Bilinear.wrap f u v)). Proof. by rewrite linearZ_LR/= linearZl_LR; case: f => f /= -> ->. Qed. End BidirectionalLinearZ. End BilinearTheory. (* TODO Canonical rev_mulmx (R : nzRingType) m n p := [revop mulmxr of @mulmx R m n p]. *) (*Canonical mulmx_bilinear (R : comNzRingType) m n p := [bilinear of @mulmx R m n p].*) Lemma mulmx_is_bilinear (R : comNzRingType) m n p : bilinear_for (GRing.Scale.Law.clone _ _ *:%R _) (GRing.Scale.Law.clone _ _ *:%R _) (@mulmx R m n p). Proof. split=> [u'|u] a x y /=. - by rewrite mulmxDl scalemxAl. - by rewrite mulmxDr scalemxAr. Qed. HB.instance Definition _ (R : comNzRingType) m n p := bilinear_isBilinear.Build R [the lmodType R of 'M[R]_(m, n)] [the lmodType R of 'M[R]_(n, p)] [the zmodType of 'M[R]_(m, p)] _ _ (@mulmx R m n p) (mulmx_is_bilinear R m n p). Section BilinearForms. Variables (R : fieldType) (theta : {rmorphism R -> R}). Variables (n : nat) (M : 'M[R]_n). Implicit Types (a b : R) (u v : 'rV[R]_n) (N P Q : 'M[R]_n). Definition form u v := (u *m M *m (v ^t theta)) 0 0. Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u] : ring_scope. Lemma form0l u : '[0, u] = 0. Proof. by rewrite /form !mul0mx mxE. Qed. Lemma form0r u : '[u, 0] = 0. Proof. by rewrite /form trmx0 map_mx0 mulmx0 mxE. Qed. Lemma formDl u v w : '[u + v, w] = '[u, w] + '[v, w]. Proof. by rewrite /form !mulmxDl mxE. Qed. Lemma formDr u v w : '[u, v + w] = '[u, v] + '[u, w]. Proof. by rewrite /form linearD !map_mxD !mulmxDr mxE. Qed. Lemma formZr a u v : '[u, a *: v] = theta a * '[u, v]. Proof. by rewrite /form !(linearZ, map_mxZ) /= mxE. Qed. Lemma formZl a u v : '[a *: u, v] = a * '[u, v]. Proof. by do !rewrite /form -[_ *: _ *m _]/(mulmxr _ _) linearZ /=; rewrite mxE. Qed. Lemma formNl u v : '[- u, v] = - '[u, v]. Proof. by rewrite -scaleN1r formZl mulN1r. Qed. Lemma formNr u v : '[u, - v] = - '[u, v]. Proof. by rewrite -scaleN1r formZr rmorphN1 mulN1r. Qed. Lemma formee i j : '['e_i, 'e_j] = M i j. Proof. rewrite /form -rowE -map_trmx map_delta_mx -[M in LHS]trmxK. by rewrite -tr_col -trmx_mul -rowE !mxE. Qed. Lemma form0_eq0 : M = 0 -> forall u v, '[u, v] = 0. Proof. by rewrite/form=> -> u v; rewrite mulmx0 mul0mx mxE. Qed. End BilinearForms. HB.mixin Record isHermitianSesquilinear (R : nzRingType) (U : lmodType R) (eps : bool) (theta : R -> R) (f : U -> U -> R) := { hermitian_subproof : forall x y : U, f x y = (-1) ^+ eps * theta (f y x) }. HB.structure Definition Hermitian (R : nzRingType) (U : lmodType R) (eps : bool) (theta : R -> R) := {f of @Bilinear R U U _ ( *%R ) (theta \; *%R) f & @isHermitianSesquilinear R U eps theta f}. Notation "{ 'hermitian' U 'for' eps & theta }" := (@Hermitian.type _ U eps theta) (format "{ 'hermitian' U 'for' eps & theta }") : ring_scope. (* duplicate to trick HB *) #[non_forgetful_inheritance] HB.instance Definition _ (R : nzRingType) (U : lmodType R) (eps : bool) (theta : R -> R) (f : {hermitian U for eps & theta}) (u : U) := @GRing.isZmodMorphism.Build _ _ (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u). #[non_forgetful_inheritance] HB.instance Definition _ (R : nzRingType) (U : lmodType R) (eps : bool) (theta : R -> R) (f : {hermitian U for eps & theta}) (u : U) := @GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u). (*Variables (R : nzRingType) (U : lmodType R) (eps : bool) (theta : R -> R). Implicit Types phU : phant U. Local Coercion GRing.Scale.op : GRing.Scale.law >-> Funclass. Definition axiom (f : U -> U -> R) := forall x y : U, f x y = (-1) ^+ eps * theta (f y x). Record class_of (f : U -> U -> R) : Prop := Class { base : Bilinear.class_of ( *%R) (theta \; *%R) f; mixin : axiom f }.*) (*Canonical additiver (u : U) := Additive (base class u). Canonical linearr (u : U) := Linear (base class u). Canonical additivel (u' : U) := @GRing.Additive.Pack _ _ (Phant (U -> R)) (applyr cF u') (Bilinear.basel (base class) u'). Canonical linearl (u' : U) := @GRing.Linear.Pack _ _ _ _ (Phant (U -> R)) (applyr cF u') (Bilinear.basel (base class) u'). Canonical bilinear := @Bilinear.Pack _ _ _ _ _ _ (Phant (U -> U -> R)) cF (base class).*) (*Module Exports. Notation "{ 'hermitian' U 'for' eps & theta }" := (map eps theta (Phant U)) (format "{ 'hermitian' U 'for' eps & theta }") : ring_scope. Coercion base : class_of >-> bilmorphism_for. Coercion apply : map >-> Funclass. Notation "[ 'hermitian' 'of' f 'as' g ]" := (@clone _ _ _ _ _ _ f g _ idfun idfun) (format "[ 'hermitian' 'of' f 'as' g ]") : form_scope. Notation "[ 'hermitian' 'of' f ]" := (@clone _ _ _ _ _ _ f f _ idfun idfun) (format "[ 'hermitian' 'of' f ]") : form_scope. Notation hermitian_for := Hermitian.axiom. Notation Hermitian fM := (pack (Phant _) fM idfun). Canonical additiver. Canonical linearr. Canonical additivel. Canonical linearl. Canonical bilinear. Notation hermapplyr := (@applyr_head _ _ _ _ tt). End Exports. End Hermitian. Include Hermitian.Exports.*) Definition orthomx {R : fieldType} (theta : R -> R) n m M (B : 'M_(m, n)) : 'M_n := kermx (M *m (B ^t theta)). Section Sesquilinear. Variables (R : fieldType) (n : nat). Implicit Types (a b : R) (u v : 'rV[R]_n) (N P Q : 'M[R]_n). Section Def. Variable eps_theta : bool * {rmorphism R -> R}. Definition sesqui := [qualify M : 'M_n | M == ((-1) ^+ eps_theta.1) *: M ^t eps_theta.2]. Fact sesqui_key : pred_key sesqui. Proof. by []. Qed. Canonical sesqui_keyed := KeyedQualifier sesqui_key. End Def. Local Notation "eps_theta .-sesqui" := (sesqui eps_theta). Variables (eps : bool) (theta : {rmorphism R -> R}) (M : 'M[R]_n). Local Notation "''[' u , v ]" := (form theta M u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u] : ring_scope. Lemma sesquiE : (M \is (eps, theta).-sesqui) = (M == (-1) ^+ eps *: M ^t theta). Proof. by rewrite qualifE. Qed. Lemma sesquiP : reflect (M = (-1) ^+ eps *: M ^t theta) (M \is (eps, theta).-sesqui). Proof. by rewrite sesquiE; exact/eqP. Qed. Hypotheses (thetaK : involutive theta) (M_sesqui : M \is (eps, theta).-sesqui). Lemma trmx_sesqui : M^T = (-1) ^+ eps *: M ^ theta. Proof. rewrite [in LHS](sesquiP _) // -mul_scalar_mx trmx_mul. by rewrite tr_scalar_mx mul_mx_scalar map_trmx trmxK. Qed. Lemma maptrmx_sesqui : M^t theta = (-1) ^+ eps *: M. Proof. by rewrite trmx_sesqui map_mxZ rmorph_sign -map_mx_comp eq_map_mx_id. Qed. Lemma formC u v : '[u, v] = (-1) ^+ eps * theta '[v, u]. Proof. rewrite /form [M in LHS](sesquiP _) // -mulmxA !mxE rmorph_sum mulr_sumr. apply: eq_bigr => /= i _; rewrite !(mxE, mulr_sumr, mulr_suml, rmorph_sum). apply: eq_bigr => /= j _; rewrite !mxE !rmorphM mulrCA -!mulrA. by congr (_ * _); rewrite mulrA mulrC /= thetaK. Qed. Lemma form_eq0C u v : ('[u, v] == 0) = ('[v, u] == 0). Proof. by rewrite formC mulf_eq0 signr_eq0 /= fmorph_eq0. Qed. Definition ortho m (B : 'M_(m, n)) := orthomx theta M B. Local Notation "B ^_|_" := (ortho B) : ring_scope. Local Notation "A '_|_ B" := (A%MS <= B^_|_)%MS : ring_scope. Lemma normalE u v : (u '_|_ v) = ('[u, v] == 0). Proof. by rewrite (sameP sub_kermxP eqP) mulmxA [_ *m _^t _]mx11_scalar fmorph_eq0. Qed. Lemma form_eq0P {u v} : reflect ('[u, v] = 0) (u '_|_ v). Proof. by rewrite normalE; apply/eqP. Qed. Lemma normalP p q (A : 'M_(p, n)) (B :'M_(q, n)) : reflect (forall (u v : 'rV_n), (u <= A)%MS -> (v <= B)%MS -> u '_|_ v) (A '_|_ B). Proof. apply: (iffP idP) => AnB. move=> u v uA vB; rewrite (submx_trans uA) // (submx_trans AnB) //. apply/sub_kermxP; have /submxP [w ->] := vB. rewrite trmx_mul map_mxM !mulmxA -[kermx _ *m _ *m _]mulmxA. by rewrite [kermx _ *m _](sub_kermxP _) // mul0mx. apply/rV_subP => u /AnB /(_ _) /sub_kermxP uMv; apply/sub_kermxP. suff: forall m (v : 'rV[R]_m), (forall i, v *m 'e_i ^t theta = 0 :> 'M_1) -> v = 0. apply => i; rewrite !mulmxA -!mulmxA -map_mxM -trmx_mul uMv //. by apply/submxP; exists 'e_i. move=> /= m v Hv; apply: (can_inj (@trmxK _ _ _)). rewrite trmx0; apply/row_matrixP=> i; rewrite row0 rowE. apply: (can_inj (@trmxK _ _ _)); rewrite trmx0 trmx_mul trmxK. by rewrite -(map_delta_mx theta) map_trmx Hv. Qed. Lemma normalC p q (A : 'M_(p, n)) (B : 'M_(q, n)) : (A '_|_ B) = (B '_|_ A). Proof. gen have nC : p q A B / A '_|_ B -> B '_|_ A; last by apply/idP/idP; apply/nC. move=> AnB; apply/normalP => u v ? ?; rewrite normalE. rewrite formC mulf_eq0 ?fmorph_eq0 ?signr_eq0 /=. by rewrite -normalE (normalP _ _ AnB). Qed. Lemma normal_ortho_mx p (A : 'M_(p, n)) : ((A^_|_) '_|_ A). Proof. by []. Qed. Lemma normal_mx_ortho p (A : 'M_(p, n)) : (A '_|_ (A^_|_)). Proof. by rewrite normalC. Qed. Lemma rank_normal u : (\rank (u ^_|_) >= n.-1)%N. Proof. rewrite mxrank_ker -subn1 leq_sub2l //. by rewrite (leq_trans (mxrankM_maxr _ _)) // rank_leq_col. Qed. Definition rad := 1%:M^_|_. Lemma rad_ker : rad = kermx M. Proof. by rewrite /rad /ortho /orthomx trmx1 map_mx1 mulmx1. Qed. (* Pythagoras *) Theorem formDd u v : u '_|_ v -> '[u + v] = '[u] + '[v]. Proof. move=> uNv; rewrite formDl !formDr ['[v, u]]formC. by rewrite ['[u, v]](form_eq0P _) // rmorph0 mulr0 addr0 add0r. Qed. Lemma formZ a u : '[a *: u]= (a * theta a) * '[u]. Proof. by rewrite formZl formZr mulrA. Qed. Lemma formN u : '[- u] = '[u]. Proof. by rewrite formNr formNl opprK. Qed. Lemma form_sign m u : '[(-1) ^+ m *: u] = '[u]. Proof. by rewrite -signr_odd scaler_sign; case: odd; rewrite ?formN. Qed. Lemma formD u v : let d := '[u, v] in '[u + v] = '[u] + '[v] + (d + (-1) ^+ eps * theta d). Proof. by rewrite formDl !formDr ['[v, _]]formC [_ + '[v]]addrC addrACA. Qed. Lemma formB u v : let d := '[u, v] in '[u - v] = '[u] + '[v] - (d + (-1) ^+ eps * theta d). Proof. by rewrite formD formN !formNr rmorphN mulrN -opprD. Qed. Lemma formBd u v : u '_|_ v -> '[u - v] = '[u] + '[v]. Proof. by move=> uTv; rewrite formDd ?formN // normalE formNr oppr_eq0 -normalE. Qed. (* Lemma formJ u v : '[u ^ theta, v ^ theta] = (-1) ^+ eps * theta '[u, v]. *) (* Proof. *) (* rewrite {1}/form -map_trmx -map_mx_comp (@eq_map_mx _ _ _ _ _ id) ?map_mx_id //. *) (* set x := (_ *m _); have -> : x 0 0 = theta ((x^t theta) 0 0) by rewrite !mxE. *) (* rewrite !trmx_mul trmxK map_trmx mulmxA !map_mxM. *) (* rewrite maptrmx_sesqui -!scalemxAr -scalemxAl mxE rmorphM rmorph_sign. *) (* Lemma formJ u : '[u ^ theta] = (-1) ^+ eps * '[u]. *) (* Proof. *) (* rewrite {1}/form -map_trmx -map_mx_comp (@eq_map_mx _ _ _ _ _ id) ?map_mx_id //. *) (* set x := (_ *m _); have -> : x 0 0 = theta ((x^t theta) 0 0) by rewrite !mxE. *) (* rewrite !trmx_mul trmxK map_trmx mulmxA !map_mxM. *) (* rewrite maptrmx_sesqui -!scalemxAr -scalemxAl mxE rmorphM rmorph_sign. *) (* rewrite !map_mxM. *) (* rewrite -map_mx_comp eq_map_mx_id //. *) (* !linearZr_LR /=. linearZ. *) (* linearZl. *) (* rewrite trmx_sesqui. *) (* rewrite mapmx. *) (* rewrite map *) (* apply/matrixP. *) (* rewrite formC. *) (* Proof. by rewrite cfdot_conjC geC0_conj // cfnorm_ge0. Qed. *) (* Lemma cfCauchySchwarz u v : *) (* `|'[u, v]| ^+ 2 <= '[u] * '[v] ?= iff ~~ free (u :: v). *) (* Proof. *) (* rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC. *) (* have [-> | nz_v] /= := altP (v =P 0). *) (* by apply/lerifP; rewrite !cfdot0r normCK mul0r mulr0. *) (* without loss ou: u / '[u, v] = 0. *) (* move=> IHo; pose a := '[u, v] / '[v]; pose u1 := u - a *: v. *) (* have ou: '[u1, v] = 0. *) (* by rewrite cfdotBl cfdotZl divfK ?cfnorm_eq0 ?subrr. *) (* rewrite (canRL (subrK _) (erefl u1)) rpredDr ?rpredZ ?memv_line //. *) (* rewrite cfdotDl ou add0r cfdotZl normrM (ger0_norm (cfnorm_ge0 _)). *) (* rewrite exprMn mulrA -cfnormZ cfnormDd; last by rewrite cfdotZr ou mulr0. *) (* by have:= IHo _ ou; rewrite mulrDl -lerif_subLR subrr ou normCK mul0r. *) (* rewrite ou normCK mul0r; split; first by rewrite mulr_ge0 ?cfnorm_ge0. *) (* rewrite eq_sym mulf_eq0 orbC cfnorm_eq0 (negPf nz_v) /=. *) (* apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite cfdotZr ou mulr0. *) (* by rewrite cfnorm_eq0 => /eqP->; apply: rpred0. *) (* Qed. *) End Sesquilinear. Notation "eps_theta .-sesqui" := (sesqui _ eps_theta) : ring_scope. Notation symmetric_form := (false, idfun).-sesqui. Notation skew := (true, idfun).-sesqui. Notation hermitian := (false, @Num.conj_op _).-sesqui. HB.mixin Record isDotProduct (R : numDomainType) (U : lmodType R) (op : U -> U -> R) := { neq0_dnorm_gt0 : forall u, u != 0 -> 0 < op u u }. HB.structure Definition Dot (R : numDomainType) (U : lmodType R) (theta : R -> R) := {op of isDotProduct R U op & @Hermitian R U false theta op}. Notation "{ 'dot' U 'for' theta }" := (@Dot.type _ U theta) (format "{ 'dot' U 'for' theta }") : ring_scope. (* duplicate to trick HB *) #[non_forgetful_inheritance] HB.instance Definition _ (R : numDomainType) (U : lmodType R) (theta : R -> R) (f : {dot U for theta}) (u : U) := @GRing.isZmodMorphism.Build _ _ (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u). #[non_forgetful_inheritance] HB.instance Definition _ (R : numDomainType) (U : lmodType R) (theta : R -> R) (f : {dot U for theta}) (u : U) := @GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u). (*Notation "{ 'dot' U 'for' theta }" := (map theta (Phant U)) (format "{ 'dot' U 'for' theta }") : ring_scope. Coercion base : class_of >-> Hermitian.class_of. Coercion apply : map >-> Funclass. Notation "[ 'dot' 'of' f 'as' g ]" := (@clone _ _ _ _ _ f g _ idfun idfun) (format "[ 'dot' 'of' f 'as' g ]") : form_scope. Notation "[ 'dot' 'of' f ]" := (@clone _ _ _ _ _ f f _ idfun idfun) (format "[ 'dot' 'of' f ]") : form_scope. Notation Dot fM := (pack fM idfun). Notation is_dot := Dot.axiom.*) Notation "{ 'symmetric' U }" := ({hermitian U for false & idfun}) (format "{ 'symmetric' U }") : ring_scope. Notation "{ 'skew_symmetric' U }" := ({hermitian U for true & idfun}) (format "{ 'skew_symmetric' U }") : ring_scope. Notation "{ 'hermitian_sym' U 'for' theta }" := ({hermitian U for false & theta}) (format "{ 'hermitian_sym' U 'for' theta }") : ring_scope. Definition is_skew (R : nzRingType) (eps : bool) (theta : R -> R) (U : lmodType R) (form : {hermitian U for eps & theta}) := (eps = true) /\ (theta =1 id). Definition is_sym (R : nzRingType) (eps : bool) (theta : R -> R) (U : lmodType R) (form : {hermitian U for eps & theta}) := (eps = false) /\ (theta =1 id). Definition is_hermsym (R : nzRingType) (eps : bool) (theta : R -> R) (U : lmodType R) (form : {hermitian U for eps & theta}) := (eps = false). Section HermitianModuleTheory. Variables (R : nzRingType) (eps : bool) (theta : {rmorphism R -> R}). Variables (U : lmodType R) (form : {hermitian U for eps & theta}). Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Lemma hermC u v : '[u, v] = (-1) ^+ eps * theta '[v, u]. Proof. by move: form => [? [[? ? ? ?] []]] /=. Qed. Lemma hnormN u : '[- u] = '[u]. Proof. by rewrite linearNl linearNr opprK. Qed. Lemma hnorm_sign n u : '[(-1) ^+ n *: u] = '[u]. Proof. by rewrite -signr_odd scaler_sign; case: (odd n); rewrite ?hnormN. Qed. Lemma hnormD u v : let d := '[u, v] in '[u + v] = '[u] + '[v] + (d + (-1) ^+ eps * theta d). Proof. by rewrite /= addrAC -hermC linearDl 2!linearDr !addrA. Qed. Lemma hnormB u v : let d := '[u, v] in '[u - v] = '[u] + '[v] - (d + (-1) ^+ eps * theta d). Proof. by rewrite /= hnormD hnormN linearNr addrA rmorphN mulrN opprD addrA. Qed. Lemma hnormDd u v : '[u, v] = 0 -> '[u + v] = '[u] + '[v]. Proof. by move=> ouv; rewrite hnormD ouv rmorph0 mulr0 !addr0. Qed. Lemma hnormBd u v : '[u, v] = 0 -> '[u - v] = '[u] + '[v]. Proof. by move=> ouv; rewrite hnormDd ?hnormN// linearNr [X in - X]ouv oppr0. Qed. Local Notation "u '_|_ v" := ('[u, v] == 0) : ring_scope. Definition ortho_rec (s1 s2 : seq U) := all [pred u | all [pred v | u '_|_ v] s2] s1. Fixpoint pair_ortho_rec (s : seq U) := if s is v :: s' then ortho_rec [:: v] s' && pair_ortho_rec s' else true. (* We exclude 0 from pairwise orthogonal sets. *) Definition pairwise_orthogonal s := (0 \notin s) && pair_ortho_rec s. Definition orthogonal s1 s2 := (@ortho_rec s1 s2). Arguments orthogonal : simpl never. Lemma orthogonal_cons u us vs : orthogonal (u :: us) vs = orthogonal [:: u] vs && orthogonal us vs. Proof. by rewrite /orthogonal /= andbT. Qed. Definition orthonormal s := all [pred v | '[v] == 1] s && pair_ortho_rec s. Lemma orthonormal_not0 S : orthonormal S -> 0 \notin S. Proof. by case/andP=> /allP S1 _; rewrite (contra (S1 _)) //= linear0r eq_sym oner_eq0. Qed. Lemma orthonormalE S : orthonormal S = all [pred phi | '[phi] == 1] S && pairwise_orthogonal S. Proof. by rewrite -(andb_idl (@orthonormal_not0 S)) andbCA. Qed. Lemma orthonormal_orthogonal S : orthonormal S -> pairwise_orthogonal S. Proof. by rewrite orthonormalE => /andP[_]. Qed. End HermitianModuleTheory. Arguments orthogonal {R eps theta U} form s1 s2. Arguments pairwise_orthogonal {R eps theta U} form s. Arguments orthonormal {R eps theta U} form s. Section HermitianIsometry. Variables (R : nzRingType) (eps : bool) (theta : {rmorphism R -> R}). Variables (U1 U2 : lmodType R) (form1 : {hermitian U1 for eps & theta}) (form2 : {hermitian U2 for eps & theta}). Local Notation "''[' u , v ]_1" := (form1 u%R v%R) : ring_scope. Local Notation "''[' u , v ]_2" := (form2 u%R v%R) : ring_scope. Local Notation "''[' u ]_1" := (form1 u%R u%R) : ring_scope. Local Notation "''[' u ]_2" := (form2 u%R u%R): ring_scope. Definition isometry tau := forall u v, form1 (tau u) (tau v) = form2 u%R v%R. Definition isometry_from_to mD tau mR := prop_in2 mD (inPhantom (isometry tau)) /\ prop_in1 mD (inPhantom (forall u, in_mem (tau u) mR)). Local Notation "{ 'in' D , 'isometry' tau , 'to' R }" := (isometry_from_to (mem D) tau (mem R)) (format "{ 'in' D , 'isometry' tau , 'to' R }") : type_scope. End HermitianIsometry. Section HermitianVectTheory. Variables (R : fieldType) (eps : bool) (theta : {rmorphism R -> R}). Variable (U : lmodType R) (form : {hermitian U for eps & theta}). Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Lemma herm_eq0C u v : ('[u, v] == 0) = ('[v, u] == 0). Proof. by rewrite hermC mulf_eq0 signr_eq0 /= fmorph_eq0. Qed. End HermitianVectTheory. Section HermitianFinVectTheory. Variables (F : fieldType) (eps : bool) (theta : {rmorphism F -> F}). Variables (vT : vectType F) (form : {hermitian vT for eps & theta}). Let n := \dim {:vT}. Implicit Types (u v : vT) (U V : {vspace vT}). Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Let alpha v := (linfun (applyr form v : vT -> F^o)). Definition orthov V := (\bigcap_(i < \dim V) lker (alpha (vbasis V)`_i))%VS. Local Notation "U '_|_ V" := (U <= orthov V)%VS : vspace_scope. Lemma mem_orthovPn V u : reflect (exists2 v, v \in V & '[u, v] != 0) (u \notin orthov V). Proof. apply: (iffP idP) => [u_orthovV|[v /coord_vbasis-> uvNorthov]]; last first. apply/subv_bigcapP => uP. rewrite linear_sumr big1 ?eqxx//= in uvNorthov. move=> i _; have := uP i isT. by rewrite -memvE memv_ker lfunE/= linearZr/= => /eqP/= ->; rewrite mulr0. suff /existsP [i ui_neq0] : [exists i : 'I_(\dim V), '[u, (vbasis V)`_i] != 0]. by exists (vbasis V)`_i => //; rewrite vbasis_mem ?mem_nth ?size_tuple. apply: contraNT u_orthovV; rewrite negb_exists => /forallP ui_eq0. apply/subv_bigcapP => i _. by rewrite -memvE memv_ker lfunE /= -[_ == _]negbK. Qed. Lemma mem_orthovP V u : reflect {in V, forall v, '[u, v] = 0} (u \in orthov V). Proof. apply: (iffP idP) => [/mem_orthovPn orthovNu v vV|/(_ _ _)/eqP orthov_u]. by apply/eqP/negP=> /negP Northov_uv; apply: orthovNu; exists v. by apply/mem_orthovPn => -[v /orthov_u->]. Qed. Lemma orthov1E u : orthov <[u]> = lker (alpha u). Proof. apply/eqP; rewrite eqEsubv; apply/andP. split; apply/subvP=> v; rewrite memv_ker lfunE /=. by move=> /mem_orthovP-> //; rewrite ?memv_line. move=> vu_eq0; apply/mem_orthovP => w /vlineP[k->]. by apply/eqP; rewrite linearZ mulf_eq0 vu_eq0 orbT. Qed. Lemma orthovP U V : reflect {in U & V, forall u v, '[u, v] = 0} (U '_|_ V)%VS. Proof. apply: (iffP subvP); last by move=> H ??; apply/mem_orthovP=> ??; apply: H. by move=> /(_ _ _)/mem_orthovP; move=> H ????; apply: H. Qed. Lemma orthov_sym U V : (U '_|_ V)%VS = (V '_|_ U)%VS. Proof. by apply/orthovP/orthovP => eq0 ????; apply/eqP; rewrite herm_eq0C eq0. Qed. Lemma mem_orthov1 v u : (u \in orthov <[v]>) = ('[u, v] == 0). Proof. by rewrite orthov1E memv_ker lfunE. Qed. Lemma orthov11 u v : (<[u]> '_|_ <[v]>)%VS = ('[u, v] == 0). Proof. exact: mem_orthov1. Qed. Lemma mem_orthov1_sym v u : (u \in orthov <[v]>) = (v \in orthov <[u]>). Proof. exact: orthov_sym. Qed. Lemma orthov0 : orthov 0 = fullv. Proof. apply/eqP; rewrite eqEsubv subvf. apply/subvP => x _; rewrite mem_orthov1. by rewrite linear0r. Qed. Lemma mem_orthov_sym V u : (u \in orthov V) = (V <= orthov <[u]>)%VS. Proof. exact: orthov_sym. Qed. Lemma leq_dim_orthov1 u V : ((\dim V).-1 <= \dim (V :&: orthov <[u]>))%N. Proof. rewrite -(limg_ker_dim (alpha u) V) -orthov1E. have := dimvS (subvf (alpha u @: V)); rewrite dimvf addnC. by case: (\dim _) => [|[]] // _; rewrite leq_pred. Qed. Lemma dim_img_form_eq1 u V : u \notin orthov V -> \dim (alpha u @: V)%VS = 1%N. Proof. move=> /mem_orthovPn [v vV Northov_uv]; apply/eqP; rewrite eqn_leq /=. rewrite -[1%N as X in (_ <= X)%N](dimvf [the vectType F of F^o]) dimvS ?subvf//=. have := @dimvS _ _ <['[v, u] : F^o]> (alpha u @: V). rewrite -memvE dim_vline herm_eq0C Northov_uv; apply. by apply/memv_imgP; exists v; rewrite ?memvf// !lfunE /=. Qed. Lemma eq_dim_orthov1 u V : u \notin orthov V -> (\dim V).-1 = \dim (V :&: orthov <[u]>). Proof. rewrite -(limg_ker_dim (alpha u) V) => /dim_img_form_eq1->. by rewrite -orthov1E addn1. Qed. Lemma dim_img_form_eq0 u V : u \in orthov V -> \dim (alpha u @: V)%VS = 0%N. Proof. by move=> uV; apply/eqP; rewrite dimv_eq0 -lkerE -orthov1E orthov_sym. Qed. Lemma neq_dim_orthov1 u V : (\dim V > 0)%N -> u \in orthov V -> ((\dim V).-1 < \dim (V :&: orthov <[u]>))%N. Proof. move=> V_gt0; rewrite -(limg_ker_dim (alpha u) V) -orthov1E => u_in. rewrite dim_img_form_eq0 // addn0 (capv_idPl _) 1?orthov_sym //. by case: (\dim _) V_gt0. Qed. Lemma leqif_dim_orthov1 u V : (\dim V > 0)%N -> ((\dim V).-1 <= \dim (V :&: orthov <[u]>) ?= iff (u \notin orthov V))%N. Proof. move=> Vr_gt0; apply/leqifP. by case: (boolP (u \in _)) => /= [/neq_dim_orthov1->|/eq_dim_orthov1->]. Qed. Lemma leqif_dim_orthov1_full u : (n > 0)%N -> ((\dim {:vT}).-1 <= \dim (orthov <[u]>) ?= iff (u \notin orthov fullv))%N. Proof. by move=> n_gt0; have := @leqif_dim_orthov1 u fullv; rewrite capfv; apply. Qed. (* Link between orthov and orthovgonality of sequences *) Lemma orthogonal1P u v : reflect ('[u, v] = 0) (orthogonal form [:: u] [:: v]). Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed. Lemma orthogonalP us vs : reflect {in us & vs, forall u v, '[u, v] = 0} (orthogonal form us vs). Proof. apply: (iffP allP) => ousvs u => [v /ousvs/allP opus /opus/eqP // | /ousvs opus]. by apply/allP=> v /= /opus->. Qed. Lemma orthogonal_oppr S R : orthogonal form S (map -%R R) = orthogonal form S R. Proof. wlog suffices IH: S R / orthogonal form S R -> orthogonal form S (map -%R R). by apply/idP/idP=> /IH; rewrite ?mapK //; apply: opprK. move/orthogonalP=> oSR; apply/orthogonalP=> xi1 _ Sxi1 /mapP[xi2 Rxi2 ->]. by rewrite linearNr /= oSR ?oppr0. Qed. Lemma orthogonalE us vs : (orthogonal form us vs) = (<<us>> '_|_ <<vs>>)%VS. Proof. apply/orthogonalP/orthovP => uvsP u v; last first. by move=> uus vvs; rewrite uvsP // memv_span. rewrite -[us]in_tupleE -[vs]in_tupleE => /coord_span-> /coord_span->. rewrite linear_sumr big1 //= => i _. rewrite linear_sumlz big1 //= => j _. by rewrite linearZlr/= uvsP ?mulr0// mem_nth. Qed. Lemma orthovE U V : (U '_|_ V)%VS = orthogonal form (vbasis U) (vbasis V). Proof. by rewrite orthogonalE !(span_basis (vbasisP _)). Qed. Notation radv := (orthov fullv). Lemma orthoDv U V W : (U + V '_|_ W)%VS = (U '_|_ W)%VS && (V '_|_ W)%VS. Proof. by rewrite subv_add. Qed. Lemma orthovD U V W : (U '_|_ V + W)%VS = (U '_|_ V)%VS && (U '_|_ W)%VS. Proof. by rewrite ![(U '_|_ _)%VS]orthov_sym orthoDv. Qed. Definition nondegenerate := radv == 0%VS. Definition is_psymplectic := [/\ nondegenerate, is_skew form & 2 \in [pchar F] -> forall u, '[u, u] = 0]. Definition is_porthogonal := [/\ nondegenerate, is_sym form & 2 \in [pchar F] -> forall u, '[u, u] = 0]. Definition is_unitary := nondegenerate /\ (is_hermsym form). End HermitianFinVectTheory. #[deprecated(since="mathcomp 2.4.0", note="Use is_psymplectic instead.")] Notation is_symplectic := is_psymplectic (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use is_porthogonal instead.")] Notation is_orthogonal := is_porthogonal (only parsing). Arguments orthogonalP {F eps theta vT form us vs}. Arguments orthovP {F eps theta vT form U V}. Arguments mem_orthovPn {F eps theta vT form V u}. Arguments mem_orthovP {F eps theta vT form V u}. Section DotVectTheory. Variables (C : numClosedFieldType). Variable (U : lmodType C) (form : {dot U for conjC}). Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Lemma dnorm_geiff0 u : 0 <= '[u] ?= iff (u == 0). Proof. by apply/leifP; have [->|uN0] := altP eqP; rewrite ?linear0r ?neq0_dnorm_gt0. Qed. Lemma dnorm_ge0 u : 0 <= '[u]. Proof. by rewrite dnorm_geiff0. Qed. Lemma dnorm_eq0 u : ('[u] == 0) = (u == 0). Proof. by rewrite -dnorm_geiff0 eq_sym. Qed. Lemma dnorm_gt0 u : (0 < '[u]) = (u != 0). Proof. by rewrite lt_def dnorm_eq0 dnorm_ge0 andbT. Qed. Lemma sqrt_dnorm_ge0 u : 0 <= sqrtC '[u]. Proof. by rewrite sqrtC_ge0 dnorm_ge0. Qed. Lemma sqrt_dnorm_eq0 u : (sqrtC '[u] == 0) = (u == 0). Proof. by rewrite sqrtC_eq0 dnorm_eq0. Qed. Lemma sqrt_dnorm_gt0 u : (sqrtC '[u] > 0) = (u != 0). Proof. by rewrite sqrtC_gt0 dnorm_gt0. Qed. Lemma dnormZ a u : '[a *: u]= `|a| ^+ 2 * '[u]. Proof. by rewrite linearZl_LR linearZr_LR/= mulrA normCK. Qed. Lemma dnormD u v : let d := '[u, v] in '[u + v] = '[u] + '[v] + (d + d^*). Proof. by rewrite hnormD mul1r. Qed. Lemma dnormB u v : let d := '[u, v] in '[u - v] = '[u] + '[v] - (d + d^*). Proof. by rewrite hnormB mul1r. Qed. End DotVectTheory. #[global] Hint Extern 0 (is_true (0 <= Dot.sort _ _ _ (* NB: This Hint is assuming ^*, a more precise pattern would be welcome *))) => apply: dnorm_ge0 : core. Section HermitianTheory. Variables (C : numClosedFieldType) (eps : bool) (theta : {rmorphism C -> C}). Variable (U : lmodType C) (form : {dot U for conjC}). Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Lemma pairwise_orthogonalP S : reflect (uniq (0 :: S) /\ {in S &, forall phi psi, phi != psi -> '[phi, psi] = 0}) (pairwise_orthogonal form S). Proof. rewrite /pairwise_orthogonal /=; case notS0: (~~ _); last by right; case. elim: S notS0 => [|phi S IH] /=; first by left. rewrite inE eq_sym andbT => /norP[nz_phi {}/IH IH]. have [opS | not_opS] := allP; last first. right=> [[/andP[notSp _] opS]]; case: not_opS => psi Spsi /=. by rewrite opS ?mem_head 1?mem_behead // (memPnC notSp). rewrite (contra (opS _)) /= ?dnorm_eq0 //. apply: (iffP IH) => [] [uniqS oSS]; last first. by split=> //; apply: sub_in2 oSS => psi Spsi; apply: mem_behead. split=> // psi xi; rewrite !inE => /predU1P[-> // | Spsi]. by case/predU1P=> [-> | /opS] /eqP. case/predU1P=> [-> _ | Sxi /oSS-> //]. apply/eqP; rewrite hermC. by move: (opS psi Spsi) => /= /eqP ->; rewrite rmorph0 mulr0. Qed. Lemma pairwise_orthogonal_cat R S : pairwise_orthogonal form (R ++ S) = [&& pairwise_orthogonal form R, pairwise_orthogonal form S & orthogonal form R S]. Proof. rewrite /pairwise_orthogonal mem_cat negb_or -!andbA; do !bool_congr. elim: R => [|phi R /= ->]; rewrite ?andbT// all_cat -!andbA /=. by do !bool_congr. Qed. Lemma orthonormal_cat R S : orthonormal form (R ++ S) = [&& orthonormal form R, orthonormal form S & orthogonal form R S]. Proof. rewrite !orthonormalE pairwise_orthogonal_cat all_cat -!andbA. by do !bool_congr. Qed. Lemma orthonormalP S : reflect (uniq S /\ {in S &, forall phi psi, '[phi, psi] = (phi == psi)%:R}) (orthonormal form S). Proof. rewrite orthonormalE; have [/= normS | not_normS] := allP; last first. by right=> [[_ o1S]]; case: not_normS => phi Sphi; rewrite /= o1S ?eqxx. apply: (iffP (pairwise_orthogonalP S)) => [] [uniqS oSS]. split=> // [|phi psi]; first by case/andP: uniqS. by have [-> _ /normS/eqP | /oSS] := altP eqP. split=> // [|phi psi Sphi Spsi /negbTE]; last by rewrite oSS // => ->. by rewrite /= (contra (normS _)) // linear0r eq_sym oner_eq0. Qed. Lemma sub_orthonormal S1 S2 : {subset S1 <= S2} -> uniq S1 -> orthonormal form S2 -> orthonormal form S1. Proof. move=> sS12 uniqS1 /orthonormalP[_ oS1]. by apply/orthonormalP; split; last apply: sub_in2 sS12 _ _. Qed. Lemma orthonormal2P phi psi : reflect [/\ '[phi, psi] = 0, '[phi] = 1 & '[psi] = 1] (orthonormal form [:: phi; psi]). Proof. rewrite /orthonormal /= !andbT andbC. by apply: (iffP and3P) => [] []; do 3!move/eqP->. Qed. End HermitianTheory. Section DotFinVectTheory. Variable C : numClosedFieldType. Variables (U : vectType C) (form : {dot U for conjC}). Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Lemma sub_pairwise_orthogonal S1 S2 : {subset S1 <= S2} -> uniq S1 -> pairwise_orthogonal form S2 -> pairwise_orthogonal form S1. Proof. move=> sS12 uniqS1 /pairwise_orthogonalP[/andP[notS2_0 _] oS2]. apply/pairwise_orthogonalP; rewrite /= (contra (sS12 0)) //. by split=> //; apply: sub_in2 oS2. Qed. Lemma orthogonal_free S : pairwise_orthogonal form S -> free S. Proof. case/pairwise_orthogonalP=> [/=/andP[notS0 uniqS] oSS]. rewrite -(in_tupleE S); apply/freeP => a aS0 i. have S_i: S`_i \in S by apply: mem_nth. have /eqP: '[S`_i, 0] = 0 := linear0r _ _. rewrite -{2}aS0 raddf_sum /= (bigD1 i) //= big1 => [|j neq_ji]; last 1 first. by rewrite linearZ /= oSS ?mulr0 ?mem_nth // eq_sym nth_uniq. rewrite addr0 linearZ mulf_eq0 conjC_eq0 dnorm_eq0. by case/pred2P=> // Si0; rewrite -Si0 S_i in notS0. Qed. Lemma filter_pairwise_orthogonal S p : pairwise_orthogonal form S -> pairwise_orthogonal form (filter p S). Proof. move=> orthoS; apply: sub_pairwise_orthogonal (orthoS). exact: mem_subseq (filter_subseq p S). exact/filter_uniq/free_uniq/orthogonal_free. Qed. Lemma orthonormal_free S : orthonormal form S -> free S. Proof. by move/orthonormal_orthogonal/orthogonal_free. Qed. Theorem CauchySchwarz (u v : U) : `|'[u, v]| ^+ 2 <= '[u] * '[v] ?= iff ~~ free [:: u; v]. Proof. rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC. have [-> | nz_v] /= := altP (v =P 0). by apply/leifP; rewrite /= !linear0r normCK mul0r mulr0. without loss ou: u / '[u, v] = 0. move=> IHo; pose a := '[u, v] / '[v]; pose u1 := u - a *: v. have ou: '[u1, v] = 0. rewrite linearBl/=. rewrite linearZl_LR. by rewrite divfK ?dnorm_eq0 ?subrr. rewrite (canRL (subrK _) (erefl u1)) rpredDr ?rpredZ ?memv_line //. rewrite linearDl /= ou add0r. rewrite linearZl_LR/= normrM (ger0_norm (dnorm_ge0 _ _)). rewrite exprMn mulrA -dnormZ hnormDd/=; last by rewrite linearZr_LR/= ou mulr0. have:= IHo _ ou. by rewrite mulrDl -leifBLR subrr ou normCK mul0r. rewrite ou normCK mul0r; split; first by rewrite mulr_ge0. rewrite eq_sym mulf_eq0 orbC dnorm_eq0 (negPf nz_v) /=. apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite linearZr_LR/= ou mulr0. by rewrite dnorm_eq0 => /eqP->; apply: rpred0. Qed. Lemma CauchySchwarz_sqrt u v : `|'[u, v]| <= sqrtC '[u] * sqrtC '[v] ?= iff ~~ free [:: u; v]. Proof. rewrite -(sqrCK (normr_ge0 _)) -sqrtCM ?nnegrE//. rewrite (mono_in_leif (@ler_sqrtC _)) 1?rpredM//= ?nnegrE//=. exact: CauchySchwarz. Qed. Lemma orthoP phi psi : reflect ('[phi, psi] = 0) (orthogonal form [:: phi] [:: psi]). Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed. Lemma orthoPl phi S : reflect {in S, forall psi, '[phi, psi] = 0} (orthogonal form [:: phi] S). Proof. by rewrite [orthogonal form _ S]andbT /=; apply: (iffP allP) => ophiS ? /ophiS/eqP. Qed. Arguments orthoPl {phi S}. Lemma orthogonal_sym : symmetric (orthogonal form). Proof. apply: symmetric_from_pre => R S /orthogonalP oRS. by apply/orthogonalP=> phi psi Rpsi Sphi; rewrite hermC /= oRS ?rmorph0 ?mulr0. Qed. Lemma orthoPr S psi : reflect {in S, forall phi, '[phi, psi] = 0} (orthogonal form S [:: psi]). Proof. rewrite orthogonal_sym. by apply: (iffP orthoPl) => oSpsi phi Sphi; rewrite hermC /= oSpsi //= conjC0 mulr0. Qed. Lemma orthogonal_catl R1 R2 S : orthogonal form (R1 ++ R2) S = orthogonal form R1 S && orthogonal form R2 S. Proof. exact: all_cat. Qed. Lemma orthogonal_catr R S1 S2 : orthogonal form R (S1 ++ S2) = orthogonal form R S1 && orthogonal form R S2. Proof. by rewrite !(orthogonal_sym R) orthogonal_catl. Qed. Lemma eq_pairwise_orthogonal R S : perm_eq R S -> pairwise_orthogonal form R = pairwise_orthogonal form S. Proof. apply: catCA_perm_subst R S => R S S'. rewrite !pairwise_orthogonal_cat !orthogonal_catr (orthogonal_sym R S) -!andbA. by do !bool_congr. Qed. Lemma eq_orthonormal S0 S : perm_eq S0 S -> orthonormal form S0 = orthonormal form S. Proof. move=> eqRS; rewrite !orthonormalE (eq_all_r (perm_mem eqRS)). by rewrite (eq_pairwise_orthogonal eqRS). Qed. Lemma orthogonal_oppl S R : orthogonal form (map -%R S) R = orthogonal form S R. Proof. by rewrite -!(orthogonal_sym R) orthogonal_oppr. Qed. Lemma triangle_lerif u v : sqrtC '[u + v] <= sqrtC '[u] + sqrtC '[v] ?= iff ~~ free [:: u; v] && (0 <= coord [tuple v] 0 u). Proof. rewrite -(mono_in_leif ler_sqr) ?rpredD ?nnegrE ?sqrtC_ge0//. rewrite andbC sqrrD !sqrtCK addrAC dnormD (mono_leif (lerD2l _))/=. rewrite -mulr_natr -[_ + _](divfK (negbT (pnatr_eq0 C 2))) -/('Re _). rewrite (mono_leif (ler_pM2r _)) ?ltr0n//. have := leif_trans (leif_Re_Creal '[u, v]) (CauchySchwarz_sqrt u v). rewrite ReE; congr (_ <= _ ?= iff _); apply: andb_id2r. rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC. have [-> | nz_v] := altP (v =P 0); first by rewrite linear0 coord0. case/vlineP=> [x ->]; rewrite linearZl linearZ/= pmulr_lge0 ?dnorm_gt0 //=. by rewrite (coord_free 0) ?seq1_free // eqxx mulr1. Qed. Lemma span_orthogonal S1 S2 phi1 phi2 : orthogonal form S1 S2 -> phi1 \in <<S1>>%VS -> phi2 \in <<S2>>%VS -> '[phi1, phi2] = 0. Proof. move/orthogonalP=> oS12; do 2!move/(@coord_span _ _ _ (in_tuple _))->. rewrite linear_sumlz big1 // => i _; rewrite linear_sumr big1 // => j _. by rewrite linearZlr/= oS12 ?mem_nth ?mulr0. Qed. Lemma orthogonal_split S beta : {X : U & X \in <<S>>%VS & {Y :U | [/\ beta = X + Y, '[X, Y] = 0 & orthogonal form [:: Y] S]}}. Proof. suffices [X S_X [Y -> oYS]]: {X : _ & X \in <<S>>%VS & {Y | beta = X + Y & orthogonal form [:: Y] S}}. - exists X => //; exists Y. by rewrite hermC /= (span_orthogonal oYS) ?memv_span1 ?conjC0 // mulr0. elim: S beta => [|phi S IHS] beta. by exists 0; last exists beta; rewrite ?mem0v ?add0r. have [[UU S_U [V -> oVS]] [X S_X [Y -> oYS]]] := (IHS phi, IHS beta). pose Z := '[Y, V] / '[V] *: V; exists (X + Z). rewrite /Z -{4}(addKr UU V) scalerDr scalerN addrA addrC span_cons. by rewrite memv_add ?memvB ?memvZ ?memv_line. exists (Y - Z); first by rewrite addrCA !addrA addrK addrC. apply/orthoPl=> psi; rewrite !inE => /predU1P[-> | Spsi]; last first. by rewrite linearBl linearZl_LR /= (orthoPl oVS _ Spsi) mulr0 subr0 (orthoPl oYS). rewrite linearBl !linearDr /= (span_orthogonal oYS) // ?memv_span ?mem_head //. rewrite !linearZl_LR /= (span_orthogonal oVS _ S_U) ?mulr0 ?memv_span ?mem_head //. have [-> | nzV] := eqVneq V 0; first by rewrite linear0r !mul0r subrr. by rewrite divfK ?dnorm_eq0 ?subrr. Qed. End DotFinVectTheory. Arguments orthoP {C U form phi psi}. Arguments pairwise_orthogonalP {C U form S}. Arguments orthonormalP {C U form S}. Arguments orthoPl {C U form phi S}. Arguments orthoPr {C U form S psi}. Section BuildIsometries. Variables (C : numClosedFieldType) (U U1 U2 : vectType C). Variables (form : {dot U for conjC}) (form1 : {dot U1 for conjC}) (form2 : {dot U2 for conjC}). Definition normf1 := fun u => form1 u u. Definition normf2 := fun u => form2 u u. Lemma isometry_of_dnorm S tauS : pairwise_orthogonal form1 S -> pairwise_orthogonal form2 tauS -> map normf2 tauS = map normf1 S -> {tau : {linear U1 -> U2} | map tau S = tauS & {in <<S>>%VS &, isometry form2 form1 tau}}. Proof. move=> oS oT eq_nST; have freeS := orthogonal_free oS. have eq_sz: size tauS = size S by have:= congr1 size eq_nST; rewrite !size_map. have [tau defT] := linear_of_free S tauS; rewrite -[S]/(tval (in_tuple S)). exists tau => [|u v /coord_span-> /coord_span->]; rewrite ?raddf_sum ?defT //=. apply: eq_bigr => i _ /=; rewrite !linearZ/= !linear_sumlz; congr (_ * _). apply: eq_bigr => j _ /=; rewrite linearZ !linearZl; congr (_ * _). rewrite -!(nth_map 0 0 tau) ?{}defT //; have [-> | neq_ji] := eqVneq j i. by rewrite /= -[RHS](nth_map 0 0 normf1) -?[LHS](nth_map 0 0 normf2) ?eq_sz // eq_nST. have{oS} [/=/andP[_ uS] oS] := pairwise_orthogonalP oS. have{oT} [/=/andP[_ uT] oT] := pairwise_orthogonalP oT. by rewrite oS ?oT ?mem_nth ?nth_uniq ?eq_sz. Qed. Lemma isometry_of_free S f : free S -> {in S &, isometry form2 form1 f} -> {tau : {linear U1 -> U2} | {in S, tau =1 f} & {in <<S>>%VS &, isometry form2 form1 tau}}. Proof. move=> freeS If; have defS := free_span freeS. have [tau /(_ freeS (size_map f S))Dtau] := linear_of_free S (map f S). have {}Dtau: {in S, tau =1 f}. by move=> _ /(nthP 0)[i ltiS <-]; rewrite -!(nth_map 0 0) ?Dtau. exists tau => // _ _ /defS[a -> _] /defS[b -> _] /=. rewrite 2!{1}linear_sum /= !{1}linear_sumlz /=; apply/eq_big_seq=> xi1 Sxi1. rewrite !{1}linear_sumr; apply/eq_big_seq=> xi2 Sxi2 /=. by rewrite !linearZ /= !linearZl !Dtau //= If. Qed. Lemma isometry_raddf_inj (tau : {additive U1 -> U2}) : {in U1 &, isometry form2 form1 tau} -> {in U1 &, forall u v, u - v \in U1} -> {in U1 &, injective tau}. Proof. move=> Itau linU phi psi Uphi Upsi /eqP; rewrite -subr_eq0 -raddfB. by rewrite -(dnorm_eq0 form2) Itau ?linU // dnorm_eq0 subr_eq0 => /eqP. Qed. End BuildIsometries. Section MatrixForms. Variables (R : fieldType) (n : nat). Implicit Types (a b : R) (u v : 'rV[R]_n) (M N P Q : 'M[R]_n). Section Def. Variable theta : R -> R. Definition form_of_matrix m M (U V : 'M_(m, n)) := \tr (U *m M *m (V ^t theta)). Definition matrix_of_form (form : 'rV[R]_n -> 'rV[R]_n -> R) : 'M[R]_n := \matrix_(i, j) form 'e_i 'e_j. Implicit Type form : {bilinear 'rV[R]_n -> 'rV[R]_n -> R | *%R & theta \; *%R}. Lemma matrix_of_formE form i j : matrix_of_form form i j = form 'e_i 'e_j. Proof. by rewrite mxE. Qed. End Def. Section FormOfMatrix. Variables (m : nat) (M : 'M[R]_n). Implicit Types (U V : 'M[R]_(m, n)). Variables (theta : {rmorphism R -> R}). Local Notation "''[' U , V ]" := (form_of_matrix theta M U%R V%R) : ring_scope. Local Notation "''[' U ]" := '[U, U]%R : ring_scope. Let form_of_matrix_is_linear U : linear_for (theta \; *%R) (form_of_matrix theta M U). Proof. rewrite /form_of_matrix => k v w; rewrite -linearP/=. by rewrite linearP map_mxD map_mxZ !mulmxDr !scalemxAr. Qed. HB.instance Definition _ U := @GRing.isLinear.Build _ _ _ _ (form_of_matrix theta M U) (form_of_matrix_is_linear U). Definition form_of_matrixr U := (form_of_matrix theta M)^~U. Let form_of_matrixr_is_linear U : linear_for *%R (form_of_matrixr U). Proof. rewrite /form_of_matrixr /form_of_matrix => k v w. by rewrite -linearP /= !mulmxDl -!scalemxAl. Qed. HB.instance Definition _ U := @GRing.isLinear.Build _ _ _ _ (form_of_matrixr U) (form_of_matrixr_is_linear U). (* TODO Canonical form_of_matrixr_rev := [revop form_of_matrixr of form_of_matrix theta M]. *) Lemma form_of_matrix_is_bilinear : bilinear_for (GRing.Scale.Law.clone _ _ ( *%R ) _) (GRing.Scale.Law.clone _ _ (theta \; *%R ) _) (@form_of_matrix theta m M). Proof. split=> [u'|u] a x y /=. - by rewrite /form_of_matrix !mulmxDl linearD/= -!scalemxAl linearZ. - rewrite /form_of_matrix -linearZ/= -linearD/= [in LHS]linearD/= map_mxD. rewrite mulmxDr; congr (\tr (_ + _)). rewrite scalemxAr; congr (_ *m _). by rewrite linearZ/= map_mxZ. Qed. HB.instance Definition _ := bilinear_isBilinear.Build R _ _ _ (GRing.Scale.Law.clone _ _ ( *%R ) _) (GRing.Scale.Law.clone _ _ (theta \; *%R ) _) (@form_of_matrix theta m M) form_of_matrix_is_bilinear. (*Canonical form_of_matrix_is_bilinear := [the @bilinear _ _ _ _ of form_of_matrix theta M].*) End FormOfMatrix. Section FormOfMatrix1. Variables (M : 'M[R]_n). Variables (theta : {rmorphism R -> R}). Local Notation "''[' u , v ]" := (form_of_matrix theta M u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Lemma rV_formee i j : '['e_i :'rV__, 'e_j] = M i j. Proof. rewrite /form_of_matrix -rowE -map_trmx map_delta_mx -[M in LHS]trmxK. by rewrite -tr_col -trmx_mul -rowE trace_mx11 !mxE. Qed. Lemma form_of_matrixK : matrix_of_form (form_of_matrix theta M) = M. Proof. by apply/matrixP => i j; rewrite !mxE rV_formee. Qed. Lemma rV_form0_eq0 : M = 0 -> forall u v, '[u, v] = 0. Proof. by rewrite /form_of_matrix => -> u v; rewrite mulmx0 mul0mx trace_mx11 mxE. Qed. End FormOfMatrix1. Section MatrixOfForm. Variable (theta : {rmorphism R -> R}). Variable form : {bilinear 'rV[R]_n -> 'rV[R]_n -> R | *%R & theta \; *%R}. Lemma matrix_of_formK : form_of_matrix theta (matrix_of_form form) =2 form. Proof. set f := (X in X =2 _); have f_eq i j : f 'e_i 'e_j = form 'e_i 'e_j. by rewrite /f rV_formee mxE. move=> u v; rewrite [u]row_sum_delta [v]row_sum_delta /f. rewrite !linear_sum/=; apply: eq_bigr => j _. rewrite !linear_sumlz/=; apply: eq_bigr => i _. by rewrite !linearZlr/= -f_eq. Qed. End MatrixOfForm. Section HermitianMx. Variable eps : bool. Section HermitianMxDef. Variable theta : R -> R. Definition hermitianmx := [qualify M : 'M_n | M == ((-1) ^+ eps) *: M ^t theta]. Fact hermitianmx_key : pred_key hermitianmx. Proof. by []. Qed. Canonical hermitianmx_keyed := KeyedQualifier hermitianmx_key. Structure hermitian_matrix := HermitianMx { mx_of_hermitian :> 'M[R]_n; _ : mx_of_hermitian \is hermitianmx }. Lemma is_hermitianmxE M : (M \is hermitianmx) = (M == (-1) ^+ eps *: M ^t theta). Proof. by rewrite qualifE. Qed. Lemma is_hermitianmxP M : reflect (M = (-1) ^+ eps *: M ^t theta) (M \is hermitianmx). Proof. by rewrite is_hermitianmxE; apply/eqP. Qed. Lemma hermitianmxE (M : hermitian_matrix) : M = ((-1) ^+ eps) *: M ^t theta :> 'M__. Proof. by apply/eqP; case: M. Qed. Lemma trmx_hermitian (M : hermitian_matrix) : M^T = ((-1) ^+ eps) *: M ^ theta :> 'M__. Proof. by rewrite {1}hermitianmxE linearZ /= map_trmx trmxK. Qed. End HermitianMxDef. Section HermitianMxTheory. Variables (theta : involutive_rmorphism R) (M : hermitian_matrix theta). Lemma maptrmx_hermitian : M^t theta = (-1) ^+ eps *: (M : 'M__). Proof. rewrite trmx_hermitian map_mxZ rmorph_sign -map_mx_comp. by rewrite (map_mx_id (rmorphK _)). Qed. Lemma form_of_matrix_is_hermitian m x y : (@form_of_matrix theta m M) x y = (-1) ^+ eps * theta ((@form_of_matrix theta m M) y x). Proof. rewrite {1}hermitianmxE /form_of_matrix. rewrite -!(scalemxAr, scalemxAl) linearZ/=; congr (_ * _). rewrite -mxtrace_tr -trace_map_mx !(trmx_mul, map_mxM, map_trmx, trmxK). by rewrite -mulmxA -!map_mx_comp !(map_mx_id (rmorphK _)). Qed. HB.instance Definition _ m := @isHermitianSesquilinear.Build _ _ _ _ _ (@form_of_matrix_is_hermitian m). Local Notation "''[' u , v ]" := (form_of_matrix theta M u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Local Notation "B ^!" := (orthomx theta M B) : matrix_set_scope. Local Notation "A '_|_ B" := (A%MS <= B%MS^!)%MS : matrix_set_scope. Lemma orthomxE u v : (u '_|_ v)%MS = ('[u, v] == 0). Proof. rewrite (sameP sub_kermxP eqP) mulmxA. by rewrite [_ *m _^t _]mx11_scalar -trace_mx11 fmorph_eq0. Qed. Lemma hermmx_eq0P {u v} : reflect ('[u, v] = 0) (u '_|_ v)%MS. Proof. by rewrite orthomxE; apply/eqP. Qed. Lemma orthomxP p q (A : 'M_(p, n)) (B :'M_(q, n)) : reflect (forall (u v : 'rV_n), u <= A -> v <= B -> u '_|_ v)%MS (A '_|_ B)%MS. Proof. apply: (iffP idP) => AnB. move=> u v uA vB; rewrite (submx_trans uA) // (submx_trans AnB) //. apply/sub_kermxP; have /submxP [w ->] := vB. rewrite trmx_mul map_mxM !mulmxA -[kermx _ *m _ *m _]mulmxA. by rewrite [kermx _ *m _](sub_kermxP _) // mul0mx. apply/rV_subP => u /AnB /(_ _) /sub_kermxP uMv; apply/sub_kermxP. suff: forall m (v : 'rV[R]_m), (forall i, v *m 'e_i ^t theta = 0 :> 'M_1) -> v = 0. apply => i; rewrite !mulmxA -!mulmxA -map_mxM -trmx_mul uMv //. by apply/submxP; exists 'e_i. move=> /= m v Hv; apply: (can_inj (@trmxK _ _ _)). rewrite trmx0; apply/row_matrixP=> i; rewrite row0 rowE. apply: (can_inj (@trmxK _ _ _)); rewrite trmx0 trmx_mul trmxK. by rewrite -(map_delta_mx theta) map_trmx Hv. Qed. Lemma orthomx_sym p q (A : 'M_(p, n)) (B :'M_(q, n)) : (A '_|_ B)%MS = (B '_|_ A)%MS. Proof. gen have nC : p q A B / (A '_|_ B -> B '_|_ A)%MS; last by apply/idP/idP; apply/nC. move=> AnB; apply/orthomxP => u v ? ?; rewrite orthomxE. rewrite hermC mulf_eq0 ?fmorph_eq0 ?signr_eq0 /=. by rewrite -orthomxE (orthomxP _ _ AnB). Qed. Lemma ortho_ortho_mx p (A : 'M_(p, n)) : (A^! '_|_ A)%MS. Proof. by []. Qed. Lemma ortho_mx_ortho p (A : 'M_(p, n)) : (A '_|_ A^!)%MS. Proof. by rewrite orthomx_sym. Qed. Lemma rank_orthomx u : (\rank (u ^!) >= n.-1)%N. Proof. rewrite mxrank_ker -subn1 leq_sub2l //. by rewrite (leq_trans (mxrankM_maxr _ _)) // rank_leq_col. Qed. Local Notation radmx := (1%:M^!)%MS. Lemma radmxE : radmx = kermx M. Proof. by rewrite /orthomx /orthomx trmx1 map_mx1 mulmx1. Qed. Lemma orthoNmx k m (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) : ((- A) '_|_ B)%MS = (A '_|_ B)%MS. Proof. by rewrite eqmx_opp. Qed. Lemma orthomxN k m (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) : (A '_|_ (- B))%MS = (A '_|_ B)%MS. Proof. by rewrite ![(A '_|_ _)%MS]orthomx_sym orthoNmx. Qed. Lemma orthoDmx k m p (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) (C : 'M[R]_(p, n)) : (A + B '_|_ C)%MS = (A '_|_ C)%MS && (B '_|_ C)%MS. Proof. by rewrite addsmxE !(sameP sub_kermxP eqP) mul_col_mx col_mx_eq0. Qed. Lemma orthomxD k m p (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) (C : 'M[R]_(p, n)) : (A '_|_ B + C)%MS = (A '_|_ B)%MS && (A '_|_ C)%MS. Proof. by rewrite ![(A '_|_ _)%MS]orthomx_sym orthoDmx. Qed. Lemma orthoZmx p m a (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) : a != 0 -> (a *: A '_|_ B)%MS = (A '_|_ B)%MS. Proof. by move=> a_neq0; rewrite eqmx_scale. Qed. Lemma orthomxZ p m a (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) : a != 0 -> (A '_|_ (a *: B))%MS = (A '_|_ B)%MS. Proof. by move=> a_neq0; rewrite ![(A '_|_ _)%MS]orthomx_sym orthoZmx. Qed. Lemma eqmx_ortho p m (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) : (A :=: B)%MS -> (A^! :=: B^!)%MS. Proof. move=> eqAB; apply/eqmxP. by rewrite orthomx_sym -eqAB ortho_mx_ortho orthomx_sym eqAB ortho_mx_ortho. Qed. Lemma genmx_ortho p (A : 'M[R]_(p, n)) : (<<A>>^! :=: A^!)%MS. Proof. exact: (eqmx_ortho (genmxE _)). Qed. End HermitianMxTheory. End HermitianMx. End MatrixForms. Notation symmetricmx := (hermitianmx _ false idfun). Notation skewmx := (hermitianmx _ true idfun). Notation hermsymmx := (hermitianmx _ false conjC). Lemma hermitian1mx_subproof {C : numClosedFieldType} n : (1%:M : 'M[C]_n) \is hermsymmx. Proof. by rewrite qualifE /= expr0 scale1r tr_scalar_mx map_scalar_mx conjC1. Qed. Canonical hermitian1mx {C : numClosedFieldType} n := HermitianMx (@hermitian1mx_subproof C n).
Preadditive.lean
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Generator.Basic import Mathlib.CategoryTheory.Preadditive.Yoneda.Basic /-! # Separators in preadditive categories This file contains characterizations of separating sets and objects that are valid in all preadditive categories. -/ universe v u open CategoryTheory Opposite namespace CategoryTheory variable {C : Type u} [Category.{v} C] [Preadditive C] theorem Preadditive.isSeparating_iff (𝒢 : Set C) : IsSeparating 𝒢 ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : G ⟶ X), h ≫ f = 0) → f = 0 := ⟨fun h𝒢 X Y f hf => h𝒢 _ _ (by simpa only [Limits.comp_zero] using hf), fun h𝒢 X Y f g hfg => sub_eq_zero.1 <| h𝒢 _ (by simpa only [Preadditive.comp_sub, sub_eq_zero] using hfg)⟩ theorem Preadditive.isCoseparating_iff (𝒢 : Set C) : IsCoseparating 𝒢 ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : Y ⟶ G), f ≫ h = 0) → f = 0 := ⟨fun h𝒢 X Y f hf => h𝒢 _ _ (by simpa only [Limits.zero_comp] using hf), fun h𝒢 X Y f g hfg => sub_eq_zero.1 <| h𝒢 _ (by simpa only [Preadditive.sub_comp, sub_eq_zero] using hfg)⟩ theorem Preadditive.isSeparator_iff (G : C) : IsSeparator G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : G ⟶ X, h ≫ f = 0) → f = 0 := ⟨fun hG X Y f hf => hG.def _ _ (by simpa only [Limits.comp_zero] using hf), fun hG => (isSeparator_def _).2 fun X Y f g hfg => sub_eq_zero.1 <| hG _ (by simpa only [Preadditive.comp_sub, sub_eq_zero] using hfg)⟩ theorem Preadditive.isCoseparator_iff (G : C) : IsCoseparator G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : Y ⟶ G, f ≫ h = 0) → f = 0 := ⟨fun hG X Y f hf => hG.def _ _ (by simpa only [Limits.zero_comp] using hf), fun hG => (isCoseparator_def _).2 fun X Y f g hfg => sub_eq_zero.1 <| hG _ (by simpa only [Preadditive.sub_comp, sub_eq_zero] using hfg)⟩ theorem isSeparator_iff_faithful_preadditiveCoyoneda (G : C) : IsSeparator G ↔ (preadditiveCoyoneda.obj (op G)).Faithful := by rw [isSeparator_iff_faithful_coyoneda_obj, ← whiskering_preadditiveCoyoneda, Functor.comp_obj, Functor.whiskeringRight_obj_obj] exact ⟨fun h => Functor.Faithful.of_comp _ (forget AddCommGrp), fun h => Functor.Faithful.comp _ _⟩ theorem isSeparator_iff_faithful_preadditiveCoyonedaObj (G : C) : IsSeparator G ↔ (preadditiveCoyonedaObj G).Faithful := by rw [isSeparator_iff_faithful_preadditiveCoyoneda, preadditiveCoyoneda_obj] exact ⟨fun h => Functor.Faithful.of_comp _ (forget₂ _ AddCommGrp.{v}), fun h => Functor.Faithful.comp _ _⟩ theorem isCoseparator_iff_faithful_preadditiveYoneda (G : C) : IsCoseparator G ↔ (preadditiveYoneda.obj G).Faithful := by rw [isCoseparator_iff_faithful_yoneda_obj, ← whiskering_preadditiveYoneda, Functor.comp_obj, Functor.whiskeringRight_obj_obj] exact ⟨fun h => Functor.Faithful.of_comp _ (forget AddCommGrp), fun h => Functor.Faithful.comp _ _⟩ theorem isCoseparator_iff_faithful_preadditiveYonedaObj (G : C) : IsCoseparator G ↔ (preadditiveYonedaObj G).Faithful := by rw [isCoseparator_iff_faithful_preadditiveYoneda, preadditiveYoneda_obj] exact ⟨fun h => Functor.Faithful.of_comp _ (forget₂ _ AddCommGrp.{v}), fun h => Functor.Faithful.comp _ _⟩ end CategoryTheory
Internal.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Kevin Buzzard, Jujian Zhang, Fangming Li -/ import Mathlib.Algebra.Algebra.Operations import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.Algebra.DirectSum.Algebra import Mathlib.Algebra.Order.Antidiag.Prod /-! # Internally graded rings and algebras This module provides `DirectSum.GSemiring` and `DirectSum.GCommSemiring` instances for a collection of subobjects `A` when a `SetLike.GradedMonoid` instance is available: * `SetLike.gnonUnitalNonAssocSemiring` * `SetLike.gsemiring` * `SetLike.gcommSemiring` With these instances in place, it provides the bundled canonical maps out of a direct sum of subobjects into their carrier type: * `DirectSum.coeRingHom` (a `RingHom` version of `DirectSum.coeAddMonoidHom`) * `DirectSum.coeAlgHom` (an `AlgHom` version of `DirectSum.coeLinearMap`) Strictly the definitions in this file are not sufficient to fully define an "internal" direct sum; to represent this case, `(h : DirectSum.IsInternal A) [SetLike.GradedMonoid A]` is needed. In the future there will likely be a data-carrying, constructive, typeclass version of `DirectSum.IsInternal` for providing an explicit decomposition function. When `iSupIndep (Set.range A)` (a weaker condition than `DirectSum.IsInternal A`), these provide a grading of `⨆ i, A i`, and the mapping `⨁ i, A i →+ ⨆ i, A i` can be obtained as `DirectSum.toAddMonoid (fun i ↦ AddSubmonoid.inclusion <| le_iSup A i)`. This file also provides some extra structure on `A 0`, namely: * `SetLike.GradeZero.subsemiring`, which leads to * `SetLike.GradeZero.instSemiring` * `SetLike.GradeZero.instCommSemiring` * `SetLike.GradeZero.subring`, which leads to * `SetLike.GradeZero.instRing` * `SetLike.GradeZero.instCommRing` * `SetLike.GradeZero.subalgebra`, which leads to * `SetLike.GradeZero.instAlgebra` ## Tags internally graded ring -/ open DirectSum variable {ι : Type*} {σ S R : Type*} theorem SetLike.algebraMap_mem_graded [Zero ι] [CommSemiring S] [Semiring R] [Algebra S R] (A : ι → Submodule S R) [SetLike.GradedOne A] (s : S) : algebraMap S R s ∈ A 0 := by rw [Algebra.algebraMap_eq_smul_one] exact (A 0).smul_mem s <| SetLike.one_mem_graded _ theorem SetLike.natCast_mem_graded [Zero ι] [AddMonoidWithOne R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ) [SetLike.GradedOne A] (n : ℕ) : (n : R) ∈ A 0 := by induction n with | zero => rw [Nat.cast_zero] exact zero_mem (A 0) | succ _ n_ih => rw [Nat.cast_succ] exact add_mem n_ih (SetLike.one_mem_graded _) theorem SetLike.intCast_mem_graded [Zero ι] [AddGroupWithOne R] [SetLike σ R] [AddSubgroupClass σ R] (A : ι → σ) [SetLike.GradedOne A] (z : ℤ) : (z : R) ∈ A 0 := by cases z · rw [Int.ofNat_eq_coe, Int.cast_natCast] exact SetLike.natCast_mem_graded _ _ · rw [Int.cast_negSucc] exact neg_mem (SetLike.natCast_mem_graded _ _) section DirectSum variable [DecidableEq ι] /-! #### From `AddSubmonoid`s and `AddSubgroup`s -/ namespace SetLike /-- Build a `DirectSum.GNonUnitalNonAssocSemiring` instance for a collection of additive submonoids. -/ instance gnonUnitalNonAssocSemiring [Add ι] [NonUnitalNonAssocSemiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ) [SetLike.GradedMul A] : DirectSum.GNonUnitalNonAssocSemiring fun i => A i := { SetLike.gMul A with mul_zero := fun _ => Subtype.ext (mul_zero _) zero_mul := fun _ => Subtype.ext (zero_mul _) mul_add := fun _ _ _ => Subtype.ext (mul_add _ _ _) add_mul := fun _ _ _ => Subtype.ext (add_mul _ _ _) } /-- Build a `DirectSum.GSemiring` instance for a collection of additive submonoids. -/ instance gsemiring [AddMonoid ι] [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ) [SetLike.GradedMonoid A] : DirectSum.GSemiring fun i => A i := { SetLike.gMonoid A with mul_zero := fun _ => Subtype.ext (mul_zero _) zero_mul := fun _ => Subtype.ext (zero_mul _) mul_add := fun _ _ _ => Subtype.ext (mul_add _ _ _) add_mul := fun _ _ _ => Subtype.ext (add_mul _ _ _) natCast := fun n => ⟨n, SetLike.natCast_mem_graded _ _⟩ natCast_zero := Subtype.ext Nat.cast_zero natCast_succ := fun n => Subtype.ext (Nat.cast_succ n) } /-- Build a `DirectSum.GCommSemiring` instance for a collection of additive submonoids. -/ instance gcommSemiring [AddCommMonoid ι] [CommSemiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ) [SetLike.GradedMonoid A] : DirectSum.GCommSemiring fun i => A i := { SetLike.gCommMonoid A, SetLike.gsemiring A with } /-- Build a `DirectSum.GRing` instance for a collection of additive subgroups. -/ instance gring [AddMonoid ι] [Ring R] [SetLike σ R] [AddSubgroupClass σ R] (A : ι → σ) [SetLike.GradedMonoid A] : DirectSum.GRing fun i => A i := { SetLike.gsemiring A with intCast := fun z => ⟨z, SetLike.intCast_mem_graded _ _⟩ intCast_ofNat := fun _n => Subtype.ext <| Int.cast_natCast _ intCast_negSucc_ofNat := fun n => Subtype.ext <| Int.cast_negSucc n } /-- Build a `DirectSum.GCommRing` instance for a collection of additive submonoids. -/ instance gcommRing [AddCommMonoid ι] [CommRing R] [SetLike σ R] [AddSubgroupClass σ R] (A : ι → σ) [SetLike.GradedMonoid A] : DirectSum.GCommRing fun i => A i := { SetLike.gCommMonoid A, SetLike.gring A with } end SetLike namespace DirectSum section coe variable [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ) /-- The canonical ring isomorphism between `⨁ i, A i` and `R` -/ def coeRingHom [AddMonoid ι] [SetLike.GradedMonoid A] : (⨁ i, A i) →+* R := DirectSum.toSemiring (fun i => AddSubmonoidClass.subtype (A i)) rfl fun _ _ => rfl /-- The canonical ring isomorphism between `⨁ i, A i` and `R` -/ @[simp] theorem coeRingHom_of [AddMonoid ι] [SetLike.GradedMonoid A] (i : ι) (x : A i) : (coeRingHom A : _ →+* R) (of (fun i => A i) i x) = x := DirectSum.toSemiring_of _ _ _ _ _ theorem coe_mul_apply [AddMonoid ι] [SetLike.GradedMonoid A] [∀ (i : ι) (x : A i), Decidable (x ≠ 0)] (r r' : ⨁ i, A i) (n : ι) : ((r * r') n : R) = ∑ ij ∈ r.support ×ˢ r'.support with ij.1 + ij.2 = n, (r ij.1 * r' ij.2 : R) := by rw [mul_eq_sum_support_ghas_mul, DFinsupp.finset_sum_apply, AddSubmonoidClass.coe_finset_sum] simp_rw [coe_of_apply, apply_ite, ZeroMemClass.coe_zero, ← Finset.sum_filter, SetLike.coe_gMul] theorem coe_mul_apply_eq_dfinsuppSum [AddMonoid ι] [SetLike.GradedMonoid A] [∀ (i : ι) (x : A i), Decidable (x ≠ 0)] (r r' : ⨁ i, A i) (n : ι) : ((r * r') n : R) = r.sum fun i ri => r'.sum fun j rj => if i + j = n then (ri * rj : R) else 0 := by rw [mul_eq_dfinsuppSum] iterate 2 rw [DFinsupp.sum_apply, DFinsupp.sum, AddSubmonoidClass.coe_finset_sum]; congr; ext dsimp only split_ifs with h · subst h rw [of_eq_same] rfl · rw [of_eq_of_ne _ _ _ h] rfl @[deprecated (since := "2025-04-06")] alias coe_mul_apply_eq_dfinsupp_sum := coe_mul_apply_eq_dfinsuppSum open Finset in theorem coe_mul_apply_eq_sum_antidiagonal [AddMonoid ι] [HasAntidiagonal ι] [SetLike.GradedMonoid A] (r r' : ⨁ i, A i) (n : ι) : (r * r') n = ∑ ij ∈ antidiagonal n, (r ij.1 : R) * r' ij.2 := by classical rw [coe_mul_apply] apply Finset.sum_subset (fun _ ↦ by simp) aesop (erase simp not_and) (add simp not_and_or) theorem coe_of_mul_apply_aux [AddMonoid ι] [SetLike.GradedMonoid A] {i : ι} (r : A i) (r' : ⨁ i, A i) {j n : ι} (H : ∀ x : ι, i + x = n ↔ x = j) : ((of (fun i => A i) i r * r') n : R) = r * r' j := by classical rw [coe_mul_apply_eq_dfinsuppSum] apply (DFinsupp.sum_single_index _).trans swap · simp_rw [ZeroMemClass.coe_zero, zero_mul, ite_self] exact DFinsupp.sum_zero simp_rw [DFinsupp.sum, H, Finset.sum_ite_eq'] split_ifs with h · rfl rw [DFinsupp.notMem_support_iff.mp h, ZeroMemClass.coe_zero, mul_zero] theorem coe_mul_of_apply_aux [AddMonoid ι] [SetLike.GradedMonoid A] (r : ⨁ i, A i) {i : ι} (r' : A i) {j n : ι} (H : ∀ x : ι, x + i = n ↔ x = j) : ((r * of (fun i => A i) i r') n : R) = r j * r' := by classical rw [coe_mul_apply_eq_dfinsuppSum, DFinsupp.sum_comm] apply (DFinsupp.sum_single_index _).trans swap · simp_rw [ZeroMemClass.coe_zero, mul_zero, ite_self] exact DFinsupp.sum_zero simp_rw [DFinsupp.sum, H, Finset.sum_ite_eq'] split_ifs with h · rfl rw [DFinsupp.notMem_support_iff.mp h, ZeroMemClass.coe_zero, zero_mul] theorem coe_of_mul_apply_add [AddLeftCancelMonoid ι] [SetLike.GradedMonoid A] {i : ι} (r : A i) (r' : ⨁ i, A i) (j : ι) : ((of (fun i => A i) i r * r') (i + j) : R) = r * r' j := coe_of_mul_apply_aux _ _ _ fun _x => ⟨fun h => add_left_cancel h, fun h => h ▸ rfl⟩ theorem coe_mul_of_apply_add [AddRightCancelMonoid ι] [SetLike.GradedMonoid A] (r : ⨁ i, A i) {i : ι} (r' : A i) (j : ι) : ((r * of (fun i => A i) i r') (j + i) : R) = r j * r' := coe_mul_of_apply_aux _ _ _ fun _x => ⟨fun h => add_right_cancel h, fun h => h ▸ rfl⟩ theorem coe_of_mul_apply_of_mem_zero [AddMonoid ι] [SetLike.GradedMonoid A] (r : A 0) (r' : ⨁ i, A i) (j : ι) : ((of (fun i => A i) 0 r * r') j : R) = r * r' j := coe_of_mul_apply_aux _ _ _ fun _x => by rw [zero_add] theorem coe_mul_of_apply_of_mem_zero [AddMonoid ι] [SetLike.GradedMonoid A] (r : ⨁ i, A i) (r' : A 0) (j : ι) : ((r * of (fun i => A i) 0 r') j : R) = r j * r' := coe_mul_of_apply_aux _ _ _ fun _x => by rw [add_zero] end coe section CanonicallyOrderedAddCommMonoid variable [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ) variable [AddCommMonoid ι] [PartialOrder ι] [CanonicallyOrderedAdd ι] [SetLike.GradedMonoid A] theorem coe_of_mul_apply_of_not_le {i : ι} (r : A i) (r' : ⨁ i, A i) (n : ι) (h : ¬i ≤ n) : ((of (fun i => A i) i r * r') n : R) = 0 := by classical rw [coe_mul_apply_eq_dfinsuppSum] apply (DFinsupp.sum_single_index _).trans swap · simp_rw [ZeroMemClass.coe_zero, zero_mul, ite_self] exact DFinsupp.sum_zero · rw [DFinsupp.sum, Finset.sum_ite_of_false, Finset.sum_const_zero] exact fun x _ H => h ((self_le_add_right i x).trans_eq H) theorem coe_mul_of_apply_of_not_le (r : ⨁ i, A i) {i : ι} (r' : A i) (n : ι) (h : ¬i ≤ n) : ((r * of (fun i => A i) i r') n : R) = 0 := by classical rw [coe_mul_apply_eq_dfinsuppSum, DFinsupp.sum_comm] apply (DFinsupp.sum_single_index _).trans swap · simp_rw [ZeroMemClass.coe_zero, mul_zero, ite_self] exact DFinsupp.sum_zero · rw [DFinsupp.sum, Finset.sum_ite_of_false, Finset.sum_const_zero] exact fun x _ H => h ((self_le_add_left i x).trans_eq H) variable [Sub ι] [OrderedSub ι] [AddLeftReflectLE ι] /- The following two lemmas only require the same hypotheses as `eq_tsub_iff_add_eq_of_le`, but we state them for the above typeclasses for convenience. -/ theorem coe_mul_of_apply_of_le (r : ⨁ i, A i) {i : ι} (r' : A i) (n : ι) (h : i ≤ n) : ((r * of (fun i => A i) i r') n : R) = r (n - i) * r' := coe_mul_of_apply_aux _ _ _ fun _x => (eq_tsub_iff_add_eq_of_le h).symm theorem coe_of_mul_apply_of_le {i : ι} (r : A i) (r' : ⨁ i, A i) (n : ι) (h : i ≤ n) : ((of (fun i => A i) i r * r') n : R) = r * r' (n - i) := coe_of_mul_apply_aux _ _ _ fun x => by rw [eq_tsub_iff_add_eq_of_le h, add_comm] theorem coe_mul_of_apply (r : ⨁ i, A i) {i : ι} (r' : A i) (n : ι) [Decidable (i ≤ n)] : ((r * of (fun i => A i) i r') n : R) = if i ≤ n then (r (n - i) : R) * r' else 0 := by split_ifs with h exacts [coe_mul_of_apply_of_le _ _ _ n h, coe_mul_of_apply_of_not_le _ _ _ n h] theorem coe_of_mul_apply {i : ι} (r : A i) (r' : ⨁ i, A i) (n : ι) [Decidable (i ≤ n)] : ((of (fun i => A i) i r * r') n : R) = if i ≤ n then (r * r' (n - i) : R) else 0 := by split_ifs with h exacts [coe_of_mul_apply_of_le _ _ _ n h, coe_of_mul_apply_of_not_le _ _ _ n h] end CanonicallyOrderedAddCommMonoid end DirectSum /-! #### From `Submodule`s -/ namespace Submodule /-- Build a `DirectSum.GAlgebra` instance for a collection of `Submodule`s. -/ instance galgebra [AddMonoid ι] [CommSemiring S] [Semiring R] [Algebra S R] (A : ι → Submodule S R) [SetLike.GradedMonoid A] : DirectSum.GAlgebra S fun i => A i where toFun := ((Algebra.linearMap S R).codRestrict (A 0) <| SetLike.algebraMap_mem_graded A).toAddMonoidHom map_one := Subtype.ext <| (algebraMap S R).map_one map_mul _x _y := Sigma.subtype_ext (add_zero 0).symm <| (algebraMap S R).map_mul _ _ commutes := fun _r ⟨i, _xi⟩ => Sigma.subtype_ext ((zero_add i).trans (add_zero i).symm) <| Algebra.commutes _ _ smul_def := fun _r ⟨i, _xi⟩ => Sigma.subtype_ext (zero_add i).symm <| Algebra.smul_def _ _ @[simp] theorem setLike.coe_galgebra_toFun {ι} [AddMonoid ι] [CommSemiring S] [Semiring R] [Algebra S R] (A : ι → Submodule S R) [SetLike.GradedMonoid A] (s : S) : (DirectSum.GAlgebra.toFun (A := fun i => A i) s) = (algebraMap S R s : R) := rfl /-- A direct sum of powers of a submodule of an algebra has a multiplicative structure. -/ instance nat_power_gradedMonoid [CommSemiring S] [Semiring R] [Algebra S R] (p : Submodule S R) : SetLike.GradedMonoid fun i : ℕ => p ^ i where one_mem := by rw [← one_le, pow_zero] mul_mem i j p q hp hq := by rw [pow_add] exact Submodule.mul_mem_mul hp hq end Submodule /-- The canonical algebra isomorphism between `⨁ i, A i` and `R`. -/ def DirectSum.coeAlgHom [AddMonoid ι] [CommSemiring S] [Semiring R] [Algebra S R] (A : ι → Submodule S R) [SetLike.GradedMonoid A] : (⨁ i, A i) →ₐ[S] R := DirectSum.toAlgebra S _ (fun i => (A i).subtype) rfl (fun _ _ => rfl) /-- The supremum of submodules that form a graded monoid is a subalgebra, and equal to the range of `DirectSum.coeAlgHom`. -/ theorem Submodule.iSup_eq_toSubmodule_range [AddMonoid ι] [CommSemiring S] [Semiring R] [Algebra S R] (A : ι → Submodule S R) [SetLike.GradedMonoid A] : ⨆ i, A i = Subalgebra.toSubmodule (DirectSum.coeAlgHom A).range := (Submodule.iSup_eq_range_dfinsupp_lsum A).trans <| SetLike.coe_injective rfl @[simp] theorem DirectSum.coeAlgHom_of [AddMonoid ι] [CommSemiring S] [Semiring R] [Algebra S R] (A : ι → Submodule S R) [SetLike.GradedMonoid A] (i : ι) (x : A i) : DirectSum.coeAlgHom A (DirectSum.of (fun i => A i) i x) = x := DirectSum.toSemiring_of _ (by rfl) (fun _ _ => (by rfl)) _ _ end DirectSum /-! ### Facts about grade zero -/ namespace SetLike.GradeZero section Semiring variable [Semiring R] [AddMonoid ι] [SetLike σ R] [AddSubmonoidClass σ R] variable (A : ι → σ) [SetLike.GradedMonoid A] /-- The subsemiring `A 0` of `R`. -/ def subsemiring : Subsemiring R where carrier := A 0 __ := submonoid A add_mem' := add_mem zero_mem' := zero_mem (A 0) -- TODO: it might be expensive to unify `A` in this instance in practice /-- The semiring `A 0` inherited from `R` in the presence of `SetLike.GradedMonoid A`. -/ instance instSemiring : Semiring (A 0) := (subsemiring A).toSemiring @[simp, norm_cast] theorem coe_natCast (n : ℕ) : (n : A 0) = (n : R) := rfl @[simp, norm_cast] theorem coe_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : A 0) = (ofNat(n) : R) := rfl end Semiring section CommSemiring variable [CommSemiring R] [AddMonoid ι] [SetLike σ R] [AddSubmonoidClass σ R] variable (A : ι → σ) [SetLike.GradedMonoid A] -- TODO: it might be expensive to unify `A` in this instance in practice /-- The commutative semiring `A 0` inherited from `R` in the presence of `SetLike.GradedMonoid A`. -/ instance instCommSemiring : CommSemiring (A 0) := (subsemiring A).toCommSemiring end CommSemiring section Ring variable [Ring R] [AddMonoid ι] [SetLike σ R] [AddSubgroupClass σ R] variable (A : ι → σ) [SetLike.GradedMonoid A] /-- The subring `A 0` of `R`. -/ def subring : Subring R where carrier := A 0 __ := subsemiring A neg_mem' := neg_mem -- TODO: it might be expensive to unify `A` in this instances in practice /-- The ring `A 0` inherited from `R` in the presence of `SetLike.GradedMonoid A`. -/ instance instRing : Ring (A 0) := (subring A).toRing theorem coe_intCast (z : ℤ) : (z : A 0) = (z : R) := rfl end Ring section CommRing variable [CommRing R] [AddCommMonoid ι] [SetLike σ R] [AddSubgroupClass σ R] variable (A : ι → σ) [SetLike.GradedMonoid A] -- TODO: it might be expensive to unify `A` in this instances in practice /-- The commutative ring `A 0` inherited from `R` in the presence of `SetLike.GradedMonoid A`. -/ instance instCommRing : CommRing (A 0) := (subring A).toCommRing end CommRing section Algebra variable [CommSemiring S] [Semiring R] [Algebra S R] [AddMonoid ι] variable (A : ι → Submodule S R) [SetLike.GradedMonoid A] /-- The subalgebra `A 0` of `R`. -/ def subalgebra : Subalgebra S R where carrier := A 0 __ := subsemiring A algebraMap_mem' := algebraMap_mem_graded A -- TODO: it might be expensive to unify `A` in this instances in practice /-- The `S`-algebra `A 0` inherited from `R` in the presence of `SetLike.GradedMonoid A`. -/ instance instAlgebra : Algebra S (A 0) := inferInstanceAs <| Algebra S (subalgebra A) @[simp, norm_cast] theorem coe_algebraMap (s : S) : ↑(algebraMap _ (A 0) s) = algebraMap _ R s := rfl end Algebra section variable [CommSemiring S] [CommSemiring R] [Algebra S R] [AddCommMonoid ι] variable (A : ι → Submodule S R) [SetLike.GradedMonoid A] instance : Algebra (A 0) R := (SetLike.GradeZero.subalgebra A).toAlgebra @[simp] lemma algebraMap_apply (x) : algebraMap (A 0) R x = x := rfl end end SetLike.GradeZero section HomogeneousElement theorem SetLike.homogeneous_zero_submodule [Zero ι] [Semiring S] [AddCommMonoid R] [Module S R] (A : ι → Submodule S R) : SetLike.IsHomogeneousElem A (0 : R) := ⟨0, Submodule.zero_mem _⟩ theorem SetLike.Homogeneous.smul [CommSemiring S] [Semiring R] [Algebra S R] {A : ι → Submodule S R} {s : S} {r : R} (hr : SetLike.IsHomogeneousElem A r) : SetLike.IsHomogeneousElem A (s • r) := let ⟨i, hi⟩ := hr ⟨i, Submodule.smul_mem _ _ hi⟩ end HomogeneousElement /-! ### Gradings by canonically linearly ordered additive monoids -/ section LinearOrderedAddCommMonoid variable [AddCommMonoid ι] [LinearOrder ι] [IsOrderedAddMonoid ι] [DecidableEq ι] section Semiring variable [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] variable {A : ι → σ} [SetLike.GradedMonoid A] theorem mul_apply_eq_zero {r r' : ⨁ i, A i} {m n : ι} (hr : ∀ i < m, r i = 0) (hr' : ∀ i < n, r' i = 0) ⦃k : ι⦄ (hk : k < m + n) : (r * r') k = 0 := by classical rw [Subtype.ext_iff, ZeroMemClass.coe_zero, coe_mul_apply] apply Finset.sum_eq_zero fun x hx ↦ ?_ obtain (hx | hx) : x.1 < m ∨ x.2 < n := by by_contra! h obtain ⟨hm, hn⟩ := h obtain rfl : x.1 + x.2 = k := by simp_all apply lt_irrefl (m + n) <| lt_of_le_of_lt (by gcongr) hk all_goals simp [hr, hr', hx] variable [CanonicallyOrderedAdd ι] /-- The difference with `DirectSum.listProd_apply_eq_zero` is that the indices at which the terms of the list are zero is allowed to vary. -/ theorem listProd_apply_eq_zero' {l : List ((⨁ i, A i) × ι)} (hl : ∀ xn ∈ l, ∀ k < xn.2, xn.1 k = 0) ⦃n : ι⦄ (hn : n < (l.map Prod.snd).sum) : (l.map Prod.fst).prod n = 0 := by induction l generalizing n with | nil => simp [(zero_le n).not_gt] at hn | cons head tail ih => simp only [List.mem_cons, forall_eq_or_imp, List.map_cons, List.sum_cons, List.prod_cons] at hl hn ⊢ exact mul_apply_eq_zero hl.1 (ih hl.2) hn theorem listProd_apply_eq_zero {l : List (⨁ i, A i)} {m : ι} (hl : ∀ x ∈ l, ∀ k < m, x k = 0) ⦃n : ι⦄ (hn : n < l.length • m) : l.prod n = 0 := by -- a proof which uses `DirectSum.listProd_apply_eq_zero'` is actually more work induction l generalizing n with | nil => simp [(zero_le n).not_gt] at hn | cons head tail ih => simp only [List.mem_cons, forall_eq_or_imp, List.length_cons, List.prod_cons] at hl hn ⊢ refine mul_apply_eq_zero hl.1 (ih hl.2) ?_ simpa [add_smul, add_comm m] using hn end Semiring variable [CanonicallyOrderedAdd ι] section CommSemiring variable [CommSemiring R] [SetLike σ R] [AddSubmonoidClass σ R] variable {A : ι → σ} [SetLike.GradedMonoid A] /-- The difference with `DirectSum.multisetProd_apply_eq_zero` is that the indices at which the terms of the multiset are zero is allowed to vary. -/ theorem multisetProd_apply_eq_zero' {s : Multiset ((⨁ i, A i) × ι)} (hs : ∀ xn ∈ s, ∀ k < xn.2, xn.1 k = 0) ⦃n : ι⦄ (hn : n < (s.map Prod.snd).sum) : (s.map Prod.fst).prod n = 0 := by have := listProd_apply_eq_zero' (l := s.toList) (by simpa using hs) (by simpa [← Multiset.sum_coe, ← Multiset.map_coe]) simpa [← Multiset.prod_coe, ← Multiset.map_coe] theorem multisetProd_apply_eq_zero {s : Multiset (⨁ i, A i)} {m : ι} (hs : ∀ x ∈ s, ∀ k < m, x k = 0) ⦃n : ι⦄ (hn : n < s.card • m) : s.prod n = 0 := by have := listProd_apply_eq_zero (l := s.toList) (by simpa using hs) (by simpa [← Multiset.sum_coe, ← Multiset.map_coe]) simpa [← Multiset.prod_coe, ← Multiset.map_coe] /-- The difference with `DirectSum.finsetProd_apply_eq_zero` is that the indices at which the terms of the multiset are zero is allowed to vary. -/ theorem finsetProd_apply_eq_zero' {s : Finset ((⨁ i, A i) × ι)} (hs : ∀ xn ∈ s, ∀ k < xn.2, xn.1 k = 0) ⦃n : ι⦄ (hn : n < ∑ xn ∈ s, xn.2) : (∏ xn ∈ s, xn.1) n = 0 := by simpa using listProd_apply_eq_zero' (l := s.toList) (by simpa using hs) (by simpa) theorem finsetProd_apply_eq_zero {s : Finset (⨁ i, A i)} {m : ι} (hs : ∀ x ∈ s, ∀ k < m, x k = 0) ⦃n : ι⦄ (hn : n < s.card • m) : (∏ x ∈ s, x) n = 0 := by simpa using listProd_apply_eq_zero (l := s.toList) (by simpa using hs) (by simpa) end CommSemiring end LinearOrderedAddCommMonoid
morphism.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq choice. From mathcomp Require Import fintype finfun bigop finset fingroup. (******************************************************************************) (* This file contains the definitions of: *) (* *) (* {morphism D >-> rT} == *) (* the structure type of functions that are group morphisms mapping a *) (* domain set D : {set aT} to a type rT; rT must have a finGroupType *) (* structure, and D is usually a group (most of the theory expects this). *) (* mfun == the coercion projecting {morphism D >-> rT} to aT -> rT *) (* *) (* Basic examples: *) (* idm D == the identity morphism with domain D, or more precisely *) (* the identity function, but with a canonical *) (* {morphism G -> gT} structure. *) (* trivm D == the trivial morphism with domain D. *) (* If f has a {morphism D >-> rT} structure *) (* 'dom f == D, the domain of f. *) (* f @* A == the image of A by f, where f is defined. *) (* := f @: (D :&: A) *) (* f @*^-1 R == the pre-image of R by f, where f is defined. *) (* := D :&: f @^-1: R *) (* 'ker f == the kernel of f. *) (* := f @*^-1 1 *) (* 'ker_G f == the kernel of f restricted to G. *) (* := G :&: 'ker f (this is a pure notation) *) (* 'injm f <=> f injective on D. *) (* <-> ker f \subset 1 (this is a pure notation) *) (* invm injf == the inverse morphism of f, with domain f @* D, when f *) (* is injective (injf : 'injm f). *) (* restrm f sDom == the restriction of f to a subset A of D, given *) (* (sDom : A \subset D); restrm f sDom is transparently *) (* identical to f; the restrmP and domP lemmas provide *) (* opaque restrictions. *) (* *) (* G \isog H <=> G and H are isomorphic as groups. *) (* H \homg G <=> H is a homomorphic image of G. *) (* isom G H f <=> f maps G isomorphically to H, provided D contains G. *) (* := f @: G^# == H^# *) (* *) (* If, moreover, g : {morphism G >-> gT} with G : {group aT}, *) (* factm sKer sDom == the (natural) factor morphism mapping f @* G to g @* G *) (* with sDom : G \subset D, sKer : 'ker f \subset 'ker g. *) (* ifactm injf g == the (natural) factor morphism mapping f @* G to g @* G *) (* when f is injective (injf : 'injm f); here g must *) (* denote an actual morphism structure, not its function *) (* projection. *) (* *) (* If g has a {morphism G >-> aT} structure for any G : {group gT}, then *) (* f \o g has a canonical {morphism g @*^-1 D >-> rT} structure. *) (* *) (* Finally, for an arbitrary function f : aT -> rT *) (* morphic D f <=> f preserves group multiplication in D, i.e., *) (* f (x * y) = (f x) * (f y) for all x, y in D. *) (* morphm fM == a function identical to f, but with a canonical *) (* {morphism D >-> rT} structure, given fM : morphic D f. *) (* misom D C f <=> f is a morphism that maps D isomorphically to C. *) (* := morphic D f && isom D C f *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Reserved Notation "x \isog y" (at level 70). Section MorphismStructure. Variables aT rT : finGroupType. Structure morphism (D : {set aT}) : Type := Morphism { mfun :> aT -> FinGroup.sort rT; _ : {in D &, {morph mfun : x y / x * y}} }. (* We give the 'lightest' possible specification to define morphisms: local *) (* congruence, in D, with the group law of aT. We then provide the properties *) (* for the 'textbook' notion of morphism, when the required structures are *) (* available (e.g. its domain is a group). *) Definition morphism_for D of phant rT := morphism D. Definition clone_morphism D f := let: Morphism _ fM := f return {type of @Morphism D for f} -> morphism_for D (Phant rT) in fun k => k fM. Variables (D A : {set aT}) (R : {set rT}) (x : aT) (y : rT) (f : aT -> rT). Variant morphim_spec : Prop := MorphimSpec z & z \in D & z \in A & y = f z. Lemma morphimP : reflect morphim_spec (y \in f @: (D :&: A)). Proof. apply: (iffP imsetP) => [] [z]; first by case/setIP; exists z. by exists z; first apply/setIP. Qed. Lemma morphpreP : reflect (x \in D /\ f x \in R) (x \in D :&: f @^-1: R). Proof. by rewrite !inE; apply: andP. Qed. End MorphismStructure. Notation "{ 'morphism' D >-> T }" := (morphism_for D (Phant T)) (format "{ 'morphism' D >-> T }") : type_scope. Notation "[ 'morphism' D 'of' f ]" := (@clone_morphism _ _ D _ (fun fM => @Morphism _ _ D f fM)) (format "[ 'morphism' D 'of' f ]") : form_scope. Notation "[ 'morphism' 'of' f ]" := (clone_morphism (@Morphism _ _ _ f)) (format "[ 'morphism' 'of' f ]") : form_scope. Arguments morphimP {aT rT D A y f}. Arguments morphpreP {aT rT D R x f}. (* Domain, image, preimage, kernel, using phantom types to infer the domain. *) Section MorphismOps1. Variables (aT rT : finGroupType) (D : {set aT}) (f : {morphism D >-> rT}). Lemma morphM : {in D &, {morph f : x y / x * y}}. Proof. by case f. Qed. Notation morPhantom := (phantom (aT -> rT)). Definition MorPhantom := Phantom (aT -> rT). Definition dom of morPhantom f := D. Definition morphim of morPhantom f := fun A => f @: (D :&: A). Definition morphpre of morPhantom f := fun R : {set rT} => D :&: f @^-1: R. Definition ker mph := morphpre mph 1. End MorphismOps1. Arguments morphim _ _ _%_g _ _ _%_g. Arguments morphpre _ _ _%_g _ _ _%_g. Notation "''dom' f" := (dom (MorPhantom f)) (at level 10, f at level 8, format "''dom' f") : group_scope. Notation "''ker' f" := (ker (MorPhantom f)) (at level 10, f at level 8, format "''ker' f") : group_scope. Notation "''ker_' H f" := (H :&: 'ker f) (at level 10, H at level 2, f at level 8, format "''ker_' H f") : group_scope. Notation "f @* A" := (morphim (MorPhantom f) A) (at level 24, format "f @* A") : group_scope. Notation "f @*^-1 R" := (morphpre (MorPhantom f) R) (at level 24, format "f @*^-1 R") : group_scope. Notation "''injm' f" := (pred_of_set ('ker f) \subset pred_of_set 1) (at level 10, f at level 8, format "''injm' f") : group_scope. Section MorphismTheory. Variables aT rT : finGroupType. Implicit Types A B : {set aT}. Implicit Types G H : {group aT}. Implicit Types R S : {set rT}. Implicit Types M : {group rT}. (* Most properties of morphims hold only when the domain is a group. *) Variables (D : {group aT}) (f : {morphism D >-> rT}). Lemma morph1 : f 1 = 1. Proof. by apply: (mulgI (f 1)); rewrite -morphM ?mulg1. Qed. Lemma morph_prod I r (P : pred I) F : (forall i, P i -> F i \in D) -> f (\prod_(i <- r | P i) F i) = \prod_( i <- r | P i) f (F i). Proof. move=> D_F; elim/(big_load (fun x => x \in D)): _. elim/big_rec2: _ => [|i _ x Pi [Dx <-]]; first by rewrite morph1. by rewrite groupM ?morphM // D_F. Qed. Lemma morphV : {in D, {morph f : x / x^-1}}. Proof. move=> x Dx; apply: (mulgI (f x)). by rewrite -morphM ?groupV // !mulgV morph1. Qed. Lemma morphJ : {in D &, {morph f : x y / x ^ y}}. Proof. by move=> * /=; rewrite !morphM ?morphV // ?groupM ?groupV. Qed. Lemma morphX n : {in D, {morph f : x / x ^+ n}}. Proof. by elim: n => [|n IHn] x Dx; rewrite ?morph1 // !expgS morphM ?(groupX, IHn). Qed. Lemma morphR : {in D &, {morph f : x y / [~ x, y]}}. Proof. by move=> * /=; rewrite morphM ?(groupV, groupJ) // morphJ ?morphV. Qed. (* Morphic image, preimage properties w.r.t. set-theoretic operations. *) Lemma morphimE A : f @* A = f @: (D :&: A). Proof. by []. Qed. Lemma morphpreE R : f @*^-1 R = D :&: f @^-1: R. Proof. by []. Qed. Lemma kerE : 'ker f = f @*^-1 1. Proof. by []. Qed. Lemma morphimEsub A : A \subset D -> f @* A = f @: A. Proof. by move=> sAD; rewrite /morphim (setIidPr sAD). Qed. Lemma morphimEdom : f @* D = f @: D. Proof. exact: morphimEsub. Qed. Lemma morphimIdom A : f @* (D :&: A) = f @* A. Proof. by rewrite /morphim setIA setIid. Qed. Lemma morphpreIdom R : D :&: f @*^-1 R = f @*^-1 R. Proof. by rewrite /morphim setIA setIid. Qed. Lemma morphpreIim R : f @*^-1 (f @* D :&: R) = f @*^-1 R. Proof. apply/setP=> x; rewrite morphimEdom !inE. by case Dx: (x \in D); rewrite // imset_f. Qed. Lemma morphimIim A : f @* D :&: f @* A = f @* A. Proof. by apply/setIidPr; rewrite imsetS // setIid subsetIl. Qed. Lemma mem_morphim A x : x \in D -> x \in A -> f x \in f @* A. Proof. by move=> Dx Ax; apply/morphimP; exists x. Qed. Lemma mem_morphpre R x : x \in D -> f x \in R -> x \in f @*^-1 R. Proof. by move=> Dx Rfx; apply/morphpreP. Qed. Lemma morphimS A B : A \subset B -> f @* A \subset f @* B. Proof. by move=> sAB; rewrite imsetS ?setIS. Qed. Lemma morphim_sub A : f @* A \subset f @* D. Proof. by rewrite imsetS // setIid subsetIl. Qed. Lemma leq_morphim A : #|f @* A| <= #|A|. Proof. by apply: (leq_trans (leq_imset_card _ _)); rewrite subset_leq_card ?subsetIr. Qed. Lemma morphpreS R S : R \subset S -> f @*^-1 R \subset f @*^-1 S. Proof. by move=> sRS; rewrite setIS ?preimsetS. Qed. Lemma morphpre_sub R : f @*^-1 R \subset D. Proof. exact: subsetIl. Qed. Lemma morphim_setIpre A R : f @* (A :&: f @*^-1 R) = f @* A :&: R. Proof. apply/setP=> fa; apply/morphimP/setIP=> [[a Da] | [/morphimP[a Da Aa ->] Rfa]]. by rewrite !inE Da /= => /andP[Aa Rfa] ->; rewrite mem_morphim. by exists a; rewrite // !inE Aa Da. Qed. Lemma morphim0 : f @* set0 = set0. Proof. by rewrite morphimE setI0 imset0. Qed. Lemma morphim_eq0 A : A \subset D -> (f @* A == set0) = (A == set0). Proof. by rewrite imset_eq0 => /setIidPr->. Qed. Lemma morphim_set1 x : x \in D -> f @* [set x] = [set f x]. Proof. by rewrite /morphim -sub1set => /setIidPr->; apply: imset_set1. Qed. Lemma morphim1 : f @* 1 = 1. Proof. by rewrite morphim_set1 ?morph1. Qed. Lemma morphimV A : f @* A^-1 = (f @* A)^-1. Proof. wlog suffices: A / f @* A^-1 \subset (f @* A)^-1. by move=> IH; apply/eqP; rewrite eqEsubset IH -invSg invgK -{1}(invgK A) IH. apply/subsetP=> _ /morphimP[x Dx Ax' ->]; rewrite !inE in Ax' *. by rewrite -morphV // imset_f // inE groupV Dx. Qed. Lemma morphpreV R : f @*^-1 R^-1 = (f @*^-1 R)^-1. Proof. apply/setP=> x; rewrite !inE groupV; case Dx: (x \in D) => //=. by rewrite morphV. Qed. Lemma morphimMl A B : A \subset D -> f @* (A * B) = f @* A * f @* B. Proof. move=> sAD; rewrite /morphim setIC -group_modl // (setIidPr sAD). apply/setP=> fxy; apply/idP/idP. case/imsetP=> _ /imset2P[x y Ax /setIP[Dy By] ->] ->{fxy}. by rewrite morphM // (subsetP sAD, imset2_f) // imset_f // inE By. case/imset2P=> _ _ /imsetP[x Ax ->] /morphimP[y Dy By ->] ->{fxy}. by rewrite -morphM // (subsetP sAD, imset_f) // mem_mulg // inE By. Qed. Lemma morphimMr A B : B \subset D -> f @* (A * B) = f @* A * f @* B. Proof. move=> sBD; apply: invg_inj. by rewrite invMg -!morphimV invMg morphimMl // -invGid invSg. Qed. Lemma morphpreMl R S : R \subset f @* D -> f @*^-1 (R * S) = f @*^-1 R * f @*^-1 S. Proof. move=> sRfD; apply/setP=> x; rewrite !inE. apply/andP/imset2P=> [[Dx] | [y z]]; last first. rewrite !inE => /andP[Dy Rfy] /andP[Dz Rfz] ->. by rewrite ?(groupM, morphM, imset2_f). case/imset2P=> fy fz Rfy Rfz def_fx. have /morphimP[y Dy _ def_fy]: fy \in f @* D := subsetP sRfD fy Rfy. exists y (y^-1 * x); last by rewrite mulKVg. by rewrite !inE Dy -def_fy. by rewrite !inE groupM ?(morphM, morphV, groupV) // def_fx -def_fy mulKg. Qed. Lemma morphimJ A x : x \in D -> f @* (A :^ x) = f @* A :^ f x. Proof. move=> Dx; rewrite !conjsgE morphimMl ?(morphimMr, sub1set, groupV) //. by rewrite !(morphim_set1, groupV, morphV). Qed. Lemma morphpreJ R x : x \in D -> f @*^-1 (R :^ f x) = f @*^-1 R :^ x. Proof. move=> Dx; apply/setP=> y; rewrite conjIg !inE conjGid // !mem_conjg inE. by case Dy: (y \in D); rewrite // morphJ ?(morphV, groupV). Qed. Lemma morphim_class x A : x \in D -> A \subset D -> f @* (x ^: A) = f x ^: f @* A. Proof. move=> Dx sAD; rewrite !morphimEsub ?class_subG // /class -!imset_comp. by apply: eq_in_imset => y Ay /=; rewrite morphJ // (subsetP sAD). Qed. Lemma classes_morphim A : A \subset D -> classes (f @* A) = [set f @* xA | xA in classes A]. Proof. move=> sAD; rewrite morphimEsub // /classes -!imset_comp. apply: eq_in_imset => x /(subsetP sAD) Dx /=. by rewrite morphim_class ?morphimEsub. Qed. Lemma morphimT : f @* setT = f @* D. Proof. by rewrite -morphimIdom setIT. Qed. Lemma morphimU A B : f @* (A :|: B) = f @* A :|: f @* B. Proof. by rewrite -imsetU -setIUr. Qed. Lemma morphimI A B : f @* (A :&: B) \subset f @* A :&: f @* B. Proof. by rewrite subsetI // ?morphimS ?(subsetIl, subsetIr). Qed. Lemma morphpre0 : f @*^-1 set0 = set0. Proof. by rewrite morphpreE preimset0 setI0. Qed. Lemma morphpreT : f @*^-1 setT = D. Proof. by rewrite morphpreE preimsetT setIT. Qed. Lemma morphpreU R S : f @*^-1 (R :|: S) = f @*^-1 R :|: f @*^-1 S. Proof. by rewrite -setIUr -preimsetU. Qed. Lemma morphpreI R S : f @*^-1 (R :&: S) = f @*^-1 R :&: f @*^-1 S. Proof. by rewrite -setIIr -preimsetI. Qed. Lemma morphpreD R S : f @*^-1 (R :\: S) = f @*^-1 R :\: f @*^-1 S. Proof. by apply/setP=> x /[!inE]; case: (x \in D). Qed. (* kernel, domain properties *) Lemma kerP x : x \in D -> reflect (f x = 1) (x \in 'ker f). Proof. by move=> Dx; rewrite 2!inE Dx; apply: set1P. Qed. Lemma dom_ker : {subset 'ker f <= D}. Proof. by move=> x /morphpreP[]. Qed. Lemma mker x : x \in 'ker f -> f x = 1. Proof. by move=> Kx; apply/kerP=> //; apply: dom_ker. Qed. Lemma mkerl x y : x \in 'ker f -> y \in D -> f (x * y) = f y. Proof. by move=> Kx Dy; rewrite morphM // ?(dom_ker, mker Kx, mul1g). Qed. Lemma mkerr x y : x \in D -> y \in 'ker f -> f (x * y) = f x. Proof. by move=> Dx Ky; rewrite morphM // ?(dom_ker, mker Ky, mulg1). Qed. Lemma rcoset_kerP x y : x \in D -> y \in D -> reflect (f x = f y) (x \in 'ker f :* y). Proof. move=> Dx Dy; rewrite mem_rcoset !inE groupM ?morphM ?groupV //=. by rewrite morphV // -eq_mulgV1; apply: eqP. Qed. Lemma ker_rcoset x y : x \in D -> y \in D -> f x = f y -> exists2 z, z \in 'ker f & x = z * y. Proof. by move=> Dx Dy eqfxy; apply/rcosetP; apply/rcoset_kerP. Qed. Lemma ker_norm : D \subset 'N('ker f). Proof. apply/subsetP=> x Dx /[1!inE]; apply/subsetP=> _ /imsetP[y Ky ->]. by rewrite !inE groupJ ?morphJ // ?dom_ker //= mker ?conj1g. Qed. Lemma ker_normal : 'ker f <| D. Proof. by rewrite /(_ <| D) subsetIl ker_norm. Qed. Lemma morphimGI G A : 'ker f \subset G -> f @* (G :&: A) = f @* G :&: f @* A. Proof. move=> sKG; apply/eqP; rewrite eqEsubset morphimI setIC. apply/subsetP=> _ /setIP[/morphimP[x Dx Ax ->] /morphimP[z Dz Gz]]. case/ker_rcoset=> {Dz}// y Ky def_x. have{z Gz y Ky def_x} Gx: x \in G by rewrite def_x groupMl // (subsetP sKG). by rewrite imset_f ?inE // Dx Gx Ax. Qed. Lemma morphimIG A G : 'ker f \subset G -> f @* (A :&: G) = f @* A :&: f @* G. Proof. by move=> sKG; rewrite setIC morphimGI // setIC. Qed. Lemma morphimD A B : f @* A :\: f @* B \subset f @* (A :\: B). Proof. rewrite subDset -morphimU morphimS //. by rewrite setDE setUIr setUCr setIT subsetUr. Qed. Lemma morphimDG A G : 'ker f \subset G -> f @* (A :\: G) = f @* A :\: f @* G. Proof. move=> sKG; apply/eqP; rewrite eqEsubset morphimD andbT !setDE subsetI. rewrite morphimS ?subsetIl // -[~: f @* G]setU0 -subDset setDE setCK. by rewrite -morphimIG //= setIAC -setIA setICr setI0 morphim0. Qed. Lemma morphimD1 A : (f @* A)^# \subset f @* A^#. Proof. by rewrite -!set1gE -morphim1 morphimD. Qed. (* group structure preservation *) Lemma morphpre_groupset M : group_set (f @*^-1 M). Proof. apply/group_setP; split=> [|x y]; rewrite !inE ?(morph1, group1) //. by case/andP=> Dx Mfx /andP[Dy Mfy]; rewrite morphM ?groupM. Qed. Lemma morphim_groupset G : group_set (f @* G). Proof. apply/group_setP; split=> [|_ _ /morphimP[x Dx Gx ->] /morphimP[y Dy Gy ->]]. by rewrite -morph1 imset_f ?group1. by rewrite -morphM ?imset_f ?inE ?groupM. Qed. Canonical morphpre_group fPh M := @group _ (morphpre fPh M) (morphpre_groupset M). Canonical morphim_group fPh G := @group _ (morphim fPh G) (morphim_groupset G). Canonical ker_group fPh : {group aT} := Eval hnf in [group of ker fPh]. Lemma morph_dom_groupset : group_set (f @: D). Proof. by rewrite -morphimEdom groupP. Qed. Canonical morph_dom_group := group morph_dom_groupset. Lemma morphpreMr R S : S \subset f @* D -> f @*^-1 (R * S) = f @*^-1 R * f @*^-1 S. Proof. move=> sSfD; apply: invg_inj. by rewrite invMg -!morphpreV invMg morphpreMl // -invSg invgK invGid. Qed. Lemma morphimK A : A \subset D -> f @*^-1 (f @* A) = 'ker f * A. Proof. move=> sAD; apply/setP=> x; rewrite !inE. apply/idP/idP=> [/andP[Dx /morphimP[y Dy Ay eqxy]] | /imset2P[z y Kz Ay ->{x}]]. rewrite -(mulgKV y x) mem_mulg // !inE !(groupM, morphM, groupV) //. by rewrite morphV //= eqxy mulgV. have [Dy Dz]: y \in D /\ z \in D by rewrite (subsetP sAD) // dom_ker. by rewrite groupM // morphM // mker // mul1g imset_f // inE Dy. Qed. Lemma morphimGK G : 'ker f \subset G -> G \subset D -> f @*^-1 (f @* G) = G. Proof. by move=> sKG sGD; rewrite morphimK // mulSGid. Qed. Lemma morphpre_set1 x : x \in D -> f @*^-1 [set f x] = 'ker f :* x. Proof. by move=> Dx; rewrite -morphim_set1 // morphimK ?sub1set. Qed. Lemma morphpreK R : R \subset f @* D -> f @* (f @*^-1 R) = R. Proof. move=> sRfD; apply/setP=> y; apply/morphimP/idP=> [[x _] | Ry]. by rewrite !inE; case/andP=> _ Rfx ->. have /morphimP[x Dx _ defy]: y \in f @* D := subsetP sRfD y Ry. by exists x; rewrite // !inE Dx -defy. Qed. Lemma morphim_ker : f @* 'ker f = 1. Proof. by rewrite morphpreK ?sub1G. Qed. Lemma ker_sub_pre M : 'ker f \subset f @*^-1 M. Proof. by rewrite morphpreS ?sub1G. Qed. Lemma ker_normal_pre M : 'ker f <| f @*^-1 M. Proof. by rewrite /normal ker_sub_pre subIset ?ker_norm. Qed. Lemma morphpreSK R S : R \subset f @* D -> (f @*^-1 R \subset f @*^-1 S) = (R \subset S). Proof. move=> sRfD; apply/idP/idP=> [sf'RS|]; last exact: morphpreS. suffices: R \subset f @* D :&: S by rewrite subsetI sRfD. rewrite -(morphpreK sRfD) -[_ :&: S]morphpreK (morphimS, subsetIl) //. by rewrite morphpreI morphimGK ?subsetIl // setIA setIid. Qed. Lemma sub_morphim_pre A R : A \subset D -> (f @* A \subset R) = (A \subset f @*^-1 R). Proof. move=> sAD; rewrite -morphpreSK (morphimS, morphimK) //. apply/idP/idP; first by apply: subset_trans; apply: mulG_subr. by move/(mulgS ('ker f)); rewrite -morphpreMl ?(sub1G, mul1g). Qed. Lemma morphpre_proper R S : R \subset f @* D -> S \subset f @* D -> (f @*^-1 R \proper f @*^-1 S) = (R \proper S). Proof. by move=> dQ dR; rewrite /proper !morphpreSK. Qed. Lemma sub_morphpre_im R G : 'ker f \subset G -> G \subset D -> R \subset f @* D -> (f @*^-1 R \subset G) = (R \subset f @* G). Proof. by symmetry; rewrite -morphpreSK ?morphimGK. Qed. Lemma ker_trivg_morphim A : (A \subset 'ker f) = (A \subset D) && (f @* A \subset [1]). Proof. case sAD: (A \subset D); first by rewrite sub_morphim_pre. by rewrite subsetI sAD. Qed. Lemma morphimSK A B : A \subset D -> (f @* A \subset f @* B) = (A \subset 'ker f * B). Proof. move=> sAD; transitivity (A \subset 'ker f * (D :&: B)). by rewrite -morphimK ?subsetIl // -sub_morphim_pre // /morphim setIA setIid. by rewrite setIC group_modl (subsetIl, subsetI) // andbC sAD. Qed. Lemma morphimSGK A G : A \subset D -> 'ker f \subset G -> (f @* A \subset f @* G) = (A \subset G). Proof. by move=> sGD skfK; rewrite morphimSK // mulSGid. Qed. Lemma ltn_morphim A : [1] \proper 'ker_A f -> #|f @* A| < #|A|. Proof. case/properP; rewrite sub1set => /setIP[A1 _] [x /setIP[Ax kx] x1]. rewrite (cardsD1 1 A) A1 ltnS -{1}(setD1K A1) morphimU morphim1. rewrite (setUidPr _) ?sub1set; last first. by rewrite -(mker kx) mem_morphim ?(dom_ker kx) // inE x1. by rewrite (leq_trans (leq_imset_card _ _)) ?subset_leq_card ?subsetIr. Qed. (* injectivity of image and preimage *) Lemma morphpre_inj : {in [pred R : {set rT} | R \subset f @* D] &, injective (fun R => f @*^-1 R)}. Proof. exact: can_in_inj morphpreK. Qed. Lemma morphim_injG : {in [pred G : {group aT} | 'ker f \subset G & G \subset D] &, injective (fun G => f @* G)}. Proof. move=> G H /andP[sKG sGD] /andP[sKH sHD] eqfGH. by apply: val_inj; rewrite /= -(morphimGK sKG sGD) eqfGH morphimGK. Qed. Lemma morphim_inj G H : ('ker f \subset G) && (G \subset D) -> ('ker f \subset H) && (H \subset D) -> f @* G = f @* H -> G :=: H. Proof. by move=> nsGf nsHf /morphim_injG->. Qed. (* commutation with generated groups and cycles *) Lemma morphim_gen A : A \subset D -> f @* <<A>> = <<f @* A>>. Proof. move=> sAD; apply/eqP. rewrite eqEsubset andbC gen_subG morphimS; last exact: subset_gen. by rewrite sub_morphim_pre gen_subG // -sub_morphim_pre // subset_gen. Qed. Lemma morphim_cycle x : x \in D -> f @* <[x]> = <[f x]>. Proof. by move=> Dx; rewrite morphim_gen (sub1set, morphim_set1). Qed. Lemma morphimY A B : A \subset D -> B \subset D -> f @* (A <*> B) = f @* A <*> f @* B. Proof. by move=> sAD sBD; rewrite morphim_gen ?morphimU // subUset sAD. Qed. Lemma morphpre_gen R : 1 \in R -> R \subset f @* D -> f @*^-1 <<R>> = <<f @*^-1 R>>. Proof. move=> R1 sRfD; apply/eqP. rewrite eqEsubset andbC gen_subG morphpreS; last exact: subset_gen. rewrite -{1}(morphpreK sRfD) -morphim_gen ?subsetIl // morphimGK //=. by rewrite sub_gen // setIS // preimsetS ?sub1set. by rewrite gen_subG subsetIl. Qed. (* commutator, normaliser, normal, center properties*) Lemma morphimR A B : A \subset D -> B \subset D -> f @* [~: A, B] = [~: f @* A, f @* B]. Proof. move/subsetP=> sAD /subsetP sBD. rewrite morphim_gen; last first; last congr <<_>>. by apply/subsetP=> _ /imset2P[x y Ax By ->]; rewrite groupR; auto. apply/setP=> fz; apply/morphimP/imset2P=> [[z _] | [fx fy]]. case/imset2P=> x y Ax By -> -> {z fz}. have Dx := sAD x Ax; have Dy := sBD y By. by exists (f x) (f y); rewrite ?(imset_f, morphR) // ?(inE, Dx, Dy). case/morphimP=> x Dx Ax ->{fx}; case/morphimP=> y Dy By ->{fy} -> {fz}. by exists [~ x, y]; rewrite ?(inE, morphR, groupR, imset2_f). Qed. Lemma morphim_norm A : f @* 'N(A) \subset 'N(f @* A). Proof. apply/subsetP=> fx; case/morphimP=> x Dx Nx -> {fx}. by rewrite inE -morphimJ ?(normP Nx). Qed. Lemma morphim_norms A B : A \subset 'N(B) -> f @* A \subset 'N(f @* B). Proof. by move=> nBA; apply: subset_trans (morphim_norm B); apply: morphimS. Qed. Lemma morphim_subnorm A B : f @* 'N_A(B) \subset 'N_(f @* A)(f @* B). Proof. exact: subset_trans (morphimI A _) (setIS _ (morphim_norm B)). Qed. Lemma morphim_normal A B : A <| B -> f @* A <| f @* B. Proof. by case/andP=> sAB nAB; rewrite /(_ <| _) morphimS // morphim_norms. Qed. Lemma morphim_cent1 x : x \in D -> f @* 'C[x] \subset 'C[f x]. Proof. by move=> Dx; rewrite -(morphim_set1 Dx) morphim_norm. Qed. Lemma morphim_cent1s A x : x \in D -> A \subset 'C[x] -> f @* A \subset 'C[f x]. Proof. by move=> Dx cAx; apply: subset_trans (morphim_cent1 Dx); apply: morphimS. Qed. Lemma morphim_subcent1 A x : x \in D -> f @* 'C_A[x] \subset 'C_(f @* A)[f x]. Proof. by move=> Dx; rewrite -(morphim_set1 Dx) morphim_subnorm. Qed. Lemma morphim_cent A : f @* 'C(A) \subset 'C(f @* A). Proof. apply/bigcapsP=> fx; case/morphimP=> x Dx Ax ->{fx}. by apply: subset_trans (morphim_cent1 Dx); apply: morphimS; apply: bigcap_inf. Qed. Lemma morphim_cents A B : A \subset 'C(B) -> f @* A \subset 'C(f @* B). Proof. by move=> cBA; apply: subset_trans (morphim_cent B); apply: morphimS. Qed. Lemma morphim_subcent A B : f @* 'C_A(B) \subset 'C_(f @* A)(f @* B). Proof. exact: subset_trans (morphimI A _) (setIS _ (morphim_cent B)). Qed. Lemma morphim_abelian A : abelian A -> abelian (f @* A). Proof. exact: morphim_cents. Qed. Lemma morphpre_norm R : f @*^-1 'N(R) \subset 'N(f @*^-1 R). Proof. by apply/subsetP=> x /[!inE] /andP[Dx Nfx]; rewrite -morphpreJ ?morphpreS. Qed. Lemma morphpre_norms R S : R \subset 'N(S) -> f @*^-1 R \subset 'N(f @*^-1 S). Proof. by move=> nSR; apply: subset_trans (morphpre_norm S); apply: morphpreS. Qed. Lemma morphpre_normal R S : R \subset f @* D -> S \subset f @* D -> (f @*^-1 R <| f @*^-1 S) = (R <| S). Proof. move=> sRfD sSfD; apply/idP/andP=> [|[sRS nSR]]. by move/morphim_normal; rewrite !morphpreK //; case/andP. by rewrite /(_ <| _) (subset_trans _ (morphpre_norm _)) morphpreS. Qed. Lemma morphpre_subnorm R S : f @*^-1 'N_R(S) \subset 'N_(f @*^-1 R)(f @*^-1 S). Proof. by rewrite morphpreI setIS ?morphpre_norm. Qed. Lemma morphim_normG G : 'ker f \subset G -> G \subset D -> f @* 'N(G) = 'N_(f @* D)(f @* G). Proof. move=> sKG sGD; apply/eqP; rewrite eqEsubset -{1}morphimIdom morphim_subnorm. rewrite -(morphpreK (subsetIl _ _)) morphimS //= morphpreI subIset // orbC. by rewrite -{2}(morphimGK sKG sGD) morphpre_norm. Qed. Lemma morphim_subnormG A G : 'ker f \subset G -> G \subset D -> f @* 'N_A(G) = 'N_(f @* A)(f @* G). Proof. move=> sKB sBD; rewrite morphimIG ?normsG // morphim_normG //. by rewrite setICA setIA morphimIim. Qed. Lemma morphpre_cent1 x : x \in D -> 'C_D[x] \subset f @*^-1 'C[f x]. Proof. move=> Dx; rewrite -sub_morphim_pre ?subsetIl //. by apply: subset_trans (morphim_cent1 Dx); rewrite morphimS ?subsetIr. Qed. Lemma morphpre_cent1s R x : x \in D -> R \subset f @* D -> f @*^-1 R \subset 'C[x] -> R \subset 'C[f x]. Proof. by move=> Dx sRfD; move/(morphim_cent1s Dx); rewrite morphpreK. Qed. Lemma morphpre_subcent1 R x : x \in D -> 'C_(f @*^-1 R)[x] \subset f @*^-1 'C_R[f x]. Proof. move=> Dx; rewrite -morphpreIdom -setIA setICA morphpreI setIS //. exact: morphpre_cent1. Qed. Lemma morphpre_cent A : 'C_D(A) \subset f @*^-1 'C(f @* A). Proof. rewrite -sub_morphim_pre ?subsetIl // morphimGI ?(subsetIl, subIset) // orbC. by rewrite (subset_trans (morphim_cent _)). Qed. Lemma morphpre_cents A R : R \subset f @* D -> f @*^-1 R \subset 'C(A) -> R \subset 'C(f @* A). Proof. by move=> sRfD; move/morphim_cents; rewrite morphpreK. Qed. Lemma morphpre_subcent R A : 'C_(f @*^-1 R)(A) \subset f @*^-1 'C_R(f @* A). Proof. by rewrite -morphpreIdom -setIA setICA morphpreI setIS //; apply: morphpre_cent. Qed. (* local injectivity properties *) Lemma injmP : reflect {in D &, injective f} ('injm f). Proof. apply: (iffP subsetP) => [injf x y Dx Dy | injf x /= Kx]. by case/ker_rcoset=> // z /injf/set1P->; rewrite mul1g. have Dx := dom_ker Kx; apply/set1P/injf => //. by apply/rcoset_kerP; rewrite // mulg1. Qed. Lemma card_im_injm : (#|f @* D| == #|D|) = 'injm f. Proof. by rewrite morphimEdom (sameP imset_injP injmP). Qed. Section Injective. Hypothesis injf : 'injm f. Lemma ker_injm : 'ker f = 1. Proof. exact/trivgP. Qed. Lemma injmK A : A \subset D -> f @*^-1 (f @* A) = A. Proof. by move=> sAD; rewrite morphimK // ker_injm // mul1g. Qed. Lemma injm_morphim_inj A B : A \subset D -> B \subset D -> f @* A = f @* B -> A = B. Proof. by move=> sAD sBD eqAB; rewrite -(injmK sAD) eqAB injmK. Qed. Lemma card_injm A : A \subset D -> #|f @* A| = #|A|. Proof. move=> sAD; rewrite morphimEsub // card_in_imset //. exact: (sub_in2 (subsetP sAD) (injmP injf)). Qed. Lemma order_injm x : x \in D -> #[f x] = #[x]. Proof. by move=> Dx; rewrite orderE -morphim_cycle // card_injm ?cycle_subG. Qed. Lemma injm1 x : x \in D -> f x = 1 -> x = 1. Proof. by move=> Dx; move/(kerP Dx); rewrite ker_injm; move/set1P. Qed. Lemma morph_injm_eq1 x : x \in D -> (f x == 1) = (x == 1). Proof. by move=> Dx; rewrite -morph1 (inj_in_eq (injmP injf)) ?group1. Qed. Lemma injmSK A B : A \subset D -> (f @* A \subset f @* B) = (A \subset B). Proof. by move=> sAD; rewrite morphimSK // ker_injm mul1g. Qed. Lemma sub_morphpre_injm R A : A \subset D -> R \subset f @* D -> (f @*^-1 R \subset A) = (R \subset f @* A). Proof. by move=> sAD sRfD; rewrite -morphpreSK ?injmK. Qed. Lemma injm_eq A B : A \subset D -> B \subset D -> (f @* A == f @* B) = (A == B). Proof. by move=> sAD sBD; rewrite !eqEsubset !injmSK. Qed. Lemma morphim_injm_eq1 A : A \subset D -> (f @* A == 1) = (A == 1). Proof. by move=> sAD; rewrite -morphim1 injm_eq ?sub1G. Qed. Lemma injmI A B : f @* (A :&: B) = f @* A :&: f @* B. Proof. rewrite -morphimIdom setIIr -4!(injmK (subsetIl D _), =^~ morphimIdom). by rewrite -morphpreI morphpreK // subIset ?morphim_sub. Qed. Lemma injmD1 A : f @* A^# = (f @* A)^#. Proof. by have:= morphimDG A injf; rewrite morphim1. Qed. Lemma nclasses_injm A : A \subset D -> #|classes (f @* A)| = #|classes A|. Proof. move=> sAD; rewrite classes_morphim // card_in_imset //. move=> _ _ /imsetP[x Ax ->] /imsetP[y Ay ->]. by apply: injm_morphim_inj; rewrite // class_subG ?(subsetP sAD). Qed. Lemma injm_norm A : A \subset D -> f @* 'N(A) = 'N_(f @* D)(f @* A). Proof. move=> sAD; apply/eqP; rewrite -morphimIdom eqEsubset morphim_subnorm. rewrite -sub_morphpre_injm ?subsetIl // morphpreI injmK // setIS //. by rewrite -{2}(injmK sAD) morphpre_norm. Qed. Lemma injm_norms A B : A \subset D -> B \subset D -> (f @* A \subset 'N(f @* B)) = (A \subset 'N(B)). Proof. by move=> sAD sBD; rewrite -injmSK // injm_norm // subsetI morphimS. Qed. Lemma injm_normal A B : A \subset D -> B \subset D -> (f @* A <| f @* B) = (A <| B). Proof. by move=> sAD sBD; rewrite /normal injmSK ?injm_norms. Qed. Lemma injm_subnorm A B : B \subset D -> f @* 'N_A(B) = 'N_(f @* A)(f @* B). Proof. by move=> sBD; rewrite injmI injm_norm // setICA setIA morphimIim. Qed. Lemma injm_cent1 x : x \in D -> f @* 'C[x] = 'C_(f @* D)[f x]. Proof. by move=> Dx; rewrite injm_norm ?morphim_set1 ?sub1set. Qed. Lemma injm_subcent1 A x : x \in D -> f @* 'C_A[x] = 'C_(f @* A)[f x]. Proof. by move=> Dx; rewrite injm_subnorm ?morphim_set1 ?sub1set. Qed. Lemma injm_cent A : A \subset D -> f @* 'C(A) = 'C_(f @* D)(f @* A). Proof. move=> sAD; apply/eqP; rewrite -morphimIdom eqEsubset morphim_subcent. apply/subsetP=> fx; case/setIP; case/morphimP=> x Dx _ ->{fx} cAfx. rewrite mem_morphim // inE Dx -sub1set centsC cent_set1 -injmSK //. by rewrite injm_cent1 // subsetI morphimS // -cent_set1 centsC sub1set. Qed. Lemma injm_cents A B : A \subset D -> B \subset D -> (f @* A \subset 'C(f @* B)) = (A \subset 'C(B)). Proof. by move=> sAD sBD; rewrite -injmSK // injm_cent // subsetI morphimS. Qed. Lemma injm_subcent A B : B \subset D -> f @* 'C_A(B) = 'C_(f @* A)(f @* B). Proof. by move=> sBD; rewrite injmI injm_cent // setICA setIA morphimIim. Qed. Lemma injm_abelian A : A \subset D -> abelian (f @* A) = abelian A. Proof. by move=> sAD; rewrite /abelian -subsetIidl -injm_subcent // injmSK ?subsetIidl. Qed. End Injective. Lemma eq_morphim (g : {morphism D >-> rT}): {in D, f =1 g} -> forall A, f @* A = g @* A. Proof. by move=> efg A; apply: eq_in_imset; apply: sub_in1 efg => x /setIP[]. Qed. Lemma eq_in_morphim B A (g : {morphism B >-> rT}) : D :&: A = B :&: A -> {in A, f =1 g} -> f @* A = g @* A. Proof. move=> eqDBA eqAfg; rewrite /morphim /= eqDBA. by apply: eq_in_imset => x /setIP[_]/eqAfg. Qed. End MorphismTheory. Notation "''ker' f" := (ker_group (MorPhantom f)) : Group_scope. Notation "''ker_' G f" := (G :&: 'ker f)%G : Group_scope. Notation "f @* G" := (morphim_group (MorPhantom f) G) : Group_scope. Notation "f @*^-1 M" := (morphpre_group (MorPhantom f) M) : Group_scope. Notation "f @: D" := (morph_dom_group f D) : Group_scope. Arguments injmP {aT rT D f}. Arguments morphpreK {aT rT D f} [R] sRf. Section IdentityMorphism. Variable gT : finGroupType. Implicit Types A B : {set gT}. Implicit Type G : {group gT}. Definition idm of {set gT} := fun x : gT => x : FinGroup.sort gT. Lemma idm_morphM A : {in A & , {morph idm A : x y / x * y}}. Proof. by []. Qed. Canonical idm_morphism A := Morphism (@idm_morphM A). Lemma injm_idm G : 'injm (idm G). Proof. by apply/injmP=> x y _ _. Qed. Lemma ker_idm G : 'ker (idm G) = 1. Proof. by apply/trivgP; apply: injm_idm. Qed. Lemma morphim_idm A B : B \subset A -> idm A @* B = B. Proof. rewrite /morphim /= /idm => /setIidPr->. by apply/setP=> x; apply/imsetP/idP=> [[y By ->]|Bx]; last exists x. Qed. Lemma morphpre_idm A B : idm A @*^-1 B = A :&: B. Proof. by apply/setP=> x; rewrite !inE. Qed. Lemma im_idm A : idm A @* A = A. Proof. exact: morphim_idm. Qed. End IdentityMorphism. Arguments idm {_} _%_g _%_g. Section RestrictedMorphism. Variables aT rT : finGroupType. Variables A D : {set aT}. Implicit Type B : {set aT}. Implicit Type R : {set rT}. Definition restrm of A \subset D := @id (aT -> FinGroup.sort rT). Section Props. Hypothesis sAD : A \subset D. Variable f : {morphism D >-> rT}. Local Notation fA := (restrm sAD (mfun f)). Canonical restrm_morphism := @Morphism aT rT A fA (sub_in2 (subsetP sAD) (morphM f)). Lemma morphim_restrm B : fA @* B = f @* (A :&: B). Proof. by rewrite {2}/morphim setIA (setIidPr sAD). Qed. Lemma restrmEsub B : B \subset A -> fA @* B = f @* B. Proof. by rewrite morphim_restrm => /setIidPr->. Qed. Lemma im_restrm : fA @* A = f @* A. Proof. exact: restrmEsub. Qed. Lemma morphpre_restrm R : fA @*^-1 R = A :&: f @*^-1 R. Proof. by rewrite setIA (setIidPl sAD). Qed. Lemma ker_restrm : 'ker fA = 'ker_A f. Proof. exact: morphpre_restrm. Qed. Lemma injm_restrm : 'injm f -> 'injm fA. Proof. by apply: subset_trans; rewrite ker_restrm subsetIr. Qed. End Props. Lemma restrmP (f : {morphism D >-> rT}) : A \subset 'dom f -> {g : {morphism A >-> rT} | [/\ g = f :> (aT -> rT), 'ker g = 'ker_A f, forall R, g @*^-1 R = A :&: f @*^-1 R & forall B, B \subset A -> g @* B = f @* B]}. Proof. move=> sAD; exists (restrm_morphism sAD f). split=> // [|R|B sBA]; first 1 [exact: ker_restrm | exact: morphpre_restrm]. by rewrite morphim_restrm (setIidPr sBA). Qed. Lemma domP (f : {morphism D >-> rT}) : 'dom f = A -> {g : {morphism A >-> rT} | [/\ g = f :> (aT -> rT), 'ker g = 'ker f, forall R, g @*^-1 R = f @*^-1 R & forall B, g @* B = f @* B]}. Proof. by move <-; exists f. Qed. End RestrictedMorphism. Arguments restrm {_ _ _%_g _%_g} _ _%_g. Arguments restrmP {aT rT A D}. Arguments domP {aT rT A D}. Section TrivMorphism. Variables aT rT : finGroupType. Definition trivm of {set aT} & aT := 1 : FinGroup.sort rT. Lemma trivm_morphM (A : {set aT}) : {in A &, {morph trivm A : x y / x * y}}. Proof. by move=> x y /=; rewrite mulg1. Qed. Canonical triv_morph A := Morphism (@trivm_morphM A). Lemma morphim_trivm (G H : {group aT}) : trivm G @* H = 1. Proof. apply/setP=> /= y; rewrite inE; apply/idP/eqP=> [|->]; first by case/morphimP. by apply/morphimP; exists (1 : aT); rewrite /= ?group1. Qed. Lemma ker_trivm (G : {group aT}) : 'ker (trivm G) = G. Proof. by apply/setIidPl/subsetP=> x _; rewrite !inE /=. Qed. End TrivMorphism. Arguments trivm {aT rT} _%_g _%_g. (* The composition of two morphisms is a Canonical morphism instance. *) Section MorphismComposition. Variables gT hT rT : finGroupType. Variables (G : {group gT}) (H : {group hT}). Variable f : {morphism G >-> hT}. Variable g : {morphism H >-> rT}. Local Notation gof := (mfun g \o mfun f). Lemma comp_morphM : {in f @*^-1 H &, {morph gof: x y / x * y}}. Proof. by move=> x y; rewrite /= !inE => /andP[? ?] /andP[? ?]; rewrite !morphM. Qed. Canonical comp_morphism := Morphism comp_morphM. Lemma ker_comp : 'ker gof = f @*^-1 'ker g. Proof. by apply/setP=> x; rewrite !inE andbA. Qed. Lemma injm_comp : 'injm f -> 'injm g -> 'injm gof. Proof. by move=> injf; rewrite ker_comp; move/trivgP=> ->. Qed. Lemma morphim_comp (A : {set gT}) : gof @* A = g @* (f @* A). Proof. apply/setP=> z; apply/morphimP/morphimP=> [[x]|[y Hy fAy ->{z}]]. rewrite !inE => /andP[Gx Hfx]; exists (f x) => //. by apply/morphimP; exists x. by case/morphimP: fAy Hy => x Gx Ax ->{y} Hfx; exists x; rewrite ?inE ?Gx. Qed. Lemma morphpre_comp (C : {set rT}) : gof @*^-1 C = f @*^-1 (g @*^-1 C). Proof. by apply/setP=> z; rewrite !inE andbA. Qed. End MorphismComposition. (* The factor morphism *) Section FactorMorphism. Variables aT qT rT : finGroupType. Variables G H : {group aT}. Variable f : {morphism G >-> rT}. Variable q : {morphism H >-> qT}. Definition factm of 'ker q \subset 'ker f & G \subset H := fun x => f (repr (q @*^-1 [set x])). Hypothesis sKqKf : 'ker q \subset 'ker f. Hypothesis sGH : G \subset H. Notation ff := (factm sKqKf sGH). Lemma factmE x : x \in G -> ff (q x) = f x. Proof. rewrite /ff => Gx; have Hx := subsetP sGH x Gx. have /mem_repr: x \in q @*^-1 [set q x] by rewrite !inE Hx /=. case/morphpreP; move: (repr _) => y Hy /set1P. by case/ker_rcoset=> // z Kz ->; rewrite mkerl ?(subsetP sKqKf). Qed. Lemma factm_morphM : {in q @* G &, {morph ff : x y / x * y}}. Proof. move=> _ _ /morphimP[x Hx Gx ->] /morphimP[y Hy Gy ->]. by rewrite -morphM ?factmE ?groupM // morphM. Qed. Canonical factm_morphism := Morphism factm_morphM. Lemma morphim_factm (A : {set aT}) : ff @* (q @* A) = f @* A. Proof. rewrite -morphim_comp /= {1}/morphim /= morphimGK //; last first. by rewrite (subset_trans sKqKf) ?subsetIl. apply/setP=> y; apply/morphimP/morphimP; by case=> x Gx Ax ->{y}; exists x; rewrite //= factmE. Qed. Lemma morphpre_factm (C : {set rT}) : ff @*^-1 C = q @* (f @*^-1 C). Proof. apply/setP=> y /[!inE]/=; apply/andP/morphimP=> [[]|[x Hx]]; last first. by case/morphpreP=> Gx Cfx ->; rewrite factmE ?imset_f ?inE ?Hx. case/morphimP=> x Hx Gx ->; rewrite factmE //. by exists x; rewrite // !inE Gx. Qed. Lemma ker_factm : 'ker ff = q @* 'ker f. Proof. exact: morphpre_factm. Qed. Lemma injm_factm : 'injm f -> 'injm ff. Proof. by rewrite ker_factm => /trivgP->; rewrite morphim1. Qed. Lemma injm_factmP : reflect ('ker f = 'ker q) ('injm ff). Proof. rewrite ker_factm -morphimIdom sub_morphim_pre ?subsetIl //. rewrite setIA (setIidPr sGH) (sameP setIidPr eqP) (setIidPl _) // eq_sym. exact: eqP. Qed. Lemma ker_factm_loc (K : {group aT}) : 'ker_(q @* K) ff = q @* 'ker_K f. Proof. by rewrite ker_factm -morphimIG. Qed. End FactorMorphism. Prenex Implicits factm. Section InverseMorphism. Variables aT rT : finGroupType. Implicit Types A B : {set aT}. Implicit Types C D : {set rT}. Variables (G : {group aT}) (f : {morphism G >-> rT}). Hypothesis injf : 'injm f. Lemma invm_subker : 'ker f \subset 'ker (idm G). Proof. by rewrite ker_idm. Qed. Definition invm := factm invm_subker (subxx _). Canonical invm_morphism := Eval hnf in [morphism of invm]. Lemma invmE : {in G, cancel f invm}. Proof. exact: factmE. Qed. Lemma invmK : {in f @* G, cancel invm f}. Proof. by move=> fx; case/morphimP=> x _ Gx ->; rewrite invmE. Qed. Lemma morphpre_invm A : invm @*^-1 A = f @* A. Proof. by rewrite morphpre_factm morphpre_idm morphimIdom. Qed. Lemma morphim_invm A : A \subset G -> invm @* (f @* A) = A. Proof. by move=> sAG; rewrite morphim_factm morphim_idm. Qed. Lemma morphim_invmE C : invm @* C = f @*^-1 C. Proof. rewrite -morphpreIdom -(morphim_invm (subsetIl _ _)). by rewrite morphimIdom -morphpreIim morphpreK (subsetIl, morphimIdom). Qed. Lemma injm_proper A B : A \subset G -> B \subset G -> (f @* A \proper f @* B) = (A \proper B). Proof. move=> dA dB; rewrite -morphpre_invm -(morphpre_invm B). by rewrite morphpre_proper ?morphim_invm. Qed. Lemma injm_invm : 'injm invm. Proof. by move/can_in_inj/injmP: invmK. Qed. Lemma ker_invm : 'ker invm = 1. Proof. by move/trivgP: injm_invm. Qed. Lemma im_invm : invm @* (f @* G) = G. Proof. exact: morphim_invm. Qed. End InverseMorphism. Prenex Implicits invm. Section InjFactm. Variables (gT aT rT : finGroupType) (D G : {group gT}). Variables (g : {morphism G >-> rT}) (f : {morphism D >-> aT}) (injf : 'injm f). Definition ifactm := tag (domP [morphism of g \o invm injf] (morphpre_invm injf G)). Lemma ifactmE : {in D, forall x, ifactm (f x) = g x}. Proof. rewrite /ifactm => x Dx; case: domP => f' /= [def_f' _ _ _]. by rewrite {f'}def_f' //= invmE. Qed. Lemma morphim_ifactm (A : {set gT}) : A \subset D -> ifactm @* (f @* A) = g @* A. Proof. rewrite /ifactm => sAD; case: domP => _ /= [_ _ _ ->]. by rewrite morphim_comp morphim_invm. Qed. Lemma im_ifactm : G \subset D -> ifactm @* (f @* G) = g @* G. Proof. exact: morphim_ifactm. Qed. Lemma morphpre_ifactm C : ifactm @*^-1 C = f @* (g @*^-1 C). Proof. rewrite /ifactm; case: domP => _ /= [_ _ -> _]. by rewrite morphpre_comp morphpre_invm. Qed. Lemma ker_ifactm : 'ker ifactm = f @* 'ker g. Proof. exact: morphpre_ifactm. Qed. Lemma injm_ifactm : 'injm g -> 'injm ifactm. Proof. by rewrite ker_ifactm => /trivgP->; rewrite morphim1. Qed. End InjFactm. (* Reflected (boolean) form of morphism and isomorphism properties. *) Section ReflectProp. Variables aT rT : finGroupType. Section Defs. Variables (A : {set aT}) (B : {set rT}). (* morphic is the morphM property of morphisms seen through morphicP. *) Definition morphic (f : aT -> rT) := [forall u in [predX A & A], f (u.1 * u.2) == f u.1 * f u.2]. Definition isom f := f @: A^# == B^#. Definition misom f := morphic f && isom f. Definition isog := [exists f : {ffun aT -> rT}, misom f]. Section MorphicProps. Variable f : aT -> rT. Lemma morphicP : reflect {in A &, {morph f : x y / x * y}} (morphic f). Proof. apply: (iffP forallP) => [fM x y Ax Ay | fM [x y] /=]. by apply/eqP; have:= fM (x, y); rewrite inE /= Ax Ay. by apply/implyP=> /andP[Ax Ay]; rewrite fM. Qed. Definition morphm of morphic f := f : aT -> FinGroup.sort rT. Lemma morphmE fM : morphm fM = f. Proof. by []. Qed. Canonical morphm_morphism fM := @Morphism _ _ A (morphm fM) (morphicP fM). End MorphicProps. Lemma misomP f : reflect {fM : morphic f & isom (morphm fM)} (misom f). Proof. by apply: (iffP andP) => [] [fM fiso] //; exists fM. Qed. Lemma misom_isog f : misom f -> isog. Proof. case/andP=> fM iso_f; apply/existsP; exists (finfun f). apply/andP; split; last by rewrite /misom /isom !(eq_imset _ (ffunE f)). by apply/forallP=> u; rewrite !ffunE; apply: forallP fM u. Qed. Lemma isom_isog (D : {group aT}) (f : {morphism D >-> rT}) : A \subset D -> isom f -> isog. Proof. move=> sAD isof; apply: (@misom_isog f); rewrite /misom isof andbT. by apply/morphicP; apply: (sub_in2 (subsetP sAD) (morphM f)). Qed. Lemma isog_isom : isog -> {f : {morphism A >-> rT} | isom f}. Proof. by case/existsP/sigW=> f /misomP[fM isom_f]; exists (morphm_morphism fM). Qed. End Defs. Infix "\isog" := isog. Arguments isom_isog [A B D]. (* The real reflection properties only hold for true groups and morphisms. *) Section Main. Variables (G : {group aT}) (H : {group rT}). Lemma isomP (f : {morphism G >-> rT}) : reflect ('injm f /\ f @* G = H) (isom G H f). Proof. apply: (iffP eqP) => [eqfGH | [injf <-]]; last first. by rewrite -injmD1 // morphimEsub ?subsetDl. split. apply/subsetP=> x /morphpreP[Gx fx1]; have: f x \notin H^# by rewrite inE fx1. by apply: contraR => ntx; rewrite -eqfGH imset_f // inE ntx. rewrite morphimEdom -{2}(setD1K (group1 G)) imsetU eqfGH. by rewrite imset_set1 morph1 setD1K. Qed. Lemma isogP : reflect (exists2 f : {morphism G >-> rT}, 'injm f & f @* G = H) (G \isog H). Proof. apply: (iffP idP) => [/isog_isom[f /isomP[]] | [f injf fG]]; first by exists f. by apply: (isom_isog f) => //; apply/isomP. Qed. Variable f : {morphism G >-> rT}. Hypothesis isoGH : isom G H f. Lemma isom_inj : 'injm f. Proof. by have /isomP[] := isoGH. Qed. Lemma isom_im : f @* G = H. Proof. by have /isomP[] := isoGH. Qed. Lemma isom_card : #|G| = #|H|. Proof. by rewrite -isom_im card_injm ?isom_inj. Qed. Lemma isom_sub_im : H \subset f @* G. Proof. by rewrite isom_im. Qed. Definition isom_inv := restrm isom_sub_im (invm isom_inj). End Main. Variables (G : {group aT}) (f : {morphism G >-> rT}). Lemma morphim_isom (H : {group aT}) (K : {group rT}) : H \subset G -> isom H K f -> f @* H = K. Proof. by case/(restrmP f)=> g [gf _ _ <- //]; rewrite -gf; case/isomP. Qed. Lemma sub_isom (A : {set aT}) (C : {set rT}) : A \subset G -> f @* A = C -> 'injm f -> isom A C f. Proof. move=> sAG; case: (restrmP f sAG) => g [_ _ _ img] <-{C} injf. rewrite /isom -morphimEsub ?morphimDG ?morphim1 //. by rewrite subDset setUC subsetU ?sAG. Qed. Lemma sub_isog (A : {set aT}) : A \subset G -> 'injm f -> isog A (f @* A). Proof. by move=> sAG injf; apply: (isom_isog f sAG); apply: sub_isom. Qed. Lemma restr_isom_to (A : {set aT}) (C R : {group rT}) (sAG : A \subset G) : f @* A = C -> isom G R f -> isom A C (restrm sAG f). Proof. by move=> defC /isomP[inj_f _]; apply: sub_isom. Qed. Lemma restr_isom (A : {group aT}) (R : {group rT}) (sAG : A \subset G) : isom G R f -> isom A (f @* A) (restrm sAG f). Proof. exact: restr_isom_to. Qed. End ReflectProp. Arguments isom {_ _} _%_g _%_g _. Arguments morphic {_ _} _%_g _. Arguments misom _ _ _%_g _%_g _. Arguments isog {_ _} _%_g _%_g. Arguments morphicP {aT rT A f}. Arguments misomP {aT rT A B f}. Arguments isom_isog [aT rT A B D]. Arguments isomP {aT rT G H f}. Arguments isogP {aT rT G H}. Prenex Implicits morphm. Notation "x \isog y":= (isog x y). Section Isomorphisms. Variables gT hT kT : finGroupType. Variables (G : {group gT}) (H : {group hT}) (K : {group kT}). Lemma idm_isom : isom G G (idm G). Proof. exact: sub_isom (im_idm G) (injm_idm G). Qed. Lemma isog_refl : G \isog G. Proof. exact: isom_isog idm_isom. Qed. Lemma card_isog : G \isog H -> #|G| = #|H|. Proof. by case/isogP=> f injf <-; apply: isom_card (f) _; apply/isomP. Qed. Lemma isog_abelian : G \isog H -> abelian G = abelian H. Proof. by case/isogP=> f injf <-; rewrite injm_abelian. Qed. Lemma trivial_isog : G :=: 1 -> H :=: 1 -> G \isog H. Proof. move=> -> ->; apply/isogP. exists [morphism of @trivm gT hT 1]; rewrite /= ?morphim1 //. by rewrite ker_trivm; apply: subxx. Qed. Lemma isog_eq1 : G \isog H -> (G :==: 1) = (H :==: 1). Proof. by move=> isoGH; rewrite !trivg_card1 card_isog. Qed. Lemma isom_sym (f : {morphism G >-> hT}) (isoGH : isom G H f) : isom H G (isom_inv isoGH). Proof. rewrite sub_isom 1?injm_restrm ?injm_invm // im_restrm. by rewrite -(isom_im isoGH) im_invm. Qed. Lemma isog_symr : G \isog H -> H \isog G. Proof. by case/isog_isom=> f /isom_sym/isom_isog->. Qed. Lemma isog_trans : G \isog H -> H \isog K -> G \isog K. Proof. case/isogP=> f injf <-; case/isogP=> g injg <-. have defG: f @*^-1 (f @* G) = G by rewrite morphimGK ?subsetIl. rewrite -morphim_comp -{1 8}defG. by apply/isogP; exists [morphism of g \o f]; rewrite ?injm_comp. Qed. Lemma nclasses_isog : G \isog H -> #|classes G| = #|classes H|. Proof. by case/isogP=> f injf <-; rewrite nclasses_injm. Qed. End Isomorphisms. Section IsoBoolEquiv. Variables gT hT kT : finGroupType. Variables (G : {group gT}) (H : {group hT}) (K : {group kT}). Lemma isog_sym : (G \isog H) = (H \isog G). Proof. by apply/idP/idP; apply: isog_symr. Qed. Lemma isog_transl : G \isog H -> (G \isog K) = (H \isog K). Proof. by move=> iso; apply/idP/idP; apply: isog_trans; rewrite // -isog_sym. Qed. Lemma isog_transr : G \isog H -> (K \isog G) = (K \isog H). Proof. by move=> iso; apply/idP/idP; move/isog_trans; apply; rewrite // -isog_sym. Qed. End IsoBoolEquiv. Section Homg. Implicit Types rT gT aT : finGroupType. Definition homg rT aT (C : {set rT}) (D : {set aT}) := [exists (f : {ffun aT -> rT} | morphic D f), f @: D == C]. Lemma homgP rT aT (C : {set rT}) (D : {set aT}) : reflect (exists f : {morphism D >-> rT}, f @* D = C) (homg C D). Proof. apply: (iffP exists_eq_inP) => [[f fM <-] | [f <-]]. by exists (morphm_morphism fM); rewrite /morphim /= setIid. exists (finfun f); first by apply/morphicP=> x y Dx Dy; rewrite !ffunE morphM. by rewrite /morphim setIid; apply: eq_imset => x; rewrite ffunE. Qed. Lemma morphim_homg aT rT (A D : {set aT}) (f : {morphism D >-> rT}) : A \subset D -> homg (f @* A) A. Proof. move=> sAD; apply/homgP; exists (restrm_morphism sAD f). by rewrite morphim_restrm setIid. Qed. Lemma leq_homg rT aT (C : {set rT}) (G : {group aT}) : homg C G -> #|C| <= #|G|. Proof. by case/homgP=> f <-; apply: leq_morphim. Qed. Lemma homg_refl aT (A : {set aT}) : homg A A. Proof. by apply/homgP; exists (idm_morphism A); rewrite im_idm. Qed. Lemma homg_trans aT (B : {set aT}) rT (C : {set rT}) gT (G : {group gT}) : homg C B -> homg B G -> homg C G. Proof. move=> homCB homBG; case/homgP: homBG homCB => fG <- /homgP[fK <-]. by rewrite -morphim_comp morphim_homg // -sub_morphim_pre. Qed. Lemma isogEcard rT aT (G : {group rT}) (H : {group aT}) : (G \isog H) = (homg G H) && (#|H| <= #|G|). Proof. rewrite isog_sym; apply/isogP/andP=> [[f injf <-] | []]. by rewrite leq_eqVlt eq_sym card_im_injm injf morphim_homg. case/homgP=> f <-; rewrite leq_eqVlt eq_sym card_im_injm. by rewrite ltnNge leq_morphim orbF; exists f. Qed. Lemma isog_hom rT aT (G : {group rT}) (H : {group aT}) : G \isog H -> homg G H. Proof. by rewrite isogEcard; case/andP. Qed. Lemma isogEhom rT aT (G : {group rT}) (H : {group aT}) : (G \isog H) = homg G H && homg H G. Proof. apply/idP/andP=> [isoGH | [homGH homHG]]. by rewrite !isog_hom // isog_sym. by rewrite isogEcard homGH leq_homg. Qed. Lemma eq_homgl gT aT rT (G : {group gT}) (H : {group aT}) (K : {group rT}) : G \isog H -> homg G K = homg H K. Proof. by rewrite isogEhom => /andP[homGH homHG]; apply/idP/idP; apply: homg_trans. Qed. Lemma eq_homgr gT rT aT (G : {group gT}) (H : {group rT}) (K : {group aT}) : G \isog H -> homg K G = homg K H. Proof. rewrite isogEhom => /andP[homGH homHG]. by apply/idP/idP=> homK; apply: homg_trans homK _. Qed. End Homg. Arguments homg _ _ _%_g _%_g. Notation "G \homg H" := (homg G H) (at level 70, no associativity) : group_scope. Arguments homgP {rT aT C D}. (* Isomorphism between a group and its subtype. *) Section SubMorphism. Variables (gT : finGroupType) (G : {group gT}). Canonical sgval_morphism := Morphism (@sgvalM _ G). Canonical subg_morphism := Morphism (@subgM _ G). Lemma injm_sgval : 'injm sgval. Proof. exact/injmP/(in2W subg_inj). Qed. Lemma injm_subg : 'injm (subg G). Proof. exact/injmP/(can_in_inj subgK). Qed. Hint Resolve injm_sgval injm_subg : core. Lemma ker_sgval : 'ker sgval = 1. Proof. exact/trivgP. Qed. Lemma ker_subg : 'ker (subg G) = 1. Proof. exact/trivgP. Qed. Lemma im_subg : subg G @* G = [subg G]. Proof. apply/eqP; rewrite -subTset morphimEdom. by apply/subsetP=> u _; rewrite -(sgvalK u) imset_f ?subgP. Qed. Lemma sgval_sub A : sgval @* A \subset G. Proof. by apply/subsetP=> x; case/imsetP=> u _ ->; apply: subgP. Qed. Lemma sgvalmK A : subg G @* (sgval @* A) = A. Proof. apply/eqP; rewrite eqEcard !card_injm ?subsetT ?sgval_sub // leqnn andbT. rewrite -morphim_comp; apply/subsetP=> _ /morphimP[v _ Av ->] /=. by rewrite sgvalK. Qed. Lemma subgmK (A : {set gT}) : A \subset G -> sgval @* (subg G @* A) = A. Proof. move=> sAG; apply/eqP; rewrite eqEcard !card_injm ?subsetT //. rewrite leqnn andbT -morphim_comp morphimE /= morphpreT. by apply/subsetP=> _ /morphimP[v Gv Av ->] /=; rewrite subgK. Qed. Lemma im_sgval : sgval @* [subg G] = G. Proof. by rewrite -{2}im_subg subgmK. Qed. Lemma isom_subg : isom G [subg G] (subg G). Proof. by apply/isomP; rewrite im_subg. Qed. Lemma isom_sgval : isom [subg G] G sgval. Proof. by apply/isomP; rewrite im_sgval. Qed. Lemma isog_subg : isog G [subg G]. Proof. exact: isom_isog isom_subg. Qed. End SubMorphism. Arguments sgvalmK {gT G} A. Arguments subgmK {gT G} [A] sAG.
zmodp.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 choice eqtype ssrnat seq. From mathcomp Require Import div fintype bigop finset prime fingroup perm. From mathcomp Require Import ssralg finalg countalg. (******************************************************************************) (* Definition of the additive group and ring Zp, represented as 'I_p *) (******************************************************************************) (* Definitions: *) (* From fintype.v: *) (* 'I_p == the subtype of integers less than p, taken here as the type of *) (* the integers mod p. *) (* This file: *) (* inZp == the natural projection from nat into the integers mod p, *) (* represented as 'I_p. Here p is implicit, but MUST be of the *) (* form n.+1. *) (* The operations: *) (* Zp0 == the identity element for addition *) (* Zp1 == the identity element for multiplication, and a generator of *) (* additive group *) (* Zp_opp == inverse function for addition *) (* Zp_add == addition *) (* Zp_mul == multiplication *) (* Zp_inv == inverse function for multiplication *) (* Note that while 'I_n.+1 has canonical finZmodType and finGroupType *) (* structures, only 'I_n.+2 has a canonical ring structure (it has, in fact, *) (* a canonical finComUnitRing structure), and hence an associated *) (* multiplicative unit finGroupType. To mitigate the issues caused by the *) (* trivial "ring" (which is, indeed is NOT a ring in the ssralg/finalg *) (* formalization), we define additional notation: *) (* 'Z_p == the type of integers mod (max p 2); this is always a proper *) (* ring, by constructions. Note that 'Z_p is provably equal to *) (* 'I_p if p > 1, and convertible to 'I_p if p is of the form *) (* n.+2. *) (* Zp p == the subgroup of integers mod (max p 1) in 'Z_p; this is thus *) (* all of 'Z_p if p > 1, and else the trivial group. *) (* units_Zp p == the group of all units of 'Z_p -- i.e., the group of *) (* (multiplicative) automorphisms of Zp p. *) (* We show that Zp and units_Zp are abelian, and compute their orders. *) (* We use a similar technique to represent the prime fields: *) (* 'F_p == the finite field of integers mod the first prime divisor of *) (* maxn p 2. This is provably equal to 'Z_p and 'I_p if p is *) (* provably prime, and indeed convertible to the above if p is *) (* a concrete prime such as 2, 5 or 23. *) (* Note finally that due to the canonical structures it is possible to use *) (* 0%R instead of Zp0, and 1%R instead of Zp1 (for the latter, p must be of *) (* the form n.+2, and 1%R : nat will simplify to 1%N). *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Section ZpDef. (***********************************************************************) (* *) (* Mod p arithmetic on the finite set {0, 1, 2, ..., p - 1} *) (* *) (***********************************************************************) (* Operations on 'I_p without constraint on p. *) Section Generic. Variable p : nat. Implicit Types i j : 'I_p. Lemma Zp_opp_subproof i : (p - i) %% p < p. Proof. by case: p i => [[]//|k] i; apply/ltn_pmod. Qed. Definition Zp_opp i := Ordinal (Zp_opp_subproof i). Lemma Zp_add_subproof i j : (i + j) %% p < p. Proof. by case: p i j => [[]//|k] i j; apply/ltn_pmod. Qed. Definition Zp_add i j := Ordinal (Zp_add_subproof i j). Lemma Zp_mul_subproof i j : (i * j) %% p < p. Proof. by case: p i j => [[]//|k] i j; apply/ltn_pmod. Qed. Definition Zp_mul i j := Ordinal (Zp_mul_subproof i j). Lemma Zp_inv_subproof i : (egcdn i p).1 %% p < p. Proof. by case: p i => [[]//|k] i; apply/ltn_pmod. Qed. Definition Zp_inv i := if coprime p i then Ordinal (Zp_inv_subproof i) else i. Lemma Zp_addA : associative Zp_add. Proof. by move=> x y z; apply: val_inj; rewrite /= modnDml modnDmr addnA. Qed. Lemma Zp_addC : commutative Zp_add. Proof. by move=> x y; apply: val_inj; rewrite /= addnC. Qed. Lemma Zp_mulC : commutative Zp_mul. Proof. by move=> x y; apply: val_inj; rewrite /= mulnC. Qed. Lemma Zp_mulA : associative Zp_mul. Proof. by move=> x y z; apply: val_inj; rewrite /= modnMml modnMmr mulnA. Qed. Lemma Zp_mul_addr : right_distributive Zp_mul Zp_add. Proof. by move=> x y z; apply: val_inj; rewrite /= modnMmr modnDm mulnDr. Qed. Lemma Zp_mul_addl : left_distributive Zp_mul Zp_add. Proof. by move=> x y z; rewrite -!(Zp_mulC z) Zp_mul_addr. Qed. Lemma Zp_inv_out i : ~~ coprime p i -> Zp_inv i = i. Proof. by rewrite /Zp_inv => /negPf->. Qed. End Generic. Arguments Zp_opp {p}. Arguments Zp_add {p}. Arguments Zp_mul {p}. Arguments Zp_inv {p}. Variable p' : nat. Local Notation p := p'.+1. Implicit Types x y z : 'I_p. (* Standard injection; val (inZp i) = i %% p *) Definition inZp i := Ordinal (ltn_pmod i (ltn0Sn p')). Lemma modZp x : x %% p = x. Proof. by rewrite modn_small ?ltn_ord. Qed. Lemma valZpK x : inZp x = x. Proof. by apply: val_inj; rewrite /= modZp. Qed. (* Operations *) Definition Zp0 : 'I_p := ord0. Definition Zp1 := inZp 1. (* Additive group structure. *) Lemma Zp_add0z : left_id Zp0 Zp_add. Proof. by move=> x; apply: val_inj; rewrite /= modZp. Qed. Lemma Zp_addNz : left_inverse Zp0 Zp_opp Zp_add. Proof. by move=> x; apply: val_inj; rewrite /= modnDml subnK ?modnn // ltnW. Qed. HB.instance Definition _ := GRing.isZmodule.Build 'I_p (@Zp_addA _) (@Zp_addC _) Zp_add0z Zp_addNz. HB.instance Definition _ := [finGroupMixin of 'I_p for +%R]. (* Ring operations *) Lemma Zp_mul1z : left_id Zp1 Zp_mul. Proof. by move=> x; apply: val_inj; rewrite /= modnMml mul1n modZp. Qed. Lemma Zp_mulz1 : right_id Zp1 Zp_mul. Proof. by move=> x; rewrite Zp_mulC Zp_mul1z. Qed. Lemma Zp_mulVz x : coprime p x -> Zp_mul (Zp_inv x) x = Zp1. Proof. move=> co_p_x; apply: val_inj; rewrite /Zp_inv co_p_x /= modnMml. by rewrite -(chinese_modl co_p_x 1 0) /chinese addn0 mul1n mulnC. Qed. Lemma Zp_mulzV x : coprime p x -> Zp_mul x (Zp_inv x) = Zp1. Proof. by move=> Ux; rewrite /= Zp_mulC Zp_mulVz. Qed. Lemma Zp_intro_unit x y : Zp_mul y x = Zp1 -> coprime p x. Proof. case=> yx1; have:= coprimen1 p. by rewrite -coprime_modr -yx1 coprime_modr coprimeMr; case/andP. Qed. Lemma Zp_mulrn x n : x *+ n = inZp (x * n). Proof. apply: val_inj => /=; elim: n => [|n IHn]; first by rewrite muln0 modn_small. by rewrite !GRing.mulrS /= IHn modnDmr mulnS. Qed. Import GroupScope. Lemma Zp_mulgC : @commutative 'I_p _ mulg. Proof. exact: Zp_addC. Qed. Lemma Zp_abelian : abelian [set: 'I_p]. Proof. exact: FinRing.zmod_abelian. Qed. Lemma Zp_expg x n : x ^+ n = inZp (x * n). Proof. exact: Zp_mulrn. Qed. Lemma Zp1_expgz x : Zp1 ^+ x = x. Proof. rewrite Zp_expg; apply/val_inj. by move: (Zp_mul1z x) => /(congr1 val). Qed. Lemma Zp_cycle : setT = <[Zp1]>. Proof. by apply/setP=> x; rewrite -[x]Zp1_expgz inE groupX ?mem_gen ?set11. Qed. Lemma order_Zp1 : #[Zp1] = p. Proof. by rewrite orderE -Zp_cycle cardsT card_ord. Qed. End ZpDef. Arguments Zp0 {p'}. Arguments Zp1 {p'}. Arguments inZp {p'} i. Arguments valZpK {p'} x. (* We redefine fintype.ord1 to specialize it with 0 instead of ord0 *) (* since 'I_n is now canonically a zmodType *) Lemma ord1 : all_equal_to (0 : 'I_1). Proof. exact: ord1. Qed. Lemma lshift0 m n : lshift m (0 : 'I_n.+1) = (0 : 'I_(n + m).+1). Proof. exact: val_inj. Qed. Lemma rshift1 n : @rshift 1 n =1 lift (0 : 'I_n.+1). Proof. by move=> i; apply: val_inj. Qed. Lemma split1 n i : split (i : 'I_(1 + n)) = oapp (@inr _ _) (inl _ 0) (unlift 0 i). Proof. case: unliftP => [i'|] -> /=. by rewrite -rshift1 (unsplitK (inr _ _)). by rewrite -(lshift0 n 0) (unsplitK (inl _ _)). Qed. (* TODO: bigop is imported after zmodp in matrix.v and intdiv.v to prevent these warnings from triggering. We should restore the order of imports when these are removed. *) #[deprecated(since="mathcomp 2.3.0", note="Use bigop.big_ord1 instead.")] Notation big_ord1 := big_ord1 (only parsing). #[deprecated(since="mathcomp 2.3.0", note="Use bigop.big_ord1_cond instead.")] Notation big_ord1_cond := big_ord1_cond (only parsing). Section ZpNzRing. Variable p' : nat. Local Notation p := p'.+2. Lemma Zp_nontrivial : Zp1 != 0 :> 'I_p. Proof. by []. Qed. HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build 'I_p (@Zp_mulA _) (@Zp_mulC _) (@Zp_mul1z _) (@Zp_mul_addl _) Zp_nontrivial. HB.instance Definition _ := GRing.ComNzRing_hasMulInverse.Build 'I_p (@Zp_mulVz _) (@Zp_intro_unit _) (@Zp_inv_out _). Lemma Zp_nat n : n%:R = inZp n :> 'I_p. Proof. by apply: val_inj; rewrite [n%:R]Zp_mulrn /= modnMml mul1n. Qed. Lemma natr_Zp (x : 'I_p) : x%:R = x. Proof. by rewrite Zp_nat valZpK. Qed. Lemma natr_negZp (x : 'I_p) : (- x)%:R = - x. Proof. by apply: val_inj; rewrite /= Zp_nat /= modn_mod. Qed. Import GroupScope. Lemma unit_Zp_mulgC : @commutative {unit 'I_p} _ mulg. Proof. by move=> u v; apply: val_inj; rewrite /= GRing.mulrC. Qed. Lemma unit_Zp_expg (u : {unit 'I_p}) n : val (u ^+ n) = inZp (val u ^ n) :> 'I_p. Proof. apply: val_inj => /=; elim: n => [|n IHn] //. by rewrite expgS /= IHn expnS modnMmr. Qed. End ZpNzRing. Definition Zp_trunc p := p.-2. Notation "''Z_' p" := 'I_(Zp_trunc p).+2 (at level 0, p at level 2, format "''Z_' p") : type_scope. Notation "''F_' p" := 'Z_(pdiv p) (at level 0, p at level 2, format "''F_' p") : type_scope. Arguments natr_Zp {p'} x. Section ZpNzRing. Import GRing.Theory. Lemma add_1_Zp p (x : 'Z_p) : 1 + x = ordS x. Proof. by case: p => [|[|p]] in x *; apply/val_inj. Qed. Lemma add_Zp_1 p (x : 'Z_p) : x + 1 = ordS x. Proof. by rewrite addrC add_1_Zp. Qed. Lemma sub_Zp_1 p (x : 'Z_p) : x - 1 = ord_pred x. Proof. by apply: (addIr 1); rewrite addrNK add_Zp_1 ord_predK. Qed. Lemma add_N1_Zp p (x : 'Z_p) : -1 + x = ord_pred x. Proof. by rewrite addrC sub_Zp_1. Qed. End ZpNzRing. Section Groups. Variable p : nat. Definition Zp := if p > 1 then [set: 'Z_p] else 1%g. Definition units_Zp := [set: {unit 'Z_p}]. Lemma Zp_cast : p > 1 -> (Zp_trunc p).+2 = p. Proof. by case: p => [|[]]. Qed. Lemma val_Zp_nat (p_gt1 : p > 1) n : (n%:R : 'Z_p) = (n %% p)%N :> nat. Proof. by rewrite Zp_nat /= Zp_cast. Qed. Lemma Zp_nat_mod (p_gt1 : p > 1)m : (m %% p)%:R = m%:R :> 'Z_p. Proof. by apply: ord_inj; rewrite !val_Zp_nat // modn_mod. Qed. Lemma pchar_Zp : p > 1 -> p%:R = 0 :> 'Z_p. Proof. by move=> p_gt1; rewrite -Zp_nat_mod ?modnn. Qed. Lemma unitZpE x : p > 1 -> ((x%:R : 'Z_p) \is a GRing.unit) = coprime p x. Proof. move=> p_gt1; rewrite qualifE /=. by rewrite val_Zp_nat ?Zp_cast ?coprime_modr. Qed. Lemma Zp_group_set : group_set Zp. Proof. by rewrite /Zp; case: (p > 1); apply: groupP. Qed. (* FIX ME : is this ok something similar is done in fingroup *) Canonical Zp_group := Group Zp_group_set. Lemma card_Zp : p > 0 -> #|Zp| = p. Proof. rewrite /Zp; case: p => [|[|p']] //= _; first by rewrite cards1. by rewrite cardsT card_ord. Qed. Lemma mem_Zp x : p > 1 -> x \in Zp. Proof. by rewrite /Zp => ->. Qed. Canonical units_Zp_group := [group of units_Zp]. Lemma card_units_Zp : p > 0 -> #|units_Zp| = totient p. Proof. move=> p_gt0; transitivity (totient p.-2.+2); last by case: p p_gt0 => [|[|p']]. rewrite cardsT card_sub -sum1_card big_mkcond /=. by rewrite totient_count_coprime big_mkord. Qed. Lemma units_Zp_abelian : abelian units_Zp. Proof. by apply/centsP=> u _ v _; apply: unit_Zp_mulgC. Qed. End Groups. #[deprecated(since="mathcomp 2.4.0", note="Use pchar_Zp instead.")] Notation char_Zp := (pchar_Zp) (only parsing). (* Field structure for primes. *) Section PrimeField. Open Scope ring_scope. Variable p : nat. Section F_prime. Hypothesis p_pr : prime p. Lemma Fp_Zcast : Zp_trunc (pdiv p) = Zp_trunc p. Proof. by rewrite /pdiv primes_prime. Qed. Lemma Fp_cast : (Zp_trunc (pdiv p)).+2 = p. Proof. by rewrite Fp_Zcast ?Zp_cast ?prime_gt1. Qed. Lemma card_Fp : #|'F_p| = p. Proof. by rewrite card_ord Fp_cast. Qed. Lemma val_Fp_nat n : (n%:R : 'F_p) = (n %% p)%N :> nat. Proof. by rewrite Zp_nat /= Fp_cast. Qed. Lemma Fp_nat_mod m : (m %% p)%:R = m%:R :> 'F_p. Proof. by apply: ord_inj; rewrite !val_Fp_nat // modn_mod. Qed. Lemma pchar_Fp : p \in [pchar 'F_p]. Proof. by rewrite !inE -Fp_nat_mod p_pr ?modnn. Qed. Lemma pchar_Fp_0 : p%:R = 0 :> 'F_p. Proof. exact: GRing.pcharf0 pchar_Fp. Qed. Lemma unitFpE x : ((x%:R : 'F_p) \is a GRing.unit) = coprime p x. Proof. by rewrite pdiv_id // unitZpE // prime_gt1. Qed. End F_prime. Lemma Fp_fieldMixin : GRing.ComUnitRing_isField 'F_p. Proof. constructor => x nzx. rewrite qualifE /= prime_coprime ?gtnNdvd ?lt0n //. case: (ltnP 1 p) => [lt1p | ]; last by case: p => [|[|p']]. by rewrite Zp_cast ?prime_gt1 ?pdiv_prime. Qed. HB.instance Definition _ := Fp_fieldMixin. HB.instance Definition _ := FinRing.isField.Build 'F_p. End PrimeField. Section Sym. Import GRing. Lemma gen_tperm_step n (k : 'I_n.+1) : coprime n.+1 k -> <<[set tperm i (i + k) | i : 'I_n.+1]>>%g = [set: 'S_n.+1]. Proof. case: n k => [|n] k. move=> _; apply/eqP; rewrite eqEsubset subsetT/= -(gen_tperm 0)/= gen_subG. apply/subsetP => s /imsetP[/= [][|//] lt01 _ ->]. have ->: (Ordinal lt01) = 0 by apply/val_inj. by rewrite tperm1 group1. rewrite -unitZpE// natr_Zp => k_unit. apply/eqP; rewrite eqEsubset subsetT/= -(gen_tperm 0)/= gen_subG. apply/subsetP => s /imsetP[/= i _ ->]. rewrite -[i](mulVKr k_unit) -[_ * i]natr_Zp mulr_natr. elim: (val _) => //= {i} [|[|i] IHi]; first by rewrite tperm1 group1. by rewrite mulrSr mem_gen//; apply/imsetP; exists 0. have [->|kS2N0] := eqVneq (k *+ i.+2) 0; first by rewrite tperm1 group1. have kSSneqkS : k *+ i.+2 != k *+ i.+1. rewrite -subr_eq0 -mulrnBr// subSnn mulr1n. by apply: contraTneq k_unit => ->; rewrite unitr0. rewrite -(@tpermJ_tperm _ (k *+ i.+1)) 1?eq_sym//. rewrite groupJ// 1?tpermC// mulrSr 1?tpermC. by rewrite mem_gen//; apply/imsetP; exists (k *+ i.+1). Qed. Lemma perm_addr1X n m (j k : 'I_n.+1) : (perm (addrI m%R) ^+ j)%g k = m *+ j + k. Proof. by rewrite permX (eq_iter (permE _)) iter_addr. Qed. Lemma gen_tpermn_circular_shift n (i j : 'I_n.+2) (c := perm (addrI 1)) : coprime n.+2 (j - i)%R -> <<[set tperm i j ; c]>>%g = [set: 'S_n.+2]. Proof. move=> jBi_coprime; apply/eqP; rewrite eqEsubset subsetT/=. rewrite -(gen_tperm_step jBi_coprime) gen_subG. apply/subsetP => s /imsetP[/= k _ ->]. suff -> : tperm k (k + (j - i)) = (tperm i j ^ c ^+ (k - i)%R)%g. by rewrite groupJ ?groupX ?mem_gen ?inE ?eqxx ?orbT. by rewrite tpermJ !perm_addr1X natr_Zp addrNK addrAC addrA. Qed. End Sym. #[deprecated(since="mathcomp 2.4.0", note="Use pchar_Fp instead.")] Notation char_Fp := (pchar_Fp) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pchar_Fp_0 instead.")] Notation char_Fp_0 := (pchar_Fp_0) (only parsing).
Defs.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.Algebra.Hom import Mathlib.Data.Set.Finite.Lemmas import Mathlib.Data.Finsupp.Defs import Mathlib.GroupTheory.Finiteness import Mathlib.RingTheory.Ideal.Span import Mathlib.Tactic.Algebraize /-! # Finiteness conditions in commutative algebra In this file we define a notion of finiteness that is common in commutative algebra. ## Main declarations - `Submodule.FG`, `Ideal.FG` These express that some object is finitely generated as *submodule* over some base ring. - `Module.Finite`, `RingHom.Finite`, `AlgHom.Finite` all of these express that some object is finitely generated *as module* over some base ring. -/ assert_not_exists Module.Basis Ideal.radical Matrix Subalgebra open Function (Surjective) open Finsupp namespace Submodule variable {R : Type*} {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] open Set /-- A submodule of `M` is finitely generated if it is the span of a finite subset of `M`. -/ def FG (N : Submodule R M) : Prop := ∃ S : Finset M, Submodule.span R ↑S = N theorem fg_def {N : Submodule R M} : N.FG ↔ ∃ S : Set M, S.Finite ∧ span R S = N := ⟨fun ⟨t, h⟩ => ⟨_, Finset.finite_toSet t, h⟩, by rintro ⟨t', h, rfl⟩ rcases Finite.exists_finset_coe h with ⟨t, rfl⟩ exact ⟨t, rfl⟩⟩ theorem fg_iff_addSubmonoid_fg (P : Submodule ℕ M) : P.FG ↔ P.toAddSubmonoid.FG := ⟨fun ⟨S, hS⟩ => ⟨S, by simpa [← span_nat_eq_addSubmonoid_closure] using hS⟩, fun ⟨S, hS⟩ => ⟨S, by simpa [← span_nat_eq_addSubmonoid_closure] using hS⟩⟩ theorem fg_iff_add_subgroup_fg {G : Type*} [AddCommGroup G] (P : Submodule ℤ G) : P.FG ↔ P.toAddSubgroup.FG := ⟨fun ⟨S, hS⟩ => ⟨S, by simpa [← span_int_eq_addSubgroup_closure] using hS⟩, fun ⟨S, hS⟩ => ⟨S, by simpa [← span_int_eq_addSubgroup_closure] using hS⟩⟩ theorem fg_iff_exists_fin_generating_family {N : Submodule R M} : N.FG ↔ ∃ (n : ℕ) (s : Fin n → M), span R (range s) = N := by rw [fg_def] constructor · rintro ⟨S, Sfin, hS⟩ obtain ⟨n, f, rfl⟩ := Sfin.fin_embedding exact ⟨n, f, hS⟩ · rintro ⟨n, s, hs⟩ exact ⟨range s, finite_range s, hs⟩ universe w v u in lemma fg_iff_exists_finite_generating_family {A : Type u} [Semiring A] {M : Type v} [AddCommMonoid M] [Module A M] {N : Submodule A M} : N.FG ↔ ∃ (G : Type w) (_ : Finite G) (g : G → M), Submodule.span A (Set.range g) = N := by constructor · intro hN obtain ⟨n, f, h⟩ := Submodule.fg_iff_exists_fin_generating_family.1 hN refine ⟨ULift (Fin n), inferInstance, f ∘ ULift.down, ?_⟩ convert h ext x simp only [Set.mem_range, Function.comp_apply, ULift.exists] · rintro ⟨G, _, g, hg⟩ have := Fintype.ofFinite (range g) exact ⟨(range g).toFinset, by simpa using hg⟩ theorem fg_span_iff_fg_span_finset_subset (s : Set M) : (span R s).FG ↔ ∃ s' : Finset M, ↑s' ⊆ s ∧ span R s = span R s' := by unfold FG constructor · intro ⟨s'', hs''⟩ obtain ⟨s', hs's, hss'⟩ := subset_span_finite_of_subset_span <| hs'' ▸ subset_span refine ⟨s', hs's, ?_⟩ apply le_antisymm · rwa [← hs'', Submodule.span_le] · rw [Submodule.span_le] exact le_trans hs's subset_span · intro ⟨s', _, h⟩ exact ⟨s', h.symm⟩ end Submodule namespace Ideal variable {R : Type*} {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] /-- An ideal of `R` is finitely generated if it is the span of a finite subset of `R`. This is defeq to `Submodule.FG`, but unfolds more nicely. -/ def FG (I : Ideal R) : Prop := ∃ S : Finset R, Ideal.span ↑S = I end Ideal section ModuleAndAlgebra variable (R A B M N : Type*) /-- A module over a semiring is `Module.Finite` if it is finitely generated as a module. -/ protected class Module.Finite [Semiring R] [AddCommMonoid M] [Module R M] : Prop where fg_top : (⊤ : Submodule R M).FG attribute [inherit_doc Module.Finite] Module.Finite.fg_top namespace Module variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] theorem finite_def {R M} [Semiring R] [AddCommMonoid M] [Module R M] : Module.Finite R M ↔ (⊤ : Submodule R M).FG := ⟨fun h => h.1, fun h => ⟨h⟩⟩ namespace Finite open Submodule Set theorem iff_addMonoid_fg {M : Type*} [AddCommMonoid M] : Module.Finite ℕ M ↔ AddMonoid.FG M := ⟨fun h => AddMonoid.fg_def.2 <| (Submodule.fg_iff_addSubmonoid_fg ⊤).1 (finite_def.1 h), fun h => finite_def.2 <| (Submodule.fg_iff_addSubmonoid_fg ⊤).2 (AddMonoid.fg_def.1 h)⟩ theorem iff_addGroup_fg {G : Type*} [AddCommGroup G] : Module.Finite ℤ G ↔ AddGroup.FG G := ⟨fun h => AddGroup.fg_def.2 <| (Submodule.fg_iff_add_subgroup_fg ⊤).1 (finite_def.1 h), fun h => finite_def.2 <| (Submodule.fg_iff_add_subgroup_fg ⊤).2 (AddGroup.fg_def.1 h)⟩ variable {R M N} /-- See also `Module.Finite.exists_fin'`. -/ lemma exists_fin [Module.Finite R M] : ∃ (n : ℕ) (s : Fin n → M), Submodule.span R (range s) = ⊤ := Submodule.fg_iff_exists_fin_generating_family.mp fg_top end Finite end Module instance AddMonoid.FG.to_moduleFinite_nat {M : Type*} [AddCommMonoid M] [FG M] : Module.Finite ℕ M := Module.Finite.iff_addMonoid_fg.mpr ‹_› instance AddMonoid.FG.to_moduleFinite_int {G : Type*} [AddCommGroup G] [FG G] : Module.Finite ℤ G := Module.Finite.iff_addGroup_fg.mpr <| AddGroup.fg_iff_addMonoid_fg.mpr ‹_› end ModuleAndAlgebra namespace RingHom variable {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] /-- A ring morphism `A →+* B` is `RingHom.Finite` if `B` is finitely generated as `A`-module. -/ @[algebraize Module.Finite, stacks 0563] def Finite (f : A →+* B) : Prop := letI : Algebra A B := f.toAlgebra Module.Finite A B @[simp] lemma finite_algebraMap [Algebra A B] : (algebraMap A B).Finite ↔ Module.Finite A B := by rw [RingHom.Finite, toAlgebra_algebraMap] end RingHom namespace AlgHom variable {R A B C : Type*} [CommRing R] variable [CommRing A] [CommRing B] [CommRing C] variable [Algebra R A] [Algebra R B] [Algebra R C] /-- An algebra morphism `A →ₐ[R] B` is finite if it is finite as ring morphism. In other words, if `B` is finitely generated as `A`-module. -/ def Finite (f : A →ₐ[R] B) : Prop := f.toRingHom.Finite end AlgHom
CompMap.lean
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Kernel.Composition.Comp import Mathlib.Probability.Kernel.Composition.MapComap /-! # Lemmas about compositions and maps of kernels This file contains results that use both the composition of kernels and the map of a kernel by a function. Map and comap are particular cases of composition: they correspond to composition with a deterministic kernel. See `deterministic_comp_eq_map` and `comp_deterministic_eq_comap`. -/ open MeasureTheory open scoped ENNReal namespace ProbabilityTheory namespace Kernel variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} variable {γ δ : Type*} {mγ : MeasurableSpace γ} {mδ : MeasurableSpace δ} {f : β → γ} {g : γ → α} theorem deterministic_comp_eq_map (hf : Measurable f) (κ : Kernel α β) : deterministic f hf ∘ₖ κ = map κ f := by ext a s hs simp_rw [map_apply' _ hf _ hs, comp_apply' _ _ _ hs, deterministic_apply' hf _ hs, lintegral_indicator_const_comp hf hs, one_mul] theorem comp_deterministic_eq_comap (κ : Kernel α β) (hg : Measurable g) : κ ∘ₖ deterministic g hg = comap κ g hg := by ext a s hs simp_rw [comap_apply' _ _ _ s, comp_apply' _ _ _ hs, deterministic_apply hg a, lintegral_dirac' _ (Kernel.measurable_coe κ hs)] lemma deterministic_comp_deterministic (hf : Measurable f) (hg : Measurable g) : (deterministic g hg) ∘ₖ (deterministic f hf) = deterministic (g ∘ f) (hg.comp hf) := by ext; simp [comp_deterministic_eq_comap, comap_apply, deterministic_apply] @[simp] lemma comp_id (κ : Kernel α β) : κ ∘ₖ Kernel.id = κ := by rw [Kernel.id, comp_deterministic_eq_comap, comap_id] @[simp] lemma id_comp (κ : Kernel α β) : Kernel.id ∘ₖ κ = κ := by rw [Kernel.id, deterministic_comp_eq_map, map_id] @[simp] lemma swap_swap : (swap α β) ∘ₖ (swap β α) = Kernel.id := by simp_rw [swap, Kernel.deterministic_comp_deterministic, Prod.swap_swap_eq, Kernel.id] lemma swap_comp_eq_map {κ : Kernel α (β × γ)} : (swap β γ) ∘ₖ κ = κ.map Prod.swap := by rw [swap, deterministic_comp_eq_map] lemma map_comp (κ : Kernel α β) (η : Kernel β γ) (f : γ → δ) : (η ∘ₖ κ).map f = (η.map f) ∘ₖ κ := by by_cases hf : Measurable f · ext a s hs rw [map_apply' _ hf _ hs, comp_apply', comp_apply' _ _ _ hs] · simp_rw [map_apply' _ hf _ hs] · exact hf hs · simp [map_of_not_measurable _ hf] lemma comp_map (κ : Kernel α β) (η : Kernel γ δ) {f : β → γ} (hf : Measurable f) : η ∘ₖ (κ.map f) = (η.comap f hf) ∘ₖ κ := by ext x s ms rw [comp_apply' _ _ _ ms, lintegral_map _ hf _ (η.measurable_coe ms), comp_apply' _ _ _ ms] simp_rw [comap_apply'] lemma fst_comp (κ : Kernel α β) (η : Kernel β (γ × δ)) : (η ∘ₖ κ).fst = η.fst ∘ₖ κ := by simp [fst_eq, map_comp κ η _] lemma snd_comp (κ : Kernel α β) (η : Kernel β (γ × δ)) : (η ∘ₖ κ).snd = η.snd ∘ₖ κ := by simp_rw [snd_eq, map_comp κ η _] end Kernel end ProbabilityTheory
Finite.lean
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Data.ULift import Mathlib.Data.ZMod.Defs import Mathlib.SetTheory.Cardinal.ToNat import Mathlib.SetTheory.Cardinal.ENat /-! # Finite Cardinality Functions ## Main Definitions * `Nat.card α` is the cardinality of `α` as a natural number. If `α` is infinite, `Nat.card α = 0`. * `ENat.card α` is the cardinality of `α` as an extended natural number. If `α` is infinite, `ENat.card α = ⊤`. -/ assert_not_exists Field open Cardinal Function noncomputable section variable {α β : Type*} universe u v namespace Nat /-- `Nat.card α` is the cardinality of `α` as a natural number. If `α` is infinite, `Nat.card α = 0`. -/ protected def card (α : Type*) : ℕ := toNat (mk α) @[simp] theorem card_eq_fintype_card [Fintype α] : Nat.card α = Fintype.card α := mk_toNat_eq_card /-- Because this theorem takes `Fintype α` as a non-instance argument, it can be used in particular when `Fintype.card` ends up with different instance than the one found by inference -/ theorem _root_.Fintype.card_eq_nat_card {_ : Fintype α} : Fintype.card α = Nat.card α := mk_toNat_eq_card.symm lemma card_eq_finsetCard (s : Finset α) : Nat.card s = s.card := by simp only [Nat.card_eq_fintype_card, Fintype.card_coe] lemma card_eq_card_toFinset (s : Set α) [Fintype s] : Nat.card s = s.toFinset.card := by simp only [← Nat.card_eq_finsetCard, s.mem_toFinset] lemma card_eq_card_finite_toFinset {s : Set α} (hs : s.Finite) : Nat.card s = hs.toFinset.card := by simp only [← Nat.card_eq_finsetCard, hs.mem_toFinset] theorem subtype_card {p : α → Prop} (s : Finset α) (H : ∀ x : α, x ∈ s ↔ p x) : Nat.card { x // p x } = Finset.card s := by rw [← Fintype.subtype_card s H, Fintype.card_eq_nat_card] @[simp] theorem card_of_isEmpty [IsEmpty α] : Nat.card α = 0 := by simp [Nat.card] @[simp] lemma card_eq_zero_of_infinite [Infinite α] : Nat.card α = 0 := mk_toNat_of_infinite lemma cast_card [Finite α] : (Nat.card α : Cardinal) = Cardinal.mk α := by rw [Nat.card, Cardinal.cast_toNat_of_lt_aleph0] exact Cardinal.lt_aleph0_of_finite _ lemma _root_.Set.Infinite.card_eq_zero {s : Set α} (hs : s.Infinite) : Nat.card s = 0 := @card_eq_zero_of_infinite _ hs.to_subtype lemma card_eq_zero : Nat.card α = 0 ↔ IsEmpty α ∨ Infinite α := by simp [Nat.card, mk_eq_zero_iff, aleph0_le_mk_iff] lemma card_ne_zero : Nat.card α ≠ 0 ↔ Nonempty α ∧ Finite α := by simp [card_eq_zero, not_or] lemma card_pos_iff : 0 < Nat.card α ↔ Nonempty α ∧ Finite α := by simp [Nat.card, mk_eq_zero_iff, mk_lt_aleph0_iff] @[simp] lemma card_pos [Nonempty α] [Finite α] : 0 < Nat.card α := card_pos_iff.2 ⟨‹_›, ‹_›⟩ theorem finite_of_card_ne_zero (h : Nat.card α ≠ 0) : Finite α := (card_ne_zero.1 h).2 theorem card_congr (f : α ≃ β) : Nat.card α = Nat.card β := Cardinal.toNat_congr f lemma card_le_card_of_injective {α : Type u} {β : Type v} [Finite β] (f : α → β) (hf : Injective f) : Nat.card α ≤ Nat.card β := by simpa using toNat_le_toNat (lift_mk_le_lift_mk_of_injective hf) (by simp) lemma card_le_card_of_surjective {α : Type u} {β : Type v} [Finite α] (f : α → β) (hf : Surjective f) : Nat.card β ≤ Nat.card α := by have : lift.{u} #β ≤ lift.{v} #α := mk_le_of_surjective (ULift.map_surjective.2 hf) simpa using toNat_le_toNat this (by simp) theorem card_eq_of_bijective (f : α → β) (hf : Function.Bijective f) : Nat.card α = Nat.card β := card_congr (Equiv.ofBijective f hf) protected theorem bijective_iff_injective_and_card [Finite β] (f : α → β) : Bijective f ↔ Injective f ∧ Nat.card α = Nat.card β := by rw [Bijective, and_congr_right_iff] intro h have := Fintype.ofFinite β have := Fintype.ofInjective f h revert h rw [← and_congr_right_iff, ← Bijective, card_eq_fintype_card, card_eq_fintype_card, Fintype.bijective_iff_injective_and_card] protected theorem bijective_iff_surjective_and_card [Finite α] (f : α → β) : Bijective f ↔ Surjective f ∧ Nat.card α = Nat.card β := by classical rw [_root_.and_comm, Bijective, and_congr_left_iff] intro h have := Fintype.ofFinite α have := Fintype.ofSurjective f h revert h rw [← and_congr_left_iff, ← Bijective, ← and_comm, card_eq_fintype_card, card_eq_fintype_card, Fintype.bijective_iff_surjective_and_card] theorem _root_.Function.Injective.bijective_of_nat_card_le [Finite β] {f : α → β} (inj : Injective f) (hc : Nat.card β ≤ Nat.card α) : Bijective f := (Nat.bijective_iff_injective_and_card f).mpr ⟨inj, hc.antisymm (card_le_card_of_injective f inj) |>.symm⟩ theorem _root_.Function.Surjective.bijective_of_nat_card_le [Finite α] {f : α → β} (surj : Surjective f) (hc : Nat.card α ≤ Nat.card β) : Bijective f := (Nat.bijective_iff_surjective_and_card f).mpr ⟨surj, hc.antisymm (card_le_card_of_surjective f surj)⟩ theorem card_eq_of_equiv_fin {α : Type*} {n : ℕ} (f : α ≃ Fin n) : Nat.card α = n := by simpa only [card_eq_fintype_card, Fintype.card_fin] using card_congr f lemma card_fin (n : ℕ) : Nat.card (Fin n) = n := by rw [Nat.card_eq_fintype_card, Fintype.card_fin] section Set open Set variable {s t : Set α} lemma card_mono (ht : t.Finite) (h : s ⊆ t) : Nat.card s ≤ Nat.card t := toNat_le_toNat (mk_le_mk_of_subset h) ht.lt_aleph0 lemma card_image_le {f : α → β} (hs : s.Finite) : Nat.card (f '' s) ≤ Nat.card s := have := hs.to_subtype; card_le_card_of_surjective (imageFactorization f s) surjective_onto_image lemma card_image_of_injOn {f : α → β} (hf : s.InjOn f) : Nat.card (f '' s) = Nat.card s := by classical obtain hs | hs := s.finite_or_infinite · have := hs.fintype have := fintypeImage s f simp_rw [Nat.card_eq_fintype_card, Set.card_image_of_inj_on hf] · have := hs.to_subtype have := (hs.image hf).to_subtype simp [Nat.card_eq_zero_of_infinite] lemma card_image_of_injective {f : α → β} (hf : Injective f) (s : Set α) : Nat.card (f '' s) = Nat.card s := card_image_of_injOn hf.injOn lemma card_image_equiv (e : α ≃ β) : Nat.card (e '' s) = Nat.card s := Nat.card_congr (e.image s).symm lemma card_preimage_of_injOn {f : α → β} {s : Set β} (hf : (f ⁻¹' s).InjOn f) (hsf : s ⊆ range f) : Nat.card (f ⁻¹' s) = Nat.card s := by rw [← Nat.card_image_of_injOn hf, image_preimage_eq_iff.2 hsf] lemma card_preimage_of_injective {f : α → β} {s : Set β} (hf : Injective f) (hsf : s ⊆ range f) : Nat.card (f ⁻¹' s) = Nat.card s := card_preimage_of_injOn hf.injOn hsf lemma card_univ : Nat.card (univ : Set α) = Nat.card α := card_congr (Equiv.Set.univ α) lemma card_range_of_injective {f : α → β} (hf : Injective f) : Nat.card (range f) = Nat.card α := by rw [← Nat.card_preimage_of_injective hf le_rfl] simp [Nat.card_univ] end Set /-- If the cardinality is positive, that means it is a finite type, so there is an equivalence between `α` and `Fin (Nat.card α)`. See also `Finite.equivFin`. -/ def equivFinOfCardPos {α : Type*} (h : Nat.card α ≠ 0) : α ≃ Fin (Nat.card α) := by cases fintypeOrInfinite α · simpa only [card_eq_fintype_card] using Fintype.equivFin α · simp only [card_eq_zero_of_infinite, ne_eq, not_true_eq_false] at h theorem card_of_subsingleton (a : α) [Subsingleton α] : Nat.card α = 1 := by letI := Fintype.ofSubsingleton a rw [card_eq_fintype_card, Fintype.card_ofSubsingleton a] theorem card_eq_one_iff_unique : Nat.card α = 1 ↔ Subsingleton α ∧ Nonempty α := Cardinal.toNat_eq_one_iff_unique @[simp] theorem card_unique [Nonempty α] [Subsingleton α] : Nat.card α = 1 := by simp [card_eq_one_iff_unique, *] theorem card_eq_one_iff_exists : Nat.card α = 1 ↔ ∃ x : α, ∀ y : α, y = x := by rw [card_eq_one_iff_unique] exact ⟨fun ⟨s, ⟨a⟩⟩ ↦ ⟨a, fun x ↦ s.elim x a⟩, fun ⟨x, h⟩ ↦ ⟨subsingleton_of_forall_eq x h, ⟨x⟩⟩⟩ theorem card_eq_two_iff : Nat.card α = 2 ↔ ∃ x y : α, x ≠ y ∧ {x, y} = @Set.univ α := toNat_eq_ofNat.trans mk_eq_two_iff theorem card_eq_two_iff' (x : α) : Nat.card α = 2 ↔ ∃! y, y ≠ x := toNat_eq_ofNat.trans (mk_eq_two_iff' x) @[simp] theorem card_subtype_true : Nat.card {_a : α // True} = Nat.card α := card_congr <| Equiv.subtypeUnivEquiv fun _ => trivial @[simp] theorem card_sum [Finite α] [Finite β] : Nat.card (α ⊕ β) = Nat.card α + Nat.card β := by have := Fintype.ofFinite α have := Fintype.ofFinite β simp_rw [Nat.card_eq_fintype_card, Fintype.card_sum] @[simp] theorem card_prod (α β : Type*) : Nat.card (α × β) = Nat.card α * Nat.card β := by simp only [Nat.card, mk_prod, toNat_mul, toNat_lift] @[simp] theorem card_ulift (α : Type*) : Nat.card (ULift α) = Nat.card α := card_congr Equiv.ulift @[simp] theorem card_plift (α : Type*) : Nat.card (PLift α) = Nat.card α := card_congr Equiv.plift theorem card_sigma {β : α → Type*} [Fintype α] [∀ a, Finite (β a)] : Nat.card (Sigma β) = ∑ a, Nat.card (β a) := by letI _ (a : α) : Fintype (β a) := Fintype.ofFinite (β a) simp_rw [Nat.card_eq_fintype_card, Fintype.card_sigma] theorem card_pi {β : α → Type*} [Fintype α] : Nat.card (∀ a, β a) = ∏ a, Nat.card (β a) := by simp_rw [Nat.card, mk_pi, prod_eq_of_fintype, toNat_lift, map_prod] theorem card_fun [Finite α] : Nat.card (α → β) = Nat.card β ^ Nat.card α := by haveI := Fintype.ofFinite α rw [Nat.card_pi, Finset.prod_const, Finset.card_univ, ← Nat.card_eq_fintype_card] @[simp] theorem card_zmod (n : ℕ) : Nat.card (ZMod n) = n := by cases n · exact @Nat.card_eq_zero_of_infinite _ Int.infinite · rw [Nat.card_eq_fintype_card, ZMod.card] end Nat namespace Set variable {s : Set α} lemma card_singleton_prod (a : α) (t : Set β) : Nat.card ({a} ×ˢ t) = Nat.card t := by rw [singleton_prod, Nat.card_image_of_injective (Prod.mk_right_injective a)] lemma card_prod_singleton (s : Set α) (b : β) : Nat.card (s ×ˢ {b}) = Nat.card s := by rw [prod_singleton, Nat.card_image_of_injective (Prod.mk_left_injective b)] theorem natCard_pos (hs : s.Finite) : 0 < Nat.card s ↔ s.Nonempty := by simp [pos_iff_ne_zero, Nat.card_eq_zero, hs.to_subtype, nonempty_iff_ne_empty] protected alias ⟨_, Nonempty.natCard_pos⟩ := natCard_pos lemma natCard_graphOn (s : Set α) (f : α → β) : Nat.card (s.graphOn f) = Nat.card s := by rw [← Nat.card_image_of_injOn fst_injOn_graph, image_fst_graphOn] end Set namespace ENat /-- `ENat.card α` is the cardinality of `α` as an extended natural number. If `α` is infinite, `ENat.card α = ⊤`. -/ def card (α : Type*) : ℕ∞ := toENat (mk α) @[simp] theorem card_eq_coe_fintype_card [Fintype α] : card α = Fintype.card α := by simp [card] @[simp high] theorem card_eq_top_of_infinite [Infinite α] : card α = ⊤ := by simp only [card, toENat_eq_top, aleph0_le_mk] @[simp] lemma card_eq_top : card α = ⊤ ↔ Infinite α := by simp [card, aleph0_le_mk_iff] @[simp] theorem card_lt_top_of_finite [Finite α] : card α < ⊤ := by simp [card] @[simp] theorem card_sum (α β : Type*) : card (α ⊕ β) = card α + card β := by simp only [card, mk_sum, map_add, toENat_lift] theorem card_congr {α β : Type*} (f : α ≃ β) : card α = card β := Cardinal.toENat_congr f @[simp] lemma card_ulift (α : Type*) : card (ULift α) = card α := card_congr Equiv.ulift @[simp] lemma card_plift (α : Type*) : card (PLift α) = card α := card_congr Equiv.plift theorem card_image_of_injOn {α β : Type*} {f : α → β} {s : Set α} (h : Set.InjOn f s) : card (f '' s) = card s := card_congr (Equiv.Set.imageOfInjOn f s h).symm theorem card_image_of_injective {α β : Type*} (f : α → β) (s : Set α) (h : Function.Injective f) : card (f '' s) = card s := card_image_of_injOn h.injOn @[simp] theorem _root_.Cardinal.natCast_le_toENat_iff {n : ℕ} {c : Cardinal} : ↑n ≤ toENat c ↔ ↑n ≤ c := by rw [← toENat_nat n, toENat_le_iff_of_le_aleph0 (le_of_lt (nat_lt_aleph0 n))] theorem _root_.Cardinal.toENat_le_natCast_iff {c : Cardinal} {n : ℕ} : toENat c ≤ n ↔ c ≤ n := by simp @[simp] theorem _root_.Cardinal.natCast_eq_toENat_iff {n : ℕ} {c : Cardinal} : ↑n = toENat c ↔ ↑n = c := by rw [le_antisymm_iff, le_antisymm_iff, Cardinal.toENat_le_natCast_iff, Cardinal.natCast_le_toENat_iff] theorem _root_.Cardinal.toENat_eq_natCast_iff {c : Cardinal} {n : ℕ} : Cardinal.toENat c = n ↔ c = n := by simp @[simp] theorem _root_.Cardinal.natCast_lt_toENat_iff {n : ℕ} {c : Cardinal} : ↑n < toENat c ↔ ↑n < c := by simp only [← not_le, Cardinal.toENat_le_natCast_iff] @[simp] theorem _root_.Cardinal.toENat_lt_natCast_iff {n : ℕ} {c : Cardinal} : toENat c < ↑n ↔ c < ↑n := by simp only [← not_le, Cardinal.natCast_le_toENat_iff] theorem card_eq_zero_iff_empty (α : Type*) : card α = 0 ↔ IsEmpty α := by rw [← Cardinal.mk_eq_zero_iff] simp [card] theorem card_ne_zero_iff_nonempty (α : Type*) : card α ≠ 0 ↔ Nonempty α := by simp [card_eq_zero_iff_empty] theorem card_le_one_iff_subsingleton (α : Type*) : card α ≤ 1 ↔ Subsingleton α := by rw [← le_one_iff_subsingleton] simp [card] theorem one_lt_card_iff_nontrivial (α : Type*) : 1 < card α ↔ Nontrivial α := by rw [← Cardinal.one_lt_iff_nontrivial] conv_rhs => rw [← Nat.cast_one] rw [← natCast_lt_toENat_iff] simp only [ENat.card, Nat.cast_one] @[simp] theorem card_prod (α β : Type*) : ENat.card (α × β) = .card α * .card β := by simp [ENat.card] end ENat
Opposite.lean
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Action.Defs import Mathlib.Algebra.Group.Opposite /-! # Scalar actions on and by `Mᵐᵒᵖ` This file defines the actions on the opposite type `SMul R Mᵐᵒᵖ`, and actions by the opposite type, `SMul Rᵐᵒᵖ M`. Note that `MulOpposite.smul` is provided in an earlier file as it is needed to provide the `AddMonoid.nsmul` and `AddCommGroup.zsmul` fields. ## Notation With `open scoped RightActions`, this provides: * `r •> m` as an alias for `r • m` * `m <• r` as an alias for `MulOpposite.op r • m` * `v +ᵥ> p` as an alias for `v +ᵥ p` * `p <+ᵥ v` as an alias for `AddOpposite.op v +ᵥ p` -/ assert_not_exists MonoidWithZero Units FaithfulSMul MonoidHom variable {M N α β : Type*} /-! ### Actions _on_ the opposite type Actions on the opposite type just act on the underlying type. -/ namespace MulOpposite @[to_additive] instance instMulAction [Monoid M] [MulAction M α] : MulAction M αᵐᵒᵖ where one_smul _ := unop_injective <| one_smul _ _ mul_smul _ _ _ := unop_injective <| mul_smul _ _ _ @[to_additive] instance instIsScalarTower [SMul M N] [SMul M α] [SMul N α] [IsScalarTower M N α] : IsScalarTower M N αᵐᵒᵖ where smul_assoc _ _ _ := unop_injective <| smul_assoc _ _ _ @[to_additive] instance instSMulCommClass [SMul M α] [SMul N α] [SMulCommClass M N α] : SMulCommClass M N αᵐᵒᵖ where smul_comm _ _ _ := unop_injective <| smul_comm _ _ _ @[to_additive] instance instIsCentralScalar [SMul M α] [SMul Mᵐᵒᵖ α] [IsCentralScalar M α] : IsCentralScalar M αᵐᵒᵖ where op_smul_eq_smul _ _ := unop_injective <| op_smul_eq_smul _ _ @[to_additive] lemma op_smul_eq_op_smul_op [SMul M α] [SMul Mᵐᵒᵖ α] [IsCentralScalar M α] (r : M) (a : α) : op (r • a) = op r • op a := (op_smul_eq_smul r (op a)).symm @[to_additive] lemma unop_smul_eq_unop_smul_unop [SMul M α] [SMul Mᵐᵒᵖ α] [IsCentralScalar M α] (r : Mᵐᵒᵖ) (a : αᵐᵒᵖ) : unop (r • a) = unop r • unop a := (unop_smul_eq_smul r (unop a)).symm end MulOpposite /-! ### Right actions In this section we establish `SMul αᵐᵒᵖ β` as the canonical spelling of right scalar multiplication of `β` by `α`, and provide convenient notations. -/ namespace RightActions /-- With `open scoped RightActions`, an alternative symbol for left actions, `r • m`. In lemma names this is still called `smul`. -/ scoped notation3:74 r:75 " •> " m:74 => r • m /-- With `open scoped RightActions`, a shorthand for right actions, `op r • m`. In lemma names this is still called `op_smul`. -/ scoped notation3:73 m:73 " <• " r:74 => MulOpposite.op r • m /-- With `open scoped RightActions`, an alternative symbol for left actions, `r • m`. In lemma names this is still called `vadd`. -/ scoped notation3:74 r:75 " +ᵥ> " m:74 => r +ᵥ m /-- With `open scoped RightActions`, a shorthand for right actions, `op r +ᵥ m`. In lemma names this is still called `op_vadd`. -/ scoped notation3:73 m:73 " <+ᵥ " r:74 => AddOpposite.op r +ᵥ m section examples variable [SMul α β] [SMul αᵐᵒᵖ β] [VAdd α β] [VAdd αᵃᵒᵖ β] {a a₁ a₂ a₃ a₄ : α} {b : β} -- Left and right actions are just notation around the general `•` and `+ᵥ` notations example : a •> b = a • b := rfl example : b <• a = MulOpposite.op a • b := rfl example : a +ᵥ> b = a +ᵥ b := rfl example : b <+ᵥ a = AddOpposite.op a +ᵥ b := rfl -- Left actions right-associate, right actions left-associate example : a₁ •> a₂ •> b = a₁ •> (a₂ •> b) := rfl example : b <• a₂ <• a₁ = (b <• a₂) <• a₁ := rfl example : a₁ +ᵥ> a₂ +ᵥ> b = a₁ +ᵥ> (a₂ +ᵥ> b) := rfl example : b <+ᵥ a₂ <+ᵥ a₁ = (b <+ᵥ a₂) <+ᵥ a₁ := rfl -- When left and right actions coexist, they associate to the left example : a₁ •> b <• a₂ = (a₁ •> b) <• a₂ := rfl example : a₁ •> a₂ •> b <• a₃ <• a₄ = ((a₁ •> (a₂ •> b)) <• a₃) <• a₄ := rfl example : a₁ +ᵥ> b <+ᵥ a₂ = (a₁ +ᵥ> b) <+ᵥ a₂ := rfl example : a₁ +ᵥ> a₂ +ᵥ> b <+ᵥ a₃ <+ᵥ a₄ = ((a₁ +ᵥ> (a₂ +ᵥ> b)) <+ᵥ a₃) <+ᵥ a₄ := rfl end examples end RightActions section variable [Monoid α] [MulAction αᵐᵒᵖ β] open scoped RightActions @[to_additive] lemma op_smul_op_smul (b : β) (a₁ a₂ : α) : b <• a₁ <• a₂ = b <• (a₁ * a₂) := smul_smul _ _ _ @[to_additive] lemma op_smul_mul (b : β) (a₁ a₂ : α) : b <• (a₁ * a₂) = b <• a₁ <• a₂ := mul_smul _ _ _ end /-! ### Actions _by_ the opposite type (right actions) -/ open MulOpposite @[to_additive] instance Semigroup.opposite_smulCommClass [Semigroup α] : SMulCommClass αᵐᵒᵖ α α where smul_comm _ _ _ := mul_assoc _ _ _ @[to_additive] instance Semigroup.opposite_smulCommClass' [Semigroup α] : SMulCommClass α αᵐᵒᵖ α := SMulCommClass.symm _ _ _ @[to_additive] instance CommSemigroup.isCentralScalar [CommSemigroup α] : IsCentralScalar α α where op_smul_eq_smul _ _ := mul_comm _ _ /-- Like `Monoid.toMulAction`, but multiplies on the right. -/ @[to_additive /-- Like `AddMonoid.toAddAction`, but adds on the right. -/] instance Monoid.toOppositeMulAction [Monoid α] : MulAction αᵐᵒᵖ α where smul := (· • ·) one_smul := mul_one mul_smul _ _ _ := (mul_assoc _ _ _).symm @[to_additive] instance IsScalarTower.opposite_mid {M N} [Mul N] [SMul M N] [SMulCommClass M N N] : IsScalarTower M Nᵐᵒᵖ N where smul_assoc _ _ _ := mul_smul_comm _ _ _ @[to_additive] instance SMulCommClass.opposite_mid {M N} [Mul N] [SMul M N] [IsScalarTower M N N] : SMulCommClass M Nᵐᵒᵖ N where smul_comm x y z := by induction y using MulOpposite.rec' simp only [smul_mul_assoc, MulOpposite.smul_eq_mul_unop] -- The above instance does not create an unwanted diamond, the two paths to -- `MulAction αᵐᵒᵖ αᵐᵒᵖ` are defeq. example [Monoid α] : Monoid.toMulAction αᵐᵒᵖ = MulOpposite.instMulAction := by with_reducible_and_instances rfl
AssertExistsExt.lean
/- Copyright (c) 2024 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Lean.Environment import Mathlib.Init /-! # Environment extension for tracking existence of declarations and imports This is used by the `assert_not_exists` and `assert_not_imported` commands. -/ open Lean namespace Mathlib.AssertNotExist /-- `AssertExists` is the structure that carries the data to check if a declaration or an import are meant to exist somewhere in Mathlib. -/ structure AssertExists where /-- The type of the assertion: `true` means declaration, `false` means import. -/ isDecl : Bool /-- The fully qualified name of a declaration that is expected to exist. -/ givenName : Name /-- The name of the module where the assertion was made. -/ modName : Name deriving BEq, Hashable /-- Defines the `assertExistsExt` extension for adding a `HashSet` of `AssertExists`s to the environment. -/ initialize assertExistsExt : SimplePersistentEnvExtension AssertExists (Std.HashSet AssertExists) ← registerSimplePersistentEnvExtension { addImportedFn := fun as => as.foldl Std.HashSet.insertMany {} addEntryFn := .insert } /-- `addDeclEntry isDecl declName mod` takes as input the `Bool`ean `isDecl` and the `Name`s of a declaration or import, `declName`, and of a module, `mod`. It extends the `AssertExists` environment extension with the data `isDecl, declName, mod`. This information is used to capture declarations and modules that are required to not exist/be imported at some point, but should eventually exist/be imported. -/ def addDeclEntry {m : Type → Type} [MonadEnv m] (isDecl : Bool) (declName mod : Name) : m Unit := modifyEnv (assertExistsExt.addEntry · { isDecl := isDecl, givenName := declName, modName := mod }) end Mathlib.AssertNotExist open Mathlib.AssertNotExist /-- `getSortedAssertExists env` returns the array of `AssertExists`, placing first all declarations, in alphabetical order, and then all modules, also in alphabetical order. -/ def Lean.Environment.getSortedAssertExists (env : Environment) : Array AssertExists := assertExistsExt.getState env |>.toArray.qsort fun d e => (e.isDecl < d.isDecl) || (e.isDecl == d.isDecl && (d.givenName.toString < e.givenName.toString))
IntegralDomain.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Chris Hughes -/ import Mathlib.Algebra.Polynomial.Roots import Mathlib.Data.Fintype.Inv import Mathlib.GroupTheory.SpecificGroups.Cyclic import Mathlib.Tactic.FieldSimp /-! # Integral domains Assorted theorems about integral domains. ## Main theorems * `isCyclic_of_subgroup_isDomain`: A finite subgroup of the units of an integral domain is cyclic. * `Fintype.fieldOfDomain`: A finite integral domain is a field. ## Notes Wedderburn's little theorem, which shows that all finite division rings are actually fields, is in `Mathlib/RingTheory/LittleWedderburn.lean`. ## Tags integral domain, finite integral domain, finite field -/ section open Finset Polynomial Function Nat section CancelMonoidWithZero -- There doesn't seem to be a better home for these right now variable {M : Type*} [CancelMonoidWithZero M] [Finite M] theorem mul_right_bijective_of_finite₀ {a : M} (ha : a ≠ 0) : Bijective fun b => a * b := Finite.injective_iff_bijective.1 <| mul_right_injective₀ ha theorem mul_left_bijective_of_finite₀ {a : M} (ha : a ≠ 0) : Bijective fun b => b * a := Finite.injective_iff_bijective.1 <| mul_left_injective₀ ha /-- Every finite nontrivial cancel_monoid_with_zero is a group_with_zero. -/ def Fintype.groupWithZeroOfCancel (M : Type*) [CancelMonoidWithZero M] [DecidableEq M] [Fintype M] [Nontrivial M] : GroupWithZero M := { ‹Nontrivial M›, ‹CancelMonoidWithZero M› with inv := fun a => if h : a = 0 then 0 else Fintype.bijInv (mul_right_bijective_of_finite₀ h) 1 mul_inv_cancel := fun a ha => by simp only [dif_neg ha] exact Fintype.rightInverse_bijInv _ _ inv_zero := by simp } theorem exists_eq_pow_of_mul_eq_pow_of_coprime {R : Type*} [CommSemiring R] [IsDomain R] [GCDMonoid R] [Subsingleton Rˣ] {a b c : R} {n : ℕ} (cp : IsCoprime a b) (h : a * b = c ^ n) : ∃ d : R, a = d ^ n := by refine exists_eq_pow_of_mul_eq_pow (isUnit_of_dvd_one ?_) h obtain ⟨x, y, hxy⟩ := cp rw [← hxy] exact -- Porting note: added `GCDMonoid.` twice dvd_add (dvd_mul_of_dvd_right (GCDMonoid.gcd_dvd_left _ _) _) (dvd_mul_of_dvd_right (GCDMonoid.gcd_dvd_right _ _) _) nonrec theorem Finset.exists_eq_pow_of_mul_eq_pow_of_coprime {ι R : Type*} [CommSemiring R] [IsDomain R] [GCDMonoid R] [Subsingleton Rˣ] {n : ℕ} {c : R} {s : Finset ι} {f : ι → R} (h : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → IsCoprime (f i) (f j)) (hprod : ∏ i ∈ s, f i = c ^ n) : ∀ i ∈ s, ∃ d : R, f i = d ^ n := by classical intro i hi rw [← insert_erase hi, prod_insert (notMem_erase i s)] at hprod refine exists_eq_pow_of_mul_eq_pow_of_coprime (IsCoprime.prod_right fun j hj => h i hi j (erase_subset i s hj) fun hij => ?_) hprod rw [hij] at hj exact (s.notMem_erase _) hj end CancelMonoidWithZero variable {R : Type*} {G : Type*} section Ring variable [Ring R] [IsDomain R] [Fintype R] /-- Every finite domain is a division ring. More generally, they are fields; this can be found in `Mathlib/RingTheory/LittleWedderburn.lean`. -/ def Fintype.divisionRingOfIsDomain (R : Type*) [Ring R] [IsDomain R] [DecidableEq R] [Fintype R] : DivisionRing R where __ := (‹Ring R›:) -- this also works without the `( :)`, but it's slightly slow __ := Fintype.groupWithZeroOfCancel R nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl /-- Every finite commutative domain is a field. More generally, commutativity is not required: this can be found in `Mathlib/RingTheory/LittleWedderburn.lean`. -/ def Fintype.fieldOfDomain (R) [CommRing R] [IsDomain R] [DecidableEq R] [Fintype R] : Field R := { Fintype.divisionRingOfIsDomain R, ‹CommRing R› with } theorem Finite.isField_of_domain (R) [CommRing R] [IsDomain R] [Finite R] : IsField R := by cases nonempty_fintype R exact @Field.toIsField R (@Fintype.fieldOfDomain R _ _ (Classical.decEq R) _) end Ring variable [CommRing R] [IsDomain R] [Group G] theorem card_nthRoots_subgroup_units [Fintype G] [DecidableEq G] (f : G →* R) (hf : Injective f) {n : ℕ} (hn : 0 < n) (g₀ : G) : #{g | g ^ n = g₀} ≤ Multiset.card (nthRoots n (f g₀)) := by haveI : DecidableEq R := Classical.decEq _ calc _ ≤ #(nthRoots n (f g₀)).toFinset := card_le_card_of_injOn f (by aesop (add safe unfold Set.MapsTo)) hf.injOn _ ≤ _ := (nthRoots n (f g₀)).toFinset_card_le /-- A finite subgroup of the unit group of an integral domain is cyclic. -/ theorem isCyclic_of_subgroup_isDomain [Finite G] (f : G →* R) (hf : Injective f) : IsCyclic G := by classical cases nonempty_fintype G apply isCyclic_of_card_pow_eq_one_le intro n hn exact le_trans (card_nthRoots_subgroup_units f hf hn 1) (card_nthRoots n (f 1)) /-- The unit group of a finite integral domain is cyclic. To support `ℤˣ` and other infinite monoids with finite groups of units, this requires only `Finite Rˣ` rather than deducing it from `Finite R`. -/ instance [Finite Rˣ] : IsCyclic Rˣ := isCyclic_of_subgroup_isDomain (Units.coeHom R) Units.val_injective section variable (S : Subgroup Rˣ) [Finite S] /-- A finite subgroup of the units of an integral domain is cyclic. -/ instance subgroup_units_cyclic : IsCyclic S := by -- Porting note: the original proof used a `coe`, but I was not able to get it to work. apply isCyclic_of_subgroup_isDomain (R := R) (G := S) _ _ · exact MonoidHom.mk (OneHom.mk (fun s => ↑s.val) rfl) (by simp) · exact Units.val_injective.comp Subtype.val_injective end section EuclideanDivision namespace Polynomial variable (K : Type*) [Field K] [Algebra R[X] K] [IsFractionRing R[X] K] theorem div_eq_quo_add_rem_div (f : R[X]) {g : R[X]} (hg : g.Monic) : ∃ q r : R[X], r.degree < g.degree ∧ (algebraMap R[X] K f) / (algebraMap R[X] K g) = algebraMap R[X] K q + (algebraMap R[X] K r) / (algebraMap R[X] K g) := by refine ⟨f /ₘ g, f %ₘ g, ?_, ?_⟩ · exact degree_modByMonic_lt _ hg · have hg' : algebraMap R[X] K g ≠ 0 := -- Porting note: the proof was `by exact_mod_cast Monic.ne_zero hg` (map_ne_zero_iff _ (IsFractionRing.injective R[X] K)).mpr (Monic.ne_zero hg) field_simp [hg'] -- Porting note: `norm_cast` was here, but does nothing. rw [add_comm, mul_comm, ← map_mul, ← map_add, modByMonic_add_div f hg] end Polynomial end EuclideanDivision variable [Fintype G] /-- In an integral domain, a sum indexed by a nontrivial homomorphism from a finite group is zero. -/ theorem sum_hom_units_eq_zero (f : G →* R) (hf : f ≠ 1) : ∑ g : G, f g = 0 := by classical obtain ⟨x, hx⟩ : ∃ x : MonoidHom.range f.toHomUnits, ∀ y : MonoidHom.range f.toHomUnits, y ∈ Submonoid.powers x := IsCyclic.exists_monoid_generator have hx1 : x ≠ 1 := by rintro rfl apply hf ext g rw [MonoidHom.one_apply] obtain ⟨n, hn⟩ := hx ⟨f.toHomUnits g, g, rfl⟩ rwa [Subtype.ext_iff, Units.ext_iff, Subtype.coe_mk, MonoidHom.coe_toHomUnits, one_pow, eq_comm] at hn replace hx1 : (x.val : R) - 1 ≠ 0 := -- Porting note: was `(x : R)` fun h => hx1 (Subtype.eq (Units.ext (sub_eq_zero.1 h))) let c := #{g | f.toHomUnits g = 1} calc ∑ g : G, f g = ∑ g : G, (f.toHomUnits g : R) := rfl _ = ∑ u ∈ univ.image f.toHomUnits, #{g | f.toHomUnits g = u} • (u : R) := sum_comp ((↑) : Rˣ → R) f.toHomUnits _ = ∑ u ∈ univ.image f.toHomUnits, c • (u : R) := (sum_congr rfl fun u hu => congr_arg₂ _ ?_ rfl) -- remaining goal 1, proven below -- Porting note: have to change `(b : R)` into `((b : Rˣ) : R)` _ = ∑ b : MonoidHom.range f.toHomUnits, c • ((b : Rˣ) : R) := (Finset.sum_subtype _ (by simp) _) _ = c • ∑ b : MonoidHom.range f.toHomUnits, ((b : Rˣ) : R) := smul_sum.symm _ = c • (0 : R) := congr_arg₂ _ rfl ?_ -- remaining goal 2, proven below _ = (0 : R) := smul_zero _ · -- remaining goal 1 show #{g : G | f.toHomUnits g = u} = c apply MonoidHom.card_fiber_eq_of_mem_range f.toHomUnits · simpa only [mem_image, mem_univ, true_and, Set.mem_range] using hu · exact ⟨1, f.toHomUnits.map_one⟩ -- remaining goal 2 show (∑ b : MonoidHom.range f.toHomUnits, ((b : Rˣ) : R)) = 0 calc (∑ b : MonoidHom.range f.toHomUnits, ((b : Rˣ) : R)) = ∑ n ∈ range (orderOf x), ((x : Rˣ) : R) ^ n := Eq.symm <| sum_nbij (x ^ ·) (by simp only [mem_univ, forall_true_iff]) (by simpa using pow_injOn_Iio_orderOf) (fun b _ => let ⟨n, hn⟩ := hx b ⟨n % orderOf x, mem_range.2 (Nat.mod_lt _ (orderOf_pos _)), -- Porting note: have to use `dsimp` to apply the function by dsimp at hn ⊢; rw [pow_mod_orderOf, hn]⟩) (by simp only [imp_true_iff, Subgroup.coe_pow, Units.val_pow_eq_pow_val]) _ = 0 := ?_ rw [← mul_left_inj' hx1, zero_mul, geom_sum_mul] norm_cast simp [pow_orderOf_eq_one] /-- In an integral domain, a sum indexed by a homomorphism from a finite group is zero, unless the homomorphism is trivial, in which case the sum is equal to the cardinality of the group. -/ theorem sum_hom_units (f : G →* R) [Decidable (f = 1)] : ∑ g : G, f g = if f = 1 then Fintype.card G else 0 := by split_ifs with h · simp [h] · rw [cast_zero] -- Porting note: added exact sum_hom_units_eq_zero f h end
OrderedCancelAddCommMonoidWithBounds.lean
/- Copyright (c) 2023 Martin Dvorak. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Martin Dvorak -/ import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.Order.BoundedOrder.Lattice /-! # Do not combine OrderedCancelAddCommMonoid with BoundedOrder This file shows that combining `OrderedCancelAddCommMonoid` with `BoundedOrder` is not a good idea, as such a structure must be trivial (`⊥ = x = ⊤` for all `x`). The same applies to any superclasses, e.g. combining `StrictOrderedSemiring` with `CompleteLattice`. -/ example {α : Type*} [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] [BoundedOrder α] [Nontrivial α] : False := have top_pos := pos_of_lt_add_right (bot_le.trans_lt (add_lt_add_left bot_lt_top (⊥ : α))) have top_add_top_lt_self := lt_add_of_le_of_pos (@le_top _ _ _ (⊤ + ⊤)) top_pos top_add_top_lt_self.false
archimedean.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 order ssralg poly ssrnum ssrint. (******************************************************************************) (* Archimedean structures *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* This file defines some numeric structures extended with the Archimedean *) (* axiom. To use this file, insert "Import Num.Theory." and optionally *) (* "Import Num.Def." before your scripts as in the ssrnum library. *) (* The modules provided by this library subsume those from ssrnum. *) (* *) (* This file defines the following structures: *) (* *) (* archiNumDomainType == numDomainType with the Archimedean axiom *) (* The HB class is called ArchiNumDomain. *) (* archiNumFieldType == numFieldType with the Archimedean axiom *) (* The HB class is called ArchiNumField. *) (* archiClosedFieldType == closedFieldType with the Archimedean axiom *) (* The HB class is called ArchiClosedField. *) (* archiRealDomainType == realDomainType with the Archimedean axiom *) (* The HB class is called ArchiRealDomain. *) (* archiRealFieldType == realFieldType with the Archimedean axiom *) (* The HB class is called ArchiRealField. *) (* archiRcfType == rcfType with the Archimedean axiom *) (* The HB class is called ArchiRealClosedField. *) (* *) (* Over these structures, we have the following operations: *) (* x \is a Num.int <=> x is an integer, i.e., x = m%:~R for some m : int *) (* x \is a Num.nat <=> x is a natural number, i.e., x = m%:R for some m : nat*) (* Num.floor x == the m : int such that m%:~R <= x < (m + 1)%:~R *) (* when x \is a Num.real, otherwise 0%Z *) (* Num.ceil x == the m : int such that (m - 1)%:~R < x <= m%:~R *) (* when x \is a Num.real, otherwise 0%Z *) (* Num.truncn x == the n : nat such that n%:R <= x < n.+1%:R *) (* when 0 <= n, otherwise 0%N *) (* Num.bound x == an upper bound for x, i.e., an n such that `|x| < n%:R *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Import Order.TTheory GRing.Theory Num.Theory. Module Num. Import Num.Def. HB.mixin Record NumDomain_hasFloorCeilTruncn R of Num.NumDomain R := { floor : R -> int; ceil : R -> int; truncn : R -> nat; int_num_subdef : pred R; nat_num_subdef : pred R; floor_subproof : forall x, if x \is Rreal then (floor x)%:~R <= x < (floor x + 1)%:~R else floor x == 0; ceil_subproof : forall x, ceil x = - floor (- x); truncn_subproof : forall x, truncn x = if floor x is Posz n then n else 0; int_num_subproof : forall x, reflect (exists n, x = n%:~R) (int_num_subdef x); nat_num_subproof : forall x, reflect (exists n, x = n%:R) (nat_num_subdef x); }. #[short(type="archiNumDomainType")] HB.structure Definition ArchiNumDomain := { R of NumDomain_hasFloorCeilTruncn R & Num.NumDomain R }. Module ArchiNumDomainExports. Bind Scope ring_scope with ArchiNumDomain.sort. End ArchiNumDomainExports. HB.export ArchiNumDomainExports. #[short(type="archiNumFieldType")] HB.structure Definition ArchiNumField := { R of NumDomain_hasFloorCeilTruncn R & Num.NumField R }. Module ArchiNumFieldExports. Bind Scope ring_scope with ArchiNumField.sort. End ArchiNumFieldExports. HB.export ArchiNumFieldExports. #[short(type="archiClosedFieldType")] HB.structure Definition ArchiClosedField := { R of NumDomain_hasFloorCeilTruncn R & Num.ClosedField R }. Module ArchiClosedFieldExports. Bind Scope ring_scope with ArchiClosedField.sort. End ArchiClosedFieldExports. HB.export ArchiClosedFieldExports. #[short(type="archiRealDomainType")] HB.structure Definition ArchiRealDomain := { R of NumDomain_hasFloorCeilTruncn R & Num.RealDomain R }. Module ArchiRealDomainExports. Bind Scope ring_scope with ArchiRealDomain.sort. End ArchiRealDomainExports. HB.export ArchiRealDomainExports. #[short(type="archiRealFieldType")] HB.structure Definition ArchiRealField := { R of NumDomain_hasFloorCeilTruncn R & Num.RealField R }. Module ArchiRealFieldExports. Bind Scope ring_scope with ArchiRealField.sort. End ArchiRealFieldExports. HB.export ArchiRealFieldExports. #[short(type="archiRcfType")] HB.structure Definition ArchiRealClosedField := { R of NumDomain_hasFloorCeilTruncn R & Num.RealClosedField R }. Module ArchiRealClosedFieldExports. Bind Scope ring_scope with ArchiRealClosedField.sort. End ArchiRealClosedFieldExports. HB.export ArchiRealClosedFieldExports. Section Def. Context {R : archiNumDomainType}. Definition nat_num : qualifier 1 R := [qualify a x : R | nat_num_subdef x]. Definition int_num : qualifier 1 R := [qualify a x : R | int_num_subdef x]. Definition bound (x : R) := (truncn `|x|).+1. End Def. Arguments floor {R} : rename, simpl never. Arguments ceil {R} : rename, simpl never. Arguments truncn {R} : rename, simpl never. Arguments nat_num {R} : simpl never. Arguments int_num {R} : simpl never. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn.")] Notation trunc := truncn. Module Def. Export ssrnum.Num.Def. Notation truncn := truncn. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn.")] Notation trunc := truncn. Notation floor := floor. Notation ceil := ceil. Notation nat_num := nat_num. Notation int_num := int_num. Notation archi_bound := bound. End Def. Module intArchimedean. Section intArchimedean. Implicit Types n : int. Lemma floorP n : if n \is Rreal then n%:~R <= n < (n + 1)%:~R else n == 0. Proof. by rewrite num_real !intz ltzD1 lexx. Qed. Lemma intrP n : reflect (exists m, n = m%:~R) true. Proof. by apply: ReflectT; exists n; rewrite intz. Qed. Lemma natrP n : reflect (exists m, n = m%:R) (0 <= n). Proof. apply: (iffP idP); last by case=> m ->; rewrite ler0n. by case: n => // n _; exists n; rewrite natz. Qed. End intArchimedean. End intArchimedean. #[export] HB.instance Definition _ := @NumDomain_hasFloorCeilTruncn.Build int id id _ xpredT Rnneg_pred intArchimedean.floorP (fun=> esym (opprK _)) (fun=> erefl) intArchimedean.intrP intArchimedean.natrP. Module Import Theory. Export ssrnum.Num.Theory. Section ArchiNumDomainTheory. Variable R : archiNumDomainType. Implicit Types x y z : R. Local Notation truncn := (@truncn R). Local Notation floor := (@floor R). Local Notation ceil := (@ceil R). Local Notation nat_num := (@Def.nat_num R). Local Notation int_num := (@Def.int_num R). Local Lemma floorP x : if x \is Rreal then (floor x)%:~R <= x < (floor x + 1)%:~R else floor x == 0. Proof. exact: floor_subproof. Qed. Lemma floorNceil x : floor x = - ceil (- x). Proof. by rewrite ceil_subproof !opprK. Qed. Lemma ceilNfloor x : ceil x = - floor (- x). Proof. exact: ceil_subproof. Qed. Lemma truncEfloor x : truncn x = if floor x is Posz n then n else 0. Proof. exact: truncn_subproof. Qed. Lemma natrP x : reflect (exists n, x = n%:R) (x \is a nat_num). Proof. exact: nat_num_subproof. Qed. Lemma intrP x : reflect (exists m, x = m%:~R) (x \is a int_num). Proof. exact: int_num_subproof. Qed. (* int_num and nat_num *) Lemma intr_int m : m%:~R \is a int_num. Proof. by apply/intrP; exists m. Qed. Lemma natr_nat n : n%:R \is a nat_num. Proof. by apply/natrP; exists n. Qed. #[local] Hint Resolve intr_int natr_nat : core. Lemma rpred_int_num (S : subringClosed R) x : x \is a int_num -> x \in S. Proof. by move=> /intrP[n ->]; rewrite rpred_int. Qed. Lemma rpred_nat_num (S : semiringClosed R) x : x \is a nat_num -> x \in S. Proof. by move=> /natrP[n ->]; apply: rpred_nat. Qed. Lemma int_num0 : 0 \is a int_num. Proof. exact: (intr_int 0). Qed. Lemma int_num1 : 1 \is a int_num. Proof. exact: (intr_int 1). Qed. Lemma nat_num0 : 0 \is a nat_num. Proof. exact: (natr_nat 0). Qed. Lemma nat_num1 : 1 \is a nat_num. Proof. exact: (natr_nat 1). Qed. #[local] Hint Resolve int_num0 int_num1 nat_num0 nat_num1 : core. Fact int_num_subring : subring_closed int_num. Proof. by split=> // _ _ /intrP[n ->] /intrP[m ->]; rewrite -(intrB, intrM). Qed. #[export] HB.instance Definition _ := GRing.isSubringClosed.Build R int_num_subdef int_num_subring. Fact nat_num_semiring : semiring_closed nat_num. Proof. by do 2![split] => //= _ _ /natrP[n ->] /natrP[m ->]; rewrite -(natrD, natrM). Qed. #[export] HB.instance Definition _ := GRing.isSemiringClosed.Build R nat_num_subdef nat_num_semiring. Lemma Rreal_nat : {subset nat_num <= Rreal}. Proof. exact: rpred_nat_num. Qed. Lemma intr_nat : {subset nat_num <= int_num}. Proof. by move=> _ /natrP[n ->]; rewrite pmulrn intr_int. Qed. Lemma Rreal_int : {subset int_num <= Rreal}. Proof. exact: rpred_int_num. Qed. Lemma intrE x : (x \is a int_num) = (x \is a nat_num) || (- x \is a nat_num). Proof. apply/idP/orP => [/intrP[[n|n] ->]|[]/intr_nat]; rewrite ?rpredN //. by left; apply/natrP; exists n. by rewrite NegzE intrN opprK; right; apply/natrP; exists n.+1. Qed. Lemma intr_normK x : x \is a int_num -> `|x| ^+ 2 = x ^+ 2. Proof. by move/Rreal_int/real_normK. Qed. Lemma natr_normK x : x \is a nat_num -> `|x| ^+ 2 = x ^+ 2. Proof. by move/Rreal_nat/real_normK. Qed. Lemma natr_norm_int x : x \is a int_num -> `|x| \is a nat_num. Proof. by move=> /intrP[m ->]; rewrite -intr_norm rpred_nat_num ?natr_nat. Qed. Lemma natr_ge0 x : x \is a nat_num -> 0 <= x. Proof. by move=> /natrP[n ->]; apply: ler0n. Qed. Lemma natr_gt0 x : x \is a nat_num -> (0 < x) = (x != 0). Proof. by move/natr_ge0; case: comparableP. Qed. Lemma natrEint x : (x \is a nat_num) = (x \is a int_num) && (0 <= x). Proof. apply/idP/andP=> [Nx | [Zx x_ge0]]; first by rewrite intr_nat ?natr_ge0. by rewrite -(ger0_norm x_ge0) natr_norm_int. Qed. Lemma intrEge0 x : 0 <= x -> (x \is a int_num) = (x \is a nat_num). Proof. by rewrite natrEint andbC => ->. Qed. Lemma intrEsign x : x \is a int_num -> x = (-1) ^+ (x < 0)%R * `|x|. Proof. by move/Rreal_int/realEsign. Qed. Lemma norm_natr x : x \is a nat_num -> `|x| = x. Proof. by move/natr_ge0/ger0_norm. Qed. Lemma natr_exp_even x n : ~~ odd n -> x \is a int_num -> x ^+ n \is a nat_num. Proof. move=> n_oddF x_intr. by rewrite natrEint rpredX //= real_exprn_even_ge0 // Rreal_int. Qed. Lemma norm_intr_ge1 x : x \is a int_num -> x != 0 -> 1 <= `|x|. Proof. rewrite -normr_eq0 => /natr_norm_int/natrP[n ->]. by rewrite pnatr_eq0 ler1n lt0n. Qed. Lemma sqr_intr_ge1 x : x \is a int_num -> x != 0 -> 1 <= x ^+ 2. Proof. by move=> Zx nz_x; rewrite -intr_normK // expr_ge1 ?normr_ge0 ?norm_intr_ge1. Qed. Lemma intr_ler_sqr x : x \is a int_num -> x <= x ^+ 2. Proof. move=> Zx; have [-> | nz_x] := eqVneq x 0; first by rewrite expr0n. apply: le_trans (_ : `|x| <= _); first by rewrite real_ler_norm ?Rreal_int. by rewrite -intr_normK // ler_eXnr // norm_intr_ge1. Qed. (* floor and int_num *) Lemma real_floor_itv x : x \is Rreal -> (floor x)%:~R <= x < (floor x + 1)%:~R. Proof. by case: ifP (floorP x). Qed. Lemma real_floor_le x : x \is Rreal -> (floor x)%:~R <= x. Proof. by case/real_floor_itv/andP. Qed. Lemma real_floorD1_gt x : x \is Rreal -> x < (floor x + 1)%:~R. Proof. by case/real_floor_itv/andP. Qed. Lemma floor_def x m : m%:~R <= x < (m + 1)%:~R -> floor x = m. Proof. case/andP=> lemx ltxm1; apply/eqP; rewrite eq_le -!ltzD1. move: (ger_real lemx); rewrite realz => /real_floor_itv/andP[lefx ltxf1]. by rewrite -!(ltr_int R) 2?(@le_lt_trans _ _ x). Qed. (* TODO: rename to real_floor_ge_int, once the currently deprecated one has been removed *) Lemma real_floor_ge_int_tmp x n : x \is Rreal -> (n <= floor x) = (n%:~R <= x). Proof. move=> /real_floor_itv /andP[lefx ltxf1]; apply/idP/idP => lenx. by apply: le_trans lefx; rewrite ler_int. by rewrite -ltzD1 -(ltr_int R); apply: le_lt_trans ltxf1. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use real_floor_ge_int_tmp instead.")] Lemma real_floor_ge_int x n : x \is Rreal -> (n%:~R <= x) = (n <= floor x). Proof. by move=> ?; rewrite real_floor_ge_int_tmp. Qed. Lemma real_floor_lt_int x n : x \is Rreal -> (floor x < n) = (x < n%:~R). Proof. by move=> ?; rewrite [RHS]real_ltNge ?realz -?real_floor_ge_int_tmp -?ltNge. Qed. Lemma real_floor_eq x n : x \is Rreal -> (floor x == n) = (n%:~R <= x < (n + 1)%:~R). Proof. by move=> xr; apply/eqP/idP => [<-|]; [exact: real_floor_itv|exact: floor_def]. Qed. Lemma le_floor : {homo floor : x y / x <= y}. Proof. move=> x y lexy; move: (floorP x) (floorP y); rewrite (ger_real lexy). case: ifP => [_ /andP[lefx _] /andP[_] | _ /eqP-> /eqP-> //]. by move=> /(le_lt_trans lexy) /(le_lt_trans lefx); rewrite ltr_int ltzD1. Qed. Lemma intrKfloor : cancel intr floor. Proof. by move=> m; apply: floor_def; rewrite lexx rmorphD ltrDl ltr01. Qed. Lemma natr_int n : n%:R \is a int_num. Proof. by rewrite intrE natr_nat. Qed. #[local] Hint Resolve natr_int : core. Lemma intrEfloor x : x \is a int_num = ((floor x)%:~R == x). Proof. by apply/intrP/eqP => [[n ->] | <-]; [rewrite intrKfloor | exists (floor x)]. Qed. Lemma floorK : {in int_num, cancel floor intr}. Proof. by move=> z; rewrite intrEfloor => /eqP. Qed. Lemma floor0 : floor 0 = 0. Proof. exact: intrKfloor 0. Qed. Lemma floor1 : floor 1 = 1. Proof. exact: intrKfloor 1. Qed. #[local] Hint Resolve floor0 floor1 : core. Lemma real_floorDzr : {in int_num & Rreal, {morph floor : x y / x + y}}. Proof. move=> _ y /intrP[m ->] Ry; apply: floor_def. by rewrite -addrA 2!rmorphD /= intrKfloor lerD2l ltrD2l real_floor_itv. Qed. Lemma real_floorDrz : {in Rreal & int_num, {morph floor : x y / x + y}}. Proof. by move=> x y xr yz; rewrite addrC real_floorDzr // addrC. Qed. Lemma floorN : {in int_num, {morph floor : x / - x}}. Proof. by move=> _ /intrP[m ->]; rewrite -rmorphN !intrKfloor. Qed. Lemma floorM : {in int_num &, {morph floor : x y / x * y}}. Proof. by move=> _ _ /intrP[m1 ->] /intrP[m2 ->]; rewrite -rmorphM !intrKfloor. Qed. Lemma floorX n : {in int_num, {morph floor : x / x ^+ n}}. Proof. by move=> _ /intrP[m ->]; rewrite -rmorphXn !intrKfloor. Qed. Lemma real_floor_ge0 x : x \is Rreal -> (0 <= floor x) = (0 <= x). Proof. by move=> ?; rewrite real_floor_ge_int_tmp. Qed. Lemma floor_lt0 x : (floor x < 0) = (x < 0). Proof. case: ifP (floorP x) => [xr _ | xr /eqP <-]; first by rewrite real_floor_lt_int. by rewrite ltxx; apply/esym/(contraFF _ xr)/ltr0_real. Qed. Lemma real_floor_le0 x : x \is Rreal -> (floor x <= 0) = (x < 1). Proof. by move=> ?; rewrite -ltzD1 add0r real_floor_lt_int. Qed. Lemma floor_gt0 x : (floor x > 0) = (x >= 1). Proof. case: ifP (floorP x) => [xr _ | xr /eqP->]. by rewrite gtz0_ge1 real_floor_ge_int_tmp. by rewrite ltxx; apply/esym/(contraFF _ xr)/ger1_real. Qed. Lemma floor_neq0 x : (floor x != 0) = (x < 0) || (x >= 1). Proof. case: ifP (floorP x) => [xr _ | xr /eqP->]; rewrite ?eqxx/=. by rewrite neq_lt floor_lt0 floor_gt0. by apply/esym/(contraFF _ xr) => /orP[/ltr0_real|/ger1_real]. Qed. Lemma floorpK : {in polyOver int_num, cancel (map_poly floor) (map_poly intr)}. Proof. move=> p /(all_nthP 0) Zp; apply/polyP=> i. rewrite coef_map coef_map_id0 //= -[p]coefK coef_poly. by case: ifP => [/Zp/floorK // | _]; rewrite floor0. Qed. Lemma floorpP (p : {poly R}) : p \is a polyOver int_num -> {q | p = map_poly intr q}. Proof. by exists (map_poly floor p); rewrite floorpK. Qed. (* ceil and int_num *) Lemma real_ceil_itv x : x \is Rreal -> (ceil x - 1)%:~R < x <= (ceil x)%:~R. Proof. rewrite ceilNfloor -opprD !intrN ltrNl lerNr andbC -realN. exact: real_floor_itv. Qed. Lemma real_ceilB1_lt x : x \is Rreal -> (ceil x - 1)%:~R < x. Proof. by case/real_ceil_itv/andP. Qed. Lemma real_ceil_ge x : x \is Rreal -> x <= (ceil x)%:~R. Proof. by case/real_ceil_itv/andP. Qed. Lemma ceil_def x m : (m - 1)%:~R < x <= m%:~R -> ceil x = m. Proof. rewrite -ltrN2 -lerN2 andbC -!intrN opprD opprK ceilNfloor. by move=> /floor_def ->; rewrite opprK. Qed. (* TODO: rename to real_ceil_le_int, once the currently deprecated one has been removed *) Lemma real_ceil_le_int_tmp x n : x \is Rreal -> (ceil x <= n) = (x <= n%:~R). Proof. rewrite ceilNfloor lerNl -realN => /real_floor_ge_int_tmp ->. by rewrite intrN lerN2. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use real_ceil_le_int_tmp instead.")] Lemma real_ceil_le_int x n : x \is Rreal -> x <= n%:~R = (ceil x <= n). Proof. by move=> ?; rewrite real_ceil_le_int_tmp. Qed. Lemma real_ceil_gt_int x n : x \is Rreal -> (n < ceil x) = (n%:~R < x). Proof. by move=> ?; rewrite [RHS]real_ltNge ?realz -?real_ceil_le_int_tmp ?ltNge. Qed. Lemma real_ceil_eq x n : x \is Rreal -> (ceil x == n) = ((n - 1)%:~R < x <= n%:~R). Proof. by move=> xr; apply/eqP/idP => [<-|]; [exact: real_ceil_itv|exact: ceil_def]. Qed. (* TODO: rename to le_ceil, once the currently deprecated one has been removed *) Lemma le_ceil_tmp : {homo ceil : x y / x <= y}. Proof. by move=> x y lexy; rewrite !ceilNfloor lerN2 le_floor ?lerN2. Qed. Lemma intrKceil : cancel intr ceil. Proof. by move=> m; rewrite ceilNfloor -intrN intrKfloor opprK. Qed. Lemma intrEceil x : x \is a int_num = ((ceil x)%:~R == x). Proof. by rewrite -rpredN intrEfloor -eqr_oppLR -intrN -ceilNfloor. Qed. Lemma ceilK : {in int_num, cancel ceil intr}. Proof. by move=> z; rewrite intrEceil => /eqP. Qed. Lemma ceil0 : ceil 0 = 0. Proof. exact: intrKceil 0. Qed. Lemma ceil1 : ceil 1 = 1. Proof. exact: intrKceil 1. Qed. #[local] Hint Resolve ceil0 ceil1 : core. Lemma real_ceilDzr : {in int_num & Rreal, {morph ceil : x y / x + y}}. Proof. move=> x y x_int y_real. by rewrite ceilNfloor opprD real_floorDzr ?rpredN // opprD -!ceilNfloor. Qed. Lemma real_ceilDrz : {in Rreal & int_num, {morph ceil : x y / x + y}}. Proof. by move=> x y xr yz; rewrite addrC real_ceilDzr // addrC. Qed. Lemma ceilN : {in int_num, {morph ceil : x / - x}}. Proof. by move=> ? ?; rewrite !ceilNfloor !opprK floorN. Qed. Lemma ceilM : {in int_num &, {morph ceil : x y / x * y}}. Proof. by move=> _ _ /intrP[m1 ->] /intrP[m2 ->]; rewrite -rmorphM !intrKceil. Qed. Lemma ceilX n : {in int_num, {morph ceil : x / x ^+ n}}. Proof. by move=> _ /intrP[m ->]; rewrite -rmorphXn !intrKceil. Qed. Lemma real_ceil_ge0 x : x \is Rreal -> (0 <= ceil x) = (-1 < x). Proof. by move=> ?; rewrite ceilNfloor oppr_ge0 real_floor_le0 ?realN 1?ltrNl. Qed. Lemma ceil_lt0 x : (ceil x < 0) = (x <= -1). Proof. by rewrite ceilNfloor oppr_lt0 floor_gt0 lerNr. Qed. Lemma real_ceil_le0 x : x \is Rreal -> (ceil x <= 0) = (x <= 0). Proof. by move=> ?; rewrite real_ceil_le_int_tmp. Qed. Lemma ceil_gt0 x : (ceil x > 0) = (x > 0). Proof. by rewrite ceilNfloor oppr_gt0 floor_lt0 oppr_lt0. Qed. Lemma ceil_neq0 x : (ceil x != 0) = (x <= -1) || (x > 0). Proof. by rewrite ceilNfloor oppr_eq0 floor_neq0 oppr_lt0 lerNr orbC. Qed. Lemma real_ceil_floor x : x \is Rreal -> ceil x = floor x + (x \isn't a int_num). Proof. case Ix: (x \is a int_num) => Rx /=. by apply/eqP; rewrite addr0 ceilNfloor eqr_oppLR floorN. apply/ceil_def; rewrite addrK; move: (real_floor_itv Rx). by rewrite le_eqVlt -intrEfloor Ix /= => /andP[-> /ltW]. Qed. (* Relating Cnat and oldCnat. *) Lemma truncn_floor x : truncn x = if 0 <= x then `|floor x|%N else 0%N. Proof. move: (floorP x); rewrite truncEfloor realE. have [/le_floor|_]/= := boolP (0 <= x); first by rewrite floor0; case: floor. by case: ifP => [/le_floor|_ /eqP->//]; rewrite floor0; case: floor => [[]|]. Qed. (* trunc and nat_num *) Local Lemma truncnP x : if 0 <= x then (truncn x)%:R <= x < (truncn x).+1%:R else truncn x == 0%N. Proof. rewrite truncn_floor. case: (boolP (0 <= x)) => //= /[dup] /le_floor + /ger0_real/real_floor_itv. by rewrite floor0; case: (floor x) => // n _; rewrite absz_nat addrC -intS. Qed. Lemma truncn_itv x : 0 <= x -> (truncn x)%:R <= x < (truncn x).+1%:R. Proof. by move=> x_ge0; move: (truncnP x); rewrite x_ge0. Qed. Lemma truncn_le x : (truncn x)%:R <= x = (0 <= x). Proof. by case: ifP (truncnP x) => [+ /andP[] | + /eqP->//]. Qed. Lemma real_truncnS_gt x : x \is Rreal -> x < (truncn x).+1%:R. Proof. by move/real_ge0P => [/truncn_itv/andP[]|/lt_le_trans->]. Qed. Lemma truncn_def x n : n%:R <= x < n.+1%:R -> truncn x = n. Proof. case/andP=> lemx ltxm1; apply/eqP; rewrite eqn_leq -ltnS -[(n <= _)%N]ltnS. have/truncn_itv/andP[lefx ltxf1]: 0 <= x by apply: le_trans lemx; apply: ler0n. by rewrite -!(ltr_nat R) 2?(@le_lt_trans _ _ x). Qed. Lemma truncn_ge_nat x n : 0 <= x -> (n <= truncn x)%N = (n%:R <= x). Proof. move=> /truncn_itv /andP[letx ltxt1]; apply/idP/idP => lenx. by apply: le_trans letx; rewrite ler_nat. by rewrite -ltnS -(ltr_nat R); apply: le_lt_trans ltxt1. Qed. Lemma truncn_gt_nat x n : (n < truncn x)%N = (n.+1%:R <= x). Proof. case: ifP (truncnP x) => [x0 _ | x0 /eqP->]; first by rewrite truncn_ge_nat. by rewrite ltn0; apply/esym/(contraFF _ x0)/le_trans. Qed. Lemma truncn_lt_nat x n : 0 <= x -> (truncn x < n)%N = (x < n%:R). Proof. by move=> ?; rewrite real_ltNge ?ger0_real// ltnNge truncn_ge_nat. Qed. Lemma real_truncn_le_nat x n : x \is Rreal -> (truncn x <= n)%N = (x < n.+1%:R). Proof. by move=> ?; rewrite real_ltNge// leqNgt truncn_gt_nat. Qed. Lemma truncn_eq x n : 0 <= x -> (truncn x == n) = (n%:R <= x < n.+1%:R). Proof. by move=> xr; apply/eqP/idP => [<-|]; [exact: truncn_itv|exact: truncn_def]. Qed. Lemma le_truncn : {homo truncn : x y / x <= y >-> (x <= y)%N}. Proof. move=> x y lexy; move: (truncnP x) (truncnP y). case: ifP => [x0 /andP[letx _] | x0 /eqP->//]. case: ifP => [y0 /andP[_] | y0 /eqP->]; [|by rewrite (le_trans x0 lexy) in y0]. by move=> /(le_lt_trans lexy) /(le_lt_trans letx); rewrite ltr_nat ltnS. Qed. Lemma natrK : cancel (GRing.natmul 1) truncn. Proof. by move=> m; apply: truncn_def; rewrite ler_nat ltr_nat ltnS leqnn. Qed. Lemma natrEtruncn x : (x \is a nat_num) = ((truncn x)%:R == x). Proof. by apply/natrP/eqP => [[n ->]|<-]; [rewrite natrK | exists (truncn x)]. Qed. Lemma archi_boundP x : 0 <= x -> x < (bound x)%:R. Proof. move=> x_ge0; case/truncn_itv/andP: (normr_ge0 x) => _. exact/le_lt_trans/real_ler_norm/ger0_real. Qed. Lemma truncnK : {in nat_num, cancel truncn (GRing.natmul 1)}. Proof. by move=> x; rewrite natrEtruncn => /eqP. Qed. Lemma truncn0 : truncn 0 = 0%N. Proof. exact: natrK 0%N. Qed. Lemma truncn1 : truncn 1 = 1%N. Proof. exact: natrK 1%N. Qed. #[local] Hint Resolve truncn0 truncn1 : core. Lemma truncnD : {in nat_num & Rnneg, {morph truncn : x y / x + y >-> (x + y)%N}}. Proof. move=> _ y /natrP[n ->] y_ge0; apply: truncn_def. by rewrite -addnS !natrD !natrK lerD2l ltrD2l truncn_itv. Qed. Lemma truncnM : {in nat_num &, {morph truncn : x y / x * y >-> (x * y)%N}}. Proof. by move=> _ _ /natrP[n1 ->] /natrP[n2 ->]; rewrite -natrM !natrK. Qed. Lemma truncnX n : {in nat_num, {morph truncn : x / x ^+ n >-> (x ^ n)%N}}. Proof. by move=> _ /natrP[n1 ->]; rewrite -natrX !natrK. Qed. Lemma truncn_gt0 x : (0 < truncn x)%N = (1 <= x). Proof. case: ifP (truncnP x) => [x0 | x0 /eqP<-]; first by rewrite truncn_ge_nat. by rewrite ltnn; apply/esym/(contraFF _ x0)/le_trans. Qed. Lemma truncn0Pn x : reflect (truncn x = 0%N) (~~ (1 <= x)). Proof. by rewrite -truncn_gt0 -eqn0Ngt; apply: eqP. Qed. Lemma sum_truncnK I r (P : pred I) F : (forall i, P i -> F i \is a nat_num) -> (\sum_(i <- r | P i) truncn (F i))%:R = \sum_(i <- r | P i) F i. Proof. by rewrite natr_sum => natr; apply: eq_bigr => i /natr /truncnK. Qed. Lemma prod_truncnK I r (P : pred I) F : (forall i, P i -> F i \is a nat_num) -> (\prod_(i <- r | P i) truncn (F i))%:R = \prod_(i <- r | P i) F i. Proof. by rewrite natr_prod => natr; apply: eq_bigr => i /natr /truncnK. Qed. Lemma natr_sum_eq1 (I : finType) (P : pred I) (F : I -> R) : (forall i, P i -> F i \is a nat_num) -> \sum_(i | P i) F i = 1 -> {i : I | [/\ P i, F i = 1 & forall j, j != i -> P j -> F j = 0]}. Proof. move=> natF /eqP; rewrite -sum_truncnK// -[1]/1%:R eqr_nat => /sum_nat_eq1 exi. have [i /and3P[Pi /eqP f1 /forallP a]] : {i : I | [&& P i, truncn (F i) == 1 & [forall j : I, ((j != i) ==> P j ==> (truncn (F j) == 0))]]}. apply/sigW; have [i [Pi /eqP f1 a]] := exi; exists i; apply/and3P; split=> //. by apply/forallP => j; apply/implyP => ji; apply/implyP => Pj; apply/eqP/a. exists i; split=> [//||j ji Pj]; rewrite -[LHS]truncnK ?natF ?f1//; apply/eqP. by rewrite -[0]/0%:R eqr_nat; apply: implyP Pj; apply: implyP ji; apply: a. Qed. Lemma natr_mul_eq1 x y : x \is a nat_num -> y \is a nat_num -> (x * y == 1) = (x == 1) && (y == 1). Proof. by do 2!move/truncnK <-; rewrite -natrM !pnatr_eq1 muln_eq1. Qed. Lemma natr_prod_eq1 (I : finType) (P : pred I) (F : I -> R) : (forall i, P i -> F i \is a nat_num) -> \prod_(i | P i) F i = 1 -> forall i, P i -> F i = 1. Proof. move=> natF /eqP; rewrite -prod_truncnK// -[1]/1%:R eqr_nat prod_nat_seq_eq1. move/allP => a i Pi; apply/eqP; rewrite -[F i]truncnK ?natF// eqr_nat. by apply: implyP Pi; apply: a; apply: mem_index_enum. Qed. (* predCmod *) Variables (U V : lmodType R) (f : {additive U -> V}). Lemma raddfZ_nat a u : a \is a nat_num -> f (a *: u) = a *: f u. Proof. by move=> /natrP[n ->]; apply: raddfZnat. Qed. Lemma rpredZ_nat (S : addrClosed V) : {in nat_num & S, forall z u, z *: u \in S}. Proof. by move=> _ u /natrP[n ->]; apply: rpredZnat. Qed. Lemma raddfZ_int a u : a \is a int_num -> f (a *: u) = a *: f u. Proof. by move=> /intrP[m ->]; rewrite !scaler_int raddfMz. Qed. Lemma rpredZ_int (S : zmodClosed V) : {in int_num & S, forall z u, z *: u \in S}. Proof. by move=> _ u /intrP[m ->] ?; rewrite scaler_int rpredMz. Qed. (* autC *) Implicit Type nu : {rmorphism R -> R}. Lemma aut_natr nu : {in nat_num, nu =1 id}. Proof. by move=> _ /natrP[n ->]; apply: rmorph_nat. Qed. Lemma aut_intr nu : {in int_num, nu =1 id}. Proof. by move=> _ /intrP[m ->]; apply: rmorph_int. Qed. End ArchiNumDomainTheory. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_itv.")] Notation trunc_itv := truncn_itv. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_def.")] Notation trunc_def := truncn_def. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnK.")] Notation truncK := truncnK. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn0.")] Notation trunc0 := truncn0. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn1.")] Notation trunc1 := truncn1. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnD.")] Notation truncD := truncnD. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnM.")] Notation truncM := truncnM. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnX.")] Notation truncX := truncnX. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_gt0.")] Notation trunc_gt0 := truncn_gt0. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn0Pn.")] Notation trunc0Pn := truncn0Pn. #[deprecated(since="mathcomp 2.4.0", note="Renamed to sum_truncnK.")] Notation sum_truncK := sum_truncnK. #[deprecated(since="mathcomp 2.4.0", note="Renamed to prod_truncnK.")] Notation prod_truncK := prod_truncnK. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_floor.")] Notation trunc_floor := truncn_floor. #[deprecated(since="mathcomp 2.4.0", note="Renamed to real_floor_le.")] Notation real_ge_floor := real_floor_le. #[deprecated(since="mathcomp 2.4.0", note="Renamed to real_floorD1_gt.")] Notation real_lt_succ_floor := real_floorD1_gt. #[deprecated(since="mathcomp 2.4.0", note="Renamed to real_ceilB1_lt.")] Notation real_gt_pred_ceil := real_floorD1_gt. #[deprecated(since="mathcomp 2.4.0", note="Renamed to real_ceil_ge.")] Notation real_le_ceil := real_ceil_ge. #[deprecated(since="mathcomp 2.4.0", note="Renamed to le_floor.")] Notation floor_le := le_floor. #[deprecated(since="mathcomp 2.4.0", note="Renamed to le_ceil.")] Notation ceil_le := le_ceil_tmp. #[deprecated(since="mathcomp 2.4.0", note="Renamed to natrEtruncn.")] Notation natrE := natrEtruncn. Arguments natrK {R} _%_N. Arguments intrKfloor {R}. Arguments intrKceil {R}. Arguments natrP {R x}. Arguments intrP {R x}. #[global] Hint Resolve truncn0 truncn1 : core. #[global] Hint Resolve floor0 floor1 : core. #[global] Hint Resolve ceil0 ceil1 : core. #[global] Hint Extern 0 (is_true (_%:R \is a nat_num)) => apply: natr_nat : core. #[global] Hint Extern 0 (is_true (_%:R \in nat_num_subdef)) => apply: natr_nat : core. #[global] Hint Extern 0 (is_true (_%:~R \is a int_num)) => apply: intr_int : core. #[global] Hint Extern 0 (is_true (_%:~R \in int_num_subdef)) => apply: intr_int : core. #[global] Hint Extern 0 (is_true (_%:R \is a int_num)) => apply: natr_int : core. #[global] Hint Extern 0 (is_true (_%:R \in int_num_subdef)) => apply: natr_int : core. #[global] Hint Extern 0 (is_true (0 \is a nat_num)) => apply: nat_num0 : core. #[global] Hint Extern 0 (is_true (0 \in nat_num_subdef)) => apply: nat_num0 : core. #[global] Hint Extern 0 (is_true (1 \is a nat_num)) => apply: nat_num1 : core. #[global] Hint Extern 0 (is_true (1 \in int_num_subdef)) => apply: nat_num1 : core. #[global] Hint Extern 0 (is_true (0 \is a int_num)) => apply: int_num0 : core. #[global] Hint Extern 0 (is_true (0 \in int_num_subdef)) => apply: int_num0 : core. #[global] Hint Extern 0 (is_true (1 \is a int_num)) => apply: int_num1 : core. #[global] Hint Extern 0 (is_true (1 \in int_num_subdef)) => apply: int_num1 : core. Section ArchiRealDomainTheory. Variables (R : archiRealDomainType). Implicit Type x : R. Lemma upper_nthrootP x i : (bound x <= i)%N -> x < 2%:R ^+ i. Proof. case/truncn_itv/andP: (normr_ge0 x) => _ /ltr_normlW xlt le_b_i. by rewrite (lt_le_trans xlt) // -natrX ler_nat (ltn_trans le_b_i) // ltn_expl. Qed. Lemma truncnS_gt x : x < (truncn x).+1%:R. Proof. exact: real_truncnS_gt. Qed. Lemma truncn_le_nat x n : (truncn x <= n)%N = (x < n.+1%:R). Proof. exact: real_truncn_le_nat. Qed. Lemma floor_itv x : (floor x)%:~R <= x < (floor x + 1)%:~R. Proof. exact: real_floor_itv. Qed. (* TODO: rename to floor_le, once the deprecated one has been removed *) Lemma floor_le_tmp x : (floor x)%:~R <= x. Proof. exact: real_floor_le. Qed. Lemma floorD1_gt x : x < (floor x + 1)%:~R. Proof. exact: real_floorD1_gt. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use floor_ge_int_tmp instead.")] Lemma floor_ge_int x n : n%:~R <= x = (n <= floor x). Proof. by rewrite real_floor_ge_int_tmp. Qed. (* TODO: rename to floor_ge_int, once the currently deprecated one has been removed *) Lemma floor_ge_int_tmp x n : (n <= floor x) = (n%:~R <= x). Proof. exact: real_floor_ge_int_tmp. Qed. Lemma floor_lt_int x n : (floor x < n) = (x < n%:~R). Proof. exact: real_floor_lt_int. Qed. Lemma floor_eq x n : (floor x == n) = (n%:~R <= x < (n + 1)%:~R). Proof. exact: real_floor_eq. Qed. Lemma floorDzr : {in @int_num R, {morph floor : x y / x + y}}. Proof. by move=> x xz y; apply/real_floorDzr/num_real. Qed. Lemma floorDrz x y : y \is a int_num -> floor (x + y) = floor x + floor y. Proof. by move=> yz; apply/real_floorDrz/yz/num_real. Qed. Lemma floor_ge0 x : (0 <= floor x) = (0 <= x). Proof. exact: real_floor_ge0. Qed. Lemma floor_le0 x : (floor x <= 0) = (x < 1). Proof. exact: real_floor_le0. Qed. Lemma ceil_itv x : (ceil x - 1)%:~R < x <= (ceil x)%:~R. Proof. exact: real_ceil_itv. Qed. Lemma ceilB1_lt x : (ceil x - 1)%:~R < x. Proof. exact: real_ceilB1_lt. Qed. Lemma ceil_ge x : x <= (ceil x)%:~R. Proof. exact: real_ceil_ge. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use ceil_le_int_tmp instead.")] Lemma ceil_le_int x n : x <= n%:~R = (ceil x <= n). Proof. by rewrite real_ceil_le_int_tmp. Qed. (* TODO: rename to ceil_le_int, once the currently deprecated one has been removed *) Lemma ceil_le_int_tmp x n : (ceil x <= n) = (x <= n%:~R). Proof. exact: real_ceil_le_int_tmp. Qed. Lemma ceil_gt_int x n : (n < ceil x) = (n%:~R < x). Proof. exact: real_ceil_gt_int. Qed. Lemma ceil_eq x n : (ceil x == n) = ((n - 1)%:~R < x <= n%:~R). Proof. exact: real_ceil_eq. Qed. Lemma ceilDzr : {in @int_num R, {morph ceil : x y / x + y}}. Proof. by move=> x xz y; apply/real_ceilDzr/num_real. Qed. Lemma ceilDrz x y : y \is a int_num -> ceil (x + y) = ceil x + ceil y. Proof. by move=> yz; apply/real_ceilDrz/yz/num_real. Qed. Lemma ceil_ge0 x : (0 <= ceil x) = (-1 < x). Proof. exact: real_ceil_ge0. Qed. Lemma ceil_le0 x : (ceil x <= 0) = (x <= 0). Proof. exact: real_ceil_le0. Qed. Lemma ceil_floor x : ceil x = floor x + (x \isn't a int_num). Proof. exact: real_ceil_floor. Qed. End ArchiRealDomainTheory. #[deprecated(since="mathcomp 2.4.0", note="Renamed to floor_le_tmp.")] Notation ge_floor := floor_le_tmp. #[deprecated(since="mathcomp 2.4.0", note="Renamed to floorD1_gt.")] Notation lt_succ_floor := floorD1_gt. #[deprecated(since="mathcomp 2.4.0", note="Renamed to ceilB1_lt.")] Notation gt_pred_ceil := ceilB1_lt. #[deprecated(since="mathcomp 2.4.0", note="Renamed to ceil_ge.")] Notation le_ceil := ceil_ge. Section ArchiNumFieldTheory. (* autLmodC *) Variables (R : archiNumFieldType) (nu : {rmorphism R -> R}). Lemma natr_aut x : (nu x \is a nat_num) = (x \is a nat_num). Proof. by apply/idP/idP=> /[dup] ? /(aut_natr nu) => [/fmorph_inj <-| ->]. Qed. Lemma intr_aut x : (nu x \is a int_num) = (x \is a int_num). Proof. by rewrite !intrE -rmorphN !natr_aut. Qed. End ArchiNumFieldTheory. Section ArchiClosedFieldTheory. Variable R : archiClosedFieldType. Implicit Type x : R. Lemma conj_natr x : x \is a nat_num -> x^* = x. Proof. by move/Rreal_nat/CrealP. Qed. Lemma conj_intr x : x \is a int_num -> x^* = x. Proof. by move/Rreal_int/CrealP. Qed. End ArchiClosedFieldTheory. Section ZnatPred. Lemma Znat_def (n : int) : (n \is a nat_num) = (0 <= n). Proof. by []. Qed. Lemma ZnatP (m : int) : reflect (exists n : nat, m = n) (m \is a nat_num). Proof. by case: m => m; constructor; [exists m | case]. Qed. End ZnatPred. End Theory. (* Factories *) HB.factory Record NumDomain_hasTruncn R of Num.NumDomain R := { trunc : R -> nat; nat_num : pred R; int_num : pred R; truncP : forall x, if 0 <= x then (trunc x)%:R <= x < (trunc x).+1%:R else trunc x == 0; natrE : forall x, nat_num x = ((trunc x)%:R == x); intrE : forall x, int_num x = nat_num x || nat_num (- x); }. #[deprecated(since="mathcomp 2.4.0", note="Use NumDomain_hasTruncn instead.")] Notation NumDomain_isArchimedean R := (NumDomain_hasTruncn R) (only parsing). Module NumDomain_isArchimedean. #[deprecated(since="mathcomp 2.4.0", note="Use NumDomain_hasTruncn.Build instead.")] Notation Build T U := (NumDomain_hasTruncn.Build T U) (only parsing). End NumDomain_isArchimedean. HB.builders Context R of NumDomain_hasTruncn R. Fact trunc_itv x : 0 <= x -> (trunc x)%:R <= x < (trunc x).+1%:R. Proof. by move=> x_ge0; move: (truncP x); rewrite x_ge0. Qed. Definition floor (x : R) : int := if 0 <= x then Posz (trunc x) else if x < 0 then - Posz (trunc (- x) + ~~ int_num x) else 0. Fact floorP x : if x \is Rreal then (floor x)%:~R <= x < (floor x + 1)%:~R else floor x == 0. Proof. rewrite /floor intrE !natrE negb_or realE. case: (comparableP x 0) (@trunc_itv x) => //=; try by rewrite -PoszD addn1 -pmulrn => _ ->. move=> x_lt0 _; move: (truncP x); rewrite lt_geF // => /eqP ->. rewrite gt_eqF //=; move: x_lt0. rewrite [_ + 1]addrC -opprB !intrN lerNl ltrNr andbC -oppr_gt0. move: {x}(- x) => x x_gt0; rewrite PoszD -addrA -PoszD. have ->: Posz ((trunc x)%:R != x) - 1 = - Posz ((trunc x)%:R == x) by case: eqP. have := trunc_itv (ltW x_gt0); rewrite le_eqVlt. case: eqVneq => /=; last first. by rewrite subr0 addn1 -!pmulrn => _ /andP[-> /ltW ->]. by rewrite intrB mulr1z addn0 -!pmulrn => -> _; rewrite gtrBl lexx andbT. Qed. Fact truncE x : trunc x = if floor x is Posz n then n else 0. Proof. rewrite /floor. case: (comparableP x 0) (truncP x) => [+ /eqP ->| |_ /eqP ->|] //=. by case: (_ + _)%N. Qed. Fact trunc_def x n : n%:R <= x < n.+1%:R -> trunc x = n. Proof. case/andP=> lemx ltxm1; apply/eqP; rewrite eqn_leq -ltnS -[(n <= _)%N]ltnS. have/trunc_itv/andP[lefx ltxf1]: 0 <= x by apply: le_trans lemx; apply: ler0n. by rewrite -!(ltr_nat R) 2?(@le_lt_trans _ _ x). Qed. Fact natrK : cancel (GRing.natmul 1) trunc. Proof. by move=> m; apply: trunc_def; rewrite ler_nat ltr_nat ltnS leqnn. Qed. Fact intrP x : reflect (exists n, x = n%:~R) (int_num x). Proof. rewrite intrE !natrE; apply: (iffP idP) => [|[n ->]]; last first. by case: n => n; rewrite ?NegzE ?opprK natrK eqxx // orbT. rewrite -eqr_oppLR !pmulrn -intrN. by move=> /orP[] /eqP<-; [exists (trunc x) | exists (- Posz (trunc (- x)))]. Qed. Fact natrP x : reflect (exists n, x = n%:R) (nat_num x). Proof. rewrite natrE. by apply: (iffP eqP) => [<-|[n ->]]; [exists (trunc x) | rewrite natrK]. Qed. HB.instance Definition _ := @NumDomain_hasFloorCeilTruncn.Build R floor _ trunc int_num nat_num floorP (fun=> erefl) truncE intrP natrP. HB.end. HB.factory Record NumDomain_bounded_isArchimedean R of Num.NumDomain R := { archi_bound_subproof : Num.archimedean_axiom R }. HB.builders Context R of NumDomain_bounded_isArchimedean R. Implicit Type x : R. Definition bound x := sval (sigW (archi_bound_subproof x)). Lemma boundP x : 0 <= x -> x < (bound x)%:R. Proof. by move/ger0_norm=> {1}<-; rewrite /bound; case: (sigW _). Qed. Fact truncn_subproof x : {m | 0 <= x -> m%:R <= x < m.+1%:R }. Proof. have [Rx | _] := boolP (0 <= x); last by exists 0%N. have/ex_minnP[n lt_x_n1 min_n]: exists n, x < n.+1%:R. by exists (bound x); rewrite (lt_trans (boundP Rx)) ?ltr_nat. exists n => _; rewrite {}lt_x_n1 andbT; case: n min_n => //= n min_n. rewrite real_leNgt ?rpred_nat ?ger0_real //; apply/negP => /min_n. by rewrite ltnn. Qed. Definition truncn x := if 0 <= x then sval (truncn_subproof x) else 0%N. Lemma truncnP x : if 0 <= x then (truncn x)%:R <= x < (truncn x).+1%:R else truncn x == 0%N. Proof. rewrite /truncn; case: truncn_subproof => // n hn. by case: ifP => x_ge0; rewrite ?(ifT _ _ x_ge0) ?(ifF _ _ x_ge0) // hn. Qed. HB.instance Definition _ := NumDomain_hasTruncn.Build R truncnP (fun => erefl) (fun => erefl). HB.end. Module Exports. HB.reexport. End Exports. (* Not to pollute the local namespace, we define Num.nat and Num.int here. *) Notation nat := nat_num. Notation int := int_num. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealDomain instead.")] Notation ArchiDomain T := (ArchiRealDomain T). Module ArchiDomain. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealDomain.type instead.")] Notation type := ArchiRealDomain.type. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealDomain.copy instead.")] Notation copy T C := (ArchiRealDomain.copy T C). #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealDomain.on instead.")] Notation on T := (ArchiRealDomain.on T). End ArchiDomain. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField instead.")] Notation ArchiField T := (ArchiRealField T). Module ArchiField. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField.type instead.")] Notation type := ArchiRealField.type. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField.copy instead.")] Notation copy T C := (ArchiRealField.copy T C). #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField.on instead.")] Notation on T := (ArchiRealField.on T). End ArchiField. #[deprecated(since="mathcomp 2.3.0", note="Use real_floorDzr instead.")] Notation floorD := real_floorDzr. #[deprecated(since="mathcomp 2.3.0", note="Use real_ceilDzr instead.")] Notation ceilD := real_ceilDzr. #[deprecated(since="mathcomp 2.3.0", note="Use real_ceilDzr instead.")] Notation real_ceilD := real_ceilDzr. End Num. Export Num.Exports. #[deprecated(since="mathcomp 2.3.0", note="Use archiRealDomainType instead.")] Notation archiDomainType := archiRealDomainType (only parsing). #[deprecated(since="mathcomp 2.3.0", note="Use archiRealFieldType instead.")] Notation archiFieldType := archiRealFieldType (only parsing).
extraspecial.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div. From mathcomp Require Import choice fintype bigop finset prime binomial. From mathcomp Require Import fingroup morphism perm automorphism presentation. From mathcomp Require Import quotient action commutator gproduct gfunctor. From mathcomp Require Import ssralg finalg zmodp cyclic pgroup center gseries. From mathcomp Require Import nilpotent sylow abelian finmodule matrix maximal. From mathcomp Require Import extremal. (******************************************************************************) (* This file contains the fine structure thorems for extraspecial p-groups. *) (* Together with the material in the maximal and extremal libraries, it *) (* completes the coverage of Aschbacher, section 23. *) (* We define canonical representatives for the group classes that cover the *) (* extremal p-groups (non-abelian p-groups with a cyclic maximal subgroup): *) (* 'Mod_m == the modular group of order m, for m = p ^ n, p prime and n >= 3. *) (* 'D_m == the dihedral group of order m, for m = 2n >= 4. *) (* 'Q_m == the generalized quaternion group of order m, for q = 2 ^ n >= 8. *) (* 'SD_m == the semi-dihedral group of order m, for m = 2 ^ n >= 16. *) (* In each case the notation is defined in the %type, %g and %G scopes, where *) (* it denotes a finGroupType, a full gset and the full group for that type. *) (* However each notation is only meaningful under the given conditions, in *) (* We construct and study the following extraspecial groups: *) (* p^{1+2} == if p is prime, an extraspecial group of order p^3 that has *) (* exponent p or 4, and p-rank 2: thus p^{1+2} is isomorphic to *) (* 'D_8 if p - 2, and NOT isomorphic to 'Mod_(p^3) if p is odd. *) (* p^{1+2*n} == the central product of n copies of p^{1+2}, thus of order *) (* p^(1+2*n) if p is a prime, and, when n > 0, a representative *) (* of the (unique) isomorphism class of extraspecial groups of *) (* order p^(1+2*n), of exponent p or 4, and p-rank n+1. *) (* 'D^n == an alternative (and preferred) notation for 2^{1+2*n}, which *) (* is isomorphic to the central product of n copies od 'D_8. *) (* 'D^n*Q == the central product of 'D^n with 'Q_8, thus isomorphic to *) (* all extraspecial groups of order 2 ^ (2 * n + 3) that are *) (* not isomorphic to 'D^n.+1 (or, equivalently, have 2-rank n). *) (* As in extremal.v, these notations are simultaneously defined in the %type, *) (* %g and %G scopes -- depending on the syntactic context, they denote either *) (* a finGroupType, the set, or the group of all its elements. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Notation "n %:R" := (n %:R%R). Import GroupScope GRing.Theory. Reserved Notation "p ^{1+2}" (format "p ^{1+2}"). Reserved Notation "p ^{1+2* n }" (n at level 2, format "p ^{1+2* n }"). Reserved Notation "''D^' n" (at level 0, n at level 2, format "''D^' n"). Reserved Notation "''D^' n * 'Q'" (format "''D^' n * 'Q'"). Module Pextraspecial. Section Construction. Variable p : nat. Definition act ij (k : 'Z_p) := let: (i, j) := ij in (i + k * j, j)%R. Lemma actP : is_action [set: 'Z_p] act. Proof. apply: is_total_action=> [] [i j] => [|k1 k2] /=; first by rewrite mul0r addr0. by rewrite mulrDl addrA. Qed. Canonical action := Action actP. Lemma gactP : is_groupAction [set: 'Z_p * 'Z_p] action. Proof. move=> k _ /[1!inE]; apply/andP; split; first by apply/subsetP=> ij _ /[1!inE]. apply/morphicP=> /= [[i1 j1] [i2 j2] _ _]. by rewrite !permE /= mulrDr -addrA (addrCA i2) (addrA i1). Qed. Definition groupAction := GroupAction gactP. Fact gtype_key : unit. Proof. by []. Qed. Definition gtype := locked_with gtype_key (sdprod_groupType groupAction). Definition ngtype := ncprod [set: gtype]. End Construction. Definition ngtypeQ n := xcprod [set: ngtype 2 n] 'Q_8. End Pextraspecial. Notation "p ^{1+2}" := (Pextraspecial.gtype p) : type_scope. Notation "p ^{1+2}" := [set: gsort p^{1+2}] : group_scope. Notation "p ^{1+2}" := [set: gsort p^{1+2}]%G : Group_scope. Notation "p ^{1+2* n }" := (Pextraspecial.ngtype p n) : type_scope. Notation "p ^{1+2* n }" := [set: gsort p^{1+2*n}] : group_scope. Notation "p ^{1+2* n }" := [set: gsort p^{1+2*n}]%G : Group_scope. Notation "''D^' n" := (Pextraspecial.ngtype 2 n) : type_scope. Notation "''D^' n" := [set: gsort 'D^n] : group_scope. Notation "''D^' n" := [set: gsort 'D^n]%G : Group_scope. Notation "''D^' n * 'Q'" := (Pextraspecial.ngtypeQ n) : type_scope. Notation "''D^' n * 'Q'" := [set: gsort 'D^n*Q] : group_scope. Notation "''D^' n * 'Q'" := [set: gsort 'D^n*Q]%G : Group_scope. Section ExponentPextraspecialTheory. Variable p : nat. Hypothesis p_pr : prime p. Let p_gt1 := prime_gt1 p_pr. Let p_gt0 := ltnW p_gt1. Local Notation gtype := Pextraspecial.gtype. Local Notation actp := (Pextraspecial.groupAction p). Lemma card_pX1p2 : #|p^{1+2}| = (p ^ 3)%N. Proof. rewrite [@gtype _]unlock -(sdprod_card (sdprod_sdpair _)). rewrite !card_injm ?injm_sdpair1 ?injm_sdpair2 // !cardsT card_prod card_ord. by rewrite -mulnA Zp_cast. Qed. Lemma Grp_pX1p2 : p^{1+2} \isog Grp (x : y : x ^+ p, y ^+ p, [~ x, y, x], [~ x, y, y]). Proof. rewrite [@gtype _]unlock; apply: intro_isoGrp => [|rT H]. apply/existsP; pose x := sdpair1 actp (0, 1)%R; pose y := sdpair2 actp 1%R. exists (x, y); rewrite /= !xpair_eqE; set z := [~ x, y]; set G := _ <*> _. have def_z: z = sdpair1 actp (1, 0)%R. rewrite [z]commgEl -sdpair_act ?inE //=. rewrite -morphV -?morphM ?inE //=; congr (sdpair1 _ (_, _)) => /=. by rewrite mulr1 mulKg. by rewrite mulVg. have def_xi i: x ^+ i = sdpair1 actp (0, i%:R)%R. (* FIXME: had to explicitly give actp (instead of _) *) rewrite -morphX ?inE //; congr (sdpair1 _ _). by apply/eqP; rewrite /eq_op /= !morphX ?inE ?expg1n //=. have def_yi i: y ^+ i = sdpair2 actp i%:R. (* FIXME: had to explicitly give actp (instead of _) *) by rewrite -morphX ?inE //. have def_zi i: z ^+ i = sdpair1 actp (i%:R, 0)%R. (* FIXME: had to explicitly give actp (instead of _) *) rewrite def_z -morphX ?inE //; congr (sdpair1 _ _). by apply/eqP; rewrite /eq_op /= !morphX ?inE ?expg1n ?andbT //=. rewrite def_xi def_yi pchar_Zp ?morph1 //. rewrite def_z -morphR ?inE // !commgEl -sdpair_act ?inE //= mulr0 addr0. rewrite mulVg -[_ * _]/(_ , _) /= !invg1 mulg1 !mul1g mulVg morph1 !andbT. have Gx: x \in G by rewrite -cycle_subG joing_subl. have Gy: y \in G by rewrite -cycle_subG joing_subr. rewrite eqEsubset subsetT -im_sdpair mulG_subG /= -/G; apply/andP; split. apply/subsetP=> u /morphimP[[i j] _ _ def_u]. suffices ->: u = z ^+ i * x ^+ j. rewrite groupMl; apply/groupX; first exact: Gx. by apply/groupR; first exact: Gx. rewrite def_zi def_xi !natr_Zp -morphM ?inE // def_u. by congr (sdpair1 _ (_, _)); rewrite ?mulg1 ?mul1g. apply/subsetP=> v /morphimP[k _ _ def_v]. suffices ->: v = y ^+ k by rewrite groupX. by rewrite def_yi natr_Zp. case/existsP=> [[x y] /=]; set z := [~ x, y]. case/eqP=> defH xp yp /eqP/commgP czx /eqP/commgP czy. have zp: z ^+ p = 1 by rewrite -commXg // xp comm1g. pose f1 (ij : 'Z_p * 'Z_p) := let: (i, j) := ij in z ^+ i * x ^+ j. have f1M: {in setT &, {morph f1 : u v / u * v}}. case=> /= [i1 j1] [i2 j2] _ _ /=; rewrite {3 6}Zp_cast // !expg_mod //. rewrite !expgD !mulgA; congr (_ * _); rewrite -!mulgA; congr (_ * _). by apply: commuteX2. pose f2 (k : 'Z_p) := y ^+ k. have f2M: {in setT &, {morph f2 : u v / u * v}}. by move=> k1 k2 _ _; rewrite /f2 /= {3}Zp_cast // expg_mod // expgD. have actf: {in setT & setT, morph_act actp 'J (Morphism f1M) (Morphism f2M)}. case=> /= i j k _ _; rewrite modnDmr {4}Zp_cast // expg_mod // expgD. rewrite /f2 conjMg {1}/conjg (commuteX2 i k czy) mulKg -mulgA. congr (_ * _); rewrite (commuteX2 _ _ czx) mulnC expgM. by rewrite -commXg // -commgX ?mulKVg // commXg // /commute commuteX. apply/homgP; exists (xsdprod_morphism actf). apply/eqP; rewrite eqEsubset -{2}defH -genM_join gen_subG /= im_xsdprodm. have Hx: x \in H by rewrite -cycle_subG -defH joing_subl. have Hy: y \in H by rewrite -cycle_subG -defH joing_subr. rewrite mulG_subG -andbA; apply/and3P; split. - apply/subsetP=> _ /morphimP[[i j] _ _ -> /=]. by rewrite groupMl groupX ?groupR. - by apply/subsetP=> _ /morphimP[k _ _ ->]; rewrite groupX. rewrite mulgSS ?cycle_subG //= morphimEdom; apply/imsetP. by exists (0, 1)%R; rewrite ?inE //= mul1g. by exists 1%R; rewrite ?inE. Qed. Lemma pX1p2_pgroup : p.-group p^{1+2}. Proof. by rewrite /pgroup card_pX1p2 pnatX pnat_id. Qed. (* This is part of the existence half of Aschbacher ex. (8.7)(1) *) Lemma pX1p2_extraspecial : extraspecial p^{1+2}. Proof. apply: (p3group_extraspecial pX1p2_pgroup); last first. by rewrite card_pX1p2 pfactorK. case/existsP: (isoGrp_hom Grp_pX1p2) card_pX1p2 => [[x y]] /=. case/eqP=> <- xp yp _ _ oXY. apply: contraL (dvdn_cardMg <[x]> <[y]>) => cXY_XY. rewrite -cent_joinEl ?(sub_abelian_cent2 cXY_XY) ?joing_subl ?joing_subr //. rewrite oXY -!orderE pfactor_dvdn ?muln_gt0 ?order_gt0 // -leqNgt. rewrite -(pfactorK 2 p_pr) dvdn_leq_log ?expn_gt0 ?p_gt0 //. by rewrite dvdn_mul ?order_dvdn ?xp ?yp. Qed. (* This is part of the existence half of Aschbacher ex. (8.7)(1) *) Lemma exponent_pX1p2 : odd p -> exponent p^{1+2} %| p. Proof. move=> p_odd; have pG := pX1p2_pgroup. have ->: p^{1+2} = 'Ohm_1(p^{1+2}). apply/eqP; rewrite eqEsubset Ohm_sub andbT (OhmE 1 pG). case/existsP: (isoGrp_hom Grp_pX1p2) => [[x y]] /=. case/eqP=> <- xp yp _ _; rewrite joing_idl joing_idr genS //. by rewrite subsetI subset_gen subUset !sub1set !inE xp yp!eqxx. rewrite exponent_Ohm1_class2 ?card_pX1p2 ?oddX // nil_class2. by have [[_ ->] _ ] := pX1p2_extraspecial. Qed. (* This is the uniqueness half of Aschbacher ex. (8.7)(1) *) Lemma isog_pX1p2 (gT : finGroupType) (G : {group gT}) : extraspecial G -> exponent G %| p -> #|G| = (p ^ 3)%N -> G \isog p^{1+2}. Proof. move=> esG expGp oG; apply/(isoGrpP _ Grp_pX1p2). rewrite card_pX1p2; split=> //. have pG: p.-group G by rewrite /pgroup oG pnatX pnat_id. have oZ := card_center_extraspecial pG esG. have [x Gx notZx]: exists2 x, x \in G & x \notin 'Z(G). apply/subsetPn; rewrite proper_subn // properEcard center_sub oZ oG. by rewrite (ltn_exp2l 1 3). have ox: #[x] = p. by apply: nt_prime_order; rewrite ?(exponentP expGp) ?(group1_contra notZx). have [y Gy not_cxy]: exists2 y, y \in G & y \notin 'C[x]. by apply/subsetPn; rewrite sub_cent1; rewrite inE Gx in notZx. apply/existsP; exists (x, y) => /=; set z := [~ x, y]. have [[defPhiG defG'] _] := esG. have Zz: z \in 'Z(G) by rewrite -defG' mem_commg. have [Gz cGz] := setIP Zz; rewrite !xpair_eqE !(exponentP expGp) //. have [_ nZG] := andP (center_normal G). rewrite /commg /conjg !(centP cGz) // !mulKg mulVg !eqxx !andbT. have sXY_G: <[x]> <*> <[y]> \subset G by rewrite join_subG !cycle_subG Gx. have defZ: <[z]> = 'Z(G). apply/eqP; rewrite eqEcard cycle_subG Zz oZ /= -orderE. rewrite (nt_prime_order p_pr) ?(exponentP expGp) //. by rewrite (sameP commgP cent1P) cent1C. have sZ_XY: 'Z(G) \subset <[x]> <*> <[y]>. by rewrite -defZ cycle_subG groupR // mem_gen // inE cycle_id ?orbT. rewrite eqEcard sXY_G /= oG -(Lagrange sZ_XY) oZ leq_pmul2l //. rewrite -card_quotient ?(subset_trans sXY_G) //. rewrite quotientY ?quotient_cycle ?cycle_subG ?(subsetP nZG) //. have abelGz: p.-abelem (G / 'Z(G)) by rewrite -defPhiG Phi_quotient_abelem. have [cGzGz expGz] := abelemP p_pr abelGz. rewrite cent_joinEr ?(sub_abelian_cent2 cGzGz) ?cycle_subG ?mem_quotient //. have oZx: #|<[coset 'Z(G) x]>| = p. rewrite -orderE (nt_prime_order p_pr) ?expGz ?mem_quotient //. by apply: contra notZx; move/eqP=> Zx; rewrite coset_idr ?(subsetP nZG). rewrite TI_cardMg ?oZx -?orderE ?(nt_prime_order p_pr) ?expGz ?mem_quotient //. apply: contra not_cxy; move/eqP=> Zy. rewrite -cent_cycle (subsetP _ y (coset_idr _ Zy)) ?(subsetP nZG) //. by rewrite subIset ?centS ?orbT ?cycle_subG. rewrite prime_TIg ?oZx // cycle_subG; apply: contra not_cxy. case/cycleP=> i; rewrite -morphX ?(subsetP nZG) // => /rcoset_kercosetP. rewrite groupX ?(subsetP nZG) // cent1C => /(_ isT isT); apply: subsetP. rewrite mul_subG ?sub1set ?groupX ?cent1id //= -cent_cycle subIset // orbC. by rewrite centS ?cycle_subG. Qed. End ExponentPextraspecialTheory. Section GeneralExponentPextraspecialTheory. Variable p : nat. Lemma pX1p2id : p^{1+2*1} \isog p^{1+2}. Proof. exact: ncprod1. Qed. Lemma pX1p2S n : xcprod_spec p^{1+2} p^{1+2*n} p^{1+2*n.+1}%type. Proof. exact: ncprodS. Qed. Lemma card_pX1p2n n : prime p -> #|p^{1+2*n}| = (p ^ n.*2.+1)%N. Proof. move=> p_pr; have pG := pX1p2_pgroup p_pr. have oG := card_pX1p2 p_pr; have esG := pX1p2_extraspecial p_pr. have oZ := card_center_extraspecial pG esG. elim: n => [|n IHn]; first by rewrite (card_isog (ncprod0 _)) oZ. case: pX1p2S => gz isoZ; rewrite -im_cpair cardMg_divn setI_im_cpair. rewrite -injm_center ?{1}card_injm ?injm_cpairg1 ?injm_cpair1g ?center_sub //. by rewrite oG oZ IHn -expnD mulKn ?prime_gt0. Qed. Lemma pX1p2n_pgroup n : prime p -> p.-group p^{1+2*n}. Proof. by move=> p_pr; rewrite /pgroup card_pX1p2n // pnatX pnat_id. Qed. (* This is part of the existence half of Aschbacher (23.13) *) Lemma exponent_pX1p2n n : prime p -> odd p -> exponent p^{1+2*n} = p. Proof. move=> p_pr odd_p; apply: prime_nt_dvdP => //. rewrite -dvdn1 -trivg_exponent -cardG_gt1 card_pX1p2n //. by rewrite (ltn_exp2l 0) // prime_gt1. elim: n => [|n IHn]. by rewrite (dvdn_trans (exponent_dvdn _)) ?card_pX1p2n. case: pX1p2S => gz isoZ; rewrite -im_cpair /=. apply/exponentP=> xy; case/imset2P=> x y C1x C2y ->{xy}. rewrite expgMn; last by red; rewrite -(centsP (im_cpair_cent isoZ)). rewrite (exponentP _ y C2y) ?exponent_injm ?injm_cpair1g // mulg1. by rewrite (exponentP _ x C1x) ?exponent_injm ?injm_cpairg1 // exponent_pX1p2. Qed. (* This is part of the existence half of Aschbacher (23.13) and (23.14) *) Lemma pX1p2n_extraspecial n : prime p -> n > 0 -> extraspecial p^{1+2*n}. Proof. move=> p_pr; elim: n => [//|n IHn _]. have esG := pX1p2_extraspecial p_pr. have [n0 | n_gt0] := posnP n. by apply: isog_extraspecial esG; rewrite isog_sym n0 pX1p2id. case: pX1p2S (pX1p2n_pgroup n.+1 p_pr) => gz isoZ pGn. apply: (cprod_extraspecial pGn (im_cpair_cprod isoZ) (setI_im_cpair isoZ)). by apply: injm_extraspecial esG; rewrite ?injm_cpairg1. by apply: injm_extraspecial (IHn n_gt0); rewrite ?injm_cpair1g. Qed. (* This is Aschbacher (23.12) *) Lemma Ohm1_extraspecial_odd (gT : finGroupType) (G : {group gT}) : p.-group G -> extraspecial G -> odd #|G| -> let Y := 'Ohm_1(G) in [/\ exponent Y = p, #|G : Y| %| p & Y != G -> exists E : {group gT}, [/\ #|G : Y| = p, #|E| = p \/ extraspecial E, exists2 X : {group gT}, #|X| = p & X \x E = Y & exists M : {group gT}, [/\ M \isog 'Mod_(p ^ 3), M \* E = G & M :&: E = 'Z(M)]]]. Proof. move=> pG esG oddG Y; have [spG _] := esG. have [defPhiG defG'] := spG; set Z := 'Z(G) in defPhiG defG'. have{spG} expG: exponent G %| p ^ 2 by apply: exponent_special. have p_pr := extraspecial_prime pG esG. have p_gt1 := prime_gt1 p_pr; have p_gt0 := ltnW p_gt1. have oZ: #|Z| = p := card_center_extraspecial pG esG. have nsZG: Z <| G := center_normal G; have [sZG nZG] := andP nsZG. have nsYG: Y <| G := Ohm_normal 1 G; have [sYG nYG] := andP nsYG. have ntZ: Z != 1 by rewrite -cardG_gt1 oZ. have sZY: Z \subset Y. by apply: contraR ntZ => ?; rewrite -(setIidPl sZG) TI_Ohm1 ?prime_TIg ?oZ. have ntY: Y != 1 by apply: subG1_contra ntZ. have p_odd: odd p by rewrite -oZ (oddSg sZG). have expY: exponent Y %| p by rewrite exponent_Ohm1_class2 // nil_class2 defG'. rewrite (prime_nt_dvdP p_pr _ expY) -?dvdn1 -?trivg_exponent //. have [-> | neYG] := eqVneq Y G; first by rewrite indexgg dvd1n; split. have sG1Z: 'Mho^1(G) \subset Z by rewrite -defPhiG (Phi_joing pG) joing_subr. have Z_Gp: {in G, forall x, x ^+ p \in Z}. by move=> x Gx; rewrite /= (subsetP sG1Z) ?(Mho_p_elt 1) ?(mem_p_elt pG). have{expG} oY': {in G :\: Y, forall u, #[u] = (p ^ 2)%N}. move=> u /setDP[Gu notYu]; apply/eqP. have [k ou] := p_natP (mem_p_elt pG Gu). rewrite eqn_dvd order_dvdn (exponentP expG) // eqxx ou dvdn_Pexp2l // ltnNge. apply: contra notYu => k_le_1; rewrite [Y](OhmE _ pG) mem_gen // !inE Gu /=. by rewrite -order_dvdn ou dvdn_exp2l. have isoMod3 (M : {group gT}): M \subset G -> ~~ abelian M -> ~~ (M \subset Y) -> #|M| = (p ^ 3)%N -> M \isog 'Mod_(p ^ 3). - move=> sMG not_cMM /subsetPn[u Mu notYu oM]. have pM := pgroupS sMG pG; have sUM: <[u]> \subset M by rewrite cycle_subG. have Y'u: u \in G :\: Y by rewrite inE notYu (subsetP sMG). have iUM: #|M : <[u]>| = p by rewrite -divgS // oM expnS -(oY' u) ?mulnK. have cM := maximal_cycle_extremal pM not_cMM (cycle_cyclic u) sUM iUM. rewrite (sameP eqP (prime_oddPn p_pr)) p_odd orbF in cM. rewrite /extremal_class oM pdiv_pfactor // pfactorK //= in cM. by do 3!case: ifP => // _ in cM. have iYG: #|G : Y| = p. have [V maxV sYV]: {V : {group gT} | maximal V G & Y \subset V}. by apply: maxgroup_exists; rewrite properEneq neYG. have [sVG [u Gu notVu]] := properP (maxgroupp maxV). without loss [v Vv notYv]: / exists2 v, v \in V & v \notin Y. have [->| ] := eqVneq Y V; first by rewrite (p_maximal_index pG). by rewrite eqEsubset sYV => not_sVY; apply; apply/subsetPn. pose U := <[u]> <*> <[v]>; have Gv := subsetP sVG v Vv. have sUG: U \subset G by rewrite join_subG !cycle_subG Gu. have Uu: u \in U by rewrite -cycle_subG joing_subl. have Uv: v \in U by rewrite -cycle_subG joing_subr. have not_sUY: ~~ (U \subset Y) by apply/subsetPn; exists v. have sU1U: 'Ohm_1(U) \subset U := Ohm_sub 1 _. have sU1Y: 'Ohm_1(U) \subset Y := OhmS 1 sUG. suffices defUV: U :&: V = 'Ohm_1(U). by rewrite (subsetP sU1Y) // -defUV inE Uv in notYv. suffices iU1U: #|U : 'Ohm_1(U)| = p. have: maximal 'Ohm_1(U) U by rewrite p_index_maximal ?Ohm_sub ?iU1U. case/maxgroupP=> _; apply; rewrite /= -/U. by apply/properP; split; last exists u; rewrite ?subsetIl ?inE ?Uu. by rewrite subsetI Ohm_sub (subset_trans sU1Y). apply/prime_nt_dvdP=> //. by apply: contra not_sUY; rewrite /U; move/eqP; move/(index1g sU1U)=> <-. have ov: #[v] = (p ^ 2)%N by rewrite oY' // inE notYv. have sZv: Z \subset <[v]>. suffices defZ: <[v ^+ p]> == Z by rewrite -(eqP defZ) cycleX. by rewrite eqEcard cycle_subG Z_Gp //= oZ -orderE (orderXexp 1 ov). have nvG: G \subset 'N(<[v]>) by rewrite sub_der1_norm ?cycle_subG // defG'. have [cUU | not_cUU] := orP (orbN (abelian U)). rewrite -divgS ?Ohm_sub // -(mul_card_Ohm_Mho_abelian 1 cUU) /= -/U. by rewrite mulKn ?cardG_gt0 //= -oZ cardSg ?(subset_trans (MhoS 1 sUG)). have oU: #|U| = (p ^ 3)%N. have nvu := subsetP nvG u Gu; have nvU := subset_trans sUG nvG. rewrite -(Lagrange (joing_subr _ _)) -orderE ov mulnC; congr (_ * _)%N. rewrite -card_quotient //= quotientYidr ?cycle_subG //=. rewrite quotient_cycle // -orderE; apply: nt_prime_order => //. by rewrite -morphX //= coset_id // (subsetP sZv) // Z_Gp. have svV: <[v]> \subset V by rewrite cycle_subG. by apply: contra notVu; move/eqP=> v_u; rewrite (subsetP svV) // coset_idr. have isoU := isoMod3 _ sUG not_cUU not_sUY oU; rewrite /= -/U in isoU. have [//|[x y] genU modU] := generators_modular_group p_pr _ isoU. case/modular_group_structure: genU => // _ _ _ _. case: eqP (p_odd) => [[-> //] | _ _]; case/(_ 1%N)=> // _ oU1. by rewrite -divgS // oU oU1 mulnK // muln_gt0 p_gt0. have iC1U (U : {group gT}) x: U \subset G -> x \in G :\: 'C(U) -> #|U : 'C_U[x]| = p. - move=> sUG /setDP[Gx not_cUx]; apply/prime_nt_dvdP=> //. apply: contra not_cUx; rewrite -sub_cent1 => /eqP sUCx. by rewrite -(index1g _ sUCx) ?subsetIl ?subsetIr. rewrite -(@dvdn_pmul2l (#|U| * #|'C_G[x]|)) ?muln_gt0 ?cardG_gt0 //. have maxCx: maximal 'C_G[x] G. rewrite cent1_extraspecial_maximal //; apply: contra not_cUx. by rewrite inE Gx; apply: subsetP (centS sUG) _. rewrite {1}mul_cardG setIA (setIidPl sUG) -(p_maximal_index pG maxCx) -!mulnA. rewrite !Lagrange ?subsetIl // mulnC dvdn_pmul2l //. have [sCxG nCxG] := andP (p_maximal_normal pG maxCx). by rewrite -norm_joinEl ?cardSg ?join_subG ?(subset_trans sUG). have oCG (U : {group gT}): Z \subset U -> U \subset G -> #|'C_G(U)| = (p * #|G : U|)%N. - have [m] := ubnP #|U|; elim: m U => // m IHm U leUm sZU sUG. have [<- | neZU] := eqVneq Z U. by rewrite -oZ Lagrange // (setIidPl _) // centsC subsetIr. have{neZU} [x Gx not_cUx]: exists2 x, x \in G & x \notin 'C(U). by apply/subsetPn; rewrite eqEsubset sZU subsetI sUG centsC in neZU. pose W := 'C_U[x]; have iWU: #|U : W| = p by rewrite iC1U // inE not_cUx. have maxW: maximal W U by rewrite p_index_maximal ?subsetIl ?iWU. have ltWU: W \proper U by apply: maxgroupp maxW. have [sWU [u Uu notWu]] := properP ltWU. have defU: W * <[u]> = U. have nsWU: W <| U := p_maximal_normal (pgroupS sUG pG) maxW. by rewrite (mulg_normal_maximal nsWU) ?cycle_subG. have sWG := subset_trans sWU sUG. have sZW: Z \subset W. by rewrite subsetI sZU -cent_set1 subIset ?centS ?orbT ?sub1set. have iCW_CU: #|'C_G(W) : 'C_G(U)| = p. rewrite -defU centM cent_cycle setIA /= -/W. rewrite iC1U ?subsetIl ?setIS ?centS // inE andbC (subsetP sUG) //=. rewrite -sub_cent1; apply/subsetPn; exists x. by rewrite inE Gx -sub_cent1 subsetIr. by rewrite -defU centM cent_cycle inE -sub_cent1 subsetIr in not_cUx. apply/eqP; rewrite -(eqn_pmul2r p_gt0) -{1}iCW_CU Lagrange ?setIS ?centS //. rewrite IHm ?(leq_trans (proper_card ltWU)) //= -/W. by rewrite -(Lagrange_index sUG sWU) iWU mulnA. have oCY: #|'C_G(Y)| = (p ^ 2)%N by rewrite oCG // iYG. have [x cYx notZx]: exists2 x, x \in 'C_G(Y) & x \notin Z. apply/subsetPn; rewrite proper_subn // properEcard setIS ?centS //=. by rewrite oZ oCY (ltn_exp2l 1 2). have{cYx} [Gx cYx] := setIP cYx; have nZx := subsetP nZG x Gx. have defCx: 'C_G[x] = Y. apply/eqP; rewrite eq_sym eqEcard subsetI sYG sub_cent1 cYx /=. rewrite -(leq_pmul2r p_gt0) -{2}iYG -(iC1U G x) ?Lagrange ?subsetIl //. by rewrite !inE Gx ?andbT in notZx *. have Yx: x \in Y by rewrite -defCx inE Gx cent1id. have ox: #[x] = p. by apply: nt_prime_order; rewrite ?(exponentP expY) // (group1_contra notZx). have defCy: 'C_G(Y) = Z * <[x]>. apply/eqP; rewrite eq_sym eqEcard mulG_subG setIS ?centS //=. rewrite cycle_subG inE Gx cYx oCY TI_cardMg ?oZ -?orderE ?ox //=. by rewrite setIC prime_TIg -?orderE ?ox ?cycle_subG. have abelYt: p.-abelem (Y / Z). by rewrite (abelemS (quotientS _ sYG)) //= -/Z -defPhiG Phi_quotient_abelem. have Yxt: coset Z x \in Y / Z by rewrite mem_quotient. have{Yxt} [Et [sEtYt oEt defYt]] := p_abelem_split1 abelYt Yxt. have nsZY: Z <| Y := normalS sZY sYG nsZG. have [E defEt sZE sEY] := inv_quotientS nsZY sEtYt. have{defYt} [_ defYt _ tiXEt] := dprodP defYt. have defY: <[x]> \x E = Y. have nZX: <[x]> \subset 'N(Z) by rewrite cycle_subG. have TIxE: <[x]> :&: E = 1. rewrite prime_TIg -?orderE ?ox // -(quotientSGK _ sZE) ?quotient_cycle //. rewrite (sameP setIidPl eqP) eq_sym -defEt tiXEt -quotient_cycle //. by rewrite -subG1 quotient_sub1 // cycle_subG. rewrite dprodE //; last 1 first. by rewrite cent_cycle (subset_trans sEY) //= -/Y -defCx subsetIr. rewrite -[Y](quotientGK nsZY) -defYt cosetpreM -quotient_cycle //. rewrite quotientK // -(normC nZX) defEt quotientGK ?(normalS _ sEY) //. by rewrite -mulgA (mulSGid sZE). have sEG := subset_trans sEY sYG; have nZE := subset_trans sEG nZG. have defZE: 'Z(E) = Z. apply/eqP; rewrite eqEsubset andbC subsetI sZE subIset ?centS ?orbT //. rewrite -quotient_sub1 ?subIset ?nZE //= -tiXEt defEt subsetI andbC. rewrite quotientS ?center_sub //= -quotient_cycle //. rewrite -(quotientMidl _ <[x]>) /= -defCy quotientS // /Y. by case/dprodP: defY => _ <- _ _; rewrite centM setIA cent_cycle defCx setSI. have pE := pgroupS sEG pG. rewrite iYG; split=> // _; exists E. split=> //; first 2 [by exists [group of <[x]>]]. have:= sZE; rewrite subEproper; case/predU1P=> [<- | ltZE]; [by left | right]. split; rewrite /special defZE ?oZ // (Phi_joing pE). have defE': E^`(1) = Z. have sE'Z: E^`(1) \subset Z by rewrite -defG' dergS. apply/eqP; rewrite eqEcard sE'Z -(prime_nt_dvdP _ _ (cardSg sE'Z)) ?oZ //=. rewrite -trivg_card1 (sameP eqP commG1P). by rewrite /proper sZE /= -/Z -defZE subsetI subxx in ltZE. split=> //; rewrite -defE'; apply/joing_idPl. by rewrite /= defE' -defPhiG (Phi_joing pG) joingC sub_gen ?subsetU ?MhoS. have iEG: #|G : E| = (p ^ 2)%N. apply/eqP; rewrite -(@eqn_pmul2l #|E|) // Lagrange // -(Lagrange sYG) iYG. by rewrite -(dprod_card defY) -mulnA mulnCA -orderE ox. pose M := 'C_G(E); exists [group of M] => /=. have sMG: M \subset G := subsetIl _ _; have pM: p.-group M := pgroupS sMG pG. have sZM: Z \subset M by rewrite setIS ?centS. have oM: #|M| = (p ^ 3)%N by rewrite oCG ?iEG. have defME: M * E = G. apply/eqP; rewrite eqEcard mulG_subG sMG sEG /= -(leq_pmul2r p_gt0). rewrite -{2}oZ -defZE /('Z(E)) -{2}(setIidPr sEG) setIAC -mul_cardG /= -/M. by rewrite -(Lagrange sEG) mulnAC -mulnA mulnC iEG oM. have defZM: 'Z(M) = Z. apply/eqP; rewrite eqEsubset andbC subsetI sZM subIset ?centS ?orbT //=. by rewrite /Z /('Z(G)) -{2}defME centM setIA setIAC. rewrite cprodE 1?centsC ?subsetIr //. rewrite defME setIAC (setIidPr sEG) defZM isoMod3 //. rewrite abelianE (sameP setIidPl eqP) eqEcard subsetIl /= -/('Z(M)) -/M. by rewrite defZM oZ oM (leq_exp2l 3 1). by apply: contra neYG => sMY; rewrite eqEsubset sYG -defME mulG_subG sMY. Qed. (* This is the uniqueness half of Aschbacher (23.13); the proof incorporates *) (* in part the proof that symplectic spaces are hyperbolic (19.16). *) Lemma isog_pX1p2n n (gT : finGroupType) (G : {group gT}) : prime p -> extraspecial G -> #|G| = (p ^ n.*2.+1)%N -> exponent G %| p -> G \isog p^{1+2*n}. Proof. move=> p_pr esG oG expG; have p_gt1 := prime_gt1 p_pr. have not_le_p3_p: ~~ (p ^ 3 <= p) by rewrite (leq_exp2l 3 1). have pG: p.-group G by rewrite /pgroup oG pnatX pnat_id. have oZ := card_center_extraspecial pG esG. have{pG esG} [Es p3Es defG] := extraspecial_structure pG esG. set Z := 'Z(G) in oZ defG p3Es. elim: Es {+}G => [|E Es IHs] S in n oG expG p3Es defG *. rewrite big_nil cprod1g in defG; rewrite -defG. have ->: n = 0. apply: double_inj; apply/eqP. by rewrite -eqSS -(eqn_exp2l _ _ p_gt1) -oG -defG oZ. by rewrite isog_cyclic_card prime_cyclic ?oZ ?card_pX1p2n //=. rewrite big_cons -cprodA in defG; rewrite /= -andbA in p3Es. have [[_ T _ defT] defET cTE] := cprodP defG; rewrite defT in defET cTE defG. move: p3Es => /and3P[/eqP oE /eqP defZE /IHs{}IHs]. have not_cEE: ~~ abelian E. by apply: contra not_le_p3_p => cEE; rewrite -oE -oZ -defZE (center_idP _). have sES: E \subset S by rewrite -defET mulG_subl. have sTS: T \subset S by rewrite -defET mulG_subr. have expE: exponent E %| p by apply: dvdn_trans (exponentS sES) expG. have expT: exponent T %| p by apply: dvdn_trans (exponentS sTS) expG. have{expE not_cEE} isoE: E \isog p^{1+2}. apply: isog_pX1p2 => //. by apply: card_p3group_extraspecial p_pr oE _; rewrite defZE. have sZT: 'Z(E) \subset T. by case/cprodP: defT => [[U _ -> _] <- _]; rewrite defZE mulG_subr. case def_n: n => [|n']. case/negP: not_le_p3_p; rewrite def_n in oG; rewrite -oE -[p]oG. exact: subset_leq_card. have zI_ET: E :&: T = 'Z(E). by apply/eqP; rewrite eqEsubset subsetI sZT subsetIl setIS // centsC. have{n def_n oG} oT: #|T| = (p ^ n'.*2.+1)%N. apply/eqP; rewrite -(eqn_pmul2l (cardG_gt0 E)) mul_cardG zI_ET defET. by rewrite defZE oE oG oZ -expnSr -expnD def_n. have{IHs oT expT defT Es} isoT: T \isog p^{1+2*n'} by rewrite IHs. case: pX1p2S => gz isoZ; rewrite (isog_cprod_by _ defG) //. exact: Aut_extraspecial_full (pX1p2_pgroup p_pr) (pX1p2_extraspecial p_pr). Qed. End GeneralExponentPextraspecialTheory. Lemma isog_2X1p2 : 2^{1+2} \isog 'D_8. Proof. have pr2: prime 2 by []; have oG := card_pX1p2 pr2; rewrite -[8]oG. case/existsP: (isoGrp_hom (Grp_pX1p2 pr2)) => [[x y]] /=. rewrite -/2^{1+2}; case/eqP=> defG x2 y2 _ _. have not_oG_2: ~~ (#|2^{1+2}| %| 2) by rewrite oG. have ox: #[x] = 2. apply: nt_prime_order => //; apply: contra not_oG_2 => x1. by rewrite -defG (eqP x1) cycle1 joing1G order_dvdn y2. have oy: #[y] = 2. apply: nt_prime_order => //; apply: contra not_oG_2 => y1. by rewrite -defG (eqP y1) cycle1 joingG1 order_dvdn x2. rewrite -defG joing_idl joing_idr involutions_gen_dihedral //. apply: contra not_oG_2 => eq_xy; rewrite -defG (eqP eq_xy) (joing_idPl _) //. by rewrite -orderE oy. Qed. Lemma Q8_extraspecial : extraspecial 'Q_8. Proof. have gt32: 3 > 2 by []; have isoQ: 'Q_8 \isog 'Q_(2 ^ 3) by apply: isog_refl. have [[x y] genQ _] := generators_quaternion gt32 isoQ. have [_ [defQ' defPhiQ _ _]] := quaternion_structure gt32 genQ isoQ. case=> defZ oZ _ _ _ _ _; split; last by rewrite oZ. by split; rewrite ?defPhiQ defZ. Qed. Lemma DnQ_P n : xcprod_spec 'D^n 'Q_8 ('D^n*Q)%type. Proof. have pQ: 2.-group 'Q_(2 ^ 3) by rewrite /pgroup card_quaternion. have{pQ} oZQ := card_center_extraspecial pQ Q8_extraspecial. suffices oZDn: #|'Z('D^n)| = 2. by apply: xcprodP; rewrite isog_cyclic_card ?prime_cyclic ?oZQ ?oZDn. have [-> | n_gt0] := posnP n; first by rewrite center_ncprod0 card_pX1p2n. have pr2: prime 2 by []; have pDn := pX1p2n_pgroup n pr2. exact: card_center_extraspecial (pX1p2n_extraspecial pr2 n_gt0). Qed. Lemma card_DnQ n : #|'D^n*Q| = (2 ^ n.+1.*2.+1)%N. Proof. have oQ: #|'Q_(2 ^ 3)| = 8 by rewrite card_quaternion. have pQ: 2.-group 'Q_8 by rewrite /pgroup oQ. case: DnQ_P => gz isoZ. rewrite -im_cpair cardMg_divn setI_im_cpair cpair_center_id. rewrite -injm_center//; last exact: injm_cpair1g. rewrite (card_injm (injm_cpairg1 _))//= (card_injm (injm_cpair1g _))//. rewrite (card_injm (injm_cpair1g _))//; last exact: center_sub. rewrite oQ card_pX1p2n // (card_center_extraspecial pQ Q8_extraspecial). by rewrite -muln_divA // mulnC -(expnD 2 2). Qed. Lemma DnQ_pgroup n : 2.-group 'D^n*Q. Proof. by rewrite /pgroup card_DnQ pnatX. Qed. (* Final part of the existence half of Aschbacher (23.14). *) Lemma DnQ_extraspecial n : extraspecial 'D^n*Q. Proof. case: DnQ_P (DnQ_pgroup n) => gz isoZ pDnQ. have [injDn injQ] := (injm_cpairg1 isoZ, injm_cpair1g isoZ). have [n0 | n_gt0] := posnP n. rewrite -im_cpair mulSGid; first exact: injm_extraspecial Q8_extraspecial. apply/setIidPl; rewrite setI_im_cpair -injm_center //=. by congr (_ @* _); rewrite n0 center_ncprod0. apply: (cprod_extraspecial pDnQ (im_cpair_cprod isoZ) (setI_im_cpair _)). exact: injm_extraspecial (pX1p2n_extraspecial _ _). exact: injm_extraspecial Q8_extraspecial. Qed. (* A special case of the uniqueness half of Achsbacher (23.14). *) Lemma card_isog8_extraspecial (gT : finGroupType) (G : {group gT}) : #|G| = 8 -> extraspecial G -> (G \isog 'D_8) || (G \isog 'Q_8). Proof. move=> oG esG; have pG: 2.-group G by rewrite /pgroup oG. apply/norP=> [[notG_D8 notG_Q8]]. have not_extG: extremal_class G = NotExtremal. by rewrite /extremal_class oG andFb (negPf notG_D8) (negPf notG_Q8). have [x Gx ox] := exponent_witness (pgroup_nil pG). pose X := <[x]>; have cycX: cyclic X := cycle_cyclic x. have sXG: X \subset G by rewrite cycle_subG. have iXG: #|G : X| = 2. by rewrite -divgS // oG -orderE -ox exponent_2extraspecial. have not_cGG := extraspecial_nonabelian esG. have:= maximal_cycle_extremal pG not_cGG cycX sXG iXG. by rewrite /extremal2 not_extG. Qed. (* The uniqueness half of Achsbacher (23.14). The proof incorporates in part *) (* the proof that symplectic spces are hyperbolic (Aschbacher (19.16)), and *) (* the determination of quadratic spaces over 'F_2 (21.2); however we use *) (* the second part of exercise (8.4) to avoid resorting to Witt's lemma and *) (* Galois theory as in (20.9) and (21.1). *) Lemma isog_2extraspecial (gT : finGroupType) (G : {group gT}) n : #|G| = (2 ^ n.*2.+1)%N -> extraspecial G -> G \isog 'D^n \/ G \isog 'D^n.-1*Q. Proof. elim: n G => [|n IHn] G oG esG. case/negP: (extraspecial_nonabelian esG). by rewrite cyclic_abelian ?prime_cyclic ?oG. have pG: 2.-group G by rewrite /pgroup oG pnatX. have oZ:= card_center_extraspecial pG esG. have: 'Z(G) \subset 'Ohm_1(G). apply/subsetP=> z Zz; rewrite (OhmE _ pG) mem_gen //. by rewrite !inE -order_dvdn -oZ order_dvdG ?(subsetP (center_sub G)). rewrite subEproper; case/predU1P=> [defG1 | ltZG1]. have [n' n'_gt2 isoG]: exists2 n', n' > 2 & G \isog 'Q_(2 ^ n'). apply/quaternion_classP; apply/eqP. have not_cycG: ~~ cyclic G. by apply: contra (extraspecial_nonabelian esG); apply: cyclic_abelian. move: oZ; rewrite defG1; move/prime_Ohm1P; rewrite (negPf not_cycG) /=. by apply=> //; apply: contra not_cycG; move/eqP->; apply: cyclic1. have [n0 n'3]: n = 0 /\ n' = 3. have [[x y] genG _] := generators_quaternion n'_gt2 isoG. have n'3: n' = 3. have [_ [_ _ oG' _] _ _ _] := quaternion_structure n'_gt2 genG isoG. apply/eqP; rewrite -(subnKC (ltnW n'_gt2)) subn2 !eqSS -(@eqn_exp2l 2) //. by rewrite -oG' -oZ; case: esG => [[_ ->]]. by move/eqP: oG; have [-> _ _ _] := genG; rewrite n'3 eqn_exp2l //; case n. right; rewrite (isog_trans isoG) // n'3 n0 /=. case: DnQ_P => z isoZ; rewrite -im_cpair mulSGid ?sub_isog ?injm_cpair1g //. apply/setIidPl; rewrite setI_im_cpair -injm_center ?injm_cpairg1 //. by rewrite center_ncprod0. case/andP: ltZG1 => _; rewrite (OhmE _ pG) gen_subG. case/subsetPn=> x; case/LdivP=> Gx x2 notZx. have ox: #[x] = 2 by apply: nt_prime_order (group1_contra notZx). have Z'x: x \in G :\: 'Z(G) by rewrite inE notZx. have [E [R [[oE oR] [defG ziER]]]] := split1_extraspecial pG esG Z'x. case=> defZE defZR [esE Ex] esR. have isoE: E \isog 2^{1+2}. apply: isog_trans (isog_symr isog_2X1p2). case/orP: (card_isog8_extraspecial oE esE) => // isoE; case/negP: notZx. have gt32: 3 > 2 by []. have [[y z] genE _] := generators_quaternion gt32 isoE. have [_ _ [defZx _ eq_y2 _ _] _ _] := quaternion_structure gt32 genE isoE. by rewrite (eq_y2 x) // -cycle_subG -defZx defZE. rewrite oG doubleS 2!expnS divnMl ?mulKn // in oR. case: ifP esR => [_ defR | _ esR]. have ->: n = 0 by move/eqP: oR; rewrite defR oZ (eqn_exp2l 1) //; case n. left; apply: isog_trans (isog_symr (ncprod1 _)). by rewrite -defG defR -defZE cprod_center_id. have AutZin2_1p2: Aut_in (Aut 2^{1+2}) 'Z(2^{1+2}) \isog Aut 'Z(2^{1+2}). exact: Aut_extraspecial_full (pX1p2_pgroup _) (pX1p2_extraspecial _). have [isoR | isoR] := IHn R oR esR. by left; case: pX1p2S => gz isoZ; rewrite (isog_cprod_by _ defG). have n_gt0: n > 0. have pR: 2.-group R by rewrite /pgroup oR pnatX. have:= min_card_extraspecial pR esR. by rewrite oR leq_exp2l // ltnS (leq_double 1). case: DnQ_P isoR => gR isoZR /=; rewrite isog_sym; case/isogP=> fR injfR im_fR. have [injDn injQ] := (injm_cpairg1 isoZR, injm_cpair1g isoZR). pose Dn1 := cpairg1 isoZR @* 'D^n.-1; pose Q := cpair1g isoZR @* 'Q_8. have defR: fR @* Dn1 \* fR @* Q = R. rewrite cprodE ?morphim_cents ?im_cpair_cent //. by rewrite -morphimMl ?subsetT ?im_cpair. rewrite -defR cprodA in defG. have [[Dn _ defDn _] _ _] := cprodP defG; rewrite defDn in defG. have isoDn: Dn \isog 'D^n. rewrite -(prednK n_gt0); case: pX1p2S => gz isoZ. rewrite (isog_cprod_by _ defDn) //; last 1 first. by rewrite isog_sym (isog_trans _ (sub_isog _ _)) ?subsetT // sub_isog. rewrite /= -morphimIim im_fR setIA ziER; apply/setIidPl. rewrite defZE -defZR -{1}im_fR -injm_center // morphimS //. by rewrite -cpairg1_center morphimS // center_sub. right; case: DnQ_P => gz isoZ; rewrite (isog_cprod_by _ defG) //; first 1 last. - exact: Aut_extraspecial_full (pX1p2n_pgroup _ _) (pX1p2n_extraspecial _ _). - by rewrite isog_sym (isog_trans _ (sub_isog _ _)) ?subsetT // sub_isog. rewrite /= -morphimIim; case/cprodP: defDn => _ defDn cDn1E. rewrite setICA setIA -defDn -group_modr ?morphimS ?subsetT //. rewrite /= im_fR (setIC R) ziER -center_prod // defZE -defZR. rewrite mulSGid /=; last first. by rewrite -{1}im_fR -injm_center // -cpairg1_center !morphimS ?center_sub. rewrite -injm_center ?subsetT // -injmI // setI_im_cpair. by rewrite -injm_center // cpairg1_center injm_center // im_fR mulGid. Qed. (* The first concluding remark of Aschbacher (23.14). *) Lemma rank_Dn n : 'r_2('D^n) = n.+1. Proof. elim: n => [|n IHn]; first by rewrite p_rank_abelem ?prime_abelem ?card_pX1p2n. have oDDn: #|'D^n.+1| = (2 ^ n.+1.*2.+1)%N by apply: card_pX1p2n. have esDDn: extraspecial 'D^n.+1 by apply: pX1p2n_extraspecial. do [case: pX1p2S => gz isoZ; set DDn := [set: _]] in oDDn esDDn *. have pDDn: 2.-group DDn by rewrite /pgroup oDDn pnatX. apply/eqP; rewrite eqn_leq; apply/andP; split. have [E EprE]:= p_rank_witness 2 [group of DDn]. have [sEDDn abelE <-] := pnElemP EprE; have [pE cEE _]:= and3P abelE. rewrite -(@leq_exp2l 2) // -p_part part_pnat_id // -leq_sqr -expnM -mulnn. rewrite muln2 doubleS expnS -oDDn -(@leq_pmul2r #|'C_DDn(E)|) ?cardG_gt0 //. rewrite {1}(card_subcent_extraspecial pDDn) // mulnCA -mulnA Lagrange //=. rewrite mulnAC mulnA leq_pmul2r ?cardG_gt0 // setTI. have ->: (2 * #|'C(E)| = #|'Z(DDn)| * #|'C(E)|)%N. by rewrite (card_center_extraspecial pDDn). by rewrite leq_mul ?subset_leq_card ?subsetIl. have [inj1 injn] := (injm_cpairg1 isoZ, injm_cpair1g isoZ). pose D := cpairg1 isoZ @* 2^{1+2}; pose Dn := cpair1g isoZ @* 'D^n. have [E EprE] := p_rank_witness 2 [group of Dn]. rewrite injm_p_rank //= IHn in EprE; have [sEDn abelE dimE]:= pnElemP EprE. have [x [Dx ox] notDnx]: exists x, [/\ x \in D, #[x] = 2 & x \notin Dn]. have isoD: D \isog 'D_(2 ^ 3). by rewrite isog_sym -(isog_transl _ isog_2X1p2) sub_isog. have [//| [x y] genD [oy _]] := generators_2dihedral _ isoD. have [_ _ _ X'y] := genD; case/setDP: X'y; rewrite /= -/D => Dy notXy. exists y; split=> //; apply: contra notXy => Dny. case/dihedral2_structure: genD => // _ _ _ _ [defZD _ _ _ _]. by rewrite (subsetP (cycleX x 2)) // -defZD -setI_im_cpair inE Dy. have def_xE: <[x]> \x E = <[x]> <*> E. rewrite dprodEY ?prime_TIg -?orderE ?ox //. by rewrite (centSS sEDn _ (im_cpair_cent _)) ?cycle_subG. by rewrite cycle_subG (contra (subsetP sEDn x)). apply/p_rank_geP; exists (<[x]> <*> E)%G. rewrite 2!inE subsetT (dprod_abelem _ def_xE) abelE -(dprod_card def_xE). by rewrite prime_abelem -?orderE ?ox //= lognM ?cardG_gt0 ?dimE. Qed. (* The second concluding remark of Aschbacher (23.14). *) Lemma rank_DnQ n : 'r_2('D^n*Q) = n.+1. Proof. have pDnQ: 2.-group 'D^n*Q := DnQ_pgroup n. have esDnQ: extraspecial 'D^n*Q := DnQ_extraspecial n. do [case: DnQ_P => gz isoZ; set DnQ := setT] in pDnQ esDnQ *. suffices [E]: exists2 E, E \in 'E*_2(DnQ) & logn 2 #|E| = n.+1. by rewrite (pmaxElem_extraspecial pDnQ esDnQ); case/pnElemP=> _ _ <-. have oZ: #|'Z(DnQ)| = 2 by apply: card_center_extraspecial. pose Dn := cpairg1 isoZ @* 'D^n; pose Q := cpair1g isoZ @* 'Q_8. have [injDn injQ] := (injm_cpairg1 isoZ, injm_cpair1g isoZ). have [E EprE]:= p_rank_witness 2 [group of Dn]. have [sEDn abelE dimE] := pnElemP EprE; have [pE cEE eE]:= and3P abelE. rewrite injm_p_rank // rank_Dn in dimE; exists E => //. have sZE: 'Z(DnQ) \subset E. have maxE := subsetP (p_rankElem_max _ _) E EprE. have abelZ: 2.-abelem 'Z(DnQ) by rewrite prime_abelem ?oZ. rewrite -(Ohm1_id abelZ) (OhmE _ (abelem_pgroup abelZ)) gen_subG. rewrite -(pmaxElem_LdivP _ maxE) // setSI //=. by rewrite -cpairg1_center injm_center // setIS ?centS. have scE: 'C_Dn(E) = E. apply/eqP; rewrite eq_sym eqEcard subsetI sEDn -abelianE cEE /=. have [n0 | n_gt0] := posnP n. rewrite subset_leq_card // subIset // (subset_trans _ sZE) //. by rewrite -cpairg1_center morphimS // n0 center_ncprod0. have pDn: 2.-group Dn by rewrite morphim_pgroup ?pX1p2n_pgroup. have esDn: extraspecial Dn. exact: injm_extraspecial (pX1p2n_extraspecial _ _). rewrite dvdn_leq ?cardG_gt0 // (card_subcent_extraspecial pDn) //=. rewrite -injm_center // cpairg1_center (setIidPl sZE) oZ. rewrite -(dvdn_pmul2l (cardG_gt0 E)) mulnn mulnCA Lagrange //. rewrite card_injm ?card_pX1p2n // -expnS pfactor_dvdn ?expn_gt0 ?cardG_gt0 //. by rewrite lognX dimE mul2n. apply/pmaxElemP; split=> [|F E2F sEF]; first by rewrite inE subsetT abelE. have{E2F} [_ abelF] := pElemP E2F; have [pF cFF eF] := and3P abelF. apply/eqP; rewrite eqEsubset sEF andbT; apply/subsetP=> x Fx. have DnQx: x \in Dn * Q by rewrite im_cpair inE. have{DnQx} [y z Dn_y Qz def_x]:= imset2P DnQx. have{Dn_y} Ey: y \in E. have cEz: z \in 'C(E). by rewrite (subsetP (centS sEDn)) // (subsetP (im_cpair_cent _)). rewrite -scE inE Dn_y -(groupMr _ cEz) -def_x (subsetP (centS sEF)) //. by rewrite (subsetP cFF). rewrite def_x groupMl // (subsetP sZE) // -cpair1g_center injm_center //= -/Q. have: z \in 'Ohm_1(Q). rewrite (OhmE 1 (pgroupS (subsetT Q) pDnQ)) mem_gen // !inE Qz /=. rewrite -[z](mulKg y) -def_x (exponentP eF) ?groupM //. by rewrite groupV (subsetP sEF). have isoQ: Q \isog 'Q_(2 ^ 3) by rewrite isog_sym sub_isog. have [//|[u v] genQ _] := generators_quaternion _ isoQ. by case/quaternion_structure: genQ => // _ _ [-> _ _ [-> _] _] _ _. Qed. (* The final concluding remark of Aschbacher (23.14). *) Lemma not_isog_Dn_DnQ n : ~~ ('D^n \isog 'D^n.-1*Q). Proof. case: n => [|n] /=; first by rewrite isogEcard card_pX1p2n // card_DnQ andbF. apply: contraL (leqnn n.+1) => isoDn1DnQ. by rewrite -ltnNge -rank_Dn (isog_p_rank isoDn1DnQ) rank_DnQ. Qed.
Quotient.lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Yuyang Zhao -/ import Mathlib.Data.List.Pi import Mathlib.Data.Fintype.Defs /-! # Quotients of families indexed by a finite type This file proves some basic facts and defines lifting and recursion principle for quotients indexed by a finite type. ## Main definitions * `Quotient.finChoice`: Given a function `f : Π i, Quotient (S i)` on a fintype `ι`, returns the class of functions `Π i, α i` sending each `i` to an element of the class `f i`. * `Quotient.finChoiceEquiv`: A finite family of quotients is equivalent to a quotient of finite families. * `Quotient.finLiftOn`: Given a fintype `ι`. A function on `Π i, α i` which respects setoid `S i` for each `i` can be lifted to a function on `Π i, Quotient (S i)`. * `Quotient.finRecOn`: Recursion principle for quotients indexed by a finite type. It is the dependent version of `Quotient.finLiftOn`. -/ namespace Quotient section List variable {ι : Type*} [DecidableEq ι] {α : ι → Sort*} {S : ∀ i, Setoid (α i)} {β : Sort*} /-- Given a collection of setoids indexed by a type `ι`, a list `l` of indices, and a function that for each `i ∈ l` gives a term of the corresponding quotient type, then there is a corresponding term in the quotient of the product of the setoids indexed by `l`. -/ def listChoice {l : List ι} (q : ∀ i ∈ l, Quotient (S i)) : @Quotient (∀ i ∈ l, α i) piSetoid := match l with | [] => ⟦nofun⟧ | i :: _ => Quotient.liftOn₂ (List.Pi.head (i := i) q) (listChoice (List.Pi.tail q)) (⟦List.Pi.cons _ _ · ·⟧) (fun _ _ _ _ ha hl ↦ Quotient.sound (List.Pi.forall_rel_cons_ext ha hl)) theorem listChoice_mk {l : List ι} (a : ∀ i ∈ l, α i) : listChoice (S := S) (⟦a · ·⟧) = ⟦a⟧ := match l with | [] => Quotient.sound nofun | i :: l => by unfold listChoice List.Pi.tail rw [listChoice_mk] exact congrArg (⟦·⟧) (List.Pi.cons_eta a) /-- Choice-free induction principle for quotients indexed by a `List`. -/ @[elab_as_elim] lemma list_ind {l : List ι} {C : (∀ i ∈ l, Quotient (S i)) → Prop} (f : ∀ a : ∀ i ∈ l, α i, C (⟦a · ·⟧)) (q : ∀ i ∈ l, Quotient (S i)) : C q := match l with | [] => cast (congr_arg _ (funext₂ nofun)) (f nofun) | i :: l => by rw [← List.Pi.cons_eta q] induction' List.Pi.head q using Quotient.ind with a refine @list_ind _ (fun q ↦ C (List.Pi.cons _ _ ⟦a⟧ q)) ?_ (List.Pi.tail q) intro as rw [List.Pi.cons_map a as (fun i ↦ Quotient.mk (S i))] exact f _ end List section Fintype variable {ι : Type*} [Fintype ι] [DecidableEq ι] {α : ι → Sort*} {S : ∀ i, Setoid (α i)} {β : Sort*} /-- Choice-free induction principle for quotients indexed by a finite type. See `Quotient.induction_on_pi` for the general version assuming `Classical.choice`. -/ @[elab_as_elim] lemma ind_fintype_pi {C : (∀ i, Quotient (S i)) → Prop} (f : ∀ a : ∀ i, α i, C (⟦a ·⟧)) (q : ∀ i, Quotient (S i)) : C q := by have {m : Multiset ι} (C : (∀ i ∈ m, Quotient (S i)) → Prop) : ∀ (_ : ∀ a : ∀ i ∈ m, α i, C (⟦a · ·⟧)) (q : ∀ i ∈ m, Quotient (S i)), C q := by induction m using Quotient.ind exact list_ind exact this (fun q ↦ C (q · (Finset.mem_univ _))) (fun _ ↦ f _) (fun i _ ↦ q i) /-- Choice-free induction principle for quotients indexed by a finite type. See `Quotient.induction_on_pi` for the general version assuming `Classical.choice`. -/ @[elab_as_elim] lemma induction_on_fintype_pi {C : (∀ i, Quotient (S i)) → Prop} (q : ∀ i, Quotient (S i)) (f : ∀ a : ∀ i, α i, C (⟦a ·⟧)) : C q := ind_fintype_pi f q /-- Given a collection of setoids indexed by a fintype `ι` and a function that for each `i : ι` gives a term of the corresponding quotient type, then there is corresponding term in the quotient of the product of the setoids. See `Quotient.choice` for the noncomputable general version. -/ def finChoice (q : ∀ i, Quotient (S i)) : @Quotient (∀ i, α i) piSetoid := by let e := Equiv.subtypeQuotientEquivQuotientSubtype (fun l : List ι ↦ ∀ i, i ∈ l) (fun s : Multiset ι ↦ ∀ i, i ∈ s) (fun i ↦ Iff.rfl) (fun _ _ ↦ Iff.rfl) ⟨_, Finset.mem_univ⟩ refine e.liftOn (fun l ↦ (listChoice fun i _ ↦ q i).map (fun a i ↦ a i (l.2 i)) ?_) ?_ · exact fun _ _ h i ↦ h i _ intro _ _ _ refine ind_fintype_pi (fun a ↦ ?_) q simp_rw [listChoice_mk, Quotient.map_mk] theorem finChoice_eq (a : ∀ i, α i) : finChoice (S := S) (⟦a ·⟧) = ⟦a⟧ := by dsimp [finChoice] obtain ⟨l, hl⟩ := (Finset.univ.val : Multiset ι).exists_rep simp_rw [← hl, Equiv.subtypeQuotientEquivQuotientSubtype, listChoice_mk] rfl lemma eval_finChoice (f : ∀ i, Quotient (S i)) : eval (finChoice f) = f := induction_on_fintype_pi f (fun a ↦ by rw [finChoice_eq]; rfl) /-- Lift a function on `∀ i, α i` to a function on `∀ i, Quotient (S i)`. -/ def finLiftOn (q : ∀ i, Quotient (S i)) (f : (∀ i, α i) → β) (h : ∀ (a b : ∀ i, α i), (∀ i, a i ≈ b i) → f a = f b) : β := (finChoice q).liftOn f h @[simp] lemma finLiftOn_empty [e : IsEmpty ι] (q : ∀ i, Quotient (S i)) : finLiftOn (β := β) q = fun f _ ↦ f e.elim := by ext f h dsimp [finLiftOn] induction finChoice q using Quotient.ind exact h _ _ e.elim @[simp] lemma finLiftOn_mk (a : ∀ i, α i) : finLiftOn (S := S) (β := β) (⟦a ·⟧) = fun f _ ↦ f a := by ext f h dsimp [finLiftOn] rw [finChoice_eq] rfl /-- `Quotient.finChoice` as an equivalence. -/ @[simps] def finChoiceEquiv : (∀ i, Quotient (S i)) ≃ @Quotient (∀ i, α i) piSetoid where toFun := finChoice invFun := eval left_inv q := by refine induction_on_fintype_pi q (fun a ↦ ?_) rw [finChoice_eq] rfl right_inv q := by induction q using Quotient.ind exact finChoice_eq _ /-- Recursion principle for quotients indexed by a finite type. -/ @[elab_as_elim] def finHRecOn {C : (∀ i, Quotient (S i)) → Sort*} (q : ∀ i, Quotient (S i)) (f : ∀ a : ∀ i, α i, C (⟦a ·⟧)) (h : ∀ (a b : ∀ i, α i), (∀ i, a i ≈ b i) → f a ≍ f b) : C q := eval_finChoice q ▸ (finChoice q).hrecOn f h /-- Recursion principle for quotients indexed by a finite type. -/ @[elab_as_elim] def finRecOn {C : (∀ i, Quotient (S i)) → Sort*} (q : ∀ i, Quotient (S i)) (f : ∀ a : ∀ i, α i, C (⟦a ·⟧)) (h : ∀ (a b : ∀ i, α i) (h : ∀ i, a i ≈ b i), Eq.ndrec (f a) (funext fun i ↦ Quotient.sound (h i)) = f b) : C q := finHRecOn q f (rec_heq_iff_heq.mp <| heq_of_eq <| h · · ·) @[simp] lemma finHRecOn_mk {C : (∀ i, Quotient (S i)) → Sort*} (a : ∀ i, α i) : finHRecOn (C := C) (⟦a ·⟧) = fun f _ ↦ f a := by ext f h refine eq_of_heq ((eqRec_heq _ _).trans ?_) rw [finChoice_eq] rfl @[simp] lemma finRecOn_mk {C : (∀ i, Quotient (S i)) → Sort*} (a : ∀ i, α i) : finRecOn (C := C) (⟦a ·⟧) = fun f _ ↦ f a := by unfold finRecOn simp end Fintype end Quotient namespace Trunc variable {ι : Type*} [DecidableEq ι] [Fintype ι] {α : ι → Sort*} {β : Sort*} /-- Given a function that for each `i : ι` gives a term of the corresponding truncation type, then there is corresponding term in the truncation of the product. -/ def finChoice (q : ∀ i, Trunc (α i)) : Trunc (∀ i, α i) := Quotient.map' id (fun _ _ _ => trivial) (Quotient.finChoice q) theorem finChoice_eq (f : ∀ i, α i) : (Trunc.finChoice fun i => Trunc.mk (f i)) = Trunc.mk f := Subsingleton.elim _ _ /-- Lift a function on `∀ i, α i` to a function on `∀ i, Trunc (α i)`. -/ def finLiftOn (q : ∀ i, Trunc (α i)) (f : (∀ i, α i) → β) (h : ∀ (a b : ∀ i, α i), f a = f b) : β := Quotient.finLiftOn q f (fun _ _ _ ↦ h _ _) @[simp] lemma finLiftOn_empty [e : IsEmpty ι] (q : ∀ i, Trunc (α i)) : finLiftOn (β := β) q = fun f _ ↦ f e.elim := funext₂ fun _ _ ↦ congrFun₂ (Quotient.finLiftOn_empty q) _ _ @[simp] lemma finLiftOn_mk (a : ∀ i, α i) : finLiftOn (β := β) (⟦a ·⟧) = fun f _ ↦ f a := funext₂ fun _ _ ↦ congrFun₂ (Quotient.finLiftOn_mk a) _ _ /-- `Trunc.finChoice` as an equivalence. -/ @[simps] def finChoiceEquiv : (∀ i, Trunc (α i)) ≃ Trunc (∀ i, α i) where toFun := finChoice invFun q i := q.map (· i) left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ /-- Recursion principle for `Trunc`s indexed by a finite type. -/ @[elab_as_elim] def finRecOn {C : (∀ i, Trunc (α i)) → Sort*} (q : ∀ i, Trunc (α i)) (f : ∀ a : ∀ i, α i, C (mk <| a ·)) (h : ∀ (a b : ∀ i, α i), (Eq.ndrec (f a) (funext fun _ ↦ Trunc.eq _ _)) = f b) : C q := Quotient.finRecOn q (f ·) (fun _ _ _ ↦ h _ _) @[simp] lemma finRecOn_mk {C : (∀ i, Trunc (α i)) → Sort*} (a : ∀ i, α i) : finRecOn (C := C) (⟦a ·⟧) = fun f _ ↦ f a := by unfold finRecOn simp end Trunc
Immersion.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.Morphisms.Preimmersion import Mathlib.AlgebraicGeometry.Morphisms.Separated /-! # Immersions of schemes A morphism of schemes `f : X ⟶ Y` is an immersion if the underlying map of topological spaces is a locally closed embedding, and the induced morphisms of stalks are all surjective. This is true if and only if it can be factored into a closed immersion followed by an open immersion. # Main result - `isImmersion_iff_exists`: A morphism is a (locally-closed) immersion if and only if it can be factored into a closed immersion followed by a (dominant) open immersion. -/ universe v u open CategoryTheory Limits namespace AlgebraicGeometry variable {X Y : Scheme.{u}} (f : X ⟶ Y) /-- A morphism of schemes `f : X ⟶ Y` is an immersion if 1. the underlying map of topological spaces is an embedding 2. the range of the map is locally closed 3. the induced morphisms of stalks are all surjective. -/ @[mk_iff] class IsImmersion (f : X ⟶ Y) : Prop extends IsPreimmersion f where isLocallyClosed_range : IsLocallyClosed (Set.range f.base) lemma Scheme.Hom.isLocallyClosed_range (f : X.Hom Y) [IsImmersion f] : IsLocallyClosed (Set.range f.base) := IsImmersion.isLocallyClosed_range /-- Given an immersion `f : X ⟶ Y`, this is the biggest open set `U ⊆ Y` containing the image of `X` such that `X` is closed in `U`. -/ def Scheme.Hom.coborderRange (f : X.Hom Y) [IsImmersion f] : Y.Opens := ⟨coborder (Set.range f.base), f.isLocallyClosed_range.isOpen_coborder⟩ /-- The first part of the factorization of an immersion `f : X ⟶ Y` to a closed immersion `f.liftCoborder : X ⟶ f.coborderRange` and a dominant open immersion `f.coborderRange.ι`. -/ noncomputable def Scheme.Hom.liftCoborder (f : X.Hom Y) [IsImmersion f] : X ⟶ f.coborderRange := IsOpenImmersion.lift f.coborderRange.ι f (by simpa using subset_coborder) /-- Any (locally-closed) immersion can be factored into a closed immersion followed by a (dominant) open immersion. -/ @[reassoc (attr := simp)] lemma Scheme.Hom.liftCoborder_ι (f : X.Hom Y) [IsImmersion f] : f.liftCoborder ≫ f.coborderRange.ι = f := IsOpenImmersion.lift_fac _ _ _ instance [IsImmersion f] : IsClosedImmersion f.liftCoborder := by have : IsPreimmersion (f.liftCoborder ≫ f.coborderRange.ι) := by simp only [Scheme.Hom.liftCoborder_ι]; infer_instance have : IsPreimmersion f.liftCoborder := .of_comp f.liftCoborder f.coborderRange.ι refine .of_isPreimmersion _ ?_ convert isClosed_preimage_val_coborder apply Set.image_injective.mpr f.coborderRange.ι.isEmbedding.injective rw [← Set.range_comp, ← TopCat.coe_comp, ← Scheme.comp_base, f.liftCoborder_ι] exact (Set.image_preimage_eq_of_subset (by simpa using subset_coborder)).symm instance [IsImmersion f] : IsDominant f.coborderRange.ι := by rw [isDominant_iff, DenseRange, Scheme.Opens.range_ι] exact dense_coborder lemma isImmersion_eq_inf : @IsImmersion = (@IsPreimmersion ⊓ topologically fun {_ _} _ _ f ↦ IsLocallyClosed (Set.range f) : MorphismProperty Scheme) := by ext; exact isImmersion_iff _ namespace IsImmersion instance : IsLocalAtTarget @IsImmersion := by suffices IsLocalAtTarget (topologically fun {X Y} _ _ f ↦ IsLocallyClosed (Set.range f)) from isImmersion_eq_inf ▸ inferInstance apply (config := { allowSynthFailures := true }) topologically_isLocalAtTarget' · refine { precomp := ?_, postcomp := ?_ } · intro X Y Z i hi f hf change IsIso i at hi change IsLocallyClosed _ simpa only [Scheme.comp_coeBase, TopCat.coe_comp, Set.range_comp, Set.range_eq_univ.mpr i.surjective, Set.image_univ] · intro X Y Z i hi f hf change IsIso i at hi change IsLocallyClosed _ simp only [Scheme.comp_coeBase, TopCat.coe_comp, Set.range_comp] refine hf.image i.homeomorph.isInducing ?_ rw [Set.range_eq_univ.mpr i.surjective] exact isOpen_univ.isLocallyClosed · simp_rw [Set.range_restrictPreimage] exact fun _ _ _ hU _ ↦ hU.isLocallyClosed_iff_coe_preimage instance (priority := 900) {X Y : Scheme} (f : X ⟶ Y) [IsOpenImmersion f] : IsImmersion f where isLocallyClosed_range := f.isOpenEmbedding.2.isLocallyClosed instance (priority := 900) {X Y : Scheme} (f : X ⟶ Y) [IsClosedImmersion f] : IsImmersion f where isLocallyClosed_range := f.isClosedEmbedding.2.isLocallyClosed instance : MorphismProperty.IsMultiplicative @IsImmersion where id_mem _ := inferInstance comp_mem {X Y Z} f g hf hg := by refine { __ := inferInstanceAs (IsPreimmersion (f ≫ g)), isLocallyClosed_range := ?_ } simp only [Scheme.comp_coeBase, TopCat.coe_comp, Set.range_comp] exact f.isLocallyClosed_range.image g.isEmbedding.isInducing g.isLocallyClosed_range instance comp {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) [IsImmersion f] [IsImmersion g] : IsImmersion (f ≫ g) := MorphismProperty.IsStableUnderComposition.comp_mem f g inferInstance inferInstance variable {f} in /-- A morphism is a (locally-closed) immersion if and only if it can be factored into a closed immersion followed by an open immersion. -/ lemma isImmersion_iff_exists : IsImmersion f ↔ ∃ (Z : Scheme) (g₁ : X ⟶ Z) (g₂ : Z ⟶ Y), IsClosedImmersion g₁ ∧ IsOpenImmersion g₂ ∧ g₁ ≫ g₂ = f := ⟨fun _ ↦ ⟨_, f.liftCoborder, f.coborderRange.ι, inferInstance, inferInstance, f.liftCoborder_ι⟩, fun ⟨_, _, _, _, _, e⟩ ↦ e ▸ inferInstance⟩ theorem of_comp {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) [IsImmersion g] [IsImmersion (f ≫ g)] : IsImmersion f where __ := IsPreimmersion.of_comp f g isLocallyClosed_range := by rw [← Set.preimage_image_eq (Set.range _) g.isEmbedding.injective] have := (f ≫ g).isLocallyClosed_range.preimage g.base.hom.2 simpa only [Scheme.comp_coeBase, TopCat.coe_comp, Set.range_comp] using this theorem comp_iff {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) [IsImmersion g] : IsImmersion (f ≫ g) ↔ IsImmersion f := ⟨fun _ ↦ of_comp f g, fun _ ↦ inferInstance⟩ instance isStableUnderBaseChange : MorphismProperty.IsStableUnderBaseChange @IsImmersion where of_isPullback := by intros X Y Y' S f g f' g' H hg let Z := Limits.pullback f g.coborderRange.ι let e : Y' ⟶ Z := Limits.pullback.lift g' (f' ≫ g.liftCoborder) (by simpa using H.w.symm) have : IsClosedImmersion e := by have := (IsPullback.paste_horiz_iff (.of_hasPullback f g.coborderRange.ι) (show e ≫ Limits.pullback.snd _ _ = _ from Limits.pullback.lift_snd _ _ _)).mp ?_ · exact MorphismProperty.of_isPullback this.flip inferInstance · simpa [e] using H.flip rw [← Limits.pullback.lift_fst (f := f) (g := g.coborderRange.ι) g' (f' ≫ g.liftCoborder) (by simpa using H.w.symm)] infer_instance open Limits Scheme.Pullback in /-- The diagonal morphism is always an immersion. -/ @[stacks 01KJ] instance : IsImmersion (pullback.diagonal f) := by let 𝒰 := Y.affineCover let 𝒱 (i) := (pullback f (𝒰.map i)).affineCover have H : pullback.diagonal f ⁻¹ᵁ diagonalCoverDiagonalRange f 𝒰 𝒱 = ⊤ := top_le_iff.mp fun _ _ ↦ range_diagonal_subset_diagonalCoverDiagonalRange _ _ _ ⟨_, rfl⟩ have := isClosedImmersion_diagonal_restrict_diagonalCoverDiagonalRange f 𝒰 𝒱 have : IsImmersion ((pullback.diagonal f ∣_ diagonalCoverDiagonalRange f 𝒰 𝒱) ≫ Scheme.Opens.ι _) := inferInstance rwa [morphismRestrict_ι, H, ← Scheme.topIso_hom, MorphismProperty.cancel_left_of_respectsIso (P := @IsImmersion)] at this instance : IsImmersion (prod.lift (𝟙 X) (𝟙 X)) := by rw [← MorphismProperty.cancel_right_of_respectsIso @IsImmersion _ (prodIsoPullback X X).hom] convert inferInstanceAs (IsImmersion (pullback.diagonal (terminal.from X))) ext : 1 <;> simp instance (f g : X ⟶ Y) : IsImmersion (equalizer.ι f g) := MorphismProperty.of_isPullback (P := @IsImmersion) (isPullback_equalizer_prod f g).flip inferInstance end IsImmersion end AlgebraicGeometry
mxabelem.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 ssrbool ssrfun eqtype ssrnat seq path. From mathcomp Require Import div choice fintype tuple finfun bigop prime. From mathcomp Require Import ssralg poly finset fingroup morphism perm. From mathcomp Require Import automorphism quotient gproduct action finalg. From mathcomp Require Import zmodp commutator cyclic center pgroup gseries. From mathcomp Require Import nilpotent sylow maximal abelian matrix. From mathcomp Require Import mxalgebra mxrepresentation. (******************************************************************************) (* This file completes the theory developed in mxrepresentation.v with the *) (* construction and properties of linear representations over finite fields, *) (* and in particular the correspondence between internal action on a (normal) *) (* elementary abelian p-subgroup and a linear representation on an Fp-module. *) (* We provide the following next constructions for a finite field F: *) (* 'Zm%act == the action of {unit F} on 'M[F]_(m, n). *) (* rowg A == the additive group of 'rV[F]_n spanned by the row space *) (* of the matrix A. *) (* rowg_mx L == the partial inverse to rowg; for any 'Zm-stable group L *) (* of 'rV[F]_n we have rowg (rowg_mx L) = L. *) (* GLrepr F n == the natural, faithful representation of 'GL_n[F]. *) (* reprGLm rG == the morphism G >-> 'GL_n[F] equivalent to the *) (* representation r of G (with rG : mx_repr r G). *) (* ('MR rG)%act == the action of G on 'rV[F]_n equivalent to the *) (* representation r of G (with rG : mx_repr r G). *) (* The second set of constructions defines the interpretation of a normal *) (* non-trivial elementary abelian p-subgroup as an 'F_p module. We assume *) (* abelE : p.-abelem E and ntE : E != 1, throughout, as these are needed to *) (* build the isomorphism between E and a nontrivial 'rV['F_p]_n. *) (* 'rV(E) == the type of row vectors of the 'F_p module equivalent *) (* to E when E is a non-trivial p.-abelem group. *) (* 'M(E) == the type of matrices corresponding to E. *) (* 'dim E == the width of vectors/matrices in 'rV(E) / 'M(E). *) (* abelem_rV abelE ntE == the one-to-one injection of E onto 'rV(E). *) (* rVabelem abelE ntE == the one-to-one projection of 'rV(E) onto E. *) (* abelem_repr abelE ntE nEG == the representation of G on 'rV(E) that is *) (* equivalent to conjugation by G in E; here abelE, ntE are *) (* as above, and G \subset 'N(E). *) (* This file end with basic results on p-modular representations of p-groups, *) (* and theorems giving the structure of the representation of extraspecial *) (* groups; these results use somewhat more advanced group theory than the *) (* rest of mxrepresentation, in particular, results of sylow.v and maximal.v. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope abelem_scope. Import GroupScope GRing.Theory FinRing.Theory. Local Open Scope ring_scope. (* Special results for representations on a finite field. In this case, the *) (* representation is equivalent to a morphism into the general linear group *) (* 'GL_n[F]. It is furthermore equivalent to a group action on the finite *) (* additive group of the corresponding row space 'rV_n. In addition, row *) (* spaces of matrices in 'M[F]_n correspond to subgroups of that vector group *) (* (this is only surjective when F is a prime field 'F_p), with moduleules *) (* corresponding to subgroups stabilized by the external action. *) Section FinNzRingRepr. Variable (R : finComUnitRingType) (gT : finGroupType). Variables (G : {group gT}) (n : nat) (rG : mx_representation R G n). Definition mx_repr_act (u : 'rV_n) x := u *m rG (val (subg G x)). Lemma mx_repr_actE u x : x \in G -> mx_repr_act u x = u *m rG x. Proof. by move=> Gx; rewrite /mx_repr_act /= subgK. Qed. Fact mx_repr_is_action : is_action G mx_repr_act. Proof. split=> [x | u x y Gx Gy]; first exact: can_inj (repr_mxK _ (subgP _)). by rewrite !mx_repr_actE ?groupM // -mulmxA repr_mxM. Qed. Canonical Structure mx_repr_action := Action mx_repr_is_action. Fact mx_repr_is_groupAction : is_groupAction [set: 'rV[R]_n] mx_repr_action. Proof. move=> x Gx /[!inE]; apply/andP; split; first by apply/subsetP=> u /[!inE]. by apply/morphicP=> /= u v _ _; rewrite !actpermE /= /mx_repr_act mulmxDl. Qed. Canonical Structure mx_repr_groupAction := GroupAction mx_repr_is_groupAction. End FinNzRingRepr. Notation "''MR' rG" := (mx_repr_action rG) (at level 10, rG at level 8) : action_scope. Notation "''MR' rG" := (mx_repr_groupAction rG) : groupAction_scope. Section FinFieldRepr. Variable F : finFieldType. (* The external group action (by scaling) of the multiplicative unit group *) (* of the finite field, and the correspondence between additive subgroups *) (* of row vectors that are stable by this action, and the matrix row spaces. *) Section ScaleAction. Variables m n : nat. Definition scale_act (A : 'M[F]_(m, n)) (a : {unit F}) := val a *: A. Lemma scale_actE A a : scale_act A a = val a *: A. Proof. by []. Qed. Fact scale_is_action : is_action setT scale_act. Proof. apply: is_total_action=> [A | A a b]; rewrite /scale_act ?scale1r //. by rewrite ?scalerA mulrC. Qed. Canonical scale_action := Action scale_is_action. Fact scale_is_groupAction : is_groupAction setT scale_action. Proof. move=> a _ /[1!inE]; apply/andP; split; first by apply/subsetP=> A /[!inE]. by apply/morphicP=> u A _ _ /=; rewrite !actpermE /= /scale_act scalerDr. Qed. Canonical scale_groupAction := GroupAction scale_is_groupAction. Lemma astab1_scale_act A : A != 0 -> 'C[A | scale_action] = 1%g. Proof. rewrite -mxrank_eq0=> nzA; apply/trivgP/subsetP=> a; apply: contraLR. rewrite !inE -val_eqE -subr_eq0 sub1set !inE => nz_a1. by rewrite -subr_eq0 -scaleN1r -scalerDl -mxrank_eq0 eqmx_scale. Qed. End ScaleAction. Local Notation "'Zm" := (scale_action _ _) : action_scope. Section RowGroup. Variable n : nat. Local Notation rVn := 'rV[F]_n. Definition rowg m (A : 'M[F]_(m, n)) : {set rVn} := [set u | u <= A]%MS. Lemma mem_rowg m A v : (v \in @rowg m A) = (v <= A)%MS. Proof. by rewrite inE. Qed. Fact rowg_group_set m A : group_set (@rowg m A). Proof. by apply/group_setP; split=> [|u v]; rewrite !inE ?sub0mx //; apply: addmx_sub. Qed. Canonical rowg_group m A := Group (@rowg_group_set m A). Lemma rowg_stable m (A : 'M_(m, n)) : [acts setT, on rowg A | 'Zm]. Proof. by apply/actsP=> a _ v; rewrite !inE eqmx_scale // -unitfE (valP a). Qed. Lemma rowgS m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (rowg A \subset rowg B) = (A <= B)%MS. Proof. apply/subsetP/idP=> sAB => [|u /[!inE] suA]; last exact: submx_trans sAB. by apply/row_subP=> i; have /[!(inE, row_sub)]-> := sAB (row i A). Qed. Lemma eq_rowg m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :=: B)%MS -> rowg A = rowg B. Proof. by move=> eqAB; apply/eqP; rewrite eqEsubset !rowgS !eqAB andbb. Qed. Lemma rowg0 m : rowg (0 : 'M_(m, n)) = 1%g. Proof. by apply/trivgP/subsetP=> v; rewrite !inE eqmx0 submx0. Qed. Lemma rowg1 : rowg 1%:M = setT. Proof. by apply/setP=> x; rewrite !inE submx1. Qed. Lemma trivg_rowg m (A : 'M_(m, n)) : (rowg A == 1%g) = (A == 0). Proof. by rewrite -submx0 -rowgS rowg0 (sameP trivgP eqP). Qed. Definition rowg_mx (L : {set rVn}) := <<\matrix_(i < #|L|) enum_val i>>%MS. Lemma rowgK m (A : 'M_(m, n)) : (rowg_mx (rowg A) :=: A)%MS. Proof. apply/eqmxP; rewrite !genmxE; apply/andP; split. by apply/row_subP=> i; rewrite rowK; have /[!inE] := enum_valP i. apply/row_subP=> i; set v := row i A. have Av: v \in rowg A by rewrite inE row_sub. by rewrite (eq_row_sub (enum_rank_in Av v)) // rowK enum_rankK_in. Qed. Lemma rowg_mxS (L M : {set 'rV[F]_n}) : L \subset M -> (rowg_mx L <= rowg_mx M)%MS. Proof. move/subsetP=> sLM; rewrite !genmxE; apply/row_subP=> i. rewrite rowK; move: (enum_val i) (sLM _ (enum_valP i)) => v Mv. by rewrite (eq_row_sub (enum_rank_in Mv v)) // rowK enum_rankK_in. Qed. Lemma sub_rowg_mx (L : {set rVn}) : L \subset rowg (rowg_mx L). Proof. apply/subsetP=> v Lv; rewrite inE genmxE. by rewrite (eq_row_sub (enum_rank_in Lv v)) // rowK enum_rankK_in. Qed. Lemma stable_rowg_mxK (L : {group rVn}) : [acts setT, on L | 'Zm] -> rowg (rowg_mx L) = L. Proof. move=> linL; apply/eqP; rewrite eqEsubset sub_rowg_mx andbT. apply/subsetP=> v; rewrite inE genmxE => /submxP[u ->{v}]. rewrite mulmx_sum_row group_prod // => i _. rewrite rowK; move: (enum_val i) (enum_valP i) => v Lv. have [->|] := eqVneq (u 0 i) 0; first by rewrite scale0r group1. by rewrite -unitfE => aP; rewrite ((actsP linL) (FinRing.Unit aP)) ?inE. Qed. Lemma rowg_mx1 : rowg_mx 1%g = 0. Proof. by apply/eqP; rewrite -submx0 -(rowg0 0) rowgK sub0mx. Qed. Lemma rowg_mx_eq0 (L : {group rVn}) : (rowg_mx L == 0) = (L :==: 1%g). Proof. rewrite -trivg_rowg; apply/idP/eqP=> [|->]; last by rewrite rowg_mx1 rowg0. exact/contraTeq/subG1_contra/sub_rowg_mx. Qed. Lemma rowgI m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : rowg (A :&: B)%MS = rowg A :&: rowg B. Proof. by apply/setP=> u; rewrite !inE sub_capmx. Qed. Lemma card_rowg m (A : 'M_(m, n)) : #|rowg A| = (#|F| ^ \rank A)%N. Proof. rewrite -[\rank A]mul1n -card_mx. have injA: injective (mulmxr (row_base A)). have /row_freeP[A' A'K] := row_base_free A. by move=> ?; apply: can_inj (mulmxr A') _ => u; rewrite /= -mulmxA A'K mulmx1. rewrite -(card_image (injA _)); apply: eq_card => v. by rewrite inE -(eq_row_base A) (sameP submxP codomP). Qed. Lemma rowgD m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : rowg (A + B)%MS = (rowg A * rowg B)%g. Proof. apply/eqP; rewrite eq_sym eqEcard mulG_subG /= !rowgS. rewrite addsmxSl addsmxSr -(@leq_pmul2r #|rowg A :&: rowg B|) ?cardG_gt0 //=. by rewrite -mul_cardG -rowgI !card_rowg -!expnD mxrank_sum_cap. Qed. Lemma cprod_rowg m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (rowg A \* rowg B)%g = rowg (A + B)%MS. Proof. by rewrite rowgD cprodE // (sub_abelian_cent2 (zmod_abelian setT)). Qed. Lemma dprod_rowg m1 m2 (A : 'M[F]_(m1, n)) (B : 'M[F]_(m2, n)) : mxdirect (A + B) -> rowg A \x rowg B = rowg (A + B)%MS. Proof. rewrite (sameP mxdirect_addsP eqP) -trivg_rowg rowgI => /eqP tiAB. by rewrite -cprod_rowg dprodEcp. Qed. Lemma bigcprod_rowg m I r (P : pred I) (A : I -> 'M[F]_n) (B : 'M[F]_(m, n)) : (\sum_(i <- r | P i) A i :=: B)%MS -> \big[cprod/1%g]_(i <- r | P i) rowg (A i) = rowg B. Proof. by move/eq_rowg <-; apply/esym/big_morph=> [? ?|]; rewrite (rowg0, cprod_rowg). Qed. Lemma bigdprod_rowg m (I : finType) (P : pred I) A (B : 'M[F]_(m, n)) : let S := (\sum_(i | P i) A i)%MS in (S :=: B)%MS -> mxdirect S -> \big[dprod/1%g]_(i | P i) rowg (A i) = rowg B. Proof. move=> S defS; rewrite mxdirectE defS /= => /eqP rankB. apply: bigcprod_card_dprod (bigcprod_rowg defS) (eq_leq _). by rewrite card_rowg rankB expn_sum; apply: eq_bigr => i; rewrite card_rowg. Qed. End RowGroup. Variables (gT : finGroupType) (G : {group gT}) (n' : nat). Local Notation n := n'.+1. Variable (rG : mx_representation F G n). Fact GL_mx_repr : mx_repr 'GL_n[F] GLval. Proof. by []. Qed. Canonical GLrepr := MxRepresentation GL_mx_repr. Lemma GLmx_faithful : mx_faithful GLrepr. Proof. by apply/subsetP=> A; rewrite !inE mul1mx. Qed. Definition reprGLm x : {'GL_n[F]} := insubd (1%g : {'GL_n[F]}) (rG x). Lemma val_reprGLm x : x \in G -> val (reprGLm x) = rG x. Proof. by move=> Gx; rewrite val_insubd (repr_mx_unitr rG). Qed. Lemma comp_reprGLm : {in G, GLval \o reprGLm =1 rG}. Proof. exact: val_reprGLm. Qed. Lemma reprGLmM : {in G &, {morph reprGLm : x y / x * y}}%g. Proof. by move=> x y Gx Gy; apply: val_inj; rewrite /= !val_reprGLm ?groupM ?repr_mxM. Qed. Canonical reprGL_morphism := Morphism reprGLmM. Lemma ker_reprGLm : 'ker reprGLm = rker rG. Proof. apply/setP=> x; rewrite !inE mul1mx; apply: andb_id2l => Gx. by rewrite -val_eqE val_reprGLm. Qed. Lemma astab_rowg_repr m (A : 'M_(m, n)) : 'C(rowg A | 'MR rG) = rstab rG A. Proof. apply/setP=> x /[!inE]/=; apply: andb_id2l => Gx. apply/subsetP/eqP=> cAx => [|u]; last first. by rewrite !inE mx_repr_actE // => /submxP[u' ->]; rewrite -mulmxA cAx. apply/row_matrixP=> i; apply/eqP; move/implyP: (cAx (row i A)). by rewrite !inE row_sub mx_repr_actE //= row_mul. Qed. Lemma astabs_rowg_repr m (A : 'M_(m, n)) : 'N(rowg A | 'MR rG) = rstabs rG A. Proof. apply/setP=> x /[!inE]/=; apply: andb_id2l => Gx. apply/subsetP/idP=> nAx => [|u]; last first. by rewrite !inE mx_repr_actE // => Au; apply: (submx_trans (submxMr _ Au)). apply/row_subP=> i; move/implyP: (nAx (row i A)). by rewrite !inE row_sub mx_repr_actE //= row_mul. Qed. Lemma acts_rowg (A : 'M_n) : [acts G, on rowg A | 'MR rG] = mxmodule rG A. Proof. by rewrite astabs_rowg_repr. Qed. Lemma astab_setT_repr : 'C(setT | 'MR rG) = rker rG. Proof. by rewrite -rowg1 astab_rowg_repr. Qed. Lemma mx_repr_action_faithful : [faithful G, on setT | 'MR rG] = mx_faithful rG. Proof. by rewrite /faithful astab_setT_repr (setIidPr _) // [rker _]setIdE subsetIl. Qed. Lemma afix_repr (H : {set gT}) : H \subset G -> 'Fix_('MR rG)(H) = rowg (rfix_mx rG H). Proof. move/subsetP=> sHG; apply/setP=> /= u; rewrite !inE. apply/subsetP/rfix_mxP=> cHu x Hx; have:= cHu x Hx; by rewrite !inE /= => /eqP; rewrite mx_repr_actE ?sHG. Qed. Lemma gacent_repr (H : {set gT}) : H \subset G -> 'C_(| 'MR rG)(H) = rowg (rfix_mx rG H). Proof. by move=> sHG; rewrite gacentE // setTI afix_repr. Qed. End FinFieldRepr. Arguments rowg_mx {F n%_N} L%_g. Notation "''Zm'" := (scale_action _ _ _) : action_scope. Notation "''Zm'" := (scale_groupAction _ _ _) : groupAction_scope. Section MatrixGroups. Implicit Types m n p q : nat. Lemma exponent_mx_group m n q : m > 0 -> n > 0 -> q > 1 -> exponent [set: 'M['Z_q]_(m, n)] = q. Proof. move=> m_gt0 n_gt0 q_gt1; apply/eqP; rewrite eqn_dvd; apply/andP; split. apply/exponentP=> x _; apply/matrixP=> i j; rewrite mulmxnE !mxE. by rewrite -mulr_natr -Zp_nat_mod // modnn mulr0. pose cmx1 := const_mx 1%R : 'M['Z_q]_(m, n). apply: dvdn_trans (dvdn_exponent (in_setT cmx1)). have/matrixP/(_ (Ordinal m_gt0))/(_ (Ordinal n_gt0))/eqP := expg_order cmx1. by rewrite mulmxnE !mxE -order_dvdn order_Zp1 Zp_cast. Qed. Lemma rank_mx_group m n q : 'r([set: 'M['Z_q]_(m, n)]) = (m * n)%N. Proof. wlog q_gt1: q / q > 1 by case: q => [|[|q -> //]] /(_ 2)->. set G := setT; have cGG: abelian G := zmod_abelian _. have [mn0 | ] := posnP (m * n). by rewrite [G](card1_trivg _) ?rank1 // cardsT card_mx mn0. rewrite muln_gt0 => /andP[m_gt0 n_gt0]. have expG: exponent G = q := exponent_mx_group m_gt0 n_gt0 q_gt1. apply/eqP; rewrite eqn_leq andbC -(leq_exp2l _ _ q_gt1) -{2}expG. have ->: (q ^ (m * n))%N = #|G| by rewrite cardsT card_mx card_ord Zp_cast. rewrite max_card_abelian //= -grank_abelian //= -/G. pose B : {set 'M['Z_q]_(m, n)} := [set delta_mx ij.1 ij.2 | ij : 'I_m * 'I_n]. suffices ->: G = <<B>>. have ->: (m * n)%N = #|{: 'I_m * 'I_n}| by rewrite card_prod !card_ord. exact: leq_trans (grank_min _) (leq_imset_card _ _). apply/setP=> v; rewrite inE (matrix_sum_delta v). rewrite group_prod // => i _; rewrite group_prod // => j _. rewrite -[v i j]natr_Zp scaler_nat groupX // mem_gen //. by apply/imsetP; exists (i, j). Qed. Lemma mx_group_homocyclic m n q : homocyclic [set: 'M['Z_q]_(m, n)]. Proof. wlog q_gt1: q / q > 1 by case: q => [|[|q -> //]] /(_ 2)->. set G := setT; have cGG: abelian G := zmod_abelian _. rewrite -max_card_abelian //= rank_mx_group cardsT card_mx card_ord -/G. rewrite {1}Zp_cast //; have [-> // | ] := posnP (m * n). by rewrite muln_gt0 => /andP[m_gt0 n_gt0]; rewrite exponent_mx_group. Qed. Lemma abelian_type_mx_group m n q : q > 1 -> abelian_type [set: 'M['Z_q]_(m, n)] = nseq (m * n) q. Proof. rewrite (abelian_type_homocyclic (mx_group_homocyclic m n q)) rank_mx_group. have [-> // | ] := posnP (m * n); rewrite muln_gt0 => /andP[m_gt0 n_gt0] q_gt1. by rewrite exponent_mx_group. Qed. End MatrixGroups. Delimit Scope abelem_scope with Mg. Open Scope abelem_scope. Definition abelem_dim' (gT : finGroupType) (E : {set gT}) := (logn (pdiv #|E|) #|E|).-1. Arguments abelem_dim' {gT} E%_g. Notation "''dim' E" := (abelem_dim' E).+1 (at level 10, E at level 8, format "''dim' E") : abelem_scope. Notation "''rV' ( E )" := 'rV_('dim E) (format "''rV' ( E )") : abelem_scope. Notation "''M' ( E )" := 'M_('dim E) (format "''M' ( E )") : abelem_scope. Notation "''rV[' F ] ( E )" := 'rV[F]_('dim E) (only parsing) : abelem_scope. Notation "''M[' F ] ( E )" := 'M[F]_('dim E) (only parsing) : abelem_scope. Section AbelemRepr. Section FpMatrix. Variables p m n : nat. Local Notation Mmn := 'M['F_p]_(m, n). Lemma mx_Fp_abelem : prime p -> p.-abelem [set: Mmn]. Proof. exact: fin_Fp_lmod_abelem. Qed. Lemma mx_Fp_stable (L : {group Mmn}) : [acts setT, on L | 'Zm]. Proof. apply/subsetP=> a _ /[!inE]; apply/subsetP=> A L_A. by rewrite inE /= /scale_act -[val _]natr_Zp scaler_nat groupX. Qed. End FpMatrix. Section FpRow. Variables p n : nat. Local Notation rVn := 'rV['F_p]_n. Lemma rowg_mxK (L : {group rVn}) : rowg (rowg_mx L) = L. Proof. by apply: stable_rowg_mxK; apply: mx_Fp_stable. Qed. Lemma rowg_mxSK (L : {set rVn}) (M : {group rVn}) : (rowg_mx L <= rowg_mx M)%MS = (L \subset M). Proof. apply/idP/idP; last exact: rowg_mxS. by rewrite -rowgS rowg_mxK; apply/subset_trans/sub_rowg_mx. Qed. Lemma mxrank_rowg (L : {group rVn}) : prime p -> \rank (rowg_mx L) = logn p #|L|. Proof. by move=> p_pr; rewrite -{2}(rowg_mxK L) card_rowg card_Fp ?pfactorK. Qed. End FpRow. Variables (p : nat) (gT : finGroupType) (E : {group gT}). Hypotheses (abelE : p.-abelem E) (ntE : E :!=: 1%g). Let pE : p.-group E := abelem_pgroup abelE. Let p_pr : prime p. Proof. by have [] := pgroup_pdiv pE ntE. Qed. Local Notation n' := (abelem_dim' (gval E)). Local Notation n := n'.+1. Local Notation rVn := 'rV['F_p](gval E). Lemma dim_abelemE : n = logn p #|E|. Proof. rewrite /n'; have [_ _ [k ->]] := pgroup_pdiv pE ntE. by rewrite /pdiv primesX ?primes_prime // pfactorK. Qed. Lemma card_abelem_rV : #|rVn| = #|E|. Proof. by rewrite dim_abelemE card_mx mul1n card_Fp // -p_part part_pnat_id. Qed. Lemma isog_abelem_rV : E \isog [set: rVn]. Proof. by rewrite (isog_abelem_card _ abelE) cardsT card_abelem_rV mx_Fp_abelem /=. Qed. Local Notation ab_rV_P := (existsP isog_abelem_rV). Definition abelem_rV : gT -> rVn := xchoose ab_rV_P. Local Notation ErV := abelem_rV. Lemma abelem_rV_M : {in E &, {morph ErV : x y / (x * y)%g >-> x + y}}. Proof. by case/misomP: (xchooseP ab_rV_P) => fM _; move/morphicP: fM. Qed. Canonical abelem_rV_morphism := Morphism abelem_rV_M. Lemma abelem_rV_isom : isom E setT ErV. Proof. by case/misomP: (xchooseP ab_rV_P). Qed. Lemma abelem_rV_injm : 'injm ErV. Proof. by case/isomP: abelem_rV_isom. Qed. Lemma abelem_rV_inj : {in E &, injective ErV}. Proof. by apply/injmP; apply: abelem_rV_injm. Qed. Lemma im_abelem_rV : ErV @* E = setT. Proof. by case/isomP: abelem_rV_isom. Qed. Lemma mem_im_abelem_rV u : u \in ErV @* E. Proof. by rewrite im_abelem_rV inE. Qed. Lemma sub_im_abelem_rV mA : subset mA (mem (ErV @* E)). Proof. by rewrite unlock; apply/pred0P=> v /=; rewrite mem_im_abelem_rV. Qed. Hint Resolve mem_im_abelem_rV sub_im_abelem_rV : core. Lemma abelem_rV_1 : ErV 1 = 0%R. Proof. by rewrite morph1. Qed. Lemma abelem_rV_X x i : x \in E -> ErV (x ^+ i) = i%:R *: ErV x. Proof. by move=> Ex; rewrite morphX // scaler_nat. Qed. Lemma abelem_rV_V x : x \in E -> ErV x^-1 = - ErV x. Proof. by move=> Ex; rewrite morphV. Qed. Definition rVabelem : rVn -> gT := invm abelem_rV_injm. Canonical rVabelem_morphism := [morphism of rVabelem]. Local Notation rV_E := rVabelem. Lemma rVabelem0 : rV_E 0 = 1%g. Proof. exact: morph1. Qed. Lemma rVabelemD : {morph rV_E : u v / u + v >-> (u * v)%g}. Proof. by move=> u v /=; rewrite -morphM. Qed. Lemma rVabelemN : {morph rV_E: u / - u >-> (u^-1)%g}. Proof. by move=> u /=; rewrite -morphV. Qed. Lemma rVabelemZ (m : 'F_p) : {morph rV_E : u / m *: u >-> (u ^+ m)%g}. Proof. by move=> u; rewrite /= -morphX -?[(u ^+ m)%g]scaler_nat ?natr_Zp. Qed. Lemma abelem_rV_K : {in E, cancel ErV rV_E}. Proof. exact: invmE. Qed. Lemma rVabelemK : cancel rV_E ErV. Proof. by move=> u; rewrite invmK. Qed. Lemma rVabelem_inj : injective rV_E. Proof. exact: can_inj rVabelemK. Qed. Lemma rVabelem_injm : 'injm rV_E. Proof. exact: injm_invm abelem_rV_injm. Qed. Lemma im_rVabelem : rV_E @* setT = E. Proof. by rewrite -im_abelem_rV im_invm. Qed. Lemma mem_rVabelem u : rV_E u \in E. Proof. by rewrite -im_rVabelem mem_morphim. Qed. Lemma sub_rVabelem L : rV_E @* L \subset E. Proof. by rewrite -[_ @* L]morphimIim im_invm subsetIl. Qed. Hint Resolve mem_rVabelem sub_rVabelem : core. Lemma card_rVabelem L : #|rV_E @* L| = #|L|. Proof. by rewrite card_injm ?rVabelem_injm. Qed. Lemma abelem_rV_mK (H : {set gT}) : H \subset E -> rV_E @* (ErV @* H) = H. Proof. exact: morphim_invm abelem_rV_injm H. Qed. Lemma rVabelem_mK L : ErV @* (rV_E @* L) = L. Proof. by rewrite morphim_invmE morphpreK. Qed. Lemma rVabelem_minj : injective (morphim (MorPhantom rV_E)). Proof. exact: can_inj rVabelem_mK. Qed. Lemma rVabelemS L M : (rV_E @* L \subset rV_E @* M) = (L \subset M). Proof. by rewrite injmSK ?rVabelem_injm. Qed. Lemma abelem_rV_S (H K : {set gT}) : H \subset E -> (ErV @* H \subset ErV @* K) = (H \subset K). Proof. by move=> sHE; rewrite injmSK ?abelem_rV_injm. Qed. Lemma sub_rVabelem_im L (H : {set gT}) : (rV_E @* L \subset H) = (L \subset ErV @* H). Proof. by rewrite sub_morphim_pre ?morphpre_invm. Qed. Lemma sub_abelem_rV_im (H : {set gT}) (L : {set 'rV['F_p]_n}) : H \subset E -> (ErV @* H \subset L) = (H \subset rV_E @* L). Proof. by move=> sHE; rewrite sub_morphim_pre ?morphim_invmE. Qed. Section OneGroup. Variable G : {group gT}. Definition abelem_mx_fun (g : subg_of G) v := ErV ((rV_E v) ^ val g). Definition abelem_mx of G \subset 'N(E) := fun x => lin1_mx (abelem_mx_fun (subg G x)). Hypothesis nEG : G \subset 'N(E). Local Notation r := (abelem_mx nEG). Fact abelem_mx_linear_proof g : linear (abelem_mx_fun g). Proof. rewrite /abelem_mx_fun; case: g => x /= /(subsetP nEG) Nx /= m u v. rewrite rVabelemD rVabelemZ conjMg conjXg. by rewrite abelem_rV_M ?abelem_rV_X ?groupX ?memJ_norm // natr_Zp. Qed. HB.instance Definition _ (g : [subg G]) := GRing.isSemilinear.Build 'F_p rVn rVn _ (abelem_mx_fun g) (GRing.semilinear_linear (abelem_mx_linear_proof g)). Let rVabelemJmx v x : x \in G -> rV_E (v *m r x) = (rV_E v) ^ x. Proof. move=> Gx; rewrite /= mul_rV_lin1 /= /abelem_mx_fun subgK //. by rewrite abelem_rV_K // memJ_norm // (subsetP nEG). Qed. Fact abelem_mx_repr : mx_repr G r. Proof. split=> [|x y Gx Gy]; apply/row_matrixP=> i; apply: rVabelem_inj. by rewrite rowE -row1 rVabelemJmx // conjg1. by rewrite !rowE mulmxA !rVabelemJmx ?groupM // conjgM. Qed. Canonical abelem_repr := MxRepresentation abelem_mx_repr. Let rG := abelem_repr. Lemma rVabelemJ v x : x \in G -> rV_E (v *m rG x) = (rV_E v) ^ x. Proof. exact: rVabelemJmx. Qed. Lemma abelem_rV_J : {in E & G, forall x y, ErV (x ^ y) = ErV x *m rG y}. Proof. by move=> x y Ex Gy; rewrite -{1}(abelem_rV_K Ex) -rVabelemJ ?rVabelemK. Qed. Lemma abelem_rowgJ m (A : 'M_(m, n)) x : x \in G -> rV_E @* rowg (A *m rG x) = (rV_E @* rowg A) :^ x. Proof. move=> Gx; apply: (canRL (conjsgKV _)); apply/setP=> y. rewrite mem_conjgV !morphim_invmE !inE memJ_norm ?(subsetP nEG) //=. apply: andb_id2l => Ey; rewrite abelem_rV_J //. by rewrite submxMfree // row_free_unit (repr_mx_unit rG). Qed. Lemma rV_abelem_sJ (L : {group gT}) x : x \in G -> L \subset E -> ErV @* (L :^ x) = rowg (rowg_mx (ErV @* L) *m rG x). Proof. move=> Gx sLE; apply: rVabelem_minj; rewrite abelem_rowgJ //. by rewrite rowg_mxK !morphim_invm // -(normsP nEG x Gx) conjSg. Qed. Lemma rstab_abelem m (A : 'M_(m, n)) : rstab rG A = 'C_G(rV_E @* rowg A). Proof. apply/setP=> x /[!inE]/=; apply: andb_id2l => Gx; apply/eqP/centP => cAx. move=> _ /morphimP[u _ + ->] => /[1!inE] /submxP[{}u ->]. by apply/esym/commgP/conjg_fixP; rewrite -rVabelemJ -?mulmxA ?cAx. apply/row_matrixP=> i; apply: rVabelem_inj. by rewrite row_mul rVabelemJ // /conjg -cAx ?mulKg ?mem_morphim // inE row_sub. Qed. Lemma rstabs_abelem m (A : 'M_(m, n)) : rstabs rG A = 'N_G(rV_E @* rowg A). Proof. apply/setP=> x /[!inE]/=; apply: andb_id2l => Gx. by rewrite -rowgS -rVabelemS abelem_rowgJ. Qed. Lemma rstabs_abelemG (L : {group gT}) : L \subset E -> rstabs rG (rowg_mx (ErV @* L)) = 'N_G(L). Proof. by move=> sLE; rewrite rstabs_abelem rowg_mxK morphim_invm. Qed. Lemma mxmodule_abelem m (U : 'M['F_p]_(m, n)) : mxmodule rG U = (G \subset 'N(rV_E @* rowg U)). Proof. by rewrite -subsetIidl -rstabs_abelem. Qed. Lemma mxmodule_abelemG (L : {group gT}) : L \subset E -> mxmodule rG (rowg_mx (ErV @* L)) = (G \subset 'N(L)). Proof. by move=> sLE; rewrite -subsetIidl -rstabs_abelemG. Qed. Lemma mxsimple_abelemP (U : 'M['F_p]_n) : reflect (mxsimple rG U) (minnormal (rV_E @* rowg U) G). Proof. apply: (iffP mingroupP) => [[/andP[ntU modU] minU] | [modU ntU minU]]. split=> [||V modV sVU ntV]; first by rewrite mxmodule_abelem. by apply: contraNneq ntU => ->; rewrite /= rowg0 morphim1. rewrite -rowgS -rVabelemS [_ @* rowg V]minU //. rewrite -subG1 sub_rVabelem_im morphim1 subG1 trivg_rowg ntV /=. by rewrite -mxmodule_abelem. by rewrite rVabelemS rowgS. split=> [|D /andP[ntD nDG sDU]]. rewrite -subG1 sub_rVabelem_im morphim1 subG1 trivg_rowg ntU /=. by rewrite -mxmodule_abelem. apply/eqP; rewrite eqEsubset sDU sub_rVabelem_im /= -rowg_mxSK rowgK. have sDE: D \subset E := subset_trans sDU (sub_rVabelem _). rewrite minU ?mxmodule_abelemG //. by rewrite -rowgS rowg_mxK sub_abelem_rV_im. by rewrite rowg_mx_eq0 (morphim_injm_eq1 abelem_rV_injm). Qed. Lemma mxsimple_abelemGP (L : {group gT}) : L \subset E -> reflect (mxsimple rG (rowg_mx (ErV @* L))) (minnormal L G). Proof. move/abelem_rV_mK=> {2}<-; rewrite -{2}[_ @* L]rowg_mxK. exact: mxsimple_abelemP. Qed. Lemma abelem_mx_irrP : reflect (mx_irreducible rG) (minnormal E G). Proof. by rewrite -[E in minnormal E G]im_rVabelem -rowg1; apply: mxsimple_abelemP. Qed. Lemma rfix_abelem (H : {set gT}) : H \subset G -> (rfix_mx rG H :=: rowg_mx (ErV @* 'C_E(H)%g))%MS. Proof. move/subsetP=> sHG; apply/eqmxP/andP; split. rewrite -rowgS rowg_mxK -sub_rVabelem_im // subsetI sub_rVabelem /=. apply/centsP=> y /morphimP[v _] /[1!inE] cGv ->{y} x Gx. by apply/commgP/conjg_fixP; rewrite /= -rVabelemJ ?sHG ?(rfix_mxP H _). rewrite genmxE; apply/rfix_mxP=> x Hx; apply/row_matrixP=> i. rewrite row_mul rowK; case/morphimP: (enum_valP i) => z Ez /setIP[_ cHz] ->. by rewrite -abelem_rV_J ?sHG // conjgE (centP cHz) ?mulKg. Qed. Lemma rker_abelem : rker rG = 'C_G(E). Proof. by rewrite /rker rstab_abelem rowg1 im_rVabelem. Qed. Lemma abelem_mx_faithful : 'C_G(E) = 1%g -> mx_faithful rG. Proof. by rewrite /mx_faithful rker_abelem => ->. Qed. End OneGroup. Section SubGroup. Variables G H : {group gT}. Hypotheses (nEG : G \subset 'N(E)) (sHG : H \subset G). Let nEH := subset_trans sHG nEG. Local Notation rG := (abelem_repr nEG). Local Notation rHG := (subg_repr rG sHG). Local Notation rH := (abelem_repr nEH). Lemma eq_abelem_subg_repr : {in H, rHG =1 rH}. Proof. move=> x Hx; apply/row_matrixP=> i; rewrite !rowE !mul_rV_lin1 /=. by rewrite /abelem_mx_fun !subgK ?(subsetP sHG). Qed. Lemma rsim_abelem_subg : mx_rsim rHG rH. Proof. exists 1%:M => [//| |x Hx]; first by rewrite row_free_unit unitmx1. by rewrite mul1mx mulmx1 eq_abelem_subg_repr. Qed. Lemma mxmodule_abelem_subg m (U : 'M_(m, n)) : mxmodule rHG U = mxmodule rH U. Proof. apply: eq_subset_r => x. rewrite [LHS]inE inE; apply: andb_id2l => Hx. by rewrite eq_abelem_subg_repr. Qed. Lemma mxsimple_abelem_subg U : mxsimple rHG U <-> mxsimple rH U. Proof. have eq_modH := mxmodule_abelem_subg; rewrite /mxsimple eq_modH. by split=> [] [-> -> minU]; split=> [//|//|V]; have:= minU V; rewrite eq_modH. Qed. End SubGroup. End AbelemRepr. Arguments rVabelem_inj {p%_N gT E%_G} abelE ntE [v1%_R v2%_R] : rename. Section ModularRepresentation. Variables (F : fieldType) (p : nat) (gT : finGroupType). Hypothesis pcharFp : p \in [pchar F]. Implicit Types G H : {group gT}. (* This is Gorenstein, Lemma 2.6.3. *) Lemma rfix_pgroup_pchar G H n (rG : mx_representation F G n) : n > 0 -> p.-group H -> H \subset G -> rfix_mx rG H != 0. Proof. move=> n_gt0 pH sHG; rewrite -(rfix_subg rG sHG). move: {2}_.+1 (ltnSn (n + #|H|)) {rG G sHG}(subg_repr _ _) => m. elim: m gT H pH => // m IHm gT' G pG in n n_gt0 *; rewrite ltnS => le_nG_m rG. apply/eqP=> Gregular; have irrG: mx_irreducible rG. apply/mx_irrP; split=> // U modU; rewrite -mxrank_eq0 -lt0n => Unz. rewrite /row_full eqn_leq rank_leq_col leqNgt; apply/negP=> ltUn. have: rfix_mx (submod_repr modU) G != 0. by apply: IHm => //; apply: leq_trans le_nG_m; rewrite ltn_add2r. by rewrite -mxrank_eq0 (rfix_submod modU) // Gregular capmx0 linear0 mxrank0. have{m le_nG_m IHm} faithfulG: mx_faithful rG. apply/trivgP/eqP/idPn; set C := _ rG => ntC. suffices: rfix_mx (kquo_repr rG) (G / _)%g != 0. by rewrite -mxrank_eq0 rfix_quo // Gregular mxrank0. apply: (IHm _ _ (morphim_pgroup _ _)) => //. by apply: leq_trans le_nG_m; rewrite ltn_add2l ltn_quotient // rstab_sub. have{Gregular} ntG: G :!=: 1%g. apply: contraL n_gt0; move/eqP=> G1; rewrite -leqNgt -(mxrank1 F n). rewrite -(mxrank0 F n n) -Gregular mxrankS //; apply/rfix_mxP=> x. by rewrite {1}G1 mul1mx => /set1P->; rewrite repr_mx1. have p_pr: prime p by case/andP: pcharFp. have{ntG pG} [z]: {z | z \in 'Z(G) & #[z] = p}; last case/setIP=> Gz cGz ozp. apply: Cauchy => //; apply: contraR ntG; rewrite -p'natE // => p'Z. have pZ: p.-group 'Z(G) by rewrite (pgroupS (center_sub G)). by rewrite (trivg_center_pgroup pG (card1_trivg (pnat_1 pZ p'Z))). have{cGz} cGz1: centgmx rG (rG z - 1%:M). apply/centgmxP=> x Gx; rewrite mulmxBl mulmxBr mulmx1 mul1mx. by rewrite -!repr_mxM // (centP cGz). have{irrG faithfulG cGz1} Urz1: rG z - 1%:M \in unitmx. apply: (mx_Schur irrG) cGz1 _; rewrite subr_eq0. move/implyP: (subsetP faithfulG z). by rewrite !inE Gz mul1mx -order_eq1 ozp -implybNN neq_ltn orbC prime_gt1. do [case: n n_gt0 => // n' _; set n := n'.+1] in rG Urz1 *. have pcharMp: p \in [pchar 'M[F]_n]. exact: (rmorph_pchar (@scalar_mx F n)). have{Urz1}: pFrobenius_aut pcharMp (rG z - 1) \in GRing.unit by rewrite unitrX. rewrite (pFrobenius_autB_comm _ (commr1 _)) pFrobenius_aut1. by rewrite -[_ (rG z)](repr_mxX rG) // -ozp expg_order repr_mx1 subrr unitr0. Qed. Variables (G : {group gT}) (n : nat) (rG : mx_representation F G n). Lemma pcore_sub_rstab_mxsimple_pchar M : mxsimple rG M -> 'O_p(G) \subset rstab rG M. Proof. case=> modM nzM simM; have sGpG := pcore_sub p G. rewrite rfix_mx_rstabC //; set U := rfix_mx _ _. have:= simM (M :&: U)%MS; rewrite sub_capmx submx_refl. apply; rewrite ?capmxSl //. by rewrite capmx_module // normal_rfix_mx_module ?pcore_normal. rewrite -(in_submodK (capmxSl _ _)) val_submod_eq0 -submx0. rewrite -(rfix_submod modM) // submx0 rfix_pgroup_pchar ?pcore_pgroup //. by rewrite lt0n mxrank_eq0. Qed. Lemma pcore_sub_rker_mx_irr_pchar : mx_irreducible rG -> 'O_p(G) \subset rker rG. Proof. exact: pcore_sub_rstab_mxsimple_pchar. Qed. (* This is Gorenstein, Lemma 3.1.3. *) Lemma pcore_faithful_mx_irr_pchar : mx_irreducible rG -> mx_faithful rG -> 'O_p(G) = 1%g. Proof. move=> irrG ffulG; apply/trivgP; apply: subset_trans ffulG. exact: pcore_sub_rstab_mxsimple_pchar. Qed. End ModularRepresentation. #[deprecated(since="mathcomp 2.4.0", note="Use rfix_pgroup_pchar instead.")] Notation rfix_pgroup_char := (rfix_pgroup_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcore_sub_rstab_mxsimple_pchar instead.")] Notation pcore_sub_rstab_mxsimple := (pcore_sub_rstab_mxsimple_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcore_sub_rker_mx_irr_pchar instead.")] Notation pcore_sub_rker_mx_irr := (pcore_sub_rker_mx_irr_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcore_faithful_mx_irr_pchar instead.")] Notation pcore_faithful_mx_irr := (pcore_faithful_mx_irr_pchar) (only parsing). Section Extraspecial. Variables (F : fieldType) (gT : finGroupType) (S : {group gT}) (p n : nat). Hypotheses (pS : p.-group S) (esS : extraspecial S). Hypothesis oSpn : #|S| = (p ^ n.*2.+1)%N. Hypotheses (splitF : group_splitting_field F S) (F'S : [pchar F]^'.-group S). Let p_pr := extraspecial_prime pS esS. Let p_gt0 := prime_gt0 p_pr. Let p_gt1 := prime_gt1 p_pr. Let oZp := card_center_extraspecial pS esS. Let modIp' (i : 'I_p.-1) : (i.+1 %% p = i.+1)%N. Proof. by case: i => i; rewrite /= -ltnS prednK //; apply: modn_small. Qed. (* This is Aschbacher (34.9), parts (1)-(4). *) Theorem extraspecial_repr_structure_pchar (sS : irrType F S) : [/\ #|linear_irr sS| = (p ^ n.*2)%N, exists iphi : 'I_p.-1 -> sS, let phi i := irr_repr (iphi i) in [/\ injective iphi, codom iphi =i ~: linear_irr sS, forall i, mx_faithful (phi i), forall z, z \in 'Z(S)^# -> exists2 w, primitive_root_of_unity p w & forall i, phi i z = (w ^+ i.+1)%:M & forall i, irr_degree (iphi i) = (p ^ n)%N] & #|sS| = (p ^ n.*2 + p.-1)%N]. Proof. have [[defPhiS defS'] prZ] := esS; set linS := linear_irr sS. have nb_lin: #|linS| = (p ^ n.*2)%N. rewrite card_linear_irr // -divgS ?der_sub //=. by rewrite oSpn defS' oZp expnS mulKn. have nb_irr: #|sS| = (p ^ n.*2 + p.-1)%N. pose Zcl := classes S ::&: 'Z(S). have cardZcl: #|Zcl| = p. transitivity #|[set [set z] | z in 'Z(S)]|; last first. by rewrite card_imset //; apply: set1_inj. apply: eq_card => zS; apply/setIdP/imsetP=> [[] | [z]]. case/imsetP=> z Sz ->{zS} szSZ. have Zz: z \in 'Z(S) by rewrite (subsetP szSZ) ?class_refl. exists z => //; rewrite inE Sz in Zz. apply/eqP; rewrite eq_sym eqEcard sub1set class_refl cards1. by rewrite -index_cent1 (setIidPl _) ?indexgg // sub_cent1. case/setIP=> Sz cSz ->{zS}; rewrite sub1set inE Sz; split=> //. apply/imsetP; exists z; rewrite //. apply/eqP; rewrite eqEcard sub1set class_refl cards1. by rewrite -index_cent1 (setIidPl _) ?indexgg // sub_cent1. move/eqP: (class_formula S); rewrite (bigID [in Zcl]) /=. rewrite (eq_bigr (fun _ => 1)) => [|zS]; last first. case/andP=> _ /setIdP[/imsetP[z Sz ->{zS}] /subsetIP[_ cSzS]]. rewrite (setIidPl _) ?indexgg // sub_cent1 (subsetP cSzS) //. exact: mem_repr (class_refl S z). rewrite sum1dep_card setIdE (setIidPr _) 1?cardsE ?cardZcl; last first. by apply/subsetP=> zS /[!inE] /andP[]. have pn_gt0: p ^ n.*2 > 0 by rewrite expn_gt0 p_gt0. rewrite card_irr_pchar // oSpn expnS -(prednK pn_gt0) mulnS eqn_add2l. rewrite (eq_bigr (fun _ => p)) => [|xS]; last first. case/andP=> SxS; rewrite inE SxS; case/imsetP: SxS => x Sx ->{xS} notZxS. have [y Sy ->] := repr_class S x; apply: p_maximal_index => //. apply: cent1_extraspecial_maximal => //; first exact: groupJ. apply: contra notZxS => Zxy; rewrite -{1}(lcoset_id Sy) class_lcoset. rewrite ((_ ^: _ =P [set x ^ y])%g _) ?sub1set // eq_sym eqEcard. rewrite sub1set class_refl cards1 -index_cent1 (setIidPl _) ?indexgg //. by rewrite sub_cent1; apply: subsetP Zxy; apply: subsetIr. rewrite sum_nat_cond_const mulnC eqn_pmul2l //; move/eqP <-. rewrite addSnnS prednK // -cardZcl -[card _](cardsID Zcl) /= addnC. by congr (_ + _)%N; apply: eq_card => t; rewrite !inE andbC // andbAC andbb. have fful_nlin i: i \in ~: linS -> mx_faithful (irr_repr i). rewrite !inE => nlin_phi. apply/trivgP; apply: (TI_center_nil (pgroup_nil pS) (rker_normal _)). rewrite setIC; apply: (prime_TIg prZ); rewrite /= -defS' der1_sub_rker //. exact: socle_irr. have [i0 nlin_i0]: exists i0, i0 \in ~: linS. by apply/card_gt0P; rewrite cardsCs setCK nb_irr nb_lin addKn -subn1 subn_gt0. have [z defZ]: exists z, 'Z(S) = <[z]> by apply/cyclicP; rewrite prime_cyclic. have Zz: z \in 'Z(S) by [rewrite defZ cycle_id]; have [Sz cSz] := setIP Zz. have ozp: #[z] = p by rewrite -oZp defZ. have ntz: z != 1%g by rewrite -order_gt1 ozp. pose phi := irr_repr i0; have irr_phi: mx_irreducible phi := socle_irr i0. pose w := irr_mode i0 z. have phi_z: phi z = w%:M by rewrite /phi irr_center_scalar. have phi_ze e: phi (z ^+ e)%g = (w ^+ e)%:M. by rewrite /phi irr_center_scalar ?groupX ?irr_modeX. have wp1: w ^+ p = 1 by rewrite -irr_modeX // -ozp expg_order irr_mode1. have injw: {in 'Z(S) &, injective (irr_mode i0)}. move=> x y Zx Zy /= eq_xy; have [[Sx _] [Sy _]] := (setIP Zx, setIP Zy). apply: mx_faithful_inj (fful_nlin _ nlin_i0) _ _ Sx Sy _. by rewrite !{1}irr_center_scalar ?eq_xy; first by split. have prim_w e: 0 < e < p -> p.-primitive_root (w ^+ e). case/andP=> e_gt0 lt_e_p; apply/andP; split=> //. apply/eqfunP=> -[d ltdp] /=; rewrite unity_rootE -exprM. rewrite -(irr_mode1 i0) -irr_modeX // (inj_in_eq injw) ?groupX ?group1 //. rewrite -order_dvdn ozp Euclid_dvdM // gtnNdvd //=. move: ltdp; rewrite leq_eqVlt. by case: eqP => [-> _ | _ ltd1p]; rewrite (dvdnn, gtnNdvd). have /cyclicP[a defAutZ]: cyclic (Aut 'Z(S)) by rewrite Aut_prime_cyclic ?ozp. have phi_unitP (i : 'I_p.-1): (i.+1%:R : 'Z_#[z]) \in GRing.unit. by rewrite unitZpE ?order_gt1 // ozp prime_coprime // -lt0n !modIp'. pose ephi i := invm (injm_Zpm a) (Zp_unitm (FinRing.Unit (phi_unitP i))). pose j : 'Z_#[z] := val (invm (injm_Zp_unitm z) a). have co_j_p: coprime j p. rewrite coprime_sym /j; case: (invm _ a) => /=. by rewrite ozp /GRing.unit /= Zp_cast. have [alpha Aut_alpha alphaZ] := center_aut_extraspecial pS esS co_j_p. have alpha_i_z i: ((alpha ^+ ephi i) z = z ^+ i.+1)%g. transitivity ((a ^+ ephi i) z)%g. elim: (ephi i : nat) => // e IHe; rewrite !expgS !permM alphaZ //. have Aut_a: a \in Aut 'Z(S) by rewrite defAutZ cycle_id. rewrite -{2}[a](invmK (injm_Zp_unitm z)); last by rewrite im_Zp_unitm -defZ. rewrite /= autE ?cycle_id // -/j /= /cyclem. rewrite -(autmE (groupX _ Aut_a)) -(autmE (groupX _ Aut_alpha)). by rewrite !morphX //= !autmE IHe. rewrite [(a ^+ _)%g](invmK (injm_Zpm a)) /=; last first. by rewrite im_Zpm -defAutZ defZ Aut_aut. by rewrite autE ?cycle_id //= val_Zp_nat ozp ?modIp'. have rphiP i: S :==: autm (groupX (ephi i) Aut_alpha) @* S by rewrite im_autm. pose rphi i := morphim_repr (eqg_repr phi (rphiP i)) (subxx S). have rphi_irr i: mx_irreducible (rphi i) by apply/morphim_mx_irr/eqg_mx_irr. have rphi_fful i: mx_faithful (rphi i). rewrite /mx_faithful rker_morphim rker_eqg. by rewrite (trivgP (fful_nlin _ nlin_i0)) morphpreIdom; apply: injm_autm. have rphi_z i: rphi i z = (w ^+ i.+1)%:M. by rewrite /rphi [phi]lock /= /morphim_mx autmE alpha_i_z -lock phi_ze. pose iphi i := irr_comp sS (rphi i); pose phi_ i := irr_repr (iphi i). have{} phi_ze i e: phi_ i (z ^+ e)%g = (w ^+ (e * i.+1)%N)%:M. rewrite /phi_ !{1}irr_center_scalar ?groupX ?irr_modeX //. suffices ->: irr_mode (iphi i) z = w ^+ i.+1 by rewrite mulnC exprM. have:= mx_rsim_sym (rsim_irr_comp_pchar sS F'S (rphi_irr i)). case/mx_rsim_def=> B [B' _ homB]; rewrite /irr_mode homB // rphi_z. rewrite -{1}scalemx1 -scalemxAr -scalemxAl -{1}(repr_mx1 (rphi i)). by rewrite -homB // repr_mx1 scalemx1 mxE. have inj_iphi: injective iphi. move=> i1 i2 eqi12; apply/eqP. move/eqP: (congr1 (fun i => irr_mode i (z ^+ 1)) eqi12). rewrite /irr_mode !{1}[irr_repr _ _]phi_ze !{1}mxE !mul1n. by rewrite (eq_prim_root_expr (prim_w 1 p_gt1)) !modIp'. have deg_phi i: irr_degree (iphi i) = irr_degree i0. by case: (rsim_irr_comp_pchar sS F'S (rphi_irr i)). have im_iphi: codom iphi =i ~: linS. apply/subset_cardP; last apply/subsetP=> _ /codomP[i ->]. by rewrite card_image // card_ord cardsCs setCK nb_irr nb_lin addKn. by rewrite !inE /= (deg_phi i) in nlin_i0 *. split=> //; exists iphi; rewrite -/phi_. split=> // [i | ze | i]. - have sim_i := rsim_irr_comp_pchar sS F'S (rphi_irr i). by rewrite -(mx_rsim_faithful sim_i) rphi_fful. - rewrite {1}defZ 2!inE andbC; case/andP. case/cyclePmin=> e; rewrite ozp => lt_e_p ->{ze}. case: (posnP e) => [-> | e_gt0 _]; first by rewrite eqxx. exists (w ^+ e) => [|i]; first by rewrite prim_w ?e_gt0. by rewrite phi_ze exprM. rewrite deg_phi {i}; set d := irr_degree i0. apply/eqP; move/eqP: (sum_irr_degree_pchar sS F'S splitF). rewrite (bigID [in linS]) /= -/irr_degree. rewrite (eq_bigr (fun=> 1)) => [|i]; last by rewrite !inE; move/eqP->. rewrite sum1_card nb_lin. rewrite (eq_bigl [in codom iphi]) // => [|i]; last first. by rewrite -in_setC -im_iphi. rewrite (eq_bigr (fun=> d ^ 2))%N => [|_ /codomP[i ->]]; last first. by rewrite deg_phi. rewrite sum_nat_const card_image // card_ord oSpn (expnS p) -{3}[p]prednK //. rewrite mulSn eqn_add2l eqn_pmul2l; last by rewrite -ltnS prednK. by rewrite -muln2 expnM eqn_sqr. Qed. (* This is the corolloray of the above that is actually used in the proof of *) (* B & G, Theorem 2.5. It encapsulates the dependency on a socle of the *) (* regular representation. *) Variables (m : nat) (rS : mx_representation F S m) (U : 'M[F]_m). Hypotheses (simU : mxsimple rS U) (ffulU : rstab rS U == 1%g). Let sZS := center_sub S. Let rZ := subg_repr rS sZS. Lemma faithful_repr_extraspecial_pchar : \rank U = (p ^ n)%N /\ (forall V, mxsimple rS V -> mx_iso rZ U V -> mx_iso rS U V). Proof. suffices IH V: mxsimple rS V -> mx_iso rZ U V -> [&& \rank U == (p ^ n)%N & mxsimple_iso rS U V]. - split=> [|/= V simV isoUV]. by case/andP: (IH U simU (mx_iso_refl _ _)) => /eqP. by case/andP: (IH V simV isoUV) => _ /(mxsimple_isoP simU). move=> simV isoUV; wlog sS: / irrType F S by apply: socle_exists. have [[_ defS'] prZ] := esS. have{prZ} ntZ: 'Z(S) :!=: 1%g by case: eqP prZ => // ->; rewrite cards1. have [_ [iphi]] := extraspecial_repr_structure_pchar sS. set phi := fun i => _ => [] [inj_phi im_phi _ phiZ dim_phi] _. have [modU nzU _]:= simU; pose rU := submod_repr modU. have nlinU: \rank U != 1. apply/eqP=> /(rker_linear rU); apply/negP; rewrite /rker rstab_submod. by rewrite (eqmx_rstab _ (val_submod1 _)) (eqP ffulU) defS' subG1. have irrU: mx_irreducible rU by apply/submod_mx_irr. have rsimU := rsim_irr_comp_pchar sS F'S irrU. set iU := irr_comp sS rU in rsimU; have [_ degU _ _]:= rsimU. have phiUP: iU \in codom iphi by rewrite im_phi !inE -degU. rewrite degU -(f_iinv phiUP) dim_phi eqxx /=; apply/(mxsimple_isoP simU). have [modV _ _]:= simV; pose rV := submod_repr modV. have irrV: mx_irreducible rV by apply/submod_mx_irr. have rsimV := rsim_irr_comp_pchar sS F'S irrV. set iV := irr_comp sS rV in rsimV; have [_ degV _ _]:= rsimV. have phiVP: iV \in codom iphi by rewrite im_phi !inE -degV -(mxrank_iso isoUV). pose jU := iinv phiUP; pose jV := iinv phiVP. have [z Zz ntz]:= trivgPn _ ntZ. have [|w prim_w phi_z] := phiZ z; first by rewrite 2!inE ntz. suffices eqjUV: jU == jV. apply/(mx_rsim_iso modU modV); apply: mx_rsim_trans rsimU _. by rewrite -(f_iinv phiUP) -/jU (eqP eqjUV) f_iinv; apply: mx_rsim_sym. have rsimUV: mx_rsim (subg_repr (phi jU) sZS) (subg_repr (phi jV) sZS). have [bU _ bUfree bUhom] := mx_rsim_sym rsimU. have [bV _ bVfree bVhom] := rsimV. have modUZ := mxmodule_subg sZS modU; have modVZ := mxmodule_subg sZS modV. case/(mx_rsim_iso modUZ modVZ): isoUV => [bZ degZ bZfree bZhom]. rewrite /phi !f_iinv; exists (bU *m bZ *m bV)=> [||x Zx]. - by rewrite -degU degZ degV. - by rewrite /row_free !mxrankMfree. have Sx := subsetP sZS x Zx. rewrite 2!mulmxA bUhom // -(mulmxA _ _ bZ) bZhom //. by rewrite -!(mulmxA bU) -!(mulmxA bZ) bVhom. have{rsimUV} [B [B' _ homB]] := mx_rsim_def rsimUV. have:= eqxx (irr_mode (iphi jU) z); rewrite /irr_mode; set i0 := Ordinal _. rewrite {2}[_ z]homB // ![_ z]phi_z mxE mulr1n -scalemx1 -scalemxAr -scalemxAl. rewrite -(repr_mx1 (subg_repr (phi jV) sZS)) -{B B'}homB // repr_mx1 scalemx1. by rewrite mxE (eq_prim_root_expr prim_w) !modIp'. Qed. End Extraspecial. #[deprecated(since="mathcomp 2.4.0", note="Use extraspecial_repr_structure_pchar instead.")] Notation extraspecial_repr_structure := (extraspecial_repr_structure_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use faithful_repr_extraspecial_pchar instead.")] Notation faithful_repr_extraspecial := (faithful_repr_extraspecial_pchar) (only parsing).
Translations.lean
/- Copyright (c) 2020 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Computation.Basic import Mathlib.Algebra.ContinuedFractions.Translations import Mathlib.Algebra.Order.Floor.Ring /-! # Basic Translation Lemmas Between Structures Defined for Computing Continued Fractions ## Summary This is a collection of simple lemmas between the different structures used for the computation of continued fractions defined in `Mathlib/Algebra/ContinuedFractions/Computation/Basic.lean`. The file consists of three sections: 1. Recurrences and inversion lemmas for `IntFractPair.stream`: these lemmas give us inversion rules and recurrences for the computation of the stream of integer and fractional parts of a value. 2. Translation lemmas for the head term: these lemmas show us that the head term of the computed continued fraction of a value `v` is `⌊v⌋` and how this head term is moved along the structures used in the computation process. 3. Translation lemmas for the sequence: these lemmas show how the sequences of the involved structures (`IntFractPair.stream`, `IntFractPair.seq1`, and `GenContFract.of`) are connected, i.e. how the values are moved along the structures and the termination of one sequence implies the termination of another sequence. ## Main Theorems - `succ_nth_stream_eq_some_iff` gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of non-termination. - `succ_nth_stream_eq_none_iff` gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of termination. - `get?_of_eq_some_of_succ_get?_intFractPair_stream` and `get?_of_eq_some_of_get?_intFractPair_stream_fr_ne_zero` show how the entries of the sequence of the computed continued fraction can be obtained from the stream of integer and fractional parts. -/ assert_not_exists Finset namespace GenContFract open GenContFract (of) -- Fix a discrete linear ordered division ring with `floor` function and a value `v`. variable {K : Type*} [DivisionRing K] [LinearOrder K] [FloorRing K] {v : K} namespace IntFractPair /-! ### Recurrences and Inversion Lemmas for `IntFractPair.stream` Here we state some lemmas that give us inversion rules and recurrences for the computation of the stream of integer and fractional parts of a value. -/ theorem stream_zero (v : K) : IntFractPair.stream v 0 = some (IntFractPair.of v) := rfl variable {n : ℕ} theorem stream_eq_none_of_fr_eq_zero {ifp_n : IntFractPair K} (stream_nth_eq : IntFractPair.stream v n = some ifp_n) (nth_fr_eq_zero : ifp_n.fr = 0) : IntFractPair.stream v (n + 1) = none := by obtain ⟨_, fr⟩ := ifp_n change fr = 0 at nth_fr_eq_zero simp [IntFractPair.stream, stream_nth_eq, nth_fr_eq_zero] /-- Gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of termination. -/ theorem succ_nth_stream_eq_none_iff : IntFractPair.stream v (n + 1) = none ↔ IntFractPair.stream v n = none ∨ ∃ ifp, IntFractPair.stream v n = some ifp ∧ ifp.fr = 0 := by rw [IntFractPair.stream] cases IntFractPair.stream v n <;> simp [imp_false] /-- Gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of non-termination. -/ theorem succ_nth_stream_eq_some_iff {ifp_succ_n : IntFractPair K} : IntFractPair.stream v (n + 1) = some ifp_succ_n ↔ ∃ ifp_n : IntFractPair K, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n := by simp [IntFractPair.stream, ite_eq_iff, Option.bind_eq_some_iff] /-- An easier to use version of one direction of `GenContFract.IntFractPair.succ_nth_stream_eq_some_iff`. -/ theorem stream_succ_of_some {p : IntFractPair K} (h : IntFractPair.stream v n = some p) (h' : p.fr ≠ 0) : IntFractPair.stream v (n + 1) = some (IntFractPair.of p.fr⁻¹) := succ_nth_stream_eq_some_iff.mpr ⟨p, h, h', rfl⟩ /-- The stream of `IntFractPair`s of an integer stops after the first term. -/ theorem stream_succ_of_int [IsStrictOrderedRing K] (a : ℤ) (n : ℕ) : IntFractPair.stream (a : K) (n + 1) = none := by induction n with | zero => refine IntFractPair.stream_eq_none_of_fr_eq_zero (IntFractPair.stream_zero (a : K)) ?_ simp only [IntFractPair.of, Int.fract_intCast] | succ n ih => exact IntFractPair.succ_nth_stream_eq_none_iff.mpr (Or.inl ih) theorem exists_succ_nth_stream_of_fr_zero {ifp_succ_n : IntFractPair K} (stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) (succ_nth_fr_eq_zero : ifp_succ_n.fr = 0) : ∃ ifp_n : IntFractPair K, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr⁻¹ = ⌊ifp_n.fr⁻¹⌋ := by -- get the witness from `succ_nth_stream_eq_some_iff` and prove that it has the additional -- properties rcases succ_nth_stream_eq_some_iff.mp stream_succ_nth_eq with ⟨ifp_n, seq_nth_eq, _, rfl⟩ refine ⟨ifp_n, seq_nth_eq, ?_⟩ simpa only [IntFractPair.of, Int.fract, sub_eq_zero] using succ_nth_fr_eq_zero /-- A recurrence relation that expresses the `(n+1)`th term of the stream of `IntFractPair`s of `v` for non-integer `v` in terms of the `n`th term of the stream associated to the inverse of the fractional part of `v`. -/ theorem stream_succ (h : Int.fract v ≠ 0) (n : ℕ) : IntFractPair.stream v (n + 1) = IntFractPair.stream (Int.fract v)⁻¹ n := by induction n with | zero => have H : (IntFractPair.of v).fr = Int.fract v := by simp [IntFractPair.of] rw [stream_zero, stream_succ_of_some (stream_zero v) (ne_of_eq_of_ne H h), H] | succ n ih => rcases eq_or_ne (IntFractPair.stream (Int.fract v)⁻¹ n) none with hnone | hsome · rw [hnone] at ih rw [succ_nth_stream_eq_none_iff.mpr (Or.inl hnone), succ_nth_stream_eq_none_iff.mpr (Or.inl ih)] · obtain ⟨p, hp⟩ := Option.ne_none_iff_exists'.mp hsome rw [hp] at ih rcases eq_or_ne p.fr 0 with hz | hnz · rw [stream_eq_none_of_fr_eq_zero hp hz, stream_eq_none_of_fr_eq_zero ih hz] · rw [stream_succ_of_some hp hnz, stream_succ_of_some ih hnz] end IntFractPair section Head /-! ### Translation of the Head Term Here we state some lemmas that show us that the head term of the computed continued fraction of a value `v` is `⌊v⌋` and how this head term is moved along the structures used in the computation process. -/ /-- The head term of the sequence with head of `v` is just the integer part of `v`. -/ @[simp] theorem IntFractPair.seq1_fst_eq_of : (IntFractPair.seq1 v).fst = IntFractPair.of v := rfl theorem of_h_eq_intFractPair_seq1_fst_b : (of v).h = (IntFractPair.seq1 v).fst.b := by cases aux_seq_eq : IntFractPair.seq1 v simp [of, aux_seq_eq] /-- The head term of the gcf of `v` is `⌊v⌋`. -/ @[simp] theorem of_h_eq_floor : (of v).h = ⌊v⌋ := by simp [of_h_eq_intFractPair_seq1_fst_b, IntFractPair.of] end Head section sequence /-! ### Translation of the Sequences Here we state some lemmas that show how the sequences of the involved structures (`IntFractPair.stream`, `IntFractPair.seq1`, and `GenContFract.of`) are connected, i.e. how the values are moved along the structures and how the termination of one sequence implies the termination of another sequence. -/ variable {n : ℕ} theorem IntFractPair.get?_seq1_eq_succ_get?_stream : (IntFractPair.seq1 v).snd.get? n = (IntFractPair.stream v) (n + 1) := rfl section Termination /-! #### Translation of the Termination of the Sequences Let's first show how the termination of one sequence implies the termination of another sequence. -/ theorem of_terminatedAt_iff_intFractPair_seq1_terminatedAt : (of v).TerminatedAt n ↔ (IntFractPair.seq1 v).snd.TerminatedAt n := Option.map_eq_none_iff theorem of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none : (of v).TerminatedAt n ↔ IntFractPair.stream v (n + 1) = none := by rw [of_terminatedAt_iff_intFractPair_seq1_terminatedAt, Stream'.Seq.TerminatedAt, IntFractPair.get?_seq1_eq_succ_get?_stream] end Termination section Values /-! #### Translation of the Values of the Sequence Now let's show how the values of the sequences correspond to one another. -/ theorem IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some {gp_n : Pair K} (s_nth_eq : (of v).s.get? n = some gp_n) : ∃ ifp : IntFractPair K, IntFractPair.stream v (n + 1) = some ifp ∧ (ifp.b : K) = gp_n.b := by obtain ⟨ifp, stream_succ_nth_eq, gp_n_eq⟩ : ∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ Pair.mk 1 (ifp.b : K) = gp_n := by unfold of IntFractPair.seq1 at s_nth_eq simpa [Stream'.Seq.get?_tail, Stream'.Seq.map_get?] using s_nth_eq cases gp_n_eq simp_all only [Option.some.injEq, exists_eq_left'] /-- Shows how the entries of the sequence of the computed continued fraction can be obtained by the integer parts of the stream of integer and fractional parts. -/ theorem get?_of_eq_some_of_succ_get?_intFractPair_stream {ifp_succ_n : IntFractPair K} (stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) : (of v).s.get? n = some ⟨1, ifp_succ_n.b⟩ := by unfold of IntFractPair.seq1 simp [Stream'.Seq.map_tail, Stream'.Seq.get?_tail, Stream'.Seq.map_get?, stream_succ_nth_eq] /-- Shows how the entries of the sequence of the computed continued fraction can be obtained by the fractional parts of the stream of integer and fractional parts. -/ theorem get?_of_eq_some_of_get?_intFractPair_stream_fr_ne_zero {ifp_n : IntFractPair K} (stream_nth_eq : IntFractPair.stream v n = some ifp_n) (nth_fr_ne_zero : ifp_n.fr ≠ 0) : (of v).s.get? n = some ⟨1, (IntFractPair.of ifp_n.fr⁻¹).b⟩ := have : IntFractPair.stream v (n + 1) = some (IntFractPair.of ifp_n.fr⁻¹) := by cases ifp_n simp only [IntFractPair.stream, stream_nth_eq, Option.bind_some, ite_eq_right_iff] intro; contradiction get?_of_eq_some_of_succ_get?_intFractPair_stream this open Int IntFractPair theorem of_s_head_aux (v : K) : (of v).s.get? 0 = (IntFractPair.stream v 1).bind (some ∘ fun p => { a := 1 b := p.b }) := by rw [of, IntFractPair.seq1] simp only [Stream'.Seq.map, Stream'.Seq.tail, Stream'.Seq.get?, Stream'.map] rw [← Stream'.get_succ, Stream'.get, Option.map.eq_def] split <;> simp_all only [Option.bind_some, Option.bind_none, Function.comp_apply] /-- This gives the first pair of coefficients of the continued fraction of a non-integer `v`. -/ theorem of_s_head (h : fract v ≠ 0) : (of v).s.head = some ⟨1, ⌊(fract v)⁻¹⌋⟩ := by change (of v).s.get? 0 = _ rw [of_s_head_aux, stream_succ_of_some (stream_zero v) h, Option.bind] rfl variable (K) variable [IsStrictOrderedRing K] /-- If `a` is an integer, then the coefficient sequence of its continued fraction is empty. -/ theorem of_s_of_int (a : ℤ) : (of (a : K)).s = Stream'.Seq.nil := haveI h : ∀ n, (of (a : K)).s.get? n = none := by intro n induction n with | zero => rw [of_s_head_aux, stream_succ_of_int, Option.bind] | succ n ih => exact (of (a : K)).s.prop ih Stream'.Seq.ext fun n => (h n).trans (Stream'.Seq.get?_nil n).symm variable {K} (v) /-- Recurrence for the `GenContFract.of` an element `v` of `K` in terms of that of the inverse of the fractional part of `v`. -/ theorem of_s_succ (n : ℕ) : (of v).s.get? (n + 1) = (of (fract v)⁻¹).s.get? n := by rcases eq_or_ne (fract v) 0 with h | h · obtain ⟨a, rfl⟩ : ∃ a : ℤ, v = a := ⟨⌊v⌋, eq_of_sub_eq_zero h⟩ rw [fract_intCast, inv_zero, of_s_of_int, ← cast_zero, of_s_of_int, Stream'.Seq.get?_nil, Stream'.Seq.get?_nil] rcases eq_or_ne ((of (fract v)⁻¹).s.get? n) none with h₁ | h₁ · rwa [h₁, ← terminatedAt_iff_s_none, of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none, stream_succ h, ← of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none, terminatedAt_iff_s_none] · obtain ⟨p, hp⟩ := Option.ne_none_iff_exists'.mp h₁ obtain ⟨p', hp'₁, _⟩ := exists_succ_get?_stream_of_gcf_of_get?_eq_some hp have Hp := get?_of_eq_some_of_succ_get?_intFractPair_stream hp'₁ rw [← stream_succ h] at hp'₁ rw [Hp, get?_of_eq_some_of_succ_get?_intFractPair_stream hp'₁] /-- This expresses the tail of the coefficient sequence of the `GenContFract.of` an element `v` of `K` as the coefficient sequence of that of the inverse of the fractional part of `v`. -/ theorem of_s_tail : (of v).s.tail = (of (fract v)⁻¹).s := Stream'.Seq.ext fun n => Stream'.Seq.get?_tail (of v).s n ▸ of_s_succ v n variable (K) (n) /-- If `a` is an integer, then the `convs'` of its continued fraction expansion are all equal to `a`. -/ theorem convs'_of_int (a : ℤ) : (of (a : K)).convs' n = a := by induction n with | zero => simp only [zeroth_conv'_eq_h, of_h_eq_floor, floor_intCast] | succ => rw [convs', of_h_eq_floor, floor_intCast, add_eq_left] exact convs'Aux_succ_none ((of_s_of_int K a).symm ▸ Stream'.Seq.get?_nil 0) _ variable {K} /-- The recurrence relation for the `convs'` of the continued fraction expansion of an element `v` of `K` in terms of the convergents of the inverse of its fractional part. -/ theorem convs'_succ : (of v).convs' (n + 1) = ⌊v⌋ + 1 / (of (fract v)⁻¹).convs' n := by rcases eq_or_ne (fract v) 0 with h | h · obtain ⟨a, rfl⟩ : ∃ a : ℤ, v = a := ⟨⌊v⌋, eq_of_sub_eq_zero h⟩ rw [convs'_of_int, fract_intCast, inv_zero, ← cast_zero, convs'_of_int, cast_zero, div_zero, add_zero, floor_intCast] · rw [convs', of_h_eq_floor, add_right_inj, convs'Aux_succ_some (of_s_head h)] exact congr_arg (1 / ·) (by rw [convs', of_h_eq_floor, add_right_inj, of_s_tail]) end Values end sequence end GenContFract
L2Space.lean
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Analysis.InnerProductSpace.LinearMap import Mathlib.MeasureTheory.Function.LpSpace.ContinuousFunctions import Mathlib.MeasureTheory.Function.StronglyMeasurable.Inner import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap /-! # `L^2` space If `E` is an inner product space over `𝕜` (`ℝ` or `ℂ`), then `Lp E 2 μ` (defined in `Mathlib/MeasureTheory/Function/LpSpace.lean`) is also an inner product space, with inner product defined as `inner f g := ∫ a, ⟪f a, g a⟫ ∂μ`. ### Main results * `mem_L1_inner` : for `f` and `g` in `Lp E 2 μ`, the pointwise inner product `fun x ↦ ⟪f x, g x⟫` belongs to `Lp 𝕜 1 μ`. * `integrable_inner` : for `f` and `g` in `Lp E 2 μ`, the pointwise inner product `fun x ↦ ⟪f x, g x⟫` is integrable. * `L2.innerProductSpace` : `Lp E 2 μ` is an inner product space. -/ noncomputable section open TopologicalSpace MeasureTheory MeasureTheory.Lp Filter open scoped NNReal ENNReal MeasureTheory namespace MeasureTheory section variable {α F : Type*} {m : MeasurableSpace α} {μ : Measure α} [NormedAddCommGroup F] theorem MemLp.integrable_sq {f : α → ℝ} (h : MemLp f 2 μ) : Integrable (fun x => f x ^ 2) μ := by simpa [← memLp_one_iff_integrable] using h.norm_rpow two_ne_zero ENNReal.ofNat_ne_top @[deprecated (since := "2025-02-21")] alias Memℒp.integrable_sq := MemLp.integrable_sq theorem memLp_two_iff_integrable_sq_norm {f : α → F} (hf : AEStronglyMeasurable f μ) : MemLp f 2 μ ↔ Integrable (fun x => ‖f x‖ ^ 2) μ := by rw [← memLp_one_iff_integrable] convert (memLp_norm_rpow_iff hf two_ne_zero ENNReal.ofNat_ne_top).symm · simp · rw [div_eq_mul_inv, ENNReal.mul_inv_cancel two_ne_zero ENNReal.ofNat_ne_top] @[deprecated (since := "2025-02-21")] alias memℒp_two_iff_integrable_sq_norm := memLp_two_iff_integrable_sq_norm theorem memLp_two_iff_integrable_sq {f : α → ℝ} (hf : AEStronglyMeasurable f μ) : MemLp f 2 μ ↔ Integrable (fun x => f x ^ 2) μ := by convert memLp_two_iff_integrable_sq_norm hf using 3 simp @[deprecated (since := "2025-02-21")] alias memℒp_two_iff_integrable_sq := memLp_two_iff_integrable_sq end section InnerProductSpace variable {α : Type*} {m : MeasurableSpace α} {p : ℝ≥0∞} {μ : Measure α} variable {E 𝕜 : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] local notation "⟪" x ", " y "⟫" => inner 𝕜 x y theorem MemLp.const_inner (c : E) {f : α → E} (hf : MemLp f p μ) : MemLp (fun a => ⟪c, f a⟫) p μ := hf.of_le_mul (AEStronglyMeasurable.inner aestronglyMeasurable_const hf.1) (Eventually.of_forall fun _ => norm_inner_le_norm _ _) @[deprecated (since := "2025-02-21")] alias Memℒp.const_inner := MemLp.const_inner theorem MemLp.inner_const {f : α → E} (hf : MemLp f p μ) (c : E) : MemLp (fun a => ⟪f a, c⟫) p μ := hf.of_le_mul (c := ‖c‖) (AEStronglyMeasurable.inner hf.1 aestronglyMeasurable_const) (Eventually.of_forall fun x => by rw [mul_comm]; exact norm_inner_le_norm _ _) @[deprecated (since := "2025-02-21")] alias Memℒp.inner_const := MemLp.inner_const variable {f : α → E} @[fun_prop] theorem Integrable.const_inner (c : E) (hf : Integrable f μ) : Integrable (fun x => ⟪c, f x⟫) μ := by rw [← memLp_one_iff_integrable] at hf ⊢; exact hf.const_inner c @[fun_prop] theorem Integrable.inner_const (hf : Integrable f μ) (c : E) : Integrable (fun x => ⟪f x, c⟫) μ := by rw [← memLp_one_iff_integrable] at hf ⊢; exact hf.inner_const c variable [CompleteSpace E] [NormedSpace ℝ E] theorem _root_.integral_inner {f : α → E} (hf : Integrable f μ) (c : E) : ∫ x, ⟪c, f x⟫ ∂μ = ⟪c, ∫ x, f x ∂μ⟫ := ((innerSL 𝕜 c).restrictScalars ℝ).integral_comp_comm hf variable (𝕜) theorem _root_.integral_eq_zero_of_forall_integral_inner_eq_zero (f : α → E) (hf : Integrable f μ) (hf_int : ∀ c : E, ∫ x, ⟪c, f x⟫ ∂μ = 0) : ∫ x, f x ∂μ = 0 := by specialize hf_int (∫ x, f x ∂μ); rwa [integral_inner hf, inner_self_eq_zero] at hf_int end InnerProductSpace namespace L2 variable {α E F 𝕜 : Type*} [RCLike 𝕜] [MeasurableSpace α] {μ : Measure α} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [NormedAddCommGroup F] local notation "⟪" x ", " y "⟫" => inner 𝕜 x y theorem eLpNorm_rpow_two_norm_lt_top (f : Lp F 2 μ) : eLpNorm (fun x => ‖f x‖ ^ (2 : ℝ)) 1 μ < ∞ := by have h_two : ENNReal.ofReal (2 : ℝ) = 2 := by simp rw [eLpNorm_norm_rpow f zero_lt_two, one_mul, h_two] exact ENNReal.rpow_lt_top_of_nonneg zero_le_two (Lp.eLpNorm_ne_top f) theorem eLpNorm_inner_lt_top (f g : α →₂[μ] E) : eLpNorm (fun x : α => ⟪f x, g x⟫) 1 μ < ∞ := by have h : ∀ x, ‖⟪f x, g x⟫‖ ≤ ‖‖f x‖ ^ (2 : ℝ) + ‖g x‖ ^ (2 : ℝ)‖ := by intro x rw [← @Nat.cast_two ℝ, Real.rpow_natCast, Real.rpow_natCast] calc ‖⟪f x, g x⟫‖ ≤ ‖f x‖ * ‖g x‖ := norm_inner_le_norm _ _ _ ≤ 2 * ‖f x‖ * ‖g x‖ := (mul_le_mul_of_nonneg_right (le_mul_of_one_le_left (norm_nonneg _) one_le_two) (norm_nonneg _)) -- TODO(kmill): the type ascription is getting around an elaboration error _ ≤ ‖(‖f x‖ ^ 2 + ‖g x‖ ^ 2 : ℝ)‖ := (two_mul_le_add_sq _ _).trans (le_abs_self _) refine (eLpNorm_mono_ae (ae_of_all _ h)).trans_lt ((eLpNorm_add_le ?_ ?_ le_rfl).trans_lt ?_) · exact ((Lp.aestronglyMeasurable f).norm.aemeasurable.pow_const _).aestronglyMeasurable · exact ((Lp.aestronglyMeasurable g).norm.aemeasurable.pow_const _).aestronglyMeasurable rw [ENNReal.add_lt_top] exact ⟨eLpNorm_rpow_two_norm_lt_top f, eLpNorm_rpow_two_norm_lt_top g⟩ section InnerProductSpace open scoped ComplexConjugate instance : Inner 𝕜 (α →₂[μ] E) := ⟨fun f g => ∫ a, ⟪f a, g a⟫ ∂μ⟩ theorem inner_def (f g : α →₂[μ] E) : ⟪f, g⟫ = ∫ a : α, ⟪f a, g a⟫ ∂μ := rfl theorem integral_inner_eq_sq_eLpNorm (f : α →₂[μ] E) : ∫ a, ⟪f a, f a⟫ ∂μ = ENNReal.toReal (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ (2 : ℝ) ∂μ) := by simp_rw [inner_self_eq_norm_sq_to_K] norm_cast rw [integral_eq_lintegral_of_nonneg_ae] rotate_left · exact Filter.Eventually.of_forall fun x => sq_nonneg _ · exact ((Lp.aestronglyMeasurable f).norm.aemeasurable.pow_const _).aestronglyMeasurable congr ext1 x have h_two : (2 : ℝ) = ((2 : ℕ) : ℝ) := by simp rw [← Real.rpow_natCast _ 2, ← h_two, ← ENNReal.ofReal_rpow_of_nonneg (norm_nonneg _) zero_le_two, ofReal_norm_eq_enorm] norm_cast private theorem norm_sq_eq_re_inner (f : α →₂[μ] E) : ‖f‖ ^ 2 = RCLike.re ⟪f, f⟫ := by have h_two : (2 : ℝ≥0∞).toReal = 2 := by simp rw [inner_def, integral_inner_eq_sq_eLpNorm, norm_def, ← ENNReal.toReal_pow, RCLike.ofReal_re, ENNReal.toReal_eq_toReal (ENNReal.pow_ne_top (Lp.eLpNorm_ne_top f)) _] · rw [← ENNReal.rpow_natCast, eLpNorm_eq_eLpNorm' two_ne_zero ENNReal.ofNat_ne_top, eLpNorm', ← ENNReal.rpow_mul, one_div, h_two] simp [enorm_eq_nnnorm] · refine (lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top zero_lt_two (ε := E) ?_).ne rw [← h_two, ← eLpNorm_eq_eLpNorm' two_ne_zero ENNReal.ofNat_ne_top] exact Lp.eLpNorm_lt_top f @[deprecated (since := "2025-04-22")] alias norm_sq_eq_inner' := norm_sq_eq_re_inner theorem mem_L1_inner (f g : α →₂[μ] E) : AEEqFun.mk (fun x => ⟪f x, g x⟫) ((Lp.aestronglyMeasurable f).inner (Lp.aestronglyMeasurable g)) ∈ Lp 𝕜 1 μ := by simp_rw [mem_Lp_iff_eLpNorm_lt_top, eLpNorm_aeeqFun]; exact eLpNorm_inner_lt_top f g theorem integrable_inner (f g : α →₂[μ] E) : Integrable (fun x : α => ⟪f x, g x⟫) μ := (integrable_congr (AEEqFun.coeFn_mk (fun x => ⟪f x, g x⟫) ((Lp.aestronglyMeasurable f).inner (Lp.aestronglyMeasurable g)))).mp (AEEqFun.integrable_iff_mem_L1.mpr (mem_L1_inner f g)) private theorem add_left' (f f' g : α →₂[μ] E) : ⟪f + f', g⟫ = ⟪f, g⟫ + ⟪f', g⟫ := by simp_rw [inner_def, ← integral_add (integrable_inner (𝕜 := 𝕜) f g) (integrable_inner f' g), ← inner_add_left] refine integral_congr_ae ((coeFn_add f f').mono fun x hx => ?_) simp only [hx, Pi.add_apply] private theorem smul_left' (f g : α →₂[μ] E) (r : 𝕜) : ⟪r • f, g⟫ = conj r * ⟪f, g⟫ := by rw [inner_def, inner_def, ← smul_eq_mul, ← integral_smul] refine integral_congr_ae ((coeFn_smul r f).mono fun x hx => ?_) simp only rw [smul_eq_mul, ← inner_smul_left, hx, Pi.smul_apply] instance innerProductSpace : InnerProductSpace 𝕜 (α →₂[μ] E) where norm_sq_eq_re_inner := norm_sq_eq_re_inner conj_inner_symm _ _ := by simp_rw [inner_def, ← integral_conj, inner_conj_symm] add_left := add_left' smul_left := smul_left' end InnerProductSpace section IndicatorConstLp variable (𝕜) {s : Set α} /-- The inner product in `L2` of the indicator of a set `indicatorConstLp 2 hs hμs c` and `f` is equal to the integral of the inner product over `s`: `∫ x in s, ⟪c, f x⟫ ∂μ`. -/ theorem inner_indicatorConstLp_eq_setIntegral_inner (f : Lp E 2 μ) (hs : MeasurableSet s) (c : E) (hμs : μ s ≠ ∞) : (⟪indicatorConstLp 2 hs hμs c, f⟫ : 𝕜) = ∫ x in s, ⟪c, f x⟫ ∂μ := by rw [inner_def, ← integral_add_compl hs (L2.integrable_inner _ f)] have h_left : (∫ x in s, ⟪(indicatorConstLp 2 hs hμs c) x, f x⟫ ∂μ) = ∫ x in s, ⟪c, f x⟫ ∂μ := by suffices h_ae_eq : ∀ᵐ x ∂μ, x ∈ s → ⟪indicatorConstLp 2 hs hμs c x, f x⟫ = ⟪c, f x⟫ from setIntegral_congr_ae hs h_ae_eq have h_indicator : ∀ᵐ x : α ∂μ, x ∈ s → indicatorConstLp 2 hs hμs c x = c := indicatorConstLp_coeFn_mem refine h_indicator.mono fun x hx hxs => ?_ congr exact hx hxs have h_right : (∫ x in sᶜ, ⟪(indicatorConstLp 2 hs hμs c) x, f x⟫ ∂μ) = 0 := by suffices h_ae_eq : ∀ᵐ x ∂μ, x ∉ s → ⟪indicatorConstLp 2 hs hμs c x, f x⟫ = 0 by simp_rw [← Set.mem_compl_iff] at h_ae_eq suffices h_int_zero : (∫ x in sᶜ, ⟪indicatorConstLp 2 hs hμs c x, f x⟫ ∂μ) = ∫ _ in sᶜ, 0 ∂μ by rw [h_int_zero] simp exact setIntegral_congr_ae hs.compl h_ae_eq have h_indicator : ∀ᵐ x : α ∂μ, x ∉ s → indicatorConstLp 2 hs hμs c x = 0 := indicatorConstLp_coeFn_notMem refine h_indicator.mono fun x hx hxs => ?_ rw [hx hxs] exact inner_zero_left _ rw [h_left, h_right, add_zero] /-- The inner product in `L2` of the indicator of a set `indicatorConstLp 2 hs hμs c` and `f` is equal to the inner product of the constant `c` and the integral of `f` over `s`. -/ theorem inner_indicatorConstLp_eq_inner_setIntegral [CompleteSpace E] [NormedSpace ℝ E] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : E) (f : Lp E 2 μ) : (⟪indicatorConstLp 2 hs hμs c, f⟫ : 𝕜) = ⟪c, ∫ x in s, f x ∂μ⟫ := by rw [← integral_inner (integrableOn_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hμs), L2.inner_indicatorConstLp_eq_setIntegral_inner] variable {𝕜} /-- The inner product in `L2` of the indicator of a set `indicatorConstLp 2 hs hμs (1 : 𝕜)` and a real or complex function `f` is equal to the integral of `f` over `s`. -/ theorem inner_indicatorConstLp_one (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (f : Lp 𝕜 2 μ) : ⟪indicatorConstLp 2 hs hμs (1 : 𝕜), f⟫ = ∫ x in s, f x ∂μ := by rw [L2.inner_indicatorConstLp_eq_inner_setIntegral 𝕜 hs hμs (1 : 𝕜) f]; simp end IndicatorConstLp end L2 section InnerContinuous variable {α 𝕜 : Type*} [TopologicalSpace α] [MeasurableSpace α] [BorelSpace α] [RCLike 𝕜] variable (μ : Measure α) [IsFiniteMeasure μ] open scoped BoundedContinuousFunction ComplexConjugate local notation "⟪" x ", " y "⟫" => inner 𝕜 x y /-- For bounded continuous functions `f`, `g` on a finite-measure topological space `α`, the L^2 inner product is the integral of their pointwise inner product. -/ theorem BoundedContinuousFunction.inner_toLp (f g : α →ᵇ 𝕜) : ⟪BoundedContinuousFunction.toLp 2 μ 𝕜 f, BoundedContinuousFunction.toLp 2 μ 𝕜 g⟫ = ∫ x, g x * conj (f x) ∂μ := by apply integral_congr_ae have hf_ae := f.coeFn_toLp 2 μ 𝕜 have hg_ae := g.coeFn_toLp 2 μ 𝕜 filter_upwards [hf_ae, hg_ae] with _ hf hg rw [hf, hg] simp variable [CompactSpace α] /-- For continuous functions `f`, `g` on a compact, finite-measure topological space `α`, the L^2 inner product is the integral of their pointwise inner product. -/ theorem ContinuousMap.inner_toLp (f g : C(α, 𝕜)) : ⟪ContinuousMap.toLp 2 μ 𝕜 f, ContinuousMap.toLp 2 μ 𝕜 g⟫ = ∫ x, g x * conj (f x) ∂μ := by apply integral_congr_ae have hf_ae := f.coeFn_toLp (p := 2) (𝕜 := 𝕜) μ have hg_ae := g.coeFn_toLp (p := 2) (𝕜 := 𝕜) μ filter_upwards [hf_ae, hg_ae] with _ hf hg rw [hf, hg] simp end InnerContinuous end MeasureTheory
Basic.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.LinearAlgebra.TensorProduct.RightExactness import Mathlib.RingTheory.Ideal.Cotangent import Mathlib.RingTheory.Localization.Defs /-! # Extension of algebras ## Main definition - `Algebra.Extension`: An extension of an `R`-algebra `S` is an `R` algebra `P` together with a surjection `P →ₐ[R] R`. - `Algebra.Extension.Hom`: Given a commuting square ``` R --→ P -→ S | | ↓ ↓ R' -→ P' → S ``` A hom between `P` and `P'` is a ring homomorphism that makes the two squares commute. - `Algebra.Extension.Cotangent`: The cotangent space wrt an extension `P → S` by `I`, i.e. the space `I/I²`. -/ universe w u v open TensorProduct MvPolynomial variable (R : Type u) (S : Type v) [CommRing R] [CommRing S] [Algebra R S] /-- An extension of an `R`-algebra `S` is an `R` algebra `P` together with a surjection `P →ₐ[R] S`. Also see `Algebra.Extension.ofSurjective`. -/ structure Algebra.Extension where /-- The underlying algebra of an extension. -/ Ring : Type w [commRing : CommRing Ring] [algebra₁ : Algebra R Ring] [algebra₂ : Algebra Ring S] [isScalarTower : IsScalarTower R Ring S] /-- A chosen (set-theoretic) section of an extension. -/ σ : S → Ring algebraMap_σ : ∀ x, algebraMap Ring S (σ x) = x namespace Algebra.Extension variable {R S} variable (P : Extension.{w} R S) attribute [instance] commRing algebra₁ algebra₂ isScalarTower attribute [simp] algebraMap_σ -- We want to make sure `R₀` acts compatibly on `R` and `S` to avoid unsensical instances @[nolint unusedArguments] noncomputable instance {R₀} [CommRing R₀] [Algebra R₀ R] [Algebra R₀ S] [IsScalarTower R₀ R S] : Algebra R₀ P.Ring := Algebra.compHom P.Ring (algebraMap R₀ R) instance {R₀} [CommRing R₀] [Algebra R₀ R] [Algebra R₀ S] [IsScalarTower R₀ R S] : IsScalarTower R₀ R P.Ring := IsScalarTower.of_algebraMap_eq' rfl instance {R₀} [CommRing R₀] [Algebra R₀ R] [Algebra R₀ S] [IsScalarTower R₀ R S] {R₁} [CommRing R₁] [Algebra R₁ R] [Algebra R₁ S] [IsScalarTower R₁ R S] [Algebra R₀ R₁] [IsScalarTower R₀ R₁ R] : IsScalarTower R₀ R₁ P.Ring := IsScalarTower.of_algebraMap_eq' <| by rw [IsScalarTower.algebraMap_eq R₀ R, IsScalarTower.algebraMap_eq R₁ R, RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq R₀ R₁ R] instance {R₀} [CommRing R₀] [Algebra R₀ R] [Algebra R₀ S] [IsScalarTower R₀ R S] : IsScalarTower R₀ P.Ring S := IsScalarTower.of_algebraMap_eq' <| by rw [IsScalarTower.algebraMap_eq R₀ R P.Ring, ← RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq] @[simp] lemma σ_smul (x y) : P.σ x • y = x * y := by rw [Algebra.smul_def, algebraMap_σ] lemma σ_injective : P.σ.Injective := by intro x y e rw [← P.algebraMap_σ x, ← P.algebraMap_σ y, e] lemma algebraMap_surjective : Function.Surjective (algebraMap P.Ring S) := (⟨_, P.algebraMap_σ ·⟩) section Construction /-- Construct `Extension` from a surjective algebra homomorphism. -/ @[simps -isSimp Ring σ] noncomputable def ofSurjective {P : Type w} [CommRing P] [Algebra R P] (f : P →ₐ[R] S) (h : Function.Surjective f) : Extension.{w} R S where Ring := P algebra₂ := f.toAlgebra isScalarTower := letI := f.toAlgebra; IsScalarTower.of_algebraMap_eq' f.comp_algebraMap.symm σ x := (h x).choose algebraMap_σ x := (h x).choose_spec variable (R S) in /-- The trivial extension of `S`. -/ @[simps -isSimp Ring σ] noncomputable def self : Extension R S where Ring := S σ := _root_.id algebraMap_σ _ := rfl /-- The kernel of an extension. -/ abbrev ker : Ideal P.Ring := RingHom.ker (algebraMap P.Ring S) section Localization variable (M : Submonoid S) {S' : Type*} [CommRing S'] [Algebra S S'] [IsLocalization M S'] variable [Algebra R S'] [IsScalarTower R S S'] /-- An `R`-extension `P → S` gives an `R`-extension `Pₘ → Sₘ`. Note that this is different from `baseChange` as the base does not change. -/ noncomputable def localization (P : Extension.{w} R S) : Extension R S' where Ring := Localization (M.comap (algebraMap P.Ring S)) algebra₂ := (IsLocalization.lift (M := (M.comap (algebraMap P.Ring S))) (g := (algebraMap S S').comp (algebraMap P.Ring S)) (by simpa using fun x hx ↦ IsLocalization.map_units S' ⟨_, hx⟩)).toAlgebra isScalarTower := by letI : Algebra (Localization (M.comap (algebraMap P.Ring S))) S' := (IsLocalization.lift (M := (M.comap (algebraMap P.Ring S))) (g := (algebraMap S S').comp (algebraMap P.Ring S)) (by simpa using fun x hx ↦ IsLocalization.map_units S' ⟨_, hx⟩)).toAlgebra apply IsScalarTower.of_algebraMap_eq' rw [RingHom.algebraMap_toAlgebra, IsScalarTower.algebraMap_eq R P.Ring (Localization _), ← RingHom.comp_assoc, IsLocalization.lift_comp, RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq] σ s := Localization.mk (P.σ (IsLocalization.sec M s).1) ⟨P.σ (IsLocalization.sec M s).2, by simp⟩ algebraMap_σ s := by simp [RingHom.algebraMap_toAlgebra, Localization.mk_eq_mk', IsLocalization.lift_mk', Units.mul_inv_eq_iff_eq_mul, IsUnit.coe_liftRight, IsLocalization.sec_spec] end Localization variable {T} [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T] /-- The base change of an `R`-extension of `S` to `T` gives a `T`-extension of `T ⊗[R] S`. -/ noncomputable def baseChange {T} [CommRing T] [Algebra R T] (P : Extension R S) : Extension T (T ⊗[R] S) where Ring := T ⊗[R] P.Ring __ := ofSurjective (P := T ⊗[R] P.Ring) (Algebra.TensorProduct.map (AlgHom.id T T) (IsScalarTower.toAlgHom _ _ _)) (LinearMap.lTensor_surjective T (g := (IsScalarTower.toAlgHom R P.Ring S).toLinearMap) P.algebraMap_surjective) end Construction variable {R' S'} [CommRing R'] [CommRing S'] [Algebra R' S'] (P' : Extension R' S') variable {R'' S''} [CommRing R''] [CommRing S''] [Algebra R'' S''] (P'' : Extension R'' S'') section Hom section variable [Algebra R R'] [Algebra R' R''] [Algebra R R''] variable [Algebra S S'] [Algebra S' S''] [Algebra S S''] /-- Given a commuting square ``` R --→ P -→ S | | ↓ ↓ R' -→ P' → S ``` A hom between `P` and `P'` is a ring homomorphism that makes the two squares commute. -/ @[ext] structure Hom where /-- The underlying ring homomorphism of a hom between extensions. -/ toRingHom : P.Ring →+* P'.Ring toRingHom_algebraMap : ∀ x, toRingHom (algebraMap R P.Ring x) = algebraMap R' P'.Ring (algebraMap R R' x) algebraMap_toRingHom : ∀ x, (algebraMap P'.Ring S' (toRingHom x)) = algebraMap S S' (algebraMap P.Ring S x) attribute [simp] Hom.toRingHom_algebraMap Hom.algebraMap_toRingHom variable {P P'} /-- A hom between extensions as an algebra homomorphism. -/ noncomputable def Hom.toAlgHom [Algebra R S'] [IsScalarTower R R' S'] (f : Hom P P') : P.Ring →ₐ[R] P'.Ring where __ := f.toRingHom commutes' := by simp [← IsScalarTower.algebraMap_apply] @[simp] lemma Hom.toAlgHom_apply [Algebra R S'] [IsScalarTower R R' S'] (f : Hom P P') (x) : f.toAlgHom x = f.toRingHom x := rfl variable (P P') /-- The identity hom. -/ @[simps] protected noncomputable def Hom.id : Hom P P := ⟨RingHom.id _, by simp, by simp⟩ @[simp] lemma Hom.toAlgHom_id : Hom.toAlgHom (.id P) = AlgHom.id _ _ := by ext1; simp variable {P P' P''} variable [IsScalarTower R R' R''] [IsScalarTower S S' S''] in /-- The composition of two homs. -/ @[simps] noncomputable def Hom.comp (f : Hom P' P'') (g : Hom P P') : Hom P P'' where toRingHom := f.toRingHom.comp g.toRingHom toRingHom_algebraMap := by simp [← IsScalarTower.algebraMap_apply] algebraMap_toRingHom := by simp [← IsScalarTower.algebraMap_apply] @[simp] lemma Hom.comp_id (f : Hom P P') : f.comp (Hom.id P) = f := by ext; simp @[simp] lemma Hom.id_comp (f : Hom P P') : (Hom.id P').comp f = f := by ext; simp [Hom.id] /-- A map between extensions induce a map between kernels. -/ @[simps] def Hom.mapKer (f : P.Hom P') [alg : Algebra P.Ring P'.Ring] (halg : algebraMap P.Ring P'.Ring = f.toRingHom) : P.ker →ₗ[P.Ring] P'.ker where toFun x := ⟨f.toRingHom x, by simp [show algebraMap P.Ring S x = 0 from x.2]⟩ map_add' _ _ := Subtype.ext (map_add _ _ _) map_smul' := by simp [Algebra.smul_def, ← halg] end end Hom section Infinitesimal /-- Given an `R`-algebra extension `0 → I → P → S → 0` of `S`, the infinitesimal extension associated to it is `0 → I/I² → P/I² → S → 0`. -/ noncomputable def infinitesimal (P : Extension R S) : Extension R S where Ring := P.Ring ⧸ P.ker ^ 2 σ := Ideal.Quotient.mk _ ∘ P.σ algebraMap_σ x := by dsimp; exact P.algebraMap_σ x /-- The canonical map `P → P/I²` as maps between extensions. -/ noncomputable def toInfinitesimal (P : Extension R S) : P.Hom P.infinitesimal where toRingHom := Ideal.Quotient.mk _ toRingHom_algebraMap _ := rfl algebraMap_toRingHom _ := rfl lemma ker_infinitesimal (P : Extension R S) : P.infinitesimal.ker = P.ker.cotangentIdeal := AlgHom.ker_kerSquareLift _ end Infinitesimal section Cotangent /-- The cotangent space of an extension. This is a type synonym so that `P.Ring` can act on it through the action of `S` without creating a diamond. -/ def Cotangent : Type _ := P.ker.Cotangent noncomputable instance : AddCommGroup P.Cotangent := inferInstanceAs (AddCommGroup P.ker.Cotangent) variable {P} /-- The identity map `P.ker.Cotangent → P.Cotangent` into the type synonym. -/ def Cotangent.of (x : P.ker.Cotangent) : P.Cotangent := x /-- The identity map `P.Cotangent → P.ker.Cotangent` from the type synonym. -/ def Cotangent.val (x : P.Cotangent) : P.ker.Cotangent := x @[ext] lemma Cotangent.ext {x y : P.Cotangent} (e : x.val = y.val) : x = y := e namespace Cotangent variable (x y : P.Cotangent) (w z : P.ker.Cotangent) @[simp] lemma val_add : (x + y).val = x.val + y.val := rfl @[simp] lemma val_zero : (0 : P.Cotangent).val = 0 := rfl @[simp] lemma of_add : of (w + z) = of w + of z := rfl @[simp] lemma of_zero : (of 0 : P.Cotangent) = 0 := rfl @[simp] lemma of_val : of x.val = x := rfl @[simp] lemma val_of : (of w).val = w := rfl @[simp] lemma val_sub : (x - y).val = x.val - y.val := rfl end Cotangent lemma Cotangent.smul_eq_zero_of_mem (p : P.Ring) (hp : p ∈ P.ker) (m : P.ker.Cotangent) : p • m = 0 := by obtain ⟨x, rfl⟩ := Ideal.toCotangent_surjective _ m rw [← map_smul, Ideal.toCotangent_eq_zero, Submodule.coe_smul, smul_eq_mul, pow_two] exact Ideal.mul_mem_mul hp x.2 attribute [local simp] RingHom.mem_ker noncomputable instance Cotangent.module : Module S P.Cotangent where smul := fun r s ↦ .of (P.σ r • s.val) smul_zero := fun r ↦ ext (smul_zero (P.σ r)) smul_add := fun r x y ↦ ext (smul_add (P.σ r) x.val y.val) add_smul := fun r s x ↦ by have := smul_eq_zero_of_mem (P.σ (r + s) - (P.σ r + P.σ s) : P.Ring) (by simp ) x simpa only [sub_smul, add_smul, sub_eq_zero] zero_smul := fun x ↦ smul_eq_zero_of_mem (P.σ 0 : P.Ring) (by simp) x one_smul := fun x ↦ by have := smul_eq_zero_of_mem (P.σ 1 - 1 : P.Ring) (by simp) x simpa [sub_eq_zero, sub_smul] mul_smul := fun r s x ↦ by have := smul_eq_zero_of_mem (P.σ (r * s) - (P.σ r * P.σ s) : P.Ring) (by simp) x simpa only [sub_smul, mul_smul, sub_eq_zero] using this noncomputable instance {R₀} [CommRing R₀] [Algebra R₀ S] : Module R₀ P.Cotangent := Module.compHom P.Cotangent (algebraMap R₀ S) instance {R₁ R₂} [CommRing R₁] [CommRing R₂] [Algebra R₁ S] [Algebra R₂ S] [Algebra R₁ R₂] [IsScalarTower R₁ R₂ S] : IsScalarTower R₁ R₂ P.Cotangent := by constructor intros r s m change algebraMap R₂ S (r • s) • m = (algebraMap _ S r) • (algebraMap _ S s) • m rw [Algebra.smul_def, map_mul, mul_smul, ← IsScalarTower.algebraMap_apply] /-- The action of `R₀` on `P.Cotangent` for an extension `P → S`, if `S` is an `R₀` algebra. -/ lemma Cotangent.val_smul''' {R₀} [CommRing R₀] [Algebra R₀ S] (r : R₀) (x : P.Cotangent) : (r • x).val = P.σ (algebraMap R₀ S r) • x.val := rfl /-- The action of `S` on `P.Cotangent` for an extension `P → S`. -/ @[simp] lemma Cotangent.val_smul (r : S) (x : P.Cotangent) : (r • x).val = P.σ r • x.val := rfl /-- The action of `P` on `P.Cotangent` for an extension `P → S`. -/ @[simp] lemma Cotangent.val_smul' (r : P.Ring) (x : P.Cotangent) : (r • x).val = r • x.val := by rw [val_smul''', ← sub_eq_zero, ← sub_smul] exact Cotangent.smul_eq_zero_of_mem _ (by simp) _ /-- The action of `R` on `P.Cotangent` for an `R`-extension `P → S`. -/ @[simp] lemma Cotangent.val_smul'' (r : R) (x : P.Cotangent) : (r • x).val = r • x.val := by rw [← algebraMap_smul P.Ring, val_smul', algebraMap_smul] /-- The quotient map from the kernel of `P → S` onto the cotangent space. -/ noncomputable def Cotangent.mk : P.ker →ₗ[P.Ring] P.Cotangent where toFun x := .of (Ideal.toCotangent _ x) map_add' x y := by simp map_smul' x y := ext <| by simp @[simp] lemma Cotangent.val_mk (x : P.ker) : (mk x).val = Ideal.toCotangent _ x := rfl lemma Cotangent.mk_surjective : Function.Surjective (mk (P := P)) := fun x ↦ Ideal.toCotangent_surjective P.ker x.val lemma Cotangent.mk_eq_zero_iff {P : Extension R S} (x : P.ker) : Cotangent.mk x = 0 ↔ x.val ∈ P.ker ^ 2 := by simp [Cotangent.ext_iff, Ideal.toCotangent_eq_zero] variable {P'} variable [Algebra R R'] [Algebra R' R''] [Algebra R' S''] variable [Algebra S S'] [Algebra S' S''] [Algebra S S''] variable [Algebra R S'] [IsScalarTower R R' S'] /-- A hom between two extensions induces a map between cotangent spaces. -/ noncomputable def Cotangent.map (f : Hom P P') : P.Cotangent →ₗ[S] P'.Cotangent where toFun x := .of (Ideal.mapCotangent (R := R) _ _ f.toAlgHom (fun x hx ↦ by simpa using RingHom.congr_arg (algebraMap S S') hx) x.val) map_add' x y := ext (map_add _ x.val y.val) map_smul' r x := by ext obtain ⟨x, rfl⟩ := Cotangent.mk_surjective x obtain ⟨r, rfl⟩ := P.algebraMap_surjective r simp only [algebraMap_smul, val_smul', val_mk, val_of, Ideal.mapCotangent_toCotangent, RingHomCompTriple.comp_apply, ← (Ideal.toCotangent _).map_smul] conv_rhs => rw [← algebraMap_smul S', ← f.algebraMap_toRingHom, algebraMap_smul, val_smul', val_of, ← (Ideal.toCotangent _).map_smul] congr 1 ext1 simp only [SetLike.val_smul, smul_eq_mul, map_mul, Hom.toAlgHom_apply] @[simp] lemma Cotangent.map_mk (f : Hom P P') (x) : Cotangent.map f (.mk x) = .mk ⟨f.toAlgHom x, by simpa [-map_aeval] using RingHom.congr_arg (algebraMap S S') x.2⟩ := rfl @[simp] lemma Cotangent.map_id : Cotangent.map (.id P) = LinearMap.id := by ext x obtain ⟨x, rfl⟩ := Cotangent.mk_surjective x simp only [map_mk, Hom.toAlgHom_id, AlgHom.coe_id, id_eq, Subtype.coe_eta, val_mk, LinearMap.id_coe] variable [Algebra R R''] [IsScalarTower R R' R''] [IsScalarTower R' R'' S''] [Algebra R S''] [IsScalarTower R R'' S''] [IsScalarTower S S' S''] lemma Cotangent.map_comp (f : Hom P P') (g : Hom P' P'') : Cotangent.map (g.comp f) = (map g).restrictScalars S ∘ₗ map f := by ext x obtain ⟨x, rfl⟩ := Cotangent.mk_surjective x simp only [map_mk, Hom.toAlgHom_apply, Hom.comp_toRingHom, RingHom.coe_comp, Function.comp_apply, val_mk, LinearMap.coe_comp, LinearMap.coe_restrictScalars] lemma Cotangent.finite (hP : P.ker.FG) : Module.Finite S P.Cotangent := by refine ⟨.of_restrictScalars (R := P.Ring) _ ?_⟩ rw [Submodule.restrictScalars_top, ← LinearMap.range_eq_top.mpr Extension.Cotangent.mk_surjective, ← Submodule.map_top] exact (P.ker.fg_top.mpr hP).map _ end Cotangent end Algebra.Extension
Adjunctions.lean
/- Copyright (c) 2021 Julian Kuelshammer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Julian Kuelshammer -/ import Mathlib.Algebra.Category.MonCat.Basic import Mathlib.Algebra.Category.Semigrp.Basic import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Algebra.Group.WithOne.Basic import Mathlib.Data.Finsupp.Basic import Mathlib.Data.Finsupp.SMulWithZero import Mathlib.CategoryTheory.Adjunction.Basic /-! # Adjunctions regarding the category of monoids This file proves the adjunction between adjoining a unit to a semigroup and the forgetful functor from monoids to semigroups. ## TODO * free-forgetful adjunction for monoids * adjunctions related to commutative monoids -/ universe u open CategoryTheory namespace MonCat /-- The functor of adjoining a neutral element `one` to a semigroup. -/ @[to_additive (attr := simps) /-- The functor of adjoining a neutral element `zero` to a semigroup -/] def adjoinOne : Semigrp.{u} ⥤ MonCat.{u} where obj S := MonCat.of (WithOne S) map f := ofHom (WithOne.map f.hom) map_id _ := MonCat.hom_ext WithOne.map_id map_comp _ _ := MonCat.hom_ext (WithOne.map_comp _ _) @[to_additive] instance hasForgetToSemigroup : HasForget₂ MonCat Semigrp where forget₂ := { obj := fun M => Semigrp.of M map f := Semigrp.ofHom f.hom.toMulHom } /-- The `adjoinOne`-forgetful adjunction from `Semigrp` to `MonCat`. -/ @[to_additive /-- The `adjoinZero`-forgetful adjunction from `AddSemigrp` to `AddMonCat` -/] def adjoinOneAdj : adjoinOne ⊣ forget₂ MonCat.{u} Semigrp.{u} := Adjunction.mkOfHomEquiv { homEquiv X Y := ConcreteCategory.homEquiv.trans (WithOne.lift.symm.trans (ConcreteCategory.homEquiv (X := X) (Y := (forget₂ _ _).obj Y)).symm) homEquiv_naturality_left_symm := by intros ext ⟨_ | _⟩ <;> simp <;> rfl } /-- The free functor `Type u ⥤ MonCat` sending a type `X` to the free monoid on `X`. -/ @[to_additive /-- The free functor `Type u ⥤ AddMonCat` sending a type `X` to the free additive monoid on `X`. -/] def free : Type u ⥤ MonCat.{u} where obj α := MonCat.of (FreeMonoid α) map f := ofHom (FreeMonoid.map f) map_id _ := MonCat.hom_ext (FreeMonoid.hom_eq fun _ => rfl) map_comp _ _ := MonCat.hom_ext (FreeMonoid.hom_eq fun _ => rfl) /-- The free-forgetful adjunction for monoids. -/ @[to_additive /-- The free-forgetful adjunction for additive monoids. -/] def adj : free ⊣ forget MonCat.{u} := Adjunction.mkOfHomEquiv -- The hint `(C := MonCat)` below speeds up the declaration by 10 times. { homEquiv X Y := (ConcreteCategory.homEquiv (C := MonCat)).trans FreeMonoid.lift.symm homEquiv_naturality_left_symm _ _ := MonCat.hom_ext (FreeMonoid.hom_eq fun _ => rfl) } instance : (forget MonCat.{u}).IsRightAdjoint := ⟨_, ⟨adj⟩⟩ end MonCat namespace AddCommMonCat /-- The free functor `Type u ⥤ AddCommMonCat` sending a type `X` to the free commutative monoid on `X`. -/ @[simps] noncomputable def free : Type u ⥤ AddCommMonCat.{u} where obj α := .of (α →₀ ℕ) map f := ofHom (Finsupp.mapDomain.addMonoidHom f) /-- The free-forgetful adjunction for commutative monoids. -/ noncomputable def adj : free ⊣ forget AddCommMonCat.{u} where unit := { app X i := Finsupp.single i 1 } counit := { app M := ofHom (Finsupp.liftAddHom (multiplesHom M)) naturality {M N} f := by dsimp; ext1; apply Finsupp.liftAddHom.symm.injective; ext; simp } instance : free.IsLeftAdjoint := ⟨_, ⟨adj⟩⟩ instance : (forget AddCommMonCat.{u}).IsRightAdjoint := ⟨_, ⟨adj⟩⟩ end AddCommMonCat namespace CommMonCat instance : (forget CommMonCat.{u}).IsRightAdjoint := ⟨_, ⟨AddCommMonCat.adj.comp AddCommMonCat.equivalence.toAdjunction⟩⟩ end CommMonCat
AffineMap.lean
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Linear import Mathlib.LinearAlgebra.AffineSpace.AffineMap /-! # Derivatives of affine maps In this file we prove formulas for one-dimensional derivatives of affine maps `f : 𝕜 →ᵃ[𝕜] E`. We also specialise some of these results to `AffineMap.lineMap` because it is useful to transfer MVT from dimension 1 to a domain in higher dimension. ## TODO Add theorems about `deriv`s and `fderiv`s of `ContinuousAffineMap`s once they will be ported to Mathlib 4. ## Keywords affine map, derivative, differentiability -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] (f : 𝕜 →ᵃ[𝕜] E) {a b : E} {L : Filter 𝕜} {s : Set 𝕜} {x : 𝕜} namespace AffineMap theorem hasStrictDerivAt : HasStrictDerivAt f (f.linear 1) x := by rw [f.decomp] exact f.linear.hasStrictDerivAt.add_const (f 0) theorem hasDerivAtFilter : HasDerivAtFilter f (f.linear 1) x L := by rw [f.decomp] exact f.linear.hasDerivAtFilter.add_const (f 0) theorem hasDerivWithinAt : HasDerivWithinAt f (f.linear 1) s x := f.hasDerivAtFilter theorem hasDerivAt : HasDerivAt f (f.linear 1) x := f.hasDerivAtFilter protected theorem derivWithin (hs : UniqueDiffWithinAt 𝕜 s x) : derivWithin f s x = f.linear 1 := f.hasDerivWithinAt.derivWithin hs @[simp] protected theorem deriv : deriv f x = f.linear 1 := f.hasDerivAt.deriv protected theorem differentiableAt : DifferentiableAt 𝕜 f x := f.hasDerivAt.differentiableAt protected theorem differentiable : Differentiable 𝕜 f := fun _ ↦ f.differentiableAt protected theorem differentiableWithinAt : DifferentiableWithinAt 𝕜 f s x := f.differentiableAt.differentiableWithinAt protected theorem differentiableOn : DifferentiableOn 𝕜 f s := fun _ _ ↦ f.differentiableWithinAt /-! ### Line map In this section we specialize some lemmas to `AffineMap.lineMap` because this map is very useful to deduce higher dimensional lemmas from one-dimensional versions. -/ theorem hasStrictDerivAt_lineMap : HasStrictDerivAt (lineMap a b) (b - a) x := by simpa using (lineMap a b : 𝕜 →ᵃ[𝕜] E).hasStrictDerivAt theorem hasDerivAt_lineMap : HasDerivAt (lineMap a b) (b - a) x := hasStrictDerivAt_lineMap.hasDerivAt theorem hasDerivWithinAt_lineMap : HasDerivWithinAt (lineMap a b) (b - a) s x := hasDerivAt_lineMap.hasDerivWithinAt end AffineMap
Defs.lean
/- Copyright (c) 2019 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Keeley Hoek, Floris van Doorn, Chris Bailey -/ import Mathlib.Init /-! # Definitions for `String` This file defines a bunch of functions for the `String` datatype. -/ namespace String /-- Pad `s : String` with repeated occurrences of `c : Char` until it's of length `n`. If `s` is initially larger than `n`, just return `s`. -/ def leftpad (n : Nat) (c : Char := ' ') (s : String) : String := ⟨List.leftpad n c s.data⟩ /-- Construct the string consisting of `n` copies of the character `c`. -/ def replicate (n : Nat) (c : Char) : String := ⟨List.replicate n c⟩ -- TODO bring this definition in line with the above, either by: -- adding `List.rightpad` to Batteries and changing the definition of `rightpad` here to match -- or by changing the definition of `leftpad` above to match this /-- Pad `s : String` with repeated occurrences of `c : Char` on the right until it's of length `n`. If `s` is initially larger than `n`, just return `s`. -/ def rightpad (n : Nat) (c : Char := ' ') (s : String) : String := s ++ String.replicate (n - s.length) c /-- `s.IsPrefix t` checks if the string `s` is a prefix of the string `t`. -/ def IsPrefix : String → String → Prop | ⟨d1⟩, ⟨d2⟩ => List.IsPrefix d1 d2 /-- `s.IsSuffix t` checks if the string `s` is a suffix of the string `t`. -/ def IsSuffix : String → String → Prop | ⟨d1⟩, ⟨d2⟩ => List.IsSuffix d1 d2 /-- `String.mapTokens c f s` tokenizes `s : string` on `c : char`, maps `f` over each token, and then reassembles the string by intercalating the separator token `c` over the mapped tokens. -/ def mapTokens (c : Char) (f : String → String) : String → String := intercalate (singleton c) ∘ List.map f ∘ (·.split (· = c)) /-- Produce the head character from the string `s`, if `s` is not empty, otherwise `'A'`. -/ def head (s : String) : Char := s.iter.curr end String
TransfiniteCompositionOfShape.lean
/- Copyright (c) 2024 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.ComposableArrows import Mathlib.CategoryTheory.Limits.Shapes.Preorder.WellOrderContinuous import Mathlib.CategoryTheory.Limits.Shapes.Preorder.Fin import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.Filtered.Final import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Preorder import Mathlib.Data.Fin.SuccPred import Mathlib.Order.LatticeIntervals import Mathlib.Order.Interval.Set.Final /-! # A structure to describe transfinite compositions Given a well-ordered type `J` and a morphism `f : X ⟶ Y` in a category, we introduce a structure `TransfiniteCompositionOfShape J f` expressing that `f` is a transfinite composition of shape `J`. This allows to extend this structure in order to require more properties or data for the morphisms `F.obj j ⟶ F.obj (Order.succ j)` which appear in the transfinite composition. See `MorphismProperty.TransfiniteCompositionOfShape` in the file `MorphismProperty.TransfiniteComposition`. -/ universe w w' v v' u u' namespace CategoryTheory open Limits variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] (J : Type w) [LinearOrder J] [OrderBot J] {X Y : C} (f : X ⟶ Y) /-- Given a well-ordered type `J`, a morphism `f : X ⟶ Y` in a category `C` is a transfinite composition of shape `J` if we have a well order continuous functor `F : J ⥤ C`, an isomorphism `F.obj ⊥ ≅ X`, a colimit cocone for `F` whose point is `Y`, such that the composition `X ⟶ F.obj ⊥ ⟶ Y` is `f`. -/ structure TransfiniteCompositionOfShape [SuccOrder J] [WellFoundedLT J] where /-- a well order continuous functor `F : J ⥤ C` -/ F : J ⥤ C /-- the isomorphism `F.obj ⊥ ≅ X` -/ isoBot : F.obj ⊥ ≅ X isWellOrderContinuous : F.IsWellOrderContinuous := by infer_instance /-- the natural morphism `F.obj j ⟶ Y` -/ incl : F ⟶ (Functor.const _).obj Y /-- the colimit of `F` identifies to `Y` -/ isColimit : IsColimit (Cocone.mk Y incl) fac : isoBot.inv ≫ incl.app ⊥ = f := by cat_disch namespace TransfiniteCompositionOfShape attribute [reassoc (attr := simp)] fac attribute [instance] isWellOrderContinuous variable {J f} [SuccOrder J] [WellFoundedLT J] (c : TransfiniteCompositionOfShape J f) /-- If `f` and `f'` are two isomorphic morphisms, and `f` is a transfinite composition of shape `J`, then `f'` also is. -/ @[simps] def ofArrowIso {X' Y' : C} {f' : X' ⟶ Y'} (e : Arrow.mk f ≅ Arrow.mk f') : TransfiniteCompositionOfShape J f' where F := c.F isoBot := c.isoBot ≪≫ Arrow.leftFunc.mapIso e incl := c.incl ≫ (Functor.const J).map e.hom.right isColimit := IsColimit.ofIsoColimit c.isColimit (Cocones.ext (Arrow.rightFunc.mapIso e)) /-- If `G : ComposableArrows C n`, then `G.hom : G.left ⟶ G.right` is a transfinite composition of shape `Fin (n + 1)`. -/ @[simps] def ofComposableArrows {n : ℕ} (G : ComposableArrows C n) : TransfiniteCompositionOfShape (Fin (n + 1)) G.hom where F := G isoBot := Iso.refl _ incl := _ isColimit := colimitOfDiagramTerminal (Fin.isTerminalLast n) G fac := Category.id_comp _ /-- If `f` is a transfinite composition of shape `J`, then it is also a transfinite composition of shape `J'` if `J' ≃o J`. -/ @[simps] def ofOrderIso {J' : Type w'} [LinearOrder J'] [OrderBot J'] [SuccOrder J'] [WellFoundedLT J'] (e : J' ≃o J) : TransfiniteCompositionOfShape J' f where F := e.equivalence.functor ⋙ c.F isoBot := c.F.mapIso (eqToIso e.map_bot) ≪≫ c.isoBot incl := Functor.whiskerLeft e.equivalence.functor c.incl isColimit := IsColimit.whiskerEquivalence (c.isColimit) e.equivalence /-- If `f` is a transfinite composition of shape `J`, then `F.map f` also is provided `F` preserves suitable colimits. -/ @[simps] noncomputable def map (F : C ⥤ D) [PreservesWellOrderContinuousOfShape J F] [PreservesColimitsOfShape J F] : TransfiniteCompositionOfShape J (F.map f) where F := c.F ⋙ F isoBot := F.mapIso c.isoBot incl := Functor.whiskerRight c.incl F ≫ (Functor.constComp _ _ _).hom isColimit := IsColimit.ofIsoColimit (isColimitOfPreserves F c.isColimit) (Cocones.ext (Iso.refl _)) fac := by simp [← Functor.map_comp] /-- A transfinite composition of shape `J` induces a transfinite composition of shape `Set.Iic j` for any `j : J`. -/ @[simps] noncomputable def iic (j : J) : TransfiniteCompositionOfShape (Set.Iic j) (c.F.map (homOfLE bot_le : ⊥ ⟶ j)) where F := (Set.initialSegIic j).monotone.functor ⋙ c.F isoBot := Iso.refl _ incl := { app i := c.F.map (homOfLE i.2) naturality i i' φ := by dsimp rw [← Functor.map_comp, Category.comp_id] rfl } isColimit := colimitOfDiagramTerminal isTerminalTop _ /-- A transfinite composition of shape `J` induces a transfinite composition of shape `Set.Ici j` for any `j : J`. -/ @[simps] noncomputable def ici (j : J) : TransfiniteCompositionOfShape (Set.Ici j) (c.incl.app j) where F := (Subtype.mono_coe (Set.Ici j)).functor ⋙ c.F isWellOrderContinuous := Functor.IsWellOrderContinuous.restriction_setIci _ isoBot := Iso.refl _ incl := Functor.whiskerLeft _ c.incl isColimit := (Functor.Final.isColimitWhiskerEquiv ((Subtype.mono_coe (Set.Ici j)).functor) _).2 c.isColimit end TransfiniteCompositionOfShape end CategoryTheory