filename
stringlengths
5
42
content
stringlengths
15
319k
Basic.lean
/- Copyright (c) 2021 Ashvni Narayanan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ashvni Narayanan, Anne Baanen -/ import Mathlib.Algebra.Algebra.Rat import Mathlib.Algebra.Ring.Int.Parity import Mathlib.Algebra.Ring.Int.Units import Mathlib.RingTheory.DedekindDomain.IntegralClosure /-! # Number fields This file defines a number field and the ring of integers corresponding to it. ## Main definitions - `NumberField` defines a number field as a field which has characteristic zero and is finite dimensional over ℚ. - `RingOfIntegers` defines the ring of integers (or number ring) corresponding to a number field as the integral closure of ℤ in the number field. ## Implementation notes The definitions that involve a field of fractions choose a canonical field of fractions, but are independent of that choice. ## References * [D. Marcus, *Number Fields*][marcus1977number] * [J.W.S. Cassels, A. Fröhlich, *Algebraic Number Theory*][cassels1967algebraic] * [P. Samuel, *Algebraic Theory of Numbers*][samuel1967] ## Tags number field, ring of integers -/ /-- A number field is a field which has characteristic zero and is finite dimensional over ℚ. -/ @[stacks 09GA] class NumberField (K : Type*) [Field K] : Prop where [to_charZero : CharZero K] [to_finiteDimensional : FiniteDimensional ℚ K] open Function Module open scoped nonZeroDivisors /-- `ℤ` with its usual ring structure is not a field. -/ theorem Int.not_isField : ¬IsField ℤ := fun h => Int.not_even_one <| (h.mul_inv_cancel two_ne_zero).imp fun a => by rw [← two_mul]; exact Eq.symm namespace NumberField variable (K L : Type*) [Field K] [Field L] -- See note [lower instance priority] attribute [instance] NumberField.to_charZero NumberField.to_finiteDimensional protected theorem isAlgebraic [NumberField K] : Algebra.IsAlgebraic ℚ K := Algebra.IsAlgebraic.of_finite _ _ instance [NumberField K] [NumberField L] [Algebra K L] : FiniteDimensional K L := Module.Finite.of_restrictScalars_finite ℚ K L /-- A finite extension of a number field is a number field. -/ theorem of_module_finite [NumberField K] [Algebra K L] [Module.Finite K L] : NumberField L where to_charZero := charZero_of_injective_algebraMap (algebraMap K L).injective to_finiteDimensional := letI := charZero_of_injective_algebraMap (algebraMap K L).injective Module.Finite.trans K L variable {K} {L} in instance of_intermediateField [NumberField K] [NumberField L] [Algebra K L] (E : IntermediateField K L) : NumberField E := of_module_finite K E variable {K} in instance of_subfield [NumberField K] (E : Subfield K) : NumberField E where to_finiteDimensional := FiniteDimensional.left ℚ E K theorem of_tower [NumberField K] [NumberField L] [Algebra K L] (E : Type*) [Field E] [Algebra K E] [Algebra E L] [IsScalarTower K E L] : NumberField E := letI := Module.Finite.left K E L of_module_finite K E /-- The ring of integers (or number ring) corresponding to a number field is the integral closure of ℤ in the number field. This is defined as its own type, rather than a `Subalgebra`, for performance reasons: looking for instances of the form `SMul (RingOfIntegers _) (RingOfIntegers _)` makes much more effective use of the discrimination tree than instances of the form `SMul (Subtype _) (Subtype _)`. The drawback is we have to copy over instances manually. -/ def RingOfIntegers : Type _ := integralClosure ℤ K @[inherit_doc] scoped notation "𝓞" => NumberField.RingOfIntegers namespace RingOfIntegers instance : CommRing (𝓞 K) := inferInstanceAs (CommRing (integralClosure _ _)) instance : IsDomain (𝓞 K) := inferInstanceAs (IsDomain (integralClosure _ _)) instance [NumberField K] : CharZero (𝓞 K) := inferInstanceAs (CharZero (integralClosure _ _)) instance : Algebra (𝓞 K) K := inferInstanceAs (Algebra (integralClosure _ _) _) instance : NoZeroSMulDivisors (𝓞 K) K := inferInstanceAs (NoZeroSMulDivisors (integralClosure _ _) _) instance : Nontrivial (𝓞 K) := inferInstanceAs (Nontrivial (integralClosure _ _)) instance {L : Type*} [Ring L] [Algebra K L] : Algebra (𝓞 K) L := inferInstanceAs (Algebra (integralClosure _ _) L) instance {L : Type*} [Ring L] [Algebra K L] : IsScalarTower (𝓞 K) K L := inferInstanceAs (IsScalarTower (integralClosure _ _) K L) variable {K} /-- The canonical coercion from `𝓞 K` to `K`. -/ @[coe] abbrev val (x : 𝓞 K) : K := algebraMap _ _ x /-- This instance has to be `CoeHead` because we only want to apply it from `𝓞 K` to `K`. -/ instance : CoeHead (𝓞 K) K := ⟨val⟩ lemma coe_eq_algebraMap (x : 𝓞 K) : (x : K) = algebraMap _ _ x := rfl @[ext] theorem ext {x y : 𝓞 K} (h : (x : K) = (y : K)) : x = y := Subtype.ext h @[norm_cast] theorem eq_iff {x y : 𝓞 K} : (x : K) = (y : K) ↔ x = y := NumberField.RingOfIntegers.ext_iff.symm @[simp] lemma map_mk (x : K) (hx) : algebraMap (𝓞 K) K ⟨x, hx⟩ = x := rfl lemma coe_mk {x : K} (hx) : ((⟨x, hx⟩ : 𝓞 K) : K) = x := rfl lemma mk_eq_mk (x y : K) (hx hy) : (⟨x, hx⟩ : 𝓞 K) = ⟨y, hy⟩ ↔ x = y := by simp @[simp] lemma mk_one : (⟨1, one_mem _⟩ : 𝓞 K) = 1 := rfl @[simp] lemma mk_zero : (⟨0, zero_mem _⟩ : 𝓞 K) = 0 := rfl -- TODO: these lemmas don't seem to fire? @[simp] lemma mk_add_mk (x y : K) (hx hy) : (⟨x, hx⟩ : 𝓞 K) + ⟨y, hy⟩ = ⟨x + y, add_mem hx hy⟩ := rfl @[simp] lemma mk_mul_mk (x y : K) (hx hy) : (⟨x, hx⟩ : 𝓞 K) * ⟨y, hy⟩ = ⟨x * y, mul_mem hx hy⟩ := rfl @[simp] lemma mk_sub_mk (x y : K) (hx hy) : (⟨x, hx⟩ : 𝓞 K) - ⟨y, hy⟩ = ⟨x - y, sub_mem hx hy⟩ := rfl @[simp] lemma neg_mk (x : K) (hx) : (-⟨x, hx⟩ : 𝓞 K) = ⟨-x, neg_mem hx⟩ := rfl /-- The ring homomorphism `(𝓞 K) →+* (𝓞 L)` given by restricting a ring homomorphism `f : K →+* L` to `𝓞 K`. -/ def mapRingHom {K L F : Type*} [Field K] [Field L] [FunLike F K L] [RingHomClass F K L] (f : F) : (𝓞 K) →+* (𝓞 L) where toFun k := ⟨f k.val, map_isIntegral_int f k.2⟩ map_zero' := by ext; simp only [map_mk, map_zero] map_one' := by ext; simp only [map_mk, map_one] map_add' x y:= by ext; simp only [map_mk, map_add] map_mul' x y := by ext; simp only [map_mk, map_mul] /-- The ring isomorphsim `(𝓞 K) ≃+* (𝓞 L)` given by restricting a ring isomorphsim `e : K ≃+* L` to `𝓞 K`. -/ def mapRingEquiv {K L E : Type*} [Field K] [Field L] [EquivLike E K L] [RingEquivClass E K L] (e : E) : (𝓞 K) ≃+* (𝓞 L) := RingEquiv.ofRingHom (mapRingHom e) (mapRingHom (e : K ≃+* L).symm) (RingHom.ext fun x => ext (EquivLike.right_inv e x.1)) (RingHom.ext fun x => ext (EquivLike.left_inv e x.1)) end RingOfIntegers /-- Given an algebra structure between two fields, this instance creates an algebra structure between their two rings of integers. -/ instance inst_ringOfIntegersAlgebra [Algebra K L] : Algebra (𝓞 K) (𝓞 L) := (RingOfIntegers.mapRingHom (algebraMap K L)).toAlgebra -- diamond at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906 example : Algebra.id (𝓞 K) = inst_ringOfIntegersAlgebra K K := rfl namespace RingOfIntegers /-- The algebra homomorphism `(𝓞 K) →ₐ[𝓞 k] (𝓞 L)` given by restricting an algebra homomorphism `f : K →ₐ[k] L` to `𝓞 K`. -/ def mapAlgHom {k K L F : Type*} [Field k] [Field K] [Field L] [Algebra k K] [Algebra k L] [FunLike F K L] [AlgHomClass F k K L] (f : F) : (𝓞 K) →ₐ[𝓞 k] (𝓞 L) where toRingHom := mapRingHom f commutes' x := SetCoe.ext (AlgHomClass.commutes ((f : K →ₐ[k] L).restrictScalars (𝓞 k)) x) /-- The isomorphism of algebras `(𝓞 K) ≃ₐ[𝓞 k] (𝓞 L)` given by restricting an isomorphism of algebras `e : K ≃ₐ[k] L` to `𝓞 K`. -/ def mapAlgEquiv {k K L E : Type*} [Field k] [Field K] [Field L] [Algebra k K] [Algebra k L] [EquivLike E K L] [AlgEquivClass E k K L] (e : E) : (𝓞 K) ≃ₐ[𝓞 k] (𝓞 L) := AlgEquiv.ofAlgHom (mapAlgHom e) (mapAlgHom (e : K ≃ₐ[k] L).symm) (AlgHom.ext fun x => ext (EquivLike.right_inv e x.1)) (AlgHom.ext fun x => ext (EquivLike.left_inv e x.1)) instance inst_isScalarTower (k K L : Type*) [Field k] [Field K] [Field L] [Algebra k K] [Algebra k L] [Algebra K L] [IsScalarTower k K L] : IsScalarTower (𝓞 k) (𝓞 K) (𝓞 L) := IsScalarTower.of_algHom (mapAlgHom (IsScalarTower.toAlgHom k K L)) variable {K} /-- The canonical map from `𝓞 K` to `K` is injective. This is a convenient abbreviation for `FaithfulSMul.algebraMap_injective`. -/ lemma coe_injective : Function.Injective (algebraMap (𝓞 K) K) := FaithfulSMul.algebraMap_injective _ _ /-- The canonical map from `𝓞 K` to `K` is injective. This is a convenient abbreviation for `map_eq_zero_iff` applied to `FaithfulSMul.algebraMap_injective`. -/ lemma coe_eq_zero_iff {x : 𝓞 K} : algebraMap _ K x = 0 ↔ x = 0 := map_eq_zero_iff _ coe_injective /-- The canonical map from `𝓞 K` to `K` is injective. This is a convenient abbreviation for `map_ne_zero_iff` applied to `FaithfulSMul.algebraMap_injective`. -/ lemma coe_ne_zero_iff {x : 𝓞 K} : algebraMap _ K x ≠ 0 ↔ x ≠ 0 := map_ne_zero_iff _ coe_injective theorem isIntegral_coe (x : 𝓞 K) : IsIntegral ℤ (algebraMap _ K x) := x.2 theorem isIntegral (x : 𝓞 K) : IsIntegral ℤ x := by obtain ⟨P, hPm, hP⟩ := x.isIntegral_coe refine ⟨P, hPm, ?_⟩ rwa [IsScalarTower.algebraMap_eq (S := 𝓞 K), ← Polynomial.hom_eval₂, coe_eq_zero_iff] at hP instance [NumberField K] : IsFractionRing (𝓞 K) K := integralClosure.isFractionRing_of_finite_extension ℚ _ instance : IsIntegralClosure (𝓞 K) ℤ K := integralClosure.isIntegralClosure _ _ instance : Algebra.IsIntegral ℤ (𝓞 K) := IsIntegralClosure.isIntegral_algebra ℤ K instance [NumberField K] : IsIntegrallyClosed (𝓞 K) := integralClosure.isIntegrallyClosedOfFiniteExtension ℚ /-- The ring of integers of `K` are equivalent to any integral closure of `ℤ` in `K` -/ protected noncomputable def equiv (R : Type*) [CommRing R] [Algebra R K] [IsIntegralClosure R ℤ K] : 𝓞 K ≃+* R := (IsIntegralClosure.equiv ℤ R K _).symm.toRingEquiv variable (K) instance [CharZero K] : CharZero (𝓞 K) := CharZero.of_module _ K variable [NumberField K] instance : IsNoetherian ℤ (𝓞 K) := IsIntegralClosure.isNoetherian _ ℚ K _ /-- The ring of integers of a number field is not a field. -/ theorem not_isField : ¬IsField (𝓞 K) := by have h_inj : Function.Injective (algebraMap ℤ (𝓞 K)) := RingHom.injective_int (algebraMap ℤ (𝓞 K)) intro hf exact Int.not_isField (((IsIntegralClosure.isIntegral_algebra ℤ K).isField_iff_isField h_inj).mpr hf) instance : IsDedekindDomain (𝓞 K) := IsIntegralClosure.isDedekindDomain ℤ ℚ K _ instance : Free ℤ (𝓞 K) := IsIntegralClosure.module_free ℤ ℚ K (𝓞 K) instance : IsLocalization (Algebra.algebraMapSubmonoid (𝓞 K) ℤ⁰) K := IsIntegralClosure.isLocalization_of_isSeparable ℤ ℚ K (𝓞 K) /-- A ℤ-basis of the ring of integers of `K`. -/ noncomputable def basis : Basis (Free.ChooseBasisIndex ℤ (𝓞 K)) ℤ (𝓞 K) := Free.chooseBasis ℤ (𝓞 K) variable {K} {M : Type*} /-- Given `f : M → K` such that `∀ x, IsIntegral ℤ (f x)`, the corresponding function `M → 𝓞 K`. -/ def restrict (f : M → K) (h : ∀ x, IsIntegral ℤ (f x)) (x : M) : 𝓞 K := ⟨f x, h x⟩ /-- Given `f : M →+ K` such that `∀ x, IsIntegral ℤ (f x)`, the corresponding function `M →+ 𝓞 K`. -/ def restrict_addMonoidHom [AddZeroClass M] (f : M →+ K) (h : ∀ x, IsIntegral ℤ (f x)) : M →+ 𝓞 K where toFun := restrict f h map_zero' := by simp only [restrict, map_zero, mk_zero] map_add' x y := by simp only [restrict, map_add, mk_add_mk _] /-- Given `f : M →* K` such that `∀ x, IsIntegral ℤ (f x)`, the corresponding function `M →* 𝓞 K`. -/ def restrict_monoidHom [MulOneClass M] (f : M →* K) (h : ∀ x, IsIntegral ℤ (f x)) : M →* 𝓞 K where toFun := restrict f h map_one' := by simp only [restrict, map_one, mk_one] map_mul' x y := by simp only [restrict, map_mul, mk_mul_mk _] section extension variable (K L : Type*) [Field K] [Field L] [Algebra K L] instance : IsScalarTower (𝓞 K) (𝓞 L) L := IsScalarTower.of_algebraMap_eq' rfl instance : IsIntegralClosure (𝓞 L) (𝓞 K) L := IsIntegralClosure.tower_top (R := ℤ) /-- The ring of integers of `L` is isomorphic to any integral closure of `𝓞 K` in `L` -/ protected noncomputable def algEquiv (R : Type*) [CommRing R] [Algebra (𝓞 K) R] [Algebra R L] [IsScalarTower (𝓞 K) R L] [IsIntegralClosure R (𝓞 K) L] : 𝓞 L ≃ₐ[𝓞 K] R := (IsIntegralClosure.equiv (𝓞 K) R L _).symm /-- Any extension between ring of integers is integral. -/ instance extension_algebra_isIntegral : Algebra.IsIntegral (𝓞 K) (𝓞 L) := IsIntegralClosure.isIntegral_algebra (𝓞 K) L /-- Any extension between ring of integers of number fields is noetherian. -/ instance extension_isNoetherian [NumberField K] [NumberField L] : IsNoetherian (𝓞 K) (𝓞 L) := IsIntegralClosure.isNoetherian (𝓞 K) K L (𝓞 L) /-- The kernel of the algebraMap between ring of integers is `⊥`. -/ theorem ker_algebraMap_eq_bot : RingHom.ker (algebraMap (𝓞 K) (𝓞 L)) = ⊥ := (RingHom.ker_eq_bot_iff_eq_zero (algebraMap (𝓞 K) (𝓞 L))).mpr <| fun x hx => by have h : (algebraMap K L) x = (algebraMap (𝓞 K) (𝓞 L)) x := rfl simp only [hx, map_zero, map_eq_zero, RingOfIntegers.coe_eq_zero_iff] at h exact h /-- The algebraMap between ring of integers is injective. -/ theorem algebraMap.injective : Function.Injective (algebraMap (𝓞 K) (𝓞 L)) := (RingHom.injective_iff_ker_eq_bot (algebraMap (𝓞 K) (𝓞 L))).mpr (ker_algebraMap_eq_bot K L) instance : NoZeroSMulDivisors (𝓞 K) (𝓞 L) := NoZeroSMulDivisors.iff_algebraMap_injective.mpr <| algebraMap.injective K L instance : NoZeroSMulDivisors (𝓞 K) L := NoZeroSMulDivisors.trans_faithfulSMul (𝓞 K) (𝓞 L) L end extension end RingOfIntegers variable [NumberField K] /-- A basis of `K` over `ℚ` that is also a basis of `𝓞 K` over `ℤ`. -/ noncomputable def integralBasis : Basis (Free.ChooseBasisIndex ℤ (𝓞 K)) ℚ K := Basis.localizationLocalization ℚ (nonZeroDivisors ℤ) K (RingOfIntegers.basis K) @[simp] theorem integralBasis_apply (i : Free.ChooseBasisIndex ℤ (𝓞 K)) : integralBasis K i = algebraMap (𝓞 K) K (RingOfIntegers.basis K i) := Basis.localizationLocalization_apply ℚ (nonZeroDivisors ℤ) K (RingOfIntegers.basis K) i @[simp] theorem integralBasis_repr_apply (x : (𝓞 K)) (i : Free.ChooseBasisIndex ℤ (𝓞 K)) : (integralBasis K).repr (algebraMap _ _ x) i = (algebraMap ℤ ℚ) ((RingOfIntegers.basis K).repr x i) := Basis.localizationLocalization_repr_algebraMap ℚ (nonZeroDivisors ℤ) K _ x i theorem mem_span_integralBasis {x : K} : x ∈ Submodule.span ℤ (Set.range (integralBasis K)) ↔ x ∈ (algebraMap (𝓞 K) K).range := by rw [integralBasis, Basis.localizationLocalization_span, LinearMap.mem_range, IsScalarTower.coe_toAlgHom', RingHom.mem_range] theorem RingOfIntegers.rank : Module.finrank ℤ (𝓞 K) = Module.finrank ℚ K := IsIntegralClosure.rank ℤ ℚ K (𝓞 K) end NumberField namespace Rat open NumberField instance numberField : NumberField ℚ where to_charZero := inferInstance to_finiteDimensional := by -- The vector space structure of `ℚ` over itself can arise in multiple ways: -- all fields are vector spaces over themselves (used in `Rat.finiteDimensional`) -- all char 0 fields have a canonical embedding of `ℚ` (used in `NumberField`). -- Show that these coincide: convert (inferInstance : FiniteDimensional ℚ ℚ) /-- The ring of integers of `ℚ` as a number field is just `ℤ`. -/ noncomputable def ringOfIntegersEquiv : 𝓞 ℚ ≃+* ℤ := RingOfIntegers.equiv ℤ @[simp] theorem coe_ringOfIntegersEquiv (z : 𝓞 ℚ) : (Rat.ringOfIntegersEquiv z : ℚ) = algebraMap (𝓞 ℚ) ℚ z := by obtain ⟨z, rfl⟩ := Rat.ringOfIntegersEquiv.symm.surjective z simp end Rat namespace AdjoinRoot section open scoped Polynomial attribute [-instance] DivisionRing.toRatAlgebra /-- The quotient of `ℚ[X]` by the ideal generated by an irreducible polynomial of `ℚ[X]` is a number field. -/ instance {f : Polynomial ℚ} [hf : Fact (Irreducible f)] : NumberField (AdjoinRoot f) where to_charZero := charZero_of_injective_algebraMap (algebraMap ℚ _).injective to_finiteDimensional := by convert (AdjoinRoot.powerBasis hf.out.ne_zero).finite end end AdjoinRoot
IsPerfectClosure.lean
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.PurelyInseparable.Basic import Mathlib.FieldTheory.PerfectClosure /-! # `IsPerfectClosure` predicate This file contains `IsPerfectClosure` which asserts that `L` is a perfect closure of `K` under a ring homomorphism `i : K →+* L`, as well as its basic properties. ## Main definitions - `pNilradical`: given a natural number `p`, the `p`-nilradical of a ring is defined to be the nilradical if `p > 1` (`pNilradical_eq_nilradical`), and defined to be the zero ideal if `p ≤ 1` (`pNilradical_eq_bot'`). Equivalently, it is the ideal consisting of elements `x` such that `x ^ p ^ n = 0` for some `n` (`mem_pNilradical`). - `IsPRadical`: a ring homomorphism `i : K →+* L` of characteristic `p` rings is called `p`-radical, if or any element `x` of `L` there is `n : ℕ` such that `x ^ (p ^ n)` is contained in `K`, and the kernel of `i` is contained in the `p`-nilradical of `K`. A generalization of purely inseparable extension for fields. - `IsPerfectClosure`: if `i : K →+* L` is `p`-radical ring homomorphism, then it makes `L` a perfect closure of `K`, if `L` is perfect. Our definition makes it synonymous to `IsPRadical` if `PerfectRing L p` is present. A caveat is that you need to write `[PerfectRing L p] [IsPerfectClosure i p]`. This is similar to `PerfectRing` which has `ExpChar` as a prerequisite. - `PerfectRing.lift`: if a `p`-radical ring homomorphism `K →+* L` is given, `M` is a perfect ring, then any ring homomorphism `K →+* M` can be lifted to `L →+* M`. This is similar to `IsAlgClosed.lift` and `IsSepClosed.lift`. - `PerfectRing.liftEquiv`: `K →+* M` is one-to-one correspondence to `L →+* M`, given by `PerfectRing.lift`. This is a generalization to `PerfectClosure.lift`. - `IsPerfectClosure.equiv`: perfect closures of a ring are isomorphic. ## Main results - `IsPRadical.trans`: composition of `p`-radical ring homomorphisms is also `p`-radical. - `PerfectClosure.isPRadical`: the absolute perfect closure `PerfectClosure` is a `p`-radical extension over the base ring, in particular, it is a perfect closure of the base ring. - `IsPRadical.isPurelyInseparable`, `IsPurelyInseparable.isPRadical`: `p`-radical and purely inseparable are equivalent for fields. - The (relative) perfect closure `perfectClosure` is a perfect closure (inferred from `IsPurelyInseparable.isPRadical` automatically by Lean). ## Tags perfect ring, perfect closure, purely inseparable -/ open Module Polynomial IntermediateField Field noncomputable section /-- Given a natural number `p`, the `p`-nilradical of a ring is defined to be the nilradical if `p > 1` (`pNilradical_eq_nilradical`), and defined to be the zero ideal if `p ≤ 1` (`pNilradical_eq_bot'`). Equivalently, it is the ideal consisting of elements `x` such that `x ^ p ^ n = 0` for some `n` (`mem_pNilradical`). -/ def pNilradical (R : Type*) [CommSemiring R] (p : ℕ) : Ideal R := if 1 < p then nilradical R else ⊥ theorem pNilradical_le_nilradical {R : Type*} [CommSemiring R] {p : ℕ} : pNilradical R p ≤ nilradical R := by by_cases hp : 1 < p · rw [pNilradical, if_pos hp] simp_rw [pNilradical, if_neg hp, bot_le] theorem pNilradical_eq_nilradical {R : Type*} [CommSemiring R] {p : ℕ} (hp : 1 < p) : pNilradical R p = nilradical R := by rw [pNilradical, if_pos hp] theorem pNilradical_eq_bot {R : Type*} [CommSemiring R] {p : ℕ} (hp : ¬ 1 < p) : pNilradical R p = ⊥ := by rw [pNilradical, if_neg hp] theorem pNilradical_eq_bot' {R : Type*} [CommSemiring R] {p : ℕ} (hp : p ≤ 1) : pNilradical R p = ⊥ := pNilradical_eq_bot (not_lt.2 hp) theorem pNilradical_prime {R : Type*} [CommSemiring R] {p : ℕ} (hp : p.Prime) : pNilradical R p = nilradical R := pNilradical_eq_nilradical hp.one_lt theorem pNilradical_one {R : Type*} [CommSemiring R] : pNilradical R 1 = ⊥ := pNilradical_eq_bot' rfl.le theorem mem_pNilradical {R : Type*} [CommSemiring R] {p : ℕ} {x : R} : x ∈ pNilradical R p ↔ ∃ n : ℕ, x ^ p ^ n = 0 := by by_cases hp : 1 < p · rw [pNilradical_eq_nilradical hp] refine ⟨fun ⟨n, h⟩ ↦ ⟨n, ?_⟩, fun ⟨n, h⟩ ↦ ⟨p ^ n, h⟩⟩ rw [← Nat.sub_add_cancel ((n.lt_pow_self hp).le), pow_add, h, mul_zero] rw [pNilradical_eq_bot hp, Ideal.mem_bot] refine ⟨fun h ↦ ⟨0, by rw [pow_zero, pow_one, h]⟩, fun ⟨n, h⟩ ↦ ?_⟩ rcases Nat.le_one_iff_eq_zero_or_eq_one.1 (not_lt.1 hp) with hp | hp · by_cases hn : n = 0 · rwa [hn, pow_zero, pow_one] at h rw [hp, zero_pow hn, pow_zero] at h subsingleton [subsingleton_of_zero_eq_one h.symm] rwa [hp, one_pow, pow_one] at h theorem sub_mem_pNilradical_iff_pow_expChar_pow_eq {R : Type*} [CommRing R] {p : ℕ} [ExpChar R p] {x y : R} : x - y ∈ pNilradical R p ↔ ∃ n : ℕ, x ^ p ^ n = y ^ p ^ n := by simp_rw [mem_pNilradical, sub_pow_expChar_pow, sub_eq_zero] theorem pow_expChar_pow_inj_of_pNilradical_eq_bot (R : Type*) [CommRing R] (p : ℕ) [ExpChar R p] (h : pNilradical R p = ⊥) (n : ℕ) : Function.Injective fun x : R ↦ x ^ p ^ n := fun _ _ H ↦ sub_eq_zero.1 <| Ideal.mem_bot.1 <| h ▸ sub_mem_pNilradical_iff_pow_expChar_pow_eq.2 ⟨n, H⟩ theorem pNilradical_eq_bot_of_frobenius_inj (R : Type*) [CommSemiring R] (p : ℕ) [ExpChar R p] (h : Function.Injective (frobenius R p)) : pNilradical R p = ⊥ := bot_unique fun x ↦ by rw [mem_pNilradical, Ideal.mem_bot] exact fun ⟨n, _⟩ ↦ h.iterate n (by rwa [← coe_iterateFrobenius, map_zero]) theorem PerfectRing.pNilradical_eq_bot (R : Type*) [CommSemiring R] (p : ℕ) [ExpChar R p] [PerfectRing R p] : pNilradical R p = ⊥ := pNilradical_eq_bot_of_frobenius_inj R p (injective_frobenius R p) section IsPerfectClosure variable {K L M N : Type*} section CommSemiring variable [CommSemiring K] [CommSemiring L] [CommSemiring M] (i : K →+* L) (j : K →+* M) (f : L →+* M) (p : ℕ) /-- If `i : K →+* L` is a ring homomorphism of characteristic `p` rings, then it is called `p`-radical if the following conditions are satisfied: - For any element `x` of `L` there is `n : ℕ` such that `x ^ (p ^ n)` is contained in `K`. - The kernel of `i` is contained in the `p`-nilradical of `K`. It is a generalization of purely inseparable extension for fields. -/ @[mk_iff] class IsPRadical : Prop where pow_mem' : ∀ x : L, ∃ (n : ℕ) (y : K), i y = x ^ p ^ n ker_le' : RingHom.ker i ≤ pNilradical K p theorem IsPRadical.pow_mem [IsPRadical i p] (x : L) : ∃ (n : ℕ) (y : K), i y = x ^ p ^ n := pow_mem' x theorem IsPRadical.ker_le [IsPRadical i p] : RingHom.ker i ≤ pNilradical K p := ker_le' theorem IsPRadical.comap_pNilradical [IsPRadical i p] : (pNilradical L p).comap i = pNilradical K p := by refine le_antisymm (fun x h ↦ mem_pNilradical.2 ?_) (fun x h ↦ ?_) · obtain ⟨n, h⟩ := mem_pNilradical.1 <| Ideal.mem_comap.1 h obtain ⟨m, h⟩ := mem_pNilradical.1 <| ker_le i p ((map_pow i x _).symm ▸ h) exact ⟨n + m, by rwa [pow_add, pow_mul]⟩ simp only [Ideal.mem_comap, mem_pNilradical] at h ⊢ obtain ⟨n, h⟩ := h exact ⟨n, by simpa only [map_pow, map_zero] using congr(i $h)⟩ variable (K) in instance IsPRadical.of_id : IsPRadical (RingHom.id K) p where pow_mem' x := ⟨0, x, by simp⟩ ker_le' x h := by convert Ideal.zero_mem _ /-- Composition of `p`-radical ring homomorphisms is also `p`-radical. -/ theorem IsPRadical.trans [IsPRadical i p] [IsPRadical f p] : IsPRadical (f.comp i) p where pow_mem' x := by obtain ⟨n, y, hy⟩ := pow_mem f p x obtain ⟨m, z, hz⟩ := pow_mem i p y exact ⟨n + m, z, by rw [RingHom.comp_apply, hz, map_pow, hy, pow_add, pow_mul]⟩ ker_le' x h := by rw [RingHom.mem_ker, RingHom.comp_apply, ← RingHom.mem_ker] at h simpa only [← Ideal.mem_comap, comap_pNilradical] using ker_le f p h /-- If `i : K →+* L` is a `p`-radical ring homomorphism, then it makes `L` a perfect closure of `K`, if `L` is perfect. In this case the kernel of `i` is equal to the `p`-nilradical of `K` (see `IsPerfectClosure.ker_eq`). Our definition makes it synonymous to `IsPRadical` if `PerfectRing L p` is present. A caveat is that you need to write `[PerfectRing L p] [IsPerfectClosure i p]`. This is similar to `PerfectRing` which has `ExpChar` as a prerequisite. -/ @[nolint unusedArguments] abbrev IsPerfectClosure [ExpChar L p] [PerfectRing L p] := IsPRadical i p /-- If `i : K →+* L` is a ring homomorphism of exponential characteristic `p` rings, such that `L` is perfect, then the `p`-nilradical of `K` is contained in the kernel of `i`. -/ theorem RingHom.pNilradical_le_ker_of_perfectRing [ExpChar L p] [PerfectRing L p] : pNilradical K p ≤ RingHom.ker i := fun x h ↦ by obtain ⟨n, h⟩ := mem_pNilradical.1 h replace h := congr((iterateFrobeniusEquiv L p n).symm (i $h)) rwa [map_pow, ← iterateFrobenius_def, ← iterateFrobeniusEquiv_apply, RingEquiv.symm_apply_apply, map_zero, map_zero] at h variable [ExpChar L p] in theorem IsPerfectClosure.ker_eq [PerfectRing L p] [IsPerfectClosure i p] : RingHom.ker i = pNilradical K p := IsPRadical.ker_le'.antisymm (i.pNilradical_le_ker_of_perfectRing p) namespace PerfectRing /- NOTE: To define `PerfectRing.lift_aux`, only the `IsPRadical.pow_mem` is required, but not `IsPRadical.ker_le`. But in order to use typeclass, here we require the whole `IsPRadical`. -/ variable [ExpChar M p] [PerfectRing M p] [IsPRadical i p] theorem lift_aux (x : L) : ∃ y : ℕ × K, i y.2 = x ^ p ^ y.1 := by obtain ⟨n, y, h⟩ := IsPRadical.pow_mem i p x exact ⟨(n, y), h⟩ /-- If `i : K →+* L` and `j : K →+* M` are ring homomorphisms of characteristic `p` rings, such that `i` is `p`-radical (in fact only the `IsPRadical.pow_mem` is required) and `M` is a perfect ring, then one can define a map `L → M` which maps an element `x` of `L` to `y ^ (p ^ -n)` if `x ^ (p ^ n)` is equal to some element `y` of `K`. -/ def liftAux (x : L) : M := (iterateFrobeniusEquiv M p (Classical.choose (lift_aux i p x)).1).symm (j (Classical.choose (lift_aux i p x)).2) @[simp] theorem liftAux_self_apply [ExpChar L p] [PerfectRing L p] (x : L) : liftAux i i p x = x := by rw [liftAux, Classical.choose_spec (lift_aux i p x), ← iterateFrobenius_def, ← iterateFrobeniusEquiv_apply, RingEquiv.symm_apply_apply] @[simp] theorem liftAux_self [ExpChar L p] [PerfectRing L p] : liftAux i i p = id := funext (liftAux_self_apply i p) @[simp] theorem liftAux_id_apply (x : K) : liftAux (RingHom.id K) j p x = j x := by have := RingHom.id_apply _ ▸ Classical.choose_spec (lift_aux (RingHom.id K) p x) rw [liftAux, this, map_pow, ← iterateFrobenius_def, ← iterateFrobeniusEquiv_apply, RingEquiv.symm_apply_apply] @[simp] theorem liftAux_id : liftAux (RingHom.id K) j p = j := funext (liftAux_id_apply j p) end PerfectRing end CommSemiring section CommRing variable [CommRing K] [CommRing L] [CommRing M] [CommRing N] (i : K →+* L) (j : K →+* M) (k : K →+* N) (f : L →+* M) (g : L →+* N) (p : ℕ) [ExpChar M p] namespace IsPRadical /-- If `i : K →+* L` is `p`-radical, then for any ring `M` of exponential charactistic `p` whose `p`-nilradical is zero, the map `(L →+* M) → (K →+* M)` induced by `i` is injective. -/ theorem injective_comp_of_pNilradical_eq_bot [IsPRadical i p] (h : pNilradical M p = ⊥) : Function.Injective fun f : L →+* M ↦ f.comp i := fun f g heq ↦ by ext x obtain ⟨n, y, hx⟩ := IsPRadical.pow_mem i p x apply_fun _ using pow_expChar_pow_inj_of_pNilradical_eq_bot M p h n simpa only [← map_pow, ← hx] using congr($(heq) y) variable (M) /-- If `i : K →+* L` is `p`-radical, then for any reduced ring `M` of exponential charactistic `p`, the map `(L →+* M) → (K →+* M)` induced by `i` is injective. A special case of `IsPRadical.injective_comp_of_pNilradical_eq_bot` and a generalization of `IsPurelyInseparable.injective_comp_algebraMap`. -/ theorem injective_comp [IsPRadical i p] [IsReduced M] : Function.Injective fun f : L →+* M ↦ f.comp i := injective_comp_of_pNilradical_eq_bot i p <| bot_unique <| pNilradical_le_nilradical.trans (nilradical_eq_zero M).le /-- If `i : K →+* L` is `p`-radical, then for any perfect ring `M` of exponential charactistic `p`, the map `(L →+* M) → (K →+* M)` induced by `i` is injective. A special case of `IsPRadical.injective_comp_of_pNilradical_eq_bot`. -/ theorem injective_comp_of_perfect [IsPRadical i p] [PerfectRing M p] : Function.Injective fun f : L →+* M ↦ f.comp i := injective_comp_of_pNilradical_eq_bot i p (PerfectRing.pNilradical_eq_bot M p) end IsPRadical namespace PerfectRing variable [ExpChar K p] [PerfectRing M p] [IsPRadical i p] /-- If `i : K →+* L` and `j : K →+* M` are ring homomorphisms of characteristic `p` rings, such that `i` is `p`-radical, and `M` is a perfect ring, then `PerfectRing.liftAux` is well-defined. -/ theorem liftAux_apply (x : L) (n : ℕ) (y : K) (h : i y = x ^ p ^ n) : liftAux i j p x = (iterateFrobeniusEquiv M p n).symm (j y) := by rw [liftAux] have h' := Classical.choose_spec (lift_aux i p x) set n' := (Classical.choose (lift_aux i p x)).1 replace h := congr($(h.symm) ^ p ^ n') rw [← pow_mul, mul_comm, pow_mul, ← h', ← map_pow, ← map_pow, ← sub_eq_zero, ← map_sub, ← RingHom.mem_ker] at h obtain ⟨m, h⟩ := mem_pNilradical.1 (IsPRadical.ker_le i p h) refine (iterateFrobeniusEquiv M p (m + n + n')).injective ?_ conv_lhs => rw [iterateFrobeniusEquiv_add_apply, RingEquiv.apply_symm_apply] rw [add_assoc, add_comm n n', ← add_assoc, iterateFrobeniusEquiv_add_apply (m := m + n'), RingEquiv.apply_symm_apply, iterateFrobeniusEquiv_def, iterateFrobeniusEquiv_def, ← sub_eq_zero, ← map_pow, ← map_pow, ← map_sub, add_comm m, add_comm m, pow_add, pow_mul, pow_add, pow_mul, ← sub_pow_expChar_pow, h, map_zero] variable [ExpChar L p] /-- If `i : K →+* L` and `j : K →+* M` are ring homomorphisms of characteristic `p` rings, such that `i` is `p`-radical, and `M` is a perfect ring, then `PerfectRing.liftAux` is a ring homomorphism. This is similar to `IsAlgClosed.lift` and `IsSepClosed.lift`. -/ def lift : L →+* M where toFun := liftAux i j p map_one' := by simp [liftAux_apply i j p 1 0 1 (by rw [one_pow, map_one])] map_mul' x1 x2 := by obtain ⟨n1, y1, h1⟩ := IsPRadical.pow_mem i p x1 obtain ⟨n2, y2, h2⟩ := IsPRadical.pow_mem i p x2 rw [liftAux_apply i j p _ _ _ h1, liftAux_apply i j p _ _ _ h2, liftAux_apply i j p (x1 * x2) (n1 + n2) (y1 ^ p ^ n2 * y2 ^ p ^ n1) (by rw [map_mul, map_pow, map_pow, h1, h2, ← pow_mul, ← pow_add, ← pow_mul, ← pow_add, add_comm n2, mul_pow]), map_mul, map_pow, map_pow, map_mul, ← iterateFrobeniusEquiv_def] nth_rw 1 [iterateFrobeniusEquiv_symm_add_apply] rw [RingEquiv.symm_apply_apply, add_comm n1, iterateFrobeniusEquiv_symm_add_apply, ← iterateFrobeniusEquiv_def, RingEquiv.symm_apply_apply] map_zero' := by simp [liftAux_apply i j p 0 0 0 (by rw [pow_zero, pow_one, map_zero])] map_add' x1 x2 := by obtain ⟨n1, y1, h1⟩ := IsPRadical.pow_mem i p x1 obtain ⟨n2, y2, h2⟩ := IsPRadical.pow_mem i p x2 rw [liftAux_apply i j p _ _ _ h1, liftAux_apply i j p _ _ _ h2, liftAux_apply i j p (x1 + x2) (n1 + n2) (y1 ^ p ^ n2 + y2 ^ p ^ n1) (by rw [map_add, map_pow, map_pow, h1, h2, ← pow_mul, ← pow_add, ← pow_mul, ← pow_add, add_comm n2, add_pow_expChar_pow]), map_add, map_pow, map_pow, map_add, ← iterateFrobeniusEquiv_def] nth_rw 1 [iterateFrobeniusEquiv_symm_add_apply] rw [RingEquiv.symm_apply_apply, add_comm n1, iterateFrobeniusEquiv_symm_add_apply, ← iterateFrobeniusEquiv_def, RingEquiv.symm_apply_apply] theorem lift_apply (x : L) (n : ℕ) (y : K) (h : i y = x ^ p ^ n) : lift i j p x = (iterateFrobeniusEquiv M p n).symm (j y) := liftAux_apply i j p _ _ _ h @[simp] theorem lift_comp_apply (x : K) : lift i j p (i x) = j x := by rw [lift_apply i j p _ 0 x (by rw [pow_zero, pow_one]), iterateFrobeniusEquiv_zero]; rfl @[simp] theorem lift_comp : (lift i j p).comp i = j := RingHom.ext (lift_comp_apply i j p) theorem lift_self_apply [PerfectRing L p] (x : L) : lift i i p x = x := liftAux_self_apply i p x @[simp] theorem lift_self [PerfectRing L p] : lift i i p = RingHom.id L := RingHom.ext (liftAux_self_apply i p) theorem lift_id_apply (x : K) : lift (RingHom.id K) j p x = j x := liftAux_id_apply j p x @[simp] theorem lift_id : lift (RingHom.id K) j p = j := RingHom.ext (liftAux_id_apply j p) @[simp] theorem comp_lift : lift i (f.comp i) p = f := IsPRadical.injective_comp_of_perfect _ i p (lift_comp i _ p) theorem comp_lift_apply (x : L) : lift i (f.comp i) p x = f x := congr($(comp_lift i f p) x) variable (M) in /-- If `i : K →+* L` is a homomorphisms of characteristic `p` rings, such that `i` is `p`-radical, and `M` is a perfect ring of characteristic `p`, then `K →+* M` is one-to-one correspondence to `L →+* M`, given by `PerfectRing.lift`. This is a generalization to `PerfectClosure.lift`. -/ def liftEquiv : (K →+* M) ≃ (L →+* M) where toFun j := lift i j p invFun f := f.comp i left_inv f := lift_comp i f p right_inv f := comp_lift i f p theorem liftEquiv_apply : liftEquiv M i p j = lift i j p := rfl theorem liftEquiv_symm_apply : (liftEquiv M i p).symm f = f.comp i := rfl theorem liftEquiv_id_apply : liftEquiv M (RingHom.id K) p j = j := lift_id j p @[simp] theorem liftEquiv_id : liftEquiv M (RingHom.id K) p = Equiv.refl _ := Equiv.ext (liftEquiv_id_apply · p) section comp variable [ExpChar N p] [PerfectRing N p] [IsPRadical j p] @[simp] theorem lift_comp_lift : (lift j k p).comp (lift i j p) = lift i k p := IsPRadical.injective_comp_of_perfect _ i p (by ext; simp) @[simp] theorem lift_comp_lift_apply (x : L) : lift j k p (lift i j p x) = lift i k p x := congr($(lift_comp_lift i j k p) x) theorem lift_comp_lift_apply_eq_self [PerfectRing L p] (x : L) : lift j i p (lift i j p x) = x := by rw [lift_comp_lift_apply, lift_self_apply] theorem lift_comp_lift_eq_id [PerfectRing L p] : (lift j i p).comp (lift i j p) = RingHom.id L := RingHom.ext (lift_comp_lift_apply_eq_self i j p) end comp section liftEquiv_comp variable [ExpChar N p] [IsPRadical g p] [IsPRadical (g.comp i) p] @[simp] theorem lift_lift : lift g (lift i j p) p = lift (g.comp i) j p := by refine IsPRadical.injective_comp_of_perfect _ (g.comp i) p ?_ simp_rw [← RingHom.comp_assoc _ _ (lift g _ p), lift_comp] theorem lift_lift_apply (x : N) : lift g (lift i j p) p x = lift (g.comp i) j p x := congr($(lift_lift i j g p) x) @[simp] theorem liftEquiv_comp_apply : liftEquiv M g p (liftEquiv M i p j) = liftEquiv M (g.comp i) p j := lift_lift i j g p @[simp] theorem liftEquiv_trans : (liftEquiv M i p).trans (liftEquiv M g p) = liftEquiv M (g.comp i) p := Equiv.ext (liftEquiv_comp_apply i · g p) end liftEquiv_comp end PerfectRing namespace IsPerfectClosure variable [ExpChar K p] [ExpChar L p] [PerfectRing L p] [IsPerfectClosure i p] [PerfectRing M p] [IsPerfectClosure j p] /-- If `L` and `M` are both perfect closures of `K`, then there is a ring isomorphism `L ≃+* M`. This is similar to `IsAlgClosure.equiv` and `IsSepClosure.equiv`. -/ def equiv : L ≃+* M where __ := PerfectRing.lift i j p invFun := PerfectRing.liftAux j i p left_inv := PerfectRing.lift_comp_lift_apply_eq_self i j p right_inv := PerfectRing.lift_comp_lift_apply_eq_self j i p theorem equiv_toRingHom : (equiv i j p).toRingHom = PerfectRing.lift i j p := rfl @[simp] theorem equiv_symm : (equiv i j p).symm = equiv j i p := rfl theorem equiv_symm_toRingHom : (equiv i j p).symm.toRingHom = PerfectRing.lift j i p := rfl theorem equiv_apply (x : L) (n : ℕ) (y : K) (h : i y = x ^ p ^ n) : equiv i j p x = (iterateFrobeniusEquiv M p n).symm (j y) := PerfectRing.liftAux_apply i j p _ _ _ h theorem equiv_symm_apply (x : M) (n : ℕ) (y : K) (h : j y = x ^ p ^ n) : (equiv i j p).symm x = (iterateFrobeniusEquiv L p n).symm (i y) := by rw [equiv_symm, equiv_apply j i p _ _ _ h] theorem equiv_self_apply (x : L) : equiv i i p x = x := PerfectRing.liftAux_self_apply i p x @[simp] theorem equiv_self : equiv i i p = RingEquiv.refl L := RingEquiv.ext (equiv_self_apply i p) @[simp] theorem equiv_comp_apply (x : K) : equiv i j p (i x) = j x := PerfectRing.lift_comp_apply i j p x @[simp] theorem equiv_comp : RingHom.comp (equiv i j p) i = j := RingHom.ext (equiv_comp_apply i j p) section comp variable [ExpChar N p] [PerfectRing N p] [IsPerfectClosure k p] @[simp] theorem equiv_comp_equiv_apply (x : L) : equiv j k p (equiv i j p x) = equiv i k p x := PerfectRing.lift_comp_lift_apply i j k p x @[simp] theorem equiv_comp_equiv : (equiv i j p).trans (equiv j k p) = equiv i k p := RingEquiv.ext (equiv_comp_equiv_apply i j k p) theorem equiv_comp_equiv_apply_eq_self (x : L) : equiv j i p (equiv i j p x) = x := by rw [equiv_comp_equiv_apply, equiv_self_apply] theorem equiv_comp_equiv_eq_id : (equiv i j p).trans (equiv j i p) = RingEquiv.refl L := RingEquiv.ext (equiv_comp_equiv_apply_eq_self i j p) end comp end IsPerfectClosure end CommRing namespace PerfectClosure variable [CommRing K] (p : ℕ) [Fact p.Prime] [CharP K p] variable (K) /-- The absolute perfect closure `PerfectClosure` is a `p`-radical extension over the base ring. In particular, it is a perfect closure of the base ring, that is, `IsPerfectClosure (PerfectClosure.of K p) p`. -/ instance isPRadical : IsPRadical (PerfectClosure.of K p) p where pow_mem' x := PerfectClosure.induction_on x fun x ↦ ⟨x.1, x.2, by rw [← iterate_frobenius, iterate_frobenius_mk K p x.1 x.2]⟩ ker_le' x h := by rw [RingHom.mem_ker, of_apply, zero_def, mk_eq_iff] at h obtain ⟨n, h⟩ := h simp_rw [zero_add, ← coe_iterateFrobenius, map_zero] at h exact mem_pNilradical.2 ⟨n, h⟩ end PerfectClosure section Field variable [Field K] [Field L] [Algebra K L] (p : ℕ) [ExpChar K p] variable (K L) /-- If `L / K` is a `p`-radical field extension, then it is purely inseparable. -/ theorem IsPRadical.isPurelyInseparable [IsPRadical (algebraMap K L) p] : IsPurelyInseparable K L := (isPurelyInseparable_iff_pow_mem K p).2 (IsPRadical.pow_mem (algebraMap K L) p) /-- If `L / K` is a purely inseparable field extension, then it is `p`-radical. In particular, if `L` is perfect, then the (relative) perfect closure `perfectClosure K L` is a perfect closure of `K`, that is, `IsPerfectClosure (algebraMap K (perfectClosure K L)) p`. -/ instance IsPurelyInseparable.isPRadical [IsPurelyInseparable K L] : IsPRadical (algebraMap K L) p where pow_mem' := (isPurelyInseparable_iff_pow_mem K p).1 ‹_› ker_le' := (RingHom.injective_iff_ker_eq_bot _).1 (algebraMap K L).injective ▸ bot_le end Field end IsPerfectClosure
OrdinaryHypergeometric.lean
/- Copyright (c) 2024 Edward Watine. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Edward Watine -/ import Mathlib.Analysis.Analytic.OfScalars import Mathlib.Analysis.SpecificLimits.RCLike /-! # Ordinary hypergeometric function in a Banach algebra In this file, we define `ordinaryHypergeometric`, the _ordinary_ or _Gaussian_ hypergeometric function in a topological algebra `𝔸` over a field `𝕂` given by: $$ _2\mathrm{F}_1(a\ b\ c : \mathbb{K}, x : \mathbb{A}) = \sum_{n=0}^{\infty}\frac{(a)_n(b)_n}{(c)_n} \frac{x^n}{n!} \,, $$ with $(a)_n$ is the ascending Pochhammer symbol (see `ascPochhammer`). This file contains the basic definitions over a general field `𝕂` and notation for `₂F₁`, as well as showing that terms of the series are zero if any of the `(a b c : 𝕂)` are sufficiently large non-positive integers, rendering the series finite. In this file "sufficiently large" means that `-n < a` for the `n`-th term, and similarly for `b` and `c`. - `ordinaryHypergeometricSeries` is the `FormalMultilinearSeries` given above for some `(a b c : 𝕂)` - `ordinaryHypergeometric` is the sum of the series for some `(x : 𝔸)` - `ordinaryHypergeometricSeries_eq_zero_of_nonpos_int` shows that the `n`-th term of the series is zero if any of the parameters are sufficiently large non-positive integers ## `[RCLike 𝕂]` If we have `[RCLike 𝕂]`, then we show that the latter result is an iff, and hence prove that the radius of convergence of the series is unity if the series is infinite, or `⊤` otherwise. - `ordinaryHypergeometricSeries_eq_zero_iff` is iff variant of `ordinaryHypergeometricSeries_eq_zero_of_nonpos_int` - `ordinaryHypergeometricSeries_radius_eq_one` proves that the radius of convergence of the `ordinaryHypergeometricSeries` is unity under non-trivial parameters ## Notation `₂F₁` is notation for `ordinaryHypergeometric`. ## References See <https://en.wikipedia.org/wiki/Hypergeometric_function>. ## Tags hypergeometric, gaussian, ordinary -/ open Nat FormalMultilinearSeries section Field variable {𝕂 : Type*} (𝔸 : Type*) [Field 𝕂] [Ring 𝔸] [Algebra 𝕂 𝔸] [TopologicalSpace 𝔸] [IsTopologicalRing 𝔸] /-- The coefficients in the ordinary hypergeometric sum. -/ noncomputable abbrev ordinaryHypergeometricCoefficient (a b c : 𝕂) (n : ℕ) := ((n !⁻¹ : 𝕂) * (ascPochhammer 𝕂 n).eval a * (ascPochhammer 𝕂 n).eval b * ((ascPochhammer 𝕂 n).eval c)⁻¹) /-- `ordinaryHypergeometricSeries 𝔸 (a b c : 𝕂)` is a `FormalMultilinearSeries`. Its sum is the `ordinaryHypergeometric` map. -/ noncomputable def ordinaryHypergeometricSeries (a b c : 𝕂) : FormalMultilinearSeries 𝕂 𝔸 𝔸 := ofScalars 𝔸 (ordinaryHypergeometricCoefficient a b c) variable {𝔸} (a b c : 𝕂) /-- `ordinaryHypergeometric (a b c : 𝕂) : 𝔸 → 𝔸`, denoted `₂F₁`, is the ordinary hypergeometric map, defined as the sum of the `FormalMultilinearSeries` `ordinaryHypergeometricSeries 𝔸 a b c`. Note that this takes the junk value `0` outside the radius of convergence. -/ noncomputable def ordinaryHypergeometric (x : 𝔸) : 𝔸 := (ordinaryHypergeometricSeries 𝔸 a b c).sum x @[inherit_doc] notation "₂F₁" => ordinaryHypergeometric theorem ordinaryHypergeometricSeries_apply_eq (x : 𝔸) (n : ℕ) : (ordinaryHypergeometricSeries 𝔸 a b c n fun _ => x) = ((n !⁻¹ : 𝕂) * (ascPochhammer 𝕂 n).eval a * (ascPochhammer 𝕂 n).eval b * ((ascPochhammer 𝕂 n).eval c)⁻¹ ) • x ^ n := by rw [ordinaryHypergeometricSeries, ofScalars_apply_eq] /-- This naming follows the convention of `NormedSpace.expSeries_apply_eq'`. -/ theorem ordinaryHypergeometricSeries_apply_eq' (x : 𝔸) : (fun n => ordinaryHypergeometricSeries 𝔸 a b c n fun _ => x) = fun n => ((n !⁻¹ : 𝕂) * (ascPochhammer 𝕂 n).eval a * (ascPochhammer 𝕂 n).eval b * ((ascPochhammer 𝕂 n).eval c)⁻¹ ) • x ^ n := by rw [ordinaryHypergeometricSeries, ofScalars_apply_eq'] theorem ordinaryHypergeometric_sum_eq (x : 𝔸) : (ordinaryHypergeometricSeries 𝔸 a b c).sum x = ∑' n : ℕ, ((n !⁻¹ : 𝕂) * (ascPochhammer 𝕂 n).eval a * (ascPochhammer 𝕂 n).eval b * ((ascPochhammer 𝕂 n).eval c)⁻¹ ) • x ^ n := tsum_congr fun n => ordinaryHypergeometricSeries_apply_eq a b c x n theorem ordinaryHypergeometric_eq_tsum : ₂F₁ a b c = fun (x : 𝔸) => ∑' n : ℕ, ((n !⁻¹ : 𝕂) * (ascPochhammer 𝕂 n).eval a * (ascPochhammer 𝕂 n).eval b * ((ascPochhammer 𝕂 n).eval c)⁻¹ ) • x ^ n := funext (ordinaryHypergeometric_sum_eq a b c) theorem ordinaryHypergeometricSeries_apply_zero (n : ℕ) : ordinaryHypergeometricSeries 𝔸 a b c n (fun _ => 0) = Pi.single (M := fun _ => 𝔸) 0 1 n := by rw [ordinaryHypergeometricSeries, ofScalars_apply_eq, ordinaryHypergeometricCoefficient] cases n <;> simp @[simp] theorem ordinaryHypergeometric_zero : ₂F₁ a b c (0 : 𝔸) = 1 := by simp [ordinaryHypergeometric_eq_tsum, ← ordinaryHypergeometricSeries_apply_eq, ordinaryHypergeometricSeries_apply_zero] theorem ordinaryHypergeometricSeries_symm : ordinaryHypergeometricSeries 𝔸 a b c = ordinaryHypergeometricSeries 𝔸 b a c := by unfold ordinaryHypergeometricSeries ordinaryHypergeometricCoefficient simp [mul_assoc, mul_left_comm] /-- If any parameter to the series is a sufficiently large nonpositive integer, then the series term is zero. -/ lemma ordinaryHypergeometricSeries_eq_zero_of_neg_nat {n k : ℕ} (habc : k = -a ∨ k = -b ∨ k = -c) (hk : k < n) : ordinaryHypergeometricSeries 𝔸 a b c n = 0 := by rw [ordinaryHypergeometricSeries, ofScalars] rcases habc with h | h | h all_goals ext simp [(ascPochhammer_eval_eq_zero_iff n _).2 ⟨k, hk, h⟩] end Field section RCLike open Asymptotics Filter Real Set Nat open scoped Topology variable {𝕂 : Type*} (𝔸 : Type*) [RCLike 𝕂] [NormedDivisionRing 𝔸] [NormedAlgebra 𝕂 𝔸] (a b c : 𝕂) theorem ordinaryHypergeometric_radius_top_of_neg_nat₁ {k : ℕ} : (ordinaryHypergeometricSeries 𝔸 (-(k : 𝕂)) b c).radius = ⊤ := by refine FormalMultilinearSeries.radius_eq_top_of_forall_image_add_eq_zero _ (1 + k) fun n ↦ ?_ exact ordinaryHypergeometricSeries_eq_zero_of_neg_nat (-(k : 𝕂)) b c (by aesop) (by omega) theorem ordinaryHypergeometric_radius_top_of_neg_nat₂ {k : ℕ} : (ordinaryHypergeometricSeries 𝔸 a (-(k : 𝕂)) c).radius = ⊤ := by rw [ordinaryHypergeometricSeries_symm] exact ordinaryHypergeometric_radius_top_of_neg_nat₁ 𝔸 a c theorem ordinaryHypergeometric_radius_top_of_neg_nat₃ {k : ℕ} : (ordinaryHypergeometricSeries 𝔸 a b (-(k : 𝕂))).radius = ⊤ := by refine FormalMultilinearSeries.radius_eq_top_of_forall_image_add_eq_zero _ (1 + k) fun n ↦ ?_ exact ordinaryHypergeometricSeries_eq_zero_of_neg_nat a b (-(k : 𝕂)) (by aesop) (by omega) /-- An iff variation on `ordinaryHypergeometricSeries_eq_zero_of_nonpos_int` for `[RCLike 𝕂]`. -/ lemma ordinaryHypergeometricSeries_eq_zero_iff (n : ℕ) : ordinaryHypergeometricSeries 𝔸 a b c n = 0 ↔ ∃ k < n, k = -a ∨ k = -b ∨ k = -c := by refine ⟨fun h ↦ ?_, fun zero ↦ ?_⟩ · rw [ordinaryHypergeometricSeries, ofScalars_eq_zero] at h simp only [_root_.mul_eq_zero, inv_eq_zero] at h rcases h with ((hn | h) | h) | h · simp [Nat.factorial_ne_zero] at hn all_goals obtain ⟨kn, hkn, hn⟩ := (ascPochhammer_eval_eq_zero_iff _ _).1 h exact ⟨kn, hkn, by tauto⟩ · obtain ⟨_, h, hn⟩ := zero exact ordinaryHypergeometricSeries_eq_zero_of_neg_nat a b c hn h theorem ordinaryHypergeometricSeries_norm_div_succ_norm (n : ℕ) (habc : ∀ kn < n, (↑kn ≠ -a ∧ ↑kn ≠ -b ∧ ↑kn ≠ -c)) : ‖ordinaryHypergeometricCoefficient a b c n‖ / ‖ordinaryHypergeometricCoefficient a b c n.succ‖ = ‖a + n‖⁻¹ * ‖b + n‖⁻¹ * ‖c + n‖ * ‖1 + (n : 𝕂)‖ := by simp only [mul_inv_rev, factorial_succ, cast_mul, cast_add, cast_one, ascPochhammer_succ_eval, norm_mul, norm_inv] calc _ = ‖Polynomial.eval a (ascPochhammer 𝕂 n)‖ * ‖Polynomial.eval a (ascPochhammer 𝕂 n)‖⁻¹ * ‖Polynomial.eval b (ascPochhammer 𝕂 n)‖ * ‖Polynomial.eval b (ascPochhammer 𝕂 n)‖⁻¹ * ‖Polynomial.eval c (ascPochhammer 𝕂 n)‖⁻¹⁻¹ * ‖Polynomial.eval c (ascPochhammer 𝕂 n)‖⁻¹ * ‖(n ! : 𝕂)‖⁻¹⁻¹ * ‖(n ! : 𝕂)‖⁻¹ * ‖a + n‖⁻¹ * ‖b + n‖⁻¹ * ‖c + n‖⁻¹⁻¹ * ‖1 + (n : 𝕂)‖⁻¹⁻¹ := by ring_nf _ = _ := by simp only [inv_inv] repeat rw [DivisionRing.mul_inv_cancel, one_mul] all_goals rw [norm_ne_zero_iff] any_goals apply (ascPochhammer_eval_eq_zero_iff n _).not.2 push_neg exact fun kn hkn ↦ by simp [habc kn hkn] exact cast_ne_zero.2 (factorial_ne_zero n) /-- The radius of convergence of `ordinaryHypergeometricSeries` is unity if none of the parameters are non-positive integers. -/ theorem ordinaryHypergeometricSeries_radius_eq_one (habc : ∀ kn : ℕ, ↑kn ≠ -a ∧ ↑kn ≠ -b ∧ ↑kn ≠ -c) : (ordinaryHypergeometricSeries 𝔸 a b c).radius = 1 := by convert ofScalars_radius_eq_of_tendsto 𝔸 _ one_ne_zero ?_ suffices Tendsto (fun k : ℕ ↦ (a + k)⁻¹ * (b + k)⁻¹ * (c + k) * ((1 : 𝕂) + k)) atTop (𝓝 1) by simp_rw [ordinaryHypergeometricSeries_norm_div_succ_norm a b c _ (fun n _ ↦ habc n)] simp only [← norm_inv, ← norm_mul, NNReal.coe_one] convert Filter.Tendsto.norm this exact norm_one.symm have (k : ℕ) : (a + k)⁻¹ * (b + k)⁻¹ * (c + k) * ((1 : 𝕂) + k) = (c + k) / (a + k) * ((1 + k) / (b + k)) := by field_simp simp_rw [this] apply (mul_one (1 : 𝕂)) ▸ Filter.Tendsto.mul <;> convert RCLike.tendsto_add_mul_div_add_mul_atTop_nhds _ _ (1 : 𝕂) one_ne_zero <;> simp end RCLike
Grothendieck.lean
/- Copyright (c) 2024 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Filtered.Basic import Mathlib.CategoryTheory.Grothendieck /-! # Filteredness of Grothendieck construction We show that if `F : C ⥤ Cat` is such that `C` is filtered and `F.obj c` is filtered for all `c : C`, then `Grothendieck F` is filtered. -/ universe v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] (F : C ⥤ Cat) open IsFiltered instance [IsFilteredOrEmpty C] [∀ c, IsFilteredOrEmpty (F.obj c)] : IsFilteredOrEmpty (Grothendieck F) := by refine ⟨?_, ?_⟩ · rintro ⟨c, f⟩ ⟨d, g⟩ exact ⟨⟨max c d, max ((F.map (leftToMax c d)).obj f) ((F.map (rightToMax c d)).obj g)⟩, ⟨leftToMax c d, leftToMax _ _⟩, ⟨rightToMax c d, rightToMax _ _⟩, trivial⟩ · rintro ⟨c, f⟩ ⟨d, g⟩ ⟨u, x⟩ ⟨v, y⟩ refine ⟨⟨coeq u v, coeq (eqToHom ?_ ≫ (F.map (coeqHom u v)).map x) ((F.map (coeqHom u v)).map y)⟩, ⟨coeqHom u v, coeqHom _ _⟩, ?_⟩ · conv_rhs => rw [← Cat.comp_obj, ← F.map_comp, coeq_condition, F.map_comp, Cat.comp_obj] · apply Grothendieck.ext _ _ (coeq_condition u v) refine Eq.trans ?_ (eqToHom _ ≫= coeq_condition _ _) simp instance [IsFiltered C] [∀ c, IsFiltered (F.obj c)] : IsFiltered (Grothendieck F) := by have : Nonempty (Grothendieck F) := by obtain ⟨c⟩ : Nonempty C := IsFiltered.nonempty obtain ⟨f⟩ : Nonempty (F.obj c) := IsFiltered.nonempty exact ⟨⟨c, f⟩⟩ apply IsFiltered.mk end CategoryTheory
ExtendToSucc.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.SmallObject.Iteration.Basic /-! # Extension of a functor from `Set.Iic j` to `Set.Iic (Order.succ j)` Given a linearly ordered type `J` with `SuccOrder J`, `j : J` that is not maximal, we define the extension of a functor `F : Set.Iic j ⥤ C` as a functor `Set.Iic (Order.succ j) ⥤ C` when an object `X : C` and a morphism `τ : F.obj ⟨j, _⟩ ⟶ X` is given. -/ universe u namespace CategoryTheory open Category namespace SmallObject variable {C : Type*} [Category C] {J : Type u} [LinearOrder J] [SuccOrder J] {j : J} (hj : ¬IsMax j) (F : Set.Iic j ⥤ C) {X : C} (τ : F.obj ⟨j, by simp⟩ ⟶ X) namespace SuccStruct namespace extendToSucc variable (X) /-- `extendToSucc`, on objects: it coincides with `F.obj` for `i ≤ j`, and it sends `Order.succ j` to the given object `X`. -/ def obj (i : Set.Iic (Order.succ j)) : C := if hij : i.1 ≤ j then F.obj ⟨i.1, hij⟩ else X lemma obj_eq (i : Set.Iic j) : obj F X ⟨i, i.2.trans (Order.le_succ j)⟩ = F.obj i := dif_pos i.2 /-- The isomorphism `obj F X ⟨i, _⟩ ≅ F.obj i` when `i : Set.Iic j`. -/ def objIso (i : Set.Iic j) : obj F X ⟨i, i.2.trans (Order.le_succ j)⟩ ≅ F.obj i := eqToIso (obj_eq _ _ _) include hj in lemma obj_succ_eq : obj F X ⟨Order.succ j, by simp⟩ = X := dif_neg (by simpa only [Order.succ_le_iff_isMax] using hj) /-- The isomorphism `obj F X ⟨Order.succ j, _⟩ ≅ X`. -/ def objSuccIso : obj F X ⟨Order.succ j, by simp⟩ ≅ X := eqToIso (obj_succ_eq hj _ _) variable {X} /-- `extendToSucc`, on morphisms. -/ def map (i₁ i₂ : J) (hi : i₁ ≤ i₂) (hi₂ : i₂ ≤ Order.succ j) : obj F X ⟨i₁, hi.trans hi₂⟩ ⟶ obj F X ⟨i₂, hi₂⟩ := if h₁ : i₂ ≤ j then (objIso F X ⟨i₁, hi.trans h₁⟩).hom ≫ F.map (homOfLE hi) ≫ (objIso F X ⟨i₂, h₁⟩).inv else if h₂ : i₁ ≤ j then (objIso F X ⟨i₁, h₂⟩).hom ≫ F.map (homOfLE h₂) ≫ τ ≫ (objSuccIso hj F X).inv ≫ eqToHom (by congr exact le_antisymm (Order.succ_le_of_lt (not_le.1 h₁)) hi₂) else eqToHom (by congr rw [le_antisymm hi₂ (Order.succ_le_of_lt (not_le.1 h₁)), le_antisymm (hi.trans hi₂) (Order.succ_le_of_lt (not_le.1 h₂))]) lemma map_eq (i₁ i₂ : J) (hi : i₁ ≤ i₂) (hi₂ : i₂ ≤ j) : map hj F τ i₁ i₂ hi (hi₂.trans (Order.le_succ j)) = (objIso F X ⟨i₁, hi.trans hi₂⟩).hom ≫ F.map (homOfLE hi) ≫ (objIso F X ⟨i₂, hi₂⟩).inv := dif_pos hi₂ lemma map_self_succ : map hj F τ j (Order.succ j) (Order.le_succ j) (by rfl) = (objIso F X ⟨j, by simp⟩).hom ≫ τ ≫ (objSuccIso hj F X).inv := by dsimp [map] rw [dif_neg (by simpa only [Order.succ_le_iff_isMax] using hj), dif_pos (by rfl), Functor.map_id, comp_id, id_comp] @[simp] lemma map_id (i : J) (hi : i ≤ Order.succ j) : map hj F τ i i (by rfl) hi = 𝟙 _ := by dsimp [map] by_cases h₁ : i ≤ j · rw [dif_pos h₁, CategoryTheory.Functor.map_id, id_comp, Iso.hom_inv_id] · obtain rfl : i = Order.succ j := le_antisymm hi (Order.succ_le_of_lt (not_le.1 h₁)) rw [dif_neg (by simpa only [Order.succ_le_iff_isMax] using hj), dif_neg h₁] lemma map_comp (i₁ i₂ i₃ : J) (h₁₂ : i₁ ≤ i₂) (h₂₃ : i₂ ≤ i₃) (h : i₃ ≤ Order.succ j) : map hj F τ i₁ i₃ (h₁₂.trans h₂₃) h = map hj F τ i₁ i₂ h₁₂ (h₂₃.trans h) ≫ map hj F τ i₂ i₃ h₂₃ h := by by_cases h₁ : i₃ ≤ j · rw [map_eq hj F τ i₁ i₂ _ (h₂₃.trans h₁), map_eq hj F τ i₂ i₃ _ h₁, map_eq hj F τ i₁ i₃ _ h₁, assoc, assoc, Iso.inv_hom_id_assoc, ← Functor.map_comp_assoc, homOfLE_comp] · obtain rfl : i₃ = Order.succ j := le_antisymm h (Order.succ_le_of_lt (not_le.1 h₁)) obtain h₂ | rfl := h₂₃.lt_or_eq · rw [Order.lt_succ_iff_of_not_isMax hj] at h₂ rw [map_eq hj F τ i₁ i₂ _ h₂] dsimp [map] rw [dif_neg h₁, dif_pos (h₁₂.trans h₂), dif_neg h₁, dif_pos h₂, assoc, assoc, Iso.inv_hom_id_assoc,comp_id, ← Functor.map_comp_assoc, homOfLE_comp] · rw [map_id, comp_id] end extendToSucc open extendToSucc in include hj in /-- The extension to `Set.Iic (Order.succ j) ⥤ C` of a functor `F : Set.Iic j ⥤ C`, when we specify a morphism `F.obj ⟨j, _⟩ ⟶ X`. -/ def extendToSucc : Set.Iic (Order.succ j) ⥤ C where obj := obj F X map {i₁ i₂} f := map hj F τ i₁ i₂ (leOfHom f) i₂.2 map_id _ := extendToSucc.map_id _ F τ _ _ map_comp {i₁ i₂ i₃} f g := extendToSucc.map_comp hj F τ i₁ i₂ i₃ (leOfHom f) (leOfHom g) i₃.2 lemma extendToSucc_obj_eq (i : J) (hi : i ≤ j) : (extendToSucc hj F τ).obj ⟨i, hi.trans (Order.le_succ j)⟩ = F.obj ⟨i, hi⟩ := extendToSucc.obj_eq F X ⟨i, hi⟩ /-- The isomorphism `(extendToSucc hj F τ).obj ⟨i, _⟩ ≅ F.obj i` when `i ≤ j` -/ def extendToSuccObjIso (i : J) (hi : i ≤ j) : (extendToSucc hj F τ).obj ⟨i, hi.trans (Order.le_succ j)⟩ ≅ F.obj ⟨i, hi⟩ := extendToSucc.objIso F X ⟨i, hi⟩ lemma extendToSucc_obj_succ_eq : (extendToSucc hj F τ).obj ⟨Order.succ j, by simp⟩ = X := extendToSucc.obj_succ_eq hj F X /-- The isomorphism `(extendToSucc hj F τ).obj ⟨Order.succ j, _⟩ ≅ X`. -/ def extendToSuccObjSuccIso : (extendToSucc hj F τ).obj ⟨Order.succ j, by simp⟩ ≅ X := extendToSucc.objSuccIso hj F X @[reassoc] lemma extendToSuccObjIso_hom_naturality (i₁ i₂ : J) (hi : i₁ ≤ i₂) (hi₂ : i₂ ≤ j) : (extendToSucc hj F τ).map (homOfLE hi : ⟨i₁, hi.trans (hi₂.trans (Order.le_succ j))⟩ ⟶ ⟨i₂, hi₂.trans (Order.le_succ j)⟩) ≫ (extendToSuccObjIso hj F τ i₂ hi₂).hom = (extendToSuccObjIso hj F τ i₁ (hi.trans hi₂)).hom ≫ F.map (homOfLE hi) := by dsimp [extendToSucc, extendToSuccObjIso] rw [extendToSucc.map_eq _ _ _ _ _ _ hi₂, assoc, assoc, Iso.inv_hom_id, comp_id] /-- The isomorphism expressing that `extendToSucc hj F τ` extends `F`. -/ @[simps!] def extendToSuccRestrictionLEIso : SmallObject.restrictionLE (extendToSucc hj F τ) (Order.le_succ j) ≅ F := NatIso.ofComponents (fun i ↦ extendToSuccObjIso hj F τ i.1 i.2) (by rintro ⟨i₁, h₁⟩ ⟨i₂, h₂⟩ f apply extendToSuccObjIso_hom_naturality) lemma extendToSucc_map (i₁ i₂ : J) (hi : i₁ ≤ i₂) (hi₂ : i₂ ≤ j) : (extendToSucc hj F τ).map (homOfLE hi : ⟨i₁, hi.trans (hi₂.trans (Order.le_succ j))⟩ ⟶ ⟨i₂, hi₂.trans (Order.le_succ j)⟩) = (extendToSuccObjIso hj F τ i₁ (hi.trans hi₂)).hom ≫ F.map (homOfLE hi) ≫ (extendToSuccObjIso hj F τ i₂ hi₂).inv := by rw [← extendToSuccObjIso_hom_naturality_assoc, Iso.hom_inv_id, comp_id] lemma extendToSucc_map_le_succ : (extendToSucc hj F τ).map (homOfLE (Order.le_succ j)) = (extendToSuccObjIso hj F τ j (by simp)).hom ≫ τ ≫ (extendToSuccObjSuccIso hj F τ).inv := extendToSucc.map_self_succ _ _ _ lemma arrowMap_extendToSucc (i₁ i₂ : J) (hi : i₁ ≤ i₂) (hi₂ : i₂ ≤ j) : arrowMap (extendToSucc hj F τ) i₁ i₂ hi (hi₂.trans (Order.le_succ j)) = arrowMap F i₁ i₂ hi hi₂ := by simp [arrowMap, extendToSucc_map hj F τ i₁ i₂ hi hi₂, extendToSuccObjIso, extendToSucc.objIso] lemma arrowSucc_extendToSucc : arrowSucc (extendToSucc hj F τ) j (Order.lt_succ_of_not_isMax hj) = Arrow.mk τ := by simp [arrowSucc, arrowMap, extendToSucc_map_le_succ, extendToSuccObjIso, extendToSucc.objIso, extendToSuccObjSuccIso, extendToSucc.objSuccIso] end SuccStruct end SmallObject end CategoryTheory
Defs.lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Aesop import Mathlib.Data.Multiset.Defs import Mathlib.Data.Set.Pairwise.Basic import Mathlib.Order.Hom.Basic /-! # Finite sets Terms of type `Finset α` are one way of talking about finite subsets of `α` in Mathlib. Below, `Finset α` is defined as a structure with 2 fields: 1. `val` is a `Multiset α` of elements; 2. `nodup` is a proof that `val` has no duplicates. Finsets in Lean are constructive in that they have an underlying `List` that enumerates their elements. In particular, any function that uses the data of the underlying list cannot depend on its ordering. This is handled on the `Multiset` level by multiset API, so in most cases one needn't worry about it explicitly. Finsets give a basic foundation for defining finite sums and products over types: 1. `∑ i ∈ (s : Finset α), f i`; 2. `∏ i ∈ (s : Finset α), f i`. Lean refers to these operations as big operators. More information can be found in `Mathlib/Algebra/BigOperators/Group/Finset.lean`. Finsets are directly used to define fintypes in Lean. A `Fintype α` instance for a type `α` consists of a universal `Finset α` containing every term of `α`, called `univ`. See `Mathlib/Data/Fintype/Basic.lean`. `Finset.card`, the size of a finset is defined in `Mathlib/Data/Finset/Card.lean`. This is then used to define `Fintype.card`, the size of a type. ## File structure This file defines the `Finset` type and the membership and subset relations between finsets. Most constructions involving `Finset`s have been split off to their own files. ## Main definitions * `Finset`: Defines a type for the finite subsets of `α`. Constructing a `Finset` requires two pieces of data: `val`, a `Multiset α` of elements, and `nodup`, a proof that `val` has no duplicates. * `Finset.instMembershipFinset`: Defines membership `a ∈ (s : Finset α)`. * `Finset.instCoeTCFinsetSet`: Provides a coercion `s : Finset α` to `s : Set α`. * `Finset.instCoeSortFinsetType`: Coerce `s : Finset α` to the type of all `x ∈ s`. ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen Multiset.powerset DirectedSystem CompleteLattice Monoid open Multiset Subtype Function universe u variable {α : Type*} {β : Type*} {γ : Type*} /-- `Finset α` is the type of finite sets of elements of `α`. It is implemented as a multiset (a list up to permutation) which has no duplicate elements. -/ structure Finset (α : Type*) where /-- The underlying multiset -/ val : Multiset α /-- `val` contains no duplicates -/ nodup : Nodup val instance Multiset.canLiftFinset {α} : CanLift (Multiset α) (Finset α) Finset.val Multiset.Nodup := ⟨fun m hm => ⟨⟨m, hm⟩, rfl⟩⟩ namespace Finset theorem eq_of_veq : ∀ {s t : Finset α}, s.1 = t.1 → s = t | ⟨s, _⟩, ⟨t, _⟩, h => by cases h; rfl theorem val_injective : Injective (val : Finset α → Multiset α) := fun _ _ => eq_of_veq @[simp] theorem val_inj {s t : Finset α} : s.1 = t.1 ↔ s = t := val_injective.eq_iff instance decidableEq [DecidableEq α] : DecidableEq (Finset α) | _, _ => decidable_of_iff _ val_inj /-! ### membership -/ instance : Membership α (Finset α) := ⟨fun s a => a ∈ s.1⟩ theorem mem_def {a : α} {s : Finset α} : a ∈ s ↔ a ∈ s.1 := Iff.rfl -- If https://github.com/leanprover/lean4/issues/2678 is resolved- -- this can be changed back to an `Iff`, but for now we would like `dsimp` to use it. @[simp, grind =] theorem mem_val {a : α} {s : Finset α} : (a ∈ s.1) = (a ∈ s) := rfl @[simp, grind =] theorem mem_mk {a : α} {s nd} : a ∈ @Finset.mk α s nd ↔ a ∈ s := Iff.rfl instance decidableMem [_h : DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ s) := Multiset.decidableMem _ _ @[simp] lemma forall_mem_not_eq {s : Finset α} {a : α} : (∀ b ∈ s, ¬ a = b) ↔ a ∉ s := by aesop @[simp] lemma forall_mem_not_eq' {s : Finset α} {a : α} : (∀ b ∈ s, ¬ b = a) ↔ a ∉ s := by aesop /-! ### set coercion -/ /-- Convert a finset to a set in the natural way. -/ @[coe] def toSet (s : Finset α) : Set α := { a | a ∈ s } /-- Convert a finset to a set in the natural way. -/ instance : CoeTC (Finset α) (Set α) := ⟨toSet⟩ @[simp, norm_cast, grind =] theorem mem_coe {a : α} {s : Finset α} : a ∈ (s : Set α) ↔ a ∈ (s : Finset α) := Iff.rfl @[simp] theorem setOf_mem {α} {s : Finset α} : { a | a ∈ s } = s := rfl @[simp] theorem coe_mem {s : Finset α} (x : (s : Set α)) : ↑x ∈ s := x.2 theorem mk_coe {s : Finset α} (x : (s : Set α)) {h} : (⟨x, h⟩ : (s : Set α)) = x := Subtype.coe_eta _ _ instance decidableMem' [DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ (s : Set α)) := s.decidableMem _ /-! ### extensionality -/ @[ext, grind ext] theorem ext {s₁ s₂ : Finset α} (h : ∀ a, a ∈ s₁ ↔ a ∈ s₂) : s₁ = s₂ := (val_inj.symm.trans <| s₁.nodup.ext s₂.nodup).mpr h @[simp, norm_cast] theorem coe_inj {s₁ s₂ : Finset α} : (s₁ : Set α) = s₂ ↔ s₁ = s₂ := Set.ext_iff.trans Finset.ext_iff.symm theorem coe_injective {α} : Injective ((↑) : Finset α → Set α) := fun _s _t => coe_inj.1 /-! ### type coercion -/ /-- Coercion from a finset to the corresponding subtype. -/ instance {α : Type u} : CoeSort (Finset α) (Type u) := ⟨fun s => { x // x ∈ s }⟩ protected theorem forall_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∀ x : s, p x) ↔ ∀ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall protected theorem exists_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∃ x : s, p x) ↔ ∃ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists instance PiFinsetCoe.canLift (ι : Type*) (α : ι → Type*) [_ne : ∀ i, Nonempty (α i)] (s : Finset ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α (· ∈ s) instance PiFinsetCoe.canLift' (ι α : Type*) [_ne : Nonempty α] (s : Finset ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiFinsetCoe.canLift ι (fun _ => α) s instance FinsetCoe.canLift (s : Finset α) : CanLift α s (↑) fun a => a ∈ s where prf a ha := ⟨⟨a, ha⟩, rfl⟩ @[simp, norm_cast] theorem coe_sort_coe (s : Finset α) : ((s : Set α) : Sort _) = s := rfl /-! ### Subset and strict subset relations -/ section Subset variable {s t : Finset α} instance : HasSubset (Finset α) := ⟨fun s t => ∀ ⦃a⦄, a ∈ s → a ∈ t⟩ instance : HasSSubset (Finset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance partialOrder : PartialOrder (Finset α) where le := (· ⊆ ·) lt := (· ⊂ ·) le_refl _ _ := id le_trans _ _ _ hst htu _ ha := htu <| hst ha le_antisymm _ _ hst hts := ext fun _ => ⟨@hst _, @hts _⟩ theorem subset_of_le : s ≤ t → s ⊆ t := id instance : IsRefl (Finset α) (· ⊆ ·) := show IsRefl (Finset α) (· ≤ ·) by infer_instance instance : IsTrans (Finset α) (· ⊆ ·) := show IsTrans (Finset α) (· ≤ ·) by infer_instance instance : IsAntisymm (Finset α) (· ⊆ ·) := show IsAntisymm (Finset α) (· ≤ ·) by infer_instance instance : IsIrrefl (Finset α) (· ⊂ ·) := show IsIrrefl (Finset α) (· < ·) by infer_instance instance : IsTrans (Finset α) (· ⊂ ·) := show IsTrans (Finset α) (· < ·) by infer_instance instance : IsAsymm (Finset α) (· ⊂ ·) := show IsAsymm (Finset α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Finset α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ theorem subset_def : s ⊆ t ↔ s.1 ⊆ t.1 := Iff.rfl theorem ssubset_def : s ⊂ t ↔ s ⊆ t ∧ ¬t ⊆ s := Iff.rfl theorem Subset.refl (s : Finset α) : s ⊆ s := Multiset.Subset.refl _ protected theorem Subset.rfl {s : Finset α} : s ⊆ s := Subset.refl _ protected theorem subset_of_eq {s t : Finset α} (h : s = t) : s ⊆ t := h ▸ Subset.refl _ theorem Subset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ := Multiset.Subset.trans theorem Superset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ := fun h' h => Subset.trans h h' theorem mem_of_subset {s₁ s₂ : Finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := Multiset.mem_of_subset theorem notMem_mono {s t : Finset α} (h : s ⊆ t) {a : α} : a ∉ t → a ∉ s := mt <| @h _ @[deprecated (since := "2025-05-23")] alias not_mem_mono := notMem_mono alias not_mem_subset := not_mem_mono theorem Subset.antisymm {s₁ s₂ : Finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ := ext fun a => ⟨@H₁ a, @H₂ a⟩ @[grind =] theorem subset_iff {s₁ s₂ : Finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ := Iff.rfl @[simp, norm_cast] theorem coe_subset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊆ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl @[gcongr] protected alias ⟨_, GCongr.coe_subset_coe⟩ := coe_subset @[simp] theorem val_le_iff {s₁ s₂ : Finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ := le_iff_subset s₁.2 theorem Subset.antisymm_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ := le_antisymm_iff theorem not_subset : ¬s ⊆ t ↔ ∃ x ∈ s, x ∉ t := by simp only [← coe_subset, Set.not_subset, mem_coe] @[simp] theorem le_eq_subset : ((· ≤ ·) : Finset α → Finset α → Prop) = (· ⊆ ·) := rfl @[simp] theorem lt_eq_subset : ((· < ·) : Finset α → Finset α → Prop) = (· ⊂ ·) := rfl theorem le_iff_subset {s₁ s₂ : Finset α} : s₁ ≤ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl theorem lt_iff_ssubset {s₁ s₂ : Finset α} : s₁ < s₂ ↔ s₁ ⊂ s₂ := Iff.rfl @[simp, norm_cast] theorem coe_ssubset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊂ s₂ := show (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊆ s₂ ∧ ¬s₂ ⊆ s₁ by simp only [Set.ssubset_def, Finset.coe_subset] @[simp] theorem val_lt_iff {s₁ s₂ : Finset α} : s₁.1 < s₂.1 ↔ s₁ ⊂ s₂ := and_congr val_le_iff <| not_congr val_le_iff lemma val_strictMono : StrictMono (val : Finset α → Multiset α) := fun _ _ ↦ val_lt_iff.2 @[grind] theorem ssubset_iff_subset_ne {s t : Finset α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne _ _ s t theorem ssubset_iff_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁ ⊂ s₂ ↔ ∃ x ∈ s₂, x ∉ s₁ := Set.ssubset_iff_of_subset h theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_ssubset_of_subset hs₁s₂ hs₂s₃ theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_subset_of_ssubset hs₁s₂ hs₂s₃ theorem exists_of_ssubset {s₁ s₂ : Finset α} (h : s₁ ⊂ s₂) : ∃ x ∈ s₂, x ∉ s₁ := Set.exists_of_ssubset h instance isWellFounded_ssubset : IsWellFounded (Finset α) (· ⊂ ·) := Subrelation.isWellFounded (InvImage _ _) val_lt_iff.2 instance wellFoundedLT : WellFoundedLT (Finset α) := Finset.isWellFounded_ssubset end Subset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans /-! ### Order embedding from `Finset α` to `Set α` -/ /-- Coercion to `Set α` as an `OrderEmbedding`. -/ def coeEmb : Finset α ↪o Set α := ⟨⟨(↑), coe_injective⟩, coe_subset⟩ @[simp] theorem coe_coeEmb : ⇑(coeEmb : Finset α ↪o Set α) = ((↑) : Finset α → Set α) := rfl /-! ### Assorted results These results can be defined using the current imports, but deserve to be given a nicer home. -/ section DecidablePiExists variable {s : Finset α} instance decidableDforallFinset {p : ∀ a ∈ s, Prop} [_hp : ∀ (a) (h : a ∈ s), Decidable (p a h)] : Decidable (∀ (a) (h : a ∈ s), p a h) := Multiset.decidableDforallMultiset instance instDecidableRelSubset [DecidableEq α] : DecidableRel (α := Finset α) (· ⊆ ·) := fun _ _ ↦ decidableDforallFinset instance instDecidableRelSSubset [DecidableEq α] : DecidableRel (α := Finset α) (· ⊂ ·) := fun _ _ ↦ instDecidableAnd instance instDecidableLE [DecidableEq α] : DecidableLE (Finset α) := instDecidableRelSubset instance instDecidableLT [DecidableEq α] : DecidableLT (Finset α) := instDecidableRelSSubset instance decidableDExistsFinset {p : ∀ a ∈ s, Prop} [_hp : ∀ (a) (h : a ∈ s), Decidable (p a h)] : Decidable (∃ (a : _) (h : a ∈ s), p a h) := Multiset.decidableDexistsMultiset instance decidableExistsAndFinset {p : α → Prop} [_hp : ∀ (a), Decidable (p a)] : Decidable (∃ a ∈ s, p a) := decidable_of_iff (∃ (a : _) (_ : a ∈ s), p a) (by simp) instance decidableExistsAndFinsetCoe {p : α → Prop} [DecidablePred p] : Decidable (∃ a ∈ (s : Set α), p a) := decidableExistsAndFinset /-- decidable equality for functions whose domain is bounded by finsets -/ instance decidableEqPiFinset {β : α → Type*} [_h : ∀ a, DecidableEq (β a)] : DecidableEq (∀ a ∈ s, β a) := Multiset.decidableEqPiMultiset end DecidablePiExists end Finset namespace List variable [DecidableEq α] {a : α} {f : α → β} {s : Finset α} {t : Set β} {t' : Finset β} instance [DecidablePred (· ∈ t)] : Decidable (Set.MapsTo f s t) := inferInstanceAs (Decidable (∀ x ∈ s, f x ∈ t)) instance [DecidableEq β] : Decidable (Set.SurjOn f s t') := inferInstanceAs (Decidable (∀ x ∈ t', ∃ y ∈ s, f y = x)) end List namespace Finset section Pairwise variable {s : Finset α} theorem pairwise_subtype_iff_pairwise_finset' (r : β → β → Prop) (f : α → β) : Pairwise (r on fun x : s => f x) ↔ (s : Set α).Pairwise (r on f) := pairwise_subtype_iff_pairwise_set (s : Set α) (r on f) theorem pairwise_subtype_iff_pairwise_finset (r : α → α → Prop) : Pairwise (r on fun x : s => x) ↔ (s : Set α).Pairwise r := pairwise_subtype_iff_pairwise_finset' r id end Pairwise end Finset
ENormedSpace.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.Analysis.Normed.Module.Basic import Mathlib.LinearAlgebra.Basis.VectorSpace /-! # Extended norm **ATTENTION.** This file is deprecated. Mathlib now has classes `ENormed(Add)(Comm)Monoid` for (additive) (commutative) monoids with an `ENorm`: this is very similar to this definition, but much more general. Should the need arise, an enormed version of a normed space can be added later: this will be different from this file. In this file we define a structure `ENormedSpace 𝕜 V` representing an extended norm (i.e., a norm that can take the value `∞`) on a vector space `V` over a normed field `𝕜`. We do not use `class` for an `ENormedSpace` because the same space can have more than one extended norm. For example, the space of measurable functions `f : α → ℝ` has a family of `L_p` extended norms. We prove some basic inequalities, then define * `EMetricSpace` structure on `V` corresponding to `e : ENormedSpace 𝕜 V`; * the subspace of vectors with finite norm, called `e.finiteSubspace`; * a `NormedSpace` structure on this space. The last definition is an instance because the type involves `e`. ## Implementation notes We do not define extended normed groups. They can be added to the chain once someone will need them. ## Tags normed space, extended norm -/ noncomputable section open ENNReal /-- Extended norm on a vector space. As in the case of normed spaces, we require only `‖c • x‖ ≤ ‖c‖ * ‖x‖` in the definition, then prove an equality in `map_smul`. -/ @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] structure ENormedSpace (𝕜 : Type*) (V : Type*) [NormedField 𝕜] [AddCommGroup V] [Module 𝕜 V] where /-- the norm of an ENormedSpace, taking values into `ℝ≥0∞` -/ toFun : V → ℝ≥0∞ eq_zero' : ∀ x, toFun x = 0 → x = 0 map_add_le' : ∀ x y : V, toFun (x + y) ≤ toFun x + toFun y map_smul_le' : ∀ (c : 𝕜) (x : V), toFun (c • x) ≤ ‖c‖₊ * toFun x set_option linter.deprecated false namespace ENormedSpace variable {𝕜 : Type*} {V : Type*} [NormedField 𝕜] [AddCommGroup V] [Module 𝕜 V] (e : ENormedSpace 𝕜 V) attribute [coe] ENormedSpace.toFun instance : CoeFun (ENormedSpace 𝕜 V) fun _ => V → ℝ≥0∞ := ⟨ENormedSpace.toFun⟩ @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem coeFn_injective : Function.Injective ((↑) : ENormedSpace 𝕜 V → V → ℝ≥0∞) := by intro e₁ e₂ h cases e₁ cases e₂ congr @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), ext] theorem ext {e₁ e₂ : ENormedSpace 𝕜 V} (h : ∀ x, e₁ x = e₂ x) : e₁ = e₂ := coeFn_injective <| funext h @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), simp, norm_cast] theorem coe_inj {e₁ e₂ : ENormedSpace 𝕜 V} : (e₁ : V → ℝ≥0∞) = e₂ ↔ e₁ = e₂ := coeFn_injective.eq_iff @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), simp] theorem map_smul (c : 𝕜) (x : V) : e (c • x) = ‖c‖₊ * e x := by apply le_antisymm (e.map_smul_le' c x) by_cases hc : c = 0 · simp [hc] calc (‖c‖₊ : ℝ≥0∞) * e x = ‖c‖₊ * e (c⁻¹ • c • x) := by rw [inv_smul_smul₀ hc] _ ≤ ‖c‖₊ * (‖c⁻¹‖₊ * e (c • x)) := mul_le_mul_left' (e.map_smul_le' _ _) _ _ = e (c • x) := by rw [← mul_assoc, nnnorm_inv, ENNReal.coe_inv, ENNReal.mul_inv_cancel _ ENNReal.coe_ne_top, one_mul] <;> simp [hc] @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), simp] theorem map_zero : e 0 = 0 := by rw [← zero_smul 𝕜 (0 : V), e.map_smul] norm_num @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), simp] theorem eq_zero_iff {x : V} : e x = 0 ↔ x = 0 := ⟨e.eq_zero' x, fun h => h.symm ▸ e.map_zero⟩ @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), simp] theorem map_neg (x : V) : e (-x) = e x := calc e (-x) = ‖(-1 : 𝕜)‖₊ * e x := by rw [← map_smul, neg_one_smul] _ = e x := by simp @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem map_sub_rev (x y : V) : e (x - y) = e (y - x) := by rw [← neg_sub, e.map_neg] @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem map_add_le (x y : V) : e (x + y) ≤ e x + e y := e.map_add_le' x y @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem map_sub_le (x y : V) : e (x - y) ≤ e x + e y := calc e (x - y) = e (x + -y) := by rw [sub_eq_add_neg] _ ≤ e x + e (-y) := e.map_add_le x (-y) _ = e x + e y := by rw [e.map_neg] instance partialOrder : PartialOrder (ENormedSpace 𝕜 V) where le e₁ e₂ := ∀ x, e₁ x ≤ e₂ x le_refl _ _ := le_rfl le_trans _ _ _ h₁₂ h₂₃ x := le_trans (h₁₂ x) (h₂₃ x) le_antisymm _ _ h₁₂ h₂₁ := ext fun x => le_antisymm (h₁₂ x) (h₂₁ x) /-- The `ENormedSpace` sending each non-zero vector to infinity. -/ noncomputable instance : Top (ENormedSpace 𝕜 V) := ⟨{ toFun := fun x => open scoped Classical in if x = 0 then 0 else ⊤ eq_zero' := fun x => by split_ifs <;> simp [*] map_add_le' := fun x y => by split_ifs with hxy hx hy hy hx hy hy <;> try simp [*] simp [hx, hy] at hxy map_smul_le' := fun c x => by split_ifs with hcx hx hx <;> simp only [smul_eq_zero, not_or] at hcx · simp only [mul_zero, le_refl] · have : c = 0 := by tauto simp [this] · tauto · simpa [mul_top'] using hcx.1 }⟩ noncomputable instance : Inhabited (ENormedSpace 𝕜 V) := ⟨⊤⟩ @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem top_map {x : V} (hx : x ≠ 0) : (⊤ : ENormedSpace 𝕜 V) x = ⊤ := if_neg hx noncomputable instance : OrderTop (ENormedSpace 𝕜 V) where top := ⊤ le_top e x := by obtain h | h := eq_or_ne x 0 <;> simp [top_map, h] noncomputable instance : SemilatticeSup (ENormedSpace 𝕜 V) := { ENormedSpace.partialOrder with le := (· ≤ ·) lt := (· < ·) sup := fun e₁ e₂ => { toFun := fun x => max (e₁ x) (e₂ x) eq_zero' := fun _ h => e₁.eq_zero_iff.1 (ENNReal.max_eq_zero_iff.1 h).1 map_add_le' := fun _ _ => max_le (le_trans (e₁.map_add_le _ _) <| add_le_add (le_max_left _ _) (le_max_left _ _)) (le_trans (e₂.map_add_le _ _) <| add_le_add (le_max_right _ _) (le_max_right _ _)) map_smul_le' := fun c x => le_of_eq <| by simp only [map_smul, mul_max] } le_sup_left := fun _ _ _ => le_max_left _ _ le_sup_right := fun _ _ _ => le_max_right _ _ sup_le := fun _ _ _ h₁ h₂ x => max_le (h₁ x) (h₂ x) } @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), simp, norm_cast] theorem coe_max (e₁ e₂ : ENormedSpace 𝕜 V) : ⇑(e₁ ⊔ e₂) = fun x => max (e₁ x) (e₂ x) := rfl @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), norm_cast] theorem max_map (e₁ e₂ : ENormedSpace 𝕜 V) (x : V) : (e₁ ⊔ e₂) x = max (e₁ x) (e₂ x) := rfl /-- Structure of an `EMetricSpace` defined by an extended norm. -/ @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] abbrev emetricSpace : EMetricSpace V where edist x y := e (x - y) edist_self x := by simp eq_of_edist_eq_zero {x y} := by simp [sub_eq_zero] edist_comm := e.map_sub_rev edist_triangle x y z := calc e (x - z) = e (x - y + (y - z)) := by rw [sub_add_sub_cancel] _ ≤ e (x - y) + e (y - z) := e.map_add_le (x - y) (y - z) /-- The subspace of vectors with finite ENormedSpace. -/ @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] def finiteSubspace : Subspace 𝕜 V where carrier := { x | e x < ⊤ } zero_mem' := by simp add_mem' {x y} hx hy := lt_of_le_of_lt (e.map_add_le x y) (ENNReal.add_lt_top.2 ⟨hx, hy⟩) smul_mem' c x (hx : _ < _) := calc e (c • x) = ‖c‖₊ * e x := e.map_smul c x _ < ⊤ := ENNReal.mul_lt_top ENNReal.coe_lt_top hx /-- Metric space structure on `e.finiteSubspace`. We use `EMetricSpace.toMetricSpace` to ensure that this definition agrees with `e.emetricSpace`. -/ instance metricSpace : MetricSpace e.finiteSubspace := by letI := e.emetricSpace refine EMetricSpace.toMetricSpace fun x y => ?_ change e (x - y) ≠ ⊤ exact ne_top_of_le_ne_top (ENNReal.add_lt_top.2 ⟨x.2, y.2⟩).ne (e.map_sub_le x y) @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem finite_dist_eq (x y : e.finiteSubspace) : dist x y = (e (x - y)).toReal := rfl @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem finite_edist_eq (x y : e.finiteSubspace) : edist x y = e (x - y) := rfl /-- Normed group instance on `e.finiteSubspace`. -/ instance normedAddCommGroup : NormedAddCommGroup e.finiteSubspace := { e.metricSpace with norm := fun x => (e x).toReal dist_eq := fun _ _ => rfl } @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem finite_norm_eq (x : e.finiteSubspace) : ‖x‖ = (e x).toReal := rfl /-- Normed space instance on `e.finiteSubspace`. -/ instance normedSpace : NormedSpace 𝕜 e.finiteSubspace where norm_smul_le c x := le_of_eq <| by simp [finite_norm_eq, ENNReal.toReal_mul] end ENormedSpace
CategoryTheory.lean
/- Copyright (c) 2023 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.LinearAlgebra.CliffordAlgebra.Basic import Mathlib.LinearAlgebra.QuadraticForm.QuadraticModuleCat import Mathlib.Algebra.Category.AlgCat.Basic /-! # Category-theoretic interpretations of `CliffordAlgebra` ## Main definitions * `QuadraticModuleCat.cliffordAlgebra`: the functor from quadratic modules to algebras -/ universe v u open CategoryTheory variable {R : Type u} [CommRing R] /-- The "clifford algebra" functor, sending a quadratic `R`-module `V` to the clifford algebra on `V`. This is `CliffordAlgebra.map` through the lens of category theory. -/ @[simps] def QuadraticModuleCat.cliffordAlgebra : QuadraticModuleCat.{u} R ⥤ AlgCat.{u} R where obj M := AlgCat.of R (CliffordAlgebra M.form) map {_M _N} f := AlgCat.ofHom <| CliffordAlgebra.map f.toIsometry map_id _M := by simp map_comp {_M _N _P} f g := by ext; simp
M.lean
/- Copyright (c) 2017 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import Mathlib.Data.PFunctor.Univariate.Basic /-! # M-types M types are potentially infinite tree-like structures. They are defined as the greatest fixpoint of a polynomial functor. -/ universe u uA uB v w open Nat Function open List variable (F : PFunctor.{uA, uB}) namespace PFunctor namespace Approx /-- `CofixA F n` is an `n` level approximation of an M-type -/ inductive CofixA : ℕ → Type (max uA uB) | continue : CofixA 0 | intro {n} : ∀ a, (F.B a → CofixA n) → CofixA (succ n) /-- default inhabitant of `CofixA` -/ protected def CofixA.default [Inhabited F.A] : ∀ n, CofixA F n | 0 => CofixA.continue | succ n => CofixA.intro default fun _ => CofixA.default n instance [Inhabited F.A] {n} : Inhabited (CofixA F n) := ⟨CofixA.default F n⟩ theorem cofixA_eq_zero : ∀ x y : CofixA F 0, x = y | CofixA.continue, CofixA.continue => rfl variable {F} /-- The label of the root of the tree for a non-trivial approximation of the cofix of a pfunctor. -/ def head' : ∀ {n}, CofixA F (succ n) → F.A | _, CofixA.intro i _ => i /-- for a non-trivial approximation, return all the subtrees of the root -/ def children' : ∀ {n} (x : CofixA F (succ n)), F.B (head' x) → CofixA F n | _, CofixA.intro _ f => f theorem approx_eta {n : ℕ} (x : CofixA F (n + 1)) : x = CofixA.intro (head' x) (children' x) := by cases x; rfl /-- Relation between two approximations of the cofix of a pfunctor that state they both contain the same data until one of them is truncated -/ inductive Agree : ∀ {n : ℕ}, CofixA F n → CofixA F (n + 1) → Prop | continu (x : CofixA F 0) (y : CofixA F 1) : Agree x y | intro {n} {a} (x : F.B a → CofixA F n) (x' : F.B a → CofixA F (n + 1)) : (∀ i : F.B a, Agree (x i) (x' i)) → Agree (CofixA.intro a x) (CofixA.intro a x') /-- Given an infinite series of approximations `approx`, `AllAgree approx` states that they are all consistent with each other. -/ def AllAgree (x : ∀ n, CofixA F n) := ∀ n, Agree (x n) (x (succ n)) @[simp] theorem agree_trivial {x : CofixA F 0} {y : CofixA F 1} : Agree x y := by constructor theorem agree_children {n : ℕ} (x : CofixA F (succ n)) (y : CofixA F (succ n + 1)) {i j} (h₀ : i ≍ j) (h₁ : Agree x y) : Agree (children' x i) (children' y j) := by obtain - | ⟨_, _, hagree⟩ := h₁; cases h₀ apply hagree /-- `truncate a` turns `a` into a more limited approximation -/ def truncate : ∀ {n : ℕ}, CofixA F (n + 1) → CofixA F n | 0, CofixA.intro _ _ => CofixA.continue | succ _, CofixA.intro i f => CofixA.intro i <| truncate ∘ f theorem truncate_eq_of_agree {n : ℕ} (x : CofixA F n) (y : CofixA F (succ n)) (h : Agree x y) : truncate y = x := by induction n <;> cases x <;> cases y · rfl · -- cases' h with _ _ _ _ _ h₀ h₁ cases h simp only [truncate, Function.comp_def] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): used to be `ext y` rename_i n_ih a f y h₁ suffices (fun x => truncate (y x)) = f by simp [this] funext y apply n_ih apply h₁ variable {X : Type w} variable (f : X → F X) /-- `sCorec f i n` creates an approximation of height `n` of the final coalgebra of `f` -/ def sCorec : X → ∀ n, CofixA F n | _, 0 => CofixA.continue | j, succ _ => CofixA.intro (f j).1 fun i => sCorec ((f j).2 i) _ theorem P_corec (i : X) (n : ℕ) : Agree (sCorec f i n) (sCorec f i (succ n)) := by induction' n with n n_ih generalizing i constructor obtain ⟨y, g⟩ := f i constructor introv apply n_ih /-- `Path F` provides indices to access internal nodes in `Corec F` -/ def Path (F : PFunctor.{uA, uB}) := List F.Idx instance Path.inhabited : Inhabited (Path F) := ⟨[]⟩ instance CofixA.instSubsingleton : Subsingleton (CofixA F 0) := ⟨by rintro ⟨⟩ ⟨⟩; rfl⟩ theorem head_succ' (n m : ℕ) (x : ∀ n, CofixA F n) (Hconsistent : AllAgree x) : head' (x (succ n)) = head' (x (succ m)) := by suffices ∀ n, head' (x (succ n)) = head' (x 1) by simp [this] clear m n intro n rcases h₀ : x (succ n) with - | ⟨_, f₀⟩ cases h₁ : x 1 dsimp only [head'] induction' n with n n_ih · rw [h₁] at h₀ cases h₀ trivial · have H := Hconsistent (succ n) cases h₂ : x (succ n) rw [h₀, h₂] at H apply n_ih (truncate ∘ f₀) rw [h₂] obtain - | ⟨_, _, hagree⟩ := H congr funext j dsimp only [comp_apply] rw [truncate_eq_of_agree] apply hagree end Approx open Approx /-- Internal definition for `M`. It is needed to avoid name clashes between `M.mk` and `M.casesOn` and the declarations generated for the structure -/ structure MIntl where /-- An `n`-th level approximation, for each depth `n` -/ approx : ∀ n, CofixA F n /-- Each approximation agrees with the next -/ consistent : AllAgree approx /-- For polynomial functor `F`, `M F` is its final coalgebra -/ def M := MIntl F theorem M.default_consistent [Inhabited F.A] : ∀ n, Agree (default : CofixA F n) default | 0 => Agree.continu _ _ | succ n => Agree.intro _ _ fun _ => M.default_consistent n instance M.inhabited [Inhabited F.A] : Inhabited (M F) := ⟨{ approx := default consistent := M.default_consistent _ }⟩ instance MIntl.inhabited [Inhabited F.A] : Inhabited (MIntl F) := show Inhabited (M F) by infer_instance namespace M theorem ext' (x y : M F) (H : ∀ i : ℕ, x.approx i = y.approx i) : x = y := by cases x cases y congr with n apply H variable {X : Type*} variable (f : X → F X) variable {F} /-- Corecursor for the M-type defined by `F`. -/ protected def corec (i : X) : M F where approx := sCorec f i consistent := P_corec _ _ /-- given a tree generated by `F`, `head` gives us the first piece of data it contains -/ def head (x : M F) := head' (x.1 1) /-- return all the subtrees of the root of a tree `x : M F` -/ def children (x : M F) (i : F.B (head x)) : M F := have H := fun n : ℕ => @head_succ' _ n 0 x.1 x.2 { approx := fun n => children' (x.1 _) (cast (congr_arg _ <| by simp only [head, H]) i) consistent := by intro n have P' := x.2 (succ n) apply agree_children _ _ _ P' trans i · apply cast_heq symm apply cast_heq } /-- select a subtree using an `i : F.Idx` or return an arbitrary tree if `i` designates no subtree of `x` -/ def ichildren [Inhabited (M F)] [DecidableEq F.A] (i : F.Idx) (x : M F) : M F := if H' : i.1 = head x then children x (cast (congr_arg _ <| by simp only [head, H']) i.2) else default theorem head_succ (n m : ℕ) (x : M F) : head' (x.approx (succ n)) = head' (x.approx (succ m)) := head_succ' n m _ x.consistent theorem head_eq_head' : ∀ (x : M F) (n : ℕ), head x = head' (x.approx <| n + 1) | ⟨_, h⟩, _ => head_succ' _ _ _ h theorem head'_eq_head : ∀ (x : M F) (n : ℕ), head' (x.approx <| n + 1) = head x | ⟨_, h⟩, _ => head_succ' _ _ _ h theorem truncate_approx (x : M F) (n : ℕ) : truncate (x.approx <| n + 1) = x.approx n := truncate_eq_of_agree _ _ (x.consistent _) /-- unfold an M-type -/ def dest : M F → F (M F) | x => ⟨head x, fun i => children x i⟩ namespace Approx /-- generates the approximations needed for `M.mk` -/ protected def sMk (x : F (M F)) : ∀ n, CofixA F n | 0 => CofixA.continue | succ n => CofixA.intro x.1 fun i => (x.2 i).approx n protected theorem P_mk (x : F (M F)) : AllAgree (Approx.sMk x) | 0 => by constructor | succ n => by constructor introv apply (x.2 i).consistent end Approx /-- constructor for M-types -/ protected def mk (x : F (M F)) : M F where approx := Approx.sMk x consistent := Approx.P_mk x /-- `Agree' n` relates two trees of type `M F` that are the same up to depth `n` -/ inductive Agree' : ℕ → M F → M F → Prop | trivial (x y : M F) : Agree' 0 x y | step {n : ℕ} {a} (x y : F.B a → M F) {x' y'} : x' = M.mk ⟨a, x⟩ → y' = M.mk ⟨a, y⟩ → (∀ i, Agree' n (x i) (y i)) → Agree' (succ n) x' y' @[simp] theorem dest_mk (x : F (M F)) : dest (M.mk x) = x := rfl @[simp] theorem mk_dest (x : M F) : M.mk (dest x) = x := by apply ext' intro n dsimp only [M.mk] induction' n with n · apply @Subsingleton.elim _ CofixA.instSubsingleton dsimp only [Approx.sMk, dest, head] rcases h : x.approx (succ n) with - | ⟨hd, ch⟩ have h' : hd = head' (x.approx 1) := by rw [← head_succ' n, h, head'] apply x.consistent revert ch rw [h'] intros ch h congr ext a dsimp only [children] generalize hh : cast _ a = a'' rw [cast_eq_iff_heq] at hh revert a'' rw [h] intros _ hh cases hh rfl theorem mk_inj {x y : F (M F)} (h : M.mk x = M.mk y) : x = y := by rw [← dest_mk x, h, dest_mk] /-- destructor for M-types -/ protected def cases {r : M F → Sort w} (f : ∀ x : F (M F), r (M.mk x)) (x : M F) : r x := suffices r (M.mk (dest x)) by rw [← mk_dest x] exact this f _ /-- destructor for M-types -/ protected def casesOn {r : M F → Sort w} (x : M F) (f : ∀ x : F (M F), r (M.mk x)) : r x := M.cases f x /-- destructor for M-types, similar to `casesOn` but also gives access directly to the root and subtrees on an M-type -/ protected def casesOn' {r : M F → Sort w} (x : M F) (f : ∀ a f, r (M.mk ⟨a, f⟩)) : r x := M.casesOn x (fun ⟨a, g⟩ => f a g) theorem approx_mk (a : F.A) (f : F.B a → M F) (i : ℕ) : (M.mk ⟨a, f⟩).approx (succ i) = CofixA.intro a fun j => (f j).approx i := rfl @[simp] theorem agree'_refl {n : ℕ} (x : M F) : Agree' n x x := by induction' n with _ n_ih generalizing x <;> induction x using PFunctor.M.casesOn' <;> constructor <;> try rfl intros apply n_ih theorem agree_iff_agree' {n : ℕ} (x y : M F) : Agree (x.approx n) (y.approx <| n + 1) ↔ Agree' n x y := by constructor <;> intro h · induction' n with _ n_ih generalizing x y · constructor · induction x using PFunctor.M.casesOn' induction y using PFunctor.M.casesOn' simp only [approx_mk] at h obtain - | ⟨_, _, hagree⟩ := h constructor <;> try rfl intro i apply n_ih apply hagree · induction' n with _ n_ih generalizing x y · constructor · obtain - | @⟨_, a, x', y'⟩ := h induction' x using PFunctor.M.casesOn' with x_a x_f induction' y using PFunctor.M.casesOn' with y_a y_f simp only [approx_mk] have h_a_1 := mk_inj ‹M.mk ⟨x_a, x_f⟩ = M.mk ⟨a, x'⟩› cases h_a_1 replace h_a_2 := mk_inj ‹M.mk ⟨y_a, y_f⟩ = M.mk ⟨a, y'⟩› cases h_a_2 constructor intro i apply n_ih simp [*] @[simp] theorem cases_mk {r : M F → Sort*} (x : F (M F)) (f : ∀ x : F (M F), r (M.mk x)) : PFunctor.M.cases f (M.mk x) = f x := by dsimp only [M.mk, PFunctor.M.cases, dest, head, Approx.sMk, head'] cases x; dsimp only [Approx.sMk] simp only [Eq.mpr] apply congrFun rfl @[simp] theorem casesOn_mk {r : M F → Sort*} (x : F (M F)) (f : ∀ x : F (M F), r (M.mk x)) : PFunctor.M.casesOn (M.mk x) f = f x := cases_mk x f @[simp] theorem casesOn_mk' {r : M F → Sort*} {a} (x : F.B a → M F) (f : ∀ (a) (f : F.B a → M F), r (M.mk ⟨a, f⟩)) : PFunctor.M.casesOn' (M.mk ⟨a, x⟩) f = f a x := @cases_mk F r ⟨a, x⟩ (fun ⟨a, g⟩ => f a g) /-- `IsPath p x` tells us if `p` is a valid path through `x` -/ inductive IsPath : Path F → M F → Prop | nil (x : M F) : IsPath [] x | cons (xs : Path F) {a} (x : M F) (f : F.B a → M F) (i : F.B a) : x = M.mk ⟨a, f⟩ → IsPath xs (f i) → IsPath (⟨a, i⟩ :: xs) x theorem isPath_cons {xs : Path F} {a a'} {f : F.B a → M F} {i : F.B a'} : IsPath (⟨a', i⟩ :: xs) (M.mk ⟨a, f⟩) → a = a' := by generalize h : M.mk ⟨a, f⟩ = x rintro (_ | ⟨_, _, _, _, rfl, _⟩) cases mk_inj h rfl theorem isPath_cons' {xs : Path F} {a} {f : F.B a → M F} {i : F.B a} : IsPath (⟨a, i⟩ :: xs) (M.mk ⟨a, f⟩) → IsPath xs (f i) := by generalize h : M.mk ⟨a, f⟩ = x rintro (_ | ⟨_, _, _, _, rfl, hp⟩) cases mk_inj h exact hp /-- follow a path through a value of `M F` and return the subtree found at the end of the path if it is a valid path for that value and return a default tree -/ def isubtree [DecidableEq F.A] [Inhabited (M F)] : Path F → M F → M F | [], x => x | ⟨a, i⟩ :: ps, x => PFunctor.M.casesOn' (r := fun _ => M F) x (fun a' f => if h : a = a' then isubtree ps (f <| cast (by rw [h]) i) else default (α := M F) ) /-- similar to `isubtree` but returns the data at the end of the path instead of the whole subtree -/ def iselect [DecidableEq F.A] [Inhabited (M F)] (ps : Path F) : M F → F.A := fun x : M F => head <| isubtree ps x theorem iselect_eq_default [DecidableEq F.A] [Inhabited (M F)] (ps : Path F) (x : M F) (h : ¬IsPath ps x) : iselect ps x = head default := by induction' ps with ps_hd ps_tail ps_ih generalizing x · exfalso apply h constructor · obtain ⟨a, i⟩ := ps_hd induction' x using PFunctor.M.casesOn' with x_a x_f simp only [iselect, isubtree] at ps_ih ⊢ by_cases h'' : a = x_a · subst x_a simp only [dif_pos, casesOn_mk'] rw [ps_ih] intro h' apply h constructor <;> try rfl apply h' · simp [*] @[simp] theorem head_mk (x : F (M F)) : head (M.mk x) = x.1 := Eq.symm <| calc x.1 = (dest (M.mk x)).1 := by rw [dest_mk] _ = head (M.mk x) := rfl theorem children_mk {a} (x : F.B a → M F) (i : F.B (head (M.mk ⟨a, x⟩))) : children (M.mk ⟨a, x⟩) i = x (cast (by rw [head_mk]) i) := by apply ext'; intro n; rfl @[simp] theorem ichildren_mk [DecidableEq F.A] [Inhabited (M F)] (x : F (M F)) (i : F.Idx) : ichildren i (M.mk x) = x.iget i := by dsimp only [ichildren, PFunctor.Obj.iget] congr with h @[simp] theorem isubtree_cons [DecidableEq F.A] [Inhabited (M F)] (ps : Path F) {a} (f : F.B a → M F) {i : F.B a} : isubtree (⟨_, i⟩ :: ps) (M.mk ⟨a, f⟩) = isubtree ps (f i) := by simp only [isubtree, dif_pos, isubtree, M.casesOn_mk']; rfl @[simp] theorem iselect_nil [DecidableEq F.A] [Inhabited (M F)] {a} (f : F.B a → M F) : iselect nil (M.mk ⟨a, f⟩) = a := rfl @[simp] theorem iselect_cons [DecidableEq F.A] [Inhabited (M F)] (ps : Path F) {a} (f : F.B a → M F) {i} : iselect (⟨a, i⟩ :: ps) (M.mk ⟨a, f⟩) = iselect ps (f i) := by simp only [iselect, isubtree_cons] theorem corec_def {X} (f : X → F X) (x₀ : X) : M.corec f x₀ = M.mk (F.map (M.corec f) (f x₀)) := by dsimp only [M.corec, M.mk] congr with n rcases n with - | n · dsimp only [sCorec, Approx.sMk] · dsimp only [sCorec, Approx.sMk] cases f x₀ dsimp only [PFunctor.map] congr theorem ext_aux [Inhabited (M F)] [DecidableEq F.A] {n : ℕ} (x y z : M F) (hx : Agree' n z x) (hy : Agree' n z y) (hrec : ∀ ps : Path F, n = ps.length → iselect ps x = iselect ps y) : x.approx (n + 1) = y.approx (n + 1) := by induction' n with n n_ih generalizing x y z · specialize hrec [] rfl induction x using PFunctor.M.casesOn' induction y using PFunctor.M.casesOn' simp only [iselect_nil] at hrec subst hrec simp only [approx_mk, heq_iff_eq, CofixA.intro.injEq, eq_iff_true_of_subsingleton, and_self] · cases hx cases hy induction x using PFunctor.M.casesOn' induction y using PFunctor.M.casesOn' subst z iterate 3 (have := mk_inj ‹_›; cases this) rename_i n_ih a f₃ f₂ hAgree₂ _ _ h₂ _ _ f₁ h₁ hAgree₁ clr simp only [approx_mk] have := mk_inj h₁ cases this; clear h₁ have := mk_inj h₂ cases this; clear h₂ congr ext i apply n_ih · solve_by_elim · solve_by_elim introv h specialize hrec (⟨_, i⟩ :: ps) (congr_arg _ h) simp only [iselect_cons] at hrec exact hrec theorem ext [Inhabited (M F)] [DecidableEq F.A] (x y : M F) (H : ∀ ps : Path F, iselect ps x = iselect ps y) : x = y := by apply ext'; intro i induction' i with i i_ih · subsingleton · apply ext_aux x y x · rw [← agree_iff_agree'] apply x.consistent · rw [← agree_iff_agree', i_ih] apply y.consistent introv H' dsimp only [iselect] at H cases H' apply H ps section Bisim variable (R : M F → M F → Prop) local infixl:50 " ~ " => R /-- Bisimulation is the standard proof technique for equality between infinite tree-like structures -/ structure IsBisimulation : Prop where /-- The head of the trees are equal -/ head : ∀ {a a'} {f f'}, M.mk ⟨a, f⟩ ~ M.mk ⟨a', f'⟩ → a = a' /-- The tails are equal -/ tail : ∀ {a} {f f' : F.B a → M F}, M.mk ⟨a, f⟩ ~ M.mk ⟨a, f'⟩ → ∀ i : F.B a, f i ~ f' i theorem nth_of_bisim [Inhabited (M F)] [DecidableEq F.A] (bisim : IsBisimulation R) (s₁ s₂) (ps : Path F) : (R s₁ s₂) → IsPath ps s₁ ∨ IsPath ps s₂ → iselect ps s₁ = iselect ps s₂ ∧ ∃ (a : _) (f f' : F.B a → M F), isubtree ps s₁ = M.mk ⟨a, f⟩ ∧ isubtree ps s₂ = M.mk ⟨a, f'⟩ ∧ ∀ i : F.B a, f i ~ f' i := by intro h₀ hh induction' s₁ using PFunctor.M.casesOn' with a f induction' s₂ using PFunctor.M.casesOn' with a' f' obtain rfl : a = a' := bisim.head h₀ induction' ps with i ps ps_ih generalizing a f f' · exists rfl, a, f, f', rfl, rfl apply bisim.tail h₀ obtain ⟨a', i⟩ := i obtain rfl : a = a' := by rcases hh with hh|hh <;> cases isPath_cons hh <;> rfl dsimp only [iselect] at ps_ih ⊢ have h₁ := bisim.tail h₀ i induction' h : f i using PFunctor.M.casesOn' with a₀ f₀ induction' h' : f' i using PFunctor.M.casesOn' with a₁ f₁ simp only [h, h', isubtree_cons] at ps_ih ⊢ rw [h, h'] at h₁ obtain rfl : a₀ = a₁ := bisim.head h₁ apply ps_ih _ _ _ h₁ rw [← h, ← h'] apply Or.imp isPath_cons' isPath_cons' hh theorem eq_of_bisim [Nonempty (M F)] (bisim : IsBisimulation R) : ∀ s₁ s₂, R s₁ s₂ → s₁ = s₂ := by inhabit M F classical introv Hr; apply ext introv by_cases h : IsPath ps s₁ ∨ IsPath ps s₂ · have H := nth_of_bisim R bisim _ _ ps Hr h exact H.left · rw [not_or] at h obtain ⟨h₀, h₁⟩ := h simp only [iselect_eq_default, *, not_false_iff] end Bisim universe u' v' /-- corecursor for `M F` with swapped arguments -/ def corecOn {X : Type*} (x₀ : X) (f : X → F X) : M F := M.corec f x₀ variable {P : PFunctor.{uA, uB}} {α : Type*} theorem dest_corec (g : α → P α) (x : α) : M.dest (M.corec g x) = P.map (M.corec g) (g x) := by rw [corec_def, dest_mk] theorem bisim (R : M P → M P → Prop) (h : ∀ x y, R x y → ∃ a f f', M.dest x = ⟨a, f⟩ ∧ M.dest y = ⟨a, f'⟩ ∧ ∀ i, R (f i) (f' i)) : ∀ x y, R x y → x = y := by introv h' haveI := Inhabited.mk x.head apply eq_of_bisim R _ _ _ h'; clear h' x y constructor <;> introv ih <;> rcases h _ _ ih with ⟨a'', g, g', h₀, h₁, h₂⟩ <;> clear h · replace h₀ := congr_arg Sigma.fst h₀ replace h₁ := congr_arg Sigma.fst h₁ simp only [dest_mk] at h₀ h₁ rw [h₀, h₁] · simp only [dest_mk] at h₀ h₁ cases h₀ cases h₁ apply h₂ theorem bisim' {α : Type*} (Q : α → Prop) (u v : α → M P) (h : ∀ x, Q x → ∃ a f f', M.dest (u x) = ⟨a, f⟩ ∧ M.dest (v x) = ⟨a, f'⟩ ∧ ∀ i, ∃ x', Q x' ∧ f i = u x' ∧ f' i = v x') : ∀ x, Q x → u x = v x := fun x Qx => let R := fun w z : M P => ∃ x', Q x' ∧ w = u x' ∧ z = v x' @M.bisim P R (fun _ _ ⟨x', Qx', xeq, yeq⟩ => let ⟨a, f, f', ux'eq, vx'eq, h'⟩ := h x' Qx' ⟨a, f, f', xeq.symm ▸ ux'eq, yeq.symm ▸ vx'eq, h'⟩) _ _ ⟨x, Qx, rfl, rfl⟩ -- for the record, show M_bisim follows from _bisim' theorem bisim_equiv (R : M P → M P → Prop) (h : ∀ x y, R x y → ∃ a f f', M.dest x = ⟨a, f⟩ ∧ M.dest y = ⟨a, f'⟩ ∧ ∀ i, R (f i) (f' i)) : ∀ x y, R x y → x = y := fun x y Rxy => let Q : M P × M P → Prop := fun p => R p.fst p.snd bisim' Q Prod.fst Prod.snd (fun p Qp => let ⟨a, f, f', hx, hy, h'⟩ := h p.fst p.snd Qp ⟨a, f, f', hx, hy, fun i => ⟨⟨f i, f' i⟩, h' i, rfl, rfl⟩⟩) ⟨x, y⟩ Rxy theorem corec_unique (g : α → P α) (f : α → M P) (hyp : ∀ x, M.dest (f x) = P.map f (g x)) : f = M.corec g := by ext x apply bisim' (fun _ => True) _ _ _ _ trivial clear x intro x _ rcases gxeq : g x with ⟨a, f'⟩ have h₀ : M.dest (f x) = ⟨a, f ∘ f'⟩ := by rw [hyp, gxeq, PFunctor.map_eq] have h₁ : M.dest (M.corec g x) = ⟨a, M.corec g ∘ f'⟩ := by rw [dest_corec, gxeq, PFunctor.map_eq] refine ⟨_, _, _, h₀, h₁, ?_⟩ intro i exact ⟨f' i, trivial, rfl, rfl⟩ /-- corecursor where the state of the computation can be sent downstream in the form of a recursive call -/ def corec₁ {α : Type u} (F : ∀ X, (α → X) → α → P X) : α → M P := M.corec (F _ id) /-- corecursor where it is possible to return a fully formed value at any point of the computation -/ def corec' {α : Type u} (F : ∀ {X : Type (max u uA uB)}, (α → X) → α → M P ⊕ P X) (x : α) : M P := corec₁ (fun _ rec (a : M P ⊕ α) => let y := Sum.bind a (F (rec ∘ Sum.inr)) match y with | Sum.inr y => y | Sum.inl y => P.map (rec ∘ Sum.inl) (M.dest y)) (@Sum.inr (M P) _ x) end M end PFunctor
Resolution.lean
/- Copyright (c) 2022 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.Algebra.Category.ModuleCat.Projective import Mathlib.AlgebraicTopology.ExtraDegeneracy import Mathlib.CategoryTheory.Abelian.Ext import Mathlib.RepresentationTheory.Rep import Mathlib.CategoryTheory.Functor.ReflectsIso.Balanced /-! # The standard and bar resolutions of `k` as a trivial `k`-linear `G`-representation Given a commutative ring `k` and a group `G`, this file defines two projective resolutions of `k` as a trivial `k`-linear `G`-representation. The first one, the standard resolution, has objects `k[Gⁿ⁺¹]` equipped with the diagonal representation, and differential defined by `(g₀, ..., gₙ) ↦ ∑ (-1)ⁱ • (g₀, ..., ĝᵢ, ..., gₙ)`. We define this as the alternating face map complex associated to an appropriate simplicial `k`-linear `G`-representation. This simplicial object is the `linearization` of the simplicial `G`-set given by the universal cover of the classifying space of `G`, `EG`. We prove this simplicial `G`-set `EG` is isomorphic to the Čech nerve of the natural arrow of `G`-sets `G ⟶ {pt}`. We then use this isomorphism to deduce that as a complex of `k`-modules, the standard resolution of `k` as a trivial `G`-representation is homotopy equivalent to the complex with `k` at 0 and 0 elsewhere. Putting this material together allows us to define `Rep.standardResolution`, the standard projective resolution of `k` as a trivial `k`-linear `G`-representation. We then construct the bar resolution. The `n`th object in this complex is the representation on `Gⁿ →₀ k[G]` defined pointwise by the left regular representation on `k[G]`. The differentials are defined by sending `(g₀, ..., gₙ)` to `g₀·(g₁, ..., gₙ) + ∑ (-1)ʲ⁺¹·(g₀, ..., gⱼgⱼ₊₁, ..., gₙ) + (-1)ⁿ⁺¹·(g₀, ..., gₙ₋₁)` for `j = 0, ... , n - 1`. In `RepresentationTheory.Rep` we define an isomorphism `Rep.diagonalSuccIsoFree` between `k[Gⁿ⁺¹] ≅ (Gⁿ →₀ k[G])` sending `(g₀, ..., gₙ) ↦ g₀·(g₀⁻¹g₁, ..., gₙ₋₁⁻¹gₙ)`. We show that this isomorphism defines a commutative square with the bar resolution differential and the standard resolution differential, and thus conclude that the bar resolution differential squares to zero and that `Rep.diagonalSuccIsoFree` defines an isomorphism between the two complexes. We carry the exactness properties across this isomorphism to conclude the bar resolution is a projective resolution too, in `Rep.barResolution`. In `RepresentationTheory/Homological/Group(Co)homology/Basic.lean`, we then use `Rep.barResolution` to define the inhomogeneous (co)chains of a representation, useful for computing group (co)homology. ## Main definitions * `groupCohomology.resolution.ofMulActionBasis` * `classifyingSpaceUniversalCover` * `Rep.standardComplex.forget₂ToModuleCatHomotopyEquiv` * `Rep.standardResolution` -/ suppress_compilation noncomputable section universe u v w variable {k G : Type u} [CommRing k] {n : ℕ} open CategoryTheory Finsupp local notation "Gⁿ" => Fin n → G set_option quotPrecheck false local notation "Gⁿ⁺¹" => Fin (n + 1) → G namespace groupCohomology.resolution open Finsupp hiding lift open MonoidalCategory open Fin (partialProd) section Basis variable (k G n) [Group G] open scoped TensorProduct open Representation @[deprecated (since := "2025-06-02")] alias groupCohomology.resolution.actionDiagonalSucc := Action.diagonalSuccIsoTensorTrivial @[deprecated (since := "2025-06-02")] alias groupCohomology.resolution.actionDiagonalSucc_hom_apply := Action.diagonalSuccIsoTensorTrivial_hom_hom_apply @[deprecated (since := "2025-06-02")] alias groupCohomology.resolution.actionDiagonalSucc_inv_apply := Action.diagonalSuccIsoTensorTrivial_inv_hom_apply @[deprecated (since := "2025-06-02")] alias groupCohomology.resolution.diagonalSucc := Rep.diagonalSuccIsoTensorTrivial @[deprecated (since := "2025-06-02")] alias groupCohomology.resolution.diagonalSucc_hom_single := Rep.diagonalSuccIsoTensorTrivial_hom_hom_single @[deprecated (since := "2025-06-02")] alias groupCohomology.resolution.diagonalSucc_inv_single_single := Rep.diagonalSuccIsoTensorTrivial_inv_hom_single_single @[deprecated (since := "2025-06-02")] alias groupCohomology.resolution.diagonalSucc_inv_single_left := Rep.diagonalSuccIsoTensorTrivial_inv_hom_single_left @[deprecated (since := "2025-06-02")] alias groupCohomology.resolution.diagonalSucc_inv_single_right := Rep.diagonalSuccIsoTensorTrivial_inv_hom_single_right /-- The `k[G]`-linear isomorphism `k[G] ⊗ₖ k[Gⁿ] ≃ k[Gⁿ⁺¹]`, where the `k[G]`-module structure on the lefthand side is `TensorProduct.leftModule`, whilst that of the righthand side comes from `Representation.asModule`. Allows us to use `Algebra.TensorProduct.basis` to get a `k[G]`-basis of the righthand side. -/ @[deprecated "We now favour `Representation.finsuppLEquivFreeAsModule`" (since := "2025-06-04")] def ofMulActionBasisAux : MonoidAlgebra k G ⊗[k] ((Fin n → G) →₀ k) ≃ₗ[MonoidAlgebra k G] (ofMulAction k G (Fin (n + 1) → G)).asModule := haveI e := (Rep.equivalenceModuleMonoidAlgebra.1.mapIso (Rep.diagonalSuccIsoTensorTrivial k G n).symm).toLinearEquiv { e with map_smul' := fun r x => by rw [RingHom.id_apply, LinearEquiv.toFun_eq_coe, ← LinearEquiv.map_smul e] congr 1 /- Porting note (https://github.com/leanprover-community/mathlib4/issues/11039): broken proof was refine' x.induction_on _ (fun x y => _) fun y z hy hz => _ · simp only [smul_zero] · simp only [TensorProduct.smul_tmul'] show (r * x) ⊗ₜ y = _ rw [← ofMulAction_self_smul_eq_mul, smul_tprod_one_asModule] · rw [smul_add, hz, hy, smul_add] -/ change _ = Representation.asAlgebraHom (tensorObj (Rep.leftRegular k G) (Rep.trivial k G ((Fin n → G) →₀ k))).ρ r _ refine x.induction_on ?_ (fun x y => ?_) fun y z hy hz => ?_ · rw [smul_zero, map_zero] · rw [TensorProduct.smul_tmul', smul_eq_mul, ← ofMulAction_self_smul_eq_mul] exact (smul_tprod_one_asModule (Representation.ofMulAction k G G) r x y).symm · rw [smul_add, hz, hy, map_add] } /-- A `k[G]`-basis of `k[Gⁿ⁺¹]`, coming from the `k[G]`-linear isomorphism `k[G] ⊗ₖ k[Gⁿ] ≃ k[Gⁿ⁺¹].` -/ @[deprecated "We now favour `Representation.freeAsModuleBasis`; the old definition can be derived from this and `Rep.diagonalSuccIsoFree" (since := "2025-06-05")] alias ofMulActionBasis := Representation.freeAsModuleBasis @[deprecated "We now favour `Representation.free_asModule_free`; the old theorem can be derived from this and `Rep.diagonalSuccIsoFree" (since := "2025-06-05")] alias ofMulAction_free := Representation.free_asModule_free end Basis end groupCohomology.resolution variable (G) /-- The simplicial `G`-set sending `[n]` to `Gⁿ⁺¹` equipped with the diagonal action of `G`. -/ @[simps obj map] def classifyingSpaceUniversalCover [Monoid G] : SimplicialObject (Action (Type u) G) where obj n := Action.ofMulAction G (Fin (n.unop.len + 1) → G) map f := { hom := fun x => x ∘ f.unop.toOrderHom comm := fun _ => rfl } map_id _ := rfl map_comp _ _ := rfl namespace classifyingSpaceUniversalCover open CategoryTheory.Limits variable [Monoid G] /-- When the category is `G`-Set, `cechNerveTerminalFrom` of `G` with the left regular action is isomorphic to `EG`, the universal cover of the classifying space of `G` as a simplicial `G`-set. -/ def cechNerveTerminalFromIso : cechNerveTerminalFrom (Action.ofMulAction G G) ≅ classifyingSpaceUniversalCover G := NatIso.ofComponents (fun _ => limit.isoLimitCone (Action.ofMulActionLimitCone _ _)) fun f => by refine IsLimit.hom_ext (Action.ofMulActionLimitCone.{u, 0} G fun _ => G).2 fun j => ?_ dsimp only [cechNerveTerminalFrom, Pi.lift] rw [Category.assoc, limit.isoLimitCone_hom_π, limit.lift_π, Category.assoc] exact (limit.isoLimitCone_hom_π _ _).symm /-- As a simplicial set, `cechNerveTerminalFrom` of a monoid `G` is isomorphic to the universal cover of the classifying space of `G` as a simplicial set. -/ def cechNerveTerminalFromIsoCompForget : cechNerveTerminalFrom G ≅ classifyingSpaceUniversalCover G ⋙ forget _ := NatIso.ofComponents (fun _ => Types.productIso _) fun _ => Matrix.ext fun _ _ => Types.Limit.lift_π_apply (Discrete.functor fun _ ↦ G) _ _ _ variable (k) open AlgebraicTopology SimplicialObject.Augmented SimplicialObject CategoryTheory.Arrow /-- The universal cover of the classifying space of `G` as a simplicial set, augmented by the map from `Fin 1 → G` to the terminal object in `Type u`. -/ def compForgetAugmented : SimplicialObject.Augmented (Type u) := SimplicialObject.augment (classifyingSpaceUniversalCover G ⋙ forget _) (terminal _) (terminal.from _) fun _ _ _ => Subsingleton.elim _ _ /-- The augmented Čech nerve of the map from `Fin 1 → G` to the terminal object in `Type u` has an extra degeneracy. -/ def extraDegeneracyAugmentedCechNerve : ExtraDegeneracy (Arrow.mk <| terminal.from G).augmentedCechNerve := AugmentedCechNerve.extraDegeneracy (Arrow.mk <| terminal.from G) ⟨fun _ => (1 : G), @Subsingleton.elim _ (@Unique.instSubsingleton _ (Limits.uniqueToTerminal _)) _ _⟩ /-- The universal cover of the classifying space of `G` as a simplicial set, augmented by the map from `Fin 1 → G` to the terminal object in `Type u`, has an extra degeneracy. -/ def extraDegeneracyCompForgetAugmented : ExtraDegeneracy (compForgetAugmented G) := by refine ExtraDegeneracy.ofIso (?_ : (Arrow.mk <| terminal.from G).augmentedCechNerve ≅ _) (extraDegeneracyAugmentedCechNerve G) exact Comma.isoMk (CechNerveTerminalFrom.iso G ≪≫ cechNerveTerminalFromIsoCompForget G) (Iso.refl _) (by ext : 1; exact IsTerminal.hom_ext terminalIsTerminal _ _) /-- The free functor `Type u ⥤ ModuleCat.{u} k` applied to the universal cover of the classifying space of `G` as a simplicial set, augmented by the map from `Fin 1 → G` to the terminal object in `Type u`. -/ def compForgetAugmented.toModule : SimplicialObject.Augmented (ModuleCat.{u} k) := ((SimplicialObject.Augmented.whiskering _ _).obj (ModuleCat.free k)).obj (compForgetAugmented G) /-- If we augment the universal cover of the classifying space of `G` as a simplicial set by the map from `Fin 1 → G` to the terminal object in `Type u`, then apply the free functor `Type u ⥤ ModuleCat.{u} k`, the resulting augmented simplicial `k`-module has an extra degeneracy. -/ def extraDegeneracyCompForgetAugmentedToModule : ExtraDegeneracy (compForgetAugmented.toModule k G) := ExtraDegeneracy.map (extraDegeneracyCompForgetAugmented G) (ModuleCat.free k) end classifyingSpaceUniversalCover variable (k) /-- The standard resolution of `k` as a trivial representation, defined as the alternating face map complex of a simplicial `k`-linear `G`-representation. -/ def Rep.standardComplex [Monoid G] := (AlgebraicTopology.alternatingFaceMapComplex (Rep k G)).obj (classifyingSpaceUniversalCover G ⋙ linearization k G) @[deprecated (since := "2025-06-06")] alias groupCohomology.resolution := Rep.standardComplex namespace Rep.standardComplex open classifyingSpaceUniversalCover AlgebraicTopology CategoryTheory.Limits variable [Monoid G] /-- The `k`-linear map underlying the differential in the standard resolution of `k` as a trivial `k`-linear `G`-representation. It sends `(g₀, ..., gₙ) ↦ ∑ (-1)ⁱ • (g₀, ..., ĝᵢ, ..., gₙ)`. -/ def d (G : Type u) (n : ℕ) : ((Fin (n + 1) → G) →₀ k) →ₗ[k] (Fin n → G) →₀ k := Finsupp.lift ((Fin n → G) →₀ k) k (Fin (n + 1) → G) fun g => (@Finset.univ (Fin (n + 1)) _).sum fun p => Finsupp.single (g ∘ p.succAbove) ((-1 : k) ^ (p : ℕ)) variable {k G} @[simp] theorem d_of {G : Type u} {n : ℕ} (c : Fin (n + 1) → G) : d k G n (Finsupp.single c 1) = Finset.univ.sum fun p : Fin (n + 1) => Finsupp.single (c ∘ p.succAbove) ((-1 : k) ^ (p : ℕ)) := by simp [d] variable (k G) /-- The `n`th object of the standard resolution of `k` is definitionally isomorphic to `k[Gⁿ⁺¹]` equipped with the representation induced by the diagonal action of `G`. -/ def xIso (n : ℕ) : (standardComplex k G).X n ≅ Rep.ofMulAction k G (Fin (n + 1) → G) := Iso.refl _ instance x_projective (G : Type u) [Group G] [DecidableEq G] (n : ℕ) : Projective ((standardComplex k G).X n) := inferInstanceAs <| Projective (Rep.diagonal k G (n + 1)) /-- Simpler expression for the differential in the standard resolution of `k` as a `G`-representation. It sends `(g₀, ..., gₙ₊₁) ↦ ∑ (-1)ⁱ • (g₀, ..., ĝᵢ, ..., gₙ₊₁)`. -/ theorem d_eq (n : ℕ) : ((standardComplex k G).d (n + 1) n).hom = ModuleCat.ofHom (d k G (n + 1)) := by refine ModuleCat.hom_ext <| Finsupp.lhom_ext' fun (x : Fin (n + 2) → G) => LinearMap.ext_ring ?_ simp [Action.ofMulAction_V, standardComplex, SimplicialObject.δ, ← Int.cast_smul_eq_zsmul k ((-1) ^ _ : ℤ), SimplexCategory.δ, Fin.succAboveOrderEmb] section Exactness /-- The standard resolution of `k` as a trivial representation as a complex of `k`-modules. -/ def forget₂ToModuleCat := ((forget₂ (Rep k G) (ModuleCat.{u} k)).mapHomologicalComplex _).obj (standardComplex k G) /-- If we apply the free functor `Type u ⥤ ModuleCat.{u} k` to the universal cover of the classifying space of `G` as a simplicial set, then take the alternating face map complex, the result is isomorphic to the standard resolution of the trivial `G`-representation `k` as a complex of `k`-modules. -/ def compForgetAugmentedIso : AlternatingFaceMapComplex.obj (SimplicialObject.Augmented.drop.obj (compForgetAugmented.toModule k G)) ≅ standardComplex.forget₂ToModuleCat k G := eqToIso (Functor.congr_obj (map_alternatingFaceMapComplex (forget₂ (Rep k G) (ModuleCat.{u} k))).symm (classifyingSpaceUniversalCover G ⋙ linearization k G)) /-- As a complex of `k`-modules, the standard resolution of the trivial `G`-representation `k` is homotopy equivalent to the complex which is `k` at 0 and 0 elsewhere. -/ def forget₂ToModuleCatHomotopyEquiv : HomotopyEquiv (standardComplex.forget₂ToModuleCat k G) ((ChainComplex.single₀ (ModuleCat k)).obj ((forget₂ (Rep k G) _).obj <| Rep.trivial k G k)) := (HomotopyEquiv.ofIso (compForgetAugmentedIso k G).symm).trans <| (SimplicialObject.Augmented.ExtraDegeneracy.homotopyEquiv (extraDegeneracyCompForgetAugmentedToModule k G)).trans (HomotopyEquiv.ofIso <| (ChainComplex.single₀ (ModuleCat.{u} k)).mapIso (@Finsupp.LinearEquiv.finsuppUnique k k _ _ _ (⊤_ Type u) Types.terminalIso.toEquiv.unique).toModuleIso) /-- The hom of `k`-linear `G`-representations `k[G¹] → k` sending `∑ nᵢgᵢ ↦ ∑ nᵢ`. -/ def ε : Rep.ofMulAction k G (Fin 1 → G) ⟶ Rep.trivial k G k where hom := ModuleCat.ofHom <| Finsupp.linearCombination _ fun _ => (1 : k) comm _ := ModuleCat.hom_ext <| Finsupp.lhom_ext' fun _ => LinearMap.ext_ring (by simp [ModuleCat.endRingEquiv]) /-- The homotopy equivalence of complexes of `k`-modules between the standard resolution of `k` as a trivial `G`-representation, and the complex which is `k` at 0 and 0 everywhere else, acts as `∑ nᵢgᵢ ↦ ∑ nᵢ : k[G¹] → k` at 0. -/ theorem forget₂ToModuleCatHomotopyEquiv_f_0_eq : (forget₂ToModuleCatHomotopyEquiv k G).1.f 0 = (forget₂ (Rep k G) _).map (ε k G) := by refine ModuleCat.hom_ext <| Finsupp.lhom_ext fun (x : Fin 1 → G) r => ?_ change mapDomain _ _ _ = Finsupp.linearCombination _ _ _ simp only [HomotopyEquiv.ofIso, Iso.symm_hom, compForgetAugmented, compForgetAugmentedIso, eqToIso.inv, HomologicalComplex.eqToHom_f] change mapDomain _ (single x r) _ = _ simp [Unique.eq_default (terminal.from _), single_apply, if_pos (Subsingleton.elim _ _)] theorem d_comp_ε : (standardComplex k G).d 1 0 ≫ ε k G = 0 := by ext : 3 have : (forget₂ToModuleCat k G).d 1 0 ≫ (forget₂ (Rep k G) (ModuleCat.{u} k)).map (ε k G) = 0 := by rw [← forget₂ToModuleCatHomotopyEquiv_f_0_eq, ← (forget₂ToModuleCatHomotopyEquiv k G).1.2 1 0 rfl] exact comp_zero exact LinearMap.ext_iff.1 (ModuleCat.hom_ext_iff.mp this) _ /-- The chain map from the standard resolution of `k` to `k[0]` given by `∑ nᵢgᵢ ↦ ∑ nᵢ` in degree zero. -/ def εToSingle₀ : standardComplex k G ⟶ (ChainComplex.single₀ _).obj (Rep.trivial k G k) := ((standardComplex k G).toSingle₀Equiv _).symm ⟨ε k G, d_comp_ε k G⟩ theorem εToSingle₀_comp_eq : ((forget₂ _ (ModuleCat.{u} k)).mapHomologicalComplex _).map (εToSingle₀ k G) ≫ (HomologicalComplex.singleMapHomologicalComplex _ _ _).hom.app _ = (forget₂ToModuleCatHomotopyEquiv k G).hom := by dsimp ext1 simpa using (forget₂ToModuleCatHomotopyEquiv_f_0_eq k G).symm theorem quasiIso_forget₂_εToSingle₀ : QuasiIso (((forget₂ _ (ModuleCat.{u} k)).mapHomologicalComplex _).map (εToSingle₀ k G)) := by have h : QuasiIso (forget₂ToModuleCatHomotopyEquiv k G).hom := inferInstance rw [← εToSingle₀_comp_eq k G] at h exact quasiIso_of_comp_right (hφφ' := h) instance : QuasiIso (εToSingle₀ k G) := by rw [← HomologicalComplex.quasiIso_map_iff_of_preservesHomology _ (forget₂ _ (ModuleCat.{u} k))] apply quasiIso_forget₂_εToSingle₀ end Exactness end standardComplex open HomologicalComplex.Hom standardComplex variable [Group G] [DecidableEq G] /-- The standard projective resolution of `k` as a trivial `k`-linear `G`-representation. -/ def standardResolution : ProjectiveResolution (Rep.trivial k G k) where complex := standardComplex k G π := εToSingle₀ k G @[deprecated (since := "2025-06-06")] alias groupCohomology.projectiveResolution := Rep.standardResolution /-- Given a `k`-linear `G`-representation `V`, `Extⁿ(k, V)` (where `k` is a trivial `k`-linear `G`-representation) is isomorphic to the `n`th cohomology group of `Hom(P, V)`, where `P` is the standard resolution of `k` called `standardComplex k G`. -/ def standardResolution.extIso (V : Rep k G) (n : ℕ) : ((Ext k (Rep k G) n).obj (Opposite.op <| Rep.trivial k G k)).obj V ≅ ((standardComplex k G).linearYonedaObj k V).homology n := (standardResolution k G).isoExt n V @[deprecated (since := "2025-06-06")] alias groupCohomology.extIso := Rep.standardResolution.extIso namespace barComplex open Rep Finsupp variable (n) /-- The differential from `Gⁿ⁺¹ →₀ k[G]` to `Gⁿ →₀ k[G]` in the bar resolution of `k` as a trivial `k`-linear `G`-representation. It sends `(g₀, ..., gₙ)` to `g₀·(g₁, ..., gₙ) + ∑ (-1)ʲ⁺¹·(g₀, ..., gⱼgⱼ₊₁, ..., gₙ) + (-1)ⁿ⁺¹·(g₀, ..., gₙ₋₁)` for `j = 0, ... , n - 1`. -/ def d : free k G Gⁿ⁺¹ ⟶ free k G Gⁿ := freeLift _ fun g => single (fun i => g i.succ) (single (g 0) 1) + Finset.univ.sum fun j : Fin (n + 1) => single (Fin.contractNth j (· * ·) g) (single (1 : G) ((-1 : k) ^ ((j : ℕ) + 1))) variable {k G} in lemma d_single (x : Gⁿ⁺¹) : (d k G n).hom (single x (single 1 1)) = single (fun i => x i.succ) (Finsupp.single (x 0) 1) + Finset.univ.sum fun j : Fin (n + 1) => single (Fin.contractNth j (· * ·) x) (single (1 : G) ((-1 : k) ^ ((j : ℕ) + 1))) := by simp [d] lemma d_comp_diagonalSuccIsoFree_inv_eq : d k G n ≫ (diagonalSuccIsoFree k G n).inv = (diagonalSuccIsoFree k G (n + 1)).inv ≫ (standardComplex k G).d (n + 1) n := free_ext _ _ fun i => by simpa [diagonalSuccIsoFree_inv_hom_single_single (k := k), d_single (k := k), standardComplex.d_eq, standardComplex.d_of (k := k) (Fin.partialProd i), Fin.sum_univ_succ, Fin.partialProd_contractNth] using congr(single $(by ext j; exact (Fin.partialProd_succ' i j).symm) 1) end barComplex open barComplex /-- The projective resolution of `k` as a trivial `k`-linear `G`-representation with `n`th differential `(Gⁿ⁺¹ →₀ k[G]) → (Gⁿ →₀ k[G])` sending `(g₀, ..., gₙ)` to `g₀·(g₁, ..., gₙ) + ∑ (-1)ʲ⁺¹·(g₀, ..., gⱼgⱼ₊₁, ..., gₙ) + (-1)ⁿ⁺¹·(g₀, ..., gₙ₋₁)` for `j = 0, ... , n - 1`. -/ noncomputable abbrev barComplex : ChainComplex (Rep k G) ℕ := ChainComplex.of (fun n => free k G (Fin n → G)) (fun n => d k G n) fun _ => by ext x simp [(diagonalSuccIsoFree k G _).comp_inv_eq.1 (d_comp_diagonalSuccIsoFree_inv_eq k G _)] namespace barComplex @[simp] theorem d_def : (barComplex k G).d (n + 1) n = d k G n := ChainComplex.of_d _ _ _ _ /-- Isomorphism between the bar resolution and standard resolution, with `n`th map `(Gⁿ →₀ k[G]) → k[Gⁿ⁺¹]` sending `(g₁, ..., gₙ) ↦ (1, g₁, g₁g₂, ..., g₁...gₙ)`. -/ def isoStandardComplex : barComplex k G ≅ standardComplex k G := HomologicalComplex.Hom.isoOfComponents (fun i => (diagonalSuccIsoFree k G i).symm) fun i j => by rintro (rfl : j + 1 = i) simp only [ChainComplex.of_x, Iso.symm_hom, d_def, d_comp_diagonalSuccIsoFree_inv_eq] end barComplex /-- The chain complex `barComplex k G` as a projective resolution of `k` as a trivial `k`-linear `G`-representation. -/ @[simps complex] def barResolution : ProjectiveResolution (Rep.trivial k G k) where complex := barComplex k G projective n := inferInstanceAs <| Projective (free k G (Fin n → G)) π := (isoStandardComplex k G).hom ≫ standardComplex.εToSingle₀ k G /-- Given a `k`-linear `G`-representation `V`, `Extⁿ(k, V)` (where `k` is the trivial `k`-linear `G`-representation) is isomorphic to the `n`th cohomology group of `Hom(P, V)`, where `P` is the bar resolution of `k`. -/ def barResolution.extIso (V : Rep k G) (n : ℕ) : ((Ext k (Rep k G) n).obj (Opposite.op <| Rep.trivial k G k)).obj V ≅ ((barComplex k G).linearYonedaObj k V).homology n := (barResolution k G).isoExt n V end Rep
finfield.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 div tuple bigop prime finset fingroup. From mathcomp Require Import ssralg poly polydiv morphism action countalg. From mathcomp Require Import finalg zmodp cyclic center pgroup abelian matrix. From mathcomp Require Import mxpoly vector falgebra fieldext separable galois. From mathcomp Require ssrnum ssrint archimedean algC cyclotomic. (******************************************************************************) (* Additional constructions and results on finite fields *) (* *) (* FinFieldExtType L == a FinFieldType structure on the carrier of L, *) (* where L IS a fieldExtType F structure for an *) (* F that has a finFieldType structure. This *) (* does not take any existing finType structure *) (* on L; this should not be made canonical *) (* FinSplittingFieldType F L == a SplittingFieldType F structure on the *) (* carrier of L, where L IS a fieldExtType F for *) (* an F with a finFieldType structure; this *) (* should not be made canonical *) (* finvect_type vT == alias of vT : vecType R equipped with *) (* canonical instances for finType, finNzRing, *) (* etc structures (including FinFieldExtType *) (* above) for abstract vectType, falgType and *) (* fieldExtType over a finFieldType *) (* pPrimeCharType pcharRp == the carrier of a nzRingType R such that *) (* pcharRp : p \in [pchar R] holds. This type has*) (* canonical nzRingType, ..., fieldType *) (* structures compatible with those of R, as well*) (* as canonical lmodType 'F_p, ..., algType 'F_p *) (* structures, plus an falgType structure if R *) (* is a finUnitRingType and a splittingFieldType *) (* structure if R is a finFieldType *) (* FinSplittingFieldFor nz_p == sigma-pair whose sval is a splittingFieldType *) (* that is the splitting field for p : {poly F} *) (* over F : finFieldType, given nz_p : p != 0 *) (* PrimePowerField pr_p k_gt0 == sigma2-triple whose s2val is a finFieldType *) (* of characteristic p and order m = p ^ k, *) (* given pr_p : prime p and k_gt0 : k > 0 *) (* FinDomainFieldType domR == a finFieldType structure on a finUnitRingType *) (* R, given domR : GRing.IntegralDomain.axiom R. *) (* This is intended to be used inside proofs, *) (* where one cannot declare Canonical instances *) (* Otherwise one should construct explicitly the *) (* intermediate structures using the ssralg and *) (* finalg constructors, and finDomain_mulrC domR *) (* finDomain_fieldP domR to prove commutativity *) (* and field axioms (the former is Wedderburn's *) (* little theorem). *) (* FinDomainSplittingFieldType domR pcharRp == a splittingFieldType structure *) (* that repackages the two constructions above *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope GRing.Theory FinRing.Theory. Local Open Scope ring_scope. Section FinNzRing. Variable R : finNzRingType. Lemma finNzRing_nontrivial : [set: R] != 1%g. Proof. by apply/trivgPn; exists 1; rewrite ?inE ?oner_neq0. Qed. Lemma finNzRing_gt1 : 1 < #|R|. Proof. by rewrite -cardsT cardG_gt1 finNzRing_nontrivial. Qed. End FinNzRing. #[deprecated(since="mathcomp 2.4.0", note="Use finNzRing_nontrivial instead.")] Notation finRing_nontrivial := (finNzRing_nontrivial) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use finNzRing_gt1 instead.")] Notation finRing_gt1 := (finNzRing_gt1) (only parsing). Section FinField. Variable F : finFieldType. Lemma card_finField_unit : #|[set: {unit F}]| = #|F|.-1. Proof. by rewrite -(cardC1 0) cardsT card_sub; apply: eq_card => x; rewrite unitfE. Qed. Definition finField_unit x (nz_x : x != 0) := FinRing.unit F (etrans (unitfE x) nz_x). Lemma expf_card x : x ^+ #|F| = x :> F. Proof. rewrite -[RHS]mulr1 -(ltn_predK (finNzRing_gt1 F)) exprS. apply/eqP; rewrite -subr_eq0 -mulrBr mulf_eq0 subr_eq0 -implyNb -unitfE. apply/implyP=> Ux; rewrite -(val_unitX _ (Sub x _)) -val_unit1 val_eqE. by rewrite -order_dvdn -card_finField_unit order_dvdG ?inE. Qed. Lemma finField_genPoly : 'X^#|F| - 'X = \prod_x ('X - x%:P) :> {poly F}. Proof. set n := #|F|; set oppX := - 'X; set pF := LHS. have le_oppX_n: size oppX <= n by rewrite size_polyN size_polyX finNzRing_gt1. have: size pF = (size (enum F)).+1 by rewrite -cardE size_polyDl size_polyXn. move/all_roots_prod_XsubC->; last by rewrite uniq_rootsE enum_uniq. by rewrite big_enum lead_coefDl ?size_polyXn // lead_coefXn scale1r. by apply/allP=> x _; rewrite rootE !hornerE expf_card subrr. Qed. Lemma finPcharP : {p | prime p & p \in [pchar F]}. Proof. pose e := exponent [set: F]; have e_gt0: e > 0 by apply: exponent_gt0. have: e%:R == 0 :> F by rewrite -zmodXgE expg_exponent // inE. by case/natf0_pchar/sigW=> // p pcharFp; exists p; rewrite ?(pcharf_prime pcharFp). Qed. Lemma finField_is_abelem : is_abelem [set: F]. Proof. have [p pr_p pcharFp] := finPcharP. by apply/is_abelemP; exists p; last apply: fin_ring_pchar_abelem. Qed. Lemma card_finPcharP p n : #|F| = (p ^ n)%N -> prime p -> p \in [pchar F]. Proof. move=> oF pr_p; rewrite inE pr_p -order_dvdn. rewrite (abelem_order_p finField_is_abelem) ?inE ?oner_neq0 //=. have n_gt0: n > 0 by rewrite -(ltn_exp2l _ _ (prime_gt1 pr_p)) -oF finNzRing_gt1. by rewrite cardsT oF -(prednK n_gt0) pdiv_pfactor. Qed. End FinField. #[deprecated(since="mathcomp 2.4.0", note="Use finPcharP instead.")] Notation finCharP := (finPcharP) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use card_finPcharP instead.")] Notation card_finCharP := (card_finPcharP) (only parsing). Section CardVspace. Variables (F : finFieldType) (T : finType). Section Vector. Variable cvT : Vector F T. Let vT := Vector.Pack cvT. Lemma card_vspace (V : {vspace vT}) : #|V| = (#|F| ^ \dim V)%N. Proof. set n := \dim V; pose V2rV v := \row_i coord (vbasis V) i v. pose rV2V (rv : 'rV_n) := \sum_i rv 0 i *: (vbasis V)`_i. have rV2V_K: cancel rV2V V2rV. have freeV: free (vbasis V) := basis_free (vbasisP V). by move=> rv; apply/rowP=> i; rewrite mxE coord_sum_free. rewrite -[n]mul1n -card_mx -(card_imset _ (can_inj rV2V_K)). apply: eq_card => v; apply/idP/imsetP=> [/coord_vbasis-> | [rv _ ->]]. by exists (V2rV v) => //; apply: eq_bigr => i _; rewrite mxE. by apply: (@rpred_sum vT) => i _; rewrite rpredZ ?vbasis_mem ?memt_nth. Qed. Lemma card_vspacef : #|{: vT}%VS| = #|T|. Proof. by apply: eq_card => v; rewrite (@memvf _ vT). Qed. End Vector. Variable caT : Falgebra F T. Let aT := Falgebra.Pack caT. Lemma card_vspace1 : #|(1%VS : {vspace aT})| = #|F|. Proof. by rewrite card_vspace (dimv1 aT). Qed. End CardVspace. Definition finvect_type (vT : Type) : predArgType := vT. Section FinVector. Variables (R : finNzRingType) (vT : vectType R). Local Notation fvT := (finvect_type vT). HB.instance Definition _ := Vector.on fvT. HB.instance Definition _ := isCountable.Build fvT (pcan_pickleK (can_pcan VectorInternalTheory.v2rK)). HB.instance Definition _ := isFinite.Build fvT (pcan_enumP (can_pcan (VectorInternalTheory.v2rK : @cancel _ fvT _ _))). End FinVector. HB.instance Definition _ (F : finFieldType) (aT : falgType F) := Falgebra.on (finvect_type aT). Section FinFieldExt. Variables (F : finFieldType) (fT : fieldExtType F). Local Notation ffT := (finvect_type fT). HB.instance Definition _ := FieldExt.on ffT. Lemma ffT_splitting_subproof : SplittingField.axiom ffT. Proof. exists ('X^#|ffT| - 'X). by rewrite (@rpredB {poly fT}) 1?rpredX ?polyOverX. exists (enum ffT); first by rewrite big_enum finField_genPoly eqpxx. by apply/vspaceP=> x; rewrite memvf seqv_sub_adjoin ?mem_enum. Qed. HB.instance Definition _ := FieldExt_isSplittingField.Build F ffT ffT_splitting_subproof. End FinFieldExt. Definition FinSplittingFieldType (F : finFieldType) (fT : fieldExtType F) := HB.pack_for (splittingFieldType F) fT (SplittingField.on (finvect_type fT)). Definition FinFieldExtType (F : finFieldType) (fT : fieldExtType F) := HB.pack_for finFieldType (FinSplittingFieldType fT) (FinRing.Field.on (finvect_type fT)). Arguments FinSplittingFieldType : clear implicits. Section PrimeChar. Variable p : nat. Section PrimeCharRing. Variable R0 : nzRingType. Definition pPrimeCharType of p \in [pchar R0] : predArgType := R0. Hypothesis pcharRp : p \in [pchar R0]. Local Notation R := (pPrimeCharType pcharRp). Implicit Types (a b : 'F_p) (x y : R). HB.instance Definition _ := GRing.NzRing.on R. Definition pprimeChar_scale a x := a%:R * x. Local Infix "*p':" := pprimeChar_scale (at level 40). Let natrFp n : (inZp n : 'F_p)%:R = n%:R :> R. Proof. rewrite [in RHS](divn_eq n p) natrD mulrnA (mulrn_pchar pcharRp) add0r. by rewrite /= (Fp_cast (pcharf_prime pcharRp)). Qed. Lemma pprimeChar_scaleA a b x : a *p': (b *p': x) = (a * b) *p': x. Proof. by rewrite /pprimeChar_scale mulrA -natrM natrFp. Qed. Lemma pprimeChar_scale1 : left_id 1 pprimeChar_scale. Proof. by move=> x; rewrite /pprimeChar_scale mul1r. Qed. Lemma pprimeChar_scaleDr : right_distributive pprimeChar_scale +%R. Proof. by move=> a x y /=; rewrite /pprimeChar_scale mulrDr. Qed. Lemma pprimeChar_scaleDl x : {morph pprimeChar_scale^~ x: a b / a + b}. Proof. by move=> a b; rewrite /pprimeChar_scale natrFp natrD mulrDl. Qed. HB.instance Definition _ := GRing.Zmodule_isLmodule.Build 'F_p R pprimeChar_scaleA pprimeChar_scale1 pprimeChar_scaleDr pprimeChar_scaleDl. Lemma pprimeChar_scaleAl (a : 'F_p) (u v : R) : a *: (u * v) = (a *: u) * v. Proof. by apply: mulrA. Qed. HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build 'F_p R pprimeChar_scaleAl. Lemma pprimeChar_scaleAr (a : 'F_p) (x y : R) : a *: (x * y) = x * (a *: y). Proof. by rewrite ![a *: _]mulr_natl mulrnAr. Qed. HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build 'F_p R pprimeChar_scaleAr. End PrimeCharRing. Local Notation type := @pPrimeCharType. (* TODO: automatize parameter inference to do all of these *) HB.instance Definition _ (R : unitRingType) pcharRp := GRing.UnitRing.on (type R pcharRp). HB.instance Definition _ (R : comNzRingType) pcharRp := GRing.ComNzRing.on (type R pcharRp). HB.instance Definition _ (R : comUnitRingType) pcharRp := GRing.ComUnitRing.on (type R pcharRp). HB.instance Definition _ (R : idomainType) pcharRp := GRing.IntegralDomain.on (type R pcharRp). HB.instance Definition _ (R : fieldType) pcharRp := GRing.Field.on (type R pcharRp). Section FinNzRing. Variables (R0 : finNzRingType) (pcharRp : p \in [pchar R0]). Local Notation R := (type _ pcharRp). HB.instance Definition _ := FinGroup.on R. Let pr_p : prime p. Proof. exact: pcharf_prime pcharRp. Qed. Lemma pprimeChar_abelem : p.-abelem [set: R]. Proof. exact: fin_Fp_lmod_abelem. Qed. Lemma pprimeChar_pgroup : p.-group [set: R]. Proof. by case/and3P: pprimeChar_abelem. Qed. Lemma order_pprimeChar x : x != 0 :> R -> #[x]%g = p. Proof. by apply: (abelem_order_p pprimeChar_abelem); rewrite inE. Qed. Let n := logn p #|R|. Lemma card_pprimeChar : #|R| = (p ^ n)%N. Proof. by rewrite /n -cardsT {1}(card_pgroup pprimeChar_pgroup). Qed. Lemma pprimeChar_vectAxiom : Vector.axiom n R. Proof. have /isog_isom/=[f /isomP[injf im_f]]: [set: R] \isog [set: 'rV['F_p]_n]. rewrite (@isog_abelem_card _ _ p) fin_Fp_lmod_abelem //=. by rewrite !cardsT card_pprimeChar card_mx mul1n card_Fp. exists f; last by exists (invm injf) => x; rewrite ?invmE ?invmK ?im_f ?inE. move=> a x y; rewrite [a *: _]mulr_natl morphM ?morphX ?inE // zmodXgE. by congr (_ + _); rewrite -scaler_nat natr_Zp. Qed. HB.instance Definition _ := Lmodule_hasFinDim.Build 'F_p R pprimeChar_vectAxiom. Lemma pprimeChar_dimf : \dim {: R : vectType 'F_p } = n. Proof. by rewrite dimvf. Qed. End FinNzRing. HB.instance Definition _ (R : finUnitRingType) pcharRp := FinRing.UnitRing.on (type R pcharRp). HB.instance Definition _ (R : finComNzRingType) pcharRp := FinRing.ComNzRing.on (type R pcharRp). HB.instance Definition _ (R : finComUnitRingType) pcharRp := FinRing.ComUnitRing.on (type R pcharRp). HB.instance Definition _ (R : finIdomainType) pcharRp := FinRing.IntegralDomain.on (type R pcharRp). Section FinField. Variables (F0 : finFieldType) (pcharFp : p \in [pchar F0]). Local Notation F := (type _ pcharFp). HB.instance Definition _ := Finite.on F. HB.instance Definition _ := SplittingField.copy F (finvect_type F). End FinField. End PrimeChar. #[deprecated(since="mathcomp 2.4.0", note="Use pPrimeCharType instead.")] Notation PrimeCharType := (pPrimeCharType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scale instead.")] Notation primeChar_scale := (pprimeChar_scale) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scaleA instead.")] Notation primeChar_scaleA := (pprimeChar_scaleA) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scale1 instead.")] Notation primeChar_scale1 := (pprimeChar_scale1) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scaleDr instead.")] Notation primeChar_scaleDr := (pprimeChar_scaleDr) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scaleDl instead.")] Notation primeChar_scaleDl := (pprimeChar_scaleDl) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scaleAl instead.")] Notation primeChar_scaleAl := (pprimeChar_scaleAl) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scaleAr instead.")] Notation primeChar_scaleAr := (pprimeChar_scaleAr) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_abelem instead.")] Notation primeChar_abelem := (pprimeChar_abelem) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_pgroup instead.")] Notation primeChar_pgroup := (pprimeChar_pgroup) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use order_pprimeChar instead.")] Notation order_primeChar := (order_pprimeChar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use card_pprimeChar instead.")] Notation card_primeChar := (card_pprimeChar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_vectAxiom instead.")] Notation primeChar_vectAxiom := (pprimeChar_vectAxiom) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_dimf instead.")] Notation primeChar_dimf := (pprimeChar_dimf) (only parsing). Section FinSplittingField. Variable F : finFieldType. (* By card_vspace order K = #|K| for any finType structure on L; however we *) (* do not want to impose the FinVector instance here. *) Let order (L : vectType F) (K : {vspace L}) := (#|F| ^ \dim K)%N. Section FinGalois. Variable L : splittingFieldType F. Implicit Types (a b : F) (x y : L) (K E : {subfield L}). Let galL K : galois K {:L}. Proof. without loss {K} ->: K / K = 1%AS. by move=> IH_K; apply: galoisS (IH_K _ (erefl _)); rewrite sub1v subvf. apply/splitting_galoisField; pose finL := FinFieldExtType L. exists ('X^#|finL| - 'X); split; first by rewrite rpredB 1?rpredX ?polyOverX. rewrite (finField_genPoly finL) -big_enum /=. by rewrite separable_prod_XsubC ?(enum_uniq finL). exists (enum finL). by rewrite (@big_enum _ _ _ _ finL) (finField_genPoly finL) eqpxx. by apply/vspaceP=> x; rewrite memvf seqv_sub_adjoin ?(mem_enum finL). Qed. Fact galLgen K : {alpha | generator 'Gal({:L} / K) alpha & forall x, alpha x = x ^+ order K}. Proof. without loss{K} ->: K / K = 1%AS; last rewrite /order dimv1 expn1. case/(_ 1%AS)=> // alpha /eqP-defGalL; rewrite /order dimv1 expn1 => Dalpha. exists (alpha ^+ \dim K)%g => [|x]; last first. elim: (\dim K) => [|n IHn]; first by rewrite gal_id. by rewrite expgSr galM ?memvf // IHn Dalpha expnSr exprM. have sGalLK: 'Gal({:L} / K) \subset <[alpha]> by rewrite -defGalL galS ?sub1v. rewrite /generator {sGalLK}(eq_subG_cyclic _ sGalLK) ?cycle_cyclic ?cycleX //. rewrite -orderE orderXdiv orderE -defGalL -?{1}galois_dim ?dimv1 ?divn1 //. by rewrite field_dimS ?subvf. pose f x := x ^+ #|F|. have idfP x: reflect (f x = x) (x \in 1%VS). apply: (iffP (vlineP _ _)) => [[a ->] | xFx]. by rewrite -in_algE -[LHS]rmorphXn expf_card. pose q := map_poly (in_alg L) ('X^#|F| - 'X). have: root q x. rewrite /q rmorphB /= map_polyXn map_polyX. by rewrite rootE !(hornerE, hornerXn) [x ^+ _]xFx subrr. have{q} ->: q = \prod_(z <- [seq b%:A | b : F]) ('X - z%:P). rewrite /q finField_genPoly rmorph_prod big_image /=. by apply: eq_bigr => b _; rewrite rmorphB /= map_polyX map_polyC. by rewrite root_prod_XsubC => /mapP[a]; exists a. have fA : zmod_morphism f. rewrite /f => x y; rewrite ?exprMn ?expr1n //. have [p _ pcharFp] := finPcharP F; rewrite (card_pprimeChar pcharFp). elim: (logn _ _) => // n IHn; rewrite expnSr !exprM {}IHn. by rewrite -(pchar_lalg L) in pcharFp; rewrite -pFrobenius_autE rmorphB. have fM : monoid_morphism f. by rewrite /f; split=> [|x y]; rewrite ?exprMn ?expr1n //. have fZ: scalable f. move=> a x; rewrite -[in LHS]mulr_algl fM. by rewrite (idfP _ _) ?mulr_algl ?memvZ // memv_line. pose faM := GRing.isZmodMorphism.Build _ _ f fA. pose fmM := GRing.isMonoidMorphism.Build _ _ f fM. pose flM := GRing.isScalable.Build _ _ _ _ f fZ. pose fLRM : {lrmorphism _ -> _} := HB.pack f faM fmM flM. have /kAut_to_gal[alpha galLalpha Dalpha]: kAut 1 {:L} (linfun fLRM). rewrite kAutfE; apply/kHomP_tmp; split=> [x /idfP | x y _ _]; rewrite !lfunE //=. exact: (rmorphM fLRM). have{} Dalpha: alpha =1 f by move=> a; rewrite -Dalpha ?memvf ?lfunE. suffices <-: fixedField [set alpha] = 1%AS. by rewrite gal_generated /generator; exists alpha. apply/vspaceP=> x; apply/fixedFieldP/idfP; rewrite ?memvf // => id_x. by rewrite -Dalpha id_x ?set11. by move=> _ /set1P->; rewrite Dalpha. Qed. Lemma finField_galois K E : (K <= E)%VS -> galois K E. Proof. move=> sKE; have /galois_fixedField <- := galL E. rewrite normal_fixedField_galois // -sub_abelian_normal ?galS //. apply: abelianS (galS _ (sub1v _)) _. by have [alpha /('Gal(_ / _) =P _)-> _] := galLgen 1; apply: cycle_abelian. Qed. Lemma finField_galois_generator K E : (K <= E)%VS -> {alpha | generator 'Gal(E / K) alpha & {in E, forall x, alpha x = x ^+ order K}}. Proof. move=> sKE; have [alpha defGalLK Dalpha] := galLgen K. have inKL_E: (K <= E <= {:L})%VS by rewrite sKE subvf. have nKE: normalField K E by have/and3P[] := finField_galois sKE. have galLKalpha: alpha \in 'Gal({:L} / K). by rewrite (('Gal(_ / _) =P _) defGalLK) cycle_id. exists (normalField_cast _ alpha) => [|x Ex]; last first. by rewrite (normalField_cast_eq inKL_E). rewrite /generator -(morphim_cycle (normalField_cast_morphism inKL_E nKE)) //. by rewrite -((_ =P <[alpha]>) defGalLK) normalField_img. Qed. End FinGalois. Lemma Fermat's_little_theorem (L : fieldExtType F) (K : {subfield L}) a : (a \in K) = (a ^+ order K == a). Proof. move: K a; wlog [{}L -> K a]: L / exists galL : splittingFieldType F, L = galL. by pose galL := FinSplittingFieldType F L => /(_ galL); apply; exists galL. have /galois_fixedField fixLK := finField_galois (subvf K). have [alpha defGalLK Dalpha] := finField_galois_generator (subvf K). rewrite -Dalpha ?memvf // -{1}fixLK (('Gal(_ / _) =P _) defGalLK). rewrite /cycle -gal_generated (galois_fixedField _) ?fixedField_galois //. by apply/fixedFieldP/eqP=> [|-> | alpha_x _ /set1P->]; rewrite ?memvf ?set11. Qed. End FinSplittingField. Section FinFieldExists. (* While the existence of finite splitting fields and of finite fields of *) (* arbitrary prime power order is mathematically straightforward, it is *) (* technically challenging to formalize in Coq. The Coq typechecker performs *) (* poorly for some of the deeply nested dependent types used in the *) (* construction, such as polynomials over extensions of extensions of finite *) (* fields. Any conversion in a nested structure parameter incurs a huge *) (* overhead as it is shared across term comparison by call-by-need evalution. *) (* The proof of FinSplittingFieldFor is contrived to mitigate this effect: *) (* the abbreviation map_poly_extField alone divides by 3 the proof checking *) (* time, by reducing the number of occurrences of field(Ext)Type structures *) (* in the subgoals; the successive, apparently redundant 'suffices' localize *) (* some of the conversions to smaller subgoals, yielding a further 8-fold *) (* time gain. In particular, we construct the splitting field as a subtype *) (* of a recursive construction rather than prove that the latter yields *) (* precisely a splitting field. *) (* The apparently redundant type annotation reduces checking time by 30%. *) Let map_poly_extField (F : fieldType) (L : fieldExtType F) := map_poly (in_alg L) : {poly F} -> {poly L}. Local Notation "p ^%:A" := (map_poly_extField _ p) (format "p ^%:A") : ring_scope. Lemma FinSplittingFieldFor (F : finFieldType) (p : {poly F}) : p != 0 -> {L : splittingFieldType F | splittingFieldFor 1 p^%:A {:L}}. Proof. have mapXsubC (f : {rmorphism _ -> _}) x: map_poly f ('X - x%:P) = 'X - (f x)%:P. by rewrite rmorphB /= map_polyX map_polyC. move=> nz_p; pose splits q := {zs | q %= \prod_(z <- zs) ('X - z%:P)}. suffices [L splitLp]: {L : fieldExtType F | splittingFieldFor 1 p^%:A {:L}}. by exists (FinSplittingFieldType F L). suffices [L [ys Dp]]: {L : fieldExtType F & splits L p^%:A}. pose Lp := subvs_of <<1 & ys>>; pose toL := linfun (vsval : Lp -> L). have [zs Dys]: {zs | map toL zs = ys}. exists (map (vsproj _) ys); rewrite -map_comp map_id_in // => y ys_y. by rewrite /= lfunE /= vsprojK ?seqv_sub_adjoin. exists Lp, zs. set lhs := (lhs in lhs %= _); set rhs := (rhs in _ %= rhs). suffices: map_poly toL lhs %= map_poly toL rhs by rewrite eqp_map. rewrite -Dys big_map in Dp; apply: etrans Dp; apply: congr2. by rewrite -map_poly_comp; apply/eq_map_poly=> x; apply: rmorph_alg. by rewrite rmorph_prod; apply/eq_bigr=> z _; apply mapXsubC. set Lzs := LHS; pose Lys := (toL @: Lzs)%VS; apply/vspaceP=> u. have: val u \in Lys by rewrite /Lys aimg_adjoin_seq aimg1 Dys (valP u). by case/memv_imgP=> v Lzs_v; rewrite memvf lfunE => /val_inj->. move: {2}_.+1 (ltnSn (size p)) => n; elim: n => // n IHn in F p nz_p * => lbn. have [Cp|C'p] := leqP (size p) 1. exists F^o, [::]. by rewrite big_nil -size_poly_eq1 size_map_poly eqn_leq Cp size_poly_gt0. have [r r_dv_p irr_r]: {r | r %| p & irreducible_poly r}. pose rVp (v : 'rV_n) (r := rVpoly v) := (1 < size r) && (r %| p). have [v0 Dp]: {v0 | rVpoly v0 = p & rVp v0}. by exists (poly_rV p); rewrite /rVp poly_rV_K ?C'p /=. case/(arg_minnP (size \o rVpoly))=> /= v; set r := rVpoly v. case/andP=> C'r r_dv_p min_r; exists r => //; split=> // q C'q q_dv_r. have nz_r: r != 0 by rewrite -size_poly_gt0 ltnW. have le_q_r: size q <= size r by rewrite dvdp_leq. have [u Dq]: {u : 'rV_n | rVpoly u = q}. by exists (poly_rV q); rewrite poly_rV_K ?(leq_trans le_q_r) ?size_poly. rewrite -dvdp_size_eqp // eqn_leq le_q_r -Dq min_r // /rVp Dq. rewrite ltn_neqAle eq_sym C'q size_poly_gt0 (dvdpN0 q_dv_r) //=. exact: dvdp_trans q_dv_r r_dv_p. have{irr_r} [K _ [x rx0 defK]] := irredp_FAdjoin irr_r. have{r rx0 r_dv_p} /factor_theorem/sig_eqW[q Dp]: root p^%:A x. by rewrite -(divpK r_dv_p) [_^%:A]rmorphM rootM rx0 orbT. have Dszp: size p = size (q * ('X - x%:P)) by rewrite -Dp size_map_poly. have nz_q: q != 0. by move: nz_p; rewrite -size_poly_eq0 Dszp size_poly_eq0 mulf_eq0 => /norP[]. have [L [zs Dq]]: {L : fieldExtType K & splits L q^%:A}. apply: (IHn (FinFieldExtType K) q nz_q). by rewrite ltnS Dszp size_mul ?polyXsubC_eq0 ?size_XsubC ?addn2 in lbn. suffices: splits L p^%:A^%:A. rewrite -[_^%:A]map_poly_comp. (* TODO_HB : had to give the F explicitly *) rewrite -(eq_map_poly (fun a : F => baseField_scaleE a 1)). by exists (baseFieldType L). exists (x%:A :: zs); rewrite big_cons; set rhs := _ * _. by rewrite Dp mulrC [_^%:A]rmorphM /= mapXsubC /= eqp_mull. Qed. Lemma pPrimePowerField p k (m := (p ^ k)%N) : prime p -> 0 < k -> {Fm : finFieldType | p \in [pchar Fm] & #|Fm| = m}. Proof. move=> pr_p k_gt0; have m_gt1: m > 1 by rewrite (ltn_exp2l 0) ?prime_gt1. have m_gt0 := ltnW m_gt1; have m1_gt0: m.-1 > 0 by rewrite -ltnS prednK. pose q := 'X^m - 'X; have Dq R: q R = ('X^(m.-1) - 1) * ('X - 0). by rewrite subr0 mulrBl mul1r -exprSr prednK. have /FinSplittingFieldFor[/= L splitLq]: q 'F_p != 0. by rewrite Dq monic_neq0 ?rpredM ?monicXsubC ?monicXnsubC. rewrite [_^%:A]rmorphB rmorphXn /= map_polyX -/(q L) in splitLq. have pcharL: p \in [pchar L] by rewrite pchar_lalg pchar_Fp. pose Fm := FinFieldExtType L; exists Fm => //. have /finField_galois_generator[/= a _ Da]: (1 <= {:L})%VS by apply: sub1v. pose Em := fixedSpace (a ^+ k)%g; rewrite card_Fp //= dimv1 expn1 in Da. have{splitLq} [zs DqL defL] := splitLq. have Uzs: uniq zs. rewrite -separable_prod_XsubC -(eqp_separable DqL) Dq separable_root andbC. rewrite /root !hornerE subr_eq0 eq_sym expr0n gtn_eqF ?oner_eq0 //=. rewrite cyclotomic.separable_Xn_sub_1 // -subn1 natrB // subr_eq0. by rewrite natrX pcharf0 // expr0n gtn_eqF // eq_sym oner_eq0. suffices /eq_card->: Fm =i zs. apply: succn_inj; rewrite (card_uniqP _) //= -(size_prod_XsubC _ id). by rewrite -(eqp_size DqL) size_polyDl size_polyXn // size_polyN size_polyX. have in_zs: zs =i Em. move=> z; rewrite -root_prod_XsubC -(eqp_root DqL) (sameP fixedSpaceP eqP). rewrite /root !hornerE subr_eq0 /= /m; congr (_ == z). elim: (k) => [|i IHi]; first by rewrite gal_id. by rewrite expgSr expnSr exprM IHi galM ?Da ?memvf. suffices defEm: Em = {:L}%VS by move=> z; rewrite in_zs defEm memvf. apply/eqP; rewrite eqEsubv subvf -defL -[Em]subfield_closed agenvS //. by rewrite subv_add sub1v; apply/span_subvP=> z; rewrite in_zs. Qed. End FinFieldExists. #[deprecated(since="mathcomp 2.4.0", note="Use pPrimePowerField instead.")] Notation PrimePowerField := (pPrimePowerField) (only parsing). Section FinDomain. Import order ssrnum ssrint archimedean algC cyclotomic Order.TTheory Num.Theory. Local Infix "%|" := dvdn. (* Hide polynomial divisibility. *) Variable R : finUnitRingType. Hypothesis domR : GRing.integral_domain_axiom R. Implicit Types x y : R. Let lregR x : x != 0 -> GRing.lreg x. Proof. by move=> xnz; apply: mulrI0_lreg => y /domR/orP[/idPn | /eqP]. Qed. Lemma finDomain_field : GRing.field_axiom R. Proof. move=> x /lregR-regx; apply/unitrP; exists (invF regx 1). by split; first apply: (regx); rewrite ?mulrA f_invF // mulr1 mul1r. Qed. (* This is Witt's proof of Wedderburn's little theorem. *) Theorem finDomain_mulrC : @commutative R R *%R. Proof. have fieldR := finDomain_field. have [p p_pr pcharRp]: exists2 p, prime p & p \in [pchar R]. have [e /prod_prime_decomp->]: {e | (e > 0)%N & e%:R == 0 :> R}. by exists #|[set: R]%G|; rewrite // -order_dvdn order_dvdG ?inE. rewrite big_seq; elim/big_rec: _ => [|[p m] /= n]; first by rewrite oner_eq0. case/mem_prime_decomp=> p_pr _ _ IHn. elim: m => [|m IHm]; rewrite ?mul1n {IHn}// expnS -mulnA natrM. by case/eqP/domR/orP=> //; exists p; last apply/andP. pose Rp := pPrimeCharType pcharRp; pose L : {vspace Rp} := fullv. pose G := [set: {unit R}]; pose ofG : {unit R} -> Rp := val. pose projG (E : {vspace Rp}) := [preim ofG of E]. have inG t nzt: Sub t (finDomain_field nzt) \in G by rewrite inE. have card_projG E: #|projG E| = (p ^ \dim E - 1)%N. transitivity #|E|.-1; last by rewrite subn1 card_vspace card_Fp. rewrite (cardD1 0) mem0v (card_preim val_inj) /=. apply: eq_card => x; congr (_ && _); rewrite [LHS]codom_val. by apply/idP/idP=> [/(memPn _ _)-> | /fieldR]; rewrite ?unitr0. pose C u := 'C[ofG u]%AS; pose Q := 'C(L)%AS; pose q := (p ^ \dim Q)%N. have defC u: 'C[u] =i projG (C u). by move=> v; rewrite cent1E !inE (sameP cent1vP eqP). have defQ: 'Z(G) =i projG Q. move=> u /[!inE]. apply/centP/centvP=> cGu v _; last exact/val_inj/cGu/memvf. by have [-> | /inG/cGu[]] := eqVneq v 0; first by rewrite commr0. have q_gt1: (1 < q)%N by rewrite (ltn_exp2l 0) ?prime_gt1 ?adim_gt0. pose n := \dim_Q L; have oG: #|G| = (q ^ n - 1)%N. rewrite -expnM mulnC divnK ?skew_field_dimS ?subvf // -card_projG. by apply: eq_card => u; rewrite !inE memvf. have oZ: #|'Z(G)| = (q - 1)%N by rewrite -card_projG; apply: eq_card. suffices n_le1: (n <= 1)%N. move=> u v; apply/centvsP: (memvf (u : Rp)) (memvf (v : Rp)) => {u v}. rewrite -(geq_leqif (dimv_leqif_sup (subvf Q))) -/L. by rewrite leq_divLR ?mul1n ?skew_field_dimS ?subvf in n_le1. without loss n_gt1: / (1 < n)%N by rewrite ltnNge; apply: wlog_neg. have [q_gt0 n_gt0] := (ltnW q_gt1, ltnW n_gt1). have [z z_prim] := C_prim_root_exists n_gt0. have zn1: z ^+ n = 1 by apply: prim_expr_order. have /eqP-n1z: `|z| == 1 by rewrite -(pexpr_eq1 n_gt0) // -normrX zn1 normr1. suffices /eqP/normCBeq[t n1t [Dq Dz]]: `|q%:R - z : algC| == `|q%:R : algC| - `|z|. suffices z1: z == 1 by rewrite leq_eqVlt -dvdn1 (prim_order_dvd z_prim) z1. by rewrite Dz n1z mul1r -(eqr_pMn2r q_gt0) Dq normr_nat mulr_natl. pose aq d : algC := (cyclotomic (z ^+ (n %/ d)) d).[q%:R]. suffices: `|aq n| <= (q - 1)%:R. rewrite eq_le lerB_dist andbT n1z normr_nat natrB //; apply: le_trans. rewrite {}/aq horner_prod divnn n_gt0 expr1 normr_prod. rewrite (bigD1 (Ordinal n_gt1)) ?coprime1n //= !hornerE ler_peMr //. elim/big_ind: _ => // [|d _]; first exact: mulr_ege1. rewrite !hornerE; apply: le_trans (lerB_dist _ _). by rewrite normr_nat normrX n1z expr1n lerBDl (leC_nat 2). have Zaq d: d %| n -> aq d \in Num.int. move/(dvdn_prim_root z_prim)=> zd_prim. rewrite rpred_horner ?rpred_nat //= -Cintr_Cyclotomic //. by apply/polyOverP=> i; rewrite coef_map ?rpred_int. suffices: (aq n %| (q - 1)%:R)%C. rewrite {1}[aq n]intrEsign ?Zaq // -(rpredMsign _ (aq n < 0)%R). rewrite dvdC_mul2l ?signr_eq0 //. have /natrP[m ->]: `|aq n| \in Num.nat by rewrite natr_norm_int ?Zaq. by rewrite leC_nat dvdC_nat; apply: dvdn_leq; rewrite subn_gt0. have prod_aq m: m %| n -> \prod_(d < n.+1 | d %| m) aq d = (q ^ m - 1)%:R. move=> m_dv_n; transitivity ('X^m - 1).[q%:R : algC]; last first. by rewrite !hornerE -natrX natrB ?expn_gt0 ?prime_gt0. rewrite (prod_cyclotomic (dvdn_prim_root z_prim m_dv_n)). have def_divm: perm_eq (divisors m) [seq d <- index_iota 0 n.+1 | d %| m]. rewrite uniq_perm ?divisors_uniq ?filter_uniq ?iota_uniq // => d. rewrite -dvdn_divisors ?(dvdn_gt0 n_gt0) // mem_filter mem_iota ltnS /=. by apply/esym/andb_idr=> d_dv_m; rewrite dvdn_leq ?(dvdn_trans d_dv_m). rewrite (perm_big _ def_divm) big_filter big_mkord horner_prod. by apply: eq_bigr => d d_dv_m; rewrite -exprM muln_divA ?divnK. have /rpredBl<-: (aq n %| #|G|%:R)%C. rewrite oG -prod_aq // (bigD1 ord_max) //= dvdC_mulr //. by apply: rpred_prod => d /andP[/Zaq]. rewrite center_class_formula addrC oZ natrD addKr natr_sum /=. apply: rpred_sum => _ /imsetP[u /setDP[_ Z'u] ->]; rewrite -/G /=. have sQC: (Q <= C u)%VS by apply/subvP=> v /centvP-cLv; apply/cent1vP/cLv/memvf. have{sQC} /dvdnP[m Dm]: \dim Q %| \dim (C u) by apply: skew_field_dimS. have m_dv_n: m %| n by rewrite dvdn_divRL // -?Dm ?skew_field_dimS ?subvf. have m_gt0: (0 < m)%N := dvdn_gt0 n_gt0 m_dv_n. have{Dm} oCu: #|'C[u]| = (q ^ m - 1)%N. by rewrite -expnM mulnC -Dm (eq_card (defC u)) card_projG. have ->: #|u ^: G|%:R = \prod_(d < n.+1 | d %| n) (aq d / aq d ^+ (d %| m)). rewrite -index_cent1 natf_indexg ?subsetT //= setTI prodf_div prod_aq // -oG. congr (_ / _); rewrite big_mkcond oCu -prod_aq //= big_mkcond /=. by apply: eq_bigr => d _; case: ifP => [/dvdn_trans->| _]; rewrite ?if_same. rewrite (bigD1 ord_max) //= [n %| m](contraNF _ Z'u) => [|n_dv_m]; last first. rewrite -sub_cent1 subEproper eq_sym eqEcard subsetT oG oCu leq_sub2r //. by rewrite leq_exp2l // dvdn_leq. rewrite divr1 dvdC_mulr //; apply/rpred_prod => d /andP[/Zaq-Zaqd _]. have [-> | nz_aqd] := eqVneq (aq d) 0; first by rewrite mul0r /=. by rewrite -[aq d]expr1 -exprB ?leq_b1 ?unitfE ?rpredX. Qed. Definition FinDomainFieldType : finFieldType := let cC := GRing.PzRing_hasCommutativeMul.Build R finDomain_mulrC in let cR : comUnitRingType := HB.pack R cC in let iC := GRing.ComUnitRing_isIntegral.Build cR domR in let iR : finIdomainType := HB.pack cR iC in let fC := GRing.UnitRing_isField.Build iR finDomain_field in HB.pack iR fC. Definition FinDomainSplittingFieldType_pchar p (pcharRp : p \in [pchar R]) := SplittingField.clone 'F_p R (@pPrimeCharType p FinDomainFieldType pcharRp). End FinDomain. #[deprecated(since="mathcomp 2.4.0", note="Use FinDomainSplittingFieldType_pchar instead.")] Notation FinDomainSplittingFieldType := (FinDomainSplittingFieldType_pchar) (only parsing).
MonoidAlgebra.lean
/- Copyright (c) 2025 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.Algebra.Polynomial.Laurent import Mathlib.RingTheory.Coalgebra.Basic /-! # The coalgebra structure on monoid algebras Given a type `X`, a commutative semiring `R` and a semiring `A` which is also an `R`-coalgebra, this file collects results about the `R`-coalgebra instance on `A[X]` inherited from the corresponding structure on its coefficients, defined in `Mathlib/RingTheory/Coalgebra/Basic.lean`. ## Main definitions * `(Add)MonoidAlgebra.instCoalgebra`: the `R`-coalgebra structure on `A[X]` when `A` is an `R`-coalgebra. * `LaurentPolynomial.instCoalgebra`: the `R`-coalgebra structure on the Laurent polynomials `A[T;T⁻¹]` when `A` is an `R`-coalgebra. -/ noncomputable section open Coalgebra namespace MonoidAlgebra variable {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] {X : Type*} [Module R A] [Coalgebra R A] variable (R A X) in instance instCoalgebra : Coalgebra R (MonoidAlgebra A X) := Finsupp.instCoalgebra R X A instance instIsCocomm [IsCocomm R A] : IsCocomm R (MonoidAlgebra A X) := Finsupp.instIsCocomm R X A @[simp] lemma counit_single (x : X) (a : A) : Coalgebra.counit (single x a) = Coalgebra.counit (R := R) a := Finsupp.counit_single _ _ _ _ _ @[simp] lemma comul_single (x : X) (a : A) : Coalgebra.comul (R := R) (single x a) = TensorProduct.map (lsingle x) (lsingle x) (Coalgebra.comul a) := Finsupp.comul_single _ _ _ _ _ end MonoidAlgebra namespace AddMonoidAlgebra variable {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] {X : Type*} [Module R A] [Coalgebra R A] variable (R A X) in instance instCoalgebra : Coalgebra R A[X] := Finsupp.instCoalgebra R X A instance instIsCocomm [IsCocomm R A] : IsCocomm R A[X] := Finsupp.instIsCocomm R X A @[simp] lemma counit_single (x : X) (a : A) : Coalgebra.counit (single x a) = Coalgebra.counit (R := R) a := Finsupp.counit_single _ _ _ _ _ @[simp] lemma comul_single (x : X) (a : A) : Coalgebra.comul (R := R) (single x a) = TensorProduct.map (lsingle x) (lsingle x) (Coalgebra.comul a) := Finsupp.comul_single _ _ _ _ _ end AddMonoidAlgebra namespace LaurentPolynomial open AddMonoidAlgebra variable (R A : Type*) [CommSemiring R] [Semiring A] [Module R A] [Coalgebra R A] instance instCoalgebra : Coalgebra R A[T;T⁻¹] := inferInstanceAs <| Coalgebra R A[ℤ] instance instIsCocomm [IsCocomm R A] : IsCocomm R A[T;T⁻¹] := inferInstanceAs <| IsCocomm R A[ℤ] variable {R A} @[simp] theorem comul_C (a : A) : Coalgebra.comul (R := R) (C a) = TensorProduct.map (lsingle 0) (lsingle 0) (Coalgebra.comul (R := R) a) := comul_single _ _ @[simp] theorem comul_C_mul_T (a : A) (n : ℤ) : Coalgebra.comul (R := R) (C a * T n) = TensorProduct.map (lsingle n) (lsingle n) (Coalgebra.comul (R := R) a) := by simp [← single_eq_C_mul_T] theorem comul_C_mul_T_self (a : R) (n : ℤ) : Coalgebra.comul (C a * T n) = T n ⊗ₜ[R] (C a * T n) := by simp @[simp] theorem counit_C (a : A) : Coalgebra.counit (R := R) (C a) = Coalgebra.counit (R := R) a := counit_single _ _ @[simp] theorem counit_C_mul_T (a : A) (n : ℤ) : Coalgebra.counit (R := R) (C a * T n) = Coalgebra.counit (R := R) a := by simp [← single_eq_C_mul_T] end LaurentPolynomial
FunctorToTypes.lean
/- Copyright (c) 2024 Jack McKoen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jack McKoen -/ import Mathlib.CategoryTheory.Functor.FunctorHom import Mathlib.CategoryTheory.Closed.Monoidal /-! # Functors to Type are closed. Show that `C ⥤ Type max w v u` is monoidal closed for `C` a category in `Type u` with morphisms in `Type v`, and `w` an arbitrary universe. ## TODO It should be shown that `C ⥤ Type max w v u` is cartesian closed. -/ universe w v' v u u' open CategoryTheory Functor MonoidalCategory namespace CategoryTheory.FunctorToTypes variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] variable (F : C ⥤ Type max w v u) /-- When `F G H : C ⥤ Type max w v u`, we have `(G ⟶ F.functorHom H) ≃ (F ⊗ G ⟶ H)`. -/ @[simps!] def functorHomEquiv (G H : C ⥤ Type max w v u) : (G ⟶ F.functorHom H) ≃ (F ⊗ G ⟶ H) := (Functor.functorHomEquiv F H G).trans (homObjEquiv F H G) /-- Given a morphism `f : G ⟶ H`, an object `c : C`, and an element of `(F.functorHom G).obj c`, construct an element of `(F.functorHom H).obj c`. -/ @[simps] def rightAdj_map {F G H : C ⥤ Type max w v u} (f : G ⟶ H) (c : C) (a : (F.functorHom G).obj c) : (F.functorHom H).obj c where app d b := a.app d b ≫ f.app d naturality g h := by have := a.naturality g h change (F.map g ≫ a.app _ (h ≫ g)) ≫ _ = _ aesop /-- A right adjoint of `tensorLeft F`. -/ @[simps!] def rightAdj : (C ⥤ Type max w v u) ⥤ C ⥤ Type max w v u where obj G := F.functorHom G map f := { app := rightAdj_map f } /-- The adjunction `tensorLeft F ⊣ rightAdj F`. -/ def adj : tensorLeft F ⊣ rightAdj F where unit := { app := fun G ↦ (functorHomEquiv F G _).2 (𝟙 _) naturality := fun G H f ↦ by dsimp [rightAdj] ext _ simp [FunctorToTypes.naturality] } counit := { app := fun G ↦ functorHomEquiv F _ G (𝟙 _) } instance closed : Closed F where rightAdj := rightAdj F adj := adj F instance monoidalClosed : MonoidalClosed (C ⥤ Type max w v u) where end CategoryTheory.FunctorToTypes
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.Notation import Mathlib.Data.Nat.Notation import Mathlib.Order.Defs.LinearOrder /-! # The order relation on the integers -/ open Nat namespace Int theorem le.elim {a b : ℤ} (h : a ≤ b) {P : Prop} (h' : ∀ n : ℕ, a + ↑n = b → P) : P := Exists.elim (le.dest h) h' alias ⟨le_of_ofNat_le_ofNat, ofNat_le_ofNat_of_le⟩ := ofNat_le theorem lt.elim {a b : ℤ} (h : a < b) {P : Prop} (h' : ∀ n : ℕ, a + ↑(Nat.succ n) = b → P) : P := Exists.elim (lt.dest h) h' alias ⟨lt_of_ofNat_lt_ofNat, ofNat_lt_ofNat_of_lt⟩ := ofNat_lt instance instLinearOrder : LinearOrder ℤ where le := (· ≤ ·) le_refl := Int.le_refl le_trans := @Int.le_trans le_antisymm := @Int.le_antisymm lt := (· < ·) lt_iff_le_not_ge := @Int.lt_iff_le_not_le le_total := Int.le_total toDecidableEq := by infer_instance toDecidableLE := by infer_instance toDecidableLT := by infer_instance protected theorem eq_zero_or_eq_zero_of_mul_eq_zero {a b : ℤ} (h : a * b = 0) : a = 0 ∨ b = 0 := Int.mul_eq_zero.mp h theorem nonneg_or_nonpos_of_mul_nonneg {a b : ℤ} : 0 ≤ a * b → 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 := by intro h by_cases ha : 0 ≤ a <;> by_cases hb : 0 ≤ b · exact .inl ⟨ha, hb⟩ · refine .inr ⟨?_, le_of_not_ge hb⟩ obtain _ | _ := Int.mul_eq_zero.mp <| Int.le_antisymm (Int.mul_nonpos_of_nonneg_of_nonpos ha <| le_of_not_ge hb) h all_goals omega · refine .inr ⟨le_of_not_ge ha, ?_⟩ obtain _ | _ := Int.mul_eq_zero.mp <| Int.le_antisymm (Int.mul_nonpos_of_nonpos_of_nonneg (le_of_not_ge ha) hb) h all_goals omega · exact .inr ⟨le_of_not_ge ha, le_of_not_ge hb⟩ theorem mul_nonneg_of_nonneg_or_nonpos {a b : ℤ} : 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 → 0 ≤ a * b | .inl ⟨ha, hb⟩ => Int.mul_nonneg ha hb | .inr ⟨ha, hb⟩ => Int.mul_nonneg_of_nonpos_of_nonpos ha hb protected theorem mul_nonneg_iff {a b : ℤ} : 0 ≤ a * b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 := ⟨nonneg_or_nonpos_of_mul_nonneg, mul_nonneg_of_nonneg_or_nonpos⟩ end Int
LocallyFinite.lean
/- Copyright (c) 2023 Yaël Dillies, Sara Rousta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Set.Finite.Lattice import Mathlib.Order.Interval.Finset.Defs import Mathlib.Order.UpperLower.Closure /-! # Upper and lower sets in a locally finite order In this file we characterise the interaction of `UpperSet`/`LowerSet` and `LocallyFiniteOrder`. -/ namespace Set variable {α : Type*} [Preorder α] {s : Set α} protected theorem Finite.upperClosure [LocallyFiniteOrderTop α] (hs : s.Finite) : (upperClosure s : Set α).Finite := by rw [coe_upperClosure] exact hs.biUnion fun _ _ => finite_Ici _ protected theorem Finite.lowerClosure [LocallyFiniteOrderBot α] (hs : s.Finite) : (lowerClosure s : Set α).Finite := by rw [coe_lowerClosure] exact hs.biUnion fun _ _ => finite_Iic _ end Set
all_character.v
From mathcomp Require Export character. From mathcomp Require Export classfun. From mathcomp Require Export inertia. From mathcomp Require Export integral_char. From mathcomp Require Export mxabelem. From mathcomp Require Export mxrepresentation. From mathcomp Require Export vcharacter.
Associated.lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker -/ import Mathlib.Algebra.Prime.Lemmas import Mathlib.Order.BoundedOrder.Basic /-! # Associated elements. In this file we define an equivalence relation `Associated` saying that two elements of a monoid differ by a multiplication by a unit. Then we show that the quotient type `Associates` is a monoid and prove basic properties of this quotient. -/ assert_not_exists OrderedCommMonoid Multiset Ring variable {M : Type*} /-- Two elements of a `Monoid` are `Associated` if one of them is another one multiplied by a unit on the right. -/ def Associated [Monoid M] (x y : M) : Prop := ∃ u : Mˣ, x * u = y /-- Notation for two elements of a monoid are associated, i.e. if one of them is another one multiplied by a unit on the right. -/ local infixl:50 " ~ᵤ " => Associated namespace Associated @[refl] protected theorem refl [Monoid M] (x : M) : x ~ᵤ x := ⟨1, by simp⟩ protected theorem rfl [Monoid M] {x : M} : x ~ᵤ x := .refl x instance [Monoid M] : IsRefl M Associated := ⟨Associated.refl⟩ @[symm] protected theorem symm [Monoid M] : ∀ {x y : M}, x ~ᵤ y → y ~ᵤ x | x, _, ⟨u, rfl⟩ => ⟨u⁻¹, by rw [mul_assoc, Units.mul_inv, mul_one]⟩ instance [Monoid M] : IsSymm M Associated := ⟨fun _ _ => Associated.symm⟩ protected theorem comm [Monoid M] {x y : M} : x ~ᵤ y ↔ y ~ᵤ x := ⟨Associated.symm, Associated.symm⟩ @[trans] protected theorem trans [Monoid M] : ∀ {x y z : M}, x ~ᵤ y → y ~ᵤ z → x ~ᵤ z | x, _, _, ⟨u, rfl⟩, ⟨v, rfl⟩ => ⟨u * v, by rw [Units.val_mul, mul_assoc]⟩ instance [Monoid M] : IsTrans M Associated := ⟨fun _ _ _ => Associated.trans⟩ /-- The setoid of the relation `x ~ᵤ y` iff there is a unit `u` such that `x * u = y` -/ protected def setoid (M : Type*) [Monoid M] : Setoid M where r := Associated iseqv := ⟨Associated.refl, Associated.symm, Associated.trans⟩ theorem map {M N : Type*} [Monoid M] [Monoid N] {F : Type*} [FunLike F M N] [MonoidHomClass F M N] (f : F) {x y : M} (ha : Associated x y) : Associated (f x) (f y) := by obtain ⟨u, ha⟩ := ha exact ⟨Units.map f u, by rw [← ha, map_mul, Units.coe_map, MonoidHom.coe_coe]⟩ end Associated attribute [local instance] Associated.setoid theorem unit_associated_one [Monoid M] {u : Mˣ} : (u : M) ~ᵤ 1 := ⟨u⁻¹, Units.mul_inv u⟩ @[simp] theorem associated_one_iff_isUnit [Monoid M] {a : M} : (a : M) ~ᵤ 1 ↔ IsUnit a := Iff.intro (fun h => let ⟨c, h⟩ := h.symm h ▸ ⟨c, (one_mul _).symm⟩) fun ⟨c, h⟩ => Associated.symm ⟨c, by simp [h]⟩ @[simp] theorem associated_zero_iff_eq_zero [MonoidWithZero M] (a : M) : a ~ᵤ 0 ↔ a = 0 := Iff.intro (fun h => by let ⟨u, h⟩ := h.symm simpa using h.symm) fun h => h ▸ Associated.refl a theorem associated_one_of_mul_eq_one [CommMonoid M] {a : M} (b : M) (hab : a * b = 1) : a ~ᵤ 1 := show (Units.mkOfMulEqOne a b hab : M) ~ᵤ 1 from unit_associated_one theorem associated_one_of_associated_mul_one [CommMonoid M] {a b : M} : a * b ~ᵤ 1 → a ~ᵤ 1 | ⟨u, h⟩ => associated_one_of_mul_eq_one (b * u) <| by simpa [mul_assoc] using h theorem associated_mul_unit_left {N : Type*} [Monoid N] (a u : N) (hu : IsUnit u) : Associated (a * u) a := let ⟨u', hu⟩ := hu ⟨u'⁻¹, hu ▸ Units.mul_inv_cancel_right _ _⟩ theorem associated_unit_mul_left {N : Type*} [CommMonoid N] (a u : N) (hu : IsUnit u) : Associated (u * a) a := by rw [mul_comm] exact associated_mul_unit_left _ _ hu theorem associated_mul_unit_right {N : Type*} [Monoid N] (a u : N) (hu : IsUnit u) : Associated a (a * u) := (associated_mul_unit_left a u hu).symm theorem associated_unit_mul_right {N : Type*} [CommMonoid N] (a u : N) (hu : IsUnit u) : Associated a (u * a) := (associated_unit_mul_left a u hu).symm theorem associated_mul_isUnit_left_iff {N : Type*} [Monoid N] {a u b : N} (hu : IsUnit u) : Associated (a * u) b ↔ Associated a b := ⟨(associated_mul_unit_right _ _ hu).trans, (associated_mul_unit_left _ _ hu).trans⟩ theorem associated_isUnit_mul_left_iff {N : Type*} [CommMonoid N] {u a b : N} (hu : IsUnit u) : Associated (u * a) b ↔ Associated a b := by rw [mul_comm] exact associated_mul_isUnit_left_iff hu theorem associated_mul_isUnit_right_iff {N : Type*} [Monoid N] {a b u : N} (hu : IsUnit u) : Associated a (b * u) ↔ Associated a b := Associated.comm.trans <| (associated_mul_isUnit_left_iff hu).trans Associated.comm theorem associated_isUnit_mul_right_iff {N : Type*} [CommMonoid N] {a u b : N} (hu : IsUnit u) : Associated a (u * b) ↔ Associated a b := Associated.comm.trans <| (associated_isUnit_mul_left_iff hu).trans Associated.comm @[simp] theorem associated_mul_unit_left_iff {N : Type*} [Monoid N] {a b : N} {u : Units N} : Associated (a * u) b ↔ Associated a b := associated_mul_isUnit_left_iff u.isUnit @[simp] theorem associated_unit_mul_left_iff {N : Type*} [CommMonoid N] {a b : N} {u : Units N} : Associated (↑u * a) b ↔ Associated a b := associated_isUnit_mul_left_iff u.isUnit @[simp] theorem associated_mul_unit_right_iff {N : Type*} [Monoid N] {a b : N} {u : Units N} : Associated a (b * u) ↔ Associated a b := associated_mul_isUnit_right_iff u.isUnit @[simp] theorem associated_unit_mul_right_iff {N : Type*} [CommMonoid N] {a b : N} {u : Units N} : Associated a (↑u * b) ↔ Associated a b := associated_isUnit_mul_right_iff u.isUnit theorem Associated.mul_left [Monoid M] (a : M) {b c : M} (h : b ~ᵤ c) : a * b ~ᵤ a * c := by obtain ⟨d, rfl⟩ := h; exact ⟨d, mul_assoc _ _ _⟩ theorem Associated.mul_right [CommMonoid M] {a b : M} (h : a ~ᵤ b) (c : M) : a * c ~ᵤ b * c := by obtain ⟨d, rfl⟩ := h; exact ⟨d, mul_right_comm _ _ _⟩ theorem Associated.mul_mul [CommMonoid M] {a₁ a₂ b₁ b₂ : M} (h₁ : a₁ ~ᵤ b₁) (h₂ : a₂ ~ᵤ b₂) : a₁ * a₂ ~ᵤ b₁ * b₂ := (h₁.mul_right _).trans (h₂.mul_left _) theorem Associated.pow_pow [CommMonoid M] {a b : M} {n : ℕ} (h : a ~ᵤ b) : a ^ n ~ᵤ b ^ n := by induction n with | zero => simp [Associated.refl] | succ n ih => convert h.mul_mul ih <;> rw [pow_succ'] protected theorem Associated.dvd [Monoid M] {a b : M} : a ~ᵤ b → a ∣ b := fun ⟨u, hu⟩ => ⟨u, hu.symm⟩ protected theorem Associated.dvd' [Monoid M] {a b : M} (h : a ~ᵤ b) : b ∣ a := h.symm.dvd protected theorem Associated.dvd_dvd [Monoid M] {a b : M} (h : a ~ᵤ b) : a ∣ b ∧ b ∣ a := ⟨h.dvd, h.symm.dvd⟩ theorem associated_of_dvd_dvd [CancelMonoidWithZero M] {a b : M} (hab : a ∣ b) (hba : b ∣ a) : a ~ᵤ b := by rcases hab with ⟨c, rfl⟩ rcases hba with ⟨d, a_eq⟩ by_cases ha0 : a = 0 · simp_all have hac0 : a * c ≠ 0 := by intro con rw [con, zero_mul] at a_eq apply ha0 a_eq have : a * (c * d) = a * 1 := by rw [← mul_assoc, ← a_eq, mul_one] have hcd : c * d = 1 := mul_left_cancel₀ ha0 this have : a * c * (d * c) = a * c * 1 := by rw [← mul_assoc, ← a_eq, mul_one] have hdc : d * c = 1 := mul_left_cancel₀ hac0 this exact ⟨⟨c, d, hcd, hdc⟩, rfl⟩ theorem dvd_dvd_iff_associated [CancelMonoidWithZero M] {a b : M} : a ∣ b ∧ b ∣ a ↔ a ~ᵤ b := ⟨fun ⟨h1, h2⟩ => associated_of_dvd_dvd h1 h2, Associated.dvd_dvd⟩ instance [CancelMonoidWithZero M] [DecidableRel ((· ∣ ·) : M → M → Prop)] : DecidableRel ((· ~ᵤ ·) : M → M → Prop) := fun _ _ => decidable_of_iff _ dvd_dvd_iff_associated theorem Associated.dvd_iff_dvd_left [Monoid M] {a b c : M} (h : a ~ᵤ b) : a ∣ c ↔ b ∣ c := let ⟨_, hu⟩ := h hu ▸ Units.mul_right_dvd.symm theorem Associated.dvd_iff_dvd_right [Monoid M] {a b c : M} (h : b ~ᵤ c) : a ∣ b ↔ a ∣ c := let ⟨_, hu⟩ := h hu ▸ Units.dvd_mul_right.symm theorem Associated.eq_zero_iff [MonoidWithZero M] {a b : M} (h : a ~ᵤ b) : a = 0 ↔ b = 0 := by obtain ⟨u, rfl⟩ := h rw [← Units.eq_mul_inv_iff_mul_eq, zero_mul] theorem Associated.ne_zero_iff [MonoidWithZero M] {a b : M} (h : a ~ᵤ b) : a ≠ 0 ↔ b ≠ 0 := not_congr h.eq_zero_iff protected theorem Associated.prime [CommMonoidWithZero M] {p q : M} (h : p ~ᵤ q) (hp : Prime p) : Prime q := ⟨h.ne_zero_iff.1 hp.ne_zero, let ⟨u, hu⟩ := h ⟨fun ⟨v, hv⟩ => hp.not_unit ⟨v * u⁻¹, by simp [hv, hu.symm]⟩, hu ▸ by simp only [Units.isUnit, IsUnit.mul_right_dvd] intro a b exact hp.dvd_or_dvd⟩⟩ theorem prime_mul_iff [CancelCommMonoidWithZero M] {x y : M} : Prime (x * y) ↔ (Prime x ∧ IsUnit y) ∨ (IsUnit x ∧ Prime y) := by refine ⟨fun h ↦ ?_, ?_⟩ · rcases of_irreducible_mul h.irreducible with hx | hy · exact Or.inr ⟨hx, (associated_unit_mul_left y x hx).prime h⟩ · exact Or.inl ⟨(associated_mul_unit_left x y hy).prime h, hy⟩ · rintro (⟨hx, hy⟩ | ⟨hx, hy⟩) · exact (associated_mul_unit_left x y hy).symm.prime hx · exact (associated_unit_mul_right y x hx).prime hy @[simp] lemma prime_pow_iff [CancelCommMonoidWithZero M] {p : M} {n : ℕ} : Prime (p ^ n) ↔ Prime p ∧ n = 1 := by refine ⟨fun hp ↦ ?_, fun ⟨hp, hn⟩ ↦ by simpa [hn]⟩ suffices n = 1 by simp_all rcases n with - | n · simp at hp · rw [Nat.succ.injEq] rw [pow_succ', prime_mul_iff] at hp rcases hp with ⟨hp, hpn⟩ | ⟨hp, hpn⟩ · by_contra contra rw [isUnit_pow_iff contra] at hpn exact hp.not_unit hpn · exfalso exact hpn.not_unit (hp.pow n) theorem Irreducible.dvd_iff [Monoid M] {x y : M} (hx : Irreducible x) : y ∣ x ↔ IsUnit y ∨ Associated x y := by constructor · rintro ⟨z, hz⟩ obtain (h|h) := hx.isUnit_or_isUnit hz · exact Or.inl h · rw [hz] exact Or.inr (associated_mul_unit_left _ _ h) · rintro (hy|h) · exact hy.dvd · exact h.symm.dvd theorem Irreducible.associated_of_dvd [Monoid M] {p q : M} (p_irr : Irreducible p) (q_irr : Irreducible q) (dvd : p ∣ q) : Associated p q := ((q_irr.dvd_iff.mp dvd).resolve_left p_irr.not_isUnit).symm theorem Irreducible.dvd_irreducible_iff_associated [Monoid M] {p q : M} (pp : Irreducible p) (qp : Irreducible q) : p ∣ q ↔ Associated p q := ⟨Irreducible.associated_of_dvd pp qp, Associated.dvd⟩ theorem Prime.associated_of_dvd [CancelCommMonoidWithZero M] {p q : M} (p_prime : Prime p) (q_prime : Prime q) (dvd : p ∣ q) : Associated p q := p_prime.irreducible.associated_of_dvd q_prime.irreducible dvd theorem Prime.dvd_prime_iff_associated [CancelCommMonoidWithZero M] {p q : M} (pp : Prime p) (qp : Prime q) : p ∣ q ↔ Associated p q := pp.irreducible.dvd_irreducible_iff_associated qp.irreducible theorem Associated.prime_iff [CommMonoidWithZero M] {p q : M} (h : p ~ᵤ q) : Prime p ↔ Prime q := ⟨h.prime, h.symm.prime⟩ protected theorem Associated.isUnit [Monoid M] {a b : M} (h : a ~ᵤ b) : IsUnit a → IsUnit b := let ⟨u, hu⟩ := h fun ⟨v, hv⟩ => ⟨v * u, by simp [hv, hu.symm]⟩ theorem Associated.isUnit_iff [Monoid M] {a b : M} (h : a ~ᵤ b) : IsUnit a ↔ IsUnit b := ⟨h.isUnit, h.symm.isUnit⟩ theorem Irreducible.isUnit_iff_not_associated_of_dvd [Monoid M] {x y : M} (hx : Irreducible x) (hy : y ∣ x) : IsUnit y ↔ ¬ Associated x y := ⟨fun hy hxy => hx.1 (hxy.symm.isUnit hy), (hx.dvd_iff.mp hy).resolve_right⟩ protected theorem Associated.irreducible [Monoid M] {p q : M} (h : p ~ᵤ q) (hp : Irreducible p) : Irreducible q := ⟨mt h.symm.isUnit hp.1, let ⟨u, hu⟩ := h fun a b hab => have hpab : p = a * (b * (u⁻¹ : Mˣ)) := calc p = p * u * (u⁻¹ : Mˣ) := by simp _ = _ := by rw [hu]; simp [hab, mul_assoc] (hp.isUnit_or_isUnit hpab).elim Or.inl fun ⟨v, hv⟩ => Or.inr ⟨v * u, by simp [hv]⟩⟩ protected theorem Associated.irreducible_iff [Monoid M] {p q : M} (h : p ~ᵤ q) : Irreducible p ↔ Irreducible q := ⟨h.irreducible, h.symm.irreducible⟩ theorem Associated.of_mul_left [CancelCommMonoidWithZero M] {a b c d : M} (h : a * b ~ᵤ c * d) (h₁ : a ~ᵤ c) (ha : a ≠ 0) : b ~ᵤ d := let ⟨u, hu⟩ := h let ⟨v, hv⟩ := Associated.symm h₁ ⟨u * (v : Mˣ), mul_left_cancel₀ ha (by rw [← hv, mul_assoc c (v : M) d, mul_left_comm c, ← hu] simp [hv.symm, mul_comm, mul_left_comm])⟩ theorem Associated.of_mul_right [CancelCommMonoidWithZero M] {a b c d : M} : a * b ~ᵤ c * d → b ~ᵤ d → b ≠ 0 → a ~ᵤ c := by rw [mul_comm a, mul_comm c]; exact Associated.of_mul_left theorem Associated.of_pow_associated_of_prime [CancelCommMonoidWithZero M] {p₁ p₂ : M} {k₁ k₂ : ℕ} (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₁ : 0 < k₁) (h : p₁ ^ k₁ ~ᵤ p₂ ^ k₂) : p₁ ~ᵤ p₂ := by have : p₁ ∣ p₂ ^ k₂ := by rw [← h.dvd_iff_dvd_right] apply dvd_pow_self _ hk₁.ne' rw [← hp₁.dvd_prime_iff_associated hp₂] exact hp₁.dvd_of_dvd_pow this theorem Associated.of_pow_associated_of_prime' [CancelCommMonoidWithZero M] {p₁ p₂ : M} {k₁ k₂ : ℕ} (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₂ : 0 < k₂) (h : p₁ ^ k₁ ~ᵤ p₂ ^ k₂) : p₁ ~ᵤ p₂ := (h.symm.of_pow_associated_of_prime hp₂ hp₁ hk₂).symm /-- See also `Irreducible.coprime_iff_not_dvd`. -/ lemma Irreducible.isRelPrime_iff_not_dvd [Monoid M] {p n : M} (hp : Irreducible p) : IsRelPrime p n ↔ ¬ p ∣ n := by refine ⟨fun h contra ↦ hp.not_isUnit (h dvd_rfl contra), fun hpn d hdp hdn ↦ ?_⟩ contrapose! hpn suffices Associated p d from this.dvd.trans hdn exact (hp.dvd_iff.mp hdp).resolve_left hpn lemma Irreducible.dvd_or_isRelPrime [Monoid M] {p n : M} (hp : Irreducible p) : p ∣ n ∨ IsRelPrime p n := Classical.or_iff_not_imp_left.mpr hp.isRelPrime_iff_not_dvd.2 section UniqueUnits variable [Monoid M] [Subsingleton Mˣ] theorem associated_iff_eq {x y : M} : x ~ᵤ y ↔ x = y := by constructor · rintro ⟨c, rfl⟩ rw [units_eq_one c, Units.val_one, mul_one] · rintro rfl rfl theorem associated_eq_eq : (Associated : M → M → Prop) = Eq := by ext rw [associated_iff_eq] theorem prime_dvd_prime_iff_eq {M : Type*} [CancelCommMonoidWithZero M] [Subsingleton Mˣ] {p q : M} (pp : Prime p) (qp : Prime q) : p ∣ q ↔ p = q := by rw [pp.dvd_prime_iff_associated qp, ← associated_eq_eq] end UniqueUnits section UniqueUnits₀ variable {R : Type*} [CancelCommMonoidWithZero R] [Subsingleton Rˣ] {p₁ p₂ : R} {k₁ k₂ : ℕ} theorem eq_of_prime_pow_eq (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₁ : 0 < k₁) (h : p₁ ^ k₁ = p₂ ^ k₂) : p₁ = p₂ := by rw [← associated_iff_eq] at h ⊢ apply h.of_pow_associated_of_prime hp₁ hp₂ hk₁ theorem eq_of_prime_pow_eq' (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₁ : 0 < k₂) (h : p₁ ^ k₁ = p₂ ^ k₂) : p₁ = p₂ := by rw [← associated_iff_eq] at h ⊢ apply h.of_pow_associated_of_prime' hp₁ hp₂ hk₁ end UniqueUnits₀ /-- The quotient of a monoid by the `Associated` relation. Two elements `x` and `y` are associated iff there is a unit `u` such that `x * u = y`. There is a natural monoid structure on `Associates M`. -/ abbrev Associates (M : Type*) [Monoid M] : Type _ := Quotient (Associated.setoid M) namespace Associates open Associated /-- The canonical quotient map from a monoid `M` into the `Associates` of `M` -/ protected abbrev mk {M : Type*} [Monoid M] (a : M) : Associates M := ⟦a⟧ instance [Monoid M] : Inhabited (Associates M) := ⟨⟦1⟧⟩ theorem mk_eq_mk_iff_associated [Monoid M] {a b : M} : Associates.mk a = Associates.mk b ↔ a ~ᵤ b := Iff.intro Quotient.exact Quot.sound theorem quotient_mk_eq_mk [Monoid M] (a : M) : ⟦a⟧ = Associates.mk a := rfl theorem quot_mk_eq_mk [Monoid M] (a : M) : Quot.mk Setoid.r a = Associates.mk a := rfl @[simp] theorem quot_out [Monoid M] (a : Associates M) : Associates.mk (Quot.out a) = a := by rw [← quot_mk_eq_mk, Quot.out_eq] theorem mk_quot_out [Monoid M] (a : M) : Quot.out (Associates.mk a) ~ᵤ a := by rw [← Associates.mk_eq_mk_iff_associated, Associates.quot_out] theorem forall_associated [Monoid M] {p : Associates M → Prop} : (∀ a, p a) ↔ ∀ a, p (Associates.mk a) := Iff.intro (fun h _ => h _) fun h a => Quotient.inductionOn a h theorem mk_surjective [Monoid M] : Function.Surjective (@Associates.mk M _) := forall_associated.2 fun a => ⟨a, rfl⟩ instance [Monoid M] : One (Associates M) := ⟨⟦1⟧⟩ @[simp] theorem mk_one [Monoid M] : Associates.mk (1 : M) = 1 := rfl theorem one_eq_mk_one [Monoid M] : (1 : Associates M) = Associates.mk 1 := rfl @[simp] theorem mk_eq_one [Monoid M] {a : M} : Associates.mk a = 1 ↔ IsUnit a := by rw [← mk_one, mk_eq_mk_iff_associated, associated_one_iff_isUnit] instance [Monoid M] : Bot (Associates M) := ⟨1⟩ theorem bot_eq_one [Monoid M] : (⊥ : Associates M) = 1 := rfl theorem exists_rep [Monoid M] (a : Associates M) : ∃ a0 : M, Associates.mk a0 = a := Quot.exists_rep a instance [Monoid M] [Subsingleton M] : Unique (Associates M) where default := 1 uniq := forall_associated.2 fun _ ↦ mk_eq_one.2 <| isUnit_of_subsingleton _ theorem mk_injective [Monoid M] [Subsingleton Mˣ] : Function.Injective (@Associates.mk M _) := fun _ _ h => associated_iff_eq.mp (Associates.mk_eq_mk_iff_associated.mp h) section CommMonoid variable [CommMonoid M] instance instMul : Mul (Associates M) := ⟨Quotient.map₂ (· * ·) fun _ _ h₁ _ _ h₂ ↦ h₁.mul_mul h₂⟩ theorem mk_mul_mk {x y : M} : Associates.mk x * Associates.mk y = Associates.mk (x * y) := rfl instance instCommMonoid : CommMonoid (Associates M) where one := 1 mul := (· * ·) mul_one a' := Quotient.inductionOn a' fun a => show ⟦a * 1⟧ = ⟦a⟧ by simp one_mul a' := Quotient.inductionOn a' fun a => show ⟦1 * a⟧ = ⟦a⟧ by simp mul_assoc a' b' c' := Quotient.inductionOn₃ a' b' c' fun a b c => show ⟦a * b * c⟧ = ⟦a * (b * c)⟧ by rw [mul_assoc] mul_comm a' b' := Quotient.inductionOn₂ a' b' fun a b => show ⟦a * b⟧ = ⟦b * a⟧ by rw [mul_comm] instance instPreorder : Preorder (Associates M) where le := Dvd.dvd le_refl := dvd_refl le_trans _ _ _ := dvd_trans /-- `Associates.mk` as a `MonoidHom`. -/ protected def mkMonoidHom : M →* Associates M where toFun := Associates.mk map_one' := mk_one map_mul' _ _ := mk_mul_mk @[simp] theorem mkMonoidHom_apply (a : M) : Associates.mkMonoidHom a = Associates.mk a := rfl theorem associated_map_mk {f : Associates M →* M} (hinv : Function.RightInverse f Associates.mk) (a : M) : a ~ᵤ f (Associates.mk a) := Associates.mk_eq_mk_iff_associated.1 (hinv (Associates.mk a)).symm theorem mk_pow (a : M) (n : ℕ) : Associates.mk (a ^ n) = Associates.mk a ^ n := by induction n <;> simp [*, pow_succ, Associates.mk_mul_mk.symm] theorem dvd_eq_le : ((· ∣ ·) : Associates M → Associates M → Prop) = (· ≤ ·) := rfl instance uniqueUnits : Unique (Associates M)ˣ where uniq := by rintro ⟨a, b, hab, hba⟩ revert hab hba exact Quotient.inductionOn₂ a b <| fun a b hab hba ↦ Units.ext <| Quotient.sound <| associated_one_of_associated_mul_one <| Quotient.exact hab @[simp] theorem coe_unit_eq_one (u : (Associates M)ˣ) : (u : Associates M) = 1 := by simp [eq_iff_true_of_subsingleton] theorem isUnit_iff_eq_one (a : Associates M) : IsUnit a ↔ a = 1 := Iff.intro (fun ⟨_, h⟩ => h ▸ coe_unit_eq_one _) fun h => h.symm ▸ isUnit_one theorem isUnit_iff_eq_bot {a : Associates M} : IsUnit a ↔ a = ⊥ := by rw [Associates.isUnit_iff_eq_one, bot_eq_one] theorem isUnit_mk {a : M} : IsUnit (Associates.mk a) ↔ IsUnit a := calc IsUnit (Associates.mk a) ↔ a ~ᵤ 1 := by rw [isUnit_iff_eq_one, one_eq_mk_one, mk_eq_mk_iff_associated] _ ↔ IsUnit a := associated_one_iff_isUnit section Order theorem mul_mono {a b c d : Associates M} (h₁ : a ≤ b) (h₂ : c ≤ d) : a * c ≤ b * d := let ⟨x, hx⟩ := h₁ let ⟨y, hy⟩ := h₂ ⟨x * y, by simp [hx, hy, mul_comm, mul_left_comm]⟩ theorem one_le {a : Associates M} : 1 ≤ a := Dvd.intro _ (one_mul a) theorem le_mul_right {a b : Associates M} : a ≤ a * b := ⟨b, rfl⟩ theorem le_mul_left {a b : Associates M} : a ≤ b * a := by rw [mul_comm]; exact le_mul_right instance instOrderBot : OrderBot (Associates M) where bot := 1 bot_le _ := one_le end Order @[simp] theorem mk_dvd_mk {a b : M} : Associates.mk a ∣ Associates.mk b ↔ a ∣ b := by simp only [dvd_def, mk_surjective.exists, mk_mul_mk, mk_eq_mk_iff_associated, Associated.comm (x := b)] constructor · rintro ⟨x, u, rfl⟩ exact ⟨_, mul_assoc ..⟩ · rintro ⟨c, rfl⟩ use c theorem dvd_of_mk_le_mk {a b : M} : Associates.mk a ≤ Associates.mk b → a ∣ b := mk_dvd_mk.mp theorem mk_le_mk_of_dvd {a b : M} : a ∣ b → Associates.mk a ≤ Associates.mk b := mk_dvd_mk.mpr theorem mk_le_mk_iff_dvd {a b : M} : Associates.mk a ≤ Associates.mk b ↔ a ∣ b := mk_dvd_mk @[simp] theorem isPrimal_mk {a : M} : IsPrimal (Associates.mk a) ↔ IsPrimal a := by simp_rw [IsPrimal, forall_associated, mk_surjective.exists, mk_mul_mk, mk_dvd_mk] constructor <;> intro h b c dvd <;> obtain ⟨a₁, a₂, h₁, h₂, eq⟩ := @h b c dvd · obtain ⟨u, rfl⟩ := mk_eq_mk_iff_associated.mp eq.symm exact ⟨a₁, a₂ * u, h₁, Units.mul_right_dvd.mpr h₂, mul_assoc _ _ _⟩ · exact ⟨a₁, a₂, h₁, h₂, congr_arg _ eq⟩ @[simp] theorem decompositionMonoid_iff : DecompositionMonoid (Associates M) ↔ DecompositionMonoid M := by simp_rw [_root_.decompositionMonoid_iff, forall_associated, isPrimal_mk] instance instDecompositionMonoid [DecompositionMonoid M] : DecompositionMonoid (Associates M) := decompositionMonoid_iff.mpr ‹_› @[simp] theorem mk_isRelPrime_iff {a b : M} : IsRelPrime (Associates.mk a) (Associates.mk b) ↔ IsRelPrime a b := by simp_rw [IsRelPrime, forall_associated, mk_dvd_mk, isUnit_mk] end CommMonoid instance [Zero M] [Monoid M] : Zero (Associates M) := ⟨⟦0⟧⟩ instance [Zero M] [Monoid M] : Top (Associates M) := ⟨0⟩ @[simp] theorem mk_zero [Zero M] [Monoid M] : Associates.mk (0 : M) = 0 := rfl section MonoidWithZero variable [MonoidWithZero M] @[simp] theorem mk_eq_zero {a : M} : Associates.mk a = 0 ↔ a = 0 := ⟨fun h => (associated_zero_iff_eq_zero a).1 <| Quotient.exact h, fun h => h.symm ▸ rfl⟩ @[simp] theorem quot_out_zero : Quot.out (0 : Associates M) = 0 := by rw [← mk_eq_zero, quot_out] theorem mk_ne_zero {a : M} : Associates.mk a ≠ 0 ↔ a ≠ 0 := not_congr mk_eq_zero instance [Nontrivial M] : Nontrivial (Associates M) := ⟨⟨1, 0, mk_ne_zero.2 one_ne_zero⟩⟩ theorem exists_non_zero_rep {a : Associates M} : a ≠ 0 → ∃ a0 : M, a0 ≠ 0 ∧ Associates.mk a0 = a := Quotient.inductionOn a fun b nz => ⟨b, mt (congr_arg Quotient.mk'') nz, rfl⟩ end MonoidWithZero section CommMonoidWithZero variable [CommMonoidWithZero M] instance instCommMonoidWithZero : CommMonoidWithZero (Associates M) where zero_mul := forall_associated.2 fun a ↦ by rw [← mk_zero, mk_mul_mk, zero_mul] mul_zero := forall_associated.2 fun a ↦ by rw [← mk_zero, mk_mul_mk, mul_zero] instance instOrderTop : OrderTop (Associates M) where top := 0 le_top := dvd_zero @[simp] protected theorem le_zero (a : Associates M) : a ≤ 0 := le_top instance instBoundedOrder : BoundedOrder (Associates M) where instance [DecidableRel ((· ∣ ·) : M → M → Prop)] : DecidableRel ((· ∣ ·) : Associates M → Associates M → Prop) := fun a b => Quotient.recOnSubsingleton₂ a b fun _ _ => decidable_of_iff' _ mk_dvd_mk theorem Prime.le_or_le {p : Associates M} (hp : Prime p) {a b : Associates M} (h : p ≤ a * b) : p ≤ a ∨ p ≤ b := hp.2.2 a b h @[simp] theorem prime_mk {p : M} : Prime (Associates.mk p) ↔ Prime p := by rw [Prime, _root_.Prime, forall_associated] simp only [forall_associated, mk_ne_zero, isUnit_mk, mk_mul_mk, mk_dvd_mk] @[simp] theorem irreducible_mk {a : M} : Irreducible (Associates.mk a) ↔ Irreducible a := by simp only [irreducible_iff, isUnit_mk, forall_associated, isUnit_mk, mk_mul_mk, mk_eq_mk_iff_associated, Associated.comm (x := a)] apply Iff.rfl.and constructor · rintro h x y rfl exact h _ _ <| .refl _ · rintro h x y ⟨u, rfl⟩ simpa using h (mul_assoc _ _ _) @[simp] theorem mk_dvdNotUnit_mk_iff {a b : M} : DvdNotUnit (Associates.mk a) (Associates.mk b) ↔ DvdNotUnit a b := by simp only [DvdNotUnit, mk_ne_zero, mk_surjective.exists, isUnit_mk, mk_mul_mk, mk_eq_mk_iff_associated, Associated.comm (x := b)] refine Iff.rfl.and ?_ constructor · rintro ⟨x, hx, u, rfl⟩ refine ⟨x * u, ?_, mul_assoc ..⟩ simpa · rintro ⟨x, ⟨hx, rfl⟩⟩ use x theorem dvdNotUnit_of_lt {a b : Associates M} (hlt : a < b) : DvdNotUnit a b := by constructor · rintro rfl apply not_lt_of_ge _ hlt apply dvd_zero rcases hlt with ⟨⟨x, rfl⟩, ndvd⟩ refine ⟨x, ?_, rfl⟩ contrapose! ndvd rcases ndvd with ⟨u, rfl⟩ simp theorem irreducible_iff_prime_iff : (∀ a : M, Irreducible a ↔ Prime a) ↔ ∀ a : Associates M, Irreducible a ↔ Prime a := by simp_rw [forall_associated, irreducible_mk, prime_mk] end CommMonoidWithZero section CancelCommMonoidWithZero variable [CancelCommMonoidWithZero M] instance instPartialOrder : PartialOrder (Associates M) where le_antisymm := mk_surjective.forall₂.2 fun _a _b hab hba => mk_eq_mk_iff_associated.2 <| associated_of_dvd_dvd (dvd_of_mk_le_mk hab) (dvd_of_mk_le_mk hba) instance instCancelCommMonoidWithZero : CancelCommMonoidWithZero (Associates M) := { (by infer_instance : CommMonoidWithZero (Associates M)) with mul_left_cancel_of_ne_zero := by rintro ⟨a⟩ ha ⟨b⟩ ⟨c⟩ h rcases Quotient.exact' h with ⟨u, hu⟩ have hu : a * (b * ↑u) = a * c := by rwa [← mul_assoc] exact Quotient.sound' ⟨u, mul_left_cancel₀ (mk_ne_zero.1 ha) hu⟩ } theorem _root_.associates_irreducible_iff_prime [DecompositionMonoid M] {p : Associates M} : Irreducible p ↔ Prime p := irreducible_iff_prime instance : NoZeroDivisors (Associates M) := by infer_instance theorem le_of_mul_le_mul_left (a b c : Associates M) (ha : a ≠ 0) : a * b ≤ a * c → b ≤ c | ⟨d, hd⟩ => ⟨d, mul_left_cancel₀ ha <| by rwa [← mul_assoc]⟩ theorem one_or_eq_of_le_of_prime {p m : Associates M} (hp : Prime p) (hle : m ≤ p) : m = 1 ∨ m = p := by rcases mk_surjective p with ⟨p, rfl⟩ rcases mk_surjective m with ⟨m, rfl⟩ simpa [mk_eq_mk_iff_associated, Associated.comm, -Quotient.eq] using (prime_mk.1 hp).irreducible.dvd_iff.mp (mk_le_mk_iff_dvd.1 hle) theorem dvdNotUnit_iff_lt {a b : Associates M} : DvdNotUnit a b ↔ a < b := dvd_and_not_dvd_iff.symm theorem le_one_iff {p : Associates M} : p ≤ 1 ↔ p = 1 := by rw [← Associates.bot_eq_one, le_bot_iff] end CancelCommMonoidWithZero end Associates section CommMonoidWithZero theorem dvdNotUnit_of_dvdNotUnit_associated [CommMonoidWithZero M] [Nontrivial M] {p q r : M} (h : DvdNotUnit p q) (h' : Associated q r) : DvdNotUnit p r := by obtain ⟨u, rfl⟩ := Associated.symm h' obtain ⟨hp, x, hx⟩ := h refine ⟨hp, x * ↑u⁻¹, DvdNotUnit.not_unit ⟨u⁻¹.ne_zero, x, hx.left, mul_comm _ _⟩, ?_⟩ rw [← mul_assoc, ← hx.right, mul_assoc, Units.mul_inv, mul_one] end CommMonoidWithZero section CancelCommMonoidWithZero theorem isUnit_of_associated_mul [CancelCommMonoidWithZero M] {p b : M} (h : Associated (p * b) p) (hp : p ≠ 0) : IsUnit b := by obtain ⟨a, ha⟩ := h refine isUnit_of_mul_eq_one b a ((mul_right_inj' hp).mp ?_) rwa [← mul_assoc, mul_one] theorem DvdNotUnit.not_associated [CancelCommMonoidWithZero M] {p q : M} (h : DvdNotUnit p q) : ¬Associated p q := by rintro ⟨a, rfl⟩ obtain ⟨hp, x, hx, hx'⟩ := h rcases (mul_right_inj' hp).mp hx' with rfl exact hx a.isUnit theorem dvd_prime_pow [CancelCommMonoidWithZero M] {p q : M} (hp : Prime p) (n : ℕ) : q ∣ p ^ n ↔ ∃ i ≤ n, Associated q (p ^ i) := by induction n generalizing q with | zero => simp [← isUnit_iff_dvd_one, associated_one_iff_isUnit] | succ n ih => refine ⟨fun h => ?_, fun ⟨i, hi, hq⟩ => hq.dvd.trans (pow_dvd_pow p hi)⟩ rw [pow_succ'] at h rcases hp.left_dvd_or_dvd_right_of_dvd_mul h with (⟨q, rfl⟩ | hno) · rw [mul_dvd_mul_iff_left hp.ne_zero, ih] at h rcases h with ⟨i, hi, hq⟩ refine ⟨i + 1, Nat.succ_le_succ hi, (hq.mul_left p).trans ?_⟩ rw [pow_succ'] · obtain ⟨i, hi, hq⟩ := ih.mp hno exact ⟨i, hi.trans n.le_succ, hq⟩ end CancelCommMonoidWithZero
AbstractCompletion.lean
/- Copyright (c) 2019 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Topology.UniformSpace.UniformEmbedding import Mathlib.Topology.UniformSpace.Equiv /-! # Abstract theory of Hausdorff completions of uniform spaces This file characterizes Hausdorff completions of a uniform space α as complete Hausdorff spaces equipped with a map from α which has dense image and induce the original uniform structure on α. Assuming these properties we "extend" uniformly continuous maps from α to complete Hausdorff spaces to the completions of α. This is the universal property expected from a completion. It is then used to extend uniformly continuous maps from α to α' to maps between completions of α and α'. This file does not construct any such completion, it only study consequences of their existence. The first advantage is that formal properties are clearly highlighted without interference from construction details. The second advantage is that this framework can then be used to compare different completion constructions. See `Topology/UniformSpace/CompareReals` for an example. Of course the comparison comes from the universal property as usual. A general explicit construction of completions is done in `UniformSpace/Completion`, leading to a functor from uniform spaces to complete Hausdorff uniform spaces that is left adjoint to the inclusion, see `UniformSpace/UniformSpaceCat` for the category packaging. ## Implementation notes A tiny technical advantage of using a characteristic predicate such as the properties listed in `AbstractCompletion` instead of stating the universal property is that the universal property derived from the predicate is more universe polymorphic. ## References We don't know any traditional text discussing this. Real world mathematics simply silently identify the results of any two constructions that lead to something one could reasonably call a completion. ## Tags uniform spaces, completion, universal property -/ noncomputable section open Filter Set Function /-- A completion of `α` is the data of a complete separated uniform space and a map from `α` with dense range and inducing the original uniform structure on `α`. -/ @[pp_with_univ] structure AbstractCompletion.{v, u} (α : Type u) [UniformSpace α] where /-- The underlying space of the completion. -/ space : Type v /-- A map from a space to its completion. -/ coe : α → space /-- The completion carries a uniform structure. -/ uniformStruct : UniformSpace space /-- The completion is complete. -/ complete : CompleteSpace space /-- The completion is a T₀ space. -/ separation : T0Space space /-- The map into the completion is uniform-inducing. -/ isUniformInducing : IsUniformInducing coe /-- The map into the completion has dense range. -/ dense : DenseRange coe attribute [local instance] AbstractCompletion.uniformStruct AbstractCompletion.complete AbstractCompletion.separation namespace AbstractCompletion universe uα vα vα' uβ vβ uγ vγ variable {α : Type uα} [UniformSpace α] (pkg : AbstractCompletion.{vα} α) local notation "hatα" => pkg.space local notation "ι" => pkg.coe /-- If `α` is complete, then it is an abstract completion of itself. -/ def ofComplete [T0Space α] [CompleteSpace α] : AbstractCompletion α := mk α id inferInstance inferInstance inferInstance .id denseRange_id theorem closure_range : closure (range ι) = univ := pkg.dense.closure_range theorem isDenseInducing : IsDenseInducing ι := ⟨pkg.isUniformInducing.isInducing, pkg.dense⟩ theorem uniformContinuous_coe : UniformContinuous ι := IsUniformInducing.uniformContinuous pkg.isUniformInducing theorem continuous_coe : Continuous ι := pkg.uniformContinuous_coe.continuous @[elab_as_elim] theorem induction_on {p : hatα → Prop} (a : hatα) (hp : IsClosed { a | p a }) (ih : ∀ a, p (ι a)) : p a := isClosed_property pkg.dense hp ih a variable {β : Type uβ} protected theorem funext [TopologicalSpace β] [T2Space β] {f g : hatα → β} (hf : Continuous f) (hg : Continuous g) (h : ∀ a, f (ι a) = g (ι a)) : f = g := funext fun a => pkg.induction_on a (isClosed_eq hf hg) h variable [UniformSpace β] section Extend /-- Extension of maps to completions -/ protected def extend (f : α → β) : hatα → β := open scoped Classical in if UniformContinuous f then pkg.isDenseInducing.extend f else fun x => f (pkg.dense.some x) variable {f : α → β} theorem extend_def (hf : UniformContinuous f) : pkg.extend f = pkg.isDenseInducing.extend f := if_pos hf theorem extend_coe [T2Space β] (hf : UniformContinuous f) (a : α) : (pkg.extend f) (ι a) = f a := by rw [pkg.extend_def hf] exact pkg.isDenseInducing.extend_eq hf.continuous a variable [CompleteSpace β] theorem uniformContinuous_extend : UniformContinuous (pkg.extend f) := by by_cases hf : UniformContinuous f · rw [pkg.extend_def hf] exact uniformContinuous_uniformly_extend pkg.isUniformInducing pkg.dense hf · unfold AbstractCompletion.extend rw [if_neg hf] exact uniformContinuous_of_const fun a b => by congr 1 theorem continuous_extend : Continuous (pkg.extend f) := pkg.uniformContinuous_extend.continuous variable [T0Space β] theorem extend_unique (hf : UniformContinuous f) {g : hatα → β} (hg : UniformContinuous g) (h : ∀ a : α, f a = g (ι a)) : pkg.extend f = g := by apply pkg.funext pkg.continuous_extend hg.continuous simpa only [pkg.extend_coe hf] using h @[simp] theorem extend_comp_coe {f : hatα → β} (hf : UniformContinuous f) : pkg.extend (f ∘ ι) = f := funext fun x => pkg.induction_on x (isClosed_eq pkg.continuous_extend hf.continuous) fun y => pkg.extend_coe (hf.comp <| pkg.uniformContinuous_coe) y end Extend section MapSec variable (pkg' : AbstractCompletion.{vβ} β) local notation "hatβ" => pkg'.space local notation "ι'" => pkg'.coe /-- Lifting maps to completions -/ protected def map (f : α → β) : hatα → hatβ := pkg.extend (ι' ∘ f) local notation "map" => pkg.map pkg' variable (f : α → β) theorem uniformContinuous_map : UniformContinuous (map f) := pkg.uniformContinuous_extend @[continuity] theorem continuous_map : Continuous (map f) := pkg.continuous_extend variable {f} @[simp] theorem map_coe (hf : UniformContinuous f) (a : α) : map f (ι a) = ι' (f a) := pkg.extend_coe (pkg'.uniformContinuous_coe.comp hf) a theorem map_unique {f : α → β} {g : hatα → hatβ} (hg : UniformContinuous g) (h : ∀ a, ι' (f a) = g (ι a)) : map f = g := pkg.funext (pkg.continuous_map _ _) hg.continuous <| by intro a change pkg.extend (ι' ∘ f) _ = _ simp_rw [Function.comp_def, h, ← comp_apply (f := g)] rw [pkg.extend_coe (hg.comp pkg.uniformContinuous_coe)] @[simp] theorem map_id : pkg.map pkg id = id := pkg.map_unique pkg uniformContinuous_id fun _ => rfl variable {γ : Type uγ} [UniformSpace γ] theorem extend_map [CompleteSpace γ] [T0Space γ] {f : β → γ} {g : α → β} (hf : UniformContinuous f) (hg : UniformContinuous g) : pkg'.extend f ∘ map g = pkg.extend (f ∘ g) := pkg.funext (pkg'.continuous_extend.comp (pkg.continuous_map pkg' _)) pkg.continuous_extend fun a => by rw [pkg.extend_coe (hf.comp hg), comp_apply, pkg.map_coe pkg' hg, pkg'.extend_coe hf] rfl variable (pkg'' : AbstractCompletion.{vγ} γ) theorem map_comp {g : β → γ} {f : α → β} (hg : UniformContinuous g) (hf : UniformContinuous f) : pkg'.map pkg'' g ∘ pkg.map pkg' f = pkg.map pkg'' (g ∘ f) := pkg.extend_map pkg' (pkg''.uniformContinuous_coe.comp hg) hf end MapSec section Compare -- We can now compare two completion packages for the same uniform space variable (pkg' : AbstractCompletion.{vα'} α) /-- The comparison map between two completions of the same uniform space. -/ def compare : pkg.space → pkg'.space := pkg.extend pkg'.coe theorem uniformContinuous_compare : UniformContinuous (pkg.compare pkg') := pkg.uniformContinuous_extend theorem compare_coe (a : α) : pkg.compare pkg' (pkg.coe a) = pkg'.coe a := pkg.extend_coe pkg'.uniformContinuous_coe a theorem inverse_compare : pkg.compare pkg' ∘ pkg'.compare pkg = id := by have uc := pkg.uniformContinuous_compare pkg' have uc' := pkg'.uniformContinuous_compare pkg apply pkg'.funext (uc.comp uc').continuous continuous_id intro a rw [comp_apply, pkg'.compare_coe pkg, pkg.compare_coe pkg'] rfl /-- The uniform bijection between two completions of the same uniform space. -/ def compareEquiv : pkg.space ≃ᵤ pkg'.space where toFun := pkg.compare pkg' invFun := pkg'.compare pkg left_inv := congr_fun (pkg'.inverse_compare pkg) right_inv := congr_fun (pkg.inverse_compare pkg') uniformContinuous_toFun := uniformContinuous_compare _ _ uniformContinuous_invFun := uniformContinuous_compare _ _ theorem uniformContinuous_compareEquiv : UniformContinuous (pkg.compareEquiv pkg') := pkg.uniformContinuous_compare pkg' theorem uniformContinuous_compareEquiv_symm : UniformContinuous (pkg.compareEquiv pkg').symm := pkg'.uniformContinuous_compare pkg open scoped Topology /-Let `f : α → γ` be a continuous function between a uniform space `α` and a regular topological space `γ`, and let `pkg, pkg'` be two abstract completions of `α`. Then if for every point `a : pkg` the filter `f.map (coe⁻¹ (𝓝 a))` obtained by pushing forward with `f` the preimage in `α` of `𝓝 a` tends to `𝓝 (f.extend a : β)`, then the comparison map between `pkg` and `pkg'` composed with the extension of `f` to `pkg`` coincides with the extension of `f` to `pkg'`. The situation is described in the following diagram, where the two diagonal arrows are the extensions of `f` to the two different completions `pkg` and `pkg'`; the statement of `compare_comp_eq_compare` is the commutativity of the right triangle. ``` `α^`=`pkg` ≅ `α^'`=`pkg'` *here `≅` is `compare`* ∧ \ / | \ / | \ / | V ∨ α ---f---> γ ``` -/ theorem compare_comp_eq_compare (γ : Type uγ) [TopologicalSpace γ] [T3Space γ] {f : α → γ} (cont_f : Continuous f) : letI := pkg.uniformStruct.toTopologicalSpace letI := pkg'.uniformStruct.toTopologicalSpace (∀ a : pkg.space, Filter.Tendsto f (Filter.comap pkg.coe (𝓝 a)) (𝓝 ((pkg.isDenseInducing.extend f) a))) → pkg.isDenseInducing.extend f ∘ pkg'.compare pkg = pkg'.isDenseInducing.extend f := by let _ := pkg'.uniformStruct let _ := pkg.uniformStruct intro h have (x : α) : (pkg.isDenseInducing.extend f ∘ pkg'.compare pkg) (pkg'.coe x) = f x := by simp only [Function.comp_apply, compare_coe, IsDenseInducing.extend_eq _ cont_f] apply (IsDenseInducing.extend_unique (AbstractCompletion.isDenseInducing _) this (Continuous.comp _ (uniformContinuous_compare pkg' pkg).continuous )).symm apply IsDenseInducing.continuous_extend exact fun a ↦ ⟨(pkg.isDenseInducing.extend f) a, h a⟩ end Compare section Prod variable (pkg' : AbstractCompletion.{vβ} β) local notation "hatβ" => pkg'.space local notation "ι'" => pkg'.coe /-- Products of completions -/ protected def prod : AbstractCompletion (α × β) where space := hatα × hatβ coe p := ⟨ι p.1, ι' p.2⟩ uniformStruct := inferInstance complete := inferInstance separation := inferInstance isUniformInducing := IsUniformInducing.prod pkg.isUniformInducing pkg'.isUniformInducing dense := pkg.dense.prodMap pkg'.dense end Prod section Extension₂ variable (pkg' : AbstractCompletion.{vβ} β) local notation "hatβ" => pkg'.space local notation "ι'" => pkg'.coe variable {γ : Type uγ} [UniformSpace γ] open Function /-- Extend two variable map to completions. -/ protected def extend₂ (f : α → β → γ) : hatα → hatβ → γ := curry <| (pkg.prod pkg').extend (uncurry f) section T0Space variable [T0Space γ] {f : α → β → γ} theorem extension₂_coe_coe (hf : UniformContinuous <| uncurry f) (a : α) (b : β) : pkg.extend₂ pkg' f (ι a) (ι' b) = f a b := show (pkg.prod pkg').extend (uncurry f) ((pkg.prod pkg').coe (a, b)) = uncurry f (a, b) from (pkg.prod pkg').extend_coe hf _ end T0Space variable {f : α → β → γ} variable [CompleteSpace γ] (f) theorem uniformContinuous_extension₂ : UniformContinuous₂ (pkg.extend₂ pkg' f) := by rw [uniformContinuous₂_def, AbstractCompletion.extend₂, uncurry_curry] apply uniformContinuous_extend end Extension₂ section Map₂ variable (pkg' : AbstractCompletion β) local notation "hatβ" => pkg'.space local notation "ι'" => pkg'.coe variable {γ : Type uγ} [UniformSpace γ] (pkg'' : AbstractCompletion.{vγ} γ) local notation "hatγ" => pkg''.space local notation "ι''" => pkg''.coe local notation f " ∘₂ " g => bicompr f g /-- Lift two variable maps to completions. -/ protected def map₂ (f : α → β → γ) : hatα → hatβ → hatγ := pkg.extend₂ pkg' (pkg''.coe ∘₂ f) theorem uniformContinuous_map₂ (f : α → β → γ) : UniformContinuous₂ (pkg.map₂ pkg' pkg'' f) := AbstractCompletion.uniformContinuous_extension₂ pkg pkg' _ theorem continuous_map₂ {δ} [TopologicalSpace δ] {f : α → β → γ} {a : δ → hatα} {b : δ → hatβ} (ha : Continuous a) (hb : Continuous b) : Continuous fun d : δ => pkg.map₂ pkg' pkg'' f (a d) (b d) := (pkg.uniformContinuous_map₂ pkg' pkg'' f).continuous.comp₂ ha hb theorem map₂_coe_coe (a : α) (b : β) (f : α → β → γ) (hf : UniformContinuous₂ f) : pkg.map₂ pkg' pkg'' f (ι a) (ι' b) = ι'' (f a b) := pkg.extension₂_coe_coe (f := pkg''.coe ∘₂ f) pkg' (pkg''.uniformContinuous_coe.comp hf) a b end Map₂ end AbstractCompletion
falgebra.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 path. From mathcomp Require Import choice fintype div tuple finfun bigop ssralg. From mathcomp Require Import finalg zmodp matrix vector poly. (******************************************************************************) (* Finite dimensional free algebras, usually known as F-algebras *) (* *) (* falgType K == the interface type for F-algebras over K; it simply *) (* joins the unitAlgType K and vectType K interfaces *) (* The HB class is called Falgebra. *) (* Any aT with an falgType structure inherits all the Vector, NzRing and *) (* Algebra operations, and supports the following additional operations: *) (* \dim_A M == (\dim M %/ dim A)%N -- free module dimension *) (* amull u == the linear function v |-> u * v, for u, v : aT *) (* amulr u == the linear function v |-> v * u, for u, v : aT *) (* 1, f * g, f ^+ n == the identity function, the composite g \o f, the nth *) (* iterate of f, for 1, f, g in 'End(aT) *) (* This is just the usual F-algebra structure on *) (* 'End(aT). It is NOT canonical by default, but can be *) (* activated by the line Import FalgLfun. Beware also *) (* that (f^-1)%VF is the linear function inverse, not *) (* the ring inverse of f (though they do coincide when *) (* f is injective). *) (* 1%VS == the line generated by 1 : aT *) (* (U * V)%VS == the smallest subspace of aT that contains all *) (* products u * v for u in U, v in V *) (* (U ^+ n)%VS == (U * U * ... * U), n-times. U ^+ 0 = 1%VS *) (* 'C[u]%VS == the centraliser subspace of the vector u *) (* 'C_U[v]%VS := (U :&: 'C[v])%VS *) (* 'C(V)%VS == the centraliser subspace of the subspace V *) (* 'C_U(V)%VS := (U :&: 'C(V))%VS *) (* 'Z(V)%VS == the center subspace of the subspace V *) (* agenv U == the smallest subalgebra containing U ^+ n for all n *) (* <<U; v>>%VS == agenv (U + <[v]>) (adjoin v to U) *) (* <<U & vs>>%VS == agenv (U + <<vs>>) (adjoin vs to U) *) (* {aspace aT} == a subType of {vspace aT} consisting of sub-algebras *) (* of aT (see below); for A : {aspace aT}, subvs_of A *) (* has a canonical falgType K structure *) (* is_aspace U <=> the characteristic predicate of {aspace aT} stating *) (* that U is closed under product and contains an *) (* identity element, := has_algid U && (U * U <= U)%VS *) (* algid A == the identity element of A : {aspace aT}, which need *) (* not be equal to 1 (indeed, in a Wedderburn *) (* decomposition it is not even a unit in aT) *) (* is_algid U e <-> e : aT is an identity element for the subspace U: *) (* e in U, e != 0 & e * u = u * e = u for all u in U *) (* has_algid U <=> there is an e such that is_algid U e *) (* [aspace of U] == a clone of an existing {aspace aT} structure on *) (* U : {vspace aT} (more instances of {aspace aT} will *) (* be defined in extFieldType) *) (* [aspace of U for A] == a clone of A : {aspace aT} for U : {vspace aT} *) (* 1%AS == the canonical sub-algebra 1%VS *) (* {:aT}%AS == the canonical full algebra *) (* <<U>>%AS == the canonical algebra for agenv U; note that this is *) (* unrelated to <<vs>>%VS, the subspace spanned by vs *) (* <<U; v>>%AS == the canonical algebra for <<U; v>>%VS *) (* <<U & vs>>%AS == the canonical algebra for <<U & vs>>%VS *) (* ahom_in U f <=> f : 'Hom(aT, rT) is a multiplicative homomorphism *) (* inside U, and in addition f 1 = 1 (even if U doesn't *) (* contain 1) *) (* Note that f @: U need not be a subalgebra when U is, *) (* as f could annilate U. *) (* 'AHom(aT, rT) == the type of algebra homomorphisms from aT to rT, *) (* where aT and rT ARE falgType structures. Elements of *) (* 'AHom(aT, rT) coerce to 'End(aT, rT) and aT -> rT *) (* 'AEnd(aT) == algebra endomorphisms of aT (:= 'AHom(aT, aT)) *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope aspace_scope. Declare Scope lrfun_scope. Local Open Scope ring_scope. Reserved Notation "{ 'aspace' T }" (format "{ 'aspace' T }"). Reserved Notation "<< U & vs >>" (format "<< U & vs >>"). Reserved Notation "<< U ; x >>" (format "<< U ; x >>"). Reserved Notation "''AHom' ( T , rT )" (format "''AHom' ( T , rT )"). Reserved Notation "''AEnd' ( T )" (format "''AEnd' ( T )"). Notation "\dim_ E V" := (divn (\dim V) (\dim E)) (at level 10, E at level 2, V at level 8, format "\dim_ E V") : nat_scope. Import GRing.Theory. (* Finite dimensional algebra *) #[short(type="falgType")] HB.structure Definition Falgebra (R : nzRingType) := { A of Vector R A & GRing.UnitAlgebra R A }. #[deprecated(since="mathcomp 2.0.0", note="Use falgType instead.")] Notation FalgType := falgType. (* Supply a default unitRing mixin for the default unitAlgType base type. *) HB.factory Record Algebra_isFalgebra (K : fieldType) A of Vector K A & GRing.Algebra K A := {}. HB.builders Context K A of Algebra_isFalgebra K A. Let vA : Vector.type K := A. Let am u := linfun (u \o* idfun : vA -> vA). Let uam := [pred u | lker (am u) == 0%VS]. Let vam := [fun u => if u \in uam then (am u)^-1%VF 1 else u]. Lemma amE u v : am u v = v * u. Proof. by rewrite lfunE. Qed. Lemma mulVr : {in uam, left_inverse 1 vam *%R}. Proof. by move=> u Uu; rewrite /= Uu -amE lker0_lfunVK. Qed. Lemma divrr : {in uam, right_inverse 1 vam *%R}. Proof. by move=> u Uu; apply/(lker0P Uu); rewrite !amE -mulrA mulVr // mul1r mulr1. Qed. Lemma unitrP : forall x y, y * x = 1 /\ x * y = 1 -> uam x. Proof. move=> u v [_ uv1]. by apply/lker0P=> w1 w2 /(congr1 (am v)); rewrite !amE -!mulrA uv1 !mulr1. Qed. Lemma invr_out : {in [predC uam], vam =1 id}. Proof. by move=> u /negbTE/= ->. Qed. HB.instance Definition _ := GRing.NzRing_hasMulInverse.Build A mulVr divrr unitrP invr_out. HB.end. Module FalgebraExports. Bind Scope ring_scope with sort. End FalgebraExports. HB.export FalgebraExports. Notation "1" := (vline 1) : vspace_scope. HB.instance Definition _ (K : fieldType) n := Algebra_isFalgebra.Build K 'M[K]_n.+1. HB.instance Definition _ (R : comUnitRingType) := GRing.UnitAlgebra.on R^o. (* FIXME: remove once https://github.com/math-comp/hierarchy-builder/issues/197 is fixed *) Lemma regular_fullv (K : fieldType) : (fullv = 1 :> {vspace K^o})%VS. Proof. by apply/esym/eqP; rewrite eqEdim subvf dim_vline oner_eq0 dimvf. Qed. Section Proper. Variables (R : nzRingType) (aT : falgType R). Import VectorInternalTheory. Lemma FalgType_proper : dim aT > 0. Proof. rewrite lt0n; apply: contraNneq (oner_neq0 aT) => aT0. by apply/eqP/v2r_inj; do 2!move: (v2r _); rewrite aT0 => u v; rewrite !thinmx0. Qed. End Proper. Module FalgLfun. Section FalgLfun. Variable (R : comNzRingType) (aT : falgType R). Implicit Types f g : 'End(aT). HB.instance Definition _ := GRing.Algebra.copy 'End(aT) (lfun_algType (FalgType_proper aT)). Lemma lfun_mulE f g u : (f * g) u = g (f u). Proof. exact: lfunE. Qed. Lemma lfun_compE f g : (g \o f)%VF = f * g. Proof. by []. Qed. End FalgLfun. Section InvLfun. Variable (K : fieldType) (aT : falgType K). Implicit Types f g : 'End(aT). Definition lfun_invr f := if lker f == 0%VS then f^-1%VF else f. Lemma lfun_mulVr f : lker f == 0%VS -> f^-1%VF * f = 1. Proof. exact: lker0_compfV. Qed. Lemma lfun_mulrV f : lker f == 0%VS -> f * f^-1%VF = 1. Proof. exact: lker0_compVf. Qed. Fact lfun_mulRVr f : lker f == 0%VS -> lfun_invr f * f = 1. Proof. by move=> Uf; rewrite /lfun_invr Uf lfun_mulVr. Qed. Fact lfun_mulrRV f : lker f == 0%VS -> f * lfun_invr f = 1. Proof. by move=> Uf; rewrite /lfun_invr Uf lfun_mulrV. Qed. Fact lfun_unitrP f g : g * f = 1 /\ f * g = 1 -> lker f == 0%VS. Proof. case=> _ fK; apply/lker0P; apply: can_inj (g) _ => u. by rewrite -lfun_mulE fK lfunE. Qed. Lemma lfun_invr_out f : lker f != 0%VS -> lfun_invr f = f. Proof. by rewrite /lfun_invr => /negPf->. Qed. HB.instance Definition _ := GRing.NzRing_hasMulInverse.Build 'End(aT) lfun_mulRVr lfun_mulrRV lfun_unitrP lfun_invr_out. Lemma lfun_invE f : lker f == 0%VS -> f^-1%VF = f^-1. Proof. by rewrite /f^-1 /= /lfun_invr => ->. Qed. End InvLfun. End FalgLfun. Section FalgebraTheory. Variables (K : fieldType) (aT : falgType K). Implicit Types (u v : aT) (U V W : {vspace aT}). Import FalgLfun. Definition amull u : 'End(aT) := linfun (u \*o @idfun aT). Definition amulr u : 'End(aT) := linfun (u \o* @idfun aT). Lemma amull_inj : injective amull. Proof. by move=> u v /lfunP/(_ 1); rewrite !lfunE /= !mulr1. Qed. Lemma amulr_inj : injective amulr. Proof. by move=> u v /lfunP/(_ 1); rewrite !lfunE /= !mul1r. Qed. Fact amull_is_linear : linear amull. Proof. move=> a u v; apply/lfunP => w. by rewrite !lfunE /= scale_lfunE !lfunE /= mulrDl scalerAl. Qed. #[hnf] HB.instance Definition _ := GRing.isSemilinear.Build K aT (hom aT aT) _ amull (GRing.semilinear_linear amull_is_linear). (* amull is a converse ring morphism *) Lemma amull1 : amull 1 = \1%VF. Proof. by apply/lfunP => z; rewrite id_lfunE lfunE /= mul1r. Qed. Lemma amullM u v : (amull (u * v) = amull v * amull u)%VF. Proof. by apply/lfunP => w; rewrite comp_lfunE !lfunE /= mulrA. Qed. Lemma amulr_is_linear : linear amulr. Proof. move=> a u v; apply/lfunP => w. by rewrite !lfunE /= !lfunE /= lfunE mulrDr /= scalerAr. Qed. Lemma amulr_is_monoid_morphism : monoid_morphism amulr. Proof. split=> [|x y]; first by apply/lfunP => w; rewrite id_lfunE !lfunE /= mulr1. by apply/lfunP=> w; rewrite comp_lfunE !lfunE /= mulrA. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `amulr_is_monoid_morphism` instead")] Definition amulr_is_multiplicative := (fun p => (p.2, p.1)) amulr_is_monoid_morphism. #[hnf] HB.instance Definition _ := GRing.isSemilinear.Build K aT (hom aT aT) _ amulr (GRing.semilinear_linear amulr_is_linear). #[hnf] HB.instance Definition _ := GRing.isMonoidMorphism.Build aT (hom aT aT) amulr amulr_is_monoid_morphism. Lemma lker0_amull u : u \is a GRing.unit -> lker (amull u) == 0%VS. Proof. by move=> Uu; apply/lker0P=> v w; rewrite !lfunE; apply: mulrI. Qed. Lemma lker0_amulr u : u \is a GRing.unit -> lker (amulr u) == 0%VS. Proof. by move=> Uu; apply/lker0P=> v w; rewrite !lfunE; apply: mulIr. Qed. Lemma lfun1_poly (p : {poly aT}) : map_poly \1%VF p = p. Proof. by apply: map_poly_id => u _; apply: id_lfunE. Qed. Fact prodv_key : unit. Proof. by []. Qed. Definition prodv := locked_with prodv_key (fun U V => <<allpairs *%R (vbasis U) (vbasis V)>>%VS). Canonical prodv_unlockable := [unlockable fun prodv]. Local Notation "A * B" := (prodv A B) : vspace_scope. Lemma memv_mul U V : {in U & V, forall u v, u * v \in (U * V)%VS}. Proof. move=> u v /coord_vbasis-> /coord_vbasis->. rewrite mulr_suml; apply: memv_suml => i _. rewrite mulr_sumr; apply: memv_suml => j _. rewrite -scalerAl -scalerAr !memvZ // [prodv]unlock memv_span //. by apply/allpairsP; exists ((vbasis U)`_i, (vbasis V)`_j); rewrite !memt_nth. Qed. Lemma prodvP {U V W} : reflect {in U & V, forall u v, u * v \in W} (U * V <= W)%VS. Proof. apply: (iffP idP) => [sUVW u v Uu Vv | sUVW]. by rewrite (subvP sUVW) ?memv_mul. rewrite [prodv]unlock; apply/span_subvP=> _ /allpairsP[[u v] /= [Uu Vv ->]]. by rewrite sUVW ?vbasis_mem. Qed. Lemma prodv_line u v : (<[u]> * <[v]> = <[u * v]>)%VS. Proof. apply: subv_anti; rewrite -memvE memv_mul ?memv_line // andbT. apply/prodvP=> _ _ /vlineP[a ->] /vlineP[b ->]. by rewrite -scalerAr -scalerAl !memvZ ?memv_line. Qed. Lemma dimv1: \dim (1%VS : {vspace aT}) = 1. Proof. by rewrite dim_vline oner_neq0. Qed. Lemma dim_prodv U V : \dim (U * V) <= \dim U * \dim V. Proof. by rewrite unlock (leq_trans (dim_span _)) ?size_tuple. Qed. Lemma vspace1_neq0 : (1 != 0 :> {vspace aT})%VS. Proof. by rewrite -dimv_eq0 dimv1. Qed. Lemma vbasis1 : exists2 k, k != 0 & vbasis 1 = [:: k%:A] :> seq aT. Proof. move: (vbasis 1) (@vbasisP K aT 1); rewrite dim_vline oner_neq0. case/tupleP=> x X0; rewrite {X0}tuple0 => defX; have Xx := mem_head x nil. have /vlineP[k def_x] := basis_mem defX Xx; exists k; last by rewrite def_x. by have:= basis_not0 defX Xx; rewrite def_x scaler_eq0 oner_eq0 orbF. Qed. Lemma prod0v : left_zero 0%VS prodv. Proof. move=> U; apply/eqP; rewrite -dimv_eq0 -leqn0 (leq_trans (dim_prodv 0 U)) //. by rewrite dimv0. Qed. Lemma prodv0 : right_zero 0%VS prodv. Proof. move=> U; apply/eqP; rewrite -dimv_eq0 -leqn0 (leq_trans (dim_prodv U 0)) //. by rewrite dimv0 muln0. Qed. HB.instance Definition _ := Monoid.isMulLaw.Build {vspace aT} 0%VS prodv prod0v prodv0. Lemma prod1v : left_id 1%VS prodv. Proof. move=> U; apply/subv_anti/andP; split. by apply/prodvP=> _ u /vlineP[a ->] Uu; rewrite mulr_algl memvZ. by apply/subvP=> u Uu; rewrite -[u]mul1r memv_mul ?memv_line. Qed. Lemma prodv1 : right_id 1%VS prodv. Proof. move=> U; apply/subv_anti/andP; split. by apply/prodvP=> u _ Uu /vlineP[a ->]; rewrite mulr_algr memvZ. by apply/subvP=> u Uu; rewrite -[u]mulr1 memv_mul ?memv_line. Qed. Lemma prodvS U1 U2 V1 V2 : (U1 <= U2 -> V1 <= V2 -> U1 * V1 <= U2 * V2)%VS. Proof. move/subvP=> sU12 /subvP sV12; apply/prodvP=> u v Uu Vv. by rewrite memv_mul ?sU12 ?sV12. Qed. Lemma prodvSl U1 U2 V : (U1 <= U2 -> U1 * V <= U2 * V)%VS. Proof. by move/prodvS->. Qed. Lemma prodvSr U V1 V2 : (V1 <= V2 -> U * V1 <= U * V2)%VS. Proof. exact: prodvS. Qed. Lemma prodvDl : left_distributive prodv addv. Proof. move=> U1 U2 V; apply/esym/subv_anti/andP; split. by rewrite subv_add 2?prodvS ?addvSl ?addvSr. apply/prodvP=> _ v /memv_addP[u1 Uu1 [u2 Uu2 ->]] Vv. by rewrite mulrDl memv_add ?memv_mul. Qed. Lemma prodvDr : right_distributive prodv addv. Proof. move=> U V1 V2; apply/esym/subv_anti/andP; split. by rewrite subv_add 2?prodvS ?addvSl ?addvSr. apply/prodvP=> u _ Uu /memv_addP[v1 Vv1 [v2 Vv2 ->]]. by rewrite mulrDr memv_add ?memv_mul. Qed. HB.instance Definition _ := Monoid.isAddLaw.Build {vspace aT} prodv addv prodvDl prodvDr. Lemma prodvA : associative prodv. Proof. move=> U V W; rewrite -(span_basis (vbasisP U)) span_def !big_distrl /=. apply: eq_bigr => u _; rewrite -(span_basis (vbasisP W)) span_def !big_distrr. apply: eq_bigr => w _; rewrite -(span_basis (vbasisP V)) span_def /=. rewrite !(big_distrl, big_distrr) /=; apply: eq_bigr => v _. by rewrite !prodv_line mulrA. Qed. HB.instance Definition _ := Monoid.isLaw.Build {vspace aT} 1%VS prodv prodvA prod1v prodv1. Definition expv U n := iterop n.+1.-1 prodv U 1%VS. Local Notation "A ^+ n" := (expv A n) : vspace_scope. Lemma expv0 U : (U ^+ 0 = 1)%VS. Proof. by []. Qed. Lemma expv1 U : (U ^+ 1 = U)%VS. Proof. by []. Qed. Lemma expv2 U : (U ^+ 2 = U * U)%VS. Proof. by []. Qed. Lemma expvSl U n : (U ^+ n.+1 = U * U ^+ n)%VS. Proof. by case: n => //; rewrite prodv1. Qed. Lemma expv0n n : (0 ^+ n = if n is _.+1 then 0 else 1)%VS. Proof. by case: n => // n; rewrite expvSl prod0v. Qed. Lemma expv1n n : (1 ^+ n = 1)%VS. Proof. by elim: n => // n IHn; rewrite expvSl IHn prodv1. Qed. Lemma expvD U m n : (U ^+ (m + n) = U ^+ m * U ^+ n)%VS. Proof. by elim: m => [|m IHm]; rewrite ?prod1v // !expvSl IHm prodvA. Qed. Lemma expvSr U n : (U ^+ n.+1 = U ^+ n * U)%VS. Proof. by rewrite -addn1 expvD. Qed. Lemma expvM U m n : (U ^+ (m * n) = U ^+ m ^+ n)%VS. Proof. by elim: n => [|n IHn]; rewrite ?muln0 // mulnS expvD IHn expvSl. Qed. Lemma expvS U V n : (U <= V -> U ^+ n <= V ^+ n)%VS. Proof. move=> sUV; elim: n => [|n IHn]; first by rewrite !expv0 subvv. by rewrite !expvSl prodvS. Qed. Lemma expv_line u n : (<[u]> ^+ n = <[u ^+ n]>)%VS. Proof. elim: n => [|n IH]; first by rewrite expr0 expv0. by rewrite exprS expvSl IH prodv_line. Qed. (* Centralisers and centers. *) Definition centraliser1_vspace u := lker (amulr u - amull u). Local Notation "'C [ u ]" := (centraliser1_vspace u) : vspace_scope. Definition centraliser_vspace V := (\bigcap_i 'C[tnth (vbasis V) i])%VS. Local Notation "'C ( V )" := (centraliser_vspace V) : vspace_scope. Definition center_vspace V := (V :&: 'C(V))%VS. Local Notation "'Z ( V )" := (center_vspace V) : vspace_scope. Lemma cent1vP u v : reflect (u * v = v * u) (u \in 'C[v]%VS). Proof. by rewrite (sameP eqlfunP eqP) !lfunE /=; apply: eqP. Qed. Lemma cent1v1 u : 1 \in 'C[u]%VS. Proof. by apply/cent1vP; rewrite commr1. Qed. Lemma cent1v_id u : u \in 'C[u]%VS. Proof. exact/cent1vP. Qed. Lemma cent1vX u n : u ^+ n \in 'C[u]%VS. Proof. exact/cent1vP/esym/commrX. Qed. Lemma cent1vC u v : (u \in 'C[v])%VS = (v \in 'C[u])%VS. Proof. exact/cent1vP/cent1vP. Qed. Lemma centvP u V : reflect {in V, forall v, u * v = v * u} (u \in 'C(V))%VS. Proof. apply: (iffP subv_bigcapP) => [cVu y /coord_vbasis-> | cVu i _]. apply/esym/cent1vP/rpred_sum=> i _; apply: rpredZ. by rewrite -tnth_nth cent1vC memvE cVu. exact/cent1vP/cVu/vbasis_mem/mem_tnth. Qed. Lemma centvsP U V : reflect {in U & V, commutative *%R} (U <= 'C(V))%VS. Proof. by apply: (iffP subvP) => [cUV u v | cUV u] /cUV-/centvP; apply. Qed. Lemma subv_cent1 U v : (U <= 'C[v])%VS = (v \in 'C(U)%VS). Proof. by apply/subvP/centvP=> cUv u Uu; apply/cent1vP; rewrite 1?cent1vC cUv. Qed. Lemma centv1 V : 1 \in 'C(V)%VS. Proof. by apply/centvP=> v _; rewrite commr1. Qed. Lemma centvX V u n : u \in 'C(V)%VS -> u ^+ n \in 'C(V)%VS. Proof. by move/centvP=> cVu; apply/centvP=> v /cVu/esym/commrX->. Qed. Lemma centvC U V : (U <= 'C(V))%VS = (V <= 'C(U))%VS. Proof. by apply/centvsP/centvsP=> cUV u v UVu /cUV->. Qed. Lemma centerv_sub V : ('Z(V) <= V)%VS. Proof. exact: capvSl. Qed. Lemma cent_centerv V : (V <= 'C('Z(V)))%VS. Proof. by rewrite centvC capvSr. Qed. (* Building the predicate that checks is a vspace has a unit *) Definition is_algid e U := [/\ e \in U, e != 0 & {in U, forall u, e * u = u /\ u * e = u}]. Fact algid_decidable U : decidable (exists e, is_algid e U). Proof. have [-> | nzU] := eqVneq U 0%VS. by right=> [[e []]]; rewrite memv0 => ->. pose X := vbasis U; pose feq f1 f2 := [tuple of map f1 X ++ map f2 X]. have feqL f i: tnth (feq _ f _) (lshift _ i) = f X`_i. set v := f _; rewrite (tnth_nth v) /= nth_cat size_map size_tuple. by rewrite ltn_ord (nth_map 0) ?size_tuple. have feqR f i: tnth (feq _ _ f) (rshift _ i) = f X`_i. set v := f _; rewrite (tnth_nth v) /= nth_cat size_map size_tuple. by rewrite ltnNge leq_addr addKn /= (nth_map 0) ?size_tuple. apply: decP (vsolve_eq (feq _ amulr amull) (feq _ id id) U) _. apply: (iffP (vsolve_eqP _ _ _)) => [[e Ue id_e] | [e [Ue _ id_e]]]. suffices idUe: {in U, forall u, e * u = u /\ u * e = u}. exists e; split=> //; apply: contraNneq nzU => e0; rewrite -subv0. by apply/subvP=> u /idUe[<- _]; rewrite e0 mul0r mem0v. move=> u /coord_vbasis->; rewrite mulr_sumr mulr_suml. split; apply/eq_bigr=> i _; rewrite -(scalerAr, scalerAl); congr (_ *: _). by have:= id_e (lshift _ i); rewrite !feqL lfunE. by have:= id_e (rshift _ i); rewrite !feqR lfunE. have{id_e} /all_and2[ideX idXe]:= id_e _ (vbasis_mem (mem_tnth _ X)). exists e => // k; rewrite -[k]splitK. by case: (split k) => i; rewrite !(feqL, feqR) lfunE /= -tnth_nth. Qed. Definition has_algid : pred {vspace aT} := algid_decidable. Lemma has_algidP {U} : reflect (exists e, is_algid e U) (has_algid U). Proof. exact: sumboolP. Qed. Lemma has_algid1 U : 1 \in U -> has_algid U. Proof. move=> U1; apply/has_algidP; exists 1; split; rewrite ?oner_eq0 // => u _. by rewrite mulr1 mul1r. Qed. Definition is_aspace U := has_algid U && (U * U <= U)%VS. Structure aspace := ASpace {asval :> {vspace aT}; _ : is_aspace asval}. HB.instance Definition _ := [isSub for asval]. HB.instance Definition _ := [Choice of aspace by <:]. Definition clone_aspace U (A : aspace) := fun algU & phant_id algU (valP A) => @ASpace U algU : aspace. Fact aspace1_subproof : is_aspace 1. Proof. by rewrite /is_aspace prod1v -memvE has_algid1 memv_line. Qed. Canonical aspace1 : aspace := ASpace aspace1_subproof. Lemma aspacef_subproof : is_aspace fullv. Proof. by rewrite /is_aspace subvf has_algid1 ?memvf. Qed. Canonical aspacef : aspace := ASpace aspacef_subproof. Lemma polyOver1P p : reflect (exists q, p = map_poly (in_alg aT) q) (p \is a polyOver 1%VS). Proof. apply: (iffP idP) => [/allP/=Qp | [q ->]]; last first. by apply/polyOverP=> j; rewrite coef_map rpredZ ?memv_line. exists (map_poly (coord [tuple 1] 0) p). rewrite -map_poly_comp map_poly_id // => _ /Qp/vlineP[a ->] /=. by rewrite linearZ /= (coord_free 0) ?mulr1 // seq1_free ?oner_eq0. Qed. End FalgebraTheory. Delimit Scope aspace_scope with AS. Bind Scope aspace_scope with aspace. Arguments asval {K aT} a%_AS. Arguments aspace [K]%_type aT%_type. Arguments clone_aspace [K aT U%_VS A%_AS algU] _. Notation "{ 'aspace' T }" := (aspace T) : type_scope. Notation "A * B" := (prodv A B) : vspace_scope. Notation "A ^+ n" := (expv A n) : vspace_scope. Notation "'C [ u ]" := (centraliser1_vspace u) : vspace_scope. Notation "'C_ U [ v ]" := (capv U 'C[v]) : vspace_scope. Notation "'C_ ( U ) [ v ]" := (capv U 'C[v]) (only parsing) : vspace_scope. Notation "'C ( V )" := (centraliser_vspace V) : vspace_scope. Notation "'C_ U ( V )" := (capv U 'C(V)) : vspace_scope. Notation "'C_ ( U ) ( V )" := (capv U 'C(V)) (only parsing) : vspace_scope. Notation "'Z ( V )" := (center_vspace V) : vspace_scope. Notation "1" := (aspace1 _) : aspace_scope. Notation "{ : aT }" := (aspacef aT) : aspace_scope. Notation "[ 'aspace' 'of' U ]" := (@clone_aspace _ _ U _ _ id) (format "[ 'aspace' 'of' U ]") : form_scope. Notation "[ 'aspace' 'of' U 'for' A ]" := (@clone_aspace _ _ U A _ idfun) (format "[ 'aspace' 'of' U 'for' A ]") : form_scope. Arguments prodvP {K aT U V W}. Arguments cent1vP {K aT u v}. Arguments centvP {K aT u V}. Arguments centvsP {K aT U V}. Arguments has_algidP {K aT U}. Arguments polyOver1P {K aT p}. Section AspaceTheory. Variables (K : fieldType) (aT : falgType K). Implicit Types (u v e : aT) (U V : {vspace aT}) (A B : {aspace aT}). Import FalgLfun. Lemma algid_subproof U : {e | e \in U & has_algid U ==> (U <= lker (amull e - 1) :&: lker (amulr e - 1))%VS}. Proof. apply: sig2W; case: has_algidP => [[e]|]; last by exists 0; rewrite ?mem0v. case=> Ae _ idAe; exists e => //; apply/subvP=> u /idAe[eu_u ue_u]. by rewrite memv_cap !memv_ker !lfun_simp /= eu_u ue_u subrr eqxx. Qed. Definition algid U := s2val (algid_subproof U). Lemma memv_algid U : algid U \in U. Proof. by rewrite /algid; case: algid_subproof. Qed. Lemma algidl A : {in A, left_id (algid A) *%R}. Proof. rewrite /algid; case: algid_subproof => e _ /=; have /andP[-> _] := valP A. move/subvP=> idAe u /idAe/memv_capP[]. by rewrite memv_ker !lfun_simp /= subr_eq0 => /eqP. Qed. Lemma algidr A : {in A, right_id (algid A) *%R}. Proof. rewrite /algid; case: algid_subproof => e _ /=; have /andP[-> _] := valP A. move/subvP=> idAe u /idAe/memv_capP[_]. by rewrite memv_ker !lfun_simp /= subr_eq0 => /eqP. Qed. Lemma unitr_algid1 A u : u \in A -> u \is a GRing.unit -> algid A = 1. Proof. by move=> Eu /mulrI; apply; rewrite mulr1 algidr. Qed. Lemma algid_eq1 A : (algid A == 1) = (1 \in A). Proof. by apply/eqP/idP=> [<- | /algidr <-]; rewrite ?memv_algid ?mul1r. Qed. Lemma algid_neq0 A : algid A != 0. Proof. have /andP[/has_algidP[u [Au nz_u _]] _] := valP A. by apply: contraNneq nz_u => e0; rewrite -(algidr Au) e0 mulr0. Qed. Lemma dim_algid A : \dim <[algid A]> = 1%N. Proof. by rewrite dim_vline algid_neq0. Qed. Lemma adim_gt0 A : (0 < \dim A)%N. Proof. by rewrite -(dim_algid A) dimvS // -memvE ?memv_algid. Qed. Lemma not_asubv0 A : ~~ (A <= 0)%VS. Proof. by rewrite subv0 -dimv_eq0 -lt0n adim_gt0. Qed. Lemma adim1P {A} : reflect (A = <[algid A]>%VS :> {vspace aT}) (\dim A == 1%N). Proof. rewrite eqn_leq adim_gt0 -(memv_algid A) andbC -(dim_algid A) -eqEdim eq_sym. exact: eqP. Qed. Lemma asubv A : (A * A <= A)%VS. Proof. by have /andP[] := valP A. Qed. Lemma memvM A : {in A &, forall u v, u * v \in A}. Proof. exact/prodvP/asubv. Qed. Lemma prodv_id A : (A * A)%VS = A. Proof. apply/eqP; rewrite eqEsubv asubv; apply/subvP=> u Au. by rewrite -(algidl Au) memv_mul // memv_algid. Qed. Lemma prodv_sub U V A : (U <= A -> V <= A -> U * V <= A)%VS. Proof. by move=> sUA sVA; rewrite -prodv_id prodvS. Qed. Lemma expv_id A n : (A ^+ n.+1)%VS = A. Proof. by elim: n => // n IHn; rewrite !expvSl prodvA prodv_id -expvSl. Qed. Lemma limg_amulr U v : (amulr v @: U = U * <[v]>)%VS. Proof. rewrite -(span_basis (vbasisP U)) limg_span !span_def big_distrl /= big_map. by apply: eq_bigr => u; rewrite prodv_line lfunE. Qed. Lemma memv_cosetP {U v w} : reflect (exists2 u, u\in U & w = u * v) (w \in U * <[v]>)%VS. Proof. rewrite -limg_amulr. by apply: (iffP memv_imgP) => [] [u] Uu ->; exists u; rewrite ?lfunE. Qed. Lemma dim_cosetv_unit V u : u \is a GRing.unit -> \dim (V * <[u]>) = \dim V. Proof. by move/lker0_amulr/eqP=> Uu; rewrite -limg_amulr limg_dim_eq // Uu capv0. Qed. Lemma memvV A u : (u^-1 \in A) = (u \in A). Proof. suffices{u} invA: invr_closed A by apply/idP/idP=> /invA; rewrite ?invrK. move=> u Au; have [Uu | /invr_out-> //] := boolP (u \is a GRing.unit). rewrite memvE -(limg_ker0 _ _ (lker0_amulr Uu)) limg_line lfunE /= mulVr //. suff ->: (amulr u @: A)%VS = A by rewrite -memvE -algid_eq1 (unitr_algid1 Au). by apply/eqP; rewrite limg_amulr -dimv_leqif_eq ?prodv_sub ?dim_cosetv_unit. Qed. Fact aspace_cap_subproof A B : algid A \in B -> is_aspace (A :&: B). Proof. move=> BeA; apply/andP. split; [apply/has_algidP | by rewrite subv_cap !prodv_sub ?capvSl ?capvSr]. exists (algid A); rewrite /is_algid algid_neq0 memv_cap memv_algid. by split=> // u /memv_capP[Au _]; rewrite ?algidl ?algidr. Qed. Definition aspace_cap A B BeA := ASpace (@aspace_cap_subproof A B BeA). Fact centraliser1_is_aspace u : is_aspace 'C[u]. Proof. rewrite /is_aspace has_algid1 ?cent1v1 //=. apply/prodvP=> v w /cent1vP-cuv /cent1vP-cuw. by apply/cent1vP; rewrite -mulrA cuw !mulrA cuv. Qed. Canonical centraliser1_aspace u := ASpace (centraliser1_is_aspace u). Fact centraliser_is_aspace V : is_aspace 'C(V). Proof. rewrite /is_aspace has_algid1 ?centv1 //=. apply/prodvP=> u w /centvP-cVu /centvP-cVw. by apply/centvP=> v Vv; rewrite /= -mulrA cVw // !mulrA cVu. Qed. Canonical centraliser_aspace V := ASpace (centraliser_is_aspace V). Lemma centv_algid A : algid A \in 'C(A)%VS. Proof. by apply/centvP=> u Au; rewrite algidl ?algidr. Qed. Canonical center_aspace A := [aspace of 'Z(A) for aspace_cap (centv_algid A)]. Lemma algid_center A : algid 'Z(A) = algid A. Proof. rewrite -(algidl (subvP (centerv_sub A) _ (memv_algid _))) algidr //=. by rewrite memv_cap memv_algid centv_algid. Qed. Lemma Falgebra_FieldMixin : GRing.integral_domain_axiom aT -> GRing.field_axiom aT. Proof. move=> domT u nz_u; apply/unitrP. have kerMu: lker (amulr u) == 0%VS. rewrite eqEsubv sub0v andbT; apply/subvP=> v; rewrite memv_ker lfunE /=. by move/eqP/domT; rewrite (negPf nz_u) orbF memv0. have /memv_imgP[v _ vu1]: 1 \in limg (amulr u); last rewrite lfunE /= in vu1. suffices /eqP->: limg (amulr u) == fullv by rewrite memvf. by rewrite -dimv_leqif_eq ?subvf ?limg_dim_eq // (eqP kerMu) capv0. exists v; split=> //; apply: (lker0P kerMu). by rewrite !lfunE /= -mulrA -vu1 mulr1 mul1r. Qed. Section SkewField. Hypothesis fieldT : GRing.field_axiom aT. Lemma skew_field_algid1 A : algid A = 1. Proof. by rewrite (unitr_algid1 (memv_algid A)) ?fieldT ?algid_neq0. Qed. Lemma skew_field_module_semisimple A M : let sumA X := (\sum_(x <- X) A * <[x]>)%VS in (A * M <= M)%VS -> {X | [/\ sumA X = M, directv (sumA X) & 0 \notin X]}. Proof. move=> sumA sAM_M; pose X := Nil aT; pose k := (\dim (A * M) - \dim (sumA X))%N. have: (\dim (A * M) - \dim (sumA X) < k.+1)%N by []. have: [/\ (sumA X <= A * M)%VS, directv (sumA X) & 0 \notin X]. by rewrite /sumA directvE /= !big_nil sub0v dimv0. elim: {X k}k.+1 (X) => // k IHk X [sAX_AM dxAX nzX]; rewrite ltnS => leAXk. have [sM_AX | /subvPn/sig2W[y My notAXy]] := boolP (M <= sumA X)%VS. by exists X; split=> //; apply/eqP; rewrite eqEsubv (subv_trans sAX_AM). have nz_y: y != 0 by rewrite (memPnC notAXy) ?mem0v. pose AY := sumA (y :: X). have sAY_AM: (AY <= A * M)%VS by rewrite [AY]big_cons subv_add ?prodvSr. have dxAY: directv AY. rewrite directvE /= !big_cons [_ == _]directv_addE dxAX directvE eqxx /=. rewrite -/(sumA X) eqEsubv sub0v andbT -limg_amulr. apply/subvP=> _ /memv_capP[/memv_imgP[a Aa ->]]/[!lfunE]/= AXay. rewrite memv0 (mulIr_eq0 a (mulIr _)) ?fieldT //. apply: contraR notAXy => /fieldT-Ua; rewrite -[y](mulKr Ua) /sumA. by rewrite -big_distrr -(prodv_id A) /= -prodvA big_distrr memv_mul ?memvV. apply: (IHk (y :: X)); first by rewrite !inE eq_sym negb_or nz_y. rewrite -subSn ?dimvS // (directvP dxAY) /= big_cons -(directvP dxAX) /=. rewrite subnDA (leq_trans _ leAXk) ?leq_sub2r // leq_subLR -add1n leq_add2r. by rewrite dim_cosetv_unit ?fieldT ?adim_gt0. Qed. Lemma skew_field_module_dimS A M : (A * M <= M)%VS -> \dim A %| \dim M. Proof. case/skew_field_module_semisimple=> X [<- /directvP-> nzX] /=. rewrite big_seq prime.dvdn_sum // => x /(memPn nzX)nz_x. by rewrite dim_cosetv_unit ?fieldT. Qed. Lemma skew_field_dimS A B : (A <= B)%VS -> \dim A %| \dim B. Proof. by move=> sAB; rewrite skew_field_module_dimS ?prodv_sub. Qed. End SkewField. End AspaceTheory. (* Note that local centraliser might not be proper sub-algebras. *) Notation "'C [ u ]" := (centraliser1_aspace u) : aspace_scope. Notation "'C ( V )" := (centraliser_aspace V) : aspace_scope. Notation "'Z ( A )" := (center_aspace A) : aspace_scope. Arguments adim1P {K aT A}. Arguments memv_cosetP {K aT U v w}. Section Closure. Variables (K : fieldType) (aT : falgType K). Implicit Types (u v : aT) (U V W : {vspace aT}). (* Subspaces of an F-algebra form a Kleene algebra *) Definition agenv U := (\sum_(i < \dim {:aT}) U ^+ i)%VS. Local Notation "<< U & vs >>" := (agenv (U + <<vs>>)) : vspace_scope. Local Notation "<< U ; x >>" := (agenv (U + <[x]>)) : vspace_scope. Lemma agenvEl U : agenv U = (1 + U * agenv U)%VS. Proof. pose f V := (1 + U * V)%VS; rewrite -/(f _); pose n := \dim {:aT}. have ->: agenv U = iter n f 0%VS. rewrite /agenv -/n; elim: n => [|n IHn]; first by rewrite big_ord0. rewrite big_ord_recl /= -{}IHn; congr (1 + _)%VS; rewrite big_distrr /=. by apply: eq_bigr => i; rewrite expvSl. have fS i j: i <= j -> (iter i f 0 <= iter j f 0)%VS. by elim: i j => [|i IHi] [|j] leij; rewrite ?sub0v //= addvS ?prodvSr ?IHi. suffices /(@trajectP _ f _ n.+1)[i le_i_n Dfi]: looping f 0%VS n.+1. by apply/eqP; rewrite eqEsubv -iterS fS // Dfi fS. apply: contraLR (dimvS (subvf (iter n.+1 f 0%VS))); rewrite -/n -ltnNge. rewrite -looping_uniq; elim: n.+1 => // i IHi; rewrite trajectSr rcons_uniq. rewrite {1}trajectSr mem_rcons inE negb_or eq_sym eqEdim fS ?leqW // -ltnNge. by rewrite -andbA => /and3P[lt_fi _ /IHi/leq_ltn_trans->]. Qed. Lemma agenvEr U : agenv U = (1 + agenv U * U)%VS. Proof. rewrite [lhs in lhs = _]agenvEl big_distrr big_distrl /=; congr (_ + _)%VS. by apply: eq_bigr => i _ /=; rewrite -expvSr -expvSl. Qed. Lemma agenv_modl U V : (U * V <= V -> agenv U * V <= V)%VS. Proof. rewrite big_distrl /= => idlU_V; apply/subv_sumP=> [[i _] /= _]. elim: i => [|i]; first by rewrite expv0 prod1v. by apply: subv_trans; rewrite expvSr -prodvA prodvSr. Qed. Lemma agenv_modr U V : (V * U <= V -> V * agenv U <= V)%VS. Proof. rewrite big_distrr /= => idrU_V; apply/subv_sumP=> [[i _] /= _]. elim: i => [|i]; first by rewrite expv0 prodv1. by apply: subv_trans; rewrite expvSl prodvA prodvSl. Qed. Fact agenv_is_aspace U : is_aspace (agenv U). Proof. rewrite /is_aspace has_algid1; last by rewrite memvE agenvEl addvSl. by rewrite agenv_modl // [V in (_ <= V)%VS]agenvEl addvSr. Qed. Canonical agenv_aspace U : {aspace aT} := ASpace (agenv_is_aspace U). Lemma agenvE U : agenv U = agenv_aspace U. Proof. by []. Qed. (* Kleene algebra properties *) Lemma agenvM U : (agenv U * agenv U)%VS = agenv U. Proof. exact: prodv_id. Qed. Lemma agenvX n U : (agenv U ^+ n.+1)%VS = agenv U. Proof. exact: expv_id. Qed. Lemma sub1_agenv U : (1 <= agenv U)%VS. Proof. by rewrite agenvEl addvSl. Qed. Lemma sub_agenv U : (U <= agenv U)%VS. Proof. by rewrite 2!agenvEl addvC prodvDr prodv1 -addvA addvSl. Qed. Lemma subX_agenv U n : (U ^+ n <= agenv U)%VS. Proof. by case: n => [|n]; rewrite ?sub1_agenv // -(agenvX n) expvS // sub_agenv. Qed. Lemma agenv_sub_modl U V : (1 <= V -> U * V <= V -> agenv U <= V)%VS. Proof. move=> s1V /agenv_modl; apply: subv_trans. by rewrite -[Us in (Us <= _)%VS]prodv1 prodvSr. Qed. Lemma agenv_sub_modr U V : (1 <= V -> V * U <= V -> agenv U <= V)%VS. Proof. move=> s1V /agenv_modr; apply: subv_trans. by rewrite -[Us in (Us <= _)%VS]prod1v prodvSl. Qed. Lemma agenv_id U : agenv (agenv U) = agenv U. Proof. apply/eqP; rewrite eqEsubv sub_agenv andbT. by rewrite agenv_sub_modl ?sub1_agenv ?agenvM. Qed. Lemma agenvS U V : (U <= V -> agenv U <= agenv V)%VS. Proof. move=> sUV; rewrite agenv_sub_modl ?sub1_agenv //. by rewrite -[Vs in (_ <= Vs)%VS]agenvM prodvSl ?(subv_trans sUV) ?sub_agenv. Qed. Lemma agenv_add_id U V : agenv (agenv U + V) = agenv (U + V). Proof. apply/eqP; rewrite eqEsubv andbC agenvS ?addvS ?sub_agenv //=. rewrite agenv_sub_modl ?sub1_agenv //. rewrite -[rhs in (_ <= rhs)%VS]agenvM prodvSl // subv_add agenvS ?addvSl //=. exact: subv_trans (addvSr U V) (sub_agenv _). Qed. Lemma subv_adjoin U x : (U <= <<U; x>>)%VS. Proof. by rewrite (subv_trans (sub_agenv _)) ?agenvS ?addvSl. Qed. Lemma subv_adjoin_seq U xs : (U <= <<U & xs>>)%VS. Proof. by rewrite (subv_trans (sub_agenv _)) // ?agenvS ?addvSl. Qed. Lemma memv_adjoin U x : x \in <<U; x>>%VS. Proof. by rewrite memvE (subv_trans (sub_agenv _)) ?agenvS ?addvSr. Qed. Lemma seqv_sub_adjoin U xs : {subset xs <= <<U & xs>>%VS}. Proof. by apply/span_subvP; rewrite (subv_trans (sub_agenv _)) ?agenvS ?addvSr. Qed. Lemma subvP_adjoin U x y : y \in U -> y \in <<U; x>>%VS. Proof. exact/subvP/subv_adjoin. Qed. Lemma adjoin_nil V : <<V & [::]>>%VS = agenv V. Proof. by rewrite span_nil addv0. Qed. Lemma adjoin_cons V x rs : <<V & x :: rs>>%VS = << <<V; x>> & rs>>%VS. Proof. by rewrite span_cons addvA agenv_add_id. Qed. Lemma adjoin_rcons V rs x : <<V & rcons rs x>>%VS = << <<V & rs>>%VS; x>>%VS. Proof. by rewrite -cats1 span_cat addvA span_seq1 agenv_add_id. Qed. Lemma adjoin_seq1 V x : <<V & [:: x]>>%VS = <<V; x>>%VS. Proof. by rewrite adjoin_cons adjoin_nil agenv_id. Qed. Lemma adjoinC V x y : << <<V; x>>; y>>%VS = << <<V; y>>; x>>%VS. Proof. by rewrite !agenv_add_id -!addvA (addvC <[x]>%VS). Qed. Lemma adjoinSl U V x : (U <= V -> <<U; x>> <= <<V; x>>)%VS. Proof. by move=> sUV; rewrite agenvS ?addvS. Qed. Lemma adjoin_seqSl U V rs : (U <= V -> <<U & rs>> <= <<V & rs>>)%VS. Proof. by move=> sUV; rewrite agenvS ?addvS. Qed. Lemma adjoin_seqSr U rs1 rs2 : {subset rs1 <= rs2} -> (<<U & rs1>> <= <<U & rs2>>)%VS. Proof. by move/sub_span=> s_rs12; rewrite agenvS ?addvS. Qed. End Closure. Notation "<< U >>" := (agenv_aspace U) : aspace_scope. Notation "<< U & vs >>" := (agenv (U + <<vs>>)) : vspace_scope. Notation "<< U ; x >>" := (agenv (U + <[x]>)) : vspace_scope. Notation "<< U & vs >>" := << U + <<vs>> >>%AS : aspace_scope. Notation "<< U ; x >>" := << U + <[x]> >>%AS : aspace_scope. Section SubFalgType. (* The falgType structure of subvs_of A for A : {aspace aT}. *) (* We can't use the rpred-based mixin, because A need not contain 1. *) Variable (K : fieldType) (aT : falgType K) (A : {aspace aT}). Definition subvs_one := Subvs (memv_algid A). Definition subvs_mul (u v : subvs_of A) := Subvs (subv_trans (memv_mul (subvsP u) (subvsP v)) (asubv _)). Fact subvs_mulA : associative subvs_mul. Proof. by move=> x y z; apply/val_inj/mulrA. Qed. Fact subvs_mu1l : left_id subvs_one subvs_mul. Proof. by move=> x; apply/val_inj/algidl/(valP x). Qed. Fact subvs_mul1 : right_id subvs_one subvs_mul. Proof. by move=> x; apply/val_inj/algidr/(valP x). Qed. Fact subvs_mulDl : left_distributive subvs_mul +%R. Proof. move=> x y z; apply/val_inj/mulrDl. Qed. Fact subvs_mulDr : right_distributive subvs_mul +%R. Proof. move=> x y z; apply/val_inj/mulrDr. Qed. HB.instance Definition _ := GRing.Zmodule_isNzRing.Build (subvs_of A) subvs_mulA subvs_mu1l subvs_mul1 subvs_mulDl subvs_mulDr (algid_neq0 _). Lemma subvs_scaleAl k (x y : subvs_of A) : k *: (x * y) = (k *: x) * y. Proof. exact/val_inj/scalerAl. Qed. HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build K (subvs_of A) subvs_scaleAl. Lemma subvs_scaleAr k (x y : subvs_of A) : k *: (x * y) = x * (k *: y). Proof. exact/val_inj/scalerAr. Qed. HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build K (subvs_of A) subvs_scaleAr. HB.instance Definition _ := Algebra_isFalgebra.Build K (subvs_of A). Implicit Type w : subvs_of A. Lemma vsval_unitr w : vsval w \is a GRing.unit -> w \is a GRing.unit. Proof. case: w => /= u Au Uu; have Au1: u^-1 \in A by rewrite memvV. apply/unitrP; exists (Subvs Au1). by split; apply: val_inj; rewrite /= ?mulrV ?mulVr ?(unitr_algid1 Au). Qed. Lemma vsval_invr w : vsval w \is a GRing.unit -> val w^-1 = (val w)^-1. Proof. move=> Uu; have def_w: w / w * w = w by rewrite divrK ?vsval_unitr. by apply: (mulrI Uu); rewrite -[in u in u / _]def_w ?mulrK. Qed. End SubFalgType. Section AHom. Variable K : fieldType. Section Class_Def. Variables aT rT : falgType K. Definition ahom_in (U : {vspace aT}) (f : 'Hom(aT, rT)) := all2rel (fun x y : aT => f (x * y) == f x * f y) (vbasis U) && (f 1 == 1). Lemma ahom_inP {f : 'Hom(aT, rT)} {U : {vspace aT}} : reflect ({in U &, {morph f : x y / x * y >-> x * y}} * (f 1 = 1)) (ahom_in U f). Proof. apply: (iffP andP) => [[/allrelP fM /eqP f1] | [fM f1]]; last first. rewrite f1; split=> //; apply/allrelP => x y Ax Ay. by rewrite fM // vbasis_mem. split=> // x y /coord_vbasis -> /coord_vbasis ->. rewrite !mulr_suml ![f _]linear_sum mulr_suml; apply: eq_bigr => i _ /=. rewrite !mulr_sumr linear_sum; apply: eq_bigr => j _ /=. rewrite !linearZ -!scalerAr -!scalerAl 2!linearZ /=; congr (_ *: (_ *: _)). by apply/eqP/fM; apply: memt_nth. Qed. Lemma ahomP_tmp {f : 'Hom(aT, rT)} : reflect (monoid_morphism f) (ahom_in {:aT} f). Proof. apply: (iffP ahom_inP) => [[fM f1] | fRM_P]; last first. by split=> [x y|]; [rewrite fRM_P.2|rewrite fRM_P.1]. by split=> // x y; rewrite fM ?memvf. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `ahomP_tmp` instead")] Lemma ahomP {f : 'Hom(aT, rT)} : reflect (multiplicative f) (ahom_in {:aT} f). Proof. by apply: (iffP ahomP_tmp) => [][]. Qed. Structure ahom := AHom {ahval :> 'Hom(aT, rT); _ : ahom_in {:aT} ahval}. HB.instance Definition _ := [isSub for ahval]. HB.instance Definition _ := [Equality of ahom by <:]. HB.instance Definition _ := [Choice of ahom by <:]. Fact linfun_is_ahom (f : {lrmorphism aT -> rT}) : ahom_in {:aT} (linfun f). Proof. by apply/ahom_inP; split=> [x y|]; rewrite !lfunE ?rmorphM ?rmorph1. Qed. Canonical linfun_ahom f := AHom (linfun_is_ahom f). End Class_Def. Arguments ahom_in [aT rT]. Arguments ahom_inP {aT rT f U}. #[warning="-deprecated-since-mathcomp-2.5.0"] Arguments ahomP {aT rT f}. Arguments ahomP_tmp {aT rT f}. Section LRMorphism. Variables aT rT sT : falgType K. Fact ahom_is_monoid_morphism (f : ahom aT rT) : monoid_morphism f. Proof. by apply/ahomP_tmp; case: f. Qed. #[hnf] HB.instance Definition _ (f : ahom aT rT) := GRing.isMonoidMorphism.Build aT rT f (ahom_is_monoid_morphism f). #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `ahom_is_monoid_morphism` instead")] Definition ahom_is_multiplicative (f : ahom aT rT) : multiplicative f := (fun p => (p.2, p.1)) (ahom_is_monoid_morphism f). Lemma ahomWin (f : ahom aT rT) U : ahom_in U f. Proof. by apply/ahom_inP; split; [apply: in2W (rmorphM _) | apply: rmorph1]. Qed. Lemma id_is_ahom (V : {vspace aT}) : ahom_in V \1. Proof. by apply/ahom_inP; split=> [x y|] /=; rewrite !id_lfunE. Qed. Canonical id_ahom := AHom (id_is_ahom (aspacef aT)). Lemma comp_is_ahom (V : {vspace aT}) (f : 'Hom(rT, sT)) (g : 'Hom(aT, rT)) : ahom_in {:rT} f -> ahom_in V g -> ahom_in V (f \o g). Proof. move=> /ahom_inP fM /ahom_inP gM; apply/ahom_inP. by split=> [x y Vx Vy|] /=; rewrite !comp_lfunE gM // fM ?memvf. Qed. Canonical comp_ahom (f : ahom rT sT) (g : ahom aT rT) := AHom (comp_is_ahom (valP f) (valP g)). Lemma aimgM (f : ahom aT rT) U V : (f @: (U * V) = f @: U * f @: V)%VS. Proof. apply/eqP; rewrite eqEsubv; apply/andP; split; last first. apply/prodvP=> _ _ /memv_imgP[u Hu ->] /memv_imgP[v Hv ->]. by rewrite -rmorphM memv_img // memv_mul. apply/subvP=> _ /memv_imgP[w UVw ->]; rewrite memv_preim (subvP _ w UVw) //. by apply/prodvP=> u v Uu Vv; rewrite -memv_preim rmorphM memv_mul // memv_img. Qed. Lemma aimg1 (f : ahom aT rT) : (f @: 1 = 1)%VS. Proof. by rewrite limg_line rmorph1. Qed. Lemma aimgX (f : ahom aT rT) U n : (f @: (U ^+ n) = f @: U ^+ n)%VS. Proof. elim: n => [|n IH]; first by rewrite !expv0 aimg1. by rewrite !expvSl aimgM IH. Qed. Lemma aimg_agen (f : ahom aT rT) U : (f @: agenv U)%VS = agenv (f @: U). Proof. apply/eqP; rewrite eqEsubv; apply/andP; split. by rewrite limg_sum; apply/subv_sumP => i _; rewrite aimgX subX_agenv. apply: agenv_sub_modl; first by rewrite -(aimg1 f) limgS // sub1_agenv. by rewrite -aimgM limgS // [rhs in (_ <= rhs)%VS]agenvEl addvSr. Qed. Lemma aimg_adjoin (f : ahom aT rT) U x : (f @: <<U; x>> = <<f @: U; f x>>)%VS. Proof. by rewrite aimg_agen limgD limg_line. Qed. Lemma aimg_adjoin_seq (f : ahom aT rT) U xs : (f @: <<U & xs>> = <<f @: U & map f xs>>)%VS. Proof. by rewrite aimg_agen limgD limg_span. Qed. Fact ker_sub_ahom_is_aspace (f g : ahom aT rT) : is_aspace (lker (ahval f - ahval g)). Proof. rewrite /is_aspace has_algid1; last by apply/eqlfunP; rewrite !rmorph1. apply/prodvP=> a b /eqlfunP Dfa /eqlfunP Dfb. by apply/eqlfunP; rewrite !rmorphM /= Dfa Dfb. Qed. Canonical ker_sub_ahom_aspace f g := ASpace (ker_sub_ahom_is_aspace f g). End LRMorphism. Canonical fixedSpace_aspace aT (f : ahom aT aT) := [aspace of fixedSpace f]. End AHom. Arguments ahom_in [K aT rT]. Notation "''AHom' ( aT , rT )" := (ahom aT rT) : type_scope. Notation "''AEnd' ( aT )" := (ahom aT aT) : type_scope. Delimit Scope lrfun_scope with AF. Bind Scope lrfun_scope with ahom. Notation "\1" := (@id_ahom _ _) : lrfun_scope. Notation "f \o g" := (comp_ahom f g) : lrfun_scope.
Dedup.lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Data.Finset.Defs import Mathlib.Data.Multiset.Dedup import Mathlib.Data.Multiset.Basic /-! # Deduplicating Multisets to make Finsets This file concerns `Multiset.dedup` and `List.dedup` as a way to create `Finset`s. ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen Multiset.powerset CompleteLattice OrderedCommMonoid open Multiset Subtype Function universe u variable {α : Type*} {β : Type*} {γ : Type*} namespace Finset @[simp] theorem dedup_eq_self [DecidableEq α] (s : Finset α) : dedup s.1 = s.1 := s.2.dedup end Finset /-! ### dedup on list and multiset -/ namespace Multiset variable [DecidableEq α] {s t : Multiset α} /-- `toFinset s` removes duplicates from the multiset `s` to produce a finset. -/ def toFinset (s : Multiset α) : Finset α := ⟨_, nodup_dedup s⟩ @[simp] theorem toFinset_val (s : Multiset α) : s.toFinset.1 = s.dedup := rfl theorem toFinset_eq {s : Multiset α} (n : Nodup s) : Finset.mk s n = s.toFinset := Finset.val_inj.1 n.dedup.symm theorem Nodup.toFinset_inj {l l' : Multiset α} (hl : Nodup l) (hl' : Nodup l') (h : l.toFinset = l'.toFinset) : l = l' := by simpa [← toFinset_eq hl, ← toFinset_eq hl'] using h @[simp] theorem mem_toFinset {a : α} {s : Multiset α} : a ∈ s.toFinset ↔ a ∈ s := mem_dedup @[simp] theorem toFinset_subset : s.toFinset ⊆ t.toFinset ↔ s ⊆ t := by simp only [Finset.subset_iff, Multiset.subset_iff, Multiset.mem_toFinset] @[simp] theorem toFinset_ssubset : s.toFinset ⊂ t.toFinset ↔ s ⊂ t := by simp_rw [Finset.ssubset_def, toFinset_subset] rfl @[simp] theorem toFinset_dedup (m : Multiset α) : m.dedup.toFinset = m.toFinset := by simp_rw [toFinset, dedup_idem] instance isWellFounded_ssubset : IsWellFounded (Multiset β) (· ⊂ ·) := by classical exact Subrelation.isWellFounded (InvImage _ toFinset) toFinset_ssubset.2 end Multiset namespace Finset @[simp] theorem val_toFinset [DecidableEq α] (s : Finset α) : s.val.toFinset = s := by ext rw [Multiset.mem_toFinset, ← mem_def] theorem val_le_iff_val_subset {a : Finset α} {b : Multiset α} : a.val ≤ b ↔ a.val ⊆ b := Multiset.le_iff_subset a.nodup end Finset namespace List variable [DecidableEq α] {l l' : List α} {a : α} {f : α → β} {s : Finset α} {t : Set β} {t' : Finset β} /-- `toFinset l` removes duplicates from the list `l` to produce a finset. -/ def toFinset (l : List α) : Finset α := Multiset.toFinset l @[simp] theorem toFinset_val (l : List α) : l.toFinset.1 = (l.dedup : Multiset α) := rfl @[simp] theorem toFinset_coe (l : List α) : (l : Multiset α).toFinset = l.toFinset := rfl theorem toFinset_eq (n : Nodup l) : @Finset.mk α l n = l.toFinset := Multiset.toFinset_eq <| by rwa [Multiset.coe_nodup] @[simp] theorem mem_toFinset : a ∈ l.toFinset ↔ a ∈ l := mem_dedup @[simp, norm_cast] theorem coe_toFinset (l : List α) : (l.toFinset : Set α) = { a | a ∈ l } := Set.ext fun _ => List.mem_toFinset theorem toFinset_surj_on : Set.SurjOn toFinset { l : List α | l.Nodup } Set.univ := by rintro ⟨⟨l⟩, hl⟩ _ exact ⟨l, hl, (toFinset_eq hl).symm⟩ theorem toFinset_surjective : Surjective (toFinset : List α → Finset α) := fun s => let ⟨l, _, hls⟩ := toFinset_surj_on (Set.mem_univ s) ⟨l, hls⟩ theorem toFinset_eq_iff_perm_dedup : l.toFinset = l'.toFinset ↔ l.dedup ~ l'.dedup := by simp [Finset.ext_iff, perm_ext_iff_of_nodup (nodup_dedup _) (nodup_dedup _)] theorem toFinset.ext_iff {a b : List α} : a.toFinset = b.toFinset ↔ ∀ x, x ∈ a ↔ x ∈ b := by simp only [Finset.ext_iff, mem_toFinset] theorem toFinset.ext : (∀ x, x ∈ l ↔ x ∈ l') → l.toFinset = l'.toFinset := toFinset.ext_iff.mpr theorem toFinset_eq_of_perm (l l' : List α) (h : l ~ l') : l.toFinset = l'.toFinset := toFinset_eq_iff_perm_dedup.mpr h.dedup theorem perm_of_nodup_nodup_toFinset_eq (hl : Nodup l) (hl' : Nodup l') (h : l.toFinset = l'.toFinset) : l ~ l' := by rw [← Multiset.coe_eq_coe] exact Multiset.Nodup.toFinset_inj hl hl' h @[simp] theorem toFinset_reverse {l : List α} : toFinset l.reverse = l.toFinset := toFinset_eq_of_perm _ _ (reverse_perm l) end List namespace Finset section ToList /-- Produce a list of the elements in the finite set using choice. -/ noncomputable def toList (s : Finset α) : List α := s.1.toList theorem nodup_toList (s : Finset α) : s.toList.Nodup := by rw [toList, ← Multiset.coe_nodup, Multiset.coe_toList] exact s.nodup @[simp] theorem mem_toList {a : α} {s : Finset α} : a ∈ s.toList ↔ a ∈ s := Multiset.mem_toList @[simp, norm_cast] theorem coe_toList (s : Finset α) : (s.toList : Multiset α) = s.val := s.val.coe_toList @[simp] theorem toList_toFinset [DecidableEq α] (s : Finset α) : s.toList.toFinset = s := by ext simp theorem _root_.List.toFinset_toList [DecidableEq α] {s : List α} (hs : s.Nodup) : s.toFinset.toList.Perm s := by apply List.perm_of_nodup_nodup_toFinset_eq (nodup_toList _) hs rw [toList_toFinset] theorem exists_list_nodup_eq [DecidableEq α] (s : Finset α) : ∃ l : List α, l.Nodup ∧ l.toFinset = s := ⟨s.toList, s.nodup_toList, s.toList_toFinset⟩ @[simp] protected theorem perm_toList {f₁ f₂ : Finset α} : f₁.toList.Perm f₂.toList ↔ f₁ = f₂ where mp h := Finset.ext fun x => by simp [← Finset.mem_toList, h.mem_iff] mpr h := .of_eq <| congrArg Finset.toList h @[deprecated (since := "2025-08-05")] alias _root_.perm_toList := Finset.perm_toList end ToList end Finset
Defs.lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.Order.Filter.AtTopBot.BigOperators import Mathlib.Topology.Separation.Hausdorff /-! # Infinite sum and product over a topological monoid This file defines unconditionally convergent sums over a commutative topological additive monoid. For Euclidean spaces (finite dimensional Banach spaces) this is equivalent to absolute convergence. We also define unconditionally convergent products over a commutative topological multiplicative monoid. Note: There are summable sequences which are not unconditionally convergent! The other way holds generally, see `HasSum.tendsto_sum_nat`. ## Implementation notes We say that a function `f : β → α` has an unconditional product of `a` if the function `fun s : Finset β ↦ ∏ b ∈ s, f b` converges to `a` on the `atTop` filter on `Finset β`. In other words, for every neighborhood `U` of `a`, there exists a finite set `s : Finset β` of indices such that `∏ b ∈ s', f b ∈ U` for any finite set `s'` which is a superset of `s`. This may yield some unexpected results. For example, according to this definition, the product `∏' n : ℕ, (1 : ℝ) / 2` unconditionally exists and is equal to `0`. More strikingly, the product `∏' n : ℕ, (n : ℝ)` unconditionally exists and is equal to `0`, because one of its terms is `0` (even though the product of the remaining terms diverges). Users who would prefer that these products be considered not to exist can carry them out in the unit group `ℝˣ` rather than in `ℝ`. ## References * Bourbaki: General Topology (1995), Chapter 3 §5 (Infinite sums in commutative groups) -/ /- **NOTE**. This file is intended to be kept short, just enough to state the basic definitions and six key lemmas relating them together, namely `Summable.hasSum`, `Multipliable.hasProd`, `HasSum.tsum_eq`, `HasProd.tprod_eq`, `Summable.hasSum_iff`, and `Multipliable.hasProd_iff`. Do not add further lemmas here -- add them to `InfiniteSum.Basic` or (preferably) another, more specific file. -/ noncomputable section open Filter Function open scoped Topology variable {α β γ : Type*} section HasProd variable [CommMonoid α] [TopologicalSpace α] /-- `HasProd f a` means that the (potentially infinite) product of the `f b` for `b : β` converges to `a`. The `atTop` filter on `Finset β` is the limit of all finite sets towards the entire type. So we take the product over bigger and bigger sets. This product operation is invariant under reordering. For the definition and many statements, `α` does not need to be a topological monoid. We only add this assumption later, for the lemmas where it is relevant. These are defined in an identical way to infinite sums (`HasSum`). For example, we say that the function `ℕ → ℝ` sending `n` to `1 / 2` has a product of `0`, rather than saying that it does not converge as some authors would. -/ @[to_additive /-- `HasSum f a` means that the (potentially infinite) sum of the `f b` for `b : β` converges to `a`. The `atTop` filter on `Finset β` is the limit of all finite sets towards the entire type. So we sum up bigger and bigger sets. This sum operation is invariant under reordering. In particular, the function `ℕ → ℝ` sending `n` to `(-1)^n / (n+1)` does not have a sum for this definition, but a series which is absolutely convergent will have the correct sum. This is based on Mario Carneiro's [infinite sum `df-tsms` in Metamath](http://us.metamath.org/mpeuni/df-tsms.html). For the definition and many statements, `α` does not need to be a topological monoid. We only add this assumption later, for the lemmas where it is relevant. -/] def HasProd (f : β → α) (a : α) : Prop := Tendsto (fun s : Finset β ↦ ∏ b ∈ s, f b) atTop (𝓝 a) /-- `Multipliable f` means that `f` has some (infinite) product. Use `tprod` to get the value. -/ @[to_additive /-- `Summable f` means that `f` has some (infinite) sum. Use `tsum` to get the value. -/] def Multipliable (f : β → α) : Prop := ∃ a, HasProd f a open scoped Classical in /-- `∏' i, f i` is the product of `f` if it exists and is unconditionally convergent, or 1 otherwise. -/ @[to_additive /-- `∑' i, f i` is the sum of `f` if it exists and is unconditionally convergent, or 0 otherwise. -/] noncomputable irreducible_def tprod {β} (f : β → α) := if h : Multipliable f then /- Note that the product might not be uniquely defined if the topology is not separated. When the multiplicative support of `f` is finite, we make the most reasonable choice to use the product over the multiplicative support. Otherwise, we choose arbitrarily an `a` satisfying `HasProd f a`. -/ if (mulSupport f).Finite then finprod f else h.choose else 1 -- see Note [operator precedence of big operators] @[inherit_doc tprod] notation3 "∏' "(...)", "r:67:(scoped f => tprod f) => r @[inherit_doc tsum] notation3 "∑' "(...)", "r:67:(scoped f => tsum f) => r variable {f : β → α} {a : α} {s : Finset β} @[to_additive] theorem HasProd.multipliable (h : HasProd f a) : Multipliable f := ⟨a, h⟩ @[to_additive] theorem tprod_eq_one_of_not_multipliable (h : ¬Multipliable f) : ∏' b, f b = 1 := by simp [tprod_def, h] @[to_additive] theorem Function.Injective.hasProd_iff {g : γ → β} (hg : Injective g) (hf : ∀ x, x ∉ Set.range g → f x = 1) : HasProd (f ∘ g) a ↔ HasProd f a := by simp only [HasProd, Tendsto, comp_apply, hg.map_atTop_finset_prod_eq hf] @[to_additive] theorem hasProd_subtype_iff_of_mulSupport_subset {s : Set β} (hf : mulSupport f ⊆ s) : HasProd (f ∘ (↑) : s → α) a ↔ HasProd f a := Subtype.coe_injective.hasProd_iff <| by simpa using mulSupport_subset_iff'.1 hf @[to_additive] theorem hasProd_fintype [Fintype β] (f : β → α) : HasProd f (∏ b, f b) := OrderTop.tendsto_atTop_nhds _ @[to_additive] protected theorem Finset.hasProd (s : Finset β) (f : β → α) : HasProd (f ∘ (↑) : (↑s : Set β) → α) (∏ b ∈ s, f b) := by rw [← prod_attach] exact hasProd_fintype _ /-- If a function `f` is `1` outside of a finite set `s`, then it `HasProd` `∏ b ∈ s, f b`. -/ @[to_additive /-- If a function `f` vanishes outside of a finite set `s`, then it `HasSum` `∑ b ∈ s, f b`. -/] theorem hasProd_prod_of_ne_finset_one (hf : ∀ b ∉ s, f b = 1) : HasProd f (∏ b ∈ s, f b) := (hasProd_subtype_iff_of_mulSupport_subset <| mulSupport_subset_iff'.2 hf).1 <| s.hasProd f @[to_additive] theorem multipliable_of_ne_finset_one (hf : ∀ b ∉ s, f b = 1) : Multipliable f := (hasProd_prod_of_ne_finset_one hf).multipliable @[to_additive] theorem Multipliable.hasProd (ha : Multipliable f) : HasProd f (∏' b, f b) := by simp only [tprod_def, ha, dite_true] by_cases H : (mulSupport f).Finite · simp [H, hasProd_prod_of_ne_finset_one, finprod_eq_prod] · simpa [H] using ha.choose_spec @[to_additive] theorem HasProd.unique {a₁ a₂ : α} [T2Space α] : HasProd f a₁ → HasProd f a₂ → a₁ = a₂ := by classical exact tendsto_nhds_unique variable [T2Space α] @[to_additive] theorem HasProd.tprod_eq (ha : HasProd f a) : ∏' b, f b = a := (Multipliable.hasProd ⟨a, ha⟩).unique ha @[to_additive] theorem Multipliable.hasProd_iff (h : Multipliable f) : HasProd f a ↔ ∏' b, f b = a := Iff.intro HasProd.tprod_eq fun eq ↦ eq ▸ h.hasProd end HasProd
norm_num.lean
/- Copyright (c) 2017 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Mario Carneiro, Thomas Murrills -/ import Mathlib.Tactic.NormNum private axiom test_sorry : ∀ {α}, α /-! # Tests for `norm_num` extensions -/ set_option autoImplicit true -- We deliberately mock R and C here so that we don't have to import the deps axiom Real : Type notation "ℝ" => Real @[instance] axiom Real.field : Field ℝ @[instance] axiom Real.linearOrder : LinearOrder ℝ @[instance] axiom Real.isStrictOrderedRing : IsStrictOrderedRing ℝ axiom NNReal : Type notation "ℝ≥0" => NNReal @[instance] axiom NNReal.semifield : Semifield ℝ≥0 @[instance] axiom NNReal.linearOrder : LinearOrder ℝ≥0 @[instance] axiom NNReal.isStrictOrderedRing : IsStrictOrderedRing ℝ≥0 axiom Complex : Type notation "ℂ" => Complex @[instance] axiom Complex.field : Field ℂ @[instance] axiom Complex.charZero : CharZero ℂ example : 43 ≤ 74 + (33 : ℤ) := by norm_num1 -- example : 374 + (32 - (2 * 8123) : ℤ) - 61 * 50 = 86 + 32 * 32 - 4 * 5000 -- ∧ 43 ≤ 74 + (33 : ℤ) := by norm_num1 example : ¬ (7-2)/(2*3) ≥ (1:ℝ) + 2/(3^2) := by norm_num1 example : (6:ℝ) + 9 = 15 := by norm_num1 example : (2:ℝ)/4 + 4 = 3*3/2 := by norm_num1 example : (((3:ℝ)/4)-12)<6 := by norm_num1 example : (5:ℝ) ≠ 8 := by norm_num1 example : (10:ℝ) > 7 := by norm_num1 example : (2:ℝ) * 2 + 3 = 7 := by norm_num1 example : (6:ℝ) < 10 := by norm_num1 example : (7:ℝ)/2 > 3 := by norm_num1 example : (4:ℝ)⁻¹ < 1 := by norm_num1 example : ((1:ℝ) / 2)⁻¹ = 2 := by norm_num1 example : 2 ^ 17 - 1 = 131071 := by norm_num1 example : (3 : ℝ) ^ (-2 : ℤ) = 1/9 := by norm_num1 example : (-3 : ℝ) ^ (0 : ℤ) = 1 := by norm_num1 example : (-3 : ℝ) ^ (-1 : ℤ) = -1/3 := by norm_num1 example : (-3 : ℝ) ^ (1 : ℤ) = -3 := by norm_num1 example : (-3 : ℝ) ^ (2 : ℤ) = 9 := by norm_num1 example : (1/3 : ℝ) ^ (2 : ℤ) = 1/9 := by norm_num1 example : (1/3 : ℝ) ^ (-2 : ℤ) = 9 := by norm_num1 example : (-1/3 : ℝ) ^ (-1 : ℤ) = -3 := by norm_num1 example : (3 : ℝ≥0) ^ (2 : ℤ) = 9 := by norm_num1 section InvLit variable [DivisionRing α] example : (0 : α)⁻¹ = 0 := by norm_num1 example : (1 : α)⁻¹ = 1 := by norm_num1 example : (-1 : α)⁻¹ = -1 := by norm_num1 end InvLit example (h : x = 1) : x = (1/5 + 4/5 : ℚ) := by norm_num1; exact h example (h : x = 1) : x = (5 * 5⁻¹ : ℚ) := by norm_num1; exact h example (h : x = 1) : x = (6/5 - 1/5 : ℚ) := by norm_num1; exact h example (h : x = 1) : x = ((6/5) ^ 0 : ℚ) := by norm_num1; exact h section ConstructorsEtc example : Int.ofNat 3 = 3 := by norm_num1 example : mkRat 3 4 = 3/4 := by norm_num1 example : mkRat 6 8 = 3/4 := by norm_num1 example : mkRat 5 0 = 0 := by norm_num1 example : mkRat (10 + 6) (5 * 4) = 4/5 := by norm_num1 end ConstructorsEtc section ScientificNotation variable [DivisionRing α] [CharZero α] example : (0.1 : ℚ) = 1/10 := by norm_num1 example : (3.14 : ℚ) = 157/50 := by norm_num1 example : (3.14159 : ℚ) = 314159/100000 := by norm_num1 example : (0.1 : α) = 1/10 := by norm_num1 example : (3.14 : α) = 157/50 := by norm_num1 example : (3.14159 : α) = 314159/100000 := by norm_num1 example : (42e7 : ℚ) = 420000000 := by norm_num1 example : (42e7 : α) = 420000000 := by norm_num1 end ScientificNotation /- # `=` and `≠` -/ section Equality section Bool example : True := by norm_num1 example (h : False) : ¬True := by norm_num1; guard_target =ₛ False; exact h example : ¬¬¬¬True := by norm_num1 example : ¬False := by norm_num1 end Bool section Nat variable [AddMonoidWithOne α] [CharZero α] -- Normalize to True example : 1 = 1 := by norm_num1 example : 1 ≠ 2 := by norm_num1 example : (1 : α) ≠ 2 := by norm_num1 -- Normalize to False example : ¬(1 = 2) := by norm_num1 example : ¬((1 : α) = 2) := by norm_num1 example : ¬((1 : α) ≠ 1) := by norm_num1 end Nat section Semiring variable [Semiring α] [CharZero α] example : (1 : α) ≠ 2 := by norm_num1 end Semiring section Int variable [Ring α] [CharZero α] -- Normalize to True example : (1 : ℤ) = 1 := by norm_num1 example : (-1 : ℤ) = -1 := by norm_num1 example : (1 : α) = 1 := by norm_num1 example : (-1 : α) = -1 := by norm_num1 example : (1 : ℤ) ≠ 2 := by norm_num1 example : (1 : ℤ) ≠ -2 := by norm_num1 example : (-1 : ℤ) ≠ -2 := by norm_num1 example : (1 : α) ≠ 2 := by norm_num1 example : (-1 : α) ≠ 2 := by norm_num1 example : (-1 : α) ≠ -2 := by norm_num1 -- Normalize to False example : ((1 : ℤ) = 2) = False := by norm_num1 example : ((-1 : ℤ) = 2) = False := by norm_num1 example : ((1 : α) = 2) = False := by norm_num1 example : ((-1 : α) = 2) = False := by norm_num1 example : ((1 : ℤ) ≠ 1) = False := by norm_num1 example : ((-1 : ℤ) ≠ -1) = False := by norm_num1 example : ((1 : α) ≠ 1) = False := by norm_num1 example : ((-1 : α) = 2) = False := by norm_num1 example : Int.natAbs 5 = 5 := by norm_num1 example : Int.natAbs (-5) = 5 := by norm_num1 example : Int.natAbs 0 = 0 := by norm_num1 end Int section NNRat open scoped NNRat variable [DivisionSemiring α] [CharZero α] -- Normalize to True example : (1 : ℚ≥0) = 1 := by norm_num1 example : (1/2 : ℚ≥0) = 1/2 := by norm_num1 example : (1 : α) = 1 := by norm_num1 example : (1/2 : α) = 1/2 := by norm_num1 example : (1 : ℚ≥0) ≠ 2 := by norm_num1 example : (1/2 : ℚ≥0) ≠ 1 := by norm_num1 example : (1/2 : ℚ≥0) ≠ 1/3 := by norm_num1 example : (1/2 : ℚ≥0) ≠ 5/2 := by norm_num1 example : (1/2 : α) ≠ 1/3 := by norm_num1 example : (1/2 : α) ≠ 5/2 := by norm_num1 example : (1 : α) / 3 ≠ 0 := by norm_num1 example : (1 : α) / 3 ≠ 2 / 7 := by norm_num1 -- Normalize to False example : ((1 : ℚ≥0) = 2) = False := by norm_num1 example : ((1/2 : ℚ≥0) = 2) = False := by norm_num1 example : ((1 : α) = 2) = False := by norm_num1 example : ((1/2 : α) = 2) = False := by norm_num1 example : ((1 : ℚ≥0) ≠ 1) = False := by norm_num1 example : ((1/2 : ℚ≥0) ≠ 1/2) = False := by norm_num1 example : ((1/2 : α) ≠ 1/2) = False := by norm_num1 end NNRat section Rat variable [DivisionRing α] [CharZero α] -- Normalize to True example : (1 : ℚ) = 1 := by norm_num1 example : (-1 : ℚ) = -1 := by norm_num1 example : (1/2 : ℚ) = 1/2 := by norm_num1 example : (-1/2 : ℚ) = -1/2 := by norm_num1 example : (-1/(-2) : ℚ) = -1/(-2) := by norm_num1 example : (1 : α) = 1 := by norm_num1 example : (-1 : α) = -1 := by norm_num1 example : (1/2 : α) = 1/2 := by norm_num1 example : (-1/2 : α) = -1/2 := by norm_num1 example : (-1/(-2) : α) = -1/(-2) := by norm_num1 example : (1 : ℚ) ≠ 2 := by norm_num1 example : (1 : ℚ) ≠ -2 := by norm_num1 example : (-1 : ℚ) ≠ -2 := by norm_num1 example : (1/2 : ℚ) ≠ 1 := by norm_num1 example : (1/2 : ℚ) ≠ -1 := by norm_num1 example : (1/2 : ℚ) ≠ 1/3 := by norm_num1 example : (1/2 : ℚ) ≠ 5/2 := by norm_num1 example : (1/2 : α) ≠ 1/3 := by norm_num1 example : (1/2 : α) ≠ 5/2 := by norm_num1 example : (1/2 : α) ≠ -2 := by norm_num1 example : (-1 : α) ≠ 2 := by norm_num1 example : (1 : α) / 3 ≠ 0 := by norm_num1 example : (1 : α) / 3 ≠ 2 / 7 := by norm_num1 -- Normalize to False example : ((1 : ℚ) = 2) = False := by norm_num1 example : ((-1 : ℚ) = 2) = False := by norm_num1 example : ((1/2 : ℚ) = 2) = False := by norm_num1 example : ((1 : α) = 2) = False := by norm_num1 example : ((-1 : α) = 2) = False := by norm_num1 example : ((1/2 : α) = 2) = False := by norm_num1 example : ((1 : ℚ) ≠ 1) = False := by norm_num1 example : ((-1 : ℚ) ≠ -1) = False := by norm_num1 example : ((1/2 : ℚ) ≠ 1/2) = False := by norm_num1 example : ((1/2 : α) ≠ 1/2) = False := by norm_num1 end Rat end Equality /- # `<` and `≤` -/ section Order section Nat variable [Semiring α] [PartialOrder α] [IsOrderedRing α] [CharZero α] -- Normalize to True example : 1 ≤ 1 := by norm_num1 example : (1 : α) ≤ 2 := by norm_num1 example : 1 < 2 := by norm_num1 example : (1 : α) < 2 := by norm_num1 -- Normalize to False example : ¬(2 ≤ 1) := by norm_num1 example : ¬((2 : α) ≤ 1) := by norm_num1 example : ¬(1 < 1) := by norm_num1 example : ¬((2 : α) < 2) := by norm_num1 end Nat section Int variable [Ring α] [PartialOrder α] [IsOrderedRing α] [Nontrivial α] -- Normalize to True example : (1 : ℤ) ≤ 1 := by norm_num1 example : (-1 : ℤ) ≤ -1 := by norm_num1 example : (-1 : ℤ) ≤ 1 := by norm_num1 example : (1 : α) ≤ 1 := by norm_num1 example : (-1 : α) ≤ -1 := by norm_num1 example : (-1 : α) ≤ 1 := by norm_num1 example : (1 : ℤ) < 2 := by norm_num1 example : (-2 : ℤ) < 1 := by norm_num1 example : (-1 : ℤ) < 1 := by norm_num1 example : (1 : α) < 2 := by norm_num1 example : (-1 : α) < 2 := by norm_num1 example : (-1 : α) < 1 := by norm_num1 -- Normalize to False example : ¬((2 : ℤ) ≤ 1) := by norm_num1 example : ¬((2 : ℤ) ≤ -1) := by norm_num1 example : ¬((2 : α) ≤ 1) := by norm_num1 example : ¬((2 : α) ≤ -1) := by norm_num1 example : ¬((2 : ℤ) < 1) := by norm_num1 example : ¬((2 : ℤ) < -1) := by norm_num1 example : ¬((2 : α) < 1) := by norm_num1 example : ¬((2 : α) < -1) := by norm_num1 end Int section OrderedCharZeroRing variable [Ring α] [PartialOrder α] [IsOrderedRing α] [CharZero α] example : (-1 : α) < 2 := by norm_num1 end OrderedCharZeroRing section LinearOrderedRing variable [Ring α] [LinearOrder α] [IsStrictOrderedRing α] example : (1 : α) ≤ 1 := by norm_num1 example : (-1 : α) ≤ -1 := by norm_num1 example : (-1 : α) ≤ 1 := by norm_num1 example : (1 : α) < 2 := by norm_num1 example : (-1 : α) < 2 := by norm_num1 example : (-1 : α) < 1 := by norm_num1 end LinearOrderedRing section Rat variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] [Nontrivial α] -- Normalize to True example : (1 : ℚ) ≤ 1 := by norm_num1 example : (-1 : ℚ) ≤ -1 := by norm_num1 example : (-1 : ℚ) ≤ 1 := by norm_num1 example : (-1/2 : ℚ) ≤ 1 := by norm_num1 example : (1/2 : ℚ) ≤ 5/4 := by norm_num1 example : (1 : α) ≤ 1 := by norm_num1 example : (-1 : α) ≤ -1 := by norm_num1 example : (-1 : α) ≤ 1 := by norm_num1 example : (-1/2 : α) ≤ 1 := by norm_num1 example : (1/2 : α) ≤ 5/4 := by norm_num1 example : (1 : ℤ) < 2 := by norm_num1 example : (-2 : ℤ) < 1 := by norm_num1 example : (-1 : ℤ) < 1 := by norm_num1 example : (-1/2 : ℚ) < 1 := by norm_num1 example : (1/2 : ℚ) < 5/4 := by norm_num1 example : (1 : α) < 2 := by norm_num1 example : (-1 : α) < 2 := by norm_num1 example : (-1 : α) < 1 := by norm_num1 example : (-1/2 : α) < 1 := by norm_num1 example : (1/2 : α) < 5/4 := by norm_num1 -- Normalize to False example : ¬((2 : ℚ) ≤ 1) := by norm_num1 example : ¬((2 : ℚ) ≤ -1) := by norm_num1 example : ¬((1/2 : ℚ) ≤ -1) := by norm_num1 example : ¬((2 : α) ≤ 1) := by norm_num1 example : ¬((2 : α) ≤ -1) := by norm_num1 example : ¬((1/2 : α) ≤ -1) := by norm_num1 example : ¬((2 : ℚ) < 1) := by norm_num1 example : ¬((2 : ℚ) < -1) := by norm_num1 example : ¬((1/2 : ℚ) < -1) := by norm_num1 example : ¬((2 : α) < 1) := by norm_num1 example : ¬((2 : α) < -1) := by norm_num1 example : ¬((1/2 : α) < -1) := by norm_num1 end Rat end Order example : (1:ℂ) ≠ 2 := by norm_num1 example : (1:ℂ) / 3 ≠ 2 / 7 := by norm_num1 example : (1:ℝ) ≠ 2 := by norm_num1 example : (5 / 2:ℕ) = 2 := by norm_num1 example : (5 / -2:ℤ) < -1 := by norm_num1 example : (0 + 1) / 2 < 0 + 1 := by norm_num1 example : Nat.succ (Nat.succ (2 ^ 3)) = 10 := by norm_num1 example : 10 = (-1 : ℤ) % 11 := by norm_num1 example : (12321 - 2 : ℤ) = 12319 := by norm_num1 example : (63:ℚ) ≥ 5 := by norm_num1 example (x : ℤ) (h : 1000 + 2000 < x) : 100 * 30 < x := by norm_num at *; exact h example : (1103 : ℤ) ≤ (2102 : ℤ) := by norm_num1 example : (110474 : ℤ) ≤ (210485 : ℤ) := by norm_num1 example : (11047462383473829263 : ℤ) ≤ (21048574677772382462 : ℤ) := by norm_num1 example : (210485742382937847263 : ℤ) ≤ (1104857462382937847262 : ℤ) := by norm_num1 example : (210485987642382937847263 : ℕ) ≤ (11048512347462382937847262 : ℕ) := by norm_num1 example : (210485987642382937847263 : ℚ) ≤ (11048512347462382937847262 : ℚ) := by norm_num1 example : (2 * 12868 + 25705) * 11621 ^ 2 ≤ 23235 ^ 2 * 12868 := by norm_num1 -- example (x : ℕ) : ℕ := by -- let n : ℕ := by apply_normed (2^32 - 71) -- exact n set_option linter.unusedVariables false in example (a : ℚ) (h : 3⁻¹ * a = a) : True := by norm_num1 at h guard_hyp h : 1 / 3 * a = a trivial example (h : (5 : ℤ) ∣ 2) : False := by norm_num1 at h example (h : False) : False := by norm_num1 at h example : True := by norm_num1 -- example : True ∧ True := by norm_num1 /-! # Nat operations -/ section Nat.sub example : 10 - 1 = 9 := by norm_num1 example : 12 - 5 = 3 + 4 := by norm_num1 example : 5 - 20 = 0 := by norm_num1 example : 0 - 2 = 0 := by norm_num1 example : 4 - (5 - 10) = 2 + (3 - 1) := by norm_num1 example : 0 - 0 = 0 := by norm_num1 example : 100 - 100 = 0 := by norm_num1 example : 5 * (2 - 3) = 0 := by norm_num1 example : 10 - 5 * 5 + (7 - 3) * 6 = 27 - 3 := by norm_num1 end Nat.sub section Nat.mod example : 10 % 1 = 0 := by norm_num1 example : 5 % 4 = 1 := by norm_num1 example : (9 % 4) % (12 % 8) = 1 := by norm_num1 example : 0 % 10 = 0 := by norm_num1 example : 10 % 0 = 10 := by norm_num1 example : 1 % 1 = 0 := by norm_num1 end Nat.mod section Nat.div example : 10 / 1 = 10 := by norm_num1 example : 5 / 4 = 1 := by norm_num1 example : 9 / 4 = 2 := by norm_num1 example : 0 / 1 = 0 := by norm_num1 example : 10 / 9 = 1 := by norm_num1 example : 1099 / 100 = 10 := by norm_num1 end Nat.div /-! # Numbers in algebraic structures -/ noncomputable def foo : ℝ := 1 example : foo = 1 := by norm_num [foo] section variable [AddMonoidWithOne α] example : (1 + 0 : α) = (0 + 1 : α) := by norm_num1 example : (0 + (2 + 3) + 1 : α) = 6 := by norm_num1 end section variable [Semiring α] example : (70 * (33 + 2) : α) = 2450 := by norm_num1 example : (8 + 2 ^ 2 * 3 : α) = 20 := by norm_num1 example : ((2 * 1 + 1) ^ 2 : α) = (3 * 3 : α) := by norm_num1 end section variable [Ring α] example : (-1 : α) * 1 = -1 := by norm_num1 example : (-2 : α) * 1 = -2 := by norm_num1 example : (-2 : α) * -1 = 2 := by norm_num1 example : (-2 : α) * -2 = 4 := by norm_num1 example : (1 : α) * 0 = 0 := by norm_num1 example : ((1 : α) + 1) * 5 = 6 + 4 := by norm_num1 example : (1 : α) = 0 + 1 := by norm_num1 example : (1 : α) = 1 + 0 := by norm_num1 example : (2 : α) = 1 + 1 := by norm_num1 example : (2 : α) = 0 + 2 := by norm_num1 example : (3 : α) = 1 + 2 := by norm_num1 example : (3 : α) = 2 + 1 := by norm_num1 example : (4 : α) = 3 + 1 := by norm_num1 example : (4 : α) = 2 + 2 := by norm_num1 example : (5 : α) = 4 + 1 := by norm_num1 example : (5 : α) = 3 + 2 := by norm_num1 example : (5 : α) = 2 + 3 := by norm_num1 example : (6 : α) = 0 + 6 := by norm_num1 example : (6 : α) = 3 + 3 := by norm_num1 example : (6 : α) = 4 + 2 := by norm_num1 example : (6 : α) = 5 + 1 := by norm_num1 example : (7 : α) = 4 + 3 := by norm_num1 example : (7 : α) = 1 + 6 := by norm_num1 example : (7 : α) = 6 + 1 := by norm_num1 example : 33 = 5 + (28 : α) := by norm_num1 example : (12 : α) = 0 + (2 + 3) + 7 := by norm_num1 example : (105 : α) = 70 + (33 + 2) := by norm_num1 example : (45000000000 : α) = 23000000000 + 22000000000 := by norm_num1 example : (0 : α) - 3 = -3 := by norm_num1 example : (0 : α) - 2 = -2 := by norm_num1 example : (1 : α) - 3 = -2 := by norm_num1 example : (1 : α) - 1 = 0 := by norm_num1 example : (0 : α) - 3 = -3 := by norm_num1 example : (0 : α) - 3 = -3 := by norm_num1 example : (12 : α) - 4 - (5 + -2) = 5 := by norm_num1 example : (12 : α) - 4 - (5 + -2) - 20 = -15 := by norm_num1 example : (0 : α) * 0 = 0 := by norm_num1 example : (0 : α) * 1 = 0 := by norm_num1 example : (0 : α) * 2 = 0 := by norm_num1 example : (2 : α) * 0 = 0 := by norm_num1 example : (1 : α) * 0 = 0 := by norm_num1 example : (1 : α) * 1 = 1 := by norm_num1 example : (2 : α) * 1 = 2 := by norm_num1 example : (1 : α) * 2 = 2 := by norm_num1 example : (2 : α) * 2 = 4 := by norm_num1 example : (3 : α) * 2 = 6 := by norm_num1 example : (2 : α) * 3 = 6 := by norm_num1 example : (4 : α) * 1 = 4 := by norm_num1 example : (1 : α) * 4 = 4 := by norm_num1 example : (3 : α) * 3 = 9 := by norm_num1 example : (3 : α) * 4 = 12 := by norm_num1 example : (4 : α) * 4 = 16 := by norm_num1 example : (11 : α) * 2 = 22 := by norm_num1 example : (15 : α) * 6 = 90 := by norm_num1 example : (123456 : α) * 123456 = 15241383936 := by norm_num1 end section variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] example : (4 : α) / 2 = 2 := by norm_num1 example : (4 : α) / 1 = 4 := by norm_num1 example : (4 : α) / 3 = 4 / 3 := by norm_num1 example : (50 : α) / 5 = 10 := by norm_num1 example : (1056 : α) / 1 = 1056 := by norm_num1 example : (6 : α) / 4 = 3/2 := by norm_num1 example : (0 : α) / 3 = 0 := by norm_num1 example : (3 : α) / 0 = 0 := by norm_num1 example : (9 * 9 * 9) * (12 : α) / 27 = 81 * (2 + 2) := by norm_num1 example : (-2 : α) * 4 / 3 = -8 / 3 := by norm_num1 example : - (-4 / 3) = 1 / (3 / (4 : α)) := by norm_num1 end -- user command set_option linter.style.commandStart false /-- info: True -/ #guard_msgs in #norm_num 1 = 1 example : 1 = 1 := by norm_num1 /-- info: True -/ #guard_msgs in #norm_num 2^4-1 ∣ 2^16-1 example : 2^4-1 ∣ 2^16-1 := by norm_num1 -- #norm_num (3 : Real) ^ (-2 : ℤ) = 1/9 -- example : (3 : Real) ^ (-2 : ℤ) = 1/9 := by norm_num1 section norm_num_cmd_variable -- [fixme] obsolete? -- variables (x y : ℕ) -- #norm_num bit0 x < bit0 (y + x) ↔ 0 < y -- example : bit0 x < bit0 (y + x) ↔ 0 < y := by norm_num1 -- #norm_num bit0 x < bit0 (y + (2^10%11 - 1) + x) ↔ 0 < y -- example : bit0 x < bit0 (y + (2^10%11 - 1) + x) ↔ 0 < y := by norm_num1 -- #norm_num bit0 x < bit0 (y + (2^10%11 - 1) + x) + 3*2-6 ↔ 0 < y -- example : bit0 x < bit0 (y + (2^10%11 - 1) + x) + 3*2-6 ↔ 0 < y := by norm_num1 end norm_num_cmd_variable section norm_num_erase example : 3 ^ 3 + 4 = 31 := by norm_num1 set_option linter.unusedTactic false in attribute [-norm_num] Mathlib.Meta.NormNum.evalPow in example : 3 ^ 3 + 4 = 31 := by norm_num1 guard_target =ₛ 3 ^ 3 + 4 = 31 rfl /- Check that the scoping above works: -/ example : 3 ^ 3 + 4 = 31 := by norm_num1 attribute [-norm_num] Mathlib.Meta.NormNum.evalPow /- If run, the following commented line of code will produce the error "'Mathlib.Meta.NormNum.evalPow' does not have [norm_num] attribute". This checks that the `norm_num` attribute is indeed considered to be erased from `Mathlib.Meta.NormNum.evalPow` in this scope. -/ -- attribute [-norm_num] Mathlib.Meta.NormNum.evalPow end norm_num_erase -- auto gen tests variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] example : ((25 * (1 / 1)) + (30 - 16)) = (39 : α) := by norm_num1 example : ((19 * (- 2 - 3)) / 6) = (-95/6 : α) := by norm_num1 example : - (3 * 28) = (-84 : α) := by norm_num1 example : - - (16 / ((11 / (- - (6 * 19) + 12)) * 21)) = (96/11 : α) := by norm_num1 example : (- (- 21 + 24) - - (- - (28 + (- 21 / - (16 / ((1 * 26) * ((0 * - 11) + 13))))) * 21)) = (79209/8 : α) := by norm_num1 example : (27 * (((16 + - (12 + 4)) + (22 - - 19)) - 23)) = (486 : α) := by norm_num1 example : - (13 * (- 30 / ((7 / 24) + - 7))) = (-9360/161 : α) := by norm_num1 example : - (0 + 20) = (-20 : α) := by norm_num1 example : (- 2 - (27 + (((2 / 14) - (7 + 21)) + (16 - - - 14)))) = (-22/7 : α) := by norm_num1 example : (25 + ((8 - 2) + 16)) = (47 : α) := by norm_num1 example : (- - 26 / 27) = (26/27 : α) := by norm_num1 example : ((((16 * (22 / 14)) - 18) / 11) + 30) = (2360/77 : α) := by norm_num1 example : (((- 28 * 28) / (29 - 24)) * 24) = (-18816/5 : α) := by norm_num1 example : ((- (18 - ((- - (10 + - 2) - - (23 / 5)) / 5)) - (21 * 22)) - (((20 / - ((((19 + 18) + 15) + 3) + - 22)) + 14) / 17)) = (-394571/825 : α) := by norm_num1 example : ((3 + 25) - - 4) = (32 : α) := by norm_num1 example : ((1 - 0) - 22) = (-21 : α) := by norm_num1 example : (((- (8 / 7) / 14) + 20) + 22) = (2054/49 : α) := by norm_num1 example : ((21 / 20) - 29) = (-559/20 : α) := by norm_num1 example : - - 20 = (20 : α) := by norm_num1 example : (24 - (- 9 / 4)) = (105/4 : α) := by norm_num1 example : (((7 / ((23 * 19) + (27 * 10))) - ((28 - - 15) * 24)) + (9 / - (10 * - 3))) = (-1042007/1010 : α) := by norm_num1 example : (26 - (- 29 + (12 / 25))) = (1363/25 : α) := by norm_num1 example : ((11 * 27) / (4 - 5)) = (-297 : α) := by norm_num1 example : (24 - (9 + 15)) = (0 : α) := by norm_num1 example : (- 9 - - 0) = (-9 : α) := by norm_num1 example : (- 10 / (30 + 10)) = (-1/4 : α) := by norm_num1 example : (22 - (6 * (28 * - 8))) = (1366 : α) := by norm_num1 example : ((- - 2 * (9 * - 3)) + (22 / 30)) = (-799/15 : α) := by norm_num1 example : - (26 / ((3 + 7) / - (27 * (12 / - 16)))) = (-1053/20 : α) := by norm_num1 example : ((- 29 / 1) + 28) = (-1 : α) := by norm_num1 example : ((21 * ((10 - (((17 + 28) - - 0) + 20)) + 26)) + ((17 + - 16) * 7)) = (-602 : α) := by norm_num1 example : (((- 5 - ((24 + - - 8) + 3)) + 20) + - 23) = (-43 : α) := by norm_num1 example : ((- ((14 - 15) * (14 + 8)) + ((- (18 - 27) - 0) + 12)) - 11) = (32 : α) := by norm_num1 example : (((15 / 17) * (26 / 27)) + 28) = (4414/153 : α) := by norm_num1 example : (14 - ((- 16 - 3) * - (20 * 19))) = (-7206 : α) := by norm_num1 example : (21 - - - (28 - (12 * 11))) = (125 : α) := by norm_num1 example : ((0 + (7 + (25 + 8))) * - (11 * 27)) = (-11880 : α) := by norm_num1 example : (19 * - 5) = (-95 : α) := by norm_num1 example : (29 * - 8) = (-232 : α) := by norm_num1 example : ((22 / 9) - 29) = (-239/9 : α) := by norm_num1 example : (3 + (19 / 12)) = (55/12 : α) := by norm_num1 example : - (13 + 30) = (-43 : α) := by norm_num1 example : - - - (((21 * - - ((- 25 - (- (30 - 5) / (- 5 - 5))) / (((6 + ((25 * - 13) + 22)) - 3) / 2))) / (- 3 / 10)) * (- 8 - 0)) = (-308/3 : α) := by norm_num1 example : - (2 * - (- 24 * 22)) = (-1056 : α) := by norm_num1 example : - - (((28 / - ((- 13 * - 5) / - (((7 - 30) / 16) + 6))) * 0) - 24) = (-24 : α) := by norm_num1 example : ((13 + 24) - (27 / (21 * 13))) = (3358/91 : α) := by norm_num1 example : ((3 / - 21) * 25) = (-25/7 : α) := by norm_num1 example : (17 - (29 - 18)) = (6 : α) := by norm_num1 example : ((28 / 20) * 15) = (21 : α) := by norm_num1 example : ((((26 * (- (23 - 13) - 3)) / 20) / (14 - (10 + 20))) / ((16 / 6) / (16 * - (3 / 28)))) = (-1521/2240 : α) := by norm_num1 example : (46 / (- ((- 17 * 28) - 77) + 87)) = (23/320 : α) := by norm_num1 example : (73 * - (67 - (74 * - - 11))) = (54531 : α) := by norm_num1 example : ((8 * (25 / 9)) + 59) = (731/9 : α) := by norm_num1 example : - ((59 + 85) * - 70) = (10080 : α) := by norm_num1 example : (66 + (70 * 58)) = (4126 : α) := by norm_num1 example : (- - 49 * 0) = (0 : α) := by norm_num1 example : ((- 78 - 69) * 9) = (-1323 : α) := by norm_num1 example : - - (7 - - (50 * 79)) = (3957 : α) := by norm_num1 example : - (85 * (((4 * 93) * 19) * - 31)) = (18624180 : α) := by norm_num1 example : (21 + (- 5 / ((74 * 85) / 45))) = (26373/1258 : α) := by norm_num1 example : (42 - ((27 + 64) + 26)) = (-75 : α) := by norm_num1 example : (- ((38 - - 17) + 86) - (74 + 58)) = (-273 : α) := by norm_num1 example : ((29 * - (75 + - 68)) + (- 41 / 28)) = (-5725/28 : α) := by norm_num1 example : (- - (40 - 11) - (68 * 86)) = (-5819 : α) := by norm_num1 example : (6 + ((65 - 14) + - 89)) = (-32 : α) := by norm_num1 example : (97 * - (29 * 35)) = (-98455 : α) := by norm_num1 example : - (66 / 33) = (-2 : α) := by norm_num1 example : - ((94 * 89) + (79 - (23 - (((- 1 / 55) + 95) * (28 - (54 / - - - 22)))))) = (-1369070/121 : α) := by norm_num1 example : (- 23 + 61) = (38 : α) := by norm_num1 example : - (93 / 69) = (-31/23 : α) := by norm_num1 example : (- - ((68 / (39 + (((45 * - (59 - (37 + 35))) / (53 - 75)) - - (100 + - (50 / (- 30 - 59)))))) - (69 - (23 * 30))) / (57 + 17)) = (137496481/16368578 : α) := by norm_num1 example : (- 19 * - - (75 * - - 41)) = (-58425 : α) := by norm_num1 example : ((3 / ((- 28 * 45) * (19 + ((- (- 88 - (- (- 1 + 90) + 8)) + 87) * 48)))) + 1) = (1903019/1903020 : α) := by norm_num1 example : ((- - (28 + 48) / 75) + ((- 59 - 14) - 0)) = (-5399/75 : α) := by norm_num1 example : (- ((- (((66 - 86) - 36) / 94) - 3) / - - (77 / (56 - - - 79))) + 87) = (312254/3619 : α) := by norm_num1 example : 2 ^ 13 - 1 = Int.ofNat 8191 := by norm_num1 set_option linter.unusedTactic false in -- Since https://github.com/leanprover/lean4/pull/4177 -- `simp` will continue even if given invalid theorem names (but generates an error) -- and this felicitously applies to `norm_num` too. -- Previous this was a `fail_if_success` test, but now we just check for the error. /-- error: Unknown identifier `this_doesnt_exist` -/ #guard_msgs in example : 1 + 1 = 2 := by norm_num [this_doesnt_exist] done example : 1 + 100 + a = a + 101 := by norm_num [add_comm] def R : Type u → Type v → Sort (max (u+1) (v+1)) := test_sorry noncomputable instance : Field (R a b) := test_sorry noncomputable instance : LinearOrder (R a b) := test_sorry noncomputable instance : IsStrictOrderedRing (R a b) := test_sorry example : (1 : R PUnit.{u+1} PUnit.{v+1}) <= 2 := by norm_num -- Check that we avoid deep recursion in evaluating large powers. -- This used to be 10^40000000, but Lean's non-GMP multiplication is -- asymptotically slower than the GMP implementation. -- It would be great to fix that, and restore this test. example : 10^400000 = 10^400000 := by norm_num
prime.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path. From mathcomp Require Import choice fintype div bigop. (******************************************************************************) (* This file contains the definitions of: *) (* prime p <=> p is a prime. *) (* primes m == the sorted list of prime divisors of m > 1, else [::]. *) (* pfactor p e == the value p ^ e of a prime factor (p, e). *) (* NumFactor f == print version of a prime factor, converting the prime *) (* component to a Num (which can print large values). *) (* prime_decomp m == the list of prime factors of m > 1, sorted by primes. *) (* logn p m == the e such that (p ^ e) \in prime_decomp n, else 0. *) (* trunc_log p m == the largest e such that p ^ e <= m, or 0 if p <= 1 or *) (* m is 0. *) (* up_log p m == the smallest e such that m <= p ^ e, or 0 if p <= 1 *) (* pdiv n == the smallest prime divisor of n > 1, else 1. *) (* max_pdiv n == the largest prime divisor of n > 1, else 1. *) (* divisors m == the sorted list of divisors of m > 0, else [::]. *) (* totient n == the Euler totient (#|{i < n | i and n coprime}|). *) (* nat_pred == the type of explicit collective nat predicates. *) (* := simpl_pred nat. *) (* -> We allow the coercion nat >-> nat_pred, interpreting p as pred1 p. *) (* -> We define a predType for nat_pred, enabling the notation p \in pi. *) (* -> We don't have nat_pred >-> pred, which would imply nat >-> Funclass. *) (* pi^' == the complement of pi : nat_pred, i.e., the nat_pred such *) (* that (p \in pi^') = (p \notin pi). *) (* \pi(n) == the set of prime divisors of n, i.e., the nat_pred such *) (* that (p \in \pi(n)) = (p \in primes n). *) (* \pi(A) == the set of primes of #|A|, with A a collective predicate *) (* over a finite Type. *) (* -> The notation \pi(A) is implemented with a collapsible Coercion. The *) (* type of A must coerce to finpred_sort (e.g., by coercing to {set T}) *) (* and not merely implement the predType interface (as seq T does). *) (* -> The expression #|A| will only appear in \pi(A) after simplification *) (* collapses the coercion, so it is advisable to do so early on. *) (* pi.-nat n <=> n > 0 and all prime divisors of n are in pi. *) (* n`_pi == the pi-part of n -- the largest pi.-nat divisor of n. *) (* := \prod_(0 <= p < n.+1 | p \in pi) p ^ logn p n. *) (* -> The nat >-> nat_pred coercion lets us write p.-nat n and n`_p. *) (* In addition to the lemmas relevant to these definitions, this file also *) (* contains the dvdn_sum lemma, so that bigop.v doesn't depend on div.v. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Reserved Notation "pi ^'" (format "pi ^'"). Reserved Notation "pi .-nat" (format "pi .-nat"). (* The complexity of any arithmetic operation with the Peano representation *) (* is pretty dreadful, so using algorithms for "harder" problems such as *) (* factoring, that are geared for efficient arithmetic leads to dismal *) (* performance -- it takes a significant time, for instance, to compute the *) (* divisors of just a two-digit number. On the other hand, for Peano *) (* integers, prime factoring (and testing) is linear-time with a small *) (* constant factor -- indeed, the same as converting in and out of a binary *) (* representation. This is implemented by the code below, which is then *) (* used to give the "standard" definitions of prime, primes, and divisors, *) (* which can then be used casually in proofs with moderately-sized numeric *) (* values (indeed, the code here performs well for up to 6-digit numbers). *) Module Import PrimeDecompAux. (* We start with faster mod-2 and 2-valuation functions. *) Fixpoint edivn2 q r := if r is r'.+2 then edivn2 q.+1 r' else (q, r). Lemma edivn2P n : edivn_spec n 2 (edivn2 0 n). Proof. rewrite -[n]odd_double_half addnC -{1}[n./2]addn0 -{1}mul2n mulnC. elim: n./2 {1 4}0 => [|r IHr] q; first by case (odd n) => /=. by rewrite addSnnS; apply: IHr. Qed. Fixpoint elogn2 e q r {struct q} := match q, r with | 0, _ | _, 0 => (e, q) | q'.+1, 1 => elogn2 e.+1 q' q' | q'.+1, r'.+2 => elogn2 e q' r' end. Arguments elogn2 : simpl nomatch. Variant elogn2_spec n : nat * nat -> Type := Elogn2Spec e m of n = 2 ^ e * m.*2.+1 : elogn2_spec n (e, m). Lemma elogn2P n : elogn2_spec n.+1 (elogn2 0 n n). Proof. rewrite -[n.+1]mul1n -[1]/(2 ^ 0) -[n in _ * n.+1](addKn n n) addnn. elim: n {1 4 6}n {2 3}0 (leqnn n) => [|q IHq] [|[|r]] e //=; last first. by move/ltnW; apply: IHq. rewrite subn1 prednK // -mul2n mulnA -expnSr. by rewrite -[q in _ * q.+1](addKn q q) addnn => _; apply: IHq. Qed. Definition ifnz T n (x y : T) := if n is 0 then y else x. Variant ifnz_spec T n (x y : T) : T -> Type := | IfnzPos of n > 0 : ifnz_spec n x y x | IfnzZero of n = 0 : ifnz_spec n x y y. Lemma ifnzP T n (x y : T) : ifnz_spec n x y (ifnz n x y). Proof. by case: n => [|n]; [right | left]. Qed. (* The list of divisors and the Euler function are computed directly from *) (* the decomposition, using a merge_sort variant sort of the divisor list. *) Definition add_divisors f divs := let: (p, e) := f in let add1 divs' := merge leq (map (NatTrec.mul p) divs') divs in iter e add1 divs. Import NatTrec. Definition add_totient_factor f m := let: (p, e) := f in p.-1 * p ^ e.-1 * m. Definition cons_pfactor (p e : nat) pd := ifnz e ((p, e) :: pd) pd. Notation "p ^? e :: pd" := (cons_pfactor p e pd) (at level 30, e at level 30, pd at level 60) : nat_scope. End PrimeDecompAux. (* For pretty-printing. *) Definition NumFactor (f : nat * nat) := ([Num of f.1], f.2). Definition pfactor p e := p ^ e. Section prime_decomp. Import NatTrec. Local Fixpoint prime_decomp_rec m k a b c e := let p := k.*2.+1 in if a is a'.+1 then if b - (ifnz e 1 k - c) is b'.+1 then [rec m, k, a', b', ifnz c c.-1 (ifnz e p.-2 1), e] else if (b == 0) && (c == 0) then let b' := k + a' in [rec b'.*2.+3, k, a', b', k.-1, e.+1] else let bc' := ifnz e (ifnz b (k, 0) (edivn2 0 c)) (b, c) in p ^? e :: ifnz a' [rec m, k.+1, a'.-1, bc'.1 + a', bc'.2, 0] [:: (m, 1)] else if (b == 0) && (c == 0) then [:: (p, e.+2)] else p ^? e :: [:: (m, 1)] where "[ 'rec' m , k , a , b , c , e ]" := (prime_decomp_rec m k a b c e). Definition prime_decomp n := let: (e2, m2) := elogn2 0 n.-1 n.-1 in if m2 < 2 then 2 ^? e2 :: 3 ^? m2 :: [::] else let: (a, bc) := edivn m2.-2 3 in let: (b, c) := edivn (2 - bc) 2 in 2 ^? e2 :: [rec m2.*2.+1, 1, a, b, c, 0]. End prime_decomp. Definition primes n := unzip1 (prime_decomp n). Definition prime p := if prime_decomp p is [:: (_ , 1)] then true else false. Definition nat_pred := simpl_pred nat. Definition pi_arg := nat. Coercion pi_arg_of_nat (n : nat) : pi_arg := n. Coercion pi_arg_of_fin_pred T pT (A : @fin_pred_sort T pT) : pi_arg := #|A|. Arguments pi_arg_of_nat n /. Arguments pi_arg_of_fin_pred {T pT} A /. Definition pi_of (n : pi_arg) : nat_pred := [pred p in primes n]. Notation "\pi ( n )" := (pi_of n) (format "\pi ( n )") : nat_scope. Notation "\p 'i' ( A )" := \pi(#|A|) (format "\p 'i' ( A )") : nat_scope. Definition pdiv n := head 1 (primes n). Definition max_pdiv n := last 1 (primes n). Definition divisors n := foldr add_divisors [:: 1] (prime_decomp n). Definition totient n := foldr add_totient_factor (n > 0) (prime_decomp n). (* Correctness of the decomposition algorithm. *) Lemma prime_decomp_correct : let pd_val pd := \prod_(f <- pd) pfactor f.1 f.2 in let lb_dvd q m := ~~ has [pred d | d %| m] (index_iota 2 q) in let pf_ok f := lb_dvd f.1 f.1 && (0 < f.2) in let pd_ord q pd := path ltn q (unzip1 pd) in let pd_ok q n pd := [/\ n = pd_val pd, all pf_ok pd & pd_ord q pd] in forall n, n > 0 -> pd_ok 1 n (prime_decomp n). Proof. rewrite unlock => pd_val lb_dvd pf_ok pd_ord pd_ok. have leq_pd_ok m p q pd: q <= p -> pd_ok p m pd -> pd_ok q m pd. rewrite /pd_ok /pd_ord; case: pd => [|[r _] pd] //= leqp [<- ->]. by case/andP=> /(leq_trans _)->. have apd_ok m e q p pd: lb_dvd p p || (e == 0) -> q < p -> pd_ok p m pd -> pd_ok q (p ^ e * m) (p ^? e :: pd). - case: e => [|e]; rewrite orbC /= => pr_p ltqp. by rewrite mul1n; apply: leq_pd_ok; apply: ltnW. by rewrite /pd_ok /pd_ord /pf_ok /= pr_p ltqp => [[<- -> ->]]. case=> // n _; rewrite /prime_decomp. case: elogn2P => e2 m2 -> {n}; case: m2 => [|[|abc]]; try exact: apd_ok. rewrite [_.-2]/= !ltnS ltn0 natTrecE; case: edivnP => a bc ->{abc}. case: edivnP => b c def_bc /= ltc2 ltbc3; apply: (apd_ok) => //. move def_m: _.*2.+1 => m; set k := {2}1; rewrite -[2]/k.*2; set e := 0. pose p := k.*2.+1; rewrite -{1}[m]mul1n -[1]/(p ^ e)%N. have{def_m bc def_bc ltc2 ltbc3}: let kb := (ifnz e k 1).*2 in [&& k > 0, p < m, lb_dvd p m, c < kb & lb_dvd p p || (e == 0)] /\ m + (b * kb + c).*2 = p ^ 2 + (a * p).*2. - rewrite -def_m [in lb_dvd _ _]def_m; split=> //=; last first. by rewrite -def_bc addSn -doubleD 2!addSn -addnA subnKC // addnC. rewrite ltc2 /lb_dvd /index_iota /= dvdn2 -def_m. by rewrite [_.+2]lock /= odd_double. have [n] := ubnP a. elim: n => // n IHn in a (k) p m b c (e) * => /ltnSE-le_a_n []. set kb := _.*2; set d := _ + c => /and5P[lt0k ltpm leppm ltc pr_p def_m]. have def_k1: k.-1.+1 = k := ltn_predK lt0k. have def_kb1: kb.-1.+1 = kb by rewrite /kb -def_k1; case e. have eq_bc_0: (b == 0) && (c == 0) = (d == 0). by rewrite addn_eq0 muln_eq0 orbC -def_kb1. have lt1p: 1 < p by rewrite ltnS double_gt0. have co_p_2: coprime p 2 by rewrite /coprime gcdnC gcdnE modn2 /= odd_double. have if_d0: d = 0 -> [/\ m = (p + a.*2) * p, lb_dvd p p & lb_dvd p (p + a.*2)]. move=> d0; have{d0} def_m: m = (p + a.*2) * p. by rewrite d0 addn0 -!mul2n mulnA -mulnDl in def_m *. split=> //; apply/hasPn=> r /(hasPn leppm); apply: contra => /= dv_r. by rewrite def_m dvdn_mull. by rewrite def_m dvdn_mulr. case def_a: a => [|a'] /= in le_a_n *; rewrite !natTrecE -/p {}eq_bc_0. case: d if_d0 def_m => [[//| def_m {}pr_p pr_m'] _ | d _ def_m] /=. rewrite def_m def_a addn0 mulnA -2!expnSr. by split; rewrite /pd_ord /pf_ok /= ?muln1 ?pr_p ?leqnn. apply: apd_ok; rewrite // /pd_ok /= /pfactor expn1 muln1 /pd_ord /= ltpm. rewrite /pf_ok !andbT /=; split=> //; apply: contra leppm. case/hasP=> r /=; rewrite mem_index_iota => /andP[lt1r ltrm] dvrm; apply/hasP. have [ltrp | lepr] := ltnP r p. by exists r; rewrite // mem_index_iota lt1r. case/dvdnP: dvrm => q def_q; exists q; last by rewrite def_q /= dvdn_mulr. rewrite mem_index_iota -(ltn_pmul2r (ltnW lt1r)) -def_q mul1n ltrm. move: def_m; rewrite def_a addn0 -(@ltn_pmul2r p) // mulnn => <-. apply: (@leq_ltn_trans m); first by rewrite def_q leq_mul. by rewrite -addn1 leq_add2l. have def_k2: k.*2 = ifnz e 1 k * kb. by rewrite /kb; case: (e) => [|e']; rewrite (mul1n, muln2). case def_b': (b - _) => [|b']; last first. have ->: ifnz e k.*2.-1 1 = kb.-1 by rewrite /kb; case e. apply: IHn => {n le_a_n}//; rewrite -/p -/kb; split=> //. rewrite lt0k ltpm leppm pr_p andbT /=. by case: ifnzP; [move/ltn_predK->; apply: ltnW | rewrite def_kb1]. apply: (@addIn p.*2). rewrite -2!addnA -!doubleD -addnA -mulSnr -def_a -def_m /d. have ->: b * kb = b' * kb + (k.*2 - c * kb + kb). rewrite addnCA addnC -mulSnr -def_b' def_k2 -mulnBl -mulnDl subnK //. by rewrite ltnW // -subn_gt0 def_b'. rewrite -addnA; congr (_ + (_ + _).*2). case: (c) ltc; first by rewrite -addSnnS def_kb1 subn0 addn0 addnC. rewrite /kb; case e => [[] // _ | e' c' _] /=; last first. by rewrite subnDA subnn addnC addSnnS. by rewrite mul1n -doubleB -doubleD subn1 !addn1 def_k1. have ltdp: d < p. move/eqP: def_b'; rewrite subn_eq0 -(@leq_pmul2r kb); last first. by rewrite -def_kb1. rewrite mulnBl -def_k2 ltnS -(leq_add2r c); move/leq_trans; apply. have{} ltc: c < k.*2. by apply: (leq_trans ltc); rewrite leq_double /kb; case e. rewrite -{2}(subnK (ltnW ltc)) leq_add2r leq_sub2l //. by rewrite -def_kb1 mulnS leq_addr. case def_d: d if_d0 => [|d'] => [[//|{ltdp pr_p}def_m pr_p pr_m'] | _]. rewrite eqxx -doubleS -addnS -def_a doubleD -addSn -/p def_m. rewrite mulnCA mulnC -expnSr. apply: IHn => {n le_a_n}//; rewrite -/p -/kb; split. rewrite lt0k -addn1 leq_add2l {1}def_a pr_m' pr_p /= def_k1 -addnn. by rewrite leq_addr. rewrite -addnA -doubleD addnCA def_a addSnnS def_k1 -(addnC k) -mulnSr. by rewrite -[_.*2.+1]/p mulnDl doubleD addnA -mul2n mulnA mul2n -mulSn. have next_pm: lb_dvd p.+2 m. rewrite /lb_dvd /index_iota (addKn 2) -(subnK lt1p) iotaD has_cat. apply/norP; split; rewrite //= orbF subnKC // orbC. apply/norP; split; apply/dvdnP=> [[q def_q]]. case/hasP: leppm; exists 2; first by rewrite /p -(subnKC lt0k). by rewrite /= def_q dvdn_mull // dvdn2 /= odd_double. move/(congr1 (dvdn p)): def_m; rewrite -!mul2n mulnA -mulnDl. rewrite dvdn_mull // dvdn_addr; last by rewrite def_q dvdn_mull. case/dvdnP=> r; rewrite mul2n => def_r; move: ltdp (congr1 odd def_r). rewrite odd_double -ltn_double def_r -mul2n ltn_pmul2r //. by case: r def_r => [|[|[]]] //; rewrite def_d // mul1n /= odd_double. apply: apd_ok => //; case: a' def_a le_a_n => [|a'] def_a => [_ | lta] /=. rewrite /pd_ok /= /pfactor expn1 muln1 /pd_ord /= ltpm /pf_ok !andbT /=. split=> //; apply: contra next_pm. case/hasP=> q; rewrite mem_index_iota => /andP[lt1q ltqm] dvqm; apply/hasP. have [ltqp | lepq] := ltnP q p.+2. by exists q; rewrite // mem_index_iota lt1q. case/dvdnP: dvqm => r def_r; exists r; last by rewrite def_r /= dvdn_mulr. rewrite mem_index_iota -(ltn_pmul2r (ltnW lt1q)) -def_r mul1n ltqm /=. rewrite -(@ltn_pmul2l p.+2) //; apply: (@leq_ltn_trans m). by rewrite def_r mulnC leq_mul. rewrite -addn2 mulnn sqrnD mul2n muln2 -addnn addnACA. by rewrite def_a mul1n in def_m; rewrite -def_m addnS /= ltnS -addnA leq_addr. set bc := ifnz _ _ _; apply: leq_pd_ok (leqnSn _) _. rewrite -doubleS -{1}[m]mul1n -[1]/(k.+1.*2.+1 ^ 0)%N. apply: IHn; first exact: ltnW. rewrite doubleS -/p [ifnz 0 _ _]/=; do 2?split => //. rewrite orbT next_pm /= -(leq_add2r d.*2) def_m 2!addSnnS -doubleS leq_add. - move: ltc; rewrite /kb {}/bc andbT; case e => //= e' _; case: ifnzP => //. by case: edivn2P. - by rewrite -[ltnLHS]muln1 ltn_pmul2l. by rewrite leq_double def_a mulSn (leq_trans ltdp) ?leq_addr. rewrite mulnDl !muln2 -addnA addnCA doubleD addnCA. rewrite (_ : _ + bc.2 = d); last first. rewrite /d {}/bc /kb -muln2. case: (e) (b) def_b' => //= _ []; first by case: edivn2P. by case c; do 2?case; rewrite // mul1n /= muln2. rewrite def_m 3!doubleS addnC -(addn2 p) sqrnD mul2n muln2 -3!addnA. congr (_ + _); rewrite 4!addnS -!doubleD; congr _.*2.+2.+2. by rewrite def_a -add2n mulnDl -addnA -muln2 -mulnDr mul2n. Qed. Lemma primePn n : reflect (n < 2 \/ exists2 d, 1 < d < n & d %| n) (~~ prime n). Proof. rewrite /prime; case: n => [|[|p2]]; try by do 2!left. case: (@prime_decomp_correct p2.+2) => //; rewrite unlock. case: prime_decomp => [|[q [|[|e]]] pd] //=; last first; last by rewrite andbF. rewrite {1}/pfactor 2!expnS -!mulnA /=. case: (_ ^ _ * _) => [|u -> _ /andP[lt1q _]]; first by rewrite !muln0. left; right; exists q; last by rewrite dvdn_mulr. have lt0q := ltnW lt1q; rewrite lt1q -[ltnLHS]muln1 ltn_pmul2l //. by rewrite -[2]muln1 leq_mul. rewrite {1}/pfactor expn1; case: pd => [|[r e] pd] /=; last first. case: e => [|e] /=; first by rewrite !andbF. rewrite {1}/pfactor expnS -mulnA. case: (_ ^ _ * _) => [|u -> _ /and3P[lt1q ltqr _]]; first by rewrite !muln0. left; right; exists q; last by rewrite dvdn_mulr. by rewrite lt1q -[ltnLHS]mul1n ltn_mul // -[q.+1]muln1 leq_mul. rewrite muln1 !andbT => def_q pr_q lt1q; right=> [[]] // [d]. by rewrite def_q -mem_index_iota => in_d_2q dv_d_q; case/hasP: pr_q; exists d. Qed. Lemma primeNsig n : ~~ prime n -> 2 <= n -> { d : nat | 1 < d < n & d %| n }. Proof. by move=> /primePn; case: ltnP => // lt1n nP _; apply/sig2W; case: nP. Qed. Lemma primeP p : reflect (p > 1 /\ forall d, d %| p -> xpred2 1 p d) (prime p). Proof. rewrite -[prime p]negbK; have [npr_p | pr_p] := primePn p. right=> [[lt1p pr_p]]; case: npr_p => [|[d n1pd]]. by rewrite ltnNge lt1p. by move/pr_p=> /orP[] /eqP def_d; rewrite def_d ltnn ?andbF in n1pd. have [lep1 | lt1p] := leqP; first by case: pr_p; left. left; split=> // d dv_d_p; apply/norP=> [[nd1 ndp]]; case: pr_p; right. exists d; rewrite // andbC 2!ltn_neqAle ndp eq_sym nd1. by have lt0p := ltnW lt1p; rewrite dvdn_leq // (dvdn_gt0 lt0p). Qed. Lemma prime_nt_dvdP d p : prime p -> d != 1 -> reflect (d = p) (d %| p). Proof. case/primeP=> _ min_p d_neq1; apply: (iffP idP) => [/min_p|-> //]. by rewrite (negPf d_neq1) /= => /eqP. Qed. Arguments primeP {p}. Arguments primePn {n}. Lemma prime_gt1 p : prime p -> 1 < p. Proof. by case/primeP. Qed. Lemma prime_gt0 p : prime p -> 0 < p. Proof. by move/prime_gt1; apply: ltnW. Qed. #[global] Hint Resolve prime_gt1 prime_gt0 : core. Lemma prod_prime_decomp n : n > 0 -> n = \prod_(f <- prime_decomp n) f.1 ^ f.2. Proof. by case/prime_decomp_correct. Qed. Lemma even_prime p : prime p -> p = 2 \/ odd p. Proof. move=> pr_p; case odd_p: (odd p); [by right | left]. have: 2 %| p by rewrite dvdn2 odd_p. by case/primeP: pr_p => _ dv_p /dv_p/(2 =P p). Qed. Lemma prime_oddPn p : prime p -> reflect (p = 2) (~~ odd p). Proof. by move=> p_pr; apply: (iffP idP) => [|-> //]; case/even_prime: p_pr => ->. Qed. Lemma odd_prime_gt2 p : odd p -> prime p -> p > 2. Proof. by move=> odd_p /prime_gt1; apply: odd_gt2. Qed. Lemma mem_prime_decomp n p e : (p, e) \in prime_decomp n -> [/\ prime p, e > 0 & p ^ e %| n]. Proof. case: (posnP n) => [-> //| /prime_decomp_correct[def_n mem_pd ord_pd pd_pe]]. have /andP[pr_p ->] := allP mem_pd _ pd_pe; split=> //; last first. case/splitPr: pd_pe def_n => pd1 pd2 ->. by rewrite big_cat big_cons /= mulnCA dvdn_mulr. have lt1p: 1 < p. apply: (allP (order_path_min ltn_trans ord_pd)). by apply/mapP; exists (p, e). apply/primeP; split=> // d dv_d_p; apply/norP=> [[nd1 ndp]]. case/hasP: pr_p; exists d => //. rewrite mem_index_iota andbC 2!ltn_neqAle ndp eq_sym nd1. by have lt0p := ltnW lt1p; rewrite dvdn_leq // (dvdn_gt0 lt0p). Qed. Lemma prime_coprime p m : prime p -> coprime p m = ~~ (p %| m). Proof. case/primeP=> p_gt1 p_pr; apply/eqP/negP=> [d1 | ndv_pm]. case/dvdnP=> k def_m; rewrite -(addn0 m) def_m gcdnMDl gcdn0 in d1. by rewrite d1 in p_gt1. by apply: gcdn_def => // d /p_pr /orP[] /eqP->. Qed. Lemma dvdn_prime2 p q : prime p -> prime q -> (p %| q) = (p == q). Proof. move=> pr_p pr_q; apply: negb_inj. by rewrite eqn_dvd negb_and -!prime_coprime // coprime_sym orbb. Qed. Lemma Euclid_dvd1 p : prime p -> (p %| 1) = false. Proof. by rewrite dvdn1; case: eqP => // ->. Qed. Lemma Euclid_dvdM m n p : prime p -> (p %| m * n) = (p %| m) || (p %| n). Proof. move=> pr_p; case dv_pm: (p %| m); first exact: dvdn_mulr. by rewrite Gauss_dvdr // prime_coprime // dv_pm. Qed. Lemma Euclid_dvd_prod (I : Type) (r : seq I) (P : pred I) (f : I -> nat) p : prime p -> p %| \prod_(i <- r | P i) f i = \big[orb/false]_(i <- r | P i) (p %| f i). Proof. move=> pP; apply: big_morph=> [x y|]; [exact: Euclid_dvdM | exact: Euclid_dvd1]. Qed. Lemma Euclid_dvdX m n p : prime p -> (p %| m ^ n) = (p %| m) && (n > 0). Proof. case: n => [|n] pr_p; first by rewrite andbF Euclid_dvd1. by apply: (inv_inj negbK); rewrite !andbT -!prime_coprime // coprime_pexpr. Qed. Lemma mem_primes p n : (p \in primes n) = [&& prime p, n > 0 & p %| n]. Proof. rewrite andbCA; have [-> // | /= n_gt0] := posnP. apply/mapP/andP=> [[[q e]]|[pr_p]] /=. case/mem_prime_decomp=> pr_q e_gt0 /dvdnP [u ->] -> {p}. by rewrite -(prednK e_gt0) expnS mulnCA dvdn_mulr. rewrite [n in _ %| n]prod_prime_decomp // big_seq. apply big_ind => [| u v IHu IHv | [q e] /= mem_qe dv_p_qe]. - by rewrite Euclid_dvd1. - by rewrite Euclid_dvdM // => /orP[]. exists (q, e) => //=; case/mem_prime_decomp: mem_qe => pr_q _ _. by rewrite Euclid_dvdX // dvdn_prime2 // in dv_p_qe; case: eqP dv_p_qe. Qed. Lemma sorted_primes n : sorted ltn (primes n). Proof. by case: (posnP n) => [-> // | /prime_decomp_correct[_ _]]; apply: path_sorted. Qed. Lemma all_prime_primes n : all prime (primes n). Proof. by apply/allP => p; rewrite mem_primes => /and3P[]. Qed. Lemma eq_primes m n : (primes m =i primes n) <-> (primes m = primes n). Proof. split=> [eqpr| -> //]. by apply: (irr_sorted_eq ltn_trans ltnn); rewrite ?sorted_primes. Qed. Lemma primes_uniq n : uniq (primes n). Proof. exact: (sorted_uniq ltn_trans ltnn (sorted_primes n)). Qed. (* The smallest prime divisor *) Lemma pi_pdiv n : (pdiv n \in \pi(n)) = (n > 1). Proof. case: n => [|[|n]] //; rewrite /pdiv !inE /primes. have:= prod_prime_decomp (ltn0Sn n.+1); rewrite unlock. by case: prime_decomp => //= pf pd _; rewrite mem_head. Qed. Lemma pdiv_prime n : 1 < n -> prime (pdiv n). Proof. by rewrite -pi_pdiv mem_primes; case/and3P. Qed. Lemma pdiv_dvd n : pdiv n %| n. Proof. by case: n (pi_pdiv n) => [|[|n]] //; rewrite mem_primes=> /and3P[]. Qed. Lemma pi_max_pdiv n : (max_pdiv n \in \pi(n)) = (n > 1). Proof. rewrite !inE -pi_pdiv /max_pdiv /pdiv !inE. by case: (primes n) => //= p ps; rewrite mem_head mem_last. Qed. Lemma max_pdiv_prime n : n > 1 -> prime (max_pdiv n). Proof. by rewrite -pi_max_pdiv mem_primes => /andP[]. Qed. Lemma max_pdiv_dvd n : max_pdiv n %| n. Proof. by case: n (pi_max_pdiv n) => [|[|n]] //; rewrite mem_primes => /andP[]. Qed. Lemma pdiv_leq n : 0 < n -> pdiv n <= n. Proof. by move=> n_gt0; rewrite dvdn_leq // pdiv_dvd. Qed. Lemma max_pdiv_leq n : 0 < n -> max_pdiv n <= n. Proof. by move=> n_gt0; rewrite dvdn_leq // max_pdiv_dvd. Qed. Lemma pdiv_gt0 n : 0 < pdiv n. Proof. by case: n => [|[|n]] //; rewrite prime_gt0 ?pdiv_prime. Qed. Lemma max_pdiv_gt0 n : 0 < max_pdiv n. Proof. by case: n => [|[|n]] //; rewrite prime_gt0 ?max_pdiv_prime. Qed. #[global] Hint Resolve pdiv_gt0 max_pdiv_gt0 : core. Lemma pdiv_min_dvd m d : 1 < d -> d %| m -> pdiv m <= d. Proof. case: (posnP m) => [->|mpos] lt1d dv_d_m; first exact: ltnW. rewrite /pdiv; apply: leq_trans (pdiv_leq (ltnW lt1d)). have: pdiv d \in primes m. by rewrite mem_primes mpos pdiv_prime // (dvdn_trans (pdiv_dvd d)). case: (primes m) (sorted_primes m) => //= p pm ord_pm; rewrite inE. by case/predU1P => [-> | /(allP (order_path_min ltn_trans ord_pm)) /ltnW]. Qed. Lemma max_pdiv_max n p : p \in \pi(n) -> p <= max_pdiv n. Proof. rewrite /max_pdiv !inE => n_p. case/splitPr: n_p (sorted_primes n) => p1 p2; rewrite last_cat -cat_rcons /=. rewrite headI /= cat_path -(last_cons 0) -headI last_rcons; case/andP=> _. move/(order_path_min ltn_trans); case/lastP: p2 => //= p2 q. by rewrite all_rcons last_rcons ltn_neqAle -andbA => /and3P[]. Qed. Lemma ltn_pdiv2_prime n : 0 < n -> n < pdiv n ^ 2 -> prime n. Proof. case def_n: n => [|[|n']] // _; rewrite -def_n => lt_n_p2. suffices ->: n = pdiv n by rewrite pdiv_prime ?def_n. apply/eqP; rewrite eqn_leq leqNgt andbC pdiv_leq; last by rewrite def_n. apply/contraL: lt_n_p2 => lt_pm_m; case/dvdnP: (pdiv_dvd n) => q def_q. rewrite -leqNgt [leqRHS]def_q leq_pmul2r // pdiv_min_dvd //. by rewrite -[pdiv n]mul1n [ltnRHS]def_q ltn_pmul2r in lt_pm_m. by rewrite def_q dvdn_mulr. Qed. Lemma primePns n : reflect (n < 2 \/ exists p, [/\ prime p, p ^ 2 <= n & p %| n]) (~~ prime n). Proof. apply: (iffP idP) => [npr_p|]; last first. case=> [|[p [pr_p le_p2_n dv_p_n]]]; first by case: n => [|[]]. apply/negP=> pr_n; move: dv_p_n le_p2_n; rewrite dvdn_prime2 //; move/eqP->. by rewrite leqNgt -[ltnLHS]muln1 ltn_pmul2l ?prime_gt1 ?prime_gt0. have [lt1p|] := leqP; [right | by left]. exists (pdiv n); rewrite pdiv_dvd pdiv_prime //; split=> //. by case: leqP npr_p => // /ltn_pdiv2_prime -> //; exact: ltnW. Qed. Arguments primePns {n}. Lemma pdivP n : n > 1 -> {p | prime p & p %| n}. Proof. by move=> lt1n; exists (pdiv n); rewrite ?pdiv_dvd ?pdiv_prime. Qed. Lemma primes_eq0 n : (primes n == [::]) = (n < 2). Proof. case: n => [|[|n']]//=; have [//|p pp pn] := @pdivP (n'.+2). suff: p \in primes n'.+2 by case: primes. by rewrite mem_primes pp pn. Qed. Lemma primesM m n p : m > 0 -> n > 0 -> (p \in primes (m * n)) = (p \in primes m) || (p \in primes n). Proof. move=> m_gt0 n_gt0; rewrite !mem_primes muln_gt0 m_gt0 n_gt0. by case pr_p: (prime p); rewrite // Euclid_dvdM. Qed. Lemma primesX m n : n > 0 -> primes (m ^ n) = primes m. Proof. case: n => // n _; rewrite expnS; have [-> // | m_gt0] := posnP m. apply/eq_primes => /= p; elim: n => [|n IHn]; first by rewrite muln1. by rewrite primesM ?(expn_gt0, expnS, IHn, orbb, m_gt0). Qed. Lemma primes_prime p : prime p -> primes p = [:: p]. Proof. move=> pr_p; apply: (irr_sorted_eq ltn_trans ltnn) => // [|q]. exact: sorted_primes. rewrite mem_seq1 mem_primes prime_gt0 //=. by apply/andP/idP=> [[pr_q q_p] | /eqP-> //]; rewrite -dvdn_prime2. Qed. Lemma coprime_has_primes m n : 0 < m -> 0 < n -> coprime m n = ~~ has [in primes m] (primes n). Proof. move=> m_gt0 n_gt0; apply/eqP/hasPn=> [mn1 p | no_p_mn]. rewrite /= !mem_primes m_gt0 n_gt0 /= => /andP[pr_p p_n]. have:= prime_gt1 pr_p; rewrite pr_p ltnNge -mn1 /=; apply: contra => p_m. by rewrite dvdn_leq ?gcdn_gt0 ?m_gt0 // dvdn_gcd ?p_m. apply/eqP; rewrite eqn_leq gcdn_gt0 m_gt0 andbT leqNgt; apply/negP. move/pdiv_prime; set p := pdiv _ => pr_p. move/implyP: (no_p_mn p); rewrite /= !mem_primes m_gt0 n_gt0 pr_p /=. by rewrite !(dvdn_trans (pdiv_dvd _)) // (dvdn_gcdl, dvdn_gcdr). Qed. Lemma pdiv_id p : prime p -> pdiv p = p. Proof. by move=> p_pr; rewrite /pdiv primes_prime. Qed. Lemma pdiv_pfactor p k : prime p -> pdiv (p ^ k.+1) = p. Proof. by move=> p_pr; rewrite /pdiv primesX ?primes_prime. Qed. (* Primes are unbounded. *) Lemma prime_above m : {p | m < p & prime p}. Proof. have /pdivP[p pr_p p_dv_m1]: 1 < m`! + 1 by rewrite addn1 ltnS fact_gt0. exists p => //; rewrite ltnNge; apply: contraL p_dv_m1 => p_le_m. by rewrite dvdn_addr ?dvdn_fact ?prime_gt0 // gtnNdvd ?prime_gt1. Qed. (* "prime" logarithms and p-parts. *) Fixpoint logn_rec d m r := match r, edivn m d with | r'.+1, (_.+1 as m', 0) => (logn_rec d m' r').+1 | _, _ => 0 end. Definition logn p m := if prime p then logn_rec p m m else 0. Lemma lognE p m : logn p m = if [&& prime p, 0 < m & p %| m] then (logn p (m %/ p)).+1 else 0. Proof. rewrite /logn /dvdn; case p_pr: (prime p) => //. case def_m: m => // [m']; rewrite !andTb [LHS]/= -def_m /divn modn_def. case: edivnP def_m => [[|q] [|r] -> _] // def_m; congr _.+1; rewrite [_.1]/=. have{m def_m}: q < m'. by rewrite -ltnS -def_m addn0 mulnC -{1}[q.+1]mul1n ltn_pmul2r // prime_gt1. elim/ltn_ind: m' {q}q.+1 (ltn0Sn q) => -[_ []|r IHr m] //= m_gt0 le_mr. rewrite -[m in logn_rec _ _ m]prednK //=. case: edivnP => [[|q] [|_] def_q _] //; rewrite addn0 in def_q. have{def_q} lt_qm1: q < m.-1. by rewrite -[q.+1]muln1 -ltnS prednK // def_q ltn_pmul2l // prime_gt1. have{le_mr} le_m1r: m.-1 <= r by rewrite -ltnS prednK. by rewrite (IHr r) ?(IHr m.-1) // (leq_trans lt_qm1). Qed. Lemma logn_gt0 p n : (0 < logn p n) = (p \in primes n). Proof. by rewrite lognE -mem_primes; case: {+}(p \in _). Qed. Lemma ltn_log0 p n : n < p -> logn p n = 0. Proof. by case: n => [|n] ltnp; rewrite lognE ?andbF // gtnNdvd ?andbF. Qed. Lemma logn0 p : logn p 0 = 0. Proof. by rewrite /logn if_same. Qed. Lemma logn1 p : logn p 1 = 0. Proof. by rewrite lognE dvdn1 /= andbC; case: eqP => // ->. Qed. Lemma pfactor_gt0 p n : 0 < p ^ logn p n. Proof. by rewrite expn_gt0 lognE; case: (posnP p) => // ->. Qed. #[global] Hint Resolve pfactor_gt0 : core. Lemma pfactor_dvdn p n m : prime p -> m > 0 -> (p ^ n %| m) = (n <= logn p m). Proof. move=> p_pr; elim: n m => [|n IHn] m m_gt0; first exact: dvd1n. rewrite lognE p_pr m_gt0 /=; case dv_pm: (p %| m); last first. apply/dvdnP=> [] [/= q def_m]. by rewrite def_m expnS mulnCA dvdn_mulr in dv_pm. case/dvdnP: dv_pm m_gt0 => q ->{m}; rewrite muln_gt0 => /andP[p_gt0 q_gt0]. by rewrite expnSr dvdn_pmul2r // mulnK // IHn. Qed. Lemma pfactor_dvdnn p n : p ^ logn p n %| n. Proof. case: n => // n; case pr_p: (prime p); first by rewrite pfactor_dvdn. by rewrite lognE pr_p dvd1n. Qed. Lemma logn_prime p q : prime q -> logn p q = (p == q). Proof. move=> pr_q; have q_gt0 := prime_gt0 pr_q; rewrite lognE q_gt0 /=. case pr_p: (prime p); last by case: eqP pr_p pr_q => // -> ->. by rewrite dvdn_prime2 //; case: eqP => // ->; rewrite divnn q_gt0 logn1. Qed. Lemma pfactor_coprime p n : prime p -> n > 0 -> {m | coprime p m & n = m * p ^ logn p n}. Proof. move=> p_pr n_gt0; set k := logn p n. have dv_pk_n: p ^ k %| n by rewrite pfactor_dvdn. exists (n %/ p ^ k); last by rewrite divnK. rewrite prime_coprime // -(@dvdn_pmul2r (p ^ k)) ?expn_gt0 ?prime_gt0 //. by rewrite -expnS divnK // pfactor_dvdn // ltnn. Qed. Lemma pfactorK p n : prime p -> logn p (p ^ n) = n. Proof. move=> p_pr; have pn_gt0: p ^ n > 0 by rewrite expn_gt0 prime_gt0. apply/eqP; rewrite eqn_leq -pfactor_dvdn // dvdnn andbT. by rewrite -(leq_exp2l _ _ (prime_gt1 p_pr)) dvdn_leq // pfactor_dvdn. Qed. Lemma pfactorKpdiv p n : prime p -> logn (pdiv (p ^ n)) (p ^ n) = n. Proof. by case: n => // n p_pr; rewrite pdiv_pfactor ?pfactorK. Qed. Lemma dvdn_leq_log p m n : 0 < n -> m %| n -> logn p m <= logn p n. Proof. move=> n_gt0 dv_m_n; have m_gt0 := dvdn_gt0 n_gt0 dv_m_n. case p_pr: (prime p); last by do 2!rewrite lognE p_pr /=. by rewrite -pfactor_dvdn //; apply: dvdn_trans dv_m_n; rewrite pfactor_dvdn. Qed. Lemma ltn_logl p n : 0 < n -> logn p n < n. Proof. move=> n_gt0; have [p_gt1 | p_le1] := boolP (1 < p). by rewrite (leq_trans (ltn_expl _ p_gt1)) // dvdn_leq ?pfactor_dvdnn. by rewrite lognE (contraNF (@prime_gt1 _)). Qed. Lemma logn_Gauss p m n : coprime p m -> logn p (m * n) = logn p n. Proof. move=> co_pm; case p_pr: (prime p); last by rewrite /logn p_pr. have [-> | n_gt0] := posnP n; first by rewrite muln0. have [m0 | m_gt0] := posnP m; first by rewrite m0 prime_coprime ?dvdn0 in co_pm. have mn_gt0: m * n > 0 by rewrite muln_gt0 m_gt0. apply/eqP; rewrite eqn_leq andbC dvdn_leq_log ?dvdn_mull //. set k := logn p _; have: p ^ k %| m * n by rewrite pfactor_dvdn. by rewrite Gauss_dvdr ?coprimeXl // -pfactor_dvdn. Qed. Lemma logn_coprime p m : coprime p m -> logn p m = 0. Proof. by move=> coprime_pm; rewrite -[m]muln1 logn_Gauss// logn1. Qed. Lemma lognM p m n : 0 < m -> 0 < n -> logn p (m * n) = logn p m + logn p n. Proof. case p_pr: (prime p); last by rewrite /logn p_pr. have xlp := pfactor_coprime p_pr. case/xlp=> m' co_m' def_m /xlp[n' co_n' def_n] {xlp}. rewrite [in LHS]def_m [in LHS]def_n mulnCA -mulnA -expnD !logn_Gauss //. exact: pfactorK. Qed. Lemma lognX p m n : logn p (m ^ n) = n * logn p m. Proof. case p_pr: (prime p); last by rewrite /logn p_pr muln0. elim: n => [|n IHn]; first by rewrite logn1. have [->|m_gt0] := posnP m; first by rewrite exp0n // lognE andbF muln0. by rewrite expnS lognM ?IHn // expn_gt0 m_gt0. Qed. Lemma logn_div p m n : m %| n -> logn p (n %/ m) = logn p n - logn p m. Proof. rewrite dvdn_eq => /eqP def_n. case: (posnP n) => [-> |]; first by rewrite div0n logn0. by rewrite -{1 3}def_n muln_gt0 => /andP[q_gt0 m_gt0]; rewrite lognM ?addnK. Qed. Lemma dvdn_pfactor p d n : prime p -> reflect (exists2 m, m <= n & d = p ^ m) (d %| p ^ n). Proof. move=> p_pr; have pn_gt0: p ^ n > 0 by rewrite expn_gt0 prime_gt0. apply: (iffP idP) => [dv_d_pn|[m le_m_n ->]]; last first. by rewrite -(subnK le_m_n) expnD dvdn_mull. exists (logn p d); first by rewrite -(pfactorK n p_pr) dvdn_leq_log. have d_gt0: d > 0 by apply: dvdn_gt0 dv_d_pn. case: (pfactor_coprime p_pr d_gt0) => q co_p_q def_d. rewrite [LHS]def_d ((q =P 1) _) ?mul1n // -dvdn1. suff: q %| p ^ n * 1 by rewrite Gauss_dvdr // coprime_sym coprimeXl. by rewrite muln1 (dvdn_trans _ dv_d_pn) // def_d dvdn_mulr. Qed. Lemma prime_decompE n : prime_decomp n = [seq (p, logn p n) | p <- primes n]. Proof. case: n => // n; pose f0 := (0, 0); rewrite -map_comp. apply: (@eq_from_nth _ f0) => [|i lt_i_n]; first by rewrite size_map. rewrite (nth_map f0) //; case def_f: (nth _ _ i) => [p e] /=. congr (_, _); rewrite [n.+1]prod_prime_decomp //. have: (p, e) \in prime_decomp n.+1 by rewrite -def_f mem_nth. case/mem_prime_decomp=> pr_p _ _. rewrite (big_nth f0) big_mkord (bigD1 (Ordinal lt_i_n)) //=. rewrite def_f mulnC logn_Gauss ?pfactorK //. apply big_ind => [|m1 m2 com1 com2| [j ltj] /=]; first exact: coprimen1. by rewrite coprimeMr com1. rewrite -val_eqE /= => nji; case def_j: (nth _ _ j) => [q e1] /=. have: (q, e1) \in prime_decomp n.+1 by rewrite -def_j mem_nth. case/mem_prime_decomp=> pr_q e1_gt0 _; rewrite coprime_pexpr //. rewrite prime_coprime // dvdn_prime2 //; apply: contra nji => eq_pq. rewrite -(nth_uniq 0 _ _ (primes_uniq n.+1)) ?size_map //=. by rewrite !(nth_map f0) // def_f def_j /= eq_sym. Qed. (* Some combinatorial formulae. *) Lemma divn_count_dvd d n : n %/ d = \sum_(1 <= i < n.+1) (d %| i). Proof. have [-> | d_gt0] := posnP d; first by rewrite big_add1 divn0 big1. apply: (@addnI (d %| 0)); rewrite -(@big_ltn _ 0 _ 0 _ (dvdn d)) // big_mkord. rewrite (partition_big (fun i : 'I_n.+1 => inord (i %/ d)) 'I_(n %/ d).+1) //=. rewrite dvdn0 add1n -[_.+1 in LHS]card_ord -sum1_card. apply: eq_bigr => [[q ?] _]. rewrite (bigD1 (inord (q * d))) /eq_op /= !inordK ?ltnS -?leq_divRL ?mulnK //. rewrite dvdn_mull ?big1 // => [[i /= ?] /andP[/eqP <- /negPf]]. by rewrite eq_sym dvdn_eq inordK ?ltnS ?leq_div2r // => ->. Qed. Lemma logn_count_dvd p n : prime p -> logn p n = \sum_(1 <= k < n) (p ^ k %| n). Proof. rewrite big_add1 => p_prime; case: n => [|n]; first by rewrite logn0 big_geq. rewrite big_mkord -big_mkcond (eq_bigl _ _ (fun _ => pfactor_dvdn _ _ _)) //=. by rewrite big_ord_narrow ?sum1_card ?card_ord // -ltnS ltn_logl. Qed. (* Truncated real log. *) Definition trunc_log p n := let fix loop n k := if k is k'.+1 then if p <= n then (loop (n %/ p) k').+1 else 0 else 0 in if p <= 1 then 0 else loop n n. Lemma trunc_log0 p : trunc_log p 0 = 0. Proof. by case: p => [] // []. Qed. Lemma trunc_log1 p : trunc_log p 1 = 0. Proof. by case: p => [|[]]. Qed. Lemma trunc_log_bounds p n : 1 < p -> 0 < n -> let k := trunc_log p n in p ^ k <= n < p ^ k.+1. Proof. rewrite {+}/trunc_log => p_gt1; have p_gt0 := ltnW p_gt1. rewrite [p <= 1]leqNgt p_gt1 /=. set loop := (loop in loop n n); set m := n; rewrite [in n in loop m n]/m. have: m <= n by []; elim: n m => [|n IHn] [|m] //= /ltnSE-le_m_n _. have [le_p_n | // ] := leqP p _; rewrite 2!expnSr -leq_divRL -?ltn_divLR //. by apply: IHn; rewrite ?divn_gt0 // -ltnS (leq_trans (ltn_Pdiv _ _)). Qed. Lemma trunc_logP p n : 1 < p -> 0 < n -> p ^ trunc_log p n <= n. Proof. by move=> p_gt1 /(trunc_log_bounds p_gt1)/andP[]. Qed. Lemma trunc_log_ltn p n : 1 < p -> n < p ^ (trunc_log p n).+1. Proof. have [-> | n_gt0] := posnP n; first by rewrite trunc_log0 => /ltnW. by case/trunc_log_bounds/(_ n_gt0)/andP. Qed. Lemma trunc_log_max p k j : 1 < p -> p ^ j <= k -> j <= trunc_log p k. Proof. move=> p_gt1 le_pj_k; rewrite -ltnS -(@ltn_exp2l p) //. exact: leq_ltn_trans (trunc_log_ltn _ _). Qed. Lemma trunc_log_eq0 p n : (trunc_log p n == 0) = (p <= 1) || (n <= p.-1). Proof. case: p => [|[|p]]; case: n => // n; rewrite /= ltnS. have /= /andP[] := trunc_log_bounds (isT : 1 < p.+2) (isT : 0 < n.+1). case: trunc_log => [//|k] b1 b2. apply/idP/idP => [/eqP sk0 | nlep]; first by move: b2; rewrite sk0. symmetry; rewrite -[_ == _]/false /is_true -b1; apply/negbTE; rewrite -ltnNge. move: nlep; rewrite -ltnS => nlep; apply: (leq_ltn_trans nlep). by rewrite -[leqLHS]expn1; apply: leq_pexp2l. Qed. Lemma trunc_log_gt0 p n : (0 < trunc_log p n) = (1 < p) && (p.-1 < n). Proof. by rewrite ltnNge leqn0 trunc_log_eq0 negb_or -!ltnNge. Qed. Lemma trunc_log0n n : trunc_log 0 n = 0. Proof. by []. Qed. Lemma trunc_log1n n : trunc_log 1 n = 0. Proof. by []. Qed. Lemma leq_trunc_log p m n : m <= n -> trunc_log p m <= trunc_log p n. Proof. move=> mlen; case: p => [|[|p]]; rewrite ?trunc_log0n ?trunc_log1n //. case: m mlen => [|m] mlen; first by rewrite trunc_log0. apply/trunc_log_max => //; apply: leq_trans mlen; exact: trunc_logP. Qed. Lemma trunc_log_eq p n k : 1 < p -> p ^ n <= k < p ^ n.+1 -> trunc_log p k = n. Proof. move=> p_gt1 /andP[npLk kLpn]; apply/anti_leq. rewrite trunc_log_max// andbT -ltnS -(ltn_exp2l _ _ p_gt1). apply: leq_ltn_trans kLpn; apply: trunc_logP => //. by apply: leq_trans npLk; rewrite expn_gt0 ltnW. Qed. Lemma trunc_lognn p : 1 < p -> trunc_log p p = 1. Proof. by case: p => [|[|p]] // _; rewrite /trunc_log ltnSn divnn. Qed. Lemma trunc_expnK p n : 1 < p -> trunc_log p (p ^ n) = n. Proof. by move=> ?; apply: trunc_log_eq; rewrite // leqnn ltn_exp2l /=. Qed. Lemma trunc_logMp p n : 1 < p -> 0 < n -> trunc_log p (p * n) = (trunc_log p n).+1. Proof. case: p => [//|p] => p_gt0 n_gt0; apply: trunc_log_eq => //. rewrite expnS leq_pmul2l// trunc_logP//=. by rewrite expnS ltn_pmul2l// trunc_log_ltn. Qed. Lemma trunc_log2_double n : 0 < n -> trunc_log 2 n.*2 = (trunc_log 2 n).+1. Proof. by move=> n_gt0; rewrite -mul2n trunc_logMp. Qed. Lemma trunc_log2S n : 1 < n -> trunc_log 2 n = (trunc_log 2 n./2).+1. Proof. move=> n_gt1. rewrite -trunc_log2_double ?half_gt0//. rewrite -[n in LHS]odd_double_half. case: odd => //; rewrite add1n. apply: trunc_log_eq => //. rewrite leqW ?trunc_logP //= ?double_gt0 ?half_gt0//. rewrite trunc_log2_double ?half_gt0// expnS. by rewrite -doubleS mul2n leq_double trunc_log_ltn. Qed. (* Truncated up real logarithm *) Definition up_log p n := if (p <= 1) then 0 else let v := trunc_log p n in if n <= p ^ v then v else v.+1. Lemma up_log0 p : up_log p 0 = 0. Proof. by case: p => // [] []. Qed. Lemma up_log1 p : up_log p 1 = 0. Proof. by case: p => // [] []. Qed. Lemma up_log_eq0 p n : (up_log p n == 0) = (p <= 1) || (n <= 1). Proof. case: p => // [] [] // p. case: n => [|[|n]]; rewrite /up_log //=. have /= := trunc_log_bounds (isT : 1 < p.+2) (isT : 0 < n.+2). by case: (leqP _ n.+1); case: trunc_log. Qed. Lemma up_log_gt0 p n : (0 < up_log p n) = (1 < p) && (1 < n). Proof. by rewrite ltnNge leqn0 up_log_eq0 negb_or -!ltnNge. Qed. Lemma up_log_bounds p n : 1 < p -> 1 < n -> let k := up_log p n in p ^ k.-1 < n <= p ^ k. Proof. move=> p_gt1 n_gt1. have n_gt0 : 0 < n by apply: leq_trans n_gt1. rewrite /up_log (leqNgt p 1) p_gt1 /=. have /= /andP[tpLn nLtpS] := trunc_log_bounds p_gt1 n_gt0. have [nLnp|npLn] := leqP n (p ^ trunc_log p n); last by rewrite npLn ltnW. rewrite nLnp (leq_trans _ tpLn) // ltn_exp2l // prednK ?leqnn //. by case: trunc_log (leq_trans n_gt1 nLnp). Qed. Lemma up_logP p n : 1 < p -> n <= p ^ up_log p n. Proof. case: n => [|[|n]] // p_gt1; first by rewrite up_log1. by have /andP[] := up_log_bounds p_gt1 (isT: 1 < n.+2). Qed. Lemma up_log_gtn p n : 1 < p -> 1 < n -> p ^ (up_log p n).-1 < n. Proof. by case: n => [|[|n]] p_gt1 n_gt1 //; have /andP[] := up_log_bounds p_gt1 n_gt1. Qed. Lemma up_log_min p k j : 1 < p -> k <= p ^ j -> up_log p k <= j. Proof. case: k => [|[|k]] // p_gt1 kLj; rewrite ?(up_log0, up_log1) //. rewrite -[up_log _ _]prednK ?up_log_gt0 ?p_gt1 // -(@ltn_exp2l p) //. by apply: leq_trans (up_log_gtn p_gt1 (isT : 1 < k.+2)) _. Qed. Lemma leq_up_log p m n : m <= n -> up_log p m <= up_log p n. Proof. move=> mLn; case: p => [|[|p]] //. by apply/up_log_min => //; apply: leq_trans mLn (up_logP _ _). Qed. Lemma up_log_eq p n k : 1 < p -> p ^ n < k <= p ^ n.+1 -> up_log p k = n.+1. Proof. move=> p_gt1 /andP[npLk kLpn]; apply/eqP; rewrite eqn_leq. apply/andP; split; first by apply: up_log_min. rewrite -(ltn_exp2l _ _ p_gt1) //. by apply: leq_trans npLk (up_logP _ _). Qed. Lemma up_lognn p : 1 < p -> up_log p p = 1. Proof. by move=> p_gt1; apply: up_log_eq; rewrite p_gt1 /=. Qed. Lemma up_expnK p n : 1 < p -> up_log p (p ^ n) = n. Proof. case: n => [|n] p_gt1 /=; first by rewrite up_log1. by apply: up_log_eq; rewrite // leqnn andbT ltn_exp2l. Qed. Lemma up_logMp p n : 1 < p -> 0 < n -> up_log p (p * n) = (up_log p n).+1. Proof. case: p => [//|p] p_gt0. case: n => [//|[|n]] _; first by rewrite muln1 up_lognn// up_log1. apply: up_log_eq => //. rewrite expnS leq_pmul2l// up_logP// andbT. rewrite -[up_log _ _]prednK ?up_log_gt0 ?p_gt0 //. by rewrite expnS ltn_pmul2l// up_log_gtn. Qed. Lemma up_log2_double n : 0 < n -> up_log 2 n.*2 = (up_log 2 n).+1. Proof. by move=> n_gt0; rewrite -mul2n up_logMp. Qed. Lemma up_log2S n : 0 < n -> up_log 2 n.+1 = (up_log 2 (n./2.+1)).+1. Proof. case: n=> // [] [|n] // _. apply: up_log_eq => //; apply/andP; split. apply: leq_trans (_ : n./2.+1.*2 < n.+3); last first. by rewrite doubleS !ltnS -[leqRHS]odd_double_half leq_addl. have /= /andP[H1n _] := up_log_bounds (isT : 1 < 2) (isT : 1 < n./2.+2). by rewrite ltnS -leq_double -mul2n -expnS prednK ?up_log_gt0 // in H1n. rewrite -[_./2.+1]/(n./2.+2). have /= /andP[_ H2n] := up_log_bounds (isT : 1 < 2) (isT : 1 < n./2.+2). rewrite -leq_double -!mul2n -expnS in H2n. apply: leq_trans H2n. rewrite mul2n !doubleS !ltnS. by rewrite -[leqLHS]odd_double_half -add1n leq_add2r; case: odd. Qed. Lemma up_log_trunc_log p n : 1 < p -> 1 < n -> up_log p n = (trunc_log p n.-1).+1. Proof. move=> p_gt1 n_gt1; apply: up_log_eq => //. rewrite -[n]prednK ?ltnS -?pred_Sn ?[0 < n]ltnW//. by rewrite trunc_logP ?ltn_predRL// trunc_log_ltn. Qed. Lemma trunc_log_up_log p n : 1 < p -> 0 < n -> trunc_log p n = (up_log p n.+1).-1. Proof. by move=> ? ?; rewrite up_log_trunc_log. Qed. (* pi- parts *) (* Testing for membership in set of prime factors. *) Canonical nat_pred_pred := Eval hnf in [predType of nat_pred]. Coercion nat_pred_of_nat (p : nat) : nat_pred := pred1 p. Section NatPreds. Variables (n : nat) (pi : nat_pred). Definition negn : nat_pred := [predC pi]. Definition pnat : pred nat := fun m => (m > 0) && all [in pi] (primes m). Definition partn := \prod_(0 <= p < n.+1 | p \in pi) p ^ logn p n. End NatPreds. Notation "pi ^'" := (negn pi) : nat_scope. Notation "pi .-nat" := (pnat pi) : nat_scope. Notation "n `_ pi" := (partn n pi) : nat_scope. Section PnatTheory. Implicit Types (n p : nat) (pi rho : nat_pred). Lemma negnK pi : pi^'^' =i pi. Proof. by move=> p; apply: negbK. Qed. Lemma eq_negn pi1 pi2 : pi1 =i pi2 -> pi1^' =i pi2^'. Proof. by move=> eq_pi n; rewrite inE eq_pi. Qed. Lemma eq_piP m n : \pi(m) =i \pi(n) <-> \pi(m) = \pi(n). Proof. rewrite /pi_of; have eqs := irr_sorted_eq ltn_trans ltnn. by split=> [|-> //] /(eqs _ _ (sorted_primes m) (sorted_primes n)) ->. Qed. Lemma part_gt0 pi n : 0 < n`_pi. Proof. exact: prodn_gt0. Qed. Hint Resolve part_gt0 : core. Lemma sub_in_partn pi1 pi2 n : {in \pi(n), {subset pi1 <= pi2}} -> n`_pi1 %| n`_pi2. Proof. move=> pi12; rewrite ![n`__]big_mkcond /=. apply (big_ind2 (fun m1 m2 => m1 %| m2)) => // [*|p _]; first exact: dvdn_mul. rewrite lognE -mem_primes; case: ifP => pi1p; last exact: dvd1n. by case: ifP => pr_p; [rewrite pi12 | rewrite if_same]. Qed. Lemma eq_in_partn pi1 pi2 n : {in \pi(n), pi1 =i pi2} -> n`_pi1 = n`_pi2. Proof. by move=> pi12; apply/eqP; rewrite eqn_dvd ?sub_in_partn // => p /pi12->. Qed. Lemma eq_partn pi1 pi2 n : pi1 =i pi2 -> n`_pi1 = n`_pi2. Proof. by move=> pi12; apply: eq_in_partn => p _. Qed. Lemma partnNK pi n : n`_pi^'^' = n`_pi. Proof. by apply: eq_partn; apply: negnK. Qed. Lemma widen_partn m pi n : n <= m -> n`_pi = \prod_(0 <= p < m.+1 | p \in pi) p ^ logn p n. Proof. move=> le_n_m; rewrite big_mkcond /=. rewrite [n`_pi](big_nat_widen _ _ m.+1) // big_mkcond /=. apply: eq_bigr => p _; rewrite ltnS lognE. by case: and3P => [[_ n_gt0 p_dv_n]|]; rewrite ?if_same // andbC dvdn_leq. Qed. Lemma eq_partn_from_log m n (pi : nat_pred) : 0 < m -> 0 < n -> {in pi, logn^~ m =1 logn^~ n} -> m`_pi = n`_pi. Proof. move=> m0 n0 eq_log; rewrite !(@widen_partn (maxn m n)) ?leq_maxl ?leq_maxr//. by apply: eq_bigr => p /eq_log ->. Qed. Lemma partn0 pi : 0`_pi = 1. Proof. by apply: big1_seq => [] [|n]; rewrite andbC. Qed. Lemma partn1 pi : 1`_pi = 1. Proof. by apply: big1_seq => [] [|[|n]]; rewrite andbC. Qed. Lemma partnM pi m n : m > 0 -> n > 0 -> (m * n)`_pi = m`_pi * n`_pi. Proof. have le_pmul m' n': m' > 0 -> n' <= m' * n' by move/prednK <-; apply: leq_addr. move=> mpos npos; rewrite !(@widen_partn (n * m)) 3?(le_pmul, mulnC) //. rewrite !big_mkord -big_split; apply: eq_bigr => p _ /=. by rewrite lognM // expnD. Qed. Lemma partnX pi m n : (m ^ n)`_pi = m`_pi ^ n. Proof. elim: n => [|n IHn]; first exact: partn1. rewrite expnS; have [->|m_gt0] := posnP m; first by rewrite partn0 exp1n. by rewrite expnS partnM ?IHn // expn_gt0 m_gt0. Qed. Lemma partn_dvd pi m n : n > 0 -> m %| n -> m`_pi %| n`_pi. Proof. move=> n_gt0 dvmn; case/dvdnP: dvmn n_gt0 => q ->{n}. by rewrite muln_gt0 => /andP[q_gt0 m_gt0]; rewrite partnM ?dvdn_mull. Qed. Lemma p_part p n : n`_p = p ^ logn p n. Proof. case (posnP (logn p n)) => [log0 |]. by rewrite log0 [n`_p]big1_seq // => q /andP [/eqP ->]; rewrite log0. rewrite logn_gt0 mem_primes; case/and3P=> _ n_gt0 dv_p_n. have le_p_n: p < n.+1 by rewrite ltnS dvdn_leq. by rewrite [n`_p]big_mkord (big_pred1 (Ordinal le_p_n)). Qed. Lemma p_part_eq1 p n : (n`_p == 1) = (p \notin \pi(n)). Proof. rewrite mem_primes p_part lognE; case: and3P => // [[p_pr _ _]]. by rewrite -dvdn1 pfactor_dvdn // logn1. Qed. Lemma p_part_gt1 p n : (n`_p > 1) = (p \in \pi(n)). Proof. by rewrite ltn_neqAle part_gt0 andbT eq_sym p_part_eq1 negbK. Qed. Lemma primes_part pi n : primes n`_pi = filter [in pi] (primes n). Proof. have ltnT := ltn_trans; have [->|n_gt0] := posnP n; first by rewrite partn0. apply: (irr_sorted_eq ltnT ltnn); rewrite ?(sorted_primes, sorted_filter) //. move=> p; rewrite mem_filter /= !mem_primes n_gt0 part_gt0 /=. apply/andP/and3P=> [[p_pr] | [pi_p p_pr dv_p_n]]. rewrite /partn; apply big_ind => [|n1 n2 IHn1 IHn2|q pi_q]. - by rewrite dvdn1; case: eqP p_pr => // ->. - by rewrite Euclid_dvdM //; case/orP. rewrite -{1}(expn1 p) pfactor_dvdn // lognX muln_gt0. rewrite logn_gt0 mem_primes n_gt0 - andbA /=; case/and3P=> pr_q dv_q_n. by rewrite logn_prime //; case: eqP => // ->. have le_p_n: p < n.+1 by rewrite ltnS dvdn_leq. rewrite [n`_pi]big_mkord (bigD1 (Ordinal le_p_n)) //= dvdn_mulr //. by rewrite lognE p_pr n_gt0 dv_p_n expnS dvdn_mulr. Qed. Lemma filter_pi_of n m : n < m -> filter \pi(n) (index_iota 0 m) = primes n. Proof. move=> lt_n_m; have ltnT := ltn_trans; apply: (irr_sorted_eq ltnT ltnn). - by rewrite sorted_filter // iota_ltn_sorted. - exact: sorted_primes. move=> p; rewrite mem_filter mem_index_iota /= mem_primes; case: and3P => //. by case=> _ n_gt0 dv_p_n; apply: leq_ltn_trans lt_n_m; apply: dvdn_leq. Qed. Lemma partn_pi n : n > 0 -> n`_\pi(n) = n. Proof. move=> n_gt0; rewrite [RHS]prod_prime_decomp // prime_decompE big_map. by rewrite -[n`__]big_filter filter_pi_of. Qed. Lemma partnT n : n > 0 -> n`_predT = n. Proof. move=> n_gt0; rewrite -[RHS]partn_pi // [RHS]/partn big_mkcond /=. by apply: eq_bigr => p _; rewrite -logn_gt0; case: (logn p _). Qed. Lemma eqn_from_log m n : 0 < m -> 0 < n -> logn^~ m =1 logn^~ n -> m = n. Proof. by move=> ? ? /(@in1W _ predT)/eq_partn_from_log; rewrite !partnT// => ->. Qed. Lemma partnC pi n : n > 0 -> n`_pi * n`_pi^' = n. Proof. move=> n_gt0; rewrite -[RHS]partnT /partn //. do 2!rewrite mulnC big_mkcond /=; rewrite -big_split; apply: eq_bigr => p _ /=. by rewrite mulnC inE /=; case: (p \in pi); rewrite /= (muln1, mul1n). Qed. Lemma dvdn_part pi n : n`_pi %| n. Proof. by case: n => // n; rewrite -{2}[n.+1](@partnC pi) // dvdn_mulr. Qed. Lemma logn_part p m : logn p m`_p = logn p m. Proof. case p_pr: (prime p); first by rewrite p_part pfactorK. by rewrite lognE (lognE p m) p_pr. Qed. Lemma partn_lcm pi m n : m > 0 -> n > 0 -> (lcmn m n)`_pi = lcmn m`_pi n`_pi. Proof. move=> m_gt0 n_gt0; have p_gt0: lcmn m n > 0 by rewrite lcmn_gt0 m_gt0. apply/eqP; rewrite eqn_dvd dvdn_lcm !partn_dvd ?dvdn_lcml ?dvdn_lcmr //. rewrite -(dvdn_pmul2r (part_gt0 pi^' (lcmn m n))) partnC // dvdn_lcm !andbT. rewrite -[m in m %| _](partnC pi m_gt0) andbC -[n in n %| _](partnC pi n_gt0). by rewrite !dvdn_mul ?partn_dvd ?dvdn_lcml ?dvdn_lcmr. Qed. Lemma partn_gcd pi m n : m > 0 -> n > 0 -> (gcdn m n)`_pi = gcdn m`_pi n`_pi. Proof. move=> m_gt0 n_gt0; have p_gt0: gcdn m n > 0 by rewrite gcdn_gt0 m_gt0. apply/eqP; rewrite eqn_dvd dvdn_gcd !partn_dvd ?dvdn_gcdl ?dvdn_gcdr //=. rewrite -(dvdn_pmul2r (part_gt0 pi^' (gcdn m n))) partnC // dvdn_gcd. rewrite -[m in _ %| m](partnC pi m_gt0) andbC -[n in _%| n](partnC pi n_gt0). by rewrite !dvdn_mul ?partn_dvd ?dvdn_gcdl ?dvdn_gcdr. Qed. Lemma partn_biglcm (I : finType) (P : pred I) F pi : (forall i, P i -> F i > 0) -> (\big[lcmn/1%N]_(i | P i) F i)`_pi = \big[lcmn/1%N]_(i | P i) (F i)`_pi. Proof. move=> F_gt0; set m := \big[lcmn/1%N]_(i | P i) F i. have m_gt0: 0 < m by elim/big_ind: m => // p q p_gt0; rewrite lcmn_gt0 p_gt0. apply/eqP; rewrite eqn_dvd andbC; apply/andP; split. by apply/dvdn_biglcmP=> i Pi; rewrite partn_dvd // (@biglcmn_sup _ i). rewrite -(dvdn_pmul2r (part_gt0 pi^' m)) partnC //. apply/dvdn_biglcmP=> i Pi; rewrite -(partnC pi (F_gt0 i Pi)) dvdn_mul //. by rewrite (@biglcmn_sup _ i). by rewrite partn_dvd // (@biglcmn_sup _ i). Qed. Lemma partn_biggcd (I : finType) (P : pred I) F pi : #|SimplPred P| > 0 -> (forall i, P i -> F i > 0) -> (\big[gcdn/0]_(i | P i) F i)`_pi = \big[gcdn/0]_(i | P i) (F i)`_pi. Proof. move=> ntP F_gt0; set d := \big[gcdn/0]_(i | P i) F i. have d_gt0: 0 < d. case/card_gt0P: ntP => i /= Pi; have:= F_gt0 i Pi. rewrite !lt0n -!dvd0n; apply: contra => dv0d. by rewrite (dvdn_trans dv0d) // (@biggcdn_inf _ i). apply/eqP; rewrite eqn_dvd; apply/andP; split. by apply/dvdn_biggcdP=> i Pi; rewrite partn_dvd ?F_gt0 // (@biggcdn_inf _ i). rewrite -(dvdn_pmul2r (part_gt0 pi^' d)) partnC //. apply/dvdn_biggcdP=> i Pi; rewrite -(partnC pi (F_gt0 i Pi)) dvdn_mul //. by rewrite (@biggcdn_inf _ i). by rewrite partn_dvd ?F_gt0 // (@biggcdn_inf _ i). Qed. Lemma logn_gcd p m n : 0 < m -> 0 < n -> logn p (gcdn m n) = minn (logn p m) (logn p n). Proof. move=> m_gt0 n_gt0; case p_pr: (prime p); last by rewrite /logn p_pr. by apply: (@expnI p); rewrite ?prime_gt1// expn_min -!p_part partn_gcd. Qed. Lemma logn_lcm p m n : 0 < m -> 0 < n -> logn p (lcmn m n) = maxn (logn p m) (logn p n). Proof. move=> m_gt0 n_gt0; rewrite /lcmn logn_div ?dvdn_mull ?dvdn_gcdr//. by rewrite lognM// logn_gcd// -addn_min_max addnC addnK. Qed. Lemma sub_in_pnat pi rho n : {in \pi(n), {subset pi <= rho}} -> pi.-nat n -> rho.-nat n. Proof. rewrite /pnat => subpi /andP[-> pi_n]. by apply/allP=> p pr_p; apply: subpi => //; apply: (allP pi_n). Qed. Lemma eq_in_pnat pi rho n : {in \pi(n), pi =i rho} -> pi.-nat n = rho.-nat n. Proof. by move=> eqpi; apply/idP/idP; apply: sub_in_pnat => p /eqpi->. Qed. Lemma eq_pnat pi rho n : pi =i rho -> pi.-nat n = rho.-nat n. Proof. by move=> eqpi; apply: eq_in_pnat => p _. Qed. Lemma pnatNK pi n : pi^'^'.-nat n = pi.-nat n. Proof. exact: eq_pnat (negnK pi). Qed. Lemma pnatI pi rho n : [predI pi & rho].-nat n = pi.-nat n && rho.-nat n. Proof. by rewrite /pnat andbCA all_predI !andbA andbb. Qed. Lemma pnatM pi m n : pi.-nat (m * n) = pi.-nat m && pi.-nat n. Proof. rewrite /pnat muln_gt0 andbCA -andbA andbCA. case: posnP => // n_gt0; case: posnP => //= m_gt0. apply/allP/andP=> [pi_mn | [pi_m pi_n] p]. by split; apply/allP=> p m_p; apply: pi_mn; rewrite primesM // m_p ?orbT. by rewrite primesM // => /orP[]; [apply: (allP pi_m) | apply: (allP pi_n)]. Qed. Lemma pnatX pi m n : pi.-nat (m ^ n) = pi.-nat m || (n == 0). Proof. by case: n => [|n]; rewrite orbC // /pnat expn_gt0 orbC primesX. Qed. Lemma part_pnat pi n : pi.-nat n`_pi. Proof. rewrite /pnat primes_part part_gt0. by apply/allP=> p; rewrite mem_filter => /andP[]. Qed. Lemma pnatE pi p : prime p -> pi.-nat p = (p \in pi). Proof. by move=> pr_p; rewrite /pnat prime_gt0 ?primes_prime //= andbT. Qed. Lemma pnat_id p : prime p -> p.-nat p. Proof. by move=> pr_p; rewrite pnatE ?inE /=. Qed. Lemma coprime_pi' m n : m > 0 -> n > 0 -> coprime m n = \pi(m)^'.-nat n. Proof. by move=> m_gt0 n_gt0; rewrite /pnat n_gt0 all_predC coprime_has_primes. Qed. Lemma pnat_pi n : n > 0 -> \pi(n).-nat n. Proof. by rewrite /pnat => ->; apply/allP. Qed. Lemma pi_of_dvd m n : m %| n -> n > 0 -> {subset \pi(m) <= \pi(n)}. Proof. move=> m_dv_n n_gt0 p; rewrite !mem_primes n_gt0 => /and3P[-> _ p_dv_m]. exact: dvdn_trans p_dv_m m_dv_n. Qed. Lemma pi_ofM m n : m > 0 -> n > 0 -> \pi(m * n) =i [predU \pi(m) & \pi(n)]. Proof. by move=> m_gt0 n_gt0 p; apply: primesM. Qed. Lemma pi_of_part pi n : n > 0 -> \pi(n`_pi) =i [predI \pi(n) & pi]. Proof. by move=> n_gt0 p; rewrite /pi_of primes_part mem_filter andbC. Qed. Lemma pi_of_exp p n : n > 0 -> \pi(p ^ n) = \pi(p). Proof. by move=> n_gt0; rewrite /pi_of primesX. Qed. Lemma pi_of_prime p : prime p -> \pi(p) =i (p : nat_pred). Proof. by move=> pr_p q; rewrite /pi_of primes_prime // mem_seq1. Qed. Lemma p'natEpi p n : n > 0 -> p^'.-nat n = (p \notin \pi(n)). Proof. by case: n => // n _; rewrite /pnat all_predC has_pred1. Qed. Lemma p'natE p n : prime p -> p^'.-nat n = ~~ (p %| n). Proof. case: n => [|n] p_pr; first by case: p p_pr. by rewrite p'natEpi // mem_primes p_pr. Qed. Lemma pnatPpi pi n p : pi.-nat n -> p \in \pi(n) -> p \in pi. Proof. by case/andP=> _ /allP; apply. Qed. Lemma pnat_dvd m n pi : m %| n -> pi.-nat n -> pi.-nat m. Proof. by case/dvdnP=> q ->; rewrite pnatM; case/andP. Qed. Lemma pnat_div m n pi : m %| n -> pi.-nat n -> pi.-nat (n %/ m). Proof. case/dvdnP=> q ->; rewrite pnatM andbC => /andP[]. by case: m => // m _; rewrite mulnK. Qed. Lemma pnat_coprime pi m n : pi.-nat m -> pi^'.-nat n -> coprime m n. Proof. case/andP=> m_gt0 pi_m /andP[n_gt0 pi'_n]; rewrite coprime_has_primes //. by apply/hasPn=> p /(allP pi'_n); apply/contra/allP. Qed. Lemma p'nat_coprime pi m n : pi^'.-nat m -> pi.-nat n -> coprime m n. Proof. by move=> pi'm pi_n; rewrite (pnat_coprime pi'm) ?pnatNK. Qed. Lemma sub_pnat_coprime pi rho m n : {subset rho <= pi^'} -> pi.-nat m -> rho.-nat n -> coprime m n. Proof. by move=> pi'rho pi_m /(sub_in_pnat (in1W pi'rho)); apply: pnat_coprime. Qed. Lemma coprime_partC pi m n : coprime m`_pi n`_pi^'. Proof. by apply: (@pnat_coprime pi); apply: part_pnat. Qed. Lemma pnat_1 pi n : pi.-nat n -> pi^'.-nat n -> n = 1. Proof. by move=> pi_n pi'_n; rewrite -(eqnP (pnat_coprime pi_n pi'_n)) gcdnn. Qed. Lemma part_pnat_id pi n : pi.-nat n -> n`_pi = n. Proof. case/andP=> n_gt0 pi_n; rewrite -[RHS]partnT // /partn big_mkcond /=. apply: eq_bigr=> p _; have [->|] := posnP (logn p n); first by rewrite if_same. by rewrite logn_gt0 => /(allP pi_n)/= ->. Qed. Lemma part_p'nat pi n : pi^'.-nat n -> n`_pi = 1. Proof. case/andP=> n_gt0 pi'_n; apply: big1_seq => p /andP[pi_p _]. by have [-> //|] := posnP (logn p n); rewrite logn_gt0; case/(allP pi'_n)/negP. Qed. Lemma partn_eq1 pi n : n > 0 -> (n`_pi == 1) = pi^'.-nat n. Proof. move=> n_gt0; apply/eqP/idP=> [pi_n_1|]; last exact: part_p'nat. by rewrite -(partnC pi n_gt0) pi_n_1 mul1n part_pnat. Qed. Lemma pnatP pi n : n > 0 -> reflect (forall p, prime p -> p %| n -> p \in pi) (pi.-nat n). Proof. move=> n_gt0; rewrite /pnat n_gt0. apply: (iffP allP) => /= pi_n p => [pr_p p_n|]. by rewrite pi_n // mem_primes pr_p n_gt0. by rewrite mem_primes n_gt0 /=; case/andP; move: p. Qed. Lemma pi_pnat pi p n : p.-nat n -> p \in pi -> pi.-nat n. Proof. move=> p_n pi_p; have [n_gt0 _] := andP p_n. by apply/pnatP=> // q q_pr /(pnatP _ n_gt0 p_n _ q_pr)/eqnP->. Qed. Lemma p_natP p n : p.-nat n -> {k | n = p ^ k}. Proof. by move=> p_n; exists (logn p n); rewrite -p_part part_pnat_id. Qed. Lemma pi'_p'nat pi p n : pi^'.-nat n -> p \in pi -> p^'.-nat n. Proof. by move=> pi'n pi_p; apply: sub_in_pnat pi'n => q _; apply: contraNneq => ->. Qed. Lemma pi_p'nat p pi n : pi.-nat n -> p \in pi^' -> p^'.-nat n. Proof. by move=> pi_n; apply: pi'_p'nat; rewrite pnatNK. Qed. Lemma partn_part pi rho n : {subset pi <= rho} -> n`_rho`_pi = n`_pi. Proof. move=> pi_sub_rho; have [->|n_gt0] := posnP n; first by rewrite !partn0 partn1. rewrite -[in RHS](partnC rho n_gt0) partnM //. suffices: pi^'.-nat n`_rho^' by move/part_p'nat->; rewrite muln1. by apply: sub_in_pnat (part_pnat _ _) => q _; apply/contra/pi_sub_rho. Qed. Lemma partnI pi rho n : n`_[predI pi & rho] = n`_pi`_rho. Proof. rewrite -(@partnC [predI pi & rho] _`_rho) //. symmetry; rewrite 2?partn_part; try by move=> p /andP []. rewrite mulnC part_p'nat ?mul1n // pnatNK pnatI part_pnat andbT. exact: pnat_dvd (dvdn_part _ _) (part_pnat _ _). Qed. Lemma odd_2'nat n : odd n = 2^'.-nat n. Proof. by case: n => // n; rewrite p'natE // dvdn2 negbK. Qed. End PnatTheory. #[global] Hint Resolve part_gt0 : core. (************************************) (* Properties of the divisors list. *) (************************************) Lemma divisors_correct n : n > 0 -> [/\ uniq (divisors n), sorted leq (divisors n) & forall d, (d \in divisors n) = (d %| n)]. Proof. move/prod_prime_decomp=> def_n; rewrite {4}def_n {def_n}. have: all prime (primes n) by apply/allP=> p; rewrite mem_primes; case/andP. have:= primes_uniq n; rewrite /primes /divisors; move/prime_decomp: n. elim=> [|[p e] pd] /=; first by split=> // d; rewrite big_nil dvdn1 mem_seq1. rewrite big_cons /=; move: (foldr _ _ pd) => divs. move=> IHpd /andP[npd_p Upd] /andP[pr_p pr_pd]. have lt0p: 0 < p by apply: prime_gt0. have {IHpd Upd}[Udivs Odivs mem_divs] := IHpd Upd pr_pd. have ndivs_p m: p * m \notin divs. suffices: p \notin divs; rewrite !mem_divs. by apply: contra => /dvdnP[n ->]; rewrite mulnCA dvdn_mulr. have ndv_p_1: ~~(p %| 1) by rewrite dvdn1 neq_ltn orbC prime_gt1. rewrite big_seq; elim/big_ind: _ => [//|u v npu npv|[q f] /= pd_qf]. by rewrite Euclid_dvdM //; apply/norP. elim: (f) => // f'; rewrite expnS Euclid_dvdM // orbC negb_or => -> {f'}/=. have pd_q: q \in unzip1 pd by apply/mapP; exists (q, f). by apply: contra npd_p; rewrite dvdn_prime2 // ?(allP pr_pd) // => /eqP->. elim: e => [|e] /=; first by split=> // d; rewrite mul1n. have Tmulp_inj: injective (NatTrec.mul p). by move=> u v /eqP; rewrite !natTrecE eqn_pmul2l // => /eqP. move: (iter e _ _) => divs' [Udivs' Odivs' mem_divs']; split=> [||d]. - rewrite merge_uniq cat_uniq map_inj_uniq // Udivs Udivs' andbT /=. apply/hasP=> [[d dv_d /mapP[d' _ def_d]]]. by case/idPn: dv_d; rewrite def_d natTrecE. - rewrite (merge_sorted leq_total) //; case: (divs') Odivs' => //= d ds. rewrite (@map_path _ _ _ _ leq xpred0) ?has_pred0 // => u v _. by rewrite !natTrecE leq_pmul2l. rewrite mem_merge mem_cat; case dv_d_p: (p %| d). case/dvdnP: dv_d_p => d' ->{d}; rewrite mulnC (negbTE (ndivs_p d')) orbF. rewrite expnS -mulnA dvdn_pmul2l // -mem_divs'. by rewrite -(mem_map Tmulp_inj divs') natTrecE. case pdiv_d: (_ \in _). by case/mapP: pdiv_d dv_d_p => d' _ ->; rewrite natTrecE dvdn_mulr. rewrite mem_divs Gauss_dvdr // coprime_sym. by rewrite coprimeXl ?prime_coprime ?dv_d_p. Qed. Lemma sorted_divisors n : sorted leq (divisors n). Proof. by case: (posnP n) => [-> | /divisors_correct[]]. Qed. Lemma divisors_uniq n : uniq (divisors n). Proof. by case: (posnP n) => [-> | /divisors_correct[]]. Qed. Lemma sorted_divisors_ltn n : sorted ltn (divisors n). Proof. by rewrite ltn_sorted_uniq_leq divisors_uniq sorted_divisors. Qed. Lemma dvdn_divisors d m : 0 < m -> (d %| m) = (d \in divisors m). Proof. by case/divisors_correct. Qed. Lemma divisor1 n : 1 \in divisors n. Proof. by case: n => // n; rewrite -dvdn_divisors // dvd1n. Qed. Lemma divisors_id n : 0 < n -> n \in divisors n. Proof. by move/dvdn_divisors <-. Qed. (* Big sum / product lemmas*) Lemma dvdn_sum d I r (K : pred I) F : (forall i, K i -> d %| F i) -> d %| \sum_(i <- r | K i) F i. Proof. by move=> dF; elim/big_ind: _ => //; apply: dvdn_add. Qed. Lemma dvdn_partP n m : 0 < n -> reflect (forall p, p \in \pi(n) -> n`_p %| m) (n %| m). Proof. move=> n_gt0; apply: (iffP idP) => n_dvd_m => [p _|]. by apply: dvdn_trans n_dvd_m; apply: dvdn_part. have [-> // | m_gt0] := posnP m. rewrite -(partnT n_gt0) -(partnT m_gt0). rewrite !(@widen_partn (m + n)) ?leq_addl ?leq_addr // /in_mem /=. elim/big_ind2: _ => // [* | q _]; first exact: dvdn_mul. have [-> // | ] := posnP (logn q n); rewrite logn_gt0 => q_n. have pr_q: prime q by move: q_n; rewrite mem_primes; case/andP. by have:= n_dvd_m q q_n; rewrite p_part !pfactor_dvdn // pfactorK. Qed. Lemma modn_partP n a b : 0 < n -> reflect (forall p : nat, p \in \pi(n) -> a = b %[mod n`_p]) (a == b %[mod n]). Proof. move=> n_gt0; wlog le_b_a: a b / b <= a. move=> IH; case: (leqP b a) => [|/ltnW] /IH {IH}// IH. by rewrite eq_sym; apply: (iffP IH) => eqab p /eqab. rewrite eqn_mod_dvd //; apply: (iffP (dvdn_partP _ n_gt0)) => eqab p /eqab; by rewrite -eqn_mod_dvd // => /eqP. Qed. (* The Euler totient function *) Lemma totientE n : n > 0 -> totient n = \prod_(p <- primes n) (p.-1 * p ^ (logn p n).-1). Proof. move=> n_gt0; rewrite /totient n_gt0 prime_decompE unlock. by elim: (primes n) => //= [p pr ->]; rewrite !natTrecE. Qed. Lemma totient_gt0 n : (0 < totient n) = (0 < n). Proof. case: n => // n; rewrite totientE // big_seq_cond prodn_cond_gt0 // => p. by rewrite mem_primes muln_gt0 expn_gt0; case: p => [|[|]]. Qed. Lemma totient_pfactor p e : prime p -> e > 0 -> totient (p ^ e) = p.-1 * p ^ e.-1. Proof. move=> p_pr e_gt0; rewrite totientE ?expn_gt0 ?prime_gt0 //. by rewrite primesX // primes_prime // unlock /= muln1 pfactorK. Qed. Lemma totient_prime p : prime p -> totient p = p.-1. Proof. by move=> p_prime; rewrite -{1}[p]expn1 totient_pfactor // muln1. Qed. Lemma totient_coprime m n : coprime m n -> totient (m * n) = totient m * totient n. Proof. move=> co_mn; have [-> //| m_gt0] := posnP m. have [->|n_gt0] := posnP n; first by rewrite !muln0. rewrite !totientE ?muln_gt0 ?m_gt0 //. have /(perm_big _)->: perm_eq (primes (m * n)) (primes m ++ primes n). apply: uniq_perm => [||p]; first exact: primes_uniq. by rewrite cat_uniq !primes_uniq -coprime_has_primes // co_mn. by rewrite mem_cat primesM. rewrite big_cat /= !big_seq. congr (_ * _); apply: eq_bigr => p; rewrite mem_primes => /and3P[_ _ dvp]. rewrite (mulnC m) logn_Gauss //; move: co_mn. by rewrite -(divnK dvp) coprimeMl => /andP[]. rewrite logn_Gauss //; move: co_mn. by rewrite coprime_sym -(divnK dvp) coprimeMl => /andP[]. Qed. Lemma totient_count_coprime n : totient n = \sum_(0 <= d < n) coprime n d. Proof. elim/ltn_ind: n => // n IHn. case: (leqP n 1) => [|lt1n]; first by rewrite unlock; case: (n) => [|[]]. pose p := pdiv n; have p_pr: prime p by apply: pdiv_prime. have p1 := prime_gt1 p_pr; have p0 := ltnW p1. pose np := n`_p; pose np' := n`_p^'. have co_npp': coprime np np' by rewrite coprime_partC. have [n0 np0 np'0]: [/\ n > 0, np > 0 & np' > 0] by rewrite ltnW ?part_gt0. have def_n: n = np * np' by rewrite partnC. have lnp0: 0 < logn p n by rewrite lognE p_pr n0 pdiv_dvd. pose in_mod k (k0 : k > 0) d := Ordinal (ltn_pmod d k0). rewrite {1}def_n totient_coprime // {IHn}(IHn np') ?big_mkord; last first. by rewrite def_n ltn_Pmull // /np p_part -(expn0 p) ltn_exp2l. have ->: totient np = #|[pred d : 'I_np | coprime np d]|. rewrite [np in LHS]p_part totient_pfactor //=; set q := p ^ _. apply: (@addnI (1 * q)); rewrite -mulnDl [1 + _]prednK // mul1n. have def_np: np = p * q by rewrite -expnS prednK // -p_part. pose mulp := [fun d : 'I_q => in_mod _ np0 (p * d)]. rewrite -def_np -{1}[np]card_ord -(cardC [in codom mulp]). rewrite card_in_image => [|[d1 ltd1] [d2 ltd2] /= _ _ []]; last first. move/eqP; rewrite def_np -!muln_modr ?modn_small //. by rewrite eqn_pmul2l // => eq_op12; apply/eqP. rewrite card_ord; congr (q + _); apply: eq_card => d /=. rewrite !inE [np in coprime np _]p_part coprime_pexpl ?prime_coprime //. congr (~~ _); apply/codomP/idP=> [[d' -> /=] | /dvdnP[r def_d]]. by rewrite def_np -muln_modr // dvdn_mulr. do [rewrite mulnC; case: d => d ltd /=] in def_d *. have ltr: r < q by rewrite -(ltn_pmul2l p0) -def_np -def_d. by exists (Ordinal ltr); apply: val_inj; rewrite /= -def_d modn_small. pose h (d : 'I_n) := (in_mod _ np0 d, in_mod _ np'0 d). pose h' (d : 'I_np * 'I_np') := in_mod _ n0 (chinese np np' d.1 d.2). rewrite -!big_mkcond -sum_nat_const pair_big (reindex_onto h h') => [|[d d'] _]. apply: eq_bigl => [[d ltd] /=]; rewrite !inE -val_eqE /= andbC !coprime_modr. by rewrite def_n -chinese_mod // -coprimeMl -def_n modn_small ?eqxx. apply/eqP; rewrite /eq_op /= /eq_op /= !modn_dvdm ?dvdn_part //. by rewrite chinese_modl // chinese_modr // !modn_small ?eqxx ?ltn_ord. Qed. Lemma totient_gt1 n : (totient n > 1) = (n > 2). Proof. case: n => [|[|[|[|n']]]]//=; set n := n'.+4; rewrite [RHS]isT. wlog [q] : / exists k, k.+3 \in primes n; last first. rewrite mem_primes => /and3P[qp ngt0 qn]. have [[|k]// cqk ->] := pfactor_coprime qp ngt0. rewrite totient_coprime 1?coprime_sym ?coprimeXl//. rewrite totient_pfactor// -?pfactor_dvdn// mulnCA/= (@leq_trans q.+2)//. by rewrite leq_pmulr// muln_gt0 totient_gt0 expn_gt0. have := @prod_prime_decomp n isT; rewrite prime_decompE big_map/=. case: (primes n) (all_prime_primes n) (sorted_primes n) => [|[|[|p']]// [|[|[|[|q']]] r]]//=; first by rewrite big_nil. case: p' => [_ _|p' _ _ _]; last by apply; exists p'; rewrite ?mem_head. rewrite big_seq1; case: logn => [|[|k]]//= ->. by rewrite totient_pfactor//= mul1n (@leq_pexp2l 2 1)//. by move=> _ _ _; apply; exists q'=> //; rewrite !in_cons eqxx orbT. Qed.
Integral.lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.LocalProperties.Basic import Mathlib.RingTheory.Localization.Integral /-! # The meta properties of integral ring homomorphisms. -/ namespace RingHom open scoped TensorProduct open TensorProduct Algebra.TensorProduct theorem isIntegral_stableUnderComposition : StableUnderComposition fun f => f.IsIntegral := by introv R hf hg; exact hf.trans _ _ hg theorem isIntegral_respectsIso : RespectsIso fun f => f.IsIntegral := by apply isIntegral_stableUnderComposition.respectsIso introv x rw [← e.apply_symm_apply x] apply RingHom.isIntegralElem_map theorem isIntegral_isStableUnderBaseChange : IsStableUnderBaseChange fun f => f.IsIntegral := by refine IsStableUnderBaseChange.mk isIntegral_respectsIso ?_ introv h x refine TensorProduct.induction_on x ?_ ?_ ?_ · apply isIntegral_zero · intro x y; exact IsIntegral.tmul x (h y) · intro x y hx hy; exact IsIntegral.add hx hy open Polynomial in /-- `S` is an integral `R`-algebra if there exists a set `{ r }` that spans `R` such that each `Sᵣ` is an integral `Rᵣ`-algebra. -/ theorem isIntegral_ofLocalizationSpan : OfLocalizationSpan (RingHom.IsIntegral ·) := by introv R hs H r letI := f.toAlgebra change r ∈ (integralClosure R S).toSubmodule apply Submodule.mem_of_span_eq_top_of_smul_pow_mem _ s hs rintro ⟨t, ht⟩ letI := (Localization.awayMap f t).toAlgebra haveI : IsScalarTower R (Localization.Away t) (Localization.Away (f t)) := .of_algebraMap_eq' (IsLocalization.lift_comp _).symm have : _root_.IsIntegral (Localization.Away t) (algebraMap S (Localization.Away (f t)) r) := H ⟨t, ht⟩ (algebraMap _ _ r) obtain ⟨⟨_, n, rfl⟩, p, hp, hp'⟩ := this.exists_multiple_integral_of_isLocalization (.powers t) rw [IsScalarTower.algebraMap_eq R S, Submonoid.smul_def, Algebra.smul_def, IsScalarTower.algebraMap_apply R S, ← map_mul, ← hom_eval₂, IsLocalization.map_eq_zero_iff (.powers (f t))] at hp' obtain ⟨⟨x, m, (rfl : algebraMap R S t ^ m = x)⟩, e⟩ := hp' by_cases hp' : 1 ≤ p.natDegree; swap · obtain rfl : p = 1 := eq_one_of_monic_natDegree_zero hp (by omega) exact ⟨m, by simp [Algebra.smul_def, show algebraMap R S t ^ m = 0 by simpa using e]⟩ refine ⟨m + n, p.scaleRoots (t ^ m), (monic_scaleRoots_iff _).mpr hp, ?_⟩ have := p.scaleRoots_eval₂_mul (algebraMap R S) (t ^ n • r) (t ^ m) simp only [pow_add, ← Algebra.smul_def, mul_smul, ← map_pow] at e this ⊢ rw [this, ← tsub_add_cancel_of_le hp', pow_succ, mul_smul, e, smul_zero] end RingHom
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.
Sum.lean
/- Copyright (c) 2024 Martin Dvorak. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Martin Dvorak -/ import Mathlib.Algebra.Notation.Pi.Defs import Mathlib.Order.Basic /-! # Interaction between `Sum.elim`, `≤`, and `0` or `1` This file provides basic API for part-wise comparison of `Sum.elim` vectors against `0` or `1`. -/ namespace Sum variable {α₁ α₂ β : Type*} [LE β] [One β] {v₁ : α₁ → β} {v₂ : α₂ → β} @[to_additive] lemma one_le_elim_iff : 1 ≤ Sum.elim v₁ v₂ ↔ 1 ≤ v₁ ∧ 1 ≤ v₂ := const_le_elim_iff @[to_additive] lemma elim_le_one_iff : Sum.elim v₁ v₂ ≤ 1 ↔ v₁ ≤ 1 ∧ v₂ ≤ 1 := elim_le_const_iff end Sum
Truncated.lean
/- Copyright (c) 2025 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer -/ import Mathlib.AlgebraicTopology.SimplexCategory.Basic import Mathlib.CategoryTheory.Limits.Final /-! # Properties of the truncated simplex category We prove that for `n > 0`, the inclusion functor from the `n`-truncated simplex category to the untruncated simplex category, and the inclusion functor from the `n`-truncated to the `m`-truncated simplex category, for `n ≤ m` are initial. -/ open Simplicial CategoryTheory namespace SimplexCategory.Truncated /-- For `0 < n`, the inclusion functor from the `n`-truncated simplex category to the untruncated simplex category is initial. -/ instance initial_inclusion {n : ℕ} [NeZero n] : (inclusion n).Initial := by have := Nat.pos_of_neZero n constructor intro Δ have : Nonempty (CostructuredArrow (inclusion n) Δ) := ⟨⟨⦋0⦌ₙ, ⟨⟨⟩⟩, ⦋0⦌.const _ 0 ⟩⟩ apply zigzag_isConnected rintro ⟨⟨Δ₁, hΔ₁⟩, ⟨⟨⟩⟩, f⟩ ⟨⟨Δ₂, hΔ₂⟩, ⟨⟨⟩⟩, f'⟩ apply Zigzag.trans (j₂ := ⟨⦋0⦌ₙ, ⟨⟨⟩⟩, ⦋0⦌.const _ (f 0)⟩) (.of_inv <| CostructuredArrow.homMk <| Hom.tr <| ⦋0⦌.const _ 0) by_cases hff' : f 0 ≤ f' 0 · trans ⟨⦋1⦌ₙ, ⟨⟨⟩⟩, mkOfLe (n := Δ.len) (f 0) (f' 0) hff'⟩ · apply Zigzag.of_hom <| CostructuredArrow.homMk <| Hom.tr <| ⦋0⦌.const _ 0 · trans ⟨⦋0⦌ₙ, ⟨⟨⟩⟩, ⦋0⦌.const _ (f' 0)⟩ · apply Zigzag.of_inv <| CostructuredArrow.homMk <| Hom.tr <| ⦋0⦌.const _ 1 · apply Zigzag.of_hom <| CostructuredArrow.homMk <| Hom.tr <| ⦋0⦌.const _ 0 · trans ⟨⦋1⦌ₙ, ⟨⟨⟩⟩, mkOfLe (n := Δ.len) (f' 0) (f 0) (le_of_not_ge hff')⟩ · apply Zigzag.of_hom <| CostructuredArrow.homMk <| Hom.tr <| ⦋0⦌.const _ 1 · trans ⟨⦋0⦌ₙ, ⟨⟨⟩⟩, ⦋0⦌.const _ (f' 0)⟩ · apply Zigzag.of_inv <| CostructuredArrow.homMk <| Hom.tr <| ⦋0⦌.const _ 0 · apply Zigzag.of_hom <| CostructuredArrow.homMk <| Hom.tr <| ⦋0⦌.const _ 0 /-- For `0 < n ≤ m`, the inclusion functor from the `n`-truncated simplex category to the `m`-truncated simplex category is initial. -/ theorem initial_incl {n m : ℕ} [NeZero n] (hm : n ≤ m) : (incl n m).Initial := by have : (incl n m hm ⋙ inclusion m).Initial := Functor.initial_of_natIso (inclCompInclusion _).symm apply Functor.initial_of_comp_full_faithful _ (inclusion m) end SimplexCategory.Truncated
ConjTranspose.lean
/- Copyright (c) 2018 Ellen Arlt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin, Lu-Ming Zhang -/ import Mathlib.Algebra.BigOperators.GroupWithZero.Action import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.BigOperators.RingEquiv import Mathlib.Algebra.Module.Pi import Mathlib.Algebra.Star.BigOperators import Mathlib.Algebra.Star.Module import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Matrix.Basis import Mathlib.Data.Matrix.Mul /-! # Matrices over star rings. ## Notation The locale `Matrix` gives the following notation: * `ᴴ` for `Matrix.conjTranspose` -/ universe u u' v w variable {l m n o : Type*} {m' : o → Type*} {n' : o → Type*} variable {R : Type*} {S : Type*} {α : Type v} {β : Type w} {γ : Type*} namespace Matrix /-- The conjugate transpose of a matrix defined in term of `star`. -/ def conjTranspose [Star α] (M : Matrix m n α) : Matrix n m α := M.transpose.map star @[inherit_doc] scoped postfix:1024 "ᴴ" => Matrix.conjTranspose @[simp] lemma conjTranspose_single [DecidableEq n] [DecidableEq m] [AddMonoid α] [StarAddMonoid α] (i : m) (j : n) (a : α) : (single i j a)ᴴ = single j i (star a) := by change (single i j a).transpose.map starAddEquiv = single j i (star a) simp @[deprecated (since := "2025-05-05")] alias conjTranspose_stdBasisMatrix := conjTranspose_single section Diagonal variable [DecidableEq n] @[simp] theorem diagonal_conjTranspose [AddMonoid α] [StarAddMonoid α] (v : n → α) : (diagonal v)ᴴ = diagonal (star v) := by rw [conjTranspose, diagonal_transpose, diagonal_map (star_zero _)] rfl end Diagonal section Diag @[simp] theorem diag_conjTranspose [Star α] (A : Matrix n n α) : diag Aᴴ = star (diag A) := rfl end Diag section DotProduct variable [Fintype m] [Fintype n] section StarRing variable [NonUnitalSemiring α] [StarRing α] (v w : m → α) theorem star_dotProduct_star : star v ⬝ᵥ star w = star (w ⬝ᵥ v) := by simp [dotProduct] theorem star_dotProduct : star v ⬝ᵥ w = star (star w ⬝ᵥ v) := by simp [dotProduct] theorem dotProduct_star : v ⬝ᵥ star w = star (w ⬝ᵥ star v) := by simp [dotProduct] end StarRing end DotProduct section NonUnitalSemiring variable [NonUnitalSemiring α] theorem star_mulVec [Fintype n] [StarRing α] (M : Matrix m n α) (v : n → α) : star (M *ᵥ v) = star v ᵥ* Mᴴ := funext fun _ => (star_dotProduct_star _ _).symm theorem star_vecMul [Fintype m] [StarRing α] (M : Matrix m n α) (v : m → α) : star (v ᵥ* M) = Mᴴ *ᵥ star v := funext fun _ => (star_dotProduct_star _ _).symm theorem mulVec_conjTranspose [Fintype m] [StarRing α] (A : Matrix m n α) (x : m → α) : Aᴴ *ᵥ x = star (star x ᵥ* A) := funext fun _ => star_dotProduct _ _ theorem vecMul_conjTranspose [Fintype n] [StarRing α] (A : Matrix m n α) (x : n → α) : x ᵥ* Aᴴ = star (A *ᵥ star x) := funext fun _ => dotProduct_star _ _ end NonUnitalSemiring @[simp] theorem conjTranspose_vecMulVec [Mul α] [StarMul α] (w : m → α) (v : n → α) : (vecMulVec w v)ᴴ = vecMulVec (star v) (star w) := ext fun _ _ => star_mul _ _ section ConjTranspose open Matrix /-- Tell `simp` what the entries are in a conjugate transposed matrix. Compare with `mul_apply`, `diagonal_apply_eq`, etc. -/ @[simp] theorem conjTranspose_apply [Star α] (M : Matrix m n α) (i j) : M.conjTranspose j i = star (M i j) := rfl @[simp] theorem conjTranspose_conjTranspose [InvolutiveStar α] (M : Matrix m n α) : Mᴴᴴ = M := Matrix.ext <| by simp theorem conjTranspose_transpose [Star α] (M : Matrix m n α) : Mᴴᵀ = M.map star := rfl theorem transpose_conjTranspose [Star α] (M : Matrix m n α) : Mᵀᴴ = M.map star := rfl theorem conjTranspose_injective [InvolutiveStar α] : Function.Injective (conjTranspose : Matrix m n α → Matrix n m α) := (map_injective star_injective).comp transpose_injective @[simp] theorem conjTranspose_inj [InvolutiveStar α] {A B : Matrix m n α} : Aᴴ = Bᴴ ↔ A = B := conjTranspose_injective.eq_iff @[simp] theorem conjTranspose_eq_diagonal [DecidableEq n] [AddMonoid α] [StarAddMonoid α] {M : Matrix n n α} {v : n → α} : Mᴴ = diagonal v ↔ M = diagonal (star v) := (Function.Involutive.eq_iff conjTranspose_conjTranspose).trans <| by rw [diagonal_conjTranspose] @[simp] theorem conjTranspose_zero [AddMonoid α] [StarAddMonoid α] : (0 : Matrix m n α)ᴴ = 0 := Matrix.ext <| by simp @[simp] theorem conjTranspose_eq_zero [AddMonoid α] [StarAddMonoid α] {M : Matrix m n α} : Mᴴ = 0 ↔ M = 0 := by rw [← conjTranspose_inj (A := M), conjTranspose_zero] @[simp] theorem conjTranspose_one [DecidableEq n] [NonAssocSemiring α] [StarRing α] : (1 : Matrix n n α)ᴴ = 1 := by simp [conjTranspose] @[simp] theorem conjTranspose_eq_one [DecidableEq n] [NonAssocSemiring α] [StarRing α] {M : Matrix n n α} : Mᴴ = 1 ↔ M = 1 := (Function.Involutive.eq_iff conjTranspose_conjTranspose).trans <| by rw [conjTranspose_one] @[simp] theorem conjTranspose_natCast [DecidableEq n] [NonAssocSemiring α] [StarRing α] (d : ℕ) : (d : Matrix n n α)ᴴ = d := by simp [conjTranspose, Matrix.map_natCast, diagonal_natCast] @[simp] theorem conjTranspose_eq_natCast [DecidableEq n] [NonAssocSemiring α] [StarRing α] {M : Matrix n n α} {d : ℕ} : Mᴴ = d ↔ M = d := (Function.Involutive.eq_iff conjTranspose_conjTranspose).trans <| by rw [conjTranspose_natCast] @[simp] theorem conjTranspose_ofNat [DecidableEq n] [NonAssocSemiring α] [StarRing α] (d : ℕ) [d.AtLeastTwo] : (ofNat(d) : Matrix n n α)ᴴ = OfNat.ofNat d := conjTranspose_natCast _ @[simp] theorem conjTranspose_eq_ofNat [DecidableEq n] [Semiring α] [StarRing α] {M : Matrix n n α} {d : ℕ} [d.AtLeastTwo] : Mᴴ = ofNat(d) ↔ M = OfNat.ofNat d := conjTranspose_eq_natCast @[simp] theorem conjTranspose_intCast [DecidableEq n] [Ring α] [StarRing α] (d : ℤ) : (d : Matrix n n α)ᴴ = d := by simp [conjTranspose, Matrix.map_intCast, diagonal_intCast] @[simp] theorem conjTranspose_eq_intCast [DecidableEq n] [Ring α] [StarRing α] {M : Matrix n n α} {d : ℤ} : Mᴴ = d ↔ M = d := (Function.Involutive.eq_iff conjTranspose_conjTranspose).trans <| by rw [conjTranspose_intCast] @[simp] theorem conjTranspose_add [AddMonoid α] [StarAddMonoid α] (M N : Matrix m n α) : (M + N)ᴴ = Mᴴ + Nᴴ := Matrix.ext <| by simp @[simp] theorem conjTranspose_sub [AddGroup α] [StarAddMonoid α] (M N : Matrix m n α) : (M - N)ᴴ = Mᴴ - Nᴴ := Matrix.ext <| by simp /-- Note that `StarModule` is quite a strong requirement; as such we also provide the following variants which this lemma would not apply to: * `Matrix.conjTranspose_smul_non_comm` * `Matrix.conjTranspose_nsmul` * `Matrix.conjTranspose_zsmul` * `Matrix.conjTranspose_natCast_smul` * `Matrix.conjTranspose_intCast_smul` * `Matrix.conjTranspose_inv_natCast_smul` * `Matrix.conjTranspose_inv_intCast_smul` * `Matrix.conjTranspose_ratCast_smul` -/ @[simp] theorem conjTranspose_smul [Star R] [Star α] [SMul R α] [StarModule R α] (c : R) (M : Matrix m n α) : (c • M)ᴴ = star c • Mᴴ := Matrix.ext fun _ _ => star_smul _ _ @[simp] theorem conjTranspose_smul_non_comm [Star R] [Star α] [SMul R α] [SMul Rᵐᵒᵖ α] (c : R) (M : Matrix m n α) (h : ∀ (r : R) (a : α), star (r • a) = MulOpposite.op (star r) • star a) : (c • M)ᴴ = MulOpposite.op (star c) • Mᴴ := Matrix.ext <| by simp [h] theorem conjTranspose_smul_self [Mul α] [StarMul α] (c : α) (M : Matrix m n α) : (c • M)ᴴ = MulOpposite.op (star c) • Mᴴ := conjTranspose_smul_non_comm c M star_mul @[simp] theorem conjTranspose_nsmul [AddMonoid α] [StarAddMonoid α] (c : ℕ) (M : Matrix m n α) : (c • M)ᴴ = c • Mᴴ := Matrix.ext <| by simp @[simp] theorem conjTranspose_zsmul [AddGroup α] [StarAddMonoid α] (c : ℤ) (M : Matrix m n α) : (c • M)ᴴ = c • Mᴴ := Matrix.ext <| by simp @[simp] theorem conjTranspose_natCast_smul [Semiring R] [AddCommMonoid α] [StarAddMonoid α] [Module R α] (c : ℕ) (M : Matrix m n α) : ((c : R) • M)ᴴ = (c : R) • Mᴴ := Matrix.ext <| by simp @[simp] theorem conjTranspose_ofNat_smul [Semiring R] [AddCommMonoid α] [StarAddMonoid α] [Module R α] (c : ℕ) [c.AtLeastTwo] (M : Matrix m n α) : ((ofNat(c) : R) • M)ᴴ = (OfNat.ofNat c : R) • Mᴴ := conjTranspose_natCast_smul c M @[simp] theorem conjTranspose_intCast_smul [Ring R] [AddCommGroup α] [StarAddMonoid α] [Module R α] (c : ℤ) (M : Matrix m n α) : ((c : R) • M)ᴴ = (c : R) • Mᴴ := Matrix.ext <| by simp @[simp] theorem conjTranspose_inv_natCast_smul [DivisionSemiring R] [AddCommMonoid α] [StarAddMonoid α] [Module R α] (c : ℕ) (M : Matrix m n α) : ((c : R)⁻¹ • M)ᴴ = (c : R)⁻¹ • Mᴴ := Matrix.ext <| by simp @[simp] theorem conjTranspose_inv_ofNat_smul [DivisionSemiring R] [AddCommMonoid α] [StarAddMonoid α] [Module R α] (c : ℕ) [c.AtLeastTwo] (M : Matrix m n α) : ((ofNat(c) : R)⁻¹ • M)ᴴ = (OfNat.ofNat c : R)⁻¹ • Mᴴ := conjTranspose_inv_natCast_smul c M @[simp] theorem conjTranspose_inv_intCast_smul [DivisionRing R] [AddCommGroup α] [StarAddMonoid α] [Module R α] (c : ℤ) (M : Matrix m n α) : ((c : R)⁻¹ • M)ᴴ = (c : R)⁻¹ • Mᴴ := Matrix.ext <| by simp @[simp] theorem conjTranspose_ratCast_smul [DivisionRing R] [AddCommGroup α] [StarAddMonoid α] [Module R α] (c : ℚ) (M : Matrix m n α) : ((c : R) • M)ᴴ = (c : R) • Mᴴ := Matrix.ext <| by simp theorem conjTranspose_rat_smul [AddCommGroup α] [StarAddMonoid α] [Module ℚ α] (c : ℚ) (M : Matrix m n α) : (c • M)ᴴ = c • Mᴴ := Matrix.ext <| by simp @[simp] theorem conjTranspose_mul [Fintype n] [NonUnitalNonAssocSemiring α] [StarRing α] (M : Matrix m n α) (N : Matrix n l α) : (M * N)ᴴ = Nᴴ * Mᴴ := Matrix.ext <| by simp [mul_apply] @[simp] theorem conjTranspose_neg [AddGroup α] [StarAddMonoid α] (M : Matrix m n α) : (-M)ᴴ = -Mᴴ := Matrix.ext <| by simp theorem conjTranspose_map [Star α] [Star β] {A : Matrix m n α} (f : α → β) (hf : Function.Semiconj f star star) : Aᴴ.map f = (A.map f)ᴴ := Matrix.ext fun _ _ => hf _ /-- When `star x = x` on the coefficients (such as the real numbers) `conjTranspose` and `transpose` are the same operation. -/ @[simp] theorem conjTranspose_eq_transpose_of_trivial [Star α] [TrivialStar α] (A : Matrix m n α) : Aᴴ = Aᵀ := Matrix.ext fun _ _ => star_trivial _ variable (m n α) /-- `Matrix.conjTranspose` as an `AddEquiv` -/ @[simps apply] def conjTransposeAddEquiv [AddMonoid α] [StarAddMonoid α] : Matrix m n α ≃+ Matrix n m α where toFun := conjTranspose invFun := conjTranspose left_inv := conjTranspose_conjTranspose right_inv := conjTranspose_conjTranspose map_add' := conjTranspose_add @[simp] theorem conjTransposeAddEquiv_symm [AddMonoid α] [StarAddMonoid α] : (conjTransposeAddEquiv m n α).symm = conjTransposeAddEquiv n m α := rfl variable {m n α} theorem conjTranspose_list_sum [AddMonoid α] [StarAddMonoid α] (l : List (Matrix m n α)) : l.sumᴴ = (l.map conjTranspose).sum := map_list_sum (conjTransposeAddEquiv m n α) l theorem conjTranspose_multiset_sum [AddCommMonoid α] [StarAddMonoid α] (s : Multiset (Matrix m n α)) : s.sumᴴ = (s.map conjTranspose).sum := (conjTransposeAddEquiv m n α).toAddMonoidHom.map_multiset_sum s theorem conjTranspose_sum [AddCommMonoid α] [StarAddMonoid α] {ι : Type*} (s : Finset ι) (M : ι → Matrix m n α) : (∑ i ∈ s, M i)ᴴ = ∑ i ∈ s, (M i)ᴴ := map_sum (conjTransposeAddEquiv m n α) _ s variable (m n R α) /-- `Matrix.conjTranspose` as a `LinearMap` -/ @[simps apply] def conjTransposeLinearEquiv [CommSemiring R] [StarRing R] [AddCommMonoid α] [StarAddMonoid α] [Module R α] [StarModule R α] : Matrix m n α ≃ₗ⋆[R] Matrix n m α := { conjTransposeAddEquiv m n α with map_smul' := conjTranspose_smul } @[simp] theorem conjTransposeLinearEquiv_symm [CommSemiring R] [StarRing R] [AddCommMonoid α] [StarAddMonoid α] [Module R α] [StarModule R α] : (conjTransposeLinearEquiv m n R α).symm = conjTransposeLinearEquiv n m R α := rfl variable {m n R α} variable (m α) /-- `Matrix.conjTranspose` as a `RingEquiv` to the opposite ring -/ @[simps] def conjTransposeRingEquiv [Semiring α] [StarRing α] [Fintype m] : Matrix m m α ≃+* (Matrix m m α)ᵐᵒᵖ := { (conjTransposeAddEquiv m m α).trans MulOpposite.opAddEquiv with toFun := fun M => MulOpposite.op Mᴴ invFun := fun M => M.unopᴴ map_mul' := fun M N => (congr_arg MulOpposite.op (conjTranspose_mul M N)).trans (MulOpposite.op_mul _ _) } variable {m α} @[simp] theorem conjTranspose_pow [Semiring α] [StarRing α] [Fintype m] [DecidableEq m] (M : Matrix m m α) (k : ℕ) : (M ^ k)ᴴ = Mᴴ ^ k := MulOpposite.op_injective <| map_pow (conjTransposeRingEquiv m α) M k theorem conjTranspose_list_prod [Semiring α] [StarRing α] [Fintype m] [DecidableEq m] (l : List (Matrix m m α)) : l.prodᴴ = (l.map conjTranspose).reverse.prod := (conjTransposeRingEquiv m α).unop_map_list_prod l end ConjTranspose section Star /-- When `α` has a star operation, square matrices `Matrix n n α` have a star operation equal to `Matrix.conjTranspose`. -/ instance [Star α] : Star (Matrix n n α) where star := conjTranspose theorem star_eq_conjTranspose [Star α] (M : Matrix m m α) : star M = Mᴴ := rfl @[simp] theorem star_apply [Star α] (M : Matrix n n α) (i j) : (star M) i j = star (M j i) := rfl instance [InvolutiveStar α] : InvolutiveStar (Matrix n n α) where star_involutive := conjTranspose_conjTranspose /-- When `α` is a `*`-additive monoid, `Matrix.star` is also a `*`-additive monoid. -/ instance [AddMonoid α] [StarAddMonoid α] : StarAddMonoid (Matrix n n α) where star_add := conjTranspose_add instance [Star α] [Star β] [SMul α β] [StarModule α β] : StarModule α (Matrix n n β) where star_smul := conjTranspose_smul /-- When `α` is a `*`-(semi)ring, `Matrix.star` is also a `*`-(semi)ring. -/ instance [Fintype n] [NonUnitalSemiring α] [StarRing α] : StarRing (Matrix n n α) where star_add := conjTranspose_add star_mul := conjTranspose_mul /-- A version of `star_mul` for `*` instead of `*`. -/ theorem star_mul [Fintype n] [NonUnitalNonAssocSemiring α] [StarRing α] (M N : Matrix n n α) : star (M * N) = star N * star M := conjTranspose_mul _ _ end Star @[simp] theorem conjTranspose_submatrix [Star α] (A : Matrix m n α) (r : l → m) (c : o → n) : (A.submatrix r c)ᴴ = Aᴴ.submatrix c r := ext fun _ _ => rfl theorem conjTranspose_reindex [Star α] (eₘ : m ≃ l) (eₙ : n ≃ o) (M : Matrix m n α) : (reindex eₘ eₙ M)ᴴ = reindex eₙ eₘ Mᴴ := rfl end Matrix
Rev.lean
/- Copyright (c) 2022 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez, Joel Riou, Yury Kudryashov -/ import Mathlib.Data.Fin.Basic /-! # Reverse on `Fin n` This file contains lemmas about `Fin.rev : Fin n → Fin n` which maps `i` to `n - 1 - i`. ## Definitions * `Fin.revPerm : Equiv.Perm (Fin n)` : `Fin.rev` as an `Equiv.Perm`, the antitone involution given by `i ↦ n-(i+1)` -/ assert_not_exists Monoid Fintype open Fin Nat Function namespace Fin variable {n m : ℕ} theorem rev_involutive : Involutive (rev : Fin n → Fin n) := rev_rev /-- `Fin.rev` as an `Equiv.Perm`, the antitone involution `Fin n → Fin n` given by `i ↦ n-(i+1)`. -/ @[simps! apply symm_apply] def revPerm : Equiv.Perm (Fin n) := Involutive.toPerm rev rev_involutive theorem rev_injective : Injective (@rev n) := rev_involutive.injective theorem rev_surjective : Surjective (@rev n) := rev_involutive.surjective theorem rev_bijective : Bijective (@rev n) := rev_involutive.bijective @[simp] theorem revPerm_symm : (@revPerm n).symm = revPerm := rfl theorem cast_rev (i : Fin n) (h : n = m) : i.rev.cast h = (i.cast h).rev := by subst h; simp theorem rev_eq_iff {i j : Fin n} : rev i = j ↔ i = rev j := by rw [← rev_inj, rev_rev] theorem rev_ne_iff {i j : Fin n} : rev i ≠ j ↔ i ≠ rev j := rev_eq_iff.not theorem rev_lt_iff {i j : Fin n} : rev i < j ↔ rev j < i := by rw [← rev_lt_rev, rev_rev] theorem rev_le_iff {i j : Fin n} : rev i ≤ j ↔ rev j ≤ i := by rw [← rev_le_rev, rev_rev] theorem lt_rev_iff {i j : Fin n} : i < rev j ↔ j < rev i := by rw [← rev_lt_rev, rev_rev] theorem le_rev_iff {i j : Fin n} : i ≤ rev j ↔ j ≤ rev i := by rw [← rev_le_rev, rev_rev] theorem val_rev_zero [NeZero n] : ((rev 0 : Fin n) : ℕ) = n.pred := rfl theorem rev_pred {i : Fin (n + 1)} (h : i ≠ 0) (h' := rev_ne_iff.mpr ((rev_last _).symm ▸ h)) : rev (pred i h) = castPred (rev i) h' := by rw [← castSucc_inj, castSucc_castPred, ← rev_succ, succ_pred] theorem rev_castPred {i : Fin (n + 1)} (h : i ≠ last n) (h' := rev_ne_iff.mpr ((rev_zero _).symm ▸ h)) : rev (castPred i h) = pred (rev i) h' := by rw [← succ_inj, succ_pred, ← rev_castSucc, castSucc_castPred] lemma succAbove_rev_left (p : Fin (n + 1)) (i : Fin n) : p.rev.succAbove i = (p.succAbove i.rev).rev := by obtain h | h := (rev p).succ_le_or_le_castSucc i · rw [succAbove_of_succ_le _ _ h, succAbove_of_le_castSucc _ _ (rev_succ _ ▸ (le_rev_iff.mpr h)), rev_succ, rev_rev] · rw [succAbove_of_le_castSucc _ _ h, succAbove_of_succ_le _ _ (rev_castSucc _ ▸ (rev_le_iff.mpr h)), rev_castSucc, rev_rev] lemma succAbove_rev_right (p : Fin (n + 1)) (i : Fin n) : p.succAbove i.rev = (p.rev.succAbove i).rev := by rw [succAbove_rev_left, rev_rev] /-- `rev` commutes with `succAbove`. -/ lemma rev_succAbove (p : Fin (n + 1)) (i : Fin n) : rev (succAbove p i) = succAbove (rev p) (rev i) := by rw [succAbove_rev_left, rev_rev] lemma predAbove_rev_left (p : Fin n) (i : Fin (n + 1)) : p.rev.predAbove i = (p.predAbove i.rev).rev := by obtain h | h := (rev i).succ_le_or_le_castSucc p · rw [predAbove_of_succ_le _ _ h, rev_pred, predAbove_of_le_castSucc _ _ (rev_succ _ ▸ (le_rev_iff.mpr h)), castPred_inj, rev_rev] · rw [predAbove_of_le_castSucc _ _ h, rev_castPred, predAbove_of_succ_le _ _ (rev_castSucc _ ▸ (rev_le_iff.mpr h)), pred_inj, rev_rev] lemma predAbove_rev_right (p : Fin n) (i : Fin (n + 1)) : p.predAbove i.rev = (p.rev.predAbove i).rev := by rw [predAbove_rev_left, rev_rev] /-- `rev` commutes with `predAbove`. -/ lemma rev_predAbove {n : ℕ} (p : Fin n) (i : Fin (n + 1)) : (predAbove p i).rev = predAbove p.rev i.rev := by rw [predAbove_rev_left, rev_rev] lemma add_rev_cast (j : Fin (n + 1)) : j.1 + j.rev.1 = n := by obtain ⟨j, hj⟩ := j simp [Nat.add_sub_cancel' <| le_of_lt_succ hj] lemma rev_add_cast (j : Fin (n + 1)) : j.rev.1 + j.1 = n := by rw [Nat.add_comm, j.add_rev_cast] end Fin
Ultraproducts.lean
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.ModelTheory.Quotients import Mathlib.Order.Filter.Finite import Mathlib.Order.Filter.Germ.Basic import Mathlib.Order.Filter.Ultrafilter.Defs /-! # Ultraproducts and Łoś's Theorem ## Main Definitions - `FirstOrder.Language.Ultraproduct.Structure` is the ultraproduct structure on `Filter.Product`. ## Main Results - Łoś's Theorem: `FirstOrder.Language.Ultraproduct.sentence_realize`. An ultraproduct models a sentence `φ` if and only if the set of structures in the product that model `φ` is in the ultrafilter. ## Tags ultraproduct, Los's theorem -/ universe u v variable {α : Type*} (M : α → Type*) (u : Ultrafilter α) open FirstOrder Filter namespace FirstOrder namespace Language open Structure variable {L : Language.{u, v}} [∀ a, L.Structure (M a)] namespace Ultraproduct instance setoidPrestructure : L.Prestructure ((u : Filter α).productSetoid M) := { (u : Filter α).productSetoid M with toStructure := { funMap := fun {_} f x a => funMap f fun i => x i a RelMap := fun {_} r x => ∀ᶠ a : α in u, RelMap r fun i => x i a } fun_equiv := fun {n} f x y xy => by refine mem_of_superset (iInter_mem.2 xy) fun a ha => ?_ simp only [Set.mem_iInter, Set.mem_setOf_eq] at ha simp only [Set.mem_setOf_eq, ha] rel_equiv := fun {n} r x y xy => by rw [← iff_eq_eq] refine ⟨fun hx => ?_, fun hy => ?_⟩ · refine mem_of_superset (inter_mem hx (iInter_mem.2 xy)) ?_ rintro a ⟨ha1, ha2⟩ simp only [Set.mem_iInter, Set.mem_setOf_eq] at * rw [← funext ha2] exact ha1 · refine mem_of_superset (inter_mem hy (iInter_mem.2 xy)) ?_ rintro a ⟨ha1, ha2⟩ simp only [Set.mem_iInter, Set.mem_setOf_eq] at * rw [funext ha2] exact ha1 } variable {M} {u} instance «structure» : L.Structure ((u : Filter α).Product M) := Language.quotientStructure theorem funMap_cast {n : ℕ} (f : L.Functions n) (x : Fin n → ∀ a, M a) : (funMap f fun i => (x i : (u : Filter α).Product M)) = (fun a => funMap f fun i => x i a : (u : Filter α).Product M) := by apply funMap_quotient_mk' theorem term_realize_cast {β : Type*} (x : β → ∀ a, M a) (t : L.Term β) : (t.realize fun i => (x i : (u : Filter α).Product M)) = (fun a => t.realize fun i => x i a : (u : Filter α).Product M) := by convert @Term.realize_quotient_mk' L _ ((u : Filter α).productSetoid M) (Ultraproduct.setoidPrestructure M u) _ t x using 2 ext a induction t with | var => rfl | func _ _ t_ih => simp only [Term.realize, t_ih]; rfl variable [∀ a : α, Nonempty (M a)] theorem boundedFormula_realize_cast {β : Type*} {n : ℕ} (φ : L.BoundedFormula β n) (x : β → ∀ a, M a) (v : Fin n → ∀ a, M a) : (φ.Realize (fun i : β => (x i : (u : Filter α).Product M)) (fun i => (v i : (u : Filter α).Product M))) ↔ ∀ᶠ a : α in u, φ.Realize (fun i : β => x i a) fun i => v i a := by letI := (u : Filter α).productSetoid M induction φ with | falsum => simp only [BoundedFormula.Realize, eventually_const] | equal => have h2 : ∀ a : α, (Sum.elim (fun i : β => x i a) fun i => v i a) = fun i => Sum.elim x v i a := fun a => funext fun i => Sum.casesOn i (fun i => rfl) fun i => rfl simp only [BoundedFormula.Realize, h2] erw [(Sum.comp_elim ((↑) : (∀ a, M a) → (u : Filter α).Product M) x v).symm, term_realize_cast, term_realize_cast] exact Quotient.eq'' | rel => have h2 : ∀ a : α, (Sum.elim (fun i : β => x i a) fun i => v i a) = fun i => Sum.elim x v i a := fun a => funext fun i => Sum.casesOn i (fun i => rfl) fun i => rfl simp only [BoundedFormula.Realize, h2] erw [(Sum.comp_elim ((↑) : (∀ a, M a) → (u : Filter α).Product M) x v).symm] conv_lhs => enter [2, i]; erw [term_realize_cast] apply relMap_quotient_mk' | imp _ _ ih ih' => simp only [BoundedFormula.Realize, ih v, ih' v] rw [Ultrafilter.eventually_imp] | @all k φ ih => simp only [BoundedFormula.Realize] apply Iff.trans (b := ∀ m : ∀ a : α, M a, φ.Realize (fun i : β => (x i : (u : Filter α).Product M)) (Fin.snoc (((↑) : (∀ a, M a) → (u : Filter α).Product M) ∘ v) (m : (u : Filter α).Product M))) · exact Quotient.forall have h' : ∀ (m : ∀ a, M a) (a : α), (fun i : Fin (k + 1) => (Fin.snoc v m : _ → ∀ a, M a) i a) = Fin.snoc (fun i : Fin k => v i a) (m a) := by refine fun m a => funext (Fin.reverseInduction ?_ fun i _ => ?_) · simp only [Fin.snoc_last] · simp only [Fin.snoc_castSucc] simp only [← Fin.comp_snoc] simp only [Function.comp_def, ih, h'] refine ⟨fun h => ?_, fun h m => ?_⟩ · contrapose! h simp_rw [← Ultrafilter.eventually_not, not_forall] at h refine ⟨fun a : α => Classical.epsilon fun m : M a => ¬φ.Realize (fun i => x i a) (Fin.snoc (fun i => v i a) m), ?_⟩ rw [← Ultrafilter.eventually_not] exact Filter.mem_of_superset h fun a ha => Classical.epsilon_spec ha · rw [Filter.eventually_iff] at * exact Filter.mem_of_superset h fun a ha => ha (m a) theorem realize_formula_cast {β : Type*} (φ : L.Formula β) (x : β → ∀ a, M a) : (φ.Realize fun i => (x i : (u : Filter α).Product M)) ↔ ∀ᶠ a : α in u, φ.Realize fun i => x i a := by simp_rw [Formula.Realize, ← boundedFormula_realize_cast φ x, iff_eq_eq] exact congr rfl (Subsingleton.elim _ _) /-- **Łoś's Theorem**: A sentence is true in an ultraproduct if and only if the set of structures it is true in is in the ultrafilter. -/ theorem sentence_realize (φ : L.Sentence) : (u : Filter α).Product M ⊨ φ ↔ ∀ᶠ a : α in u, M a ⊨ φ := by simp_rw [Sentence.Realize] rw [← realize_formula_cast φ, iff_eq_eq] exact congr rfl (Subsingleton.elim _ _) nonrec instance Product.instNonempty : Nonempty ((u : Filter α).Product M) := letI : ∀ a, Inhabited (M a) := fun _ => Classical.inhabited_of_nonempty' inferInstance end Ultraproduct end Language end FirstOrder
all_character.v
From mathcomp Require Export character. From mathcomp Require Export classfun. From mathcomp Require Export inertia. From mathcomp Require Export integral_char. From mathcomp Require Export mxabelem. From mathcomp Require Export mxrepresentation. From mathcomp Require Export vcharacter.
Basic.lean
/- Copyright (c) 2022 Floris van Doorn, Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Heather Macbeth -/ import Mathlib.Geometry.Manifold.ContMDiff.Atlas import Mathlib.Geometry.Manifold.VectorBundle.FiberwiseLinear import Mathlib.Topology.VectorBundle.Constructions /-! # `C^n` vector bundles This file defines `C^n` vector bundles over a manifold. Let `E` be a topological vector bundle, with model fiber `F` and base space `B`. We consider `E` as carrying a charted space structure given by its trivializations -- these are charts to `B × F`. Then, by "composition", if `B` is itself a charted space over `H` (e.g. a smooth manifold), then `E` is also a charted space over `H × F`. Now, we define `ContMDiffVectorBundle` as the `Prop` of having `C^n` transition functions. Recall the structure groupoid `contMDiffFiberwiseLinear` on `B × F` consisting of `C^n`, fiberwise linear partial homeomorphisms. We show that our definition of "`C^n` vector bundle" implies `HasGroupoid` for this groupoid, and show (by a "composition" of `HasGroupoid` instances) that this means that a `C^n` vector bundle is a `C^n` manifold. Since `ContMDiffVectorBundle` is a mixin, it should be easy to make variants and for many such variants to coexist -- vector bundles can be `C^n` vector bundles over several different base fields, etc. ## Main definitions and constructions * `FiberBundle.chartedSpace`: A fiber bundle `E` over a base `B` with model fiber `F` is naturally a charted space modelled on `B × F`. * `FiberBundle.chartedSpace'`: Let `B` be a charted space modelled on `HB`. Then a fiber bundle `E` over a base `B` with model fiber `F` is naturally a charted space modelled on `HB.prod F`. * `ContMDiffVectorBundle`: Mixin class stating that a (topological) `VectorBundle` is `C^n`, in the sense of having `C^n` transition functions, where the smoothness index `n` belongs to `WithTop ℕ∞`. * `ContMDiffFiberwiseLinear.hasGroupoid`: For a `C^n` vector bundle `E` over `B` with fiber modelled on `F`, the change-of-co-ordinates between two trivializations `e`, `e'` for `E`, considered as charts to `B × F`, is `C^n` and fiberwise linear, in the sense of belonging to the structure groupoid `contMDiffFiberwiseLinear`. * `Bundle.TotalSpace.isManifold`: A `C^n` vector bundle is naturally a `C^n` manifold. * `VectorBundleCore.instContMDiffVectorBundle`: If a (topological) `VectorBundleCore` is `C^n`, in the sense of having `C^n` transition functions (cf. `VectorBundleCore.IsContMDiff`), then the vector bundle constructed from it is a `C^n` vector bundle. * `VectorPrebundle.contMDiffVectorBundle`: If a `VectorPrebundle` is `C^n`, in the sense of having `C^n` transition functions (cf. `VectorPrebundle.IsContMDiff`), then the vector bundle constructed from it is a `C^n` vector bundle. * `Bundle.Prod.contMDiffVectorBundle`: The direct sum of two `C^n` vector bundles is a `C^n` vector bundle. -/ assert_not_exists mfderiv open Bundle Set PartialHomeomorph open Function (id_def) open Filter open scoped Manifold Bundle Topology ContDiff variable {n : WithTop ℕ∞} {𝕜 B B' F M : Type*} {E : B → Type*} /-! ### Charted space structure on a fiber bundle -/ section variable [TopologicalSpace F] [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] {HB : Type*} [TopologicalSpace HB] [TopologicalSpace B] [ChartedSpace HB B] [FiberBundle F E] /-- A fiber bundle `E` over a base `B` with model fiber `F` is naturally a charted space modelled on `B × F`. -/ instance FiberBundle.chartedSpace' : ChartedSpace (B × F) (TotalSpace F E) where atlas := (fun e : Trivialization F (π F E) => e.toPartialHomeomorph) '' trivializationAtlas F E chartAt x := (trivializationAt F E x.proj).toPartialHomeomorph mem_chart_source x := (trivializationAt F E x.proj).mem_source.mpr (mem_baseSet_trivializationAt F E x.proj) chart_mem_atlas _ := mem_image_of_mem _ (trivialization_mem_atlas F E _) theorem FiberBundle.chartedSpace'_chartAt (x : TotalSpace F E) : chartAt (B × F) x = (trivializationAt F E x.proj).toPartialHomeomorph := rfl /- Porting note: In Lean 3, the next instance was inside a section with locally reducible `ModelProd` and it used `ModelProd B F` as the intermediate space. Using `B × F` in the middle gives the same instance. -/ --attribute [local reducible] ModelProd /-- Let `B` be a charted space modelled on `HB`. Then a fiber bundle `E` over a base `B` with model fiber `F` is naturally a charted space modelled on `HB.prod F`. -/ instance FiberBundle.chartedSpace : ChartedSpace (ModelProd HB F) (TotalSpace F E) := ChartedSpace.comp _ (B × F) _ theorem FiberBundle.chartedSpace_chartAt (x : TotalSpace F E) : chartAt (ModelProd HB F) x = (trivializationAt F E x.proj).toPartialHomeomorph ≫ₕ (chartAt HB x.proj).prod (PartialHomeomorph.refl F) := by dsimp only [chartAt_comp, prodChartedSpace_chartAt, FiberBundle.chartedSpace'_chartAt, chartAt_self_eq] rw [Trivialization.coe_coe, Trivialization.coe_fst' _ (mem_baseSet_trivializationAt F E x.proj)] theorem FiberBundle.chartedSpace_chartAt_symm_fst (x : TotalSpace F E) (y : ModelProd HB F) (hy : y ∈ (chartAt (ModelProd HB F) x).target) : ((chartAt (ModelProd HB F) x).symm y).proj = (chartAt HB x.proj).symm y.1 := by simp only [FiberBundle.chartedSpace_chartAt, mfld_simps] at hy ⊢ exact (trivializationAt F E x.proj).proj_symm_apply hy.2 end section variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] {EB : Type*} [NormedAddCommGroup EB] [NormedSpace 𝕜 EB] {HB : Type*} [TopologicalSpace HB] {IB : ModelWithCorners 𝕜 EB HB} (E' : B → Type*) [∀ x, Zero (E' x)] {EM : Type*} [NormedAddCommGroup EM] [NormedSpace 𝕜 EM] {HM : Type*} [TopologicalSpace HM] {IM : ModelWithCorners 𝕜 EM HM} [TopologicalSpace M] [ChartedSpace HM M] variable [TopologicalSpace B] [ChartedSpace HB B] [FiberBundle F E] protected theorem FiberBundle.extChartAt (x : TotalSpace F E) : extChartAt (IB.prod 𝓘(𝕜, F)) x = (trivializationAt F E x.proj).toPartialEquiv ≫ (extChartAt IB x.proj).prod (PartialEquiv.refl F) := by simp_rw [extChartAt, FiberBundle.chartedSpace_chartAt, extend] simp only [PartialEquiv.trans_assoc, mfld_simps] -- Porting note: should not be needed rw [PartialEquiv.prod_trans, PartialEquiv.refl_trans] protected theorem FiberBundle.extChartAt_target (x : TotalSpace F E) : (extChartAt (IB.prod 𝓘(𝕜, F)) x).target = ((extChartAt IB x.proj).target ∩ (extChartAt IB x.proj).symm ⁻¹' (trivializationAt F E x.proj).baseSet) ×ˢ univ := by rw [FiberBundle.extChartAt, PartialEquiv.trans_target, Trivialization.target_eq, inter_prod] rfl theorem FiberBundle.writtenInExtChartAt_trivializationAt {x : TotalSpace F E} {y} (hy : y ∈ (extChartAt (IB.prod 𝓘(𝕜, F)) x).target) : writtenInExtChartAt (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) x (trivializationAt F E x.proj) y = y := writtenInExtChartAt_chartAt_comp _ hy theorem FiberBundle.writtenInExtChartAt_trivializationAt_symm {x : TotalSpace F E} {y} (hy : y ∈ (extChartAt (IB.prod 𝓘(𝕜, F)) x).target) : writtenInExtChartAt (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) (trivializationAt F E x.proj x) (trivializationAt F E x.proj).toPartialHomeomorph.symm y = y := writtenInExtChartAt_chartAt_symm_comp _ hy /-! ### Regularity of maps in/out fiber bundles Note: For these results we don't need that the bundle is a `C^n` vector bundle, or even a vector bundle at all, just that it is a fiber bundle over a charted base space. -/ namespace Bundle /-- Characterization of `C^n` functions into a vector bundle. Version at a point within a set. -/ theorem contMDiffWithinAt_totalSpace {f : M → TotalSpace F E} {s : Set M} {x₀ : M} : ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F)) n f s x₀ ↔ ContMDiffWithinAt IM IB n (fun x => (f x).proj) s x₀ ∧ ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun x ↦ (trivializationAt F E (f x₀).proj (f x)).2) s x₀ := by simp +singlePass only [contMDiffWithinAt_iff_target] rw [and_and_and_comm, ← FiberBundle.continuousWithinAt_totalSpace, and_congr_right_iff] intro hf simp_rw [modelWithCornersSelf_prod, FiberBundle.extChartAt, Function.comp_def, PartialEquiv.trans_apply, PartialEquiv.prod_coe, PartialEquiv.refl_coe, extChartAt_self_apply, modelWithCornersSelf_coe, Function.id_def, ← chartedSpaceSelf_prod] refine (contMDiffWithinAt_prod_iff _).trans (and_congr ?_ Iff.rfl) have h1 : (fun x => (f x).proj) ⁻¹' (trivializationAt F E (f x₀).proj).baseSet ∈ 𝓝[s] x₀ := ((FiberBundle.continuous_proj F E).continuousWithinAt.comp hf (mapsTo_image f s)) ((Trivialization.open_baseSet _).mem_nhds (mem_baseSet_trivializationAt F E _)) refine EventuallyEq.contMDiffWithinAt_iff (eventually_of_mem h1 fun x hx => ?_) ?_ · simp_rw [Function.comp, PartialHomeomorph.coe_coe, Trivialization.coe_coe] rw [Trivialization.coe_fst'] exact hx · simp only [mfld_simps] /-- Characterization of `C^n` functions into a vector bundle. Version at a point. -/ theorem contMDiffAt_totalSpace {f : M → TotalSpace F E} {x₀ : M} : ContMDiffAt IM (IB.prod 𝓘(𝕜, F)) n f x₀ ↔ ContMDiffAt IM IB n (fun x ↦ (f x).proj) x₀ ∧ ContMDiffAt IM 𝓘(𝕜, F) n (fun x ↦ (trivializationAt F E (f x₀).proj (f x)).2) x₀ := by simp_rw [← contMDiffWithinAt_univ]; exact contMDiffWithinAt_totalSpace /-- Characterization of `C^n` sections within a set at a point of a vector bundle. -/ theorem contMDiffWithinAt_section {s : ∀ x, E x} {a : Set B} {x₀ : B} : ContMDiffWithinAt IB (IB.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) a x₀ ↔ ContMDiffWithinAt IB 𝓘(𝕜, F) n (fun x ↦ (trivializationAt F E x₀ ⟨x, s x⟩).2) a x₀ := by simp_rw [contMDiffWithinAt_totalSpace, and_iff_right_iff_imp]; intro; exact contMDiffWithinAt_id /-- Characterization of `C^n` sections of a vector bundle. -/ theorem contMDiffAt_section {s : ∀ x, E x} (x₀ : B) : ContMDiffAt IB (IB.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) x₀ ↔ ContMDiffAt IB 𝓘(𝕜, F) n (fun x ↦ (trivializationAt F E x₀ ⟨x, s x⟩).2) x₀ := by simp_rw [contMDiffAt_totalSpace, and_iff_right_iff_imp]; intro; exact contMDiffAt_id variable (E) theorem contMDiff_proj : ContMDiff (IB.prod 𝓘(𝕜, F)) IB n (π F E) := fun x ↦ by have : ContMDiffAt (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) n id x := contMDiffAt_id rw [contMDiffAt_totalSpace] at this exact this.1 theorem contMDiffOn_proj {s : Set (TotalSpace F E)} : ContMDiffOn (IB.prod 𝓘(𝕜, F)) IB n (π F E) s := (contMDiff_proj E).contMDiffOn theorem contMDiffAt_proj {p : TotalSpace F E} : ContMDiffAt (IB.prod 𝓘(𝕜, F)) IB n (π F E) p := (contMDiff_proj E).contMDiffAt theorem contMDiffWithinAt_proj {s : Set (TotalSpace F E)} {p : TotalSpace F E} : ContMDiffWithinAt (IB.prod 𝓘(𝕜, F)) IB n (π F E) s p := (contMDiffAt_proj E).contMDiffWithinAt variable (𝕜) [∀ x, AddCommMonoid (E x)] variable [∀ x, Module 𝕜 (E x)] [VectorBundle 𝕜 F E] theorem contMDiff_zeroSection : ContMDiff IB (IB.prod 𝓘(𝕜, F)) n (zeroSection F E) := by intro x unfold zeroSection rw [contMDiffAt_section] apply (contMDiffAt_const (c := 0)).congr_of_eventuallyEq filter_upwards [(trivializationAt F E x).open_baseSet.mem_nhds (mem_baseSet_trivializationAt F E x)] with y hy using congr_arg Prod.snd <| (trivializationAt F E x).zeroSection 𝕜 hy theorem contMDiffOn_zeroSection {t : Set B} : ContMDiffOn IB (IB.prod 𝓘(𝕜, F)) n (zeroSection F E) t := (contMDiff_zeroSection _ _).contMDiffOn theorem contMDiffAt_zeroSection {x : B} : ContMDiffAt IB (IB.prod 𝓘(𝕜, F)) n (zeroSection F E) x := (contMDiff_zeroSection _ _).contMDiffAt theorem contMDiffWithinAt_zeroSection {t : Set B} {x : B} : ContMDiffWithinAt IB (IB.prod 𝓘(𝕜, F)) n (zeroSection F E) t x := (contMDiff_zeroSection _ _ x).contMDiffWithinAt end Bundle end /-! ### `C^n` vector bundles -/ variable [NontriviallyNormedField 𝕜] {EB : Type*} [NormedAddCommGroup EB] [NormedSpace 𝕜 EB] {HB : Type*} [TopologicalSpace HB] {IB : ModelWithCorners 𝕜 EB HB} [TopologicalSpace B] [ChartedSpace HB B] {EM : Type*} [NormedAddCommGroup EM] [NormedSpace 𝕜 EM] {HM : Type*} [TopologicalSpace HM] {IM : ModelWithCorners 𝕜 EM HM} [TopologicalSpace M] [ChartedSpace HM M] [∀ x, AddCommMonoid (E x)] [∀ x, Module 𝕜 (E x)] [NormedAddCommGroup F] [NormedSpace 𝕜 F] section WithTopology variable [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] (F E) variable [FiberBundle F E] [VectorBundle 𝕜 F E] variable (n IB) in /-- When `B` is a manifold with respect to a model `IB` and `E` is a topological vector bundle over `B` with fibers isomorphic to `F`, then `ContMDiffVectorBundle n F E IB` registers that the bundle is `C^n`, in the sense of having `C^n` transition functions. This is a mixin, not carrying any new data. -/ class ContMDiffVectorBundle : Prop where protected contMDiffOn_coordChangeL : ∀ (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'], ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun b : B => (e.coordChangeL 𝕜 e' b : F →L[𝕜] F)) (e.baseSet ∩ e'.baseSet) variable {F E} in protected theorem ContMDiffVectorBundle.of_le {m n : WithTop ℕ∞} (hmn : m ≤ n) [h : ContMDiffVectorBundle n F E IB] : ContMDiffVectorBundle m F E IB := ⟨fun e e' _ _ ↦ (h.contMDiffOn_coordChangeL e e').of_le hmn⟩ instance {a : WithTop ℕ∞} [ContMDiffVectorBundle ∞ F E IB] [h : ENat.LEInfty a] : ContMDiffVectorBundle a F E IB := ContMDiffVectorBundle.of_le h.out instance {a : WithTop ℕ∞} [ContMDiffVectorBundle ω F E IB] : ContMDiffVectorBundle a F E IB := ContMDiffVectorBundle.of_le le_top instance [ContMDiffVectorBundle 2 F E IB] : ContMDiffVectorBundle 1 F E IB := ContMDiffVectorBundle.of_le one_le_two instance : ContMDiffVectorBundle 0 F E IB := by constructor intro e e' he he' rw [contMDiffOn_zero_iff] exact VectorBundle.continuousOn_coordChange' e e' variable [ContMDiffVectorBundle n F E IB] section ContMDiffCoordChange variable {F E} variable (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'] theorem contMDiffOn_coordChangeL : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun b : B => (e.coordChangeL 𝕜 e' b : F →L[𝕜] F)) (e.baseSet ∩ e'.baseSet) := ContMDiffVectorBundle.contMDiffOn_coordChangeL e e' theorem contMDiffOn_symm_coordChangeL : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun b : B => ((e.coordChangeL 𝕜 e' b).symm : F →L[𝕜] F)) (e.baseSet ∩ e'.baseSet) := by rw [inter_comm] refine (ContMDiffVectorBundle.contMDiffOn_coordChangeL e' e).congr fun b hb ↦ ?_ rw [e.symm_coordChangeL e' hb] variable {e e'} theorem contMDiffAt_coordChangeL {x : B} (h : x ∈ e.baseSet) (h' : x ∈ e'.baseSet) : ContMDiffAt IB 𝓘(𝕜, F →L[𝕜] F) n (fun b : B => (e.coordChangeL 𝕜 e' b : F →L[𝕜] F)) x := (contMDiffOn_coordChangeL e e').contMDiffAt <| (e.open_baseSet.inter e'.open_baseSet).mem_nhds ⟨h, h'⟩ variable {s : Set M} {f : M → B} {g : M → F} {x : M} protected theorem ContMDiffWithinAt.coordChangeL (hf : ContMDiffWithinAt IM IB n f s x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) : ContMDiffWithinAt IM 𝓘(𝕜, F →L[𝕜] F) n (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) s x := (contMDiffAt_coordChangeL he he').comp_contMDiffWithinAt _ hf protected nonrec theorem ContMDiffAt.coordChangeL (hf : ContMDiffAt IM IB n f x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) : ContMDiffAt IM 𝓘(𝕜, F →L[𝕜] F) n (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) x := hf.coordChangeL he he' protected theorem ContMDiffOn.coordChangeL (hf : ContMDiffOn IM IB n f s) (he : MapsTo f s e.baseSet) (he' : MapsTo f s e'.baseSet) : ContMDiffOn IM 𝓘(𝕜, F →L[𝕜] F) n (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) s := fun x hx ↦ (hf x hx).coordChangeL (he hx) (he' hx) protected theorem ContMDiff.coordChangeL (hf : ContMDiff IM IB n f) (he : ∀ x, f x ∈ e.baseSet) (he' : ∀ x, f x ∈ e'.baseSet) : ContMDiff IM 𝓘(𝕜, F →L[𝕜] F) n (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) := fun x ↦ (hf x).coordChangeL (he x) (he' x) protected theorem ContMDiffWithinAt.coordChange (hf : ContMDiffWithinAt IM IB n f s x) (hg : ContMDiffWithinAt IM 𝓘(𝕜, F) n g s x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) : ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ e.coordChange e' (f y) (g y)) s x := by refine ((hf.coordChangeL he he').clm_apply hg).congr_of_eventuallyEq ?_ ?_ · have : e.baseSet ∩ e'.baseSet ∈ 𝓝 (f x) := (e.open_baseSet.inter e'.open_baseSet).mem_nhds ⟨he, he'⟩ filter_upwards [hf.continuousWithinAt this] with y hy exact (Trivialization.coordChangeL_apply' e e' hy (g y)).symm · exact (Trivialization.coordChangeL_apply' e e' ⟨he, he'⟩ (g x)).symm protected nonrec theorem ContMDiffAt.coordChange (hf : ContMDiffAt IM IB n f x) (hg : ContMDiffAt IM 𝓘(𝕜, F) n g x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) : ContMDiffAt IM 𝓘(𝕜, F) n (fun y ↦ e.coordChange e' (f y) (g y)) x := hf.coordChange hg he he' protected theorem ContMDiffOn.coordChange (hf : ContMDiffOn IM IB n f s) (hg : ContMDiffOn IM 𝓘(𝕜, F) n g s) (he : MapsTo f s e.baseSet) (he' : MapsTo f s e'.baseSet) : ContMDiffOn IM 𝓘(𝕜, F) n (fun y ↦ e.coordChange e' (f y) (g y)) s := fun x hx ↦ (hf x hx).coordChange (hg x hx) (he hx) (he' hx) protected theorem ContMDiff.coordChange (hf : ContMDiff IM IB n f) (hg : ContMDiff IM 𝓘(𝕜, F) n g) (he : ∀ x, f x ∈ e.baseSet) (he' : ∀ x, f x ∈ e'.baseSet) : ContMDiff IM 𝓘(𝕜, F) n (fun y ↦ e.coordChange e' (f y) (g y)) := fun x ↦ (hf x).coordChange (hg x) (he x) (he' x) variable (e e') variable (IB) in theorem Trivialization.contMDiffOn_symm_trans : ContMDiffOn (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) n (e.toPartialHomeomorph.symm ≫ₕ e'.toPartialHomeomorph) (e.target ∩ e'.target) := by have Hmaps : MapsTo Prod.fst (e.target ∩ e'.target) (e.baseSet ∩ e'.baseSet) := fun x hx ↦ ⟨e.mem_target.1 hx.1, e'.mem_target.1 hx.2⟩ rw [mapsTo_inter] at Hmaps -- TODO: drop `congr` https://github.com/leanprover-community/mathlib4/issues/5473 refine (contMDiffOn_fst.prodMk (contMDiffOn_fst.coordChange contMDiffOn_snd Hmaps.1 Hmaps.2)).congr ?_ rintro ⟨b, x⟩ hb refine Prod.ext ?_ rfl have : (e.toPartialHomeomorph.symm (b, x)).1 ∈ e'.baseSet := by simp_all only [Trivialization.mem_target, mfld_simps] exact (e'.coe_fst' this).trans (e.proj_symm_apply hb.1) variable {e e'} theorem ContMDiffWithinAt.change_section_trivialization {f : M → TotalSpace F E} (hp : ContMDiffWithinAt IM IB n (π F E ∘ f) s x) (hf : ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ (e (f y)).2) s x) (he : f x ∈ e.source) (he' : f x ∈ e'.source) : ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ (e' (f y)).2) s x := by rw [Trivialization.mem_source] at he he' refine (hp.coordChange hf he he').congr_of_eventuallyEq ?_ ?_ · filter_upwards [hp.continuousWithinAt (e.open_baseSet.mem_nhds he)] with y hy rw [Function.comp_apply, e.coordChange_apply_snd _ hy] · rw [Function.comp_apply, e.coordChange_apply_snd _ he] theorem Trivialization.contMDiffWithinAt_snd_comp_iff₂ {f : M → TotalSpace F E} (hp : ContMDiffWithinAt IM IB n (π F E ∘ f) s x) (he : f x ∈ e.source) (he' : f x ∈ e'.source) : ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ (e (f y)).2) s x ↔ ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ (e' (f y)).2) s x := ⟨(hp.change_section_trivialization · he he'), (hp.change_section_trivialization · he' he)⟩ end ContMDiffCoordChange variable [IsManifold IB n B] in /-- For a `C^n` vector bundle `E` over `B` with fiber modelled on `F`, the change-of-co-ordinates between two trivializations `e`, `e'` for `E`, considered as charts to `B × F`, is `C^n` and fiberwise linear. -/ instance ContMDiffFiberwiseLinear.hasGroupoid : HasGroupoid (TotalSpace F E) (contMDiffFiberwiseLinear B F IB n) where compatible := by rintro _ _ ⟨e, he, rfl⟩ ⟨e', he', rfl⟩ haveI : MemTrivializationAtlas e := ⟨he⟩ haveI : MemTrivializationAtlas e' := ⟨he'⟩ rw [mem_contMDiffFiberwiseLinear_iff] refine ⟨_, _, e.open_baseSet.inter e'.open_baseSet, contMDiffOn_coordChangeL e e', contMDiffOn_symm_coordChangeL e e', ?_⟩ refine PartialHomeomorph.eqOnSourceSetoid.symm ⟨?_, ?_⟩ · simp only [e.symm_trans_source_eq e', FiberwiseLinear.partialHomeomorph, trans_toPartialEquiv, symm_toPartialEquiv] · rintro ⟨b, v⟩ hb exact (e.apply_symm_apply_eq_coordChangeL e' hb.1 v).symm variable [IsManifold IB n B] in /-- A `C^n` vector bundle `E` is naturally a `C^n` manifold. -/ instance Bundle.TotalSpace.isManifold : IsManifold (IB.prod 𝓘(𝕜, F)) n (TotalSpace F E) := by refine { StructureGroupoid.HasGroupoid.comp (contMDiffFiberwiseLinear B F IB n) ?_ with } intro e he rw [mem_contMDiffFiberwiseLinear_iff] at he obtain ⟨φ, U, hU, hφ, h2φ, heφ⟩ := he rw [isLocalStructomorphOn_contDiffGroupoid_iff] refine ⟨ContMDiffOn.congr ?_ (EqOnSource.eqOn heφ), ContMDiffOn.congr ?_ (EqOnSource.eqOn (EqOnSource.symm' heφ))⟩ · rw [EqOnSource.source_eq heφ] apply contMDiffOn_fst.prodMk exact (hφ.comp contMDiffOn_fst <| prod_subset_preimage_fst _ _).clm_apply contMDiffOn_snd · rw [EqOnSource.target_eq heφ] apply contMDiffOn_fst.prodMk exact (h2φ.comp contMDiffOn_fst <| prod_subset_preimage_fst _ _).clm_apply contMDiffOn_snd section variable {F E} variable {e e' : Trivialization F (π F E)} [MemTrivializationAtlas e] [MemTrivializationAtlas e'] theorem Trivialization.contMDiffWithinAt_iff {f : M → TotalSpace F E} {s : Set M} {x₀ : M} (he : f x₀ ∈ e.source) : ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F)) n f s x₀ ↔ ContMDiffWithinAt IM IB n (fun x => (f x).proj) s x₀ ∧ ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun x ↦ (e (f x)).2) s x₀ := contMDiffWithinAt_totalSpace.trans <| and_congr_right fun h ↦ Trivialization.contMDiffWithinAt_snd_comp_iff₂ h FiberBundle.mem_trivializationAt_proj_source he theorem Trivialization.contMDiffAt_iff {f : M → TotalSpace F E} {x₀ : M} (he : f x₀ ∈ e.source) : ContMDiffAt IM (IB.prod 𝓘(𝕜, F)) n f x₀ ↔ ContMDiffAt IM IB n (fun x => (f x).proj) x₀ ∧ ContMDiffAt IM 𝓘(𝕜, F) n (fun x ↦ (e (f x)).2) x₀ := e.contMDiffWithinAt_iff he theorem Trivialization.contMDiffOn_iff {f : M → TotalSpace F E} {s : Set M} (he : MapsTo f s e.source) : ContMDiffOn IM (IB.prod 𝓘(𝕜, F)) n f s ↔ ContMDiffOn IM IB n (fun x => (f x).proj) s ∧ ContMDiffOn IM 𝓘(𝕜, F) n (fun x ↦ (e (f x)).2) s := by simp only [ContMDiffOn, ← forall_and] exact forall₂_congr fun x hx ↦ e.contMDiffWithinAt_iff (he hx) theorem Trivialization.contMDiff_iff {f : M → TotalSpace F E} (he : ∀ x, f x ∈ e.source) : ContMDiff IM (IB.prod 𝓘(𝕜, F)) n f ↔ ContMDiff IM IB n (fun x => (f x).proj) ∧ ContMDiff IM 𝓘(𝕜, F) n (fun x ↦ (e (f x)).2) := (forall_congr' fun x ↦ e.contMDiffAt_iff (he x)).trans forall_and theorem Trivialization.contMDiffOn (e : Trivialization F (π F E)) [MemTrivializationAtlas e] : ContMDiffOn (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) n e e.source := by have : ContMDiffOn (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) n id e.source := contMDiffOn_id rw [e.contMDiffOn_iff (mapsTo_id _)] at this exact (this.1.prodMk this.2).congr fun x hx ↦ (e.mk_proj_snd hx).symm theorem Trivialization.contMDiffOn_symm (e : Trivialization F (π F E)) [MemTrivializationAtlas e] : ContMDiffOn (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) n e.toPartialHomeomorph.symm e.target := by rw [e.contMDiffOn_iff e.toPartialHomeomorph.symm_mapsTo] refine ⟨contMDiffOn_fst.congr fun x hx ↦ e.proj_symm_apply hx, contMDiffOn_snd.congr fun x hx ↦ ?_⟩ rw [e.apply_symm_apply hx] /-- Smoothness of a `C^n` section at `x₀` within a set `a` can be determined using any trivialisation whose `baseSet` contains `x₀`. -/ theorem Trivialization.contMDiffWithinAt_section {s : ∀ x, E x} (a : Set B) {x₀ : B} {e : Trivialization F (Bundle.TotalSpace.proj : Bundle.TotalSpace F E → B)} [MemTrivializationAtlas e] (hx₀ : x₀ ∈ e.baseSet) : ContMDiffWithinAt IB (IB.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) a x₀ ↔ ContMDiffWithinAt IB 𝓘(𝕜, F) n (fun x ↦ (e ⟨x, s x⟩).2) a x₀ := by rw [e.contMDiffWithinAt_iff] · change ContMDiffWithinAt IB IB n id a x₀ ∧ _ ↔ _ simp [contMDiffWithinAt_id] · rwa [mem_source] /-- Smoothness of a `C^n` section at `x₀` can be determined using any trivialisation whose `baseSet` contains `x₀`. -/ theorem contMDiffAt_section_of_mem_baseSet {s : ∀ x, E x} {x₀ : B} {e : Trivialization F (Bundle.TotalSpace.proj : Bundle.TotalSpace F E → B)} [MemTrivializationAtlas e] (hx₀ : x₀ ∈ e.baseSet) : ContMDiffAt IB (IB.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) x₀ ↔ ContMDiffAt IB 𝓘(𝕜, F) n (fun x ↦ (e ⟨x, s x⟩).2) x₀ := by simp_rw [← contMDiffWithinAt_univ] exact e.contMDiffWithinAt_section univ hx₀ /-- Smoothness of a `C^n` section on `s` can be determined using any trivialisation whose `baseSet` contains `s`. -/ theorem contMDiffOn_section_of_mem_baseSet {s : ∀ x, E x} {a : Set B} {e : Trivialization F (Bundle.TotalSpace.proj : Bundle.TotalSpace F E → B)} [MemTrivializationAtlas e] (ha : IsOpen a) (ha' : a ⊆ e.baseSet) : ContMDiffOn IB (IB.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) a ↔ ContMDiffOn IB 𝓘(𝕜, F) n (fun x ↦ (e ⟨x, s x⟩).2) a := by refine ⟨fun h x hx ↦ ?_, fun h x hx ↦ ?_⟩ <;> have := (h x hx).contMDiffAt <| ha.mem_nhds hx · exact ((contMDiffAt_section_of_mem_baseSet (ha' hx)).mp this).contMDiffWithinAt · exact ((contMDiffAt_section_of_mem_baseSet (ha' hx)).mpr this).contMDiffWithinAt /-- For any trivialization `e`, the smoothness of a `C^n` section on `e.baseSet` can be determined using `e`. -/ theorem contMDiffOn_section_of_mem_baseSet₀ {s : ∀ x, E x} {e : Trivialization F (Bundle.TotalSpace.proj : Bundle.TotalSpace F E → B)} [MemTrivializationAtlas e] : ContMDiffOn IB (IB.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) e.baseSet ↔ ContMDiffOn IB 𝓘(𝕜, F) n (fun x ↦ (e ⟨x, s x⟩).2) e.baseSet := contMDiffOn_section_of_mem_baseSet e.open_baseSet (subset_refl _) end /-! ### Core construction for `C^n` vector bundles -/ namespace VectorBundleCore variable {F} variable {ι : Type*} (Z : VectorBundleCore 𝕜 B F ι) /-- Mixin for a `VectorBundleCore` stating that transition functions are `C^n`. -/ class IsContMDiff (IB : ModelWithCorners 𝕜 EB HB) (n : WithTop ℕ∞) : Prop where contMDiffOn_coordChange : ∀ i j, ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (Z.coordChange i j) (Z.baseSet i ∩ Z.baseSet j) theorem contMDiffOn_coordChange (IB : ModelWithCorners 𝕜 EB HB) [h : Z.IsContMDiff IB n] (i j : ι) : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (Z.coordChange i j) (Z.baseSet i ∩ Z.baseSet j) := h.1 i j variable [Z.IsContMDiff IB n] /-- If a `VectorBundleCore` has the `IsContMDiff` mixin, then the vector bundle constructed from it is a `C^n` vector bundle. -/ instance instContMDiffVectorBundle : ContMDiffVectorBundle n F Z.Fiber IB where contMDiffOn_coordChangeL := by rintro - - ⟨i, rfl⟩ ⟨i', rfl⟩ refine (Z.contMDiffOn_coordChange IB i i').congr fun b hb ↦ ?_ ext v exact Z.localTriv_coordChange_eq i i' hb v end VectorBundleCore /-! ### The trivial `C^n` vector bundle -/ /-- A trivial vector bundle over a manifold is a `C^n` vector bundle. -/ instance Bundle.Trivial.contMDiffVectorBundle : ContMDiffVectorBundle n F (Bundle.Trivial B F) IB where contMDiffOn_coordChangeL := by intro e e' he he' obtain rfl := Bundle.Trivial.eq_trivialization B F e obtain rfl := Bundle.Trivial.eq_trivialization B F e' simp_rw [Bundle.Trivial.trivialization.coordChangeL] exact contMDiff_const.contMDiffOn /-! ### Direct sums of `C^n` vector bundles -/ section Prod variable (F₁ : Type*) [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] (E₁ : B → Type*) [TopologicalSpace (TotalSpace F₁ E₁)] [∀ x, AddCommMonoid (E₁ x)] [∀ x, Module 𝕜 (E₁ x)] variable (F₂ : Type*) [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] (E₂ : B → Type*) [TopologicalSpace (TotalSpace F₂ E₂)] [∀ x, AddCommMonoid (E₂ x)] [∀ x, Module 𝕜 (E₂ x)] variable [∀ x : B, TopologicalSpace (E₁ x)] [∀ x : B, TopologicalSpace (E₂ x)] [FiberBundle F₁ E₁] [FiberBundle F₂ E₂] [VectorBundle 𝕜 F₁ E₁] [VectorBundle 𝕜 F₂ E₂] [ContMDiffVectorBundle n F₁ E₁ IB] [ContMDiffVectorBundle n F₂ E₂ IB] variable [IsManifold IB n B] /-- The direct sum of two `C^n` vector bundles over the same base is a `C^n` vector bundle. -/ instance Bundle.Prod.contMDiffVectorBundle : ContMDiffVectorBundle n (F₁ × F₂) (E₁ ×ᵇ E₂) IB where contMDiffOn_coordChangeL := by rintro _ _ ⟨e₁, e₂, i₁, i₂, rfl⟩ ⟨e₁', e₂', i₁', i₂', rfl⟩ refine ContMDiffOn.congr ?_ (e₁.coordChangeL_prod 𝕜 e₁' e₂ e₂') refine ContMDiffOn.clm_prodMap ?_ ?_ · refine (contMDiffOn_coordChangeL e₁ e₁').mono ?_ simp only [Trivialization.prod_baseSet, mfld_simps] mfld_set_tac · refine (contMDiffOn_coordChangeL e₂ e₂').mono ?_ simp only [Trivialization.prod_baseSet, mfld_simps] mfld_set_tac end Prod end WithTopology /-! ### Prebundle construction for `C^n` vector bundles -/ namespace VectorPrebundle variable [∀ x, TopologicalSpace (E x)] variable (IB) in /-- Mixin for a `VectorPrebundle` stating that coordinate changes are `C^n`. -/ class IsContMDiff (a : VectorPrebundle 𝕜 F E) (n : WithTop ℕ∞) : Prop where exists_contMDiffCoordChange : ∀ᵉ (e ∈ a.pretrivializationAtlas) (e' ∈ a.pretrivializationAtlas), ∃ f : B → F →L[𝕜] F, ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n f (e.baseSet ∩ e'.baseSet) ∧ ∀ (b : B) (_ : b ∈ e.baseSet ∩ e'.baseSet) (v : F), f b v = (e' ⟨b, e.symm b v⟩).2 variable (a : VectorPrebundle 𝕜 F E) [ha : a.IsContMDiff IB n] {e e' : Pretrivialization F (π F E)} variable (IB n) in /-- A randomly chosen coordinate change on a `VectorPrebundle` satisfying `IsContMDiff`, given by the field `exists_coordChange`. Note that `a.contMDiffCoordChange` need not be the same as `a.coordChange`. -/ noncomputable def contMDiffCoordChange (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) (b : B) : F →L[𝕜] F := Classical.choose (ha.exists_contMDiffCoordChange e he e' he') b theorem contMDiffOn_contMDiffCoordChange (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (a.contMDiffCoordChange n IB he he') (e.baseSet ∩ e'.baseSet) := (Classical.choose_spec (ha.exists_contMDiffCoordChange e he e' he')).1 theorem contMDiffCoordChange_apply (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) : a.contMDiffCoordChange n IB he he' b v = (e' ⟨b, e.symm b v⟩).2 := (Classical.choose_spec (ha.exists_contMDiffCoordChange e he e' he')).2 b hb v theorem mk_contMDiffCoordChange (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) : (b, a.contMDiffCoordChange n IB he he' b v) = e' ⟨b, e.symm b v⟩ := by ext · rw [e.mk_symm hb.1 v, e'.coe_fst', e.proj_symm_apply' hb.1] rw [e.proj_symm_apply' hb.1]; exact hb.2 · exact a.contMDiffCoordChange_apply he he' hb v variable (IB) in /-- Make a `ContMDiffVectorBundle` from a `ContMDiffVectorPrebundle`. -/ theorem contMDiffVectorBundle : @ContMDiffVectorBundle n _ _ F E _ _ _ _ _ _ IB _ _ _ _ _ _ a.totalSpaceTopology _ a.toFiberBundle a.toVectorBundle := letI := a.totalSpaceTopology; letI := a.toFiberBundle; letI := a.toVectorBundle { contMDiffOn_coordChangeL := by rintro _ _ ⟨e, he, rfl⟩ ⟨e', he', rfl⟩ refine (a.contMDiffOn_contMDiffCoordChange he he').congr ?_ intro b hb ext v rw [a.contMDiffCoordChange_apply he he' hb v, ContinuousLinearEquiv.coe_coe, Trivialization.coordChangeL_apply] exacts [rfl, hb] } end VectorPrebundle
Kolmogorov.lean
/- Copyright (c) 2025 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic import Mathlib.MeasureTheory.Function.StronglyMeasurable.AEStronglyMeasurable import Mathlib.MeasureTheory.Integral.Lebesgue.Basic /-! # Stochastic processes satisfying the Kolmogorov condition A stochastic process `X : T → Ω → E` on an index space `T` and a measurable space `Ω` with measure `P` is said to satisfy the Kolmogorov condition with exponents `p, q` and constant `M` if for all `s, t : T`, the pair `(X s, X t)` is measurable for the Borel sigma-algebra on `E × E` and the following condition holds: `∫⁻ ω, edist (X s ω) (X t ω) ^ p ∂P ≤ M * edist s t ^ q`. This condition is the main assumption of the Kolmogorov-Chentsov theorem, which gives the existence of a continuous modification of the process. The measurability condition on pairs ensures that the distance `edist (X s ω) (X t ω)` is measurable in `ω` for fixed `s, t`. In a space with second-countable topology, the measurability of pairs can be obtained from measurability of each `X t`. ## Main definitions * `IsKolmogorovProcess`: property of being a stochastic process that satisfies the Kolmogorov condition. * `IsAEKolmogorovProcess`: a stochastic process satisfies `IsAEKolmogorovProcess` if it is a modification of a process satisfying the Kolmogorov condition. ## Main statements * `IsKolmogorovProcess.mk_of_secondCountableTopology`: in a space with second-countable topology, a process is a Kolmogorov process if each `X t` is measurable and the Kolmogorov condition holds. -/ open MeasureTheory open scoped ENNReal NNReal namespace ProbabilityTheory variable {T Ω E : Type*} [PseudoEMetricSpace T] {mΩ : MeasurableSpace Ω} [PseudoEMetricSpace E] {p q : ℝ} {M : ℝ≥0} {P : Measure Ω} {X : T → Ω → E} /-- A stochastic process `X : T → Ω → E` on an index space `T` and a measurable space `Ω` with measure `P` is said to satisfy the Kolmogorov condition with exponents `p, q` and constant `M` if for all `s, t : T`, the pair `(X s, X t)` is measurable for the Borel sigma-algebra on `E × E` and the following condition holds: `∫⁻ ω, edist (X s ω) (X t ω) ^ p ∂P ≤ M * edist s t ^ q`. -/ structure IsKolmogorovProcess (X : T → Ω → E) (P : Measure Ω) (p q : ℝ) (M : ℝ≥0) : Prop where measurablePair : ∀ s t : T, Measurable[_, borel (E × E)] fun ω ↦ (X s ω, X t ω) kolmogorovCondition : ∀ s t : T, ∫⁻ ω, edist (X s ω) (X t ω) ^ p ∂P ≤ M * edist s t ^ q p_pos : 0 < p q_pos : 0 < q /-- Property of being a modification of a stochastic process that satisfies the Kolmogorov condition (`IsKolmogorovProcess`). -/ def IsAEKolmogorovProcess (X : T → Ω → E) (P : Measure Ω) (p q : ℝ) (M : ℝ≥0) : Prop := ∃ Y, IsKolmogorovProcess Y P p q M ∧ ∀ t, X t =ᵐ[P] Y t lemma IsKolmogorovProcess.IsAEKolmogorovProcess (hX : IsKolmogorovProcess X P p q M) : IsAEKolmogorovProcess X P p q M := ⟨X, hX, by simp⟩ namespace IsAEKolmogorovProcess /-- A process with the property `IsKolmogorovProcess` such that `∀ t, X t =ᵐ[P] h.mk X t`. -/ protected noncomputable def mk (X : T → Ω → E) (h : IsAEKolmogorovProcess X P p q M) : T → Ω → E := Classical.choose h lemma IsKolmogorovProcess_mk (h : IsAEKolmogorovProcess X P p q M) : IsKolmogorovProcess (h.mk X) P p q M := (Classical.choose_spec h).1 lemma ae_eq_mk (h : IsAEKolmogorovProcess X P p q M) : ∀ t, X t =ᵐ[P] h.mk X t := (Classical.choose_spec h).2 lemma kolmogorovCondition (hX : IsAEKolmogorovProcess X P p q M) (s t : T) : ∫⁻ ω, edist (X s ω) (X t ω) ^ p ∂P ≤ M * edist s t ^ q := by convert hX.IsKolmogorovProcess_mk.kolmogorovCondition s t using 1 refine lintegral_congr_ae ?_ filter_upwards [hX.ae_eq_mk s, hX.ae_eq_mk t] with ω hω₁ hω₂ simp_rw [hω₁, hω₂] lemma p_pos (hX : IsAEKolmogorovProcess X P p q M) : 0 < p := hX.IsKolmogorovProcess_mk.p_pos lemma q_pos (hX : IsAEKolmogorovProcess X P p q M) : 0 < q := hX.IsKolmogorovProcess_mk.q_pos lemma congr {Y : T → Ω → E} (hX : IsAEKolmogorovProcess X P p q M) (h : ∀ t, X t =ᵐ[P] Y t) : IsAEKolmogorovProcess Y P p q M := by refine ⟨hX.mk X, hX.IsKolmogorovProcess_mk, fun t ↦ ?_⟩ filter_upwards [hX.ae_eq_mk t, h t] with ω hX hY using hY.symm.trans hX end IsAEKolmogorovProcess section Measurability lemma IsKolmogorovProcess.stronglyMeasurable_edist (hX : IsKolmogorovProcess X P p q M) {s t : T} : StronglyMeasurable (fun ω ↦ edist (X s ω) (X t ω)) := by borelize (E × E) exact continuous_edist.stronglyMeasurable.comp_measurable (hX.measurablePair s t) lemma IsAEKolmogorovProcess.aestronglyMeasurable_edist (hX : IsAEKolmogorovProcess X P p q M) {s t : T} : AEStronglyMeasurable (fun ω ↦ edist (X s ω) (X t ω)) P := by refine ⟨(fun ω ↦ edist (hX.mk X s ω) (hX.mk X t ω)), hX.IsKolmogorovProcess_mk.stronglyMeasurable_edist, ?_⟩ filter_upwards [hX.ae_eq_mk s, hX.ae_eq_mk t] with ω hω₁ hω₂ using by simp [hω₁, hω₂] lemma IsKolmogorovProcess.measurable_edist (hX : IsKolmogorovProcess X P p q M) {s t : T} : Measurable (fun ω ↦ edist (X s ω) (X t ω)) := hX.stronglyMeasurable_edist.measurable lemma IsAEKolmogorovProcess.aemeasurable_edist (hX : IsAEKolmogorovProcess X P p q M) {s t : T} : AEMeasurable (fun ω ↦ edist (X s ω) (X t ω)) P := hX.aestronglyMeasurable_edist.aemeasurable variable [MeasurableSpace E] [BorelSpace E] lemma IsKolmogorovProcess.measurable (hX : IsKolmogorovProcess X P p q M) (s : T) : Measurable (X s) := (measurable_fst.mono prod_le_borel_prod le_rfl).comp (hX.measurablePair s s) lemma IsAEKolmogorovProcess.aemeasurable (hX : IsAEKolmogorovProcess X P p q M) (s : T) : AEMeasurable (X s) P := by refine ⟨hX.mk X s, hX.IsKolmogorovProcess_mk.measurable s, ?_⟩ filter_upwards [hX.ae_eq_mk s] with ω hω using hω lemma IsKolmogorovProcess.mk_of_secondCountableTopology [SecondCountableTopology E] (h_meas : ∀ s, Measurable (X s)) (h_kol : ∀ s t : T, ∫⁻ ω, (edist (X s ω) (X t ω)) ^ p ∂P ≤ M * edist s t ^ q) (hp : 0 < p) (hq : 0 < q) : IsKolmogorovProcess X P p q M where measurablePair s t := by suffices Measurable (fun ω ↦ (X s ω, X t ω)) by rwa [Prod.borelSpace.measurable_eq] at this fun_prop kolmogorovCondition := h_kol p_pos := hp q_pos := hq end Measurability section ZeroDist lemma IsAEKolmogorovProcess.edist_eq_zero (hX : IsAEKolmogorovProcess X P p q M) {s t : T} (h : edist s t = 0) : ∀ᵐ ω ∂P, edist (X s ω) (X t ω) = 0 := by suffices ∀ᵐ ω ∂P, edist (X s ω) (X t ω) ^ p = 0 by filter_upwards [this] with ω hω simpa [hX.p_pos, not_lt_of_gt hX.p_pos] using hω refine (lintegral_eq_zero_iff' (hX.aemeasurable_edist.pow_const p)).mp ?_ refine le_antisymm ?_ zero_le' calc ∫⁻ ω, edist (X s ω) (X t ω) ^ p ∂P _ ≤ M * edist s t ^ q := hX.kolmogorovCondition s t _ = 0 := by simp [h, hX.q_pos] lemma IsKolmogorovProcess.edist_eq_zero (hX : IsKolmogorovProcess X P p q M) {s t : T} (h : edist s t = 0) : ∀ᵐ ω ∂P, edist (X s ω) (X t ω) = 0 := hX.IsAEKolmogorovProcess.edist_eq_zero h lemma IsAEKolmogorovProcess.edist_eq_zero_of_const_eq_zero (hX : IsAEKolmogorovProcess X P p q 0) (s t : T) : ∀ᵐ ω ∂P, edist (X s ω) (X t ω) = 0 := by suffices ∀ᵐ ω ∂P, edist (X s ω) (X t ω) ^ p = 0 by filter_upwards [this] with ω hω simpa [hX.p_pos, not_lt_of_gt hX.p_pos] using hω refine (lintegral_eq_zero_iff' (hX.aemeasurable_edist.pow_const p)).mp ?_ refine le_antisymm ?_ zero_le' calc ∫⁻ ω, edist (X s ω) (X t ω) ^ p ∂P _ ≤ 0 * edist s t ^ q := hX.kolmogorovCondition s t _ = 0 := by simp lemma IsKolmogorovProcess.edist_eq_zero_of_const_eq_zero (hX : IsKolmogorovProcess X P p q 0) (s t : T) : ∀ᵐ ω ∂P, edist (X s ω) (X t ω) = 0 := hX.IsAEKolmogorovProcess.edist_eq_zero_of_const_eq_zero s t end ZeroDist end ProbabilityTheory
Frobenius.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.FieldTheory.Finite.Basic import Mathlib.RingTheory.Invariant.Basic import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots import Mathlib.RingTheory.Unramified.Locus /-! # Frobenius elements In algebraic number theory, if `L/K` is a finite Galois extension of number fields, with rings of integers `𝓞L/𝓞K`, and if `q` is prime ideal of `𝓞L` lying over a prime ideal `p` of `𝓞K`, then there exists a **Frobenius element** `Frob p` in `Gal(L/K)` with the property that `Frob p x ≡ x ^ #(𝓞K/p) (mod q)` for all `x ∈ 𝓞L`. Following `RingTheory/Invariant.lean`, we develop the theory in the setting that there is a finite group `G` acting on a ring `S`, and `R` is the fixed subring of `S`. ## Main results Let `S/R` be an extension of rings, `Q` be a prime of `S`, and `P := R ∩ Q` with finite residue field of cardinality `q`. - `AlgHom.IsArithFrobAt`: We say that a `φ : S →ₐ[R] S` is an (arithmetic) Frobenius at `Q` if `φ x ≡ x ^ q (mod Q)` for all `x : S`. - `AlgHom.IsArithFrobAt.apply_of_pow_eq_one`: Suppose `S` is a domain and `φ` is a Frobenius at `Q`, then `φ ζ = ζ ^ q` for any `m`-th root of unity `ζ` with `q ∤ m`. - `AlgHom.IsArithFrobAt.eq_of_isUnramifiedAt`: Suppose `S` is noetherian, `Q` contains all zero-divisors, and the extension is unramified at `Q`. Then the Frobenius is unique (if exists). Let `G` be a finite group acting on a ring `S`, and `R` is the fixed subring of `S`. - `IsArithFrobAt`: We say that a `σ : G` is an (arithmetic) Frobenius at `Q` if `σ • x ≡ x ^ q (mod Q)` for all `x : S`. - `IsArithFrobAt.mul_inv_mem_inertia`: Two Frobenius elements at `Q` differ by an element in the inertia subgroup of `Q`. - `IsArithFrobAt.conj`: If `σ` is a Frobenius at `Q`, then `τστ⁻¹` is a Frobenius at `σ • Q`. - `IsArithFrobAt.exists_of_isInvariant`: Frobenius element exists. -/ variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] /-- `φ : S →ₐ[R] S` is an (arithmetic) Frobenius at `Q` if `φ x ≡ x ^ #(R/p) (mod Q)` for all `x : S` (`AlgHom.IsArithFrobAt`). -/ def AlgHom.IsArithFrobAt (φ : S →ₐ[R] S) (Q : Ideal S) : Prop := ∀ x, φ x - x ^ Nat.card (R ⧸ Q.under R) ∈ Q namespace AlgHom.IsArithFrobAt variable {φ ψ : S →ₐ[R] S} {Q : Ideal S} (H : φ.IsArithFrobAt Q) include H lemma mk_apply (x) : Ideal.Quotient.mk Q (φ x) = x ^ Nat.card (R ⧸ Q.under R) := by rw [← map_pow, Ideal.Quotient.eq] exact H x lemma finite_quotient : _root_.Finite (R ⧸ Q.under R) := by rw [← not_infinite_iff_finite] intro h obtain rfl : Q = ⊤ := by simpa [Nat.card_eq_zero_of_infinite, ← Ideal.eq_top_iff_one] using H 0 simp only [Ideal.comap_top] at h exact not_finite (R ⧸ (⊤ : Ideal R)) lemma card_pos : 0 < Nat.card (R ⧸ Q.under R) := have := H.finite_quotient Nat.card_pos lemma le_comap : Q ≤ Q.comap φ := by intro x hx simp_all only [Ideal.mem_comap, ← Ideal.Quotient.eq_zero_iff_mem (I := Q), H.mk_apply, zero_pow_eq, ite_eq_right_iff, H.card_pos.ne', false_implies] /-- A Frobenius element at `Q` restricts to the Frobenius map on `S ⧸ Q`. -/ def restrict : S ⧸ Q →ₐ[R ⧸ Q.under R] S ⧸ Q where toRingHom := Ideal.quotientMap Q φ H.le_comap commutes' x := by obtain ⟨x, rfl⟩ := Ideal.Quotient.mk_surjective x exact DFunLike.congr_arg (Ideal.Quotient.mk Q) (φ.commutes x) lemma restrict_apply (x : S ⧸ Q) : H.restrict x = x ^ Nat.card (R ⧸ Q.under R) := by obtain ⟨x, rfl⟩ := Ideal.Quotient.mk_surjective x exact H.mk_apply x lemma restrict_mk (x : S) : H.restrict ↑x = ↑(φ x) := rfl lemma restrict_injective [Q.IsPrime] : Function.Injective H.restrict := by rw [injective_iff_map_eq_zero] intro x hx simpa [restrict_apply, H.card_pos.ne'] using hx lemma comap_eq [Q.IsPrime] : Q.comap φ = Q := by refine le_antisymm (fun x hx ↦ ?_) H.le_comap rwa [← Ideal.Quotient.eq_zero_iff_mem, ← H.restrict_injective.eq_iff, map_zero, restrict_mk, Ideal.Quotient.eq_zero_iff_mem, ← Ideal.mem_comap] /-- Suppose `S` is a domain, and `φ : S →ₐ[R] S` is a Frobenius at `Q : Ideal S`. Let `ζ` be a `m`-th root of unity with `Q ∤ m`, then `φ` sends `ζ` to `ζ ^ q`. -/ lemma apply_of_pow_eq_one [IsDomain S] {ζ : S} {m : ℕ} (hζ : ζ ^ m = 1) (hk' : ↑m ∉ Q) : φ ζ = ζ ^ Nat.card (R ⧸ Q.under R) := by set q := Nat.card (R ⧸ Q.under R) have hm : m ≠ 0 := by rintro rfl; exact hk' (by simp) obtain ⟨k, hk, hζ⟩ := IsPrimitiveRoot.exists_pos hζ hm have hk' : ↑k ∉ Q := fun h ↦ hk' (Q.mem_of_dvd (Nat.cast_dvd_cast (hζ.2 m ‹_›)) h) have : NeZero k := ⟨hk.ne'⟩ obtain ⟨i, hi, e⟩ := hζ.eq_pow_of_pow_eq_one (ξ := φ ζ) (by rw [← map_pow, hζ.1, map_one]) have (j : _) : 1 - ζ ^ ((q + k - i) * j) ∈ Q := by rw [← Ideal.mul_unit_mem_iff_mem _ ((hζ.isUnit k.pos_of_neZero).pow (i * j)), sub_mul, one_mul, ← pow_add, ← add_mul, tsub_add_cancel_of_le (by linarith), add_mul, pow_add, pow_mul _ k, hζ.1, one_pow, mul_one, pow_mul, e, ← map_pow, mul_comm, pow_mul] exact H _ have h₁ := sum_mem (t := Finset.range k) fun j _ ↦ this j have h₂ := geom_sum_mul (ζ ^ (q + k - i)) k rw [pow_right_comm, hζ.1, one_pow, sub_self, mul_eq_zero, sub_eq_zero] at h₂ rcases h₂ with h₂ | h₂ · simp [h₂, pow_mul, hk'] at h₁ replace h₂ := congr($h₂ * ζ ^ i) rw [one_mul, ← pow_add, tsub_add_cancel_of_le (by linarith), pow_add, hζ.1, mul_one] at h₂ rw [h₂, e] /-- A Frobenius element at `Q` restricts to an automorphism of `S_Q`. -/ noncomputable def localize [Q.IsPrime] : Localization.AtPrime Q →ₐ[R] Localization.AtPrime Q where toRingHom := Localization.localRingHom _ _ φ H.comap_eq.symm commutes' x := by simp [IsScalarTower.algebraMap_apply R S (Localization.AtPrime Q), Localization.localRingHom_to_map] @[simp] lemma localize_algebraMap [Q.IsPrime] (x : S) : H.localize (algebraMap _ _ x) = algebraMap _ _ (φ x) := Localization.localRingHom_to_map _ _ _ H.comap_eq.symm _ open IsLocalRing nonZeroDivisors lemma isArithFrobAt_localize [Q.IsPrime] : H.localize.IsArithFrobAt (maximalIdeal _) := by have h : Nat.card (R ⧸ (maximalIdeal _).comap (algebraMap R (Localization.AtPrime Q))) = Nat.card (R ⧸ Q.under R) := by congr 2 rw [IsScalarTower.algebraMap_eq R S (Localization.AtPrime Q), ← Ideal.comap_comap, Localization.AtPrime.comap_maximalIdeal] intro x obtain ⟨x, s, rfl⟩ := IsLocalization.mk'_surjective Q.primeCompl x simp only [localize, coe_mk, Localization.localRingHom_mk', RingHom.coe_coe, h, ← IsLocalization.mk'_pow] rw [← IsLocalization.mk'_sub, IsLocalization.AtPrime.mk'_mem_maximal_iff (Localization.AtPrime Q) Q] simp only [SubmonoidClass.coe_pow, ← Ideal.Quotient.eq_zero_iff_mem] simp [H.mk_apply] /-- Suppose `S` is noetherian and `Q` is a prime of `S` containing all zero divisors. If `S/R` is unramified at `Q`, then the Frobenius `φ : S →ₐ[R] S` over `Q` is unique. -/ lemma eq_of_isUnramifiedAt (H' : ψ.IsArithFrobAt Q) [Q.IsPrime] (hQ : Q.primeCompl ≤ S⁰) [Algebra.IsUnramifiedAt R Q] [IsNoetherianRing S] : φ = ψ := by have : H.localize = H'.localize := by have : IsNoetherianRing (Localization.AtPrime Q) := IsLocalization.isNoetherianRing Q.primeCompl _ inferInstance apply Algebra.FormallyUnramified.ext_of_iInf _ (Ideal.iInf_pow_eq_bot_of_isLocalRing (maximalIdeal _) Ideal.IsPrime.ne_top') intro x rw [H.isArithFrobAt_localize.mk_apply, H'.isArithFrobAt_localize.mk_apply] ext x apply IsLocalization.injective (Localization.AtPrime Q) hQ rw [← H.localize_algebraMap, ← H'.localize_algebraMap, this] end AlgHom.IsArithFrobAt variable (R) in /-- Suppose `S` is an `R` algebra, `M` is a monoid acting on `S` whose action is trivial on `R` `σ : M` is an (arithmetic) Frobenius at an ideal `Q` of `S` if `σ • x ≡ x ^ q (mod Q)` for all `x`. -/ abbrev IsArithFrobAt {M : Type*} [Monoid M] [MulSemiringAction M S] [SMulCommClass M R S] (σ : M) (Q : Ideal S) : Prop := (MulSemiringAction.toAlgHom R S σ).IsArithFrobAt Q namespace IsArithFrobAt open scoped Pointwise variable {G : Type*} [Group G] [MulSemiringAction G S] [SMulCommClass G R S] variable {Q : Ideal S} {σ σ' : G} lemma mul_inv_mem_inertia (H : IsArithFrobAt R σ Q) (H' : IsArithFrobAt R σ' Q) : σ * σ'⁻¹ ∈ Q.toAddSubgroup.inertia G := by intro x simpa [mul_smul] using sub_mem (H (σ'⁻¹ • x)) (H' (σ'⁻¹ • x)) lemma conj (H : IsArithFrobAt R σ Q) (τ : G) : IsArithFrobAt R (τ * σ * τ⁻¹) (τ • Q) := by intro x have : (Q.map (MulSemiringAction.toRingEquiv G S τ)).under R = Q.under R := by rw [← Ideal.comap_symm, ← Ideal.comap_coe, Ideal.under, Ideal.comap_comap] congr 1 exact (MulSemiringAction.toAlgEquiv R S τ).symm.toAlgHom.comp_algebraMap rw [Ideal.pointwise_smul_eq_comap, Ideal.mem_comap] simpa [smul_sub, mul_smul, this] using H (τ⁻¹ • x) variable [Finite G] [Algebra.IsInvariant R S G] variable (R G Q) in attribute [local instance] Ideal.Quotient.field in /-- Let `G` be a finite group acting on `S`, and `R` be the fixed subring. If `Q` is a prime of `S` with finite residue field, then there exists a Frobenius element `σ : G` at `Q`. -/ lemma exists_of_isInvariant [Q.IsPrime] [Finite (S ⧸ Q)] : ∃ σ : G, IsArithFrobAt R σ Q := by let P := Q.under R have := Algebra.IsInvariant.isIntegral R S G have : Q.IsMaximal := Ideal.Quotient.maximal_of_isField _ (Finite.isField_of_domain (S ⧸ Q)) have : P.IsMaximal := Ideal.isMaximal_comap_of_isIntegral_of_isMaximal Q obtain ⟨p, hc⟩ := CharP.exists (R ⧸ P) have : Finite (R ⧸ P) := .of_injective _ Ideal.algebraMap_quotient_injective cases nonempty_fintype (R ⧸ P) obtain ⟨k, hp, hk⟩ := FiniteField.card (R ⧸ P) p have := CharP.of_ringHom_of_ne_zero (algebraMap (R ⧸ P) (S ⧸ Q)) p hp.ne_zero have : ExpChar (S ⧸ Q) p := .prime hp let l : (S ⧸ Q) ≃ₐ[R ⧸ P] S ⧸ Q := { __ := iterateFrobeniusEquiv (S ⧸ Q) p k, commutes' r := by dsimp [iterateFrobenius_def] rw [← map_pow, ← hk, FiniteField.pow_card] } obtain ⟨σ, hσ⟩ := Ideal.Quotient.stabilizerHom_surjective G P Q l refine ⟨σ, fun x ↦ ?_⟩ rw [← Ideal.Quotient.eq, Nat.card_eq_fintype_card, hk] exact DFunLike.congr_fun hσ (Ideal.Quotient.mk Q x) variable (S G) in lemma exists_primesOver_isConj (P : Ideal R) (hP : ∃ Q : Ideal.primesOver P S, Finite (S ⧸ Q.1)) : ∃ σ : Ideal.primesOver P S → G, (∀ Q, IsArithFrobAt R (σ Q) Q.1) ∧ (∀ Q₁ Q₂, IsConj (σ Q₁) (σ Q₂)) := by obtain ⟨⟨Q, hQ₁, hQ₂⟩, hQ₃⟩ := hP have (Q' : Ideal.primesOver P S) : ∃ σ : G, Q'.1 = σ • Q := Algebra.IsInvariant.exists_smul_of_under_eq R S G _ _ (hQ₂.over.symm.trans Q'.2.2.over) choose τ hτ using this obtain ⟨σ, hσ⟩ := exists_of_isInvariant R G Q refine ⟨fun Q' ↦ τ Q' * σ * (τ Q')⁻¹, fun Q' ↦ hτ Q' ▸ hσ.conj (τ Q'), fun Q₁ Q₂ ↦ .trans (.symm (isConj_iff.mpr ⟨τ Q₁, rfl⟩)) (isConj_iff.mpr ⟨τ Q₂, rfl⟩)⟩ variable (R G Q) /-- Let `G` be a finite group acting on `S`, `R` be the fixed subring, and `Q` be a prime of `S` with finite residue field. This is an arbitrary choice of a Frobenius over `Q`. It is chosen so that the Frobenius elements of `Q₁` and `Q₂` are conjugate if they lie over the same prime. -/ noncomputable def _root_.arithFrobAt [Q.IsPrime] [Finite (S ⧸ Q)] : G := (exists_primesOver_isConj S G (Q.under R) ⟨⟨Q, ‹_›, ⟨rfl⟩⟩, ‹Finite (S ⧸ Q)›⟩).choose ⟨Q, ‹_›, ⟨rfl⟩⟩ protected lemma arithFrobAt [Q.IsPrime] [Finite (S ⧸ Q)] : IsArithFrobAt R (arithFrobAt R G Q) Q := (exists_primesOver_isConj S G (Q.under R) ⟨⟨Q, ‹_›, ⟨rfl⟩⟩, ‹Finite (S ⧸ Q)›⟩).choose_spec.1 ⟨Q, ‹_›, ⟨rfl⟩⟩ lemma _root_.isConj_arithFrobAt [Q.IsPrime] [Finite (S ⧸ Q)] (Q' : Ideal S) [Q'.IsPrime] [Finite (S ⧸ Q')] (H : Q.under R = Q'.under R) : IsConj (arithFrobAt R G Q) (arithFrobAt R G Q') := by obtain ⟨P, hP, h₁, h₂⟩ : ∃ P : Ideal R, P.IsPrime ∧ P = Q.under R ∧ P = Q'.under R := ⟨Q.under R, inferInstance, rfl, H⟩ convert (exists_primesOver_isConj S G P ⟨⟨Q, ‹_›, ⟨h₁⟩⟩, ‹Finite (S ⧸ Q)›⟩).choose_spec.2 ⟨Q, ‹_›, ⟨h₁⟩⟩ ⟨Q', ‹_›, ⟨h₂⟩⟩ · subst h₁; rfl · subst h₂; rfl end IsArithFrobAt
DirectSum.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.DirectSum.Module import Mathlib.Algebra.Lie.OfAssociative import Mathlib.Algebra.Lie.Ideal import Mathlib.Algebra.Lie.Basic /-! # Direct sums of Lie algebras and Lie modules Direct sums of Lie algebras and Lie modules carry natural algebra and module structures. ## Tags lie algebra, lie module, direct sum -/ universe u v w w₁ namespace DirectSum open DFinsupp open scoped DirectSum variable {R : Type u} {ι : Type v} [CommRing R] section Modules /-! The direct sum of Lie modules over a fixed Lie algebra carries a natural Lie module structure. -/ variable {L : Type w₁} {M : ι → Type w} variable [LieRing L] [LieAlgebra R L] variable [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] variable [∀ i, LieRingModule L (M i)] [∀ i, LieModule R L (M i)] instance : LieRingModule L (⨁ i, M i) where bracket x m := m.mapRange (fun _ m' => ⁅x, m'⁆) fun _ => lie_zero x add_lie x y m := by ext simp only [mapRange_apply, add_apply, add_lie] lie_add x m n := by ext simp only [mapRange_apply, add_apply, lie_add] leibniz_lie x y m := by ext simp only [mapRange_apply, lie_lie, add_apply, sub_add_cancel] @[simp] theorem lie_module_bracket_apply (x : L) (m : ⨁ i, M i) (i : ι) : ⁅x, m⁆ i = ⁅x, m i⁆ := mapRange_apply _ _ m i instance : LieModule R L (⨁ i, M i) where smul_lie t x m := by ext simp only [smul_lie, lie_module_bracket_apply, smul_apply] lie_smul t x m := by ext simp only [lie_smul, lie_module_bracket_apply, smul_apply] variable (R ι L M) /-- The inclusion of each component into a direct sum as a morphism of Lie modules. -/ def lieModuleOf [DecidableEq ι] (j : ι) : M j →ₗ⁅R,L⁆ ⨁ i, M i := { lof R ι M j with map_lie' := fun {x m} => by ext i by_cases h : j = i · rw [← h]; simp · -- This used to be the end of the proof before https://github.com/leanprover/lean4/pull/2644 -- old proof `simp [lof, lsingle, h]` simp only [lof, lsingle, AddHom.toFun_eq_coe, lie_module_bracket_apply] -- The coercion in the goal is `DFunLike.coe (β := fun x ↦ Π₀ (i : ι), M i)` -- but the lemma is expecting `DFunLike.coe (β := fun x ↦ ⨁ (i : ι), M i)` erw [AddHom.coe_mk] simp [h] } /-- The projection map onto one component, as a morphism of Lie modules. -/ def lieModuleComponent (j : ι) : (⨁ i, M i) →ₗ⁅R,L⁆ M j := { component R ι M j with map_lie' := fun {x m} => by simp [component, lapply] } end Modules section Algebras /-! The direct sum of Lie algebras carries a natural Lie algebra structure. -/ variable (L : ι → Type w) variable [∀ i, LieRing (L i)] [∀ i, LieAlgebra R (L i)] instance lieRing : LieRing (⨁ i, L i) := { (inferInstance : AddCommGroup _) with bracket := zipWith (fun _ => fun x y => ⁅x, y⁆) fun _ => lie_zero 0 add_lie := fun x y z => by ext simp only [zipWith_apply, add_apply, add_lie] lie_add := fun x y z => by ext simp only [zipWith_apply, add_apply, lie_add] lie_self := fun x => by ext simp only [zipWith_apply, lie_self, zero_apply] leibniz_lie := fun x y z => by ext simp only [zipWith_apply, add_apply] apply leibniz_lie } @[simp] theorem bracket_apply (x y : ⨁ i, L i) (i : ι) : ⁅x, y⁆ i = ⁅x i, y i⁆ := zipWith_apply _ _ x y i theorem lie_of_same [DecidableEq ι] {i : ι} (x y : L i) : ⁅of L i x, of L i y⁆ = of L i ⁅x, y⁆ := DFinsupp.zipWith_single_single _ _ _ _ theorem lie_of_of_ne [DecidableEq ι] {i j : ι} (hij : i ≠ j) (x : L i) (y : L j) : ⁅of L i x, of L j y⁆ = 0 := by ext k rw [bracket_apply] obtain rfl | hik := Decidable.eq_or_ne i k · rw [of_eq_of_ne _ _ _ hij.symm, lie_zero, zero_apply] · rw [of_eq_of_ne _ _ _ hik, zero_lie, zero_apply] @[simp] theorem lie_of [DecidableEq ι] {i j : ι} (x : L i) (y : L j) : ⁅of L i x, of L j y⁆ = if hij : i = j then of L i ⁅x, hij.symm.recOn y⁆ else 0 := by obtain rfl | hij := Decidable.eq_or_ne i j · simp only [lie_of_same L x y, dif_pos] · simp only [lie_of_of_ne L hij x y, hij, dite_false] instance lieAlgebra : LieAlgebra R (⨁ i, L i) := { (inferInstance : Module R _) with lie_smul := fun c x y => by ext simp only [smul_apply, bracket_apply, lie_smul] } variable (R ι) /-- The inclusion of each component into the direct sum as morphism of Lie algebras. -/ @[simps] def lieAlgebraOf [DecidableEq ι] (j : ι) : L j →ₗ⁅R⁆ ⨁ i, L i := { lof R ι L j with toFun := of L j map_lie' := fun {x y} => (lie_of_same L x y).symm } /-- The projection map onto one component, as a morphism of Lie algebras. -/ @[simps] def lieAlgebraComponent (j : ι) : (⨁ i, L i) →ₗ⁅R⁆ L j := { component R ι L j with toFun := component R ι L j map_lie' := fun {x y} => by simp [component, lapply] } -- Note(kmill): `ext` cannot generate an iff theorem here since `x` and `y` do not determine `R`. @[ext (iff := false)] theorem lieAlgebra_ext {x y : ⨁ i, L i} (h : ∀ i, lieAlgebraComponent R ι L i x = lieAlgebraComponent R ι L i y) : x = y := DFinsupp.ext h variable {R L ι} /-- Given a family of Lie algebras `L i`, together with a family of morphisms of Lie algebras `f i : L i →ₗ⁅R⁆ L'` into a fixed Lie algebra `L'`, we have a natural linear map: `(⨁ i, L i) →ₗ[R] L'`. If in addition `⁅f i x, f j y⁆ = 0` for any `x ∈ L i` and `y ∈ L j` (`i ≠ j`) then this map is a morphism of Lie algebras. -/ @[simps] def toLieAlgebra [DecidableEq ι] (L' : Type w₁) [LieRing L'] [LieAlgebra R L'] (f : ∀ i, L i →ₗ⁅R⁆ L') (hf : Pairwise fun i j => ∀ (x : L i) (y : L j), ⁅f i x, f j y⁆ = 0) : (⨁ i, L i) →ₗ⁅R⁆ L' := { toModule R ι L' fun i => (f i : L i →ₗ[R] L') with toFun := toModule R ι L' fun i => (f i : L i →ₗ[R] L') map_lie' := fun {x y} => by let f' i := (f i : L i →ₗ[R] L') /- The goal is linear in `y`. We can use this to reduce to the case that `y` has only one non-zero component. -/ suffices ∀ (i : ι) (y : L i), toModule R ι L' f' ⁅x, of L i y⁆ = ⁅toModule R ι L' f' x, toModule R ι L' f' (of L i y)⁆ by simp only [← LieAlgebra.ad_apply R] rw [← LinearMap.comp_apply, ← LinearMap.comp_apply] congr; clear y; ext i y; exact this i y -- Similarly, we can reduce to the case that `x` has only one non-zero component. suffices ∀ (i j) (y : L i) (x : L j), toModule R ι L' f' ⁅of L j x, of L i y⁆ = ⁅toModule R ι L' f' (of L j x), toModule R ι L' f' (of L i y)⁆ by intro i y rw [← lie_skew x, ← lie_skew (toModule R ι L' f' x)] simp only [LinearMap.map_neg, neg_inj, ← LieAlgebra.ad_apply R] rw [← LinearMap.comp_apply, ← LinearMap.comp_apply] congr; clear x; ext j x; exact this j i x y intro i j y x simp only [f', coe_toModule_eq_coe_toAddMonoid, toAddMonoid_of] -- And finish with trivial case analysis. obtain rfl | hij := Decidable.eq_or_ne i j · simp_rw [lie_of_same, toAddMonoid_of, LinearMap.toAddMonoidHom_coe, LieHom.coe_toLinearMap, LieHom.map_lie] · simp_rw [lie_of_of_ne _ hij.symm, map_zero, LinearMap.toAddMonoidHom_coe, LieHom.coe_toLinearMap, hf hij.symm x y] } end Algebras section Ideals variable {L : Type w} [LieRing L] [LieAlgebra R L] (I : ι → LieIdeal R L) /-- The fact that this instance is necessary seems to be a bug in typeclass inference. See [this Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/ Typeclass.20resolution.20under.20binders/near/245151099). -/ instance lieRingOfIdeals : LieRing (⨁ i, I i) := DirectSum.lieRing fun i => ↥(I i) /-- See `DirectSum.lieRingOfIdeals` comment. -/ instance lieAlgebraOfIdeals : LieAlgebra R (⨁ i, I i) := DirectSum.lieAlgebra fun i => ↥(I i) end Ideals end DirectSum
commutator.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat fintype. From mathcomp Require Import bigop finset binomial fingroup morphism. From mathcomp Require Import automorphism quotient gfunctor. (******************************************************************************) (* This files contains the proofs of several key properties of commutators, *) (* including the Hall-Witt identity and the Three Subgroup Lemma. *) (* The definition and notation for both pointwise and set wise commutators *) (* ([~x, y, ...] and [~: A, B ,...], respectively) are given in fingroup.v *) (* This file defines the derived group series: *) (* G^`(0) == G *) (* G^`(n.+1) == [~: G^`(n), G^`(n)] *) (* as several classical results involve the (first) derived group G^`(1), *) (* such as the equivalence H <| G /\ G / H abelian <-> G^`(1) \subset H. *) (* The connection between the derived series and solvable groups will only be *) (* established in nilpotent.v, however. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Definition derived_at n (gT : finGroupType) (A : {set gT}) := iter n (fun B => [~: B, B]) A. Arguments derived_at n%_N {gT} A%_g : simpl never. Notation "G ^` ( n )" := (derived_at n G) : group_scope. Section DerivedBasics. Variables gT : finGroupType. Implicit Type A : {set gT}. Implicit Types G : {group gT}. Lemma derg0 A : A^`(0) = A. Proof. by []. Qed. Lemma derg1 A : A^`(1) = [~: A, A]. Proof. by []. Qed. Lemma dergSn n A : A^`(n.+1) = [~: A^`(n), A^`(n)]. Proof. by []. Qed. Lemma der_group_set G n : group_set G^`(n). Proof. by case: n => [|n]; apply: groupP. Qed. Canonical derived_at_group G n := Group (der_group_set G n). End DerivedBasics. Notation "G ^` ( n )" := (derived_at_group G n) : Group_scope. Section Basic_commutator_properties. Variable gT : finGroupType. Implicit Types x y z : gT. Lemma conjg_mulR x y : x ^ y = x * [~ x, y]. Proof. by rewrite mulKVg. Qed. Lemma conjg_Rmul x y : x ^ y = [~ y, x^-1] * x. Proof. by rewrite commgEr invgK mulgKV. Qed. Lemma commMgJ x y z : [~ x * y, z] = [~ x, z] ^ y * [~ y, z]. Proof. by rewrite !commgEr conjgM mulgA -conjMg mulgK. Qed. Lemma commgMJ x y z : [~ x, y * z] = [~ x, z] * [~ x, y] ^ z. Proof. by rewrite !commgEl conjgM -mulgA -conjMg mulKVg. Qed. Lemma commMgR x y z : [~ x * y, z] = [~ x, z] * [~ x, z, y] * [~ y, z]. Proof. by rewrite commMgJ conjg_mulR. Qed. Lemma commgMR x y z : [~ x, y * z] = [~ x, z] * [~ x, y] * [~ x, y, z]. Proof. by rewrite commgMJ conjg_mulR mulgA. Qed. Lemma Hall_Witt_identity x y z : [~ x, y^-1, z] ^ y * [~ y, z^-1, x] ^ z * [~ z, x^-1, y] ^ x = 1. Proof. (* gsimpl *) pose a x y z : gT := x * z * y ^ x. suffices{x y z} hw_aux x y z: [~ x, y^-1, z] ^ y = (a x y z)^-1 * (a y z x). by rewrite !hw_aux 2!mulgA !mulgK mulVg. by rewrite commgEr conjMg -conjgM -conjg_Rmul 2!invMg conjgE !mulgA. Qed. (* the following properties are useful for studying p-groups of class 2 *) Section LeftComm. Variables (i : nat) (x y : gT). Hypothesis cxz : commute x [~ x, y]. Lemma commVg : [~ x^-1, y] = [~ x, y]^-1. Proof. apply/eqP; rewrite commgEl eq_sym eq_invg_mul invgK mulgA -cxz. by rewrite -conjg_mulR -conjMg mulgV conj1g. Qed. Lemma commXg : [~ x ^+ i, y] = [~ x, y] ^+ i. Proof. elim: i => [|i' IHi]; first exact: comm1g. by rewrite !expgS commMgJ /conjg commuteX // mulKg IHi. Qed. End LeftComm. Section RightComm. Variables (i : nat) (x y : gT). Hypothesis cyz : commute y [~ x, y]. Let cyz' := commuteV cyz. Lemma commgV : [~ x, y^-1] = [~ x, y]^-1. Proof. by rewrite -invg_comm commVg -(invg_comm x y) ?invgK. Qed. Lemma commgX : [~ x, y ^+ i] = [~ x, y] ^+ i. Proof. by rewrite -invg_comm commXg -(invg_comm x y) ?expgVn ?invgK. Qed. End RightComm. Section LeftRightComm. Variables (i j : nat) (x y : gT). Hypotheses (cxz : commute x [~ x, y]) (cyz : commute y [~ x, y]). Lemma commXXg : [~ x ^+ i, y ^+ j] = [~ x, y] ^+ (i * j). Proof. by rewrite expgM commgX commXg //; apply: commuteX. Qed. Lemma expMg_Rmul : (y * x) ^+ i = y ^+ i * x ^+ i * [~ x, y] ^+ 'C(i, 2). Proof. rewrite -bin2_sum; symmetry. elim: i => [|k IHk] /=; first by rewrite big_geq ?mulg1. rewrite big_nat_recr //= addnC expgD !expgS -{}IHk !mulgA; congr (_ * _). by rewrite -!mulgA commuteX2 // -commgX // [mulg y]lock 3!mulgA -commgC. Qed. End LeftRightComm. End Basic_commutator_properties. (***** Set theoretic commutators *****) Section Commutator_properties. Variable gT : finGroupType. Implicit Type (rT : finGroupType) (A B C : {set gT}) (D G H K : {group gT}). Lemma commG1 A : [~: A, 1] = 1. Proof. by apply/commG1P; rewrite centsC sub1G. Qed. Lemma comm1G A : [~: 1, A] = 1. Proof. by rewrite commGC commG1. Qed. Lemma commg_sub A B : [~: A, B] \subset A <*> B. Proof. by rewrite comm_subG // (joing_subl, joing_subr). Qed. Lemma commg_norml G A : G \subset 'N([~: G, A]). Proof. apply/subsetP=> x Gx; rewrite inE -genJ gen_subG. apply/subsetP=> _ /imsetP[_ /imset2P[y z Gy Az ->] ->]. by rewrite -(mulgK [~ x, z] (_ ^ x)) -commMgJ !(mem_commg, groupMl, groupV). Qed. Lemma commg_normr G A : G \subset 'N([~: A, G]). Proof. by rewrite commGC commg_norml. Qed. Lemma commg_norm G H : G <*> H \subset 'N([~: G, H]). Proof. by rewrite join_subG ?commg_norml ?commg_normr. Qed. Lemma commg_normal G H : [~: G, H] <| G <*> H. Proof. by rewrite /(_ <| _) commg_sub commg_norm. Qed. Lemma normsRl A G B : A \subset G -> A \subset 'N([~: G, B]). Proof. by move=> sAG; apply: subset_trans (commg_norml G B). Qed. Lemma normsRr A G B : A \subset G -> A \subset 'N([~: B, G]). Proof. by move=> sAG; apply: subset_trans (commg_normr G B). Qed. Lemma commg_subr G H : ([~: G, H] \subset H) = (G \subset 'N(H)). Proof. rewrite gen_subG; apply/subsetP/subsetP=> [sRH x Gx | nGH xy]. rewrite inE; apply/subsetP=> _ /imsetP[y Ky ->]. by rewrite conjg_Rmul groupMr // sRH // imset2_f ?groupV. case/imset2P=> x y Gx Hy ->{xy}. by rewrite commgEr groupMr // memJ_norm (groupV, nGH). Qed. Lemma commg_subl G H : ([~: G, H] \subset G) = (H \subset 'N(G)). Proof. by rewrite commGC commg_subr. Qed. Lemma commg_subI A B G H : A \subset 'N_G(H) -> B \subset 'N_H(G) -> [~: A, B] \subset G :&: H. Proof. rewrite !subsetI -(gen_subG _ 'N(G)) -(gen_subG _ 'N(H)). rewrite -commg_subr -commg_subl; case/andP=> sAG sRH; case/andP=> sBH sRG. by rewrite (subset_trans _ sRG) ?(subset_trans _ sRH) ?commgSS ?subset_gen. Qed. Lemma quotient_cents2 A B K : A \subset 'N(K) -> B \subset 'N(K) -> (A / K \subset 'C(B / K)) = ([~: A, B] \subset K). Proof. move=> nKA nKB. by rewrite (sameP commG1P trivgP) /= -quotientR // quotient_sub1 // comm_subG. Qed. Lemma quotient_cents2r A B K : [~: A, B] \subset K -> (A / K) \subset 'C(B / K). Proof. move=> sABK; rewrite -2![_ / _]morphimIdom -!quotientE. by rewrite quotient_cents2 ?subsetIl ?(subset_trans _ sABK) ?commgSS ?subsetIr. Qed. Lemma sub_der1_norm G H : G^`(1) \subset H -> H \subset G -> G \subset 'N(H). Proof. by move=> sG'H sHG; rewrite -commg_subr (subset_trans _ sG'H) ?commgS. Qed. Lemma sub_der1_normal G H : G^`(1) \subset H -> H \subset G -> H <| G. Proof. by move=> sG'H sHG; rewrite /(H <| G) sHG sub_der1_norm. Qed. Lemma sub_der1_abelian G H : G^`(1) \subset H -> abelian (G / H). Proof. by move=> sG'H; apply: quotient_cents2r. Qed. Lemma der1_min G H : G \subset 'N(H) -> abelian (G / H) -> G^`(1) \subset H. Proof. by move=> nHG abGH; rewrite -quotient_cents2. Qed. Lemma der_abelian n G : abelian (G^`(n) / G^`(n.+1)). Proof. by rewrite sub_der1_abelian // der_subS. Qed. Lemma commg_normSl G H K : G \subset 'N(H) -> [~: G, H] \subset 'N([~: K, H]). Proof. by move=> nHG; rewrite normsRr // commg_subr. Qed. Lemma commg_normSr G H K : G \subset 'N(H) -> [~: H, G] \subset 'N([~: H, K]). Proof. by move=> nHG; rewrite !(commGC H) commg_normSl. Qed. Lemma commMGr G H K : [~: G, K] * [~: H, K] \subset [~: G * H , K]. Proof. by rewrite mul_subG ?commSg ?(mulG_subl, mulG_subr). Qed. Lemma commMG G H K : H \subset 'N([~: G, K]) -> [~: G * H , K] = [~: G, K] * [~: H, K]. Proof. move=> nRH; apply/eqP; rewrite eqEsubset commMGr andbT. have nRHK: [~: H, K] \subset 'N([~: G, K]) by rewrite comm_subG ?commg_normr. have defM := norm_joinEr nRHK; rewrite -defM gen_subG /=. apply/subsetP=> _ /imset2P[_ z /imset2P[x y Gx Hy ->] Kz ->]. by rewrite commMgJ {}defM mem_mulg ?memJ_norm ?mem_commg // (subsetP nRH). Qed. Lemma comm3G1P A B C : reflect {in A & B & C, forall h k l, [~ h, k, l] = 1} ([~: A, B, C] :==: 1). Proof. have R_C := sameP trivgP commG1P. rewrite -subG1 R_C gen_subG -{}R_C gen_subG. apply: (iffP subsetP) => [cABC x y z Ax By Cz | cABC xyz]. by apply/set1P; rewrite cABC // !imset2_f. by case/imset2P=> _ z /imset2P[x y Ax By ->] Cz ->; rewrite cABC. Qed. Lemma three_subgroup G H K : [~: G, H, K] :=: 1 -> [~: H, K, G] :=: 1-> [~: K, G, H] :=: 1. Proof. move/eqP/comm3G1P=> cGHK /eqP/comm3G1P cHKG. apply/eqP/comm3G1P=> x y z Kx Gy Hz; symmetry. rewrite -(conj1g y) -(Hall_Witt_identity y^-1 z x) invgK. by rewrite cGHK ?groupV // cHKG ?groupV // !conj1g !mul1g conjgKV. Qed. Lemma der1_joing_cycles (x y : gT) : let XY := <[x]> <*> <[y]> in let xy := [~ x, y] in xy \in 'C(XY) -> XY^`(1) = <[xy]>. Proof. rewrite joing_idl joing_idr /= -sub_cent1 => /norms_gen nRxy. apply/eqP; rewrite eqEsubset cycle_subG mem_commg ?mem_gen ?set21 ?set22 //. rewrite der1_min // quotient_gen -1?gen_subG // quotientU abelian_gen. rewrite /abelian subUset centU !subsetI andbC centsC -andbA -!abelianE. rewrite !quotient_abelian ?(abelianS (subset_gen _) (cycle_abelian _)) //=. by rewrite andbb quotient_cents2r ?genS // /commg_set imset2_set1l imset_set1. Qed. Lemma commgAC G x y z : x \in G -> y \in G -> z \in G -> commute y z -> abelian [~: [set x], G] -> [~ x, y, z] = [~ x, z, y]. Proof. move=> Gx Gy Gz cyz /centsP cRxG; pose cx' u := [~ x^-1, u]. have xR3 u v: [~ x, u, v] = x^-1 * (cx' u * cx' v) * x ^ (u * v). rewrite mulgA -conjg_mulR conjVg [cx' v]commgEl mulgA -invMg. by rewrite -mulgA conjgM -conjMg -!commgEl. suffices RxGcx' u: u \in G -> cx' u \in [~: [set x], G]. by rewrite !xR3 {}cyz; congr (_ * _ * _); rewrite cRxG ?RxGcx'. move=> Gu; suffices/groupMl <-: [~ x, u] ^ x^-1 \in [~: [set x], G]. by rewrite -commMgJ mulgV comm1g group1. by rewrite memJ_norm ?mem_commg ?set11 // groupV (subsetP (commg_normr _ _)). Qed. (* Aschbacher, exercise 3.6 (used in proofs of Aschbacher 24.7 and B & G 1.10 *) Lemma comm_norm_cent_cent H G K : H \subset 'N(G) -> H \subset 'C(K) -> G \subset 'N(K) -> [~: G, H] \subset 'C(K). Proof. move=> nGH /centsP cKH nKG; rewrite commGC gen_subG centsC. apply/centsP=> x Kx _ /imset2P[y z Hy Gz ->]; red. rewrite mulgA -[x * _]cKH ?groupV // -!mulgA; congr (_ * _). rewrite (mulgA x) (conjgC x) (conjgCV z) 3!mulgA; congr (_ * _). by rewrite -2!mulgA (cKH y) // -mem_conjg (normsP nKG). Qed. Lemma charR H K G : H \char G -> K \char G -> [~: H, K] \char G. Proof. case/charP=> sHG chH /charP[sKG chK]; apply/charP. by split=> [|f infj Gf]; [rewrite comm_subG | rewrite morphimR // chH // chK]. Qed. Lemma der_char n G : G^`(n) \char G. Proof. by elim: n => [|n IHn]; rewrite ?char_refl // dergSn charR. Qed. Lemma der_sub n G : G^`(n) \subset G. Proof. by rewrite char_sub ?der_char. Qed. Lemma der_norm n G : G \subset 'N(G^`(n)). Proof. by rewrite char_norm ?der_char. Qed. Lemma der_normal n G : G^`(n) <| G. Proof. by rewrite char_normal ?der_char. Qed. Lemma der_subS n G : G^`(n.+1) \subset G^`(n). Proof. by rewrite comm_subG. Qed. Lemma der_normalS n G : G^`(n.+1) <| G^`(n). Proof. by rewrite sub_der1_normal // der_subS. Qed. Lemma morphim_der rT D (f : {morphism D >-> rT}) n G : G \subset D -> f @* G^`(n) = (f @* G)^`(n). Proof. move=> sGD; elim: n => // n IHn. by rewrite !dergSn -IHn morphimR ?(subset_trans (der_sub n G)). Qed. Lemma dergS n G H : G \subset H -> G^`(n) \subset H^`(n). Proof. by move=> sGH; elim: n => // n IHn; apply: commgSS. Qed. Lemma quotient_der n G H : G \subset 'N(H) -> G^`(n) / H = (G / H)^`(n). Proof. exact: morphim_der. Qed. Lemma derJ G n x : (G :^ x)^`(n) = G^`(n) :^ x. Proof. by elim: n => //= n IHn; rewrite !dergSn IHn -conjsRg. Qed. Lemma derG1P G : reflect (G^`(1) = 1) (abelian G). Proof. exact: commG1P. Qed. End Commutator_properties. Arguments derG1P {gT G}. Lemma der_cont n : GFunctor.continuous (@derived_at n). Proof. by move=> aT rT G f; rewrite morphim_der. Qed. Canonical der_igFun n := [igFun by der_sub^~ n & der_cont n]. Canonical der_gFun n := [gFun by der_cont n]. Canonical der_mgFun n := [mgFun by dergS^~ n]. Lemma isog_der (aT rT : finGroupType) n (G : {group aT}) (H : {group rT}) : G \isog H -> G^`(n) \isog H^`(n). Proof. exact: gFisog. Qed.
Lattice.lean
/- Copyright (c) 2024 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang -/ import Mathlib.RingTheory.TwoSidedIdeal.Basic /-! # The complete lattice structure on two-sided ideals -/ namespace TwoSidedIdeal variable (R : Type*) [NonUnitalNonAssocRing R] instance : SemilatticeSup (TwoSidedIdeal R) where sup I J := { ringCon := I.ringCon ⊔ J.ringCon } le_sup_left I J := by rw [ringCon_le_iff]; exact le_sup_left le_sup_right I J := by rw [ringCon_le_iff]; exact le_sup_right sup_le I J K h1 h2 := by rw [ringCon_le_iff] at h1 h2 ⊢; exact sup_le h1 h2 lemma sup_ringCon (I J : TwoSidedIdeal R) : (I ⊔ J).ringCon = I.ringCon ⊔ J.ringCon := rfl section sup variable {R} lemma mem_sup_left {I J : TwoSidedIdeal R} {x : R} (h : x ∈ I) : x ∈ I ⊔ J := (show I ≤ I ⊔ J from le_sup_left) h lemma mem_sup_right {I J : TwoSidedIdeal R} {x : R} (h : x ∈ J) : x ∈ I ⊔ J := (show J ≤ I ⊔ J from le_sup_right) h lemma mem_sup {I J : TwoSidedIdeal R} {x : R} : x ∈ I ⊔ J ↔ ∃ y ∈ I, ∃ z ∈ J, y + z = x := by constructor · let s : TwoSidedIdeal R := .mk' {x | ∃ y ∈ I, ∃ z ∈ J, y + z = x} ⟨0, ⟨zero_mem _, ⟨0, ⟨zero_mem _, zero_add _⟩⟩⟩⟩ (by rintro _ _ ⟨x, ⟨hx, ⟨y, ⟨hy, rfl⟩⟩⟩⟩ ⟨a, ⟨ha, ⟨b, ⟨hb, rfl⟩⟩⟩⟩; exact ⟨x + a, ⟨add_mem _ hx ha, ⟨y + b, ⟨add_mem _ hy hb, by abel⟩⟩⟩⟩) (by rintro _ ⟨x, ⟨hx, ⟨y, ⟨hy, rfl⟩⟩⟩⟩ exact ⟨-x, ⟨neg_mem _ hx, ⟨-y, ⟨neg_mem _ hy, by abel⟩⟩⟩⟩) (by rintro r _ ⟨x, ⟨hx, ⟨y, ⟨hy, rfl⟩⟩⟩⟩ exact ⟨_, ⟨mul_mem_left _ _ _ hx, ⟨_, ⟨mul_mem_left _ _ _ hy, mul_add _ _ _ |>.symm⟩⟩⟩⟩) (by rintro r _ ⟨x, ⟨hx, ⟨y, ⟨hy, rfl⟩⟩⟩⟩ exact ⟨_, ⟨mul_mem_right _ _ _ hx, ⟨_, ⟨mul_mem_right _ _ _ hy, add_mul _ _ _ |>.symm⟩⟩⟩⟩) suffices (I.ringCon ⊔ J.ringCon) ≤ s.ringCon by intro h; convert this h; rw [rel_iff, sub_zero, mem_mk']; rfl refine sup_le (fun x y h => ?_) (fun x y h => ?_) <;> rw [rel_iff] at h ⊢ <;> rw [mem_mk'] exacts [⟨_, ⟨h, ⟨0, ⟨zero_mem _, add_zero _⟩⟩⟩⟩, ⟨0, ⟨zero_mem _, ⟨_, ⟨h, zero_add _⟩⟩⟩⟩] · rintro ⟨y, ⟨hy, ⟨z, ⟨hz, rfl⟩⟩⟩⟩; exact add_mem _ (mem_sup_left hy) (mem_sup_right hz) end sup instance : SemilatticeInf (TwoSidedIdeal R) where inf I J := { ringCon := I.ringCon ⊓ J.ringCon } inf_le_left I J := by rw [ringCon_le_iff]; exact inf_le_left inf_le_right I J := by rw [ringCon_le_iff]; exact inf_le_right le_inf I J K h1 h2 := by rw [ringCon_le_iff] at h1 h2 ⊢; exact le_inf h1 h2 lemma inf_ringCon (I J : TwoSidedIdeal R) : (I ⊓ J).ringCon = I.ringCon ⊓ J.ringCon := rfl lemma mem_inf {I J : TwoSidedIdeal R} {x : R} : x ∈ I ⊓ J ↔ x ∈ I ∧ x ∈ J := Iff.rfl instance : SupSet (TwoSidedIdeal R) where sSup s := { ringCon := sSup <| TwoSidedIdeal.ringCon '' s } lemma sSup_ringCon (S : Set (TwoSidedIdeal R)) : (sSup S).ringCon = sSup (TwoSidedIdeal.ringCon '' S) := rfl lemma iSup_ringCon {ι : Type*} (I : ι → TwoSidedIdeal R) : (⨆ i, I i).ringCon = ⨆ i, (I i).ringCon := by simp only [iSup, sSup_ringCon]; congr; ext; simp instance : CompleteSemilatticeSup (TwoSidedIdeal R) where sSup_le s I h := by simp_rw [ringCon_le_iff] at h ⊢; exact sSup_le <| by aesop le_sSup s I hI := by rw [ringCon_le_iff]; exact le_sSup <| by aesop instance : InfSet (TwoSidedIdeal R) where sInf s := { ringCon := sInf <| TwoSidedIdeal.ringCon '' s } lemma sInf_ringCon (S : Set (TwoSidedIdeal R)) : (sInf S).ringCon = sInf (TwoSidedIdeal.ringCon '' S) := rfl lemma iInf_ringCon {ι : Type*} (I : ι → TwoSidedIdeal R) : (⨅ i, I i).ringCon = ⨅ i, (I i).ringCon := by simp only [iInf, sInf_ringCon]; congr!; ext; simp instance : CompleteSemilatticeInf (TwoSidedIdeal R) where le_sInf s I h := by simp_rw [ringCon_le_iff] at h ⊢; exact le_sInf <| by aesop sInf_le s I hI := by rw [ringCon_le_iff]; exact sInf_le <| by aesop lemma mem_iInf {ι : Type*} {I : ι → TwoSidedIdeal R} {x : R} : x ∈ iInf I ↔ ∀ i, x ∈ I i := show (∀ _, _) ↔ _ by simp [mem_iff] lemma mem_sInf {S : Set (TwoSidedIdeal R)} {x : R} : x ∈ sInf S ↔ ∀ I ∈ S, x ∈ I := show (∀ _, _) ↔ _ by simp [mem_iff] instance : Top (TwoSidedIdeal R) where top := { ringCon := ⊤ } lemma top_ringCon : (⊤ : TwoSidedIdeal R).ringCon = ⊤ := rfl @[simp] lemma mem_top {x : R} : x ∈ (⊤: TwoSidedIdeal R) := trivial instance : Bot (TwoSidedIdeal R) where bot := { ringCon := ⊥ } lemma bot_ringCon : (⊥ : TwoSidedIdeal R).ringCon = ⊥ := rfl @[simp] lemma mem_bot {x : R} : x ∈ (⊥ : TwoSidedIdeal R) ↔ x = 0 := Iff.rfl instance : CompleteLattice (TwoSidedIdeal R) where __ := (inferInstance : SemilatticeSup (TwoSidedIdeal R)) __ := (inferInstance : SemilatticeInf (TwoSidedIdeal R)) __ := (inferInstance : CompleteSemilatticeSup (TwoSidedIdeal R)) __ := (inferInstance : CompleteSemilatticeInf (TwoSidedIdeal R)) le_top _ := by rw [ringCon_le_iff]; exact le_top bot_le _ := by rw [ringCon_le_iff]; exact bot_le @[simp] lemma coe_bot : ((⊥ : TwoSidedIdeal R) : Set R) = {0} := rfl @[simp] lemma coe_top : ((⊤ : TwoSidedIdeal R) : Set R) = Set.univ := rfl lemma one_mem_iff {R : Type*} [NonAssocRing R] (I : TwoSidedIdeal R) : (1 : R) ∈ I ↔ I = ⊤ := ⟨fun h => eq_top_iff.2 fun x _ => by simpa using I.mul_mem_left x _ h, fun h ↦ h.symm ▸ trivial⟩ alias ⟨eq_top, one_mem⟩ := one_mem_iff end TwoSidedIdeal
separable.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 tuple finfun bigop finset prime. From mathcomp Require Import binomial ssralg poly polydiv fingroup perm. From mathcomp Require Import morphism quotient gproduct finalg zmodp cyclic. From mathcomp Require Import matrix mxalgebra mxpoly polyXY vector falgebra. From mathcomp Require Import fieldext. (******************************************************************************) (* This file provides a theory of separable and inseparable field extensions. *) (* *) (* separable_poly p <=> p has no multiple roots in any field extension. *) (* separable_element K x <=> the minimal polynomial of x over K is separable. *) (* separable K E <=> every member of E is separable over K. *) (* separable_generator K E == some x \in E that generates the largest *) (* subfield K[x] that is separable over K. *) (* purely_inseparable_element K x <=> there is a [pchar L].-nat n such that *) (* x ^+ n \in K. *) (* purely_inseparable K E <=> every member of E is purely inseparable over K. *) (* *) (* Derivations are introduced to prove the adjoin_separableP Lemma: *) (* Derivation K D <=> the linear operator D satisfies the Leibniz *) (* product rule inside K. *) (* extendDerivation x D K == given a derivation D on K and a separable *) (* element x over K, this function returns the *) (* unique extension of D to K(x). *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Import GRing.Theory. HB.lock Definition separable_poly {R : idomainType} (p : {poly R}) := coprimep p p^`(). Canonical separable_poly_unlockable := Unlockable separable_poly.unlock. Section SeparablePoly. Variable R : idomainType. Implicit Types p q d u v : {poly R}. Local Notation separable := (@separable_poly R). Local Notation lcn_neq0 := (Pdiv.Idomain.lc_expn_scalp_neq0 _). Lemma separable_poly_neq0 p : separable p -> p != 0. Proof. by apply: contraTneq => ->; rewrite unlock deriv0 coprime0p eqp01. Qed. Lemma poly_square_freeP p : (forall u v, u * v %| p -> coprimep u v) <-> (forall u, size u != 1 -> ~~ (u ^+ 2 %| p)). Proof. split=> [sq'p u | sq'p u v dvd_uv_p]. by apply: contra => /sq'p; rewrite coprimepp. rewrite coprimep_def (contraLR (sq'p _)) // (dvdp_trans _ dvd_uv_p) //. by rewrite dvdp_mul ?dvdp_gcdl ?dvdp_gcdr. Qed. Lemma separable_polyP {p} : reflect [/\ forall u v, u * v %| p -> coprimep u v & forall u, u %| p -> 1 < size u -> u^`() != 0] (separable p). Proof. apply: (iffP idP) => [sep_p | [sq'p nz_der1p]]. split=> [u v | u u_dv_p]; last first. apply: contraTneq => u'0; rewrite unlock in sep_p; rewrite -leqNgt -(eqnP sep_p). rewrite dvdp_leq -?size_poly_eq0 ?(eqnP sep_p) // dvdp_gcd u_dv_p. have /dvdpZr <-: lead_coef u ^+ scalp p u != 0 by rewrite lcn_neq0. by rewrite -derivZ -Pdiv.Idomain.divpK //= derivM u'0 mulr0 addr0 dvdp_mull. rewrite Pdiv.Idomain.dvdp_eq mulrCA mulrA; set c := _ ^+ _ => /eqP Dcp. have nz_c: c != 0 by rewrite lcn_neq0. move: sep_p; rewrite coprimep_sym unlock -(coprimepZl _ _ nz_c). rewrite -(coprimepZr _ _ nz_c) -derivZ Dcp derivM coprimepMl. by rewrite coprimep_addl_mul !coprimepMr -andbA => /and4P[]. rewrite unlock coprimep_def eqn_leq size_poly_gt0; set g := gcdp _ _. have nz_g: g != 0. rewrite -dvd0p dvdp_gcd -(mulr0 0); apply/nandP; left. by have /poly_square_freeP-> := sq'p; rewrite ?size_poly0. have [g_p]: g %| p /\ g %| p^`() by rewrite dvdp_gcdr ?dvdp_gcdl. pose c := lead_coef g ^+ scalp p g; have nz_c: c != 0 by rewrite lcn_neq0. have Dcp: c *: p = p %/ g * g by rewrite Pdiv.Idomain.divpK. rewrite nz_g andbT leqNgt -(dvdpZr _ _ nz_c) -derivZ Dcp derivM. rewrite dvdp_addr; last by rewrite dvdp_mull. rewrite Gauss_dvdpr; last by rewrite sq'p // mulrC -Dcp dvdpZl. by apply: contraL => /nz_der1p nz_g'; rewrite gtNdvdp ?nz_g' ?lt_size_deriv. Qed. Lemma separable_coprime p u v : separable p -> u * v %| p -> coprimep u v. Proof. by move=> /separable_polyP[sq'p _] /sq'p. Qed. Lemma separable_nosquare p u k : separable p -> 1 < k -> size u != 1 -> (u ^+ k %| p) = false. Proof. move=> /separable_polyP[/poly_square_freeP sq'p _] /subnKC <- /sq'p. by apply: contraNF; apply: dvdp_trans; rewrite exprD dvdp_mulr. Qed. Lemma separable_deriv_eq0 p u : separable p -> u %| p -> 1 < size u -> (u^`() == 0) = false. Proof. by move=> /separable_polyP[_ nz_der1p] u_p /nz_der1p/negPf->. Qed. Lemma dvdp_separable p q : q %| p -> separable p -> separable q. Proof. move=> /(dvdp_trans _)q_dv_p /separable_polyP[sq'p nz_der1p]. by apply/separable_polyP; split=> [u v /q_dv_p/sq'p | u /q_dv_p/nz_der1p]. Qed. Lemma separable_mul p q : separable (p * q) = [&& separable p, separable q & coprimep p q]. Proof. apply/idP/and3P => [sep_pq | [sep_p sep_q co_pq]]. rewrite !(dvdp_separable _ sep_pq) ?dvdp_mulIr ?dvdp_mulIl //. by rewrite (separable_coprime sep_pq). rewrite unlock in sep_p sep_q *. rewrite derivM coprimepMl {1}addrC mulrC !coprimep_addl_mul. by rewrite !coprimepMr (coprimep_sym q p) co_pq !andbT; apply/andP. Qed. Lemma eqp_separable p q : p %= q -> separable p = separable q. Proof. by case/andP=> p_q q_p; apply/idP/idP=> /dvdp_separable->. Qed. Lemma separable_root p x : separable (p * ('X - x%:P)) = separable p && ~~ root p x. Proof. rewrite separable_mul; apply: andb_id2l => seq_p. by rewrite unlock derivXsubC coprimep1 coprimep_XsubC. Qed. Lemma separable_prod_XsubC (r : seq R) : separable (\prod_(x <- r) ('X - x%:P)) = uniq r. Proof. elim: r => [|x r IH]; first by rewrite big_nil unlock /separable_poly coprime1p. by rewrite big_cons mulrC separable_root IH root_prod_XsubC andbC. Qed. Lemma make_separable p : p != 0 -> separable (p %/ gcdp p p^`()). Proof. set g := gcdp p p^`() => nz_p; apply/separable_polyP. have max_dvd_u (u : {poly R}): 1 < size u -> exists k, ~~ (u ^+ k %| p). move=> u_gt1; exists (size p); rewrite gtNdvdp // polySpred //. by rewrite -(ltn_subRL 1) subn1 size_exp leq_pmull // -(subnKC u_gt1). split=> [|u u_pg u_gt1]; last first. apply/eqP=> u'0 /=; have [k /negP[]] := max_dvd_u u u_gt1. elim: k => [|k IHk]; first by rewrite dvd1p. suffices: u ^+ k.+1 %| (p %/ g) * g. by rewrite Pdiv.Idomain.divpK ?dvdp_gcdl // dvdpZr ?lcn_neq0. rewrite exprS dvdp_mul // dvdp_gcd IHk //=. suffices: u ^+ k %| (p %/ u ^+ k * u ^+ k)^`(). by rewrite Pdiv.Idomain.divpK // derivZ dvdpZr ?lcn_neq0. by rewrite !derivCE u'0 mul0r mul0rn mulr0 addr0 dvdp_mull. have pg_dv_p: p %/ g %| p by rewrite divp_dvd ?dvdp_gcdl. apply/poly_square_freeP=> u; rewrite neq_ltn ltnS leqn0 size_poly_eq0. case/predU1P=> [-> | /max_dvd_u[k]]. by apply: contra nz_p; rewrite expr0n -dvd0p => /dvdp_trans->. apply: contra => u2_dv_pg; case: k; [by rewrite dvd1p | elim=> [|n IHn]]. exact: dvdp_trans (dvdp_mulr _ _) (dvdp_trans u2_dv_pg pg_dv_p). suff: u ^+ n.+2 %| (p %/ g) * g. by rewrite Pdiv.Idomain.divpK ?dvdp_gcdl // dvdpZr ?lcn_neq0. rewrite -add2n exprD dvdp_mul // dvdp_gcd. rewrite (dvdp_trans _ IHn) ?exprS ?dvdp_mull //=. suff: u ^+ n %| ((p %/ u ^+ n.+1) * u ^+ n.+1)^`(). by rewrite Pdiv.Idomain.divpK // derivZ dvdpZr ?lcn_neq0. by rewrite !derivCE dvdp_add // -1?mulr_natl ?exprS !dvdp_mull. Qed. End SeparablePoly. Arguments separable_polyP {R p}. Lemma separable_map (F : fieldType) (R : idomainType) (f : {rmorphism F -> R}) (p : {poly F}) : separable_poly (map_poly f p) = separable_poly p. Proof. by rewrite unlock deriv_map /coprimep -gcdp_map size_map_poly. Qed. Section InfinitePrimitiveElementTheorem. Local Notation "p ^ f" := (map_poly f p) : ring_scope. Variables (F L : fieldType) (iota : {rmorphism F -> L}). Variables (x y : L) (p : {poly F}). Hypotheses (nz_p : p != 0) (px_0 : root (p ^ iota) x). Let inFz z w := exists q, (q ^ iota).[z] = w. Lemma large_field_PET q : root (q ^ iota) y -> separable_poly q -> exists2 r, r != 0 & forall t (z := iota t * y - x), ~~ root r (iota t) -> inFz z x /\ inFz z y. Proof. move=> qy_0 sep_q; have nz_q := separable_poly_neq0 sep_q. have /factor_theorem[q0 Dq] := qy_0. set p1 := p ^ iota \Po ('X + x%:P); set q1 := q0 \Po ('X + y%:P). have nz_p1: p1 != 0. apply: contraNneq nz_p => /(canRL (fun r => comp_polyXaddC_K r _))/eqP. by rewrite comp_poly0 map_poly_eq0. have{sep_q} nz_q10: q1.[0] != 0. move: sep_q; rewrite -(separable_map iota) Dq separable_root => /andP[_]. by rewrite horner_comp !hornerE. have nz_q1: q1 != 0 by apply: contraNneq nz_q10 => ->; rewrite horner0. pose p2 := p1 ^ polyC \Po ('X * 'Y); pose q2 := q1 ^ polyC. have /Bezout_coprimepP[[u v]]: coprimep p2 q2. rewrite coprimep_def eqn_leq leqNgt andbC size_poly_gt0 gcdp_eq0 poly_XmY_eq0. by rewrite map_polyC_eq0 (negPf nz_p1) -resultant_eq0 div_annihilant_neq0. rewrite -size_poly_eq1 => /size_poly1P[r nzr Dr]; exists r => {nzr}// t z nz_rt. have [r1 nz_r1 r1z_0]: algebraicOver iota z. apply/algebraic_sub; last by exists p. by apply: algebraic_mul; [apply: algebraic_id | exists q]. pose Fz := subFExtend iota z r1; pose kappa : Fz -> L := subfx_inj. pose kappa' := inj_subfx iota z r1. have /eq_map_poly Diota: kappa \o kappa' =1 iota. by move=> w; rewrite /kappa /= subfx_inj_eval // map_polyC hornerC. suffices [y3]: exists y3, y = kappa y3. have [q3 ->] := subfxE y3; rewrite /kappa subfx_inj_eval // => Dy. split; [exists (t *: q3 - 'X) | by exists q3]. by rewrite rmorphB /= linearZ map_polyX !hornerE -Dy opprB addrC addrNK. pose p0 := p ^ iota \Po (iota t *: 'X - z%:P). have co_p0_q0: coprimep p0 q0. pose at_t := horner_eval (iota t); have at_t0: at_t 0 = 0 by apply: rmorph0. have /map_polyK polyCK: cancel polyC at_t by move=> w; apply: hornerC. have ->: p0 = p2 ^ at_t \Po ('X - y%:P). rewrite map_comp_poly polyCK // rmorphM /= map_polyC map_polyX /=. rewrite horner_evalE hornerX. rewrite -!comp_polyA comp_polyM comp_polyD !comp_polyC !comp_polyX. by rewrite mulrC mulrBr mul_polyC addrAC -addrA -opprB -rmorphM -rmorphB. have ->: q0 = q2 ^ at_t \Po ('X - y%:P) by rewrite polyCK ?comp_polyXaddC_K. apply/coprimep_comp_poly/Bezout_coprimepP; exists (u ^ at_t, v ^ at_t). by rewrite /= -!rmorphM -rmorphD Dr /= map_polyC polyC_eqp1. have{co_p0_q0}: gcdp p0 (q ^ iota) %= 'X - y%:P. rewrite /eqp Dq (eqp_dvdl _ (Gauss_gcdpr _ _)) // dvdp_gcdr dvdp_gcd. rewrite dvdp_mull // -root_factor_theorem rootE horner_comp !hornerE. by rewrite opprB addrC subrK. have{p0} [p3 ->]: exists p3, p0 = p3 ^ kappa. exists (p ^ kappa' \Po (kappa' t *: 'X - (subfx_eval iota z r1 'X)%:P)). rewrite map_comp_poly rmorphB /= linearZ /= map_polyC map_polyX /=. rewrite !subfx_inj_eval // map_polyC hornerC map_polyX hornerX. by rewrite -map_poly_comp Diota. rewrite -Diota map_poly_comp -gcdp_map /= -/kappa. move: (gcdp _ _) => r3 /eqpf_eq[c nz_c Dr3]. exists (- (r3`_0 / r3`_1)); rewrite [kappa _]rmorphN fmorph_div -!coef_map Dr3. by rewrite !coefZ polyseqXsubC mulr1 mulrC mulKf ?opprK. Qed. Lemma pchar0_PET (q : {poly F}) : q != 0 -> root (q ^ iota) y -> [pchar F] =i pred0 -> exists n, let z := y *+ n - x in inFz z x /\ inFz z y. Proof. move=> nz_q qy_0 /pcharf0P pcharF0. without loss{nz_q} sep_q: q qy_0 / separable_poly q. move=> IHq; apply: IHq (make_separable nz_q). have /dvdpP[q1 Dq] := dvdp_gcdl q q^`(). rewrite {1}Dq mulpK ?gcdp_eq0; last by apply/nandP; left. have [n [r nz_ry Dr]] := multiplicity_XsubC (q ^ iota) y. rewrite map_poly_eq0 nz_q /= in nz_ry. case: n => [|n] in Dr; first by rewrite Dr mulr1 (negPf nz_ry) in qy_0. have: ('X - y%:P) ^+ n.+1 %| q ^ iota by rewrite Dr dvdp_mulIr. rewrite Dq rmorphM /= gcdp_map -(eqp_dvdr _ (gcdp_mul2l _ _ _)) -deriv_map Dr. rewrite dvdp_gcd derivM deriv_exp derivXsubC mul1r !mulrA dvdp_mulIr /=. rewrite mulrDr mulrA dvdp_addr ?dvdp_mulIr // exprS -scaler_nat -!scalerAr. rewrite dvdpZr -?(rmorph_nat iota) ?fmorph_eq0 ?pcharF0 //. rewrite mulrA dvdp_mul2r ?expf_neq0 ?polyXsubC_eq0 //. by rewrite Gauss_dvdpl ?dvdp_XsubCl // coprimep_sym coprimep_XsubC. have [r nz_r PETxy] := large_field_PET qy_0 sep_q. pose ts := mkseq (fun n => iota n%:R) (size r). have /(max_ring_poly_roots nz_r)/=/implyP: uniq_roots ts. rewrite uniq_rootsE mkseq_uniq // => m n eq_mn; apply/eqP; rewrite eqn_leq. wlog suffices: m n eq_mn / m <= n by move=> IHmn; rewrite !IHmn. move/fmorph_inj/eqP: eq_mn; rewrite -subr_eq0 leqNgt; apply: contraL => lt_mn. by rewrite -natrB ?(ltnW lt_mn) // pcharF0 -lt0n subn_gt0. rewrite size_mkseq ltnn implybF all_map => /allPn[n _ /= /PETxy]. by rewrite rmorph_nat mulr_natl; exists n. Qed. End InfinitePrimitiveElementTheorem. #[deprecated(since="mathcomp 2.4.0", note="Use pchar0_PET instead.")] Notation char0_PET := (pchar0_PET) (only parsing). Section Separable. Variables (F : fieldType) (L : fieldExtType F). Implicit Types (U V W : {vspace L}) (E K M : {subfield L}) (D : 'End(L)). Section Derivation. Variables (K : {vspace L}) (D : 'End(L)). (* A deriviation only needs to be additive and satisfy Lebniz's law, but all *) (* the deriviations used here are going to be linear, so we only define *) (* the Derivation predicate for linear endomorphisms. *) Definition Derivation : bool := all2rel (fun u v => D (u * v) == D u * v + u * D v) (vbasis K). Hypothesis derD : Derivation. Lemma Derivation_mul : {in K &, forall u v, D (u * v) = D u * v + u * D v}. Proof. move=> u v /coord_vbasis-> /coord_vbasis->. rewrite !(mulr_sumr, linear_sum) -big_split; apply: eq_bigr => /= j _. rewrite !mulr_suml linear_sum -big_split; apply: eq_bigr => /= i _. rewrite !(=^~ scalerAl, linearZZ) -!scalerAr linearZZ -!scalerDr !scalerA /=. by congr (_ *: _); apply/eqP/(allrelP derD); exact: memt_nth. Qed. Lemma Derivation_mul_poly (Dp := map_poly D) : {in polyOver K &, forall p q, Dp (p * q) = Dp p * q + p * Dp q}. Proof. move=> p q Kp Kq; apply/polyP=> i; rewrite {}/Dp coefD coef_map /= !coefM. rewrite linear_sum -big_split; apply: eq_bigr => /= j _. by rewrite !{1}coef_map Derivation_mul ?(polyOverP _). Qed. End Derivation. Lemma DerivationS E K D : (K <= E)%VS -> Derivation E D -> Derivation K D. Proof. move/subvP=> sKE derD; apply/allrelP=> x y Kx Ky; apply/eqP. by rewrite (Derivation_mul derD) ?sKE // vbasis_mem. Qed. Section DerivationAlgebra. Variables (E : {subfield L}) (D : 'End(L)). Hypothesis derD : Derivation E D. Lemma Derivation1 : D 1 = 0. Proof. apply: (addIr (D (1 * 1))); rewrite add0r {1}mul1r. by rewrite (Derivation_mul derD) ?mem1v // mulr1 mul1r. Qed. Lemma Derivation_scalar x : x \in 1%VS -> D x = 0. Proof. by case/vlineP=> y ->; rewrite linearZ /= Derivation1 scaler0. Qed. Lemma Derivation_exp x m : x \in E -> D (x ^+ m) = x ^+ m.-1 *+ m * D x. Proof. move=> Ex; case: m; first by rewrite expr0 mulr0n mul0r Derivation1. elim=> [|m IHm]; first by rewrite mul1r. rewrite exprS (Derivation_mul derD) //; last by apply: rpredX. by rewrite mulrC IHm mulrA mulrnAr -exprS -mulrDl. Qed. Lemma Derivation_horner p x : p \is a polyOver E -> x \in E -> D p.[x] = (map_poly D p).[x] + p^`().[x] * D x. Proof. move=> Ep Ex; elim/poly_ind: p Ep => [|p c IHp] /polyOverP EpXc. by rewrite !(raddf0, horner0) mul0r add0r. have Ep: p \is a polyOver E. by apply/polyOverP=> i; have:= EpXc i.+1; rewrite coefD coefMX coefC addr0. have->: map_poly D (p * 'X + c%:P) = map_poly D p * 'X + (D c)%:P. apply/polyP=> i; rewrite !(coefD, coefMX, coef_map) /= linearD /= !coefC. by rewrite !(fun_if D) linear0. rewrite derivMXaddC !hornerE mulrDl mulrAC addrAC linearD /=; congr (_ + _). by rewrite addrCA -mulrDl -IHp // addrC (Derivation_mul derD) ?rpred_horner. Qed. End DerivationAlgebra. Definition separable_element U x := separable_poly (minPoly U x). Section SeparableElement. Variables (K : {subfield L}) (x : L). (* begin hide *) Let sKxK : (K <= <<K; x>>)%VS := subv_adjoin K x. Let Kx_x : x \in <<K; x>>%VS := memv_adjoin K x. (* end hide *) Lemma separable_elementP : reflect (exists f, [/\ f \is a polyOver K, root f x & separable_poly f]) (separable_element K x). Proof. apply: (iffP idP) => [sep_x | [f [Kf /(minPoly_dvdp Kf)/dvdpP[g ->]]]]. by exists (minPoly K x); rewrite minPolyOver root_minPoly. by rewrite separable_mul => /and3P[]. Qed. Lemma base_separable : x \in K -> separable_element K x. Proof. move=> Kx; apply/separable_elementP; exists ('X - x%:P). by rewrite polyOverXsubC root_XsubC unlock !derivCE coprimep1. Qed. Lemma separable_nz_der : separable_element K x = ((minPoly K x)^`() != 0). Proof. rewrite /separable_element unlock. apply/idP/idP=> [|nzPx']. by apply: contraTneq => ->; rewrite coprimep0 -size_poly_eq1 size_minPoly. have gcdK : gcdp (minPoly K x) (minPoly K x)^`() \in polyOver K. by rewrite gcdp_polyOver ?polyOver_deriv // minPolyOver. rewrite -gcdp_eqp1 -size_poly_eq1 -dvdp1. have /orP[/andP[_]|/andP[]//] := minPoly_irr gcdK (dvdp_gcdl _ _). rewrite dvdp_gcd dvdpp /= => /(dvdp_leq nzPx')/leq_trans/(_ (size_poly _ _)). by rewrite size_minPoly ltnn. Qed. Lemma separablePn_pchar : reflect (exists2 p, p \in [pchar L] & exists2 g, g \is a polyOver K & minPoly K x = g \Po 'X^p) (~~ separable_element K x). Proof. rewrite separable_nz_der negbK; set f := minPoly K x. apply: (iffP eqP) => [f'0 | [p Hp [g _ ->]]]; last first. by rewrite deriv_comp derivXn -scaler_nat (pcharf0 Hp) scale0r mulr0. pose n := adjoin_degree K x; have sz_f: size f = n.+1 := size_minPoly K x. have fn1: f`_n = 1 by rewrite -(monicP (monic_minPoly K x)) lead_coefE sz_f. have dimKx: (adjoin_degree K x)%:R == 0 :> L. by rewrite -(coef0 _ n.-1) -f'0 coef_deriv fn1. have /natf0_pchar[// | p pcharLp] := dimKx. have /dvdnP[r Dn]: (p %| n)%N by rewrite (dvdn_pcharf pcharLp). exists p => //; exists (\poly_(i < r.+1) f`_(i * p)). by apply: polyOver_poly => i _; rewrite (polyOverP _) ?minPolyOver. rewrite comp_polyE size_poly_eq -?Dn ?fn1 ?oner_eq0 //. have pr_p := pcharf_prime pcharLp; have p_gt0 := prime_gt0 pr_p. apply/polyP=> i; rewrite coef_sum. have [[{}i ->] | p'i] := altP (@dvdnP p i); last first. rewrite big1 => [|j _]; last first. rewrite coefZ -exprM coefXn [_ == _](contraNF _ p'i) ?mulr0 // => /eqP->. by rewrite dvdn_mulr. rewrite (dvdn_pcharf pcharLp) in p'i; apply: mulfI p'i _ _ _. by rewrite mulr0 mulr_natl; case: i => // i; rewrite -coef_deriv f'0 coef0. have [ltri | leir] := leqP r.+1 i. rewrite nth_default ?sz_f ?Dn ?ltn_pmul2r ?big1 // => j _. rewrite coefZ -exprM coefXn mulnC gtn_eqF ?mulr0 //. by rewrite ltn_pmul2l ?(leq_trans _ ltri). rewrite (bigD1 (Sub i _)) //= big1 ?addr0 => [|j i'j]; last first. by rewrite coefZ -exprM coefXn mulnC eqn_pmul2l // mulr_natr mulrb ifN_eqC. by rewrite coef_poly leir coefZ -exprM coefXn mulnC eqxx mulr1. Qed. Lemma separable_root_der : separable_element K x (+) root (minPoly K x)^`() x. Proof. have KpKx': _^`() \is a polyOver K := polyOver_deriv (minPolyOver K x). rewrite separable_nz_der addNb (root_small_adjoin_poly KpKx') ?addbb //. by rewrite (leq_trans (size_poly _ _)) ?size_minPoly. Qed. Lemma Derivation_separable D : Derivation <<K; x>> D -> separable_element K x -> D x = - (map_poly D (minPoly K x)).[x] / (minPoly K x)^`().[x]. Proof. move=> derD sepKx; have:= separable_root_der; rewrite {}sepKx -sub0r => nzKx'x. apply: canRL (mulfK nzKx'x) (canRL (addrK _) _); rewrite mulrC addrC. rewrite -(Derivation_horner derD) ?minPolyxx ?linear0 //. exact: polyOverSv sKxK _ (minPolyOver _ _). Qed. Section ExtendDerivation. Variable D : 'End(L). Let Dx E := - (map_poly D (minPoly E x)).[x] / ((minPoly E x)^`()).[x]. Fact extendDerivation_zmod_morphism_subproof E (adjEx := Fadjoin_poly E x) : let body y (p := adjEx y) := (map_poly D p).[x] + p^`().[x] * Dx E in zmod_morphism body. Proof. move: Dx => C /= u v; rewrite /adjEx. rewrite raddfB /= derivB -/adjEx !hornerE /= raddfB /= !hornerE. by rewrite mulrBl addrACA opprD. Qed. Fact extendDerivation_scalable_subproof E (adjEx := Fadjoin_poly E x) : let body y (p := adjEx y) := (map_poly D p).[x] + p^`().[x] * Dx E in scalable body. Proof. move: Dx => C /= a u; rewrite /adjEx linearZ /= derivZ -/adjEx. rewrite hornerE -[RHS]mulr_algl mulrDr mulrA -[in RHS]hornerZ. congr (_.[x] + _); apply/polyP=> i. by rewrite coefZ !coef_map coefZ !mulr_algl /= linearZ. Qed. Section DerivationLinear. Variable (E : {subfield L}). Let body (y : L) (p := Fadjoin_poly E x y) : L := (map_poly D p).[x] + p^`().[x] * Dx E. HB.instance Definition _ := @GRing.isZmodMorphism.Build _ _ body (extendDerivation_zmod_morphism_subproof E). HB.instance Definition _ := @GRing.isScalable.Build _ _ _ _ body (extendDerivation_scalable_subproof E). Let extendDerivationLinear := Eval hnf in (body : {linear _ -> _}). Definition extendDerivation : 'End(L) := linfun extendDerivationLinear. End DerivationLinear. Hypothesis derD : Derivation K D. Lemma extendDerivation_id y : y \in K -> extendDerivation K y = D y. Proof. move=> yK; rewrite lfunE /= Fadjoin_polyC // derivC map_polyC hornerC. by rewrite horner0 mul0r addr0. Qed. Lemma extendDerivation_horner p : p \is a polyOver K -> separable_element K x -> extendDerivation K p.[x] = (map_poly D p).[x] + p^`().[x] * Dx K. Proof. move=> Kp sepKx; have:= separable_root_der; rewrite {}sepKx /= => nz_pKx'x. rewrite [in RHS](divp_eq p (minPoly K x)) lfunE /= Fadjoin_poly_mod ?raddfD //=. rewrite (Derivation_mul_poly derD) ?divp_polyOver ?minPolyOver //. rewrite derivM !{1}hornerD !{1}hornerM minPolyxx !{1}mulr0 !{1}add0r. rewrite mulrDl addrA [_ + (_ * _ * _)]addrC {2}/Dx -mulrA -/Dx. by rewrite [_ / _]mulrC (mulVKf nz_pKx'x) mulrN addKr. Qed. Lemma extendDerivationP : separable_element K x -> Derivation <<K; x>> (extendDerivation K). Proof. move=> sep; apply/allrelP=> u v /vbasis_mem Hu /vbasis_mem Hv; apply/eqP. rewrite -(Fadjoin_poly_eq Hu) -(Fadjoin_poly_eq Hv) -hornerM. rewrite !{1}extendDerivation_horner ?{1}rpredM ?Fadjoin_polyOver //. rewrite (Derivation_mul_poly derD) ?Fadjoin_polyOver //. rewrite derivM !{1}hornerD !{1}hornerM !{1}mulrDl !{1}mulrDr -!addrA. congr (_ + _); rewrite [Dx K]lock -!{1}mulrA !{1}addrA; congr (_ + _). by rewrite addrC; congr (_ * _ + _); rewrite mulrC. Qed. End ExtendDerivation. (* Reference: http://www.math.uconn.edu/~kconrad/blurbs/galoistheory/separable2.pdf *) Lemma Derivation_separableP : reflect (forall D, Derivation <<K; x>> D -> K <= lker D -> <<K; x>> <= lker D)%VS (separable_element K x). Proof. apply: (iffP idP) => [sepKx D derD /subvP DK_0 | derKx_0]. have{} DK_0 q: q \is a polyOver K -> map_poly D q = 0. move=> /polyOverP Kq; apply/polyP=> i; apply/eqP. by rewrite coef0 coef_map -memv_ker DK_0. apply/subvP=> _ /Fadjoin_polyP[p Kp ->]; rewrite memv_ker. rewrite (Derivation_horner derD) ?(polyOverSv sKxK) //. rewrite (Derivation_separable derD sepKx) !DK_0 ?minPolyOver //. by rewrite horner0 oppr0 mul0r mulr0 addr0. apply: wlog_neg; rewrite {1}separable_nz_der negbK => /eqP pKx'_0. pose Df := fun y => (Fadjoin_poly K x y)^`().[x]. have Dlin: linear Df. move=> a u v; rewrite /Df linearP /= -mul_polyC derivD derivM derivC. by rewrite mul0r add0r hornerD hornerM hornerC -scalerAl mul1r. pose DlinM := GRing.isLinear.Build _ _ _ _ Df Dlin. pose DL : {linear _ -> _} := HB.pack Df DlinM. pose D := linfun DL; apply: base_separable. have DK_0: (K <= lker D)%VS. apply/subvP=> v Kv; rewrite memv_ker lfunE /= /Df Fadjoin_polyC //. by rewrite derivC horner0. have Dder: Derivation <<K; x>> D. apply/allrelP=> u v /vbasis_mem Kx_u /vbasis_mem Kx_v; apply/eqP. rewrite !lfunE /= /Df; set Px := Fadjoin_poly K x. set Px_u := Px u; rewrite -(Fadjoin_poly_eq Kx_u) -/Px -/Px_u. set Px_v := Px v; rewrite -(Fadjoin_poly_eq Kx_v) -/Px -/Px_v. rewrite -!hornerM -hornerD -derivM. rewrite /Px Fadjoin_poly_mod ?rpredM ?Fadjoin_polyOver //. rewrite [in RHS](divp_eq (Px_u * Px_v) (minPoly K x)) derivD derivM. by rewrite pKx'_0 mulr0 addr0 hornerD hornerM minPolyxx mulr0 add0r. have{Dder DK_0}: x \in lker D by apply: subvP Kx_x; apply: derKx_0. apply: contraLR => K'x; rewrite memv_ker lfunE /= /Df Fadjoin_polyX //. by rewrite derivX hornerC oner_eq0. Qed. End SeparableElement. #[deprecated(since="mathcomp 2.4.0", note="Use separablePn_pchar instead.")] Notation separablePn := (separablePn_pchar) (only parsing). Arguments separable_elementP {K x}. Lemma separable_elementS K E x : (K <= E)%VS -> separable_element K x -> separable_element E x. Proof. move=> sKE /separable_elementP[f [fK rootf sepf]]; apply/separable_elementP. by exists f; rewrite (polyOverSv sKE). Qed. Lemma adjoin_separableP {K x} : reflect (forall y, y \in <<K; x>>%VS -> separable_element K y) (separable_element K x). Proof. apply: (iffP idP) => [sepKx | -> //]; last exact: memv_adjoin. move=> _ /Fadjoin_polyP[q Kq ->]; apply/Derivation_separableP=> D derD DK_0. apply/subvP=> _ /Fadjoin_polyP[p Kp ->]. rewrite memv_ker -(extendDerivation_id x D (mempx_Fadjoin _ Kp)). have sepFyx: (separable_element <<K; q.[x]>> x). by apply: (separable_elementS (subv_adjoin _ _)). have KyxEqKx: (<< <<K; q.[x]>>; x>> = <<K; x>>)%VS. apply/eqP; rewrite eqEsubv andbC adjoinSl ?subv_adjoin //=. apply/FadjoinP/andP; rewrite memv_adjoin andbT. by apply/FadjoinP/andP; rewrite subv_adjoin mempx_Fadjoin. have /[!KyxEqKx] derDx := extendDerivationP derD sepFyx. rewrite -horner_comp (Derivation_horner derDx) ?memv_adjoin //; last first. by apply: (polyOverSv (subv_adjoin _ _)); apply: polyOver_comp. set Dx_p := map_poly _; have Dx_p_0 t: t \is a polyOver K -> (Dx_p t).[x] = 0. move/polyOverP=> Kt; congr (_.[x] = 0): (horner0 x); apply/esym/polyP => i. have /eqP Dti_0: D t`_i == 0 by rewrite -memv_ker (subvP DK_0) ?Kt. by rewrite coef0 coef_map /= {1}extendDerivation_id ?subvP_adjoin. rewrite (Derivation_separable derDx sepKx) -/Dx_p Dx_p_0 ?polyOver_comp //. by rewrite add0r mulrCA Dx_p_0 ?minPolyOver ?oppr0 ?mul0r. Qed. Lemma separable_exponent_pchar K x : exists n, [pchar L].-nat n && separable_element K (x ^+ n). Proof. pose d := adjoin_degree K x; move: {2}d.+1 (ltnSn d) => n. elim: n => // n IHn in x @d *; rewrite ltnS => le_d_n. have [[p pcharLp]|] := altP (separablePn_pchar K x); last by rewrite negbK; exists 1. case=> g Kg defKx; have p_pr := pcharf_prime pcharLp. suffices /IHn[m /andP[pcharLm sepKxpm]]: adjoin_degree K (x ^+ p) < n. by exists (p * m)%N; rewrite pnatM pnatE // pcharLp pcharLm exprM. apply: leq_trans le_d_n; rewrite -ltnS -!size_minPoly. have nzKx: minPoly K x != 0 by rewrite monic_neq0 ?monic_minPoly. have nzg: g != 0 by apply: contra_eqN defKx => /eqP->; rewrite comp_poly0. apply: leq_ltn_trans (dvdp_leq nzg _) _. by rewrite minPoly_dvdp // rootE -hornerXn -horner_comp -defKx minPolyxx. rewrite (polySpred nzKx) ltnS defKx size_comp_poly size_polyXn /=. suffices g_gt1: 1 < size g by rewrite -(subnKC g_gt1) ltn_Pmulr ?prime_gt1. apply: contra_eqT (size_minPoly K x); rewrite defKx -leqNgt => /size1_polyC->. by rewrite comp_polyC size_polyC; case: (_ != 0). Qed. #[deprecated(since="mathcomp 2.4.0", note="Use separable_exponent_pchar instead.")] Notation separable_exponent := (separable_exponent_pchar) (only parsing). Lemma pcharf0_separable K : [pchar L] =i pred0 -> forall x, separable_element K x. Proof. move=> pcharL0 x; have [n /andP[pcharLn]] := separable_exponent_pchar K x. by rewrite (pnat_1 pcharLn (sub_in_pnat _ pcharLn)) // => p _; rewrite pcharL0. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf0_separable instead.")] Notation charf0_separable := (pcharf0_separable) (only parsing). Lemma pcharf_p_separable K x e p : p \in [pchar L] -> separable_element K x = (x \in <<K; x ^+ (p ^ e.+1)>>%VS). Proof. move=> pcharLp; apply/idP/idP=> [sepKx | /Fadjoin_poly_eq]; last first. set m := p ^ _; set f := Fadjoin_poly K _ x => Dx; apply/separable_elementP. have mL0: m%:R = 0 :> L by apply/eqP; rewrite -(dvdn_pcharf pcharLp) dvdn_exp. exists ('X - (f \Po 'X^m)); split. - by rewrite rpredB ?polyOver_comp ?rpredX ?polyOverX ?Fadjoin_polyOver. - by rewrite rootE !hornerE horner_comp hornerXn Dx subrr. rewrite unlock !(derivE, deriv_comp) -mulr_natr -rmorphMn /= mL0. by rewrite !mulr0 subr0 coprimep1. without loss{e} ->: e x sepKx / e = 0. move=> IH; elim: {e}e.+1 => [|e]; [exact: memv_adjoin | apply: subvP]. apply/FadjoinP/andP; rewrite subv_adjoin expnSr exprM (IH 0) //. by have /adjoin_separableP-> := sepKx; rewrite ?rpredX ?memv_adjoin. set K' := <<K; x ^+ p>>%VS; have sKK': (K <= K')%VS := subv_adjoin _ _. pose q := minPoly K' x; pose g := 'X^p - (x ^+ p)%:P. have [K'g]: g \is a polyOver K' /\ q \is a polyOver K'. by rewrite minPolyOver rpredB ?rpredX ?polyOverX // polyOverC memv_adjoin. have /dvdpP[c Dq]: 'X - x%:P %| q by rewrite dvdp_XsubCl root_minPoly. have co_c_g: coprimep c g. have pcharPp: p \in [pchar {poly L}] := rmorph_pchar polyC pcharLp. rewrite /g polyC_exp -!(pFrobenius_autE pcharPp) -rmorphB coprimep_expr //. have: separable_poly q := separable_elementS sKK' sepKx. by rewrite Dq separable_mul => /and3P[]. have{g K'g co_c_g} /size_poly1P[a nz_a Dc]: size c == 1. suffices c_dv_g: c %| g by rewrite -(eqp_size (dvdp_gcd_idl c_dv_g)). have: q %| g by rewrite minPoly_dvdp // rootE !hornerE subrr. by apply: dvdp_trans; rewrite Dq dvdp_mulIl. rewrite {q}Dq {c}Dc mulrBr -rmorphM -rmorphN -cons_poly_def qualifE /=. by rewrite polyseq_cons !polyseqC nz_a /= rpredN andbCA => /and3P[/fpredMl->]. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_p_separable instead.")] Notation charf_p_separable := (pcharf_p_separable) (only parsing). Lemma pcharf_n_separable K x n : [pchar L].-nat n -> 1 < n -> separable_element K x = (x \in <<K; x ^+ n>>%VS). Proof. rewrite -pi_pdiv; set p := pdiv n => pcharLn pi_n_p. have pcharLp: p \in [pchar L] := pnatPpi pcharLn pi_n_p. have <-: (n`_p)%N = n by rewrite -(eq_partn n (pcharf_eq pcharLp)) part_pnat_id. by rewrite p_part lognE -mem_primes pi_n_p -pcharf_p_separable. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_n_separable instead.")] Notation charf_n_separable := (pcharf_n_separable) (only parsing). Definition purely_inseparable_element U x := x ^+ ex_minn (separable_exponent_pchar <<U>> x) \in U. Lemma purely_inseparable_elementP_pchar {K x} : reflect (exists2 n, [pchar L].-nat n & x ^+ n \in K) (purely_inseparable_element K x). Proof. rewrite /purely_inseparable_element. case: ex_minnP => n /andP[pcharLn /=]; rewrite subfield_closed => sepKxn min_xn. apply: (iffP idP) => [Kxn | [m pcharLm Kxm]]; first by exists n. have{min_xn}: n <= m by rewrite min_xn ?pcharLm ?base_separable. rewrite leq_eqVlt => /predU1P[-> // | ltnm]; pose p := pdiv m. have m_gt1: 1 < m by have [/leq_ltn_trans->] := andP pcharLn. have pcharLp: p \in [pchar L] by rewrite (pnatPpi pcharLm) ?pi_pdiv. have [/p_natP[em Dm] /p_natP[en Dn]]: p.-nat m /\ p.-nat n. by rewrite -!(eq_pnat _ (pcharf_eq pcharLp)). rewrite Dn Dm ltn_exp2l ?prime_gt1 ?pdiv_prime // in ltnm. rewrite -(Fadjoin_idP Kxm) Dm -(subnKC ltnm) addSnnS expnD exprM -Dn. by rewrite -pcharf_p_separable. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use purely_inseparable_elementP_pchar instead.")] Notation purely_inseparable_elementP := (purely_inseparable_elementP_pchar) (only parsing). Lemma separable_inseparable_element K x : separable_element K x && purely_inseparable_element K x = (x \in K). Proof. rewrite /purely_inseparable_element; case: ex_minnP => [[|m]] //=. rewrite subfield_closed; case: m => /= [-> //| m _ /(_ 1)/implyP/= insepKx]. by rewrite (negPf insepKx) (contraNF (@base_separable K x) insepKx). Qed. Lemma base_inseparable K x : x \in K -> purely_inseparable_element K x. Proof. by rewrite -separable_inseparable_element => /andP[]. Qed. Lemma sub_inseparable K E x : (K <= E)%VS -> purely_inseparable_element K x -> purely_inseparable_element E x. Proof. move/subvP=> sKE /purely_inseparable_elementP_pchar[n pcharLn /sKE Exn]. by apply/purely_inseparable_elementP_pchar; exists n. Qed. Section PrimitiveElementTheorem. Variables (K : {subfield L}) (x y : L). Section FiniteCase. Variable N : nat. Let K_is_large := exists s, [/\ uniq s, {subset s <= K} & N < size s]. Let cyclic_or_large (z : L) : z != 0 -> K_is_large \/ exists a, z ^+ a.+1 = 1. Proof. move=> nz_z; pose d := adjoin_degree K z. pose h0 (i : 'I_(N ^ d).+1) (j : 'I_d) := (Fadjoin_poly K z (z ^+ i))`_j. pose s := undup [seq h0 i j | i <- enum 'I_(N ^ d).+1, j <- enum 'I_d]. have s_h0 i j: h0 i j \in s. by rewrite mem_undup; apply/allpairsP; exists (i, j); rewrite !mem_enum. pose h i := [ffun j => Ordinal (etrans (index_mem _ _) (s_h0 i j))]. pose h' (f : {ffun 'I_d -> 'I_(size s)}) := \sum_(j < d) s`_(f j) * z ^+ j. have hK i: h' (h i) = z ^+ i. have Kz_zi: z ^+ i \in <<K; z>>%VS by rewrite rpredX ?memv_adjoin. rewrite -(Fadjoin_poly_eq Kz_zi) (horner_coef_wide z (size_poly _ _)) -/d. by apply: eq_bigr => j _; rewrite ffunE /= nth_index. have [inj_h | ] := altP (@injectiveP _ _ h). left; exists s; split=> [|zi_j|]; rewrite ?undup_uniq ?mem_undup //=. by case/allpairsP=> ij [_ _ ->]; apply/polyOverP/Fadjoin_polyOver. rewrite -[size s]card_ord -(@ltn_exp2r _ _ d) // -{2}[d]card_ord -card_ffun. by rewrite -[_.+1]card_ord -(card_image inj_h) max_card. case/injectivePn=> i1 [i2 i1'2 /(congr1 h')]; rewrite !hK => eq_zi12; right. without loss{i1'2} lti12: i1 i2 eq_zi12 / i1 < i2. by move=> IH; move: i1'2; rewrite neq_ltn => /orP[]; apply: IH. by exists (i2 - i1.+1)%N; rewrite subnSK ?expfB // eq_zi12 divff ?expf_neq0. Qed. Lemma finite_PET : K_is_large \/ exists z, (<< <<K; y>>; x>> = <<K; z>>)%VS. Proof. have [-> | /cyclic_or_large[|[a Dxa]]] := eqVneq x 0; first 2 [by left]. by rewrite addv0 subfield_closed; right; exists y. have [-> | /cyclic_or_large[|[b Dyb]]] := eqVneq y 0; first 2 [by left]. by rewrite addv0 subfield_closed; right; exists x. pose h0 (ij : 'I_a.+1 * 'I_b.+1) := x ^+ ij.1 * y ^+ ij.2. pose H := <<[set ij | h0 ij == 1%R]>>%G; pose h (u : coset_of H) := h0 (repr u). have h0M: {morph h0: ij1 ij2 / (ij1 * ij2)%g >-> ij1 * ij2}. by rewrite /h0 => [] [i1 j1] [i2 j2] /=; rewrite mulrACA -!exprD !expr_mod. have memH ij: (ij \in H) = (h0 ij == 1). rewrite /= gen_set_id ?inE //; apply/group_setP; rewrite inE [h0 _]mulr1. by split=> // ? ? /[!(inE, h0M)] /eqP-> /eqP->; rewrite mulr1. have nH ij: ij \in 'N(H)%g. by apply/(subsetP (cent_sub _))/centP=> ij1 _; congr (_, _); rewrite Zp_mulgC. have hE ij: h (coset H ij) = h0 ij. rewrite /h val_coset //; case: repr_rcosetP => ij1. by rewrite memH h0M => /eqP->; rewrite mul1r. have h1: h 1%g = 1 by rewrite /h repr_coset1 [h0 _]mulr1. have hM: {morph h: u v / (u * v)%g >-> u * v}. by do 2![move=> u; have{u} [? _ ->] := cosetP u]; rewrite -morphM // !hE h0M. have /cyclicP[w defW]: cyclic [set: coset_of H]. apply: field_mul_group_cyclic (in2W hM) _ => u _; have [ij _ ->] := cosetP u. by split=> [/eqP | -> //]; rewrite hE -memH => /coset_id. have Kw_h ij t: h0 ij = t -> t \in <<K; h w>>%VS. have /cycleP[k Dk]: coset H ij \in <[w]>%g by rewrite -defW inE. rewrite -hE {}Dk => <-; elim: k => [|k IHk]; first by rewrite h1 rpred1. by rewrite expgS hM rpredM // memv_adjoin. right; exists (h w); apply/eqP; rewrite eqEsubv !(sameP FadjoinP andP). rewrite subv_adjoin (subv_trans (subv_adjoin K y)) ?subv_adjoin //=. rewrite (Kw_h (0, inZp 1)) 1?(Kw_h (inZp 1, 0)) /h0 ?mulr1 ?mul1r ?expr_mod //=. by rewrite rpredM ?rpredX ?memv_adjoin // subvP_adjoin ?memv_adjoin. Qed. End FiniteCase. Hypothesis sepKy : separable_element K y. Lemma Primitive_Element_Theorem : exists z, (<< <<K; y>>; x>> = <<K; z>>)%VS. Proof. have /polyOver_subvs[p Dp]: minPoly K x \is a polyOver K := minPolyOver K x. have nz_pKx: minPoly K x != 0 by rewrite monic_neq0 ?monic_minPoly. have{nz_pKx} nz_p: p != 0 by rewrite Dp map_poly_eq0 in nz_pKx. have{Dp} px0: root (map_poly vsval p) x by rewrite -Dp root_minPoly. have [q0 [Kq0 q0y0 sepKq0]] := separable_elementP sepKy. have /polyOver_subvs[q Dq]: minPoly K y \is a polyOver K := minPolyOver K y. have qy0: root (map_poly vsval q) y by rewrite -Dq root_minPoly. have sep_pKy: separable_poly (minPoly K y). by rewrite (dvdp_separable _ sepKq0) ?minPoly_dvdp. have{sep_pKy} sep_q: separable_poly q by rewrite Dq separable_map in sep_pKy. have [r nz_r PETr] := large_field_PET nz_p px0 qy0 sep_q. have [[s [Us Ks /ltnW leNs]] | //] := finite_PET (size r). have{s Us leNs} /allPn[t {}/Ks Kt nz_rt]: ~~ all (root r) s. by apply: contraTN leNs; rewrite -ltnNge => /max_poly_roots->. have{PETr} [/= [p1 Dx] [q1 Dy]] := PETr (Subvs Kt) nz_rt. set z := t * y - x in Dx Dy; exists z; apply/eqP. rewrite eqEsubv !(sameP FadjoinP andP) subv_adjoin. have Kz_p1z (r1 : {poly subvs_of K}): (map_poly vsval r1).[z] \in <<K; z>>%VS. rewrite rpred_horner ?memv_adjoin ?(polyOverSv (subv_adjoin K z)) //. by apply/polyOver_subvs; exists r1. rewrite -{1}Dx -{1}Dy !{Dx Dy}Kz_p1z /=. rewrite (subv_trans (subv_adjoin K y)) ?subv_adjoin // rpredB ?memv_adjoin //. by rewrite subvP_adjoin // rpredM ?memv_adjoin ?subvP_adjoin. Qed. Lemma adjoin_separable : separable_element <<K; y>> x -> separable_element K x. Proof. have /Derivation_separableP derKy := sepKy => /Derivation_separableP derKy_x. have [z defKz] := Primitive_Element_Theorem. suffices /adjoin_separableP: separable_element K z. by apply; rewrite -defKz memv_adjoin. apply/Derivation_separableP=> D; rewrite -defKz => derKxyD DK_0. suffices derKyD: Derivation <<K; y>>%VS D by rewrite derKy_x // derKy. by apply: DerivationS derKxyD; apply: subv_adjoin. Qed. End PrimitiveElementTheorem. Lemma strong_Primitive_Element_Theorem K x y : separable_element <<K; x>> y -> exists2 z : L, (<< <<K; y>>; x>> = <<K; z>>)%VS & separable_element K x -> separable_element K y. Proof. move=> sepKx_y; have [n /andP[pcharLn sepKyn]] := separable_exponent_pchar K y. have adjK_C z t: (<<<<K; z>>; t>> = <<<<K; t>>; z>>)%VS. by rewrite !agenv_add_id -!addvA (addvC <[_]>%VS). have [z defKz] := Primitive_Element_Theorem x sepKyn. exists z => [|/adjoin_separable->]; rewrite ?sepKx_y // -defKz. have [|n_gt1|-> //] := ltngtP n 1; first by case: (n) pcharLn. apply/eqP; rewrite !(adjK_C _ x) eqEsubv; apply/andP. split; apply/FadjoinP/andP; rewrite subv_adjoin ?rpredX ?memv_adjoin //=. by rewrite -pcharf_n_separable ?sepKx_y. Qed. Definition separable U W : bool := all (separable_element U) (vbasis W). Definition purely_inseparable U W : bool := all (purely_inseparable_element U) (vbasis W). Lemma separable_add K x y : separable_element K x -> separable_element K y -> separable_element K (x + y). Proof. move/(separable_elementS (subv_adjoin K y))=> sepKy_x sepKy. have [z defKz] := Primitive_Element_Theorem x sepKy. have /(adjoin_separableP _): x + y \in <<K; z>>%VS. by rewrite -defKz rpredD ?memv_adjoin // subvP_adjoin ?memv_adjoin. apply; apply: adjoin_separable sepKy (adjoin_separable sepKy_x _). by rewrite defKz base_separable ?memv_adjoin. Qed. Lemma separable_sum I r (P : pred I) (v_ : I -> L) K : (forall i, P i -> separable_element K (v_ i)) -> separable_element K (\sum_(i <- r | P i) v_ i). Proof. move=> sepKi. by elim/big_ind: _; [apply/base_separable/mem0v | apply: separable_add |]. Qed. Lemma inseparable_add K x y : purely_inseparable_element K x -> purely_inseparable_element K y -> purely_inseparable_element K (x + y). Proof. have insepP := purely_inseparable_elementP_pchar. move=> /insepP[n pcharLn Kxn] /insepP[m pcharLm Kym]; apply/insepP. have pcharLnm: [pchar L].-nat (n * m)%N by rewrite pnatM pcharLn. by exists (n * m)%N; rewrite ?exprDn_pchar // {2}mulnC !exprM memvD // rpredX. Qed. Lemma inseparable_sum I r (P : pred I) (v_ : I -> L) K : (forall i, P i -> purely_inseparable_element K (v_ i)) -> purely_inseparable_element K (\sum_(i <- r | P i) v_ i). Proof. move=> insepKi. by elim/big_ind: _; [apply/base_inseparable/mem0v | apply: inseparable_add |]. Qed. Lemma separableP {K E} : reflect (forall y, y \in E -> separable_element K y) (separable K E). Proof. apply/(iffP idP)=> [/allP|] sepK_E; last by apply/allP=> x /vbasis_mem/sepK_E. move=> y /coord_vbasis->; apply/separable_sum=> i _. have: separable_element K (vbasis E)`_i by apply/sepK_E/memt_nth. by move/adjoin_separableP; apply; rewrite rpredZ ?memv_adjoin. Qed. Lemma purely_inseparableP {K E} : reflect (forall y, y \in E -> purely_inseparable_element K y) (purely_inseparable K E). Proof. apply/(iffP idP)=> [/allP|] sep'K_E; last by apply/allP=> x /vbasis_mem/sep'K_E. move=> y /coord_vbasis->; apply/inseparable_sum=> i _. have: purely_inseparable_element K (vbasis E)`_i by apply/sep'K_E/memt_nth. case/purely_inseparable_elementP_pchar=> n pcharLn K_Ein. by apply/purely_inseparable_elementP_pchar; exists n; rewrite // exprZn rpredZ. Qed. Lemma adjoin_separable_eq K x : separable_element K x = separable K <<K; x>>%VS. Proof. exact: sameP adjoin_separableP separableP. Qed. Lemma separable_inseparable_decomposition E K : {x | x \in E /\ separable_element K x & purely_inseparable <<K; x>> E}. Proof. without loss sKE: K / (K <= E)%VS. case/(_ _ (capvSr K E)) => x [Ex sepKEx] /purely_inseparableP sep'KExE. exists x; first by split; last exact/(separable_elementS _ sepKEx)/capvSl. apply/purely_inseparableP=> y /sep'KExE; apply: sub_inseparable. exact/adjoinSl/capvSl. pose E_ i := (vbasis E)`_i; pose fP i := separable_exponent_pchar K (E_ i). pose f i := E_ i ^+ ex_minn (fP i); pose s := mkseq f (\dim E). pose K' := <<K & s>>%VS. have sepKs: all (separable_element K) s. by rewrite all_map /f; apply/allP=> i _ /=; case: ex_minnP => m /andP[]. have [x sepKx defKx]: {x | x \in E /\ separable_element K x & K' = <<K; x>>%VS}. have: all [in E] s. rewrite all_map; apply/allP=> i; rewrite mem_iota => ltis /=. by rewrite rpredX // vbasis_mem // memt_nth. rewrite {}/K'; elim/last_ind: s sepKs => [|s t IHs]. by exists 0; [rewrite base_separable mem0v | rewrite adjoin_nil addv0]. rewrite adjoin_rcons !all_rcons => /andP[sepKt sepKs] /andP[/= Et Es]. have{IHs sepKs Es} [y [Ey sepKy] ->{s}] := IHs sepKs Es. have /sig_eqW[x defKx] := Primitive_Element_Theorem t sepKy. exists x; [split | exact: defKx]. suffices: (<<K; x>> <= E)%VS by case/FadjoinP. by rewrite -defKx !(sameP FadjoinP andP) sKE Ey Et. apply/adjoin_separableP=> z; rewrite -defKx => Kyt_z. apply: adjoin_separable sepKy _; apply: adjoin_separableP Kyt_z. exact: separable_elementS (subv_adjoin K y) sepKt. exists x; rewrite // -defKx; apply/(all_nthP 0)=> i; rewrite size_tuple => ltiE. apply/purely_inseparable_elementP_pchar. exists (ex_minn (fP i)); first by case: ex_minnP => n /andP[]. by apply/seqv_sub_adjoin/map_f; rewrite mem_iota. Qed. Definition separable_generator K E : L := s2val (locked (separable_inseparable_decomposition E K)). Lemma separable_generator_mem E K : separable_generator K E \in E. Proof. by rewrite /separable_generator; case: (locked _) => ? []. Qed. Lemma separable_generatorP E K : separable_element K (separable_generator K E). Proof. by rewrite /separable_generator; case: (locked _) => ? []. Qed. Lemma separable_generator_maximal E K : purely_inseparable <<K; separable_generator K E>> E. Proof. by rewrite /separable_generator; case: (locked _). Qed. Lemma sub_adjoin_separable_generator E K : separable K E -> (E <= <<K; separable_generator K E>>)%VS. Proof. move/separableP=> sepK_E; apply/subvP=> v Ev. rewrite -separable_inseparable_element. have /purely_inseparableP-> // := separable_generator_maximal E K. by rewrite (separable_elementS _ (sepK_E _ Ev)) // subv_adjoin. Qed. Lemma eq_adjoin_separable_generator E K : separable K E -> (K <= E)%VS -> E = <<K; separable_generator K E>>%VS :> {vspace _}. Proof. move=> sepK_E sKE; apply/eqP; rewrite eqEsubv sub_adjoin_separable_generator //. by apply/FadjoinP/andP; rewrite sKE separable_generator_mem. Qed. Lemma separable_refl K : separable K K. Proof. exact/separableP/base_separable. Qed. Lemma separable_trans M K E : separable K M -> separable M E -> separable K E. Proof. move/sub_adjoin_separable_generator. set x := separable_generator K M => sMKx /separableP sepM_E. apply/separableP => w /sepM_E/(separable_elementS sMKx). case/strong_Primitive_Element_Theorem => _ _ -> //. exact: separable_generatorP. Qed. Lemma separableS K1 K2 E2 E1 : (K1 <= K2)%VS -> (E2 <= E1)%VS -> separable K1 E1 -> separable K2 E2. Proof. move=> sK12 /subvP sE21 /separableP sepK1_E1. by apply/separableP=> y /sE21/sepK1_E1/(separable_elementS sK12). Qed. Lemma separableSl K M E : (K <= M)%VS -> separable K E -> separable M E. Proof. by move/separableS; apply. Qed. Lemma separableSr K M E : (M <= E)%VS -> separable K E -> separable K M. Proof. exact: separableS. Qed. Lemma separable_Fadjoin_seq K rs : all (separable_element K) rs -> separable K <<K & rs>>. Proof. elim/last_ind: rs => [|s x IHs] in K *. by rewrite adjoin_nil subfield_closed separable_refl. rewrite all_rcons adjoin_rcons => /andP[sepKx /IHs/separable_trans-> //]. by rewrite -adjoin_separable_eq (separable_elementS _ sepKx) ?subv_adjoin_seq. Qed. Lemma purely_inseparable_refl K : purely_inseparable K K. Proof. by apply/purely_inseparableP; apply: base_inseparable. Qed. Lemma purely_inseparable_trans M K E : purely_inseparable K M -> purely_inseparable M E -> purely_inseparable K E. Proof. have insepP := purely_inseparableP => /insepP insepK_M /insepP insepM_E. have insepPe := purely_inseparable_elementP_pchar. apply/insepP=> x /insepM_E/insepPe[n pcharLn /insepK_M/insepPe[m pcharLm Kxnm]]. by apply/insepPe; exists (n * m)%N; rewrite ?exprM // pnatM pcharLn pcharLm. Qed. End Separable. Arguments separable_elementP {F L K x}. Arguments separablePn_pchar {F L K x}. Arguments Derivation_separableP {F L K x}. Arguments adjoin_separableP {F L K x}. Arguments purely_inseparable_elementP_pchar {F L K x}. Arguments separableP {F L K E}. Arguments purely_inseparableP {F L K E}.
Basis.lean
/- Copyright (c) 2021 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer -/ import Mathlib.LinearAlgebra.Basis.Basic import Mathlib.LinearAlgebra.DirectSum.Finsupp import Mathlib.LinearAlgebra.Finsupp.VectorSpace import Mathlib.LinearAlgebra.FreeModule.Basic /-! # Bases and dimensionality of tensor products of modules This file defines various bases on the tensor product of modules, and shows that the tensor product of free modules is again free. -/ noncomputable section open LinearMap Module Set Submodule open scoped TensorProduct section CommSemiring variable {R : Type*} {S : Type*} {M : Type*} {N : Type*} {ι : Type*} {κ : Type*} [CommSemiring R] [Semiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] [AddCommMonoid N] [Module R N] namespace Module.Basis /-- If `b : ι → M` and `c : κ → N` are bases then so is `fun i ↦ b i.1 ⊗ₜ c i.2 : ι × κ → M ⊗ N`. -/ def tensorProduct (b : Basis ι S M) (c : Basis κ R N) : Basis (ι × κ) S (M ⊗[R] N) := Finsupp.basisSingleOne.map ((TensorProduct.AlgebraTensorModule.congr b.repr c.repr).trans <| (finsuppTensorFinsupp R S _ _ _ _).trans <| Finsupp.lcongr (Equiv.refl _) (TensorProduct.AlgebraTensorModule.rid R S S)).symm @[simp] theorem tensorProduct_apply (b : Basis ι S M) (c : Basis κ R N) (i : ι) (j : κ) : tensorProduct b c (i, j) = b i ⊗ₜ c j := by simp [tensorProduct] theorem tensorProduct_apply' (b : Basis ι S M) (c : Basis κ R N) (i : ι × κ) : tensorProduct b c i = b i.1 ⊗ₜ c i.2 := by simp [tensorProduct] @[simp] theorem tensorProduct_repr_tmul_apply (b : Basis ι S M) (c : Basis κ R N) (m : M) (n : N) (i : ι) (j : κ) : (tensorProduct b c).repr (m ⊗ₜ n) (i, j) = c.repr n j • b.repr m i := by simp [tensorProduct] variable (S : Type*) [Semiring S] [Algebra R S] /-- The lift of an `R`-basis of `M` to an `S`-basis of the base change `S ⊗[R] M`. -/ noncomputable def baseChange (b : Basis ι R M) : Basis ι S (S ⊗[R] M) := (tensorProduct (.singleton Unit S) b).reindex (Equiv.punitProd ι) @[simp] lemma baseChange_repr_tmul (b : Basis ι R M) (x y i) : (b.baseChange S).repr (x ⊗ₜ y) i = b.repr y i • x := by simp [baseChange, tensorProduct] @[simp] lemma baseChange_apply (b : Basis ι R M) (i) : b.baseChange S i = 1 ⊗ₜ b i := by simp [baseChange, tensorProduct] end Module.Basis section variable [DecidableEq ι] [DecidableEq κ] variable (ℬ : Basis ι R M) (𝒞 : Basis κ R N) (x : M ⊗[R] N) /-- If `{𝒞ᵢ}` is a basis for the module `N`, then every elements of `x ∈ M ⊗ N` can be uniquely written as `∑ᵢ mᵢ ⊗ 𝒞ᵢ` for some `mᵢ ∈ M`. -/ def TensorProduct.equivFinsuppOfBasisRight : M ⊗[R] N ≃ₗ[R] κ →₀ M := LinearEquiv.lTensor M 𝒞.repr ≪≫ₗ TensorProduct.finsuppScalarRight R M κ @[simp] lemma TensorProduct.equivFinsuppOfBasisRight_apply_tmul (m : M) (n : N) : (TensorProduct.equivFinsuppOfBasisRight 𝒞) (m ⊗ₜ n) = (𝒞.repr n).mapRange (· • m) (zero_smul _ _) := by ext; simp [equivFinsuppOfBasisRight] lemma TensorProduct.equivFinsuppOfBasisRight_apply_tmul_apply (m : M) (n : N) (i : κ) : (TensorProduct.equivFinsuppOfBasisRight 𝒞) (m ⊗ₜ n) i = 𝒞.repr n i • m := by simp only [equivFinsuppOfBasisRight_apply_tmul, Finsupp.mapRange_apply] lemma TensorProduct.equivFinsuppOfBasisRight_symm : (TensorProduct.equivFinsuppOfBasisRight 𝒞).symm.toLinearMap = Finsupp.lsum R fun i ↦ (TensorProduct.mk R M N).flip (𝒞 i) := by ext; simp [equivFinsuppOfBasisRight] @[simp] lemma TensorProduct.equivFinsuppOfBasisRight_symm_apply (b : κ →₀ M) : (TensorProduct.equivFinsuppOfBasisRight 𝒞).symm b = b.sum fun i m ↦ m ⊗ₜ 𝒞 i := congr($(TensorProduct.equivFinsuppOfBasisRight_symm 𝒞) b) omit [DecidableEq κ] in lemma TensorProduct.sum_tmul_basis_right_injective : Function.Injective (Finsupp.lsum R fun i ↦ (TensorProduct.mk R M N).flip (𝒞 i)) := have := Classical.decEq κ (equivFinsuppOfBasisRight_symm (M := M) 𝒞).symm ▸ (TensorProduct.equivFinsuppOfBasisRight 𝒞).symm.injective omit [DecidableEq κ] in lemma TensorProduct.sum_tmul_basis_right_eq_zero (b : κ →₀ M) (h : (b.sum fun i m ↦ m ⊗ₜ[R] 𝒞 i) = 0) : b = 0 := have := Classical.decEq κ (TensorProduct.equivFinsuppOfBasisRight 𝒞).symm.injective (a₂ := 0) <| by simpa /-- If `{ℬᵢ}` is a basis for the module `M`, then every elements of `x ∈ M ⊗ N` can be uniquely written as `∑ᵢ ℬᵢ ⊗ nᵢ` for some `nᵢ ∈ N`. -/ def TensorProduct.equivFinsuppOfBasisLeft : M ⊗[R] N ≃ₗ[R] ι →₀ N := TensorProduct.comm R M N ≪≫ₗ TensorProduct.equivFinsuppOfBasisRight ℬ @[simp] lemma TensorProduct.equivFinsuppOfBasisLeft_apply_tmul (m : M) (n : N) : (TensorProduct.equivFinsuppOfBasisLeft ℬ) (m ⊗ₜ n) = (ℬ.repr m).mapRange (· • n) (zero_smul _ _) := by ext; simp [equivFinsuppOfBasisLeft] lemma TensorProduct.equivFinsuppOfBasisLeft_apply_tmul_apply (m : M) (n : N) (i : ι) : (TensorProduct.equivFinsuppOfBasisLeft ℬ) (m ⊗ₜ n) i = ℬ.repr m i • n := by simp only [equivFinsuppOfBasisLeft_apply_tmul, Finsupp.mapRange_apply] lemma TensorProduct.equivFinsuppOfBasisLeft_symm : (TensorProduct.equivFinsuppOfBasisLeft ℬ).symm.toLinearMap = Finsupp.lsum R fun i ↦ (TensorProduct.mk R M N) (ℬ i) := by ext; simp [equivFinsuppOfBasisLeft] @[simp] lemma TensorProduct.equivFinsuppOfBasisLeft_symm_apply (b : ι →₀ N) : (TensorProduct.equivFinsuppOfBasisLeft ℬ).symm b = b.sum fun i n ↦ ℬ i ⊗ₜ n := congr($(TensorProduct.equivFinsuppOfBasisLeft_symm ℬ) b) omit [DecidableEq κ] in /-- Elements in `M ⊗ N` can be represented by sum of elements in `M` tensor elements of basis of `N`. -/ lemma TensorProduct.eq_repr_basis_right : ∃ b : κ →₀ M, b.sum (fun i m ↦ m ⊗ₜ 𝒞 i) = x := by classical simpa using (TensorProduct.equivFinsuppOfBasisRight 𝒞).symm.surjective x omit [DecidableEq ι] in /-- Elements in `M ⊗ N` can be represented by sum of elements of basis of `M` tensor elements of `N`. -/ lemma TensorProduct.eq_repr_basis_left : ∃ (c : ι →₀ N), (c.sum fun i n ↦ ℬ i ⊗ₜ n) = x := by classical obtain ⟨c, rfl⟩ := (TensorProduct.equivFinsuppOfBasisLeft ℬ).symm.surjective x exact ⟨c, (TensorProduct.comm R M N).injective <| by simp [Finsupp.sum]⟩ omit [DecidableEq ι] in lemma TensorProduct.sum_tmul_basis_left_injective : Function.Injective (Finsupp.lsum R fun i ↦ (TensorProduct.mk R M N) (ℬ i)) := have := Classical.decEq ι (equivFinsuppOfBasisLeft_symm (N := N) ℬ).symm ▸ (TensorProduct.equivFinsuppOfBasisLeft ℬ).symm.injective omit [DecidableEq ι] in lemma TensorProduct.sum_tmul_basis_left_eq_zero (b : ι →₀ N) (h : (b.sum fun i n ↦ ℬ i ⊗ₜ[R] n) = 0) : b = 0 := have := Classical.decEq ι (TensorProduct.equivFinsuppOfBasisLeft ℬ).symm.injective (a₂ := 0) <| by simpa end variable [CommSemiring R] [Semiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] [Module.Free S M] [AddCommMonoid N] [Module R N] [Module.Free R N] instance Module.Free.tensor : Module.Free S (M ⊗[R] N) := let ⟨bM⟩ := exists_basis (R := S) (M := M) let ⟨bN⟩ := exists_basis (R := R) (M := N) of_basis (bM.2.tensorProduct bN.2) end CommSemiring end
TopComparison.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.CategoryTheory.Limits.Preserves.Opposites import Mathlib.CategoryTheory.Sites.Coherent.SheafComparison import Mathlib.Condensed.Basic import Mathlib.Topology.Category.TopCat.Yoneda /-! # The functor from topological spaces to condensed sets This file builds on the API from the file `TopCat.Yoneda`. If the forgetful functor to `TopCat` has nice properties, like preserving pullbacks and finite coproducts, then this Yoneda presheaf satisfies the sheaf condition for the regular and extensive topologies respectively. We apply this API to `CompHaus` and define the functor `topCatToCondensedSet : TopCat.{u+1} ⥤ CondensedSet.{u}`. -/ universe w w' v u open CategoryTheory Opposite Limits regularTopology ContinuousMap Topology variable {C : Type u} [Category.{v} C] (G : C ⥤ TopCat.{w}) (X : Type w') [TopologicalSpace X] /-- An auxiliary lemma to that allows us to use `IsQuotientMap.lift` in the proof of `equalizerCondition_yonedaPresheaf`. -/ theorem factorsThrough_of_pullbackCondition {Z B : C} {π : Z ⟶ B} [HasPullback π π] [PreservesLimit (cospan π π) G] {a : C(G.obj Z, X)} (ha : a ∘ (G.map (pullback.fst _ _)) = a ∘ (G.map (pullback.snd π π))) : Function.FactorsThrough a (G.map π) := by intro x y hxy let xy : G.obj (pullback π π) := (PreservesPullback.iso G π π).inv <| (TopCat.pullbackIsoProdSubtype (G.map π) (G.map π)).inv ⟨(x, y), hxy⟩ have ha' := congr_fun ha xy dsimp at ha' have h₁ : ∀ y, G.map (pullback.fst _ _) ((PreservesPullback.iso G π π).inv y) = pullback.fst (G.map π) (G.map π) y := by simp only [← PreservesPullback.iso_inv_fst]; intro y; rfl have h₂ : ∀ y, G.map (pullback.snd _ _) ((PreservesPullback.iso G π π).inv y) = pullback.snd (G.map π) (G.map π) y := by simp only [← PreservesPullback.iso_inv_snd]; intro y; rfl rw [h₁, h₂, TopCat.pullbackIsoProdSubtype_inv_fst_apply, TopCat.pullbackIsoProdSubtype_inv_snd_apply] at ha' simpa using ha' /-- If `G` preserves the relevant pullbacks and every effective epi in `C` is a quotient map (which is the case when `C` is `CompHaus` or `Profinite`), then `yonedaPresheaf` satisfies the equalizer condition which is required to be a sheaf for the regular topology. -/ theorem equalizerCondition_yonedaPresheaf [∀ (Z B : C) (π : Z ⟶ B) [EffectiveEpi π], PreservesLimit (cospan π π) G] (hq : ∀ (Z B : C) (π : Z ⟶ B) [EffectiveEpi π], IsQuotientMap (G.map π)) : EqualizerCondition (yonedaPresheaf G X) := by apply EqualizerCondition.mk intro Z B π _ _ refine ⟨fun a b h ↦ ?_, fun ⟨a, ha⟩ ↦ ?_⟩ · simp only [yonedaPresheaf, unop_op, Quiver.Hom.unop_op, Set.coe_setOf, MapToEqualizer, Set.mem_setOf_eq, Subtype.mk.injEq, comp, ContinuousMap.mk.injEq] at h simp only [yonedaPresheaf, unop_op] ext x obtain ⟨y, hy⟩ := (hq Z B π).surjective x rw [← hy] exact congr_fun h y · simp only [yonedaPresheaf, comp, unop_op, Quiver.Hom.unop_op, Set.mem_setOf_eq, ContinuousMap.mk.injEq] at ha simp only [yonedaPresheaf, comp, unop_op, Quiver.Hom.unop_op, Set.coe_setOf, MapToEqualizer, Set.mem_setOf_eq, Subtype.mk.injEq] simp only [yonedaPresheaf, unop_op] at a refine ⟨(hq Z B π).lift a (factorsThrough_of_pullbackCondition G X ha), ?_⟩ congr 1 exact DFunLike.ext'_iff.mp ((hq Z B π).lift_comp a (factorsThrough_of_pullbackCondition G X ha)) /-- If `G` preserves finite coproducts (which is the case when `C` is `CompHaus`, `Profinite` or `Stonean`), then `yonedaPresheaf` preserves finite products, which is required to be a sheaf for the extensive topology. -/ noncomputable instance [PreservesFiniteCoproducts G] : PreservesFiniteProducts (yonedaPresheaf G X) := have := preservesFiniteProducts_op G ⟨fun _ ↦ comp_preservesLimitsOfShape G.op (yonedaPresheaf' X)⟩ section variable (P : TopCat.{u} → Prop) (X : TopCat.{max u w}) [CompHausLike.HasExplicitFiniteCoproducts.{0} P] [CompHausLike.HasExplicitPullbacks.{u} P] (hs : ∀ ⦃X Y : CompHausLike P⦄ (f : X ⟶ Y), EffectiveEpi f → Function.Surjective f) /-- The sheaf on `CompHausLike P` of continuous maps to a topological space. -/ @[simps! val_obj val_map] def TopCat.toSheafCompHausLike : have := CompHausLike.preregular hs Sheaf (coherentTopology (CompHausLike.{u} P)) (Type (max u w)) where val := yonedaPresheaf.{u, max u w} (CompHausLike.compHausLikeToTop.{u} P) X cond := by have := CompHausLike.preregular hs rw [Presheaf.isSheaf_iff_preservesFiniteProducts_and_equalizerCondition] refine ⟨inferInstance, ?_⟩ apply (config := { allowSynthFailures := true }) equalizerCondition_yonedaPresheaf (CompHausLike.compHausLikeToTop.{u} P) X intro Z B π he apply IsQuotientMap.of_surjective_continuous (hs _ he) π.hom.continuous /-- `TopCat.toSheafCompHausLike` yields a functor from `TopCat.{max u w}` to `Sheaf (coherentTopology (CompHausLike.{u} P)) (Type (max u w))`. -/ @[simps] noncomputable def topCatToSheafCompHausLike : have := CompHausLike.preregular hs TopCat.{max u w} ⥤ Sheaf (coherentTopology (CompHausLike.{u} P)) (Type (max u w)) where obj X := X.toSheafCompHausLike P hs map f := ⟨⟨fun _ g ↦ f.hom.comp g, by aesop⟩⟩ end /-- Associate to a `(u+1)`-small topological space the corresponding condensed set, given by `yonedaPresheaf`. -/ noncomputable abbrev TopCat.toCondensedSet (X : TopCat.{u + 1}) : CondensedSet.{u} := toSheafCompHausLike.{u+1} _ X (fun _ _ _ ↦ ((CompHaus.effectiveEpi_tfae _).out 0 2).mp) /-- `TopCat.toCondensedSet` yields a functor from `TopCat.{u+1}` to `CondensedSet.{u}`. -/ noncomputable abbrev topCatToCondensedSet : TopCat.{u+1} ⥤ CondensedSet.{u} := topCatToSheafCompHausLike.{u+1} _ (fun _ _ _ ↦ ((CompHaus.effectiveEpi_tfae _).out 0 2).mp)
EisensteinCriterion.lean
/- Copyright (c) 2020 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Data.Nat.Cast.WithTop import Mathlib.RingTheory.Ideal.Quotient.Basic import Mathlib.RingTheory.Polynomial.Content import Mathlib.RingTheory.Prime deprecated_module "Auto-generated deprecation" (since := "2025-04-11")
ClopenBox.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.Topology.Compactness.Bases import Mathlib.Topology.CompactOpen import Mathlib.Topology.Separation.Profinite import Mathlib.Topology.Sets.Closeds /-! # Clopen subsets in cartesian products In general, a clopen subset in a cartesian product of topological spaces cannot be written as a union of "clopen boxes", i.e. products of clopen subsets of the components (see [buzyakovaClopenBox] for counterexamples). However, when one of the factors is compact, a clopen subset can be written as such a union. Our argument in `TopologicalSpace.Clopens.exists_prod_subset` follows the one given in [buzyakovaClopenBox]. We deduce that in a product of compact spaces, a clopen subset is a finite union of clopen boxes, and use that to prove that the property of having countably many clopens is preserved by taking cartesian products of compact spaces (this is relevant to the theory of light profinite sets). ## References - [buzyakovaClopenBox]: *On clopen sets in Cartesian products*, 2001. - [engelking1989]: *General Topology*, 1989. -/ open Function Set Filter TopologicalSpace open scoped Topology variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [CompactSpace Y] namespace TopologicalSpace.Clopens theorem exists_prod_subset (W : Clopens (X × Y)) {a : X × Y} (h : a ∈ W) : ∃ U : Clopens X, a.1 ∈ U ∧ ∃ V : Clopens Y, a.2 ∈ V ∧ U ×ˢ V ≤ W := by have hp : Continuous (fun y : Y ↦ (a.1, y)) := .prodMk_right _ let V : Set Y := {y | (a.1, y) ∈ W} have hV : IsCompact V := (W.2.1.preimage hp).isCompact let U : Set X := {x | MapsTo (Prod.mk x) V W} have hUV : U ×ˢ V ⊆ W := fun ⟨_, _⟩ hw ↦ hw.1 hw.2 exact ⟨⟨U, (ContinuousMap.isClopen_setOf_mapsTo hV W.2).preimage (ContinuousMap.id (X × Y)).curry.2⟩, by simp [U, V, MapsTo], ⟨V, W.2.preimage hp⟩, h, hUV⟩ variable [CompactSpace X] /-- Every clopen set in a product of two compact spaces is a union of finitely many clopen boxes. -/ theorem exists_finset_eq_sup_prod (W : Clopens (X × Y)) : ∃ (I : Finset (Clopens X × Clopens Y)), W = I.sup fun i ↦ i.1 ×ˢ i.2 := by choose! U hxU V hxV hUV using fun x ↦ W.exists_prod_subset (a := x) rcases W.2.1.isCompact.elim_nhds_subcover (fun x ↦ U x ×ˢ V x) (fun x hx ↦ (U x ×ˢ V x).2.isOpen.mem_nhds ⟨hxU x hx, hxV x hx⟩) with ⟨I, hIW, hWI⟩ classical use I.image fun x ↦ (U x, V x) rw [Finset.sup_image] refine le_antisymm (fun x hx ↦ ?_) (Finset.sup_le fun x hx ↦ ?_) · rcases Set.mem_iUnion₂.1 (hWI hx) with ⟨i, hi, hxi⟩ exact SetLike.le_def.1 (Finset.le_sup hi) hxi · exact hUV _ <| hIW _ hx lemma surjective_finset_sup_prod : Surjective fun I : Finset (Clopens X × Clopens Y) ↦ I.sup fun i ↦ i.1 ×ˢ i.2 := fun W ↦ let ⟨I, hI⟩ := W.exists_finset_eq_sup_prod; ⟨I, hI.symm⟩ instance countable_prod [Countable (Clopens X)] [Countable (Clopens Y)] : Countable (Clopens (X × Y)) := surjective_finset_sup_prod.countable instance finite_prod [Finite (Clopens X)] [Finite (Clopens Y)] : Finite (Clopens (X × Y)) := by cases nonempty_fintype (Clopens X) cases nonempty_fintype (Clopens Y) exact .of_surjective _ surjective_finset_sup_prod lemma countable_iff_secondCountable [T2Space X] [TotallyDisconnectedSpace X] : Countable (Clopens X) ↔ SecondCountableTopology X := by refine ⟨fun h ↦ ⟨{s : Set X | IsClopen s}, ?_, ?_⟩, fun h ↦ ?_⟩ · let f : {s : Set X | IsClopen s} → Clopens X := fun s ↦ ⟨s.1, s.2⟩ exact (injective_of_le_imp_le f fun a ↦ a).countable · apply IsTopologicalBasis.eq_generateFrom exact loc_compact_Haus_tot_disc_of_zero_dim · have : ∀ (s : Clopens X), ∃ (t : Finset (countableBasis X)), s.1 = t.toSet.sUnion := fun s ↦ eq_sUnion_finset_of_isTopologicalBasis_of_isCompact_open _ (isBasis_countableBasis X) s.1 s.2.1.isCompact s.2.2 let f : Clopens X → Finset (countableBasis X) := fun s ↦ (this s).choose have hf : f.Injective := by intro s t (h : Exists.choose _ = Exists.choose _) ext1; change s.carrier = t.carrier rw [(this s).choose_spec, (this t).choose_spec, h] exact hf.countable end TopologicalSpace.Clopens
Nontriviality.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, Mario Carneiro -/ import Mathlib.Tactic.Nontriviality.Core /-! # The `nontriviality` tactic. -/
Coprime.lean
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Algebra.EuclideanDomain.Int import Mathlib.Data.Nat.Prime.Int import Mathlib.Data.ZMod.Basic import Mathlib.RingTheory.Int.Basic import Mathlib.RingTheory.PrincipalIdealDomain /-! # Coprimality and vanishing We show that for prime `p`, the image of an integer `a` in `ZMod p` vanishes if and only if `a` and `p` are not coprime. -/ assert_not_exists TwoSidedIdeal namespace ZMod theorem coe_int_isUnit_iff_isCoprime (n : ℤ) (m : ℕ) : IsUnit (n : ZMod m) ↔ IsCoprime (m : ℤ) n := by rw [Int.isCoprime_iff_nat_coprime, Nat.coprime_comm, ← isUnit_iff_coprime, Associated.isUnit_iff] simpa only [eq_intCast, Int.cast_natCast] using (Int.associated_natAbs _).map (Int.castRingHom _) /-- If `p` is a prime and `a` is an integer, then `a : ZMod p` is zero if and only if `gcd a p ≠ 1`. -/ theorem eq_zero_iff_gcd_ne_one {a : ℤ} {p : ℕ} [pp : Fact p.Prime] : (a : ZMod p) = 0 ↔ a.gcd p ≠ 1 := by rw [Ne, Int.gcd_comm, ← Int.isCoprime_iff_gcd_eq_one, (Nat.prime_iff_prime_int.1 pp.1).coprime_iff_not_dvd, Classical.not_not, intCast_zmod_eq_zero_iff_dvd] /-- If an integer `a` and a prime `p` satisfy `gcd a p = 1`, then `a : ZMod p` is nonzero. -/ theorem ne_zero_of_gcd_eq_one {a : ℤ} {p : ℕ} (pp : p.Prime) (h : a.gcd p = 1) : (a : ZMod p) ≠ 0 := mt (@eq_zero_iff_gcd_ne_one a p ⟨pp⟩).mp (Classical.not_not.mpr h) /-- If an integer `a` and a prime `p` satisfy `gcd a p ≠ 1`, then `a : ZMod p` is zero. -/ theorem eq_zero_of_gcd_ne_one {a : ℤ} {p : ℕ} (pp : p.Prime) (h : a.gcd p ≠ 1) : (a : ZMod p) = 0 := (@eq_zero_iff_gcd_ne_one a p ⟨pp⟩).mpr h end ZMod
Inseparable.lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang, Yury Kudryashov -/ import Mathlib.Order.UpperLower.Closure import Mathlib.Order.UpperLower.Fibration import Mathlib.Tactic.TFAE import Mathlib.Topology.ContinuousOn import Mathlib.Topology.Maps.OpenQuotient /-! # Inseparable points in a topological space In this file we prove basic properties of the following notions defined elsewhere. * `Specializes` (notation: `x ⤳ y`) : a relation saying that `𝓝 x ≤ 𝓝 y`; * `Inseparable`: a relation saying that two points in a topological space have the same neighbourhoods; equivalently, they can't be separated by an open set; * `InseparableSetoid X`: same relation, as a `Setoid`; * `SeparationQuotient X`: the quotient of `X` by its `InseparableSetoid`. We also prove various basic properties of the relation `Inseparable`. ## Notations - `x ⤳ y`: notation for `Specializes x y`; - `x ~ᵢ y` is used as a local notation for `Inseparable x y`; - `𝓝 x` is the neighbourhoods filter `nhds x` of a point `x`, defined elsewhere. ## Tags topological space, separation setoid -/ open Set Filter Function Topology variable {X Y Z α ι : Type*} {A : ι → Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [∀ i, TopologicalSpace (A i)] {x y z : X} {s : Set X} {f g : X → Y} /-! ### `Specializes` relation -/ /-- A collection of equivalent definitions of `x ⤳ y`. The public API is given by `iff` lemmas below. -/ theorem specializes_TFAE (x y : X) : List.TFAE [x ⤳ y, pure x ≤ 𝓝 y, ∀ s : Set X , IsOpen s → y ∈ s → x ∈ s, ∀ s : Set X , IsClosed s → x ∈ s → y ∈ s, y ∈ closure ({ x } : Set X), closure ({ y } : Set X) ⊆ closure { x }, ClusterPt y (pure x)] := by tfae_have 1 → 2 := (pure_le_nhds _).trans tfae_have 2 → 3 := fun h s hso hy => h (hso.mem_nhds hy) tfae_have 3 → 4 := fun h s hsc hx => of_not_not fun hy => h sᶜ hsc.isOpen_compl hy hx tfae_have 4 → 5 := fun h => h _ isClosed_closure (subset_closure <| mem_singleton _) tfae_have 6 ↔ 5 := isClosed_closure.closure_subset_iff.trans singleton_subset_iff tfae_have 5 ↔ 7 := by rw [mem_closure_iff_clusterPt, principal_singleton] tfae_have 5 → 1 := by refine fun h => (nhds_basis_opens _).ge_iff.2 ?_ rintro s ⟨hy, ho⟩ rcases mem_closure_iff.1 h s ho hy with ⟨z, hxs, rfl : z = x⟩ exact ho.mem_nhds hxs tfae_finish theorem specializes_iff_nhds : x ⤳ y ↔ 𝓝 x ≤ 𝓝 y := Iff.rfl theorem Specializes.not_disjoint (h : x ⤳ y) : ¬Disjoint (𝓝 x) (𝓝 y) := fun hd ↦ absurd (hd.mono_right h) <| by simp [NeBot.ne'] theorem specializes_iff_pure : x ⤳ y ↔ pure x ≤ 𝓝 y := (specializes_TFAE x y).out 0 1 alias ⟨Specializes.nhds_le_nhds, _⟩ := specializes_iff_nhds alias ⟨Specializes.pure_le_nhds, _⟩ := specializes_iff_pure theorem ker_nhds_eq_specializes : (𝓝 x).ker = {y | y ⤳ x} := by ext; simp [specializes_iff_pure, le_def] theorem specializes_iff_forall_open : x ⤳ y ↔ ∀ s : Set X, IsOpen s → y ∈ s → x ∈ s := (specializes_TFAE x y).out 0 2 theorem Specializes.mem_open (h : x ⤳ y) (hs : IsOpen s) (hy : y ∈ s) : x ∈ s := specializes_iff_forall_open.1 h s hs hy theorem IsOpen.not_specializes (hs : IsOpen s) (hx : x ∉ s) (hy : y ∈ s) : ¬x ⤳ y := fun h => hx <| h.mem_open hs hy theorem specializes_iff_forall_closed : x ⤳ y ↔ ∀ s : Set X, IsClosed s → x ∈ s → y ∈ s := (specializes_TFAE x y).out 0 3 theorem Specializes.mem_closed (h : x ⤳ y) (hs : IsClosed s) (hx : x ∈ s) : y ∈ s := specializes_iff_forall_closed.1 h s hs hx theorem IsClosed.not_specializes (hs : IsClosed s) (hx : x ∈ s) (hy : y ∉ s) : ¬x ⤳ y := fun h => hy <| h.mem_closed hs hx theorem specializes_iff_mem_closure : x ⤳ y ↔ y ∈ closure ({x} : Set X) := (specializes_TFAE x y).out 0 4 alias ⟨Specializes.mem_closure, _⟩ := specializes_iff_mem_closure theorem specializes_iff_closure_subset : x ⤳ y ↔ closure ({y} : Set X) ⊆ closure {x} := (specializes_TFAE x y).out 0 5 alias ⟨Specializes.closure_subset, _⟩ := specializes_iff_closure_subset theorem specializes_iff_clusterPt : x ⤳ y ↔ ClusterPt y (pure x) := (specializes_TFAE x y).out 0 6 theorem Filter.HasBasis.specializes_iff {ι} {p : ι → Prop} {s : ι → Set X} (h : (𝓝 y).HasBasis p s) : x ⤳ y ↔ ∀ i, p i → x ∈ s i := specializes_iff_pure.trans h.ge_iff theorem specializes_rfl : x ⤳ x := le_rfl @[refl] theorem specializes_refl (x : X) : x ⤳ x := specializes_rfl @[trans] theorem Specializes.trans : x ⤳ y → y ⤳ z → x ⤳ z := le_trans theorem specializes_of_eq (e : x = y) : x ⤳ y := e ▸ specializes_refl x alias Specializes.of_eq := specializes_of_eq theorem specializes_of_nhdsWithin (h₁ : 𝓝[s] x ≤ 𝓝[s] y) (h₂ : x ∈ s) : x ⤳ y := specializes_iff_pure.2 <| calc pure x ≤ 𝓝[s] x := le_inf (pure_le_nhds _) (le_principal_iff.2 h₂) _ ≤ 𝓝[s] y := h₁ _ ≤ 𝓝 y := inf_le_left theorem Specializes.map_of_continuousWithinAt {s : Set X} (h : x ⤳ y) (hf : ContinuousWithinAt f s y) (hx : x ∈ s) : f x ⤳ f y := by rw [specializes_iff_pure] at h ⊢ calc pure (f x) _ = map f (pure x) := (map_pure f x).symm _ ≤ map f (𝓝 y ⊓ 𝓟 s) := map_mono (le_inf h ((pure_le_principal x).mpr hx)) _ = map f (𝓝[s] y) := rfl _ ≤ _ := hf.tendsto theorem Specializes.map_of_continuousOn {s : Set X} (h : x ⤳ y) (hf : ContinuousOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ⤳ f y := h.map_of_continuousWithinAt (hf.continuousWithinAt hy) hx theorem Specializes.map_of_continuousAt (h : x ⤳ y) (hf : ContinuousAt f y) : f x ⤳ f y := h.map_of_continuousWithinAt hf.continuousWithinAt (mem_univ x) theorem Specializes.map (h : x ⤳ y) (hf : Continuous f) : f x ⤳ f y := h.map_of_continuousAt hf.continuousAt theorem Topology.IsInducing.specializes_iff (hf : IsInducing f) : f x ⤳ f y ↔ x ⤳ y := by simp only [specializes_iff_mem_closure, hf.closure_eq_preimage_closure_image, image_singleton, mem_preimage] theorem subtype_specializes_iff {p : X → Prop} (x y : Subtype p) : x ⤳ y ↔ (x : X) ⤳ y := IsInducing.subtypeVal.specializes_iff.symm @[simp] theorem specializes_prod {x₁ x₂ : X} {y₁ y₂ : Y} : (x₁, y₁) ⤳ (x₂, y₂) ↔ x₁ ⤳ x₂ ∧ y₁ ⤳ y₂ := by simp only [Specializes, nhds_prod_eq, prod_le_prod] theorem Specializes.prod {x₁ x₂ : X} {y₁ y₂ : Y} (hx : x₁ ⤳ x₂) (hy : y₁ ⤳ y₂) : (x₁, y₁) ⤳ (x₂, y₂) := specializes_prod.2 ⟨hx, hy⟩ theorem Specializes.fst {a b : X × Y} (h : a ⤳ b) : a.1 ⤳ b.1 := (specializes_prod.1 h).1 theorem Specializes.snd {a b : X × Y} (h : a ⤳ b) : a.2 ⤳ b.2 := (specializes_prod.1 h).2 @[simp] theorem specializes_pi {f g : ∀ i, A i} : f ⤳ g ↔ ∀ i, f i ⤳ g i := by simp only [Specializes, nhds_pi, pi_le_pi] theorem not_specializes_iff_exists_open : ¬x ⤳ y ↔ ∃ S : Set X, IsOpen S ∧ y ∈ S ∧ x ∉ S := by rw [specializes_iff_forall_open] push_neg rfl theorem not_specializes_iff_exists_closed : ¬x ⤳ y ↔ ∃ S : Set X, IsClosed S ∧ x ∈ S ∧ y ∉ S := by rw [specializes_iff_forall_closed] push_neg rfl theorem IsOpen.continuous_piecewise_of_specializes [DecidablePred (· ∈ s)] (hs : IsOpen s) (hf : Continuous f) (hg : Continuous g) (hspec : ∀ x, f x ⤳ g x) : Continuous (s.piecewise f g) := by have : ∀ U, IsOpen U → g ⁻¹' U ⊆ f ⁻¹' U := fun U hU x hx ↦ (hspec x).mem_open hU hx rw [continuous_def] intro U hU rw [piecewise_preimage, ite_eq_of_subset_right _ (this U hU)] exact hU.preimage hf |>.inter hs |>.union (hU.preimage hg) theorem IsClosed.continuous_piecewise_of_specializes [DecidablePred (· ∈ s)] (hs : IsClosed s) (hf : Continuous f) (hg : Continuous g) (hspec : ∀ x, g x ⤳ f x) : Continuous (s.piecewise f g) := by simpa only [piecewise_compl] using hs.isOpen_compl.continuous_piecewise_of_specializes hg hf hspec attribute [local instance] specializationPreorder /-- A continuous function is monotone with respect to the specialization preorders on the domain and the codomain. -/ theorem Continuous.specialization_monotone (hf : Continuous f) : Monotone f := fun _ _ h => h.map hf lemma closure_singleton_eq_Iic (x : X) : closure {x} = Iic x := Set.ext fun _ ↦ specializes_iff_mem_closure.symm /-- A subset `S` of a topological space is stable under specialization if `x ∈ S → y ∈ S` for all `x ⤳ y`. -/ def StableUnderSpecialization (s : Set X) : Prop := ∀ ⦃x y⦄, x ⤳ y → x ∈ s → y ∈ s /-- A subset `S` of a topological space is stable under specialization if `x ∈ S → y ∈ S` for all `y ⤳ x`. -/ def StableUnderGeneralization (s : Set X) : Prop := ∀ ⦃x y⦄, y ⤳ x → x ∈ s → y ∈ s example {s : Set X} : StableUnderSpecialization s ↔ IsLowerSet s := Iff.rfl example {s : Set X} : StableUnderGeneralization s ↔ IsUpperSet s := Iff.rfl lemma IsClosed.stableUnderSpecialization {s : Set X} (hs : IsClosed s) : StableUnderSpecialization s := fun _ _ e ↦ e.mem_closed hs lemma IsOpen.stableUnderGeneralization {s : Set X} (hs : IsOpen s) : StableUnderGeneralization s := fun _ _ e ↦ e.mem_open hs @[simp] lemma stableUnderSpecialization_compl_iff {s : Set X} : StableUnderSpecialization sᶜ ↔ StableUnderGeneralization s := isLowerSet_compl @[simp] lemma stableUnderGeneralization_compl_iff {s : Set X} : StableUnderGeneralization sᶜ ↔ StableUnderSpecialization s := isUpperSet_compl alias ⟨_, StableUnderGeneralization.compl⟩ := stableUnderSpecialization_compl_iff alias ⟨_, StableUnderSpecialization.compl⟩ := stableUnderGeneralization_compl_iff lemma stableUnderSpecialization_univ : StableUnderSpecialization (univ : Set X) := isLowerSet_univ lemma stableUnderSpecialization_empty : StableUnderSpecialization (∅ : Set X) := isLowerSet_empty lemma stableUnderGeneralization_univ : StableUnderGeneralization (univ : Set X) := isUpperSet_univ lemma stableUnderGeneralization_empty : StableUnderGeneralization (∅ : Set X) := isUpperSet_empty lemma stableUnderSpecialization_sUnion (S : Set (Set X)) (H : ∀ s ∈ S, StableUnderSpecialization s) : StableUnderSpecialization (⋃₀ S) := isLowerSet_sUnion H lemma stableUnderSpecialization_sInter (S : Set (Set X)) (H : ∀ s ∈ S, StableUnderSpecialization s) : StableUnderSpecialization (⋂₀ S) := isLowerSet_sInter H lemma stableUnderGeneralization_sUnion (S : Set (Set X)) (H : ∀ s ∈ S, StableUnderGeneralization s) : StableUnderGeneralization (⋃₀ S) := isUpperSet_sUnion H lemma stableUnderGeneralization_sInter (S : Set (Set X)) (H : ∀ s ∈ S, StableUnderGeneralization s) : StableUnderGeneralization (⋂₀ S) := isUpperSet_sInter H lemma stableUnderSpecialization_iUnion {ι : Sort*} (S : ι → Set X) (H : ∀ i, StableUnderSpecialization (S i)) : StableUnderSpecialization (⋃ i, S i) := isLowerSet_iUnion H lemma stableUnderSpecialization_iInter {ι : Sort*} (S : ι → Set X) (H : ∀ i, StableUnderSpecialization (S i)) : StableUnderSpecialization (⋂ i, S i) := isLowerSet_iInter H lemma stableUnderGeneralization_iUnion {ι : Sort*} (S : ι → Set X) (H : ∀ i, StableUnderGeneralization (S i)) : StableUnderGeneralization (⋃ i, S i) := isUpperSet_iUnion H lemma stableUnderGeneralization_iInter {ι : Sort*} (S : ι → Set X) (H : ∀ i, StableUnderGeneralization (S i)) : StableUnderGeneralization (⋂ i, S i) := isUpperSet_iInter H lemma Union_closure_singleton_eq_iff {s : Set X} : (⋃ x ∈ s, closure {x}) = s ↔ StableUnderSpecialization s := show _ ↔ IsLowerSet s by simp only [closure_singleton_eq_Iic, ← lowerClosure_eq, coe_lowerClosure] lemma stableUnderSpecialization_iff_Union_eq {s : Set X} : StableUnderSpecialization s ↔ (⋃ x ∈ s, closure {x}) = s := Union_closure_singleton_eq_iff.symm alias ⟨StableUnderSpecialization.Union_eq, _⟩ := stableUnderSpecialization_iff_Union_eq /-- A set is stable under specialization iff it is a union of closed sets. -/ lemma stableUnderSpecialization_iff_exists_sUnion_eq {s : Set X} : StableUnderSpecialization s ↔ ∃ (S : Set (Set X)), (∀ s ∈ S, IsClosed s) ∧ ⋃₀ S = s := by refine ⟨fun H ↦ ⟨(fun x : X ↦ closure {x}) '' s, ?_, ?_⟩, fun ⟨S, hS, e⟩ ↦ e ▸ stableUnderSpecialization_sUnion S (fun x hx ↦ (hS x hx).stableUnderSpecialization)⟩ · rintro _ ⟨_, _, rfl⟩; exact isClosed_closure · conv_rhs => rw [← H.Union_eq] simp /-- A set is stable under generalization iff it is an intersection of open sets. -/ lemma stableUnderGeneralization_iff_exists_sInter_eq {s : Set X} : StableUnderGeneralization s ↔ ∃ (S : Set (Set X)), (∀ s ∈ S, IsOpen s) ∧ ⋂₀ S = s := by refine ⟨?_, fun ⟨S, hS, e⟩ ↦ e ▸ stableUnderGeneralization_sInter S (fun x hx ↦ (hS x hx).stableUnderGeneralization)⟩ rw [← stableUnderSpecialization_compl_iff, stableUnderSpecialization_iff_exists_sUnion_eq] exact fun ⟨S, h₁, h₂⟩ ↦ ⟨(·ᶜ) '' S, fun s ⟨t, ht, e⟩ ↦ e ▸ (h₁ t ht).isOpen_compl, compl_injective ((sUnion_eq_compl_sInter_compl S).symm.trans h₂)⟩ lemma StableUnderSpecialization.preimage {s : Set Y} (hs : StableUnderSpecialization s) (hf : Continuous f) : StableUnderSpecialization (f ⁻¹' s) := IsLowerSet.preimage hs hf.specialization_monotone lemma StableUnderGeneralization.preimage {s : Set Y} (hs : StableUnderGeneralization s) (hf : Continuous f) : StableUnderGeneralization (f ⁻¹' s) := IsUpperSet.preimage hs hf.specialization_monotone /-- A map `f` between topological spaces is specializing if specializations lifts along `f`, i.e. for each `f x' ⤳ y` there is some `x` with `x' ⤳ x` whose image is `y`. -/ def SpecializingMap (f : X → Y) : Prop := Relation.Fibration (flip (· ⤳ ·)) (flip (· ⤳ ·)) f /-- A map `f` between topological spaces is generalizing if generalizations lifts along `f`, i.e. for each `y ⤳ f x'` there is some `x ⤳ x'` whose image is `y`. -/ def GeneralizingMap (f : X → Y) : Prop := Relation.Fibration (· ⤳ ·) (· ⤳ ·) f lemma specializingMap_iff_closure_singleton_subset : SpecializingMap f ↔ ∀ x, closure {f x} ⊆ f '' closure {x} := by simp only [SpecializingMap, Relation.Fibration, flip, specializes_iff_mem_closure]; rfl alias ⟨SpecializingMap.closure_singleton_subset, _⟩ := specializingMap_iff_closure_singleton_subset lemma SpecializingMap.stableUnderSpecialization_image (hf : SpecializingMap f) {s : Set X} (hs : StableUnderSpecialization s) : StableUnderSpecialization (f '' s) := IsLowerSet.image_fibration hf hs alias StableUnderSpecialization.image := SpecializingMap.stableUnderSpecialization_image lemma specializingMap_iff_stableUnderSpecialization_image_singleton : SpecializingMap f ↔ ∀ x, StableUnderSpecialization (f '' closure {x}) := by simpa only [closure_singleton_eq_Iic] using Relation.fibration_iff_isLowerSet_image_Iic lemma specializingMap_iff_stableUnderSpecialization_image : SpecializingMap f ↔ ∀ s, StableUnderSpecialization s → StableUnderSpecialization (f '' s) := Relation.fibration_iff_isLowerSet_image lemma specializingMap_iff_closure_singleton (hf : Continuous f) : SpecializingMap f ↔ ∀ x, f '' closure {x} = closure {f x} := by simpa only [closure_singleton_eq_Iic] using Relation.fibration_iff_image_Iic hf.specialization_monotone lemma specializingMap_iff_isClosed_image_closure_singleton (hf : Continuous f) : SpecializingMap f ↔ ∀ x, IsClosed (f '' closure {x}) := by refine ⟨fun h x ↦ ?_, fun h ↦ specializingMap_iff_stableUnderSpecialization_image_singleton.mpr (fun x ↦ (h x).stableUnderSpecialization)⟩ rw [(specializingMap_iff_closure_singleton hf).mp h x] exact isClosed_closure lemma SpecializingMap.comp {f : X → Y} {g : Y → Z} (hf : SpecializingMap f) (hg : SpecializingMap g) : SpecializingMap (g ∘ f) := by simp only [specializingMap_iff_stableUnderSpecialization_image, Set.image_comp] at * exact fun s h ↦ hg _ (hf _ h) lemma IsClosedMap.specializingMap (hf : IsClosedMap f) : SpecializingMap f := specializingMap_iff_stableUnderSpecialization_image_singleton.mpr <| fun _ ↦ (hf _ isClosed_closure).stableUnderSpecialization lemma Topology.IsInducing.specializingMap (hf : IsInducing f) (h : StableUnderSpecialization (range f)) : SpecializingMap f := by intros x y e obtain ⟨y, rfl⟩ := h e ⟨x, rfl⟩ exact ⟨_, hf.specializes_iff.mp e, rfl⟩ lemma Topology.IsInducing.generalizingMap (hf : IsInducing f) (h : StableUnderGeneralization (range f)) : GeneralizingMap f := by intros x y e obtain ⟨y, rfl⟩ := h e ⟨x, rfl⟩ exact ⟨_, hf.specializes_iff.mp e, rfl⟩ lemma IsOpenEmbedding.generalizingMap (hf : IsOpenEmbedding f) : GeneralizingMap f := hf.isInducing.generalizingMap hf.isOpen_range.stableUnderGeneralization lemma SpecializingMap.stableUnderSpecialization_range (h : SpecializingMap f) : StableUnderSpecialization (range f) := @image_univ _ _ f ▸ stableUnderSpecialization_univ.image h lemma GeneralizingMap.stableUnderGeneralization_image (hf : GeneralizingMap f) {s : Set X} (hs : StableUnderGeneralization s) : StableUnderGeneralization (f '' s) := IsUpperSet.image_fibration hf hs lemma GeneralizingMap_iff_stableUnderGeneralization_image : GeneralizingMap f ↔ ∀ s, StableUnderGeneralization s → StableUnderGeneralization (f '' s) := Relation.fibration_iff_isUpperSet_image alias StableUnderGeneralization.image := GeneralizingMap.stableUnderGeneralization_image lemma GeneralizingMap.stableUnderGeneralization_range (h : GeneralizingMap f) : StableUnderGeneralization (range f) := @image_univ _ _ f ▸ stableUnderGeneralization_univ.image h lemma GeneralizingMap.comp {f : X → Y} {g : Y → Z} (hf : GeneralizingMap f) (hg : GeneralizingMap g) : GeneralizingMap (g ∘ f) := by simp only [GeneralizingMap_iff_stableUnderGeneralization_image, Set.image_comp] at * exact fun s h ↦ hg _ (hf _ h) /-! ### `Inseparable` relation -/ local infixl:0 " ~ᵢ " => Inseparable theorem inseparable_def : (x ~ᵢ y) ↔ 𝓝 x = 𝓝 y := Iff.rfl theorem inseparable_iff_specializes_and : (x ~ᵢ y) ↔ x ⤳ y ∧ y ⤳ x := le_antisymm_iff theorem Inseparable.specializes (h : x ~ᵢ y) : x ⤳ y := h.le theorem Inseparable.specializes' (h : x ~ᵢ y) : y ⤳ x := h.ge theorem Specializes.antisymm (h₁ : x ⤳ y) (h₂ : y ⤳ x) : x ~ᵢ y := le_antisymm h₁ h₂ theorem inseparable_iff_forall_isOpen : (x ~ᵢ y) ↔ ∀ s : Set X, IsOpen s → (x ∈ s ↔ y ∈ s) := by simp only [inseparable_iff_specializes_and, specializes_iff_forall_open, ← forall_and, ← iff_def, Iff.comm] theorem not_inseparable_iff_exists_open : ¬(x ~ᵢ y) ↔ ∃ s : Set X, IsOpen s ∧ Xor' (x ∈ s) (y ∈ s) := by simp [inseparable_iff_forall_isOpen, ← xor_iff_not_iff] theorem inseparable_iff_forall_isClosed : (x ~ᵢ y) ↔ ∀ s : Set X, IsClosed s → (x ∈ s ↔ y ∈ s) := by simp only [inseparable_iff_specializes_and, specializes_iff_forall_closed, ← forall_and, ← iff_def] theorem inseparable_iff_mem_closure : (x ~ᵢ y) ↔ x ∈ closure ({y} : Set X) ∧ y ∈ closure ({x} : Set X) := inseparable_iff_specializes_and.trans <| by simp only [specializes_iff_mem_closure, and_comm] theorem inseparable_iff_closure_eq : (x ~ᵢ y) ↔ closure ({x} : Set X) = closure {y} := by simp only [inseparable_iff_specializes_and, specializes_iff_closure_subset, ← subset_antisymm_iff, eq_comm] theorem inseparable_of_nhdsWithin_eq (hx : x ∈ s) (hy : y ∈ s) (h : 𝓝[s] x = 𝓝[s] y) : x ~ᵢ y := (specializes_of_nhdsWithin h.le hx).antisymm (specializes_of_nhdsWithin h.ge hy) theorem Topology.IsInducing.inseparable_iff (hf : IsInducing f) : (f x ~ᵢ f y) ↔ (x ~ᵢ y) := by simp only [inseparable_iff_specializes_and, hf.specializes_iff] theorem subtype_inseparable_iff {p : X → Prop} (x y : Subtype p) : (x ~ᵢ y) ↔ ((x : X) ~ᵢ y) := IsInducing.subtypeVal.inseparable_iff.symm @[simp] theorem inseparable_prod {x₁ x₂ : X} {y₁ y₂ : Y} : ((x₁, y₁) ~ᵢ (x₂, y₂)) ↔ (x₁ ~ᵢ x₂) ∧ (y₁ ~ᵢ y₂) := by simp only [Inseparable, nhds_prod_eq, prod_inj] theorem Inseparable.prod {x₁ x₂ : X} {y₁ y₂ : Y} (hx : x₁ ~ᵢ x₂) (hy : y₁ ~ᵢ y₂) : (x₁, y₁) ~ᵢ (x₂, y₂) := inseparable_prod.2 ⟨hx, hy⟩ @[simp] theorem inseparable_pi {f g : ∀ i, A i} : (f ~ᵢ g) ↔ ∀ i, f i ~ᵢ g i := by simp only [Inseparable, nhds_pi, funext_iff, pi_inj] namespace Inseparable @[refl] theorem refl (x : X) : x ~ᵢ x := Eq.refl (𝓝 x) theorem rfl : x ~ᵢ x := refl x theorem of_eq (e : x = y) : Inseparable x y := e ▸ refl x @[symm] nonrec theorem symm (h : x ~ᵢ y) : y ~ᵢ x := h.symm @[trans] nonrec theorem trans (h₁ : x ~ᵢ y) (h₂ : y ~ᵢ z) : x ~ᵢ z := h₁.trans h₂ theorem nhds_eq (h : x ~ᵢ y) : 𝓝 x = 𝓝 y := h theorem mem_open_iff (h : x ~ᵢ y) (hs : IsOpen s) : x ∈ s ↔ y ∈ s := inseparable_iff_forall_isOpen.1 h s hs theorem mem_closed_iff (h : x ~ᵢ y) (hs : IsClosed s) : x ∈ s ↔ y ∈ s := inseparable_iff_forall_isClosed.1 h s hs theorem map_of_continuousWithinAt {s t : Set X} (h : x ~ᵢ y) (hfx : ContinuousWithinAt f s x) (hfy : ContinuousWithinAt f t y) (hx : x ∈ t) (hy : y ∈ s) : f x ~ᵢ f y := (h.specializes.map_of_continuousWithinAt hfy hx).antisymm (h.specializes'.map_of_continuousWithinAt hfx hy) theorem map_of_continuousOn {s : Set X} (h : x ~ᵢ y) (hf : ContinuousOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ~ᵢ f y := h.map_of_continuousWithinAt (hf.continuousWithinAt hx) (hf.continuousWithinAt hy) hx hy theorem map_of_continuousAt (h : x ~ᵢ y) (hx : ContinuousAt f x) (hy : ContinuousAt f y) : f x ~ᵢ f y := h.map_of_continuousWithinAt hx.continuousWithinAt hy.continuousWithinAt (mem_univ x) (mem_univ y) theorem map (h : x ~ᵢ y) (hf : Continuous f) : f x ~ᵢ f y := h.map_of_continuousAt hf.continuousAt hf.continuousAt end Inseparable theorem IsClosed.not_inseparable (hs : IsClosed s) (hx : x ∈ s) (hy : y ∉ s) : ¬(x ~ᵢ y) := fun h => hy <| (h.mem_closed_iff hs).1 hx theorem IsOpen.not_inseparable (hs : IsOpen s) (hx : x ∈ s) (hy : y ∉ s) : ¬(x ~ᵢ y) := fun h => hy <| (h.mem_open_iff hs).1 hx /-! ### Separation quotient In this section we define the quotient of a topological space by the `Inseparable` relation. -/ variable (X) in instance : TopologicalSpace (SeparationQuotient X) := instTopologicalSpaceQuotient variable {t : Set (SeparationQuotient X)} namespace SeparationQuotient /-- The natural map from a topological space to its separation quotient. -/ def mk : X → SeparationQuotient X := Quotient.mk'' theorem isQuotientMap_mk : IsQuotientMap (mk : X → SeparationQuotient X) := isQuotientMap_quot_mk @[fun_prop, continuity] theorem continuous_mk : Continuous (mk : X → SeparationQuotient X) := continuous_quot_mk @[simp] theorem mk_eq_mk : mk x = mk y ↔ (x ~ᵢ y) := Quotient.eq'' theorem surjective_mk : Surjective (mk : X → SeparationQuotient X) := Quot.mk_surjective @[simp] theorem range_mk : range (mk : X → SeparationQuotient X) = univ := surjective_mk.range_eq instance [Nonempty X] : Nonempty (SeparationQuotient X) := Nonempty.map mk ‹_› instance [Inhabited X] : Inhabited (SeparationQuotient X) := ⟨mk default⟩ instance [Subsingleton X] : Subsingleton (SeparationQuotient X) := surjective_mk.subsingleton @[to_additive] instance [One X] : One (SeparationQuotient X) := ⟨mk 1⟩ @[to_additive (attr := simp)] theorem mk_one [One X] : mk (1 : X) = 1 := rfl theorem preimage_image_mk_open (hs : IsOpen s) : mk ⁻¹' (mk '' s) = s := by refine Subset.antisymm ?_ (subset_preimage_image _ _) rintro x ⟨y, hys, hxy⟩ exact ((mk_eq_mk.1 hxy).mem_open_iff hs).1 hys theorem isOpenMap_mk : IsOpenMap (mk : X → SeparationQuotient X) := fun s hs => isQuotientMap_mk.isOpen_preimage.1 <| by rwa [preimage_image_mk_open hs] theorem isOpenQuotientMap_mk : IsOpenQuotientMap (mk : X → SeparationQuotient X) := ⟨surjective_mk, continuous_mk, isOpenMap_mk⟩ theorem preimage_image_mk_closed (hs : IsClosed s) : mk ⁻¹' (mk '' s) = s := by refine Subset.antisymm ?_ (subset_preimage_image _ _) rintro x ⟨y, hys, hxy⟩ exact ((mk_eq_mk.1 hxy).mem_closed_iff hs).1 hys theorem isInducing_mk : IsInducing (mk : X → SeparationQuotient X) := ⟨le_antisymm (continuous_iff_le_induced.1 continuous_mk) fun s hs => ⟨mk '' s, isOpenMap_mk s hs, preimage_image_mk_open hs⟩⟩ theorem isClosedMap_mk : IsClosedMap (mk : X → SeparationQuotient X) := isInducing_mk.isClosedMap <| by rw [range_mk]; exact isClosed_univ @[simp] theorem comap_mk_nhds_mk : comap mk (𝓝 (mk x)) = 𝓝 x := (isInducing_mk.nhds_eq_comap _).symm @[simp] theorem comap_mk_nhdsSet_image : comap mk (𝓝ˢ (mk '' s)) = 𝓝ˢ s := (isInducing_mk.nhdsSet_eq_comap _).symm /-- Push-forward of the neighborhood of a point along the projection to the separation quotient is the neighborhood of its equivalence class. -/ theorem map_mk_nhds : map mk (𝓝 x) = 𝓝 (mk x) := by rw [← comap_mk_nhds_mk, map_comap_of_surjective surjective_mk] @[deprecated map_mk_nhds (since := "2025-03-21")] theorem nhds_mk (x : X) : 𝓝 (mk x) = .map mk (𝓝 x) := .symm <| map_mk_nhds .. theorem map_mk_nhdsSet : map mk (𝓝ˢ s) = 𝓝ˢ (mk '' s) := by rw [← comap_mk_nhdsSet_image, map_comap_of_surjective surjective_mk] theorem comap_mk_nhdsSet : comap mk (𝓝ˢ t) = 𝓝ˢ (mk ⁻¹' t) := by conv_lhs => rw [← image_preimage_eq t surjective_mk, comap_mk_nhdsSet_image] theorem preimage_mk_closure : mk ⁻¹' closure t = closure (mk ⁻¹' t) := isOpenMap_mk.preimage_closure_eq_closure_preimage continuous_mk t theorem preimage_mk_interior : mk ⁻¹' interior t = interior (mk ⁻¹' t) := isOpenMap_mk.preimage_interior_eq_interior_preimage continuous_mk t theorem preimage_mk_frontier : mk ⁻¹' frontier t = frontier (mk ⁻¹' t) := isOpenMap_mk.preimage_frontier_eq_frontier_preimage continuous_mk t theorem image_mk_closure : mk '' closure s = closure (mk '' s) := (image_closure_subset_closure_image continuous_mk).antisymm <| isClosedMap_mk.closure_image_subset _ theorem map_prod_map_mk_nhds (x : X) (y : Y) : map (Prod.map mk mk) (𝓝 (x, y)) = 𝓝 (mk x, mk y) := by rw [nhds_prod_eq, ← prod_map_map_eq', map_mk_nhds, map_mk_nhds, nhds_prod_eq] theorem map_mk_nhdsWithin_preimage (s : Set (SeparationQuotient X)) (x : X) : map mk (𝓝[mk ⁻¹' s] x) = 𝓝[s] mk x := by rw [nhdsWithin, ← comap_principal, Filter.push_pull, nhdsWithin, map_mk_nhds] /-- The map `(x, y) ↦ (mk x, mk y)` is a quotient map. -/ theorem isQuotientMap_prodMap_mk : IsQuotientMap (Prod.map mk mk : X × Y → _) := (isOpenQuotientMap_mk.prodMap isOpenQuotientMap_mk).isQuotientMap /-- Lift a map `f : X → α` such that `Inseparable x y → f x = f y` to a map `SeparationQuotient X → α`. -/ def lift (f : X → α) (hf : ∀ x y, (x ~ᵢ y) → f x = f y) : SeparationQuotient X → α := fun x => Quotient.liftOn' x f hf @[simp] theorem lift_mk {f : X → α} (hf : ∀ x y, (x ~ᵢ y) → f x = f y) (x : X) : lift f hf (mk x) = f x := rfl @[simp] theorem lift_comp_mk {f : X → α} (hf : ∀ x y, (x ~ᵢ y) → f x = f y) : lift f hf ∘ mk = f := rfl @[simp] theorem tendsto_lift_nhds_mk {f : X → α} {hf : ∀ x y, (x ~ᵢ y) → f x = f y} {l : Filter α} : Tendsto (lift f hf) (𝓝 <| mk x) l ↔ Tendsto f (𝓝 x) l := by simp only [← map_mk_nhds, tendsto_map'_iff, lift_comp_mk] @[simp] theorem tendsto_lift_nhdsWithin_mk {f : X → α} {hf : ∀ x y, (x ~ᵢ y) → f x = f y} {s : Set (SeparationQuotient X)} {l : Filter α} : Tendsto (lift f hf) (𝓝[s] mk x) l ↔ Tendsto f (𝓝[mk ⁻¹' s] x) l := by simp only [← map_mk_nhdsWithin_preimage, tendsto_map'_iff, lift_comp_mk] @[simp] theorem continuousAt_lift {hf : ∀ x y, (x ~ᵢ y) → f x = f y} : ContinuousAt (lift f hf) (mk x) ↔ ContinuousAt f x := tendsto_lift_nhds_mk @[simp] theorem continuousWithinAt_lift {hf : ∀ x y, (x ~ᵢ y) → f x = f y} {s : Set (SeparationQuotient X)} : ContinuousWithinAt (lift f hf) s (mk x) ↔ ContinuousWithinAt f (mk ⁻¹' s) x := tendsto_lift_nhdsWithin_mk @[simp] theorem continuousOn_lift {hf : ∀ x y, (x ~ᵢ y) → f x = f y} {s : Set (SeparationQuotient X)} : ContinuousOn (lift f hf) s ↔ ContinuousOn f (mk ⁻¹' s) := by simp only [ContinuousOn, surjective_mk.forall, continuousWithinAt_lift, mem_preimage] @[simp] theorem continuous_lift {hf : ∀ x y, (x ~ᵢ y) → f x = f y} : Continuous (lift f hf) ↔ Continuous f := by simp only [← continuousOn_univ, continuousOn_lift, preimage_univ] /-- Lift a map `f : X → Y → α` such that `Inseparable a b → Inseparable c d → f a c = f b d` to a map `SeparationQuotient X → SeparationQuotient Y → α`. -/ def lift₂ (f : X → Y → α) (hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d) : SeparationQuotient X → SeparationQuotient Y → α := fun x y => Quotient.liftOn₂' x y f hf @[simp] theorem lift₂_mk {f : X → Y → α} (hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d) (x : X) (y : Y) : lift₂ f hf (mk x) (mk y) = f x y := rfl @[simp] theorem tendsto_lift₂_nhds {f : X → Y → α} {hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d} {x : X} {y : Y} {l : Filter α} : Tendsto (uncurry <| lift₂ f hf) (𝓝 (mk x, mk y)) l ↔ Tendsto (uncurry f) (𝓝 (x, y)) l := by rw [← map_prod_map_mk_nhds, tendsto_map'_iff] rfl @[simp] theorem tendsto_lift₂_nhdsWithin {f : X → Y → α} {hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d} {x : X} {y : Y} {s : Set (SeparationQuotient X × SeparationQuotient Y)} {l : Filter α} : Tendsto (uncurry <| lift₂ f hf) (𝓝[s] (mk x, mk y)) l ↔ Tendsto (uncurry f) (𝓝[Prod.map mk mk ⁻¹' s] (x, y)) l := by rw [nhdsWithin, ← map_prod_map_mk_nhds, ← Filter.push_pull, comap_principal] rfl @[simp] theorem continuousAt_lift₂ {f : X → Y → Z} {hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d} {x : X} {y : Y} : ContinuousAt (uncurry <| lift₂ f hf) (mk x, mk y) ↔ ContinuousAt (uncurry f) (x, y) := tendsto_lift₂_nhds @[simp] theorem continuousWithinAt_lift₂ {f : X → Y → Z} {hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d} {s : Set (SeparationQuotient X × SeparationQuotient Y)} {x : X} {y : Y} : ContinuousWithinAt (uncurry <| lift₂ f hf) s (mk x, mk y) ↔ ContinuousWithinAt (uncurry f) (Prod.map mk mk ⁻¹' s) (x, y) := tendsto_lift₂_nhdsWithin @[simp] theorem continuousOn_lift₂ {f : X → Y → Z} {hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d} {s : Set (SeparationQuotient X × SeparationQuotient Y)} : ContinuousOn (uncurry <| lift₂ f hf) s ↔ ContinuousOn (uncurry f) (Prod.map mk mk ⁻¹' s) := by simp_rw [ContinuousOn, (surjective_mk.prodMap surjective_mk).forall, Prod.forall, Prod.map, continuousWithinAt_lift₂] rfl @[simp] theorem continuous_lift₂ {f : X → Y → Z} {hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d} : Continuous (uncurry <| lift₂ f hf) ↔ Continuous (uncurry f) := by simp only [← continuousOn_univ, continuousOn_lift₂, preimage_univ] end SeparationQuotient theorem continuous_congr_of_inseparable (h : ∀ x, f x ~ᵢ g x) : Continuous f ↔ Continuous g := by simp_rw [SeparationQuotient.isInducing_mk.continuous_iff (Y := Y)] exact continuous_congr fun x ↦ SeparationQuotient.mk_eq_mk.mpr (h x)
slim_check.lean
import Mathlib.Algebra.Group.Fin.Basic import Mathlib.Data.DFinsupp.Defs import Mathlib.Data.Finsupp.Notation import Mathlib.Data.Nat.Prime.Defs import Mathlib.Data.PNat.Basic import Mathlib.Tactic.Have import Mathlib.Tactic.SuccessIfFailWithMsg import Mathlib.Testing.Plausible.Functions import Mathlib.Testing.Plausible.Sampleable import Plausible private axiom test_sorry : ∀ {α}, α /-- error: =================== Found a counter-example! x := 104 guard: ⋯ issue: 104 < 100 does not hold (0 shrinks) ------------------- -/ #guard_msgs in example : ∀ x : ℕ, 2 ∣ x → x < 100 := by plausible (config := { randomSeed := some 257, maxSize := 200 }) -- example (xs : List ℕ) (w : ∃ x ∈ xs, x < 3) : true := by -- have : ∀ y ∈ xs, y < 5 -- success_if_fail_with_msg -- " -- =================== -- Found problems! -- xs := [5, 5, 0, 1] -- x := 0 -- y := 5 -- issue: 5 < 5 does not hold -- (5 shrinks) -- ------------------- -- " -- plausible (config := { randomSeed := some 257 }) -- admit -- trivial example (x : ℕ) (_h : 2 ∣ x) : true := by have : x < 100 := by success_if_fail_with_msg " =================== Found a counter-example! x := 104 guard: ⋯ issue: 104 < 100 does not hold (0 shrinks) ------------------- " plausible (config := { randomSeed := some 257, maxSize := 200 }) exact test_sorry trivial open Function Plausible -- Porting note: the "small" functor provided in mathlib3's `Sampleable.lean` was not ported, -- so we should not expect this to work. -- example (f : ℤ → ℤ) (h : Injective f) : true := by -- have : Monotone (f ∘ small.mk) -- success_if_fail_with_msg -- " -- =================== -- Found problems! -- f := [2 ↦ 3, 3 ↦ 9, 4 ↦ 6, 5 ↦ 4, 6 ↦ 2, 8 ↦ 5, 9 ↦ 8, x ↦ x] -- x := 3 -- y := 4 -- guard: 3 ≤ 4 (by construction) -- issue: 9 ≤ 6 does not hold -- (5 shrinks) -- ------------------- -- " -- plausible (config := { randomSeed := some 257 }) -- admit -- trivial /-- error: =================== Found a counter-example! f := [x ↦ x] guard: ⋯ (by construction) g := [0 => 0, 1 => 3, 2 => 1, 3 => 2, x ↦ x] guard: ⋯ (by construction) i := 1 issue: 1 = 3 does not hold (2 shrinks) ------------------- -/ #guard_msgs in example (f : ℤ → ℤ) (_h : Injective f) (g : ℤ → ℤ) (_h : Injective g) (i : ℤ) : f i = g i := by plausible (config := { randomSeed := some 257 }) /-- error: =================== Found a counter-example! f := [-2 => 8, -3 => -5, -5 => -3, 8 => -2, x ↦ x] guard: ⋯ (by construction) x := -2 y := 0 guard: -2 ≤ 0 issue: 8 ≤ 0 does not hold (7 shrinks) ------------------- -/ #guard_msgs in example (f : ℤ → ℤ) (_h : Injective f) : Monotone f := by plausible (config := { randomSeed := some 257 }) /-- error: =================== Found a counter-example! f := [_ => 0] x := 0 y := 1 guard: 0 = 0 issue: 0 = 1 does not hold (5 shrinks) ------------------- -/ #guard_msgs in example (f : ℤ → ℤ) : Injective f := by plausible (config := { randomSeed := some 257 }) /-- error: =================== Found a counter-example! f := [-2 => 5, -4 => 0, _ => 0] x := -2 y := 1 guard: -2 ≤ 1 issue: 5 ≤ 0 does not hold (3 shrinks) ------------------- -/ #guard_msgs in example (f : ℤ → ℤ) : Monotone f := by plausible (config := { randomSeed := some 257 }) -- TODO: fails without this line! attribute [-instance] Finsupp.instRepr in example (f : ℕ →₀ ℕ) : true := by have : f = 0 := by success_if_fail_with_msg " =================== Found a counter-example! f := [1 => 1, _ => 0] issue: ⋯ does not hold (1 shrinks) ------------------- " plausible (config := { randomSeed := some 257 }) exact test_sorry trivial example (f : Π₀ _n : ℕ, ℕ) : true := by have : f.update 0 0 = 0 := by success_if_fail_with_msg " =================== Found a counter-example! f := [1 => 1, _ => 0] issue: ⋯ does not hold (1 shrinks) ------------------- " plausible (config := { randomSeed := some 257 }) exact test_sorry trivial example (n : ℕ) : true := by have : ∑ f : Unit → Fin (n + 1), f () = 0 := by success_if_fail_with_msg " =================== Found a counter-example! n := 1 issue: 1 = 0 does not hold (0 shrinks) ------------------- " plausible (config := { randomSeed := some 257 }) exact test_sorry trivial -- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/slim_check.20question/near/412709012 /-- info: Unable to find a counter-example --- warning: declaration uses 'sorry' -/ #guard_msgs in example (q : ℕ) : q = 0 ∨ q ≥ 2 ∨ 8 = ∑ k ∈ Finset.range 2, 5 ^ k * Nat.choose (2 * q + 1) (2 * k + 1) := by plausible -- https://github.com/leanprover-community/mathlib4/issues/12565 -- Make `plausible` handle `Fact` instances. /-- error: =================== Found a counter-example! a := 7 guard: ⋯ issue: ⋯ does not hold issue: ⋯ does not hold (0 shrinks) ------------------- -/ #guard_msgs in example {a : ℕ} [Fact a.Prime] : (a + 1).Prime ∨ (a + 2).Prime := by plausible (config := { randomSeed := some 257 }) /-- error: =================== Found a counter-example! x := 4 issue: 64 < 42 does not hold (0 shrinks) ------------------- -/ #guard_msgs in example (x : PNat) : x^3 < 2*x^2 + 10:= by plausible (config := { randomSeed := some 257 })
numfield.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 ssrAC div fintype path bigop order finset fingroup. From mathcomp Require Import ssralg poly orderedzmod numdomain. (******************************************************************************) (* Number structures *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* This file defines some classes to manipulate number structures, i.e, *) (* structures with an order and a norm. To use this file, insert *) (* "Import Num.Theory." before your scripts. You can also "Import Num.Def." *) (* to enjoy shorter notations (e.g., minr instead of Num.min, lerif instead *) (* of Num.leif, etc.). *) (* *) (* This file defines the following number structures: *) (* *) (* numFieldType == Field with an order and a norm *) (* The HB class is called NumField. *) (* numClosedFieldType == Partially ordered Closed Field with conjugation *) (* The HB class is called ClosedField. *) (* realDomainType == Num domain where all elements are positive or negative *) (* The HB class is called RealDomain. *) (* realFieldType == Num Field where all elements are positive or negative *) (* The HB class is called RealField. *) (* rcfType == A Real Field with the real closed axiom *) (* The HB class is called RealClosedField. *) (* *) (* Over these structures, we have the following operation: *) (* Num.sqrt x == in a real-closed field, a positive square root of x if *) (* x >= 0, or 0 otherwise *) (* For numeric algebraically closed fields we provide the generic definitions *) (* 'i == the imaginary number (:= sqrtC (-1)) *) (* 'Re z == the real component of z *) (* 'Im z == the imaginary component of z *) (* z^* == the complex conjugate of z (:= conjC z) *) (* sqrtC z == a nonnegative square root of z, i.e., 0 <= sqrt x if 0 <= x *) (* n.-root z == more generally, for n > 0, an nth root of z, chosen with a *) (* minimal non-negative argument for n > 1 (i.e., with a *) (* maximal real part subject to a nonnegative imaginary part) *) (* Note that n.-root (-1) is a primitive 2nth root of unity, *) (* an thus not equal to -1 for n odd > 1 (this will be shown in *) (* file cyclotomic.v). *) (* *) (* - list of prefixes : *) (* p : positive *) (* n : negative *) (* sp : strictly positive *) (* sn : strictly negative *) (* i : interior = in [0, 1] or ]0, 1[ *) (* e : exterior = in [1, +oo[ or ]1; +oo[ *) (* w : non strict (weak) monotony *) (* *) (* Pdeg2.NumClosed : theory of the degree 2 polynomials on NumClosedField. *) (* Pdeg2.NumClosedMonic : theory of Pdeg2.NumClosed specialized to monic *) (* polynomials. *) (* Pdeg2.Real : theory of the degree 2 polynomials on RealField and rcfType. *) (* Pdeg2.RealMonic : theory of Pdeg2.Real specialized to monic polynomials. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope order_scope. Local Open Scope group_scope. Local Open Scope ring_scope. Import Order.TTheory GRing.Theory. Import orderedzmod.Num numdomain.Num. Module Num. #[short(type="numFieldType")] HB.structure Definition NumField := { R of GRing.UnitRing_isField R & GRing.IntegralDomain R & POrderedZmodule R & NormedZmodule (POrderedZmodule.clone R _) R & isNumRing R }. Module NumFieldExports. Bind Scope ring_scope with NumField.sort. End NumFieldExports. HB.export NumFieldExports. HB.mixin Record NumField_isImaginary R of NumField R := { imaginary : R; conj_op : {rmorphism R -> R}; sqrCi : imaginary ^+ 2 = - 1; normCK : forall x, `|x| ^+ 2 = x * conj_op x; }. #[short(type="numClosedFieldType")] HB.structure Definition ClosedField := { R of NumField_isImaginary R & GRing.ClosedField R & NumField R }. Module ClosedFieldExports. Bind Scope ring_scope with ClosedField.sort. End ClosedFieldExports. HB.export ClosedFieldExports. #[short(type="realFieldType")] HB.structure Definition RealField := { R of Order.Total ring_display R & NumField R }. Module RealFieldExports. Bind Scope ring_scope with RealField.sort. End RealFieldExports. HB.export RealFieldExports. HB.mixin Record RealField_isClosed R of RealField R := { poly_ivt_subproof : real_closed_axiom R }. #[short(type="rcfType")] HB.structure Definition RealClosedField := { R of RealField_isClosed R & RealField R }. Module RealClosedFieldExports. Bind Scope ring_scope with RealClosedField.sort. End RealClosedFieldExports. HB.export RealClosedFieldExports. Section RealClosed. Variable R : rcfType. Lemma poly_ivt : real_closed_axiom R. Proof. exact: poly_ivt_subproof. Qed. Fact sqrtr_subproof (x : R) : exists2 y, 0 <= y & (if 0 <= x then y ^+ 2 == x else y == 0) : bool. Proof. case x_ge0: (0 <= x); last by exists 0. have le0x1: 0 <= x + 1 by rewrite -nnegrE rpredD ?rpred1. have [|y /andP[y_ge0 _]] := @poly_ivt ('X^2 - x%:P) _ _ le0x1. rewrite !hornerE -subr_ge0 add0r expr0n sub0r opprK x_ge0 sqrrD mulr1. by rewrite addrAC !addrA addrK -nnegrE !rpredD ?rpredX ?rpred1. by rewrite rootE !hornerE subr_eq0; exists y. Qed. End RealClosed. Module Import Def. Definition sqrtr {R} x := s2val (sig2W (@sqrtr_subproof R x)). End Def. Notation sqrt := sqrtr. Module Export Theory. Section NumFieldTheory. Variable F : numFieldType. Implicit Types x y z t : F. Lemma unitf_gt0 x : 0 < x -> x \is a GRing.unit. Proof. by move=> hx; rewrite unitfE eq_sym lt_eqF. Qed. Lemma unitf_lt0 x : x < 0 -> x \is a GRing.unit. Proof. by move=> hx; rewrite unitfE lt_eqF. Qed. Lemma lef_pV2 : {in pos &, {mono (@GRing.inv F) : x y /~ x <= y}}. Proof. by move=> x y hx hy /=; rewrite ler_pV2 ?inE ?unitf_gt0. Qed. Lemma lef_nV2 : {in neg &, {mono (@GRing.inv F) : x y /~ x <= y}}. Proof. by move=> x y hx hy /=; rewrite ler_nV2 ?inE ?unitf_lt0. Qed. Lemma ltf_pV2 : {in pos &, {mono (@GRing.inv F) : x y /~ x < y}}. Proof. exact: leW_nmono_in lef_pV2. Qed. Lemma ltf_nV2 : {in neg &, {mono (@GRing.inv F) : x y /~ x < y}}. Proof. exact: leW_nmono_in lef_nV2. Qed. Definition ltef_pV2 := (lef_pV2, ltf_pV2). Definition ltef_nV2 := (lef_nV2, ltf_nV2). Lemma invf_pgt : {in pos &, forall x y, (x < y^-1) = (y < x^-1)}. Proof. by move=> x y *; rewrite -[x in LHS]invrK ltf_pV2// posrE invr_gt0. Qed. Lemma invf_pge : {in pos &, forall x y, (x <= y^-1) = (y <= x^-1)}. Proof. by move=> x y *; rewrite -[x in LHS]invrK lef_pV2// posrE invr_gt0. Qed. Lemma invf_ngt : {in neg &, forall x y, (x < y^-1) = (y < x^-1)}. Proof. by move=> x y *; rewrite -[x in LHS]invrK ltf_nV2// negrE invr_lt0. Qed. Lemma invf_nge : {in neg &, forall x y, (x <= y^-1) = (y <= x^-1)}. Proof. by move=> x y *; rewrite -[x in LHS]invrK lef_nV2// negrE invr_lt0. Qed. Lemma invf_gt1 x : 0 < x -> (1 < x^-1) = (x < 1). Proof. by move=> x0; rewrite invf_pgt ?invr1 ?posrE. Qed. Lemma invf_ge1 x : 0 < x -> (1 <= x^-1) = (x <= 1). Proof. by move=> x0; rewrite invf_pge ?invr1 ?posrE. Qed. Definition invf_gte1 := (invf_ge1, invf_gt1). Lemma invf_plt : {in pos &, forall x y, (x^-1 < y) = (y^-1 < x)}. Proof. by move=> x y *; rewrite -[y in LHS]invrK ltf_pV2// posrE invr_gt0. Qed. Lemma invf_ple : {in pos &, forall x y, (x^-1 <= y) = (y^-1 <= x)}. Proof. by move=> x y *; rewrite -[y in LHS]invrK lef_pV2// posrE invr_gt0. Qed. Lemma invf_nlt : {in neg &, forall x y, (x^-1 < y) = (y^-1 < x)}. Proof. by move=> x y *; rewrite -[y in LHS]invrK ltf_nV2// negrE invr_lt0. Qed. Lemma invf_nle : {in neg &, forall x y, (x^-1 <= y) = (y^-1 <= x)}. Proof. by move=> x y *; rewrite -[y in LHS]invrK lef_nV2// negrE invr_lt0. Qed. Lemma invf_le1 x : 0 < x -> (x^-1 <= 1) = (1 <= x). Proof. by move=> x0; rewrite -invf_ple ?invr1 ?posrE. Qed. Lemma invf_lt1 x : 0 < x -> (x^-1 < 1) = (1 < x). Proof. by move=> x0; rewrite invf_plt ?invr1 ?posrE. Qed. Definition invf_lte1 := (invf_le1, invf_lt1). Definition invf_cp1 := (invf_gte1, invf_lte1). (* These lemma are all combinations of mono(LR|RL) with ler_[pn]mul2[rl]. *) Lemma ler_pdivlMr z x y : 0 < z -> (x <= y / z) = (x * z <= y). Proof. by move=> z_gt0; rewrite -(@ler_pM2r _ z _ x) ?mulfVK ?gt_eqF. Qed. Lemma ltr_pdivlMr z x y : 0 < z -> (x < y / z) = (x * z < y). Proof. by move=> z_gt0; rewrite -(@ltr_pM2r _ z _ x) ?mulfVK ?gt_eqF. Qed. Definition lter_pdivlMr := (ler_pdivlMr, ltr_pdivlMr). Lemma ler_pdivrMr z x y : 0 < z -> (y / z <= x) = (y <= x * z). Proof. by move=> z_gt0; rewrite -(@ler_pM2r _ z) ?mulfVK ?gt_eqF. Qed. Lemma ltr_pdivrMr z x y : 0 < z -> (y / z < x) = (y < x * z). Proof. by move=> z_gt0; rewrite -(@ltr_pM2r _ z) ?mulfVK ?gt_eqF. Qed. Definition lter_pdivrMr := (ler_pdivrMr, ltr_pdivrMr). Lemma ler_pdivlMl z x y : 0 < z -> (x <= z^-1 * y) = (z * x <= y). Proof. by move=> z_gt0; rewrite mulrC ler_pdivlMr ?[z * _]mulrC. Qed. Lemma ltr_pdivlMl z x y : 0 < z -> (x < z^-1 * y) = (z * x < y). Proof. by move=> z_gt0; rewrite mulrC ltr_pdivlMr ?[z * _]mulrC. Qed. Definition lter_pdivlMl := (ler_pdivlMl, ltr_pdivlMl). Lemma ler_pdivrMl z x y : 0 < z -> (z^-1 * y <= x) = (y <= z * x). Proof. by move=> z_gt0; rewrite mulrC ler_pdivrMr ?[z * _]mulrC. Qed. Lemma ltr_pdivrMl z x y : 0 < z -> (z^-1 * y < x) = (y < z * x). Proof. by move=> z_gt0; rewrite mulrC ltr_pdivrMr ?[z * _]mulrC. Qed. Definition lter_pdivrMl := (ler_pdivrMl, ltr_pdivrMl). Lemma ler_ndivlMr z x y : z < 0 -> (x <= y / z) = (y <= x * z). Proof. by move=> z_lt0; rewrite -(@ler_nM2r _ z) ?mulfVK ?lt_eqF. Qed. Lemma ltr_ndivlMr z x y : z < 0 -> (x < y / z) = (y < x * z). Proof. by move=> z_lt0; rewrite -(@ltr_nM2r _ z) ?mulfVK ?lt_eqF. Qed. Definition lter_ndivlMr := (ler_ndivlMr, ltr_ndivlMr). Lemma ler_ndivrMr z x y : z < 0 -> (y / z <= x) = (x * z <= y). Proof. by move=> z_lt0; rewrite -(@ler_nM2r _ z) ?mulfVK ?lt_eqF. Qed. Lemma ltr_ndivrMr z x y : z < 0 -> (y / z < x) = (x * z < y). Proof. by move=> z_lt0; rewrite -(@ltr_nM2r _ z) ?mulfVK ?lt_eqF. Qed. Definition lter_ndivrMr := (ler_ndivrMr, ltr_ndivrMr). Lemma ler_ndivlMl z x y : z < 0 -> (x <= z^-1 * y) = (y <= z * x). Proof. by move=> z_lt0; rewrite mulrC ler_ndivlMr ?[z * _]mulrC. Qed. Lemma ltr_ndivlMl z x y : z < 0 -> (x < z^-1 * y) = (y < z * x). Proof. by move=> z_lt0; rewrite mulrC ltr_ndivlMr ?[z * _]mulrC. Qed. Definition lter_ndivlMl := (ler_ndivlMl, ltr_ndivlMl). Lemma ler_ndivrMl z x y : z < 0 -> (z^-1 * y <= x) = (z * x <= y). Proof. by move=> z_lt0; rewrite mulrC ler_ndivrMr ?[z * _]mulrC. Qed. Lemma ltr_ndivrMl z x y : z < 0 -> (z^-1 * y < x) = (z * x < y). Proof. by move=> z_lt0; rewrite mulrC ltr_ndivrMr ?[z * _]mulrC. Qed. Definition lter_ndivrMl := (ler_ndivrMl, ltr_ndivrMl). Lemma natf_div m d : (d %| m)%N -> (m %/ d)%:R = m%:R / d%:R :> F. Proof. by apply: pchar0_natf_div; apply: (@pchar_num F). Qed. Lemma normfV : {morph (norm : F -> F) : x / x ^-1}. Proof. move=> x /=; have [/normrV //|Nux] := boolP (x \is a GRing.unit). by rewrite !invr_out // unitfE normr_eq0 -unitfE. Qed. Lemma normf_div : {morph (norm : F -> F) : x y / x / y}. Proof. by move=> x y /=; rewrite normrM normfV. Qed. Lemma invr_sg x : (sg x)^-1 = sgr x. Proof. by rewrite !(fun_if GRing.inv) !(invr0, invrN, invr1). Qed. Lemma sgrV x : sgr x^-1 = sgr x. Proof. by rewrite /sgr invr_eq0 invr_lt0. Qed. Lemma splitr x : x = x / 2%:R + x / 2%:R. Proof. by rewrite -mulr2n -[RHS]mulr_natr mulfVK //= pnatr_eq0. Qed. (* lteif *) Lemma lteif_pdivlMr C z x y : 0 < z -> x < y / z ?<= if C = (x * z < y ?<= if C). Proof. by case: C => ? /=; rewrite lter_pdivlMr. Qed. Lemma lteif_pdivrMr C z x y : 0 < z -> y / z < x ?<= if C = (y < x * z ?<= if C). Proof. by case: C => ? /=; rewrite lter_pdivrMr. Qed. Lemma lteif_pdivlMl C z x y : 0 < z -> x < z^-1 * y ?<= if C = (z * x < y ?<= if C). Proof. by case: C => ? /=; rewrite lter_pdivlMl. Qed. Lemma lteif_pdivrMl C z x y : 0 < z -> z^-1 * y < x ?<= if C = (y < z * x ?<= if C). Proof. by case: C => ? /=; rewrite lter_pdivrMl. Qed. Lemma lteif_ndivlMr C z x y : z < 0 -> x < y / z ?<= if C = (y < x * z ?<= if C). Proof. by case: C => ? /=; rewrite lter_ndivlMr. Qed. Lemma lteif_ndivrMr C z x y : z < 0 -> y / z < x ?<= if C = (x * z < y ?<= if C). Proof. by case: C => ? /=; rewrite lter_ndivrMr. Qed. Lemma lteif_ndivlMl C z x y : z < 0 -> x < z^-1 * y ?<= if C = (y < z * x ?<= if C). Proof. by case: C => ? /=; rewrite lter_ndivlMl. Qed. Lemma lteif_ndivrMl C z x y : z < 0 -> z^-1 * y < x ?<= if C = (z * x < y ?<= if C). Proof. by case: C => ? /=; rewrite lter_ndivrMl. Qed. (* Interval midpoint. *) Local Notation mid x y := ((x + y) / 2). Lemma midf_le x y : x <= y -> (x <= mid x y) * (mid x y <= y). Proof. move=> lexy; rewrite ler_pdivlMr ?ler_pdivrMr ?ltr0Sn //. by rewrite !mulrDr !mulr1 !lerD2. Qed. Lemma midf_lt x y : x < y -> (x < mid x y) * (mid x y < y). Proof. move=> ltxy; rewrite ltr_pdivlMr ?ltr_pdivrMr ?ltr0Sn //. by rewrite !mulrDr !mulr1 !ltrD2. Qed. Definition midf_lte := (midf_le, midf_lt). Lemma ler_addgt0Pr x y : reflect (forall e, e > 0 -> x <= y + e) (x <= y). Proof. apply/(iffP idP)=> [lexy e e_gt0 | lexye]; first by rewrite ler_wpDr// ltW. have [||ltyx]// := comparable_leP. rewrite (@comparabler_trans _ (y + 1))// /Order.comparable ?lexye ?ltr01//. by rewrite lerDl ler01 orbT. have /midf_lt [_] := ltyx; rewrite le_gtF//. rewrite -(@addrK _ y y) (addrAC _ _ x) -addrA 2!mulrDl -splitr lexye//. by rewrite divr_gt0// ?ltr0n// subr_gt0. Qed. Lemma ler_addgt0Pl x y : reflect (forall e, e > 0 -> x <= e + y) (x <= y). Proof. by apply/(equivP (ler_addgt0Pr x y)); split=> lexy e /lexy; rewrite addrC. Qed. Lemma lt_le a b : (forall x, x < a -> x < b) -> a <= b. Proof. move=> ab; apply/ler_addgt0Pr => e e_gt0; rewrite -lerBDr ltW//. by rewrite ab// ltrBlDr ltrDl. Qed. Lemma gt_ge a b : (forall x, b < x -> a < x) -> a <= b. Proof. by move=> ab; apply/ler_addgt0Pr => e e_gt0; rewrite ltW// ab// ltrDl. Qed. (* The AGM, unscaled but without the nth root. *) Lemma real_leif_mean_square x y : x \is real -> y \is real -> x * y <= mid (x ^+ 2) (y ^+ 2) ?= iff (x == y). Proof. move=> Rx Ry; rewrite -(mono_leif (ler_pM2r (ltr_nat F 0 2))). by rewrite divfK ?pnatr_eq0 // mulr_natr; apply: real_leif_mean_square_scaled. Qed. Lemma real_leif_AGM2 x y : x \is real -> y \is real -> x * y <= mid x y ^+ 2 ?= iff (x == y). Proof. move=> Rx Ry; rewrite -(mono_leif (ler_pM2r (ltr_nat F 0 4))). rewrite mulr_natr (natrX F 2 2) -exprMn divfK ?pnatr_eq0 //. exact: real_leif_AGM2_scaled. Qed. Lemma leif_AGM (I : finType) (A : {pred I}) (E : I -> F) : let n := #|A| in let mu := (\sum_(i in A) E i) / n%:R in {in A, forall i, 0 <= E i} -> \prod_(i in A) E i <= mu ^+ n ?= iff [forall i in A, forall j in A, E i == E j]. Proof. move=> n mu Ege0; have [n0 | n_gt0] := posnP n. by rewrite n0 -big_andE !(big_pred0 _ _ _ _ (card0_eq n0)); apply/leifP. pose E' i := E i / n%:R. have defE' i: E' i *+ n = E i by rewrite -mulr_natr divfK ?pnatr_eq0 -?lt0n. have /leif_AGM_scaled (i): i \in A -> 0 <= E' i *+ n by rewrite defE' => /Ege0. rewrite -/n -mulr_suml (eq_bigr _ (in1W defE')); congr (_ <= _ ?= iff _). by do 2![apply: eq_forallb_in => ? _]; rewrite -(eqr_pMn2r n_gt0) !defE'. Qed. Implicit Type p : {poly F}. Lemma Cauchy_root_bound p : p != 0 -> {b | forall x, root p x -> `|x| <= b}. Proof. move=> nz_p; set a := lead_coef p; set n := (size p).-1. have [q Dp]: {q | forall x, x != 0 -> p.[x] = (a - q.[x^-1] / x) * x ^+ n}. exists (- \poly_(i < n) p`_(n - i.+1)) => x nz_x. rewrite hornerN mulNr opprK horner_poly mulrDl !mulr_suml addrC. rewrite horner_coef polySpred // big_ord_recr (reindex_inj rev_ord_inj) /=. rewrite -/n -lead_coefE; congr (_ + _); apply: eq_bigr=> i _. by rewrite exprB ?unitfE // -exprVn mulrA mulrAC exprSr mulrA. have [b ub_q] := poly_disk_bound q 1; exists (b / `|a| + 1) => x px0. have b_ge0: 0 <= b by rewrite (le_trans (normr_ge0 q.[1])) ?ub_q ?normr1. have{b_ge0} ba_ge0: 0 <= b / `|a| by rewrite divr_ge0. rewrite real_leNgt ?rpredD ?rpred1 ?ger0_real //. apply: contraL px0 => lb_x; rewrite rootE. have x_ge1: 1 <= `|x| by rewrite (le_trans _ (ltW lb_x)) // ler_wpDl. have nz_x: x != 0 by rewrite -normr_gt0 (lt_le_trans ltr01). rewrite {}Dp // mulf_neq0 ?expf_neq0 // subr_eq0 eq_sym. have: (b / `|a|) < `|x| by rewrite (lt_trans _ lb_x) // ltr_pwDr ?ltr01. apply: contraTneq => /(canRL (divfK nz_x))Dax. rewrite ltr_pdivrMr ?normr_gt0 ?lead_coef_eq0 // mulrC -normrM -{}Dax. by rewrite le_gtF // ub_q // normfV invf_le1 ?normr_gt0. Qed. Lemma natf_indexg (gT : finGroupType) (G H : {group gT}) : H \subset G -> #|G : H|%:R = (#|G|%:R / #|H|%:R)%R :> F. Proof. by move=> sHG; rewrite -divgS // natf_div ?cardSg. Qed. End NumFieldTheory. Section RealField. Variables F : realFieldType. Implicit Type x y : F. Lemma leif_mean_square x y : x * y <= (x ^+ 2 + y ^+ 2) / 2 ?= iff (x == y). Proof. by apply: real_leif_mean_square; apply: num_real. Qed. Lemma leif_AGM2 x y : x * y <= ((x + y) / 2)^+ 2 ?= iff (x == y). Proof. by apply: real_leif_AGM2; apply: num_real. Qed. Section MinMax. Lemma maxr_absE x y : Num.max x y = (x + y + `|x - y|) / 2. Proof. apply: canRL (mulfK _) _ => //; rewrite ?pnatr_eq0//. case: lerP => _; rewrite [2]mulr2n mulrDr mulr1. by rewrite addrCA addrK. by rewrite addrCA addrAC subrr add0r. Qed. Lemma minr_absE x y : Num.min x y = (x + y - `|x - y|) / 2. Proof. apply: (addrI (Num.max x y)); rewrite addr_max_min maxr_absE. by rewrite -mulrDl addrCA addrK mulrDl -splitr. Qed. End MinMax. End RealField. Section RealClosedFieldTheory. Variable R : rcfType. Implicit Types a x y : R. Lemma poly_ivt : real_closed_axiom R. Proof. exact: poly_ivt. Qed. (* Square Root theory *) Lemma sqrtr_ge0 a : 0 <= sqrt a. Proof. by rewrite /sqrt; case: (sig2W _). Qed. Hint Resolve sqrtr_ge0 : core. Lemma sqr_sqrtr a : 0 <= a -> sqrt a ^+ 2 = a. Proof. by rewrite /sqrt => a_ge0; case: (sig2W _) => /= x _; rewrite a_ge0 => /eqP. Qed. Lemma ler0_sqrtr a : a <= 0 -> sqrt a = 0. Proof. rewrite /sqrtr; case: (sig2W _) => x /= _. by have [//|_ /eqP//|->] := ltrgt0P a; rewrite mulf_eq0 orbb => /eqP. Qed. Lemma ltr0_sqrtr a : a < 0 -> sqrt a = 0. Proof. by move=> /ltW; apply: ler0_sqrtr. Qed. Variant sqrtr_spec a : R -> bool -> bool -> R -> Type := | IsNoSqrtr of a < 0 : sqrtr_spec a a false true 0 | IsSqrtr b of 0 <= b : sqrtr_spec a (b ^+ 2) true false b. Lemma sqrtrP a : sqrtr_spec a a (0 <= a) (a < 0) (sqrt a). Proof. have [a_ge0|a_lt0] := ger0P a. by rewrite -{1 2}[a]sqr_sqrtr //; constructor. by rewrite ltr0_sqrtr //; constructor. Qed. Lemma sqrtr_sqr a : sqrt (a ^+ 2) = `|a|. Proof. have /eqP : sqrt (a ^+ 2) ^+ 2 = `|a| ^+ 2. by rewrite -normrX ger0_norm ?sqr_sqrtr ?sqr_ge0. rewrite eqf_sqr => /predU1P[-> //|ha]. have := sqrtr_ge0 (a ^+ 2); rewrite (eqP ha) oppr_ge0 normr_le0 => /eqP ->. by rewrite normr0 oppr0. Qed. Lemma sqrtrM a b : 0 <= a -> sqrt (a * b) = sqrt a * sqrt b. Proof. case: (sqrtrP a) => // {}a a_ge0 _; case: (sqrtrP b) => [b_lt0 | {}b b_ge0]. by rewrite mulr0 ler0_sqrtr // nmulr_lle0 ?mulr_ge0. by rewrite mulrACA sqrtr_sqr ger0_norm ?mulr_ge0. Qed. Lemma sqrtr0 : sqrt 0 = 0 :> R. Proof. by move: (sqrtr_sqr 0); rewrite exprS mul0r => ->; rewrite normr0. Qed. Lemma sqrtr1 : sqrt 1 = 1 :> R. Proof. by move: (sqrtr_sqr 1); rewrite expr1n => ->; rewrite normr1. Qed. Lemma sqrtr_eq0 a : (sqrt a == 0) = (a <= 0). Proof. case: sqrtrP => [/ltW ->|b]; first by rewrite eqxx. case: ltrgt0P => [b_gt0|//|->]; last by rewrite exprS mul0r lexx. by rewrite lt_geF ?pmulr_rgt0. Qed. Lemma sqrtr_gt0 a : (0 < sqrt a) = (0 < a). Proof. by rewrite lt0r sqrtr_ge0 sqrtr_eq0 -ltNge andbT. Qed. Lemma eqr_sqrt a b : 0 <= a -> 0 <= b -> (sqrt a == sqrt b) = (a == b). Proof. move=> a_ge0 b_ge0; apply/eqP/eqP=> [HS|->] //. by move: (sqr_sqrtr a_ge0); rewrite HS (sqr_sqrtr b_ge0). Qed. Lemma ler_wsqrtr : {homo @sqrt R : a b / a <= b}. Proof. move=> a b /= le_ab; case: (boolP (0 <= a))=> [pa|]; last first. by rewrite -ltNge; move/ltW; rewrite -sqrtr_eq0; move/eqP->. rewrite -(@ler_pXn2r R 2) ?nnegrE ?sqrtr_ge0 //. by rewrite !sqr_sqrtr // (le_trans pa). Qed. Lemma ler_psqrt : {in @nneg R &, {mono sqrt : a b / a <= b}}. Proof. apply: le_mono_in => x y x_gt0 y_gt0. rewrite !lt_neqAle => /andP[neq_xy le_xy]. by rewrite ler_wsqrtr // eqr_sqrt // neq_xy. Qed. Lemma ler_sqrt a b : 0 <= b -> (sqrt a <= sqrt b) = (a <= b). Proof. move=> b_ge0; have [a_le0|a_gt0] := ler0P a; last first. by rewrite ler_psqrt // nnegrE ltW. by rewrite ler0_sqrtr // sqrtr_ge0 (le_trans a_le0). Qed. Lemma ltr_sqrt a b : 0 < b -> (sqrt a < sqrt b) = (a < b). Proof. move=> b_gt0; have [a_le0|a_gt0] := ler0P a; last first. by rewrite (leW_mono_in ler_psqrt)//; apply: ltW. by rewrite ler0_sqrtr // sqrtr_gt0 b_gt0 (le_lt_trans a_le0). Qed. Lemma sqrtrV x : 0 <= x -> sqrt (x^-1) = (sqrt x)^-1. Proof. case: ltrgt0P => // [x_gt0 _|->]; last by rewrite !(invr0, sqrtr0). have sx_neq0 : sqrt x != 0 by rewrite sqrtr_eq0 -ltNge. apply: (mulfI sx_neq0). by rewrite -sqrtrM !(divff, ltW, sqrtr1) // lt0r_neq0. Qed. End RealClosedFieldTheory. Notation "z ^*" := (conj_op z) : ring_scope. Notation "'i" := imaginary : ring_scope. Section ClosedFieldTheory. Variable C : numClosedFieldType. Implicit Types a x y z : C. Definition normCK : forall x, `|x| ^+ 2 = x * x^* := normCK. Definition sqrCi : 'i ^+ 2 = -1 :> C := sqrCi. Lemma mulCii : 'i * 'i = -1 :> C. Proof. exact: sqrCi. Qed. Lemma conjCK : involutive (@conj_op C). Proof. have JE x : x^* = `|x|^+2 / x. have [->|x_neq0] := eqVneq x 0; first by rewrite rmorph0 invr0 mulr0. by apply: (canRL (mulfK _)) => //; rewrite mulrC -normCK. move=> x; have [->|x_neq0] := eqVneq x 0; first by rewrite !rmorph0. rewrite !JE normrM normfV exprMn normrX normr_id. rewrite invfM exprVn (AC (2*2) (1*(2*3)*4))/= -invfM -exprMn. by rewrite divff ?mul1r ?invrK // !expf_eq0 normr_eq0 //. Qed. Let Re2 z := z + z^*. Definition nnegIm z := (0 <= 'i * (z^* - z)). Definition argCle y z := nnegIm z ==> nnegIm y && (Re2 z <= Re2 y). Variant rootC_spec n (x : C) : Type := RootCspec (y : C) of if (n > 0)%N then y ^+ n = x else y = 0 & forall z, (n > 0)%N -> z ^+ n = x -> argCle y z. Fact rootC_subproof n x : rootC_spec n x. Proof. have realRe2 u : Re2 u \is Num.real by rewrite realEsqr expr2 {2}/Re2 -{2}[u]conjCK addrC -rmorphD -normCK exprn_ge0. have argCle_total : total argCle. move=> u v; rewrite /total /argCle. by do 2!case: (nnegIm _) => //; rewrite ?orbT //= real_leVge. have argCle_trans : transitive argCle. move=> u v w /implyP geZuv /implyP geZvw; apply/implyP. by case/geZvw/andP=> /geZuv/andP[-> geRuv] /le_trans->. pose p := 'X^n - (x *+ (n > 0))%:P; have [r0 Dp] := closed_field_poly_normal p. have sz_p : size p = n.+1. rewrite size_polyDl ?size_polyXn // ltnS size_polyN size_polyC mulrn_eq0. by case: posnP => //; case: negP. pose r := sort argCle r0; have r_arg: sorted argCle r by apply: sort_sorted. have{} Dp: p = \prod_(z <- r) ('X - z%:P). rewrite Dp lead_coefE sz_p coefB coefXn coefC -mulrb -mulrnA mulnb lt0n andNb. by rewrite subr0 eqxx scale1r; apply/esym/perm_big; rewrite perm_sort. have mem_rP z: (n > 0)%N -> reflect (z ^+ n = x) (z \in r). move=> n_gt0; rewrite -root_prod_XsubC -Dp rootE !hornerE n_gt0. by rewrite subr_eq0; apply: eqP. exists r`_0 => [|z n_gt0 /(mem_rP z n_gt0) r_z]. have sz_r: size r = n by apply: succn_inj; rewrite -sz_p Dp size_prod_XsubC. case: posnP => [n0 | n_gt0]; first by rewrite nth_default // sz_r n0. by apply/mem_rP=> //; rewrite mem_nth ?sz_r. case: {Dp mem_rP}r r_z r_arg => // y r1 /[1!inE] /predU1P[-> _|r1z]. by apply/implyP=> ->; rewrite lexx. by move/(order_path_min argCle_trans)/allP->. Qed. Definition nthroot n x := let: RootCspec y _ _ := rootC_subproof n x in y. Notation "n .-root" := (nthroot n) : ring_scope. Notation sqrtC := 2.-root. Fact Re_lock : unit. Proof. exact: tt. Qed. Fact Im_lock : unit. Proof. exact: tt. Qed. Definition Re z := locked_with Re_lock ((z + z^*) / 2%:R). Definition Im z := locked_with Im_lock ('i * (z^* - z) / 2%:R). Notation "'Re z" := (Re z) : ring_scope. Notation "'Im z" := (Im z) : ring_scope. Lemma ReE z : 'Re z = (z + z^*) / 2%:R. Proof. by rewrite ['Re _]unlock. Qed. Lemma ImE z : 'Im z = 'i * (z^* - z) / 2%:R. Proof. by rewrite ['Im _]unlock. Qed. Let nz2 : 2 != 0 :> C. Proof. by rewrite pnatr_eq0. Qed. Lemma normCKC x : `|x| ^+ 2 = x^* * x. Proof. by rewrite normCK mulrC. Qed. Lemma mul_conjC_ge0 x : 0 <= x * x^*. Proof. by rewrite -normCK exprn_ge0. Qed. Lemma mul_conjC_gt0 x : (0 < x * x^* ) = (x != 0). Proof. have [->|x_neq0] := eqVneq; first by rewrite rmorph0 mulr0. by rewrite -normCK exprn_gt0 ?normr_gt0. Qed. Lemma mul_conjC_eq0 x : (x * x^* == 0) = (x == 0). Proof. by rewrite -normCK expf_eq0 normr_eq0. Qed. Lemma conjC_ge0 x : (0 <= x^* ) = (0 <= x). Proof. wlog suffices: x / 0 <= x -> 0 <= x^*. by move=> IH; apply/idP/idP=> /IH; rewrite ?conjCK. rewrite [in X in X -> _]le0r => /predU1P[-> | x_gt0]; first by rewrite rmorph0. by rewrite -(pmulr_rge0 _ x_gt0) mul_conjC_ge0. Qed. Lemma conjC_nat n : (n%:R)^* = n%:R :> C. Proof. exact: rmorph_nat. Qed. Lemma conjC0 : 0^* = 0 :> C. Proof. exact: rmorph0. Qed. Lemma conjC1 : 1^* = 1 :> C. Proof. exact: rmorph1. Qed. Lemma conjCN1 : (- 1)^* = - 1 :> C. Proof. exact: rmorphN1. Qed. Lemma conjC_eq0 x : (x^* == 0) = (x == 0). Proof. exact: fmorph_eq0. Qed. Lemma invC_norm x : x^-1 = `|x| ^- 2 * x^*. Proof. have [-> | nx_x] := eqVneq x 0; first by rewrite conjC0 mulr0 invr0. by rewrite normCK invfM divfK ?conjC_eq0. Qed. (* Real number subset. *) Lemma CrealE x : (x \is real) = (x^* == x). Proof. rewrite realEsqr ger0_def normrX normCK. by have [-> | /mulfI/inj_eq-> //] := eqVneq x 0; rewrite rmorph0 !eqxx. Qed. Lemma CrealP {x} : reflect (x^* = x) (x \is real). Proof. by rewrite CrealE; apply: eqP. Qed. Lemma conj_Creal x : x \is real -> x^* = x. Proof. by move/CrealP. Qed. Lemma conj_normC z : `|z|^* = `|z|. Proof. by rewrite conj_Creal ?normr_real. Qed. Lemma CrealJ : {mono (@conj_op C) : x / x \is Num.real}. Proof. by apply: (homo_mono1 conjCK) => x xreal; rewrite conj_Creal. Qed. Lemma geC0_conj x : 0 <= x -> x^* = x. Proof. by move=> /ger0_real/CrealP. Qed. Lemma geC0_unit_exp x n : 0 <= x -> (x ^+ n.+1 == 1) = (x == 1). Proof. by move=> x_ge0; rewrite pexpr_eq1. Qed. (* Elementary properties of roots. *) Ltac case_rootC := rewrite /nthroot; case: (rootC_subproof _ _). Lemma root0C x : 0.-root x = 0. Proof. by case_rootC. Qed. Lemma rootCK n : (n > 0)%N -> cancel n.-root (fun x => x ^+ n). Proof. by case: n => //= n _ x; case_rootC. Qed. Lemma root1C x : 1.-root x = x. Proof. exact: (@rootCK 1). Qed. Lemma rootC0 n : n.-root 0 = 0. Proof. have [-> | n_gt0] := posnP n; first by rewrite root0C. by have /eqP := rootCK n_gt0 0; rewrite expf_eq0 n_gt0 /= => /eqP. Qed. Lemma rootC_inj n : (n > 0)%N -> injective n.-root. Proof. by move/rootCK/can_inj. Qed. Lemma eqr_rootC n : (n > 0)%N -> {mono n.-root : x y / x == y}. Proof. by move/rootC_inj/inj_eq. Qed. Lemma rootC_eq0 n x : (n > 0)%N -> (n.-root x == 0) = (x == 0). Proof. by move=> n_gt0; rewrite -{1}(rootC0 n) eqr_rootC. Qed. (* Rectangular coordinates. *) Lemma nonRealCi : ('i : C) \isn't real. Proof. by rewrite realEsqr sqrCi oppr_ge0 lt_geF ?ltr01. Qed. Lemma neq0Ci : 'i != 0 :> C. Proof. by apply: contraNneq nonRealCi => ->. Qed. Lemma normCi : `|'i| = 1 :> C. Proof. by apply/eqP; rewrite -(@pexpr_eq1 _ _ 2) // -normrX sqrCi normrN1. Qed. Lemma invCi : 'i^-1 = - 'i :> C. Proof. by rewrite -div1r -[1]opprK -sqrCi mulNr mulfK ?neq0Ci. Qed. Lemma conjCi : 'i^* = - 'i :> C. Proof. by rewrite -invCi invC_norm normCi expr1n invr1 mul1r. Qed. Lemma Crect x : x = 'Re x + 'i * 'Im x. Proof. rewrite !(ReE, ImE) 2!mulrA mulCii mulN1r opprB -mulrDl. by rewrite addrACA subrr addr0 mulrDl -splitr. Qed. Lemma eqCP x y : x = y <-> ('Re x = 'Re y) /\ ('Im x = 'Im y). Proof. by split=> [->//|[eqRe eqIm]]; rewrite [x]Crect [y]Crect eqRe eqIm. Qed. Lemma eqC x y : (x == y) = ('Re x == 'Re y) && ('Im x == 'Im y). Proof. by apply/eqP/(andPP eqP eqP) => /eqCP. Qed. Lemma Creal_Re x : 'Re x \is real. Proof. by rewrite ReE CrealE fmorph_div rmorph_nat rmorphD /= conjCK addrC. Qed. Lemma Creal_Im x : 'Im x \is real. Proof. rewrite ImE CrealE fmorph_div rmorph_nat rmorphM /= rmorphB conjCK. by rewrite conjCi -opprB mulrNN. Qed. Hint Resolve Creal_Re Creal_Im : core. Fact Re_is_zmod_morphism : zmod_morphism Re. Proof. by move=> x y; rewrite !ReE rmorphB addrACA -opprD mulrBl. Qed. #[export] HB.instance Definition _ := GRing.isZmodMorphism.Build C C Re Re_is_zmod_morphism. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `Re_is_zmod_morphism` instead")] Definition Re_is_additive := Re_is_zmod_morphism. Fact Im_is_zmod_morphism : zmod_morphism Im. Proof. by move=> x y; rewrite !ImE rmorphB opprD addrACA -opprD mulrBr mulrBl. Qed. #[export] HB.instance Definition _ := GRing.isZmodMorphism.Build C C Im Im_is_zmod_morphism. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `Im_is_zmod_morphism` instead")] Definition Im_is_additive := Im_is_zmod_morphism. Lemma Creal_ImP z : reflect ('Im z = 0) (z \is real). Proof. rewrite ImE CrealE -subr_eq0 -(can_eq (mulKf neq0Ci)) mulr0. by rewrite -(can_eq (divfK nz2)) mul0r; apply: eqP. Qed. Lemma Creal_ReP z : reflect ('Re z = z) (z \in real). Proof. rewrite (sameP (Creal_ImP z) eqP) -(can_eq (mulKf neq0Ci)) mulr0. by rewrite -(inj_eq (addrI ('Re z))) addr0 -Crect eq_sym; apply: eqP. Qed. Lemma ReMl : {in real, forall x, {morph Re : z / x * z}}. Proof. by move=> x Rx z /=; rewrite !ReE rmorphM /= (conj_Creal Rx) -mulrDr -mulrA. Qed. Lemma ReMr : {in real, forall x, {morph Re : z / z * x}}. Proof. by move=> x Rx z /=; rewrite mulrC ReMl // mulrC. Qed. Lemma ImMl : {in real, forall x, {morph Im : z / x * z}}. Proof. by move=> x Rx z; rewrite !ImE rmorphM /= (conj_Creal Rx) -mulrBr mulrCA !mulrA. Qed. Lemma ImMr : {in real, forall x, {morph Im : z / z * x}}. Proof. by move=> x Rx z /=; rewrite mulrC ImMl // mulrC. Qed. Lemma Re_i : 'Re 'i = 0. Proof. by rewrite ReE conjCi subrr mul0r. Qed. Lemma Im_i : 'Im 'i = 1. Proof. rewrite ImE conjCi -opprD mulrN -mulr2n mulrnAr mulCii. by rewrite mulNrn opprK divff. Qed. Lemma Re_conj z : 'Re z^* = 'Re z. Proof. by rewrite !ReE addrC conjCK. Qed. Lemma Im_conj z : 'Im z^* = - 'Im z. Proof. by rewrite !ImE -mulNr -mulrN opprB conjCK. Qed. Lemma Re_rect : {in real &, forall x y, 'Re (x + 'i * y) = x}. Proof. move=> x y Rx Ry; rewrite /= raddfD /= (Creal_ReP x Rx). by rewrite ReMr // Re_i mul0r addr0. Qed. Lemma Im_rect : {in real &, forall x y, 'Im (x + 'i * y) = y}. Proof. move=> x y Rx Ry; rewrite /= raddfD /= (Creal_ImP x Rx) add0r. by rewrite ImMr // Im_i mul1r. Qed. Lemma conjC_rect : {in real &, forall x y, (x + 'i * y)^* = x - 'i * y}. Proof. by move=> x y Rx Ry; rewrite /= rmorphD rmorphM /= conjCi mulNr !conj_Creal. Qed. Lemma addC_rect x1 y1 x2 y2 : (x1 + 'i * y1) + (x2 + 'i * y2) = x1 + x2 + 'i * (y1 + y2). Proof. by rewrite addrACA -mulrDr. Qed. Lemma oppC_rect x y : - (x + 'i * y) = - x + 'i * (- y). Proof. by rewrite mulrN -opprD. Qed. Lemma subC_rect x1 y1 x2 y2 : (x1 + 'i * y1) - (x2 + 'i * y2) = x1 - x2 + 'i * (y1 - y2). Proof. by rewrite oppC_rect addC_rect. Qed. Lemma mulC_rect x1 y1 x2 y2 : (x1 + 'i * y1) * (x2 + 'i * y2) = x1 * x2 - y1 * y2 + 'i * (x1 * y2 + x2 * y1). Proof. rewrite mulrDl !mulrDr (AC (2*2) (1*4*(2*3)))/= mulrACA. by rewrite -expr2 sqrCi mulN1r -!mulrA [_ * ('i * _)]mulrCA [_ * y1]mulrC. Qed. Lemma ImM x y : 'Im (x * y) = 'Re x * 'Im y + 'Re y * 'Im x. Proof. rewrite [x in LHS]Crect [y in LHS]Crect mulC_rect. by rewrite !(Im_rect, rpredB, rpredD, rpredM). Qed. Lemma ImMil x : 'Im ('i * x) = 'Re x. Proof. by rewrite ImM Re_i Im_i mul0r mulr1 add0r. Qed. Lemma ReMil x : 'Re ('i * x) = - 'Im x. Proof. by rewrite -ImMil mulrA mulCii mulN1r raddfN. Qed. Lemma ReMir x : 'Re (x * 'i) = - 'Im x. Proof. by rewrite mulrC ReMil. Qed. Lemma ImMir x : 'Im (x * 'i) = 'Re x. Proof. by rewrite mulrC ImMil. Qed. Lemma ReM x y : 'Re (x * y) = 'Re x * 'Re y - 'Im x * 'Im y. Proof. by rewrite -ImMil mulrCA ImM ImMil ReMil mulNr ['Im _ * _]mulrC. Qed. Lemma normC2_rect : {in real &, forall x y, `|x + 'i * y| ^+ 2 = x ^+ 2 + y ^+ 2}. Proof. move=> x y Rx Ry; rewrite /= normCK rmorphD rmorphM /= conjCi !conj_Creal //. by rewrite mulrC mulNr -subr_sqr exprMn sqrCi mulN1r opprK. Qed. Lemma normC2_Re_Im z : `|z| ^+ 2 = 'Re z ^+ 2 + 'Im z ^+ 2. Proof. by rewrite -normC2_rect -?Crect. Qed. Lemma invC_Crect x y : (x + 'i * y)^-1 = (x^* - 'i * y^*) / `|x + 'i * y| ^+ 2. Proof. by rewrite /= invC_norm mulrC !rmorphE rmorphM /= conjCi mulNr. Qed. Lemma invC_rect : {in real &, forall x y, (x + 'i * y)^-1 = (x - 'i * y) / (x ^+ 2 + y ^+ 2)}. Proof. by move=> x y Rx Ry; rewrite invC_Crect normC2_rect ?conj_Creal. Qed. Lemma ImV x : 'Im x^-1 = - 'Im x / `|x| ^+ 2. Proof. rewrite [x in LHS]Crect invC_rect// ImMr ?(rpredV, rpredD, rpredX)//. by rewrite -mulrN Im_rect ?rpredN// -normC2_rect// -Crect. Qed. Lemma ReV x : 'Re x^-1 = 'Re x / `|x| ^+ 2. Proof. rewrite [x in LHS]Crect invC_rect// ReMr ?(rpredV, rpredD, rpredX)//. by rewrite -mulrN Re_rect ?rpredN// -normC2_rect// -Crect. Qed. Lemma rectC_mulr x y z : (x + 'i * y) * z = x * z + 'i * (y * z). Proof. by rewrite mulrDl mulrA. Qed. Lemma rectC_mull x y z : z * (x + 'i * y) = z * x + 'i * (z * y). Proof. by rewrite mulrDr mulrCA. Qed. Lemma divC_Crect x1 y1 x2 y2 : (x1 + 'i * y1) / (x2 + 'i * y2) = (x1 * x2^* + y1 * y2^* + 'i * (x2^* * y1 - x1 * y2^*)) / `|x2 + 'i * y2| ^+ 2. Proof. rewrite invC_Crect// -mulrN [_ / _]rectC_mulr mulC_rect !mulrA -mulrBl. rewrite [_ * _ * y1]mulrAC -mulrDl mulrA -mulrDl !(mulrN, mulNr) opprK. by rewrite [- _ + _]addrC. Qed. Lemma divC_rect x1 y1 x2 y2 : x1 \is real -> y1 \is real -> x2 \is real -> y2 \is real -> (x1 + 'i * y1) / (x2 + 'i * y2) = (x1 * x2 + y1 * y2 + 'i * (x2 * y1 - x1 * y2)) / (x2 ^+ 2 + y2 ^+ 2). Proof. by move=> *; rewrite divC_Crect normC2_rect ?conj_Creal. Qed. Lemma Im_div x y : 'Im (x / y) = ('Re y * 'Im x - 'Re x * 'Im y) / `|y| ^+ 2. Proof. by rewrite ImM ImV ReV mulrA [X in _ + X]mulrAC -mulrDl mulrN addrC. Qed. Lemma Re_div x y : 'Re (x / y) = ('Re x * 'Re y + 'Im x * 'Im y) / `|y| ^+ 2. Proof. by rewrite ReM ImV ReV !mulrA -mulrBl mulrN opprK. Qed. Lemma leif_normC_Re_Creal z : `|'Re z| <= `|z| ?= iff (z \is real). Proof. rewrite -(mono_in_leif ler_sqr); try by rewrite qualifE /=. rewrite [`|'Re _| ^+ 2]normCK conj_Creal // normC2_Re_Im -expr2. rewrite addrC -leifBLR subrr (sameP (Creal_ImP _) eqP) -sqrf_eq0 eq_sym. by apply: leif_eq; rewrite -realEsqr. Qed. Lemma leif_Re_Creal z : 'Re z <= `|z| ?= iff (0 <= z). Proof. have ubRe: 'Re z <= `|'Re z| ?= iff (0 <= 'Re z). by rewrite ger0_def eq_sym; apply/leif_eq/real_ler_norm. congr (_ <= _ ?= iff _): (leif_trans ubRe (leif_normC_Re_Creal z)). apply/andP/idP=> [[zRge0 /Creal_ReP <- //] | z_ge0]. by have Rz := ger0_real z_ge0; rewrite (Creal_ReP _ _). Qed. (* Equality from polar coordinates, for the upper plane. *) Lemma eqC_semipolar x y : `|x| = `|y| -> 'Re x = 'Re y -> 0 <= 'Im x * 'Im y -> x = y. Proof. move=> eq_norm eq_Re sign_Im. rewrite [x]Crect [y]Crect eq_Re; congr (_ + 'i * _). have /eqP := congr1 (fun z => z ^+ 2) eq_norm. rewrite !normC2_Re_Im eq_Re (can_eq (addKr _)) eqf_sqr => /pred2P[] // eq_Im. rewrite eq_Im mulNr -expr2 oppr_ge0 real_exprn_even_le0 //= in sign_Im. by rewrite eq_Im (eqP sign_Im) oppr0. Qed. (* Nth roots. *) Let argCleP y z : reflect (0 <= 'Im z -> 0 <= 'Im y /\ 'Re z <= 'Re y) (argCle y z). Proof. suffices dIm x: nnegIm x = (0 <= 'Im x). rewrite /argCle !dIm !(ImE, ReE) ler_pM2r ?invr_gt0 ?ltr0n //. by apply: (iffP implyP) => geZyz /geZyz/andP. by rewrite (ImE x) pmulr_lge0 ?invr_gt0 ?ltr0n //; congr (0 <= _ * _). Qed. Lemma rootC_Re_max n x y : (n > 0)%N -> y ^+ n = x -> 0 <= 'Im y -> 'Re y <= 'Re (n.-root x). Proof. by move=> n_gt0 yn_x leI0y; case_rootC=> z /= _ /(_ y n_gt0 yn_x)/argCleP[]. Qed. Let neg_unity_root n : (n > 1)%N -> exists2 w : C, w ^+ n = 1 & 'Re w < 0. Proof. move=> n_gt1; have [|w /eqP pw_0] := closed_rootP (\poly_(i < n) (1 : C)) _. by rewrite size_poly_eq ?oner_eq0 // -(subnKC n_gt1). rewrite horner_poly (eq_bigr _ (fun _ _ => mul1r _)) in pw_0. have wn1: w ^+ n = 1 by apply/eqP; rewrite -subr_eq0 subrX1 pw_0 mulr0. suffices /existsP[i ltRwi0]: [exists i : 'I_n, 'Re (w ^+ i) < 0]. by exists (w ^+ i) => //; rewrite exprAC wn1 expr1n. apply: contra_eqT (congr1 Re pw_0) => /existsPn geRw0. rewrite raddf_sum raddf0 /= (bigD1 (Ordinal (ltnW n_gt1))) //=. rewrite (Creal_ReP _ _) ?rpred1 // gt_eqF ?ltr_wpDr ?ltr01 //=. by apply: sumr_ge0 => i _; rewrite real_leNgt ?rpred0. Qed. Lemma Im_rootC_ge0 n x : (n > 1)%N -> 0 <= 'Im (n.-root x). Proof. set y := n.-root x => n_gt1; have n_gt0 := ltnW n_gt1. apply: wlog_neg; rewrite -real_ltNge ?rpred0 // => ltIy0. suffices [z zn_x leI0z]: exists2 z, z ^+ n = x & 'Im z >= 0. by rewrite /y; case_rootC => /= y1 _ /(_ z n_gt0 zn_x)/argCleP[]. have [w wn1 ltRw0] := neg_unity_root n_gt1. wlog leRI0yw: w wn1 ltRw0 / 0 <= 'Re y * 'Im w. move=> IHw; have: 'Re y * 'Im w \is real by rewrite rpredM. case/real_ge0P=> [|/ltW leRIyw0]; first exact: IHw. apply: (IHw w^* ); rewrite ?Re_conj ?Im_conj ?mulrN ?oppr_ge0 //. by rewrite -rmorphXn wn1 rmorph1. exists (w * y); first by rewrite exprMn wn1 mul1r rootCK. rewrite [w]Crect [y]Crect mulC_rect. by rewrite Im_rect ?rpredD ?rpredN 1?rpredM // addr_ge0 // ltW ?nmulr_rgt0. Qed. Lemma rootC_lt0 n x : (1 < n)%N -> (n.-root x < 0) = false. Proof. set y := n.-root x => n_gt1; have n_gt0 := ltnW n_gt1. apply: negbTE; apply: wlog_neg => /negbNE lt0y; rewrite le_gtF //. have Rx: x \is real by rewrite -[x](rootCK n_gt0) rpredX // ltr0_real. have Re_y: 'Re y = y by apply/Creal_ReP; rewrite ltr0_real. have [z zn_x leR0z]: exists2 z, z ^+ n = x & 'Re z >= 0. have [w wn1 ltRw0] := neg_unity_root n_gt1. exists (w * y); first by rewrite exprMn wn1 mul1r rootCK. by rewrite ReMr ?ltr0_real // ltW // nmulr_lgt0. without loss leI0z: z zn_x leR0z / 'Im z >= 0. move=> IHz; have: 'Im z \is real by []. case/real_ge0P=> [|/ltW leIz0]; first exact: IHz. apply: (IHz z^* ); rewrite ?Re_conj ?Im_conj ?oppr_ge0 //. by rewrite -rmorphXn /= zn_x conj_Creal. by apply: le_trans leR0z _; rewrite -Re_y ?rootC_Re_max ?ltr0_real. Qed. Lemma rootC_ge0 n x : (n > 0)%N -> (0 <= n.-root x) = (0 <= x). Proof. set y := n.-root x => n_gt0. apply/idP/idP=> [/(exprn_ge0 n) | x_ge0]; first by rewrite rootCK. rewrite -(ge_leif (leif_Re_Creal y)). have Ray: `|y| \is real by apply: normr_real. rewrite -(Creal_ReP _ Ray) rootC_Re_max ?(Creal_ImP _ Ray) //. by rewrite -normrX rootCK // ger0_norm. Qed. Lemma rootC_gt0 n x : (n > 0)%N -> (n.-root x > 0) = (x > 0). Proof. by move=> n_gt0; rewrite !lt0r rootC_ge0 ?rootC_eq0. Qed. Lemma rootC_le0 n x : (1 < n)%N -> (n.-root x <= 0) = (x == 0). Proof. by move=> n_gt1; rewrite le_eqVlt rootC_lt0 // orbF rootC_eq0 1?ltnW. Qed. Lemma ler_rootCl n : (n > 0)%N -> {in Num.nneg, {mono n.-root : x y / x <= y}}. Proof. move=> n_gt0 x x_ge0 y; have [y_ge0 | not_y_ge0] := boolP (0 <= y). by rewrite -(ler_pXn2r n_gt0) ?qualifE /= ?rootC_ge0 ?rootCK. rewrite (contraNF (@le_trans _ _ _ 0 _ _)) ?rootC_ge0 //. by rewrite (contraNF (le_trans x_ge0)). Qed. Lemma ler_rootC n : (n > 0)%N -> {in Num.nneg &, {mono n.-root : x y / x <= y}}. Proof. by move=> n_gt0 x y x_ge0 _; apply: ler_rootCl. Qed. Lemma ltr_rootCl n : (n > 0)%N -> {in Num.nneg, {mono n.-root : x y / x < y}}. Proof. by move=> n_gt0 x x_ge0 y; rewrite !lt_def ler_rootCl ?eqr_rootC. Qed. Lemma ltr_rootC n : (n > 0)%N -> {in Num.nneg &, {mono n.-root : x y / x < y}}. Proof. by move/ler_rootC/leW_mono_in. Qed. Lemma exprCK n x : (0 < n)%N -> 0 <= x -> n.-root (x ^+ n) = x. Proof. move=> n_gt0 x_ge0; apply/eqP. by rewrite -(eqrXn2 n_gt0) ?rootC_ge0 ?exprn_ge0 ?rootCK. Qed. Lemma norm_rootC n x : `|n.-root x| = n.-root `|x|. Proof. have [-> | n_gt0] := posnP n; first by rewrite !root0C normr0. by apply/eqP; rewrite -(eqrXn2 n_gt0) ?rootC_ge0 // -normrX !rootCK. Qed. Lemma rootCX n x k : (n > 0)%N -> 0 <= x -> n.-root (x ^+ k) = n.-root x ^+ k. Proof. move=> n_gt0 x_ge0; apply/eqP. by rewrite -(eqrXn2 n_gt0) ?(exprn_ge0, rootC_ge0) // 1?exprAC !rootCK. Qed. Lemma rootC1 n : (n > 0)%N -> n.-root 1 = 1. Proof. by move/(rootCX 0)/(_ ler01). Qed. Lemma rootCpX n x k : (k > 0)%N -> 0 <= x -> n.-root (x ^+ k) = n.-root x ^+ k. Proof. by case: n => [|n] k_gt0; [rewrite !root0C expr0n gtn_eqF | apply: rootCX]. Qed. Lemma rootCV n x : 0 <= x -> n.-root x^-1 = (n.-root x)^-1. Proof. move=> x_ge0; have [->|n_gt0] := posnP n; first by rewrite !root0C invr0. apply/eqP. by rewrite -(eqrXn2 n_gt0) ?(invr_ge0, rootC_ge0) // !exprVn !rootCK. Qed. Lemma rootC_eq1 n x : (n > 0)%N -> (n.-root x == 1) = (x == 1). Proof. by move=> n_gt0; rewrite -{1}(rootC1 n_gt0) eqr_rootC. Qed. Lemma rootC_ge1 n x : (n > 0)%N -> (n.-root x >= 1) = (x >= 1). Proof. by move=> n_gt0; rewrite -{1}(rootC1 n_gt0) ler_rootCl // qualifE /= ler01. Qed. Lemma rootC_gt1 n x : (n > 0)%N -> (n.-root x > 1) = (x > 1). Proof. by move=> n_gt0; rewrite !lt_def rootC_eq1 ?rootC_ge1. Qed. Lemma rootC_le1 n x : (n > 0)%N -> 0 <= x -> (n.-root x <= 1) = (x <= 1). Proof. by move=> n_gt0 x_ge0; rewrite -{1}(rootC1 n_gt0) ler_rootCl. Qed. Lemma rootC_lt1 n x : (n > 0)%N -> 0 <= x -> (n.-root x < 1) = (x < 1). Proof. by move=> n_gt0 x_ge0; rewrite !lt_neqAle rootC_eq1 ?rootC_le1. Qed. Lemma rootCMl n x z : 0 <= x -> n.-root (x * z) = n.-root x * n.-root z. Proof. rewrite le0r => /predU1P[-> | x_gt0]; first by rewrite !(mul0r, rootC0). have [| n_gt1 | ->] := ltngtP n 1; last by rewrite !root1C. by case: n => //; rewrite !root0C mul0r. have [x_ge0 n_gt0] := (ltW x_gt0, ltnW n_gt1). have nx_gt0: 0 < n.-root x by rewrite rootC_gt0. have Rnx: n.-root x \is real by rewrite ger0_real ?ltW. apply: eqC_semipolar; last 1 first; try apply/eqP. - by rewrite ImMl // !(Im_rootC_ge0, mulr_ge0, rootC_ge0). - by rewrite -(eqrXn2 n_gt0) // -!normrX exprMn !rootCK. rewrite eq_le; apply/andP; split; last first. rewrite rootC_Re_max ?exprMn ?rootCK ?ImMl //. by rewrite mulr_ge0 ?Im_rootC_ge0 ?ltW. rewrite -[n.-root _](mulVKf (negbT (gt_eqF nx_gt0))) !(ReMl Rnx) //. rewrite ler_pM2l // rootC_Re_max ?exprMn ?exprVn ?rootCK ?mulKf ?gt_eqF //. by rewrite ImMl ?rpredV // mulr_ge0 ?invr_ge0 ?Im_rootC_ge0 ?ltW. Qed. Lemma rootCMr n x z : 0 <= x -> n.-root (z * x) = n.-root z * n.-root x. Proof. by move=> x_ge0; rewrite mulrC rootCMl // mulrC. Qed. Lemma imaginaryCE : 'i = sqrtC (-1). Proof. have : sqrtC (-1) ^+ 2 - 'i ^+ 2 == 0 by rewrite sqrCi rootCK // subrr. rewrite subr_sqr mulf_eq0 subr_eq0 addr_eq0; have [//|_/= /eqP sCN1E] := eqP. by have := @Im_rootC_ge0 2 (-1) isT; rewrite sCN1E raddfN /= Im_i ler0N1. Qed. (* More properties of n.-root will be established in cyclotomic.v. *) (* The proper form of the Arithmetic - Geometric Mean inequality. *) Lemma leif_rootC_AGM (I : finType) (A : {pred I}) (n := #|A|) E : {in A, forall i, 0 <= E i} -> n.-root (\prod_(i in A) E i) <= (\sum_(i in A) E i) / n%:R ?= iff [forall i in A, forall j in A, E i == E j]. Proof. move=> Ege0; have [n0 | n_gt0] := posnP n. rewrite n0 root0C invr0 mulr0; apply/leif_refl/forall_inP=> i. by rewrite (card0_eq n0). rewrite -(mono_in_leif (ler_pXn2r n_gt0)) ?rootCK //=; first 1 last. - by rewrite qualifE /= rootC_ge0 // prodr_ge0. - by rewrite rpred_div ?rpred_nat ?rpred_sum. exact: leif_AGM. Qed. (* Square root. *) Lemma sqrtC0 : sqrtC 0 = 0. Proof. exact: rootC0. Qed. Lemma sqrtC1 : sqrtC 1 = 1. Proof. exact: rootC1. Qed. Lemma sqrtCK x : sqrtC x ^+ 2 = x. Proof. exact: rootCK. Qed. Lemma sqrCK x : 0 <= x -> sqrtC (x ^+ 2) = x. Proof. exact: exprCK. Qed. Lemma sqrtC_ge0 x : (0 <= sqrtC x) = (0 <= x). Proof. exact: rootC_ge0. Qed. Lemma sqrtC_eq0 x : (sqrtC x == 0) = (x == 0). Proof. exact: rootC_eq0. Qed. Lemma sqrtC_gt0 x : (sqrtC x > 0) = (x > 0). Proof. exact: rootC_gt0. Qed. Lemma sqrtC_lt0 x : (sqrtC x < 0) = false. Proof. exact: rootC_lt0. Qed. Lemma sqrtC_le0 x : (sqrtC x <= 0) = (x == 0). Proof. exact: rootC_le0. Qed. Lemma ler_sqrtC : {in Num.nneg &, {mono sqrtC : x y / x <= y}}. Proof. exact: ler_rootC. Qed. Lemma ltr_sqrtC : {in Num.nneg &, {mono sqrtC : x y / x < y}}. Proof. exact: ltr_rootC. Qed. Lemma eqr_sqrtC : {mono sqrtC : x y / x == y}. Proof. exact: eqr_rootC. Qed. Lemma sqrtC_inj : injective sqrtC. Proof. exact: rootC_inj. Qed. Lemma sqrtCM : {in Num.nneg &, {morph sqrtC : x y / x * y}}. Proof. by move=> x y _; apply: rootCMr. Qed. Lemma sqrtC_real x : 0 <= x -> sqrtC x \in Num.real. Proof. by rewrite -sqrtC_ge0; apply: ger0_real. Qed. Lemma sqrCK_P x : reflect (sqrtC (x ^+ 2) = x) ((0 <= 'Im x) && ~~ (x < 0)). Proof. apply: (iffP andP) => [[leI0x not_gt0x] | <-]; last first. by rewrite sqrtC_lt0 Im_rootC_ge0. have /eqP := sqrtCK (x ^+ 2); rewrite eqf_sqr => /pred2P[] // defNx. apply: sqrCK; rewrite -real_leNgt ?rpred0 // in not_gt0x; apply/Creal_ImP/le_anti; by rewrite leI0x -oppr_ge0 -raddfN -defNx Im_rootC_ge0. Qed. Lemma normC_def x : `|x| = sqrtC (x * x^* ). Proof. by rewrite -normCK sqrCK. Qed. Lemma norm_conjC x : `|x^*| = `|x|. Proof. by rewrite !normC_def conjCK mulrC. Qed. Lemma normC_rect : {in real &, forall x y, `|x + 'i * y| = sqrtC (x ^+ 2 + y ^+ 2)}. Proof. by move=> x y Rx Ry; rewrite /= normC_def -normCK normC2_rect. Qed. Lemma normC_Re_Im z : `|z| = sqrtC ('Re z ^+ 2 + 'Im z ^+ 2). Proof. by rewrite normC_def -normCK normC2_Re_Im. Qed. (* Norm sum (in)equalities. *) Lemma normCDeq x y : `|x + y| = `|x| + `|y| -> {t : C | `|t| == 1 & (x, y) = (`|x| * t, `|y| * t)}. Proof. move=> lin_xy; apply: sig2_eqW; pose u z := if z == 0 then 1 else z / `|z|. have uE z: (`|u z| = 1) * (`|z| * u z = z). rewrite /u; have [->|nz_z] := eqVneq; first by rewrite normr0 normr1 mul0r. by rewrite normf_div normr_id mulrCA divff ?mulr1 ?normr_eq0. have [->|nz_x] := eqVneq x 0; first by exists (u y); rewrite uE ?normr0 ?mul0r. exists (u x); rewrite uE // /u (negPf nz_x); congr (_ , _). have{lin_xy} def2xy: `|x| * `|y| *+ 2 = x * y ^* + y * x ^*. apply/(addrI (x * x^* ))/(addIr (y * y^* )); rewrite -2!{1}normCK -sqrrD. by rewrite addrA -[RHS]addrA -!mulrDr -mulrDl -rmorphD -normCK lin_xy. have def_xy: x * y^* = y * x^*. apply/eqP; rewrite -subr_eq0 -[_ == 0](@expf_eq0 _ _ 2). rewrite (canRL (subrK _) (subr_sqrDB _ _)) opprK -def2xy exprMn_n exprMn. by rewrite mulrN (@GRing.mul C).[AC (2*2) (1*4*(3*2))] -!normCK mulNrn addNr. have{def_xy def2xy} def_yx: `|y * x| = y * x^*. by apply: (mulIf nz2); rewrite !mulr_natr mulrC normrM def2xy def_xy. rewrite -{1}(divfK nz_x y) invC_norm mulrCA -{}def_yx !normrM invfM. by rewrite mulrCA divfK ?normr_eq0 // mulrAC mulrA. Qed. Lemma normC_sum_eq (I : finType) (P : pred I) (F : I -> C) : `|\sum_(i | P i) F i| = \sum_(i | P i) `|F i| -> {t : C | `|t| == 1 & forall i, P i -> F i = `|F i| * t}. Proof. have [i /andP[Pi nzFi] | F0] := pickP [pred i | P i & F i != 0]; last first. exists 1 => [|i Pi]; first by rewrite normr1. by case/nandP: (F0 i) => [/negP[]// | /negbNE/eqP->]; rewrite normr0 mul0r. rewrite !(bigD1 i Pi) /= => norm_sumF; pose Q j := P j && (j != i). rewrite -normr_eq0 in nzFi; set c := F i / `|F i|; exists c => [|j Pj]. by rewrite normrM normfV normr_id divff. have [Qj | /nandP[/negP[]// | /negbNE/eqP->]] := boolP (Q j); last first. by rewrite mulrC divfK. have: `|F i + F j| = `|F i| + `|F j|. do [rewrite !(bigD1 j Qj) /=; set z := \sum_(k | _) `|_|] in norm_sumF. apply/eqP; rewrite eq_le ler_normD -(lerD2r z) -addrA -norm_sumF addrA. by rewrite (le_trans (ler_normD _ _)) // lerD2l ler_norm_sum. by case/normCDeq=> k _ [/(canLR (mulKf nzFi)) <-]; rewrite -(mulrC (F i)). Qed. Lemma normC_sum_eq1 (I : finType) (P : pred I) (F : I -> C) : `|\sum_(i | P i) F i| = (\sum_(i | P i) `|F i|) -> (forall i, P i -> `|F i| = 1) -> {t : C | `|t| == 1 & forall i, P i -> F i = t}. Proof. case/normC_sum_eq=> t t1 defF normF. by exists t => // i Pi; rewrite defF // normF // mul1r. Qed. Lemma normC_sum_upper (I : finType) (P : pred I) (F G : I -> C) : (forall i, P i -> `|F i| <= G i) -> \sum_(i | P i) F i = \sum_(i | P i) G i -> forall i, P i -> F i = G i. Proof. set sumF := \sum_(i | _) _; set sumG := \sum_(i | _) _ => leFG eq_sumFG. have posG i: P i -> 0 <= G i by move/leFG; apply: le_trans. have norm_sumG: `|sumG| = sumG by rewrite ger0_norm ?sumr_ge0. have norm_sumF: `|sumF| = \sum_(i | P i) `|F i|. apply/eqP; rewrite eq_le ler_norm_sum eq_sumFG norm_sumG -subr_ge0 -sumrB. by rewrite sumr_ge0 // => i Pi; rewrite subr_ge0 ?leFG. have [t _ defF] := normC_sum_eq norm_sumF. have [/(psumr_eq0P posG) G0 i Pi | nz_sumG] := eqVneq sumG 0. by apply/eqP; rewrite G0 // -normr_eq0 eq_le normr_ge0 -(G0 i Pi) leFG. have t1: t = 1. apply: (mulfI nz_sumG); rewrite mulr1 -{1}norm_sumG -eq_sumFG norm_sumF. by rewrite mulr_suml -(eq_bigr _ defF). have /psumr_eq0P eqFG i: P i -> 0 <= G i - F i. by move=> Pi; rewrite subr_ge0 defF // t1 mulr1 leFG. move=> i /eqFG/(canRL (subrK _))->; rewrite ?add0r //. by rewrite sumrB -/sumF eq_sumFG subrr. Qed. Lemma normCBeq x y : `|x - y| = `|x| - `|y| -> {t | `|t| == 1 & (x, y) = (`|x| * t, `|y| * t)}. Proof. set z := x - y; rewrite -(subrK y x) -/z => /(canLR (subrK _))/esym-Dx. have [t t_1 [Dz Dy]] := normCDeq Dx. by exists t; rewrite // Dx mulrDl -Dz -Dy. Qed. End ClosedFieldTheory. Notation "n .-root" := (@nthroot _ n). Notation sqrtC := 2.-root. Notation "'i" := imaginary : ring_scope. Notation "'Re z" := (Re z) : ring_scope. Notation "'Im z" := (Im z) : ring_scope. Arguments conjCK {C} x. Arguments sqrCK {C} [x] le0x. Arguments sqrCK_P {C x}. #[global] Hint Extern 0 (is_true (in_mem ('Re _) _)) => solve [apply: Creal_Re] : core. #[global] Hint Extern 0 (is_true (in_mem ('Im _) _)) => solve [apply: Creal_Im] : core. Module Export Pdeg2. Module NumClosed. Section Pdeg2NumClosed. Variables (F : numClosedFieldType) (p : {poly F}). Hypothesis degp : size p = 3. Let a := p`_2. Let b := p`_1. Let c := p`_0. Let delta := b ^+ 2 - 4 * a * c. Let r1 := (- b - sqrtC delta) / (2 * a). Let r2 := (- b + sqrtC delta) / (2 * a). Lemma deg2_poly_factor : p = a *: ('X - r1%:P) * ('X - r2%:P). Proof. by apply: deg2_poly_factor; rewrite ?pnatr_eq0// sqrtCK. Qed. Lemma deg2_poly_root1 : root p r1. Proof. by apply: deg2_poly_root1; rewrite ?pnatr_eq0// sqrtCK. Qed. Lemma deg2_poly_root2 : root p r2. Proof. by apply: deg2_poly_root2; rewrite ?pnatr_eq0// sqrtCK. Qed. End Pdeg2NumClosed. End NumClosed. Module NumClosedMonic. Export FieldMonic. Section Pdeg2NumClosedMonic. Variables (F : numClosedFieldType) (p : {poly F}). Hypothesis degp : size p = 3. Hypothesis monicp : p \is monic. Let a := p`_2. Let b := p`_1. Let c := p`_0. Let delta := b ^+ 2 - 4 * c. Let r1 := (- b - sqrtC delta) / 2. Let r2 := (- b + sqrtC delta) / 2. Lemma deg2_poly_factor : p = ('X - r1%:P) * ('X - r2%:P). Proof. by apply: deg2_poly_factor; rewrite ?pnatr_eq0// sqrtCK. Qed. Lemma deg2_poly_root1 : root p r1. Proof. by apply: deg2_poly_root1; rewrite ?pnatr_eq0// sqrtCK. Qed. Lemma deg2_poly_root2 : root p r2. Proof. by apply: deg2_poly_root2; rewrite ?pnatr_eq0// sqrtCK. Qed. End Pdeg2NumClosedMonic. End NumClosedMonic. Module Real. Section Pdeg2Real. Variable F : realFieldType. Section Pdeg2RealConvex. Variable p : {poly F}. Hypothesis degp : size p = 3. Let a := p`_2. Let b := p`_1. Let c := p`_0. Hypothesis age0 : 0 <= a. Let delta := b ^+ 2 - 4 * a * c. Let pneq0 : p != 0. Proof. by rewrite -size_poly_gt0 degp. Qed. Let aneq0 : a != 0. Proof. by move: pneq0; rewrite -lead_coef_eq0 lead_coefE degp. Qed. Let agt0 : 0 < a. Proof. by rewrite lt_def aneq0. Qed. Let a4gt0 : 0 < 4 * a. Proof. by rewrite mulr_gt0 ?ltr0n. Qed. Lemma deg2_poly_min x : p.[- b / (2 * a)] <= p.[x]. Proof. rewrite [p]deg2_poly_canonical ?pnatr_eq0// -/a -/b -/c /delta !hornerE/=. by rewrite ler_pM2l// lerD2r addrC mulNr subrr expr0n sqr_ge0. Qed. Lemma deg2_poly_minE : p.[- b / (2 * a)] = - delta / (4 * a). Proof. rewrite [p]deg2_poly_canonical ?pnatr_eq0// -/a -/b -/c -/delta !hornerE/=. rewrite [X in X^+2]addrC [in LHS]mulNr subrr expr0n add0r mulNr. by rewrite mulrC mulNr invfM mulrA mulfVK. Qed. Lemma deg2_poly_gt0 : reflect (forall x, 0 < p.[x]) (delta < 0). Proof. apply/(iffP idP) => [dlt0 x | /(_ (- b / (2 * a)))]; last first. by rewrite deg2_poly_minE ltr_pdivlMr// mul0r oppr_gt0. apply: lt_le_trans (deg2_poly_min _). by rewrite deg2_poly_minE ltr_pdivlMr// mul0r oppr_gt0. Qed. Lemma deg2_poly_ge0 : reflect (forall x, 0 <= p.[x]) (delta <= 0). Proof. apply/(iffP idP) => [dlt0 x | /(_ (- b / (2 * a)))]; last first. by rewrite deg2_poly_minE ler_pdivlMr// mul0r oppr_ge0. apply: le_trans (deg2_poly_min _). by rewrite deg2_poly_minE ler_pdivlMr// mul0r oppr_ge0. Qed. End Pdeg2RealConvex. Section Pdeg2RealConcave. Variable p : {poly F}. Hypothesis degp : size p = 3. Let a := p`_2. Let b := p`_1. Let c := p`_0. Hypothesis ale0 : a <= 0. Let delta := b ^+ 2 - 4 * a * c. Let degpN : size (- p) = 3. Proof. by rewrite size_polyN. Qed. Let b2a : - (- p)`_1 / (2 * (- p)`_2) = - b / (2 * a). Proof. by rewrite !coefN mulrN divrNN. Qed. Let deltaN : (- p)`_1 ^+ 2 - 4 * (- p)`_2 * (- p)`_0 = delta. Proof. by rewrite !coefN sqrrN -mulrN opprK mulrN mulNr. Qed. Lemma deg2_poly_max x : p.[x] <= p.[- b / (2 * a)]. Proof. by rewrite -lerN2 -!hornerN -b2a deg2_poly_min// coefN oppr_ge0. Qed. Lemma deg2_poly_maxE : p.[- b / (2 * a)] = - delta / (4 * a). Proof. apply/eqP; rewrite [eqbRHS]mulNr -eqr_oppLR -hornerN -b2a. by rewrite deg2_poly_minE// deltaN coefN mulrN divrNN. Qed. Lemma deg2_poly_lt0 : reflect (forall x, p.[x] < 0) (delta < 0). Proof. rewrite -deltaN; apply/(iffP (deg2_poly_gt0 _ _)); rewrite ?coefN ?oppr_ge0//. - by move=> gt0 x; rewrite -oppr_gt0 -hornerN gt0. - by move=> lt0 x; rewrite hornerN oppr_gt0 lt0. Qed. Lemma deg2_poly_le0 : reflect (forall x, p.[x] <= 0) (delta <= 0). Proof. rewrite -deltaN; apply/(iffP (deg2_poly_ge0 _ _)); rewrite ?coefN ?oppr_ge0//. - by move=> ge0 x; rewrite -oppr_ge0 -hornerN ge0. - by move=> le0 x; rewrite hornerN oppr_ge0 le0. Qed. End Pdeg2RealConcave. End Pdeg2Real. Section Pdeg2RealClosed. Variable F : rcfType. Section Pdeg2RealClosedConvex. Variable p : {poly F}. Hypothesis degp : size p = 3. Let a := p`_2. Let b := p`_1. Let c := p`_0. Let pneq0 : p != 0. Proof. by rewrite -size_poly_gt0 degp. Qed. Let aneq0 : a != 0. Proof. by move: pneq0; rewrite -lead_coef_eq0 lead_coefE degp. Qed. Let sqa2 : 4 * a ^+ 2 = (2 * a) ^+ 2. Proof. by rewrite exprMn -natrX. Qed. Let nz2 : 2 != 0 :> F. Proof. by rewrite pnatr_eq0. Qed. Let delta := b ^+ 2 - 4 * a * c. Let r1 := (- b - sqrt delta) / (2 * a). Let r2 := (- b + sqrt delta) / (2 * a). Lemma deg2_poly_factor : 0 <= delta -> p = a *: ('X - r1%:P) * ('X - r2%:P). Proof. by move=> dge0; apply: deg2_poly_factor; rewrite ?sqr_sqrtr. Qed. Lemma deg2_poly_root1 : 0 <= delta -> root p r1. Proof. by move=> dge0; apply: deg2_poly_root1; rewrite ?sqr_sqrtr. Qed. Lemma deg2_poly_root2 : 0 <= delta -> root p r2. Proof. by move=> dge0; apply: deg2_poly_root2; rewrite ?sqr_sqrtr. Qed. Lemma deg2_poly_noroot : reflect (forall x, ~~ root p x) (delta < 0). Proof. apply/(iffP idP) => [dlt0 x | /(_ r1)]. case: ltgtP aneq0 => [agt0 _|alt0 _|//]; rewrite rootE; last first. exact/lt0r_neq0/(deg2_poly_gt0 degp (ltW alt0)). rewrite -oppr_eq0 -hornerN. apply/lt0r_neq0/deg2_poly_gt0; rewrite ?size_polyN ?coefN ?oppr_ge0 ?ltW//. by rewrite sqrrN -mulrA mulrNN mulrA. by rewrite ltNge; apply: contraNN => ?; apply: deg2_poly_root1. Qed. Hypothesis age0 : 0 <= a. Let agt0 : 0 < a. Proof. by rewrite lt_def aneq0. Qed. Let a2gt0 : 0 < 2 * a. Proof. by rewrite mulr_gt0 ?ltr0n. Qed. Let a4gt0 : 0 < 4 * a. Proof. by rewrite mulr_gt0 ?ltr0n. Qed. Let aa4gt0 : 0 < 4 * a * a. Proof. by rewrite mulr_gt0 ?ltr0n. Qed. Let xb4 x : (x + b / (2 * a)) ^+ 2 * (4 * a * a) = (x * (2 * a) + b) ^+ 2. Proof. have -> : 4 * a * a = (2 * a) ^+ 2 by rewrite expr2 mulrACA -natrM mulrA. by rewrite -exprMn mulrDl mulfVK ?mulf_neq0 ?pnatr_eq0. Qed. Lemma deg2_poly_gt0l x : x < r1 -> 0 < p.[x]. Proof. move=> xltr1; have [? | dge0] := ltP delta 0; first exact: deg2_poly_gt0. have {}xltr1 : sqrt delta < - (x * (2 * a) + b). by rewrite ltrNr -ltrBrDr addrC -ltr_pdivlMr. rewrite [p]deg2_poly_canonical// -/a -/b -/c -/delta !hornerE/=. rewrite mulr_gt0// subr_gt0 ltr_pdivrMr// xb4 -sqrrN. rewrite -ltr_sqrt ?sqrtr_sqr ?(lt_le_trans xltr1) ?ler_norm//. by rewrite exprn_gt0 ?(le_lt_trans _ xltr1) ?sqrtr_ge0. Qed. Lemma deg2_poly_gt0r x : r2 < x -> 0 < p.[x]. Proof. move=> xgtr2; have [? | dge0] := ltP delta 0; first exact: deg2_poly_gt0. have {}xgtr2 : sqrt delta < x * (2 * a) + b. by rewrite -ltrBlDr addrC -ltr_pdivrMr. rewrite [p]deg2_poly_canonical// -/a -/b -/c -/delta !hornerE/=. rewrite mulr_gt0// subr_gt0 ltr_pdivrMr// xb4. rewrite -ltr_sqrt ?sqrtr_sqr ?(lt_le_trans xgtr2) ?ler_norm//. by rewrite exprn_gt0 ?(le_lt_trans _ xgtr2) ?sqrtr_ge0. Qed. Lemma deg2_poly_lt0m x : r1 < x < r2 -> p.[x] < 0. Proof. move=> /andP[r1ltx xltr2]. have [dle0 | dgt0] := leP delta 0. by move: (lt_trans r1ltx xltr2); rewrite /r1 /r2 ler0_sqrtr// oppr0 ltxx. rewrite [p]deg2_poly_canonical// !hornerE/= -/a -/b -/c -/delta. rewrite pmulr_rlt0// subr_lt0 ltr_pdivlMr// xb4 -ltr_sqrt// sqrtr_sqr ltr_norml. by rewrite -ltrBlDr addrC -ltr_pdivrMr// r1ltx -ltrBrDr addrC -ltr_pdivlMr. Qed. Lemma deg2_poly_ge0l x : x <= r1 -> 0 <= p.[x]. Proof. rewrite le_eqVlt => /orP[/eqP->|xltr1]; last exact/ltW/deg2_poly_gt0l. have [dge0|dlt0] := leP 0 delta; last by apply: deg2_poly_ge0 => //; apply: ltW. by rewrite le_eqVlt (rootP (deg2_poly_root1 dge0)) eqxx. Qed. Lemma deg2_poly_ge0r x : r2 <= x -> 0 <= p.[x]. Proof. rewrite le_eqVlt => /orP[/eqP<-|xgtr2]; last exact/ltW/deg2_poly_gt0r. have [dge0|dlt0] := leP 0 delta; last by apply: deg2_poly_ge0 => //; apply: ltW. by rewrite le_eqVlt (rootP (deg2_poly_root2 dge0)) eqxx. Qed. Lemma deg2_poly_le0m x : 0 <= delta -> r1 <= x <= r2 -> p.[x] <= 0. Proof. move=> dge0; rewrite le_eqVlt andb_orl => /orP[/andP[/eqP<- _]|]. by rewrite le_eqVlt (rootP (deg2_poly_root1 dge0)) eqxx. rewrite le_eqVlt andb_orr => /orP[/andP[_ /eqP->]|]. by rewrite le_eqVlt (rootP (deg2_poly_root2 dge0)) eqxx. by move=> ?; apply/ltW/deg2_poly_lt0m. Qed. End Pdeg2RealClosedConvex. Section Pdeg2RealClosedConcave. Variable p : {poly F}. Hypothesis degp : size p = 3. Let a := p`_2. Let b := p`_1. Let c := p`_0. Let delta := b ^+ 2 - 4 * a * c. Let r1 := (- b + sqrt delta) / (2 * a). Let r2 := (- b - sqrt delta) / (2 * a). Hypothesis ale0 : a <= 0. Let degpN : size (- p) = 3. Proof. by rewrite size_polyN. Qed. Let aNge0 : 0 <= (- p)`_2. Proof. by rewrite coefN oppr_ge0. Qed. Let deltaN : (- p)`_1 ^+ 2 - 4 * (- p)`_2 * (- p)`_0 = delta. Proof. by rewrite !coefN sqrrN -mulrN opprK mulrN mulNr. Qed. Let r1N : (- (- p)`_1 - sqrt delta) / (2 * (- p)`_2) = r1. Proof. by rewrite !coefN -opprD mulrN divrNN. Qed. Let r2N : (- (- p)`_1 + sqrt delta) / (2 * (- p)`_2) = r2. Proof. by rewrite !coefN mulrN divrN -mulNr opprK opprD. Qed. Lemma deg2_poly_lt0l x : x < r1 -> p.[x] < 0. Proof. by move=> ?; rewrite -oppr_gt0 -hornerN deg2_poly_gt0l// deltaN r1N. Qed. Lemma deg2_poly_lt0r x : r2 < x -> p.[x] < 0. Proof. by move=> ?; rewrite -oppr_gt0 -hornerN deg2_poly_gt0r// deltaN r2N. Qed. Lemma deg2_poly_gt0m x : r1 < x < r2 -> 0 < p.[x]. Proof. by move=> ?; rewrite -oppr_lt0 -hornerN deg2_poly_lt0m// deltaN r1N r2N. Qed. Lemma deg2_poly_le0l x : x <= r1 -> p.[x] <= 0. Proof. by move=> ?; rewrite -oppr_ge0 -hornerN deg2_poly_ge0l// deltaN r1N. Qed. Lemma deg2_poly_le0r x : r2 <= x -> p.[x] <= 0. Proof. by move=> ?; rewrite -oppr_ge0 -hornerN deg2_poly_ge0r// deltaN r2N. Qed. Lemma deg2_poly_ge0m x : 0 <= delta -> r1 <= x <= r2 -> 0 <= p.[x]. Proof. by move=> ? ?; rewrite -oppr_le0 -hornerN deg2_poly_le0m ?deltaN// r1N r2N. Qed. End Pdeg2RealClosedConcave. End Pdeg2RealClosed. End Real. Module RealMonic. Import Real. Export FieldMonic. Section Pdeg2RealMonic. Variable F : realFieldType. Variable p : {poly F}. Hypothesis degp : size p = 3. Hypothesis monicp : p \is monic. Let a := p`_2. Let b := p`_1. Let c := p`_0. Let delta := b ^+ 2 - 4 * c. Let a1 : a = 1. Proof. by move: (monicP monicp); rewrite lead_coefE degp. Qed. Let a2 : 2 * a = 2. Proof. by rewrite a1 mulr1. Qed. Let a4 : 4 * a = 4. Proof. by rewrite a1 mulr1. Qed. Lemma deg2_poly_min x : p.[- b / 2] <= p.[x]. Proof. by rewrite -a2 deg2_poly_min -/a ?a1 ?ler01. Qed. Let deltam : delta = b ^+ 2 - 4 * a * c. Proof. by rewrite a1 mulr1. Qed. Lemma deg2_poly_minE : p.[- b / 2] = - delta / 4. Proof. by rewrite -a2 -a4 deltam deg2_poly_minE. Qed. Lemma deg2_poly_gt0 : reflect (forall x, 0 < p.[x]) (delta < 0). Proof. by rewrite deltam; apply: deg2_poly_gt0; rewrite // -/a a1 ler01. Qed. Lemma deg2_poly_ge0 : reflect (forall x, 0 <= p.[x]) (delta <= 0). Proof. by rewrite deltam; apply: deg2_poly_ge0; rewrite // -/a a1 ler01. Qed. End Pdeg2RealMonic. Section Pdeg2RealClosedMonic. Variables (F : rcfType) (p : {poly F}). Hypothesis degp : size p = 3. Hypothesis monicp : p \is monic. Let a := p`_2. Let b := p`_1. Let c := p`_0. Let a1 : a = 1. Proof. by move: (monicP monicp); rewrite lead_coefE degp. Qed. Let delta := b ^+ 2 - 4 * c. Let deltam : delta = b ^+ 2 - 4 * a * c. Proof. by rewrite a1 mulr1. Qed. Let r1 := (- b - sqrt delta) / 2. Let r2 := (- b + sqrt delta) / 2. Let nz2 : 2 != 0 :> F. Proof. by rewrite pnatr_eq0. Qed. Lemma deg2_poly_factor : 0 <= delta -> p = ('X - r1%:P) * ('X - r2%:P). Proof. by move=> dge0; apply: deg2_poly_factor; rewrite ?sqr_sqrtr. Qed. Lemma deg2_poly_root1 : 0 <= delta -> root p r1. Proof. by move=> dge0; apply: deg2_poly_root1; rewrite ?sqr_sqrtr. Qed. Lemma deg2_poly_root2 : 0 <= delta -> root p r2. Proof. by move=> dge0; apply: deg2_poly_root2; rewrite ?sqr_sqrtr. Qed. Lemma deg2_poly_noroot : reflect (forall x, ~~ root p x) (delta < 0). Proof. by rewrite deltam; apply: deg2_poly_noroot. Qed. Lemma deg2_poly_gt0l x : x < r1 -> 0 < p.[x]. Proof. by move=> ?; apply: deg2_poly_gt0l; rewrite // -/a ?a1 ?ler01 ?mulr1. Qed. Lemma deg2_poly_gt0r x : r2 < x -> 0 < p.[x]. Proof. by move=> ?; apply: deg2_poly_gt0r; rewrite // -/a ?a1 ?ler01 ?mulr1. Qed. Lemma deg2_poly_lt0m x : r1 < x < r2 -> p.[x] < 0. Proof. by move=> ?; apply: deg2_poly_lt0m; rewrite // -/a ?a1 ?ler01 ?mulr1. Qed. Lemma deg2_poly_ge0l x : x <= r1 -> 0 <= p.[x]. Proof. by move=> ?; apply: deg2_poly_ge0l; rewrite // -/a ?a1 ?ler01 ?mulr1. Qed. Lemma deg2_poly_ge0r x : r2 <= x -> 0 <= p.[x]. Proof. by move=> ?; apply: deg2_poly_ge0r; rewrite // -/a ?a1 ?ler01 ?mulr1. Qed. Lemma deg2_poly_le0m x : 0 <= delta -> r1 <= x <= r2 -> p.[x] <= 0. move=> dge0 xm. by apply: deg2_poly_le0m; rewrite -/a -/b -/c ?a1 ?mulr1 -/delta ?ler01. Qed. End Pdeg2RealClosedMonic. End RealMonic. End Pdeg2. Section Degle2PolyRealConvex. Variable (F : realFieldType) (p : {poly F}). Hypothesis degp : (size p <= 3)%N. Let a := p`_2. Let b := p`_1. Let c := p`_0. Let delta := b ^+ 2 - 4 * a * c. Lemma deg_le2_poly_delta_ge0 : 0 <= a -> (forall x, 0 <= p.[x]) -> delta <= 0. Proof. move=> age0 pge0; move: degp; rewrite leq_eqVlt => /orP[/eqP|] degp'. exact/(Real.deg2_poly_ge0 degp' age0). have a0 : a = 0 by rewrite /a nth_default. rewrite /delta a0 mulr0 mul0r subr0 exprn_even_le0//=. have [//|/eqP nzb] := eqP; move: (pge0 ((- 1 - c) / b)). have -> : p = b *: 'X + c%:P. apply/polyP => + /[!coefE] => -[|[|i]] /=; rewrite !Monoid.simpm//. by rewrite nth_default// -ltnS (leq_trans degp'). by rewrite !hornerE/= mulrAC mulfV// mul1r subrK ler0N1. Qed. End Degle2PolyRealConvex. Section Degle2PolyRealConcave. Variable (F : realFieldType) (p : {poly F}). Hypothesis degp : (size p <= 3)%N. Let a := p`_2. Let b := p`_1. Let c := p`_0. Let delta := b ^+ 2 - 4 * a * c. Lemma deg_le2_poly_delta_le0 : a <= 0 -> (forall x, p.[x] <= 0) -> delta <= 0. Proof. move=> ale0 ple0; rewrite /delta -sqrrN -[c]opprK mulrN -mulNr -[-(4 * a)]mulrN. rewrite -!coefN deg_le2_poly_delta_ge0 ?size_polyN ?coefN ?oppr_ge0// => x. by rewrite hornerN oppr_ge0. Qed. End Degle2PolyRealConcave. Section Degle2PolyRealClosedConvex. Variable (F : rcfType) (p : {poly F}). Hypothesis degp : (size p <= 3)%N. Let a := p`_2. Let b := p`_1. Let c := p`_0. Let delta := b ^+ 2 - 4 * a * c. Lemma deg_le2_poly_ge0 : (forall x, 0 <= p.[x]) -> delta <= 0. Proof. have [age0|alt0] := leP 0 a; first exact: deg_le2_poly_delta_ge0. move=> pge0; move: degp; rewrite leq_eqVlt => /orP[/eqP|] degp'; last first. by move: alt0; rewrite /a nth_default ?ltxx. have [//|dge0] := leP delta 0. pose r1 := (- b - sqrt delta) / (2 * a). pose r2 := (- b + sqrt delta) / (2 * a). pose x0 := Num.max (r1 + 1) (r2 + 1). move: (pge0 x0); rewrite (Real.deg2_poly_factor degp' (ltW dge0)). rewrite !hornerE/= -mulrA nmulr_rge0// leNgt => /negbTE<-. by apply: mulr_gt0; rewrite subr_gt0 lt_max ltrDl ltr01 ?orbT. Qed. End Degle2PolyRealClosedConvex. Section Degle2PolyRealClosedConcave. Variable (F : rcfType) (p : {poly F}). Hypothesis degp : (size p <= 3)%N. Let a := p`_2. Let b := p`_1. Let c := p`_0. Let delta := b ^+ 2 - 4 * a * c. Lemma deg_le2_poly_le0 : (forall x, p.[x] <= 0) -> delta <= 0. Proof. move=> ple0; rewrite /delta -sqrrN -[c]opprK mulrN -mulNr -[-(4 * a)]mulrN. by rewrite -!coefN deg_le2_poly_ge0 ?size_polyN// => x; rewrite hornerN oppr_ge0. Qed. End Degle2PolyRealClosedConcave. End Theory. Module Exports. HB.reexport. End Exports. End Num. Export Num.Exports.
Radical.lean
/- Copyright (c) 2024 Jineon Baek, Seewoo Lee. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jineon Baek, Seewoo Lee -/ import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.RingTheory.Polynomial.Wronskian import Mathlib.RingTheory.Radical import Mathlib.RingTheory.UniqueFactorizationDomain.Multiplicative /-! # Radical of a polynomial This file proves some theorems on `radical` and `divRadical` of polynomials. See `RingTheory.Radical` for the definition of `radical` and `divRadical`. -/ open Polynomial UniqueFactorizationMonoid UniqueFactorizationDomain EuclideanDomain variable {k : Type*} [Field k] [DecidableEq k] theorem degree_radical_le {a : k[X]} (h : a ≠ 0) : (radical a).degree ≤ a.degree := degree_le_of_dvd radical_dvd_self h theorem natDegree_radical_le {a : k[X]} : (radical a).natDegree ≤ a.natDegree := by by_cases ha : a = 0 · simp [ha] · exact natDegree_le_of_dvd radical_dvd_self ha theorem divRadical_dvd_derivative (a : k[X]) : divRadical a ∣ derivative a := by induction a using induction_on_coprime · case h0 => rw [derivative_zero] apply dvd_zero · case h1 a ha => exact (divRadical_isUnit ha).dvd · case hpr p i hp => cases i · rw [pow_zero, derivative_one] apply dvd_zero · case succ i => rw [← mul_dvd_mul_iff_left radical_ne_zero, radical_mul_divRadical, radical_pow_of_prime hp i.succ_ne_zero, derivative_pow_succ, ← mul_assoc] apply dvd_mul_of_dvd_left rw [mul_comm, mul_assoc] apply dvd_mul_of_dvd_right rw [pow_succ, mul_dvd_mul_iff_left (pow_ne_zero i hp.ne_zero), dvd_normalize_iff] · -- If it holds for coprime pair a and b, then it also holds for a * b. case hcp x y hpxy hx hy => have hc : IsCoprime x y := EuclideanDomain.isCoprime_of_dvd (fun ⟨hx, hy⟩ => not_isUnit_zero (hpxy (zero_dvd_iff.mpr hx) (zero_dvd_iff.mpr hy))) fun p hp _ hpx hpy => hp (hpxy hpx hpy) rw [divRadical_mul hc, derivative_mul] exact dvd_add (mul_dvd_mul hx (divRadical_dvd_self y)) (mul_dvd_mul (divRadical_dvd_self x) hy) theorem divRadical_dvd_wronskian_left (a b : k[X]) : divRadical a ∣ wronskian a b := by rw [wronskian] apply dvd_sub · apply dvd_mul_of_dvd_left exact divRadical_dvd_self a · apply dvd_mul_of_dvd_left exact divRadical_dvd_derivative a theorem divRadical_dvd_wronskian_right (a b : k[X]) : divRadical b ∣ wronskian a b := by rw [← wronskian_neg_eq, dvd_neg] exact divRadical_dvd_wronskian_left _ _
Jacobian.lean
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.FDeriv.Congr import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap import Mathlib.MeasureTheory.Covering.BesicovitchVectorSpace import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.MeasureTheory.Constructions.Polish.Basic import Mathlib.Analysis.Calculus.InverseFunctionTheorem.ApproximatesLinearOn import Mathlib.Topology.Algebra.Module.Determinant /-! # Change of variables in higher-dimensional integrals Let `μ` be a Lebesgue measure on a finite-dimensional real vector space `E`. Let `f : E → E` be a function which is injective and differentiable on a measurable set `s`, with derivative `f'`. Then we prove that `f '' s` is measurable, and its measure is given by the formula `μ (f '' s) = ∫⁻ x in s, |(f' x).det| ∂μ` (where `(f' x).det` is almost everywhere measurable, but not Borel-measurable in general). This formula is proved in `lintegral_abs_det_fderiv_eq_addHaar_image`. We deduce the change of variables formula for the Lebesgue and Bochner integrals, in `lintegral_image_eq_lintegral_abs_det_fderiv_mul` and `integral_image_eq_integral_abs_det_fderiv_smul` respectively. Specialized versions in one dimension (using the derivative instead of the determinant of the Fréchet derivative) can be found in the file `Mathlib/MeasureTheory/Function/JacobianOneDim.lean`, together with versions for monotone and antitone functions. ## Main results * `addHaar_image_eq_zero_of_differentiableOn_of_addHaar_eq_zero`: if `f` is differentiable on a set `s` with zero measure, then `f '' s` also has zero measure. * `addHaar_image_eq_zero_of_det_fderivWithin_eq_zero`: if `f` is differentiable on a set `s`, and its derivative is never invertible, then `f '' s` has zero measure (a version of Sard's lemma). * `aemeasurable_fderivWithin`: if `f` is differentiable on a measurable set `s`, then `f'` is almost everywhere measurable on `s`. For the next statements, `s` is a measurable set and `f` is differentiable on `s` (with a derivative `f'`) and injective on `s`. * `measurable_image_of_fderivWithin`: the image `f '' s` is measurable. * `measurableEmbedding_of_fderivWithin`: the function `s.restrict f` is a measurable embedding. * `lintegral_abs_det_fderiv_eq_addHaar_image`: the image measure is given by `μ (f '' s) = ∫⁻ x in s, |(f' x).det| ∂μ`. * `lintegral_image_eq_lintegral_abs_det_fderiv_mul`: for `g : E → ℝ≥0∞`, one has `∫⁻ x in f '' s, g x ∂μ = ∫⁻ x in s, ENNReal.ofReal |(f' x).det| * g (f x) ∂μ`. * `integral_image_eq_integral_abs_det_fderiv_smul`: for `g : E → F`, one has `∫ x in f '' s, g x ∂μ = ∫ x in s, |(f' x).det| • g (f x) ∂μ`. * `integrableOn_image_iff_integrableOn_abs_det_fderiv_smul`: for `g : E → F`, the function `g` is integrable on `f '' s` if and only if `|(f' x).det| • g (f x))` is integrable on `s`. ## Implementation Typical versions of these results in the literature have much stronger assumptions: `s` would typically be open, and the derivative `f' x` would depend continuously on `x` and be invertible everywhere, to have the local inverse theorem at our disposal. The proof strategy under our weaker assumptions is more involved. We follow [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2]. The first remark is that, if `f` is sufficiently well approximated by a linear map `A` on a set `s`, then `f` expands the volume of `s` by at least `A.det - ε` and at most `A.det + ε`, where the closeness condition depends on `A` in a non-explicit way (see `addHaar_image_le_mul_of_det_lt` and `mul_le_addHaar_image_of_lt_det`). This fact holds for balls by a simple inclusion argument, and follows for general sets using the Besicovitch covering theorem to cover the set by balls with measures adding up essentially to `μ s`. When `f` is differentiable on `s`, one may partition `s` into countably many subsets `s ∩ t n` (where `t n` is measurable), on each of which `f` is well approximated by a linear map, so that the above results apply. See `exists_partition_approximatesLinearOn_of_hasFDerivWithinAt`, which follows from the pointwise differentiability (in a non-completely trivial way, as one should ensure a form of uniformity on the sets of the partition). Combining the above two results would give the conclusion, except for two difficulties: it is not obvious why `f '' s` and `f'` should be measurable, which prevents us from using countable additivity for the measure and the integral. It turns out that `f '' s` is indeed measurable, and that `f'` is almost everywhere measurable, which is enough to recover countable additivity. The measurability of `f '' s` follows from the deep Lusin-Souslin theorem ensuring that, in a Polish space, a continuous injective image of a measurable set is measurable. The key point to check the almost everywhere measurability of `f'` is that, if `f` is approximated up to `δ` by a linear map on a set `s`, then `f'` is within `δ` of `A` on a full measure subset of `s` (namely, its density points). With the above approximation argument, it follows that `f'` is the almost everywhere limit of a sequence of measurable functions (which are constant on the pieces of the good discretization), and is therefore almost everywhere measurable. ## Tags Change of variables in integrals ## References [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2] -/ open MeasureTheory MeasureTheory.Measure Metric Filter Set Module Asymptotics TopologicalSpace open scoped NNReal ENNReal Topology Pointwise variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {s : Set E} {f : E → E} {f' : E → E →L[ℝ] E} /-! ### Decomposition lemmas We state lemmas ensuring that a differentiable function can be approximated, on countably many measurable pieces, by linear maps (with a prescribed precision depending on the linear map). -/ /-- Assume that a function `f` has a derivative at every point of a set `s`. Then one may cover `s` with countably many closed sets `t n` on which `f` is well approximated by linear maps `A n`. -/ theorem exists_closed_cover_approximatesLinearOn_of_hasFDerivWithinAt [SecondCountableTopology F] (f : E → F) (s : Set E) (f' : E → E →L[ℝ] F) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (r : (E →L[ℝ] F) → ℝ≥0) (rpos : ∀ A, r A ≠ 0) : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] F), (∀ n, IsClosed (t n)) ∧ (s ⊆ ⋃ n, t n) ∧ (∀ n, ApproximatesLinearOn f (A n) (s ∩ t n) (r (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := by /- Choose countably many linear maps `f' z`. For every such map, if `f` has a derivative at `x` close enough to `f' z`, then `f y - f x` is well approximated by `f' z (y - x)` for `y` close enough to `x`, say on a ball of radius `r` (or even `u n` for some `n`, where `u` is a fixed sequence tending to `0`). Let `M n z` be the points where this happens. Then this set is relatively closed inside `s`, and moreover in every closed ball of radius `u n / 3` inside it the map is well approximated by `f' z`. Using countably many closed balls to split `M n z` into small diameter subsets `K n z p`, one obtains the desired sets `t q` after reindexing. -/ -- exclude the trivial case where `s` is empty rcases eq_empty_or_nonempty s with (rfl | hs) · refine ⟨fun _ => ∅, fun _ => 0, ?_, ?_, ?_, ?_⟩ <;> simp -- we will use countably many linear maps. Select these from all the derivatives since the -- space of linear maps is second-countable obtain ⟨T, T_count, hT⟩ : ∃ T : Set s, T.Countable ∧ ⋃ x ∈ T, ball (f' (x : E)) (r (f' x)) = ⋃ x : s, ball (f' x) (r (f' x)) := TopologicalSpace.isOpen_iUnion_countable _ fun x => isOpen_ball -- fix a sequence `u` of positive reals tending to zero. obtain ⟨u, _, u_pos, u_lim⟩ : ∃ u : ℕ → ℝ, StrictAnti u ∧ (∀ n : ℕ, 0 < u n) ∧ Tendsto u atTop (𝓝 0) := exists_seq_strictAnti_tendsto (0 : ℝ) -- `M n z` is the set of points `x` such that `f y - f x` is close to `f' z (y - x)` for `y` -- in the ball of radius `u n` around `x`. let M : ℕ → T → Set E := fun n z => {x | x ∈ s ∧ ∀ y ∈ s ∩ ball x (u n), ‖f y - f x - f' z (y - x)‖ ≤ r (f' z) * ‖y - x‖} -- As `f` is differentiable everywhere on `s`, the sets `M n z` cover `s` by design. have s_subset : ∀ x ∈ s, ∃ (n : ℕ) (z : T), x ∈ M n z := by intro x xs obtain ⟨z, zT, hz⟩ : ∃ z ∈ T, f' x ∈ ball (f' (z : E)) (r (f' z)) := by have : f' x ∈ ⋃ z ∈ T, ball (f' (z : E)) (r (f' z)) := by rw [hT] refine mem_iUnion.2 ⟨⟨x, xs⟩, ?_⟩ simpa only [mem_ball, Subtype.coe_mk, dist_self] using (rpos (f' x)).bot_lt rwa [mem_iUnion₂, bex_def] at this obtain ⟨ε, εpos, hε⟩ : ∃ ε : ℝ, 0 < ε ∧ ‖f' x - f' z‖ + ε ≤ r (f' z) := by refine ⟨r (f' z) - ‖f' x - f' z‖, ?_, le_of_eq (by abel)⟩ simpa only [sub_pos] using mem_ball_iff_norm.mp hz obtain ⟨δ, δpos, hδ⟩ : ∃ (δ : ℝ), 0 < δ ∧ ball x δ ∩ s ⊆ {y | ‖f y - f x - (f' x) (y - x)‖ ≤ ε * ‖y - x‖} := Metric.mem_nhdsWithin_iff.1 ((hf' x xs).isLittleO.def εpos) obtain ⟨n, hn⟩ : ∃ n, u n < δ := ((tendsto_order.1 u_lim).2 _ δpos).exists refine ⟨n, ⟨z, zT⟩, ⟨xs, ?_⟩⟩ intro y hy calc ‖f y - f x - (f' z) (y - x)‖ = ‖f y - f x - (f' x) (y - x) + (f' x - f' z) (y - x)‖ := by congr 1 simp only [ContinuousLinearMap.coe_sub', map_sub, Pi.sub_apply] abel _ ≤ ‖f y - f x - (f' x) (y - x)‖ + ‖(f' x - f' z) (y - x)‖ := norm_add_le _ _ _ ≤ ε * ‖y - x‖ + ‖f' x - f' z‖ * ‖y - x‖ := by refine add_le_add (hδ ?_) (ContinuousLinearMap.le_opNorm _ _) rw [inter_comm] exact inter_subset_inter_right _ (ball_subset_ball hn.le) hy _ ≤ r (f' z) * ‖y - x‖ := by rw [← add_mul, add_comm] gcongr -- the sets `M n z` are relatively closed in `s`, as all the conditions defining it are clearly -- closed have closure_M_subset : ∀ n z, s ∩ closure (M n z) ⊆ M n z := by rintro n z x ⟨xs, hx⟩ refine ⟨xs, fun y hy => ?_⟩ obtain ⟨a, aM, a_lim⟩ : ∃ a : ℕ → E, (∀ k, a k ∈ M n z) ∧ Tendsto a atTop (𝓝 x) := mem_closure_iff_seq_limit.1 hx have L1 : Tendsto (fun k : ℕ => ‖f y - f (a k) - (f' z) (y - a k)‖) atTop (𝓝 ‖f y - f x - (f' z) (y - x)‖) := by apply Tendsto.norm have L : Tendsto (fun k => f (a k)) atTop (𝓝 (f x)) := by apply (hf' x xs).continuousWithinAt.tendsto.comp apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ a_lim exact Eventually.of_forall fun k => (aM k).1 apply Tendsto.sub (tendsto_const_nhds.sub L) exact ((f' z).continuous.tendsto _).comp (tendsto_const_nhds.sub a_lim) have L2 : Tendsto (fun k : ℕ => (r (f' z) : ℝ) * ‖y - a k‖) atTop (𝓝 (r (f' z) * ‖y - x‖)) := (tendsto_const_nhds.sub a_lim).norm.const_mul _ have I : ∀ᶠ k in atTop, ‖f y - f (a k) - (f' z) (y - a k)‖ ≤ r (f' z) * ‖y - a k‖ := by have L : Tendsto (fun k => dist y (a k)) atTop (𝓝 (dist y x)) := tendsto_const_nhds.dist a_lim filter_upwards [(tendsto_order.1 L).2 _ hy.2] intro k hk exact (aM k).2 y ⟨hy.1, hk⟩ exact le_of_tendsto_of_tendsto L1 L2 I -- choose a dense sequence `d p` rcases TopologicalSpace.exists_dense_seq E with ⟨d, hd⟩ -- split `M n z` into subsets `K n z p` of small diameters by intersecting with the ball -- `closedBall (d p) (u n / 3)`. let K : ℕ → T → ℕ → Set E := fun n z p => closure (M n z) ∩ closedBall (d p) (u n / 3) -- on the sets `K n z p`, the map `f` is well approximated by `f' z` by design. have K_approx : ∀ (n) (z : T) (p), ApproximatesLinearOn f (f' z) (s ∩ K n z p) (r (f' z)) := by intro n z p x hx y hy have yM : y ∈ M n z := closure_M_subset _ _ ⟨hy.1, hy.2.1⟩ refine yM.2 _ ⟨hx.1, ?_⟩ calc dist x y ≤ dist x (d p) + dist y (d p) := dist_triangle_right _ _ _ _ ≤ u n / 3 + u n / 3 := add_le_add hx.2.2 hy.2.2 _ < u n := by linarith [u_pos n] -- the sets `K n z p` are also closed, again by design. have K_closed : ∀ (n) (z : T) (p), IsClosed (K n z p) := fun n z p => isClosed_closure.inter isClosed_closedBall -- reindex the sets `K n z p`, to let them only depend on an integer parameter `q`. obtain ⟨F, hF⟩ : ∃ F : ℕ → ℕ × T × ℕ, Function.Surjective F := by haveI : Encodable T := T_count.toEncodable have : Nonempty T := by rcases hs with ⟨x, xs⟩ rcases s_subset x xs with ⟨n, z, _⟩ exact ⟨z⟩ inhabit ↥T exact ⟨_, Encodable.surjective_decode_iget (ℕ × T × ℕ)⟩ -- these sets `t q = K n z p` will do refine ⟨fun q => K (F q).1 (F q).2.1 (F q).2.2, fun q => f' (F q).2.1, fun n => K_closed _ _ _, fun x xs => ?_, fun q => K_approx _ _ _, fun _ q => ⟨(F q).2.1, (F q).2.1.1.2, rfl⟩⟩ -- the only fact that needs further checking is that they cover `s`. -- we already know that any point `x ∈ s` belongs to a set `M n z`. obtain ⟨n, z, hnz⟩ : ∃ (n : ℕ) (z : T), x ∈ M n z := s_subset x xs -- by density, it also belongs to a ball `closedBall (d p) (u n / 3)`. obtain ⟨p, hp⟩ : ∃ p : ℕ, x ∈ closedBall (d p) (u n / 3) := by have : Set.Nonempty (ball x (u n / 3)) := by simp only [nonempty_ball]; linarith [u_pos n] obtain ⟨p, hp⟩ : ∃ p : ℕ, d p ∈ ball x (u n / 3) := hd.exists_mem_open isOpen_ball this exact ⟨p, (mem_ball'.1 hp).le⟩ -- choose `q` for which `t q = K n z p`. obtain ⟨q, hq⟩ : ∃ q, F q = (n, z, p) := hF _ -- then `x` belongs to `t q`. apply mem_iUnion.2 ⟨q, _⟩ simp -zeta only [K, hq, mem_inter_iff, hp, and_true] exact subset_closure hnz variable [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] open scoped Function -- required for scoped `on` notation /-- Assume that a function `f` has a derivative at every point of a set `s`. Then one may partition `s` into countably many disjoint relatively measurable sets (i.e., intersections of `s` with measurable sets `t n`) on which `f` is well approximated by linear maps `A n`. -/ theorem exists_partition_approximatesLinearOn_of_hasFDerivWithinAt [SecondCountableTopology F] (f : E → F) (s : Set E) (f' : E → E →L[ℝ] F) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (r : (E →L[ℝ] F) → ℝ≥0) (rpos : ∀ A, r A ≠ 0) : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] F), Pairwise (Disjoint on t) ∧ (∀ n, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n, t n) ∧ (∀ n, ApproximatesLinearOn f (A n) (s ∩ t n) (r (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := by rcases exists_closed_cover_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' r rpos with ⟨t, A, t_closed, st, t_approx, ht⟩ refine ⟨disjointed t, A, disjoint_disjointed _, MeasurableSet.disjointed fun n => (t_closed n).measurableSet, ?_, ?_, ht⟩ · rw [iUnion_disjointed]; exact st · intro n; exact (t_approx n).mono_set (inter_subset_inter_right _ (disjointed_subset _ _)) namespace MeasureTheory /-! ### Local lemmas We check that a function which is well enough approximated by a linear map expands the volume essentially like this linear map, and that its derivative (if it exists) is almost everywhere close to the approximating linear map. -/ /-- Let `f` be a function which is sufficiently close (in the Lipschitz sense) to a given linear map `A`. Then it expands the volume of any set by at most `m` for any `m > det A`. -/ theorem addHaar_image_le_mul_of_det_lt (A : E →L[ℝ] E) {m : ℝ≥0} (hm : ENNReal.ofReal |A.det| < m) : ∀ᶠ δ in 𝓝[>] (0 : ℝ≥0), ∀ (s : Set E) (f : E → E), ApproximatesLinearOn f A s δ → μ (f '' s) ≤ m * μ s := by apply nhdsWithin_le_nhds let d := ENNReal.ofReal |A.det| -- construct a small neighborhood of `A '' (closedBall 0 1)` with measure comparable to -- the determinant of `A`. obtain ⟨ε, hε, εpos⟩ : ∃ ε : ℝ, μ (closedBall 0 ε + A '' closedBall 0 1) < m * μ (closedBall 0 1) ∧ 0 < ε := by have HC : IsCompact (A '' closedBall 0 1) := (ProperSpace.isCompact_closedBall _ _).image A.continuous have L0 : Tendsto (fun ε => μ (cthickening ε (A '' closedBall 0 1))) (𝓝[>] 0) (𝓝 (μ (A '' closedBall 0 1))) := by apply Tendsto.mono_left _ nhdsWithin_le_nhds exact tendsto_measure_cthickening_of_isCompact HC have L1 : Tendsto (fun ε => μ (closedBall 0 ε + A '' closedBall 0 1)) (𝓝[>] 0) (𝓝 (μ (A '' closedBall 0 1))) := by apply L0.congr' _ filter_upwards [self_mem_nhdsWithin] with r hr rw [← HC.add_closedBall_zero (le_of_lt hr), add_comm] have L2 : Tendsto (fun ε => μ (closedBall 0 ε + A '' closedBall 0 1)) (𝓝[>] 0) (𝓝 (d * μ (closedBall 0 1))) := by convert L1 exact (addHaar_image_continuousLinearMap _ _ _).symm have I : d * μ (closedBall 0 1) < m * μ (closedBall 0 1) := (ENNReal.mul_lt_mul_right (measure_closedBall_pos μ _ zero_lt_one).ne' measure_closedBall_lt_top.ne).2 hm have H : ∀ᶠ b : ℝ in 𝓝[>] 0, μ (closedBall 0 b + A '' closedBall 0 1) < m * μ (closedBall 0 1) := (tendsto_order.1 L2).2 _ I exact (H.and self_mem_nhdsWithin).exists have : Iio (⟨ε, εpos.le⟩ : ℝ≥0) ∈ 𝓝 (0 : ℝ≥0) := by apply Iio_mem_nhds; exact εpos filter_upwards [this] -- fix a function `f` which is close enough to `A`. intro δ hδ s f hf simp only [mem_Iio, ← NNReal.coe_lt_coe, NNReal.coe_mk] at hδ -- This function expands the volume of any ball by at most `m` have I : ∀ x r, x ∈ s → 0 ≤ r → μ (f '' (s ∩ closedBall x r)) ≤ m * μ (closedBall x r) := by intro x r xs r0 have K : f '' (s ∩ closedBall x r) ⊆ A '' closedBall 0 r + closedBall (f x) (ε * r) := by rintro y ⟨z, ⟨zs, zr⟩, rfl⟩ rw [mem_closedBall_iff_norm] at zr apply Set.mem_add.2 ⟨A (z - x), _, f z - f x - A (z - x) + f x, _, _⟩ · apply mem_image_of_mem simpa only [dist_eq_norm, mem_closedBall, mem_closedBall_zero_iff, sub_zero] using zr · rw [mem_closedBall_iff_norm, add_sub_cancel_right] calc ‖f z - f x - A (z - x)‖ ≤ δ * ‖z - x‖ := hf _ zs _ xs _ ≤ ε * r := by gcongr · simp only [map_sub] abel have : A '' closedBall 0 r + closedBall (f x) (ε * r) = {f x} + r • (A '' closedBall 0 1 + closedBall 0 ε) := by rw [smul_add, ← add_assoc, add_comm {f x}, add_assoc, smul_closedBall _ _ εpos.le, smul_zero, singleton_add_closedBall_zero, ← image_smul_set, _root_.smul_closedBall _ _ zero_le_one, smul_zero, Real.norm_eq_abs, abs_of_nonneg r0, mul_one, mul_comm] rw [this] at K calc μ (f '' (s ∩ closedBall x r)) ≤ μ ({f x} + r • (A '' closedBall 0 1 + closedBall 0 ε)) := measure_mono K _ = ENNReal.ofReal (r ^ finrank ℝ E) * μ (A '' closedBall 0 1 + closedBall 0 ε) := by simp only [abs_of_nonneg r0, addHaar_smul, image_add_left, abs_pow, singleton_add, measure_preimage_add] _ ≤ ENNReal.ofReal (r ^ finrank ℝ E) * (m * μ (closedBall 0 1)) := by rw [add_comm]; gcongr _ = m * μ (closedBall x r) := by simp only [addHaar_closedBall' μ _ r0]; ring -- covering `s` by closed balls with total measure very close to `μ s`, one deduces that the -- measure of `f '' s` is at most `m * (μ s + a)` for any positive `a`. have J : ∀ᶠ a in 𝓝[>] (0 : ℝ≥0∞), μ (f '' s) ≤ m * (μ s + a) := by filter_upwards [self_mem_nhdsWithin] with a ha rw [mem_Ioi] at ha obtain ⟨t, r, t_count, ts, rpos, st, μt⟩ : ∃ (t : Set E) (r : E → ℝ), t.Countable ∧ t ⊆ s ∧ (∀ x : E, x ∈ t → 0 < r x) ∧ (s ⊆ ⋃ x ∈ t, closedBall x (r x)) ∧ (∑' x : ↥t, μ (closedBall (↑x) (r ↑x))) ≤ μ s + a := Besicovitch.exists_closedBall_covering_tsum_measure_le μ ha.ne' (fun _ => Ioi 0) s fun x _ δ δpos => ⟨δ / 2, by simp [half_pos δpos, δpos]⟩ haveI : Encodable t := t_count.toEncodable calc μ (f '' s) ≤ μ (⋃ x : t, f '' (s ∩ closedBall x (r x))) := by rw [biUnion_eq_iUnion] at st apply measure_mono rw [← image_iUnion, ← inter_iUnion] exact Set.image_mono (subset_inter (Subset.refl _) st) _ ≤ ∑' x : t, μ (f '' (s ∩ closedBall x (r x))) := measure_iUnion_le _ _ ≤ ∑' x : t, m * μ (closedBall x (r x)) := (ENNReal.tsum_le_tsum fun x => I x (r x) (ts x.2) (rpos x x.2).le) _ ≤ m * (μ s + a) := by rw [ENNReal.tsum_mul_left]; gcongr -- taking the limit in `a`, one obtains the conclusion have L : Tendsto (fun a => (m : ℝ≥0∞) * (μ s + a)) (𝓝[>] 0) (𝓝 (m * (μ s + 0))) := by apply Tendsto.mono_left _ nhdsWithin_le_nhds apply ENNReal.Tendsto.const_mul (tendsto_const_nhds.add tendsto_id) simp only [ENNReal.coe_ne_top, Ne, or_true, not_false_iff] rw [add_zero] at L exact ge_of_tendsto L J /-- Let `f` be a function which is sufficiently close (in the Lipschitz sense) to a given linear map `A`. Then it expands the volume of any set by at least `m` for any `m < det A`. -/ theorem mul_le_addHaar_image_of_lt_det (A : E →L[ℝ] E) {m : ℝ≥0} (hm : (m : ℝ≥0∞) < ENNReal.ofReal |A.det|) : ∀ᶠ δ in 𝓝[>] (0 : ℝ≥0), ∀ (s : Set E) (f : E → E), ApproximatesLinearOn f A s δ → (m : ℝ≥0∞) * μ s ≤ μ (f '' s) := by apply nhdsWithin_le_nhds -- The assumption `hm` implies that `A` is invertible. If `f` is close enough to `A`, it is also -- invertible. One can then pass to the inverses, and deduce the estimate from -- `addHaar_image_le_mul_of_det_lt` applied to `f⁻¹` and `A⁻¹`. -- exclude first the trivial case where `m = 0`. rcases eq_or_lt_of_le (zero_le m) with (rfl | mpos) · filter_upwards simp only [forall_const, zero_mul, imp_true_iff, zero_le, ENNReal.coe_zero] have hA : A.det ≠ 0 := by intro h; simp only [h, ENNReal.not_lt_zero, ENNReal.ofReal_zero, abs_zero] at hm -- let `B` be the continuous linear equiv version of `A`. let B := A.toContinuousLinearEquivOfDetNeZero hA -- the determinant of `B.symm` is bounded by `m⁻¹` have I : ENNReal.ofReal |(B.symm : E →L[ℝ] E).det| < (m⁻¹ : ℝ≥0) := by simp only [ENNReal.ofReal, abs_inv, Real.toNNReal_inv, ContinuousLinearEquiv.det_coe_symm, ENNReal.coe_lt_coe] at hm ⊢ exact NNReal.inv_lt_inv mpos.ne' hm -- therefore, we may apply `addHaar_image_le_mul_of_det_lt` to `B.symm` and `m⁻¹`. obtain ⟨δ₀, δ₀pos, hδ₀⟩ : ∃ δ : ℝ≥0, 0 < δ ∧ ∀ (t : Set E) (g : E → E), ApproximatesLinearOn g (B.symm : E →L[ℝ] E) t δ → μ (g '' t) ≤ ↑m⁻¹ * μ t := by have : ∀ᶠ δ : ℝ≥0 in 𝓝[>] 0, ∀ (t : Set E) (g : E → E), ApproximatesLinearOn g (B.symm : E →L[ℝ] E) t δ → μ (g '' t) ≤ ↑m⁻¹ * μ t := addHaar_image_le_mul_of_det_lt μ B.symm I rcases (this.and self_mem_nhdsWithin).exists with ⟨δ₀, h, h'⟩ exact ⟨δ₀, h', h⟩ -- record smallness conditions for `δ` that will be needed to apply `hδ₀` below. have L1 : ∀ᶠ δ in 𝓝 (0 : ℝ≥0), Subsingleton E ∨ δ < ‖(B.symm : E →L[ℝ] E)‖₊⁻¹ := by by_cases h : Subsingleton E · simp only [h, true_or, eventually_const] simp only [h, false_or] apply Iio_mem_nhds simpa only [h, false_or, inv_pos] using B.subsingleton_or_nnnorm_symm_pos have L2 : ∀ᶠ δ in 𝓝 (0 : ℝ≥0), ‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - δ)⁻¹ * δ < δ₀ := by have : Tendsto (fun δ => ‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - δ)⁻¹ * δ) (𝓝 0) (𝓝 (‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - 0)⁻¹ * 0)) := by rcases eq_or_ne ‖(B.symm : E →L[ℝ] E)‖₊ 0 with (H | H) · simpa only [H, zero_mul] using tendsto_const_nhds refine Tendsto.mul (tendsto_const_nhds.mul ?_) tendsto_id refine (Tendsto.sub tendsto_const_nhds tendsto_id).inv₀ ?_ simpa only [tsub_zero, inv_eq_zero, Ne] using H simp only [mul_zero] at this exact (tendsto_order.1 this).2 δ₀ δ₀pos -- let `δ` be small enough, and `f` approximated by `B` up to `δ`. filter_upwards [L1, L2] intro δ h1δ h2δ s f hf have hf' : ApproximatesLinearOn f (B : E →L[ℝ] E) s δ := by convert hf let F := hf'.toPartialEquiv h1δ -- the condition to be checked can be reformulated in terms of the inverse maps suffices H : μ (F.symm '' F.target) ≤ (m⁻¹ : ℝ≥0) * μ F.target by change (m : ℝ≥0∞) * μ F.source ≤ μ F.target rwa [← F.symm_image_target_eq_source, mul_comm, ← ENNReal.le_div_iff_mul_le, div_eq_mul_inv, mul_comm, ← ENNReal.coe_inv mpos.ne'] · apply Or.inl simpa only [ENNReal.coe_eq_zero, Ne] using mpos.ne' · simp only [ENNReal.coe_ne_top, true_or, Ne, not_false_iff] -- as `f⁻¹` is well approximated by `B⁻¹`, the conclusion follows from `hδ₀` -- and our choice of `δ`. exact hδ₀ _ _ ((hf'.to_inv h1δ).mono_num h2δ.le) /-- If a differentiable function `f` is approximated by a linear map `A` on a set `s`, up to `δ`, then at almost every `x` in `s` one has `‖f' x - A‖ ≤ δ`. -/ theorem _root_.ApproximatesLinearOn.norm_fderiv_sub_le {A : E →L[ℝ] E} {δ : ℝ≥0} (hf : ApproximatesLinearOn f A s δ) (hs : MeasurableSet s) (f' : E → E →L[ℝ] E) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : ∀ᵐ x ∂μ.restrict s, ‖f' x - A‖₊ ≤ δ := by /- The conclusion will hold at the Lebesgue density points of `s` (which have full measure). At such a point `x`, for any `z` and any `ε > 0` one has for small `r` that `{x} + r • closedBall z ε` intersects `s`. At a point `y` in the intersection, `f y - f x` is close both to `f' x (r z)` (by differentiability) and to `A (r z)` (by linear approximation), so these two quantities are close, i.e., `(f' x - A) z` is small. -/ filter_upwards [Besicovitch.ae_tendsto_measure_inter_div μ s, ae_restrict_mem hs] -- start from a Lebesgue density point `x`, belonging to `s`. intro x hx xs -- consider an arbitrary vector `z`. apply ContinuousLinearMap.opNorm_le_bound _ δ.2 fun z => ?_ -- to show that `‖(f' x - A) z‖ ≤ δ ‖z‖`, it suffices to do it up to some error that vanishes -- asymptotically in terms of `ε > 0`. suffices H : ∀ ε, 0 < ε → ‖(f' x - A) z‖ ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ε by have : Tendsto (fun ε : ℝ => ((δ : ℝ) + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ε) (𝓝[>] 0) (𝓝 ((δ + 0) * (‖z‖ + 0) + ‖f' x - A‖ * 0)) := Tendsto.mono_left (Continuous.tendsto (by fun_prop) 0) nhdsWithin_le_nhds simp only [add_zero, mul_zero] at this apply le_of_tendsto_of_tendsto tendsto_const_nhds this filter_upwards [self_mem_nhdsWithin] exact H -- fix a positive `ε`. intro ε εpos -- for small enough `r`, the rescaled ball `r • closedBall z ε` intersects `s`, as `x` is a -- density point have B₁ : ∀ᶠ r in 𝓝[>] (0 : ℝ), (s ∩ ({x} + r • closedBall z ε)).Nonempty := eventually_nonempty_inter_smul_of_density_one μ s x hx _ measurableSet_closedBall (measure_closedBall_pos μ z εpos).ne' obtain ⟨ρ, ρpos, hρ⟩ : ∃ ρ > 0, ball x ρ ∩ s ⊆ {y : E | ‖f y - f x - (f' x) (y - x)‖ ≤ ε * ‖y - x‖} := mem_nhdsWithin_iff.1 ((hf' x xs).isLittleO.def εpos) -- for small enough `r`, the rescaled ball `r • closedBall z ε` is included in the set where -- `f y - f x` is well approximated by `f' x (y - x)`. have B₂ : ∀ᶠ r in 𝓝[>] (0 : ℝ), {x} + r • closedBall z ε ⊆ ball x ρ := by apply nhdsWithin_le_nhds exact eventually_singleton_add_smul_subset isBounded_closedBall (ball_mem_nhds x ρpos) -- fix a small positive `r` satisfying the above properties, as well as a corresponding `y`. obtain ⟨r, ⟨y, ⟨ys, hy⟩⟩, rρ, rpos⟩ : ∃ r : ℝ, (s ∩ ({x} + r • closedBall z ε)).Nonempty ∧ {x} + r • closedBall z ε ⊆ ball x ρ ∧ 0 < r := (B₁.and (B₂.and self_mem_nhdsWithin)).exists -- write `y = x + r a` with `a ∈ closedBall z ε`. obtain ⟨a, az, ya⟩ : ∃ a, a ∈ closedBall z ε ∧ y = x + r • a := by simp only [mem_smul_set, image_add_left, mem_preimage, singleton_add] at hy rcases hy with ⟨a, az, ha⟩ exact ⟨a, az, by simp only [ha, add_neg_cancel_left]⟩ have norm_a : ‖a‖ ≤ ‖z‖ + ε := calc ‖a‖ = ‖z + (a - z)‖ := by simp only [add_sub_cancel] _ ≤ ‖z‖ + ‖a - z‖ := norm_add_le _ _ _ ≤ ‖z‖ + ε := add_le_add_left (mem_closedBall_iff_norm.1 az) _ -- use the approximation properties to control `(f' x - A) a`, and then `(f' x - A) z` as `z` is -- close to `a`. have I : r * ‖(f' x - A) a‖ ≤ r * (δ + ε) * (‖z‖ + ε) := calc r * ‖(f' x - A) a‖ = ‖(f' x - A) (r • a)‖ := by simp only [ContinuousLinearMap.map_smul, norm_smul, Real.norm_eq_abs, abs_of_nonneg rpos.le] _ = ‖f y - f x - A (y - x) - (f y - f x - (f' x) (y - x))‖ := by congr 1 simp only [ya, add_sub_cancel_left, sub_sub_sub_cancel_left, ContinuousLinearMap.coe_sub', Pi.sub_apply, ContinuousLinearMap.map_smul, smul_sub] _ ≤ ‖f y - f x - A (y - x)‖ + ‖f y - f x - (f' x) (y - x)‖ := norm_sub_le _ _ _ ≤ δ * ‖y - x‖ + ε * ‖y - x‖ := (add_le_add (hf _ ys _ xs) (hρ ⟨rρ hy, ys⟩)) _ = r * (δ + ε) * ‖a‖ := by simp only [ya, add_sub_cancel_left, norm_smul, Real.norm_eq_abs, abs_of_nonneg rpos.le] ring _ ≤ r * (δ + ε) * (‖z‖ + ε) := by gcongr calc ‖(f' x - A) z‖ = ‖(f' x - A) a + (f' x - A) (z - a)‖ := by congr 1 simp only [ContinuousLinearMap.coe_sub', map_sub, Pi.sub_apply] abel _ ≤ ‖(f' x - A) a‖ + ‖(f' x - A) (z - a)‖ := norm_add_le _ _ _ ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ‖z - a‖ := by apply add_le_add · rw [mul_assoc] at I; exact (mul_le_mul_left rpos).1 I · apply ContinuousLinearMap.le_opNorm _ ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ε := by rw [mem_closedBall_iff_norm'] at az gcongr /-! ### Measure zero of the image, over non-measurable sets If a set has measure `0`, then its image under a differentiable map has measure zero. This doesn't require the set to be measurable. In the same way, if `f` is differentiable on a set `s` with non-invertible derivative everywhere, then `f '' s` has measure `0`, again without measurability assumptions. -/ /-- A differentiable function maps sets of measure zero to sets of measure zero. -/ theorem addHaar_image_eq_zero_of_differentiableOn_of_addHaar_eq_zero (hf : DifferentiableOn ℝ f s) (hs : μ s = 0) : μ (f '' s) = 0 := by refine le_antisymm ?_ (zero_le _) have : ∀ A : E →L[ℝ] E, ∃ δ : ℝ≥0, 0 < δ ∧ ∀ (t : Set E), ApproximatesLinearOn f A t δ → μ (f '' t) ≤ (Real.toNNReal |A.det| + 1 : ℝ≥0) * μ t := by intro A let m : ℝ≥0 := Real.toNNReal |A.det| + 1 have I : ENNReal.ofReal |A.det| < m := by simp only [m, ENNReal.ofReal, lt_add_iff_pos_right, zero_lt_one, ENNReal.coe_lt_coe] rcases ((addHaar_image_le_mul_of_det_lt μ A I).and self_mem_nhdsWithin).exists with ⟨δ, h, h'⟩ exact ⟨δ, h', fun t ht => h t f ht⟩ choose δ hδ using this obtain ⟨t, A, _, _, t_cover, ht, -⟩ : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E), Pairwise (Disjoint on t) ∧ (∀ n : ℕ, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n : ℕ, t n) ∧ (∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) (δ (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = fderivWithin ℝ f s y) := exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s (fderivWithin ℝ f s) (fun x xs => (hf x xs).hasFDerivWithinAt) δ fun A => (hδ A).1.ne' calc μ (f '' s) ≤ μ (⋃ n, f '' (s ∩ t n)) := by apply measure_mono rw [← image_iUnion, ← inter_iUnion] exact Set.image_mono (subset_inter Subset.rfl t_cover) _ ≤ ∑' n, μ (f '' (s ∩ t n)) := measure_iUnion_le _ _ ≤ ∑' n, (Real.toNNReal |(A n).det| + 1 : ℝ≥0) * μ (s ∩ t n) := by apply ENNReal.tsum_le_tsum fun n => ?_ apply (hδ (A n)).2 exact ht n _ ≤ ∑' n, ((Real.toNNReal |(A n).det| + 1 : ℝ≥0) : ℝ≥0∞) * 0 := by refine ENNReal.tsum_le_tsum fun n => mul_le_mul_left' ?_ _ exact le_trans (measure_mono inter_subset_left) (le_of_eq hs) _ = 0 := by simp only [tsum_zero, mul_zero] /-- A version of **Sard's lemma** in fixed dimension: given a differentiable function from `E` to `E` and a set where the differential is not invertible, then the image of this set has zero measure. Here, we give an auxiliary statement towards this result. -/ theorem addHaar_image_eq_zero_of_det_fderivWithin_eq_zero_aux (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (R : ℝ) (hs : s ⊆ closedBall 0 R) (ε : ℝ≥0) (εpos : 0 < ε) (h'f' : ∀ x ∈ s, (f' x).det = 0) : μ (f '' s) ≤ ε * μ (closedBall 0 R) := by rcases eq_empty_or_nonempty s with (rfl | h's); · simp only [measure_empty, zero_le, image_empty] have : ∀ A : E →L[ℝ] E, ∃ δ : ℝ≥0, 0 < δ ∧ ∀ (t : Set E), ApproximatesLinearOn f A t δ → μ (f '' t) ≤ (Real.toNNReal |A.det| + ε : ℝ≥0) * μ t := by intro A let m : ℝ≥0 := Real.toNNReal |A.det| + ε have I : ENNReal.ofReal |A.det| < m := by simp only [m, ENNReal.ofReal, lt_add_iff_pos_right, εpos, ENNReal.coe_lt_coe] rcases ((addHaar_image_le_mul_of_det_lt μ A I).and self_mem_nhdsWithin).exists with ⟨δ, h, h'⟩ exact ⟨δ, h', fun t ht => h t f ht⟩ choose δ hδ using this obtain ⟨t, A, t_disj, t_meas, t_cover, ht, Af'⟩ : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E), Pairwise (Disjoint on t) ∧ (∀ n : ℕ, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n : ℕ, t n) ∧ (∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) (δ (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' δ fun A => (hδ A).1.ne' calc μ (f '' s) ≤ μ (⋃ n, f '' (s ∩ t n)) := by rw [← image_iUnion, ← inter_iUnion] gcongr exact subset_inter Subset.rfl t_cover _ ≤ ∑' n, μ (f '' (s ∩ t n)) := measure_iUnion_le _ _ ≤ ∑' n, (Real.toNNReal |(A n).det| + ε : ℝ≥0) * μ (s ∩ t n) := by gcongr exact (hδ (A _)).2 _ (ht _) _ = ∑' n, ε * μ (s ∩ t n) := by congr with n rcases Af' h's n with ⟨y, ys, hy⟩ simp only [hy, h'f' y ys, Real.toNNReal_zero, abs_zero, zero_add] _ ≤ ε * ∑' n, μ (closedBall 0 R ∩ t n) := by rw [ENNReal.tsum_mul_left] gcongr _ = ε * μ (⋃ n, closedBall 0 R ∩ t n) := by rw [measure_iUnion] · exact pairwise_disjoint_mono t_disj fun n => inter_subset_right · intro n exact measurableSet_closedBall.inter (t_meas n) _ ≤ ε * μ (closedBall 0 R) := by rw [← inter_iUnion] exact mul_le_mul_left' (measure_mono inter_subset_left) _ /-- A version of Sard lemma in fixed dimension: given a differentiable function from `E` to `E` and a set where the differential is not invertible, then the image of this set has zero measure. -/ theorem addHaar_image_eq_zero_of_det_fderivWithin_eq_zero (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (h'f' : ∀ x ∈ s, (f' x).det = 0) : μ (f '' s) = 0 := by suffices H : ∀ R, μ (f '' (s ∩ closedBall 0 R)) = 0 by apply le_antisymm _ (zero_le _) rw [← iUnion_inter_closedBall_nat s 0] calc μ (f '' ⋃ n : ℕ, s ∩ closedBall 0 n) ≤ ∑' n : ℕ, μ (f '' (s ∩ closedBall 0 n)) := by rw [image_iUnion]; exact measure_iUnion_le _ _ ≤ 0 := by simp only [H, tsum_zero, nonpos_iff_eq_zero] intro R have A : ∀ (ε : ℝ≥0), 0 < ε → μ (f '' (s ∩ closedBall 0 R)) ≤ ε * μ (closedBall 0 R) := fun ε εpos => addHaar_image_eq_zero_of_det_fderivWithin_eq_zero_aux μ (fun x hx => (hf' x hx.1).mono inter_subset_left) R inter_subset_right ε εpos fun x hx => h'f' x hx.1 have B : Tendsto (fun ε : ℝ≥0 => (ε : ℝ≥0∞) * μ (closedBall 0 R)) (𝓝[>] 0) (𝓝 0) := by have : Tendsto (fun ε : ℝ≥0 => (ε : ℝ≥0∞) * μ (closedBall 0 R)) (𝓝 0) (𝓝 (((0 : ℝ≥0) : ℝ≥0∞) * μ (closedBall 0 R))) := ENNReal.Tendsto.mul_const (ENNReal.tendsto_coe.2 tendsto_id) (Or.inr measure_closedBall_lt_top.ne) simp only [zero_mul, ENNReal.coe_zero] at this exact Tendsto.mono_left this nhdsWithin_le_nhds apply le_antisymm _ (zero_le _) apply ge_of_tendsto B filter_upwards [self_mem_nhdsWithin] exact A /-! ### Weak measurability statements We show that the derivative of a function on a set is almost everywhere measurable, and that the image `f '' s` is measurable if `f` is injective on `s`. The latter statement follows from the Lusin-Souslin theorem. -/ /-- The derivative of a function on a measurable set is almost everywhere measurable on this set with respect to Lebesgue measure. Note that, in general, it is not genuinely measurable there, as `f'` is not unique (but only on a set of measure `0`, as the argument shows). -/ theorem aemeasurable_fderivWithin (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : AEMeasurable f' (μ.restrict s) := by /- It suffices to show that `f'` can be uniformly approximated by a measurable function. Fix `ε > 0`. Thanks to `exists_partition_approximatesLinearOn_of_hasFDerivWithinAt`, one can find a countable measurable partition of `s` into sets `s ∩ t n` on which `f` is well approximated by linear maps `A n`. On almost all of `s ∩ t n`, it follows from `ApproximatesLinearOn.norm_fderiv_sub_le` that `f'` is uniformly approximated by `A n`, which gives the conclusion. -/ -- fix a precision `ε` refine aemeasurable_of_unif_approx fun ε εpos => ?_ let δ : ℝ≥0 := ⟨ε, le_of_lt εpos⟩ have δpos : 0 < δ := εpos -- partition `s` into sets `s ∩ t n` on which `f` is approximated by linear maps `A n`. obtain ⟨t, A, t_disj, t_meas, t_cover, ht, _⟩ : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E), Pairwise (Disjoint on t) ∧ (∀ n : ℕ, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n : ℕ, t n) ∧ (∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) δ) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' (fun _ => δ) fun _ => δpos.ne' -- define a measurable function `g` which coincides with `A n` on `t n`. obtain ⟨g, g_meas, hg⟩ : ∃ g : E → E →L[ℝ] E, Measurable g ∧ ∀ (n : ℕ) (x : E), x ∈ t n → g x = A n := exists_measurable_piecewise t t_meas (fun n _ => A n) (fun n => measurable_const) <| t_disj.mono fun i j h => by simp only [h.inter_eq, eqOn_empty] refine ⟨g, g_meas.aemeasurable, ?_⟩ -- reduce to checking that `f'` and `g` are close on almost all of `s ∩ t n`, for all `n`. suffices H : ∀ᵐ x : E ∂sum fun n ↦ μ.restrict (s ∩ t n), dist (g x) (f' x) ≤ ε by have : μ.restrict s ≤ sum fun n => μ.restrict (s ∩ t n) := by have : s = ⋃ n, s ∩ t n := by rw [← inter_iUnion] exact Subset.antisymm (subset_inter Subset.rfl t_cover) inter_subset_left conv_lhs => rw [this] exact restrict_iUnion_le exact ae_mono this H -- fix such an `n`. refine ae_sum_iff.2 fun n => ?_ -- on almost all `s ∩ t n`, `f' x` is close to `A n` thanks to -- `ApproximatesLinearOn.norm_fderiv_sub_le`. have E₁ : ∀ᵐ x : E ∂μ.restrict (s ∩ t n), ‖f' x - A n‖₊ ≤ δ := (ht n).norm_fderiv_sub_le μ (hs.inter (t_meas n)) f' fun x hx => (hf' x hx.1).mono inter_subset_left -- moreover, `g x` is equal to `A n` there. have E₂ : ∀ᵐ x : E ∂μ.restrict (s ∩ t n), g x = A n := by suffices H : ∀ᵐ x : E ∂μ.restrict (t n), g x = A n from ae_mono (restrict_mono inter_subset_right le_rfl) H filter_upwards [ae_restrict_mem (t_meas n)] exact hg n -- putting these two properties together gives the conclusion. filter_upwards [E₁, E₂] with x hx1 hx2 rw [← nndist_eq_nnnorm] at hx1 rw [hx2, dist_comm] exact hx1 theorem aemeasurable_ofReal_abs_det_fderivWithin (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : AEMeasurable (fun x => ENNReal.ofReal |(f' x).det|) (μ.restrict s) := by apply ENNReal.measurable_ofReal.comp_aemeasurable refine continuous_abs.measurable.comp_aemeasurable ?_ refine ContinuousLinearMap.continuous_det.measurable.comp_aemeasurable ?_ exact aemeasurable_fderivWithin μ hs hf' theorem aemeasurable_toNNReal_abs_det_fderivWithin (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : AEMeasurable (fun x => |(f' x).det|.toNNReal) (μ.restrict s) := by apply measurable_real_toNNReal.comp_aemeasurable refine continuous_abs.measurable.comp_aemeasurable ?_ refine ContinuousLinearMap.continuous_det.measurable.comp_aemeasurable ?_ exact aemeasurable_fderivWithin μ hs hf' /-- If a function is differentiable and injective on a measurable set, then the image is measurable. -/ theorem measurable_image_of_fderivWithin (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : MeasurableSet (f '' s) := haveI : DifferentiableOn ℝ f s := fun x hx => (hf' x hx).differentiableWithinAt hs.image_of_continuousOn_injOn (DifferentiableOn.continuousOn this) hf /-- If a function is differentiable and injective on a null measurable set, then the image is null measurable. -/ theorem nullMeasurable_image_of_fderivWithin (hs : NullMeasurableSet s μ) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : NullMeasurableSet (f '' s) μ := by rcases hs.exists_measurable_subset_ae_eq with ⟨t, ts, ht, t_eq_s⟩ have A : f '' s =ᵐ[μ] f '' t := by have : s = t ∪ (s \ t) := by simp [union_eq_self_of_subset_left ts] rw [this, image_union] refine union_ae_eq_left_of_ae_eq_empty (ae_eq_empty.mpr ?_) apply addHaar_image_eq_zero_of_differentiableOn_of_addHaar_eq_zero _ (fun x hx ↦ ?_) (ae_eq_set.1 t_eq_s).2 exact (hf' x hx.1).differentiableWithinAt.mono diff_subset apply NullMeasurableSet.congr _ A.symm apply MeasurableSet.nullMeasurableSet apply measurable_image_of_fderivWithin ht _ (hf.mono ts) (f' := f') intro x hx exact (hf' x (ts hx)).mono ts /-- If a function is differentiable and injective on a measurable set `s`, then its restriction to `s` is a measurable embedding. -/ theorem measurableEmbedding_of_fderivWithin (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : MeasurableEmbedding (s.restrict f) := haveI : DifferentiableOn ℝ f s := fun x hx => (hf' x hx).differentiableWithinAt this.continuousOn.measurableEmbedding hs hf /-! ### Proving the estimate for the measure of the image We show the formula `∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ = μ (f '' s)`, in `lintegral_abs_det_fderiv_eq_addHaar_image`. For this, we show both inequalities in both directions, first up to controlled errors and then letting these errors tend to `0`. -/ theorem addHaar_image_le_lintegral_abs_det_fderiv_aux1 (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) {ε : ℝ≥0} (εpos : 0 < ε) : μ (f '' s) ≤ (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) + 2 * ε * μ s := by /- To bound `μ (f '' s)`, we cover `s` by sets where `f` is well-approximated by linear maps `A n` (and where `f'` is almost everywhere close to `A n`), and then use that `f` expands the measure of such a set by at most `(A n).det + ε`. -/ have : ∀ A : E →L[ℝ] E, ∃ δ : ℝ≥0, 0 < δ ∧ (∀ B : E →L[ℝ] E, ‖B - A‖ ≤ δ → |B.det - A.det| ≤ ε) ∧ ∀ (t : Set E) (g : E → E), ApproximatesLinearOn g A t δ → μ (g '' t) ≤ (ENNReal.ofReal |A.det| + ε) * μ t := by intro A let m : ℝ≥0 := Real.toNNReal |A.det| + ε have I : ENNReal.ofReal |A.det| < m := by simp only [m, ENNReal.ofReal, lt_add_iff_pos_right, εpos, ENNReal.coe_lt_coe] rcases ((addHaar_image_le_mul_of_det_lt μ A I).and self_mem_nhdsWithin).exists with ⟨δ, h, δpos⟩ obtain ⟨δ', δ'pos, hδ'⟩ : ∃ (δ' : ℝ), 0 < δ' ∧ ∀ B, dist B A < δ' → dist B.det A.det < ↑ε := by refine continuousAt_iff.1 ?_ ε εpos exact ContinuousLinearMap.continuous_det.continuousAt let δ'' : ℝ≥0 := ⟨δ' / 2, (half_pos δ'pos).le⟩ refine ⟨min δ δ'', lt_min δpos (half_pos δ'pos), ?_, ?_⟩ · intro B hB rw [← Real.dist_eq] apply (hδ' B _).le rw [dist_eq_norm] calc ‖B - A‖ ≤ (min δ δ'' : ℝ≥0) := hB _ ≤ δ'' := by simp only [le_refl, NNReal.coe_min, min_le_iff, or_true] _ < δ' := half_lt_self δ'pos · intro t g htg exact h t g (htg.mono_num (min_le_left _ _)) choose δ hδ using this obtain ⟨t, A, t_disj, t_meas, t_cover, ht, -⟩ : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E), Pairwise (Disjoint on t) ∧ (∀ n : ℕ, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n : ℕ, t n) ∧ (∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) (δ (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' δ fun A => (hδ A).1.ne' calc μ (f '' s) ≤ μ (⋃ n, f '' (s ∩ t n)) := by apply measure_mono rw [← image_iUnion, ← inter_iUnion] exact Set.image_mono (subset_inter Subset.rfl t_cover) _ ≤ ∑' n, μ (f '' (s ∩ t n)) := measure_iUnion_le _ _ ≤ ∑' n, (ENNReal.ofReal |(A n).det| + ε) * μ (s ∩ t n) := by apply ENNReal.tsum_le_tsum fun n => ?_ apply (hδ (A n)).2.2 exact ht n _ = ∑' n, ∫⁻ _ in s ∩ t n, ENNReal.ofReal |(A n).det| + ε ∂μ := by simp only [lintegral_const, MeasurableSet.univ, Measure.restrict_apply, univ_inter] _ ≤ ∑' n, ∫⁻ x in s ∩ t n, ENNReal.ofReal |(f' x).det| + 2 * ε ∂μ := by apply ENNReal.tsum_le_tsum fun n => ?_ apply lintegral_mono_ae filter_upwards [(ht n).norm_fderiv_sub_le μ (hs.inter (t_meas n)) f' fun x hx => (hf' x hx.1).mono inter_subset_left] intro x hx have I : |(A n).det| ≤ |(f' x).det| + ε := calc |(A n).det| = |(f' x).det - ((f' x).det - (A n).det)| := by congr 1; abel _ ≤ |(f' x).det| + |(f' x).det - (A n).det| := abs_sub _ _ _ ≤ |(f' x).det| + ε := add_le_add le_rfl ((hδ (A n)).2.1 _ hx) calc ENNReal.ofReal |(A n).det| + ε ≤ ENNReal.ofReal (|(f' x).det| + ε) + ε := by gcongr _ = ENNReal.ofReal |(f' x).det| + 2 * ε := by simp only [ENNReal.ofReal_add, abs_nonneg, two_mul, add_assoc, NNReal.zero_le_coe, ENNReal.ofReal_coe_nnreal] _ = ∫⁻ x in ⋃ n, s ∩ t n, ENNReal.ofReal |(f' x).det| + 2 * ε ∂μ := by have M : ∀ n : ℕ, MeasurableSet (s ∩ t n) := fun n => hs.inter (t_meas n) rw [lintegral_iUnion M] exact pairwise_disjoint_mono t_disj fun n => inter_subset_right _ = ∫⁻ x in s, ENNReal.ofReal |(f' x).det| + 2 * ε ∂μ := by rw [← inter_iUnion, inter_eq_self_of_subset_left t_cover] _ = (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) + 2 * ε * μ s := by simp only [lintegral_add_right' _ aemeasurable_const, setLIntegral_const] theorem addHaar_image_le_lintegral_abs_det_fderiv_aux2 (hs : MeasurableSet s) (h's : μ s ≠ ∞) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : μ (f '' s) ≤ ∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ := by -- We just need to let the error tend to `0` in the previous lemma. have : Tendsto (fun ε : ℝ≥0 => (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) + 2 * ε * μ s) (𝓝[>] 0) (𝓝 ((∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) + 2 * (0 : ℝ≥0) * μ s)) := by apply Tendsto.mono_left _ nhdsWithin_le_nhds refine tendsto_const_nhds.add ?_ refine ENNReal.Tendsto.mul_const ?_ (Or.inr h's) exact ENNReal.Tendsto.const_mul (ENNReal.tendsto_coe.2 tendsto_id) (Or.inr ENNReal.coe_ne_top) simp only [add_zero, zero_mul, mul_zero, ENNReal.coe_zero] at this apply ge_of_tendsto this filter_upwards [self_mem_nhdsWithin] intro ε εpos rw [mem_Ioi] at εpos exact addHaar_image_le_lintegral_abs_det_fderiv_aux1 μ hs hf' εpos theorem addHaar_image_le_lintegral_abs_det_fderiv (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : μ (f '' s) ≤ ∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ := by /- We already know the result for finite-measure sets. We cover `s` by finite-measure sets using `spanningSets μ`, and apply the previous result to each of these parts. -/ let u n := disjointed (spanningSets μ) n have u_meas : ∀ n, MeasurableSet (u n) := by intro n apply MeasurableSet.disjointed fun i => ?_ exact measurableSet_spanningSets μ i have A : s = ⋃ n, s ∩ u n := by rw [← inter_iUnion, iUnion_disjointed, iUnion_spanningSets, inter_univ] calc μ (f '' s) ≤ ∑' n, μ (f '' (s ∩ u n)) := by conv_lhs => rw [A, image_iUnion] exact measure_iUnion_le _ _ ≤ ∑' n, ∫⁻ x in s ∩ u n, ENNReal.ofReal |(f' x).det| ∂μ := by apply ENNReal.tsum_le_tsum fun n => ?_ apply addHaar_image_le_lintegral_abs_det_fderiv_aux2 μ (hs.inter (u_meas n)) _ fun x hx => (hf' x hx.1).mono inter_subset_left have : μ (u n) < ∞ := lt_of_le_of_lt (measure_mono (disjointed_subset _ _)) (measure_spanningSets_lt_top μ n) exact ne_of_lt (lt_of_le_of_lt (measure_mono inter_subset_right) this) _ = ∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ := by conv_rhs => rw [A] rw [lintegral_iUnion] · intro n; exact hs.inter (u_meas n) · exact pairwise_disjoint_mono (disjoint_disjointed _) fun n => inter_subset_right theorem lintegral_abs_det_fderiv_le_addHaar_image_aux1 (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) {ε : ℝ≥0} (εpos : 0 < ε) : (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) ≤ μ (f '' s) + 2 * ε * μ s := by /- To bound `∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ`, we cover `s` by sets where `f` is well-approximated by linear maps `A n` (and where `f'` is almost everywhere close to `A n`), and then use that `f` expands the measure of such a set by at least `(A n).det - ε`. -/ have : ∀ A : E →L[ℝ] E, ∃ δ : ℝ≥0, 0 < δ ∧ (∀ B : E →L[ℝ] E, ‖B - A‖ ≤ δ → |B.det - A.det| ≤ ε) ∧ ∀ (t : Set E) (g : E → E), ApproximatesLinearOn g A t δ → ENNReal.ofReal |A.det| * μ t ≤ μ (g '' t) + ε * μ t := by intro A obtain ⟨δ', δ'pos, hδ'⟩ : ∃ (δ' : ℝ), 0 < δ' ∧ ∀ B, dist B A < δ' → dist B.det A.det < ↑ε := by refine continuousAt_iff.1 ?_ ε εpos exact ContinuousLinearMap.continuous_det.continuousAt let δ'' : ℝ≥0 := ⟨δ' / 2, (half_pos δ'pos).le⟩ have I'' : ∀ B : E →L[ℝ] E, ‖B - A‖ ≤ ↑δ'' → |B.det - A.det| ≤ ↑ε := by intro B hB rw [← Real.dist_eq] apply (hδ' B _).le rw [dist_eq_norm] exact hB.trans_lt (half_lt_self δ'pos) rcases eq_or_ne A.det 0 with (hA | hA) · refine ⟨δ'', half_pos δ'pos, I'', ?_⟩ simp only [hA, forall_const, zero_mul, ENNReal.ofReal_zero, imp_true_iff, zero_le, abs_zero] let m : ℝ≥0 := Real.toNNReal |A.det| - ε have I : (m : ℝ≥0∞) < ENNReal.ofReal |A.det| := by simp only [m, ENNReal.ofReal, ENNReal.coe_sub] apply ENNReal.sub_lt_self ENNReal.coe_ne_top · simpa only [abs_nonpos_iff, Real.toNNReal_eq_zero, ENNReal.coe_eq_zero, Ne] using hA · simp only [εpos.ne', ENNReal.coe_eq_zero, Ne, not_false_iff] rcases ((mul_le_addHaar_image_of_lt_det μ A I).and self_mem_nhdsWithin).exists with ⟨δ, h, δpos⟩ refine ⟨min δ δ'', lt_min δpos (half_pos δ'pos), ?_, ?_⟩ · intro B hB apply I'' _ (hB.trans _) simp only [le_refl, NNReal.coe_min, min_le_iff, or_true] · intro t g htg rcases eq_or_ne (μ t) ∞ with (ht | ht) · simp only [ht, εpos.ne', ENNReal.mul_top, ENNReal.coe_eq_zero, le_top, Ne, not_false_iff, _root_.add_top] have := h t g (htg.mono_num (min_le_left _ _)) rwa [ENNReal.coe_sub, ENNReal.sub_mul, tsub_le_iff_right] at this simp only [ht, imp_true_iff, Ne, not_false_iff] choose δ hδ using this obtain ⟨t, A, t_disj, t_meas, t_cover, ht, -⟩ : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E), Pairwise (Disjoint on t) ∧ (∀ n : ℕ, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n : ℕ, t n) ∧ (∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) (δ (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' δ fun A => (hδ A).1.ne' have s_eq : s = ⋃ n, s ∩ t n := by rw [← inter_iUnion] exact Subset.antisymm (subset_inter Subset.rfl t_cover) inter_subset_left calc (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) = ∑' n, ∫⁻ x in s ∩ t n, ENNReal.ofReal |(f' x).det| ∂μ := by conv_lhs => rw [s_eq] rw [lintegral_iUnion] · exact fun n => hs.inter (t_meas n) · exact pairwise_disjoint_mono t_disj fun n => inter_subset_right _ ≤ ∑' n, ∫⁻ _ in s ∩ t n, ENNReal.ofReal |(A n).det| + ε ∂μ := by apply ENNReal.tsum_le_tsum fun n => ?_ apply lintegral_mono_ae filter_upwards [(ht n).norm_fderiv_sub_le μ (hs.inter (t_meas n)) f' fun x hx => (hf' x hx.1).mono inter_subset_left] intro x hx have I : |(f' x).det| ≤ |(A n).det| + ε := calc |(f' x).det| = |(A n).det + ((f' x).det - (A n).det)| := by congr 1; abel _ ≤ |(A n).det| + |(f' x).det - (A n).det| := abs_add _ _ _ ≤ |(A n).det| + ε := add_le_add le_rfl ((hδ (A n)).2.1 _ hx) calc ENNReal.ofReal |(f' x).det| ≤ ENNReal.ofReal (|(A n).det| + ε) := ENNReal.ofReal_le_ofReal I _ = ENNReal.ofReal |(A n).det| + ε := by simp only [ENNReal.ofReal_add, abs_nonneg, NNReal.zero_le_coe, ENNReal.ofReal_coe_nnreal] _ = ∑' n, (ENNReal.ofReal |(A n).det| * μ (s ∩ t n) + ε * μ (s ∩ t n)) := by simp only [setLIntegral_const, lintegral_add_right _ measurable_const] _ ≤ ∑' n, (μ (f '' (s ∩ t n)) + ε * μ (s ∩ t n) + ε * μ (s ∩ t n)) := by gcongr exact (hδ (A _)).2.2 _ _ (ht _) _ = μ (f '' s) + 2 * ε * μ s := by conv_rhs => rw [s_eq] rw [image_iUnion, measure_iUnion]; rotate_left · intro i j hij apply Disjoint.image _ hf inter_subset_left inter_subset_left exact Disjoint.mono inter_subset_right inter_subset_right (t_disj hij) · intro i exact measurable_image_of_fderivWithin (hs.inter (t_meas i)) (fun x hx => (hf' x hx.1).mono inter_subset_left) (hf.mono inter_subset_left) rw [measure_iUnion]; rotate_left · exact pairwise_disjoint_mono t_disj fun i => inter_subset_right · exact fun i => hs.inter (t_meas i) rw [← ENNReal.tsum_mul_left, ← ENNReal.tsum_add] congr 1 ext1 i rw [mul_assoc, two_mul, add_assoc] theorem lintegral_abs_det_fderiv_le_addHaar_image_aux2 (hs : MeasurableSet s) (h's : μ s ≠ ∞) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) ≤ μ (f '' s) := by -- We just need to let the error tend to `0` in the previous lemma. have : Tendsto (fun ε : ℝ≥0 => μ (f '' s) + 2 * ε * μ s) (𝓝[>] 0) (𝓝 (μ (f '' s) + 2 * (0 : ℝ≥0) * μ s)) := by apply Tendsto.mono_left _ nhdsWithin_le_nhds refine tendsto_const_nhds.add ?_ refine ENNReal.Tendsto.mul_const ?_ (Or.inr h's) exact ENNReal.Tendsto.const_mul (ENNReal.tendsto_coe.2 tendsto_id) (Or.inr ENNReal.coe_ne_top) simp only [add_zero, zero_mul, mul_zero, ENNReal.coe_zero] at this apply ge_of_tendsto this filter_upwards [self_mem_nhdsWithin] intro ε εpos rw [mem_Ioi] at εpos exact lintegral_abs_det_fderiv_le_addHaar_image_aux1 μ hs hf' hf εpos theorem lintegral_abs_det_fderiv_le_addHaar_image (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) ≤ μ (f '' s) := by /- We already know the result for finite-measure sets. We cover `s` by finite-measure sets using `spanningSets μ`, and apply the previous result to each of these parts. -/ let u n := disjointed (spanningSets μ) n have u_meas : ∀ n, MeasurableSet (u n) := by intro n apply MeasurableSet.disjointed fun i => ?_ exact measurableSet_spanningSets μ i have A : s = ⋃ n, s ∩ u n := by rw [← inter_iUnion, iUnion_disjointed, iUnion_spanningSets, inter_univ] calc (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) = ∑' n, ∫⁻ x in s ∩ u n, ENNReal.ofReal |(f' x).det| ∂μ := by conv_lhs => rw [A] rw [lintegral_iUnion] · intro n; exact hs.inter (u_meas n) · exact pairwise_disjoint_mono (disjoint_disjointed _) fun n => inter_subset_right _ ≤ ∑' n, μ (f '' (s ∩ u n)) := by apply ENNReal.tsum_le_tsum fun n => ?_ apply lintegral_abs_det_fderiv_le_addHaar_image_aux2 μ (hs.inter (u_meas n)) _ (fun x hx => (hf' x hx.1).mono inter_subset_left) (hf.mono inter_subset_left) have : μ (u n) < ∞ := lt_of_le_of_lt (measure_mono (disjointed_subset _ _)) (measure_spanningSets_lt_top μ n) exact ne_of_lt (lt_of_le_of_lt (measure_mono inter_subset_right) this) _ = μ (f '' s) := by conv_rhs => rw [A, image_iUnion] rw [measure_iUnion] · intro i j hij apply Disjoint.image _ hf inter_subset_left inter_subset_left exact Disjoint.mono inter_subset_right inter_subset_right (disjoint_disjointed _ hij) · intro i exact measurable_image_of_fderivWithin (hs.inter (u_meas i)) (fun x hx => (hf' x hx.1).mono inter_subset_left) (hf.mono inter_subset_left) /-- Change of variable formula for differentiable functions, set version: if a function `f` is injective and differentiable on a measurable set `s`, then the measure of `f '' s` is given by the integral of `|(f' x).det|` on `s`. Note that the measurability of `f '' s` is given by `measurable_image_of_fderivWithin`. -/ theorem lintegral_abs_det_fderiv_eq_addHaar_image (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) = μ (f '' s) := le_antisymm (lintegral_abs_det_fderiv_le_addHaar_image μ hs hf' hf) (addHaar_image_le_lintegral_abs_det_fderiv μ hs hf') /-- Change of variable formula for differentiable functions, set version: if a function `f` is injective and differentiable on a null measurable set `s`, then the measure of `f '' s` is given by the integral of `|(f' x).det|` on `s`. Note that the null-measurability of `f '' s` is given by `nullMeasurable_image_of_fderivWithin`. -/ theorem lintegral_abs_det_fderiv_eq_addHaar_image₀ (hs : NullMeasurableSet s μ) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) = μ (f '' s) := by rcases hs.exists_measurable_subset_ae_eq with ⟨t, ts, ht, t_eq_s⟩ have A : μ (f '' s) = μ (f '' t) := by apply measure_congr have : s = t ∪ (s \ t) := by simp [union_eq_self_of_subset_left ts] rw [this, image_union] refine union_ae_eq_left_of_ae_eq_empty (ae_eq_empty.mpr ?_) apply addHaar_image_eq_zero_of_differentiableOn_of_addHaar_eq_zero _ (fun x hx ↦ ?_) (ae_eq_set.1 t_eq_s).2 exact (hf' x hx.1).differentiableWithinAt.mono diff_subset have B : (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) = (∫⁻ x in t, ENNReal.ofReal |(f' x).det| ∂μ) := setLIntegral_congr t_eq_s.symm rw [A, B, lintegral_abs_det_fderiv_eq_addHaar_image _ ht _ (hf.mono ts)] intro x hx exact (hf' x (ts hx)).mono ts /-- Change of variable formula for differentiable functions, set version: if a function `f` is injective and differentiable on a null measurable set `s`, then the pushforward of the measure with density `|(f' x).det|` on `s` is the Lebesgue measure on the image set. -/ theorem map_withDensity_abs_det_fderiv_eq_addHaar (hs : NullMeasurableSet s μ) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : Measure.map f ((μ.restrict s).withDensity fun x => ENNReal.ofReal |(f' x).det|) = μ.restrict (f '' s) := by have h'f : AEMeasurable f (μ.restrict s) := by apply ContinuousOn.aemeasurable₀ (fun x hx ↦ ?_) hs exact (hf' x hx).differentiableWithinAt.continuousWithinAt have h''f : AEMeasurable f ((μ.restrict s).withDensity fun x => ENNReal.ofReal |(f' x).det|) := by apply h'f.mono_ac exact withDensity_absolutelyContinuous _ _ apply Measure.ext fun t ht => ?_ have h't : NullMeasurableSet (f ⁻¹' t) (μ.restrict s) := h'f.nullMeasurableSet_preimage ht rw [map_apply_of_aemeasurable h''f ht, withDensity_apply₀ _ h't, Measure.restrict_apply ht, restrict_restrict₀ h't, lintegral_abs_det_fderiv_eq_addHaar_image₀ μ ((nullMeasurableSet_restrict hs).1 h't) (fun x hx => (hf' x hx.2).mono inter_subset_right) (hf.mono inter_subset_right), image_preimage_inter] /-- Change of variable formula for differentiable functions, set version: if a function `f` is injective and differentiable on a measurable set `s`, then the pushforward of the measure with density `|(f' x).det|` on `s` is the Lebesgue measure on the image set. This version is expressed in terms of the restricted function `s.restrict f`. For a version for the original function, see `map_withDensity_abs_det_fderiv_eq_addHaar`. -/ theorem restrict_map_withDensity_abs_det_fderiv_eq_addHaar (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : Measure.map (s.restrict f) (comap (↑) (μ.withDensity fun x => ENNReal.ofReal |(f' x).det|)) = μ.restrict (f '' s) := by obtain ⟨u, u_meas, uf⟩ : ∃ u, Measurable u ∧ EqOn u f s := by classical refine ⟨piecewise s f 0, ?_, piecewise_eqOn _ _ _⟩ refine ContinuousOn.measurable_piecewise ?_ continuous_zero.continuousOn hs have : DifferentiableOn ℝ f s := fun x hx => (hf' x hx).differentiableWithinAt exact this.continuousOn have u' : ∀ x ∈ s, HasFDerivWithinAt u (f' x) s x := fun x hx => (hf' x hx).congr (fun y hy => uf hy) (uf hx) set F : s → E := u ∘ (↑) with hF have A : Measure.map F (comap (↑) (μ.withDensity fun x => ENNReal.ofReal |(f' x).det|)) = μ.restrict (u '' s) := by rw [hF, ← Measure.map_map u_meas measurable_subtype_coe, map_comap_subtype_coe hs, restrict_withDensity hs] exact map_withDensity_abs_det_fderiv_eq_addHaar μ hs.nullMeasurableSet u' (hf.congr uf.symm) rw [uf.image_eq] at A have : F = s.restrict f := by ext x exact uf x.2 rwa [this] at A /-! ### Change of variable formulas in integrals -/ /- Change of variable formula for differentiable functions: if a function `f` is injective and differentiable on a measurable set `s`, then the Lebesgue integral of a function `g : E → ℝ≥0∞` on `f '' s` coincides with the integral of `|(f' x).det| * g ∘ f` on `s`. Note that the measurability of `f '' s` is given by `measurable_image_of_fderivWithin`. -/ theorem lintegral_image_eq_lintegral_abs_det_fderiv_mul (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) (g : E → ℝ≥0∞) : ∫⁻ x in f '' s, g x ∂μ = ∫⁻ x in s, ENNReal.ofReal |(f' x).det| * g (f x) ∂μ := by rw [← restrict_map_withDensity_abs_det_fderiv_eq_addHaar μ hs hf' hf, (measurableEmbedding_of_fderivWithin hs hf' hf).lintegral_map] simp only [Set.restrict_apply, ← Function.comp_apply (f := g)] rw [← (MeasurableEmbedding.subtype_coe hs).lintegral_map, map_comap_subtype_coe hs, setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable₀ _ _ _ hs] · simp only [Pi.mul_apply] · simp only [eventually_true, ENNReal.ofReal_lt_top] · exact aemeasurable_ofReal_abs_det_fderivWithin μ hs hf' /-- Integrability in the change of variable formula for differentiable functions: if a function `f` is injective and differentiable on a measurable set `s`, then a function `g : E → F` is integrable on `f '' s` if and only if `|(f' x).det| • g ∘ f` is integrable on `s`. -/ theorem integrableOn_image_iff_integrableOn_abs_det_fderiv_smul (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) (g : E → F) : IntegrableOn g (f '' s) μ ↔ IntegrableOn (fun x => |(f' x).det| • g (f x)) s μ := by rw [IntegrableOn, ← restrict_map_withDensity_abs_det_fderiv_eq_addHaar μ hs hf' hf, (measurableEmbedding_of_fderivWithin hs hf' hf).integrable_map_iff] simp only [Set.restrict_eq, ← Function.comp_assoc, ENNReal.ofReal] rw [← (MeasurableEmbedding.subtype_coe hs).integrable_map_iff, map_comap_subtype_coe hs, restrict_withDensity hs, integrable_withDensity_iff_integrable_coe_smul₀] · simp_rw [IntegrableOn, Real.coe_toNNReal _ (abs_nonneg _), Function.comp_apply] · exact aemeasurable_toNNReal_abs_det_fderivWithin μ hs hf' /-- Change of variable formula for differentiable functions: if a function `f` is injective and differentiable on a measurable set `s`, then the Bochner integral of a function `g : E → F` on `f '' s` coincides with the integral of `|(f' x).det| • g ∘ f` on `s`. -/ theorem integral_image_eq_integral_abs_det_fderiv_smul (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) (g : E → F) : ∫ x in f '' s, g x ∂μ = ∫ x in s, |(f' x).det| • g (f x) ∂μ := by rw [← restrict_map_withDensity_abs_det_fderiv_eq_addHaar μ hs hf' hf, (measurableEmbedding_of_fderivWithin hs hf' hf).integral_map] simp only [Set.restrict_apply, ← Function.comp_apply (f := g), ENNReal.ofReal] rw [← (MeasurableEmbedding.subtype_coe hs).integral_map, map_comap_subtype_coe hs, setIntegral_withDensity_eq_setIntegral_smul₀ (aemeasurable_toNNReal_abs_det_fderivWithin μ hs hf') _ hs] congr with x rw [NNReal.smul_def, Real.coe_toNNReal _ (abs_nonneg (f' x).det)] theorem integral_target_eq_integral_abs_det_fderiv_smul {f : PartialHomeomorph E E} (hf' : ∀ x ∈ f.source, HasFDerivAt f (f' x) x) (g : E → F) : ∫ x in f.target, g x ∂μ = ∫ x in f.source, |(f' x).det| • g (f x) ∂μ := by have : f '' f.source = f.target := PartialEquiv.image_source_eq_target f.toPartialEquiv rw [← this] apply integral_image_eq_integral_abs_det_fderiv_smul μ f.open_source.measurableSet _ f.injOn intro x hx exact (hf' x hx).hasFDerivWithinAt section withDensity lemma _root_.MeasurableEmbedding.withDensity_ofReal_comap_apply_eq_integral_abs_det_fderiv_mul (hs : MeasurableSet s) (hf : MeasurableEmbedding f) {g : E → ℝ} (hg : ∀ᵐ x ∂μ, x ∈ f '' s → 0 ≤ g x) (hg_int : IntegrableOn g (f '' s) μ) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : (μ.withDensity (fun x ↦ ENNReal.ofReal (g x))).comap f s = ENNReal.ofReal (∫ x in s, |(f' x).det| * g (f x) ∂μ) := by rw [Measure.comap_apply f hf.injective (fun t ht ↦ hf.measurableSet_image' ht) _ hs, withDensity_apply _ (hf.measurableSet_image' hs), ← ofReal_integral_eq_lintegral_ofReal hg_int ((ae_restrict_iff' (hf.measurableSet_image' hs)).mpr hg), integral_image_eq_integral_abs_det_fderiv_smul μ hs hf' hf.injective.injOn] simp_rw [smul_eq_mul] lemma _root_.MeasurableEquiv.withDensity_ofReal_map_symm_apply_eq_integral_abs_det_fderiv_mul (hs : MeasurableSet s) (f : E ≃ᵐ E) {g : E → ℝ} (hg : ∀ᵐ x ∂μ, x ∈ f '' s → 0 ≤ g x) (hg_int : IntegrableOn g (f '' s) μ) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : (μ.withDensity (fun x ↦ ENNReal.ofReal (g x))).map f.symm s = ENNReal.ofReal (∫ x in s, |(f' x).det| * g (f x) ∂μ) := by rw [MeasurableEquiv.map_symm, MeasurableEmbedding.withDensity_ofReal_comap_apply_eq_integral_abs_det_fderiv_mul μ hs f.measurableEmbedding hg hg_int hf'] end withDensity end MeasureTheory
AsSmall.lean
/- Copyright (c) 2024 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer -/ import Mathlib.CategoryTheory.Category.Cat import Mathlib.CategoryTheory.Category.ULift /-! # Functorially embedding `Cat` into the category of small categories There is a canonical functor `asSmallFunctor` between the category of categories of any size and any larger category of small categories. ## Future Work Show that `asSmallFunctor` is faithful. -/ universe w v u namespace CategoryTheory namespace Cat /-- Assigning to each category `C` the small category `AsSmall C` induces a functor `Cat ⥤ Cat`. -/ @[simps] def asSmallFunctor : Cat.{v, u} ⥤ Cat.{max w v u, max w v u} where obj C := .of <| AsSmall C map F := AsSmall.down ⋙ F ⋙ AsSmall.up end Cat end CategoryTheory
matrix.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 choice. From mathcomp Require Import fintype finfun finset fingroup perm order div. From mathcomp Require Import prime binomial ssralg countalg finalg zmodp bigop. (******************************************************************************) (* Basic concrete linear algebra : definition of type for matrices, and all *) (* basic matrix operations including determinant, trace and support for block *) (* decomposition. Matrices are represented by a row-major list of their *) (* coefficients but this implementation is hidden by three levels of wrappers *) (* (Matrix/Finfun/Tuple) so the matrix type should be treated as abstract and *) (* handled using only the operations described below: *) (* 'M[R]_(m, n) == the type of m rows by n columns matrices with *) (* 'M_(m, n) coefficients in R; the [R] is optional and is usually *) (* omitted. *) (* 'M[R]_n, 'M_n == the type of n x n square matrices. *) (* 'rV[R]_n, 'rV_n == the type of 1 x n row vectors. *) (* 'cV[R]_n, 'cV_n == the type of n x 1 column vectors. *) (* \matrix_(i < m, j < n) Expr(i, j) == *) (* the m x n matrix with general coefficient Expr(i, j), *) (* with i : 'I_m and j : 'I_n. the < m bound can be omitted *) (* if it is equal to n, though usually both bounds are *) (* omitted as they can be inferred from the context. *) (* \row_(j < n) Expr(j), \col_(i < m) Expr(i) *) (* the row / column vectors with general term Expr; the *) (* parentheses can be omitted along with the bound. *) (* \matrix_(i < m) RowExpr(i) == *) (* the m x n matrix with row i given by RowExpr(i) : 'rV_n. *) (* A i j == the coefficient of matrix A : 'M_(m, n) in column j of *) (* row i, where i : 'I_m, and j : 'I_n (via the coercion *) (* fun_of_matrix : matrix >-> Funclass). *) (* const_mx a == the constant matrix whose entries are all a (dimensions *) (* should be determined by context). *) (* map_mx f A == the pointwise image of A by f, i.e., the matrix Af *) (* congruent to A with Af i j = f (A i j) for all i and j. *) (* map2_mx f A B == the pointwise image of A and B by f, i.e., the matrix *) (* ABf congruent to A with ABf i j = f (A i j) (B i j) *) (* for all i and j. *) (* A^T == the matrix transpose of A. *) (* row i A == the i'th row of A (this is a row vector). *) (* col j A == the j'th column of A (a column vector). *) (* row' i A == A with the i'th row spliced out. *) (* col' i A == A with the j'th column spliced out. *) (* xrow i1 i2 A == A with rows i1 and i2 interchanged. *) (* xcol j1 j2 A == A with columns j1 and j2 interchanged. *) (* row_perm s A == A : 'M_(m, n) with rows permuted by s : 'S_m. *) (* col_perm s A == A : 'M_(m, n) with columns permuted by s : 'S_n. *) (* row_mx Al Ar == the row block matrix <Al Ar> obtained by concatenating *) (* two matrices Al and Ar of the same height. *) (* col_mx Au Ad == the column block matrix / Au \ (Au and Ad must have the *) (* same width). \ Ad / *) (* block_mx Aul Aur Adl Adr == the block matrix / Aul Aur \ *) (* \ Adl Adr / *) (* \mxblock_(i < m, j < n) B i j *) (* == the block matrix of type 'M_(\sum_i p_ i, \sum_j q_ j) *) (* / (B 0 0) ⋯ (B 0 j) ⋯ (B 0 n) \ *) (* | ... ... ... | *) (* | (B i 0) ⋯ (B i j) ⋯ (B i n) | *) (* | ... ... ... | *) (* \ (B m 0) ⋯ (B m j) ⋯ (B m n) / *) (* where each block (B i j) has type 'M_(p_ i, q_ j). *) (* \mxdiag_(i < n) B i == the block square matrix of type 'M_(\sum_i p_ i) *) (* / (B 0) 0 \ *) (* | ... ... | *) (* | 0 (B i) 0 | *) (* | ... ... | *) (* \ 0 (B n) / *) (* where each block (B i) has type 'M_(p_ i). *) (* \mxrow_(j < n) B j == the block matrix of type 'M_(m, \sum_j q_ j). *) (* < (B 0) ... (B n) > *) (* where each block (B j) has type 'M_(m, q_ j). *) (* \mxcol_(i < m) B i == the block matrix of type 'M_(\sum_i p_ i, n) *) (* / (B 0) \ *) (* | ... | *) (* \ (B m) / *) (* where each block (B i) has type 'M(p_ i, n). *) (* [l|r]submx A == the left/right submatrices of a row block matrix A. *) (* Note that the type of A, 'M_(m, n1 + n2) indicates how A *) (* should be decomposed. *) (* [u|d]submx A == the up/down submatrices of a column block matrix A. *) (* [u|d][l|r]submx A == the upper left, etc submatrices of a block matrix A. *) (* submxblock A i j == the block submatrix of type 'M_(p_ i, q_ j) of A. *) (* The type of A, 'M_(\sum_i p_ i, \sum_i q_ i) *) (* indicates how A should be decomposed. *) (* There is no analogous for mxdiag since one can use *) (* submxblock A i i to extract a diagonal block. *) (* submxrow A j == the submatrix of type 'M_(m, q_ j) of A. The type of A, *) (* 'M_(m, \sum_j q_ j) indicates how A should be decomposed.*) (* submxrow A j == the submatrix of type 'M_(p_ i, n) of A. The type of A, *) (* 'M_(\sum_i p_ i, n) indicates how A should be decomposed.*) (* mxsub f g A == generic reordered submatrix, given by functions f and g *) (* which specify which subset of rows and columns to take *) (* and how to reorder them, e.g. picking f and g to be *) (* increasing yields traditional submatrices. *) (* := \matrix_(i, j) A (f i) (g i) *) (* rowsub f A := mxsub f id A *) (* colsub g A := mxsub id g A *) (* castmx eq_mn A == A : 'M_(m, n) cast to 'M_(m', n') using the equation *) (* pair eq_mn : (m = m') * (n = n'). This is the usual *) (* workaround for the syntactic limitations of dependent *) (* types in Coq, and can be used to introduce a block *) (* decomposition. It simplifies to A when eq_mn is the *) (* pair (erefl m, erefl n) (using rewrite /castmx /=). *) (* conform_mx B A == A if A and B have the same dimensions, else B. *) (* mxvec A == a row vector of width m * n holding all the entries of *) (* the m x n matrix A. *) (* mxvec_index i j == the index of A i j in mxvec A. *) (* vec_mx v == the inverse of mxvec, reshaping a vector of width m * n *) (* back into into an m x n rectangular matrix. *) (* In 'M[R]_(m, n), R can be any type, but 'M[R]_(m, n) inherits the eqType, *) (* choiceType, countType, finType, nmodType, and zmodType structures from R; *) (* 'M[R]_(m, n) also forms a natural lmodType R when R is a pzRingType. *) (* Square matrices of type 'M[R]_n (resp. non-trivial square matrices of type *) (* 'M[R]_n.+1) inherit the pz(Semi)RingType (resp. nz(Semi)RingType) structure*) (* from R; indeed they then have an algebra structure (lalgType R, or algType *) (* R if R is a comNzRingType, or even unitAlgType if R is a comUnitRingType). *) (* We thus provide separate syntax for the general matrix multiplication, *) (* and other operations for matrices over a pzRingType R: *) (* A *m B == the matrix product of A and B; the width of A must be *) (* equal to the height of B. *) (* a%:M == the scalar matrix with a's on the main diagonal; in *) (* particular 1%:M denotes the identity matrix, and is *) (* equal to 1%R when n is of the form n'.+1 (e.g., n >= 1). *) (* is_scalar_mx A <=> A is a scalar matrix (A = a%:M for some A). *) (* diag_mx d == the diagonal matrix whose main diagonal is d : 'rV_n. *) (* is_diag_mx A <=> A is a diagonal matrix: forall i j, i != j -> A i j = 0 *) (* is_trig_mx A <=> A is a triangular matrix: forall i j, i < j -> A i j = 0 *) (* delta_mx i j == the matrix with a 1 in row i, column j and 0 elsewhere. *) (* pid_mx r == the partial identity matrix with 1s only on the r first *) (* coefficients of the main diagonal; the dimensions of *) (* pid_mx r are determined by the context, and pid_mx r can *) (* be rectangular. *) (* copid_mx r == the complement to 1%:M of pid_mx r: a square diagonal *) (* matrix with 1s on all but the first r coefficients on *) (* its main diagonal. *) (* perm_mx s == the n x n permutation matrix for s : 'S_n. *) (* tperm_mx i1 i2 == the permutation matrix that exchanges i1 i2 : 'I_n. *) (* is_perm_mx A == A is a permutation matrix. *) (* lift0_mx A == the 1 + n square matrix block_mx 1 0 0 A when A : 'M_n. *) (* \tr A == the trace of a square matrix A. *) (* \det A == the determinant of A, using the Leibnitz formula. *) (* cofactor i j A == the i, j cofactor of A (the signed i, j minor of A), *) (* \adj A == the adjugate matrix of A (\adj A i j = cofactor j i A). *) (* A \in unitmx == A is invertible (R must be a comUnitRingType). *) (* invmx A == the inverse matrix of A if A \in unitmx A, otherwise A. *) (* A \is a mxOver S == the matrix A has its coefficients in S. *) (* comm_mx A B := A *m B = B *m A *) (* comm_mxb A B := A *m B == B *m A *) (* all_comm_mx As fs := all2rel comm_mxb fs *) (* The following operations provide a correspondence between linear functions *) (* and matrices: *) (* lin1_mx f == the m x n matrix that emulates via right product *) (* a (linear) function f : 'rV_m -> 'rV_n on ROW VECTORS *) (* lin_mx f == the (m1 * n1) x (m2 * n2) matrix that emulates, via the *) (* right multiplication on the mxvec encodings, a linear *) (* function f : 'M_(m1, n1) -> 'M_(m2, n2) *) (* lin_mul_row u := lin1_mx (mulmx u \o vec_mx) (applies a row-encoded *) (* function to the row-vector u). *) (* mulmx A == partially applied matrix multiplication (mulmx A B is *) (* displayed as A *m B), with, for A : 'M_(m, n), a *) (* canonical {linear 'M_(n, p) -> 'M(m, p}} structure. *) (* mulmxr A == self-simplifying right-hand matrix multiplication, i.e., *) (* mulmxr A B simplifies to B *m A, with, for A : 'M_(n, p), *) (* a canonical {linear 'M_(m, n) -> 'M(m, p}} structure. *) (* lin_mulmx A := lin_mx (mulmx A). *) (* lin_mulmxr A := lin_mx (mulmxr A). *) (* We also extend any finType structure of R to 'M[R]_(m, n), and define: *) (* {'GL_n[R]} == the finGroupType of units of 'M[R]_n.-1.+1. *) (* 'GL_n[R] == the general linear group of all matrices in {'GL_n(R)}. *) (* 'GL_n(p) == 'GL_n['F_p], the general linear group of a prime field. *) (* GLval u == the coercion of u : {'GL_n(R)} to a matrix. *) (* In addition to the lemmas relevant to these definitions, this file also *) (* proves several classic results, including : *) (* - The determinant is a multilinear alternate form. *) (* - The Laplace determinant expansion formulas: expand_det_[row|col]. *) (* - The Cramer rule : mul_mx_adj & mul_adj_mx. *) (* Vandermonde m a == the 'M[R]_(m, n) Vandermonde matrix, given a : 'rV_n *) (* / 1 ... 1 \ *) (* | (a 0 0) ... (a 0 (n - 1)) | *) (* | (a 0 0 ^+ 2) ... (a 0 (n - 1) ^+ 2) | *) (* | ... ... | *) (* \ (a 0 0 ^+ (m - 1)) ... (a 0 (n - 1) ^+ (m - 1)) / *) (* := \matrix_(i < m, j < n) a 0 j ^+ i. *) (* Finally, as an example of the use of block products, we program and prove *) (* the correctness of a classical linear algebra algorithm: *) (* cormen_lup A == the triangular decomposition (L, U, P) of a nontrivial *) (* square matrix A into a lower triagular matrix L with 1s *) (* on the main diagonal, an upper matrix U, and a *) (* permutation matrix P, such that P * A = L * U. *) (* This is example only; we use a different, more precise algorithm to *) (* develop the theory of matrix ranks and row spaces in mxalgebra.v *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Import GRing.Theory. Local Open Scope ring_scope. Reserved Notation "''M_' n" (at level 0, n at level 2, format "''M_' n"). Reserved Notation "''rV_' n" (at level 0, n at level 2, format "''rV_' n"). Reserved Notation "''cV_' n" (at level 0, n at level 2, format "''cV_' n"). Reserved Notation "''M_' ( n )". (* only parsing *) Reserved Notation "''M_' ( m , n )" (format "''M_' ( m , n )"). Reserved Notation "''M[' R ]_ n" (at level 0, n at level 2). (* only parsing *) Reserved Notation "''rV[' R ]_ n" (at level 0, n at level 2). (* only parsing *) Reserved Notation "''cV[' R ]_ n" (at level 0, n at level 2). (* only parsing *) Reserved Notation "''M[' R ]_ ( n )". (* only parsing *) Reserved Notation "''M[' R ]_ ( m , n )". (* only parsing *) Reserved Notation "\matrix_ i E" (at level 34, E at level 39, i at level 2, format "\matrix_ i E"). Reserved Notation "\matrix_ ( i < n ) E" (E at level 39, i, n at level 50). (* only parsing *) Reserved Notation "\matrix_ ( i , j ) E" (E at level 39, j at level 50, format "\matrix_ ( i , j ) E"). Reserved Notation "\matrix[ k ]_ ( i , j ) E" (at level 34, E at level 39, i, j at level 50, format "\matrix[ k ]_ ( i , j ) E"). Reserved Notation "\matrix_ ( i < m , j < n ) E" (E at level 39, j, n at level 50). (* only parsing *) Reserved Notation "\matrix_ ( i , j < n ) E" (E at level 39, n at level 50). (* only parsing *) Reserved Notation "\row_ j E" (at level 34, E at level 39, j at level 2, format "\row_ j E"). Reserved Notation "\row_ ( j < n ) E" (E at level 39, j, n at level 50). (* only parsing *) Reserved Notation "\col_ j E" (at level 34, E at level 39, j at level 2, format "\col_ j E"). Reserved Notation "\col_ ( j < n ) E" (E at level 39, j, n at level 50). (* only parsing *) Reserved Notation "\mxblock_ ( i , j ) E" (at level 34, E at level 39, i, j at level 50, format "\mxblock_ ( i , j ) E"). Reserved Notation "\mxblock_ ( i < m , j < n ) E" (E at level 39, m, j, n at level 50). (* only parsing *) Reserved Notation "\mxblock_ ( i , j < n ) E" (E at level 39, n at level 50). (* only parsing *) Reserved Notation "\mxrow_ j E" (at level 34, E at level 39, j at level 2, format "\mxrow_ j E"). Reserved Notation "\mxrow_ ( j < n ) E" (E at level 39, j, n at level 50). (* only parsing *) Reserved Notation "\mxcol_ j E" (at level 34, E at level 39, j at level 2, format "\mxcol_ j E"). Reserved Notation "\mxcol_ ( j < n ) E" (E at level 39, j, n at level 50). (* only parsing *) Reserved Notation "\mxdiag_ j E" (at level 34, E at level 39, j at level 2, format "\mxdiag_ j E"). Reserved Notation "\mxdiag_ ( j < n ) E" (E at level 39, j, n at level 50). (* only parsing *) Reserved Notation "x %:M" (format "x %:M"). Reserved Notation "A *m B" (at level 40, left associativity, format "A *m B"). Reserved Notation "A ^T" (format "A ^T"). Reserved Notation "\tr A" (at level 10, A at level 8, format "\tr A"). Reserved Notation "\det A" (at level 10, A at level 8, format "\det A"). Reserved Notation "\adj A" (at level 10, A at level 8, format "\adj A"). Reserved Notation "{ ''GL_' n [ R ] }" (n at level 2, format "{ ''GL_' n [ R ] }"). Reserved Notation "{ ''GL_' n ( p ) }" (p at level 10, format "{ ''GL_' n ( p ) }"). Local Notation simp := (Monoid.Theory.simpm, oppr0). (*****************************************************************************) (****************************Type Definition**********************************) (*****************************************************************************) Section MatrixDef. Variable R : Type. Variables m n : nat. (* Basic linear algebra (matrices). *) (* We use dependent types (ordinals) for the indices so that ranges are *) (* mostly inferred automatically *) Variant matrix : predArgType := Matrix of {ffun 'I_m * 'I_n -> R}. Definition mx_val A := let: Matrix g := A in g. HB.instance Definition _ := [isNew for mx_val]. Definition fun_of_matrix A (i : 'I_m) (j : 'I_n) := mx_val A (i, j). Coercion fun_of_matrix : matrix >-> Funclass. End MatrixDef. Fact matrix_key : unit. Proof. by []. Qed. HB.lock Definition matrix_of_fun R (m n : nat) (k : unit) (F : 'I_m -> 'I_n -> R) := @Matrix R m n [ffun ij => F ij.1 ij.2]. Canonical matrix_unlockable := Unlockable matrix_of_fun.unlock. Section MatrixDef2. Variable R : Type. Variables m n : nat. Implicit Type F : 'I_m -> 'I_n -> R. Lemma mxE k F : matrix_of_fun k F =2 F. Proof. by move=> i j; rewrite unlock /fun_of_matrix /= ffunE. Qed. Lemma matrixP (A B : matrix R m n) : A =2 B <-> A = B. Proof. rewrite /fun_of_matrix; split=> [/= eqAB | -> //]. by apply/val_inj/ffunP=> [[i j]]; apply: eqAB. Qed. Lemma eq_mx k F1 F2 : (F1 =2 F2) -> matrix_of_fun k F1 = matrix_of_fun k F2. Proof. by move=> eq_F; apply/matrixP => i j; rewrite !mxE eq_F. Qed. End MatrixDef2. Arguments eq_mx {R m n k} [F1] F2 eq_F12. Bind Scope ring_scope with matrix. Notation "''M[' R ]_ ( m , n )" := (matrix R m n) (only parsing): type_scope. Notation "''rV[' R ]_ n" := 'M[R]_(1, n) (only parsing) : type_scope. Notation "''cV[' R ]_ n" := 'M[R]_(n, 1) (only parsing) : type_scope. Notation "''M[' R ]_ n" := 'M[R]_(n, n) (only parsing) : type_scope. Notation "''M[' R ]_ ( n )" := 'M[R]_n (only parsing) : type_scope. Notation "''M_' ( m , n )" := 'M[_]_(m, n) : type_scope. Notation "''rV_' n" := 'M_(1, n) : type_scope. Notation "''cV_' n" := 'M_(n, 1) : type_scope. Notation "''M_' n" := 'M_(n, n) : type_scope. Notation "''M_' ( n )" := 'M_n (only parsing) : type_scope. Notation "\matrix[ k ]_ ( i , j ) E" := (matrix_of_fun k (fun i j => E)) : ring_scope. Notation "\matrix_ ( i < m , j < n ) E" := (@matrix_of_fun _ m n matrix_key (fun i j => E)) (only parsing) : ring_scope. Notation "\matrix_ ( i , j < n ) E" := (\matrix_(i < n, j < n) E) (only parsing) : ring_scope. Notation "\matrix_ ( i , j ) E" := (\matrix_(i < _, j < _) E) : ring_scope. Notation "\matrix_ ( i < m ) E" := (\matrix_(i < m, j < _) @fun_of_matrix _ 1 _ E 0 j) (only parsing) : ring_scope. Notation "\matrix_ i E" := (\matrix_(i < _) E) : ring_scope. Notation "\col_ ( i < n ) E" := (@matrix_of_fun _ n 1 matrix_key (fun i _ => E)) (only parsing) : ring_scope. Notation "\col_ i E" := (\col_(i < _) E) : ring_scope. Notation "\row_ ( j < n ) E" := (@matrix_of_fun _ 1 n matrix_key (fun _ j => E)) (only parsing) : ring_scope. Notation "\row_ j E" := (\row_(j < _) E) : ring_scope. HB.instance Definition _ (R : eqType) m n := [Equality of 'M[R]_(m, n) by <:]. HB.instance Definition _ (R : choiceType) m n := [Choice of 'M[R]_(m, n) by <:]. HB.instance Definition _ (R : countType) m n := [Countable of 'M[R]_(m, n) by <:]. HB.instance Definition _ (R : finType) m n := [Finite of 'M[R]_(m, n) by <:]. Lemma card_mx (F : finType) m n : (#|{: 'M[F]_(m, n)}| = #|F| ^ (m * n))%N. Proof. by rewrite card_sub card_ffun card_prod !card_ord. Qed. (*****************************************************************************) (****** Matrix structural operations (transpose, permutation, blocks) ********) (*****************************************************************************) Section MatrixStructural. Variable R : Type. (* Constant matrix *) Fact const_mx_key : unit. Proof. by []. Qed. Definition const_mx m n a : 'M[R]_(m, n) := \matrix[const_mx_key]_(i, j) a. Arguments const_mx {m n}. Section FixedDim. (* Definitions and properties for which we can work with fixed dimensions. *) Variables m n : nat. Implicit Type A : 'M[R]_(m, n). (* Reshape a matrix, to accommodate the block functions for instance. *) Definition castmx m' n' (eq_mn : (m = m') * (n = n')) A : 'M_(m', n') := let: erefl in _ = m' := eq_mn.1 return 'M_(m', n') in let: erefl in _ = n' := eq_mn.2 return 'M_(m, n') in A. Definition conform_mx m' n' B A := match m =P m', n =P n' with | ReflectT eq_m, ReflectT eq_n => castmx (eq_m, eq_n) A | _, _ => B end. (* Transpose a matrix *) Fact trmx_key : unit. Proof. by []. Qed. Definition trmx A := \matrix[trmx_key]_(i, j) A j i. (* Permute a matrix vertically (rows) or horizontally (columns) *) Fact row_perm_key : unit. Proof. by []. Qed. Definition row_perm (s : 'S_m) A := \matrix[row_perm_key]_(i, j) A (s i) j. Fact col_perm_key : unit. Proof. by []. Qed. Definition col_perm (s : 'S_n) A := \matrix[col_perm_key]_(i, j) A i (s j). (* Exchange two rows/columns of a matrix *) Definition xrow i1 i2 := row_perm (tperm i1 i2). Definition xcol j1 j2 := col_perm (tperm j1 j2). (* Row/Column sub matrices of a matrix *) Definition row i0 A := \row_j A i0 j. Definition col j0 A := \col_i A i j0. (* Removing a row/column from a matrix *) Definition row' i0 A := \matrix_(i, j) A (lift i0 i) j. Definition col' j0 A := \matrix_(i, j) A i (lift j0 j). (* reindexing/subindex a matrix *) Definition mxsub m' n' f g A := \matrix_(i < m', j < n') A (f i) (g j). Local Notation colsub g := (mxsub id g). Local Notation rowsub f := (mxsub f id). Lemma castmx_const m' n' (eq_mn : (m = m') * (n = n')) a : castmx eq_mn (const_mx a) = const_mx a. Proof. by case: eq_mn; case: m' /; case: n' /. Qed. Lemma trmx_const a : trmx (const_mx a) = const_mx a. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma row_perm_const s a : row_perm s (const_mx a) = const_mx a. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma col_perm_const s a : col_perm s (const_mx a) = const_mx a. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma xrow_const i1 i2 a : xrow i1 i2 (const_mx a) = const_mx a. Proof. exact: row_perm_const. Qed. Lemma xcol_const j1 j2 a : xcol j1 j2 (const_mx a) = const_mx a. Proof. exact: col_perm_const. Qed. Lemma rowP (u v : 'rV[R]_n) : u 0 =1 v 0 <-> u = v. Proof. by split=> [eq_uv | -> //]; apply/matrixP=> i; rewrite ord1. Qed. Lemma rowK u_ i0 : row i0 (\matrix_i u_ i) = u_ i0. Proof. by apply/rowP=> i'; rewrite !mxE. Qed. Lemma row_matrixP A B : (forall i, row i A = row i B) <-> A = B. Proof. split=> [eqAB | -> //]; apply/matrixP=> i j. by move/rowP/(_ j): (eqAB i); rewrite !mxE. Qed. Lemma colP (u v : 'cV[R]_m) : u^~ 0 =1 v^~ 0 <-> u = v. Proof. by split=> [eq_uv | -> //]; apply/matrixP=> i j; rewrite ord1. Qed. Lemma row_const i0 a : row i0 (const_mx a) = const_mx a. Proof. by apply/rowP=> j; rewrite !mxE. Qed. Lemma col_const j0 a : col j0 (const_mx a) = const_mx a. Proof. by apply/colP=> i; rewrite !mxE. Qed. Lemma row'_const i0 a : row' i0 (const_mx a) = const_mx a. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma col'_const j0 a : col' j0 (const_mx a) = const_mx a. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma col_perm1 A : col_perm 1 A = A. Proof. by apply/matrixP=> i j; rewrite mxE perm1. Qed. Lemma row_perm1 A : row_perm 1 A = A. Proof. by apply/matrixP=> i j; rewrite mxE perm1. Qed. Lemma col_permM s t A : col_perm (s * t) A = col_perm s (col_perm t A). Proof. by apply/matrixP=> i j; rewrite !mxE permM. Qed. Lemma row_permM s t A : row_perm (s * t) A = row_perm s (row_perm t A). Proof. by apply/matrixP=> i j; rewrite !mxE permM. Qed. Lemma col_row_permC s t A : col_perm s (row_perm t A) = row_perm t (col_perm s A). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma rowEsub i : row i = rowsub (fun=> i). Proof. by []. Qed. Lemma colEsub j : col j = colsub (fun=> j). Proof. by []. Qed. Lemma row'Esub i : row' i = rowsub (lift i). Proof. by []. Qed. Lemma col'Esub j : col' j = colsub (lift j). Proof. by []. Qed. Lemma row_permEsub s : row_perm s = rowsub s. Proof. by rewrite /row_perm /mxsub !unlock. Qed. Lemma col_permEsub s : col_perm s = colsub s. Proof. by rewrite /col_perm /mxsub !unlock. Qed. Lemma xrowEsub i1 i2 : xrow i1 i2 = rowsub (tperm i1 i2). Proof. exact: row_permEsub. Qed. Lemma xcolEsub j1 j2 : xcol j1 j2 = colsub (tperm j1 j2). Proof. exact: col_permEsub. Qed. Lemma mxsub_id : mxsub id id =1 id. Proof. by move=> A; apply/matrixP => i j; rewrite !mxE. Qed. Lemma eq_mxsub m' n' f f' g g' : f =1 f' -> g =1 g' -> @mxsub m' n' f g =1 mxsub f' g'. Proof. by move=> eq_f eq_g A; apply/matrixP => i j; rewrite !mxE eq_f eq_g. Qed. Lemma eq_rowsub m' (f f' : 'I_m' -> 'I_m) : f =1 f' -> rowsub f =1 rowsub f'. Proof. by move=> /eq_mxsub; apply. Qed. Lemma eq_colsub n' (g g' : 'I_n' -> 'I_n) : g =1 g' -> colsub g =1 colsub g'. Proof. by move=> /eq_mxsub; apply. Qed. Lemma mxsub_eq_id f g : f =1 id -> g =1 id -> mxsub f g =1 id. Proof. by move=> fid gid A; rewrite (eq_mxsub fid gid) mxsub_id. Qed. Lemma mxsub_eq_colsub n' f g : f =1 id -> @mxsub _ n' f g =1 colsub g. Proof. by move=> f_id; apply: eq_mxsub. Qed. Lemma mxsub_eq_rowsub m' f g : g =1 id -> @mxsub m' _ f g =1 rowsub f. Proof. exact: eq_mxsub. Qed. Lemma mxsub_ffunl m' n' f g : @mxsub m' n' (finfun f) g =1 mxsub f g. Proof. by apply: eq_mxsub => // i; rewrite ffunE. Qed. Lemma mxsub_ffunr m' n' f g : @mxsub m' n' f (finfun g) =1 mxsub f g. Proof. by apply: eq_mxsub => // i; rewrite ffunE. Qed. Lemma mxsub_ffun m' n' f g : @mxsub m' n' (finfun f) (finfun g) =1 mxsub f g. Proof. by move=> A; rewrite mxsub_ffunl mxsub_ffunr. Qed. Lemma mxsub_const m' n' f g a : @mxsub m' n' f g (const_mx a) = const_mx a. Proof. by apply/matrixP => i j; rewrite !mxE. Qed. End FixedDim. Local Notation colsub g := (mxsub id g). Local Notation rowsub f := (mxsub f id). Local Notation "A ^T" := (trmx A) : ring_scope. Lemma castmx_id m n erefl_mn (A : 'M_(m, n)) : castmx erefl_mn A = A. Proof. by case: erefl_mn => e_m e_n; rewrite [e_m]eq_axiomK [e_n]eq_axiomK. Qed. Lemma castmx_comp m1 n1 m2 n2 m3 n3 (eq_m1 : m1 = m2) (eq_n1 : n1 = n2) (eq_m2 : m2 = m3) (eq_n2 : n2 = n3) A : castmx (eq_m2, eq_n2) (castmx (eq_m1, eq_n1) A) = castmx (etrans eq_m1 eq_m2, etrans eq_n1 eq_n2) A. Proof. by case: m2 / eq_m1 eq_m2; case: m3 /; case: n2 / eq_n1 eq_n2; case: n3 /. Qed. Lemma castmxK m1 n1 m2 n2 (eq_m : m1 = m2) (eq_n : n1 = n2) : cancel (castmx (eq_m, eq_n)) (castmx (esym eq_m, esym eq_n)). Proof. by case: m2 / eq_m; case: n2 / eq_n. Qed. Lemma castmxKV m1 n1 m2 n2 (eq_m : m1 = m2) (eq_n : n1 = n2) : cancel (castmx (esym eq_m, esym eq_n)) (castmx (eq_m, eq_n)). Proof. by case: m2 / eq_m; case: n2 / eq_n. Qed. (* This can be use to reverse an equation that involves a cast. *) Lemma castmx_sym m1 n1 m2 n2 (eq_m : m1 = m2) (eq_n : n1 = n2) A1 A2 : A1 = castmx (eq_m, eq_n) A2 -> A2 = castmx (esym eq_m, esym eq_n) A1. Proof. by move/(canLR (castmxK _ _)). Qed. Lemma eq_castmx m1 n1 m2 n2 (eq_mn eq_mn' : (m1 = m2) * (n1 = n2)) : castmx eq_mn =1 castmx eq_mn'. Proof. case: eq_mn eq_mn' => [em en] [em' en'] A. by apply: (canRL (castmxKV _ _)); rewrite castmx_comp castmx_id. Qed. Lemma castmxE m1 n1 m2 n2 (eq_mn : (m1 = m2) * (n1 = n2)) A i j : castmx eq_mn A i j = A (cast_ord (esym eq_mn.1) i) (cast_ord (esym eq_mn.2) j). Proof. by do [case: eq_mn; case: m2 /; case: n2 /] in A i j *; rewrite !cast_ord_id. Qed. Lemma conform_mx_id m n (B A : 'M_(m, n)) : conform_mx B A = A. Proof. by rewrite /conform_mx; do 2!case: eqP => // *; rewrite castmx_id. Qed. Lemma nonconform_mx m m' n n' (B : 'M_(m', n')) (A : 'M_(m, n)) : (m != m') || (n != n') -> conform_mx B A = B. Proof. by rewrite /conform_mx; do 2!case: eqP. Qed. Lemma conform_castmx m1 n1 m2 n2 m3 n3 (e_mn : (m2 = m3) * (n2 = n3)) (B : 'M_(m1, n1)) A : conform_mx B (castmx e_mn A) = conform_mx B A. Proof. by do [case: e_mn; case: m3 /; case: n3 /] in A *. Qed. Lemma trmxK m n : cancel (@trmx m n) (@trmx n m). Proof. by move=> A; apply/matrixP=> i j; rewrite !mxE. Qed. Lemma trmx_inj m n : injective (@trmx m n). Proof. exact: can_inj (@trmxK m n). Qed. Lemma trmx_cast m1 n1 m2 n2 (eq_mn : (m1 = m2) * (n1 = n2)) A : (castmx eq_mn A)^T = castmx (eq_mn.2, eq_mn.1) A^T. Proof. by case: eq_mn => eq_m eq_n; apply/matrixP=> i j; rewrite !(mxE, castmxE). Qed. Lemma trmx_conform m' n' m n (B : 'M_(m', n')) (A : 'M_(m, n)) : (conform_mx B A)^T = conform_mx B^T A^T. Proof. rewrite /conform_mx; do !case: eqP; rewrite ?mxE// => en em. by rewrite trmx_cast. Qed. Lemma tr_row_perm m n s (A : 'M_(m, n)) : (row_perm s A)^T = col_perm s A^T. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma tr_col_perm m n s (A : 'M_(m, n)) : (col_perm s A)^T = row_perm s A^T. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma tr_xrow m n i1 i2 (A : 'M_(m, n)) : (xrow i1 i2 A)^T = xcol i1 i2 A^T. Proof. exact: tr_row_perm. Qed. Lemma tr_xcol m n j1 j2 (A : 'M_(m, n)) : (xcol j1 j2 A)^T = xrow j1 j2 A^T. Proof. exact: tr_col_perm. Qed. Lemma row_id n i (V : 'rV_n) : row i V = V. Proof. by apply/rowP=> j; rewrite mxE [i]ord1. Qed. Lemma col_id n j (V : 'cV_n) : col j V = V. Proof. by apply/colP=> i; rewrite mxE [j]ord1. Qed. Lemma row_eq m1 m2 n i1 i2 (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) : row i1 A1 = row i2 A2 -> A1 i1 =1 A2 i2. Proof. by move/rowP=> eqA12 j; have /[!mxE] := eqA12 j. Qed. Lemma col_eq m n1 n2 j1 j2 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) : col j1 A1 = col j2 A2 -> A1^~ j1 =1 A2^~ j2. Proof. by move/colP=> eqA12 i; have /[!mxE] := eqA12 i. Qed. Lemma row'_eq m n i0 (A B : 'M_(m, n)) : row' i0 A = row' i0 B -> {in predC1 i0, A =2 B}. Proof. move=> /matrixP eqAB' i /[!inE]/[1!eq_sym]/unlift_some[i' -> _] j. by have /[!mxE] := eqAB' i' j. Qed. Lemma col'_eq m n j0 (A B : 'M_(m, n)) : col' j0 A = col' j0 B -> forall i, {in predC1 j0, A i =1 B i}. Proof. move=> /matrixP eqAB' i j /[!inE]/[1!eq_sym]/unlift_some[j' -> _]. by have /[!mxE] := eqAB' i j'. Qed. Lemma tr_row m n i0 (A : 'M_(m, n)) : (row i0 A)^T = col i0 A^T. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma tr_row' m n i0 (A : 'M_(m, n)) : (row' i0 A)^T = col' i0 A^T. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma tr_col m n j0 (A : 'M_(m, n)) : (col j0 A)^T = row j0 A^T. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma tr_col' m n j0 (A : 'M_(m, n)) : (col' j0 A)^T = row' j0 A^T. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma mxsub_comp m1 m2 m3 n1 n2 n3 (f : 'I_m2 -> 'I_m1) (f' : 'I_m3 -> 'I_m2) (g : 'I_n2 -> 'I_n1) (g' : 'I_n3 -> 'I_n2) (A : 'M_(m1, n1)) : mxsub (f \o f') (g \o g') A = mxsub f' g' (mxsub f g A). Proof. by apply/matrixP => i j; rewrite !mxE. Qed. Lemma rowsub_comp m1 m2 m3 n (f : 'I_m2 -> 'I_m1) (f' : 'I_m3 -> 'I_m2) (A : 'M_(m1, n)) : rowsub (f \o f') A = rowsub f' (rowsub f A). Proof. exact: mxsub_comp. Qed. Lemma colsub_comp m n n2 n3 (g : 'I_n2 -> 'I_n) (g' : 'I_n3 -> 'I_n2) (A : 'M_(m, n)) : colsub (g \o g') A = colsub g' (colsub g A). Proof. exact: mxsub_comp. Qed. Lemma mxsubrc m1 m2 n n2 f g (A : 'M_(m1, n)) : mxsub f g A = rowsub f (colsub g A) :> 'M_(m2, n2). Proof. exact: mxsub_comp. Qed. Lemma mxsubcr m1 m2 n n2 f g (A : 'M_(m1, n)) : mxsub f g A = colsub g (rowsub f A) :> 'M_(m2, n2). Proof. exact: mxsub_comp. Qed. Lemma rowsub_cast m1 m2 n (eq_m : m1 = m2) (A : 'M_(m2, n)) : rowsub (cast_ord eq_m) A = castmx (esym eq_m, erefl) A. Proof. by case: _ / eq_m in A *; apply: (mxsub_eq_id (cast_ord_id _)). Qed. Lemma colsub_cast m n1 n2 (eq_n : n1 = n2) (A : 'M_(m, n2)) : colsub (cast_ord eq_n) A = castmx (erefl, esym eq_n) A. Proof. by case: _ / eq_n in A *; apply: (mxsub_eq_id _ (cast_ord_id _)). Qed. Lemma mxsub_cast m1 m2 n1 n2 (eq_m : m1 = m2) (eq_n : n1 = n2) A : mxsub (cast_ord eq_m) (cast_ord eq_n) A = castmx (esym eq_m, esym eq_n) A. Proof. by rewrite mxsubrc rowsub_cast colsub_cast castmx_comp/= etrans_id. Qed. Lemma castmxEsub m1 m2 n1 n2 (eq_mn : (m1 = m2) * (n1 = n2)) A : castmx eq_mn A = mxsub (cast_ord (esym eq_mn.1)) (cast_ord (esym eq_mn.2)) A. Proof. by rewrite mxsub_cast !esymK; case: eq_mn. Qed. Lemma trmx_mxsub m1 m2 n1 n2 f g (A : 'M_(m1, n1)) : (mxsub f g A)^T = mxsub g f A^T :> 'M_(n2, m2). Proof. by apply/matrixP => i j; rewrite !mxE. Qed. Lemma row_mxsub m1 m2 n1 n2 (f : 'I_m2 -> 'I_m1) (g : 'I_n2 -> 'I_n1) (A : 'M_(m1, n1)) i : row i (mxsub f g A) = row (f i) (colsub g A). Proof. by rewrite !rowEsub -!mxsub_comp. Qed. Lemma col_mxsub m1 m2 n1 n2 (f : 'I_m2 -> 'I_m1) (g : 'I_n2 -> 'I_n1) (A : 'M_(m1, n1)) i : col i (mxsub f g A) = col (g i) (rowsub f A). Proof. by rewrite !colEsub -!mxsub_comp. Qed. Lemma row_rowsub m1 m2 n (f : 'I_m2 -> 'I_m1) (A : 'M_(m1, n)) i : row i (rowsub f A) = row (f i) A. Proof. by rewrite row_mxsub mxsub_id. Qed. Lemma col_colsub m n1 n2 (g : 'I_n2 -> 'I_n1) (A : 'M_(m, n1)) i : col i (colsub g A) = col (g i) A. Proof. by rewrite col_mxsub mxsub_id. Qed. Ltac split_mxE := apply/matrixP=> i j; do ![rewrite mxE | case: split => ?]. Section CutPaste. Variables m m1 m2 n n1 n2 : nat. (* Concatenating two matrices, in either direction. *) Fact row_mx_key : unit. Proof. by []. Qed. Definition row_mx (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) : 'M[R]_(m, n1 + n2) := \matrix[row_mx_key]_(i, j) match split j with inl j1 => A1 i j1 | inr j2 => A2 i j2 end. Fact col_mx_key : unit. Proof. by []. Qed. Definition col_mx (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) : 'M[R]_(m1 + m2, n) := \matrix[col_mx_key]_(i, j) match split i with inl i1 => A1 i1 j | inr i2 => A2 i2 j end. (* Left/Right | Up/Down submatrices of a rows | columns matrix. *) (* The shape of the (dependent) width parameters of the type of A *) (* determines which submatrix is selected. *) Fact lsubmx_key : unit. Proof. by []. Qed. Definition lsubmx (A : 'M[R]_(m, n1 + n2)) := \matrix[lsubmx_key]_(i, j) A i (lshift n2 j). Fact rsubmx_key : unit. Proof. by []. Qed. Definition rsubmx (A : 'M[R]_(m, n1 + n2)) := \matrix[rsubmx_key]_(i, j) A i (rshift n1 j). Fact usubmx_key : unit. Proof. by []. Qed. Definition usubmx (A : 'M[R]_(m1 + m2, n)) := \matrix[usubmx_key]_(i, j) A (lshift m2 i) j. Fact dsubmx_key : unit. Proof. by []. Qed. Definition dsubmx (A : 'M[R]_(m1 + m2, n)) := \matrix[dsubmx_key]_(i, j) A (rshift m1 i) j. Lemma row_mxEl A1 A2 i j : row_mx A1 A2 i (lshift n2 j) = A1 i j. Proof. by rewrite mxE (unsplitK (inl _ _)). Qed. Lemma row_mxKl A1 A2 : lsubmx (row_mx A1 A2) = A1. Proof. by apply/matrixP=> i j; rewrite mxE row_mxEl. Qed. Lemma row_mxEr A1 A2 i j : row_mx A1 A2 i (rshift n1 j) = A2 i j. Proof. by rewrite mxE (unsplitK (inr _ _)). Qed. Lemma row_mxKr A1 A2 : rsubmx (row_mx A1 A2) = A2. Proof. by apply/matrixP=> i j; rewrite mxE row_mxEr. Qed. Lemma hsubmxK A : row_mx (lsubmx A) (rsubmx A) = A. Proof. by apply/matrixP=> i j /[!mxE]; case: split_ordP => k -> /[!mxE]. Qed. Lemma col_mxEu A1 A2 i j : col_mx A1 A2 (lshift m2 i) j = A1 i j. Proof. by rewrite mxE (unsplitK (inl _ _)). Qed. Lemma col_mxKu A1 A2 : usubmx (col_mx A1 A2) = A1. Proof. by apply/matrixP=> i j; rewrite mxE col_mxEu. Qed. Lemma col_mxEd A1 A2 i j : col_mx A1 A2 (rshift m1 i) j = A2 i j. Proof. by rewrite mxE (unsplitK (inr _ _)). Qed. Lemma col_mxKd A1 A2 : dsubmx (col_mx A1 A2) = A2. Proof. by apply/matrixP=> i j; rewrite mxE col_mxEd. Qed. Lemma lsubmxEsub : lsubmx = colsub (lshift _). Proof. by rewrite /lsubmx /mxsub !unlock. Qed. Lemma rsubmxEsub : rsubmx = colsub (@rshift _ _). Proof. by rewrite /rsubmx /mxsub !unlock. Qed. Lemma usubmxEsub : usubmx = rowsub (lshift _). Proof. by rewrite /usubmx /mxsub !unlock. Qed. Lemma dsubmxEsub : dsubmx = rowsub (@rshift _ _). Proof. by rewrite /dsubmx /mxsub !unlock. Qed. Lemma eq_row_mx A1 A2 B1 B2 : row_mx A1 A2 = row_mx B1 B2 -> A1 = B1 /\ A2 = B2. Proof. move=> eqAB; move: (congr1 lsubmx eqAB) (congr1 rsubmx eqAB). by rewrite !(row_mxKl, row_mxKr). Qed. Lemma eq_col_mx A1 A2 B1 B2 : col_mx A1 A2 = col_mx B1 B2 -> A1 = B1 /\ A2 = B2. Proof. move=> eqAB; move: (congr1 usubmx eqAB) (congr1 dsubmx eqAB). by rewrite !(col_mxKu, col_mxKd). Qed. Lemma lsubmx_const (r : R) : lsubmx (const_mx r : 'M_(m, n1 + n2)) = const_mx r. Proof. by apply/matrixP => i j; rewrite !mxE. Qed. Lemma rsubmx_const (r : R) : rsubmx (const_mx r : 'M_(m, n1 + n2)) = const_mx r. Proof. by apply/matrixP => i j; rewrite !mxE. Qed. Lemma row_mx_const a : row_mx (const_mx a) (const_mx a) = const_mx a. Proof. by split_mxE. Qed. Lemma col_mx_const a : col_mx (const_mx a) (const_mx a) = const_mx a. Proof. by split_mxE. Qed. Lemma row_usubmx A i : row i (usubmx A) = row (lshift m2 i) A. Proof. by apply/rowP=> j; rewrite !mxE; congr (A _ _); apply/val_inj. Qed. Lemma row_dsubmx A i : row i (dsubmx A) = row (rshift m1 i) A. Proof. by apply/rowP=> j; rewrite !mxE; congr (A _ _); apply/val_inj. Qed. Lemma col_lsubmx A i : col i (lsubmx A) = col (lshift n2 i) A. Proof. by apply/colP=> j; rewrite !mxE; congr (A _ _); apply/val_inj. Qed. Lemma col_rsubmx A i : col i (rsubmx A) = col (rshift n1 i) A. Proof. by apply/colP=> j; rewrite !mxE; congr (A _ _); apply/val_inj. Qed. End CutPaste. Lemma row_thin_mx m n (A : 'M_(m,0)) (B : 'M_(m,n)) : row_mx A B = B. Proof. apply/matrixP=> i j; rewrite mxE; case: splitP=> [|k H]; first by case. by congr fun_of_matrix; exact: val_inj. Qed. Lemma col_flat_mx m n (A : 'M_(0,n)) (B : 'M_(m,n)) : col_mx A B = B. Proof. apply/matrixP=> i j; rewrite mxE; case: splitP => [|k H]; first by case. by congr fun_of_matrix; exact: val_inj. Qed. Lemma trmx_lsub m n1 n2 (A : 'M_(m, n1 + n2)) : (lsubmx A)^T = usubmx A^T. Proof. by split_mxE. Qed. Lemma trmx_rsub m n1 n2 (A : 'M_(m, n1 + n2)) : (rsubmx A)^T = dsubmx A^T. Proof. by split_mxE. Qed. Lemma tr_row_mx m n1 n2 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) : (row_mx A1 A2)^T = col_mx A1^T A2^T. Proof. by split_mxE. Qed. Lemma tr_col_mx m1 m2 n (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) : (col_mx A1 A2)^T = row_mx A1^T A2^T. Proof. by split_mxE. Qed. Lemma trmx_usub m1 m2 n (A : 'M_(m1 + m2, n)) : (usubmx A)^T = lsubmx A^T. Proof. by split_mxE. Qed. Lemma trmx_dsub m1 m2 n (A : 'M_(m1 + m2, n)) : (dsubmx A)^T = rsubmx A^T. Proof. by split_mxE. Qed. Lemma vsubmxK m1 m2 n (A : 'M_(m1 + m2, n)) : col_mx (usubmx A) (dsubmx A) = A. Proof. by apply: trmx_inj; rewrite tr_col_mx trmx_usub trmx_dsub hsubmxK. Qed. Lemma cast_row_mx m m' n1 n2 (eq_m : m = m') A1 A2 : castmx (eq_m, erefl _) (row_mx A1 A2) = row_mx (castmx (eq_m, erefl n1) A1) (castmx (eq_m, erefl n2) A2). Proof. by case: m' / eq_m. Qed. Lemma cast_col_mx m1 m2 n n' (eq_n : n = n') A1 A2 : castmx (erefl _, eq_n) (col_mx A1 A2) = col_mx (castmx (erefl m1, eq_n) A1) (castmx (erefl m2, eq_n) A2). Proof. by case: n' / eq_n. Qed. (* This lemma has Prenex Implicits to help RL rewriting with castmx_sym. *) Lemma row_mxA m n1 n2 n3 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) (A3 : 'M_(m, n3)) : let cast := (erefl m, esym (addnA n1 n2 n3)) in row_mx A1 (row_mx A2 A3) = castmx cast (row_mx (row_mx A1 A2) A3). Proof. apply: (canRL (castmxKV _ _)); apply/matrixP=> i j. rewrite castmxE !mxE cast_ord_id; case: splitP => j1 /= def_j. have: (j < n1 + n2) && (j < n1) by rewrite def_j lshift_subproof /=. by move: def_j; do 2![case: splitP => // ? ->; rewrite ?mxE] => /ord_inj->. case: splitP def_j => j2 ->{j} def_j /[!mxE]. have: ~~ (j2 < n1) by rewrite -leqNgt def_j leq_addr. have: j1 < n2 by rewrite -(ltn_add2l n1) -def_j. by move: def_j; do 2![case: splitP => // ? ->] => /addnI/val_inj->. have: ~~ (j1 < n2) by rewrite -leqNgt -(leq_add2l n1) -def_j leq_addr. by case: splitP def_j => // ? ->; rewrite addnA => /addnI/val_inj->. Qed. Definition row_mxAx := row_mxA. (* bypass Prenex Implicits. *) (* This lemma has Prenex Implicits to help RL rewrititng with castmx_sym. *) Lemma col_mxA m1 m2 m3 n (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) (A3 : 'M_(m3, n)) : let cast := (esym (addnA m1 m2 m3), erefl n) in col_mx A1 (col_mx A2 A3) = castmx cast (col_mx (col_mx A1 A2) A3). Proof. by apply: trmx_inj; rewrite trmx_cast !tr_col_mx -row_mxA. Qed. Definition col_mxAx := col_mxA. (* bypass Prenex Implicits. *) Lemma row_row_mx m n1 n2 i0 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) : row i0 (row_mx A1 A2) = row_mx (row i0 A1) (row i0 A2). Proof. by apply/matrixP=> i j /[!mxE]; case: (split j) => j' /[1!mxE]. Qed. Lemma col_col_mx m1 m2 n j0 (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) : col j0 (col_mx A1 A2) = col_mx (col j0 A1) (col j0 A2). Proof. by apply: trmx_inj; rewrite !(tr_col, tr_col_mx, row_row_mx). Qed. Lemma row'_row_mx m n1 n2 i0 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) : row' i0 (row_mx A1 A2) = row_mx (row' i0 A1) (row' i0 A2). Proof. by apply/matrixP=> i j /[!mxE]; case: (split j) => j' /[1!mxE]. Qed. Lemma col'_col_mx m1 m2 n j0 (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) : col' j0 (col_mx A1 A2) = col_mx (col' j0 A1) (col' j0 A2). Proof. by apply: trmx_inj; rewrite !(tr_col', tr_col_mx, row'_row_mx). Qed. Lemma colKl m n1 n2 j1 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) : col (lshift n2 j1) (row_mx A1 A2) = col j1 A1. Proof. by apply/matrixP=> i j; rewrite !(row_mxEl, mxE). Qed. Lemma colKr m n1 n2 j2 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) : col (rshift n1 j2) (row_mx A1 A2) = col j2 A2. Proof. by apply/matrixP=> i j; rewrite !(row_mxEr, mxE). Qed. Lemma rowKu m1 m2 n i1 (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) : row (lshift m2 i1) (col_mx A1 A2) = row i1 A1. Proof. by apply/matrixP=> i j; rewrite !(col_mxEu, mxE). Qed. Lemma rowKd m1 m2 n i2 (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) : row (rshift m1 i2) (col_mx A1 A2) = row i2 A2. Proof. by apply/matrixP=> i j; rewrite !(col_mxEd, mxE). Qed. Lemma col'Kl m n1 n2 j1 (A1 : 'M_(m, n1.+1)) (A2 : 'M_(m, n2)) : col' (lshift n2 j1) (row_mx A1 A2) = row_mx (col' j1 A1) A2. Proof. apply/matrixP=> i /= j; symmetry; rewrite 2!mxE; case: split_ordP => j' ->. by rewrite mxE -(row_mxEl _ A2); congr (row_mx _ _ _); apply: ord_inj. rewrite -(row_mxEr A1); congr (row_mx _ _ _); apply: ord_inj => /=. by rewrite /bump -ltnS -addSn ltn_addr. Qed. Lemma row'Ku m1 m2 n i1 (A1 : 'M_(m1.+1, n)) (A2 : 'M_(m2, n)) : row' (lshift m2 i1) (@col_mx m1.+1 m2 n A1 A2) = col_mx (row' i1 A1) A2. Proof. by apply: trmx_inj; rewrite tr_col_mx !(@tr_row' _.+1) (@tr_col_mx _.+1) col'Kl. Qed. Lemma mx'_cast m n : 'I_n -> (m + n.-1)%N = (m + n).-1. Proof. by case=> j /ltn_predK <-; rewrite addnS. Qed. Lemma col'Kr m n1 n2 j2 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) : col' (rshift n1 j2) (@row_mx m n1 n2 A1 A2) = castmx (erefl m, mx'_cast n1 j2) (row_mx A1 (col' j2 A2)). Proof. apply/matrixP=> i j; symmetry; rewrite castmxE mxE cast_ord_id. case: splitP => j' /= def_j. rewrite mxE -(row_mxEl _ A2); congr (row_mx _ _ _); apply: ord_inj. by rewrite /= def_j /bump leqNgt ltn_addr. rewrite 2!mxE -(row_mxEr A1); congr (row_mx _ _ _ _); apply: ord_inj. by rewrite /= def_j /bump leq_add2l addnCA. Qed. Lemma row'Kd m1 m2 n i2 (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) : row' (rshift m1 i2) (col_mx A1 A2) = castmx (mx'_cast m1 i2, erefl n) (col_mx A1 (row' i2 A2)). Proof. by apply: trmx_inj; rewrite trmx_cast !(tr_row', tr_col_mx) col'Kr. Qed. Section Block. Variables m1 m2 n1 n2 : nat. (* Building a block matrix from 4 matrices : *) (* up left, up right, down left and down right components *) Definition block_mx Aul Aur Adl Adr : 'M_(m1 + m2, n1 + n2) := col_mx (row_mx Aul Aur) (row_mx Adl Adr). Lemma eq_block_mx Aul Aur Adl Adr Bul Bur Bdl Bdr : block_mx Aul Aur Adl Adr = block_mx Bul Bur Bdl Bdr -> [/\ Aul = Bul, Aur = Bur, Adl = Bdl & Adr = Bdr]. Proof. by case/eq_col_mx; do 2!case/eq_row_mx=> -> ->. Qed. Lemma block_mx_const a : block_mx (const_mx a) (const_mx a) (const_mx a) (const_mx a) = const_mx a. Proof. by split_mxE. Qed. Section CutBlock. Variable A : matrix R (m1 + m2) (n1 + n2). Definition ulsubmx := lsubmx (usubmx A). Definition ursubmx := rsubmx (usubmx A). Definition dlsubmx := lsubmx (dsubmx A). Definition drsubmx := rsubmx (dsubmx A). Lemma submxK : block_mx ulsubmx ursubmx dlsubmx drsubmx = A. Proof. by rewrite /block_mx !hsubmxK vsubmxK. Qed. Lemma ulsubmxEsub : ulsubmx = mxsub (lshift _) (lshift _) A. Proof. by rewrite /ulsubmx lsubmxEsub usubmxEsub -mxsub_comp. Qed. Lemma dlsubmxEsub : dlsubmx = mxsub (@rshift _ _) (lshift _) A. Proof. by rewrite /dlsubmx lsubmxEsub dsubmxEsub -mxsub_comp. Qed. Lemma ursubmxEsub : ursubmx = mxsub (lshift _) (@rshift _ _) A. Proof. by rewrite /ursubmx rsubmxEsub usubmxEsub -mxsub_comp. Qed. Lemma drsubmxEsub : drsubmx = mxsub (@rshift _ _) (@rshift _ _) A. Proof. by rewrite /drsubmx rsubmxEsub dsubmxEsub -mxsub_comp. Qed. End CutBlock. Section CatBlock. Variables (Aul : 'M[R]_(m1, n1)) (Aur : 'M[R]_(m1, n2)). Variables (Adl : 'M[R]_(m2, n1)) (Adr : 'M[R]_(m2, n2)). Let A := block_mx Aul Aur Adl Adr. Lemma block_mxEul i j : A (lshift m2 i) (lshift n2 j) = Aul i j. Proof. by rewrite col_mxEu row_mxEl. Qed. Lemma block_mxKul : ulsubmx A = Aul. Proof. by rewrite /ulsubmx col_mxKu row_mxKl. Qed. Lemma block_mxEur i j : A (lshift m2 i) (rshift n1 j) = Aur i j. Proof. by rewrite col_mxEu row_mxEr. Qed. Lemma block_mxKur : ursubmx A = Aur. Proof. by rewrite /ursubmx col_mxKu row_mxKr. Qed. Lemma block_mxEdl i j : A (rshift m1 i) (lshift n2 j) = Adl i j. Proof. by rewrite col_mxEd row_mxEl. Qed. Lemma block_mxKdl : dlsubmx A = Adl. Proof. by rewrite /dlsubmx col_mxKd row_mxKl. Qed. Lemma block_mxEdr i j : A (rshift m1 i) (rshift n1 j) = Adr i j. Proof. by rewrite col_mxEd row_mxEr. Qed. Lemma block_mxKdr : drsubmx A = Adr. Proof. by rewrite /drsubmx col_mxKd row_mxKr. Qed. Lemma block_mxEv : A = col_mx (row_mx Aul Aur) (row_mx Adl Adr). Proof. by []. Qed. End CatBlock. End Block. Section TrCutBlock. Variables m1 m2 n1 n2 : nat. Variable A : 'M[R]_(m1 + m2, n1 + n2). Lemma trmx_ulsub : (ulsubmx A)^T = ulsubmx A^T. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma trmx_ursub : (ursubmx A)^T = dlsubmx A^T. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma trmx_dlsub : (dlsubmx A)^T = ursubmx A^T. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma trmx_drsub : (drsubmx A)^T = drsubmx A^T. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. End TrCutBlock. Section TrBlock. Variables m1 m2 n1 n2 : nat. Variables (Aul : 'M[R]_(m1, n1)) (Aur : 'M[R]_(m1, n2)). Variables (Adl : 'M[R]_(m2, n1)) (Adr : 'M[R]_(m2, n2)). Lemma tr_block_mx : (block_mx Aul Aur Adl Adr)^T = block_mx Aul^T Adl^T Aur^T Adr^T. Proof. rewrite -[_^T]submxK -trmx_ulsub -trmx_ursub -trmx_dlsub -trmx_drsub. by rewrite block_mxKul block_mxKur block_mxKdl block_mxKdr. Qed. Lemma block_mxEh : block_mx Aul Aur Adl Adr = row_mx (col_mx Aul Adl) (col_mx Aur Adr). Proof. by apply: trmx_inj; rewrite tr_block_mx tr_row_mx 2!tr_col_mx. Qed. End TrBlock. (* This lemma has Prenex Implicits to help RL rewrititng with castmx_sym. *) Lemma block_mxA m1 m2 m3 n1 n2 n3 (A11 : 'M_(m1, n1)) (A12 : 'M_(m1, n2)) (A13 : 'M_(m1, n3)) (A21 : 'M_(m2, n1)) (A22 : 'M_(m2, n2)) (A23 : 'M_(m2, n3)) (A31 : 'M_(m3, n1)) (A32 : 'M_(m3, n2)) (A33 : 'M_(m3, n3)) : let cast := (esym (addnA m1 m2 m3), esym (addnA n1 n2 n3)) in let row1 := row_mx A12 A13 in let col1 := col_mx A21 A31 in let row3 := row_mx A31 A32 in let col3 := col_mx A13 A23 in block_mx A11 row1 col1 (block_mx A22 A23 A32 A33) = castmx cast (block_mx (block_mx A11 A12 A21 A22) col3 row3 A33). Proof. rewrite /= block_mxEh !col_mxA -cast_row_mx -block_mxEv -block_mxEh. rewrite block_mxEv block_mxEh !row_mxA -cast_col_mx -block_mxEh -block_mxEv. by rewrite castmx_comp etrans_id. Qed. Definition block_mxAx := block_mxA. (* Bypass Prenex Implicits *) Section Induction. Lemma row_ind m (P : forall n, 'M[R]_(m, n) -> Type) : (forall A, P 0 A) -> (forall n c A, P n A -> P (1 + n)%N (row_mx c A)) -> forall n A, P n A. Proof. move=> P0 PS; elim=> [//|n IHn] A. by rewrite -[n.+1]/(1 + n)%N in A *; rewrite -[A]hsubmxK; apply: PS. Qed. Lemma col_ind n (P : forall m, 'M[R]_(m, n) -> Type) : (forall A, P 0 A) -> (forall m r A, P m A -> P (1 + m)%N (col_mx r A)) -> forall m A, P m A. Proof. move=> P0 PS; elim=> [//|m IHm] A. by rewrite -[m.+1]/(1 + m)%N in A *; rewrite -[A]vsubmxK; apply: PS. Qed. Lemma mx_ind (P : forall m n, 'M[R]_(m, n) -> Type) : (forall m A, P m 0 A) -> (forall n A, P 0 n A) -> (forall m n x r c A, P m n A -> P (1 + m)%N (1 + n)%N (block_mx x r c A)) -> forall m n A, P m n A. Proof. move=> P0l P0r PS; elim=> [|m IHm] [|n] A; do ?by [apply: P0l|apply: P0r]. by rewrite -[A](@submxK 1 _ 1); apply: PS. Qed. Definition matrix_rect := mx_ind. Definition matrix_rec := mx_ind. Definition matrix_ind := mx_ind. Lemma sqmx_ind (P : forall n, 'M[R]_n -> Type) : (forall A, P 0 A) -> (forall n x r c A, P n A -> P (1 + n)%N (block_mx x r c A)) -> forall n A, P n A. Proof. by move=> P0 PS; elim=> [//|n IHn] A; rewrite -[A](@submxK 1 _ 1); apply: PS. Qed. Lemma ringmx_ind (P : forall n, 'M[R]_n.+1 -> Type) : (forall x, P 0 x) -> (forall n x (r : 'rV_n.+1) (c : 'cV_n.+1) A, P n A -> P (1 + n)%N (block_mx x r c A)) -> forall n A, P n A. Proof. by move=> P0 PS; elim=> [//|n IHn] A; rewrite -[A](@submxK 1 _ 1); apply: PS. Qed. Lemma mxsub_ind (weight : forall m n, 'M[R]_(m, n) -> nat) (sub : forall m n m' n', ('I_m' -> 'I_m) -> ('I_n' -> 'I_n) -> Prop) (P : forall m n, 'M[R]_(m, n) -> Type) : (forall m n (A : 'M[R]_(m, n)), (forall m' n' f g, weight m' n' (mxsub f g A) < weight m n A -> sub m n m' n' f g -> P m' n' (mxsub f g A)) -> P m n A) -> forall m n A, P m n A. Proof. move=> Psub m n A; have [k] := ubnP (weight m n A). elim: k => [//|k IHk] in m n A *. rewrite ltnS => lt_A_k; apply: Psub => m' n' f g lt_A'_A ?. by apply: IHk; apply: leq_trans lt_A_k. Qed. End Induction. (* Bijections mxvec : 'M_(m, n) <----> 'rV_(m * n) : vec_mx *) Section VecMatrix. Variables m n : nat. Lemma mxvec_cast : #|{:'I_m * 'I_n}| = (m * n)%N. Proof. by rewrite card_prod !card_ord. Qed. Definition mxvec_index (i : 'I_m) (j : 'I_n) := cast_ord mxvec_cast (enum_rank (i, j)). Variant is_mxvec_index : 'I_(m * n) -> Type := isMxvecIndex i j : is_mxvec_index (mxvec_index i j). Lemma mxvec_indexP k : is_mxvec_index k. Proof. rewrite -[k](cast_ordK (esym mxvec_cast)) esymK. by rewrite -[_ k]enum_valK; case: (enum_val _). Qed. Coercion pair_of_mxvec_index k (i_k : is_mxvec_index k) := let: isMxvecIndex i j := i_k in (i, j). Definition mxvec (A : 'M[R]_(m, n)) := castmx (erefl _, mxvec_cast) (\row_k A (enum_val k).1 (enum_val k).2). Fact vec_mx_key : unit. Proof. by []. Qed. Definition vec_mx (u : 'rV[R]_(m * n)) := \matrix[vec_mx_key]_(i, j) u 0 (mxvec_index i j). Lemma mxvecE A i j : mxvec A 0 (mxvec_index i j) = A i j. Proof. by rewrite castmxE mxE cast_ordK enum_rankK. Qed. Lemma mxvecK : cancel mxvec vec_mx. Proof. by move=> A; apply/matrixP=> i j; rewrite mxE mxvecE. Qed. Lemma vec_mxK : cancel vec_mx mxvec. Proof. by move=> u; apply/rowP=> k; case/mxvec_indexP: k => i j; rewrite mxvecE mxE. Qed. Lemma curry_mxvec_bij : {on 'I_(m * n), bijective (uncurry mxvec_index)}. Proof. exists (enum_val \o cast_ord (esym mxvec_cast)) => [[i j] _ | k _] /=. by rewrite cast_ordK enum_rankK. by case/mxvec_indexP: k => i j /=; rewrite cast_ordK enum_rankK. Qed. End VecMatrix. End MatrixStructural. Arguments const_mx {R m n}. Arguments row_mxA {R m n1 n2 n3 A1 A2 A3}. Arguments col_mxA {R m1 m2 m3 n A1 A2 A3}. Arguments block_mxA {R m1 m2 m3 n1 n2 n3 A11 A12 A13 A21 A22 A23 A31 A32 A33}. Prenex Implicits castmx trmx trmxK lsubmx rsubmx usubmx dsubmx row_mx col_mx. Prenex Implicits block_mx ulsubmx ursubmx dlsubmx drsubmx. Prenex Implicits mxvec vec_mx mxvec_indexP mxvecK vec_mxK. Arguments trmx_inj {R m n} [A1 A2] eqA12t : rename. Notation "A ^T" := (trmx A) : ring_scope. Notation colsub g := (mxsub id g). Notation rowsub f := (mxsub f id). Arguments eq_mxsub [R m n m' n' f] f' [g] g' _. Arguments eq_rowsub [R m n m' f] f' _. Arguments eq_colsub [R m n n' g] g' _. (* Matrix parametricity. *) Section MapMatrix. Variables (aT rT : Type) (f : aT -> rT). Fact map_mx_key : unit. Proof. by []. Qed. Definition map_mx m n (A : 'M_(m, n)) := \matrix[map_mx_key]_(i, j) f (A i j). Notation "A ^f" := (map_mx A) : ring_scope. Section OneMatrix. Variables (m n : nat) (A : 'M[aT]_(m, n)). Lemma map_trmx : A^f^T = A^T^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_const_mx a : (const_mx a)^f = const_mx (f a) :> 'M_(m, n). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_row i : (row i A)^f = row i A^f. Proof. by apply/rowP=> j; rewrite !mxE. Qed. Lemma map_col j : (col j A)^f = col j A^f. Proof. by apply/colP=> i; rewrite !mxE. Qed. Lemma map_row' i0 : (row' i0 A)^f = row' i0 A^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_col' j0 : (col' j0 A)^f = col' j0 A^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_mxsub m' n' g h : (@mxsub _ _ _ m' n' g h A)^f = mxsub g h A^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_row_perm s : (row_perm s A)^f = row_perm s A^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_col_perm s : (col_perm s A)^f = col_perm s A^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_xrow i1 i2 : (xrow i1 i2 A)^f = xrow i1 i2 A^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_xcol j1 j2 : (xcol j1 j2 A)^f = xcol j1 j2 A^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_castmx m' n' c : (castmx c A)^f = castmx c A^f :> 'M_(m', n'). Proof. by apply/matrixP=> i j; rewrite !(castmxE, mxE). Qed. Lemma map_conform_mx m' n' (B : 'M_(m', n')) : (conform_mx B A)^f = conform_mx B^f A^f. Proof. move: B; have [[<- <-] B|] := eqVneq (m, n) (m', n'). by rewrite !conform_mx_id. by rewrite negb_and => neq_mn B; rewrite !nonconform_mx. Qed. Lemma map_mxvec : (mxvec A)^f = mxvec A^f. Proof. by apply/rowP=> i; rewrite !(castmxE, mxE). Qed. Lemma map_vec_mx (v : 'rV_(m * n)) : (vec_mx v)^f = vec_mx v^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. End OneMatrix. Section Block. Variables m1 m2 n1 n2 : nat. Variables (Aul : 'M[aT]_(m1, n1)) (Aur : 'M[aT]_(m1, n2)). Variables (Adl : 'M[aT]_(m2, n1)) (Adr : 'M[aT]_(m2, n2)). Variables (Bh : 'M[aT]_(m1, n1 + n2)) (Bv : 'M[aT]_(m1 + m2, n1)). Variable B : 'M[aT]_(m1 + m2, n1 + n2). Lemma map_row_mx : (row_mx Aul Aur)^f = row_mx Aul^f Aur^f. Proof. by apply/matrixP=> i j; do 2![rewrite !mxE //; case: split => ?]. Qed. Lemma map_col_mx : (col_mx Aul Adl)^f = col_mx Aul^f Adl^f. Proof. by apply/matrixP=> i j; do 2![rewrite !mxE //; case: split => ?]. Qed. Lemma map_block_mx : (block_mx Aul Aur Adl Adr)^f = block_mx Aul^f Aur^f Adl^f Adr^f. Proof. by apply/matrixP=> i j; do 3![rewrite !mxE //; case: split => ?]. Qed. Lemma map_lsubmx : (lsubmx Bh)^f = lsubmx Bh^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_rsubmx : (rsubmx Bh)^f = rsubmx Bh^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_usubmx : (usubmx Bv)^f = usubmx Bv^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_dsubmx : (dsubmx Bv)^f = dsubmx Bv^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_ulsubmx : (ulsubmx B)^f = ulsubmx B^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_ursubmx : (ursubmx B)^f = ursubmx B^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_dlsubmx : (dlsubmx B)^f = dlsubmx B^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map_drsubmx : (drsubmx B)^f = drsubmx B^f. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. End Block. End MapMatrix. Arguments map_mx {aT rT} f {m n} A. Section MultipleMapMatrix. Context {R S T : Type} {m n : nat}. Local Notation "M ^ phi" := (map_mx phi M). Lemma map_mx_comp (f : R -> S) (g : S -> T) (M : 'M_(m, n)) : M ^ (g \o f) = (M ^ f) ^ g. Proof. by apply/matrixP => i j; rewrite !mxE. Qed. Lemma eq_in_map_mx (g f : R -> S) (M : 'M_(m, n)) : (forall i j, f (M i j) = g (M i j)) -> M ^ f = M ^ g. Proof. by move=> fg; apply/matrixP => i j; rewrite !mxE. Qed. Lemma eq_map_mx (g f : R -> S) : f =1 g -> forall (M : 'M_(m, n)), M ^ f = M ^ g. Proof. by move=> eq_fg M; apply/eq_in_map_mx. Qed. Lemma map_mx_id_in (f : R -> R) (M : 'M_(m, n)) : (forall i j, f (M i j) = M i j) -> M ^ f = M. Proof. by move=> fM; apply/matrixP => i j; rewrite !mxE. Qed. Lemma map_mx_id (f : R -> R) : f =1 id -> forall M : 'M_(m, n), M ^ f = M. Proof. by move=> fid M; rewrite map_mx_id_in. Qed. End MultipleMapMatrix. Arguments eq_map_mx {R S m n} g [f]. Arguments eq_in_map_mx {R S m n} g [f M]. Arguments map_mx_id_in {R m n} [f M]. Arguments map_mx_id {R m n} [f]. (*****************************************************************************) (********************* Matrix lifted laws *******************) (*****************************************************************************) Section Map2Matrix. Context {R S T : Type} (f : R -> S -> T). Fact map2_mx_key : unit. Proof. by []. Qed. Definition map2_mx m n (A : 'M_(m, n)) (B : 'M_(m, n)) := \matrix[map2_mx_key]_(i, j) f (A i j) (B i j). Section OneMatrix. Variables (m n : nat) (A : 'M[R]_(m, n)) (B : 'M[S]_(m, n)). Lemma map2_trmx : (map2_mx A B)^T = map2_mx A^T B^T. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_const_mx a b : map2_mx (const_mx a) (const_mx b) = const_mx (f a b) :> 'M_(m, n). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_row i : map2_mx (row i A) (row i B) = row i (map2_mx A B). Proof. by apply/rowP=> j; rewrite !mxE. Qed. Lemma map2_col j : map2_mx (col j A) (col j B) = col j (map2_mx A B). Proof. by apply/colP=> i; rewrite !mxE. Qed. Lemma map2_row' i0 : map2_mx (row' i0 A) (row' i0 B) = row' i0 (map2_mx A B). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_col' j0 : map2_mx (col' j0 A) (col' j0 B) = col' j0 (map2_mx A B). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_mxsub m' n' g h : map2_mx (@mxsub _ _ _ m' n' g h A) (@mxsub _ _ _ m' n' g h B) = mxsub g h (map2_mx A B). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_row_perm s : map2_mx (row_perm s A) (row_perm s B) = row_perm s (map2_mx A B). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_col_perm s : map2_mx (col_perm s A) (col_perm s B) = col_perm s (map2_mx A B). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_xrow i1 i2 : map2_mx (xrow i1 i2 A) (xrow i1 i2 B) = xrow i1 i2 (map2_mx A B). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_xcol j1 j2 : map2_mx (xcol j1 j2 A) (xcol j1 j2 B) = xcol j1 j2 (map2_mx A B). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_castmx m' n' c : map2_mx (castmx c A) (castmx c B) = castmx c (map2_mx A B) :> 'M_(m', n'). Proof. by apply/matrixP=> i j; rewrite !(castmxE, mxE). Qed. Lemma map2_conform_mx m' n' (A' : 'M_(m', n')) (B' : 'M_(m', n')) : map2_mx (conform_mx A' A) (conform_mx B' B) = conform_mx (map2_mx A' B') (map2_mx A B). Proof. move: A' B'; have [[<- <-] A' B'|] := eqVneq (m, n) (m', n'). by rewrite !conform_mx_id. by rewrite negb_and => neq_mn A' B'; rewrite !nonconform_mx. Qed. Lemma map2_mxvec : map2_mx (mxvec A) (mxvec B) = mxvec (map2_mx A B). Proof. by apply/rowP=> i; rewrite !(castmxE, mxE). Qed. Lemma map2_vec_mx (v : 'rV_(m * n)) (w : 'rV_(m * n)) : map2_mx (vec_mx v) (vec_mx w) = vec_mx (map2_mx v w). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. End OneMatrix. Section Block. Variables m1 m2 n1 n2 : nat. Variables (Aul : 'M[R]_(m1, n1)) (Aur : 'M[R]_(m1, n2)). Variables (Adl : 'M[R]_(m2, n1)) (Adr : 'M[R]_(m2, n2)). Variables (Bh : 'M[R]_(m1, n1 + n2)) (Bv : 'M[R]_(m1 + m2, n1)). Variable B : 'M[R]_(m1 + m2, n1 + n2). Variables (A'ul : 'M[S]_(m1, n1)) (A'ur : 'M[S]_(m1, n2)). Variables (A'dl : 'M[S]_(m2, n1)) (A'dr : 'M[S]_(m2, n2)). Variables (B'h : 'M[S]_(m1, n1 + n2)) (B'v : 'M[S]_(m1 + m2, n1)). Variable B' : 'M[S]_(m1 + m2, n1 + n2). Lemma map2_row_mx : map2_mx (row_mx Aul Aur) (row_mx A'ul A'ur) = row_mx (map2_mx Aul A'ul) (map2_mx Aur A'ur). Proof. by apply/matrixP=> i j; do 2![rewrite !mxE //; case: split => ?]. Qed. Lemma map2_col_mx : map2_mx (col_mx Aul Adl) (col_mx A'ul A'dl) = col_mx (map2_mx Aul A'ul) (map2_mx Adl A'dl). Proof. by apply/matrixP=> i j; do 2![rewrite !mxE //; case: split => ?]. Qed. Lemma map2_block_mx : map2_mx (block_mx Aul Aur Adl Adr) (block_mx A'ul A'ur A'dl A'dr) = block_mx (map2_mx Aul A'ul) (map2_mx Aur A'ur) (map2_mx Adl A'dl) (map2_mx Adr A'dr). Proof. by apply/matrixP=> i j; do 3![rewrite !mxE //; case: split => ?]. Qed. Lemma map2_lsubmx : map2_mx (lsubmx Bh) (lsubmx B'h) = lsubmx (map2_mx Bh B'h). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_rsubmx : map2_mx (rsubmx Bh) (rsubmx B'h) = rsubmx (map2_mx Bh B'h). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_usubmx : map2_mx (usubmx Bv) (usubmx B'v) = usubmx (map2_mx Bv B'v). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_dsubmx : map2_mx (dsubmx Bv) (dsubmx B'v) = dsubmx (map2_mx Bv B'v). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_ulsubmx : map2_mx (ulsubmx B) (ulsubmx B') = ulsubmx (map2_mx B B'). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_ursubmx : map2_mx (ursubmx B) (ursubmx B') = ursubmx (map2_mx B B'). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_dlsubmx : map2_mx (dlsubmx B) (dlsubmx B') = dlsubmx (map2_mx B B'). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma map2_drsubmx : map2_mx (drsubmx B) (drsubmx B') = drsubmx (map2_mx B B'). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. End Block. End Map2Matrix. Section Map2Eq. Context {R S T : Type} {m n : nat}. Lemma eq_in_map2_mx (f g : R -> S -> T) (M : 'M[R]_(m, n)) (M' : 'M[S]_(m, n)) : (forall i j, f (M i j) (M' i j) = g (M i j) (M' i j)) -> map2_mx f M M' = map2_mx g M M'. Proof. by move=> fg; apply/matrixP => i j; rewrite !mxE. Qed. Lemma eq_map2_mx (f g : R -> S -> T) : f =2 g -> @map2_mx _ _ _ f m n =2 @map2_mx _ _ _ g m n. Proof. by move=> eq_fg M M'; apply/eq_in_map2_mx. Qed. Lemma map2_mx_left_in (f : R -> R -> R) (M : 'M_(m, n)) (M' : 'M_(m, n)) : (forall i j, f (M i j) (M' i j) = M i j) -> map2_mx f M M' = M. Proof. by move=> fM; apply/matrixP => i j; rewrite !mxE. Qed. Lemma map2_mx_left (f : R -> R -> R) : f =2 (fun x _ => x) -> forall (M : 'M_(m, n)) (M' : 'M_(m, n)), map2_mx f M M' = M. Proof. by move=> fl M M'; rewrite map2_mx_left_in// =>i j; rewrite fl. Qed. Lemma map2_mx_right_in (f : R -> R -> R) (M : 'M_(m, n)) (M' : 'M_(m, n)) : (forall i j, f (M i j) (M' i j) = M' i j) -> map2_mx f M M' = M'. Proof. by move=> fM; apply/matrixP => i j; rewrite !mxE. Qed. Lemma map2_mx_right (f : R -> R -> R) : f =2 (fun _ x => x) -> forall (M : 'M_(m, n)) (M' : 'M_(m, n)), map2_mx f M M' = M'. Proof. by move=> fr M M'; rewrite map2_mx_right_in// =>i j; rewrite fr. Qed. End Map2Eq. Section MatrixLaws. Context {T : Type} {m n : nat} {idm : T}. Lemma map2_mxA {opm : Monoid.law idm} : associative (@map2_mx _ _ _ opm m n). Proof. by move=> A B C; apply/matrixP=> i j; rewrite !mxE Monoid.mulmA. Qed. Lemma map2_1mx {opm : Monoid.law idm} : left_id (const_mx idm) (@map2_mx _ _ _ opm m n). Proof. by move=> A; apply/matrixP=> i j; rewrite !mxE Monoid.mul1m. Qed. Lemma map2_mx1 {opm : Monoid.law idm} : right_id (const_mx idm) (@map2_mx _ _ _ opm m n). Proof. by move=> A; apply/matrixP=> i j; rewrite !mxE Monoid.mulm1. Qed. HB.instance Definition _ {opm : Monoid.law idm} := Monoid.isLaw.Build 'M_(m, n) (const_mx idm) (@map2_mx _ _ _ opm _ _) map2_mxA map2_1mx map2_mx1. Lemma map2_mxC {opm : Monoid.com_law idm} : commutative (@map2_mx _ _ _ opm m n). Proof. by move=> A B; apply/matrixP=> i j; rewrite !mxE Monoid.mulmC. Qed. HB.instance Definition _ {opm : Monoid.com_law idm} := SemiGroup.isCommutativeLaw.Build 'M_(m, n) (@map2_mx _ _ _ opm _ _) map2_mxC. Lemma map2_0mx {opm : Monoid.mul_law idm} : left_zero (const_mx idm) (@map2_mx _ _ _ opm m n). Proof. by move=> A; apply/matrixP=> i j; rewrite !mxE Monoid.mul0m. Qed. Lemma map2_mx0 {opm : Monoid.mul_law idm} : right_zero (const_mx idm) (@map2_mx _ _ _ opm m n). Proof. by move=> A; apply/matrixP=> i j; rewrite !mxE Monoid.mulm0. Qed. HB.instance Definition _ {opm : Monoid.mul_law idm} := Monoid.isMulLaw.Build 'M_(m, n) (const_mx idm) (@map2_mx _ _ _ opm _ _) map2_0mx map2_mx0. Lemma map2_mxDl {mul : T -> T -> T} {add : Monoid.add_law idm mul} : left_distributive (@map2_mx _ _ _ mul m n) (@map2_mx _ _ _ add m n). Proof. by move=> A B C; apply/matrixP=> i j; rewrite !mxE Monoid.mulmDl. Qed. Lemma map2_mxDr {mul : T -> T -> T} {add : Monoid.add_law idm mul} : right_distributive (@map2_mx _ _ _ mul m n) (@map2_mx _ _ _ add m n). Proof. by move=> A B C; apply/matrixP=> i j; rewrite !mxE Monoid.mulmDr. Qed. HB.instance Definition _ {mul : T -> T -> T} {add : Monoid.add_law idm mul} := Monoid.isAddLaw.Build 'M_(m, n) (@map2_mx _ _ _ mul _ _) (@map2_mx _ _ _ add _ _) map2_mxDl map2_mxDr. End MatrixLaws. (*****************************************************************************) (************* Matrix Nmodule (additive abelian monoid) structure ************) (*****************************************************************************) Section MatrixNmodule. Variable V : nmodType. Section FixedDim. Variables m n : nat. Implicit Types A B : 'M[V]_(m, n). Fact addmx_key : unit. Proof. by []. Qed. Definition addmx := @map2_mx V V V +%R m n. Definition addmxA : associative addmx := map2_mxA. Definition addmxC : commutative addmx := map2_mxC. Definition add0mx : left_id (const_mx 0) addmx := map2_1mx. HB.instance Definition _ := GRing.isNmodule.Build 'M[V]_(m, n) addmxA addmxC add0mx. Lemma mulmxnE A d i j : (A *+ d) i j = A i j *+ d. Proof. by elim: d => [|d IHd]; rewrite ?mulrS mxE ?IHd. Qed. Lemma summxE I r (P : pred I) (E : I -> 'M_(m, n)) i j : (\sum_(k <- r | P k) E k) i j = \sum_(k <- r | P k) E k i j. Proof. by apply: (big_morph (fun A => A i j)) => [A B|]; rewrite mxE. Qed. Fact const_mx_is_nmod_morphism : nmod_morphism const_mx. Proof. by split=> [|a b]; apply/matrixP => // i j; rewrite !mxE. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `const_mx_is_nmod_morphism` instead")] Definition const_mx_is_semi_additive := const_mx_is_nmod_morphism. HB.instance Definition _ := GRing.isNmodMorphism.Build V 'M[V]_(m, n) const_mx const_mx_is_nmod_morphism. End FixedDim. Section SemiAdditive. Variables (m n p q : nat) (f : 'I_p -> 'I_q -> 'I_m) (g : 'I_p -> 'I_q -> 'I_n). Definition swizzle_mx k (A : 'M[V]_(m, n)) := \matrix[k]_(i, j) A (f i j) (g i j). Fact swizzle_mx_is_nmod_morphism k : nmod_morphism (swizzle_mx k). Proof. by split=> [|A B]; apply/matrixP => i j; rewrite !mxE. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `swizzle_mx_is_nmod_morphism` instead")] Definition swizzle_mx_is_semi_additive := swizzle_mx_is_nmod_morphism. HB.instance Definition _ k := GRing.isNmodMorphism.Build 'M_(m, n) 'M_(p, q) (swizzle_mx k) (swizzle_mx_is_nmod_morphism k). End SemiAdditive. Local Notation SwizzleAdd op := (GRing.Additive.copy op (swizzle_mx _ _ _)). HB.instance Definition _ m n := SwizzleAdd (@trmx V m n). HB.instance Definition _ m n i := SwizzleAdd (@row V m n i). HB.instance Definition _ m n j := SwizzleAdd (@col V m n j). HB.instance Definition _ m n i := SwizzleAdd (@row' V m n i). HB.instance Definition _ m n j := SwizzleAdd (@col' V m n j). HB.instance Definition _ m n m' n' f g := SwizzleAdd (@mxsub V m n m' n' f g). HB.instance Definition _ m n s := SwizzleAdd (@row_perm V m n s). HB.instance Definition _ m n s := SwizzleAdd (@col_perm V m n s). HB.instance Definition _ m n i1 i2 := SwizzleAdd (@xrow V m n i1 i2). HB.instance Definition _ m n j1 j2 := SwizzleAdd (@xcol V m n j1 j2). HB.instance Definition _ m n1 n2 := SwizzleAdd (@lsubmx V m n1 n2). HB.instance Definition _ m n1 n2 := SwizzleAdd (@rsubmx V m n1 n2). HB.instance Definition _ m1 m2 n := SwizzleAdd (@usubmx V m1 m2 n). HB.instance Definition _ m1 m2 n := SwizzleAdd (@dsubmx V m1 m2 n). HB.instance Definition _ m n := SwizzleAdd (@vec_mx V m n). HB.instance Definition _ m n := GRing.isNmodMorphism.Build 'M_(m, n) 'rV_(m * n) mxvec (can2_nmod_morphism (@vec_mxK V m n) mxvecK). Lemma flatmx0 n : all_equal_to (0 : 'M_(0, n)). Proof. by move=> A; apply/matrixP=> [] []. Qed. Lemma thinmx0 n : all_equal_to (0 : 'M_(n, 0)). Proof. by move=> A; apply/matrixP=> i []. Qed. Lemma trmx0 m n : (0 : 'M_(m, n))^T = 0. Proof. exact: trmx_const. Qed. Lemma row0 m n i0 : row i0 (0 : 'M_(m, n)) = 0. Proof. exact: row_const. Qed. Lemma col0 m n j0 : col j0 (0 : 'M_(m, n)) = 0. Proof. exact: col_const. Qed. Lemma mxvec_eq0 m n (A : 'M_(m, n)) : (mxvec A == 0) = (A == 0). Proof. by rewrite (can2_eq mxvecK vec_mxK) raddf0. Qed. Lemma vec_mx_eq0 m n (v : 'rV_(m * n)) : (vec_mx v == 0) = (v == 0). Proof. by rewrite (can2_eq vec_mxK mxvecK) raddf0. Qed. Lemma row_mx0 m n1 n2 : row_mx 0 0 = 0 :> 'M_(m, n1 + n2). Proof. exact: row_mx_const. Qed. Lemma col_mx0 m1 m2 n : col_mx 0 0 = 0 :> 'M_(m1 + m2, n). Proof. exact: col_mx_const. Qed. Lemma block_mx0 m1 m2 n1 n2 : block_mx 0 0 0 0 = 0 :> 'M_(m1 + m2, n1 + n2). Proof. exact: block_mx_const. Qed. Ltac split_mxE := apply/matrixP=> i j; do ![rewrite mxE | case: split => ?]. Lemma add_row_mx m n1 n2 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) B1 B2 : row_mx A1 A2 + row_mx B1 B2 = row_mx (A1 + B1) (A2 + B2). Proof. by split_mxE. Qed. Lemma add_col_mx m1 m2 n (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) B1 B2 : col_mx A1 A2 + col_mx B1 B2 = col_mx (A1 + B1) (A2 + B2). Proof. by split_mxE. Qed. Lemma add_block_mx m1 m2 n1 n2 (Aul : 'M_(m1, n1)) Aur Adl (Adr : 'M_(m2, n2)) Bul Bur Bdl Bdr : let A := block_mx Aul Aur Adl Adr in let B := block_mx Bul Bur Bdl Bdr in A + B = block_mx (Aul + Bul) (Aur + Bur) (Adl + Bdl) (Adr + Bdr). Proof. by rewrite /= add_col_mx !add_row_mx. Qed. Lemma row_mx_eq0 (m n1 n2 : nat) (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)): (row_mx A1 A2 == 0) = (A1 == 0) && (A2 == 0). Proof. apply/eqP/andP; last by case=> /eqP-> /eqP->; rewrite row_mx0. by rewrite -row_mx0 => /eq_row_mx [-> ->]. Qed. Lemma col_mx_eq0 (m1 m2 n : nat) (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)): (col_mx A1 A2 == 0) = (A1 == 0) && (A2 == 0). Proof. by rewrite -![_ == 0](inj_eq trmx_inj) !trmx0 tr_col_mx row_mx_eq0. Qed. Lemma block_mx_eq0 m1 m2 n1 n2 (Aul : 'M_(m1, n1)) Aur Adl (Adr : 'M_(m2, n2)) : (block_mx Aul Aur Adl Adr == 0) = [&& Aul == 0, Aur == 0, Adl == 0 & Adr == 0]. Proof. by rewrite col_mx_eq0 !row_mx_eq0 !andbA. Qed. Lemma trmx_eq0 m n (A : 'M_(m, n)) : (A^T == 0) = (A == 0). Proof. by rewrite -trmx0 (inj_eq trmx_inj). Qed. Lemma matrix_eq0 m n (A : 'M_(m, n)) : (A == 0) = [forall i, forall j, A i j == 0]. Proof. apply/eqP/'forall_'forall_eqP => [-> i j|A_eq0]; first by rewrite !mxE. by apply/matrixP => i j; rewrite A_eq0 !mxE. Qed. Lemma matrix0Pn m n (A : 'M_(m, n)) : reflect (exists i j, A i j != 0) (A != 0). Proof. by rewrite matrix_eq0; apply/(iffP forallPn) => -[i /forallPn]; exists i. Qed. Lemma rV0Pn n (v : 'rV_n) : reflect (exists i, v 0 i != 0) (v != 0). Proof. apply: (iffP (matrix0Pn _)) => [[i [j]]|[j]]; last by exists 0, j. by rewrite ord1; exists j. Qed. Lemma cV0Pn n (v : 'cV_n) : reflect (exists i, v i 0 != 0) (v != 0). Proof. apply: (iffP (matrix0Pn _)) => [[i] [j]|[i]]; last by exists i, 0. by rewrite ord1; exists i. Qed. Definition nz_row m n (A : 'M_(m, n)) := oapp (fun i => row i A) 0 [pick i | row i A != 0]. Lemma nz_row_eq0 m n (A : 'M_(m, n)) : (nz_row A == 0) = (A == 0). Proof. rewrite /nz_row; symmetry; case: pickP => [i /= nzAi | Ai0]. by rewrite (negPf nzAi); apply: contraTF nzAi => /eqP->; rewrite row0 eqxx. by rewrite eqxx; apply/eqP/row_matrixP=> i; move/eqP: (Ai0 i) ->; rewrite row0. Qed. Definition is_diag_mx m n (A : 'M[V]_(m, n)) := [forall i : 'I__, forall j : 'I__, (i != j :> nat) ==> (A i j == 0)]. Lemma is_diag_mxP m n (A : 'M[V]_(m, n)) : reflect (forall i j : 'I__, i != j :> nat -> A i j = 0) (is_diag_mx A). Proof. by apply: (iffP 'forall_'forall_implyP) => /(_ _ _ _)/eqP. Qed. Lemma mx0_is_diag m n : is_diag_mx (0 : 'M[V]_(m, n)). Proof. by apply/is_diag_mxP => i j _; rewrite mxE. Qed. Lemma mx11_is_diag (M : 'M_1) : is_diag_mx M. Proof. by apply/is_diag_mxP => i j; rewrite !ord1 eqxx. Qed. Definition is_trig_mx m n (A : 'M[V]_(m, n)) := [forall i : 'I__, forall j : 'I__, (i < j)%N ==> (A i j == 0)]. Lemma is_trig_mxP m n (A : 'M[V]_(m, n)) : reflect (forall i j : 'I__, (i < j)%N -> A i j = 0) (is_trig_mx A). Proof. by apply: (iffP 'forall_'forall_implyP) => /(_ _ _ _)/eqP. Qed. Lemma is_diag_mx_is_trig m n (A : 'M[V]_(m, n)) : is_diag_mx A -> is_trig_mx A. Proof. by move=> /is_diag_mxP A_eq0; apply/is_trig_mxP=> i j lt_ij; rewrite A_eq0// ltn_eqF. Qed. Lemma mx0_is_trig m n : is_trig_mx (0 : 'M[V]_(m, n)). Proof. by apply/is_trig_mxP => i j _; rewrite mxE. Qed. Lemma mx11_is_trig (M : 'M_1) : is_trig_mx M. Proof. by apply/is_trig_mxP => i j; rewrite !ord1 ltnn. Qed. Lemma is_diag_mxEtrig m n (A : 'M[V]_(m, n)) : is_diag_mx A = is_trig_mx A && is_trig_mx A^T. Proof. apply/is_diag_mxP/andP => [Adiag|[/is_trig_mxP Atrig /is_trig_mxP ATtrig]]. by split; apply/is_trig_mxP => i j lt_ij; rewrite ?mxE ?Adiag//; [rewrite ltn_eqF|rewrite gtn_eqF]. by move=> i j; case: ltngtP => // [/Atrig|/ATtrig]; rewrite ?mxE. Qed. Lemma is_diag_trmx m n (A : 'M[V]_(m, n)) : is_diag_mx A^T = is_diag_mx A. Proof. by rewrite !is_diag_mxEtrig trmxK andbC. Qed. Lemma ursubmx_trig m1 m2 n1 n2 (A : 'M[V]_(m1 + m2, n1 + n2)) : m1 <= n1 -> is_trig_mx A -> ursubmx A = 0. Proof. move=> leq_m1_n1 /is_trig_mxP Atrig; apply/matrixP => i j. by rewrite !mxE Atrig//= ltn_addr// (@leq_trans m1). Qed. Lemma dlsubmx_diag m1 m2 n1 n2 (A : 'M[V]_(m1 + m2, n1 + n2)) : n1 <= m1 -> is_diag_mx A -> dlsubmx A = 0. Proof. move=> leq_m2_n2 /is_diag_mxP Adiag; apply/matrixP => i j. by rewrite !mxE Adiag// gtn_eqF//= ltn_addr// (@leq_trans n1). Qed. Lemma ulsubmx_trig m1 m2 n1 n2 (A : 'M[V]_(m1 + m2, n1 + n2)) : is_trig_mx A -> is_trig_mx (ulsubmx A). Proof. move=> /is_trig_mxP Atrig; apply/is_trig_mxP => i j lt_ij. by rewrite !mxE Atrig. Qed. Lemma drsubmx_trig m1 m2 n1 n2 (A : 'M[V]_(m1 + m2, n1 + n2)) : m1 <= n1 -> is_trig_mx A -> is_trig_mx (drsubmx A). Proof. move=> leq_m1_n1 /is_trig_mxP Atrig; apply/is_trig_mxP => i j lt_ij. by rewrite !mxE Atrig//= -addnS leq_add. Qed. Lemma ulsubmx_diag m1 m2 n1 n2 (A : 'M[V]_(m1 + m2, n1 + n2)) : is_diag_mx A -> is_diag_mx (ulsubmx A). Proof. rewrite !is_diag_mxEtrig trmx_ulsub. by move=> /andP[/ulsubmx_trig-> /ulsubmx_trig->]. Qed. Lemma drsubmx_diag m1 m2 n1 n2 (A : 'M[V]_(m1 + m2, n1 + n2)) : m1 = n1 -> is_diag_mx A -> is_diag_mx (drsubmx A). Proof. move=> eq_m1_n1 /is_diag_mxP Adiag; apply/is_diag_mxP => i j neq_ij. by rewrite !mxE Adiag//= eq_m1_n1 eqn_add2l. Qed. Lemma is_trig_block_mx m1 m2 n1 n2 ul ur dl dr : m1 = n1 -> @is_trig_mx (m1 + m2) (n1 + n2) (block_mx ul ur dl dr) = [&& ur == 0, is_trig_mx ul & is_trig_mx dr]. Proof. move=> eq_m1_n1; rewrite {}eq_m1_n1 in ul ur dl dr *. apply/is_trig_mxP/and3P => [Atrig|]; last first. move=> [/eqP-> /is_trig_mxP ul_trig /is_trig_mxP dr_trig] i j; rewrite !mxE. do 2![case: split_ordP => ? ->; rewrite ?mxE//=] => lt_ij; rewrite ?ul_trig//. move: lt_ij; rewrite ltnNge -ltnS. by rewrite (leq_trans (ltn_ord _))// -addnS leq_addr. by rewrite dr_trig//; move: lt_ij; rewrite ltn_add2l. split. - apply/eqP/matrixP => i j; have := Atrig (lshift _ i) (rshift _ j). rewrite !mxE; case: split_ordP => k /eqP; rewrite eq_shift// ?mxE. case: split_ordP => l /eqP; rewrite eq_shift// ?mxE => /eqP-> /eqP<- <- //. by rewrite /= (leq_trans (ltn_ord _)) ?leq_addr. - apply/is_trig_mxP => i j lt_ij; have := Atrig (lshift _ i) (lshift _ j). rewrite !mxE; case: split_ordP => k /eqP; rewrite eq_shift// ?mxE. by case: split_ordP => l /eqP; rewrite eq_shift// ?mxE => /eqP<- /eqP<- ->. - apply/is_trig_mxP => i j lt_ij; have := Atrig (rshift _ i) (rshift _ j). rewrite !mxE; case: split_ordP => k /eqP; rewrite eq_shift// ?mxE. case: split_ordP => l /eqP; rewrite eq_shift// ?mxE => /eqP<- /eqP<- -> //. by rewrite /= ltn_add2l. Qed. Lemma trigmx_ind (P : forall m n, 'M_(m, n) -> Type) : (forall m, P m 0 0) -> (forall n, P 0 n 0) -> (forall m n x c A, is_trig_mx A -> P m n A -> P (1 + m)%N (1 + n)%N (block_mx x 0 c A)) -> forall m n A, is_trig_mx A -> P m n A. Proof. move=> P0l P0r PS m n A; elim: A => {m n} [m|n|m n xx r c] A PA; do ?by rewrite (flatmx0, thinmx0); by [apply: P0l|apply: P0r]. by rewrite is_trig_block_mx => // /and3P[/eqP-> _ Atrig]; apply: PS (PA _). Qed. Lemma trigsqmx_ind (P : forall n, 'M[V]_n -> Type) : (P 0 0) -> (forall n x c A, is_trig_mx A -> P n A -> P (1 + n)%N (block_mx x 0 c A)) -> forall n A, is_trig_mx A -> P n A. Proof. move=> P0 PS n A; elim/sqmx_ind: A => {n} [|n x r c] A PA. by rewrite thinmx0; apply: P0. by rewrite is_trig_block_mx => // /and3P[/eqP-> _ Atrig]; apply: PS (PA _). Qed. Lemma is_diag_block_mx m1 m2 n1 n2 ul ur dl dr : m1 = n1 -> @is_diag_mx (m1 + m2) (n1 + n2) (block_mx ul ur dl dr) = [&& ur == 0, dl == 0, is_diag_mx ul & is_diag_mx dr]. Proof. move=> eq_m1_n1. rewrite !is_diag_mxEtrig tr_block_mx !is_trig_block_mx// trmx_eq0. by rewrite andbACA -!andbA; congr [&& _, _, _ & _]; rewrite andbCA. Qed. Lemma diagmx_ind (P : forall m n, 'M_(m, n) -> Type) : (forall m, P m 0 0) -> (forall n, P 0 n 0) -> (forall m n x c A, is_diag_mx A -> P m n A -> P (1 + m)%N (1 + n)%N (block_mx x 0 c A)) -> forall m n A, is_diag_mx A -> P m n A. Proof. move=> P0l P0r PS m n A Adiag; have Atrig := is_diag_mx_is_trig Adiag. elim/trigmx_ind: Atrig Adiag => // {}m {}n r c {}A _ PA. rewrite is_diag_block_mx => // /and4P[_ /eqP-> _ Adiag]. exact: PS (PA _). Qed. Lemma diagsqmx_ind (P : forall n, 'M[V]_n -> Type) : (P 0 0) -> (forall n x c A, is_diag_mx A -> P n A -> P (1 + n)%N (block_mx x 0 c A)) -> forall n A, is_diag_mx A -> P n A. Proof. move=> P0 PS n A; elim/sqmx_ind: A => [|{}n x r c] A PA. by rewrite thinmx0; apply: P0. rewrite is_diag_block_mx => // /and4P[/eqP-> /eqP-> _ Adiag]. exact: PS (PA _). Qed. (* Diagonal matrices *) Fact diag_mx_key : unit. Proof. by []. Qed. Definition diag_mx n (d : 'rV[V]_n) := \matrix[diag_mx_key]_(i, j) (d 0 i *+ (i == j)). Lemma tr_diag_mx n (d : 'rV_n) : (diag_mx d)^T = diag_mx d. Proof. by apply/matrixP=> i j /[!mxE]; case: eqVneq => // ->. Qed. Fact diag_mx_is_nmod_morphism n : nmod_morphism (@diag_mx n). Proof. by split=> [|A B]; apply/matrixP => i j; rewrite !mxE ?mul0rn// mulrnDl. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `diag_mx_is_nmod_morphism` instead")] Definition diag_mx_is_semi_additive := diag_mx_is_nmod_morphism. HB.instance Definition _ n := GRing.isNmodMorphism.Build 'rV_n 'M_n (@diag_mx n) (@diag_mx_is_nmod_morphism n). Lemma diag_mx_row m n (l : 'rV_n) (r : 'rV_m) : diag_mx (row_mx l r) = block_mx (diag_mx l) 0 0 (diag_mx r). Proof. apply/matrixP => i j. by do ?[rewrite !mxE; case: split_ordP => ? ->]; rewrite mxE eq_shift. Qed. Lemma diag_mxP n (A : 'M[V]_n) : reflect (exists d : 'rV_n, A = diag_mx d) (is_diag_mx A). Proof. apply: (iffP (is_diag_mxP A)) => [Adiag|[d ->] i j neq_ij]; last first. by rewrite !mxE -val_eqE (negPf neq_ij). exists (\row_i A i i); apply/matrixP => i j; rewrite !mxE. by case: (altP (i =P j)) => [->|/Adiag->]. Qed. Lemma diag_mx_is_diag n (r : 'rV[V]_n) : is_diag_mx (diag_mx r). Proof. by apply/diag_mxP; exists r. Qed. Lemma diag_mx_is_trig n (r : 'rV[V]_n) : is_trig_mx (diag_mx r). Proof. exact/is_diag_mx_is_trig/diag_mx_is_diag. Qed. (* Scalar matrix : a diagonal matrix with a constant on the diagonal *) Section ScalarMx. Variable n : nat. Fact scalar_mx_key : unit. Proof. by []. Qed. Definition scalar_mx x : 'M[V]_n := \matrix[scalar_mx_key]_(i , j) (x *+ (i == j)). Notation "x %:M" := (scalar_mx x) : ring_scope. Lemma diag_const_mx a : diag_mx (const_mx a) = a%:M :> 'M_n. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma tr_scalar_mx a : (a%:M)^T = a%:M. Proof. by apply/matrixP=> i j; rewrite !mxE eq_sym. Qed. Fact scalar_mx_is_nmod_morphism : nmod_morphism scalar_mx. Proof. by split=> [|a b]; rewrite -!diag_const_mx ?raddf0// !raddfD. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `scalar_mx_is_nmod_morphism` instead")] Definition scalar_mx_is_semi_additive := scalar_mx_is_nmod_morphism. HB.instance Definition _ := GRing.isNmodMorphism.Build V 'M_n scalar_mx scalar_mx_is_nmod_morphism. Definition is_scalar_mx (A : 'M[V]_n) := if insub 0 is Some i then A == (A i i)%:M else true. Lemma is_scalar_mxP A : reflect (exists a, A = a%:M) (is_scalar_mx A). Proof. rewrite /is_scalar_mx; case: insubP => [i _ _ | ]. by apply: (iffP eqP) => [|[a ->]]; [exists (A i i) | rewrite mxE eqxx]. rewrite -eqn0Ngt => /eqP n0; left; exists 0. by rewrite raddf0; rewrite n0 in A *; rewrite [A]flatmx0. Qed. Lemma scalar_mx_is_scalar a : is_scalar_mx a%:M. Proof. by apply/is_scalar_mxP; exists a. Qed. Lemma mx0_is_scalar : is_scalar_mx 0. Proof. by apply/is_scalar_mxP; exists 0; rewrite raddf0. Qed. Lemma scalar_mx_is_diag a : is_diag_mx a%:M. Proof. by rewrite -diag_const_mx diag_mx_is_diag. Qed. Lemma is_scalar_mx_is_diag A : is_scalar_mx A -> is_diag_mx A. Proof. by move=> /is_scalar_mxP[a ->]; apply: scalar_mx_is_diag. Qed. Lemma scalar_mx_is_trig a : is_trig_mx a%:M. Proof. by rewrite is_diag_mx_is_trig// scalar_mx_is_diag. Qed. Lemma is_scalar_mx_is_trig A : is_scalar_mx A -> is_trig_mx A. Proof. by move=> /is_scalar_mx_is_diag /is_diag_mx_is_trig. Qed. End ScalarMx. Notation "x %:M" := (scalar_mx _ x) : ring_scope. Lemma mx11_scalar (A : 'M_1) : A = (A 0 0)%:M. Proof. by apply/rowP=> j; rewrite ord1 mxE. Qed. Lemma scalar_mx_block n1 n2 a : a%:M = block_mx a%:M 0 0 a%:M :> 'M_(n1 + n2). Proof. apply/matrixP=> i j; rewrite !mxE. by do 2![case: split_ordP => ? ->; rewrite !mxE]; rewrite ?eq_shift. Qed. (* The trace. *) Section Trace. Variable n : nat. (*TODO: undergeneralize to monoid *) Definition mxtrace (A : 'M[V]_n) := \sum_i A i i. Local Notation "'\tr' A" := (mxtrace A) : ring_scope. Lemma mxtrace_tr A : \tr A^T = \tr A. Proof. by apply: eq_bigr=> i _; rewrite mxE. Qed. Fact mxtrace_is_nmod_morphism : nmod_morphism mxtrace. Proof. split=> [|A B]; first by apply: big1 => i; rewrite mxE. by rewrite -big_split /=; apply: eq_bigr => i _; rewrite mxE. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `mxtrace_is_nmod_morphism` instead")] Definition mxtrace_is_semi_additive := mxtrace_is_nmod_morphism. HB.instance Definition _ := GRing.isNmodMorphism.Build 'M_n V mxtrace mxtrace_is_nmod_morphism. Lemma mxtrace0 : \tr 0 = 0. Proof. exact: raddf0. Qed. Lemma mxtraceD A B : \tr (A + B) = \tr A + \tr B. Proof. exact: raddfD. Qed. Lemma mxtrace_diag D : \tr (diag_mx D) = \sum_j D 0 j. Proof. by apply: eq_bigr => j _; rewrite mxE eqxx. Qed. Lemma mxtrace_scalar a : \tr a%:M = a *+ n. Proof. rewrite -diag_const_mx mxtrace_diag; under eq_bigr do rewrite mxE. by rewrite sumr_const card_ord. Qed. End Trace. Local Notation "'\tr' A" := (mxtrace A) : ring_scope. Lemma trace_mx11 (A : 'M_1) : \tr A = A 0 0. Proof. by rewrite [A in LHS]mx11_scalar mxtrace_scalar. Qed. Lemma mxtrace_block n1 n2 (Aul : 'M_n1) Aur Adl (Adr : 'M_n2) : \tr (block_mx Aul Aur Adl Adr) = \tr Aul + \tr Adr. Proof. rewrite /(\tr _) big_split_ord /=. by congr (_ + _); under eq_bigr do rewrite (block_mxEul, block_mxEdr). Qed. End MatrixNmodule. Arguments is_diag_mx {V m n}. Arguments is_diag_mxP {V m n A}. Arguments is_trig_mx {V m n}. Arguments is_trig_mxP {V m n A}. Arguments scalar_mx {V n}. Arguments is_scalar_mxP {V n A}. Notation "\tr A" := (mxtrace A) : ring_scope. (* Parametricity over the semi-additive structure. *) Section MapNmodMatrix. Variables (aR rR : nmodType) (f : {additive aR -> rR}) (m n : nat). Local Notation "A ^f" := (map_mx f A) : ring_scope. Implicit Type A : 'M[aR]_(m, n). Lemma map_mx0 : 0^f = 0 :> 'M_(m, n). Proof. by rewrite map_const_mx raddf0. Qed. Lemma map_mxD A B : (A + B)^f = A^f + B^f. Proof. by apply/matrixP=> i j; rewrite !mxE raddfD. Qed. Definition map_mx_sum := big_morph _ map_mxD map_mx0. HB.instance Definition _ := GRing.isNmodMorphism.Build 'M[aR]_(m, n) 'M[rR]_(m, n) (map_mx f) (map_mx0, map_mxD). End MapNmodMatrix. Section MatrixZmodule. Variable V : zmodType. Section FixedDim. Variables m n : nat. Implicit Types A B : 'M[V]_(m, n). Fact oppmx_key : unit. Proof. by []. Qed. Definition oppmx := @map_mx V V -%R m n. Lemma addNmx : left_inverse (const_mx 0) oppmx (@addmx V m n). Proof. by move=> A; apply/matrixP=> i j; rewrite !mxE addNr. Qed. HB.instance Definition _ := GRing.Nmodule_isZmodule.Build 'M[V]_(m, n) addNmx. #[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead")] Fact const_mx_is_zmod_morphism : zmod_morphism const_mx. Proof. exact: raddfB. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead"), warning="-deprecated"] Definition const_mx_is_additive := const_mx_is_zmod_morphism. End FixedDim. Section Additive. Variables (m n p q : nat) (f : 'I_p -> 'I_q -> 'I_m) (g : 'I_p -> 'I_q -> 'I_n). #[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead")] Fact swizzle_mx_is_zmod_morphism k : zmod_morphism (swizzle_mx f g k). Proof. exact: raddfB. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead"), warning="-deprecated"] Definition swizzle_mx_is_additive := swizzle_mx_is_zmod_morphism. End Additive. Ltac split_mxE := apply/matrixP=> i j; do ![rewrite mxE | case: split => ?]. Lemma opp_row_mx m n1 n2 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) : - row_mx A1 A2 = row_mx (- A1) (- A2). Proof. by split_mxE. Qed. Lemma opp_col_mx m1 m2 n (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) : - col_mx A1 A2 = col_mx (- A1) (- A2). Proof. by split_mxE. Qed. Lemma opp_block_mx m1 m2 n1 n2 (Aul : 'M_(m1, n1)) Aur Adl (Adr : 'M_(m2, n2)) : - block_mx Aul Aur Adl Adr = block_mx (- Aul) (- Aur) (- Adl) (- Adr). Proof. by rewrite opp_col_mx !opp_row_mx. Qed. (* Diagonal matrices *) #[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead")] Fact diag_mx_is_zmod_morphism n : zmod_morphism (@diag_mx V n). Proof. exact: raddfB. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead"), warning="-deprecated"] Definition diag_mx_is_additive := diag_mx_is_zmod_morphism. (* Scalar matrix : a diagonal matrix with a constant on the diagonal *) Section ScalarMx. Variable n : nat. #[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead")] Fact scalar_mx_is_zmod_morphism : zmod_morphism (@scalar_mx V n). Proof. exact: raddfB. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead"), warning="-deprecated"] Definition scalar_mx_is_additive := scalar_mx_is_zmod_morphism. End ScalarMx. (* The trace. *) Section Trace. Variable n : nat. #[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead")] Fact mxtrace_is_zmod_morphism : zmod_morphism (@mxtrace V n). Proof. exact: raddfB. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead"), warning="-deprecated"] Definition mxtrace_is_additive := mxtrace_is_zmod_morphism. End Trace. End MatrixZmodule. (* Parametricity over the additive structure. *) Section MapZmodMatrix. Variables (aR rR : zmodType) (f : {additive aR -> rR}) (m n : nat). Local Notation "A ^f" := (map_mx f A) : ring_scope. Implicit Type A : 'M[aR]_(m, n). Lemma map_mxN A : (- A)^f = - A^f. Proof. exact: raddfN. Qed. Lemma map_mxB A B : (A - B)^f = A^f - B^f. Proof. exact: raddfB. Qed. End MapZmodMatrix. (*****************************************************************************) (*********** Matrix ring module, graded ring, and ring structures ************) (*****************************************************************************) Section MatrixAlgebra. Variable R : pzSemiRingType. Section SemiRingModule. (* The ring module/vector space structure *) Variables m n : nat. Implicit Types A B : 'M[R]_(m, n). Fact scalemx_key : unit. Proof. by []. Qed. Definition scalemx x A := \matrix[scalemx_key]_(i, j) (x * A i j). (* Basis *) Fact delta_mx_key : unit. Proof. by []. Qed. Definition delta_mx i0 j0 : 'M[R]_(m, n) := \matrix[delta_mx_key]_(i, j) ((i == i0) && (j == j0))%:R. Local Notation "x *m: A" := (scalemx x A) (at level 40) : ring_scope. Fact scale0mx A : 0 *m: A = 0. Proof. by apply/matrixP=> i j; rewrite !mxE mul0r. Qed. Fact scale1mx A : 1 *m: A = A. Proof. by apply/matrixP=> i j; rewrite !mxE mul1r. Qed. Fact scalemxDl A x y : (x + y) *m: A = x *m: A + y *m: A. Proof. by apply/matrixP=> i j; rewrite !mxE mulrDl. Qed. Fact scalemxDr x A B : x *m: (A + B) = x *m: A + x *m: B. Proof. by apply/matrixP=> i j; rewrite !mxE mulrDr. Qed. Fact scalemxA x y A : x *m: (y *m: A) = (x * y) *m: A. Proof. by apply/matrixP=> i j; rewrite !mxE mulrA. Qed. HB.instance Definition _ := GRing.Nmodule_isLSemiModule.Build R 'M[R]_(m, n) scalemxA scale0mx scale1mx scalemxDr scalemxDl. Lemma scalemx_const a b : a *: const_mx b = const_mx (a * b). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma matrix_sum_delta A : A = \sum_(i < m) \sum_(j < n) A i j *: delta_mx i j. Proof. apply/matrixP=> i j. rewrite summxE (bigD1_ord i) // summxE (bigD1_ord j) //= !mxE !eqxx mulr1. rewrite !big1 ?addr0 //= => [i' | j'] _. by rewrite summxE big1// => j' _; rewrite !mxE eq_liftF mulr0. by rewrite !mxE eqxx eq_liftF mulr0. Qed. End SemiRingModule. Lemma trmx_delta m n i j : (delta_mx i j)^T = delta_mx j i :> 'M[R]_(n, m). Proof. by apply/matrixP=> i' j'; rewrite !mxE andbC. Qed. Lemma delta_mx_lshift m n1 n2 i j : delta_mx i (lshift n2 j) = row_mx (delta_mx i j) 0 :> 'M_(m, n1 + n2). Proof. apply/matrixP=> i' j'; rewrite !mxE -(can_eq splitK) (unsplitK (inl _ _)). by case: split => ?; rewrite mxE ?andbF. Qed. Lemma delta_mx_rshift m n1 n2 i j : delta_mx i (rshift n1 j) = row_mx 0 (delta_mx i j) :> 'M_(m, n1 + n2). Proof. apply/matrixP=> i' j'; rewrite !mxE -(can_eq splitK) (unsplitK (inr _ _)). by case: split => ?; rewrite mxE ?andbF. Qed. Lemma delta_mx_ushift m1 m2 n i j : delta_mx (lshift m2 i) j = col_mx (delta_mx i j) 0 :> 'M_(m1 + m2, n). Proof. apply/matrixP=> i' j'; rewrite !mxE -(can_eq splitK) (unsplitK (inl _ _)). by case: split => ?; rewrite mxE. Qed. Lemma delta_mx_dshift m1 m2 n i j : delta_mx (rshift m1 i) j = col_mx 0 (delta_mx i j) :> 'M_(m1 + m2, n). Proof. apply/matrixP=> i' j'; rewrite !mxE -(can_eq splitK) (unsplitK (inr _ _)). by case: split => ?; rewrite mxE. Qed. Lemma vec_mx_delta m n i j : vec_mx (delta_mx 0 (mxvec_index i j)) = delta_mx i j :> 'M_(m, n). Proof. by apply/matrixP=> i' j'; rewrite !mxE /= [_ == _](inj_eq enum_rank_inj). Qed. Lemma mxvec_delta m n i j : mxvec (delta_mx i j) = delta_mx 0 (mxvec_index i j) :> 'rV_(m * n). Proof. by rewrite -vec_mx_delta vec_mxK. Qed. Ltac split_mxE := apply/matrixP=> i j; do ![rewrite mxE | case: split => ?]. (* Scalar matrix *) Notation "x %:M" := (scalar_mx x) : ring_scope. Lemma trmx1 n : (1%:M)^T = 1%:M :> 'M[R]_n. Proof. exact: tr_scalar_mx. Qed. Lemma row1 n i : row i (1%:M : 'M_n) = delta_mx 0 i. Proof. by apply/rowP=> j; rewrite !mxE eq_sym. Qed. Lemma col1 n i : col i (1%:M : 'M_n) = delta_mx i 0. Proof. by apply/colP => j; rewrite !mxE eqxx andbT. Qed. (* Matrix multiplication using bigops. *) Fact mulmx_key : unit. Proof. by []. Qed. Definition mulmx {m n p} (A : 'M_(m, n)) (B : 'M_(n, p)) : 'M[R]_(m, p) := \matrix[mulmx_key]_(i, k) \sum_j (A i j * B j k). Local Notation "A *m B" := (mulmx A B) : ring_scope. Lemma mulmxA m n p q (A : 'M_(m, n)) (B : 'M_(n, p)) (C : 'M_(p, q)) : A *m (B *m C) = A *m B *m C. Proof. apply/matrixP=> i l /[!mxE]; under eq_bigr do rewrite mxE big_distrr/=. rewrite exchange_big; apply: eq_bigr => j _; rewrite mxE big_distrl /=. by under eq_bigr do rewrite mulrA. Qed. Lemma mul0mx m n p (A : 'M_(n, p)) : 0 *m A = 0 :> 'M_(m, p). Proof. by apply/matrixP=> i k; rewrite !mxE big1 //= => j _; rewrite mxE mul0r. Qed. Lemma mulmx0 m n p (A : 'M_(m, n)) : A *m 0 = 0 :> 'M_(m, p). Proof. by apply/matrixP=> i k; rewrite !mxE big1 // => j _; rewrite mxE mulr0. Qed. Lemma mulmxDl m n p (A1 A2 : 'M_(m, n)) (B : 'M_(n, p)) : (A1 + A2) *m B = A1 *m B + A2 *m B. Proof. apply/matrixP=> i k; rewrite !mxE -big_split /=. by apply: eq_bigr => j _; rewrite !mxE -mulrDl. Qed. Lemma mulmxDr m n p (A : 'M_(m, n)) (B1 B2 : 'M_(n, p)) : A *m (B1 + B2) = A *m B1 + A *m B2. Proof. apply/matrixP=> i k; rewrite !mxE -big_split /=. by apply: eq_bigr => j _; rewrite mxE mulrDr. Qed. HB.instance Definition _ m n p A := GRing.isNmodMorphism.Build 'M_(n, p) 'M_(m, p) (mulmx A) (mulmx0 _ A, mulmxDr A). Lemma scalemxAl m n p a (A : 'M_(m, n)) (B : 'M_(n, p)) : a *: (A *m B) = (a *: A) *m B. Proof. apply/matrixP=> i k; rewrite !mxE big_distrr /=. by apply: eq_bigr => j _; rewrite mulrA mxE. Qed. Lemma mulmx_suml m n p (A : 'M_(n, p)) I r P (B_ : I -> 'M_(m, n)) : (\sum_(i <- r | P i) B_ i) *m A = \sum_(i <- r | P i) B_ i *m A. Proof. by apply: (big_morph (mulmx^~ A)) => [B C|]; rewrite ?mul0mx ?mulmxDl. Qed. Lemma mulmx_sumr m n p (A : 'M_(m, n)) I r P (B_ : I -> 'M_(n, p)) : A *m (\sum_(i <- r | P i) B_ i) = \sum_(i <- r | P i) A *m B_ i. Proof. exact: raddf_sum. Qed. Lemma rowE m n i (A : 'M_(m, n)) : row i A = delta_mx 0 i *m A. Proof. apply/rowP=> j; rewrite !mxE (bigD1_ord i) //= mxE !eqxx mul1r. by rewrite big1 ?addr0 // => i'; rewrite mxE /= lift_eqF mul0r. Qed. Lemma colE m n i (A : 'M_(m, n)) : col i A = A *m delta_mx i 0. Proof. apply/colP=> j; rewrite !mxE (bigD1_ord i) //= mxE !eqxx mulr1. by rewrite big1 ?addr0 // => i'; rewrite mxE /= lift_eqF mulr0. Qed. Lemma mul_rVP m n A B : ((@mulmx 1 m n)^~ A =1 mulmx^~ B) <-> (A = B). Proof. by split=> [eqAB|->//]; apply/row_matrixP => i; rewrite !rowE eqAB. Qed. Lemma row_mul m n p (i : 'I_m) A (B : 'M_(n, p)) : row i (A *m B) = row i A *m B. Proof. by rewrite !rowE mulmxA. Qed. Lemma mxsub_mul m n m' n' p f g (A : 'M_(m, p)) (B : 'M_(p, n)) : mxsub f g (A *m B) = rowsub f A *m colsub g B :> 'M_(m', n'). Proof. by split_mxE; under [RHS]eq_bigr do rewrite !mxE. Qed. Lemma mul_rowsub_mx m n m' p f (A : 'M_(m, p)) (B : 'M_(p, n)) : rowsub f A *m B = rowsub f (A *m B) :> 'M_(m', n). Proof. by rewrite mxsub_mul mxsub_id. Qed. Lemma mulmx_colsub m n n' p g (A : 'M_(m, p)) (B : 'M_(p, n)) : A *m colsub g B = colsub g (A *m B) :> 'M_(m, n'). Proof. by rewrite mxsub_mul mxsub_id. Qed. Lemma mul_delta_mx_cond m n p (j1 j2 : 'I_n) (i1 : 'I_m) (k2 : 'I_p) : delta_mx i1 j1 *m delta_mx j2 k2 = delta_mx i1 k2 *+ (j1 == j2). Proof. apply/matrixP => i k; rewrite !mxE (bigD1_ord j1) //=. rewrite mulmxnE !mxE !eqxx andbT -natrM -mulrnA !mulnb !andbA andbAC. by rewrite big1 ?addr0 // => j; rewrite !mxE andbC -natrM lift_eqF. Qed. Lemma mul_delta_mx m n p (j : 'I_n) (i : 'I_m) (k : 'I_p) : delta_mx i j *m delta_mx j k = delta_mx i k. Proof. by rewrite mul_delta_mx_cond eqxx. Qed. Lemma mul_delta_mx_0 m n p (j1 j2 : 'I_n) (i1 : 'I_m) (k2 : 'I_p) : j1 != j2 -> delta_mx i1 j1 *m delta_mx j2 k2 = 0. Proof. by rewrite mul_delta_mx_cond => /negPf->. Qed. Lemma mul_diag_mx m n d (A : 'M_(m, n)) : diag_mx d *m A = \matrix_(i, j) (d 0 i * A i j). Proof. apply/matrixP=> i j; rewrite !mxE (bigD1 i) //= mxE eqxx big1 ?addr0 // => i'. by rewrite mxE eq_sym mulrnAl => /negPf->. Qed. Lemma mul_mx_diag m n (A : 'M_(m, n)) d : A *m diag_mx d = \matrix_(i, j) (A i j * d 0 j). Proof. apply/matrixP=> i j; rewrite !mxE (bigD1 j) //= mxE eqxx big1 ?addr0 // => i'. by rewrite mxE eq_sym mulrnAr; move/negPf->. Qed. Lemma mulmx_diag n (d e : 'rV_n) : diag_mx d *m diag_mx e = diag_mx (\row_j (d 0 j * e 0 j)). Proof. by apply/matrixP=> i j; rewrite mul_diag_mx !mxE mulrnAr. Qed. Lemma scalar_mxM n a b : (a * b)%:M = a%:M *m b%:M :> 'M_n. Proof. rewrite -[in RHS]diag_const_mx mul_diag_mx. by apply/matrixP => i j; rewrite !mxE mulrnAr. Qed. Lemma mul1mx m n (A : 'M_(m, n)) : 1%:M *m A = A. Proof. by rewrite -diag_const_mx mul_diag_mx; apply/matrixP => i j; rewrite !mxE mul1r. Qed. Lemma mulmx1 m n (A : 'M_(m, n)) : A *m 1%:M = A. Proof. by rewrite -diag_const_mx mul_mx_diag; apply/matrixP=> i j; rewrite !mxE mulr1. Qed. Lemma rowsubE m m' n f (A : 'M_(m, n)) : rowsub f A = rowsub f 1%:M *m A :> 'M_(m', n). Proof. by rewrite mul_rowsub_mx mul1mx. Qed. (* mulmx and col_perm, row_perm, xcol, xrow *) Lemma mul_col_perm m n p s (A : 'M_(m, n)) (B : 'M_(n, p)) : col_perm s A *m B = A *m row_perm s^-1 B. Proof. apply/matrixP=> i k; rewrite !mxE (reindex_perm s^-1). by apply: eq_bigr => j _ /=; rewrite !mxE permKV. Qed. Lemma mul_row_perm m n p s (A : 'M_(m, n)) (B : 'M_(n, p)) : A *m row_perm s B = col_perm s^-1 A *m B. Proof. by rewrite mul_col_perm invgK. Qed. Lemma mul_xcol m n p j1 j2 (A : 'M_(m, n)) (B : 'M_(n, p)) : xcol j1 j2 A *m B = A *m xrow j1 j2 B. Proof. by rewrite mul_col_perm tpermV. Qed. (* Permutation matrix *) Definition perm_mx n s : 'M_n := row_perm s (1%:M : 'M[R]_n). Definition tperm_mx n i1 i2 : 'M_n := perm_mx (tperm i1 i2). Lemma col_permE m n s (A : 'M_(m, n)) : col_perm s A = A *m perm_mx s^-1. Proof. by rewrite mul_row_perm mulmx1 invgK. Qed. Lemma row_permE m n s (A : 'M_(m, n)) : row_perm s A = perm_mx s *m A. Proof. by rewrite -[perm_mx _]mul1mx mul_row_perm mulmx1 -mul_row_perm mul1mx. Qed. Lemma xcolE m n j1 j2 (A : 'M_(m, n)) : xcol j1 j2 A = A *m tperm_mx j1 j2. Proof. by rewrite /xcol col_permE tpermV. Qed. Lemma xrowE m n i1 i2 (A : 'M_(m, n)) : xrow i1 i2 A = tperm_mx i1 i2 *m A. Proof. exact: row_permE. Qed. Lemma perm_mxEsub n s : @perm_mx n s = rowsub s 1%:M. Proof. by rewrite /perm_mx row_permEsub. Qed. Lemma tperm_mxEsub n i1 i2 : @tperm_mx n i1 i2 = rowsub (tperm i1 i2) 1%:M. Proof. by rewrite /tperm_mx perm_mxEsub. Qed. Lemma tr_perm_mx n (s : 'S_n) : (perm_mx s)^T = perm_mx s^-1. Proof. by rewrite -[_^T]mulmx1 tr_row_perm mul_col_perm trmx1 mul1mx. Qed. Lemma tr_tperm_mx n i1 i2 : (tperm_mx i1 i2)^T = tperm_mx i1 i2 :> 'M_n. Proof. by rewrite tr_perm_mx tpermV. Qed. Lemma perm_mx1 n : perm_mx 1 = 1%:M :> 'M_n. Proof. exact: row_perm1. Qed. Lemma perm_mxM n (s t : 'S_n) : perm_mx (s * t) = perm_mx s *m perm_mx t. Proof. by rewrite -row_permE -row_permM. Qed. Definition is_perm_mx n (A : 'M_n) := [exists s, A == perm_mx s]. Lemma is_perm_mxP n (A : 'M_n) : reflect (exists s, A = perm_mx s) (is_perm_mx A). Proof. by apply: (iffP existsP) => [] [s /eqP]; exists s. Qed. Lemma perm_mx_is_perm n (s : 'S_n) : is_perm_mx (perm_mx s). Proof. by apply/is_perm_mxP; exists s. Qed. Lemma is_perm_mx1 n : is_perm_mx (1%:M : 'M_n). Proof. by rewrite -perm_mx1 perm_mx_is_perm. Qed. Lemma is_perm_mxMl n (A B : 'M_n) : is_perm_mx A -> is_perm_mx (A *m B) = is_perm_mx B. Proof. case/is_perm_mxP=> s ->. apply/is_perm_mxP/is_perm_mxP=> [[t def_t] | [t ->]]; last first. by exists (s * t)%g; rewrite perm_mxM. exists (s^-1 * t)%g. by rewrite perm_mxM -def_t -!row_permE -row_permM mulVg row_perm1. Qed. Lemma is_perm_mx_tr n (A : 'M_n) : is_perm_mx A^T = is_perm_mx A. Proof. apply/is_perm_mxP/is_perm_mxP=> [[t def_t] | [t ->]]; exists t^-1%g. by rewrite -tr_perm_mx -def_t trmxK. by rewrite tr_perm_mx. Qed. Lemma is_perm_mxMr n (A B : 'M_n) : is_perm_mx B -> is_perm_mx (A *m B) = is_perm_mx A. Proof. case/is_perm_mxP=> s ->. rewrite -[s]invgK -col_permE -is_perm_mx_tr tr_col_perm row_permE. by rewrite is_perm_mxMl (perm_mx_is_perm, is_perm_mx_tr). Qed. (* Partial identity matrix (used in rank decomposition). *) Fact pid_mx_key : unit. Proof. by []. Qed. Definition pid_mx {m n} r : 'M[R]_(m, n) := \matrix[pid_mx_key]_(i, j) ((i == j :> nat) && (i < r))%:R. Lemma pid_mx_0 m n : pid_mx 0 = 0 :> 'M_(m, n). Proof. by apply/matrixP=> i j; rewrite !mxE andbF. Qed. Lemma pid_mx_1 r : pid_mx r = 1%:M :> 'M_r. Proof. by apply/matrixP=> i j; rewrite !mxE ltn_ord andbT. Qed. Lemma pid_mx_row n r : pid_mx r = row_mx 1%:M 0 :> 'M_(r, r + n). Proof. apply/matrixP=> i j; rewrite !mxE ltn_ord andbT. by case: split_ordP => j' ->; rewrite !mxE// (val_eqE (lshift n i)) eq_shift. Qed. Lemma pid_mx_col m r : pid_mx r = col_mx 1%:M 0 :> 'M_(r + m, r). Proof. apply/matrixP=> i j; rewrite !mxE andbC. by case: split_ordP => ? ->; rewrite !mxE//. Qed. Lemma pid_mx_block m n r : pid_mx r = block_mx 1%:M 0 0 0 :> 'M_(r + m, r + n). Proof. apply/matrixP=> i j; rewrite !mxE row_mx0 andbC. do ![case: split_ordP => ? -> /[!mxE]//]. by rewrite (val_eqE (lshift n _)) eq_shift. Qed. Lemma tr_pid_mx m n r : (pid_mx r)^T = pid_mx r :> 'M_(n, m). Proof. by apply/matrixP=> i j /[!mxE]; case: eqVneq => // ->. Qed. Lemma pid_mx_minv m n r : pid_mx (minn m r) = pid_mx r :> 'M_(m, n). Proof. by apply/matrixP=> i j; rewrite !mxE leq_min ltn_ord. Qed. Lemma pid_mx_minh m n r : pid_mx (minn n r) = pid_mx r :> 'M_(m, n). Proof. by apply: trmx_inj; rewrite !tr_pid_mx pid_mx_minv. Qed. Lemma mul_pid_mx m n p q r : (pid_mx q : 'M_(m, n)) *m (pid_mx r : 'M_(n, p)) = pid_mx (minn n (minn q r)). Proof. apply/matrixP=> i k; rewrite !mxE !leq_min. have [le_n_i | lt_i_n] := leqP n i. rewrite andbF big1 // => j _. by rewrite -pid_mx_minh !mxE leq_min ltnNge le_n_i andbF mul0r. rewrite (bigD1 (Ordinal lt_i_n)) //= big1 ?addr0 => [|j]. by rewrite !mxE eqxx /= -natrM mulnb andbCA. by rewrite -val_eqE /= !mxE eq_sym -natrM => /negPf->. Qed. Lemma pid_mx_id m n p r : r <= n -> (pid_mx r : 'M_(m, n)) *m (pid_mx r : 'M_(n, p)) = pid_mx r. Proof. by move=> le_r_n; rewrite mul_pid_mx minnn (minn_idPr _). Qed. Lemma pid_mxErow m n (le_mn : m <= n) : pid_mx m = rowsub (widen_ord le_mn) 1%:M. Proof. by apply/matrixP=> i j; rewrite !mxE -!val_eqE/= ltn_ord andbT. Qed. Lemma pid_mxEcol m n (le_mn : m <= n) : pid_mx n = colsub (widen_ord le_mn) 1%:M. Proof. by apply/matrixP=> i j; rewrite !mxE -!val_eqE/= ltn_ord andbT. Qed. (* Block products; we cover all 1 x 2, 2 x 1, and 2 x 2 block products. *) Lemma mul_mx_row m n p1 p2 (A : 'M_(m, n)) (Bl : 'M_(n, p1)) (Br : 'M_(n, p2)) : A *m row_mx Bl Br = row_mx (A *m Bl) (A *m Br). Proof. apply/matrixP=> i k; rewrite !mxE. by case defk: (split k) => /[!mxE]; under eq_bigr do rewrite mxE defk. Qed. Lemma mul_col_mx m1 m2 n p (Au : 'M_(m1, n)) (Ad : 'M_(m2, n)) (B : 'M_(n, p)) : col_mx Au Ad *m B = col_mx (Au *m B) (Ad *m B). Proof. apply/matrixP=> i k; rewrite !mxE. by case defi: (split i) => /[!mxE]; under eq_bigr do rewrite mxE defi. Qed. Lemma mul_row_col m n1 n2 p (Al : 'M_(m, n1)) (Ar : 'M_(m, n2)) (Bu : 'M_(n1, p)) (Bd : 'M_(n2, p)) : row_mx Al Ar *m col_mx Bu Bd = Al *m Bu + Ar *m Bd. Proof. apply/matrixP=> i k; rewrite !mxE big_split_ord /=. congr (_ + _); apply: eq_bigr => j _; first by rewrite row_mxEl col_mxEu. by rewrite row_mxEr col_mxEd. Qed. Lemma mul_col_row m1 m2 n p1 p2 (Au : 'M_(m1, n)) (Ad : 'M_(m2, n)) (Bl : 'M_(n, p1)) (Br : 'M_(n, p2)) : col_mx Au Ad *m row_mx Bl Br = block_mx (Au *m Bl) (Au *m Br) (Ad *m Bl) (Ad *m Br). Proof. by rewrite mul_col_mx !mul_mx_row. Qed. Lemma mul_row_block m n1 n2 p1 p2 (Al : 'M_(m, n1)) (Ar : 'M_(m, n2)) (Bul : 'M_(n1, p1)) (Bur : 'M_(n1, p2)) (Bdl : 'M_(n2, p1)) (Bdr : 'M_(n2, p2)) : row_mx Al Ar *m block_mx Bul Bur Bdl Bdr = row_mx (Al *m Bul + Ar *m Bdl) (Al *m Bur + Ar *m Bdr). Proof. by rewrite block_mxEh mul_mx_row !mul_row_col. Qed. Lemma mul_block_col m1 m2 n1 n2 p (Aul : 'M_(m1, n1)) (Aur : 'M_(m1, n2)) (Adl : 'M_(m2, n1)) (Adr : 'M_(m2, n2)) (Bu : 'M_(n1, p)) (Bd : 'M_(n2, p)) : block_mx Aul Aur Adl Adr *m col_mx Bu Bd = col_mx (Aul *m Bu + Aur *m Bd) (Adl *m Bu + Adr *m Bd). Proof. by rewrite mul_col_mx !mul_row_col. Qed. Lemma mulmx_block m1 m2 n1 n2 p1 p2 (Aul : 'M_(m1, n1)) (Aur : 'M_(m1, n2)) (Adl : 'M_(m2, n1)) (Adr : 'M_(m2, n2)) (Bul : 'M_(n1, p1)) (Bur : 'M_(n1, p2)) (Bdl : 'M_(n2, p1)) (Bdr : 'M_(n2, p2)) : block_mx Aul Aur Adl Adr *m block_mx Bul Bur Bdl Bdr = block_mx (Aul *m Bul + Aur *m Bdl) (Aul *m Bur + Aur *m Bdr) (Adl *m Bul + Adr *m Bdl) (Adl *m Bur + Adr *m Bdr). Proof. by rewrite mul_col_mx !mul_row_block. Qed. Lemma mulmx_lsub m n p k (A : 'M_(m, n)) (B : 'M_(n, p + k)) : A *m lsubmx B = lsubmx (A *m B). Proof. by rewrite !lsubmxEsub mulmx_colsub. Qed. Lemma mulmx_rsub m n p k (A : 'M_(m, n)) (B : 'M_(n, p + k)) : A *m rsubmx B = rsubmx (A *m B). Proof. by rewrite !rsubmxEsub mulmx_colsub. Qed. Lemma mul_usub_mx m k n p (A : 'M_(m + k, n)) (B : 'M_(n, p)) : usubmx A *m B = usubmx (A *m B). Proof. by rewrite !usubmxEsub mul_rowsub_mx. Qed. Lemma mul_dsub_mx m k n p (A : 'M_(m + k, n)) (B : 'M_(n, p)) : dsubmx A *m B = dsubmx (A *m B). Proof. by rewrite !dsubmxEsub mul_rowsub_mx. Qed. (* The trace *) Section Trace. Variable n : nat. Lemma mxtrace1 : \tr (1%:M : 'M[R]_n) = n%:R. Proof. exact: mxtrace_scalar. Qed. Lemma mxtraceZ a (A : 'M_n) : \tr (a *: A) = a * \tr A. Proof. by rewrite mulr_sumr; apply: eq_bigr=> i _; rewrite mxE. Qed. HB.instance Definition _ := GRing.isScalable.Build R 'M_n R _ (@mxtrace _ n) mxtraceZ. End Trace. Section StructuralLinear. Fact swizzle_mx_is_scalable m n p q f g k : scalable (@swizzle_mx R m n p q f g k). Proof. by move=> a A; apply/matrixP=> i j; rewrite !mxE. Qed. HB.instance Definition _ m n p q f g k := GRing.isScalable.Build R 'M[R]_(m, n) 'M[R]_(p, q) *:%R (swizzle_mx f g k) (swizzle_mx_is_scalable f g k). Local Notation SwizzleLin op := (GRing.Linear.copy op (swizzle_mx _ _ _)). HB.instance Definition _ m n := SwizzleLin (@trmx R m n). HB.instance Definition _ m n i := SwizzleLin (@row R m n i). HB.instance Definition _ m n j := SwizzleLin (@col R m n j). HB.instance Definition _ m n i := SwizzleLin (@row' R m n i). HB.instance Definition _ m n j := SwizzleLin (@col' R m n j). HB.instance Definition _ m n m' n' f g := SwizzleLin (@mxsub R m n m' n' f g). HB.instance Definition _ m n s := SwizzleLin (@row_perm R m n s). HB.instance Definition _ m n s := SwizzleLin (@col_perm R m n s). HB.instance Definition _ m n i1 i2 := SwizzleLin (@xrow R m n i1 i2). HB.instance Definition _ m n j1 j2 := SwizzleLin (@xcol R m n j1 j2). HB.instance Definition _ m n1 n2 := SwizzleLin (@lsubmx R m n1 n2). HB.instance Definition _ m n1 n2 := SwizzleLin (@rsubmx R m n1 n2). HB.instance Definition _ m1 m2 n := SwizzleLin (@usubmx R m1 m2 n). HB.instance Definition _ m1 m2 n := SwizzleLin (@dsubmx R m1 m2 n). HB.instance Definition _ m n := SwizzleLin (@vec_mx R m n). Definition mxvec_is_scalable m n := can2_scalable (@vec_mxK R m n) mxvecK. HB.instance Definition _ m n := GRing.isScalable.Build R 'M_(m, n) 'rV_(m * n) *:%R mxvec (@mxvec_is_scalable m n). End StructuralLinear. Lemma row_sum_delta n (u : 'rV_n) : u = \sum_(j < n) u 0 j *: delta_mx 0 j. Proof. by rewrite [u in LHS]matrix_sum_delta big_ord1. Qed. Lemma scale_row_mx m n1 n2 a (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) : a *: row_mx A1 A2 = row_mx (a *: A1) (a *: A2). Proof. by split_mxE. Qed. Lemma scale_col_mx m1 m2 n a (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) : a *: col_mx A1 A2 = col_mx (a *: A1) (a *: A2). Proof. by split_mxE. Qed. Lemma scale_block_mx m1 m2 n1 n2 a (Aul : 'M_(m1, n1)) (Aur : 'M_(m1, n2)) (Adl : 'M_(m2, n1)) (Adr : 'M_(m2, n2)) : a *: block_mx Aul Aur Adl Adr = block_mx (a *: Aul) (a *: Aur) (a *: Adl) (a *: Adr). Proof. by rewrite scale_col_mx !scale_row_mx. Qed. (* Diagonal matrices *) Fact diag_mx_is_scalable n : scalable (@diag_mx R n). Proof. by move=> a A; apply/matrixP=> i j; rewrite !mxE mulrnAr. Qed. HB.instance Definition _ n := GRing.isScalable.Build R 'rV_n 'M_n _ (@diag_mx _ n) (@diag_mx_is_scalable n). Lemma diag_mx_sum_delta n (d : 'rV_n) : diag_mx d = \sum_i d 0 i *: delta_mx i i. Proof. apply/matrixP=> i j; rewrite summxE (bigD1_ord i) //= !mxE eqxx /=. by rewrite eq_sym mulr_natr big1 ?addr0 // => i'; rewrite !mxE eq_liftF mulr0. Qed. Lemma row_diag_mx n (d : 'rV_n) i : row i (diag_mx d) = d 0 i *: delta_mx 0 i. Proof. by apply/rowP => j; rewrite !mxE eqxx eq_sym mulr_natr. Qed. (* Scalar matrix *) Lemma scale_scalar_mx n a1 a2 : a1 *: a2%:M = (a1 * a2)%:M :> 'M_n. Proof. by apply/matrixP=> i j; rewrite !mxE mulrnAr. Qed. Lemma scalemx1 n a : a *: 1%:M = a%:M :> 'M_n. Proof. by rewrite scale_scalar_mx mulr1. Qed. Lemma scalar_mx_sum_delta n a : a%:M = \sum_i a *: delta_mx i i :> 'M_n. Proof. by rewrite -diag_const_mx diag_mx_sum_delta; under eq_bigr do rewrite mxE. Qed. Lemma mx1_sum_delta n : 1%:M = \sum_i delta_mx i i :> 'M[R]_n. Proof. by rewrite [1%:M]scalar_mx_sum_delta -scaler_sumr scale1r. Qed. (* Right scaling associativity requires a commutative ring *) Lemma mulmx_sum_row m n (u : 'rV_m) (A : 'M_(m, n)) : u *m A = \sum_i u 0 i *: row i A. Proof. by apply/rowP => j /[!(mxE, summxE)]; apply: eq_bigr => i _ /[!mxE]. Qed. Lemma mul_scalar_mx m n a (A : 'M_(m, n)) : a%:M *m A = a *: A. Proof. by rewrite -diag_const_mx mul_diag_mx; apply/matrixP=> i j; rewrite !mxE. Qed. Section MatrixSemiRing. Variable n : nat. HB.instance Definition _ := GRing.Nmodule_isPzSemiRing.Build 'M[R]_n (@mulmxA n n n n) (@mul1mx n n) (@mulmx1 n n) (@mulmxDl n n n) (@mulmxDr n n n) (@mul0mx n n n) (@mulmx0 n n n). Lemma mulmxE : mulmx = *%R. Proof. by []. Qed. Lemma idmxE : 1%:M = 1 :> 'M_n. Proof. by []. Qed. Fact scalar_mx_is_monoid_morphism : monoid_morphism (@scalar_mx R n). Proof. by split=> //; apply: scalar_mxM. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `scalar_mx_is_monoid_morphism` instead")] Definition scalar_mx_is_multiplicative := scalar_mx_is_monoid_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build R 'M_n (@scalar_mx _ n) scalar_mx_is_monoid_morphism. End MatrixSemiRing. (* Correspondence between matrices and linear function on row vectors. *) Section LinRowVector. Variables m n : nat. Fact lin1_mx_key : unit. Proof. by []. Qed. Definition lin1_mx (f : 'rV[R]_m -> 'rV[R]_n) := \matrix[lin1_mx_key]_(i, j) f (delta_mx 0 i) 0 j. Variable f : {linear 'rV[R]_m -> 'rV[R]_n}. Lemma mul_rV_lin1 u : u *m lin1_mx f = f u. Proof. rewrite [u in RHS]matrix_sum_delta big_ord1 linear_sum; apply/rowP=> i. by rewrite mxE summxE; apply: eq_bigr => j _; rewrite linearZ !mxE. Qed. End LinRowVector. (* Correspondence between matrices and linear function on matrices. *) Section LinMatrix. Variables m1 n1 m2 n2 : nat. Definition lin_mx (f : 'M[R]_(m1, n1) -> 'M[R]_(m2, n2)) := lin1_mx (mxvec \o f \o vec_mx). Variable f : {linear 'M[R]_(m1, n1) -> 'M[R]_(m2, n2)}. Lemma mul_rV_lin u : u *m lin_mx f = mxvec (f (vec_mx u)). Proof. exact: mul_rV_lin1. Qed. Lemma mul_vec_lin A : mxvec A *m lin_mx f = mxvec (f A). Proof. by rewrite mul_rV_lin mxvecK. Qed. Lemma mx_rV_lin u : vec_mx (u *m lin_mx f) = f (vec_mx u). Proof. by rewrite mul_rV_lin mxvecK. Qed. Lemma mx_vec_lin A : vec_mx (mxvec A *m lin_mx f) = f A. Proof. by rewrite mul_rV_lin !mxvecK. Qed. End LinMatrix. Section Mulmxr. Variables m n p : nat. Implicit Type A : 'M[R]_(m, n). Implicit Type B : 'M[R]_(n, p). Definition mulmxr B A := mulmx A B. Arguments mulmxr B A /. Fact mulmxr_is_semilinear B : semilinear (mulmxr B). Proof. by split=> [a A|A1 A2]; rewrite /= (mulmxDl, scalemxAl). Qed. HB.instance Definition _ (B : 'M_(n, p)) := GRing.isSemilinear.Build R 'M_(m, n) 'M_(m, p) _ (mulmxr B) (mulmxr_is_semilinear B). Definition lin_mulmxr B := lin_mx (mulmxr B). Fact lin_mulmxr_is_semilinear : semilinear lin_mulmxr. Proof. split=> [a A|A B]; apply/row_matrixP; case/mxvec_indexP=> i j; rewrite (linearZ, linearD) /= !rowE !mul_rV_lin /= vec_mx_delta; rewrite -(linearZ, linearD) 1?mulmxDr //=. congr mxvec; apply/row_matrixP=> k. rewrite linearZ /= !row_mul rowE mul_delta_mx_cond. by case: (k == i); [rewrite -!rowE linearZ | rewrite !mul0mx raddf0]. Qed. HB.instance Definition _ := GRing.isSemilinear.Build R 'M_(n, p) 'M_(m * n, m * p) _ lin_mulmxr lin_mulmxr_is_semilinear. End Mulmxr. Section LiftPerm. (* Block expression of a lifted permutation matrix, for the Cormen LUP. *) Variable n : nat. (* These could be in zmodp, but that would introduce a dependency on perm. *) Definition lift0_perm s : 'S_n.+1 := lift_perm 0 0 s. Lemma lift0_perm0 s : lift0_perm s 0 = 0. Proof. exact: lift_perm_id. Qed. Lemma lift0_perm_lift s k' : lift0_perm s (lift 0 k') = lift (0 : 'I_n.+1) (s k'). Proof. exact: lift_perm_lift. Qed. Lemma lift0_permK s : cancel (lift0_perm s) (lift0_perm s^-1). Proof. by move=> i; rewrite /lift0_perm -lift_permV permK. Qed. Lemma lift0_perm_eq0 s i : (lift0_perm s i == 0) = (i == 0). Proof. by rewrite (canF_eq (lift0_permK s)) lift0_perm0. Qed. (* Block expression of a lifted permutation matrix *) Definition lift0_mx A : 'M_(1 + n) := block_mx 1 0 0 A. Lemma lift0_mx_perm s : lift0_mx (perm_mx s) = perm_mx (lift0_perm s). Proof. apply/matrixP=> /= i j; rewrite !mxE split1 /=; case: unliftP => [i'|] -> /=. rewrite lift0_perm_lift !mxE split1 /=. by case: unliftP => [j'|] ->; rewrite ?(inj_eq (lift_inj _)) /= !mxE. rewrite lift0_perm0 !mxE split1 /=. by case: unliftP => [j'|] ->; rewrite /= mxE. Qed. Lemma lift0_mx_is_perm s : is_perm_mx (lift0_mx (perm_mx s)). Proof. by rewrite lift0_mx_perm perm_mx_is_perm. Qed. End LiftPerm. Lemma exp_block_diag_mx m n (A: 'M_m.+1) (B : 'M_n.+1) k : (block_mx A 0 0 B) ^+ k = block_mx (A ^+ k) 0 0 (B ^+ k). Proof. elim: k=> [|k IHk]; first by rewrite !expr0 -scalar_mx_block. rewrite !exprS IHk [LHS](mulmx_block A _ _ _ (A ^+ k)). by rewrite !mulmx0 !mul0mx !add0r !addr0. Qed. End MatrixAlgebra. Arguments delta_mx {R m n}. Arguments perm_mx {R n}. Arguments tperm_mx {R n}. Arguments pid_mx {R m n}. Arguments lin_mulmxr {R m n p}. Prenex Implicits diag_mx is_scalar_mx. Prenex Implicits mulmx mxtrace. Arguments mul_delta_mx {R m n p}. Arguments mulmxr {_ _ _ _} B A /. #[global] Hint Extern 0 (is_true (is_diag_mx (scalar_mx _))) => apply: scalar_mx_is_diag : core. #[global] Hint Extern 0 (is_true (is_trig_mx (scalar_mx _))) => apply: scalar_mx_is_trig : core. #[global] Hint Extern 0 (is_true (is_diag_mx (diag_mx _))) => apply: diag_mx_is_diag : core. #[global] Hint Extern 0 (is_true (is_trig_mx (diag_mx _))) => apply: diag_mx_is_trig : core. Notation "a %:M" := (scalar_mx a) : ring_scope. Notation "A *m B" := (mulmx A B) : ring_scope. (* Non-commutative transpose requires multiplication in the converse ring. *) Lemma trmx_mul_rev (R : pzSemiRingType) m n p (A : 'M[R]_(m, n)) (B : 'M[R]_(n, p)) : (A *m B)^T = (B : 'M[R^c]_(n, p))^T *m (A : 'M[R^c]_(m, n))^T. Proof. by apply/matrixP=> k i /[!mxE]; apply: eq_bigr => j _ /[!mxE]. Qed. HB.instance Definition _ (R : pzRingType) m n := GRing.LSemiModule.on 'M[R]_(m, n). HB.instance Definition _ (R : pzRingType) n := GRing.PzSemiRing.on 'M[R]_n. Section MatrixNzSemiRing. Variables (R : nzSemiRingType) (n' : nat). Local Notation n := n'.+1. Lemma matrix_nonzero1 : 1%:M != 0 :> 'M[R]_n. Proof. by apply/eqP=> /matrixP/(_ 0 0)/eqP; rewrite !mxE oner_eq0. Qed. HB.instance Definition _ := GRing.PzSemiRing_isNonZero.Build 'M[R]_n matrix_nonzero1. HB.instance Definition _ := GRing.LSemiModule_isLSemiAlgebra.Build R 'M[R]_n (@scalemxAl R n n n). End MatrixNzSemiRing. HB.instance Definition _ (R : nzRingType) n := GRing.NzSemiRing.on 'M[R]_n.+1. HB.instance Definition _ (M : countNmodType) m n := [Countable of 'M[M]_(m, n) by <:]. HB.instance Definition _ (M : countZmodType) m n := [Countable of 'M[M]_(m, n) by <:]. HB.instance Definition _ (R : countNzSemiRingType) n := [Countable of 'M[R]_n.+1 by <:]. HB.instance Definition _ (R : countNzRingType) n := [Countable of 'M[R]_n.+1 by <:]. HB.instance Definition _ (V : finNmodType) (m n : nat) := [Finite of 'M[V]_(m, n) by <:]. HB.instance Definition _ (V : finZmodType) (m n : nat) := [Finite of 'M[V]_(m, n) by <:]. #[compress_coercions] HB.instance Definition _ (V : finZmodType) (m n : nat) := [finGroupMixin of 'M[V]_(m, n) for +%R]. #[compress_coercions] HB.instance Definition _ (R : finNzSemiRingType) n := [Finite of 'M[R]_n.+1 by <:]. #[compress_coercions] HB.instance Definition _ (R : finNzRingType) (m n : nat) := FinRing.Zmodule.on 'M[R]_(m, n). #[compress_coercions] HB.instance Definition _ (R : finNzRingType) n := [Finite of 'M[R]_n.+1 by <:]. (* Parametricity over the algebra structure. *) Section MapSemiRingMatrix. Variables (aR rR : pzSemiRingType) (f : {rmorphism aR -> rR}). Local Notation "A ^f" := (map_mx f A) : ring_scope. Section FixedSize. Variables m n p : nat. Implicit Type A : 'M[aR]_(m, n). Lemma map_mxZ a A : (a *: A)^f = f a *: A^f. Proof. by apply/matrixP=> i j; rewrite !mxE rmorphM. Qed. Lemma map_mxM A B : (A *m B)^f = A^f *m B^f :> 'M_(m, p). Proof. apply/matrixP=> i k; rewrite !mxE rmorph_sum //. by apply: eq_bigr => j; rewrite !mxE rmorphM. Qed. Lemma map_delta_mx i j : (delta_mx i j)^f = delta_mx i j :> 'M_(m, n). Proof. by apply/matrixP=> i' j'; rewrite !mxE rmorph_nat. Qed. Lemma map_diag_mx d : (diag_mx d)^f = diag_mx d^f :> 'M_n. Proof. by apply/matrixP=> i j; rewrite !mxE rmorphMn. Qed. Lemma map_scalar_mx a : a%:M^f = (f a)%:M :> 'M_n. Proof. by apply/matrixP=> i j; rewrite !mxE rmorphMn. Qed. Lemma map_mx1 : 1%:M^f = 1%:M :> 'M_n. Proof. by rewrite map_scalar_mx rmorph1. Qed. Lemma map_perm_mx (s : 'S_n) : (perm_mx s)^f = perm_mx s. Proof. by apply/matrixP=> i j; rewrite !mxE rmorph_nat. Qed. Lemma map_tperm_mx (i1 i2 : 'I_n) : (tperm_mx i1 i2)^f = tperm_mx i1 i2. Proof. exact: map_perm_mx. Qed. Lemma map_pid_mx r : (pid_mx r)^f = pid_mx r :> 'M_(m, n). Proof. by apply/matrixP=> i j; rewrite !mxE rmorph_nat. Qed. Lemma trace_map_mx (A : 'M_n) : \tr A^f = f (\tr A). Proof. by rewrite rmorph_sum; apply: eq_bigr => i _; rewrite mxE. Qed. End FixedSize. Lemma map_lin1_mx m n (g : 'rV_m -> 'rV_n) gf : (forall v, (g v)^f = gf v^f) -> (lin1_mx g)^f = lin1_mx gf. Proof. by move=> def_gf; apply/matrixP => i j; rewrite !mxE -map_delta_mx -def_gf mxE. Qed. Lemma map_lin_mx m1 n1 m2 n2 (g : 'M_(m1, n1) -> 'M_(m2, n2)) gf : (forall A, (g A)^f = gf A^f) -> (lin_mx g)^f = lin_mx gf. Proof. move=> def_gf; apply: map_lin1_mx => A /=. by rewrite map_mxvec def_gf map_vec_mx. Qed. Fact map_mx_is_monoid_morphism n : monoid_morphism (map_mx f : 'M_n -> 'M_n). Proof. by split; [apply: map_mx1 | apply: map_mxM]. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `map_mx_is_monoid_morphism` instead")] Definition map_mx_is_multiplicative := map_mx_is_monoid_morphism. HB.instance Definition _ n := GRing.isMonoidMorphism.Build 'M[aR]_n 'M[rR]_n (map_mx f) (map_mx_is_monoid_morphism n). End MapSemiRingMatrix. Section CommMx. (***********************************************************************) (************* Commutation property specialized to 'M[R]_n *************) (***********************************************************************) (* GRing.comm is bound to (non trivial) rings, and matrices form a *) (* (non trivial) ring only when they are square and of manifestly *) (* positive size. However during proofs in endomorphism reduction, we *) (* take restrictions, which are matrices of size #|V| (with V a matrix *) (* space) and it becomes cumbersome to state commutation between *) (* restrictions, unless we relax the setting, and this relaxation *) (* corresponds to comm_mx A B := A *m B = B *m A. *) (* As witnessed by comm_mxE, when A and B have type 'M_n.+1, *) (* comm_mx A B is convertible to GRing.comm A B. *) (* The boolean version comm_mxb is designed to be used with seq.allrel *) (***********************************************************************) Context {R : pzSemiRingType} {n : nat}. Implicit Types (f g p : 'M[R]_n) (fs : seq 'M[R]_n) (d : 'rV[R]_n) (I : Type). Definition comm_mx f g : Prop := f *m g = g *m f. Definition comm_mxb f g : bool := f *m g == g *m f. Lemma comm_mx_sym f g : comm_mx f g -> comm_mx g f. Proof. by rewrite /comm_mx. Qed. Lemma comm_mx_refl f : comm_mx f f. Proof. by []. Qed. Lemma comm_mx0 f : comm_mx f 0. Proof. by rewrite /comm_mx mulmx0 mul0mx. Qed. Lemma comm0mx f : comm_mx 0 f. Proof. by rewrite /comm_mx mulmx0 mul0mx. Qed. Lemma comm_mx1 f : comm_mx f 1%:M. Proof. by rewrite /comm_mx mulmx1 mul1mx. Qed. Lemma comm1mx f : comm_mx 1%:M f. Proof. by rewrite /comm_mx mulmx1 mul1mx. Qed. Hint Resolve comm_mx0 comm0mx comm_mx1 comm1mx : core. Lemma comm_mxD f g g' : comm_mx f g -> comm_mx f g' -> comm_mx f (g + g'). Proof. by rewrite /comm_mx mulmxDl mulmxDr => -> ->. Qed. Lemma comm_mxM f g g' : comm_mx f g -> comm_mx f g' -> comm_mx f (g *m g'). Proof. by rewrite /comm_mx mulmxA => ->; rewrite -!mulmxA => ->. Qed. Lemma comm_mx_sum I (s : seq I) (P : pred I) (F : I -> 'M[R]_n) (f : 'M[R]_n) : (forall i : I, P i -> comm_mx f (F i)) -> comm_mx f (\sum_(i <- s | P i) F i). Proof. by move=> comm_mxfF; elim/big_ind: _ => // g h; apply: comm_mxD. Qed. Lemma comm_mxP f g : reflect (comm_mx f g) (comm_mxb f g). Proof. exact: eqP. Qed. Notation all_comm_mx fs := (all2rel comm_mxb fs). Lemma all_comm_mxP fs : reflect {in fs &, forall f g, f *m g = g *m f} (all_comm_mx fs). Proof. by apply: (iffP allrelP) => fsP ? ? ? ?; apply/eqP/fsP. Qed. Lemma all_comm_mx1 f : all_comm_mx [:: f]. Proof. by rewrite /comm_mxb all2rel1. Qed. Lemma all_comm_mx2P f g : reflect (f *m g = g *m f) (all_comm_mx [:: f; g]). Proof. by rewrite /comm_mxb /= all2rel2 ?eqxx //; exact: eqP. Qed. Lemma all_comm_mx_cons f fs : all_comm_mx (f :: fs) = all (comm_mxb f) fs && all_comm_mx fs. Proof. by rewrite /comm_mxb /= all2rel_cons //= eqxx. Qed. Lemma comm_mxE : comm_mx = @GRing.comm _. Proof. by []. Qed. End CommMx. Notation all_comm_mx := (allrel comm_mxb). Section ComMatrix. (* Lemmas for matrices with coefficients in a commutative ring *) Variable R : comPzSemiRingType. Section AssocLeft. Variables m n p : nat. Implicit Type A : 'M[R]_(m, n). Implicit Type B : 'M[R]_(n, p). Lemma trmx_mul A B : (A *m B)^T = B^T *m A^T. Proof. rewrite trmx_mul_rev; apply/matrixP=> k i; rewrite !mxE. by apply: eq_bigr => j _; rewrite mulrC. Qed. Lemma scalemxAr a A B : a *: (A *m B) = A *m (a *: B). Proof. by apply: trmx_inj; rewrite trmx_mul !linearZ /= trmx_mul scalemxAl. Qed. Fact mulmx_is_scalable A : scalable (@mulmx _ m n p A). Proof. by move=> a B; rewrite scalemxAr. Qed. HB.instance Definition _ A := GRing.isScalable.Build R 'M[R]_(n, p) 'M[R]_(m, p) *:%R (mulmx A) (mulmx_is_scalable A). Definition lin_mulmx A : 'M[R]_(n * p, m * p) := lin_mx (mulmx A). Fact lin_mulmx_is_semilinear : semilinear lin_mulmx. Proof. by split=> [a A|A B]; apply/row_matrixP=> i; rewrite (linearZ, linearD) /=; rewrite !rowE !mul_rV_lin /= -(linearZ, linearD) /= (scalemxAl, mulmxDl). Qed. HB.instance Definition _ := GRing.isSemilinear.Build R 'M[R]_(m, n) 'M[R]_(n * p, m * p) _ lin_mulmx lin_mulmx_is_semilinear. End AssocLeft. Section LinMulRow. Variables m n : nat. Definition lin_mul_row u : 'M[R]_(m * n, n) := lin1_mx (mulmx u \o vec_mx). Fact lin_mul_row_is_semilinear : semilinear lin_mul_row. Proof. by split=> [a u|u v]; apply/row_matrixP=> i; rewrite (linearZ, linearD) /=; rewrite !rowE !mul_rV_lin1 /= (mulmxDl, scalemxAl). Qed. HB.instance Definition _ := GRing.isSemilinear.Build R _ _ _ lin_mul_row lin_mul_row_is_semilinear. Lemma mul_vec_lin_row A u : mxvec A *m lin_mul_row u = u *m A. Proof. by rewrite mul_rV_lin1 /= mxvecK. Qed. End LinMulRow. Lemma diag_mxC n (d e : 'rV[R]_n) : diag_mx d *m diag_mx e = diag_mx e *m diag_mx d. Proof. by rewrite !mulmx_diag; congr (diag_mx _); apply/rowP=> i; rewrite !mxE mulrC. Qed. Lemma diag_mx_comm n (d e : 'rV[R]_n) : comm_mx (diag_mx d) (diag_mx e). Proof. exact: diag_mxC. Qed. Lemma scalar_mxC m n a (A : 'M[R]_(m, n)) : A *m a%:M = a%:M *m A. Proof. rewrite -!diag_const_mx mul_mx_diag mul_diag_mx. by apply/matrixP => i j; rewrite !mxE mulrC. Qed. Lemma comm_mx_scalar n a (A : 'M[R]_n) : comm_mx A a%:M. Proof. exact: scalar_mxC. Qed. Lemma comm_scalar_mx n a (A : 'M[R]_n) : comm_mx a%:M A. Proof. exact/comm_mx_sym/comm_mx_scalar. Qed. Lemma mxtrace_mulC m n (A : 'M[R]_(m, n)) B : \tr (A *m B) = \tr (B *m A). Proof. have expand_trM C D: \tr (C *m D) = \sum_i \sum_j C i j * D j i. by apply: eq_bigr => i _; rewrite mxE. rewrite !{}expand_trM exchange_big /=. by do 2!apply: eq_bigr => ? _; apply: mulrC. Qed. Lemma mxvec_dotmul m n (A : 'M[R]_(m, n)) u v : mxvec (u^T *m v) *m (mxvec A)^T = u *m A *m v^T. Proof. transitivity (\sum_i \sum_j (u 0 i * A i j *: row j v^T)). apply/rowP=> i; rewrite {i}ord1 mxE (reindex _ (curry_mxvec_bij _ _)) /=. rewrite pair_bigA summxE; apply: eq_bigr => [[i j]] /= _. by rewrite !mxE !mxvecE mxE big_ord1 mxE mulrAC. rewrite mulmx_sum_row exchange_big; apply: eq_bigr => j _ /=. by rewrite mxE -scaler_suml. Qed. Lemma mul_mx_scalar m n a (A : 'M[R]_(m, n)) : A *m a%:M = a *: A. Proof. by rewrite scalar_mxC mul_scalar_mx. Qed. End ComMatrix. Arguments lin_mulmx {R m n p} A. Arguments lin_mul_row {R m n} u. Arguments diag_mx_comm {R n}. Arguments comm_mx_scalar {R n}. Arguments comm_scalar_mx {R n}. #[global] Hint Resolve comm_mx_scalar comm_scalar_mx : core. Section MatrixAlgebra. Variable R : pzRingType. (* Diagonal matrices *) #[deprecated(since="mathcomp 2.5.0", note="use `linearP` instead")] Fact diag_mx_is_linear n : linear (@diag_mx R n). Proof. exact: linearP. Qed. (* Scalar matrix *) Lemma mulmxN m n p (A : 'M[R]_(m, n)) (B : 'M_(n, p)) : A *m (- B) = - (A *m B). Proof. exact: raddfN. Qed. Lemma mulNmx m n p (A : 'M[R]_(m, n)) (B : 'M_(n, p)) : - A *m B = - (A *m B). Proof. exact: (raddfN (mulmxr _)). Qed. Lemma mulmxBl m n p (A1 A2 : 'M[R]_(m, n)) (B : 'M_(n, p)) : (A1 - A2) *m B = A1 *m B - A2 *m B. Proof. exact: (raddfB (mulmxr _)). Qed. Lemma mulmxBr m n p (A : 'M[R]_(m, n)) (B1 B2 : 'M_(n, p)) : A *m (B1 - B2) = A *m B1 - A *m B2. Proof. exact: raddfB. Qed. (* Partial identity matrix (used in rank decomposition). *) Definition copid_mx {n} r : 'M[R]_n := 1%:M - pid_mx r. Lemma mul_copid_mx_pid m n r : r <= m -> copid_mx r *m pid_mx r = 0 :> 'M_(m, n). Proof. by move=> le_r_m; rewrite mulmxBl mul1mx pid_mx_id ?subrr. Qed. Lemma mul_pid_mx_copid m n r : r <= n -> pid_mx r *m copid_mx r = 0 :> 'M_(m, n). Proof. by move=> le_r_n; rewrite mulmxBr mulmx1 pid_mx_id ?subrr. Qed. Lemma copid_mx_id n r : r <= n -> copid_mx r *m copid_mx r = copid_mx r :> 'M_n. Proof. by move=> le_r_n; rewrite mulmxBl mul1mx mul_pid_mx_copid // oppr0 addr0. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `linearP` instead")] Fact mulmxr_is_linear m n p B : linear (@mulmxr R m n p B). Proof. exact: linearP. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `linearP` instead")] Fact lin_mulmxr_is_linear m n p : linear (@lin_mulmxr R m n p). Proof. exact: linearP. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `scalarP` instead")] Fact mxtrace_is_scalar n : scalar (@mxtrace R n). Proof. exact: scalarP. Qed. (* Determinants and adjugates are defined here, but most of their properties *) (* only hold for matrices over a commutative ring, so their theory is *) (* deferred to that section. *) (* The determinant, in one line with the Leibniz Formula *) Definition determinant n (A : 'M_n) : R := \sum_(s : 'S_n) (-1) ^+ s * \prod_i A i (s i). (* The cofactor of a matrix on the indexes i and j *) Definition cofactor n A (i j : 'I_n) : R := (-1) ^+ (i + j) * determinant (row' i (col' j A)). (* The adjugate matrix : defined as the transpose of the matrix of cofactors *) Fact adjugate_key : unit. Proof. by []. Qed. Definition adjugate n (A : 'M_n) := \matrix[adjugate_key]_(i, j) cofactor A j i. End MatrixAlgebra. Arguments copid_mx {R n}. Prenex Implicits determinant cofactor adjugate. Notation "'\det' A" := (determinant A) : ring_scope. Notation "'\adj' A" := (adjugate A) : ring_scope. (* Parametricity over the algebra structure. *) Section MapRingMatrix. Variables (aR rR : pzRingType) (f : {rmorphism aR -> rR}). Local Notation "A ^f" := (map_mx f A) : ring_scope. Section FixedSize. Variables m n p : nat. Implicit Type A : 'M[aR]_(m, n). Lemma det_map_mx n' (A : 'M_n') : \det A^f = f (\det A). Proof. rewrite rmorph_sum //; apply: eq_bigr => s _. rewrite rmorphM /= rmorph_sign rmorph_prod; congr (_ * _). by apply: eq_bigr => i _; rewrite mxE. Qed. Lemma cofactor_map_mx (A : 'M_n) i j : cofactor A^f i j = f (cofactor A i j). Proof. by rewrite rmorphM /= rmorph_sign -det_map_mx map_row' map_col'. Qed. Lemma map_mx_adj (A : 'M_n) : (\adj A)^f = \adj A^f. Proof. by apply/matrixP=> i j; rewrite !mxE cofactor_map_mx. Qed. End FixedSize. Lemma map_copid_mx n r : (copid_mx r)^f = copid_mx r :> 'M_n. Proof. by rewrite map_mxB map_mx1 map_pid_mx. Qed. End MapRingMatrix. Section CommMx. (***********************************************************************) (************* Commutation property specialized to 'M[R]_n *************) (***********************************************************************) (* See comment on top of NzSemiRing section CommMx above. *) (***********************************************************************) Context {R : pzRingType} {n : nat}. Implicit Types (f g p : 'M[R]_n) (fs : seq 'M[R]_n) (d : 'rV[R]_n) (I : Type). Lemma comm_mxN f g : comm_mx f g -> comm_mx f (- g). Proof. by rewrite /comm_mx mulmxN mulNmx => ->. Qed. Lemma comm_mxN1 f : comm_mx f (- 1%:M). Proof. exact/comm_mxN/comm_mx1. Qed. Lemma comm_mxB f g g' : comm_mx f g -> comm_mx f g' -> comm_mx f (g - g'). Proof. by move=> fg fg'; apply/comm_mxD => //; apply/comm_mxN. Qed. End CommMx. (* Lemmas for matrices with coefficients in a commutative ring *) Section ComMatrix. Variable R : comPzRingType. #[deprecated(since="mathcomp 2.5.0", note="use `linearP` instead")] Fact lin_mulmx_is_linear m n p : linear (@lin_mulmx R m n p). Proof. exact: linearP. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `linearP` instead")] Fact lin_mul_row_is_linear m n : linear (@lin_mul_row R m n). Proof. exact: linearP. Qed. (* The theory of determinants *) Lemma determinant_multilinear n (A B C : 'M[R]_n) i0 b c : row i0 A = b *: row i0 B + c *: row i0 C -> row' i0 B = row' i0 A -> row' i0 C = row' i0 A -> \det A = b * \det B + c * \det C. Proof. rewrite -[_ + _](row_id 0); move/row_eq=> ABC. move/row'_eq=> BA; move/row'_eq=> CA. rewrite !big_distrr -big_split; apply: eq_bigr => s _ /=. rewrite -!(mulrCA (_ ^+s)) -mulrDr; congr (_ * _). rewrite !(bigD1 i0 (_ : predT i0)) //= {}ABC !mxE mulrDl !mulrA. by congr (_ * _ + _ * _); apply: eq_bigr => i i0i; rewrite ?BA ?CA. Qed. Lemma determinant_alternate n (A : 'M[R]_n) i1 i2 : i1 != i2 -> A i1 =1 A i2 -> \det A = 0. Proof. move=> neq_i12 eqA12; pose t := tperm i1 i2. have oddMt s: (t * s)%g = ~~ s :> bool by rewrite odd_permM odd_tperm neq_i12. rewrite [\det A](bigID (@odd_perm _)) /=. apply: canLR (subrK _) _; rewrite add0r -sumrN. rewrite (reindex_inj (mulgI t)); apply: eq_big => //= s. rewrite oddMt => /negPf->; rewrite mulN1r mul1r; congr (- _). rewrite (reindex_perm t); apply: eq_bigr => /= i _. by rewrite permM tpermK /t; case: tpermP => // ->; rewrite eqA12. Qed. Lemma det_tr n (A : 'M[R]_n) : \det A^T = \det A. Proof. rewrite [\det A^T](reindex_inj invg_inj) /=. apply: eq_bigr => s _ /=; rewrite !odd_permV (reindex_perm s) /=. by congr (_ * _); apply: eq_bigr => i _; rewrite mxE permK. Qed. Lemma det_perm n (s : 'S_n) : \det (perm_mx s) = (-1) ^+ s :> R. Proof. rewrite [\det _](bigD1 s) //= big1 => [|i _]; last by rewrite /= !mxE eqxx. rewrite mulr1 big1 ?addr0 => //= t Dst. case: (pickP (fun i => s i != t i)) => [i ist | Est]. by rewrite (bigD1 i) // mulrCA /= !mxE (negPf ist) mul0r. by case/eqP: Dst; apply/permP => i; move/eqP: (Est i). Qed. Lemma det1 n : \det (1%:M : 'M[R]_n) = 1. Proof. by rewrite -perm_mx1 det_perm odd_perm1. Qed. Lemma det_mx00 (A : 'M[R]_0) : \det A = 1. Proof. by rewrite flatmx0 -(flatmx0 1%:M) det1. Qed. Lemma detZ n a (A : 'M[R]_n) : \det (a *: A) = a ^+ n * \det A. Proof. rewrite big_distrr /=; apply: eq_bigr => s _; rewrite mulrCA; congr (_ * _). rewrite -[n in a ^+ n]card_ord -prodr_const -big_split /=. by apply: eq_bigr=> i _; rewrite mxE. Qed. Lemma det0 n' : \det (0 : 'M[R]_n'.+1) = 0. Proof. by rewrite -(scale0r 0) detZ exprS !mul0r. Qed. Lemma det_scalar n a : \det (a%:M : 'M[R]_n) = a ^+ n. Proof. by rewrite -{1}(mulr1 a) -scale_scalar_mx detZ det1 mulr1. Qed. Lemma det_scalar1 a : \det (a%:M : 'M[R]_1) = a. Proof. exact: det_scalar. Qed. Lemma det_mx11 (M : 'M[R]_1) : \det M = M 0 0. Proof. by rewrite {1}[M]mx11_scalar det_scalar. Qed. Lemma det_mulmx n (A B : 'M[R]_n) : \det (A *m B) = \det A * \det B. Proof. rewrite big_distrl /=. pose F := ('I_n ^ n)%type; pose AB s i j := A i j * B j (s i). transitivity (\sum_(f : F) \sum_(s : 'S_n) (-1) ^+ s * \prod_i AB s i (f i)). rewrite exchange_big; apply: eq_bigr => /= s _; rewrite -big_distrr /=. congr (_ * _); rewrite -(bigA_distr_bigA (AB s)) /=. by apply: eq_bigr => x _; rewrite mxE. rewrite (bigID (fun f : F => injectiveb f)) /= addrC big1 ?add0r => [|f Uf]. rewrite (reindex (@pval _)) /=; last first. pose in_Sn := insubd (1%g : 'S_n). by exists in_Sn => /= f Uf; first apply: val_inj; apply: insubdK. apply: eq_big => /= [s | s _]; rewrite ?(valP s) // big_distrr /=. rewrite (reindex_inj (mulgI s)); apply: eq_bigr => t _ /=. rewrite big_split /= [in LHS]mulrA mulrCA mulrA mulrCA mulrA. rewrite -signr_addb odd_permM !pvalE; congr (_ * _); symmetry. by rewrite (reindex_perm s); apply: eq_bigr => i; rewrite permM. transitivity (\det (\matrix_(i, j) B (f i) j) * \prod_i A i (f i)). rewrite mulrC big_distrr /=; apply: eq_bigr => s _. rewrite mulrCA big_split //=; congr (_ * (_ * _)). by apply: eq_bigr => x _; rewrite mxE. case/injectivePn: Uf => i1 [i2 Di12 Ef12]. by rewrite (determinant_alternate Di12) ?simp //= => j; rewrite !mxE Ef12. Qed. Lemma detM n' (A B : 'M[R]_n'.+1) : \det (A * B) = \det A * \det B. Proof. exact: det_mulmx. Qed. (* Laplace expansion lemma *) Lemma expand_cofactor n (A : 'M[R]_n) i j : cofactor A i j = \sum_(s : 'S_n | s i == j) (-1) ^+ s * \prod_(k | i != k) A k (s k). Proof. case: n A i j => [|n] A i0 j0; first by case: i0. rewrite (reindex (lift_perm i0 j0)); last first. pose ulsf i (s : 'S_n.+1) k := odflt k (unlift (s i) (s (lift i k))). have ulsfK i (s : 'S_n.+1) k: lift (s i) (ulsf i s k) = s (lift i k). rewrite /ulsf; have:= neq_lift i k. by rewrite -(can_eq (permK s)) => /unlift_some[] ? ? ->. have inj_ulsf: injective (ulsf i0 _). move=> s; apply: can_inj (ulsf (s i0) s^-1%g) _ => k'. by rewrite {1}/ulsf ulsfK !permK liftK. exists (fun s => perm (inj_ulsf s)) => [s _ | s]. by apply/permP=> k'; rewrite permE /ulsf lift_perm_lift lift_perm_id liftK. move/(s _ =P _) => si0; apply/permP=> k. case: (unliftP i0 k) => [k'|] ->; rewrite ?lift_perm_id //. by rewrite lift_perm_lift -si0 permE ulsfK. rewrite /cofactor big_distrr /=. apply: eq_big => [s | s _]; first by rewrite lift_perm_id eqxx. rewrite -signr_odd mulrA -signr_addb oddD -odd_lift_perm; congr (_ * _). case: (pickP 'I_n) => [k0 _ | n0]; last first. by rewrite !big1 // => [j /unlift_some[i] | i _]; have:= n0 i. rewrite (reindex (lift i0)). by apply: eq_big => [k | k _] /=; rewrite ?neq_lift // !mxE lift_perm_lift. exists (fun k => odflt k0 (unlift i0 k)) => k; first by rewrite liftK. by case/unlift_some=> k' -> ->. Qed. Lemma expand_det_row n (A : 'M[R]_n) i0 : \det A = \sum_j A i0 j * cofactor A i0 j. Proof. rewrite /(\det A) (partition_big (fun s : 'S_n => s i0) predT) //=. apply: eq_bigr => j0 _; rewrite expand_cofactor big_distrr /=. apply: eq_bigr => s /eqP Dsi0. rewrite mulrCA (bigID (pred1 i0)) /= big_pred1_eq Dsi0; congr (_ * (_ * _)). by apply: eq_bigl => i; rewrite eq_sym. Qed. Lemma cofactor_tr n (A : 'M[R]_n) i j : cofactor A^T i j = cofactor A j i. Proof. rewrite /cofactor addnC; congr (_ * _). rewrite -tr_row' -tr_col' det_tr; congr (\det _). by apply/matrixP=> ? ?; rewrite !mxE. Qed. Lemma cofactorZ n a (A : 'M[R]_n) i j : cofactor (a *: A) i j = a ^+ n.-1 * cofactor A i j. Proof. by rewrite {1}/cofactor !linearZ detZ mulrCA mulrA. Qed. Lemma expand_det_col n (A : 'M[R]_n) j0 : \det A = \sum_i (A i j0 * cofactor A i j0). Proof. rewrite -det_tr (expand_det_row _ j0). by under eq_bigr do rewrite cofactor_tr mxE. Qed. Lemma trmx_adj n (A : 'M[R]_n) : (\adj A)^T = \adj A^T. Proof. by apply/matrixP=> i j; rewrite !mxE cofactor_tr. Qed. Lemma adjZ n a (A : 'M[R]_n) : \adj (a *: A) = a^+n.-1 *: \adj A. Proof. by apply/matrixP=> i j; rewrite !mxE cofactorZ. Qed. (* Cramer Rule : adjugate on the left *) Lemma mul_mx_adj n (A : 'M[R]_n) : A *m \adj A = (\det A)%:M. Proof. apply/matrixP=> i1 i2 /[!mxE]; have [->|Di] := eqVneq. rewrite (expand_det_row _ i2) //=. by apply: eq_bigr => j _; congr (_ * _); rewrite mxE. pose B := \matrix_(i, j) (if i == i2 then A i1 j else A i j). have EBi12: B i1 =1 B i2 by move=> j; rewrite /= !mxE eqxx (negPf Di). rewrite -[_ *+ _](determinant_alternate Di EBi12) (expand_det_row _ i2). apply: eq_bigr => j _; rewrite !mxE eqxx; congr (_ * (_ * _)). apply: eq_bigr => s _; congr (_ * _); apply: eq_bigr => i _. by rewrite !mxE eq_sym -if_neg neq_lift. Qed. (* Cramer rule : adjugate on the right *) Lemma mul_adj_mx n (A : 'M[R]_n) : \adj A *m A = (\det A)%:M. Proof. by apply: trmx_inj; rewrite trmx_mul trmx_adj mul_mx_adj det_tr tr_scalar_mx. Qed. Lemma adj1 n : \adj (1%:M) = 1%:M :> 'M[R]_n. Proof. by rewrite -{2}(det1 n) -mul_adj_mx mulmx1. Qed. (* Left inverses are right inverses. *) Lemma mulmx1C n (A B : 'M[R]_n) : A *m B = 1%:M -> B *m A = 1%:M. Proof. move=> AB1; pose A' := \det B *: \adj A. suffices kA: A' *m A = 1%:M by rewrite -[B]mul1mx -kA -(mulmxA A') AB1 mulmx1. by rewrite -scalemxAl mul_adj_mx scale_scalar_mx mulrC -det_mulmx AB1 det1. Qed. Lemma det_ublock n1 n2 Aul (Aur : 'M[R]_(n1, n2)) Adr : \det (block_mx Aul Aur 0 Adr) = \det Aul * \det Adr. Proof. elim: n1 => [|n1 IHn1] in Aul Aur *. have ->: Aul = 1%:M by apply/matrixP=> i []. rewrite det1 mul1r; congr (\det _); apply/matrixP=> i j. by do 2![rewrite !mxE; case: splitP => [[]|k] //=; move/val_inj=> <- {k}]. rewrite (expand_det_col _ (lshift n2 0)) big_split_ord /=. rewrite addrC big1 1?simp => [|i _]; last by rewrite block_mxEdl mxE simp. rewrite (expand_det_col _ 0) big_distrl /=; apply: eq_bigr=> i _. rewrite block_mxEul -!mulrA; do 2!congr (_ * _). by rewrite col'_col_mx !col'Kl raddf0 row'Ku row'_row_mx IHn1. Qed. Lemma det_lblock n1 n2 Aul (Adl : 'M[R]_(n2, n1)) Adr : \det (block_mx Aul 0 Adl Adr) = \det Aul * \det Adr. Proof. by rewrite -det_tr tr_block_mx trmx0 det_ublock !det_tr. Qed. Lemma det_trig n (A : 'M[R]_n) : is_trig_mx A -> \det A = \prod_(i < n) A i i. Proof. elim/trigsqmx_ind => [|k x c B Bt IHB]; first by rewrite ?big_ord0 ?det_mx00. rewrite det_lblock big_ord_recl det_mx11 IHB//; congr (_ * _). by rewrite -[ord0](lshift0 _ 0) block_mxEul. by apply: eq_bigr => i; rewrite -!rshift1 block_mxEdr. Qed. Lemma det_diag n (d : 'rV[R]_n) : \det (diag_mx d) = \prod_i d 0 i. Proof. by rewrite det_trig//; apply: eq_bigr => i; rewrite !mxE eqxx. Qed. End ComMatrix. Arguments lin_mul_row {R m n} u. Arguments lin_mulmx {R m n p} A. HB.instance Definition _ (R : comNzSemiRingType) n := GRing.LSemiAlgebra_isSemiAlgebra.Build R 'M[R]_n.+1 (fun k => scalemxAr k). HB.instance Definition _ (R : comNzRingType) (n' : nat) := GRing.LSemiAlgebra.on 'M[R]_n'.+1. HB.instance Definition _ (R : finComNzRingType) (n' : nat) := [Finite of 'M[R]_n'.+1 by <:]. (* Only tall matrices have inverses. *) Lemma mulmx1_min (R : comNzRingType) m n (A : 'M[R]_(m, n)) B : A *m B = 1%:M -> m <= n. Proof. move=> AB1; rewrite leqNgt; apply/negP=> /subnKC; rewrite addSnnS. move: (_ - _)%N => m' def_m; move: AB1; rewrite -{m}def_m in A B *. rewrite -(vsubmxK A) -(hsubmxK B) mul_col_row scalar_mx_block. case/eq_block_mx=> /mulmx1C BlAu1 AuBr0 _ => /eqP/idPn[]. by rewrite -[_ B]mul1mx -BlAu1 -mulmxA AuBr0 !mulmx0 eq_sym oner_neq0. Qed. (*****************************************************************************) (********************** Matrix unit ring and inverse matrices ****************) (*****************************************************************************) Section MatrixInv. Variables R : comUnitRingType. Section Defs. Variable n : nat. Implicit Type A : 'M[R]_n. Definition unitmx : pred 'M[R]_n := fun A => \det A \is a GRing.unit. Definition invmx A := if A \in unitmx then (\det A)^-1 *: \adj A else A. Lemma unitmxE A : (A \in unitmx) = (\det A \is a GRing.unit). Proof. by []. Qed. Lemma unitmx1 : 1%:M \in unitmx. Proof. by rewrite unitmxE det1 unitr1. Qed. Lemma unitmx_perm s : perm_mx s \in unitmx. Proof. by rewrite unitmxE det_perm unitrX ?unitrN ?unitr1. Qed. Lemma unitmx_tr A : (A^T \in unitmx) = (A \in unitmx). Proof. by rewrite unitmxE det_tr. Qed. Lemma unitmxZ a A : a \is a GRing.unit -> (a *: A \in unitmx) = (A \in unitmx). Proof. by move=> Ua; rewrite !unitmxE detZ unitrM unitrX. Qed. Lemma invmx1 : invmx 1%:M = 1%:M. Proof. by rewrite /invmx det1 invr1 scale1r adj1 if_same. Qed. Lemma invmxZ a A : a *: A \in unitmx -> invmx (a *: A) = a^-1 *: invmx A. Proof. rewrite /invmx !unitmxE detZ unitrM => /andP[Ua U_A]. rewrite Ua U_A adjZ !scalerA invrM {U_A}//=. case: (posnP n) A => [-> | n_gt0] A; first by rewrite flatmx0 [_ *: _]flatmx0. rewrite unitrX_pos // in Ua; rewrite -[_ * _](mulrK Ua) mulrC -!mulrA. by rewrite -exprSr prednK // !mulrA divrK ?unitrX. Qed. Lemma invmx_scalar a : invmx a%:M = a^-1%:M. Proof. case Ua: (a%:M \in unitmx). by rewrite -scalemx1 in Ua *; rewrite invmxZ // invmx1 scalemx1. rewrite /invmx Ua; have [->|n_gt0] := posnP n; first by rewrite ![_%:M]flatmx0. by rewrite unitmxE det_scalar unitrX_pos // in Ua; rewrite invr_out ?Ua. Qed. Lemma mulVmx : {in unitmx, left_inverse 1%:M invmx mulmx}. Proof. by move=> A nsA; rewrite /invmx nsA -scalemxAl mul_adj_mx scale_scalar_mx mulVr. Qed. Lemma mulmxV : {in unitmx, right_inverse 1%:M invmx mulmx}. Proof. by move=> A nsA; rewrite /invmx nsA -scalemxAr mul_mx_adj scale_scalar_mx mulVr. Qed. Lemma mulKmx m : {in unitmx, @left_loop _ 'M_(n, m) invmx mulmx}. Proof. by move=> A uA /= B; rewrite mulmxA mulVmx ?mul1mx. Qed. Lemma mulKVmx m : {in unitmx, @rev_left_loop _ 'M_(n, m) invmx mulmx}. Proof. by move=> A uA /= B; rewrite mulmxA mulmxV ?mul1mx. Qed. Lemma mulmxK m : {in unitmx, @right_loop 'M_(m, n) _ invmx mulmx}. Proof. by move=> A uA /= B; rewrite -mulmxA mulmxV ?mulmx1. Qed. Lemma mulmxKV m : {in unitmx, @rev_right_loop 'M_(m, n) _ invmx mulmx}. Proof. by move=> A uA /= B; rewrite -mulmxA mulVmx ?mulmx1. Qed. Lemma det_inv A : \det (invmx A) = (\det A)^-1. Proof. case uA: (A \in unitmx); last by rewrite /invmx uA invr_out ?negbT. by apply: (mulrI uA); rewrite -det_mulmx mulmxV ?divrr ?det1. Qed. Lemma unitmx_inv A : (invmx A \in unitmx) = (A \in unitmx). Proof. by rewrite !unitmxE det_inv unitrV. Qed. Lemma unitmx_mul A B : (A *m B \in unitmx) = (A \in unitmx) && (B \in unitmx). Proof. by rewrite -unitrM -det_mulmx. Qed. Lemma trmx_inv (A : 'M_n) : (invmx A)^T = invmx (A^T). Proof. by rewrite (fun_if trmx) linearZ /= trmx_adj -unitmx_tr -det_tr. Qed. Lemma invmxK : involutive invmx. Proof. move=> A; case uA : (A \in unitmx); last by rewrite /invmx !uA. by apply: (can_inj (mulKVmx uA)); rewrite mulVmx // mulmxV ?unitmx_inv. Qed. Lemma mulmx1_unit A B : A *m B = 1%:M -> A \in unitmx /\ B \in unitmx. Proof. by move=> AB1; apply/andP; rewrite -unitmx_mul AB1 unitmx1. Qed. Lemma intro_unitmx A B : B *m A = 1%:M /\ A *m B = 1%:M -> unitmx A. Proof. by case=> _ /mulmx1_unit[]. Qed. Lemma invmx_out : {in [predC unitmx], invmx =1 id}. Proof. by move=> A; rewrite inE /= /invmx -if_neg => ->. Qed. End Defs. Variable n' : nat. Local Notation n := n'.+1. HB.instance Definition _ := GRing.NzRing_hasMulInverse.Build 'M[R]_n (@mulVmx n) (@mulmxV n) (@intro_unitmx n) (@invmx_out n). (* Lemmas requiring that the coefficients are in a unit ring *) Lemma detV (A : 'M_n) : \det A^-1 = (\det A)^-1. Proof. exact: det_inv. Qed. Lemma unitr_trmx (A : 'M_n) : (A^T \is a GRing.unit) = (A \is a GRing.unit). Proof. exact: unitmx_tr. Qed. Lemma trmxV (A : 'M_n) : A^-1^T = (A^T)^-1. Proof. exact: trmx_inv. Qed. Lemma perm_mxV (s : 'S_n) : perm_mx s^-1 = (perm_mx s)^-1. Proof. rewrite -[_^-1]mul1r; apply: (canRL (mulmxK (unitmx_perm s))). by rewrite -perm_mxM mulVg perm_mx1. Qed. Lemma is_perm_mxV (A : 'M_n) : is_perm_mx A^-1 = is_perm_mx A. Proof. apply/is_perm_mxP/is_perm_mxP=> [] [s defA]; exists s^-1%g. by rewrite -(invrK A) defA perm_mxV. by rewrite defA perm_mxV. Qed. End MatrixInv. Prenex Implicits unitmx invmx invmxK. Lemma block_diag_mx_unit (R : comUnitRingType) n1 n2 (Aul : 'M[R]_n1) (Adr : 'M[R]_n2) : (block_mx Aul 0 0 Adr \in unitmx) = (Aul \in unitmx) && (Adr \in unitmx). Proof. by rewrite !unitmxE det_ublock unitrM. Qed. Lemma invmx_block_diag (R : comUnitRingType) n1 n2 (Aul : 'M[R]_n1) (Adr : 'M[R]_n2) : block_mx Aul 0 0 Adr \in unitmx -> invmx (block_mx Aul 0 0 Adr) = block_mx (invmx Aul) 0 0 (invmx Adr). Proof. move=> /[dup] Aunit; rewrite block_diag_mx_unit => /andP[Aul_unit Adr_unit]. rewrite -[LHS]mul1mx; apply: (canLR (mulmxK _)) => //. rewrite [RHS](mulmx_block (invmx Aul)) !(mulmx0, mul0mx, add0r, addr0). by rewrite !mulVmx// -?scalar_mx_block. Qed. HB.instance Definition _ (R : countComUnitRingType) (n' : nat) := [Countable of 'M[R]_n'.+1 by <:]. HB.instance Definition _ (n : nat) (R : finComUnitRingType) := [Finite of 'M[R]_n.+1 by <:]. (* Finite inversible matrices and the general linear group. *) Section FinUnitMatrix. Variable n : nat. Definition GLtype (R : finComUnitRingType) := {unit 'M[R]_n.-1.+1}. Coercion GLval R (u : GLtype R) : 'M[R]_n.-1.+1 := let: FinRing.Unit A _ := u in A. End FinUnitMatrix. Bind Scope group_scope with GLtype. Arguments GLtype n%_N R%_type. Arguments GLval {n%_N R} u%_g. Notation "{ ''GL_' n [ R ] }" := (GLtype n R) : type_scope. Notation "{ ''GL_' n ( p ) }" := {'GL_n['F_p]} : type_scope. HB.instance Definition _ (n : nat) (R : finComUnitRingType) := [isSub of {'GL_n[R]} for GLval]. Section GL_unit. Variables (n : nat) (R : finComUnitRingType). HB.instance Definition _ := [Finite of {'GL_n[R]} by <:]. HB.instance Definition _ := FinGroup.on {'GL_n[R]}. Definition GLgroup := [set: {'GL_n[R]}]. Canonical GLgroup_group := Eval hnf in [group of GLgroup]. Implicit Types u v : {'GL_n[R]}. Lemma GL_1E : GLval 1 = 1. Proof. by []. Qed. Lemma GL_VE u : GLval u^-1 = (GLval u)^-1. Proof. by []. Qed. Lemma GL_VxE u : GLval u^-1 = invmx u. Proof. by []. Qed. Lemma GL_ME u v : GLval (u * v) = GLval u * GLval v. Proof. by []. Qed. Lemma GL_MxE u v : GLval (u * v) = u *m v. Proof. by []. Qed. Lemma GL_unit u : GLval u \is a GRing.unit. Proof. exact: valP. Qed. Lemma GL_unitmx u : val u \in unitmx. Proof. exact: GL_unit. Qed. Lemma GL_det u : \det u != 0. Proof. by apply: contraL (GL_unitmx u); rewrite unitmxE => /eqP->; rewrite unitr0. Qed. End GL_unit. Arguments GLgroup n%_N R%_type. Arguments GLgroup_group n%_N R%_type. Notation "''GL_' n [ R ]" := (GLgroup n R) (n at level 2, format "''GL_' n [ R ]") : group_scope. Notation "''GL_' n ( p )" := 'GL_n['F_p] (p at level 10, format "''GL_' n ( p )") : group_scope. Notation "''GL_' n [ R ]" := (GLgroup_group n R) : Group_scope. Notation "''GL_' n ( p )" := (GLgroup_group n 'F_p) : Group_scope. (*****************************************************************************) (********************** Matrices over a domain *******************************) (*****************************************************************************) Section MatrixDomain. Variable R : idomainType. Lemma scalemx_eq0 m n a (A : 'M[R]_(m, n)) : (a *: A == 0) = (a == 0) || (A == 0). Proof. case nz_a: (a == 0) / eqP => [-> | _]; first by rewrite scale0r eqxx. apply/eqP/eqP=> [aA0 | ->]; last exact: scaler0. apply/matrixP=> i j; apply/eqP; move/matrixP/(_ i j)/eqP: aA0. by rewrite !mxE mulf_eq0 nz_a. Qed. Lemma scalemx_inj m n a : a != 0 -> injective ( *:%R a : 'M[R]_(m, n) -> 'M[R]_(m, n)). Proof. move=> nz_a A B eq_aAB; apply: contraNeq nz_a. rewrite -[A == B]subr_eq0 -[a == 0]orbF => /negPf<-. by rewrite -scalemx_eq0 linearB subr_eq0 /= eq_aAB. Qed. Lemma det0P n (A : 'M[R]_n) : reflect (exists2 v : 'rV[R]_n, v != 0 & v *m A = 0) (\det A == 0). Proof. apply: (iffP eqP) => [detA0 | [v n0v vA0]]; last first. apply: contraNeq n0v => nz_detA; rewrite -(inj_eq (scalemx_inj nz_detA)). by rewrite scaler0 -mul_mx_scalar -mul_mx_adj mulmxA vA0 mul0mx. elim: n => [|n IHn] in A detA0 *. by case/idP: (oner_eq0 R); rewrite -detA0 [A]thinmx0 -(thinmx0 1%:M) det1. have [{detA0}A'0 | nzA'] := eqVneq (row 0 (\adj A)) 0; last first. exists (row 0 (\adj A)) => //; rewrite rowE -mulmxA mul_adj_mx detA0. by rewrite mul_mx_scalar scale0r. pose A' := col' 0 A; pose vA := col 0 A. have defA: A = row_mx vA A'. apply/matrixP=> i j /[!mxE]. by case: split_ordP => j' -> /[!(mxE, ord1)]; congr (A i _); apply: val_inj. have{IHn} w_ j : exists w : 'rV_n.+1, [/\ w != 0, w 0 j = 0 & w *m A' = 0]. have [|wj nzwj wjA'0] := IHn (row' j A'). by apply/eqP; move/rowP/(_ j)/eqP: A'0; rewrite !mxE mulf_eq0 signr_eq0. exists (\row_k oapp (wj 0) 0 (unlift j k)). rewrite !mxE unlift_none -wjA'0; split=> //. apply: contraNneq nzwj => w0; apply/eqP/rowP=> k'. by move/rowP/(_ (lift j k')): w0; rewrite !mxE liftK. apply/rowP=> k; rewrite !mxE (bigD1_ord j) //= mxE unlift_none mul0r add0r. by apply: eq_big => //= k'; rewrite !mxE/= liftK. have [w0 [/rV0Pn[j nz_w0j] w00_0 w0A']] := w_ 0; pose a0 := (w0 *m vA) 0 0. have{w_} [wj [nz_wj wj0_0 wjA']] := w_ j; pose aj := (wj *m vA) 0 0. have [aj0 | nz_aj] := eqVneq aj 0. exists wj => //; rewrite defA (@mul_mx_row _ _ _ 1) [_ *m _]mx11_scalar -/aj. by rewrite aj0 raddf0 wjA' row_mx0. exists (aj *: w0 - a0 *: wj). apply: contraNneq nz_aj; move/rowP/(_ j)/eqP; rewrite !mxE wj0_0 mulr0 subr0. by rewrite mulf_eq0 (negPf nz_w0j) orbF. rewrite defA (@mul_mx_row _ _ _ 1) !mulmxBl -!scalemxAl w0A' wjA' !linear0. by rewrite -mul_mx_scalar -mul_scalar_mx -!mx11_scalar subrr addr0 row_mx0. Qed. End MatrixDomain. Arguments det0P {R n A}. (* Parametricity at the field level (mx_is_scalar, unit and inverse are only *) (* mapped at this level). *) Section MapFieldMatrix. Variables (aF : fieldType) (rF : comUnitRingType) (f : {rmorphism aF -> rF}). Local Notation "A ^f" := (map_mx f A) : ring_scope. Lemma map_mx_inj {m n} : injective (map_mx f : 'M_(m, n) -> 'M_(m, n)). Proof. move=> A B eq_AB; apply/matrixP=> i j. by move/matrixP/(_ i j): eq_AB => /[!mxE]; apply: fmorph_inj. Qed. Lemma map_mx_is_scalar n (A : 'M_n) : is_scalar_mx A^f = is_scalar_mx A. Proof. rewrite /is_scalar_mx; case: (insub _) => // i. by rewrite mxE -map_scalar_mx inj_eq //; apply: map_mx_inj. Qed. Lemma map_unitmx n (A : 'M_n) : (A^f \in unitmx) = (A \in unitmx). Proof. by rewrite unitmxE det_map_mx // fmorph_unit // -unitfE. Qed. Lemma map_mx_unit n' (A : 'M_n'.+1) : (A^f \is a GRing.unit) = (A \is a GRing.unit). Proof. exact: map_unitmx. Qed. Lemma map_invmx n (A : 'M_n) : (invmx A)^f = invmx A^f. Proof. rewrite /invmx map_unitmx (fun_if (map_mx f)). by rewrite map_mxZ map_mx_adj det_map_mx fmorphV. Qed. Lemma map_mx_inv n' (A : 'M_n'.+1) : A^-1^f = A^f^-1. Proof. exact: map_invmx. Qed. Lemma map_mx_eq0 m n (A : 'M_(m, n)) : (A^f == 0) = (A == 0). Proof. by rewrite -(inj_eq map_mx_inj) raddf0. Qed. End MapFieldMatrix. Arguments map_mx_inj {aF rF f m n} [A1 A2] eqA12f : rename. (*****************************************************************************) (***************************** LUP decomposition *****************************) (*****************************************************************************) Section CormenLUP. Variable F : fieldType. (* Decomposition of the matrix A to P A = L U with *) (* - P a permutation matrix *) (* - L a unipotent lower triangular matrix *) (* - U an upper triangular matrix *) Fixpoint cormen_lup {n} := match n return let M := 'M[F]_n.+1 in M -> M * M * M with | 0 => fun A => (1, 1, A) | _.+1 => fun A => let k := odflt 0 [pick k | A k 0 != 0] in let A1 : 'M_(1 + _) := xrow 0 k A in let P1 : 'M_(1 + _) := tperm_mx 0 k in let Schur := ((A k 0)^-1 *: dlsubmx A1) *m ursubmx A1 in let: (P2, L2, U2) := cormen_lup (drsubmx A1 - Schur) in let P := block_mx 1 0 0 P2 *m P1 in let L := block_mx 1 0 ((A k 0)^-1 *: (P2 *m dlsubmx A1)) L2 in let U := block_mx (ulsubmx A1) (ursubmx A1) 0 U2 in (P, L, U) end. Lemma cormen_lup_perm n (A : 'M_n.+1) : is_perm_mx (cormen_lup A).1.1. Proof. elim: n => [|n IHn] /= in A *; first exact: is_perm_mx1. set A' := _ - _; move/(_ A'): IHn; case: cormen_lup => [[P L U]] {A'}/=. rewrite (is_perm_mxMr _ (perm_mx_is_perm _ _)). by case/is_perm_mxP => s ->; apply: lift0_mx_is_perm. Qed. Lemma cormen_lup_correct n (A : 'M_n.+1) : let: (P, L, U) := cormen_lup A in P * A = L * U. Proof. elim: n => [|n IHn] /= in A *; first by rewrite !mul1r. set k := odflt _ _; set A1 : 'M_(1 + _) := xrow _ _ _. set A' := _ - _; move/(_ A'): IHn; case: cormen_lup => [[P' L' U']] /= IHn. rewrite -mulrA -!mulmxE -xrowE -/A1 /= -[n.+2]/(1 + n.+1)%N -{1}(submxK A1). rewrite !mulmx_block !mul0mx !mulmx0 !add0r !addr0 !mul1mx -{L' U'}[L' *m _]IHn. rewrite -scalemxAl !scalemxAr -!mulmxA addrC -mulrDr {A'}subrK. congr (block_mx _ _ (_ *m _) _). rewrite [_ *: _]mx11_scalar !mxE lshift0 tpermL {}/A1 {}/k. case: pickP => /= [k nzAk0 | no_k]; first by rewrite mulVf ?mulmx1. rewrite (_ : dlsubmx _ = 0) ?mul0mx //; apply/colP=> i. by rewrite !mxE lshift0 (elimNf eqP (no_k _)). Qed. Lemma cormen_lup_detL n (A : 'M_n.+1) : \det (cormen_lup A).1.2 = 1. Proof. elim: n => [|n IHn] /= in A *; first by rewrite det1. set A' := _ - _; move/(_ A'): IHn; case: cormen_lup => [[P L U]] {A'}/= detL. by rewrite (@det_lblock _ 1) det1 mul1r. Qed. Lemma cormen_lup_lower n A (i j : 'I_n.+1) : i <= j -> (cormen_lup A).1.2 i j = (i == j)%:R. Proof. elim: n => [|n IHn] /= in A i j *; first by rewrite [i]ord1 [j]ord1 mxE. set A' := _ - _; move/(_ A'): IHn; case: cormen_lup => [[P L U]] {A'}/= Ll. rewrite !mxE split1; case: unliftP => [i'|] -> /=; rewrite !mxE split1. by case: unliftP => [j'|] -> //; apply: Ll. by case: unliftP => [j'|] ->; rewrite /= mxE. Qed. Lemma cormen_lup_upper n A (i j : 'I_n.+1) : j < i -> (cormen_lup A).2 i j = 0 :> F. Proof. elim: n => [|n IHn] /= in A i j *; first by rewrite [i]ord1. set A' := _ - _; move/(_ A'): IHn; case: cormen_lup => [[P L U]] {A'}/= Uu. rewrite !mxE split1; case: unliftP => [i'|] -> //=; rewrite !mxE split1. by case: unliftP => [j'|] ->; [apply: Uu | rewrite /= mxE]. Qed. End CormenLUP. Section mxOver. Section mxOverType. Context {m n : nat} {T : Type}. Implicit Types (S : {pred T}). Definition mxOver_pred (S : {pred T}) := fun M : 'M[T]_(m, n) => [forall i, [forall j, M i j \in S]]. Arguments mxOver_pred _ _ /. Definition mxOver (S : {pred T}) := [qualify a M | mxOver_pred S M]. Lemma mxOverP {S : {pred T}} {M : 'M[T]__} : reflect (forall i j, M i j \in S) (M \is a mxOver S). Proof. exact/'forall_forallP. Qed. Lemma mxOverS (S1 S2 : {pred T}) : {subset S1 <= S2} -> {subset mxOver S1 <= mxOver S2}. Proof. by move=> sS12 M /mxOverP S1M; apply/mxOverP=> i j; apply/sS12/S1M. Qed. Lemma mxOver_const c S : c \in S -> const_mx c \is a mxOver S. Proof. by move=> cS; apply/mxOverP => i j; rewrite !mxE. Qed. Lemma mxOver_constE c S : (m > 0)%N -> (n > 0)%N -> (const_mx c \is a mxOver S) = (c \in S). Proof. move=> m_gt0 n_gt0; apply/idP/idP; last exact: mxOver_const. by move=> /mxOverP /(_ (Ordinal m_gt0) (Ordinal n_gt0)); rewrite mxE. Qed. End mxOverType. Lemma thinmxOver {n : nat} {T : Type} (M : 'M[T]_(n, 0)) S : M \is a mxOver S. Proof. by apply/mxOverP => ? []. Qed. Lemma flatmxOver {n : nat} {T : Type} (M : 'M[T]_(0, n)) S : M \is a mxOver S. Proof. by apply/mxOverP => - []. Qed. Section mxOverZmodule. Context {M : zmodType} {m n : nat}. Implicit Types (S : {pred M}). Lemma mxOver0 S : 0 \in S -> 0 \is a @mxOver m n _ S. Proof. exact: mxOver_const. Qed. Section mxOverAdd. Variable addS : addrClosed M. Fact mxOver_add_subproof : addr_closed (@mxOver m n _ addS). Proof. split=> [|p q Sp Sq]; first by rewrite mxOver0 // ?rpred0. by apply/mxOverP=> i j; rewrite mxE rpredD // !(mxOverP _). Qed. HB.instance Definition _ := GRing.isAddClosed.Build 'M[M]_(m, n) (mxOver_pred addS) mxOver_add_subproof. End mxOverAdd. Section mxOverOpp. Variable oppS : opprClosed M. Fact mxOver_opp_subproof : oppr_closed (@mxOver m n _ oppS). Proof. by move=> A /mxOverP SA; apply/mxOverP=> i j; rewrite mxE rpredN. Qed. HB.instance Definition _ := GRing.isOppClosed.Build 'M[M]_(m, n) (mxOver_pred oppS) mxOver_opp_subproof. End mxOverOpp. HB.instance Definition _ (zmodS : zmodClosed M) := GRing.OppClosed.on (mxOver_pred zmodS). End mxOverZmodule. Section mxOverRing. Context {R : pzSemiRingType} {m n : nat}. Lemma mxOver_scalar S c : 0 \in S -> c \in S -> c%:M \is a @mxOver n n R S. Proof. by move=> S0 cS; apply/mxOverP => i j; rewrite !mxE; case: eqP. Qed. Lemma mxOver_scalarE S c : (n > 0)%N -> (c%:M \is a @mxOver n n R S) = ((n > 1) ==> (0 \in S)) && (c \in S). Proof. case: n => [|[|k]]//= _. by apply/mxOverP/idP => [/(_ ord0 ord0)|cij i j]; rewrite ?mxE ?ord1. apply/mxOverP/andP => [cij|[S0 cij] i j]; last by rewrite !mxE; case: eqP. by split; [have := cij 0 1|have := cij 0 0]; rewrite !mxE. Qed. Lemma mxOverZ (S : mulrClosed R) : {in S & mxOver S, forall a : R, forall v : 'M[R]_(m, n), a *: v \is a mxOver S}. Proof. by move=> a v aS /mxOverP vS; apply/mxOverP => i j; rewrite !mxE rpredM. Qed. Lemma mxOver_diag (S : {pred R}) k (D : 'rV[R]_k) : 0 \in S -> D \is a mxOver S -> diag_mx D \is a mxOver S. Proof. move=> S0 DS; apply/mxOverP => i j; rewrite !mxE. by case: eqP => //; rewrite (mxOverP DS). Qed. Lemma mxOver_diagE (S : {pred R}) k (D : 'rV[R]_k) : k > 0 -> (diag_mx D \is a mxOver S) = ((k > 1) ==> (0 \in S)) && (D \is a mxOver S). Proof. case: k => [|[|k]]//= in D * => _. by rewrite [diag_mx _]mx11_scalar [D in RHS]mx11_scalar !mxE. apply/idP/andP => [/mxOverP DS|[S0 DS]]; last exact: mxOver_diag. split; first by have /[!mxE] := DS 0 1. by apply/mxOverP => i j; have := DS j j; rewrite ord1 !mxE eqxx. Qed. Lemma mxOverM (S : semiringClosed R) p q r : {in mxOver S & mxOver S, forall u : 'M[R]_(p, q), forall v : 'M[R]_(q, r), u *m v \is a mxOver S}. Proof. move=> M N /mxOverP MS /mxOverP NS; apply/mxOverP => i j. by rewrite !mxE rpred_sum // => k _; rewrite rpredM. Qed. End mxOverRing. Section mxRingOver. Context {R : pzSemiRingType} {n : nat} (S : semiringClosed R). Fact mxOver_mul_subproof : mulr_closed (@mxOver n n _ S). Proof. by split; rewrite ?mxOver_scalar ?rpred0 ?rpred1//; apply: mxOverM. Qed. HB.instance Definition _ := GRing.isMulClosed.Build _ (mxOver_pred S) mxOver_mul_subproof. End mxRingOver. HB.instance Definition _ {R : pzRingType} {n : nat} (S : subringClosed R) := GRing.MulClosed.on (@mxOver_pred n n _ S). End mxOver. Section BlockMatrix. Import tagnat. Context {T : Type} {p q : nat} {p_ : 'I_p -> nat} {q_ : 'I_q -> nat}. Notation sp := (\sum_i p_ i)%N. Notation sq := (\sum_i q_ i)%N. Implicit Type (s : 'I_sp) (t : 'I_sq). Definition mxblock (B_ : forall i j, 'M[T]_(p_ i, q_ j)) := \matrix_(j, k) B_ (sig1 j) (sig1 k) (sig2 j) (sig2 k). Local Notation "\mxblock_ ( i , j ) E" := (mxblock (fun i j => E)) : ring_scope. Definition mxrow m (B_ : forall j, 'M[T]_(m, q_ j)) := \matrix_(j, k) B_ (sig1 k) j (sig2 k). Local Notation "\mxrow_ i E" := (mxrow (fun i => E)) : ring_scope. Definition mxcol n (B_ : forall i, 'M[T]_(p_ i, n)) := \matrix_(j, k) B_ (sig1 j) (sig2 j) k. Local Notation "\mxcol_ i E" := (mxcol (fun i => E)) : ring_scope. Definition submxblock (A : 'M[T]_(sp, sq)) i j := mxsub (Rank i) (Rank j) A. Definition submxrow m (A : 'M[T]_(m, sq)) j := colsub (Rank j) A. Definition submxcol n (A : 'M[T]_(sp, n)) i := rowsub (Rank i) A. Lemma mxblockEh B_ : \mxblock_(i, j) B_ i j = \mxrow_j \mxcol_i B_ i j. Proof. by apply/matrixP => k l; rewrite !mxE. Qed. Lemma mxblockEv B_ : \mxblock_(i, j) B_ i j = \mxcol_i \mxrow_j B_ i j. Proof. by apply/matrixP => k l; rewrite !mxE. Qed. Lemma submxblockEh A i j : submxblock A i j = submxcol (submxrow A j) i. Proof. by apply/matrixP => k l; rewrite !mxE. Qed. Lemma submxblockEv A i j : submxblock A i j = submxrow (submxcol A i) j. Proof. by apply/matrixP => k l; rewrite !mxE. Qed. Lemma mxblockK B_ i j : submxblock (\mxblock_(i, j) B_ i j) i j = B_ i j. Proof. apply/matrixP => k l; rewrite !mxE !Rank2K. by do !case: _ / esym; rewrite !cast_ord_id. Qed. Lemma mxrowK m B_ j : @submxrow m (\mxrow_j B_ j) j = B_ j. Proof. apply/matrixP => k l; rewrite !mxE !Rank2K. by do !case: _ / esym; rewrite !cast_ord_id. Qed. Lemma mxcolK n B_ i : @submxcol n (\mxcol_i B_ i) i = B_ i. Proof. apply/matrixP => k l; rewrite !mxE !Rank2K. by do !case: _ / esym; rewrite !cast_ord_id. Qed. Lemma submxrow_matrix B_ j : submxrow (\mxblock_(i, j) B_ i j) j = \mxcol_i B_ i j. Proof. by rewrite mxblockEh mxrowK. Qed. Lemma submxcol_matrix B_ i : submxcol (\mxblock_(i, j) B_ i j) i = \mxrow_j B_ i j. Proof. by rewrite mxblockEv mxcolK. Qed. Lemma submxblockK A : \mxblock_(i, j) (submxblock A i j) = A. Proof. by apply/matrixP => k l; rewrite !mxE !sig2K. Qed. Lemma submxrowK m (A : 'M[T]_(m, sq)) : \mxrow_j (submxrow A j) = A. Proof. by apply/matrixP => k l; rewrite !mxE !sig2K. Qed. Lemma submxcolK n (A : 'M[T]_(sp, n)) : \mxcol_i (submxcol A i) = A. Proof. by apply/matrixP => k l; rewrite !mxE !sig2K. Qed. Lemma mxblockP A B : (forall i j, submxblock A i j = submxblock B i j) <-> A = B. Proof. split=> [eqAB|->//]; apply/matrixP=> s t; have /matrixP := eqAB (sig1 s) (sig1 t). by move=> /(_ (sig2 s) (sig2 t)); rewrite !mxE !sig2K. Qed. Lemma mxrowP m (A B : 'M_(m, sq)) : (forall j, submxrow A j = submxrow B j) <-> A = B. Proof. split=> [eqAB|->//]; apply/matrixP=> i t; have /matrixP := eqAB (sig1 t). by move=> /(_ i (sig2 t)); rewrite !mxE !sig2K. Qed. Lemma mxcolP n (A B : 'M_(sp, n)) : (forall i, submxcol A i = submxcol B i) <-> A = B. Proof. split=> [eqAB|->//]; apply/matrixP=> s j; have /matrixP := eqAB (sig1 s). by move=> /(_ (sig2 s) j); rewrite !mxE !sig2K. Qed. Lemma eq_mxblockP A_ B_ : (forall i j, A_ i j = B_ i j) <-> (\mxblock_(i, j) A_ i j = \mxblock_(i, j) B_ i j). Proof. split; first by move=> e; apply/mxblockP => i j; rewrite !mxblockK. by move=> + i j => /mxblockP/(_ i j); rewrite !mxblockK. Qed. Lemma eq_mxblock A_ B_ : (forall i j, A_ i j = B_ i j) -> (\mxblock_(i, j) A_ i j = \mxblock_(i, j) B_ i j). Proof. by move=> /eq_mxblockP. Qed. Lemma eq_mxrowP m (A_ B_ : forall j, 'M[T]_(m, q_ j)) : (forall j, A_ j = B_ j) <-> (\mxrow_j A_ j = \mxrow_j B_ j). Proof. split; first by move=> e; apply/mxrowP => j; rewrite !mxrowK. by move=> + j => /mxrowP/(_ j); rewrite !mxrowK. Qed. Lemma eq_mxrow m (A_ B_ : forall j, 'M[T]_(m, q_ j)) : (forall j, A_ j = B_ j) -> (\mxrow_j A_ j = \mxrow_j B_ j). Proof. by move=> /eq_mxrowP. Qed. Lemma eq_mxcolP n (A_ B_ : forall i, 'M[T]_(p_ i, n)) : (forall i, A_ i = B_ i) <-> (\mxcol_i A_ i = \mxcol_i B_ i). Proof. split; first by move=> e; apply/mxcolP => i; rewrite !mxcolK. by move=> + i => /mxcolP/(_ i); rewrite !mxcolK. Qed. Lemma eq_mxcol n (A_ B_ : forall i, 'M[T]_(p_ i, n)) : (forall i, A_ i = B_ i) -> (\mxcol_i A_ i = \mxcol_i B_ i). Proof. by move=> /eq_mxcolP. Qed. Lemma row_mxrow m (B_ : forall j, 'M[T]_(m, q_ j)) i : row i (\mxrow_j B_ j) = \mxrow_j (row i (B_ j)). Proof. by apply/rowP => l; rewrite !mxE. Qed. Lemma col_mxrow m (B_ : forall j, 'M[T]_(m, q_ j)) j : col j (\mxrow_j B_ j) = col (sig2 j) (B_ (sig1 j)). Proof. by apply/colP => l; rewrite !mxE. Qed. Lemma row_mxcol n (B_ : forall i, 'M[T]_(p_ i, n)) i : row i (\mxcol_i B_ i) = row (sig2 i) (B_ (sig1 i)). Proof. by apply/rowP => l; rewrite !mxE. Qed. Lemma col_mxcol n (B_ : forall i, 'M[T]_(p_ i, n)) j : col j (\mxcol_i B_ i) = \mxcol_i (col j (B_ i)). Proof. by apply/colP => l; rewrite !mxE. Qed. Lemma row_mxblock B_ i : row i (\mxblock_(i, j) B_ i j) = \mxrow_j row (sig2 i) (B_ (sig1 i) j). Proof. by apply/rowP => l; rewrite !mxE. Qed. Lemma col_mxblock B_ j : col j (\mxblock_(i, j) B_ i j) = \mxcol_i col (sig2 j) (B_ i (sig1 j)). Proof. by apply/colP => l; rewrite !mxE. Qed. End BlockMatrix. Notation "\mxblock_ ( i < m , j < n ) E" := (mxblock (fun (i : 'I_m) (j : 'I_ n) => E)) (only parsing) : ring_scope. Notation "\mxblock_ ( i , j < n ) E" := (\mxblock_(i < n, j < n) E) (only parsing) : ring_scope. Notation "\mxblock_ ( i , j ) E" := (\mxblock_(i < _, j < _) E) : ring_scope. Notation "\mxrow_ ( j < m ) E" := (mxrow (fun (j : 'I_m) => E)) (only parsing) : ring_scope. Notation "\mxrow_ j E" := (\mxrow_(j < _) E) : ring_scope. Notation "\mxcol_ ( i < m ) E" := (mxcol (fun (i : 'I_m) => E)) (only parsing) : ring_scope. Notation "\mxcol_ i E" := (\mxcol_(i < _) E) : ring_scope. Lemma tr_mxblock {T : Type} {p q : nat} {p_ : 'I_p -> nat} {q_ : 'I_q -> nat} (B_ : forall i j, 'M[T]_(p_ i, q_ j)) : (\mxblock_(i, j) B_ i j)^T = \mxblock_(i, j) (B_ j i)^T. Proof. by apply/matrixP => i j; rewrite !mxE. Qed. Section SquareBlockMatrix. Context {T : Type} {p : nat} {p_ : 'I_p -> nat}. Notation sp := (\sum_i p_ i)%N. Implicit Type (s : 'I_sp). Lemma tr_mxrow n (B_ : forall j, 'M[T]_(n, p_ j)) : (\mxrow_j B_ j)^T = \mxcol_i (B_ i)^T. Proof. by apply/matrixP => i j; rewrite !mxE. Qed. Lemma tr_mxcol n (B_ : forall i, 'M[T]_(p_ i, n)) : (\mxcol_i B_ i)^T = \mxrow_i (B_ i)^T. Proof. by apply/matrixP => i j; rewrite !mxE. Qed. Lemma tr_submxblock (A : 'M[T]_sp) i j : (submxblock A i j)^T = (submxblock A^T j i). Proof. by apply/matrixP => k l; rewrite !mxE. Qed. Lemma tr_submxrow n (A : 'M[T]_(n, sp)) j : (submxrow A j)^T = (submxcol A^T j). Proof. by apply/matrixP => k l; rewrite !mxE. Qed. Lemma tr_submxcol n (A : 'M[T]_(sp, n)) i : (submxcol A i)^T = (submxrow A^T i). Proof. by apply/matrixP => k l; rewrite !mxE. Qed. End SquareBlockMatrix. Section BlockRowRecL. Import tagnat. Context {T : Type} {m : nat} {p_ : 'I_m.+1 -> nat}. Notation sp := (\sum_i p_ i)%N. Lemma mxsize_recl : (p_ ord0 + \sum_i p_ (lift ord0 i) = (\sum_i p_ i))%N. Proof. by rewrite big_ord_recl. Qed. Lemma mxrow_recl n (B_ : forall j, 'M[T]_(n, p_ j)) : \mxrow_j B_ j = castmx (erefl, mxsize_recl) (row_mx (B_ 0) (\mxrow_j B_ (lift ord0 j))). Proof. apply/mxrowP => i; rewrite mxrowK. apply/matrixP => j k; rewrite !(castmxE, mxE)/=. case: splitP => l /=; do [ rewrite [LHS]RankEsum big_mkcond big_ord_recl -big_mkcond/=; rewrite /bump/= -addnA cast_ord_id; under eq_bigl do rewrite add1n -ltn_predRL/=]. case: posnP => i0; last first. by move=> lE; have := ltn_ord l; rewrite /= -lE -ltn_subRL subnn. by rewrite (@val_inj _ _ _ i 0 i0) big_pred0_eq in k * => /val_inj->. case: posnP => i0. rewrite (@val_inj _ _ _ i 0 i0) big_pred0_eq in k l * => kE. by have := ltn_ord k; rewrite /= [val k]kE -ltn_subRL subnn. have i_lt : i.-1 < m by rewrite -subn1 ltn_subLR. set i' := lift ord0 (Ordinal i_lt). have ii' : i = i' by apply/val_inj; rewrite /=/bump/= add1n prednK. have k_lt : k < p_ i' by rewrite -ii'. move=> /addnI; rewrite eqRank => /val_inj/= /[dup] kl<-; rewrite mxE. rewrite Rank2K//; case: _ / esym; rewrite cast_ord_id/=. rewrite -/i'; set j' := Ordinal _; have : k = j' :> nat by []. by move: j'; rewrite -ii' => j' /val_inj->. Qed. End BlockRowRecL. Lemma mxcol_recu {T : Type} {p : nat} {p_ : 'I_p.+1 -> nat} m (B_ : forall j, 'M[T]_(p_ j, m)) : \mxcol_j B_ j = castmx (mxsize_recl, erefl) (col_mx (B_ 0) (\mxcol_j B_ (lift ord0 j))). Proof. by apply: trmx_inj; rewrite trmx_cast tr_col_mx !tr_mxcol mxrow_recl. Qed. Section BlockMatrixRec. Local Notation e := (mxsize_recl, mxsize_recl). Local Notation l0 := (lift ord0). Context {T : Type}. Lemma mxblock_recu {p q : nat} {p_ : 'I_p.+1 -> nat} {q_ : 'I_q -> nat} (B_ : forall i j, 'M[T]_(p_ i, q_ j)) : \mxblock_(i, j) B_ i j = castmx (mxsize_recl, erefl) (col_mx (\mxrow_j B_ ord0 j) (\mxblock_(i, j) B_ (l0 i) j)). Proof. by rewrite !mxblockEv mxcol_recu. Qed. Lemma mxblock_recl {p q : nat} {p_ : 'I_p -> nat} {q_ : 'I_q.+1 -> nat} (B_ : forall i j, 'M[T]_(p_ i, q_ j)) : \mxblock_(i, j) B_ i j = castmx (erefl, mxsize_recl) (row_mx (\mxcol_i B_ i ord0) (\mxblock_(i, j) B_ i (l0 j))). Proof. by rewrite !mxblockEh mxrow_recl. Qed. Lemma mxblock_recul {p q : nat} {p_ : 'I_p.+1 -> nat} {q_ : 'I_q.+1 -> nat} (B_ : forall i j, 'M[T]_(p_ i, q_ j)) : \mxblock_(i, j) B_ i j = castmx e (block_mx (B_ 0 0) (\mxrow_j B_ ord0 (l0 j)) (\mxcol_i B_ (l0 i) ord0) (\mxblock_(i, j) B_ (l0 i) (l0 j))). Proof. rewrite mxblock_recl mxcol_recu mxblock_recu -cast_row_mx -block_mxEh. by rewrite castmx_comp; apply: eq_castmx. Qed. Lemma mxrowEblock {q : nat} {q_ : 'I_q -> nat} m (R_ : forall j, 'M[T]_(m, q_ j)) : (\mxrow_j R_ j) = castmx (big_ord1 _ (fun=> m), erefl) (\mxblock_(i < 1, j < q) R_ j). Proof. rewrite mxblock_recu castmx_comp. apply/matrixP => i j; rewrite !castmxE !mxE/=; case: splitP => //=. by move=> k /val_inj->; rewrite ?cast_ord_id ?mxE//=. by move=> [k klt]; suff: false by []; rewrite big_ord0 in klt. Qed. Lemma mxcolEblock {p : nat} {p_ : 'I_p -> nat} n (C_ : forall i, 'M[T]_(p_ i, n)) : (\mxcol_i C_ i) = castmx (erefl, big_ord1 _ (fun=> n)) (\mxblock_(i < p, j < 1) C_ i). Proof. by apply: trmx_inj; rewrite tr_mxcol mxrowEblock trmx_cast tr_mxblock. Qed. Lemma mxEmxrow m n (A : 'M[T]_(m, n)) : A = castmx (erefl, big_ord1 _ (fun=> n)) (\mxrow__ A). Proof. apply/matrixP => i j; rewrite castmxE !mxE/= cast_ord_id. congr (A i); set j' := cast_ord _ _. suff -> : j' = (tagnat.Rank 0 j) by apply/val_inj; rewrite tagnat.Rank2K. by apply/val_inj; rewrite [RHS]tagnat.RankEsum/= big_pred0_eq add0n. Qed. Lemma mxEmxcol m n (A : 'M[T]_(m, n)) : A = castmx (big_ord1 _ (fun=> m), erefl) (\mxcol__ A). Proof. by apply: trmx_inj; rewrite trmx_cast tr_mxcol [LHS]mxEmxrow. Qed. Lemma mxEmxblock m n (A : 'M[T]_(m, n)) : A = castmx (big_ord1 _ (fun=> m), big_ord1 _ (fun=> n)) (\mxblock_(i < 1, j < 1) A). Proof. by rewrite [LHS]mxEmxrow mxrowEblock castmx_comp; apply: eq_castmx. Qed. End BlockMatrixRec. Section BlockRowNmod. Context {V : nmodType} {q : nat} {q_ : 'I_q -> nat}. Notation sq := (\sum_i q_ i)%N. Implicit Type (s : 'I_sq). Lemma mxrowD m (R_ R'_ : forall j, 'M[V]_(m, q_ j)) : \mxrow_j (R_ j + R'_ j) = \mxrow_j (R_ j) + \mxrow_j (R'_ j). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma mxrow0 m : \mxrow_j (0 : 'M[V]_(m, q_ j)) = 0. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma mxrow_const m a : \mxrow_j (const_mx a : 'M[V]_(m, q_ j)) = const_mx a. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma mxrow_sum (J : finType) m (R_ : forall i j, 'M[V]_(m, q_ j)) (P : {pred J}) : \mxrow_j (\sum_(i | P i) R_ i j) = \sum_(i | P i) \mxrow_j (R_ i j). Proof. apply/matrixP => i j; rewrite !(mxE, summxE). by apply: eq_bigr => l; rewrite !mxE. Qed. Lemma submxrowD m (B B' : 'M[V]_(m, sq)) j : submxrow (B + B') j = submxrow B j + submxrow B' j. Proof. by apply/matrixP => i i'; rewrite !mxE. Qed. Lemma submxrow0 m j : submxrow (0 : 'M[V]_(m, sq)) j = 0. Proof. by apply/matrixP=> i i'; rewrite !mxE. Qed. Lemma submxrow_sum (J : finType) m (R_ : forall i, 'M[V]_(m, sq)) (P : {pred J}) j: submxrow (\sum_(i | P i) R_ i) j = \sum_(i | P i) submxrow (R_ i) j. Proof. apply/matrixP => i i'; rewrite !(mxE, summxE). by apply: eq_bigr => l; rewrite !mxE. Qed. End BlockRowNmod. Section BlockRowZmod. Context {V : zmodType} {q : nat} {q_ : 'I_q -> nat}. Notation sq := (\sum_i q_ i)%N. Implicit Type (s : 'I_sq). Lemma mxrowN m (R_ : forall j, 'M[V]_(m, q_ j)) : \mxrow_j (- R_ j) = - \mxrow_j (R_ j). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma mxrowB m (R_ R'_ : forall j, 'M[V]_(m, q_ j)) : \mxrow_j (R_ j - R'_ j) = \mxrow_j (R_ j) - \mxrow_j (R'_ j). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma submxrowN m (B : 'M[V]_(m, sq)) j : submxrow (- B) j = - submxrow B j. Proof. by apply/matrixP => i i'; rewrite !mxE. Qed. Lemma submxrowB m (B B' : 'M[V]_(m, sq)) j : submxrow (B - B') j = submxrow B j - submxrow B' j. Proof. by apply/matrixP => i i'; rewrite !mxE. Qed. End BlockRowZmod. Section BlockRowSemiRing. Context {R : pzSemiRingType} {n : nat} {q_ : 'I_n -> nat}. Notation sq := (\sum_i q_ i)%N. Implicit Type (s : 'I_sq). Lemma mul_mxrow m n' (A : 'M[R]_(m, n')) (R_ : forall j, 'M[R]_(n', q_ j)) : A *m \mxrow_j R_ j= \mxrow_j (A *m R_ j). Proof. by apply/matrixP=> i s; rewrite !mxE; under [LHS]eq_bigr do rewrite !mxE. Qed. Lemma mul_submxrow m n' (A : 'M[R]_(m, n')) (B : 'M[R]_(n', sq)) j : A *m submxrow B j= submxrow (A *m B) j. Proof. by apply/matrixP=> i s; rewrite !mxE; under [LHS]eq_bigr do rewrite !mxE. Qed. End BlockRowSemiRing. Section BlockColNmod. Context {V : nmodType} {n : nat} {p_ : 'I_n -> nat}. Notation sp := (\sum_i p_ i)%N. Implicit Type (s : 'I_sp). Lemma mxcolD m (C_ C'_ : forall i, 'M[V]_(p_ i, m)) : \mxcol_i (C_ i + C'_ i) = \mxcol_i (C_ i) + \mxcol_i (C'_ i). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma mxcol0 m : \mxcol_i (0 : 'M[V]_(p_ i, m)) = 0. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma mxcol_const m a : \mxcol_j (const_mx a : 'M[V]_(p_ j, m)) = const_mx a. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma mxcol_sum (I : finType) m (C_ : forall j i, 'M[V]_(p_ i, m)) (P : {pred I}): \mxcol_i (\sum_(j | P j) C_ j i) = \sum_(j | P j) \mxcol_i (C_ j i). Proof. apply/matrixP => i j; rewrite !(mxE, summxE). by apply: eq_bigr => l; rewrite !mxE. Qed. Lemma submxcolD m (B B' : 'M[V]_(sp, m)) i : submxcol (B + B') i = submxcol B i + submxcol B' i. Proof. by apply/matrixP => j j'; rewrite !mxE. Qed. Lemma submxcol0 m i : submxcol (0 : 'M[V]_(sp, m)) i = 0. Proof. by apply/matrixP=> j j'; rewrite !mxE. Qed. Lemma submxcol_sum (I : finType) m (C_ : forall j, 'M[V]_(sp, m)) (P : {pred I}) i : submxcol (\sum_(j | P j) C_ j) i = \sum_(j | P j) submxcol (C_ j) i. Proof. apply/matrixP => j j'; rewrite !(mxE, summxE). by apply: eq_bigr => l; rewrite !mxE. Qed. End BlockColNmod. Section BlockColZmod. Context {V : zmodType} {n : nat} {p_ : 'I_n -> nat}. Notation sp := (\sum_i p_ i)%N. Implicit Type (s : 'I_sp). Lemma mxcolN m (C_ : forall i, 'M[V]_(p_ i, m)) : \mxcol_i (- C_ i) = - \mxcol_i (C_ i). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma mxcolB m (C_ C'_ : forall i, 'M[V]_(p_ i, m)) : \mxcol_i (C_ i - C'_ i) = \mxcol_i (C_ i) - \mxcol_i (C'_ i). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma submxcolN m (B : 'M[V]_(sp, m)) i : submxcol (- B) i = - submxcol B i. Proof. by apply/matrixP => j j'; rewrite !mxE. Qed. Lemma submxcolB m (B B' : 'M[V]_(sp, m)) i : submxcol (B - B') i = submxcol B i - submxcol B' i. Proof. by apply/matrixP => j j'; rewrite !mxE. Qed. End BlockColZmod. Section BlockColSemiRing. Context {R : pzSemiRingType} {n : nat} {p_ : 'I_n -> nat}. Notation sp := (\sum_i p_ i)%N. Implicit Type (s : 'I_sp). Lemma mxcol_mul n' m (C_ : forall i, 'M[R]_(p_ i, n')) (A : 'M[R]_(n', m)) : \mxcol_i C_ i *m A = \mxcol_i (C_ i *m A). Proof. by apply/matrixP=> i s; rewrite !mxE; under [LHS]eq_bigr do rewrite !mxE. Qed. Lemma submxcol_mul n' m (B : 'M[R]_(sp, n')) (A : 'M[R]_(n', m)) i : submxcol B i *m A = submxcol (B *m A) i. Proof. by apply/matrixP=> j s; rewrite !mxE; under [LHS]eq_bigr do rewrite !mxE. Qed. End BlockColSemiRing. Section BlockMatrixNmod. Context {V : nmodType} {m n : nat}. Context {p_ : 'I_m -> nat} {q_ : 'I_n -> nat}. Notation sp := (\sum_i p_ i)%N. Notation sq := (\sum_i q_ i)%N. Lemma mxblockD (B_ B'_ : forall i j, 'M[V]_(p_ i, q_ j)) : \mxblock_(i, j) (B_ i j + B'_ i j) = \mxblock_(i, j) (B_ i j) + \mxblock_(i, j) (B'_ i j). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma mxblock0 : \mxblock_(i, j) (0 : 'M[V]_(p_ i, q_ j)) = 0. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma mxblock_const a : \mxblock_(i, j) (const_mx a : 'M[V]_(p_ i, q_ j)) = const_mx a. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma mxblock_sum (I : finType) (B_ : forall k i j, 'M[V]_(p_ i, q_ j)) (P : {pred I}): \mxblock_(i, j) (\sum_(k | P k) B_ k i j) = \sum_(k | P k) \mxblock_(i, j) (B_ k i j). Proof. apply/matrixP => i j; rewrite !(mxE, summxE). by apply: eq_bigr => l; rewrite !mxE. Qed. Lemma submxblockD (B B' : 'M[V]_(sp, sq)) i j : submxblock (B + B') i j = submxblock B i j + submxblock B' i j. Proof. by apply/matrixP => k l; rewrite !mxE. Qed. Lemma submxblock0 i j : submxblock (0 : 'M[V]_(sp, sq)) i j = 0. Proof. by apply/matrixP=> k l; rewrite !mxE. Qed. Lemma submxblock_sum (I : finType) (B_ : forall k, 'M[V]_(sp, sq)) (P : {pred I}) i j : submxblock (\sum_(k | P k) B_ k) i j = \sum_(k | P k) submxblock (B_ k) i j. Proof. apply/matrixP => k l; rewrite !(mxE, summxE). by apply: eq_bigr => p; rewrite !mxE. Qed. End BlockMatrixNmod. Section BlockMatrixZmod. Context {V : zmodType} {m n : nat}. Context {p_ : 'I_m -> nat} {q_ : 'I_n -> nat}. Notation sp := (\sum_i p_ i)%N. Notation sq := (\sum_i q_ i)%N. Lemma mxblockN (B_ : forall i j, 'M[V]_(p_ i, q_ j)) : \mxblock_(i, j) (- B_ i j) = - \mxblock_(i, j) (B_ i j). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma mxblockB (B_ B'_ : forall i j, 'M[V]_(p_ i, q_ j)) : \mxblock_(i, j) (B_ i j - B'_ i j) = \mxblock_(i, j) (B_ i j) - \mxblock_(i, j) (B'_ i j). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma submxblockN (B : 'M[V]_(sp, sq)) i j : submxblock (- B) i j = - submxblock B i j. Proof. by apply/matrixP => k l; rewrite !mxE. Qed. Lemma submxblockB (B B' : 'M[V]_(sp, sq)) i j : submxblock (B - B') i j = submxblock B i j - submxblock B' i j. Proof. by apply/matrixP => k l; rewrite !mxE. Qed. End BlockMatrixZmod. Section BlockMatrixSemiRing. Context {R : pzSemiRingType} {p q : nat} {p_ : 'I_p -> nat} {q_ : 'I_q -> nat}. Notation sp := (\sum_i p_ i)%N. Notation sq := (\sum_i q_ i)%N. Lemma mul_mxrow_mxcol m n (R_ : forall j, 'M[R]_(m, p_ j)) (C_ : forall i, 'M[R]_(p_ i, n)) : \mxrow_j R_ j *m \mxcol_i C_ i = \sum_i (R_ i *m C_ i). Proof. apply/matrixP => i j; rewrite !mxE summxE; under [RHS]eq_bigr do rewrite !mxE. rewrite sig_big_dep/= (reindex _ tagnat.sig_bij_on)/=. by apply: eq_bigr=> l _; rewrite !mxE. Qed. Lemma mul_mxcol_mxrow m (C_ : forall i, 'M[R]_(p_ i, m)) (R_ : forall j, 'M[R]_(m, q_ j)) : \mxcol_i C_ i*m \mxrow_j R_ j = \mxblock_(i, j) (C_ i *m R_ j). Proof. apply/mxblockP => i j; rewrite mxblockK. by rewrite submxblockEh -mul_submxrow -submxcol_mul mxcolK mxrowK. Qed. Lemma mul_mxrow_mxblock m (R_ : forall i, 'M[R]_(m, p_ i)) (B_ : forall i j, 'M[R]_(p_ i, q_ j)) : \mxrow_i R_ i *m \mxblock_(i, j) B_ i j = \mxrow_j (\sum_i (R_ i *m B_ i j)). Proof. rewrite mxblockEv mul_mxrow_mxcol mxrow_sum. by apply: eq_bigr => i _; rewrite mul_mxrow. Qed. Lemma mul_mxblock_mxrow m (B_ : forall i j, 'M[R]_(q_ i, p_ j)) (C_ : forall i, 'M[R]_(p_ i, m)) : \mxblock_(i, j) B_ i j *m \mxcol_j C_ j = \mxcol_i (\sum_j (B_ i j *m C_ j)). Proof. rewrite mxblockEh mul_mxrow_mxcol mxcol_sum. by apply: eq_bigr => i _; rewrite mxcol_mul. Qed. End BlockMatrixSemiRing. Lemma mul_mxblock {R : pzSemiRingType} {p q r : nat} {p_ : 'I_p -> nat} {q_ : 'I_q -> nat} {r_ : 'I_r -> nat} (A_ : forall i j, 'M[R]_(p_ i, q_ j)) (B_ : forall j k, 'M_(q_ j, r_ k)) : \mxblock_(i, j) A_ i j *m \mxblock_(j, k) B_ j k = \mxblock_(i, k) \sum_j (A_ i j *m B_ j k). Proof. rewrite mxblockEh mul_mxrow_mxblock mxblockEh; apply: eq_mxrow => i. by under [LHS]eq_bigr do rewrite mxcol_mul; rewrite -mxcol_sum. Qed. Section SquareBlockMatrixNmod. Import Order.TTheory tagnat. Context {V : nmodType} {p : nat} {p_ : 'I_p -> nat}. Notation sp := (\sum_i p_ i)%N. Implicit Type (s : 'I_sp). Lemma is_trig_mxblockP (B_ : forall i j, 'M[V]_(p_ i, p_ j)) : reflect [/\ forall (i j : 'I_p), (i < j)%N -> B_ i j = 0 & forall i, is_trig_mx (B_ i i)] (is_trig_mx (\mxblock_(i, j) B_ i j)). Proof. apply: (iffP is_trig_mxP); last first. move=> [Blt1 /(_ _)/is_trig_mxP Blt2]/= s s'; rewrite !mxE. rewrite -[_ < _]lt_sig ltEsig/= /sig1 /sig2 leEord. case: ltngtP => //= ii'; first by rewrite (Blt1 _ _ ii') mxE. move: (sig s) (sig s') ii' => -[/= i j] [/= i' +] /val_inj ii'. by case: _ / ii' => j'; rewrite tagged_asE => /Blt2->. move=> Btrig; split=> [i i' lti|i]. apply/matrixP => j j'; have := Btrig (Rank _ j) (Rank _ j'). rewrite !mxE !Rank2K; do !case: _ / esym; rewrite !cast_ord_id. rewrite /Rank [_ <= _]lt_rank. by rewrite ltEsig/= leEord ltnW//= (ltn_geF lti)//= => /(_ isT). apply/is_trig_mxP => j j' ltj; have := Btrig (Rank _ j) (Rank _ j'). rewrite !mxE !Rank2K; do! case: _ / esym; rewrite !cast_ord_id. by rewrite [_ <= _]lt_rank ltEsig/= !leEord leqnn/= tagged_asE; apply. Qed. Lemma is_trig_mxblock (B_ : forall i j, 'M[V]_(p_ i, p_ j)) : is_trig_mx (\mxblock_(i, j) B_ i j) = ([forall i : 'I_p, forall j : 'I_p, (i < j)%N ==> (B_ i j == 0)] && [forall i, is_trig_mx (B_ i i)]). Proof. by apply/is_trig_mxblockP/andP => -[] => [/(_ _ _ _)/eqP|] => /'forall_'forall_implyP => [|/(_ _ _ _)/eqP] Blt /forallP. Qed. Lemma is_diag_mxblockP (B_ : forall i j, 'M[V]_(p_ i, p_ j)) : reflect [/\ forall (i j : 'I_p), i != j -> B_ i j = 0 & forall i, is_diag_mx (B_ i i)] (is_diag_mx (\mxblock_(i, j) B_ i j)). Proof. apply: (iffP is_diag_mxP); last first. move=> [Bneq1 /(_ _)/is_diag_mxP Bneq2]/= s s'; rewrite !mxE. rewrite val_eqE -(can_eq sigK) /sig1 /sig2. move: (sig s) (sig s') => -[/= i j] [/= i' j']. rewrite -tag_eqE/= /tag_eq/= negb_and. case: eqVneq => /= [ii'|/Bneq1->]; last by rewrite !mxE. by rewrite -ii' in j' *; rewrite tagged_asE => /Bneq2. move=> Bdiag; split=> [i i' Ni|i]. apply/matrixP => j j'; have := Bdiag (Rank _ j) (Rank _ j'). rewrite !mxE !Rank2K; do !case: _ / esym; rewrite !cast_ord_id. by rewrite eq_Rank negb_and Ni; apply. apply/is_diag_mxP => j j' Nj; have := Bdiag (Rank _ j) (Rank _ j'). rewrite !mxE !Rank2K; do! case: _ / esym; rewrite !cast_ord_id. by rewrite eq_Rank negb_and val_eqE Nj orbT; apply. Qed. Lemma is_diag_mxblock (B_ : forall i j, 'M[V]_(p_ i, p_ j)) : is_diag_mx (\mxblock_(i, j) B_ i j) = ([forall i : 'I_p, forall j : 'I_p, (i != j) ==> (B_ i j == 0)] && [forall i, is_diag_mx (B_ i i)]). Proof. by apply/is_diag_mxblockP/andP => -[] => [/(_ _ _ _)/eqP|] => /'forall_'forall_implyP => [|/(_ _ _ _)/eqP] Blt /forallP. Qed. Definition mxdiag (B_ : forall i, 'M[V]_(p_ i)) : 'M[V]_(\sum_i p_ i) := \mxblock_(j, k) if j == k then conform_mx 0 (B_ j) else 0. Local Notation "\mxdiag_ i E" := (mxdiag (fun i => E)) : ring_scope. Lemma submxblock_diag (B_ : forall i, 'M[V]_(p_ i)) i : submxblock (\mxdiag_i B_ i) i i = B_ i. Proof. by rewrite mxblockK conform_mx_id eqxx. Qed. Lemma eq_mxdiagP (B_ B'_ : forall i, 'M[V]_(p_ i)) : (forall i, B_ i = B'_ i) <-> (\mxdiag_i B_ i = \mxdiag_i B'_ i). Proof. rewrite /mxdiag; split; first by move=> e; apply/eq_mxblockP => i j; rewrite e. by move=> + i => /eq_mxblockP/(_ i i); rewrite eqxx !conform_mx_id. Qed. Lemma eq_mxdiag (B_ B'_ : forall i, 'M[V]_(p_ i)) : (forall i, B_ i = B'_ i) -> (\mxdiag_i B_ i = \mxdiag_i B'_ i). Proof. by move=> /eq_mxdiagP. Qed. Lemma mxdiagD (B_ B'_ : forall i, 'M[V]_(p_ i)) : \mxdiag_i (B_ i + B'_ i) = \mxdiag_i (B_ i) + \mxdiag_i (B'_ i). Proof. rewrite /mxdiag -mxblockD; apply/eq_mxblock => i j. by case: eqVneq => [->|]; rewrite ?conform_mx_id ?addr0. Qed. Lemma mxdiag_sum (I : finType) (B_ : forall k i, 'M[V]_(p_ i)) (P : {pred I}) : \mxdiag_i (\sum_(k | P k) B_ k i) = \sum_(k | P k) \mxdiag_i (B_ k i). Proof. rewrite /mxdiag -mxblock_sum; apply/eq_mxblock => i j. case: eqVneq => [->|]; rewrite ?conform_mx_id//; last by rewrite big1. by apply: eq_bigr => k; rewrite conform_mx_id. Qed. Lemma tr_mxdiag (B_ : forall i, 'M[V]_(p_ i)) : (\mxdiag_i B_ i)^T = \mxdiag_i (B_ i)^T. Proof. rewrite tr_mxblock; apply/eq_mxblock => i j. by case: eqVneq => [->|]; rewrite ?trmx_conform ?trmx0. Qed. Lemma row_mxdiag (B_ : forall i, 'M[V]_(p_ i)) k : let B'_ i := if sig1 k == i then conform_mx 0 (B_ i) else 0 in row k (\mxdiag_ i B_ i) = row (sig2 k) (\mxrow_i B'_ i). Proof. rewrite /= row_mxblock row_mxrow; apply/eq_mxrow => i. by case: eqVneq => // e; congr row; rewrite e. Qed. Lemma col_mxdiag (B_ : forall i, 'M[V]_(p_ i)) k : let B'_ i := if sig1 k == i then conform_mx 0 (B_ i) else 0 in col k (\mxdiag_ i B_ i) = col (sig2 k) (\mxcol_i B'_ i). Proof. by rewrite /= col_mxblock col_mxcol; apply/eq_mxcol => i; rewrite eq_sym. Qed. End SquareBlockMatrixNmod. Notation "\mxdiag_ ( i < n ) E" := (mxdiag (fun i : 'I_n => E)) (only parsing) : ring_scope. Notation "\mxdiag_ i E" := (\mxdiag_(i < _) E) : ring_scope. Section SquareBlockMatrixZmod. Import Order.TTheory tagnat. Context {V : zmodType} {p : nat} {p_ : 'I_p -> nat}. Notation sp := (\sum_i p_ i)%N. Implicit Type (s : 'I_sp). Lemma mxdiagN (B_ : forall i, 'M[V]_(p_ i)) : \mxdiag_i (- B_ i) = - \mxdiag_i (B_ i). Proof. rewrite /mxdiag -mxblockN; apply/eq_mxblock => i j. by case: eqVneq => [->|]; rewrite ?conform_mx_id ?oppr0. Qed. Lemma mxdiagB (B_ B'_ : forall i, 'M[V]_(p_ i)) : \mxdiag_i (B_ i - B'_ i) = \mxdiag_i (B_ i) - \mxdiag_i (B'_ i). Proof. by rewrite mxdiagD mxdiagN. Qed. Lemma mxdiag0 : \mxdiag_i (0 : 'M[V]_(p_ i)) = 0. Proof. by under [LHS]eq_mxdiag do rewrite -[0]subr0; rewrite mxdiagB subrr. Qed. End SquareBlockMatrixZmod. Lemma mxdiag_recl {V : nmodType} {m : nat} {p_ : 'I_m.+1 -> nat} (B_ : forall i, 'M[V]_(p_ i)) : \mxdiag_i B_ i = castmx (mxsize_recl, mxsize_recl) (block_mx (B_ 0) 0 0 (\mxdiag_i B_ (lift ord0 i))). Proof. rewrite /mxdiag mxblock_recul/= !conform_mx_id. by congr (castmx _ (block_mx _ _ _ _)); rewrite ?mxrow0 ?mxcol0. Qed. Section SquareBlockMatrixSemiRing. Import tagnat. Context {R : pzSemiRingType} {p : nat} {p_ : 'I_p -> nat}. Notation sp := (\sum_i p_ i)%N. Implicit Type (s : 'I_sp). Lemma mxtrace_mxblock (B_ : forall i j, 'M[R]_(p_ i, p_ j)) : \tr (\mxblock_(i, j) B_ i j) = \sum_i \tr (B_ i i). Proof. rewrite /mxtrace sig_big_dep (reindex _ sig_bij_on)/=. by apply: eq_bigr => i _; rewrite !mxE. Qed. Lemma mxdiagZ a : \mxdiag_i (a%:M : 'M[R]_(p_ i)) = a%:M. Proof. apply/matrixP => s t; rewrite !mxE -(can_eq sigK) /sig1 /sig2. case: (sig s) (sig t) => [/= i j] [/= i' j']. case: eqP => [<-|ni] in j' *; last by rewrite !mxE; case: eqVneq => // -[]. by rewrite conform_mx_id eq_Tagged/= mxE. Qed. Lemma diag_mxrow (B_ : forall j, 'rV[R]_(p_ j)) : diag_mx (\mxrow_j B_ j) = \mxdiag_j (diag_mx (B_ j)). Proof. apply/matrixP => s s'; rewrite !mxE/= -(can_eq sigK) /sig1 /sig2. case: (sig s) (sig s') => [/= i j] [/= i' j']. rewrite -tag_eqE /tag_eq/=; case: (eqVneq i i') => ii'; rewrite ?mxE//=. by case: _ / ii' in j' *; rewrite tagged_asE/= conform_mx_id mxE. Qed. Lemma mxtrace_mxdiag (B_ : forall i, 'M[R]_(p_ i)) : \tr (\mxdiag_i B_ i) = \sum_i \tr (B_ i). Proof. by rewrite mxtrace_mxblock; apply: eq_bigr => i _; rewrite eqxx/= conform_mx_id. Qed. Lemma mul_mxdiag_mxcol m (D_ : forall i, 'M[R]_(p_ i)) (C_ : forall i, 'M[R]_(p_ i, m)): \mxdiag_i D_ i *m \mxcol_i C_ i = \mxcol_i (D_ i *m C_ i). Proof. rewrite /mxdiag mxblockEh mul_mxrow_mxcol. under [LHS]eq_bigr do rewrite mxcol_mul; rewrite -mxcol_sum. apply/eq_mxcol => i; rewrite (bigD1 i)//= eqxx conform_mx_id big1 ?addr0//. by move=> j; case: eqVneq => //=; rewrite mul0mx. Qed. End SquareBlockMatrixSemiRing. Lemma mul_mxrow_mxdiag {R : pzSemiRingType} {p : nat} {p_ : 'I_p -> nat} m (R_ : forall i, 'M[R]_(m, p_ i)) (D_ : forall i, 'M[R]_(p_ i)) : \mxrow_i R_ i *m \mxdiag_i D_ i = \mxrow_i (R_ i *m D_ i). Proof. apply: trmx_inj; rewrite trmx_mul_rev !tr_mxrow tr_mxdiag mul_mxdiag_mxcol. by apply/ eq_mxcol => i; rewrite trmx_mul_rev. Qed. Lemma mul_mxblock_mxdiag {R : pzSemiRingType} {p q : nat} {p_ : 'I_p -> nat} {q_ : 'I_q -> nat} (B_ : forall i j, 'M[R]_(p_ i, q_ j)) (D_ : forall j, 'M[R]_(q_ j)) : \mxblock_(i, j) B_ i j *m \mxdiag_j D_ j = \mxblock_(i, j) (B_ i j *m D_ j). Proof. by rewrite !mxblockEh mul_mxrow_mxdiag; under eq_mxrow do rewrite mxcol_mul. Qed. Lemma mul_mxdiag_mxblock {R : pzSemiRingType} {p q : nat} {p_ : 'I_p -> nat} {q_ : 'I_q -> nat} (D_ : forall j, 'M[R]_(p_ j)) (B_ : forall i j, 'M[R]_(p_ i, q_ j)): \mxdiag_j D_ j *m \mxblock_(i, j) B_ i j = \mxblock_(i, j) (D_ i *m B_ i j). Proof. by rewrite !mxblockEv mul_mxdiag_mxcol; under eq_mxcol do rewrite mul_mxrow. Qed. Definition Vandermonde (R : pzRingType) (m n : nat) (a : 'rV[R]_n) := \matrix_(i < m, j < n) a 0 j ^+ i. Lemma det_Vandermonde (R : comPzRingType) (n : nat) (a : 'rV[R]_n) : \det (Vandermonde n a) = \prod_(i < n) \prod_(j < n | i < j) (a 0 j - a 0 i). Proof. set V := @Vandermonde R. elim: n => [|n IHn] in a *; first by rewrite det_mx00 big1// => -[] []. pose b : 'rV_n := \row_i a 0 (lift 0 i). pose C : 'M_n := diag_mx (\row_(i < n) (b 0 i - a 0 0)). pose D : 'M_n.+1 := 1 - a 0 0 *: \matrix_(i, j) (i == j.+1 :> nat)%:R. have detD : \det D = 1. rewrite det_trig ?big_ord_recl ?mxE ?mulr0 ?subr0 ?eqxx. by rewrite ?big1 ?mulr1// => i; rewrite !mxE eqxx ltn_eqF// mulr0 subr0. by apply/is_trig_mxP => *; rewrite !mxE ![_ == _]ltn_eqF ?mulr0 ?subr0 ?leqW. suff: D * V _ _ a = block_mx 1 (const_mx 1) 0 (V _ _ b *m C) :> 'M_(1 + n). move=> /(congr1 determinant); rewrite detM detD mul1r => ->. rewrite det_ublock det1 mul1r det_mulmx IHn big_ord_recl mulrC; congr (_ * _). rewrite big_mkcond big_ord_recl/= mul1r det_diag. by under eq_bigr do rewrite !mxE. apply: eq_bigr => i _; under eq_bigr do rewrite !mxE. by rewrite big_mkcond [RHS]big_mkcond big_ord_recl/= mul1r. rewrite mulrBl mul1r -[_ * _]scalemxAl; apply/matrixP => i j; rewrite !mxE. under eq_bigr do rewrite !mxE; case: splitP => [{i}_ -> /[!ord1]|{}i ->]. rewrite !expr0 big1; last by move=> ?; rewrite mul0r. by rewrite ?mulr0 ?subr0 ?mxE; case: splitP => k; rewrite ?ord1 mxE//. under eq_bigr do rewrite eqSS mulr_natl mulrb eq_sym. rewrite -big_mkcond/= big_ord1_eq exprS ifT// ?leqW// -mulrBl !mxE/=. case: split_ordP => [{j}_ -> /[!ord1]|{}j ->]; rewrite ?lshift0 ?rshift1 ?mxE. by rewrite ?subrr ?mul0r//. under eq_bigr do rewrite !mxE mulrnAr mulrb. by rewrite -big_mkcond big_pred1_eq /= mulrC. Qed.
NatTrans.lean
/- Copyright (c) 2017 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tim Baumann, Stephen Morgan, Kim Morrison, Floris van Doorn -/ import Mathlib.Tactic.CategoryTheory.Reassoc /-! # Natural transformations Defines natural transformations between functors. A natural transformation `α : NatTrans F G` consists of morphisms `α.app X : F.obj X ⟶ G.obj X`, and the naturality squares `α.naturality f : F.map f ≫ α.app Y = α.app X ≫ G.map f`, where `f : X ⟶ Y`. Note that we make `NatTrans.naturality` a simp lemma, with the preferred simp normal form pushing components of natural transformations to the left. See also `CategoryTheory.FunctorCat`, where we provide the category structure on functors and natural transformations. Introduces notations * `τ.app X` for the components of natural transformations, * `F ⟶ G` for the type of natural transformations between functors `F` and `G` (this and the next require `CategoryTheory.FunctorCat`), * `σ ≫ τ` for vertical compositions, and * `σ ◫ τ` for horizontal compositions. -/ set_option mathlib.tactic.category.grind true namespace CategoryTheory -- declare the `v`'s first; see note [CategoryTheory universes]. universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] /-- `NatTrans F G` represents a natural transformation between functors `F` and `G`. The field `app` provides the components of the natural transformation. Naturality is expressed by `α.naturality`. -/ @[ext] structure NatTrans (F G : C ⥤ D) : Type max u₁ v₂ where /-- The component of a natural transformation. -/ app : ∀ X : C, F.obj X ⟶ G.obj X /-- The naturality square for a given morphism. -/ naturality : ∀ ⦃X Y : C⦄ (f : X ⟶ Y), F.map f ≫ app Y = app X ≫ G.map f := by cat_disch -- Rather arbitrarily, we say that the 'simpler' form is -- components of natural transformations moving earlier. attribute [reassoc (attr := simp)] NatTrans.naturality attribute [grind _=_] NatTrans.naturality theorem congr_app {F G : C ⥤ D} {α β : NatTrans F G} (h : α = β) (X : C) : α.app X = β.app X := by cat_disch namespace NatTrans /-- `NatTrans.id F` is the identity natural transformation on a functor `F`. -/ protected def id (F : C ⥤ D) : NatTrans F F where app X := 𝟙 (F.obj X) @[simp] theorem id_app' (F : C ⥤ D) (X : C) : (NatTrans.id F).app X = 𝟙 (F.obj X) := rfl instance (F : C ⥤ D) : Inhabited (NatTrans F F) := ⟨NatTrans.id F⟩ open Category open CategoryTheory.Functor section variable {F G H : C ⥤ D} /-- `vcomp α β` is the vertical compositions of natural transformations. -/ def vcomp (α : NatTrans F G) (β : NatTrans G H) : NatTrans F H where app X := α.app X ≫ β.app X -- functor_category will rewrite (vcomp α β) to (α ≫ β), so this is not a -- suitable simp lemma. We will declare the variant vcomp_app' there. theorem vcomp_app (α : NatTrans F G) (β : NatTrans G H) (X : C) : (vcomp α β).app X = α.app X ≫ β.app X := rfl attribute [grind =] vcomp_app end /-- The diagram ``` F(f) F(g) F(h) F X ----> F Y ----> F U ----> F U | | | | | α(X) | α(Y) | α(U) | α(V) v v v v G X ----> G Y ----> G U ----> G V G(f) G(g) G(h) ``` commutes. -/ example {F G : C ⥤ D} (α : NatTrans F G) {X Y U V : C} (f : X ⟶ Y) (g : Y ⟶ U) (h : U ⟶ V) : α.app X ≫ G.map f ≫ G.map g ≫ G.map h = F.map f ≫ F.map g ≫ F.map h ≫ α.app V := by grind end NatTrans end CategoryTheory
Attribute.lean
/- Copyright (c) 2024 Geoffrey Irving. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Geoffrey Irving -/ import Mathlib.Tactic.Bound.Init import Qq import Aesop /-! # The `bound` attribute Any lemma tagged with `@[bound]` is registered as an apply rule for the `bound` tactic, by converting it to either `norm apply` or `safe apply <priority>`. The classification is based on the number and types of the lemma's hypotheses. -/ open Lean (MetaM) open Qq namespace Mathlib.Tactic.Bound initialize Lean.registerTraceClass `bound.attribute variable {u : Lean.Level} {α : Q(Type u)} /-- Check if an expression is zero -/ def isZero (e : Q($α)) : MetaM Bool := match e with | ~q(@OfNat.ofNat.{u} _ (nat_lit 0) $i) => return true | _ => return false /-- Map the arguments of an inequality expression to a score -/ def ineqPriority (a b : Q($α)) : MetaM Nat := do return if (← isZero a) || (← isZero b) then 1 else 10 /-- Map a hypothesis type to a score -/ partial def hypPriority (hyp : Q(Prop)) : MetaM Nat := do match hyp with -- Conjunctions add scores | ~q($a ∧ $b) => pure <| (← hypPriority a) + (← hypPriority b) -- Guessing (disjunction) gets a big penalty | ~q($a ∨ $b) => pure <| 100 + (← hypPriority a) + (← hypPriority b) -- Inequalities get score 1 if they contain zero, 10 otherwise | ~q(@LE.le _ $i $a $b) => ineqPriority a b | ~q(@LT.lt _ $i $a $b) => ineqPriority a b | ~q(@GE.ge _ $i $b $a) => ineqPriority a b | ~q(@GT.gt _ $i $b $a) => ineqPriority a b -- Assume anything else is non-relevant | _ => pure 0 /-- Map a type to a score -/ def typePriority (decl : Lean.Name) (type : Lean.Expr) : MetaM Nat := Lean.Meta.forallTelescope type fun xs t ↦ do checkResult t xs.foldlM (fun (t : Nat) x ↦ do return t + (← argPriority x)) 0 where /-- Score the type of argument `x` -/ argPriority (x : Lean.Expr) : MetaM Nat := do hypPriority (← Lean.Meta.inferType x) /-- Insist that our conclusion is an inequality -/ checkResult (t : Q(Prop)) : MetaM Unit := do match t with | ~q(@LE.le _ $i $a $b) => return () | ~q(@LT.lt _ $i $a $b) => return () | ~q(@GE.ge _ $i $b $a) => return () | ~q(@GT.gt _ $i $b $a) => return () | _ => throwError (f!"`{decl}` has invalid type `{type}` as a 'bound' lemma: \ it should be an inequality") /-- Map a theorem decl to a score (0 means `norm apply`, `0 <` means `safe apply`) -/ def declPriority (decl : Lean.Name) : Lean.MetaM Nat := do match (← Lean.getEnv).find? decl with | some info => do typePriority decl info.type | none => throwError "unknown declaration {decl}" /-- Map a score to either `norm apply` or `safe apply <priority>` -/ def scoreToConfig (decl : Lean.Name) (score : Nat) : Aesop.Frontend.RuleConfig := let (phase, priority) := match score with | 0 => (Aesop.PhaseName.norm, 0) -- No hypotheses: this rule closes the goal immediately | s => (Aesop.PhaseName.safe, s) { term? := some (Lean.mkIdent decl) phase? := phase priority? := some (Aesop.Frontend.Priority.int priority) builder? := some (.regular .apply) builderOptions := {} ruleSets := ⟨#[`Bound]⟩ } /-- Register a lemma as an `apply` rule for the `bound` tactic. A lemma is appropriate for `bound` if it proves an inequality using structurally simpler inequalities, "recursing" on the structure of the expressions involved, assuming positivity or nonnegativity where useful. Examples include 1. `gcongr`-like inequalities over `<` and `≤` such as `f x ≤ f y` where `f` is monotone (note that `gcongr` supports other relations). 2. `mul_le_mul` which proves `a * b ≤ c * d` from `a ≤ c ∧ b ≤ d ∧ 0 ≤ b ∧ 0 ≤ c` 3. Positivity or nonnegativity inequalities such as `sub_nonneg`: `a ≤ b → 0 ≤ b - a` 4. Inequalities involving `1` such as `one_le_div` or `Real.one_le_exp` 5. Disjunctions where the natural recursion branches, such as `a ^ n ≤ a ^ m` when the inequality for `n,m` depends on whether `1 ≤ a ∨ a ≤ 1`. Each `@[bound]` lemma is assigned a score based on the number and complexity of its hypotheses, and the `aesop` implementation chooses lemmas with lower scores first: 1. Inequality hypotheses involving `0` add 1 to the score. 2. General inequalities add `10`. 3. Disjunctions `a ∨ b` add `100` plus the sum of the scores of `a` and `b`. The functionality of `bound` overlaps with `positivity` and `gcongr`, but can jump back and forth between `0 ≤ x` and `x ≤ y`-type inequalities. For example, `bound` proves `0 ≤ c → b ≤ a → 0 ≤ a * c - b * c` by turning the goal into `b * c ≤ a * c`, then using `mul_le_mul_of_nonneg_right`. `bound` also uses specialized lemmas for goals of the form `1 ≤ x, 1 < x, x ≤ 1, x < 1`. See also `@[bound_forward]` which marks a lemma as a forward rule for `bound`: these lemmas are applied to hypotheses to extract inequalities (e.g. `HasPowerSeriesOnBall.r_pos`). -/ initialize Lean.registerBuiltinAttribute { name := `bound descr := "Register a theorem as an apply rule for the `bound` tactic." applicationTime := .afterCompilation add := fun decl stx attrKind => Lean.withRef stx do let score ← Aesop.runTermElabMAsCoreM <| declPriority decl trace[bound.attribute] "'{decl}' has score '{score}'" let context ← Aesop.runMetaMAsCoreM Aesop.ElabM.Context.forAdditionalGlobalRules let (rule, ruleSets) ← Aesop.runTermElabMAsCoreM <| (scoreToConfig decl score).buildGlobalRule.run context for ruleSet in ruleSets do Aesop.Frontend.addGlobalRule ruleSet rule attrKind (checkNotExists := true) erase := fun decl => let ruleFilter := { name := decl, scope := .global, builders := #[], phases := #[] } Aesop.Frontend.eraseGlobalRules Aesop.RuleSetNameFilter.all ruleFilter (checkExists := true) } /-- Attribute for `forward` rules for the `bound` tactic. `@[bound_forward]` lemmas should produce inequalities given other hypotheses that might be in the context. A typical example is exposing an inequality field of a structure, such as `HasPowerSeriesOnBall.r_pos`. -/ macro "bound_forward" : attr => `(attr|aesop safe forward (rule_sets := [$(Lean.mkIdent `Bound):ident])) end Mathlib.Tactic.Bound
qfpoly.v
From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice. From mathcomp Require Import fintype tuple div bigop binomial finset finfun. From mathcomp Require Import ssralg countalg finalg poly polydiv qpoly perm. From mathcomp Require Import fingroup falgebra fieldext finfield galois. From mathcomp Require Import finalg zmodp matrix vector. (******************************************************************************) (* This file extends the algebras R[X]/<p> defined in qpoly with the field *) (* when p is irreducible *) (* It defines the new field on top of {qpoly p}. As irreducible is in general *) (* decidable in general, this is done by giving a proof explicitly. *) (* monic_irreducible_poly p == proof that p is monic and irreducible *) (* {poly %/ p with mi} == defined as {poly %/ p} where mi is proof of *) (* monic_irreducible_poly p *) (* It also defines the discrete logarithm with a primitive polynomial on a *) (* finite field *) (* primitive_poly p == p is a primitive polynomial *) (* qlogp q == is the discrete log of q where q is an element of *) (* the quotient field with respect to a primitive *) (* polynomial p *) (* plogp p q == is the discrete log of q with respect to p in {poly F} *) (* this makes only sense if p is a primitive polynomial of *) (* size > 2 *) (******************************************************************************) 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' '%/' p 'with' mi }" (p at level 2, mi at level 10, format "{ 'poly' '%/' p 'with' mi }"). Section DomainDef. Variable R : idomainType. Variable h : {poly R}. Definition monic_irreducible_poly (p : {poly R}) := ((irreducible_poly p) * (p \is monic))%type. Hypothesis hI : monic_irreducible_poly h. Definition qfpoly : monic_irreducible_poly h -> predArgType := fun=> {poly %/ h}. End DomainDef. Notation "{ 'poly' '%/' p 'with' hi }" := (@qfpoly _ p hi). Section iDomain. Variable R : idomainType. Variable h : {poly R}. Hypothesis hI : monic_irreducible_poly h. HB.instance Definition _ := GRing.NzRing.on {poly %/ h with hI}. End iDomain. Section finIDomain. Variable R : finIdomainType. Variable h : {poly R}. Hypothesis hI : monic_irreducible_poly h. HB.instance Definition _ := Finite.on {poly %/ h with hI}. End finIDomain. Section Field. Variable R : fieldType. Variable h : {poly R}. Local Notation hQ := (mk_monic h). Hypothesis hI : monic_irreducible_poly h. HB.instance Definition _ := GRing.ComUnitRing.on {poly %/ h with hI}. Lemma mk_monicE : mk_monic h = h. Proof. by rewrite /mk_monic !hI. Qed. Lemma coprimep_unit (p : {poly %/ h}) : p != 0%R -> coprimep hQ p. Proof. move=> pNZ. rewrite irreducible_poly_coprime //; last first. by case: hI; rewrite mk_monicE. apply: contra pNZ => H; case: eqP => // /eqP /dvdp_leq /(_ H). by rewrite leqNgt size_mk_monic. Qed. Lemma qpoly_mulVp (p : {poly %/ h}) : p != 0%R -> (qpoly_inv p * p = 1)%R. Proof. by move=> pNZ; apply/qpoly_mulVz/coprimep_unit. Qed. Lemma qpoly_inv0 : qpoly_inv 0%R = 0%R :> {poly %/ h}. Proof. rewrite /qpoly_inv /= coprimep0 -size_poly_eq1. rewrite [in X in X == _]mk_monicE. by have [[]] := hI; case: size => [|[]]. Qed. HB.instance Definition _ := GRing.ComUnitRing_isField.Build {poly %/ h with hI} coprimep_unit. HB.instance Definition _ := GRing.UnitAlgebra.on {poly %/ h with hI}. HB.instance Definition _ := Vector.on {poly %/ h with hI}. End Field. Section FinField. Variable R : finFieldType. Variable h : {poly R}. Local Notation hQ := (mk_monic h). HB.instance Definition _ := Finite.on {poly %/ h}. Hypothesis hI : monic_irreducible_poly h. HB.instance Definition _ := Finite.on {poly %/ h with hI}. Lemma card_qfpoly : #|{poly %/ h with hI}| = #|R| ^ (size h).-1. Proof. by rewrite card_monic_qpoly ?hI. Qed. Lemma card_qfpoly_gt1 : 1 < #|{poly %/ h with hI}|. Proof. by have := card_finNzRing_gt1 {poly %/ h with hI}. Qed. End FinField. Section inPoly. Variable R : comNzRingType. Variable h : {poly R}. Lemma in_qpoly_comp_horner (p q : {poly R}) : in_qpoly h (p \Po q) = (map_poly (qpolyC h) p).[in_qpoly h q]. Proof. have hQM := monic_mk_monic h. rewrite comp_polyE /map_poly poly_def horner_sum /=. apply: val_inj. rewrite /= rmodp_sum // poly_of_qpoly_sum. apply: eq_bigr => i _. rewrite !hornerE /in_qpoly /=. rewrite mul_polyC // !rmodpZ //=. by rewrite poly_of_qpolyX /= rmodp_id // rmodpX // rmodp_id. Qed. Lemma map_poly_div_inj : injective (map_poly (qpolyC h)). Proof. apply: map_inj_poly => [x y /val_eqP /eqP /polyC_inj //|]. by rewrite qpolyC0. Qed. End inPoly. Section finPoly. (* Unfortunately we need some duplications so inference propagates qfpoly :-( )*) Definition qfpoly_const (R : idomainType) (h : {poly R}) (hMI : monic_irreducible_poly h) : R -> {poly %/ h with hMI} := qpolyC h. Lemma map_fpoly_div_inj (R : idomainType) (h : {poly R}) (hMI : monic_irreducible_poly h) : injective (map_poly (qfpoly_const hMI)). Proof. by apply: (@map_poly_div_inj R h). Qed. End finPoly. Section Splitting. Variable F : finFieldType. Variable h : {poly F}. Hypothesis hI : monic_irreducible_poly h. Definition qfpoly_splitting_field_type := FinSplittingFieldType F {poly %/ h with hI}. End Splitting. Section PrimitivePoly. Variable F : finFieldType. Variable h : {poly F}. Hypothesis sh_gt2 : 2 < size h. Let sh_gt1 : 1 < size h. Proof. by apply: leq_ltn_trans sh_gt2. Qed. Definition primitive_poly (p: {poly F}) := let v := #|{poly %/ p}|.-1 in [&& p \is monic, irreducibleb p, p %| 'X^v - 1 & [forall n : 'I_v, (p %| 'X^n - 1) ==> (n == 0%N :> nat)]]. Lemma primitive_polyP (p : {poly F}) : reflect (let v := #|{poly %/ p}|.-1 in [/\ monic_irreducible_poly p, p %| 'X^v - 1 & forall n, 0 < n < v -> ~~ (p %| 'X^n - 1)]) (primitive_poly p). Proof. apply: (iffP and4P) => [[H1 H2 H3 /forallP H4] v|[[H1 H2] H3 H4]]; split => //. - by split => //; apply/irreducibleP. - move=> n /andP[n_gt0 nLv]; apply/negP => /(implyP (H4 (Ordinal nLv))) /=. by rewrite eqn0Ngt n_gt0. - by apply/irreducibleP. apply/forallP=> [] [[|n] Hn] /=; apply/implyP => pDX //. by case/negP: (H4 n.+1 Hn). Qed. Hypothesis Hh : primitive_poly h. Lemma primitive_mi : monic_irreducible_poly h. Proof. by case/primitive_polyP: Hh. Qed. Lemma primitive_poly_in_qpoly_eq0 p : (in_qpoly h p == 0) = (h %| p). Proof. have hM : h \is monic by case/and4P:Hh. have hMi : monic_irreducible_poly h by apply: primitive_mi. apply/eqP/idP => [/val_eqP /= | hDp]. by rewrite -Pdiv.IdomainMonic.modpE mk_monicE. by apply/val_eqP; rewrite /= -Pdiv.IdomainMonic.modpE mk_monicE. Qed. Local Notation qT := {poly %/ h with primitive_mi}. Lemma card_primitive_qpoly : #|{poly %/ h}|= #|F| ^ (size h).-1. Proof. by rewrite card_monic_qpoly ?primitive_mi. Qed. Lemma qX_neq0 : 'qX != 0 :> qT. Proof. apply/eqP => /val_eqP/=. by rewrite [rmodp _ _]qpolyXE ?polyX_eq0 //; case: primitive_mi. Qed. Lemma qX_in_unit : ('qX : qT) \in GRing.unit. Proof. by rewrite unitfE /= qX_neq0. Qed. Definition gX : {unit qT} := FinRing.unit _ qX_in_unit. Lemma dvdp_order n : (h %| 'X^n - 1) = (gX ^+ n == 1)%g. Proof. have [hM hI] := primitive_mi. have eqr_add2r (r : nzRingType) (a b c : r) : (a + c == b + c) = (a == b). by apply/eqP/eqP => [H|->//]; rewrite -(addrK c a) H addrK. rewrite -val_eqE /= val_unitX /= -val_eqE /=. rewrite (poly_of_qpolyX) qpolyXE // mk_monicE //. rewrite -[in RHS](subrK 1 'X^n) rmodpD //. rewrite [rmodp 1 h]rmodp_small ?size_poly1 //. rewrite -[1%:P]add0r polyC1 /= eqr_add2r. by rewrite dvdpE /=; apply/rmodp_eq0P/eqP. Qed. Lemma gX_order : #[gX]%g = (#|qT|).-1. Proof. have /primitive_polyP[Hp1 Hp2 Hp3] := Hh. set n := _.-1 in Hp2 Hp3 *. have n_gt0 : 0 < n by rewrite ltn_predRL card_qfpoly_gt1. have [hM hI] := primitive_mi. have gX_neq1 : gX != 1%g. apply/eqP/val_eqP/eqP/val_eqP=> /=. rewrite [X in X != _]qpolyXE /= //. by apply/eqP=> Hx1; have := @size_polyX F; rewrite Hx1 size_poly1. have Hx : (gX ^+ n)%g = 1%g by apply/eqP; rewrite -dvdp_order. have Hf i : 0 < i < n -> (gX ^+ i != 1)%g by rewrite -dvdp_order => /Hp3. have o_gt0 : 0 < #[gX]%g by rewrite order_gt0. have : n <= #[gX]%g. rewrite leqNgt; apply/negP=> oLx. have /Hf/eqP[] : 0 < #[gX]%g < n by rewrite o_gt0. by rewrite expg_order. case: ltngtP => nLo _ //. have: uniq (path.traject (mulg gX) 1%g #[gX]%g). by apply/card_uniqP; rewrite path.size_traject -(eq_card (cycle_traject gX)). case: #[gX]%g o_gt0 nLo => //= n1 _ nLn1 /andP[/negP[]]. apply/path.trajectP; exists n.-1; first by rewrite prednK. rewrite -iterSr prednK // -[LHS]Hx. by elim: (n) => //= n2 <-; rewrite expgS. Qed. Lemma gX_all : <[gX]>%g = [set: {unit qT}]%G. Proof. apply/eqP; rewrite eqEcard; apply/andP; split. by apply/subsetP=> i; rewrite inE. rewrite leq_eqVlt; apply/orP; left; apply/eqP. rewrite -orderE gX_order card_qfpoly -[in RHS](mk_monicE primitive_mi). rewrite -card_qpoly -(cardC1 (0 : {poly %/ h with primitive_mi})). rewrite cardsT card_sub. by apply: eq_card => x; rewrite [LHS]unitfE. Qed. Let pred_card_qT_gt0 : 0 < #|qT|.-1. Proof. by rewrite ltn_predRL card_qfpoly_gt1. Qed. Definition qlogp (p : qT) : nat := odflt (Ordinal pred_card_qT_gt0) (pick [pred i in 'I_ _ | ('qX ^+ i == p)]). Lemma qlogp_lt p : qlogp p < #|qT|.-1. Proof. by rewrite /qlogp; case: pickP. Qed. Lemma qlogp_qX (p : qT) : p != 0 -> 'qX ^+ (qlogp p) = p. Proof. move=> p_neq0. have Up : p \in GRing.unit by rewrite unitfE. pose gp : {unit qT}:= FinRing.unit _ Up. have /cyclePmin[i iLc iX] : gp \in <[gX]>%g by rewrite gX_all inE. rewrite gX_order in iLc. rewrite /qlogp; case: pickP => [j /eqP//|/(_ (Ordinal iLc))] /eqP[]. by have /val_eqP/eqP/= := iX; rewrite FinRing.val_unitX. Qed. Lemma qX_order_card : 'qX ^+ (#|qT|).-1 = 1 :> qT. Proof. have /primitive_polyP [_ Hd _] := Hh. rewrite dvdp_order in Hd. have -> : 1 = val (1%g : {unit qT}) by []. by rewrite -(eqP Hd) val_unitX. Qed. Lemma qX_order_dvd (i : nat) : 'qX ^+ i = 1 :> qT -> (#|qT|.-1 %| i)%N. Proof. rewrite -gX_order cyclic.order_dvdn => Hd. by apply/eqP/val_inj; rewrite /= -Hd val_unitX. Qed. Lemma qlogp0 : qlogp 0 = 0%N. Proof. rewrite /qlogp; case: pickP => //= x. by rewrite (expf_eq0 ('qX : qT)) (negPf qX_neq0) andbF. Qed. Lemma qlogp1 : qlogp 1 = 0%N. Proof. case: (qlogp 1 =P 0%N) => // /eqP log1_neq0. have := qlogp_lt 1; rewrite ltnNge => /negP[]. apply: dvdn_leq; first by rewrite lt0n. by rewrite qX_order_dvd // qlogp_qX ?oner_eq0. Qed. Lemma qlogp_eq0 (q : qT) : (qlogp q == 0%N) = (q == 0) || (q == 1). Proof. case: (q =P 0) => [->|/eqP q_neq0]/=; first by rewrite qlogp0. case: (q =P 1) => [->|/eqP q_neq1]/=; first by rewrite qlogp1. rewrite /qlogp; case: pickP => [x|/(_ (Ordinal (qlogp_lt q)))] /=. by case: ((x : nat) =P 0%N) => // ->; rewrite expr0 eq_sym (negPf q_neq1). by rewrite qlogp_qX // eqxx. Qed. Lemma qX_exp_neq0 i : 'qX ^+ i != 0 :> qT. Proof. by rewrite expf_eq0 negb_and qX_neq0 orbT. Qed. Lemma qX_exp_inj i j : i < #|qT|.-1 -> j < #|qT|.-1 -> 'qX ^+ i = 'qX ^+ j :> qT -> i = j. Proof. wlog iLj : i j / (i <= j)%N => [Hw|] iL jL Hqx. case: (ltngtP i j)=> // /ltnW iLj; first by apply: Hw. by apply/sym_equal/Hw. suff ji_eq0 : (j - i = 0)%N by rewrite -(subnK iLj) ji_eq0. case: ((j - i)%N =P 0%N) => // /eqP ji_neq0. have : j - i < #|qT|.-1 by apply: leq_ltn_trans (leq_subr _ _) jL. rewrite ltnNge => /negP[]. apply: dvdn_leq; first by rewrite lt0n. have HqXi : 'qX ^+ i != 0 :> qT by rewrite expf_eq0 (negPf qX_neq0) andbF. by apply/qX_order_dvd/(mulIf HqXi); rewrite mul1r -exprD subnK. Qed. Lemma powX_eq_mod i j : i = j %[mod #|qT|.-1] -> 'qX ^+ i = 'qX ^+ j :> qT. Proof. set n := _.-1 => iEj. rewrite [i](divn_eq i n) [j](divn_eq j n) !exprD ![(_ * n)%N]mulnC. by rewrite !exprM !qX_order_card !expr1n !mul1r iEj. Qed. Lemma qX_expK i : i < #|qT|.-1 -> qlogp ('qX ^+ i) = i. Proof. move=> iLF; apply: qX_exp_inj => //; first by apply: qlogp_lt. by rewrite qlogp_qX // expf_eq0 (negPf qX_neq0) andbF. Qed. Lemma qlogpD (q1 q2 : qT) : q1 != 0 -> q2 != 0 ->qlogp (q1 * q2) = ((qlogp q1 + qlogp q2) %% #|qT|.-1)%N. Proof. move=> q1_neq0 q2_neq0. apply: qX_exp_inj; [apply: qlogp_lt => // | rewrite ltn_mod // |]. rewrite -[RHS]mul1r -(expr1n _ ((qlogp q1 + qlogp q2) %/ #|qT|.-1)). rewrite -qX_order_card -exprM mulnC -exprD -divn_eq exprD !qlogp_qX //. by rewrite mulf_eq0 negb_or q1_neq0. Qed. End PrimitivePoly. Section Plogp. Variable F : finFieldType. Definition plogp (p q : {poly F}) := if boolP (primitive_poly p) is AltTrue Hh then qlogp ((in_qpoly p q) : {poly %/ p with primitive_mi Hh}) else 0%N. Lemma plogp_lt (p q : {poly F}) : 2 < size p -> plogp p q < #|{poly %/ p}|.-1. Proof. move=> /ltnW size_gt1. rewrite /plogp. case (boolP (primitive_poly p)) => // Hh; first by apply: qlogp_lt. by rewrite ltn_predRL (card_finNzRing_gt1 {poly %/ p}). Qed. Lemma plogp_X (p q : {poly F}) : 2 < size p -> primitive_poly p -> ~~ (p %| q) -> p %| q - 'X ^+ plogp p q. Proof. move=> sp_gt2 Hh pNDq. rewrite /plogp. case (boolP (primitive_poly p)) => // Hh'; last by case/negP: Hh'. have pM : p \is monic by case/and4P: Hh'. have pMi : monic_irreducible_poly p by apply: primitive_mi. set q' : {poly %/ p with primitive_mi Hh'} := in_qpoly p q. apply/modp_eq0P; rewrite modpD modpN; apply/eqP; rewrite subr_eq0; apply/eqP. rewrite !Pdiv.IdomainMonic.modpE //=. suff /val_eqP/eqP/= : 'qX ^+ qlogp q' = q'. rewrite /= [X in rmodp _ X]mk_monicE // => <-. by rewrite poly_of_qpolyX /= mk_monicE // [rmodp 'X p]rmodp_small ?size_polyX. apply: qlogp_qX => //. apply/eqP=> /val_eqP/eqP. rewrite /= mk_monicE // => /rmodp_eq0P; rewrite -dvdpE => pDq. by case/negP: pNDq. Qed. Lemma plogp0 (p : {poly F}) : 2 < size p -> plogp p 0 = 0%N. Proof. move=> sp_gt2; rewrite /plogp; case (boolP (primitive_poly p)) => // i. by rewrite in_qpoly0 qlogp0. Qed. Lemma plogp1 (p : {poly F}) : 2 < size p -> plogp p 1 = 0%N. Proof. move=> sp_gt2; rewrite /plogp; case (boolP (primitive_poly p)) => // i. suff->: in_qpoly p 1 = 1 by apply: qlogp1. apply/val_eqP/eqP; apply: in_qpoly_small. rewrite mk_monicE ?size_poly1 ?(leq_trans _ sp_gt2) //. by apply: primitive_mi. Qed. Lemma plogp_div_eq0 (p q : {poly F}) : 2 < size p -> (p %| q) -> plogp p q = 0%N. Proof. move=> sp_gt2; rewrite /plogp; case (boolP (primitive_poly p)) => // i pDq. suff-> : in_qpoly p q = 0 by apply: qlogp0. by apply/eqP; rewrite primitive_poly_in_qpoly_eq0. Qed. Lemma plogpD (p q1 q2 : {poly F}) : 2 < size p -> primitive_poly p -> ~~ (p %| q1) -> ~~ (p %| q2) -> plogp p (q1 * q2) = ((plogp p q1 + plogp p q2) %% #|{poly %/ p}|.-1)%N. Proof. move=> sp_gt2 Pp pNDq1 pNDq2. rewrite /plogp; case (boolP (primitive_poly p)) => [|/negP//] i /=. have pmi := primitive_mi i. by rewrite rmorphM qlogpD //= primitive_poly_in_qpoly_eq0. Qed. End Plogp.
mxrepresentation.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 finset fingroup morphism. From mathcomp Require Import perm automorphism quotient finalg action zmodp. From mathcomp Require Import commutator cyclic center pgroup matrix mxalgebra. From mathcomp Require Import mxalgebra mxpoly. (******************************************************************************) (* This file provides linkage between classic Group Theory and commutative *) (* algebra -- representation theory. Since general abstract linear algebra is *) (* still being sorted out, we develop the required theory here on the *) (* assumption that all vector spaces are matrix spaces, indeed that most are *) (* row matrix spaces; our representation theory is specialized to the latter *) (* case. We provide many definitions and results of representation theory: *) (* enveloping algebras, reducible, irreducible and absolutely irreducible *) (* representations, representation centralisers, submodules and kernels, *) (* simple and semisimple modules, the Schur lemmas, Maschke's theorem, *) (* components, socles, homomorphisms and isomorphisms, the Jacobson density *) (* theorem, similar representations, the Jordan-Holder theorem, Clifford's *) (* theorem and Wedderburn components, regular representations and the *) (* Wedderburn structure theorem for semisimple group rings, and the *) (* construction of a splitting field of an irreducible representation, and of *) (* reduced, tensored, and factored representations. *) (* mx_representation F G n == the Structure type for representations of G *) (* with n x n matrices with coefficients in F. Note that *) (* rG : mx_representation F G n coerces to a function from *) (* the element type of G to 'M_n, and conversely all such *) (* functions have a Canonical mx_representation. *) (* mx_repr G r <-> r : gT -> 'M_n defines a (matrix) group representation *) (* on G : {set gT} (Prop predicate). *) (* enveloping_algebra_mx rG == a #|G| x (n ^ 2) matrix whose rows are the *) (* mxvec encodings of the image of G under rG, and whose *) (* row space therefore encodes the enveloping algebra of *) (* the representation of G. *) (* rker rG == the kernel of the representation of r on G, i.e., the *) (* subgroup of elements of G mapped to the identity by rG. *) (* mx_faithful rG == the representation rG of G is faithful (its kernel is *) (* trivial). *) (* rfix_mx rG H == an n x n matrix whose row space is the set of vectors *) (* fixed (centralised) by the representation of H by rG. *) (* rcent rG A == the subgroup of G whose representation via rG commutes *) (* with the square matrix A. *) (* rcenter rG == the subgroup of G whose representation via rG consists of *) (* scalar matrices. *) (* centgmx rG f <=> f commutes with every matrix in the representation of G *) (* (i.e., f is a total rG-homomorphism). *) (* rstab rG U == the subgroup of G whose representation via r fixes all *) (* vectors in U, pointwise. *) (* rstabs rG U == the subgroup of G whose representation via r fixes the row *) (* space of U globally. *) (* mxmodule rG U <=> the row-space of the matrix U is a module (globally *) (* invariant) under the representation rG of G. *) (* max_submod rG U V <-> U < V and U is not a proper of any proper *) (* rG-submodule of V (if both U and V are modules, *) (* then U is a maximal proper submodule of V). *) (* mx_subseries rG Us <=> Us : seq 'M_n is a list of rG-modules *) (* mx_composition_series rG Us <-> Us is an increasing composition series *) (* for an rG-module (namely, last 0 Us). *) (* mxsimple rG M <-> M is a simple rG-module (i.e., minimal and nontrivial) *) (* This is a Prop predicate on square matrices. *) (* mxnonsimple rG U <-> U is constructively not a submodule, that is, U *) (* contains a proper nontrivial submodule. *) (* mxnonsimple_sat rG U == U is not a simple as an rG-module. *) (* This is a bool predicate, which requires a decField *) (* structure on the scalar field. *) (* mxsemisimple rG W <-> W is constructively a direct sum of simple modules. *) (* mxsplits rG V U <-> V splits over U in rG, i.e., U has an rG-invariant *) (* complement in V. *) (* mx_completely_reducible rG V <-> V splits over all its submodules; note *) (* that this is only classically equivalent to stating that *) (* V is semisimple. *) (* mx_irreducible rG <-> the representation rG is irreducible, i.e., the full *) (* module 1%:M of rG is simple. *) (* mx_absolutely_irreducible rG == the representation rG of G is absolutely *) (* irreducible: its enveloping algebra is the full matrix *) (* ring. This is only classically equivalent to the more *) (* standard ``rG does not reduce in any field extension''. *) (* group_splitting_field F G <-> F is a splitting field for the group G: *) (* every irreducible representation of G is absolutely *) (* irreducible. Any field can be embedded classically into a *) (* splitting field. *) (* group_closure_field F gT <-> F is a splitting field for every group *) (* G : {group gT}, and indeed for any section of such a *) (* group. This is a convenient constructive substitute for *) (* algebraic closures, that can be constructed classically. *) (* dom_hom_mx rG f == a square matrix encoding the set of vectors for which *) (* multiplication by the n x n matrix f commutes with the *) (* representation of G, i.e., the largest domain on which *) (* f is an rG homomorphism. *) (* mx_iso rG U V <-> U and V are (constructively) rG-isomorphic; this is *) (* a Prop predicate. *) (* mx_simple_iso rG U V == U and V are rG-isomorphic if one of them is *) (* simple; this is a bool predicate. *) (* cyclic_mx rG u == the cyclic rG-module generated by the row vector u *) (* annihilator_mx rG u == the annihilator of the row vector u in the *) (* enveloping algebra the representation rG. *) (* row_hom_mx rG u == the image of u by the set of all rG-homomorphisms on *) (* its cyclic module, or, equivalently, the null-space of the *) (* annihilator of u. *) (* component_mx rG M == when M is a simple rG-module, the component of M in *) (* the representation rG, i.e. the module generated by all *) (* the (simple) modules rG-isomorphic to M. *) (* socleType rG == a Structure that represents the type of all components *) (* of rG (more precisely, it coerces to such a type via *) (* socle_sort). For sG : socleType, values of type sG (to be *) (* exact, socle_sort sG) coerce to square matrices. For any *) (* representation rG we can construct sG : socleType rG *) (* classically; the socleType structure encapsulates this *) (* use of classical logic. *) (* DecSocleType rG == a socleType rG structure, for a representation over a *) (* decidable field type. DecSocleType rG is opaque. *) (* socle_base W == for W : (sG : socleType), a simple module whose *) (* component is W; socle_simple W and socle_module W are *) (* proofs that socle_base W is a simple module. *) (* socle_mult W == the multiplicity of socle_base W in W : sG. *) (* := \rank W %/ \rank (socle_base W) *) (* Socle sG == the Socle of rG, given sG : socleType rG, i.e., the *) (* (direct) sum of all the components of rG. *) (* mx_rsim rG rG' <-> rG and rG' are similar representations of the same *) (* group G. Note that rG and rG' must then have equal, but *) (* not necessarily convertible, degree. *) (* submod_repr modU == a representation of G on 'rV_(\rank U) equivalent to *) (* the restriction of rG to U (here modU : mxmodule rG U). *) (* socle_repr W := submod_repr (socle_module W) *) (* val/in_submod rG U == the projections resp. from/onto 'rV_(\rank U), *) (* that correspond to submod_repr r G U (these work both on *) (* vectors and row spaces). *) (* factmod_repr modV == a representation of G on 'rV_(\rank (cokermx V)) that *) (* is equivalent to the factor module 'rV_n / V induced by V *) (* and rG (here modV : mxmodule rG V). *) (* val/in_factmod rG U == the projections for factmod_repr r G U. *) (* section_repr modU modV == the restriction to in_factmod V U of the factor *) (* representation factmod_repr modV (for modU : mxmodule rG U *) (* and modV : mxmodule rG V); section_repr modU modV is *) (* irreducible iff max_submod rG U V. *) (* subseries_repr modUs i == the representation for the section module *) (* in_factmod (0 :: Us)`_i Us`_i, where *) (* modUs : mx_subseries rG Us. *) (* series_repr compUs i == the representation for the section module *) (* in_factmod (0 :: Us)`_i Us`_i, where *) (* compUs : mx_composition_series rG Us. The Jordan-Holder *) (* theorem asserts the uniqueness of the set of such *) (* representations, up to similarity and permutation. *) (* regular_repr F G == the regular F-representation of the group G. *) (* group_ring F G == a #|G| x #|G|^2 matrix that encodes the free group *) (* ring of G -- that is, the enveloping algebra of the *) (* regular F-representation of G. *) (* gring_index x == the index corresponding to x \in G in the matrix *) (* encoding of regular_repr and group_ring. *) (* gring_row A == the row vector corresponding to A \in group_ring F G in *) (* the regular FG-module. *) (* gring_proj x A == the 1 x 1 matrix holding the coefficient of x \in G in *) (* (A \in group_ring F G)%MS. *) (* gring_mx rG u == the image of a row vector u of the regular FG-module, *) (* in the enveloping algebra of another representation rG. *) (* gring_op rG A == the image of a matrix of the free group ring of G, *) (* in the enveloping algebra of rG. *) (* gset_mx F G C == the group sum of C in the free group ring of G -- the *) (* sum of the images of all the x \in C in group_ring F G. *) (* classg_base F G == a #|classes G| x #|G|^2 matrix whose rows encode the *) (* group sums of the conjugacy classes of G -- this is a *) (* basis of 'Z(group_ring F G)%MS. *) (* irrType F G == a type indexing irreducible representations of G over a *) (* field F, provided its characteristic does not divide the *) (* order of G; it also indexes Wedderburn subrings. *) (* := socleType (regular_repr F G) *) (* irr_repr i == the irreducible representation corresponding to the *) (* index i : irrType sG *) (* := socle_repr i as i coerces to a component matrix. *) (* 'n_i, irr_degree i == the degree of irr_repr i; the notation is only *) (* active after Open Scope group_ring_scope. *) (* linear_irr sG == the set of sG-indices of linear irreducible *) (* representations of G. *) (* irr_comp sG rG == the sG-index of the unique irreducible representation *) (* similar to rG, at least when rG is irreducible and the *) (* characteristic is coprime. *) (* irr_mode i z == the unique eigenvalue of irr_repr i z, at least when *) (* irr_repr i z is scalar (e.g., when z \in 'Z(G)). *) (* [1 sG]%irr == the index of the principal representation of G, in *) (* sG : irrType F G. The i argument of irr_repr, irr_degree *) (* and irr_mode is in the %irr scope. This notation may be *) (* replaced locally by an interpretation of 1%irr as [1 sG] *) (* for some specific irrType sG. *) (* 'R_i, Wedderburn_subring i == the subring (indeed, the component) of the *) (* free group ring of G corresponding to the component i : sG *) (* of the regular FG-module, where sG : irrType F g. In *) (* coprime characteristic the Wedderburn structure theorem *) (* asserts that the free group ring is the direct sum of *) (* these subrings; as with 'n_i above, the notation is only *) (* active in group_ring_scope. *) (* 'e_i, Wedderburn_id i == the projection of the identity matrix 1%:M on the *) (* Wedderburn subring of i : sG (with sG a socleType). In *) (* coprime characteristic this is the identity element of *) (* the subring, and the basis of its center if the field F is *) (* a splitting field. As 'R_i, 'e_i is in group_ring_scope. *) (* subg_repr rG sHG == the restriction to H of the representation rG of G; *) (* here sHG : H \subset G. *) (* eqg_repr rG eqHG == the representation rG of G viewed a a representation *) (* of H; here eqHG : G == H. *) (* morphpre_repr f rG == the representation of f @*^-1 G obtained by *) (* composing the group morphism f with rG. *) (* morphim_repr rGf sGD == the representation of G induced by a *) (* representation rGf of f @* G; here sGD : G \subset D where *) (* D is the domain of the group morphism f. *) (* rconj_repr rG uB == the conjugate representation x |-> B * rG x * B^-1; *) (* here uB : B \in unitmx. *) (* quo_repr sHK nHG == the representation of G / H induced by rG, given *) (* sHK : H \subset rker rG, and nHG : G \subset 'N(H). *) (* kquo_repr rG == the representation induced on G / rker rG by rG. *) (* map_repr f rG == the representation f \o rG, whose module is the tensor *) (* product of the module of rG with the extension field into *) (* which f : {rmorphism F -> Fstar} embeds F. *) (* 'Cl%act == the transitive action of G on the Wedderburn components of *) (* H, with nsGH : H <| G, given by Clifford's theorem. More *) (* precisely this is a total action of G on socle_sort sH, *) (* where sH : socleType (subg_repr rG (normal_sub sGH)). *) (* We build on the MatrixFormula toolkit to define decision procedures for *) (* the reducibility property: *) (* mxmodule_form rG U == a formula asserting that the interpretation of U is *) (* a module of the representation rG. *) (* mxnonsimple_form rG U == a formula asserting that the interpretation of U *) (* contains a proper nontrivial rG-module. *) (* mxnonsimple_sat rG U <=> mxnonsimple_form rG U is satisfied. *) (* More involved constructions are encapsulated in two Coq submodules: *) (* MatrixGenField == a module that encapsulates the lengthy details of the *) (* construction of appropriate extension fields. We assume we *) (* have an irreducible representation rG of a group G, and a *) (* non-scalar matrix A that centralises rG(G), as this data *) (* is readily extracted from the Jacobson density theorem. It *) (* then follows from Schur's lemma that the ring generated by *) (* A is a field on which the extension of the representation *) (* rG of G is reducible. Note that this is equivalent to the *) (* more traditional quotient of the polynomial ring by an *) (* irreducible polynomial (the minimal polynomial of A), but *) (* much better suited to our needs. *) (* Here are the main definitions of MatrixGenField; they all have three *) (* proofs as arguments: (implicit) rG : mx_repr n G, irrG : mx_irreducible rG *) (* and cGA : centgmx rG A. These ensure the validity of the construction and *) (* allow us to define Canonical instances; we assume degree_mxminpoly A > 1 *) (* (which is equivalent to ~~ is_scalar_mx A) only to prove reducibility. *) (* + gen_of irrG cGA == the carrier type of the field generated by A. It is *) (* at least equipped with a fieldType structure; we also *) (* propagate any decFieldType/finFieldType structures on the *) (* original field. *) (* + gen irrG cGA == the morphism injecting into gen_of irrG cGA. *) (* + groot irrG cGA == the root of mxminpoly A in the gen_of irrG cGA field. *) (* + pval x, rVval x, mxval x == the interpretation of x : gen_of irrG cGA *) (* as a polynomial, a row vector, and a matrix, respectively. *) (* Both irrG and cGA are implicit arguments here. *) (* + gen_repr irrG cGA == an alternative to the field extension *) (* representation, which consists in reconsidering the *) (* original module as a module over the new gen_of field, *) (* thereby DIVIDING the original dimension n by the degree of *) (* the minimal polynomial of A. This can be simpler than the *) (* extension method, is actually required by the proof that *) (* odd groups are p-stable (B & G 6.1-2, and Appendix A), but *) (* is only applicable if G is the LARGEST group represented *) (* by rG (e.g., NOT for B & G 2.6). *) (* + gen_dim A == the dimension of gen_repr irrG cGA (only depends on A). *) (* + in_gen irrG cGA W == the ROWWISE image of a matrix W : 'M[F]_(m, n), *) (* i.e., interpreting W as a sequence of m tow vectors, *) (* under the bijection from rG to gen_repr irrG cGA. *) (* The sequence length m is a maximal implicit argument *) (* passed between the explicit argument cGA and W. *) (* + val_gen W == the ROWWISE image of an 'M[gen_of irrG cGA]_(m, gen_dim A) *) (* matrix W under the bijection from gen_repr irrG cGA to rG. *) (* + rowval_gen W == the ROWSPACE image of W under the bijection from *) (* gen_repr irrG cGA to rG, i.e., a 'M[F]_n matrix whose row *) (* space is the image of the row space of W. *) (* This is the A-ideal generated by val_gen W. *) (* + gen_sat e f <=> f : GRing.formula (gen_of irrG cGA) is satisfied in *) (* environment e : seq (gen_of irrG cGA), provided F has a *) (* decFieldType structure. *) (* + gen_env e, gen_term t, gen_form f == interpretations of environments, *) (* terms, and RING formulas over gen_of irrG cGA as row *) (* vector formulae, used to construct gen_sat. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope irrType_scope. Declare Scope group_ring_scope. Import GroupScope GRing.Theory. Local Open Scope ring_scope. Reserved Notation "''n_' i" (at level 8, i at level 2, format "''n_' i"). Reserved Notation "''R_' i" (at level 8, i at level 2, format "''R_' i"). Reserved Notation "''e_' i" (at level 8, i at level 2, format "''e_' i"). Delimit Scope irrType_scope with irr. Section RingRepr. Variable R : comUnitRingType. Section OneRepresentation. Variable gT : finGroupType. Definition mx_repr (G : {set gT}) n (r : gT -> 'M[R]_n) := r 1%g = 1%:M /\ {in G &, {morph r : x y / (x * y)%g >-> x *m y}}. Structure mx_representation G n := MxRepresentation { repr_mx :> gT -> 'M_n; _ : mx_repr G repr_mx }. Variables (G : {group gT}) (n : nat) (rG : mx_representation G n). Arguments rG _%_group_scope : extra scopes. Lemma repr_mx1 : rG 1 = 1%:M. Proof. by case: rG => r []. Qed. Lemma repr_mxM : {in G &, {morph rG : x y / (x * y)%g >-> x *m y}}. Proof. by case: rG => r []. Qed. Lemma repr_mxK m x : x \in G -> cancel ((@mulmx R m n n)^~ (rG x)) (mulmx^~ (rG x^-1)). Proof. by move=> Gx U; rewrite -mulmxA -repr_mxM ?groupV // mulgV repr_mx1 mulmx1. Qed. Lemma repr_mxKV m x : x \in G -> cancel ((@mulmx R m n n)^~ (rG x^-1)) (mulmx^~ (rG x)). Proof. by rewrite -groupV -{3}[x]invgK; apply: repr_mxK. Qed. Lemma repr_mx_unit x : x \in G -> rG x \in unitmx. Proof. by move=> Gx; case/mulmx1_unit: (repr_mxKV Gx 1%:M). Qed. Lemma repr_mxV : {in G, {morph rG : x / x^-1%g >-> invmx x}}. Proof. by move=> x Gx /=; rewrite -[rG x^-1](mulKmx (repr_mx_unit Gx)) mulmxA repr_mxK. Qed. (* This is only used in the group ring construction below, as we only have *) (* developped the theory of matrix subalgebras for F-algebras. *) Definition enveloping_algebra_mx := \matrix_(i < #|G|) mxvec (rG (enum_val i)). Section Stabiliser. Variables (m : nat) (U : 'M[R]_(m, n)). Definition rstab := [set x in G | U *m rG x == U]. Lemma rstab_sub : rstab \subset G. Proof. by apply/subsetP=> x; case/setIdP. Qed. Lemma rstab_group_set : group_set rstab. Proof. apply/group_setP; rewrite inE group1 repr_mx1 mulmx1; split=> //= x y. case/setIdP=> Gx cUx; case/setIdP=> Gy cUy; rewrite inE repr_mxM ?groupM //. by rewrite mulmxA (eqP cUx). Qed. Canonical rstab_group := Group rstab_group_set. End Stabiliser. (* Centralizer subgroup and central homomorphisms. *) Section CentHom. Variable f : 'M[R]_n. Definition rcent := [set x in G | f *m rG x == rG x *m f]. Lemma rcent_sub : rcent \subset G. Proof. by apply/subsetP=> x; case/setIdP. Qed. Lemma rcent_group_set : group_set rcent. Proof. apply/group_setP; rewrite inE group1 repr_mx1 mulmx1 mul1mx; split=> //= x y. case/setIdP=> Gx; move/eqP=> cfx; case/setIdP=> Gy; move/eqP=> cfy. by rewrite inE repr_mxM ?groupM //= -mulmxA -cfy !mulmxA cfx. Qed. Canonical rcent_group := Group rcent_group_set. Definition centgmx := G \subset rcent. Lemma centgmxP : reflect (forall x, x \in G -> f *m rG x = rG x *m f) centgmx. Proof. by apply: (iffP subsetP) => cGf x Gx; have /[!(inE, Gx)] /eqP := cGf x Gx. Qed. End CentHom. (* Representation kernel, and faithful representations. *) Definition rker := rstab 1%:M. Canonical rker_group := Eval hnf in [group of rker]. Lemma rkerP x : reflect (x \in G /\ rG x = 1%:M) (x \in rker). Proof. by apply: (iffP setIdP) => [] [->]; move/eqP; rewrite mul1mx. Qed. Lemma rker_norm : G \subset 'N(rker). Proof. apply/subsetP=> x Gx; rewrite inE sub_conjg; apply/subsetP=> y. case/rkerP=> Gy ry1; rewrite mem_conjgV !inE groupJ //=. by rewrite !repr_mxM ?groupM ?groupV // ry1 !mulmxA mulmx1 repr_mxKV. Qed. Lemma rker_normal : rker <| G. Proof. by rewrite /normal rstab_sub rker_norm. Qed. Definition mx_faithful := rker \subset [1]. Lemma mx_faithful_inj : mx_faithful -> {in G &, injective rG}. Proof. move=> ffulG x y Gx Gy eq_rGxy; apply/eqP; rewrite eq_mulgV1 -in_set1. rewrite (subsetP ffulG) // inE groupM ?repr_mxM ?groupV //= eq_rGxy. by rewrite mulmxA repr_mxK. Qed. Lemma rker_linear : n = 1 -> G^`(1)%g \subset rker. Proof. move=> n1; rewrite gen_subG; apply/subsetP=> xy; case/imset2P=> x y Gx Gy ->. rewrite !inE groupR //= /commg mulgA -invMg repr_mxM ?groupV ?groupM //. rewrite mulmxA (can2_eq (repr_mxK _) (repr_mxKV _)) ?groupM //. rewrite !repr_mxV ?repr_mxM ?groupM //; move: (rG x) (rG y). by rewrite n1 => rx ry; rewrite (mx11_scalar rx) scalar_mxC. Qed. (* Representation center. *) Definition rcenter := [set g in G | is_scalar_mx (rG g)]. Fact rcenter_group_set : group_set rcenter. Proof. apply/group_setP; split=> [|x y]. by rewrite inE group1 repr_mx1 scalar_mx_is_scalar. move=> /setIdP[Gx /is_scalar_mxP[a defx]] /setIdP[Gy /is_scalar_mxP[b defy]]. by rewrite !inE groupM ?repr_mxM // defx defy -scalar_mxM ?scalar_mx_is_scalar. Qed. Canonical rcenter_group := Group rcenter_group_set. Lemma rcenter_normal : rcenter <| G. Proof. rewrite /normal /rcenter {1}setIdE subsetIl; apply/subsetP=> x Gx /[1!inE]. apply/subsetP=> _ /imsetP[y /setIdP[Gy /is_scalar_mxP[c rGy]] ->]. rewrite inE !repr_mxM ?groupM ?groupV //= mulmxA rGy scalar_mxC repr_mxKV //. exact: scalar_mx_is_scalar. Qed. End OneRepresentation. Arguments rkerP {gT G n rG x}. Section Proper. Variables (gT : finGroupType) (G : {group gT}) (n' : nat). Local Notation n := n'.+1. Variable rG : mx_representation G n. Lemma repr_mxMr : {in G &, {morph rG : x y / (x * y)%g >-> x * y}}. Proof. exact: repr_mxM. Qed. Lemma repr_mxVr : {in G, {morph rG : x / (x^-1)%g >-> x^-1}}. Proof. exact: repr_mxV. Qed. Lemma repr_mx_unitr x : x \in G -> rG x \is a GRing.unit. Proof. exact: repr_mx_unit. Qed. Lemma repr_mxX m : {in G, {morph rG : x / (x ^+ m)%g >-> x ^+ m}}. Proof. elim: m => [|m IHm] x Gx; rewrite /= ?repr_mx1 // expgS exprS -IHm //. by rewrite repr_mxM ?groupX. Qed. End Proper. Section ChangeGroup. Variables (gT : finGroupType) (G H : {group gT}) (n : nat). Variables (rG : mx_representation G n). Section SubGroup. Hypothesis sHG : H \subset G. Lemma subg_mx_repr : mx_repr H rG. Proof. by split=> [|x y Hx Hy]; rewrite (repr_mx1, repr_mxM) ?(subsetP sHG). Qed. Definition subg_repr := MxRepresentation subg_mx_repr. Local Notation rH := subg_repr. Lemma rcent_subg U : rcent rH U = H :&: rcent rG U. Proof. by apply/setP=> x; rewrite !inE andbA -in_setI (setIidPl sHG). Qed. Section Stabiliser. Variables (m : nat) (U : 'M[R]_(m, n)). Lemma rstab_subg : rstab rH U = H :&: rstab rG U. Proof. by apply/setP=> x; rewrite !inE andbA -in_setI (setIidPl sHG). Qed. End Stabiliser. Lemma rker_subg : rker rH = H :&: rker rG. Proof. exact: rstab_subg. Qed. Lemma subg_mx_faithful : mx_faithful rG -> mx_faithful rH. Proof. by apply: subset_trans; rewrite rker_subg subsetIr. Qed. End SubGroup. Section SameGroup. Hypothesis eqGH : G :==: H. Lemma eqg_repr_proof : H \subset G. Proof. by rewrite (eqP eqGH). Qed. Definition eqg_repr := subg_repr eqg_repr_proof. Local Notation rH := eqg_repr. Lemma rcent_eqg U : rcent rH U = rcent rG U. Proof. by rewrite rcent_subg -(eqP eqGH) (setIidPr _) ?rcent_sub. Qed. Section Stabiliser. Variables (m : nat) (U : 'M[R]_(m, n)). Lemma rstab_eqg : rstab rH U = rstab rG U. Proof. by rewrite rstab_subg -(eqP eqGH) (setIidPr _) ?rstab_sub. Qed. End Stabiliser. Lemma rker_eqg : rker rH = rker rG. Proof. exact: rstab_eqg. Qed. Lemma eqg_mx_faithful : mx_faithful rH = mx_faithful rG. Proof. by rewrite /mx_faithful rker_eqg. Qed. End SameGroup. End ChangeGroup. Section Morphpre. Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}). Variables (G : {group rT}) (n : nat) (rG : mx_representation G n). Lemma morphpre_mx_repr : mx_repr (f @*^-1 G) (rG \o f). Proof. split=> [|x y]; first by rewrite /= morph1 repr_mx1. case/morphpreP=> Dx Gfx; case/morphpreP=> Dy Gfy. by rewrite /= morphM ?repr_mxM. Qed. Canonical morphpre_repr := MxRepresentation morphpre_mx_repr. Local Notation rGf := morphpre_repr. Section Stabiliser. Variables (m : nat) (U : 'M[R]_(m, n)). Lemma rstab_morphpre : rstab rGf U = f @*^-1 (rstab rG U). Proof. by apply/setP=> x; rewrite !inE andbA. Qed. End Stabiliser. Lemma rker_morphpre : rker rGf = f @*^-1 (rker rG). Proof. exact: rstab_morphpre. Qed. End Morphpre. Section Morphim. Variables (aT rT : finGroupType) (G D : {group aT}) (f : {morphism D >-> rT}). Variables (n : nat) (rGf : mx_representation (f @* G) n). Definition morphim_mx of G \subset D := fun x => rGf (f x). Hypothesis sGD : G \subset D. Lemma morphim_mxE x : morphim_mx sGD x = rGf (f x). Proof. by []. Qed. Let sG_f'fG : G \subset f @*^-1 (f @* G). Proof. by rewrite -sub_morphim_pre. Qed. Lemma morphim_mx_repr : mx_repr G (morphim_mx sGD). Proof. exact: subg_mx_repr (morphpre_repr f rGf) sG_f'fG. Qed. Canonical morphim_repr := MxRepresentation morphim_mx_repr. Local Notation rG := morphim_repr. Section Stabiliser. Variables (m : nat) (U : 'M[R]_(m, n)). Lemma rstab_morphim : rstab rG U = G :&: f @*^-1 rstab rGf U. Proof. by rewrite -rstab_morphpre -(rstab_subg _ sG_f'fG). Qed. End Stabiliser. Lemma rker_morphim : rker rG = G :&: f @*^-1 (rker rGf). Proof. exact: rstab_morphim. Qed. End Morphim. Section Conjugate. Variables (gT : finGroupType) (G : {group gT}) (n : nat). Variables (rG : mx_representation G n) (B : 'M[R]_n). Definition rconj_mx of B \in unitmx := fun x => B *m rG x *m invmx B. Hypothesis uB : B \in unitmx. Lemma rconj_mx_repr : mx_repr G (rconj_mx uB). Proof. split=> [|x y Gx Gy]; rewrite /rconj_mx ?repr_mx1 ?mulmx1 ?mulmxV ?repr_mxM //. by rewrite !mulmxA mulmxKV. Qed. Canonical rconj_repr := MxRepresentation rconj_mx_repr. Local Notation rGB := rconj_repr. Lemma rconj_mxE x : rGB x = B *m rG x *m invmx B. Proof. by []. Qed. Lemma rconj_mxJ m (W : 'M_(m, n)) x : W *m rGB x *m B = W *m B *m rG x. Proof. by rewrite !mulmxA mulmxKV. Qed. Lemma rcent_conj A : rcent rGB A = rcent rG (invmx B *m A *m B). Proof. apply/setP=> x; rewrite !inE /= rconj_mxE !mulmxA. rewrite (can2_eq (mulmxKV uB) (mulmxK uB)) -!mulmxA. by rewrite -(can2_eq (mulKVmx uB) (mulKmx uB)). Qed. Lemma rstab_conj m (U : 'M_(m, n)) : rstab rGB U = rstab rG (U *m B). Proof. apply/setP=> x; rewrite !inE /= rconj_mxE !mulmxA. by rewrite (can2_eq (mulmxKV uB) (mulmxK uB)). Qed. Lemma rker_conj : rker rGB = rker rG. Proof. apply/setP=> x; rewrite !inE /= mulmxA (can2_eq (mulmxKV uB) (mulmxK uB)). by rewrite mul1mx -scalar_mxC (inj_eq (can_inj (mulKmx uB))) mul1mx. Qed. Lemma conj_mx_faithful : mx_faithful rGB = mx_faithful rG. Proof. by rewrite /mx_faithful rker_conj. Qed. End Conjugate. Section Quotient. Variables (gT : finGroupType) (G : {group gT}) (n : nat). Variable rG : mx_representation G n. Definition quo_mx (H : {set gT}) of H \subset rker rG & G \subset 'N(H) := fun Hx : coset_of H => rG (repr Hx). Section SubQuotient. Variable H : {group gT}. Hypotheses (krH : H \subset rker rG) (nHG : G \subset 'N(H)). Let nHGs := subsetP nHG. Lemma quo_mx_coset x : x \in G -> quo_mx krH nHG (coset H x) = rG x. Proof. move=> Gx; rewrite /quo_mx val_coset ?nHGs //; case: repr_rcosetP => z Hz. by case/rkerP: (subsetP krH z Hz) => Gz rz1; rewrite repr_mxM // rz1 mul1mx. Qed. Lemma quo_mx_repr : mx_repr (G / H)%g (quo_mx krH nHG). Proof. split=> [|Hx Hy]; first by rewrite /quo_mx repr_coset1 repr_mx1. case/morphimP=> x Nx Gx ->{Hx}; case/morphimP=> y Ny Gy ->{Hy}. by rewrite -morphM // !quo_mx_coset ?groupM ?repr_mxM. Qed. Canonical quo_repr := MxRepresentation quo_mx_repr. Local Notation rGH := quo_repr. Lemma quo_repr_coset x : x \in G -> rGH (coset H x) = rG x. Proof. exact: quo_mx_coset. Qed. Lemma rcent_quo A : rcent rGH A = (rcent rG A / H)%g. Proof. apply/setP=> Hx /[!inE]; apply/andP/idP=> [[]|]; case/morphimP=> x Nx Gx ->{Hx}. by rewrite quo_repr_coset // => cAx; rewrite mem_morphim // inE Gx. by case/setIdP: Gx => Gx cAx; rewrite quo_repr_coset ?mem_morphim. Qed. Lemma rstab_quo m (U : 'M_(m, n)) : rstab rGH U = (rstab rG U / H)%g. Proof. apply/setP=> Hx /[!inE]; apply/andP/idP=> [[]|]; case/morphimP=> x Nx Gx ->{Hx}. by rewrite quo_repr_coset // => nUx; rewrite mem_morphim // inE Gx. by case/setIdP: Gx => Gx nUx; rewrite quo_repr_coset ?mem_morphim. Qed. Lemma rker_quo : rker rGH = (rker rG / H)%g. Proof. exact: rstab_quo. Qed. End SubQuotient. Definition kquo_mx := quo_mx (subxx (rker rG)) (rker_norm rG). Lemma kquo_mxE : kquo_mx = quo_mx (subxx (rker rG)) (rker_norm rG). Proof. by []. Qed. Canonical kquo_repr := @MxRepresentation _ _ _ kquo_mx (quo_mx_repr _ _). Lemma kquo_repr_coset x : x \in G -> kquo_repr (coset (rker rG) x) = rG x. Proof. exact: quo_repr_coset. Qed. Lemma kquo_mx_faithful : mx_faithful kquo_repr. Proof. by rewrite /mx_faithful rker_quo trivg_quotient. Qed. End Quotient. Section Regular. Variables (gT : finGroupType) (G : {group gT}). Definition gcard := #|G|. (* hides the projections to set *) Local Notation nG := gcard. Definition gring_index (x : gT) := enum_rank_in (group1 G) x. Lemma gring_valK : cancel enum_val gring_index. Proof. exact: enum_valK_in. Qed. Lemma gring_indexK : {in G, cancel gring_index enum_val}. Proof. exact: enum_rankK_in. Qed. Definition regular_mx x : 'M[R]_nG := \matrix_i delta_mx 0 (gring_index (enum_val i * x)). Lemma regular_mx_repr : mx_repr G regular_mx. Proof. split=> [|x y Gx Gy]; apply/row_matrixP=> i; rewrite !rowK. by rewrite mulg1 row1 gring_valK. by rewrite row_mul rowK -rowE rowK mulgA gring_indexK // groupM ?enum_valP. Qed. Canonical regular_repr := MxRepresentation regular_mx_repr. Local Notation aG := regular_repr. Definition group_ring := enveloping_algebra_mx aG. Local Notation R_G := group_ring. Definition gring_row : 'M[R]_nG -> 'rV_nG := row (gring_index 1). HB.instance Definition _ := GRing.Linear.on gring_row. Lemma gring_row_mul A B : gring_row (A *m B) = gring_row A *m B. Proof. exact: row_mul. Qed. Definition gring_proj x := row (gring_index x) \o trmx \o gring_row. HB.instance Definition _ x := GRing.Linear.on (gring_proj x). Lemma gring_projE : {in G &, forall x y, gring_proj x (aG y) = (x == y)%:R}. Proof. move=> x y Gx Gy; rewrite /gring_proj /= /gring_row rowK gring_indexK //=. rewrite mul1g trmx_delta rowE mul_delta_mx_cond [delta_mx 0 0]mx11_scalar !mxE. by rewrite /= -(inj_eq (can_inj gring_valK)) !gring_indexK. Qed. Lemma regular_mx_faithful : mx_faithful aG. Proof. apply/subsetP=> x /setIdP[Gx]. rewrite mul1mx inE => /eqP/(congr1 (gring_proj 1%g)). rewrite -(repr_mx1 aG) !gring_projE ?group1 // eqxx eq_sym. by case: (x == _) => // /eqP; rewrite eq_sym oner_eq0. Qed. Section GringMx. Variables (n : nat) (rG : mx_representation G n). Definition gring_mx := vec_mx \o mulmxr (enveloping_algebra_mx rG). HB.instance Definition _ := GRing.Linear.on gring_mx. Lemma gring_mxJ a x : x \in G -> gring_mx (a *m aG x) = gring_mx a *m rG x. Proof. move=> Gx; rewrite /gring_mx /= ![a *m _]mulmx_sum_row. rewrite !(mulmx_suml, linear_sum); apply: eq_bigr => i _. rewrite linearZ -!scalemxAl linearZ /=; congr (_ *: _) => {a}. rewrite !rowK /= !mxvecK -rowE rowK mxvecK. by rewrite gring_indexK ?groupM ?repr_mxM ?enum_valP. Qed. End GringMx. Lemma gring_mxK : cancel (gring_mx aG) gring_row. Proof. move=> a; rewrite /gring_mx /= mulmx_sum_row !linear_sum /= [RHS]row_sum_delta. apply: eq_bigr => i _; rewrite 2!linearZ /= /gring_row !(rowK, mxvecK). by rewrite gring_indexK // mul1g gring_valK. Qed. Section GringOp. Variables (n : nat) (rG : mx_representation G n). Definition gring_op := gring_mx rG \o gring_row. HB.instance Definition _ := GRing.Linear.on gring_op. Lemma gring_opE a : gring_op a = gring_mx rG (gring_row a). Proof. by []. Qed. Lemma gring_opG x : x \in G -> gring_op (aG x) = rG x. Proof. move=> Gx; rewrite gring_opE /gring_row rowK gring_indexK // mul1g. by rewrite /gring_mx /= -rowE rowK mxvecK gring_indexK. Qed. Lemma gring_op1 : gring_op 1%:M = 1%:M. Proof. by rewrite -(repr_mx1 aG) gring_opG ?repr_mx1. Qed. Lemma gring_opJ A b : gring_op (A *m gring_mx aG b) = gring_op A *m gring_mx rG b. Proof. rewrite /gring_mx /= ![b *m _]mulmx_sum_row !linear_sum. apply: eq_bigr => i _; rewrite !linearZ /= !rowK !mxvecK. by rewrite gring_opE gring_row_mul gring_mxJ ?enum_valP. Qed. Lemma gring_op_mx b : gring_op (gring_mx aG b) = gring_mx rG b. Proof. by rewrite -[_ b]mul1mx gring_opJ gring_op1 mul1mx. Qed. Lemma gring_mxA a b : gring_mx rG (a *m gring_mx aG b) = gring_mx rG a *m gring_mx rG b. Proof. by rewrite -(gring_op_mx a) -gring_opJ gring_opE gring_row_mul gring_mxK. Qed. End GringOp. End Regular. End RingRepr. Arguments mx_representation R {gT} G%_g n%_N. Arguments mx_repr {R gT} G%_g {n%_N} r. Arguments group_ring R {gT} G%_g. Arguments regular_repr R {gT} G%_g. Arguments centgmxP {R gT G n rG f}. Arguments rkerP {R gT G n rG x}. Arguments repr_mxK {R gT G%_G n%_N} rG {m%_N} [x%_g] Gx. Arguments repr_mxKV {R gT G%_G n%_N} rG {m%_N} [x%_g] Gx. Arguments gring_valK {gT G%_G} i%_R : rename. Arguments gring_indexK {gT G%_G} x%_g. Arguments gring_mxK {R gT G%_G} v%_R : rename. Section ChangeOfRing. Variables (aR rR : comUnitRingType) (f : {rmorphism aR -> rR}). Local Notation "A ^f" := (map_mx (GRing.RMorphism.sort f) A) : ring_scope. Variables (gT : finGroupType) (G : {group gT}). Lemma map_regular_mx x : (regular_mx aR G x)^f = regular_mx rR G x. Proof. by apply/matrixP=> i j; rewrite !mxE rmorph_nat. Qed. Lemma map_gring_row (A : 'M_#|G|) : (gring_row A)^f = gring_row A^f. Proof. by rewrite map_row. Qed. Lemma map_gring_proj x (A : 'M_#|G|) : (gring_proj x A)^f = gring_proj x A^f. Proof. by rewrite map_row -map_trmx map_gring_row. Qed. Section OneRepresentation. Variables (n : nat) (rG : mx_representation aR G n). Definition map_repr_mx (f0 : aR -> rR) rG0 (g : gT) : 'M_n := map_mx f0 (rG0 g). Lemma map_mx_repr : mx_repr G (map_repr_mx f rG). Proof. split=> [|x y Gx Gy]; first by rewrite /map_repr_mx repr_mx1 map_mx1. by rewrite -map_mxM -repr_mxM. Qed. Canonical map_repr := MxRepresentation map_mx_repr. Local Notation rGf := map_repr. Lemma map_reprE x : rGf x = (rG x)^f. Proof. by []. Qed. Lemma map_reprJ m (A : 'M_(m, n)) x : (A *m rG x)^f = A^f *m rGf x. Proof. exact: map_mxM. Qed. Lemma map_enveloping_algebra_mx : (enveloping_algebra_mx rG)^f = enveloping_algebra_mx rGf. Proof. by apply/row_matrixP=> i; rewrite -map_row !rowK map_mxvec. Qed. Lemma map_gring_mx a : (gring_mx rG a)^f = gring_mx rGf a^f. Proof. by rewrite map_vec_mx map_mxM map_enveloping_algebra_mx. Qed. Lemma map_gring_op A : (gring_op rG A)^f = gring_op rGf A^f. Proof. by rewrite map_gring_mx map_gring_row. Qed. End OneRepresentation. Lemma map_regular_repr : map_repr (regular_repr aR G) =1 regular_repr rR G. Proof. exact: map_regular_mx. Qed. Lemma map_group_ring : (group_ring aR G)^f = group_ring rR G. Proof. rewrite map_enveloping_algebra_mx; apply/row_matrixP=> i. by rewrite !rowK map_regular_repr. Qed. (* Stabilisers, etc, are only mapped properly for fields. *) End ChangeOfRing. Section FieldRepr. Variable F : fieldType. Section OneRepresentation. Variable gT : finGroupType. Variables (G : {group gT}) (n : nat) (rG : mx_representation F G n). Arguments rG _%_group_scope : extra scopes. Local Notation E_G := (enveloping_algebra_mx rG). Lemma repr_mx_free x : x \in G -> row_free (rG x). Proof. by move=> Gx; rewrite row_free_unit repr_mx_unit. Qed. Section Stabilisers. Variables (m : nat) (U : 'M[F]_(m, n)). Definition rstabs := [set x in G | U *m rG x <= U]%MS. Lemma rstabs_sub : rstabs \subset G. Proof. by apply/subsetP=> x /setIdP[]. Qed. Lemma rstabs_group_set : group_set rstabs. Proof. apply/group_setP; rewrite inE group1 repr_mx1 mulmx1. split=> //= x y /setIdP[Gx nUx] /setIdP[Gy]; rewrite inE repr_mxM ?groupM //. by apply: submx_trans; rewrite mulmxA submxMr. Qed. Canonical rstabs_group := Group rstabs_group_set. Lemma rstab_act x m1 (W : 'M_(m1, n)) : x \in rstab rG U -> (W <= U)%MS -> W *m rG x = W. Proof. by case/setIdP=> _ /eqP cUx /submxP[w ->]; rewrite -mulmxA cUx. Qed. Lemma rstabs_act x m1 (W : 'M_(m1, n)) : x \in rstabs -> (W <= U)%MS -> (W *m rG x <= U)%MS. Proof. by case/setIdP=> [_ nUx] sWU; apply: submx_trans nUx; apply: submxMr. Qed. Definition mxmodule := G \subset rstabs. Lemma mxmoduleP : reflect {in G, forall x, U *m rG x <= U}%MS mxmodule. Proof. by apply: (iffP subsetP) => modU x Gx; have:= modU x Gx; rewrite !inE ?Gx. Qed. End Stabilisers. Arguments mxmoduleP {m U}. Lemma rstabS m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, n)) : (U <= V)%MS -> rstab rG V \subset rstab rG U. Proof. case/submxP=> u ->; apply/subsetP=> x. by rewrite !inE => /andP[-> /= /eqP cVx]; rewrite -mulmxA cVx. Qed. Lemma eqmx_rstab m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, n)) : (U :=: V)%MS -> rstab rG U = rstab rG V. Proof. by move=> eqUV; apply/eqP; rewrite eqEsubset !rstabS ?eqUV. Qed. Lemma eqmx_rstabs m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, n)) : (U :=: V)%MS -> rstabs U = rstabs V. Proof. by move=> eqUV; apply/setP=> x; rewrite !inE eqUV (eqmxMr _ eqUV). Qed. Lemma eqmx_module m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, n)) : (U :=: V)%MS -> mxmodule U = mxmodule V. Proof. by move=> eqUV; rewrite /mxmodule (eqmx_rstabs eqUV). Qed. Lemma mxmodule0 m : mxmodule (0 : 'M_(m, n)). Proof. by apply/mxmoduleP=> x _; rewrite mul0mx. Qed. Lemma mxmodule1 : mxmodule 1%:M. Proof. by apply/mxmoduleP=> x _; rewrite submx1. Qed. Lemma mxmodule_trans m1 m2 (U : 'M_(m1, n)) (W : 'M_(m2, n)) x : mxmodule U -> x \in G -> (W <= U -> W *m rG x <= U)%MS. Proof. by move=> modU Gx sWU; apply: submx_trans (mxmoduleP modU x Gx); apply: submxMr. Qed. Lemma mxmodule_eigenvector m (U : 'M_(m, n)) : mxmodule U -> \rank U = 1 -> {u : 'rV_n & {a | (U :=: u)%MS & {in G, forall x, u *m rG x = a x *: u}}}. Proof. move=> modU linU; set u := nz_row U; exists u. have defU: (U :=: u)%MS. apply/eqmxP; rewrite andbC -(geq_leqif (mxrank_leqif_eq _)) ?nz_row_sub //. by rewrite linU lt0n mxrank_eq0 nz_row_eq0 -mxrank_eq0 linU. pose a x := (u *m rG x *m pinvmx u) 0 0; exists a => // x Gx. by rewrite -mul_scalar_mx -mx11_scalar mulmxKpV // -defU mxmodule_trans ?defU. Qed. Lemma addsmx_module m1 m2 U V : @mxmodule m1 U -> @mxmodule m2 V -> mxmodule (U + V)%MS. Proof. move=> modU modV; apply/mxmoduleP=> x Gx. by rewrite addsmxMr addsmxS ?(mxmoduleP _ x Gx). Qed. Lemma sumsmx_module I r (P : pred I) U : (forall i, P i -> mxmodule (U i)) -> mxmodule (\sum_(i <- r | P i) U i)%MS. Proof. by move=> modU; elim/big_ind: _; [apply: mxmodule0 | apply: addsmx_module | ]. Qed. Lemma capmx_module m1 m2 U V : @mxmodule m1 U -> @mxmodule m2 V -> mxmodule (U :&: V)%MS. Proof. move=> modU modV; apply/mxmoduleP=> x Gx. by rewrite sub_capmx !mxmodule_trans ?capmxSl ?capmxSr. Qed. Lemma bigcapmx_module I r (P : pred I) U : (forall i, P i -> mxmodule (U i)) -> mxmodule (\bigcap_(i <- r | P i) U i)%MS. Proof. by move=> modU; elim/big_ind: _; [apply: mxmodule1 | apply: capmx_module | ]. Qed. (* Sub- and factor representations induced by a (sub)module. *) Section Submodule. Variable U : 'M[F]_n. Definition val_submod m : 'M_(m, \rank U) -> 'M_(m, n) := mulmxr (row_base U). Definition in_submod m : 'M_(m, n) -> 'M_(m, \rank U) := mulmxr (invmx (row_ebase U) *m pid_mx (\rank U)). HB.instance Definition _ m := GRing.Linear.on (@val_submod m). HB.instance Definition _ m := GRing.Linear.on (@in_submod m). Lemma val_submodE m W : @val_submod m W = W *m val_submod 1%:M. Proof. by rewrite mulmxA mulmx1. Qed. Lemma in_submodE m W : @in_submod m W = W *m in_submod 1%:M. Proof. by rewrite mulmxA mulmx1. Qed. Lemma val_submod1 : (val_submod 1%:M :=: U)%MS. Proof. by rewrite /val_submod /= mul1mx; apply: eq_row_base. Qed. Lemma val_submodP m W : (@val_submod m W <= U)%MS. Proof. by rewrite mulmx_sub ?eq_row_base. Qed. Lemma val_submodK m : cancel (@val_submod m) (@in_submod m). Proof. move=> W; rewrite /in_submod /= -!mulmxA mulKVmx ?row_ebase_unit //. by rewrite pid_mx_id ?rank_leq_row // pid_mx_1 mulmx1. Qed. Lemma val_submod_inj m : injective (@val_submod m). Proof. exact: can_inj (@val_submodK m). Qed. Lemma val_submodS m1 m2 (V : 'M_(m1, \rank U)) (W : 'M_(m2, \rank U)) : (val_submod V <= val_submod W)%MS = (V <= W)%MS. Proof. apply/idP/idP=> sVW; last exact: submxMr. by rewrite -[V]val_submodK -[W]val_submodK submxMr. Qed. Lemma in_submodK m W : (W <= U)%MS -> val_submod (@in_submod m W) = W. Proof. case/submxP=> w ->; rewrite /val_submod /= -!mulmxA. congr (_ *m _); rewrite -{1}[U]mulmx_ebase !mulmxA mulmxK ?row_ebase_unit //. by rewrite -2!(mulmxA (col_ebase U)) !pid_mx_id ?rank_leq_row // mulmx_ebase. Qed. Lemma val_submod_eq0 m W : (@val_submod m W == 0) = (W == 0). Proof. by rewrite -!submx0 -val_submodS linear0 !(submx0, eqmx0). Qed. Lemma in_submod_eq0 m W : (@in_submod m W == 0) = (W <= U^C)%MS. Proof. apply/eqP/submxP=> [W_U0 | [w ->{W}]]. exists (W *m invmx (row_ebase U)). rewrite mulmxA mulmxBr mulmx1 -(pid_mx_id _ _ _ (leqnn _)). rewrite mulmxA -(mulmxA W) [W *m (_ *m _)]W_U0 mul0mx subr0. by rewrite mulmxKV ?row_ebase_unit. rewrite /in_submod /= -!mulmxA mulKVmx ?row_ebase_unit //. by rewrite mul_copid_mx_pid ?rank_leq_row ?mulmx0. Qed. Lemma mxrank_in_submod m (W : 'M_(m, n)) : (W <= U)%MS -> \rank (in_submod W) = \rank W. Proof. by move=> sWU; apply/eqP; rewrite eqn_leq -{3}(in_submodK sWU) !mxrankM_maxl. Qed. Definition val_factmod m : _ -> 'M_(m, n) := mulmxr (row_base (cokermx U) *m row_ebase U). Definition in_factmod m : 'M_(m, n) -> _ := mulmxr (col_base (cokermx U)). HB.instance Definition _ m := GRing.Linear.on (@val_factmod m). HB.instance Definition _ m := GRing.Linear.on (@in_factmod m). Lemma val_factmodE m W : @val_factmod m W = W *m val_factmod 1%:M. Proof. by rewrite mulmxA mulmx1. Qed. Lemma in_factmodE m W : @in_factmod m W = W *m in_factmod 1%:M. Proof. by rewrite mulmxA mulmx1. Qed. Lemma val_factmodP m W : (@val_factmod m W <= U^C)%MS. Proof. by rewrite mulmx_sub {m W}// (eqmxMr _ (eq_row_base _)) -mulmxA submxMl. Qed. Lemma val_factmodK m : cancel (@val_factmod m) (@in_factmod m). Proof. move=> W /=; rewrite /in_factmod /=; set Uc := cokermx U. apply: (row_free_inj (row_base_free Uc)); rewrite -mulmxA mulmx_base. rewrite /val_factmod /= 2!mulmxA -/Uc mulmxK ?row_ebase_unit //. have /submxP[u ->]: (row_base Uc <= Uc)%MS by rewrite eq_row_base. by rewrite -!mulmxA copid_mx_id ?rank_leq_row. Qed. Lemma val_factmod_inj m : injective (@val_factmod m). Proof. exact: can_inj (@val_factmodK m). Qed. Lemma val_factmodS m1 m2 (V : 'M_(m1, _)) (W : 'M_(m2, _)) : (val_factmod V <= val_factmod W)%MS = (V <= W)%MS. Proof. apply/idP/idP=> sVW; last exact: submxMr. by rewrite -[V]val_factmodK -[W]val_factmodK submxMr. Qed. Lemma val_factmod_eq0 m W : (@val_factmod m W == 0) = (W == 0). Proof. by rewrite -!submx0 -val_factmodS linear0 !(submx0, eqmx0). Qed. Lemma in_factmod_eq0 m (W : 'M_(m, n)) : (in_factmod W == 0) = (W <= U)%MS. Proof. rewrite submxE -!mxrank_eq0 -{2}[_ U]mulmx_base mulmxA. by rewrite (mxrankMfree _ (row_base_free _)). Qed. Lemma in_factmodK m (W : 'M_(m, n)) : (W <= U^C)%MS -> val_factmod (in_factmod W) = W. Proof. case/submxP=> w ->{W}; rewrite /val_factmod /= -2!mulmxA. congr (_ *m _); rewrite (mulmxA (col_base _)) mulmx_base -2!mulmxA. by rewrite mulKVmx ?row_ebase_unit // mulmxA copid_mx_id ?rank_leq_row. Qed. Lemma in_factmod_addsK m (W : 'M_(m, n)) : (in_factmod (U + W)%MS :=: in_factmod W)%MS. Proof. apply: eqmx_trans (addsmxMr _ _ _) _. by rewrite ((_ *m _ =P 0) _) ?in_factmod_eq0 //; apply: adds0mx. Qed. Lemma add_sub_fact_mod m (W : 'M_(m, n)) : val_submod (in_submod W) + val_factmod (in_factmod W) = W. Proof. rewrite /val_submod /val_factmod /= -!mulmxA -mulmxDr. rewrite addrC ![in X in X + _](mulmxA (pid_mx _)) pid_mx_id //. rewrite (mulmxA (col_ebase _)) (mulmxA _ _ (row_ebase _)) mulmx_ebase. rewrite (mulmxA (pid_mx _)) pid_mx_id // mulmxA -mulmxDl -mulmxDr. by rewrite subrK mulmx1 mulmxA mulmxKV ?row_ebase_unit. Qed. Lemma proj_factmodS m (W : 'M_(m, n)) : (val_factmod (in_factmod W) <= U + W)%MS. Proof. by rewrite -{2}[W]add_sub_fact_mod addsmx_addKl ?val_submodP ?addsmxSr. Qed. Lemma in_factmodsK m (W : 'M_(m, n)) : (U <= W)%MS -> (U + val_factmod (in_factmod W) :=: W)%MS. Proof. move/addsmx_idPr; apply: eqmx_trans (eqmx_sym _). by rewrite -{1}[W]add_sub_fact_mod; apply: addsmx_addKl; apply: val_submodP. Qed. Lemma mxrank_in_factmod m (W : 'M_(m, n)) : (\rank (in_factmod W) + \rank U)%N = \rank (U + W). Proof. rewrite -in_factmod_addsK in_factmodE; set fU := in_factmod 1%:M. suffices <-: ((U + W) :&: kermx fU :=: U)%MS by rewrite mxrank_mul_ker. apply: eqmx_trans (capmx_idPr (addsmxSl U W)). apply: cap_eqmx => //; apply/eqmxP/rV_eqP => u. by rewrite (sameP sub_kermxP eqP) -in_factmodE in_factmod_eq0. Qed. Definition submod_mx of mxmodule U := fun x => in_submod (val_submod 1%:M *m rG x). Definition factmod_mx of mxmodule U := fun x => in_factmod (val_factmod 1%:M *m rG x). Hypothesis Umod : mxmodule U. Lemma in_submodJ m (W : 'M_(m, n)) x : (W <= U)%MS -> in_submod (W *m rG x) = in_submod W *m submod_mx Umod x. Proof. move=> sWU; rewrite mulmxA; congr (in_submod _). by rewrite mulmxA -val_submodE in_submodK. Qed. Lemma val_submodJ m (W : 'M_(m, \rank U)) x : x \in G -> val_submod (W *m submod_mx Umod x) = val_submod W *m rG x. Proof. move=> Gx; rewrite 2!(mulmxA W) -val_submodE in_submodK //. by rewrite mxmodule_trans ?val_submodP. Qed. Lemma submod_mx_repr : mx_repr G (submod_mx Umod). Proof. rewrite /submod_mx; split=> [|x y Gx Gy /=]. by rewrite repr_mx1 mulmx1 val_submodK. rewrite -in_submodJ; first by rewrite repr_mxM ?mulmxA. by rewrite mxmodule_trans ?val_submodP. Qed. Canonical submod_repr := MxRepresentation submod_mx_repr. Lemma in_factmodJ m (W : 'M_(m, n)) x : x \in G -> in_factmod (W *m rG x) = in_factmod W *m factmod_mx Umod x. Proof. move=> Gx; rewrite -{1}[W]add_sub_fact_mod mulmxDl linearD /=. apply: (canLR (subrK _)); apply: etrans (_ : 0 = _). apply/eqP; rewrite in_factmod_eq0 (submx_trans _ (mxmoduleP Umod x Gx)) //. by rewrite submxMr ?val_submodP. by rewrite /in_factmod /val_factmod /= !mulmxA mulmx1 ?subrr. Qed. Lemma val_factmodJ m (W : 'M_(m, \rank (cokermx U))) x : x \in G -> val_factmod (W *m factmod_mx Umod x) = val_factmod (in_factmod (val_factmod W *m rG x)). Proof. by move=> Gx; rewrite -{1}[W]val_factmodK -in_factmodJ. Qed. Lemma factmod_mx_repr : mx_repr G (factmod_mx Umod). Proof. split=> [|x y Gx Gy /=]. by rewrite /factmod_mx repr_mx1 mulmx1 val_factmodK. by rewrite -in_factmodJ // -mulmxA -repr_mxM. Qed. Canonical factmod_repr := MxRepresentation factmod_mx_repr. (* For character theory. *) Lemma mxtrace_sub_fact_mod x : \tr (submod_repr x) + \tr (factmod_repr x) = \tr (rG x). Proof. rewrite -[submod_repr x]mulmxA mxtrace_mulC -val_submodE addrC. rewrite -[factmod_repr x]mulmxA mxtrace_mulC -val_factmodE addrC. by rewrite -mxtraceD add_sub_fact_mod. Qed. End Submodule. (* Properties of enveloping algebra as a subspace of 'rV_(n ^ 2). *) Lemma envelop_mx_id x : x \in G -> (rG x \in E_G)%MS. Proof. by move=> Gx; rewrite (eq_row_sub (enum_rank_in Gx x)) // rowK enum_rankK_in. Qed. Lemma envelop_mx1 : (1%:M \in E_G)%MS. Proof. by rewrite -(repr_mx1 rG) envelop_mx_id. Qed. Lemma envelop_mxP A : reflect (exists a, A = \sum_(x in G) a x *: rG x) (A \in E_G)%MS. Proof. have G_1 := group1 G; have bijG := enum_val_bij_in G_1. set h := enum_val in bijG; have Gh: h _ \in G by apply: enum_valP. apply: (iffP submxP) => [[u defA] | [a ->]]. exists (fun x => u 0 (enum_rank_in G_1 x)); apply: (can_inj mxvecK). rewrite defA mulmx_sum_row linear_sum (reindex h) //=. by apply: eq_big => [i | i _]; rewrite ?Gh // rowK linearZ enum_valK_in. exists (\row_i a (h i)); rewrite mulmx_sum_row linear_sum (reindex h) //=. by apply: eq_big => [i | i _]; rewrite ?Gh // mxE rowK linearZ. Qed. Lemma envelop_mxM A B : (A \in E_G -> B \in E_G -> A *m B \in E_G)%MS. Proof. move=> {A B} /envelop_mxP[a ->] /envelop_mxP[b ->]. rewrite mulmx_suml !linear_sum summx_sub //= => x Gx. rewrite !linear_sum summx_sub //= => y Gy. rewrite -scalemxAl 3!linearZ !scalemx_sub//= -repr_mxM //. by rewrite envelop_mx_id ?groupM. Qed. Lemma mxmodule_envelop m1 m2 (U : 'M_(m1, n)) (W : 'M_(m2, n)) A : (mxmodule U -> mxvec A <= E_G -> W <= U -> W *m A <= U)%MS. Proof. move=> modU /envelop_mxP[a ->] sWU; rewrite linear_sum summx_sub //= => x Gx. by rewrite -scalemxAr scalemx_sub ?mxmodule_trans. Qed. (* Module homomorphisms; any square matrix f defines a module homomorphism *) (* over some domain, namely, dom_hom_mx f. *) Definition dom_hom_mx f : 'M_n := kermx (lin1_mx (mxvec \o mulmx (cent_mx_fun E_G f) \o lin_mul_row)). Lemma hom_mxP m f (W : 'M_(m, n)) : reflect (forall x, x \in G -> W *m rG x *m f = W *m f *m rG x) (W <= dom_hom_mx f)%MS. Proof. apply: (iffP row_subP) => [cGf x Gx | cGf i]. apply/row_matrixP=> i; apply/eqP; rewrite -subr_eq0 -!mulmxA -!linearB /=. have:= sub_kermxP (cGf i); rewrite mul_rV_lin1 /=. move/(canRL mxvecK)/row_matrixP/(_ (enum_rank_in Gx x))/eqP; rewrite !linear0. by rewrite !row_mul rowK mul_vec_lin /= mul_vec_lin_row enum_rankK_in. apply/sub_kermxP; rewrite mul_rV_lin1 /=; apply: (canLR vec_mxK). apply/row_matrixP=> j; rewrite !row_mul rowK mul_vec_lin /= mul_vec_lin_row. by rewrite -!row_mul mulmxBr !mulmxA cGf ?enum_valP // subrr !linear0. Qed. Arguments hom_mxP {m f W}. Lemma hom_envelop_mxC m f (W : 'M_(m, n)) A : (W <= dom_hom_mx f -> A \in E_G -> W *m A *m f = W *m f *m A)%MS. Proof. move/hom_mxP=> cWfG /envelop_mxP[a ->]; rewrite !linear_sum mulmx_suml. by apply: eq_bigr => x Gx /=; rewrite -2!scalemxAr -scalemxAl cWfG. Qed. Lemma dom_hom_invmx f : f \in unitmx -> (dom_hom_mx (invmx f) :=: dom_hom_mx f *m f)%MS. Proof. move=> injf; set U := dom_hom_mx _; apply/eqmxP. rewrite -{1}[U](mulmxKV injf) submxMr; apply/hom_mxP=> x Gx. by rewrite -[_ *m rG x](hom_mxP _) ?mulmxK. by rewrite -[_ *m rG x](hom_mxP _) ?mulmxKV. Qed. Lemma dom_hom_mx_module f : mxmodule (dom_hom_mx f). Proof. apply/mxmoduleP=> x Gx; apply/hom_mxP=> y Gy. rewrite -[_ *m rG y]mulmxA -repr_mxM // 2?(hom_mxP _) ?groupM //. by rewrite repr_mxM ?mulmxA. Qed. Lemma hom_mxmodule m (U : 'M_(m, n)) f : (U <= dom_hom_mx f)%MS -> mxmodule U -> mxmodule (U *m f). Proof. move/hom_mxP=> cGfU modU; apply/mxmoduleP=> x Gx. by rewrite -cGfU // submxMr // (mxmoduleP modU). Qed. Lemma kermx_hom_module m (U : 'M_(m, n)) f : (U <= dom_hom_mx f)%MS -> mxmodule U -> mxmodule (U :&: kermx f)%MS. Proof. move=> homUf modU; apply/mxmoduleP=> x Gx. rewrite sub_capmx mxmodule_trans ?capmxSl //=. apply/sub_kermxP; rewrite (hom_mxP _) ?(submx_trans (capmxSl _ _)) //. by rewrite (sub_kermxP (capmxSr _ _)) mul0mx. Qed. Lemma scalar_mx_hom a m (U : 'M_(m, n)) : (U <= dom_hom_mx a%:M)%MS. Proof. by apply/hom_mxP=> x Gx; rewrite -!mulmxA scalar_mxC. Qed. Lemma proj_mx_hom (U V : 'M_n) : (U :&: V = 0)%MS -> mxmodule U -> mxmodule V -> (U + V <= dom_hom_mx (proj_mx U V))%MS. Proof. move=> dxUV modU modV; apply/hom_mxP=> x Gx. rewrite -{1}(add_proj_mx dxUV (submx_refl _)) !mulmxDl addrC. rewrite {1}[_ *m _]proj_mx_0 ?add0r //; last first. by rewrite mxmodule_trans ?proj_mx_sub. by rewrite [_ *m _](proj_mx_id dxUV) // mxmodule_trans ?proj_mx_sub. Qed. (* The subspace fixed by a subgroup H of G; it is a module if H <| G. *) (* The definition below is extensionally equivalent to the straightforward *) (* \bigcap_(x in H) kermx (rG x - 1%:M) *) (* but it avoids the dependency on the choice function; this allows it to *) (* commute with ring morphisms. *) Definition rfix_mx (H : {set gT}) := let commrH := \matrix_(i < #|H|) mxvec (rG (enum_val i) - 1%:M) in kermx (lin1_mx (mxvec \o mulmx commrH \o lin_mul_row)). Lemma rfix_mxP m (W : 'M_(m, n)) (H : {set gT}) : reflect (forall x, x \in H -> W *m rG x = W) (W <= rfix_mx H)%MS. Proof. rewrite /rfix_mx; set C := \matrix_i _. apply: (iffP row_subP) => [cHW x Hx | cHW j]. apply/row_matrixP=> j; apply/eqP; rewrite -subr_eq0 row_mul. move/sub_kermxP: {cHW}(cHW j); rewrite mul_rV_lin1 /=; move/(canRL mxvecK). move/row_matrixP/(_ (enum_rank_in Hx x)); rewrite row_mul rowK !linear0. by rewrite enum_rankK_in // mul_vec_lin_row mulmxBr mulmx1 => ->. apply/sub_kermxP; rewrite mul_rV_lin1 /=; apply: (canLR vec_mxK). apply/row_matrixP=> i; rewrite row_mul rowK mul_vec_lin_row -row_mul. by rewrite mulmxBr mulmx1 cHW ?enum_valP // subrr !linear0. Qed. Arguments rfix_mxP {m W}. Lemma rfix_mx_id (H : {set gT}) x : x \in H -> rfix_mx H *m rG x = rfix_mx H. Proof. exact/rfix_mxP. Qed. Lemma rfix_mxS (H K : {set gT}) : H \subset K -> (rfix_mx K <= rfix_mx H)%MS. Proof. by move=> sHK; apply/rfix_mxP=> x Hx; apply: rfix_mxP (subsetP sHK x Hx). Qed. Lemma rfix_mx_conjsg (H : {set gT}) x : x \in G -> H \subset G -> (rfix_mx (H :^ x) :=: rfix_mx H *m rG x)%MS. Proof. move=> Gx sHG; pose rf y := rfix_mx (H :^ y). suffices{x Gx} IH: {in G &, forall y z, rf y *m rG z <= rf (y * z)%g}%MS. apply/eqmxP; rewrite -/(rf x) -[H]conjsg1 -/(rf 1%g). rewrite -{4}[x] mul1g -{1}[rf x](repr_mxKV rG Gx) -{1}(mulgV x). by rewrite submxMr IH ?groupV. move=> x y Gx Gy; apply/rfix_mxP=> zxy; rewrite actM => /imsetP[zx Hzx ->]. have Gzx: zx \in G by apply: subsetP Hzx; rewrite conj_subG. rewrite -mulmxA -repr_mxM ?groupM ?groupV // -conjgC repr_mxM // mulmxA. by rewrite rfix_mx_id. Qed. Lemma norm_sub_rstabs_rfix_mx (H : {set gT}) : H \subset G -> 'N_G(H) \subset rstabs (rfix_mx H). Proof. move=> sHG; apply/subsetP=> x /setIP[Gx nHx]; rewrite inE Gx. apply/rfix_mxP=> y Hy; have Gy := subsetP sHG y Hy. have Hyx: (y ^ x^-1)%g \in H by rewrite memJ_norm ?groupV. rewrite -mulmxA -repr_mxM // conjgCV repr_mxM ?(subsetP sHG _ Hyx) // mulmxA. by rewrite (rfix_mx_id Hyx). Qed. Lemma normal_rfix_mx_module H : H <| G -> mxmodule (rfix_mx H). Proof. case/andP=> sHG nHG. by rewrite /mxmodule -{1}(setIidPl nHG) norm_sub_rstabs_rfix_mx. Qed. Lemma rfix_mx_module : mxmodule (rfix_mx G). Proof. exact: normal_rfix_mx_module. Qed. Lemma rfix_mx_rstabC (H : {set gT}) m (U : 'M[F]_(m, n)) : H \subset G -> (H \subset rstab rG U) = (U <= rfix_mx H)%MS. Proof. move=> sHG; apply/subsetP/rfix_mxP=> cHU x Hx. by rewrite (rstab_act (cHU x Hx)). by rewrite !inE (subsetP sHG) //= cHU. Qed. (* The cyclic module generated by a single vector. *) Definition cyclic_mx u := <<E_G *m lin_mul_row u>>%MS. Lemma cyclic_mxP u v : reflect (exists2 A, A \in E_G & v = u *m A)%MS (v <= cyclic_mx u)%MS. Proof. rewrite genmxE; apply: (iffP submxP) => [[a] | [A /submxP[a defA]]] -> {v}. exists (vec_mx (a *m E_G)); last by rewrite mulmxA mul_rV_lin1. by rewrite vec_mxK submxMl. by exists a; rewrite mulmxA mul_rV_lin1 /= -defA mxvecK. Qed. Arguments cyclic_mxP {u v}. Lemma cyclic_mx_id u : (u <= cyclic_mx u)%MS. Proof. by apply/cyclic_mxP; exists 1%:M; rewrite ?mulmx1 ?envelop_mx1. Qed. Lemma cyclic_mx_eq0 u : (cyclic_mx u == 0) = (u == 0). Proof. rewrite -!submx0; apply/idP/idP. by apply: submx_trans; apply: cyclic_mx_id. move/submx0null->; rewrite genmxE; apply/row_subP=> i. by rewrite row_mul mul_rV_lin1 /= mul0mx ?sub0mx. Qed. Lemma cyclic_mx_module u : mxmodule (cyclic_mx u). Proof. apply/mxmoduleP=> x Gx; apply/row_subP=> i; rewrite row_mul. have [A E_A ->{i}] := @cyclic_mxP u _ (row_sub i _); rewrite -mulmxA. by apply/cyclic_mxP; exists (A *m rG x); rewrite ?envelop_mxM ?envelop_mx_id. Qed. Lemma cyclic_mx_sub m u (W : 'M_(m, n)) : mxmodule W -> (u <= W)%MS -> (cyclic_mx u <= W)%MS. Proof. move=> modU Wu; rewrite genmxE; apply/row_subP=> i. by rewrite row_mul mul_rV_lin1 /= mxmodule_envelop // vec_mxK row_sub. Qed. Lemma hom_cyclic_mx u f : (u <= dom_hom_mx f)%MS -> (cyclic_mx u *m f :=: cyclic_mx (u *m f))%MS. Proof. move=> domf_u; apply/eqmxP; rewrite !(eqmxMr _ (genmxE _)). apply/genmxP; rewrite genmx_id; congr <<_>>%MS; apply/row_matrixP=> i. by rewrite !row_mul !mul_rV_lin1 /= hom_envelop_mxC // vec_mxK row_sub. Qed. (* The annihilator of a single vector. *) Definition annihilator_mx u := (E_G :&: kermx (lin_mul_row u))%MS. Lemma annihilator_mxP u A : reflect (A \in E_G /\ u *m A = 0)%MS (A \in annihilator_mx u)%MS. Proof. rewrite sub_capmx; apply: (iffP andP) => [[-> /sub_kermxP]|[-> uA0]]. by rewrite mul_rV_lin1 /= mxvecK. by split=> //; apply/sub_kermxP; rewrite mul_rV_lin1 /= mxvecK. Qed. (* The subspace of homomorphic images of a row vector. *) Definition row_hom_mx u := (\bigcap_j kermx (vec_mx (row j (annihilator_mx u))))%MS. Lemma row_hom_mxP u v : reflect (exists2 f, u <= dom_hom_mx f & u *m f = v)%MS (v <= row_hom_mx u)%MS. Proof. apply: (iffP sub_bigcapmxP) => [iso_uv | [f hom_uf <-] i _]. have{iso_uv} uv0 A: (A \in E_G)%MS /\ u *m A = 0 -> v *m A = 0. move/annihilator_mxP=> /submxP[a defA]. rewrite -[A]mxvecK {A}defA [a *m _]mulmx_sum_row !linear_sum big1 // => i _. by rewrite !linearZ /= (sub_kermxP _) ?scaler0 ?iso_uv. pose U := E_G *m lin_mul_row u; pose V := E_G *m lin_mul_row v. pose f := pinvmx U *m V. have hom_uv_f x: x \in G -> u *m rG x *m f = v *m rG x. move=> Gx; apply/eqP; rewrite 2!mulmxA mul_rV_lin1 -subr_eq0 -mulmxBr /=. rewrite uv0 // linearB /= mulmxBr vec_mxK; split. (* FIXME: slow *) by rewrite addmx_sub ?submxMl // eqmx_opp envelop_mx_id. have Uux: (u *m rG x <= U)%MS. by rewrite -(genmxE U) mxmodule_trans ?cyclic_mx_id ?cyclic_mx_module. by rewrite -{2}(mulmxKpV Uux) [_ *m U]mulmxA mul_rV_lin1 subrr. have def_uf: u *m f = v. by rewrite -[u]mulmx1 -[v]mulmx1 -(repr_mx1 rG) hom_uv_f. by exists f => //; apply/hom_mxP=> x Gx; rewrite def_uf hom_uv_f. apply/sub_kermxP; set A := vec_mx _. have: (A \in annihilator_mx u)%MS by rewrite vec_mxK row_sub. by case/annihilator_mxP => E_A uA0; rewrite -hom_envelop_mxC // uA0 mul0mx. Qed. (* Sub-, isomorphic, simple, semisimple and completely reducible modules. *) (* All these predicates are intuitionistic (since, e.g., testing simplicity *) (* requires a splitting algorithm fo r the mas field). They are all *) (* specialized to square matrices, to avoid spurious height parameters. *) (* Module isomorphism is an intentional property in general, but it can be *) (* decided when one of the two modules is known to be simple. *) Variant mx_iso (U V : 'M_n) : Prop := MxIso f of f \in unitmx & (U <= dom_hom_mx f)%MS & (U *m f :=: V)%MS. Lemma eqmx_iso U V : (U :=: V)%MS -> mx_iso U V. Proof. by move=> eqUV; exists 1%:M; rewrite ?unitmx1 ?scalar_mx_hom ?mulmx1. Qed. Lemma mx_iso_refl U : mx_iso U U. Proof. exact: eqmx_iso. Qed. Lemma mx_iso_sym U V : mx_iso U V -> mx_iso V U. Proof. case=> f injf homUf defV; exists (invmx f); first by rewrite unitmx_inv. by rewrite dom_hom_invmx // -defV submxMr. by rewrite -[U](mulmxK injf); apply: eqmxMr (eqmx_sym _). Qed. Lemma mx_iso_trans U V W : mx_iso U V -> mx_iso V W -> mx_iso U W. Proof. case=> f injf homUf defV [g injg homVg defW]. exists (f *m g); first by rewrite unitmx_mul injf. by apply/hom_mxP=> x Gx; rewrite !mulmxA 2?(hom_mxP _) ?defV. by rewrite mulmxA; apply: eqmx_trans (eqmxMr g defV) defW. Qed. Lemma mxrank_iso U V : mx_iso U V -> \rank U = \rank V. Proof. by case=> f injf _ <-; rewrite mxrankMfree ?row_free_unit. Qed. Lemma mx_iso_module U V : mx_iso U V -> mxmodule U -> mxmodule V. Proof. by case=> f _ homUf defV; rewrite -(eqmx_module defV); apply: hom_mxmodule. Qed. (* Simple modules (we reserve the term "irreducible" for representations). *) Definition mxsimple (V : 'M_n) := [/\ mxmodule V, V != 0 & forall U : 'M_n, mxmodule U -> (U <= V)%MS -> U != 0 -> (V <= U)%MS]. Definition mxnonsimple (U : 'M_n) := exists V : 'M_n, [&& mxmodule V, (V <= U)%MS, V != 0 & \rank V < \rank U]. Lemma mxsimpleP U : [/\ mxmodule U, U != 0 & ~ mxnonsimple U] <-> mxsimple U. Proof. do [split => [] [modU nzU simU]; split] => // [V modV sVU nzV | [V]]. apply/idPn; rewrite -(ltn_leqif (mxrank_leqif_sup sVU)) => ltVU. by case: simU; exists V; apply/and4P. by case/and4P=> modV sVU nzV; apply/negP; rewrite -leqNgt mxrankS ?simU. Qed. Lemma mxsimple_module U : mxsimple U -> mxmodule U. Proof. by case. Qed. Lemma mxsimple_exists m (U : 'M_(m, n)) : mxmodule U -> U != 0 -> classically (exists2 V, mxsimple V & V <= U)%MS. Proof. move=> modU nzU [] // simU; move: {2}_.+1 (ltnSn (\rank U)) => r leUr. elim: r => // r IHr in m U leUr modU nzU simU. have genU := genmxE U; apply: (simU); exists <<U>>%MS; last by rewrite genU. apply/mxsimpleP; split; rewrite ?(eqmx_eq0 genU) ?(eqmx_module genU) //. case=> V; rewrite !genU=> /and4P[modV sVU nzV ltVU]; case: notF. apply: IHr nzV _ => // [|[W simW sWV]]; first exact: leq_trans ltVU _. by apply: simU; exists W => //; apply: submx_trans sWV sVU. Qed. Lemma mx_iso_simple U V : mx_iso U V -> mxsimple U -> mxsimple V. Proof. move=> isoUV [modU nzU simU]; have [f injf homUf defV] := isoUV. split=> [||W modW sWV nzW]; first by rewrite (mx_iso_module isoUV). by rewrite -(eqmx_eq0 defV) -(mul0mx n f) (can_eq (mulmxK injf)). rewrite -defV -[W](mulmxKV injf) submxMr //; set W' := W *m _. have sW'U: (W' <= U)%MS by rewrite -[U](mulmxK injf) submxMr ?defV. rewrite (simU W') //; last by rewrite -(can_eq (mulmxK injf)) mul0mx mulmxKV. rewrite hom_mxmodule ?dom_hom_invmx // -[W](mulmxKV injf) submxMr //. exact: submx_trans sW'U homUf. Qed. Lemma mxsimple_cyclic u U : mxsimple U -> u != 0 -> (u <= U)%MS -> (U :=: cyclic_mx u)%MS. Proof. case=> [modU _ simU] nz_u Uu; apply/eqmxP; set uG := cyclic_mx u. have s_uG_U: (uG <= U)%MS by rewrite cyclic_mx_sub. by rewrite simU ?cyclic_mx_eq0 ?submx_refl // cyclic_mx_module. Qed. (* The surjective part of Schur's lemma. *) Lemma mx_Schur_onto m (U : 'M_(m, n)) V f : mxmodule U -> mxsimple V -> (U <= dom_hom_mx f)%MS -> (U *m f <= V)%MS -> U *m f != 0 -> (U *m f :=: V)%MS. Proof. move=> modU [modV _ simV] homUf sUfV nzUf. apply/eqmxP; rewrite sUfV -(genmxE (U *m f)). rewrite simV ?(eqmx_eq0 (genmxE _)) ?genmxE //. by rewrite (eqmx_module (genmxE _)) hom_mxmodule. Qed. (* The injective part of Schur's lemma. *) Lemma mx_Schur_inj U f : mxsimple U -> (U <= dom_hom_mx f)%MS -> U *m f != 0 -> (U :&: kermx f)%MS = 0. Proof. case=> [modU _ simU] homUf nzUf; apply/eqP; apply: contraR nzUf => nz_ker. rewrite (sameP eqP sub_kermxP) (sameP capmx_idPl eqmxP) simU ?capmxSl //. exact: kermx_hom_module. Qed. (* The injectve part of Schur's lemma, stated as isomorphism with the image. *) Lemma mx_Schur_inj_iso U f : mxsimple U -> (U <= dom_hom_mx f)%MS -> U *m f != 0 -> mx_iso U (U *m f). Proof. move=> simU homUf nzUf; have [modU _ _] := simU. have eqUfU: \rank (U *m f) = \rank U by apply/mxrank_injP; rewrite mx_Schur_inj. have{eqUfU} [g invg defUf] := complete_unitmx eqUfU. suffices homUg: (U <= dom_hom_mx g)%MS by exists g; rewrite ?defUf. apply/hom_mxP=> x Gx; have [ux defUx] := submxP (mxmoduleP modU x Gx). by rewrite -defUf -(hom_mxP homUf) // defUx -!(mulmxA ux) defUf. Qed. (* The isomorphism part of Schur's lemma. *) Lemma mx_Schur_iso U V f : mxsimple U -> mxsimple V -> (U <= dom_hom_mx f)%MS -> (U *m f <= V)%MS -> U *m f != 0 -> mx_iso U V. Proof. move=> simU simV homUf sUfV nzUf; have [modU _ _] := simU. have [g invg homUg defUg] := mx_Schur_inj_iso simU homUf nzUf. exists g => //; apply: mx_Schur_onto; rewrite ?defUg //. by rewrite -!submx0 defUg in nzUf *. Qed. (* A boolean test for module isomorphism that is only valid for simple *) (* modules; this is the only case that matters in practice. *) Lemma nz_row_mxsimple U : mxsimple U -> nz_row U != 0. Proof. by case=> _ nzU _; rewrite nz_row_eq0. Qed. Definition mxsimple_iso (U V : 'M_n) := [&& mxmodule V, (V :&: row_hom_mx (nz_row U))%MS != 0 & \rank V <= \rank U]. Lemma mxsimple_isoP U V : mxsimple U -> reflect (mx_iso U V) (mxsimple_iso U V). Proof. move=> simU; pose u := nz_row U. have [Uu nz_u]: (u <= U)%MS /\ u != 0 by rewrite nz_row_sub nz_row_mxsimple. apply: (iffP and3P) => [[modV] | isoUV]; last first. split; last by rewrite (mxrank_iso isoUV). by case: (mx_iso_simple isoUV simU). have [f injf homUf defV] := isoUV; apply/rowV0Pn; exists (u *m f). rewrite sub_capmx -defV submxMr //. by apply/row_hom_mxP; exists f; first apply: (submx_trans Uu). by rewrite -(mul0mx _ f) (can_eq (mulmxK injf)) nz_u. case/rowV0Pn=> v; rewrite sub_capmx => /andP[Vv]. case/row_hom_mxP => f homMf def_v nz_v eqrUV. pose uG := cyclic_mx u; pose vG := cyclic_mx v. have def_vG: (uG *m f :=: vG)%MS by rewrite /vG -def_v; apply: hom_cyclic_mx. have defU: (U :=: uG)%MS by apply: mxsimple_cyclic. have mod_uG: mxmodule uG by rewrite cyclic_mx_module. have homUf: (U <= dom_hom_mx f)%MS. by rewrite defU cyclic_mx_sub ?dom_hom_mx_module. have isoUf: mx_iso U (U *m f). apply: mx_Schur_inj_iso => //; apply: contra nz_v; rewrite -!submx0. by rewrite (eqmxMr f defU) def_vG; apply: submx_trans (cyclic_mx_id v). apply: mx_iso_trans (isoUf) (eqmx_iso _); apply/eqmxP. have sUfV: (U *m f <= V)%MS by rewrite (eqmxMr f defU) def_vG cyclic_mx_sub. by rewrite -mxrank_leqif_eq ?eqn_leq 1?mxrankS // -(mxrank_iso isoUf). Qed. Lemma mxsimple_iso_simple U V : mxsimple_iso U V -> mxsimple U -> mxsimple V. Proof. by move=> isoUV simU; apply: mx_iso_simple (simU); apply/mxsimple_isoP. Qed. (* For us, "semisimple" means "sum of simple modules"; this is classically, *) (* but not intuitionistically, equivalent to the "completely reducible" *) (* alternate characterization. *) Implicit Type I : finType. Variant mxsemisimple (V : 'M_n) := MxSemisimple I U (W := (\sum_(i : I) U i)%MS) of forall i, mxsimple (U i) & (W :=: V)%MS & mxdirect W. (* This is a slight generalization of Aschbacher 12.5 for finite sets. *) Lemma sum_mxsimple_direct_compl m I W (U : 'M_(m, n)) : let V := (\sum_(i : I) W i)%MS in (forall i : I, mxsimple (W i)) -> mxmodule U -> (U <= V)%MS -> {J : {set I} | let S := U + \sum_(i in J) W i in S :=: V /\ mxdirect S}%MS. Proof. move=> V simW modU sUV; pose V_ (J : {set I}) := (\sum_(i in J) W i)%MS. pose dxU (J : {set I}) := mxdirect (U + V_ J). have [J maxJ]: {J | maxset dxU J}; last case/maxsetP: maxJ => dxUVJ maxJ. apply: ex_maxset; exists set0. by rewrite /dxU mxdirectE /V_ /= !big_set0 addn0 addsmx0 /=. have modWJ: mxmodule (V_ J) by apply: sumsmx_module => i _; case: (simW i). exists J; split=> //; apply/eqmxP; rewrite addsmx_sub sUV; apply/andP; split. by apply/sumsmx_subP=> i Ji; rewrite (sumsmx_sup i). rewrite -/(V_ J); apply/sumsmx_subP=> i _. case Ji: (i \in J). by apply: submx_trans (addsmxSr _ _); apply: (sumsmx_sup i). have [modWi nzWi simWi] := simW i. rewrite (sameP capmx_idPl eqmxP) simWi ?capmxSl ?capmx_module ?addsmx_module //. apply: contraFT (Ji); rewrite negbK => dxWiUVJ. rewrite -(maxJ (i |: J)) ?setU11 ?subsetUr // /dxU. rewrite mxdirectE /= !big_setU1 ?Ji //=. rewrite addnCA addsmxA (addsmxC U) -addsmxA -mxdirectE /=. by rewrite mxdirect_addsE /= mxdirect_trivial -/(dxU _) dxUVJ. Qed. Lemma sum_mxsimple_direct_sub I W (V : 'M_n) : (forall i : I, mxsimple (W i)) -> (\sum_i W i :=: V)%MS -> {J : {set I} | let S := \sum_(i in J) W i in S :=: V /\ mxdirect S}%MS. Proof. move=> simW defV. have [|J [defS dxS]] := sum_mxsimple_direct_compl simW (mxmodule0 n). exact: sub0mx. exists J; split; last by rewrite mxdirectE /= adds0mx mxrank0 in dxS. by apply: eqmx_trans defV; rewrite adds0mx_id in defS. Qed. Lemma mxsemisimple0 : mxsemisimple 0. Proof. exists 'I_0 (fun _ => 0); [by case | by rewrite big_ord0 | ]. by rewrite mxdirectE /= !big_ord0 mxrank0. Qed. Lemma intro_mxsemisimple (I : Type) r (P : pred I) W V : (\sum_(i <- r | P i) W i :=: V)%MS -> (forall i, P i -> W i != 0 -> mxsimple (W i)) -> mxsemisimple V. Proof. move=> defV simW; pose W_0 := [pred i | W i == 0]. have [-> | nzV] := eqVneq V 0; first exact: mxsemisimple0. case def_r: r => [| i0 r'] => [|{r' def_r}]. by rewrite -mxrank_eq0 -defV def_r big_nil mxrank0 in nzV. move: defV; rewrite (bigID W_0) /= addsmxC -big_filter !(big_nth i0) !big_mkord. rewrite addsmxC big1 ?adds0mx_id => [|i /andP[_ /eqP] //]. set tI := 'I_(_); set r_ := nth _ _ => defV. have{simW} simWr (i : tI) : mxsimple (W (r_ i)). case: i => m /=; set Pr := fun i => _ => lt_m_r /=. suffices: (Pr (r_ m)) by case/andP; apply: simW. apply: all_nthP m lt_m_r; apply/all_filterP. by rewrite -filter_predI; apply: eq_filter => i; rewrite /= andbb. have [J []] := sum_mxsimple_direct_sub simWr defV. case: (set_0Vmem J) => [-> V0 | [j0 Jj0]]. by rewrite -mxrank_eq0 -V0 big_set0 mxrank0 in nzV. pose K := {j | j \in J}; pose k0 : K := Sub j0 Jj0. have bij_KJ: {on J, bijective (sval : K -> _)}. by exists (insubd k0) => [k _ | j Jj]; rewrite ?valKd ?insubdK. have J_K (k : K) : sval k \in J by apply: valP k. rewrite mxdirectE /= !(reindex _ bij_KJ) !(eq_bigl _ _ J_K) -mxdirectE /= -/tI. exact: MxSemisimple. Qed. Lemma mxsimple_semisimple U : mxsimple U -> mxsemisimple U. Proof. move=> simU; apply: (intro_mxsemisimple (_ : \sum_(i < 1) U :=: U))%MS => //. by rewrite big_ord1. Qed. Lemma addsmx_semisimple U V : mxsemisimple U -> mxsemisimple V -> mxsemisimple (U + V)%MS. Proof. case=> [I W /= simW defU _] [J T /= simT defV _]. have defUV: (\sum_ij sum_rect (fun _ => 'M_n) W T ij :=: U + V)%MS. by rewrite big_sumType /=; apply: adds_eqmx. by apply: intro_mxsemisimple defUV _; case=> /=. Qed. Lemma sumsmx_semisimple (I : finType) (P : pred I) V : (forall i, P i -> mxsemisimple (V i)) -> mxsemisimple (\sum_(i | P i) V i)%MS. Proof. move=> ssimV; elim/big_ind: _ => //; first exact: mxsemisimple0. exact: addsmx_semisimple. Qed. Lemma eqmx_semisimple U V : (U :=: V)%MS -> mxsemisimple U -> mxsemisimple V. Proof. by move=> eqUV [I W S simW defU dxS]; exists I W => //; apply: eqmx_trans eqUV. Qed. Lemma hom_mxsemisimple (V f : 'M_n) : mxsemisimple V -> (V <= dom_hom_mx f)%MS -> mxsemisimple (V *m f). Proof. case=> I W /= simW defV _; rewrite -defV => /sumsmx_subP homWf. have{defV} defVf: (\sum_i W i *m f :=: V *m f)%MS. by apply: eqmx_trans (eqmx_sym _) (eqmxMr f defV); apply: sumsmxMr. apply: (intro_mxsemisimple defVf) => i _ nzWf. by apply: mx_iso_simple (simW i); apply: mx_Schur_inj_iso; rewrite ?homWf. Qed. Lemma mxsemisimple_module U : mxsemisimple U -> mxmodule U. Proof. case=> I W /= simW defU _. by rewrite -(eqmx_module defU) sumsmx_module // => i _; case: (simW i). Qed. (* Completely reducible modules, and Maeschke's Theorem. *) Variant mxsplits (V U : 'M_n) := MxSplits (W : 'M_n) of mxmodule W & (U + W :=: V)%MS & mxdirect (U + W). Definition mx_completely_reducible V := forall U, mxmodule U -> (U <= V)%MS -> mxsplits V U. Lemma mx_reducibleS U V : mxmodule U -> (U <= V)%MS -> mx_completely_reducible V -> mx_completely_reducible U. Proof. move=> modU sUV redV U1 modU1 sU1U. have [W modW defV dxU1W] := redV U1 modU1 (submx_trans sU1U sUV). exists (W :&: U)%MS; first exact: capmx_module. by apply/eqmxP; rewrite !matrix_modl // capmxSr sub_capmx defV sUV /=. by apply/mxdirect_addsP; rewrite capmxA (mxdirect_addsP dxU1W) cap0mx. Qed. Lemma mx_Maschke_pchar : [pchar F]^'.-group G -> mx_completely_reducible 1%:M. Proof. rewrite /pgroup pcharf'_nat; set nG := _%:R => nzG U => /mxmoduleP Umod _. pose phi := nG^-1 *: (\sum_(x in G) rG x^-1 *m pinvmx U *m U *m rG x). have phiG x: x \in G -> phi *m rG x = rG x *m phi. move=> Gx; rewrite -scalemxAl -scalemxAr; congr (_ *: _). rewrite {2}(reindex_acts 'R _ Gx) ?astabsR //= mulmx_suml mulmx_sumr. apply: eq_bigr => y Gy; rewrite !mulmxA -repr_mxM ?groupV ?groupM //. by rewrite invMg mulKVg repr_mxM ?mulmxA. have Uphi: U *m phi = U. rewrite -scalemxAr mulmx_sumr (eq_bigr (fun _ => U)) => [|x Gx]. by rewrite sumr_const -scaler_nat !scalerA mulVf ?scale1r. by rewrite 3!mulmxA mulmxKpV ?repr_mxKV ?Umod ?groupV. have tiUker: (U :&: kermx phi = 0)%MS. apply/eqP/rowV0P=> v; rewrite sub_capmx => /andP[/submxP[u ->] /sub_kermxP]. by rewrite -mulmxA Uphi. exists (kermx phi); last exact/mxdirect_addsP. apply/mxmoduleP=> x Gx; apply/sub_kermxP. by rewrite -mulmxA -phiG // mulmxA mulmx_ker mul0mx. apply/eqmxP; rewrite submx1 sub1mx. rewrite /row_full mxrank_disjoint_sum //= mxrank_ker. suffices ->: (U :=: phi)%MS by rewrite subnKC ?rank_leq_row. apply/eqmxP; rewrite -{1}Uphi submxMl scalemx_sub //. by rewrite summx_sub // => x Gx; rewrite -mulmxA mulmx_sub ?Umod. Qed. Lemma mxsemisimple_reducible V : mxsemisimple V -> mx_completely_reducible V. Proof. case=> [I W /= simW defV _] U modU sUV; rewrite -defV in sUV. have [J [defV' dxV]] := sum_mxsimple_direct_compl simW modU sUV. exists (\sum_(i in J) W i)%MS. - by apply: sumsmx_module => i _; case: (simW i). - exact: eqmx_trans defV' defV. by rewrite mxdirect_addsE (sameP eqP mxdirect_addsP) /= in dxV; case/and3P: dxV. Qed. Lemma mx_reducible_semisimple V : mxmodule V -> mx_completely_reducible V -> classically (mxsemisimple V). Proof. move=> modV redV [] // nssimV; have [r leVr] := ubnP (\rank V). elim: r => // r IHr in V leVr modV redV nssimV. have [V0 | nzV] := eqVneq V 0. by rewrite nssimV ?V0 //; apply: mxsemisimple0. apply: (mxsimple_exists modV nzV) => [[U simU sUV]]; have [modU nzU _] := simU. have [W modW defUW dxUW] := redV U modU sUV. have sWV: (W <= V)%MS by rewrite -defUW addsmxSr. apply: IHr (mx_reducibleS modW sWV redV) _ => // [|ssimW]. rewrite ltnS -defUW (mxdirectP dxUW) /= in leVr; apply: leq_trans leVr. by rewrite -add1n leq_add2r lt0n mxrank_eq0. apply: nssimV (eqmx_semisimple defUW (addsmx_semisimple _ ssimW)). exact: mxsimple_semisimple. Qed. Lemma mxsemisimpleS U V : mxmodule U -> (U <= V)%MS -> mxsemisimple V -> mxsemisimple U. Proof. move=> modU sUV ssimV. have [W modW defUW dxUW]:= mxsemisimple_reducible ssimV modU sUV. move/mxdirect_addsP: dxUW => dxUW. have defU : (V *m proj_mx U W :=: U)%MS. by apply/eqmxP; rewrite proj_mx_sub -{1}[U](proj_mx_id dxUW) ?submxMr. apply: eqmx_semisimple defU _; apply: hom_mxsemisimple ssimV _. by rewrite -defUW proj_mx_hom. Qed. Lemma hom_mxsemisimple_iso I P U W f : let V := (\sum_(i : I | P i) W i)%MS in mxsimple U -> (forall i, P i -> W i != 0 -> mxsimple (W i)) -> (V <= dom_hom_mx f)%MS -> (U <= V *m f)%MS -> {i | P i & mx_iso (W i) U}. Proof. move=> V simU simW homVf sUVf; have [modU nzU _] := simU. have ssimVf: mxsemisimple (V *m f). exact: hom_mxsemisimple (intro_mxsemisimple (eqmx_refl V) simW) homVf. have [U' modU' defVf] := mxsemisimple_reducible ssimVf modU sUVf. move/mxdirect_addsP=> dxUU'; pose p := f *m proj_mx U U'. case: (pickP (fun i => P i && (W i *m p != 0))) => [i /andP[Pi nzWip] | no_i]. have sWiV: (W i <= V)%MS by rewrite (sumsmx_sup i). have sWipU: (W i *m p <= U)%MS by rewrite mulmxA proj_mx_sub. exists i => //; apply: (mx_Schur_iso (simW i Pi _) simU _ sWipU nzWip). by apply: contraNneq nzWip => ->; rewrite mul0mx. apply: (submx_trans sWiV); apply/hom_mxP=> x Gx. by rewrite mulmxA [_ *m p]mulmxA 2?(hom_mxP _) -?defVf ?proj_mx_hom. case/negP: nzU; rewrite -submx0 -[U](proj_mx_id dxUU') //. rewrite (submx_trans (submxMr _ sUVf)) // -mulmxA -/p sumsmxMr. by apply/sumsmx_subP=> i Pi; move/negbT: (no_i i); rewrite Pi negbK submx0. Qed. (* The component associated to a given irreducible module. *) Section Components. Fact component_mx_key : unit. Proof. by []. Qed. Definition component_mx_expr (U : 'M[F]_n) := (\sum_i cyclic_mx (row i (row_hom_mx (nz_row U))))%MS. Definition component_mx := locked_with component_mx_key component_mx_expr. Canonical component_mx_unfoldable := [unlockable fun component_mx]. Variable U : 'M[F]_n. Hypothesis simU : mxsimple U. Let u := nz_row U. Let iso_u := row_hom_mx u. Let nz_u : u != 0 := nz_row_mxsimple simU. Let Uu : (u <= U)%MS := nz_row_sub U. Let defU : (U :=: cyclic_mx u)%MS := mxsimple_cyclic simU nz_u Uu. Local Notation compU := (component_mx U). Lemma component_mx_module : mxmodule compU. Proof. by rewrite unlock sumsmx_module // => i; rewrite cyclic_mx_module. Qed. Lemma genmx_component : <<compU>>%MS = compU. Proof. by rewrite [in compU]unlock genmx_sums; apply: eq_bigr => i; rewrite genmx_id. Qed. Lemma component_mx_def : {I : finType & {W : I -> 'M_n | forall i, mx_iso U (W i) & compU = \sum_i W i}}%MS. Proof. pose r i := row i iso_u; pose r_nz i := r i != 0; pose I := {i | r_nz i}. exists I; exists (fun i => cyclic_mx (r (sval i))) => [i|]. apply/mxsimple_isoP=> //; apply/and3P. split; first by rewrite cyclic_mx_module. apply/rowV0Pn; exists (r (sval i)); last exact: (svalP i). by rewrite sub_capmx cyclic_mx_id row_sub. have [f hom_u_f <-] := @row_hom_mxP u (r (sval i)) (row_sub _ _). by rewrite defU -hom_cyclic_mx ?mxrankM_maxl. rewrite -(eq_bigr _ (fun _ _ => genmx_id _)) -genmx_sums -genmx_component. rewrite [in compU]unlock; apply/genmxP/andP; split; last first. by apply/sumsmx_subP => i _; rewrite (sumsmx_sup (sval i)). apply/sumsmx_subP => i _. case i0: (r_nz i); first by rewrite (sumsmx_sup (Sub i i0)). by move/negbFE: i0; rewrite -cyclic_mx_eq0 => /eqP->; apply: sub0mx. Qed. Lemma component_mx_semisimple : mxsemisimple compU. Proof. have [I [W isoUW ->]] := component_mx_def. apply: intro_mxsemisimple (eqmx_refl _) _ => i _ _. exact: mx_iso_simple (isoUW i) simU. Qed. Lemma mx_iso_component V : mx_iso U V -> (V <= compU)%MS. Proof. move=> isoUV; have [f injf homUf defV] := isoUV. have simV := mx_iso_simple isoUV simU. have hom_u_f := submx_trans Uu homUf. have ->: (V :=: cyclic_mx (u *m f))%MS. apply: eqmx_trans (hom_cyclic_mx hom_u_f). exact: eqmx_trans (eqmx_sym defV) (eqmxMr _ defU). have iso_uf: (u *m f <= iso_u)%MS by apply/row_hom_mxP; exists f. rewrite genmxE; apply/row_subP=> j; rewrite row_mul mul_rV_lin1 /=. set a := vec_mx _; apply: submx_trans (submxMr _ iso_uf) _. apply/row_subP=> i; rewrite row_mul [in compU]unlock (sumsmx_sup i) //. by apply/cyclic_mxP; exists a; rewrite // vec_mxK row_sub. Qed. Lemma component_mx_id : (U <= compU)%MS. Proof. exact: mx_iso_component (mx_iso_refl U). Qed. Lemma hom_component_mx_iso f V : mxsimple V -> (compU <= dom_hom_mx f)%MS -> (V <= compU *m f)%MS -> mx_iso U V. Proof. have [I [W isoUW ->]] := component_mx_def => simV homWf sVWf. have [i _ _|i _ ] := hom_mxsemisimple_iso simV _ homWf sVWf. exact: mx_iso_simple (simU). exact: mx_iso_trans. Qed. Lemma component_mx_iso V : mxsimple V -> (V <= compU)%MS -> mx_iso U V. Proof. move=> simV; rewrite -[compU]mulmx1. exact: hom_component_mx_iso (scalar_mx_hom _ _). Qed. Lemma hom_component_mx f : (compU <= dom_hom_mx f)%MS -> (compU *m f <= compU)%MS. Proof. move=> hom_f. have [I W /= simW defW _] := hom_mxsemisimple component_mx_semisimple hom_f. rewrite -defW; apply/sumsmx_subP=> i _; apply: mx_iso_component. by apply: hom_component_mx_iso hom_f _ => //; rewrite -defW (sumsmx_sup i). Qed. End Components. Lemma component_mx_isoP U V : mxsimple U -> mxsimple V -> reflect (mx_iso U V) (component_mx U == component_mx V). Proof. move=> simU simV; apply: (iffP eqP) => isoUV. by apply: component_mx_iso; rewrite ?isoUV ?component_mx_id. rewrite -(genmx_component U) -(genmx_component V); apply/genmxP. wlog suffices: U V simU simV isoUV / (component_mx U <= component_mx V)%MS. by move=> IH; rewrite !IH //; apply: mx_iso_sym. have [I [W isoWU ->]] := component_mx_def simU. apply/sumsmx_subP => i _; apply: mx_iso_component => //. exact: mx_iso_trans (mx_iso_sym isoUV) (isoWU i). Qed. Lemma component_mx_disjoint U V : mxsimple U -> mxsimple V -> component_mx U != component_mx V -> (component_mx U :&: component_mx V = 0)%MS. Proof. move=> simU simV neUV; apply: contraNeq neUV => ntUV. apply: (mxsimple_exists _ ntUV) => [|[W simW]]. by rewrite capmx_module ?component_mx_module. rewrite sub_capmx => /andP[sWU sWV]; apply/component_mx_isoP=> //. by apply: mx_iso_trans (_ : mx_iso U W) (mx_iso_sym _); apply: component_mx_iso. Qed. Section Socle. Record socleType := EnumSocle { socle_base_enum : seq 'M[F]_n; _ : forall M, M \in socle_base_enum -> mxsimple M; _ : forall M, mxsimple M -> has (mxsimple_iso M) socle_base_enum }. Lemma socle_exists : classically socleType. Proof. pose V : 'M[F]_n := 0; have: mxsemisimple V by apply: mxsemisimple0. have: n - \rank V < n.+1 by rewrite mxrank0 subn0. elim: _.+1 V => // n' IHn' V; rewrite ltnS => le_nV_n' ssimV. case=> // maxV; apply: (maxV); have [I /= U simU defV _] := ssimV. exists (codom U) => [M | M simM]; first by case/mapP=> i _ ->. suffices sMV: (M <= V)%MS. rewrite -defV -(mulmx1 (\sum_i _)%MS) in sMV. have [//| i _] := hom_mxsemisimple_iso simM _ (scalar_mx_hom _ _) sMV. move/mx_iso_sym=> isoM; apply/hasP. by exists (U i); [apply: codom_f | apply/mxsimple_isoP]. have ssimMV := addsmx_semisimple (mxsimple_semisimple simM) ssimV. apply: contraLR isT => nsMV; apply: IHn' ssimMV _ maxV. apply: leq_trans le_nV_n'; rewrite ltn_sub2l //. rewrite ltn_neqAle rank_leq_row andbT -[_ == _]sub1mx. by apply: contra nsMV; apply: submx_trans; apply: submx1. rewrite (ltn_leqif (mxrank_leqif_sup _)) ?addsmxSr //. by rewrite addsmx_sub submx_refl andbT. Qed. Section SocleDef. Variable sG0 : socleType. Definition socle_enum := map component_mx (socle_base_enum sG0). Lemma component_socle M : mxsimple M -> component_mx M \in socle_enum. Proof. rewrite /socle_enum; case: sG0 => e0 /= sim_e mem_e simM. have /hasP[M' e0M' isoMM'] := mem_e M simM; apply/mapP; exists M' => //. by apply/eqP/component_mx_isoP; [|apply: sim_e | apply/mxsimple_isoP]. Qed. Inductive socle_sort : predArgType := PackSocle W of W \in socle_enum. Local Notation sG := socle_sort. Local Notation e0 := (socle_base_enum sG0). Definition socle_base W := let: PackSocle W _ := W in e0`_(index W socle_enum). Coercion socle_val W : 'M[F]_n := component_mx (socle_base W). Definition socle_mult (W : sG) := (\rank W %/ \rank (socle_base W))%N. Lemma socle_simple W : mxsimple (socle_base W). Proof. case: W => M /=; rewrite /= /socle_enum /=; case: sG0 => e sim_e _ /= e_M. by apply: sim_e; rewrite mem_nth // -(size_map component_mx) index_mem. Qed. Definition socle_module (W : sG) := mxsimple_module (socle_simple W). Definition socle_repr W := submod_repr (socle_module W). Lemma nz_socle (W : sG) : W != 0 :> 'M_n. Proof. have simW := socle_simple W; have [_ nzW _] := simW; apply: contra nzW. by rewrite -!submx0; apply: submx_trans (component_mx_id simW). Qed. Lemma socle_mem (W : sG) : (W : 'M_n) \in socle_enum. Proof. exact: component_socle (socle_simple _). Qed. Lemma PackSocleK W e0W : @PackSocle W e0W = W :> 'M_n. Proof. rewrite /socle_val /= in e0W *; rewrite -(nth_map _ 0) ?nth_index //. by rewrite -(size_map component_mx) index_mem. Qed. HB.instance Definition _ := isSub.Build _ _ sG socle_sort_rect PackSocleK. HB.instance Definition _ := [Choice of sG by <:]. Lemma socleP (W W' : sG) : reflect (W = W') (W == W')%MS. Proof. by rewrite (sameP genmxP eqP) !{1}genmx_component; apply: (W =P _). Qed. Fact socle_can_subproof : cancel (fun W => SeqSub (socle_mem W)) (fun s => PackSocle (valP s)). Proof. by move=> W /=; apply: val_inj; rewrite /= PackSocleK. Qed. HB.instance Definition _ := isCountable.Build sG (pcan_pickleK (can_pcan socle_can_subproof)). HB.instance Definition _ := isFinite.Build sG (pcan_enumP (can_pcan socle_can_subproof)). End SocleDef. Coercion socle_sort : socleType >-> predArgType. Variable sG : socleType. Section SubSocle. Variable P : pred sG. Notation S := (\sum_(W : sG | P W) socle_val W)%MS. Lemma subSocle_module : mxmodule S. Proof. by rewrite sumsmx_module // => W _; apply: component_mx_module. Qed. Lemma subSocle_semisimple : mxsemisimple S. Proof. apply: sumsmx_semisimple => W _; apply: component_mx_semisimple. exact: socle_simple. Qed. Local Notation ssimS := subSocle_semisimple. Lemma subSocle_iso M : mxsimple M -> (M <= S)%MS -> {W : sG | P W & mx_iso (socle_base W) M}. Proof. move=> simM sMS; have [modM nzM _] := simM. have [V /= modV defMV] := mxsemisimple_reducible ssimS modM sMS. move/mxdirect_addsP=> dxMV; pose p := proj_mx M V; pose Sp (W : sG) := W *m p. case: (pickP [pred i | P i & Sp i != 0]) => [/= W | Sp0]; last first. case/negP: nzM; rewrite -submx0 -[M](proj_mx_id dxMV) //. rewrite (submx_trans (submxMr _ sMS)) // sumsmxMr big1 // => W P_W. by apply/eqP; move/negbT: (Sp0 W); rewrite /= P_W negbK. rewrite {}/Sp /= => /andP[P_W nzSp]; exists W => //. have homWp: (W <= dom_hom_mx p)%MS. apply: submx_trans (proj_mx_hom dxMV modM modV). by rewrite defMV (sumsmx_sup W). have simWP := socle_simple W; apply: hom_component_mx_iso (homWp) _ => //. by rewrite (mx_Schur_onto _ simM) ?proj_mx_sub ?component_mx_module. Qed. Lemma capmx_subSocle m (M : 'M_(m, n)) : mxmodule M -> (M :&: S :=: \sum_(W : sG | P W) (M :&: W))%MS. Proof. move=> modM; apply/eqmxP/andP; split; last first. by apply/sumsmx_subP=> W P_W; rewrite capmxS // (sumsmx_sup W). have modMS: mxmodule (M :&: S)%MS by rewrite capmx_module ?subSocle_module. have [J /= U simU defMS _] := mxsemisimpleS modMS (capmxSr M S) ssimS. rewrite -defMS; apply/sumsmx_subP=> j _. have [sUjV sUjS]: (U j <= M /\ U j <= S)%MS. by apply/andP; rewrite -sub_capmx -defMS (sumsmx_sup j). have [W P_W isoWU] := subSocle_iso (simU j) sUjS. rewrite (sumsmx_sup W) // sub_capmx sUjV mx_iso_component //. exact: socle_simple. Qed. End SubSocle. Lemma subSocle_direct P : mxdirect (\sum_(W : sG | P W) W). Proof. apply/mxdirect_sumsP=> W _; apply/eqP. rewrite -submx0 capmx_subSocle ?component_mx_module //. apply/sumsmx_subP=> W' /andP[_ neWW']. by rewrite capmxC component_mx_disjoint //; apply: socle_simple. Qed. Definition Socle := (\sum_(W : sG) W)%MS. Lemma simple_Socle M : mxsimple M -> (M <= Socle)%MS. Proof. move=> simM; have socM := component_socle sG simM. by rewrite (sumsmx_sup (PackSocle socM)) // PackSocleK component_mx_id. Qed. Lemma semisimple_Socle U : mxsemisimple U -> (U <= Socle)%MS. Proof. by case=> I M /= simM <- _; apply/sumsmx_subP=> i _; apply: simple_Socle. Qed. Lemma reducible_Socle U : mxmodule U -> mx_completely_reducible U -> (U <= Socle)%MS. Proof. move=> modU redU; apply: (mx_reducible_semisimple modU redU). exact: semisimple_Socle. Qed. Lemma genmx_Socle : <<Socle>>%MS = Socle. Proof. by rewrite genmx_sums; apply: eq_bigr => W; rewrite genmx_component. Qed. Lemma reducible_Socle1 : mx_completely_reducible 1%:M -> Socle = 1%:M. Proof. move=> redG; rewrite -genmx1 -genmx_Socle; apply/genmxP. by rewrite submx1 reducible_Socle ?mxmodule1. Qed. Lemma Socle_module : mxmodule Socle. Proof. exact: subSocle_module. Qed. Lemma Socle_semisimple : mxsemisimple Socle. Proof. exact: subSocle_semisimple. Qed. Lemma Socle_direct : mxdirect Socle. Proof. exact: subSocle_direct. Qed. Lemma Socle_iso M : mxsimple M -> {W : sG | mx_iso (socle_base W) M}. Proof. by move=> simM; case/subSocle_iso: (simple_Socle simM) => // W _; exists W. Qed. End Socle. (* Centralizer subgroup and central homomorphisms. *) Section CentHom. Variable f : 'M[F]_n. Lemma row_full_dom_hom : row_full (dom_hom_mx f) = centgmx rG f. Proof. by rewrite -sub1mx; apply/hom_mxP/centgmxP=> cfG x /cfG; rewrite !mul1mx. Qed. Lemma memmx_cent_envelop : (f \in 'C(E_G))%MS = centgmx rG f. Proof. apply/cent_rowP/centgmxP=> [cfG x Gx | cfG i]. by have:= cfG (enum_rank_in Gx x); rewrite rowK mxvecK enum_rankK_in. by rewrite rowK mxvecK /= cfG ?enum_valP. Qed. Lemma kermx_centg_module : centgmx rG f -> mxmodule (kermx f). Proof. move/centgmxP=> cGf; apply/mxmoduleP=> x Gx; apply/sub_kermxP. by rewrite -mulmxA -cGf // mulmxA mulmx_ker mul0mx. Qed. Lemma centgmx_hom m (U : 'M_(m, n)) : centgmx rG f -> (U <= dom_hom_mx f)%MS. Proof. by rewrite -row_full_dom_hom -sub1mx; apply: submx_trans (submx1 _). Qed. End CentHom. (* (Globally) irreducible, and absolutely irreducible representations. Note *) (* that unlike "reducible", "absolutely irreducible" can easily be decided. *) Definition mx_irreducible := mxsimple 1%:M. Lemma mx_irrP : mx_irreducible <-> n > 0 /\ (forall U, @mxmodule n U -> U != 0 -> row_full U). Proof. rewrite /mx_irreducible /mxsimple mxmodule1 -mxrank_eq0 mxrank1 -lt0n. do [split=> [[_ -> irrG] | [-> irrG]]; split=> // U] => [modU | modU _] nzU. by rewrite -sub1mx (irrG U) ?submx1. by rewrite sub1mx irrG. Qed. (* Schur's lemma for endomorphisms. *) Lemma mx_Schur : mx_irreducible -> forall f, centgmx rG f -> f != 0 -> f \in unitmx. Proof. move/mx_Schur_onto=> irrG f. rewrite -row_full_dom_hom -!row_full_unit -!sub1mx => cGf nz. by rewrite -[f]mul1mx irrG ?submx1 ?mxmodule1 ?mul1mx. Qed. Definition mx_absolutely_irreducible := (n > 0) && row_full E_G. Lemma mx_abs_irrP : reflect (n > 0 /\ exists a_, forall A, A = \sum_(x in G) a_ x A *: rG x) mx_absolutely_irreducible. Proof. have G_1 := group1 G; have bijG := enum_val_bij_in G_1. set h := enum_val in bijG; have Gh : h _ \in G by apply: enum_valP. rewrite /mx_absolutely_irreducible; case: (n > 0); last by right; case. apply: (iffP row_fullP) => [[E' E'G] | [_ [a_ a_G]]]. split=> //; exists (fun x B => (mxvec B *m E') 0 (enum_rank_in G_1 x)) => B. apply: (can_inj mxvecK); rewrite -{1}[mxvec B]mulmx1 -{}E'G mulmxA. move: {B E'}(_ *m E') => u; apply/rowP=> j. rewrite linear_sum (reindex h) //= mxE summxE. by apply: eq_big => [k| k _]; rewrite ?Gh // enum_valK_in linearZ !mxE. exists (\matrix_(j, i) a_ (h i) (vec_mx (row j 1%:M))). apply/row_matrixP=> i; rewrite -[row i 1%:M]vec_mxK {}[vec_mx _]a_G. apply/rowP=> j; rewrite linear_sum (reindex h) //= 2!mxE summxE. by apply: eq_big => [k| k _]; [rewrite Gh | rewrite linearZ !mxE]. Qed. Lemma mx_abs_irr_cent_scalar : mx_absolutely_irreducible -> forall A, centgmx rG A -> is_scalar_mx A. Proof. case/mx_abs_irrP=> n_gt0 [a_ a_G] A /centgmxP cGA. have{cGA a_G} cMA B: A *m B = B *m A. rewrite {}[B]a_G mulmx_suml mulmx_sumr. by apply: eq_bigr => x Gx; rewrite -scalemxAl -scalemxAr cGA. pose i0 := Ordinal n_gt0; apply/is_scalar_mxP; exists (A i0 i0). apply/matrixP=> i j; move/matrixP/(_ i0 j): (esym (cMA (delta_mx i0 i))). rewrite -[A *m _]trmxK trmx_mul trmx_delta -!(@mul_delta_mx _ n 1 n 0) -!mulmxA. by rewrite -!rowE !mxE !big_ord1 !mxE !eqxx !mulr_natl /= andbT eq_sym. Qed. Lemma mx_abs_irrW : mx_absolutely_irreducible -> mx_irreducible. Proof. case/mx_abs_irrP=> n_gt0 [a_ a_G]; apply/mx_irrP; split=> // U Umod. case/rowV0Pn=> u Uu; rewrite -mxrank_eq0 -lt0n row_leq_rank -sub1mx. case/submxP: Uu => v ->{u} /row_freeP[u' vK]; apply/row_subP=> i. rewrite rowE scalar_mxC -{}vK -2![_ *m _]mulmxA; move: {u' i}(u' *m _) => A. rewrite mulmx_sub {v}// [A]a_G linear_sum summx_sub //= => x Gx. by rewrite -scalemxAr scalemx_sub // (mxmoduleP Umod). Qed. Lemma linear_mx_abs_irr : n = 1 -> mx_absolutely_irreducible. Proof. move=> n1; rewrite /mx_absolutely_irreducible /row_full eqn_leq rank_leq_col. rewrite {1 2 3}n1 /= lt0n mxrank_eq0; apply: contraTneq envelop_mx1 => ->. by rewrite eqmx0 submx0 mxvec_eq0 -mxrank_eq0 mxrank1 n1. Qed. Lemma abelian_abs_irr : abelian G -> mx_absolutely_irreducible = (n == 1). Proof. move=> cGG; apply/idP/eqP=> [absG|]; last exact: linear_mx_abs_irr. have [n_gt0 _] := andP absG. pose M := <<delta_mx 0 (Ordinal n_gt0) : 'rV[F]_n>>%MS. have rM: \rank M = 1 by rewrite genmxE mxrank_delta. suffices defM: (M == 1%:M)%MS by rewrite (eqmxP defM) mxrank1 in rM. case: (mx_abs_irrW absG) => _ _ ->; rewrite ?submx1 -?mxrank_eq0 ?rM //. apply/mxmoduleP=> x Gx; suffices: is_scalar_mx (rG x). by case/is_scalar_mxP=> a ->; rewrite mul_mx_scalar scalemx_sub. apply: (mx_abs_irr_cent_scalar absG). by apply/centgmxP=> y Gy; rewrite -!repr_mxM // (centsP cGG). Qed. End OneRepresentation. Arguments mxmoduleP {gT G n rG m U}. Arguments envelop_mxP {gT G n rG A}. Arguments hom_mxP {gT G n rG m f W}. Arguments rfix_mxP {gT G n rG m W}. Arguments cyclic_mxP {gT G n rG u v}. Arguments annihilator_mxP {gT G n rG u A}. Arguments row_hom_mxP {gT G n rG u v}. Arguments mxsimple_isoP {gT G n rG U V}. Arguments socleP {gT G n rG sG0 W W'}. Arguments mx_abs_irrP {gT G n rG}. Arguments val_submod {n U m} W. Arguments in_submod {n} U {m} W. Arguments val_submodK {n U m} W : rename. Arguments in_submodK {n U m} [W] sWU. Arguments val_submod_inj {n U m} [W1 W2] : rename. Arguments val_factmod {n U m} W. Arguments in_factmod {n} U {m} W. Arguments val_factmodK {n U m} W : rename. Arguments in_factmodK {n} U {m} [W] sWU. Arguments val_factmod_inj {n U m} [W1 W2] : rename. Section Proper. Variables (gT : finGroupType) (G : {group gT}) (n' : nat). Local Notation n := n'.+1. Variable rG : mx_representation F G n. Lemma envelop_mx_ring : mxring (enveloping_algebra_mx rG). Proof. apply/andP; split; first by apply/mulsmx_subP; apply: envelop_mxM. apply/mxring_idP; exists 1%:M; split=> *; rewrite ?mulmx1 ?mul1mx //. by rewrite -mxrank_eq0 mxrank1. exact: envelop_mx1. Qed. End Proper. Section JacobsonDensity. Variables (gT : finGroupType) (G : {group gT}) (n : nat). Variable rG : mx_representation F G n. Hypothesis irrG : mx_irreducible rG. Local Notation E_G := (enveloping_algebra_mx rG). Local Notation Hom_G := 'C(E_G)%MS. Lemma mx_Jacobson_density : ('C(Hom_G) <= E_G)%MS. Proof. apply/row_subP=> iB; rewrite -[row iB _]vec_mxK; move defB: (vec_mx _) => B. have{defB} cBcE: (B \in 'C(Hom_G))%MS by rewrite -defB vec_mxK row_sub. have rGnP: mx_repr G (fun x => lin_mx (mulmxr (rG x)) : 'A_n). split=> [|x y Gx Gy]; apply/row_matrixP=> i. by rewrite !rowE mul_rV_lin repr_mx1 /= !mulmx1 vec_mxK. by rewrite !rowE mulmxA !mul_rV_lin repr_mxM //= mxvecK mulmxA. move def_rGn: (MxRepresentation rGnP) => rGn. pose E_Gn := enveloping_algebra_mx rGn. pose e1 : 'rV[F]_(n ^ 2) := mxvec 1%:M; pose U := cyclic_mx rGn e1. have U_e1: (e1 <= U)%MS by rewrite cyclic_mx_id. have modU: mxmodule rGn U by rewrite cyclic_mx_module. pose Bn : 'M_(n ^ 2) := lin_mx (mulmxr B). suffices U_e1Bn: (e1 *m Bn <= U)%MS. rewrite mul_vec_lin /= mul1mx in U_e1Bn; apply: submx_trans U_e1Bn _. rewrite genmxE; apply/row_subP=> i; rewrite row_mul rowK mul_vec_lin_row. by rewrite -def_rGn mul_vec_lin /= mul1mx (eq_row_sub i) ?rowK. have{cBcE} cBncEn A: centgmx rGn A -> A *m Bn = Bn *m A. rewrite -def_rGn => cAG; apply/row_matrixP; case/mxvec_indexP=> j k /=. rewrite !rowE !mulmxA -mxvec_delta -(mul_delta_mx (0 : 'I_1)). rewrite mul_rV_lin mul_vec_lin /= -mulmxA; apply: (canLR vec_mxK). apply/row_matrixP=> i; set dj0 := delta_mx j 0. have /= defAij := mul_rV_lin1 (row i \o vec_mx \o mulmxr A \o mxvec \o mulmx dj0). rewrite -defAij row_mul -defAij -!mulmxA (cent_mxP cBcE) {k}//. rewrite memmx_cent_envelop; apply/centgmxP=> x Gx; apply/row_matrixP=> k. rewrite !row_mul !rowE !{}defAij /= -row_mul mulmxA mul_delta_mx. congr (row i _); rewrite -(mul_vec_lin (mulmxr (rG x))) -mulmxA. by rewrite -(centgmxP cAG) // mulmxA mx_rV_lin. suffices redGn: mx_completely_reducible rGn 1%:M. have [V modV defUV] := redGn _ modU (submx1 _); move/mxdirect_addsP=> dxUV. rewrite -(proj_mx_id dxUV U_e1) -mulmxA {}cBncEn 1?mulmxA ?proj_mx_sub //. by rewrite -row_full_dom_hom -sub1mx -defUV proj_mx_hom. pose W i : 'M[F]_(n ^ 2) := <<lin1_mx (mxvec \o mulmx (delta_mx i 0))>>%MS. have defW: (\sum_i W i :=: 1%:M)%MS. apply/eqmxP; rewrite submx1; apply/row_subP; case/mxvec_indexP=> i j. rewrite row1 -mxvec_delta (sumsmx_sup i) // genmxE; apply/submxP. by exists (delta_mx 0 j); rewrite mul_rV_lin1 /= mul_delta_mx. apply: mxsemisimple_reducible; apply: (intro_mxsemisimple defW) => i _ nzWi. split=> // [|Vi modVi sViWi nzVi]. apply/mxmoduleP=> x Gx; rewrite genmxE (eqmxMr _ (genmxE _)) -def_rGn. apply/row_subP=> j; rewrite rowE mulmxA !mul_rV_lin1 /= mxvecK -mulmxA. by apply/submxP; move: (_ *m rG x) => v; exists v; rewrite mul_rV_lin1. do [rewrite !genmxE; set f := lin1_mx _] in sViWi *. have f_free: row_free f. apply/row_freeP; exists (lin1_mx (row i \o vec_mx)); apply/row_matrixP=> j. by rewrite row1 rowE mulmxA !mul_rV_lin1 /= mxvecK rowE !mul_delta_mx. pose V := <<Vi *m pinvmx f>>%MS; have Vidf := mulmxKpV sViWi. suffices: (1%:M <= V)%MS by rewrite genmxE -(submxMfree _ _ f_free) mul1mx Vidf. case: irrG => _ _ ->; rewrite ?submx1 //; last first. by rewrite -mxrank_eq0 genmxE -(mxrankMfree _ f_free) Vidf mxrank_eq0. apply/mxmoduleP=> x Gx; rewrite genmxE (eqmxMr _ (genmxE _)). rewrite -(submxMfree _ _ f_free) Vidf. apply: submx_trans (mxmoduleP modVi x Gx); rewrite -{2}Vidf. apply/row_subP=> j; apply: (eq_row_sub j); rewrite row_mul -def_rGn. by rewrite !(row_mul _ _ f) !mul_rV_lin1 /= mxvecK !row_mul !mulmxA. Qed. Lemma cent_mx_scalar_abs_irr : \rank Hom_G <= 1 -> mx_absolutely_irreducible rG. Proof. rewrite leqNgt => /(has_non_scalar_mxP (scalar_mx_cent _ _)) scal_cE. apply/andP; split; first by case/mx_irrP: irrG. rewrite -sub1mx; apply: submx_trans mx_Jacobson_density. apply/memmx_subP=> B _; apply/cent_mxP=> A cGA. case scalA: (is_scalar_mx A); last by case: scal_cE; exists A; rewrite ?scalA. by case/is_scalar_mxP: scalA => a ->; rewrite scalar_mxC. Qed. End JacobsonDensity. Section ChangeGroup. Variables (gT : finGroupType) (G H : {group gT}) (n : nat). Variables (rG : mx_representation F G n). Section SubGroup. Hypothesis sHG : H \subset G. Local Notation rH := (subg_repr rG sHG). Lemma rfix_subg : rfix_mx rH = rfix_mx rG. Proof. by []. Qed. Section Stabilisers. Variables (m : nat) (U : 'M[F]_(m, n)). Lemma rstabs_subg : rstabs rH U = H :&: rstabs rG U. Proof. by apply/setP=> x; rewrite !inE andbA -in_setI (setIidPl sHG). Qed. Lemma mxmodule_subg : mxmodule rG U -> mxmodule rH U. Proof. by rewrite /mxmodule rstabs_subg subsetI subxx; apply: subset_trans. Qed. End Stabilisers. Lemma mxsimple_subg M : mxmodule rG M -> mxsimple rH M -> mxsimple rG M. Proof. by move=> modM [_ nzM minM]; split=> // U /mxmodule_subg; apply: minM. Qed. Lemma subg_mx_irr : mx_irreducible rH -> mx_irreducible rG. Proof. by apply: mxsimple_subg; apply: mxmodule1. Qed. Lemma subg_mx_abs_irr : mx_absolutely_irreducible rH -> mx_absolutely_irreducible rG. Proof. rewrite /mx_absolutely_irreducible -!sub1mx => /andP[-> /submx_trans-> //]. apply/row_subP=> i; rewrite rowK /= envelop_mx_id //. by rewrite (subsetP sHG) ?enum_valP. Qed. End SubGroup. Section SameGroup. Hypothesis eqGH : G :==: H. Local Notation rH := (eqg_repr rG eqGH). Lemma rfix_eqg : rfix_mx rH = rfix_mx rG. Proof. by []. Qed. Section Stabilisers. Variables (m : nat) (U : 'M[F]_(m, n)). Lemma rstabs_eqg : rstabs rH U = rstabs rG U. Proof. by rewrite rstabs_subg -(eqP eqGH) (setIidPr _) ?rstabs_sub. Qed. Lemma mxmodule_eqg : mxmodule rH U = mxmodule rG U. Proof. by rewrite /mxmodule rstabs_eqg -(eqP eqGH). Qed. End Stabilisers. Lemma mxsimple_eqg M : mxsimple rH M <-> mxsimple rG M. Proof. rewrite /mxsimple mxmodule_eqg. split=> [] [-> -> minM]; split=> // U modU; by apply: minM; rewrite mxmodule_eqg in modU *. Qed. Lemma eqg_mx_irr : mx_irreducible rH <-> mx_irreducible rG. Proof. exact: mxsimple_eqg. Qed. Lemma eqg_mx_abs_irr : mx_absolutely_irreducible rH = mx_absolutely_irreducible rG. Proof. by congr (_ && (_ == _)); rewrite /enveloping_algebra_mx /= -(eqP eqGH). Qed. End SameGroup. End ChangeGroup. Section Morphpre. Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}). Variables (G : {group rT}) (n : nat) (rG : mx_representation F G n). Local Notation rGf := (morphpre_repr f rG). Section Stabilisers. Variables (m : nat) (U : 'M[F]_(m, n)). Lemma rstabs_morphpre : rstabs rGf U = f @*^-1 (rstabs rG U). Proof. by apply/setP=> x; rewrite !inE andbA. Qed. Lemma mxmodule_morphpre : G \subset f @* D -> mxmodule rGf U = mxmodule rG U. Proof. by move=> sGf; rewrite /mxmodule rstabs_morphpre morphpreSK. Qed. End Stabilisers. Lemma rfix_morphpre (H : {set aT}) : H \subset D -> (rfix_mx rGf H :=: rfix_mx rG (f @* H))%MS. Proof. move=> sHD; apply/eqmxP/andP; split. by apply/rfix_mxP=> _ /morphimP[x _ Hx ->]; rewrite rfix_mx_id. by apply/rfix_mxP=> x Hx; rewrite rfix_mx_id ?mem_morphim ?(subsetP sHD). Qed. Lemma morphpre_mx_irr : G \subset f @* D -> (mx_irreducible rGf <-> mx_irreducible rG). Proof. move/mxmodule_morphpre=> modG; split=> /mx_irrP[n_gt0 irrG]; by apply/mx_irrP; split=> // U modU; apply: irrG; rewrite modG in modU *. Qed. Lemma morphpre_mx_abs_irr : G \subset f @* D -> mx_absolutely_irreducible rGf = mx_absolutely_irreducible rG. Proof. move=> sGfD; congr (_ && (_ == _)); apply/eqP; rewrite mxrank_leqif_sup //. apply/row_subP=> i; rewrite rowK. case/morphimP: (subsetP sGfD _ (enum_valP i)) => x Dx _ def_i. by rewrite def_i (envelop_mx_id rGf) // !inE Dx -def_i enum_valP. apply/row_subP=> i; rewrite rowK (envelop_mx_id rG) //. by case/morphpreP: (enum_valP i). Qed. End Morphpre. Section Morphim. Variables (aT rT : finGroupType) (G D : {group aT}) (f : {morphism D >-> rT}). Variables (n : nat) (rGf : mx_representation F (f @* G) n). Hypothesis sGD : G \subset D. Let sG_f'fG : G \subset f @*^-1 (f @* G). Proof. by rewrite -sub_morphim_pre. Qed. Local Notation rG := (morphim_repr rGf sGD). Section Stabilisers. Variables (m : nat) (U : 'M[F]_(m, n)). Lemma rstabs_morphim : rstabs rG U = G :&: f @*^-1 rstabs rGf U. Proof. by rewrite -rstabs_morphpre -(rstabs_subg _ sG_f'fG). Qed. Lemma mxmodule_morphim : mxmodule rG U = mxmodule rGf U. Proof. by rewrite /mxmodule rstabs_morphim subsetI subxx -sub_morphim_pre. Qed. End Stabilisers. Lemma rfix_morphim (H : {set aT}) : H \subset D -> (rfix_mx rG H :=: rfix_mx rGf (f @* H))%MS. Proof. exact: rfix_morphpre. Qed. Lemma mxsimple_morphim M : mxsimple rG M <-> mxsimple rGf M. Proof. rewrite /mxsimple mxmodule_morphim. split=> [] [-> -> minM]; split=> // U modU; by apply: minM; rewrite mxmodule_morphim in modU *. Qed. Lemma morphim_mx_irr : (mx_irreducible rG <-> mx_irreducible rGf). Proof. exact: mxsimple_morphim. Qed. Lemma morphim_mx_abs_irr : mx_absolutely_irreducible rG = mx_absolutely_irreducible rGf. Proof. have fG_onto: f @* G \subset restrm sGD f @* G. by rewrite (morphim_restrm sGD) setIid. rewrite -(morphpre_mx_abs_irr _ fG_onto); congr (_ && (_ == _)). by rewrite /enveloping_algebra_mx /= morphpre_restrm (setIidPl _). Qed. End Morphim. Section Submodule. Variables (gT : finGroupType) (G : {group gT}) (n : nat). Variables (rG : mx_representation F G n) (U : 'M[F]_n) (Umod : mxmodule rG U). Local Notation rU := (submod_repr Umod). Local Notation rU' := (factmod_repr Umod). Lemma rfix_submod (H : {set gT}) : H \subset G -> (rfix_mx rU H :=: in_submod U (U :&: rfix_mx rG H))%MS. Proof. move=> sHG; apply/eqmxP/andP; split; last first. apply/rfix_mxP=> x Hx; rewrite -in_submodJ ?capmxSl //. by rewrite (rfix_mxP H _) ?capmxSr. rewrite -val_submodS in_submodK ?capmxSl // sub_capmx val_submodP //=. apply/rfix_mxP=> x Hx. by rewrite -(val_submodJ Umod) ?(subsetP sHG) ?rfix_mx_id. Qed. Lemma rfix_factmod (H : {set gT}) : H \subset G -> (in_factmod U (rfix_mx rG H) <= rfix_mx rU' H)%MS. Proof. move=> sHG; apply/rfix_mxP=> x Hx. by rewrite -(in_factmodJ Umod) ?(subsetP sHG) ?rfix_mx_id. Qed. Lemma rstab_submod m (W : 'M_(m, \rank U)) : rstab rU W = rstab rG (val_submod W). Proof. apply/setP=> x /[!inE]; apply: andb_id2l => Gx. by rewrite -(inj_eq val_submod_inj) val_submodJ. Qed. Lemma rstabs_submod m (W : 'M_(m, \rank U)) : rstabs rU W = rstabs rG (val_submod W). Proof. apply/setP=> x /[!inE]; apply: andb_id2l => Gx. by rewrite -val_submodS val_submodJ. Qed. Lemma val_submod_module m (W : 'M_(m, \rank U)) : mxmodule rG (val_submod W) = mxmodule rU W. Proof. by rewrite /mxmodule rstabs_submod. Qed. Lemma in_submod_module m (V : 'M_(m, n)) : (V <= U)%MS -> mxmodule rU (in_submod U V) = mxmodule rG V. Proof. by move=> sVU; rewrite -val_submod_module in_submodK. Qed. Lemma rstab_factmod m (W : 'M_(m, n)) : rstab rG W \subset rstab rU' (in_factmod U W). Proof. by apply/subsetP=> x /setIdP[Gx /eqP cUW]; rewrite inE Gx -in_factmodJ //= cUW. Qed. Lemma rstabs_factmod m (W : 'M_(m, \rank (cokermx U))) : rstabs rU' W = rstabs rG (U + val_factmod W)%MS. Proof. apply/setP=> x /[!inE]; apply: andb_id2l => Gx. rewrite addsmxMr addsmx_sub (submx_trans (mxmoduleP Umod x Gx)) ?addsmxSl //. rewrite -val_factmodS val_factmodJ //= val_factmodS; apply/idP/idP=> nWx. rewrite (submx_trans (addsmxSr U _)) // -(in_factmodsK (addsmxSl U _)) //. by rewrite addsmxS // val_factmodS in_factmod_addsK. rewrite in_factmodE (submx_trans (submxMr _ nWx)) // -in_factmodE. by rewrite in_factmod_addsK val_factmodK. Qed. Lemma val_factmod_module m (W : 'M_(m, \rank (cokermx U))) : mxmodule rG (U + val_factmod W)%MS = mxmodule rU' W. Proof. by rewrite /mxmodule rstabs_factmod. Qed. Lemma in_factmod_module m (V : 'M_(m, n)) : mxmodule rU' (in_factmod U V) = mxmodule rG (U + V)%MS. Proof. rewrite -(eqmx_module _ (in_factmodsK (addsmxSl U V))). by rewrite val_factmod_module (eqmx_module _ (in_factmod_addsK _ _)). Qed. Lemma rker_submod : rker rU = rstab rG U. Proof. by rewrite /rker rstab_submod; apply: eqmx_rstab (val_submod1 U). Qed. Lemma rstab_norm : G \subset 'N(rstab rG U). Proof. by rewrite -rker_submod rker_norm. Qed. Lemma rstab_normal : rstab rG U <| G. Proof. by rewrite -rker_submod rker_normal. Qed. Lemma submod_mx_faithful : mx_faithful rU -> mx_faithful rG. Proof. by apply: subset_trans; rewrite rker_submod rstabS ?submx1. Qed. Lemma rker_factmod : rker rG \subset rker rU'. Proof. apply/subsetP=> x /rkerP[Gx cVx]. by rewrite inE Gx /= /factmod_mx cVx mul1mx mulmx1 val_factmodK. Qed. Lemma factmod_mx_faithful : mx_faithful rU' -> mx_faithful rG. Proof. exact: subset_trans rker_factmod. Qed. Lemma submod_mx_irr : mx_irreducible rU <-> mxsimple rG U. Proof. split=> [] [_ nzU simU]. rewrite -mxrank_eq0 mxrank1 mxrank_eq0 in nzU; split=> // V modV sVU nzV. rewrite -(in_submodK sVU) -val_submod1 val_submodS. rewrite -(genmxE (in_submod U V)) simU ?genmxE ?submx1 //=. by rewrite (eqmx_module _ (genmxE _)) in_submod_module. by rewrite -submx0 genmxE -val_submodS in_submodK // linear0 eqmx0 submx0. apply/mx_irrP; rewrite lt0n mxrank_eq0; split=> // V modV. rewrite -(inj_eq val_submod_inj) linear0 -(eqmx_eq0 (genmxE _)) => nzV. rewrite -sub1mx -val_submodS val_submod1 -(genmxE (val_submod V)). rewrite simU ?genmxE ?val_submodP //=. by rewrite (eqmx_module _ (genmxE _)) val_submod_module. Qed. End Submodule. Section Conjugate. Variables (gT : finGroupType) (G : {group gT}) (n : nat). Variables (rG : mx_representation F G n) (B : 'M[F]_n). Hypothesis uB : B \in unitmx. Local Notation rGB := (rconj_repr rG uB). Lemma rfix_conj (H : {set gT}) : (rfix_mx rGB H :=: B *m rfix_mx rG H *m invmx B)%MS. Proof. apply/eqmxP/andP; split. rewrite -mulmxA (eqmxMfull (_ *m _)) ?row_full_unit //. rewrite -[rfix_mx rGB H](mulmxK uB) submxMr //; apply/rfix_mxP=> x Hx. apply: (canRL (mulmxKV uB)); rewrite -(rconj_mxJ _ uB) mulmxK //. by rewrite rfix_mx_id. apply/rfix_mxP=> x Gx; rewrite -3!mulmxA; congr (_ *m _). by rewrite !mulmxA mulmxKV // rfix_mx_id. Qed. Lemma rstabs_conj m (U : 'M_(m, n)) : rstabs rGB U = rstabs rG (U *m B). Proof. apply/setP=> x; rewrite !inE rconj_mxE !mulmxA. by rewrite -{2}[U](mulmxK uB) submxMfree // row_free_unit unitmx_inv. Qed. Lemma mxmodule_conj m (U : 'M_(m, n)) : mxmodule rGB U = mxmodule rG (U *m B). Proof. by rewrite /mxmodule rstabs_conj. Qed. Lemma conj_mx_irr : mx_irreducible rGB <-> mx_irreducible rG. Proof. have Bfree: row_free B by rewrite row_free_unit. split => /mx_irrP[n_gt0 irrG]; apply/mx_irrP; split=> // U. rewrite -[U](mulmxKV uB) -mxmodule_conj -mxrank_eq0 /row_full mxrankMfree //. by rewrite mxrank_eq0; apply: irrG. rewrite -mxrank_eq0 /row_full -(mxrankMfree _ Bfree) mxmodule_conj mxrank_eq0. exact: irrG. Qed. End Conjugate. Section Quotient. Variables (gT : finGroupType) (G : {group gT}) (n : nat). Variables (rG : mx_representation F G n) (H : {group gT}). Hypotheses (krH : H \subset rker rG) (nHG : G \subset 'N(H)). Let nHGs := subsetP nHG. Local Notation rGH := (quo_repr krH nHG). Local Notation E_ r := (enveloping_algebra_mx r). Lemma quo_mx_quotient : (E_ rGH :=: E_ rG)%MS. Proof. apply/eqmxP/andP; split; apply/row_subP=> i. rewrite rowK; case/morphimP: (enum_valP i) => x _ Gx ->{i}. rewrite quo_repr_coset // (eq_row_sub (enum_rank_in Gx x)) // rowK. by rewrite enum_rankK_in. rewrite rowK -(quo_mx_coset krH nHG) ?enum_valP //; set Hx := coset H _. have GHx: Hx \in (G / H)%g by rewrite mem_quotient ?enum_valP. by rewrite (eq_row_sub (enum_rank_in GHx Hx)) // rowK enum_rankK_in. Qed. Lemma rfix_quo (K : {group gT}) : K \subset G -> (rfix_mx rGH (K / H)%g :=: rfix_mx rG K)%MS. Proof. move=> sKG; apply/eqmxP/andP; (split; apply/rfix_mxP) => [x Kx | Hx]. have Gx := subsetP sKG x Kx; rewrite -(quo_mx_coset krH nHG) // rfix_mx_id //. by rewrite mem_morphim ?(subsetP nHG). case/morphimP=> x _ Kx ->; have Gx := subsetP sKG x Kx. by rewrite quo_repr_coset ?rfix_mx_id. Qed. Lemma rstabs_quo m (U : 'M_(m, n)) : rstabs rGH U = (rstabs rG U / H)%g. Proof. apply/setP=> Hx /[!inE]; apply/andP/idP=> [[]|] /morphimP[x Nx Gx ->{Hx}]. by rewrite quo_repr_coset // => nUx; rewrite mem_morphim // inE Gx. by case/setIdP: Gx => Gx nUx; rewrite quo_repr_coset ?mem_morphim. Qed. Lemma mxmodule_quo m (U : 'M_(m, n)) : mxmodule rGH U = mxmodule rG U. Proof. rewrite /mxmodule rstabs_quo quotientSGK // ?(subset_trans krH) //. by apply/subsetP=> x /[!inE]/andP[-> /[1!mul1mx]/eqP->/=]; rewrite mulmx1. Qed. Lemma quo_mx_irr : mx_irreducible rGH <-> mx_irreducible rG. Proof. split; case/mx_irrP=> n_gt0 irrG; apply/mx_irrP; split=> // U modU; by apply: irrG; rewrite mxmodule_quo in modU *. Qed. End Quotient. Section SplittingField. Implicit Type gT : finGroupType. Definition group_splitting_field gT (G : {group gT}) := forall n (rG : mx_representation F G n), mx_irreducible rG -> mx_absolutely_irreducible rG. Definition group_closure_field gT := forall G : {group gT}, group_splitting_field G. Lemma quotient_splitting_field gT (G : {group gT}) (H : {set gT}) : G \subset 'N(H) -> group_splitting_field G -> group_splitting_field (G / H). Proof. move=> nHG splitG n rGH irrGH. by rewrite -(morphim_mx_abs_irr _ nHG) splitG //; apply/morphim_mx_irr. Qed. Lemma coset_splitting_field gT (H : {set gT}) : group_closure_field gT -> group_closure_field (coset_of H). Proof. move=> split_gT Gbar; have ->: Gbar = (coset H @*^-1 Gbar / H)%G. by apply: val_inj; rewrite /= /quotient morphpreK ?sub_im_coset. by apply: quotient_splitting_field; [apply: subsetIl | apply: split_gT]. Qed. End SplittingField. Section Abelian. Variables (gT : finGroupType) (G : {group gT}). Lemma mx_faithful_irr_center_cyclic n (rG : mx_representation F G n) : mx_faithful rG -> mx_irreducible rG -> cyclic 'Z(G). Proof. case: n rG => [|n] rG injG irrG; first by case/mx_irrP: irrG. move/trivgP: injG => KrG1; pose rZ := subg_repr rG (center_sub _). apply: (div_ring_mul_group_cyclic (repr_mx1 rZ)) (repr_mxM rZ) _ _; last first. exact: center_abelian. move=> x; rewrite -[[set _]]KrG1 !inE mul1mx -subr_eq0 andbC; set U := _ - _. do 2![case/andP]=> Gx cGx; rewrite Gx /=; apply: (mx_Schur irrG). apply/centgmxP=> y Gy; rewrite mulmxBl mulmxBr mulmx1 mul1mx. by rewrite -!repr_mxM // (centP cGx). Qed. Lemma mx_faithful_irr_abelian_cyclic n (rG : mx_representation F G n) : mx_faithful rG -> mx_irreducible rG -> abelian G -> cyclic G. Proof. move=> injG irrG cGG; rewrite -(setIidPl cGG). exact: mx_faithful_irr_center_cyclic injG irrG. Qed. Hypothesis splitG : group_splitting_field G. Lemma mx_irr_abelian_linear n (rG : mx_representation F G n) : mx_irreducible rG -> abelian G -> n = 1. Proof. by move=> irrG cGG; apply/eqP; rewrite -(abelian_abs_irr rG) ?splitG. Qed. Lemma mxsimple_abelian_linear n (rG : mx_representation F G n) M : abelian G -> mxsimple rG M -> \rank M = 1. Proof. move=> cGG simM; have [modM _ _] := simM. by move/(submod_mx_irr modM)/mx_irr_abelian_linear: simM => ->. Qed. Lemma linear_mxsimple n (rG : mx_representation F G n) (M : 'M_n) : mxmodule rG M -> \rank M = 1 -> mxsimple rG M. Proof. move=> modM rM1; apply/(submod_mx_irr modM). by apply: mx_abs_irrW; rewrite linear_mx_abs_irr. Qed. End Abelian. Section AbelianQuotient. Variables (gT : finGroupType) (G : {group gT}). Variables (n : nat) (rG : mx_representation F G n). Lemma center_kquo_cyclic : mx_irreducible rG -> cyclic 'Z(G / rker rG)%g. Proof. move=> irrG; apply: mx_faithful_irr_center_cyclic (kquo_mx_faithful rG) _. exact/quo_mx_irr. Qed. Lemma der1_sub_rker : group_splitting_field G -> mx_irreducible rG -> (G^`(1) \subset rker rG)%g = (n == 1)%N. Proof. move=> splitG irrG; apply/idP/idP; last by move/eqP; apply: rker_linear. move/sub_der1_abelian; move/(abelian_abs_irr (kquo_repr rG))=> <-. by apply: (quotient_splitting_field (rker_norm _) splitG); apply/quo_mx_irr. Qed. End AbelianQuotient. Section Similarity. Variables (gT : finGroupType) (G : {group gT}). Local Notation reprG := (mx_representation F G). Variant mx_rsim n1 (rG1 : reprG n1) n2 (rG2 : reprG n2) : Prop := MxReprSim B of n1 = n2 & row_free B & forall x, x \in G -> rG1 x *m B = B *m rG2 x. Lemma mxrank_rsim n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> n1 = n2. Proof. by case. Qed. Lemma mx_rsim_refl n (rG : reprG n) : mx_rsim rG rG. Proof. exists 1%:M => // [|x _]; first by rewrite row_free_unit unitmx1. by rewrite mulmx1 mul1mx. Qed. Lemma mx_rsim_sym n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> mx_rsim rG2 rG1. Proof. case=> B def_n1; rewrite def_n1 in rG1 B *. rewrite row_free_unit => injB homB; exists (invmx B) => // [|x Gx]. by rewrite row_free_unit unitmx_inv. by apply: canRL (mulKmx injB) _; rewrite mulmxA -homB ?mulmxK. Qed. Lemma mx_rsim_trans n1 n2 n3 (rG1 : reprG n1) (rG2 : reprG n2) (rG3 : reprG n3) : mx_rsim rG1 rG2 -> mx_rsim rG2 rG3 -> mx_rsim rG1 rG3. Proof. case=> [B1 defn1 freeB1 homB1] [B2 defn2 freeB2 homB2]. exists (B1 *m B2); rewrite /row_free ?mxrankMfree 1?defn1 // => x Gx. by rewrite mulmxA homB1 // -!mulmxA homB2. Qed. Lemma mx_rsim_def n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> exists B, exists2 B', B' *m B = 1%:M & forall x, x \in G -> rG1 x = B *m rG2 x *m B'. Proof. case=> B def_n1; rewrite def_n1 in rG1 B *; rewrite row_free_unit => injB homB. by exists B, (invmx B) => [|x Gx]; rewrite ?mulVmx // -homB // mulmxK. Qed. Lemma mx_rsim_iso n (rG : reprG n) (U V : 'M_n) (modU : mxmodule rG U) (modV : mxmodule rG V) : mx_rsim (submod_repr modU) (submod_repr modV) <-> mx_iso rG U V. Proof. split=> [[B eqrUV injB homB] | [f injf homf defV]]. have: \rank (U *m val_submod (in_submod U 1%:M *m B)) = \rank U. do 2!rewrite mulmxA mxrankMfree ?row_base_free //. by rewrite -(eqmxMr _ (val_submod1 U)) -in_submodE val_submodK mxrank1. case/complete_unitmx => f injf defUf; exists f => //. apply/hom_mxP=> x Gx; rewrite -defUf -2!mulmxA -(val_submodJ modV) //. rewrite -(mulmxA _ B) -homB // val_submodE 3!(mulmxA U) (mulmxA _ _ B). rewrite -in_submodE -in_submodJ //. have [u ->] := submxP (mxmoduleP modU x Gx). by rewrite in_submodE -mulmxA -defUf !mulmxA !mulmx1. apply/eqmxP; rewrite -mxrank_leqif_eq. by rewrite mxrankMfree ?eqrUV ?row_free_unit. by rewrite -defUf mulmxA val_submodP. have eqrUV: \rank U = \rank V by rewrite -defV mxrankMfree ?row_free_unit. exists (in_submod V (val_submod 1%:M *m f)) => // [|x Gx]. rewrite /row_free {6}eqrUV -[_ == _]sub1mx -val_submodS. rewrite in_submodK; last by rewrite -defV submxMr ?val_submodP. by rewrite val_submod1 -defV submxMr ?val_submod1. rewrite -in_submodJ; last by rewrite -defV submxMr ?val_submodP. rewrite -(hom_mxP (submx_trans (val_submodP _) homf)) // -(val_submodJ modU) //. by rewrite mul1mx 2!(mulmxA ((submod_repr _) x)) -val_submodE. Qed. Lemma mx_rsim_irr n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> mx_irreducible rG1 -> mx_irreducible rG2. Proof. case/mx_rsim_sym=> f def_n2; rewrite {n2}def_n2 in f rG2 * => injf homf. case/mx_irrP=> n1_gt0 minG; apply/mx_irrP; split=> // U modU nzU. rewrite /row_full -(mxrankMfree _ injf) -genmxE. apply: minG; last by rewrite -mxrank_eq0 genmxE mxrankMfree // mxrank_eq0. rewrite (eqmx_module _ (genmxE _)); apply/mxmoduleP=> x Gx. by rewrite -mulmxA -homf // mulmxA submxMr // (mxmoduleP modU). Qed. Lemma mx_rsim_abs_irr n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> mx_absolutely_irreducible rG1 = mx_absolutely_irreducible rG2. Proof. case=> f def_n2; rewrite -{n2}def_n2 in f rG2 *. rewrite row_free_unit => injf homf; congr (_ && (_ == _)). pose Eg (g : 'M[F]_n1) := lin_mx (mulmxr (invmx g) \o mulmx g). have free_Ef: row_free (Eg f). apply/row_freeP; exists (Eg (invmx f)); apply/row_matrixP=> i. rewrite rowE row1 mulmxA mul_rV_lin mx_rV_lin /=. by rewrite invmxK !{1}mulmxA mulmxKV // -mulmxA mulKmx // vec_mxK. symmetry; rewrite -(mxrankMfree _ free_Ef); congr (\rank _). apply/row_matrixP=> i; rewrite row_mul !rowK mul_vec_lin /=. by rewrite -homf ?enum_valP // mulmxK. Qed. Lemma rker_mx_rsim n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> rker rG1 = rker rG2. Proof. case=> f def_n2; rewrite -{n2}def_n2 in f rG2 *. rewrite row_free_unit => injf homf. apply/setP=> x; rewrite !inE !mul1mx; apply: andb_id2l => Gx. by rewrite -(can_eq (mulmxK injf)) homf // -scalar_mxC (can_eq (mulKmx injf)). Qed. Lemma mx_rsim_faithful n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> mx_faithful rG1 = mx_faithful rG2. Proof. by move=> simG12; rewrite /mx_faithful (rker_mx_rsim simG12). Qed. Lemma mx_rsim_factmod n (rG : reprG n) U V (modU : mxmodule rG U) (modV : mxmodule rG V) : (U + V :=: 1%:M)%MS -> mxdirect (U + V) -> mx_rsim (factmod_repr modV) (submod_repr modU). Proof. move=> addUV dxUV. have eqUV: \rank U = \rank (cokermx V). by rewrite mxrank_coker -{3}(mxrank1 F n) -addUV (mxdirectP dxUV) addnK. have{} dxUV: (U :&: V = 0)%MS by apply/mxdirect_addsP. exists (in_submod U (val_factmod 1%:M *m proj_mx U V)) => // [|x Gx]. rewrite /row_free -{6}eqUV -[_ == _]sub1mx -val_submodS val_submod1. rewrite in_submodK ?proj_mx_sub // -{1}[U](proj_mx_id dxUV) //. rewrite -{1}(add_sub_fact_mod V U) mulmxDl proj_mx_0 ?val_submodP // add0r. by rewrite submxMr // val_factmodS submx1. rewrite -in_submodJ ?proj_mx_sub // -(hom_mxP _) //; last first. by apply: submx_trans (submx1 _) _; rewrite -addUV proj_mx_hom. rewrite mulmxA; congr (_ *m _); rewrite mulmxA -val_factmodE; apply/eqP. rewrite eq_sym -subr_eq0 -mulmxBl proj_mx_0 //. by rewrite -[_ *m rG x](add_sub_fact_mod V) addrK val_submodP. Qed. Lemma mxtrace_rsim n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> {in G, forall x, \tr (rG1 x) = \tr (rG2 x)}. Proof. case/mx_rsim_def=> B [B' B'B def_rG1] x Gx. by rewrite def_rG1 // mxtrace_mulC mulmxA B'B mul1mx. Qed. Lemma mx_rsim_scalar n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) x c : x \in G -> mx_rsim rG1 rG2 -> rG1 x = c%:M -> rG2 x = c%:M. Proof. move=> Gx /mx_rsim_sym[B _ Bfree rG2_B] rG1x. by apply: (row_free_inj Bfree); rewrite rG2_B // rG1x scalar_mxC. Qed. End Similarity. Section Socle. Variables (gT : finGroupType) (G : {group gT}). Variables (n : nat) (rG : mx_representation F G n) (sG : socleType rG). Lemma socle_irr (W : sG) : mx_irreducible (socle_repr W). Proof. by apply/submod_mx_irr; apply: socle_simple. Qed. Lemma socle_rsimP (W1 W2 : sG) : reflect (mx_rsim (socle_repr W1) (socle_repr W2)) (W1 == W2). Proof. have [simW1 simW2] := (socle_simple W1, socle_simple W2). by apply: (iffP (component_mx_isoP simW1 simW2)); move/mx_rsim_iso; apply. Qed. Local Notation mG U := (mxmodule rG U). Local Notation sr modV := (submod_repr modV). Lemma mx_rsim_in_submod U V (modU : mG U) (modV : mG V) : let U' := <<in_submod V U>>%MS in (U <= V)%MS -> exists modU' : mxmodule (sr modV) U', mx_rsim (sr modU) (sr modU'). Proof. move=> U' sUV; have modU': mxmodule (sr modV) U'. by rewrite (eqmx_module _ (genmxE _)) in_submod_module. have rankU': \rank U = \rank U' by rewrite genmxE mxrank_in_submod. pose v1 := val_submod 1%:M; pose U1 := v1 _ U. have sU1V: (U1 <= V)%MS by rewrite val_submod1. have sU1U': (in_submod V U1 <= U')%MS by rewrite genmxE submxMr ?val_submod1. exists modU', (in_submod U' (in_submod V U1)) => // [|x Gx]. apply/row_freeP; exists (v1 _ _ *m v1 _ _ *m in_submod U 1%:M). rewrite mulmxA [X in X *m _]mulmxA -in_submodE. by rewrite -!val_submodE !in_submodK ?val_submodK. rewrite -!in_submodJ // -(val_submodJ modU) // mul1mx. by rewrite 2!{1}in_submodE mulmxA (mulmxA _ U1) -val_submodE -!in_submodE. Qed. Lemma rsim_submod1 U (modU : mG U) : (U :=: 1%:M)%MS -> mx_rsim (sr modU) rG. Proof. move=> U1; exists (val_submod 1%:M) => [||x Gx]; first by rewrite U1 mxrank1. by rewrite /row_free val_submod1. by rewrite -(val_submodJ modU) // mul1mx -val_submodE. Qed. Lemma mxtrace_submod1 U (modU : mG U) : (U :=: 1%:M)%MS -> {in G, forall x, \tr (sr modU x) = \tr (rG x)}. Proof. by move=> defU; apply: mxtrace_rsim (rsim_submod1 modU defU). Qed. Lemma mxtrace_dadd_mod U V W (modU : mG U) (modV : mG V) (modW : mG W) : (U + V :=: W)%MS -> mxdirect (U + V) -> {in G, forall x, \tr (sr modU x) + \tr (sr modV x) = \tr (sr modW x)}. Proof. move=> defW dxW x Gx; have [sUW sVW]: (U <= W)%MS /\ (V <= W)%MS. by apply/andP; rewrite -addsmx_sub defW. pose U' := <<in_submod W U>>%MS; pose V' := <<in_submod W V>>%MS. have addUV': (U' + V' :=: 1%:M)%MS. apply/eqmxP; rewrite submx1 /= (adds_eqmx (genmxE _) (genmxE _)). by rewrite -addsmxMr -val_submodS val_submod1 in_submodK ?defW. have dxUV': mxdirect (U' + V'). apply/eqnP; rewrite /= addUV' mxrank1 !genmxE !mxrank_in_submod //. by rewrite -(mxdirectP dxW) /= defW. have [modU' simU] := mx_rsim_in_submod modU modW sUW. have [modV' simV] := mx_rsim_in_submod modV modW sVW. rewrite (mxtrace_rsim simU) // (mxtrace_rsim simV) //. rewrite -(mxtrace_sub_fact_mod modV') addrC; congr (_ + _). by rewrite (mxtrace_rsim (mx_rsim_factmod modU' modV' addUV' dxUV')). Qed. Lemma mxtrace_dsum_mod (I : finType) (P : pred I) U W (modU : forall i, mG (U i)) (modW : mG W) : let S := (\sum_(i | P i) U i)%MS in (S :=: W)%MS -> mxdirect S -> {in G, forall x, \sum_(i | P i) \tr (sr (modU i) x) = \tr (sr modW x)}. Proof. move=> /= sumS dxS x Gx; have [m lePm] := ubnP #|P|. elim: m => // m IHm in P lePm W modW sumS dxS *. have [j /= Pj | P0] := pickP P; last first. case: sumS (_ x); rewrite !big_pred0 // mxrank0 => <- _ rWx. by rewrite [rWx]flatmx0 linear0. rewrite ltnS (cardD1x Pj) in lePm. rewrite mxdirectE /= !(bigD1 j Pj) -mxdirectE mxdirect_addsE /= in dxS sumS *. have [_ dxW' dxW] := and3P dxS; rewrite (sameP eqP mxdirect_addsP) in dxW. rewrite (IHm _ _ _ (sumsmx_module _ (fun i _ => modU i)) (eqmx_refl _)) //. exact: mxtrace_dadd_mod. Qed. Lemma mxtrace_component U (simU : mxsimple rG U) : let V := component_mx rG U in let modV := component_mx_module rG U in let modU := mxsimple_module simU in {in G, forall x, \tr (sr modV x) = \tr (sr modU x) *+ (\rank V %/ \rank U)}. Proof. move=> V modV modU x Gx. have [I W S simW defV dxV] := component_mx_semisimple simU. rewrite -(mxtrace_dsum_mod (fun i => mxsimple_module (simW i)) modV defV) //. have rankU_gt0: \rank U > 0 by rewrite lt0n mxrank_eq0; case simU. have isoW i: mx_iso rG U (W i). by apply: component_mx_iso; rewrite ?simU // -defV (sumsmx_sup i). have ->: (\rank V %/ \rank U)%N = #|I|. symmetry; rewrite -(mulnK #|I| rankU_gt0); congr (_ %/ _)%N. rewrite -defV (mxdirectP dxV) /= -sum_nat_const. by apply: eq_bigr => i _; apply: mxrank_iso. rewrite -sumr_const; apply: eq_bigr => i _; symmetry. by apply: mxtrace_rsim Gx; apply/mx_rsim_iso; apply: isoW. Qed. Lemma mxtrace_Socle : let modS := Socle_module sG in {in G, forall x, \tr (sr modS x) = \sum_(W : sG) \tr (socle_repr W x) *+ socle_mult W}. Proof. move=> /= x Gx /=; pose modW (W : sG) := component_mx_module rG (socle_base W). rewrite -(mxtrace_dsum_mod modW _ (eqmx_refl _) (Socle_direct sG)) //. by apply: eq_bigr => W _; rewrite (mxtrace_component (socle_simple W)). Qed. End Socle. Section Clifford. Variables (gT : finGroupType) (G H : {group gT}). Hypothesis nsHG : H <| G. Variables (n : nat) (rG : mx_representation F G n). Let sHG := normal_sub nsHG. Let nHG := normal_norm nsHG. Let rH := subg_repr rG sHG. Lemma Clifford_simple M x : mxsimple rH M -> x \in G -> mxsimple rH (M *m rG x). Proof. have modmG m U y: y \in G -> (mxmodule rH) m U -> mxmodule rH (U *m rG y). move=> Gy modU; apply/mxmoduleP=> h Hh; have Gh := subsetP sHG h Hh. rewrite -mulmxA -repr_mxM // conjgCV repr_mxM ?groupJ ?groupV // mulmxA. by rewrite submxMr ?(mxmoduleP modU) // -mem_conjg (normsP nHG). have nzmG m y (U : 'M_(m, n)): y \in G -> (U *m rG y == 0) = (U == 0). by move=> Gy; rewrite -{1}(mul0mx m (rG y)) (can_eq (repr_mxK rG Gy)). case=> [modM nzM simM] Gx; have Gx' := groupVr Gx. split=> [||U modU sUMx nzU]; rewrite ?modmG ?nzmG //. rewrite -(repr_mxKV rG Gx U) submxMr //. by rewrite (simM (U *m _)) ?modmG ?nzmG // -(repr_mxK rG Gx M) submxMr. Qed. Lemma Clifford_hom x m (U : 'M_(m, n)) : x \in 'C_G(H) -> (U <= dom_hom_mx rH (rG x))%MS. Proof. case/setIP=> Gx cHx; apply/rV_subP=> v _{U}. apply/hom_mxP=> h Hh; have Gh := subsetP sHG h Hh. by rewrite -!mulmxA /= -!repr_mxM // (centP cHx). Qed. Lemma Clifford_iso x U : x \in 'C_G(H) -> mx_iso rH U (U *m rG x). Proof. move=> cHx; have [Gx _] := setIP cHx. by exists (rG x); rewrite ?repr_mx_unit ?Clifford_hom. Qed. Lemma Clifford_iso2 x U V : mx_iso rH U V -> x \in G -> mx_iso rH (U *m rG x) (V *m rG x). Proof. case=> [f injf homUf defV] Gx; have Gx' := groupVr Gx. pose fx := rG (x^-1)%g *m f *m rG x; exists fx; last 1 first. - by rewrite !mulmxA repr_mxK //; apply: eqmxMr. - by rewrite !unitmx_mul andbC !repr_mx_unit. apply/hom_mxP=> h Hh; have Gh := subsetP sHG h Hh. rewrite -(mulmxA U) -repr_mxM // conjgCV repr_mxM ?groupJ // !mulmxA. rewrite !repr_mxK // (hom_mxP homUf) -?mem_conjg ?(normsP nHG) //=. by rewrite !repr_mxM ?invgK ?groupM // !mulmxA repr_mxKV. Qed. Lemma Clifford_componentJ M x : mxsimple rH M -> x \in G -> (component_mx rH (M *m rG x) :=: component_mx rH M *m rG x)%MS. Proof. set simH := mxsimple rH; set cH := component_mx rH. have actG: {in G, forall y M, simH M -> cH M *m rG y <= cH (M *m rG y)}%MS. move=> {M} y Gy /= M simM; have [I [U isoU def_cHM]] := component_mx_def simM. rewrite /cH def_cHM sumsmxMr; apply/sumsmx_subP=> i _. by apply: mx_iso_component; [apply: Clifford_simple | apply: Clifford_iso2]. move=> simM Gx; apply/eqmxP; rewrite actG // -/cH. rewrite -{1}[cH _](repr_mxKV rG Gx) submxMr // -{2}[M](repr_mxK rG Gx). by rewrite actG ?groupV //; apply: Clifford_simple. Qed. Hypothesis irrG : mx_irreducible rG. Lemma Clifford_basis M : mxsimple rH M -> {X : {set gT} | X \subset G & let S := \sum_(x in X) M *m rG x in S :=: 1%:M /\ mxdirect S}%MS. Proof. move=> simM. have simMG (g : [subg G]) : mxsimple rH (M *m rG (val g)). by case: g => x Gx; apply: Clifford_simple. have [|XG [defX1 dxX1]] := sum_mxsimple_direct_sub simMG (_ : _ :=: 1%:M)%MS. apply/eqmxP; case irrG => _ _ ->; rewrite ?submx1 //; last first. rewrite -submx0; apply/sumsmx_subP; move/(_ 1%g (erefl _)); apply: negP. by rewrite submx0 repr_mx1 mulmx1; case simM. apply/mxmoduleP=> x Gx; rewrite sumsmxMr; apply/sumsmx_subP=> [[y Gy]] /= _. by rewrite (sumsmx_sup (subg G (y * x)))// subgK ?groupM// -mulmxA repr_mxM. exists (val @: XG); first by apply/subsetP=> ?; case/imsetP=> [[x Gx]] _ ->. have bij_val: {on val @: XG, bijective (@sgval _ G)}. exists (subg G) => [g _ | x]; first exact: sgvalK. by case/imsetP=> [[x' Gx]] _ ->; rewrite subgK. have defXG g: (val g \in val @: XG) = (g \in XG). by apply/imsetP/idP=> [[h XGh] | XGg]; [move/val_inj-> | exists g]. by rewrite /= mxdirectE /= !(reindex _ bij_val) !(eq_bigl _ _ defXG). Qed. Variable sH : socleType rH. Definition Clifford_act (W : sH) x := let Gx := subgP (subg G x) in PackSocle (component_socle sH (Clifford_simple (socle_simple W) Gx)). Let valWact W x : (Clifford_act W x :=: W *m rG (sgval (subg G x)))%MS. Proof. rewrite PackSocleK; apply: Clifford_componentJ (subgP _). exact: socle_simple. Qed. Fact Clifford_is_action : is_action G Clifford_act. Proof. split=> [x W W' eqWW' | W x y Gx Gy]. pose Gx := subgP (subg G x); apply/socleP; apply/eqmxP. rewrite -(repr_mxK rG Gx W) -(repr_mxK rG Gx W'); apply: eqmxMr. apply: eqmx_trans (eqmx_sym _) (valWact _ _). by rewrite -eqWW'; apply: valWact. apply/socleP; rewrite !{1}valWact 2!{1}(eqmxMr _ (valWact _ _)). by rewrite !subgK ?groupM ?repr_mxM ?mulmxA ?andbb. Qed. Definition Clifford_action := Action Clifford_is_action. Local Notation "'Cl" := Clifford_action : action_scope. Lemma val_Clifford_act W x : x \in G -> ('Cl%act W x :=: W *m rG x)%MS. Proof. by move=> Gx; apply: eqmx_trans (valWact _ _) _; rewrite subgK. Qed. Lemma Clifford_atrans : [transitive G, on [set: sH] | 'Cl]. Proof. have [_ nz1 _] := irrG. apply: mxsimple_exists (mxmodule1 rH) nz1 _ _ => [[M simM _]]. pose W1 := PackSocle (component_socle sH simM). have [X sXG [def1 _]] := Clifford_basis simM; move/subsetP: sXG => sXG. apply/imsetP; exists W1; first by rewrite inE. symmetry; apply/setP=> W /[1!inE]; have simW := socle_simple W. have:= submx1 (socle_base W); rewrite -def1 -[(\sum_(x in X) _)%MS]mulmx1. case/(hom_mxsemisimple_iso simW) => [x Xx _ | | x Xx isoMxW]. - by apply: Clifford_simple; rewrite ?sXG. - exact: scalar_mx_hom. have Gx := sXG x Xx; apply/imsetP; exists x => //; apply/socleP/eqmxP/eqmx_sym. apply: eqmx_trans (val_Clifford_act _ Gx) _; rewrite PackSocleK. apply: eqmx_trans (eqmx_sym (Clifford_componentJ simM Gx)) _. apply/eqmxP; rewrite (sameP genmxP eqP) !{1}genmx_component. by apply/component_mx_isoP=> //; apply: Clifford_simple. Qed. Lemma Clifford_Socle1 : Socle sH = 1%:M. Proof. case/imsetP: Clifford_atrans => W _ _; have simW := socle_simple W. have [X sXG [def1 _]] := Clifford_basis simW. rewrite reducible_Socle1 //; apply: mxsemisimple_reducible. apply: intro_mxsemisimple def1 _ => x /(subsetP sXG) Gx _. exact: Clifford_simple. Qed. Lemma Clifford_rank_components (W : sH) : (#|sH| * \rank W)%N = n. Proof. rewrite -{9}(mxrank1 F n) -Clifford_Socle1. rewrite (mxdirectP (Socle_direct sH)) /= -sum_nat_const. apply: eq_bigr => W1 _; have [W0 _ W0G] := imsetP Clifford_atrans. have{} W0G W': W' \in orbit 'Cl G W0 by rewrite -W0G inE. have [/orbitP[x Gx <-] /orbitP[y Gy <-]] := (W0G W, W0G W1). by rewrite !{1}val_Clifford_act // !mxrankMfree // !repr_mx_free. Qed. Theorem Clifford_component_basis M : mxsimple rH M -> {t : nat & {x_ : sH -> 'I_t -> gT | forall W, let sW := (\sum_j M *m rG (x_ W j))%MS in [/\ forall j, x_ W j \in G, (sW :=: W)%MS & mxdirect sW]}}. Proof. move=> simM; pose t := (n %/ #|sH| %/ \rank M)%N; exists t. have [X /subsetP sXG [defX1 dxX1]] := Clifford_basis simM. pose sMv (W : sH) x := (M *m rG x <= W)%MS; pose Xv := [pred x in X | sMv _ x]. have sXvG W: {subset Xv W <= G} by move=> x /andP[/sXG]. have defW W: (\sum_(x in Xv W) M *m rG x :=: W)%MS. apply/eqmxP; rewrite -(geq_leqif (mxrank_leqif_eq _)); last first. by apply/sumsmx_subP=> x /andP[]. rewrite -(leq_add2r (\sum_(W' | W' != W) \rank W')) -((bigD1 W) predT) //=. rewrite -(mxdirectP (Socle_direct sH)) /= -/(Socle _) Clifford_Socle1 -defX1. apply: leq_trans (mxrankS _) (mxrank_sum_leqif _).1 => /=. rewrite (bigID (sMv W))%MS addsmxS //=. apply/sumsmx_subP=> x /andP[Xx notW_Mx]; have Gx := sXG x Xx. have simMx := Clifford_simple simM Gx. pose Wx := PackSocle (component_socle sH simMx). have sMxWx: (M *m rG x <= Wx)%MS by rewrite PackSocleK component_mx_id. by rewrite (sumsmx_sup Wx) //; apply: contra notW_Mx => /eqP <-. have dxXv W: mxdirect (\sum_(x in Xv W) M *m rG x). move: dxX1; rewrite !mxdirectE /= !(bigID (sMv W) [in X]) /=. by rewrite -mxdirectE mxdirect_addsE /= => /andP[]. have def_t W: #|Xv W| = t. rewrite /t -{1}(Clifford_rank_components W) mulKn 1?(cardD1 W) //. rewrite -defW (mxdirectP (dxXv W)) /= (eq_bigr (fun _ => \rank M)) => [|x]. rewrite sum_nat_const mulnK //; last by rewrite lt0n mxrank_eq0; case simM. by move/sXvG=> Gx; rewrite mxrankMfree // row_free_unit repr_mx_unit. exists (fun W i => enum_val (cast_ord (esym (def_t W)) i)) => W. case: {def_t}t / (def_t W) => sW. case: (pickP (Xv W)) => [x0 XvWx0 | XvW0]; last first. by case/negP: (nz_socle W); rewrite -submx0 -defW big_pred0. have{x0 XvWx0} reXv := reindex _ (enum_val_bij_in XvWx0). have def_sW: (sW :=: W)%MS. apply: eqmx_trans (defW W); apply/eqmxP; apply/genmxP; congr <<_>>%MS. rewrite reXv /=; apply: eq_big => [j | j _]; first by have:= enum_valP j. by rewrite cast_ord_id. split=> // [j|]; first by rewrite (sXvG W) ?enum_valP. apply/mxdirectP; rewrite def_sW -(defW W) /= (mxdirectP (dxXv W)) /= reXv /=. by apply: eq_big => [j | j _]; [move: (enum_valP j) | rewrite cast_ord_id]. Qed. Lemma Clifford_astab : H <*> 'C_G(H) \subset 'C([set: sH] | 'Cl). Proof. rewrite join_subG !subsetI sHG subsetIl /=; apply/andP; split. apply/subsetP=> h Hh /[1!inE]; have Gh := subsetP sHG h Hh. apply/subsetP=> W _; have simW := socle_simple W; have [modW _ _] := simW. have simWh: mxsimple rH (socle_base W *m rG h) by apply: Clifford_simple. rewrite inE -val_eqE /= PackSocleK eq_sym. apply/component_mx_isoP; rewrite ?subgK //; apply: component_mx_iso => //. by apply: submx_trans (component_mx_id simW); move/mxmoduleP: modW => ->. apply/subsetP=> z cHz /[1!inE]; have [Gz _] := setIP cHz. apply/subsetP=> W _; have simW := socle_simple W; have [modW _ _] := simW. have simWz: mxsimple rH (socle_base W *m rG z) by apply: Clifford_simple. rewrite inE -val_eqE /= PackSocleK eq_sym. by apply/component_mx_isoP; rewrite ?subgK //; apply: Clifford_iso. Qed. Lemma Clifford_astab1 (W : sH) : 'C[W | 'Cl] = rstabs rG W. Proof. apply/setP=> x /[!inE]; apply: andb_id2l => Gx. rewrite sub1set inE (sameP eqP socleP) !val_Clifford_act //. rewrite andb_idr // => sWxW; rewrite -mxrank_leqif_sup //. by rewrite mxrankMfree ?repr_mx_free. Qed. Lemma Clifford_rstabs_simple (W : sH) : mxsimple (subg_repr rG (rstabs_sub rG W)) W. Proof. split => [||U modU sUW nzU]; last 2 [exact: nz_socle]. by rewrite /mxmodule rstabs_subg setIid. have modUH: mxmodule rH U. apply/mxmoduleP=> h Hh; rewrite (mxmoduleP modU) //. rewrite /= -Clifford_astab1 !(inE, sub1set) (subsetP sHG) //. rewrite (astab_act (subsetP Clifford_astab h _)) ?inE //=. by rewrite mem_gen // inE Hh. apply: (mxsimple_exists modUH nzU) => [[M simM sMU]]. have [t [x_ /(_ W)[Gx_ defW _]]] := Clifford_component_basis simM. rewrite -defW; apply/sumsmx_subP=> j _; set x := x_ W j. have{Gx_} Gx: x \in G by rewrite Gx_. apply: submx_trans (submxMr _ sMU) _; apply: (mxmoduleP modU). rewrite inE -val_Clifford_act Gx //; set Wx := 'Cl%act W x. case: (eqVneq Wx W) (simM) => [-> //=|] neWxW [_ /negP[]]; rewrite -submx0. rewrite (canF_eq (actKin 'Cl Gx)) in neWxW. rewrite -(component_mx_disjoint _ _ neWxW); try exact: socle_simple. rewrite sub_capmx {1}(submx_trans sMU sUW) val_Clifford_act ?groupV //. by rewrite -(eqmxMr _ defW) sumsmxMr (sumsmx_sup j) ?repr_mxK. Qed. End Clifford. Section JordanHolder. Variables (gT : finGroupType) (G : {group gT}). Variables (n : nat) (rG : mx_representation F G n). Local Notation modG := ((mxmodule rG) n). Lemma section_module (U V : 'M_n) (modU : modG U) (modV : modG V) : mxmodule (factmod_repr modU) <<in_factmod U V>>%MS. Proof. by rewrite (eqmx_module _ (genmxE _)) in_factmod_module addsmx_module. Qed. Definition section_repr U V (modU : modG U) (modV : modG V) := submod_repr (section_module modU modV). Lemma mx_factmod_sub U modU : mx_rsim (@section_repr U _ modU (mxmodule1 rG)) (factmod_repr modU). Proof. exists (val_submod 1%:M) => [||x Gx]. - apply: (@addIn (\rank U)); rewrite genmxE mxrank_in_factmod mxrank_coker. by rewrite (addsmx_idPr (submx1 U)) mxrank1 subnK ?rank_leq_row. - by rewrite /row_free val_submod1. by rewrite -[_ x]mul1mx -val_submodE val_submodJ. Qed. Definition max_submod (U V : 'M_n) := (U < V)%MS /\ (forall W, ~ [/\ modG W, U < W & W < V])%MS. Lemma max_submodP U V (modU : modG U) (modV : modG V) : (U <= V)%MS -> (max_submod U V <-> mx_irreducible (section_repr modU modV)). Proof. move=> sUV; split=> [[ltUV maxU] | ]. apply/mx_irrP; split=> [|WU modWU nzWU]. by rewrite genmxE lt0n mxrank_eq0 in_factmod_eq0; case/andP: ltUV. rewrite -sub1mx -val_submodS val_submod1 genmxE. pose W := (U + val_factmod (val_submod WU))%MS. suffices sVW: (V <= W)%MS. rewrite {2}in_factmodE (submx_trans (submxMr _ sVW)) //. rewrite addsmxMr -!in_factmodE val_factmodK. by rewrite ((in_factmod U U =P 0) _) ?adds0mx ?in_factmod_eq0. move/and3P: {maxU}(maxU W); apply: contraR; rewrite /ltmx addsmxSl => -> /=. move: modWU; rewrite /mxmodule rstabs_submod rstabs_factmod => -> /=. rewrite addsmx_sub submx_refl -in_factmod_eq0 val_factmodK. move: nzWU; rewrite -[_ == 0](inj_eq val_submod_inj) linear0 => ->. rewrite -(in_factmodsK sUV) addsmxS // val_factmodS. by rewrite -(genmxE (in_factmod U V)) val_submodP. case/mx_irrP; rewrite lt0n {1}genmxE mxrank_eq0 in_factmod_eq0 => ltUV maxV. split=> // [|W [modW /andP[sUW ltUW] /andP[sWV /negP[]]]]; first exact/andP. rewrite -(in_factmodsK sUV) -(in_factmodsK sUW) addsmxS // val_factmodS. rewrite -genmxE -val_submod1; set VU := <<_>>%MS. have sW_VU: (in_factmod U W <= VU)%MS. by rewrite genmxE -val_factmodS !submxMr. rewrite -(in_submodK sW_VU) val_submodS -(genmxE (in_submod _ _)). rewrite sub1mx maxV //. rewrite (eqmx_module _ (genmxE _)) in_submod_module ?genmxE ?submxMr //. by rewrite in_factmod_module addsmx_module. rewrite -submx0 [(_ <= 0)%MS]genmxE -val_submodS linear0 in_submodK //. by rewrite eqmx0 submx0 in_factmod_eq0. Qed. Lemma max_submod_eqmx U1 U2 V1 V2 : (U1 :=: U2)%MS -> (V1 :=: V2)%MS -> max_submod U1 V1 -> max_submod U2 V2. Proof. move=> eqU12 eqV12 [ltUV1 maxU1]. by split=> [|W]; rewrite -(lt_eqmx eqU12) -(lt_eqmx eqV12). Qed. Definition mx_subseries := all modG. Definition mx_composition_series V := mx_subseries V /\ (forall i, i < size V -> max_submod (0 :: V)`_i V`_i). Local Notation mx_series := mx_composition_series. Fact mx_subseries_module V i : mx_subseries V -> mxmodule rG V`_i. Proof. move=> modV; have [|leVi] := ltnP i (size V); first exact: all_nthP. by rewrite nth_default ?mxmodule0. Qed. Fact mx_subseries_module' V i : mx_subseries V -> mxmodule rG (0 :: V)`_i. Proof. by move=> modV; rewrite mx_subseries_module //= mxmodule0. Qed. Definition subseries_repr V i (modV : all modG V) := section_repr (mx_subseries_module' i modV) (mx_subseries_module i modV). Definition series_repr V i (compV : mx_composition_series V) := subseries_repr i (proj1 compV). Lemma mx_series_lt V : mx_composition_series V -> path ltmx 0 V. Proof. by case=> _ compV; apply/(pathP 0)=> i /compV[]. Qed. Lemma max_size_mx_series (V : seq 'M[F]_n) : path ltmx 0 V -> size V <= \rank (last 0 V). Proof. rewrite -[size V]addn0 -(mxrank0 F n n); elim: V 0 => //= V1 V IHV V0. rewrite ltmxErank -andbA => /and3P[_ ltV01 ltV]. by apply: leq_trans (IHV _ ltV); rewrite addSnnS leq_add2l. Qed. Lemma mx_series_repr_irr V i (compV : mx_composition_series V) : i < size V -> mx_irreducible (series_repr i compV). Proof. case: compV => modV compV /compV maxVi; apply/max_submodP => //. by apply: ltmxW; case: maxVi. Qed. Lemma mx_series_rcons U V : mx_series (rcons U V) <-> [/\ mx_series U, modG V & max_submod (last 0 U) V]. Proof. rewrite /mx_series /mx_subseries all_rcons size_rcons -rcons_cons. split=> [ [/andP[modU modV] maxU] | [[modU maxU] modV maxV]]. split=> //; last first. by have:= maxU _ (leqnn _); rewrite !nth_rcons leqnn ltnn eqxx -last_nth. by split=> // i ltiU; have:= maxU i (ltnW ltiU); rewrite !nth_rcons leqW ltiU. rewrite modV; split=> // i; rewrite !nth_rcons ltnS leq_eqVlt. case: eqP => [-> _ | /= _ ltiU]; first by rewrite ltnn ?eqxx -last_nth. by rewrite ltiU; apply: maxU. Qed. Theorem mx_Schreier U : mx_subseries U -> path ltmx 0 U -> classically (exists V, [/\ mx_series V, last 0 V :=: 1%:M & subseq U V])%MS. Proof. move: U => U0; set U := {1 2}U0; have: subseq U0 U := subseq_refl U. pose n' := n.+1; have: n < size U + n' by rewrite leq_addl. elim: n' U => [|n' IH_U] U ltUn' sU0U modU incU [] // noV. rewrite addn0 ltnNge in ltUn'; case/negP: ltUn'. by rewrite (leq_trans (max_size_mx_series incU)) ?rank_leq_row. apply: (noV); exists U; split => //; first split=> // i lt_iU; last first. apply/eqmxP; apply: contraT => neU1. apply: {IH_U}(IH_U (rcons U 1%:M)) noV. - by rewrite size_rcons addSnnS. - by rewrite (subseq_trans sU0U) ?subseq_rcons. - by rewrite /mx_subseries all_rcons mxmodule1. by rewrite rcons_path ltmxEneq neU1 submx1 !andbT. set U'i := _`_i; set Ui := _`_i; have defU := cat_take_drop i U. have defU'i: U'i = last 0 (take i U). rewrite (last_nth 0) /U'i -{1}defU -cat_cons nth_cat /=. by rewrite size_take lt_iU leqnn. move: incU; rewrite -defU cat_path (drop_nth 0) //= -/Ui -defU'i. set U' := take i U; set U'' := drop _ U; case/and3P=> incU' ltUi incU''. split=> // W [modW ltUW ltWV]; case: notF. apply: {IH_U}(IH_U (U' ++ W :: Ui :: U'')) noV; last 2 first. - by rewrite /mx_subseries -drop_nth // all_cat /= modW -all_cat defU. - by rewrite cat_path /= -defU'i; apply/and4P. - by rewrite -drop_nth // size_cat /= addnS -size_cat defU addSnnS. by rewrite (subseq_trans sU0U) // -defU cat_subseq // -drop_nth ?subseq_cons. Qed. Lemma mx_second_rsim U V (modU : modG U) (modV : modG V) : let modI := capmx_module modU modV in let modA := addsmx_module modU modV in mx_rsim (section_repr modI modU) (section_repr modV modA). Proof. move=> modI modA; set nI := {1}(\rank _). have sIU := capmxSl U V; have sVA := addsmxSr U V. pose valI := val_factmod (val_submod (1%:M : 'M_nI)). have UvalI: (valI <= U)%MS. rewrite -(addsmx_idPr sIU) (submx_trans _ (proj_factmodS _ _)) //. by rewrite submxMr // val_submod1 genmxE. exists (valI *m in_factmod _ 1%:M *m in_submod _ 1%:M) => [||x Gx]. - apply: (@addIn (\rank (U :&: V) + \rank V)%N); rewrite genmxE addnA addnCA. rewrite /nI genmxE !{1}mxrank_in_factmod 2?(addsmx_idPr _) //. by rewrite -mxrank_sum_cap addnC. - rewrite -kermx_eq0; apply/rowV0P=> u; rewrite (sameP sub_kermxP eqP). rewrite mulmxA -in_submodE mulmxA -in_factmodE -(inj_eq val_submod_inj). rewrite linear0 in_submodK ?in_factmod_eq0 => [Vvu|]; last first. by rewrite genmxE addsmxC in_factmod_addsK submxMr // mulmx_sub. apply: val_submod_inj; apply/eqP; rewrite linear0 -[val_submod u]val_factmodK. rewrite val_submodE val_factmodE -mulmxA -val_factmodE -/valI. by rewrite in_factmod_eq0 sub_capmx mulmx_sub. symmetry; rewrite -{1}in_submodE -{1}in_submodJ; last first. by rewrite genmxE addsmxC in_factmod_addsK -in_factmodE submxMr. rewrite -{1}in_factmodE -{1}in_factmodJ // mulmxA in_submodE; congr (_ *m _). apply/eqP; rewrite mulmxA -in_factmodE -subr_eq0 -linearB in_factmod_eq0. apply: submx_trans (capmxSr U V); rewrite -in_factmod_eq0 linearB /=. rewrite subr_eq0 {1}(in_factmodJ modI) // val_factmodK eq_sym. rewrite /valI val_factmodE mulmxA -val_factmodE val_factmodK. by rewrite -[submod_mx _ _]mul1mx -val_submodE val_submodJ. Qed. Lemma section_eqmx_add U1 U2 V1 V2 modU1 modU2 modV1 modV2 : (U1 :=: U2)%MS -> (U1 + V1 :=: U2 + V2)%MS -> mx_rsim (@section_repr U1 V1 modU1 modV1) (@section_repr U2 V2 modU2 modV2). Proof. move=> eqU12 eqV12; set n1 := {1}(\rank _). pose v1 := val_factmod (val_submod (1%:M : 'M_n1)). have sv12: (v1 <= U2 + V2)%MS. rewrite -eqV12 (submx_trans _ (proj_factmodS _ _)) //. by rewrite submxMr // val_submod1 genmxE. exists (v1 *m in_factmod _ 1%:M *m in_submod _ 1%:M) => [||x Gx]. - apply: (@addIn (\rank U1)); rewrite {2}eqU12 /n1 !{1}genmxE. by rewrite !{1}mxrank_in_factmod eqV12. - rewrite -kermx_eq0; apply/rowV0P=> u; rewrite (sameP sub_kermxP eqP) mulmxA. rewrite -in_submodE mulmxA -in_factmodE -(inj_eq val_submod_inj) linear0. rewrite in_submodK ?in_factmod_eq0 -?eqU12 => [U1uv1|]; last first. by rewrite genmxE -(in_factmod_addsK U2 V2) submxMr // mulmx_sub. apply: val_submod_inj; apply/eqP; rewrite linear0 -[val_submod _]val_factmodK. by rewrite in_factmod_eq0 val_factmodE val_submodE -mulmxA -val_factmodE. symmetry; rewrite -{1}in_submodE -{1}in_factmodE -{1}in_submodJ; last first. by rewrite genmxE -(in_factmod_addsK U2 V2) submxMr. rewrite -{1}in_factmodJ // mulmxA in_submodE; congr (_ *m _); apply/eqP. rewrite mulmxA -in_factmodE -subr_eq0 -linearB in_factmod_eq0 -eqU12. rewrite -in_factmod_eq0 linearB /= subr_eq0 {1}(in_factmodJ modU1) //. rewrite val_factmodK /v1 val_factmodE eq_sym mulmxA -val_factmodE val_factmodK. by rewrite -[_ *m _]mul1mx mulmxA -val_submodE val_submodJ. Qed. Lemma section_eqmx U1 U2 V1 V2 modU1 modU2 modV1 modV2 (eqU : (U1 :=: U2)%MS) (eqV : (V1 :=: V2)%MS) : mx_rsim (@section_repr U1 V1 modU1 modV1) (@section_repr U2 V2 modU2 modV2). Proof. by apply: section_eqmx_add => //; apply: adds_eqmx. Qed. Lemma mx_butterfly U V W modU modV modW : ~~ (U == V)%MS -> max_submod U W -> max_submod V W -> let modUV := capmx_module modU modV in max_submod (U :&: V)%MS U /\ mx_rsim (@section_repr V W modV modW) (@section_repr _ U modUV modU). Proof. move=> neUV maxU maxV modUV; have{neUV maxU} defW: (U + V :=: W)%MS. wlog{neUV modUV} ltUV: U V modU modV maxU maxV / ~~ (V <= U)%MS. by case/nandP: neUV => ?; first rewrite addsmxC; apply. apply/eqmxP/idPn=> neUVW; case: maxU => ltUW; case/(_ (U + V)%MS). rewrite addsmx_module // ltmxE ltmxEneq neUVW addsmxSl !addsmx_sub. by have [ltVW _] := maxV; rewrite submx_refl andbT ltUV !ltmxW. have sUV_U := capmxSl U V; have sVW: (V <= W)%MS by rewrite -defW addsmxSr. set goal := mx_rsim _ _; suffices{maxV} simUV: goal. split=> //; apply/(max_submodP modUV modU sUV_U). by apply: mx_rsim_irr simUV _; apply/max_submodP. apply: {goal}mx_rsim_sym. by apply: mx_rsim_trans (mx_second_rsim modU modV) _; apply: section_eqmx. Qed. Lemma mx_JordanHolder_exists U V : mx_composition_series U -> modG V -> max_submod V (last 0 U) -> {W : seq 'M_n | mx_composition_series W & last 0 W = V}. Proof. elim/last_ind: U V => [|U Um IHU] V compU modV; first by case; rewrite ltmx0. rewrite last_rcons => maxV; case/mx_series_rcons: compU => compU modUm maxUm. case eqUV: (last 0 U == V)%MS. case/lastP: U eqUV compU {maxUm IHU} => [|U' Um']. by rewrite andbC; move/eqmx0P->; exists [::]. rewrite last_rcons; move/eqmxP=> eqU'V; case/mx_series_rcons=> compU _ maxUm'. exists (rcons U' V); last by rewrite last_rcons. by apply/mx_series_rcons; split => //; apply: max_submod_eqmx maxUm'. set Um' := last 0 U in maxUm eqUV; have [modU _] := compU. have modUm': modG Um' by rewrite /Um' (last_nth 0) mx_subseries_module'. have [|||W compW lastW] := IHU (V :&: Um')%MS; rewrite ?capmx_module //. by case: (mx_butterfly modUm' modV modUm); rewrite ?eqUV // {1}capmxC. exists (rcons W V); last by rewrite last_rcons. apply/mx_series_rcons; split; rewrite // lastW. by case: (mx_butterfly modV modUm' modUm); rewrite // andbC eqUV. Qed. Let rsim_rcons U V compU compUV i : i < size U -> mx_rsim (@series_repr U i compU) (@series_repr (rcons U V) i compUV). Proof. by move=> ltiU; apply: section_eqmx; rewrite -?rcons_cons nth_rcons ?leqW ?ltiU. Qed. Let last_mod U (compU : mx_series U) : modG (last 0 U). Proof. by case: compU => modU _; rewrite (last_nth 0) (mx_subseries_module' _ modU). Qed. Let rsim_last U V modUm modV compUV : mx_rsim (@section_repr (last 0 U) V modUm modV) (@series_repr (rcons U V) (size U) compUV). Proof. apply: section_eqmx; last by rewrite nth_rcons ltnn eqxx. by rewrite -rcons_cons nth_rcons leqnn -last_nth. Qed. Local Notation rsimT := mx_rsim_trans. Local Notation rsimC := mx_rsim_sym. Lemma mx_JordanHolder U V compU compV : let m := size U in (last 0 U :=: last 0 V)%MS -> m = size V /\ (exists p : 'S_m, forall i : 'I_m, mx_rsim (@series_repr U i compU) (@series_repr V (p i) compV)). Proof. move Dr: {-}(size U) => r; move/eqP in Dr. elim: r U V Dr compU compV => /= [|r IHr] U V. move/nilP->; case/lastP: V => [|V Vm] /= ? compVm; rewrite ?last_rcons => Vm0. by split=> //; exists 1%g; case. by case/mx_series_rcons: (compVm) => _ _ []; rewrite -(lt_eqmx Vm0) ltmx0. case/lastP: U => // [U Um]; rewrite size_rcons eqSS => szUr compUm. case/mx_series_rcons: (compUm); set Um' := last 0 U => compU modUm maxUm. case/lastP: V => [|V Vm] compVm; rewrite ?last_rcons ?size_rcons /= => eqUVm. by case/mx_series_rcons: (compUm) => _ _ []; rewrite (lt_eqmx eqUVm) ltmx0. case/mx_series_rcons: (compVm); set Vm' := last 0 V => compV modVm maxVm. have [modUm' modVm']: modG Um' * modG Vm' := (last_mod compU, last_mod compV). pose i_m := @ord_max (size U). have [eqUVm' | neqUVm'] := altP (@eqmxP _ _ _ _ Um' Vm'). have [szV [p sim_p]] := IHr U V szUr compU compV eqUVm'. split; first by rewrite szV. exists (lift_perm i_m i_m p) => i; case: (unliftP i_m i) => [j|] ->{i}. apply: rsimT (rsimC _) (rsimT (sim_p j) _). by rewrite lift_max; apply: rsim_rcons. by rewrite lift_perm_lift lift_max; apply: rsim_rcons; rewrite -szV. have simUVm := section_eqmx modUm' modVm' modUm modVm eqUVm' eqUVm. apply: rsimT (rsimC _) (rsimT simUVm _); first exact: rsim_last. by rewrite lift_perm_id /= szV; apply: rsim_last. have maxVUm: max_submod Vm' Um by apply: max_submod_eqmx (eqmx_sym _) maxVm. have:= mx_butterfly modUm' modVm' modUm neqUVm' maxUm maxVUm. move: (capmx_module _ _); set Wm := (Um' :&: Vm')%MS => modWm [maxWUm simWVm]. have:= mx_butterfly modVm' modUm' modUm _ maxVUm maxUm. move: (capmx_module _ _); rewrite andbC capmxC -/Wm => modWmV [// | maxWVm]. rewrite {modWmV}(bool_irrelevance modWmV modWm) => simWUm. have [W compW lastW] := mx_JordanHolder_exists compU modWm maxWUm. have compWU: mx_series (rcons W Um') by apply/mx_series_rcons; rewrite lastW. have compWV: mx_series (rcons W Vm') by apply/mx_series_rcons; rewrite lastW. have [|szW [pU pUW]] := IHr U _ szUr compU compWU; first by rewrite last_rcons. rewrite size_rcons in szW; have ltWU: size W < size U by rewrite -szW. have{IHr} := IHr _ V _ compWV compV; rewrite last_rcons size_rcons -szW. case=> {r szUr}// szV [pV pWV]; split; first by rewrite szV. pose j_m := Ordinal ltWU; pose i_m' := lift i_m j_m. exists (lift_perm i_m i_m pU * tperm i_m i_m' * lift_perm i_m i_m pV)%g => i. rewrite !permM; case: (unliftP i_m i) => [j {simWUm}|] ->{i}; last first. rewrite lift_perm_id tpermL lift_perm_lift lift_max {simWVm}. apply: rsimT (rsimT (pWV j_m) _); last by apply: rsim_rcons; rewrite -szV. apply: rsimT (rsimC _) {simWUm}(rsimT simWUm _); first exact: rsim_last. by rewrite -lastW in modWm *; apply: rsim_last. apply: rsimT (rsimC _) {pUW}(rsimT (pUW j) _). by rewrite lift_max; apply: rsim_rcons. rewrite lift_perm_lift; case: (unliftP j_m (pU j)) => [k|] ->{j pU}. rewrite tpermD ?(inj_eq lift_inj) ?neq_lift //. rewrite lift_perm_lift !lift_max; set j := lift j_m k. have ltjW: j < size W by have:= ltn_ord k; rewrite -(lift_max k) /= {1 3}szW. apply: rsimT (rsimT (pWV j) _); last by apply: rsim_rcons; rewrite -szV. by apply: rsimT (rsimC _) (rsim_rcons compW _ _); first apply: rsim_rcons. apply: rsimT {simWVm}(rsimC (rsimT simWVm _)) _. by rewrite -lastW in modWm *; apply: rsim_last. rewrite tpermR lift_perm_id /= szV. by apply: rsimT (rsim_last modVm' modVm _); apply: section_eqmx. Qed. Lemma mx_JordanHolder_max U (m := size U) V compU modV : (last 0 U :=: 1%:M)%MS -> mx_irreducible (@factmod_repr _ G n rG V modV) -> exists i : 'I_m, mx_rsim (factmod_repr modV) (@series_repr U i compU). Proof. rewrite {}/m; set Um := last 0 U => Um1 irrV. have modUm: modG Um := last_mod compU; have simV := rsimC (mx_factmod_sub modV). have maxV: max_submod V Um. move/max_submodP: (mx_rsim_irr simV irrV) => /(_ (submx1 _)). by apply: max_submod_eqmx; last apply: eqmx_sym. have [W compW lastW] := mx_JordanHolder_exists compU modV maxV. have compWU: mx_series (rcons W Um) by apply/mx_series_rcons; rewrite lastW. have:= mx_JordanHolder compU compWU; rewrite last_rcons size_rcons. case=> // szW [p pUW]; have ltWU: size W < size U by rewrite szW. pose i := Ordinal ltWU; exists ((p^-1)%g i). apply: rsimT simV (rsimT _ (rsimC (pUW _))); rewrite permKV. apply: rsimT (rsimC _) (rsim_last (last_mod compW) modUm _). by apply: section_eqmx; rewrite ?lastW. Qed. End JordanHolder. Bind Scope irrType_scope with socle_sort. Section Regular. Variables (gT : finGroupType) (G : {group gT}). Local Notation nG := #|pred_of_set (gval G)|. Local Notation aG := (regular_repr F G). Local Notation R_G := (group_ring F G). Lemma gring_free : row_free R_G. Proof. apply/row_freeP; exists (lin1_mx (row (gring_index G 1) \o vec_mx)). apply/row_matrixP=> i; rewrite row_mul rowK mul_rV_lin1 /= mxvecK rowK row1. by rewrite gring_indexK // mul1g gring_valK. Qed. Lemma gring_op_id A : (A \in R_G)%MS -> gring_op aG A = A. Proof. case/envelop_mxP=> a ->{A}; rewrite linear_sum. by apply: eq_bigr => x Gx; rewrite linearZ /= gring_opG. Qed. Lemma gring_rowK A : (A \in R_G)%MS -> gring_mx aG (gring_row A) = A. Proof. exact: gring_op_id. Qed. Lemma mem_gring_mx m a (M : 'M_(m, nG)) : (gring_mx aG a \in M *m R_G)%MS = (a <= M)%MS. Proof. by rewrite vec_mxK submxMfree ?gring_free. Qed. Lemma mem_sub_gring m A (M : 'M_(m, nG)) : (A \in M *m R_G)%MS = (A \in R_G)%MS && (gring_row A <= M)%MS. Proof. rewrite -(andb_idl (memmx_subP (submxMl _ _) A)); apply: andb_id2l => R_A. by rewrite -mem_gring_mx gring_rowK. Qed. Section GringMx. Variables (n : nat) (rG : mx_representation F G n). Lemma gring_mxP a : (gring_mx rG a \in enveloping_algebra_mx rG)%MS. Proof. by rewrite vec_mxK submxMl. Qed. Lemma gring_opM A B : (B \in R_G)%MS -> gring_op rG (A *m B) = gring_op rG A *m gring_op rG B. Proof. by move=> R_B; rewrite -gring_opJ gring_rowK. Qed. Hypothesis irrG : mx_irreducible rG. Lemma rsim_regular_factmod : {U : 'M_nG & {modU : mxmodule aG U & mx_rsim rG (factmod_repr modU)}}. Proof. pose v : 'rV[F]_n := nz_row 1%:M. pose fU := lin1_mx (mulmx v \o gring_mx rG); pose U := kermx fU. have modU: mxmodule aG U. apply/mxmoduleP => x Gx; apply/sub_kermxP/row_matrixP=> i. rewrite 2!row_mul row0; move: (row i U) (sub_kermxP (row_sub i U)) => u. by rewrite !mul_rV_lin1 /= gring_mxJ // mulmxA => ->; rewrite mul0mx. have def_n: \rank (cokermx U) = n. apply/eqP; rewrite mxrank_coker mxrank_ker subKn ?rank_leq_row // -genmxE. rewrite -[_ == _]sub1mx; have [_ _ ->] := irrG; rewrite ?submx1 //. rewrite (eqmx_module _ (genmxE _)); apply/mxmoduleP=> x Gx. apply/row_subP=> i; apply: eq_row_sub (gring_index G (enum_val i * x)) _. rewrite !rowE mulmxA !mul_rV_lin1 /= -mulmxA -gring_mxJ //. by rewrite -rowE rowK. rewrite (eqmx_eq0 (genmxE _)); apply/rowV0Pn. exists v; last exact: (nz_row_mxsimple irrG). apply/submxP; exists (gring_row (aG 1%g)); rewrite mul_rV_lin1 /=. by rewrite -gring_opE gring_opG // repr_mx1 mulmx1. exists U; exists modU; apply: mx_rsim_sym. exists (val_factmod 1%:M *m fU) => // [|x Gx]. rewrite /row_free eqn_leq rank_leq_row /= -subn_eq0 -mxrank_ker mxrank_eq0. apply/rowV0P=> u /sub_kermxP; rewrite mulmxA => /sub_kermxP. by rewrite -/U -in_factmod_eq0 mulmxA mulmx1 val_factmodK => /eqP. rewrite mulmxA -val_factmodE (canRL (addKr _) (add_sub_fact_mod U _)). rewrite mulmxDl mulNmx (sub_kermxP (val_submodP _)) oppr0 add0r. apply/row_matrixP=> i; move: (val_factmod _) => zz. by rewrite !row_mul !mul_rV_lin1 /= gring_mxJ // mulmxA. Qed. Lemma rsim_regular_series U (compU : mx_composition_series aG U) : (last 0 U :=: 1%:M)%MS -> exists i : 'I_(size U), mx_rsim rG (series_repr i compU). Proof. move=> lastU; have [V [modV simGV]] := rsim_regular_factmod. have irrV := mx_rsim_irr simGV irrG. have [i simVU] := mx_JordanHolder_max compU lastU irrV. by exists i; apply: mx_rsim_trans simGV simVU. Qed. Hypothesis F'G : [pchar F]^'.-group G. Lemma rsim_regular_submod_pchar : {U : 'M_nG & {modU : mxmodule aG U & mx_rsim rG (submod_repr modU)}}. Proof. have [V [modV eqG'V]] := rsim_regular_factmod. have [U modU defVU dxVU] := mx_Maschke_pchar F'G modV (submx1 V). exists U; exists modU; apply: mx_rsim_trans eqG'V _. by apply: mx_rsim_factmod; rewrite ?mxdirectE /= addsmxC // addnC. Qed. End GringMx. Definition gset_mx (A : {set gT}) := \sum_(x in A) aG x. Local Notation tG := #|pred_of_set (classes (gval G))|. Definition classg_base := \matrix_(k < tG) mxvec (gset_mx (enum_val k)). Let groupCl : {in G, forall x, {subset x ^: G <= G}}. Proof. by move=> x Gx; apply: subsetP; apply: class_subG. Qed. Lemma classg_base_free : row_free classg_base. Proof. rewrite -kermx_eq0; apply/rowV0P=> v /sub_kermxP; rewrite mulmx_sum_row => v0. apply/rowP=> k /[1!mxE]. have [x Gx def_k] := imsetP (enum_valP k). transitivity (@gring_proj F _ G x (vec_mx 0) 0 0); last first. by rewrite !linear0 !mxE. rewrite -{}v0 !linear_sum (bigD1 k) //= 2!linearZ /= rowK mxvecK def_k. rewrite linear_sum (bigD1 x) ?class_refl //= gring_projE // eqxx. rewrite !big1 ?addr0 ?mxE ?mulr1 // => [k' | y /andP[xGy ne_yx]]; first 1 last. by rewrite gring_projE ?(groupCl Gx xGy) // eq_sym (negPf ne_yx). rewrite rowK 2!linearZ /= mxvecK -(inj_eq enum_val_inj) def_k eq_sym. have [z Gz ->] := imsetP (enum_valP k'). move/eqP=> not_Gxz; rewrite linear_sum big1 ?scaler0 //= => y zGy. rewrite gring_projE ?(groupCl Gz zGy) //. by case: eqP zGy => // <- /class_eqP. Qed. Lemma classg_base_center : (classg_base :=: 'Z(R_G))%MS. Proof. apply/eqmxP/andP; split. apply/row_subP=> k; rewrite rowK /gset_mx sub_capmx {1}linear_sum. have [x Gx ->{k}] := imsetP (enum_valP k); have sxGG := groupCl Gx. rewrite summx_sub => [|y xGy]; last by rewrite envelop_mx_id ?sxGG. rewrite memmx_cent_envelop; apply/centgmxP=> y Gy. rewrite {2}(reindex_acts 'J _ Gy) ?astabsJ ?class_norm //=. rewrite mulmx_suml mulmx_sumr; apply: eq_bigr => z; move/sxGG=> Gz. by rewrite -!repr_mxM ?groupJ -?conjgC. apply/memmx_subP=> A; rewrite sub_capmx memmx_cent_envelop. case/andP=> /envelop_mxP[a ->{A}] cGa. rewrite (partition_big_imset (class^~ G)) -/(classes G) /=. rewrite linear_sum summx_sub //= => xG GxG; have [x Gx def_xG] := imsetP GxG. apply: submx_trans (scalemx_sub (a x) (submx_refl _)). rewrite (eq_row_sub (enum_rank_in GxG xG)) // linearZ /= rowK enum_rankK_in //. rewrite !linear_sum {xG GxG}def_xG; apply: eq_big => [y | xy] /=. apply/idP/andP=> [| [_ xGy]]; last by rewrite -(eqP xGy) class_refl. by case/imsetP=> z Gz ->; rewrite groupJ // classGidl. case/imsetP=> y Gy ->{xy}; rewrite linearZ; congr (_ *: _). move/(canRL (repr_mxK aG Gy)): (centgmxP cGa y Gy); have Gy' := groupVr Gy. move/(congr1 (gring_proj x)); rewrite -mulmxA mulmx_suml !linear_sum. rewrite (bigD1 x Gx) big1 => [|z /andP[Gz]]; rewrite linearZ /=; last first. by rewrite eq_sym gring_projE // => /negPf->; rewrite scaler0. rewrite gring_projE // eqxx scalemx1 (bigD1 (x ^ y)%g) ?groupJ //=. rewrite big1 => [|z /andP[Gz]]; rewrite -scalemxAl 2!linearZ /=. rewrite !addr0 -!repr_mxM ?groupM // mulgA mulKVg mulgK => /rowP/(_ 0). by rewrite gring_projE // eqxx scalemx1 !mxE. rewrite eq_sym -(can_eq (conjgKV y)) conjgK conjgE invgK. by rewrite -!repr_mxM ?gring_projE ?groupM // => /negPf->; rewrite scaler0. Qed. Lemma regular_module_ideal m (M : 'M_(m, nG)) : mxmodule aG M = right_mx_ideal R_G (M *m R_G). Proof. apply/idP/idP=> modM. apply/mulsmx_subP=> A B; rewrite !mem_sub_gring => /andP[R_A M_A] R_B. by rewrite envelop_mxM // gring_row_mul (mxmodule_envelop modM). apply/mxmoduleP=> x Gx; apply/row_subP=> i; rewrite row_mul -mem_gring_mx. rewrite gring_mxJ // (mulsmx_subP modM) ?envelop_mx_id //. by rewrite mem_gring_mx row_sub. Qed. Definition irrType := socleType aG. Identity Coercion type_of_irrType : irrType >-> socleType. Variable sG : irrType. Definition irr_degree (i : sG) := \rank (socle_base i). Local Notation "'n_ i" := (irr_degree i) : group_ring_scope. Local Open Scope group_ring_scope. Lemma irr_degreeE i : 'n_i = \rank (socle_base i). Proof. by []. Qed. Lemma irr_degree_gt0 i : 'n_i > 0. Proof. by rewrite lt0n mxrank_eq0; case: (socle_simple i). Qed. Definition irr_repr i : mx_representation F G 'n_i := socle_repr i. Lemma irr_reprE i x : irr_repr i x = submod_mx (socle_module i) x. Proof. by []. Qed. Lemma rfix_regular : (rfix_mx aG G :=: gring_row (gset_mx G))%MS. Proof. apply/eqmxP/andP; split; last first. apply/rfix_mxP => x Gx; rewrite -gring_row_mul; congr gring_row. rewrite {2}/gset_mx (reindex_astabs 'R x) ?astabsR //= mulmx_suml. by apply: eq_bigr => y Gy; rewrite repr_mxM. apply/rV_subP=> v /rfix_mxP cGv. have /envelop_mxP[a def_v]: (gring_mx aG v \in R_G)%MS. by rewrite vec_mxK submxMl. suffices ->: v = a 1%g *: gring_row (gset_mx G) by rewrite scalemx_sub. rewrite -linearZ scaler_sumr -[v]gring_mxK def_v; congr (gring_row _). apply: eq_bigr => x Gx; congr (_ *: _). move/rowP/(_ 0): (congr1 (gring_proj x \o gring_mx aG) (cGv x Gx)). rewrite /= gring_mxJ // def_v mulmx_suml !linear_sum (bigD1 1%g) //=. rewrite repr_mx1 -scalemxAl mul1mx linearZ /= gring_projE // eqxx scalemx1. rewrite big1 ?addr0 ?mxE /= => [ | y /andP[Gy nt_y]]; last first. rewrite -scalemxAl linearZ -repr_mxM //= gring_projE ?groupM //. by rewrite eq_sym eq_mulgV1 mulgK (negPf nt_y) scaler0. rewrite (bigD1 x) //= linearZ /= gring_projE // eqxx scalemx1. rewrite big1 ?addr0 ?mxE // => y /andP[Gy ne_yx]. by rewrite linearZ /= gring_projE // eq_sym (negPf ne_yx) scaler0. Qed. Lemma principal_comp_subproof : mxsimple aG (rfix_mx aG G). Proof. apply: linear_mxsimple; first exact: rfix_mx_module. apply/eqP; rewrite rfix_regular eqn_leq rank_leq_row lt0n mxrank_eq0. apply/eqP => /(congr1 (gring_proj 1 \o gring_mx aG)); apply/eqP. rewrite /= -[gring_mx _ _]/(gring_op _ _) !linear0 !linear_sum (bigD1 1%g) //=. rewrite gring_opG ?gring_projE // eqxx big1 ?addr0 ?oner_eq0 // => x. by case/andP=> Gx nt_x; rewrite gring_opG // gring_projE // eq_sym (negPf nt_x). Qed. Fact principal_comp_key : unit. Proof. by []. Qed. Definition principal_comp_def := PackSocle (component_socle sG principal_comp_subproof). Definition principal_comp := locked_with principal_comp_key principal_comp_def. Local Notation "1" := principal_comp : irrType_scope. Lemma irr1_rfix : (1%irr :=: rfix_mx aG G)%MS. Proof. rewrite [1%irr]unlock PackSocleK; apply/eqmxP. rewrite (component_mx_id principal_comp_subproof) andbT. have [I [W isoW ->]] := component_mx_def principal_comp_subproof. apply/sumsmx_subP=> i _; have [f _ hom_f <-]:= isoW i. (* FIX ME : this takes time *) by apply/rfix_mxP=> x Gx; rewrite -(hom_mxP hom_f) // (rfix_mxP G _). Qed. Lemma rank_irr1 : \rank 1%irr = 1. Proof. apply/eqP; rewrite eqn_leq lt0n mxrank_eq0 nz_socle andbT. by rewrite irr1_rfix rfix_regular rank_leq_row. Qed. Lemma degree_irr1 : 'n_1 = 1. Proof. apply/eqP; rewrite eqn_leq irr_degree_gt0 -rank_irr1. by rewrite mxrankS ?component_mx_id //; apply: socle_simple. Qed. Definition Wedderburn_subring (i : sG) := <<i *m R_G>>%MS. Local Notation "''R_' i" := (Wedderburn_subring i) : group_ring_scope. Let sums_R : (\sum_i 'R_i :=: Socle sG *m R_G)%MS. Proof. apply/eqmxP; set R_S := (_ <= _)%MS. have sRS: R_S by apply/sumsmx_subP=> i; rewrite genmxE submxMr ?(sumsmx_sup i). rewrite sRS -(mulmxKpV sRS) mulmxA submxMr //; apply/sumsmx_subP=> i _. rewrite -(submxMfree _ _ gring_free) -(mulmxA _ _ R_G) mulmxKpV //. by rewrite (sumsmx_sup i) ?genmxE. Qed. Lemma Wedderburn_ideal i : mx_ideal R_G 'R_i. Proof. apply/andP; split; last first. rewrite /right_mx_ideal genmxE (muls_eqmx (genmxE _) (eqmx_refl _)). by rewrite -[(_ <= _)%MS]regular_module_ideal component_mx_module. apply/mulsmx_subP=> A B R_A; rewrite !genmxE !mem_sub_gring => /andP[R_B SiB]. rewrite envelop_mxM {R_A}// gring_row_mul -{R_B}(gring_rowK R_B). pose f := mulmx (gring_row A) \o gring_mx aG. rewrite -[_ *m _](mul_rV_lin1 f). suffices: (i *m lin1_mx f <= i)%MS by apply: submx_trans; rewrite submxMr. apply: hom_component_mx; first exact: socle_simple. apply/rV_subP=> v _; apply/hom_mxP=> x Gx. by rewrite !mul_rV_lin1 /f /= gring_mxJ ?mulmxA. Qed. Lemma Wedderburn_direct : mxdirect (\sum_i 'R_i)%MS. Proof. apply/mxdirectP; rewrite /= sums_R mxrankMfree ?gring_free //. rewrite (mxdirectP (Socle_direct sG)); apply: eq_bigr=> i _ /=. by rewrite genmxE mxrankMfree ?gring_free. Qed. Lemma Wedderburn_disjoint i j : i != j -> ('R_i :&: 'R_j)%MS = 0. Proof. move=> ne_ij; apply/eqP; rewrite -submx0 capmxC. by rewrite -(mxdirect_sumsP Wedderburn_direct j) // capmxS // (sumsmx_sup i). Qed. Lemma Wedderburn_annihilate i j : i != j -> ('R_i * 'R_j)%MS = 0. Proof. move=> ne_ij; apply/eqP; rewrite -submx0 -(Wedderburn_disjoint ne_ij). rewrite sub_capmx; apply/andP; split. case/andP: (Wedderburn_ideal i) => _; apply: submx_trans. by rewrite mulsmxS // genmxE submxMl. case/andP: (Wedderburn_ideal j) => idlRj _; apply: submx_trans idlRj. by rewrite mulsmxS // genmxE submxMl. Qed. Lemma Wedderburn_mulmx0 i j A B : i != j -> (A \in 'R_i)%MS -> (B \in 'R_j)%MS -> A *m B = 0. Proof. move=> ne_ij RiA RjB; apply: memmx0. by rewrite -(Wedderburn_annihilate ne_ij) mem_mulsmx. Qed. Hypothesis F'G : [pchar F]^'.-group G. Lemma irr_mx_sum_pchar : (\sum_(i : sG) i = 1%:M)%MS. Proof. by apply: reducible_Socle1; apply: mx_Maschke_pchar. Qed. Lemma Wedderburn_sum_pchar : (\sum_i 'R_i :=: R_G)%MS. Proof. by apply: eqmx_trans sums_R _; rewrite /Socle irr_mx_sum_pchar mul1mx. Qed. Definition Wedderburn_id i := vec_mx (mxvec 1%:M *m proj_mx 'R_i (\sum_(j | j != i) 'R_j)%MS). Local Notation "''e_' i" := (Wedderburn_id i) : group_ring_scope. Lemma Wedderburn_sum_id_pchar : \sum_i 'e_i = 1%:M. Proof. rewrite -linear_sum; apply: canLR mxvecK _. have: (1%:M \in R_G)%MS := envelop_mx1 aG. rewrite -Wedderburn_sum_pchar. case/(sub_dsumsmx Wedderburn_direct) => e Re -> _. apply: eq_bigr => i _; have dxR := mxdirect_sumsP Wedderburn_direct i (erefl _). rewrite (bigD1 i) // mulmxDl proj_mx_id ?Re // proj_mx_0 ?addr0 //=. by rewrite summx_sub // => j ne_ji; rewrite (sumsmx_sup j) ?Re. Qed. Lemma Wedderburn_id_mem i : ('e_i \in 'R_i)%MS. Proof. by rewrite vec_mxK proj_mx_sub. Qed. Lemma Wedderburn_is_id_pchar i : mxring_id 'R_i 'e_i. Proof. have ideRi A: (A \in 'R_i)%MS -> 'e_i *m A = A. move=> RiA; rewrite -{2}[A]mul1mx -Wedderburn_sum_id_pchar mulmx_suml. rewrite (bigD1 i) //= big1 ?addr0 // => j ne_ji. by rewrite (Wedderburn_mulmx0 ne_ji) ?Wedderburn_id_mem. split=> // [||A RiA]; first 2 [exact: Wedderburn_id_mem]. apply: contraNneq (nz_socle i) => e0. apply/rowV0P=> v; rewrite -mem_gring_mx -(genmxE (i *m _)) => /ideRi. by rewrite e0 mul0mx => /(canLR gring_mxK); rewrite linear0. rewrite -{2}[A]mulmx1 -Wedderburn_sum_id_pchar mulmx_sumr (bigD1 i) //=. rewrite big1 ?addr0 // => j; rewrite eq_sym => ne_ij. by rewrite (Wedderburn_mulmx0 ne_ij) ?Wedderburn_id_mem. Qed. Lemma Wedderburn_closed_pchar i : ('R_i * 'R_i = 'R_i)%MS. Proof. rewrite -{3}['R_i]genmx_id -/'R_i -genmx_muls; apply/genmxP. have [idlRi idrRi] := andP (Wedderburn_ideal i). apply/andP; split. by apply: submx_trans idrRi; rewrite mulsmxS // genmxE submxMl. have [_ Ri_e ideRi _] := Wedderburn_is_id_pchar i. by apply/memmx_subP=> A RiA; rewrite -[A]ideRi ?mem_mulsmx. Qed. Lemma Wedderburn_is_ring_pchar i : mxring 'R_i. Proof. rewrite /mxring /left_mx_ideal Wedderburn_closed_pchar submx_refl. by apply/mxring_idP; exists 'e_i; apply: Wedderburn_is_id_pchar. Qed. Lemma Wedderburn_min_ideal_pchar m i (E : 'A_(m, nG)) : E != 0 -> (E <= 'R_i)%MS -> mx_ideal R_G E -> (E :=: 'R_i)%MS. Proof. move=> nzE sE_Ri /andP[idlE idrE]; apply/eqmxP; rewrite sE_Ri. pose M := E *m pinvmx R_G; have defE: E = M *m R_G. by rewrite mulmxKpV // (submx_trans sE_Ri) // genmxE submxMl. have modM: mxmodule aG M by rewrite regular_module_ideal -defE. have simSi := socle_simple i; set Si := socle_base i in simSi. have [I [W isoW defW]]:= component_mx_def simSi. rewrite /'R_i /socle_val /= defW genmxE defE submxMr //. apply/sumsmx_subP=> j _. have simW := mx_iso_simple (isoW j) simSi; have [modW _ minW] := simW. have [{minW}dxWE | nzWE] := eqVneq (W j :&: M)%MS 0; last first. by rewrite (sameP capmx_idPl eqmxP) minW ?capmxSl ?capmx_module. have [_ Rei ideRi _] := Wedderburn_is_id_pchar i. have:= nzE; rewrite -submx0 => /memmx_subP[A E_A]. rewrite -(ideRi _ (memmx_subP sE_Ri _ E_A)). have:= E_A; rewrite defE mem_sub_gring => /andP[R_A M_A]. have:= Rei; rewrite genmxE mem_sub_gring => /andP[Re]. rewrite -{2}(gring_rowK Re) /socle_val defW => /sub_sumsmxP[e ->]. rewrite !(linear_sum, mulmx_suml) summx_sub //= => k _. rewrite -(gring_rowK R_A) -gring_mxA -mulmxA gring_rowK //. rewrite ((W k *m _ =P 0) _) ?linear0 ?sub0mx //. have [f _ homWf defWk] := mx_iso_trans (mx_iso_sym (isoW j)) (isoW k). rewrite -submx0 -{k defWk}(eqmxMr _ defWk) -(hom_envelop_mxC homWf) //. rewrite -(mul0mx _ f) submxMr {f homWf}// -dxWE sub_capmx. rewrite (mxmodule_envelop modW) //=; apply/row_subP=> k. rewrite row_mul -mem_gring_mx -(gring_rowK R_A) gring_mxA gring_rowK //. by rewrite -defE (memmx_subP idlE) // mem_mulsmx ?gring_mxP. Qed. Section IrrComponent. (* The component of the socle of the regular module that is associated to an *) (* irreducible representation. *) Variables (n : nat) (rG : mx_representation F G n). Local Notation E_G := (enveloping_algebra_mx rG). Let not_rsim_op0_pchar (iG j : sG) A : mx_rsim rG (socle_repr iG) -> iG != j -> (A \in 'R_j)%MS -> gring_op rG A = 0. Proof. case/mx_rsim_def=> f [f' _ hom_f] ne_iG_j RjA. transitivity (f *m in_submod _ (val_submod 1%:M *m A) *m f'). have{RjA}: (A \in R_G)%MS by rewrite -Wedderburn_sum_pchar (sumsmx_sup j). case/envelop_mxP=> a ->{A}; rewrite !(linear_sum, mulmx_suml). by apply: eq_bigr => x Gx; rewrite 4!linearZ /= -scalemxAl -hom_f ?gring_opG. rewrite (_ : _ *m A = 0) ?(linear0, mul0mx) //. apply/row_matrixP=> i; rewrite row_mul row0 -[row _ _]gring_mxK -gring_row_mul. rewrite (Wedderburn_mulmx0 ne_iG_j) ?linear0 // genmxE mem_gring_mx. by rewrite (row_subP _) // val_submod1 component_mx_id //; apply: socle_simple. Qed. Definition irr_comp := odflt 1%irr [pick i | gring_op rG 'e_i != 0]. Local Notation iG := irr_comp. Hypothesis irrG : mx_irreducible rG. Lemma rsim_irr_comp_pchar : mx_rsim rG (irr_repr iG). Proof. have [M [modM rsimM]] := rsim_regular_submod_pchar irrG F'G. have simM: mxsimple aG M. case/mx_irrP: irrG => n_gt0 minG. have [f def_n injf homf] := mx_rsim_sym rsimM. apply/(submod_mx_irr modM)/mx_irrP. split=> [|U modU nzU]; first by rewrite def_n. rewrite /row_full -(mxrankMfree _ injf) -genmxE {4}def_n. apply: minG; last by rewrite -mxrank_eq0 genmxE mxrankMfree // mxrank_eq0. rewrite (eqmx_module _ (genmxE _)); apply/mxmoduleP=> x Gx. by rewrite -mulmxA -homf // mulmxA submxMr // (mxmoduleP modU). pose i := PackSocle (component_socle sG simM). have{modM} rsimM: mx_rsim rG (socle_repr i). apply: mx_rsim_trans rsimM (mx_rsim_sym _); apply/mx_rsim_iso. apply: (component_mx_iso (socle_simple _)) => //. by rewrite [component_mx _ _]PackSocleK component_mx_id. have [<- // | ne_i_iG] := eqVneq i iG. suffices {i M simM ne_i_iG rsimM}: gring_op rG 'e_iG != 0. by rewrite (not_rsim_op0_pchar rsimM ne_i_iG) ?Wedderburn_id_mem ?eqxx. rewrite /iG; case: pickP => //= G0. suffices: rG 1%g == 0. by case/idPn; rewrite -mxrank_eq0 repr_mx1 mxrank1 -lt0n; case/mx_irrP: irrG. rewrite -gring_opG // repr_mx1 -Wedderburn_sum_id_pchar linear_sum big1 //. by move=> j _; move/eqP: (G0 j). Qed. Lemma irr_comp'_op0_pchar j A : j != iG -> (A \in 'R_j)%MS -> gring_op rG A = 0. Proof. by rewrite eq_sym; apply: not_rsim_op0_pchar rsim_irr_comp_pchar. Qed. Lemma irr_comp_envelop_pchar : ('R_iG *m lin_mx (gring_op rG) :=: E_G)%MS. Proof. apply/eqmxP/andP; split; apply/row_subP=> i. by rewrite row_mul mul_rV_lin gring_mxP. rewrite rowK /= -gring_opG ?enum_valP // -mul_vec_lin -gring_opG ?enum_valP //. rewrite vec_mxK /= -mulmxA mulmx_sub {i}//= -(eqmxMr _ Wedderburn_sum_pchar). rewrite (bigD1 iG) //= addsmxMr addsmxC [_ *m _](sub_kermxP _) ?adds0mx //=. apply/sumsmx_subP => j ne_j_iG; apply/memmx_subP=> A RjA; apply/sub_kermxP. by rewrite mul_vec_lin /= (irr_comp'_op0_pchar ne_j_iG RjA) linear0. Qed. Lemma ker_irr_comp_op_pchar : ('R_iG :&: kermx (lin_mx (gring_op rG)))%MS = 0. Proof. apply/eqP; rewrite -submx0; apply/memmx_subP=> A. rewrite sub_capmx /= submx0 mxvec_eq0 => /andP[R_A]. rewrite (sameP sub_kermxP eqP) mul_vec_lin mxvec_eq0 /= => opA0. have [_ Re ideR _] := Wedderburn_is_id_pchar iG; rewrite -[A]ideR {ideR}//. move: Re; rewrite genmxE mem_sub_gring /socle_val => /andP[Re]. rewrite -{2}(gring_rowK Re) -submx0. pose simMi := socle_simple iG; have [J [M isoM ->]] := component_mx_def simMi. case/sub_sumsmxP=> e ->; rewrite linear_sum mulmx_suml summx_sub // => j _. rewrite -(in_submodK (submxMl _ (M j))); move: (in_submod _ _) => v. have modMj: mxmodule aG (M j) by apply: mx_iso_module (isoM j) _; case: simMi. have rsimMj: mx_rsim rG (submod_repr modMj). by apply: mx_rsim_trans rsim_irr_comp_pchar _; apply/mx_rsim_iso. have [f [f' _ hom_f]] := mx_rsim_def (mx_rsim_sym rsimMj); rewrite submx0. have <-: (gring_mx aG (val_submod (v *m (f *m gring_op rG A *m f')))) = 0. by rewrite (eqP opA0) !(mul0mx, linear0). have: (A \in R_G)%MS by rewrite -Wedderburn_sum_pchar (sumsmx_sup iG). case/envelop_mxP=> a ->; rewrite !(linear_sum, mulmx_suml) /=; apply/eqP. apply: eq_bigr=> x Gx; rewrite 3!linearZ -scalemxAl 3!linearZ /=. by rewrite gring_opG // -hom_f // val_submodJ // gring_mxJ. Qed. Lemma regular_op_inj_pchar : {in [pred A | (A \in 'R_iG)%MS] &, injective (gring_op rG)}. Proof. move=> A B RnA RnB /= eqAB; apply/eqP; rewrite -subr_eq0 -mxvec_eq0 -submx0. rewrite -ker_irr_comp_op_pchar sub_capmx (sameP sub_kermxP eqP) mul_vec_lin. by rewrite 2!raddfB /= eqAB subrr linear0 addmx_sub ?eqmx_opp /=. Qed. Lemma rank_irr_comp_pchar : \rank 'R_iG = \rank E_G. Proof. rewrite -irr_comp_envelop_pchar; apply/esym/mxrank_injP. by rewrite ker_irr_comp_op_pchar. Qed. End IrrComponent. Lemma irr_comp_rsim_pchar n1 n2 rG1 rG2 : @mx_rsim _ G n1 rG1 n2 rG2 -> irr_comp rG1 = irr_comp rG2. Proof. case=> f eq_n12; rewrite -eq_n12 in rG2 f * => inj_f hom_f. rewrite /irr_comp; apply/f_equal/eq_pick => i; rewrite -!mxrank_eq0. (* [congr (odflt 1%irr _)] works but is very slow *) rewrite -(mxrankMfree _ inj_f); symmetry; rewrite -(eqmxMfull _ inj_f). have /envelop_mxP[e ->{i}]: ('e_i \in R_G)%MS. by rewrite -Wedderburn_sum_pchar (sumsmx_sup i) ?Wedderburn_id_mem. congr (\rank _ != _); rewrite !(mulmx_suml, linear_sum); apply: eq_bigr => x Gx. by rewrite 3!linearZ -scalemxAl /= !gring_opG ?hom_f. Qed. Lemma irr_reprK_pchar i : irr_comp (irr_repr i) = i. Proof. apply/eqP; apply/component_mx_isoP; try exact: socle_simple. by move/mx_rsim_iso: (rsim_irr_comp_pchar (socle_irr i)); apply: mx_iso_sym. Qed. Lemma irr_repr'_op0_pchar i j A : j != i -> (A \in 'R_j)%MS -> gring_op (irr_repr i) A = 0. Proof. move=> neq_ij /(irr_comp'_op0_pchar _). by move=> ->; [|apply: socle_irr|rewrite irr_reprK_pchar]. Qed. Lemma op_Wedderburn_id_pchar i : gring_op (irr_repr i) 'e_i = 1%:M. Proof. rewrite -(gring_op1 (irr_repr i)) -Wedderburn_sum_id_pchar. rewrite linear_sum (bigD1 i) //= addrC big1 ?add0r // => j neq_ji. exact: irr_repr'_op0_pchar (Wedderburn_id_mem j). Qed. Lemma irr_comp_id_pchar (M : 'M_nG) (modM : mxmodule aG M) (iM : sG) : mxsimple aG M -> (M <= iM)%MS -> irr_comp (submod_repr modM) = iM. Proof. move=> simM sMiM; rewrite -[iM]irr_reprK_pchar. apply/esym/irr_comp_rsim_pchar/mx_rsim_iso/component_mx_iso => //. exact: socle_simple. Qed. Lemma irr1_repr x : x \in G -> irr_repr 1 x = 1%:M. Proof. move=> Gx; suffices: x \in rker (irr_repr 1) by case/rkerP. apply: subsetP x Gx; rewrite rker_submod rfix_mx_rstabC // -irr1_rfix. by apply: component_mx_id; apply: socle_simple. Qed. Hypothesis splitG : group_splitting_field G. Lemma rank_Wedderburn_subring_pchar i : \rank 'R_i = ('n_i ^ 2)%N. Proof. apply/eqP; rewrite -{1}[i]irr_reprK_pchar; have irrSi := socle_irr i. by case/andP: (splitG irrSi) => _; rewrite rank_irr_comp_pchar. Qed. Lemma sum_irr_degree_pchar : (\sum_i 'n_i ^ 2 = nG)%N. Proof. apply: etrans (eqnP gring_free). rewrite -Wedderburn_sum_pchar (mxdirectP Wedderburn_direct) /=. by apply: eq_bigr => i _; rewrite rank_Wedderburn_subring_pchar. Qed. Lemma irr_mx_mult_pchar i : socle_mult i = 'n_i. Proof. rewrite /socle_mult -(mxrankMfree _ gring_free) -genmxE. by rewrite rank_Wedderburn_subring_pchar mulKn ?irr_degree_gt0. Qed. Lemma mxtrace_regular_pchar : {in G, forall x, \tr (aG x) = \sum_i \tr (socle_repr i x) *+ 'n_i}. Proof. move=> x Gx; have soc1: (Socle sG :=: 1%:M)%MS by rewrite -irr_mx_sum_pchar. rewrite -(mxtrace_submod1 (Socle_module sG) soc1) // mxtrace_Socle //. by apply: eq_bigr => i _; rewrite irr_mx_mult_pchar. Qed. Definition linear_irr := [set i | 'n_i == 1]. Lemma irr_degree_abelian : abelian G -> forall i, 'n_i = 1. Proof. by move=> cGG i; apply: mxsimple_abelian_linear (socle_simple i). Qed. Lemma linear_irr_comp_pchar i : 'n_i = 1 -> (i :=: socle_base i)%MS. Proof. move=> ni1; apply/eqmxP; rewrite andbC -mxrank_leqif_eq -/'n_i. rewrite -(mxrankMfree _ gring_free) -genmxE. by rewrite rank_Wedderburn_subring_pchar ni1. exact: component_mx_id (socle_simple i). Qed. Lemma Wedderburn_subring_center_pchar i : ('Z('R_i) :=: mxvec 'e_i)%MS. Proof. have [nz_e Re ideR idRe] := Wedderburn_is_id_pchar i. have Ze: (mxvec 'e_i <= 'Z('R_i))%MS. rewrite sub_capmx [(_ <= _)%MS]Re. by apply/cent_mxP=> A R_A; rewrite ideR // idRe. pose irrG := socle_irr i; set rG := socle_repr i in irrG. pose E_G := enveloping_algebra_mx rG; have absG := splitG irrG. apply/eqmxP; rewrite andbC -(geq_leqif (mxrank_leqif_eq Ze)). have ->: \rank (mxvec 'e_i) = (0 + 1)%N. by apply/eqP; rewrite eqn_leq rank_leq_row lt0n mxrank_eq0 mxvec_eq0. rewrite -(mxrank_mul_ker _ (lin_mx (gring_op rG))) addnC leq_add //. rewrite leqn0 mxrank_eq0 -submx0 -(ker_irr_comp_op_pchar irrG) capmxS //. by rewrite irr_reprK_pchar capmxSl. apply: leq_trans (mxrankS _) (rank_leq_row (mxvec 1%:M)). apply/memmx_subP=> Ar; case/submxP=> a ->{Ar}. rewrite mulmxA mul_rV_lin /=; set A := vec_mx _. rewrite memmx1 (mx_abs_irr_cent_scalar absG) // -memmx_cent_envelop. apply/cent_mxP=> Br; rewrite -(irr_comp_envelop_pchar irrG) irr_reprK_pchar. case/submxP=> b /(canRL mxvecK) ->{Br}; rewrite mulmxA mx_rV_lin /=. set B := vec_mx _; have RiB: (B \in 'R_i)%MS by rewrite vec_mxK submxMl. have sRiR: ('R_i <= R_G)%MS by rewrite -Wedderburn_sum_pchar (sumsmx_sup i). have: (A \in 'Z('R_i))%MS by rewrite vec_mxK submxMl. rewrite sub_capmx => /andP[RiA /cent_mxP cRiA]. by rewrite -!gring_opM ?(memmx_subP sRiR) 1?cRiA. Qed. Lemma Wedderburn_center_pchar : ('Z(R_G) :=: \matrix_(i < #|sG|) mxvec 'e_(enum_val i))%MS. Proof. have:= mxdirect_sums_center Wedderburn_sum_pchar Wedderburn_direct Wedderburn_ideal. move/eqmx_trans; apply; apply/eqmxP/andP; split. apply/sumsmx_subP=> i _; rewrite Wedderburn_subring_center_pchar. by apply: (eq_row_sub (enum_rank i)); rewrite rowK enum_rankK. apply/row_subP=> i; rewrite rowK -Wedderburn_subring_center_pchar. by rewrite (sumsmx_sup (enum_val i)). Qed. Lemma card_irr_pchar : #|sG| = tG. Proof. rewrite -(eqnP classg_base_free) classg_base_center. have:= mxdirect_sums_center Wedderburn_sum_pchar Wedderburn_direct Wedderburn_ideal. move->; rewrite (mxdirectP _) /=; last first. apply/mxdirect_sumsP=> i _; apply/eqP; rewrite -submx0. rewrite -{2}(mxdirect_sumsP Wedderburn_direct i) // capmxS ?capmxSl //=. by apply/sumsmx_subP=> j neji; rewrite (sumsmx_sup j) ?capmxSl. rewrite -sum1_card; apply: eq_bigr => i _; apply/eqP. rewrite Wedderburn_subring_center_pchar eqn_leq rank_leq_row lt0n mxrank_eq0. by rewrite andbT mxvec_eq0; case: (Wedderburn_is_id_pchar i). Qed. Section CenterMode. Variable i : sG. Let i0 := Ordinal (irr_degree_gt0 i). Definition irr_mode x := irr_repr i x i0 i0. Lemma irr_mode1 : irr_mode 1 = 1. Proof. by rewrite /irr_mode repr_mx1 mxE eqxx. Qed. Lemma irr_center_scalar : {in 'Z(G), forall x, irr_repr i x = (irr_mode x)%:M}. Proof. rewrite /irr_mode => x /setIP[Gx cGx]. suffices [a ->]: exists a, irr_repr i x = a%:M by rewrite mxE eqxx. apply/is_scalar_mxP; apply: (mx_abs_irr_cent_scalar (splitG (socle_irr i))). by apply/centgmxP=> y Gy; rewrite -!{1}repr_mxM 1?(centP cGx). Qed. Lemma irr_modeM : {in 'Z(G) &, {morph irr_mode : x y / (x * y)%g >-> x * y}}. Proof. move=> x y Zx Zy; rewrite {1}/irr_mode repr_mxM ?(subsetP (center_sub G)) //. by rewrite !irr_center_scalar // -scalar_mxM mxE eqxx. Qed. Lemma irr_modeX n : {in 'Z(G), {morph irr_mode : x / (x ^+ n)%g >-> x ^+ n}}. Proof. elim: n => [|n IHn] x Zx; first exact: irr_mode1. by rewrite expgS irr_modeM ?groupX // exprS IHn. Qed. Lemma irr_mode_unit : {in 'Z(G), forall x, irr_mode x \is a GRing.unit}. Proof. move=> x Zx /=; have:= unitr1 F. by rewrite -irr_mode1 -(mulVg x) irr_modeM ?groupV // unitrM; case/andP=> _. Qed. Lemma irr_mode_neq0 : {in 'Z(G), forall x, irr_mode x != 0}. Proof. by move=> x /irr_mode_unit; rewrite unitfE. Qed. Lemma irr_modeV : {in 'Z(G), {morph irr_mode : x / (x^-1)%g >-> x^-1}}. Proof. move=> x Zx /=; rewrite -[_^-1]mul1r; apply: canRL (mulrK (irr_mode_unit Zx)) _. by rewrite -irr_modeM ?groupV // mulVg irr_mode1. Qed. End CenterMode. Lemma irr1_mode x : x \in G -> irr_mode 1 x = 1. Proof. by move=> Gx; rewrite /irr_mode irr1_repr ?mxE. Qed. End Regular. Local Notation "[ 1 sG ]" := (principal_comp sG) : irrType_scope. Section LinearIrr. Variables (gT : finGroupType) (G : {group gT}). Lemma card_linear_irr (sG : irrType G) : [pchar F]^'.-group G -> group_splitting_field G -> #|linear_irr sG| = #|G : G^`(1)|%g. Proof. move=> F'G splitG; apply/eqP. wlog sGq: / irrType (G / G^`(1))%G by apply: socle_exists. have [_ nG'G] := andP (der_normal 1 G); apply/eqP; rewrite -card_quotient //. have cGqGq: abelian (G / G^`(1))%g by apply: sub_der1_abelian. have F'Gq: [pchar F]^'.-group (G / G^`(1))%g by apply: morphim_pgroup. have splitGq: group_splitting_field (G / G^`(1))%G. exact: quotient_splitting_field. rewrite -(sum_irr_degree_pchar sGq) // -sum1_card. pose rG (j : sGq) := morphim_repr (socle_repr j) nG'G. have irrG j: mx_irreducible (rG j) by apply/morphim_mx_irr; apply: socle_irr. rewrite (reindex (fun j => irr_comp sG (rG j))) /=. apply: eq_big => [j | j _]; last by rewrite irr_degree_abelian. have [_ lin_j _ _] := rsim_irr_comp_pchar sG F'G (irrG j). by rewrite inE -lin_j -irr_degreeE irr_degree_abelian. pose sGlin := {i | i \in linear_irr sG}. have sG'k (i : sGlin) : G^`(1)%g \subset rker (irr_repr (val i)). by case: i => i /= /[!inE] lin; rewrite rker_linear //=; apply/eqP. pose h' u := irr_comp sGq (quo_repr (sG'k u) nG'G). have irrGq u: mx_irreducible (quo_repr (sG'k u) nG'G). by apply/quo_mx_irr; apply: socle_irr. exists (fun i => oapp h' [1 sGq]%irr (insub i)) => [j | i] lin_i. rewrite (insubT [in _] lin_i) /=; apply/esym/eqP/socle_rsimP. apply: mx_rsim_trans (rsim_irr_comp_pchar sGq F'Gq (irrGq _)). have [g lin_g inj_g hom_g] := rsim_irr_comp_pchar sG F'G (irrG j). exists g => [||G'x]; last 1 [case/morphimP=> x _ Gx ->] || by []. by rewrite quo_repr_coset ?hom_g. rewrite (insubT (mem _) lin_i) /=; apply/esym/eqP/socle_rsimP. set u := Sub i lin_i. apply: mx_rsim_trans (rsim_irr_comp_pchar sG F'G (irrG _)). have [g lin_g inj_g hom_g] := rsim_irr_comp_pchar sGq F'Gq (irrGq u). exists g => [||x Gx]; last 1 [have:= hom_g (coset _ x)] || by []. by rewrite quo_repr_coset; first by apply; rewrite mem_quotient. Qed. Lemma primitive_root_splitting_abelian (z : F) : #|G|.-primitive_root z -> abelian G -> group_splitting_field G. Proof. move=> ozG cGG [|n] rG irrG; first by case/mx_irrP: irrG. case: (pickP [pred x in G | ~~ is_scalar_mx (rG x)]) => [x | scalG]. case/andP=> Gx nscal_rGx; have: horner_mx (rG x) ('X^#|G| - 1) == 0. rewrite rmorphB rmorphXn /= horner_mx_C horner_mx_X. rewrite -repr_mxX ?inE // ((_ ^+ _ =P 1)%g _) ?repr_mx1 ?subrr //. by rewrite -order_dvdn order_dvdG. case/idPn; rewrite -mxrank_eq0 -(factor_Xn_sub_1 ozG). elim: #|G| => [|i IHi]; first by rewrite big_nil horner_mx_C mxrank1. rewrite big_nat_recr => [|//]; rewrite rmorphM mxrankMfree {IHi}//=. rewrite row_free_unit rmorphB /= horner_mx_X horner_mx_C. rewrite (mx_Schur irrG) ?subr_eq0 //; last first. by apply: contraNneq nscal_rGx => ->; apply: scalar_mx_is_scalar. rewrite -memmx_cent_envelop raddfB. rewrite addmx_sub ?eqmx_opp ?scalar_mx_cent //= memmx_cent_envelop. by apply/centgmxP=> j Zh_j; rewrite -!repr_mxM // (centsP cGG). pose M := <<delta_mx 0 0 : 'rV[F]_n.+1>>%MS. have linM: \rank M = 1 by rewrite genmxE mxrank_delta. have modM: mxmodule rG M. apply/mxmoduleP=> x Gx; move/idPn: (scalG x); rewrite /= Gx negbK. by case/is_scalar_mxP=> ? ->; rewrite scalar_mxC submxMl. apply: linear_mx_abs_irr; apply/eqP; rewrite eq_sym -linM. by case/mx_irrP: irrG => _; apply; rewrite // -mxrank_eq0 linM. Qed. Lemma cycle_repr_structure_pchar x (sG : irrType G) : G :=: <[x]> -> [pchar F]^'.-group G -> group_splitting_field G -> exists2 w : F, #|G|.-primitive_root w & exists iphi : 'I_#|G| -> sG, [/\ bijective iphi, #|sG| = #|G|, forall i, irr_mode (iphi i) x = w ^+ i & forall i, irr_repr (iphi i) x = (w ^+ i)%:M]. Proof. move=> defG; rewrite {defG}(group_inj defG) -/#[x] in sG * => F'X splitF. have Xx := cycle_id x; have cXX := cycle_abelian x. have card_sG: #|sG| = #[x]. by rewrite card_irr_pchar //; apply/eqP; rewrite -card_classes_abelian. have linX := irr_degree_abelian splitF cXX (_ : sG). pose r (W : sG) := irr_mode W x. have scalX W: irr_repr W x = (r W)%:M. by apply: irr_center_scalar; rewrite ?(center_idP _). have inj_r: injective r. move=> V W eqVW; rewrite -(irr_reprK_pchar F'X V) -(irr_reprK_pchar F'X W). move: (irr_repr V) (irr_repr W) (scalX V) (scalX W). rewrite !linX {}eqVW => rV rW <- rWx; apply: irr_comp_rsim_pchar => //. exists 1%:M; rewrite ?row_free_unit ?unitmx1 // => xk; case/cycleP=> k ->{xk}. by rewrite mulmx1 mul1mx !repr_mxX // rWx. have rx1 W: r W ^+ #[x] = 1. by rewrite -irr_modeX ?(center_idP _) // expg_order irr_mode1. have /hasP[w _ prim_w]: has #[x].-primitive_root (map r (enum sG)). rewrite has_prim_root 1?map_inj_uniq ?enum_uniq //; first 1 last. by rewrite size_map -cardE card_sG. by apply/allP=> _ /mapP[W _ ->]; rewrite unity_rootE rx1. have iphi'P := prim_rootP prim_w (rx1 _); pose iphi' := sval (iphi'P _). have def_r W: r W = w ^+ iphi' W by apply: svalP (iphi'P W). have inj_iphi': injective iphi'. by move=> i j eq_ij; apply: inj_r; rewrite !def_r eq_ij. have iphiP: codom iphi' =i 'I_#[x]. by apply/subset_cardP; rewrite ?subset_predT // card_ord card_image. pose iphi i := iinv (iphiP i); exists w => //; exists iphi. have iphiK: cancel iphi iphi' by move=> i; apply: f_iinv. have r_iphi i: r (iphi i) = w ^+ i by rewrite def_r iphiK. split=> // [|i]; last by rewrite scalX r_iphi. by exists iphi' => // W; rewrite /iphi iinv_f. Qed. Lemma splitting_cyclic_primitive_root_pchar : cyclic G -> [pchar F]^'.-group G -> group_splitting_field G -> classically {z : F | #|G|.-primitive_root z}. Proof. case/cyclicP=> x defG F'G splitF; case=> // IH. wlog sG: / irrType G by apply: socle_exists. have [w prim_w _] := cycle_repr_structure_pchar sG defG F'G splitF. by apply: IH; exists w. Qed. End LinearIrr. End FieldRepr. #[deprecated(since="mathcomp 2.4.0", note="Use mx_Maschke_pchar instead.")] Notation mx_Maschke := (mx_Maschke_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use rsim_regular_submod_pchar instead.")] Notation rsim_regular_submod := (rsim_regular_submod_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_mx_sum_pchar instead.")] Notation irr_mx_sum := (irr_mx_sum_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_sum_pchar instead.")] Notation Wedderburn_sum := (Wedderburn_sum_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_sum_id_pchar instead.")] Notation Wedderburn_sum_id := (Wedderburn_sum_id_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_is_id_pchar instead.")] Notation Wedderburn_is_id:= (Wedderburn_is_id_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_closed_pchar instead.")] Notation Wedderburn_closed := (Wedderburn_closed_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_is_ring_pchar instead.")] Notation Wedderburn_is_ring := (Wedderburn_is_ring_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_min_ideal_pchar instead.")] Notation Wedderburn_min_ideal := (Wedderburn_min_ideal_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use rsim_irr_comp_pchar instead.")] Notation rsim_irr_comp := (rsim_irr_comp_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_comp'_op0_pchar instead.")] Notation irr_comp'_op0 := (irr_comp'_op0_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_comp_envelop_pchar instead.")] Notation irr_comp_envelop := (irr_comp_envelop_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ker_irr_comp_op_pchar instead.")] Notation ker_irr_comp_op := (ker_irr_comp_op_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use regular_op_inj_pchar instead.")] Notation regular_op_inj := (regular_op_inj_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use rank_irr_comp_pchar instead.")] Notation rank_irr_comp := (rank_irr_comp_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_comp_rsim_pchar instead.")] Notation irr_comp_rsim := (irr_comp_rsim_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_reprK_pchar instead.")] Notation irr_reprK := (irr_reprK_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_repr'_op0_pchar instead.")] Notation irr_repr'_op0 := (irr_repr'_op0_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use op_Wedderburn_id_pchar instead.")] Notation op_Wedderburn_id := (op_Wedderburn_id_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_comp_id_pchar instead.")] Notation irr_comp_id := (irr_comp_id_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use rank_Wedderburn_subring_pchar instead.")] Notation rank_Wedderburn_subring := (rank_Wedderburn_subring_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use sum_irr_degree_pchar instead.")] Notation sum_irr_degree := (sum_irr_degree_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_mx_mult_pchar instead.")] Notation irr_mx_mult := (irr_mx_mult_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use mxtrace_regular_pchar instead.")] Notation mxtrace_regular := (mxtrace_regular_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use linear_irr_comp_pchar instead.")] Notation linear_irr_comp := (linear_irr_comp_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_subring_center_pchar instead.")] Notation Wedderburn_subring_center := (Wedderburn_subring_center_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_center_pchar instead.")] Notation Wedderburn_center := (Wedderburn_center_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use card_irr_pchar instead.")] Notation card_irr := (card_irr_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use cycle_repr_structure_pchar instead.")] Notation cycle_repr_structure := (cycle_repr_structure_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use splitting_cyclic_primitive_root_pchar instead.")] Notation splitting_cyclic_primitive_root := (splitting_cyclic_primitive_root_pchar) (only parsing). Arguments rfix_mx {F gT G%_g n%_N} rG H%_g. Arguments gset_mx F {gT} G%_g A%_g. Arguments classg_base F {gT} G%_g _%_g : extra scopes. Arguments irrType F {gT} G%_g. Arguments mxmoduleP {F gT G n rG m U}. Arguments envelop_mxP {F gT G n rG A}. Arguments hom_mxP {F gT G n rG m f W}. Arguments mx_Maschke_pchar [F gT G n] rG _ [U]. Arguments rfix_mxP {F gT G n rG m W}. Arguments cyclic_mxP {F gT G n rG u v}. Arguments annihilator_mxP {F gT G n rG u A}. Arguments row_hom_mxP {F gT G n rG u v}. Arguments mxsimple_isoP {F gT G n rG U V}. Arguments socle_exists [F gT G n]. Arguments socleP {F gT G n rG sG0 W W'}. Arguments mx_abs_irrP {F gT G n rG}. Arguments socle_rsimP {F gT G n rG sG W1 W2}. Arguments val_submod {F n U m} W. Arguments in_submod {F n} U {m} W. Arguments val_submodK {F n U m} W : rename. Arguments in_submodK {F n U m} [W] sWU. Arguments val_submod_inj {F n U m} [W1 W2] : rename. Arguments val_factmod {F n U m} W. Arguments in_factmod {F n} U {m} W. Arguments val_factmodK {F n U m} W : rename. Arguments in_factmodK {F n} U {m} [W] sWU. Arguments val_factmod_inj {F n U m} [W1 W2] : rename. Notation "'Cl" := (Clifford_action _) : action_scope. Arguments gring_row {R gT G} A. Arguments gring_rowK {F gT G} [A] RG_A. Bind Scope irrType_scope with socle_sort. Notation "[ 1 sG ]" := (principal_comp sG) : irrType_scope. Arguments irr_degree {F gT G%_G sG} i%_irr. Arguments irr_repr {F gT G%_G sG} i%_irr _%_g : extra scopes. Arguments irr_mode {F gT G%_G sG} i%_irr z%_g : rename. Notation "''n_' i" := (irr_degree i) : group_ring_scope. Notation "''R_' i" := (Wedderburn_subring i) : group_ring_scope. Notation "''e_' i" := (Wedderburn_id i) : group_ring_scope. Section DecideRed. Import MatrixFormula. Local Notation term := GRing.term. Local Notation True := GRing.True. Local Notation And := GRing.And (only parsing). Local Notation morphAnd f := ((big_morph f) true andb). Local Notation eval := GRing.eval. Local Notation holds := GRing.holds. Local Notation qf_form := GRing.qf_form. Local Notation qf_eval := GRing.qf_eval. Section Definitions. Variables (F : fieldType) (gT : finGroupType) (G : {group gT}) (n : nat). Variable rG : mx_representation F G n. Definition mxmodule_form (U : 'M[term F]_n) := \big[And/True]_(x in G) submx_form (mulmx_term U (mx_term (rG x))) U. Lemma mxmodule_form_qf U : qf_form (mxmodule_form U). Proof. by rewrite (morphAnd (@qf_form _)) ?big1 //= => x _; rewrite submx_form_qf. Qed. Lemma eval_mxmodule U e : qf_eval e (mxmodule_form U) = mxmodule rG (eval_mx e U). Proof. rewrite (morphAnd (qf_eval e)) //= big_andE /=. apply/forallP/mxmoduleP=> Umod x; move/implyP: (Umod x); by rewrite eval_submx eval_mulmx eval_mx_term. Qed. Definition mxnonsimple_form (U : 'M[term F]_n) := let V := vec_mx (row_var F (n * n) 0) in let nzV := (~ mxrank_form 0 V)%T in let properVU := (submx_form V U /\ ~ submx_form U V)%T in (Exists_row_form (n * n) 0 (mxmodule_form V /\ nzV /\ properVU))%T. End Definitions. Variables (F : decFieldType) (gT : finGroupType) (G : {group gT}) (n : nat). Variable rG : mx_representation F G n. Definition mxnonsimple_sat U := GRing.sat (@row_env _ (n * n) [::]) (mxnonsimple_form rG (mx_term U)). Lemma mxnonsimpleP U : U != 0 -> reflect (mxnonsimple rG U) (mxnonsimple_sat U). Proof. rewrite /mxnonsimple_sat {1}/mxnonsimple_form; set Vt := vec_mx _ => /= nzU. pose nsim V := [&& mxmodule rG V, (V <= U)%MS, V != 0 & \rank V < \rank U]. set nsimUt := (_ /\ _)%T; have: qf_form nsimUt. by rewrite /= mxmodule_form_qf !mxrank_form_qf !submx_form_qf. move/GRing.qf_evalP; set qev := @GRing.qf_eval _ => qevP. have qev_nsim u: qev (row_env [:: u]) nsimUt = nsim n (vec_mx u). rewrite /nsim -mxrank_eq0 /qev /= eval_mxmodule eval_mxrank. rewrite !eval_submx eval_mx_term eval_vec_mx eval_row_var /=. do 2!bool_congr; apply: andb_id2l => sUV. by rewrite ltn_neqAle andbC !mxrank_leqif_sup. have n2gt0: n ^ 2 > 0. by move: nzU; rewrite muln_gt0 -mxrank_eq0 unlock; case: posnP (U) => // ->. apply: (iffP satP) => [|[V nsimV]]. by case/Exists_rowP=> // v; move/qevP; rewrite qev_nsim; exists (vec_mx v). apply/Exists_rowP=> //; exists (mxvec V); apply/qevP. by rewrite qev_nsim mxvecK. Qed. Lemma dec_mxsimple_exists (U : 'M_n) : mxmodule rG U -> U != 0 -> {V | mxsimple rG V & V <= U}%MS. Proof. have [m] := ubnP (\rank U); elim: m U => // m IHm U leUm modU nzU. have [nsimU | simU] := mxnonsimpleP nzU; last first. by exists U; first apply/mxsimpleP. move: (xchooseP nsimU); move: (xchoose _) => W /and4P[modW sWU nzW ltWU]. case: (IHm W) => // [|V simV sVW]; first exact: leq_trans ltWU _. by exists V; last apply: submx_trans sVW sWU. Qed. Lemma dec_mx_reducible_semisimple U : mxmodule rG U -> mx_completely_reducible rG U -> mxsemisimple rG U. Proof. have [m] := ubnP (\rank U); elim: m U => // m IHm U leUm modU redU. have [U0 | nzU] := eqVneq U 0. have{} U0: (\sum_(i < 0) 0 :=: U)%MS by rewrite big_ord0 U0. by apply: (intro_mxsemisimple U0); case. have [V simV sVU] := dec_mxsimple_exists modU nzU; have [modV nzV _] := simV. have [W modW defVW dxVW] := redU V modV sVU. have [||I W_ /= simW defW _] := IHm W _ modW. - rewrite ltnS in leUm; apply: leq_trans leUm. by rewrite -defVW (mxdirectP dxVW) /= -add1n leq_add2r lt0n mxrank_eq0. - by apply: mx_reducibleS redU; rewrite // -defVW addsmxSr. suffices defU: (\sum_i oapp W_ V i :=: U)%MS. by apply: (intro_mxsemisimple defU) => [] [|i] //=. apply: eqmx_trans defVW; rewrite (bigD1 None) //=; apply/eqmxP. have [i0 _ | I0] := pickP I. by rewrite (reindex some) ?addsmxS ?defW //; exists (odflt i0) => //; case. rewrite big_pred0 //; last by case=> // /I0. by rewrite !addsmxS ?sub0mx // -defW big_pred0. Qed. Lemma DecSocleType : socleType rG. Proof. have [n0 | n_gt0] := posnP n. by exists [::] => // M [_]; rewrite -mxrank_eq0 -leqn0 -n0 rank_leq_row. have n2_gt0: n ^ 2 > 0 by rewrite muln_gt0 n_gt0. pose span Ms := (\sum_(M <- Ms) component_mx rG M)%MS. have: {in [::], forall M, mxsimple rG M} by []. have [m] := ubnP (n - \rank (span [::])). elim: m [::] => // m IHm Ms /ltnSE-Ms_ge_n simMs. pose V := span Ms; pose Vt := mx_term V. pose Ut i := vec_mx (row_var F (n * n) i); pose Zt := mx_term (0 : 'M[F]_n). pose exU i f := Exists_row_form (n * n) i (~ submx_form (Ut i) Zt /\ f (Ut i)). pose meetUVf U := exU 1 (fun W => submx_form W Vt /\ submx_form W U)%T. pose mx_sat := GRing.sat (@row_env F (n * n) [::]). have ev_sub0 := GRing.qf_evalP _ (submx_form_qf _ Zt). have ev_mod := GRing.qf_evalP _ (mxmodule_form_qf rG _). pose ev := (eval_mxmodule, eval_submx, eval_vec_mx, eval_row_var, eval_mx_term). case haveU: (mx_sat (exU 0 (fun U => mxmodule_form rG U /\ ~ meetUVf _ U)%T)). have [U modU]: {U : 'M_n | mxmodule rG U & (U != 0) && ((U :&: V)%MS == 0)}. apply: sig2W; case/Exists_rowP: (satP haveU) => //= u [nzU [modU tiUV]]. exists (vec_mx u); first by move/ev_mod: modU; rewrite !ev. set W := (_ :&: V)%MS; move/ev_sub0: nzU; rewrite !ev -!submx0 => -> /=. apply/idPn=> nzW; case: tiUV; apply/Exists_rowP=> //; exists (mxvec W). apply/GRing.qf_evalP; rewrite /= ?submx_form_qf // !ev mxvecK nzW /=. by rewrite andbC -sub_capmx. case/andP=> nzU tiUV; have [M simM sMU] := dec_mxsimple_exists modU nzU. apply: (IHm (M :: Ms)) => [|M']; last first. by case/predU1P=> [-> //|]; apply: simMs. have [_ nzM _] := simM. suffices ltVMV: \rank V < \rank (span (M :: Ms)). rewrite (leq_trans _ Ms_ge_n) // ltn_sub2l ?(leq_trans ltVMV) //. exact: rank_leq_row. rewrite /span big_cons (ltn_leqif (mxrank_leqif_sup (addsmxSr _ _))). apply: contra nzM; rewrite addsmx_sub -submx0 -(eqP tiUV) sub_capmx sMU. by case/andP=> sMV _; rewrite (submx_trans _ sMV) ?component_mx_id. exists Ms => // M simM; have [modM nzM minM] := simM. have sMV: (M <= V)%MS. apply: contraFT haveU => not_sMV; apply/satP/Exists_rowP=> //. exists (mxvec M); split; first by apply/ev_sub0; rewrite !ev mxvecK submx0. split; first by apply/ev_mod; rewrite !ev mxvecK. apply/Exists_rowP=> // [[w]]. apply/GRing.qf_evalP; rewrite /= ?submx_form_qf // !ev /= mxvecK submx0. rewrite -nz_row_eq0 -(cyclic_mx_eq0 rG); set W := cyclic_mx _ _. apply: contra not_sMV => /and3P[nzW Vw Mw]. have{Vw Mw} [sWV sWM]: (W <= V /\ W <= M)%MS. rewrite !cyclic_mx_sub ?(submx_trans (nz_row_sub _)) //. by rewrite sumsmx_module // => M' _; apply: component_mx_module. by rewrite (submx_trans _ sWV) // minM ?cyclic_mx_module. wlog sG: / socleType rG by apply: socle_exists. have sVS: (V <= \sum_(W : sG | has (fun Mi => Mi <= W) Ms) W)%MS. rewrite [V](big_nth 0) big_mkord; apply/sumsmx_subP=> i _. set Mi := Ms`_i; have MsMi: Mi \in Ms by apply: mem_nth. have simMi := simMs _ MsMi; have S_Mi := component_socle sG simMi. rewrite (sumsmx_sup (PackSocle S_Mi)) ?PackSocleK //. by apply/hasP; exists Mi; rewrite ?component_mx_id. have [W MsW isoWM] := subSocle_iso simM (submx_trans sMV sVS). have [Mi MsMi sMiW] := hasP MsW; apply/hasP; exists Mi => //. have [simMi simW] := (simMs _ MsMi, socle_simple W); apply/mxsimple_isoP=> //. exact: mx_iso_trans (mx_iso_sym isoWM) (component_mx_iso simW simMi sMiW). Qed. End DecideRed. Prenex Implicits mxmodule_form mxnonsimple_form mxnonsimple_sat. (* Change of representation field (by tensoring) *) Section ChangeOfField. Variables (aF rF : fieldType) (f : {rmorphism aF -> rF}). Local Notation "A ^f" := (map_mx (GRing.RMorphism.sort f) A) : ring_scope. Variables (gT : finGroupType) (G : {group gT}). Section OneRepresentation. Variables (n : nat) (rG : mx_representation aF G n). Local Notation rGf := (map_repr f rG). Lemma map_rfix_mx H : (rfix_mx rG H)^f = rfix_mx rGf H. Proof. rewrite map_kermx //; congr (kermx _); apply: map_lin1_mx => //= v. rewrite map_mxvec map_mxM; congr (mxvec (_ *m _)); last first. by apply: map_lin1_mx => //= u; rewrite map_mxM map_vec_mx. by apply/row_matrixP=> i; rewrite -map_row !rowK map_mxvec map_mxB map_mx1. Qed. Lemma rcent_map A : rcent rGf A^f = rcent rG A. Proof. by apply/setP=> x; rewrite !inE -!map_mxM inj_eq //; apply: map_mx_inj. Qed. Lemma rstab_map m (U : 'M_(m, n)) : rstab rGf U^f = rstab rG U. Proof. by apply/setP=> x; rewrite !inE -!map_mxM inj_eq //; apply: map_mx_inj. Qed. Lemma rstabs_map m (U : 'M_(m, n)) : rstabs rGf U^f = rstabs rG U. Proof. by apply/setP=> x; rewrite !inE -!map_mxM ?map_submx. Qed. Lemma centgmx_map A : centgmx rGf A^f = centgmx rG A. Proof. by rewrite /centgmx rcent_map. Qed. Lemma mxmodule_map m (U : 'M_(m, n)) : mxmodule rGf U^f = mxmodule rG U. Proof. by rewrite /mxmodule rstabs_map. Qed. Lemma mxsimple_map (U : 'M_n) : mxsimple rGf U^f -> mxsimple rG U. Proof. case; rewrite map_mx_eq0 // mxmodule_map // => modU nzU minU. split=> // V modV sVU nzV; rewrite -(map_submx f). by rewrite (minU V^f) //= ?mxmodule_map ?map_mx_eq0 // map_submx. Qed. Lemma mx_irr_map : mx_irreducible rGf -> mx_irreducible rG. Proof. by move=> irrGf; apply: mxsimple_map; rewrite map_mx1. Qed. Lemma rker_map : rker rGf = rker rG. Proof. by rewrite /rker -rstab_map map_mx1. Qed. Lemma map_mx_faithful : mx_faithful rGf = mx_faithful rG. Proof. by rewrite /mx_faithful rker_map. Qed. Lemma map_mx_abs_irr : mx_absolutely_irreducible rGf = mx_absolutely_irreducible rG. Proof. by rewrite /mx_absolutely_irreducible -map_enveloping_algebra_mx row_full_map. Qed. End OneRepresentation. Lemma mx_rsim_map n1 n2 rG1 rG2 : @mx_rsim _ _ G n1 rG1 n2 rG2 -> mx_rsim (map_repr f rG1) (map_repr f rG2). Proof. case=> g eqn12 inj_g hom_g. by exists g^f => // [|x Gx]; rewrite ?row_free_map // -!map_mxM ?hom_g. Qed. Lemma map_section_repr n (rG : mx_representation aF G n) rGf U V (modU : mxmodule rG U) (modV : mxmodule rG V) (modUf : mxmodule rGf U^f) (modVf : mxmodule rGf V^f) : map_repr f rG =1 rGf -> mx_rsim (map_repr f (section_repr modU modV)) (section_repr modUf modVf). Proof. move=> def_rGf; set VU := <<_>>%MS. pose valUV := val_factmod (val_submod (1%:M : 'M[aF]_(\rank VU))). have sUV_Uf: (valUV^f <= U^f + V^f)%MS. rewrite -map_addsmx map_submx; apply: submx_trans (proj_factmodS _ _). by rewrite val_factmodS val_submod1 genmxE. exists (in_submod _ (in_factmod U^f valUV^f)) => [||x Gx]. - rewrite !genmxE -(mxrank_map f) map_mxM map_col_base. by case: (\rank (cokermx U)) / (mxrank_map _ _); rewrite map_cokermx. - rewrite -kermx_eq0 -submx0; apply/rV_subP=> u. rewrite (sameP sub_kermxP eqP) submx0 -val_submod_eq0. rewrite val_submodE -mulmxA -val_submodE in_submodK; last first. by rewrite genmxE -(in_factmod_addsK _ V^f) submxMr. rewrite in_factmodE mulmxA -in_factmodE in_factmod_eq0. move/(submxMr (in_factmod U 1%:M *m in_submod VU 1%:M)^f). rewrite -mulmxA -!map_mxM //; do 2!rewrite mulmxA -in_factmodE -in_submodE. rewrite val_factmodK val_submodK map_mx1 mulmx1. have ->: in_factmod U U = 0 by apply/eqP; rewrite in_factmod_eq0. by rewrite linear0 map_mx0 eqmx0 submx0. rewrite {1}in_submodE mulmxA -in_submodE -in_submodJ; last first. by rewrite genmxE -(in_factmod_addsK _ V^f) submxMr. congr (in_submod _ _); rewrite -in_factmodJ // in_factmodE mulmxA -in_factmodE. apply/eqP; rewrite -subr_eq0 -def_rGf -!map_mxM -linearB in_factmod_eq0. rewrite -map_mxB map_submx -in_factmod_eq0 linearB. rewrite /= (in_factmodJ modU) // val_factmodK. rewrite [valUV]val_factmodE mulmxA -val_factmodE val_factmodK. rewrite -val_submodE in_submodK ?subrr //. by rewrite mxmodule_trans ?section_module // val_submod1. Qed. Lemma map_regular_subseries U i (modU : mx_subseries (regular_repr aF G) U) (modUf : mx_subseries (regular_repr rF G) [seq M^f | M <- U]) : mx_rsim (map_repr f (subseries_repr i modU)) (subseries_repr i modUf). Proof. set mf := map _ in modUf *; rewrite /subseries_repr. do 2!move: (mx_subseries_module' _ _) (mx_subseries_module _ _). have mf_i V: nth 0^f (mf V) i = (V`_i)^f. case: (ltnP i (size V)) => [ltiV | leVi]; first exact: nth_map. by rewrite !nth_default ?size_map. rewrite -(map_mx0 f) mf_i (mf_i (0 :: U)) => modUi'f modUif modUi' modUi. by apply: map_section_repr; apply: map_regular_repr. Qed. Lemma extend_group_splitting_field : group_splitting_field aF G -> group_splitting_field rF G. Proof. move=> splitG n rG irrG. have modU0: all ((mxmodule (regular_repr aF G)) #|G|) [::] by []. apply: (mx_Schreier modU0 _) => // [[U [compU lastU _]]]; have [modU _]:= compU. pose Uf := map (map_mx f) U. have{lastU} lastUf: (last 0 Uf :=: 1%:M)%MS. by rewrite -(map_mx0 f) -(map_mx1 f) last_map; apply/map_eqmx. have modUf: mx_subseries (regular_repr rF G) Uf. rewrite /mx_subseries all_map; apply: etrans modU; apply: eq_all => Ui /=. rewrite -mxmodule_map; apply: eq_subset_r => x. by rewrite !inE map_regular_repr. have absUf i: i < size U -> mx_absolutely_irreducible (subseries_repr i modUf). move=> lt_i_U; rewrite -(mx_rsim_abs_irr (map_regular_subseries i modU _)). rewrite map_mx_abs_irr; apply: splitG. by apply: mx_rsim_irr (mx_series_repr_irr compU lt_i_U); apply: section_eqmx. have compUf: mx_composition_series (regular_repr rF G) Uf. split=> // i; rewrite size_map => ltiU. move/max_submodP: (mx_abs_irrW (absUf i ltiU)); apply. rewrite -{2}(map_mx0 f) -map_cons !(nth_map 0) ?leqW //. by rewrite map_submx // ltmxW // (pathP _ (mx_series_lt compU)). have [[i ltiU] simUi] := rsim_regular_series irrG compUf lastUf. have{} simUi: mx_rsim rG (subseries_repr i modUf). by apply: mx_rsim_trans simUi _; apply: section_eqmx. by rewrite (mx_rsim_abs_irr simUi) absUf; rewrite size_map in ltiU. Qed. End ChangeOfField. (* Construction of a splitting field FA of an irreducible representation, for *) (* a matrix A in the centraliser of the representation. FA is the row-vector *) (* space of the matrix algebra generated by A with basis 1, A, ..., A ^+ d.-1 *) (* or, equivalently, the polynomials in {poly F} taken mod the (irreducible) *) (* minimal polynomial pA of A (of degree d). *) (* The details of the construction of FA are encapsulated in a submodule. *) Module Import MatrixGenField. (* The type definition must come before the main section so that the Bind *) (* Scope directive applies to all lemmas and definition discharged at the *) (* of the section. *) Record gen_of {F : fieldType} {gT : finGroupType} {G : {group gT}} {n' : nat} {rG : mx_representation F G n'.+1} {A : 'M[F]_n'.+1} (irrG : mx_irreducible rG) (cGA : centgmx rG A) := Gen {rVval : 'rV[F]_(degree_mxminpoly A)}. Local Arguments rVval {F gT G%_G n'%_N rG A%_R irrG cGA} x%_R : rename. Bind Scope ring_scope with gen_of. Section GenField. Variables (F : fieldType) (gT : finGroupType) (G : {group gT}) (n' : nat). Local Notation n := n'.+1. Variables (rG : mx_representation F G n) (A : 'M[F]_n). Local Notation d := (degree_mxminpoly A). Local Notation Ad := (powers_mx A d). Local Notation pA := (mxminpoly A). Let d_gt0 := mxminpoly_nonconstant A. Local Notation irr := mx_irreducible. Hypotheses (irrG : irr rG) (cGA : centgmx rG A). Notation FA := (gen_of irrG cGA). Let inFA := Gen irrG cGA. #[export, hnf] HB.instance Definition _ := [isNew for rVval : FA -> 'rV_d]. #[export] HB.instance Definition _ := [Choice of FA by <:]. Definition gen0 := inFA 0. Definition genN (x : FA) := inFA (- val x). Definition genD (x y : FA) := inFA (val x + val y). Lemma gen_addA : associative genD. Proof. by move=> x y z; apply: val_inj; rewrite /= addrA. Qed. Lemma gen_addC : commutative genD. Proof. by move=> x y; apply: val_inj; rewrite /= addrC. Qed. Lemma gen_add0r : left_id gen0 genD. Proof. by move=> x; apply: val_inj; rewrite /= add0r. Qed. Lemma gen_addNr : left_inverse gen0 genN genD. Proof. by move=> x; apply: val_inj; rewrite /= addNr. Qed. #[export] HB.instance Definition _ := GRing.isZmodule.Build FA gen_addA gen_addC gen_add0r gen_addNr. Definition pval (x : FA) := rVpoly (val x). Definition mxval (x : FA) := horner_mx A (pval x). Definition gen (x : F) := inFA (poly_rV x%:P). Lemma genK x : mxval (gen x) = x%:M. Proof. by rewrite /mxval [pval _]poly_rV_K ?horner_mx_C // size_polyC; case: (x != 0). Qed. Lemma mxval_inj : injective mxval. Proof. exact: inj_comp horner_rVpoly_inj val_inj. Qed. Lemma mxval0 : mxval 0 = 0. Proof. by rewrite /mxval [pval _]raddf0 rmorph0. Qed. Lemma mxvalN : {morph mxval : x / - x}. Proof. by move=> x; rewrite /mxval [pval _](@raddfN 'rV[F]_d) rmorphN. Qed. Lemma mxvalD : {morph mxval : x y / x + y}. Proof. by move=> x y; rewrite /mxval [pval _]raddfD rmorphD. Qed. Definition mxval_sum := big_morph mxval mxvalD mxval0. Definition gen1 := inFA (poly_rV 1). Definition genM x y := inFA (poly_rV (pval x * pval y %% pA)). Definition genV x := inFA (poly_rV (mx_inv_horner A (mxval x)^-1)). Lemma mxval_gen1 : mxval gen1 = 1%:M. Proof. by rewrite /mxval [pval _]poly_rV_K ?size_poly1 // horner_mx_C. Qed. Lemma mxval_genM : {morph mxval : x y / genM x y >-> x *m y}. Proof. move=> x y; rewrite /mxval [pval _]poly_rV_K ?size_mod_mxminpoly //. by rewrite -horner_mxK mx_inv_hornerK ?horner_mx_mem // rmorphM. Qed. Lemma mxval_genV : {morph mxval : x / genV x >-> invmx x}. Proof. move=> x; rewrite /mxval [pval _]poly_rV_K ?size_poly ?mx_inv_hornerK //. pose m B : 'M[F]_(n * n) := lin_mx (mulmxr B); set B := mxval x. case uB: (B \is a GRing.unit); last by rewrite invr_out ?uB ?horner_mx_mem. have defAd: Ad = Ad *m m B *m m B^-1. apply/row_matrixP=> i. by rewrite !row_mul mul_rV_lin /= mx_rV_lin /= mulmxK ?vec_mxK. rewrite -[B^-1]mul1mx -(mul_vec_lin (mulmxr B^-1)) defAd submxMr //. rewrite -mxval_gen1 (submx_trans (horner_mx_mem _ _)) // {1}defAd. rewrite -(geq_leqif (mxrank_leqif_sup _)) ?mxrankM_maxl // -{}defAd. apply/row_subP=> i; rewrite row_mul rowK mul_vec_lin /= -{2}[A]horner_mx_X. by rewrite -rmorphXn mulmxE -rmorphM horner_mx_mem. Qed. Lemma gen_mulA : associative genM. Proof. by move=> x y z; apply: mxval_inj; rewrite !mxval_genM mulmxA. Qed. Lemma gen_mulC : commutative genM. Proof. by move=> x y; rewrite /genM mulrC. Qed. Lemma gen_mul1r : left_id gen1 genM. Proof. by move=> x; apply: mxval_inj; rewrite mxval_genM mxval_gen1 mul1mx. Qed. Lemma gen_mulDr : left_distributive genM +%R. Proof. by move=> x y z; apply: mxval_inj; rewrite !(mxvalD, mxval_genM) mulmxDl. Qed. Lemma gen_ntriv : gen1 != 0. Proof. by rewrite -(inj_eq mxval_inj) mxval_gen1 mxval0 oner_eq0. Qed. #[export] HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build FA gen_mulA gen_mulC gen_mul1r gen_mulDr gen_ntriv. Lemma mxval1 : mxval 1 = 1%:M. Proof. exact: mxval_gen1. Qed. Lemma mxvalM : {morph mxval : x y / x * y >-> x *m y}. Proof. exact: mxval_genM. Qed. Lemma mxval_is_zmod_morphism : zmod_morphism mxval. Proof. by move=> x y; rewrite mxvalD mxvalN. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `mxval_is_zmod_morphism` instead")] Definition mxval_sub := mxval_is_zmod_morphism. #[export] HB.instance Definition _ := GRing.isZmodMorphism.Build FA 'M[F]_n mxval mxval_is_zmod_morphism. Lemma mxval_is_monoid_morphism : monoid_morphism mxval. Proof. by split; [apply: mxval1 | apply: mxvalM]. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `mxval_is_monoid_morphism` instead")] Definition mxval_is_multiplicative := (fun g => (g.2,g.1)) mxval_is_monoid_morphism. #[export] HB.instance Definition _ := GRing.isMonoidMorphism.Build FA 'M[F]_n mxval mxval_is_monoid_morphism. Lemma mxval_centg x : centgmx rG (mxval x). Proof. rewrite [mxval _]horner_rVpoly -memmx_cent_envelop vec_mxK {x}mulmx_sub //. apply/row_subP=> k; rewrite rowK memmx_cent_envelop; apply/centgmxP => g Gg /=. by rewrite !mulmxE commrX // /GRing.comm -mulmxE (centgmxP cGA). Qed. Lemma gen_mulVr x : x != 0 -> genV x * x = 1. Proof. rewrite -(inj_eq mxval_inj) mxval0. move/(mx_Schur irrG (mxval_centg x)) => u_x. by apply: mxval_inj; rewrite mxvalM mxval_genV mxval1 mulVmx. Qed. Lemma gen_invr0 : genV 0 = 0. Proof. by apply: mxval_inj; rewrite mxval_genV !mxval0 -{2}invr0. Qed. #[export] HB.instance Definition _ := GRing.ComNzRing_isField.Build FA gen_mulVr gen_invr0. Lemma mxvalV : {morph mxval : x / x^-1 >-> invmx x}. Proof. exact: mxval_genV. Qed. Lemma gen_is_zmod_morphism : zmod_morphism gen. Proof. by move=> x y; apply: mxval_inj; rewrite genK !rmorphB /= !genK. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `gen_is_zmod_morphism` instead")] Definition gen_is_additive := gen_is_zmod_morphism. Lemma gen_is_monoid_morphism : monoid_morphism gen. Proof. by split=> // x y; apply: mxval_inj; rewrite genK !rmorphM /= !genK. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `gen_is_monoid_morphism` instead")] Definition gen_is_multiplicative := (fun g => (g.2,g.1)) gen_is_monoid_morphism. #[export] HB.instance Definition _ := GRing.isZmodMorphism.Build F FA gen gen_is_zmod_morphism. #[export] HB.instance Definition _ := GRing.isMonoidMorphism.Build F FA gen gen_is_monoid_morphism. (* The generated field contains a root of the minimal polynomial (in some *) (* cases we want to use the construction solely for that purpose). *) Definition groot := inFA (poly_rV ('X %% pA)). Lemma mxval_groot : mxval groot = A. Proof. rewrite /mxval [pval _]poly_rV_K ?size_mod_mxminpoly // -horner_mxK. by rewrite mx_inv_hornerK ?horner_mx_mem // horner_mx_X. Qed. Lemma mxval_grootXn k : mxval (groot ^+ k) = A ^+ k. Proof. by rewrite rmorphXn /= mxval_groot. Qed. Lemma map_mxminpoly_groot : (map_poly gen pA).[groot] = 0. Proof. (* The [_ groot] prevents divergence of simpl. *) apply: mxval_inj; rewrite -horner_map [_ groot]/= mxval_groot mxval0. rewrite -(mx_root_minpoly A); congr ((_ : {poly _}).[A]). by apply/polyP=> i; rewrite 3!coef_map; apply: genK. Qed. (* Plugging the extension morphism gen into the ext_repr construction *) (* yields a (reducible) tensored representation. *) Lemma non_linear_gen_reducible : d > 1 -> mxnonsimple (map_repr gen rG) 1%:M. Proof. rewrite ltnNge mxminpoly_linear_is_scalar => Anscal. pose Af := map_mx gen A; exists (kermx (Af - groot%:M)). rewrite submx1 kermx_centg_module /=; last first. apply/centgmxP=> z Gz; rewrite mulmxBl [RHS]mulmxBr [in RHS]scalar_mxC. by rewrite -!map_mxM 1?(centgmxP cGA). rewrite andbC mxrank_ker -subn_gt0 mxrank1 subKn ?rank_leq_row // lt0n. rewrite mxrank_eq0 subr_eq0; case: eqP => [defAf | _]. rewrite -(map_mx_is_scalar gen) -/Af in Anscal. by case/is_scalar_mxP: Anscal; exists groot. rewrite -mxrank_eq0 mxrank_ker subn_eq0 row_leq_rank. apply/row_freeP=> [[XA' XAK]]. have pAf0: (mxminpoly Af).[groot] == 0. by rewrite mxminpoly_map ?map_mxminpoly_groot. have{pAf0} [q def_pAf]:= factor_theorem _ _ pAf0. have q_nz: q != 0. case: eqP (congr1 (fun p : {poly _} => size p) def_pAf) => // ->. by rewrite size_mxminpoly mul0r size_poly0. have qAf0: horner_mx Af q = 0. rewrite -[_ q]mulr1 -[1]XAK mulrA -{2}(horner_mx_X Af) -(horner_mx_C Af). by rewrite -rmorphB -rmorphM -def_pAf /= mx_root_minpoly mul0r. have{qAf0} := dvdp_leq q_nz (mxminpoly_min qAf0); rewrite def_pAf. by rewrite size_Mmonic ?monicXsubC // polyseqXsubC addn2 ltnn. Qed. (* An alternative to the above, used in the proof of the p-stability of *) (* groups of odd order, is to reconsider the original vector space as a *) (* vector space of dimension n / e over FA. This is applicable only if G is *) (* the largest group represented on the original vector space (i.e., if we *) (* are not studying a representation of G induced by one of a larger group, *) (* as in B & G Theorem 2.6 for instance). We can't fully exploit one of the *) (* benefits of this approach -- that the type domain for the vector space can *) (* remain unchanged -- because we're restricting ourselves to row matrices; *) (* we have to use explicit bijections to convert between the two views. *) Definition subbase nA (B : 'rV_nA) : 'M_(nA * d, n) := \matrix_ik mxvec (\matrix_(i, k) (row (B 0 i) (A ^+ k))) 0 ik. Lemma gen_dim_ex_proof : exists nA, [exists B : 'rV_nA, row_free (subbase B)]. Proof. by exists 0; apply/existsP; exists 0; rewrite /row_free unlock. Qed. Lemma gen_dim_ub_proof nA : [exists B : 'rV_nA, row_free (subbase B)] -> (nA <= n)%N. Proof. case/existsP=> B /eqnP def_nAd. by rewrite (leq_trans _ (rank_leq_col (subbase B))) // def_nAd leq_pmulr. Qed. Definition gen_dim := ex_maxn gen_dim_ex_proof gen_dim_ub_proof. Notation nA := gen_dim. Definition gen_base : 'rV_nA := odflt 0 [pick B | row_free (subbase B)]. Definition base := subbase gen_base. Lemma base_free : row_free base. Proof. rewrite /base /gen_base /nA; case: pickP => //; case: ex_maxnP => nA_max. by case/existsP=> B Bfree _ no_free; rewrite no_free in Bfree. Qed. Lemma base_full : row_full base. Proof. rewrite /row_full (eqnP base_free) /nA; case: ex_maxnP => nA. case/existsP=> /= B /eqnP Bfree nA_max; rewrite -Bfree eqn_leq rank_leq_col. rewrite -{1}(mxrank1 F n) mxrankS //; apply/row_subP=> j; set u := row _ _. move/implyP: {nA_max}(nA_max nA.+1); rewrite ltnn implybF. apply: contraR => nBj; apply/existsP. exists (row_mx (const_mx j : 'M_1) B); rewrite -row_leq_rank. pose Bj := Ad *m lin1_mx (mulmx u \o vec_mx). have rBj: \rank Bj = d. apply/eqP; rewrite eqn_leq rank_leq_row -subn_eq0 -mxrank_ker mxrank_eq0 /=. apply/rowV0P=> v /sub_kermxP; rewrite mulmxA mul_rV_lin1 /=. rewrite -horner_rVpoly; pose x := inFA v; rewrite -/(mxval x). have [[] // | nzx /(congr1 (mulmx^~ (mxval x^-1)))] := eqVneq x 0. rewrite mul0mx /= -mulmxA -mxvalM divff // mxval1 mulmx1. by move/rowP/(_ j)/eqP; rewrite !mxE !eqxx oner_eq0. rewrite {1}mulSn -Bfree -{1}rBj {rBj} -mxrank_disjoint_sum. rewrite mxrankS // addsmx_sub -[nA.+1]/(1 + nA)%N; apply/andP; split. apply/row_subP=> k; rewrite row_mul mul_rV_lin1 /=. apply: eq_row_sub (mxvec_index (lshift _ 0) k) _. by rewrite !rowK mxvecK mxvecE mxE row_mxEl mxE -row_mul mul1mx. apply/row_subP; case/mxvec_indexP=> i k. apply: eq_row_sub (mxvec_index (rshift 1 i) k) _. by rewrite !rowK !mxvecE 2!mxE row_mxEr. apply/eqP/rowV0P=> v; rewrite sub_capmx => /andP[/submxP[w]]. set x := inFA w; rewrite {Bj}mulmxA mul_rV_lin1 /= -horner_rVpoly -/(mxval x). have [-> | nzx ->] := eqVneq x 0; first by rewrite mxval0 mulmx0. move/(submxMr (mxval x^-1)); rewrite -mulmxA -mxvalM divff {nzx}//. rewrite mxval1 mulmx1 => Bx'j; rewrite (submx_trans Bx'j) in nBj => {Bx'j} //. apply/row_subP; case/mxvec_indexP=> i k. rewrite row_mul rowK mxvecE mxE rowE -mulmxA. have ->: A ^+ k *m mxval x^-1 = mxval (groot ^+ k / x). by rewrite mxvalM rmorphXn /= mxval_groot. rewrite [mxval _]horner_rVpoly; move: {k u x}(val _) => u. rewrite (mulmx_sum_row u) !linear_sum summx_sub //= => k _. rewrite 2!linearZ scalemx_sub //= rowK mxvecK -rowE. by apply: eq_row_sub (mxvec_index i k) _; rewrite rowK mxvecE mxE. Qed. Lemma gen_dim_factor : (nA * d)%N = n. Proof. by rewrite -(eqnP base_free) (eqnP base_full). Qed. Lemma gen_dim_gt0 : nA > 0. Proof. by case: posnP gen_dim_factor => // ->. Qed. Section Bijection. Variable m : nat. Definition in_gen (W : 'M[F]_(m, n)) : 'M[FA]_(m, nA) := \matrix_(i, j) inFA (row j (vec_mx (row i W *m pinvmx base))). Definition val_gen (W : 'M[FA]_(m, nA)) : 'M[F]_(m, n) := \matrix_i (mxvec (\matrix_j val (W i j)) *m base). Lemma in_genK : cancel in_gen val_gen. Proof. move=> W; apply/row_matrixP=> i; rewrite rowK; set w := row i W. have b_w: (w <= base)%MS by rewrite submx_full ?base_full. rewrite -{b_w}(mulmxKpV b_w); congr (_ *m _). by apply/rowP; case/mxvec_indexP=> j k; rewrite mxvecE !mxE. Qed. Lemma val_genK : cancel val_gen in_gen. Proof. move=> W; apply/matrixP=> i j; apply: val_inj; rewrite mxE /= rowK. case/row_freeP: base_free => B' BB'; rewrite -[_ *m _]mulmx1 -BB' mulmxA. by rewrite mulmxKpV ?submxMl // -mulmxA BB' mulmx1 mxvecK rowK. Qed. Lemma in_gen0 : in_gen 0 = 0. Proof. by apply/matrixP=> i j; rewrite !mxE !(mul0mx, linear0). Qed. Lemma val_gen0 : val_gen 0 = 0. Proof. by apply: (canLR in_genK); rewrite in_gen0. Qed. Lemma in_genD : {morph in_gen : U V / U + V}. Proof. by move=> U V; apply/matrixP=> i j; rewrite !mxE 4!(mulmxDl, linearD). Qed. Lemma val_genD : {morph val_gen : U V / U + V}. Proof. by move=> U V; apply: (canLR in_genK); rewrite in_genD !val_genK. Qed. Lemma in_genN : {morph in_gen : W / - W}. Proof. by move=> W; apply/esym/addr0_eq; rewrite -in_genD subrr in_gen0. Qed. Lemma val_genN : {morph val_gen : W / - W}. Proof. by move=> W; apply: (canLR in_genK); rewrite in_genN val_genK. Qed. Definition in_gen_sum := big_morph in_gen in_genD in_gen0. Definition val_gen_sum := big_morph val_gen val_genD val_gen0. Lemma in_genZ a : {morph in_gen : W / a *: W >-> gen a *: W}. Proof. move=> W; apply/matrixP=> i j; apply: mxval_inj. rewrite !mxE mxvalM genK ![mxval _]horner_rVpoly /=. by rewrite mul_scalar_mx !(I, scalemxAl, linearZ). Qed. End Bijection. Prenex Implicits val_genK in_genK. Lemma val_gen_rV (w : 'rV_nA) : val_gen w = mxvec (\matrix_j val (w 0 j)) *m base. Proof. by apply/rowP=> j /[1!mxE]. Qed. Section Bijection2. Variable m : nat. Lemma val_gen_row W (i : 'I_m) : val_gen (row i W) = row i (val_gen W). Proof. rewrite val_gen_rV rowK; congr (mxvec _ *m _). by apply/matrixP=> j k /[!mxE]. Qed. Lemma in_gen_row W (i : 'I_m) : in_gen (row i W) = row i (in_gen W). Proof. by apply: (canLR val_genK); rewrite val_gen_row in_genK. Qed. Lemma row_gen_sum_mxval W (i : 'I_m) : row i (val_gen W) = \sum_j row (gen_base 0 j) (mxval (W i j)). Proof. rewrite -val_gen_row [row i W]row_sum_delta val_gen_sum. apply: eq_bigr => /= j _ /[1!mxE]; move: {W i}(W i j) => x. have ->: x = \sum_k gen (val x 0 k) * inFA (delta_mx 0 k). case: x => u; apply: mxval_inj; rewrite {1}[u]row_sum_delta. rewrite mxval_sum [mxval _]horner_rVpoly mulmx_suml linear_sum /=. apply: eq_bigr => k _; rewrite mxvalM genK [mxval _]horner_rVpoly /=. by rewrite mul_scalar_mx -scalemxAl linearZ. rewrite scaler_suml val_gen_sum mxval_sum linear_sum; apply: eq_bigr => k _. rewrite mxvalM genK mul_scalar_mx linearZ [mxval _]horner_rVpoly /=. rewrite -scalerA; apply: (canLR in_genK); rewrite in_genZ; congr (_ *: _). apply: (canRL val_genK); transitivity (row (mxvec_index j k) base); last first. by rewrite -rowE rowK mxvecE mxE rowK mxvecK. rewrite rowE -mxvec_delta -[val_gen _](row_id 0) rowK /=; congr (mxvec _ *m _). apply/row_matrixP=> j'; rewrite rowK !mxE mulr_natr rowE mul_delta_mx_cond. by rewrite !mulrb (fun_if rVval). Qed. Lemma val_genZ x : {morph @val_gen m : W / x *: W >-> W *m mxval x}. Proof. move=> W; apply/row_matrixP=> i; rewrite row_mul !row_gen_sum_mxval. by rewrite mulmx_suml; apply: eq_bigr => j _; rewrite mxE mulrC mxvalM row_mul. Qed. End Bijection2. Lemma submx_in_gen m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, n)) : (U <= V -> in_gen U <= in_gen V)%MS. Proof. move=> sUV; apply/row_subP=> i; rewrite -in_gen_row. case/submxP: (row_subP sUV i) => u ->{i}. rewrite mulmx_sum_row in_gen_sum summx_sub // => j _. by rewrite in_genZ in_gen_row scalemx_sub ?row_sub. Qed. Lemma submx_in_gen_eq m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, n)) : (V *m A <= V -> (in_gen U <= in_gen V) = (U <= V))%MS. Proof. move=> sVA_V; apply/idP/idP=> siUV; last exact: submx_in_gen. apply/row_subP=> i; rewrite -[row i U]in_genK in_gen_row. case/submxP: (row_subP siUV i) => u ->{i U siUV}. rewrite mulmx_sum_row val_gen_sum summx_sub // => j _. rewrite val_genZ val_gen_row in_genK rowE -mulmxA mulmx_sub //. rewrite [mxval _]horner_poly mulmx_sumr summx_sub // => [[k _]] _ /=. rewrite mulmxA mul_mx_scalar -scalemxAl scalemx_sub {u j}//. elim: k => [|k IHk]; first by rewrite mulmx1. by rewrite exprSr mulmxA (submx_trans (submxMr A IHk)). Qed. Definition gen_mx g := \matrix_i in_gen (row (gen_base 0 i) (rG g)). Let val_genJmx m : {in G, forall g, {morph @val_gen m : W / W *m gen_mx g >-> W *m rG g}}. Proof. move=> g Gg /= W; apply/row_matrixP=> i; rewrite -val_gen_row !row_mul. rewrite mulmx_sum_row val_gen_sum row_gen_sum_mxval mulmx_suml. apply: eq_bigr => /= j _; rewrite val_genZ rowK in_genK mxE -!row_mul. by rewrite (centgmxP (mxval_centg _)). Qed. Lemma gen_mx_repr : mx_repr G gen_mx. Proof. split=> [|g h Gg Gh]; apply: (can_inj val_genK). by rewrite -[gen_mx 1]mul1mx val_genJmx // repr_mx1 mulmx1. rewrite {1}[val_gen]lock -[gen_mx g]mul1mx !val_genJmx // -mulmxA -repr_mxM //. by rewrite -val_genJmx ?groupM ?mul1mx -?lock. Qed. Canonical gen_repr := MxRepresentation gen_mx_repr. Local Notation rGA := gen_repr. Lemma val_genJ m : {in G, forall g, {morph @val_gen m : W / W *m rGA g >-> W *m rG g}}. Proof. exact: val_genJmx. Qed. Lemma in_genJ m : {in G, forall g, {morph @in_gen m : v / v *m rG g >-> v *m rGA g}}. Proof. by move=> g Gg /= v; apply: (canLR val_genK); rewrite val_genJ ?in_genK. Qed. Lemma rfix_gen (H : {set gT}) : H \subset G -> (rfix_mx rGA H :=: in_gen (rfix_mx rG H))%MS. Proof. move/subsetP=> sHG; apply/eqmxP/andP; split; last first. by apply/rfix_mxP=> g Hg; rewrite -in_genJ ?sHG ?rfix_mx_id. rewrite -[rfix_mx rGA H]val_genK; apply: submx_in_gen. by apply/rfix_mxP=> g Hg; rewrite -val_genJ ?rfix_mx_id ?sHG. Qed. Definition rowval_gen m U := <<\matrix_ik mxvec (\matrix_(i < m, k < d) (row i (val_gen U) *m A ^+ k)) 0 ik>>%MS. Lemma submx_rowval_gen m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, nA)) : (U <= rowval_gen V)%MS = (in_gen U <= V)%MS. Proof. rewrite genmxE; apply/idP/idP=> sUV. apply: submx_trans (submx_in_gen sUV) _. apply/row_subP; case/mxvec_indexP=> i k; rewrite -in_gen_row rowK mxvecE mxE. rewrite -mxval_grootXn -val_gen_row -val_genZ val_genK scalemx_sub //. exact: row_sub. rewrite -[U]in_genK; case/submxP: sUV => u ->{U}. apply/row_subP=> i0; rewrite -val_gen_row row_mul; move: {i0 u}(row _ u) => u. rewrite mulmx_sum_row val_gen_sum summx_sub // => i _. rewrite val_genZ [mxval _]horner_rVpoly [_ *m Ad]mulmx_sum_row. rewrite !linear_sum summx_sub // => k _. rewrite 2!linearZ scalemx_sub {u}//= rowK mxvecK val_gen_row. by apply: (eq_row_sub (mxvec_index i k)); rewrite rowK mxvecE mxE. Qed. Lemma rowval_genK m (U : 'M_(m, nA)) : (in_gen (rowval_gen U) :=: U)%MS. Proof. apply/eqmxP; rewrite -submx_rowval_gen submx_refl /=. by rewrite -{1}[U]val_genK submx_in_gen // submx_rowval_gen val_genK. Qed. Lemma rowval_gen_stable m (U : 'M_(m, nA)) : (rowval_gen U *m A <= rowval_gen U)%MS. Proof. rewrite -[A]mxval_groot -{1}[_ U]in_genK -val_genZ. by rewrite submx_rowval_gen val_genK scalemx_sub // rowval_genK. Qed. Lemma rstab_in_gen m (U : 'M_(m, n)) : rstab rGA (in_gen U) = rstab rG U. Proof. apply/setP=> x /[!inE]; case Gx: (x \in G) => //=. by rewrite -in_genJ // (inj_eq (can_inj in_genK)). Qed. Lemma rstabs_in_gen m (U : 'M_(m, n)) : rstabs rG U \subset rstabs rGA (in_gen U). Proof. by apply/subsetP=> x /[!inE] /andP[Gx nUx]; rewrite -in_genJ Gx // submx_in_gen. Qed. Lemma rstabs_rowval_gen m (U : 'M_(m, nA)) : rstabs rG (rowval_gen U) = rstabs rGA U. Proof. apply/setP=> x /[!inE]; case Gx: (x \in G) => //=. by rewrite submx_rowval_gen in_genJ // (eqmxMr _ (rowval_genK U)). Qed. Lemma mxmodule_rowval_gen m (U : 'M_(m, nA)) : mxmodule rG (rowval_gen U) = mxmodule rGA U. Proof. by rewrite /mxmodule rstabs_rowval_gen. Qed. Lemma gen_mx_irr : mx_irreducible rGA. Proof. apply/mx_irrP; split=> [|U Umod nzU]; first exact: gen_dim_gt0. rewrite -sub1mx -rowval_genK -submx_rowval_gen submx_full //. case/mx_irrP: irrG => _; apply; first by rewrite mxmodule_rowval_gen. rewrite -(inj_eq (can_inj in_genK)) in_gen0. by rewrite -mxrank_eq0 rowval_genK mxrank_eq0. Qed. Lemma rker_gen : rker rGA = rker rG. Proof. apply/setP=> g; rewrite !inE !mul1mx; case Gg: (g \in G) => //=. apply/eqP/eqP=> g1; apply/row_matrixP=> i. by apply: (can_inj in_genK); rewrite rowE in_genJ //= g1 mulmx1 row1. by apply: (can_inj val_genK); rewrite rowE val_genJ //= g1 mulmx1 row1. Qed. Lemma gen_mx_faithful : mx_faithful rGA = mx_faithful rG. Proof. by rewrite /mx_faithful rker_gen. Qed. End GenField. Section DecideGenField. Import MatrixFormula. Variable F : decFieldType. Local Notation False := GRing.False. Local Notation True := GRing.True. Local Notation Bool b := (GRing.Bool b%bool). Local Notation term := (GRing.term F). Local Notation form := (GRing.formula F). Local Notation morphAnd f := ((big_morph f) true andb). Variables (gT : finGroupType) (G : {group gT}) (n' : nat). Local Notation n := n'.+1. Variables (rG : mx_representation F G n) (A : 'M[F]_n). Hypotheses (irrG : mx_irreducible rG) (cGA : centgmx rG A). Local Notation FA := (gen_of irrG cGA). Local Notation inFA := (Gen irrG cGA). Local Notation d := (degree_mxminpoly A). Let d_gt0 : d > 0 := mxminpoly_nonconstant A. Local Notation Ad := (powers_mx A d). Let mxT (u : 'rV_d) := vec_mx (mulmx_term u (mx_term Ad)). Let eval_mxT e u : eval_mx e (mxT u) = mxval (inFA (eval_mx e u)). Proof. by rewrite eval_vec_mx eval_mulmx eval_mx_term [mxval _]horner_rVpoly. Qed. Let Ad'T := mx_term (pinvmx Ad). Let mulT (u v : 'rV_d) := mulmx_term (mxvec (mulmx_term (mxT u) (mxT v))) Ad'T. Lemma eval_mulT e u v : eval_mx e (mulT u v) = val (inFA (eval_mx e u) * inFA (eval_mx e v)). Proof. rewrite !(eval_mulmx, eval_mxvec) !eval_mxT eval_mx_term. by apply: (can_inj rVpolyK); rewrite -mxvalM [rVpoly _]horner_rVpolyK. Qed. Fixpoint gen_term t := match t with | 'X_k => row_var _ d k | x%:T => mx_term (val (x : FA)) | n1%:R => mx_term (val (n1%:R : FA))%R | t1 + t2 => \row_i (gen_term t1 0%R i + gen_term t2 0%R i) | - t1 => \row_i (- gen_term t1 0%R i) | t1 *+ n1 => mulmx_term (mx_term n1%:R%:M)%R (gen_term t1) | t1 * t2 => mulT (gen_term t1) (gen_term t2) | t1^-1 => gen_term t1 | t1 ^+ n1 => iter n1 (mulT (gen_term t1)) (mx_term (val (1%R : FA))) end%T. Definition gen_env (e : seq FA) := row_env (map val e). Lemma nth_map_rVval (e : seq FA) j : (map val e)`_j = val e`_j. Proof. case: (ltnP j (size e)) => [| leej]; first exact: (nth_map 0 0). by rewrite !nth_default ?size_map. Qed. Lemma set_nth_map_rVval (e : seq FA) j v : set_nth 0 (map val e) j v = map val (set_nth 0 e j (inFA v)). Proof. apply: (@eq_from_nth _ 0) => [|k _]; first by rewrite !(size_set_nth, size_map). by rewrite !(nth_map_rVval, nth_set_nth) /= nth_map_rVval [rVval _]fun_if. Qed. Lemma eval_gen_term e t : GRing.rterm t -> eval_mx (gen_env e) (gen_term t) = val (GRing.eval e t). Proof. elim: t => //=. - by move=> k _; apply/rowP=> i; rewrite !mxE /= nth_row_env nth_map_rVval. - by move=> x _; rewrite eval_mx_term. - by move=> x _; rewrite eval_mx_term. - by move=> t1 + t2 + /andP[rt1 rt2] => <-// <-//; apply/rowP => k /[!mxE]. - by move=> t1 + rt1 => <-//; apply/rowP=> k /[!mxE]. - move=> t1 IH1 n1 rt1; rewrite eval_mulmx eval_mx_term mul_scalar_mx. by rewrite scaler_nat {}IH1 //; elim: n1 => //= n1 IHn1; rewrite !mulrS IHn1. - by move=> t1 IH1 t2 IH2 /andP[rt1 rt2]; rewrite eval_mulT IH1 ?IH2. move=> t1 + n1 => /[apply] IH1. elim: n1 => [|n1 IHn1] /=; first by rewrite eval_mx_term. by rewrite eval_mulT exprS IH1 IHn1. Qed. Fixpoint gen_form f := match f with | Bool b => Bool b | t1 == t2 => mxrank_form 0 (gen_term (t1 - t2)) | GRing.Unit t1 => mxrank_form 1 (gen_term t1) | f1 /\ f2 => gen_form f1 /\ gen_form f2 | f1 \/ f2 => gen_form f1 \/ gen_form f2 | f1 ==> f2 => gen_form f1 ==> gen_form f2 | ~ f1 => ~ gen_form f1 | ('exists 'X_k, f1) => Exists_row_form d k (gen_form f1) | ('forall 'X_k, f1) => ~ Exists_row_form d k (~ (gen_form f1)) end%T. Lemma sat_gen_form e f : GRing.rformula f -> reflect (GRing.holds e f) (GRing.sat (gen_env e) (gen_form f)). Proof. have ExP := Exists_rowP; have set_val := set_nth_map_rVval. elim: f e => //. - by move=> b e _; apply: (iffP satP). - rewrite /gen_form => t1 t2 e rt_t; set t := (_ - _)%T. have:= GRing.qf_evalP (gen_env e) (mxrank_form_qf 0 (gen_term t)). rewrite eval_mxrank mxrank_eq0 eval_gen_term // => tP. by rewrite (sameP satP tP) /= subr_eq0 val_eqE; apply: eqP. - move=> f1 IH1 f2 IH2 s /= /andP[/(IH1 s)f1P /(IH2 s)f2P]. by apply: (iffP satP) => [[/satP/f1P ? /satP/f2P] | [/f1P/satP ? /f2P/satP]]. - move=> f1 IH1 f2 IH2 s /= /andP[/(IH1 s)f1P /(IH2 s)f2P]. by apply: (iffP satP) => /= [] []; try move/satP; do [move/f1P | move/f2P]; try move/satP; auto. - move=> f1 IH1 f2 IH2 s /= /andP[/(IH1 s)f1P /(IH2 s)f2P]. by apply: (iffP satP) => /= implP; try move/satP; move/f1P; try move/satP; move/implP; try move/satP; move/f2P; try move/satP. - move=> f1 IH1 s /= /(IH1 s) f1P. by apply: (iffP satP) => /= notP; try move/satP; move/f1P; try move/satP. - move=> k f1 IHf1 s /IHf1 f1P; apply: (iffP satP) => /= [|[[v f1v]]]. by case/ExP=> // x /satP; rewrite set_val => /f1P; exists (inFA x). by apply/ExP=> //; exists v; rewrite set_val; apply/satP/f1P. move=> i f1 IHf1 s /IHf1 f1P; apply: (iffP satP) => /= allf1 => [[v]|]. apply/f1P; case: satP => // notf1x; case: allf1; apply/ExP=> //. by exists v; rewrite set_val. by case/ExP=> //= v []; apply/satP; rewrite set_val; apply/f1P. Qed. Definition gen_sat e f := GRing.sat (gen_env e) (gen_form (GRing.to_rform f)). (* FIXME : why this MathCompCompatDecidableField *) Lemma gen_satP : GRing.MathCompCompatDecidableField.DecidableField.axiom gen_sat. Proof. move=> e f; have [tor rto] := GRing.to_rformP e f. exact: (iffP (sat_gen_form e (GRing.to_rform_rformula f))). Qed. #[export] HB.instance Definition _ := GRing.Field_isDecField.Build FA gen_satP. End DecideGenField. Section FiniteGenField. Variables (F : finFieldType) (gT : finGroupType) (G : {group gT}) (n' : nat). Local Notation n := n'.+1. Variables (rG : mx_representation F G n) (A : 'M[F]_n). Hypotheses (irrG : mx_irreducible rG) (cGA : centgmx rG A). Notation FA := (gen_of irrG cGA). #[export] HB.instance Definition _ := [Finite of FA by <:]. #[export] HB.instance Definition _ := [finGroupMixin of FA for +%R]. Lemma card_gen : #|{:FA}| = (#|F| ^ degree_mxminpoly A)%N. Proof. by rewrite card_sub card_mx mul1n. Qed. End FiniteGenField. End MatrixGenField. Module MatrixGenFieldExports. HB.reexport. End MatrixGenFieldExports. Export MatrixGenFieldExports. Bind Scope ring_scope with gen_of. Arguments rVval {F gT G%_G n'%_N rG A%_R irrG cGA} x%_R : rename. Prenex Implicits gen_of Gen rVval pval mxval gen groot. Arguments subbase {F n'} A {nA}. Prenex Implicits gen_dim gen_base base val_gen gen_mx rowval_gen. Arguments in_gen {F gT G n' rG A} irrG cGA {m} W. Arguments in_genK {F gT G n' rG A} irrG cGA {m} W : rename. Arguments val_genK {F gT G n' rG A irrG cGA m} W : rename. Prenex Implicits gen_env gen_term gen_form gen_sat. (* Classical splitting and closure field constructions provide convenient *) (* packaging for the pointwise construction. *) Section BuildSplittingField. Implicit Type gT : finGroupType. Implicit Type F : fieldType. Lemma group_splitting_field_exists gT (G : {group gT}) F : classically {Fs : fieldType & {rmorphism F -> Fs} & group_splitting_field Fs G}. Proof. move: F => F0 [] // nosplit; pose nG := #|G|; pose aG F := regular_repr F G. pose m := nG.+1; pose F := F0; pose U : seq 'M[F]_nG := [::]. suffices: size U + m <= nG by rewrite ltnn. have: mx_subseries (aG F) U /\ path ltmx 0 U by []. pose f : {rmorphism F0 -> F} := idfun. elim: m F U f => [|m IHm] F U f [modU ltU]. by rewrite addn0 (leq_trans (max_size_mx_series ltU)) ?rank_leq_row. rewrite addnS ltnNge -implybF; apply/implyP=> le_nG_Um; apply: nosplit. exists F => //; case=> [|n] rG irrG; first by case/mx_irrP: irrG. apply/idPn=> nabsG; pose cG := ('C(enveloping_algebra_mx rG))%MS. have{nabsG} [A]: exists2 A, (A \in cG)%MS & ~~ is_scalar_mx A. apply/has_non_scalar_mxP; rewrite ?scalar_mx_cent // ltnNge. by apply: contra nabsG; apply: cent_mx_scalar_abs_irr. rewrite {cG}memmx_cent_envelop -mxminpoly_linear_is_scalar -ltnNge => cGA. move/(non_linear_gen_reducible irrG cGA). (* FIXME: _ matches a generated constant *) set F' := _ irrG cGA; set rG' := @map_repr _ F' _ _ _ _ rG. move: F' (gen _ _ : {rmorphism F -> F'}) => F' f' in rG' * => irrG'. pose U' := [seq map_mx f' Ui | Ui <- U]. have modU': mx_subseries (aG F') U'. apply: etrans modU; rewrite /mx_subseries all_map; apply: eq_all => Ui. rewrite -(mxmodule_map f'); apply: eq_subset_r => x. by rewrite !inE map_regular_repr. case: notF; apply: (mx_Schreier modU ltU) => [[V [compV lastV sUV]]]. have{lastV} [] := rsim_regular_series irrG compV lastV. have{sUV} defV: V = U. apply/eqP; rewrite eq_sym -(geq_leqif (size_subseq_leqif sUV)). rewrite -(leq_add2r m); apply: leq_trans le_nG_Um. by apply: IHm f _; rewrite (mx_series_lt compV); case: compV. rewrite {V}defV in compV * => i rsimVi. apply: (mx_Schreier modU') => [|[V' [compV' _ sUV']]]. rewrite {modU' compV modU i le_nG_Um rsimVi}/U' -(map_mx0 f'). by apply: etrans ltU; elim: U 0 => //= Ui U IHU Ui'; rewrite IHU map_ltmx. have{sUV'} defV': V' = U'; last rewrite {V'}defV' in compV'. apply/eqP; rewrite eq_sym -(geq_leqif (size_subseq_leqif sUV')) size_map. rewrite -(leq_add2r m); apply: leq_trans le_nG_Um. apply: IHm (f' \o f) _. by rewrite (mx_series_lt compV'); case: compV'. suffices{irrG'}: mx_irreducible rG' by case/mxsimpleP=> _ _ []. have ltiU': i < size U' by rewrite size_map. apply: mx_rsim_irr (mx_rsim_sym _ ) (mx_series_repr_irr compV' ltiU'). by apply: mx_rsim_trans (mx_rsim_map f' rsimVi) _; apply: map_regular_subseries. Qed. Lemma group_closure_field_exists gT F : classically {Fs : fieldType & {rmorphism F -> Fs} & group_closure_field Fs gT}. Proof. set n := #|{group gT}|. suffices: classically {Fs : fieldType & {rmorphism F -> Fs} & forall G : {group gT}, enum_rank G < n -> group_splitting_field Fs G}. - apply: classic_bind => [[Fs f splitFs]] _ -> //. by exists Fs => // G; apply: splitFs. elim: (n) => [|i IHi]; first by move=> _ -> //; exists F => //; exists id. apply: classic_bind IHi => [[F' f splitF']]. have [le_n_i _ -> // | lt_i_n] := leqP n i. by exists F' => // G _; apply: splitF'; apply: leq_trans le_n_i. have:= @group_splitting_field_exists _ (enum_val (Ordinal lt_i_n)) F'. apply: classic_bind => [[Fs f' splitFs]] _ -> //. exists Fs => [|G]; first exact: (f' \o f). rewrite ltnS leq_eqVlt -{1}[i]/(val (Ordinal lt_i_n)) val_eqE. case/predU1P=> [defG | ltGi]; first by rewrite -[G]enum_rankK defG. by apply: (extend_group_splitting_field f'); apply: splitF'. Qed. Lemma group_closure_closed_field (F : closedFieldType) gT : group_closure_field F gT. Proof. move=> G [|n] rG irrG; first by case/mx_irrP: irrG. apply: cent_mx_scalar_abs_irr => //; rewrite leqNgt. apply/(has_non_scalar_mxP (scalar_mx_cent _ _)) => [[A cGA nscalA]]. have [a]: exists a, eigenvalue A a. pose P := mxminpoly A; pose d := degree_mxminpoly A. have Pd1: P`_d = 1. by rewrite -(eqP (mxminpoly_monic A)) /lead_coef size_mxminpoly. have d_gt0: d > 0 := mxminpoly_nonconstant A. have [a def_ad] := solve_monicpoly (nth 0 (- P)) d_gt0. exists a; rewrite eigenvalue_root_min -/P /root -oppr_eq0 -hornerN. rewrite horner_coef size_polyN size_mxminpoly -/d big_ord_recr -def_ad. by rewrite coefN Pd1 mulN1r /= subrr. case/negP; rewrite kermx_eq0 row_free_unit (mx_Schur irrG) ?subr_eq0 //. by rewrite -memmx_cent_envelop -raddfN linearD addmx_sub ?scalar_mx_cent. by apply: contraNneq nscalA => ->; exact: scalar_mx_is_scalar. Qed. End BuildSplittingField.
ssrbool.v
From mathcomp Require Import ssreflect ssrfun. From Corelib Require Export ssrbool. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. (**********************) (* not yet backported *) (**********************) Lemma homo_mono1 [aT rT : Type] [f : aT -> rT] [g : rT -> aT] [aP : pred aT] [rP : pred rT] : cancel g f -> {homo f : x / aP x >-> rP x} -> {homo g : x / rP x >-> aP x} -> {mono g : x / rP x >-> aP x}. Proof. by move=> gK fP gP x; apply/idP/idP => [/fP|/gP//]; rewrite gK. Qed. Lemma if_and b1 b2 T (x y : T) : (if b1 && b2 then x else y) = (if b1 then if b2 then x else y else y). Proof. by case: b1 b2 => [] []. Qed. Lemma if_or b1 b2 T (x y : T) : (if b1 || b2 then x else y) = (if b1 then x else if b2 then x else y). Proof. by case: b1 b2 => [] []. Qed. Lemma if_implyb b1 b2 T (x y : T) : (if b1 ==> b2 then x else y) = (if b1 then if b2 then x else y else x). Proof. by case: b1 b2 => [] []. Qed. Lemma if_implybC b1 b2 T (x y : T) : (if b1 ==> b2 then x else y) = (if b2 then x else if b1 then y else x). Proof. by case: b1 b2 => [] []. Qed. Lemma if_add b1 b2 T (x y : T) : (if b1 (+) b2 then x else y) = (if b1 then if b2 then y else x else if b2 then x else y). Proof. by case: b1 b2 => [] []. Qed. Lemma relpre_trans {T' T : Type} {leT : rel T} {f : T' -> T} : transitive leT -> transitive (relpre f leT). Proof. by move=> + y x z; apply. Qed.
ExactSequence.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.Exact import Mathlib.CategoryTheory.ComposableArrows /-! # Exact sequences A sequence of `n` composable arrows `S : ComposableArrows C` (i.e. a functor `S : Fin (n + 1) ⥤ C`) is said to be exact (`S.Exact`) if the composition of two consecutive arrows are zero (`S.IsComplex`) and the diagram is exact at each `i` for `1 ≤ i < n`. Together with the inductive construction of composable arrows `ComposableArrows.precomp`, this is useful in order to state that certain finite sequences of morphisms are exact (e.g the snake lemma), even though in the applications it would usually be more convenient to use individual lemmas expressing the exactness at a particular object. This implementation is a refactor of `exact_seq` with appeared in the Liquid Tensor Experiment as a property of lists in `Arrow C`. -/ namespace CategoryTheory open Limits variable {C : Type*} [Category C] [HasZeroMorphisms C] /-- The composable arrows associated to a short complex. -/ @[simps!] def ShortComplex.toComposableArrows (S : ShortComplex C) : ComposableArrows C 2 := ComposableArrows.mk₂ S.f S.g /-- A map of short complexes induces a map of composable arrows with the same data. -/ def ShortComplex.mapToComposableArrows {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) : S₁.toComposableArrows ⟶ S₂.toComposableArrows := ComposableArrows.homMk₂ φ.τ₁ φ.τ₂ φ.τ₃ φ.comm₁₂.symm φ.comm₂₃.symm @[simp] theorem ShortComplex.mapToComposableArrows_app_0 {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) : (ShortComplex.mapToComposableArrows φ).app 0 = φ.τ₁ := rfl @[simp] theorem ShortComplex.mapToComposableArrows_app_1 {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) : (ShortComplex.mapToComposableArrows φ).app 1 = φ.τ₂ := rfl @[simp] theorem ShortComplex.mapToComposableArrows_app_2 {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) : (ShortComplex.mapToComposableArrows φ).app 2 = φ.τ₃ := rfl @[simp] theorem ShortComplex.mapToComposableArrows_id {S₁ : ShortComplex C} : (ShortComplex.mapToComposableArrows (𝟙 S₁)) = 𝟙 S₁.toComposableArrows := by cat_disch @[simp] theorem ShortComplex.mapToComposableArrows_comp {S₁ S₂ S₃ : ShortComplex C} (φ : S₁ ⟶ S₂) (ψ : S₂ ⟶ S₃) : ShortComplex.mapToComposableArrows (φ ≫ ψ) = ShortComplex.mapToComposableArrows φ ≫ ShortComplex.mapToComposableArrows ψ := by cat_disch namespace ComposableArrows variable {n : ℕ} (S : ComposableArrows C n) /-- `F : ComposableArrows C n` is a complex if all compositions of two consecutive arrows are zero. -/ structure IsComplex : Prop where /-- the composition of two consecutive arrows is zero -/ zero (i : ℕ) (hi : i + 2 ≤ n := by omega) : S.map' i (i + 1) ≫ S.map' (i + 1) (i + 2) = 0 attribute [reassoc] IsComplex.zero variable {S} @[reassoc] lemma IsComplex.zero' (hS : S.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : S.map' i j ≫ S.map' j k = 0 := by subst hij hjk exact hS.zero i hk lemma isComplex_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.IsComplex) : S₂.IsComplex where zero i hi := by rw [← cancel_epi (ComposableArrows.app' e.hom i), comp_zero, ← NatTrans.naturality_assoc, ← NatTrans.naturality, reassoc_of% (h₁.zero i hi), zero_comp] lemma isComplex_iff_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) : S₁.IsComplex ↔ S₂.IsComplex := ⟨isComplex_of_iso e, isComplex_of_iso e.symm⟩ lemma isComplex₀ (S : ComposableArrows C 0) : S.IsComplex where -- See https://github.com/leanprover/lean4/issues/2862 -- Without `decide := true`, simp gets stuck at `hi : autoParam False _auto✝` zero i hi := by simp +decide at hi lemma isComplex₁ (S : ComposableArrows C 1) : S.IsComplex where zero i hi := by omega variable (S) /-- The short complex consisting of maps `S.map' i j` and `S.map' j k` when we know that `S : ComposableArrows C n` satisfies `S.IsComplex`. -/ abbrev sc' (hS : S.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : ShortComplex C := ShortComplex.mk (S.map' i j) (S.map' j k) (hS.zero' i j k) /-- The short complex consisting of maps `S.map' i (i + 1)` and `S.map' (i + 1) (i + 2)` when we know that `S : ComposableArrows C n` satisfies `S.IsComplex`. -/ abbrev sc (hS : S.IsComplex) (i : ℕ) (hi : i + 2 ≤ n := by omega) : ShortComplex C := S.sc' hS i (i + 1) (i + 2) /-- `F : ComposableArrows C n` is exact if it is a complex and that all short complexes consisting of two consecutive arrows are exact. -/ structure Exact : Prop extends S.IsComplex where exact (i : ℕ) (hi : i + 2 ≤ n := by omega) : (S.sc toIsComplex i).Exact variable {S} lemma Exact.exact' (hS : S.Exact) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : (S.sc' hS.toIsComplex i j k).Exact := by subst hij hjk exact hS.exact i hk /-- Functoriality maps for `ComposableArrows.sc'`. -/ @[simps] def sc'Map {S₁ S₂ : ComposableArrows C n} (φ : S₁ ⟶ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : S₁.sc' h₁ i j k ⟶ S₂.sc' h₂ i j k where τ₁ := φ.app _ τ₂ := φ.app _ τ₃ := φ.app _ /-- Functoriality maps for `ComposableArrows.sc`. -/ @[simps!] def scMap {S₁ S₂ : ComposableArrows C n} (φ : S₁ ⟶ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i : ℕ) (hi : i + 2 ≤ n := by omega) : S₁.sc h₁ i ⟶ S₂.sc h₂ i := sc'Map φ h₁ h₂ i (i + 1) (i + 2) /-- The isomorphism `S₁.sc' _ i j k ≅ S₂.sc' _ i j k` induced by an isomorphism `S₁ ≅ S₂` in `ComposableArrows C n`. -/ @[simps] def sc'MapIso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : S₁.sc' h₁ i j k ≅ S₂.sc' h₂ i j k where hom := sc'Map e.hom h₁ h₂ i j k inv := sc'Map e.inv h₂ h₁ i j k hom_inv_id := by ext <;> simp inv_hom_id := by ext <;> simp /-- The isomorphism `S₁.sc _ i ≅ S₂.sc _ i` induced by an isomorphism `S₁ ≅ S₂` in `ComposableArrows C n`. -/ @[simps] def scMapIso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i : ℕ) (hi : i + 2 ≤ n := by omega) : S₁.sc h₁ i ≅ S₂.sc h₂ i where hom := scMap e.hom h₁ h₂ i inv := scMap e.inv h₂ h₁ i hom_inv_id := by ext <;> simp inv_hom_id := by ext <;> simp lemma exact_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.Exact) : S₂.Exact where toIsComplex := isComplex_of_iso e h₁.toIsComplex exact i hi := ShortComplex.exact_of_iso (scMapIso e h₁.toIsComplex (isComplex_of_iso e h₁.toIsComplex) i) (h₁.exact i hi) lemma exact_iff_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) : S₁.Exact ↔ S₂.Exact := ⟨exact_of_iso e, exact_of_iso e.symm⟩ lemma exact₀ (S : ComposableArrows C 0) : S.Exact where toIsComplex := S.isComplex₀ -- See https://github.com/leanprover/lean4/issues/2862 exact i hi := by simp at hi lemma exact₁ (S : ComposableArrows C 1) : S.Exact where toIsComplex := S.isComplex₁ exact i hi := by exfalso; omega lemma isComplex₂_iff (S : ComposableArrows C 2) : S.IsComplex ↔ S.map' 0 1 ≫ S.map' 1 2 = 0 := by constructor · intro h exact h.zero 0 (by omega) · intro h refine IsComplex.mk (fun i hi => ?_) obtain rfl : i = 0 := by omega exact h lemma isComplex₂_mk (S : ComposableArrows C 2) (w : S.map' 0 1 ≫ S.map' 1 2 = 0) : S.IsComplex := S.isComplex₂_iff.2 w lemma _root_.CategoryTheory.ShortComplex.isComplex_toComposableArrows (S : ShortComplex C) : S.toComposableArrows.IsComplex := -- Disable `Fin.reduceFinMk` because otherwise `Precompose.map_one_succ` does not apply. (#27382) isComplex₂_mk _ (by simp [-Fin.reduceFinMk]) lemma exact₂_iff (S : ComposableArrows C 2) (hS : S.IsComplex) : S.Exact ↔ (S.sc' hS 0 1 2).Exact := by constructor · intro h exact h.exact 0 (by omega) · intro h refine Exact.mk hS (fun i hi => ?_) obtain rfl : i = 0 := by omega exact h lemma exact₂_mk (S : ComposableArrows C 2) (w : S.map' 0 1 ≫ S.map' 1 2 = 0) (h : (ShortComplex.mk _ _ w).Exact) : S.Exact := (S.exact₂_iff (S.isComplex₂_mk w)).2 h lemma _root_.CategoryTheory.ShortComplex.Exact.exact_toComposableArrows {S : ShortComplex C} (hS : S.Exact) : S.toComposableArrows.Exact := exact₂_mk _ _ hS lemma _root_.CategoryTheory.ShortComplex.exact_iff_exact_toComposableArrows (S : ShortComplex C) : S.Exact ↔ S.toComposableArrows.Exact := (S.toComposableArrows.exact₂_iff S.isComplex_toComposableArrows).symm lemma exact_iff_δ₀ (S : ComposableArrows C (n + 2)) : S.Exact ↔ (mk₂ (S.map' 0 1) (S.map' 1 2)).Exact ∧ S.δ₀.Exact := by constructor · intro h constructor · rw [exact₂_iff]; swap · rw [isComplex₂_iff] exact h.toIsComplex.zero 0 exact h.exact 0 (by omega) · exact Exact.mk (IsComplex.mk (fun i hi => h.toIsComplex.zero (i + 1))) (fun i hi => h.exact (i + 1)) · rintro ⟨h, h₀⟩ refine Exact.mk (IsComplex.mk (fun i hi => ?_)) (fun i hi => ?_) · obtain _ | i := i · exact h.toIsComplex.zero 0 · exact h₀.toIsComplex.zero i · obtain _ | i := i · exact h.exact 0 · exact h₀.exact i lemma Exact.δ₀ {S : ComposableArrows C (n + 2)} (hS : S.Exact) : S.δ₀.Exact := by rw [exact_iff_δ₀] at hS exact hS.2 /-- If `S : ComposableArrows C (n + 2)` is such that the first two arrows form an exact sequence and that the tail `S.δ₀` is exact, then `S` is also exact. See `ShortComplex.SnakeInput.snake_lemma` in `Algebra.Homology.ShortComplex.SnakeLemma` for a use of this lemma. -/ lemma exact_of_δ₀ {S : ComposableArrows C (n + 2)} (h : (mk₂ (S.map' 0 1) (S.map' 1 2)).Exact) (h₀ : S.δ₀.Exact) : S.Exact := by rw [exact_iff_δ₀] constructor <;> assumption lemma exact_iff_δlast {n : ℕ} (S : ComposableArrows C (n + 2)) : S.Exact ↔ S.δlast.Exact ∧ (mk₂ (S.map' n (n + 1)) (S.map' (n + 1) (n + 2))).Exact := by constructor · intro h constructor · exact Exact.mk (IsComplex.mk (fun i hi => h.toIsComplex.zero i)) (fun i hi => h.exact i) · rw [exact₂_iff]; swap · rw [isComplex₂_iff] exact h.toIsComplex.zero n exact h.exact n (by omega) · rintro ⟨h, h'⟩ refine Exact.mk (IsComplex.mk (fun i hi => ?_)) (fun i hi => ?_) · simp only [Nat.add_le_add_iff_right] at hi obtain hi | rfl := hi.lt_or_eq · exact h.toIsComplex.zero i · exact h'.toIsComplex.zero 0 · simp only [Nat.add_le_add_iff_right] at hi obtain hi | rfl := hi.lt_or_eq · exact h.exact i · exact h'.exact 0 lemma Exact.δlast {S : ComposableArrows C (n + 2)} (hS : S.Exact) : S.δlast.Exact := by rw [exact_iff_δlast] at hS exact hS.1 lemma exact_of_δlast {n : ℕ} (S : ComposableArrows C (n + 2)) (h₁ : S.δlast.Exact) (h₂ : (mk₂ (S.map' n (n + 1)) (S.map' (n + 1) (n + 2))).Exact) : S.Exact := by rw [exact_iff_δlast] constructor <;> assumption lemma Exact.isIso_map' {C : Type*} [Category C] [Preadditive C] [Balanced C] {n : ℕ} {S : ComposableArrows C n} (hS : S.Exact) (k : ℕ) (hk : k + 3 ≤ n) (h₀ : S.map' k (k + 1) = 0) (h₁ : S.map' (k + 2) (k + 3) = 0) : IsIso (S.map' (k + 1) (k + 2)) := by have := (hS.exact k).mono_g h₀ have := (hS.exact (k + 1)).epi_f h₁ apply isIso_of_mono_of_epi end ComposableArrows end CategoryTheory
GoingDown.lean
/- Copyright (c) 2025 Christian Merten, Yi Song, Sihan Su. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten, Yi Song, Sihan Su -/ import Mathlib.RingTheory.Ideal.GoingUp import Mathlib.RingTheory.Flat.FaithfullyFlat.Algebra import Mathlib.RingTheory.Flat.Localization import Mathlib.RingTheory.Spectrum.Prime.Topology /-! # Going down In this file we define a predicate `Algebra.HasGoingDown`: An `R`-algebra `S` satisfies `Algebra.HasGoingDown R S` if for every pair of prime ideals `p ≤ q` of `R` with `Q` a prime of `S` lying above `q`, there exists a prime `P ≤ Q` of `S` lying above `p`. ## Main results - `Algebra.HasGoingDown.iff_generalizingMap_primeSpectrumComap`: going down is equivalent to generalizations lifting along `Spec S → Spec R`. - `Algebra.HasGoingDown.of_flat`: flat algebras satisfy going down. ## TODOs - An integral extension of domains with normal base satisfies going down. -/ /-- An `R`-algebra `S` satisfies `Algebra.HasGoingDown R S` if for every pair of prime ideals `p ≤ q` of `R` with `Q` a prime of `S` lying above `q`, there exists a prime `P ≤ Q` of `S` lying above `p`. The condition only asks for `<` which is easier to prove, use `Ideal.exists_ideal_le_liesOver_of_le` for applying it. -/ @[stacks 00HV "(2)"] class Algebra.HasGoingDown (R S : Type*) [CommRing R] [CommRing S] [Algebra R S] : Prop where exists_ideal_le_liesOver_of_lt {p : Ideal R} [p.IsPrime] (Q : Ideal S) [Q.IsPrime] : p < Q.under R → ∃ P ≤ Q, P.IsPrime ∧ P.LiesOver p variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] lemma Ideal.exists_ideal_le_liesOver_of_le [Algebra.HasGoingDown R S] {p q : Ideal R} [p.IsPrime] [q.IsPrime] (Q : Ideal S) [Q.IsPrime] [Q.LiesOver q] (hle : p ≤ q) : ∃ P ≤ Q, P.IsPrime ∧ P.LiesOver p := by by_cases h : p = q · subst h use Q · have := Q.over_def q subst this exact Algebra.HasGoingDown.exists_ideal_le_liesOver_of_lt Q (lt_of_le_of_ne hle h) lemma Ideal.exists_ideal_lt_liesOver_of_lt [Algebra.HasGoingDown R S] {p q : Ideal R} [p.IsPrime] [q.IsPrime] (Q : Ideal S) [Q.IsPrime] [Q.LiesOver q] (hpq : p < q) : ∃ P < Q, P.IsPrime ∧ P.LiesOver p := by obtain ⟨P, hPQ, _, _⟩ := Q.exists_ideal_le_liesOver_of_le (p := p) (q := q) hpq.le refine ⟨P, ?_, inferInstance, inferInstance⟩ by_contra hc have : P = Q := eq_of_le_of_not_lt hPQ hc subst this simp [P.over_def p, P.over_def q] at hpq namespace Algebra.HasGoingDown variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] /-- An `R`-algebra `S` has the going down property if and only if generalizations lift along `Spec S → Spec R`. -/ @[stacks 00HW "(1)"] lemma iff_generalizingMap_primeSpectrumComap : Algebra.HasGoingDown R S ↔ GeneralizingMap (PrimeSpectrum.comap (algebraMap R S)) := by refine ⟨?_, fun h ↦ ⟨fun {p} hp Q hQ hlt ↦ ?_⟩⟩ · intro h Q p hp rw [← PrimeSpectrum.le_iff_specializes] at hp obtain ⟨P, hle, hP, h⟩ := Q.asIdeal.exists_ideal_le_liesOver_of_le (p := p.asIdeal) (q := Q.asIdeal.under R) hp refine ⟨⟨P, hP⟩, (PrimeSpectrum.le_iff_specializes _ Q).mp hle, ?_⟩ ext : 1 exact h.over.symm · have : (⟨p, hp⟩ : PrimeSpectrum R) ⤳ (PrimeSpectrum.comap (algebraMap R S) ⟨Q, hQ⟩) := (PrimeSpectrum.le_iff_specializes _ _).mp hlt.le obtain ⟨P, hs, heq⟩ := h this refine ⟨P.asIdeal, (PrimeSpectrum.le_iff_specializes _ _).mpr hs, P.2, ⟨?_⟩⟩ simpa [PrimeSpectrum.ext_iff] using heq.symm variable (R S) in @[stacks 00HX] lemma trans (T : Type*) [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T] [Algebra.HasGoingDown R S] [Algebra.HasGoingDown S T] : Algebra.HasGoingDown R T := by rw [iff_generalizingMap_primeSpectrumComap, IsScalarTower.algebraMap_eq R S T] simp only [PrimeSpectrum.comap_comp, ContinuousMap.coe_comp] apply GeneralizingMap.comp · rwa [← iff_generalizingMap_primeSpectrumComap] · rwa [← iff_generalizingMap_primeSpectrumComap] /-- If for every prime of `S`, the map `Spec Sₚ → Spec Rₚ` is surjective, the algebra satisfies going down. -/ lemma of_specComap_localRingHom_surjective (H : ∀ (P : Ideal S) [P.IsPrime], Function.Surjective (Localization.localRingHom (P.under R) P (algebraMap R S) rfl).specComap) : Algebra.HasGoingDown R S where exists_ideal_le_liesOver_of_lt {p} _ Q _ hlt := by let pl : Ideal (Localization.AtPrime <| Q.under R) := p.map (algebraMap R _) have : pl.IsPrime := Ideal.isPrime_map_of_isLocalizationAtPrime (Q.under R) hlt.le obtain ⟨⟨Pl, _⟩, hl⟩ := H Q ⟨pl, inferInstance⟩ refine ⟨Pl.under S, ?_, Ideal.IsPrime.under S Pl, ⟨?_⟩⟩ · exact (IsLocalization.AtPrime.orderIsoOfPrime _ Q ⟨Pl, inferInstance⟩).2.2 · replace hl : Pl.under _ = pl := by simpa using hl rw [Ideal.under_under, ← Ideal.under_under (B := (Localization.AtPrime <| Q.under R)) Pl, hl, Ideal.under_map_of_isLocalizationAtPrime (Q.under R) hlt.le] /-- Flat algebras satisfy the going down property. -/ @[stacks 00HS] instance of_flat [Module.Flat R S] : Algebra.HasGoingDown R S := by apply of_specComap_localRingHom_surjective intro P hP have : IsLocalHom (algebraMap (Localization.AtPrime <| P.under R) (Localization.AtPrime P)) := by rw [RingHom.algebraMap_toAlgebra] exact Localization.isLocalHom_localRingHom (P.under R) P (algebraMap R S) Ideal.LiesOver.over have : Module.FaithfullyFlat (Localization.AtPrime (P.under R)) (Localization.AtPrime P) := Module.FaithfullyFlat.of_flat_of_isLocalHom apply PrimeSpectrum.specComap_surjective_of_faithfullyFlat end Algebra.HasGoingDown
byContra.lean
-- tests for by_contra! tactic import Mathlib.Tactic.ByContra import Mathlib.Tactic.Rename import Mathlib.Tactic.Set import Mathlib.Algebra.Notation.Defs import Mathlib.Data.Nat.Basic import Mathlib.Order.Basic set_option autoImplicit true example (a b : ℕ) (foo : False) : a < b := by by_contra! guard_hyp this : b ≤ a exact foo example (a b : ℕ) (h : False) : a < b := by by_contra! foo revert foo; change b ≤ a → False; intro; exact h example (a b : ℕ) (h : False) : a < b := by by_contra! foo : ¬ a < b -- can avoid push_neg guard_hyp foo : ¬ a < b exact h example : 1 < 2 := by by_contra! guard_hyp this : 2 ≤ 1 contradiction example (_p : Prop) (bar : False) : ¬ ¬ ¬ ¬ ¬ ¬ P := by by_contra! foo : ¬ ¬ ¬ P -- normalises to ¬ P, as does ¬ (goal). guard_hyp foo : ¬ ¬ ¬ P exact bar example (_p : Prop) (bar : False) : ¬ ¬ ¬ ¬ ¬ ¬ P := by by_contra! : ¬ ¬ ¬ P guard_hyp this : ¬ ¬ ¬ P exact bar variable [LinearOrder α] [One α] [Mul α] example (x : α) (f : False) : x ≤ 1 := by set a := x * x by_contra! h guard_hyp h : 1 < x assumption example (x : α) (f : False) : x ≤ 1 := by let _a := x * x by_contra! h guard_hyp h : 1 < x assumption example (x : α) (f : False) : x ≤ 1 := by set a := x * x have : a ≤ a := le_rfl by_contra! h guard_hyp h : 1 < x assumption
fingroup.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 choice. From mathcomp Require Import fintype div path tuple bigop prime finset. From mathcomp Require Export monoid. (******************************************************************************) (* Finite groups *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* This file defines the main interface for finite groups: *) (* finGroupType == the structure for finite types with a group law *) (* The HB class is called FinGroup. *) (* {group gT} == type of groups with elements of type gT *) (* baseFinGroupType == the structure for finite types with a monoid law *) (* and an involutive antimorphism; finGroupType is *) (* derived from baseFinGroupType *) (* The HB class is called BaseFinGroup. *) (* FinGroupType mulVg == the finGroupType structure for an existing *) (* baseFinGroupType structure, built from a proof of *) (* the left inverse group axiom for that structure's *) (* operations *) (* [group of G] == a clone for an existing {group gT} structure on *) (* G : {set gT} (the existing structure might be for *) (* some delta-expansion of G) *) (* If gT implements finGroupType, then we can form {set gT}, the type of *) (* finite sets with elements of type gT (as finGroupType extends finType). *) (* The group law extends pointwise to {set gT}, which thus implements a sub- *) (* interface baseFinGroupType of finGroupType. To be consistent with the *) (* predType interface, this is done by coercion to FinGroup.arg_sort, an *) (* alias for FinGroup.sort. Accordingly, all pointwise group operations below *) (* have arguments of type (FinGroup.arg_sort) gT and return results of type *) (* FinGroup.sort gT. *) (* The notations below are declared in two scopes: *) (* group_scope (delimiter %g) for point operations and set constructs. *) (* Group_scope (delimiter %G) for explicit {group gT} structures. *) (* These scopes should not be opened globally, although group_scope is often *) (* opened locally in group-theory files (via Import GroupScope). *) (* As {group gT} is both a subtype and an interface structure for {set gT}, *) (* the fact that a given G : {set gT} is a group can (and usually should) be *) (* inferred by type inference with canonical structures. This means that all *) (* `group' constructions (e.g., the normaliser 'N_G(H)) actually define sets *) (* with a canonical {group gT} structure; the %G delimiter can be used to *) (* specify the actual {group gT} structure (e.g., 'N_G(H)%G). *) (* Operations on elements of a group: *) (* x * y == the group product of x and y *) (* x ^+ n == the nth power of x, i.e., x * ... * x (n times) *) (* x^-1 == the group inverse of x *) (* x ^- n == the inverse of x ^+ n (notation for (x ^+ n)^-1) *) (* 1 == the unit element *) (* x ^ y == the conjugate of x by y (i.e., y^-1 * (x * y)) *) (* [~ x, y] == the commutator of x and y (i.e., x^-1 * x ^ y) *) (* [~ x1, ..., xn] == the commutator of x1, ..., xn (associating left) *) (* \prod_(i ...) x i == the product of the x i (order-sensitive) *) (* commute x y <-> x and y commute *) (* centralises x A <-> x centralises A *) (* 'C[x] == the set of elements that commute with x *) (* 'C_G[x] == the set of elements of G that commute with x *) (* <[x]> == the cyclic subgroup generated by the element x *) (* #[x] == the order of the element x, i.e., #|<[x]>| *) (* Operations on subsets/subgroups of a finite group: *) (* H * G == {xy | x \in H, y \in G} *) (* 1 or [1] or [1 gT] == the unit group *) (* [set: gT]%G == the group of all x : gT (in Group_scope) *) (* group_set G == G contains 1 and is closed under binary product; *) (* this is the characteristic property of the *) (* {group gT} subtype of {set gT} *) (* [subg G] == the subtype, set, or group of all x \in G: this *) (* notation is defined simultaneously in %type, %g *) (* and %G scopes, and G must denote a {group gT} *) (* structure (G is in the %G scope) *) (* subg, sgval == the projection into and injection from [subg G] *) (* H^# == the set H minus the unit element *) (* repr H == some element of H if 1 \notin H != set0, else 1 *) (* (repr is defined over sets of a baseFinGroupType, *) (* so it can be used, e.g., to pick right cosets.) *) (* x *: H == left coset of H by x *) (* lcosets H G == the set of the left cosets of H by elements of G *) (* H :* x == right coset of H by x *) (* rcosets H G == the set of the right cosets of H by elements of G *) (* #|G : H| == the index of H in G, i.e., #|rcosets G H| *) (* H :^ x == the conjugate of H by x *) (* x ^: H == the conjugate class of x in H *) (* classes G == the set of all conjugate classes of G *) (* G :^: H == {G :^ x | x \in H} *) (* class_support G H == {x ^ y | x \in G, y \in H} *) (* commg_set G H == {[~ x, y] | x \in G, y \in H}; NOT the commutator! *) (* <<H>> == the subgroup generated by the set H *) (* [~: G, H] == the commmutator subgroup of G and H, i.e., *) (* <<commg_set G H>>> *) (* [~: H1, ..., Hn] == commutator subgroup of H1, ..., Hn (left assoc.) *) (* H <*> G == the subgroup generated by sets H and G (H join G) *) (* (H * G)%G == the join of G H : {group gT} (convertible, but not *) (* identical to (G <*> H)%G) *) (* (\prod_(i ...) H i)%G == the group generated by the H i *) (* {in G, centralised H} <-> G centralises H *) (* {in G, normalised H} <-> G normalises H *) (* <-> forall x, x \in G -> H :^ x = H *) (* 'N(H) == the normaliser of H *) (* 'N_G(H) == the normaliser of H in G *) (* H <| G <=> H is a normal subgroup of G *) (* 'C(H) == the centraliser of H *) (* 'C_G(H) == the centraliser of H in G *) (* gcore H G == the largest subgroup of H normalised by G *) (* If H is a subgroup of G, this is the largest *) (* normal subgroup of G contained in H). *) (* abelian H <=> H is abelian *) (* subgroups G == the set of subgroups of G, i.e., the set of all *) (* H : {group gT} such that H \subset G *) (* In the notation below G is a variable that is bound in P. *) (* [max G | P] <=> G is the largest group such that P holds *) (* [max H of G | P] <=> H is the largest group G such that P holds *) (* [max G | P & Q] := [max G | P && Q], likewise [max H of G | P & Q] *) (* [min G | P] <=> G is the smallest group such that P holds *) (* [min G | P & Q] := [min G | P && Q], likewise [min H of G | P & Q] *) (* [min H of G | P] <=> H is the smallest group G such that P holds *) (* In addition to the generic suffixes described in ssrbool.v and finset.v, *) (* we associate the following suffixes to group operations: *) (* 1 - identity element, as in group1 : 1 \in G *) (* M - multiplication, as is invMg : (x * y)^-1 = y^-1 * x^-1 *) (* Also nat multiplication, for expgM : x ^+ (m * n) = x ^+ m ^+ n *) (* D - (nat) addition, for expgD : x ^+ (m + n) = x ^+ m * x ^+ n *) (* V - inverse, as in mulgV : x * x^-1 = 1 *) (* X - exponentiation, as in conjXg : (x ^+ n) ^ y = (x ^ y) ^+ n *) (* J - conjugation, as in orderJ : #[x ^ y] = #[x] *) (* R - commutator, as in conjRg : [~ x, y] ^ z = [~ x ^ z, y ^ z] *) (* Y - join, as in centY : 'C(G <*> H) = 'C(G) :&: 'C(H) *) (* We sometimes prefix these with an `s' to indicate a set-lifted operation, *) (* e.g., conjsMg : (A * B) :^ x = A :^ x * B :^ x. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope Group_scope. Delimit Scope Group_scope with G. (* This module can be imported to open the scope for group element *) (* operations locally to a file, without exporting the Open to *) (* clients of that file (as Open would do). *) Module GroupScope. Open Scope group_scope. End GroupScope. Import GroupScope. (* These are the operation notations introduced by this file. *) Reserved Notation "[ ~ x1 , x2 , .. , xn ]" (format "'[ ' [ ~ x1 , '/' x2 , '/' .. , '/' xn ] ']'"). Reserved Notation "[ 1 gT ]" (format "[ 1 gT ]"). Reserved Notation "[ 1 ]" (format "[ 1 ]"). Reserved Notation "[ 'subg' G ]" (format "[ 'subg' G ]"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "A ^#" (at level 3, format "A ^#"). Reserved Notation "A :^ x" (at level 35, right associativity). Reserved Notation "x ^: B" (at level 35, right associativity). Reserved Notation "A :^: B" (at level 35, right associativity). Reserved Notation "#| B : A |" (A at level 99, format "#| B : A |"). Reserved Notation "''N' ( A )" (format "''N' ( A )"). Reserved Notation "''N_' G ( A )" (G at level 2, format "''N_' G ( A )"). Reserved Notation "A <| B" (at level 70, no associativity). Reserved Notation "A <*> B" (at level 40, left associativity). Reserved Notation "[ ~: A1 , A2 , .. , An ]" (format "[ ~: '[' A1 , '/' A2 , '/' .. , '/' An ']' ]"). Reserved Notation "[ 'max' A 'of' G | gP ]" (format "[ '[hv' 'max' A 'of' G '/ ' | gP ']' ]"). Reserved Notation "[ 'max' G | gP ]" (format "[ '[hv' 'max' G '/ ' | gP ']' ]"). Reserved Notation "[ 'max' A 'of' G | gP & gQ ]" (format "[ '[hv' 'max' A 'of' G '/ ' | gP '/ ' & gQ ']' ]"). Reserved Notation "[ 'max' G | gP & gQ ]" (format "[ '[hv' 'max' G '/ ' | gP '/ ' & gQ ']' ]"). Reserved Notation "[ 'min' A 'of' G | gP ]" (format "[ '[hv' 'min' A 'of' G '/ ' | gP ']' ]"). Reserved Notation "[ 'min' G | gP ]" (format "[ '[hv' 'min' G '/ ' | gP ']' ]"). Reserved Notation "[ 'min' A 'of' G | gP & gQ ]" (format "[ '[hv' 'min' A 'of' G '/ ' | gP '/ ' & gQ ']' ]"). Reserved Notation "[ 'min' G | gP & gQ ]" (format "[ '[hv' 'min' G '/ ' | gP '/ ' & gQ ']' ]"). (* We split the group axiomatisation in two. We define a *) (* class of "base groups", which are basically monoids *) (* with an involutive antimorphism, from which we derive *) (* the class of groups proper. This allows us to reuse *) (* much of the group notation and algebraic axioms for *) (* group subsets, by defining a base group class on them. *) (* We use class/mixins here rather than telescopes to *) (* be able to interoperate with the type coercions. *) (* Another potential benefit (not exploited here) would *) (* be to define a class for infinite groups, which could *) (* share all of the algebraic laws. *) HB.mixin Record isMulBaseGroup G := { mulg_subdef : G -> G -> G; oneg_subdef : G; invg_subdef : G -> G; mulgA_subproof : associative mulg_subdef ; mul1g_subproof : left_id oneg_subdef mulg_subdef ; invgK_subproof : involutive invg_subdef ; invMg_subproof : {morph invg_subdef : x y / mulg_subdef x y >-> mulg_subdef y x} }. (* We want to use sort as a coercion class, both to infer *) (* argument scopes properly, and to allow groups and cosets to *) (* coerce to the base group of group subsets. *) (* However, the return type of group operations should NOT be a *) (* coercion class, since this would trump the real (head-normal) *) (* coercion class for concrete group types, thus spoiling the *) (* coercion of A * B to pred_sort in x \in A * B, or rho * tau to *) (* ffun and Funclass in (rho * tau) x, when rho tau : perm T. *) (* Therefore we define an alias of sort for argument types, and *) (* make it the default coercion FinGroup.base_type >-> Sortclass *) (* so that arguments of a functions whose parameters are of type, *) (* say, gT : finGroupType, can be coerced to the coercion class *) (* of arg_sort. Care should be taken, however, to declare the *) (* return type of functions and operators as FinGroup.sort gT *) (* rather than gT, e.g., mulg : gT -> gT -> FinGroup.sort gT. *) (* Note that since we do this here and in quotient.v for all the *) (* basic functions, the inferred return type should generally be *) (* correct. *) #[arg_sort, short(type="baseFinGroupType")] HB.structure Definition BaseFinGroup := { G of isMulBaseGroup G & Finite G }. Module BaseFinGroupExports. Bind Scope group_scope with BaseFinGroup.arg_sort. Bind Scope group_scope with BaseFinGroup.sort. End BaseFinGroupExports. HB.export BaseFinGroupExports. Module Notations. Section ElementOps. Variable T : baseFinGroupType. Notation rT := (BaseFinGroup.sort T). Definition oneg : rT := Eval unfold oneg_subdef in @oneg_subdef T. Definition mulg : T -> T -> rT := Eval unfold mulg_subdef in @mulg_subdef T. Definition invg : T -> rT := Eval unfold invg_subdef in @invg_subdef T. Definition expgn (x : T) n : rT := iterop n mulg x oneg. End ElementOps. Arguments expgn : simpl never. Notation "1" := (@oneg _) : group_scope. Notation "x1 * x2" := (mulg x1 x2) : group_scope. Notation "x ^-1" := (invg x) : group_scope. Notation "x ^+ n" := (expgn x n) : group_scope. Notation "x ^- n" := (x ^+ n)^-1 : group_scope. End Notations. HB.export Notations. HB.mixin Record BaseFinGroup_isGroup G of BaseFinGroup G := { mulVg_subproof : left_inverse (@oneg G) (@invg _) (@mulg _) }. #[short(type="finGroupType")] HB.structure Definition FinGroup := { G of BaseFinGroup_isGroup G & BaseFinGroup G }. Module FinGroupExports. Bind Scope group_scope with FinGroup.sort. End FinGroupExports. HB.export FinGroupExports. HB.factory Record isMulGroup G of Finite G := { mulg : G -> G -> G; oneg : G; invg : G -> G; mulgA : associative mulg; mul1g : left_id oneg mulg; mulVg : left_inverse oneg invg mulg; }. HB.builders Context G of isMulGroup G. Notation "1" := oneg. Infix "*" := mulg. Notation "x ^-1" := (invg x). Lemma mk_invgK : involutive invg. Proof. have mulV21 x: x^-1^-1 * 1 = x by rewrite -(mulVg x) mulgA mulVg mul1g. by move=> x; rewrite -[_ ^-1]mulV21 -(mul1g 1) mulgA !mulV21. Qed. Lemma mk_invMg : {morph invg : x y / x * y >-> y * x}. Proof. have mulgV x: x * x^-1 = 1 by rewrite -{1}[x]mk_invgK mulVg. move=> x y /=; rewrite -[y^-1 * _]mul1g -(mulVg (x * y)) -2!mulgA (mulgA y). by rewrite mulgV mul1g mulgV -(mulgV (x * y)) mulgA mulVg mul1g. Qed. HB.instance Definition _ := isMulBaseGroup.Build G mulgA mul1g mk_invgK mk_invMg. HB.instance Definition _ := BaseFinGroup_isGroup.Build G mulVg. HB.end. #[compress_coercions] HB.instance Definition _ (T : baseFinGroupType) : Finite (BaseFinGroup.arg_sort T) := Finite.class T. (* Arguments of conjg are restricted to true groups to avoid an *) (* improper interpretation of A ^ B with A and B sets, namely: *) (* {x^-1 * (y * z) | y \in A, x, z \in B} *) Definition conjg (T : finGroupType) (x y : T) := y^-1 * (x * y). Notation "x1 ^ x2" := (conjg x1 x2) : group_scope. Definition commg (T : finGroupType) (x y : T) := x^-1 * x ^ y. Notation "[ ~ x1 , x2 , .. , xn ]" := (commg .. (commg x1 x2) .. xn) : group_scope. Prenex Implicits mulg invg expgn conjg commg. Notation "\prod_ ( i <- r | P ) F" := (\big[mulg/1]_(i <- r | P%B) F%g) : group_scope. Notation "\prod_ ( i <- r ) F" := (\big[mulg/1]_(i <- r) F%g) : group_scope. Notation "\prod_ ( m <= i < n | P ) F" := (\big[mulg/1]_(m <= i < n | P%B) F%g) : group_scope. Notation "\prod_ ( m <= i < n ) F" := (\big[mulg/1]_(m <= i < n) F%g) : group_scope. Notation "\prod_ ( i | P ) F" := (\big[mulg/1]_(i | P%B) F%g) : group_scope. Notation "\prod_ i F" := (\big[mulg/1]_i F%g) : group_scope. Notation "\prod_ ( i : t | P ) F" := (\big[mulg/1]_(i : t | P%B) F%g) (only parsing) : group_scope. Notation "\prod_ ( i : t ) F" := (\big[mulg/1]_(i : t) F%g) (only parsing) : group_scope. Notation "\prod_ ( i < n | P ) F" := (\big[mulg/1]_(i < n | P%B) F%g) : group_scope. Notation "\prod_ ( i < n ) F" := (\big[mulg/1]_(i < n) F%g) : group_scope. Notation "\prod_ ( i 'in' A | P ) F" := (\big[mulg/1]_(i in A | P%B) F%g) : group_scope. Notation "\prod_ ( i 'in' A ) F" := (\big[mulg/1]_(i in A) F%g) : group_scope. Section PreGroupIdentities. Variable T : baseFinGroupType. Implicit Types x y z : T. Local Notation mulgT := (@mulg T). Lemma mulgA : associative mulgT. Proof. exact: mulgA_subproof. Qed. Lemma mul1g : left_id 1 mulgT. Proof. exact: mul1g_subproof. Qed. Lemma invgK : @involutive T invg. Proof. exact: invgK_subproof. Qed. Lemma invMg x y : (x * y)^-1 = y^-1 * x^-1. Proof. exact: invMg_subproof. Qed. Lemma invg_inj : @injective T T invg. Proof. exact: can_inj invgK. Qed. Lemma eq_invg_sym x y : (x^-1 == y) = (x == y^-1). Proof. by apply: (inv_eq invgK). Qed. Lemma invg1 : 1^-1 = 1 :> T. Proof. by apply: invg_inj; rewrite -{1}[1^-1]mul1g invMg invgK mul1g. Qed. Lemma eq_invg1 x : (x^-1 == 1) = (x == 1). Proof. by rewrite eq_invg_sym invg1. Qed. Lemma mulg1 : right_id 1 mulgT. Proof. by move=> x; apply: invg_inj; rewrite invMg invg1 mul1g. Qed. HB.instance Definition _ := Monoid.isLaw.Build T 1 mulgT mulgA mul1g mulg1. Lemma expgnE x n : x ^+ n = iterop n mulg x 1. Proof. by []. Qed. Lemma expg0 x : x ^+ 0 = 1. Proof. by []. Qed. Lemma expg1 x : x ^+ 1 = x. Proof. by []. Qed. Lemma expgS x n : x ^+ n.+1 = x * x ^+ n. Proof. by case: n => //; rewrite mulg1. Qed. Lemma expg1n n : 1 ^+ n = 1 :> T. Proof. by elim: n => // n IHn; rewrite expgS mul1g. Qed. Lemma expgD x n m : x ^+ (n + m) = x ^+ n * x ^+ m. Proof. by elim: n => [|n IHn]; rewrite ?mul1g // !expgS IHn mulgA. Qed. Lemma expgSr x n : x ^+ n.+1 = x ^+ n * x. Proof. by rewrite -addn1 expgD expg1. Qed. Lemma expgM x n m : x ^+ (n * m) = x ^+ n ^+ m. Proof. elim: m => [|m IHm]; first by rewrite muln0 expg0. by rewrite mulnS expgD IHm expgS. Qed. Lemma expgAC x m n : x ^+ m ^+ n = x ^+ n ^+ m. Proof. by rewrite -!expgM mulnC. Qed. Definition commute x y := x * y = y * x. Lemma commute_refl x : commute x x. Proof. by []. Qed. Lemma commute_sym x y : commute x y -> commute y x. Proof. by []. Qed. Lemma commute1 x : commute x 1. Proof. by rewrite /commute mulg1 mul1g. Qed. Lemma commuteM x y z : commute x y -> commute x z -> commute x (y * z). Proof. by move=> cxy cxz; rewrite /commute -mulgA -cxz !mulgA cxy. Qed. Lemma commuteX x y n : commute x y -> commute x (y ^+ n). Proof. by move=> cxy; case: n; [apply: commute1 | elim=> // n; apply: commuteM]. Qed. Lemma commuteX2 x y m n : commute x y -> commute (x ^+ m) (y ^+ n). Proof. by move=> cxy; apply/commuteX/commute_sym/commuteX. Qed. Lemma expgVn x n : x^-1 ^+ n = x ^- n. Proof. by elim: n => [|n IHn]; rewrite ?invg1 // expgSr expgS invMg IHn. Qed. Lemma expgMn x y n : commute x y -> (x * y) ^+ n = x ^+ n * y ^+ n. Proof. move=> cxy; elim: n => [|n IHn]; first by rewrite mulg1. by rewrite !expgS IHn -mulgA (mulgA y) (commuteX _ (commute_sym cxy)) !mulgA. Qed. End PreGroupIdentities. #[global] Hint Resolve commute1 : core. Arguments invg_inj {T} [x1 x2]. Prenex Implicits commute invgK. Section GroupIdentities. Variable T : finGroupType. Implicit Types x y z : T. Local Notation mulgT := (@mulg T). Lemma mulVg : left_inverse 1 invg mulgT. Proof. exact: mulVg_subproof. Qed. Lemma mulgV : right_inverse 1 invg mulgT. Proof. by move=> x; rewrite -{1}(invgK x) mulVg. Qed. Lemma mulKg : left_loop invg mulgT. Proof. by move=> x y; rewrite mulgA mulVg mul1g. Qed. Lemma mulKVg : rev_left_loop invg mulgT. Proof. by move=> x y; rewrite mulgA mulgV mul1g. Qed. Lemma mulgI : right_injective mulgT. Proof. by move=> x; apply: can_inj (mulKg x). Qed. Lemma mulgK : right_loop invg mulgT. Proof. by move=> x y; rewrite -mulgA mulgV mulg1. Qed. Lemma mulgKV : rev_right_loop invg mulgT. Proof. by move=> x y; rewrite -mulgA mulVg mulg1. Qed. Lemma mulIg : left_injective mulgT. Proof. by move=> x; apply: can_inj (mulgK x). Qed. Lemma eq_invg_mul x y : (x^-1 == y :> T) = (x * y == 1 :> T). Proof. by rewrite -(inj_eq (@mulgI x)) mulgV eq_sym. Qed. Lemma eq_mulgV1 x y : (x == y) = (x * y^-1 == 1 :> T). Proof. by rewrite -(inj_eq invg_inj) eq_invg_mul. Qed. Lemma eq_mulVg1 x y : (x == y) = (x^-1 * y == 1 :> T). Proof. by rewrite -eq_invg_mul invgK. Qed. Lemma commuteV x y : commute x y -> commute x y^-1. Proof. by move=> cxy; apply: (@mulIg y); rewrite mulgKV -mulgA cxy mulKg. Qed. Lemma conjgE x y : x ^ y = y^-1 * (x * y). Proof. by []. Qed. Lemma conjgC x y : x * y = y * x ^ y. Proof. by rewrite mulKVg. Qed. Lemma conjgCV x y : x * y = y ^ x^-1 * x. Proof. by rewrite -mulgA mulgKV invgK. Qed. Lemma conjg1 x : x ^ 1 = x. Proof. by rewrite conjgE commute1 mulKg. Qed. Lemma conj1g x : 1 ^ x = 1. Proof. by rewrite conjgE mul1g mulVg. Qed. Lemma conjMg x y z : (x * y) ^ z = x ^ z * y ^ z. Proof. by rewrite !conjgE !mulgA mulgK. Qed. Lemma conjgM x y z : x ^ (y * z) = (x ^ y) ^ z. Proof. by rewrite !conjgE invMg !mulgA. Qed. Lemma conjVg x y : x^-1 ^ y = (x ^ y)^-1. Proof. by rewrite !conjgE !invMg invgK mulgA. Qed. Lemma conjJg x y z : (x ^ y) ^ z = (x ^ z) ^ y ^ z. Proof. by rewrite 2!conjMg conjVg. Qed. Lemma conjXg x y n : (x ^+ n) ^ y = (x ^ y) ^+ n. Proof. by elim: n => [|n IHn]; rewrite ?conj1g // !expgS conjMg IHn. Qed. Lemma conjgK : @right_loop T T invg conjg. Proof. by move=> y x; rewrite -conjgM mulgV conjg1. Qed. Lemma conjgKV : @rev_right_loop T T invg conjg. Proof. by move=> y x; rewrite -conjgM mulVg conjg1. Qed. Lemma conjg_inj : @left_injective T T T conjg. Proof. by move=> y; apply: can_inj (conjgK y). Qed. Lemma conjg_eq1 x y : (x ^ y == 1) = (x == 1). Proof. by rewrite (canF_eq (conjgK _)) conj1g. Qed. Lemma conjg_prod I r (P : pred I) F z : (\prod_(i <- r | P i) F i) ^ z = \prod_(i <- r | P i) (F i ^ z). Proof. by apply: (big_morph (conjg^~ z)) => [x y|]; rewrite ?conj1g ?conjMg. Qed. Lemma commgEl x y : [~ x, y] = x^-1 * x ^ y. Proof. by []. Qed. Lemma commgEr x y : [~ x, y] = y^-1 ^ x * y. Proof. by rewrite -!mulgA. Qed. Lemma commgC x y : x * y = y * x * [~ x, y]. Proof. by rewrite -mulgA !mulKVg. Qed. Lemma commgCV x y : x * y = [~ x^-1, y^-1] * (y * x). Proof. by rewrite commgEl !mulgA !invgK !mulgKV. Qed. Lemma conjRg x y z : [~ x, y] ^ z = [~ x ^ z, y ^ z]. Proof. by rewrite !conjMg !conjVg. Qed. Lemma invg_comm x y : [~ x, y]^-1 = [~ y, x]. Proof. by rewrite commgEr conjVg invMg invgK. Qed. Lemma commgP x y : reflect (commute x y) ([~ x, y] == 1 :> T). Proof. by rewrite [[~ x, y]]mulgA -invMg -eq_mulVg1 eq_sym; apply: eqP. Qed. Lemma conjg_fixP x y : reflect (x ^ y = x) ([~ x, y] == 1 :> T). Proof. by rewrite -eq_mulVg1 eq_sym; apply: eqP. Qed. Lemma commg1_sym x y : ([~ x, y] == 1 :> T) = ([~ y, x] == 1 :> T). Proof. by rewrite -invg_comm (inv_eq invgK) invg1. Qed. Lemma commg1 x : [~ x, 1] = 1. Proof. exact/eqP/commgP. Qed. Lemma comm1g x : [~ 1, x] = 1. Proof. by rewrite -invg_comm commg1 invg1. Qed. Lemma commgg x : [~ x, x] = 1. Proof. exact/eqP/commgP. Qed. Lemma commgXg x n : [~ x, x ^+ n] = 1. Proof. exact/eqP/commgP/commuteX. Qed. Lemma commgVg x : [~ x, x^-1] = 1. Proof. exact/eqP/commgP/commuteV. Qed. Lemma commgXVg x n : [~ x, x ^- n] = 1. Proof. exact/eqP/commgP/commuteV/commuteX. Qed. (* Other commg identities should slot in here. *) End GroupIdentities. #[global] Hint Rewrite mulg1 @mul1g invg1 @mulVg mulgV (@invgK) mulgK mulgKV @invMg @mulgA : gsimpl. Ltac gsimpl := autorewrite with gsimpl; try done. Definition gsimp := (@mulg1, @mul1g, (@invg1, @invgK), (@mulgV, @mulVg)). Definition gnorm := (gsimp, (@mulgK, @mulgKV, (@mulgA, @invMg))). Arguments mulgI [T]. Arguments mulIg [T]. Arguments conjg_inj {T} x [x1 x2]. Arguments commgP {T x y}. Arguments conjg_fixP {T x y}. Section Repr. (* Plucking a set representative. *) Variable gT : baseFinGroupType. Implicit Type A : {set gT}. Definition repr A := if 1 \in A then 1 else odflt 1 [pick x in A]. Lemma mem_repr A x : x \in A -> repr A \in A. Proof. by rewrite /repr; case: ifP => // _; case: pickP => // A0; rewrite [x \in A]A0. Qed. Lemma card_mem_repr A : #|A| > 0 -> repr A \in A. Proof. by rewrite lt0n => /existsP[x]; apply: mem_repr. Qed. Lemma repr_set1 x : repr [set x] = x. Proof. by apply/set1P/card_mem_repr; rewrite cards1. Qed. Lemma repr_set0 : repr set0 = 1. Proof. by rewrite /repr; case: pickP => [x|_] /[!inE]. Qed. End Repr. Arguments mem_repr [gT A]. Section BaseSetMulDef. (* We only assume a baseFinGroupType to allow this construct to be iterated. *) Variable gT : baseFinGroupType. Implicit Types A B : {set gT}. (* Set-lifted group operations. *) Definition set_mulg A B := mulg @2: (A, B). Definition set_invg A := invg @^-1: A. (* The pre-group structure of group subsets. *) Lemma set_mul1g : left_id [set 1] set_mulg. Proof. move=> A; apply/setP=> y; apply/imset2P/idP=> [[_ x /set1P-> Ax ->] | Ay]. by rewrite mul1g. by exists (1 : gT) y; rewrite ?(set11, mul1g). Qed. Lemma set_mulgA : associative set_mulg. Proof. move=> A B C; apply/setP=> y. apply/imset2P/imset2P=> [[x1 z Ax1 /imset2P[x2 x3 Bx2 Cx3 ->] ->]| [z x3]]. by exists (x1 * x2) x3; rewrite ?mulgA //; apply/imset2P; exists x1 x2. case/imset2P=> x1 x2 Ax1 Bx2 -> Cx3 ->. by exists x1 (x2 * x3); rewrite ?mulgA //; apply/imset2P; exists x2 x3. Qed. Lemma set_invgK : involutive set_invg. Proof. by move=> A; apply/setP=> x; rewrite !inE invgK. Qed. Lemma set_invgM : {morph set_invg : A B / set_mulg A B >-> set_mulg B A}. Proof. move=> A B; apply/setP=> z; rewrite inE. apply/imset2P/imset2P=> [[x y Ax By /(canRL invgK)->] | [y x]]. by exists y^-1 x^-1; rewrite ?invMg // inE invgK. by rewrite !inE => By1 Ax1 ->; exists x^-1 y^-1; rewrite ?invMg. Qed. HB.instance Definition set_base_group := isMulBaseGroup.Build (set_type gT) set_mulgA set_mul1g set_invgK set_invgM. HB.instance Definition _ : isMulBaseGroup {set gT} := set_base_group. End BaseSetMulDef. (* Time to open the bag of dirty tricks. When we define groups down below *) (* as a subtype of {set gT}, we need them to be able to coerce to sets in *) (* both set-style contexts (x \in G) and monoid-style contexts (G * H), *) (* and we need the coercion function to be EXACTLY the structure *) (* projection in BOTH cases -- otherwise the canonical unification breaks.*) (* Alas, Coq doesn't let us use the same coercion function twice, even *) (* when the targets are convertible. Our workaround (ab)uses the module *) (* system to declare two different identity coercions on an alias class. *) Module GroupSet. Definition sort (gT : baseFinGroupType) := {set gT}. End GroupSet. Identity Coercion GroupSet_of_sort : GroupSet.sort >-> set_of. Module Type GroupSetBaseGroupSig. Definition sort (gT : baseFinGroupType) := BaseFinGroup.arg_sort {set gT}. End GroupSetBaseGroupSig. Module MakeGroupSetBaseGroup (Gset_base : GroupSetBaseGroupSig). Identity Coercion of_sort : Gset_base.sort >-> BaseFinGroup.arg_sort. End MakeGroupSetBaseGroup. Module Export GroupSetBaseGroup := MakeGroupSetBaseGroup GroupSet. HB.instance Definition _ gT : Finite (GroupSet.sort gT) := Finite.class {set gT}. Section GroupSetMulDef. (* Some of these constructs could be defined on a baseFinGroupType. *) (* We restrict them to proper finGroupType because we only develop *) (* the theory for that case. *) Variable gT : finGroupType. Implicit Types A B : {set gT}. Implicit Type x y : gT. Definition lcoset A x := mulg x @: A. Definition rcoset A x := mulg^~ x @: A. Definition lcosets A B := lcoset A @: B. Definition rcosets A B := rcoset A @: B. Definition indexg B A := #|rcosets A B|. Definition conjugate A x := conjg^~ x @: A. Definition conjugates A B := conjugate A @: B. Definition class x B := conjg x @: B. Definition classes A := class^~ A @: A. Definition class_support A B := conjg @2: (A, B). Definition commg_set A B := commg @2: (A, B). (* These will only be used later, but are defined here so that we can *) (* keep all the Notation together. *) Definition normaliser A := [set x | conjugate A x \subset A]. Definition centraliser A := \bigcap_(x in A) normaliser [set x]. Definition abelian A := A \subset centraliser A. Definition normal A B := (A \subset B) && (B \subset normaliser A). (* "normalised" and "centralise[s|d]" are intended to be used with *) (* the {in ...} form, as in abelian below. *) Definition normalised A := forall x, conjugate A x = A. Definition centralises x A := forall y, y \in A -> commute x y. Definition centralised A := forall x, centralises x A. End GroupSetMulDef. Arguments lcoset _ _%_g _%_g. Arguments rcoset _ _%_g _%_g. Arguments rcosets _ _%_g _%_g. Arguments lcosets _ _%_g _%_g. Arguments indexg _ _%_g _%_g. Arguments conjugate _ _%_g _%_g. Arguments conjugates _ _%_g _%_g. Arguments class _ _%_g _%_g. Arguments classes _ _%_g. Arguments class_support _ _%_g _%_g. Arguments commg_set _ _%_g _%_g. Arguments normaliser _ _%_g. Arguments centraliser _ _%_g. Arguments abelian _ _%_g. Arguments normal _ _%_g _%_g. Arguments normalised _ _%_g. Arguments centralises _ _%_g _%_g. Arguments centralised _ _%_g. Notation "[ 1 gT ]" := (1 : {set gT}) : group_scope. Notation "[ 1 ]" := [1 FinGroup.sort _] : group_scope. Notation "A ^#" := (A :\ 1) : group_scope. Notation "x *: A" := ([set x%g] * A) : group_scope. Notation "A :* x" := (A * [set x%g]) : group_scope. Notation "A :^ x" := (conjugate A x) : group_scope. Notation "x ^: B" := (class x B) : group_scope. Notation "A :^: B" := (conjugates A B) : group_scope. Notation "#| B : A |" := (indexg B A) : group_scope. (* No notation for lcoset and rcoset, which are to be used mostly *) (* in curried form; x *: B and A :* 1 denote singleton products, *) (* so we can use mulgA, mulg1, etc, on, say, A :* 1 * B :* x. *) (* No notation for the set commutator generator set commg_set. *) Notation "''N' ( A )" := (normaliser A) : group_scope. Notation "''N_' G ( A )" := (G%g :&: 'N(A)) : group_scope. Notation "A <| B" := (normal A B) : group_scope. Notation "''C' ( A )" := (centraliser A) : group_scope. Notation "''C_' G ( A )" := (G%g :&: 'C(A)) : group_scope. Notation "''C_' ( G ) ( A )" := 'C_G(A) (only parsing) : group_scope. Notation "''C' [ x ]" := 'N([set x%g]) : group_scope. Notation "''C_' G [ x ]" := 'N_G([set x%g]) : group_scope. Notation "''C_' ( G ) [ x ]" := 'C_G[x] (only parsing) : group_scope. Prenex Implicits repr lcoset rcoset lcosets rcosets normal. Prenex Implicits conjugate conjugates class classes class_support. Prenex Implicits commg_set normalised centralised abelian. Section BaseSetMulProp. (* Properties of the purely multiplicative structure. *) Variable gT : baseFinGroupType. Implicit Types A B C D : {set gT}. Implicit Type x y z : gT. (* Set product. We already have all the pregroup identities, so we *) (* only need to add the monotonicity rules. *) Lemma mulsgP A B x : reflect (imset2_spec mulg (mem A) (fun _ => mem B) x) (x \in A * B). Proof. exact: imset2P. Qed. Lemma mem_mulg A B x y : x \in A -> y \in B -> x * y \in A * B. Proof. by move=> Ax By; apply/mulsgP; exists x y. Qed. Lemma prodsgP (I : finType) (P : pred I) (A : I -> {set gT}) x : reflect (exists2 c, forall i, P i -> c i \in A i & x = \prod_(i | P i) c i) (x \in \prod_(i | P i) A i). Proof. have [r big_r [Ur mem_r] _] := big_enumP P. pose inA c := all (fun i => c i \in A i); rewrite -big_r; set piAx := x \in _. suffices{big_r} IHr: reflect (exists2 c, inA c r & x = \prod_(i <- r) c i) piAx. apply: (iffP IHr) => -[c inAc ->]; do [exists c; last by rewrite big_r]. by move=> i Pi; rewrite (allP inAc) ?mem_r. by apply/allP=> i; rewrite mem_r => /inAc. elim: {P mem_r}r x @piAx Ur => /= [x _ | i r IHr x /andP[r'i /IHr{}IHr]]. by rewrite unlock; apply: (iffP set1P) => [-> | [] //]; exists (fun=> x). rewrite big_cons; apply: (iffP idP) => [|[c /andP[Aci Ac] ->]]; last first. by rewrite big_cons mem_mulg //; apply/IHr=> //; exists c. case/mulsgP=> c_i _ Ac_i /IHr[c /allP-inAcr ->] ->{x}. exists [eta c with i |-> c_i]; rewrite /= ?big_cons eqxx ?Ac_i. by apply/allP=> j rj; rewrite /= ifN ?(memPn r'i) ?inAcr. by congr (_ * _); apply: eq_big_seq => j rj; rewrite ifN ?(memPn r'i). Qed. Lemma mem_prodg (I : finType) (P : pred I) (A : I -> {set gT}) c : (forall i, P i -> c i \in A i) -> \prod_(i | P i) c i \in \prod_(i | P i) A i. Proof. by move=> Ac; apply/prodsgP; exists c. Qed. Lemma mulSg A B C : A \subset B -> A * C \subset B * C. Proof. exact: imset2Sl. Qed. Lemma mulgS A B C : B \subset C -> A * B \subset A * C. Proof. exact: imset2Sr. Qed. Lemma mulgSS A B C D : A \subset B -> C \subset D -> A * C \subset B * D. Proof. exact: imset2S. Qed. Lemma mulg_subl A B : 1 \in B -> A \subset A * B. Proof. by move=> B1; rewrite -{1}(mulg1 A) mulgS ?sub1set. Qed. Lemma mulg_subr A B : 1 \in A -> B \subset A * B. Proof. by move=> A1; rewrite -{1}(mul1g B) mulSg ?sub1set. Qed. Lemma mulUg A B C : (A :|: B) * C = (A * C) :|: (B * C). Proof. exact: imset2Ul. Qed. Lemma mulgU A B C : A * (B :|: C) = (A * B) :|: (A * C). Proof. exact: imset2Ur. Qed. (* Set (pointwise) inverse. *) Lemma invUg A B : (A :|: B)^-1 = A^-1 :|: B^-1. Proof. exact: preimsetU. Qed. Lemma invIg A B : (A :&: B)^-1 = A^-1 :&: B^-1. Proof. exact: preimsetI. Qed. Lemma invDg A B : (A :\: B)^-1 = A^-1 :\: B^-1. Proof. exact: preimsetD. Qed. Lemma invCg A : (~: A)^-1 = ~: A^-1. Proof. exact: preimsetC. Qed. Lemma invSg A B : (A^-1 \subset B^-1) = (A \subset B). Proof. by rewrite !(sameP setIidPl eqP) -invIg (inj_eq invg_inj). Qed. Lemma mem_invg x A : (x \in A^-1) = (x^-1 \in A). Proof. by rewrite inE. Qed. Lemma memV_invg x A : (x^-1 \in A^-1) = (x \in A). Proof. by rewrite inE invgK. Qed. Lemma card_invg A : #|A^-1| = #|A|. Proof. exact/card_preimset/invg_inj. Qed. (* Product with singletons. *) Lemma set1gE : 1 = [set 1] :> {set gT}. Proof. by []. Qed. Lemma set1gP x : reflect (x = 1) (x \in [1 gT]). Proof. exact: set1P. Qed. Lemma mulg_set1 x y : [set x] :* y = [set x * y]. Proof. by rewrite [_ * _]imset2_set1l imset_set1. Qed. Lemma invg_set1 x : [set x]^-1 = [set x^-1]. Proof. by apply/setP=> y; rewrite !inE inv_eq //; apply: invgK. Qed. End BaseSetMulProp. Arguments set1gP {gT x}. Arguments mulsgP {gT A B x}. Arguments prodsgP {gT I P A x}. Section GroupSetMulProp. (* Constructs that need a finGroupType *) Variable gT : finGroupType. Implicit Types A B C D : {set gT}. Implicit Type x y z : gT. (* Left cosets. *) Lemma lcosetE A x : lcoset A x = x *: A. Proof. by rewrite [_ * _]imset2_set1l. Qed. Lemma card_lcoset A x : #|x *: A| = #|A|. Proof. by rewrite -lcosetE (card_imset _ (mulgI _)). Qed. Lemma mem_lcoset A x y : (y \in x *: A) = (x^-1 * y \in A). Proof. by rewrite -lcosetE [_ x](can_imset_pre _ (mulKg _)) inE. Qed. Lemma lcosetP A x y : reflect (exists2 a, a \in A & y = x * a) (y \in x *: A). Proof. by rewrite -lcosetE; apply: imsetP. Qed. Lemma lcosetsP A B C : reflect (exists2 x, x \in B & C = x *: A) (C \in lcosets A B). Proof. by apply: (iffP imsetP) => [] [x Bx ->]; exists x; rewrite ?lcosetE. Qed. Lemma lcosetM A x y : (x * y) *: A = x *: (y *: A). Proof. by rewrite -mulg_set1 mulgA. Qed. Lemma lcoset1 A : 1 *: A = A. Proof. exact: mul1g. Qed. Lemma lcosetK : left_loop invg (fun x A => x *: A). Proof. by move=> x A; rewrite -lcosetM mulVg mul1g. Qed. Lemma lcosetKV : rev_left_loop invg (fun x A => x *: A). Proof. by move=> x A; rewrite -lcosetM mulgV mul1g. Qed. Lemma lcoset_inj : right_injective (fun x A => x *: A). Proof. by move=> x; apply: can_inj (lcosetK x). Qed. Lemma lcosetS x A B : (x *: A \subset x *: B) = (A \subset B). Proof. apply/idP/idP=> sAB; last exact: mulgS. by rewrite -(lcosetK x A) -(lcosetK x B) mulgS. Qed. Lemma sub_lcoset x A B : (A \subset x *: B) = (x^-1 *: A \subset B). Proof. by rewrite -(lcosetS x^-1) lcosetK. Qed. Lemma sub_lcosetV x A B : (A \subset x^-1 *: B) = (x *: A \subset B). Proof. by rewrite sub_lcoset invgK. Qed. (* Right cosets. *) Lemma rcosetE A x : rcoset A x = A :* x. Proof. by rewrite [_ * _]imset2_set1r. Qed. Lemma card_rcoset A x : #|A :* x| = #|A|. Proof. by rewrite -rcosetE (card_imset _ (mulIg _)). Qed. Lemma mem_rcoset A x y : (y \in A :* x) = (y * x^-1 \in A). Proof. by rewrite -rcosetE [_ x](can_imset_pre A (mulgK _)) inE. Qed. Lemma rcosetP A x y : reflect (exists2 a, a \in A & y = a * x) (y \in A :* x). Proof. by rewrite -rcosetE; apply: imsetP. Qed. Lemma rcosetsP A B C : reflect (exists2 x, x \in B & C = A :* x) (C \in rcosets A B). Proof. by apply: (iffP imsetP) => [] [x Bx ->]; exists x; rewrite ?rcosetE. Qed. Lemma rcosetM A x y : A :* (x * y) = A :* x :* y. Proof. by rewrite -mulg_set1 mulgA. Qed. Lemma rcoset1 A : A :* 1 = A. Proof. exact: mulg1. Qed. Lemma rcosetK : right_loop invg (fun A x => A :* x). Proof. by move=> x A; rewrite -rcosetM mulgV mulg1. Qed. Lemma rcosetKV : rev_right_loop invg (fun A x => A :* x). Proof. by move=> x A; rewrite -rcosetM mulVg mulg1. Qed. Lemma rcoset_inj : left_injective (fun A x => A :* x). Proof. by move=> x; apply: can_inj (rcosetK x). Qed. Lemma rcosetS x A B : (A :* x \subset B :* x) = (A \subset B). Proof. apply/idP/idP=> sAB; last exact: mulSg. by rewrite -(rcosetK x A) -(rcosetK x B) mulSg. Qed. Lemma sub_rcoset x A B : (A \subset B :* x) = (A :* x ^-1 \subset B). Proof. by rewrite -(rcosetS x^-1) rcosetK. Qed. Lemma sub_rcosetV x A B : (A \subset B :* x^-1) = (A :* x \subset B). Proof. by rewrite sub_rcoset invgK. Qed. (* Inverse maps lcosets to rcosets *) Lemma invg_lcosets A B : (lcosets A B)^-1 = rcosets A^-1 B^-1. Proof. rewrite /A^-1/= -![_^-1](can_imset_pre _ invgK) -[RHS]imset_comp -imset_comp. by apply: eq_imset => x /=; rewrite lcosetE rcosetE invMg invg_set1. Qed. (* Conjugates. *) Lemma conjg_preim A x : A :^ x = (conjg^~ x^-1) @^-1: A. Proof. exact: can_imset_pre (conjgK _). Qed. Lemma mem_conjg A x y : (y \in A :^ x) = (y ^ x^-1 \in A). Proof. by rewrite conjg_preim inE. Qed. Lemma mem_conjgV A x y : (y \in A :^ x^-1) = (y ^ x \in A). Proof. by rewrite mem_conjg invgK. Qed. Lemma memJ_conjg A x y : (y ^ x \in A :^ x) = (y \in A). Proof. by rewrite mem_conjg conjgK. Qed. Lemma conjsgE A x : A :^ x = x^-1 *: (A :* x). Proof. by apply/setP=> y; rewrite mem_lcoset mem_rcoset -mulgA mem_conjg. Qed. Lemma conjsg1 A : A :^ 1 = A. Proof. by rewrite conjsgE invg1 mul1g mulg1. Qed. Lemma conjsgM A x y : A :^ (x * y) = (A :^ x) :^ y. Proof. by rewrite !conjsgE invMg -!mulg_set1 !mulgA. Qed. Lemma conjsgK : @right_loop _ gT invg conjugate. Proof. by move=> x A; rewrite -conjsgM mulgV conjsg1. Qed. Lemma conjsgKV : @rev_right_loop _ gT invg conjugate. Proof. by move=> x A; rewrite -conjsgM mulVg conjsg1. Qed. Lemma conjsg_inj : @left_injective _ gT _ conjugate. Proof. by move=> x; apply: can_inj (conjsgK x). Qed. Lemma cardJg A x : #|A :^ x| = #|A|. Proof. by rewrite (card_imset _ (conjg_inj x)). Qed. Lemma conjSg A B x : (A :^ x \subset B :^ x) = (A \subset B). Proof. by rewrite !conjsgE lcosetS rcosetS. Qed. Lemma properJ A B x : (A :^ x \proper B :^ x) = (A \proper B). Proof. by rewrite /proper !conjSg. Qed. Lemma sub_conjg A B x : (A :^ x \subset B) = (A \subset B :^ x^-1). Proof. by rewrite -(conjSg A _ x) conjsgKV. Qed. Lemma sub_conjgV A B x : (A :^ x^-1 \subset B) = (A \subset B :^ x). Proof. by rewrite -(conjSg _ B x) conjsgKV. Qed. Lemma conjg_set1 x y : [set x] :^ y = [set x ^ y]. Proof. by rewrite [_ :^ _]imset_set1. Qed. Lemma conjs1g x : 1 :^ x = 1. Proof. by rewrite conjg_set1 conj1g. Qed. Lemma conjsg_eq1 A x : (A :^ x == 1%g) = (A == 1%g). Proof. by rewrite (canF_eq (conjsgK x)) conjs1g. Qed. Lemma conjsMg A B x : (A * B) :^ x = A :^ x * B :^ x. Proof. by rewrite !conjsgE !mulgA rcosetK. Qed. Lemma conjIg A B x : (A :&: B) :^ x = A :^ x :&: B :^ x. Proof. by rewrite !conjg_preim preimsetI. Qed. Lemma conj0g x : set0 :^ x = set0. Proof. exact: imset0. Qed. Lemma conjTg x : [set: gT] :^ x = [set: gT]. Proof. by rewrite conjg_preim preimsetT. Qed. Lemma bigcapJ I r (P : pred I) (B : I -> {set gT}) x : \bigcap_(i <- r | P i) (B i :^ x) = (\bigcap_(i <- r | P i) B i) :^ x. Proof. by rewrite (big_endo (conjugate^~ x)) => // [B1 B2|]; rewrite (conjTg, conjIg). Qed. Lemma conjUg A B x : (A :|: B) :^ x = A :^ x :|: B :^ x. Proof. by rewrite !conjg_preim preimsetU. Qed. Lemma bigcupJ I r (P : pred I) (B : I -> {set gT}) x : \bigcup_(i <- r | P i) (B i :^ x) = (\bigcup_(i <- r | P i) B i) :^ x. Proof. rewrite (big_endo (conjugate^~ x)) => // [B1 B2|]; first by rewrite conjUg. exact: imset0. Qed. Lemma conjCg A x : (~: A) :^ x = ~: A :^ x. Proof. by rewrite !conjg_preim preimsetC. Qed. Lemma conjDg A B x : (A :\: B) :^ x = A :^ x :\: B :^ x. Proof. by rewrite !setDE !(conjCg, conjIg). Qed. Lemma conjD1g A x : A^# :^ x = (A :^ x)^#. Proof. by rewrite conjDg conjs1g. Qed. (* Classes; not much for now. *) Lemma memJ_class x y A : y \in A -> x ^ y \in x ^: A. Proof. exact: imset_f. Qed. Lemma classS x A B : A \subset B -> x ^: A \subset x ^: B. Proof. exact: imsetS. Qed. Lemma class_set1 x y : x ^: [set y] = [set x ^ y]. Proof. exact: imset_set1. Qed. Lemma class1g x A : x \in A -> 1 ^: A = 1. Proof. move=> Ax; apply/setP=> y. by apply/imsetP/set1P=> [[a Aa]|] ->; last exists x; rewrite ?conj1g. Qed. Lemma classVg x A : x^-1 ^: A = (x ^: A)^-1. Proof. apply/setP=> xy; rewrite inE; apply/imsetP/imsetP=> [] [y Ay def_xy]. by rewrite def_xy conjVg invgK; exists y. by rewrite -[xy]invgK def_xy -conjVg; exists y. Qed. Lemma mem_classes x A : x \in A -> x ^: A \in classes A. Proof. exact: imset_f. Qed. Lemma memJ_class_support A B x y : x \in A -> y \in B -> x ^ y \in class_support A B. Proof. by move=> Ax By; apply: imset2_f. Qed. Lemma class_supportM A B C : class_support A (B * C) = class_support (class_support A B) C. Proof. apply/setP=> x; apply/imset2P/imset2P=> [[a y Aa] | [y c]]. case/mulsgP=> b c Bb Cc -> ->{x y}. by exists (a ^ b) c; rewrite ?(imset2_f, conjgM). case/imset2P=> a b Aa Bb -> Cc ->{x y}. by exists a (b * c); rewrite ?(mem_mulg, conjgM). Qed. Lemma class_support_set1l A x : class_support [set x] A = x ^: A. Proof. exact: imset2_set1l. Qed. Lemma class_support_set1r A x : class_support A [set x] = A :^ x. Proof. exact: imset2_set1r. Qed. Lemma classM x A B : x ^: (A * B) = class_support (x ^: A) B. Proof. by rewrite -!class_support_set1l class_supportM. Qed. Lemma class_lcoset x y A : x ^: (y *: A) = (x ^ y) ^: A. Proof. by rewrite classM class_set1 class_support_set1l. Qed. Lemma class_rcoset x A y : x ^: (A :* y) = (x ^: A) :^ y. Proof. by rewrite -class_support_set1r classM. Qed. (* Conjugate set. *) Lemma conjugatesS A B C : B \subset C -> A :^: B \subset A :^: C. Proof. exact: imsetS. Qed. Lemma conjugates_set1 A x : A :^: [set x] = [set A :^ x]. Proof. exact: imset_set1. Qed. Lemma conjugates_conj A x B : (A :^ x) :^: B = A :^: (x *: B). Proof. rewrite /conjugates [x *: B]imset2_set1l -imset_comp. by apply: eq_imset => y /=; rewrite conjsgM. Qed. (* Class support. *) Lemma class_supportEl A B : class_support A B = \bigcup_(x in A) x ^: B. Proof. exact: curry_imset2l. Qed. Lemma class_supportEr A B : class_support A B = \bigcup_(x in B) A :^ x. Proof. exact: curry_imset2r. Qed. (* Groups (at last!) *) Definition group_set A := (1 \in A) && (A * A \subset A). Lemma group_setP A : reflect (1 \in A /\ {in A & A, forall x y, x * y \in A}) (group_set A). Proof. apply: (iffP andP) => [] [A1 AM]; split=> {A1}//. by move=> x y Ax Ay; apply: (subsetP AM); rewrite mem_mulg. by apply/subsetP=> _ /mulsgP[x y Ax Ay ->]; apply: AM. Qed. Structure group_type : Type := Group { gval :> GroupSet.sort gT; _ : group_set gval }. Definition group_of : predArgType := group_type. Local Notation groupT := group_of. Identity Coercion type_of_group : group_of >-> group_type. HB.instance Definition _ := [isSub for gval]. #[hnf] HB.instance Definition _ := [Finite of group_type by <:]. (* No predType or baseFinGroupType structures, as these would hide the *) (* group-to-set coercion and thus spoil unification. *) HB.instance Definition _ := SubFinite.copy groupT group_type. Definition group (A : {set gT}) gA : groupT := @Group A gA. Definition clone_group G := let: Group _ gP := G return {type of Group for G} -> groupT in fun k => k gP. Lemma group_inj : injective gval. Proof. exact: val_inj. Qed. Lemma groupP (G : groupT) : group_set G. Proof. by case: G. Qed. Lemma congr_group (H K : groupT) : H = K -> H :=: K. Proof. exact: congr1. Qed. Lemma isgroupP A : reflect (exists G : groupT, A = G) (group_set A). Proof. by apply: (iffP idP) => [gA | [[B gB] -> //]]; exists (Group gA). Qed. Lemma group_set_one : group_set 1. Proof. by rewrite /group_set set11 mulg1 subxx. Qed. Canonical one_group := group group_set_one. Canonical set1_group := @group [set 1] group_set_one. Lemma group_setT : group_set (setTfor gT). Proof. by apply/group_setP; split=> [|x y _ _]; rewrite inE. Qed. Canonical setT_group := group group_setT. End GroupSetMulProp. Arguments group_of gT%_type. Arguments lcosetP {gT A x y}. Arguments lcosetsP {gT A B C}. Arguments rcosetP {gT A x y}. Arguments rcosetsP {gT A B C}. Arguments group_setP {gT A}. Arguments setT_group gT%_type. Prenex Implicits group_set mulsgP set1gP. Notation "{ 'group' gT }" := (group_of gT) (format "{ 'group' gT }") : type_scope. Notation "[ 'group' 'of' G ]" := (clone_group (@group _ G)) (format "[ 'group' 'of' G ]") : form_scope. Bind Scope Group_scope with group_type. Bind Scope Group_scope with group_of. Notation "1" := (one_group _) : Group_scope. Notation "[ 1 gT ]" := (1%G : {group gT}) : Group_scope. Notation "[ 'set' : gT ]" := (setT_group gT) : Group_scope. (* These definitions come early so we can establish the Notation. *) HB.lock Definition generated (gT : finGroupType) (A : {set gT}) := \bigcap_(G : {group gT} | A \subset G) G. Canonical generated_unlockable := Unlockable generated.unlock. Definition gcore (gT : finGroupType) (A B : {set gT}) := \bigcap_(x in B) A :^ x. Definition joing (gT : finGroupType) (A B : {set gT}) := generated (A :|: B). Definition commutator (gT : finGroupType) (A B : {set gT}) := generated (commg_set A B). Definition cycle (gT : finGroupType) (x : gT) := generated [set x]. Definition order (gT : finGroupType) (x : gT) := #|cycle x|. Arguments commutator _ _%_g _%_g. Arguments joing _ _%_g _%_g. Arguments generated _ _%_g. (* Helper notation for defining new groups that need a bespoke finGroupType. *) (* The actual group for such a type (say, my_gT) will be the full group, *) (* i.e., [set: my_gT] or [set: my_gT]%G, but Coq will not recognize *) (* specific notation for these because of the coercions inserted during type *) (* inference, unless they are defined as [set: gsort my_gT] using the *) (* Notation below. *) Notation gsort gT := (BaseFinGroup.arg_sort gT%type) (only parsing). Notation "<< A >>" := (generated A) : group_scope. Notation "<[ x ] >" := (cycle x) : group_scope. Notation "#[ x ]" := (order x) : group_scope. Notation "A <*> B" := (joing A B) : group_scope. Notation "[ ~: A1 , A2 , .. , An ]" := (commutator .. (commutator A1 A2) .. An) : group_scope. Prenex Implicits order cycle gcore. Section GroupProp. Variable gT : finGroupType. Notation sT := {set gT}. Implicit Types A B C D : sT. Implicit Types x y z : gT. Implicit Types G H K : {group gT}. Section OneGroup. Variable G : {group gT}. Lemma valG : val G = G. Proof. by []. Qed. (* Non-triviality. *) Lemma group1 : 1 \in G. Proof. by case/group_setP: (valP G). Qed. #[local] Hint Resolve group1 : core. Lemma group1_contra x : x \notin G -> x != 1. Proof. by apply: contraNneq => ->. Qed. Lemma sub1G : [1 gT] \subset G. Proof. by rewrite sub1set. Qed. Lemma subG1 : (G \subset [1]) = (G :==: 1). Proof. by rewrite eqEsubset sub1G andbT. Qed. Lemma setI1g : 1 :&: G = 1. Proof. exact: (setIidPl sub1G). Qed. Lemma setIg1 : G :&: 1 = 1. Proof. exact: (setIidPr sub1G). Qed. Lemma subG1_contra H : G \subset H -> G :!=: 1 -> H :!=: 1. Proof. by move=> sGH; rewrite -subG1; apply: contraNneq => <-. Qed. Lemma repr_group : repr G = 1. Proof. by rewrite /repr group1. Qed. Lemma cardG_gt0 : 0 < #|G|. Proof. by rewrite lt0n; apply/existsP; exists (1 : gT). Qed. Lemma indexg_gt0 A : 0 < #|G : A|. Proof. rewrite lt0n; apply/existsP; exists A. by rewrite -{2}[A]mulg1 -rcosetE; apply: imset_f. Qed. Lemma trivgP : reflect (G :=: 1) (G \subset [1]). Proof. by rewrite subG1; apply: eqP. Qed. Lemma trivGP : reflect (G = 1%G) (G \subset [1]). Proof. by rewrite subG1; apply: eqP. Qed. Lemma proper1G : ([1] \proper G) = (G :!=: 1). Proof. by rewrite properEneq sub1G andbT eq_sym. Qed. Lemma in_one_group x : (x \in 1%G) = (x == 1). Proof. by rewrite -[x \in _]/(x \in [set 1]) !inE. Qed. Definition inE := (in_one_group, inE). Lemma trivgPn : reflect (exists2 x, x \in G & x != 1) (G :!=: 1). Proof. rewrite -subG1. by apply: (iffP subsetPn) => [] [x Gx x1]; exists x; rewrite ?inE in x1 *. Qed. Lemma trivg_card_le1 : (G :==: 1) = (#|G| <= 1). Proof. by rewrite eq_sym eqEcard cards1 sub1G. Qed. Lemma trivg_card1 : (G :==: 1) = (#|G| == 1%N). Proof. by rewrite trivg_card_le1 eqn_leq cardG_gt0 andbT. Qed. Lemma cardG_gt1 : (#|G| > 1) = (G :!=: 1). Proof. by rewrite trivg_card_le1 ltnNge. Qed. Lemma card_le1_trivg : #|G| <= 1 -> G :=: 1. Proof. by rewrite -trivg_card_le1; move/eqP. Qed. Lemma card1_trivg : #|G| = 1%N -> G :=: 1. Proof. by move=> G1; rewrite card_le1_trivg ?G1. Qed. (* Inclusion and product. *) Lemma mulG_subl A : A \subset A * G. Proof. exact: mulg_subl group1. Qed. Lemma mulG_subr A : A \subset ((G : {set gT}) * A ). Proof. exact: mulg_subr group1. Qed. Lemma mulGid : (G : {set gT}) * G = G. Proof. by apply/eqP; rewrite eqEsubset mulG_subr andbT; case/andP: (valP G). Qed. Lemma mulGS A B : (G * A \subset G * B) = (A \subset G * B). Proof. apply/idP/idP; first exact: subset_trans (mulG_subr A). by move/(mulgS G); rewrite mulgA mulGid. Qed. Lemma mulSG A B : (A * G \subset B * G) = (A \subset B * G). Proof. apply/idP/idP; first exact: subset_trans (mulG_subl A). by move/(mulSg G); rewrite -mulgA mulGid. Qed. Lemma mul_subG A B : A \subset G -> B \subset G -> A * B \subset G. Proof. by move=> sAG sBG; rewrite -mulGid mulgSS. Qed. Lemma prod_subG (I : Type) (r : seq I) (P : {pred I}) (F : I -> {set gT}) : (forall i, P i -> F i \subset G) -> \prod_(i <- r | P i) F i \subset G. Proof. move=> subFG; elim/big_rec: _ => [|/= i A /subFG]; first by rewrite sub1set. exact: mul_subG. Qed. (* Membership lemmas *) Lemma groupM x y : x \in G -> y \in G -> x * y \in G. Proof. by case/group_setP: (valP G) x y. Qed. Lemma groupX x n : x \in G -> x ^+ n \in G. Proof. by move=> Gx; elim: n => [|n IHn]; rewrite ?group1 // expgS groupM. Qed. Lemma groupVr x : x \in G -> x^-1 \in G. Proof. move=> Gx; rewrite -(mul1g x^-1) -mem_rcoset ((G :* x =P G) _) //. by rewrite eqEcard card_rcoset leqnn mul_subG ?sub1set. Qed. Lemma groupVl x : x^-1 \in G -> x \in G. Proof. by move/groupVr; rewrite invgK. Qed. Lemma groupV x : (x^-1 \in G) = (x \in G). Proof. by apply/idP/idP; [apply: groupVl | apply: groupVr]. Qed. Lemma groupMl x y : x \in G -> (x * y \in G) = (y \in G). Proof. move=> Gx; apply/idP/idP=> [Gxy|]; last exact: groupM. by rewrite -(mulKg x y) groupM ?groupVr. Qed. Lemma groupMr x y : x \in G -> (y * x \in G) = (y \in G). Proof. by move=> Gx; rewrite -[_ \in G]groupV invMg groupMl groupV. Qed. Definition in_group := (group1, groupV, (groupMl, groupX)). Lemma groupJ x y : x \in G -> y \in G -> x ^ y \in G. Proof. by move=> Gx Gy; rewrite !in_group. Qed. Lemma groupJr x y : y \in G -> (x ^ y \in G) = (x \in G). Proof. by move=> Gy; rewrite groupMl (groupMr, groupV). Qed. Lemma groupR x y : x \in G -> y \in G -> [~ x, y] \in G. Proof. by move=> Gx Gy; rewrite !in_group. Qed. Lemma group_prod I r (P : pred I) F : (forall i, P i -> F i \in G) -> \prod_(i <- r | P i) F i \in G. Proof. by move=> G_P; elim/big_ind: _ => //; apply: groupM. Qed. (* Inverse is an anti-morphism. *) Lemma invGid : G^-1 = G. Proof. by apply/setP=> x; rewrite inE groupV. Qed. Lemma inv_subG A : (A^-1 \subset G) = (A \subset G). Proof. by rewrite -{1}invGid invSg. Qed. Lemma invg_lcoset x : (x *: G)^-1 = G :* x^-1. Proof. by rewrite invMg invGid invg_set1. Qed. Lemma invg_rcoset x : (G :* x)^-1 = x^-1 *: G. Proof. by rewrite invMg invGid invg_set1. Qed. Lemma memV_lcosetV x y : (y^-1 \in x^-1 *: G) = (y \in G :* x). Proof. by rewrite -invg_rcoset memV_invg. Qed. Lemma memV_rcosetV x y : (y^-1 \in G :* x^-1) = (y \in x *: G). Proof. by rewrite -invg_lcoset memV_invg. Qed. (* Product idempotence *) Lemma mulSgGid A x : x \in A -> A \subset G -> A * G = G. Proof. move=> Ax sAG; apply/eqP; rewrite eqEsubset -{2}mulGid mulSg //=. apply/subsetP=> y Gy; rewrite -(mulKVg x y) mem_mulg // groupMr // groupV. exact: (subsetP sAG). Qed. Lemma mulGSgid A x : x \in A -> A \subset G -> G * A = G. Proof. rewrite -memV_invg -invSg invGid => Ax sAG. by apply: invg_inj; rewrite invMg invGid (mulSgGid Ax). Qed. (* Left cosets *) Lemma lcoset_refl x : x \in x *: G. Proof. by rewrite mem_lcoset mulVg group1. Qed. Lemma lcoset_sym x y : (x \in y *: G) = (y \in x *: G). Proof. by rewrite !mem_lcoset -groupV invMg invgK. Qed. Lemma lcoset_eqP {x y} : reflect (x *: G = y *: G) (x \in y *: G). Proof. suffices <-: (x *: G == y *: G) = (x \in y *: G) by apply: eqP. by rewrite eqEsubset !mulSG !sub1set lcoset_sym andbb. Qed. Lemma lcoset_transl x y z : x \in y *: G -> (x \in z *: G) = (y \in z *: G). Proof. by move=> Gyx; rewrite -2!(lcoset_sym z) (lcoset_eqP Gyx). Qed. Lemma lcoset_trans x y z : x \in y *: G -> y \in z *: G -> x \in z *: G. Proof. by move/lcoset_transl->. Qed. Lemma lcoset_id x : x \in G -> x *: G = G. Proof. by move=> Gx; rewrite (lcoset_eqP (_ : x \in 1 *: G)) mul1g. Qed. (* Right cosets, with an elimination form for repr. *) Lemma rcoset_refl x : x \in G :* x. Proof. by rewrite mem_rcoset mulgV group1. Qed. Lemma rcoset_sym x y : (x \in G :* y) = (y \in G :* x). Proof. by rewrite -!memV_lcosetV lcoset_sym. Qed. Lemma rcoset_eqP {x y} : reflect (G :* x = G :* y) (x \in G :* y). Proof. suffices <-: (G :* x == G :* y) = (x \in G :* y) by apply: eqP. by rewrite eqEsubset !mulGS !sub1set rcoset_sym andbb. Qed. Lemma rcoset_transl x y z : x \in G :* y -> (x \in G :* z) = (y \in G :* z). Proof. by move=> Gyx; rewrite -2!(rcoset_sym z) (rcoset_eqP Gyx). Qed. Lemma rcoset_trans x y z : x \in G :* y -> y \in G :* z -> x \in G :* z. Proof. by move/rcoset_transl->. Qed. Lemma rcoset_id x : x \in G -> G :* x = G. Proof. by move=> Gx; rewrite (rcoset_eqP (_ : x \in G :* 1)) mulg1. Qed. (* Elimination form. *) Variant rcoset_repr_spec x : gT -> Type := RcosetReprSpec g : g \in G -> rcoset_repr_spec x (g * x). Lemma mem_repr_rcoset x : repr (G :* x) \in G :* x. Proof. exact: mem_repr (rcoset_refl x). Qed. (* This form sometimes fails because ssreflect 1.1 delegates matching to the *) (* (weaker) primitive Coq algorithm for general (co)inductive type families. *) Lemma repr_rcosetP x : rcoset_repr_spec x (repr (G :* x)). Proof. by rewrite -[repr _](mulgKV x); split; rewrite -mem_rcoset mem_repr_rcoset. Qed. Lemma rcoset_repr x : G :* (repr (G :* x)) = G :* x. Proof. exact/rcoset_eqP/mem_repr_rcoset. Qed. (* Coset spaces. *) Lemma mem_rcosets A x : (G :* x \in rcosets G A) = (x \in G * A). Proof. apply/rcosetsP/mulsgP=> [[a Aa /rcoset_eqP/rcosetP[g]] | ]; first by exists g a. by case=> g a Gg Aa ->{x}; exists a; rewrite // rcosetM rcoset_id. Qed. Lemma mem_lcosets A x : (x *: G \in lcosets G A) = (x \in A * G). Proof. rewrite -[LHS]memV_invg invg_lcoset invg_lcosets. by rewrite -[RHS]memV_invg invMg invGid mem_rcosets. Qed. (* Conjugates. *) Lemma group_setJ A x : group_set (A :^ x) = group_set A. Proof. by rewrite /group_set mem_conjg conj1g -conjsMg conjSg. Qed. Lemma group_set_conjG x : group_set (G :^ x). Proof. by rewrite group_setJ groupP. Qed. Canonical conjG_group x := group (group_set_conjG x). Lemma conjGid : {in G, normalised G}. Proof. by move=> x Gx; apply/setP=> y; rewrite mem_conjg groupJr ?groupV. Qed. Lemma conj_subG x A : x \in G -> A \subset G -> A :^ x \subset G. Proof. by move=> Gx sAG; rewrite -(conjGid Gx) conjSg. Qed. (* Classes *) Lemma class1G : 1 ^: G = 1. Proof. exact: class1g group1. Qed. Lemma classes1 : [1] \in classes G. Proof. by rewrite -class1G mem_classes. Qed. Lemma classGidl x y : y \in G -> (x ^ y) ^: G = x ^: G. Proof. by move=> Gy; rewrite -class_lcoset lcoset_id. Qed. Lemma classGidr x : {in G, normalised (x ^: G)}. Proof. by move=> y Gy /=; rewrite -class_rcoset rcoset_id. Qed. Lemma class_refl x : x \in x ^: G. Proof. by apply/imsetP; exists 1; rewrite ?conjg1. Qed. #[local] Hint Resolve class_refl : core. Lemma class_eqP x y : reflect (x ^: G = y ^: G) (x \in y ^: G). Proof. by apply: (iffP idP) => [/imsetP[z Gz ->] | <-]; rewrite ?class_refl ?classGidl. Qed. Lemma class_sym x y : (x \in y ^: G) = (y \in x ^: G). Proof. by apply/idP/idP=> /class_eqP->. Qed. Lemma class_transl x y z : x \in y ^: G -> (x \in z ^: G) = (y \in z ^: G). Proof. by rewrite -!(class_sym z) => /class_eqP->. Qed. Lemma class_trans x y z : x \in y ^: G -> y \in z ^: G -> x \in z ^: G. Proof. by move/class_transl->. Qed. Lemma repr_class x : {y | y \in G & repr (x ^: G) = x ^ y}. Proof. set z := repr _; have: #|[set y in G | z == x ^ y]| > 0. have: z \in x ^: G by apply: (mem_repr x). by case/imsetP=> y Gy ->; rewrite (cardD1 y) inE Gy eqxx. by move/card_mem_repr; move: (repr _) => y /setIdP[Gy /eqP]; exists y. Qed. Lemma classG_eq1 x : (x ^: G == 1) = (x == 1). Proof. apply/eqP/eqP=> [xG1 | ->]; last exact: class1G. by have:= class_refl x; rewrite xG1 => /set1P. Qed. Lemma class_subG x A : x \in G -> A \subset G -> x ^: A \subset G. Proof. move=> Gx sAG; apply/subsetP=> _ /imsetP[y Ay ->]. by rewrite groupJ // (subsetP sAG). Qed. Lemma repr_classesP xG : reflect (repr xG \in G /\ xG = repr xG ^: G) (xG \in classes G). Proof. apply: (iffP imsetP) => [[x Gx ->] | []]; last by exists (repr xG). by have [y Gy ->] := repr_class x; rewrite classGidl ?groupJ. Qed. Lemma mem_repr_classes xG : xG \in classes G -> repr xG \in xG. Proof. by case/repr_classesP=> _ {2}->; apply: class_refl. Qed. Lemma classes_gt0 : 0 < #|classes G|. Proof. by rewrite (cardsD1 1) classes1. Qed. Lemma classes_gt1 : (#|classes G| > 1) = (G :!=: 1). Proof. rewrite (cardsD1 1) classes1 ltnS lt0n cards_eq0. apply/set0Pn/trivgPn=> [[xG /setD1P[nt_xG]] | [x Gx ntx]]. by case/imsetP=> x Gx def_xG; rewrite def_xG classG_eq1 in nt_xG; exists x. by exists (x ^: G); rewrite !inE classG_eq1 ntx; apply: imset_f. Qed. Lemma mem_class_support A x : x \in A -> x \in class_support A G. Proof. by move=> Ax; rewrite -[x]conjg1 memJ_class_support. Qed. Lemma class_supportGidl A x : x \in G -> class_support (A :^ x) G = class_support A G. Proof. by move=> Gx; rewrite -class_support_set1r -class_supportM lcoset_id. Qed. Lemma class_supportGidr A : {in G, normalised (class_support A G)}. Proof. by move=> x Gx /=; rewrite -class_support_set1r -class_supportM rcoset_id. Qed. Lemma class_support_subG A : A \subset G -> class_support A G \subset G. Proof. by move=> sAG; rewrite class_supportEr; apply/bigcupsP=> x Gx; apply: conj_subG. Qed. Lemma sub_class_support A : A \subset class_support A G. Proof. by rewrite class_supportEr (bigcup_max 1) ?conjsg1. Qed. Lemma class_support_id : class_support G G = G. Proof. by apply/eqP; rewrite eqEsubset sub_class_support class_support_subG. Qed. Lemma class_supportD1 A : (class_support A G)^# = cover (A^# :^: G). Proof. rewrite cover_imset class_supportEr setDE big_distrl /=. by apply: eq_bigr => x _; rewrite -setDE conjD1g. Qed. (* Subgroup Type construction. *) (* We only expect to use this for abstract groups, so we don't project *) (* the argument to a set. *) Inductive subg_of : predArgType := Subg x & x \in G. Definition sgval u := let: Subg x _ := u in x. Definition subg_of_Sub := Eval hnf in [isSub for sgval]. HB.instance Definition _ := subg_of_Sub. #[hnf] HB.instance Definition _ := [Finite of subg_of by <:]. Lemma subgP u : sgval u \in G. Proof. exact: valP. Qed. Lemma subg_inj : injective sgval. Proof. exact: val_inj. Qed. Lemma congr_subg u v : u = v -> sgval u = sgval v. Proof. exact: congr1. Qed. Definition subg_one := Subg group1. Definition subg_inv u := Subg (groupVr (subgP u)). Definition subg_mul u v := Subg (groupM (subgP u) (subgP v)). Lemma subg_oneP : left_id subg_one subg_mul. Proof. by move=> u; apply: val_inj; apply: mul1g. Qed. Lemma subg_invP : left_inverse subg_one subg_inv subg_mul. Proof. by move=> u; apply: val_inj; apply: mulVg. Qed. Lemma subg_mulP : associative subg_mul. Proof. by move=> u v w; apply: val_inj; apply: mulgA. Qed. HB.instance Definition _ := isMulGroup.Build subg_of subg_mulP subg_oneP subg_invP. Lemma sgvalM : {in setT &, {morph sgval : x y / x * y}}. Proof. by []. Qed. Lemma valgM : {in setT &, {morph val : x y / (x : subg_of) * y >-> x * y}}. Proof. by []. Qed. Definition subg : gT -> subg_of := insubd (1 : subg_of). Lemma subgK x : x \in G -> val (subg x) = x. Proof. by move=> Gx; rewrite insubdK. Qed. Lemma sgvalK : cancel sgval subg. Proof. by case=> x Gx; apply: val_inj; apply: subgK. Qed. Lemma subg_default x : (x \in G) = false -> val (subg x) = 1. Proof. by move=> Gx; rewrite val_insubd Gx. Qed. Lemma subgM : {in G &, {morph subg : x y / x * y}}. Proof. by move=> x y Gx Gy; apply: val_inj; rewrite /= !subgK ?groupM. Qed. End OneGroup. #[local] Hint Resolve group1 : core. Lemma groupD1_inj G H : G^# = H^# -> G :=: H. Proof. by move/(congr1 (setU 1)); rewrite !setD1K. Qed. Lemma invMG G H : (G * H)^-1 = H * G. Proof. by rewrite invMg !invGid. Qed. Lemma mulSGid G H : H \subset G -> H * G = G. Proof. exact: mulSgGid (group1 H). Qed. Lemma mulGSid G H : H \subset G -> G * H = G. Proof. exact: mulGSgid (group1 H). Qed. Lemma mulGidPl G H : reflect (G * H = G) (H \subset G). Proof. by apply: (iffP idP) => [|<-]; [apply: mulGSid | apply: mulG_subr]. Qed. Lemma mulGidPr G H : reflect (G * H = H) (G \subset H). Proof. by apply: (iffP idP) => [|<-]; [apply: mulSGid | apply: mulG_subl]. Qed. Lemma comm_group_setP G H : reflect (commute G H) (group_set (G * H)). Proof. rewrite /group_set (subsetP (mulG_subl _ _)) ?group1 // andbC. have <-: #|G * H| <= #|H * G| by rewrite -invMG card_invg. by rewrite -mulgA mulGS mulgA mulSG -eqEcard eq_sym; apply: eqP. Qed. Lemma card_lcosets G H : #|lcosets H G| = #|G : H|. Proof. by rewrite -card_invg invg_lcosets !invGid. Qed. (* Group Modularity equations *) Lemma group_modl A B G : A \subset G -> A * (B :&: G) = A * B :&: G. Proof. move=> sAG; apply/eqP; rewrite eqEsubset subsetI mulgS ?subsetIl //. rewrite -{2}mulGid mulgSS ?subsetIr //. apply/subsetP => _ /setIP[/mulsgP[a b Aa Bb ->] Gab]. by rewrite mem_mulg // inE Bb -(groupMl _ (subsetP sAG _ Aa)). Qed. Lemma group_modr A B G : B \subset G -> (G :&: A) * B = G :&: A * B. Proof. move=> sBG; apply: invg_inj; rewrite !(invMg, invIg) invGid !(setIC G). by rewrite group_modl // -invGid invSg. Qed. End GroupProp. #[global] Hint Extern 0 (is_true (1%g \in _)) => apply: group1 : core. #[global] Hint Extern 0 (is_true (0 < #|_|)) => apply: cardG_gt0 : core. #[global] Hint Extern 0 (is_true (0 < #|_ : _|)) => apply: indexg_gt0 : core. Notation "G :^ x" := (conjG_group G x) : Group_scope. Notation "[ 'subg' G ]" := (subg_of G) : type_scope. Notation "[ 'subg' G ]" := [set: subg_of G] : group_scope. Notation "[ 'subg' G ]" := [set: subg_of G]%G : Group_scope. Prenex Implicits subg sgval subg_of. Bind Scope group_scope with subg_of. Arguments subgK {gT G}. Arguments sgvalK {gT G}. Arguments subg_inj {gT G} [u1 u2] eq_u12 : rename. Arguments trivgP {gT G}. Arguments trivGP {gT G}. Arguments lcoset_eqP {gT G x y}. Arguments rcoset_eqP {gT G x y}. Arguments mulGidPl {gT G H}. Arguments mulGidPr {gT G H}. Arguments comm_group_setP {gT G H}. Arguments class_eqP {gT G x y}. Arguments repr_classesP {gT G xG}. Section GroupInter. Variable gT : finGroupType. Implicit Types A B : {set gT}. Implicit Types G H : {group gT}. Lemma group_setI G H : group_set (G :&: H). Proof. apply/group_setP; split=> [|x y]; rewrite !inE ?group1 //. by case/andP=> Gx Hx; rewrite !groupMl. Qed. Canonical setI_group G H := group (group_setI G H). Section Nary. Variables (I : finType) (P : pred I) (F : I -> {group gT}). Lemma group_set_bigcap : group_set (\bigcap_(i | P i) F i). Proof. by elim/big_rec: _ => [|i G _ gG]; rewrite -1?(insubdK 1%G gG) groupP. Qed. Canonical bigcap_group := group group_set_bigcap. End Nary. Lemma group_set_generated (A : {set gT}) : group_set <<A>>. Proof. by rewrite unlock group_set_bigcap. Qed. Canonical generated_group A := group (group_set_generated A). Canonical gcore_group G A : {group _} := Eval hnf in [group of gcore G A]. Canonical commutator_group A B : {group _} := Eval hnf in [group of [~: A, B]]. Canonical joing_group A B : {group _} := Eval hnf in [group of A <*> B]. Canonical cycle_group x : {group _} := Eval hnf in [group of <[x]>]. Definition joinG G H := joing_group G H. Definition subgroups A := [set G : {group gT} | G \subset A]. Lemma order_gt0 (x : gT) : 0 < #[x]. Proof. exact: cardG_gt0. Qed. End GroupInter. #[global] Hint Resolve order_gt0 : core. Arguments generated_group _ _%_g. Arguments joing_group _ _%_g _%_g. Arguments subgroups _ _%_g. Notation "G :&: H" := (setI_group G H) : Group_scope. Notation "<< A >>" := (generated_group A) : Group_scope. Notation "<[ x ] >" := (cycle_group x) : Group_scope. Notation "[ ~: A1 , A2 , .. , An ]" := (commutator_group .. (commutator_group A1 A2) .. An) : Group_scope. Notation "A <*> B" := (joing_group A B) : Group_scope. Notation "G * H" := (joinG G H) : Group_scope. Prenex Implicits joinG subgroups. Notation "\prod_ ( i <- r | P ) F" := (\big[joinG/1%G]_(i <- r | P%B) F%G) : Group_scope. Notation "\prod_ ( i <- r ) F" := (\big[joinG/1%G]_(i <- r) F%G) : Group_scope. Notation "\prod_ ( m <= i < n | P ) F" := (\big[joinG/1%G]_(m <= i < n | P%B) F%G) : Group_scope. Notation "\prod_ ( m <= i < n ) F" := (\big[joinG/1%G]_(m <= i < n) F%G) : Group_scope. Notation "\prod_ ( i | P ) F" := (\big[joinG/1%G]_(i | P%B) F%G) : Group_scope. Notation "\prod_ i F" := (\big[joinG/1%G]_i F%G) : Group_scope. Notation "\prod_ ( i : t | P ) F" := (\big[joinG/1%G]_(i : t | P%B) F%G) (only parsing) : Group_scope. Notation "\prod_ ( i : t ) F" := (\big[joinG/1%G]_(i : t) F%G) (only parsing) : Group_scope. Notation "\prod_ ( i < n | P ) F" := (\big[joinG/1%G]_(i < n | P%B) F%G) : Group_scope. Notation "\prod_ ( i < n ) F" := (\big[joinG/1%G]_(i < n) F%G) : Group_scope. Notation "\prod_ ( i 'in' A | P ) F" := (\big[joinG/1%G]_(i in A | P%B) F%G) : Group_scope. Notation "\prod_ ( i 'in' A ) F" := (\big[joinG/1%G]_(i in A) F%G) : Group_scope. Section Lagrange. Variable gT : finGroupType. Implicit Types G H K : {group gT}. Lemma LagrangeI G H : (#|G :&: H| * #|G : H|)%N = #|G|. Proof. rewrite -[#|G|]sum1_card (partition_big_imset (rcoset H)) /=. rewrite mulnC -sum_nat_const; apply: eq_bigr => _ /rcosetsP[x Gx ->]. rewrite -(card_rcoset _ x) -sum1_card; apply: eq_bigl => y. by rewrite rcosetE (sameP eqP rcoset_eqP) group_modr ?sub1set // !inE. Qed. Lemma divgI G H : #|G| %/ #|G :&: H| = #|G : H|. Proof. by rewrite -(LagrangeI G H) mulKn ?cardG_gt0. Qed. Lemma divg_index G H : #|G| %/ #|G : H| = #|G :&: H|. Proof. by rewrite -(LagrangeI G H) mulnK. Qed. Lemma dvdn_indexg G H : #|G : H| %| #|G|. Proof. by rewrite -(LagrangeI G H) dvdn_mull. Qed. Theorem Lagrange G H : H \subset G -> (#|H| * #|G : H|)%N = #|G|. Proof. by move/setIidPr=> sHG; rewrite -{1}sHG LagrangeI. Qed. Lemma cardSg G H : H \subset G -> #|H| %| #|G|. Proof. by move/Lagrange <-; rewrite dvdn_mulr. Qed. Lemma lognSg p G H : G \subset H -> logn p #|G| <= logn p #|H|. Proof. by move=> sGH; rewrite dvdn_leq_log ?cardSg. Qed. Lemma piSg G H : G \subset H -> {subset \pi(gval G) <= \pi(gval H)}. Proof. move=> sGH p; rewrite !mem_primes !cardG_gt0 => /and3P[-> _ pG]. exact: dvdn_trans (cardSg sGH). Qed. Lemma divgS G H : H \subset G -> #|G| %/ #|H| = #|G : H|. Proof. by move/Lagrange <-; rewrite mulKn. Qed. Lemma divg_indexS G H : H \subset G -> #|G| %/ #|G : H| = #|H|. Proof. by move/Lagrange <-; rewrite mulnK. Qed. Lemma coprimeSg G H p : H \subset G -> coprime #|G| p -> coprime #|H| p. Proof. by move=> sHG; apply: coprime_dvdl (cardSg sHG). Qed. Lemma coprimegS G H p : H \subset G -> coprime p #|G| -> coprime p #|H|. Proof. by move=> sHG; apply: coprime_dvdr (cardSg sHG). Qed. Lemma indexJg G H x : #|G :^ x : H :^ x| = #|G : H|. Proof. by rewrite -!divgI -conjIg !cardJg. Qed. Lemma indexgg G : #|G : G| = 1%N. Proof. by rewrite -divgS // divnn cardG_gt0. Qed. Lemma rcosets_id G : rcosets G G = [set G : {set gT}]. Proof. apply/esym/eqP; rewrite eqEcard sub1set [#|_|]indexgg cards1 andbT. by apply/rcosetsP; exists 1; rewrite ?mulg1. Qed. Lemma Lagrange_index G H K : H \subset G -> K \subset H -> (#|G : H| * #|H : K|)%N = #|G : K|. Proof. move=> sHG sKH; apply/eqP; rewrite mulnC -(eqn_pmul2l (cardG_gt0 K)). by rewrite mulnA !Lagrange // (subset_trans sKH). Qed. Lemma indexgI G H : #|G : G :&: H| = #|G : H|. Proof. by rewrite -[RHS]divgI divgS ?subsetIl. Qed. Lemma indexgS G H K : H \subset K -> #|G : K| %| #|G : H|. Proof. move=> sHK; rewrite -(@dvdn_pmul2l #|G :&: K|) ?cardG_gt0 // LagrangeI. by rewrite -(Lagrange (setIS G sHK)) mulnAC LagrangeI dvdn_mulr. Qed. Lemma indexSg G H K : H \subset K -> K \subset G -> #|K : H| %| #|G : H|. Proof. move=> sHK sKG; rewrite -(@dvdn_pmul2l #|H|) ?cardG_gt0 //. by rewrite !Lagrange ?(cardSg, subset_trans sHK). Qed. Lemma indexg_eq1 G H : (#|G : H| == 1%N) = (G \subset H). Proof. rewrite eqn_leq -(leq_pmul2l (cardG_gt0 (G :&: H))) LagrangeI muln1. by rewrite indexg_gt0 andbT (sameP setIidPl eqP) eqEcard subsetIl. Qed. Lemma indexg_gt1 G H : (#|G : H| > 1) = ~~ (G \subset H). Proof. by rewrite -indexg_eq1 eqn_leq indexg_gt0 andbT -ltnNge. Qed. Lemma index1g G H : H \subset G -> #|G : H| = 1%N -> H :=: G. Proof. by move=> sHG iHG; apply/eqP; rewrite eqEsubset sHG -indexg_eq1 iHG. Qed. Lemma indexg1 G : #|G : 1| = #|G|. Proof. by rewrite -divgS ?sub1G // cards1 divn1. Qed. Lemma indexMg G A : #|G * A : G| = #|A : G|. Proof. apply/eq_card/setP/eqP; rewrite eqEsubset andbC imsetS ?mulG_subr //. by apply/subsetP=> _ /rcosetsP[x GAx ->]; rewrite mem_rcosets. Qed. Lemma rcosets_partition_mul G H : partition (rcosets H G) (H * G). Proof. set HG := H * G; have sGHG: {subset G <= HG} by apply/subsetP/mulG_subr. have defHx x: x \in HG -> [set y in HG | rcoset H x == rcoset H y] = H :* x. move=> HGx; apply/setP=> y; rewrite inE !rcosetE (sameP eqP rcoset_eqP). by rewrite rcoset_sym; apply/andb_idl/subsetP; rewrite mulGS sub1set. have:= preim_partitionP (rcoset H) HG; congr (partition _ _); apply/setP=> Hx. apply/imsetP/idP=> [[x HGx ->] | ]; first by rewrite defHx // mem_rcosets. by case/rcosetsP=> x /sGHG-HGx ->; exists x; rewrite ?defHx. Qed. Lemma rcosets_partition G H : H \subset G -> partition (rcosets H G) G. Proof. by move=> sHG; have:= rcosets_partition_mul G H; rewrite mulSGid. Qed. Lemma LagrangeMl G H : (#|G| * #|H : G|)%N = #|G * H|. Proof. rewrite mulnC -(card_uniform_partition _ (rcosets_partition_mul H G)) //. by move=> _ /rcosetsP[x Hx ->]; rewrite card_rcoset. Qed. Lemma LagrangeMr G H : (#|G : H| * #|H|)%N = #|G * H|. Proof. by rewrite mulnC LagrangeMl -card_invg invMg !invGid. Qed. Lemma mul_cardG G H : (#|G| * #|H| = #|G * H|%g * #|G :&: H|)%N. Proof. by rewrite -LagrangeMr -(LagrangeI G H) -mulnA mulnC. Qed. Lemma dvdn_cardMg G H : #|G * H| %| #|G| * #|H|. Proof. by rewrite mul_cardG dvdn_mulr. Qed. Lemma cardMg_divn G H : #|G * H| = (#|G| * #|H|) %/ #|G :&: H|. Proof. by rewrite mul_cardG mulnK ?cardG_gt0. Qed. Lemma cardIg_divn G H : #|G :&: H| = (#|G| * #|H|) %/ #|G * H|. Proof. by rewrite mul_cardG mulKn // (cardD1 (1 * 1)) mem_mulg. Qed. Lemma TI_cardMg G H : G :&: H = 1 -> #|G * H| = (#|G| * #|H|)%N. Proof. by move=> tiGH; rewrite mul_cardG tiGH cards1 muln1. Qed. Lemma cardMg_TI G H : #|G| * #|H| <= #|G * H| -> G :&: H = 1. Proof. move=> leGH; apply: card_le1_trivg. rewrite -(@leq_pmul2l #|G * H|); first by rewrite -mul_cardG muln1. by apply: leq_trans leGH; rewrite muln_gt0 !cardG_gt0. Qed. Lemma coprime_TIg G H : coprime #|G| #|H| -> G :&: H = 1. Proof. move=> coGH; apply/eqP; rewrite trivg_card1 -dvdn1 -{}(eqnP coGH). by rewrite dvdn_gcd /= {2}setIC !cardSg ?subsetIl. Qed. Lemma prime_TIg G H : prime #|G| -> ~~ (G \subset H) -> G :&: H = 1. Proof. case/primeP=> _ /(_ _ (cardSg (subsetIl G H))). rewrite (sameP setIidPl eqP) eqEcard subsetIl => /pred2P[/card1_trivg|] //= ->. by case/negP. Qed. Lemma prime_meetG G H : prime #|G| -> G :&: H != 1 -> G \subset H. Proof. by move=> prG; apply: contraR; move/prime_TIg->. Qed. Lemma coprime_cardMg G H : coprime #|G| #|H| -> #|G * H| = (#|G| * #|H|)%N. Proof. by move=> coGH; rewrite TI_cardMg ?coprime_TIg. Qed. Lemma coprime_index_mulG G H K : H \subset G -> K \subset G -> coprime #|G : H| #|G : K| -> H * K = G. Proof. move=> sHG sKG co_iG_HK; apply/eqP; rewrite eqEcard mul_subG //=. rewrite -(@leq_pmul2r #|H :&: K|) ?cardG_gt0 // -mul_cardG. rewrite -(Lagrange sHG) -(LagrangeI K H) mulnAC setIC -mulnA. rewrite !leq_pmul2l ?cardG_gt0 // dvdn_leq // -(Gauss_dvdr _ co_iG_HK). by rewrite -(indexgI K) Lagrange_index ?indexgS ?subsetIl ?subsetIr. Qed. End Lagrange. Section GeneratedGroup. Variable gT : finGroupType. Implicit Types x y z : gT. Implicit Types A B C D : {set gT}. Implicit Types G H K : {group gT}. Lemma subset_gen A : A \subset <<A>>. Proof. rewrite [@generated]unlock; exact/bigcapsP. Qed. Lemma sub_gen A B : A \subset B -> A \subset <<B>>. Proof. by move/subset_trans=> -> //; apply: subset_gen. Qed. Lemma mem_gen x A : x \in A -> x \in <<A>>. Proof. exact: subsetP (subset_gen A) x. Qed. Lemma generatedP x A : reflect (forall G, A \subset G -> x \in G) (x \in <<A>>). Proof. rewrite [@generated]unlock; exact: bigcapP. Qed. Lemma gen_subG A G : (<<A>> \subset G) = (A \subset G). Proof. apply/idP/idP=> [|sAG]; first exact: subset_trans (subset_gen A). by apply/subsetP=> x /generatedP; apply. Qed. Lemma genGid G : <<G>> = G. Proof. by apply/eqP; rewrite eqEsubset gen_subG subset_gen andbT. Qed. Lemma genGidG G : <<G>>%G = G. Proof. by apply: val_inj; apply: genGid. Qed. Lemma gen_set_id A : group_set A -> <<A>> = A. Proof. by move=> gA; apply: (genGid (group gA)). Qed. Lemma genS A B : A \subset B -> <<A>> \subset <<B>>. Proof. by move=> sAB; rewrite gen_subG sub_gen. Qed. Lemma gen0 : <<set0>> = 1 :> {set gT}. Proof. by apply/eqP; rewrite eqEsubset sub1G gen_subG sub0set. Qed. Lemma gen_expgs A : {n | <<A>> = (1 |: A) ^+ n}. Proof. set B := (1 |: A); pose N := #|gT|. have BsubG n : B ^+ n \subset <<A>>. by elim: n => [|n IHn]; rewrite ?expgS ?mul_subG ?subUset ?sub1G ?subset_gen. have B_1 n : 1 \in B ^+ n. by elim: n => [|n IHn]; rewrite ?set11 // expgS mulUg mul1g inE IHn. case: (pickP (fun i : 'I_N => B ^+ i.+1 \subset B ^+ i)) => [n fixBn | no_fix]. exists n; apply/eqP; rewrite eqEsubset BsubG andbT. rewrite -[B ^+ n]gen_set_id ?genS ?subsetUr //. by apply: subset_trans fixBn; rewrite expgS mulUg subsetU ?mulg_subl ?orbT. rewrite /group_set B_1 /=. elim: {2}(n : nat) => [|m IHm]; first by rewrite mulg1. by apply: subset_trans fixBn; rewrite !expgSr mulgA mulSg. suffices: N < #|B ^+ N| by rewrite ltnNge max_card. have [] := ubnPgeq N; elim=> [|n IHn] lt_nN; first by rewrite cards1. apply: leq_ltn_trans (IHn (ltnW lt_nN)) (proper_card _). by rewrite /proper (no_fix (Ordinal lt_nN)) expgS mulUg mul1g subsetUl. Qed. Lemma gen_prodgP A x : reflect (exists n, exists2 c, forall i : 'I_n, c i \in A & x = \prod_i c i) (x \in <<A>>). Proof. apply: (iffP idP) => [|[n [c Ac ->]]]; last first. by apply: group_prod => i _; rewrite mem_gen ?Ac. have [n ->] := gen_expgs A; rewrite /expgn Monoid.iteropE /=. rewrite -[n]card_ord -big_const => /prodsgP[/= c Ac def_x]. have{Ac def_x} ->: x = \prod_(i | c i \in A) c i. rewrite big_mkcond {x}def_x; apply: eq_bigr => i _. by case/setU1P: (Ac i isT) => -> //; rewrite if_same. have [e <- [_ /= mem_e] _] := big_enumP [preim c of A]. pose t := in_tuple e; rewrite -[e]/(val t) big_tuple. by exists (size e), (c \o tnth t) => // i; rewrite -mem_e mem_tnth. Qed. Lemma genD A B : A \subset <<A :\: B>> -> <<A :\: B>> = <<A>>. Proof. by move=> sAB; apply/eqP; rewrite eqEsubset genS (subsetDl, gen_subG). Qed. Lemma genV A : <<A^-1>> = <<A>>. Proof. apply/eqP; rewrite eqEsubset !gen_subG -!(invSg _ <<_>>) invgK. by rewrite !invGid !subset_gen. Qed. Lemma genJ A z : <<A :^z>> = <<A>> :^ z. Proof. by apply/eqP; rewrite eqEsubset sub_conjg !gen_subG conjSg -?sub_conjg !sub_gen. Qed. Lemma conjYg A B z : (A <*> B) :^z = A :^ z <*> B :^ z. Proof. by rewrite -genJ conjUg. Qed. Lemma genD1 A x : x \in <<A :\ x>> -> <<A :\ x>> = <<A>>. Proof. move=> gA'x; apply/eqP; rewrite eqEsubset genS; last by rewrite subsetDl. rewrite gen_subG; apply/subsetP=> y Ay. by case: (y =P x) => [-> //|]; move/eqP=> nyx; rewrite mem_gen // !inE nyx. Qed. Lemma genD1id A : <<A^#>> = <<A>>. Proof. by rewrite genD1 ?group1. Qed. Notation joingT := (@joing gT) (only parsing). Notation joinGT := (@joinG gT) (only parsing). Lemma joingE A B : A <*> B = <<A :|: B>>. Proof. by []. Qed. Lemma joinGE G H : (G * H)%G = (G <*> H)%G. Proof. by []. Qed. Lemma joingC : commutative joingT. Proof. by move=> A B; rewrite /joing setUC. Qed. Lemma joing_idr A B : A <*> <<B>> = A <*> B. Proof. apply/eqP; rewrite eqEsubset gen_subG subUset gen_subG /=. by rewrite -subUset subset_gen genS // setUS // subset_gen. Qed. Lemma joing_idl A B : <<A>> <*> B = A <*> B. Proof. by rewrite -!(joingC B) joing_idr. Qed. Lemma joing_subl A B : A \subset A <*> B. Proof. by rewrite sub_gen ?subsetUl. Qed. Lemma joing_subr A B : B \subset A <*> B. Proof. by rewrite sub_gen ?subsetUr. Qed. Lemma join_subG A B G : (A <*> B \subset G) = (A \subset G) && (B \subset G). Proof. by rewrite gen_subG subUset. Qed. Lemma joing_idPl G A : reflect (G <*> A = G) (A \subset G). Proof. apply: (iffP idP) => [sHG | <-]; last by rewrite joing_subr. by rewrite joingE (setUidPl sHG) genGid. Qed. Lemma joing_idPr A G : reflect (A <*> G = G) (A \subset G). Proof. by rewrite joingC; apply: joing_idPl. Qed. Lemma joing_subP A B G : reflect (A \subset G /\ B \subset G) (A <*> B \subset G). Proof. by rewrite join_subG; apply: andP. Qed. Lemma joing_sub A B C : A <*> B = C -> A \subset C /\ B \subset C. Proof. by move <-; apply/joing_subP. Qed. Lemma genDU A B C : A \subset C -> <<C :\: A>> = <<B>> -> <<A :|: B>> = <<C>>. Proof. move=> sAC; rewrite -joingE -joing_idr => <- {B}; rewrite joing_idr. by congr <<_>>; rewrite setDE setUIr setUCr setIT; apply/setUidPr. Qed. Lemma joingA : associative joingT. Proof. by move=> A B C; rewrite joing_idl joing_idr /joing setUA. Qed. Lemma joing1G G : 1 <*> G = G. Proof. by rewrite -gen0 joing_idl /joing set0U genGid. Qed. Lemma joingG1 G : G <*> 1 = G. Proof. by rewrite joingC joing1G. Qed. Lemma genM_join G H : <<G * H>> = G <*> H. Proof. apply/eqP; rewrite eqEsubset gen_subG /= -{1}[G <*> H]mulGid. rewrite genS; last by rewrite subUset mulG_subl mulG_subr. by rewrite mulgSS ?(sub_gen, subsetUl, subsetUr). Qed. Lemma mulG_subG G H K : (G * H \subset K) = (G \subset K) && (H \subset K). Proof. by rewrite -gen_subG genM_join join_subG. Qed. Lemma mulGsubP K H G : reflect (K \subset G /\ H \subset G) (K * H \subset G). Proof. by rewrite mulG_subG; apply: andP. Qed. Lemma mulG_sub K H A : K * H = A -> K \subset A /\ H \subset A. Proof. by move <-; rewrite mulG_subl mulG_subr. Qed. Lemma trivMg G H : (G * H == 1) = (G :==: 1) && (H :==: 1). Proof. by rewrite !eqEsubset -{2}[1]mulGid mulgSS ?sub1G // !andbT mulG_subG. Qed. Lemma comm_joingE G H : commute G H -> G <*> H = G * H. Proof. by move/comm_group_setP=> gGH; rewrite -genM_join; apply: (genGid (group gGH)). Qed. Lemma joinGC : commutative joinGT. Proof. by move=> G H; apply: val_inj; apply: joingC. Qed. Lemma joinGA : associative joinGT. Proof. by move=> G H K; apply: val_inj; apply: joingA. Qed. Lemma join1G : left_id 1%G joinGT. Proof. by move=> G; apply: val_inj; apply: joing1G. Qed. Lemma joinG1 : right_id 1%G joinGT. Proof. by move=> G; apply: val_inj; apply: joingG1. Qed. HB.instance Definition _ := Monoid.isComLaw.Build {group gT} 1%G joinGT joinGA joinGC join1G. Lemma bigprodGEgen I r (P : pred I) (F : I -> {set gT}) : (\prod_(i <- r | P i) <<F i>>)%G :=: << \bigcup_(i <- r | P i) F i >>. Proof. elim/big_rec2: _ => /= [|i A _ _ ->]; first by rewrite gen0. by rewrite joing_idl joing_idr. Qed. Lemma bigprodGE I r (P : pred I) (F : I -> {group gT}) : (\prod_(i <- r | P i) F i)%G :=: << \bigcup_(i <- r | P i) F i >>. Proof. rewrite -bigprodGEgen /=; apply: congr_group. by apply: eq_bigr => i _; rewrite genGidG. Qed. Lemma mem_commg A B x y : x \in A -> y \in B -> [~ x, y] \in [~: A, B]. Proof. by move=> Ax By; rewrite mem_gen ?imset2_f. Qed. Lemma commSg A B C : A \subset B -> [~: A, C] \subset [~: B, C]. Proof. by move=> sAC; rewrite genS ?imset2S. Qed. Lemma commgS A B C : B \subset C -> [~: A, B] \subset [~: A, C]. Proof. by move=> sBC; rewrite genS ?imset2S. Qed. Lemma commgSS A B C D : A \subset B -> C \subset D -> [~: A, C] \subset [~: B, D]. Proof. by move=> sAB sCD; rewrite genS ?imset2S. Qed. Lemma der1_subG G : [~: G, G] \subset G. Proof. by rewrite gen_subG; apply/subsetP=> _ /imset2P[x y Gx Gy ->]; apply: groupR. Qed. Lemma comm_subG A B G : A \subset G -> B \subset G -> [~: A, B] \subset G. Proof. by move=> sAG sBG; apply: subset_trans (der1_subG G); apply: commgSS. Qed. Lemma commGC A B : [~: A, B] = [~: B, A]. Proof. rewrite -[[~: A, B]]genV; congr <<_>>; apply/setP=> z; rewrite inE. by apply/imset2P/imset2P=> [] [x y Ax Ay]; last rewrite -{1}(invgK z); rewrite -invg_comm => /invg_inj->; exists y x. Qed. Lemma conjsRg A B x : [~: A, B] :^ x = [~: A :^ x, B :^ x]. Proof. wlog suffices: A B x / [~: A, B] :^ x \subset [~: A :^ x, B :^ x]. move=> subJ; apply/eqP; rewrite eqEsubset subJ /= -sub_conjgV. by rewrite -{2}(conjsgK x A) -{2}(conjsgK x B). rewrite -genJ gen_subG; apply/subsetP=> _ /imsetP[_ /imset2P[y z Ay Bz ->] ->]. by rewrite conjRg mem_commg ?memJ_conjg. Qed. End GeneratedGroup. Arguments gen_prodgP {gT A x}. Arguments joing_idPl {gT G A}. Arguments joing_idPr {gT A G}. Arguments mulGsubP {gT K H G}. Arguments joing_subP {gT A B G}. Section Cycles. (* Elementary properties of cycles and order, needed in perm.v. *) (* More advanced results on the structure of cyclic groups will *) (* be given in cyclic.v. *) Variable gT : finGroupType. Implicit Types x y : gT. Implicit Types G : {group gT}. Import Monoid.Theory. Lemma cycle1 : <[1]> = [1 gT]. Proof. exact: genGid. Qed. Lemma order1 : #[1 : gT] = 1%N. Proof. by rewrite /order cycle1 cards1. Qed. Lemma cycle_id x : x \in <[x]>. Proof. by rewrite mem_gen // set11. Qed. Lemma mem_cycle x i : x ^+ i \in <[x]>. Proof. by rewrite groupX // cycle_id. Qed. Lemma cycle_subG x G : (<[x]> \subset G) = (x \in G). Proof. by rewrite gen_subG sub1set. Qed. Lemma cycle_eq1 x : (<[x]> == 1) = (x == 1). Proof. by rewrite eqEsubset sub1G andbT cycle_subG inE. Qed. Lemma orderE x : #[x] = #|<[x]>|. Proof. by []. Qed. Lemma order_eq1 x : (#[x] == 1%N) = (x == 1). Proof. by rewrite -trivg_card1 cycle_eq1. Qed. Lemma order_gt1 x : (#[x] > 1) = (x != 1). Proof. by rewrite ltnNge -trivg_card_le1 cycle_eq1. Qed. Lemma cycle_traject x : <[x]> =i traject (mulg x) 1 #[x]. Proof. set t := _ 1; apply: fsym; apply/subset_cardP; last first. by apply/subsetP=> _ /trajectP[i _ ->]; rewrite -iteropE mem_cycle. rewrite (card_uniqP _) ?size_traject //; case def_n: #[_] => // [n]. rewrite looping_uniq; apply: contraL (card_size (t n)) => /loopingP t_xi. rewrite -ltnNge size_traject -def_n ?subset_leq_card //. rewrite -(eq_subset_r (in_set _)) {}/t; set G := finset _. rewrite -[x]mulg1 -[G]gen_set_id ?genS ?sub1set ?inE ?(t_xi 1%N)//. apply/group_setP; split=> [|y z]; rewrite !inE ?(t_xi 0) //. by do 2!case/trajectP=> ? _ ->; rewrite -!iteropE -expgD [x ^+ _]iteropE. Qed. Lemma cycle2g x : #[x] = 2 -> <[x]> = [set 1; x]. Proof. by move=> ox; apply/setP=> y; rewrite cycle_traject ox !inE mulg1. Qed. Lemma cyclePmin x y : y \in <[x]> -> {i | i < #[x] & y = x ^+ i}. Proof. rewrite cycle_traject; set tx := traject _ _ #[x] => tx_y; pose i := index y tx. have lt_i_x : i < #[x] by rewrite -index_mem size_traject in tx_y. by exists i; rewrite // [x ^+ i]iteropE /= -(nth_traject _ lt_i_x) nth_index. Qed. Lemma cycleP x y : reflect (exists i, y = x ^+ i) (y \in <[x]>). Proof. by apply: (iffP idP) => [/cyclePmin[i _]|[i ->]]; [exists i | apply: mem_cycle]. Qed. Lemma expg_order x : x ^+ #[x] = 1. Proof. have: uniq (traject (mulg x) 1 #[x]). by apply/card_uniqP; rewrite size_traject -(eq_card (cycle_traject x)). case/cyclePmin: (mem_cycle x #[x]) => [] [//|i] ltix. rewrite -(subnKC ltix) addSnnS /= expgD; move: (_ - _) => j x_j1. case/andP=> /trajectP[]; exists j; first exact: leq_addl. by apply: (mulgI (x ^+ i.+1)); rewrite -iterSr iterS -iteropE -expgS mulg1. Qed. Lemma expg_mod p k x : x ^+ p = 1 -> x ^+ (k %% p) = x ^+ k. Proof. move=> xp. by rewrite {2}(divn_eq k p) expgD mulnC expgM xp expg1n mul1g. Qed. Lemma expg_mod_order x i : x ^+ (i %% #[x]) = x ^+ i. Proof. by rewrite expg_mod // expg_order. Qed. Lemma invg_expg x : x^-1 = x ^+ #[x].-1. Proof. by apply/eqP; rewrite eq_invg_mul -expgS prednK ?expg_order. Qed. Lemma invg2id x : #[x] = 2 -> x^-1 = x. Proof. by move=> ox; rewrite invg_expg ox. Qed. Lemma cycleX x i : <[x ^+ i]> \subset <[x]>. Proof. by rewrite cycle_subG; apply: mem_cycle. Qed. Lemma cycleV x : <[x^-1]> = <[x]>. Proof. by apply/eqP; rewrite eq_sym eqEsubset !cycle_subG groupV -groupV !cycle_id. Qed. Lemma orderV x : #[x^-1] = #[x]. Proof. by rewrite /order cycleV. Qed. Lemma cycleJ x y : <[x ^ y]> = <[x]> :^ y. Proof. by rewrite -genJ conjg_set1. Qed. Lemma orderJ x y : #[x ^ y] = #[x]. Proof. by rewrite /order cycleJ cardJg. Qed. End Cycles. Section Normaliser. Variable gT : finGroupType. Implicit Types x y z : gT. Implicit Types A B C D : {set gT}. Implicit Type G H K : {group gT}. Lemma normP x A : reflect (A :^ x = A) (x \in 'N(A)). Proof. suffices ->: (x \in 'N(A)) = (A :^ x == A) by apply: eqP. by rewrite eqEcard cardJg leqnn andbT inE. Qed. Arguments normP {x A}. Lemma group_set_normaliser A : group_set 'N(A). Proof. apply/group_setP; split=> [|x y Nx Ny]; rewrite inE ?conjsg1 //. by rewrite conjsgM !(normP _). Qed. Canonical normaliser_group A := group (group_set_normaliser A). Lemma normsP A B : reflect {in A, normalised B} (A \subset 'N(B)). Proof. apply: (iffP subsetP) => nBA x Ax; last by rewrite inE nBA //. by apply/normP; apply: nBA. Qed. Arguments normsP {A B}. Lemma memJ_norm x y A : x \in 'N(A) -> (y ^ x \in A) = (y \in A). Proof. by move=> Nx; rewrite -{1}(normP Nx) memJ_conjg. Qed. Lemma norms_cycle x y : (<[y]> \subset 'N(<[x]>)) = (x ^ y \in <[x]>). Proof. by rewrite cycle_subG inE -cycleJ cycle_subG. Qed. Lemma norm1 : 'N(1) = setT :> {set gT}. Proof. by apply/setP=> x; rewrite !inE conjs1g subxx. Qed. Lemma norms1 A : A \subset 'N(1). Proof. by rewrite norm1 subsetT. Qed. Lemma normCs A : 'N(~: A) = 'N(A). Proof. by apply/setP=> x; rewrite -groupV !inE conjCg setCS sub_conjg. Qed. Lemma normG G : G \subset 'N(G). Proof. by apply/normsP; apply: conjGid. Qed. Lemma normT : 'N([set: gT]) = [set: gT]. Proof. by apply/eqP; rewrite -subTset normG. Qed. Lemma normsG A G : A \subset G -> A \subset 'N(G). Proof. by move=> sAG; apply: subset_trans (normG G). Qed. Lemma normC A B : A \subset 'N(B) -> commute A B. Proof. move/subsetP=> nBA; apply/setP=> u. apply/mulsgP/mulsgP=> [[x y Ax By] | [y x By Ax]] -> {u}. by exists (y ^ x^-1) x; rewrite -?conjgCV // memJ_norm // groupV nBA. by exists x (y ^ x); rewrite -?conjgC // memJ_norm // nBA. Qed. Lemma norm_joinEl G H : G \subset 'N(H) -> G <*> H = G * H. Proof. by move/normC/comm_joingE. Qed. Lemma norm_joinEr G H : H \subset 'N(G) -> G <*> H = G * H. Proof. by move/normC=> cHG; apply: comm_joingE. Qed. Lemma norm_rlcoset G x : x \in 'N(G) -> G :* x = x *: G. Proof. by rewrite -sub1set => /normC. Qed. Lemma rcoset_mul G x y : x \in 'N(G) -> (G :* x) * (G :* y) = G :* (x * y). Proof. move/norm_rlcoset=> GxxG. by rewrite mulgA -(mulgA _ _ G) -GxxG mulgA mulGid -mulgA mulg_set1. Qed. Lemma normJ A x : 'N(A :^ x) = 'N(A) :^ x. Proof. by apply/setP=> y; rewrite mem_conjg !inE -conjsgM conjgCV conjsgM conjSg. Qed. Lemma norm_conj_norm x A B : x \in 'N(A) -> (A \subset 'N(B :^ x)) = (A \subset 'N(B)). Proof. by move=> Nx; rewrite normJ -sub_conjgV (normP _) ?groupV. Qed. Lemma norm_gen A : 'N(A) \subset 'N(<<A>>). Proof. by apply/normsP=> x Nx; rewrite -genJ (normP Nx). Qed. Lemma class_norm x G : G \subset 'N(x ^: G). Proof. by apply/normsP=> y; apply: classGidr. Qed. Lemma class_normal x G : x \in G -> x ^: G <| G. Proof. by move=> Gx; rewrite /normal class_norm class_subG. Qed. Lemma class_sub_norm G A x : G \subset 'N(A) -> (x ^: G \subset A) = (x \in A). Proof. move=> nAG; apply/subsetP/idP=> [-> // | Ax xy]; first exact: class_refl. by case/imsetP=> y Gy ->; rewrite memJ_norm ?(subsetP nAG). Qed. Lemma class_support_norm A G : G \subset 'N(class_support A G). Proof. by apply/normsP; apply: class_supportGidr. Qed. Lemma class_support_sub_norm A B G : A \subset G -> B \subset 'N(G) -> class_support A B \subset G. Proof. move=> sAG nGB; rewrite class_supportEr. by apply/bigcupsP=> x Bx; rewrite -(normsP nGB x Bx) conjSg. Qed. Section norm_trans. Variables (A B C D : {set gT}). Hypotheses (nBA : A \subset 'N(B)) (nCA : A \subset 'N(C)). Lemma norms_gen : A \subset 'N(<<B>>). Proof. exact: subset_trans nBA (norm_gen B). Qed. Lemma norms_norm : A \subset 'N('N(B)). Proof. by apply/normsP=> x Ax; rewrite -normJ (normsP nBA). Qed. Lemma normsI : A \subset 'N(B :&: C). Proof. by apply/normsP=> x Ax; rewrite conjIg !(normsP _ x Ax). Qed. Lemma normsU : A \subset 'N(B :|: C). Proof. by apply/normsP=> x Ax; rewrite conjUg !(normsP _ x Ax). Qed. Lemma normsIs : B \subset 'N(D) -> A :&: B \subset 'N(C :&: D). Proof. move/normsP=> nDB; apply/normsP=> x; case/setIP=> Ax Bx. by rewrite conjIg (normsP nCA) ?nDB. Qed. Lemma normsD : A \subset 'N(B :\: C). Proof. by apply/normsP=> x Ax; rewrite conjDg !(normsP _ x Ax). Qed. Lemma normsM : A \subset 'N(B * C). Proof. by apply/normsP=> x Ax; rewrite conjsMg !(normsP _ x Ax). Qed. Lemma normsY : A \subset 'N(B <*> C). Proof. by apply/normsP=> x Ax; rewrite -genJ conjUg !(normsP _ x Ax). Qed. Lemma normsR : A \subset 'N([~: B, C]). Proof. by apply/normsP=> x Ax; rewrite conjsRg !(normsP _ x Ax). Qed. Lemma norms_class_support : A \subset 'N(class_support B C). Proof. apply/subsetP=> x Ax; rewrite inE sub_conjg class_supportEr. apply/bigcupsP=> y Cy; rewrite -sub_conjg -conjsgM conjgC conjsgM. by rewrite (normsP nBA) // bigcup_sup ?memJ_norm ?(subsetP nCA). Qed. End norm_trans. Lemma normsIG A B G : A \subset 'N(B) -> A :&: G \subset 'N(B :&: G). Proof. by move/normsIs->; rewrite ?normG. Qed. Lemma normsGI A B G : A \subset 'N(B) -> G :&: A \subset 'N(G :&: B). Proof. by move=> nBA; rewrite !(setIC G) normsIG. Qed. Lemma norms_bigcap I r (P : pred I) A (B_ : I -> {set gT}) : A \subset \bigcap_(i <- r | P i) 'N(B_ i) -> A \subset 'N(\bigcap_(i <- r | P i) B_ i). Proof. elim/big_rec2: _ => [|i B N _ IH /subsetIP[nBiA /IH]]; last exact: normsI. by rewrite normT. Qed. Lemma norms_bigcup I r (P : pred I) A (B_ : I -> {set gT}) : A \subset \bigcap_(i <- r | P i) 'N(B_ i) -> A \subset 'N(\bigcup_(i <- r | P i) B_ i). Proof. move=> nBA; rewrite -normCs setC_bigcup norms_bigcap //. by rewrite (eq_bigr _ (fun _ _ => normCs _)). Qed. Lemma normsD1 A B : A \subset 'N(B) -> A \subset 'N(B^#). Proof. by move/normsD->; rewrite ?norms1. Qed. Lemma normD1 A : 'N(A^#) = 'N(A). Proof. apply/eqP; rewrite eqEsubset normsD1 //. rewrite -{2}(setID A 1) setIC normsU //; apply/normsP=> x _; apply/setP=> y. by rewrite conjIg conjs1g !inE mem_conjg; case: eqP => // ->; rewrite conj1g. Qed. Lemma normalP A B : reflect (A \subset B /\ {in B, normalised A}) (A <| B). Proof. by apply: (iffP andP)=> [] [sAB]; move/normsP. Qed. Lemma normal_sub A B : A <| B -> A \subset B. Proof. by case/andP. Qed. Lemma normal_norm A B : A <| B -> B \subset 'N(A). Proof. by case/andP. Qed. Lemma normalS G H K : K \subset H -> H \subset G -> K <| G -> K <| H. Proof. by move=> sKH sHG /andP[_ nKG]; rewrite /(K <| _) sKH (subset_trans sHG). Qed. Lemma normal1 G : 1 <| G. Proof. by rewrite /normal sub1set group1 norms1. Qed. Lemma normal_refl G : G <| G. Proof. by rewrite /(G <| _) normG subxx. Qed. Lemma normalG G : G <| 'N(G). Proof. by rewrite /(G <| _) normG subxx. Qed. Lemma normalSG G H : H \subset G -> H <| 'N_G(H). Proof. by move=> sHG; rewrite /normal subsetI sHG normG subsetIr. Qed. Lemma normalJ A B x : (A :^ x <| B :^ x) = (A <| B). Proof. by rewrite /normal normJ !conjSg. Qed. Lemma normalM G A B : A <| G -> B <| G -> A * B <| G. Proof. by case/andP=> sAG nAG /andP[sBG nBG]; rewrite /normal mul_subG ?normsM. Qed. Lemma normalY G A B : A <| G -> B <| G -> A <*> B <| G. Proof. by case/andP=> sAG ? /andP[sBG ?]; rewrite /normal join_subG sAG sBG ?normsY. Qed. Lemma normalYl G H : (H <| H <*> G) = (G \subset 'N(H)). Proof. by rewrite /normal joing_subl join_subG normG. Qed. Lemma normalYr G H : (H <| G <*> H) = (G \subset 'N(H)). Proof. by rewrite joingC normalYl. Qed. Lemma normalI G A B : A <| G -> B <| G -> A :&: B <| G. Proof. by case/andP=> sAG nAG /andP[_ nBG]; rewrite /normal subIset ?sAG // normsI. Qed. Lemma norm_normalI G A : G \subset 'N(A) -> G :&: A <| G. Proof. by move=> nAG; rewrite /normal subsetIl normsI ?normG. Qed. Lemma normalGI G H A : H \subset G -> A <| G -> H :&: A <| H. Proof. by move=> sHG /andP[_ nAG]; apply: norm_normalI (subset_trans sHG nAG). Qed. Lemma normal_subnorm G H : (H <| 'N_G(H)) = (H \subset G). Proof. by rewrite /normal subsetIr subsetI normG !andbT. Qed. Lemma normalD1 A G : (A^# <| G) = (A <| G). Proof. by rewrite /normal normD1 subDset (setUidPr (sub1G G)). Qed. Lemma gcore_sub A G : gcore A G \subset A. Proof. by rewrite (bigcap_min 1) ?conjsg1. Qed. Lemma gcore_norm A G : G \subset 'N(gcore A G). Proof. apply/subsetP=> x Gx; rewrite inE; apply/bigcapsP=> y Gy. by rewrite sub_conjg -conjsgM bigcap_inf ?groupM ?groupV. Qed. Lemma gcore_normal A G : A \subset G -> gcore A G <| G. Proof. by move=> sAG; rewrite /normal gcore_norm (subset_trans (gcore_sub A G)). Qed. Lemma gcore_max A B G : B \subset A -> G \subset 'N(B) -> B \subset gcore A G. Proof. move=> sBA nBG; apply/bigcapsP=> y Gy. by rewrite -sub_conjgV (normsP nBG) ?groupV. Qed. Lemma sub_gcore A B G : G \subset 'N(B) -> (B \subset gcore A G) = (B \subset A). Proof. move=> nBG; apply/idP/idP=> [sBAG | sBA]; last exact: gcore_max. exact: subset_trans (gcore_sub A G). Qed. (* An elementary proof that subgroups of index 2 are normal; it is almost as *) (* short as the "advanced" proof using group actions; besides, the fact that *) (* the coset is equal to the complement is used in extremal.v. *) Lemma rcoset_index2 G H x : H \subset G -> #|G : H| = 2 -> x \in G :\: H -> H :* x = G :\: H. Proof. move=> sHG indexHG => /setDP[Gx notHx]; apply/eqP. rewrite eqEcard -(leq_add2l #|G :&: H|) cardsID -(LagrangeI G H) indexHG muln2. rewrite (setIidPr sHG) card_rcoset addnn leqnn andbT. apply/subsetP=> _ /rcosetP[y Hy ->]; apply/setDP. by rewrite !groupMl // (subsetP sHG). Qed. Lemma index2_normal G H : H \subset G -> #|G : H| = 2 -> H <| G. Proof. move=> sHG indexHG; rewrite /normal sHG; apply/subsetP=> x Gx. case Hx: (x \in H); first by rewrite inE conjGid. rewrite inE conjsgE mulgA -sub_rcosetV -invg_rcoset. by rewrite !(rcoset_index2 sHG) ?inE ?groupV ?Hx // invDg !invGid. Qed. Lemma cent1P x y : reflect (commute x y) (x \in 'C[y]). Proof. rewrite [x \in _]inE conjg_set1 sub1set !inE (sameP eqP conjg_fixP)commg1_sym. exact: commgP. Qed. Lemma cent1id x : x \in 'C[x]. Proof. exact/cent1P. Qed. Lemma cent1E x y : (x \in 'C[y]) = (x * y == y * x). Proof. by rewrite (sameP (cent1P x y) eqP). Qed. Lemma cent1C x y : (x \in 'C[y]) = (y \in 'C[x]). Proof. by rewrite !cent1E eq_sym. Qed. Canonical centraliser_group A : {group _} := Eval hnf in [group of 'C(A)]. Lemma cent_set1 x : 'C([set x]) = 'C[x]. Proof. by apply: big_pred1 => y /=; rewrite !inE. Qed. Lemma cent1J x y : 'C[x ^ y] = 'C[x] :^ y. Proof. by rewrite -conjg_set1 normJ. Qed. Lemma centP A x : reflect (centralises x A) (x \in 'C(A)). Proof. by apply: (iffP bigcapP) => cxA y /cxA/cent1P. Qed. Lemma centsP A B : reflect {in A, centralised B} (A \subset 'C(B)). Proof. by apply: (iffP subsetP) => cAB x /cAB/centP. Qed. Lemma centsC A B : (A \subset 'C(B)) = (B \subset 'C(A)). Proof. by apply/centsP/centsP=> cAB x ? y ?; rewrite /commute -cAB. Qed. Lemma cents1 A : A \subset 'C(1). Proof. by rewrite centsC sub1G. Qed. Lemma cent1T : 'C(1) = setT :> {set gT}. Proof. by apply/eqP; rewrite -subTset cents1. Qed. Lemma cent11T : 'C[1] = setT :> {set gT}. Proof. by rewrite -cent_set1 cent1T. Qed. Lemma cent_sub A : 'C(A) \subset 'N(A). Proof. apply/subsetP=> x /centP cAx; rewrite inE. by apply/subsetP=> _ /imsetP[y Ay ->]; rewrite /conjg -cAx ?mulKg. Qed. Lemma cents_norm A B : A \subset 'C(B) -> A \subset 'N(B). Proof. by move=> cAB; apply: subset_trans (cent_sub B). Qed. Lemma centC A B : A \subset 'C(B) -> commute A B. Proof. by move=> cAB; apply: normC (cents_norm cAB). Qed. Lemma cent_joinEl G H : G \subset 'C(H) -> G <*> H = G * H. Proof. by move=> cGH; apply: norm_joinEl (cents_norm cGH). Qed. Lemma cent_joinEr G H : H \subset 'C(G) -> G <*> H = G * H. Proof. by move=> cGH; apply: norm_joinEr (cents_norm cGH). Qed. Lemma centJ A x : 'C(A :^ x) = 'C(A) :^ x. Proof. apply/setP=> y; rewrite mem_conjg; apply/centP/centP=> cAy z Az. by apply: (conjg_inj x); rewrite 2!conjMg conjgKV cAy ?memJ_conjg. by apply: (conjg_inj x^-1); rewrite 2!conjMg cAy -?mem_conjg. Qed. Lemma cent_norm A : 'N(A) \subset 'N('C(A)). Proof. by apply/normsP=> x nCx; rewrite -centJ (normP nCx). Qed. Lemma norms_cent A B : A \subset 'N(B) -> A \subset 'N('C(B)). Proof. by move=> nBA; apply: subset_trans nBA (cent_norm B). Qed. Lemma cent_normal A : 'C(A) <| 'N(A). Proof. by rewrite /(_ <| _) cent_sub cent_norm. Qed. Lemma centS A B : B \subset A -> 'C(A) \subset 'C(B). Proof. by move=> sAB; rewrite centsC (subset_trans sAB) 1?centsC. Qed. Lemma centsS A B C : A \subset B -> C \subset 'C(B) -> C \subset 'C(A). Proof. by move=> sAB cCB; apply: subset_trans cCB (centS sAB). Qed. Lemma centSS A B C D : A \subset C -> B \subset D -> C \subset 'C(D) -> A \subset 'C(B). Proof. by move=> sAC sBD cCD; apply: subset_trans (centsS sBD cCD). Qed. Lemma centI A B : 'C(A) <*> 'C(B) \subset 'C(A :&: B). Proof. by rewrite gen_subG subUset !centS ?(subsetIl, subsetIr). Qed. Lemma centU A B : 'C(A :|: B) = 'C(A) :&: 'C(B). Proof. apply/eqP; rewrite eqEsubset subsetI 2?centS ?(subsetUl, subsetUr) //=. by rewrite centsC subUset -centsC subsetIl -centsC subsetIr. Qed. Lemma cent_gen A : 'C(<<A>>) = 'C(A). Proof. by apply/setP=> x; rewrite -!sub1set centsC gen_subG centsC. Qed. Lemma cent_cycle x : 'C(<[x]>) = 'C[x]. Proof. by rewrite cent_gen cent_set1. Qed. Lemma sub_cent1 A x : (A \subset 'C[x]) = (x \in 'C(A)). Proof. by rewrite -cent_cycle centsC cycle_subG. Qed. Lemma cents_cycle x y : commute x y -> <[x]> \subset 'C(<[y]>). Proof. by move=> cxy; rewrite cent_cycle cycle_subG; apply/cent1P. Qed. Lemma cycle_abelian x : abelian <[x]>. Proof. exact: cents_cycle. Qed. Lemma centY A B : 'C(A <*> B) = 'C(A) :&: 'C(B). Proof. by rewrite cent_gen centU. Qed. Lemma centM G H : 'C(G * H) = 'C(G) :&: 'C(H). Proof. by rewrite -cent_gen genM_join centY. Qed. Lemma cent_classP x G : reflect (x ^: G = [set x]) (x \in 'C(G)). Proof. apply: (iffP (centP _ _)) => [Cx | Cx1 y Gy]. apply/eqP; rewrite eqEsubset sub1set class_refl andbT. by apply/subsetP=> _ /imsetP[y Gy ->]; rewrite !inE conjgE Cx ?mulKg. by apply/commgP/conjg_fixP/set1P; rewrite -Cx1; apply/imsetP; exists y. Qed. Lemma commG1P A B : reflect ([~: A, B] = 1) (A \subset 'C(B)). Proof. apply: (iffP (centsP A B)) => [cAB | cAB1 x Ax y By]. apply/trivgP; rewrite gen_subG; apply/subsetP=> _ /imset2P[x y Ax Ay ->]. by rewrite inE; apply/commgP; apply: cAB. by apply/commgP; rewrite -in_set1 -[[set 1]]cAB1 mem_commg. Qed. Lemma abelianE A : abelian A = (A \subset 'C(A)). Proof. by []. Qed. Lemma abelian1 : abelian [1 gT]. Proof. exact: sub1G. Qed. Lemma abelianS A B : A \subset B -> abelian B -> abelian A. Proof. by move=> sAB; apply: centSS. Qed. Lemma abelianJ A x : abelian (A :^ x) = abelian A. Proof. by rewrite /abelian centJ conjSg. Qed. Lemma abelian_gen A : abelian <<A>> = abelian A. Proof. by rewrite /abelian cent_gen gen_subG. Qed. Lemma abelianY A B : abelian (A <*> B) = [&& abelian A, abelian B & B \subset 'C(A)]. Proof. rewrite /abelian join_subG /= centY !subsetI -!andbA; congr (_ && _). by rewrite centsC andbA andbb andbC. Qed. Lemma abelianM G H : abelian (G * H) = [&& abelian G, abelian H & H \subset 'C(G)]. Proof. by rewrite -abelian_gen genM_join abelianY. Qed. Section SubAbelian. Variable A B C : {set gT}. Hypothesis cAA : abelian A. Lemma sub_abelian_cent : C \subset A -> A \subset 'C(C). Proof. by move=> sCA; rewrite centsC (subset_trans sCA). Qed. Lemma sub_abelian_cent2 : B \subset A -> C \subset A -> B \subset 'C(C). Proof. by move=> sBA; move/sub_abelian_cent; apply: subset_trans. Qed. Lemma sub_abelian_norm : C \subset A -> A \subset 'N(C). Proof. by move=> sCA; rewrite cents_norm ?sub_abelian_cent. Qed. Lemma sub_abelian_normal : (C \subset A) = (C <| A). Proof. by rewrite /normal; case sHG: (C \subset A); rewrite // sub_abelian_norm. Qed. End SubAbelian. End Normaliser. Arguments normP {gT x A}. Arguments centP {gT A x}. Arguments normsP {gT A B}. Arguments cent1P {gT x y}. Arguments normalP {gT A B}. Arguments centsP {gT A B}. Arguments commG1P {gT A B}. Arguments normaliser_group _ _%_g. Arguments centraliser_group _ _%_g. Notation "''N' ( A )" := (normaliser_group A) : Group_scope. Notation "''C' ( A )" := (centraliser_group A) : Group_scope. Notation "''C' [ x ]" := (normaliser_group [set x%g]) : Group_scope. Notation "''N_' G ( A )" := (setI_group G 'N(A)) : Group_scope. Notation "''C_' G ( A )" := (setI_group G 'C(A)) : Group_scope. Notation "''C_' ( G ) ( A )" := (setI_group G 'C(A)) (only parsing) : Group_scope. Notation "''C_' G [ x ]" := (setI_group G 'C[x]) : Group_scope. Notation "''C_' ( G ) [ x ]" := (setI_group G 'C[x]) (only parsing) : Group_scope. #[global] Hint Extern 0 (is_true (_ \subset _)) => apply: normG : core. #[global] Hint Extern 0 (is_true (_ <| _)) => apply: normal_refl : core. Section MinMaxGroup. Variable gT : finGroupType. Implicit Types gP : pred {group gT}. Definition maxgroup A gP := maxset (fun A => group_set A && gP <<A>>%G) A. Definition mingroup A gP := minset (fun A => group_set A && gP <<A>>%G) A. Variable gP : pred {group gT}. Arguments gP _%_G. Lemma ex_maxgroup : (exists G, gP G) -> {G : {group gT} | maxgroup G gP}. Proof. move=> exP; have [A maxA]: {A | maxgroup A gP}. apply: ex_maxset; case: exP => G gPG. by exists (G : {set gT}); rewrite groupP genGidG. by exists <<A>>%G; rewrite /= gen_set_id; case/andP: (maxsetp maxA). Qed. Lemma ex_mingroup : (exists G, gP G) -> {G : {group gT} | mingroup G gP}. Proof. move=> exP; have [A minA]: {A | mingroup A gP}. apply: ex_minset; case: exP => G gPG. by exists (G : {set gT}); rewrite groupP genGidG. by exists <<A>>%G; rewrite /= gen_set_id; case/andP: (minsetp minA). Qed. Variable G : {group gT}. Lemma mingroupP : reflect (gP G /\ forall H, gP H -> H \subset G -> H :=: G) (mingroup G gP). Proof. apply: (iffP minsetP); rewrite /= groupP genGidG /= => [] [-> minG]. by split=> // H gPH sGH; apply: minG; rewrite // groupP genGidG. by split=> // A; case/andP=> gA gPA; rewrite -(gen_set_id gA); apply: minG. Qed. Lemma maxgroupP : reflect (gP G /\ forall H, gP H -> G \subset H -> H :=: G) (maxgroup G gP). Proof. apply: (iffP maxsetP); rewrite /= groupP genGidG /= => [] [-> maxG]. by split=> // H gPH sGH; apply: maxG; rewrite // groupP genGidG. by split=> // A; case/andP=> gA gPA; rewrite -(gen_set_id gA); apply: maxG. Qed. Lemma maxgroupp : maxgroup G gP -> gP G. Proof. by case/maxgroupP. Qed. Lemma mingroupp : mingroup G gP -> gP G. Proof. by case/mingroupP. Qed. Hypothesis gPG : gP G. Lemma maxgroup_exists : {H : {group gT} | maxgroup H gP & G \subset H}. Proof. have [A maxA sGA]: {A | maxgroup A gP & G \subset A}. by apply: maxset_exists; rewrite groupP genGidG. by exists <<A>>%G; rewrite /= gen_set_id; case/andP: (maxsetp maxA). Qed. Lemma mingroup_exists : {H : {group gT} | mingroup H gP & H \subset G}. Proof. have [A maxA sGA]: {A | mingroup A gP & A \subset G}. by apply: minset_exists; rewrite groupP genGidG. by exists <<A>>%G; rewrite /= gen_set_id; case/andP: (minsetp maxA). Qed. End MinMaxGroup. Arguments mingroup {gT} A%_g gP. Arguments maxgroup {gT} A%_g gP. Arguments mingroupP {gT gP G}. Arguments maxgroupP {gT gP G}. Notation "[ 'max' A 'of' G | gP ]" := (maxgroup A (fun G : {group _} => gP)) : group_scope. Notation "[ 'max' G | gP ]" := [max gval G of G | gP] : group_scope. Notation "[ 'max' A 'of' G | gP & gQ ]" := [max A of G | gP && gQ] : group_scope. Notation "[ 'max' G | gP & gQ ]" := [max G | gP && gQ] : group_scope. Notation "[ 'min' A 'of' G | gP ]" := (mingroup A (fun G : {group _} => gP)) : group_scope. Notation "[ 'min' G | gP ]" := [min gval G of G | gP] : group_scope. Notation "[ 'min' A 'of' G | gP & gQ ]" := [min A of G | gP && gQ] : group_scope. Notation "[ 'min' G | gP & gQ ]" := [min G | gP && gQ] : group_scope. HB.reexport.
FormallyUnramified.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.AlgebraicGeometry.Morphisms.Separated import Mathlib.RingTheory.Ideal.IdempotentFG import Mathlib.RingTheory.RingHom.Unramified /-! # Formally unramified morphisms A morphism of schemes `f : X ⟶ Y` is formally unramified if for each affine `U ⊆ Y` and `V ⊆ f ⁻¹' U`, the induced map `Γ(Y, U) ⟶ Γ(X, V)` is formally unramified. We show that these properties are local, and are stable under compositions and base change. -/ noncomputable section open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace universe v u open AlgebraicGeometry /-- If `S` is a formally unramified `R`-algebra, essentially of finite type, the diagonal is an open immersion. -/ instance Algebra.FormallyUnramified.isOpenImmersion_SpecMap_lmul {R S : Type u} [CommRing R] [CommRing S] [Algebra R S] [Algebra.FormallyUnramified R S] [Algebra.EssFiniteType R S] : IsOpenImmersion (Spec.map (CommRingCat.ofHom (TensorProduct.lmul' R (S := S)).toRingHom)) := by rw [isOpenImmersion_SpecMap_iff_of_surjective _ (fun x ↦ ⟨1 ⊗ₜ x, by simp⟩)] apply (Ideal.isIdempotentElem_iff_of_fg _ (KaehlerDifferential.ideal_fg R S)).mp apply (Ideal.cotangent_subsingleton_iff _).mp exact inferInstanceAs <| Subsingleton Ω[S⁄R] namespace AlgebraicGeometry variable {X Y : Scheme.{u}} (f : X ⟶ Y) /-- A morphism of schemes `f : X ⟶ Y` is formally unramified if for each affine `U ⊆ Y` and `V ⊆ f ⁻¹' U`, The induced map `Γ(Y, U) ⟶ Γ(X, V)` is formally unramified. -/ @[mk_iff] class FormallyUnramified (f : X ⟶ Y) : Prop where formallyUnramified_of_affine_subset : ∀ (U : Y.affineOpens) (V : X.affineOpens) (e : V.1 ≤ f ⁻¹ᵁ U.1), (f.appLE U V e).hom.FormallyUnramified namespace FormallyUnramified instance : HasRingHomProperty @FormallyUnramified RingHom.FormallyUnramified where isLocal_ringHomProperty := RingHom.FormallyUnramified.propertyIsLocal eq_affineLocally' := by ext X Y f rw [formallyUnramified_iff, affineLocally_iff_affineOpens_le] instance : MorphismProperty.IsStableUnderComposition @FormallyUnramified := HasRingHomProperty.stableUnderComposition RingHom.FormallyUnramified.stableUnderComposition /-- `f : X ⟶ S` is formally unramified if `X ⟶ X ×ₛ X` is an open immersion. In particular, monomorphisms (e.g. immersions) are formally unramified. The converse is true if `f` is locally of finite type. -/ instance (priority := 900) [IsOpenImmersion (pullback.diagonal f)] : FormallyUnramified f := by wlog hY : ∃ R, Y = Spec R · rw [IsLocalAtTarget.iff_of_openCover (P := @FormallyUnramified) Y.affineCover] intro i have inst : IsOpenImmersion (pullback.diagonal (pullback.snd f (Y.affineCover.map i))) := MorphismProperty.pullback_snd (P := .diagonal @IsOpenImmersion) _ _ ‹_› exact this (pullback.snd _ _) ⟨_, rfl⟩ obtain ⟨R, rfl⟩ := hY wlog hX : ∃ S, X = Spec S generalizing X · rw [IsLocalAtSource.iff_of_openCover (P := @FormallyUnramified) X.affineCover] intro i have inst : IsOpenImmersion (pullback.diagonal (X.affineCover.map i ≫ f)) := MorphismProperty.comp_mem (.diagonal @IsOpenImmersion) _ _ (inferInstanceAs (IsOpenImmersion _)) ‹_› exact this (_ ≫ _) ⟨_, rfl⟩ obtain ⟨S, rfl⟩ := hX obtain ⟨φ, rfl : Spec.map φ = f⟩ := Spec.homEquiv.symm.surjective f rw [HasRingHomProperty.Spec_iff (P := @FormallyUnramified)] algebraize [φ.hom] let F := (Algebra.TensorProduct.lmul' R (S := S)).toRingHom have hF : Function.Surjective F := fun x ↦ ⟨.mk _ _ _ x 1, by simp [F]⟩ have : IsOpenImmersion (Spec.map (CommRingCat.ofHom F)) := by rwa [← MorphismProperty.cancel_right_of_respectsIso (P := @IsOpenImmersion) _ (pullbackSpecIso R S S).inv, ← AlgebraicGeometry.diagonal_Spec_map R S] obtain ⟨e, he, he'⟩ := (isOpenImmersion_SpecMap_iff_of_surjective _ hF).mp this refine ⟨subsingleton_of_forall_eq 0 fun x ↦ ?_⟩ obtain ⟨⟨x, hx⟩, rfl⟩ := Ideal.toCotangent_surjective _ x obtain ⟨x, rfl⟩ := Ideal.mem_span_singleton.mp (he'.le hx) refine (Ideal.toCotangent_eq_zero _ _).mpr ?_ rw [pow_two, Subtype.coe_mk, ← he, mul_assoc] exact Ideal.mul_mem_mul (he'.ge (Ideal.mem_span_singleton_self e)) hx theorem of_comp {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) [FormallyUnramified (f ≫ g)] : FormallyUnramified f := HasRingHomProperty.of_comp (fun {R S T _ _ _} f g H ↦ by algebraize [f, g, g.comp f] exact Algebra.FormallyUnramified.of_comp R S T) ‹_› instance : MorphismProperty.IsMultiplicative @FormallyUnramified where id_mem _ := inferInstance instance : MorphismProperty.IsStableUnderBaseChange @FormallyUnramified := HasRingHomProperty.isStableUnderBaseChange RingHom.FormallyUnramified.isStableUnderBaseChange open MorphismProperty in /-- The diagonal of a formally unramified morphism of finite type is an open immersion. -/ instance isOpenImmersion_diagonal [FormallyUnramified f] [LocallyOfFiniteType f] : IsOpenImmersion (pullback.diagonal f) := by wlog hX : (∃ S, X = Spec S) ∧ ∃ R, Y = Spec R · let 𝒰Y := Y.affineCover let 𝒰X (j : (Y.affineCover.pullbackCover f).J) : ((Y.affineCover.pullbackCover f).obj j).OpenCover := Scheme.affineCover _ apply IsLocalAtTarget.of_range_subset_iSup _ (Scheme.Pullback.range_diagonal_subset_diagonalCoverDiagonalRange f 𝒰Y 𝒰X) intro ⟨i, j⟩ rw [arrow_mk_iso_iff (P := @IsOpenImmersion) (Scheme.Pullback.diagonalRestrictIsoDiagonal f 𝒰Y 𝒰X i j)] have hu : FormallyUnramified ((𝒰X i).map j ≫ pullback.snd f (𝒰Y.map i)) := comp_mem _ _ _ inferInstance (pullback_snd _ _ inferInstance) have hfin : LocallyOfFiniteType ((𝒰X i).map j ≫ pullback.snd f (𝒰Y.map i)) := comp_mem _ _ _ inferInstance (pullback_snd _ _ inferInstance) exact this _ ⟨⟨_, rfl⟩, ⟨_, rfl⟩⟩ obtain ⟨⟨S, rfl⟩, R, rfl⟩ := hX obtain ⟨f, rfl⟩ := Spec.map_surjective f rw [HasRingHomProperty.Spec_iff (P := @FormallyUnramified), HasRingHomProperty.Spec_iff (P := @LocallyOfFiniteType)] at * algebraize [f.hom] rw [show f = CommRingCat.ofHom (algebraMap R S) from rfl, diagonal_Spec_map R S, cancel_right_of_respectsIso (P := @IsOpenImmersion)] infer_instance @[deprecated (since := "2025-05-03")] alias AlgebraicGeometry.FormallyUnramified.isOpenImmersion_diagonal := isOpenImmersion_diagonal end FormallyUnramified end AlgebraicGeometry
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).
Algebraic.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.RingTheory.LocalRing.ResidueField.Ideal import Mathlib.RingTheory.Algebraic.Integral /-! # Algebraic extensions of the residue field -/ instance {R : Type*} [CommRing R] (p : Ideal R) [p.IsPrime] : Algebra.IsAlgebraic (R ⧸ p) p.ResidueField := IsLocalization.isAlgebraic _ (nonZeroDivisors (R ⧸ p)) instance {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] (p : Ideal R) (P : Ideal S) [p.IsPrime] [P.IsPrime] [P.LiesOver p] [Algebra.IsIntegral R S] : Algebra.IsAlgebraic p.ResidueField P.ResidueField := by have : Algebra.IsIntegral (R ⧸ p) (S ⧸ P) := .tower_top R letI := ((algebraMap (S ⧸ P) P.ResidueField).comp (algebraMap (R ⧸ p) (S ⧸ P))).toAlgebra haveI : IsScalarTower (R ⧸ p) (S ⧸ P) P.ResidueField := .of_algebraMap_eq' rfl haveI : Algebra.IsAlgebraic (R ⧸ p) P.ResidueField := .trans _ (S ⧸ P) _ haveI : IsScalarTower (R ⧸ p) p.ResidueField P.ResidueField := by refine .of_algebraMap_eq fun x ↦ ?_ obtain ⟨x, rfl⟩ := Ideal.Quotient.mk_surjective x simp [RingHom.algebraMap_toAlgebra, Algebra.ofId_apply] refine .extendScalars (Ideal.injective_algebraMap_quotient_residueField p)
Defs.lean
/- Copyright (c) 2024 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck, David Loeffler -/ import Mathlib.NumberTheory.ModularForms.SlashInvariantForms import Mathlib.NumberTheory.ModularForms.CongruenceSubgroups /-! # Eisenstein Series ## Main definitions * We define Eisenstein series of level `Γ(N)` for any `N : ℕ` and weight `k : ℤ` as the infinite sum `∑' v : (Fin 2 → ℤ), (1 / (v 0 * z + v 1) ^ k)`, where `z : ℍ` and `v` ranges over all pairs of coprime integers congruent to a fixed pair `(a, b)` modulo `N`. Note that by using `(Fin 2 → ℤ)` instead of `ℤ × ℤ` we can state all of the required equivalences using matrices and vectors, which makes working with them more convenient. * We show that they define a slash invariant form of level `Γ(N)` and weight `k`. ## References * [F. Diamond and J. Shurman, *A First Course in Modular Forms*][diamondshurman2005] -/ noncomputable section open ModularForm UpperHalfPlane Complex Matrix CongruenceSubgroup open scoped MatrixGroups namespace EisensteinSeries variable (N : ℕ) (a : Fin 2 → ZMod N) section gammaSet_def /-- The set of pairs of coprime integers congruent to `a` mod `N`. -/ def gammaSet := {v : Fin 2 → ℤ | (↑) ∘ v = a ∧ IsCoprime (v 0) (v 1)} open scoped Function in -- required for scoped `on` notation lemma pairwise_disjoint_gammaSet : Pairwise (Disjoint on gammaSet N) := by refine fun u v huv ↦ ?_ contrapose! huv obtain ⟨f, hf⟩ := Set.not_disjoint_iff.mp huv exact hf.1.1.symm.trans hf.2.1 /-- For level `N = 1`, the gamma sets are all equal. -/ lemma gammaSet_one_eq (a a' : Fin 2 → ZMod 1) : gammaSet 1 a = gammaSet 1 a' := congr_arg _ (Subsingleton.elim _ _) /-- For level `N = 1`, the gamma sets are all equivalent; this is the equivalence. -/ def gammaSet_one_equiv (a a' : Fin 2 → ZMod 1) : gammaSet 1 a ≃ gammaSet 1 a' := Equiv.setCongr (gammaSet_one_eq a a') end gammaSet_def variable {N a} section gamma_action /-- Right-multiplying by `γ ∈ SL(2, ℤ)` sends `gammaSet N a` to `gammaSet N (a ᵥ* γ)`. -/ lemma vecMul_SL2_mem_gammaSet {v : Fin 2 → ℤ} (hv : v ∈ gammaSet N a) (γ : SL(2, ℤ)) : v ᵥ* γ ∈ gammaSet N (a ᵥ* γ) := by refine ⟨?_, hv.2.vecMulSL γ⟩ have := RingHom.map_vecMul (m := Fin 2) (n := Fin 2) (Int.castRingHom (ZMod N)) γ v simp only [eq_intCast, Int.coe_castRingHom] at this simp_rw [Function.comp_def, this, hv.1] simp variable (a) in /-- The bijection between `GammaSets` given by multiplying by an element of `SL(2, ℤ)`. -/ def gammaSetEquiv (γ : SL(2, ℤ)) : gammaSet N a ≃ gammaSet N (a ᵥ* γ) where toFun v := ⟨v.1 ᵥ* γ, vecMul_SL2_mem_gammaSet v.2 γ⟩ invFun v := ⟨v.1 ᵥ* ↑(γ⁻¹), by have := vecMul_SL2_mem_gammaSet v.2 γ⁻¹ rw [vecMul_vecMul, ← SpecialLinearGroup.coe_mul] at this simpa only [SpecialLinearGroup.map_apply_coe, RingHom.mapMatrix_apply, Int.coe_castRingHom, map_inv, mul_inv_cancel, SpecialLinearGroup.coe_one, vecMul_one]⟩ left_inv v := by simp_rw [vecMul_vecMul, ← SpecialLinearGroup.coe_mul, mul_inv_cancel, SpecialLinearGroup.coe_one, vecMul_one] right_inv v := by simp_rw [vecMul_vecMul, ← SpecialLinearGroup.coe_mul, inv_mul_cancel, SpecialLinearGroup.coe_one, vecMul_one] end gamma_action section eisSummand /-- The function on `(Fin 2 → ℤ)` whose sum defines an Eisenstein series. -/ def eisSummand (k : ℤ) (v : Fin 2 → ℤ) (z : ℍ) : ℂ := (v 0 * z + v 1) ^ (-k) /-- How the `eisSummand` function changes under the Moebius action. -/ theorem eisSummand_SL2_apply (k : ℤ) (i : (Fin 2 → ℤ)) (A : SL(2, ℤ)) (z : ℍ) : eisSummand k i (A • z) = (denom A z) ^ k * eisSummand k (i ᵥ* A) z := by simp only [eisSummand, vecMul, vec2_dotProduct, denom, UpperHalfPlane.specialLinearGroup_apply] have h (a b c d u v : ℂ) (hc : c * z + d ≠ 0) : (u * ((a * z + b) / (c * z + d)) + v) ^ (-k) = (c * z + d) ^ k * ((u * a + v * c) * z + (u * b + v * d)) ^ (-k) := by field_simp [hc] ring_nf simpa using h (hc := denom_ne_zero A z) .. end eisSummand variable (a) /-- An Eisenstein series of weight `k` and level `Γ(N)`, with congruence condition `a`. -/ def _root_.eisensteinSeries (k : ℤ) (z : ℍ) : ℂ := ∑' x : gammaSet N a, eisSummand k x z lemma eisensteinSeries_slash_apply (k : ℤ) (γ : SL(2, ℤ)) : eisensteinSeries a k ∣[k] γ = eisensteinSeries (a ᵥ* γ) k := by ext1 z simp_rw [SL_slash_apply, zpow_neg, mul_inv_eq_iff_eq_mul₀ (zpow_ne_zero _ <| denom_ne_zero _ z), eisensteinSeries, eisSummand_SL2_apply, tsum_mul_left, mul_comm (_ ^ k)] congr 1 exact (gammaSetEquiv a γ).tsum_eq (eisSummand k · z) /-- The SlashInvariantForm defined by an Eisenstein series of weight `k : ℤ`, level `Γ(N)`, and congruence condition given by `a : Fin 2 → ZMod N`. -/ def eisensteinSeries_SIF (k : ℤ) : SlashInvariantForm (Gamma N) k where toFun := eisensteinSeries a k slash_action_eq' A hA := by simp only [eisensteinSeries_slash_apply, Gamma_mem'.mp hA, SpecialLinearGroup.coe_one, vecMul_one] lemma eisensteinSeries_SIF_apply (k : ℤ) (z : ℍ) : eisensteinSeries_SIF a k z = eisensteinSeries a k z := rfl end EisensteinSeries
gfunctor.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 fintype. From mathcomp Require Import bigop finset fingroup morphism automorphism. From mathcomp Require Import quotient gproduct. (******************************************************************************) (* This file provides basic interfaces for the notion of "generic" *) (* characteristic subgroups; these amount to subfunctors of the identity *) (* functor in some category of groups. *) (* See "Generic Proof Tools And Finite Group Theory", *) (* Francois Garillot, PhD, 2011, Chapter 3. *) (* The implementation proposed here is fairly basic, relying on first order *) (* function matching and on structure telescopes, both of which are somewhat *) (* limited and fragile. It should switch in the future to more general and *) (* more robust quotation matching. *) (* The definitions in this file (types, properties and structures) are all *) (* packaged under the GFunctor submodule, i.e., client code should refer to *) (* GFunctor.continuous, GFunctor.map, etc. Notations, Coercions and Lemmas *) (* are exported and thus directly available, however. *) (* We provide the following: *) (* object_map == the type of the (polymorphic) object map of a group *) (* functor; the %gF scope is bound to object_map. *) (* := forall gT : finGroupType, {set gT} -> {set gT}. *) (* We define two operations on object_map (with notations in the %gF scope): *) (* F1 \o F2 == the composite map; (F1 \o F2) G expands to F1 (F2 G). *) (* F1 %% F2 == F1 computed modulo F2; we have *) (* (F1 %% F2) G / F2 G = F1 (G / F2 G) *) (* We define the following (type-polymorphic) properties of an object_map F: *) (* group_valued F <-> F G is a group when G is a group *) (* closed F <-> F G is a subgroup o fG when G is a group *) (* continuous F <-> F is continuous with respect to morphism image: *) (* for any f : {morphism G >-> ..}, f @* (F G) is a *) (* a subgroup of F (f @* G); equivalently, F is *) (* functorial in the category Grp of groups. *) (* Most common "characteristic subgroup" are produced *) (* continuous object maps. *) (* iso_continuous F <-> F is continuous with respect to isomorphism image; *) (* equivalently, F is functorial in the Grp groupoid. *) (* The Puig and the Thompson J subgroups are examples *) (* of iso_continuous maps that are not continuous. *) (* pcontinuous F <-> F is continuous with respect to partial morphism *) (* image, i.e., functorial in the category of groups *) (* and partial morphisms. The center and p-core are *) (* examples of pcontinuous maps. *) (* hereditary F <-> inclusion in the image of F is hereditary, i.e., *) (* for any subgroup H of G, the intersection of H with *) (* F G is included in H. Note that F is pcontinuous *) (* iff it is continuous and hereditary; indeed proofs *) (* of pcontinuous F coerce to proofs of hereditary F *) (* and continuous F. *) (* monotonic F <-> F is monotonic with respect to inclusion: for any *) (* subgroup H of G, F H is a subgroup of F G. The *) (* derived and lower central series are examples of *) (* monotonic maps. *) (* Four structures provide interfaces to these properties: *) (* GFunctor.iso_map == structure for object maps that are group_valued, *) (* closed, and iso_continuous. *) (* [igFun by Fsub & !Fcont] == the iso_map structure for an object map F *) (* such that F G is canonically a group when G is, and *) (* given Fsub : closed F and Fcont : iso_continuous F. *) (* [igFun by Fsub & Fcont] == as above, but expecting Fcont : continuous F. *) (* [igFun of F] == clone an existing GFunctor.iso_map structure for F. *) (* GFunctor.map == structure for continuous object maps, inheriting *) (* from the GFunctor.iso_map structure. *) (* [gFun by Fcont] == the map structure for an F with a canonical iso_map *) (* structure, given Fcont : continuous F. *) (* [gFun of F] == clone an existing GFunctor.map structure for F. *) (* GFunctor.pmap == structure for pcontinuous object maps, inheriting *) (* from the GFunctor.map structure. *) (* [pgFun by Fher] == the pmap structure for an F with a canonical map *) (* structure, given Fher : hereditary F. *) (* [pgFun of F] == clone an existing GFunctor.pmap structure for F. *) (* GFunctor.mono_map == structure for monotonic, continuous object maps *) (* inheriting from the GFunctor.map structure. *) (* [mgFun by Fmon] == the mono_map structure for an F with a canonical *) (* map structure, given Fmon : monotonic F. *) (* [mgFun of F] == clone an existing GFunctor.mono_map structure for F *) (* Lemmas for these group functors use either a 'gF' prefix or an 'F' suffix. *) (* The (F1 \o F2) and (F1 %% F2) operations have canonical GFunctor.map *) (* structures when F1 is monotonic or hereditary, respectively. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope gFun_scope. Import GroupScope. Delimit Scope gFun_scope with gF. Module GFunctor. Definition object_map := forall gT : finGroupType, {set gT} -> {set gT}. Bind Scope gFun_scope with object_map. Section Definitions. Implicit Types gT hT : finGroupType. Variable F : object_map. (* Group closure. *) Definition group_valued := forall gT (G : {group gT}), group_set (F G). (* Subgroup closure. *) Definition closed := forall gT (G : {group gT}), F G \subset G. (* General functoriality, i.e., continuity of the object map *) Definition continuous := forall gT hT (G : {group gT}) (phi : {morphism G >-> hT}), phi @* F G \subset F (phi @* G). (* Functoriality on the Grp groupoid (arrows are restricted to isos). *) Definition iso_continuous := forall gT hT (G : {group gT}) (phi : {morphism G >-> hT}), 'injm phi -> phi @* F G \subset F (phi @* G). Lemma continuous_is_iso_continuous : continuous -> iso_continuous. Proof. by move=> Fcont gT hT G phi inj_phi; apply: Fcont. Qed. (* Functoriality on Grp with partial morphisms. *) Definition pcontinuous := forall gT hT (G D : {group gT}) (phi : {morphism D >-> hT}), phi @* F G \subset F (phi @* G). Lemma pcontinuous_is_continuous : pcontinuous -> continuous. Proof. by move=> Fcont gT hT G; apply: Fcont. Qed. (* Heredity with respect to inclusion *) Definition hereditary := forall gT (H G : {group gT}), H \subset G -> F G :&: H \subset F H. Lemma pcontinuous_is_hereditary : pcontinuous -> hereditary. Proof. move=> Fcont gT H G sHG; rewrite -{2}(setIidPl sHG) setIC. by do 2!rewrite -(morphim_idm (subsetIl H _)) morphimIdom ?Fcont. Qed. (* Monotonicity with respect to inclusion *) Definition monotonic := forall gT (H G : {group gT}), H \subset G -> F H \subset F G. (* Self-expanding composition, and modulo *) Variables (F1 F2 : object_map). Definition comp : object_map := fun gT A => F1 (F2 A). Definition modulo : object_map := fun gT A => coset (F2 A) @*^-1 (F1 (A / (F2 A))). End Definitions. Section ClassDefinitions. Structure iso_map := IsoMap { apply : object_map; _ : group_valued apply; _ : closed apply; _ : iso_continuous apply }. Local Coercion apply : iso_map >-> object_map. Structure map := Map { iso_of_map : iso_map; _ : continuous iso_of_map }. Local Coercion iso_of_map : map >-> iso_map. Structure pmap := Pmap { map_of_pmap : map; _ : hereditary map_of_pmap }. Local Coercion map_of_pmap : pmap >-> map. Structure mono_map := MonoMap { map_of_mono : map; _ : monotonic map_of_mono }. Local Coercion map_of_mono : mono_map >-> map. Definition pack_iso F Fcont Fgrp Fsub := @IsoMap F Fgrp Fsub Fcont. Definition clone_iso (F : object_map) := fun Fgrp Fsub Fcont (isoF := @IsoMap F Fgrp Fsub Fcont) => fun isoF0 & phant_id (apply isoF0) F & phant_id isoF isoF0 => isoF. Definition clone (F : object_map) := fun isoF & phant_id (apply isoF) F => fun (funF0 : map) & phant_id (apply funF0) F => fun Fcont (funF := @Map isoF Fcont) & phant_id funF0 funF => funF. Definition clone_pmap (F : object_map) := fun (funF : map) & phant_id (apply funF) F => fun (pfunF0 : pmap) & phant_id (apply pfunF0) F => fun Fher (pfunF := @Pmap funF Fher) & phant_id pfunF0 pfunF => pfunF. Definition clone_mono (F : object_map) := fun (funF : map) & phant_id (apply funF) F => fun (mfunF0 : mono_map) & phant_id (apply mfunF0) F => fun Fmon (mfunF := @MonoMap funF Fmon) & phant_id mfunF0 mfunF => mfunF. End ClassDefinitions. Module Exports. Identity Coercion fun_of_object_map : object_map >-> Funclass. Coercion apply : iso_map >-> object_map. Coercion iso_of_map : map >-> iso_map. Coercion map_of_pmap : pmap >-> map. Coercion map_of_mono : mono_map >-> map. Coercion continuous_is_iso_continuous : continuous >-> iso_continuous. Coercion pcontinuous_is_continuous : pcontinuous >-> continuous. Coercion pcontinuous_is_hereditary : pcontinuous >-> hereditary. Notation "[ 'igFun' 'by' Fsub & Fcont ]" := (pack_iso (continuous_is_iso_continuous Fcont) (fun gT G => groupP _) Fsub) (format "[ 'igFun' 'by' Fsub & Fcont ]") : form_scope. Notation "[ 'igFun' 'by' Fsub & ! Fcont ]" := (pack_iso Fcont (fun gT G => groupP _) Fsub) (format "[ 'igFun' 'by' Fsub & ! Fcont ]") : form_scope. Notation "[ 'igFun' 'of' F ]" := (@clone_iso F _ _ _ _ id id) (format "[ 'igFun' 'of' F ]") : form_scope. Notation "[ 'gFun' 'by' Fcont ]" := (Map Fcont) (format "[ 'gFun' 'by' Fcont ]") : form_scope. Notation "[ 'gFun' 'of' F ]" := (@clone F _ id _ id _ id) (format "[ 'gFun' 'of' F ]") : form_scope. Notation "[ 'pgFun' 'by' Fher ]" := (Pmap Fher) (format "[ 'pgFun' 'by' Fher ]") : form_scope. Notation "[ 'pgFun' 'of' F ]" := (@clone_pmap F _ id _ id _ id) (format "[ 'pgFun' 'of' F ]") : form_scope. Notation "[ 'mgFun' 'by' Fmon ]" := (MonoMap Fmon) (format "[ 'mgFun' 'by' Fmon ]") : form_scope. Notation "[ 'mgFun' 'of' F ]" := (@clone_mono F _ id _ id _ id) (format "[ 'mgFun' 'of' F ]") : form_scope. End Exports. End GFunctor. Export GFunctor.Exports. Bind Scope gFun_scope with GFunctor.object_map. Arguments GFunctor.comp F1 F2 _ /. Notation "F1 \o F2" := (GFunctor.comp F1 F2) : gFun_scope. Notation "F1 %% F2" := (GFunctor.modulo F1 F2) : gFun_scope. Section FunctorGroup. Variables (F : GFunctor.iso_map) (gT : finGroupType) (G : {group gT}). Lemma gFgroupset : group_set (F gT G). Proof. by case: F. Qed. Canonical gFgroup := Group gFgroupset. End FunctorGroup. Canonical gFmod_group (F1 : GFunctor.iso_map) (F2 : GFunctor.object_map) (gT : finGroupType) (G : {group gT}) := [group of (F1 %% F2)%gF gT G]. Section IsoFunctorTheory. Implicit Types gT rT : finGroupType. Variable F : GFunctor.iso_map. Lemma gFsub gT (G : {group gT}) : F gT G \subset G. Proof. by case: F gT G. Qed. Lemma gFsub_trans gT (G : {group gT}) (A : {pred gT}) : G \subset A -> F gT G \subset A. Proof. exact/subset_trans/gFsub. Qed. Lemma gF1 gT : F gT 1 = 1. Proof. exact/trivgP/gFsub. Qed. Lemma gFiso_cont : GFunctor.iso_continuous F. Proof. by case F. Qed. Lemma gFchar gT (G : {group gT}) : F gT G \char G. Proof. apply/andP; split => //; first by apply: gFsub. apply/forall_inP=> f Af; rewrite -{2}(im_autm Af) -(autmE Af). by rewrite -morphimEsub ?gFsub ?gFiso_cont ?injm_autm. Qed. Lemma gFnorm gT (G : {group gT}) : G \subset 'N(F gT G). Proof. exact/char_norm/gFchar. Qed. Lemma gFnorms gT (G : {group gT}) : 'N(G) \subset 'N(F gT G). Proof. exact/char_norms/gFchar. Qed. Lemma gFnormal gT (G : {group gT}) : F gT G <| G. Proof. exact/char_normal/gFchar. Qed. Lemma gFchar_trans gT (G H : {group gT}) : H \char G -> F gT H \char G. Proof. exact/char_trans/gFchar. Qed. Lemma gFnormal_trans gT (G H : {group gT}) : H <| G -> F gT H <| G. Proof. exact/char_normal_trans/gFchar. Qed. Lemma gFnorm_trans gT (A : {pred gT}) (G : {group gT}) : A \subset 'N(G) -> A \subset 'N(F gT G). Proof. by move/subset_trans/(_ (gFnorms G)). Qed. Lemma injmF_sub gT rT (G D : {group gT}) (f : {morphism D >-> rT}) : 'injm f -> G \subset D -> f @* (F gT G) \subset F rT (f @* G). Proof. move=> injf sGD; have:= gFiso_cont (injm_restrm sGD injf). by rewrite im_restrm morphim_restrm (setIidPr _) ?gFsub. Qed. Lemma injmF gT rT (G D : {group gT}) (f : {morphism D >-> rT}) : 'injm f -> G \subset D -> f @* (F gT G) = F rT (f @* G). Proof. move=> injf sGD; have [sfGD injf'] := (morphimS f sGD, injm_invm injf). apply/esym/eqP; rewrite eqEsubset -(injmSK injf') ?gFsub_trans //. by rewrite !(subset_trans (injmF_sub _ _)) ?morphim_invm // gFsub_trans. Qed. Lemma gFisom gT rT (G D : {group gT}) R (f : {morphism D >-> rT}) : G \subset D -> isom G (gval R) f -> isom (F gT G) (F rT R) f. Proof. case/(restrmP f)=> g [gf _ _ _]; rewrite -{f}gf => /isomP[injg <-]. by rewrite sub_isom ?gFsub ?injmF. Qed. Lemma gFisog gT rT (G : {group gT}) (R : {group rT}) : G \isog R -> F gT G \isog F rT R. Proof. by case/isogP=> f injf <-; rewrite -injmF // sub_isog ?gFsub. Qed. End IsoFunctorTheory. Section FunctorTheory. Implicit Types gT rT : finGroupType. Variable F : GFunctor.map. Lemma gFcont : GFunctor.continuous F. Proof. by case F. Qed. Lemma morphimF gT rT (G D : {group gT}) (f : {morphism D >-> rT}) : G \subset D -> f @* (F gT G) \subset F rT (f @* G). Proof. move=> sGD; rewrite -(setIidPr (gFsub F G)). by rewrite -{3}(setIid G) -!(morphim_restrm sGD) gFcont. Qed. End FunctorTheory. Section PartialFunctorTheory. Implicit Types gT rT : finGroupType. Section BasicTheory. Variable F : GFunctor.pmap. Lemma gFhereditary : GFunctor.hereditary F. Proof. by case F. Qed. Lemma gFunctorI gT (G H : {group gT}) : F gT G :&: H = F gT G :&: F gT (G :&: H). Proof. rewrite -{1}(setIidPr (gFsub F G)) setIAC setIC. rewrite -(setIidPr (gFhereditary (subsetIl G H))). by rewrite setIC -setIA (setIidPr (gFsub F (G :&: H))). Qed. Lemma pmorphimF : GFunctor.pcontinuous F. Proof. move=> gT rT G D f; rewrite -morphimIdom -(setIidPl (gFsub F G)) setICA. apply: (subset_trans (morphimS f (gFhereditary (subsetIr D G)))). by rewrite (subset_trans (morphimF F _ _ )) ?morphimIdom ?subsetIl. Qed. Lemma gFid gT (G : {group gT}) : F gT (F gT G) = F gT G. Proof. apply/eqP; rewrite eqEsubset gFsub. by move/gFhereditary: (gFsub F G); rewrite setIid /=. Qed. End BasicTheory. Section Modulo. Variables (F1 : GFunctor.pmap) (F2 : GFunctor.map). Lemma gFmod_closed : GFunctor.closed (F1 %% F2). Proof. by move=> gT G; rewrite sub_cosetpre_quo ?gFsub ?gFnormal. Qed. Lemma gFmod_cont : GFunctor.continuous (F1 %% F2). Proof. move=> gT rT G f; have nF2 := gFnorm F2. have sDF: G \subset 'dom (coset (F2 _ G)) by rewrite nF2. have sDFf: G \subset 'dom (coset (F2 _ (f @* G)) \o f). by rewrite -sub_morphim_pre ?subsetIl // nF2. pose K := 'ker (restrm sDFf (coset (F2 _ (f @* G)) \o f)). have sFK: 'ker (restrm sDF (coset (F2 _ G))) \subset K. rewrite {}/K !ker_restrm ker_comp /= subsetI subsetIl !ker_coset /=. by rewrite -sub_morphim_pre ?subsetIl // morphimIdom ?morphimF. have sOF := gFsub F1 (G / F2 _ G); have sGG: G \subset G by []. rewrite -sub_quotient_pre; last first. by apply: subset_trans (nF2 _ _); rewrite morphimS ?gFmod_closed. suffices im_fact H : F2 _ G \subset gval H -> H \subset G -> factm sFK sGG @* (H / F2 _ G) = f @* H / F2 _ (f @* G). - rewrite -2?im_fact ?gFmod_closed ?gFsub //. by rewrite cosetpreK morphimF /= ?morphim_restrm ?setIid. by rewrite -sub_quotient_pre ?normG //= trivg_quotient sub1G. move=> sFH sHG; rewrite -(morphimIdom _ (H / _)) /= {2}morphim_restrm /= setIid. rewrite -morphimIG ?ker_coset // -(morphim_restrm sDF) morphim_factm. by rewrite morphim_restrm morphim_comp -quotientE morphimIdom. Qed. Canonical gFmod_igFun := [igFun by gFmod_closed & gFmod_cont]. Canonical gFmod_gFun := [gFun by gFmod_cont]. End Modulo. Variables F1 F2 : GFunctor.pmap. Lemma gFmod_hereditary : GFunctor.hereditary (F1 %% F2). Proof. move=> gT H G sHG; set FGH := _ :&: H; have nF2H := gFnorm F2 H. rewrite -sub_quotient_pre; last exact: subset_trans (subsetIr _ _) _. pose rH := restrm nF2H (coset (F2 _ H)); pose rHM := [morphism of rH]. have rnorm_simpl: rHM @* H = H / F2 _ H by rewrite morphim_restrm setIid. have nF2G := subset_trans sHG (gFnorm F2 G). pose rG := restrm nF2G (coset (F2 _ G)); pose rGM := [morphism of rG]. have sqKfK: 'ker rGM \subset 'ker rHM. rewrite !ker_restrm !ker_coset (setIidPr (gFsub F2 _)) setIC /=. exact: gFhereditary. have sHH := subxx H; rewrite -rnorm_simpl /= -(morphim_factm sqKfK sHH) /=. apply: subset_trans (gFcont F1 _); rewrite /= {2}morphim_restrm setIid /=. apply: subset_trans (morphimS _ (gFhereditary _ (quotientS _ sHG))) => /=. have ->: FGH / _ = restrm nF2H (coset _) @* FGH. by rewrite morphim_restrm setICA setIid. rewrite -(morphim_factm sqKfK sHH) morphimS //= morphim_restrm -quotientE. by rewrite setICA setIid (subset_trans (quotientI _ _ _)) // cosetpreK. Qed. Canonical gFmod_pgFun := [pgFun by gFmod_hereditary]. End PartialFunctorTheory. Section MonotonicFunctorTheory. Implicit Types gT rT : finGroupType. Lemma gFunctorS (F : GFunctor.mono_map) : GFunctor.monotonic F. Proof. by case: F. Qed. Section Composition. Variables (F1 : GFunctor.mono_map) (F2 : GFunctor.map). Lemma gFcomp_closed : GFunctor.closed (F1 \o F2). Proof. by move=> gT G; rewrite !gFsub_trans. Qed. Lemma gFcomp_cont : GFunctor.continuous (F1 \o F2). Proof. move=> gT rT G phi; rewrite (subset_trans (morphimF _ _ (gFsub _ _))) //. by rewrite (subset_trans (gFunctorS F1 (gFcont F2 phi))). Qed. Canonical gFcomp_igFun := [igFun by gFcomp_closed & gFcomp_cont]. Canonical gFcomp_gFun :=[gFun by gFcomp_cont]. End Composition. Variables F1 F2 : GFunctor.mono_map. Lemma gFcompS : GFunctor.monotonic (F1 \o F2). Proof. by move=> gT H G sHG; rewrite !gFunctorS. Qed. Canonical gFcomp_mgFun := [mgFun by gFcompS]. End MonotonicFunctorTheory. Section GFunctorExamples. Implicit Types gT : finGroupType. Definition idGfun gT := @id {set gT}. Lemma idGfun_closed : GFunctor.closed idGfun. Proof. by []. Qed. Lemma idGfun_cont : GFunctor.continuous idGfun. Proof. by []. Qed. Lemma idGfun_monotonic : GFunctor.monotonic idGfun. Proof. by []. Qed. Canonical bgFunc_id := [igFun by idGfun_closed & idGfun_cont]. Canonical gFunc_id := [gFun by idGfun_cont]. Canonical mgFunc_id := [mgFun by idGfun_monotonic]. Definition trivGfun gT of {set gT} := [1 gT]. Lemma trivGfun_cont : GFunctor.pcontinuous trivGfun. Proof. by move=> gT rT D G f; rewrite morphim1. Qed. Canonical trivGfun_igFun := [igFun by sub1G & trivGfun_cont]. Canonical trivGfun_gFun := [gFun by trivGfun_cont]. Canonical trivGfun_pgFun := [pgFun by trivGfun_cont]. End GFunctorExamples.
SuccPred.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.Order.SuccPred import Mathlib.Order.Interval.Set.SuccPred /-! # Set intervals in an additive successor-predecessor order This file proves relations between the various set intervals in an additive successor/predecessor order. ## Notes Please keep in sync with: * `Mathlib/Algebra/Order/Interval/Finset/SuccPred.lean` * `Mathlib/Order/Interval/Finset/SuccPred.lean` * `Mathlib/Order/Interval/Set/SuccPred.lean` ## TODO Copy over `insert` lemmas from `Mathlib/Order/Interval/Finset/Nat.lean`. -/ open Function Order OrderDual variable {ι α : Type*} namespace Set variable [LinearOrder α] [One α] /-! ### Two-sided intervals -/ section SuccAddOrder variable [Add α] [SuccAddOrder α] {a b : α} /-! #### Orders possibly with maximal elements ##### Equalities of intervals -/ lemma Ico_add_one_left_eq_Ioo (a b : α) : Ico (a + 1) b = Ioo a b := by simpa [succ_eq_add_one] using Ico_succ_left_eq_Ioo a b lemma Icc_add_one_left_eq_Ioc_of_not_isMax (ha : ¬ IsMax a) (b : α) : Icc (a + 1) b = Ioc a b := by simpa [succ_eq_add_one] using Icc_succ_left_eq_Ioc_of_not_isMax ha b lemma Ico_add_one_right_eq_Icc_of_not_isMax (hb : ¬ IsMax b) (a : α) : Ico a (b + 1) = Icc a b := by simpa [succ_eq_add_one] using Ico_succ_right_eq_Icc_of_not_isMax hb a lemma Ioo_add_one_right_eq_Ioc_of_not_isMax (hb : ¬ IsMax b) (a : α) : Ioo a (b + 1) = Ioc a b := by simpa [succ_eq_add_one] using Ioo_succ_right_eq_Ioc_of_not_isMax hb a lemma Ico_add_one_add_one_eq_Ioc_of_not_isMax (hb : ¬ IsMax b) (a : α) : Ico (a + 1) (b + 1) = Ioc a b := by simpa [succ_eq_add_one] using Ico_succ_succ_eq_Ioc_of_not_isMax hb a /-! ##### Inserting into intervals -/ lemma insert_Icc_add_one_left_eq_Icc (h : a ≤ b) : insert a (Icc (a + 1) b) = Icc a b := by simpa [succ_eq_add_one] using insert_Icc_succ_left_eq_Icc h lemma insert_Icc_right_eq_Icc_add_one (h : a ≤ b + 1) : insert (b + 1) (Icc a b) = Icc a (b + 1) := by simpa [← succ_eq_add_one] using insert_Icc_right_eq_Icc_succ (succ_eq_add_one b ▸ h) @[deprecated (since := "2025-04-19")] alias insert_Icc_eq_Icc_add_one_right := insert_Icc_right_eq_Icc_add_one lemma insert_Ico_right_eq_Ico_add_one_of_not_isMax (h : a ≤ b) (hb : ¬ IsMax b) : insert b (Ico a b) = Ico a (b + 1) := by simpa [succ_eq_add_one] using insert_Ico_right_eq_Ico_succ_of_not_isMax h hb @[deprecated (since := "2025-04-14")] alias insert_Ico_right_eq_Ico_add_one_right_of_not_isMax := insert_Ico_right_eq_Ico_add_one_of_not_isMax lemma insert_Ico_add_one_left_eq_Ico (h : a < b) : insert a (Ico (a + 1) b) = Ico a b := by simpa [succ_eq_add_one] using insert_Ico_succ_left_eq_Ico h lemma insert_Ioc_right_eq_Ioc_add_one_of_not_isMax (h : a ≤ b) (hb : ¬ IsMax b) : insert (b + 1) (Ioc a b) = Ioc a (b + 1) := by simpa [succ_eq_add_one] using insert_Ioc_right_eq_Ioc_succ_of_not_isMax h hb lemma insert_Ioc_add_one_left_eq_Ioc (h : a < b) : insert (a + 1) (Ioc (a + 1) b) = Ioc a b := by simpa [succ_eq_add_one] using insert_Ioc_succ_left_eq_Ioc h /-! #### Orders with no maximal elements ##### Equalities of intervals -/ variable [NoMaxOrder α] lemma Icc_add_one_left_eq_Ioc (a b : α) : Icc (a + 1) b = Ioc a b := by simpa [succ_eq_add_one] using Icc_succ_left_eq_Ioc a b lemma Ico_add_one_right_eq_Icc (a b : α) : Ico a (b + 1) = Icc a b := by simpa [succ_eq_add_one] using Ico_succ_right_eq_Icc a b lemma Ioo_add_one_right_eq_Ioc (a b : α) : Ioo a (b + 1) = Ioc a b := by simpa [succ_eq_add_one] using Ioo_succ_right_eq_Ioc a b lemma Ico_add_one_add_one_eq_Ioc (a b : α) : Ico (a + 1) (b + 1) = Ioc a b := by simpa [succ_eq_add_one] using Ico_succ_succ_eq_Ioc a b /-! ##### Inserting into intervals -/ lemma insert_Ico_right_eq_Ico_add_one (h : a ≤ b) : insert b (Ico a b) = Ico a (b + 1) := by simpa [succ_eq_add_one] using insert_Ico_right_eq_Ico_succ h @[deprecated (since := "2025-04-14")] alias insert_Ico_right_eq_Ico_add_one_right := insert_Ico_right_eq_Ico_add_one lemma insert_Ioc_right_eq_Ioc_add_one (h : a ≤ b) : insert (b + 1) (Ioc a b) = Ioc a (b + 1) := insert_Ioc_right_eq_Ioc_add_one_of_not_isMax h (not_isMax _) end SuccAddOrder section PredSubOrder variable [Sub α] [PredSubOrder α] {a b : α} /-! #### Orders possibly with minimal elements ##### Equalities of intervals -/ lemma Ioc_sub_one_right_eq_Ioo (a b : α) : Ioc a (b - 1) = Ioo a b := by simpa [pred_eq_sub_one] using Ioc_pred_right_eq_Ioo a b lemma Icc_sub_one_right_eq_Ico_of_not_isMin (hb : ¬ IsMin b) (a : α) : Icc a (b - 1) = Ico a b := by simpa [pred_eq_sub_one] using Icc_pred_right_eq_Ico_of_not_isMin hb a lemma Ioc_sub_one_left_eq_Icc_of_not_isMin (ha : ¬ IsMin a) (b : α) : Ioc (a - 1) b = Icc a b := by simpa [pred_eq_sub_one] using Ioc_pred_left_eq_Icc_of_not_isMin ha b lemma Ioo_sub_one_left_eq_Ioc_of_not_isMin (ha : ¬ IsMin a) (b : α) : Ioo (a - 1) b = Ico a b := by simpa [pred_eq_sub_one] using Ioo_pred_left_eq_Ioc_of_not_isMin ha b lemma Ioc_sub_one_sub_one_eq_Ico_of_not_isMin (ha : ¬ IsMin a) (b : α) : Ioc (a - 1) (b - 1) = Ico a b := by simpa [pred_eq_sub_one] using Ioc_pred_pred_eq_Ico_of_not_isMin ha b /-! ##### Inserting into intervals -/ lemma insert_Icc_sub_one_right_eq_Icc (h : a ≤ b) : insert b (Icc a (b - 1)) = Icc a b := by simpa [pred_eq_sub_one] using insert_Icc_pred_right_eq_Icc h lemma insert_Icc_left_eq_Icc_sub_one (h : a - 1 ≤ b) : insert (a - 1) (Icc a b) = Icc (a - 1) b := by simpa [← pred_eq_sub_one] using insert_Icc_left_eq_Icc_pred (pred_eq_sub_one a ▸ h) @[deprecated (since := "2025-04-19")] alias insert_Icc_eq_Icc_sub_one_left := insert_Icc_left_eq_Icc_sub_one lemma insert_Ioc_left_eq_Ioc_sub_one_of_not_isMin (h : a ≤ b) (ha : ¬ IsMin a) : insert a (Ioc a b) = Ioc (a - 1) b := by simpa [pred_eq_sub_one] using insert_Ioc_left_eq_Ioc_pred_of_not_isMin h ha @[deprecated (since := "2025-04-14")] alias insert_Ioc_left_eq_Ioc_sub_one_left_of_not_isMin := insert_Ioc_left_eq_Ioc_sub_one_of_not_isMin lemma insert_Ioc_sub_one_right_eq_Ioc (h : a < b) : insert b (Ioc a (b - 1)) = Ioc a b := by simpa [pred_eq_sub_one] using insert_Ioc_pred_right_eq_Ioc h lemma insert_Ico_left_eq_Ico_sub_one_of_not_isMin (h : a ≤ b) (ha : ¬ IsMin a) : insert (a - 1) (Ico a b) = Ico (a - 1) b := by simpa [pred_eq_sub_one] using insert_Ico_left_eq_Ico_pred_of_not_isMin h ha lemma insert_Ico_sub_one_right_eq_Ico (h : a < b) : insert (b - 1) (Ico a (b - 1)) = Ico a b := by simpa [pred_eq_sub_one] using insert_Ico_pred_right_eq_Ico h /-! #### Orders with no minimal elements ##### Equalities of intervals -/ variable [NoMinOrder α] lemma Icc_sub_one_right_eq_Ico (a b : α) : Icc a (b - 1) = Ico a b := by simpa [pred_eq_sub_one] using Icc_pred_right_eq_Ico a b lemma Ioc_sub_one_left_eq_Icc (a b : α) : Ioc (a - 1) b = Icc a b := by simpa [pred_eq_sub_one] using Ioc_pred_left_eq_Icc a b lemma Ioo_sub_one_left_eq_Ioc (a b : α) : Ioo (a - 1) b = Ico a b := by simpa [pred_eq_sub_one] using Ioo_pred_left_eq_Ioc a b lemma Ioc_sub_one_sub_one_eq_Ico (a b : α) : Ioc (a - 1) (b - 1) = Ico a b := by simpa [pred_eq_sub_one] using Ioc_pred_pred_eq_Ico a b /-! ##### Inserting into intervals -/ lemma insert_Ioc_left_eq_Ioc_sub_one (h : a ≤ b) : insert a (Ioc a b) = Ioc (a - 1) b := by simpa [pred_eq_sub_one] using insert_Ioc_left_eq_Ioc_pred h @[deprecated (since := "2025-04-14")] alias insert_Ioc_left_eq_Ioc_sub_one_left := insert_Ioc_left_eq_Ioc_sub_one lemma insert_Ico_left_eq_Ico_sub_one (h : a ≤ b) : insert (a - 1) (Ico a b) = Ico (a - 1) b := insert_Ico_left_eq_Ico_sub_one_of_not_isMin h (not_isMin _) end PredSubOrder section SuccAddPredSubOrder variable [Add α] [Sub α] [SuccAddOrder α] [PredSubOrder α] [Nontrivial α] lemma Icc_add_one_sub_one_eq_Ioo (a b : α) : Icc (a + 1) (b - 1) = Ioo a b := by simpa [succ_eq_add_one, pred_eq_sub_one] using Icc_succ_pred_eq_Ioo a b end SuccAddPredSubOrder /-! ### One-sided interval towards `⊥` -/ section SuccAddOrder variable [Add α] [SuccAddOrder α] {b : α} lemma Iio_add_one_eq_Iic_of_not_isMax (hb : ¬ IsMax b) : Iio (b + 1) = Iic b := by simpa [succ_eq_add_one] using Iio_succ_eq_Iic_of_not_isMax hb variable [NoMaxOrder α] lemma Iio_add_one_eq_Iic (b : α) : Iio (b + 1) = Iic b := by simpa [succ_eq_add_one] using Iio_succ_eq_Iic b end SuccAddOrder section PredSubOrder variable [Sub α] [PredSubOrder α] {a b : α} lemma Iic_sub_one_eq_Iio_of_not_isMin (hb : ¬ IsMin b) : Iic (b - 1) = Iio b := by simpa [pred_eq_sub_one] using Iic_pred_eq_Iio_of_not_isMin hb variable [NoMinOrder α] lemma Iic_sub_one_eq_Iio (b : α) : Iic (b - 1) = Iio b := by simpa [pred_eq_sub_one] using Iic_pred_eq_Iio b end PredSubOrder /-! ### One-sided interval towards `⊤` -/ section SuccAddOrder variable [Add α] [SuccAddOrder α] {a : α} lemma Ici_add_one_eq_Ioi_of_not_isMax (ha : ¬ IsMax a) : Ici (a + 1) = Ioi a := by simpa [succ_eq_add_one] using Ici_succ_eq_Ioi_of_not_isMax ha variable [NoMaxOrder α] lemma Ici_add_one_eq_Ioi (a : α) : Ici (a + 1) = Ioi a := by simpa [succ_eq_add_one] using Ici_succ_eq_Ioi a end SuccAddOrder section PredSubOrder variable [Sub α] [PredSubOrder α] {a a : α} lemma Ioi_sub_one_eq_Ici_of_not_isMin (ha : ¬ IsMin a) : Ioi (a - 1) = Ici a := by simpa [pred_eq_sub_one] using Ioi_pred_eq_Ici_of_not_isMin ha variable [NoMinOrder α] lemma Ioi_sub_one_eq_Ici (a : α) : Ioi (a - 1) = Ici a := by simpa [pred_eq_sub_one] using Ioi_pred_eq_Ici a end PredSubOrder end Set
SumIntegralComparisons.lean
/- Copyright (c) 2022 Kevin H. Wilson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin H. Wilson -/ import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic import Mathlib.Data.Set.Function /-! # Comparing sums and integrals ## Summary It is often the case that error terms in analysis can be computed by comparing an infinite sum to the improper integral of an antitone function. This file will eventually enable that. At the moment it contains several lemmas in this direction, for antitone or monotone functions (or products of antitone and monotone functions), formulated for sums on `range i` or `Ico a b`. `TODO`: Add more lemmas to the API to directly address limiting issues ## Main Results * `AntitoneOn.integral_le_sum`: The integral of an antitone function is at most the sum of its values at integer steps aligning with the left-hand side of the interval * `AntitoneOn.sum_le_integral`: The sum of an antitone function along integer steps aligning with the right-hand side of the interval is at most the integral of the function along that interval * `MonotoneOn.integral_le_sum`: The integral of a monotone function is at most the sum of its values at integer steps aligning with the right-hand side of the interval * `MonotoneOn.sum_le_integral`: The sum of a monotone function along integer steps aligning with the left-hand side of the interval is at most the integral of the function along that interval * `sum_mul_Ico_le_integral_of_monotone_antitone`: the sum of `f i * g i` on an interval is bounded by the integral of `f x * g (x - 1)` if `f` is monotone and `g` is antitone. * `integral_le_sum_mul_Ico_of_antitone_monotone`: the sum of `f i * g i` on an interval is bounded below by the integral of `f x * g (x - 1)` if `f` is antitone and `g` is monotone. ## Tags analysis, comparison, asymptotics -/ open Set MeasureTheory MeasureSpace variable {x₀ : ℝ} {a b : ℕ} {f g : ℝ → ℝ} lemma sum_Ico_le_integral_of_le (hab : a ≤ b) (h : ∀ i ∈ Ico a b, ∀ x ∈ Ico (i : ℝ) (i + 1 : ℕ), f i ≤ g x) (hg : IntegrableOn g (Set.Ico a b)) : ∑ i ∈ Finset.Ico a b, f i ≤ ∫ x in a..b, g x := by have A i (hi : i ∈ Finset.Ico a b) : IntervalIntegrable g volume i (i + 1 : ℕ) := by rw [intervalIntegrable_iff_integrableOn_Ico_of_le (by simp)] apply hg.mono _ le_rfl rintro x ⟨hx, h'x⟩ simp only [Finset.mem_Ico, mem_Ico] at hi ⊢ exact ⟨le_trans (mod_cast hi.1) hx, h'x.trans_le (mod_cast hi.2)⟩ calc ∑ i ∈ Finset.Ico a b, f i _ = ∑ i ∈ Finset.Ico a b, (∫ x in (i : ℝ)..(i + 1 : ℕ), f i) := by simp _ ≤ ∑ i ∈ Finset.Ico a b, (∫ x in (i : ℝ)..(i + 1 : ℕ), g x) := by gcongr with i hi apply intervalIntegral.integral_mono_on_of_le_Ioo (by simp) (by simp) (A _ hi) (fun x hx ↦ ?_) exact h _ (by simpa using hi) _ (Ioo_subset_Ico_self hx) _ = ∫ x in a..b, g x := by rw [intervalIntegral.sum_integral_adjacent_intervals_Ico (a := fun i ↦ i) hab] intro i hi exact A _ (by simpa using hi) lemma integral_le_sum_Ico_of_le (hab : a ≤ b) (h : ∀ i ∈ Ico a b, ∀ x ∈ Ico (i : ℝ) (i + 1 : ℕ), g x ≤ f i) (hg : IntegrableOn g (Set.Ico a b)) : ∫ x in a..b, g x ≤ ∑ i ∈ Finset.Ico a b, f i := by convert neg_le_neg (sum_Ico_le_integral_of_le (f := -f) (g := -g) hab (fun i hi x hx ↦ neg_le_neg (h i hi x hx)) hg.neg) <;> simp theorem AntitoneOn.integral_le_sum (hf : AntitoneOn f (Icc x₀ (x₀ + a))) : (∫ x in x₀..x₀ + a, f x) ≤ ∑ i ∈ Finset.range a, f (x₀ + i) := by have hint : ∀ k : ℕ, k < a → IntervalIntegrable f volume (x₀ + k) (x₀ + (k + 1 : ℕ)) := by intro k hk refine (hf.mono ?_).intervalIntegrable rw [uIcc_of_le] · apply Icc_subset_Icc · simp only [le_add_iff_nonneg_right, Nat.cast_nonneg] · simp only [add_le_add_iff_left, Nat.cast_le, Nat.succ_le_of_lt hk] · simp only [add_le_add_iff_left, Nat.cast_le, Nat.le_succ] calc ∫ x in x₀..x₀ + a, f x = ∑ i ∈ Finset.range a, ∫ x in x₀ + i..x₀ + (i + 1 : ℕ), f x := by convert (intervalIntegral.sum_integral_adjacent_intervals hint).symm simp only [Nat.cast_zero, add_zero] _ ≤ ∑ i ∈ Finset.range a, ∫ _ in x₀ + i..x₀ + (i + 1 : ℕ), f (x₀ + i) := by apply Finset.sum_le_sum fun i hi => ?_ have ia : i < a := Finset.mem_range.1 hi refine intervalIntegral.integral_mono_on (by simp) (hint _ ia) (by simp) fun x hx => ?_ apply hf _ _ hx.1 · simp only [ia.le, mem_Icc, le_add_iff_nonneg_right, Nat.cast_nonneg, add_le_add_iff_left, Nat.cast_le, and_self_iff] · refine mem_Icc.2 ⟨le_trans (by simp) hx.1, le_trans hx.2 ?_⟩ simp only [add_le_add_iff_left, Nat.cast_le, Nat.succ_le_of_lt ia] _ = ∑ i ∈ Finset.range a, f (x₀ + i) := by simp theorem AntitoneOn.integral_le_sum_Ico (hab : a ≤ b) (hf : AntitoneOn f (Set.Icc a b)) : (∫ x in a..b, f x) ≤ ∑ x ∈ Finset.Ico a b, f x := by rw [(Nat.sub_add_cancel hab).symm, Nat.cast_add] conv => congr congr · skip · skip rw [add_comm] · skip · skip congr congr rw [← zero_add a] rw [← Finset.sum_Ico_add, Nat.Ico_zero_eq_range] conv => rhs congr · skip ext rw [Nat.cast_add] apply AntitoneOn.integral_le_sum simp only [hf, hab, Nat.cast_sub, add_sub_cancel] theorem AntitoneOn.sum_le_integral (hf : AntitoneOn f (Icc x₀ (x₀ + a))) : (∑ i ∈ Finset.range a, f (x₀ + (i + 1 : ℕ))) ≤ ∫ x in x₀..x₀ + a, f x := by have hint : ∀ k : ℕ, k < a → IntervalIntegrable f volume (x₀ + k) (x₀ + (k + 1 : ℕ)) := by intro k hk refine (hf.mono ?_).intervalIntegrable rw [uIcc_of_le] · apply Icc_subset_Icc · simp only [le_add_iff_nonneg_right, Nat.cast_nonneg] · simp only [add_le_add_iff_left, Nat.cast_le, Nat.succ_le_of_lt hk] · simp only [add_le_add_iff_left, Nat.cast_le, Nat.le_succ] calc (∑ i ∈ Finset.range a, f (x₀ + (i + 1 : ℕ))) = ∑ i ∈ Finset.range a, ∫ _ in x₀ + i..x₀ + (i + 1 : ℕ), f (x₀ + (i + 1 : ℕ)) := by simp _ ≤ ∑ i ∈ Finset.range a, ∫ x in x₀ + i..x₀ + (i + 1 : ℕ), f x := by apply Finset.sum_le_sum fun i hi => ?_ have ia : i + 1 ≤ a := Finset.mem_range.1 hi refine intervalIntegral.integral_mono_on (by simp) (by simp) (hint _ ia) fun x hx => ?_ apply hf _ _ hx.2 · refine mem_Icc.2 ⟨le_trans (le_add_of_nonneg_right (Nat.cast_nonneg _)) hx.1, le_trans hx.2 ?_⟩ simp only [Nat.cast_le, add_le_add_iff_left, ia] · refine mem_Icc.2 ⟨le_add_of_nonneg_right (Nat.cast_nonneg _), ?_⟩ simp only [add_le_add_iff_left, Nat.cast_le, ia] _ = ∫ x in x₀..x₀ + a, f x := by convert intervalIntegral.sum_integral_adjacent_intervals hint simp only [Nat.cast_zero, add_zero] theorem AntitoneOn.sum_le_integral_Ico (hab : a ≤ b) (hf : AntitoneOn f (Set.Icc a b)) : (∑ i ∈ Finset.Ico a b, f (i + 1 : ℕ)) ≤ ∫ x in a..b, f x := by rw [(Nat.sub_add_cancel hab).symm, Nat.cast_add] conv => congr congr congr rw [← zero_add a] · skip · skip · skip rw [add_comm] rw [← Finset.sum_Ico_add, Nat.Ico_zero_eq_range] conv => lhs congr congr · skip ext rw [add_assoc, Nat.cast_add] apply AntitoneOn.sum_le_integral simp only [hf, hab, Nat.cast_sub, add_sub_cancel] theorem MonotoneOn.sum_le_integral (hf : MonotoneOn f (Icc x₀ (x₀ + a))) : (∑ i ∈ Finset.range a, f (x₀ + i)) ≤ ∫ x in x₀..x₀ + a, f x := by rw [← neg_le_neg_iff, ← Finset.sum_neg_distrib, ← intervalIntegral.integral_neg] exact hf.neg.integral_le_sum theorem MonotoneOn.sum_le_integral_Ico (hab : a ≤ b) (hf : MonotoneOn f (Set.Icc a b)) : ∑ x ∈ Finset.Ico a b, f x ≤ ∫ x in a..b, f x := by rw [← neg_le_neg_iff, ← Finset.sum_neg_distrib, ← intervalIntegral.integral_neg] exact hf.neg.integral_le_sum_Ico hab theorem MonotoneOn.integral_le_sum (hf : MonotoneOn f (Icc x₀ (x₀ + a))) : (∫ x in x₀..x₀ + a, f x) ≤ ∑ i ∈ Finset.range a, f (x₀ + (i + 1 : ℕ)) := by rw [← neg_le_neg_iff, ← Finset.sum_neg_distrib, ← intervalIntegral.integral_neg] exact hf.neg.sum_le_integral theorem MonotoneOn.integral_le_sum_Ico (hab : a ≤ b) (hf : MonotoneOn f (Set.Icc a b)) : (∫ x in a..b, f x) ≤ ∑ i ∈ Finset.Ico a b, f (i + 1 : ℕ) := by rw [← neg_le_neg_iff, ← Finset.sum_neg_distrib, ← intervalIntegral.integral_neg] exact hf.neg.sum_le_integral_Ico hab lemma sum_mul_Ico_le_integral_of_monotone_antitone (hab : a ≤ b) (hf : MonotoneOn f (Icc a b)) (hg : AntitoneOn g (Icc (a - 1) (b - 1))) (fpos : 0 ≤ f a) (gpos : 0 ≤ g (b - 1)) : ∑ i ∈ Finset.Ico a b, f i * g i ≤ ∫ x in a..b, f x * g (x - 1) := by apply sum_Ico_le_integral_of_le (f := fun x ↦ f x * g x) hab · intro i hi x hx simp only [Nat.cast_add, Nat.cast_one, mem_Ico] at hx hi have I0 : (i : ℝ) ≤ b - 1 := by simp only [le_sub_iff_add_le] norm_cast omega have I1 : (i : ℝ) ∈ Icc (a - 1 : ℝ) (b - 1) := by simp only [mem_Icc, tsub_le_iff_right] exact ⟨by norm_cast; omega, I0⟩ have I2 : x ∈ Icc (a : ℝ) b := by refine ⟨le_trans (mod_cast hi.1) hx.1, hx.2.le.trans ?_⟩ norm_cast omega apply mul_le_mul · apply hf · simp only [mem_Icc, Nat.cast_le] exact ⟨hi.1, hi.2.le⟩ · exact I2 · exact hx.1 · apply hg · simp only [mem_Icc, tsub_le_iff_right, sub_add_cancel] refine ⟨le_trans (mod_cast hi.1) hx.1, hx.2.le.trans ?_⟩ norm_cast omega · exact I1 · simpa [sub_le_iff_le_add] using hx.2.le · apply gpos.trans apply hg I1 (by simp [hab]) I0 · apply fpos.trans apply hf (by simp [hab]) I2 exact le_trans (mod_cast hi.1) hx.1 · apply Integrable.mono_measure _ (Measure.restrict_mono_set _ Ico_subset_Icc_self) apply Integrable.mul_of_top_left · exact hf.integrableOn_isCompact isCompact_Icc · apply AntitoneOn.memLp_isCompact isCompact_Icc intro x hx y hy hxy apply hg · simpa using hx · simpa using hy · simpa using hxy lemma integral_le_sum_mul_Ico_of_antitone_monotone (hab : a ≤ b) (hf : AntitoneOn f (Icc a b)) (hg : MonotoneOn g (Icc (a - 1) (b - 1))) (fpos : 0 ≤ f b) (gpos : 0 ≤ g (a - 1)) : ∫ x in a..b, f x * g (x - 1) ≤ ∑ i ∈ Finset.Ico a b, f i * g i := by apply integral_le_sum_Ico_of_le (f := fun x ↦ f x * g x) hab · intro i hi x hx simp only [Nat.cast_add, Nat.cast_one, mem_Ico] at hx hi have I0 : (i : ℝ) ≤ b - 1 := by simp only [le_sub_iff_add_le] norm_cast omega have I1 : (i : ℝ) ∈ Icc (a - 1 : ℝ) (b - 1) := by simp only [mem_Icc, tsub_le_iff_right] exact ⟨by norm_cast; omega, I0⟩ have I2 : x ∈ Icc (a : ℝ) b := by refine ⟨le_trans (mod_cast hi.1) hx.1, hx.2.le.trans ?_⟩ norm_cast omega apply mul_le_mul · apply hf · simp only [mem_Icc, Nat.cast_le] exact ⟨hi.1, hi.2.le⟩ · exact I2 · exact hx.1 · apply hg · simp only [mem_Icc, tsub_le_iff_right, sub_add_cancel] refine ⟨le_trans (mod_cast hi.1) hx.1, hx.2.le.trans ?_⟩ norm_cast omega · exact I1 · simpa [sub_le_iff_le_add] using hx.2.le · apply gpos.trans apply hg (by simp [hab]) (by simpa using I2) (by simpa using I2.1) · apply fpos.trans apply hf ⟨mod_cast hi.1, mod_cast hi.2.le⟩ (by simpa using hab) (mod_cast hi.2.le) · apply Integrable.mono_measure _ (Measure.restrict_mono_set _ Ico_subset_Icc_self) apply Integrable.mul_of_top_left · exact hf.integrableOn_isCompact isCompact_Icc · apply MonotoneOn.memLp_isCompact isCompact_Icc intro x hx y hy hxy apply hg · simpa using hx · simpa using hy · simpa using hxy
HasCardinalLT.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.Subobject.Basic import Mathlib.SetTheory.Cardinal.HasCardinalLT /-! # Cardinality of Subobject If `X ⟶ Y` is a monomorphism, and the cardinality of `Subobject Y` is `< κ`, then the cardinality of `Subobject X` is also `< κ`. -/ universe w v u namespace CategoryTheory.Subobject variable {C : Type u} [Category.{v} C] lemma hasCardinalLT_of_mono {Y : C} {κ : Cardinal.{w}} (h : HasCardinalLT (Subobject Y) κ) {X : C} (f : X ⟶ Y) [Mono f] : HasCardinalLT (Subobject X) κ := h.of_injective _ (map_obj_injective f) end CategoryTheory.Subobject
FunctorCategories.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Idempotents.Karoubi /-! # Idempotent completeness and functor categories In this file we define an instance `functor_category_isIdempotentComplete` expressing that a functor category `J ⥤ C` is idempotent complete when the target category `C` is. We also provide a fully faithful functor `karoubiFunctorCategoryEmbedding : Karoubi (J ⥤ C)) : J ⥤ Karoubi C` for all categories `J` and `C`. -/ open CategoryTheory open CategoryTheory.Category open CategoryTheory.Idempotents.Karoubi open CategoryTheory.Limits namespace CategoryTheory namespace Idempotents variable {J C : Type*} [Category J] [Category C] (P Q : Karoubi (J ⥤ C)) (f : P ⟶ Q) (X : J) @[reassoc (attr := simp)] theorem app_idem : P.p.app X ≫ P.p.app X = P.p.app X := congr_app P.idem X variable {P Q} @[reassoc (attr := simp)] theorem app_p_comp : P.p.app X ≫ f.f.app X = f.f.app X := congr_app (p_comp f) X @[reassoc (attr := simp)] theorem app_comp_p : f.f.app X ≫ Q.p.app X = f.f.app X := congr_app (comp_p f) X @[reassoc] theorem app_p_comm : P.p.app X ≫ f.f.app X = f.f.app X ≫ Q.p.app X := congr_app (p_comm f) X variable (J C) instance functor_category_isIdempotentComplete [IsIdempotentComplete C] : IsIdempotentComplete (J ⥤ C) := by refine ⟨fun F p hp => ?_⟩ have hC := (isIdempotentComplete_iff_hasEqualizer_of_id_and_idempotent C).mp inferInstance haveI : ∀ j : J, HasEqualizer (𝟙 _) (p.app j) := fun j => hC _ _ (congr_app hp j) /- We construct the direct factor `Y` associated to `p : F ⟶ F` by computing the equalizer of the identity and `p.app j` on each object `(j : J)`. -/ let Y : J ⥤ C := { obj := fun j => Limits.equalizer (𝟙 _) (p.app j) map := fun {j j'} φ => equalizer.lift (Limits.equalizer.ι (𝟙 _) (p.app j) ≫ F.map φ) (by rw [comp_id, assoc, p.naturality φ, ← assoc, ← Limits.equalizer.condition, comp_id]) } let i : Y ⟶ F := { app := fun j => equalizer.ι _ _ naturality := fun _ _ _ => by rw [equalizer.lift_ι] } let e : F ⟶ Y := { app := fun j => equalizer.lift (p.app j) (by simpa only [comp_id] using (congr_app hp j).symm) naturality := fun j j' φ => equalizer.hom_ext (by simp [Y]) } use Y, i, e constructor · ext j dsimp rw [assoc, equalizer.lift_ι, ← equalizer.condition, id_comp, comp_id] · ext j simp [Y, i, e] namespace KaroubiFunctorCategoryEmbedding variable {J C} /-- On objects, the functor which sends a formal direct factor `P` of a functor `F : J ⥤ C` to the functor `J ⥤ Karoubi C` which sends `(j : J)` to the corresponding direct factor of `F.obj j`. -/ @[simps] def obj (P : Karoubi (J ⥤ C)) : J ⥤ Karoubi C where obj j := ⟨P.X.obj j, P.p.app j, congr_app P.idem j⟩ map {j j'} φ := { f := P.p.app j ≫ P.X.map φ comm := by simp only [NatTrans.naturality, assoc] have h := congr_app P.idem j rw [NatTrans.comp_app] at h rw [reassoc_of% h, reassoc_of% h] } /-- Tautological action on maps of the functor `Karoubi (J ⥤ C) ⥤ (J ⥤ Karoubi C)`. -/ @[simps] def map {P Q : Karoubi (J ⥤ C)} (f : P ⟶ Q) : obj P ⟶ obj Q where app j := ⟨f.f.app j, congr_app f.comm j⟩ end KaroubiFunctorCategoryEmbedding /-- The tautological fully faithful functor `Karoubi (J ⥤ C) ⥤ (J ⥤ Karoubi C)`. -/ @[simps] def karoubiFunctorCategoryEmbedding : Karoubi (J ⥤ C) ⥤ J ⥤ Karoubi C where obj := KaroubiFunctorCategoryEmbedding.obj map := KaroubiFunctorCategoryEmbedding.map instance : (karoubiFunctorCategoryEmbedding J C).Full where map_surjective {P Q} f := ⟨{f := { app := fun j => (f.app j).f naturality := fun j j' φ => by rw [← Karoubi.comp_p_assoc] have h := hom_ext_iff.mp (f.naturality φ) simp only [comp_f] at h dsimp [karoubiFunctorCategoryEmbedding] at h erw [← h, assoc, ← P.p.naturality_assoc φ, p_comp (f.app j')] } comm := by ext j exact (f.app j).comm }, rfl⟩ instance : (karoubiFunctorCategoryEmbedding J C).Faithful where map_injective h := by ext j exact hom_ext_iff.mp (congr_app h j) /-- The composition of `(J ⥤ C) ⥤ Karoubi (J ⥤ C)` and `Karoubi (J ⥤ C) ⥤ (J ⥤ Karoubi C)` equals the functor `(J ⥤ C) ⥤ (J ⥤ Karoubi C)` given by the composition with `toKaroubi C : C ⥤ Karoubi C`. -/ theorem toKaroubi_comp_karoubiFunctorCategoryEmbedding : toKaroubi _ ⋙ karoubiFunctorCategoryEmbedding J C = (Functor.whiskeringRight J _ _).obj (toKaroubi C) := by apply Functor.ext · intro X Y f ext j simp · intro X apply Functor.ext · intro j j' φ ext simp · intro j rfl end Idempotents end CategoryTheory
HomologySequence.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.HomologicalComplex import Mathlib.Algebra.Homology.ShortComplex.SnakeLemma import Mathlib.Algebra.Homology.ShortComplex.ShortExact import Mathlib.Algebra.Homology.HomologicalComplexLimits /-! # The homology sequence If `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` is a short exact sequence in a category of complexes `HomologicalComplex C c` in an abelian category (i.e. `S` is a short complex in that category and satisfies `hS : S.ShortExact`), then whenever `i` and `j` are degrees such that `hij : c.Rel i j`, then there is a long exact sequence : `... ⟶ S.X₁.homology i ⟶ S.X₂.homology i ⟶ S.X₃.homology i ⟶ S.X₁.homology j ⟶ ...`. The connecting homomorphism `S.X₃.homology i ⟶ S.X₁.homology j` is `hS.δ i j hij`, and the exactness is asserted as lemmas `hS.homology_exact₁`, `hS.homology_exact₂` and `hS.homology_exact₃`. The proof is based on the snake lemma, similarly as it was originally done in the Liquid Tensor Experiment. ## References * https://stacks.math.columbia.edu/tag/0111 -/ open CategoryTheory Category Limits namespace HomologicalComplex section HasZeroMorphisms variable {C ι : Type*} [Category C] [HasZeroMorphisms C] {c : ComplexShape ι} (K L : HomologicalComplex C c) (φ : K ⟶ L) (i j : ι) [K.HasHomology i] [K.HasHomology j] [L.HasHomology i] [L.HasHomology j] /-- The morphism `K.opcycles i ⟶ K.cycles j` that is induced by `K.d i j`. -/ noncomputable def opcyclesToCycles [K.HasHomology i] [K.HasHomology j] : K.opcycles i ⟶ K.cycles j := K.liftCycles (K.fromOpcycles i j) _ rfl (by simp) @[reassoc (attr := simp)] lemma opcyclesToCycles_iCycles : K.opcyclesToCycles i j ≫ K.iCycles j = K.fromOpcycles i j := by dsimp only [opcyclesToCycles] simp @[reassoc] lemma pOpcycles_opcyclesToCycles_iCycles : K.pOpcycles i ≫ K.opcyclesToCycles i j ≫ K.iCycles j = K.d i j := by simp [opcyclesToCycles] @[reassoc (attr := simp)] lemma pOpcycles_opcyclesToCycles : K.pOpcycles i ≫ K.opcyclesToCycles i j = K.toCycles i j := by simp only [← cancel_mono (K.iCycles j), assoc, opcyclesToCycles_iCycles, p_fromOpcycles, toCycles_i] @[reassoc (attr := simp)] lemma homologyι_opcyclesToCycles : K.homologyι i ≫ K.opcyclesToCycles i j = 0 := by simp only [← cancel_mono (K.iCycles j), assoc, opcyclesToCycles_iCycles, homologyι_comp_fromOpcycles, zero_comp] @[reassoc (attr := simp)] lemma opcyclesToCycles_homologyπ : K.opcyclesToCycles i j ≫ K.homologyπ j = 0 := by simp only [← cancel_epi (K.pOpcycles i), pOpcycles_opcyclesToCycles_assoc, toCycles_comp_homologyπ, comp_zero] variable {K L} @[reassoc (attr := simp)] lemma opcyclesToCycles_naturality : opcyclesMap φ i ≫ opcyclesToCycles L i j = opcyclesToCycles K i j ≫ cyclesMap φ j := by simp only [← cancel_mono (L.iCycles j), ← cancel_epi (K.pOpcycles i), assoc, p_opcyclesMap_assoc, pOpcycles_opcyclesToCycles_iCycles, Hom.comm, cyclesMap_i, pOpcycles_opcyclesToCycles_iCycles_assoc] variable (C c) /-- The natural transformation `K.opcyclesToCycles i j : K.opcycles i ⟶ K.cycles j` for all `K : HomologicalComplex C c`. -/ @[simps] noncomputable def natTransOpCyclesToCycles [CategoryWithHomology C] : opcyclesFunctor C c i ⟶ cyclesFunctor C c j where app K := K.opcyclesToCycles i j end HasZeroMorphisms section Preadditive variable {C ι : Type*} [Category C] [Preadditive C] {c : ComplexShape ι} (K : HomologicalComplex C c) (i j : ι) (hij : c.Rel i j) namespace HomologySequence /-- The diagram `K.homology i ⟶ K.opcycles i ⟶ K.cycles j ⟶ K.homology j`. -/ @[simp] noncomputable def composableArrows₃ [K.HasHomology i] [K.HasHomology j] : ComposableArrows C 3 := ComposableArrows.mk₃ (K.homologyι i) (K.opcyclesToCycles i j) (K.homologyπ j) instance [K.HasHomology i] [K.HasHomology j] : Mono ((composableArrows₃ K i j).map' 0 1) := by dsimp infer_instance instance [K.HasHomology i] [K.HasHomology j] : Epi ((composableArrows₃ K i j).map' 2 3) := by -- Disable `Fin.reduceFinMk`, otherwise `Precomp.obj_succ` does not fire. (#27382) dsimp [-Fin.reduceFinMk] infer_instance include hij in /-- The diagram `K.homology i ⟶ K.opcycles i ⟶ K.cycles j ⟶ K.homology j` is exact when `c.Rel i j`. -/ lemma composableArrows₃_exact [CategoryWithHomology C] : (composableArrows₃ K i j).Exact := by let S := ShortComplex.mk (K.homologyι i) (K.opcyclesToCycles i j) (by simp) let S' := ShortComplex.mk (K.homologyι i) (K.fromOpcycles i j) (by simp) let ι : S ⟶ S' := { τ₁ := 𝟙 _ τ₂ := 𝟙 _ τ₃ := K.iCycles j } have hS : S.Exact := by rw [ShortComplex.exact_iff_of_epi_of_isIso_of_mono ι] exact S'.exact_of_f_is_kernel (K.homologyIsKernel i j (c.next_eq' hij)) let T := ShortComplex.mk (K.opcyclesToCycles i j) (K.homologyπ j) (by simp) let T' := ShortComplex.mk (K.toCycles i j) (K.homologyπ j) (by simp) let π : T' ⟶ T := { τ₁ := K.pOpcycles i τ₂ := 𝟙 _ τ₃ := 𝟙 _ } have hT : T.Exact := by rw [← ShortComplex.exact_iff_of_epi_of_isIso_of_mono π] exact T'.exact_of_g_is_cokernel (K.homologyIsCokernel i j (c.prev_eq' hij)) apply ComposableArrows.exact_of_δ₀ · exact hS.exact_toComposableArrows · exact hT.exact_toComposableArrows variable (C) attribute [local simp] homologyMap_comp cyclesMap_comp opcyclesMap_comp /-- The functor `HomologicalComplex C c ⥤ ComposableArrows C 3` that maps `K` to the diagram `K.homology i ⟶ K.opcycles i ⟶ K.cycles j ⟶ K.homology j`. -/ @[simps] noncomputable def composableArrows₃Functor [CategoryWithHomology C] : HomologicalComplex C c ⥤ ComposableArrows C 3 where obj K := composableArrows₃ K i j map {K L} φ := ComposableArrows.homMk₃ (homologyMap φ i) (opcyclesMap φ i) (cyclesMap φ j) -- Disable `Fin.reduceFinMk`, otherwise `Precomp.obj_succ` does not fire. (#27382) (homologyMap φ j) (by simp) (by simp [-Fin.reduceFinMk]) (by simp [-Fin.reduceFinMk]) end HomologySequence end Preadditive section Abelian variable {C ι : Type*} [Category C] [Abelian C] {c : ComplexShape ι} /-- If `X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` is an exact sequence of homological complexes, then `X₁.opcycles i ⟶ X₂.opcycles i ⟶ X₃.opcycles i ⟶ 0` is exact. This lemma states the exactness at `X₂.opcycles i`, while the fact that `X₂.opcycles i ⟶ X₃.opcycles i` is an epi is an instance. -/ lemma opcycles_right_exact (S : ShortComplex (HomologicalComplex C c)) (hS : S.Exact) [Epi S.g] (i : ι) [S.X₁.HasHomology i] [S.X₂.HasHomology i] [S.X₃.HasHomology i] : (ShortComplex.mk (opcyclesMap S.f i) (opcyclesMap S.g i) (by rw [← opcyclesMap_comp, S.zero, opcyclesMap_zero])).Exact := by have : Epi (ShortComplex.map S (eval C c i)).g := by dsimp; infer_instance have hj := (hS.map (HomologicalComplex.eval C c i)).gIsCokernel apply ShortComplex.exact_of_g_is_cokernel refine CokernelCofork.IsColimit.ofπ' _ _ (fun {A} k hk => by dsimp at k hk ⊢ have H := CokernelCofork.IsColimit.desc' hj (S.X₂.pOpcycles i ≫ k) (by dsimp rw [← p_opcyclesMap_assoc, hk, comp_zero]) dsimp at H refine ⟨S.X₃.descOpcycles H.1 _ rfl ?_, ?_⟩ · rw [← cancel_epi (S.g.f (c.prev i)), comp_zero, Hom.comm_assoc, H.2, d_pOpcycles_assoc, zero_comp] · rw [← cancel_epi (S.X₂.pOpcycles i), opcyclesMap_comp_descOpcycles, p_descOpcycles, H.2]) /-- If `0 ⟶ X₁ ⟶ X₂ ⟶ X₃` is an exact sequence of homological complex, then `0 ⟶ X₁.cycles i ⟶ X₂.cycles i ⟶ X₃.cycles i` is exact. This lemma states the exactness at `X₂.cycles i`, while the fact that `X₁.cycles i ⟶ X₂.cycles i` is a mono is an instance. -/ lemma cycles_left_exact (S : ShortComplex (HomologicalComplex C c)) (hS : S.Exact) [Mono S.f] (i : ι) [S.X₁.HasHomology i] [S.X₂.HasHomology i] [S.X₃.HasHomology i] : (ShortComplex.mk (cyclesMap S.f i) (cyclesMap S.g i) (by rw [← cyclesMap_comp, S.zero, cyclesMap_zero])).Exact := by have : Mono (ShortComplex.map S (eval C c i)).f := by dsimp; infer_instance have hi := (hS.map (HomologicalComplex.eval C c i)).fIsKernel apply ShortComplex.exact_of_f_is_kernel exact KernelFork.IsLimit.ofι' _ _ (fun {A} k hk => by dsimp at k hk ⊢ have H := KernelFork.IsLimit.lift' hi (k ≫ S.X₂.iCycles i) (by dsimp rw [assoc, ← cyclesMap_i, reassoc_of% hk, zero_comp]) dsimp at H refine ⟨S.X₁.liftCycles H.1 _ rfl ?_, ?_⟩ · rw [← cancel_mono (S.f.f _), assoc, zero_comp, ← Hom.comm, reassoc_of% H.2, iCycles_d, comp_zero] · rw [← cancel_mono (S.X₂.iCycles i), liftCycles_comp_cyclesMap, liftCycles_i, H.2]) variable {S : ShortComplex (HomologicalComplex C c)} (hS : S.ShortExact) (i j : ι) (hij : c.Rel i j) namespace HomologySequence /-- Given a short exact short complex `S : HomologicalComplex C c`, and degrees `i` and `j` such that `c.Rel i j`, this is the snake diagram whose four lines are respectively obtained by applying the functors `homologyFunctor C c i`, `opcyclesFunctor C c i`, `cyclesFunctor C c j`, `homologyFunctor C c j` to `S`. Applying the snake lemma to this gives the homology sequence of `S`. -/ @[simps] noncomputable def snakeInput (hS : S.ShortExact) (i j : ι) (hij : c.Rel i j) : ShortComplex.SnakeInput C where L₀ := (homologyFunctor C c i).mapShortComplex.obj S L₁ := (opcyclesFunctor C c i).mapShortComplex.obj S L₂ := (cyclesFunctor C c j).mapShortComplex.obj S L₃ := (homologyFunctor C c j).mapShortComplex.obj S v₀₁ := S.mapNatTrans (natTransHomologyι C c i) v₁₂ := S.mapNatTrans (natTransOpCyclesToCycles C c i j) v₂₃ := S.mapNatTrans (natTransHomologyπ C c j) h₀ := by apply ShortComplex.isLimitOfIsLimitπ all_goals exact (KernelFork.isLimitMapConeEquiv _ _).symm ((composableArrows₃_exact _ i j hij).exact 0).fIsKernel h₃ := by apply ShortComplex.isColimitOfIsColimitπ all_goals exact (CokernelCofork.isColimitMapCoconeEquiv _ _).symm ((composableArrows₃_exact _ i j hij).exact 1).gIsCokernel L₁_exact := by have := hS.epi_g exact opcycles_right_exact S hS.exact i L₂_exact := by have := hS.mono_f exact cycles_left_exact S hS.exact j epi_L₁_g := by have := hS.epi_g dsimp infer_instance mono_L₂_f := by have := hS.mono_f dsimp infer_instance end HomologySequence end Abelian end HomologicalComplex namespace CategoryTheory open HomologicalComplex HomologySequence variable {C ι : Type*} [Category C] [Abelian C] {c : ComplexShape ι} {S : ShortComplex (HomologicalComplex C c)} (hS : S.ShortExact) (i j : ι) (hij : c.Rel i j) namespace ShortComplex namespace ShortExact /-- The connecting homomorphism `S.X₃.homology i ⟶ S.X₁.homology j` for a short exact short complex `S`. -/ noncomputable def δ : S.X₃.homology i ⟶ S.X₁.homology j := (snakeInput hS i j hij).δ @[reassoc (attr := simp)] lemma δ_comp : hS.δ i j hij ≫ HomologicalComplex.homologyMap S.f j = 0 := (snakeInput hS i j hij).δ_L₃_f @[reassoc (attr := simp)] lemma comp_δ : HomologicalComplex.homologyMap S.g i ≫ hS.δ i j hij = 0 := (snakeInput hS i j hij).L₀_g_δ /-- Exactness of `S.X₃.homology i ⟶ S.X₁.homology j ⟶ S.X₂.homology j`. -/ lemma homology_exact₁ : (ShortComplex.mk _ _ (δ_comp hS i j hij)).Exact := (snakeInput hS i j hij).L₂'_exact include hS in /-- Exactness of `S.X₁.homology i ⟶ S.X₂.homology i ⟶ S.X₃.homology i`. -/ lemma homology_exact₂ : (ShortComplex.mk (HomologicalComplex.homologyMap S.f i) (HomologicalComplex.homologyMap S.g i) (by rw [← HomologicalComplex.homologyMap_comp, S.zero, HomologicalComplex.homologyMap_zero])).Exact := by by_cases h : c.Rel i (c.next i) · exact (snakeInput hS i _ h).L₀_exact · have := hS.epi_g have : ∀ (K : HomologicalComplex C c), IsIso (K.homologyι i) := fun K => ShortComplex.isIso_homologyι (K.sc i) (K.shape _ _ h) have e : S.map (HomologicalComplex.homologyFunctor C c i) ≅ S.map (HomologicalComplex.opcyclesFunctor C c i) := ShortComplex.isoMk (asIso (S.X₁.homologyι i)) (asIso (S.X₂.homologyι i)) (asIso (S.X₃.homologyι i)) (by simp) (by simp) exact ShortComplex.exact_of_iso e.symm (opcycles_right_exact S hS.exact i) /-- Exactness of `S.X₂.homology i ⟶ S.X₃.homology i ⟶ S.X₁.homology j`. -/ lemma homology_exact₃ : (ShortComplex.mk _ _ (comp_δ hS i j hij)).Exact := (snakeInput hS i j hij).L₁'_exact lemma δ_eq' {A : C} (x₃ : A ⟶ S.X₃.homology i) (x₂ : A ⟶ S.X₂.opcycles i) (x₁ : A ⟶ S.X₁.cycles j) (h₂ : x₂ ≫ HomologicalComplex.opcyclesMap S.g i = x₃ ≫ S.X₃.homologyι i) (h₁ : x₁ ≫ HomologicalComplex.cyclesMap S.f j = x₂ ≫ S.X₂.opcyclesToCycles i j) : x₃ ≫ hS.δ i j hij = x₁ ≫ S.X₁.homologyπ j := (snakeInput hS i j hij).δ_eq x₃ x₂ x₁ h₂ h₁ lemma δ_eq {A : C} (x₃ : A ⟶ S.X₃.X i) (hx₃ : x₃ ≫ S.X₃.d i j = 0) (x₂ : A ⟶ S.X₂.X i) (hx₂ : x₂ ≫ S.g.f i = x₃) (x₁ : A ⟶ S.X₁.X j) (hx₁ : x₁ ≫ S.f.f j = x₂ ≫ S.X₂.d i j) (k : ι) (hk : c.next j = k) : S.X₃.liftCycles x₃ j (c.next_eq' hij) hx₃ ≫ S.X₃.homologyπ i ≫ hS.δ i j hij = S.X₁.liftCycles x₁ k hk (by have := hS.mono_f rw [← cancel_mono (S.f.f k), assoc, ← S.f.comm, reassoc_of% hx₁, d_comp_d, comp_zero, zero_comp]) ≫ S.X₁.homologyπ j := by simpa only [assoc] using hS.δ_eq' i j hij (S.X₃.liftCycles x₃ j (c.next_eq' hij) hx₃ ≫ S.X₃.homologyπ i) (x₂ ≫ S.X₂.pOpcycles i) (S.X₁.liftCycles x₁ k hk _) (by simp only [assoc, HomologicalComplex.p_opcyclesMap, HomologicalComplex.homology_π_ι, HomologicalComplex.liftCycles_i_assoc, reassoc_of% hx₂]) (by rw [← cancel_mono (S.X₂.iCycles j), HomologicalComplex.liftCycles_comp_cyclesMap, HomologicalComplex.liftCycles_i, assoc, assoc, opcyclesToCycles_iCycles, HomologicalComplex.p_fromOpcycles, hx₁]) theorem mono_δ (hi : IsZero (S.X₂.homology i)) : Mono (hS.δ i j hij) := (HomologicalComplex.HomologySequence.snakeInput _ _ _ _).mono_δ hi theorem epi_δ (hj : IsZero (S.X₂.homology j)) : Epi (hS.δ i j hij) := (HomologicalComplex.HomologySequence.snakeInput _ _ _ _).epi_δ hj theorem isIso_δ (hi : IsZero (S.X₂.homology i)) (hj : IsZero (S.X₂.homology j)) : IsIso (hS.δ i j hij) := (HomologicalComplex.HomologySequence.snakeInput _ _ _ _).isIso_δ hi hj /-- If `c.Rel i j` and `Hᵢ(X₂), Hⱼ(X₂)` are trivial, `δ` defines an isomorphism `Hᵢ(X₃) ≅ Hⱼ(X₁)`. -/ noncomputable def δIso (hi : IsZero (S.X₂.homology i)) (hj : IsZero (S.X₂.homology j)) : S.X₃.homology i ≅ S.X₁.homology j := @asIso _ _ _ _ (hS.δ i j hij) (hS.isIso_δ i j hij hi hj) end ShortExact end ShortComplex end CategoryTheory
CompileInductive.lean
/- Copyright (c) 2023 Parth Shastri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parth Shastri, Gabriel Ebner, Mario Carneiro -/ import Mathlib.Init import Lean.Elab.Command import Lean.Compiler.CSimpAttr import Lean.Util.FoldConsts import Lean.Data.AssocList /-! # Define the `compile_inductive%` command. The command `compile_inductive% Foo` adds compiled code for the recursor `Foo.rec`, working around a bug in the core Lean compiler which does not support recursors. For technical reasons, the recursor code generated by `compile_inductive%` unfortunately evaluates the base cases eagerly. That is, `List.rec (unreachable!) (fun _ _ _ => 42) [42]` will panic. Similarly, `compile_def% Foo.foo` adds compiled code for definitions when missing. This can be the case for type class projections, or definitions like `List._sizeOf_1`. -/ namespace Mathlib.Util open Lean Meta private def replaceConst (repl : AssocList Name Name) (e : Expr) : Expr := e.replace fun | .const n us => repl.find? n |>.map (.const · us) | _ => none /-- Returns the names of the recursors for a nested or mutual inductive, using the `all` and `numMotives` arguments from `RecursorVal`. -/ def mkRecNames (all : List Name) (numMotives : Nat) : List Name := if numMotives ≤ all.length then all.map mkRecName else let main := all[0]! all.map mkRecName ++ (List.range (numMotives - all.length)).map (fun i => main.str s!"rec_{i+1}") private def addAndCompile' (decl : Declaration) : CoreM Unit := do try addAndCompile decl catch e => match decl with | .defnDecl val => throwError "while compiling {val.name}: {e.toMessageData}" | .mutualDefnDecl val => throwError "while compiling {val.map (·.name)}: {e.toMessageData}" | _ => unreachable! /-- Compile the definition `dv` by adding a second definition `dv✝` with the same body, and registering a `csimp`-lemma `dv = dv✝`. -/ def compileDefn (dv : DefinitionVal) : MetaM Unit := do if ((← getEnv).getModuleIdxFor? dv.name).isNone then -- If it's in the same module then we can safely just call `compileDecl` -- on the original definition return ← compileDecl <| .defnDecl dv let name ← mkFreshUserName dv.name addAndCompile' <| .defnDecl { dv with name } let levels := dv.levelParams.map .param let old := .const dv.name levels let new := .const name levels let name ← mkFreshUserName <| dv.name.str "eq" addDecl <| .thmDecl { name levelParams := dv.levelParams type := ← mkEq old new value := ← mkEqRefl old } Compiler.CSimp.add name .global open Elab /-- Returns true if the given declaration has a `@[csimp]` lemma. -/ def hasCSimpLemma (env : Environment) (n : Name) : Bool := (Compiler.CSimp.ext.getState env).map.contains n /-- `compile_def% Foo.foo` adds compiled code for the definition `Foo.foo`. This can be used for type class projections or definitions like `List._sizeOf_1`, for which Lean does not generate compiled code by default (since it is not used 99% of the time). -/ elab tk:"compile_def% " i:ident : command => Command.liftTermElabM do let n ← realizeGlobalConstNoOverloadWithInfo i if hasCSimpLemma (← getEnv) n then logWarningAt tk m!"already compiled {n}" return let dv ← withRef i <| getConstInfoDefn n withRef tk <| compileDefn dv private def compileStructOnly (iv : InductiveVal) (rv : RecursorVal) : MetaM Unit := do let value ← forallTelescope rv.type fun xs _ => let val := xs[rv.getFirstMinorIdx]! let val := mkAppN val ⟨.map (xs[rv.getMajorIdx]!.proj iv.name) <| .range rv.rules[0]!.nfields⟩ mkLambdaFVars xs val go value where go value := do let name ← mkFreshUserName rv.name addAndCompile' <| .defnDecl { rv with name value hints := .abbrev safety := .safe } let levels := rv.levelParams.map .param let old := .const rv.name levels let new := .const name levels let name ← mkFreshUserName <| rv.name.str "eq" addDecl <| .mutualDefnDecl [{ name levelParams := rv.levelParams type := ← mkEq old new value := .const name levels hints := .opaque safety := .partial }] Compiler.CSimp.add name .global compileDefn <| ← getConstInfoDefn <| mkRecOnName iv.name /-- Generate compiled code for the recursor for `iv`, excluding the `sizeOf` function. -/ def compileInductiveOnly (iv : InductiveVal) (rv : RecursorVal) (warn := true) : MetaM Unit := do if ← isProp rv.type then if warn then logWarning m!"not compiling {rv.name}" return if !iv.isRec && rv.numMotives == 1 && iv.numCtors == 1 && iv.numIndices == 0 then compileStructOnly iv rv return let levels := rv.levelParams.map .param let rvs ← if rv.numMotives == 1 then pure [rv] else mkRecNames iv.all rv.numMotives |>.mapM getConstInfoRec let rvs ← rvs.mapM fun rv => return (rv, ← mkFreshUserName rv.name) let repl := rvs.foldl (fun l (rv, name) => .cons rv.name name l) .nil addAndCompile' <| .mutualDefnDecl <|← rvs.mapM fun (rv, name) => do pure { rv with name value := ← forallTelescope rv.type fun xs body => do let major := xs[rv.getMajorIdx]! (← whnfD <| ← inferType major).withApp fun head args => do let .const iv levels' := head | throwError "not an inductive" let iv ← getConstInfoInduct iv let rv' ← getConstInfoRec <| mkRecName iv.name if !iv.isRec && rv'.numMotives == 1 && iv.numCtors == 1 && iv.numIndices == 0 then let rule := rv.rules[0]! let val := .beta (replaceConst repl rule.rhs) xs[:rv.getFirstIndexIdx] let val := .beta val ⟨.map (major.proj iv.name) <| .range rule.nfields⟩ mkLambdaFVars xs val else let val := .const (mkCasesOnName iv.name) (.param rv.levelParams.head! :: levels') let val := mkAppN val args[:rv'.numParams] let val := .app val <| ← mkLambdaFVars xs[rv.getFirstIndexIdx:] body let val := mkAppN val xs[rv.getFirstIndexIdx:] let val := mkAppN val <| rv.rules.toArray.map fun rule => .beta (replaceConst repl rule.rhs) xs[:rv.getFirstIndexIdx] mkLambdaFVars xs val hints := .opaque safety := .partial } for (rv, name) in rvs do let old := .const rv.name levels let new := .const name levels let name ← mkFreshUserName <| rv.name.str "eq" addDecl <| .mutualDefnDecl [{ name levelParams := rv.levelParams type := ← mkEq old new value := .const name levels hints := .opaque safety := .partial }] Compiler.CSimp.add name .global for name in iv.all do for aux in [mkRecOnName name, mkBRecOnName name] do if let some (.defnInfo dv) := (← getEnv).find? aux then compileDefn dv mutual /-- Generate compiled code for the recursor for `iv`. -/ partial def compileInductive (iv : InductiveVal) (warn := true) : MetaM Unit := do let rv ← getConstInfoRec <| mkRecName iv.name if hasCSimpLemma (← getEnv) rv.name then if warn then logWarning m!"already compiled {rv.name}" return compileInductiveOnly iv rv warn compileSizeOf iv rv /-- Compiles the `sizeOf` auxiliary functions. It also recursively compiles any inductives required to compile the `sizeOf` definition (because `sizeOf` definitions depend on `T.rec`). -/ partial def compileSizeOf (iv : InductiveVal) (rv : RecursorVal) : MetaM Unit := do let go aux := do if let some (.defnInfo dv) := (← getEnv).find? aux then if !hasCSimpLemma (← getEnv) aux then let deps : NameSet := dv.value.foldConsts ∅ fun c arr => if let .str name "_sizeOf_inst" := c then arr.insert name else arr for i in deps do -- We only want to recompile inductives defined in external modules, because attempting -- to recompile `sizeOf` functions defined in the current module multiple times will lead -- to errors. An entire mutual block of inductives is compiled when compiling any -- inductive within it, so every inductive within the same module can be explicitly -- compiled using `compile_inductive%` if necessary. if ((← getEnv).getModuleIdxFor? i).isSome then if let some (.inductInfo iv) := (← getEnv).find? i then compileInductive iv (warn := false) compileDefn dv for name in iv.all do for i in [:rv.numMotives] do go <| name.str s!"_sizeOf_{i+1}" go <| name.str "_sizeOf_inst" end /-- `compile_inductive% Foo` creates compiled code for the recursor `Foo.rec`, so that `Foo.rec` can be used in a definition without having to mark the definition as `noncomputable`. -/ elab tk:"compile_inductive% " i:ident : command => Command.liftTermElabM do let n ← realizeGlobalConstNoOverloadWithInfo i let iv ← withRef i <| getConstInfoInduct n withRef tk <| compileInductive iv end Mathlib.Util -- `Nat.rec` already has a `@[csimp]` lemma in Lean. compile_def% Nat.recOn compile_def% Nat.brecOn compile_inductive% Prod compile_inductive% List compile_inductive% PUnit compile_inductive% PEmpty compile_inductive% Sum compile_inductive% PSum compile_inductive% And compile_inductive% False compile_inductive% Empty compile_inductive% Bool compile_inductive% Sigma compile_inductive% Option -- In addition to the manual implementation below, we also have to override the `Float.val` and -- `Float.mk` functions because these also have no implementation in core lean. -- Because `floatSpec.float` is an opaque type, the identity function is as good an implementation -- as any. private unsafe def Float.valUnsafe : Float → floatSpec.float := unsafeCast private unsafe def Float.mkUnsafe : floatSpec.float → Float := unsafeCast @[implemented_by Float.valUnsafe] private def Float.valImpl (x : Float) : floatSpec.float := x.1 @[implemented_by Float.mkUnsafe] private def Float.mkImpl (x : floatSpec.float) : Float := ⟨x⟩ @[csimp] private theorem Float.val_eq : @Float.val = Float.valImpl := rfl @[csimp] private theorem Float.mk_eq : @Float.mk = Float.mkImpl := rfl -- These types need manual implementations because the default implementation in `compileStruct` -- uses `Expr.proj` which has an invalid IR type. open Lean Meta Elab Mathlib.Util in run_cmd Command.liftTermElabM do for n in [``UInt8, ``UInt16, ``UInt32, ``UInt64, ``USize, ``Float] do let iv ← getConstInfoInduct n let rv ← getConstInfoRec <| mkRecName n let value ← Elab.Term.elabTerm (← `(fun H t => H t.1)) (← inferType (.const rv.name (rv.levelParams.map .param))) compileStructOnly.go iv rv value compileSizeOf iv rv -- These need special handling because `Lean.Name.sizeOf` and `Lean.instSizeOfName` -- were manually implemented as `noncomputable` compile_inductive% String compile_inductive% Lean.Name compile_def% Lean.Name.sizeOf compile_def% Lean.instSizeOfName
Pairing.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.GroupTheory.MonoidLocalization.Basic import Mathlib.LinearAlgebra.Dual.Defs import Mathlib.LinearAlgebra.TensorPower.Basic /-! # The pairing between the tensor power of the dual and the tensor power We construct the pairing `TensorPower.pairingDual : ⨂[R]^n (Module.Dual R M) →ₗ[R] (Module.Dual R (⨂[R]^n M))`. -/ open TensorProduct PiTensorProduct namespace TensorPower variable (R : Type*) (M : Type*) [CommSemiring R] [AddCommMonoid M] [Module R M] (n : ℕ) open BigOperators /-- The canonical multilinear map from `n` copies of the dual of the module `M` to the dual of `⨂[R]^n M`. -/ noncomputable def multilinearMapToDual : MultilinearMap R (fun (_ : Fin n) ↦ Module.Dual R M) (Module.Dual R (⨂[R]^n M)) := have : ∀ (_ : DecidableEq (Fin n)) (f : Fin n → Module.Dual R M) (φ : Module.Dual R M) (i j : Fin n) (v : Fin n → M), (Function.update f i φ) j (v j) = Function.update (fun j ↦ f j (v j)) i (φ (v i)) j := fun _ f φ i j v ↦ by by_cases h : j = i · subst h simp only [Function.update_self] · simp only [Function.update_of_ne h] { toFun := fun f ↦ PiTensorProduct.lift (MultilinearMap.compLinearMap (MultilinearMap.mkPiRing R (Fin n) 1) f) map_update_add' := fun f i φ₁ φ₂ ↦ by ext v dsimp simp only [lift.tprod, MultilinearMap.compLinearMap_apply, this, LinearMap.add_apply, MultilinearMap.map_update_add] map_update_smul' := fun f i a φ ↦ by ext v dsimp simp only [lift.tprod, MultilinearMap.compLinearMap_apply, this, LinearMap.smul_apply, MultilinearMap.map_update_smul] dsimp } variable {R M n} in @[simp] theorem multilinearMapToDual_apply_tprod (f : (_ : Fin n) → Module.Dual R M) (v : Fin n → M) : multilinearMapToDual R M n f (tprod _ v) = ∏ i, (f i (v i)) := by simp [multilinearMapToDual] /-- The linear map from the tensor power of the dual to the dual of the tensor power. -/ noncomputable def pairingDual : ⨂[R]^n (Module.Dual R M) →ₗ[R] (Module.Dual R (⨂[R]^n M)) := PiTensorProduct.lift (multilinearMapToDual R M n) variable {R M n} in @[simp] lemma pairingDual_tprod_tprod (f : (_ : Fin n) → Module.Dual R M) (v : Fin n → M) : pairingDual R M n (tprod _ f) (tprod _ v) = ∏ i, (f i (v i)) := by simp [pairingDual] end TensorPower
TopologicalSpace.lean
/- Copyright (c) 2025 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Topology.Algebra.Group.Pointwise import Mathlib.Topology.Algebra.RestrictedProduct.Basic import Mathlib.Topology.Algebra.Ring.Basic /-! # Restricted products of topological spaces, topological groups and rings We endow a restricted product of topological spaces with a natural topology, which we describe below. We also show various compatibility results when we change filters, and extend the construction of restricted products of algebraic structures to the topological setting. In particular, with the theory of adeles in mind, we show that if each `R i` is a locally compact topological ring with open subring `A i`, and if all but finitely many of the `A i`s are also compact, then `Πʳ i, [R i, A i]` is a locally compact topological ring. ## Main definitions * `RestrictedProduct.topologicalSpace`: the `TopologicalSpace` instance on the restricted product `Πʳ i, [R i, A i]_[𝓕]`. ## Topology on the restricted product The topology on the restricted product `Πʳ i, [R i, A i]_[𝓕]` is defined in the following way: 1. If `𝓕` is some principal filter `𝓟 s`, recall that `Πʳ i, [R i, A i]_[𝓟 s]` is canonically identified with `(Π i ∈ s, A i) × (Π i ∉ s, R i)`. We endow it with the product topology, which is also the topology induced from the full product `Π i, R i`. 2. In general, we note that `𝓕` is the infimum of the principal filters coarser than `𝓕`. We then endow `Πʳ i, [R i, A i]_[𝓕]` with the inductive limit / final topology associated to the inclusion maps `Πʳ i, [R i, A i]_[𝓟 s] → Πʳ i, [R i, A i]_[𝓕]` where `𝓕 ≤ 𝓟 s`. In particular: * On the classical restricted product, with respect to the cofinite filter, this corresponds to taking the inductive limit of the `Πʳ i, [R i, A i]_[𝓟 s]` over all *cofinite* sets `s : Set ι`. * If `𝓕 = 𝓟 s` is a principal filter, this second step clearly does not change the topology, since `s` belongs to the indexing set of the inductive limit. Taking advantage of that second remark, we do not actually declare an instance specific to principal filters. Instead, we provide directly the general instance (corresponding to step 2 above) as `RestrictedProduct.topologicalSpace`. We then prove that, for a principal filter, the map to the full product is an inducing (`RestrictedProduct.isEmbedding_coe_of_principal`), and that the topology for a general `𝓕` is indeed the expected inductive limit (`RestrictedProduct.topologicalSpace_eq_iSup`). ## Main statements * `RestrictedProduct.isEmbedding_coe_of_principal`: for any set `S`, `Πʳ i, [R i, A i]_[𝓟 S]` is endowed with the subset topology coming from `Π i, R i`. * `RestrictedProduct.topologicalSpace_eq_iSup`: the topology on `Πʳ i, [R i, A i]_[𝓕]` is the inductive limit / final topology associated to the natural maps `Πʳ i, [R i, A i]_[𝓟 S] → Πʳ i, [R i, A i]_[𝓕]`, where `𝓕 ≤ 𝓟 S`. * `RestrictedProduct.continuous_dom`: a map from `Πʳ i, [R i, A i]_[𝓕]` is continuous *if and only if* its restriction to each `Πʳ i, [R i, A i]_[𝓟 s]` (with `𝓕 ≤ 𝓟 s`) is continuous. * `RestrictedProduct.continuous_dom_prod_left`: assume that each `A i` is an **open** subset of `R i`. Then, for any topological space `Y`, a map from `Y × Πʳ i, [R i, A i]` is continuous *if and only if* its restriction to each `Y × Πʳ i, [R i, A i]_[𝓟 S]` (with `S` cofinite) is continuous. * `RestrictedProduct.isTopologicalGroup`: if each `R i` is a topological group and each `A i` is an open subgroup of `R i`, then `Πʳ i, [R i, A i]` is a topological group. * `RestrictedProduct.isTopologicalRing`: if each `R i` is a topological ring and each `A i` is an open subring of `R i`, then `Πʳ i, [R i, A i]` is a topological ring. * `RestrictedProduct.continuousSMul`: if some topological monoid `G` acts on each `M i`, and each `A i` is stable for that action, then the natural action of `G` on `Πʳ i, [M i, A i]` is also continuous. In particular, if each `M i` is a topological `R`-module and each `A i` is an open sub-`R`-module of `M i`, then `Πʳ i, [M i, A i]` is a topological `R`-module. * `RestrictedProduct.weaklyLocallyCompactSpace_of_cofinite`: if each `R i` is weakly locally compact, each `A i` is open, and all but finitely many `A i`s are also compact, then the restricted product `Πʳ i, [R i, A i]` is weakly locally compact. * `RestrictedProduct.locallyCompactSpace_of_group`: assume that each `R i` is a locally compact group with `A i` an open subgroup. Assume also that all but finitely many `A i`s are compact. Then the restricted product `Πʳ i, [R i, A i]` is a locally compact group. ## Implementation details Outside of principal filters and the cofinite filter, the topology we define on the restricted product does not seem well-behaved. While declaring a single instance is practical, it may conflict with more interesting topologies in some other cases. Thus, future contributions should not restrain from specializing these instances to principal and cofinite filters if necessary. ## Tags restricted product, adeles, ideles -/ open Set Topology Filter variable {ι : Type*} variable (R : ι → Type*) (A : (i : ι) → Set (R i)) namespace RestrictedProduct open scoped RestrictedProduct variable {𝓕 𝓖 : Filter ι} section Topology /-! ## Topology on the restricted product The topology on the restricted product `Πʳ i, [R i, A i]_[𝓕]` is defined in the following way: 1. If `𝓕` is some principal filter `𝓟 s`, recall that `Πʳ i, [R i, A i]_[𝓟 s]` is canonically identified with `(Π i ∈ s, A i) × (Π i ∉ s, R i)`. We endow it with the product topology, which is also the topology induced from the full product `Π i, R i`. 2. In general, we note that `𝓕` is the infimum of the principal filters coarser than `𝓕`. We then endow `Πʳ i, [R i, A i]_[𝓕]` with the inductive limit / final topology associated to the inclusion maps `Πʳ i, [R i, A i]_[𝓟 s] → Πʳ i, [R i, A i]_[𝓕]` where `𝓕 ≤ 𝓟 s`. In particular: * On the classical restricted product, with respect to the cofinite filter, this corresponds to taking the inductive limit of the `Πʳ i, [R i, A i]_[𝓟 s]` over all *cofinite* sets `s : Set ι`. * If `𝓕 = 𝓟 s` is a principal filter, this second step clearly does not change the topology, since `s` belongs to the indexing set of the inductive limit. Taking advantage of that second remark, we do not actually declare an instance specific to principal filters. Instead, we provide directly the general instance (corresponding to step 2 above) as `RestrictedProduct.topologicalSpace`. We then prove that, for a principal filter, the map to the full product is an inducing (`RestrictedProduct.isEmbedding_coe_of_principal`), and that the topology for a general `𝓕` is indeed the expected inductive limit (`RestrictedProduct.topologicalSpace_eq_iSup`). Note: outside of these two cases, this topology on the restricted product does not seem well-behaved. While declaring a single instance is practical, it may conflict with more interesting topologies in some other cases. Thus, future contributions should not restrain from specializing these instances to principal and cofinite filters if necessary. -/ /-! ### Definition of the topology -/ variable {R A R' A'} variable {𝓕 : Filter ι} variable [∀ i, TopologicalSpace (R i)] variable (R A 𝓕) in instance topologicalSpace : TopologicalSpace (Πʳ i, [R i, A i]_[𝓕]) := ⨆ (S : Set ι) (hS : 𝓕 ≤ 𝓟 S), .coinduced (inclusion R A hS) (.induced ((↑) : Πʳ i, [R i, A i]_[𝓟 S] → Π i, R i) inferInstance) @[fun_prop] theorem continuous_coe : Continuous ((↑) : Πʳ i, [R i, A i]_[𝓕] → Π i, R i) := continuous_iSup_dom.mpr fun _ ↦ continuous_iSup_dom.mpr fun _ ↦ continuous_coinduced_dom.mpr continuous_induced_dom @[fun_prop] theorem continuous_eval (i : ι) : Continuous (fun (x : Πʳ i, [R i, A i]_[𝓕]) ↦ x i) := continuous_apply _ |>.comp continuous_coe @[fun_prop] theorem continuous_inclusion {𝓖 : Filter ι} (h : 𝓕 ≤ 𝓖) : Continuous (inclusion R A h) := by simp_rw [continuous_iff_coinduced_le, topologicalSpace, coinduced_iSup, coinduced_compose] exact iSup₂_le fun S hS ↦ le_iSup₂_of_le S (le_trans h hS) le_rfl instance [∀ i, T0Space (R i)] : T0Space (Πʳ i, [R i, A i]_[𝓕]) := t0Space_of_injective_of_continuous DFunLike.coe_injective continuous_coe instance [∀ i, T1Space (R i)] : T1Space (Πʳ i, [R i, A i]_[𝓕]) := t1Space_of_injective_of_continuous DFunLike.coe_injective continuous_coe instance [∀ i, T2Space (R i)] : T2Space (Πʳ i, [R i, A i]_[𝓕]) := .of_injective_continuous DFunLike.coe_injective continuous_coe section principal /-! ### Topological facts in the principal case -/ variable {S : Set ι} theorem topologicalSpace_eq_of_principal : topologicalSpace R A (𝓟 S) = .induced ((↑) : Πʳ i, [R i, A i]_[𝓟 S] → Π i, R i) inferInstance := le_antisymm (continuous_iff_le_induced.mp continuous_coe) <| (le_iSup₂_of_le S le_rfl <| by rw [inclusion_eq_id R A (𝓟 S), @coinduced_id]) theorem topologicalSpace_eq_of_top : topologicalSpace R A ⊤ = .induced ((↑) : Πʳ i, [R i, A i]_[⊤] → Π i, R i) inferInstance := principal_univ ▸ topologicalSpace_eq_of_principal theorem topologicalSpace_eq_of_bot : topologicalSpace R A ⊥ = .induced ((↑) : Πʳ i, [R i, A i]_[⊥] → Π i, R i) inferInstance := principal_empty ▸ topologicalSpace_eq_of_principal theorem isEmbedding_coe_of_principal : IsEmbedding ((↑) : Πʳ i, [R i, A i]_[𝓟 S] → Π i, R i) where eq_induced := topologicalSpace_eq_of_principal injective := DFunLike.coe_injective theorem isEmbedding_coe_of_top : IsEmbedding ((↑) : Πʳ i, [R i, A i]_[⊤] → Π i, R i) := principal_univ ▸ isEmbedding_coe_of_principal theorem isEmbedding_coe_of_bot : IsEmbedding ((↑) : Πʳ i, [R i, A i]_[⊥] → Π i, R i) := principal_empty ▸ isEmbedding_coe_of_principal theorem continuous_rng_of_principal {X : Type*} [TopologicalSpace X] {f : X → Πʳ i, [R i, A i]_[𝓟 S]} : Continuous f ↔ Continuous ((↑) ∘ f : X → Π i, R i) := isEmbedding_coe_of_principal.continuous_iff theorem continuous_rng_of_top {X : Type*} [TopologicalSpace X] {f : X → Πʳ i, [R i, A i]_[⊤]} : Continuous f ↔ Continuous ((↑) ∘ f : X → Π i, R i) := isEmbedding_coe_of_top.continuous_iff theorem continuous_rng_of_bot {X : Type*} [TopologicalSpace X] {f : X → Πʳ i, [R i, A i]_[⊥]} : Continuous f ↔ Continuous ((↑) ∘ f : X → Π i, R i) := isEmbedding_coe_of_bot.continuous_iff lemma continuous_rng_of_principal_iff_forall {X : Type*} [TopologicalSpace X] {f : X → Πʳ (i : ι), [R i, A i]_[𝓟 S]} : Continuous f ↔ ∀ i : ι, Continuous ((fun x ↦ x i) ∘ f) := continuous_rng_of_principal.trans continuous_pi_iff /-- The obvious bijection between `Πʳ i, [R i, A i]_[⊤]` and `Π i, A i` is a homeomorphism. -/ def homeoTop : (Π i, A i) ≃ₜ (Πʳ i, [R i, A i]_[⊤]) where toFun f := ⟨fun i ↦ f i, fun i ↦ (f i).2⟩ invFun f i := ⟨f i, f.2 i⟩ continuous_toFun := continuous_rng_of_top.mpr <| continuous_pi fun i ↦ continuous_subtype_val.comp <| continuous_apply i continuous_invFun := continuous_pi fun i ↦ continuous_induced_rng.mpr <| continuous_eval i /-- The obvious bijection between `Πʳ i, [R i, A i]_[⊥]` and `Π i, R i` is a homeomorphism. -/ def homeoBot : (Π i, R i) ≃ₜ (Πʳ i, [R i, A i]_[⊥]) where toFun f := ⟨fun i ↦ f i, eventually_bot⟩ invFun f i := f i continuous_toFun := continuous_rng_of_bot.mpr <| continuous_pi fun i ↦ continuous_apply i continuous_invFun := continuous_pi continuous_eval /-- Assume that `S` is a subset of `ι` with finite complement, that each `R i` is weakly locally compact, and that `A i` is *compact* for all `i ∈ S`. Then the restricted product `Πʳ i, [R i, A i]_[𝓟 S]` is locally compact. Note: we spell "`S` has finite complement" as `cofinite ≤ 𝓟 S`. -/ theorem weaklyLocallyCompactSpace_of_principal [∀ i, WeaklyLocallyCompactSpace (R i)] (hS : cofinite ≤ 𝓟 S) (hAcompact : ∀ i ∈ S, IsCompact (A i)) : WeaklyLocallyCompactSpace (Πʳ i, [R i, A i]_[𝓟 S]) where exists_compact_mem_nhds := fun x ↦ by rw [le_principal_iff, mem_cofinite] at hS classical have : ∀ i, ∃ K, IsCompact K ∧ K ∈ 𝓝 (x i) := fun i ↦ exists_compact_mem_nhds (x i) choose K K_compact hK using this set Q : Set (Π i, R i) := univ.pi (fun i ↦ if i ∈ S then A i else K i) with Q_def have Q_compact : IsCompact Q := isCompact_univ_pi fun i ↦ by split_ifs with his · exact hAcompact i his · exact K_compact i set U : Set (Π i, R i) := Sᶜ.pi K have U_nhds : U ∈ 𝓝 (x : Π i, R i) := set_pi_mem_nhds hS fun i _ ↦ hK i have QU : (↑) ⁻¹' U ⊆ ((↑) ⁻¹' Q : Set (Πʳ i, [R i, A i]_[𝓟 S])) := fun y H i _ ↦ by dsimp only split_ifs with hi · exact y.2 hi · exact H i hi refine ⟨((↑) ⁻¹' Q), ?_, mem_of_superset ?_ QU⟩ · refine isEmbedding_coe_of_principal.isCompact_preimage_iff ?_ |>.mpr Q_compact simp_rw [range_coe_principal, Q_def, pi_if, mem_univ, true_and] exact inter_subset_left · simpa only [isEmbedding_coe_of_principal.nhds_eq_comap] using preimage_mem_comap U_nhds instance [∀ i, WeaklyLocallyCompactSpace (R i)] [hS : Fact (cofinite ≤ 𝓟 S)] [hAcompact : ∀ i, CompactSpace (A i)] : WeaklyLocallyCompactSpace (Πʳ i, [R i, A i]_[𝓟 S]) := weaklyLocallyCompactSpace_of_principal hS.out fun _ _ ↦ isCompact_iff_compactSpace.mpr inferInstance end principal section general /-! ### Topological facts in the general case -/ variable (𝓕) in theorem topologicalSpace_eq_iSup : topologicalSpace R A 𝓕 = ⨆ (S : Set ι) (hS : 𝓕 ≤ 𝓟 S), .coinduced (inclusion R A hS) (topologicalSpace R A (𝓟 S)) := by simp_rw [topologicalSpace_eq_of_principal, topologicalSpace] /-- The **universal property** of the topology on the restricted product: a map from `Πʳ i, [R i, A i]_[𝓕]` is continuous *iff* its restriction to each `Πʳ i, [R i, A i]_[𝓟 s]` (with `𝓕 ≤ 𝓟 s`) is continuous. See also `RestrictedProduct.continuous_dom_prod_left`. -/ theorem continuous_dom {X : Type*} [TopologicalSpace X] {f : Πʳ i, [R i, A i]_[𝓕] → X} : Continuous f ↔ ∀ (S : Set ι) (hS : 𝓕 ≤ 𝓟 S), Continuous (f ∘ inclusion R A hS) := by simp_rw [topologicalSpace_eq_of_principal, continuous_iSup_dom, continuous_coinduced_dom] theorem isEmbedding_inclusion_principal {S : Set ι} (hS : 𝓕 ≤ 𝓟 S) : IsEmbedding (inclusion R A hS) := .of_comp (continuous_inclusion hS) continuous_coe isEmbedding_coe_of_principal theorem isEmbedding_inclusion_top : IsEmbedding (inclusion R A (le_top : 𝓕 ≤ ⊤)) := .of_comp (continuous_inclusion _) continuous_coe isEmbedding_coe_of_top /-- `Π i, A i` has the subset topology from the restricted product. -/ theorem isEmbedding_structureMap : IsEmbedding (structureMap R A 𝓕) := isEmbedding_inclusion_top.comp homeoTop.isEmbedding end general section cofinite /-! ### Topological facts in the case where `𝓕 = cofinite` and all `A i`s are open The classical restricted product, associated to the cofinite filter, satisfies more topological properties when each `A i` is an open subset of `R i`. The key fact is that each `Πʳ i, [R i, A i]_[𝓟 S]` (with `S` cofinite) then embeds **as an open subset** in `Πʳ i, [R i, A i]`. This allows us to prove a "universal property with parameters", expressing that for any arbitrary topolgical space `X` (of "parameters"), the product `X × Πʳ i, [R i, A i]` is still the inductive limit of the `X × Πʳ i, [R i, A i]_[𝓟 S]` for `S` cofinite. This fact, which is **not true** for a general inductive limit, will allow us to prove continuity of functions of two variables (e.g algebraic operations), which would otherwise be inaccessible. -/ variable (hAopen : ∀ i, IsOpen (A i)) include hAopen in theorem isOpen_forall_imp_mem_of_principal {S : Set ι} (hS : cofinite ≤ 𝓟 S) {p : ι → Prop} : IsOpen {f : Πʳ i, [R i, A i]_[𝓟 S] | ∀ i, p i → f.1 i ∈ A i} := by rw [le_principal_iff] at hS convert isOpen_set_pi (hS.inter_of_left {i | p i}) (fun i _ ↦ hAopen i) |>.preimage continuous_coe ext f refine ⟨fun H i hi ↦ H i hi.2, fun H i hiT ↦ ?_⟩ by_cases hiS : i ∈ S · exact f.2 hiS · exact H i ⟨hiS, hiT⟩ include hAopen in theorem isOpen_forall_mem_of_principal {S : Set ι} (hS : cofinite ≤ 𝓟 S) : IsOpen {f : Πʳ i, [R i, A i]_[𝓟 S] | ∀ i, f.1 i ∈ A i} := by convert isOpen_forall_imp_mem_of_principal hAopen hS (p := fun _ ↦ True) simp include hAopen in theorem isOpen_forall_imp_mem {p : ι → Prop} : IsOpen {f : Πʳ i, [R i, A i] | ∀ i, p i → f.1 i ∈ A i} := by simp_rw [topologicalSpace_eq_iSup cofinite, isOpen_iSup_iff, isOpen_coinduced] exact fun S hS ↦ isOpen_forall_imp_mem_of_principal hAopen hS include hAopen in theorem isOpen_forall_mem : IsOpen {f : Πʳ i, [R i, A i] | ∀ i, f.1 i ∈ A i} := by simp_rw [topologicalSpace_eq_iSup cofinite, isOpen_iSup_iff, isOpen_coinduced] exact fun S hS ↦ isOpen_forall_mem_of_principal hAopen hS include hAopen in theorem isOpenEmbedding_inclusion_principal {S : Set ι} (hS : cofinite ≤ 𝓟 S) : IsOpenEmbedding (inclusion R A hS) where toIsEmbedding := isEmbedding_inclusion_principal hS isOpen_range := by rw [range_inclusion] exact isOpen_forall_imp_mem hAopen include hAopen in /-- `Π i, A i` is homeomorphic to an open subset of the restricted product. -/ theorem isOpenEmbedding_structureMap : IsOpenEmbedding (structureMap R A cofinite) where toIsEmbedding := isEmbedding_structureMap isOpen_range := by rw [range_structureMap] exact isOpen_forall_mem hAopen include hAopen in theorem nhds_eq_map_inclusion {S : Set ι} (hS : cofinite ≤ 𝓟 S) (x : Πʳ i, [R i, A i]_[𝓟 S]) : (𝓝 (inclusion R A hS x)) = .map (inclusion R A hS) (𝓝 x) := by rw [isOpenEmbedding_inclusion_principal hAopen hS |>.map_nhds_eq x] include hAopen in theorem nhds_eq_map_structureMap (x : Π i, A i) : (𝓝 (structureMap R A cofinite x)) = .map (structureMap R A cofinite) (𝓝 x) := by rw [isOpenEmbedding_structureMap hAopen |>.map_nhds_eq x] include hAopen in /-- If each `R i` is weakly locally compact, each `A i` is open, and all but finitely many `A i`s are also compact, then the restricted product `Πʳ i, [R i, A i]` is weakly locally compact. -/ theorem weaklyLocallyCompactSpace_of_cofinite [∀ i, WeaklyLocallyCompactSpace (R i)] (hAcompact : ∀ᶠ i in cofinite, IsCompact (A i)) : WeaklyLocallyCompactSpace (Πʳ i, [R i, A i]) where exists_compact_mem_nhds := fun x ↦ by set S := {i | IsCompact (A i) ∧ x i ∈ A i} have hS : cofinite ≤ 𝓟 S := le_principal_iff.mpr (hAcompact.and x.2) have hSx : ∀ i ∈ S, x i ∈ A i := fun i hi ↦ hi.2 have hSA : ∀ i ∈ S, IsCompact (A i) := fun i hi ↦ hi.1 haveI := weaklyLocallyCompactSpace_of_principal hS hSA rcases exists_inclusion_eq_of_eventually R A hS hSx with ⟨x', hxx'⟩ rw [← hxx', nhds_eq_map_inclusion hAopen] rcases exists_compact_mem_nhds x' with ⟨K, K_compact, hK⟩ exact ⟨inclusion R A hS '' K, K_compact.image (continuous_inclusion hS), image_mem_map hK⟩ instance [hAopen : Fact (∀ i, IsOpen (A i))] [∀ i, WeaklyLocallyCompactSpace (R i)] [hAcompact : ∀ i, CompactSpace (A i)] : WeaklyLocallyCompactSpace (Πʳ i, [R i, A i]) := weaklyLocallyCompactSpace_of_cofinite hAopen.out <| .of_forall fun _ ↦ isCompact_iff_compactSpace.mpr inferInstance include hAopen in /-- The **universal property with parameters** of the topology on the restricted product: for any topological space `Y` of "parameters", a map from `(Πʳ i, [R i, A i]) × Y` is continuous *iff* its restriction to each `(Πʳ i, [R i, A i]_[𝓟 S]) × Y` (with `S` cofinite) is continuous. -/ theorem continuous_dom_prod_right {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {f : Πʳ i, [R i, A i] × Y → X} : Continuous f ↔ ∀ (S : Set ι) (hS : cofinite ≤ 𝓟 S), Continuous (f ∘ (Prod.map (inclusion R A hS) id)) := by refine ⟨fun H S hS ↦ H.comp ((continuous_inclusion hS).prodMap continuous_id), fun H ↦ ?_⟩ simp_rw [continuous_iff_continuousAt, ContinuousAt] rintro ⟨x, y⟩ set S : Set ι := {i | x i ∈ A i} have hS : cofinite ≤ 𝓟 S := le_principal_iff.mpr x.2 have hxS : ∀ i ∈ S, x i ∈ A i := fun i hi ↦ hi rcases exists_inclusion_eq_of_eventually R A hS hxS with ⟨x', hxx'⟩ rw [← hxx', nhds_prod_eq, nhds_eq_map_inclusion hAopen hS x', ← Filter.map_id (f := 𝓝 y), prod_map_map_eq, ← nhds_prod_eq, tendsto_map'_iff] exact H S hS |>.tendsto ⟨x', y⟩ -- TODO: get from the previous one instead of copy-pasting include hAopen in /-- The **universal property with parameters** of the topology on the restricted product: for any topological space `Y` of "parameters", a map from `Y × Πʳ i, [R i, A i]` is continuous *iff* its restriction to each `Y × Πʳ i, [R i, A i]_[𝓟 S]` (with `S` cofinite) is continuous. -/ theorem continuous_dom_prod_left {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {f : Y × Πʳ i, [R i, A i] → X} : Continuous f ↔ ∀ (S : Set ι) (hS : cofinite ≤ 𝓟 S), Continuous (f ∘ (Prod.map id (inclusion R A hS))) := by refine ⟨fun H S hS ↦ H.comp (continuous_id.prodMap (continuous_inclusion hS)), fun H ↦ ?_⟩ simp_rw [continuous_iff_continuousAt, ContinuousAt] rintro ⟨y, x⟩ set S : Set ι := {i | x i ∈ A i} have hS : cofinite ≤ 𝓟 S := le_principal_iff.mpr x.2 have hxS : ∀ i ∈ S, x i ∈ A i := fun i hi ↦ hi rcases exists_inclusion_eq_of_eventually R A hS hxS with ⟨x', hxx'⟩ rw [← hxx', nhds_prod_eq, nhds_eq_map_inclusion hAopen hS x', ← Filter.map_id (f := 𝓝 y), prod_map_map_eq, ← nhds_prod_eq, tendsto_map'_iff] exact H S hS |>.tendsto ⟨y, x'⟩ include hAopen in /-- A map from `Πʳ i, [R i, A i] × Πʳ i, [R' i, A' i]` is continuous *iff* its restriction to each `Πʳ i, [R i, A i]_[𝓟 S] × Πʳ i, [R' i, A' i]_[𝓟 S]` (with `S` cofinite) is continuous. This is the key result for continuity of multiplication and addition. -/ theorem continuous_dom_prod {R' : ι → Type*} {A' : (i : ι) → Set (R' i)} [∀ i, TopologicalSpace (R' i)] (hAopen' : ∀ i, IsOpen (A' i)) {X : Type*} [TopologicalSpace X] {f : Πʳ i, [R i, A i] × Πʳ i, [R' i, A' i] → X} : Continuous f ↔ ∀ (S : Set ι) (hS : cofinite ≤ 𝓟 S), Continuous (f ∘ (Prod.map (inclusion R A hS) (inclusion R' A' hS))) := by simp_rw [continuous_dom_prod_right hAopen, continuous_dom_prod_left hAopen'] refine ⟨fun H S hS ↦ H S hS S hS, fun H S hS T hT ↦ ?_⟩ set U := S ∩ T have hU : cofinite ≤ 𝓟 (S ∩ T) := inf_principal ▸ le_inf hS hT have hSU : 𝓟 U ≤ 𝓟 S := principal_mono.mpr inter_subset_left have hTU : 𝓟 U ≤ 𝓟 T := principal_mono.mpr inter_subset_right exact (H U hU).comp ((continuous_inclusion hSU).prodMap (continuous_inclusion hTU)) /-- A finitary (instead of binary) version of `continuous_dom_prod`. -/ theorem continuous_dom_pi {n : Type*} [Fintype n] {X : Type*} [TopologicalSpace X] {A : n → ι → Type*} [∀ j i, TopologicalSpace (A j i)] {C : (j : n) → (i : ι) → Set (A j i)} (hCopen : ∀ j i, IsOpen (C j i)) {f : (Π j : n, Πʳ i : ι, [A j i, C j i]) → X} : Continuous f ↔ ∀ (S : Set ι) (hS : cofinite ≤ 𝓟 S), Continuous (f ∘ Pi.map fun _ ↦ inclusion _ _ hS) := by refine ⟨by fun_prop, fun H ↦ ?_⟩ simp_rw [continuous_iff_continuousAt, ContinuousAt] intro x set S : Set ι := {i | ∀ j, x j i ∈ C j i} have hS : cofinite ≤ 𝓟 S := by rw [le_principal_iff] change ∀ᶠ i in cofinite, ∀ j : n, x j i ∈ C j i simp [-eventually_cofinite] let x' (j : n) : Πʳ i : ι, [A j i, C j i]_[𝓟 S] := .mk (fun i ↦ x j i) (fun i hi ↦ hi _) have hxx' : Pi.map (fun j ↦ inclusion _ _ hS) x' = x := rfl simp_rw [← hxx', nhds_pi, Pi.map_apply, nhds_eq_map_inclusion (hCopen _), ← map_piMap_pi_finite, tendsto_map'_iff, ← nhds_pi] exact (H _ _).tendsto _ end cofinite end Topology section Compatibility /-! ## Compatibility properties between algebra and topology -/ variable {S : ι → Type*} -- subobject type variable [Π i, SetLike (S i) (R i)] variable {B : Π i, S i} variable {T : Set ι} {𝓕 : Filter ι} variable [Π i, TopologicalSpace (R i)] section general @[to_additive] instance [Π i, Inv (R i)] [∀ i, InvMemClass (S i) (R i)] [∀ i, ContinuousInv (R i)] : ContinuousInv (Πʳ i, [R i, B i]_[𝓕]) where continuous_inv := by rw [continuous_dom] intro T hT haveI : ContinuousInv (Πʳ i, [R i, B i]_[𝓟 T]) := isEmbedding_coe_of_principal.continuousInv fun _ ↦ rfl exact (continuous_inclusion hT).comp continuous_inv @[to_additive] instance {G : Type*} [Π i, SMul G (R i)] [∀ i, SMulMemClass (S i) G (R i)] [∀ i, ContinuousConstSMul G (R i)] : ContinuousConstSMul G (Πʳ i, [R i, B i]_[𝓕]) where continuous_const_smul g := by rw [continuous_dom] intro T hT haveI : ContinuousConstSMul G (Πʳ i, [R i, B i]_[𝓟 T]) := isEmbedding_coe_of_principal.continuousConstSMul id rfl exact (continuous_inclusion hT).comp (continuous_const_smul g) end general section principal @[to_additive] instance [Π i, Mul (R i)] [∀ i, MulMemClass (S i) (R i)] [∀ i, ContinuousMul (R i)] : ContinuousMul (Πʳ i, [R i, B i]_[𝓟 T]) := let φ : Πʳ i, [R i, B i]_[𝓟 T] →ₙ* Π i, R i := { toFun := (↑) map_mul' := fun _ _ ↦ rfl } isEmbedding_coe_of_principal.continuousMul φ @[to_additive] instance {G : Type*} [TopologicalSpace G] [Π i, SMul G (R i)] [∀ i, SMulMemClass (S i) G (R i)] [∀ i, ContinuousSMul G (R i)] : ContinuousSMul G (Πʳ i, [R i, B i]_[𝓟 T]) := isEmbedding_coe_of_principal.continuousSMul continuous_id rfl @[to_additive] instance [Π i, Group (R i)] [∀ i, SubgroupClass (S i) (R i)] [∀ i, IsTopologicalGroup (R i)] : IsTopologicalGroup (Πʳ i, [R i, B i]_[𝓟 T]) where instance [Π i, Ring (R i)] [∀ i, SubringClass (S i) (R i)] [∀ i, IsTopologicalRing (R i)] : IsTopologicalRing (Πʳ i, [R i, B i]_[𝓟 T]) where end principal section cofinite theorem nhds_zero_eq_map_ofPre [Π i, Zero (R i)] [∀ i, ZeroMemClass (S i) (R i)] (hBopen : ∀ i, IsOpen (B i : Set (R i))) (hT : cofinite ≤ 𝓟 T) : (𝓝 (inclusion R (fun i ↦ B i) hT 0)) = .map (inclusion R (fun i ↦ B i) hT) (𝓝 0) := nhds_eq_map_inclusion hBopen hT 0 theorem nhds_zero_eq_map_structureMap [Π i, Zero (R i)] [∀ i, ZeroMemClass (S i) (R i)] (hBopen : ∀ i, IsOpen (B i : Set (R i))) : (𝓝 (structureMap R (fun i ↦ B i) cofinite 0)) = .map (structureMap R (fun i ↦ B i) cofinite) (𝓝 0) := nhds_eq_map_structureMap hBopen 0 -- TODO: Make `IsOpen` a class like `IsClosed` ? variable [hBopen : Fact (∀ i, IsOpen (B i : Set (R i)))] @[to_additive] instance [Π i, Mul (R i)] [∀ i, MulMemClass (S i) (R i)] [∀ i, ContinuousMul (R i)] : ContinuousMul (Πʳ i, [R i, B i]) where continuous_mul := by rw [continuous_dom_prod hBopen.out hBopen.out] exact fun S hS ↦ (continuous_inclusion hS).comp continuous_mul @[to_additive] instance continuousSMul {G : Type*} [TopologicalSpace G] [Π i, SMul G (R i)] [∀ i, SMulMemClass (S i) G (R i)] [∀ i, ContinuousSMul G (R i)] : ContinuousSMul G (Πʳ i, [R i, B i]) where continuous_smul := by rw [continuous_dom_prod_left hBopen.out] exact fun S hS ↦ (continuous_inclusion hS).comp continuous_smul @[to_additive] instance isTopologicalGroup [Π i, Group (R i)] [∀ i, SubgroupClass (S i) (R i)] [∀ i, IsTopologicalGroup (R i)] : IsTopologicalGroup (Πʳ i, [R i, B i]) where instance isTopologicalRing [Π i, Ring (R i)] [∀ i, SubringClass (S i) (R i)] [∀ i, IsTopologicalRing (R i)] : IsTopologicalRing (Πʳ i, [R i, B i]) where /-- Assume that each `R i` is a locally compact group with `A i` an open subgroup. Assume also that all but finitely many `A i`s are compact. Then the restricted product `Πʳ i, [R i, A i]` is a locally compact group. -/ @[to_additive /-- Assume that each `R i` is a locally compact additive group with `A i` an open subgroup. Assume also that all but finitely many `A i`s are compact. Then the restricted product `Πʳ i, [R i, A i]` is a locally compact additive group. -/] theorem locallyCompactSpace_of_group [Π i, Group (R i)] [∀ i, SubgroupClass (S i) (R i)] [∀ i, IsTopologicalGroup (R i)] [∀ i, LocallyCompactSpace (R i)] (hBcompact : ∀ᶠ i in cofinite, IsCompact (B i : Set (R i))) : LocallyCompactSpace (Πʳ i, [R i, B i]) := haveI : WeaklyLocallyCompactSpace (Πʳ i, [R i, B i]) := weaklyLocallyCompactSpace_of_cofinite hBopen.out hBcompact inferInstance open Pointwise in @[to_additive] instance [Π i, Group (R i)] [∀ i, SubgroupClass (S i) (R i)] [∀ i, IsTopologicalGroup (R i)] [hAcompact : ∀ i, CompactSpace (B i)] : LocallyCompactSpace (Πʳ i, [R i, B i]) := -- TODO: extract as a lemma haveI : ∀ i, WeaklyLocallyCompactSpace (R i) := fun i ↦ .mk fun x ↦ ⟨x • (B i : Set (R i)), .smul _ (isCompact_iff_compactSpace.mpr inferInstance), hBopen.out i |>.smul _ |>.mem_nhds <| by simpa using smul_mem_smul_set (a := x) (one_mem (B i))⟩ locallyCompactSpace_of_group _ <| .of_forall fun _ ↦ isCompact_iff_compactSpace.mpr inferInstance end cofinite end Compatibility section map_continuous variable {ι₁ ι₂ : Type*} variable (R₁ : ι₁ → Type*) (R₂ : ι₂ → Type*) variable [∀ i, TopologicalSpace (R₁ i)] [∀ i, TopologicalSpace (R₂ i)] variable {𝓕₁ : Filter ι₁} {𝓕₂ : Filter ι₂} variable {A₁ : (i : ι₁) → Set (R₁ i)} {A₂ : (i : ι₂) → Set (R₂ i)} variable (f : ι₂ → ι₁) (hf : Tendsto f 𝓕₂ 𝓕₁) variable (φ : ∀ j, R₁ (f j) → R₂ j) (hφ : ∀ᶠ j in 𝓕₂, MapsTo (φ j) (A₁ (f j)) (A₂ j)) theorem mapAlong_continuous (φ_cont : ∀ j, Continuous (φ j)) : Continuous (mapAlong R₁ R₂ f hf φ hφ) := by rw [continuous_dom] intro S hS set T := f ⁻¹' S ∩ {j | MapsTo (φ j) (A₁ (f j)) (A₂ j)} have hT : 𝓕₂ ≤ 𝓟 T := by rw [le_principal_iff] at hS ⊢ exact inter_mem (hf hS) hφ have hf' : Tendsto f (𝓟 T) (𝓟 S) := by aesop have hφ' : ∀ᶠ j in 𝓟 T, MapsTo (φ j) (A₁ (f j)) (A₂ j) := by aesop have key : mapAlong R₁ R₂ f hf φ hφ ∘ inclusion R₁ A₁ hS = inclusion R₂ A₂ hT ∘ mapAlong R₁ R₂ f hf' φ hφ' := rfl rw [key] exact continuous_inclusion _ |>.comp <| continuous_rng_of_principal.mpr <| continuous_pi fun j ↦ φ_cont j |>.comp <| continuous_eval (f j) end map_continuous end RestrictedProduct
orderedzmod.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 ssrAC div fintype path bigop order finset fingroup. From mathcomp Require Import ssralg poly. (******************************************************************************) (* Number structures *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* This file defines some classes to manipulate number structures, i.e, *) (* structures with an order and a norm. To use this file, insert *) (* "Import Num.Theory." before your scripts. You can also "Import Num.Def." *) (* to enjoy shorter notations (e.g., minr instead of Num.min, lerif instead *) (* of Num.leif, etc.). *) (* *) (* This file defines the following number structures: *) (* *) (* porderZmodType == join of Order.POrder and GRing.Zmodule *) (* The HB class is called POrderedZmodule. *) (* *) (* The ordering symbols and notations (<, <=, >, >=, _ <= _ ?= iff _, *) (* _ < _ ?<= if _, >=<, and ><) and lattice operations (meet and join) *) (* defined in order.v are redefined for the ring_display in the ring_scope *) (* (%R). 0-ary ordering symbols for the ring_display have the suffix "%R", *) (* e.g., <%R. All the other ordering notations are the same as order.v. *) (* *) (* Over these structures, we have the following operations: *) (* x \is a Num.pos <=> x is positive (:= x > 0) *) (* x \is a Num.neg <=> x is negative (:= x < 0) *) (* x \is a Num.nneg <=> x is positive or 0 (:= x >= 0) *) (* x \is a Num.npos <=> x is negative or 0 (:= x <= 0) *) (* x \is a Num.real <=> x is real (:= x >= 0 or x < 0) *) (* *) (* - list of prefixes : *) (* p : positive *) (* n : negative *) (* sp : strictly positive *) (* sn : strictly negative *) (* i : interior = in [0, 1] or ]0, 1[ *) (* e : exterior = in [1, +oo[ or ]1; +oo[ *) (* w : non strict (weak) monotony *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Reserved Notation "n .-root" (format "n .-root"). Reserved Notation "'i". Reserved Notation "'Re z" (at level 10, z at level 8). Reserved Notation "'Im z" (at level 10, z at level 8). Local Open Scope order_scope. Local Open Scope group_scope. Local Open Scope ring_scope. Import Order.TTheory GRing.Theory. Fact ring_display : Order.disp_t. Proof. exact. Qed. Module Num. #[short(type="porderZmodType")] HB.structure Definition POrderedZmodule := { R of Order.isPOrder ring_display R & GRing.Zmodule R }. Module Export Def. Notation ler := (@Order.le ring_display _) (only parsing). Notation "@ 'ler' R" := (@Order.le ring_display R) (at level 10, R at level 8, only parsing) : function_scope. Notation ltr := (@Order.lt ring_display _) (only parsing). Notation "@ 'ltr' R" := (@Order.lt ring_display R) (at level 10, R at level 8, only parsing) : function_scope. Notation ger := (@Order.ge ring_display _) (only parsing). Notation "@ 'ger' R" := (@Order.ge ring_display R) (at level 10, R at level 8, only parsing) : function_scope. Notation gtr := (@Order.gt ring_display _) (only parsing). Notation "@ 'gtr' R" := (@Order.gt ring_display R) (at level 10, R at level 8, only parsing) : function_scope. Notation lerif := (@Order.leif ring_display _) (only parsing). Notation "@ 'lerif' R" := (@Order.leif ring_display R) (at level 10, R at level 8, only parsing) : function_scope. Notation lterif := (@Order.lteif ring_display _) (only parsing). Notation "@ 'lteif' R" := (@Order.lteif ring_display R) (at level 10, R at level 8, only parsing) : function_scope. Notation comparabler := (@Order.comparable ring_display _) (only parsing). Notation "@ 'comparabler' R" := (@Order.comparable ring_display R) (at level 10, R at level 8, only parsing) : function_scope. Notation maxr := (@Order.max ring_display _). Notation "@ 'maxr' R" := (@Order.max ring_display R) (at level 10, R at level 8, only parsing) : function_scope. Notation minr := (@Order.min ring_display _). Notation "@ 'minr' R" := (@Order.min ring_display R) (at level 10, R at level 8, only parsing) : function_scope. Section Def. Context {R : porderZmodType}. Definition Rpos_pred := fun x : R => 0 < x. Definition Rpos : qualifier 0 R := [qualify x | Rpos_pred x]. Definition Rneg_pred := fun x : R => x < 0. Definition Rneg : qualifier 0 R := [qualify x : R | Rneg_pred x]. Definition Rnneg_pred := fun x : R => 0 <= x. Definition Rnneg : qualifier 0 R := [qualify x : R | Rnneg_pred x]. Definition Rnpos_pred := fun x : R => x <= 0. Definition Rnpos : qualifier 0 R := [qualify x : R | Rnpos_pred x]. Definition Rreal_pred := fun x : R => (0 <= x) || (x <= 0). Definition Rreal : qualifier 0 R := [qualify x : R | Rreal_pred x]. End Def. Arguments Rpos_pred _ _ /. Arguments Rneg_pred _ _ /. Arguments Rnneg_pred _ _ /. Arguments Rreal_pred _ _ /. End Def. (* Shorter qualified names, when Num.Def is not imported. *) Notation le := ler (only parsing). Notation lt := ltr (only parsing). Notation ge := ger (only parsing). Notation gt := gtr (only parsing). Notation leif := lerif (only parsing). Notation lteif := lterif (only parsing). Notation comparable := comparabler (only parsing). Notation max := maxr. Notation min := minr. Notation pos := Rpos. Notation neg := Rneg. Notation nneg := Rnneg. Notation npos := Rnpos. Notation real := Rreal. (* (Exported) symbolic syntax. *) Module Import Syntax. Notation "<=%R" := le : function_scope. Notation ">=%R" := ge : function_scope. Notation "<%R" := lt : function_scope. Notation ">%R" := gt : function_scope. Notation "<?=%R" := leif : function_scope. Notation "<?<=%R" := lteif : function_scope. Notation ">=<%R" := comparable : function_scope. Notation "><%R" := (fun x y => ~~ (comparable x y)) : function_scope. Notation "<= y" := (ge y) : ring_scope. Notation "<= y :> T" := (<= (y : T)) (only parsing) : ring_scope. Notation ">= y" := (le y) : ring_scope. Notation ">= y :> T" := (>= (y : T)) (only parsing) : ring_scope. Notation "< y" := (gt y) : ring_scope. Notation "< y :> T" := (< (y : T)) (only parsing) : ring_scope. Notation "> y" := (lt y) : ring_scope. Notation "> y :> T" := (> (y : T)) (only parsing) : ring_scope. Notation "x <= y" := (le x y) : ring_scope. Notation "x <= y :> T" := ((x : T) <= (y : T)) (only parsing) : ring_scope. Notation "x >= y" := (y <= x) (only parsing) : ring_scope. Notation "x >= y :> T" := ((x : T) >= (y : T)) (only parsing) : ring_scope. Notation "x < y" := (lt x y) : ring_scope. Notation "x < y :> T" := ((x : T) < (y : T)) (only parsing) : ring_scope. Notation "x > y" := (y < x) (only parsing) : ring_scope. Notation "x > y :> T" := ((x : T) > (y : T)) (only parsing) : ring_scope. Notation "x <= y <= z" := ((x <= y) && (y <= z)) : ring_scope. Notation "x < y <= z" := ((x < y) && (y <= z)) : ring_scope. Notation "x <= y < z" := ((x <= y) && (y < z)) : ring_scope. Notation "x < y < z" := ((x < y) && (y < z)) : ring_scope. Notation "x <= y ?= 'iff' C" := (lerif x y C) : ring_scope. Notation "x <= y ?= 'iff' C :> R" := ((x : R) <= (y : R) ?= iff C) (only parsing) : ring_scope. Notation "x < y ?<= 'if' C" := (lterif x y C) : ring_scope. Notation "x < y ?<= 'if' C :> R" := ((x : R) < (y : R) ?<= if C) (only parsing) : ring_scope. Notation ">=< y" := [pred x | comparable x y] : ring_scope. Notation ">=< y :> T" := (>=< (y : T)) (only parsing) : ring_scope. Notation "x >=< y" := (comparable x y) : ring_scope. Notation ">< y" := [pred x | ~~ comparable x y] : ring_scope. Notation ">< y :> T" := (>< (y : T)) (only parsing) : ring_scope. Notation "x >< y" := (~~ (comparable x y)) : ring_scope. Export Order.PreOCoercions. End Syntax. Module Export Theory. End Theory. Module Exports. HB.reexport. End Exports. End Num. Export Num.Syntax Num.Exports.
Basic.lean
/- Copyright (c) 2021 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff import Mathlib.LinearAlgebra.Determinant import Mathlib.FieldTheory.Minpoly.Field /-! # Characteristic polynomial We define the characteristic polynomial of `f : M →ₗ[R] M`, where `M` is a finite and free `R`-module. The proof that `f.charpoly` is the characteristic polynomial of the matrix of `f` in any basis is in `LinearAlgebra/Charpoly/ToMatrix`. ## Main definition * `LinearMap.charpoly f` : the characteristic polynomial of `f : M →ₗ[R] M`. -/ universe u v w variable {R : Type u} {M : Type v} [CommRing R] variable [AddCommGroup M] [Module R M] [Module.Free R M] [Module.Finite R M] (f : M →ₗ[R] M) open Matrix Polynomial noncomputable section open Module.Free Polynomial Matrix namespace LinearMap section Basic /-- The characteristic polynomial of `f : M →ₗ[R] M`. -/ def charpoly : R[X] := (toMatrix (chooseBasis R M) (chooseBasis R M) f).charpoly theorem charpoly_def : f.charpoly = (toMatrix (chooseBasis R M) (chooseBasis R M) f).charpoly := rfl theorem eval_charpoly (t : R) : f.charpoly.eval t = (algebraMap _ _ t - f).det := by rw [charpoly, Matrix.eval_charpoly, ← LinearMap.det_toMatrix (chooseBasis R M), map_sub, scalar_apply, toMatrix_algebraMap, scalar_apply] @[simp] theorem charpoly_zero [StrongRankCondition R] : (0 : M →ₗ[R] M).charpoly = X ^ Module.finrank R M := by simp [charpoly, Module.finrank_eq_card_chooseBasisIndex] theorem charpoly_one [StrongRankCondition R] : (1 : M →ₗ[R] M).charpoly = (X - 1) ^ Module.finrank R M := by simp [charpoly, Module.finrank_eq_card_chooseBasisIndex, Matrix.charpoly_one] end Basic section Coeff theorem charpoly_monic : f.charpoly.Monic := Matrix.charpoly_monic _ open Module in lemma charpoly_natDegree [Nontrivial R] [StrongRankCondition R] : natDegree (charpoly f) = finrank R M := by rw [charpoly, Matrix.charpoly_natDegree_eq_dim, finrank_eq_card_chooseBasisIndex] end Coeff section CayleyHamilton /-- The **Cayley-Hamilton Theorem**, that the characteristic polynomial of a linear map, applied to the linear map itself, is zero. See `Matrix.aeval_self_charpoly` for the equivalent statement about matrices. -/ theorem aeval_self_charpoly : aeval f f.charpoly = 0 := by apply (LinearEquiv.map_eq_zero_iff (algEquivMatrix (chooseBasis R M)).toLinearEquiv).1 rw [AlgEquiv.toLinearEquiv_apply, ← AlgEquiv.coe_algHom, ← Polynomial.aeval_algHom_apply _ _ _, charpoly_def] exact Matrix.aeval_self_charpoly _ theorem isIntegral : IsIntegral R f := ⟨f.charpoly, ⟨charpoly_monic f, aeval_self_charpoly f⟩⟩ theorem minpoly_dvd_charpoly {K : Type u} {M : Type v} [Field K] [AddCommGroup M] [Module K M] [FiniteDimensional K M] (f : M →ₗ[K] M) : minpoly K f ∣ f.charpoly := minpoly.dvd _ _ (aeval_self_charpoly f) /-- Any endomorphism polynomial `p` is equivalent under evaluation to `p %ₘ f.charpoly`; that is, `p` is equivalent to a polynomial with degree less than the dimension of the module. -/ theorem aeval_eq_aeval_mod_charpoly (p : R[X]) : aeval f p = aeval f (p %ₘ f.charpoly) := (aeval_modByMonic_eq_self_of_root f.charpoly_monic f.aeval_self_charpoly).symm /-- Any endomorphism power can be computed as the sum of endomorphism powers less than the dimension of the module. -/ theorem pow_eq_aeval_mod_charpoly (k : ℕ) : f ^ k = aeval f (X ^ k %ₘ f.charpoly) := by rw [← aeval_eq_aeval_mod_charpoly, map_pow, aeval_X] variable {f} theorem minpoly_coeff_zero_of_injective [Nontrivial R] (hf : Function.Injective f) : (minpoly R f).coeff 0 ≠ 0 := by intro h obtain ⟨P, hP⟩ := X_dvd_iff.2 h have hdegP : P.degree < (minpoly R f).degree := by rw [hP, mul_comm] refine degree_lt_degree_mul_X fun h => ?_ rw [h, mul_zero] at hP exact minpoly.ne_zero (isIntegral f) hP have hPmonic : P.Monic := by suffices (minpoly R f).Monic by rwa [Monic.def, hP, mul_comm, leadingCoeff_mul_X, ← Monic.def] at this exact minpoly.monic (isIntegral f) have hzero : aeval f (minpoly R f) = 0 := minpoly.aeval _ _ simp only [hP, Module.End.mul_eq_comp, LinearMap.ext_iff, hf, aeval_X, map_eq_zero_iff, coe_comp, map_mul, zero_apply, Function.comp_apply] at hzero exact not_le.2 hdegP (minpoly.min _ _ hPmonic (LinearMap.ext hzero)) end CayleyHamilton end LinearMap
AbelSummation.lean
/- Copyright (c) 2024 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.MeasureTheory.Function.Floor import Mathlib.MeasureTheory.Integral.Asymptotics import Mathlib.MeasureTheory.Integral.IntegralEqImproper import Mathlib.Topology.Order.IsLocallyClosed /-! # Abel's summation formula We prove several versions of Abel's summation formula. ## Results * `sum_mul_eq_sub_sub_integral_mul`: general statement of the formula for a sum between two (nonnegative) reals `a` and `b`. * `sum_mul_eq_sub_integral_mul`: a specialized version of `sum_mul_eq_sub_sub_integral_mul` for the case `a = 0`. * `sum_mul_eq_sub_integral_mul₀`: a specialized version of `sum_mul_eq_sub_integral_mul` for when the first coefficient of the sequence is `0`. This is useful for `ArithmeticFunction`. Primed versions of the three results above are also stated for when the endpoints are `Nat`. * `tendsto_sum_mul_atTop_nhds_one_sub_integral`: limit version of `sum_mul_eq_sub_integral_mul` when `a` tends to `∞`. * `tendsto_sum_mul_atTop_nhds_one_sub_integral₀`: limit version of `sum_mul_eq_sub_integral_mul₀` when `a` tends to `∞`. * `summable_mul_of_bigO_atTop`: let `c : ℕ → 𝕜` and `f : ℝ → 𝕜` with `𝕜 = ℝ` or `ℂ`, prove the summability of `n ↦ (c n) * (f n)` using Abel's formula under some `bigO` assumptions at infinity. ## References * <https://en.wikipedia.org/wiki/Abel%27s_summation_formula> -/ noncomputable section open Finset MeasureTheory variable {𝕜 : Type*} [RCLike 𝕜] (c : ℕ → 𝕜) {f : ℝ → 𝕜} {a b : ℝ} namespace abelSummationProof open intervalIntegral IntervalIntegrable private theorem sumlocc {m : ℕ} (n : ℕ) : ∀ᵐ t, t ∈ Set.Icc (n : ℝ) (n + 1) → ∑ k ∈ Icc m ⌊t⌋₊, c k = ∑ k ∈ Icc m n, c k := by filter_upwards [Ico_ae_eq_Icc] with t h ht rw [Nat.floor_eq_on_Ico _ _ (h.mpr ht)] open scoped Interval in private theorem integralmulsum (hf_diff : ∀ t ∈ Set.Icc a b, DifferentiableAt ℝ f t) (hf_int : IntegrableOn (deriv f) (Set.Icc a b)) (t₁ t₂ : ℝ) (n : ℕ) (h : t₁ ≤ t₂) (h₁ : n ≤ t₁) (h₂ : t₂ ≤ n + 1) (h₃ : a ≤ t₁) (h₄ : t₂ ≤ b) : ∫ t in t₁..t₂, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k = (f t₂ - f t₁) * ∑ k ∈ Icc 0 n, c k := by have h_inc₁ : Ι t₁ t₂ ⊆ Set.Icc n (n + 1) := Set.uIoc_of_le h ▸ Set.Ioc_subset_Icc_self.trans <| Set.Icc_subset_Icc h₁ h₂ have h_inc₂ : Set.uIcc t₁ t₂ ⊆ Set.Icc a b := Set.uIcc_of_le h ▸ Set.Icc_subset_Icc h₃ h₄ rw [← integral_deriv_eq_sub (fun t ht ↦ hf_diff t (h_inc₂ ht)), ← intervalIntegral.integral_mul_const] · refine integral_congr_ae ?_ filter_upwards [sumlocc c n] with t h h' rw [h (h_inc₁ h')] · refine (intervalIntegrable_iff_integrableOn_Icc_of_le h).mpr (hf_int.mono_set ?_) rwa [← Set.uIcc_of_le h] private theorem ineqofmemIco {k : ℕ} (hk : k ∈ Set.Ico (⌊a⌋₊ + 1) ⌊b⌋₊) : a ≤ k ∧ k + 1 ≤ b := by constructor · have := (Set.mem_Ico.mp hk).1 exact le_of_lt <| (Nat.floor_lt' (by omega)).mp this · rw [← Nat.cast_add_one, ← Nat.le_floor_iff' (Nat.succ_ne_zero k)] exact (Set.mem_Ico.mp hk).2 private theorem ineqofmemIco' {k : ℕ} (hk : k ∈ Ico (⌊a⌋₊ + 1) ⌊b⌋₊) : a ≤ k ∧ k + 1 ≤ b := ineqofmemIco (by rwa [← Finset.coe_Ico]) theorem _root_.integrableOn_mul_sum_Icc {m : ℕ} (ha : 0 ≤ a) {g : ℝ → 𝕜} (hg_int : IntegrableOn g (Set.Icc a b)) : IntegrableOn (fun t ↦ g t * ∑ k ∈ Icc m ⌊t⌋₊, c k) (Set.Icc a b) := by obtain hab | hab := le_or_gt a b · obtain hb | hb := eq_or_lt_of_le (Nat.floor_le_floor hab) · have : ∀ᵐ t, t ∈ Set.Icc a b → ∑ k ∈ Icc m ⌊a⌋₊, c k = ∑ k ∈ Icc m ⌊t⌋₊, c k := by filter_upwards [sumlocc c ⌊a⌋₊] with t ht₁ ht₂ rw [ht₁ ⟨(Nat.floor_le ha).trans ht₂.1, hb ▸ ht₂.2.trans (Nat.lt_floor_add_one b).le⟩] rw [← ae_restrict_iff' measurableSet_Icc] at this exact IntegrableOn.congr_fun_ae (hg_int.mul_const _) ((Filter.EventuallyEq.refl _ g).mul this) · have h_locint {t₁ t₂ : ℝ} {n : ℕ} (h : t₁ ≤ t₂) (h₁ : n ≤ t₁) (h₂ : t₂ ≤ n + 1) (h₃ : a ≤ t₁) (h₄ : t₂ ≤ b) : IntervalIntegrable (fun t ↦ g t * ∑ k ∈ Icc m ⌊t⌋₊, c k) volume t₁ t₂ := by rw [intervalIntegrable_iff_integrableOn_Icc_of_le h] exact (IntegrableOn.mono_set (hg_int.mul_const _) (Set.Icc_subset_Icc h₃ h₄)).congr <| ae_restrict_of_ae_restrict_of_subset (Set.Icc_subset_Icc h₁ h₂) <| (ae_restrict_iff' measurableSet_Icc).mpr (by filter_upwards [sumlocc c n] with t h ht using by rw [h ht]) have aux1 : 0 ≤ b := (Nat.pos_of_floor_pos <| (Nat.zero_le _).trans_lt hb).le have aux2 : ⌊a⌋₊ + 1 ≤ b := by rwa [← Nat.cast_add_one, ← Nat.le_floor_iff aux1] have aux3 : a ≤ ⌊a⌋₊ + 1 := (Nat.lt_floor_add_one _).le have aux4 : a ≤ ⌊b⌋₊ := le_of_lt (by rwa [← Nat.floor_lt ha]) -- now break up into 3 subintervals rw [← intervalIntegrable_iff_integrableOn_Icc_of_le (aux3.trans aux2)] have I1 : IntervalIntegrable _ volume a ↑(⌊a⌋₊ + 1) := h_locint (mod_cast aux3) (Nat.floor_le ha) (mod_cast le_rfl) le_rfl (mod_cast aux2) have I2 : IntervalIntegrable _ volume ↑(⌊a⌋₊ + 1) ⌊b⌋₊ := trans_iterate_Ico hb fun k hk ↦ h_locint (mod_cast k.le_succ) le_rfl (mod_cast le_rfl) (ineqofmemIco hk).1 (mod_cast (ineqofmemIco hk).2) have I3 : IntervalIntegrable _ volume ⌊b⌋₊ b := h_locint (Nat.floor_le aux1) le_rfl (Nat.lt_floor_add_one _).le aux4 le_rfl exact (I1.trans I2).trans I3 · rw [Set.Icc_eq_empty_of_lt hab] exact integrableOn_empty /-- Abel's summation formula. -/ theorem _root_.sum_mul_eq_sub_sub_integral_mul (ha : 0 ≤ a) (hab : a ≤ b) (hf_diff : ∀ t ∈ Set.Icc a b, DifferentiableAt ℝ f t) (hf_int : IntegrableOn (deriv f) (Set.Icc a b)) : ∑ k ∈ Ioc ⌊a⌋₊ ⌊b⌋₊, f k * c k = f b * (∑ k ∈ Icc 0 ⌊b⌋₊, c k) - f a * (∑ k ∈ Icc 0 ⌊a⌋₊, c k) - ∫ t in Set.Ioc a b, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k := by rw [← integral_of_le hab] have aux1 : ⌊a⌋₊ ≤ a := Nat.floor_le ha have aux2 : b ≤ ⌊b⌋₊ + 1 := (Nat.lt_floor_add_one _).le -- We consider two cases depending on whether the sum is empty or not obtain hb | hb := eq_or_lt_of_le (Nat.floor_le_floor hab) · rw [hb, Ioc_eq_empty_of_le le_rfl, sum_empty, ← sub_mul, integralmulsum c hf_diff hf_int _ _ ⌊b⌋₊ hab (hb ▸ aux1) aux2 le_rfl le_rfl, sub_self] have aux3 : a ≤ ⌊a⌋₊ + 1 := (Nat.lt_floor_add_one _).le have aux4 : ⌊a⌋₊ + 1 ≤ b := by rwa [← Nat.cast_add_one, ← Nat.le_floor_iff (ha.trans hab)] have aux5 : ⌊b⌋₊ ≤ b := Nat.floor_le (ha.trans hab) have aux6 : a ≤ ⌊b⌋₊ := Nat.floor_lt ha |>.mp hb |>.le simp_rw [← smul_eq_mul, sum_Ioc_by_parts (fun k ↦ f k) _ hb, range_eq_Ico, Ico_add_one_right_eq_Icc, smul_eq_mul] have : ∑ k ∈ Ioc ⌊a⌋₊ (⌊b⌋₊ - 1), (f ↑(k + 1) - f k) * ∑ n ∈ Icc 0 k, c n = ∑ k ∈ Ico (⌊a⌋₊ + 1) ⌊b⌋₊, ∫ t in k..↑(k + 1), deriv f t * ∑ n ∈ Icc 0 ⌊t⌋₊, c n := by rw [← Ico_add_one_add_one_eq_Ioc, Nat.sub_add_cancel (by omega), Eq.comm] exact sum_congr rfl fun k hk ↦ (integralmulsum c hf_diff hf_int _ _ _ (mod_cast k.le_succ) le_rfl (mod_cast le_rfl) (ineqofmemIco' hk).1 <| mod_cast (ineqofmemIco' hk).2) rw [this, sum_integral_adjacent_intervals_Ico hb, Nat.cast_add, Nat.cast_one, ← integral_interval_sub_left (a := a) (c := ⌊a⌋₊ + 1), ← integral_add_adjacent_intervals (b := ⌊b⌋₊) (c := b), integralmulsum c hf_diff hf_int _ _ _ aux3 aux1 le_rfl le_rfl aux4, integralmulsum c hf_diff hf_int _ _ _ aux5 le_rfl aux2 aux6 le_rfl] · ring -- now deal with the integrability side goals -- (Note we have 5 goals, but the 1st and 3rd are identical. TODO: find a non-hacky way of dealing -- with both at once.) · rw [intervalIntegrable_iff_integrableOn_Icc_of_le aux6] exact (integrableOn_mul_sum_Icc c ha hf_int).mono_set (Set.Icc_subset_Icc_right aux5) · rw [intervalIntegrable_iff_integrableOn_Icc_of_le aux5] exact (integrableOn_mul_sum_Icc c ha hf_int).mono_set (Set.Icc_subset_Icc_left aux6) · rw [intervalIntegrable_iff_integrableOn_Icc_of_le aux6] exact (integrableOn_mul_sum_Icc c ha hf_int).mono_set (Set.Icc_subset_Icc_right aux5) · rw [intervalIntegrable_iff_integrableOn_Icc_of_le aux3] exact (integrableOn_mul_sum_Icc c ha hf_int).mono_set (Set.Icc_subset_Icc_right aux4) · exact fun k hk ↦ (intervalIntegrable_iff_integrableOn_Icc_of_le (mod_cast k.le_succ)).mpr <| (integrableOn_mul_sum_Icc c ha hf_int).mono_set <| (Set.Icc_subset_Icc_iff (mod_cast k.le_succ)).mpr <| mod_cast (ineqofmemIco hk) /-- A version of `sum_mul_eq_sub_sub_integral_mul` where the endpoints are `Nat`. -/ theorem _root_.sum_mul_eq_sub_sub_integral_mul' {n m : ℕ} (h : n ≤ m) (hf_diff : ∀ t ∈ Set.Icc (n : ℝ) m, DifferentiableAt ℝ f t) (hf_int : IntegrableOn (deriv f) (Set.Icc (n : ℝ) m)) : ∑ k ∈ Ioc n m, f k * c k = f m * (∑ k ∈ Icc 0 m, c k) - f n * (∑ k ∈ Icc 0 n, c k) - ∫ t in Set.Ioc (n : ℝ) m, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k := by convert sum_mul_eq_sub_sub_integral_mul c n.cast_nonneg (Nat.cast_le.mpr h) hf_diff hf_int all_goals rw [Nat.floor_natCast] end abelSummationProof section specialversions /-- Specialized version of `sum_mul_eq_sub_sub_integral_mul` for the case `a = 0` -/ theorem sum_mul_eq_sub_integral_mul {b : ℝ} (hb : 0 ≤ b) (hf_diff : ∀ t ∈ Set.Icc 0 b, DifferentiableAt ℝ f t) (hf_int : IntegrableOn (deriv f) (Set.Icc 0 b)) : ∑ k ∈ Icc 0 ⌊b⌋₊, f k * c k = f b * (∑ k ∈ Icc 0 ⌊b⌋₊, c k) - ∫ t in Set.Ioc 0 b, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k := by nth_rewrite 1 [Icc_eq_cons_Ioc (Nat.zero_le _)] rw [sum_cons, ← Nat.floor_zero (R := ℝ), sum_mul_eq_sub_sub_integral_mul c le_rfl hb hf_diff hf_int, Nat.floor_zero, Nat.cast_zero, Icc_self, sum_singleton] ring /-- A version of `sum_mul_eq_sub_integral_mul` where the endpoint is a `Nat`. -/ theorem sum_mul_eq_sub_integral_mul' (m : ℕ) (hf_diff : ∀ t ∈ Set.Icc (0 : ℝ) m, DifferentiableAt ℝ f t) (hf_int : IntegrableOn (deriv f) (Set.Icc (0 : ℝ) m)) : ∑ k ∈ Icc 0 m, f k * c k = f m * (∑ k ∈ Icc 0 m, c k) - ∫ t in Set.Ioc (0 : ℝ) m, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k := by convert sum_mul_eq_sub_integral_mul c m.cast_nonneg hf_diff hf_int all_goals rw [Nat.floor_natCast] /-- Specialized version of `sum_mul_eq_sub_integral_mul` when the first coefficient of the sequence `c` is equal to `0`. -/ theorem sum_mul_eq_sub_integral_mul₀ (hc : c 0 = 0) (b : ℝ) (hf_diff : ∀ t ∈ Set.Icc 1 b, DifferentiableAt ℝ f t) (hf_int : IntegrableOn (deriv f) (Set.Icc 1 b)) : ∑ k ∈ Icc 0 ⌊b⌋₊, f k * c k = f b * (∑ k ∈ Icc 0 ⌊b⌋₊, c k) - ∫ t in Set.Ioc 1 b, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k := by obtain hb | hb := le_or_gt 1 b · have : 1 ≤ ⌊b⌋₊ := (Nat.one_le_floor_iff _).mpr hb nth_rewrite 1 [Icc_eq_cons_Ioc (Nat.zero_le _), sum_cons, ← Icc_add_one_left_eq_Ioc, Icc_eq_cons_Ioc (by omega), sum_cons] rw [zero_add, ← Nat.floor_one (R := ℝ), sum_mul_eq_sub_sub_integral_mul c zero_le_one hb hf_diff hf_int, Nat.floor_one, Nat.cast_one, Icc_eq_cons_Ioc zero_le_one, sum_cons, show 1 = 0 + 1 by rfl, Nat.Ioc_succ_singleton, zero_add, sum_singleton, hc, mul_zero, zero_add] ring · simp_rw [Nat.floor_eq_zero.mpr hb, Icc_self, sum_singleton, Nat.cast_zero, hc, mul_zero, Set.Ioc_eq_empty_of_le hb.le, Measure.restrict_empty, integral_zero_measure, sub_self] /-- A version of `sum_mul_eq_sub_integral_mul₀` where the endpoint is a `Nat`. -/ theorem sum_mul_eq_sub_integral_mul₀' (hc : c 0 = 0) (m : ℕ) (hf_diff : ∀ t ∈ Set.Icc (1 : ℝ) m, DifferentiableAt ℝ f t) (hf_int : IntegrableOn (deriv f) (Set.Icc (1 : ℝ) m)) : ∑ k ∈ Icc 0 m, f k * c k = f m * (∑ k ∈ Icc 0 m, c k) - ∫ t in Set.Ioc (1 : ℝ) m, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k := by convert sum_mul_eq_sub_integral_mul₀ c hc m hf_diff hf_int all_goals rw [Nat.floor_natCast] end specialversions section limit open Filter Topology abelSummationProof intervalIntegral theorem locallyIntegrableOn_mul_sum_Icc {m : ℕ} (ha : 0 ≤ a) {g : ℝ → 𝕜} (hg : LocallyIntegrableOn g (Set.Ici a)) : LocallyIntegrableOn (fun t ↦ g t * ∑ k ∈ Icc m ⌊t⌋₊, c k) (Set.Ici a) := by refine (locallyIntegrableOn_iff isLocallyClosed_Ici).mpr fun K hK₁ hK₂ ↦ ?_ by_cases hK₃ : K.Nonempty · have h_inf : a ≤ sInf K := (hK₁ (hK₂.sInf_mem hK₃)) refine IntegrableOn.mono_set ?_ (Bornology.IsBounded.subset_Icc_sInf_sSup hK₂.isBounded) refine integrableOn_mul_sum_Icc _ (ha.trans h_inf) ?_ refine hg.integrableOn_compact_subset ?_ isCompact_Icc exact (Set.Icc_subset_Ici_iff (Real.sInf_le_sSup _ hK₂.bddBelow hK₂.bddAbove)).mpr h_inf · rw [Set.not_nonempty_iff_eq_empty.mp hK₃] exact integrableOn_empty theorem tendsto_sum_mul_atTop_nhds_one_sub_integral (hf_diff : ∀ t ∈ Set.Ici 0, DifferentiableAt ℝ f t) (hf_int : LocallyIntegrableOn (deriv f) (Set.Ici 0)) {l : 𝕜} (h_lim : Tendsto (fun n : ℕ ↦ f n * ∑ k ∈ Icc 0 n, c k) atTop (𝓝 l)) {g : ℝ → 𝕜} (hg_dom : (fun t ↦ deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k) =O[atTop] g) (hg_int : IntegrableAtFilter g atTop) : Tendsto (fun n : ℕ ↦ ∑ k ∈ Icc 0 n, f k * c k) atTop (𝓝 (l - ∫ t in Set.Ioi 0, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k)) := by have h_lim' : Tendsto (fun n : ℕ ↦ ∫ t in Set.Ioc (0 : ℝ) n, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k) atTop (𝓝 (∫ t in Set.Ioi 0, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k)) := by refine Tendsto.congr (fun _ ↦ by rw [← integral_of_le (Nat.cast_nonneg _)]) ?_ refine intervalIntegral_tendsto_integral_Ioi _ ?_ tendsto_natCast_atTop_atTop exact Iff.mp integrableOn_Ici_iff_integrableOn_Ioi <| (locallyIntegrableOn_mul_sum_Icc c le_rfl hf_int).integrableOn_of_isBigO_atTop hg_dom hg_int refine (h_lim.sub h_lim').congr (fun _ ↦ ?_) rw [sum_mul_eq_sub_integral_mul' _ _ (fun t ht ↦ hf_diff _ ht.1)] exact hf_int.integrableOn_compact_subset Set.Icc_subset_Ici_self isCompact_Icc theorem tendsto_sum_mul_atTop_nhds_one_sub_integral₀ (hc : c 0 = 0) (hf_diff : ∀ t ∈ Set.Ici 1, DifferentiableAt ℝ f t) (hf_int : LocallyIntegrableOn (deriv f) (Set.Ici 1)) {l : 𝕜} (h_lim : Tendsto (fun n : ℕ ↦ f n * ∑ k ∈ Icc 0 n, c k) atTop (𝓝 l)) {g : ℝ → ℝ} (hg_dom : (fun t ↦ deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k) =O[atTop] g) (hg_int : IntegrableAtFilter g atTop) : Tendsto (fun n : ℕ ↦ ∑ k ∈ Icc 0 n, f k * c k) atTop (𝓝 (l - ∫ t in Set.Ioi 1, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k)) := by have h : (fun n : ℕ ↦ ∫ (x : ℝ) in (1 : ℝ)..n, deriv f x * ∑ k ∈ Icc 0 ⌊x⌋₊, c k) =ᶠ[atTop] (fun n : ℕ ↦ ∫ (t : ℝ) in Set.Ioc 1 ↑n, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k) := by filter_upwards [eventually_ge_atTop 1] with _ h rw [← integral_of_le (Nat.one_le_cast.mpr h)] have h_lim' : Tendsto (fun n : ℕ ↦ ∫ t in Set.Ioc (1 : ℝ) n, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k) atTop (𝓝 (∫ t in Set.Ioi 1, deriv f t * ∑ k ∈ Icc 0 ⌊t⌋₊, c k)) := by refine Tendsto.congr' h (intervalIntegral_tendsto_integral_Ioi _ ?_ tendsto_natCast_atTop_atTop) exact Iff.mp integrableOn_Ici_iff_integrableOn_Ioi <| (locallyIntegrableOn_mul_sum_Icc c zero_le_one hf_int).integrableOn_of_isBigO_atTop hg_dom hg_int refine (h_lim.sub h_lim').congr (fun _ ↦ ?_) rw [sum_mul_eq_sub_integral_mul₀' _ hc _ (fun t ht ↦ hf_diff _ ht.1)] exact hf_int.integrableOn_compact_subset Set.Icc_subset_Ici_self isCompact_Icc end limit section summable open Filter abelSummationProof private theorem summable_mul_of_bigO_atTop_aux (m : ℕ) (h_bdd : (fun n : ℕ ↦ ‖f n‖ * ∑ k ∈ Icc 0 n, ‖c k‖) =O[atTop] fun _ ↦ (1 : ℝ)) (hf_int : LocallyIntegrableOn (deriv (fun t ↦ ‖f t‖)) (Set.Ici (m : ℝ))) (hf : ∀ n : ℕ, ∑ k ∈ Icc 0 n, ‖f k‖ * ‖c k‖ = ‖f n‖ * ∑ k ∈ Icc 0 n, ‖c k‖ - ∫ (t : ℝ) in Set.Ioc ↑m ↑n, deriv (fun t ↦ ‖f t‖) t * ∑ k ∈ Icc 0 ⌊t⌋₊, ‖c k‖) {g : ℝ → ℝ} (hg₁ : (fun t ↦ deriv (fun t ↦ ‖f t‖) t * ∑ k ∈ Icc 0 ⌊t⌋₊, ‖c k‖) =O[atTop] g) (hg₂ : IntegrableAtFilter g atTop) : Summable (fun n : ℕ ↦ f n * c n) := by obtain ⟨C₁, hC₁⟩ := Asymptotics.isBigO_one_nat_atTop_iff.mp h_bdd let C₂ := ∫ t in Set.Ioi (m : ℝ), ‖deriv (fun t ↦ ‖f t‖) t * ∑ k ∈ Icc 0 ⌊t⌋₊, ‖c k‖‖ refine summable_of_sum_range_norm_le (c := max (C₁ + C₂) 1) fun n ↦ ?_ cases n with | zero => simp only [range_zero, norm_mul, sum_empty, le_sup_iff, zero_le_one, or_true] | succ n => have h_mes : Measurable fun t ↦ deriv (fun t ↦ ‖f t‖) t * ∑ k ∈ Icc 0 ⌊t⌋₊, ‖c k‖ := (measurable_deriv _).mul <| Measurable.comp' (g := fun n : ℕ ↦ ∑ k ∈ Icc 0 n, ‖c k‖) (fun _ _ ↦ trivial) Nat.measurable_floor rw [Nat.range_eq_Icc_zero_sub_one _ n.add_one_ne_zero, add_tsub_cancel_right] calc _ = ∑ k ∈ Icc 0 n, ‖f k‖ * ‖c k‖ := by simp_rw [norm_mul] _ = ‖f n‖ * ∑ k ∈ Icc 0 n, ‖c k‖ - ∫ t in Set.Ioc ↑m ↑n, deriv (fun t ↦ ‖f t‖) t * ∑ k ∈ Icc 0 ⌊t⌋₊, ‖c k‖ := ?_ _ ≤ C₁ - ∫ t in Set.Ioc ↑m ↑n, deriv (fun t ↦ ‖f t‖) t * ∑ k ∈ Icc 0 ⌊t⌋₊, ‖c k‖ := ?_ _ ≤ C₁ + ∫ t in Set.Ioc ↑m ↑n, ‖deriv (fun t ↦ ‖f t‖) t * ∑ k ∈ Icc 0 ⌊t⌋₊, ‖c k‖‖ := ?_ _ ≤ C₁ + C₂ := ?_ _ ≤ max (C₁ + C₂) 1 := le_max_left _ _ · exact hf _ · refine tsub_le_tsub_right (le_of_eq_of_le (Real.norm_of_nonneg ?_).symm (hC₁ n)) _ exact mul_nonneg (norm_nonneg _) (sum_nonneg fun _ _ ↦ norm_nonneg _) · exact add_le_add_left (le_trans (neg_le_abs _) (Real.norm_eq_abs _ ▸ norm_integral_le_integral_norm _)) _ · refine add_le_add_left (setIntegral_mono_set ?_ ?_ Set.Ioc_subset_Ioi_self.eventuallyLE) C₁ · exact Iff.mp integrableOn_Ici_iff_integrableOn_Ioi <| (integrable_norm_iff h_mes.aestronglyMeasurable).mpr <| (locallyIntegrableOn_mul_sum_Icc _ m.cast_nonneg hf_int).integrableOn_of_isBigO_atTop hg₁ hg₂ · filter_upwards with t using norm_nonneg _ theorem summable_mul_of_bigO_atTop (hf_diff : ∀ t ∈ Set.Ici 0, DifferentiableAt ℝ (fun x ↦ ‖f x‖) t) (hf_int : LocallyIntegrableOn (deriv (fun t ↦ ‖f t‖)) (Set.Ici 0)) (h_bdd : (fun n : ℕ ↦ ‖f n‖ * ∑ k ∈ Icc 0 n, ‖c k‖) =O[atTop] fun _ ↦ (1 : ℝ)) {g : ℝ → ℝ} (hg₁ : (fun t ↦ deriv (fun t ↦ ‖f t‖) t * ∑ k ∈ Icc 0 ⌊t⌋₊, ‖c k‖) =O[atTop] g) (hg₂ : IntegrableAtFilter g atTop) : Summable (fun n : ℕ ↦ f n * c n) := by refine summable_mul_of_bigO_atTop_aux c 0 h_bdd (by rwa [Nat.cast_zero]) (fun n ↦ ?_) hg₁ hg₂ exact_mod_cast sum_mul_eq_sub_integral_mul' _ _ (fun _ ht ↦ hf_diff _ ht.1) (hf_int.integrableOn_compact_subset Set.Icc_subset_Ici_self isCompact_Icc) /-- A version of `summable_mul_of_bigO_atTop` that can be useful to avoid difficulties near zero. -/ theorem summable_mul_of_bigO_atTop' (hf_diff : ∀ t ∈ Set.Ici 1, DifferentiableAt ℝ (fun x ↦ ‖f x‖) t) (hf_int : LocallyIntegrableOn (deriv (fun t ↦ ‖f t‖)) (Set.Ici 1)) (h_bdd : (fun n : ℕ ↦ ‖f n‖ * ∑ k ∈ Icc 1 n, ‖c k‖) =O[atTop] fun _ ↦ (1 : ℝ)) {g : ℝ → ℝ} (hg₁ : (fun t ↦ deriv (fun t ↦ ‖f t‖) t * ∑ k ∈ Icc 1 ⌊t⌋₊, ‖c k‖) =O[atTop] g) (hg₂ : IntegrableAtFilter g atTop) : Summable (fun n : ℕ ↦ f n * c n) := by have h : ∀ n, ∑ k ∈ Icc 1 n, ‖c k‖ = ∑ k ∈ Icc 0 n, ‖(fun n ↦ if n = 0 then 0 else c n) k‖ := by intro n rw [Icc_eq_cons_Ioc n.zero_le, sum_cons, ← Icc_add_one_left_eq_Ioc, zero_add] simp_rw [if_pos, norm_zero, zero_add] exact Finset.sum_congr rfl fun _ h ↦ by rw [if_neg (zero_lt_one.trans_le (mem_Icc.mp h).1).ne'] simp_rw [h] at h_bdd hg₁ refine Summable.congr_atTop (summable_mul_of_bigO_atTop_aux (fun n ↦ if n = 0 then 0 else c n) 1 h_bdd (by rwa [Nat.cast_one]) (fun n ↦ ?_) hg₁ hg₂) ?_ · exact_mod_cast sum_mul_eq_sub_integral_mul₀' _ (by simp only [reduceIte, norm_zero]) n (fun _ ht ↦ hf_diff _ ht.1) (hf_int.integrableOn_compact_subset Set.Icc_subset_Ici_self isCompact_Icc) · filter_upwards [eventually_ne_atTop 0] with k hk simp_rw [if_neg hk] end summable
JordanChevalley.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.Dynamics.Newton import Mathlib.LinearAlgebra.Semisimple import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix /-! # Jordan-Chevalley-Dunford decomposition Given a finite-dimensional linear endomorphism `f`, the Jordan-Chevalley-Dunford theorem provides a sufficient condition for there to exist a nilpotent endomorphism `n` and a semisimple endomorphism `s`, such that `f = n + s` and both `n` and `s` are polynomial expressions in `f`. The condition is that there exists a separable polynomial `P` such that the endomorphism `P(f)` is nilpotent. This condition is always satisfied when the coefficients are a perfect field. The proof given here uses Newton's method and is taken from Chambert-Loir's notes: [Algebre](http://webusers.imj-prg.fr/~antoine.chambert-loir/enseignement/2022-23/agreg/algebre.pdf) ## Main definitions / results: * `Module.End.exists_isNilpotent_isSemisimple`: an endomorphism of a finite-dimensional vector space over a perfect field may be written as a sum of nilpotent and semisimple endomorphisms. Moreover these nilpotent and semisimple components are polynomial expressions in the original endomorphism. ## TODO * Uniqueness of decomposition (once we prove that the sum of commuting semisimple endomorphims is semisimple, this will follow from `Module.End.eq_zero_of_isNilpotent_isSemisimple`). -/ open Algebra Polynomial namespace Module.End variable {K V : Type*} [Field K] [AddCommGroup V] [Module K V] {f : End K V} theorem exists_isNilpotent_isSemisimple_of_separable_of_dvd_pow {P : K[X]} {k : ℕ} (sep : P.Separable) (nil : minpoly K f ∣ P ^ k) : ∃ᵉ (n ∈ adjoin K {f}) (s ∈ adjoin K {f}), IsNilpotent n ∧ IsSemisimple s ∧ f = n + s := by set ff : adjoin K {f} := ⟨f, self_mem_adjoin_singleton K f⟩ set P' := derivative P have nil' : IsNilpotent (aeval ff P) := by use k obtain ⟨q, hq⟩ := nil rw [← map_pow, Subtype.ext_iff] simp [ff, hq] have sep' : IsUnit (aeval ff P') := by obtain ⟨a, b, h⟩ : IsCoprime (P ^ k) P' := sep.pow_left replace h : (aeval f b) * (aeval f P') = 1 := by simpa only [map_add, map_mul, map_one, minpoly.dvd_iff.mp nil, mul_zero, zero_add] using (aeval f).congr_arg h refine isUnit_of_mul_eq_one_right (aeval ff b) _ (Subtype.ext_iff.mpr ?_) simpa [ff, coe_aeval_mk_apply] using h obtain ⟨⟨s, mem⟩, ⟨⟨k, hk⟩, hss⟩, -⟩ := existsUnique_nilpotent_sub_and_aeval_eq_zero nil' sep' refine ⟨f - s, ?_, s, mem, ⟨k, ?_⟩, ?_, (sub_add_cancel f s).symm⟩ · exact sub_mem (self_mem_adjoin_singleton K f) mem · rw [Subtype.ext_iff] at hk simpa using hk · replace hss : aeval s P = 0 := by rwa [Subtype.ext_iff, coe_aeval_mk_apply] at hss exact isSemisimple_of_squarefree_aeval_eq_zero sep.squarefree hss variable [FiniteDimensional K V] /-- **Jordan-Chevalley-Dunford decomposition**: an endomorphism of a finite-dimensional vector space over a perfect field may be written as a sum of nilpotent and semisimple endomorphisms. Moreover these nilpotent and semisimple components are polynomial expressions in the original endomorphism. -/ theorem exists_isNilpotent_isSemisimple [PerfectField K] : ∃ᵉ (n ∈ adjoin K {f}) (s ∈ adjoin K {f}), IsNilpotent n ∧ IsSemisimple s ∧ f = n + s := by obtain ⟨g, k, sep, -, nil⟩ := exists_squarefree_dvd_pow_of_ne_zero (minpoly.ne_zero_of_finite K f) rw [← PerfectField.separable_iff_squarefree] at sep exact exists_isNilpotent_isSemisimple_of_separable_of_dvd_pow sep nil end Module.End
Basic.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.LinearAlgebra.PiTensorProduct import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Algebra.DirectSum.Algebra /-! # Tensor power of a semimodule over a commutative semiring We define the `n`th tensor power of `M` as the n-ary tensor product indexed by `Fin n` of `M`, `⨂[R] (i : Fin n), M`. This is a special case of `PiTensorProduct`. This file introduces the notation `⨂[R]^n M` for `TensorPower R n M`, which in turn is an abbreviation for `⨂[R] i : Fin n, M`. ## Main definitions: * `TensorPower.gsemiring`: the tensor powers form a graded semiring. * `TensorPower.galgebra`: the tensor powers form a graded algebra. ## Implementation notes In this file we use `ₜ1` and `ₜ*` as local notation for the graded multiplicative structure on tensor powers. Elsewhere, using `1` and `*` on `GradedMonoid` should be preferred. -/ open scoped TensorProduct /-- Homogeneous tensor powers $M^{\otimes n}$. `⨂[R]^n M` is a shorthand for `⨂[R] (i : Fin n), M`. -/ abbrev TensorPower (R : Type*) (n : ℕ) (M : Type*) [CommSemiring R] [AddCommMonoid M] [Module R M] : Type _ := ⨂[R] _ : Fin n, M variable {R : Type*} {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] @[inherit_doc] scoped[TensorProduct] notation:max "⨂[" R "]^" n:arg => TensorPower R n namespace PiTensorProduct /-- Two dependent pairs of tensor products are equal if their index is equal and the contents are equal after a canonical reindexing. -/ @[ext (iff := false)] theorem gradedMonoid_eq_of_reindex_cast {ιι : Type*} {ι : ιι → Type*} : ∀ {a b : GradedMonoid fun ii => ⨂[R] _ : ι ii, M} (h : a.fst = b.fst), reindex R (fun _ ↦ M) (Equiv.cast <| congr_arg ι h) a.snd = b.snd → a = b | ⟨ai, a⟩, ⟨bi, b⟩ => fun (hi : ai = bi) (h : reindex R (fun _ ↦ M) _ a = b) => by subst hi simp_all end PiTensorProduct namespace TensorPower open scoped TensorProduct DirectSum open PiTensorProduct /-- As a graded monoid, `⨂[R]^i M` has a `1 : ⨂[R]^0 M`. -/ instance gOne : GradedMonoid.GOne fun i => ⨂[R]^i M where one := tprod R <| @Fin.elim0 M local notation "ₜ1" => @GradedMonoid.GOne.one ℕ (fun i => ⨂[R]^i M) _ _ theorem gOne_def : ₜ1 = tprod R (@Fin.elim0 M) := rfl /-- A variant of `PiTensorProduct.tmulEquiv` with the result indexed by `Fin (n + m)`. -/ def mulEquiv {n m : ℕ} : ⨂[R]^n M ⊗[R] (⨂[R]^m) M ≃ₗ[R] (⨂[R]^(n + m)) M := (tmulEquiv R M).trans (reindex R (fun _ ↦ M) finSumFinEquiv) /-- As a graded monoid, `⨂[R]^i M` has a `(*) : ⨂[R]^i M → ⨂[R]^j M → ⨂[R]^(i + j) M`. -/ instance gMul : GradedMonoid.GMul fun i => ⨂[R]^i M where mul {i j} a b := (TensorProduct.mk R _ _).compr₂ (↑(mulEquiv : _ ≃ₗ[R] (⨂[R]^(i + j)) M)) a b local infixl:70 " ₜ* " => @GradedMonoid.GMul.mul ℕ (fun i => ⨂[R]^i M) _ _ _ _ theorem gMul_def {i j} (a : ⨂[R]^i M) (b : (⨂[R]^j) M) : a ₜ* b = @mulEquiv R M _ _ _ i j (a ⊗ₜ b) := rfl theorem gMul_eq_coe_linearMap {i j} (a : ⨂[R]^i M) (b : (⨂[R]^j) M) : a ₜ* b = ((TensorProduct.mk R _ _).compr₂ ↑(mulEquiv : _ ≃ₗ[R] (⨂[R]^(i + j)) M) : ⨂[R]^i M →ₗ[R] (⨂[R]^j) M →ₗ[R] (⨂[R]^(i + j)) M) a b := rfl variable (R M) /-- Cast between "equal" tensor powers. -/ def cast {i j} (h : i = j) : ⨂[R]^i M ≃ₗ[R] (⨂[R]^j) M := reindex R (fun _ ↦ M) (finCongr h) theorem cast_tprod {i j} (h : i = j) (a : Fin i → M) : cast R M h (tprod R a) = tprod R (a ∘ Fin.cast h.symm) := reindex_tprod _ _ @[simp] theorem cast_refl {i} (h : i = i) : cast R M h = LinearEquiv.refl _ _ := (congr_arg (reindex R fun _ ↦ M) <| finCongr_refl h).trans reindex_refl @[simp] theorem cast_symm {i j} (h : i = j) : (cast R M h).symm = cast R M h.symm := reindex_symm _ @[simp] theorem cast_trans {i j k} (h : i = j) (h' : j = k) : (cast R M h).trans (cast R M h') = cast R M (h.trans h') := reindex_trans _ _ variable {R M} @[simp] theorem cast_cast {i j k} (h : i = j) (h' : j = k) (a : ⨂[R]^i M) : cast R M h' (cast R M h a) = cast R M (h.trans h') a := reindex_reindex _ _ _ @[ext (iff := false)] theorem gradedMonoid_eq_of_cast {a b : GradedMonoid fun n => ⨂[R] _ : Fin n, M} (h : a.fst = b.fst) (h2 : cast R M h a.snd = b.snd) : a = b := by refine gradedMonoid_eq_of_reindex_cast h ?_ rw [cast] at h2 rw [← finCongr_eq_equivCast, ← h2] theorem cast_eq_cast {i j} (h : i = j) : ⇑(cast R M h) = _root_.cast (congrArg (fun i => ⨂[R]^i M) h) := by subst h rw [cast_refl] rfl variable (R) in theorem tprod_mul_tprod {na nb} (a : Fin na → M) (b : Fin nb → M) : tprod R a ₜ* tprod R b = tprod R (Fin.append a b) := by dsimp [gMul_def, mulEquiv] rw [tmulEquiv_apply R M a b] refine (reindex_tprod _ _).trans ?_ congr 1 dsimp only [Fin.append, finSumFinEquiv, Equiv.coe_fn_symm_mk] apply funext apply Fin.addCases <;> simp theorem one_mul {n} (a : ⨂[R]^n M) : cast R M (zero_add n) (ₜ1 ₜ* a) = a := by rw [gMul_def, gOne_def] induction a using PiTensorProduct.induction_on with | smul_tprod r a => rw [TensorProduct.tmul_smul, LinearEquiv.map_smul, LinearEquiv.map_smul, ← gMul_def, tprod_mul_tprod, cast_tprod] congr 2 with i rw [Fin.elim0_append] refine congr_arg a (Fin.ext ?_) simp | add x y hx hy => rw [TensorProduct.tmul_add, map_add, map_add, hx, hy] theorem mul_one {n} (a : ⨂[R]^n M) : cast R M (add_zero _) (a ₜ* ₜ1) = a := by rw [gMul_def, gOne_def] induction a using PiTensorProduct.induction_on with | smul_tprod r a => rw [← TensorProduct.smul_tmul', LinearEquiv.map_smul, LinearEquiv.map_smul, ← gMul_def, tprod_mul_tprod R a _, cast_tprod] congr 2 with i rw [Fin.append_elim0] refine congr_arg a (Fin.ext ?_) simp | add x y hx hy => rw [TensorProduct.add_tmul, map_add, map_add, hx, hy] theorem mul_assoc {na nb nc} (a : (⨂[R]^na) M) (b : (⨂[R]^nb) M) (c : (⨂[R]^nc) M) : cast R M (add_assoc _ _ _) (a ₜ* b ₜ* c) = a ₜ* (b ₜ* c) := by let mul : ∀ n m : ℕ, ⨂[R]^n M →ₗ[R] (⨂[R]^m) M →ₗ[R] (⨂[R]^(n + m)) M := fun n m => (TensorProduct.mk R _ _).compr₂ ↑(mulEquiv : _ ≃ₗ[R] (⨂[R]^(n + m)) M) -- replace `a`, `b`, `c` with `tprod R a`, `tprod R b`, `tprod R c` let e : (⨂[R]^(na + nb + nc)) M ≃ₗ[R] (⨂[R]^(na + (nb + nc))) M := cast R M (add_assoc _ _ _) let lhs : (⨂[R]^na) M →ₗ[R] (⨂[R]^nb) M →ₗ[R] (⨂[R]^nc) M →ₗ[R] (⨂[R]^(na + (nb + nc))) M := (LinearMap.llcomp R _ _ _ ((mul _ nc).compr₂ e.toLinearMap)).comp (mul na nb) have lhs_eq : ∀ a b c, lhs a b c = e (a ₜ* b ₜ* c) := fun _ _ _ => rfl let rhs : (⨂[R]^na) M →ₗ[R] (⨂[R]^nb) M →ₗ[R] (⨂[R]^nc) M →ₗ[R] (⨂[R]^(na + (nb + nc))) M := (LinearMap.llcomp R _ _ _ (LinearMap.lflip (R := R)).toLinearMap <| (LinearMap.llcomp R _ _ _ (mul na _).flip).comp (mul nb nc)).flip have rhs_eq : ∀ a b c, rhs a b c = a ₜ* (b ₜ* c) := fun _ _ _ => rfl suffices lhs = rhs from LinearMap.congr_fun (LinearMap.congr_fun (LinearMap.congr_fun this a) b) c ext a b c -- clean up simp only [e, LinearMap.compMultilinearMap_apply, lhs_eq, rhs_eq, tprod_mul_tprod, cast_tprod] congr 1 with j rw [Fin.append_assoc] refine congr_arg (Fin.append a (Fin.append b c)) (Fin.ext ?_) rw [Fin.coe_cast, Fin.coe_cast] -- for now we just use the default for the `gnpow` field as it's easier. instance gmonoid : GradedMonoid.GMonoid fun i => ⨂[R]^i M := { TensorPower.gMul, TensorPower.gOne with one_mul := fun _ => gradedMonoid_eq_of_cast (zero_add _) (one_mul _) mul_one := fun _ => gradedMonoid_eq_of_cast (add_zero _) (mul_one _) mul_assoc := fun _ _ _ => gradedMonoid_eq_of_cast (add_assoc _ _ _) (mul_assoc _ _ _) } /-- The canonical map from `R` to `⨂[R]^0 M` corresponding to the `algebraMap` of the tensor algebra. -/ def algebraMap₀ : R ≃ₗ[R] (⨂[R]^0) M := LinearEquiv.symm <| isEmptyEquiv (Fin 0) theorem algebraMap₀_eq_smul_one (r : R) : (algebraMap₀ r : (⨂[R]^0) M) = r • ₜ1 := by simp [algebraMap₀]; congr theorem algebraMap₀_one : (algebraMap₀ 1 : (⨂[R]^0) M) = ₜ1 := (algebraMap₀_eq_smul_one 1).trans (one_smul _ _) theorem algebraMap₀_mul {n} (r : R) (a : ⨂[R]^n M) : cast R M (zero_add _) (algebraMap₀ r ₜ* a) = r • a := by rw [gMul_eq_coe_linearMap, algebraMap₀_eq_smul_one, LinearMap.map_smul₂, LinearEquiv.map_smul, ← gMul_eq_coe_linearMap, one_mul] theorem mul_algebraMap₀ {n} (r : R) (a : ⨂[R]^n M) : cast R M (add_zero _) (a ₜ* algebraMap₀ r) = r • a := by rw [gMul_eq_coe_linearMap, algebraMap₀_eq_smul_one, LinearMap.map_smul, LinearEquiv.map_smul, ← gMul_eq_coe_linearMap, mul_one] theorem algebraMap₀_mul_algebraMap₀ (r s : R) : cast R M (add_zero _) (algebraMap₀ r ₜ* algebraMap₀ s) = algebraMap₀ (r * s) := by rw [← smul_eq_mul, LinearEquiv.map_smul] exact algebraMap₀_mul r (@algebraMap₀ R M _ _ _ s) instance gsemiring : DirectSum.GSemiring fun i => ⨂[R]^i M := { TensorPower.gmonoid with mul_zero := fun _ => LinearMap.map_zero _ zero_mul := fun _ => LinearMap.map_zero₂ _ _ mul_add := fun _ _ _ => LinearMap.map_add _ _ _ add_mul := fun _ _ _ => LinearMap.map_add₂ _ _ _ _ natCast := fun n => algebraMap₀ (n : R) natCast_zero := by simp only [Nat.cast_zero, map_zero] natCast_succ := fun n => by simp only [Nat.cast_succ, map_add, algebraMap₀_one] } example : Semiring (⨁ n : ℕ, ⨂[R]^n M) := by infer_instance /-- The tensor powers form a graded algebra. Note that this instance implies `Algebra R (⨁ n : ℕ, ⨂[R]^n M)` via `DirectSum.Algebra`. -/ instance galgebra : DirectSum.GAlgebra R fun i => ⨂[R]^i M where toFun := (algebraMap₀ : R ≃ₗ[R] (⨂[R]^0) M).toLinearMap.toAddMonoidHom map_one := algebraMap₀_one map_mul r s := gradedMonoid_eq_of_cast rfl (by rw [← LinearEquiv.eq_symm_apply] have := algebraMap₀_mul_algebraMap₀ (M := M) r s exact this.symm) commutes r x := gradedMonoid_eq_of_cast (add_comm _ _) (by have := (algebraMap₀_mul r x.snd).trans (mul_algebraMap₀ r x.snd).symm rw [← LinearEquiv.eq_symm_apply, cast_symm] rw [← LinearEquiv.eq_symm_apply, cast_symm, cast_cast] at this exact this) smul_def r x := gradedMonoid_eq_of_cast (zero_add x.fst).symm (by rw [← LinearEquiv.eq_symm_apply, cast_symm] exact (algebraMap₀_mul r x.snd).symm) theorem galgebra_toFun_def (r : R) : DirectSum.GAlgebra.toFun (A := fun i ↦ ⨂[R]^i M) r = algebraMap₀ r := rfl example : Algebra R (⨁ n : ℕ, ⨂[R]^n M) := by infer_instance end TensorPower
alt.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 choice. From mathcomp Require Import div fintype tuple tuple bigop prime finset ssralg. From mathcomp Require Import zmodp fingroup morphism perm automorphism quotient. From mathcomp Require Import action cyclic pgroup gseries sylow. From mathcomp Require Import primitive_action nilpotent maximal. (******************************************************************************) (* Definitions of the symmetric and alternate groups, and some properties. *) (* 'Sym_T == The symmetric group over type T (which must have a finType *) (* structure). *) (* := [set: {perm T}] *) (* 'Alt_T == The alternating group over type T. *) (******************************************************************************) Unset Printing Implicit Defensive. Set Implicit Arguments. Unset Strict Implicit. Import GroupScope GRing. HB.instance Definition _ := isMulGroup.Build bool addbA addFb addbb. Section SymAltDef. Variable T : finType. Implicit Types (s : {perm T}) (x y z : T). (** Definitions of the alternate groups and some Properties **) Definition Sym : {set {perm T}} := setT. Canonical Sym_group := Eval hnf in [group of Sym]. Local Notation "'Sym_T" := Sym. Canonical sign_morph := @Morphism _ _ 'Sym_T _ (in2W (@odd_permM _)). Definition Alt := 'ker (@odd_perm T). Canonical Alt_group := Eval hnf in [group of Alt]. Local Notation "'Alt_T" := Alt. Lemma Alt_even p : (p \in 'Alt_T) = ~~ p. Proof. by rewrite !inE /=; case: odd_perm. Qed. Lemma Alt_subset : 'Alt_T \subset 'Sym_T. Proof. exact: subsetT. Qed. Lemma Alt_normal : 'Alt_T <| 'Sym_T. Proof. exact: ker_normal. Qed. Lemma Alt_norm : 'Sym_T \subset 'N('Alt_T). Proof. by case/andP: Alt_normal. Qed. Let n := #|T|. Lemma Alt_index : 1 < n -> #|'Sym_T : 'Alt_T| = 2. Proof. move=> lt1n; rewrite -card_quotient ?Alt_norm //=. have : ('Sym_T / 'Alt_T) \isog (@odd_perm T @* 'Sym_T) by apply: first_isog. case/isogP=> g /injmP/card_in_imset <-. rewrite /morphim setIid=> ->; rewrite -card_bool; apply: eq_card => b. apply/imsetP; case: b => /=; last first. by exists (1 : {perm T}); [rewrite setIid inE | rewrite odd_perm1]. case: (pickP T) lt1n => [x1 _ | d0]; last by rewrite /n eq_card0. rewrite /n (cardD1 x1) ltnS lt0n => /existsP[x2 /=]. by rewrite eq_sym andbT -odd_tperm; exists (tperm x1 x2); rewrite ?inE. Qed. Lemma card_Sym : #|'Sym_T| = n`!. Proof. rewrite -[n]cardsE -card_perm; apply: eq_card => p. by apply/idP/subsetP=> [? ?|]; rewrite !inE. Qed. Lemma card_Alt : 1 < n -> (2 * #|'Alt_T|)%N = n`!. Proof. by move/Alt_index <-; rewrite mulnC (Lagrange Alt_subset) card_Sym. Qed. Lemma Sym_trans : [transitive^n 'Sym_T, on setT | 'P]. Proof. apply/imsetP; pose t1 := [tuple of enum T]. have dt1: t1 \in n.-dtuple(setT) by rewrite inE enum_uniq; apply/subsetP. exists t1 => //; apply/setP=> t; apply/idP/imsetP=> [|[a _ ->{t}]]; last first. by apply: n_act_dtuple => //; apply/astabsP=> x; rewrite !inE. case/dtuple_onP=> injt _; have injf := inj_comp injt enum_rank_inj. exists (perm injf); first by rewrite inE. apply: eq_from_tnth => i; rewrite tnth_map /= [aperm _ _]permE; congr tnth. by rewrite (tnth_nth (enum_default i)) enum_valK. Qed. Lemma Alt_trans : [transitive^n.-2 'Alt_T, on setT | 'P]. Proof. case n_m2: n Sym_trans => [|[|m]] /= tr_m2; try exact: ntransitive0. have tr_m := ntransitive_weak (leqW (leqnSn m)) tr_m2. case/imsetP: tr_m2; case/tupleP=> x; case/tupleP=> y t. rewrite !dtuple_on_add 2![x \in _]inE inE negb_or /= -!andbA. case/and4P=> nxy ntx nty dt _; apply/imsetP; exists t => //; apply/setP=> u. apply/idP/imsetP=> [|[a _ ->{u}]]; last first. by apply: n_act_dtuple => //; apply/astabsP=> z; rewrite !inE. case/(atransP2 tr_m dt)=> /= a _ ->{u}. case odd_a: (odd_perm a); last by exists a => //; rewrite !inE /= odd_a. exists (tperm x y * a); first by rewrite !inE /= odd_permM odd_tperm nxy odd_a. apply/val_inj/eq_in_map => z tz; rewrite actM /= /aperm; congr (a _). by case: tpermP ntx nty => // <-; rewrite tz. Qed. Lemma aperm_faithful (A : {group {perm T}}) : [faithful A, on setT | 'P]. Proof. by apply/faithfulP=> /= p _ np1; apply/eqP/perm_act1P=> y; rewrite np1 ?inE. Qed. End SymAltDef. Arguments Sym T%_type. Arguments Sym_group T%_type. Arguments Alt T%_type. Arguments Alt_group T%_type. Notation "''Sym_' T" := (Sym T) (at level 8, T at level 2, format "''Sym_' T") : group_scope. Notation "''Sym_' T" := (Sym_group T) : Group_scope. Notation "''Alt_' T" := (Alt T) (at level 8, T at level 2, format "''Alt_' T") : group_scope. Notation "''Alt_' T" := (Alt_group T) : Group_scope. Lemma trivial_Alt_2 (T : finType) : #|T| <= 2 -> 'Alt_T = 1. Proof. rewrite leq_eqVlt => /predU1P[] oT. by apply: card_le1_trivg; rewrite -leq_double -mul2n card_Alt oT. suffices Sym1: 'Sym_T = 1 by apply/trivgP; rewrite -Sym1 subsetT. by apply: card1_trivg; rewrite card_Sym; case: #|T| oT; do 2?case. Qed. Lemma simple_Alt_3 (T : finType) : #|T| = 3 -> simple 'Alt_T. Proof. move=> T3; have{T3} oA: #|'Alt_T| = 3. by apply: double_inj; rewrite -mul2n card_Alt T3. apply/simpleP; split=> [|K]; [by rewrite trivg_card1 oA | case/andP=> sKH _]. have:= cardSg sKH; rewrite oA dvdn_divisors // !inE orbC /= -oA. case/pred2P=> eqK; [right | left]; apply/eqP. by rewrite eqEcard sKH eqK leqnn. by rewrite eq_sym eqEcard sub1G eqK cards1. Qed. Lemma not_simple_Alt_4 (T : finType) : #|T| = 4 -> ~~ simple 'Alt_T. Proof. move=> oT; set A := 'Alt_T. have oA: #|A| = 12 by apply: double_inj; rewrite -mul2n card_Alt oT. suffices [p]: exists p, [/\ prime p, 1 < #|A|`_p < #|A| & #|'Syl_p(A)| == 1%N]. case=> p_pr pA_int; rewrite /A; case/normal_sylowP=> P; case/pHallP. rewrite /= -/A => sPA pP nPA; apply/simpleP=> [] [_]; rewrite -pP in pA_int. by case/(_ P)=> // defP; rewrite defP oA ?cards1 in pA_int. have: #|'Syl_3(A)| \in filter [pred d | d %% 3 == 1%N] (divisors 12). by rewrite mem_filter -dvdn_divisors //= -oA card_Syl_dvd ?card_Syl_mod. rewrite /= oA mem_seq2 orbC. case/predU1P=> [oQ3|]; [exists 2 | exists 3]; split; rewrite ?p_part //. pose A3 := [set x : {perm T} | #[x] == 3]; suffices oA3: #|A :&: A3| = 8. have sQ2 P: P \in 'Syl_2(A) -> P :=: A :\: A3. rewrite inE pHallE oA p_part -natTrecE /= => /andP[sPA /eqP oP]. apply/eqP; rewrite eqEcard -(leq_add2l 8) -{1}oA3 cardsID oA oP. rewrite andbT subsetD sPA; apply/exists_inP=> -[x] /= Px. by rewrite inE => /eqP ox; have:= order_dvdG Px; rewrite oP ox. have [/= P sylP] := Sylow_exists 2 [group of A]. rewrite -(([set P] =P 'Syl_2(A)) _) ?cards1 // eqEsubset sub1set inE sylP. by apply/subsetP=> Q sylQ; rewrite inE -val_eqE /= !sQ2 // inE. rewrite -[8]/(4 * 2)%N -{}oQ3 -sum1_card -sum_nat_const. rewrite (partition_big (fun x => <[x]>%G) [in 'Syl_3(A)]) => [|x]; last first. by case/setIP=> Ax; rewrite /= !inE pHallE p_part cycle_subG Ax oA. apply: eq_bigr => Q; rewrite inE pHallE oA p_part -?natTrecE //=. case/andP=> sQA /eqP oQ; have:= oQ. rewrite (cardsD1 1) group1 -sum1_card => [[/= <-]]; apply: eq_bigl => x. rewrite setIC -val_eqE /= 2!inE in_setD1 -andbA -{4}[x]expg1 -order_dvdn dvdn1. apply/and3P/andP=> [[/eqP-> _ /eqP <-] | [ntx Qx]]; first by rewrite cycle_id. have:= order_dvdG Qx; rewrite oQ dvdn_divisors // mem_seq2 (negPf ntx) /=. by rewrite eqEcard cycle_subG Qx (subsetP sQA) // oQ /order => /eqP->. Qed. Lemma simple_Alt5_base (T : finType) : #|T| = 5 -> simple 'Alt_T. Proof. move=> oT. have F1: #|'Alt_T| = 60 by apply: double_inj; rewrite -mul2n card_Alt oT. have FF (H : {group {perm T}}): H <| 'Alt_T -> H :<>: 1 -> 20 %| #|H|. - move=> Hh1 Hh3. have [x _]: exists x, x \in T by apply/existsP/eqP; rewrite oT. have F2 := Alt_trans T; rewrite oT /= in F2. have F3: [transitive 'Alt_T, on setT | 'P] by apply: ntransitive1 F2. have F4: [primitive 'Alt_T, on setT | 'P] by apply: ntransitive_primitive F2. case: (prim_trans_norm F4 Hh1) => F5. by case: Hh3; apply/trivgP; apply: subset_trans F5 (aperm_faithful _). have F6: 5 %| #|H| by rewrite -oT -cardsT (atrans_dvd F5). have F7: 4 %| #|H|. have F7: #|[set~ x]| = 4 by rewrite cardsC1 oT. case: (pickP [in [set~ x]]) => [y Hy | ?]; last by rewrite eq_card0 in F7. pose K := 'C_H[x | 'P]%G. have F8 : K \subset H by apply: subsetIl. pose Gx := 'C_('Alt_T)[x | 'P]%G. have F9: [transitive^2 Gx, on [set~ x] | 'P]. by rewrite -[[set~ x]]setTI -setDE stab_ntransitive ?inE. have F10: [transitive Gx, on [set~ x] | 'P]. exact: ntransitive1 F9. have F11: [primitive Gx, on [set~ x] | 'P]. exact: ntransitive_primitive F9. have F12: K \subset Gx by apply: setSI; apply: normal_sub. have F13: K <| Gx by rewrite /(K <| _) F12 normsIG // normal_norm. case: (prim_trans_norm F11 F13) => Ksub; last first. by apply: dvdn_trans (cardSg F8); rewrite -F7; apply: atrans_dvd Ksub. have F14: [faithful Gx, on [set~ x] | 'P]. apply/subsetP=> g; do 2![case/setIP] => Altg cgx cgx'. apply: (subsetP (aperm_faithful 'Alt_T)). rewrite inE Altg /=; apply/astabP=> z _. case: (z =P x) => [->|]; first exact: (astab1P cgx). by move/eqP=> nxz; rewrite (astabP cgx') ?inE //. have Hreg g (z : T): g \in H -> g z = z -> g = 1. have F15 h: h \in H -> h x = x -> h = 1. move=> Hh Hhx; have: h \in K by rewrite inE Hh; apply/astab1P. by rewrite (trivGP (subset_trans Ksub F14)) => /set1P. move=> Hg Hgz; have:= in_setT x; rewrite -(atransP F3 z) ?inE //. case/imsetP=> g1 Hg1 Hg2; apply: (conjg_inj g1); rewrite conj1g. apply: F15; last by rewrite Hg2 -permM mulKVg permM Hgz. by case/normalP: Hh1 => _ nH1; rewrite -(nH1 _ Hg1) memJ_conjg. clear K F8 F12 F13 Ksub F14. case: (Cauchy _ F6) => // h Hh /eqP Horder. have diff_hnx_x n: 0 < n -> n < 5 -> x != (h ^+ n) x. move=> Hn1 Hn2; rewrite eq_sym; apply/negP => HH. have: #[h ^+ n] = 5. rewrite orderXgcd // (eqP Horder). by move: Hn1 Hn2 {HH}; do 5 (case: n => [|n] //). have Hhd2: h ^+ n \in H by rewrite groupX. by rewrite (Hreg _ _ Hhd2 (eqP HH)) order1. pose S1 := [tuple x; h x; (h ^+ 3) x]. have DnS1: S1 \in 3.-dtuple(setT). rewrite inE memtE subset_all /= !inE /= !negb_or -!andbA /= andbT. rewrite -{1}[h]expg1 !diff_hnx_x // expgSr permM. by rewrite (inj_eq perm_inj) diff_hnx_x. pose S2 := [tuple x; h x; (h ^+ 2) x]. have DnS2: S2 \in 3.-dtuple(setT). rewrite inE memtE subset_all /= !inE /= !negb_or -!andbA /= andbT. rewrite -{1}[h]expg1 !diff_hnx_x // expgSr permM. by rewrite (inj_eq perm_inj) diff_hnx_x. case: (atransP2 F2 DnS1 DnS2) => g Hg [/=]. rewrite /aperm => Hgx Hghx Hgh3x. have h_g_com: h * g = g * h. suff HH: (g * h * g^-1) * h^-1 = 1 by rewrite -[h * g]mul1g -HH !gnorm. apply: (Hreg _ x); last first. by rewrite !permM -Hgx Hghx -!permM mulKVg mulgV perm1. rewrite groupM // ?groupV // (conjgCV g) mulgK -mem_conjg. by case/normalP: Hh1 => _ ->. have: (g * (h ^+ 2) * g ^-1) x = (h ^+ 3) x. rewrite !permM -Hgx. have ->: h (h x) = (h ^+ 2) x by rewrite /= permM. by rewrite {1}Hgh3x -!permM /= mulgV mulg1 -expgSr. rewrite commuteX // mulgK {1}[expgn]lock expgS permM -lock. by move/perm_inj=> eqxhx; case/eqP: (diff_hnx_x 1%N isT isT); rewrite expg1. by rewrite (@Gauss_dvd 4 5) // F7. apply/simpleP; split => [|H Hnorm]; first by rewrite trivg_card1 F1. case Hcard1: (#|H| == 1%N); move/eqP: Hcard1 => Hcard1. by left; apply: card1_trivg; rewrite Hcard1. right; case Hcard60: (#|H| == 60); move/eqP: Hcard60 => Hcard60. by apply/eqP; rewrite eqEcard Hcard60 F1 andbT; case/andP: Hnorm. have {Hcard1 Hcard60} Hcard20: #|H| = 20. have Hdiv: 20 %| #|H| by apply: FF => // HH; case Hcard1; rewrite HH cards1. case H20: (#|H| == 20); first exact/eqP. case: Hcard60; case/andP: Hnorm; move/cardSg; rewrite F1 => Hdiv1 _. by case/dvdnP: Hdiv H20 Hdiv1 => n ->; move: n; do 4!case=> //. have prime_5: prime 5 by []. have nSyl5: #|'Syl_5(H)| = 1%N. move: (card_Syl_dvd 5 H) (card_Syl_mod H prime_5). rewrite Hcard20; case: (card _) => // n Hdiv. move: (dvdn_leq (isT: (0 < 20)%N) Hdiv). by move: (n) Hdiv; do 20 (case=> //). case: (Sylow_exists 5 H) => S; case/pHallP=> sSH oS. have{} oS: #|S| = 5 by rewrite oS p_part Hcard20. suff: 20 %| #|S| by rewrite oS. apply: FF => [|S1]; last by rewrite S1 cards1 in oS. apply: char_normal_trans Hnorm; apply: lone_subgroup_char => // Q sQH isoQS. rewrite subEproper; apply/norP=> [[nQS _]]; move: nSyl5. rewrite (cardsD1 S) (cardsD1 Q) 4!{1}inE nQS !pHallE sQH sSH Hcard20 p_part. by rewrite (card_isog isoQS) oS. Qed. Section Restrict. Variables (T : finType) (x : T). Notation T' := {y | y != x}. Lemma rfd_funP (p : {perm T}) (u : T') : let p1 := if p x == x then p else 1 in p1 (val u) != x. Proof. case: (p x =P x) => /= [pxx | _]; last by rewrite perm1 (valP u). by rewrite -[x in _ != x]pxx (inj_eq perm_inj); apply: (valP u). Qed. Definition rfd_fun p := [fun u => Sub ((_ : {perm T}) _) (rfd_funP p u) : T']. Lemma rfdP p : injective (rfd_fun p). Proof. apply: can_inj (rfd_fun p^-1) _ => u; apply: val_inj => /=. rewrite -(can_eq (permK p)) permKV eq_sym. by case: eqP => _; rewrite !(perm1, permK). Qed. Definition rfd p := perm (@rfdP p). Hypothesis card_T : 2 < #|T|. Lemma rfd_morph : {in 'C_('Sym_T)[x | 'P] &, {morph rfd : y z / y * z}}. Proof. move=> p q; rewrite !setIA !setIid; move/astab1P=> p_x; move/astab1P=> q_x. apply/permP=> u; apply: val_inj. by rewrite permE /= !permM !permE /= [p x]p_x [q x]q_x eqxx permM /=. Qed. Canonical rfd_morphism := Morphism rfd_morph. Definition rgd_fun (p : {perm T'}) := [fun x1 => if insub x1 is Some u then sval (p u) else x]. Lemma rgdP p : injective (rgd_fun p). Proof. apply: can_inj (rgd_fun p^-1) _ => y /=. case: (insubP _ y) => [u _ val_u|]; first by rewrite valK permK. by rewrite negbK; move/eqP->; rewrite insubF //= eqxx. Qed. Definition rgd p := perm (@rgdP p). Lemma rfd_odd (p : {perm T}) : p x = x -> rfd p = p :> bool. Proof. have rfd1: rfd 1 = 1. by apply/permP => u; apply: val_inj; rewrite permE /= if_same !perm1. have [n] := ubnP #|[set x | p x != x]|; elim: n p => // n IHn p le_p_n px_x. have [p_id | [x1 Hx1]] := set_0Vmem [set x | p x != x]. suffices ->: p = 1 by rewrite rfd1 !odd_perm1. by apply/permP => z; apply: contraFeq (in_set0 z); rewrite perm1 -p_id inE. have nx1x: x1 != x by apply: contraTneq Hx1 => ->; rewrite inE px_x eqxx. have npxx1: p x != x1 by apply: contraNneq nx1x => <-; rewrite px_x. have npx1x: p x1 != x by rewrite -px_x (inj_eq perm_inj). pose p1 := p * tperm x1 (p x1). have fix_p1 y: p y = y -> p1 y = y. by move=> pyy; rewrite permM; have [<-|/perm_inj<-|] := tpermP; rewrite ?pyy. have p1x_x: p1 x = x by apply: fix_p1. have{le_p_n} lt_p1_n: #|[set x | p1 x != x]| < n. move: le_p_n; rewrite ltnS (cardsD1 x1) Hx1; apply/leq_trans/subset_leq_card. rewrite subsetD1 inE permM tpermR eqxx andbT. by apply/subsetP=> y /[!inE]; apply: contraNneq=> /fix_p1->. transitivity (p1 (+) true); last first. by rewrite odd_permM odd_tperm -Hx1 inE eq_sym addbK. have ->: p = p1 * tperm x1 (p x1) by rewrite -tpermV mulgK. rewrite morphM; last 2 first; first by rewrite 2!inE; apply/astab1P. by rewrite 2!inE; apply/astab1P; rewrite -[RHS]p1x_x permM px_x. rewrite odd_permM IHn //=; congr (_ (+) _). pose x2 : T' := Sub x1 nx1x; pose px2 : T' := Sub (p x1) npx1x. suffices ->: rfd (tperm x1 (p x1)) = tperm x2 px2. by rewrite odd_tperm eq_sym; rewrite inE in Hx1. apply/permP => z; apply/val_eqP; rewrite permE /= tpermD // eqxx. by rewrite !permE /= -!val_eqE /= !(fun_if sval) /=. Qed. Lemma rfd_iso : 'C_('Alt_T)[x | 'P] \isog 'Alt_T'. Proof. have rgd_x p: rgd p x = x by rewrite permE /= insubF //= eqxx. have rfd_rgd p: rfd (rgd p) = p. apply/permP => [[z Hz]]; apply/val_eqP; rewrite !permE. by rewrite /= [rgd _ _]permE /= insubF eqxx // permE /= insubT. have sSd: 'C_('Alt_T)[x | 'P] \subset 'dom rfd. by apply/subsetP=> p /[!inE]/= /andP[]. apply/isogP; exists [morphism of restrm sSd rfd] => /=; last first. rewrite morphim_restrm setIid; apply/setP=> z; apply/morphimP/idP=> [[p _]|]. case/setIP; rewrite Alt_even => Hp; move/astab1P=> Hp1 ->. by rewrite Alt_even rfd_odd. have dz': rgd z x == x by rewrite rgd_x. move=> kz; exists (rgd z); last by rewrite /= rfd_rgd. by rewrite 2!inE (sameP astab1P eqP). rewrite 4!inE /= (sameP astab1P eqP) dz' -rfd_odd; last exact/eqP. by rewrite rfd_rgd mker // ?set11. apply/injmP=> x1 y1 /=. case/setIP=> Hax1; move/astab1P; rewrite /= /aperm => Hx1. case/setIP=> Hay1; move/astab1P; rewrite /= /aperm => Hy1 Hr. apply/permP => z. case (z =P x) => [->|]; [by rewrite Hx1 | move/eqP => nzx]. move: (congr1 (fun q : {perm T'} => q (Sub z nzx)) Hr). by rewrite !permE => [[]]; rewrite Hx1 Hy1 !eqxx. Qed. End Restrict. Lemma simple_Alt5 (T : finType) : #|T| >= 5 -> simple 'Alt_T. Proof. suff F1 n: #|T| = n + 5 -> simple 'Alt_T by move/subnK/esym/F1. elim: n T => [| n Hrec T Hde]; first exact: simple_Alt5_base. have oT: 5 < #|T| by rewrite Hde addnC. apply/simpleP; split=> [|H Hnorm]; last have [Hh1 nH] := andP Hnorm. rewrite trivg_card1 -[#|_|]half_double -mul2n card_Alt Hde addnC //. by rewrite addSn factS mulnC -(prednK (fact_gt0 _)). case E1: (pred0b T); first by rewrite /pred0b in E1; rewrite (eqP E1) in oT. case/pred0Pn: E1 => x _; have Hx := in_setT x. have F2: [transitive^4 'Alt_T, on setT | 'P]. by apply: ntransitive_weak (Alt_trans T); rewrite -(subnKC oT). have F3 := ntransitive1 (isT: 0 < 4) F2. have F4 := ntransitive_primitive (isT: 1 < 4) F2. case Hcard1: (#|H| == 1%N); move/eqP: Hcard1 => Hcard1. by left; apply: card1_trivg; rewrite Hcard1. right; case: (prim_trans_norm F4 Hnorm) => F5. by rewrite (trivGP (subset_trans F5 (aperm_faithful _))) cards1 in Hcard1. case E1: (pred0b (predD1 T x)). rewrite /pred0b in E1; move: oT. by rewrite (cardD1 x) (eqP E1); case: (T x). case/pred0Pn: E1 => y Hdy; case/andP: (Hdy) => diff_x_y Hy. pose K := 'C_H[x | 'P]%G. have F8: K \subset H by apply: subsetIl. pose Gx := 'C_('Alt_T)[x | 'P]. have F9: [transitive^3 Gx, on [set~ x] | 'P]. by rewrite -[[set~ x]]setTI -setDE stab_ntransitive ?inE. have F10: [transitive Gx, on [set~ x] | 'P]. by apply: ntransitive1 F9. have F11: [primitive Gx, on [set~ x] | 'P]. by apply: ntransitive_primitive F9. have F12: K \subset Gx by rewrite setSI // normal_sub. have F13: K <| Gx by apply/andP; rewrite normsIG. have:= prim_trans_norm F11; case/(_ K) => //= => Ksub; last first. have F14: Gx * H = 'Alt_T by apply/(subgroup_transitiveP _ _ F3). have: simple Gx. by rewrite (isog_simple (rfd_iso x)) Hrec //= card_sig cardC1 Hde. case/simpleP=> _ simGx; case/simGx: F13 => /= HH2. case Ez: (pred0b (predD1 (predD1 T x) y)). move: oT; rewrite /pred0b in Ez. by rewrite (cardD1 x) (cardD1 y) (eqP Ez) inE /= inE /= diff_x_y. case/pred0Pn: Ez => z; case/andP => diff_y_z Hdz. have [diff_x_z Hz] := andP Hdz. have: z \in [set~ x] by rewrite !inE. rewrite -(atransP Ksub y) ?inE //; case/imsetP => g. rewrite /= HH2 inE; move/eqP=> -> HH4. by case/negP: diff_y_z; rewrite HH4 act1. by rewrite /= -F14 -[Gx]HH2 (mulSGid F8). have F14: [faithful Gx, on [set~ x] | 'P]. apply: subset_trans (aperm_faithful 'Sym_T); rewrite subsetI subsetT. apply/subsetP=> g; do 2![case/setIP]=> _ cgx cgx'; apply/astabP=> z _ /=. case: (z =P x) => [->|]; first exact: (astab1P cgx). by move/eqP=> zx; rewrite [_ g](astabP cgx') ?inE. have Hreg g z: g \in H -> g z = z -> g = 1. have F15 h: h \in H -> h x = x -> h = 1. move=> Hh Hhx; have: h \in K by rewrite inE Hh; apply/astab1P. by rewrite [K](trivGP (subset_trans Ksub F14)) => /set1P. move=> Hg Hgz; have:= in_setT x; rewrite -(atransP F3 z) ?inE //. case/imsetP=> g1 Hg1 Hg2; apply: (conjg_inj g1); rewrite conj1g. apply: F15; last by rewrite Hg2 -permM mulKVg permM Hgz. by rewrite memJ_norm ?(subsetP nH). clear K F8 F12 F13 Ksub F14. have Hcard: 5 < #|H|. apply: (leq_trans oT); apply: dvdn_leq; first exact: cardG_gt0. by rewrite -cardsT (atrans_dvd F5). case Eh: (pred0b [predD1 H & 1]). by move: Hcard; rewrite /pred0b in Eh; rewrite (cardD1 1) group1 (eqP Eh). case/pred0Pn: Eh => h; case/andP => diff_1_h /= Hh. case Eg: (pred0b (predD1 (predD1 [predD1 H & 1] h) h^-1)). move: Hcard; rewrite ltnNge; case/negP. rewrite (cardD1 1) group1 (cardD1 h) (cardD1 h^-1) (eqnP Eg). by do 2!case: (_ \in _). case/pred0Pn: Eg => g; case/andP => diff_h1_g; case/andP => diff_h_g. case/andP => diff_1_g /= Hg. case diff_hx_x: (h x == x). by case/negP: diff_1_h; apply/eqP; apply: (Hreg _ _ Hh (eqP diff_hx_x)). case diff_gx_x: (g x == x). case/negP: diff_1_g; apply/eqP; apply: (Hreg _ _ Hg (eqP diff_gx_x)). case diff_gx_hx: (g x == h x). case/negP: diff_h_g; apply/eqP; symmetry; apply: (mulIg g^-1); rewrite gsimp. apply: (Hreg _ x); first by rewrite groupM // groupV. by rewrite permM -(eqP diff_gx_hx) -permM mulgV perm1. case diff_hgx_x: ((h * g) x == x). case/negP: diff_h1_g; apply/eqP; apply: (mulgI h); rewrite !gsimp. by apply: (Hreg _ x); [apply: groupM | apply/eqP]. case diff_hgx_hx: ((h * g) x == h x). case/negP: diff_1_g; apply/eqP. by apply: (Hreg _ (h x)) => //; apply/eqP; rewrite -permM. case diff_hgx_gx: ((h * g) x == g x). by case/idP: diff_hx_x; rewrite -(can_eq (permK g)) -permM. case Ez: (pred0b (predD1 (predD1 (predD1 (predD1 T x) (h x)) (g x)) ((h * g) x))). - move: oT; rewrite /pred0b in Ez. rewrite (cardD1 x) (cardD1 (h x)) (cardD1 (g x)) (cardD1 ((h * g) x)). by rewrite (eqP Ez) addnC; do 3!case: (_ x \in _). case/pred0Pn: Ez => z. case/and5P=> diff_hgx_z diff_gx_z diff_hx_z diff_x_z /= Hz. pose S1 := [tuple x; h x; g x; z]. have DnS1: S1 \in 4.-dtuple(setT). rewrite inE memtE subset_all -!andbA !negb_or /= !inE !andbT. rewrite -!(eq_sym z) diff_gx_z diff_x_z diff_hx_z. by rewrite !(eq_sym x) diff_hx_x diff_gx_x eq_sym diff_gx_hx. pose S2 := [tuple x; h x; g x; (h * g) x]. have DnS2: S2 \in 4.-dtuple(setT). rewrite inE memtE subset_all -!andbA !negb_or /= !inE !andbT !(eq_sym x). rewrite diff_hx_x diff_gx_x diff_hgx_x. by rewrite !(eq_sym (h x)) diff_gx_hx diff_hgx_hx eq_sym diff_hgx_gx. case: (atransP2 F2 DnS1 DnS2) => k Hk [/=]. rewrite /aperm => Hkx Hkhx Hkgx Hkhgx. have h_k_com: h * k = k * h. suff HH: (k * h * k^-1) * h^-1 = 1 by rewrite -[h * k]mul1g -HH !gnorm. apply: (Hreg _ x); last first. by rewrite !permM -Hkx Hkhx -!permM mulKVg mulgV perm1. by rewrite groupM // ?groupV // (conjgCV k) mulgK -mem_conjg (normsP nH). have g_k_com: g * k = k * g. suff HH: (k * g * k^-1) * g^-1 = 1 by rewrite -[g * k]mul1g -HH !gnorm. apply: (Hreg _ x); last first. by rewrite !permM -Hkx Hkgx -!permM mulKVg mulgV perm1. by rewrite groupM // ?groupV // (conjgCV k) mulgK -mem_conjg (normsP nH). have HH: (k * (h * g) * k ^-1) x = z. by rewrite 2!permM -Hkx Hkhgx -permM mulgV perm1. case/negP: diff_hgx_z. rewrite -HH !mulgA -h_k_com -!mulgA [k * _]mulgA. by rewrite -g_k_com -!mulgA mulgV mulg1. Qed. Lemma gen_tperm_circular_shift (X : finType) x y c : prime #|X| -> x != y -> #[c]%g = #|X| -> <<[set tperm x y; c]>>%g = ('Sym_X)%g. Proof. move=> Xprime neq_xy ord_c; apply/eqP; rewrite eqEsubset subsetT/=. have c_gt1 : (1 < #[c]%g)%N by rewrite ord_c prime_gt1. have cppSS : #[c]%g.-2.+2 = #|X| by rewrite ?prednK ?ltn_predRL. pose f (i : 'Z_#[c]%g) : X := Zpm i x. have [g fK gK] : bijective f. apply: inj_card_bij; rewrite ?cppSS ?card_ord// /f /Zpm => i j cijx. pose stabx := ('C_<[c]>[x | 'P])%g. have cjix : (c ^+ (j - i)%R)%g x = x. by apply: (@perm_inj _ (c ^+ i)%g); rewrite -permM -expgD_Zp// addrNK. have : (c ^+ (j - i)%R)%g \in stabx. by rewrite !inE ?groupX ?mem_gen ?sub1set ?inE// ['P%act _ _]cjix eqxx. rewrite [stabx]perm_prime_astab// => /set1gP. move=> /(congr1 (mulg (c ^+ i))); rewrite -expgD_Zp// addrC addrNK mulg1. by move=> /eqP; rewrite eq_expg_ord// ?cppSS ?ord_c// => /eqP->. pose gsf s := g \o s \o f. have gsf_inj (s : {perm X}) : injective (gsf s). apply: inj_comp; last exact: can_inj fK. by apply: inj_comp; [exact: can_inj gK|exact: perm_inj]. pose fsg s := f \o s \o g. have fsg_inj (s : {perm _}) : injective (fsg s). apply: inj_comp; last exact: can_inj gK. by apply: inj_comp; [exact: can_inj fK|exact: perm_inj]. have gsf_morphic : morphic 'Sym_X (fun s => perm (gsf_inj s)). apply/morphicP => u v _ _; apply/permP => /= i. by rewrite !permE/= !permE /gsf /= gK permM. pose phi := morphm gsf_morphic; rewrite /= in phi. have phi_inj : ('injm phi)%g. apply/subsetP => /= u /mker/=; rewrite morphmE => gsfu1. apply/set1gP/permP=> z; have /permP/(_ (g z)) := gsfu1. by rewrite !perm1 permE /gsf/= gK => /(can_inj gK). have phiT : (phi @* 'Sym_X)%g = [set: {perm 'Z_#[c]%g}]. apply/eqP; rewrite eqEsubset subsetT/=; apply/subsetP => /= u _. apply/morphimP; exists (perm (fsg_inj u)); rewrite ?in_setT//. by apply/permP => /= i; rewrite morphmE permE /gsf/fsg/= permE/= !fK. have f0 : f 0%R = x by rewrite /f /Zpm permX. pose k := g y; have k_gt0 : (k > 0)%N. by rewrite lt0n (val_eqE k 0%R) -(can_eq fK) eq_sym gK f0. have phixy : phi (tperm x y) = tperm (0%R : 'Z_#[c]) k. apply/permP => i; rewrite permE/= /gsf/=; apply: (canLR fK). by rewrite !permE/= -f0 -[y]gK !(can_eq fK) -!fun_if. have phic : phi c = perm (addrI (1%R : 'Z_#[c])). apply/permP => i; rewrite /phi morphmE !permE /gsf/=; apply: (canLR fK). by rewrite /f /Zpm -permM addrC expgD_Zp. rewrite -(injmSK phi_inj)//= morphim_gen/= ?subsetT//= -/phi. rewrite phiT /morphim !setTI/= -/phi imsetU1 imset_set1/= phixy phic. suff /gen_tpermn_circular_shift<- : coprime #[c]%g.-2.+2 (k - 0)%R by []. by rewrite subr0 prime_coprime ?gtnNdvd// ?cppSS. Qed. Section Perm_solvable. Local Open Scope nat_scope. Variable T : finType. Lemma solvable_AltF : 4 < #|T| -> solvable 'Alt_T = false. Proof. move=> card_T; apply/negP => Alt_solvable. have/simple_Alt5 Alt_simple := card_T. have := simple_sol_prime Alt_solvable Alt_simple. have lt_T n : n <= 4 -> n < #|T| by move/leq_ltn_trans; apply. have -> : #|('Alt_T)%G| = #|T|`! %/ 2 by rewrite -card_Alt ?mulKn ?lt_T. move/even_prime => [/eqP|]; apply/negP. rewrite neq_ltn leq_divRL // mulnC -[2 * 3]/(3`!). by apply/orP; right; apply/ltnW/ltn_fact/lt_T. by rewrite -dvdn2 dvdn_divRL dvdn_fact //=; apply/ltnW/lt_T. Qed. Lemma solvable_SymF : 4 < #|T| -> solvable 'Sym_T = false. Proof. by rewrite (series_sol (Alt_normal T)) => /solvable_AltF->. Qed. End Perm_solvable.
center.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 fingroup morphism perm. From mathcomp Require Import automorphism quotient action gproduct gfunctor. From mathcomp Require Import cyclic. (******************************************************************************) (* Definition of the center of a group and of external central products: *) (* 'Z(G) == the center of the group G, i.e., 'C_G(G). *) (* cprod_by isoZ == the finGroupType for the central product of H and K *) (* with centers identified by the isomorphism gz on 'Z(H); *) (* here isoZ : isom 'Z(H) 'Z(K) gz. Note that the actual *) (* central product is [set: cprod_by isoZ]. *) (* cpairg1 isoZ == the isomorphism from H to cprod_by isoZ, isoZ as above. *) (* cpair1g isoZ == the isomorphism from K to cprod_by isoZ, isoZ as above. *) (* xcprod H K == the finGroupType for the external central product of H *) (* and K with identified centers, provided the dynamically *) (* tested condition 'Z(H) \isog 'Z(K) holds. *) (* ncprod H n == the finGroupType for the central product of n copies of *) (* H with their centers identified; [set: ncprod H 0] is *) (* isomorphic to 'Z(H). *) (* xcprodm cf eqf == the morphism induced on cprod_by isoZ, where as above *) (* isoZ : isom 'Z(H) 'Z(K) gz, by fH : {morphism H >-> rT} *) (* and fK : {morphism K >-> rT}, given both *) (* cf : fH @* H \subset 'C(fK @* K) and *) (* eqf : {in 'Z(H), fH =1 fK \o gz}. *) (* Following Aschbacher, we only provide external central products with *) (* identified centers, as these are well defined provided the local center *) (* isomorphism group of one of the subgroups is full. Nevertheless the *) (* entire construction could be carried out under the weaker assumption that *) (* gz is an isomorphism between subgroups of 'Z(H) and 'Z(K), and even the *) (* uniqueness theorem holds under the weaker assumption that gz map 'Z(H) to *) (* a characteristic subgroup of 'Z(K) not isomorphic to any other subgroup of *) (* 'Z(K), a condition that holds for example when K is cyclic, as in the *) (* structure theorem for p-groups of symplectic type. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Section Defs. Variable gT : finGroupType. Definition center (A : {set gT}) := 'C_A(A). Canonical center_group (G : {group gT}) : {group gT} := Eval hnf in [group of center G]. End Defs. Arguments center {gT} A%_g. Notation "''Z' ( A )" := (center A) : group_scope. Notation "''Z' ( H )" := (center_group H) : Group_scope. Lemma morphim_center : GFunctor.pcontinuous (@center). Proof. by move=> gT rT G D f; apply: morphim_subcent. Qed. Canonical center_igFun := [igFun by fun _ _ => subsetIl _ _ & morphim_center]. Canonical center_gFun := [gFun by morphim_center]. Canonical center_pgFun := [pgFun by morphim_center]. Section Center. Variables gT : finGroupType. Implicit Type rT : finGroupType. Implicit Types (x y : gT) (A B : {set gT}) (G H K D : {group gT}). Lemma subcentP A B x : reflect (x \in A /\ centralises x B) (x \in 'C_A(B)). Proof. rewrite inE. case: (x \in A); last by right; case. by apply: (iffP centP) => [|[]]. Qed. Lemma subcent_sub A B : 'C_A(B) \subset 'N_A(B). Proof. by rewrite setIS ?cent_sub. Qed. Lemma subcent_norm G B : 'N_G(B) \subset 'N('C_G(B)). Proof. by rewrite normsI ?subIset ?normG // orbC cent_norm. Qed. Lemma subcent_normal G B : 'C_G(B) <| 'N_G(B). Proof. by rewrite /normal subcent_sub subcent_norm. Qed. Lemma subcent_char G H K : H \char G -> K \char G -> 'C_H(K) \char G. Proof. case/charP=> sHG chHG /charP[sKG chKG]; apply/charP. split=> [|f injf Gf]; first by rewrite subIset ?sHG. by rewrite injm_subcent ?chHG ?chKG. Qed. Lemma centerP A x : reflect (x \in A /\ centralises x A) (x \in 'Z(A)). Proof. exact: subcentP. Qed. Lemma center_sub A : 'Z(A) \subset A. Proof. exact: subsetIl. Qed. Lemma center1 : 'Z(1) = 1 :> {set gT}. Proof. exact: gF1. Qed. Lemma centerC A : {in A, centralised 'Z(A)}. Proof. by apply/centsP; rewrite centsC subsetIr. Qed. Lemma center_normal G : 'Z(G) <| G. Proof. exact: gFnormal. Qed. Lemma sub_center_normal H G : H \subset 'Z(G) -> H <| G. Proof. by rewrite subsetI centsC /normal => /andP[-> /cents_norm]. Qed. Lemma center_abelian G : abelian 'Z(G). Proof. by rewrite /abelian subIset // centsC subIset // subxx orbT. Qed. Lemma center_char G : 'Z(G) \char G. Proof. exact: gFchar. Qed. Lemma center_idP A : reflect ('Z(A) = A) (abelian A). Proof. exact: setIidPl. Qed. Lemma center_class_formula G : #|G| = #|'Z(G)| + \sum_(xG in [set x ^: G | x in G :\: 'C(G)]) #|xG|. Proof. by rewrite acts_sum_card_orbit ?cardsID // astabsJ normsD ?norms_cent ?normG. Qed. Lemma subcent1P A x y : reflect (y \in A /\ commute x y) (y \in 'C_A[x]). Proof. rewrite inE; case: (y \in A); last by right; case. by apply: (iffP cent1P) => [|[]]. Qed. Lemma subcent1_id x G : x \in G -> x \in 'C_G[x]. Proof. by move=> Gx; rewrite inE Gx; apply/cent1P. Qed. Lemma subcent1_sub x G : 'C_G[x] \subset G. Proof. exact: subsetIl. Qed. Lemma subcent1C x y G : x \in G -> y \in 'C_G[x] -> x \in 'C_G[y]. Proof. by move=> Gx /subcent1P[_ cxy]; apply/subcent1P. Qed. Lemma subcent1_cycle_sub x G : x \in G -> <[x]> \subset 'C_G[x]. Proof. by move=> Gx; rewrite cycle_subG ?subcent1_id. Qed. Lemma subcent1_cycle_norm x G : 'C_G[x] \subset 'N(<[x]>). Proof. by rewrite cents_norm // cent_gen cent_set1 subsetIr. Qed. Lemma subcent1_cycle_normal x G : x \in G -> <[x]> <| 'C_G[x]. Proof. by move=> Gx; rewrite /normal subcent1_cycle_norm subcent1_cycle_sub. Qed. (* Gorenstein. 1.3.4 *) Lemma cyclic_center_factor_abelian G : cyclic (G / 'Z(G)) -> abelian G. Proof. case/cyclicP=> a Ga; case: (cosetP a) => /= z Nz def_a. have G_Zz: G :=: 'Z(G) * <[z]>. rewrite -quotientK ?cycle_subG ?quotient_cycle //=. by rewrite -def_a -Ga quotientGK // center_normal. rewrite G_Zz abelianM cycle_abelian center_abelian centsC /= G_Zz. by rewrite subIset ?centS ?orbT ?mulG_subr. Qed. Lemma cyclic_factor_abelian H G : H \subset 'Z(G) -> cyclic (G / H) -> abelian G. Proof. move=> sHZ cycGH; apply: cyclic_center_factor_abelian. have /andP[_ nHG]: H <| G := sub_center_normal sHZ. have [f <-]:= homgP (homg_quotientS nHG (gFnorm _ G) sHZ). exact: morphim_cyclic cycGH. Qed. Section Injm. Variables (rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}). Hypothesis injf : 'injm f. Lemma injm_center G : G \subset D -> f @* 'Z(G) = 'Z(f @* G). Proof. exact: injm_subcent. Qed. End Injm. End Center. Arguments center_idP {gT A}. Lemma isog_center (aT rT : finGroupType) (G : {group aT}) (H : {group rT}) : G \isog H -> 'Z(G) \isog 'Z(H). Proof. exact: gFisog. Qed. Section Product. Variable gT : finGroupType. Implicit Types (A B C : {set gT}) (G H K : {group gT}). Lemma center_prod H K : K \subset 'C(H) -> 'Z(H) * 'Z(K) = 'Z(H * K). Proof. move=> cHK; apply/setP=> z; rewrite {3}/center centM !inE. have cKH: H \subset 'C(K) by rewrite centsC. apply/imset2P/and3P=> [[x y /setIP[Hx cHx] /setIP[Ky cKy] ->{z}]| []]. by rewrite imset2_f ?groupM // ?(subsetP cHK) ?(subsetP cKH). case/imset2P=> x y Hx Ky ->{z}. rewrite groupMr => [cHx|]; last exact: subsetP Ky. rewrite groupMl => [cKy|]; last exact: subsetP Hx. by exists x y; rewrite ?inE ?Hx ?Ky. Qed. Lemma center_cprod A B G : A \* B = G -> 'Z(A) \* 'Z(B) = 'Z(G). Proof. case/cprodP => [[H K -> ->] <- cHK]. rewrite cprodE ?center_prod //= subIset ?(subset_trans cHK) //. by rewrite centS ?center_sub. Qed. Lemma center_bigcprod I r P (F : I -> {set gT}) G : \big[cprod/1]_(i <- r | P i) F i = G -> \big[cprod/1]_(i <- r | P i) 'Z(F i) = 'Z(G). Proof. elim/big_ind2: _ G => [_ <-|A B C D IHA IHB G dG|_ _ G ->]; rewrite ?center1 //. case/cprodP: dG IHA IHB (dG) => [[H K -> ->] _ _] IHH IHK dG. by rewrite (IHH H) // (IHK K) // (center_cprod dG). Qed. Lemma cprod_center_id G : G \* 'Z(G) = G. Proof. by rewrite cprodE ?subsetIr // mulGSid ?center_sub. Qed. Lemma center_dprod A B G : A \x B = G -> 'Z(A) \x 'Z(B) = 'Z(G). Proof. case/dprodP=> [[H1 H2 -> ->] defG cH12 trH12]. move: defG; rewrite -cprodE // => /center_cprod/cprodP[_ /= <- cZ12]. by apply: dprodE; rewrite //= setIAC setIA -setIA trH12 (setIidPl _) ?sub1G. Qed. Lemma center_bigdprod I r P (F: I -> {set gT}) G : \big[dprod/1]_(i <- r | P i) F i = G -> \big[dprod/1]_(i <- r | P i) 'Z(F i) = 'Z(G). Proof. elim/big_ind2: _ G => [_ <-|A B C D IHA IHB G dG|_ _ G ->]; rewrite ?center1 //. case/dprodP: dG IHA IHB (dG) => [[H K -> ->] _ _ _] IHH IHK dG. by rewrite (IHH H) // (IHK K) // (center_dprod dG). Qed. Lemma Aut_cprod_full G H K : H \* K = G -> 'Z(H) = 'Z(K) -> Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H) -> Aut_in (Aut K) 'Z(K) \isog Aut 'Z(K) -> Aut_in (Aut G) 'Z(G) \isog Aut 'Z(G). Proof. move=> defG eqZHK; have [_ defHK cHK] := cprodP defG. have defZ: 'Z(G) = 'Z(H) by rewrite -defHK -center_prod // eqZHK mulGid. have ziHK: H :&: K = 'Z(K). by apply/eqP; rewrite eqEsubset subsetI -{1 2}eqZHK !center_sub setIS. have AutZP := Aut_sub_fullP (@center_sub gT _). move/AutZP=> AutZHfull /AutZP AutZKfull; apply/AutZP=> g injg gZ. have [gH [def_gH ker_gH _ im_gH]] := domP g defZ. have [gK [def_gK ker_gK _ im_gK]] := domP g (etrans defZ eqZHK). have [injgH injgK]: 'injm gH /\ 'injm gK by rewrite ker_gH ker_gK. have [gHH gKK]: gH @* 'Z(H) = 'Z(H) /\ gK @* 'Z(K) = 'Z(K). by rewrite im_gH im_gK -eqZHK -defZ. have [|fH [injfH im_fH fHZ]] := AutZHfull gH injgH. by rewrite im_gH /= -defZ. have [|fK [injfK im_fK fKZ]] := AutZKfull gK injgK. by rewrite im_gK /= -eqZHK -defZ. have cfHK: fK @* K \subset 'C(fH @* H) by rewrite im_fH im_fK. have eq_fHK: {in H :&: K, fH =1 fK}. by move=> z; rewrite ziHK => Zz; rewrite fHZ ?fKZ /= ?eqZHK // def_gH def_gK. exists (cprodm_morphism defG cfHK eq_fHK). rewrite injm_cprodm injfH injfK im_cprodm im_fH im_fK defHK. rewrite -morphimIdom ziHK -eqZHK injm_center // im_fH eqxx. split=> //= z; rewrite {1}defZ => Zz; have [Hz _] := setIP Zz. by rewrite cprodmEl // fHZ // def_gH. Qed. End Product. Section CprodBy. Variables gTH gTK : finGroupType. Variables (H : {group gTH}) (K : {group gTK}) (gz : {morphism 'Z(H) >-> gTK}). Definition ker_cprod_by of isom 'Z(H) 'Z(K) gz := [set xy | let: (x, y) := xy in (x \in 'Z(H)) && (y == (gz x)^-1)]. Hypothesis isoZ : isom 'Z(H) 'Z(K) gz. Let kerHK := ker_cprod_by isoZ. Let injgz : 'injm gz. Proof. by case/isomP: isoZ. Qed. Let gzZ : gz @* 'Z(H) = 'Z(K). Proof. by case/isomP: isoZ. Qed. Let gzZchar : gz @* 'Z(H) \char 'Z(K). Proof. by rewrite gzZ. Qed. Let sgzZZ : gz @* 'Z(H) \subset 'Z(K) := char_sub gzZchar. Let sZH := center_sub H. Let sZK := center_sub K. Let sgzZG : gz @* 'Z(H) \subset K := subset_trans sgzZZ sZK. Lemma ker_cprod_by_is_group : group_set kerHK. Proof. apply/group_setP; rewrite inE /= group1 morph1 invg1 /=. split=> // [[x1 y1] [x2 y2]]. rewrite inE /= => /andP[Zx1 /eqP->]; have [_ cGx1] := setIP Zx1. rewrite inE /= => /andP[Zx2 /eqP->]; have [Gx2 _] := setIP Zx2. by rewrite inE /= groupM //= -invMg (centP cGx1) // morphM. Qed. Canonical ker_cprod_by_group := Group ker_cprod_by_is_group. Lemma ker_cprod_by_central : kerHK \subset 'Z(setX H K). Proof. rewrite -(center_dprod (setX_dprod H K)) -morphim_pairg1 -morphim_pair1g. rewrite -!injm_center ?subsetT ?injm_pair1g ?injm_pairg1 //=. rewrite morphim_pairg1 morphim_pair1g setX_dprod. apply/subsetP=> [[x y]] /[1!inE] /andP[Zx /eqP->]. by rewrite inE /= Zx groupV (subsetP sgzZZ) ?mem_morphim. Qed. Fact cprod_by_key : unit. Proof. by []. Qed. Definition cprod_by_def : finGroupType := subg_of (setX H K / kerHK). Definition cprod_by := locked_with cprod_by_key cprod_by_def. Local Notation C := [set: FinGroup.sort cprod_by]. (*FIXME : Check if we need arg_sort instead of sort*) Definition in_cprod : gTH * gTK -> cprod_by := let: tt as k := cprod_by_key return _ -> locked_with k cprod_by_def in subg _ \o coset kerHK. Lemma in_cprodM : {in setX H K &, {morph in_cprod : u v / u * v}}. Proof. rewrite /in_cprod /cprod_by; case: cprod_by_key => /= u v Gu Gv. have nkerHKG := normal_norm (sub_center_normal ker_cprod_by_central). by rewrite -!morphM ?mem_quotient // (subsetP nkerHKG). Qed. Canonical in_cprod_morphism := Morphism in_cprodM. Lemma ker_in_cprod : 'ker in_cprod = kerHK. Proof. transitivity ('ker (subg [group of setX H K / kerHK] \o coset kerHK)). rewrite /ker /morphpre /= /in_cprod /cprod_by; case: cprod_by_key => /=. by rewrite ['N(_) :&: _]quotientGK ?sub_center_normal ?ker_cprod_by_central. by rewrite ker_comp ker_subg -kerE ker_coset. Qed. Lemma cpairg1_dom : H \subset 'dom (in_cprod \o @pairg1 gTH gTK). Proof. by rewrite -sub_morphim_pre ?subsetT // morphim_pairg1 setXS ?sub1G. Qed. Lemma cpair1g_dom : K \subset 'dom (in_cprod \o @pair1g gTH gTK). Proof. by rewrite -sub_morphim_pre ?subsetT // morphim_pair1g setXS ?sub1G. Qed. Definition cpairg1 := tag (restrmP _ cpairg1_dom). Definition cpair1g := tag (restrmP _ cpair1g_dom). Local Notation CH := (mfun cpairg1 @* gval H). Local Notation CK := (mfun cpair1g @* gval K). Lemma injm_cpairg1 : 'injm cpairg1. Proof. rewrite /cpairg1; case: restrmP => _ [_ -> _ _]. rewrite ker_comp ker_in_cprod; apply/subsetP=> x; rewrite !inE /=. by case/and3P=> _ Zx; rewrite eq_sym (inv_eq invgK) invg1 morph_injm_eq1. Qed. Let injH := injm_cpairg1. Lemma injm_cpair1g : 'injm cpair1g. Proof. rewrite /cpair1g; case: restrmP => _ [_ -> _ _]. rewrite ker_comp ker_in_cprod; apply/subsetP=> y; rewrite !inE /= morph1 invg1. by case/and3P. Qed. Let injK := injm_cpair1g. Lemma im_cpair_cent : CK \subset 'C(CH). Proof. rewrite /cpairg1 /cpair1g; do 2!case: restrmP => _ [_ _ _ -> //]. rewrite !morphim_comp morphim_cents // morphim_pair1g morphim_pairg1. by case/dprodP: (setX_dprod H K). Qed. Hint Resolve im_cpair_cent : core. Lemma im_cpair : CH * CK = C. Proof. rewrite /cpairg1 /cpair1g; do 2!case: restrmP => _ [_ _ _ -> //]. rewrite !morphim_comp -morphimMl morphim_pairg1 ?setXS ?sub1G //. rewrite morphim_pair1g setX_prod morphimEdom /= /in_cprod /cprod_by. by case: cprod_by_key; rewrite /= imset_comp imset_coset -morphimEdom im_subg. Qed. Lemma im_cpair_cprod : CH \* CK = C. Proof. by rewrite cprodE ?im_cpair. Qed. Lemma eq_cpairZ : {in 'Z(H), cpairg1 =1 cpair1g \o gz}. Proof. rewrite /cpairg1 /cpair1g => z1 Zz1; set z2 := gz z1. have Zz2: z2 \in 'Z(K) by rewrite (subsetP sgzZZ) ?mem_morphim. have [[Gz1 _] [/= Gz2 _]]:= (setIP Zz1, setIP Zz2). do 2![case: restrmP => f /= [df _ _ _]; rewrite {f}df]. apply/rcoset_kerP; rewrite ?inE ?group1 ?andbT //. by rewrite ker_in_cprod mem_rcoset inE /= invg1 mulg1 mul1g Zz1 /=. Qed. Lemma setI_im_cpair : CH :&: CK = 'Z(CH). Proof. apply/eqP; rewrite eqEsubset setIS //=. rewrite subsetI center_sub -injm_center //. rewrite (eq_in_morphim _ eq_cpairZ); first by rewrite morphim_comp morphimS. by rewrite !(setIidPr _) // -sub_morphim_pre. Qed. Lemma cpair1g_center : cpair1g @* 'Z(K) = 'Z(C). Proof. case/cprodP: (center_cprod im_cpair_cprod) => _ <- _. by rewrite injm_center // -setI_im_cpair mulSGid //= setIC setIS 1?centsC. Qed. (* Uses gzZ. *) Lemma cpair_center_id : 'Z(CH) = 'Z(CK). Proof. rewrite -!injm_center // -gzZ -morphim_comp; apply: eq_in_morphim eq_cpairZ. by rewrite !(setIidPr _) // -sub_morphim_pre. Qed. (* Uses gzZ. *) Lemma cpairg1_center : cpairg1 @* 'Z(H) = 'Z(C). Proof. by rewrite -cpair1g_center !injm_center // cpair_center_id. Qed. Section ExtCprodm. Variable rT : finGroupType. Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}). Hypothesis cfHK : fK @* K \subset 'C(fH @* H). Hypothesis eq_fHK : {in 'Z(H), fH =1 fK \o gz}. Let gH := ifactm fH injm_cpairg1. Let gK := ifactm fK injm_cpair1g. Lemma xcprodm_cent : gK @* CK \subset 'C(gH @* CH). Proof. by rewrite !im_ifactm. Qed. Lemma xcprodmI : {in CH :&: CK, gH =1 gK}. Proof. rewrite setI_im_cpair -injm_center // => fHx; case/morphimP=> x Gx Zx ->{fHx}. by rewrite {2}eq_cpairZ //= ?ifactmE ?eq_fHK //= (subsetP sgzZG) ?mem_morphim. Qed. Definition xcprodm := cprodm im_cpair_cprod xcprodm_cent xcprodmI. Canonical xcprod_morphism := [morphism of xcprodm]. Lemma xcprodmEl : {in H, forall x, xcprodm (cpairg1 x) = fH x}. Proof. by move=> x Hx; rewrite /xcprodm cprodmEl ?mem_morphim ?ifactmE. Qed. Lemma xcprodmEr : {in K, forall y, xcprodm (cpair1g y) = fK y}. Proof. by move=> y Ky; rewrite /xcprodm cprodmEr ?mem_morphim ?ifactmE. Qed. Lemma xcprodmE : {in H & K, forall x y, xcprodm (cpairg1 x * cpair1g y) = fH x * fK y}. Proof. by move=> x y Hx Ky; rewrite /xcprodm cprodmE ?mem_morphim ?ifactmE. Qed. Lemma im_xcprodm : xcprodm @* C = fH @* H * fK @* K. Proof. by rewrite -im_cpair morphim_cprodm // !im_ifactm. Qed. Lemma im_xcprodml A : xcprodm @* (cpairg1 @* A) = fH @* A. Proof. rewrite -!(morphimIdom _ A) morphim_cprodml ?morphimS ?subsetIl //. by rewrite morphim_ifactm ?subsetIl. Qed. Lemma im_xcprodmr A : xcprodm @* (cpair1g @* A) = fK @* A. Proof. rewrite -!(morphimIdom _ A) morphim_cprodmr ?morphimS ?subsetIl //. by rewrite morphim_ifactm ?subsetIl. Qed. Lemma injm_xcprodm : 'injm xcprodm = 'injm fH && 'injm fK. Proof. rewrite injm_cprodm !ker_ifactm !subG1 !morphim_injm_eq1 ?subsetIl // -!subG1. apply: andb_id2l => /= injfH; apply: andb_idr => _. rewrite !im_ifactm // -(morphimIdom gH) setI_im_cpair -injm_center //. rewrite morphim_ifactm // eqEsubset subsetI morphimS //=. rewrite {1}injm_center // setIS //=. rewrite (eq_in_morphim _ eq_fHK); first by rewrite morphim_comp morphimS. by rewrite !(setIidPr _) // -sub_morphim_pre. Qed. End ExtCprodm. (* Uses gzZchar. *) Lemma Aut_cprod_by_full : Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H) -> Aut_in (Aut K) 'Z(K) \isog Aut 'Z(K) -> Aut_in (Aut C) 'Z(C) \isog Aut 'Z(C). Proof. move=> AutZinH AutZinK. have Cfull:= Aut_cprod_full im_cpair_cprod cpair_center_id. by rewrite Cfull // -injm_center // injm_Aut_full ?center_sub. Qed. Section Isomorphism. Let gzZ_lone (Y : {group gTK}) : Y \subset 'Z(K) -> gz @* 'Z(H) \isog Y -> gz @* 'Z(H) = Y. Proof. move=> sYZ isoY; apply/eqP. by rewrite eq_sym eqEcard (card_isog isoY) gzZ sYZ /=. Qed. Variables (rT : finGroupType) (GH GK G : {group rT}). Hypotheses (defG : GH \* GK = G) (ziGHK : GH :&: GK = 'Z(GH)). Hypothesis AutZHfull : Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H). Hypotheses (isoGH : GH \isog H) (isoGK : GK \isog K). (* Uses gzZ_lone *) Lemma cprod_by_uniq : exists f : {morphism G >-> cprod_by}, [/\ isom G C f, f @* GH = CH & f @* GK = CK]. Proof. have [_ defGHK cGKH] := cprodP defG. have AutZinH := Aut_sub_fullP sZH AutZHfull. have [fH injfH defGH]:= isogP (isog_symr isoGH). have [fK injfK defGK]:= isogP (isog_symr isoGK). have sfHZfK: fH @* 'Z(H) \subset fK @* K. by rewrite injm_center //= defGH defGK -ziGHK subsetIr. have gzZ_id: gz @* 'Z(H) = invm injfK @* (fH @* 'Z(H)). apply: gzZ_lone => /=. rewrite injm_center // defGH -ziGHK sub_morphim_pre /= ?defGK ?subsetIr //. by rewrite setIC morphpre_invm injm_center // defGK setIS 1?centsC. rewrite -morphim_comp. apply: isog_trans (sub_isog _ _); first by rewrite isog_sym sub_isog. by rewrite -sub_morphim_pre. by rewrite !injm_comp ?injm_invm. have: 'dom (invm injfH \o fK \o gz) = 'Z(H). rewrite /dom /= -(morphpreIdom gz); apply/setIidPl. by rewrite -2?sub_morphim_pre // gzZ_id morphim_invmE morphpreK ?morphimS. case/domP=> gzH [def_gzH ker_gzH _ im_gzH]. have{ker_gzH} injgzH: 'injm gzH by rewrite ker_gzH !injm_comp ?injm_invm. have{AutZinH} [|gH [injgH gH_H def_gH]] := AutZinH _ injgzH. by rewrite im_gzH !morphim_comp /= gzZ_id !morphim_invmE morphpreK ?injmK. have: 'dom (fH \o gH) = H by rewrite /dom /= -{3}gH_H injmK. case/domP=> gfH [def_gfH ker_gfH _ im_gfH]. have{im_gfH} gfH_H: gfH @* H = GH by rewrite im_gfH morphim_comp gH_H. have cgfHfK: fK @* K \subset 'C(gfH @* H) by rewrite gfH_H defGK. have eq_gfHK: {in 'Z(H), gfH =1 fK \o gz}. move=> z Zz; rewrite def_gfH /= def_gH //= def_gzH /= invmK //. have {Zz}: gz z \in gz @* 'Z(H) by rewrite mem_morphim. rewrite gzZ_id morphim_invmE; case/morphpreP=> _. exact: (subsetP (morphimS _ _)). pose f := xcprodm cgfHfK eq_gfHK. have injf: 'injm f by rewrite injm_xcprodm ker_gfH injm_comp. have fCH: f @* CH = GH by rewrite im_xcprodml gfH_H. have fCK: f @* CK = GK by rewrite im_xcprodmr defGK. have fC: f @* C = G by rewrite im_xcprodm gfH_H defGK defGHK. have [f' [_ ker_f' _ im_f']] := domP (invm_morphism injf) fC. exists f'; rewrite -fCH -fCK !{1}im_f' !{1}morphim_invm ?subsetT //. by split=> //; apply/isomP; rewrite ker_f' injm_invm im_f' -fC im_invm. Qed. Lemma isog_cprod_by : G \isog C. Proof. by have [f [isoG _ _]] := cprod_by_uniq; apply: isom_isog isoG. Qed. End Isomorphism. End CprodBy. Section ExtCprod. Import finfun. Variables gTH gTK : finGroupType. Variables (H : {group gTH}) (K : {group gTK}). Let gt_ b := if b then gTK else gTH. Local Notation isob := ('Z(H) \isog 'Z(K)) (only parsing). Let G_ b := if b as b' return {group gt_ b'} then K else H. Lemma xcprod_subproof : {gz : {morphism 'Z(H) >-> gt_ isob} | isom 'Z(H) 'Z(G_ isob) gz}. Proof. case: (pickP [pred f : {ffun _} | misom 'Z(H) 'Z(K) f]) => [f isoZ | no_f]. rewrite (misom_isog isoZ); case/andP: isoZ => fM isoZ. by exists [morphism of morphm fM]. move/pred0P: no_f => not_isoZ; rewrite [isob](congr1 negb not_isoZ). by exists (idm_morphism _); apply/isomP; rewrite injm_idm im_idm. Qed. Definition xcprod := cprod_by (svalP xcprod_subproof). Inductive xcprod_spec : finGroupType -> Prop := XcprodSpec gz isoZ : xcprod_spec (@cprod_by gTH gTK H K gz isoZ). Lemma xcprodP : 'Z(H) \isog 'Z(K) -> xcprod_spec xcprod. Proof. by rewrite /xcprod => isoZ; move: xcprod_subproof; rewrite isoZ. Qed. Lemma isog_xcprod (rT : finGroupType) (GH GK G : {group rT}) : Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H) -> GH \isog H -> GK \isog K -> GH \* GK = G -> 'Z(GH) = 'Z(GK) -> G \isog [set: xcprod]. Proof. move=> AutZinH isoGH isoGK defG eqZGHK; have [_ _ cGHK] := cprodP defG. have [|gz isoZ] := xcprodP. have [[fH injfH <-] [fK injfK <-]] := (isogP isoGH, isogP isoGK). rewrite -!injm_center -?(isog_transl _ (sub_isog _ _)) ?center_sub //=. by rewrite eqZGHK sub_isog ?center_sub. rewrite (isog_cprod_by _ defG) //. by apply/eqP; rewrite eqEsubset setIS // subsetI {2}eqZGHK !center_sub. Qed. End ExtCprod. Section IterCprod. Variables (gT : finGroupType) (G : {group gT}). Fixpoint ncprod_def n : finGroupType := if n is n'.+1 then xcprod G [set: ncprod_def n'] else subg_of 'Z(G). Fact ncprod_key : unit. Proof. by []. Qed. Definition ncprod := locked_with ncprod_key ncprod_def. Local Notation G_ n := [set: gsort (ncprod n)]. Lemma ncprod0 : G_ 0 \isog 'Z(G). Proof. by rewrite [ncprod]unlock isog_sym isog_subg. Qed. Lemma center_ncprod0 : 'Z(G_ 0) = G_ 0. Proof. by apply: center_idP; rewrite (isog_abelian ncprod0) center_abelian. Qed. Lemma center_ncprod n : 'Z(G_ n) \isog 'Z(G). Proof. elim: n => [|n]; first by rewrite center_ncprod0 ncprod0. rewrite [ncprod]unlock=> /isog_symr/xcprodP[gz isoZ] /=. by rewrite -cpairg1_center isog_sym sub_isog ?center_sub ?injm_cpairg1. Qed. Lemma ncprodS n : xcprod_spec G [set: ncprod n] (ncprod n.+1). Proof. by have:= xcprodP (isog_symr (center_ncprod n)); rewrite [ncprod]unlock. Qed. Lemma ncprod1 : G_ 1 \isog G. Proof. case: ncprodS => gz isoZ; rewrite isog_sym /= -im_cpair. rewrite mulGSid /=; first by rewrite sub_isog ?injm_cpairg1. rewrite -{3}center_ncprod0 injm_center ?injm_cpair1g //. by rewrite -cpair_center_id center_sub. Qed. Lemma Aut_ncprod_full n : Aut_in (Aut G) 'Z(G) \isog Aut 'Z(G) -> Aut_in (Aut (G_ n)) 'Z(G_ n) \isog Aut 'Z(G_ n). Proof. move=> AutZinG; elim: n => [|n IHn]. by rewrite center_ncprod0; apply/Aut_sub_fullP=> // g injg gG0; exists g. by case: ncprodS => gz isoZ; apply: Aut_cprod_by_full. Qed. End IterCprod.
Defs.lean
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Order.Module.OrderedSMul import Mathlib.Data.Real.Archimedean /-! # Nonnegative real numbers In this file we define `NNReal` (notation: `ℝ≥0`) to be the type of non-negative real numbers, a.k.a. the interval `[0, ∞)`. We also define the following operations and structures on `ℝ≥0`: * the order on `ℝ≥0` is the restriction of the order on `ℝ`; these relations define a conditionally complete linear order with a bottom element, `ConditionallyCompleteLinearOrderBot`; * `a + b` and `a * b` are the restrictions of addition and multiplication of real numbers to `ℝ≥0`; these operations together with `0 = ⟨0, _⟩` and `1 = ⟨1, _⟩` turn `ℝ≥0` into a conditionally complete linear ordered archimedean commutative semifield; we have no typeclass for this in `mathlib` yet, so we define the following instances instead: - `LinearOrderedSemiring ℝ≥0`; - `OrderedCommSemiring ℝ≥0`; - `CanonicallyOrderedAdd ℝ≥0`; - `LinearOrderedCommGroupWithZero ℝ≥0`; - `CanonicallyLinearOrderedAddCommMonoid ℝ≥0`; - `Archimedean ℝ≥0`; - `ConditionallyCompleteLinearOrderBot ℝ≥0`. These instances are derived from corresponding instances about the type `{x : α // 0 ≤ x}` in an appropriate ordered field/ring/group/monoid `α`, see `Mathlib/Algebra/Order/Nonneg/Ring.lean`. * `Real.toNNReal x` is defined as `⟨max x 0, _⟩`, i.e. `↑(Real.toNNReal x) = x` when `0 ≤ x` and `↑(Real.toNNReal x) = 0` otherwise. We also define an instance `CanLift ℝ ℝ≥0`. This instance can be used by the `lift` tactic to replace `x : ℝ` and `hx : 0 ≤ x` in the proof context with `x : ℝ≥0` while replacing all occurrences of `x` with `↑x`. This tactic also works for a function `f : α → ℝ` with a hypothesis `hf : ∀ x, 0 ≤ f x`. ## Notations This file defines `ℝ≥0` as a localized notation for `NNReal`. -/ assert_not_exists TrivialStar open Function -- to ensure these instances are computable /-- Nonnegative real numbers, denoted as `ℝ≥0` within the NNReal namespace -/ def NNReal := { r : ℝ // 0 ≤ r } deriving Zero, One, Semiring, CommMonoidWithZero, CommSemiring, PartialOrder, SemilatticeInf, SemilatticeSup, DistribLattice, Nontrivial, Inhabited namespace NNReal @[inherit_doc] scoped notation "ℝ≥0" => NNReal instance : CanonicallyOrderedAdd ℝ≥0 := Nonneg.canonicallyOrderedAdd instance : NoZeroDivisors ℝ≥0 := Nonneg.noZeroDivisors instance instDenselyOrdered : DenselyOrdered ℝ≥0 := Nonneg.instDenselyOrdered instance : OrderBot ℝ≥0 := Nonneg.orderBot instance instArchimedean : Archimedean ℝ≥0 := Nonneg.instArchimedean instance instMulArchimedean : MulArchimedean ℝ≥0 := Nonneg.instMulArchimedean instance : Min ℝ≥0 := SemilatticeInf.toMin instance : Max ℝ≥0 := SemilatticeSup.toMax instance : Sub ℝ≥0 := Nonneg.sub instance : OrderedSub ℝ≥0 := Nonneg.orderedSub -- a computable copy of `Nonneg.instNNRatCast` instance : NNRatCast ℝ≥0 where nnratCast r := ⟨r, r.cast_nonneg⟩ noncomputable instance : LinearOrder ℝ≥0 := Subtype.instLinearOrder _ noncomputable instance : Semifield ℝ≥0 := Nonneg.semifield instance : IsOrderedRing ℝ≥0 := Nonneg.isOrderedRing instance : IsStrictOrderedRing ℝ≥0 := Nonneg.isStrictOrderedRing noncomputable instance : LinearOrderedCommGroupWithZero ℝ≥0 where /- Both `LinearOrderedCommGroupWithZero` and `Semifield` inherit from `CommGroupWithZero`. However, if we project both of them into a `GroupWithZero` and try to unify them at `reducible_and_instances` transparency, then we unfold `instSemifield` into `Nonneg.semifield` which also causes an unfolding of `NNReal` to `{x // 0 ≤ x}`. Those two are (intentionally!) not defeq at `reducible_and_instances`, even though the instances on them are. So we either need to copy all the `Nonneg` instances and redefine them specifically for `NNReal`, or we need to avoid the unfold in the unification. The latter has a smaller impact. -/ __ := instSemifield.toCommGroupWithZero.toGroupWithZero __ := Nonneg.linearOrderedCommGroupWithZero example {p q : ℝ≥0} (h1p : 0 < p) (h2p : p ≤ q) : q⁻¹ ≤ p⁻¹ := by with_reducible_and_instances exact inv_anti₀ h1p h2p /-- Coercion `ℝ≥0 → ℝ`. -/ @[coe] def toReal : ℝ≥0 → ℝ := Subtype.val instance : Coe ℝ≥0 ℝ := ⟨toReal⟩ -- Simp lemma to put back `n.val` into the normal form given by the coercion. @[simp] theorem val_eq_coe (n : ℝ≥0) : n.val = n := rfl instance canLift : CanLift ℝ ℝ≥0 toReal fun r => 0 ≤ r := Subtype.canLift _ @[ext] protected theorem eq {n m : ℝ≥0} : (n : ℝ) = (m : ℝ) → n = m := Subtype.eq theorem ne_iff {x y : ℝ≥0} : (x : ℝ) ≠ (y : ℝ) ↔ x ≠ y := not_congr <| NNReal.eq_iff.symm protected theorem «forall» {p : ℝ≥0 → Prop} : (∀ x : ℝ≥0, p x) ↔ ∀ (x : ℝ) (hx : 0 ≤ x), p ⟨x, hx⟩ := Subtype.forall protected theorem «exists» {p : ℝ≥0 → Prop} : (∃ x : ℝ≥0, p x) ↔ ∃ (x : ℝ) (hx : 0 ≤ x), p ⟨x, hx⟩ := Subtype.exists /-- Reinterpret a real number `r` as a non-negative real number. Returns `0` if `r < 0`. -/ def _root_.Real.toNNReal (r : ℝ) : ℝ≥0 := ⟨max r 0, le_max_right _ _⟩ theorem _root_.Real.coe_toNNReal (r : ℝ) (hr : 0 ≤ r) : (Real.toNNReal r : ℝ) = r := max_eq_left hr theorem _root_.Real.toNNReal_of_nonneg {r : ℝ} (hr : 0 ≤ r) : r.toNNReal = ⟨r, hr⟩ := by simp_rw [Real.toNNReal, max_eq_left hr] theorem _root_.Real.le_coe_toNNReal (r : ℝ) : r ≤ Real.toNNReal r := le_max_left r 0 @[bound] theorem coe_nonneg (r : ℝ≥0) : (0 : ℝ) ≤ r := r.2 @[simp, norm_cast] theorem coe_mk (a : ℝ) (ha) : toReal ⟨a, ha⟩ = a := rfl example : Zero ℝ≥0 := by infer_instance example : One ℝ≥0 := by infer_instance example : Add ℝ≥0 := by infer_instance example : Sub ℝ≥0 := by infer_instance example : Mul ℝ≥0 := by infer_instance noncomputable example : Inv ℝ≥0 := by infer_instance noncomputable example : Div ℝ≥0 := by infer_instance example : LE ℝ≥0 := by infer_instance example : Bot ℝ≥0 := by infer_instance example : Inhabited ℝ≥0 := by infer_instance example : Nontrivial ℝ≥0 := by infer_instance protected theorem coe_injective : Injective ((↑) : ℝ≥0 → ℝ) := Subtype.coe_injective @[simp, norm_cast] lemma coe_inj {r₁ r₂ : ℝ≥0} : (r₁ : ℝ) = r₂ ↔ r₁ = r₂ := NNReal.coe_injective.eq_iff @[simp, norm_cast] lemma coe_zero : ((0 : ℝ≥0) : ℝ) = 0 := rfl @[simp, norm_cast] lemma coe_one : ((1 : ℝ≥0) : ℝ) = 1 := rfl @[simp] lemma mk_zero : (⟨0, le_rfl⟩ : ℝ≥0) = 0 := rfl @[simp] lemma mk_one : (⟨1, zero_le_one⟩ : ℝ≥0) = 1 := rfl @[simp, norm_cast] protected theorem coe_add (r₁ r₂ : ℝ≥0) : ((r₁ + r₂ : ℝ≥0) : ℝ) = r₁ + r₂ := rfl @[simp, norm_cast] protected theorem coe_mul (r₁ r₂ : ℝ≥0) : ((r₁ * r₂ : ℝ≥0) : ℝ) = r₁ * r₂ := rfl @[simp, norm_cast] protected theorem coe_inv (r : ℝ≥0) : ((r⁻¹ : ℝ≥0) : ℝ) = (r : ℝ)⁻¹ := rfl @[simp, norm_cast] protected theorem coe_div (r₁ r₂ : ℝ≥0) : ((r₁ / r₂ : ℝ≥0) : ℝ) = (r₁ : ℝ) / r₂ := rfl protected theorem coe_two : ((2 : ℝ≥0) : ℝ) = 2 := rfl @[simp, norm_cast] protected theorem coe_sub {r₁ r₂ : ℝ≥0} (h : r₂ ≤ r₁) : ((r₁ - r₂ : ℝ≥0) : ℝ) = ↑r₁ - ↑r₂ := max_eq_left <| le_sub_comm.2 <| by simp [show (r₂ : ℝ) ≤ r₁ from h] variable {r r₁ r₂ : ℝ≥0} {x y : ℝ} @[simp, norm_cast] lemma coe_eq_zero : (r : ℝ) = 0 ↔ r = 0 := by rw [← coe_zero, coe_inj] @[simp, norm_cast] lemma coe_eq_one : (r : ℝ) = 1 ↔ r = 1 := by rw [← coe_one, coe_inj] @[norm_cast] lemma coe_ne_zero : (r : ℝ) ≠ 0 ↔ r ≠ 0 := coe_eq_zero.not @[norm_cast] lemma coe_ne_one : (r : ℝ) ≠ 1 ↔ r ≠ 1 := coe_eq_one.not example : CommSemiring ℝ≥0 := by infer_instance /-- Coercion `ℝ≥0 → ℝ` as a `RingHom`. TODO: what if we define `Coe ℝ≥0 ℝ` using this function? -/ def toRealHom : ℝ≥0 →+* ℝ where toFun := (↑) map_one' := NNReal.coe_one map_mul' := NNReal.coe_mul map_zero' := NNReal.coe_zero map_add' := NNReal.coe_add @[simp] theorem coe_toRealHom : ⇑toRealHom = toReal := rfl section Actions /-- A `MulAction` over `ℝ` restricts to a `MulAction` over `ℝ≥0`. -/ instance {M : Type*} [MulAction ℝ M] : MulAction ℝ≥0 M := MulAction.compHom M toRealHom.toMonoidHom theorem smul_def {M : Type*} [MulAction ℝ M] (c : ℝ≥0) (x : M) : c • x = (c : ℝ) • x := rfl instance {M N : Type*} [MulAction ℝ M] [MulAction ℝ N] [SMul M N] [IsScalarTower ℝ M N] : IsScalarTower ℝ≥0 M N where smul_assoc r := smul_assoc (r : ℝ) instance smulCommClass_left {M N : Type*} [MulAction ℝ N] [SMul M N] [SMulCommClass ℝ M N] : SMulCommClass ℝ≥0 M N where smul_comm r := smul_comm (r : ℝ) instance smulCommClass_right {M N : Type*} [MulAction ℝ N] [SMul M N] [SMulCommClass M ℝ N] : SMulCommClass M ℝ≥0 N where smul_comm m r := smul_comm m (r : ℝ) /-- A `DistribMulAction` over `ℝ` restricts to a `DistribMulAction` over `ℝ≥0`. -/ instance {M : Type*} [AddMonoid M] [DistribMulAction ℝ M] : DistribMulAction ℝ≥0 M := DistribMulAction.compHom M toRealHom.toMonoidHom /-- A `Module` over `ℝ` restricts to a `Module` over `ℝ≥0`. -/ instance {M : Type*} [AddCommMonoid M] [Module ℝ M] : Module ℝ≥0 M := Module.compHom M toRealHom /-- An `Algebra` over `ℝ` restricts to an `Algebra` over `ℝ≥0`. -/ instance {A : Type*} [Semiring A] [Algebra ℝ A] : Algebra ℝ≥0 A where smul := (· • ·) commutes' r x := by simp [Algebra.commutes] smul_def' r x := by simp [← Algebra.smul_def (r : ℝ) x, smul_def] algebraMap := (algebraMap ℝ A).comp (toRealHom : ℝ≥0 →+* ℝ) -- verify that the above produces instances we might care about example : Algebra ℝ≥0 ℝ := by infer_instance example : DistribMulAction ℝ≥0ˣ ℝ := by infer_instance end Actions example : MonoidWithZero ℝ≥0 := by infer_instance example : CommMonoidWithZero ℝ≥0 := by infer_instance noncomputable example : CommGroupWithZero ℝ≥0 := by infer_instance @[simp, norm_cast] theorem coe_pow (r : ℝ≥0) (n : ℕ) : ((r ^ n : ℝ≥0) : ℝ) = (r : ℝ) ^ n := rfl @[simp, norm_cast] theorem coe_zpow (r : ℝ≥0) (n : ℤ) : ((r ^ n : ℝ≥0) : ℝ) = (r : ℝ) ^ n := rfl variable {ι : Type*} {f : ι → ℝ} @[simp, norm_cast] lemma coe_nsmul (r : ℝ≥0) (n : ℕ) : ↑(n • r) = n • (r : ℝ) := rfl @[simp, norm_cast] lemma coe_nnqsmul (q : ℚ≥0) (x : ℝ≥0) : ↑(q • x) = (q • x : ℝ) := rfl @[simp, norm_cast] protected theorem coe_natCast (n : ℕ) : (↑(↑n : ℝ≥0) : ℝ) = n := map_natCast toRealHom n @[simp, norm_cast] protected theorem coe_ofNat (n : ℕ) [n.AtLeastTwo] : ((ofNat(n) : ℝ≥0) : ℝ) = ofNat(n) := rfl @[simp, norm_cast] protected theorem coe_ofScientific (m : ℕ) (s : Bool) (e : ℕ) : ↑(OfScientific.ofScientific m s e : ℝ≥0) = (OfScientific.ofScientific m s e : ℝ) := rfl @[simp, norm_cast] lemma algebraMap_eq_coe : (algebraMap ℝ≥0 ℝ : ℝ≥0 → ℝ) = (↑) := rfl noncomputable example : LinearOrder ℝ≥0 := by infer_instance @[simp, norm_cast] lemma coe_le_coe : (r₁ : ℝ) ≤ r₂ ↔ r₁ ≤ r₂ := Iff.rfl @[simp, norm_cast] lemma coe_lt_coe : (r₁ : ℝ) < r₂ ↔ r₁ < r₂ := Iff.rfl @[bound] private alias ⟨_, Bound.coe_lt_coe_of_lt⟩ := coe_lt_coe @[simp, norm_cast] lemma coe_pos : (0 : ℝ) < r ↔ 0 < r := Iff.rfl @[bound] private alias ⟨_, Bound.coe_pos_of_pos⟩ := coe_pos @[simp, norm_cast] lemma one_le_coe : 1 ≤ (r : ℝ) ↔ 1 ≤ r := by rw [← coe_le_coe, coe_one] @[simp, norm_cast] lemma one_lt_coe : 1 < (r : ℝ) ↔ 1 < r := by rw [← coe_lt_coe, coe_one] @[simp, norm_cast] lemma coe_le_one : (r : ℝ) ≤ 1 ↔ r ≤ 1 := by rw [← coe_le_coe, coe_one] @[simp, norm_cast] lemma coe_lt_one : (r : ℝ) < 1 ↔ r < 1 := by rw [← coe_lt_coe, coe_one] @[mono] lemma coe_mono : Monotone ((↑) : ℝ≥0 → ℝ) := fun _ _ => NNReal.coe_le_coe.2 /-- Alias for the use of `gcongr` -/ @[gcongr] alias ⟨_, GCongr.toReal_le_toReal⟩ := coe_le_coe protected theorem _root_.Real.toNNReal_mono : Monotone Real.toNNReal := fun _ _ h => max_le_max h (le_refl 0) @[simp] theorem _root_.Real.toNNReal_coe {r : ℝ≥0} : Real.toNNReal r = r := NNReal.eq <| max_eq_left r.2 @[simp] theorem mk_natCast (n : ℕ) : @Eq ℝ≥0 (⟨(n : ℝ), n.cast_nonneg⟩ : ℝ≥0) n := NNReal.eq (NNReal.coe_natCast n).symm @[simp] theorem _root_.Real.toNNReal_coe_nat (n : ℕ) : Real.toNNReal n = n := NNReal.eq <| by simp [Real.coe_toNNReal] @[deprecated Real.toNNReal_coe_nat (since := "2025-03-12")] alias toNNReal_coe_nat := Real.toNNReal_coe_nat @[simp] theorem _root_.Real.toNNReal_ofNat (n : ℕ) [n.AtLeastTwo] : Real.toNNReal ofNat(n) = OfNat.ofNat n := Real.toNNReal_coe_nat n /-- `Real.toNNReal` and `NNReal.toReal : ℝ≥0 → ℝ` form a Galois insertion. -/ def gi : GaloisInsertion Real.toNNReal (↑) := GaloisInsertion.monotoneIntro NNReal.coe_mono Real.toNNReal_mono Real.le_coe_toNNReal fun _ => Real.toNNReal_coe -- note that anything involving the (decidability of the) linear order, -- will be noncomputable, everything else should not be. example : OrderBot ℝ≥0 := by infer_instance example : PartialOrder ℝ≥0 := by infer_instance example : AddCommMonoid ℝ≥0 := by infer_instance example : IsOrderedAddMonoid ℝ≥0 := by infer_instance example : DistribLattice ℝ≥0 := by infer_instance example : SemilatticeInf ℝ≥0 := by infer_instance example : SemilatticeSup ℝ≥0 := by infer_instance example : Semiring ℝ≥0 := by infer_instance example : CommMonoid ℝ≥0 := by infer_instance example : IsOrderedMonoid ℝ≥0 := by infer_instance noncomputable example : LinearOrderedCommMonoidWithZero ℝ≥0 := by infer_instance example : DenselyOrdered ℝ≥0 := by infer_instance example : NoMaxOrder ℝ≥0 := by infer_instance instance instPosSMulStrictMono {α} [Preorder α] [MulAction ℝ α] [PosSMulStrictMono ℝ α] : PosSMulStrictMono ℝ≥0 α where elim _r hr _a₁ _a₂ ha := (smul_lt_smul_of_pos_left ha (coe_pos.2 hr):) instance instSMulPosStrictMono {α} [Zero α] [Preorder α] [MulAction ℝ α] [SMulPosStrictMono ℝ α] : SMulPosStrictMono ℝ≥0 α where elim _a ha _r₁ _r₂ hr := (smul_lt_smul_of_pos_right (coe_lt_coe.2 hr) ha :) /-- If `a` is a nonnegative real number, then the closed interval `[0, a]` in `ℝ` is order isomorphic to the interval `Set.Iic a`. -/ -- TODO: if we use `@[simps!]` it will look through the `NNReal = Subtype _` definition, -- but if we use `@[simps]` it will not look through the `Equiv.Set.sep` definition. -- Turning `NNReal` into a structure may be the best way to go here. -- @[simps!? apply_coe_coe] def orderIsoIccZeroCoe (a : ℝ≥0) : Set.Icc (0 : ℝ) a ≃o Set.Iic a where toEquiv := Equiv.Set.sep (Set.Ici 0) fun x : ℝ => x ≤ a map_rel_iff' := Iff.rfl @[simp] theorem orderIsoIccZeroCoe_apply_coe_coe (a : ℝ≥0) (b : Set.Icc (0 : ℝ) a) : (orderIsoIccZeroCoe a b : ℝ) = b := rfl @[simp] theorem orderIsoIccZeroCoe_symm_apply_coe (a : ℝ≥0) (b : Set.Iic a) : ((orderIsoIccZeroCoe a).symm b : ℝ) = b := rfl -- note we need the `@` to make the `Membership.mem` have a sensible type theorem coe_image {s : Set ℝ≥0} : (↑) '' s = { x : ℝ | ∃ h : 0 ≤ x, @Membership.mem ℝ≥0 _ _ s ⟨x, h⟩ } := Subtype.coe_image theorem bddAbove_coe {s : Set ℝ≥0} : BddAbove (((↑) : ℝ≥0 → ℝ) '' s) ↔ BddAbove s := Iff.intro (fun ⟨b, hb⟩ => ⟨Real.toNNReal b, fun ⟨y, _⟩ hys => show y ≤ max b 0 from le_max_of_le_left <| hb <| Set.mem_image_of_mem _ hys⟩) fun ⟨b, hb⟩ => ⟨b, fun _ ⟨_, hx, eq⟩ => eq ▸ hb hx⟩ theorem bddBelow_coe (s : Set ℝ≥0) : BddBelow (((↑) : ℝ≥0 → ℝ) '' s) := ⟨0, fun _ ⟨q, _, eq⟩ => eq ▸ q.2⟩ noncomputable instance : ConditionallyCompleteLinearOrderBot ℝ≥0 := Nonneg.conditionallyCompleteLinearOrderBot 0 @[norm_cast] theorem coe_sSup (s : Set ℝ≥0) : (↑(sSup s) : ℝ) = sSup (((↑) : ℝ≥0 → ℝ) '' s) := by rcases Set.eq_empty_or_nonempty s with rfl | hs · simp by_cases H : BddAbove s · have A : sSup (Subtype.val '' s) ∈ Set.Ici 0 := by apply Real.sSup_nonneg rintro - ⟨y, -, rfl⟩ exact y.2 exact (@subset_sSup_of_within ℝ (Set.Ici (0 : ℝ)) _ _ (_) s hs H A).symm · simp only [csSup_of_not_bddAbove H, csSup_empty, bot_eq_zero', NNReal.coe_zero] apply (Real.sSup_of_not_bddAbove ?_).symm contrapose! H exact bddAbove_coe.1 H @[simp, norm_cast] theorem coe_iSup {ι : Sort*} (s : ι → ℝ≥0) : (↑(⨆ i, s i) : ℝ) = ⨆ i, ↑(s i) := by rw [iSup, iSup, coe_sSup, ← Set.range_comp]; rfl @[norm_cast] theorem coe_sInf (s : Set ℝ≥0) : (↑(sInf s) : ℝ) = sInf (((↑) : ℝ≥0 → ℝ) '' s) := by rcases Set.eq_empty_or_nonempty s with rfl | hs · simp only [Set.image_empty, Real.sInf_empty, coe_eq_zero] exact @subset_sInf_emptyset ℝ (Set.Ici (0 : ℝ)) _ _ (_) have A : sInf (Subtype.val '' s) ∈ Set.Ici 0 := by apply Real.sInf_nonneg rintro - ⟨y, -, rfl⟩ exact y.2 exact (@subset_sInf_of_within ℝ (Set.Ici (0 : ℝ)) _ _ (_) s hs (OrderBot.bddBelow s) A).symm @[simp] theorem sInf_empty : sInf (∅ : Set ℝ≥0) = 0 := by rw [← coe_eq_zero, coe_sInf, Set.image_empty, Real.sInf_empty] @[norm_cast] theorem coe_iInf {ι : Sort*} (s : ι → ℝ≥0) : (↑(⨅ i, s i) : ℝ) = ⨅ i, ↑(s i) := by rw [iInf, iInf, coe_sInf, ← Set.range_comp]; rfl -- Short-circuit instance search instance addLeftMono : AddLeftMono ℝ≥0 := inferInstance instance addLeftReflectLT : AddLeftReflectLT ℝ≥0 := inferInstance instance mulLeftMono : MulLeftMono ℝ≥0 := inferInstance theorem lt_iff_exists_rat_btwn (a b : ℝ≥0) : a < b ↔ ∃ q : ℚ, 0 ≤ q ∧ a < Real.toNNReal q ∧ Real.toNNReal q < b := Iff.intro (fun h : (↑a : ℝ) < (↑b : ℝ) => let ⟨q, haq, hqb⟩ := exists_rat_btwn h have : 0 ≤ (q : ℝ) := le_trans a.2 <| le_of_lt haq ⟨q, Rat.cast_nonneg.1 this, by simp [Real.coe_toNNReal _ this, NNReal.coe_lt_coe.symm, haq, hqb]⟩) fun ⟨_, _, haq, hqb⟩ => lt_trans haq hqb theorem bot_eq_zero : (⊥ : ℝ≥0) = 0 := rfl theorem mul_sup (a b c : ℝ≥0) : a * (b ⊔ c) = a * b ⊔ a * c := mul_max_of_nonneg _ _ <| zero_le a theorem sup_mul (a b c : ℝ≥0) : (a ⊔ b) * c = a * c ⊔ b * c := max_mul_of_nonneg _ _ <| zero_le c @[simp, norm_cast] theorem coe_max (x y : ℝ≥0) : ((max x y : ℝ≥0) : ℝ) = max (x : ℝ) (y : ℝ) := NNReal.coe_mono.map_max @[simp, norm_cast] theorem coe_min (x y : ℝ≥0) : ((min x y : ℝ≥0) : ℝ) = min (x : ℝ) (y : ℝ) := NNReal.coe_mono.map_min @[simp] theorem zero_le_coe {q : ℝ≥0} : 0 ≤ (q : ℝ) := q.2 instance instOrderedSMul {M : Type*} [AddCommMonoid M] [PartialOrder M] [Module ℝ M] [OrderedSMul ℝ M] : OrderedSMul ℝ≥0 M where smul_lt_smul_of_pos hab hc := (smul_lt_smul_of_pos_left hab (NNReal.coe_pos.2 hc) :) lt_of_smul_lt_smul_of_pos {_ _ c} hab _ := lt_of_smul_lt_smul_of_nonneg_left (by exact hab) (NNReal.coe_nonneg c) end NNReal open NNReal namespace Real section ToNNReal @[simp] theorem coe_toNNReal' (r : ℝ) : (Real.toNNReal r : ℝ) = max r 0 := rfl @[simp] theorem toNNReal_zero : Real.toNNReal 0 = 0 := NNReal.eq <| coe_toNNReal _ le_rfl @[simp] theorem toNNReal_one : Real.toNNReal 1 = 1 := NNReal.eq <| coe_toNNReal _ zero_le_one @[simp] theorem toNNReal_pos {r : ℝ} : 0 < Real.toNNReal r ↔ 0 < r := by simp [← NNReal.coe_lt_coe] @[simp] theorem toNNReal_eq_zero {r : ℝ} : Real.toNNReal r = 0 ↔ r ≤ 0 := by simpa [-toNNReal_pos] using not_iff_not.2 (@toNNReal_pos r) theorem toNNReal_of_nonpos {r : ℝ} : r ≤ 0 → Real.toNNReal r = 0 := toNNReal_eq_zero.2 lemma toNNReal_eq_iff_eq_coe {r : ℝ} {p : ℝ≥0} (hp : p ≠ 0) : r.toNNReal = p ↔ r = p := ⟨fun h ↦ h ▸ (coe_toNNReal _ <| not_lt.1 fun hlt ↦ hp <| h ▸ toNNReal_of_nonpos hlt.le).symm, fun h ↦ h.symm ▸ toNNReal_coe⟩ @[simp] lemma toNNReal_eq_one {r : ℝ} : r.toNNReal = 1 ↔ r = 1 := toNNReal_eq_iff_eq_coe one_ne_zero @[simp] lemma toNNReal_eq_natCast {r : ℝ} {n : ℕ} (hn : n ≠ 0) : r.toNNReal = n ↔ r = n := mod_cast toNNReal_eq_iff_eq_coe <| Nat.cast_ne_zero.2 hn @[simp] lemma toNNReal_eq_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] : r.toNNReal = ofNat(n) ↔ r = OfNat.ofNat n := toNNReal_eq_natCast (NeZero.ne n) @[simp] theorem toNNReal_le_toNNReal_iff {r p : ℝ} (hp : 0 ≤ p) : toNNReal r ≤ toNNReal p ↔ r ≤ p := by simp [← NNReal.coe_le_coe, hp] @[simp] lemma toNNReal_le_one {r : ℝ} : r.toNNReal ≤ 1 ↔ r ≤ 1 := by simpa using toNNReal_le_toNNReal_iff zero_le_one @[simp] lemma one_lt_toNNReal {r : ℝ} : 1 < r.toNNReal ↔ 1 < r := by simpa only [not_le] using toNNReal_le_one.not @[simp] lemma toNNReal_le_natCast {r : ℝ} {n : ℕ} : r.toNNReal ≤ n ↔ r ≤ n := by simpa using toNNReal_le_toNNReal_iff n.cast_nonneg @[simp] lemma natCast_lt_toNNReal {r : ℝ} {n : ℕ} : n < r.toNNReal ↔ n < r := by simpa only [not_le] using toNNReal_le_natCast.not @[simp] lemma toNNReal_le_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] : r.toNNReal ≤ ofNat(n) ↔ r ≤ n := toNNReal_le_natCast @[simp] lemma ofNat_lt_toNNReal {r : ℝ} {n : ℕ} [n.AtLeastTwo] : ofNat(n) < r.toNNReal ↔ n < r := natCast_lt_toNNReal @[simp] theorem toNNReal_eq_toNNReal_iff {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) : toNNReal r = toNNReal p ↔ r = p := by simp [← coe_inj, hr, hp] @[simp] theorem toNNReal_lt_toNNReal_iff' {r p : ℝ} : Real.toNNReal r < Real.toNNReal p ↔ r < p ∧ 0 < p := NNReal.coe_lt_coe.symm.trans max_lt_max_left_iff theorem toNNReal_lt_toNNReal_iff {r p : ℝ} (h : 0 < p) : Real.toNNReal r < Real.toNNReal p ↔ r < p := toNNReal_lt_toNNReal_iff'.trans (and_iff_left h) theorem lt_of_toNNReal_lt {r p : ℝ} (h : r.toNNReal < p.toNNReal) : r < p := (Real.toNNReal_lt_toNNReal_iff <| Real.toNNReal_pos.1 (ne_bot_of_gt h).bot_lt).1 h theorem toNNReal_lt_toNNReal_iff_of_nonneg {r p : ℝ} (hr : 0 ≤ r) : Real.toNNReal r < Real.toNNReal p ↔ r < p := toNNReal_lt_toNNReal_iff'.trans ⟨And.left, fun h => ⟨h, lt_of_le_of_lt hr h⟩⟩ lemma toNNReal_le_toNNReal_iff' {r p : ℝ} : r.toNNReal ≤ p.toNNReal ↔ r ≤ p ∨ r ≤ 0 := by simp_rw [← not_lt, toNNReal_lt_toNNReal_iff', not_and_or] lemma toNNReal_le_toNNReal_iff_of_pos {r p : ℝ} (hr : 0 < r) : r.toNNReal ≤ p.toNNReal ↔ r ≤ p := by simp [toNNReal_le_toNNReal_iff', hr.not_ge] @[simp] lemma one_le_toNNReal {r : ℝ} : 1 ≤ r.toNNReal ↔ 1 ≤ r := by simpa using toNNReal_le_toNNReal_iff_of_pos one_pos @[simp] lemma toNNReal_lt_one {r : ℝ} : r.toNNReal < 1 ↔ r < 1 := by simp only [← not_le, one_le_toNNReal] @[simp] lemma natCastle_toNNReal' {n : ℕ} {r : ℝ} : ↑n ≤ r.toNNReal ↔ n ≤ r ∨ n = 0 := by simpa [n.cast_nonneg.ge_iff_eq'] using toNNReal_le_toNNReal_iff' (r := n) @[simp] lemma toNNReal_lt_natCast' {n : ℕ} {r : ℝ} : r.toNNReal < n ↔ r < n ∧ n ≠ 0 := by simpa [pos_iff_ne_zero] using toNNReal_lt_toNNReal_iff' (r := r) (p := n) lemma natCast_le_toNNReal {n : ℕ} {r : ℝ} (hn : n ≠ 0) : ↑n ≤ r.toNNReal ↔ n ≤ r := by simp [hn] lemma toNNReal_lt_natCast {r : ℝ} {n : ℕ} (hn : n ≠ 0) : r.toNNReal < n ↔ r < n := by simp [hn] @[simp] lemma toNNReal_lt_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] : r.toNNReal < ofNat(n) ↔ r < OfNat.ofNat n := toNNReal_lt_natCast (NeZero.ne n) @[simp] lemma ofNat_le_toNNReal {n : ℕ} {r : ℝ} [n.AtLeastTwo] : ofNat(n) ≤ r.toNNReal ↔ OfNat.ofNat n ≤ r := natCast_le_toNNReal (NeZero.ne n) @[simp] theorem toNNReal_add {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) : Real.toNNReal (r + p) = Real.toNNReal r + Real.toNNReal p := NNReal.eq <| by simp [hr, hp, add_nonneg] theorem toNNReal_add_toNNReal {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) : Real.toNNReal r + Real.toNNReal p = Real.toNNReal (r + p) := (Real.toNNReal_add hr hp).symm theorem toNNReal_le_toNNReal {r p : ℝ} (h : r ≤ p) : Real.toNNReal r ≤ Real.toNNReal p := Real.toNNReal_mono h theorem toNNReal_add_le {r p : ℝ} : Real.toNNReal (r + p) ≤ Real.toNNReal r + Real.toNNReal p := NNReal.coe_le_coe.1 <| max_le (add_le_add (le_max_left _ _) (le_max_left _ _)) NNReal.zero_le_coe theorem toNNReal_le_iff_le_coe {r : ℝ} {p : ℝ≥0} : toNNReal r ≤ p ↔ r ≤ ↑p := NNReal.gi.gc r p theorem le_toNNReal_iff_coe_le {r : ℝ≥0} {p : ℝ} (hp : 0 ≤ p) : r ≤ Real.toNNReal p ↔ ↑r ≤ p := by rw [← NNReal.coe_le_coe, Real.coe_toNNReal p hp] theorem le_toNNReal_iff_coe_le' {r : ℝ≥0} {p : ℝ} (hr : 0 < r) : r ≤ Real.toNNReal p ↔ ↑r ≤ p := (le_or_gt 0 p).elim le_toNNReal_iff_coe_le fun hp => by simp only [(hp.trans_le r.coe_nonneg).not_ge, toNNReal_eq_zero.2 hp.le, hr.not_ge] theorem toNNReal_lt_iff_lt_coe {r : ℝ} {p : ℝ≥0} (ha : 0 ≤ r) : Real.toNNReal r < p ↔ r < ↑p := by rw [← NNReal.coe_lt_coe, Real.coe_toNNReal r ha] theorem lt_toNNReal_iff_coe_lt {r : ℝ≥0} {p : ℝ} : r < Real.toNNReal p ↔ ↑r < p := lt_iff_lt_of_le_iff_le toNNReal_le_iff_le_coe theorem toNNReal_pow {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : (x ^ n).toNNReal = x.toNNReal ^ n := by rw [← coe_inj, NNReal.coe_pow, Real.coe_toNNReal _ (pow_nonneg hx _), Real.coe_toNNReal x hx] theorem toNNReal_zpow {x : ℝ} (hx : 0 ≤ x) (n : ℤ) : (x ^ n).toNNReal = x.toNNReal ^ n := by rw [← coe_inj, NNReal.coe_zpow, Real.coe_toNNReal _ (zpow_nonneg hx _), Real.coe_toNNReal x hx] theorem toNNReal_mul {p q : ℝ} (hp : 0 ≤ p) : Real.toNNReal (p * q) = Real.toNNReal p * Real.toNNReal q := NNReal.eq <| by simp [mul_max_of_nonneg, hp] end ToNNReal end Real open Real namespace NNReal section Mul theorem mul_eq_mul_left {a b c : ℝ≥0} (h : a ≠ 0) : a * b = a * c ↔ b = c := by rw [mul_eq_mul_left_iff, or_iff_left h] end Mul section Pow theorem pow_antitone_exp {a : ℝ≥0} (m n : ℕ) (mn : m ≤ n) (a1 : a ≤ 1) : a ^ n ≤ a ^ m := pow_le_pow_of_le_one (zero_le a) a1 mn nonrec theorem exists_pow_lt_of_lt_one {a b : ℝ≥0} (ha : 0 < a) (hb : b < 1) : ∃ n : ℕ, b ^ n < a := by simpa only [← coe_pow, NNReal.coe_lt_coe] using exists_pow_lt_of_lt_one (NNReal.coe_pos.2 ha) (NNReal.coe_lt_coe.2 hb) nonrec theorem exists_mem_Ico_zpow {x : ℝ≥0} {y : ℝ≥0} (hx : x ≠ 0) (hy : 1 < y) : ∃ n : ℤ, x ∈ Set.Ico (y ^ n) (y ^ (n + 1)) := exists_mem_Ico_zpow hx.bot_lt hy nonrec theorem exists_mem_Ioc_zpow {x : ℝ≥0} {y : ℝ≥0} (hx : x ≠ 0) (hy : 1 < y) : ∃ n : ℤ, x ∈ Set.Ioc (y ^ n) (y ^ (n + 1)) := exists_mem_Ioc_zpow hx.bot_lt hy end Pow section Sub /-! ### Lemmas about subtraction In this section we provide a few lemmas about subtraction that do not fit well into any other typeclass. For lemmas about subtraction and addition see lemmas about `OrderedSub` in the file `Mathlib/Algebra/Order/Sub/Basic.lean`. See also `mul_tsub` and `tsub_mul`. -/ theorem sub_def {r p : ℝ≥0} : r - p = Real.toNNReal (r - p) := rfl theorem coe_sub_def {r p : ℝ≥0} : ↑(r - p) = max (r - p : ℝ) 0 := rfl example : OrderedSub ℝ≥0 := by infer_instance end Sub section Inv @[simp] theorem inv_le {r p : ℝ≥0} (h : r ≠ 0) : r⁻¹ ≤ p ↔ 1 ≤ r * p := by rw [← mul_le_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel₀ h] theorem inv_le_of_le_mul {r p : ℝ≥0} (h : 1 ≤ r * p) : r⁻¹ ≤ p := by by_cases r = 0 <;> simp [*, inv_le] @[simp] theorem le_inv_iff_mul_le {r p : ℝ≥0} (h : p ≠ 0) : r ≤ p⁻¹ ↔ r * p ≤ 1 := by rw [← mul_le_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel₀ h, mul_comm] @[simp] theorem lt_inv_iff_mul_lt {r p : ℝ≥0} (h : p ≠ 0) : r < p⁻¹ ↔ r * p < 1 := by rw [← mul_lt_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel₀ h, mul_comm] theorem div_le_of_le_mul {a b c : ℝ≥0} (h : a ≤ b * c) : a / c ≤ b := if h0 : c = 0 then by simp [h0] else (div_le_iff₀ (pos_iff_ne_zero.2 h0)).2 h theorem div_le_of_le_mul' {a b c : ℝ≥0} (h : a ≤ b * c) : a / b ≤ c := div_le_of_le_mul <| mul_comm b c ▸ h theorem mul_lt_of_lt_div {a b r : ℝ≥0} (h : a < b / r) : a * r < b := (lt_div_iff₀ <| pos_iff_ne_zero.2 fun hr => False.elim <| by simp [hr] at h).1 h theorem le_of_forall_lt_one_mul_le {x y : ℝ≥0} (h : ∀ a < 1, a * x ≤ y) : x ≤ y := le_of_forall_lt_imp_le_of_dense fun a ha => by have hx : x ≠ 0 := pos_iff_ne_zero.1 (lt_of_le_of_lt (zero_le _) ha) have hx' : x⁻¹ ≠ 0 := by rwa [Ne, inv_eq_zero] have : a * x⁻¹ < 1 := by rwa [← lt_inv_iff_mul_lt hx', inv_inv] have : a * x⁻¹ * x ≤ y := h _ this rwa [mul_assoc, inv_mul_cancel₀ hx, mul_one] at this nonrec theorem half_le_self (a : ℝ≥0) : a / 2 ≤ a := half_le_self bot_le nonrec theorem half_lt_self {a : ℝ≥0} (h : a ≠ 0) : a / 2 < a := half_lt_self h.bot_lt theorem div_lt_one_of_lt {a b : ℝ≥0} (h : a < b) : a / b < 1 := by rwa [div_lt_iff₀ h.bot_lt, one_mul] theorem _root_.Real.toNNReal_inv {x : ℝ} : Real.toNNReal x⁻¹ = (Real.toNNReal x)⁻¹ := by rcases le_total 0 x with hx | hx · nth_rw 1 [← Real.coe_toNNReal x hx] rw [← NNReal.coe_inv, Real.toNNReal_coe] · rw [toNNReal_eq_zero.mpr hx, inv_zero, toNNReal_eq_zero.mpr (inv_nonpos.mpr hx)] theorem _root_.Real.toNNReal_div {x y : ℝ} (hx : 0 ≤ x) : Real.toNNReal (x / y) = Real.toNNReal x / Real.toNNReal y := by rw [div_eq_mul_inv, div_eq_mul_inv, ← Real.toNNReal_inv, ← Real.toNNReal_mul hx] theorem _root_.Real.toNNReal_div' {x y : ℝ} (hy : 0 ≤ y) : Real.toNNReal (x / y) = Real.toNNReal x / Real.toNNReal y := by rw [div_eq_inv_mul, div_eq_inv_mul, Real.toNNReal_mul (inv_nonneg.2 hy), Real.toNNReal_inv] theorem inv_lt_one_iff {x : ℝ≥0} (hx : x ≠ 0) : x⁻¹ < 1 ↔ 1 < x := by rw [← one_div, div_lt_iff₀ hx.bot_lt, one_mul] theorem inv_lt_inv {x y : ℝ≥0} (hx : x ≠ 0) (h : x < y) : y⁻¹ < x⁻¹ := inv_strictAnti₀ hx.bot_lt h lemma exists_nat_pos_inv_lt {b : ℝ≥0} (hb : 0 < b) : ∃ (n : ℕ), 0 < n ∧ (n : ℝ≥0)⁻¹ < b := b.toReal.exists_nat_pos_inv_lt hb end Inv @[simp] theorem abs_eq (x : ℝ≥0) : |(x : ℝ)| = x := abs_of_nonneg x.property section Csupr open Set variable {ι : Sort*} {f : ι → ℝ≥0} theorem le_toNNReal_of_coe_le {x : ℝ≥0} {y : ℝ} (h : ↑x ≤ y) : x ≤ y.toNNReal := (le_toNNReal_iff_coe_le <| x.2.trans h).2 h nonrec theorem sSup_of_not_bddAbove {s : Set ℝ≥0} (hs : ¬BddAbove s) : SupSet.sSup s = 0 := by rw [← bddAbove_coe] at hs rw [← coe_inj, coe_sSup, NNReal.coe_zero] exact sSup_of_not_bddAbove hs theorem iSup_of_not_bddAbove (hf : ¬BddAbove (range f)) : ⨆ i, f i = 0 := sSup_of_not_bddAbove hf theorem iSup_empty [IsEmpty ι] (f : ι → ℝ≥0) : ⨆ i, f i = 0 := ciSup_of_empty f theorem iInf_empty [IsEmpty ι] (f : ι → ℝ≥0) : ⨅ i, f i = 0 := by rw [_root_.iInf_of_isEmpty, sInf_empty] @[simp] lemma iSup_eq_zero (hf : BddAbove (range f)) : ⨆ i, f i = 0 ↔ ∀ i, f i = 0 := by cases isEmpty_or_nonempty ι · simp · simp [← bot_eq_zero', ← le_bot_iff, ciSup_le_iff hf] @[simp] theorem iInf_const_zero {α : Sort*} : ⨅ _ : α, (0 : ℝ≥0) = 0 := by rw [← coe_inj, coe_iInf] exact Real.iInf_const_zero end Csupr end NNReal namespace Set namespace OrdConnected variable {s : Set ℝ} {t : Set ℝ≥0} theorem preimage_coe_nnreal_real (h : s.OrdConnected) : ((↑) ⁻¹' s : Set ℝ≥0).OrdConnected := h.preimage_mono NNReal.coe_mono theorem image_coe_nnreal_real (h : t.OrdConnected) : ((↑) '' t : Set ℝ).OrdConnected := ⟨forall_mem_image.2 fun x hx => forall_mem_image.2 fun _y hy z hz => ⟨⟨z, x.2.trans hz.1⟩, h.out hx hy hz, rfl⟩⟩ -- TODO: does it generalize to a `GaloisInsertion`? theorem image_real_toNNReal (h : s.OrdConnected) : (Real.toNNReal '' s).OrdConnected := by refine ⟨forall_mem_image.2 fun x hx => forall_mem_image.2 fun y hy z hz => ?_⟩ rcases le_total y 0 with hy₀ | hy₀ · rw [mem_Icc, Real.toNNReal_of_nonpos hy₀, nonpos_iff_eq_zero] at hz exact ⟨y, hy, (toNNReal_of_nonpos hy₀).trans hz.2.symm⟩ · lift y to ℝ≥0 using hy₀ rw [toNNReal_coe] at hz exact ⟨z, h.out hx hy ⟨toNNReal_le_iff_le_coe.1 hz.1, hz.2⟩, toNNReal_coe⟩ theorem preimage_real_toNNReal (h : t.OrdConnected) : (Real.toNNReal ⁻¹' t).OrdConnected := h.preimage_mono Real.toNNReal_mono end OrdConnected end Set namespace Real /-- The absolute value on `ℝ` as a map to `ℝ≥0`. -/ -- Porting note (kmill): `pp_nodot` has no affect here -- unless RFC https://github.com/leanprover/lean4/issues/6178 leads to dot notation pp for CoeFun @[pp_nodot] def nnabs : ℝ →*₀ ℝ≥0 where toFun x := ⟨|x|, abs_nonneg x⟩ map_zero' := by ext; simp map_one' := by ext; simp map_mul' x y := by ext; simp [abs_mul] @[norm_cast, simp] theorem coe_nnabs (x : ℝ) : (nnabs x : ℝ) = |x| := rfl @[simp] theorem nnabs_of_nonneg {x : ℝ} (h : 0 ≤ x) : nnabs x = toNNReal x := by ext rw [coe_toNNReal x h, coe_nnabs, abs_of_nonneg h] theorem nnabs_coe (x : ℝ≥0) : nnabs x = x := by simp theorem coe_toNNReal_le (x : ℝ) : (toNNReal x : ℝ) ≤ |x| := max_le (le_abs_self _) (abs_nonneg _) @[simp] lemma toNNReal_abs (x : ℝ) : |x|.toNNReal = nnabs x := NNReal.coe_injective <| by simp theorem cast_natAbs_eq_nnabs_cast (n : ℤ) : (n.natAbs : ℝ≥0) = nnabs n := by ext rw [NNReal.coe_natCast, Int.cast_natAbs, Real.coe_nnabs, Int.cast_abs] /-- Every real number nonnegative or nonpositive, phrased using `ℝ≥0`. -/ lemma nnreal_dichotomy (r : ℝ) : ∃ x : ℝ≥0, r = x ∨ r = -x := by obtain (hr | hr) : 0 ≤ r ∨ 0 ≤ -r := by simpa using le_total .. all_goals rw [← neg_neg r] lift (_ : ℝ) to ℝ≥0 using hr with r aesop /-- Every real number is either zero, positive or negative, phrased using `ℝ≥0`. -/ lemma nnreal_trichotomy (r : ℝ) : r = 0 ∨ ∃ x : ℝ≥0, 0 < x ∧ (r = x ∨ r = -x) := by obtain ⟨x, hx⟩ := nnreal_dichotomy r rw [or_iff_not_imp_left] aesop (add simp pos_iff_ne_zero) /-- To prove a property holds for real numbers it suffices to show that it holds for `x : ℝ≥0`, and if it holds for `x : ℝ≥0`, then it does also for `(-↑x : ℝ)`. -/ @[elab_as_elim] lemma nnreal_induction_on {motive : ℝ → Prop} (nonneg : ∀ x : ℝ≥0, motive x) (nonpos : ∀ x : ℝ≥0, motive x → motive (-x)) (r : ℝ) : motive r := by obtain ⟨r, (rfl | rfl)⟩ := r.nnreal_dichotomy all_goals simp_all /-- A version of `nnreal_induction_on` which splits into three cases (zero, positive and negative) instead of two. -/ @[elab_as_elim] lemma nnreal_induction_on' {motive : ℝ → Prop} (zero : motive 0) (pos : ∀ x : ℝ≥0, 0 < x → motive x) (neg : ∀ x : ℝ≥0, 0 < x → motive x → motive (-x)) (r : ℝ) : motive r := by obtain rfl | ⟨r, hr, (rfl | rfl)⟩ := r.nnreal_trichotomy all_goals simp_all end Real section StrictMono variable {Γ₀ : Type*} [LinearOrderedCommGroupWithZero Γ₀] /-- If `Γ₀ˣ` is nontrivial and `f : Γ₀ →*₀ ℝ≥0` is strictly monotone, then for any positive `r : ℝ≥0`, there exists `d : Γ₀ˣ` with `f d < r`. -/ theorem NNReal.exists_lt_of_strictMono [h : Nontrivial Γ₀ˣ] {f : Γ₀ →*₀ ℝ≥0} (hf : StrictMono f) {r : ℝ≥0} (hr : 0 < r) : ∃ d : Γ₀ˣ, f d < r := by obtain ⟨g, hg1⟩ := (nontrivial_iff_exists_ne (1 : Γ₀ˣ)).mp h set u : Γ₀ˣ := if g < 1 then g else g⁻¹ with hu have hfu : f u < 1 := by rw [hu] split_ifs with hu1 · rw [← map_one f]; exact hf hu1 · have hfg0 : f g ≠ 0 := fun h0 ↦ (Units.ne_zero g) ((map_eq_zero f).mp h0) have hg1' : 1 < g := lt_of_le_of_ne (not_lt.mp hu1) hg1.symm rw [Units.val_inv_eq_inv_val, map_inv₀, inv_lt_one_iff hfg0, ← map_one f] exact hf hg1' obtain ⟨n, hn⟩ := exists_pow_lt_of_lt_one hr hfu use u ^ n rwa [Units.val_pow_eq_pow_val, map_pow] /-- If `Γ₀ˣ` is nontrivial and `f : Γ₀ →*₀ ℝ≥0` is strictly monotone, then for any positive real `r`, there exists `d : Γ₀ˣ` with `f d < r`. -/ theorem Real.exists_lt_of_strictMono [h : Nontrivial Γ₀ˣ] {f : Γ₀ →*₀ ℝ≥0} (hf : StrictMono f) {r : ℝ} (hr : 0 < r) : ∃ d : Γ₀ˣ, (f d : ℝ) < r := by set s : NNReal := ⟨r, le_of_lt hr⟩ have hs : 0 < s := hr exact NNReal.exists_lt_of_strictMono hf hs end StrictMono /-- While not very useful, this instance uses the same representation as `Real.instRepr`. -/ unsafe instance : Repr ℝ≥0 where reprPrec r _ := f!"({repr r.val}).toNNReal" namespace Mathlib.Meta.Positivity open Lean Meta Qq private alias ⟨_, nnreal_coe_pos⟩ := coe_pos /-- Extension for the `positivity` tactic: cast from `ℝ≥0` to `ℝ`. -/ @[positivity NNReal.toReal _] def evalNNRealtoReal : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(NNReal.toReal $a) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure (.positive q(nnreal_coe_pos $pa)) | _ => pure (.nonnegative q(NNReal.coe_nonneg $a)) | _, _, _ => throwError "not NNReal.toReal" end Mathlib.Meta.Positivity
Compact.lean
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Topology.ContinuousMap.Bounded.Star import Mathlib.Topology.ContinuousMap.Star import Mathlib.Topology.UniformSpace.Compact import Mathlib.Topology.CompactOpen import Mathlib.Topology.Sets.Compacts import Mathlib.Analysis.Normed.Group.InfiniteSum /-! # Continuous functions on a compact space Continuous functions `C(α, β)` from a compact space `α` to a metric space `β` are automatically bounded, and so acquire various structures inherited from `α →ᵇ β`. This file transfers these structures, and restates some lemmas characterising these structures. If you need a lemma which is proved about `α →ᵇ β` but not for `C(α, β)` when `α` is compact, you should restate it here. You can also use `ContinuousMap.equivBoundedOfCompact` to move functions back and forth. -/ noncomputable section open NNReal BoundedContinuousFunction Set Metric namespace ContinuousMap variable {α β E : Type*} variable [TopologicalSpace α] [CompactSpace α] [PseudoMetricSpace β] [SeminormedAddCommGroup E] section variable (α β) /-- When `α` is compact, the bounded continuous maps `α →ᵇ β` are equivalent to `C(α, β)`. -/ @[simps -fullyApplied] def equivBoundedOfCompact : C(α, β) ≃ (α →ᵇ β) := ⟨mkOfCompact, BoundedContinuousFunction.toContinuousMap, fun f => by ext rfl, fun f => by ext rfl⟩ theorem isUniformInducing_equivBoundedOfCompact : IsUniformInducing (equivBoundedOfCompact α β) := IsUniformInducing.mk' (by simp only [hasBasis_compactConvergenceUniformity.mem_iff, uniformity_basis_dist_le.mem_iff] exact fun s => ⟨fun ⟨⟨a, b⟩, ⟨_, ⟨ε, hε, hb⟩⟩, hs⟩ => ⟨{ p | ∀ x, (p.1 x, p.2 x) ∈ b }, ⟨ε, hε, fun _ h x => hb ((dist_le hε.le).mp h x)⟩, fun f g h => hs fun x _ => h x⟩, fun ⟨_, ⟨ε, hε, ht⟩, hs⟩ => ⟨⟨Set.univ, { p | dist p.1 p.2 ≤ ε }⟩, ⟨isCompact_univ, ⟨ε, hε, fun _ h => h⟩⟩, fun ⟨f, g⟩ h => hs _ _ (ht ((dist_le hε.le).mpr fun x => h x (mem_univ x)))⟩⟩) theorem isUniformEmbedding_equivBoundedOfCompact : IsUniformEmbedding (equivBoundedOfCompact α β) := { isUniformInducing_equivBoundedOfCompact α β with injective := (equivBoundedOfCompact α β).injective } /-- When `α` is compact, the bounded continuous maps `α →ᵇ 𝕜` are additively equivalent to `C(α, 𝕜)`. -/ @[simps! -fullyApplied apply symm_apply] def addEquivBoundedOfCompact [AddMonoid β] [LipschitzAdd β] : C(α, β) ≃+ (α →ᵇ β) := ({ toContinuousMapAddHom α β, (equivBoundedOfCompact α β).symm with } : (α →ᵇ β) ≃+ C(α, β)).symm instance instPseudoMetricSpace : PseudoMetricSpace C(α, β) := (isUniformEmbedding_equivBoundedOfCompact α β).comapPseudoMetricSpace _ instance instMetricSpace {β : Type*} [MetricSpace β] : MetricSpace C(α, β) := (isUniformEmbedding_equivBoundedOfCompact α β).comapMetricSpace _ /-- When `α` is compact, and `β` is a metric space, the bounded continuous maps `α →ᵇ β` are isometric to `C(α, β)`. -/ @[simps! -fullyApplied toEquiv apply symm_apply] def isometryEquivBoundedOfCompact : C(α, β) ≃ᵢ (α →ᵇ β) where isometry_toFun _ _ := rfl toEquiv := equivBoundedOfCompact α β end @[simp] theorem _root_.BoundedContinuousFunction.dist_mkOfCompact (f g : C(α, β)) : dist (mkOfCompact f) (mkOfCompact g) = dist f g := rfl @[simp] theorem _root_.BoundedContinuousFunction.dist_toContinuousMap (f g : α →ᵇ β) : dist f.toContinuousMap g.toContinuousMap = dist f g := rfl open BoundedContinuousFunction section variable {f g : C(α, β)} {C : ℝ} /-- The pointwise distance is controlled by the distance between functions, by definition. -/ theorem dist_apply_le_dist (x : α) : dist (f x) (g x) ≤ dist f g := by simp only [← dist_mkOfCompact, dist_coe_le_dist, ← mkOfCompact_apply] /-- The distance between two functions is controlled by the supremum of the pointwise distances. -/ theorem dist_le (C0 : (0 : ℝ) ≤ C) : dist f g ≤ C ↔ ∀ x : α, dist (f x) (g x) ≤ C := by simp only [← dist_mkOfCompact, BoundedContinuousFunction.dist_le C0, mkOfCompact_apply] theorem dist_le_iff_of_nonempty [Nonempty α] : dist f g ≤ C ↔ ∀ x, dist (f x) (g x) ≤ C := by simp only [← dist_mkOfCompact, BoundedContinuousFunction.dist_le_iff_of_nonempty, mkOfCompact_apply] theorem dist_lt_iff_of_nonempty [Nonempty α] : dist f g < C ↔ ∀ x : α, dist (f x) (g x) < C := by simp only [← dist_mkOfCompact, dist_lt_iff_of_nonempty_compact, mkOfCompact_apply] theorem dist_lt_of_nonempty [Nonempty α] (w : ∀ x : α, dist (f x) (g x) < C) : dist f g < C := dist_lt_iff_of_nonempty.2 w theorem dist_lt_iff (C0 : (0 : ℝ) < C) : dist f g < C ↔ ∀ x : α, dist (f x) (g x) < C := by rw [← dist_mkOfCompact, dist_lt_iff_of_compact C0] simp only [mkOfCompact_apply] theorem dist_eq_iSup : dist f g = ⨆ x, dist (f x) (g x) := by simp [← isometryEquivBoundedOfCompact α β |>.dist_eq f g, BoundedContinuousFunction.dist_eq_iSup] theorem nndist_eq_iSup : nndist f g = ⨆ x, nndist (f x) (g x) := by simp [← isometryEquivBoundedOfCompact α β |>.nndist_eq f g, BoundedContinuousFunction.nndist_eq_iSup] theorem edist_eq_iSup : edist f g = ⨆ (x : α), edist (f x) (g x) := by simp [← isometryEquivBoundedOfCompact α β |>.edist_eq f g, BoundedContinuousFunction.edist_eq_iSup] instance {R} [Zero R] [Zero β] [PseudoMetricSpace R] [SMul R β] [IsBoundedSMul R β] : IsBoundedSMul R C(α, β) where dist_smul_pair' r f g := by simpa only [← dist_mkOfCompact] using dist_smul_pair r (mkOfCompact f) (mkOfCompact g) dist_pair_smul' r₁ r₂ f := by simpa only [← dist_mkOfCompact] using dist_pair_smul r₁ r₂ (mkOfCompact f) end -- TODO at some point we will need lemmas characterising this norm! -- At the moment the only way to reason about it is to transfer `f : C(α,E)` back to `α →ᵇ E`. instance : Norm C(α, E) where norm x := dist x 0 @[simp] theorem _root_.BoundedContinuousFunction.norm_mkOfCompact (f : C(α, E)) : ‖mkOfCompact f‖ = ‖f‖ := rfl @[simp] theorem _root_.BoundedContinuousFunction.norm_toContinuousMap_eq (f : α →ᵇ E) : ‖f.toContinuousMap‖ = ‖f‖ := rfl open BoundedContinuousFunction instance : SeminormedAddCommGroup C(α, E) where __ := ContinuousMap.instPseudoMetricSpace _ _ __ := ContinuousMap.instAddCommGroupContinuousMap dist_eq x y := by rw [← norm_mkOfCompact, ← dist_mkOfCompact, dist_eq_norm, mkOfCompact_sub] dist := dist norm := norm instance {E : Type*} [NormedAddCommGroup E] : NormedAddCommGroup C(α, E) where __ : SeminormedAddCommGroup C(α, E) := inferInstance __ : MetricSpace C(α, E) := inferInstance instance [Nonempty α] [One E] [NormOneClass E] : NormOneClass C(α, E) where norm_one := by simp only [← norm_mkOfCompact, mkOfCompact_one, norm_one] section variable (f : C(α, E)) -- The corresponding lemmas for `BoundedContinuousFunction` are stated with `{f}`, -- and so can not be used in dot notation. theorem norm_coe_le_norm (x : α) : ‖f x‖ ≤ ‖f‖ := (mkOfCompact f).norm_coe_le_norm x /-- Distance between the images of any two points is at most twice the norm of the function. -/ theorem dist_le_two_norm (x y : α) : dist (f x) (f y) ≤ 2 * ‖f‖ := (mkOfCompact f).dist_le_two_norm x y /-- The norm of a function is controlled by the supremum of the pointwise norms. -/ theorem norm_le {C : ℝ} (C0 : (0 : ℝ) ≤ C) : ‖f‖ ≤ C ↔ ∀ x : α, ‖f x‖ ≤ C := @BoundedContinuousFunction.norm_le _ _ _ _ (mkOfCompact f) _ C0 theorem norm_le_of_nonempty [Nonempty α] {M : ℝ} : ‖f‖ ≤ M ↔ ∀ x, ‖f x‖ ≤ M := @BoundedContinuousFunction.norm_le_of_nonempty _ _ _ _ _ (mkOfCompact f) _ theorem norm_lt_iff {M : ℝ} (M0 : 0 < M) : ‖f‖ < M ↔ ∀ x, ‖f x‖ < M := @BoundedContinuousFunction.norm_lt_iff_of_compact _ _ _ _ _ (mkOfCompact f) _ M0 theorem nnnorm_lt_iff {M : ℝ≥0} (M0 : 0 < M) : ‖f‖₊ < M ↔ ∀ x : α, ‖f x‖₊ < M := f.norm_lt_iff M0 theorem norm_lt_iff_of_nonempty [Nonempty α] {M : ℝ} : ‖f‖ < M ↔ ∀ x, ‖f x‖ < M := @BoundedContinuousFunction.norm_lt_iff_of_nonempty_compact _ _ _ _ _ _ (mkOfCompact f) _ theorem nnnorm_lt_iff_of_nonempty [Nonempty α] {M : ℝ≥0} : ‖f‖₊ < M ↔ ∀ x, ‖f x‖₊ < M := f.norm_lt_iff_of_nonempty theorem apply_le_norm (f : C(α, ℝ)) (x : α) : f x ≤ ‖f‖ := le_trans (le_abs.mpr (Or.inl (le_refl (f x)))) (f.norm_coe_le_norm x) theorem neg_norm_le_apply (f : C(α, ℝ)) (x : α) : -‖f‖ ≤ f x := le_trans (neg_le_neg (f.norm_coe_le_norm x)) (neg_le.mp (neg_le_abs (f x))) theorem nnnorm_eq_iSup_nnnorm : ‖f‖₊ = ⨆ x : α, ‖f x‖₊ := (mkOfCompact f).nnnorm_eq_iSup_nnnorm theorem norm_eq_iSup_norm : ‖f‖ = ⨆ x : α, ‖f x‖ := (mkOfCompact f).norm_eq_iSup_norm theorem enorm_eq_iSup_enorm : ‖f‖ₑ = ⨆ x, ‖f x‖ₑ := (mkOfCompact f).enorm_eq_iSup_enorm -- A version with better keys instance {X : Type*} [TopologicalSpace X] (K : TopologicalSpace.Compacts X) : CompactSpace (K : Set X) := TopologicalSpace.Compacts.instCompactSpaceSubtypeMem .. theorem norm_restrict_mono_set {X : Type*} [TopologicalSpace X] (f : C(X, E)) {K L : TopologicalSpace.Compacts X} (hKL : K ≤ L) : ‖f.restrict K‖ ≤ ‖f.restrict L‖ := (norm_le _ (norm_nonneg _)).mpr fun x => norm_coe_le_norm (f.restrict L) <| Set.inclusion hKL x end section variable {R : Type*} instance [NonUnitalSeminormedRing R] : NonUnitalSeminormedRing C(α, R) where __ : SeminormedAddCommGroup C(α, R) := inferInstance __ : NonUnitalRing C(α, R) := inferInstance norm_mul_le f g := norm_mul_le (mkOfCompact f) (mkOfCompact g) instance [NonUnitalSeminormedCommRing R] : NonUnitalSeminormedCommRing C(α, R) where __ : NonUnitalSeminormedRing C(α, R) := inferInstance __ : NonUnitalCommRing C(α, R) := inferInstance instance [SeminormedRing R] : SeminormedRing C(α, R) where __ : NonUnitalSeminormedRing C(α, R) := inferInstance __ : Ring C(α, R) := inferInstance instance [SeminormedCommRing R] : SeminormedCommRing C(α, R) where __ : SeminormedRing C(α, R) := inferInstance __ : CommRing C(α, R) := inferInstance instance [NonUnitalNormedRing R] : NonUnitalNormedRing C(α, R) where __ : NormedAddCommGroup C(α, R) := inferInstance __ : NonUnitalSeminormedRing C(α, R) := inferInstance instance [NonUnitalNormedCommRing R] : NonUnitalNormedCommRing C(α, R) where __ : NonUnitalNormedRing C(α, R) := inferInstance __ : NonUnitalCommRing C(α, R) := inferInstance instance [NormedRing R] : NormedRing C(α, R) where __ : NormedAddCommGroup C(α, R) := inferInstance __ : SeminormedRing C(α, R) := inferInstance instance [NormedCommRing R] : NormedCommRing C(α, R) where __ : NormedRing C(α, R) := inferInstance __ : CommRing C(α, R) := inferInstance end section variable {𝕜 : Type*} [NormedRing 𝕜] [Module 𝕜 E] [IsBoundedSMul 𝕜 E] instance normedSpace {𝕜 : Type*} [NormedField 𝕜] [NormedSpace 𝕜 E] : NormedSpace 𝕜 C(α, E) where norm_smul_le := norm_smul_le section variable (α 𝕜 E) /-- When `α` is compact and `𝕜` is a normed field, the `𝕜`-algebra of bounded continuous maps `α →ᵇ β` is `𝕜`-linearly isometric to `C(α, β)`. -/ def linearIsometryBoundedOfCompact : C(α, E) ≃ₗᵢ[𝕜] α →ᵇ E := { addEquivBoundedOfCompact α E with map_smul' := fun c f => by ext norm_cast norm_map' := fun _ => rfl } end -- this lemma and the next are the analogues of those autogenerated by `@[simps]` for -- `equivBoundedOfCompact`, `addEquivBoundedOfCompact` @[simp] theorem linearIsometryBoundedOfCompact_symm_apply (f : α →ᵇ E) : (linearIsometryBoundedOfCompact α E 𝕜).symm f = f.toContinuousMap := rfl @[simp] theorem linearIsometryBoundedOfCompact_apply_apply (f : C(α, E)) (a : α) : (linearIsometryBoundedOfCompact α E 𝕜 f) a = f a := rfl @[simp] theorem linearIsometryBoundedOfCompact_toIsometryEquiv : (linearIsometryBoundedOfCompact α E 𝕜).toIsometryEquiv = isometryEquivBoundedOfCompact α E := rfl @[simp] theorem linearIsometryBoundedOfCompact_toAddEquiv : ((linearIsometryBoundedOfCompact α E 𝕜).toLinearEquiv : C(α, E) ≃+ (α →ᵇ E)) = addEquivBoundedOfCompact α E := rfl @[simp] theorem linearIsometryBoundedOfCompact_of_compact_toEquiv : (linearIsometryBoundedOfCompact α E 𝕜).toLinearEquiv.toEquiv = equivBoundedOfCompact α E := rfl end @[simp] lemma nnnorm_smul_const {R β : Type*} [SeminormedAddCommGroup β] [SeminormedRing R] [Module R β] [NormSMulClass R β] (f : C(α, R)) (b : β) : ‖f • const α b‖₊ = ‖f‖₊ * ‖b‖₊ := by simp only [nnnorm_eq_iSup_nnnorm, smul_apply', const_apply, nnnorm_smul, iSup_mul] @[simp] lemma norm_smul_const {R β : Type*} [SeminormedAddCommGroup β] [SeminormedRing R] [Module R β] [NormSMulClass R β] (f : C(α, R)) (b : β) : ‖f • const α b‖ = ‖f‖ * ‖b‖ := by simp only [← coe_nnnorm, NNReal.coe_mul, nnnorm_smul_const] section variable {𝕜 : Type*} {γ : Type*} [NormedField 𝕜] [SeminormedRing γ] [NormedAlgebra 𝕜 γ] instance : NormedAlgebra 𝕜 C(α, γ) := { ContinuousMap.normedSpace, ContinuousMap.algebra with } end end ContinuousMap namespace ContinuousMap section UniformContinuity variable {α β : Type*} variable [PseudoMetricSpace α] [CompactSpace α] [PseudoMetricSpace β] /-! We now set up some declarations making it convenient to use uniform continuity. -/ theorem uniform_continuity (f : C(α, β)) (ε : ℝ) (h : 0 < ε) : ∃ δ > 0, ∀ {x y}, dist x y < δ → dist (f x) (f y) < ε := Metric.uniformContinuous_iff.mp (CompactSpace.uniformContinuous_of_continuous f.continuous) ε h -- This definition allows us to separate the choice of some `δ`, -- and the corresponding use of `dist a b < δ → dist (f a) (f b) < ε`, -- even across different declarations. /-- An arbitrarily chosen modulus of uniform continuity for a given function `f` and `ε > 0`. -/ def modulus (f : C(α, β)) (ε : ℝ) (h : 0 < ε) : ℝ := Classical.choose (uniform_continuity f ε h) theorem modulus_pos (f : C(α, β)) {ε : ℝ} {h : 0 < ε} : 0 < f.modulus ε h := (Classical.choose_spec (uniform_continuity f ε h)).1 theorem dist_lt_of_dist_lt_modulus (f : C(α, β)) (ε : ℝ) (h : 0 < ε) {a b : α} (w : dist a b < f.modulus ε h) : dist (f a) (f b) < ε := (Classical.choose_spec (uniform_continuity f ε h)).2 w end UniformContinuity end ContinuousMap section CompLeft @[deprecated (since := "2025-05-18")] alias ContinuousLinearMap.compLeftContinuousCompact := ContinuousLinearMap.compLeftContinuous @[deprecated (since := "2025-05-18")] alias ContinuousLinearMap.compLeftContinuousCompact_apply := ContinuousLinearMap.compLeftContinuous_apply end CompLeft namespace ContinuousMap section LocalNormalConvergence /-! ### Local normal convergence A sum of continuous functions (on a locally compact space) is "locally normally convergent" if the sum of its sup-norms on any compact subset is summable. This implies convergence in the topology of `C(X, E)` (i.e. locally uniform convergence). -/ open TopologicalSpace variable {X : Type*} [TopologicalSpace X] [LocallyCompactSpace X] variable {E : Type*} [NormedAddCommGroup E] [CompleteSpace E] theorem summable_of_locally_summable_norm {ι : Type*} {F : ι → C(X, E)} (hF : ∀ K : Compacts X, Summable fun i => ‖(F i).restrict K‖) : Summable F := by classical refine (ContinuousMap.exists_tendsto_compactOpen_iff_forall _).2 fun K hK => ?_ lift K to Compacts X using hK have A : ∀ s : Finset ι, restrict K (∑ i ∈ s, F i) = ∑ i ∈ s, restrict K (F i) := by intro s ext1 x -- TODO: there is a non-confluence problem in the lemmas here, -- and `SetLike.coe_sort_coe` prevents `restrict_apply` from being used. simp [-SetLike.coe_sort_coe] simpa only [HasSum, A] using (hF K).of_norm end LocalNormalConvergence /-! ### Star structures In this section, if `β` is a normed ⋆-group, then so is the space of continuous functions from `α` to `β`, by using the star operation pointwise. Furthermore, if `α` is compact and `β` is a C⋆-ring, then `C(α, β)` is a C⋆-ring. -/ section NormedSpace variable {α : Type*} {β : Type*} variable [TopologicalSpace α] [SeminormedAddCommGroup β] [StarAddMonoid β] [NormedStarGroup β] theorem _root_.BoundedContinuousFunction.mkOfCompact_star [CompactSpace α] (f : C(α, β)) : mkOfCompact (star f) = star (mkOfCompact f) := rfl instance [CompactSpace α] : NormedStarGroup C(α, β) where norm_star_le f := by rw [← BoundedContinuousFunction.norm_mkOfCompact, BoundedContinuousFunction.mkOfCompact_star, norm_star, BoundedContinuousFunction.norm_mkOfCompact] end NormedSpace section CStarRing variable {α : Type*} {β : Type*} variable [TopologicalSpace α] [CompactSpace α] instance [NonUnitalNormedRing β] [StarRing β] [CStarRing β] : CStarRing C(α, β) where norm_mul_self_le f := by rw [← sq, ← Real.le_sqrt (norm_nonneg _) (norm_nonneg _), ContinuousMap.norm_le _ (Real.sqrt_nonneg _)] intro x rw [Real.le_sqrt (norm_nonneg _) (norm_nonneg _), sq, ← CStarRing.norm_star_mul_self] exact ContinuousMap.norm_coe_le_norm (star f * f) x end CStarRing end ContinuousMap
mxred.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq div. From mathcomp Require Import choice fintype finfun bigop fingroup perm order. From mathcomp Require Import ssralg zmodp matrix mxalgebra poly polydiv mxpoly. (*****************************************************************************) (* In this file, we prove diagonalization theorems. For this purpose, we *) (* define conjugation, similarity and diagonalizability. *) (* *) (* conjmx V f := V *m f *m pinvmx V *) (* == the conjugation of f by V, i.e. "the" matrix of f *) (* in the basis of row vectors of V. *) (* Although this makes sense only when f stabilizes V, *) (* the definition can be stated more generally. *) (* similar_to P A C == where P is a base change matrix, A is a matrix, *) (* and C is a class of matrices, *) (* this states that conjmx P A is in C, *) (* which means A is similar to a matrix in C. *) (* *) (* From the latter, we derive serveral related notions: *) (* similar P A B := similar_to P A (pred1 B) *) (* == A is similar to B, with base change matrix P *) (* similar_in D A B == A is similar to B, *) (* with a base change matrix in D *) (* similar_in_to D A C == A is similar to a matrix in the class C, *) (* with a base change matrix in D *) (* all_similar_to D As C == all the matrices in the sequence As are similar *) (* to some matrix in the class C, *) (* with a base change matrix in D. *) (* *) (* We also specialize the class C, to diagonalizability: *) (* similar_diag P A := (similar_to P A is_diag_mx). *) (* diagonalizable_in D A := (similar_in_to D A is_diag_mx). *) (* diagonalizable A := (diagonalizable_in unitmx A). *) (* codiagonalizable_in D As := (all_similar_to D As is_diag_mx). *) (* codiagonalizable As := (codiagonalizable_in unitmx As). *) (* *) (* The main results of this file are: *) (* diagonalizablePeigen: *) (* a matrix is diagonalizable iff there is a sequence *) (* of scalars r, such that the sum of the associated *) (* eigenspaces is full. *) (* diagonalizableP: *) (* a matrix is diagonalizable iff its minimal polynomial *) (* divides a split polynomial with simple roots. *) (* codiagonalizableP: *) (* a sequence of matrices are diagonalizable in the same basis *) (* iff they are all diagonalizable and commute pairwize. *) (* *) (* We also specialize the class C, to trigonalizablility: *) (* similar_trig P A := (similar_to P A is_trig_mx). *) (* trigonalizable_in D A := (similar_in_to D A is_trig_mx). *) (* trigonalizable A := (trigonalizable_in unitmx A). *) (* cotrigonalizable_in D As := (all_similar_to D As is_trig_mx). *) (* cotrigonalizable As := (cotrigonalizable_in unitmx As). *) (* The theory of trigonalization is however not developed in this file. *) (*****************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory. Import Monoid.Theory. Local Open Scope ring_scope. Section ConjMx. Context {F : fieldType}. Definition conjmx (m n : nat) (V : 'M_(m, n)) (f : 'M[F]_n) : 'M_m := V *m f *m pinvmx V. Notation restrictmx V := (conjmx (row_base V)). Lemma stablemx_comp (m n p : nat) (V : 'M[F]_(m, n)) (W : 'M_(n, p)) (f : 'M_p) : stablemx W f -> stablemx V (conjmx W f) -> stablemx (V *m W) f. Proof. by move=> Wf /(submxMr W); rewrite -mulmxA mulmxKpV// mulmxA. Qed. Lemma stablemx_restrict m n (A : 'M[F]_n) (V : 'M_n) (W : 'M_(m, \rank V)): stablemx V A -> stablemx W (restrictmx V A) = stablemx (W *m row_base V) A. Proof. move=> A_stabV; rewrite mulmxA -[in RHS]mulmxA. rewrite -(submxMfree _ W (row_base_free V)) mulmxKpV //. by rewrite mulmx_sub ?stablemx_row_base. Qed. Lemma conjmxM (m n : nat) (V : 'M[F]_(m, n)) : {in [pred f | stablemx V f] &, {morph conjmx V : f g / f *m g}}. Proof. move=> f g; rewrite !inE => Vf Vg /=. by rewrite /conjmx 2!mulmxA mulmxA mulmxKpV ?stablemx_row_base. Qed. Lemma conjMmx (m n p : nat) (V : 'M[F]_(m, n)) (W : 'M_(n, p)) (f : 'M_p) : row_free (V *m W) -> stablemx W f -> stablemx V (conjmx W f) -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. move=> rfVW Wf VWf; apply: (row_free_inj rfVW); rewrite mulmxKpV ?stablemx_comp//. by rewrite mulmxA mulmxKpV// -[RHS]mulmxA mulmxKpV ?mulmxA. Qed. Lemma conjuMmx (m n : nat) (V : 'M[F]_m) (W : 'M_(m, n)) (f : 'M_n) : V \in unitmx -> row_free W -> stablemx W f -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. move=> Vu rfW Wf; rewrite conjMmx ?stablemx_unit//. by rewrite /row_free mxrankMfree// -/(row_free V) row_free_unit. Qed. Lemma conjMumx (m n : nat) (V : 'M[F]_(m, n)) (W f : 'M_n) : W \in unitmx -> row_free V -> stablemx V (conjmx W f) -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. move=> Wu rfW Wf; rewrite conjMmx ?stablemx_unit//. by rewrite /row_free mxrankMfree ?row_free_unit. Qed. Lemma conjuMumx (n : nat) (V W f : 'M[F]_n) : V \in unitmx -> W \in unitmx -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. by move=> Vu Wu; rewrite conjuMmx ?stablemx_unit ?row_free_unit. Qed. Lemma conjmx_scalar (m n : nat) (V : 'M[F]_(m, n)) (a : F) : row_free V -> conjmx V a%:M = a%:M. Proof. by move=> rfV; rewrite /conjmx scalar_mxC mulmxKp. Qed. Lemma conj0mx (m n : nat) f : conjmx (0 : 'M[F]_(m, n)) f = 0. Proof. by rewrite /conjmx !mul0mx. Qed. Lemma conjmx0 (m n : nat) (V : 'M[F]_(m, n)) : conjmx V 0 = 0. Proof. by rewrite /conjmx mulmx0 mul0mx. Qed. Lemma conjumx (n : nat) (V : 'M_n) (f : 'M[F]_n) : V \in unitmx -> conjmx V f = V *m f *m invmx V. Proof. by move=> uV; rewrite /conjmx pinvmxE. Qed. Lemma conj1mx (n : nat) (f : 'M[F]_n) : conjmx 1%:M f = f. Proof. by rewrite conjumx ?unitmx1// invmx1 mulmx1 mul1mx. Qed. Lemma conjVmx (n : nat) (V : 'M_n) (f : 'M[F]_n) : V \in unitmx -> conjmx (invmx V) f = invmx V *m f *m V. Proof. by move=> Vunit; rewrite conjumx ?invmxK ?unitmx_inv. Qed. Lemma conjmxK (n : nat) (V f : 'M[F]_n) : V \in unitmx -> conjmx (invmx V) (conjmx V f) = f. Proof. by move=> Vu; rewrite -conjuMumx ?unitmx_inv// mulVmx ?conj1mx. Qed. Lemma conjmxVK (n : nat) (V f : 'M[F]_n) : V \in unitmx -> conjmx V (conjmx (invmx V) f) = f. Proof. by move=> Vu; rewrite -conjuMumx ?unitmx_inv// mulmxV ?conj1mx. Qed. Lemma horner_mx_conj m n p (B : 'M[F]_(n.+1, m.+1)) (f : 'M_m.+1) : row_free B -> stablemx B f -> horner_mx (conjmx B f) p = conjmx B (horner_mx f p). Proof. move=> B_free B_stab; rewrite/conjmx; elim/poly_ind: p => [|p c]. by rewrite !rmorph0 mulmx0 mul0mx. rewrite !(rmorphD, rmorphM)/= !(horner_mx_X, horner_mx_C) => ->. rewrite [_ * _]mulmxA [_ *m (B *m _)]mulmxA mulmxKpV ?horner_mx_stable//. apply: (row_free_inj B_free); rewrite [_ *m B]mulmxDl. pose stablemxE := (stablemxD, stablemxM, stablemxC, horner_mx_stable). by rewrite !mulmxKpV -?[B *m _ *m _]mulmxA ?stablemxE// mulmxDr -scalar_mxC. Qed. Lemma horner_mx_uconj n p (B : 'M[F]_(n.+1)) (f : 'M_n.+1) : B \is a GRing.unit -> horner_mx (B *m f *m invmx B) p = B *m horner_mx f p *m invmx B. Proof. move=> B_unit; rewrite -!conjumx//. by rewrite horner_mx_conj ?row_free_unit ?stablemx_unit. Qed. Lemma horner_mx_uconjC n p (B : 'M[F]_(n.+1)) (f : 'M_n.+1) : B \is a GRing.unit -> horner_mx (invmx B *m f *m B) p = invmx B *m horner_mx f p *m B. Proof. move=> B_unit; rewrite -[X in _ *m X](invmxK B). by rewrite horner_mx_uconj ?invmxK ?unitmx_inv. Qed. Lemma mxminpoly_conj m n (V : 'M[F]_(m.+1, n.+1)) (f : 'M_n.+1) : row_free V -> stablemx V f -> mxminpoly (conjmx V f) %| mxminpoly f. Proof. by move=> *; rewrite mxminpoly_min// horner_mx_conj// mx_root_minpoly conjmx0. Qed. Lemma mxminpoly_uconj n (V : 'M[F]_(n.+1)) (f : 'M_n.+1) : V \in unitmx -> mxminpoly (conjmx V f) = mxminpoly f. Proof. have simp := (row_free_unit, stablemx_unit, unitmx_inv, unitmx1). move=> Vu; apply/eqP; rewrite -eqp_monic ?mxminpoly_monic// /eqp. apply/andP; split; first by rewrite mxminpoly_conj ?simp. by rewrite -[f in X in X %| _](conjmxK _ Vu) mxminpoly_conj ?simp. Qed. Section fixed_stablemx_space. Variables (m n : nat). Implicit Types (V : 'M[F]_(m, n)) (f : 'M[F]_n). Implicit Types (a : F) (p : {poly F}). Section Sub. Variable (k : nat). Implicit Types (W : 'M[F]_(k, m)). Lemma sub_kermxpoly_conjmx V f p W : stablemx V f -> row_free V -> (W <= kermxpoly (conjmx V f) p)%MS = (W *m V <= kermxpoly f p)%MS. Proof. move: n m => [|n'] [|m']// in V f W *; rewrite ?thinmx0// => fV rfV. - by rewrite /row_free mxrank0 in rfV. - by rewrite mul0mx !sub0mx. - apply/sub_kermxP/sub_kermxP; rewrite horner_mx_conj//; last first. by move=> /(congr1 (mulmxr (pinvmx V)))/=; rewrite mul0mx !mulmxA. move=> /(congr1 (mulmxr V))/=; rewrite ![W *m _]mulmxA ?mul0mx mulmxKpV//. by rewrite -mulmxA mulmx_sub// horner_mx_stable//. Qed. Lemma sub_eigenspace_conjmx V f a W : stablemx V f -> row_free V -> (W <= eigenspace (conjmx V f) a)%MS = (W *m V <= eigenspace f a)%MS. Proof. by move=> fV rfV; rewrite !eigenspace_poly sub_kermxpoly_conjmx. Qed. End Sub. Lemma eigenpoly_conjmx V f : stablemx V f -> row_free V -> {subset eigenpoly (conjmx V f) <= eigenpoly f}. Proof. move=> fV rfV a /eigenpolyP [x]; rewrite sub_kermxpoly_conjmx//. move=> xV_le_fa x_neq0; apply/eigenpolyP. by exists (x *m V); rewrite ?mulmx_free_eq0. Qed. Lemma eigenvalue_conjmx V f : stablemx V f -> row_free V -> {subset eigenvalue (conjmx V f) <= eigenvalue f}. Proof. by move=> fV rfV a; rewrite ![_ \in _]eigenvalue_poly; apply: eigenpoly_conjmx. Qed. Lemma conjmx_eigenvalue a V f : (V <= eigenspace f a)%MS -> row_free V -> conjmx V f = a%:M. Proof. by move=> /eigenspaceP Vfa rfV; rewrite /conjmx Vfa -mul_scalar_mx mulmxKp. Qed. End fixed_stablemx_space. End ConjMx. Notation restrictmx V := (conjmx (row_base V)). Definition similar_to {F : fieldType} {m n} (P : 'M_(m, n)) A (C : {pred 'M[F]_m}) := C (conjmx P A). Notation similar P A B := (similar_to P A (PredOfSimpl.coerce (pred1 B))). Notation similar_in D A B := (exists2 P, P \in D & similar P A B). Notation similar_in_to D A C := (exists2 P, P \in D & similar_to P A C). Notation all_similar_to D As C := (exists2 P, P \in D & all [pred A | similar_to P A C] As). Notation similar_diag P A := (similar_to P A is_diag_mx). Notation diagonalizable_in D A := (similar_in_to D A is_diag_mx). Notation diagonalizable A := (diagonalizable_in unitmx A). Notation codiagonalizable_in D As := (all_similar_to D As is_diag_mx). Notation codiagonalizable As := (codiagonalizable_in unitmx As). Notation similar_trig P A := (similar_to P A is_trig_mx). Notation trigonalizable_in D A := (similar_in_to D A is_trig_mx). Notation trigonalizable A := (trigonalizable_in unitmx A). Notation cotrigonalizable_in D As := (all_similar_to D As is_trig_mx). Notation cotrigonalizable As := (cotrigonalizable_in unitmx As). Section Similarity. Context {F : fieldType}. Lemma similarPp m n {P : 'M[F]_(m, n)} {A B} : stablemx P A -> similar P A B -> P *m A = B *m P. Proof. by move=> stablemxPA /eqP <-; rewrite mulmxKpV. Qed. Lemma similarW m n {P : 'M[F]_(m, n)} {A B} : row_free P -> P *m A = B *m P -> similar P A B. Proof. by rewrite /similar_to/= /conjmx => fP ->; rewrite mulmxKp. Qed. Section Similar. Context {n : nat}. Implicit Types (f g p : 'M[F]_n) (fs : seq 'M[F]_n) (d : 'rV[F]_n). Lemma similarP {p f g} : p \in unitmx -> reflect (p *m f = g *m p) (similar p f g). Proof. move=> p_unit; apply: (iffP idP); first exact/similarPp/stablemx_unit. by apply: similarW; rewrite row_free_unit. Qed. Lemma similarRL {p f g} : p \in unitmx -> reflect (g = p *m f *m invmx p) (similar p f g). Proof. by move=> ?; apply: (iffP eqP); rewrite conjumx. Qed. Lemma similarLR {p f g} : p \in unitmx -> reflect (f = conjmx (invmx p) g) (similar p f g). Proof. by move=> pu; rewrite conjVmx//; apply: (iffP (similarRL pu)) => ->; rewrite !mulmxA ?(mulmxK, mulmxKV, mulVmx, mulmxV, mul1mx, mulmx1). Qed. End Similar. Lemma similar_mxminpoly {n} {p f g : 'M[F]_n.+1} : p \in unitmx -> similar p f g -> mxminpoly f = mxminpoly g. Proof. by move=> pu /eqP<-; rewrite mxminpoly_uconj. Qed. Lemma similar_diag_row_base m n (P : 'M[F]_(m, n)) (A : 'M_n) : similar_diag (row_base P) A = is_diag_mx (restrictmx P A). Proof. by []. Qed. Lemma similar_diagPp m n (P : 'M[F]_(m, n)) A : reflect (forall i j : 'I__, i != j :> nat -> conjmx P A i j = 0) (similar_diag P A). Proof. exact: @is_diag_mxP. Qed. Lemma similar_diagP n (P : 'M[F]_n) A : P \in unitmx -> reflect (forall i j : 'I__, i != j :> nat -> (P *m A *m invmx P) i j = 0) (similar_diag P A). Proof. by move=> Pu; rewrite -conjumx//; exact: is_diag_mxP. Qed. Lemma similar_diagPex {m} {n} {P : 'M[F]_(m, n)} {A} : reflect (exists D, similar P A (diag_mx D)) (similar_diag P A). Proof. by apply: (iffP (diag_mxP _)) => -[D]/eqP; exists D. Qed. Lemma similar_diagLR n {P : 'M[F]_n} {A} : P \in unitmx -> reflect (exists D, A = conjmx (invmx P) (diag_mx D)) (similar_diag P A). Proof. by move=> Punit; apply: (iffP similar_diagPex) => -[D /(similarLR Punit)]; exists D. Qed. Lemma similar_diag_mxminpoly {n} {p f : 'M[F]_n.+1} (rs := undup [seq conjmx p f i i | i <- enum 'I_n.+1]) : p \in unitmx -> similar_diag p f -> mxminpoly f = \prod_(r <- rs) ('X - r%:P). Proof. rewrite /rs => pu /(similar_diagLR pu)[d {f rs}->]. rewrite mxminpoly_uconj ?unitmx_inv// mxminpoly_diag. by rewrite [in RHS](@eq_map _ _ _ (d 0))// => i; rewrite conjmxVK// mxE eqxx. Qed. End Similarity. Lemma similar_diag_sum (F : fieldType) (m n : nat) (p_ : 'I_n -> nat) (V_ : forall i, 'M[F]_(p_ i, m)) (f : 'M[F]_m) : mxdirect (\sum_i <<V_ i>>) -> (forall i, stablemx (V_ i) f) -> (forall i, row_free (V_ i)) -> similar_diag (\mxcol_i V_ i) f = [forall i, similar_diag (V_ i) f]. Proof. move=> Vd Vf rfV; have aVf : stablemx (\mxcol_i V_ i) f. rewrite (eqmx_stable _ (eqmx_col _)) stablemx_sums//. by move=> i; rewrite (eqmx_stable _ (genmxE _)). apply/similar_diagPex/'forall_similar_diagPex => /= [[D /(similarPp aVf) +] i|/(_ _)/sigW Dof]. rewrite mxcol_mul -[D]submxrowK diag_mxrow mul_mxdiag_mxcol. move=> /eq_mxcolP/(_ i); set D0 := (submxrow _ _) => VMeq. by exists D0; apply/similarW. exists (\mxrow_i tag (Dof i)); apply/similarW. rewrite -row_leq_rank eqmx_col (mxdirectP Vd)/=. by under [X in (_ <= X)%N]eq_bigr do rewrite genmxE (eqP (rfV _)). rewrite mxcol_mul diag_mxrow mul_mxdiag_mxcol; apply: eq_mxcol => i. by case: Dof => /= k /(similarPp); rewrite Vf => /(_ isT) ->. Qed. Section Diag. Variable (F : fieldType). Lemma codiagonalizable1 n (A : 'M[F]_n) : codiagonalizable [:: A] <-> diagonalizable A. Proof. by split=> -[P Punit PA]; exists P; move: PA; rewrite //= andbT. Qed. Lemma codiagonalizablePfull n (As : seq 'M[F]_n) : codiagonalizable As <-> exists m, exists2 P : 'M_(m, n), row_full P & all [pred A | similar_diag P A] As. Proof. split => [[P Punit SPA]|[m [P Pfull SPA]]]. by exists n => //; exists P; rewrite ?row_full_unit. have Qfull := fullrowsub_unit Pfull. exists (rowsub (fullrankfun Pfull) P) => //; apply/allP => A AAs/=. have /allP /(_ _ AAs)/= /similar_diagPex[d /similarPp] := SPA. rewrite submx_full// => /(_ isT) PA_eq. apply/similar_diagPex; exists (colsub (fullrankfun Pfull) d). apply/similarP => //; apply/row_matrixP => i. rewrite !row_mul row_diag_mx -scalemxAl -rowE !row_rowsub !mxE. have /(congr1 (row (fullrankfun Pfull i))) := PA_eq. by rewrite !row_mul row_diag_mx -scalemxAl -rowE => ->. Qed. Lemma codiagonalizable_on m n (V_ : 'I_n -> 'M[F]_m) (As : seq 'M[F]_m) : (\sum_i V_ i :=: 1%:M)%MS -> mxdirect (\sum_i V_ i) -> (forall i, all (fun A => stablemx (V_ i) A) As) -> (forall i, codiagonalizable (map (restrictmx (V_ i)) As)) -> codiagonalizable As. Proof. move=> V1 Vdirect /(_ _)/allP AV /(_ _) /sig2W/= Pof. pose P_ i := tag (Pof i). have P_unit i : P_ i \in unitmx by rewrite /P_; case: {+}Pof. have P_diag i A : A \in As -> similar_diag (P_ i *m row_base (V_ i)) A. move=> AAs; rewrite /P_; case: {+}Pof => /= P Punit. rewrite all_map => /allP/(_ A AAs); rewrite /similar_to/=. by rewrite conjuMmx ?row_base_free ?stablemx_row_base ?AV. pose P := \mxcol_i (P_ i *m row_base (V_ i)). have P_full i : row_full (P_ i) by rewrite row_full_unit. have PrV i : (P_ i *m row_base (V_ i) :=: V_ i)%MS. exact/(eqmx_trans _ (eq_row_base _))/eqmxMfull. apply/codiagonalizablePfull; eexists _; last exists P; rewrite /=. - rewrite -sub1mx eqmx_col. by under eq_bigr do rewrite (eq_genmx (PrV _)); rewrite -genmx_sums genmxE V1. apply/allP => A AAs /=; rewrite similar_diag_sum. - by apply/forallP => i; apply: P_diag. - rewrite mxdirectE/=. under eq_bigr do rewrite (eq_genmx (PrV _)); rewrite -genmx_sums genmxE V1. by under eq_bigr do rewrite genmxE PrV; rewrite -(mxdirectP Vdirect)//= V1. - by move=> i; rewrite (eqmx_stable _ (PrV _)) ?AV. - by move=> i; rewrite /row_free eqmxMfull ?eq_row_base ?row_full_unit. Qed. Lemma diagonalizable_diag {n} (d : 'rV[F]_n) : diagonalizable (diag_mx d). Proof. by exists 1%:M; rewrite ?unitmx1// /similar_to conj1mx diag_mx_is_diag. Qed. Hint Resolve diagonalizable_diag : core. Lemma diagonalizable_scalar {n} (a : F) : diagonalizable (a%:M : 'M_n). Proof. by rewrite -diag_const_mx. Qed. Hint Resolve diagonalizable_scalar : core. Lemma diagonalizable0 {n} : diagonalizable (0 : 'M[F]_n). Proof. by rewrite (_ : 0 = 0%:M)//; apply/matrixP => i j; rewrite !mxE// mul0rn. Qed. Hint Resolve diagonalizable0 : core. Lemma diagonalizablePeigen {n} {f : 'M[F]_n} : diagonalizable f <-> exists2 rs, uniq rs & (\sum_(r <- rs) eigenspace f r :=: 1%:M)%MS. Proof. split=> [df|[rs urs rsP]]. suff [rs rsP] : exists rs, (\sum_(r <- rs) eigenspace f r :=: 1%:M)%MS. exists (undup rs); rewrite ?undup_uniq//; apply: eqmx_trans rsP. elim: rs => //= r rs IHrs; rewrite big_cons. case: ifPn => in_rs; rewrite ?big_cons; last exact: adds_eqmx. apply/(eqmx_trans IHrs)/eqmx_sym/addsmx_idPr. have rrs : (index r rs < size rs)%N by rewrite index_mem. rewrite (big_nth 0) big_mkord (sumsmx_sup (Ordinal rrs)) ?nth_index//. move: df => [P Punit /(similar_diagLR Punit)[d ->]]. exists [seq d 0 i | i <- enum 'I_n]; rewrite big_image/=. apply: (@eqmx_trans _ _ _ _ _ _ P); apply/eqmxP; rewrite ?sub1mx ?submx1 ?row_full_unit//. rewrite submx_full ?row_full_unit//=. apply/row_subP => i; rewrite rowE (sumsmx_sup i)//. apply/eigenspaceP; rewrite conjVmx// !mulmxA mulmxK//. by rewrite -rowE row_diag_mx scalemxAl. have mxdirect_eigenspaces : mxdirect (\sum_(i < size rs) eigenspace f rs`_i). apply: mxdirect_sum_eigenspace => i j _ _ rsij; apply/val_inj. by apply: uniqP rsij; rewrite ?inE. rewrite (big_nth 0) big_mkord in rsP; apply/codiagonalizable1. apply/(codiagonalizable_on _ mxdirect_eigenspaces) => // i/=. case: n => [|n] in f {mxdirect_eigenspaces} rsP *. by rewrite thinmx0 sub0mx. by rewrite comm_mx_stable_eigenspace. apply/codiagonalizable1. by rewrite (@conjmx_eigenvalue _ _ _ rs`_i) ?eq_row_base ?row_base_free. Qed. Lemma diagonalizableP n' (n := n'.+1) (f : 'M[F]_n) : diagonalizable f <-> exists2 rs, uniq rs & mxminpoly f %| \prod_(x <- rs) ('X - x%:P). Proof. split=> [[P Punit /similar_diagPex[d /(similarLR Punit)->]]|]. rewrite mxminpoly_uconj ?unitmx_inv// mxminpoly_diag. by eexists; [|by []]; rewrite undup_uniq. move=> [rs rsU rsP]; apply: diagonalizablePeigen.2. exists rs => //. rewrite (big_nth 0) big_mkord (eq_bigr _ (fun _ _ => eigenspace_poly _ _)). apply: (eqmx_trans (eqmx_sym (kermxpoly_prod _ _)) (kermxpoly_min _)). by move=> i j _ _; rewrite coprimep_XsubC root_XsubC nth_uniq. by rewrite (big_nth 0) big_mkord in rsP. Qed. Lemma diagonalizable_conj_diag m n (V : 'M[F]_(m, n)) (d : 'rV[F]_n) : stablemx V (diag_mx d) -> row_free V -> diagonalizable (conjmx V (diag_mx d)). Proof. (move: m n => [|m] [|n] in V d *; rewrite ?thinmx0; [by []|by []| |]) => Vd rdV. - by rewrite /row_free mxrank0 in rdV. - apply/diagonalizableP; pose u := undup [seq d 0 i | i <- enum 'I_n.+1]. exists u; first by rewrite undup_uniq. by rewrite (dvdp_trans (mxminpoly_conj rdV _))// mxminpoly_diag. Qed. Lemma codiagonalizableP n (fs : seq 'M[F]_n) : {in fs &, forall f g, comm_mx f g} /\ (forall f, f \in fs -> diagonalizable f) <-> codiagonalizable fs. Proof. split => [cdfs|[P Punit /allP/= fsD]]/=; last first. split; last by exists P; rewrite // fsD. move=> f g ffs gfs; move=> /(_ _ _)/similar_diagPex/sigW in fsD. have [[df /similarLR->//] [dg /similarLR->//]] := (fsD _ ffs, fsD _ gfs). by rewrite /comm_mx -!conjmxM 1?diag_mxC// inE stablemx_unit ?unitmx_inv. move: cdfs => [/(rwP (all_comm_mxP _)).1 cdfs1 cdfs2]. have [k] := ubnP (size fs); elim: k => [|k IHk]//= in n fs cdfs1 cdfs2 *. case: fs cdfs1 cdfs2 => [|f fs]//=; first by exists 1%:M; rewrite ?unitmx1. rewrite ltnS all_comm_mx_cons => /andP[/allP/(_ _ _)/eqP ffsC fsC dffs] fsk. have /diagonalizablePeigen [rs urs rs1] := dffs _ (mem_head _ _). rewrite (big_nth 0) big_mkord in rs1. have efg (i : 'I_(size rs)) g : g \in f :: fs -> stablemx (eigenspace f rs`_i) g. case: n => [|n'] in g f fs ffsC fsC {dffs rs1 fsk} * => g_ffs. by rewrite thinmx0 sub0mx. rewrite comm_mx_stable_eigenspace//. by move: g_ffs; rewrite !inE => /predU1P [->//|/ffsC]. apply/(@codiagonalizable_on _ _ _ (_ :: _) rs1) => [|i|i /=]. - apply: mxdirect_sum_eigenspace => i j _ _ rsij; apply/val_inj. by apply: uniqP rsij; rewrite ?inE. - by apply/allP => g g_ffs; rewrite efg. rewrite (@conjmx_eigenvalue _ _ _ rs`_i) ?eq_row_base ?row_base_free//. set gs := map _ _; suff [P Punit /= Pgs] : codiagonalizable gs. exists P; rewrite /= ?Pgs ?andbT// /similar_to. by rewrite conjmx_scalar ?mx_scalar_is_diag// row_free_unit. apply: IHk; rewrite ?size_map/= ?ltnS//. apply/all_comm_mxP => _ _ /mapP[/= g gfs ->] /mapP[/= h hfs ->]. rewrite -!conjmxM ?inE ?stablemx_row_base ?efg ?inE ?gfs ?hfs ?orbT//. by rewrite (all_comm_mxP _ fsC). move=> _ /mapP[/= g gfs ->]. have: stablemx (row_base (eigenspace f rs`_i)) g. by rewrite stablemx_row_base efg// inE gfs orbT. have := dffs g; rewrite inE gfs orbT => /(_ isT) [P Punit]. move=> /similar_diagPex[D /(similarLR Punit)->] sePD. have rfeP : row_free (row_base (eigenspace f rs`_i) *m invmx P). by rewrite /row_free mxrankMfree ?row_free_unit ?unitmx_inv// eq_row_base. rewrite -conjMumx ?unitmx_inv ?row_base_free//. apply/diagonalizable_conj_diag => //. by rewrite stablemx_comp// stablemx_unit ?unitmx_inv. Qed. End Diag.
FiniteDimension.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 -/ import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent import Mathlib.Analysis.Normed.Group.Lemmas import Mathlib.Analysis.Normed.Affine.AddTorsor import Mathlib.Analysis.Normed.Affine.Isometry import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace import Mathlib.Analysis.NormedSpace.RieszLemma import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Logic.Encodable.Pi import Mathlib.Topology.Algebra.Module.FiniteDimension import Mathlib.Topology.Algebra.InfiniteSum.Module import Mathlib.Topology.Instances.Matrix import Mathlib.LinearAlgebra.Dimension.LinearMap /-! # Finite dimensional normed spaces over complete fields Over a complete nontrivially normed field, in finite dimension, all norms are equivalent and all linear maps are continuous. Moreover, a finite-dimensional subspace is always complete and closed. ## Main results: * `FiniteDimensional.complete` : a finite-dimensional space over a complete field is complete. This is not registered as an instance, as the field would be an unknown metavariable in typeclass resolution. * `Submodule.closed_of_finiteDimensional` : a finite-dimensional subspace over a complete field is closed * `FiniteDimensional.proper` : a finite-dimensional space over a proper field is proper. This is not registered as an instance, as the field would be an unknown metavariable in typeclass resolution. It is however registered as an instance for `𝕜 = ℝ` and `𝕜 = ℂ`. As properness implies completeness, there is no need to also register `FiniteDimensional.complete` on `ℝ` or `ℂ`. * `FiniteDimensional.of_isCompact_closedBall`: Riesz' theorem: if the closed unit ball is compact, then the space is finite-dimensional. ## Implementation notes The fact that all norms are equivalent is not written explicitly, as it would mean having two norms on a single space, which is not the way type classes work. However, if one has a finite-dimensional vector space `E` with a norm, and a copy `E'` of this type with another norm, then the identities from `E` to `E'` and from `E'`to `E` are continuous thanks to `LinearMap.continuous_of_finiteDimensional`. This gives the desired norm equivalence. -/ universe u v w x noncomputable section open Asymptotics Filter Module Metric Module NNReal Set TopologicalSpace Topology namespace LinearIsometry open LinearMap variable {F E₁ : Type*} [SeminormedAddCommGroup F] [NormedAddCommGroup E₁] variable {R₁ : Type*} [Field R₁] [Module R₁ E₁] [Module R₁ F] [FiniteDimensional R₁ E₁] [FiniteDimensional R₁ F] /-- A linear isometry between finite dimensional spaces of equal dimension can be upgraded to a linear isometry equivalence. -/ def toLinearIsometryEquiv (li : E₁ →ₗᵢ[R₁] F) (h : finrank R₁ E₁ = finrank R₁ F) : E₁ ≃ₗᵢ[R₁] F where toLinearEquiv := li.toLinearMap.linearEquivOfInjective li.injective h norm_map' := li.norm_map' @[simp] theorem coe_toLinearIsometryEquiv (li : E₁ →ₗᵢ[R₁] F) (h : finrank R₁ E₁ = finrank R₁ F) : (li.toLinearIsometryEquiv h : E₁ → F) = li := rfl @[simp] theorem toLinearIsometryEquiv_apply (li : E₁ →ₗᵢ[R₁] F) (h : finrank R₁ E₁ = finrank R₁ F) (x : E₁) : (li.toLinearIsometryEquiv h) x = li x := rfl end LinearIsometry namespace AffineIsometry open AffineMap variable {𝕜 : Type*} {V₁ V₂ : Type*} {P₁ P₂ : Type*} [NormedField 𝕜] [NormedAddCommGroup V₁] [SeminormedAddCommGroup V₂] [NormedSpace 𝕜 V₁] [NormedSpace 𝕜 V₂] [MetricSpace P₁] [PseudoMetricSpace P₂] [NormedAddTorsor V₁ P₁] [NormedAddTorsor V₂ P₂] variable [FiniteDimensional 𝕜 V₁] [FiniteDimensional 𝕜 V₂] /-- An affine isometry between finite dimensional spaces of equal dimension can be upgraded to an affine isometry equivalence. -/ def toAffineIsometryEquiv [Inhabited P₁] (li : P₁ →ᵃⁱ[𝕜] P₂) (h : finrank 𝕜 V₁ = finrank 𝕜 V₂) : P₁ ≃ᵃⁱ[𝕜] P₂ := AffineIsometryEquiv.mk' li (li.linearIsometry.toLinearIsometryEquiv h) (Inhabited.default (α := P₁)) fun p => by simp @[simp] theorem coe_toAffineIsometryEquiv [Inhabited P₁] (li : P₁ →ᵃⁱ[𝕜] P₂) (h : finrank 𝕜 V₁ = finrank 𝕜 V₂) : (li.toAffineIsometryEquiv h : P₁ → P₂) = li := rfl @[simp] theorem toAffineIsometryEquiv_apply [Inhabited P₁] (li : P₁ →ᵃⁱ[𝕜] P₂) (h : finrank 𝕜 V₁ = finrank 𝕜 V₂) (x : P₁) : (li.toAffineIsometryEquiv h) x = li x := rfl end AffineIsometry section CompleteField variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type v} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type w} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace 𝕜] section Affine variable {PE PF : Type*} [MetricSpace PE] [NormedAddTorsor E PE] [MetricSpace PF] [NormedAddTorsor F PF] [FiniteDimensional 𝕜 E] theorem AffineMap.continuous_of_finiteDimensional (f : PE →ᵃ[𝕜] PF) : Continuous f := AffineMap.continuous_linear_iff.1 f.linear.continuous_of_finiteDimensional theorem AffineEquiv.continuous_of_finiteDimensional (f : PE ≃ᵃ[𝕜] PF) : Continuous f := f.toAffineMap.continuous_of_finiteDimensional /-- Reinterpret an affine equivalence as a homeomorphism. -/ def AffineEquiv.toHomeomorphOfFiniteDimensional (f : PE ≃ᵃ[𝕜] PF) : PE ≃ₜ PF where toEquiv := f.toEquiv continuous_toFun := f.continuous_of_finiteDimensional continuous_invFun := haveI : FiniteDimensional 𝕜 F := f.linear.finiteDimensional f.symm.continuous_of_finiteDimensional @[simp] theorem AffineEquiv.coe_toHomeomorphOfFiniteDimensional (f : PE ≃ᵃ[𝕜] PF) : ⇑f.toHomeomorphOfFiniteDimensional = f := rfl @[simp] theorem AffineEquiv.coe_toHomeomorphOfFiniteDimensional_symm (f : PE ≃ᵃ[𝕜] PF) : ⇑f.toHomeomorphOfFiniteDimensional.symm = f.symm := rfl end Affine theorem ContinuousLinearMap.continuous_det : Continuous fun f : E →L[𝕜] E => f.det := by change Continuous fun f : E →L[𝕜] E => LinearMap.det (f : E →ₗ[𝕜] E) -- TODO: this could be easier with `det_cases` by_cases h : ∃ s : Finset E, Nonempty (Basis (↥s) 𝕜 E) · rcases h with ⟨s, ⟨b⟩⟩ haveI : FiniteDimensional 𝕜 E := FiniteDimensional.of_fintype_basis b classical simp_rw [LinearMap.det_eq_det_toMatrix_of_finset b] refine Continuous.matrix_det ?_ exact ((LinearMap.toMatrix b b).toLinearMap.comp (ContinuousLinearMap.coeLM 𝕜)).continuous_of_finiteDimensional · rw [LinearMap.det] simpa only [h, MonoidHom.one_apply, dif_neg, not_false_iff] using continuous_const /-- Any `K`-Lipschitz map from a subset `s` of a metric space `α` to a finite-dimensional real vector space `E'` can be extended to a Lipschitz map on the whole space `α`, with a slightly worse constant `C * K` where `C` only depends on `E'`. We record a working value for this constant `C` as `lipschitzExtensionConstant E'`. -/ irreducible_def lipschitzExtensionConstant (E' : Type*) [NormedAddCommGroup E'] [NormedSpace ℝ E'] [FiniteDimensional ℝ E'] : ℝ≥0 := let A := (Basis.ofVectorSpace ℝ E').equivFun.toContinuousLinearEquiv max (‖A.symm.toContinuousLinearMap‖₊ * ‖A.toContinuousLinearMap‖₊) 1 theorem lipschitzExtensionConstant_pos (E' : Type*) [NormedAddCommGroup E'] [NormedSpace ℝ E'] [FiniteDimensional ℝ E'] : 0 < lipschitzExtensionConstant E' := by rw [lipschitzExtensionConstant] exact zero_lt_one.trans_le (le_max_right _ _) /-- Any `K`-Lipschitz map from a subset `s` of a metric space `α` to a finite-dimensional real vector space `E'` can be extended to a Lipschitz map on the whole space `α`, with a slightly worse constant `lipschitzExtensionConstant E' * K`. -/ theorem LipschitzOnWith.extend_finite_dimension {α : Type*} [PseudoMetricSpace α] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E'] [FiniteDimensional ℝ E'] {s : Set α} {f : α → E'} {K : ℝ≥0} (hf : LipschitzOnWith K f s) : ∃ g : α → E', LipschitzWith (lipschitzExtensionConstant E' * K) g ∧ EqOn f g s := by /- This result is already known for spaces `ι → ℝ`. We use a continuous linear equiv between `E'` and such a space to transfer the result to `E'`. -/ let ι : Type _ := Basis.ofVectorSpaceIndex ℝ E' let A := (Basis.ofVectorSpace ℝ E').equivFun.toContinuousLinearEquiv have LA : LipschitzWith ‖A.toContinuousLinearMap‖₊ A := by apply A.lipschitz have L : LipschitzOnWith (‖A.toContinuousLinearMap‖₊ * K) (A ∘ f) s := LA.comp_lipschitzOnWith hf obtain ⟨g, hg, gs⟩ : ∃ g : α → ι → ℝ, LipschitzWith (‖A.toContinuousLinearMap‖₊ * K) g ∧ EqOn (A ∘ f) g s := L.extend_pi refine ⟨A.symm ∘ g, ?_, ?_⟩ · have LAsymm : LipschitzWith ‖A.symm.toContinuousLinearMap‖₊ A.symm := by apply A.symm.lipschitz apply (LAsymm.comp hg).weaken rw [lipschitzExtensionConstant, ← mul_assoc] exact mul_le_mul' (le_max_left _ _) le_rfl · intro x hx have : A (f x) = g x := gs hx simp only [(· ∘ ·), ← this, A.symm_apply_apply] theorem LinearMap.exists_antilipschitzWith [FiniteDimensional 𝕜 E] (f : E →ₗ[𝕜] F) (hf : LinearMap.ker f = ⊥) : ∃ K > 0, AntilipschitzWith K f := by cases subsingleton_or_nontrivial E · exact ⟨1, zero_lt_one, AntilipschitzWith.of_subsingleton⟩ · rw [LinearMap.ker_eq_bot] at hf let e : E ≃L[𝕜] LinearMap.range f := (LinearEquiv.ofInjective f hf).toContinuousLinearEquiv exact ⟨_, e.nnnorm_symm_pos, e.antilipschitz⟩ open Function in /-- A `LinearMap` on a finite-dimensional space over a complete field is injective iff it is anti-Lipschitz. -/ theorem LinearMap.injective_iff_antilipschitz [FiniteDimensional 𝕜 E] (f : E →ₗ[𝕜] F) : Injective f ↔ ∃ K > 0, AntilipschitzWith K f := by constructor · rw [← LinearMap.ker_eq_bot] exact f.exists_antilipschitzWith · rintro ⟨K, -, H⟩ exact H.injective open Function in /-- The set of injective continuous linear maps `E → F` is open, if `E` is finite-dimensional over a complete field. -/ theorem ContinuousLinearMap.isOpen_injective [FiniteDimensional 𝕜 E] : IsOpen { L : E →L[𝕜] F | Injective L } := by rw [isOpen_iff_eventually] rintro φ₀ hφ₀ rcases φ₀.injective_iff_antilipschitz.mp hφ₀ with ⟨K, K_pos, H⟩ have : ∀ᶠ φ in 𝓝 φ₀, ‖φ - φ₀‖₊ < K⁻¹ := eventually_nnnorm_sub_lt _ <| inv_pos_of_pos K_pos filter_upwards [this] with φ hφ apply φ.injective_iff_antilipschitz.mpr exact ⟨(K⁻¹ - ‖φ - φ₀‖₊)⁻¹, inv_pos_of_pos (tsub_pos_of_lt hφ), H.add_sub_lipschitzWith (φ - φ₀).lipschitz hφ⟩ protected theorem LinearIndependent.eventually {ι} [Finite ι] {f : ι → E} (hf : LinearIndependent 𝕜 f) : ∀ᶠ g in 𝓝 f, LinearIndependent 𝕜 g := by cases nonempty_fintype ι classical simp only [Fintype.linearIndependent_iff'] at hf ⊢ rcases LinearMap.exists_antilipschitzWith _ hf with ⟨K, K0, hK⟩ have : Tendsto (fun g : ι → E => ∑ i, ‖g i - f i‖) (𝓝 f) (𝓝 <| ∑ i, ‖f i - f i‖) := tendsto_finset_sum _ fun i _ => Tendsto.norm <| ((continuous_apply i).tendsto _).sub tendsto_const_nhds simp only [sub_self, norm_zero, Finset.sum_const_zero] at this refine (this.eventually (gt_mem_nhds <| inv_pos.2 K0)).mono fun g hg => ?_ replace hg : ∑ i, ‖g i - f i‖₊ < K⁻¹ := by rw [← NNReal.coe_lt_coe] push_cast exact hg rw [LinearMap.ker_eq_bot] refine (hK.add_sub_lipschitzWith (LipschitzWith.of_dist_le_mul fun v u => ?_) hg).injective simp only [dist_eq_norm, LinearMap.lsum_apply, Pi.sub_apply, LinearMap.sum_apply, LinearMap.comp_apply, LinearMap.proj_apply, LinearMap.smulRight_apply, LinearMap.id_apply, ← Finset.sum_sub_distrib, ← smul_sub, ← sub_smul, NNReal.coe_sum, coe_nnnorm, Finset.sum_mul] refine norm_sum_le_of_le _ fun i _ => ?_ rw [norm_smul, mul_comm] gcongr exact norm_le_pi_norm (v - u) i theorem isOpen_setOf_linearIndependent {ι : Type*} [Finite ι] : IsOpen { f : ι → E | LinearIndependent 𝕜 f } := isOpen_iff_mem_nhds.2 fun _ => LinearIndependent.eventually theorem isOpen_setOf_nat_le_rank (n : ℕ) : IsOpen { f : E →L[𝕜] F | ↑n ≤ (f : E →ₗ[𝕜] F).rank } := by simp only [LinearMap.le_rank_iff_exists_linearIndependent_finset, setOf_exists, ← exists_prop] refine isOpen_biUnion fun t _ => ?_ have : Continuous fun f : E →L[𝕜] F => fun x : (t : Set E) => f x := continuous_pi fun x => (ContinuousLinearMap.apply 𝕜 F (x : E)).continuous exact isOpen_setOf_linearIndependent.preimage this namespace Module.Basis theorem opNNNorm_le {ι : Type*} [Fintype ι] (v : Basis ι 𝕜 E) {u : E →L[𝕜] F} (M : ℝ≥0) (hu : ∀ i, ‖u (v i)‖₊ ≤ M) : ‖u‖₊ ≤ Fintype.card ι • ‖v.equivFunL.toContinuousLinearMap‖₊ * M := u.opNNNorm_le_bound _ fun e => by set φ := v.equivFunL.toContinuousLinearMap calc ‖u e‖₊ = ‖u (∑ i, v.equivFun e i • v i)‖₊ := by rw [v.sum_equivFun] _ = ‖∑ i, v.equivFun e i • (u <| v i)‖₊ := by simp only [equivFun_apply, map_sum, map_smul] _ ≤ ∑ i, ‖v.equivFun e i • (u <| v i)‖₊ := nnnorm_sum_le _ _ _ = ∑ i, ‖v.equivFun e i‖₊ * ‖u (v i)‖₊ := by simp only [nnnorm_smul] _ ≤ ∑ i, ‖v.equivFun e i‖₊ * M := by gcongr; apply hu _ = (∑ i, ‖v.equivFun e i‖₊) * M := by rw [Finset.sum_mul] _ ≤ Fintype.card ι • (‖φ‖₊ * ‖e‖₊) * M := by gcongr calc ∑ i, ‖v.equivFun e i‖₊ ≤ Fintype.card ι • ‖φ e‖₊ := Pi.sum_nnnorm_apply_le_nnnorm _ _ ≤ Fintype.card ι • (‖φ‖₊ * ‖e‖₊) := nsmul_le_nsmul_right (φ.le_opNNNorm e) _ _ = Fintype.card ι • ‖φ‖₊ * M * ‖e‖₊ := by simp only [smul_mul_assoc, mul_right_comm] theorem opNorm_le {ι : Type*} [Fintype ι] (v : Basis ι 𝕜 E) {u : E →L[𝕜] F} {M : ℝ} (hM : 0 ≤ M) (hu : ∀ i, ‖u (v i)‖ ≤ M) : ‖u‖ ≤ Fintype.card ι • ‖v.equivFunL.toContinuousLinearMap‖ * M := by simpa using NNReal.coe_le_coe.mpr (v.opNNNorm_le ⟨M, hM⟩ hu) /-- A weaker version of `Basis.opNNNorm_le` that abstracts away the value of `C`. -/ theorem exists_opNNNorm_le {ι : Type*} [Finite ι] (v : Basis ι 𝕜 E) : ∃ C > (0 : ℝ≥0), ∀ {u : E →L[𝕜] F} (M : ℝ≥0), (∀ i, ‖u (v i)‖₊ ≤ M) → ‖u‖₊ ≤ C * M := by cases nonempty_fintype ι exact ⟨max (Fintype.card ι • ‖v.equivFunL.toContinuousLinearMap‖₊) 1, zero_lt_one.trans_le (le_max_right _ _), fun {u} M hu => (v.opNNNorm_le M hu).trans <| mul_le_mul_of_nonneg_right (le_max_left _ _) (zero_le M)⟩ /-- A weaker version of `Basis.opNorm_le` that abstracts away the value of `C`. -/ theorem exists_opNorm_le {ι : Type*} [Finite ι] (v : Basis ι 𝕜 E) : ∃ C > (0 : ℝ), ∀ {u : E →L[𝕜] F} {M : ℝ}, 0 ≤ M → (∀ i, ‖u (v i)‖ ≤ M) → ‖u‖ ≤ C * M := by obtain ⟨C, hC, h⟩ := v.exists_opNNNorm_le (F := F) refine ⟨C, hC, ?_⟩ intro u M hM H simpa using h ⟨M, hM⟩ H end Module.Basis instance [FiniteDimensional 𝕜 E] [SecondCountableTopology F] : SecondCountableTopology (E →L[𝕜] F) := by set d := Module.finrank 𝕜 E suffices ∀ ε > (0 : ℝ), ∃ n : (E →L[𝕜] F) → Fin d → ℕ, ∀ f g : E →L[𝕜] F, n f = n g → dist f g ≤ ε from Metric.secondCountable_of_countable_discretization fun ε ε_pos => ⟨Fin d → ℕ, by infer_instance, this ε ε_pos⟩ intro ε ε_pos obtain ⟨u : ℕ → F, hu : DenseRange u⟩ := exists_dense_seq F let v := Module.finBasis 𝕜 E obtain ⟨C : ℝ, C_pos : 0 < C, hC : ∀ {φ : E →L[𝕜] F} {M : ℝ}, 0 ≤ M → (∀ i, ‖φ (v i)‖ ≤ M) → ‖φ‖ ≤ C * M⟩ := v.exists_opNorm_le (E := E) (F := F) have h_2C : 0 < 2 * C := mul_pos zero_lt_two C_pos have hε2C : 0 < ε / (2 * C) := div_pos ε_pos h_2C have : ∀ φ : E →L[𝕜] F, ∃ n : Fin d → ℕ, ‖φ - (v.constrL <| u ∘ n)‖ ≤ ε / 2 := by intro φ have : ∀ i, ∃ n, ‖φ (v i) - u n‖ ≤ ε / (2 * C) := by simp only [norm_sub_rev] intro i have : φ (v i) ∈ closure (range u) := hu _ obtain ⟨n, hn⟩ : ∃ n, ‖u n - φ (v i)‖ < ε / (2 * C) := by rw [mem_closure_iff_nhds_basis Metric.nhds_basis_ball] at this specialize this (ε / (2 * C)) hε2C simpa [dist_eq_norm] exact ⟨n, le_of_lt hn⟩ choose n hn using this use n replace hn : ∀ i : Fin d, ‖(φ - (v.constrL <| u ∘ n)) (v i)‖ ≤ ε / (2 * C) := by simp [hn] have : C * (ε / (2 * C)) = ε / 2 := by rw [eq_div_iff (two_ne_zero : (2 : ℝ) ≠ 0), mul_comm, ← mul_assoc, mul_div_cancel₀ _ (ne_of_gt h_2C)] specialize hC (le_of_lt hε2C) hn rwa [this] at hC choose n hn using this set Φ := fun φ : E →L[𝕜] F => v.constrL <| u ∘ n φ change ∀ z, dist z (Φ z) ≤ ε / 2 at hn use n intro x y hxy calc dist x y ≤ dist x (Φ x) + dist (Φ x) y := dist_triangle _ _ _ _ = dist x (Φ x) + dist y (Φ y) := by simp [Φ, hxy, dist_comm] _ ≤ ε := by linarith [hn x, hn y] theorem AffineSubspace.closed_of_finiteDimensional {P : Type*} [MetricSpace P] [NormedAddTorsor E P] (s : AffineSubspace 𝕜 P) [FiniteDimensional 𝕜 s.direction] : IsClosed (s : Set P) := s.isClosed_direction_iff.mp s.direction.closed_of_finiteDimensional section Riesz /-- In an infinite dimensional space, given a finite number of points, one may find a point with norm at most `R` which is at distance at least `1` of all these points. -/ theorem exists_norm_le_le_norm_sub_of_finset {c : 𝕜} (hc : 1 < ‖c‖) {R : ℝ} (hR : ‖c‖ < R) (h : ¬FiniteDimensional 𝕜 E) (s : Finset E) : ∃ x : E, ‖x‖ ≤ R ∧ ∀ y ∈ s, 1 ≤ ‖y - x‖ := by let F := Submodule.span 𝕜 (s : Set E) haveI : FiniteDimensional 𝕜 F := Module.finite_def.2 ((Submodule.fg_top _).2 (Submodule.fg_def.2 ⟨s, Finset.finite_toSet _, rfl⟩)) have Fclosed : IsClosed (F : Set E) := Submodule.closed_of_finiteDimensional _ have : ∃ x, x ∉ F := by contrapose! h have : (⊤ : Submodule 𝕜 E) = F := by ext x simp [h] have : FiniteDimensional 𝕜 (⊤ : Submodule 𝕜 E) := by rwa [this] exact Module.finite_def.2 ((Submodule.fg_top _).1 (Module.finite_def.1 this)) obtain ⟨x, xR, hx⟩ : ∃ x : E, ‖x‖ ≤ R ∧ ∀ y : E, y ∈ F → 1 ≤ ‖x - y‖ := riesz_lemma_of_norm_lt hc hR Fclosed this have hx' : ∀ y : E, y ∈ F → 1 ≤ ‖y - x‖ := by intro y hy rw [← norm_neg] simpa using hx y hy exact ⟨x, xR, fun y hy => hx' _ (Submodule.subset_span hy)⟩ /-- In an infinite-dimensional normed space, there exists a sequence of points which are all bounded by `R` and at distance at least `1`. For a version not assuming `c` and `R`, see `exists_seq_norm_le_one_le_norm_sub`. -/ theorem exists_seq_norm_le_one_le_norm_sub' {c : 𝕜} (hc : 1 < ‖c‖) {R : ℝ} (hR : ‖c‖ < R) (h : ¬FiniteDimensional 𝕜 E) : ∃ f : ℕ → E, (∀ n, ‖f n‖ ≤ R) ∧ Pairwise fun m n => 1 ≤ ‖f m - f n‖ := by have : IsSymm E fun x y : E => 1 ≤ ‖x - y‖ := by constructor intro x y hxy rw [← norm_neg] simpa apply exists_seq_of_forall_finset_exists' (fun x : E => ‖x‖ ≤ R) fun (x : E) (y : E) => 1 ≤ ‖x - y‖ rintro s - exact exists_norm_le_le_norm_sub_of_finset hc hR h s theorem exists_seq_norm_le_one_le_norm_sub (h : ¬FiniteDimensional 𝕜 E) : ∃ (R : ℝ) (f : ℕ → E), 1 < R ∧ (∀ n, ‖f n‖ ≤ R) ∧ Pairwise fun m n => 1 ≤ ‖f m - f n‖ := by obtain ⟨c, hc⟩ : ∃ c : 𝕜, 1 < ‖c‖ := NormedField.exists_one_lt_norm 𝕜 have A : ‖c‖ < ‖c‖ + 1 := by linarith rcases exists_seq_norm_le_one_le_norm_sub' hc A h with ⟨f, hf⟩ exact ⟨‖c‖ + 1, f, hc.trans A, hf.1, hf.2⟩ variable (𝕜) /-- **Riesz's theorem**: if a closed ball with center zero of positive radius is compact in a vector space, then the space is finite-dimensional. -/ theorem FiniteDimensional.of_isCompact_closedBall₀ {r : ℝ} (rpos : 0 < r) (h : IsCompact (Metric.closedBall (0 : E) r)) : FiniteDimensional 𝕜 E := by by_contra hfin obtain ⟨R, f, Rgt, fle, lef⟩ : ∃ (R : ℝ) (f : ℕ → E), 1 < R ∧ (∀ n, ‖f n‖ ≤ R) ∧ Pairwise fun m n => 1 ≤ ‖f m - f n‖ := exists_seq_norm_le_one_le_norm_sub hfin have rRpos : 0 < r / R := div_pos rpos (zero_lt_one.trans Rgt) obtain ⟨c, hc⟩ : ∃ c : 𝕜, 0 < ‖c‖ ∧ ‖c‖ < r / R := NormedField.exists_norm_lt _ rRpos let g := fun n : ℕ => c • f n have A : ∀ n, g n ∈ Metric.closedBall (0 : E) r := by intro n simp only [g, norm_smul, dist_zero_right, Metric.mem_closedBall] calc ‖c‖ * ‖f n‖ ≤ r / R * R := by gcongr · exact hc.2.le · apply fle _ = r := by simp [(zero_lt_one.trans Rgt).ne'] obtain ⟨x : E, _ : x ∈ Metric.closedBall (0 : E) r, φ : ℕ → ℕ, φmono : StrictMono φ, φlim : Tendsto (g ∘ φ) atTop (𝓝 x)⟩ := h.tendsto_subseq A have B : CauchySeq (g ∘ φ) := φlim.cauchySeq obtain ⟨N, hN⟩ : ∃ N : ℕ, ∀ n : ℕ, N ≤ n → dist ((g ∘ φ) n) ((g ∘ φ) N) < ‖c‖ := Metric.cauchySeq_iff'.1 B ‖c‖ hc.1 apply lt_irrefl ‖c‖ calc ‖c‖ ≤ dist (g (φ (N + 1))) (g (φ N)) := by conv_lhs => rw [← mul_one ‖c‖] simp only [g, dist_eq_norm, ← smul_sub, norm_smul] gcongr apply lef (ne_of_gt _) exact φmono (Nat.lt_succ_self N) _ < ‖c‖ := hN (N + 1) (Nat.le_succ N) /-- **Riesz's theorem**: if a closed ball of positive radius is compact in a vector space, then the space is finite-dimensional. -/ theorem FiniteDimensional.of_isCompact_closedBall {r : ℝ} (rpos : 0 < r) {c : E} (h : IsCompact (Metric.closedBall c r)) : FiniteDimensional 𝕜 E := .of_isCompact_closedBall₀ 𝕜 rpos <| by simpa using h.vadd (-c) /-- **Riesz's theorem**: a locally compact normed vector space is finite-dimensional. -/ theorem FiniteDimensional.of_locallyCompactSpace [LocallyCompactSpace E] : FiniteDimensional 𝕜 E := let ⟨_r, rpos, hr⟩ := exists_isCompact_closedBall (0 : E) .of_isCompact_closedBall₀ 𝕜 rpos hr /-- If a function has compact support, then either the function is trivial or the space is finite-dimensional. -/ theorem HasCompactSupport.eq_zero_or_finiteDimensional {X : Type*} [TopologicalSpace X] [Zero X] [T1Space X] {f : E → X} (hf : HasCompactSupport f) (h'f : Continuous f) : f = 0 ∨ FiniteDimensional 𝕜 E := (HasCompactSupport.eq_zero_or_locallyCompactSpace_of_addGroup hf h'f).imp_right fun h ↦ -- TODO: Lean doesn't find the instance without this `have` have : LocallyCompactSpace E := h; .of_locallyCompactSpace 𝕜 /-- If a function has compact multiplicative support, then either the function is trivial or the space is finite-dimensional. -/ @[to_additive existing] theorem HasCompactMulSupport.eq_one_or_finiteDimensional {X : Type*} [TopologicalSpace X] [One X] [T1Space X] {f : E → X} (hf : HasCompactMulSupport f) (h'f : Continuous f) : f = 1 ∨ FiniteDimensional 𝕜 E := have : T1Space (Additive X) := ‹_› HasCompactSupport.eq_zero_or_finiteDimensional (X := Additive X) 𝕜 hf h'f /-- A locally compact normed vector space is proper. -/ lemma ProperSpace.of_locallyCompactSpace (𝕜 : Type*) [NontriviallyNormedField 𝕜] {E : Type*} [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] [LocallyCompactSpace E] : ProperSpace E := by rcases exists_isCompact_closedBall (0 : E) with ⟨r, rpos, hr⟩ rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩ have hC : ∀ n, IsCompact (closedBall (0 : E) (‖c‖^n * r)) := fun n ↦ by have : c ^ n ≠ 0 := pow_ne_zero _ <| fun h ↦ by simp [h, zero_le_one.not_gt] at hc simpa [_root_.smul_closedBall' this] using hr.smul (c ^ n) have hTop : Tendsto (fun n ↦ ‖c‖^n * r) atTop atTop := Tendsto.atTop_mul_const rpos (tendsto_pow_atTop_atTop_of_one_lt hc) exact .of_seq_closedBall hTop (Eventually.of_forall hC) variable (E) lemma ProperSpace.of_locallyCompact_module [Nontrivial E] [LocallyCompactSpace E] : ProperSpace 𝕜 := have : LocallyCompactSpace 𝕜 := by obtain ⟨v, hv⟩ : ∃ v : E, v ≠ 0 := exists_ne 0 let L : 𝕜 → E := fun t ↦ t • v have : IsClosedEmbedding L := isClosedEmbedding_smul_left hv apply IsClosedEmbedding.locallyCompactSpace this .of_locallyCompactSpace 𝕜 end Riesz open ContinuousLinearMap /-- Continuous linear equivalence between continuous linear functions `𝕜ⁿ → E` and `Eⁿ`. The spaces `𝕜ⁿ` and `Eⁿ` are represented as `ι → 𝕜` and `ι → E`, respectively, where `ι` is a finite type. -/ def ContinuousLinearEquiv.piRing (ι : Type*) [Fintype ι] [DecidableEq ι] : ((ι → 𝕜) →L[𝕜] E) ≃L[𝕜] ι → E := { LinearMap.toContinuousLinearMap.symm.trans (LinearEquiv.piRing 𝕜 E ι 𝕜) with continuous_toFun := by refine continuous_pi fun i => ?_ exact (ContinuousLinearMap.apply 𝕜 E (Pi.single i 1)).continuous continuous_invFun := by simp_rw [LinearEquiv.invFun_eq_symm, LinearEquiv.trans_symm, LinearEquiv.symm_symm] -- Note: added explicit type and removed `change` that tried to achieve the same refine AddMonoidHomClass.continuous_of_bound (LinearMap.toContinuousLinearMap.toLinearMap.comp (LinearEquiv.piRing 𝕜 E ι 𝕜).symm.toLinearMap) (Fintype.card ι : ℝ) fun g => ?_ rw [← nsmul_eq_mul] refine opNorm_le_bound _ (nsmul_nonneg (norm_nonneg g) (Fintype.card ι)) fun t => ?_ simp_rw [LinearMap.coe_comp, LinearEquiv.coe_toLinearMap, Function.comp_apply, LinearMap.coe_toContinuousLinearMap', LinearEquiv.piRing_symm_apply] apply le_trans (norm_sum_le _ _) rw [smul_mul_assoc] refine Finset.sum_le_card_nsmul _ _ _ fun i _ => ?_ rw [norm_smul, mul_comm] gcongr <;> apply norm_le_pi_norm } /-- A family of continuous linear maps is continuous on `s` if all its applications are. -/ theorem continuousOn_clm_apply {X : Type*} [TopologicalSpace X] [FiniteDimensional 𝕜 E] {f : X → E →L[𝕜] F} {s : Set X} : ContinuousOn f s ↔ ∀ y, ContinuousOn (fun x => f x y) s := by refine ⟨fun h y => (ContinuousLinearMap.apply 𝕜 F y).continuous.comp_continuousOn h, fun h => ?_⟩ let d := finrank 𝕜 E have hd : d = finrank 𝕜 (Fin d → 𝕜) := (finrank_fin_fun 𝕜).symm let e₁ : E ≃L[𝕜] Fin d → 𝕜 := ContinuousLinearEquiv.ofFinrankEq hd let e₂ : (E →L[𝕜] F) ≃L[𝕜] Fin d → F := (e₁.arrowCongr (1 : F ≃L[𝕜] F)).trans (ContinuousLinearEquiv.piRing (Fin d)) rw [← f.id_comp, ← e₂.symm_comp_self] exact e₂.symm.continuous.comp_continuousOn (continuousOn_pi.mpr fun i => h _) theorem continuous_clm_apply {X : Type*} [TopologicalSpace X] [FiniteDimensional 𝕜 E] {f : X → E →L[𝕜] F} : Continuous f ↔ ∀ y, Continuous (f · y) := by simp_rw [← continuousOn_univ, continuousOn_clm_apply] end CompleteField section LocallyCompactField variable (𝕜 : Type u) [NontriviallyNormedField 𝕜] (E : Type v) [NormedAddCommGroup E] [NormedSpace 𝕜 E] [LocallyCompactSpace 𝕜] /-- Any finite-dimensional vector space over a locally compact field is proper. We do not register this as an instance to avoid an instance loop when trying to prove the properness of `𝕜`, and the search for `𝕜` as an unknown metavariable. Declare the instance explicitly when needed. -/ theorem FiniteDimensional.proper [FiniteDimensional 𝕜 E] : ProperSpace E := by have : ProperSpace 𝕜 := .of_locallyCompactSpace 𝕜 set e := ContinuousLinearEquiv.ofFinrankEq (@finrank_fin_fun 𝕜 _ _ (finrank 𝕜 E)).symm exact e.symm.antilipschitz.properSpace e.symm.continuous e.symm.surjective end LocallyCompactField /- Over the real numbers, we can register the previous statement as an instance as it will not cause problems in instance resolution since the properness of `ℝ` is already known. -/ instance (priority := 900) FiniteDimensional.proper_real (E : Type u) [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] : ProperSpace E := FiniteDimensional.proper ℝ E /-- A submodule of a locally compact space over a complete field is also locally compact (and even proper). -/ instance {𝕜 E : Type*} [NontriviallyNormedField 𝕜] [CompleteSpace 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [LocallyCompactSpace E] (S : Submodule 𝕜 E) : ProperSpace S := by nontriviality E have : ProperSpace 𝕜 := .of_locallyCompact_module 𝕜 E have : FiniteDimensional 𝕜 E := .of_locallyCompactSpace 𝕜 exact FiniteDimensional.proper 𝕜 S /-- If `E` is a finite dimensional normed real vector space, `x : E`, and `s` is a neighborhood of `x` that is not equal to the whole space, then there exists a point `y ∈ frontier s` at distance `Metric.infDist x sᶜ` from `x`. See also `IsCompact.exists_mem_frontier_infDist_compl_eq_dist`. -/ theorem exists_mem_frontier_infDist_compl_eq_dist {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {x : E} {s : Set E} (hx : x ∈ s) (hs : s ≠ univ) : ∃ y ∈ frontier s, Metric.infDist x sᶜ = dist x y := by rcases Metric.exists_mem_closure_infDist_eq_dist (nonempty_compl.2 hs) x with ⟨y, hys, hyd⟩ rw [closure_compl] at hys refine ⟨y, ⟨Metric.closedBall_infDist_compl_subset_closure hx <| Metric.mem_closedBall.2 <| ge_of_eq ?_, hys⟩, hyd⟩ rwa [dist_comm] /-- If `K` is a compact set in a nontrivial real normed space and `x ∈ K`, then there exists a point `y` of the boundary of `K` at distance `Metric.infDist x Kᶜ` from `x`. See also `exists_mem_frontier_infDist_compl_eq_dist`. -/ nonrec theorem IsCompact.exists_mem_frontier_infDist_compl_eq_dist {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [Nontrivial E] {x : E} {K : Set E} (hK : IsCompact K) (hx : x ∈ K) : ∃ y ∈ frontier K, Metric.infDist x Kᶜ = dist x y := by obtain hx' | hx' : x ∈ interior K ∪ frontier K := by rw [← closure_eq_interior_union_frontier] exact subset_closure hx · rw [mem_interior_iff_mem_nhds, Metric.nhds_basis_closedBall.mem_iff] at hx' rcases hx' with ⟨r, hr₀, hrK⟩ have : FiniteDimensional ℝ E := .of_isCompact_closedBall ℝ hr₀ (hK.of_isClosed_subset Metric.isClosed_closedBall hrK) exact exists_mem_frontier_infDist_compl_eq_dist hx hK.ne_univ · refine ⟨x, hx', ?_⟩ rw [frontier_eq_closure_inter_closure] at hx' rw [Metric.infDist_zero_of_mem_closure hx'.2, dist_self] /-- In a finite dimensional vector space over `ℝ`, the series `∑ x, ‖f x‖` is unconditionally summable if and only if the series `∑ x, f x` is unconditionally summable. One implication holds in any complete normed space, while the other holds only in finite dimensional spaces. -/ theorem summable_norm_iff {α E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {f : α → E} : (Summable fun x => ‖f x‖) ↔ Summable f := by refine ⟨Summable.of_norm, fun hf ↦ ?_⟩ -- First we use a finite basis to reduce the problem to the case `E = Fin N → ℝ` suffices ∀ {N : ℕ} {g : α → Fin N → ℝ}, Summable g → Summable fun x => ‖g x‖ by obtain v := Module.finBasis ℝ E set e := v.equivFunL have H : Summable fun x => ‖e (f x)‖ := this (e.summable.2 hf) refine .of_norm_bounded (H.mul_left ↑‖(e.symm : (Fin (finrank ℝ E) → ℝ) →L[ℝ] E)‖₊) fun i ↦ ?_ simpa using (e.symm : (Fin (finrank ℝ E) → ℝ) →L[ℝ] E).le_opNorm (e <| f i) clear! E -- Now we deal with `g : α → Fin N → ℝ` intro N g hg have : ∀ i, Summable fun x => ‖g x i‖ := fun i => (Pi.summable.1 hg i).abs refine .of_norm_bounded (summable_sum fun i (_ : i ∈ Finset.univ) => this i) fun x => ?_ rw [norm_norm, pi_norm_le_iff_of_nonneg] · refine fun i => Finset.single_le_sum (f := fun i => ‖g x i‖) (fun i _ => ?_) (Finset.mem_univ i) exact norm_nonneg (g x i) · exact Finset.sum_nonneg fun _ _ => norm_nonneg _ alias ⟨_, Summable.norm⟩ := summable_norm_iff theorem summable_of_sum_range_norm_le {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {c : ℝ} {f : ℕ → E} (h : ∀ n, ∑ i ∈ Finset.range n, ‖f i‖ ≤ c) : Summable f := summable_norm_iff.mp <| summable_of_sum_range_le (fun _ ↦ norm_nonneg _) h theorem summable_of_isBigO' {ι E F : Type*} [NormedAddCommGroup E] [CompleteSpace E] [NormedAddCommGroup F] [NormedSpace ℝ F] [FiniteDimensional ℝ F] {f : ι → E} {g : ι → F} (hg : Summable g) (h : f =O[cofinite] g) : Summable f := summable_of_isBigO hg.norm h.norm_right lemma Asymptotics.IsBigO.comp_summable {ι E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] [NormedAddCommGroup F] [CompleteSpace F] {f : E → F} (hf : f =O[𝓝 0] id) {g : ι → E} (hg : Summable g) : Summable (f ∘ g) := .of_norm <| hf.comp_summable_norm hg.norm theorem summable_of_isBigO_nat' {E F : Type*} [NormedAddCommGroup E] [CompleteSpace E] [NormedAddCommGroup F] [NormedSpace ℝ F] [FiniteDimensional ℝ F] {f : ℕ → E} {g : ℕ → F} (hg : Summable g) (h : f =O[atTop] g) : Summable f := summable_of_isBigO_nat hg.norm h.norm_right theorem summable_of_isEquivalent {ι E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {f : ι → E} {g : ι → E} (hg : Summable g) (h : f ~[cofinite] g) : Summable f := hg.trans_sub (summable_of_isBigO' hg h.isLittleO.isBigO) theorem summable_of_isEquivalent_nat {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {f : ℕ → E} {g : ℕ → E} (hg : Summable g) (h : f ~[atTop] g) : Summable f := hg.trans_sub (summable_of_isBigO_nat' hg h.isLittleO.isBigO) theorem IsEquivalent.summable_iff {ι E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {f : ι → E} {g : ι → E} (h : f ~[cofinite] g) : Summable f ↔ Summable g := ⟨fun hf => summable_of_isEquivalent hf h.symm, fun hg => summable_of_isEquivalent hg h⟩ theorem IsEquivalent.summable_iff_nat {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {f : ℕ → E} {g : ℕ → E} (h : f ~[atTop] g) : Summable f ↔ Summable g := ⟨fun hf => summable_of_isEquivalent_nat hf h.symm, fun hg => summable_of_isEquivalent_nat hg h⟩
PreorderRestrict.lean
/- Copyright (c) 2024 Etienne Marion. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Etienne Marion -/ import Mathlib.MeasureTheory.MeasurableSpace.Constructions import Mathlib.Order.Restriction /-! # Measurability of the restriction function for functions indexed by a preorder We prove that the map which restricts a function `f : (i : α) → X i` to elements `≤ a` is measurable. -/ open MeasureTheory namespace Preorder variable {α : Type*} [Preorder α] {X : α → Type*} [∀ a, MeasurableSpace (X a)] @[measurability, fun_prop] theorem measurable_restrictLe (a : α) : Measurable (restrictLe (π := X) a) := Set.measurable_restrict _ @[measurability, fun_prop] theorem measurable_restrictLe₂ {a b : α} (hab : a ≤ b) : Measurable (restrictLe₂ (π := X) hab) := Set.measurable_restrict₂ _ variable [LocallyFiniteOrderBot α] @[measurability, fun_prop] theorem measurable_frestrictLe (a : α) : Measurable (frestrictLe (π := X) a) := Finset.measurable_restrict _ @[measurability, fun_prop] theorem measurable_frestrictLe₂ {a b : α} (hab : a ≤ b) : Measurable (frestrictLe₂ (π := X) hab) := Finset.measurable_restrict₂ _ end Preorder
closed_field.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 generic_quotient bigop ssralg poly. From mathcomp Require Import polydiv matrix mxpoly countalg ring_quotient. (******************************************************************************) (* A quantifier elimination for algebraically closed fields *) (* *) (* This files contains two main contributions: *) (* 1. Factory "Field_isAlgClosed" *) (* Build an algebraically closed field that enjoy quantifier elimination, *) (* as described in *) (* ``A formal quantifier elimination for algebraically closed fields'', *) (* proceedings of Calculemus 2010, by Cyril Cohen and Assia Mahboubi *) (* *) (* We construct an instance of quantifier elimination mixin, *) (* (see the ssralg library) from the theory of polynomials with coefficients *) (* in an algebraically closed field (see the polydiv library). *) (* The algebraic operations on formulae are implemented in CPS style. *) (* We provide one CPS counterpart for each operation involved in the proof *) (* of quantifier elimination. See the paper above for more details. *) (* *) (* 2. Theorems "countable_field_extension" and "countable_algebraic_closure" *) (* constructions for both simple extension and algebraic closure of *) (* countable fields, by Georges Gonthier. *) (* Note that the construction of the algebraic closure relies on the *) (* above mentioned quantifier elimination. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory. Local Open Scope ring_scope. Import Pdiv.Ring. Import PreClosedField. Module ClosedFieldQE. Section ClosedFieldQE. Variables (F : fieldType) (F_closed : GRing.closed_field_axiom F). Notation fF := (@GRing.formula F). Notation tF := (@GRing.term F). Notation qf f := (GRing.qf_form f && GRing.rformula f). Definition polyF := seq tF. Lemma qf_simpl (f : fF) : (qf f -> GRing.qf_form f) * (qf f -> GRing.rformula f). Proof. by split=> /andP[]. Qed. Notation cps T := ((T -> fF) -> fF). Definition ret T1 : T1 -> cps T1 := fun x k => k x. Arguments ret {T1} x k /. Definition bind T1 T2 (x : cps T1) (f : T1 -> cps T2) : cps T2 := fun k => x (fun x => f x k). Arguments bind {T1 T2} x f k /. Notation "''let' x <- y ; z" := (bind y (fun x => z)) (at level 99, x at level 0, z at level 200, format "'[hv' ''let' x <- y ; '/' z ']'"). Definition cpsif T (c : fF) (t : T) (e : T) : cps T := fun k => GRing.If c (k t) (k e). Arguments cpsif {T} c t e k /. Notation "''if' c1 'then' c2 'else' c3" := (cpsif c1%T c2%T c3%T) (at level 200, right associativity, format "'[hv ' ''if' c1 '/' '[' 'then' c2 ']' '/' '[' 'else' c3 ']' ']'"). Notation eval := GRing.eval. Notation rterm := GRing.rterm. Notation qf_eval := GRing.qf_eval. Fixpoint eval_poly (e : seq F) pf := if pf is c :: q then eval_poly e q * 'X + (eval e c)%:P else 0. Definition rpoly (p : polyF) := all (@rterm F) p. Definition sizeT : polyF -> cps nat := (fix loop p := if p isn't c :: q then ret 0 else 'let n <- loop q; if n is m.+1 then ret m.+2 else 'if (c == 0) then 0%N else 1%N). Definition qf_red_cps T (x : cps T) (y : _ -> T) := forall e k, qf_eval e (x k) = qf_eval e (k (y e)). Notation "x ->_ e y" := (qf_red_cps x (fun e => y)) (e name, at level 90, format "x ->_ e y"). Definition qf_cps T D (x : cps T) := forall k, (forall y, D y -> qf (k y)) -> qf (x k). Lemma qf_cps_ret T D (x : T) : D x -> qf_cps D (ret x). Proof. move=> ??; exact. Qed. Hint Resolve qf_cps_ret : core. Lemma qf_cps_bind T1 D1 T2 D2 (x : cps T1) (f : T1 -> cps T2) : qf_cps D1 x -> (forall x, D1 x -> qf_cps D2 (f x)) -> qf_cps D2 (bind x f). Proof. by move=> xP fP k kP /=; apply: xP => y ?; apply: fP. Qed. Lemma qf_cps_if T D (c : fF) (t : T) (e : T) : qf c -> D t -> D e -> qf_cps D ('if c then t else e). Proof. move=> qfc Dt De k kP /=; have [qft qfe] := (kP _ Dt, kP _ De). by do !rewrite qf_simpl //. Qed. Lemma sizeTP (pf : polyF) : sizeT pf ->_e size (eval_poly e pf). Proof. elim: pf=> [|c qf qfP /=]; first by rewrite /= size_poly0. move=> e k; rewrite size_MXaddC qfP -(size_poly_eq0 (eval_poly _ _)). by case: (size (eval_poly e qf))=> //=; case: eqP; rewrite // orbF. Qed. Lemma sizeT_qf (p : polyF) : rpoly p -> qf_cps xpredT (sizeT p). Proof. elim: p => /= [_|c p ihp /andP[rc rq]]; first exact: qf_cps_ret. apply: qf_cps_bind; first exact: ihp. move=> [|n] //= _; last exact: qf_cps_ret. by apply: qf_cps_if; rewrite //= rc. Qed. Definition isnull (p : polyF) : cps bool := 'let n <- sizeT p; ret (n == 0). Lemma isnullP (p : polyF) : isnull p ->_e (eval_poly e p == 0). Proof. by move=> e k; rewrite sizeTP size_poly_eq0. Qed. Lemma isnull_qf (p : polyF) : rpoly p -> qf_cps xpredT (isnull p). Proof. move=> rp; apply: qf_cps_bind; first exact: sizeT_qf. by move=> ? _; apply: qf_cps_ret. Qed. Definition lt_sizeT (p q : polyF) : cps bool := 'let n <- sizeT p; 'let m <- sizeT q; ret (n < m). Definition lift (p : {poly F}) := map GRing.Const p. Lemma eval_lift (e : seq F) (p : {poly F}) : eval_poly e (lift p) = p. Proof. elim/poly_ind: p => [|p c]; first by rewrite /lift polyseq0. rewrite -cons_poly_def /lift polyseq_cons /nilp. case pn0: (_ == _) => /=; last by move->; rewrite -cons_poly_def. move=> _; rewrite polyseqC. case c0: (_==_)=> /=. move: pn0; rewrite (eqP c0) size_poly_eq0; move/eqP->. by apply: val_inj=> /=; rewrite polyseq_cons // polyseq0. by rewrite mul0r add0r; apply: val_inj=> /=; rewrite polyseq_cons // /nilp pn0. Qed. Fixpoint lead_coefT p : cps tF := if p is c :: q then 'let l <- lead_coefT q; 'if (l == 0) then c else l else ret 0%T. Lemma lead_coefTP (k : tF -> fF) : (forall x e, qf_eval e (k x) = qf_eval e (k (eval e x)%:T%T)) -> forall (p : polyF) (e : seq F), qf_eval e (lead_coefT p k) = qf_eval e (k (lead_coef (eval_poly e p))%:T%T). Proof. move=> kP p e; elim: p => [|a p IHp]/= in k kP e *. by rewrite lead_coef0 kP. rewrite IHp; last by move=> *; rewrite //= -kP. rewrite GRing.eval_If /= lead_coef_eq0. case p'0: (_ == _); first by rewrite (eqP p'0) mul0r add0r lead_coefC -kP. rewrite lead_coefDl ?lead_coefMX // polyseqC size_mul ?p'0 //; last first. by rewrite -size_poly_eq0 size_polyX. rewrite size_polyX addnC /=; case: (_ == _)=> //=. by rewrite ltnS lt0n size_poly_eq0 p'0. Qed. Lemma lead_coefT_qf (p : polyF) : rpoly p -> qf_cps (@rterm _) (lead_coefT p). Proof. elim: p => [_|c q ihp //= /andP[rc rq]]; first by apply: qf_cps_ret. apply: qf_cps_bind => [|y ty]; first exact: ihp. by apply: qf_cps_if; rewrite //= ty. Qed. Fixpoint amulXnT (a : tF) (n : nat) : polyF := if n is n'.+1 then 0%T :: (amulXnT a n') else [:: a]. Lemma eval_amulXnT (a : tF) (n : nat) (e : seq F) : eval_poly e (amulXnT a n) = (eval e a)%:P * 'X^n. Proof. elim: n=> [|n] /=; first by rewrite expr0 mulr1 mul0r add0r. by move->; rewrite addr0 -mulrA -exprSr. Qed. Lemma ramulXnT: forall a n, rterm a -> rpoly (amulXnT a n). Proof. by move=> a n; elim: n a=> [a /= -> //|n ihn a ra]; apply: ihn. Qed. Fixpoint sumpT (p q : polyF) := match p, q with a :: p, b :: q => (a + b)%T :: sumpT p q | [::], q => q | p, [::] => p end. Arguments sumpT : simpl nomatch. Lemma eval_sumpT (p q : polyF) (e : seq F) : eval_poly e (sumpT p q) = (eval_poly e p) + (eval_poly e q). Proof. elim: p q => [|a p Hp] q /=; first by rewrite add0r. case: q => [|b q] /=; first by rewrite addr0. rewrite Hp mulrDl -!addrA; congr (_ + _); rewrite polyCD addrC -addrA. by congr (_ + _); rewrite addrC. Qed. Lemma rsumpT (p q : polyF) : rpoly p -> rpoly q -> rpoly (sumpT p q). Proof. elim: p q=> [|a p ihp] q rp rq //; move: rp; case/andP=> ra rp. case: q rq => [|b q]; rewrite /= ?ra ?rp //=. by case/andP=> -> rq //=; apply: ihp. Qed. Fixpoint mulpT (p q : polyF) := if p isn't a :: p then [::] else sumpT [seq (a * x)%T | x <- q] (0%T :: mulpT p q). Lemma eval_mulpT (p q : polyF) (e : seq F) : eval_poly e (mulpT p q) = (eval_poly e p) * (eval_poly e q). Proof. elim: p q=> [|a p Hp] q /=; first by rewrite mul0r. rewrite eval_sumpT /= Hp addr0 mulrDl addrC mulrAC; congr (_ + _). by elim: q=> [|b q Hq] /=; rewrite ?mulr0 // Hq polyCM mulrDr mulrA. Qed. Lemma rpoly_map_mul (t : tF) (p : polyF) (rt : rterm t) : rpoly [seq (t * x)%T | x <- p] = rpoly p. Proof. by rewrite /rpoly all_map; apply/eq_all => x; rewrite /= rt. Qed. Lemma rmulpT (p q : polyF) : rpoly p -> rpoly q -> rpoly (mulpT p q). Proof. elim: p q=> [|a p ihp] q rp rq //=; move: rp; case/andP=> ra rp /=. apply: rsumpT; last exact: ihp. by rewrite rpoly_map_mul. Qed. Definition opppT : polyF -> polyF := map (GRing.Mul (- 1%T)%T). Lemma eval_opppT (p : polyF) (e : seq F) : eval_poly e (opppT p) = - eval_poly e p. Proof. by elim: p; rewrite /= ?oppr0 // => ? ? ->; rewrite !mulNr opprD polyCN mul1r. Qed. Definition natmulpT n : polyF -> polyF := map (GRing.Mul n%:R%T). Lemma eval_natmulpT (p : polyF) (n : nat) (e : seq F) : eval_poly e (natmulpT n p) = (eval_poly e p) *+ n. Proof. elim: p; rewrite //= ?mul0rn // => c p ->. rewrite mulrnDl mulr_natl polyCMn; congr (_ + _). by rewrite -mulr_natl mulrAC -mulrA mulr_natl mulrC. Qed. Fixpoint redivp_rec_loopT (q : polyF) sq cq (c : nat) (qq r : polyF) (n : nat) {struct n} : cps (nat * polyF * polyF) := 'let sr <- sizeT r; if sr < sq then ret (c, qq, r) else 'let lr <- lead_coefT r; let m := amulXnT lr (sr - sq) in let qq1 := sumpT (mulpT qq [::cq]) m in let r1 := sumpT (mulpT r ([::cq])) (opppT (mulpT m q)) in if n is n1.+1 then redivp_rec_loopT q sq cq c.+1 qq1 r1 n1 else ret (c.+1, qq1, r1). Fixpoint redivp_rec_loop (q : {poly F}) sq cq (k : nat) (qq r : {poly F}) (n : nat) {struct n} := if size r < sq then (k, qq, r) else let m := (lead_coef r) *: 'X^(size r - sq) in let qq1 := qq * cq%:P + m in let r1 := r * cq%:P - m * q in if n is n1.+1 then redivp_rec_loop q sq cq k.+1 qq1 r1 n1 else (k.+1, qq1, r1). Lemma redivp_rec_loopTP (k : nat * polyF * polyF -> fF) : (forall c qq r e, qf_eval e (k (c,qq,r)) = qf_eval e (k (c, lift (eval_poly e qq), lift (eval_poly e r)))) -> forall q sq cq c qq r n e (d := redivp_rec_loop (eval_poly e q) sq (eval e cq) c (eval_poly e qq) (eval_poly e r) n), qf_eval e (redivp_rec_loopT q sq cq c qq r n k) = qf_eval e (k (d.1.1, lift d.1.2, lift d.2)). Proof. move=> Pk q sq cq c qq r n e /=. elim: n c qq r k Pk e => [|n Pn] c qq r k Pk e; rewrite sizeTP. case ltrq : (_ < _); first by rewrite /= ltrq /= -Pk. rewrite lead_coefTP => [|a p]; rewrite [in LHS]Pk; [|symmetry]. rewrite ?(eval_mulpT,eval_amulXnT,eval_sumpT,eval_opppT) //=. by rewrite ltrq //= !mul_polyC ?(mul0r,add0r,scale0r). by rewrite [in LHS]Pk ?(eval_mulpT,eval_amulXnT,eval_sumpT, eval_opppT). case ltrq : (_<_); first by rewrite /= ltrq Pk. rewrite lead_coefTP. rewrite Pn ?(eval_mulpT,eval_amulXnT,eval_sumpT,eval_opppT) //=. by rewrite ltrq //= !mul_polyC ?(mul0r,add0r,scale0r). rewrite -/redivp_rec_loopT => x e'. rewrite Pn; last by move=> *; rewrite Pk. symmetry; rewrite Pn; last by move=> *; rewrite Pk. rewrite Pk ?(eval_lift,eval_mulpT,eval_amulXnT,eval_sumpT,eval_opppT). by rewrite mul_polyC ?(mul0r,add0r). Qed. Lemma redivp_rec_loopT_qf (q : polyF) (sq : nat) (cq : tF) (c : nat) (qq r : polyF) (n : nat) : rpoly q -> rterm cq -> rpoly qq -> rpoly r -> qf_cps (fun x => [&& rpoly x.1.2 & rpoly x.2]) (redivp_rec_loopT q sq cq c qq r n). Proof. do ![move=>x/(pair x){x}] => rw; elim: n => [|n IHn]//= in q sq cq c qq r rw *; apply: qf_cps_bind; do ?[by apply: sizeT_qf; rewrite !rw] => sr _; case: ifPn => // _; do ?[by apply: qf_cps_ret; rewrite //= ?rw]; apply: qf_cps_bind; do ?[by apply: lead_coefT_qf; rewrite !rw] => lr /= rlr; [apply: qf_cps_ret|apply: IHn]; by do !rewrite ?(rsumpT,rmulpT,ramulXnT,rpoly_map_mul,rlr,rw) //=. Qed. Definition redivpT (p : polyF) (q : polyF) : cps (nat * polyF * polyF) := 'let b <- isnull q; if b then ret (0, [::0%T], p) else 'let sq <- sizeT q; 'let sp <- sizeT p; 'let lq <- lead_coefT q; redivp_rec_loopT q sq lq 0 [::0%T] p sp. Lemma redivp_rec_loopP (q : {poly F}) (c : nat) (qq r : {poly F}) (n : nat) : redivp_rec q c qq r n = redivp_rec_loop q (size q) (lead_coef q) c qq r n. Proof. by elim: n c qq r => [| n Pn] c qq r //=; rewrite Pn. Qed. Lemma redivpTP (k : nat * polyF * polyF -> fF) : (forall c qq r e, qf_eval e (k (c,qq,r)) = qf_eval e (k (c, lift (eval_poly e qq), lift (eval_poly e r)))) -> forall p q e (d := redivp (eval_poly e p) (eval_poly e q)), qf_eval e (redivpT p q k) = qf_eval e (k (d.1.1, lift d.1.2, lift d.2)). Proof. move=> Pk p q e /=; rewrite isnullP unlock /=. case q0 : (eval_poly e q == 0) => /=; first by rewrite Pk /= mul0r add0r polyC0. rewrite !sizeTP lead_coefTP /=; last by move=> *; rewrite !redivp_rec_loopTP. rewrite redivp_rec_loopTP /=; last by move=> *; rewrite Pk. by rewrite mul0r add0r polyC0 redivp_rec_loopP. Qed. Lemma redivpT_qf (p : polyF) (q : polyF) : rpoly p -> rpoly q -> qf_cps (fun x => [&& rpoly x.1.2 & rpoly x.2]) (redivpT p q). Proof. move=> rp rq; apply: qf_cps_bind => [|[] _]; first exact: isnull_qf. by apply: qf_cps_ret. apply: qf_cps_bind => [|sp _]; first exact: sizeT_qf. apply: qf_cps_bind => [|sq _]; first exact: sizeT_qf. apply: qf_cps_bind => [|lq rlq]; first exact: lead_coefT_qf. by apply: redivp_rec_loopT_qf => //=. Qed. Definition rmodpT (p : polyF) (q : polyF) : cps polyF := 'let d <- redivpT p q; ret d.2. Definition rdivpT (p : polyF) (q : polyF) : cps polyF := 'let d <- redivpT p q; ret d.1.2. Definition rscalpT (p : polyF) (q : polyF) : cps nat := 'let d <- redivpT p q; ret d.1.1. Definition rdvdpT (p : polyF) (q : polyF) : cps bool := 'let d <- rmodpT p q; isnull d. Fixpoint rgcdp_loop n (pp qq : {poly F}) {struct n} := let rr := rmodp pp qq in if rr == 0 then qq else if n is n1.+1 then rgcdp_loop n1 qq rr else rr. Fixpoint rgcdp_loopT n (pp : polyF) (qq : polyF) : cps polyF := 'let rr <- rmodpT pp qq; 'let nrr <- isnull rr; if nrr then ret qq else if n is n1.+1 then rgcdp_loopT n1 qq rr else ret rr. Lemma rgcdp_loopP (k : polyF -> fF) : (forall p e, qf_eval e (k p) = qf_eval e (k (lift (eval_poly e p)))) -> forall n p q e, qf_eval e (rgcdp_loopT n p q k) = qf_eval e (k (lift (rgcdp_loop n (eval_poly e p) (eval_poly e q)))). Proof. move=> Pk n p q e; elim: n => /= [| m IHm] in p q e *; rewrite redivpTP /==> *; rewrite ?isnullP ?eval_lift -/(rmodp _ _); by case: (_ == _); do ?by rewrite -?Pk ?IHm ?eval_lift. Qed. Lemma rgcdp_loopT_qf (n : nat) (p : polyF) (q : polyF) : rpoly p -> rpoly q -> qf_cps rpoly (rgcdp_loopT n p q). Proof. elim: n => [|n IHn] in p q * => rp rq /=; (apply: qf_cps_bind=> [|rr rrr]; [ apply: qf_cps_bind => [|[[a u] v]]; do ?exact: redivpT_qf; by move=> /andP[/= ??]; apply: (@qf_cps_ret _ rpoly)| apply: qf_cps_bind => [|[] _]; by [apply: isnull_qf|apply: qf_cps_ret|apply: IHn]]). Qed. Definition rgcdpT (p : polyF) (q : polyF) : cps polyF := let aux p1 q1 : cps polyF := 'let b <- isnull p1; if b then ret q1 else 'let n <- sizeT p1; rgcdp_loopT n p1 q1 in 'let b <- lt_sizeT p q; if b then aux q p else aux p q. Lemma rgcdpTP (k : polyF -> fF) : (forall p e, qf_eval e (k p) = qf_eval e (k (lift (eval_poly e p)))) -> forall p q e, qf_eval e (rgcdpT p q k) = qf_eval e (k (lift (rgcdp (eval_poly e p) (eval_poly e q)))). Proof. move=> Pk p q e; rewrite /rgcdpT /rgcdp !sizeTP /=. case: (_ < _); rewrite !isnullP /=; case: (_ == _); rewrite -?Pk ?sizeTP; by rewrite ?rgcdp_loopP. Qed. Lemma rgcdpT_qf (p : polyF) (q : polyF) : rpoly p -> rpoly q -> qf_cps rpoly (rgcdpT p q). Proof. move=> rp rq k kP; rewrite /rgcdpT /=; do ![rewrite sizeT_qf => // ? _]. case: (_ < _); rewrite ?isnull_qf // => -[]; rewrite ?kP // => _; by rewrite sizeT_qf => // ? _; rewrite rgcdp_loopT_qf. Qed. Fixpoint rgcdpTs (ps : seq polyF) : cps polyF := if ps is p :: pr then 'let pr <- rgcdpTs pr; rgcdpT p pr else ret [::0%T]. Lemma rgcdpTsP (k : polyF -> fF) : (forall p e, qf_eval e (k p) = qf_eval e (k (lift (eval_poly e p)))) -> forall ps e, qf_eval e (rgcdpTs ps k) = qf_eval e (k (lift (\big[@rgcdp _/0%:P]_(i <- ps)(eval_poly e i)))). Proof. move=> Pk ps e; elim: ps k Pk => [|p ps Pps] /= k Pk. by rewrite /= big_nil Pk /= mul0r add0r. by rewrite big_cons Pps => *; rewrite !rgcdpTP // !eval_lift -?Pk. Qed. Lemma rgcdpTs_qf (ps : seq polyF) : all rpoly ps -> qf_cps rpoly (rgcdpTs ps). Proof. elim: ps => [_|c p ihp /andP[rc rp]] //=; first exact: qf_cps_ret. by apply: qf_cps_bind => [|r rr]; [apply: ihp|apply: rgcdpT_qf]. Qed. Fixpoint rgdcop_recT n (q : polyF) (p : polyF) := if n is m.+1 then 'let g <- rgcdpT p q; 'let sg <- sizeT g; if sg == 1 then ret p else 'let r <- rdivpT p g; rgdcop_recT m q r else 'let b <- isnull q; ret [::b%:R%T]. Lemma rgdcop_recTP (k : polyF -> fF) : (forall p e, qf_eval e (k p) = qf_eval e (k (lift (eval_poly e p)))) -> forall p q n e, qf_eval e (rgdcop_recT n p q k) = qf_eval e (k (lift (rgdcop_rec (eval_poly e p) (eval_poly e q) n))). Proof. move=> Pk p q n e; elim: n => [|n Pn] /= in k Pk p q e *. rewrite isnullP /=. by case: (_ == _); rewrite Pk /= mul0r add0r ?(polyC0, polyC1). rewrite /rcoprimep rgcdpTP ?sizeTP ?eval_lift => * /=. case: (_ == _); by do ?[rewrite /= ?(=^~Pk, redivpTP, rgcdpTP, sizeTP, Pn, eval_lift) //==> *]. do ?[rewrite /= ?(=^~Pk, redivpTP, rgcdpTP, sizeTP, Pn, eval_lift) //==> *]. case: (_ == _); by do ?[rewrite /= ?(=^~Pk, redivpTP, rgcdpTP, sizeTP, Pn, eval_lift) //==> *]. Qed. Lemma rgdcop_recT_qf (n : nat) (p : polyF) (q : polyF) : rpoly p -> rpoly q -> qf_cps rpoly (rgdcop_recT n p q). Proof. elim: n => [|n ihn] in p q * => k kP rp rq /=. by rewrite isnull_qf => //*; rewrite rq. rewrite rgcdpT_qf=> //*; rewrite sizeT_qf=> //*. case: (_ == _); rewrite ?kP ?rq //= redivpT_qf=> //= ? /andP[??]. by rewrite ihn. Qed. Definition rgdcopT q p := 'let sp <- sizeT p; rgdcop_recT sp q p. Lemma rgdcopTP (k : polyF -> fF) : (forall p e, qf_eval e (k p) = qf_eval e (k (lift (eval_poly e p)))) -> forall p q e, qf_eval e (rgdcopT p q k) = qf_eval e (k (lift (rgdcop (eval_poly e p) (eval_poly e q)))). Proof. by move=> *; rewrite sizeTP rgdcop_recTP 1?Pk. Qed. Lemma rgdcopT_qf (p : polyF) (q : polyF) : rpoly p -> rpoly q -> qf_cps rpoly (rgdcopT p q). Proof. by move=> rp rq k kP; rewrite sizeT_qf => //*; rewrite rgdcop_recT_qf. Qed. Definition ex_elim_seq (ps : seq polyF) (q : polyF) : fF := ('let g <- rgcdpTs ps; 'let d <- rgdcopT q g; 'let n <- sizeT d; ret (n != 1)) GRing.Bool. Lemma ex_elim_seqP (ps : seq polyF) (q : polyF) (e : seq F) : let gp := (\big[@rgcdp _/0%:P]_(p <- ps)(eval_poly e p)) in qf_eval e (ex_elim_seq ps q) = (size (rgdcop (eval_poly e q) gp) != 1). Proof. by do ![rewrite (rgcdpTsP,rgdcopTP,sizeTP,eval_lift) //= | move=> * //=]. Qed. Lemma ex_elim_seq_qf (ps : seq polyF) (q : polyF) : all rpoly ps -> rpoly q -> qf (ex_elim_seq ps q). Proof. move=> rps rq; apply: rgcdpTs_qf=> // g rg; apply: rgdcopT_qf=> // d rd. exact : sizeT_qf. Qed. Fixpoint abstrX (i : nat) (t : tF) := match t with | 'X_n => if n == i then [::0; 1] else [::t] | - x => opppT (abstrX i x) | x + y => sumpT (abstrX i x) (abstrX i y) | x * y => mulpT (abstrX i x) (abstrX i y) | x *+ n => natmulpT n (abstrX i x) | x ^+ n => let ax := (abstrX i x) in iter n (mulpT ax) [::1] | _ => [::t] end%T. Lemma abstrXP (i : nat) (t : tF) (e : seq F) (x : F) : rterm t -> (eval_poly e (abstrX i t)).[x] = eval (set_nth 0 e i x) t. Proof. elim: t => [n | r | n | t tP s sP | t tP | t tP n | t tP s sP | t tP | t tP n] h. - move=> /=; case ni: (_ == _); rewrite //= ?(mul0r,add0r,addr0,polyC1,mul1r,hornerX,hornerC); by rewrite // nth_set_nth /= ni. - by rewrite /= mul0r add0r hornerC. - by rewrite /= mul0r add0r hornerC. - by case/andP: h => *; rewrite /= eval_sumpT hornerD tP ?sP. - by rewrite /= eval_opppT hornerN tP. - by rewrite /= eval_natmulpT hornerMn tP. - by case/andP: h => *; rewrite /= eval_mulpT hornerM tP ?sP. - by []. - elim: n h => [|n ihn] rt; first by rewrite /= expr0 mul0r add0r hornerC. by rewrite /= eval_mulpT exprSr hornerM ihn // mulrC tP. Qed. Lemma rabstrX (i : nat) (t : tF) : rterm t -> rpoly (abstrX i t). Proof. elim: t; do ?[ by move=> * //=; do ?case: (_ == _)]. - move=> t irt s irs /=; case/andP=> rt rs. by apply: rsumpT; rewrite ?irt ?irs //. - by move=> t irt /= rt; rewrite rpoly_map_mul ?irt //. - by move=> t irt /= n rt; rewrite rpoly_map_mul ?irt //. - move=> t irt s irs /=; case/andP=> rt rs. by apply: rmulpT; rewrite ?irt ?irs //. - move=> t irt /= n rt; move: (irt rt) => {}rt; elim: n => [|n ihn] //=. exact: rmulpT. Qed. Implicit Types tx ty : tF. Lemma abstrX_mulM (i : nat) : {morph abstrX i : x y / x * y >-> mulpT x y}%T. Proof. by []. Qed. Lemma abstrX1 (i : nat) : abstrX i 1%T = [::1%T]. Proof. done. Qed. Lemma eval_poly_mulM e : {morph eval_poly e : x y / mulpT x y >-> x * y}. Proof. by move=> x y; rewrite eval_mulpT. Qed. Lemma eval_poly1 e : eval_poly e [::1%T] = 1. Proof. by rewrite /= mul0r add0r. Qed. Notation abstrX_bigmul := (big_morph _ (abstrX_mulM _) (abstrX1 _)). Notation eval_bigmul := (big_morph _ (eval_poly_mulM _) (eval_poly1 _)). Notation bigmap_id := (big_map _ (fun _ => true) id). Lemma rseq_poly_map (x : nat) (ts : seq tF) : all (@rterm _) ts -> all rpoly (map (abstrX x) ts). Proof. by elim: ts => //= t ts iht; case/andP=> rt rts; rewrite rabstrX // iht. Qed. Definition ex_elim (x : nat) (pqs : seq tF * seq tF) := ex_elim_seq (map (abstrX x) pqs.1) (abstrX x (\big[GRing.Mul/1%T]_(q <- pqs.2) q)). Lemma ex_elim_qf (x : nat) (pqs : seq tF * seq tF) : GRing.dnf_rterm pqs -> qf (ex_elim x pqs). case: pqs => ps qs; case/andP=> /= rps rqs. apply: ex_elim_seq_qf; first exact: rseq_poly_map. apply: rabstrX=> /=. elim: qs rqs=> [|t ts iht] //=; first by rewrite big_nil. by case/andP=> rt rts; rewrite big_cons /= rt /= iht. Qed. Lemma holds_conj : forall e i x ps, all (@rterm _) ps -> (GRing.holds (set_nth 0 e i x) (foldr (fun t : tF => GRing.And (t == 0)) GRing.True%T ps) <-> all ((@root _)^~ x) (map (eval_poly e \o abstrX i) ps)). Proof. move=> e i x; elim=> [|p ps ihps] //=. case/andP=> rp rps; rewrite rootE abstrXP //. constructor; first by case=> -> hps; rewrite eqxx /=; apply/ihps. by case/andP; move/eqP=> -> psr; split=> //; apply/ihps. Qed. Lemma holds_conjn (e : seq F) (i : nat) (x : F) (ps : seq tF) : all (@rterm _) ps -> (GRing.holds (set_nth 0 e i x) (foldr (fun t : tF => GRing.And (t != 0)) GRing.True ps) <-> all (fun p => ~~root p x) (map (eval_poly e \o abstrX i) ps)). Proof. elim: ps => [|p ps ihps] //=. case/andP=> rp rps; rewrite rootE abstrXP //. constructor; first by case=> /eqP-> hps /=; apply/ihps. by case/andP=> pr psr; split; first apply/eqP=> //; apply/ihps. Qed. Lemma holds_ex_elim: GRing.valid_QE_proj ex_elim. Proof. move=> i [ps qs] /= e; case/andP=> /= rps rqs. rewrite ex_elim_seqP big_map. have -> : \big[@rgcdp _/0%:P]_(j <- ps) eval_poly e (abstrX i j) = \big[@rgcdp _/0%:P]_(j <- (map (eval_poly e) (map (abstrX i) (ps)))) j. by rewrite !big_map. rewrite -!map_comp. have aux I (l : seq I) (P : I -> {poly F}) : \big[(@gcdp F)/0]_(j <- l) P j %= \big[(@rgcdp F)/0]_(j <- l) P j. elim: l => [| u l ihl] /=; first by rewrite !big_nil eqpxx. rewrite !big_cons; move: ihl; move/(eqp_gcdr (P u)) => h. by apply: eqp_trans h _; rewrite eqp_sym; apply: eqp_rgcd_gcd. case g0: (\big[(@rgcdp F)/0%:P]_(j <- map (eval_poly e \o abstrX i) ps) j == 0). rewrite (eqP g0) rgdcop0. case m0 : (_ == 0)=> //=; rewrite ?(size_poly1,size_poly0) //=. rewrite abstrX_bigmul eval_bigmul -bigmap_id in m0. constructor=> [[x] // []] //. case=> _; move/holds_conjn=> hc; move/hc:rqs. by rewrite -root_bigmul //= (eqP m0) root0. constructor; move/negP:m0; move/negP=>m0. case: (closed_nonrootP F_closed _ m0) => x {m0}. rewrite abstrX_bigmul eval_bigmul -bigmap_id root_bigmul=> m0. exists x; do 2?constructor=> //; last by apply/holds_conjn. apply/holds_conj; rewrite //= -root_biggcd. by rewrite (eqp_root (aux _ _ _ )) (eqP g0) root0. apply: (iffP (closed_rootP F_closed _)) => -[x Px]; exists x; move: Px => //=. rewrite (eqp_root (@eqp_rgdco_gdco F _ _)) root_gdco ?g0 //. rewrite -(eqp_root (aux _ _ _ )) root_biggcd abstrX_bigmul eval_bigmul. rewrite -bigmap_id root_bigmul; case/andP=> psr qsr. do 2?constructor; first by apply/holds_conj. by apply/holds_conjn. rewrite (eqp_root(@eqp_rgdco_gdco F _ _)) root_gdco?g0// -(eqp_root(aux _ _ _)). rewrite root_biggcd abstrX_bigmul eval_bigmul -bigmap_id. rewrite root_bigmul=> [[] // [hps hqs]]; apply/andP. constructor; first by apply/holds_conj. by apply/holds_conjn. Qed. Lemma wf_ex_elim : GRing.wf_QE_proj ex_elim. Proof. by move=> i bc /= rbc; apply: ex_elim_qf. Qed. End ClosedFieldQE. End ClosedFieldQE. HB.factory Record Field_isAlgClosed F of GRing.Field F := { solve_monicpoly : GRing.closed_field_axiom F; }. HB.builders Context F of Field_isAlgClosed F. HB.instance Definition _ := GRing.Field_QE_isDecField.Build F (@ClosedFieldQE.wf_ex_elim F) (ClosedFieldQE.holds_ex_elim solve_monicpoly). HB.instance Definition _ := GRing.DecField_isAlgClosed.Build F solve_monicpoly. HB.end. Import CodeSeq. Lemma countable_field_extension (F : countFieldType) (p : {poly F}) : size p > 1 -> {E : countFieldType & {FtoE : {rmorphism F -> E} & {w : E | root (map_poly FtoE p) w & forall u : E, exists q, u = (map_poly FtoE q).[w]}}}. Proof. pose fix d i := if i is i1.+1 then let d1 := oapp (gcdp (d i1)) 0 (unpickle i1) in if size d1 > 1 then d1 else d i1 else p. move=> p_gt1; have sz_d i: size (d i) > 1 by elim: i => //= i IHi; case: ifP. have dv_d i j: i <= j -> d j %| d i. move/subnK <-; elim: {j}(j - i)%N => //= j IHj; case: ifP => //=. case: (unpickle _) => /= [q _|]; last by rewrite size_poly0. exact: dvdp_trans (dvdp_gcdl _ _) IHj. pose I : pred {poly F} := [pred q | d (pickle q).+1 %| q]. have I'co q i: q \notin I -> i > pickle q -> coprimep q (d i). rewrite inE => I'q /dv_d/coprimep_dvdl-> //; apply: contraR I'q. rewrite coprimep_sym /coprimep /= pickleK /= neq_ltn. case: ifP => [_ _| ->]; first exact: dvdp_gcdr. rewrite orbF ltnS leqn0 size_poly_eq0 gcdp_eq0 -size_poly_eq0. by rewrite -leqn0 leqNgt ltnW //. have memI q: reflect (exists i, d i %| q) (q \in I). apply: (iffP idP) => [|[i dv_di_q]]; first by exists (pickle q).+1. have [le_i_q | /I'co i_co_q] := leqP i (pickle q). rewrite inE /= pickleK /=; case: ifP => _; first exact: dvdp_gcdr. exact: dvdp_trans (dv_d _ _ le_i_q) dv_di_q. apply: contraR i_co_q _. by rewrite /coprimep (eqp_size (dvdp_gcd_idr dv_di_q)) neq_ltn sz_d orbT. have I_ideal : idealr_closed I. split=> [||a q1 q2 Iq1 Iq2]; first exact: dvdp0. by apply/memI=> [[i /idPn[]]]; rewrite dvdp1 neq_ltn sz_d orbT. apply/memI; exists (maxn (pickle q1).+1 (pickle q2).+1); apply: dvdp_add. by apply: dvdp_mull; apply: dvdp_trans Iq1; apply/dv_d/leq_maxl. by apply: dvdp_trans Iq2; apply/dv_d/leq_maxr. pose IaM := GRing.isZmodClosed.Build _ I (idealr_closedB I_ideal). pose IpM := isProperIdeal.Build _ I (idealr_closed_nontrivial I_ideal). pose Iid : idealr _ := HB.pack I IaM IpM. pose E : comNzRingType := {ideal_quot Iid}. pose PtoE : {rmorphism {poly F} -> E} := \pi_E%qT. have PtoEd i: PtoE (d i) = 0. by apply/eqP; rewrite piE Quotient.equivE subr0; apply/memI; exists i. pose Einv (z : E) (q := repr z) (dq := d (pickle q).+1) := let q_unitP := Bezout_eq1_coprimepP q dq in if q_unitP is ReflectT ex_uv then PtoE (sval (sig_eqW ex_uv)).1 else 0. have Einv0 : Einv 0 = 0. rewrite /Einv; case: Bezout_eq1_coprimepP => // ex_uv. case/negP: (oner_neq0 E); rewrite [X in X == _]piE. rewrite /= -[_ 1]/(PtoE 1); have [uv <-] := ex_uv. by rewrite rmorphD !rmorphM [X in _ + _ * X]PtoEd /= reprK !mulr0 addr0. have EmulV : forall x, x != 0 -> Einv x * x = 1. rewrite /Einv=> z nz_z; case: Bezout_eq1_coprimepP => [ex_uv |]; last first. move/Bezout_eq1_coprimepP; rewrite I'co //. by rewrite piE -{1}[z]reprK -Quotient.idealrBE subr0 in nz_z. apply/eqP; case: sig_eqW => {ex_uv} [uv uv1]; set i := _.+1 in uv1 *. rewrite piE /= -[z]reprK -(rmorphM PtoE) -Quotient.idealrBE. rewrite -[X in _ - X]uv1 opprD addNKr -mulNr. by apply/memI; exists i; apply: dvdp_mull. pose EfieldMixin := GRing.ComNzRing_isField.Build _ EmulV Einv0. pose Efield : fieldType := HB.pack E EfieldMixin. pose EIsCountable := isCountable.Build E (pcan_pickleK (can_pcan (reprK))). pose Ecount : countFieldType := HB.pack E Efield EIsCountable. pose FtoE : {rmorphism _ -> _} := PtoE \o polyC; pose w : E := PtoE 'X. have defPtoE q: (map_poly FtoE q).[w] = PtoE q. by rewrite (map_poly_comp PtoE polyC) horner_map [_.['X]]comp_polyXr. exists Ecount, FtoE, w => [|u]. by rewrite /root defPtoE (PtoEd 0). by exists (repr u); rewrite defPtoE /= reprK. Qed. Lemma countable_algebraic_closure (F : countFieldType) : {K : countClosedFieldType & {FtoK : {rmorphism F -> K} | integralRange FtoK}}. Proof. pose minXp (R : nzRingType) (p : {poly R}) := if size p > 1 then p else 'X. have minXp_gt1 R p: size (minXp R p) > 1. by rewrite /minXp; case: ifP => // _; rewrite size_polyX. have minXpE (R : nzRingType) (p : {poly R}) : size p > 1 -> minXp R p = p. by rewrite /minXp => ->. have ext1 p := countable_field_extension (minXp_gt1 _ p). pose ext1fT E p := tag (ext1 E p). pose ext1to E p : {rmorphism _ -> ext1fT E p} := tag (tagged (ext1 E p)). pose ext1w E p : ext1fT E p := s2val (tagged (tagged (ext1 E p))). have ext1root E p: root (map_poly (ext1to E p) (minXp E p)) (ext1w E p). by rewrite /ext1w; case: (tagged (tagged (ext1 E p))). have ext1gen E p u: {q | u = (map_poly (ext1to E p) q).[ext1w E p]}. by apply: sig_eqW; rewrite /ext1w; case: (tagged (tagged (ext1 E p))) u. pose pExtEnum (E : countFieldType) := nat -> {poly E}. pose Ext := {E : countFieldType & pExtEnum E}; pose MkExt : Ext := Tagged _ _. pose EtoInc (E : Ext) i := ext1to (tag E) (tagged E i). pose incEp E i j := let v := map_poly (EtoInc E i) (tagged E j) in if decode j is [:: i1; k] then if i1 == i then odflt v (unpickle k) else v else v. pose fix E_ i := if i is i1.+1 then MkExt _ (incEp (E_ i1) i1) else MkExt F \0. pose E i := tag (E_ i); pose Krep := {i : nat & E i}. pose fix toEadd i k : {rmorphism E i -> E (k + i)%N} := if k isn't k1.+1 then idfun else EtoInc _ (k1 + i)%N \o toEadd _ _. pose toE i j (le_ij : i <= j) := ecast j {rmorphism E i -> E j} (subnK le_ij) (toEadd i (j - i)%N). have toEeq i le_ii: toE i i le_ii =1 id. by rewrite /toE; move: (subnK _); rewrite subnn => ?; rewrite eq_axiomK. have toEleS i j leij leiSj z: toE i j.+1 leiSj z = EtoInc _ _ (toE i j leij z). rewrite /toE; move: (j - i)%N {leij leiSj}(subnK _) (subnK _) => k. by case: j /; rewrite (addnK i k.+1) => eq_kk; rewrite [eq_kk]eq_axiomK. have toEirr := congr1 ((toE _ _)^~ _) (bool_irrelevance _ _). have toEtrans j i k leij lejk leik z: toE i k leik z = toE j k lejk (toE i j leij z). - elim: k leik lejk => [|k IHk] leiSk lejSk. by case: j => // in leij lejSk *; rewrite toEeq. have:= lejSk; rewrite {1}leq_eqVlt ltnS => /predU1P[Dk | lejk]. by rewrite -Dk in leiSk lejSk *; rewrite toEeq. by have leik := leq_trans leij lejk; rewrite !toEleS -IHk. have [leMl leMr] := (leq_maxl, leq_maxr); pose le_max := (leq_max, leqnn, orbT). pose pairK (x y : Krep) (m := maxn _ _) := (toE _ m (leMl _ _) (tagged x), toE _ m (leMr _ _) (tagged y)). pose eqKrep x y := uncurry (@eq_op _) (pairK x y). have eqKrefl : reflexive eqKrep by move=> z; apply/eqP; apply: toEirr. have eqKsym : symmetric eqKrep. move=> z1 z2; rewrite {1}/eqKrep /= eq_sym; move: (leMl _ _) (leMr _ _). by rewrite maxnC => lez1m lez2m; congr (_ == _); apply: toEirr. have eqKtrans : transitive eqKrep. rewrite /eqKrep /= => z2 z1 z3 /eqP eq_z12 /eqP eq_z23. rewrite -(inj_eq (fmorph_inj (toE _ _ (leMr (tag z2) _)))). rewrite -!toEtrans ?le_max // maxnCA maxnA => lez3m lez1m. rewrite {lez1m}(toEtrans (maxn (tag z1) (tag z2))) // {}eq_z12. do [rewrite -toEtrans ?le_max // -maxnA => lez2m] in lez3m *. by rewrite (toEtrans (maxn (tag z2) (tag z3))) // eq_z23 -toEtrans. pose K := {eq_quot EquivRel _ eqKrefl eqKsym eqKtrans}%qT. pose cntK := isCountable.Build K (pcan_pickleK (can_pcan (reprK))). pose EtoKrep i (x : E i) : K := \pi%qT (Tagged E x). have [EtoK piEtoK]: {EtoK | forall i, EtoKrep i =1 EtoK i} by exists EtoKrep. pose FtoK := EtoK 0; rewrite {}/EtoKrep in piEtoK. have eqEtoK i j x y: toE i _ (leMl i j) x = toE j _ (leMr i j) y -> EtoK i x = EtoK j y. - by move/eqP=> eq_xy; rewrite -!piEtoK; apply/eqmodP. have toEtoK j i leij x : EtoK j (toE i j leij x) = EtoK i x. by apply: eqEtoK; rewrite -toEtrans. have EtoK_0 i: EtoK i 0 = FtoK 0 by apply: eqEtoK; rewrite !rmorph0. have EtoK_1 i: EtoK i 1 = FtoK 1 by apply: eqEtoK; rewrite !rmorph1. have EtoKeq0 i x: (EtoK i x == FtoK 0) = (x == 0). by rewrite /FtoK -!piEtoK eqmodE /= /eqKrep /= rmorph0 fmorph_eq0. have toErepr m i leim x lerm: toE _ m lerm (tagged (repr (EtoK i x))) = toE i m leim x. - have: (Tagged E x == repr (EtoK i x) %[mod K])%qT by rewrite reprK piEtoK. rewrite eqmodE /= /eqKrep; case: (repr _) => j y /= in lerm * => /eqP /=. have leijm: maxn i j <= m by rewrite geq_max leim. by move/(congr1 (toE _ _ leijm)); rewrite -!toEtrans. pose Kadd (x y : K) := EtoK _ (uncurry +%R (pairK (repr x) (repr y))). pose Kopp (x : K) := EtoK _ (- tagged (repr x)). pose Kmul (x y : K) := EtoK _ (uncurry *%R (pairK (repr x) (repr y))). pose Kinv (x : K) := EtoK _ (tagged (repr x))^-1. have EtoK_D i: {morph EtoK i : x y / x + y >-> Kadd x y}. move=> x y; apply: eqEtoK; set j := maxn (tag _) _; rewrite !rmorphD. rewrite -![X in _ = X + _]toEtrans ?le_max// => lexm. rewrite -![X in _ = _ + X]toEtrans ?le_max// => leym. by rewrite !toErepr. have EtoK_N i: {morph EtoK i : x / - x >-> Kopp x}. by move=> x; apply: eqEtoK; set j := tag _; rewrite !rmorphN toErepr. have EtoK_M i: {morph EtoK i : x y / x * y >-> Kmul x y}. move=> x y; apply: eqEtoK; set j := maxn (tag _) _; rewrite !rmorphM. rewrite -![X in _ = X * _]toEtrans ?le_max// => lexm. rewrite -![X in _ = _ * X]toEtrans ?le_max// => leym. by rewrite !toErepr. have EtoK_V i: {morph EtoK i : x / x^-1 >-> Kinv x}. by move=> x; apply: eqEtoK; set j := tag _; rewrite !fmorphV toErepr. case: {toErepr}I in (Kadd) (Kopp) (Kmul) (Kinv) EtoK_D EtoK_N EtoK_M EtoK_V. pose inEi i z := {x : E i | z = EtoK i x}; have KtoE z: {i : nat & inEi i z}. by elim/quotW: z => [[i x] /=]; exists i, x; rewrite piEtoK. have inEle i j z: i <= j -> inEi i z -> inEi j z. by move=> leij [x ->]; exists (toE i j leij x); rewrite toEtoK. have KtoE2 z1 z2: {i : nat & inEi i z1 & inEi i z2}. have [[i1 Ez1] [i2 Ez2]] := (KtoE z1, KtoE z2). by exists (maxn i1 i2); [apply: inEle Ez1 | apply: inEle Ez2]. have KtoE3 z1 z2 z3: {i : nat & inEi i z1 & inEi i z2 * inEi i z3}%type. have [[i1 Ez1] [i2 Ez2 Ez3]] := (KtoE z1, KtoE2 z2 z3). by exists (maxn i1 i2); [apply: inEle Ez1 | split; apply: inEle (leMr _ _) _]. have KaddC: commutative Kadd. by move=> u v; have [i [x ->] [y ->]] := KtoE2 u v; rewrite -!EtoK_D addrC. have KaddA: associative Kadd. move=> u v w; have [i [x ->] [[y ->] [z ->]]] := KtoE3 u v w. by rewrite -!EtoK_D addrA. have Kadd0: left_id (FtoK 0) Kadd. by move=> u; have [i [x ->]] := KtoE u; rewrite -(EtoK_0 i) -EtoK_D add0r. have KaddN: left_inverse (FtoK 0) Kopp Kadd. by move=> u; have [i [x ->]] := KtoE u; rewrite -EtoK_N -EtoK_D addNr EtoK_0. pose KzmodMixin := GRing.isZmodule.Build K KaddA KaddC Kadd0 KaddN. pose Kzmod : countZmodType := HB.pack K KzmodMixin. have KmulC: commutative Kmul. by move=> u v; have [i [x ->] [y ->]] := KtoE2 u v; rewrite -!EtoK_M mulrC. have KmulA: @associative Kzmod Kmul. move=> u v w; have [i [x ->] [[y ->] [z ->]]] := KtoE3 u v w. by rewrite -!EtoK_M mulrA. have Kmul1: left_id (FtoK 1) Kmul. by move=> u; have [i [x ->]] := KtoE u; rewrite -(EtoK_1 i) -EtoK_M mul1r. have KmulD: left_distributive Kmul Kadd. move=> u v w; have [i [x ->] [[y ->] [z ->]]] := KtoE3 u v w. by rewrite -!(EtoK_M, EtoK_D) mulrDl. have Kone_nz: FtoK 1 != FtoK 0 by rewrite EtoKeq0 oner_neq0. pose KringMixin := GRing.Zmodule_isComNzRing.Build _ KmulA KmulC Kmul1 KmulD Kone_nz. pose Kring : comNzRingType := HB.pack K Kzmod KringMixin cntK. have KmulV: forall x : Kring, x != 0 -> (Kinv x : Kring) * x = 1. move=> u; have [i [x ->]] := KtoE u; rewrite EtoKeq0 => nz_x. by rewrite -EtoK_V -[_ * _]EtoK_M mulVf ?EtoK_1. have Kinv0: Kinv (FtoK 0) = FtoK 0 by rewrite -EtoK_V invr0. pose KfieldMixin := GRing.ComNzRing_isField.Build _ KmulV Kinv0. pose Kfield : fieldType := HB.pack K Kring KfieldMixin. have EtoKAdd i : zmod_morphism (EtoK i : E i -> Kfield). by move=> x y; rewrite EtoK_D EtoK_N. have EtoKMul i : monoid_morphism (EtoK i : E i -> Kfield). by split=> [|x y]; rewrite ?EtoK_M ?EtoK_1. pose EtoKMa i := GRing.isZmodMorphism.Build _ _ _ (EtoKAdd i). pose EtoKMm i := GRing.isMonoidMorphism.Build _ _ _ (EtoKMul i). pose EtoKM i : {rmorphism _ -> _} := HB.pack (EtoK i : E i -> Kfield) (EtoKMa i) (EtoKMm i). have EtoK_E: EtoK _ = EtoKM _ by []. have toEtoKp := @eq_map_poly _ Kring _ _(toEtoK _ _ _). have Kclosed: GRing.closed_field_axiom Kfield. move=> n pK n_gt0; pose m0 := \max_(i < n) tag (KtoE (pK i)); pose m := m0.+1. have /fin_all_exists[pE DpE] (i : 'I_n): exists y, EtoK m y = pK i. pose u := KtoE (pK i); have leum0: tag u <= m0 by rewrite (bigmax_sup i). by have [y ->] := tagged u; exists (toE _ _ (leqW leum0) y); rewrite toEtoK. pose p := 'X^n - rVpoly (\row_i pE i); pose j := code [:: m0; pickle p]. pose pj := tagged (E_ j) j; pose w : E j.+1 := ext1w (E j) pj. have lemj: m <= j by rewrite (allP (ltn_code _)) ?mem_head. exists (EtoKM j.+1 w); apply/eqP; rewrite -subr_eq0; apply/eqP. transitivity (EtoKM j.+1 (map_poly (toE m j.+1 (leqW lemj)) p).[w]). rewrite -horner_map -map_poly_comp toEtoKp EtoK_E. move: (EtoKM j.+1 w) => {}w. rewrite rmorphB [_ 'X^n]map_polyXn !hornerE; congr (_ - _ : Kring). rewrite (@horner_coef_wide _ n) ?size_map_poly ?size_poly //. by apply: eq_bigr => i _; rewrite coef_map coef_rVpoly valK mxE /= DpE. suffices Dpj: map_poly (toE m j lemj) p = pj. apply/eqP; rewrite EtoKeq0 (eq_map_poly (toEleS _ _ _ _)) map_poly_comp Dpj. rewrite -rootE -[pj]minXpE ?ext1root // -Dpj size_map_poly. by rewrite size_polyDl ?size_polyXn ltnS ?size_polyN ?size_poly. rewrite {w}/pj; set j0 := (j in tagged (E_ _) j). elim: {+}j lemj => // k IHk lemSk; rewrite {}/j0 in IHk *. have:= lemSk; rewrite leq_eqVlt ltnS => /predU1P[Dm | lemk]. rewrite -{}Dm in lemSk *; rewrite {k IHk lemSk}(eq_map_poly (toEeq m _)). by rewrite map_poly_id //= /incEp codeK eqxx pickleK. rewrite (eq_map_poly (toEleS _ _ _ _)) map_poly_comp {}IHk //= /incEp codeK. by rewrite -if_neg neq_ltn lemk. suffices{Kclosed} algF_K: {FtoK : {rmorphism F -> Kfield} | integralRange FtoK}. pose Kcc := Field_isAlgClosed.Build Kfield Kclosed. by exists (HB.pack_for countClosedFieldType K Kfield Kcc). exists (EtoKM 0) => /= z; have [i [{}z ->]] := KtoE z. suffices{z} /(_ z)[p mon_p]: integralRange (toE 0 i isT). by rewrite -(fmorph_root (EtoKM i)) -map_poly_comp toEtoKp; exists p. rewrite /toE /E; clear - minXp_gt1 ext1root ext1gen. move: (i - 0)%N (subnK _) => n; case: i /. elim: n => [|n IHn] /= z; first exact: integral_id. have{z} [q ->] := ext1gen _ _ z; set pn := tagged (E_ _) _. apply: integral_horner. by apply/integral_poly=> i; rewrite coef_map; apply: integral_rmorph. apply: integral_root (ext1root _ _) _. by rewrite map_poly_eq0 -size_poly_gt0 ltnW. by apply/integral_poly=> i; rewrite coef_map; apply: integral_rmorph. Qed.
Adjugate.lean
/- Copyright (c) 2019 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Algebra.Regular.Basic import Mathlib.LinearAlgebra.Matrix.MvPolynomial import Mathlib.LinearAlgebra.Matrix.Polynomial /-! # Cramer's rule and adjugate matrices The adjugate matrix is the transpose of the cofactor matrix. It is calculated with Cramer's rule, which we introduce first. The vectors returned by Cramer's rule are given by the linear map `cramer`, which sends a matrix `A` and vector `b` to the vector consisting of the determinant of replacing the `i`th column of `A` with `b` at index `i` (written as `(A.update_column i b).det`). Using Cramer's rule, we can compute for each matrix `A` the matrix `adjugate A`. The entries of the adjugate are the minors of `A`. Instead of defining a minor by deleting row `i` and column `j` of `A`, we replace the `i`th row of `A` with the `j`th basis vector; the resulting matrix has the same determinant but more importantly equals Cramer's rule applied to `A` and the `j`th basis vector, simplifying the subsequent proofs. We prove the adjugate behaves like `det A • A⁻¹`. ## Main definitions * `Matrix.cramer A b`: the vector output by Cramer's rule on `A` and `b`. * `Matrix.adjugate A`: the adjugate (or classical adjoint) of the matrix `A`. ## References * https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix ## Tags cramer, cramer's rule, adjugate -/ namespace Matrix universe u v w variable {m : Type u} {n : Type v} {α : Type w} variable [DecidableEq n] [Fintype n] [DecidableEq m] [Fintype m] [CommRing α] open Matrix Polynomial Equiv Equiv.Perm Finset section Cramer /-! ### `cramer` section Introduce the linear map `cramer` with values defined by `cramerMap`. After defining `cramerMap` and showing it is linear, we will restrict our proofs to using `cramer`. -/ variable (A : Matrix n n α) (b : n → α) /-- `cramerMap A b i` is the determinant of the matrix `A` with column `i` replaced with `b`, and thus `cramerMap A b` is the vector output by Cramer's rule on `A` and `b`. If `A * x = b` has a unique solution in `x`, `cramerMap A` sends the vector `b` to `A.det • x`. Otherwise, the outcome of `cramerMap` is well-defined but not necessarily useful. -/ def cramerMap (i : n) : α := (A.updateCol i b).det theorem cramerMap_is_linear (i : n) : IsLinearMap α fun b => cramerMap A b i := { map_add := det_updateCol_add _ _ map_smul := det_updateCol_smul _ _ } theorem cramer_is_linear : IsLinearMap α (cramerMap A) := by constructor <;> intros <;> ext i · apply (cramerMap_is_linear A i).1 · apply (cramerMap_is_linear A i).2 /-- `cramer A b i` is the determinant of the matrix `A` with column `i` replaced with `b`, and thus `cramer A b` is the vector output by Cramer's rule on `A` and `b`. If `A * x = b` has a unique solution in `x`, `cramer A` sends the vector `b` to `A.det • x`. Otherwise, the outcome of `cramer` is well-defined but not necessarily useful. -/ def cramer (A : Matrix n n α) : (n → α) →ₗ[α] (n → α) := IsLinearMap.mk' (cramerMap A) (cramer_is_linear A) theorem cramer_apply (i : n) : cramer A b i = (A.updateCol i b).det := rfl theorem cramer_transpose_apply (i : n) : cramer Aᵀ b i = (A.updateRow i b).det := by rw [cramer_apply, updateCol_transpose, det_transpose] theorem cramer_transpose_row_self (i : n) : Aᵀ.cramer (A i) = Pi.single i A.det := by ext j rw [cramer_apply, Pi.single_apply] split_ifs with h · -- i = j: this entry should be `A.det` subst h simp only [updateCol_transpose, det_transpose, updateRow_eq_self] · -- i ≠ j: this entry should be 0 rw [updateCol_transpose, det_transpose] apply det_zero_of_row_eq h rw [updateRow_self, updateRow_ne (Ne.symm h)] theorem cramer_row_self (i : n) (h : ∀ j, b j = A j i) : A.cramer b = Pi.single i A.det := by rw [← transpose_transpose A, det_transpose] convert cramer_transpose_row_self Aᵀ i exact funext h @[simp] theorem cramer_one : cramer (1 : Matrix n n α) = 1 := by ext i j convert congr_fun (cramer_row_self (1 : Matrix n n α) (Pi.single i 1) i _) j · simp · intro j rw [Matrix.one_eq_pi_single, Pi.single_comm] theorem cramer_smul (r : α) (A : Matrix n n α) : cramer (r • A) = r ^ (Fintype.card n - 1) • cramer A := LinearMap.ext fun _ => funext fun _ => det_updateCol_smul_left _ _ _ _ @[simp] theorem cramer_subsingleton_apply [Subsingleton n] (A : Matrix n n α) (b : n → α) (i : n) : cramer A b i = b i := by rw [cramer_apply, det_eq_elem_of_subsingleton _ i, updateCol_self] theorem cramer_zero [Nontrivial n] : cramer (0 : Matrix n n α) = 0 := by ext i j obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := exists_ne j apply det_eq_zero_of_column_eq_zero j' intro j'' simp [updateCol_ne hj'] /-- Use linearity of `cramer` to take it out of a summation. -/ theorem sum_cramer {β} (s : Finset β) (f : β → n → α) : (∑ x ∈ s, cramer A (f x)) = cramer A (∑ x ∈ s, f x) := (map_sum (cramer A) ..).symm /-- Use linearity of `cramer` and vector evaluation to take `cramer A _ i` out of a summation. -/ theorem sum_cramer_apply {β} (s : Finset β) (f : n → β → α) (i : n) : (∑ x ∈ s, cramer A (fun j => f j x) i) = cramer A (fun j : n => ∑ x ∈ s, f j x) i := calc (∑ x ∈ s, cramer A (fun j => f j x) i) = (∑ x ∈ s, cramer A fun j => f j x) i := (Finset.sum_apply i s _).symm _ = cramer A (fun j : n => ∑ x ∈ s, f j x) i := by rw [sum_cramer, cramer_apply, cramer_apply] simp only [updateCol] congr with j congr apply Finset.sum_apply theorem cramer_submatrix_equiv (A : Matrix m m α) (e : n ≃ m) (b : n → α) : cramer (A.submatrix e e) b = cramer A (b ∘ e.symm) ∘ e := by ext i simp_rw [Function.comp_apply, cramer_apply, updateCol_submatrix_equiv, det_submatrix_equiv_self e, Function.comp_def] theorem cramer_reindex (e : m ≃ n) (A : Matrix m m α) (b : n → α) : cramer (reindex e e A) b = cramer A (b ∘ e) ∘ e.symm := cramer_submatrix_equiv _ _ _ end Cramer section Adjugate /-! ### `adjugate` section Define the `adjugate` matrix and a few equations. These will hold for any matrix over a commutative ring. -/ /-- The adjugate matrix is the transpose of the cofactor matrix. Typically, the cofactor matrix is defined by taking minors, i.e. the determinant of the matrix with a row and column removed. However, the proof of `mul_adjugate` becomes a lot easier if we use the matrix replacing a column with a basis vector, since it allows us to use facts about the `cramer` map. -/ def adjugate (A : Matrix n n α) : Matrix n n α := of fun i => cramer Aᵀ (Pi.single i 1) theorem adjugate_def (A : Matrix n n α) : adjugate A = of fun i => cramer Aᵀ (Pi.single i 1) := rfl theorem adjugate_apply (A : Matrix n n α) (i j : n) : adjugate A i j = (A.updateRow j (Pi.single i 1)).det := by rw [adjugate_def, of_apply, cramer_apply, updateCol_transpose, det_transpose] theorem adjugate_transpose (A : Matrix n n α) : (adjugate A)ᵀ = adjugate Aᵀ := by ext i j rw [transpose_apply, adjugate_apply, adjugate_apply, updateRow_transpose, det_transpose] rw [det_apply', det_apply'] apply Finset.sum_congr rfl intro σ _ congr 1 by_cases h : i = σ j · -- Everything except `(i , j)` (= `(σ j , j)`) is given by A, and the rest is a single `1`. congr ext j' subst h have : σ j' = σ j ↔ j' = j := σ.injective.eq_iff rw [updateRow_apply, updateCol_apply] simp_rw [this] rw [← dite_eq_ite, ← dite_eq_ite] congr 1 with rfl rw [Pi.single_eq_same, Pi.single_eq_same] · -- Otherwise, we need to show that there is a `0` somewhere in the product. have : (∏ j' : n, updateCol A j (Pi.single i 1) (σ j') j') = 0 := by apply prod_eq_zero (mem_univ j) rw [updateCol_self, Pi.single_eq_of_ne' h] rw [this] apply prod_eq_zero (mem_univ (σ⁻¹ i)) erw [apply_symm_apply σ i, updateRow_self] apply Pi.single_eq_of_ne intro h' exact h ((symm_apply_eq σ).mp h') @[simp] theorem adjugate_submatrix_equiv_self (e : n ≃ m) (A : Matrix m m α) : adjugate (A.submatrix e e) = (adjugate A).submatrix e e := by ext i j have : (fun j ↦ Pi.single i 1 <| e.symm j) = Pi.single (e i) 1 := Function.update_comp_equiv (0 : n → α) e.symm i 1 rw [adjugate_apply, submatrix_apply, adjugate_apply, ← det_submatrix_equiv_self e, updateRow_submatrix_equiv, this] theorem adjugate_reindex (e : m ≃ n) (A : Matrix m m α) : adjugate (reindex e e A) = reindex e e (adjugate A) := adjugate_submatrix_equiv_self _ _ /-- Since the map `b ↦ cramer A b` is linear in `b`, it must be multiplication by some matrix. This matrix is `A.adjugate`. -/ theorem cramer_eq_adjugate_mulVec (A : Matrix n n α) (b : n → α) : cramer A b = A.adjugate *ᵥ b := by nth_rw 2 [← A.transpose_transpose] rw [← adjugate_transpose, adjugate_def] have : b = ∑ i, b i • (Pi.single i 1 : n → α) := by refine (pi_eq_sum_univ b).trans ?_ congr with j simp [Pi.single_apply, eq_comm] conv_lhs => rw [this] ext k simp [mulVec, dotProduct, mul_comm] theorem mul_adjugate_apply (A : Matrix n n α) (i j k) : A i k * adjugate A k j = cramer Aᵀ (Pi.single k (A i k)) j := by rw [← smul_eq_mul, adjugate, of_apply, ← Pi.smul_apply, ← LinearMap.map_smul, ← Pi.single_smul', smul_eq_mul, mul_one] theorem mul_adjugate (A : Matrix n n α) : A * adjugate A = A.det • (1 : Matrix n n α) := by ext i j rw [mul_apply, Pi.smul_apply, Pi.smul_apply, one_apply, smul_eq_mul, mul_boole] simp [mul_adjugate_apply, sum_cramer_apply, cramer_transpose_row_self, Pi.single_apply, eq_comm] theorem adjugate_mul (A : Matrix n n α) : adjugate A * A = A.det • (1 : Matrix n n α) := calc adjugate A * A = (Aᵀ * adjugate Aᵀ)ᵀ := by rw [← adjugate_transpose, ← transpose_mul, transpose_transpose] _ = _ := by rw [mul_adjugate Aᵀ, det_transpose, transpose_smul, transpose_one] theorem adjugate_smul (r : α) (A : Matrix n n α) : adjugate (r • A) = r ^ (Fintype.card n - 1) • adjugate A := by rw [adjugate, adjugate, transpose_smul, cramer_smul] rfl /-- A stronger form of **Cramer's rule** that allows us to solve some instances of `A * x = b` even if the determinant is not a unit. A sufficient (but still not necessary) condition is that `A.det` divides `b`. -/ @[simp] theorem mulVec_cramer (A : Matrix n n α) (b : n → α) : A *ᵥ cramer A b = A.det • b := by rw [cramer_eq_adjugate_mulVec, mulVec_mulVec, mul_adjugate, smul_mulVec, one_mulVec] theorem adjugate_subsingleton [Subsingleton n] (A : Matrix n n α) : adjugate A = 1 := by ext i j simp [Subsingleton.elim i j, adjugate_apply, det_eq_elem_of_subsingleton _ i, one_apply] theorem adjugate_eq_one_of_card_eq_one {A : Matrix n n α} (h : Fintype.card n = 1) : adjugate A = 1 := haveI : Subsingleton n := Fintype.card_le_one_iff_subsingleton.mp h.le adjugate_subsingleton _ @[simp] theorem adjugate_zero [Nontrivial n] : adjugate (0 : Matrix n n α) = 0 := by ext i j obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := exists_ne j apply det_eq_zero_of_column_eq_zero j' intro j'' simp [updateCol_ne hj'] @[simp] theorem adjugate_one : adjugate (1 : Matrix n n α) = 1 := by ext simp [adjugate_def, Matrix.one_apply, Pi.single_apply, eq_comm] @[simp] theorem adjugate_diagonal (v : n → α) : adjugate (diagonal v) = diagonal fun i => ∏ j ∈ Finset.univ.erase i, v j := by ext i j simp only [adjugate_def, cramer_apply, diagonal_transpose, of_apply] obtain rfl | hij := eq_or_ne i j · rw [diagonal_apply_eq, diagonal_updateCol_single, det_diagonal, prod_update_of_mem (Finset.mem_univ _), sdiff_singleton_eq_erase, one_mul] · rw [diagonal_apply_ne _ hij] refine det_eq_zero_of_row_eq_zero j fun k => ?_ obtain rfl | hjk := eq_or_ne k j · rw [updateCol_self, Pi.single_eq_of_ne' hij] · rw [updateCol_ne hjk, diagonal_apply_ne' _ hjk] theorem _root_.RingHom.map_adjugate {R S : Type*} [CommRing R] [CommRing S] (f : R →+* S) (M : Matrix n n R) : f.mapMatrix M.adjugate = Matrix.adjugate (f.mapMatrix M) := by ext i k have : Pi.single i (1 : S) = f ∘ Pi.single i 1 := by rw [← f.map_one] exact Pi.single_op (fun _ => f) (fun _ => f.map_zero) i (1 : R) rw [adjugate_apply, RingHom.mapMatrix_apply, map_apply, RingHom.mapMatrix_apply, this, ← map_updateRow, ← RingHom.mapMatrix_apply, ← RingHom.map_det, ← adjugate_apply] theorem _root_.AlgHom.map_adjugate {R A B : Type*} [CommSemiring R] [CommRing A] [CommRing B] [Algebra R A] [Algebra R B] (f : A →ₐ[R] B) (M : Matrix n n A) : f.mapMatrix M.adjugate = Matrix.adjugate (f.mapMatrix M) := f.toRingHom.map_adjugate _ theorem det_adjugate (A : Matrix n n α) : (adjugate A).det = A.det ^ (Fintype.card n - 1) := by -- get rid of the `- 1` rcases (Fintype.card n).eq_zero_or_pos with h_card | h_card · haveI : IsEmpty n := Fintype.card_eq_zero_iff.mp h_card rw [h_card, Nat.zero_sub, pow_zero, adjugate_subsingleton, det_one] replace h_card := tsub_add_cancel_of_le h_card.nat_succ_le -- express `A` as an evaluation of a polynomial in n^2 variables, and solve in the polynomial ring -- where `A'.det` is non-zero. let A' := mvPolynomialX n n ℤ suffices A'.adjugate.det = A'.det ^ (Fintype.card n - 1) by rw [← mvPolynomialX_mapMatrix_aeval ℤ A, ← AlgHom.map_adjugate, ← AlgHom.map_det, ← AlgHom.map_det, ← map_pow, this] apply mul_left_cancel₀ (show A'.det ≠ 0 from det_mvPolynomialX_ne_zero n ℤ) calc A'.det * A'.adjugate.det = (A' * adjugate A').det := (det_mul _ _).symm _ = A'.det ^ Fintype.card n := by rw [mul_adjugate, det_smul, det_one, mul_one] _ = A'.det * A'.det ^ (Fintype.card n - 1) := by rw [← pow_succ', h_card] @[simp] theorem adjugate_fin_zero (A : Matrix (Fin 0) (Fin 0) α) : adjugate A = 0 := Subsingleton.elim _ _ @[simp] theorem adjugate_fin_one (A : Matrix (Fin 1) (Fin 1) α) : adjugate A = 1 := adjugate_subsingleton A theorem adjugate_fin_succ_eq_det_submatrix {n : ℕ} (A : Matrix (Fin n.succ) (Fin n.succ) α) (i j) : adjugate A i j = (-1) ^ (j + i : ℕ) * det (A.submatrix j.succAbove i.succAbove) := by simp_rw [adjugate_apply, det_succ_row _ j, updateRow_self, submatrix_updateRow_succAbove] rw [Fintype.sum_eq_single i fun h hjk => ?_, Pi.single_eq_same, mul_one] rw [Pi.single_eq_of_ne hjk, mul_zero, zero_mul] theorem adjugate_fin_two (A : Matrix (Fin 2) (Fin 2) α) : adjugate A = !![A 1 1, -A 0 1; -A 1 0, A 0 0] := by ext i j rw [adjugate_fin_succ_eq_det_submatrix] fin_cases i <;> fin_cases j <;> simp @[simp] theorem adjugate_fin_two_of (a b c d : α) : adjugate !![a, b; c, d] = !![d, -b; -c, a] := adjugate_fin_two _ theorem adjugate_fin_three (A : Matrix (Fin 3) (Fin 3) α) : adjugate A = !![A 1 1 * A 2 2 - A 1 2 * A 2 1, -(A 0 1 * A 2 2) + A 0 2 * A 2 1, A 0 1 * A 1 2 - A 0 2 * A 1 1; -(A 1 0 * A 2 2) + A 1 2 * A 2 0, A 0 0 * A 2 2 - A 0 2 * A 2 0, -(A 0 0 * A 1 2) + A 0 2 * A 1 0; A 1 0 * A 2 1 - A 1 1 * A 2 0, -(A 0 0 * A 2 1) + A 0 1 * A 2 0, A 0 0 * A 1 1 - A 0 1 * A 1 0] := by ext i j rw [adjugate_fin_succ_eq_det_submatrix, det_fin_two] fin_cases i <;> fin_cases j <;> simp [Fin.succAbove, Fin.lt_def] <;> ring @[simp] theorem adjugate_fin_three_of (a b c d e f g h i : α) : adjugate !![a, b, c; d, e, f; g, h, i] = !![ e * i - f * h, -(b * i) + c * h, b * f - c * e; -(d * i) + f * g, a * i - c * g, -(a * f) + c * d; d * h - e * g, -(a * h) + b * g, a * e - b * d] := adjugate_fin_three _ theorem det_eq_sum_mul_adjugate_row (A : Matrix n n α) (i : n) : det A = ∑ j : n, A i j * adjugate A j i := by haveI : Nonempty n := ⟨i⟩ obtain ⟨n', hn'⟩ := Nat.exists_eq_succ_of_ne_zero (Fintype.card_ne_zero : Fintype.card n ≠ 0) obtain ⟨e⟩ := Fintype.truncEquivFinOfCardEq hn' let A' := reindex e e A suffices det A' = ∑ j : Fin n'.succ, A' (e i) j * adjugate A' j (e i) by simp_rw [A', det_reindex_self, adjugate_reindex, reindex_apply, submatrix_apply, ← e.sum_comp, Equiv.symm_apply_apply] at this exact this rw [det_succ_row A' (e i)] simp_rw [mul_assoc, mul_left_comm _ (A' _ _), ← adjugate_fin_succ_eq_det_submatrix] theorem det_eq_sum_mul_adjugate_col (A : Matrix n n α) (j : n) : det A = ∑ i : n, A i j * adjugate A j i := by simpa only [det_transpose, ← adjugate_transpose] using det_eq_sum_mul_adjugate_row Aᵀ j theorem adjugate_conjTranspose [StarRing α] (A : Matrix n n α) : A.adjugateᴴ = adjugate Aᴴ := by dsimp only [conjTranspose] have : Aᵀ.adjugate.map star = adjugate (Aᵀ.map star) := (starRingEnd α).map_adjugate Aᵀ rw [A.adjugate_transpose, this] theorem isRegular_of_isLeftRegular_det {A : Matrix n n α} (hA : IsLeftRegular A.det) : IsRegular A := by constructor · intro B C h refine hA.matrix ?_ simp only at h ⊢ rw [← Matrix.one_mul B, ← Matrix.one_mul C, ← Matrix.smul_mul, ← Matrix.smul_mul, ← adjugate_mul, Matrix.mul_assoc, Matrix.mul_assoc, h] · intro B C (h : B * A = C * A) refine hA.matrix ?_ simp only rw [← Matrix.mul_one B, ← Matrix.mul_one C, ← Matrix.mul_smul, ← Matrix.mul_smul, ← mul_adjugate, ← Matrix.mul_assoc, ← Matrix.mul_assoc, h] theorem adjugate_mul_distrib_aux (A B : Matrix n n α) (hA : IsLeftRegular A.det) (hB : IsLeftRegular B.det) : adjugate (A * B) = adjugate B * adjugate A := by have hAB : IsLeftRegular (A * B).det := by rw [det_mul] exact hA.mul hB refine (isRegular_of_isLeftRegular_det hAB).left ?_ simp only rw [mul_adjugate, Matrix.mul_assoc, ← Matrix.mul_assoc B, mul_adjugate, smul_mul, Matrix.one_mul, mul_smul, mul_adjugate, smul_smul, mul_comm, ← det_mul] /-- Proof follows from "The trace Cayley-Hamilton theorem" by Darij Grinberg, Section 5.3 -/ theorem adjugate_mul_distrib (A B : Matrix n n α) : adjugate (A * B) = adjugate B * adjugate A := by let g : Matrix n n α → Matrix n n α[X] := fun M => M.map Polynomial.C + (Polynomial.X : α[X]) • (1 : Matrix n n α[X]) let f' : Matrix n n α[X] →+* Matrix n n α := (Polynomial.evalRingHom 0).mapMatrix have f'_inv : ∀ M, f' (g M) = M := by intro ext simp [f', g] have f'_adj : ∀ M : Matrix n n α, f' (adjugate (g M)) = adjugate M := by intro rw [RingHom.map_adjugate, f'_inv] have f'_g_mul : ∀ M N : Matrix n n α, f' (g M * g N) = M * N := by intros M N rw [RingHom.map_mul, f'_inv, f'_inv] have hu : ∀ M : Matrix n n α, IsRegular (g M).det := by intro M refine Polynomial.Monic.isRegular ?_ simp only [g, Polynomial.Monic.def, ← Polynomial.leadingCoeff_det_X_one_add_C M, add_comm] rw [← f'_adj, ← f'_adj, ← f'_adj, ← f'.map_mul, ← adjugate_mul_distrib_aux _ _ (hu A).left (hu B).left, RingHom.map_adjugate, RingHom.map_adjugate, f'_inv, f'_g_mul] @[simp] theorem adjugate_pow (A : Matrix n n α) (k : ℕ) : adjugate (A ^ k) = adjugate A ^ k := by induction k with | zero => simp | succ k IH => rw [pow_succ', adjugate_mul_distrib, IH, pow_succ] theorem det_smul_adjugate_adjugate (A : Matrix n n α) : det A • adjugate (adjugate A) = det A ^ (Fintype.card n - 1) • A := by have : A * (A.adjugate * A.adjugate.adjugate) = A * (A.det ^ (Fintype.card n - 1) • (1 : Matrix n n α)) := by rw [← adjugate_mul_distrib, adjugate_mul, adjugate_smul, adjugate_one] rwa [← Matrix.mul_assoc, mul_adjugate, Matrix.mul_smul, Matrix.mul_one, Matrix.smul_mul, Matrix.one_mul] at this /-- Note that this is not true for `Fintype.card n = 1` since `1 - 2 = 0` and not `-1`. -/ theorem adjugate_adjugate (A : Matrix n n α) (h : Fintype.card n ≠ 1) : adjugate (adjugate A) = det A ^ (Fintype.card n - 2) • A := by -- get rid of the `- 2` rcases h_card : Fintype.card n with _ | n' · subsingleton [Fintype.card_eq_zero_iff.mp h_card] cases n' · exact (h h_card).elim rw [← h_card] -- express `A` as an evaluation of a polynomial in n^2 variables, and solve in the polynomial ring -- where `A'.det` is non-zero. let A' := mvPolynomialX n n ℤ suffices adjugate (adjugate A') = det A' ^ (Fintype.card n - 2) • A' by rw [← mvPolynomialX_mapMatrix_aeval ℤ A, ← AlgHom.map_adjugate, ← AlgHom.map_adjugate, this, ← AlgHom.map_det, ← map_pow (MvPolynomial.aeval fun p : n × n ↦ A p.1 p.2), AlgHom.mapMatrix_apply, AlgHom.mapMatrix_apply, Matrix.map_smul' _ _ _ (map_mul _)] have h_card' : Fintype.card n - 2 + 1 = Fintype.card n - 1 := by simp [h_card] have is_reg : IsSMulRegular (MvPolynomial (n × n) ℤ) (det A') := fun x y => mul_left_cancel₀ (det_mvPolynomialX_ne_zero n ℤ) apply is_reg.matrix simp only rw [smul_smul, ← pow_succ', h_card', det_smul_adjugate_adjugate] /-- A weaker version of `Matrix.adjugate_adjugate` that uses `Nontrivial`. -/ theorem adjugate_adjugate' (A : Matrix n n α) [Nontrivial n] : adjugate (adjugate A) = det A ^ (Fintype.card n - 2) • A := adjugate_adjugate _ <| Fintype.one_lt_card.ne' end Adjugate end Matrix
Derivation.lean
/- Copyright (c) 2023 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Richard M. Hill -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Algebra.Polynomial.Module.AEval import Mathlib.RingTheory.Adjoin.Polynomial import Mathlib.RingTheory.Derivation.Basic /-! # Derivations of univariate polynomials In this file we prove that an `R`-derivation of `Polynomial R` is determined by its value on `X`. We also provide a constructor `Polynomial.mkDerivation` that builds a derivation from its value on `X`, and a linear equivalence `Polynomial.mkDerivationEquiv` between `A` and `Derivation (Polynomial R) A`. -/ noncomputable section namespace Polynomial section CommSemiring variable {R A : Type*} [CommSemiring R] /-- `Polynomial.derivative` as a derivation. -/ @[simps] def derivative' : Derivation R R[X] R[X] where toFun := derivative map_add' _ _ := derivative_add map_smul' := derivative_smul map_one_eq_zero' := derivative_one leibniz' f g := by simp [mul_comm, add_comm, derivative_mul] variable [AddCommMonoid A] [Module R A] [Module (Polynomial R) A] @[simp] theorem derivation_C (D : Derivation R R[X] A) (a : R) : D (C a) = 0 := D.map_algebraMap a @[simp] theorem C_smul_derivation_apply (D : Derivation R R[X] A) (a : R) (f : R[X]) : C a • D f = a • D f := by have : C a • D f = D (C a * f) := by simp rw [this, C_mul', D.map_smul] @[ext] theorem derivation_ext {D₁ D₂ : Derivation R R[X] A} (h : D₁ X = D₂ X) : D₁ = D₂ := Derivation.ext fun f => Derivation.eqOn_adjoin (Set.eqOn_singleton.2 h) <| by simp only [adjoin_X, Algebra.coe_top, Set.mem_univ] variable [IsScalarTower R (Polynomial R) A] variable (R) /-- The derivation on `R[X]` that takes the value `a` on `X`. -/ def mkDerivation : A →ₗ[R] Derivation R R[X] A where toFun := fun a ↦ (LinearMap.toSpanSingleton R[X] A a).compDer derivative' map_add' := fun a b ↦ by ext; simp map_smul' := fun t a ↦ by ext; simp lemma mkDerivation_apply (a : A) (f : R[X]) : mkDerivation R a f = derivative f • a := by rfl @[simp] theorem mkDerivation_X (a : A) : mkDerivation R a X = a := by simp [mkDerivation_apply] lemma mkDerivation_one_eq_derivative' : mkDerivation R (1 : R[X]) = derivative' := by ext : 1 simp [derivative'] lemma mkDerivation_one_eq_derivative (f : R[X]) : mkDerivation R (1 : R[X]) f = derivative f := by rw [mkDerivation_one_eq_derivative'] rfl /-- `Polynomial.mkDerivation` as a linear equivalence. -/ def mkDerivationEquiv : A ≃ₗ[R] Derivation R R[X] A := LinearEquiv.symm <| { invFun := mkDerivation R toFun := fun D => D X map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl left_inv := fun _ => derivation_ext <| mkDerivation_X _ _ right_inv := fun _ => mkDerivation_X _ _ } @[simp] lemma mkDerivationEquiv_apply (a : A) : mkDerivationEquiv R a = mkDerivation R a := by rfl @[simp] lemma mkDerivationEquiv_symm_apply (D : Derivation R R[X] A) : (mkDerivationEquiv R).symm D = D X := rfl end CommSemiring end Polynomial namespace Derivation variable {R A M : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M] (d : Derivation R A M) (a : A) open Polynomial Module /-- For a derivation `d : A → M` and an element `a : A`, `d.compAEval a` is the derivation of `R[X]` which takes a polynomial `f` to `d(aeval a f)`. This derivation takes values in `Module.AEval R M a`, which is `M`, regarded as an `R[X]`-module, with the action of a polynomial `f` defined by `f • m = (aeval a f) • m`. -/ /- Note: `compAEval` is not defined using `Derivation.compAlgebraMap`. This because `A` is not an `R[X]` algebra and it would be messy to create an algebra instance within the definition. -/ @[simps] def compAEval : Derivation R R[X] <| AEval R M a where toFun f := AEval.of R M a (d (aeval a f)) map_add' := by simp map_smul' := by simp leibniz' := by simp [AEval.of_aeval_smul, -Derivation.map_aeval] map_one_eq_zero' := by simp /-- A form of the chain rule: if `f` is a polynomial over `R` and `d : A → M` is an `R`-derivation then for all `a : A` we have $$ d(f(a)) = f' (a) d a. $$ The equation is in the `R[X]`-module `Module.AEval R M a`. For the same equation in `M`, see `Derivation.compAEval_eq`. -/ theorem compAEval_eq (d : Derivation R A M) (f : R[X]) : d.compAEval a f = derivative f • (AEval.of R M a (d a)) := by rw [← mkDerivation_apply] congr apply derivation_ext simp /-- A form of the chain rule: if `f` is a polynomial over `R` and `d : A → M` is an `R`-derivation then for all `a : A` we have $$ d(f(a)) = f' (a) d a. $$ The equation is in `M`. For the same equation in `Module.AEval R M a`, see `Derivation.compAEval_eq`. -/ theorem comp_aeval_eq (d : Derivation R A M) (f : R[X]) : d (aeval a f) = aeval a (derivative f) • d a := calc _ = (AEval.of R M a).symm (d.compAEval a f) := rfl _ = _ := by simp [-compAEval_apply, compAEval_eq] end Derivation
JordanSub.lean
/- Copyright (c) 2025 Loic Simon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Loic Simon -/ import Mathlib.MeasureTheory.Measure.Decomposition.Hahn import Mathlib.MeasureTheory.Measure.Sub import Mathlib.MeasureTheory.VectorMeasure.Decomposition.Jordan /-! # Jordan decomposition from signed measure subtraction This file develops the Jordan decomposition of the signed measure `μ - ν` for finite measures `μ` and `ν`, expressing it as the pair `(μ - ν, ν - μ)` of mutually singular finite measures. The key tool is the Hahn decomposition theorem, which yields a measurable partition of the space where `μ ≤ ν` and `ν ≤ μ`, and the measure difference behaves like a signed measure difference. ## Main results * `toJordanDecomposition_toSignedMeasure_sub`: The Jordan decomposition of `μ.toSignedMeasure - ν.toSignedMeasure` is given by `(μ - ν, ν - μ)`. It relies on the following intermediate results. * `mutually_singular_measure_sub`: The measures `μ - ν` and `ν - μ` are mutually singular. * `sub_toSignedMeasure_eq_toSignedMeasure_sub`: The signed measure `μ.toSignedMeasure - ν.toSignedMeasure` equals `(μ - ν).toSignedMeasure - (ν - μ).toSignedMeasure`. -/ open scoped ENNReal NNReal namespace MeasureTheory.Measure noncomputable section variable {X : Type*} {mX : MeasurableSpace X} variable {s : Set X} variable {μ ν : Measure X} lemma sub_apply_eq_zero_of_isHahnDecomposition (hs : IsHahnDecomposition μ ν s) : (μ - ν) s = 0 := by rw [← restrict_eq_zero, restrict_sub_eq_restrict_sub_restrict hs.measurableSet] exact sub_eq_zero_of_le hs.le_on variable [IsFiniteMeasure μ] [IsFiniteMeasure ν] theorem mutually_singular_measure_sub : (μ - ν).MutuallySingular (ν - μ) := by obtain ⟨s, hs⟩ := exists_isHahnDecomposition μ ν exact ⟨s, hs.measurableSet, sub_apply_eq_zero_of_isHahnDecomposition hs, sub_apply_eq_zero_of_isHahnDecomposition hs.compl⟩ lemma toSignedMeasure_restrict_sub (hs : IsHahnDecomposition μ ν s) : ((ν - μ).restrict s).toSignedMeasure = ν.toSignedMeasure.restrict s - μ.toSignedMeasure.restrict s := by have hmeas := hs.measurableSet rw [eq_sub_iff_add_eq, toSignedMeasure_restrict_eq_restrict_toSignedMeasure _ _ hmeas, ← toSignedMeasure_add] simp only [restrict_sub_eq_restrict_sub_restrict, hmeas, sub_add_cancel_of_le hs.le_on] exact (toSignedMeasure_restrict_eq_restrict_toSignedMeasure _ _ hmeas).symm theorem sub_toSignedMeasure_eq_toSignedMeasure_sub : μ.toSignedMeasure - ν.toSignedMeasure = (μ - ν).toSignedMeasure - (ν - μ).toSignedMeasure := by obtain ⟨s, hs⟩ := exists_isHahnDecomposition μ ν have hsc := hs.compl have h₁ := toSignedMeasure_restrict_sub hs have h₂ := toSignedMeasure_restrict_sub hsc have h₁' := toSignedMeasure_congr <| restrict_eq_zero.mpr <| sub_apply_eq_zero_of_isHahnDecomposition hs have h₂' := toSignedMeasure_congr <| restrict_eq_zero.mpr <| sub_apply_eq_zero_of_isHahnDecomposition hsc have partition₁ := VectorMeasure.restrict_add_restrict_compl (μ - ν).toSignedMeasure hs.measurableSet have partition₂ := VectorMeasure.restrict_add_restrict_compl (ν - μ).toSignedMeasure hs.measurableSet rw [toSignedMeasure_restrict_eq_restrict_toSignedMeasure _ _ hs.measurableSet, toSignedMeasure_restrict_eq_restrict_toSignedMeasure _ _ hs.measurableSet.compl] at partition₁ partition₂ rw [h₁', h₂] at partition₁ rw [h₁, h₂'] at partition₂ simp only [toSignedMeasure_zero, zero_add] at partition₁ partition₂ rw [← VectorMeasure.restrict_add_restrict_compl μ.toSignedMeasure hs.measurableSet, ← VectorMeasure.restrict_add_restrict_compl ν.toSignedMeasure hs.measurableSet, ← partition₁, ← partition₂] repeat rw [sub_eq_add_neg] abel /-- The Jordan decomposition associated to the pair of mutually singular measures `μ - ν` and `ν - μ`. -/ def jordanDecompositionOfToSignedMeasureSub (μ ν : Measure X) [IsFiniteMeasure μ] [IsFiniteMeasure ν] : JordanDecomposition X where posPart := μ - ν negPart := ν - μ mutuallySingular := mutually_singular_measure_sub lemma jordanDecompositionOfToSignedMeasureSub_posPart : (jordanDecompositionOfToSignedMeasureSub μ ν).posPart = μ - ν := rfl lemma jordanDecompositionOfToSignedMeasureSub_negPart : (jordanDecompositionOfToSignedMeasureSub μ ν).negPart = ν - μ := rfl lemma jordanDecompositionOfToSignedMeasureSub_toSignedMeasure : (jordanDecompositionOfToSignedMeasureSub μ ν).toSignedMeasure = μ.toSignedMeasure - ν.toSignedMeasure := by simp_rw [JordanDecomposition.toSignedMeasure, jordanDecompositionOfToSignedMeasureSub_posPart, jordanDecompositionOfToSignedMeasureSub_negPart, ← sub_toSignedMeasure_eq_toSignedMeasure_sub] /-- The Jordan decomposition of `μ.toSignedMeasure - ν.toSignedMeasure` is `(μ - ν, ν - μ)`. -/ @[simp] theorem toJordanDecomposition_toSignedMeasure_sub : (μ.toSignedMeasure - ν.toSignedMeasure).toJordanDecomposition = jordanDecompositionOfToSignedMeasureSub μ ν := by apply JordanDecomposition.toSignedMeasure_injective rw [SignedMeasure.toSignedMeasure_toJordanDecomposition, jordanDecompositionOfToSignedMeasureSub_toSignedMeasure] end end MeasureTheory.Measure
Decomposition.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.AlgebraicTopology.DoldKan.PInfty /-! # Decomposition of the Q endomorphisms In this file, we obtain a lemma `decomposition_Q` which expresses explicitly the projection `(Q q).f (n+1) : X _⦋n+1⦌ ⟶ X _⦋n+1⦌` (`X : SimplicialObject C` with `C` a preadditive category) as a sum of terms which are postcompositions with degeneracies. (TODO @joelriou: when `C` is abelian, define the degenerate subcomplex of the alternating face map complex of `X` and show that it is a complement to the normalized Moore complex.) Then, we introduce an ad hoc structure `MorphComponents X n Z` which can be used in order to define morphisms `X _⦋n+1⦌ ⟶ Z` using the decomposition provided by `decomposition_Q`. This shall play a critical role in the proof that the functor `N₁ : SimplicialObject C ⥤ Karoubi (ChainComplex C ℕ))` reflects isomorphisms. (See `Equivalence.lean` for the general strategy of proof of the Dold-Kan equivalence.) -/ open CategoryTheory CategoryTheory.Category CategoryTheory.Preadditive Opposite Simplicial noncomputable section namespace AlgebraicTopology namespace DoldKan variable {C : Type*} [Category C] [Preadditive C] {X X' : SimplicialObject C} /-- In each positive degree, this lemma decomposes the idempotent endomorphism `Q q` as a sum of morphisms which are postcompositions with suitable degeneracies. As `Q q` is the complement projection to `P q`, this implies that in the case of simplicial abelian groups, any $(n+1)$-simplex $x$ can be decomposed as $x = x' + \sum (i=0}^{q-1} σ_{n-i}(y_i)$ where $x'$ is in the image of `P q` and the $y_i$ are in degree $n$. -/ theorem decomposition_Q (n q : ℕ) : ((Q q).f (n + 1) : X _⦋n + 1⦌ ⟶ X _⦋n + 1⦌) = ∑ i : Fin (n + 1) with i.val < q, (P i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ (Fin.rev i) := by induction' q with q hq · simp only [Q_zero, HomologicalComplex.zero_f_apply, Nat.not_lt_zero, Finset.filter_False, Finset.sum_empty] · by_cases hqn : q + 1 ≤ n + 1 swap · rw [Q_is_eventually_constant (show n + 1 ≤ q by omega), hq] congr 1 ext ⟨x, hx⟩ simp_rw [Finset.mem_filter_univ] omega · obtain ⟨a, ha⟩ := Nat.le.dest (Nat.succ_le_succ_iff.mp hqn) rw [Q_succ, HomologicalComplex.sub_f_apply, HomologicalComplex.comp_f, hq] symm conv_rhs => rw [sub_eq_add_neg, add_comm] let q' : Fin (n + 1) := ⟨q, Nat.succ_le_iff.mp hqn⟩ rw [← @Finset.add_sum_erase _ _ _ _ _ _ q' (by simp [q'])] congr · have hnaq' : n = a + q := by omega simp only [(HigherFacesVanish.of_P q n).comp_Hσ_eq hnaq', q'.rev_eq hnaq', neg_neg] rfl · ext ⟨i, hi⟩ simp_rw [Finset.mem_erase, Finset.mem_filter_univ, q', ne_eq, Fin.mk.injEq] omega variable (X) /-- The structure `MorphComponents` is an ad hoc structure that is used in the proof that `N₁ : SimplicialObject C ⥤ Karoubi (ChainComplex C ℕ))` reflects isomorphisms. The fields are the data that are needed in order to construct a morphism `X _⦋n+1⦌ ⟶ Z` (see `φ`) using the decomposition of the identity given by `decomposition_Q n (n+1)`. -/ @[ext] structure MorphComponents (n : ℕ) (Z : C) where a : X _⦋n + 1⦌ ⟶ Z b : Fin (n + 1) → (X _⦋n⦌ ⟶ Z) namespace MorphComponents variable {X} {n : ℕ} {Z Z' : C} (f : MorphComponents X n Z) (g : X' ⟶ X) (h : Z ⟶ Z') /-- The morphism `X _⦋n+1⦌ ⟶ Z` associated to `f : MorphComponents X n Z`. -/ def φ {Z : C} (f : MorphComponents X n Z) : X _⦋n + 1⦌ ⟶ Z := PInfty.f (n + 1) ≫ f.a + ∑ i : Fin (n + 1), (P i).f (n + 1) ≫ X.δ i.rev.succ ≫ f.b (Fin.rev i) variable (X n) /-- the canonical `MorphComponents` whose associated morphism is the identity (see `F_id`) thanks to `decomposition_Q n (n+1)` -/ @[simps] def id : MorphComponents X n (X _⦋n + 1⦌) where a := PInfty.f (n + 1) b i := X.σ i @[simp] theorem id_φ : (id X n).φ = 𝟙 _ := by simp only [← P_add_Q_f (n + 1) (n + 1), φ] congr 1 · simp only [id, PInfty_f, P_f_idem] · exact Eq.trans (by congr; simp) (decomposition_Q n (n + 1)).symm variable {X n} /-- A `MorphComponents` can be postcomposed with a morphism. -/ @[simps] def postComp : MorphComponents X n Z' where a := f.a ≫ h b i := f.b i ≫ h @[simp] theorem postComp_φ : (f.postComp h).φ = f.φ ≫ h := by unfold φ postComp simp only [add_comp, sum_comp, assoc] /-- A `MorphComponents` can be precomposed with a morphism of simplicial objects. -/ @[simps] def preComp : MorphComponents X' n Z where a := g.app (op ⦋n + 1⦌) ≫ f.a b i := g.app (op ⦋n⦌) ≫ f.b i @[simp] theorem preComp_φ : (f.preComp g).φ = g.app (op ⦋n + 1⦌) ≫ f.φ := by unfold φ preComp simp only [PInfty_f, comp_add] congr 1 · simp only [P_f_naturality_assoc] · simp only [comp_sum, P_f_naturality_assoc, SimplicialObject.δ_naturality_assoc] end MorphComponents end DoldKan end AlgebraicTopology
OreSet.lean
/- Copyright (c) 2022 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer, Kevin Klinge -/ import Mathlib.Algebra.Group.Submonoid.Defs import Mathlib.Algebra.GroupWithZero.Basic import Mathlib.Algebra.Ring.Regular import Mathlib.GroupTheory.OreLocalization.OreSet /-! # (Left) Ore sets and rings This file contains results on left Ore sets for rings and monoids with zero. ## References * https://ncatlab.org/nlab/show/Ore+set -/ assert_not_exists RelIso namespace OreLocalization /-- Cancellability in monoids with zeros can act as a replacement for the `ore_right_cancel` condition of an ore set. -/ def oreSetOfCancelMonoidWithZero {R : Type*} [CancelMonoidWithZero R] {S : Submonoid R} (oreNum : R → S → R) (oreDenom : R → S → S) (ore_eq : ∀ (r : R) (s : S), oreDenom r s * r = oreNum r s * s) : OreSet S := { ore_right_cancel := fun _ _ s h => ⟨s, mul_eq_mul_left_iff.mpr (mul_eq_mul_right_iff.mp h)⟩ oreNum oreDenom ore_eq } /-- In rings without zero divisors, the first (cancellability) condition is always fulfilled, it suffices to give a proof for the Ore condition itself. -/ def oreSetOfNoZeroDivisors {R : Type*} [Ring R] [NoZeroDivisors R] {S : Submonoid R} (oreNum : R → S → R) (oreDenom : R → S → S) (ore_eq : ∀ (r : R) (s : S), oreDenom r s * r = oreNum r s * s) : OreSet S := letI : CancelMonoidWithZero R := NoZeroDivisors.toCancelMonoidWithZero oreSetOfCancelMonoidWithZero oreNum oreDenom ore_eq lemma nonempty_oreSet_iff {R : Type*} [Monoid R] {S : Submonoid R} : Nonempty (OreSet S) ↔ (∀ (r₁ r₂ : R) (s : S), r₁ * s = r₂ * s → ∃ s' : S, s' * r₁ = s' * r₂) ∧ (∀ (r : R) (s : S), ∃ (r' : R) (s' : S), s' * r = r' * s) := by constructor · exact fun ⟨_⟩ ↦ ⟨ore_right_cancel, fun r s ↦ ⟨oreNum r s, oreDenom r s, ore_eq r s⟩⟩ · intro ⟨H, H'⟩ choose r' s' h using H' exact ⟨H, r', s', h⟩ lemma nonempty_oreSet_iff_of_noZeroDivisors {R : Type*} [Ring R] [NoZeroDivisors R] {S : Submonoid R} : Nonempty (OreSet S) ↔ ∀ (r : R) (s : S), ∃ (r' : R) (s' : S), s' * r = r' * s := by constructor · exact fun ⟨_⟩ ↦ fun r s ↦ ⟨oreNum r s, oreDenom r s, ore_eq r s⟩ · intro H choose r' s' h using H exact ⟨oreSetOfNoZeroDivisors r' s' h⟩ end OreLocalization
WeierstrassPreparation.lean
/- Copyright (c) 2025 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.RingTheory.LocalRing.ResidueField.Basic import Mathlib.RingTheory.Polynomial.Eisenstein.Distinguished import Mathlib.RingTheory.PowerSeries.CoeffMulMem import Mathlib.RingTheory.PowerSeries.Inverse import Mathlib.RingTheory.PowerSeries.Trunc /-! # Weierstrass preparation theorem for power series over a complete local ring In this file we define Weierstrass division, Weierstrass factorization, and prove Weierstrass preparation theorem. We assume that a ring is adic complete with respect to some ideal. If such ideal is a maximal ideal, then by `isLocalRing_of_isAdicComplete_maximal`, such ring has only one maximal ideal, and hence it is a complete local ring. ## Main definitions - `PowerSeries.IsWeierstrassDivisionAt f g q r I`: let `f` and `g` be power series over `A`, `I` be an ideal of `A`, this is a `Prop` which asserts that a power series `q` and a polynomial `r` of degree `< n` satisfy `f = g * q + r`, where `n` is the order of the image of `g` in `(A / I)⟦X⟧` (defined to be zero if such image is zero, in which case it's mathematically not considered). - `PowerSeries.IsWeierstrassDivision`: version of `PowerSeries.IsWeierstrassDivisionAt` for local rings with respect to its maximal ideal. - `PowerSeries.IsWeierstrassDivisorAt g I`: let `g` be a power series over `A`, `I` be an ideal of `A`, this is a `Prop` which asserts that the `n`-th coefficient of `g` is a unit, where `n` is the order of the image of `g` in `(A / I)⟦X⟧` (defined to be zero if such image is zero, in which case it's mathematically not considered). This property guarantees that if the `A` is `I`-adic complete, then `g` can be used as a divisor in Weierstrass division (`PowerSeries.IsWeierstrassDivisorAt.isWeierstrassDivisionAt_div_mod`). - `PowerSeries.IsWeierstrassDivisor`: version of `PowerSeries.IsWeierstrassDivisorAt` for local rings with respect to its maximal ideal. - `PowerSeries.IsWeierstrassFactorizationAt g f h I`: for a power series `g` over `A` and an ideal `I` of `A`, this is a `Prop` which asserts that `f` is a distinguished polynomial at `I`, `h` is a formal power series over `A` that is a unit and such that `g = f * h`. - `PowerSeries.IsWeierstrassFactorization`: version of `PowerSeries.IsWeierstrassFactorizationAt` for local rings with respect to its maximal ideal. ## Main results - `PowerSeries.exists_isWeierstrassDivision`: **Weierstrass division** ([washington_cyclotomic], Proposition 7.2): let `f`, `g` be power series over a complete local ring, such that the image of `g` in the residue field is not zero. Let `n` be the order of the image of `g` in the residue field. Then there exists a power series `q` and a polynomial `r` of degree `< n`, such that `f = g * q + r`. - `PowerSeries.IsWeierstrassDivision.elim`, `PowerSeries.IsWeierstrassDivision.unique`: `q` and `r` in the Weierstrass division are unique. - `PowerSeries.exists_isWeierstrassFactorization`: **Weierstrass preparation theorem** ([washington_cyclotomic], Theorem 7.3): let `g` be a power series over a complete local ring, such that its image in the residue field is not zero. Then there exists a distinguished polynomial `f` and a power series `h` which is a unit, such that `g = f * h`. - `PowerSeries.IsWeierstrassFactorization.elim`, `PowerSeries.IsWeierstrassFactorization.unique`: `f` and `h` in Weierstrass preparation theorem are unique. - `Polynomial.IsDistinguishedAt.algEquivQuotient`: a distinguished polynomial `g` induces a natural isomorphism `A[X] / (g) ≃ₐ[A] A⟦X⟧ / (g)`. - `PowerSeries.IsWeierstrassFactorizationAt.algEquivQuotient`: a Weierstrass factorization `g = f * h` induces a natural isomorphism `A[X] / (f) ≃ₐ[A] A⟦X⟧ / (g)`. - `PowerSeries.algEquivQuotientWeierstrassDistinguished`: if `g` is a power series over a complete local ring, such that its image in the residue field is not zero, then there is a natural isomorphism `A[X] / (f) ≃ₐ[A] A⟦X⟧ / (g)` where `f` is `PowerSeries.weierstrassDistinguished g`. ## References - [Washington, Lawrence C. *Introduction to cyclotomic fields.*][washington_cyclotomic] -/ open scoped Polynomial namespace PowerSeries variable {A : Type*} [CommRing A] /-! ## Weierstrass division -/ section IsWeierstrassDivisionAt variable (f g q : A⟦X⟧) (r : A[X]) (I : Ideal A) /-- Let `f`, `g` be power series over `A`, `I` be an ideal of `A`, `PowerSeries.IsWeierstrassDivisionAt f g q r I` is a `Prop` which asserts that a power series `q` and a polynomial `r` of degree `< n` satisfy `f = g * q + r`, where `n` is the order of the image of `g` in `(A / I)⟦X⟧` (defined to be zero if such image is zero, in which case it's mathematically not considered). -/ @[mk_iff] structure IsWeierstrassDivisionAt : Prop where degree_lt : r.degree < (g.map (Ideal.Quotient.mk I)).order.toNat eq_mul_add : f = g * q + r /-- Version of `PowerSeries.IsWeierstrassDivisionAt` for local rings with respect to its maximal ideal. -/ abbrev IsWeierstrassDivision [IsLocalRing A] : Prop := f.IsWeierstrassDivisionAt g q r (IsLocalRing.maximalIdeal A) theorem isWeierstrassDivisionAt_zero : IsWeierstrassDivisionAt 0 g 0 0 I := by constructor · rw [Polynomial.degree_zero] exact WithBot.bot_lt_coe _ · simp variable {f g q r I} namespace IsWeierstrassDivisionAt theorem coeff_f_sub_r_mem (H : f.IsWeierstrassDivisionAt g q r I) {i : ℕ} (hi : i < (g.map (Ideal.Quotient.mk I)).order.toNat) : coeff A i (f - r) ∈ I := by replace H := H.2 rw [← sub_eq_iff_eq_add] at H rw [H] refine coeff_mul_mem_ideal_of_coeff_left_mem_ideal i (fun j hj ↦ ?_) i le_rfl have := coeff_of_lt_order_toNat _ (lt_of_le_of_lt hj hi) rwa [coeff_map, ← RingHom.mem_ker, Ideal.mk_ker] at this theorem add {f' q' r'} (H : f.IsWeierstrassDivisionAt g q r I) (H' : f'.IsWeierstrassDivisionAt g q' r' I) : (f + f').IsWeierstrassDivisionAt g (q + q') (r + r') I := ⟨(Polynomial.degree_add_le _ _).trans_lt (sup_lt_iff.2 ⟨H.degree_lt, H'.degree_lt⟩), by rw [H.eq_mul_add, H'.eq_mul_add, Polynomial.coe_add]; ring⟩ theorem smul (H : f.IsWeierstrassDivisionAt g q r I) (a : A) : (a • f).IsWeierstrassDivisionAt g (a • q) (a • r) I := ⟨(Polynomial.degree_smul_le a _).trans_lt H.degree_lt, by simp [H.eq_mul_add, Algebra.smul_def, mul_add, mul_left_comm]⟩ end IsWeierstrassDivisionAt end IsWeierstrassDivisionAt section IsWeierstrassDivisorAt variable (g : A⟦X⟧) (I : Ideal A) /-- `PowerSeries.IsWeierstrassDivisorAt g I` is a `Prop` which asserts that the `n`-th coefficient of `g` is a unit, where `n` is the order of the image of `g` in `(A / I)⟦X⟧` (defined to be zero if such image is zero, in which case it's mathematically not considered). This property guarantees that if the ring is `I`-adic complete, then `g` can be used as a divisor in Weierstrass division (`PowerSeries.IsWeierstrassDivisorAt.isWeierstrassDivisionAt_div_mod`). -/ def IsWeierstrassDivisorAt : Prop := IsUnit (coeff A (g.map (Ideal.Quotient.mk I)).order.toNat g) /-- Version of `PowerSeries.IsWeierstrassDivisorAt` for local rings with respect to its maximal ideal. -/ abbrev IsWeierstrassDivisor [IsLocalRing A] : Prop := g.IsWeierstrassDivisorAt (IsLocalRing.maximalIdeal A) variable {g} in /-- If `g` is a power series over a local ring such that its image in the residue field is not zero, then `g` can be used as a Weierstrass divisor. -/ theorem IsWeierstrassDivisor.of_map_ne_zero [IsLocalRing A] (hg : g.map (IsLocalRing.residue A) ≠ 0) : g.IsWeierstrassDivisor := by rw [IsWeierstrassDivisor, IsWeierstrassDivisorAt, ← IsLocalRing.notMem_maximalIdeal] have h := coeff_order hg contrapose! h rwa [coeff_map, IsLocalRing.residue_eq_zero_iff] theorem _root_.Polynomial.IsDistinguishedAt.isWeierstrassDivisorAt {g : A[X]} {I : Ideal A} (H : g.IsDistinguishedAt I) (hI : I ≠ ⊤) : IsWeierstrassDivisorAt g I := by have : g.natDegree = _ := congr(ENat.toNat $(H.coe_natDegree_eq_order_map g 1 (by rwa [constantCoeff_one, ← Ideal.ne_top_iff_one]) (by simp))) simp [IsWeierstrassDivisorAt, ← this, H.monic.leadingCoeff] theorem _root_.Polynomial.IsDistinguishedAt.isWeierstrassDivisorAt' {g : A[X]} {I : Ideal A} (H : g.IsDistinguishedAt I) [IsHausdorff I A] : IsWeierstrassDivisorAt g I := by rcases eq_or_ne I ⊤ with rfl | hI · have := ‹IsHausdorff ⊤ A›.subsingleton exact isUnit_of_subsingleton _ exact H.isWeierstrassDivisorAt hI private theorem coeff_trunc_order_mem (i : ℕ) : (g.trunc (g.map (Ideal.Quotient.mk I)).order.toNat).coeff i ∈ I := by rw [coeff_trunc] split_ifs with h · simpa [← RingHom.mem_ker] using coeff_of_lt_order_toNat _ h · exact zero_mem _ namespace IsWeierstrassDivisorAt variable {g I} (H : g.IsWeierstrassDivisorAt I) include H theorem isUnit_shift : IsUnit <| mk fun i ↦ coeff A (i + (g.map (Ideal.Quotient.mk I)).order.toNat) g := by simpa [isUnit_iff_constantCoeff] /-- The inductively constructed sequence `qₖ` in the proof of Weierstrass division. -/ noncomputable def seq (H : g.IsWeierstrassDivisorAt I) (f : A⟦X⟧) : ℕ → A⟦X⟧ | 0 => 0 | k + 1 => H.seq f k + (mk fun i ↦ coeff A (i + (g.map (Ideal.Quotient.mk I)).order.toNat) (f - g * H.seq f k)) * H.isUnit_shift.unit⁻¹ variable (a : A) (f f' : A⟦X⟧) theorem coeff_seq_mem (k : ℕ) {i : ℕ} (hi : i ≥ (g.map (Ideal.Quotient.mk I)).order.toNat) : coeff A i (f - g * H.seq f k) ∈ I ^ k := by induction k generalizing hi i with | zero => simp | succ k hq => rw [seq] set q := H.seq f k set s := f - g * q set n := (g.map (Ideal.Quotient.mk I)).order.toNat have hs := s.eq_X_pow_mul_shift_add_trunc n set s₀ := s.trunc n set s₁ := PowerSeries.mk fun i ↦ coeff A (i + n) s set q' := q + s₁ * H.isUnit_shift.unit⁻¹ have key : f - g * q' = (s₀ : A⟦X⟧) - (g.trunc n : A⟦X⟧) * s₁ * H.isUnit_shift.unit⁻¹ := by trans s + g * (q - q') · simp_rw [s]; ring simp_rw [q'] rw [sub_add_cancel_left, mul_neg, ← mul_assoc, mul_right_comm] nth_rw 1 [g.eq_X_pow_mul_shift_add_trunc n] rw [add_mul, mul_assoc, IsUnit.mul_val_inv, hs] ring rw [key, map_sub, Polynomial.coeff_coe, coeff_trunc, if_neg hi.not_gt, zero_sub, neg_mem_iff, pow_succ'] refine coeff_mul_mem_ideal_of_coeff_left_mem_ideal' (fun i ↦ ?_) i refine coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal' (by simp [n, g.coeff_trunc_order_mem]) (fun i ↦ ?_) i rw [coeff_mk] exact hq (by simp) theorem coeff_seq_succ_sub_seq_mem (k i : ℕ) : coeff A i (H.seq f (k + 1) - H.seq f k) ∈ I ^ k := by rw [seq, add_sub_cancel_left] refine coeff_mul_mem_ideal_of_coeff_left_mem_ideal' (fun i ↦ ?_) i rw [coeff_mk] exact H.coeff_seq_mem f k (by simp) @[simp] theorem seq_zero : H.seq f 0 = 0 := rfl theorem seq_one : H.seq f 1 = (PowerSeries.mk fun i ↦ coeff A (i + (g.map (Ideal.Quotient.mk I)).order.toNat) f) * H.isUnit_shift.unit⁻¹ := by simp_rw [seq, mul_zero, zero_add, sub_zero] /-- The (bundled version of) coefficient of the limit `q` of the inductively constructed sequence `qₖ` in the proof of Weierstrass division. -/ noncomputable def divCoeff [IsPrecomplete I A] (i : ℕ) := Classical.indefiniteDescription _ <| IsPrecomplete.prec' (I := I) (fun k ↦ coeff A i (H.seq f k)) fun {m} {n} hn ↦ by induction n, hn using Nat.le_induction with | base => rw [SModEq.def] | succ n hn ih => refine ih.trans (SModEq.symm ?_) rw [SModEq.sub_mem, smul_eq_mul, Ideal.mul_top, ← map_sub] exact Ideal.pow_le_pow_right hn (H.coeff_seq_succ_sub_seq_mem f n i) /-- The limit `q` of the inductively constructed sequence `qₖ` in the proof of Weierstrass division. -/ noncomputable def div [IsPrecomplete I A] : A⟦X⟧ := PowerSeries.mk fun i ↦ (H.divCoeff f i).1 theorem coeff_div [IsPrecomplete I A] (i : ℕ) : coeff A i (H.div f) = (H.divCoeff f i).1 := by simp [div] theorem coeff_div_sub_seq_mem [IsPrecomplete I A] (k i : ℕ) : coeff A i (H.div f - (H.seq f k)) ∈ I ^ k := by simpa [coeff_div, SModEq.sub_mem] using ((H.divCoeff f i).2 k).symm /-- The remainder `r` in the proof of Weierstrass division. -/ noncomputable def mod [IsPrecomplete I A] : A[X] := (f - g * H.div f).trunc (g.map (Ideal.Quotient.mk I)).order.toNat /-- If the ring is `I`-adic complete, then `g` can be used as a divisor in Weierstrass division. -/ theorem isWeierstrassDivisionAt_div_mod [IsAdicComplete I A] : f.IsWeierstrassDivisionAt g (H.div f) (H.mod f) I := by rcases eq_or_ne I ⊤ with rfl | hI · have := ‹IsAdicComplete ⊤ A›.toIsHausdorff.subsingleton rw [Subsingleton.elim f 0, Subsingleton.elim (H.div 0) 0, Subsingleton.elim (H.mod 0) 0] exact g.isWeierstrassDivisionAt_zero _ constructor · exact degree_trunc_lt _ _ · rw [mod, add_comm, ← sub_eq_iff_eq_add] ext i rw [Polynomial.coeff_coe, coeff_trunc] split_ifs with hi · rfl refine IsHausdorff.haus' (I := I) _ fun k ↦ ?_ rw [SModEq.zero, smul_eq_mul, Ideal.mul_top, show f - g * H.div f = f - g * (H.seq f k) - g * (H.div f - (H.seq f k)) by ring, map_sub] exact Ideal.sub_mem _ (H.coeff_seq_mem f k (not_lt.1 hi)) <| coeff_mul_mem_ideal_of_coeff_right_mem_ideal' (H.coeff_div_sub_seq_mem f k) i /-- If `g * q = r` for some power series `q` and some polynomial `r` whose degree is `< n`, then `q` and `r` are all zero. This implies the uniqueness of Weierstrass division. -/ theorem eq_zero_of_mul_eq [IsHausdorff I A] {q : A⟦X⟧} {r : A[X]} (hdeg : r.degree < (g.map (Ideal.Quotient.mk I)).order.toNat) (heq : g * q = r) : q = 0 ∧ r = 0 := by suffices ∀ k i, coeff A i q ∈ I ^ k by have hq : q = 0 := by ext i refine IsHausdorff.haus' (I := I) _ fun k ↦ ?_ rw [SModEq.zero, smul_eq_mul, Ideal.mul_top] exact this _ _ rw [hq, mul_zero, Eq.comm, Polynomial.coe_eq_zero_iff] at heq exact ⟨hq, heq⟩ intro k induction k with | zero => simp | succ k ih => rw [g.eq_X_pow_mul_shift_add_trunc (g.map (Ideal.Quotient.mk I)).order.toNat] at heq have h1 : ∀ i, coeff A i r ∈ I ^ (k + 1) := fun i ↦ by rcases lt_or_ge i (g.map (Ideal.Quotient.mk I)).order.toNat with hi | hi · rw [← heq, pow_succ'] refine coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal i (fun j hj ↦ ?_) (fun j _ ↦ ih j) i le_rfl rw [map_add, Polynomial.coeff_coe] refine Ideal.add_mem _ ?_ (g.coeff_trunc_order_mem I j) simp_rw [coeff_X_pow_mul', if_neg (lt_of_le_of_lt hj hi).not_ge, zero_mem] simp_rw [Polynomial.coeff_coe, Polynomial.coeff_eq_zero_of_degree_lt (lt_of_lt_of_le hdeg (by simpa)), zero_mem] rw [add_mul, mul_comm (X ^ _), ← eq_sub_iff_add_eq] at heq replace heq := congr(H.isUnit_shift.unit⁻¹ * $heq) rw [← mul_assoc, ← mul_assoc, IsUnit.val_inv_mul, one_mul] at heq intro i rw [← coeff_X_pow_mul _ (g.map (Ideal.Quotient.mk I)).order.toNat i, heq] refine coeff_mul_mem_ideal_of_coeff_right_mem_ideal' (fun i ↦ ?_) _ rw [map_sub] refine Ideal.sub_mem _ (h1 _) ?_ rw [pow_succ'] refine coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal' (fun i ↦ ?_) ih _ simp_rw [Polynomial.coeff_coe, g.coeff_trunc_order_mem] /-- If `g * q + r = g * q' + r'` for some power series `q`, `q'` and some polynomials `r`, `r'` whose degrees are `< n`, then `q = q'` and `r = r'` are all zero. This implies the uniqueness of Weierstrass division. -/ theorem eq_of_mul_add_eq_mul_add [IsHausdorff I A] {q q' : A⟦X⟧} {r r' : A[X]} (hr : r.degree < (g.map (Ideal.Quotient.mk I)).order.toNat) (hr' : r'.degree < (g.map (Ideal.Quotient.mk I)).order.toNat) (heq : g * q + r = g * q' + r') : q = q' ∧ r = r' := by replace heq : g * (q - q') = ↑(r' - r) := by rw [← eq_sub_iff_add_eq] at heq rw [Polynomial.coe_sub, mul_sub, heq] ring have h := H.eq_zero_of_mul_eq (lt_of_le_of_lt (r'.degree_sub_le r) (max_lt hr' hr)) heq simp_rw [sub_eq_zero] at h exact ⟨h.1, h.2.symm⟩ @[simp] theorem div_add [IsAdicComplete I A] : H.div (f + f') = H.div f + H.div f' := by have H1 := (H.isWeierstrassDivisionAt_div_mod f).add (H.isWeierstrassDivisionAt_div_mod f') have H2 := H.isWeierstrassDivisionAt_div_mod (f + f') exact (H.eq_of_mul_add_eq_mul_add H2.degree_lt H1.degree_lt (H2.eq_mul_add.symm.trans H1.eq_mul_add)).1 @[simp] theorem div_smul [IsAdicComplete I A] : H.div (a • f) = a • H.div f := by have H1 := (H.isWeierstrassDivisionAt_div_mod f).smul a have H2 := H.isWeierstrassDivisionAt_div_mod (a • f) exact (H.eq_of_mul_add_eq_mul_add H2.degree_lt H1.degree_lt (H2.eq_mul_add.symm.trans H1.eq_mul_add)).1 @[simp] theorem div_zero [IsAdicComplete I A] : H.div 0 = 0 := by simpa using H.div_smul 0 0 @[simp] theorem mod_add [IsAdicComplete I A] : H.mod (f + f') = H.mod f + H.mod f' := by have H1 := (H.isWeierstrassDivisionAt_div_mod f).add (H.isWeierstrassDivisionAt_div_mod f') have H2 := H.isWeierstrassDivisionAt_div_mod (f + f') exact (H.eq_of_mul_add_eq_mul_add H2.degree_lt H1.degree_lt (H2.eq_mul_add.symm.trans H1.eq_mul_add)).2 @[simp] theorem mod_smul [IsAdicComplete I A] : H.mod (a • f) = a • H.mod f := by have H1 := (H.isWeierstrassDivisionAt_div_mod f).smul a have H2 := H.isWeierstrassDivisionAt_div_mod (a • f) exact (H.eq_of_mul_add_eq_mul_add H2.degree_lt H1.degree_lt (H2.eq_mul_add.symm.trans H1.eq_mul_add)).2 @[simp] theorem mod_zero [IsAdicComplete I A] : H.mod 0 = 0 := by simpa using H.mod_smul 0 0 /-- The remainder map `PowerSeries.IsWeierstrassDivisorAt.mod` induces a linear map `A⟦X⟧ / (g) →ₗ[A] A[X]`. -/ noncomputable def mod' [IsAdicComplete I A] : A⟦X⟧ ⧸ Ideal.span {g} →ₗ[A] A[X] where toFun := Quotient.lift (fun f ↦ H.mod f) fun f f' hf ↦ by simp_rw [HasEquiv.Equiv, Submodule.quotientRel_def, Ideal.mem_span_singleton'] at hf obtain ⟨a, ha⟩ := hf obtain ⟨hf1, hf2⟩ := H.isWeierstrassDivisionAt_div_mod f obtain ⟨hf'1, hf'2⟩ := H.isWeierstrassDivisionAt_div_mod f' rw [eq_sub_iff_add_eq, hf2, hf'2, ← add_assoc, mul_comm, ← mul_add] at ha exact (H.eq_of_mul_add_eq_mul_add hf'1 hf1 ha).2.symm map_add' f f' := by obtain ⟨f, rfl⟩ := Ideal.Quotient.mk_surjective f obtain ⟨f', rfl⟩ := Ideal.Quotient.mk_surjective f' exact H.mod_add f f' map_smul' a f := by obtain ⟨f, rfl⟩ := Ideal.Quotient.mk_surjective f exact H.mod_smul a f @[simp] theorem mod'_mk_eq_mod [IsAdicComplete I A] {f : A⟦X⟧} : H.mod' (Ideal.Quotient.mk _ f) = H.mod f := rfl theorem div_coe_eq_zero [IsAdicComplete I A] {r : A[X]} (hr : r.degree < (g.map (Ideal.Quotient.mk I)).order.toNat) : H.div r = 0 := by obtain ⟨h1, h2⟩ := H.isWeierstrassDivisionAt_div_mod r exact (H.eq_of_mul_add_eq_mul_add (q := H.div r) (q' := 0) h1 hr (by simpa using h2.symm)).1 theorem mod_coe_eq_self [IsAdicComplete I A] {r : A[X]} (hr : r.degree < (g.map (Ideal.Quotient.mk I)).order.toNat) : H.mod r = r := by obtain ⟨h1, h2⟩ := H.isWeierstrassDivisionAt_div_mod r exact (H.eq_of_mul_add_eq_mul_add (q := H.div r) (q' := 0) h1 hr (by simpa using h2.symm)).2 @[simp] theorem mk_mod'_eq_self [IsAdicComplete I A] {f : A⟦X⟧ ⧸ Ideal.span {g}} : Ideal.Quotient.mk _ (H.mod' f : A⟦X⟧) = f := by obtain ⟨f, rfl⟩ := Ideal.Quotient.mk_surjective f rw [mod'_mk_eq_mod, Eq.comm, Ideal.Quotient.mk_eq_mk_iff_sub_mem, Ideal.mem_span_singleton'] use H.div f rw [eq_sub_iff_add_eq, mul_comm, (H.isWeierstrassDivisionAt_div_mod f).2.symm] end IsWeierstrassDivisorAt section Equiv variable {g : A[X]} {I : Ideal A} (H : g.IsDistinguishedAt I) [IsAdicComplete I A] include H /-- A distinguished polynomial `g` induces a natural isomorphism `A[X] / (g) ≃ₐ[A] A⟦X⟧ / (g)`. -/ @[simps! apply symm_apply] noncomputable def _root_.Polynomial.IsDistinguishedAt.algEquivQuotient : (A[X] ⧸ Ideal.span {g}) ≃ₐ[A] A⟦X⟧ ⧸ Ideal.span {(g : A⟦X⟧)} where __ := Ideal.quotientMapₐ _ (Polynomial.coeToPowerSeries.algHom A) fun a ha ↦ by obtain ⟨b, hb⟩ := Ideal.mem_span_singleton'.1 ha simp only [Ideal.mem_comap, Polynomial.coeToPowerSeries.algHom_apply, Algebra.algebraMap_self, map_id, id_eq, Ideal.mem_span_singleton'] exact ⟨b, by simp [← hb]⟩ invFun := Ideal.Quotient.mk _ ∘ H.isWeierstrassDivisorAt'.mod' left_inv f := by rcases subsingleton_or_nontrivial A with _ | _ · have : Subsingleton A[X] := inferInstance have : Subsingleton (A[X] ⧸ Ideal.span {g}) := Quot.Subsingleton exact Subsingleton.elim _ _ have hI : I ≠ ⊤ := by rintro rfl exact not_subsingleton _ ‹IsAdicComplete ⊤ A›.toIsHausdorff.subsingleton have := Ideal.Quotient.nontrivial hI obtain ⟨f, hfdeg, rfl⟩ : ∃ r : A[X], r.degree < g.degree ∧ Ideal.Quotient.mk _ r = f := by obtain ⟨f, rfl⟩ := Ideal.Quotient.mk_surjective f refine ⟨f %ₘ g, Polynomial.degree_modByMonic_lt f H.monic, ?_⟩ rw [Eq.comm, Ideal.Quotient.mk_eq_mk_iff_sub_mem, Ideal.mem_span_singleton'] exact ⟨f /ₘ g, by rw [Polynomial.modByMonic_eq_sub_mul_div _ H.monic]; ring⟩ have h1 : g.degree = ((g : A⟦X⟧).map (Ideal.Quotient.mk I)).order.toNat := by convert H.degree_eq_coe_lift_order_map g 1 (by rwa [constantCoeff_one, ← Ideal.ne_top_iff_one]) (by simp) exact (ENat.lift_eq_toNat_of_lt_top _).symm dsimp rw [Ideal.Quotient.mk_eq_mk_iff_sub_mem, Ideal.mem_span_singleton'] exact ⟨0, by simp [H.isWeierstrassDivisorAt'.mod_coe_eq_self (hfdeg.trans_eq h1)]⟩ right_inv f := by exact H.isWeierstrassDivisorAt'.mk_mod'_eq_self end Equiv end IsWeierstrassDivisorAt section IsLocalRing variable [IsLocalRing A] (a : A) (f f' g : A⟦X⟧) variable {g} in /-- **Weierstrass division** ([washington_cyclotomic], Proposition 7.2): let `f`, `g` be power series over a complete local ring, such that the image of `g` in the residue field is not zero. Let `n` be the order of the image of `g` in the residue field. Then there exists a power series `q` and a polynomial `r` of degree `< n`, such that `f = g * q + r`. -/ theorem exists_isWeierstrassDivision [IsAdicComplete (IsLocalRing.maximalIdeal A) A] (hg : g.map (IsLocalRing.residue A) ≠ 0) : ∃ q r, f.IsWeierstrassDivision g q r := ⟨_, _, (IsWeierstrassDivisor.of_map_ne_zero hg).isWeierstrassDivisionAt_div_mod f⟩ -- Unfortunately there is no Unicode subscript `w`. /-- The quotient `q` in Weierstrass division, denoted by `f /ʷ g`. Note that when the image of `g` in the residue field is zero, this is defined to be zero. -/ noncomputable def weierstrassDiv [IsPrecomplete (IsLocalRing.maximalIdeal A) A] : A⟦X⟧ := open scoped Classical in if hg : g.map (IsLocalRing.residue A) ≠ 0 then (IsWeierstrassDivisor.of_map_ne_zero hg).div f else 0 /-- The remainder `r` in Weierstrass division, denoted by `f %ʷ g`. Note that when the image of `g` in the residue field is zero, this is defined to be zero. -/ noncomputable def weierstrassMod [IsPrecomplete (IsLocalRing.maximalIdeal A) A] : A[X] := open scoped Classical in if hg : g.map (IsLocalRing.residue A) ≠ 0 then (IsWeierstrassDivisor.of_map_ne_zero hg).mod f else 0 @[inherit_doc] infixl:70 " /ʷ " => weierstrassDiv @[inherit_doc] infixl:70 " %ʷ " => weierstrassMod @[simp] theorem weierstrassDiv_zero_right [IsPrecomplete (IsLocalRing.maximalIdeal A) A] : f /ʷ 0 = 0 := by rw [weierstrassDiv, dif_neg (by simp)] alias weierstrassDiv_zero := weierstrassDiv_zero_right @[simp] theorem weierstrassMod_zero_right [IsPrecomplete (IsLocalRing.maximalIdeal A) A] : f %ʷ 0 = 0 := by rw [weierstrassMod, dif_neg (by simp)] alias weierstrassMod_zero := weierstrassMod_zero_right theorem degree_weierstrassMod_lt [IsPrecomplete (IsLocalRing.maximalIdeal A) A] : (f %ʷ g).degree < (g.map (IsLocalRing.residue A)).order.toNat := by rw [weierstrassMod] split_ifs with hg · exact degree_trunc_lt _ _ · nontriviality A rw [Polynomial.degree_zero] exact WithBot.bot_lt_coe _ section variable {g} (hg : g.map (IsLocalRing.residue A) ≠ 0) include hg theorem isWeierstrassDivision_weierstrassDiv_weierstrassMod [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : f.IsWeierstrassDivision g (f /ʷ g) (f %ʷ g) := by simp_rw [weierstrassDiv, weierstrassMod, dif_pos hg] exact (IsWeierstrassDivisor.of_map_ne_zero hg).isWeierstrassDivisionAt_div_mod f theorem eq_mul_weierstrassDiv_add_weierstrassMod [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : f = g * (f /ʷ g) + (f %ʷ g) := by simp_rw [weierstrassDiv, weierstrassMod, dif_pos hg] exact ((IsWeierstrassDivisor.of_map_ne_zero hg).isWeierstrassDivisionAt_div_mod f).2 variable {f} in /-- The quotient `q` and the remainder `r` in the Weierstrass division are unique. This result is stated using two `PowerSeries.IsWeierstrassDivision` assertions, and only requires the ring being Hausdorff with respect to the maximal ideal. If you want `q` and `r` equal to `f /ʷ g` and `f %ʷ g`, use `PowerSeries.IsWeierstrassDivision.unique` instead, which requires the ring being complete with respect to the maximal ideal. -/ theorem IsWeierstrassDivision.elim [IsHausdorff (IsLocalRing.maximalIdeal A) A] {q q' : A⟦X⟧} {r r' : A[X]} (H : f.IsWeierstrassDivision g q r) (H2 : f.IsWeierstrassDivision g q' r') : q = q' ∧ r = r' := (IsWeierstrassDivisor.of_map_ne_zero hg).eq_of_mul_add_eq_mul_add H.1 H2.1 (H.2.symm.trans H2.2) /-- If `q` and `r` are quotient and remainder in the Weierstrass division `0 / g`, then they are equal to `0`. -/ theorem IsWeierstrassDivision.eq_zero [IsHausdorff (IsLocalRing.maximalIdeal A) A] {q : A⟦X⟧} {r : A[X]} (H : IsWeierstrassDivision 0 g q r) : q = 0 ∧ r = 0 := H.elim hg (g.isWeierstrassDivisionAt_zero _) variable {f} in /-- If `q` and `r` are quotient and remainder in the Weierstrass division `f / g`, then they are equal to `f /ʷ g` and `f %ʷ g`. -/ theorem IsWeierstrassDivision.unique [IsAdicComplete (IsLocalRing.maximalIdeal A) A] {q : A⟦X⟧} {r : A[X]} (H : f.IsWeierstrassDivision g q r) : q = f /ʷ g ∧ r = f %ʷ g := H.elim hg (f.isWeierstrassDivision_weierstrassDiv_weierstrassMod hg) end @[simp] theorem add_weierstrassDiv [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : (f + f') /ʷ g = f /ʷ g + f' /ʷ g := by simp_rw [weierstrassDiv] split_ifs <;> simp @[simp] theorem smul_weierstrassDiv [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : (a • f) /ʷ g = a • (f /ʷ g) := by simp_rw [weierstrassDiv] split_ifs <;> simp @[simp] theorem weierstrassDiv_zero_left [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : 0 /ʷ g = 0 := by simp_rw [weierstrassDiv] split_ifs <;> simp alias zero_weierstrassDiv := weierstrassDiv_zero_left @[simp] theorem add_weierstrassMod [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : (f + f') %ʷ g = f %ʷ g + f' %ʷ g := by simp_rw [weierstrassMod] split_ifs <;> simp @[simp] theorem smul_weierstrassMod [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : (a • f) %ʷ g = a • (f %ʷ g) := by simp_rw [weierstrassMod] split_ifs <;> simp @[simp] theorem weierstrassMod_zero_left [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : 0 %ʷ g = 0 := by simp_rw [weierstrassMod] split_ifs <;> simp alias zero_weierstrassMod := weierstrassMod_zero_left end IsLocalRing /-! ## Weierstrass preparation theorem -/ /-- If `f` is a polynomial over `A`, `g` and `h` are power series over `A`, then `PowerSeries.IsWeierstrassFactorizationAt g f h I` is a `Prop` which asserts that `f` is distinguished at `I`, `h` is a unit, such that `g = f * h`. -/ @[mk_iff] structure IsWeierstrassFactorizationAt (g : A⟦X⟧) (f : A[X]) (h : A⟦X⟧) (I : Ideal A) : Prop where isDistinguishedAt : f.IsDistinguishedAt I isUnit : IsUnit h eq_mul : g = f * h /-- Version of `PowerSeries.IsWeierstrassFactorizationAt` for local rings with respect to its maximal ideal. -/ abbrev IsWeierstrassFactorization (g : A⟦X⟧) (f : A[X]) (h : A⟦X⟧) [IsLocalRing A] : Prop := g.IsWeierstrassFactorizationAt f h (IsLocalRing.maximalIdeal A) namespace IsWeierstrassFactorizationAt variable {g : A⟦X⟧} {f : A[X]} {h : A⟦X⟧} {I : Ideal A} (H : g.IsWeierstrassFactorizationAt f h I) include H theorem map_ne_zero_of_ne_top (hI : I ≠ ⊤) : g.map (Ideal.Quotient.mk I) ≠ 0 := by have := Ideal.Quotient.nontrivial hI rw [congr(map (Ideal.Quotient.mk I) $(H.eq_mul)), map_mul, ← Polynomial.polynomial_map_coe, ne_eq, (H.isUnit.map _).mul_left_eq_zero] exact_mod_cast f.map_monic_ne_zero (f := Ideal.Quotient.mk I) H.isDistinguishedAt.monic theorem degree_eq_coe_lift_order_map_of_ne_top (hI : I ≠ ⊤) : f.degree = (g.map (Ideal.Quotient.mk I)).order.lift (order_finite_iff_ne_zero.2 (H.map_ne_zero_of_ne_top hI)) := by refine H.isDistinguishedAt.degree_eq_coe_lift_order_map g h ?_ H.eq_mul contrapose! hI exact Ideal.eq_top_of_isUnit_mem _ hI (isUnit_iff_constantCoeff.1 H.isUnit) theorem natDegree_eq_toNat_order_map_of_ne_top (hI : I ≠ ⊤) : f.natDegree = (g.map (Ideal.Quotient.mk I)).order.toNat := by rw [Polynomial.natDegree, H.degree_eq_coe_lift_order_map_of_ne_top hI, ENat.lift_eq_toNat_of_lt_top] exact WithBot.unbotD_coe _ _ /-- If `g = f * h` is a Weierstrass factorization, then there is a natural isomorphism `A[X] / (f) ≃ₐ[A] A⟦X⟧ / (g)`. -/ @[simps! apply] noncomputable def algEquivQuotient [IsAdicComplete I A] : (A[X] ⧸ Ideal.span {f}) ≃ₐ[A] A⟦X⟧ ⧸ Ideal.span {g} := H.isDistinguishedAt.algEquivQuotient.trans <| Ideal.quotientEquivAlgOfEq A <| by rw [H.eq_mul, Ideal.span_singleton_mul_right_unit H.isUnit] @[simp] theorem algEquivQuotient_symm_apply [IsAdicComplete I A] (x : A⟦X⟧ ⧸ Ideal.span {g}) : H.algEquivQuotient.symm x = Ideal.Quotient.mk _ (H.isDistinguishedAt.isWeierstrassDivisorAt'.mod' <| Ideal.quotientEquivAlgOfEq A (by rw [H.eq_mul, Ideal.span_singleton_mul_right_unit H.isUnit]) x) := by simp [algEquivQuotient] theorem mul {g' : A⟦X⟧} {f' : A[X]} {h' : A⟦X⟧} (H' : g'.IsWeierstrassFactorizationAt f' h' I) : (g * g').IsWeierstrassFactorizationAt (f * f') (h * h') I := ⟨H.isDistinguishedAt.mul H'.isDistinguishedAt, H.isUnit.mul H'.isUnit, by rw [H.eq_mul, H'.eq_mul, Polynomial.coe_mul]; ring⟩ theorem smul {a : A} (ha : IsUnit a) : (a • g).IsWeierstrassFactorizationAt f (a • h) I := by refine ⟨H.isDistinguishedAt, ?_, ?_⟩ · rw [Algebra.smul_def] exact (ha.map _).mul H.isUnit · simp [H.eq_mul] end IsWeierstrassFactorizationAt variable [IsLocalRing A] namespace IsWeierstrassFactorization variable {g : A⟦X⟧} {f : A[X]} {h : A⟦X⟧} (H : g.IsWeierstrassFactorization f h) include H theorem map_ne_zero : g.map (IsLocalRing.residue A) ≠ 0 := H.map_ne_zero_of_ne_top (Ideal.IsMaximal.ne_top inferInstance) theorem degree_eq_coe_lift_order_map : f.degree = (g.map (IsLocalRing.residue A)).order.lift (order_finite_iff_ne_zero.2 H.map_ne_zero) := H.degree_eq_coe_lift_order_map_of_ne_top (Ideal.IsMaximal.ne_top inferInstance) theorem natDegree_eq_toNat_order_map : f.natDegree = (g.map (IsLocalRing.residue A)).order.toNat := H.natDegree_eq_toNat_order_map_of_ne_top (Ideal.IsMaximal.ne_top inferInstance) end IsWeierstrassFactorization theorem IsWeierstrassDivision.isUnit_of_map_ne_zero {g q : A⟦X⟧} {r : A[X]} (hg : g.map (IsLocalRing.residue A) ≠ 0) (H : (X ^ (g.map (IsLocalRing.residue A)).order.toNat).IsWeierstrassDivision g q r) : IsUnit q := by obtain ⟨H1 : r.degree < (g.map (IsLocalRing.residue A)).order.toNat, H2⟩ := H set n := (g.map (IsLocalRing.residue A)).order.toNat replace H2 := congr(coeff _ n (($H2).map (IsLocalRing.residue A))) simp_rw [map_pow, map_X, coeff_X_pow_self, map_add, map_mul, coeff_map, Polynomial.coeff_coe, Polynomial.coeff_eq_zero_of_degree_lt H1, map_zero, add_zero] at H2 rw [isUnit_iff_constantCoeff, ← isUnit_map_iff (IsLocalRing.residue A)] rw [coeff_mul, ← Finset.sum_subset (s₁ := {(n, 0)}) (by simp) (fun p hp hnotMem ↦ ?_), Finset.sum_singleton, coeff_map, coeff_map, coeff_zero_eq_constantCoeff, mul_comm] at H2 · exact isUnit_of_mul_eq_one _ _ H2.symm · rw [coeff_of_lt_order p.1 ?_] · rw [zero_mul] · rw [← ENat.lt_lift_iff (h := order_finite_iff_ne_zero.2 hg), ENat.lift_eq_toNat_of_lt_top] refine (Finset.antidiagonal.fst_le hp).lt_of_ne ?_ contrapose! hnotMem rwa [Finset.mem_singleton, Finset.antidiagonal_congr hp (by simp)] theorem IsWeierstrassDivision.isWeierstrassFactorization {g q : A⟦X⟧} {r : A[X]} (hg : g.map (IsLocalRing.residue A) ≠ 0) (H : (X ^ (g.map (IsLocalRing.residue A)).order.toNat).IsWeierstrassDivision g q r) : g.IsWeierstrassFactorization (Polynomial.X ^ (g.map (IsLocalRing.residue A)).order.toNat - r) ↑(H.isUnit_of_map_ne_zero hg).unit⁻¹ := by have H1 : r.degree < (g.map (IsLocalRing.residue A)).order.toNat := H.1 set n := (g.map (IsLocalRing.residue A)).order.toNat set f := Polynomial.X ^ n - r replace H1 : r.degree < (Polynomial.X (R := A) ^ n).degree := by rwa [Polynomial.degree_X_pow] have hfdeg : f.natDegree = n := by suffices f.degree = n by rw [Polynomial.natDegree, this]; rfl rw [Polynomial.degree_sub_eq_left_of_degree_lt H1, Polynomial.degree_X_pow] refine ⟨⟨⟨fun {i} hi ↦ ?_⟩, .sub_of_left (Polynomial.monic_X_pow _) H1⟩, Units.isUnit _, ?_⟩ · rw [hfdeg] at hi simp_rw [f, Polynomial.coeff_sub, Polynomial.coeff_X_pow, if_neg hi.ne, zero_sub, neg_mem_iff] have := H.coeff_f_sub_r_mem hi rwa [map_sub, coeff_X_pow, if_neg hi.ne, zero_sub, neg_mem_iff, Polynomial.coeff_coe] at this · have := congr($(H.2) * ↑(H.isUnit_of_map_ne_zero hg).unit⁻¹) rw [add_mul, mul_assoc, IsUnit.mul_val_inv, mul_one, ← sub_eq_iff_eq_add] at this simp_rw [← this, f, Polynomial.coe_sub, Polynomial.coe_pow, Polynomial.coe_X, sub_mul] theorem IsWeierstrassFactorization.isWeierstrassDivision {g : A⟦X⟧} {f : A[X]} {h : A⟦X⟧} (H : g.IsWeierstrassFactorization f h) : (X ^ (g.map (IsLocalRing.residue A)).order.toNat).IsWeierstrassDivision g ↑H.isUnit.unit⁻¹ (Polynomial.X ^ (g.map (IsLocalRing.residue A)).order.toNat - f) := by set n := (g.map (IsLocalRing.residue A)).order.toNat with hn constructor · refine (Polynomial.degree_sub_lt ?_ (Polynomial.monic_X_pow n).ne_zero ?_).trans_eq (by simpa) · simp_rw [H.degree_eq_coe_lift_order_map, Polynomial.degree_X_pow, n, ENat.lift_eq_toNat_of_lt_top] · rw [(Polynomial.monic_X_pow n).leadingCoeff, H.isDistinguishedAt.monic.leadingCoeff] · simp_rw [H.eq_mul, mul_assoc, IsUnit.mul_val_inv, mul_one, Polynomial.coe_sub, Polynomial.coe_pow, Polynomial.coe_X, add_sub_cancel] /-- The `f` and `h` in the Weierstrass preparation theorem are unique. This result is stated using two `PowerSeries.IsWeierstrassFactorization` assertions, and only requires the ring being Hausdorff with respect to the maximal ideal. If you want `f` and `h` equal to `PowerSeries.weierstrassDistinguished` and `PowerSeries.weierstrassUnit`, use `PowerSeries.IsWeierstrassFactorization.unique` instead, which requires the ring being complete with respect to the maximal ideal. -/ theorem IsWeierstrassFactorization.elim [IsHausdorff (IsLocalRing.maximalIdeal A) A] {g : A⟦X⟧} {f f' : A[X]} {h h' : A⟦X⟧} (H : g.IsWeierstrassFactorization f h) (H2 : g.IsWeierstrassFactorization f' h') : f = f' ∧ h = h' := by obtain ⟨h1, h2⟩ := H.isWeierstrassDivision.elim H.map_ne_zero H2.isWeierstrassDivision rw [← Units.ext_iff, inv_inj, Units.ext_iff] at h1 exact ⟨by simpa using h2, h1⟩ section IsAdicComplete variable [IsAdicComplete (IsLocalRing.maximalIdeal A) A] {a : A} {g g' : A⟦X⟧} {f : A[X]} {h : A⟦X⟧} /-- **Weierstrass preparation theorem** ([washington_cyclotomic], Theorem 7.3): let `g` be a power series over a complete local ring, such that its image in the residue field is not zero. Then there exists a distinguished polynomial `f` and a power series `h` which is a unit, such that `g = f * h`. -/ theorem exists_isWeierstrassFactorization (hg : g.map (IsLocalRing.residue A) ≠ 0) : ∃ f h, g.IsWeierstrassFactorization f h := by obtain ⟨q, r, H⟩ := (X ^ (g.map (IsLocalRing.residue A)).order.toNat).exists_isWeierstrassDivision hg exact ⟨_, _, H.isWeierstrassFactorization hg⟩ variable (g) in /-- The `f` in the Weierstrass preparation theorem. -/ noncomputable def weierstrassDistinguished (hg : g.map (IsLocalRing.residue A) ≠ 0) : A[X] := (g.exists_isWeierstrassFactorization hg).choose variable (g) in /-- The `h` in the Weierstrass preparation theorem. -/ noncomputable def weierstrassUnit (hg : g.map (IsLocalRing.residue A) ≠ 0) : A⟦X⟧ := (g.exists_isWeierstrassFactorization hg).choose_spec.choose theorem isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (hg : g.map (IsLocalRing.residue A) ≠ 0) : g.IsWeierstrassFactorization (g.weierstrassDistinguished hg) (g.weierstrassUnit hg) := (g.exists_isWeierstrassFactorization hg).choose_spec.choose_spec /-- If `g` is a power series over a complete local ring, such that its image in the residue field is not zero, then there is a natural isomorphism `A[X] / (f) ≃ₐ[A] A⟦X⟧ / (g)` where `f` is `PowerSeries.weierstrassDistinguished g`. -/ noncomputable abbrev algEquivQuotientWeierstrassDistinguished (hg : g.map (IsLocalRing.residue A) ≠ 0) := (g.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit hg).algEquivQuotient theorem isDistinguishedAt_weierstrassDistinguished (hg : g.map (IsLocalRing.residue A) ≠ 0) : (g.weierstrassDistinguished hg).IsDistinguishedAt (IsLocalRing.maximalIdeal A) := (g.exists_isWeierstrassFactorization hg).choose_spec.choose_spec.isDistinguishedAt theorem isUnit_weierstrassUnit (hg : g.map (IsLocalRing.residue A) ≠ 0) : IsUnit (g.weierstrassUnit hg) := (g.exists_isWeierstrassFactorization hg).choose_spec.choose_spec.isUnit theorem eq_weierstrassDistinguished_mul_weierstrassUnit (hg : g.map (IsLocalRing.residue A) ≠ 0) : g = g.weierstrassDistinguished hg * g.weierstrassUnit hg := (g.exists_isWeierstrassFactorization hg).choose_spec.choose_spec.eq_mul /-- The `f` and `h` in Weierstrass preparation theorem are equal to `PowerSeries.weierstrassDistinguished` and `PowerSeries.weierstrassUnit`. -/ theorem IsWeierstrassFactorization.unique (H : g.IsWeierstrassFactorization f h) (hg : g.map (IsLocalRing.residue A) ≠ 0) : f = g.weierstrassDistinguished hg ∧ h = g.weierstrassUnit hg := H.elim (g.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit hg) @[simp] theorem weierstrassDistinguished_mul (hg : (g * g').map (IsLocalRing.residue A) ≠ 0) : (g * g').weierstrassDistinguished hg = g.weierstrassDistinguished (fun h ↦ hg (by simp [h])) * g'.weierstrassDistinguished (fun h ↦ hg (by simp [h])) := by have H := g.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (fun h ↦ hg (by simp [h])) have H' := g'.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (fun h ↦ hg (by simp [h])) have H'' := (g * g').isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit hg exact (H''.elim (H.mul H')).1 @[simp] theorem weierstrassUnit_mul (hg : (g * g').map (IsLocalRing.residue A) ≠ 0) : (g * g').weierstrassUnit hg = g.weierstrassUnit (fun h ↦ hg (by simp [h])) * g'.weierstrassUnit (fun h ↦ hg (by simp [h])) := by have H := g.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (fun h ↦ hg (by simp [h])) have H' := g'.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (fun h ↦ hg (by simp [h])) have H'' := (g * g').isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit hg exact (H''.elim (H.mul H')).2 @[simp] theorem weierstrassDistinguished_smul (hg : (a • g).map (IsLocalRing.residue A) ≠ 0) : (a • g).weierstrassDistinguished hg = g.weierstrassDistinguished (fun h ↦ hg (by simp [Algebra.smul_def, h])) := by have H := g.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (fun h ↦ hg (by simp [Algebra.smul_def, h])) have H' := (a • g).isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit hg have ha : IsLocalRing.residue A a ≠ 0 := fun h ↦ hg (by simp [Algebra.smul_def, h]) exact (H'.elim (H.smul (by simpa using ha))).1 @[simp] theorem weierstrassUnit_smul (hg : (a • g).map (IsLocalRing.residue A) ≠ 0) : (a • g).weierstrassUnit hg = a • g.weierstrassUnit (fun h ↦ hg (by simp [Algebra.smul_def, h])) := by have H := g.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (fun h ↦ hg (by simp [Algebra.smul_def, h])) have H' := (a • g).isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit hg have ha : IsLocalRing.residue A a ≠ 0 := fun h ↦ hg (by simp [Algebra.smul_def, h]) exact (H'.elim (H.smul (by simpa using ha))).2 end IsAdicComplete end PowerSeries
OrderIso.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, Patrick Massot, Yury Kudryashov, Rémy Degenne -/ import Mathlib.Order.Interval.Set.Basic import Mathlib.Order.Hom.Set /-! # Lemmas about images of intervals under order isomorphisms. -/ open Set namespace OrderIso section Preorder variable {α β : Type*} [Preorder α] [Preorder β] @[simp] theorem preimage_Iic (e : α ≃o β) (b : β) : e ⁻¹' Iic b = Iic (e.symm b) := by ext x simp [← e.le_iff_le] @[simp] theorem preimage_Ici (e : α ≃o β) (b : β) : e ⁻¹' Ici b = Ici (e.symm b) := by ext x simp [← e.le_iff_le] @[simp] theorem preimage_Iio (e : α ≃o β) (b : β) : e ⁻¹' Iio b = Iio (e.symm b) := by ext x simp [← e.lt_iff_lt] @[simp] theorem preimage_Ioi (e : α ≃o β) (b : β) : e ⁻¹' Ioi b = Ioi (e.symm b) := by ext x simp [← e.lt_iff_lt] @[simp] theorem preimage_Icc (e : α ≃o β) (a b : β) : e ⁻¹' Icc a b = Icc (e.symm a) (e.symm b) := by simp [← Ici_inter_Iic] @[simp] theorem preimage_Ico (e : α ≃o β) (a b : β) : e ⁻¹' Ico a b = Ico (e.symm a) (e.symm b) := by simp [← Ici_inter_Iio] @[simp] theorem preimage_Ioc (e : α ≃o β) (a b : β) : e ⁻¹' Ioc a b = Ioc (e.symm a) (e.symm b) := by simp [← Ioi_inter_Iic] @[simp] theorem preimage_Ioo (e : α ≃o β) (a b : β) : e ⁻¹' Ioo a b = Ioo (e.symm a) (e.symm b) := by simp [← Ioi_inter_Iio] @[simp] theorem image_Iic (e : α ≃o β) (a : α) : e '' Iic a = Iic (e a) := by rw [e.image_eq_preimage, e.symm.preimage_Iic, e.symm_symm] @[simp] theorem image_Ici (e : α ≃o β) (a : α) : e '' Ici a = Ici (e a) := e.dual.image_Iic a @[simp] theorem image_Iio (e : α ≃o β) (a : α) : e '' Iio a = Iio (e a) := by rw [e.image_eq_preimage, e.symm.preimage_Iio, e.symm_symm] @[simp] theorem image_Ioi (e : α ≃o β) (a : α) : e '' Ioi a = Ioi (e a) := e.dual.image_Iio a @[simp] theorem image_Ioo (e : α ≃o β) (a b : α) : e '' Ioo a b = Ioo (e a) (e b) := by rw [e.image_eq_preimage, e.symm.preimage_Ioo, e.symm_symm] @[simp] theorem image_Ioc (e : α ≃o β) (a b : α) : e '' Ioc a b = Ioc (e a) (e b) := by rw [e.image_eq_preimage, e.symm.preimage_Ioc, e.symm_symm] @[simp] theorem image_Ico (e : α ≃o β) (a b : α) : e '' Ico a b = Ico (e a) (e b) := by rw [e.image_eq_preimage, e.symm.preimage_Ico, e.symm_symm] @[simp] theorem image_Icc (e : α ≃o β) (a b : α) : e '' Icc a b = Icc (e a) (e b) := by rw [e.image_eq_preimage, e.symm.preimage_Icc, e.symm_symm] end Preorder /-- Order isomorphism between `Iic (⊤ : α)` and `α` when `α` has a top element -/ def IicTop {α : Type*} [Preorder α] [OrderTop α] : Iic (⊤ : α) ≃o α := { @Equiv.subtypeUnivEquiv α (Iic (⊤ : α)) fun _ => le_top with map_rel_iff' := @fun x y => by rfl } /-- Order isomorphism between `Ici (⊥ : α)` and `α` when `α` has a bottom element -/ def IciBot {α : Type*} [Preorder α] [OrderBot α] : Ici (⊥ : α) ≃o α := { @Equiv.subtypeUnivEquiv α (Ici (⊥ : α)) fun _ => bot_le with map_rel_iff' := @fun x y => by rfl } end OrderIso
FrameAdjunction.lean
/- Copyright (c) 2023 Anne Baanen, Sam van Gool, Leo Mayer, Brendan Murphy. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Sam van Gool, Leo Mayer, Brendan Murphy -/ import Mathlib.Topology.Category.Locale /-! # Adjunction between Locales and Topological Spaces This file defines the point functor from the category of locales to topological spaces and proves that it is right adjoint to the forgetful functor from topological spaces to locales. ## Main declarations * `Locale.pt`: the *points* functor from the category of locales to the category of topological spaces. * `Locale.adjunctionTopToLocalePT`: the adjunction between the functors `topToLocale` and `pt`. ## Motivation This adjunction provides a framework in which several Stone-type dualities fit. ## Implementation notes * In naming the various functions below, we follow common terminology and reserve the word *point* for an inhabitant of a type `X` which is a topological space, while we use the word *element* for an inhabitant of a type `L` which is a locale. ## References * [J. Picado and A. Pultr, Frames and Locales: topology without points][picado2011frames] ## Tags topological space, frame, locale, Stone duality, adjunction, points -/ open CategoryTheory Order Set Topology TopologicalSpace namespace Locale /-! ### Definition of the points functor `pt` -/ section pt_definition variable (L : Type*) [CompleteLattice L] /-- The type of points of a complete lattice `L`, where a *point* of a complete lattice is, by definition, a frame homomorphism from `L` to `Prop`. -/ abbrev PT := FrameHom L Prop /-- The frame homomorphism from a complete lattice `L` to the complete lattice of sets of points of `L`. -/ @[simps] def openOfElementHom : FrameHom L (Set (PT L)) where toFun u := {x | x u} map_inf' a b := by simp [Set.setOf_and] map_top' := by simp map_sSup' S := by ext; simp [Prop.exists_iff] namespace PT /-- The topology on the set of points of the complete lattice `L`. -/ instance instTopologicalSpace : TopologicalSpace (PT L) where IsOpen s := ∃ u, {x | x u} = s isOpen_univ := ⟨⊤, by simp⟩ isOpen_inter := by rintro s t ⟨u, rfl⟩ ⟨v, rfl⟩; use u ⊓ v; simp_rw [map_inf]; rfl isOpen_sUnion S hS := by choose f hf using hS use ⨆ t, ⨆ ht, f t ht simp_rw [map_iSup, iSup_Prop_eq, setOf_exists, hf, sUnion_eq_biUnion] /-- Characterization of when a subset of the space of points is open. -/ lemma isOpen_iff (U : Set (PT L)) : IsOpen U ↔ ∃ u : L, {x | x u} = U := Iff.rfl end PT /-- The covariant functor `pt` from the category of locales to the category of topological spaces, which sends a locale `L` to the topological space `PT L` of homomorphisms from `L` to `Prop` and a locale homomorphism `f` to a continuous function between the spaces of points. -/ def pt : Locale ⥤ TopCat where obj L := .of (PT L.unop) map f := TopCat.ofHom ⟨fun p ↦ p.comp f.unop.hom, continuous_def.2 <| by rintro s ⟨u, rfl⟩; use f.unop u; rfl⟩ end pt_definition section locale_top_adjunction variable (X : Type*) [TopologicalSpace X] (L : Locale) /-- The unit of the adjunction between locales and topological spaces, which associates with a point `x` of the space `X` a point of the locale of opens of `X`. -/ @[simps] def localePointOfSpacePoint (x : X) : PT (Opens X) where toFun := (x ∈ ·) map_inf' _ _ := rfl map_top' := rfl map_sSup' S := by simp [Prop.exists_iff] /-- The counit is a frame homomorphism. -/ def counitAppCont : FrameHom L (Opens <| PT L) where toFun u := ⟨openOfElementHom L u, u, rfl⟩ map_inf' a b := by simp map_top' := by simp map_sSup' S := by ext; simp /-- The forgetful functor `topToLocale` is left adjoint to the functor `pt`. -/ def adjunctionTopToLocalePT : topToLocale ⊣ pt where unit := { app := fun X ↦ TopCat.ofHom ⟨localePointOfSpacePoint X, continuous_def.2 <| by rintro _ ⟨u, rfl⟩; simpa using u.2⟩ } counit := { app := fun L ↦ ⟨Frm.ofHom (counitAppCont L)⟩ } end locale_top_adjunction end Locale
Lemmas.lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Alexander Bentkamp, Anne Baanen -/ import Mathlib.Data.Fin.Tuple.Reflection import Mathlib.LinearAlgebra.Finsupp.SumProd import Mathlib.LinearAlgebra.LinearIndependent.Basic import Mathlib.LinearAlgebra.Pi import Mathlib.Logic.Equiv.Fin.Rotate import Mathlib.Tactic.FinCases import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Module import Mathlib.Tactic.NoncommRing /-! # Linear independence This file collects consequences of linear (in)dependence and includes specialized tests for specific families of vectors, requiring more theory to state. ## Main statements We prove several specialized tests for linear independence of families of vectors and of sets of vectors. * `linearIndependent_option`, `linearIndependent_fin_cons`, `linearIndependent_fin_succ`: type-specific tests for linear independence of families of vector fields; * `linearIndependent_insert`, `linearIndependent_pair`: linear independence tests for set operations In many cases we additionally provide dot-style operations (e.g., `LinearIndependent.union`) to make the linear independence tests usable as `hv.insert ha` etc. We also prove that, when working over a division ring, any family of vectors includes a linear independent subfamily spanning the same subspace. ## TODO Rework proofs to hold in semirings, by avoiding the path through `ker (Finsupp.linearCombination R v) = ⊥`. ## Tags linearly dependent, linear dependence, linearly independent, linear independence -/ assert_not_exists Cardinal noncomputable section open Function Set Submodule universe u' u variable {ι : Type u'} {ι' : Type*} {R : Type*} {K : Type*} {s : Set ι} variable {M : Type*} {M' : Type*} {V : Type u} section Semiring variable {v : ι → M} variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M'] variable [Module R M] [Module R M'] variable (R) (v) variable {R v} /-- A finite family of vectors `v i` is linear independent iff the linear map that sends `c : ι → R` to `∑ i, c i • v i` is injective. -/ theorem Fintype.linearIndependent_iff'ₛ [Fintype ι] [DecidableEq ι] : LinearIndependent R v ↔ Injective (LinearMap.lsum R (fun _ ↦ R) ℕ fun i ↦ LinearMap.id.smulRight (v i)) := by simp [Fintype.linearIndependent_iffₛ, Injective, funext_iff] lemma LinearIndependent.pair_iffₛ {x y : M} : LinearIndependent R ![x, y] ↔ ∀ (s t s' t' : R), s • x + t • y = s' • x + t' • y → s = s' ∧ t = t' := by simp [Fintype.linearIndependent_iffₛ, Fin.forall_fin_two, ← FinVec.forall_iff]; rfl lemma LinearIndependent.eq_of_pair {x y : M} (h : LinearIndependent R ![x, y]) {s t s' t' : R} (h' : s • x + t • y = s' • x + t' • y) : s = s' ∧ t = t' := pair_iffₛ.mp h _ _ _ _ h' lemma LinearIndependent.eq_zero_of_pair' {x y : M} (h : LinearIndependent R ![x, y]) {s t : R} (h' : s • x = t • y) : s = 0 ∧ t = 0 := by suffices H : s = 0 ∧ 0 = t from ⟨H.1, H.2.symm⟩ exact h.eq_of_pair (by simpa using h') lemma LinearIndependent.eq_zero_of_pair {x y : M} (h : LinearIndependent R ![x, y]) {s t : R} (h' : s • x + t • y = 0) : s = 0 ∧ t = 0 := by replace h := @h (.single 0 s + .single 1 t) 0 ?_ · exact ⟨by simpa using congr($h 0), by simpa using congr($h 1)⟩ simpa section Indexed theorem linearIndepOn_iUnion_of_directed {η : Type*} {s : η → Set ι} (hs : Directed (· ⊆ ·) s) (h : ∀ i, LinearIndepOn R v (s i)) : LinearIndepOn R v (⋃ i, s i) := by by_cases hη : Nonempty η · refine linearIndepOn_of_finite (⋃ i, s i) fun t ht ft => ?_ rcases finite_subset_iUnion ft ht with ⟨I, fi, hI⟩ rcases hs.finset_le fi.toFinset with ⟨i, hi⟩ exact (h i).mono (Subset.trans hI <| iUnion₂_subset fun j hj => hi j (fi.mem_toFinset.2 hj)) · refine (linearIndepOn_empty R v).mono (t := iUnion (s ·)) ?_ rintro _ ⟨_, ⟨i, _⟩, _⟩ exact hη ⟨i⟩ @[deprecated (since := "2025-02-15")] alias linearIndependent_iUnion_of_directed := linearIndepOn_iUnion_of_directed theorem linearIndepOn_sUnion_of_directed {s : Set (Set ι)} (hs : DirectedOn (· ⊆ ·) s) (h : ∀ a ∈ s, LinearIndepOn R v a) : LinearIndepOn R v (⋃₀ s) := by rw [sUnion_eq_iUnion] exact linearIndepOn_iUnion_of_directed hs.directed_val (by simpa using h) @[deprecated (since := "2025-02-15")] alias linearIndependent_sUnion_of_directed := linearIndepOn_sUnion_of_directed theorem linearIndepOn_biUnion_of_directed {η} {s : Set η} {t : η → Set ι} (hs : DirectedOn (t ⁻¹'o (· ⊆ ·)) s) (h : ∀ a ∈ s, LinearIndepOn R v (t a)) : LinearIndepOn R v (⋃ a ∈ s, t a) := by rw [biUnion_eq_iUnion] exact linearIndepOn_iUnion_of_directed (directed_comp.2 <| hs.directed_val) (by simpa using h) @[deprecated (since := "2025-02-15")] alias linearIndependent_biUnion_of_directed := linearIndepOn_biUnion_of_directed end Indexed section repr variable (hv : LinearIndependent R v) /-- See also `iSupIndep_iff_linearIndependent_of_ne_zero`. -/ theorem LinearIndependent.iSupIndep_span_singleton (hv : LinearIndependent R v) : iSupIndep fun i => R ∙ v i := by refine iSupIndep_def.mp fun i => ?_ rw [disjoint_iff_inf_le] intro m hm simp only [mem_inf, mem_span_singleton, iSup_subtype'] at hm rw [← span_range_eq_iSup] at hm obtain ⟨⟨r, rfl⟩, hm⟩ := hm suffices r = 0 by simp [this] apply hv.eq_zero_of_smul_mem_span i convert hm ext simp end repr section union open LinearMap Finsupp theorem linearIndependent_inl_union_inr' {v : ι → M} {v' : ι' → M'} (hv : LinearIndependent R v) (hv' : LinearIndependent R v') : LinearIndependent R (Sum.elim (inl R M M' ∘ v) (inr R M M' ∘ v')) := by have : linearCombination R (Sum.elim (inl R M M' ∘ v) (inr R M M' ∘ v')) = .prodMap (linearCombination R v) (linearCombination R v') ∘ₗ (sumFinsuppLEquivProdFinsupp R).toLinearMap := by ext (_ | _) <;> simp [linearCombination_comapDomain] rw [LinearIndependent, this] simpa [LinearMap.coe_prodMap] using ⟨hv, hv'⟩ theorem LinearIndependent.inl_union_inr {s : Set M} {t : Set M'} (hs : LinearIndependent R (fun x => x : s → M)) (ht : LinearIndependent R (fun x => x : t → M')) : LinearIndependent R (fun x => x : ↥(inl R M M' '' s ∪ inr R M M' '' t) → M × M') := by nontriviality R let e : s ⊕ t ≃ ↥(inl R M M' '' s ∪ inr R M M' '' t) := .ofBijective (Sum.elim (fun i ↦ ⟨_, .inl ⟨_, i.2, rfl⟩⟩) fun i ↦ ⟨_, .inr ⟨_, i.2, rfl⟩⟩) ⟨by rintro (_ | _) (_ | _) eq <;> simp [hs.ne_zero, ht.ne_zero] at eq <;> aesop, by rintro ⟨_, ⟨_, _, rfl⟩ | ⟨_, _, rfl⟩⟩ <;> aesop⟩ refine (linearIndependent_equiv' e ?_).mp (linearIndependent_inl_union_inr' hs ht) ext (_ | _) <;> rfl end union section Maximal universe v w variable (R) /-- TODO : refactor to use `Maximal`. -/ theorem exists_maximal_linearIndepOn' (v : ι → M) : ∃ s : Set ι, (LinearIndepOn R v s) ∧ ∀ t : Set ι, s ⊆ t → (LinearIndepOn R v t) → s = t := by let indep : Set ι → Prop := fun s => LinearIndepOn R v s let X := { I : Set ι // indep I } let r : X → X → Prop := fun I J => I.1 ⊆ J.1 have key : ∀ c : Set X, IsChain r c → indep (⋃ (I : X) (_ : I ∈ c), I) := by intro c hc dsimp [indep] rw [linearIndepOn_iffₛ] intro f hfsupp g hgsupp hsum rcases eq_empty_or_nonempty c with (rfl | hn) · rw [show f = 0 by simpa using hfsupp, show g = 0 by simpa using hgsupp] haveI : IsRefl X r := ⟨fun _ => Set.Subset.refl _⟩ classical obtain ⟨I, _I_mem, hI⟩ : ∃ I ∈ c, (f.support ∪ g.support : Set ι) ⊆ I := f.support.coe_union _ ▸ hc.directedOn.exists_mem_subset_of_finset_subset_biUnion hn <| by simpa using And.intro hfsupp hgsupp exact linearIndepOn_iffₛ.mp I.2 f (subset_union_left.trans hI) g (subset_union_right.trans hI) hsum have trans : Transitive r := fun I J K => Set.Subset.trans obtain ⟨⟨I, hli : indep I⟩, hmax : ∀ a, r ⟨I, hli⟩ a → r a ⟨I, hli⟩⟩ := exists_maximal_of_chains_bounded (fun c hc => ⟨⟨⋃ I ∈ c, (I : Set ι), key c hc⟩, fun I => Set.subset_biUnion_of_mem⟩) @trans exact ⟨I, hli, fun J hsub hli => Set.Subset.antisymm hsub (hmax ⟨J, hli⟩ hsub)⟩ @[deprecated (since := "2025-02-15")] alias exists_maximal_independent' := exists_maximal_linearIndepOn' end Maximal end Semiring section Module variable {v : ι → M} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] variable [Module R M] [Module R M'] /-- A finite family of vectors `v i` is linear independent iff the linear map that sends `c : ι → R` to `∑ i, c i • v i` has the trivial kernel. -/ theorem Fintype.linearIndependent_iff' [Fintype ι] [DecidableEq ι] : LinearIndependent R v ↔ LinearMap.ker (LinearMap.lsum R (fun _ ↦ R) ℕ fun i ↦ LinearMap.id.smulRight (v i)) = ⊥ := by simp [Fintype.linearIndependent_iff, LinearMap.ker_eq_bot', funext_iff] /-- `linearIndepOn_pair_iff` is a simpler version over fields. -/ lemma LinearIndepOn.pair_iff {i j : ι} (f : ι → M) (hij : i ≠ j) : LinearIndepOn R f {i,j} ↔ ∀ c d : R, c • f i + d • f j = 0 → c = 0 ∧ d = 0 := by classical rw [linearIndepOn_iff''] refine ⟨fun h c d hcd ↦ ?_, fun h t g ht hg0 h0 ↦ ?_⟩ · specialize h {i, j} (Pi.single i c + Pi.single j d) simpa +contextual [Finset.sum_pair, Pi.single_apply, hij, hij.symm, hcd] using h have ht' : t ⊆ {i, j} := by simpa [← Finset.coe_subset] rw [Finset.sum_subset ht', Finset.sum_pair hij] at h0 · obtain ⟨hi0, hj0⟩ := h _ _ h0 exact fun k hkt ↦ Or.elim (ht hkt) (fun h ↦ h ▸ hi0) (fun h ↦ h ▸ hj0) simp +contextual [hg0] section Pair variable {x y : M} /-- Also see `LinearIndependent.pair_iff'` for a simpler version over fields. -/ lemma LinearIndependent.pair_iff : LinearIndependent R ![x, y] ↔ ∀ (s t : R), s • x + t • y = 0 → s = 0 ∧ t = 0 := by rw [← linearIndepOn_univ, ← Finset.coe_univ, show @Finset.univ (Fin 2) _ = {0,1} from rfl, Finset.coe_insert, Finset.coe_singleton, LinearIndepOn.pair_iff _ (by trivial)] simp lemma LinearIndependent.pair_symm_iff : LinearIndependent R ![x, y] ↔ LinearIndependent R ![y, x] := by suffices ∀ x y : M, LinearIndependent R ![x, y] → LinearIndependent R ![y, x] by tauto simp only [LinearIndependent.pair_iff] intro x y h s t specialize h t s rwa [add_comm, and_comm] @[simp] lemma LinearIndependent.pair_neg_left_iff : LinearIndependent R ![-x, y] ↔ LinearIndependent R ![x, y] := by rw [pair_iff, pair_iff] refine ⟨fun h s t hst ↦ ?_, fun h s t hst ↦ ?_⟩ <;> simpa using h (-s) t (by simpa using hst) @[simp] lemma LinearIndependent.pair_neg_right_iff : LinearIndependent R ![x, -y] ↔ LinearIndependent R ![x, y] := by rw [pair_symm_iff, pair_neg_left_iff, pair_symm_iff] variable {S : Type*} [CommRing S] [Module S R] [Module S M] [SMulCommClass S R M] [IsScalarTower S R M] [NoZeroSMulDivisors S R] (a b c d : S) lemma LinearIndependent.pair_smul_iff {u : S} (hu : u ≠ 0) : LinearIndependent R ![u • x, u • y] ↔ LinearIndependent R ![x, y] := by simp only [LinearIndependent.pair_iff] refine ⟨fun h s t hst ↦ ?_, fun h s t hst ↦ ?_⟩ · exact h s t (by rw [← smul_comm u s, ← smul_comm u t, ← smul_add, hst, smul_zero]) · specialize h (u • s) (u • t) (by rw [smul_assoc, smul_assoc, smul_comm u s, smul_comm u t, hst]) exact ⟨(smul_eq_zero_iff_right hu).mp h.1, (smul_eq_zero_iff_right hu).mp h.2⟩ private lemma LinearIndependent.pair_add_smul_add_smul_iff_aux (h : a * d ≠ b * c) (h' : LinearIndependent R ![x, y]) : LinearIndependent R ![a • x + b • y, c • x + d • y] := by simp only [LinearIndependent.pair_iff] at h' ⊢ intro s t hst specialize h' (a • s + c • t) (b • s + d • t) (by simp only [← hst, smul_add, add_smul, smul_assoc, smul_comm a s, smul_comm c t, smul_comm b s, smul_comm d t]; abel) obtain ⟨h₁, h₂⟩ := h' constructor · suffices (a * d) • s = (b * c) • s by by_contra hs; exact h (_root_.smul_left_injective S hs ‹_›) calc (a * d) • s = d • a • s := by rw [mul_comm, mul_smul] _ = - (d • c • t) := by rw [eq_neg_iff_add_eq_zero, ← smul_add, h₁, smul_zero] _ = (b * c) • s := ?_ · rw [mul_comm, mul_smul, neg_eq_iff_add_eq_zero, add_comm, smul_comm d c, ← smul_add, h₂, smul_zero] · suffices (a * d) • t = (b * c) • t by by_contra ht; exact h (_root_.smul_left_injective S ht ‹_›) calc (a * d) • t = a • d • t := by rw [mul_smul] _ = - (a • b • s) := by rw [eq_neg_iff_add_eq_zero, ← smul_add, add_comm, h₂, smul_zero] _ = (b * c) • t := ?_ · rw [mul_smul, neg_eq_iff_add_eq_zero, smul_comm a b, ← smul_add, h₁, smul_zero] @[simp] lemma LinearIndependent.pair_add_smul_add_smul_iff [Nontrivial R] : LinearIndependent R ![a • x + b • y, c • x + d • y] ↔ LinearIndependent R ![x, y] ∧ a * d ≠ b * c := by rcases eq_or_ne (a * d) (b * c) with h | h · suffices ¬ LinearIndependent R ![a • x + b • y, c • x + d • y] by simpa [h] rw [pair_iff] push_neg by_cases hbd : b = 0 ∧ d = 0 · simp only [hbd.1, hbd.2, zero_smul, add_zero] by_cases hac : a = 0 ∧ c = 0; · exact ⟨1, 0, by simp [hac.1, hac.2], by simp⟩ refine ⟨c • 1, -a • 1, ?_, by aesop⟩ simp only [smul_assoc, one_smul, neg_smul] module refine ⟨d • 1, -b • 1, ?_, by contrapose! hbd; aesop⟩ simp only [smul_add, smul_assoc, one_smul, smul_smul, mul_comm d, h] module refine ⟨fun h' ↦ ⟨?_, h⟩, fun ⟨h₁, h₂⟩ ↦ pair_add_smul_add_smul_iff_aux _ _ _ _ h₂ h₁⟩ suffices LinearIndependent R ![(a * d - b * c) • x, (a * d - b * c) • y] by rwa [pair_smul_iff (sub_ne_zero_of_ne h)] at this convert pair_add_smul_add_smul_iff_aux d (-b) (-c) a (by simpa [mul_comm d a]) h' using 1 ext i; fin_cases i <;> simp <;> module @[deprecated (since := "2025-04-15")] alias LinearIndependent.linear_combination_pair_of_det_ne_zero := LinearIndependent.pair_add_smul_add_smul_iff @[simp] lemma LinearIndependent.pair_add_smul_right_iff : LinearIndependent R ![x, c • x + y] ↔ LinearIndependent R ![x, y] := by rcases subsingleton_or_nontrivial S with hS | hS; · simp [hS.elim c 0] nontriviality R simpa using pair_add_smul_add_smul_iff (x := x) (y := y) 1 0 c 1 @[simp] lemma LinearIndependent.pair_add_smul_left_iff : LinearIndependent R ![x + b • y, y] ↔ LinearIndependent R ![x, y] := by rcases subsingleton_or_nontrivial S with hS | hS; · simp [hS.elim b 0] nontriviality R simpa using pair_add_smul_add_smul_iff (x := x) (y := y) 1 b 0 1 @[simp] lemma LinearIndependent.pair_add_right_iff : LinearIndependent R ![x, x + y] ↔ LinearIndependent R ![x, y] := by suffices ∀ x y : M, LinearIndependent R ![x, x + y] → LinearIndependent R ![x, y] from ⟨this x y, fun h ↦ by simpa using this (-x) (x + y) (by simpa)⟩ simp only [LinearIndependent.pair_iff] intro x y h s t h' obtain ⟨h₁, h₂⟩ := h (s - t) t (by rw [sub_smul, smul_add, ← h']; abel) rw [h₂, sub_zero] at h₁ tauto @[simp] lemma LinearIndependent.pair_add_left_iff : LinearIndependent R ![x + y, y] ↔ LinearIndependent R ![x, y] := by rw [← pair_symm_iff, add_comm, pair_add_right_iff, pair_symm_iff] end Pair end Module /-! ### Properties which require `Ring R` -/ section Module variable {v : ι → M} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] variable [Module R M] [Module R M'] theorem linearIndepOn_id_iUnion_finite {f : ι → Set M} (hl : ∀ i, LinearIndepOn R id (f i)) (hd : ∀ i, ∀ t : Set ι, t.Finite → i ∉ t → Disjoint (span R (f i)) (⨆ i ∈ t, span R (f i))) : LinearIndepOn R id (⋃ i, f i) := by classical rw [iUnion_eq_iUnion_finset f] apply linearIndepOn_iUnion_of_directed · apply directed_of_isDirected_le exact fun t₁ t₂ ht => iUnion_mono fun i => iUnion_subset_iUnion_const fun h => ht h intro t induction t using Finset.induction_on with | empty => simp | insert i s his ih => rw [Finset.set_biUnion_insert] refine (hl _).id_union ih ?_ rw [span_iUnion₂] exact hd i s s.finite_toSet his @[deprecated (since := "2025-02-15")] alias linearIndependent_iUnion_finite_subtype := linearIndepOn_id_iUnion_finite theorem linearIndependent_iUnion_finite {η : Type*} {ιs : η → Type*} {f : ∀ j : η, ιs j → M} (hindep : ∀ j, LinearIndependent R (f j)) (hd : ∀ i, ∀ t : Set η, t.Finite → i ∉ t → Disjoint (span R (range (f i))) (⨆ i ∈ t, span R (range (f i)))) : LinearIndependent R fun ji : Σ j, ιs j => f ji.1 ji.2 := by nontriviality R apply LinearIndependent.of_linearIndepOn_id_range · rintro ⟨x₁, x₂⟩ ⟨y₁, y₂⟩ hxy by_cases h_cases : x₁ = y₁ · subst h_cases refine Sigma.eq rfl ?_ rw [LinearIndependent.injective (hindep _) hxy] · have h0 : f x₁ x₂ = 0 := by apply disjoint_def.1 (hd x₁ {y₁} (finite_singleton y₁) fun h => h_cases (eq_of_mem_singleton h)) (f x₁ x₂) (subset_span (mem_range_self _)) rw [iSup_singleton] simp only at hxy rw [hxy] exact subset_span (mem_range_self y₂) exact False.elim ((hindep x₁).ne_zero _ h0) rw [range_sigma_eq_iUnion_range] apply linearIndepOn_id_iUnion_finite (fun j => (hindep j).linearIndepOn_id) hd open LinearMap variable (R) in theorem exists_maximal_linearIndepOn (v : ι → M) : ∃ s : Set ι, (LinearIndepOn R v s) ∧ ∀ i ∉ s, ∃ a : R, a ≠ 0 ∧ a • v i ∈ span R (v '' s) := by classical rcases exists_maximal_linearIndepOn' R v with ⟨I, hIlinind, hImaximal⟩ use I, hIlinind intro i hi specialize hImaximal (I ∪ {i}) (by simp) set J := I ∪ {i} with hJ have memJ : ∀ {x}, x ∈ J ↔ x = i ∨ x ∈ I := by simp [hJ] have hiJ : i ∈ J := by simp [J] have h := by refine mt hImaximal ?_ · intro h2 rw [h2] at hi exact absurd hiJ hi obtain ⟨f, supp_f, sum_f, f_ne⟩ := linearDepOn_iff.mp h have hfi : f i ≠ 0 := by contrapose hIlinind refine linearDepOn_iff.mpr ⟨f, ?_, sum_f, f_ne⟩ simp only [Finsupp.mem_supported, hJ] at supp_f ⊢ rintro x hx refine (memJ.mp (supp_f hx)).resolve_left ?_ rintro rfl exact hIlinind (Finsupp.mem_support_iff.mp hx) use f i, hfi have hfi' : i ∈ f.support := Finsupp.mem_support_iff.mpr hfi rw [← Finset.insert_erase hfi', Finset.sum_insert (Finset.notMem_erase _ _), add_eq_zero_iff_eq_neg] at sum_f rw [sum_f] refine neg_mem (sum_mem fun c hc => smul_mem _ _ (subset_span ⟨c, ?_, rfl⟩)) exact (memJ.mp (supp_f (Finset.erase_subset _ _ hc))).resolve_left (Finset.ne_of_mem_erase hc) @[deprecated (since := "2025-02-15")] alias exists_maximal_independent := exists_maximal_linearIndepOn @[stacks 0CKM] lemma linearIndependent_algHom_toLinearMap (K M L) [CommSemiring K] [Semiring M] [Algebra K M] [CommRing L] [IsDomain L] [Algebra K L] : LinearIndependent L (AlgHom.toLinearMap : (M →ₐ[K] L) → M →ₗ[K] L) := by apply LinearIndependent.of_comp (LinearMap.ltoFun K M L) exact (linearIndependent_monoidHom M L).comp (RingHom.toMonoidHom ∘ AlgHom.toRingHom) (fun _ _ e ↦ AlgHom.ext (DFunLike.congr_fun e :)) lemma linearIndependent_algHom_toLinearMap' (K M L) [CommRing K] [Semiring M] [Algebra K M] [CommRing L] [IsDomain L] [Algebra K L] [NoZeroSMulDivisors K L] : LinearIndependent K (AlgHom.toLinearMap : (M →ₐ[K] L) → M →ₗ[K] L) := (linearIndependent_algHom_toLinearMap K M L).restrict_scalars' K end Module /-! ### Properties which require `DivisionRing K` These can be considered generalizations of properties of linear independence in vector spaces. -/ section Module variable [DivisionRing K] [AddCommGroup V] [Module K V] variable {v : ι → V} {s t : Set V} {x y : V} open Submodule /- TODO: some of the following proofs can generalized with a zero_ne_one predicate type class (instead of a data containing type class) -/ theorem mem_span_insert_exchange : x ∈ span K (insert y s) → x ∉ span K s → y ∈ span K (insert x s) := by simp only [mem_span_insert, forall_exists_index, and_imp] rintro a z hz rfl h refine ⟨a⁻¹, -a⁻¹ • z, smul_mem _ _ hz, ?_⟩ have a0 : a ≠ 0 := by rintro rfl simp_all match_scalars <;> simp [a0] protected theorem LinearIndepOn.insert {s : Set ι} {x : ι} (hs : LinearIndepOn K v s) (hx : v x ∉ span K (v '' s)) : LinearIndepOn K v (insert x s) := by rw [← union_singleton] have x0 : v x ≠ 0 := fun h => hx (h ▸ zero_mem _) apply hs.union (LinearIndepOn.singleton _ x0) rwa [image_singleton, disjoint_span_singleton' x0] protected theorem LinearIndepOn.id_insert (hs : LinearIndepOn K id s) (hx : x ∉ span K s) : LinearIndepOn K id (insert x s) := hs.insert ((image_id s).symm ▸ hx) @[deprecated (since := "2025-02-15")] alias LinearIndependent.insert := LinearIndepOn.id_insert theorem linearIndependent_option' : LinearIndependent K (fun o => Option.casesOn' o x v : Option ι → V) ↔ LinearIndependent K v ∧ x ∉ Submodule.span K (range v) := by -- Porting note: Explicit universe level is required in `Equiv.optionEquivSumPUnit`. rw [← linearIndependent_equiv (Equiv.optionEquivSumPUnit.{u', _} ι).symm, linearIndependent_sum, @range_unique _ PUnit, @linearIndependent_unique_iff PUnit, disjoint_span_singleton] dsimp [(· ∘ ·)] refine ⟨fun h => ⟨h.1, fun hx => h.2.1 <| h.2.2 hx⟩, fun h => ⟨h.1, ?_, fun hx => (h.2 hx).elim⟩⟩ rintro rfl exact h.2 (zero_mem _) theorem LinearIndependent.option (hv : LinearIndependent K v) (hx : x ∉ Submodule.span K (range v)) : LinearIndependent K (fun o => Option.casesOn' o x v : Option ι → V) := linearIndependent_option'.2 ⟨hv, hx⟩ theorem linearIndependent_option {v : Option ι → V} : LinearIndependent K v ↔ LinearIndependent K (v ∘ (↑) : ι → V) ∧ v none ∉ Submodule.span K (range (v ∘ (↑) : ι → V)) := by simp only [← linearIndependent_option', Option.casesOn'_none_coe] theorem linearIndepOn_insert {s : Set ι} {a : ι} {f : ι → V} (has : a ∉ s) : LinearIndepOn K f (insert a s) ↔ LinearIndepOn K f s ∧ f a ∉ Submodule.span K (f '' s) := by classical rw [LinearIndepOn, LinearIndepOn, ← linearIndependent_equiv ((Equiv.optionEquivSumPUnit _).trans (Equiv.Set.insert has).symm), linearIndependent_option] simp only [comp_def] rw [range_comp'] simp @[deprecated (since := "2025-02-15")] alias linearIndependent_insert' := linearIndepOn_insert theorem linearIndepOn_id_insert (hxs : x ∉ s) : LinearIndepOn K id (insert x s) ↔ LinearIndepOn K id s ∧ x ∉ Submodule.span K s := (linearIndepOn_insert (f := id) hxs).trans <| by simp @[deprecated (since := "2025-02-15")] alias linearIndependent_insert := linearIndepOn_insert theorem linearIndepOn_insert_iff {s : Set ι} {a : ι} {f : ι → V} : LinearIndepOn K f (insert a s) ↔ LinearIndepOn K f s ∧ (f a ∈ span K (f '' s) → a ∈ s) := by by_cases has : a ∈ s · simp [insert_eq_of_mem has, has] simp [linearIndepOn_insert has, has] theorem linearIndepOn_id_insert_iff {a : V} {s : Set V} : LinearIndepOn K id (insert a s) ↔ LinearIndepOn K id s ∧ (a ∈ span K s → a ∈ s) := by simpa using linearIndepOn_insert_iff (a := a) (f := id) theorem LinearIndepOn.mem_span_iff {s : Set ι} {a : ι} {f : ι → V} (h : LinearIndepOn K f s) : f a ∈ Submodule.span K (f '' s) ↔ (LinearIndepOn K f (insert a s) → a ∈ s) := by by_cases has : a ∈ s · exact iff_of_true (subset_span <| mem_image_of_mem f has) fun _ ↦ has simp [linearIndepOn_insert_iff, h, has] /-- A shortcut to a convenient form for the negation in `LinearIndepOn.mem_span_iff`. -/ theorem LinearIndepOn.notMem_span_iff {s : Set ι} {a : ι} {f : ι → V} (h : LinearIndepOn K f s) : f a ∉ Submodule.span K (f '' s) ↔ LinearIndepOn K f (insert a s) ∧ a ∉ s := by rw [h.mem_span_iff, _root_.not_imp] @[deprecated (since := "2025-05-23")] alias LinearIndepOn.not_mem_span_iff := LinearIndepOn.notMem_span_iff theorem LinearIndepOn.mem_span_iff_id {s : Set V} {a : V} (h : LinearIndepOn K id s) : a ∈ Submodule.span K s ↔ (LinearIndepOn K id (insert a s) → a ∈ s) := by simpa using h.mem_span_iff (a := a) theorem LinearIndepOn.notMem_span_iff_id {s : Set V} {a : V} (h : LinearIndepOn K id s) : a ∉ Submodule.span K s ↔ LinearIndepOn K id (insert a s) ∧ a ∉ s := by rw [h.mem_span_iff_id, _root_.not_imp] @[deprecated (since := "2025-05-23")] alias LinearIndepOn.not_mem_span_iff_id := LinearIndepOn.notMem_span_iff_id theorem linearIndepOn_id_pair {x y : V} (hx : x ≠ 0) (hy : ∀ a : K, a • x ≠ y) : LinearIndepOn K id {x, y} := pair_comm y x ▸ (LinearIndepOn.id_singleton K hx).id_insert (x := y) <| mt mem_span_singleton.1 <| not_exists.2 hy @[deprecated (since := "2025-02-15")] alias linearIndependent_pair := linearIndepOn_id_pair /-- `LinearIndepOn.pair_iff` is a version that works over arbitrary rings. -/ theorem linearIndepOn_pair_iff {i j : ι} (v : ι → V) (hij : i ≠ j) (hi : v i ≠ 0) : LinearIndepOn K v {i, j} ↔ ∀ (c : K), c • v i ≠ v j := by rw [pair_comm] convert linearIndepOn_insert (s := {i}) (a := j) hij.symm simp [hi, mem_span_singleton] /-- Also see `LinearIndependent.pair_iff` for the version over arbitrary rings. -/ theorem LinearIndependent.pair_iff' {x y : V} (hx : x ≠ 0) : LinearIndependent K ![x, y] ↔ ∀ a : K, a • x ≠ y := by rw [← linearIndepOn_univ, ← Finset.coe_univ, show @Finset.univ (Fin 2) _ = {0,1} from rfl, Finset.coe_insert, Finset.coe_singleton, linearIndepOn_pair_iff _ (by simp) (by simpa)] simp theorem linearIndependent_fin_cons {n} {v : Fin n → V} : LinearIndependent K (Fin.cons x v : Fin (n + 1) → V) ↔ LinearIndependent K v ∧ x ∉ Submodule.span K (range v) := by rw [← linearIndependent_equiv (finSuccEquiv n).symm, linearIndependent_option] exact Iff.rfl theorem linearIndependent_fin_snoc {n} {v : Fin n → V} : LinearIndependent K (Fin.snoc v x : Fin (n + 1) → V) ↔ LinearIndependent K v ∧ x ∉ Submodule.span K (range v) := by rw [Fin.snoc_eq_cons_rotate, ← Function.comp_def, linearIndependent_equiv, linearIndependent_fin_cons] /-- See `LinearIndependent.fin_cons'` for an uglier version that works if you only have a module over a semiring. -/ theorem LinearIndependent.fin_cons {n} {v : Fin n → V} (hv : LinearIndependent K v) (hx : x ∉ Submodule.span K (range v)) : LinearIndependent K (Fin.cons x v : Fin (n + 1) → V) := linearIndependent_fin_cons.2 ⟨hv, hx⟩ theorem linearIndependent_fin_succ {n} {v : Fin (n + 1) → V} : LinearIndependent K v ↔ LinearIndependent K (Fin.tail v) ∧ v 0 ∉ Submodule.span K (range <| Fin.tail v) := by rw [← linearIndependent_fin_cons, Fin.cons_self_tail] theorem linearIndependent_fin_succ' {n} {v : Fin (n + 1) → V} : LinearIndependent K v ↔ LinearIndependent K (Fin.init v) ∧ v (Fin.last _) ∉ Submodule.span K (range <| Fin.init v) := by rw [← linearIndependent_fin_snoc, Fin.snoc_init_self] /-- Equivalence between `k + 1` vectors of length `n` and `k` vectors of length `n` along with a vector in the complement of their span. -/ def equiv_linearIndependent (n : ℕ) : { s : Fin (n + 1) → V // LinearIndependent K s } ≃ Σ s : { s : Fin n → V // LinearIndependent K s }, ((Submodule.span K (Set.range (s : Fin n → V)))ᶜ : Set V) where toFun s := ⟨⟨Fin.tail s.val, (linearIndependent_fin_succ.mp s.property).left⟩, ⟨s.val 0, (linearIndependent_fin_succ.mp s.property).right⟩⟩ invFun s := ⟨Fin.cons s.2.val s.1.val, linearIndependent_fin_cons.mpr ⟨s.1.property, s.2.property⟩⟩ left_inv _ := by simp only [Fin.cons_self_tail, Subtype.coe_eta] right_inv := fun ⟨_, _⟩ => by simp only [Fin.cons_zero, Subtype.coe_eta, Sigma.mk.inj_iff, Fin.tail_cons, heq_eq_eq, and_self] theorem linearIndependent_fin2 {f : Fin 2 → V} : LinearIndependent K f ↔ f 1 ≠ 0 ∧ ∀ a : K, a • f 1 ≠ f 0 := by rw [linearIndependent_fin_succ, linearIndependent_unique_iff, range_unique, mem_span_singleton, not_exists, show Fin.tail f default = f 1 by rw [← Fin.succ_zero_eq_one]; rfl] theorem exists_linearIndepOn_extension {s t : Set ι} (hs : LinearIndepOn K v s) (hst : s ⊆ t) : ∃ b ⊆ t, s ⊆ b ∧ v '' t ⊆ span K (v '' b) ∧ LinearIndepOn K v b := by obtain ⟨b, sb, h⟩ := by refine zorn_subset_nonempty { b | b ⊆ t ∧ LinearIndepOn K v b} ?_ _ ⟨hst, hs⟩ · refine fun c hc cc _c0 => ⟨⋃₀ c, ⟨?_, ?_⟩, fun x => ?_⟩ · exact sUnion_subset fun x xc => (hc xc).1 · exact linearIndepOn_sUnion_of_directed cc.directedOn fun x xc => (hc xc).2 · exact subset_sUnion_of_mem refine ⟨b, h.prop.1, sb, fun _ ⟨x, hx, hvx⟩ => by_contra fun hn ↦ hn ?_, h.prop.2⟩ subst hvx exact subset_span <| mem_image_of_mem v <| h.mem_of_prop_insert ⟨insert_subset hx h.prop.1, h.prop.2.insert hn⟩ theorem exists_linearIndepOn_id_extension (hs : LinearIndepOn K id s) (hst : s ⊆ t) : ∃ b ⊆ t, s ⊆ b ∧ t ⊆ span K b ∧ LinearIndepOn K id b := by convert exists_linearIndepOn_extension hs hst <;> simp @[deprecated (since := "2025-02-15")] alias exists_linearIndependent_extension := exists_linearIndepOn_id_extension variable (K t) theorem exists_linearIndependent : ∃ b ⊆ t, span K b = span K t ∧ LinearIndependent K ((↑) : b → V) := by obtain ⟨b, hb₁, -, hb₂, hb₃⟩ := exists_linearIndepOn_id_extension (linearIndependent_empty K V) (Set.empty_subset t) exact ⟨b, hb₁, (span_eq_of_le _ hb₂ (Submodule.span_mono hb₁)).symm, hb₃⟩ /-- Indexed version of `exists_linearIndependent`. -/ lemma exists_linearIndependent' (v : ι → V) : ∃ (κ : Type u') (a : κ → ι), Injective a ∧ Submodule.span K (Set.range (v ∘ a)) = Submodule.span K (Set.range v) ∧ LinearIndependent K (v ∘ a) := by obtain ⟨t, ht, hsp, hli⟩ := exists_linearIndependent K (Set.range v) choose f hf using ht let s : Set ι := Set.range (fun a : t ↦ f a.property) have hs {i : ι} (hi : i ∈ s) : v i ∈ t := by obtain ⟨a, rfl⟩ := hi; simp [hf] let f' (a : s) : t := ⟨v a.val, hs a.property⟩ refine ⟨s, Subtype.val, Subtype.val_injective, hsp.symm ▸ by congr; aesop, ?_⟩ · rw [← show Subtype.val ∘ f' = v ∘ Subtype.val by ext; simp [f']] apply hli.comp rintro ⟨i, x, rfl⟩ ⟨j, y, rfl⟩ hij simp only [Subtype.ext_iff, hf, f'] at hij simp [hij] variable {K} {s t : Set ι} /-- `LinearIndepOn.extend` adds vectors to a linear independent set `s ⊆ t` until it spans all elements of `t`. -/ noncomputable def LinearIndepOn.extend (hs : LinearIndepOn K v s) (hst : s ⊆ t) : Set ι := Classical.choose (exists_linearIndepOn_extension hs hst) @[deprecated (since := "2025-02-15")] alias LinearIndependent.extend := LinearIndepOn.extend theorem LinearIndepOn.extend_subset (hs : LinearIndepOn K v s) (hst : s ⊆ t) : hs.extend hst ⊆ t := let ⟨hbt, _hsb, _htb, _hli⟩ := Classical.choose_spec (exists_linearIndepOn_extension hs hst) hbt @[deprecated (since := "2025-02-15")] alias LinearIndependent.extend_subset := LinearIndepOn.extend_subset theorem LinearIndepOn.subset_extend (hs : LinearIndepOn K v s) (hst : s ⊆ t) : s ⊆ hs.extend hst := let ⟨_hbt, hsb, _htb, _hli⟩ := Classical.choose_spec (exists_linearIndepOn_extension hs hst) hsb @[deprecated (since := "2025-02-15")] alias LinearIndependent.subset_extend := LinearIndepOn.subset_extend theorem LinearIndepOn.image_subset_span_image_extend (hs : LinearIndepOn K v s) (hst : s ⊆ t) : v '' t ⊆ span K (v '' hs.extend hst) := let ⟨_hbt, _hsb, htb, _hli⟩ := Classical.choose_spec (exists_linearIndepOn_extension hs hst) htb theorem LinearIndepOn.subset_span_extend {s t : Set V} (hs : LinearIndepOn K id s) (hst : s ⊆ t) : t ⊆ span K (hs.extend hst) := by convert hs.image_subset_span_image_extend hst <;> simp @[deprecated (since := "2025-02-15")] alias LinearIndependent.subset_span_extend := LinearIndepOn.subset_span_extend theorem LinearIndepOn.span_image_extend_eq_span_image (hs : LinearIndepOn K v s) (hst : s ⊆ t) : span K (v '' hs.extend hst) = span K (v '' t) := le_antisymm (span_mono (image_mono (hs.extend_subset hst))) (span_le.2 (hs.image_subset_span_image_extend hst)) theorem LinearIndepOn.span_extend_eq_span {s t : Set V} (hs : LinearIndepOn K id s) (hst : s ⊆ t) : span K (hs.extend hst) = span K t := le_antisymm (span_mono (hs.extend_subset hst)) (span_le.2 (hs.subset_span_extend hst)) @[deprecated (since := "2025-02-15")] alias LinearIndependent.span_extend_eq_span := LinearIndepOn.span_extend_eq_span theorem LinearIndepOn.linearIndepOn_extend (hs : LinearIndepOn K v s) (hst : s ⊆ t) : LinearIndepOn K v (hs.extend hst) := let ⟨_hbt, _hsb, _htb, hli⟩ := Classical.choose_spec (exists_linearIndepOn_extension hs hst) hli @[deprecated (since := "2025-02-15")] alias LinearIndependent.linearIndependent_extend := LinearIndepOn.linearIndepOn_extend -- TODO(Mario): rewrite? theorem exists_of_linearIndepOn_of_finite_span {s : Set V} {t : Finset V} (hs : LinearIndepOn K id s) (hst : s ⊆ (span K ↑t : Submodule K V)) : ∃ t' : Finset V, ↑t' ⊆ s ∪ ↑t ∧ s ⊆ ↑t' ∧ t'.card = t.card := by classical have : ∀ t : Finset V, ∀ s' : Finset V, ↑s' ⊆ s → s ∩ ↑t = ∅ → s ⊆ (span K ↑(s' ∪ t) : Submodule K V) → ∃ t' : Finset V, ↑t' ⊆ s ∪ ↑t ∧ s ⊆ ↑t' ∧ t'.card = (s' ∪ t).card := fun t => Finset.induction_on t (fun s' hs' _ hss' => have : s = ↑s' := eq_of_linearIndepOn_id_of_span_subtype hs hs' <| by simpa using hss' ⟨s', by simp [this]⟩) fun b₁ t hb₁t ih s' hs' hst hss' => have hb₁s : b₁ ∉ s := fun h => by have : b₁ ∈ s ∩ ↑(insert b₁ t) := ⟨h, Finset.mem_insert_self _ _⟩ rwa [hst] at this have hb₁s' : b₁ ∉ s' := fun h => hb₁s <| hs' h have hst : s ∩ ↑t = ∅ := eq_empty_of_subset_empty <| -- Porting note: `-inter_subset_left, -subset_inter_iff` required. Subset.trans (by simp [inter_subset_inter, -inter_subset_left, -subset_inter_iff]) (le_of_eq hst) Classical.by_cases (p := s ⊆ (span K ↑(s' ∪ t) : Submodule K V)) (fun this => let ⟨u, hust, hsu, Eq⟩ := ih _ hs' hst this have hb₁u : b₁ ∉ u := fun h => (hust h).elim hb₁s hb₁t ⟨insert b₁ u, by simp [insert_subset_insert hust], Subset.trans hsu (by simp), by simp [Eq, hb₁t, hb₁s', hb₁u]⟩) fun this => let ⟨b₂, hb₂s, hb₂t⟩ := not_subset.mp this have hb₂t' : b₂ ∉ s' ∪ t := fun h => hb₂t <| subset_span h have : s ⊆ (span K ↑(insert b₂ s' ∪ t) : Submodule K V) := fun b₃ hb₃ => by have : ↑(s' ∪ insert b₁ t) ⊆ insert b₁ (insert b₂ ↑(s' ∪ t) : Set V) := by simp only [insert_eq, union_subset_union, Subset.refl, subset_union_right, Finset.union_insert, Finset.coe_insert] have hb₃ : b₃ ∈ span K (insert b₁ (insert b₂ ↑(s' ∪ t) : Set V)) := span_mono this (hss' hb₃) have : s ⊆ (span K (insert b₁ ↑(s' ∪ t)) : Submodule K V) := by simpa [insert_eq, -singleton_union, -union_singleton] using hss' have hb₁ : b₁ ∈ span K (insert b₂ ↑(s' ∪ t)) := mem_span_insert_exchange (this hb₂s) hb₂t rw [span_insert_eq_span hb₁] at hb₃; simpa using hb₃ let ⟨u, hust, hsu, eq⟩ := ih _ (by simp [insert_subset_iff, hb₂s, hs']) hst this ⟨u, Subset.trans hust <| union_subset_union (Subset.refl _) (by simp [subset_insert]), hsu, by simp [eq, hb₂t', hb₁t, hb₁s']⟩ have eq : ((t.filter fun x => x ∈ s) ∪ t.filter fun x => x ∉ s) = t := by ext1 x by_cases x ∈ s <;> simp [*] apply Exists.elim (this (t.filter fun x => x ∉ s) (t.filter fun x => x ∈ s) (by simp [Set.subset_def]) (by simp +contextual [Set.ext_iff]) (by rwa [eq])) intro u h exact ⟨u, Subset.trans h.1 (by simp +contextual [subset_def, or_imp]), h.2.1, by simp only [h.2.2, eq]⟩ @[deprecated (since := "2025-02-15")] alias exists_of_linearIndependent_of_finite_span := exists_of_linearIndepOn_of_finite_span theorem exists_finite_card_le_of_finite_of_linearIndependent_of_span {s t : Set V} (ht : t.Finite) (hs : LinearIndepOn K id s) (hst : s ⊆ span K t) : ∃ h : s.Finite, h.toFinset.card ≤ ht.toFinset.card := have : s ⊆ (span K ↑ht.toFinset : Submodule K V) := by simpa let ⟨u, _hust, hsu, Eq⟩ := exists_of_linearIndepOn_of_finite_span hs this have : s.Finite := u.finite_toSet.subset hsu ⟨this, by rw [← Eq]; exact Finset.card_le_card <| Finset.coe_subset.mp <| by simp [hsu]⟩ end Module
Expand.lean
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.Algebra.Algebra.ZMod import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots /-! # Cyclotomic polynomials and `expand`. We gather results relating cyclotomic polynomials and `expand`. ## Main results * `Polynomial.cyclotomic_expand_eq_cyclotomic_mul` : If `p` is a prime such that `¬ p ∣ n`, then `expand R p (cyclotomic n R) = (cyclotomic (n * p) R) * (cyclotomic n R)`. * `Polynomial.cyclotomic_expand_eq_cyclotomic` : If `p` is a prime such that `p ∣ n`, then `expand R p (cyclotomic n R) = cyclotomic (p * n) R`. * `Polynomial.cyclotomic_mul_prime_eq_pow_of_not_dvd` : If `R` is of characteristic `p` and `¬p ∣ n`, then `cyclotomic (n * p) R = (cyclotomic n R) ^ (p - 1)`. * `Polynomial.cyclotomic_mul_prime_dvd_eq_pow` : If `R` is of characteristic `p` and `p ∣ n`, then `cyclotomic (n * p) R = (cyclotomic n R) ^ p`. * `Polynomial.cyclotomic_mul_prime_pow_eq` : If `R` is of characteristic `p` and `¬p ∣ m`, then `cyclotomic (p ^ k * m) R = (cyclotomic m R) ^ (p ^ k - p ^ (k - 1))`. -/ namespace Polynomial /-- If `p` is a prime such that `¬ p ∣ n`, then `expand R p (cyclotomic n R) = (cyclotomic (n * p) R) * (cyclotomic n R)`. -/ @[simp] theorem cyclotomic_expand_eq_cyclotomic_mul {p n : ℕ} (hp : Nat.Prime p) (hdiv : ¬p ∣ n) (R : Type*) [CommRing R] : expand R p (cyclotomic n R) = cyclotomic (n * p) R * cyclotomic n R := by rcases Nat.eq_zero_or_pos n with (rfl | hnpos) · simp haveI := NeZero.of_pos hnpos suffices expand ℤ p (cyclotomic n ℤ) = cyclotomic (n * p) ℤ * cyclotomic n ℤ by rw [← map_cyclotomic_int, ← map_expand, this, Polynomial.map_mul, map_cyclotomic_int, map_cyclotomic] refine eq_of_monic_of_dvd_of_natDegree_le ((cyclotomic.monic _ ℤ).mul (cyclotomic.monic _ ℤ)) ((cyclotomic.monic n ℤ).expand hp.pos) ?_ ?_ · refine (IsPrimitive.Int.dvd_iff_map_cast_dvd_map_cast _ _ (IsPrimitive.mul (cyclotomic.isPrimitive (n * p) ℤ) (cyclotomic.isPrimitive n ℤ)) ((cyclotomic.monic n ℤ).expand hp.pos).isPrimitive).2 ?_ rw [Polynomial.map_mul, map_cyclotomic_int, map_cyclotomic_int, map_expand, map_cyclotomic_int] refine IsCoprime.mul_dvd (cyclotomic.isCoprime_rat fun h => ?_) ?_ ?_ · replace h : n * p = n * 1 := by simp [h] exact Nat.Prime.ne_one hp (mul_left_cancel₀ hnpos.ne' h) · have hpos : 0 < n * p := mul_pos hnpos hp.pos have hprim := Complex.isPrimitiveRoot_exp _ hpos.ne' rw [cyclotomic_eq_minpoly_rat hprim hpos] refine minpoly.dvd ℚ _ ?_ rw [aeval_def, ← eval_map, map_expand, map_cyclotomic, expand_eval, ← IsRoot.def, @isRoot_cyclotomic_iff] convert IsPrimitiveRoot.pow_of_dvd hprim hp.ne_zero (dvd_mul_left p n) rw [Nat.mul_div_cancel _ (Nat.Prime.pos hp)] · have hprim := Complex.isPrimitiveRoot_exp _ hnpos.ne.symm rw [cyclotomic_eq_minpoly_rat hprim hnpos] refine minpoly.dvd ℚ _ ?_ rw [aeval_def, ← eval_map, map_expand, expand_eval, ← IsRoot.def, ← cyclotomic_eq_minpoly_rat hprim hnpos, map_cyclotomic, @isRoot_cyclotomic_iff] exact IsPrimitiveRoot.pow_of_prime hprim hp hdiv · rw [natDegree_expand, natDegree_cyclotomic, natDegree_mul (cyclotomic_ne_zero _ ℤ) (cyclotomic_ne_zero _ ℤ), natDegree_cyclotomic, natDegree_cyclotomic, mul_comm n, Nat.totient_mul ((Nat.Prime.coprime_iff_not_dvd hp).2 hdiv), Nat.totient_prime hp, mul_comm (p - 1), ← Nat.mul_succ, Nat.sub_one, Nat.succ_pred_eq_of_pos hp.pos] /-- If `p` is a prime such that `p ∣ n`, then `expand R p (cyclotomic n R) = cyclotomic (p * n) R`. -/ @[simp] theorem cyclotomic_expand_eq_cyclotomic {p n : ℕ} (hp : Nat.Prime p) (hdiv : p ∣ n) (R : Type*) [CommRing R] : expand R p (cyclotomic n R) = cyclotomic (n * p) R := by rcases n.eq_zero_or_pos with (rfl | hzero) · simp haveI := NeZero.of_pos hzero suffices expand ℤ p (cyclotomic n ℤ) = cyclotomic (n * p) ℤ by rw [← map_cyclotomic_int, ← map_expand, this, map_cyclotomic_int] refine eq_of_monic_of_dvd_of_natDegree_le (cyclotomic.monic _ ℤ) ((cyclotomic.monic n ℤ).expand hp.pos) ?_ ?_ · have hpos := Nat.mul_pos hzero hp.pos have hprim := Complex.isPrimitiveRoot_exp _ hpos.ne.symm rw [cyclotomic_eq_minpoly hprim hpos] refine minpoly.isIntegrallyClosed_dvd (hprim.isIntegral hpos) ?_ rw [aeval_def, ← eval_map, map_expand, map_cyclotomic, expand_eval, ← IsRoot.def, @isRoot_cyclotomic_iff] convert IsPrimitiveRoot.pow_of_dvd hprim hp.ne_zero (dvd_mul_left p n) rw [Nat.mul_div_cancel _ hp.pos] · rw [natDegree_expand, natDegree_cyclotomic, natDegree_cyclotomic, mul_comm n, Nat.totient_mul_of_prime_of_dvd hp hdiv, mul_comm] /-- If the `p ^ n`th cyclotomic polynomial is irreducible, so is the `p ^ m`th, for `m ≤ n`. -/ theorem cyclotomic_irreducible_pow_of_irreducible_pow {p : ℕ} (hp : Nat.Prime p) {R} [CommRing R] [IsDomain R] {n m : ℕ} (hmn : m ≤ n) (h : Irreducible (cyclotomic (p ^ n) R)) : Irreducible (cyclotomic (p ^ m) R) := by rcases m.eq_zero_or_pos with (rfl | hm) · simpa using irreducible_X_sub_C (1 : R) obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn induction' k with k hk · simpa using h have : m + k ≠ 0 := (add_pos_of_pos_of_nonneg hm k.zero_le).ne' rw [Nat.add_succ, pow_succ, ← cyclotomic_expand_eq_cyclotomic hp <| dvd_pow_self p this] at h exact hk (by omega) (of_irreducible_expand hp.ne_zero h) /-- If `Irreducible (cyclotomic (p ^ n) R)` then `Irreducible (cyclotomic p R).` -/ theorem cyclotomic_irreducible_of_irreducible_pow {p : ℕ} (hp : Nat.Prime p) {R} [CommRing R] [IsDomain R] {n : ℕ} (hn : n ≠ 0) (h : Irreducible (cyclotomic (p ^ n) R)) : Irreducible (cyclotomic p R) := pow_one p ▸ cyclotomic_irreducible_pow_of_irreducible_pow hp hn.bot_lt h section CharP /-- If `R` is of characteristic `p` and `¬p ∣ n`, then `cyclotomic (n * p) R = (cyclotomic n R) ^ (p - 1)`. -/ theorem cyclotomic_mul_prime_eq_pow_of_not_dvd (R : Type*) {p n : ℕ} [hp : Fact (Nat.Prime p)] [Ring R] [CharP R p] (hn : ¬p ∣ n) : cyclotomic (n * p) R = cyclotomic n R ^ (p - 1) := by letI : Algebra (ZMod p) R := ZMod.algebra _ _ suffices cyclotomic (n * p) (ZMod p) = cyclotomic n (ZMod p) ^ (p - 1) by rw [← map_cyclotomic _ (algebraMap (ZMod p) R), ← map_cyclotomic _ (algebraMap (ZMod p) R), this, Polynomial.map_pow] apply mul_right_injective₀ (cyclotomic_ne_zero n <| ZMod p); dsimp rw [← pow_succ', tsub_add_cancel_of_le hp.out.one_lt.le, mul_comm, ← ZMod.expand_card] conv_rhs => rw [← map_cyclotomic_int] rw [← map_expand, cyclotomic_expand_eq_cyclotomic_mul hp.out hn, Polynomial.map_mul, map_cyclotomic, map_cyclotomic] /-- If `R` is of characteristic `p` and `p ∣ n`, then `cyclotomic (n * p) R = (cyclotomic n R) ^ p`. -/ theorem cyclotomic_mul_prime_dvd_eq_pow (R : Type*) {p n : ℕ} [hp : Fact (Nat.Prime p)] [Ring R] [CharP R p] (hn : p ∣ n) : cyclotomic (n * p) R = cyclotomic n R ^ p := by letI : Algebra (ZMod p) R := ZMod.algebra _ _ suffices cyclotomic (n * p) (ZMod p) = cyclotomic n (ZMod p) ^ p by rw [← map_cyclotomic _ (algebraMap (ZMod p) R), ← map_cyclotomic _ (algebraMap (ZMod p) R), this, Polynomial.map_pow] rw [← ZMod.expand_card, ← map_cyclotomic_int n, ← map_expand, cyclotomic_expand_eq_cyclotomic hp.out hn, map_cyclotomic] /-- If `R` is of characteristic `p` and `¬p ∣ m`, then `cyclotomic (p ^ k * m) R = (cyclotomic m R) ^ (p ^ k - p ^ (k - 1))`. -/ theorem cyclotomic_mul_prime_pow_eq (R : Type*) {p m : ℕ} [Fact (Nat.Prime p)] [Ring R] [CharP R p] (hm : ¬p ∣ m) : ∀ {k}, 0 < k → cyclotomic (p ^ k * m) R = cyclotomic m R ^ (p ^ k - p ^ (k - 1)) | 1, _ => by rw [pow_one, Nat.sub_self, pow_zero, mul_comm, cyclotomic_mul_prime_eq_pow_of_not_dvd R hm] | a + 2, _ => by have hdiv : p ∣ p ^ a.succ * m := ⟨p ^ a * m, by rw [← mul_assoc, pow_succ']⟩ rw [pow_succ', mul_assoc, mul_comm, cyclotomic_mul_prime_dvd_eq_pow R hdiv, cyclotomic_mul_prime_pow_eq _ _ a.succ_pos, ← pow_mul] · simp only [tsub_zero, Nat.succ_sub_succ_eq_sub] rw [Nat.mul_sub_right_distrib, mul_comm, pow_succ] · assumption /-- If `R` is of characteristic `p` and `¬p ∣ m`, then `ζ` is a root of `cyclotomic (p ^ k * m) R` if and only if it is a primitive `m`-th root of unity. -/ theorem isRoot_cyclotomic_prime_pow_mul_iff_of_charP {m k p : ℕ} {R : Type*} [CommRing R] [IsDomain R] [hp : Fact (Nat.Prime p)] [hchar : CharP R p] {μ : R} [NeZero (m : R)] : (Polynomial.cyclotomic (p ^ k * m) R).IsRoot μ ↔ IsPrimitiveRoot μ m := by rcases k.eq_zero_or_pos with (rfl | hk) · rw [pow_zero, one_mul, isRoot_cyclotomic_iff] refine ⟨fun h => ?_, fun h => ?_⟩ · rw [IsRoot.def, cyclotomic_mul_prime_pow_eq R (NeZero.not_char_dvd R p m) hk, eval_pow] at h replace h := pow_eq_zero h rwa [← IsRoot.def, isRoot_cyclotomic_iff] at h · rw [← isRoot_cyclotomic_iff, IsRoot.def] at h rw [cyclotomic_mul_prime_pow_eq R (NeZero.not_char_dvd R p m) hk, IsRoot.def, eval_pow, h, zero_pow] exact Nat.sub_ne_zero_of_lt <| pow_right_strictMono₀ hp.out.one_lt <| Nat.pred_lt hk.ne' end CharP end Polynomial
SProd.lean
/- Copyright (c) 2023 Miyahara Kō. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Miyahara Kō -/ import Mathlib.Tactic.FBinop /-! # Set Product Notation This file provides notation for a product of sets, and other similar types. ## Main Definitions * `SProd α β γ` for a binary operation `(· ×ˢ ·) : α → β → γ`. ## Notation We introduce the notation `x ×ˢ y` for the `sprod` of any `SProd` structure. Ideally, `x × y` notation is desirable but this notation is defined in core for `Prod` so replacing `x ×ˢ y` with `x × y` seems difficult. -/ universe u v w /-- Notation type class for the set product `×ˢ`. -/ class SProd (α : Type u) (β : Type v) (γ : outParam (Type w)) where /-- The cartesian product `s ×ˢ t` is the set of `(a, b)` such that `a ∈ s` and `b ∈ t`. -/ sprod : α → β → γ -- This notation binds more strongly than (pre)images, unions and intersections. @[inherit_doc SProd.sprod] infixr:82 " ×ˢ " => SProd.sprod macro_rules | `($x ×ˢ $y) => `(fbinop% SProd.sprod $x $y)
Tannery.lean
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.RCLike.Basic import Mathlib.Analysis.Normed.Group.InfiniteSum /-! # Tannery's theorem Tannery's theorem gives a sufficient criterion for the limit of an infinite sum (with respect to an auxiliary parameter) to equal the sum of the pointwise limits. See https://en.wikipedia.org/wiki/Tannery%27s_theorem. It is a special case of the dominated convergence theorem (with the measure chosen to be the counting measure); but we give here a direct proof, in order to avoid some unnecessary hypotheses that appear when specialising the general measure-theoretic result. -/ open Filter Topology /-- **Tannery's theorem**: topological sums commute with termwise limits, when the norms of the summands are eventually uniformly bounded by a summable function. (This is the special case of the Lebesgue dominated convergence theorem for the counting measure on a discrete set. However, we prove it under somewhat weaker assumptions than the general measure-theoretic result, e.g. `G` is not assumed to be an `ℝ`-vector space or second countable, and the limit is along an arbitrary filter rather than `atTop ℕ`.) See also: * `MeasureTheory.tendsto_integral_of_dominated_convergence` (for general integrals, but with more assumptions on `G`) * `continuous_tsum` (continuity of infinite sums in a parameter) -/ lemma tendsto_tsum_of_dominated_convergence {α β G : Type*} {𝓕 : Filter α} [NormedAddCommGroup G] [CompleteSpace G] {f : α → β → G} {g : β → G} {bound : β → ℝ} (h_sum : Summable bound) (hab : ∀ k : β, Tendsto (f · k) 𝓕 (𝓝 (g k))) (h_bound : ∀ᶠ n in 𝓕, ∀ k, ‖f n k‖ ≤ bound k) : Tendsto (∑' k, f · k) 𝓕 (𝓝 (∑' k, g k)) := by -- WLOG β is nonempty rcases isEmpty_or_nonempty β · simpa only [tsum_empty] using tendsto_const_nhds -- WLOG 𝓕 ≠ ⊥ rcases 𝓕.eq_or_neBot with rfl | _ · simp only [tendsto_bot] -- Auxiliary lemmas have h_g_le (k : β) : ‖g k‖ ≤ bound k := le_of_tendsto (tendsto_norm.comp (hab k)) <| h_bound.mono (fun n h => h k) have h_sumg : Summable (‖g ·‖) := h_sum.of_norm_bounded (fun k ↦ (norm_norm (g k)).symm ▸ h_g_le k) have h_suma : ∀ᶠ n in 𝓕, Summable (‖f n ·‖) := by filter_upwards [h_bound] with n h exact h_sum.of_norm_bounded <| by simpa only [norm_norm] using h -- Now main proof, by an `ε / 3` argument rw [Metric.tendsto_nhds] intro ε hε let ⟨S, hS⟩ := h_sum obtain ⟨T, hT⟩ : ∃ (T : Finset β), dist (∑ b ∈ T, bound b) S < ε / 3 := by rw [HasSum, Metric.tendsto_nhds] at hS classical exact Eventually.exists <| hS _ (by positivity) have h1 : ∑' (k : (Tᶜ : Set β)), bound k < ε / 3 := by calc _ ≤ ‖∑' (k : (Tᶜ : Set β)), bound k‖ := Real.le_norm_self _ _ = ‖S - ∑ b ∈ T, bound b‖ := congrArg _ ?_ _ < ε / 3 := by rwa [dist_eq_norm, norm_sub_rev] at hT simpa only [h_sum.sum_add_tsum_compl, eq_sub_iff_add_eq'] using hS.tsum_eq have h2 : Tendsto (∑ k ∈ T, f · k) 𝓕 (𝓝 (T.sum g)) := tendsto_finset_sum _ (fun i _ ↦ hab i) rw [Metric.tendsto_nhds] at h2 filter_upwards [h2 (ε / 3) (by positivity), h_suma, h_bound] with n hn h_suma h_bound rw [dist_eq_norm, ← h_suma.of_norm.tsum_sub h_sumg.of_norm, ← (h_suma.of_norm.sub h_sumg.of_norm).sum_add_tsum_compl (s := T), (by ring : ε = ε / 3 + (ε / 3 + ε / 3))] refine (norm_add_le _ _).trans_lt (add_lt_add ?_ ?_) · simpa only [dist_eq_norm, Finset.sum_sub_distrib] using hn · rw [(h_suma.subtype _).of_norm.tsum_sub (h_sumg.subtype _).of_norm] refine (norm_sub_le _ _).trans_lt (add_lt_add ?_ ?_) · refine ((norm_tsum_le_tsum_norm (h_suma.subtype _)).trans ?_).trans_lt h1 exact (h_suma.subtype _).tsum_le_tsum (h_bound ·) (h_sum.subtype _) · refine ((norm_tsum_le_tsum_norm <| h_sumg.subtype _).trans ?_).trans_lt h1 exact (h_sumg.subtype _).tsum_le_tsum (h_g_le ·) (h_sum.subtype _)
Lex.lean
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Minchao Wu -/ import Mathlib.Data.Prod.Basic import Mathlib.Order.Lattice import Mathlib.Order.BoundedOrder.Basic import Mathlib.Tactic.Tauto /-! # Lexicographic order This file defines the lexicographic relation for pairs of orders, partial orders and linear orders. ## Main declarations * `Prod.Lex.<pre/partial/linear>Order`: Instances lifting the orders on `α` and `β` to `α ×ₗ β`. ## Notation * `α ×ₗ β`: `α × β` equipped with the lexicographic order ## See also Related files are: * `Data.Finset.CoLex`: Colexicographic order on finite sets. * `Data.List.Lex`: Lexicographic order on lists. * `Data.Pi.Lex`: Lexicographic order on `Πₗ i, α i`. * `Data.PSigma.Order`: Lexicographic order on `Σ' i, α i`. * `Data.Sigma.Order`: Lexicographic order on `Σ i, α i`. -/ variable {α β : Type*} namespace Prod.Lex @[inherit_doc] notation:35 α " ×ₗ " β:34 => Lex (Prod α β) /-- Dictionary / lexicographic ordering on pairs. -/ instance instLE (α β : Type*) [LT α] [LE β] : LE (α ×ₗ β) where le := Prod.Lex (· < ·) (· ≤ ·) instance instLT (α β : Type*) [LT α] [LT β] : LT (α ×ₗ β) where lt := Prod.Lex (· < ·) (· < ·) theorem toLex_le_toLex [LT α] [LE β] {x y : α × β} : toLex x ≤ toLex y ↔ x.1 < y.1 ∨ x.1 = y.1 ∧ x.2 ≤ y.2 := Prod.lex_def theorem toLex_lt_toLex [LT α] [LT β] {x y : α × β} : toLex x < toLex y ↔ x.1 < y.1 ∨ x.1 = y.1 ∧ x.2 < y.2 := Prod.lex_def lemma le_iff [LT α] [LE β] {x y : α ×ₗ β} : x ≤ y ↔ (ofLex x).1 < (ofLex y).1 ∨ (ofLex x).1 = (ofLex y).1 ∧ (ofLex x).2 ≤ (ofLex y).2 := Prod.lex_def lemma lt_iff [LT α] [LT β] {x y : α ×ₗ β} : x < y ↔ (ofLex x).1 < (ofLex y).1 ∨ (ofLex x).1 = (ofLex y).1 ∧ (ofLex x).2 < (ofLex y).2 := Prod.lex_def instance [LT α] [LT β] [WellFoundedLT α] [WellFoundedLT β] : WellFoundedLT (α ×ₗ β) := instIsWellFounded instance [LT α] [LT β] [WellFoundedLT α] [WellFoundedLT β] : WellFoundedRelation (α ×ₗ β) := ⟨(· < ·), wellFounded_lt⟩ /-- Dictionary / lexicographic preorder for pairs. -/ instance instPreorder (α β : Type*) [Preorder α] [Preorder β] : Preorder (α ×ₗ β) where le_refl := refl_of <| Prod.Lex _ _ le_trans _ _ _ := trans_of <| Prod.Lex _ _ lt_iff_le_not_ge x₁ x₂ := by aesop (add simp [le_iff, lt_iff, lt_iff_le_not_ge]) /-- See also `monotone_fst_ofLex` for a version stated in terms of `Monotone`. -/ theorem monotone_fst [Preorder α] [LE β] (t c : α ×ₗ β) (h : t ≤ c) : (ofLex t).1 ≤ (ofLex c).1 := by cases toLex_le_toLex.mp h with | inl h' => exact h'.le | inr h' => exact h'.1.le section Preorder variable [Preorder α] [Preorder β] theorem monotone_fst_ofLex : Monotone fun x : α ×ₗ β ↦ (ofLex x).1 := monotone_fst theorem toLex_covBy_toLex_iff {a₁ a₂ : α} {b₁ b₂ : β} : toLex (a₁, b₁) ⋖ toLex (a₂, b₂) ↔ a₁ = a₂ ∧ b₁ ⋖ b₂ ∨ a₁ ⋖ a₂ ∧ IsMax b₁ ∧ IsMin b₂ := by simp only [CovBy, toLex_lt_toLex, toLex.surjective.forall, Prod.forall, isMax_iff_forall_not_lt, isMin_iff_forall_not_lt] constructor · rintro ⟨ha | ⟨rfl, hb⟩, h₂⟩ · refine .inr ⟨⟨ha, fun c hc₁ hc₂ ↦ ?_⟩, fun c hc ↦ ?_, fun c hc ↦ ?_⟩ · exact h₂ c b₁ (.inl hc₁) (.inl hc₂) · exact h₂ a₁ c (.inr ⟨rfl, hc⟩) (.inl ha) · exact h₂ a₂ c (.inl ha) (.inr ⟨rfl, hc⟩) · exact .inl ⟨rfl, hb, fun c hc₁ hc₂ ↦ h₂ _ _ (.inr ⟨rfl, hc₁⟩) (.inr ⟨rfl, hc₂⟩)⟩ · rintro (⟨rfl, hb, h⟩ | ⟨⟨ha, h⟩, hb₁, hb₂⟩) · refine ⟨.inr ⟨rfl, hb⟩, fun a b ↦ ?_⟩ rintro (hlt₁ | ⟨rfl, hlt₁⟩) (hlt₂ | ⟨heq, hlt₂⟩) exacts [hlt₁.not_gt hlt₂, hlt₁.ne' heq, hlt₂.false, h hlt₁ hlt₂] · refine ⟨.inl ha, fun a b ↦ ?_⟩ rintro (hlt₁ | ⟨rfl, hlt₁⟩) (hlt₂ | ⟨heq, hlt₂⟩) exacts [h hlt₁ hlt₂, hb₂ _ hlt₂, hb₁ _ hlt₁, hb₁ _ hlt₁] theorem covBy_iff {a b : α ×ₗ β} : a ⋖ b ↔ (ofLex a).1 = (ofLex b).1 ∧ (ofLex a).2 ⋖ (ofLex b).2 ∨ (ofLex a).1 ⋖ (ofLex b).1 ∧ IsMax (ofLex a).2 ∧ IsMin (ofLex b).2 := toLex_covBy_toLex_iff end Preorder section PartialOrderPreorder variable [PartialOrder α] [Preorder β] {x y : α × β} /-- Variant of `Prod.Lex.toLex_le_toLex` for partial orders. -/ lemma toLex_le_toLex' : toLex x ≤ toLex y ↔ x.1 ≤ y.1 ∧ (x.1 = y.1 → x.2 ≤ y.2) := by simp only [toLex_le_toLex, lt_iff_le_not_ge, le_antisymm_iff] tauto /-- Variant of `Prod.Lex.toLex_lt_toLex` for partial orders. -/ lemma toLex_lt_toLex' : toLex x < toLex y ↔ x.1 ≤ y.1 ∧ (x.1 = y.1 → x.2 < y.2) := by rw [toLex_lt_toLex] simp only [lt_iff_le_not_ge, le_antisymm_iff] tauto /-- Variant of `Prod.Lex.le_iff` for partial orders. -/ lemma le_iff' {x y : α ×ₗ β} : x ≤ y ↔ (ofLex x).1 ≤ (ofLex y).1 ∧ ((ofLex x).1 = (ofLex y).1 → (ofLex x).2 ≤ (ofLex y).2) := toLex_le_toLex' /-- Variant of `Prod.Lex.lt_iff` for partial orders. -/ lemma lt_iff' {x y : α ×ₗ β} : x < y ↔ (ofLex x).1 ≤ (ofLex y).1 ∧ ((ofLex x).1 = (ofLex y).1 → (ofLex x).2 < (ofLex y).2) := toLex_lt_toLex' theorem toLex_mono : Monotone (toLex : α × β → α ×ₗ β) := fun _x _y hxy ↦ toLex_le_toLex'.2 ⟨hxy.1, fun _ ↦ hxy.2⟩ theorem toLex_strictMono : StrictMono (toLex : α × β → α ×ₗ β) := by rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ h obtain rfl | ha : a₁ = a₂ ∨ _ := h.le.1.eq_or_lt · exact right _ (Prod.mk_lt_mk_iff_right.1 h) · exact left _ _ ha end PartialOrderPreorder /-- Dictionary / lexicographic partial order for pairs. -/ instance instPartialOrder (α β : Type*) [PartialOrder α] [PartialOrder β] : PartialOrder (α ×ₗ β) where le_antisymm _ _ := antisymm_of (Prod.Lex _ _) instance instOrdLexProd [Ord α] [Ord β] : Ord (α ×ₗ β) := lexOrd theorem compare_def [Ord α] [Ord β] : @compare (α ×ₗ β) _ = compareLex (compareOn fun x => (ofLex x).1) (compareOn fun x => (ofLex x).2) := rfl theorem _root_.lexOrd_eq [Ord α] [Ord β] : @lexOrd α β _ _ = instOrdLexProd := rfl theorem _root_.Ord.lex_eq [oα : Ord α] [oβ : Ord β] : Ord.lex oα oβ = instOrdLexProd := rfl instance [Ord α] [Ord β] [Std.OrientedOrd α] [Std.OrientedOrd β] : Std.OrientedOrd (α ×ₗ β) := inferInstanceAs (Std.OrientedCmp (compareLex _ _)) instance [Ord α] [Ord β] [Std.TransOrd α] [Std.TransOrd β] : Std.TransOrd (α ×ₗ β) := inferInstanceAs (Std.TransCmp (compareLex _ _)) /-- Dictionary / lexicographic linear order for pairs. -/ instance instLinearOrder (α β : Type*) [LinearOrder α] [LinearOrder β] : LinearOrder (α ×ₗ β) := { Prod.Lex.instPartialOrder α β with le_total := total_of (Prod.Lex _ _) toDecidableLE := Prod.Lex.decidable _ _ toDecidableLT := Prod.Lex.decidable _ _ toDecidableEq := instDecidableEqLex _ compare_eq_compareOfLessAndEq := fun a b => by have : DecidableLT (α ×ₗ β) := Prod.Lex.decidable _ _ have : Std.LawfulBEqOrd (α ×ₗ β) := ⟨by simp [compare_def, compareLex, compareOn, Ordering.then_eq_eq]⟩ have : Std.LawfulLTOrd (α ×ₗ β) := ⟨by simp [compare_def, compareLex, compareOn, Ordering.then_eq_lt, toLex_lt_toLex, compare_lt_iff_lt]⟩ convert Std.LawfulLTCmp.eq_compareOfLessAndEq (cmp := compare) a b } instance orderBot [PartialOrder α] [Preorder β] [OrderBot α] [OrderBot β] : OrderBot (α ×ₗ β) where bot := toLex ⊥ bot_le _ := toLex_mono bot_le instance orderTop [PartialOrder α] [Preorder β] [OrderTop α] [OrderTop β] : OrderTop (α ×ₗ β) where top := toLex ⊤ le_top _ := toLex_mono le_top instance boundedOrder [PartialOrder α] [Preorder β] [BoundedOrder α] [BoundedOrder β] : BoundedOrder (α ×ₗ β) := { Lex.orderBot, Lex.orderTop with } instance [Preorder α] [Preorder β] [DenselyOrdered α] [DenselyOrdered β] : DenselyOrdered (α ×ₗ β) where dense := by rintro _ _ (@⟨a₁, b₁, a₂, b₂, h⟩ | @⟨a, b₁, b₂, h⟩) · obtain ⟨c, h₁, h₂⟩ := exists_between h exact ⟨(c, b₁), left _ _ h₁, left _ _ h₂⟩ · obtain ⟨c, h₁, h₂⟩ := exists_between h exact ⟨(a, c), right _ h₁, right _ h₂⟩ instance noMaxOrder_of_left [Preorder α] [Preorder β] [NoMaxOrder α] : NoMaxOrder (α ×ₗ β) where exists_gt := by rintro ⟨a, b⟩ obtain ⟨c, h⟩ := exists_gt a exact ⟨⟨c, b⟩, left _ _ h⟩ instance noMinOrder_of_left [Preorder α] [Preorder β] [NoMinOrder α] : NoMinOrder (α ×ₗ β) where exists_lt := by rintro ⟨a, b⟩ obtain ⟨c, h⟩ := exists_lt a exact ⟨⟨c, b⟩, left _ _ h⟩ instance noMaxOrder_of_right [Preorder α] [Preorder β] [NoMaxOrder β] : NoMaxOrder (α ×ₗ β) where exists_gt := by rintro ⟨a, b⟩ obtain ⟨c, h⟩ := exists_gt b exact ⟨⟨a, c⟩, right _ h⟩ instance noMinOrder_of_right [Preorder α] [Preorder β] [NoMinOrder β] : NoMinOrder (α ×ₗ β) where exists_lt := by rintro ⟨a, b⟩ obtain ⟨c, h⟩ := exists_lt b exact ⟨⟨a, c⟩, right _ h⟩ end Prod.Lex
Elab.lean
/- Copyright (c) 2023 Sebastian Zimmer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sebastian Zimmer, Mario Carneiro, Heather Macbeth, Jovan Gerbscheid -/ import Mathlib.Tactic.GRewrite.Core /-! # The generalized rewriting tactic This file defines the tactics that use the backend defined in `Mathlib.Tactic.GRewrite.Core`: - `grewrite` - `grw` - `apply_rw` - `nth_grewrite` - `nth_grw` -/ namespace Mathlib.Tactic open Lean Meta Elab Parser Tactic /-- Apply the `grewrite` tactic to the current goal. -/ def grewriteTarget (stx : Syntax) (symm : Bool) (config : GRewrite.Config) : TacticM Unit := do let goal ← getMainGoal Term.withSynthesize <| goal.withContext do let e ← elabTerm stx none true if e.hasSyntheticSorry then throwAbortTactic let goal ← getMainGoal let target ← goal.getType let r ← goal.grewrite target e (forwardImp := false) (symm := symm) (config := config) let mvarNew ← mkFreshExprSyntheticOpaqueMVar r.eNew (← goal.getTag) goal.assign (mkApp r.impProof mvarNew) replaceMainGoal (mvarNew.mvarId! :: r.mvarIds) /-- Apply the `grewrite` tactic to a local hypothesis. -/ def grewriteLocalDecl (stx : Syntax) (symm : Bool) (fvarId : FVarId) (config : GRewrite.Config) : TacticM Unit := withMainContext do -- Note: we cannot execute `replace` inside `Term.withSynthesize`. -- See issues #2711 and #2727. let goal ← getMainGoal let r ← Term.withSynthesize <| withMainContext do let e ← elabTerm stx none true if e.hasSyntheticSorry then throwAbortTactic let localDecl ← fvarId.getDecl goal.grewrite localDecl.type e (forwardImp := true) (symm := symm) (config := config) let proof := .app (r.impProof) (.fvar fvarId) let { mvarId, .. } ← goal.replace fvarId proof r.eNew replaceMainGoal (mvarId :: r.mvarIds) /-- Function elaborating `GRewrite.Config`. -/ declare_config_elab elabGRewriteConfig GRewrite.Config /-- `grewrite [e]` works just like `rewrite [e]`, but `e` can be a relation other than `=` or `↔`. For example, ```lean variable {a b c d n : ℤ} example (h₁ : a < b) (h₂ : b ≤ c) : a + d ≤ c + d := by grewrite [h₁, h₂]; rfl example (h : a ≡ b [ZMOD n]) : a ^ 2 ≡ b ^ 2 [ZMOD n] := by grewrite [h]; rfl example (h₁ : a ∣ b) (h₂ : b ∣ a ^ 2 * c) : a ∣ b ^ 2 * c := by grewrite [h₁] at * exact h₂ ``` To be able to use `grewrite`, the relevant lemmas need to be tagged with `@[gcongr]`. To rewrite inside a transitive relation, you can also give it an `IsTrans` instance. -/ syntax (name := grewriteSeq) "grewrite" optConfig rwRuleSeq (location)? : tactic @[tactic grewriteSeq, inherit_doc grewriteSeq] def evalGRewriteSeq : Tactic := fun stx => do let cfg ← elabGRewriteConfig stx[1] let loc := expandOptLocation stx[3] withRWRulesSeq stx[0] stx[2] fun symm term => do withLocation loc (grewriteLocalDecl term symm · cfg) (grewriteTarget term symm cfg) (throwTacticEx `grewrite · "did not find instance of the pattern in the current goal") /-- `grw [e]` works just like `rw [e]`, but `e` can be a relation other than `=` or `↔`. For example, ```lean variable {a b c d n : ℤ} example (h₁ : a < b) (h₂ : b ≤ c) : a + d ≤ c + d := by grw [h₁, h₂] example (h : a ≡ b [ZMOD n]) : a ^ 2 ≡ b ^ 2 [ZMOD n] := by grw [h] example (h₁ : a ∣ b) (h₂ : b ∣ a ^ 2 * c) : a ∣ b ^ 2 * c := by grw [h₁] at * exact h₂ ``` To be able to use `grw`, the relevant lemmas need to be tagged with `@[gcongr]`. To rewrite inside a transitive relation, you can also give it an `IsTrans` instance. -/ macro (name := grwSeq) "grw " c:optConfig s:rwRuleSeq l:(location)? : tactic => match s with | `(rwRuleSeq| [$rs,*]%$rbrak) => -- We show the `rfl` state on `]` `(tactic| (grewrite $c [$rs,*] $(l)?; with_annotate_state $rbrak (try (with_reducible rfl)))) | _ => Macro.throwUnsupported /-- `apply_rewrite [rules]` is a shorthand for `grewrite +implicationHyp [rules]`. -/ macro "apply_rewrite" c:optConfig s:rwRuleSeq loc:(location)? : tactic => do `(tactic| grewrite $[$(getConfigItems c)]* +implicationHyp $s:rwRuleSeq $(loc)?) /-- `apply_rw [rules]` is a shorthand for `grw +implicationHyp [rules]`. -/ macro (name := applyRwSeq) "apply_rw " c:optConfig s:rwRuleSeq loc:(location)? : tactic => do `(tactic| grw $[$(getConfigItems c)]* +implicationHyp $s:rwRuleSeq $(loc)?) /-- `nth_grewrite` is just like `nth_rewrite`, but for `grewrite`. -/ macro "nth_grewrite" c:optConfig ppSpace nums:(num)+ s:rwRuleSeq loc:(location)? : tactic => do `(tactic| grewrite $[$(getConfigItems c)]* (occs := .pos [$[$nums],*]) $s:rwRuleSeq $(loc)?) /-- `nth_grw` is just like `nth_rw`, but for `grw`. -/ macro "nth_grw" c:optConfig ppSpace nums:(num)+ s:rwRuleSeq loc:(location)? : tactic => do `(tactic| grw $[$(getConfigItems c)]* (occs := .pos [$[$nums],*]) $s:rwRuleSeq $(loc)?) end Mathlib.Tactic